@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
@@ -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
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.DefaultCamera = exports.Camera = exports.CAMERA_TYPE = exports.CAMERA_TRACKING_MODE = exports.CAMERA_PROJECTION_MODE = exports.CAMERA_EVENT = void 0;
6
+ exports.DefaultCamera = exports.CameraEvent = exports.Camera = exports.CAMERA_TYPE = exports.CAMERA_TRACKING_MODE = exports.CAMERA_PROJECTION_MODE = void 0;
7
7
 
8
8
  var _tslib = require("tslib");
9
9
 
@@ -48,10 +48,10 @@ exports.CAMERA_PROJECTION_MODE = CAMERA_PROJECTION_MODE;
48
48
  CAMERA_PROJECTION_MODE["PERSPECTIVE"] = "PERSPECTIVE";
49
49
  })(CAMERA_PROJECTION_MODE || (exports.CAMERA_PROJECTION_MODE = CAMERA_PROJECTION_MODE = {}));
50
50
 
51
- var CAMERA_EVENT = {
52
- Updated: 'updated'
51
+ var CameraEvent = {
52
+ UPDATED: 'updated'
53
53
  };
54
- exports.CAMERA_EVENT = CAMERA_EVENT;
54
+ exports.CameraEvent = CameraEvent;
55
55
  var DEG_2_RAD = Math.PI / 180;
56
56
  var RAD_2_DEG = 180 / Math.PI;
57
57
  /**
@@ -437,7 +437,7 @@ function (_super) {
437
437
 
438
438
  _glMatrix.mat4.invert(this.projectionMatrixInverse, this.projectionMatrix);
439
439
 
440
- this.emit(CAMERA_EVENT.Updated);
440
+ this.triggerUpdate();
441
441
  return this;
442
442
  };
443
443
 
@@ -476,7 +476,7 @@ function (_super) {
476
476
 
477
477
  this._getOrthoMatrix();
478
478
 
479
- this.emit(CAMERA_EVENT.Updated);
479
+ this.triggerUpdate();
480
480
  return this;
481
481
  };
482
482
  /**
@@ -741,7 +741,7 @@ function (_super) {
741
741
 
742
742
  this._setPosition(pos);
743
743
 
744
- this.emit(CAMERA_EVENT.Updated);
744
+ this.triggerUpdate();
745
745
  return this;
746
746
  };
747
747
  /**
@@ -772,7 +772,7 @@ function (_super) {
772
772
  _glMatrix.vec3.add(this.focalPoint, pos, this.distanceVector);
773
773
  }
774
774
 
775
- this.emit(CAMERA_EVENT.Updated);
775
+ this.triggerUpdate();
776
776
  return this;
777
777
  };
778
778
 
@@ -853,7 +853,7 @@ function (_super) {
853
853
 
854
854
  _this.computeMatrix();
855
855
 
856
- _this.emit(CAMERA_EVENT.Updated);
856
+ _this.triggerUpdate();
857
857
 
858
858
  var dist = _glMatrix.vec3.dist(interFocalPoint, destFocalPoint_1) + _glMatrix.vec3.dist(interPosition, destPosition_1);
859
859
 
@@ -895,7 +895,7 @@ function (_super) {
895
895
 
896
896
  this._getOrthoMatrix();
897
897
 
898
- this.emit(CAMERA_EVENT.Updated);
898
+ this.triggerUpdate();
899
899
  };
900
900
  /**
901
901
  * 计算相机矩阵
@@ -1045,6 +1045,16 @@ function (_super) {
1045
1045
  _glMatrix.mat4.fromRotationTranslationScaleOrigin(this.orthoMatrix, rotZ, _glMatrix.vec3.fromValues((this.rright - this.left) / 2 - position[0], (this.top - this.bottom) / 2 - position[1], 0), _glMatrix.vec3.fromValues(this.zoom, this.zoom, 1), position);
1046
1046
  };
1047
1047
 
1048
+ Camera.prototype.triggerUpdate = function () {
1049
+ // update frustum
1050
+ var viewMatrix = this.getViewTransform();
1051
+
1052
+ var vpMatrix = _glMatrix.mat4.multiply(_glMatrix.mat4.create(), this.getPerspective(), viewMatrix);
1053
+
1054
+ this.getFrustum().extractFromVPMatrix(vpMatrix);
1055
+ this.emit(CameraEvent.UPDATED);
1056
+ };
1057
+
1048
1058
  Camera.ProjectionMode = {
1049
1059
  ORTHOGRAPHIC: 'ORTHOGRAPHIC',
1050
1060
  PERSPECTIVE: 'PERSPECTIVE'
@@ -19,6 +19,7 @@ var _services = require("./services");
19
19
 
20
20
  var _EventPlugin = require("./plugins/EventPlugin");
21
21
 
22
+ // import { CSSCalculatorPlugin } from './plugins/CSSStyleCalculator';
22
23
  var containerModule = (0, _manaSyringe.Module)(function (register) {
23
24
  _manaSyringe.Contribution.register(register, _services.RenderingPluginContribution, {
24
25
  cache: false
@@ -33,7 +34,8 @@ var containerModule = (0, _manaSyringe.Module)(function (register) {
33
34
  register(_services.RenderingService);
34
35
  register(_services.EventService);
35
36
  register(_EventPlugin.EventPlugin);
36
- register(_PrepareRendererPlugin.PrepareRendererPlugin);
37
+ register(_PrepareRendererPlugin.PrepareRendererPlugin); // register(CSSCalculatorPlugin);
38
+
37
39
  register(_DirtyCheckPlugin.DirtyCheckPlugin);
38
40
  register(_CullingPlugin.CullingPlugin);
39
41
  register(_FrustumCullingStrategy.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
  */
@@ -17,7 +17,6 @@ function () {
17
17
  this.dirtyFlag = false;
18
18
  this.localDirtyFlag = false;
19
19
  this.frozen = false;
20
- this.graphDepth = 0;
21
20
  /**
22
21
  * local space RTS
23
22
  */
@@ -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
  }
@@ -17,13 +17,18 @@ function (_super) {
17
17
  (0, _tslib.__extends)(Circle, _super);
18
18
 
19
19
  function Circle(_a) {
20
+ if (_a === void 0) {
21
+ _a = {};
22
+ }
23
+
20
24
  var style = _a.style,
21
25
  rest = (0, _tslib.__rest)(_a, ["style"]);
22
26
  return _super.call(this, (0, _tslib.__assign)({
23
- type: _types.SHAPE.Circle,
27
+ type: _types.Shape.CIRCLE,
24
28
  style: (0, _tslib.__assign)({
25
29
  r: 0,
26
- anchor: [0.5, 0.5]
30
+ anchor: [0.5, 0.5],
31
+ lineWidth: 0
27
32
  }, style)
28
33
  }, rest)) || this;
29
34
  }
@@ -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
  */
@@ -21,6 +21,10 @@ function (_super) {
21
21
  (0, _tslib.__extends)(CustomElement, _super); // private shadowNodes: DisplayObject[] = [];
22
22
 
23
23
  function CustomElement(config) {
24
+ if (config === void 0) {
25
+ config = {};
26
+ }
27
+
24
28
  var _this = _super.call(this, config) || this;
25
29
 
26
30
  _this.handleMounted = function (e) {
@@ -64,20 +68,19 @@ function (_super) {
64
68
  return;
65
69
  }
66
70
 
67
- var _a = e.detail,
68
- attributeName = _a.attributeName,
69
- oldValue = _a.oldValue,
70
- newValue = _a.newValue;
71
+ var attrName = e.attrName,
72
+ prevValue = e.prevValue,
73
+ newValue = e.newValue;
71
74
 
72
75
  if (_this.attributeChangedCallback) {
73
- _this.attributeChangedCallback(attributeName, oldValue, newValue);
76
+ _this.attributeChangedCallback(attrName, prevValue, newValue);
74
77
  }
75
78
  }; // this.addEventListener(ElementEvent.CHILD_INSERTED, this.handleChildInserted);
76
79
  // this.addEventListener(ElementEvent.CHILD_REMOVED, this.handleChildRemoved);
77
80
 
78
81
 
79
82
  if (_this.attributeChangedCallback) {
80
- _this.addEventListener(_interfaces.ElementEvent.ATTRIBUTE_CHANGED, _this.handleAttributeChanged);
83
+ _this.addEventListener(_interfaces.ElementEvent.ATTR_MODIFIED, _this.handleAttributeChanged);
81
84
  }
82
85
 
83
86
  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
  /**
@@ -27,8 +27,10 @@ var _globalModule = require("../global-module");
27
27
 
28
28
  var _services = require("../services");
29
29
 
30
- // import type { StylePropertyParser, StylePropertyUpdater } from '../property-handlers';
31
- // import { StylePropertyParserFactory, StylePropertyUpdaterFactory } from '../property-handlers';
30
+ var _MutationEvent = require("../dom/MutationEvent");
31
+
32
+ var _shapes = require("../shapes");
33
+
32
34
  var DEFAULT_STYLE_PROPS = {
33
35
  anchor: [0, 0, 0],
34
36
  origin: [0, 0, 0],
@@ -60,22 +62,18 @@ var DEFAULT_STYLE_PROPS = {
60
62
  var DisplayObject =
61
63
  /** @class */
62
64
  function (_super) {
63
- (0, _tslib.__extends)(DisplayObject, _super); // stylePropertyUpdaterFactory = globalContainer.get<
64
- // <Key extends keyof StyleProps>(stylePropertyName: Key) => StylePropertyUpdater<any>[]
65
- // >(StylePropertyUpdaterFactory);
66
- // stylePropertyParserFactory = globalContainer.get<
67
- // <Key extends keyof ParsedStyleProps>(stylePropertyName: Key) => StylePropertyParser<any, any>
68
- // >(StylePropertyParserFactory);
65
+ (0, _tslib.__extends)(DisplayObject, _super);
69
66
 
70
67
  function DisplayObject(config) {
68
+ var _this = this;
69
+
71
70
  var _a, _b, _c;
72
71
 
73
- var _this = _super.call(this) || this;
72
+ _this = _super.call(this) || this;
74
73
  /**
75
74
  * push to active animations after calling `animate()`
76
75
  */
77
76
 
78
-
79
77
  _this.activeAnimations = []; // assign name, id to config
80
78
  // eg. group.get('name')
81
79
 
@@ -85,17 +83,38 @@ function (_super) {
85
83
 
86
84
  _this.id = _this.config.id || '';
87
85
  _this.name = _this.config.name || '';
88
- _this.className = _this.config.className || '';
86
+
87
+ if (_this.config.className || _this.config.class) {
88
+ _this.className = _this.config.className || _this.config.class;
89
+ }
90
+
89
91
  _this.interactive = (_b = _this.config.interactive) !== null && _b !== void 0 ? _b : true;
90
- _this.nodeName = _this.config.type || _types.SHAPE.Group; // compatible with G 3.0
92
+ _this.nodeName = _this.config.type || _types.Shape.GROUP; // compatible with G 3.0
91
93
 
92
94
  _this.config.style = (0, _tslib.__assign)((0, _tslib.__assign)((0, _tslib.__assign)((0, _tslib.__assign)({}, DEFAULT_STYLE_PROPS), {
93
95
  zIndex: (_c = _this.config.zIndex) !== null && _c !== void 0 ? _c : 0,
94
96
  visibility: _this.config.visible === false ? 'hidden' : 'visible'
95
97
  }), _this.config.style), _this.config.attrs);
96
- _this.style = new Proxy(_this.attributes, {
97
- get: function get(_, prop) {
98
- return _this.getAttribute(prop);
98
+ _this.style = new Proxy((0, _tslib.__assign)((0, _tslib.__assign)({}, _this.attributes), {
99
+ setProperty: function setProperty(propertyName, value) {
100
+ _this.setAttribute(propertyName, value);
101
+ },
102
+ getPropertyValue: function getPropertyValue(propertyName) {
103
+ return _this.getAttribute(propertyName);
104
+ },
105
+ removeProperty: function removeProperty(propertyName) {
106
+ _this.removeAttribute(propertyName);
107
+ },
108
+ item: function item() {
109
+ return '';
110
+ }
111
+ }), {
112
+ get: function get(target, name) {
113
+ if (name in target) {
114
+ return target[name];
115
+ }
116
+
117
+ return _this.getAttribute(name);
99
118
  },
100
119
  set: function set(_, prop, value) {
101
120
  _this.setAttribute(prop, value);
@@ -132,7 +151,7 @@ function (_super) {
132
151
  name: this.name,
133
152
  className: this.name,
134
153
  interactive: this.interactive,
135
- style: (0, _tslib.__assign)({}, this.style)
154
+ style: (0, _tslib.__assign)({}, this.attributes)
136
155
  });
137
156
 
138
157
  if (deep) {
@@ -155,51 +174,62 @@ function (_super) {
155
174
  var renderable = this.renderable; // parse attributes first
156
175
 
157
176
  for (var attributeName in attributes) {
158
- var value = attributes[attributeName];
159
- this.attributes[attributeName] = value; // @ts-ignore
177
+ var _a = (0, _tslib.__read)((0, _utils.formatAttribute)(attributeName, attributes[attributeName]), 2),
178
+ name_1 = _a[0],
179
+ value = _a[1];
180
+
181
+ this.attributes[name_1] = value; // @ts-ignore
160
182
 
161
- this.parseStyleProperty(attributeName, value);
183
+ this.parseStyleProperty(name_1, value);
162
184
  }
163
185
 
164
186
  var priorities = {
165
- x: 1000,
166
- y: 1000
187
+ x: Infinity,
188
+ y: Infinity
167
189
  }; // update x, y at last
168
190
 
169
191
  var sortedNames = Object.keys(attributes).sort(function (a, b) {
170
192
  return (priorities[a] || 0) - (priorities[b] || 0);
171
193
  });
172
194
  sortedNames.forEach(function (attributeName) {
173
- // @ts-ignore
174
- _this.updateStyleProperty(attributeName, undefined, _this.parsedStyle[attributeName]);
195
+ var _a = (0, _tslib.__read)((0, _utils.formatAttribute)(attributeName, ''), 1),
196
+ name = _a[0]; // @ts-ignore
197
+
198
+
199
+ _this.updateStyleProperty(name, undefined, _this.parsedStyle[name]);
175
200
  }); // redraw at next frame
176
201
 
177
202
  renderable.dirty = true;
178
203
  };
179
204
 
180
- DisplayObject.prototype.setAttribute = function (attributeName, value, force) {
205
+ DisplayObject.prototype.setAttribute = function (name, value, force) {
181
206
  if (force === void 0) {
182
207
  force = false;
183
208
  }
184
209
 
185
- if (force || !(0, _util.isEqual)(value, this.attributes[attributeName]) || attributeName === 'transformOrigin' || attributeName === 'visibility' // will affect children
210
+ var _a = (0, _tslib.__read)((0, _utils.formatAttribute)(name, value), 2),
211
+ attributeName = _a[0],
212
+ attributeValue = _a[1];
213
+
214
+ if (force || !(0, _util.isEqual)(attributeValue, this.attributes[attributeName]) || attributeName === 'transformOrigin' || attributeName === 'visibility' // will affect children
186
215
  ) {
187
216
  if (attributeName === 'visibility') {
188
217
  // set value cascade
189
218
  this.forEach(function (object) {
190
- object.changeAttribute(attributeName, value);
219
+ object.changeAttribute(attributeName, attributeValue);
191
220
  });
192
221
  } else {
193
- this.changeAttribute(attributeName, value);
222
+ this.changeAttribute(attributeName, attributeValue);
194
223
  }
195
224
 
196
- _super.prototype.setAttribute.call(this, attributeName, value);
225
+ _super.prototype.setAttribute.call(this, attributeName, attributeValue);
197
226
  }
198
227
  };
199
228
  /**
200
229
  * parse property, eg.
201
230
  * * fill: 'red' => [1, 0, 0, 1]
202
231
  * * translateX: '10px' => { unit: 'px', value: 10 }
232
+ * * fontSize: '2em' => { unit: 'px', value: 32 }
203
233
  */
204
234
 
205
235
 
@@ -209,16 +239,14 @@ function (_super) {
209
239
 
210
240
  if (stylePropertyParser) {
211
241
  // @ts-ignore
212
- this.parsedStyle[name] = stylePropertyParser(value, this);
242
+ this.parsedStyle[name] = stylePropertyParser(value, this, name);
213
243
  } else {
214
244
  this.parsedStyle[name] = value;
215
245
  }
216
246
  };
217
247
 
218
248
  DisplayObject.prototype.updateStyleProperty = function (name, oldParsedValue, newParsedValue) {
219
- var _this = this; // update property, which may cause AABB re-calc
220
- // @ts-ignore
221
- // const stylePropertyUpdaters = this.stylePropertyUpdaterFactory(name);
249
+ var _this = this; // @ts-ignore
222
250
 
223
251
 
224
252
  var stylePropertyUpdaters = _globalModule.stylePropertyUpdaterFactory[name];
@@ -226,7 +254,7 @@ function (_super) {
226
254
  if (stylePropertyUpdaters) {
227
255
  stylePropertyUpdaters.forEach(function (updater) {
228
256
  // @ts-ignore
229
- updater(oldParsedValue, newParsedValue, _this, _this.sceneGraphService);
257
+ updater(oldParsedValue, newParsedValue, _this, _this.sceneGraphService, name);
230
258
  });
231
259
  }
232
260
  };
@@ -253,26 +281,48 @@ function (_super) {
253
281
 
254
282
  if (this.attributes.clipPathTargets && this.attributes.clipPathTargets.length) {
255
283
  this.attributes.clipPathTargets.forEach(function (target) {
256
- (0, _services.dirtifyToRoot)(target);
257
- target.emit(_interfaces.ElementEvent.ATTRIBUTE_CHANGED, {
258
- attributeName: 'clipPath',
259
- oldValue: _this,
260
- newValue: _this
261
- });
284
+ (0, _services.dirtifyToRoot)(target); // target.emit(ElementEvent.ATTR_MODIFIED, {
285
+ // attributeName: 'clipPath',
286
+ // oldValue: this,
287
+ // newValue: this,
288
+ // });
289
+
290
+ target.dispatchEvent(new _MutationEvent.MutationEvent(_interfaces.ElementEvent.ATTR_MODIFIED, target, _this, _this, 'clipPath', _MutationEvent.MutationEvent.MODIFICATION, _this, _this));
262
291
  });
263
292
  } // redraw at next frame
264
293
 
265
294
 
266
295
  renderable.dirty = true;
267
- this.emit(_interfaces.ElementEvent.ATTRIBUTE_CHANGED, {
268
- attributeName: name,
269
- oldValue: oldValue,
270
- newValue: value,
271
- oldParsedValue: oldParsedValue,
272
- newParsedValue: newParsedValue
273
- });
296
+ this.dispatchEvent(new _MutationEvent.MutationEvent(_interfaces.ElementEvent.ATTR_MODIFIED, this, oldValue, value, name, _MutationEvent.MutationEvent.MODIFICATION, oldParsedValue, newParsedValue)); // this.emit(ElementEvent.ATTR_MODIFIED, {
297
+ // attrName: name,
298
+ // attributeName: name,
299
+ // prevValue: oldValue,
300
+ // oldValue,
301
+ // newValue: value,
302
+ // oldParsedValue,
303
+ // newParsedValue,
304
+ // });
274
305
  }; // #region transformable
275
306
 
307
+ /**
308
+ * returns different values than getBoundingClientRect(), as the latter returns value relative to the viewport
309
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/SVGGraphicsElement/getBBox
310
+ */
311
+
312
+
313
+ DisplayObject.prototype.getBBox = function () {
314
+ var aabb = this.getBounds();
315
+
316
+ var _a = (0, _tslib.__read)(aabb.getMin(), 2),
317
+ left = _a[0],
318
+ top = _a[1];
319
+
320
+ var _b = (0, _tslib.__read)(aabb.getMax(), 2),
321
+ right = _b[0],
322
+ bottom = _b[1];
323
+
324
+ return new _shapes.Rectangle(left, top, right - left, bottom - top);
325
+ };
276
326
 
277
327
  DisplayObject.prototype.setOrigin = function (position, y, z) {
278
328
  if (y === void 0) {
@@ -594,7 +644,7 @@ function (_super) {
594
644
 
595
645
  DisplayObject.prototype.isVisible = function () {
596
646
  var cullable = this.cullable;
597
- return this.style.visibility === 'visible' && (!cullable || cullable && !cullable.isCulled());
647
+ return this.getAttribute('visibility') === 'visible' && (!cullable || cullable && !cullable.isCulled());
598
648
  };
599
649
  /**
600
650
  * 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
  }
@@ -17,14 +17,19 @@ function (_super) {
17
17
  (0, _tslib.__extends)(Ellipse, _super);
18
18
 
19
19
  function Ellipse(_a) {
20
+ if (_a === void 0) {
21
+ _a = {};
22
+ }
23
+
20
24
  var style = _a.style,
21
25
  rest = (0, _tslib.__rest)(_a, ["style"]);
22
26
  return _super.call(this, (0, _tslib.__assign)({
23
- type: _types.SHAPE.Ellipse,
27
+ type: _types.Shape.ELLIPSE,
24
28
  style: (0, _tslib.__assign)({
25
29
  rx: 0,
26
30
  ry: 0,
27
- anchor: [0.5, 0.5]
31
+ anchor: [0.5, 0.5],
32
+ lineWidth: 0
28
33
  }, style)
29
34
  }, rest)) || this;
30
35
  }
@@ -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
  }
@@ -16,21 +16,22 @@ var Group =
16
16
  function (_super) {
17
17
  (0, _tslib.__extends)(Group, _super);
18
18
 
19
- function Group(config) {
20
- var _this = this;
19
+ function Group(_a) {
20
+ if (_a === void 0) {
21
+ _a = {};
22
+ }
21
23
 
22
- var _a = config || {},
23
- style = _a.style,
24
+ var style = _a.style,
24
25
  rest = (0, _tslib.__rest)(_a, ["style"]);
25
-
26
- _this = _super.call(this, (0, _tslib.__assign)({
27
- type: _types.SHAPE.Group,
26
+ return _super.call(this, (0, _tslib.__assign)({
27
+ type: _types.Shape.GROUP,
28
28
  style: (0, _tslib.__assign)({
29
29
  width: 'auto',
30
- height: 'auto'
30
+ height: 'auto',
31
+ textAlign: 'inherit',
32
+ fontSize: 'inherit'
31
33
  }, style)
32
34
  }, rest)) || this;
33
- return _this;
34
35
  }
35
36
 
36
37
  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
@@ -25,18 +25,22 @@ function (_super) {
25
25
  (0, _tslib.__extends)(HTML, _super);
26
26
 
27
27
  function HTML(_a) {
28
+ if (_a === void 0) {
29
+ _a = {};
30
+ }
31
+
32
+ var _this = this;
33
+
28
34
  var style = _a.style,
29
35
  rest = (0, _tslib.__rest)(_a, ["style"]);
30
-
31
- var _this = _super.call(this, (0, _tslib.__assign)({
32
- type: _types.SHAPE.HTML,
36
+ _this = _super.call(this, (0, _tslib.__assign)({
37
+ type: _types.Shape.HTML,
33
38
  style: (0, _tslib.__assign)({
34
39
  innerHTML: '',
35
40
  className: '',
36
41
  style: ''
37
42
  }, style)
38
43
  }, rest)) || this;
39
-
40
44
  _this.cullable.enable = false;
41
45
  return _this;
42
46
  }