@antv/g 5.6.4 → 5.7.0

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 (35) hide show
  1. package/dist/css/StyleValueRegistry.d.ts.map +1 -1
  2. package/dist/css/interfaces.d.ts +1 -0
  3. package/dist/css/interfaces.d.ts.map +1 -1
  4. package/dist/css/properties/CSSPropertyMarker.d.ts +6 -0
  5. package/dist/css/properties/CSSPropertyMarker.d.ts.map +1 -0
  6. package/dist/css/properties/index.d.ts +1 -0
  7. package/dist/css/properties/index.d.ts.map +1 -1
  8. package/dist/display-objects/CustomElement.d.ts +1 -1
  9. package/dist/display-objects/CustomElement.d.ts.map +1 -1
  10. package/dist/display-objects/DisplayObject.d.ts +1 -1
  11. package/dist/display-objects/DisplayObject.d.ts.map +1 -1
  12. package/dist/display-objects/Line.d.ts +30 -0
  13. package/dist/display-objects/Line.d.ts.map +1 -1
  14. package/dist/display-objects/Path.d.ts +43 -0
  15. package/dist/display-objects/Path.d.ts.map +1 -1
  16. package/dist/display-objects/Polygon.d.ts +34 -0
  17. package/dist/display-objects/Polygon.d.ts.map +1 -1
  18. package/dist/display-objects/Polyline.d.ts +29 -2
  19. package/dist/display-objects/Polyline.d.ts.map +1 -1
  20. package/dist/dom/FederatedMouseEvent.d.ts +0 -2
  21. package/dist/dom/FederatedMouseEvent.d.ts.map +1 -1
  22. package/dist/global-module.d.ts.map +1 -1
  23. package/dist/index.esm.js +594 -85
  24. package/dist/index.js +593 -84
  25. package/dist/index.umd.js +593 -84
  26. package/dist/index.umd.min.js +2 -2
  27. package/dist/plugins/PrepareRendererPlugin.d.ts.map +1 -1
  28. package/dist/services/SceneGraphService.d.ts +1 -1
  29. package/dist/services/SceneGraphService.d.ts.map +1 -1
  30. package/dist/shapes/AABB.d.ts.map +1 -1
  31. package/dist/types.d.ts +53 -7
  32. package/dist/types.d.ts.map +1 -1
  33. package/dist/utils/path.d.ts +1 -1
  34. package/dist/utils/path.d.ts.map +1 -1
  35. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -2129,6 +2129,7 @@ function computeRadialGradient(width, height, cx, cy) {
2129
2129
  PropertySyntax["OFFSET_PATH"] = "<offset-path>";
2130
2130
  PropertySyntax["OFFSET_DISTANCE"] = "<offset-distance>";
2131
2131
  PropertySyntax["CLIP_PATH"] = "<clip-path>";
2132
+ PropertySyntax["MARKER"] = "<marker>";
2132
2133
  PropertySyntax["TRANSFORM"] = "<transform>";
2133
2134
  PropertySyntax["TRANSFORM_ORIGIN"] = "<transform-origin>";
2134
2135
  PropertySyntax["TEXT"] = "<text>";
@@ -2931,25 +2932,45 @@ function convertToPath(object, applyLocalTransform) {
2931
2932
  return commandsToPathString(commands, object, applyLocalTransform);
2932
2933
  }
2933
2934
  }
2934
- function translatePathToString(pathArray, x, y) {
2935
- var newValue = pathArray.map(function (params) {
2936
- var command = params[0];
2935
+ function translatePathToString(pathArray, x, y, startOffsetX, startOffsetY, endOffsetX, endOffsetY) {
2936
+ if (startOffsetX === void 0) {
2937
+ startOffsetX = 0;
2938
+ }
2939
+
2940
+ if (startOffsetY === void 0) {
2941
+ startOffsetY = 0;
2942
+ }
2943
+
2944
+ if (endOffsetX === void 0) {
2945
+ endOffsetX = 0;
2946
+ }
2947
+
2948
+ if (endOffsetY === void 0) {
2949
+ endOffsetY = 0;
2950
+ }
2951
+
2952
+ var newValue = pathArray.map(function (params, i) {
2953
+ var command = params[0]; // @ts-ignore
2954
+
2955
+ var isClosed = pathArray[pathArray.length - 1][0] === 'Z';
2956
+ var offsetX = i === pathArray.length - (isClosed ? 2 : 1) ? endOffsetX : 0;
2957
+ var offsetY = i === pathArray.length - (isClosed ? 2 : 1) ? endOffsetY : 0;
2937
2958
 
2938
2959
  switch (command) {
2939
2960
  case 'M':
2940
- return "M " + (params[1] - x) + "," + (params[2] - y);
2961
+ return "M " + (params[1] - x + startOffsetX) + "," + (params[2] - y + startOffsetY);
2941
2962
 
2942
2963
  case 'L':
2943
- return "L " + (params[1] - x) + "," + (params[2] - y);
2964
+ return "L " + (params[1] - x + offsetX) + "," + (params[2] - y + offsetY);
2944
2965
 
2945
2966
  case 'Q':
2946
- return "Q " + (params[1] - x) + " " + (params[2] - y) + "," + (params[3] - x) + " " + (params[4] - y);
2967
+ return "Q " + (params[1] - x) + " " + (params[2] - y) + "," + (params[3] - x + offsetX) + " " + (params[4] - y + offsetY);
2947
2968
 
2948
2969
  case 'C':
2949
- return "C " + (params[1] - x) + " " + (params[2] - y) + "," + (params[3] - x) + " " + (params[4] - y) + "," + (params[5] - x) + " " + (params[6] - y);
2970
+ return "C " + (params[1] - x) + " " + (params[2] - y) + "," + (params[3] - x) + " " + (params[4] - y) + "," + (params[5] - x + offsetX) + " " + (params[6] - y + offsetY);
2950
2971
 
2951
2972
  case 'A':
2952
- return "A " + params[1] + " " + params[2] + " " + params[3] + " " + params[4] + " " + params[5] + " " + (params[6] - x) + " " + (params[7] - y);
2973
+ return "A " + params[1] + " " + params[2] + " " + params[3] + " " + params[4] + " " + params[5] + " " + (params[6] - x + offsetX) + " " + (params[7] - y + offsetY);
2953
2974
 
2954
2975
  case 'Z':
2955
2976
  return 'Z';
@@ -7401,8 +7422,8 @@ var AABB = /*#__PURE__*/function () {
7401
7422
  };
7402
7423
 
7403
7424
  function AABB(center, halfExtents) {
7404
- this.center = void 0;
7405
- this.halfExtents = void 0;
7425
+ this.center = glMatrix.vec3.create();
7426
+ this.halfExtents = glMatrix.vec3.create();
7406
7427
  this.min = glMatrix.vec3.create();
7407
7428
  this.max = glMatrix.vec3.create();
7408
7429
  this.update(center, halfExtents);
@@ -7411,8 +7432,14 @@ var AABB = /*#__PURE__*/function () {
7411
7432
  var _proto = AABB.prototype;
7412
7433
 
7413
7434
  _proto.update = function update(center, halfExtents) {
7414
- this.center = glMatrix.vec3.copy(glMatrix.vec3.create(), center || glMatrix.vec3.create());
7415
- this.halfExtents = glMatrix.vec3.copy(glMatrix.vec3.create(), halfExtents || glMatrix.vec3.fromValues(0, 0, 0));
7435
+ if (center) {
7436
+ glMatrix.vec3.copy(this.center, center);
7437
+ }
7438
+
7439
+ if (halfExtents) {
7440
+ glMatrix.vec3.copy(this.halfExtents, halfExtents || glMatrix.vec3.fromValues(0, 0, 0));
7441
+ }
7442
+
7416
7443
  this.min = glMatrix.vec3.sub(this.min, this.center, this.halfExtents);
7417
7444
  this.max = glMatrix.vec3.add(this.max, this.center, this.halfExtents);
7418
7445
  };
@@ -10727,7 +10754,22 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
10727
10754
  });
10728
10755
  };
10729
10756
 
10730
- _proto.cloneNode = function cloneNode(deep) {
10757
+ _proto.cloneNode = function cloneNode(deep, customCloneFunc) {
10758
+ var clonedStyle = _extends({}, this.attributes);
10759
+
10760
+ for (var attributeName in clonedStyle) {
10761
+ var attribute = clonedStyle[attributeName]; // @see https://github.com/antvis/G/issues/1095
10762
+
10763
+ if (attribute instanceof DisplayObject) {
10764
+ clonedStyle[attributeName] = attribute.cloneNode(deep);
10765
+ } // TODO: clone other type
10766
+
10767
+
10768
+ if (customCloneFunc) {
10769
+ clonedStyle[attributeName] = customCloneFunc(attributeName, attribute);
10770
+ }
10771
+ }
10772
+
10731
10773
  var cloned = new this.constructor({
10732
10774
  // copy id & name
10733
10775
  // @see https://developer.mozilla.org/en-US/docs/Web/API/Node/cloneNode#notes
@@ -10735,15 +10777,18 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
10735
10777
  name: this.name,
10736
10778
  className: this.name,
10737
10779
  interactive: this.interactive,
10738
- style: _extends({}, this.attributes)
10780
+ style: clonedStyle
10739
10781
  }); // apply transform
10740
10782
 
10741
10783
  cloned.setLocalTransform(this.getLocalTransform());
10742
10784
 
10743
10785
  if (deep) {
10744
10786
  this.children.forEach(function (child) {
10745
- var clonedChild = child.cloneNode(deep);
10746
- cloned.appendChild(clonedChild);
10787
+ // skip marker
10788
+ if (!child.style.isMarker) {
10789
+ var clonedChild = child.cloneNode(deep);
10790
+ cloned.appendChild(clonedChild);
10791
+ }
10747
10792
  });
10748
10793
  }
10749
10794
 
@@ -10817,17 +10862,19 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
10817
10862
  renderable.dirty = true; // trigger later
10818
10863
  // this.sceneGraphService.pendingEvents.push([ElementEvent.ATTR_MODIFIED, { affectChildren }]);
10819
10864
 
10820
- this.mutationEvent.prevValue = oldValue;
10821
- this.mutationEvent.newValue = value;
10822
- this.mutationEvent.attrName = name;
10823
- this.mutationEvent.prevParsedValue = oldParsedValue;
10824
- this.mutationEvent.newParsedValue = this.parsedStyle[name];
10825
- this.dispatchEvent(this.mutationEvent);
10865
+ var newParsedValue = this.parsedStyle[name];
10826
10866
 
10827
- if (this.isCustomElement && this.isConnected) {
10828
- if (this.attributeChangedCallback) {
10829
- this.attributeChangedCallback(name, oldValue, value);
10830
- }
10867
+ if (this.isConnected) {
10868
+ this.mutationEvent.prevValue = oldValue;
10869
+ this.mutationEvent.newValue = value;
10870
+ this.mutationEvent.attrName = name;
10871
+ this.mutationEvent.prevParsedValue = oldParsedValue;
10872
+ this.mutationEvent.newParsedValue = newParsedValue;
10873
+ this.dispatchEvent(this.mutationEvent);
10874
+ }
10875
+
10876
+ if (this.attributeChangedCallback) {
10877
+ this.attributeChangedCallback(name, oldValue, value, oldParsedValue, newParsedValue);
10831
10878
  }
10832
10879
  } // #region transformable
10833
10880
 
@@ -11632,15 +11679,24 @@ var Image = /*#__PURE__*/function (_DisplayObject) {
11632
11679
  }(DisplayObject);
11633
11680
 
11634
11681
  var _excluded$5 = ["style"];
11682
+ /**
11683
+ * Create a line connecting two points.
11684
+ * @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/line
11685
+ *
11686
+ * Also support for using marker.
11687
+ */
11688
+
11635
11689
  var Line = /*#__PURE__*/function (_DisplayObject) {
11636
11690
  _inheritsLoose(Line, _DisplayObject);
11637
11691
 
11638
11692
  function Line(_temp) {
11693
+ var _this;
11694
+
11639
11695
  var _ref = _temp === void 0 ? {} : _temp,
11640
11696
  style = _ref.style,
11641
11697
  rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
11642
11698
 
11643
- return _DisplayObject.call(this, _extends({
11699
+ _this = _DisplayObject.call(this, _extends({
11644
11700
  type: exports.Shape.LINE,
11645
11701
  style: _extends({
11646
11702
  x1: 0,
@@ -11652,19 +11708,120 @@ var Line = /*#__PURE__*/function (_DisplayObject) {
11652
11708
  isBillboard: false
11653
11709
  }, style)
11654
11710
  }, rest)) || this;
11711
+ _this.markerStartAngle = 0;
11712
+ _this.markerEndAngle = 0;
11713
+ var _this$parsedStyle = _this.parsedStyle,
11714
+ markerStart = _this$parsedStyle.markerStart,
11715
+ markerEnd = _this$parsedStyle.markerEnd;
11716
+
11717
+ if (markerStart && markerStart instanceof DisplayObject) {
11718
+ _this.markerStartAngle = markerStart.getLocalEulerAngles();
11719
+
11720
+ _this.appendChild(markerStart);
11721
+ }
11722
+
11723
+ if (markerEnd && markerEnd instanceof DisplayObject) {
11724
+ _this.markerEndAngle = markerEnd.getLocalEulerAngles();
11725
+
11726
+ _this.appendChild(markerEnd);
11727
+ }
11728
+
11729
+ _this.transformMarker(true);
11730
+
11731
+ _this.transformMarker(false);
11732
+
11733
+ return _this;
11655
11734
  }
11656
11735
 
11657
11736
  var _proto = Line.prototype;
11658
11737
 
11738
+ _proto.attributeChangedCallback = function attributeChangedCallback(attrName, oldValue, newValue, prevParsedValue, newParsedValue) {
11739
+ if (attrName === 'x1' || attrName === 'y1' || attrName === 'x2' || attrName === 'y2' || attrName === 'markerStartOffset' || attrName === 'markerEndOffset') {
11740
+ this.transformMarker(true);
11741
+ this.transformMarker(false);
11742
+ } else if (attrName === 'markerStart') {
11743
+ if (prevParsedValue && prevParsedValue instanceof DisplayObject) {
11744
+ this.markerStartAngle = 0;
11745
+ prevParsedValue.remove();
11746
+ } // CSSKeyword 'unset'
11747
+
11748
+
11749
+ if (newParsedValue && newParsedValue instanceof DisplayObject) {
11750
+ this.markerStartAngle = newParsedValue.getLocalEulerAngles();
11751
+ this.appendChild(newParsedValue);
11752
+ this.transformMarker(true);
11753
+ }
11754
+ } else if (attrName === 'markerEnd') {
11755
+ if (prevParsedValue && prevParsedValue instanceof DisplayObject) {
11756
+ this.markerEndAngle = 0;
11757
+ prevParsedValue.remove();
11758
+ }
11759
+
11760
+ if (newParsedValue && newParsedValue instanceof DisplayObject) {
11761
+ this.markerEndAngle = newParsedValue.getLocalEulerAngles();
11762
+ this.appendChild(newParsedValue);
11763
+ this.transformMarker(false);
11764
+ }
11765
+ }
11766
+ };
11767
+
11768
+ _proto.transformMarker = function transformMarker(isStart) {
11769
+ var _this$parsedStyle2 = this.parsedStyle,
11770
+ markerStart = _this$parsedStyle2.markerStart,
11771
+ markerEnd = _this$parsedStyle2.markerEnd,
11772
+ markerStartOffset = _this$parsedStyle2.markerStartOffset,
11773
+ markerEndOffset = _this$parsedStyle2.markerEndOffset,
11774
+ x1 = _this$parsedStyle2.x1,
11775
+ x2 = _this$parsedStyle2.x2,
11776
+ y1 = _this$parsedStyle2.y1,
11777
+ y2 = _this$parsedStyle2.y2,
11778
+ defX = _this$parsedStyle2.defX,
11779
+ defY = _this$parsedStyle2.defY;
11780
+ var marker = isStart ? markerStart : markerEnd;
11781
+
11782
+ if (!marker || !(marker instanceof DisplayObject)) {
11783
+ return;
11784
+ }
11785
+
11786
+ var rad = 0;
11787
+ var x;
11788
+ var y;
11789
+ var ox;
11790
+ var oy;
11791
+ var offset;
11792
+ var originalAngle;
11793
+
11794
+ if (isStart) {
11795
+ ox = x1.value - defX;
11796
+ oy = y1.value - defY;
11797
+ x = x2.value - x1.value;
11798
+ y = y2.value - y1.value;
11799
+ offset = (markerStartOffset === null || markerStartOffset === void 0 ? void 0 : markerStartOffset.value) || 0;
11800
+ originalAngle = this.markerStartAngle;
11801
+ } else {
11802
+ ox = x2.value - defX;
11803
+ oy = y2.value - defY;
11804
+ x = x1.value - x2.value;
11805
+ y = y1.value - y2.value;
11806
+ offset = (markerEndOffset === null || markerEndOffset === void 0 ? void 0 : markerEndOffset.value) || 0;
11807
+ originalAngle = this.markerEndAngle;
11808
+ }
11809
+
11810
+ rad = Math.atan2(y, x); // account for markerOffset
11811
+
11812
+ marker.setLocalEulerAngles(rad * 180 / Math.PI + originalAngle);
11813
+ marker.setLocalPosition(ox + Math.cos(rad) * offset, oy + Math.sin(rad) * offset);
11814
+ };
11815
+
11659
11816
  _proto.getPoint = function getPoint(ratio) {
11660
11817
  // TODO: account for z1/z2 in 3D line
11661
- var _this$parsedStyle = this.parsedStyle,
11662
- x1 = _this$parsedStyle.x1,
11663
- y1 = _this$parsedStyle.y1,
11664
- x2 = _this$parsedStyle.x2,
11665
- y2 = _this$parsedStyle.y2,
11666
- defX = _this$parsedStyle.defX,
11667
- defY = _this$parsedStyle.defY;
11818
+ var _this$parsedStyle3 = this.parsedStyle,
11819
+ x1 = _this$parsedStyle3.x1,
11820
+ y1 = _this$parsedStyle3.y1,
11821
+ x2 = _this$parsedStyle3.x2,
11822
+ y2 = _this$parsedStyle3.y2,
11823
+ defX = _this$parsedStyle3.defX,
11824
+ defY = _this$parsedStyle3.defY;
11668
11825
 
11669
11826
  var _LineUtil$pointAt = gMath.Line.pointAt(x1.value, y1.value, x2.value, y2.value, ratio),
11670
11827
  x = _LineUtil$pointAt.x,
@@ -11677,11 +11834,11 @@ var Line = /*#__PURE__*/function (_DisplayObject) {
11677
11834
 
11678
11835
  _proto.getTotalLength = function getTotalLength() {
11679
11836
  // TODO: account for z1/z2 in 3D line
11680
- var _this$parsedStyle2 = this.parsedStyle,
11681
- x1 = _this$parsedStyle2.x1,
11682
- y1 = _this$parsedStyle2.y1,
11683
- x2 = _this$parsedStyle2.x2,
11684
- y2 = _this$parsedStyle2.y2;
11837
+ var _this$parsedStyle4 = this.parsedStyle,
11838
+ x1 = _this$parsedStyle4.x1,
11839
+ y1 = _this$parsedStyle4.y1,
11840
+ x2 = _this$parsedStyle4.x2,
11841
+ y2 = _this$parsedStyle4.y2;
11685
11842
  return gMath.Line.length(x1.value, y1.value, x2.value, y2.value);
11686
11843
  };
11687
11844
 
@@ -11692,22 +11849,169 @@ var _excluded$6 = ["style"];
11692
11849
  var Path = /*#__PURE__*/function (_DisplayObject) {
11693
11850
  _inheritsLoose(Path, _DisplayObject);
11694
11851
 
11852
+ /**
11853
+ * markers placed at the mid
11854
+ */
11695
11855
  function Path(_temp) {
11856
+ var _this;
11857
+
11696
11858
  var _ref = _temp === void 0 ? {} : _temp,
11697
11859
  style = _ref.style,
11698
11860
  rest = _objectWithoutPropertiesLoose(_ref, _excluded$6);
11699
11861
 
11700
- return _DisplayObject.call(this, _extends({
11862
+ _this = _DisplayObject.call(this, _extends({
11701
11863
  type: exports.Shape.PATH,
11702
11864
  style: _extends({
11703
11865
  path: '',
11704
11866
  miterLimit: ''
11705
11867
  }, style)
11706
11868
  }, rest)) || this;
11869
+ _this.markerStartAngle = 0;
11870
+ _this.markerEndAngle = 0;
11871
+ _this.markerMidList = [];
11872
+ var _this$parsedStyle = _this.parsedStyle,
11873
+ markerStart = _this$parsedStyle.markerStart,
11874
+ markerEnd = _this$parsedStyle.markerEnd,
11875
+ markerMid = _this$parsedStyle.markerMid;
11876
+
11877
+ if (markerStart && markerStart instanceof DisplayObject) {
11878
+ _this.markerStartAngle = markerStart.getLocalEulerAngles();
11879
+
11880
+ _this.appendChild(markerStart);
11881
+ }
11882
+
11883
+ if (markerMid && markerMid instanceof DisplayObject) {
11884
+ _this.placeMarkerMid(markerMid);
11885
+ }
11886
+
11887
+ if (markerEnd && markerEnd instanceof DisplayObject) {
11888
+ _this.markerEndAngle = markerEnd.getLocalEulerAngles();
11889
+
11890
+ _this.appendChild(markerEnd);
11891
+ }
11892
+
11893
+ _this.transformMarker(true);
11894
+
11895
+ _this.transformMarker(false);
11896
+
11897
+ return _this;
11707
11898
  }
11708
11899
 
11709
11900
  var _proto = Path.prototype;
11710
11901
 
11902
+ _proto.attributeChangedCallback = function attributeChangedCallback(attrName, oldValue, newValue, prevParsedValue, newParsedValue) {
11903
+ if (attrName === 'path') {
11904
+ // recalc markers
11905
+ this.transformMarker(true);
11906
+ this.transformMarker(false);
11907
+ this.placeMarkerMid(this.parsedStyle.markerMid);
11908
+ } else if (attrName === 'markerStartOffset' || attrName === 'markerEndOffset') {
11909
+ this.transformMarker(true);
11910
+ this.transformMarker(false);
11911
+ } else if (attrName === 'markerStart') {
11912
+ if (prevParsedValue && prevParsedValue instanceof DisplayObject) {
11913
+ this.markerStartAngle = 0;
11914
+ prevParsedValue.remove();
11915
+ } // CSSKeyword 'unset'
11916
+
11917
+
11918
+ if (newParsedValue && newParsedValue instanceof DisplayObject) {
11919
+ this.markerStartAngle = newParsedValue.getLocalEulerAngles();
11920
+ this.appendChild(newParsedValue);
11921
+ this.transformMarker(true);
11922
+ }
11923
+ } else if (attrName === 'markerEnd') {
11924
+ if (prevParsedValue && prevParsedValue instanceof DisplayObject) {
11925
+ this.markerEndAngle = 0;
11926
+ prevParsedValue.remove();
11927
+ }
11928
+
11929
+ if (newParsedValue && newParsedValue instanceof DisplayObject) {
11930
+ this.markerEndAngle = newParsedValue.getLocalEulerAngles();
11931
+ this.appendChild(newParsedValue);
11932
+ this.transformMarker(false);
11933
+ }
11934
+ } else if (attrName === 'markerMid') {
11935
+ this.placeMarkerMid(newParsedValue);
11936
+ }
11937
+ };
11938
+
11939
+ _proto.transformMarker = function transformMarker(isStart) {
11940
+ var _this$parsedStyle2 = this.parsedStyle,
11941
+ markerStart = _this$parsedStyle2.markerStart,
11942
+ markerEnd = _this$parsedStyle2.markerEnd,
11943
+ markerStartOffset = _this$parsedStyle2.markerStartOffset,
11944
+ markerEndOffset = _this$parsedStyle2.markerEndOffset,
11945
+ defX = _this$parsedStyle2.defX,
11946
+ defY = _this$parsedStyle2.defY;
11947
+ var marker = isStart ? markerStart : markerEnd;
11948
+
11949
+ if (!marker || !(marker instanceof DisplayObject)) {
11950
+ return;
11951
+ }
11952
+
11953
+ var rad = 0;
11954
+ var x;
11955
+ var y;
11956
+ var ox;
11957
+ var oy;
11958
+ var offset;
11959
+ var originalAngle;
11960
+
11961
+ if (isStart) {
11962
+ var _this$getStartTangent = this.getStartTangent(),
11963
+ p1 = _this$getStartTangent[0],
11964
+ p2 = _this$getStartTangent[1];
11965
+
11966
+ ox = p2[0] - defX;
11967
+ oy = p2[1] - defY;
11968
+ x = p1[0] - p2[0];
11969
+ y = p1[1] - p2[1];
11970
+ offset = (markerStartOffset === null || markerStartOffset === void 0 ? void 0 : markerStartOffset.value) || 0;
11971
+ originalAngle = this.markerStartAngle;
11972
+ } else {
11973
+ var _this$getEndTangent = this.getEndTangent(),
11974
+ _p = _this$getEndTangent[0],
11975
+ _p2 = _this$getEndTangent[1];
11976
+
11977
+ ox = _p2[0] - defX;
11978
+ oy = _p2[1] - defY;
11979
+ x = _p[0] - _p2[0];
11980
+ y = _p[1] - _p2[1];
11981
+ offset = (markerEndOffset === null || markerEndOffset === void 0 ? void 0 : markerEndOffset.value) || 0;
11982
+ originalAngle = this.markerEndAngle;
11983
+ }
11984
+
11985
+ rad = Math.atan2(y, x); // account for markerOffset
11986
+
11987
+ marker.setLocalEulerAngles(rad * 180 / Math.PI + originalAngle);
11988
+ marker.setLocalPosition(ox + Math.cos(rad) * offset, oy + Math.sin(rad) * offset);
11989
+ };
11990
+
11991
+ _proto.placeMarkerMid = function placeMarkerMid(marker) {
11992
+ var _this$parsedStyle3 = this.parsedStyle,
11993
+ segments = _this$parsedStyle3.path.segments,
11994
+ defX = _this$parsedStyle3.defX,
11995
+ defY = _this$parsedStyle3.defY; // clear all existed markers
11996
+
11997
+ this.markerMidList.forEach(function (marker) {
11998
+ marker.remove();
11999
+ });
12000
+
12001
+ if (marker && marker instanceof DisplayObject) {
12002
+ // FIXME: should use original path instead of parsed curve
12003
+ for (var i = 1; i < segments.length - 1; i++) {
12004
+ var _segments$i$currentPo = segments[i].currentPoint,
12005
+ ox = _segments$i$currentPo[0],
12006
+ oy = _segments$i$currentPo[1];
12007
+ var cloned = i === 1 ? marker : marker.cloneNode(true);
12008
+ this.markerMidList.push(cloned);
12009
+ this.appendChild(cloned);
12010
+ cloned.setLocalPosition(ox - defX, oy - defY); // TODO: orient of marker
12011
+ }
12012
+ }
12013
+ };
12014
+
11711
12015
  _proto.getTotalLength = function getTotalLength() {
11712
12016
  return this.parsedStyle.path.totalLength;
11713
12017
  }
@@ -11717,12 +12021,12 @@ var Path = /*#__PURE__*/function (_DisplayObject) {
11717
12021
  ;
11718
12022
 
11719
12023
  _proto.getPoint = function getPoint(ratio) {
11720
- var _this$parsedStyle = this.parsedStyle,
11721
- defX = _this$parsedStyle.defX,
11722
- defY = _this$parsedStyle.defY,
11723
- _this$parsedStyle$pat = _this$parsedStyle.path,
11724
- totalLength = _this$parsedStyle$pat.totalLength,
11725
- absolutePath = _this$parsedStyle$pat.absolutePath;
12024
+ var _this$parsedStyle4 = this.parsedStyle,
12025
+ defX = _this$parsedStyle4.defX,
12026
+ defY = _this$parsedStyle4.defY,
12027
+ _this$parsedStyle4$pa = _this$parsedStyle4.path,
12028
+ totalLength = _this$parsedStyle4$pa.totalLength,
12029
+ absolutePath = _this$parsedStyle4$pa.absolutePath;
11726
12030
 
11727
12031
  var _getPointAtLength = util.getPointAtLength(absolutePath, ratio * totalLength),
11728
12032
  x = _getPointAtLength.x,
@@ -11793,37 +12097,191 @@ var _excluded$7 = ["style"];
11793
12097
  var Polygon = /*#__PURE__*/function (_DisplayObject) {
11794
12098
  _inheritsLoose(Polygon, _DisplayObject);
11795
12099
 
12100
+ /**
12101
+ * markers placed at the mid
12102
+ */
11796
12103
  function Polygon(_temp) {
12104
+ var _this;
12105
+
11797
12106
  var _ref = _temp === void 0 ? {} : _temp,
11798
12107
  style = _ref.style,
11799
12108
  rest = _objectWithoutPropertiesLoose(_ref, _excluded$7);
11800
12109
 
11801
- return _DisplayObject.call(this, _extends({
12110
+ _this = _DisplayObject.call(this, _extends({
11802
12111
  type: exports.Shape.POLYGON,
11803
12112
  style: _extends({
11804
12113
  points: '',
11805
- miterLimit: ''
12114
+ miterLimit: '',
12115
+ isClosed: true
11806
12116
  }, style)
11807
12117
  }, rest)) || this;
12118
+ _this.markerStartAngle = 0;
12119
+ _this.markerEndAngle = 0;
12120
+ _this.markerMidList = [];
12121
+ var _this$parsedStyle = _this.parsedStyle,
12122
+ markerStart = _this$parsedStyle.markerStart,
12123
+ markerEnd = _this$parsedStyle.markerEnd,
12124
+ markerMid = _this$parsedStyle.markerMid;
12125
+
12126
+ if (markerStart && markerStart instanceof DisplayObject) {
12127
+ _this.markerStartAngle = markerStart.getLocalEulerAngles();
12128
+
12129
+ _this.appendChild(markerStart);
12130
+ }
12131
+
12132
+ if (markerMid && markerMid instanceof DisplayObject) {
12133
+ _this.placeMarkerMid(markerMid);
12134
+ }
12135
+
12136
+ if (markerEnd && markerEnd instanceof DisplayObject) {
12137
+ _this.markerEndAngle = markerEnd.getLocalEulerAngles();
12138
+
12139
+ _this.appendChild(markerEnd);
12140
+ }
12141
+
12142
+ _this.transformMarker(true);
12143
+
12144
+ _this.transformMarker(false);
12145
+
12146
+ return _this;
11808
12147
  }
11809
12148
 
12149
+ var _proto = Polygon.prototype;
12150
+
12151
+ _proto.attributeChangedCallback = function attributeChangedCallback(attrName, oldValue, newValue, prevParsedValue, newParsedValue) {
12152
+ if (attrName === 'points') {
12153
+ // recalc markers
12154
+ this.transformMarker(true);
12155
+ this.transformMarker(false);
12156
+ this.placeMarkerMid(this.parsedStyle.markerMid);
12157
+ } else if (attrName === 'markerStartOffset' || attrName === 'markerEndOffset') {
12158
+ this.transformMarker(true);
12159
+ this.transformMarker(false);
12160
+ } else if (attrName === 'markerStart') {
12161
+ if (prevParsedValue && prevParsedValue instanceof DisplayObject) {
12162
+ this.markerStartAngle = 0;
12163
+ prevParsedValue.remove();
12164
+ } // CSSKeyword 'unset'
12165
+
12166
+
12167
+ if (newParsedValue && newParsedValue instanceof DisplayObject) {
12168
+ this.markerStartAngle = newParsedValue.getLocalEulerAngles();
12169
+ this.appendChild(newParsedValue);
12170
+ this.transformMarker(true);
12171
+ }
12172
+ } else if (attrName === 'markerEnd') {
12173
+ if (prevParsedValue && prevParsedValue instanceof DisplayObject) {
12174
+ this.markerEndAngle = 0;
12175
+ prevParsedValue.remove();
12176
+ }
12177
+
12178
+ if (newParsedValue && newParsedValue instanceof DisplayObject) {
12179
+ this.markerEndAngle = newParsedValue.getLocalEulerAngles();
12180
+ this.appendChild(newParsedValue);
12181
+ this.transformMarker(false);
12182
+ }
12183
+ } else if (attrName === 'markerMid') {
12184
+ this.placeMarkerMid(newParsedValue);
12185
+ }
12186
+ };
12187
+
12188
+ _proto.transformMarker = function transformMarker(isStart) {
12189
+ var _this$parsedStyle2 = this.parsedStyle,
12190
+ markerStart = _this$parsedStyle2.markerStart,
12191
+ markerEnd = _this$parsedStyle2.markerEnd,
12192
+ markerStartOffset = _this$parsedStyle2.markerStartOffset,
12193
+ markerEndOffset = _this$parsedStyle2.markerEndOffset,
12194
+ points = _this$parsedStyle2.points.points,
12195
+ defX = _this$parsedStyle2.defX,
12196
+ defY = _this$parsedStyle2.defY;
12197
+ var marker = isStart ? markerStart : markerEnd;
12198
+
12199
+ if (!marker || !(marker instanceof DisplayObject)) {
12200
+ return;
12201
+ }
12202
+
12203
+ var rad = 0;
12204
+ var x;
12205
+ var y;
12206
+ var ox;
12207
+ var oy;
12208
+ var offset;
12209
+ var originalAngle;
12210
+ ox = points[0][0] - defX;
12211
+ oy = points[0][1] - defY;
12212
+
12213
+ if (isStart) {
12214
+ x = points[1][0] - points[0][0];
12215
+ y = points[1][1] - points[0][1];
12216
+ offset = (markerStartOffset === null || markerStartOffset === void 0 ? void 0 : markerStartOffset.value) || 0;
12217
+ originalAngle = this.markerStartAngle;
12218
+ } else {
12219
+ var length = points.length;
12220
+
12221
+ if (!this.style.isClosed) {
12222
+ ox = points[length - 1][0] - defX;
12223
+ oy = points[length - 1][1] - defY;
12224
+ x = points[length - 2][0] - points[length - 1][0];
12225
+ y = points[length - 2][1] - points[length - 1][1];
12226
+ } else {
12227
+ x = points[length - 1][0] - points[0][0];
12228
+ y = points[length - 1][1] - points[0][1];
12229
+ }
12230
+
12231
+ offset = (markerEndOffset === null || markerEndOffset === void 0 ? void 0 : markerEndOffset.value) || 0;
12232
+ originalAngle = this.markerEndAngle;
12233
+ }
12234
+
12235
+ rad = Math.atan2(y, x); // account for markerOffset
12236
+
12237
+ marker.setLocalEulerAngles(rad * 180 / Math.PI + originalAngle);
12238
+ marker.setLocalPosition(ox + Math.cos(rad) * offset, oy + Math.sin(rad) * offset);
12239
+ };
12240
+
12241
+ _proto.placeMarkerMid = function placeMarkerMid(marker) {
12242
+ var _this$parsedStyle3 = this.parsedStyle,
12243
+ points = _this$parsedStyle3.points.points,
12244
+ defX = _this$parsedStyle3.defX,
12245
+ defY = _this$parsedStyle3.defY; // clear all existed markers
12246
+
12247
+ this.markerMidList.forEach(function (marker) {
12248
+ marker.remove();
12249
+ });
12250
+
12251
+ if (marker && marker instanceof DisplayObject) {
12252
+ for (var i = 1; i < (this.style.isClosed ? points.length : points.length - 1); i++) {
12253
+ var ox = points[i][0] - defX;
12254
+ var oy = points[i][1] - defY;
12255
+ var cloned = i === 1 ? marker : marker.cloneNode(true);
12256
+ this.markerMidList.push(cloned);
12257
+ this.appendChild(cloned);
12258
+ cloned.setLocalPosition(ox, oy); // TODO: orient of marker
12259
+ }
12260
+ }
12261
+ };
12262
+
11810
12263
  return Polygon;
11811
12264
  }(DisplayObject);
11812
12265
 
11813
12266
  var _excluded$8 = ["style"];
11814
- var Polyline = /*#__PURE__*/function (_DisplayObject) {
11815
- _inheritsLoose(Polyline, _DisplayObject);
12267
+ /**
12268
+ * Polyline inherits the marker-related capabilities of Polygon.
12269
+ */
12270
+
12271
+ var Polyline = /*#__PURE__*/function (_Polygon) {
12272
+ _inheritsLoose(Polyline, _Polygon);
11816
12273
 
11817
12274
  function Polyline(_temp) {
11818
12275
  var _ref = _temp === void 0 ? {} : _temp,
11819
12276
  style = _ref.style,
11820
12277
  rest = _objectWithoutPropertiesLoose(_ref, _excluded$8);
11821
12278
 
11822
- return _DisplayObject.call(this, _extends({
12279
+ return _Polygon.call(this, _extends({
11823
12280
  type: exports.Shape.POLYLINE,
11824
12281
  style: _extends({
11825
12282
  points: '',
11826
- miterLimit: ''
12283
+ miterLimit: '',
12284
+ isClosed: false
11827
12285
  }, style)
11828
12286
  }, rest)) || this;
11829
12287
  }
@@ -11877,7 +12335,7 @@ var Polyline = /*#__PURE__*/function (_DisplayObject) {
11877
12335
  };
11878
12336
 
11879
12337
  return Polyline;
11880
- }(DisplayObject);
12338
+ }(Polygon);
11881
12339
 
11882
12340
  var _excluded$9 = ["style"];
11883
12341
  var Rect = /*#__PURE__*/function (_DisplayObject) {
@@ -13237,16 +13695,6 @@ var FederatedMouseEvent = /*#__PURE__*/function (_FederatedEvent) {
13237
13695
  get: function get() {
13238
13696
  return this.client.y;
13239
13697
  }
13240
- }, {
13241
- key: "x",
13242
- get: function get() {
13243
- return this.clientX;
13244
- }
13245
- }, {
13246
- key: "y",
13247
- get: function get() {
13248
- return this.clientY;
13249
- }
13250
13698
  /**
13251
13699
  * The movement in this pointer relative to the last `mousemove` event.
13252
13700
  */
@@ -14565,25 +15013,46 @@ exports.DefaultSceneGraphService = /*#__PURE__*/function () {
14565
15013
 
14566
15014
  this.setPosition = function () {
14567
15015
  var parentInvertMatrix = glMatrix.mat4.create();
15016
+ var tmpPosition = glMatrix.vec3.create();
14568
15017
  return function (element, position) {
14569
15018
  var transform = element.transformable;
14570
- position = glMatrix.vec3.fromValues(position[0], position[1], position[2] || 0);
15019
+ tmpPosition[0] = position[0];
15020
+ tmpPosition[1] = position[1];
15021
+ tmpPosition[2] = position[2] || 0;
14571
15022
 
14572
- if (glMatrix.vec3.equals(_this.getPosition(element), position)) {
15023
+ if (glMatrix.vec3.equals(_this.getPosition(element), tmpPosition)) {
14573
15024
  return;
14574
15025
  }
14575
15026
 
14576
- transform.position = position;
15027
+ glMatrix.vec3.copy(transform.position, tmpPosition);
14577
15028
 
14578
15029
  if (element.parentNode === null || !element.parentNode.transformable) {
14579
- glMatrix.vec3.copy(transform.localPosition, position);
15030
+ glMatrix.vec3.copy(transform.localPosition, tmpPosition);
14580
15031
  } else {
14581
15032
  var parentTransform = element.parentNode.transformable;
14582
15033
  glMatrix.mat4.copy(parentInvertMatrix, parentTransform.worldTransform);
14583
15034
  glMatrix.mat4.invert(parentInvertMatrix, parentInvertMatrix);
14584
- glMatrix.vec3.transformMat4(transform.localPosition, position, parentInvertMatrix);
15035
+ glMatrix.vec3.transformMat4(transform.localPosition, tmpPosition, parentInvertMatrix);
15036
+ }
15037
+
15038
+ _this.dirtifyLocal(element, transform);
15039
+ };
15040
+ }();
15041
+
15042
+ this.setLocalPosition = function () {
15043
+ var tmpPosition = glMatrix.vec3.create();
15044
+ return function (element, position) {
15045
+ var transform = element.transformable;
15046
+ tmpPosition[0] = position[0];
15047
+ tmpPosition[1] = position[1];
15048
+ tmpPosition[2] = position[2] || 0;
15049
+
15050
+ if (glMatrix.vec3.equals(transform.localPosition, tmpPosition)) {
15051
+ return;
14585
15052
  }
14586
15053
 
15054
+ glMatrix.vec3.copy(transform.localPosition, tmpPosition);
15055
+
14587
15056
  _this.dirtifyLocal(element, transform);
14588
15057
  };
14589
15058
  }();
@@ -14789,25 +15258,9 @@ exports.DefaultSceneGraphService = /*#__PURE__*/function () {
14789
15258
  */
14790
15259
  ;
14791
15260
 
14792
- /**
14793
- * move to position in local space
14794
- */
14795
- _proto.setLocalPosition = function setLocalPosition(element, position) {
14796
- var transform = element.transformable;
14797
- position = glMatrix.vec3.fromValues(position[0], position[1], position[2] || 0);
14798
-
14799
- if (glMatrix.vec3.equals(transform.localPosition, position)) {
14800
- return;
14801
- }
14802
-
14803
- glMatrix.vec3.copy(transform.localPosition, position);
14804
- this.dirtifyLocal(element, transform);
14805
- }
14806
15261
  /**
14807
15262
  * scale in local space
14808
15263
  */
14809
- ;
14810
-
14811
15264
  _proto.scaleLocal = function scaleLocal(element, scaling) {
14812
15265
  var transform = element.transformable;
14813
15266
  glMatrix.vec3.multiply(transform.localScale, transform.localScale, glMatrix.vec3.fromValues(scaling[0], scaling[1], scaling[2] || 1));
@@ -19020,6 +19473,39 @@ exports.CSSPropertyLocalPosition = tslib.__decorate([manaSyringe.singleton({
19020
19473
  }
19021
19474
  })], exports.CSSPropertyLocalPosition);
19022
19475
 
19476
+ exports.CSSPropertyMarker = /*#__PURE__*/function () {
19477
+ function CSSPropertyMarker() {}
19478
+
19479
+ var _proto = CSSPropertyMarker.prototype;
19480
+
19481
+ _proto.calculator = function calculator(name, oldMarker, newMarker, object) {
19482
+ var _newMarker;
19483
+
19484
+ // unset
19485
+ if (newMarker instanceof CSSKeywordValue) {
19486
+ newMarker = null;
19487
+ }
19488
+
19489
+ var cloned = (_newMarker = newMarker) === null || _newMarker === void 0 ? void 0 : _newMarker.cloneNode(true);
19490
+
19491
+ if (cloned) {
19492
+ // FIXME: SVG should not inherit parent's style, add a flag here
19493
+ cloned.style.isMarker = true;
19494
+ }
19495
+
19496
+ return cloned;
19497
+ };
19498
+
19499
+ return CSSPropertyMarker;
19500
+ }();
19501
+
19502
+ exports.CSSPropertyMarker = tslib.__decorate([manaSyringe.singleton({
19503
+ token: {
19504
+ token: CSSProperty,
19505
+ named: exports.PropertySyntax.MARKER
19506
+ }
19507
+ })], exports.CSSPropertyMarker);
19508
+
19023
19509
  exports.CSSPropertyNumber = function CSSPropertyNumber() {
19024
19510
  this.mixer = mergeNumbers;
19025
19511
  this.parser = parseNumber;
@@ -19957,6 +20443,27 @@ var BUILT_IN_PROPERTIES = [{
19957
20443
  }, {
19958
20444
  name: 'whiteSpace',
19959
20445
  layoutDependent: true
20446
+ }, {
20447
+ name: 'markerStart',
20448
+ syntax: exports.PropertySyntax.MARKER
20449
+ }, {
20450
+ name: 'markerEnd',
20451
+ syntax: exports.PropertySyntax.MARKER
20452
+ }, {
20453
+ name: 'markerMid',
20454
+ syntax: exports.PropertySyntax.MARKER
20455
+ }, {
20456
+ name: 'markerStartOffset',
20457
+ syntax: exports.PropertySyntax.LENGTH,
20458
+ layoutDependent: true,
20459
+ interpolable: true,
20460
+ defaultValue: '0'
20461
+ }, {
20462
+ name: 'markerEndOffset',
20463
+ syntax: exports.PropertySyntax.LENGTH,
20464
+ layoutDependent: true,
20465
+ interpolable: true,
20466
+ defaultValue: '0'
19960
20467
  }];
19961
20468
 
19962
20469
  exports.DefaultStyleValueRegistry = /*#__PURE__*/function () {
@@ -20509,6 +21016,7 @@ var containerModule = manaSyringe.Module(function (register) {
20509
21016
  register(exports.CSSPropertyTransform);
20510
21017
  register(exports.CSSPropertyTransformOrigin);
20511
21018
  register(exports.CSSPropertyZIndex);
21019
+ register(exports.CSSPropertyMarker);
20512
21020
  register({
20513
21021
  token: CSSPropertySyntaxFactory,
20514
21022
  useFactory: function useFactory(context) {
@@ -21346,6 +21854,7 @@ var PrepareRendererPlugin = PrepareRendererPlugin_1 = (_class$4 = /*#__PURE__*/f
21346
21854
  // @see https://github.com/mourner/rbush#bulk-inserting-data
21347
21855
 
21348
21856
  this.rBush.load(bulk);
21857
+ bulk.length = 0;
21349
21858
  this.toSync.clear();
21350
21859
  };
21351
21860