@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
package/es/Canvas.d.ts CHANGED
@@ -1,23 +1,28 @@
1
1
  import { CanvasConfig } from './types';
2
- import { DisplayObject } from './DisplayObject';
2
+ import { DisplayObject } from './display-objects/DisplayObject';
3
3
  import { ContextService } from './services';
4
4
  import { RenderingService } from './services/RenderingService';
5
5
  import { RenderingContext } from './services/RenderingContext';
6
6
  import { EventService } from './services/EventService';
7
+ import { Camera } from './camera';
7
8
  import { AbstractRenderer } from './AbstractRenderer';
8
- import { Point } from './shapes';
9
- import { EventTarget } from './dom/EventTarget';
10
- import { Document } from './dom/Document';
11
- export interface CanvasService {
12
- init(): void;
13
- destroy(): void;
9
+ import type { PointLike } from './shapes';
10
+ import { Document, EventTarget } from './dom';
11
+ import type { IElement, INode, ICanvas } from './dom/interfaces';
12
+ import { CustomElementRegistry } from './dom/CustomElementRegistry';
13
+ export declare enum CanvasEvent {
14
+ READY = "ready",
15
+ BEFORE_RENDER = "beforerender",
16
+ AFTER_RENDER = "afterrender",
17
+ BEFORE_DESTROY = "beforedestroy",
18
+ AFTER_DESTROY = "afterdestroy"
14
19
  }
15
20
  /**
16
21
  * can be treated like Window in DOM
17
22
  *
18
23
  * prototype chains: Canvas(Window) -> EventTarget
19
24
  */
20
- export declare class Canvas extends EventTarget {
25
+ export declare class Canvas extends EventTarget implements ICanvas {
21
26
  /**
22
27
  * child container of current canvas, use hierarchy container
23
28
  */
@@ -26,6 +31,10 @@ export declare class Canvas extends EventTarget {
26
31
  * window.document
27
32
  */
28
33
  document: Document;
34
+ /**
35
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry
36
+ */
37
+ customElements: CustomElementRegistry;
29
38
  Element: typeof DisplayObject;
30
39
  /**
31
40
  * rAF in auto rendering
@@ -35,15 +44,16 @@ export declare class Canvas extends EventTarget {
35
44
  private initRenderingContext;
36
45
  private initDefaultCamera;
37
46
  getConfig(): Partial<CanvasConfig>;
47
+ getContainer(): import("inversify/lib/container/container").Container;
38
48
  /**
39
49
  * get the root displayObject in scenegraph
40
50
  * @alias this.document.documentElement
41
51
  */
42
- getRoot(): import("./display-objects").Group;
52
+ getRoot(): import(".").Group;
43
53
  /**
44
54
  * get the camera of canvas
45
55
  */
46
- getCamera(): unknown;
56
+ getCamera(): Camera;
47
57
  getContextService(): ContextService<unknown>;
48
58
  getEventService(): EventService;
49
59
  getRenderingService(): RenderingService;
@@ -52,14 +62,15 @@ export declare class Canvas extends EventTarget {
52
62
  destroy(destroyScenegraph?: boolean): void;
53
63
  /**
54
64
  * compatible with G 3.0
65
+ * @deprecated
66
+ * @alias resize
55
67
  */
56
68
  changeSize(width: number, height: number): void;
57
69
  resize(width: number, height: number): void;
58
- appendChild(node: DisplayObject): import("./display-objects").Group;
59
- insertBefore(group: DisplayObject, reference?: DisplayObject): DisplayObject;
60
- removeChild(node: DisplayObject, destroy?: boolean): import("./display-objects").Group;
61
- removeChildren(): void;
62
- decorate(object: DisplayObject, renderingService: RenderingService, root: DisplayObject): void;
70
+ appendChild<T extends INode>(child: T, index?: number): T;
71
+ insertBefore<T extends INode>(newChild: T, refChild: IElement | null): T;
72
+ removeChild<T extends INode>(child: T, destroy?: boolean): T;
73
+ removeChildren(destroy?: boolean): void;
63
74
  render(): void;
64
75
  private run;
65
76
  private initRenderer;
@@ -68,7 +79,18 @@ export declare class Canvas extends EventTarget {
68
79
  setRenderer(renderer: AbstractRenderer): void;
69
80
  private unmountChildren;
70
81
  private mountChildren;
71
- private mountChild;
72
- getPointByClient(clientX: number, clientY: number): Point;
73
- getClientByPoint(x: number, y: number): Point;
82
+ client2Viewport(client: PointLike): PointLike;
83
+ viewport2Client(canvas: PointLike): PointLike;
84
+ viewport2Canvas(viewport: PointLike): PointLike;
85
+ canvas2Viewport(canvas: PointLike): PointLike;
86
+ /**
87
+ * @deprecated
88
+ * @alias client2Viewport
89
+ */
90
+ getPointByClient(clientX: number, clientY: number): PointLike;
91
+ /**
92
+ * @deprecated
93
+ * @alias viewport2Client
94
+ */
95
+ getClientByPoint(x: number, y: number): PointLike;
74
96
  }
package/es/Canvas.js CHANGED
@@ -1,25 +1,34 @@
1
1
  import { __assign, __extends } from "tslib";
2
2
  import { CanvasConfig } from './types';
3
3
  import { cleanExistedCanvas } from './utils/canvas';
4
- import { DisplayObject } from './DisplayObject';
4
+ import { DisplayObject } from './display-objects/DisplayObject';
5
5
  import { ContextService } from './services';
6
6
  import { container } from './inversify.config';
7
7
  import { RenderingService } from './services/RenderingService';
8
8
  import { RenderingContext, RENDER_REASON } from './services/RenderingContext';
9
9
  import { EventService } from './services/EventService';
10
- import { Camera, CAMERA_EVENT, CAMERA_PROJECTION_MODE, DefaultCamera } from './Camera';
10
+ import { Camera, CAMERA_EVENT, CAMERA_PROJECTION_MODE, DefaultCamera } from './camera';
11
11
  import { containerModule as commonContainerModule } from './canvas-module';
12
12
  import { cancelAnimationFrame } from './utils/raf';
13
- import { Point } from './shapes';
14
- import { DISPLAY_OBJECT_EVENT } from './dom/Element';
15
- import { EventTarget } from './dom/EventTarget';
16
- import { Document } from './dom/Document';
13
+ import { Document, EventTarget, ElementEvent } from './dom';
14
+ import { CustomElementRegistry } from './dom/CustomElementRegistry';
15
+ import { Renderable } from './components';
16
+ export var CanvasEvent;
17
+
18
+ (function (CanvasEvent) {
19
+ CanvasEvent["READY"] = "ready";
20
+ CanvasEvent["BEFORE_RENDER"] = "beforerender";
21
+ CanvasEvent["AFTER_RENDER"] = "afterrender";
22
+ CanvasEvent["BEFORE_DESTROY"] = "beforedestroy";
23
+ CanvasEvent["AFTER_DESTROY"] = "afterdestroy";
24
+ })(CanvasEvent || (CanvasEvent = {}));
17
25
  /**
18
26
  * can be treated like Window in DOM
19
27
  *
20
28
  * prototype chains: Canvas(Window) -> EventTarget
21
29
  */
22
30
 
31
+
23
32
  var Canvas = function (_super) {
24
33
  __extends(Canvas, _super);
25
34
 
@@ -48,20 +57,33 @@ var Canvas = function (_super) {
48
57
  }
49
58
 
50
59
  Canvas.prototype.initRenderingContext = function (mergedConfig) {
60
+ var _this = this;
61
+
51
62
  this.container.bind(CanvasConfig).toConstantValue(mergedConfig);
52
63
  this.document = new Document();
53
- this.document.defaultView = this; // bind rendering context, shared by all renderers
64
+ this.document.defaultView = this;
65
+ this.customElements = new CustomElementRegistry(); // bind rendering context, shared by all renderers
54
66
 
55
67
  this.container.bind(RenderingContext).toConstantValue({
56
68
  /**
57
69
  * the root node in scene graph
58
70
  */
59
71
  root: this.document.documentElement,
60
- removedAABBs: [],
72
+
73
+ /**
74
+ * removed render bounds
75
+ */
76
+ removedRenderBoundsList: [],
61
77
  renderReasons: new Set(),
62
78
  force: false,
63
79
  dirty: false
64
80
  });
81
+ this.document.documentElement.addEventListener(ElementEvent.CHILD_INSERTED, function (e) {
82
+ _this.mountChildren(e.detail.child);
83
+ });
84
+ this.document.documentElement.addEventListener(ElementEvent.CHILD_REMOVED, function (e) {
85
+ _this.unmountChildren(e.detail.child);
86
+ });
65
87
  };
66
88
 
67
89
  Canvas.prototype.initDefaultCamera = function (width, height) {
@@ -80,6 +102,10 @@ var Canvas = function (_super) {
80
102
  Canvas.prototype.getConfig = function () {
81
103
  return this.container.get(CanvasConfig);
82
104
  };
105
+
106
+ Canvas.prototype.getContainer = function () {
107
+ return this.container;
108
+ };
83
109
  /**
84
110
  * get the root displayObject in scenegraph
85
111
  * @alias this.document.documentElement
@@ -119,13 +145,11 @@ var Canvas = function (_super) {
119
145
  };
120
146
 
121
147
  Canvas.prototype.destroy = function (destroyScenegraph) {
122
- var _this = this;
123
-
124
148
  if (destroyScenegraph === void 0) {
125
149
  destroyScenegraph = true;
126
150
  }
127
151
 
128
- this.emit('beforedestroy', function () {});
152
+ this.emit(CanvasEvent.BEFORE_DESTROY, function () {});
129
153
 
130
154
  if (this.frameId) {
131
155
  cancelAnimationFrame(this.frameId);
@@ -133,25 +157,22 @@ var Canvas = function (_super) {
133
157
 
134
158
 
135
159
  var root = this.getRoot();
136
- var renderingService = this.container.get(RenderingService);
160
+ this.unmountChildren(root);
137
161
 
138
162
  if (destroyScenegraph) {
139
- root.forEach(function (child) {
140
- _this.removeChild(child, true);
141
- }); // destroy timeline
142
-
143
- this.document.timeline.destroy();
144
- } else {
145
- this.unmountChildren(root);
163
+ // destroy Document
164
+ this.document.destroy();
146
165
  } // destroy services
147
166
 
148
167
 
149
168
  this.getContextService().destroy();
150
- renderingService.destroy();
151
- this.emit('afterdestroy', {});
169
+ this.getRenderingService().destroy();
170
+ this.emit(CanvasEvent.AFTER_DESTROY, {});
152
171
  };
153
172
  /**
154
173
  * compatible with G 3.0
174
+ * @deprecated
175
+ * @alias resize
155
176
  */
156
177
 
157
178
 
@@ -178,46 +199,39 @@ var Canvas = function (_super) {
178
199
  }; // proxy to document.documentElement
179
200
 
180
201
 
181
- Canvas.prototype.appendChild = function (node) {
182
- return this.document.documentElement.appendChild(node);
202
+ Canvas.prototype.appendChild = function (child, index) {
203
+ return this.document.documentElement.appendChild(child, index);
183
204
  };
184
205
 
185
- Canvas.prototype.insertBefore = function (group, reference) {
186
- return this.document.documentElement.insertBefore(group, reference);
206
+ Canvas.prototype.insertBefore = function (newChild, refChild) {
207
+ return this.document.documentElement.insertBefore(newChild, refChild);
187
208
  };
188
209
 
189
- Canvas.prototype.removeChild = function (node, destroy) {
190
- return this.document.documentElement.removeChild(node, destroy);
191
- };
210
+ Canvas.prototype.removeChild = function (child, destroy) {
211
+ if (destroy === void 0) {
212
+ destroy = true;
213
+ }
192
214
 
193
- Canvas.prototype.removeChildren = function () {
194
- this.document.documentElement.removeChildren();
215
+ return this.document.documentElement.removeChild(child, destroy);
195
216
  };
196
217
 
197
- Canvas.prototype.decorate = function (object, renderingService, root) {
198
- var _this = this;
199
-
200
- object.forEach(function (child) {
201
- _this.mountChild(child);
218
+ Canvas.prototype.removeChildren = function (destroy) {
219
+ if (destroy === void 0) {
220
+ destroy = true;
221
+ }
202
222
 
203
- child.on(DISPLAY_OBJECT_EVENT.ChildInserted, function (grandchild) {
204
- return _this.decorate(grandchild, renderingService, root);
205
- });
206
- child.on(DISPLAY_OBJECT_EVENT.ChildRemoved, function (grandchild) {
207
- return _this.unmountChildren(grandchild);
208
- });
209
- });
223
+ this.document.documentElement.removeChildren(destroy);
210
224
  };
211
225
 
212
226
  Canvas.prototype.render = function () {
213
- this.emit('beforerender', {});
227
+ this.emit(CanvasEvent.BEFORE_RENDER, {});
214
228
 
215
229
  if (this.container.isBound(RenderingService)) {
216
230
  var renderingService = this.container.get(RenderingService);
217
231
  renderingService.render();
218
232
  }
219
233
 
220
- this.emit('afterrender', {});
234
+ this.emit(CanvasEvent.AFTER_RENDER, {});
221
235
  };
222
236
 
223
237
  Canvas.prototype.run = function () {
@@ -233,6 +247,8 @@ var Canvas = function (_super) {
233
247
  };
234
248
 
235
249
  Canvas.prototype.initRenderer = function (renderer) {
250
+ var _this = this;
251
+
236
252
  if (!renderer) {
237
253
  throw new Error('Renderer is required.');
238
254
  }
@@ -244,12 +260,23 @@ var Canvas = function (_super) {
244
260
  var contextService = this.container.get(ContextService);
245
261
  var renderingService = this.container.get(RenderingService);
246
262
  contextService.init();
247
- renderingService.init();
263
+ renderingService.init().then(function () {
264
+ _this.emit(CanvasEvent.READY, {});
265
+ });
248
266
 
249
267
  if (renderer.getConfig().enableAutoRendering) {
250
268
  this.run();
251
- } // keep current scenegraph unchanged, just trigger mounted event
269
+ }
270
+
271
+ this.getRoot().forEach(function (node) {
272
+ var renderable = node.entity.getComponent(Renderable);
252
273
 
274
+ if (renderable) {
275
+ renderable.renderBoundsDirty = true;
276
+ renderable.boundsDirty = true;
277
+ renderable.dirty = true; // element.emit(ElementEvent.BOUNDS_CHANGED, {});
278
+ }
279
+ }); // keep current scenegraph unchanged, just trigger mounted event
253
280
 
254
281
  this.mountChildren(this.getRoot());
255
282
  };
@@ -290,14 +317,18 @@ var Canvas = function (_super) {
290
317
  this.initRenderer(renderer);
291
318
  };
292
319
 
293
- Canvas.prototype.unmountChildren = function (node) {
294
- var renderingService = this.container.get(RenderingService);
295
- node.forEach(function (child) {
320
+ Canvas.prototype.unmountChildren = function (parent) {
321
+ var path = [];
322
+ parent.forEach(function (child) {
296
323
  if (child.isConnected) {
297
- renderingService.hooks.unmounted.call(child);
298
- child.isConnected = false;
299
- child.ownerDocument = null;
324
+ path.push(child);
300
325
  }
326
+ }); // unmount from leaf to root
327
+
328
+ path.reverse().forEach(function (child) {
329
+ child.emit(ElementEvent.UNMOUNTED, {});
330
+ child.ownerDocument = null;
331
+ child.isConnected = false;
301
332
  });
302
333
  };
303
334
 
@@ -305,28 +336,53 @@ var Canvas = function (_super) {
305
336
  var _this = this;
306
337
 
307
338
  parent.forEach(function (child) {
308
- _this.mountChild(child);
339
+ if (!child.isConnected) {
340
+ child.ownerDocument = _this.document;
341
+ child.isConnected = true;
342
+ debugger;
343
+ child.emit(ElementEvent.MOUNTED, {});
344
+ }
309
345
  });
310
346
  };
311
347
 
312
- Canvas.prototype.mountChild = function (child) {
313
- // trigger mount on node's descendants
314
- if (!child.isConnected) {
315
- var renderingService = this.container.get(RenderingService);
316
- child.ownerDocument = this.document;
317
- renderingService.hooks.mounted.call(child);
318
- child.isConnected = true;
319
- }
348
+ Canvas.prototype.client2Viewport = function (client) {
349
+ return this.getEventService().client2Viewport(client);
320
350
  };
321
351
 
352
+ Canvas.prototype.viewport2Client = function (canvas) {
353
+ return this.getEventService().viewport2Client(canvas);
354
+ };
355
+
356
+ Canvas.prototype.viewport2Canvas = function (viewport) {
357
+ return this.getEventService().viewport2Canvas(viewport);
358
+ };
359
+
360
+ Canvas.prototype.canvas2Viewport = function (canvas) {
361
+ return this.getEventService().canvas2Viewport(canvas);
362
+ };
363
+ /**
364
+ * @deprecated
365
+ * @alias client2Viewport
366
+ */
367
+
368
+
322
369
  Canvas.prototype.getPointByClient = function (clientX, clientY) {
323
- var bbox = this.getContextService().getBoundingClientRect();
324
- return new Point(clientX - ((bbox === null || bbox === void 0 ? void 0 : bbox.left) || 0), clientY - ((bbox === null || bbox === void 0 ? void 0 : bbox.top) || 0));
370
+ return this.client2Viewport({
371
+ x: clientX,
372
+ y: clientY
373
+ });
325
374
  };
375
+ /**
376
+ * @deprecated
377
+ * @alias viewport2Client
378
+ */
379
+
326
380
 
327
381
  Canvas.prototype.getClientByPoint = function (x, y) {
328
- var bbox = this.getContextService().getBoundingClientRect();
329
- return new Point(x + ((bbox === null || bbox === void 0 ? void 0 : bbox.left) || 0), y + ((bbox === null || bbox === void 0 ? void 0 : bbox.top) || 0));
382
+ return this.viewport2Client({
383
+ x: x,
384
+ y: y
385
+ });
330
386
  };
331
387
 
332
388
  return Canvas;
@@ -1,6 +1,7 @@
1
- import type { DisplayObject } from './DisplayObject';
1
+ import type { DisplayObject } from './display-objects';
2
2
  export declare class DisplayObjectPool {
3
3
  private pool;
4
4
  getByName(name: string): DisplayObject;
5
5
  add(name: string, groupOrShape: DisplayObject): void;
6
+ remove(name: string): void;
6
7
  }
@@ -14,6 +14,10 @@ var DisplayObjectPool = function () {
14
14
  this.pool[name] = groupOrShape;
15
15
  };
16
16
 
17
+ DisplayObjectPool.prototype.remove = function (name) {
18
+ delete this.pool[name];
19
+ };
20
+
17
21
  DisplayObjectPool = __decorate([injectable()], DisplayObjectPool);
18
22
  return DisplayObjectPool;
19
23
  }();
@@ -1,7 +1,7 @@
1
1
  import { EventEmitter } from 'eventemitter3';
2
2
  import { mat4, vec3 } from 'gl-matrix';
3
- import Landmark from './Landmark';
4
- import { Frustum } from './shapes';
3
+ import { Landmark } from './Landmark';
4
+ import { Frustum } from '../shapes';
5
5
  export declare const DefaultCamera = "DefaultCamera";
6
6
  export declare enum CAMERA_TYPE {
7
7
  ORBITING = "ORBITING",
@@ -108,7 +108,8 @@ export declare class Camera extends EventEmitter {
108
108
  private rright;
109
109
  private top;
110
110
  private bottom;
111
- private perspective;
111
+ private projectionMatrix;
112
+ private projectionMatrixInverse;
112
113
  private jitteredProjectionMatrix;
113
114
  private view;
114
115
  private following;
@@ -131,8 +132,10 @@ export declare class Camera extends EventEmitter {
131
132
  clone(): Camera;
132
133
  getProjectionMode(): CAMERA_PROJECTION_MODE;
133
134
  getPerspective(): mat4;
135
+ getPerspectiveInverse(): mat4;
134
136
  getFrustum(): Frustum;
135
137
  getPosition(): vec3;
138
+ getFocalPoint(): vec3;
136
139
  getNear(): number;
137
140
  getFar(): number;
138
141
  getZoom(): number;
@@ -1,11 +1,10 @@
1
- import { __decorate, __extends } from "tslib";
1
+ import { __extends } from "tslib";
2
2
  import { EventEmitter } from 'eventemitter3';
3
3
  import { mat3, mat4, quat, vec3, vec4 } from 'gl-matrix';
4
- import { injectable } from 'inversify';
5
- import Landmark from './Landmark';
6
- import { Frustum } from './shapes';
7
- import { createVec3, getAngle } from './utils/math';
8
- import { requestAnimationFrame, cancelAnimationFrame } from './utils/raf';
4
+ import { Landmark } from './Landmark';
5
+ import { Frustum } from '../shapes';
6
+ import { createVec3, getAngle } from '../utils/math';
7
+ import { requestAnimationFrame, cancelAnimationFrame } from '../utils/raf';
9
8
  export var DefaultCamera = 'DefaultCamera';
10
9
  export var CAMERA_TYPE;
11
10
 
@@ -137,7 +136,8 @@ var Camera = function (_super) {
137
136
  _this.near = 0.1;
138
137
  _this.far = 10000;
139
138
  _this.aspect = 1;
140
- _this.perspective = mat4.create();
139
+ _this.projectionMatrix = mat4.create();
140
+ _this.projectionMatrixInverse = mat4.create();
141
141
  _this.jitteredProjectionMatrix = undefined;
142
142
  _this.following = undefined;
143
143
  _this.type = CAMERA_TYPE.EXPLORING;
@@ -161,10 +161,8 @@ var Camera = function (_super) {
161
161
  return _this;
162
162
  }
163
163
 
164
- Camera_1 = Camera;
165
-
166
164
  Camera.prototype.clone = function () {
167
- var camera = new Camera_1();
165
+ var camera = new Camera();
168
166
  camera.setType(this.type, undefined); // camera.interactor = this.interactor;
169
167
 
170
168
  return camera;
@@ -176,7 +174,11 @@ var Camera = function (_super) {
176
174
 
177
175
  Camera.prototype.getPerspective = function () {
178
176
  // account for TAA
179
- return this.jitteredProjectionMatrix || this.perspective;
177
+ return this.jitteredProjectionMatrix || this.projectionMatrix;
178
+ };
179
+
180
+ Camera.prototype.getPerspectiveInverse = function () {
181
+ return this.projectionMatrixInverse;
180
182
  };
181
183
 
182
184
  Camera.prototype.getFrustum = function () {
@@ -187,6 +189,10 @@ var Camera = function (_super) {
187
189
  return this.position;
188
190
  };
189
191
 
192
+ Camera.prototype.getFocalPoint = function () {
193
+ return this.focalPoint;
194
+ };
195
+
190
196
  Camera.prototype.getNear = function () {
191
197
  return this.near;
192
198
  };
@@ -268,7 +274,7 @@ var Camera = function (_super) {
268
274
 
269
275
  Camera.prototype.jitterProjectionMatrix = function (x, y) {
270
276
  var translation = mat4.fromTranslation(mat4.create(), [x, y, 0]);
271
- this.jitteredProjectionMatrix = mat4.multiply(mat4.create(), translation, this.perspective);
277
+ this.jitteredProjectionMatrix = mat4.multiply(mat4.create(), translation, this.projectionMatrix);
272
278
  };
273
279
 
274
280
  Camera.prototype.clearJitterProjectionMatrix = function () {
@@ -395,7 +401,8 @@ var Camera = function (_super) {
395
401
  // }
396
402
  // flip Y
397
403
 
398
- mat4.perspective(this.perspective, -this.fov * DEG_2_RAD, -this.aspect, this.near, this.far);
404
+ mat4.perspective(this.projectionMatrix, -this.fov * DEG_2_RAD, -this.aspect, this.near, this.far);
405
+ mat4.invert(this.projectionMatrixInverse, this.projectionMatrix);
399
406
  this.emit(CAMERA_EVENT.Updated);
400
407
  return this;
401
408
  };
@@ -426,7 +433,8 @@ var Camera = function (_super) {
426
433
  bottom = top - scaleH * this.view.height;
427
434
  }
428
435
 
429
- mat4.ortho(this.perspective, left, right, bottom, top, near, far);
436
+ mat4.ortho(this.projectionMatrix, left, right, bottom, top, near, far);
437
+ mat4.invert(this.projectionMatrixInverse, this.projectionMatrix);
430
438
 
431
439
  this._getOrthoMatrix();
432
440
 
@@ -943,12 +951,10 @@ var Camera = function (_super) {
943
951
  mat4.fromRotationTranslationScaleOrigin(this.orthoMatrix, rotZ, vec3.fromValues((this.rright - this.left) / 2 - position[0], (this.bottom - this.top) / 2 - position[1], 0), vec3.fromValues(this.zoom, this.zoom, 1), position);
944
952
  };
945
953
 
946
- var Camera_1;
947
954
  Camera.ProjectionMode = {
948
955
  ORTHOGRAPHIC: 'ORTHOGRAPHIC',
949
956
  PERSPECTIVE: 'PERSPECTIVE'
950
957
  };
951
- Camera = Camera_1 = __decorate([injectable()], Camera);
952
958
  return Camera;
953
959
  }(EventEmitter);
954
960
 
@@ -1,9 +1,9 @@
1
1
  import { vec3 } from 'gl-matrix';
2
- import { Camera } from './Camera';
2
+ import type { Camera } from './Camera';
3
3
  /**
4
4
  * 保存相机状态,便于后续在多个 Landmark 间移动
5
5
  */
6
- export default class Landmark {
6
+ export declare class Landmark {
7
7
  name: string;
8
8
  private matrix;
9
9
  private right;
@@ -63,4 +63,4 @@ var Landmark = function () {
63
63
  return Landmark;
64
64
  }();
65
65
 
66
- export default Landmark;
66
+ export { Landmark };
@@ -0,0 +1,2 @@
1
+ export * from './Camera';
2
+ export * from './Landmark';
@@ -0,0 +1,2 @@
1
+ export * from './Camera';
2
+ export * from './Landmark';
@@ -18,7 +18,7 @@ var Cullable = function (_super) {
18
18
 
19
19
  _this.strategy = Strategy.Standard;
20
20
  _this.visibilityPlaneMask = -1;
21
- _this.visible = false;
21
+ _this.visible = true;
22
22
  _this.enable = true;
23
23
  return _this;
24
24
  }
@@ -2,5 +2,12 @@ import { Component } from '@antv/g-ecs';
2
2
  import { AABB } from '../shapes';
3
3
  export declare class Geometry extends Component {
4
4
  static tag: string;
5
- aabb: AABB | undefined;
5
+ /**
6
+ * excluding all children
7
+ */
8
+ contentBounds: AABB | undefined;
9
+ /**
10
+ * including extra rendering effects, eg. shadowBlur filters(drop-shadow, blur)
11
+ */
12
+ renderBounds: AABB | undefined;
6
13
  }
@@ -7,18 +7,19 @@ export declare class Renderable extends Component {
7
7
  * 1. 包围盒会受 transform 影响。例如每次 transform 之后应该重新计算包围盒(center 发生偏移)。
8
8
  * 2. 多个 Mesh 可以共享一个 Geometry,但可以各自拥有不同的 aabb
9
9
  */
10
- aabb: AABB | undefined;
11
- aabbDirty: boolean;
10
+ bounds: AABB | undefined;
11
+ boundsDirty: boolean;
12
12
  /**
13
- * dirty rectangle(aabb) in last render frame
13
+ * account for hierarchy, also including extra rendering effects
14
14
  */
15
- dirtyAABB: AABB;
15
+ renderBounds: AABB | undefined;
16
+ renderBoundsDirty: boolean;
16
17
  /**
17
- * dirty rectangle flag
18
+ * dirty render bounds in last render frame
18
19
  */
19
- dirty: boolean;
20
+ dirtyRenderBounds: AABB;
20
21
  /**
21
- * is instanced
22
+ * dirty rectangle flag
22
23
  */
23
- instanced: boolean;
24
+ dirty: boolean;
24
25
  }