@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
@@ -169,10 +169,8 @@ function (_super) {
169
169
  clickHistory.timeStamp = now;
170
170
  clickEvent.detail = clickHistory.clickCount;
171
171
 
172
- if (clickEvent.pointerType === 'mouse') {
172
+ if (clickEvent.pointerType === 'mouse' || clickEvent.pointerType === 'touch') {
173
173
  this.dispatchEvent(clickEvent, 'click');
174
- } else if (clickEvent.pointerType === 'touch') {
175
- this.dispatchEvent(clickEvent, 'tap');
176
174
  } else {
177
175
  this.dispatchEvent(clickEvent, 'pointertap');
178
176
  }
@@ -591,7 +589,7 @@ function (_super) {
591
589
  mappers[i].fn(e);
592
590
  }
593
591
  } else {
594
- console.warn("[EventService]: Event mapping not defined for " + e.type);
592
+ console.warn("[EventService]: Event mapping not defined for ".concat(e.type));
595
593
  }
596
594
  };
597
595
 
@@ -881,7 +879,7 @@ function (_super) {
881
879
 
882
880
  EventService.prototype.notifyTarget = function (e, type) {
883
881
  type = type !== null && type !== void 0 ? type : e.type;
884
- var key = e.eventPhase === e.CAPTURING_PHASE || e.eventPhase === e.AT_TARGET ? type + "capture" : type;
882
+ var key = e.eventPhase === e.CAPTURING_PHASE || e.eventPhase === e.AT_TARGET ? "".concat(type, "capture") : type;
885
883
  this.notifyListeners(e, key);
886
884
 
887
885
  if (e.eventPhase === e.AT_TARGET) {
@@ -1,13 +1,11 @@
1
1
  import type { Group } from '../display-objects';
2
- import type { AABB } from '../shapes';
3
2
  /**
4
3
  * why we need re-render
5
4
  */
6
- export declare enum RENDER_REASON {
7
- CameraChanged = 0,
8
- DisplayObjectChanged = 1,
9
- DisplayObjectRemoved = 2,
10
- None = 3
5
+ export declare enum RenderReason {
6
+ CAMERA_CHANGED = 0,
7
+ DISPLAY_OBJECT_CHANGED = 1,
8
+ NONE = 2
11
9
  }
12
10
  export declare const RenderingContext = "RenderingContext";
13
11
  export interface RenderingContext {
@@ -19,10 +17,9 @@ export interface RenderingContext {
19
17
  * force rendering at next frame
20
18
  */
21
19
  force: boolean;
22
- removedRenderBoundsList: AABB[];
23
20
  /**
24
21
  * reason of re-render, reset after every renderred frame
25
22
  */
26
- renderReasons: Set<RENDER_REASON>;
23
+ renderReasons: Set<RenderReason>;
27
24
  dirty: boolean;
28
25
  }
@@ -3,20 +3,19 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.RenderingContext = exports.RENDER_REASON = void 0;
6
+ exports.RenderingContext = exports.RenderReason = void 0;
7
7
 
8
8
  /**
9
9
  * why we need re-render
10
10
  */
11
- var RENDER_REASON;
12
- exports.RENDER_REASON = RENDER_REASON;
11
+ var RenderReason;
12
+ exports.RenderReason = RenderReason;
13
13
 
14
- (function (RENDER_REASON) {
15
- RENDER_REASON[RENDER_REASON["CameraChanged"] = 0] = "CameraChanged";
16
- RENDER_REASON[RENDER_REASON["DisplayObjectChanged"] = 1] = "DisplayObjectChanged";
17
- RENDER_REASON[RENDER_REASON["DisplayObjectRemoved"] = 2] = "DisplayObjectRemoved";
18
- RENDER_REASON[RENDER_REASON["None"] = 3] = "None";
19
- })(RENDER_REASON || (exports.RENDER_REASON = RENDER_REASON = {}));
14
+ (function (RenderReason) {
15
+ RenderReason[RenderReason["CAMERA_CHANGED"] = 0] = "CAMERA_CHANGED";
16
+ RenderReason[RenderReason["DISPLAY_OBJECT_CHANGED"] = 1] = "DISPLAY_OBJECT_CHANGED";
17
+ RenderReason[RenderReason["NONE"] = 2] = "NONE";
18
+ })(RenderReason || (exports.RenderReason = RenderReason = {}));
20
19
 
21
20
  var RenderingContext = 'RenderingContext';
22
21
  exports.RenderingContext = RenderingContext;
@@ -109,11 +109,6 @@ function () {
109
109
  if (this.renderingContext.dirty) {
110
110
  this.hooks.endFrame.call();
111
111
  this.renderingContext.dirty = false;
112
- } else {
113
- if (this.renderingContext.renderReasons.has(_RenderingContext.RENDER_REASON.DisplayObjectRemoved)) {
114
- this.hooks.beginFrame.call();
115
- this.hooks.endFrame.call();
116
- }
117
112
  }
118
113
 
119
114
  this.renderingContext.renderReasons.clear();
@@ -148,7 +143,6 @@ function () {
148
143
  var renderOrderChanged = false;
149
144
 
150
145
  if (sortable.dirty) {
151
- // sortable.sorted = [...(displayObject.childNodes as IElement[])].sort(sortByZIndex);
152
146
  sortable.sorted = displayObject.childNodes.slice().sort(_SceneGraphService.sortByZIndex);
153
147
  renderOrderChanged = true;
154
148
  sortable.dirty = false;
@@ -175,7 +169,7 @@ function () {
175
169
 
176
170
  RenderingService.prototype.dirtify = function () {
177
171
  // need re-render
178
- this.renderingContext.renderReasons.add(_RenderingContext.RENDER_REASON.DisplayObjectChanged);
172
+ this.renderingContext.renderReasons.add(_RenderingContext.RenderReason.DISPLAY_OBJECT_CHANGED);
179
173
  };
180
174
 
181
175
  (0, _tslib.__decorate)([(0, _manaSyringe.contrib)(RenderingPluginContribution), (0, _tslib.__metadata)("design:type", Object)], RenderingService.prototype, "renderingPluginProvider", void 0);
@@ -1,6 +1,7 @@
1
+ import { Syringe } from 'mana-syringe';
1
2
  import type { IElement } from '../dom/interfaces';
2
- export declare const SceneGraphSelectorFactory = "SceneGraphSelectorFactory";
3
- export declare const SceneGraphSelector = "SceneGraphSelector";
3
+ export declare const SceneGraphSelectorFactory: Syringe.DefinedToken;
4
+ export declare const SceneGraphSelector: Syringe.DefinedToken;
4
5
  export interface SceneGraphSelector {
5
6
  selectOne: <R extends IElement, T extends IElement>(query: string, root: R) => T | null;
6
7
  selectAll: <R extends IElement, T extends IElement>(query: string, root: R) => T[];
@@ -9,9 +9,13 @@ var _tslib = require("tslib");
9
9
 
10
10
  var _manaSyringe = require("mana-syringe");
11
11
 
12
- var SceneGraphSelectorFactory = 'SceneGraphSelectorFactory';
12
+ var SceneGraphSelectorFactory = _manaSyringe.Syringe.defineToken('SceneGraphSelectorFactory');
13
+
13
14
  exports.SceneGraphSelectorFactory = SceneGraphSelectorFactory;
14
- var SceneGraphSelector = 'SceneGraphSelector';
15
+
16
+ var SceneGraphSelector = _manaSyringe.Syringe.defineToken('SceneGraphSelector', {
17
+ multiple: false
18
+ });
15
19
  /**
16
20
  * support following DOM API
17
21
  * * getElementById
@@ -20,6 +24,7 @@ var SceneGraphSelector = 'SceneGraphSelector';
20
24
  * * getElementsByTag
21
25
  */
22
26
 
27
+
23
28
  exports.SceneGraphSelector = SceneGraphSelector;
24
29
 
25
30
  var DefaultSceneGraphSelector =
@@ -70,7 +75,9 @@ function () {
70
75
  return true;
71
76
  };
72
77
 
73
- DefaultSceneGraphSelector = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)()], DefaultSceneGraphSelector);
78
+ DefaultSceneGraphSelector = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
79
+ token: SceneGraphSelector
80
+ })], DefaultSceneGraphSelector);
74
81
  return DefaultSceneGraphSelector;
75
82
  }();
76
83
 
@@ -53,12 +53,6 @@ export declare class DefaultSceneGraphService implements SceneGraphService {
53
53
  querySelectorAll<R extends IElement, T extends IElement>(query: string, root: R): T[];
54
54
  attach<C extends INode, P extends INode & IParentNode>(child: C, parent: P, index?: number): void;
55
55
  detach<C extends INode>(child: C): void;
56
- /**
57
- * compare two display objects by hierarchy-index and z-index
58
- *
59
- * use materialized path
60
- * @see https://stackoverflow.com/questions/31470730/comparing-tree-nodes
61
- */
62
56
  getOrigin(element: INode): vec3;
63
57
  setOrigin(element: INode, origin: vec3 | number, y?: number, z?: number): void;
64
58
  /**
@@ -147,6 +141,5 @@ export declare class DefaultSceneGraphService implements SceneGraphService {
147
141
  private dirtifyWorldInternal;
148
142
  syncHierarchy(element: INode): void;
149
143
  private sync;
150
- private updateGraphDepth;
151
144
  private unfreezeParentToRoot;
152
145
  }
@@ -21,6 +21,8 @@ var _SceneGraphSelector = require("./SceneGraphSelector");
21
21
 
22
22
  var _interfaces = require("../dom/interfaces");
23
23
 
24
+ var _MutationEvent = require("../dom/MutationEvent");
25
+
24
26
  function sortByZIndex(o1, o2) {
25
27
  var zIndex1 = Number(o1.style.zIndex);
26
28
  var zIndex2 = Number(o2.style.zIndex);
@@ -366,9 +368,9 @@ function () {
366
368
 
367
369
  if (sortable) {
368
370
  sortable.dirty = true;
369
- }
371
+ } // this.updateGraphDepth(child);
372
+
370
373
 
371
- this.updateGraphDepth(child);
372
374
  var transform = child.transformable;
373
375
 
374
376
  if (transform) {
@@ -416,60 +418,6 @@ function () {
416
418
  child.parentNode = null;
417
419
  }
418
420
  };
419
- /**
420
- * compare two display objects by hierarchy-index and z-index
421
- *
422
- * use materialized path
423
- * @see https://stackoverflow.com/questions/31470730/comparing-tree-nodes
424
- */
425
- // sort = (object1: INode, object2: INode): number => {
426
- // if (!object1.parentNode) {
427
- // return -1;
428
- // }
429
- // if (!object2.parentNode) {
430
- // return 1;
431
- // }
432
- // const hierarchyDiff =
433
- // (object1 as Element).transformable.graphDepth - (object2 as Element).transformable.graphDepth;
434
- // let o1 = object1;
435
- // let o2 = object2;
436
- // if (hierarchyDiff < 0) {
437
- // o2 = object2.getAncestor(-hierarchyDiff)!;
438
- // if (o2 === o1) {
439
- // return -1;
440
- // }
441
- // } else if (hierarchyDiff > 0) {
442
- // o1 = object1.getAncestor(hierarchyDiff)!;
443
- // if (o2 === o1) {
444
- // return 1;
445
- // }
446
- // }
447
- // while (o1 && o2 && o1.parentNode !== o2.parentNode) {
448
- // o1 = o1.parentNode!;
449
- // o2 = o2.parentNode!;
450
- // }
451
- // const parent = o1.parentNode;
452
- // if (parent) {
453
- // const parentSortable = (parent as Element).sortable;
454
- // if (parentSortable) {
455
- // // no need to re-sort, use cached sorted children
456
- // if (!parentSortable.sorted) {
457
- // parentSortable.sorted = (parent.childNodes as IElement[]).slice();
458
- // }
459
- // if (parentSortable.dirty) {
460
- // parentSortable.sorted = (parent.childNodes as IElement[]).slice().sort(sortByZIndex);
461
- // // parentSortable.sorted.forEach(
462
- // // (child, i) => ((child as Element).sortable.lastSortedIndex = i),
463
- // // );
464
- // parentSortable.dirty = false;
465
- // }
466
- // // return (o1 as Element).sortable.lastSortedIndex - (o2 as Element).sortable.lastSortedIndex;
467
- // return parentSortable.sorted.indexOf(o1) - parentSortable.sorted.indexOf(o2);
468
- // }
469
- // }
470
- // return -1;
471
- // };
472
-
473
421
 
474
422
  DefaultSceneGraphService.prototype.getOrigin = function (element) {
475
423
  return element.transformable.origin;
@@ -839,13 +787,14 @@ function () {
839
787
  renderable.boundsDirty = true;
840
788
  renderable.dirty = true;
841
789
  } // model matrix changed
790
+ // element.emit(ElementEvent.ATTR_MODIFIED, {
791
+ // attributeName: 'modelMatrix',
792
+ // oldValue: null,
793
+ // newValue: null,
794
+ // });
842
795
 
843
796
 
844
- element.emit(_interfaces.ElementEvent.ATTRIBUTE_CHANGED, {
845
- attributeName: 'modelMatrix',
846
- oldValue: null,
847
- newValue: null
848
- });
797
+ element.dispatchEvent(new _MutationEvent.MutationEvent(_interfaces.ElementEvent.ATTR_MODIFIED, element, null, null, 'modelMatrix', _MutationEvent.MutationEvent.MODIFICATION, null, null));
849
798
  }
850
799
  };
851
800
 
@@ -892,22 +841,6 @@ function () {
892
841
  }
893
842
  };
894
843
 
895
- DefaultSceneGraphService.prototype.updateGraphDepth = function (element) {
896
- var transform = element.transformable;
897
-
898
- if (element.parentNode) {
899
- transform.graphDepth = element.parentNode.transformable.graphDepth + 1;
900
- } else {
901
- transform.graphDepth = 0;
902
- }
903
-
904
- var children = element.childNodes;
905
-
906
- for (var i = 0; i < children.length; i++) {
907
- this.updateGraphDepth(children[i]);
908
- }
909
- };
910
-
911
844
  DefaultSceneGraphService.prototype.unfreezeParentToRoot = function (child) {
912
845
  var p = child.parentNode;
913
846
 
@@ -27,7 +27,7 @@ function () {
27
27
  var unit = r.unit,
28
28
  value = r.value;
29
29
  var width = 0;
30
- var height = 0;
30
+ var height = 0; // absolute unit
31
31
 
32
32
  if (unit === '' || unit === 'px') {
33
33
  width = value * 2;
@@ -46,7 +46,7 @@ function () {
46
46
  CircleUpdater = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
47
47
  token: {
48
48
  token: _interfaces.GeometryAABBUpdater,
49
- named: _types.SHAPE.Circle
49
+ named: _types.Shape.CIRCLE
50
50
  }
51
51
  })], CircleUpdater);
52
52
  return CircleUpdater;
@@ -53,7 +53,7 @@ function () {
53
53
  EllipseUpdater = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
54
54
  token: {
55
55
  token: _interfaces.GeometryAABBUpdater,
56
- named: _types.SHAPE.Ellipse
56
+ named: _types.Shape.ELLIPSE
57
57
  }
58
58
  })], EllipseUpdater);
59
59
  return EllipseUpdater;
@@ -40,7 +40,7 @@ function () {
40
40
  LineUpdater = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
41
41
  token: {
42
42
  token: _interfaces.GeometryAABBUpdater,
43
- named: _types.SHAPE.Line
43
+ named: _types.Shape.LINE
44
44
  }
45
45
  })], LineUpdater);
46
46
  return LineUpdater;
@@ -36,7 +36,7 @@ function () {
36
36
  PathUpdater = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
37
37
  token: {
38
38
  token: _interfaces.GeometryAABBUpdater,
39
- named: _types.SHAPE.Path
39
+ named: _types.Shape.PATH
40
40
  }
41
41
  })], PathUpdater);
42
42
  return PathUpdater;
@@ -46,10 +46,10 @@ function () {
46
46
  PolylineUpdater = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
47
47
  token: [{
48
48
  token: _interfaces.GeometryAABBUpdater,
49
- named: _types.SHAPE.Polyline
49
+ named: _types.Shape.POLYLINE
50
50
  }, {
51
51
  token: _interfaces.GeometryAABBUpdater,
52
- named: _types.SHAPE.Polygon
52
+ named: _types.Shape.POLYGON
53
53
  }]
54
54
  })], PolylineUpdater);
55
55
  return PolylineUpdater;
@@ -67,13 +67,13 @@ function () {
67
67
  RectUpdater = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
68
68
  token: [{
69
69
  token: _interfaces.GeometryAABBUpdater,
70
- named: _types.SHAPE.Rect
70
+ named: _types.Shape.RECT
71
71
  }, {
72
72
  token: _interfaces.GeometryAABBUpdater,
73
- named: _types.SHAPE.Image
73
+ named: _types.Shape.IMAGE
74
74
  }, {
75
75
  token: _interfaces.GeometryAABBUpdater,
76
- named: _types.SHAPE.Group
76
+ named: _types.Shape.GROUP
77
77
  }]
78
78
  })], RectUpdater);
79
79
  return RectUpdater;
@@ -26,13 +26,14 @@ function () {
26
26
  var _a = parsedStyle.text,
27
27
  text = _a === void 0 ? '' : _a,
28
28
  textAlign = parsedStyle.textAlign,
29
- _b = parsedStyle.lineWidth,
30
- lineWidth = _b === void 0 ? 0 : _b,
29
+ lineWidth = parsedStyle.lineWidth,
31
30
  textBaseline = parsedStyle.textBaseline,
32
- _c = parsedStyle.x,
33
- x = _c === void 0 ? 0 : _c,
34
- _d = parsedStyle.y,
35
- y = _d === void 0 ? 0 : _d;
31
+ _b = parsedStyle.x,
32
+ x = _b === void 0 ? 0 : _b,
33
+ _c = parsedStyle.y,
34
+ y = _c === void 0 ? 0 : _c,
35
+ dx = parsedStyle.dx,
36
+ dy = parsedStyle.dy;
36
37
  var metrics = this.textService.measureText(text, parsedStyle);
37
38
  parsedStyle.metrics = metrics;
38
39
  var width = metrics.width,
@@ -47,10 +48,10 @@ function () {
47
48
  var lineXOffset = 0;
48
49
 
49
50
  if (textAlign === 'center') {
50
- lineXOffset = lineWidth / 2;
51
+ lineXOffset = lineWidth.value / 2;
51
52
  anchor = [0.5, 1];
52
53
  } else if (textAlign === 'right' || textAlign === 'end') {
53
- lineXOffset = lineWidth;
54
+ lineXOffset = lineWidth.value;
54
55
  anchor = [1, 1];
55
56
  } // update anchor
56
57
 
@@ -70,6 +71,14 @@ function () {
70
71
  } // TODO: ideographic & bottom
71
72
 
72
73
 
74
+ if (dx && dx.unit === 'px') {
75
+ lineXOffset += dx.value;
76
+ }
77
+
78
+ if (dy && dy.unit === 'px') {
79
+ lineYOffset += dy.value;
80
+ }
81
+
73
82
  return {
74
83
  width: halfExtents[0] * 2,
75
84
  height: halfExtents[1] * 2,
@@ -84,7 +93,7 @@ function () {
84
93
  TextUpdater = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
85
94
  token: {
86
95
  token: _interfaces.GeometryAABBUpdater,
87
- named: _types.SHAPE.Text
96
+ named: _types.Shape.TEXT
88
97
  }
89
98
  })], TextUpdater);
90
99
  return TextUpdater;
@@ -36,8 +36,8 @@ var regexCannotStartJaJp = /[)\]}〕〉》」』】〙〗〟'"⦆»ヽヾー
36
36
  var regexCannotEndJaJp = /[([{〔〈《「『【〘〖〝'"⦅«—...‥〳〴〵]/;
37
37
  var regexCannotStartKoKr = /[!%),.:;?\]}¢°'"†‡℃〆〈《「『〕!%),.:;?]}]/;
38
38
  var regexCannotEndKoKr = /[$([{£¥'"々〇〉》」〔$([{⦆¥₩#]/;
39
- var regexCannotStart = new RegExp(regexCannotStartZhCn.source + "|" + regexCannotStartZhTw.source + "|" + regexCannotStartJaJp.source + "|" + regexCannotStartKoKr.source);
40
- var regexCannotEnd = new RegExp(regexCannotEndZhCn.source + "|" + regexCannotEndZhTw.source + "|" + regexCannotEndJaJp.source + "|" + regexCannotEndKoKr.source);
39
+ var regexCannotStart = new RegExp("".concat(regexCannotStartZhCn.source, "|").concat(regexCannotStartZhTw.source, "|").concat(regexCannotStartJaJp.source, "|").concat(regexCannotStartKoKr.source));
40
+ var regexCannotEnd = new RegExp("".concat(regexCannotEndZhCn.source, "|").concat(regexCannotEndZhTw.source, "|").concat(regexCannotEndJaJp.source, "|").concat(regexCannotEndKoKr.source));
41
41
 
42
42
  var TextService =
43
43
  /** @class */
@@ -104,7 +104,7 @@ function () {
104
104
  context.textBaseline = 'alphabetic';
105
105
  context.fillStyle = '#000';
106
106
  context.fillText(metricsString, 0, baseline);
107
- var imagedata = context.getImageData(0, 0, width, height).data;
107
+ var imagedata = context.getImageData(0, 0, width || 1, height || 1).data;
108
108
  var pixels = imagedata.length;
109
109
  var line = width * 4;
110
110
  var i = 0;
@@ -152,29 +152,27 @@ function () {
152
152
  };
153
153
 
154
154
  TextService.prototype.measureText = function (text, attributes) {
155
- var _a = attributes.fontSize,
156
- fontSize = _a === void 0 ? 0 : _a,
155
+ var fontSize = attributes.fontSize,
157
156
  wordWrap = attributes.wordWrap,
158
- _b = attributes.lineHeight,
159
- strokeHeight = _b === void 0 ? 0 : _b,
160
- _c = attributes.lineWidth,
161
- lineWidth = _c === void 0 ? 0 : _c,
157
+ _a = attributes.lineHeight,
158
+ strokeHeight = _a === void 0 ? 0 : _a,
159
+ lineWidth = attributes.lineWidth,
162
160
  textBaseline = attributes.textBaseline,
163
161
  textAlign = attributes.textAlign,
164
- _d = attributes.letterSpacing,
165
- letterSpacing = _d === void 0 ? 0 : _d,
162
+ _b = attributes.letterSpacing,
163
+ letterSpacing = _b === void 0 ? 0 : _b,
166
164
  dropShadow = attributes.dropShadow,
167
- _e = attributes.dropShadowDistance,
168
- dropShadowDistance = _e === void 0 ? 0 : _e,
169
- _f = attributes.leading,
170
- leading = _f === void 0 ? 0 : _f;
165
+ _c = attributes.dropShadowDistance,
166
+ dropShadowDistance = _c === void 0 ? 0 : _c,
167
+ _d = attributes.leading,
168
+ leading = _d === void 0 ? 0 : _d;
171
169
  var font = (0, _text.toFontString)(attributes);
172
170
  var fontProperties = this.measureFont(font); // fallback in case UA disallow canvas data extraction
173
171
  // (toDataURI, getImageData functions)
174
172
 
175
173
  if (fontProperties.fontSize === 0) {
176
- fontProperties.fontSize = fontSize;
177
- fontProperties.ascent = fontSize;
174
+ fontProperties.fontSize = fontSize.value;
175
+ fontProperties.ascent = fontSize.value;
178
176
  }
179
177
 
180
178
  var context = this.offscreenCanvas.getOrCreateContext();
@@ -190,14 +188,14 @@ function () {
190
188
  maxLineWidth = Math.max(maxLineWidth, lineWidth_1);
191
189
  }
192
190
 
193
- var width = maxLineWidth + lineWidth;
191
+ var width = maxLineWidth + lineWidth.value;
194
192
 
195
193
  if (dropShadow) {
196
194
  width += dropShadowDistance;
197
195
  }
198
196
 
199
- var lineHeight = strokeHeight || fontProperties.fontSize + lineWidth;
200
- var height = Math.max(lineHeight, fontProperties.fontSize + lineWidth) + (lines.length - 1) * (lineHeight + leading);
197
+ var lineHeight = strokeHeight || fontProperties.fontSize + lineWidth.value;
198
+ var height = Math.max(lineHeight, fontProperties.fontSize + lineWidth.value) + (lines.length - 1) * (lineHeight + leading);
201
199
 
202
200
  if (dropShadow) {
203
201
  height += dropShadowDistance;
@@ -233,7 +231,7 @@ function () {
233
231
  offsetX -= width;
234
232
  }
235
233
 
236
- return new _shapes.Rectangle(offsetX - lineWidth / 2, offsetY + i * lineHeight, width + lineWidth, lineHeight);
234
+ return new _shapes.Rectangle(offsetX - lineWidth.value / 2, offsetY + i * lineHeight, width + lineWidth.value, lineHeight);
237
235
  })
238
236
  };
239
237
  };
package/lib/types.d.ts CHANGED
@@ -2,19 +2,19 @@
2
2
  import type { vec2, vec3 } from 'gl-matrix';
3
3
  import type { ParsedPathStyleProps, ParsedPolylineStyleProps } from './display-objects';
4
4
  import type { DisplayObject } from './display-objects';
5
- import type { ParsedColorStyleProperty } from './property-handlers';
5
+ import type { ParsedColorStyleProperty, ParsedElement } from './property-handlers';
6
6
  import type { IRenderer } from './AbstractRenderer';
7
- export declare enum SHAPE {
8
- Group = "group",
9
- Circle = "circle",
10
- Ellipse = "ellipse",
11
- Image = "image",
12
- Rect = "rect",
13
- Line = "line",
14
- Polyline = "polyline",
15
- Polygon = "polygon",
16
- Text = "text",
17
- Path = "path",
7
+ export declare enum Shape {
8
+ GROUP = "g",
9
+ CIRCLE = "circle",
10
+ ELLIPSE = "ellipse",
11
+ IMAGE = "image",
12
+ RECT = "rect",
13
+ LINE = "line",
14
+ POLYLINE = "polyline",
15
+ POLYGON = "polygon",
16
+ TEXT = "text",
17
+ PATH = "path",
18
18
  HTML = "html"
19
19
  }
20
20
  declare type ColorType = string | null;
@@ -26,17 +26,31 @@ export interface EventPosition {
26
26
  x: number;
27
27
  y: number;
28
28
  }
29
- export declare enum LINE_CAP {
30
- Butt = "butt",
31
- Round = "round",
32
- Square = "square"
29
+ export declare enum LineCap {
30
+ BUTT = "butt",
31
+ ROUND = "round",
32
+ SQUARE = "square"
33
33
  }
34
- export declare enum LINE_JOIN {
35
- Bevel = "bevel",
36
- Round = "round",
37
- Miter = "miter"
34
+ export declare enum LineJoin {
35
+ BEVEL = "bevel",
36
+ ROUND = "round",
37
+ MITER = "miter"
38
+ }
39
+ export declare enum TextTransform {
40
+ CAPITALIZE = "capitalize",
41
+ UPPERCASE = "uppercase",
42
+ LOWERCASE = "lowercase",
43
+ NONE = "none"
44
+ }
45
+ export declare enum TextAlign {
46
+ START = "start",
47
+ CENTER = "center",
48
+ END = "end",
49
+ LEFT = "left",
50
+ RIGHT = "right"
38
51
  }
39
52
  export interface BaseStyleProps {
53
+ class?: string;
40
54
  /**
41
55
  * x in local space
42
56
  */
@@ -100,11 +114,11 @@ export interface BaseStyleProps {
100
114
  /** 整体透明度 */
101
115
  opacity?: number;
102
116
  /** 线宽 */
103
- lineWidth?: number;
117
+ lineWidth?: string | number;
104
118
  /** 指定如何绘制每一条线段末端 */
105
- lineCap?: LINE_CAP;
119
+ lineCap?: LineCap;
106
120
  /** 用来设置2个长度不为0的相连部分(线段,圆弧,曲线)如何连接在一起的属性(长度为0的变形部分,其指定的末端和控制点在同一位置,会被忽略) */
107
- lineJoin?: LINE_JOIN;
121
+ lineJoin?: LineJoin;
108
122
  /**
109
123
  * 设置线的虚线样式,可以指定一个数组。一组描述交替绘制线段和间距(坐标空间单位)长度的数字。 如果数组元素的数量是奇数, 数组的元素会被复制并重复。例如, [5, 15, 25] 会变成 [5, 15, 25, 5, 15, 25]。这个属性取决于浏览器是否支持 setLineDash() 函数。
110
124
  */
@@ -126,14 +140,23 @@ export interface BaseStyleProps {
126
140
  * @see https://developer.mozilla.org/en-US/docs/Web/CSS/filter
127
141
  */
128
142
  filter?: string;
143
+ /**
144
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/text-transform
145
+ */
146
+ textTransform?: TextTransform;
147
+ /**
148
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/miterLimit
149
+ */
150
+ miterLimit?: number;
129
151
  }
130
- export interface ParsedBaseStyleProps extends Omit<BaseStyleProps, 'fill' | 'stroke' | 'path' | 'points'> {
152
+ export interface ParsedBaseStyleProps extends Omit<BaseStyleProps, 'fill' | 'stroke' | 'path' | 'points' | 'lineWidth' | 'shadowColor'> {
131
153
  fill?: ParsedColorStyleProperty;
132
154
  stroke?: ParsedColorStyleProperty;
133
155
  path?: ParsedPathStyleProps;
134
156
  points?: ParsedPolylineStyleProps;
135
157
  x?: number;
136
158
  y?: number;
159
+ lineWidth?: ParsedElement;
137
160
  /**
138
161
  * x according to definition, eg. Line's x1/x2, Polyline's points
139
162
  */
@@ -144,6 +167,7 @@ export interface ParsedBaseStyleProps extends Omit<BaseStyleProps, 'fill' | 'str
144
167
  */
145
168
  offsetX?: number;
146
169
  offsetY?: number;
170
+ shadowColor?: ParsedColorStyleProperty;
147
171
  }
148
172
  export declare type Cursor = 'auto' | 'default' | 'none' | 'context-menu' | 'help' | 'pointer' | 'progress' | 'wait' | 'cell' | 'crosshair' | 'text' | 'vertical-text' | 'alias' | 'copy' | 'move' | 'no-drop' | 'not-allowed' | 'grab' | 'grabbing' | 'all-scroll' | 'col-resize' | 'row-resize' | 'n-resize' | 'e-resize' | 's-resize' | 'w-resize' | 'ne-resize' | 'nw-resize' | 'se-resize' | 'sw-resize' | 'ew-resize' | 'ns-resize' | 'nesw-resize' | 'nwse-resize' | 'zoom-in' | 'zoom-out';
149
173
  export interface RendererConfig {