@antv/g 5.0.15 → 5.0.18

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 (236) hide show
  1. package/dist/index.umd.min.js +18 -2
  2. package/es/Canvas.d.ts +7 -1
  3. package/es/Canvas.js +9 -10
  4. package/es/camera/Camera.d.ts +3 -2
  5. package/es/camera/Camera.js +16 -8
  6. package/es/canvas-module.js +4 -2
  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 +1 -1
  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 +9 -3
  14. package/es/display-objects/DisplayObject.js +97 -50
  15. package/es/display-objects/Ellipse.d.ts +1 -1
  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 +11 -9
  19. package/es/display-objects/HTML.d.ts +1 -1
  20. package/es/display-objects/HTML.js +9 -4
  21. package/es/display-objects/Image.d.ts +5 -3
  22. package/es/display-objects/Image.js +8 -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 +1 -1
  32. package/es/display-objects/Rect.js +8 -3
  33. package/es/display-objects/Text.d.ts +32 -4
  34. package/es/display-objects/Text.js +70 -10
  35. package/es/dom/Animation.js +2 -2
  36. package/es/dom/AnimationTimeline.js +1 -2
  37. package/es/dom/CustomElementRegistry.js +12 -12
  38. package/es/dom/Document.d.ts +2 -1
  39. package/es/dom/Document.js +22 -2
  40. package/es/dom/Element.d.ts +38 -5
  41. package/es/dom/Element.js +115 -16
  42. package/es/dom/EventTarget.d.ts +2 -2
  43. package/es/dom/EventTarget.js +4 -3
  44. package/es/dom/FederatedEvent.d.ts +4 -1
  45. package/es/dom/KeyframeList.js +1 -1
  46. package/es/dom/MutationEvent.d.ts +15 -0
  47. package/es/dom/MutationEvent.js +29 -0
  48. package/es/dom/MutationObserver.d.ts +36 -0
  49. package/es/dom/MutationObserver.js +413 -0
  50. package/es/dom/MutationRecord.d.ts +14 -0
  51. package/es/dom/MutationRecord.js +31 -0
  52. package/es/dom/Node.d.ts +35 -3
  53. package/es/dom/Node.js +184 -17
  54. package/es/dom/index.d.ts +3 -0
  55. package/es/dom/index.js +3 -0
  56. package/es/dom/interfaces.d.ts +39 -8
  57. package/es/dom/interfaces.js +23 -5
  58. package/es/global-module.d.ts +1 -0
  59. package/es/global-module.js +11 -13
  60. package/es/index.d.ts +1 -0
  61. package/es/index.js +1 -0
  62. package/es/plugins/CullingPlugin.d.ts +0 -2
  63. package/es/plugins/CullingPlugin.js +3 -24
  64. package/es/plugins/DirtyCheckPlugin.js +2 -2
  65. package/es/plugins/EventPlugin.d.ts +1 -0
  66. package/es/plugins/EventPlugin.js +15 -5
  67. package/es/plugins/FrustumCullingStrategy.d.ts +1 -0
  68. package/es/plugins/FrustumCullingStrategy.js +41 -33
  69. package/es/plugins/PrepareRendererPlugin.js +21 -5
  70. package/es/property-handlers/aabb.js +19 -20
  71. package/es/property-handlers/color.js +5 -2
  72. package/es/property-handlers/dimension.d.ts +15 -3
  73. package/es/property-handlers/dimension.js +50 -9
  74. package/es/property-handlers/index.d.ts +3 -0
  75. package/es/property-handlers/index.js +4 -1
  76. package/es/property-handlers/inherit.d.ts +6 -0
  77. package/es/property-handlers/inherit.js +25 -0
  78. package/es/property-handlers/interfaces.d.ts +2 -2
  79. package/es/property-handlers/lineDash.d.ts +6 -1
  80. package/es/property-handlers/lineDash.js +23 -4
  81. package/es/property-handlers/offsetDistance.js +2 -2
  82. package/es/property-handlers/text.d.ts +2 -0
  83. package/es/property-handlers/text.js +3 -0
  84. package/es/property-handlers/textTransform.d.ts +6 -0
  85. package/es/property-handlers/textTransform.js +19 -0
  86. package/es/services/EventService.js +11 -7
  87. package/es/services/RenderingContext.d.ts +5 -8
  88. package/es/services/RenderingContext.js +6 -7
  89. package/es/services/RenderingService.d.ts +12 -2
  90. package/es/services/RenderingService.js +23 -12
  91. package/es/services/SceneGraphSelector.d.ts +3 -2
  92. package/es/services/SceneGraphSelector.js +8 -4
  93. package/es/services/SceneGraphService.d.ts +0 -7
  94. package/es/services/SceneGraphService.js +17 -87
  95. package/es/services/aabb/CircleUpdater.js +3 -3
  96. package/es/services/aabb/EllipseUpdater.js +2 -2
  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.js +4 -4
  101. package/es/services/aabb/TextUpdater.js +31 -10
  102. package/es/services/text/index.js +19 -21
  103. package/es/shapes/AABB.js +5 -0
  104. package/es/types.d.ts +48 -24
  105. package/es/types.js +50 -31
  106. package/es/utils/animation.js +1 -1
  107. package/es/utils/custom-easing.js +1 -1
  108. package/es/utils/event.js +7 -4
  109. package/es/utils/index.d.ts +2 -0
  110. package/es/utils/index.js +3 -1
  111. package/es/utils/interpolation.d.ts +1 -0
  112. package/es/utils/interpolation.js +41 -8
  113. package/es/utils/path.js +11 -11
  114. package/es/utils/raf.d.ts +1 -1
  115. package/es/utils/raf.js +0 -2
  116. package/es/utils/string.d.ts +1 -0
  117. package/es/utils/string.js +9 -0
  118. package/es/utils/text.js +3 -3
  119. package/lib/Canvas.d.ts +7 -1
  120. package/lib/Canvas.js +7 -8
  121. package/lib/camera/Camera.d.ts +3 -2
  122. package/lib/camera/Camera.js +20 -10
  123. package/lib/canvas-module.js +3 -1
  124. package/lib/components/Transform.d.ts +0 -1
  125. package/lib/components/Transform.js +0 -1
  126. package/lib/display-objects/Circle.d.ts +1 -1
  127. package/lib/display-objects/Circle.js +7 -2
  128. package/lib/display-objects/CustomElement.d.ts +3 -2
  129. package/lib/display-objects/CustomElement.js +9 -6
  130. package/lib/display-objects/DisplayObject.d.ts +9 -3
  131. package/lib/display-objects/DisplayObject.js +97 -47
  132. package/lib/display-objects/Ellipse.d.ts +1 -1
  133. package/lib/display-objects/Ellipse.js +7 -2
  134. package/lib/display-objects/Group.d.ts +18 -2
  135. package/lib/display-objects/Group.js +10 -9
  136. package/lib/display-objects/HTML.d.ts +1 -1
  137. package/lib/display-objects/HTML.js +8 -4
  138. package/lib/display-objects/Image.d.ts +5 -3
  139. package/lib/display-objects/Image.js +7 -2
  140. package/lib/display-objects/Line.d.ts +1 -1
  141. package/lib/display-objects/Line.js +11 -3
  142. package/lib/display-objects/Path.d.ts +3 -2
  143. package/lib/display-objects/Path.js +9 -4
  144. package/lib/display-objects/Polygon.d.ts +1 -1
  145. package/lib/display-objects/Polygon.js +8 -2
  146. package/lib/display-objects/Polyline.d.ts +1 -1
  147. package/lib/display-objects/Polyline.js +9 -4
  148. package/lib/display-objects/Rect.d.ts +1 -1
  149. package/lib/display-objects/Rect.js +7 -2
  150. package/lib/display-objects/Text.d.ts +32 -4
  151. package/lib/display-objects/Text.js +69 -9
  152. package/lib/dom/Animation.js +2 -2
  153. package/lib/dom/AnimationTimeline.js +1 -2
  154. package/lib/dom/CustomElementRegistry.js +11 -11
  155. package/lib/dom/Document.d.ts +2 -1
  156. package/lib/dom/Document.js +24 -3
  157. package/lib/dom/Element.d.ts +38 -5
  158. package/lib/dom/Element.js +117 -16
  159. package/lib/dom/EventTarget.d.ts +2 -2
  160. package/lib/dom/EventTarget.js +4 -3
  161. package/lib/dom/FederatedEvent.d.ts +4 -1
  162. package/lib/dom/KeyframeList.js +1 -1
  163. package/lib/dom/MutationEvent.d.ts +15 -0
  164. package/lib/dom/MutationEvent.js +37 -0
  165. package/lib/dom/MutationObserver.d.ts +36 -0
  166. package/lib/dom/MutationObserver.js +424 -0
  167. package/lib/dom/MutationRecord.d.ts +14 -0
  168. package/lib/dom/MutationRecord.js +38 -0
  169. package/lib/dom/Node.d.ts +35 -3
  170. package/lib/dom/Node.js +185 -16
  171. package/lib/dom/index.d.ts +3 -0
  172. package/lib/dom/index.js +39 -0
  173. package/lib/dom/interfaces.d.ts +39 -8
  174. package/lib/dom/interfaces.js +23 -5
  175. package/lib/global-module.d.ts +1 -0
  176. package/lib/global-module.js +12 -8
  177. package/lib/index.d.ts +1 -0
  178. package/lib/index.js +3 -1
  179. package/lib/plugins/CullingPlugin.d.ts +0 -2
  180. package/lib/plugins/CullingPlugin.js +2 -23
  181. package/lib/plugins/DirtyCheckPlugin.js +1 -1
  182. package/lib/plugins/EventPlugin.d.ts +1 -0
  183. package/lib/plugins/EventPlugin.js +13 -5
  184. package/lib/plugins/FrustumCullingStrategy.d.ts +1 -0
  185. package/lib/plugins/FrustumCullingStrategy.js +42 -33
  186. package/lib/plugins/PrepareRendererPlugin.js +24 -4
  187. package/lib/property-handlers/aabb.js +18 -19
  188. package/lib/property-handlers/color.js +6 -3
  189. package/lib/property-handlers/dimension.d.ts +15 -3
  190. package/lib/property-handlers/dimension.js +50 -8
  191. package/lib/property-handlers/index.d.ts +3 -0
  192. package/lib/property-handlers/index.js +39 -0
  193. package/lib/property-handlers/inherit.d.ts +6 -0
  194. package/lib/property-handlers/inherit.js +34 -0
  195. package/lib/property-handlers/interfaces.d.ts +2 -2
  196. package/lib/property-handlers/lineDash.d.ts +6 -1
  197. package/lib/property-handlers/lineDash.js +25 -4
  198. package/lib/property-handlers/offsetDistance.js +1 -1
  199. package/lib/property-handlers/text.d.ts +2 -0
  200. package/lib/property-handlers/text.js +10 -0
  201. package/lib/property-handlers/textTransform.d.ts +6 -0
  202. package/lib/property-handlers/textTransform.js +27 -0
  203. package/lib/services/EventService.js +11 -7
  204. package/lib/services/RenderingContext.d.ts +5 -8
  205. package/lib/services/RenderingContext.js +8 -9
  206. package/lib/services/RenderingService.d.ts +12 -2
  207. package/lib/services/RenderingService.js +23 -11
  208. package/lib/services/SceneGraphSelector.d.ts +3 -2
  209. package/lib/services/SceneGraphSelector.js +10 -3
  210. package/lib/services/SceneGraphService.d.ts +0 -7
  211. package/lib/services/SceneGraphService.js +18 -91
  212. package/lib/services/aabb/CircleUpdater.js +2 -2
  213. package/lib/services/aabb/EllipseUpdater.js +1 -1
  214. package/lib/services/aabb/LineUpdater.js +1 -1
  215. package/lib/services/aabb/PathUpdater.js +1 -1
  216. package/lib/services/aabb/PolylineUpdater.js +2 -2
  217. package/lib/services/aabb/RectUpdater.js +3 -3
  218. package/lib/services/aabb/TextUpdater.js +30 -9
  219. package/lib/services/text/index.js +19 -21
  220. package/lib/shapes/AABB.js +5 -0
  221. package/lib/types.d.ts +48 -24
  222. package/lib/types.js +56 -35
  223. package/lib/utils/animation.js +1 -1
  224. package/lib/utils/custom-easing.js +1 -1
  225. package/lib/utils/event.js +7 -4
  226. package/lib/utils/index.d.ts +2 -0
  227. package/lib/utils/index.js +26 -0
  228. package/lib/utils/interpolation.d.ts +1 -0
  229. package/lib/utils/interpolation.js +43 -7
  230. package/lib/utils/path.js +10 -10
  231. package/lib/utils/raf.d.ts +1 -1
  232. package/lib/utils/raf.js +0 -2
  233. package/lib/utils/string.d.ts +1 -0
  234. package/lib/utils/string.js +16 -0
  235. package/lib/utils/text.js +3 -3
  236. package/package.json +5 -3
package/es/Canvas.d.ts CHANGED
@@ -71,8 +71,14 @@ export declare class Canvas extends EventTarget implements ICanvas {
71
71
  getRenderingContext(): RenderingContext;
72
72
  getStats(): {
73
73
  total: number;
74
- rendered: number;
74
+ rendered: number; /**
75
+ * window.document
76
+ */
77
+ renderedOnscreen: number;
75
78
  };
79
+ /**
80
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Window/getComputedStyle
81
+ */
76
82
  getComputedStyle(node: DisplayObject): any;
77
83
  get ready(): Promise<any>;
78
84
  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;
@@ -304,7 +303,7 @@ function (_super) {
304
303
 
305
304
  if (this.container.isBound(RenderingService)) {
306
305
  var renderingService = this.container.get(RenderingService);
307
- renderingService.render();
306
+ renderingService.render(this.getConfig());
308
307
  }
309
308
 
310
309
  this.emit(CanvasEvent.AFTER_RENDER, {});
@@ -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,7 +1,8 @@
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';
@@ -18,7 +19,8 @@ export var containerModule = Module(function (register) {
18
19
  register(RenderingService);
19
20
  register(EventService);
20
21
  register(EventPlugin);
21
- register(PrepareRendererPlugin);
22
+ register(PrepareRendererPlugin); // register(CSSCalculatorPlugin);
23
+
22
24
  register(DirtyCheckPlugin);
23
25
  register(CullingPlugin);
24
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
  */
@@ -10,5 +10,5 @@ export interface ParsedCircleStyleProps extends ParsedBaseStyleProps {
10
10
  rInPixels: number;
11
11
  }
12
12
  export declare class Circle extends DisplayObject<CircleStyleProps, ParsedCircleStyleProps> {
13
- constructor({ style, ...rest }: DisplayObjectConfig<CircleStyleProps>);
13
+ constructor({ style, ...rest }?: DisplayObjectConfig<CircleStyleProps>);
14
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,18 +35,24 @@ 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
  */
49
50
  private changeAttribute;
51
+ /**
52
+ * returns different values than getBoundingClientRect(), as the latter returns value relative to the viewport
53
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGraphicsElement/getBBox
54
+ */
55
+ getBBox(): DOMRect;
50
56
  setOrigin(position: vec3 | vec2 | number, y?: number, z?: number): this;
51
57
  getOrigin(): vec3;
52
58
  /**
@@ -5,12 +5,12 @@ 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';
13
+ import { Rectangle } from '../shapes';
14
14
  var DEFAULT_STYLE_PROPS = {
15
15
  anchor: [0, 0, 0],
16
16
  origin: [0, 0, 0],
@@ -42,23 +42,18 @@ var DEFAULT_STYLE_PROPS = {
42
42
  var DisplayObject =
43
43
  /** @class */
44
44
  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
-
45
+ __extends(DisplayObject, _super);
52
46
 
53
47
  function DisplayObject(config) {
48
+ var _this = this;
49
+
54
50
  var _a, _b, _c;
55
51
 
56
- var _this = _super.call(this) || this;
52
+ _this = _super.call(this) || this;
57
53
  /**
58
54
  * push to active animations after calling `animate()`
59
55
  */
60
56
 
61
-
62
57
  _this.activeAnimations = []; // assign name, id to config
63
58
  // eg. group.get('name')
64
59
 
@@ -68,17 +63,38 @@ function (_super) {
68
63
 
69
64
  _this.id = _this.config.id || '';
70
65
  _this.name = _this.config.name || '';
71
- _this.className = _this.config.className || '';
66
+
67
+ if (_this.config.className || _this.config.class) {
68
+ _this.className = _this.config.className || _this.config.class;
69
+ }
70
+
72
71
  _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
72
+ _this.nodeName = _this.config.type || Shape.GROUP; // compatible with G 3.0
74
73
 
75
74
  _this.config.style = __assign(__assign(__assign(__assign({}, DEFAULT_STYLE_PROPS), {
76
75
  zIndex: (_c = _this.config.zIndex) !== null && _c !== void 0 ? _c : 0,
77
76
  visibility: _this.config.visible === false ? 'hidden' : 'visible'
78
77
  }), _this.config.style), _this.config.attrs);
79
- _this.style = new Proxy(_this.attributes, {
80
- get: function get(_, prop) {
81
- return _this.getAttribute(prop);
78
+ _this.style = new Proxy(__assign(__assign({}, _this.attributes), {
79
+ setProperty: function setProperty(propertyName, value) {
80
+ _this.setAttribute(propertyName, value);
81
+ },
82
+ getPropertyValue: function getPropertyValue(propertyName) {
83
+ return _this.getAttribute(propertyName);
84
+ },
85
+ removeProperty: function removeProperty(propertyName) {
86
+ _this.removeAttribute(propertyName);
87
+ },
88
+ item: function item() {
89
+ return '';
90
+ }
91
+ }), {
92
+ get: function get(target, name) {
93
+ if (name in target) {
94
+ return target[name];
95
+ }
96
+
97
+ return _this.getAttribute(name);
82
98
  },
83
99
  set: function set(_, prop, value) {
84
100
  _this.setAttribute(prop, value);
@@ -113,7 +129,7 @@ function (_super) {
113
129
  name: this.name,
114
130
  className: this.name,
115
131
  interactive: this.interactive,
116
- style: __assign({}, this.style)
132
+ style: __assign({}, this.attributes)
117
133
  });
118
134
 
119
135
  if (deep) {
@@ -136,51 +152,62 @@ function (_super) {
136
152
  var renderable = this.renderable; // parse attributes first
137
153
 
138
154
  for (var attributeName in attributes) {
139
- var value = attributes[attributeName];
140
- this.attributes[attributeName] = value; // @ts-ignore
155
+ var _a = __read(formatAttribute(attributeName, attributes[attributeName]), 2),
156
+ name_1 = _a[0],
157
+ value = _a[1];
158
+
159
+ this.attributes[name_1] = value; // @ts-ignore
141
160
 
142
- this.parseStyleProperty(attributeName, value);
161
+ this.parseStyleProperty(name_1, value);
143
162
  }
144
163
 
145
164
  var priorities = {
146
- x: 1000,
147
- y: 1000
165
+ x: Infinity,
166
+ y: Infinity
148
167
  }; // update x, y at last
149
168
 
150
169
  var sortedNames = Object.keys(attributes).sort(function (a, b) {
151
170
  return (priorities[a] || 0) - (priorities[b] || 0);
152
171
  });
153
172
  sortedNames.forEach(function (attributeName) {
154
- // @ts-ignore
155
- _this.updateStyleProperty(attributeName, undefined, _this.parsedStyle[attributeName]);
173
+ var _a = __read(formatAttribute(attributeName, ''), 1),
174
+ name = _a[0]; // @ts-ignore
175
+
176
+
177
+ _this.updateStyleProperty(name, undefined, _this.parsedStyle[name]);
156
178
  }); // redraw at next frame
157
179
 
158
180
  renderable.dirty = true;
159
181
  };
160
182
 
161
- DisplayObject.prototype.setAttribute = function (attributeName, value, force) {
183
+ DisplayObject.prototype.setAttribute = function (name, value, force) {
162
184
  if (force === void 0) {
163
185
  force = false;
164
186
  }
165
187
 
166
- if (force || !isEqual(value, this.attributes[attributeName]) || attributeName === 'transformOrigin' || attributeName === 'visibility' // will affect children
188
+ var _a = __read(formatAttribute(name, value), 2),
189
+ attributeName = _a[0],
190
+ attributeValue = _a[1];
191
+
192
+ if (force || !isEqual(attributeValue, this.attributes[attributeName]) || attributeName === 'transformOrigin' || attributeName === 'visibility' // will affect children
167
193
  ) {
168
194
  if (attributeName === 'visibility') {
169
195
  // set value cascade
170
196
  this.forEach(function (object) {
171
- object.changeAttribute(attributeName, value);
197
+ object.changeAttribute(attributeName, attributeValue);
172
198
  });
173
199
  } else {
174
- this.changeAttribute(attributeName, value);
200
+ this.changeAttribute(attributeName, attributeValue);
175
201
  }
176
202
 
177
- _super.prototype.setAttribute.call(this, attributeName, value);
203
+ _super.prototype.setAttribute.call(this, attributeName, attributeValue);
178
204
  }
179
205
  };
180
206
  /**
181
207
  * parse property, eg.
182
208
  * * fill: 'red' => [1, 0, 0, 1]
183
209
  * * translateX: '10px' => { unit: 'px', value: 10 }
210
+ * * fontSize: '2em' => { unit: 'px', value: 32 }
184
211
  */
185
212
 
186
213
 
@@ -190,16 +217,14 @@ function (_super) {
190
217
 
191
218
  if (stylePropertyParser) {
192
219
  // @ts-ignore
193
- this.parsedStyle[name] = stylePropertyParser(value, this);
220
+ this.parsedStyle[name] = stylePropertyParser(value, this, name);
194
221
  } else {
195
222
  this.parsedStyle[name] = value;
196
223
  }
197
224
  };
198
225
 
199
226
  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);
227
+ var _this = this; // @ts-ignore
203
228
 
204
229
 
205
230
  var stylePropertyUpdaters = stylePropertyUpdaterFactory[name];
@@ -207,7 +232,7 @@ function (_super) {
207
232
  if (stylePropertyUpdaters) {
208
233
  stylePropertyUpdaters.forEach(function (updater) {
209
234
  // @ts-ignore
210
- updater(oldParsedValue, newParsedValue, _this, _this.sceneGraphService);
235
+ updater(oldParsedValue, newParsedValue, _this, _this.sceneGraphService, name);
211
236
  });
212
237
  }
213
238
  };
@@ -234,26 +259,48 @@ function (_super) {
234
259
 
235
260
  if (this.attributes.clipPathTargets && this.attributes.clipPathTargets.length) {
236
261
  this.attributes.clipPathTargets.forEach(function (target) {
237
- dirtifyToRoot(target);
238
- target.emit(ElementEvent.ATTRIBUTE_CHANGED, {
239
- attributeName: 'clipPath',
240
- oldValue: _this,
241
- newValue: _this
242
- });
262
+ dirtifyToRoot(target); // target.emit(ElementEvent.ATTR_MODIFIED, {
263
+ // attributeName: 'clipPath',
264
+ // oldValue: this,
265
+ // newValue: this,
266
+ // });
267
+
268
+ target.dispatchEvent(new MutationEvent(ElementEvent.ATTR_MODIFIED, target, _this, _this, 'clipPath', MutationEvent.MODIFICATION, _this, _this));
243
269
  });
244
270
  } // redraw at next frame
245
271
 
246
272
 
247
273
  renderable.dirty = true;
248
- this.emit(ElementEvent.ATTRIBUTE_CHANGED, {
249
- attributeName: name,
250
- oldValue: oldValue,
251
- newValue: value,
252
- oldParsedValue: oldParsedValue,
253
- newParsedValue: newParsedValue
254
- });
274
+ this.dispatchEvent(new MutationEvent(ElementEvent.ATTR_MODIFIED, this, oldValue, value, name, MutationEvent.MODIFICATION, oldParsedValue, newParsedValue)); // this.emit(ElementEvent.ATTR_MODIFIED, {
275
+ // attrName: name,
276
+ // attributeName: name,
277
+ // prevValue: oldValue,
278
+ // oldValue,
279
+ // newValue: value,
280
+ // oldParsedValue,
281
+ // newParsedValue,
282
+ // });
255
283
  }; // #region transformable
256
284
 
285
+ /**
286
+ * returns different values than getBoundingClientRect(), as the latter returns value relative to the viewport
287
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGraphicsElement/getBBox
288
+ */
289
+
290
+
291
+ DisplayObject.prototype.getBBox = function () {
292
+ var aabb = this.getBounds();
293
+
294
+ var _a = __read(aabb.getMin(), 2),
295
+ left = _a[0],
296
+ top = _a[1];
297
+
298
+ var _b = __read(aabb.getMax(), 2),
299
+ right = _b[0],
300
+ bottom = _b[1];
301
+
302
+ return new Rectangle(left, top, right - left, bottom - top);
303
+ };
257
304
 
258
305
  DisplayObject.prototype.setOrigin = function (position, y, z) {
259
306
  if (y === void 0) {
@@ -575,7 +622,7 @@ function (_super) {
575
622
 
576
623
  DisplayObject.prototype.isVisible = function () {
577
624
  var cullable = this.cullable;
578
- return this.style.visibility === 'visible' && (!cullable || cullable && !cullable.isCulled());
625
+ return this.getAttribute('visibility') === 'visible' && (!cullable || cullable && !cullable.isCulled());
579
626
  };
580
627
  /**
581
628
  * bring to front in current group
@@ -13,5 +13,5 @@ export interface ParsedEllipseStyleProps extends ParsedBaseStyleProps {
13
13
  ryInPixels: number;
14
14
  }
15
15
  export declare class Ellipse extends DisplayObject<EllipseStyleProps, ParsedEllipseStyleProps> {
16
- constructor({ style, ...rest }: DisplayObjectConfig<EllipseStyleProps>);
16
+ constructor({ style, ...rest }?: DisplayObjectConfig<EllipseStyleProps>);
17
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
  }
@@ -1,6 +1,22 @@
1
- import type { BaseStyleProps } from '../types';
1
+ import type { BaseStyleProps, ParsedBaseStyleProps, TextAlign } from '../types';
2
2
  import { DisplayObject } from './DisplayObject';
3
3
  import type { DisplayObjectConfig } from '../dom';
4
+ import type { ParsedElement } from '../property-handlers';
5
+ export interface GroupStyleProps extends BaseStyleProps {
6
+ width?: number | string;
7
+ height?: number | string;
8
+ textAlign?: TextAlign | 'inherit';
9
+ fontSize?: number | string | 'inherit';
10
+ fontFamily?: string;
11
+ }
12
+ export interface ParsedGroupStyleProps extends ParsedBaseStyleProps {
13
+ width?: ParsedElement;
14
+ height?: ParsedElement;
15
+ widthInPixels?: number;
16
+ heightInPixels?: number;
17
+ textAlign?: TextAlign;
18
+ fontSize?: ParsedElement;
19
+ }
4
20
  export declare class Group extends DisplayObject {
5
- constructor(config?: DisplayObjectConfig<BaseStyleProps>);
21
+ constructor({ style, ...rest }?: DisplayObjectConfig<GroupStyleProps>);
6
22
  }