@antv/g 5.0.13 → 5.0.16

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 (244) hide show
  1. package/dist/index.umd.min.js +18 -2
  2. package/es/Canvas.d.ts +3 -0
  3. package/es/Canvas.js +9 -9
  4. package/es/camera/Camera.d.ts +3 -2
  5. package/es/camera/Camera.js +16 -8
  6. package/es/canvas-module.js +11 -17
  7. package/es/components/Transform.d.ts +0 -1
  8. package/es/components/Transform.js +0 -1
  9. package/es/display-objects/Circle.d.ts +4 -2
  10. package/es/display-objects/Circle.js +8 -3
  11. package/es/display-objects/CustomElement.d.ts +3 -2
  12. package/es/display-objects/CustomElement.js +9 -6
  13. package/es/display-objects/DisplayObject.d.ts +4 -3
  14. package/es/display-objects/DisplayObject.js +80 -49
  15. package/es/display-objects/Ellipse.d.ts +6 -3
  16. package/es/display-objects/Ellipse.js +8 -3
  17. package/es/display-objects/Group.d.ts +18 -2
  18. package/es/display-objects/Group.js +14 -9
  19. package/es/display-objects/HTML.d.ts +6 -1
  20. package/es/display-objects/HTML.js +10 -5
  21. package/es/display-objects/Image.d.ts +12 -7
  22. package/es/display-objects/Image.js +10 -3
  23. package/es/display-objects/Line.d.ts +1 -1
  24. package/es/display-objects/Line.js +12 -4
  25. package/es/display-objects/Path.d.ts +3 -2
  26. package/es/display-objects/Path.js +10 -5
  27. package/es/display-objects/Polygon.d.ts +1 -1
  28. package/es/display-objects/Polygon.js +9 -3
  29. package/es/display-objects/Polyline.d.ts +1 -1
  30. package/es/display-objects/Polyline.js +10 -5
  31. package/es/display-objects/Rect.d.ts +8 -5
  32. package/es/display-objects/Rect.js +9 -4
  33. package/es/display-objects/Text.d.ts +9 -6
  34. package/es/display-objects/Text.js +15 -10
  35. package/es/dom/Animation.js +1 -1
  36. package/es/dom/AnimationTimeline.js +1 -2
  37. package/es/dom/CustomElementRegistry.js +12 -12
  38. package/es/dom/Document.d.ts +1 -0
  39. package/es/dom/Document.js +21 -1
  40. package/es/dom/Element.d.ts +14 -9
  41. package/es/dom/Element.js +41 -14
  42. package/es/dom/EventTarget.d.ts +2 -2
  43. package/es/dom/EventTarget.js +4 -3
  44. package/es/dom/KeyframeList.js +1 -1
  45. package/es/dom/MutationEvent.d.ts +15 -0
  46. package/es/dom/MutationEvent.js +29 -0
  47. package/es/dom/MutationObserver.d.ts +36 -0
  48. package/es/dom/MutationObserver.js +413 -0
  49. package/es/dom/MutationRecord.d.ts +14 -0
  50. package/es/dom/MutationRecord.js +31 -0
  51. package/es/dom/Node.d.ts +35 -3
  52. package/es/dom/Node.js +184 -17
  53. package/es/dom/index.d.ts +3 -0
  54. package/es/dom/index.js +3 -0
  55. package/es/dom/interfaces.d.ts +36 -8
  56. package/es/dom/interfaces.js +23 -5
  57. package/es/global-module.d.ts +4 -1
  58. package/es/global-module.js +38 -80
  59. package/es/index.d.ts +1 -0
  60. package/es/index.js +1 -0
  61. package/es/plugins/CullingPlugin.d.ts +0 -2
  62. package/es/plugins/CullingPlugin.js +3 -24
  63. package/es/plugins/DirtyCheckPlugin.js +2 -2
  64. package/es/plugins/FrustumCullingStrategy.d.ts +1 -0
  65. package/es/plugins/FrustumCullingStrategy.js +40 -33
  66. package/es/plugins/PrepareRendererPlugin.js +21 -5
  67. package/es/property-handlers/aabb.js +22 -24
  68. package/es/property-handlers/anchor.js +2 -1
  69. package/es/property-handlers/color.js +5 -2
  70. package/es/property-handlers/dimension.d.ts +15 -2
  71. package/es/property-handlers/dimension.js +77 -8
  72. package/es/property-handlers/index.d.ts +3 -0
  73. package/es/property-handlers/index.js +4 -1
  74. package/es/property-handlers/inherit.d.ts +6 -0
  75. package/es/property-handlers/inherit.js +25 -0
  76. package/es/property-handlers/interfaces.d.ts +2 -2
  77. package/es/property-handlers/lineDash.d.ts +6 -1
  78. package/es/property-handlers/lineDash.js +23 -4
  79. package/es/property-handlers/offsetDistance.js +2 -2
  80. package/es/property-handlers/path.d.ts +1 -1
  81. package/es/property-handlers/text.d.ts +2 -0
  82. package/es/property-handlers/text.js +3 -0
  83. package/es/property-handlers/textTransform.d.ts +6 -0
  84. package/es/property-handlers/textTransform.js +19 -0
  85. package/es/services/EventService.js +3 -5
  86. package/es/services/RenderingContext.d.ts +5 -8
  87. package/es/services/RenderingContext.js +6 -7
  88. package/es/services/RenderingService.js +2 -8
  89. package/es/services/SceneGraphSelector.d.ts +3 -2
  90. package/es/services/SceneGraphSelector.js +8 -4
  91. package/es/services/SceneGraphService.d.ts +7 -14
  92. package/es/services/SceneGraphService.js +14 -82
  93. package/es/services/aabb/CircleUpdater.d.ts +2 -2
  94. package/es/services/aabb/CircleUpdater.js +21 -11
  95. package/es/services/aabb/EllipseUpdater.d.ts +2 -2
  96. package/es/services/aabb/EllipseUpdater.js +28 -13
  97. package/es/services/aabb/LineUpdater.js +2 -2
  98. package/es/services/aabb/PathUpdater.js +2 -2
  99. package/es/services/aabb/PolylineUpdater.js +3 -3
  100. package/es/services/aabb/RectUpdater.d.ts +2 -2
  101. package/es/services/aabb/RectUpdater.js +33 -17
  102. package/es/services/aabb/TextUpdater.js +19 -10
  103. package/es/services/aabb/interfaces.d.ts +1 -1
  104. package/es/services/aabb/interfaces.js +1 -1
  105. package/es/services/text/index.js +19 -21
  106. package/es/shapes/AABB.d.ts +1 -0
  107. package/es/shapes/AABB.js +8 -0
  108. package/es/types.d.ts +48 -27
  109. package/es/types.js +50 -31
  110. package/es/utils/custom-easing.js +1 -1
  111. package/es/utils/event.js +5 -3
  112. package/es/utils/index.d.ts +1 -0
  113. package/es/utils/index.js +2 -1
  114. package/es/utils/interpolation.d.ts +1 -0
  115. package/es/utils/interpolation.js +41 -8
  116. package/es/utils/path.d.ts +1 -1
  117. package/es/utils/path.js +16 -16
  118. package/es/utils/raf.d.ts +1 -1
  119. package/es/utils/raf.js +0 -2
  120. package/es/utils/string.d.ts +1 -0
  121. package/es/utils/string.js +9 -0
  122. package/es/utils/text.js +3 -3
  123. package/lib/Canvas.d.ts +3 -0
  124. package/lib/Canvas.js +7 -7
  125. package/lib/camera/Camera.d.ts +3 -2
  126. package/lib/camera/Camera.js +20 -10
  127. package/lib/canvas-module.js +10 -15
  128. package/lib/components/Transform.d.ts +0 -1
  129. package/lib/components/Transform.js +0 -1
  130. package/lib/display-objects/Circle.d.ts +4 -2
  131. package/lib/display-objects/Circle.js +7 -2
  132. package/lib/display-objects/CustomElement.d.ts +3 -2
  133. package/lib/display-objects/CustomElement.js +9 -6
  134. package/lib/display-objects/DisplayObject.d.ts +4 -3
  135. package/lib/display-objects/DisplayObject.js +79 -46
  136. package/lib/display-objects/Ellipse.d.ts +6 -3
  137. package/lib/display-objects/Ellipse.js +7 -2
  138. package/lib/display-objects/Group.d.ts +18 -2
  139. package/lib/display-objects/Group.js +13 -9
  140. package/lib/display-objects/HTML.d.ts +6 -1
  141. package/lib/display-objects/HTML.js +9 -5
  142. package/lib/display-objects/Image.d.ts +12 -7
  143. package/lib/display-objects/Image.js +9 -2
  144. package/lib/display-objects/Line.d.ts +1 -1
  145. package/lib/display-objects/Line.js +11 -3
  146. package/lib/display-objects/Path.d.ts +3 -2
  147. package/lib/display-objects/Path.js +9 -4
  148. package/lib/display-objects/Polygon.d.ts +1 -1
  149. package/lib/display-objects/Polygon.js +8 -2
  150. package/lib/display-objects/Polyline.d.ts +1 -1
  151. package/lib/display-objects/Polyline.js +9 -4
  152. package/lib/display-objects/Rect.d.ts +8 -5
  153. package/lib/display-objects/Rect.js +8 -3
  154. package/lib/display-objects/Text.d.ts +9 -6
  155. package/lib/display-objects/Text.js +14 -9
  156. package/lib/dom/Animation.js +1 -1
  157. package/lib/dom/AnimationTimeline.js +1 -2
  158. package/lib/dom/CustomElementRegistry.js +11 -11
  159. package/lib/dom/Document.d.ts +1 -0
  160. package/lib/dom/Document.js +22 -1
  161. package/lib/dom/Element.d.ts +14 -9
  162. package/lib/dom/Element.js +43 -14
  163. package/lib/dom/EventTarget.d.ts +2 -2
  164. package/lib/dom/EventTarget.js +4 -3
  165. package/lib/dom/KeyframeList.js +1 -1
  166. package/lib/dom/MutationEvent.d.ts +15 -0
  167. package/lib/dom/MutationEvent.js +37 -0
  168. package/lib/dom/MutationObserver.d.ts +36 -0
  169. package/lib/dom/MutationObserver.js +424 -0
  170. package/lib/dom/MutationRecord.d.ts +14 -0
  171. package/lib/dom/MutationRecord.js +38 -0
  172. package/lib/dom/Node.d.ts +35 -3
  173. package/lib/dom/Node.js +185 -16
  174. package/lib/dom/index.d.ts +3 -0
  175. package/lib/dom/index.js +39 -0
  176. package/lib/dom/interfaces.d.ts +36 -8
  177. package/lib/dom/interfaces.js +23 -5
  178. package/lib/global-module.d.ts +4 -1
  179. package/lib/global-module.js +44 -76
  180. package/lib/index.d.ts +1 -0
  181. package/lib/index.js +3 -1
  182. package/lib/plugins/CullingPlugin.d.ts +0 -2
  183. package/lib/plugins/CullingPlugin.js +2 -23
  184. package/lib/plugins/DirtyCheckPlugin.js +1 -1
  185. package/lib/plugins/FrustumCullingStrategy.d.ts +1 -0
  186. package/lib/plugins/FrustumCullingStrategy.js +41 -33
  187. package/lib/plugins/PrepareRendererPlugin.js +24 -4
  188. package/lib/property-handlers/aabb.js +21 -23
  189. package/lib/property-handlers/anchor.js +3 -1
  190. package/lib/property-handlers/color.js +6 -3
  191. package/lib/property-handlers/dimension.d.ts +15 -2
  192. package/lib/property-handlers/dimension.js +80 -7
  193. package/lib/property-handlers/index.d.ts +3 -0
  194. package/lib/property-handlers/index.js +39 -0
  195. package/lib/property-handlers/inherit.d.ts +6 -0
  196. package/lib/property-handlers/inherit.js +34 -0
  197. package/lib/property-handlers/interfaces.d.ts +2 -2
  198. package/lib/property-handlers/lineDash.d.ts +6 -1
  199. package/lib/property-handlers/lineDash.js +25 -4
  200. package/lib/property-handlers/offsetDistance.js +1 -1
  201. package/lib/property-handlers/path.d.ts +1 -1
  202. package/lib/property-handlers/text.d.ts +2 -0
  203. package/lib/property-handlers/text.js +10 -0
  204. package/lib/property-handlers/textTransform.d.ts +6 -0
  205. package/lib/property-handlers/textTransform.js +27 -0
  206. package/lib/services/EventService.js +3 -5
  207. package/lib/services/RenderingContext.d.ts +5 -8
  208. package/lib/services/RenderingContext.js +8 -9
  209. package/lib/services/RenderingService.js +1 -7
  210. package/lib/services/SceneGraphSelector.d.ts +3 -2
  211. package/lib/services/SceneGraphSelector.js +10 -3
  212. package/lib/services/SceneGraphService.d.ts +7 -14
  213. package/lib/services/SceneGraphService.js +15 -82
  214. package/lib/services/aabb/CircleUpdater.d.ts +2 -2
  215. package/lib/services/aabb/CircleUpdater.js +20 -10
  216. package/lib/services/aabb/EllipseUpdater.d.ts +2 -2
  217. package/lib/services/aabb/EllipseUpdater.js +27 -12
  218. package/lib/services/aabb/LineUpdater.js +1 -1
  219. package/lib/services/aabb/PathUpdater.js +1 -1
  220. package/lib/services/aabb/PolylineUpdater.js +2 -2
  221. package/lib/services/aabb/RectUpdater.d.ts +2 -2
  222. package/lib/services/aabb/RectUpdater.js +32 -16
  223. package/lib/services/aabb/TextUpdater.js +18 -9
  224. package/lib/services/aabb/interfaces.d.ts +1 -1
  225. package/lib/services/aabb/interfaces.js +1 -1
  226. package/lib/services/text/index.js +19 -21
  227. package/lib/shapes/AABB.d.ts +1 -0
  228. package/lib/shapes/AABB.js +8 -0
  229. package/lib/types.d.ts +48 -27
  230. package/lib/types.js +56 -35
  231. package/lib/utils/custom-easing.js +1 -1
  232. package/lib/utils/event.js +5 -3
  233. package/lib/utils/index.d.ts +1 -0
  234. package/lib/utils/index.js +13 -0
  235. package/lib/utils/interpolation.d.ts +1 -0
  236. package/lib/utils/interpolation.js +43 -7
  237. package/lib/utils/path.d.ts +1 -1
  238. package/lib/utils/path.js +15 -15
  239. package/lib/utils/raf.d.ts +1 -1
  240. package/lib/utils/raf.js +0 -2
  241. package/lib/utils/string.d.ts +1 -0
  242. package/lib/utils/string.js +16 -0
  243. package/lib/utils/text.js +3 -3
  244. package/package.json +6 -4
package/es/Canvas.d.ts CHANGED
@@ -73,6 +73,9 @@ export declare class Canvas extends EventTarget implements ICanvas {
73
73
  total: number;
74
74
  rendered: number;
75
75
  };
76
+ /**
77
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Window/getComputedStyle
78
+ */
76
79
  getComputedStyle(node: DisplayObject): any;
77
80
  get ready(): Promise<any>;
78
81
  destroy(destroyScenegraph?: boolean): void;
package/es/Canvas.js CHANGED
@@ -4,9 +4,9 @@ import { cleanExistedCanvas, isBrowser } from './utils/canvas';
4
4
  import { DisplayObject } from './display-objects/DisplayObject';
5
5
  import { ContextService } from './services';
6
6
  import { RenderingService } from './services/RenderingService';
7
- import { RenderingContext, RENDER_REASON } from './services/RenderingContext';
7
+ import { RenderingContext, RenderReason } from './services/RenderingContext';
8
8
  import { EventService } from './services/EventService';
9
- import { Camera, CAMERA_EVENT, CAMERA_PROJECTION_MODE, DefaultCamera } from './camera';
9
+ import { Camera, CameraEvent, CAMERA_PROJECTION_MODE, DefaultCamera } from './camera';
10
10
  import { containerModule as commonContainerModule } from './canvas-module';
11
11
  import { cancelAnimationFrame, requestAnimationFrame, patch } from './utils/raf';
12
12
  import { Document, EventTarget, ElementEvent } from './dom';
@@ -109,11 +109,6 @@ function (_super) {
109
109
  * the root node in scene graph
110
110
  */
111
111
  root: this.document.documentElement,
112
-
113
- /**
114
- * removed render bounds
115
- */
116
- removedRenderBoundsList: [],
117
112
  renderReasons: new Set(),
118
113
  force: false,
119
114
  dirty: false
@@ -132,8 +127,8 @@ function (_super) {
132
127
  var camera = new Camera().setPosition(width / 2, height / 2, 500).setFocalPoint(width / 2, height / 2, 0).setOrthographic(width / -2, width / 2, height / 2, height / -2, 0.1, 1000); // redraw when camera changed
133
128
 
134
129
  var context = this.container.get(RenderingContext);
135
- camera.on(CAMERA_EVENT.Updated, function () {
136
- context.renderReasons.add(RENDER_REASON.CameraChanged);
130
+ camera.on(CameraEvent.UPDATED, function () {
131
+ context.renderReasons.add(RenderReason.CAMERA_CHANGED);
137
132
  }); // bind camera
138
133
 
139
134
  this.container.register({
@@ -186,6 +181,10 @@ function (_super) {
186
181
  Canvas.prototype.getStats = function () {
187
182
  return this.getRenderingService().getStats();
188
183
  };
184
+ /**
185
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Window/getComputedStyle
186
+ */
187
+
189
188
 
190
189
  Canvas.prototype.getComputedStyle = function (node) {
191
190
  return node.parsedStyle;
@@ -367,6 +366,7 @@ function (_super) {
367
366
  };
368
367
 
369
368
  Canvas.prototype.loadCommonContainerModule = function () {
369
+ this.container.unload(commonContainerModule);
370
370
  this.container.load(commonContainerModule, true);
371
371
  };
372
372
 
@@ -18,8 +18,8 @@ export declare enum CAMERA_PROJECTION_MODE {
18
18
  ORTHOGRAPHIC = "ORTHOGRAPHIC",
19
19
  PERSPECTIVE = "PERSPECTIVE"
20
20
  }
21
- export declare const CAMERA_EVENT: {
22
- Updated: string;
21
+ export declare const CameraEvent: {
22
+ UPDATED: string;
23
23
  };
24
24
  /**
25
25
  * 参考「WebGL Insights - 23.Designing Cameras for WebGL Applications」,基于 Responsible Camera 思路设计
@@ -277,4 +277,5 @@ export declare class Camera extends EventEmitter {
277
277
  */
278
278
  private _getDistance;
279
279
  private _getOrthoMatrix;
280
+ private triggerUpdate;
280
281
  }
@@ -30,8 +30,8 @@ export var CAMERA_PROJECTION_MODE;
30
30
  CAMERA_PROJECTION_MODE["PERSPECTIVE"] = "PERSPECTIVE";
31
31
  })(CAMERA_PROJECTION_MODE || (CAMERA_PROJECTION_MODE = {}));
32
32
 
33
- export var CAMERA_EVENT = {
34
- Updated: 'updated'
33
+ export var CameraEvent = {
34
+ UPDATED: 'updated'
35
35
  };
36
36
  var DEG_2_RAD = Math.PI / 180;
37
37
  var RAD_2_DEG = 180 / Math.PI;
@@ -415,7 +415,7 @@ function (_super) {
415
415
 
416
416
  mat4.scale(this.projectionMatrix, this.projectionMatrix, vec3.fromValues(1, -1, 1));
417
417
  mat4.invert(this.projectionMatrixInverse, this.projectionMatrix);
418
- this.emit(CAMERA_EVENT.Updated);
418
+ this.triggerUpdate();
419
419
  return this;
420
420
  };
421
421
 
@@ -452,7 +452,7 @@ function (_super) {
452
452
 
453
453
  this._getOrthoMatrix();
454
454
 
455
- this.emit(CAMERA_EVENT.Updated);
455
+ this.triggerUpdate();
456
456
  return this;
457
457
  };
458
458
  /**
@@ -696,7 +696,7 @@ function (_super) {
696
696
 
697
697
  this._setPosition(pos);
698
698
 
699
- this.emit(CAMERA_EVENT.Updated);
699
+ this.triggerUpdate();
700
700
  return this;
701
701
  };
702
702
  /**
@@ -725,7 +725,7 @@ function (_super) {
725
725
  vec3.add(this.focalPoint, pos, this.distanceVector);
726
726
  }
727
727
 
728
- this.emit(CAMERA_EVENT.Updated);
728
+ this.triggerUpdate();
729
729
  return this;
730
730
  };
731
731
 
@@ -800,7 +800,7 @@ function (_super) {
800
800
 
801
801
  _this.computeMatrix();
802
802
 
803
- _this.emit(CAMERA_EVENT.Updated);
803
+ _this.triggerUpdate();
804
804
 
805
805
  var dist = vec3.dist(interFocalPoint, destFocalPoint_1) + vec3.dist(interPosition, destPosition_1);
806
806
 
@@ -842,7 +842,7 @@ function (_super) {
842
842
 
843
843
  this._getOrthoMatrix();
844
844
 
845
- this.emit(CAMERA_EVENT.Updated);
845
+ this.triggerUpdate();
846
846
  };
847
847
  /**
848
848
  * 计算相机矩阵
@@ -971,6 +971,14 @@ function (_super) {
971
971
  mat4.fromRotationTranslationScaleOrigin(this.orthoMatrix, rotZ, vec3.fromValues((this.rright - this.left) / 2 - position[0], (this.top - this.bottom) / 2 - position[1], 0), vec3.fromValues(this.zoom, this.zoom, 1), position);
972
972
  };
973
973
 
974
+ Camera.prototype.triggerUpdate = function () {
975
+ // update frustum
976
+ var viewMatrix = this.getViewTransform();
977
+ var vpMatrix = mat4.multiply(mat4.create(), this.getPerspective(), viewMatrix);
978
+ this.getFrustum().extractFromVPMatrix(vpMatrix);
979
+ this.emit(CameraEvent.UPDATED);
980
+ };
981
+
974
982
  Camera.ProjectionMode = {
975
983
  ORTHOGRAPHIC: 'ORTHOGRAPHIC',
976
984
  PERSPECTIVE: 'PERSPECTIVE'
@@ -1,32 +1,26 @@
1
1
  import { Module, Contribution } from 'mana-syringe';
2
2
  import { DirtyCheckPlugin } from './plugins/DirtyCheckPlugin';
3
3
  import { CullingPlugin, CullingStrategyContribution } from './plugins/CullingPlugin';
4
- import { PrepareRendererPlugin } from './plugins/PrepareRendererPlugin';
4
+ import { PrepareRendererPlugin } from './plugins/PrepareRendererPlugin'; // import { CSSCalculatorPlugin } from './plugins/CSSStyleCalculator';
5
+
5
6
  import { FrustumCullingStrategy } from './plugins/FrustumCullingStrategy';
6
7
  import { RenderingPluginContribution, RenderingService } from './services';
7
8
  import { EventPlugin } from './plugins/EventPlugin';
8
9
  import { EventService } from './services';
9
- export var containerModule = Module(function (register, context) {
10
- if (context.container.isBound(RenderingService)) {
11
- // remove rendering plugins
12
- context.container.remove(RenderingPluginContribution);
13
- context.container.remove(RenderingService);
14
- context.container.remove(FrustumCullingStrategy);
15
- } else {
16
- Contribution.register(register, RenderingPluginContribution, {
17
- cache: false
18
- }); // culling plugin
19
-
20
- Contribution.register(register, CullingStrategyContribution, {
21
- cache: false
22
- });
23
- } // register built-in rendering plugins
10
+ export var containerModule = Module(function (register) {
11
+ Contribution.register(register, RenderingPluginContribution, {
12
+ cache: false
13
+ }); // culling plugin
24
14
 
15
+ Contribution.register(register, CullingStrategyContribution, {
16
+ cache: false
17
+ }); // register built-in rendering plugins
25
18
 
26
19
  register(RenderingService);
27
20
  register(EventService);
28
21
  register(EventPlugin);
29
- register(PrepareRendererPlugin);
22
+ register(PrepareRendererPlugin); // register(CSSCalculatorPlugin);
23
+
30
24
  register(DirtyCheckPlugin);
31
25
  register(CullingPlugin);
32
26
  register(FrustumCullingStrategy);
@@ -7,7 +7,6 @@ export declare class Transform {
7
7
  dirtyFlag: boolean;
8
8
  localDirtyFlag: boolean;
9
9
  frozen: boolean;
10
- graphDepth: number;
11
10
  /**
12
11
  * local space RTS
13
12
  */
@@ -10,7 +10,6 @@ function () {
10
10
  this.dirtyFlag = false;
11
11
  this.localDirtyFlag = false;
12
12
  this.frozen = false;
13
- this.graphDepth = 0;
14
13
  /**
15
14
  * local space RTS
16
15
  */
@@ -1,12 +1,14 @@
1
1
  import type { DisplayObjectConfig } from '../dom/interfaces';
2
2
  import type { BaseStyleProps, ParsedBaseStyleProps } from '../types';
3
3
  import { DisplayObject } from './DisplayObject';
4
+ import type { ParsedElement } from '../property-handlers';
4
5
  export interface CircleStyleProps extends BaseStyleProps {
5
6
  r: number;
6
7
  }
7
8
  export interface ParsedCircleStyleProps extends ParsedBaseStyleProps {
8
- r: number;
9
+ r: ParsedElement;
10
+ rInPixels: number;
9
11
  }
10
12
  export declare class Circle extends DisplayObject<CircleStyleProps, ParsedCircleStyleProps> {
11
- constructor({ style, ...rest }: DisplayObjectConfig<CircleStyleProps>);
13
+ constructor({ style, ...rest }?: DisplayObjectConfig<CircleStyleProps>);
12
14
  }
@@ -1,5 +1,5 @@
1
1
  import { __assign, __extends, __rest } from "tslib";
2
- import { SHAPE } from '../types';
2
+ import { Shape } from '../types';
3
3
  import { DisplayObject } from './DisplayObject';
4
4
 
5
5
  var Circle =
@@ -8,14 +8,19 @@ function (_super) {
8
8
  __extends(Circle, _super);
9
9
 
10
10
  function Circle(_a) {
11
+ if (_a === void 0) {
12
+ _a = {};
13
+ }
14
+
11
15
  var style = _a.style,
12
16
  rest = __rest(_a, ["style"]);
13
17
 
14
18
  return _super.call(this, __assign({
15
- type: SHAPE.Circle,
19
+ type: Shape.CIRCLE,
16
20
  style: __assign({
17
21
  r: 0,
18
- anchor: [0.5, 0.5]
22
+ anchor: [0.5, 0.5],
23
+ lineWidth: 0
19
24
  }, style)
20
25
  }, rest)) || this;
21
26
  }
@@ -1,11 +1,12 @@
1
1
  import { DisplayObject } from './DisplayObject';
2
2
  import type { DisplayObjectConfig } from '../dom/interfaces';
3
+ import type { BaseStyleProps } from '../types';
3
4
  /**
4
5
  * shadow root
5
6
  * @see https://yuque.antfin-inc.com/antv/czqvg5/pgqipg
6
7
  */
7
- export declare abstract class CustomElement<CustomElementStyleProps> extends DisplayObject<CustomElementStyleProps> {
8
- constructor(config: DisplayObjectConfig<CustomElementStyleProps>);
8
+ export declare abstract class CustomElement<CustomElementStyleProps extends BaseStyleProps> extends DisplayObject<CustomElementStyleProps> {
9
+ constructor(config?: DisplayObjectConfig<CustomElementStyleProps>);
9
10
  /**
10
11
  * fired after element insert into DOM tree
11
12
  */
@@ -13,6 +13,10 @@ function (_super) {
13
13
 
14
14
 
15
15
  function CustomElement(config) {
16
+ if (config === void 0) {
17
+ config = {};
18
+ }
19
+
16
20
  var _this = _super.call(this, config) || this;
17
21
 
18
22
  _this.handleMounted = function (e) {
@@ -56,20 +60,19 @@ function (_super) {
56
60
  return;
57
61
  }
58
62
 
59
- var _a = e.detail,
60
- attributeName = _a.attributeName,
61
- oldValue = _a.oldValue,
62
- newValue = _a.newValue;
63
+ var attrName = e.attrName,
64
+ prevValue = e.prevValue,
65
+ newValue = e.newValue;
63
66
 
64
67
  if (_this.attributeChangedCallback) {
65
- _this.attributeChangedCallback(attributeName, oldValue, newValue);
68
+ _this.attributeChangedCallback(attrName, prevValue, newValue);
66
69
  }
67
70
  }; // this.addEventListener(ElementEvent.CHILD_INSERTED, this.handleChildInserted);
68
71
  // this.addEventListener(ElementEvent.CHILD_REMOVED, this.handleChildRemoved);
69
72
 
70
73
 
71
74
  if (_this.attributeChangedCallback) {
72
- _this.addEventListener(ElementEvent.ATTRIBUTE_CHANGED, _this.handleAttributeChanged);
75
+ _this.addEventListener(ElementEvent.ATTR_MODIFIED, _this.handleAttributeChanged);
73
76
  }
74
77
 
75
78
  if (_this.connectedCallback) {
@@ -35,14 +35,15 @@ export declare class DisplayObject<StyleProps extends BaseStyleProps = any, Pars
35
35
  destroy(): void;
36
36
  cloneNode(deep?: boolean): this;
37
37
  private initAttributes;
38
- setAttribute<Key extends keyof StyleProps>(attributeName: Key, value: StyleProps[Key], force?: boolean): void;
38
+ setAttribute<Key extends keyof StyleProps>(name: Key, value: StyleProps[Key], force?: boolean): void;
39
39
  /**
40
40
  * parse property, eg.
41
41
  * * fill: 'red' => [1, 0, 0, 1]
42
42
  * * translateX: '10px' => { unit: 'px', value: 10 }
43
+ * * fontSize: '2em' => { unit: 'px', value: 32 }
43
44
  */
44
- private parseStyleProperty;
45
- private updateStyleProperty;
45
+ parseStyleProperty<Key extends keyof ParsedStyleProps>(name: Key, value: ParsedStyleProps[Key]): void;
46
+ updateStyleProperty<Key extends keyof ParsedStyleProps>(name: Key, oldParsedValue: ParsedStyleProps[Key], newParsedValue: ParsedStyleProps[Key]): void;
46
47
  /**
47
48
  * called when attributes get changed or initialized
48
49
  */
@@ -5,12 +5,11 @@ import { DisplayObjectPool } from '../DisplayObjectPool';
5
5
  import { KeyframeEffect } from '../dom/KeyframeEffect';
6
6
  import { Element } from '../dom/Element';
7
7
  import { ElementEvent } from '../dom/interfaces';
8
- import { SHAPE } from '../types';
9
- import { createVec3, fromRotationTranslationScale, getEuler, rad2deg } from '../utils'; // import type { StylePropertyParser, StylePropertyUpdater } from '../property-handlers';
10
- // import { StylePropertyParserFactory, StylePropertyUpdaterFactory } from '../property-handlers';
11
-
8
+ import { Shape } from '../types';
9
+ import { createVec3, formatAttribute, fromRotationTranslationScale, getEuler, rad2deg } from '../utils';
12
10
  import { globalContainer, stylePropertyParserFactory, stylePropertyUpdaterFactory } from '../global-module';
13
11
  import { dirtifyToRoot } from '../services';
12
+ import { MutationEvent } from '../dom/MutationEvent';
14
13
  var DEFAULT_STYLE_PROPS = {
15
14
  anchor: [0, 0, 0],
16
15
  origin: [0, 0, 0],
@@ -42,23 +41,18 @@ var DEFAULT_STYLE_PROPS = {
42
41
  var DisplayObject =
43
42
  /** @class */
44
43
  function (_super) {
45
- __extends(DisplayObject, _super); // stylePropertyUpdaterFactory = globalContainer.get<
46
- // <Key extends keyof StyleProps>(stylePropertyName: Key) => StylePropertyUpdater<any>[]
47
- // >(StylePropertyUpdaterFactory);
48
- // stylePropertyParserFactory = globalContainer.get<
49
- // <Key extends keyof ParsedStyleProps>(stylePropertyName: Key) => StylePropertyParser<any, any>
50
- // >(StylePropertyParserFactory);
51
-
44
+ __extends(DisplayObject, _super);
52
45
 
53
46
  function DisplayObject(config) {
47
+ var _this = this;
48
+
54
49
  var _a, _b, _c;
55
50
 
56
- var _this = _super.call(this) || this;
51
+ _this = _super.call(this) || this;
57
52
  /**
58
53
  * push to active animations after calling `animate()`
59
54
  */
60
55
 
61
-
62
56
  _this.activeAnimations = []; // assign name, id to config
63
57
  // eg. group.get('name')
64
58
 
@@ -68,17 +62,38 @@ function (_super) {
68
62
 
69
63
  _this.id = _this.config.id || '';
70
64
  _this.name = _this.config.name || '';
71
- _this.className = _this.config.className || '';
65
+
66
+ if (_this.config.className || _this.config.class) {
67
+ _this.className = _this.config.className || _this.config.class;
68
+ }
69
+
72
70
  _this.interactive = (_b = _this.config.interactive) !== null && _b !== void 0 ? _b : true;
73
- _this.nodeName = _this.config.type || SHAPE.Group; // compatible with G 3.0
71
+ _this.nodeName = _this.config.type || Shape.GROUP; // compatible with G 3.0
74
72
 
75
73
  _this.config.style = __assign(__assign(__assign(__assign({}, DEFAULT_STYLE_PROPS), {
76
74
  zIndex: (_c = _this.config.zIndex) !== null && _c !== void 0 ? _c : 0,
77
75
  visibility: _this.config.visible === false ? 'hidden' : 'visible'
78
76
  }), _this.config.style), _this.config.attrs);
79
- _this.style = new Proxy(_this.attributes, {
80
- get: function get(_, prop) {
81
- return _this.getAttribute(prop);
77
+ _this.style = new Proxy(__assign(__assign({}, _this.attributes), {
78
+ setProperty: function setProperty(propertyName, value) {
79
+ _this.setAttribute(propertyName, value);
80
+ },
81
+ getPropertyValue: function getPropertyValue(propertyName) {
82
+ return _this.getAttribute(propertyName);
83
+ },
84
+ removeProperty: function removeProperty(propertyName) {
85
+ _this.removeAttribute(propertyName);
86
+ },
87
+ item: function item() {
88
+ return '';
89
+ }
90
+ }), {
91
+ get: function get(target, name) {
92
+ if (name in target) {
93
+ return target[name];
94
+ }
95
+
96
+ return _this.getAttribute(name);
82
97
  },
83
98
  set: function set(_, prop, value) {
84
99
  _this.setAttribute(prop, value);
@@ -113,7 +128,7 @@ function (_super) {
113
128
  name: this.name,
114
129
  className: this.name,
115
130
  interactive: this.interactive,
116
- style: __assign({}, this.style)
131
+ style: __assign({}, this.attributes)
117
132
  });
118
133
 
119
134
  if (deep) {
@@ -136,51 +151,62 @@ function (_super) {
136
151
  var renderable = this.renderable; // parse attributes first
137
152
 
138
153
  for (var attributeName in attributes) {
139
- var value = attributes[attributeName];
140
- this.attributes[attributeName] = value; // @ts-ignore
154
+ var _a = __read(formatAttribute(attributeName, attributes[attributeName]), 2),
155
+ name_1 = _a[0],
156
+ value = _a[1];
157
+
158
+ this.attributes[name_1] = value; // @ts-ignore
141
159
 
142
- this.parseStyleProperty(attributeName, value);
160
+ this.parseStyleProperty(name_1, value);
143
161
  }
144
162
 
145
163
  var priorities = {
146
- x: 1000,
147
- y: 1000
164
+ x: Infinity,
165
+ y: Infinity
148
166
  }; // update x, y at last
149
167
 
150
168
  var sortedNames = Object.keys(attributes).sort(function (a, b) {
151
169
  return (priorities[a] || 0) - (priorities[b] || 0);
152
170
  });
153
171
  sortedNames.forEach(function (attributeName) {
154
- // @ts-ignore
155
- _this.updateStyleProperty(attributeName, undefined, _this.parsedStyle[attributeName]);
172
+ var _a = __read(formatAttribute(attributeName, ''), 1),
173
+ name = _a[0]; // @ts-ignore
174
+
175
+
176
+ _this.updateStyleProperty(name, undefined, _this.parsedStyle[name]);
156
177
  }); // redraw at next frame
157
178
 
158
179
  renderable.dirty = true;
159
180
  };
160
181
 
161
- DisplayObject.prototype.setAttribute = function (attributeName, value, force) {
182
+ DisplayObject.prototype.setAttribute = function (name, value, force) {
162
183
  if (force === void 0) {
163
184
  force = false;
164
185
  }
165
186
 
166
- if (force || !isEqual(value, this.attributes[attributeName]) || attributeName === 'transformOrigin' || attributeName === 'visibility' // will affect children
187
+ var _a = __read(formatAttribute(name, value), 2),
188
+ attributeName = _a[0],
189
+ attributeValue = _a[1];
190
+
191
+ if (force || !isEqual(attributeValue, this.attributes[attributeName]) || attributeName === 'transformOrigin' || attributeName === 'visibility' // will affect children
167
192
  ) {
168
193
  if (attributeName === 'visibility') {
169
194
  // set value cascade
170
195
  this.forEach(function (object) {
171
- object.changeAttribute(attributeName, value);
196
+ object.changeAttribute(attributeName, attributeValue);
172
197
  });
173
198
  } else {
174
- this.changeAttribute(attributeName, value);
199
+ this.changeAttribute(attributeName, attributeValue);
175
200
  }
176
201
 
177
- _super.prototype.setAttribute.call(this, attributeName, value);
202
+ _super.prototype.setAttribute.call(this, attributeName, attributeValue);
178
203
  }
179
204
  };
180
205
  /**
181
206
  * parse property, eg.
182
207
  * * fill: 'red' => [1, 0, 0, 1]
183
208
  * * translateX: '10px' => { unit: 'px', value: 10 }
209
+ * * fontSize: '2em' => { unit: 'px', value: 32 }
184
210
  */
185
211
 
186
212
 
@@ -190,16 +216,14 @@ function (_super) {
190
216
 
191
217
  if (stylePropertyParser) {
192
218
  // @ts-ignore
193
- this.parsedStyle[name] = stylePropertyParser(value, this);
219
+ this.parsedStyle[name] = stylePropertyParser(value, this, name);
194
220
  } else {
195
221
  this.parsedStyle[name] = value;
196
222
  }
197
223
  };
198
224
 
199
225
  DisplayObject.prototype.updateStyleProperty = function (name, oldParsedValue, newParsedValue) {
200
- var _this = this; // update property, which may cause AABB re-calc
201
- // @ts-ignore
202
- // const stylePropertyUpdaters = this.stylePropertyUpdaterFactory(name);
226
+ var _this = this; // @ts-ignore
203
227
 
204
228
 
205
229
  var stylePropertyUpdaters = stylePropertyUpdaterFactory[name];
@@ -207,7 +231,7 @@ function (_super) {
207
231
  if (stylePropertyUpdaters) {
208
232
  stylePropertyUpdaters.forEach(function (updater) {
209
233
  // @ts-ignore
210
- updater(oldParsedValue, newParsedValue, _this, _this.sceneGraphService);
234
+ updater(oldParsedValue, newParsedValue, _this, _this.sceneGraphService, name);
211
235
  });
212
236
  }
213
237
  };
@@ -228,26 +252,33 @@ function (_super) {
228
252
 
229
253
  this.parseStyleProperty(name, value); // @ts-ignore
230
254
 
231
- this.updateStyleProperty(name, oldParsedValue, this.parsedStyle[name]); // inform clip path targets
255
+ var newParsedValue = this.parsedStyle[name]; // @ts-ignore
256
+
257
+ this.updateStyleProperty(name, oldParsedValue, newParsedValue); // inform clip path targets
232
258
 
233
259
  if (this.attributes.clipPathTargets && this.attributes.clipPathTargets.length) {
234
260
  this.attributes.clipPathTargets.forEach(function (target) {
235
- dirtifyToRoot(target);
236
- target.emit(ElementEvent.ATTRIBUTE_CHANGED, {
237
- attributeName: 'clipPath',
238
- oldValue: _this,
239
- newValue: _this
240
- });
261
+ dirtifyToRoot(target); // target.emit(ElementEvent.ATTR_MODIFIED, {
262
+ // attributeName: 'clipPath',
263
+ // oldValue: this,
264
+ // newValue: this,
265
+ // });
266
+
267
+ target.dispatchEvent(new MutationEvent(ElementEvent.ATTR_MODIFIED, target, _this, _this, 'clipPath', MutationEvent.MODIFICATION, _this, _this));
241
268
  });
242
269
  } // redraw at next frame
243
270
 
244
271
 
245
272
  renderable.dirty = true;
246
- this.emit(ElementEvent.ATTRIBUTE_CHANGED, {
247
- attributeName: name,
248
- oldValue: oldValue,
249
- newValue: value
250
- });
273
+ this.dispatchEvent(new MutationEvent(ElementEvent.ATTR_MODIFIED, this, oldValue, value, name, MutationEvent.MODIFICATION, oldParsedValue, newParsedValue)); // this.emit(ElementEvent.ATTR_MODIFIED, {
274
+ // attrName: name,
275
+ // attributeName: name,
276
+ // prevValue: oldValue,
277
+ // oldValue,
278
+ // newValue: value,
279
+ // oldParsedValue,
280
+ // newParsedValue,
281
+ // });
251
282
  }; // #region transformable
252
283
 
253
284
 
@@ -571,7 +602,7 @@ function (_super) {
571
602
 
572
603
  DisplayObject.prototype.isVisible = function () {
573
604
  var cullable = this.cullable;
574
- return this.style.visibility === 'visible' && (!cullable || cullable && !cullable.isCulled());
605
+ return this.getAttribute('visibility') === 'visible' && (!cullable || cullable && !cullable.isCulled());
575
606
  };
576
607
  /**
577
608
  * bring to front in current group
@@ -1,14 +1,17 @@
1
1
  import type { DisplayObjectConfig } from '../dom/interfaces';
2
2
  import type { BaseStyleProps, ParsedBaseStyleProps } from '../types';
3
3
  import { DisplayObject } from './DisplayObject';
4
+ import type { ParsedElement } from '../property-handlers';
4
5
  export interface EllipseStyleProps extends BaseStyleProps {
5
6
  rx: number;
6
7
  ry: number;
7
8
  }
8
9
  export interface ParsedEllipseStyleProps extends ParsedBaseStyleProps {
9
- rx: number;
10
- ry: number;
10
+ rx: ParsedElement;
11
+ ry: ParsedElement;
12
+ rxInPixels: number;
13
+ ryInPixels: number;
11
14
  }
12
15
  export declare class Ellipse extends DisplayObject<EllipseStyleProps, ParsedEllipseStyleProps> {
13
- constructor({ style, ...rest }: DisplayObjectConfig<EllipseStyleProps>);
16
+ constructor({ style, ...rest }?: DisplayObjectConfig<EllipseStyleProps>);
14
17
  }
@@ -1,5 +1,5 @@
1
1
  import { __assign, __extends, __rest } from "tslib";
2
- import { SHAPE } from '../types';
2
+ import { Shape } from '../types';
3
3
  import { DisplayObject } from './DisplayObject';
4
4
 
5
5
  var Ellipse =
@@ -8,15 +8,20 @@ function (_super) {
8
8
  __extends(Ellipse, _super);
9
9
 
10
10
  function Ellipse(_a) {
11
+ if (_a === void 0) {
12
+ _a = {};
13
+ }
14
+
11
15
  var style = _a.style,
12
16
  rest = __rest(_a, ["style"]);
13
17
 
14
18
  return _super.call(this, __assign({
15
- type: SHAPE.Ellipse,
19
+ type: Shape.ELLIPSE,
16
20
  style: __assign({
17
21
  rx: 0,
18
22
  ry: 0,
19
- anchor: [0.5, 0.5]
23
+ anchor: [0.5, 0.5],
24
+ lineWidth: 0
20
25
  }, style)
21
26
  }, rest)) || this;
22
27
  }