1 | import type EventEmitter from 'eventemitter3';
|
2 | import type { AnimationTimeline } from './AnimationTimeline';
|
3 | import type { BaseStyleProps, Shape } from '../types';
|
4 | import type { FederatedEvent } from './FederatedEvent';
|
5 | import type { CustomElementRegistry } from './CustomElementRegistry';
|
6 | import type { CanvasConfig, InteractivePointerEvent } from '../types';
|
7 | import type { DisplayObject } from '../display-objects';
|
8 | import type { PointLike } from '../shapes';
|
9 | import type { Camera } from '../camera';
|
10 | import type { ContextService, EventService, RenderingService } from '../services';
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | export declare enum ElementEvent {
|
19 | DESTROY = "destroy",
|
20 | |
21 |
|
22 |
|
23 | ATTR_MODIFIED = "DOMAttrModified",
|
24 | |
25 |
|
26 |
|
27 |
|
28 | INSERTED = "DOMNodeInserted",
|
29 | |
30 |
|
31 |
|
32 | CHILD_INSERTED = "child-inserted",
|
33 | |
34 |
|
35 |
|
36 |
|
37 | REMOVED = "removed",
|
38 | |
39 |
|
40 |
|
41 | CHILD_REMOVED = "child-removed",
|
42 | |
43 |
|
44 |
|
45 | MOUNTED = "DOMNodeInsertedIntoDocument",
|
46 | |
47 |
|
48 |
|
49 | UNMOUNTED = "DOMNodeRemovedFromDocument",
|
50 | BOUNDS_CHANGED = "bounds-changed",
|
51 | GEOMETRY_BOUNDS_CHANGED = "geometry-bounds-changed",
|
52 | |
53 |
|
54 |
|
55 | RENDER_ORDER_CHANGED = "render-order-changed"
|
56 | }
|
57 | export interface IEventTarget {
|
58 | emitter: EventEmitter;
|
59 | on: (type: string, listener: EventListenerOrEventListenerObject | ((...args: any[]) => void), options?: boolean | AddEventListenerOptions) => this;
|
60 | addEventListener: (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => this;
|
61 | off: (type: string, listener: EventListenerOrEventListenerObject | ((...args: any[]) => void), options?: boolean | AddEventListenerOptions) => this;
|
62 | removeEventListener: (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => this;
|
63 | removeAllEventListeners: () => void;
|
64 | dispatchEvent: <T extends FederatedEvent>(e: T) => boolean;
|
65 | emit: (eventName: string, object: object) => void;
|
66 | }
|
67 | export interface INode extends IEventTarget {
|
68 | shadow: boolean;
|
69 | |
70 |
|
71 |
|
72 | readonly baseURI: string;
|
73 | |
74 |
|
75 |
|
76 | readonly childNodes: IChildNode[];
|
77 | |
78 |
|
79 |
|
80 | readonly firstChild: IChildNode | null;
|
81 | |
82 |
|
83 |
|
84 | isConnected: boolean;
|
85 | |
86 |
|
87 |
|
88 | readonly lastChild: IChildNode | null;
|
89 | |
90 |
|
91 |
|
92 | readonly nextSibling: IChildNode | null;
|
93 | |
94 |
|
95 |
|
96 | readonly nodeName: string;
|
97 | |
98 |
|
99 |
|
100 | readonly nodeType: number;
|
101 | nodeValue: string | null;
|
102 | |
103 |
|
104 |
|
105 | ownerDocument: IDocument | null;
|
106 | |
107 |
|
108 |
|
109 | readonly parentElement: IElement | null;
|
110 | |
111 |
|
112 |
|
113 | parentNode: (INode & IParentNode) | null;
|
114 | |
115 |
|
116 |
|
117 | readonly previousSibling: IChildNode | null;
|
118 | textContent: string | null;
|
119 | appendChild: <T extends INode>(newChild: T, index?: number) => T;
|
120 | |
121 |
|
122 |
|
123 | cloneNode: (deep?: boolean) => INode;
|
124 | |
125 |
|
126 |
|
127 | compareDocumentPosition: (other: INode) => number;
|
128 | |
129 |
|
130 |
|
131 | contains: (other: INode | null) => boolean;
|
132 | |
133 |
|
134 |
|
135 | getRootNode: (options?: GetRootNodeOptions) => INode;
|
136 | |
137 |
|
138 |
|
139 | getAncestor: (n: number) => INode | null;
|
140 | |
141 |
|
142 |
|
143 | forEach: (callback: (o: INode) => void | boolean) => void;
|
144 | |
145 |
|
146 |
|
147 | hasChildNodes: () => boolean;
|
148 | insertBefore: <T extends INode>(newChild: T, refChild: INode | null) => T;
|
149 | isDefaultNamespace: (namespace: string | null) => boolean;
|
150 | |
151 |
|
152 |
|
153 | isEqualNode: (otherNode: INode | null) => boolean;
|
154 | isSameNode: (otherNode: INode | null) => boolean;
|
155 | lookupNamespaceURI: (prefix: string | null) => string | null;
|
156 | lookupPrefix: (namespace: string | null) => string | null;
|
157 | |
158 |
|
159 |
|
160 | normalize: () => void;
|
161 | removeChild: <T extends INode>(oldChild: T, destroy?: boolean) => T;
|
162 | replaceChild: <T extends INode>(newChild: INode, oldChild: T, destroy?: boolean) => T;
|
163 | |
164 |
|
165 |
|
166 | destroy: () => void;
|
167 | }
|
168 | export interface IParentNode {
|
169 | readonly childElementCount: number;
|
170 | |
171 |
|
172 |
|
173 | readonly children: IElement[];
|
174 | |
175 |
|
176 |
|
177 | readonly firstElementChild: IElement | null;
|
178 | |
179 |
|
180 |
|
181 | readonly lastElementChild: IElement | null;
|
182 | |
183 |
|
184 |
|
185 |
|
186 |
|
187 | append: (...nodes: INode[]) => void;
|
188 | |
189 |
|
190 |
|
191 |
|
192 |
|
193 | prepend: (...nodes: INode[]) => void;
|
194 | |
195 |
|
196 |
|
197 | querySelector: <E extends IElement = IElement>(selectors: string) => E | null;
|
198 | |
199 |
|
200 |
|
201 | querySelectorAll: <E extends IElement = IElement>(selectors: string) => E[];
|
202 | |
203 |
|
204 |
|
205 | find: <E extends IElement = IElement>(filter: (node: E) => boolean) => E | null;
|
206 | |
207 |
|
208 |
|
209 | findAll: <E extends IElement = IElement>(filter: (node: E) => boolean) => E[];
|
210 | }
|
211 | export interface IChildNode extends INode {
|
212 | |
213 |
|
214 |
|
215 |
|
216 |
|
217 | after: (...nodes: INode[]) => void;
|
218 | |
219 |
|
220 |
|
221 |
|
222 |
|
223 | before: (...nodes: INode[]) => void;
|
224 | |
225 |
|
226 |
|
227 | remove: () => void;
|
228 | |
229 |
|
230 |
|
231 |
|
232 |
|
233 | replaceWith: (...nodes: INode[]) => void;
|
234 | }
|
235 | export interface DisplayObjectConfig<StyleProps> {
|
236 | |
237 |
|
238 |
|
239 |
|
240 | id?: string;
|
241 | name?: string;
|
242 | |
243 |
|
244 |
|
245 | class?: string;
|
246 | className?: string;
|
247 | |
248 |
|
249 |
|
250 |
|
251 | style?: StyleProps;
|
252 | |
253 |
|
254 |
|
255 |
|
256 |
|
257 | attrs?: StyleProps;
|
258 | type?: Shape | string;
|
259 | |
260 |
|
261 |
|
262 | zIndex?: number;
|
263 | |
264 |
|
265 |
|
266 | visible?: boolean;
|
267 | |
268 |
|
269 |
|
270 |
|
271 |
|
272 | capture?: boolean;
|
273 | |
274 |
|
275 |
|
276 |
|
277 | interactive?: boolean;
|
278 | }
|
279 | export interface IElement<StyleProps = any, ParsedStyleProps = any> extends INode, IChildNode, IParentNode {
|
280 | |
281 |
|
282 |
|
283 | id: string;
|
284 | |
285 |
|
286 |
|
287 | tagName: string;
|
288 | name: string;
|
289 | |
290 |
|
291 |
|
292 | className: string;
|
293 | |
294 |
|
295 |
|
296 | attributes: StyleProps;
|
297 | |
298 |
|
299 |
|
300 |
|
301 | style: StyleProps & ICSSStyleDeclaration<StyleProps>;
|
302 | parsedStyle: ParsedStyleProps;
|
303 | getElementById: <E extends IElement = IElement>(id: string) => E | null;
|
304 | getElementsByName: <E extends IElement = IElement>(name: string) => E[];
|
305 | getElementsByClassName: <E extends IElement = IElement>(className: string) => E[];
|
306 | getElementsByTagName: <E extends IElement = IElement>(tagName: string) => E[];
|
307 | scrollLeft: number;
|
308 | scrollTop: number;
|
309 | clientLeft: number;
|
310 | clientTop: number;
|
311 | |
312 |
|
313 |
|
314 | setAttribute: <Key extends keyof StyleProps>(attributeName: Key, value: StyleProps[Key], force?: boolean) => void;
|
315 | |
316 |
|
317 |
|
318 | getAttribute: (attributeName: keyof StyleProps) => StyleProps[keyof StyleProps] | undefined;
|
319 | |
320 |
|
321 |
|
322 | removeAttribute: (attributeName: keyof StyleProps) => void;
|
323 | hasAttribute: (qualifiedName: string) => boolean;
|
324 | }
|
325 | export interface IDocument extends INode, IParentNode {
|
326 | |
327 |
|
328 |
|
329 | readonly defaultView: ICanvas | null;
|
330 | |
331 |
|
332 |
|
333 | readonly documentElement: IElement;
|
334 | readonly ownerDocument: null;
|
335 | readonly timeline: AnimationTimeline;
|
336 | |
337 |
|
338 |
|
339 | createElement: <T extends DisplayObject<StyleProps>, StyleProps extends BaseStyleProps>(tagName: string, options: DisplayObjectConfig<StyleProps>) => T;
|
340 | }
|
341 |
|
342 |
|
343 |
|
344 | export interface ICSSStyleDeclaration<StyleProps> {
|
345 | setProperty: <Key extends keyof StyleProps>(propertyName: Key, value: StyleProps[Key], priority?: string) => void;
|
346 | getPropertyValue: (propertyName: keyof StyleProps) => StyleProps[keyof StyleProps] | undefined;
|
347 | removeProperty: (propertyName: keyof StyleProps) => void;
|
348 | item: (index: number) => string;
|
349 | }
|
350 | export interface ICanvas extends IEventTarget {
|
351 | document: IDocument;
|
352 | customElements: CustomElementRegistry;
|
353 | devicePixelRatio: number;
|
354 | requestAnimationFrame: (callback: FrameRequestCallback) => number;
|
355 | cancelAnimationFrame: (handle: number) => void;
|
356 | supportTouchEvent: boolean;
|
357 | supportPointerEvent: boolean;
|
358 | isTouchEvent: (event: InteractivePointerEvent) => event is TouchEvent;
|
359 | isMouseEvent: (event: InteractivePointerEvent) => event is MouseEvent;
|
360 | render: () => void;
|
361 | destroy: (destroyScenegraph?: boolean) => void;
|
362 | resize: (width: number, height: number) => void;
|
363 | getConfig: () => Partial<CanvasConfig>;
|
364 | getCamera: () => Camera;
|
365 | getContextService: () => ContextService<unknown>;
|
366 | getRenderingService: () => RenderingService;
|
367 | getEventService: () => EventService;
|
368 | client2Viewport: (client: PointLike) => PointLike;
|
369 | viewport2Client: (viewport: PointLike) => PointLike;
|
370 | canvas2Viewport: (canvas: PointLike) => PointLike;
|
371 | viewport2Canvas: (viewport: PointLike) => PointLike;
|
372 | }
|