@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
@@ -1,13 +1,12 @@
1
1
  /**
2
2
  * why we need re-render
3
3
  */
4
- export var RENDER_REASON;
4
+ export var RenderReason;
5
5
 
6
- (function (RENDER_REASON) {
7
- RENDER_REASON[RENDER_REASON["CameraChanged"] = 0] = "CameraChanged";
8
- RENDER_REASON[RENDER_REASON["DisplayObjectChanged"] = 1] = "DisplayObjectChanged";
9
- RENDER_REASON[RENDER_REASON["DisplayObjectRemoved"] = 2] = "DisplayObjectRemoved";
10
- RENDER_REASON[RENDER_REASON["None"] = 3] = "None";
11
- })(RENDER_REASON || (RENDER_REASON = {}));
6
+ (function (RenderReason) {
7
+ RenderReason[RenderReason["CAMERA_CHANGED"] = 0] = "CAMERA_CHANGED";
8
+ RenderReason[RenderReason["DISPLAY_OBJECT_CHANGED"] = 1] = "DISPLAY_OBJECT_CHANGED";
9
+ RenderReason[RenderReason["NONE"] = 2] = "NONE";
10
+ })(RenderReason || (RenderReason = {}));
12
11
 
13
12
  export var RenderingContext = 'RenderingContext';
@@ -2,7 +2,7 @@ import { __awaiter, __decorate, __generator, __metadata } from "tslib";
2
2
  import { inject, singleton, contrib, Syringe, Contribution } from 'mana-syringe';
3
3
  import { SyncHook, SyncWaterfallHook, AsyncParallelHook, AsyncSeriesWaterfallHook } from 'tapable';
4
4
  import { ElementEvent } from '../dom';
5
- import { RenderingContext, RENDER_REASON } from './RenderingContext';
5
+ import { RenderingContext, RenderReason } from './RenderingContext';
6
6
  import { SceneGraphService, sortByZIndex } from './SceneGraphService';
7
7
  export var RenderingPluginContribution = Syringe.defineToken('RenderingPluginContribution');
8
8
  /**
@@ -93,11 +93,6 @@ function () {
93
93
  if (this.renderingContext.dirty) {
94
94
  this.hooks.endFrame.call();
95
95
  this.renderingContext.dirty = false;
96
- } else {
97
- if (this.renderingContext.renderReasons.has(RENDER_REASON.DisplayObjectRemoved)) {
98
- this.hooks.beginFrame.call();
99
- this.hooks.endFrame.call();
100
- }
101
96
  }
102
97
 
103
98
  this.renderingContext.renderReasons.clear();
@@ -132,7 +127,6 @@ function () {
132
127
  var renderOrderChanged = false;
133
128
 
134
129
  if (sortable.dirty) {
135
- // sortable.sorted = [...(displayObject.childNodes as IElement[])].sort(sortByZIndex);
136
130
  sortable.sorted = displayObject.childNodes.slice().sort(sortByZIndex);
137
131
  renderOrderChanged = true;
138
132
  sortable.dirty = false;
@@ -159,7 +153,7 @@ function () {
159
153
 
160
154
  RenderingService.prototype.dirtify = function () {
161
155
  // need re-render
162
- this.renderingContext.renderReasons.add(RENDER_REASON.DisplayObjectChanged);
156
+ this.renderingContext.renderReasons.add(RenderReason.DISPLAY_OBJECT_CHANGED);
163
157
  };
164
158
 
165
159
  __decorate([contrib(RenderingPluginContribution), __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[];
@@ -1,7 +1,9 @@
1
1
  import { __decorate } from "tslib";
2
- import { singleton } from 'mana-syringe';
3
- export var SceneGraphSelectorFactory = 'SceneGraphSelectorFactory';
4
- export var SceneGraphSelector = 'SceneGraphSelector';
2
+ import { singleton, Syringe } from 'mana-syringe';
3
+ export var SceneGraphSelectorFactory = Syringe.defineToken('SceneGraphSelectorFactory');
4
+ export var SceneGraphSelector = Syringe.defineToken('SceneGraphSelector', {
5
+ multiple: false
6
+ });
5
7
  /**
6
8
  * support following DOM API
7
9
  * * getElementById
@@ -58,7 +60,9 @@ function () {
58
60
  return true;
59
61
  };
60
62
 
61
- DefaultSceneGraphSelector = __decorate([singleton()], DefaultSceneGraphSelector);
63
+ DefaultSceneGraphSelector = __decorate([singleton({
64
+ token: SceneGraphSelector
65
+ })], DefaultSceneGraphSelector);
62
66
  return DefaultSceneGraphSelector;
63
67
  }();
64
68
 
@@ -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
  }
@@ -5,6 +5,7 @@ import { mat4, quat, vec3 } from 'gl-matrix';
5
5
  import { AABB, Rectangle } from '../shapes';
6
6
  import { SceneGraphSelectorFactory } from './SceneGraphSelector';
7
7
  import { ElementEvent } from '../dom/interfaces';
8
+ import { MutationEvent } from '../dom/MutationEvent';
8
9
  export function sortByZIndex(o1, o2) {
9
10
  var zIndex1 = Number(o1.style.zIndex);
10
11
  var zIndex2 = Number(o2.style.zIndex);
@@ -325,9 +326,9 @@ function () {
325
326
 
326
327
  if (sortable) {
327
328
  sortable.dirty = true;
328
- }
329
+ } // this.updateGraphDepth(child);
330
+
329
331
 
330
- this.updateGraphDepth(child);
331
332
  var transform = child.transformable;
332
333
 
333
334
  if (transform) {
@@ -371,60 +372,6 @@ function () {
371
372
  child.parentNode = null;
372
373
  }
373
374
  };
374
- /**
375
- * compare two display objects by hierarchy-index and z-index
376
- *
377
- * use materialized path
378
- * @see https://stackoverflow.com/questions/31470730/comparing-tree-nodes
379
- */
380
- // sort = (object1: INode, object2: INode): number => {
381
- // if (!object1.parentNode) {
382
- // return -1;
383
- // }
384
- // if (!object2.parentNode) {
385
- // return 1;
386
- // }
387
- // const hierarchyDiff =
388
- // (object1 as Element).transformable.graphDepth - (object2 as Element).transformable.graphDepth;
389
- // let o1 = object1;
390
- // let o2 = object2;
391
- // if (hierarchyDiff < 0) {
392
- // o2 = object2.getAncestor(-hierarchyDiff)!;
393
- // if (o2 === o1) {
394
- // return -1;
395
- // }
396
- // } else if (hierarchyDiff > 0) {
397
- // o1 = object1.getAncestor(hierarchyDiff)!;
398
- // if (o2 === o1) {
399
- // return 1;
400
- // }
401
- // }
402
- // while (o1 && o2 && o1.parentNode !== o2.parentNode) {
403
- // o1 = o1.parentNode!;
404
- // o2 = o2.parentNode!;
405
- // }
406
- // const parent = o1.parentNode;
407
- // if (parent) {
408
- // const parentSortable = (parent as Element).sortable;
409
- // if (parentSortable) {
410
- // // no need to re-sort, use cached sorted children
411
- // if (!parentSortable.sorted) {
412
- // parentSortable.sorted = (parent.childNodes as IElement[]).slice();
413
- // }
414
- // if (parentSortable.dirty) {
415
- // parentSortable.sorted = (parent.childNodes as IElement[]).slice().sort(sortByZIndex);
416
- // // parentSortable.sorted.forEach(
417
- // // (child, i) => ((child as Element).sortable.lastSortedIndex = i),
418
- // // );
419
- // parentSortable.dirty = false;
420
- // }
421
- // // return (o1 as Element).sortable.lastSortedIndex - (o2 as Element).sortable.lastSortedIndex;
422
- // return parentSortable.sorted.indexOf(o1) - parentSortable.sorted.indexOf(o2);
423
- // }
424
- // }
425
- // return -1;
426
- // };
427
-
428
375
 
429
376
  DefaultSceneGraphService.prototype.getOrigin = function (element) {
430
377
  return element.transformable.origin;
@@ -784,13 +731,14 @@ function () {
784
731
  renderable.boundsDirty = true;
785
732
  renderable.dirty = true;
786
733
  } // model matrix changed
734
+ // element.emit(ElementEvent.ATTR_MODIFIED, {
735
+ // attributeName: 'modelMatrix',
736
+ // oldValue: null,
737
+ // newValue: null,
738
+ // });
787
739
 
788
740
 
789
- element.emit(ElementEvent.ATTRIBUTE_CHANGED, {
790
- attributeName: 'modelMatrix',
791
- oldValue: null,
792
- newValue: null
793
- });
741
+ element.dispatchEvent(new MutationEvent(ElementEvent.ATTR_MODIFIED, element, null, null, 'modelMatrix', MutationEvent.MODIFICATION, null, null));
794
742
  }
795
743
  };
796
744
 
@@ -836,22 +784,6 @@ function () {
836
784
  }
837
785
  };
838
786
 
839
- DefaultSceneGraphService.prototype.updateGraphDepth = function (element) {
840
- var transform = element.transformable;
841
-
842
- if (element.parentNode) {
843
- transform.graphDepth = element.parentNode.transformable.graphDepth + 1;
844
- } else {
845
- transform.graphDepth = 0;
846
- }
847
-
848
- var children = element.childNodes;
849
-
850
- for (var i = 0; i < children.length; i++) {
851
- this.updateGraphDepth(children[i]);
852
- }
853
- };
854
-
855
787
  DefaultSceneGraphService.prototype.unfreezeParentToRoot = function (child) {
856
788
  var p = child.parentNode;
857
789
 
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { singleton } from 'mana-syringe';
3
3
  import { GeometryAABBUpdater } from './interfaces';
4
- import { SHAPE } from '../../types';
4
+ import { Shape } from '../../types';
5
5
 
6
6
  var CircleUpdater =
7
7
  /** @class */
@@ -17,7 +17,7 @@ function () {
17
17
  var unit = r.unit,
18
18
  value = r.value;
19
19
  var width = 0;
20
- var height = 0;
20
+ var height = 0; // absolute unit
21
21
 
22
22
  if (unit === '' || unit === 'px') {
23
23
  width = value * 2;
@@ -36,7 +36,7 @@ function () {
36
36
  CircleUpdater = __decorate([singleton({
37
37
  token: {
38
38
  token: GeometryAABBUpdater,
39
- named: SHAPE.Circle
39
+ named: Shape.CIRCLE
40
40
  }
41
41
  })], CircleUpdater);
42
42
  return CircleUpdater;
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { singleton } from 'mana-syringe';
3
3
  import { GeometryAABBUpdater } from './interfaces';
4
- import { SHAPE } from '../../types';
4
+ import { Shape } from '../../types';
5
5
 
6
6
  var EllipseUpdater =
7
7
  /** @class */
@@ -43,7 +43,7 @@ function () {
43
43
  EllipseUpdater = __decorate([singleton({
44
44
  token: {
45
45
  token: GeometryAABBUpdater,
46
- named: SHAPE.Ellipse
46
+ named: Shape.ELLIPSE
47
47
  }
48
48
  })], EllipseUpdater);
49
49
  return EllipseUpdater;
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { singleton } from 'mana-syringe';
3
3
  import { GeometryAABBUpdater } from './interfaces';
4
- import { SHAPE } from '../../types';
4
+ import { Shape } from '../../types';
5
5
 
6
6
  var LineUpdater =
7
7
  /** @class */
@@ -30,7 +30,7 @@ function () {
30
30
  LineUpdater = __decorate([singleton({
31
31
  token: {
32
32
  token: GeometryAABBUpdater,
33
- named: SHAPE.Line
33
+ named: Shape.LINE
34
34
  }
35
35
  })], LineUpdater);
36
36
  return LineUpdater;
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { singleton } from 'mana-syringe';
3
3
  import { GeometryAABBUpdater } from './interfaces';
4
- import { SHAPE } from '../../types';
4
+ import { Shape } from '../../types';
5
5
 
6
6
  var PathUpdater =
7
7
  /** @class */
@@ -26,7 +26,7 @@ function () {
26
26
  PathUpdater = __decorate([singleton({
27
27
  token: {
28
28
  token: GeometryAABBUpdater,
29
- named: SHAPE.Path
29
+ named: Shape.PATH
30
30
  }
31
31
  })], PathUpdater);
32
32
  return PathUpdater;
@@ -1,7 +1,7 @@
1
1
  import { __decorate, __read, __spreadArray } from "tslib";
2
2
  import { singleton } from 'mana-syringe';
3
3
  import { GeometryAABBUpdater } from './interfaces';
4
- import { SHAPE } from '../../types';
4
+ import { Shape } from '../../types';
5
5
 
6
6
  var PolylineUpdater =
7
7
  /** @class */
@@ -36,10 +36,10 @@ function () {
36
36
  PolylineUpdater = __decorate([singleton({
37
37
  token: [{
38
38
  token: GeometryAABBUpdater,
39
- named: SHAPE.Polyline
39
+ named: Shape.POLYLINE
40
40
  }, {
41
41
  token: GeometryAABBUpdater,
42
- named: SHAPE.Polygon
42
+ named: Shape.POLYGON
43
43
  }]
44
44
  })], PolylineUpdater);
45
45
  return PolylineUpdater;
@@ -2,7 +2,7 @@ import { __decorate } from "tslib";
2
2
  import { singleton } from 'mana-syringe';
3
3
  import { isString } from '@antv/util';
4
4
  import { GeometryAABBUpdater } from './interfaces';
5
- import { SHAPE } from '../../types';
5
+ import { Shape } from '../../types';
6
6
 
7
7
  var RectUpdater =
8
8
  /** @class */
@@ -56,13 +56,13 @@ function () {
56
56
  RectUpdater = __decorate([singleton({
57
57
  token: [{
58
58
  token: GeometryAABBUpdater,
59
- named: SHAPE.Rect
59
+ named: Shape.RECT
60
60
  }, {
61
61
  token: GeometryAABBUpdater,
62
- named: SHAPE.Image
62
+ named: Shape.IMAGE
63
63
  }, {
64
64
  token: GeometryAABBUpdater,
65
- named: SHAPE.Group
65
+ named: Shape.GROUP
66
66
  }]
67
67
  })], RectUpdater);
68
68
  return RectUpdater;
@@ -3,7 +3,7 @@ import { vec3 } from 'gl-matrix';
3
3
  import { singleton, inject } from 'mana-syringe';
4
4
  import { GeometryAABBUpdater } from './interfaces';
5
5
  import { TextService } from '../text';
6
- import { SHAPE } from '../../types';
6
+ import { Shape } from '../../types';
7
7
 
8
8
  var TextUpdater =
9
9
  /** @class */
@@ -14,13 +14,14 @@ function () {
14
14
  var _a = parsedStyle.text,
15
15
  text = _a === void 0 ? '' : _a,
16
16
  textAlign = parsedStyle.textAlign,
17
- _b = parsedStyle.lineWidth,
18
- lineWidth = _b === void 0 ? 0 : _b,
17
+ lineWidth = parsedStyle.lineWidth,
19
18
  textBaseline = parsedStyle.textBaseline,
20
- _c = parsedStyle.x,
21
- x = _c === void 0 ? 0 : _c,
22
- _d = parsedStyle.y,
23
- y = _d === void 0 ? 0 : _d;
19
+ _b = parsedStyle.x,
20
+ x = _b === void 0 ? 0 : _b,
21
+ _c = parsedStyle.y,
22
+ y = _c === void 0 ? 0 : _c,
23
+ dx = parsedStyle.dx,
24
+ dy = parsedStyle.dy;
24
25
  var metrics = this.textService.measureText(text, parsedStyle);
25
26
  parsedStyle.metrics = metrics;
26
27
  var width = metrics.width,
@@ -34,10 +35,10 @@ function () {
34
35
  var lineXOffset = 0;
35
36
 
36
37
  if (textAlign === 'center') {
37
- lineXOffset = lineWidth / 2;
38
+ lineXOffset = lineWidth.value / 2;
38
39
  anchor = [0.5, 1];
39
40
  } else if (textAlign === 'right' || textAlign === 'end') {
40
- lineXOffset = lineWidth;
41
+ lineXOffset = lineWidth.value;
41
42
  anchor = [1, 1];
42
43
  } // update anchor
43
44
 
@@ -57,6 +58,14 @@ function () {
57
58
  } // TODO: ideographic & bottom
58
59
 
59
60
 
61
+ if (dx && dx.unit === 'px') {
62
+ lineXOffset += dx.value;
63
+ }
64
+
65
+ if (dy && dy.unit === 'px') {
66
+ lineYOffset += dy.value;
67
+ }
68
+
60
69
  return {
61
70
  width: halfExtents[0] * 2,
62
71
  height: halfExtents[1] * 2,
@@ -72,7 +81,7 @@ function () {
72
81
  TextUpdater = __decorate([singleton({
73
82
  token: {
74
83
  token: GeometryAABBUpdater,
75
- named: SHAPE.Text
84
+ named: Shape.TEXT
76
85
  }
77
86
  })], TextUpdater);
78
87
  return TextUpdater;
@@ -24,8 +24,8 @@ var regexCannotStartJaJp = /[)\]}〕〉》」』】〙〗〟'"⦆»ヽヾー
24
24
  var regexCannotEndJaJp = /[([{〔〈《「『【〘〖〝'"⦅«—...‥〳〴〵]/;
25
25
  var regexCannotStartKoKr = /[!%),.:;?\]}¢°'"†‡℃〆〈《「『〕!%),.:;?]}]/;
26
26
  var regexCannotEndKoKr = /[$([{£¥'"々〇〉》」〔$([{⦆¥₩#]/;
27
- var regexCannotStart = new RegExp(regexCannotStartZhCn.source + "|" + regexCannotStartZhTw.source + "|" + regexCannotStartJaJp.source + "|" + regexCannotStartKoKr.source);
28
- var regexCannotEnd = new RegExp(regexCannotEndZhCn.source + "|" + regexCannotEndZhTw.source + "|" + regexCannotEndJaJp.source + "|" + regexCannotEndKoKr.source);
27
+ var regexCannotStart = new RegExp("".concat(regexCannotStartZhCn.source, "|").concat(regexCannotStartZhTw.source, "|").concat(regexCannotStartJaJp.source, "|").concat(regexCannotStartKoKr.source));
28
+ var regexCannotEnd = new RegExp("".concat(regexCannotEndZhCn.source, "|").concat(regexCannotEndZhTw.source, "|").concat(regexCannotEndJaJp.source, "|").concat(regexCannotEndKoKr.source));
29
29
 
30
30
  var TextService =
31
31
  /** @class */
@@ -93,7 +93,7 @@ function () {
93
93
  context.textBaseline = 'alphabetic';
94
94
  context.fillStyle = '#000';
95
95
  context.fillText(metricsString, 0, baseline);
96
- var imagedata = context.getImageData(0, 0, width, height).data;
96
+ var imagedata = context.getImageData(0, 0, width || 1, height || 1).data;
97
97
  var pixels = imagedata.length;
98
98
  var line = width * 4;
99
99
  var i = 0;
@@ -141,29 +141,27 @@ function () {
141
141
  };
142
142
 
143
143
  TextService.prototype.measureText = function (text, attributes) {
144
- var _a = attributes.fontSize,
145
- fontSize = _a === void 0 ? 0 : _a,
144
+ var fontSize = attributes.fontSize,
146
145
  wordWrap = attributes.wordWrap,
147
- _b = attributes.lineHeight,
148
- strokeHeight = _b === void 0 ? 0 : _b,
149
- _c = attributes.lineWidth,
150
- lineWidth = _c === void 0 ? 0 : _c,
146
+ _a = attributes.lineHeight,
147
+ strokeHeight = _a === void 0 ? 0 : _a,
148
+ lineWidth = attributes.lineWidth,
151
149
  textBaseline = attributes.textBaseline,
152
150
  textAlign = attributes.textAlign,
153
- _d = attributes.letterSpacing,
154
- letterSpacing = _d === void 0 ? 0 : _d,
151
+ _b = attributes.letterSpacing,
152
+ letterSpacing = _b === void 0 ? 0 : _b,
155
153
  dropShadow = attributes.dropShadow,
156
- _e = attributes.dropShadowDistance,
157
- dropShadowDistance = _e === void 0 ? 0 : _e,
158
- _f = attributes.leading,
159
- leading = _f === void 0 ? 0 : _f;
154
+ _c = attributes.dropShadowDistance,
155
+ dropShadowDistance = _c === void 0 ? 0 : _c,
156
+ _d = attributes.leading,
157
+ leading = _d === void 0 ? 0 : _d;
160
158
  var font = toFontString(attributes);
161
159
  var fontProperties = this.measureFont(font); // fallback in case UA disallow canvas data extraction
162
160
  // (toDataURI, getImageData functions)
163
161
 
164
162
  if (fontProperties.fontSize === 0) {
165
- fontProperties.fontSize = fontSize;
166
- fontProperties.ascent = fontSize;
163
+ fontProperties.fontSize = fontSize.value;
164
+ fontProperties.ascent = fontSize.value;
167
165
  }
168
166
 
169
167
  var context = this.offscreenCanvas.getOrCreateContext();
@@ -179,14 +177,14 @@ function () {
179
177
  maxLineWidth = Math.max(maxLineWidth, lineWidth_1);
180
178
  }
181
179
 
182
- var width = maxLineWidth + lineWidth;
180
+ var width = maxLineWidth + lineWidth.value;
183
181
 
184
182
  if (dropShadow) {
185
183
  width += dropShadowDistance;
186
184
  }
187
185
 
188
- var lineHeight = strokeHeight || fontProperties.fontSize + lineWidth;
189
- var height = Math.max(lineHeight, fontProperties.fontSize + lineWidth) + (lines.length - 1) * (lineHeight + leading);
186
+ var lineHeight = strokeHeight || fontProperties.fontSize + lineWidth.value;
187
+ var height = Math.max(lineHeight, fontProperties.fontSize + lineWidth.value) + (lines.length - 1) * (lineHeight + leading);
190
188
 
191
189
  if (dropShadow) {
192
190
  height += dropShadowDistance;
@@ -222,7 +220,7 @@ function () {
222
220
  offsetX -= width;
223
221
  }
224
222
 
225
- return new Rectangle(offsetX - lineWidth / 2, offsetY + i * lineHeight, width + lineWidth, lineHeight);
223
+ return new Rectangle(offsetX - lineWidth.value / 2, offsetY + i * lineHeight, width + lineWidth.value, lineHeight);
226
224
  })
227
225
  };
228
226
  };
package/es/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 {