@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
@@ -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
  });
@@ -54,7 +54,7 @@ function updateGeometry(oldValue, newValue, object) {
54
54
  // object.parsedStyle.depth = depth;
55
55
 
56
56
 
57
- 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) {
58
58
  object.parsedStyle.offsetX = x - (object.parsedStyle.defX || 0);
59
59
  object.parsedStyle.offsetY = y - (object.parsedStyle.defY || 0);
60
60
  object.parsedStyle.defX = x;
@@ -74,15 +74,14 @@ function updateGeometry(oldValue, newValue, object) {
74
74
 
75
75
 
76
76
  var _j = object.parsedStyle,
77
- _k = _j.lineWidth,
78
- lineWidth = _k === void 0 ? 0 : _k,
79
- _l = _j.anchor,
80
- anchor = _l === void 0 ? [0, 0] : _l,
77
+ lineWidth = _j.lineWidth,
78
+ _k = _j.anchor,
79
+ anchor = _k === void 0 ? [0, 0] : _k,
81
80
  shadowColor = _j.shadowColor,
82
- _m = _j.filter,
83
- 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
84
83
 
85
- if (object.nodeName === _types.SHAPE.Text) {
84
+ if (object.nodeName === _types.Shape.TEXT) {
86
85
  delete object.parsedStyle.anchor;
87
86
  }
88
87
 
@@ -93,22 +92,22 @@ function updateGeometry(oldValue, newValue, object) {
93
92
 
94
93
  if (lineWidth) {
95
94
  // append border
96
- _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));
97
96
  }
98
97
 
99
98
  geometry_1.renderBounds.update(center, halfExtents); // account for shadow, only support constant value now
100
99
 
101
100
  if (shadowColor && shadowColor.type === _color.PARSED_COLOR_TYPE.Constant) {
102
- var _o = geometry_1.renderBounds,
103
- min = _o.min,
104
- max = _o.max;
105
- var _p = object.parsedStyle,
106
- _q = _p.shadowBlur,
107
- shadowBlur = _q === void 0 ? 0 : _q,
108
- _r = _p.shadowOffsetX,
109
- shadowOffsetX = _r === void 0 ? 0 : _r,
110
- _s = _p.shadowOffsetY,
111
- 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;
112
111
  var shadowLeft = min[0] - shadowBlur + shadowOffsetX;
113
112
  var shadowRight = max[0] + shadowBlur + shadowOffsetX;
114
113
  var shadowTop = min[1] - shadowBlur + shadowOffsetY;
@@ -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,17 +1,29 @@
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
- export declare type Unit = LengthUnit | AngleUnit | '' | 'auto';
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;
17
29
  export declare function parseLengthOrPercentList(list: (string | number)[]): ParsedElement[];
@@ -19,16 +19,26 @@ var _util = require("@antv/util");
19
19
 
20
20
  var _shapes = require("../shapes");
21
21
 
22
+ var _inherit = require("./inherit");
23
+
22
24
  function isLengthUnit(unit) {
23
- return unit === 'px' || unit === '%';
25
+ return unit === 'px' || unit === '%' || unit === 'em';
24
26
  }
25
27
 
26
28
  function isAngleUnit(unit) {
27
29
  return unit === 'deg' || unit === 'rad' || unit === 'turn';
28
30
  }
29
31
 
30
- function parseDimension(unitRegExp, string) {
31
- 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
+ }
32
42
 
33
43
  if (string === '0') {
34
44
  if ('px'.search(unitRegExp) >= 0) {
@@ -44,17 +54,41 @@ function parseDimension(unitRegExp, string) {
44
54
  value: 0
45
55
  };
46
56
  }
47
- } else if (string === 'auto') {
57
+ } else if (string === 'auto' || string === 'inherit') {
48
58
  return {
49
- unit: 'auto',
59
+ unit: '',
50
60
  value: 0
51
61
  };
52
62
  }
53
63
 
54
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
+
55
89
  return {
56
- unit: '',
57
- value: Number(string)
90
+ unit: 'px',
91
+ value: pxValue
58
92
  };
59
93
  }
60
94
 
@@ -112,9 +146,17 @@ function mergeDimensions(left, right, nonNegative, target, index) {
112
146
  }
113
147
 
114
148
  var lengthUnits = 'px';
149
+ /**
150
+ * length with only absolute unit, eg. 1px
151
+ */
152
+
115
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
+
116
158
  exports.parseLength = parseLength;
117
- var parseLengthOrPercent = parseDimension.bind(null, new RegExp(lengthUnits + '|%', 'g'));
159
+ var parseLengthOrPercent = parseDimension.bind(null, new RegExp(lengthUnits + '|%|em', 'g'));
118
160
  exports.parseLengthOrPercent = parseLengthOrPercent;
119
161
  var parseAngle = parseDimension.bind(null, /deg|rad|grad|turn/g);
120
162
  exports.parseAngle = parseAngle;
@@ -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
+ }
@@ -1,7 +1,7 @@
1
1
  import type { IElement } from '../dom/interfaces';
2
2
  import type { SceneGraphService } from '../services/SceneGraphService';
3
3
  export declare const StylePropertyParser = "StylePropertyParser";
4
- export declare type StylePropertyParser<Original, Parsed> = (value: Original, displayObject: IElement | null) => Parsed;
4
+ export declare type StylePropertyParser<Original, Parsed> = (value: Original, displayObject: IElement | null, name: string) => Parsed;
5
5
  export declare const StylePropertyParserFactory = "StylePropertyParserFactory";
6
6
  export declare type StylePropertyParserFactory = <Original, Parsed>(name: string) => StylePropertyParser<Original, Parsed>;
7
7
  export interface ParsedStyleProperty<T, V, Formatted = string> {
@@ -11,7 +11,7 @@ export interface ParsedStyleProperty<T, V, Formatted = string> {
11
11
  }
12
12
  export declare type Interpolatable = number | boolean | number[] | boolean[];
13
13
  export declare const StylePropertyUpdater = "StylePropertyUpdater";
14
- export declare type StylePropertyUpdater<Original> = (oldValue: Original, newValue: Original, displayObject: IElement, sceneGraphService: SceneGraphService) => void;
14
+ export declare type StylePropertyUpdater<Original> = (oldValue: Original, newValue: Original, displayObject: IElement, sceneGraphService: SceneGraphService, name: string) => void;
15
15
  export declare const StylePropertyUpdaterFactory = "StylePropertyUpdaterFactory";
16
16
  export declare type StylePropertyUpdaterFactory = <Original>(name: string) => StylePropertyUpdater<Original>;
17
17
  export declare const StylePropertyMerger = "StylePropertyMerger";
@@ -1 +1,6 @@
1
- export declare function parseLineDash(lineDash: number[]): number[];
1
+ /**
2
+ * format lineDash to [dash, dash]
3
+ *
4
+ * also support string format such as `"stroke-dasharray": "2px 4px"`
5
+ */
6
+ export declare function parseLineDash(lineDash: number[] | string): number[];
@@ -5,11 +5,32 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.parseLineDash = parseLineDash;
7
7
 
8
- // format lineDash to [dash, dash]
8
+ var _tslib = require("tslib");
9
+
10
+ var _util = require("@antv/util");
11
+
12
+ var _dimension = require("./dimension");
13
+
14
+ /**
15
+ * format lineDash to [dash, dash]
16
+ *
17
+ * also support string format such as `"stroke-dasharray": "2px 4px"`
18
+ */
9
19
  function parseLineDash(lineDash) {
10
- if (lineDash && lineDash.length === 1) {
11
- return [lineDash[0], lineDash[0]];
20
+ var formatted = [];
21
+
22
+ if ((0, _util.isString)(lineDash)) {
23
+ lineDash.split(' ').forEach(function (segment) {
24
+ var dimension = (0, _dimension.parseLength)(segment);
25
+ formatted.push(dimension.value);
26
+ });
27
+ } else {
28
+ formatted.push.apply(formatted, (0, _tslib.__spreadArray)([], (0, _tslib.__read)(lineDash), false));
29
+ }
30
+
31
+ if (formatted && formatted.length === 1) {
32
+ return [formatted[0], formatted[0]];
12
33
  }
13
34
 
14
- return [lineDash[0], lineDash[1]];
35
+ return [formatted[0], formatted[1]];
15
36
  }
@@ -17,7 +17,7 @@ function updateOffsetDistance(oldOffsetDistance, newOffsetDistance, object) {
17
17
 
18
18
  var offsetPathNodeName = object.attributes.offsetPath.nodeName;
19
19
 
20
- if (offsetPathNodeName === _types.SHAPE.Line || offsetPathNodeName === _types.SHAPE.Path || offsetPathNodeName === _types.SHAPE.Polyline) {
20
+ if (offsetPathNodeName === _types.Shape.LINE || offsetPathNodeName === _types.Shape.PATH || offsetPathNodeName === _types.Shape.POLYLINE) {
21
21
  var point = object.attributes.offsetPath.getPoint(newOffsetDistance);
22
22
 
23
23
  if (point) {
@@ -0,0 +1,2 @@
1
+ import type { DisplayObject } from '../display-objects/DisplayObject';
2
+ export declare function updateText(oldValue: string, newValue: string, object: DisplayObject): void;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.updateText = updateText;
7
+
8
+ function updateText(oldValue, newValue, object) {
9
+ object.nodeValue = "".concat(newValue) || '';
10
+ }
@@ -0,0 +1,6 @@
1
+ import { TextTransform } from '../types';
2
+ import type { DisplayObject } from '../display-objects';
3
+ /**
4
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/text-transform
5
+ */
6
+ export declare function updateTextTransform(oldTextTransform: TextTransform, newTextTransform: TextTransform, o: DisplayObject): void;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.updateTextTransform = updateTextTransform;
7
+
8
+ var _types = require("../types");
9
+
10
+ var _ = require("..");
11
+
12
+ /**
13
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/text-transform
14
+ */
15
+ function updateTextTransform(oldTextTransform, newTextTransform, o) {
16
+ if (o.nodeName === _.Shape.TEXT) {
17
+ var object = o;
18
+
19
+ if (newTextTransform === _types.TextTransform.CAPITALIZE) {
20
+ object.style.text = object.style.text.charAt(0).toUpperCase() + object.style.text.slice(1);
21
+ } else if (newTextTransform === _types.TextTransform.LOWERCASE) {
22
+ object.style.text = object.style.text.toLowerCase();
23
+ } else if (newTextTransform === _types.TextTransform.UPPERCASE) {
24
+ object.style.text = object.style.text.toUpperCase(); // } else if (newTextTransform === TextTransform.NONE) {
25
+ }
26
+ }
27
+ }