| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441 |
- import type RBush from 'rbush';
- import type { GlobalRuntime } from '..';
- import type { ICamera } from '../camera';
- import type { RBushNodeAABB } from '../components';
- import type { DisplayObject } from '../display-objects';
- import type { ContextService, EventService, RenderingContext, RenderingPlugin, RenderingService } from '../services';
- import type { AABB, PointLike, Rectangle } from '../shapes';
- import type { BaseStyleProps, CanvasConfig, InteractivePointerEvent, Shape, TypeEasingFunction } from '../types';
- import type { CustomElementRegistry } from './CustomElementRegistry';
- import type { FederatedEvent } from './FederatedEvent';
- /**
- * built-in events for element
- * @see https://developer.mozilla.org/en-US/docs/Web/API/MutationEvent
- *
- * TODO: use MutationObserver instead
- * @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
- */
- export declare enum ElementEvent {
- REPARENT = "reparent",
- DESTROY = "destroy",
- /**
- * @see https://www.w3.org/TR/DOM-Level-3-Events/#event-type-DOMAttrModified
- */
- ATTR_MODIFIED = "DOMAttrModified",
- /**
- * it has been inserted
- * @see https://www.w3.org/TR/DOM-Level-3-Events/#event-type-DOMNodeInserted
- */
- INSERTED = "DOMNodeInserted",
- /**
- * it is being removed
- * @see https://www.w3.org/TR/DOM-Level-3-Events/#event-type-DOMNodeRemoved
- */
- REMOVED = "removed",
- /**
- * @see https://www.w3.org/TR/DOM-Level-3-Events/#domnodeinsertedintodocument
- */
- MOUNTED = "DOMNodeInsertedIntoDocument",
- /**
- * @see https://www.w3.org/TR/DOM-Level-3-Events/#domnoderemovedfromdocument
- */
- UNMOUNTED = "DOMNodeRemovedFromDocument",
- BOUNDS_CHANGED = "bounds-changed",
- CULLED = "culled"
- }
- export interface IEventTarget {
- addEventListener: (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void;
- removeEventListener: (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void;
- dispatchEvent: <T extends FederatedEvent>(e: T, skipPropagate?: boolean) => boolean;
- }
- export interface INode extends IEventTarget {
- shadow: boolean;
- /**
- * Returns node's node document's document base URL.
- */
- readonly baseURI: string;
- /**
- * Returns the children.
- */
- readonly childNodes: IChildNode[];
- /**
- * Returns the first child.
- */
- readonly firstChild: IChildNode | null;
- /**
- * Returns true if node is connected and false otherwise.
- */
- isConnected: boolean;
- /**
- * Returns the last child.
- */
- readonly lastChild: IChildNode | null;
- /**
- * Returns the next sibling.
- */
- readonly nextSibling: IChildNode | null;
- /**
- * Returns a string appropriate for the type of node.
- */
- readonly nodeName: string;
- /**
- * Returns the type of node.
- */
- readonly nodeType: number;
- nodeValue: string | null;
- /**
- * Returns the node document. Returns null for documents.
- */
- ownerDocument: IDocument | null;
- /**
- * Returns the parent element.
- */
- readonly parentElement: IElement | null;
- /**
- * Returns the parent.
- */
- parentNode: (INode & IParentNode) | null;
- /**
- * Returns the previous sibling.
- */
- readonly previousSibling: IChildNode | null;
- textContent: string | null;
- appendChild: <T extends INode>(newChild: T, index?: number) => T;
- /**
- * Returns a copy of node. If deep is true, the copy also includes the node's descendants.
- */
- cloneNode: (deep?: boolean) => INode;
- /**
- * Returns a bitmask indicating the position of other relative to node.
- */
- compareDocumentPosition: (other: INode) => number;
- /**
- * Returns true if other is an inclusive descendant of node, and false otherwise.
- */
- contains: (other: INode | null) => boolean;
- /**
- * Returns node's root.
- */
- getRootNode: (options?: GetRootNodeOptions) => INode;
- /**
- * Returns node's ancestor.
- */
- getAncestor: (n: number) => INode | null;
- /**
- * Traverse in sub tree.
- */
- forEach: (callback: (o: INode) => void | boolean, assigned?: boolean) => void;
- /**
- * Returns whether node has children.
- */
- hasChildNodes: () => boolean;
- insertBefore: <T extends INode>(newChild: T, refChild: INode | null) => T;
- isDefaultNamespace: (namespace: string | null) => boolean;
- /**
- * Returns whether node and otherNode have the same properties.
- */
- isEqualNode: (otherNode: INode | null) => boolean;
- isSameNode: (otherNode: INode | null) => boolean;
- lookupNamespaceURI: (prefix: string | null) => string | null;
- lookupPrefix: (namespace: string | null) => string | null;
- /**
- * Removes empty exclusive Text nodes and concatenates the data of remaining contiguous exclusive Text nodes into the first of their nodes.
- */
- normalize: () => void;
- removeChild: <T extends INode>(oldChild: T) => T;
- replaceChild: <T extends INode>(newChild: INode, oldChild: T) => T;
- /**
- * Destroy itself.
- */
- destroy: () => void;
- }
- export interface IParentNode {
- readonly childElementCount: number;
- /**
- * Returns the child elements.
- */
- readonly children: IElement[];
- /**
- * Returns the first child that is an element, and null otherwise.
- */
- readonly firstElementChild: IElement | null;
- /**
- * Returns the last child that is an element, and null otherwise.
- */
- readonly lastElementChild: IElement | null;
- /**
- * Inserts nodes after the last child of node, while replacing strings in nodes with equivalent Text nodes.
- *
- * Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
- */
- append: (...nodes: INode[]) => void;
- /**
- * Inserts nodes before the first child of node, while replacing strings in nodes with equivalent Text nodes.
- *
- * Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
- */
- prepend: (...nodes: INode[]) => void;
- /**
- * Returns the first element that is a descendant of node that matches selectors.
- */
- querySelector: <E extends IElement = IElement>(selectors: string) => E | null;
- /**
- * Returns all element descendants of node that match selectors.
- */
- querySelectorAll: <E extends IElement = IElement>(selectors: string) => E[];
- /**
- * Similar to querySelector, use custom filter instead of selectors.
- */
- find: <E extends IElement = IElement>(filter: (node: E) => boolean) => E | null;
- /**
- * Similar to querySelectorAll, use custom filter instead of selectors.
- */
- findAll: <E extends IElement = IElement>(filter: (node: E) => boolean) => E[];
- }
- export interface IChildNode extends INode {
- /**
- * Inserts nodes just after node, while replacing strings in nodes with equivalent Text nodes.
- *
- * Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
- */
- after: (...nodes: INode[]) => void;
- /**
- * Inserts nodes just before node, while replacing strings in nodes with equivalent Text nodes.
- *
- * Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
- */
- before: (...nodes: INode[]) => void;
- /**
- * Removes node.
- */
- remove: () => void;
- /**
- * Replaces node with nodes, while replacing strings in nodes with equivalent Text nodes.
- *
- * Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated.
- */
- replaceWith: (...nodes: INode[]) => void;
- }
- export interface DisplayObjectConfig<StyleProps> {
- /**
- * element's identifier, must be unique in a document.
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/id
- */
- id?: string;
- name?: string;
- /**
- * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/className
- */
- class?: string;
- className?: string;
- /**
- * all styles properties, not read-only
- * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style
- */
- style?: StyleProps;
- initialParsedStyle?: any;
- /**
- * compatible with G 3.0
- * @alias style
- * @deprecated
- */
- attrs?: StyleProps;
- type?: Shape | string;
- /**
- * @deprecated use `style.zIndex` instead
- */
- zIndex?: number;
- /**
- * @deprecated use `style.visibility = 'visible'` instead
- */
- visible?: boolean;
- /**
- * compatible with G 3.0
- * @alias interactive
- * @deprecated
- */
- capture?: boolean;
- /**
- * enable interaction events for the DisplayObject
- * @deprecated use `style.pointerEvents = 'auto'` instead
- */
- interactive?: boolean;
- }
- export interface IElement<StyleProps = any, ParsedStyleProps = any> extends INode, IChildNode, IParentNode {
- /**
- * Returns the value of element's id content attribute. Can be set to change it.
- */
- id: string;
- /**
- * Returns the qualified name.
- */
- tagName: string;
- name: string;
- /**
- * Returns the value of element's class content attribute. Can be set to change it.
- */
- className: string;
- classList: string[];
- /**
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/attributes
- */
- attributes: StyleProps;
- /**
- * compatible with `style`
- * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style
- */
- style: StyleProps & ICSSStyleDeclaration<StyleProps>;
- parsedStyle: ParsedStyleProps;
- getElementById: <E extends IElement = IElement>(id: string) => E | null;
- getElementsByName: <E extends IElement = IElement>(name: string) => E[];
- getElementsByClassName: <E extends IElement = IElement>(className: string) => E[];
- getElementsByTagName: <E extends IElement = IElement>(tagName: string) => E[];
- scrollLeft: number;
- scrollTop: number;
- clientLeft: number;
- clientTop: number;
- getGeometryBounds(): AABB;
- getRenderBounds(): AABB;
- getBounds(): AABB;
- getLocalBounds(): AABB;
- getBoundingClientRect(): Rectangle;
- getClientRects(): Rectangle[];
- /**
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute
- */
- setAttribute: <Key extends keyof StyleProps>(attributeName: Key, value: StyleProps[Key], force?: boolean) => void;
- /**
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute
- */
- getAttribute: (attributeName: keyof StyleProps) => StyleProps[keyof StyleProps] | undefined;
- /**
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute
- */
- removeAttribute: (attributeName: keyof StyleProps) => void;
- hasAttribute: (qualifiedName: string) => boolean;
- }
- export interface IAnimationTimeline {
- currentTime: number | null;
- destroy: () => void;
- play: (target: IElement, keyframes: Keyframe[] | PropertyIndexedKeyframes | null, options?: number | KeyframeAnimationOptions | undefined) => IAnimation;
- restart: () => boolean;
- getAnimations: () => IAnimation[];
- }
- export interface IAnimation {
- effect: IKeyframeEffect;
- timeline: IAnimationTimeline;
- id: string;
- pending: boolean;
- playState: AnimationPlayState;
- ready: Promise<this>;
- finished: Promise<this>;
- onfinish: ((this: this, ev: AnimationPlaybackEvent) => any) | null;
- oncancel: ((this: this, ev: AnimationPlaybackEvent) => any) | null;
- onframe: ((this: this, ev: AnimationPlaybackEvent) => any) | null;
- currentTime: number;
- startTime: number;
- playbackRate: number;
- totalDuration: number;
- play: () => void;
- pause: () => void;
- finish: () => void;
- cancel: () => void;
- reverse: () => void;
- updatePlaybackRate: (playbackRate: number) => void;
- tick: (timelineTime: number, isAnimationFrame: boolean) => void;
- }
- export interface IAnimationEffectTiming extends EffectTiming {
- easingFunction: TypeEasingFunction;
- }
- export interface IKeyframeEffect {
- composite: CompositeOperation;
- iterationComposite: IterationCompositeOperation;
- target: IElement | null;
- animation: IAnimation | null;
- timing: IAnimationEffectTiming;
- normalizedKeyframes: ComputedKeyframe[];
- applyInterpolations: () => void;
- update: (localTime: number | null) => boolean;
- getKeyframes: () => ComputedKeyframe[];
- setKeyframes: (keyframes: Keyframe[] | PropertyIndexedKeyframes | null) => void;
- getComputedTiming: () => ComputedEffectTiming;
- getTiming: () => EffectTiming;
- updateTiming: (timing?: OptionalEffectTiming) => void;
- }
- export interface IDocument extends INode, IParentNode {
- /**
- * Returns the Window object of the active document.
- */
- readonly defaultView: ICanvas | null;
- /**
- * Gets a reference to the root node of the document.
- */
- readonly documentElement: IElement;
- readonly ownerDocument: null;
- readonly timeline: IAnimationTimeline;
- /**
- * Creates an instance of the element for the specified tag.
- */
- createElement: <T extends DisplayObject<StyleProps>, StyleProps extends BaseStyleProps>(tagName: string, options: DisplayObjectConfig<StyleProps>) => T;
- elementFromPoint: (x: number, y: number) => Promise<DisplayObject>;
- elementsFromPoint: (x: number, y: number) => Promise<DisplayObject[]>;
- elementsFromBBox: (minX: number, minY: number, maxX: number, maxY: number) => DisplayObject[];
- }
- /**
- * @see https://developer.mozilla.org/zh-CN/docs/Web/API/CSSStyleDeclaration
- */
- export interface ICSSStyleDeclaration<StyleProps> {
- setProperty: <Key extends keyof StyleProps>(propertyName: Key, value: StyleProps[Key], priority?: string) => void;
- getPropertyValue: (propertyName: keyof StyleProps) => StyleProps[keyof StyleProps] | undefined;
- removeProperty: (propertyName: keyof StyleProps) => void;
- item: (index: number) => string;
- }
- export interface CanvasContext {
- config: Partial<CanvasConfig>;
- camera: ICamera;
- /**
- * ContextServiceContribution
- */
- ContextService: new (context: GlobalRuntime & CanvasContext) => ContextService<unknown>;
- contextService: ContextService<unknown>;
- renderingService: RenderingService;
- eventService: EventService;
- rBushRoot: RBush<RBushNodeAABB>;
- renderingContext: RenderingContext;
- renderingPlugins: RenderingPlugin[];
- }
- export interface ICanvas extends IEventTarget {
- document: IDocument;
- customElements: CustomElementRegistry;
- devicePixelRatio: number;
- requestAnimationFrame: (callback: FrameRequestCallback) => number;
- cancelAnimationFrame: (handle: number) => void;
- supportsTouchEvents: boolean;
- supportsPointerEvents: boolean;
- isTouchEvent: (event: InteractivePointerEvent) => event is TouchEvent;
- isMouseEvent: (event: InteractivePointerEvent) => event is MouseEvent;
- render: () => void;
- destroy: (destroyScenegraph?: boolean) => void;
- resize: (width: number, height: number) => void;
- context: CanvasContext;
- mountChildren: (parent: INode) => void;
- unmountChildren: (parent: INode) => void;
- getConfig: () => Partial<CanvasConfig>;
- getCamera: () => ICamera;
- getContextService: () => ContextService<unknown>;
- getRenderingService: () => RenderingService;
- getEventService: () => EventService;
- client2Viewport: (client: PointLike) => PointLike;
- viewport2Client: (viewport: PointLike) => PointLike;
- canvas2Viewport: (canvas: PointLike) => PointLike;
- viewport2Canvas: (viewport: PointLike) => PointLike;
- }
- interface EventListener {
- (evt: FederatedEvent): void;
- }
- interface EventListenerObject {
- handleEvent(object: FederatedEvent): void;
- }
- export type EventListenerOrEventListenerObject = EventListener | EventListenerObject;
- export {};
- //# sourceMappingURL=interfaces.d.ts.map
|