@antv/g-lite 1.0.12 → 1.0.14

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 (36) hide show
  1. package/dist/Canvas.d.ts.map +1 -1
  2. package/dist/css/StyleValueRegistry.d.ts +1 -1
  3. package/dist/css/StyleValueRegistry.d.ts.map +1 -1
  4. package/dist/css/parser/path.d.ts.map +1 -1
  5. package/dist/display-objects/DisplayObject.d.ts +1 -0
  6. package/dist/display-objects/DisplayObject.d.ts.map +1 -1
  7. package/dist/display-objects/Line.d.ts +2 -2
  8. package/dist/display-objects/Line.d.ts.map +1 -1
  9. package/dist/display-objects/Path.d.ts +28 -9
  10. package/dist/display-objects/Path.d.ts.map +1 -1
  11. package/dist/display-objects/Polyline.d.ts +2 -2
  12. package/dist/display-objects/Polyline.d.ts.map +1 -1
  13. package/dist/display-objects/Text.d.ts +2 -2
  14. package/dist/display-objects/Text.d.ts.map +1 -1
  15. package/dist/dom/EventTarget.d.ts +1 -1
  16. package/dist/dom/EventTarget.d.ts.map +1 -1
  17. package/dist/dom/interfaces.d.ts +1 -1
  18. package/dist/dom/interfaces.d.ts.map +1 -1
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.esm.js +493 -141
  22. package/dist/index.js +490 -137
  23. package/dist/index.umd.js +1255 -183
  24. package/dist/index.umd.min.js +2 -2
  25. package/dist/plugins/PrepareRendererPlugin.d.ts +0 -1
  26. package/dist/plugins/PrepareRendererPlugin.d.ts.map +1 -1
  27. package/dist/services/EventService.d.ts +1 -1
  28. package/dist/services/EventService.d.ts.map +1 -1
  29. package/dist/services/RenderingService.d.ts.map +1 -1
  30. package/dist/services/SceneGraphService.d.ts.map +1 -1
  31. package/dist/services/TextService.d.ts.map +1 -1
  32. package/dist/utils/assert.d.ts +4 -1
  33. package/dist/utils/assert.d.ts.map +1 -1
  34. package/dist/utils/path.d.ts +11 -4
  35. package/dist/utils/path.d.ts.map +1 -1
  36. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -563,10 +563,7 @@ var FORMAT_ATTR_MAP = {
563
563
  alias: 'lineWidth'
564
564
  },
565
565
  textAnchor: {
566
- alias: 'textAlign',
567
- values: {
568
- middle: 'center'
569
- }
566
+ alias: 'textAlign'
570
567
  },
571
568
  src: {
572
569
  alias: 'img'
@@ -576,18 +573,8 @@ var formatAttributeName = util.memoize(function (name) {
576
573
  var attributeName = camelCase(name);
577
574
  var map = FORMAT_ATTR_MAP[attributeName];
578
575
  attributeName = (map === null || map === void 0 ? void 0 : map.alias) || attributeName;
579
- return [attributeName, map];
576
+ return attributeName;
580
577
  });
581
- function formatAttribute(name, value) {
582
- var _map$values;
583
-
584
- var _formatAttributeName = formatAttributeName(name),
585
- attributeName = _formatAttributeName[0],
586
- map = _formatAttributeName[1];
587
-
588
- var attributeValue = util.isString(value) && (map === null || map === void 0 ? void 0 : (_map$values = map.values) === null || _map$values === void 0 ? void 0 : _map$values[value]) || value;
589
- return [attributeName, attributeValue];
590
- }
591
578
 
592
579
  var canvasMap = {};
593
580
  var defaultCanvasIdCounter = 0;
@@ -4336,14 +4323,13 @@ var internalParsePath = function internalParsePath(path) {
4336
4323
  zCommandIndexes = _path2Curve[1]; // for later use
4337
4324
 
4338
4325
 
4339
- var segments = path2Segments(curve); // Only calculate bbox here since we don't need length now.
4326
+ var segments = path2Segments(absolutePath); // Only calculate bbox here since we don't need length now.
4340
4327
 
4341
- var _getPathBBox = util.getPathBBox(absolutePath),
4328
+ var _getPathBBox = getPathBBox(segments, 0),
4342
4329
  x = _getPathBBox.x,
4343
4330
  y = _getPathBBox.y,
4344
4331
  width = _getPathBBox.width,
4345
- height = _getPathBBox.height; // const { x, y, width, height, length } = getPathBBoxTotalLength(absolutePath);
4346
-
4332
+ height = _getPathBBox.height;
4347
4333
 
4348
4334
  return {
4349
4335
  absolutePath: absolutePath,
@@ -4353,15 +4339,8 @@ var internalParsePath = function internalParsePath(path) {
4353
4339
  polylines: polylines,
4354
4340
  curve: curve,
4355
4341
  // Delay the calculation of length.
4356
- // totalLength: length,
4357
4342
  totalLength: 0,
4358
4343
  zCommandIndexes: zCommandIndexes,
4359
- // rect: new Rectangle(
4360
- // Number.isFinite(x) ? x : 0,
4361
- // Number.isFinite(y) ? y : 0,
4362
- // Number.isFinite(width) ? width : 0,
4363
- // Number.isFinite(height) ? height : 0,
4364
- // ),
4365
4344
  rect: {
4366
4345
  x: Number.isFinite(x) ? x : 0,
4367
4346
  y: Number.isFinite(y) ? y : 0,
@@ -5443,16 +5422,23 @@ var CSSPropertyOffsetDistance = /*#__PURE__*/function () {
5443
5422
  };
5444
5423
 
5445
5424
  _proto.postProcessor = function postProcessor(object) {
5446
- if (!object.attributes.offsetPath) {
5425
+ var _object$parsedStyle = object.parsedStyle,
5426
+ offsetPath = _object$parsedStyle.offsetPath,
5427
+ offsetDistance = _object$parsedStyle.offsetDistance;
5428
+
5429
+ if (!offsetPath) {
5447
5430
  return;
5448
5431
  }
5449
5432
 
5450
- var offsetPathNodeName = object.attributes.offsetPath.nodeName;
5433
+ var nodeName = offsetPath.nodeName;
5451
5434
 
5452
- if (offsetPathNodeName === exports.Shape.LINE || offsetPathNodeName === exports.Shape.PATH || offsetPathNodeName === exports.Shape.POLYLINE) {
5453
- var point = object.attributes.offsetPath.getPoint(object.parsedStyle.offsetDistance);
5435
+ if (nodeName === exports.Shape.LINE || nodeName === exports.Shape.PATH || nodeName === exports.Shape.POLYLINE) {
5436
+ // set position in world space
5437
+ var point = offsetPath.getPoint(offsetDistance);
5454
5438
 
5455
5439
  if (point) {
5440
+ object.parsedStyle.defX = point.x;
5441
+ object.parsedStyle.defY = point.y;
5456
5442
  object.setLocalPosition(point.x, point.y);
5457
5443
  }
5458
5444
  }
@@ -6647,12 +6633,148 @@ function isSamePoint(point1, point2) {
6647
6633
  return point1[0] === point2[0] && point1[1] === point2[1];
6648
6634
  }
6649
6635
 
6636
+ function getPathBBox(segments, lineWidth) {
6637
+ var xArr = [];
6638
+ var yArr = [];
6639
+ var segmentsWithAngle = [];
6640
+
6641
+ for (var i = 0; i < segments.length; i++) {
6642
+ var segment = segments[i];
6643
+ var currentPoint = segment.currentPoint,
6644
+ params = segment.params,
6645
+ prePoint = segment.prePoint;
6646
+ var box = void 0;
6647
+
6648
+ switch (segment.command) {
6649
+ case 'Q':
6650
+ box = gMath.Quad.box(prePoint[0], prePoint[1], params[1], params[2], params[3], params[4]);
6651
+ break;
6652
+
6653
+ case 'C':
6654
+ box = gMath.Cubic.box(prePoint[0], prePoint[1], params[1], params[2], params[3], params[4], params[5], params[6]);
6655
+ break;
6656
+
6657
+ case 'A':
6658
+ var arcParams = segment.arcParams;
6659
+ box = gMath.Arc.box(arcParams.cx, arcParams.cy, arcParams.rx, arcParams.ry, arcParams.xRotation, arcParams.startAngle, arcParams.endAngle);
6660
+ break;
6661
+
6662
+ default:
6663
+ xArr.push(currentPoint[0]);
6664
+ yArr.push(currentPoint[1]);
6665
+ break;
6666
+ }
6667
+
6668
+ if (box) {
6669
+ segment.box = box;
6670
+ xArr.push(box.x, box.x + box.width);
6671
+ yArr.push(box.y, box.y + box.height);
6672
+ }
6673
+
6674
+ if (lineWidth && (segment.command === 'L' || segment.command === 'M') && segment.prePoint && segment.nextPoint) {
6675
+ segmentsWithAngle.push(segment);
6676
+ }
6677
+ } // bbox calculation should ignore NaN for path attribute
6678
+ // ref: https://github.com/antvis/g/issues/210
6679
+ // ref: https://github.com/antvis/G2/issues/3109
6680
+
6681
+
6682
+ xArr = xArr.filter(function (item) {
6683
+ return !Number.isNaN(item) && item !== Infinity && item !== -Infinity;
6684
+ });
6685
+ yArr = yArr.filter(function (item) {
6686
+ return !Number.isNaN(item) && item !== Infinity && item !== -Infinity;
6687
+ });
6688
+ var minX = util.min(xArr);
6689
+ var minY = util.min(yArr);
6690
+ var maxX = util.max(xArr);
6691
+ var maxY = util.max(yArr);
6692
+
6693
+ if (segmentsWithAngle.length === 0) {
6694
+ return {
6695
+ x: minX,
6696
+ y: minY,
6697
+ width: maxX - minX,
6698
+ height: maxY - minY
6699
+ };
6700
+ }
6701
+
6702
+ for (var _i = 0; _i < segmentsWithAngle.length; _i++) {
6703
+ var _segment = segmentsWithAngle[_i];
6704
+ var _currentPoint = _segment.currentPoint;
6705
+ var extra = void 0;
6706
+
6707
+ if (_currentPoint[0] === minX) {
6708
+ extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
6709
+ minX = minX - extra.xExtra;
6710
+ } else if (_currentPoint[0] === maxX) {
6711
+ extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
6712
+ maxX = maxX + extra.xExtra;
6713
+ }
6714
+
6715
+ if (_currentPoint[1] === minY) {
6716
+ extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
6717
+ minY = minY - extra.yExtra;
6718
+ } else if (_currentPoint[1] === maxY) {
6719
+ extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
6720
+ maxY = maxY + extra.yExtra;
6721
+ }
6722
+ }
6723
+
6724
+ return {
6725
+ x: minX,
6726
+ y: minY,
6727
+ width: maxX - minX,
6728
+ height: maxY - minY
6729
+ };
6730
+ }
6731
+
6732
+ function getExtraFromSegmentWithAngle(segment, lineWidth) {
6733
+ var prePoint = segment.prePoint,
6734
+ currentPoint = segment.currentPoint,
6735
+ nextPoint = segment.nextPoint;
6736
+ var currentAndPre = Math.pow(currentPoint[0] - prePoint[0], 2) + Math.pow(currentPoint[1] - prePoint[1], 2);
6737
+ var currentAndNext = Math.pow(currentPoint[0] - nextPoint[0], 2) + Math.pow(currentPoint[1] - nextPoint[1], 2);
6738
+ var preAndNext = Math.pow(prePoint[0] - nextPoint[0], 2) + Math.pow(prePoint[1] - nextPoint[1], 2); // 以 currentPoint 为顶点的夹角
6739
+
6740
+ var currentAngle = Math.acos((currentAndPre + currentAndNext - preAndNext) / (2 * Math.sqrt(currentAndPre) * Math.sqrt(currentAndNext))); // 夹角为空、 0 或 PI 时,不需要计算夹角处的额外宽度
6741
+ // 注意: 由于计算精度问题,夹角为 0 的情况计算出来的角度可能是一个很小的值,还需要判断其与 0 是否近似相等
6742
+
6743
+ if (!currentAngle || Math.sin(currentAngle) === 0 || util.isNumberEqual(currentAngle, 0)) {
6744
+ return {
6745
+ xExtra: 0,
6746
+ yExtra: 0
6747
+ };
6748
+ }
6749
+
6750
+ var xAngle = Math.abs(Math.atan2(nextPoint[1] - currentPoint[1], nextPoint[0] - currentPoint[0]));
6751
+ var yAngle = Math.abs(Math.atan2(nextPoint[0] - currentPoint[0], nextPoint[1] - currentPoint[1])); // 将夹角转为锐角
6752
+
6753
+ xAngle = xAngle > Math.PI / 2 ? Math.PI - xAngle : xAngle;
6754
+ yAngle = yAngle > Math.PI / 2 ? Math.PI - yAngle : yAngle; // 这里不考虑在水平和垂直方向的投影,直接使用最大差值
6755
+ // 由于上层统一加减了二分之一线宽,这里需要进行弥补
6756
+
6757
+ var extra = {
6758
+ // 水平方向投影
6759
+ xExtra: Math.cos(currentAngle / 2 - xAngle) * (lineWidth / 2 * (1 / Math.sin(currentAngle / 2))) - lineWidth / 2 || 0,
6760
+ // 垂直方向投影
6761
+ yExtra: Math.cos(yAngle - currentAngle / 2) * (lineWidth / 2 * (1 / Math.sin(currentAngle / 2))) - lineWidth / 2 || 0
6762
+ };
6763
+ return extra;
6764
+ } // 点对称
6765
+
6766
+
6767
+ function toSymmetry(point, center) {
6768
+ return [center[0] + (center[0] - point[0]), center[1] + (center[1] - point[1])];
6769
+ }
6770
+
6650
6771
  function path2Segments(path) {
6651
6772
  var segments = [];
6652
6773
  var currentPoint = null; // 当前图形
6653
6774
 
6654
6775
  var nextParams = null; // 下一节点的 path 参数
6655
- // let startMovePoint = null; // 开始 M 的点,可能会有多个
6776
+
6777
+ var startMovePoint = null; // 开始 M 的点,可能会有多个
6656
6778
 
6657
6779
  var lastStartMovePointIndex = 0; // 最近一个开始点 M 的索引
6658
6780
 
@@ -6668,18 +6790,43 @@ function path2Segments(path) {
6668
6790
  prePoint: currentPoint,
6669
6791
  params: params,
6670
6792
  startTangent: null,
6671
- endTangent: null
6793
+ endTangent: null,
6794
+ currentPoint: null,
6795
+ nextPoint: null,
6796
+ arcParams: null
6672
6797
  };
6673
6798
 
6674
6799
  switch (command) {
6675
6800
  case 'M':
6676
- // startMovePoint = [params[1], params[2]];
6801
+ startMovePoint = [params[1], params[2]];
6677
6802
  lastStartMovePointIndex = i;
6678
6803
  break;
6804
+
6805
+ case 'A':
6806
+ var arcParams = getArcParams(currentPoint, params);
6807
+ segment.arcParams = arcParams;
6808
+ break;
6809
+ }
6810
+
6811
+ if (command === 'Z') {
6812
+ // 有了 Z 后,当前节点从开始 M 的点开始
6813
+ currentPoint = startMovePoint; // 如果当前点的命令为 Z,相当于当前点为最近一个 M 点,则下一个点直接指向最近一个 M 点的下一个点
6814
+
6815
+ nextParams = path[lastStartMovePointIndex + 1];
6816
+ } else {
6817
+ var len = params.length;
6818
+ currentPoint = [params[len - 2], params[len - 1]];
6679
6819
  }
6680
6820
 
6681
- var len = params.length;
6682
- currentPoint = [params[len - 2], params[len - 1]]; // @ts-ignore
6821
+ if (nextParams && nextParams[0] === 'Z') {
6822
+ // 如果下一个点的命令为 Z,则下一个点直接指向最近一个 M 点
6823
+ nextParams = path[lastStartMovePointIndex];
6824
+
6825
+ if (segments[lastStartMovePointIndex]) {
6826
+ // 如果下一个点的命令为 Z,则最近一个 M 点的前一个点为当前点
6827
+ segments[lastStartMovePointIndex].prePoint = currentPoint;
6828
+ }
6829
+ }
6683
6830
 
6684
6831
  segment.currentPoint = currentPoint; // 如果当前点与最近一个 M 点相同,则最近一个 M 点的前一个点为当前点的前一个点
6685
6832
 
@@ -6687,13 +6834,36 @@ function path2Segments(path) {
6687
6834
  segments[lastStartMovePointIndex].prePoint = segment.prePoint;
6688
6835
  }
6689
6836
 
6690
- var nextPoint = nextParams ? [nextParams[nextParams.length - 2], nextParams[nextParams.length - 1]] : null; // @ts-ignore
6691
-
6837
+ var nextPoint = nextParams ? [nextParams[nextParams.length - 2], nextParams[nextParams.length - 1]] : null;
6692
6838
  segment.nextPoint = nextPoint; // Add startTangent and endTangent
6693
6839
 
6694
6840
  var prePoint = segment.prePoint;
6695
6841
 
6696
- if (command === 'C') {
6842
+ if (['L', 'H', 'V'].includes(command)) {
6843
+ segment.startTangent = [prePoint[0] - currentPoint[0], prePoint[1] - currentPoint[1]];
6844
+ segment.endTangent = [currentPoint[0] - prePoint[0], currentPoint[1] - prePoint[1]];
6845
+ } else if (command === 'Q') {
6846
+ // 二次贝塞尔曲线只有一个控制点
6847
+ var cp = [params[1], params[2]]; // 二次贝塞尔曲线的终点为 currentPoint
6848
+
6849
+ segment.startTangent = [prePoint[0] - cp[0], prePoint[1] - cp[1]];
6850
+ segment.endTangent = [currentPoint[0] - cp[0], currentPoint[1] - cp[1]];
6851
+ } else if (command === 'T') {
6852
+ var preSegment = segments[i - 1];
6853
+
6854
+ var _cp = toSymmetry(preSegment.currentPoint, prePoint);
6855
+
6856
+ if (preSegment.command === 'Q') {
6857
+ segment.command = 'Q';
6858
+ segment.startTangent = [prePoint[0] - _cp[0], prePoint[1] - _cp[1]];
6859
+ segment.endTangent = [currentPoint[0] - _cp[0], currentPoint[1] - _cp[1]];
6860
+ } else {
6861
+ // @ts-ignore
6862
+ segment.command = 'TL';
6863
+ segment.startTangent = [prePoint[0] - currentPoint[0], prePoint[1] - currentPoint[1]];
6864
+ segment.endTangent = [currentPoint[0] - prePoint[0], currentPoint[1] - prePoint[1]];
6865
+ }
6866
+ } else if (command === 'C') {
6697
6867
  // 三次贝塞尔曲线有两个控制点
6698
6868
  var cp1 = [params[1], params[2]];
6699
6869
  var cp2 = [params[3], params[4]];
@@ -6707,25 +6877,155 @@ function path2Segments(path) {
6707
6877
  if (segment.endTangent[0] === 0 && segment.endTangent[1] === 0) {
6708
6878
  segment.endTangent = [cp2[0] - cp1[0], cp2[1] - cp1[1]];
6709
6879
  }
6880
+ } else if (command === 'S') {
6881
+ var _preSegment = segments[i - 1];
6882
+
6883
+ var _cp2 = toSymmetry(_preSegment.currentPoint, prePoint);
6884
+
6885
+ var _cp3 = [params[1], params[2]];
6886
+
6887
+ if (_preSegment.command === 'C') {
6888
+ segment.command = 'C'; // 将 S 命令变换为 C 命令
6889
+
6890
+ segment.startTangent = [prePoint[0] - _cp2[0], prePoint[1] - _cp2[1]];
6891
+ segment.endTangent = [currentPoint[0] - _cp3[0], currentPoint[1] - _cp3[1]];
6892
+ } else {
6893
+ // @ts-ignore
6894
+ segment.command = 'SQ'; // 将 S 命令变换为 SQ 命令
6895
+
6896
+ segment.startTangent = [prePoint[0] - _cp3[0], prePoint[1] - _cp3[1]];
6897
+ segment.endTangent = [currentPoint[0] - _cp3[0], currentPoint[1] - _cp3[1]];
6898
+ }
6899
+ } else if (command === 'A') {
6900
+ var d = 0.001;
6901
+
6902
+ var _ref = segment.arcParams || {},
6903
+ _ref$cx = _ref.cx,
6904
+ cx = _ref$cx === void 0 ? 0 : _ref$cx,
6905
+ _ref$cy = _ref.cy,
6906
+ cy = _ref$cy === void 0 ? 0 : _ref$cy,
6907
+ _ref$rx = _ref.rx,
6908
+ rx = _ref$rx === void 0 ? 0 : _ref$rx,
6909
+ _ref$ry = _ref.ry,
6910
+ ry = _ref$ry === void 0 ? 0 : _ref$ry,
6911
+ _ref$sweepFlag = _ref.sweepFlag,
6912
+ sweepFlag = _ref$sweepFlag === void 0 ? 0 : _ref$sweepFlag,
6913
+ _ref$startAngle = _ref.startAngle,
6914
+ startAngle = _ref$startAngle === void 0 ? 0 : _ref$startAngle,
6915
+ _ref$endAngle = _ref.endAngle,
6916
+ endAngle = _ref$endAngle === void 0 ? 0 : _ref$endAngle;
6917
+
6918
+ if (sweepFlag === 0) {
6919
+ d *= -1;
6920
+ }
6921
+
6922
+ var dx1 = rx * Math.cos(startAngle - d) + cx;
6923
+ var dy1 = ry * Math.sin(startAngle - d) + cy;
6924
+ segment.startTangent = [dx1 - startMovePoint[0], dy1 - startMovePoint[1]];
6925
+ var dx2 = rx * Math.cos(startAngle + endAngle + d) + cx;
6926
+ var dy2 = ry * Math.sin(startAngle + endAngle - d) + cy;
6927
+ segment.endTangent = [prePoint[0] - dx2, prePoint[1] - dy2];
6710
6928
  }
6711
6929
 
6712
6930
  segments.push(segment);
6713
6931
  }
6714
6932
 
6715
6933
  return segments;
6934
+ } // 向量长度
6935
+
6936
+ function vMag(v) {
6937
+ return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
6938
+ } // u.v/|u||v|,计算夹角的余弦值
6939
+
6940
+
6941
+ function vRatio(u, v) {
6942
+ // 当存在一个向量的长度为 0 时,夹角也为 0,即夹角的余弦值为 1
6943
+ return vMag(u) * vMag(v) ? (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v)) : 1;
6944
+ } // 向量角度
6945
+
6946
+
6947
+ function vAngle(u, v) {
6948
+ return (u[0] * v[1] < u[1] * v[0] ? -1 : 1) * Math.acos(vRatio(u, v));
6716
6949
  }
6717
6950
 
6718
- function commandsToPathString(commands, object, applyLocalTransform) {
6719
- if (applyLocalTransform === void 0) {
6720
- applyLocalTransform = true;
6951
+ function getArcParams(startPoint, params) {
6952
+ var rx = params[1];
6953
+ var ry = params[2];
6954
+ var xRotation = util.mod(deg2rad(params[3]), Math.PI * 2);
6955
+ var arcFlag = params[4];
6956
+ var sweepFlag = params[5]; // 弧形起点坐标
6957
+
6958
+ var x1 = startPoint[0];
6959
+ var y1 = startPoint[1]; // 弧形终点坐标
6960
+
6961
+ var x2 = params[6];
6962
+ var y2 = params[7];
6963
+ var xp = Math.cos(xRotation) * (x1 - x2) / 2.0 + Math.sin(xRotation) * (y1 - y2) / 2.0;
6964
+ var yp = -1 * Math.sin(xRotation) * (x1 - x2) / 2.0 + Math.cos(xRotation) * (y1 - y2) / 2.0;
6965
+ var lambda = xp * xp / (rx * rx) + yp * yp / (ry * ry);
6966
+
6967
+ if (lambda > 1) {
6968
+ rx *= Math.sqrt(lambda);
6969
+ ry *= Math.sqrt(lambda);
6721
6970
  }
6722
6971
 
6723
- var transform;
6972
+ var diff = rx * rx * (yp * yp) + ry * ry * (xp * xp);
6973
+ var f = diff ? Math.sqrt((rx * rx * (ry * ry) - diff) / diff) : 1;
6724
6974
 
6725
- if (applyLocalTransform) {
6726
- transform = object.getLocalTransform();
6975
+ if (arcFlag === sweepFlag) {
6976
+ f *= -1;
6977
+ }
6978
+
6979
+ if (isNaN(f)) {
6980
+ f = 0;
6981
+ } // 旋转前的起点坐标,且当长半轴和短半轴的长度为 0 时,坐标按 (0, 0) 处理
6982
+
6983
+
6984
+ var cxp = ry ? f * rx * yp / ry : 0;
6985
+ var cyp = rx ? f * -ry * xp / rx : 0; // 椭圆圆心坐标
6986
+
6987
+ var cx = (x1 + x2) / 2.0 + Math.cos(xRotation) * cxp - Math.sin(xRotation) * cyp;
6988
+ var cy = (y1 + y2) / 2.0 + Math.sin(xRotation) * cxp + Math.cos(xRotation) * cyp; // 起始点的单位向量
6989
+
6990
+ var u = [(xp - cxp) / rx, (yp - cyp) / ry]; // 终止点的单位向量
6991
+
6992
+ var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry]; // 计算起始点和圆心的连线,与 x 轴正方向的夹角
6993
+
6994
+ var theta = vAngle([1, 0], u); // 计算圆弧起始点和终止点与椭圆圆心连线的夹角
6995
+
6996
+ var dTheta = vAngle(u, v);
6997
+
6998
+ if (vRatio(u, v) <= -1) {
6999
+ dTheta = Math.PI;
7000
+ }
7001
+
7002
+ if (vRatio(u, v) >= 1) {
7003
+ dTheta = 0;
7004
+ }
7005
+
7006
+ if (sweepFlag === 0 && dTheta > 0) {
7007
+ dTheta = dTheta - 2 * Math.PI;
6727
7008
  }
6728
7009
 
7010
+ if (sweepFlag === 1 && dTheta < 0) {
7011
+ dTheta = dTheta + 2 * Math.PI;
7012
+ }
7013
+
7014
+ return {
7015
+ cx: cx,
7016
+ cy: cy,
7017
+ // 弧形的起点和终点相同时,长轴和短轴的长度按 0 处理
7018
+ rx: isSamePoint(startPoint, [x2, y2]) ? 0 : rx,
7019
+ ry: isSamePoint(startPoint, [x2, y2]) ? 0 : ry,
7020
+ startAngle: theta,
7021
+ endAngle: theta + dTheta,
7022
+ xRotation: xRotation,
7023
+ arcFlag: arcFlag,
7024
+ sweepFlag: sweepFlag
7025
+ };
7026
+ }
7027
+
7028
+ function commandsToPathString(commands, object, transform) {
6729
7029
  var _object$parsedStyle = object.parsedStyle,
6730
7030
  _object$parsedStyle$d = _object$parsedStyle.defX,
6731
7031
  defX = _object$parsedStyle$d === void 0 ? 0 : _object$parsedStyle$d,
@@ -6737,7 +7037,7 @@ function commandsToPathString(commands, object, applyLocalTransform) {
6737
7037
  if (cur[0] === 'M' || cur[0] === 'L') {
6738
7038
  var p = glMatrix.vec3.fromValues(cur[1] - defX, cur[2] - defY, 0);
6739
7039
 
6740
- if (applyLocalTransform) {
7040
+ if (transform) {
6741
7041
  glMatrix.vec3.transformMat4(p, p, transform);
6742
7042
  }
6743
7043
 
@@ -6749,7 +7049,7 @@ function commandsToPathString(commands, object, applyLocalTransform) {
6749
7049
  var p2 = glMatrix.vec3.fromValues(cur[3] - defX, cur[4] - defY, 0);
6750
7050
  var p3 = glMatrix.vec3.fromValues(cur[5] - defX, cur[6] - defY, 0);
6751
7051
 
6752
- if (applyLocalTransform) {
7052
+ if (transform) {
6753
7053
  glMatrix.vec3.transformMat4(p1, p1, transform);
6754
7054
  glMatrix.vec3.transformMat4(p2, p2, transform);
6755
7055
  glMatrix.vec3.transformMat4(p3, p3, transform);
@@ -6759,7 +7059,7 @@ function commandsToPathString(commands, object, applyLocalTransform) {
6759
7059
  } else if (cur[0] === 'A') {
6760
7060
  var c = glMatrix.vec3.fromValues(cur[6] - defX, cur[7] - defY, 0);
6761
7061
 
6762
- if (applyLocalTransform) {
7062
+ if (transform) {
6763
7063
  glMatrix.vec3.transformMat4(c, c, transform);
6764
7064
  }
6765
7065
 
@@ -6823,9 +7123,9 @@ function rectToCommands(width, height, x, y, radius) {
6823
7123
  */
6824
7124
 
6825
7125
 
6826
- function convertToPath(object, applyLocalTransform) {
6827
- if (applyLocalTransform === void 0) {
6828
- applyLocalTransform = true;
7126
+ function convertToPath(object, transform) {
7127
+ if (transform === void 0) {
7128
+ transform = object.getLocalTransform();
6829
7129
  }
6830
7130
 
6831
7131
  var commands = [];
@@ -6894,7 +7194,7 @@ function convertToPath(object, applyLocalTransform) {
6894
7194
  }
6895
7195
 
6896
7196
  if (commands.length) {
6897
- return commandsToPathString(commands, object, applyLocalTransform);
7197
+ return commandsToPathString(commands, object, transform);
6898
7198
  }
6899
7199
  }
6900
7200
  function translatePathToString(pathArray, x, y, startOffsetX, startOffsetY, endOffsetX, endOffsetY) {
@@ -6915,8 +7215,7 @@ function translatePathToString(pathArray, x, y, startOffsetX, startOffsetY, endO
6915
7215
  }
6916
7216
 
6917
7217
  var newValue = pathArray.map(function (params, i) {
6918
- var command = params[0]; // @ts-ignore
6919
-
7218
+ var command = params[0];
6920
7219
  var isClosed = pathArray[pathArray.length - 1][0] === 'Z';
6921
7220
  var offsetX = i === pathArray.length - (isClosed ? 2 : 1) ? endOffsetX : 0;
6922
7221
  var offsetY = i === pathArray.length - (isClosed ? 2 : 1) ? endOffsetY : 0;
@@ -8558,7 +8857,7 @@ var BUILT_IN_PROPERTIES = [{
8558
8857
  n: 'textAlign',
8559
8858
  l: true,
8560
8859
  inh: true,
8561
- k: ['start', 'center', 'end', 'left', 'right'],
8860
+ k: ['start', 'center', 'middle', 'end', 'left', 'right'],
8562
8861
  d: 'start'
8563
8862
  }, // {
8564
8863
  // n: 'whiteSpace',
@@ -8670,12 +8969,10 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
8670
8969
  attributeNames.forEach(function (attributeName) {
8671
8970
  var _propertyMetadataCach;
8672
8971
 
8673
- var _formatAttribute = formatAttribute(attributeName, attributes[attributeName]),
8674
- name = _formatAttribute[0],
8675
- value = _formatAttribute[1];
8972
+ var name = formatAttributeName(attributeName);
8676
8973
 
8677
8974
  if (!skipUpdateAttribute) {
8678
- object.attributes[name] = value;
8975
+ object.attributes[name] = attributes[attributeName];
8679
8976
  }
8680
8977
 
8681
8978
  if (!needUpdateGeometry && ((_propertyMetadataCach = propertyMetadataCache[name]) === null || _propertyMetadataCach === void 0 ? void 0 : _propertyMetadataCach.l)) {
@@ -9459,7 +9756,11 @@ var EventTarget = /*#__PURE__*/function () {
9459
9756
  */
9460
9757
  ;
9461
9758
 
9462
- _proto.dispatchEvent = function dispatchEvent(e) {
9759
+ _proto.dispatchEvent = function dispatchEvent(e, skipPropagate) {
9760
+ if (skipPropagate === void 0) {
9761
+ skipPropagate = false;
9762
+ }
9763
+
9463
9764
  if (!(e instanceof FederatedEvent)) {
9464
9765
  throw new Error('DisplayObject cannot propagate events outside of the Federated Events API');
9465
9766
  } // should account for Element / Document / Canvas
@@ -9489,8 +9790,12 @@ var EventTarget = /*#__PURE__*/function () {
9489
9790
 
9490
9791
  e.defaultPrevented = false;
9491
9792
  e.path = [];
9492
- e.target = this;
9493
- (_e$manager = e.manager) === null || _e$manager === void 0 ? void 0 : _e$manager.dispatchEvent(e);
9793
+
9794
+ if (!skipPropagate) {
9795
+ e.target = this;
9796
+ }
9797
+
9798
+ (_e$manager = e.manager) === null || _e$manager === void 0 ? void 0 : _e$manager.dispatchEvent(e, e.type, skipPropagate);
9494
9799
  }
9495
9800
 
9496
9801
  return !e.defaultPrevented;
@@ -10808,9 +11113,7 @@ var Element = /*#__PURE__*/function (_Node) {
10808
11113
  var value = this.attributes[name];
10809
11114
 
10810
11115
  if (value === undefined) {
10811
- var _formatAttribute = formatAttribute(name, ''),
10812
- attributeName = _formatAttribute[0];
10813
-
11116
+ var attributeName = formatAttributeName(name);
10814
11117
  value = this.attributes[attributeName]; // if the given attribute does not exist, the value returned will either be null or ""
10815
11118
 
10816
11119
  return util.isNil(value) ? null : value;
@@ -11219,6 +11522,7 @@ var DEFAULT_PARSED_STYLE_PROPS = {
11219
11522
  filter: [],
11220
11523
  shadowType: 'outer'
11221
11524
  };
11525
+ var INHERITABLE_STYLE_PROPS = ['opacity', 'fillOpacity', 'strokeOpacity', 'transformOrigin', 'visibility', 'pointerEvents', 'lineWidth', 'lineCap', 'lineJoin', 'increasedLineWidthForHitTesting', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'textAlign', 'textBaseline', 'textTransform'];
11222
11526
  /**
11223
11527
  * prototype chains: DisplayObject -> Element -> Node -> EventTarget
11224
11528
  *
@@ -11258,6 +11562,7 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
11258
11562
 
11259
11563
  _this.config = void 0;
11260
11564
  _this.isCustomElement = false;
11565
+ _this.isMutationObserved = false;
11261
11566
  _this.activeAnimations = [];
11262
11567
 
11263
11568
  _this.getClip = function () {
@@ -11392,14 +11697,7 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
11392
11697
 
11393
11698
  runtime.styleValueRegistry.processProperties(this, attributes, {
11394
11699
  forceUpdateGeometry: true,
11395
- usedAttributes: [// 'anchor',
11396
- // 'transform',
11397
- // 'zIndex',
11398
- // 'filter',
11399
- // 'shadowType',
11400
- // 'fill',
11401
- // 'stroke',
11402
- 'opacity', 'fillOpacity', 'strokeOpacity', 'transformOrigin', 'visibility', 'pointerEvents', 'lineWidth', 'lineCap', 'lineJoin', 'increasedLineWidthForHitTesting', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'textAlign', 'textBaseline', 'textTransform']
11700
+ usedAttributes: INHERITABLE_STYLE_PROPS
11403
11701
  }); // redraw at next frame
11404
11702
 
11405
11703
  renderable.dirty = true;
@@ -11410,19 +11708,16 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
11410
11708
  force = false;
11411
11709
  }
11412
11710
 
11413
- var _formatAttribute = formatAttribute(name, value),
11414
- attributeName = _formatAttribute[0],
11415
- attributeValue = _formatAttribute[1]; // ignore undefined value
11416
-
11711
+ var attributeName = formatAttributeName(name); // ignore undefined value
11417
11712
 
11418
11713
  if (util.isUndefined(value)) {
11419
11714
  return;
11420
11715
  }
11421
11716
 
11422
- if (force || attributeValue !== this.attributes[attributeName]) {
11423
- this.internalSetAttribute(attributeName, attributeValue);
11717
+ if (force || value !== this.attributes[attributeName]) {
11718
+ this.internalSetAttribute(attributeName, value);
11424
11719
 
11425
- _Element.prototype.setAttribute.call(this, attributeName, attributeValue);
11720
+ _Element.prototype.setAttribute.call(this, attributeName, value);
11426
11721
  }
11427
11722
  }
11428
11723
  /**
@@ -11452,7 +11747,13 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
11452
11747
  mutationEvent.attrName = name;
11453
11748
  mutationEvent.prevParsedValue = oldParsedValue;
11454
11749
  mutationEvent.newParsedValue = newParsedValue;
11455
- this.dispatchEvent(mutationEvent);
11750
+
11751
+ if (this.isMutationObserved) {
11752
+ this.dispatchEvent(mutationEvent);
11753
+ } else {
11754
+ mutationEvent.target = this;
11755
+ this.ownerDocument.defaultView.dispatchEvent(mutationEvent, true);
11756
+ }
11456
11757
  }
11457
11758
 
11458
11759
  if ((this.isCustomElement && this.isConnected || !this.isCustomElement) && this.attributeChangedCallback) {
@@ -12509,7 +12810,11 @@ var Line = /*#__PURE__*/function (_DisplayObject) {
12509
12810
  marker.setLocalPosition(ox + Math.cos(rad) * offset, oy + Math.sin(rad) * offset);
12510
12811
  };
12511
12812
 
12512
- _proto.getPoint = function getPoint(ratio) {
12813
+ _proto.getPoint = function getPoint(ratio, inWorldSpace) {
12814
+ if (inWorldSpace === void 0) {
12815
+ inWorldSpace = false;
12816
+ }
12817
+
12513
12818
  // TODO: account for z1/z2 in 3D line
12514
12819
  var _this$parsedStyle3 = this.parsedStyle,
12515
12820
  x1 = _this$parsedStyle3.x1,
@@ -12523,13 +12828,17 @@ var Line = /*#__PURE__*/function (_DisplayObject) {
12523
12828
  x = _LineUtil$pointAt.x,
12524
12829
  y = _LineUtil$pointAt.y;
12525
12830
 
12526
- var transformed = glMatrix.vec3.transformMat4(glMatrix.vec3.create(), glMatrix.vec3.fromValues(x - defX, y - defY, 0), this.getLocalTransform()); // apply local transformation
12831
+ var transformed = glMatrix.vec3.transformMat4(glMatrix.vec3.create(), glMatrix.vec3.fromValues(x - defX, y - defY, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform()); // apply local transformation
12527
12832
 
12528
12833
  return new Point(transformed[0], transformed[1]);
12529
12834
  };
12530
12835
 
12531
- _proto.getPointAtLength = function getPointAtLength(distance) {
12532
- return this.getPoint(distance / this.getTotalLength());
12836
+ _proto.getPointAtLength = function getPointAtLength(distance, inWorldSpace) {
12837
+ if (inWorldSpace === void 0) {
12838
+ inWorldSpace = false;
12839
+ }
12840
+
12841
+ return this.getPoint(distance / this.getTotalLength(), inWorldSpace);
12533
12842
  };
12534
12843
 
12535
12844
  _proto.getTotalLength = function getTotalLength() {
@@ -12726,7 +13035,11 @@ var Path = /*#__PURE__*/function (_DisplayObject) {
12726
13035
  */
12727
13036
  ;
12728
13037
 
12729
- _proto.getPointAtLength = function getPointAtLength(distance) {
13038
+ _proto.getPointAtLength = function getPointAtLength(distance, inWorldSpace) {
13039
+ if (inWorldSpace === void 0) {
13040
+ inWorldSpace = false;
13041
+ }
13042
+
12730
13043
  var _this$parsedStyle4 = this.parsedStyle,
12731
13044
  defX = _this$parsedStyle4.defX,
12732
13045
  defY = _this$parsedStyle4.defY,
@@ -12736,7 +13049,7 @@ var Path = /*#__PURE__*/function (_DisplayObject) {
12736
13049
  x = _getPointAtLength2.x,
12737
13050
  y = _getPointAtLength2.y;
12738
13051
 
12739
- var transformed = glMatrix.vec3.transformMat4(glMatrix.vec3.create(), glMatrix.vec3.fromValues(x - defX, y - defY, 0), this.getLocalTransform()); // apply local transformation
13052
+ var transformed = glMatrix.vec3.transformMat4(glMatrix.vec3.create(), glMatrix.vec3.fromValues(x - defX, y - defY, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform()); // apply local transformation
12740
13053
 
12741
13054
  return new Point(transformed[0], transformed[1]);
12742
13055
  }
@@ -12745,8 +13058,12 @@ var Path = /*#__PURE__*/function (_DisplayObject) {
12745
13058
  */
12746
13059
  ;
12747
13060
 
12748
- _proto.getPoint = function getPoint(ratio) {
12749
- return this.getPointAtLength(ratio * getOrCalculatePathTotalLength(this));
13061
+ _proto.getPoint = function getPoint(ratio, inWorldSpace) {
13062
+ if (inWorldSpace === void 0) {
13063
+ inWorldSpace = false;
13064
+ }
13065
+
13066
+ return this.getPointAtLength(ratio * getOrCalculatePathTotalLength(this), inWorldSpace);
12750
13067
  }
12751
13068
  /**
12752
13069
  * Get start tangent vector
@@ -13005,11 +13322,19 @@ var Polyline = /*#__PURE__*/function (_Polygon) {
13005
13322
  return this.parsedStyle.points.totalLength;
13006
13323
  };
13007
13324
 
13008
- _proto.getPointAtLength = function getPointAtLength(distance) {
13009
- return this.getPoint(distance / this.getTotalLength());
13325
+ _proto.getPointAtLength = function getPointAtLength(distance, inWorldSpace) {
13326
+ if (inWorldSpace === void 0) {
13327
+ inWorldSpace = false;
13328
+ }
13329
+
13330
+ return this.getPoint(distance / this.getTotalLength(), inWorldSpace);
13010
13331
  };
13011
13332
 
13012
- _proto.getPoint = function getPoint(ratio) {
13333
+ _proto.getPoint = function getPoint(ratio, inWorldSpace) {
13334
+ if (inWorldSpace === void 0) {
13335
+ inWorldSpace = false;
13336
+ }
13337
+
13013
13338
  var _this$parsedStyle = this.parsedStyle,
13014
13339
  defX = _this$parsedStyle.defX,
13015
13340
  defY = _this$parsedStyle.defY,
@@ -13029,7 +13354,7 @@ var Polyline = /*#__PURE__*/function (_Polygon) {
13029
13354
  x = _LineUtil$pointAt.x,
13030
13355
  y = _LineUtil$pointAt.y;
13031
13356
 
13032
- var transformed = glMatrix.vec3.transformMat4(glMatrix.vec3.create(), glMatrix.vec3.fromValues(x - defX, y - defY, 0), this.getLocalTransform()); // apply local transformation
13357
+ var transformed = glMatrix.vec3.transformMat4(glMatrix.vec3.create(), glMatrix.vec3.fromValues(x - defX, y - defY, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform()); // apply local transformation
13033
13358
 
13034
13359
  return new Point(transformed[0], transformed[1]);
13035
13360
  };
@@ -14217,7 +14542,7 @@ var TextUpdater = /*#__PURE__*/function () {
14217
14542
  var anchor = [0, 1];
14218
14543
  var lineXOffset = 0;
14219
14544
 
14220
- if (textAlign === 'center') {
14545
+ if (textAlign === 'center' || textAlign === 'middle') {
14221
14546
  lineXOffset = lineWidth / 2;
14222
14547
  anchor = [0.5, 1];
14223
14548
  } else if (textAlign === 'right' || textAlign === 'end') {
@@ -14942,10 +15267,20 @@ var EventService = /*#__PURE__*/function () {
14942
15267
  }
14943
15268
  };
14944
15269
 
14945
- _proto.dispatchEvent = function dispatchEvent(e, type) {
14946
- e.propagationStopped = false;
14947
- e.propagationImmediatelyStopped = false;
14948
- this.propagate(e, type);
15270
+ _proto.dispatchEvent = function dispatchEvent(e, type, skipPropagate) {
15271
+ // Canvas should skip
15272
+ if (!skipPropagate) {
15273
+ e.propagationStopped = false;
15274
+ e.propagationImmediatelyStopped = false;
15275
+ this.propagate(e, type);
15276
+ } else {
15277
+ // target phase
15278
+ e.eventPhase = e.AT_TARGET;
15279
+ var canvas = this.rootTarget.defaultView || null;
15280
+ e.currentTarget = canvas;
15281
+ this.notifyListeners(e, type);
15282
+ }
15283
+
14949
15284
  this.emitter.emit(type || e.type, e);
14950
15285
  };
14951
15286
 
@@ -15751,10 +16086,11 @@ var RenderingService = /*#__PURE__*/function () {
15751
16086
 
15752
16087
  if (renderOrderChanged) {
15753
16088
  displayObject.forEach(function (child) {
16089
+ _this2.renderOrderChangedEvent.target = child;
15754
16090
  _this2.renderOrderChangedEvent.detail = {
15755
16091
  renderOrder: child.sortable.renderOrder
15756
16092
  };
15757
- child.dispatchEvent(_this2.renderOrderChangedEvent);
16093
+ child.ownerDocument.defaultView.dispatchEvent(_this2.renderOrderChangedEvent, true);
15758
16094
  });
15759
16095
  }
15760
16096
  };
@@ -16415,9 +16751,10 @@ var DefaultSceneGraphService = /*#__PURE__*/function () {
16415
16751
  var set = new Set();
16416
16752
 
16417
16753
  var trigger = function trigger(element, detail) {
16418
- if (!set.has(element.entity)) {
16754
+ if (element.isConnected && !set.has(element.entity)) {
16419
16755
  _this2.boundsChangedEvent.detail = detail;
16420
- element.dispatchEvent(_this2.boundsChangedEvent);
16756
+ _this2.boundsChangedEvent.target = element;
16757
+ element.ownerDocument.defaultView.dispatchEvent(_this2.boundsChangedEvent, true);
16421
16758
  set.add(element.entity);
16422
16759
  }
16423
16760
  };
@@ -16435,6 +16772,7 @@ var DefaultSceneGraphService = /*#__PURE__*/function () {
16435
16772
  }
16436
16773
  });
16437
16774
  this.pendingEvents = [];
16775
+ set.clear();
16438
16776
  };
16439
16777
 
16440
16778
  _proto.dirtifyToRoot = function dirtifyToRoot(element, affectChildren) {
@@ -17085,7 +17423,7 @@ var TextService = /*#__PURE__*/function () {
17085
17423
  lineMetrics: lineWidths.map(function (width, i) {
17086
17424
  var offsetX = 0; // handle horizontal text align
17087
17425
 
17088
- if (textAlign === 'center') {
17426
+ if (textAlign === 'center' || textAlign === 'middle') {
17089
17427
  offsetX -= width / 2;
17090
17428
  } else if (textAlign === 'right' || textAlign === 'end') {
17091
17429
  offsetX -= width;
@@ -17915,21 +18253,14 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
17915
18253
 
17916
18254
  var _proto = PrepareRendererPlugin.prototype;
17917
18255
 
17918
- _proto.pushToSync = function pushToSync(list) {
17919
- var _this = this;
17920
-
17921
- list.forEach(function (i) {
17922
- _this.toSync.add(i);
17923
- });
17924
- } // private isFirstTimeRendering = true;
17925
- ;
17926
-
18256
+ // private isFirstTimeRendering = true;
17927
18257
  _proto.apply = function apply(context) {
17928
- var _this2 = this;
18258
+ var _this = this;
17929
18259
 
17930
18260
  var renderingService = context.renderingService,
17931
18261
  renderingContext = context.renderingContext,
17932
18262
  rBushRoot = context.rBushRoot;
18263
+ var canvas = renderingContext.root.ownerDocument.defaultView;
17933
18264
  this.rBush = rBushRoot;
17934
18265
 
17935
18266
  var handleAttributeChanged = function handleAttributeChanged(e) {
@@ -17944,20 +18275,26 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
17944
18275
 
17945
18276
  if (affectChildren) {
17946
18277
  object.forEach(function (node) {
17947
- _this2.pushToSync([node]);
18278
+ _this.toSync.add(node);
17948
18279
  });
17949
18280
  }
17950
18281
 
17951
- _this2.pushToSync(e.composedPath().slice(0, -2));
18282
+ var p = object;
18283
+
18284
+ while (p) {
18285
+ if (p.renderable) {
18286
+ _this.toSync.add(p);
18287
+ }
18288
+
18289
+ p = p.parentElement;
18290
+ } // this.pushToSync(e.composedPath().slice(0, -2) as DisplayObject[]);
18291
+
17952
18292
 
17953
18293
  renderingService.dirtify();
17954
18294
  };
17955
18295
 
17956
18296
  var handleMounted = function handleMounted(e) {
17957
- var object = e.target;
17958
-
17959
- _this2.pushToSync(e.composedPath().slice(0, -2)); // recalc style values
17960
-
18297
+ var object = e.target; // recalc style values
17961
18298
 
17962
18299
  runtime.styleValueRegistry.recalc(object);
17963
18300
  runtime.sceneGraphService.dirtifyToRoot(object);
@@ -17969,12 +18306,12 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
17969
18306
  var rBushNode = object.rBushNode;
17970
18307
 
17971
18308
  if (rBushNode.aabb) {
17972
- _this2.rBush.remove(rBushNode.aabb);
18309
+ _this.rBush.remove(rBushNode.aabb);
17973
18310
  }
17974
18311
 
17975
- _this2.toSync.delete(object);
18312
+ _this.toSync.delete(object);
17976
18313
 
17977
- runtime.sceneGraphService.dirtifyToRoot(e.target);
18314
+ runtime.sceneGraphService.dirtifyToRoot(object);
17978
18315
  renderingService.dirtify();
17979
18316
  };
17980
18317
 
@@ -17983,10 +18320,10 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
17983
18320
  while (1) {
17984
18321
  switch (_context.prev = _context.next) {
17985
18322
  case 0:
17986
- renderingContext.root.addEventListener(exports.ElementEvent.MOUNTED, handleMounted);
17987
- renderingContext.root.addEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
17988
- renderingContext.root.addEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
17989
- renderingContext.root.addEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
18323
+ canvas.addEventListener(exports.ElementEvent.MOUNTED, handleMounted);
18324
+ canvas.addEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
18325
+ canvas.addEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
18326
+ canvas.addEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
17990
18327
 
17991
18328
  case 4:
17992
18329
  case "end":
@@ -17996,10 +18333,10 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
17996
18333
  }, _callee);
17997
18334
  })));
17998
18335
  renderingService.hooks.destroy.tap(PrepareRendererPlugin.tag, function () {
17999
- renderingContext.root.removeEventListener(exports.ElementEvent.MOUNTED, handleMounted);
18000
- renderingContext.root.removeEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
18001
- renderingContext.root.removeEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
18002
- renderingContext.root.removeEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
18336
+ canvas.removeEventListener(exports.ElementEvent.MOUNTED, handleMounted);
18337
+ canvas.removeEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
18338
+ canvas.removeEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
18339
+ canvas.removeEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
18003
18340
  });
18004
18341
  renderingService.hooks.endFrame.tap(PrepareRendererPlugin.tag, function () {
18005
18342
  // if (this.isFirstTimeRendering) {
@@ -18009,12 +18346,12 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
18009
18346
  // } else {
18010
18347
  // this.syncRTree();
18011
18348
  // }
18012
- _this2.syncRTree();
18349
+ _this.syncRTree();
18013
18350
  });
18014
18351
  };
18015
18352
 
18016
18353
  _proto.syncRTree = function syncRTree() {
18017
- var _this3 = this;
18354
+ var _this2 = this;
18018
18355
 
18019
18356
  // bounds changed, need re-inserting its children
18020
18357
  var bulk = [];
@@ -18025,7 +18362,7 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
18025
18362
  var rBushNode = node.rBushNode; // clear dirty node
18026
18363
 
18027
18364
  if (rBushNode && rBushNode.aabb) {
18028
- _this3.rBush.remove(rBushNode.aabb);
18365
+ _this2.rBush.remove(rBushNode.aabb);
18029
18366
  }
18030
18367
 
18031
18368
  var renderBounds = node.getRenderBounds();
@@ -18086,8 +18423,8 @@ var DEFAULT_CAMERA_FAR = 1000;
18086
18423
  * reuse custom event preventing from re-create them in every frame
18087
18424
  */
18088
18425
 
18089
- var mountEvent = new CustomEvent(exports.ElementEvent.MOUNTED);
18090
- var unmountEvent = new CustomEvent(exports.ElementEvent.UNMOUNTED);
18426
+ var mountedEvent = new CustomEvent(exports.ElementEvent.MOUNTED);
18427
+ var unmountedEvent = new CustomEvent(exports.ElementEvent.UNMOUNTED);
18091
18428
  var beforeRenderEvent = new CustomEvent(exports.CanvasEvent.BEFORE_RENDER);
18092
18429
  var afterRenderEvent = new CustomEvent(exports.CanvasEvent.AFTER_RENDER);
18093
18430
  /**
@@ -18602,13 +18939,20 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
18602
18939
 
18603
18940
  path.reverse().forEach(function (child) {
18604
18941
  // trigger before unmounted
18605
- if (child instanceof CustomElement) {
18942
+ if (child.isCustomElement) {
18606
18943
  if (child.disconnectedCallback) {
18607
18944
  child.disconnectedCallback();
18608
18945
  }
18609
18946
  }
18610
18947
 
18611
- child.dispatchEvent(unmountEvent); // skip document.documentElement
18948
+ if (child.isMutationObserved) {
18949
+ child.dispatchEvent(unmountedEvent);
18950
+ } else {
18951
+ unmountedEvent.target = child;
18952
+
18953
+ _this5.dispatchEvent(unmountedEvent, true);
18954
+ } // skip document.documentElement
18955
+
18612
18956
 
18613
18957
  if (child !== _this5.document.documentElement) {
18614
18958
  child.ownerDocument = null;
@@ -18627,9 +18971,17 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
18627
18971
  if (!child.isConnected) {
18628
18972
  child.ownerDocument = _this6.document;
18629
18973
  child.isConnected = true;
18630
- child.dispatchEvent(mountEvent); // trigger after mounted
18631
18974
 
18632
- if (child instanceof CustomElement) {
18975
+ if (child.isMutationObserved) {
18976
+ child.dispatchEvent(mountedEvent);
18977
+ } else {
18978
+ mountedEvent.target = child;
18979
+
18980
+ _this6.dispatchEvent(mountedEvent, true);
18981
+ } // trigger after mounted
18982
+
18983
+
18984
+ if (child.isCustomElement) {
18633
18985
  if (child.connectedCallback) {
18634
18986
  child.connectedCallback();
18635
18987
  }
@@ -18776,6 +19128,7 @@ exports.definedProps = definedProps;
18776
19128
  exports.deg2rad = deg2rad;
18777
19129
  exports.deg2turn = deg2turn;
18778
19130
  exports.findClosestClipPathTarget = findClosestClipPathTarget;
19131
+ exports.fromRotationTranslationScale = fromRotationTranslationScale;
18779
19132
  exports.getAngle = getAngle;
18780
19133
  exports.getEuler = getEuler;
18781
19134
  exports.getOrCalculatePathTotalLength = getOrCalculatePathTotalLength;