@antv/g 5.0.15 → 5.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/dist/index.umd.min.js +18 -2
  2. package/es/Canvas.d.ts +7 -1
  3. package/es/Canvas.js +9 -10
  4. package/es/camera/Camera.d.ts +3 -2
  5. package/es/camera/Camera.js +16 -8
  6. package/es/canvas-module.js +4 -2
  7. package/es/components/Transform.d.ts +0 -1
  8. package/es/components/Transform.js +0 -1
  9. package/es/display-objects/Circle.d.ts +1 -1
  10. package/es/display-objects/Circle.js +8 -3
  11. package/es/display-objects/CustomElement.d.ts +3 -2
  12. package/es/display-objects/CustomElement.js +9 -6
  13. package/es/display-objects/DisplayObject.d.ts +9 -3
  14. package/es/display-objects/DisplayObject.js +97 -50
  15. package/es/display-objects/Ellipse.d.ts +1 -1
  16. package/es/display-objects/Ellipse.js +8 -3
  17. package/es/display-objects/Group.d.ts +18 -2
  18. package/es/display-objects/Group.js +11 -9
  19. package/es/display-objects/HTML.d.ts +1 -1
  20. package/es/display-objects/HTML.js +9 -4
  21. package/es/display-objects/Image.d.ts +5 -3
  22. package/es/display-objects/Image.js +8 -3
  23. package/es/display-objects/Line.d.ts +1 -1
  24. package/es/display-objects/Line.js +12 -4
  25. package/es/display-objects/Path.d.ts +3 -2
  26. package/es/display-objects/Path.js +10 -5
  27. package/es/display-objects/Polygon.d.ts +1 -1
  28. package/es/display-objects/Polygon.js +9 -3
  29. package/es/display-objects/Polyline.d.ts +1 -1
  30. package/es/display-objects/Polyline.js +10 -5
  31. package/es/display-objects/Rect.d.ts +1 -1
  32. package/es/display-objects/Rect.js +8 -3
  33. package/es/display-objects/Text.d.ts +32 -4
  34. package/es/display-objects/Text.js +70 -10
  35. package/es/dom/Animation.js +2 -2
  36. package/es/dom/AnimationTimeline.js +1 -2
  37. package/es/dom/CustomElementRegistry.js +12 -12
  38. package/es/dom/Document.d.ts +2 -1
  39. package/es/dom/Document.js +22 -2
  40. package/es/dom/Element.d.ts +38 -5
  41. package/es/dom/Element.js +115 -16
  42. package/es/dom/EventTarget.d.ts +2 -2
  43. package/es/dom/EventTarget.js +4 -3
  44. package/es/dom/FederatedEvent.d.ts +4 -1
  45. package/es/dom/KeyframeList.js +1 -1
  46. package/es/dom/MutationEvent.d.ts +15 -0
  47. package/es/dom/MutationEvent.js +29 -0
  48. package/es/dom/MutationObserver.d.ts +36 -0
  49. package/es/dom/MutationObserver.js +413 -0
  50. package/es/dom/MutationRecord.d.ts +14 -0
  51. package/es/dom/MutationRecord.js +31 -0
  52. package/es/dom/Node.d.ts +35 -3
  53. package/es/dom/Node.js +184 -17
  54. package/es/dom/index.d.ts +3 -0
  55. package/es/dom/index.js +3 -0
  56. package/es/dom/interfaces.d.ts +39 -8
  57. package/es/dom/interfaces.js +23 -5
  58. package/es/global-module.d.ts +1 -0
  59. package/es/global-module.js +11 -13
  60. package/es/index.d.ts +1 -0
  61. package/es/index.js +1 -0
  62. package/es/plugins/CullingPlugin.d.ts +0 -2
  63. package/es/plugins/CullingPlugin.js +3 -24
  64. package/es/plugins/DirtyCheckPlugin.js +2 -2
  65. package/es/plugins/EventPlugin.d.ts +1 -0
  66. package/es/plugins/EventPlugin.js +15 -5
  67. package/es/plugins/FrustumCullingStrategy.d.ts +1 -0
  68. package/es/plugins/FrustumCullingStrategy.js +41 -33
  69. package/es/plugins/PrepareRendererPlugin.js +21 -5
  70. package/es/property-handlers/aabb.js +19 -20
  71. package/es/property-handlers/color.js +5 -2
  72. package/es/property-handlers/dimension.d.ts +15 -3
  73. package/es/property-handlers/dimension.js +50 -9
  74. package/es/property-handlers/index.d.ts +3 -0
  75. package/es/property-handlers/index.js +4 -1
  76. package/es/property-handlers/inherit.d.ts +6 -0
  77. package/es/property-handlers/inherit.js +25 -0
  78. package/es/property-handlers/interfaces.d.ts +2 -2
  79. package/es/property-handlers/lineDash.d.ts +6 -1
  80. package/es/property-handlers/lineDash.js +23 -4
  81. package/es/property-handlers/offsetDistance.js +2 -2
  82. package/es/property-handlers/text.d.ts +2 -0
  83. package/es/property-handlers/text.js +3 -0
  84. package/es/property-handlers/textTransform.d.ts +6 -0
  85. package/es/property-handlers/textTransform.js +19 -0
  86. package/es/services/EventService.js +11 -7
  87. package/es/services/RenderingContext.d.ts +5 -8
  88. package/es/services/RenderingContext.js +6 -7
  89. package/es/services/RenderingService.d.ts +12 -2
  90. package/es/services/RenderingService.js +23 -12
  91. package/es/services/SceneGraphSelector.d.ts +3 -2
  92. package/es/services/SceneGraphSelector.js +8 -4
  93. package/es/services/SceneGraphService.d.ts +0 -7
  94. package/es/services/SceneGraphService.js +17 -87
  95. package/es/services/aabb/CircleUpdater.js +3 -3
  96. package/es/services/aabb/EllipseUpdater.js +2 -2
  97. package/es/services/aabb/LineUpdater.js +2 -2
  98. package/es/services/aabb/PathUpdater.js +2 -2
  99. package/es/services/aabb/PolylineUpdater.js +3 -3
  100. package/es/services/aabb/RectUpdater.js +4 -4
  101. package/es/services/aabb/TextUpdater.js +31 -10
  102. package/es/services/text/index.js +19 -21
  103. package/es/shapes/AABB.js +5 -0
  104. package/es/types.d.ts +48 -24
  105. package/es/types.js +50 -31
  106. package/es/utils/animation.js +1 -1
  107. package/es/utils/custom-easing.js +1 -1
  108. package/es/utils/event.js +7 -4
  109. package/es/utils/index.d.ts +2 -0
  110. package/es/utils/index.js +3 -1
  111. package/es/utils/interpolation.d.ts +1 -0
  112. package/es/utils/interpolation.js +41 -8
  113. package/es/utils/path.js +11 -11
  114. package/es/utils/raf.d.ts +1 -1
  115. package/es/utils/raf.js +0 -2
  116. package/es/utils/string.d.ts +1 -0
  117. package/es/utils/string.js +9 -0
  118. package/es/utils/text.js +3 -3
  119. package/lib/Canvas.d.ts +7 -1
  120. package/lib/Canvas.js +7 -8
  121. package/lib/camera/Camera.d.ts +3 -2
  122. package/lib/camera/Camera.js +20 -10
  123. package/lib/canvas-module.js +3 -1
  124. package/lib/components/Transform.d.ts +0 -1
  125. package/lib/components/Transform.js +0 -1
  126. package/lib/display-objects/Circle.d.ts +1 -1
  127. package/lib/display-objects/Circle.js +7 -2
  128. package/lib/display-objects/CustomElement.d.ts +3 -2
  129. package/lib/display-objects/CustomElement.js +9 -6
  130. package/lib/display-objects/DisplayObject.d.ts +9 -3
  131. package/lib/display-objects/DisplayObject.js +97 -47
  132. package/lib/display-objects/Ellipse.d.ts +1 -1
  133. package/lib/display-objects/Ellipse.js +7 -2
  134. package/lib/display-objects/Group.d.ts +18 -2
  135. package/lib/display-objects/Group.js +10 -9
  136. package/lib/display-objects/HTML.d.ts +1 -1
  137. package/lib/display-objects/HTML.js +8 -4
  138. package/lib/display-objects/Image.d.ts +5 -3
  139. package/lib/display-objects/Image.js +7 -2
  140. package/lib/display-objects/Line.d.ts +1 -1
  141. package/lib/display-objects/Line.js +11 -3
  142. package/lib/display-objects/Path.d.ts +3 -2
  143. package/lib/display-objects/Path.js +9 -4
  144. package/lib/display-objects/Polygon.d.ts +1 -1
  145. package/lib/display-objects/Polygon.js +8 -2
  146. package/lib/display-objects/Polyline.d.ts +1 -1
  147. package/lib/display-objects/Polyline.js +9 -4
  148. package/lib/display-objects/Rect.d.ts +1 -1
  149. package/lib/display-objects/Rect.js +7 -2
  150. package/lib/display-objects/Text.d.ts +32 -4
  151. package/lib/display-objects/Text.js +69 -9
  152. package/lib/dom/Animation.js +2 -2
  153. package/lib/dom/AnimationTimeline.js +1 -2
  154. package/lib/dom/CustomElementRegistry.js +11 -11
  155. package/lib/dom/Document.d.ts +2 -1
  156. package/lib/dom/Document.js +24 -3
  157. package/lib/dom/Element.d.ts +38 -5
  158. package/lib/dom/Element.js +117 -16
  159. package/lib/dom/EventTarget.d.ts +2 -2
  160. package/lib/dom/EventTarget.js +4 -3
  161. package/lib/dom/FederatedEvent.d.ts +4 -1
  162. package/lib/dom/KeyframeList.js +1 -1
  163. package/lib/dom/MutationEvent.d.ts +15 -0
  164. package/lib/dom/MutationEvent.js +37 -0
  165. package/lib/dom/MutationObserver.d.ts +36 -0
  166. package/lib/dom/MutationObserver.js +424 -0
  167. package/lib/dom/MutationRecord.d.ts +14 -0
  168. package/lib/dom/MutationRecord.js +38 -0
  169. package/lib/dom/Node.d.ts +35 -3
  170. package/lib/dom/Node.js +185 -16
  171. package/lib/dom/index.d.ts +3 -0
  172. package/lib/dom/index.js +39 -0
  173. package/lib/dom/interfaces.d.ts +39 -8
  174. package/lib/dom/interfaces.js +23 -5
  175. package/lib/global-module.d.ts +1 -0
  176. package/lib/global-module.js +12 -8
  177. package/lib/index.d.ts +1 -0
  178. package/lib/index.js +3 -1
  179. package/lib/plugins/CullingPlugin.d.ts +0 -2
  180. package/lib/plugins/CullingPlugin.js +2 -23
  181. package/lib/plugins/DirtyCheckPlugin.js +1 -1
  182. package/lib/plugins/EventPlugin.d.ts +1 -0
  183. package/lib/plugins/EventPlugin.js +13 -5
  184. package/lib/plugins/FrustumCullingStrategy.d.ts +1 -0
  185. package/lib/plugins/FrustumCullingStrategy.js +42 -33
  186. package/lib/plugins/PrepareRendererPlugin.js +24 -4
  187. package/lib/property-handlers/aabb.js +18 -19
  188. package/lib/property-handlers/color.js +6 -3
  189. package/lib/property-handlers/dimension.d.ts +15 -3
  190. package/lib/property-handlers/dimension.js +50 -8
  191. package/lib/property-handlers/index.d.ts +3 -0
  192. package/lib/property-handlers/index.js +39 -0
  193. package/lib/property-handlers/inherit.d.ts +6 -0
  194. package/lib/property-handlers/inherit.js +34 -0
  195. package/lib/property-handlers/interfaces.d.ts +2 -2
  196. package/lib/property-handlers/lineDash.d.ts +6 -1
  197. package/lib/property-handlers/lineDash.js +25 -4
  198. package/lib/property-handlers/offsetDistance.js +1 -1
  199. package/lib/property-handlers/text.d.ts +2 -0
  200. package/lib/property-handlers/text.js +10 -0
  201. package/lib/property-handlers/textTransform.d.ts +6 -0
  202. package/lib/property-handlers/textTransform.js +27 -0
  203. package/lib/services/EventService.js +11 -7
  204. package/lib/services/RenderingContext.d.ts +5 -8
  205. package/lib/services/RenderingContext.js +8 -9
  206. package/lib/services/RenderingService.d.ts +12 -2
  207. package/lib/services/RenderingService.js +23 -11
  208. package/lib/services/SceneGraphSelector.d.ts +3 -2
  209. package/lib/services/SceneGraphSelector.js +10 -3
  210. package/lib/services/SceneGraphService.d.ts +0 -7
  211. package/lib/services/SceneGraphService.js +18 -91
  212. package/lib/services/aabb/CircleUpdater.js +2 -2
  213. package/lib/services/aabb/EllipseUpdater.js +1 -1
  214. package/lib/services/aabb/LineUpdater.js +1 -1
  215. package/lib/services/aabb/PathUpdater.js +1 -1
  216. package/lib/services/aabb/PolylineUpdater.js +2 -2
  217. package/lib/services/aabb/RectUpdater.js +3 -3
  218. package/lib/services/aabb/TextUpdater.js +30 -9
  219. package/lib/services/text/index.js +19 -21
  220. package/lib/shapes/AABB.js +5 -0
  221. package/lib/types.d.ts +48 -24
  222. package/lib/types.js +56 -35
  223. package/lib/utils/animation.js +1 -1
  224. package/lib/utils/custom-easing.js +1 -1
  225. package/lib/utils/event.js +7 -4
  226. package/lib/utils/index.d.ts +2 -0
  227. package/lib/utils/index.js +26 -0
  228. package/lib/utils/interpolation.d.ts +1 -0
  229. package/lib/utils/interpolation.js +43 -7
  230. package/lib/utils/path.js +10 -10
  231. package/lib/utils/raf.d.ts +1 -1
  232. package/lib/utils/raf.js +0 -2
  233. package/lib/utils/string.d.ts +1 -0
  234. package/lib/utils/string.js +16 -0
  235. package/lib/utils/text.js +3 -3
  236. package/package.json +5 -3
@@ -40,6 +40,8 @@ function () {
40
40
  this.onPointerMove = function (nativeEvent) {
41
41
  var e_1, _a;
42
42
 
43
+ var _b, _c;
44
+
43
45
  if (_event.supportsTouchEvents && nativeEvent.pointerType === 'touch') return;
44
46
  var normalizedEvents = (0, _event.normalizeToPointerEvent)(nativeEvent);
45
47
 
@@ -47,7 +49,7 @@ function () {
47
49
  for (var normalizedEvents_1 = (0, _tslib.__values)(normalizedEvents), normalizedEvents_1_1 = normalizedEvents_1.next(); !normalizedEvents_1_1.done; normalizedEvents_1_1 = normalizedEvents_1.next()) {
48
50
  var normalizedEvent = normalizedEvents_1_1.value;
49
51
 
50
- var event_1 = _this.bootstrapEvent(_this.rootPointerEvent, normalizedEvent);
52
+ var event_1 = _this.bootstrapEvent(_this.rootPointerEvent, normalizedEvent, (_c = (_b = _this.renderingContext.root) === null || _b === void 0 ? void 0 : _b.ownerDocument) === null || _c === void 0 ? void 0 : _c.defaultView);
51
53
 
52
54
  _this.eventService.mapEvent(event_1);
53
55
  }
@@ -102,6 +104,8 @@ function () {
102
104
  renderingService.hooks.pointerDown.tap(EventPlugin_1.tag, function (nativeEvent) {
103
105
  var e_2, _a;
104
106
 
107
+ var _b, _c;
108
+
105
109
  if (_event.supportsTouchEvents && nativeEvent.pointerType === 'touch') {
106
110
  return;
107
111
  }
@@ -120,7 +124,7 @@ function () {
120
124
  for (var events_1 = (0, _tslib.__values)(events), events_1_1 = events_1.next(); !events_1_1.done; events_1_1 = events_1.next()) {
121
125
  var event_2 = events_1_1.value;
122
126
 
123
- var federatedEvent = _this.bootstrapEvent(_this.rootPointerEvent, event_2);
127
+ var federatedEvent = _this.bootstrapEvent(_this.rootPointerEvent, event_2, (_c = (_b = _this.renderingContext.root) === null || _b === void 0 ? void 0 : _b.ownerDocument) === null || _c === void 0 ? void 0 : _c.defaultView);
124
128
 
125
129
  _this.eventService.mapEvent(federatedEvent);
126
130
  }
@@ -141,6 +145,8 @@ function () {
141
145
  renderingService.hooks.pointerUp.tap(EventPlugin_1.tag, function (nativeEvent) {
142
146
  var e_3, _a;
143
147
 
148
+ var _b, _c;
149
+
144
150
  if (_event.supportsTouchEvents && nativeEvent.pointerType === 'touch') return; // account for element in SVG
145
151
 
146
152
  var $element = _this.contextService.getDomElement();
@@ -154,7 +160,7 @@ function () {
154
160
  for (var normalizedEvents_2 = (0, _tslib.__values)(normalizedEvents), normalizedEvents_2_1 = normalizedEvents_2.next(); !normalizedEvents_2_1.done; normalizedEvents_2_1 = normalizedEvents_2.next()) {
155
161
  var normalizedEvent = normalizedEvents_2_1.value;
156
162
 
157
- var event_3 = _this.bootstrapEvent(_this.rootPointerEvent, normalizedEvent);
163
+ var event_3 = _this.bootstrapEvent(_this.rootPointerEvent, normalizedEvent, (_c = (_b = _this.renderingContext.root) === null || _b === void 0 ? void 0 : _b.ownerDocument) === null || _c === void 0 ? void 0 : _c.defaultView);
158
164
 
159
165
  event_3.type += outside;
160
166
 
@@ -179,8 +185,9 @@ function () {
179
185
  renderingService.hooks.pointerOut.tap(EventPlugin_1.tag, this.onPointerMove);
180
186
  };
181
187
 
182
- EventPlugin.prototype.bootstrapEvent = function (event, nativeEvent) {
183
- // @ts-ignore
188
+ EventPlugin.prototype.bootstrapEvent = function (event, nativeEvent, view) {
189
+ event.view = view; // @ts-ignore
190
+
184
191
  event._originalEvent = null;
185
192
  event.nativeEvent = nativeEvent;
186
193
  event.pointerId = nativeEvent.pointerId;
@@ -288,6 +295,7 @@ function () {
288
295
  (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_types.CanvasConfig), (0, _tslib.__metadata)("design:type", Object)], EventPlugin.prototype, "canvasConfig", void 0);
289
296
  (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_services.ContextService), (0, _tslib.__metadata)("design:type", Object)], EventPlugin.prototype, "contextService", void 0);
290
297
  (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_services.RenderingService), (0, _tslib.__metadata)("design:type", _services.RenderingService)], EventPlugin.prototype, "renderingService", void 0);
298
+ (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_services.RenderingContext), (0, _tslib.__metadata)("design:type", Object)], EventPlugin.prototype, "renderingContext", void 0);
291
299
  (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_services.EventService), (0, _tslib.__metadata)("design:type", _services.EventService)], EventPlugin.prototype, "eventService", void 0);
292
300
  EventPlugin = EventPlugin_1 = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
293
301
  contrib: _services.RenderingPluginContribution
@@ -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,48 @@ 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
+ // return true;
32
+ var _a, _b;
33
+
34
+ var cullable = object.cullable;
35
+
36
+ if (!cullable.enable) {
37
+ return true;
38
+ }
39
+
40
+ var renderBounds = object.getRenderBounds();
41
+
42
+ if (_shapes.AABB.isEmpty(renderBounds)) {
43
+ return false;
44
+ } // get VP matrix from camera
45
+
46
+
47
+ var frustum = this.camera.getFrustum();
48
+ var parentVisibilityPlaneMask = (_b = (_a = object.parentNode) === null || _a === void 0 ? void 0 : _a.cullable) === null || _b === void 0 ? void 0 : _b.visibilityPlaneMask;
49
+ cullable.visibilityPlaneMask = this.computeVisibilityWithPlaneMask(object, renderBounds, parentVisibilityPlaneMask || _shapes.Mask.INDETERMINATE, frustum.planes);
50
+ cullable.visible = cullable.visibilityPlaneMask !== _shapes.Mask.OUTSIDE;
51
+ return cullable.visible;
51
52
  };
52
53
  /**
53
54
  *
@@ -65,7 +66,7 @@ function () {
65
66
  */
66
67
 
67
68
 
68
- FrustumCullingStrategy.prototype.computeVisibilityWithPlaneMask = function (aabb, parentPlaneMask, planes) {
69
+ FrustumCullingStrategy.prototype.computeVisibilityWithPlaneMask = function (object, aabb, parentPlaneMask, planes) {
69
70
  if (parentPlaneMask === _shapes.Mask.OUTSIDE || parentPlaneMask === _shapes.Mask.INSIDE) {
70
71
  // 父节点完全位于视锥内或者外部,直接返回
71
72
  return parentPlaneMask;
@@ -74,14 +75,21 @@ function () {
74
75
 
75
76
 
76
77
  var mask = _shapes.Mask.INSIDE;
78
+ var isShape2D = shape2D.indexOf(object.nodeName) > -1; // Use viewport culling for 2D shapes
79
+ // @see https://github.com/antvis/g/issues/914
77
80
 
78
81
  for (var k = 0, len = planes.length; k < len; ++k) {
79
82
  // 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;
83
+ var flag = 1 << k;
81
84
 
82
- if (k < 31 && (parentPlaneMask & flag) === 0) {
85
+ if ((parentPlaneMask & flag) === 0) {
83
86
  // 父节点处于当前面内部,可以跳过
84
87
  continue;
88
+ } // skip near & far planes when testing 2D shapes
89
+
90
+
91
+ if (isShape2D && (k === 4 || k === 5)) {
92
+ continue;
85
93
  } // p-vertex n-vertex <-|plane p-vertex n-vertex
86
94
  // 使用 p-vertex 和 n-vertex 加速,避免进行平面和 aabb 全部顶点的相交检测
87
95
 
@@ -103,6 +111,7 @@ function () {
103
111
  return mask;
104
112
  };
105
113
 
114
+ (0, _tslib.__decorate)([(0, _manaSyringe.inject)(_Camera.DefaultCamera), (0, _tslib.__metadata)("design:type", _Camera.Camera)], FrustumCullingStrategy.prototype, "camera", void 0);
106
115
  FrustumCullingStrategy = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)({
107
116
  contrib: _CullingPlugin.CullingStrategyContribution
108
117
  })], 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
  }