@antv/g 5.0.13 → 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 (244) hide show
  1. package/dist/index.umd.min.js +18 -2
  2. package/es/Canvas.d.ts +3 -0
  3. package/es/Canvas.js +9 -9
  4. package/es/camera/Camera.d.ts +3 -2
  5. package/es/camera/Camera.js +16 -8
  6. package/es/canvas-module.js +11 -17
  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 +4 -2
  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 +80 -49
  15. package/es/display-objects/Ellipse.d.ts +6 -3
  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 +14 -9
  19. package/es/display-objects/HTML.d.ts +6 -1
  20. package/es/display-objects/HTML.js +10 -5
  21. package/es/display-objects/Image.d.ts +12 -7
  22. package/es/display-objects/Image.js +10 -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 +8 -5
  32. package/es/display-objects/Rect.js +9 -4
  33. package/es/display-objects/Text.d.ts +9 -6
  34. package/es/display-objects/Text.js +15 -10
  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 +14 -9
  41. package/es/dom/Element.js +41 -14
  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 +4 -1
  58. package/es/global-module.js +38 -80
  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 +22 -24
  68. package/es/property-handlers/anchor.js +2 -1
  69. package/es/property-handlers/color.js +5 -2
  70. package/es/property-handlers/dimension.d.ts +15 -2
  71. package/es/property-handlers/dimension.js +77 -8
  72. package/es/property-handlers/index.d.ts +3 -0
  73. package/es/property-handlers/index.js +4 -1
  74. package/es/property-handlers/inherit.d.ts +6 -0
  75. package/es/property-handlers/inherit.js +25 -0
  76. package/es/property-handlers/interfaces.d.ts +2 -2
  77. package/es/property-handlers/lineDash.d.ts +6 -1
  78. package/es/property-handlers/lineDash.js +23 -4
  79. package/es/property-handlers/offsetDistance.js +2 -2
  80. package/es/property-handlers/path.d.ts +1 -1
  81. package/es/property-handlers/text.d.ts +2 -0
  82. package/es/property-handlers/text.js +3 -0
  83. package/es/property-handlers/textTransform.d.ts +6 -0
  84. package/es/property-handlers/textTransform.js +19 -0
  85. package/es/services/EventService.js +3 -5
  86. package/es/services/RenderingContext.d.ts +5 -8
  87. package/es/services/RenderingContext.js +6 -7
  88. package/es/services/RenderingService.js +2 -8
  89. package/es/services/SceneGraphSelector.d.ts +3 -2
  90. package/es/services/SceneGraphSelector.js +8 -4
  91. package/es/services/SceneGraphService.d.ts +7 -14
  92. package/es/services/SceneGraphService.js +14 -82
  93. package/es/services/aabb/CircleUpdater.d.ts +2 -2
  94. package/es/services/aabb/CircleUpdater.js +21 -11
  95. package/es/services/aabb/EllipseUpdater.d.ts +2 -2
  96. package/es/services/aabb/EllipseUpdater.js +28 -13
  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.d.ts +2 -2
  101. package/es/services/aabb/RectUpdater.js +33 -17
  102. package/es/services/aabb/TextUpdater.js +19 -10
  103. package/es/services/aabb/interfaces.d.ts +1 -1
  104. package/es/services/aabb/interfaces.js +1 -1
  105. package/es/services/text/index.js +19 -21
  106. package/es/shapes/AABB.d.ts +1 -0
  107. package/es/shapes/AABB.js +8 -0
  108. package/es/types.d.ts +48 -27
  109. package/es/types.js +50 -31
  110. package/es/utils/custom-easing.js +1 -1
  111. package/es/utils/event.js +5 -3
  112. package/es/utils/index.d.ts +1 -0
  113. package/es/utils/index.js +2 -1
  114. package/es/utils/interpolation.d.ts +1 -0
  115. package/es/utils/interpolation.js +41 -8
  116. package/es/utils/path.d.ts +1 -1
  117. package/es/utils/path.js +16 -16
  118. package/es/utils/raf.d.ts +1 -1
  119. package/es/utils/raf.js +0 -2
  120. package/es/utils/string.d.ts +1 -0
  121. package/es/utils/string.js +9 -0
  122. package/es/utils/text.js +3 -3
  123. package/lib/Canvas.d.ts +3 -0
  124. package/lib/Canvas.js +7 -7
  125. package/lib/camera/Camera.d.ts +3 -2
  126. package/lib/camera/Camera.js +20 -10
  127. package/lib/canvas-module.js +10 -15
  128. package/lib/components/Transform.d.ts +0 -1
  129. package/lib/components/Transform.js +0 -1
  130. package/lib/display-objects/Circle.d.ts +4 -2
  131. package/lib/display-objects/Circle.js +7 -2
  132. package/lib/display-objects/CustomElement.d.ts +3 -2
  133. package/lib/display-objects/CustomElement.js +9 -6
  134. package/lib/display-objects/DisplayObject.d.ts +4 -3
  135. package/lib/display-objects/DisplayObject.js +79 -46
  136. package/lib/display-objects/Ellipse.d.ts +6 -3
  137. package/lib/display-objects/Ellipse.js +7 -2
  138. package/lib/display-objects/Group.d.ts +18 -2
  139. package/lib/display-objects/Group.js +13 -9
  140. package/lib/display-objects/HTML.d.ts +6 -1
  141. package/lib/display-objects/HTML.js +9 -5
  142. package/lib/display-objects/Image.d.ts +12 -7
  143. package/lib/display-objects/Image.js +9 -2
  144. package/lib/display-objects/Line.d.ts +1 -1
  145. package/lib/display-objects/Line.js +11 -3
  146. package/lib/display-objects/Path.d.ts +3 -2
  147. package/lib/display-objects/Path.js +9 -4
  148. package/lib/display-objects/Polygon.d.ts +1 -1
  149. package/lib/display-objects/Polygon.js +8 -2
  150. package/lib/display-objects/Polyline.d.ts +1 -1
  151. package/lib/display-objects/Polyline.js +9 -4
  152. package/lib/display-objects/Rect.d.ts +8 -5
  153. package/lib/display-objects/Rect.js +8 -3
  154. package/lib/display-objects/Text.d.ts +9 -6
  155. package/lib/display-objects/Text.js +14 -9
  156. package/lib/dom/Animation.js +1 -1
  157. package/lib/dom/AnimationTimeline.js +1 -2
  158. package/lib/dom/CustomElementRegistry.js +11 -11
  159. package/lib/dom/Document.d.ts +1 -0
  160. package/lib/dom/Document.js +22 -1
  161. package/lib/dom/Element.d.ts +14 -9
  162. package/lib/dom/Element.js +43 -14
  163. package/lib/dom/EventTarget.d.ts +2 -2
  164. package/lib/dom/EventTarget.js +4 -3
  165. package/lib/dom/KeyframeList.js +1 -1
  166. package/lib/dom/MutationEvent.d.ts +15 -0
  167. package/lib/dom/MutationEvent.js +37 -0
  168. package/lib/dom/MutationObserver.d.ts +36 -0
  169. package/lib/dom/MutationObserver.js +424 -0
  170. package/lib/dom/MutationRecord.d.ts +14 -0
  171. package/lib/dom/MutationRecord.js +38 -0
  172. package/lib/dom/Node.d.ts +35 -3
  173. package/lib/dom/Node.js +185 -16
  174. package/lib/dom/index.d.ts +3 -0
  175. package/lib/dom/index.js +39 -0
  176. package/lib/dom/interfaces.d.ts +36 -8
  177. package/lib/dom/interfaces.js +23 -5
  178. package/lib/global-module.d.ts +4 -1
  179. package/lib/global-module.js +44 -76
  180. package/lib/index.d.ts +1 -0
  181. package/lib/index.js +3 -1
  182. package/lib/plugins/CullingPlugin.d.ts +0 -2
  183. package/lib/plugins/CullingPlugin.js +2 -23
  184. package/lib/plugins/DirtyCheckPlugin.js +1 -1
  185. package/lib/plugins/FrustumCullingStrategy.d.ts +1 -0
  186. package/lib/plugins/FrustumCullingStrategy.js +41 -33
  187. package/lib/plugins/PrepareRendererPlugin.js +24 -4
  188. package/lib/property-handlers/aabb.js +21 -23
  189. package/lib/property-handlers/anchor.js +3 -1
  190. package/lib/property-handlers/color.js +6 -3
  191. package/lib/property-handlers/dimension.d.ts +15 -2
  192. package/lib/property-handlers/dimension.js +80 -7
  193. package/lib/property-handlers/index.d.ts +3 -0
  194. package/lib/property-handlers/index.js +39 -0
  195. package/lib/property-handlers/inherit.d.ts +6 -0
  196. package/lib/property-handlers/inherit.js +34 -0
  197. package/lib/property-handlers/interfaces.d.ts +2 -2
  198. package/lib/property-handlers/lineDash.d.ts +6 -1
  199. package/lib/property-handlers/lineDash.js +25 -4
  200. package/lib/property-handlers/offsetDistance.js +1 -1
  201. package/lib/property-handlers/path.d.ts +1 -1
  202. package/lib/property-handlers/text.d.ts +2 -0
  203. package/lib/property-handlers/text.js +10 -0
  204. package/lib/property-handlers/textTransform.d.ts +6 -0
  205. package/lib/property-handlers/textTransform.js +27 -0
  206. package/lib/services/EventService.js +3 -5
  207. package/lib/services/RenderingContext.d.ts +5 -8
  208. package/lib/services/RenderingContext.js +8 -9
  209. package/lib/services/RenderingService.js +1 -7
  210. package/lib/services/SceneGraphSelector.d.ts +3 -2
  211. package/lib/services/SceneGraphSelector.js +10 -3
  212. package/lib/services/SceneGraphService.d.ts +7 -14
  213. package/lib/services/SceneGraphService.js +15 -82
  214. package/lib/services/aabb/CircleUpdater.d.ts +2 -2
  215. package/lib/services/aabb/CircleUpdater.js +20 -10
  216. package/lib/services/aabb/EllipseUpdater.d.ts +2 -2
  217. package/lib/services/aabb/EllipseUpdater.js +27 -12
  218. package/lib/services/aabb/LineUpdater.js +1 -1
  219. package/lib/services/aabb/PathUpdater.js +1 -1
  220. package/lib/services/aabb/PolylineUpdater.js +2 -2
  221. package/lib/services/aabb/RectUpdater.d.ts +2 -2
  222. package/lib/services/aabb/RectUpdater.js +32 -16
  223. package/lib/services/aabb/TextUpdater.js +18 -9
  224. package/lib/services/aabb/interfaces.d.ts +1 -1
  225. package/lib/services/aabb/interfaces.js +1 -1
  226. package/lib/services/text/index.js +19 -21
  227. package/lib/shapes/AABB.d.ts +1 -0
  228. package/lib/shapes/AABB.js +8 -0
  229. package/lib/types.d.ts +48 -27
  230. package/lib/types.js +56 -35
  231. package/lib/utils/custom-easing.js +1 -1
  232. package/lib/utils/event.js +5 -3
  233. package/lib/utils/index.d.ts +1 -0
  234. package/lib/utils/index.js +13 -0
  235. package/lib/utils/interpolation.d.ts +1 -0
  236. package/lib/utils/interpolation.js +43 -7
  237. package/lib/utils/path.d.ts +1 -1
  238. package/lib/utils/path.js +15 -15
  239. package/lib/utils/raf.d.ts +1 -1
  240. package/lib/utils/raf.js +0 -2
  241. package/lib/utils/string.d.ts +1 -0
  242. package/lib/utils/string.js +16 -0
  243. package/lib/utils/text.js +3 -3
  244. package/package.json +6 -4
@@ -12,8 +12,6 @@ export interface CullingStrategyContribution {
12
12
  */
13
13
  export declare class CullingPlugin implements RenderingPlugin {
14
14
  static tag: string;
15
- private canvasConfig;
16
15
  private strategyProvider;
17
- private renderingContext;
18
16
  apply(renderingService: RenderingService): void;
19
17
  }
@@ -11,10 +11,6 @@ var _manaSyringe = require("mana-syringe");
11
11
 
12
12
  var _RenderingService = require("../services/RenderingService");
13
13
 
14
- var _RenderingContext = require("../services/RenderingContext");
15
-
16
- var _types = require("../types");
17
-
18
14
  var CullingStrategyContribution = _manaSyringe.Syringe.defineToken('CullingStrategyContribution');
19
15
  /**
20
16
  * apply following rules:
@@ -33,8 +29,6 @@ function () {
33
29
  CullingPlugin_1 = CullingPlugin;
34
30
 
35
31
  CullingPlugin.prototype.apply = function (renderingService) {
36
- var _this = this;
37
-
38
32
  var strategies = this.strategyProvider.getContributions();
39
33
  renderingService.hooks.prepare.tap(CullingPlugin_1.tag, function (object) {
40
34
  if (object) {
@@ -51,22 +45,9 @@ function () {
51
45
 
52
46
  if (object.isVisible()) {
53
47
  return object;
54
- } else {
55
- // Those invisible objects which get renderred in last frame should be saved for later use.
56
- var enableDirtyRectangleRendering = _this.canvasConfig.renderer.getConfig().enableDirtyRectangleRendering;
57
-
58
- if (enableDirtyRectangleRendering) {
59
- var removedRenderBounds = object.getRenderBounds();
60
-
61
- if (removedRenderBounds) {
62
- _this.renderingContext.removedRenderBoundsList.push(removedRenderBounds);
63
-
64
- _this.renderingContext.renderReasons.add(_RenderingContext.RENDER_REASON.DisplayObjectRemoved);
65
- }
66
- }
67
-
68
- return null;
69
48
  }
49
+
50
+ return null;
70
51
  }
71
52
 
72
53
  return object;
@@ -78,9 +59,7 @@ function () {
78
59
 
79
60
  var CullingPlugin_1;
80
61
  CullingPlugin.tag = 'CullingPlugin';
81
- (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_types.CanvasConfig), (0, _tslib.__metadata)("design:type", Object)], CullingPlugin.prototype, "canvasConfig", void 0);
82
62
  (0, _tslib.__decorate)([(0, _manaSyringe.contrib)(CullingStrategyContribution), (0, _tslib.__metadata)("design:type", Object)], CullingPlugin.prototype, "strategyProvider", void 0);
83
- (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_RenderingContext.RenderingContext), (0, _tslib.__metadata)("design:type", Object)], CullingPlugin.prototype, "renderingContext", void 0);
84
63
  CullingPlugin = CullingPlugin_1 = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
85
64
  contrib: _RenderingService.RenderingPluginContribution
86
65
  })], CullingPlugin);
@@ -34,7 +34,7 @@ function () {
34
34
 
35
35
  var renderable = object.renderable;
36
36
 
37
- var isDirty = renderable.dirty || _this.renderingContext.renderReasons.has(_RenderingContext.RENDER_REASON.CameraChanged);
37
+ var isDirty = renderable.dirty || _this.renderingContext.renderReasons.has(_RenderingContext.RenderReason.CAMERA_CHANGED);
38
38
 
39
39
  if (isDirty || !enableDirtyRectangleRendering) {
40
40
  return object;
@@ -1,6 +1,7 @@
1
1
  import { CullingStrategyContribution } from './CullingPlugin';
2
2
  import type { DisplayObject } from '../display-objects/DisplayObject';
3
3
  export declare class FrustumCullingStrategy implements CullingStrategyContribution {
4
+ private camera;
4
5
  isVisible(object: DisplayObject): boolean;
5
6
  /**
6
7
  *
@@ -7,47 +7,47 @@ exports.FrustumCullingStrategy = void 0;
7
7
 
8
8
  var _tslib = require("tslib");
9
9
 
10
- var _glMatrix = require("gl-matrix");
11
-
12
10
  var _manaSyringe = require("mana-syringe");
13
11
 
12
+ var _glMatrix = require("gl-matrix");
13
+
14
14
  var _CullingPlugin = require("./CullingPlugin");
15
15
 
16
16
  var _shapes = require("../shapes");
17
17
 
18
- // import { vec3, mat4 } from 'gl-matrix';
19
- // import { inject, singleton } from 'mana-syringe';
20
- // import type { Element } from '../dom';
18
+ var _Camera = require("../camera/Camera");
19
+
20
+ var _ = require("..");
21
+
22
+ // group is not a 2d shape
23
+ var shape2D = [_.Shape.CIRCLE, _.Shape.ELLIPSE, _.Shape.IMAGE, _.Shape.RECT, _.Shape.LINE, _.Shape.POLYLINE, _.Shape.POLYGON, _.Shape.TEXT, _.Shape.PATH, _.Shape.HTML];
24
+
21
25
  var FrustumCullingStrategy =
22
26
  /** @class */
23
27
  function () {
24
- function FrustumCullingStrategy() {} // @inject(DefaultCamera)
25
- // private camera: Camera;
26
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
27
-
28
+ function FrustumCullingStrategy() {}
28
29
 
29
30
  FrustumCullingStrategy.prototype.isVisible = function (object) {
30
- return true; // const entity = object.entity;
31
- // const cullable = object.cullable;
32
- // if (!cullable.enable) {
33
- // return true;
34
- // }
35
- // const renderBounds = object.getRenderBounds();
36
- // if (!renderBounds) {
37
- // return false;
38
- // }
39
- // const viewMatrix = this.camera.getViewTransform();
40
- // const vpMatrix = mat4.multiply(mat4.create(), this.camera.getPerspective(), viewMatrix);
41
- // // get VP matrix from camera
42
- // this.camera.getFrustum().extractFromVPMatrix(vpMatrix);
43
- // const parentVisibilityPlaneMask = (object.parentNode as Element)?.cullable?.visibilityPlaneMask;
44
- // cullable.visibilityPlaneMask = this.computeVisibilityWithPlaneMask(
45
- // renderBounds,
46
- // parentVisibilityPlaneMask || Mask.INDETERMINATE,
47
- // this.camera.getFrustum().planes,
48
- // );
49
- // cullable.visible = cullable.visibilityPlaneMask !== Mask.OUTSIDE;
50
- // return cullable.visible;
31
+ var _a, _b;
32
+
33
+ var cullable = object.cullable;
34
+
35
+ if (!cullable.enable) {
36
+ return true;
37
+ }
38
+
39
+ var renderBounds = object.getRenderBounds();
40
+
41
+ if (!renderBounds) {
42
+ return false;
43
+ } // get VP matrix from camera
44
+
45
+
46
+ var frustum = this.camera.getFrustum();
47
+ var parentVisibilityPlaneMask = (_b = (_a = object.parentNode) === null || _a === void 0 ? void 0 : _a.cullable) === null || _b === void 0 ? void 0 : _b.visibilityPlaneMask;
48
+ cullable.visibilityPlaneMask = this.computeVisibilityWithPlaneMask(object, renderBounds, parentVisibilityPlaneMask || _shapes.Mask.INDETERMINATE, frustum.planes);
49
+ cullable.visible = cullable.visibilityPlaneMask !== _shapes.Mask.OUTSIDE;
50
+ return cullable.visible;
51
51
  };
52
52
  /**
53
53
  *
@@ -65,7 +65,7 @@ function () {
65
65
  */
66
66
 
67
67
 
68
- FrustumCullingStrategy.prototype.computeVisibilityWithPlaneMask = function (aabb, parentPlaneMask, planes) {
68
+ FrustumCullingStrategy.prototype.computeVisibilityWithPlaneMask = function (object, aabb, parentPlaneMask, planes) {
69
69
  if (parentPlaneMask === _shapes.Mask.OUTSIDE || parentPlaneMask === _shapes.Mask.INSIDE) {
70
70
  // 父节点完全位于视锥内或者外部,直接返回
71
71
  return parentPlaneMask;
@@ -74,14 +74,21 @@ function () {
74
74
 
75
75
 
76
76
  var mask = _shapes.Mask.INSIDE;
77
+ var isShape2D = shape2D.indexOf(object.nodeName) > -1; // Use viewport culling for 2D shapes
78
+ // @see https://github.com/antvis/g/issues/914
77
79
 
78
80
  for (var k = 0, len = planes.length; k < len; ++k) {
79
81
  // For k greater than 31 (since 31 is the maximum number of INSIDE/INTERSECTING bits we can store), skip the optimization.
80
- var flag = k < 31 ? 1 << k : 0;
82
+ var flag = 1 << k;
81
83
 
82
- if (k < 31 && (parentPlaneMask & flag) === 0) {
84
+ if ((parentPlaneMask & flag) === 0) {
83
85
  // 父节点处于当前面内部,可以跳过
84
86
  continue;
87
+ } // skip near & far planes when testing 2D shapes
88
+
89
+
90
+ if (isShape2D && (k === 4 || k === 5)) {
91
+ continue;
85
92
  } // p-vertex n-vertex <-|plane p-vertex n-vertex
86
93
  // 使用 p-vertex 和 n-vertex 加速,避免进行平面和 aabb 全部顶点的相交检测
87
94
 
@@ -103,6 +110,7 @@ function () {
103
110
  return mask;
104
111
  };
105
112
 
113
+ (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_Camera.DefaultCamera), (0, _tslib.__metadata)("design:type", _Camera.Camera)], FrustumCullingStrategy.prototype, "camera", void 0);
106
114
  FrustumCullingStrategy = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
107
115
  contrib: _CullingPlugin.CullingStrategyContribution
108
116
  })], FrustumCullingStrategy);
@@ -7,10 +7,16 @@ exports.PrepareRendererPlugin = void 0;
7
7
 
8
8
  var _tslib = require("tslib");
9
9
 
10
+ var _util = require("@antv/util");
11
+
10
12
  var _manaSyringe = require("mana-syringe");
11
13
 
12
14
  var _dom = require("../dom");
13
15
 
16
+ var _globalModule = require("../global-module");
17
+
18
+ var _propertyHandlers = require("../property-handlers");
19
+
14
20
  var _services = require("../services");
15
21
 
16
22
  var PrepareRendererPlugin =
@@ -24,7 +30,7 @@ function () {
24
30
  var _this = this;
25
31
 
26
32
  var handleAttributeChanged = function handleAttributeChanged() {
27
- _this.renderingContext.renderReasons.add(_services.RENDER_REASON.DisplayObjectChanged);
33
+ _this.renderingContext.renderReasons.add(_services.RenderReason.DISPLAY_OBJECT_CHANGED);
28
34
  };
29
35
 
30
36
  var handleBoundsChanged = function handleBoundsChanged() {
@@ -32,7 +38,21 @@ function () {
32
38
  };
33
39
 
34
40
  var handleMounted = function handleMounted(e) {
35
- (0, _services.dirtifyToRoot)(e.target);
41
+ var object = e.target; // compute some style when mounted
42
+
43
+ _globalModule.INHERIT_PROPERTIES.forEach(function (name) {
44
+ if (object.getAttribute(name) === 'inherit') {
45
+ var computedValue = (0, _propertyHandlers.computeInheritStyleProperty)(object, name);
46
+
47
+ if (!(0, _util.isNil)(computedValue)) {
48
+ var oldParsedValue = object.parsedStyle[name];
49
+ object.parsedStyle[name] = computedValue;
50
+ object.updateStyleProperty(name, oldParsedValue, computedValue);
51
+ }
52
+ }
53
+ });
54
+
55
+ (0, _services.dirtifyToRoot)(object);
36
56
  renderingService.dirtify();
37
57
  };
38
58
 
@@ -46,7 +66,7 @@ function () {
46
66
 
47
67
  _this.renderingContext.root.addEventListener(_dom.ElementEvent.UNMOUNTED, handleUnmounted);
48
68
 
49
- _this.renderingContext.root.addEventListener(_dom.ElementEvent.ATTRIBUTE_CHANGED, handleAttributeChanged);
69
+ _this.renderingContext.root.addEventListener(_dom.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
50
70
 
51
71
  _this.renderingContext.root.addEventListener(_dom.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
52
72
  });
@@ -55,7 +75,7 @@ function () {
55
75
 
56
76
  _this.renderingContext.root.removeEventListener(_dom.ElementEvent.UNMOUNTED, handleUnmounted);
57
77
 
58
- _this.renderingContext.root.removeEventListener(_dom.ElementEvent.ATTRIBUTE_CHANGED, handleAttributeChanged);
78
+ _this.renderingContext.root.removeEventListener(_dom.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
59
79
 
60
80
  _this.renderingContext.root.removeEventListener(_dom.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
61
81
  });
@@ -49,13 +49,12 @@ function updateGeometry(oldValue, newValue, object) {
49
49
  _g = _a.offsetY,
50
50
  offsetY = _g === void 0 ? 0 : _g,
51
51
  _h = _a.offsetZ,
52
- offsetZ = _h === void 0 ? 0 : _h;
52
+ offsetZ = _h === void 0 ? 0 : _h; // object.parsedStyle.width = width;
53
+ // object.parsedStyle.height = height;
54
+ // object.parsedStyle.depth = depth;
53
55
 
54
- object.parsedStyle.width = width;
55
- object.parsedStyle.height = height;
56
- object.parsedStyle.depth = depth;
57
56
 
58
- if (object.nodeName === _types.SHAPE.Line || object.nodeName === _types.SHAPE.Polyline || object.nodeName === _types.SHAPE.Polygon || object.nodeName === _types.SHAPE.Path) {
57
+ if (object.nodeName === _types.Shape.LINE || object.nodeName === _types.Shape.POLYLINE || object.nodeName === _types.Shape.POLYGON || object.nodeName === _types.Shape.PATH) {
59
58
  object.parsedStyle.offsetX = x - (object.parsedStyle.defX || 0);
60
59
  object.parsedStyle.offsetY = y - (object.parsedStyle.defY || 0);
61
60
  object.parsedStyle.defX = x;
@@ -75,15 +74,14 @@ function updateGeometry(oldValue, newValue, object) {
75
74
 
76
75
 
77
76
  var _j = object.parsedStyle,
78
- _k = _j.lineWidth,
79
- lineWidth = _k === void 0 ? 0 : _k,
80
- _l = _j.anchor,
81
- anchor = _l === void 0 ? [0, 0] : _l,
77
+ lineWidth = _j.lineWidth,
78
+ _k = _j.anchor,
79
+ anchor = _k === void 0 ? [0, 0] : _k,
82
80
  shadowColor = _j.shadowColor,
83
- _m = _j.filter,
84
- filter = _m === void 0 ? [] : _m; // <Text> use textAlign & textBaseline instead of anchor
81
+ _l = _j.filter,
82
+ filter = _l === void 0 ? [] : _l; // <Text> use textAlign & textBaseline instead of anchor
85
83
 
86
- if (object.nodeName === _types.SHAPE.Text) {
84
+ if (object.nodeName === _types.Shape.TEXT) {
87
85
  delete object.parsedStyle.anchor;
88
86
  }
89
87
 
@@ -94,22 +92,22 @@ function updateGeometry(oldValue, newValue, object) {
94
92
 
95
93
  if (lineWidth) {
96
94
  // append border
97
- _glMatrix.vec3.add(halfExtents, halfExtents, _glMatrix.vec3.fromValues(lineWidth / 2, lineWidth / 2, 0));
95
+ _glMatrix.vec3.add(halfExtents, halfExtents, _glMatrix.vec3.fromValues(lineWidth.value / 2, lineWidth.value / 2, 0));
98
96
  }
99
97
 
100
98
  geometry_1.renderBounds.update(center, halfExtents); // account for shadow, only support constant value now
101
99
 
102
100
  if (shadowColor && shadowColor.type === _color.PARSED_COLOR_TYPE.Constant) {
103
- var _o = geometry_1.renderBounds,
104
- min = _o.min,
105
- max = _o.max;
106
- var _p = object.parsedStyle,
107
- _q = _p.shadowBlur,
108
- shadowBlur = _q === void 0 ? 0 : _q,
109
- _r = _p.shadowOffsetX,
110
- shadowOffsetX = _r === void 0 ? 0 : _r,
111
- _s = _p.shadowOffsetY,
112
- shadowOffsetY = _s === void 0 ? 0 : _s;
101
+ var _m = geometry_1.renderBounds,
102
+ min = _m.min,
103
+ max = _m.max;
104
+ var _o = object.parsedStyle,
105
+ _p = _o.shadowBlur,
106
+ shadowBlur = _p === void 0 ? 0 : _p,
107
+ _q = _o.shadowOffsetX,
108
+ shadowOffsetX = _q === void 0 ? 0 : _q,
109
+ _r = _o.shadowOffsetY,
110
+ shadowOffsetY = _r === void 0 ? 0 : _r;
113
111
  var shadowLeft = min[0] - shadowBlur + shadowOffsetX;
114
112
  var shadowRight = max[0] + shadowBlur + shadowOffsetX;
115
113
  var shadowTop = min[1] - shadowBlur + shadowOffsetY;
@@ -11,12 +11,14 @@ var _glMatrix = require("gl-matrix");
11
11
 
12
12
  var _services = require("../services");
13
13
 
14
+ var _shapes = require("../shapes");
15
+
14
16
  var _utils = require("../utils");
15
17
 
16
18
  function updateAnchor(oldValue, newValue, object) {
17
19
  var bounds = object.getGeometryBounds();
18
20
 
19
- if (bounds) {
21
+ if (!_shapes.AABB.isEmpty(bounds)) {
20
22
  var geometry = object.geometry;
21
23
 
22
24
  if (geometry && geometry.contentBounds) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -45,6 +45,9 @@ function parseColor(colorStr) {
45
45
  value: [0, 0, 0, 0],
46
46
  formatted: 'rgba(0,0,0,0)'
47
47
  };
48
+ } else if (colorStr === 'currentColor') {
49
+ // @see https://github.com/adobe-webplatform/Snap.svg/issues/526
50
+ colorStr = 'black';
48
51
  }
49
52
 
50
53
  var type = colorStr[0];
@@ -101,7 +104,7 @@ function parseColor(colorStr) {
101
104
  return {
102
105
  type: PARSED_COLOR_TYPE.Constant,
103
106
  value: rgba,
104
- formatted: color && "rgba(" + color.r + "," + color.g + "," + color.b + "," + color.opacity + ")" || 'rgba(0,0,0,0)'
107
+ formatted: color && "rgba(".concat(color.r, ",").concat(color.g, ",").concat(color.b, ",").concat(color.opacity, ")") || 'rgba(0,0,0,0)'
105
108
  };
106
109
  }
107
110
 
@@ -121,7 +124,7 @@ function mergeColors(left, right) {
121
124
  }
122
125
 
123
126
  rgba[3] = (0, _util.clamp)(rgba[3], 0, 1);
124
- return "rgba(" + rgba.join(',') + ")";
127
+ return "rgba(".concat(rgba.join(','), ")");
125
128
  }];
126
129
  }
127
130
 
@@ -1,18 +1,31 @@
1
1
  import type { DisplayObject } from '../display-objects/DisplayObject';
2
- export declare type LengthUnit = 'px' | '%';
2
+ /**
3
+ * @see https://drafts.csswg.org/css-values-4/#dimension
4
+ */
5
+ export declare type LengthUnit = 'px' | '%' | 'em';
3
6
  export declare type AngleUnit = 'deg' | 'rad' | 'turn';
4
7
  export declare type Unit = LengthUnit | AngleUnit | '';
5
8
  export interface ParsedElement {
6
9
  unit: Unit;
10
+ /**
11
+ * absolute value in pixels
12
+ */
7
13
  value: number;
8
14
  }
9
- export declare function parseDimension(unitRegExp: RegExp, string: string): ParsedElement | undefined;
15
+ export declare function parseDimension(unitRegExp: RegExp, string: string, object: DisplayObject, name: string): ParsedElement | undefined;
10
16
  /**
11
17
  * eg. 10px + 20px = 30px
12
18
  */
13
19
  export declare function mergeDimensions(left: ParsedElement, right: ParsedElement, nonNegative?: boolean, target?: DisplayObject | null, index?: number): [number, number, (value: number) => string];
20
+ /**
21
+ * length with only absolute unit, eg. 1px
22
+ */
14
23
  export declare const parseLength: any;
24
+ /**
25
+ * length with absolute or relative unit, eg. 1px, 0.7em, 50%
26
+ */
15
27
  export declare const parseLengthOrPercent: any;
16
28
  export declare const parseAngle: any;
29
+ export declare function parseLengthOrPercentList(list: (string | number)[]): ParsedElement[];
17
30
  export declare function convertPercentUnit(valueWithUnit: ParsedElement, vec3Index: number, target: DisplayObject | null): number;
18
31
  export declare function convertAngleUnit(valueWithUnit: ParsedElement): number;
@@ -9,6 +9,7 @@ exports.mergeDimensions = mergeDimensions;
9
9
  exports.parseAngle = void 0;
10
10
  exports.parseDimension = parseDimension;
11
11
  exports.parseLengthOrPercent = exports.parseLength = void 0;
12
+ exports.parseLengthOrPercentList = parseLengthOrPercentList;
12
13
 
13
14
  var _numeric = require("./numeric");
14
15
 
@@ -16,16 +17,28 @@ var _math = require("../utils/math");
16
17
 
17
18
  var _util = require("@antv/util");
18
19
 
20
+ var _shapes = require("../shapes");
21
+
22
+ var _inherit = require("./inherit");
23
+
19
24
  function isLengthUnit(unit) {
20
- return unit === 'px' || unit === '%';
25
+ return unit === 'px' || unit === '%' || unit === 'em';
21
26
  }
22
27
 
23
28
  function isAngleUnit(unit) {
24
29
  return unit === 'deg' || unit === 'rad' || unit === 'turn';
25
30
  }
26
31
 
27
- function parseDimension(unitRegExp, string) {
28
- string = string.trim().toLowerCase();
32
+ function parseDimension(unitRegExp, string, object, name) {
33
+ string = "".concat(string).trim().toLowerCase();
34
+
35
+ if (string === 'inherit') {
36
+ var computed = (0, _inherit.computeInheritStyleProperty)(object, name);
37
+
38
+ if (!(0, _util.isNil)(computed)) {
39
+ return computed;
40
+ }
41
+ }
29
42
 
30
43
  if (string === '0') {
31
44
  if ('px'.search(unitRegExp) >= 0) {
@@ -41,12 +54,41 @@ function parseDimension(unitRegExp, string) {
41
54
  value: 0
42
55
  };
43
56
  }
57
+ } else if (string === 'auto' || string === 'inherit') {
58
+ return {
59
+ unit: '',
60
+ value: 0
61
+ };
44
62
  }
45
63
 
46
64
  if ((0, _util.isFinite)(Number(string))) {
65
+ if ('px'.search(unitRegExp) >= 0) {
66
+ return {
67
+ unit: 'px',
68
+ value: Number(string)
69
+ };
70
+ } else {
71
+ return {
72
+ unit: '',
73
+ value: Number(string)
74
+ };
75
+ }
76
+ }
77
+
78
+ if (string.endsWith('em')) {
79
+ var pxValue = 0;
80
+
81
+ if (object.parentElement) {
82
+ var fontSize = object.parentElement.parsedStyle.fontSize;
83
+
84
+ if (fontSize && fontSize.value) {
85
+ pxValue = fontSize.value * Number(string.replace('em', ''));
86
+ }
87
+ }
88
+
47
89
  return {
48
- unit: '',
49
- value: Number(string)
90
+ unit: 'px',
91
+ value: pxValue
50
92
  };
51
93
  }
52
94
 
@@ -104,13 +146,44 @@ function mergeDimensions(left, right, nonNegative, target, index) {
104
146
  }
105
147
 
106
148
  var lengthUnits = 'px';
149
+ /**
150
+ * length with only absolute unit, eg. 1px
151
+ */
152
+
107
153
  var parseLength = parseDimension.bind(null, new RegExp(lengthUnits, 'g'));
154
+ /**
155
+ * length with absolute or relative unit, eg. 1px, 0.7em, 50%
156
+ */
157
+
108
158
  exports.parseLength = parseLength;
109
- var parseLengthOrPercent = parseDimension.bind(null, new RegExp(lengthUnits + '|%', 'g'));
159
+ var parseLengthOrPercent = parseDimension.bind(null, new RegExp(lengthUnits + '|%|em', 'g'));
110
160
  exports.parseLengthOrPercent = parseLengthOrPercent;
111
161
  var parseAngle = parseDimension.bind(null, /deg|rad|grad|turn/g);
112
162
  exports.parseAngle = parseAngle;
113
163
 
164
+ function parseLengthOrPercentList(list) {
165
+ return list.map(parseLengthOrPercent);
166
+ } // export function mergeDimensionsLists(
167
+ // left: ParsedElement[],
168
+ // right: ParsedElement[],
169
+ // target: DisplayObject | null,
170
+ // ): [ParsedElement[], ParsedElement[], (list: ParsedElement[]) => string] | undefined {
171
+ // if (left.length != right.length) {
172
+ // return;
173
+ // }
174
+ // return [
175
+ // leftValue,
176
+ // rightValue,
177
+ // (value: number) => {
178
+ // if (nonNegative) {
179
+ // value = Math.max(value, 0);
180
+ // }
181
+ // return numberToString(value) + unit;
182
+ // },
183
+ // ];
184
+ // }
185
+
186
+
114
187
  function convertPercentUnit(valueWithUnit, vec3Index, target) {
115
188
  if (valueWithUnit.unit === 'px') {
116
189
  return Number(valueWithUnit.value);
@@ -119,7 +192,7 @@ function convertPercentUnit(valueWithUnit, vec3Index, target) {
119
192
  var bounds = target.getBounds();
120
193
  var size = 0;
121
194
 
122
- if (bounds) {
195
+ if (!_shapes.AABB.isEmpty(bounds)) {
123
196
  size = bounds.halfExtents[vec3Index] * 2;
124
197
  }
125
198
 
@@ -16,3 +16,6 @@ export * from './path';
16
16
  export * from './points';
17
17
  export * from './filter';
18
18
  export * from './lineDash';
19
+ export * from './text';
20
+ export * from './textTransform';
21
+ export * from './inherit';
@@ -223,4 +223,43 @@ Object.keys(_lineDash).forEach(function (key) {
223
223
  return _lineDash[key];
224
224
  }
225
225
  });
226
+ });
227
+
228
+ var _text = require("./text");
229
+
230
+ Object.keys(_text).forEach(function (key) {
231
+ if (key === "default" || key === "__esModule") return;
232
+ if (key in exports && exports[key] === _text[key]) return;
233
+ Object.defineProperty(exports, key, {
234
+ enumerable: true,
235
+ get: function get() {
236
+ return _text[key];
237
+ }
238
+ });
239
+ });
240
+
241
+ var _textTransform = require("./textTransform");
242
+
243
+ Object.keys(_textTransform).forEach(function (key) {
244
+ if (key === "default" || key === "__esModule") return;
245
+ if (key in exports && exports[key] === _textTransform[key]) return;
246
+ Object.defineProperty(exports, key, {
247
+ enumerable: true,
248
+ get: function get() {
249
+ return _textTransform[key];
250
+ }
251
+ });
252
+ });
253
+
254
+ var _inherit = require("./inherit");
255
+
256
+ Object.keys(_inherit).forEach(function (key) {
257
+ if (key === "default" || key === "__esModule") return;
258
+ if (key in exports && exports[key] === _inherit[key]) return;
259
+ Object.defineProperty(exports, key, {
260
+ enumerable: true,
261
+ get: function get() {
262
+ return _inherit[key];
263
+ }
264
+ });
226
265
  });
@@ -0,0 +1,6 @@
1
+ import type { DisplayObject } from '..';
2
+ /**
3
+ * update descendants
4
+ */
5
+ export declare function updateInherit(oldValue: any, newValue: any, o: DisplayObject, service: any, name: string): void;
6
+ export declare function computeInheritStyleProperty(child: DisplayObject, name: string): any;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.computeInheritStyleProperty = computeInheritStyleProperty;
7
+ exports.updateInherit = updateInherit;
8
+
9
+ /**
10
+ * update descendants
11
+ */
12
+ function updateInherit(oldValue, newValue, o, service, name) {
13
+ o.children.forEach(function (child) {
14
+ if (child.getAttribute(name) === 'inherit') {
15
+ child.parsedStyle[name] = newValue;
16
+ var oldParsedValue = child.parsedStyle[name];
17
+ child.updateStyleProperty(name, oldParsedValue, newValue);
18
+ }
19
+ });
20
+ }
21
+
22
+ function computeInheritStyleProperty(child, name) {
23
+ var ascendant = child.parentElement;
24
+
25
+ while (ascendant) {
26
+ if (ascendant.getAttribute(name) !== 'inherit' && ascendant.parsedStyle.hasOwnProperty(name)) {
27
+ return ascendant.parsedStyle[name];
28
+ }
29
+
30
+ ascendant = ascendant.parentElement;
31
+ }
32
+
33
+ return null;
34
+ }