@antv/g 5.0.15 → 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 (224) hide show
  1. package/dist/index.umd.min.js +18 -2
  2. package/es/Canvas.d.ts +3 -0
  3. package/es/Canvas.js +8 -9
  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 +4 -3
  14. package/es/display-objects/DisplayObject.js +77 -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 +9 -4
  34. package/es/display-objects/Text.js +14 -9
  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 +10 -5
  41. package/es/dom/Element.js +41 -15
  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 +1 -0
  58. package/es/global-module.js +11 -13
  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 +19 -20
  68. package/es/property-handlers/color.js +5 -2
  69. package/es/property-handlers/dimension.d.ts +15 -3
  70. package/es/property-handlers/dimension.js +50 -9
  71. package/es/property-handlers/index.d.ts +3 -0
  72. package/es/property-handlers/index.js +4 -1
  73. package/es/property-handlers/inherit.d.ts +6 -0
  74. package/es/property-handlers/inherit.js +25 -0
  75. package/es/property-handlers/interfaces.d.ts +2 -2
  76. package/es/property-handlers/lineDash.d.ts +6 -1
  77. package/es/property-handlers/lineDash.js +23 -4
  78. package/es/property-handlers/offsetDistance.js +2 -2
  79. package/es/property-handlers/text.d.ts +2 -0
  80. package/es/property-handlers/text.js +3 -0
  81. package/es/property-handlers/textTransform.d.ts +6 -0
  82. package/es/property-handlers/textTransform.js +19 -0
  83. package/es/services/EventService.js +3 -5
  84. package/es/services/RenderingContext.d.ts +5 -8
  85. package/es/services/RenderingContext.js +6 -7
  86. package/es/services/RenderingService.js +2 -8
  87. package/es/services/SceneGraphSelector.d.ts +3 -2
  88. package/es/services/SceneGraphSelector.js +8 -4
  89. package/es/services/SceneGraphService.d.ts +0 -7
  90. package/es/services/SceneGraphService.js +9 -77
  91. package/es/services/aabb/CircleUpdater.js +3 -3
  92. package/es/services/aabb/EllipseUpdater.js +2 -2
  93. package/es/services/aabb/LineUpdater.js +2 -2
  94. package/es/services/aabb/PathUpdater.js +2 -2
  95. package/es/services/aabb/PolylineUpdater.js +3 -3
  96. package/es/services/aabb/RectUpdater.js +4 -4
  97. package/es/services/aabb/TextUpdater.js +19 -10
  98. package/es/services/text/index.js +19 -21
  99. package/es/types.d.ts +48 -24
  100. package/es/types.js +50 -31
  101. package/es/utils/custom-easing.js +1 -1
  102. package/es/utils/event.js +5 -3
  103. package/es/utils/index.d.ts +1 -0
  104. package/es/utils/index.js +2 -1
  105. package/es/utils/interpolation.d.ts +1 -0
  106. package/es/utils/interpolation.js +41 -8
  107. package/es/utils/path.js +11 -11
  108. package/es/utils/raf.d.ts +1 -1
  109. package/es/utils/raf.js +0 -2
  110. package/es/utils/string.d.ts +1 -0
  111. package/es/utils/string.js +9 -0
  112. package/es/utils/text.js +3 -3
  113. package/lib/Canvas.d.ts +3 -0
  114. package/lib/Canvas.js +6 -7
  115. package/lib/camera/Camera.d.ts +3 -2
  116. package/lib/camera/Camera.js +20 -10
  117. package/lib/canvas-module.js +3 -1
  118. package/lib/components/Transform.d.ts +0 -1
  119. package/lib/components/Transform.js +0 -1
  120. package/lib/display-objects/Circle.d.ts +1 -1
  121. package/lib/display-objects/Circle.js +7 -2
  122. package/lib/display-objects/CustomElement.d.ts +3 -2
  123. package/lib/display-objects/CustomElement.js +9 -6
  124. package/lib/display-objects/DisplayObject.d.ts +4 -3
  125. package/lib/display-objects/DisplayObject.js +76 -47
  126. package/lib/display-objects/Ellipse.d.ts +1 -1
  127. package/lib/display-objects/Ellipse.js +7 -2
  128. package/lib/display-objects/Group.d.ts +18 -2
  129. package/lib/display-objects/Group.js +10 -9
  130. package/lib/display-objects/HTML.d.ts +1 -1
  131. package/lib/display-objects/HTML.js +8 -4
  132. package/lib/display-objects/Image.d.ts +5 -3
  133. package/lib/display-objects/Image.js +7 -2
  134. package/lib/display-objects/Line.d.ts +1 -1
  135. package/lib/display-objects/Line.js +11 -3
  136. package/lib/display-objects/Path.d.ts +3 -2
  137. package/lib/display-objects/Path.js +9 -4
  138. package/lib/display-objects/Polygon.d.ts +1 -1
  139. package/lib/display-objects/Polygon.js +8 -2
  140. package/lib/display-objects/Polyline.d.ts +1 -1
  141. package/lib/display-objects/Polyline.js +9 -4
  142. package/lib/display-objects/Rect.d.ts +1 -1
  143. package/lib/display-objects/Rect.js +7 -2
  144. package/lib/display-objects/Text.d.ts +9 -4
  145. package/lib/display-objects/Text.js +13 -8
  146. package/lib/dom/Animation.js +1 -1
  147. package/lib/dom/AnimationTimeline.js +1 -2
  148. package/lib/dom/CustomElementRegistry.js +11 -11
  149. package/lib/dom/Document.d.ts +1 -0
  150. package/lib/dom/Document.js +22 -1
  151. package/lib/dom/Element.d.ts +10 -5
  152. package/lib/dom/Element.js +43 -15
  153. package/lib/dom/EventTarget.d.ts +2 -2
  154. package/lib/dom/EventTarget.js +4 -3
  155. package/lib/dom/KeyframeList.js +1 -1
  156. package/lib/dom/MutationEvent.d.ts +15 -0
  157. package/lib/dom/MutationEvent.js +37 -0
  158. package/lib/dom/MutationObserver.d.ts +36 -0
  159. package/lib/dom/MutationObserver.js +424 -0
  160. package/lib/dom/MutationRecord.d.ts +14 -0
  161. package/lib/dom/MutationRecord.js +38 -0
  162. package/lib/dom/Node.d.ts +35 -3
  163. package/lib/dom/Node.js +185 -16
  164. package/lib/dom/index.d.ts +3 -0
  165. package/lib/dom/index.js +39 -0
  166. package/lib/dom/interfaces.d.ts +36 -8
  167. package/lib/dom/interfaces.js +23 -5
  168. package/lib/global-module.d.ts +1 -0
  169. package/lib/global-module.js +12 -8
  170. package/lib/index.d.ts +1 -0
  171. package/lib/index.js +3 -1
  172. package/lib/plugins/CullingPlugin.d.ts +0 -2
  173. package/lib/plugins/CullingPlugin.js +2 -23
  174. package/lib/plugins/DirtyCheckPlugin.js +1 -1
  175. package/lib/plugins/FrustumCullingStrategy.d.ts +1 -0
  176. package/lib/plugins/FrustumCullingStrategy.js +41 -33
  177. package/lib/plugins/PrepareRendererPlugin.js +24 -4
  178. package/lib/property-handlers/aabb.js +18 -19
  179. package/lib/property-handlers/color.js +6 -3
  180. package/lib/property-handlers/dimension.d.ts +15 -3
  181. package/lib/property-handlers/dimension.js +50 -8
  182. package/lib/property-handlers/index.d.ts +3 -0
  183. package/lib/property-handlers/index.js +39 -0
  184. package/lib/property-handlers/inherit.d.ts +6 -0
  185. package/lib/property-handlers/inherit.js +34 -0
  186. package/lib/property-handlers/interfaces.d.ts +2 -2
  187. package/lib/property-handlers/lineDash.d.ts +6 -1
  188. package/lib/property-handlers/lineDash.js +25 -4
  189. package/lib/property-handlers/offsetDistance.js +1 -1
  190. package/lib/property-handlers/text.d.ts +2 -0
  191. package/lib/property-handlers/text.js +10 -0
  192. package/lib/property-handlers/textTransform.d.ts +6 -0
  193. package/lib/property-handlers/textTransform.js +27 -0
  194. package/lib/services/EventService.js +3 -5
  195. package/lib/services/RenderingContext.d.ts +5 -8
  196. package/lib/services/RenderingContext.js +8 -9
  197. package/lib/services/RenderingService.js +1 -7
  198. package/lib/services/SceneGraphSelector.d.ts +3 -2
  199. package/lib/services/SceneGraphSelector.js +10 -3
  200. package/lib/services/SceneGraphService.d.ts +0 -7
  201. package/lib/services/SceneGraphService.js +10 -77
  202. package/lib/services/aabb/CircleUpdater.js +2 -2
  203. package/lib/services/aabb/EllipseUpdater.js +1 -1
  204. package/lib/services/aabb/LineUpdater.js +1 -1
  205. package/lib/services/aabb/PathUpdater.js +1 -1
  206. package/lib/services/aabb/PolylineUpdater.js +2 -2
  207. package/lib/services/aabb/RectUpdater.js +3 -3
  208. package/lib/services/aabb/TextUpdater.js +18 -9
  209. package/lib/services/text/index.js +19 -21
  210. package/lib/types.d.ts +48 -24
  211. package/lib/types.js +56 -35
  212. package/lib/utils/custom-easing.js +1 -1
  213. package/lib/utils/event.js +5 -3
  214. package/lib/utils/index.d.ts +1 -0
  215. package/lib/utils/index.js +13 -0
  216. package/lib/utils/interpolation.d.ts +1 -0
  217. package/lib/utils/interpolation.js +43 -7
  218. package/lib/utils/path.js +10 -10
  219. package/lib/utils/raf.d.ts +1 -1
  220. package/lib/utils/raf.js +0 -2
  221. package/lib/utils/string.d.ts +1 -0
  222. package/lib/utils/string.js +16 -0
  223. package/lib/utils/text.js +3 -3
  224. package/package.json +5 -3
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;
@@ -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,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
  };
@@ -234,24 +258,27 @@ function (_super) {
234
258
 
235
259
  if (this.attributes.clipPathTargets && this.attributes.clipPathTargets.length) {
236
260
  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
- });
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));
243
268
  });
244
269
  } // redraw at next frame
245
270
 
246
271
 
247
272
  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
- });
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
+ // });
255
282
  }; // #region transformable
256
283
 
257
284
 
@@ -575,7 +602,7 @@ function (_super) {
575
602
 
576
603
  DisplayObject.prototype.isVisible = function () {
577
604
  var cullable = this.cullable;
578
- return this.style.visibility === 'visible' && (!cullable || cullable && !cullable.isCulled());
605
+ return this.getAttribute('visibility') === 'visible' && (!cullable || cullable && !cullable.isCulled());
579
606
  };
580
607
  /**
581
608
  * 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
  }
@@ -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 Group =
@@ -7,21 +7,23 @@ var Group =
7
7
  function (_super) {
8
8
  __extends(Group, _super);
9
9
 
10
- function Group(config) {
11
- var _this = this;
10
+ function Group(_a) {
11
+ if (_a === void 0) {
12
+ _a = {};
13
+ }
12
14
 
13
- var _a = config || {},
14
- style = _a.style,
15
+ var style = _a.style,
15
16
  rest = __rest(_a, ["style"]);
16
17
 
17
- _this = _super.call(this, __assign({
18
- type: SHAPE.Group,
18
+ return _super.call(this, __assign({
19
+ type: Shape.GROUP,
19
20
  style: __assign({
20
21
  width: 'auto',
21
- height: 'auto'
22
+ height: 'auto',
23
+ textAlign: 'inherit',
24
+ fontSize: 'inherit'
22
25
  }, style)
23
26
  }, rest)) || this;
24
- return _this;
25
27
  }
26
28
 
27
29
  return Group;
@@ -23,7 +23,7 @@ export interface ParsedHTMLStyleProps extends ParsedBaseStyleProps {
23
23
  * @see https://github.com/pmndrs/drei#html
24
24
  */
25
25
  export declare class HTML extends DisplayObject<HTMLStyleProps, ParsedHTMLStyleProps> {
26
- constructor({ style, ...rest }: DisplayObjectConfig<HTMLStyleProps>);
26
+ constructor({ style, ...rest }?: DisplayObjectConfig<HTMLStyleProps>);
27
27
  /**
28
28
  * return wrapper HTMLElement
29
29
  * * <div> in g-webgl/canvas