@antv/g 1.0.0-alpha.20 → 1.0.0-alpha.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (293) hide show
  1. package/es/Canvas.d.ts +40 -18
  2. package/es/Canvas.js +121 -65
  3. package/es/DisplayObjectPool.d.ts +2 -1
  4. package/es/DisplayObjectPool.js +4 -0
  5. package/{lib → es/camera}/Camera.d.ts +6 -3
  6. package/es/{Camera.js → camera/Camera.js} +22 -16
  7. package/es/{Landmark.d.ts → camera/Landmark.d.ts} +2 -2
  8. package/es/{Landmark.js → camera/Landmark.js} +1 -1
  9. package/es/camera/index.d.ts +2 -0
  10. package/es/camera/index.js +2 -0
  11. package/es/components/Cullable.js +1 -1
  12. package/es/components/Geometry.d.ts +8 -1
  13. package/es/components/Renderable.d.ts +9 -8
  14. package/es/components/Renderable.js +2 -6
  15. package/es/components/Sortable.d.ts +6 -2
  16. package/es/display-objects/Circle.d.ts +2 -3
  17. package/es/display-objects/Circle.js +2 -5
  18. package/es/{CustomElement.d.ts → display-objects/CustomElement.d.ts} +1 -1
  19. package/es/{CustomElement.js → display-objects/CustomElement.js} +22 -12
  20. package/{lib → es/display-objects}/DisplayObject.d.ts +136 -141
  21. package/es/{DisplayObject.js → display-objects/DisplayObject.js} +408 -292
  22. package/es/display-objects/Ellipse.d.ts +2 -3
  23. package/es/display-objects/Ellipse.js +2 -5
  24. package/es/display-objects/Group.d.ts +2 -1
  25. package/es/display-objects/Group.js +13 -5
  26. package/es/display-objects/HTML.d.ts +2 -2
  27. package/es/display-objects/HTML.js +4 -7
  28. package/es/display-objects/Image.d.ts +2 -2
  29. package/es/display-objects/Image.js +2 -6
  30. package/es/display-objects/Line.d.ts +2 -2
  31. package/es/display-objects/Line.js +8 -8
  32. package/es/display-objects/Path.d.ts +3 -2
  33. package/es/display-objects/Path.js +8 -8
  34. package/es/display-objects/Polygon.d.ts +2 -2
  35. package/es/display-objects/Polygon.js +2 -6
  36. package/es/display-objects/Polyline.d.ts +2 -2
  37. package/es/display-objects/Polyline.js +8 -8
  38. package/es/display-objects/Rect.d.ts +2 -2
  39. package/es/display-objects/Rect.js +2 -6
  40. package/es/display-objects/Text.d.ts +2 -3
  41. package/es/display-objects/Text.js +8 -7
  42. package/es/display-objects/index.d.ts +2 -0
  43. package/es/display-objects/index.js +2 -0
  44. package/es/{Animation.d.ts → dom/Animation.d.ts} +3 -3
  45. package/es/{Animation.js → dom/Animation.js} +2 -3
  46. package/{lib → es/dom}/AnimationEffectTiming.d.ts +2 -0
  47. package/es/{AnimationEffectTiming.js → dom/AnimationEffectTiming.js} +3 -2
  48. package/es/{AnimationEvent.d.ts → dom/AnimationEvent.d.ts} +3 -2
  49. package/es/{AnimationEvent.js → dom/AnimationEvent.js} +1 -1
  50. package/es/{Timeline.d.ts → dom/AnimationTimeline.d.ts} +1 -1
  51. package/es/{Timeline.js → dom/AnimationTimeline.js} +1 -1
  52. package/es/dom/CustomElementRegistry.d.ts +15 -0
  53. package/es/dom/CustomElementRegistry.js +40 -0
  54. package/{lib → es/dom}/CustomEvent.d.ts +1 -1
  55. package/es/{CustomEvent.js → dom/CustomEvent.js} +1 -1
  56. package/es/dom/Document.d.ts +36 -17
  57. package/es/dom/Document.js +98 -14
  58. package/es/dom/Element.d.ts +71 -92
  59. package/es/dom/Element.js +179 -195
  60. package/es/dom/EventTarget.d.ts +11 -6
  61. package/es/dom/EventTarget.js +12 -4
  62. package/es/dom/FederatedEvent.d.ts +15 -7
  63. package/es/dom/FederatedEvent.js +33 -0
  64. package/es/dom/FederatedMouseEvent.d.ts +1 -1
  65. package/es/{KeyframeEffect.d.ts → dom/KeyframeEffect.d.ts} +16 -5
  66. package/es/{KeyframeEffect.js → dom/KeyframeEffect.js} +50 -4
  67. package/es/{KeyframeList.d.ts → dom/KeyframeList.d.ts} +1 -1
  68. package/es/{KeyframeList.js → dom/KeyframeList.js} +0 -0
  69. package/es/dom/Node.d.ts +38 -23
  70. package/es/dom/Node.js +37 -33
  71. package/es/dom/index.d.ts +15 -2
  72. package/es/dom/index.js +16 -3
  73. package/es/dom/interfaces.d.ts +301 -0
  74. package/es/dom/interfaces.js +1 -0
  75. package/es/global-module.d.ts +0 -2
  76. package/es/global-module.js +31 -29
  77. package/es/index.d.ts +7 -14
  78. package/es/index.js +8 -15
  79. package/es/plugins/CullingPlugin.d.ts +2 -2
  80. package/es/plugins/CullingPlugin.js +13 -16
  81. package/es/plugins/DirtyCheckPlugin.d.ts +1 -1
  82. package/es/plugins/DirtyCheckPlugin.js +8 -7
  83. package/es/plugins/EventPlugin.js +52 -31
  84. package/es/plugins/FrustumCullingStrategy.d.ts +1 -1
  85. package/es/plugins/FrustumCullingStrategy.js +5 -4
  86. package/es/plugins/PrepareRendererPlugin.d.ts +0 -1
  87. package/es/plugins/PrepareRendererPlugin.js +42 -38
  88. package/es/property-handlers/aabb.d.ts +2 -3
  89. package/es/property-handlers/aabb.js +29 -21
  90. package/es/property-handlers/anchor.d.ts +3 -0
  91. package/es/property-handlers/anchor.js +21 -0
  92. package/es/property-handlers/clipPath.d.ts +1 -1
  93. package/es/property-handlers/clipPath.js +3 -4
  94. package/es/property-handlers/color.d.ts +1 -1
  95. package/es/property-handlers/dimension.d.ts +1 -1
  96. package/es/property-handlers/dimension.js +6 -9
  97. package/es/property-handlers/filter.d.ts +1 -1
  98. package/es/property-handlers/index.d.ts +5 -4
  99. package/es/property-handlers/index.js +1 -0
  100. package/es/property-handlers/localPosition.d.ts +1 -1
  101. package/es/property-handlers/localPosition.js +1 -6
  102. package/es/property-handlers/offsetDistance.d.ts +1 -1
  103. package/es/property-handlers/offsetPath.d.ts +1 -1
  104. package/es/property-handlers/origin.d.ts +1 -1
  105. package/es/property-handlers/origin.js +9 -2
  106. package/es/property-handlers/path.d.ts +2 -2
  107. package/es/property-handlers/path.js +8 -4
  108. package/es/property-handlers/points.d.ts +1 -1
  109. package/es/property-handlers/transform.d.ts +1 -1
  110. package/es/property-handlers/zIndex.d.ts +1 -1
  111. package/es/services/ContextService.d.ts +3 -2
  112. package/es/services/EventService.d.ts +18 -13
  113. package/es/services/EventService.js +604 -384
  114. package/es/services/RenderingContext.d.ts +1 -1
  115. package/es/services/RenderingService.d.ts +23 -29
  116. package/es/services/RenderingService.js +63 -54
  117. package/es/services/SceneGraphSelector.d.ts +7 -7
  118. package/es/services/SceneGraphSelector.js +10 -6
  119. package/es/services/SceneGraphService.d.ts +73 -78
  120. package/es/services/SceneGraphService.js +165 -78
  121. package/es/services/aabb/PathUpdater.d.ts +1 -1
  122. package/es/services/aabb/RectUpdater.d.ts +2 -2
  123. package/es/services/aabb/interfaces.d.ts +1 -1
  124. package/es/shapes/Point.d.ts +4 -0
  125. package/es/shapes/Polygon.d.ts +9 -0
  126. package/es/shapes/Polygon.js +62 -0
  127. package/es/shapes/index.d.ts +1 -0
  128. package/es/shapes/index.js +2 -1
  129. package/es/types.d.ts +18 -6
  130. package/es/utils/animation.d.ts +1 -2
  131. package/es/utils/animation.js +5 -10
  132. package/es/utils/canvas.d.ts +1 -1
  133. package/es/utils/custom-easing.d.ts +3 -2
  134. package/es/utils/custom-easing.js +12 -6
  135. package/es/utils/event.js +1 -1
  136. package/es/utils/index.d.ts +1 -0
  137. package/es/utils/index.js +2 -1
  138. package/es/utils/interpolation.d.ts +3 -4
  139. package/es/utils/interpolation.js +0 -16
  140. package/es/utils/path.d.ts +2 -2
  141. package/lib/Canvas.d.ts +40 -18
  142. package/lib/Canvas.js +131 -74
  143. package/lib/DisplayObjectPool.d.ts +2 -1
  144. package/lib/DisplayObjectPool.js +4 -0
  145. package/{es → lib/camera}/Camera.d.ts +6 -3
  146. package/lib/{Camera.js → camera/Camera.js} +25 -20
  147. package/lib/{Landmark.d.ts → camera/Landmark.d.ts} +2 -2
  148. package/lib/{Landmark.js → camera/Landmark.js} +2 -3
  149. package/lib/camera/index.d.ts +2 -0
  150. package/lib/camera/index.js +31 -0
  151. package/lib/components/Cullable.js +1 -1
  152. package/lib/components/Geometry.d.ts +8 -1
  153. package/lib/components/Renderable.d.ts +9 -8
  154. package/lib/components/Renderable.js +2 -6
  155. package/lib/components/Sortable.d.ts +6 -2
  156. package/lib/display-objects/Circle.d.ts +2 -3
  157. package/lib/display-objects/Circle.js +3 -6
  158. package/lib/{CustomElement.d.ts → display-objects/CustomElement.d.ts} +1 -1
  159. package/lib/{CustomElement.js → display-objects/CustomElement.js} +22 -12
  160. package/{es → lib/display-objects}/DisplayObject.d.ts +136 -141
  161. package/lib/{DisplayObject.js → display-objects/DisplayObject.js} +418 -299
  162. package/lib/display-objects/Ellipse.d.ts +2 -3
  163. package/lib/display-objects/Ellipse.js +3 -6
  164. package/lib/display-objects/Group.d.ts +2 -1
  165. package/lib/display-objects/Group.js +12 -4
  166. package/lib/display-objects/HTML.d.ts +2 -2
  167. package/lib/display-objects/HTML.js +4 -7
  168. package/lib/display-objects/Image.d.ts +2 -2
  169. package/lib/display-objects/Image.js +2 -6
  170. package/lib/display-objects/Line.d.ts +2 -2
  171. package/lib/display-objects/Line.js +8 -8
  172. package/lib/display-objects/Path.d.ts +3 -2
  173. package/lib/display-objects/Path.js +8 -8
  174. package/lib/display-objects/Polygon.d.ts +2 -2
  175. package/lib/display-objects/Polygon.js +2 -6
  176. package/lib/display-objects/Polyline.d.ts +2 -2
  177. package/lib/display-objects/Polyline.js +8 -8
  178. package/lib/display-objects/Rect.d.ts +2 -2
  179. package/lib/display-objects/Rect.js +2 -6
  180. package/lib/display-objects/Text.d.ts +2 -3
  181. package/lib/display-objects/Text.js +9 -8
  182. package/lib/display-objects/index.d.ts +2 -0
  183. package/lib/display-objects/index.js +26 -0
  184. package/lib/{Animation.d.ts → dom/Animation.d.ts} +3 -3
  185. package/lib/{Animation.js → dom/Animation.js} +2 -3
  186. package/{es → lib/dom}/AnimationEffectTiming.d.ts +2 -0
  187. package/lib/{AnimationEffectTiming.js → dom/AnimationEffectTiming.js} +3 -3
  188. package/lib/{AnimationEvent.d.ts → dom/AnimationEvent.d.ts} +3 -2
  189. package/lib/{AnimationEvent.js → dom/AnimationEvent.js} +1 -1
  190. package/lib/{Timeline.d.ts → dom/AnimationTimeline.d.ts} +1 -1
  191. package/lib/{Timeline.js → dom/AnimationTimeline.js} +1 -1
  192. package/lib/dom/CustomElementRegistry.d.ts +15 -0
  193. package/lib/dom/CustomElementRegistry.js +48 -0
  194. package/{es → lib/dom}/CustomEvent.d.ts +1 -1
  195. package/lib/{CustomEvent.js → dom/CustomEvent.js} +1 -1
  196. package/lib/dom/Document.d.ts +36 -17
  197. package/lib/dom/Document.js +99 -15
  198. package/lib/dom/Element.d.ts +71 -92
  199. package/lib/dom/Element.js +180 -198
  200. package/lib/dom/EventTarget.d.ts +11 -6
  201. package/lib/dom/EventTarget.js +20 -10
  202. package/lib/dom/FederatedEvent.d.ts +15 -7
  203. package/lib/dom/FederatedEvent.js +33 -0
  204. package/lib/dom/FederatedMouseEvent.d.ts +1 -1
  205. package/lib/{KeyframeEffect.d.ts → dom/KeyframeEffect.d.ts} +16 -5
  206. package/lib/{KeyframeEffect.js → dom/KeyframeEffect.js} +50 -4
  207. package/lib/{KeyframeList.d.ts → dom/KeyframeList.d.ts} +1 -1
  208. package/lib/{KeyframeList.js → dom/KeyframeList.js} +0 -0
  209. package/lib/dom/Node.d.ts +38 -23
  210. package/lib/dom/Node.js +37 -33
  211. package/lib/dom/index.d.ts +15 -2
  212. package/lib/dom/index.js +177 -8
  213. package/lib/dom/interfaces.d.ts +301 -0
  214. package/lib/dom/interfaces.js +5 -0
  215. package/lib/global-module.d.ts +0 -2
  216. package/lib/global-module.js +30 -30
  217. package/lib/index.d.ts +7 -14
  218. package/lib/index.js +44 -135
  219. package/lib/plugins/CullingPlugin.d.ts +2 -2
  220. package/lib/plugins/CullingPlugin.js +14 -16
  221. package/lib/plugins/DirtyCheckPlugin.d.ts +1 -1
  222. package/lib/plugins/DirtyCheckPlugin.js +9 -7
  223. package/lib/plugins/EventPlugin.js +52 -30
  224. package/lib/plugins/FrustumCullingStrategy.d.ts +1 -1
  225. package/lib/plugins/FrustumCullingStrategy.js +5 -4
  226. package/lib/plugins/PrepareRendererPlugin.d.ts +0 -1
  227. package/lib/plugins/PrepareRendererPlugin.js +41 -37
  228. package/lib/property-handlers/aabb.d.ts +2 -3
  229. package/lib/property-handlers/aabb.js +28 -22
  230. package/lib/property-handlers/anchor.d.ts +3 -0
  231. package/lib/property-handlers/anchor.js +34 -0
  232. package/lib/property-handlers/clipPath.d.ts +1 -1
  233. package/lib/property-handlers/clipPath.js +3 -4
  234. package/lib/property-handlers/color.d.ts +1 -1
  235. package/lib/property-handlers/dimension.d.ts +1 -1
  236. package/lib/property-handlers/dimension.js +6 -9
  237. package/lib/property-handlers/filter.d.ts +1 -1
  238. package/lib/property-handlers/index.d.ts +5 -4
  239. package/lib/property-handlers/index.js +14 -0
  240. package/lib/property-handlers/localPosition.d.ts +1 -1
  241. package/lib/property-handlers/localPosition.js +1 -7
  242. package/lib/property-handlers/offsetDistance.d.ts +1 -1
  243. package/lib/property-handlers/offsetPath.d.ts +1 -1
  244. package/lib/property-handlers/origin.d.ts +1 -1
  245. package/lib/property-handlers/origin.js +10 -2
  246. package/lib/property-handlers/path.d.ts +2 -2
  247. package/lib/property-handlers/path.js +8 -4
  248. package/lib/property-handlers/points.d.ts +1 -1
  249. package/lib/property-handlers/transform.d.ts +1 -1
  250. package/lib/property-handlers/zIndex.d.ts +1 -1
  251. package/lib/services/ContextService.d.ts +3 -2
  252. package/lib/services/EventService.d.ts +18 -13
  253. package/lib/services/EventService.js +616 -385
  254. package/lib/services/RenderingContext.d.ts +1 -1
  255. package/lib/services/RenderingService.d.ts +23 -29
  256. package/lib/services/RenderingService.js +66 -56
  257. package/lib/services/SceneGraphSelector.d.ts +7 -7
  258. package/lib/services/SceneGraphSelector.js +10 -6
  259. package/lib/services/SceneGraphService.d.ts +73 -78
  260. package/lib/services/SceneGraphService.js +166 -79
  261. package/lib/services/aabb/PathUpdater.d.ts +1 -1
  262. package/lib/services/aabb/RectUpdater.d.ts +2 -2
  263. package/lib/services/aabb/interfaces.d.ts +1 -1
  264. package/lib/shapes/Point.d.ts +4 -0
  265. package/lib/shapes/Polygon.d.ts +9 -0
  266. package/lib/shapes/Polygon.js +69 -0
  267. package/lib/shapes/index.d.ts +1 -0
  268. package/lib/shapes/index.js +13 -0
  269. package/lib/types.d.ts +18 -6
  270. package/lib/utils/animation.d.ts +1 -2
  271. package/lib/utils/animation.js +8 -16
  272. package/lib/utils/canvas.d.ts +1 -1
  273. package/lib/utils/custom-easing.d.ts +3 -2
  274. package/lib/utils/custom-easing.js +16 -8
  275. package/lib/utils/event.js +1 -1
  276. package/lib/utils/index.d.ts +1 -0
  277. package/lib/utils/index.js +13 -0
  278. package/lib/utils/interpolation.d.ts +3 -4
  279. package/lib/utils/interpolation.js +0 -17
  280. package/lib/utils/path.d.ts +2 -2
  281. package/package.json +6 -6
  282. package/es/Batch.d.ts +0 -25
  283. package/es/Batch.js +0 -82
  284. package/es/shapes-type.d.ts +0 -175
  285. package/es/shapes-type.js +0 -18
  286. package/es/utils/matrix-decompose.d.ts +0 -3
  287. package/es/utils/matrix-decompose.js +0 -404
  288. package/lib/Batch.d.ts +0 -25
  289. package/lib/Batch.js +0 -91
  290. package/lib/shapes-type.d.ts +0 -175
  291. package/lib/shapes-type.js +0 -41
  292. package/lib/utils/matrix-decompose.d.ts +0 -3
  293. package/lib/utils/matrix-decompose.js +0 -414
@@ -1,39 +1,58 @@
1
- import { Canvas } from '../Canvas';
2
1
  import { Node } from './Node';
3
- import { AnimationTimeline } from '../Timeline';
4
- import { Group } from '../display-objects';
5
- import { DisplayObject } from '../DisplayObject';
2
+ import { AnimationTimeline } from './AnimationTimeline';
3
+ import { Group, DisplayObject } from '../display-objects';
4
+ import type { IDocument, IElement, INode, ICanvas, DisplayObjectConfig } from './interfaces';
5
+ import { BaseStyleProps } from '../types';
6
6
  /**
7
7
  * the entry of DOM tree
8
8
  * Document -> Node -> EventTarget
9
9
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Document
10
10
  */
11
- export declare class Document extends Node {
11
+ export declare class Document extends Node implements IDocument {
12
12
  constructor();
13
+ get children(): IElement[];
14
+ get childElementCount(): number;
15
+ get firstElementChild(): IElement | null;
16
+ get lastElementChild(): IElement | null;
13
17
  /**
14
18
  * only document has defaultView, points to canvas,
15
19
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/defaultView
16
20
  */
17
- defaultView: Canvas | null;
21
+ defaultView: ICanvas | null;
18
22
  /**
19
23
  * the root element of document, eg. <html>
20
24
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/documentElement
21
25
  */
22
- documentElement: Group;
26
+ readonly documentElement: Group;
23
27
  /**
24
28
  * document.timeline in WAAPI
25
29
  */
26
- timeline: AnimationTimeline;
30
+ readonly timeline: AnimationTimeline;
31
+ readonly ownerDocument: any;
32
+ /**
33
+ * @example const circle = document.createElement('circle', { style: { r: 10 } });
34
+ */
35
+ createElement<T extends DisplayObject<StyleProps>, StyleProps extends BaseStyleProps>(tagName: string, options: DisplayObjectConfig<StyleProps>): T;
36
+ cloneNode(deep?: boolean): INode;
37
+ destroy(): void;
27
38
  /**
28
39
  * eg. Uncaught DOMException: Failed to execute 'appendChild' on 'Node': Only one element on document allowed.
29
40
  */
30
- appendChild(child: this, index?: number): this;
31
- insertBefore(child: this, reference?: this): this;
32
- removeChild(child: this, destroy?: boolean): this;
33
- getElementById(id: string): DisplayObject | null;
34
- getElementsByName(name: string): DisplayObject[];
35
- getElementsByClassName(className: string): DisplayObject[];
36
- getElementsByTagName(tagName: string): DisplayObject[];
37
- querySelector(selector: string): DisplayObject | null;
38
- querySelectorAll(selector: string): DisplayObject[];
41
+ appendChild<T extends INode>(newChild: T, index?: number): T;
42
+ insertBefore<T extends INode>(newChild: T, refChild: INode | null): T;
43
+ removeChild<T extends INode>(oldChild: T, destroy?: boolean): T;
44
+ replaceChild<T extends INode>(newChild: INode, oldChild: T, destroy?: boolean): T;
45
+ append(...nodes: INode[]): void;
46
+ prepend(...nodes: INode[]): void;
47
+ /**
48
+ * Execute query on documentElement.
49
+ */
50
+ getElementById<E extends IElement = IElement>(id: string): E | null;
51
+ getElementsByName<E extends IElement = IElement>(name: string): E[];
52
+ getElementsByTagName<E extends IElement = IElement>(tagName: string): E[];
53
+ getElementsByClassName<E extends IElement = IElement>(className: string): E[];
54
+ querySelector<E extends IElement = IElement>(selectors: string): E | null;
55
+ querySelectorAll<E extends IElement = IElement>(selectors: string): E[];
56
+ find<E extends IElement = IElement>(filter: (node: E) => boolean): E | null;
57
+ findAll<E extends IElement = IElement>(filter: (node: E) => boolean): E[];
39
58
  }
@@ -9,7 +9,7 @@ var _tslib = require("tslib");
9
9
 
10
10
  var _Node = require("./Node");
11
11
 
12
- var _Timeline = require("../Timeline");
12
+ var _AnimationTimeline = require("./AnimationTimeline");
13
13
 
14
14
  var _displayObjects = require("../display-objects");
15
15
 
@@ -30,36 +30,112 @@ var Document = function (_super) {
30
30
 
31
31
 
32
32
  _this.defaultView = null;
33
- /**
34
- * document.timeline in WAAPI
35
- */
33
+ _this.ownerDocument = null;
34
+ _this.nodeName = 'document'; // create timeline
36
35
 
37
- _this.timeline = new _Timeline.AnimationTimeline(); // like <html> in DOM tree
36
+ _this.timeline = new _AnimationTimeline.AnimationTimeline(); // like <html> in DOM tree
38
37
 
39
38
  _this.documentElement = new _displayObjects.Group({
40
39
  id: 'g-root'
41
40
  });
42
- _this.nodeName = 'document';
41
+ _this.documentElement.ownerDocument = _this;
43
42
  _this.documentElement.parentNode = _this;
44
43
  _this.childNodes = [_this.documentElement];
45
44
  return _this;
46
45
  }
46
+
47
+ Object.defineProperty(Document.prototype, "children", {
48
+ get: function get() {
49
+ return this.childNodes;
50
+ },
51
+ enumerable: false,
52
+ configurable: true
53
+ });
54
+ Object.defineProperty(Document.prototype, "childElementCount", {
55
+ get: function get() {
56
+ return this.childNodes.length;
57
+ },
58
+ enumerable: false,
59
+ configurable: true
60
+ });
61
+ Object.defineProperty(Document.prototype, "firstElementChild", {
62
+ get: function get() {
63
+ return this.firstChild;
64
+ },
65
+ enumerable: false,
66
+ configurable: true
67
+ });
68
+ Object.defineProperty(Document.prototype, "lastElementChild", {
69
+ get: function get() {
70
+ return this.lastChild;
71
+ },
72
+ enumerable: false,
73
+ configurable: true
74
+ });
75
+ /**
76
+ * @example const circle = document.createElement('circle', { style: { r: 10 } });
77
+ */
78
+
79
+ Document.prototype.createElement = function (tagName, options) {
80
+ var clazz = this.defaultView.customElements.get(tagName);
81
+ return new clazz(options);
82
+ };
83
+
84
+ Document.prototype.cloneNode = function (deep) {
85
+ throw new Error('Method not implemented.');
86
+ };
87
+
88
+ Document.prototype.destroy = function () {
89
+ try {
90
+ this.documentElement.destroy();
91
+ } catch (e) {}
92
+
93
+ this.timeline.destroy();
94
+ };
47
95
  /**
48
96
  * eg. Uncaught DOMException: Failed to execute 'appendChild' on 'Node': Only one element on document allowed.
49
97
  */
50
98
 
51
99
 
52
- Document.prototype.appendChild = function (child, index) {
100
+ Document.prototype.appendChild = function (newChild, index) {
101
+ throw new Error('Use document.documentElement instead.');
102
+ };
103
+
104
+ Document.prototype.insertBefore = function (newChild, refChild) {
105
+ throw new Error('Use document.documentElement instead.');
106
+ };
107
+
108
+ Document.prototype.removeChild = function (oldChild, destroy) {
109
+ throw new Error('Use document.documentElement instead.');
110
+ };
111
+
112
+ Document.prototype.replaceChild = function (newChild, oldChild, destroy) {
53
113
  throw new Error('Use document.documentElement instead.');
54
114
  };
55
115
 
56
- Document.prototype.insertBefore = function (child, reference) {
116
+ Document.prototype.append = function () {
117
+ var nodes = [];
118
+
119
+ for (var _i = 0; _i < arguments.length; _i++) {
120
+ nodes[_i] = arguments[_i];
121
+ }
122
+
57
123
  throw new Error('Use document.documentElement instead.');
58
124
  };
59
125
 
60
- Document.prototype.removeChild = function (child, destroy) {
126
+ Document.prototype.prepend = function () {
127
+ var nodes = [];
128
+
129
+ for (var _i = 0; _i < arguments.length; _i++) {
130
+ nodes[_i] = arguments[_i];
131
+ }
132
+
61
133
  throw new Error('Use document.documentElement instead.');
62
134
  };
135
+ /**
136
+ * Execute query on documentElement.
137
+ */
138
+
63
139
 
64
140
  Document.prototype.getElementById = function (id) {
65
141
  return this.documentElement.getElementById(id);
@@ -69,20 +145,28 @@ var Document = function (_super) {
69
145
  return this.documentElement.getElementsByName(name);
70
146
  };
71
147
 
148
+ Document.prototype.getElementsByTagName = function (tagName) {
149
+ return this.documentElement.getElementsByTagName(tagName);
150
+ };
151
+
72
152
  Document.prototype.getElementsByClassName = function (className) {
73
153
  return this.documentElement.getElementsByClassName(className);
74
154
  };
75
155
 
76
- Document.prototype.getElementsByTagName = function (tagName) {
77
- return this.documentElement.getElementsByTagName(tagName);
156
+ Document.prototype.querySelector = function (selectors) {
157
+ return this.documentElement.querySelector(selectors);
158
+ };
159
+
160
+ Document.prototype.querySelectorAll = function (selectors) {
161
+ return this.documentElement.querySelectorAll(selectors);
78
162
  };
79
163
 
80
- Document.prototype.querySelector = function (selector) {
81
- return this.documentElement.querySelector(selector);
164
+ Document.prototype.find = function (filter) {
165
+ return this.documentElement.find(filter);
82
166
  };
83
167
 
84
- Document.prototype.querySelectorAll = function (selector) {
85
- return this.documentElement.querySelectorAll(selector);
168
+ Document.prototype.findAll = function (filter) {
169
+ return this.documentElement.findAll(filter);
86
170
  };
87
171
 
88
172
  return Document;
@@ -1,42 +1,33 @@
1
1
  import { SceneGraphService } from '../services';
2
- import type { BaseStyleProps, ParsedBaseStyleProps } from '../types';
2
+ import { BaseStyleProps, ParsedBaseStyleProps } from '../types';
3
3
  import { Node } from './Node';
4
- import type { Animation } from '../Animation';
5
4
  import { AABB, Rectangle } from '../shapes';
5
+ import type { DisplayObjectConfig, IEventTarget, IChildNode, IElement, INode } from './interfaces';
6
6
  /**
7
- * events for display object
7
+ * built-in events for element
8
8
  */
9
- export declare enum DISPLAY_OBJECT_EVENT {
10
- Init = "init",
11
- Destroy = "destroy",
12
- AttributeChanged = "attributeChanged",
9
+ export declare enum ElementEvent {
10
+ DESTROY = "destroy",
11
+ ATTRIBUTE_CHANGED = "attribute-changed",
13
12
  /**
14
13
  * it has been inserted
15
14
  */
16
- Inserted = "inserted",
15
+ INSERTED = "inserted",
17
16
  /**
18
17
  * it has had a child inserted
19
18
  */
20
- ChildInserted = "child-inserted",
19
+ CHILD_INSERTED = "child-inserted",
21
20
  /**
22
21
  * it has been removed
23
22
  */
24
- Removed = "removed",
23
+ REMOVED = "removed",
25
24
  /**
26
25
  * it has had a child removed
27
26
  */
28
- ChildRemoved = "child-removed"
29
- }
30
- export interface ElementConfig<StyleProps> {
31
- /**
32
- * element's identifier, must be unique in a document.
33
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/id
34
- */
35
- id?: string;
36
- name?: string;
37
- className?: string;
38
- attributes?: StyleProps;
39
- type?: string;
27
+ CHILD_REMOVED = "child-removed",
28
+ MOUNTED = "mounted",
29
+ UNMOUNTED = "unmounted",
30
+ BOUNDS_CHANGED = "bounds-changed"
40
31
  }
41
32
  /**
42
33
  * Has following capabilities:
@@ -44,13 +35,10 @@ export interface ElementConfig<StyleProps> {
44
35
  * * Query eg. querySelector getElementById...
45
36
  * * Animation
46
37
  */
47
- export declare class Element<StyleProps extends BaseStyleProps = any, ParsedStyleProps extends ParsedBaseStyleProps = any> extends Node {
48
- /**
49
- * push to active animations after calling `animate()`
50
- */
51
- activeAnimations: Animation[];
52
- protected sceneGraphService: SceneGraphService;
53
- constructor();
38
+ export declare class Element<StyleProps extends BaseStyleProps = any, ParsedStyleProps extends ParsedBaseStyleProps = any> extends Node implements IElement<StyleProps, ParsedStyleProps> {
39
+ static isElement(target: IEventTarget | INode | IElement): target is IElement;
40
+ sceneGraphService: SceneGraphService;
41
+ constructor(config: DisplayObjectConfig<StyleProps>);
54
42
  /**
55
43
  * used with `getElementById()`
56
44
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/id
@@ -71,104 +59,72 @@ export declare class Element<StyleProps extends BaseStyleProps = any, ParsedStyl
71
59
  */
72
60
  get classList(): string[];
73
61
  interactive: boolean;
74
- appendChild(child: this, index?: number): this;
75
- insertBefore(group: this, reference?: this): this;
76
- removeChild(child: this, destroy?: boolean): this;
77
- removeChildren(destroy?: boolean): void;
78
- get children(): this[];
62
+ scrollLeft: number;
63
+ scrollTop: number;
64
+ get tagName(): string;
65
+ get children(): IElement[];
79
66
  get childElementCount(): number;
80
- get firstElementChild(): this | null;
81
- get lastElementChild(): this | null;
67
+ get firstElementChild(): IElement | null;
68
+ get lastElementChild(): IElement | null;
69
+ get parentElement(): IElement | null;
70
+ get nextSibling(): IElement | null;
71
+ get previousSibling(): IElement | null;
72
+ cloneNode(deep?: boolean): this;
73
+ appendChild<T extends INode>(child: T, index?: number): T;
74
+ insertBefore<T extends INode>(newChild: T, refChild: IElement | null): T;
75
+ replaceChild<T extends INode & IChildNode>(newChild: INode, oldChild: T, destroy?: boolean): T;
76
+ removeChild<T extends INode>(child: T, destroy?: boolean): T;
77
+ removeChildren(destroy?: boolean): void;
82
78
  /**
83
79
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/matches
84
80
  */
85
81
  matches(selector: string): boolean;
86
- getElementById(id: string): this | null;
87
- getElementsByName(name: string): this[];
88
- getElementsByClassName(className: string): this[];
89
- getElementsByTagName(tagName: string): this[];
90
- querySelector(selector: string): this | null;
91
- querySelectorAll(selector: string): this[];
92
- /**
93
- * traverse in descendants
94
- */
95
- forEach(callback: (o: this) => void | boolean): void;
82
+ getElementById<E extends IElement = IElement>(id: string): E | null;
83
+ getElementsByName<E extends IElement = IElement>(name: string): E[];
84
+ getElementsByClassName<E extends IElement = IElement>(className: string): E[];
85
+ getElementsByTagName<E extends IElement = IElement>(tagName: string): E[];
86
+ querySelector<E extends IElement = IElement>(selectors: string): E | null;
87
+ querySelectorAll<E extends IElement = IElement>(selectors: string): E[];
96
88
  /**
97
89
  * search in scene group, but should not include itself
98
90
  */
99
- find(filter: (node: this) => boolean): this | null;
100
- findAll(filter: (node: this) => boolean): this[];
101
- /**
102
- * compatible with `style`
103
- * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style
104
- */
105
- style: StyleProps;
106
- parsedStyle: ParsedStyleProps;
107
- /**
108
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/attributes
109
- */
110
- attributes: StyleProps;
111
- /**
112
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute
113
- */
114
- getAttribute(attributeName: keyof StyleProps): StyleProps[keyof StyleProps];
115
- /**
116
- * should use removeAttribute() instead of setting the attribute value to null either directly or using setAttribute(). Many attributes will not behave as expected if you set them to null.
117
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute
118
- */
119
- removeAttribute(attributeName: keyof StyleProps): void;
120
- /**
121
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute
122
- */
123
- setAttribute<Key extends keyof StyleProps>(attributeName: Key, value: StyleProps[Key], force?: boolean): void;
91
+ find<E extends IElement = IElement>(filter: (node: E) => boolean): E | null;
92
+ findAll<E extends IElement = IElement>(filter: (node: E) => boolean): E[];
124
93
  /**
125
94
  * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/after
126
95
  */
127
- after(...nodes: this[]): void;
96
+ after(...nodes: IElement[]): void;
128
97
  /**
129
98
  * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/before
130
99
  */
131
- before(...nodes: this[]): void;
100
+ before(...nodes: IElement[]): void;
132
101
  /**
133
102
  * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/replaceWith
134
103
  */
135
- replaceWith(...nodes: this[]): void;
104
+ replaceWith(...nodes: IElement[]): void;
136
105
  /**
137
106
  * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/append
138
107
  */
139
- append(...nodes: this[]): void;
108
+ append(...nodes: IElement[]): void;
140
109
  /**
141
110
  * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/prepend
142
111
  */
143
- prepend(...nodes: this[]): void;
112
+ prepend(...nodes: IElement[]): void;
144
113
  /**
145
114
  * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/replaceChildren
146
115
  */
147
- replaceChildren(...nodes: this[]): void;
116
+ replaceChildren(...nodes: IElement[]): void;
148
117
  /**
149
118
  * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/remove
150
119
  */
151
- remove(destroy?: boolean): Node;
152
- /**
153
- * @override
154
- */
155
- protected changeAttribute<Key extends keyof StyleProps>(name: Key, value: StyleProps[Key]): void;
120
+ remove(destroy?: boolean): this;
156
121
  /**
157
122
  * is destroyed or not
158
123
  */
159
124
  destroyed: boolean;
160
125
  destroy(): void;
161
- /**
162
- * returns an array of all Animation objects affecting this element
163
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAnimations
164
- */
165
- getAnimations(): Animation[];
166
- /**
167
- * create an animation with WAAPI
168
- * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/animate
169
- */
170
- animate(keyframes: Keyframe[] | PropertyIndexedKeyframes | null, options?: number | KeyframeAnimationOptions | undefined): Animation | null;
171
126
  getGeometryBounds(): AABB | null;
127
+ getRenderBounds(): AABB | null;
172
128
  /**
173
129
  * get bounds in world space, account for children
174
130
  */
@@ -187,4 +143,27 @@ export declare class Element<StyleProps extends BaseStyleProps = any, ParsedStyl
187
143
  * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Element/getClientRects
188
144
  */
189
145
  getClientRects(): Rectangle[];
146
+ /**
147
+ * compatible with `style`
148
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style
149
+ */
150
+ style: StyleProps;
151
+ parsedStyle: ParsedStyleProps;
152
+ /**
153
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/attributes
154
+ */
155
+ attributes: StyleProps;
156
+ /**
157
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute
158
+ */
159
+ getAttribute(attributeName: keyof StyleProps): StyleProps[keyof StyleProps];
160
+ /**
161
+ * should use removeAttribute() instead of setting the attribute value to null either directly or using setAttribute(). Many attributes will not behave as expected if you set them to null.
162
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute
163
+ */
164
+ removeAttribute(attributeName: keyof StyleProps): void;
165
+ /**
166
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute
167
+ */
168
+ setAttribute<Key extends keyof StyleProps>(attributeName: Key, value: StyleProps[Key], force?: boolean): void;
190
169
  }