@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.esm.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import RBush from 'rbush';
2
2
  export { default as RBush } from 'rbush';
3
- import { memoize, isString, isNil, isObject, clamp, isNumber, normalizePath, path2Curve, getPathBBox, equalizeSegments, getDrawDirection, reverseCurve, clonePath, getRotatedCurve, distanceSquareRoot, getTotalLength, isBoolean, isUndefined, getPointAtLength } from '@antv/util';
4
- import { vec3, mat4, vec4, mat3, quat as quat$1, vec2 } from 'gl-matrix';
3
+ import { memoize, isString, isNil, isObject, clamp, isNumber, normalizePath, path2Curve, equalizeSegments, getDrawDirection, reverseCurve, clonePath, getRotatedCurve, distanceSquareRoot, getTotalLength, min, max, isNumberEqual, mod, isBoolean, isUndefined, getPointAtLength } from '@antv/util';
4
+ import { vec3, mat4, mat3, vec4, quat as quat$1, vec2 } from 'gl-matrix';
5
5
  import { color } from 'd3-color';
6
- import { Polyline as Polyline$1, Line as Line$1 } from '@antv/g-math';
6
+ import { Polyline as Polyline$1, Line as Line$1, Arc, Cubic, Quad } from '@antv/g-math';
7
7
  import { EventEmitter } from 'eventemitter3';
8
8
  import { requestAnimationFrame as requestAnimationFrame$1, cancelAnimationFrame as cancelAnimationFrame$1 } from 'request-animation-frame-polyfill';
9
9
 
@@ -561,10 +561,7 @@ var FORMAT_ATTR_MAP = {
561
561
  alias: 'lineWidth'
562
562
  },
563
563
  textAnchor: {
564
- alias: 'textAlign',
565
- values: {
566
- middle: 'center'
567
- }
564
+ alias: 'textAlign'
568
565
  },
569
566
  src: {
570
567
  alias: 'img'
@@ -574,18 +571,8 @@ var formatAttributeName = memoize(function (name) {
574
571
  var attributeName = camelCase(name);
575
572
  var map = FORMAT_ATTR_MAP[attributeName];
576
573
  attributeName = (map === null || map === void 0 ? void 0 : map.alias) || attributeName;
577
- return [attributeName, map];
574
+ return attributeName;
578
575
  });
579
- function formatAttribute(name, value) {
580
- var _map$values;
581
-
582
- var _formatAttributeName = formatAttributeName(name),
583
- attributeName = _formatAttributeName[0],
584
- map = _formatAttributeName[1];
585
-
586
- var attributeValue = isString(value) && (map === null || map === void 0 ? void 0 : (_map$values = map.values) === null || _map$values === void 0 ? void 0 : _map$values[value]) || value;
587
- return [attributeName, attributeValue];
588
- }
589
576
 
590
577
  var canvasMap = {};
591
578
  var defaultCanvasIdCounter = 0;
@@ -4338,14 +4325,13 @@ var internalParsePath = function internalParsePath(path) {
4338
4325
  zCommandIndexes = _path2Curve[1]; // for later use
4339
4326
 
4340
4327
 
4341
- var segments = path2Segments(curve); // Only calculate bbox here since we don't need length now.
4328
+ var segments = path2Segments(absolutePath); // Only calculate bbox here since we don't need length now.
4342
4329
 
4343
- var _getPathBBox = getPathBBox(absolutePath),
4330
+ var _getPathBBox = getPathBBox(segments, 0),
4344
4331
  x = _getPathBBox.x,
4345
4332
  y = _getPathBBox.y,
4346
4333
  width = _getPathBBox.width,
4347
- height = _getPathBBox.height; // const { x, y, width, height, length } = getPathBBoxTotalLength(absolutePath);
4348
-
4334
+ height = _getPathBBox.height;
4349
4335
 
4350
4336
  return {
4351
4337
  absolutePath: absolutePath,
@@ -4355,15 +4341,8 @@ var internalParsePath = function internalParsePath(path) {
4355
4341
  polylines: polylines,
4356
4342
  curve: curve,
4357
4343
  // Delay the calculation of length.
4358
- // totalLength: length,
4359
4344
  totalLength: 0,
4360
4345
  zCommandIndexes: zCommandIndexes,
4361
- // rect: new Rectangle(
4362
- // Number.isFinite(x) ? x : 0,
4363
- // Number.isFinite(y) ? y : 0,
4364
- // Number.isFinite(width) ? width : 0,
4365
- // Number.isFinite(height) ? height : 0,
4366
- // ),
4367
4346
  rect: {
4368
4347
  x: Number.isFinite(x) ? x : 0,
4369
4348
  y: Number.isFinite(y) ? y : 0,
@@ -5445,16 +5424,23 @@ var CSSPropertyOffsetDistance = /*#__PURE__*/function () {
5445
5424
  };
5446
5425
 
5447
5426
  _proto.postProcessor = function postProcessor(object) {
5448
- if (!object.attributes.offsetPath) {
5427
+ var _object$parsedStyle = object.parsedStyle,
5428
+ offsetPath = _object$parsedStyle.offsetPath,
5429
+ offsetDistance = _object$parsedStyle.offsetDistance;
5430
+
5431
+ if (!offsetPath) {
5449
5432
  return;
5450
5433
  }
5451
5434
 
5452
- var offsetPathNodeName = object.attributes.offsetPath.nodeName;
5435
+ var nodeName = offsetPath.nodeName;
5453
5436
 
5454
- if (offsetPathNodeName === Shape.LINE || offsetPathNodeName === Shape.PATH || offsetPathNodeName === Shape.POLYLINE) {
5455
- var point = object.attributes.offsetPath.getPoint(object.parsedStyle.offsetDistance);
5437
+ if (nodeName === Shape.LINE || nodeName === Shape.PATH || nodeName === Shape.POLYLINE) {
5438
+ // set position in world space
5439
+ var point = offsetPath.getPoint(offsetDistance);
5456
5440
 
5457
5441
  if (point) {
5442
+ object.parsedStyle.defX = point.x;
5443
+ object.parsedStyle.defY = point.y;
5458
5444
  object.setLocalPosition(point.x, point.y);
5459
5445
  }
5460
5446
  }
@@ -6649,12 +6635,148 @@ function isSamePoint(point1, point2) {
6649
6635
  return point1[0] === point2[0] && point1[1] === point2[1];
6650
6636
  }
6651
6637
 
6638
+ function getPathBBox(segments, lineWidth) {
6639
+ var xArr = [];
6640
+ var yArr = [];
6641
+ var segmentsWithAngle = [];
6642
+
6643
+ for (var i = 0; i < segments.length; i++) {
6644
+ var segment = segments[i];
6645
+ var currentPoint = segment.currentPoint,
6646
+ params = segment.params,
6647
+ prePoint = segment.prePoint;
6648
+ var box = void 0;
6649
+
6650
+ switch (segment.command) {
6651
+ case 'Q':
6652
+ box = Quad.box(prePoint[0], prePoint[1], params[1], params[2], params[3], params[4]);
6653
+ break;
6654
+
6655
+ case 'C':
6656
+ box = Cubic.box(prePoint[0], prePoint[1], params[1], params[2], params[3], params[4], params[5], params[6]);
6657
+ break;
6658
+
6659
+ case 'A':
6660
+ var arcParams = segment.arcParams;
6661
+ box = Arc.box(arcParams.cx, arcParams.cy, arcParams.rx, arcParams.ry, arcParams.xRotation, arcParams.startAngle, arcParams.endAngle);
6662
+ break;
6663
+
6664
+ default:
6665
+ xArr.push(currentPoint[0]);
6666
+ yArr.push(currentPoint[1]);
6667
+ break;
6668
+ }
6669
+
6670
+ if (box) {
6671
+ segment.box = box;
6672
+ xArr.push(box.x, box.x + box.width);
6673
+ yArr.push(box.y, box.y + box.height);
6674
+ }
6675
+
6676
+ if (lineWidth && (segment.command === 'L' || segment.command === 'M') && segment.prePoint && segment.nextPoint) {
6677
+ segmentsWithAngle.push(segment);
6678
+ }
6679
+ } // bbox calculation should ignore NaN for path attribute
6680
+ // ref: https://github.com/antvis/g/issues/210
6681
+ // ref: https://github.com/antvis/G2/issues/3109
6682
+
6683
+
6684
+ xArr = xArr.filter(function (item) {
6685
+ return !Number.isNaN(item) && item !== Infinity && item !== -Infinity;
6686
+ });
6687
+ yArr = yArr.filter(function (item) {
6688
+ return !Number.isNaN(item) && item !== Infinity && item !== -Infinity;
6689
+ });
6690
+ var minX = min(xArr);
6691
+ var minY = min(yArr);
6692
+ var maxX = max(xArr);
6693
+ var maxY = max(yArr);
6694
+
6695
+ if (segmentsWithAngle.length === 0) {
6696
+ return {
6697
+ x: minX,
6698
+ y: minY,
6699
+ width: maxX - minX,
6700
+ height: maxY - minY
6701
+ };
6702
+ }
6703
+
6704
+ for (var _i = 0; _i < segmentsWithAngle.length; _i++) {
6705
+ var _segment = segmentsWithAngle[_i];
6706
+ var _currentPoint = _segment.currentPoint;
6707
+ var extra = void 0;
6708
+
6709
+ if (_currentPoint[0] === minX) {
6710
+ extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
6711
+ minX = minX - extra.xExtra;
6712
+ } else if (_currentPoint[0] === maxX) {
6713
+ extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
6714
+ maxX = maxX + extra.xExtra;
6715
+ }
6716
+
6717
+ if (_currentPoint[1] === minY) {
6718
+ extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
6719
+ minY = minY - extra.yExtra;
6720
+ } else if (_currentPoint[1] === maxY) {
6721
+ extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
6722
+ maxY = maxY + extra.yExtra;
6723
+ }
6724
+ }
6725
+
6726
+ return {
6727
+ x: minX,
6728
+ y: minY,
6729
+ width: maxX - minX,
6730
+ height: maxY - minY
6731
+ };
6732
+ }
6733
+
6734
+ function getExtraFromSegmentWithAngle(segment, lineWidth) {
6735
+ var prePoint = segment.prePoint,
6736
+ currentPoint = segment.currentPoint,
6737
+ nextPoint = segment.nextPoint;
6738
+ var currentAndPre = Math.pow(currentPoint[0] - prePoint[0], 2) + Math.pow(currentPoint[1] - prePoint[1], 2);
6739
+ var currentAndNext = Math.pow(currentPoint[0] - nextPoint[0], 2) + Math.pow(currentPoint[1] - nextPoint[1], 2);
6740
+ var preAndNext = Math.pow(prePoint[0] - nextPoint[0], 2) + Math.pow(prePoint[1] - nextPoint[1], 2); // 以 currentPoint 为顶点的夹角
6741
+
6742
+ var currentAngle = Math.acos((currentAndPre + currentAndNext - preAndNext) / (2 * Math.sqrt(currentAndPre) * Math.sqrt(currentAndNext))); // 夹角为空、 0 或 PI 时,不需要计算夹角处的额外宽度
6743
+ // 注意: 由于计算精度问题,夹角为 0 的情况计算出来的角度可能是一个很小的值,还需要判断其与 0 是否近似相等
6744
+
6745
+ if (!currentAngle || Math.sin(currentAngle) === 0 || isNumberEqual(currentAngle, 0)) {
6746
+ return {
6747
+ xExtra: 0,
6748
+ yExtra: 0
6749
+ };
6750
+ }
6751
+
6752
+ var xAngle = Math.abs(Math.atan2(nextPoint[1] - currentPoint[1], nextPoint[0] - currentPoint[0]));
6753
+ var yAngle = Math.abs(Math.atan2(nextPoint[0] - currentPoint[0], nextPoint[1] - currentPoint[1])); // 将夹角转为锐角
6754
+
6755
+ xAngle = xAngle > Math.PI / 2 ? Math.PI - xAngle : xAngle;
6756
+ yAngle = yAngle > Math.PI / 2 ? Math.PI - yAngle : yAngle; // 这里不考虑在水平和垂直方向的投影,直接使用最大差值
6757
+ // 由于上层统一加减了二分之一线宽,这里需要进行弥补
6758
+
6759
+ var extra = {
6760
+ // 水平方向投影
6761
+ xExtra: Math.cos(currentAngle / 2 - xAngle) * (lineWidth / 2 * (1 / Math.sin(currentAngle / 2))) - lineWidth / 2 || 0,
6762
+ // 垂直方向投影
6763
+ yExtra: Math.cos(yAngle - currentAngle / 2) * (lineWidth / 2 * (1 / Math.sin(currentAngle / 2))) - lineWidth / 2 || 0
6764
+ };
6765
+ return extra;
6766
+ } // 点对称
6767
+
6768
+
6769
+ function toSymmetry(point, center) {
6770
+ return [center[0] + (center[0] - point[0]), center[1] + (center[1] - point[1])];
6771
+ }
6772
+
6652
6773
  function path2Segments(path) {
6653
6774
  var segments = [];
6654
6775
  var currentPoint = null; // 当前图形
6655
6776
 
6656
6777
  var nextParams = null; // 下一节点的 path 参数
6657
- // let startMovePoint = null; // 开始 M 的点,可能会有多个
6778
+
6779
+ var startMovePoint = null; // 开始 M 的点,可能会有多个
6658
6780
 
6659
6781
  var lastStartMovePointIndex = 0; // 最近一个开始点 M 的索引
6660
6782
 
@@ -6670,18 +6792,43 @@ function path2Segments(path) {
6670
6792
  prePoint: currentPoint,
6671
6793
  params: params,
6672
6794
  startTangent: null,
6673
- endTangent: null
6795
+ endTangent: null,
6796
+ currentPoint: null,
6797
+ nextPoint: null,
6798
+ arcParams: null
6674
6799
  };
6675
6800
 
6676
6801
  switch (command) {
6677
6802
  case 'M':
6678
- // startMovePoint = [params[1], params[2]];
6803
+ startMovePoint = [params[1], params[2]];
6679
6804
  lastStartMovePointIndex = i;
6680
6805
  break;
6806
+
6807
+ case 'A':
6808
+ var arcParams = getArcParams(currentPoint, params);
6809
+ segment.arcParams = arcParams;
6810
+ break;
6811
+ }
6812
+
6813
+ if (command === 'Z') {
6814
+ // 有了 Z 后,当前节点从开始 M 的点开始
6815
+ currentPoint = startMovePoint; // 如果当前点的命令为 Z,相当于当前点为最近一个 M 点,则下一个点直接指向最近一个 M 点的下一个点
6816
+
6817
+ nextParams = path[lastStartMovePointIndex + 1];
6818
+ } else {
6819
+ var len = params.length;
6820
+ currentPoint = [params[len - 2], params[len - 1]];
6681
6821
  }
6682
6822
 
6683
- var len = params.length;
6684
- currentPoint = [params[len - 2], params[len - 1]]; // @ts-ignore
6823
+ if (nextParams && nextParams[0] === 'Z') {
6824
+ // 如果下一个点的命令为 Z,则下一个点直接指向最近一个 M 点
6825
+ nextParams = path[lastStartMovePointIndex];
6826
+
6827
+ if (segments[lastStartMovePointIndex]) {
6828
+ // 如果下一个点的命令为 Z,则最近一个 M 点的前一个点为当前点
6829
+ segments[lastStartMovePointIndex].prePoint = currentPoint;
6830
+ }
6831
+ }
6685
6832
 
6686
6833
  segment.currentPoint = currentPoint; // 如果当前点与最近一个 M 点相同,则最近一个 M 点的前一个点为当前点的前一个点
6687
6834
 
@@ -6689,13 +6836,36 @@ function path2Segments(path) {
6689
6836
  segments[lastStartMovePointIndex].prePoint = segment.prePoint;
6690
6837
  }
6691
6838
 
6692
- var nextPoint = nextParams ? [nextParams[nextParams.length - 2], nextParams[nextParams.length - 1]] : null; // @ts-ignore
6693
-
6839
+ var nextPoint = nextParams ? [nextParams[nextParams.length - 2], nextParams[nextParams.length - 1]] : null;
6694
6840
  segment.nextPoint = nextPoint; // Add startTangent and endTangent
6695
6841
 
6696
6842
  var prePoint = segment.prePoint;
6697
6843
 
6698
- if (command === 'C') {
6844
+ if (['L', 'H', 'V'].includes(command)) {
6845
+ segment.startTangent = [prePoint[0] - currentPoint[0], prePoint[1] - currentPoint[1]];
6846
+ segment.endTangent = [currentPoint[0] - prePoint[0], currentPoint[1] - prePoint[1]];
6847
+ } else if (command === 'Q') {
6848
+ // 二次贝塞尔曲线只有一个控制点
6849
+ var cp = [params[1], params[2]]; // 二次贝塞尔曲线的终点为 currentPoint
6850
+
6851
+ segment.startTangent = [prePoint[0] - cp[0], prePoint[1] - cp[1]];
6852
+ segment.endTangent = [currentPoint[0] - cp[0], currentPoint[1] - cp[1]];
6853
+ } else if (command === 'T') {
6854
+ var preSegment = segments[i - 1];
6855
+
6856
+ var _cp = toSymmetry(preSegment.currentPoint, prePoint);
6857
+
6858
+ if (preSegment.command === 'Q') {
6859
+ segment.command = 'Q';
6860
+ segment.startTangent = [prePoint[0] - _cp[0], prePoint[1] - _cp[1]];
6861
+ segment.endTangent = [currentPoint[0] - _cp[0], currentPoint[1] - _cp[1]];
6862
+ } else {
6863
+ // @ts-ignore
6864
+ segment.command = 'TL';
6865
+ segment.startTangent = [prePoint[0] - currentPoint[0], prePoint[1] - currentPoint[1]];
6866
+ segment.endTangent = [currentPoint[0] - prePoint[0], currentPoint[1] - prePoint[1]];
6867
+ }
6868
+ } else if (command === 'C') {
6699
6869
  // 三次贝塞尔曲线有两个控制点
6700
6870
  var cp1 = [params[1], params[2]];
6701
6871
  var cp2 = [params[3], params[4]];
@@ -6709,25 +6879,155 @@ function path2Segments(path) {
6709
6879
  if (segment.endTangent[0] === 0 && segment.endTangent[1] === 0) {
6710
6880
  segment.endTangent = [cp2[0] - cp1[0], cp2[1] - cp1[1]];
6711
6881
  }
6882
+ } else if (command === 'S') {
6883
+ var _preSegment = segments[i - 1];
6884
+
6885
+ var _cp2 = toSymmetry(_preSegment.currentPoint, prePoint);
6886
+
6887
+ var _cp3 = [params[1], params[2]];
6888
+
6889
+ if (_preSegment.command === 'C') {
6890
+ segment.command = 'C'; // 将 S 命令变换为 C 命令
6891
+
6892
+ segment.startTangent = [prePoint[0] - _cp2[0], prePoint[1] - _cp2[1]];
6893
+ segment.endTangent = [currentPoint[0] - _cp3[0], currentPoint[1] - _cp3[1]];
6894
+ } else {
6895
+ // @ts-ignore
6896
+ segment.command = 'SQ'; // 将 S 命令变换为 SQ 命令
6897
+
6898
+ segment.startTangent = [prePoint[0] - _cp3[0], prePoint[1] - _cp3[1]];
6899
+ segment.endTangent = [currentPoint[0] - _cp3[0], currentPoint[1] - _cp3[1]];
6900
+ }
6901
+ } else if (command === 'A') {
6902
+ var d = 0.001;
6903
+
6904
+ var _ref = segment.arcParams || {},
6905
+ _ref$cx = _ref.cx,
6906
+ cx = _ref$cx === void 0 ? 0 : _ref$cx,
6907
+ _ref$cy = _ref.cy,
6908
+ cy = _ref$cy === void 0 ? 0 : _ref$cy,
6909
+ _ref$rx = _ref.rx,
6910
+ rx = _ref$rx === void 0 ? 0 : _ref$rx,
6911
+ _ref$ry = _ref.ry,
6912
+ ry = _ref$ry === void 0 ? 0 : _ref$ry,
6913
+ _ref$sweepFlag = _ref.sweepFlag,
6914
+ sweepFlag = _ref$sweepFlag === void 0 ? 0 : _ref$sweepFlag,
6915
+ _ref$startAngle = _ref.startAngle,
6916
+ startAngle = _ref$startAngle === void 0 ? 0 : _ref$startAngle,
6917
+ _ref$endAngle = _ref.endAngle,
6918
+ endAngle = _ref$endAngle === void 0 ? 0 : _ref$endAngle;
6919
+
6920
+ if (sweepFlag === 0) {
6921
+ d *= -1;
6922
+ }
6923
+
6924
+ var dx1 = rx * Math.cos(startAngle - d) + cx;
6925
+ var dy1 = ry * Math.sin(startAngle - d) + cy;
6926
+ segment.startTangent = [dx1 - startMovePoint[0], dy1 - startMovePoint[1]];
6927
+ var dx2 = rx * Math.cos(startAngle + endAngle + d) + cx;
6928
+ var dy2 = ry * Math.sin(startAngle + endAngle - d) + cy;
6929
+ segment.endTangent = [prePoint[0] - dx2, prePoint[1] - dy2];
6712
6930
  }
6713
6931
 
6714
6932
  segments.push(segment);
6715
6933
  }
6716
6934
 
6717
6935
  return segments;
6936
+ } // 向量长度
6937
+
6938
+ function vMag(v) {
6939
+ return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
6940
+ } // u.v/|u||v|,计算夹角的余弦值
6941
+
6942
+
6943
+ function vRatio(u, v) {
6944
+ // 当存在一个向量的长度为 0 时,夹角也为 0,即夹角的余弦值为 1
6945
+ return vMag(u) * vMag(v) ? (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v)) : 1;
6946
+ } // 向量角度
6947
+
6948
+
6949
+ function vAngle(u, v) {
6950
+ return (u[0] * v[1] < u[1] * v[0] ? -1 : 1) * Math.acos(vRatio(u, v));
6718
6951
  }
6719
6952
 
6720
- function commandsToPathString(commands, object, applyLocalTransform) {
6721
- if (applyLocalTransform === void 0) {
6722
- applyLocalTransform = true;
6953
+ function getArcParams(startPoint, params) {
6954
+ var rx = params[1];
6955
+ var ry = params[2];
6956
+ var xRotation = mod(deg2rad(params[3]), Math.PI * 2);
6957
+ var arcFlag = params[4];
6958
+ var sweepFlag = params[5]; // 弧形起点坐标
6959
+
6960
+ var x1 = startPoint[0];
6961
+ var y1 = startPoint[1]; // 弧形终点坐标
6962
+
6963
+ var x2 = params[6];
6964
+ var y2 = params[7];
6965
+ var xp = Math.cos(xRotation) * (x1 - x2) / 2.0 + Math.sin(xRotation) * (y1 - y2) / 2.0;
6966
+ var yp = -1 * Math.sin(xRotation) * (x1 - x2) / 2.0 + Math.cos(xRotation) * (y1 - y2) / 2.0;
6967
+ var lambda = xp * xp / (rx * rx) + yp * yp / (ry * ry);
6968
+
6969
+ if (lambda > 1) {
6970
+ rx *= Math.sqrt(lambda);
6971
+ ry *= Math.sqrt(lambda);
6723
6972
  }
6724
6973
 
6725
- var transform;
6974
+ var diff = rx * rx * (yp * yp) + ry * ry * (xp * xp);
6975
+ var f = diff ? Math.sqrt((rx * rx * (ry * ry) - diff) / diff) : 1;
6726
6976
 
6727
- if (applyLocalTransform) {
6728
- transform = object.getLocalTransform();
6977
+ if (arcFlag === sweepFlag) {
6978
+ f *= -1;
6979
+ }
6980
+
6981
+ if (isNaN(f)) {
6982
+ f = 0;
6983
+ } // 旋转前的起点坐标,且当长半轴和短半轴的长度为 0 时,坐标按 (0, 0) 处理
6984
+
6985
+
6986
+ var cxp = ry ? f * rx * yp / ry : 0;
6987
+ var cyp = rx ? f * -ry * xp / rx : 0; // 椭圆圆心坐标
6988
+
6989
+ var cx = (x1 + x2) / 2.0 + Math.cos(xRotation) * cxp - Math.sin(xRotation) * cyp;
6990
+ var cy = (y1 + y2) / 2.0 + Math.sin(xRotation) * cxp + Math.cos(xRotation) * cyp; // 起始点的单位向量
6991
+
6992
+ var u = [(xp - cxp) / rx, (yp - cyp) / ry]; // 终止点的单位向量
6993
+
6994
+ var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry]; // 计算起始点和圆心的连线,与 x 轴正方向的夹角
6995
+
6996
+ var theta = vAngle([1, 0], u); // 计算圆弧起始点和终止点与椭圆圆心连线的夹角
6997
+
6998
+ var dTheta = vAngle(u, v);
6999
+
7000
+ if (vRatio(u, v) <= -1) {
7001
+ dTheta = Math.PI;
7002
+ }
7003
+
7004
+ if (vRatio(u, v) >= 1) {
7005
+ dTheta = 0;
7006
+ }
7007
+
7008
+ if (sweepFlag === 0 && dTheta > 0) {
7009
+ dTheta = dTheta - 2 * Math.PI;
6729
7010
  }
6730
7011
 
7012
+ if (sweepFlag === 1 && dTheta < 0) {
7013
+ dTheta = dTheta + 2 * Math.PI;
7014
+ }
7015
+
7016
+ return {
7017
+ cx: cx,
7018
+ cy: cy,
7019
+ // 弧形的起点和终点相同时,长轴和短轴的长度按 0 处理
7020
+ rx: isSamePoint(startPoint, [x2, y2]) ? 0 : rx,
7021
+ ry: isSamePoint(startPoint, [x2, y2]) ? 0 : ry,
7022
+ startAngle: theta,
7023
+ endAngle: theta + dTheta,
7024
+ xRotation: xRotation,
7025
+ arcFlag: arcFlag,
7026
+ sweepFlag: sweepFlag
7027
+ };
7028
+ }
7029
+
7030
+ function commandsToPathString(commands, object, transform) {
6731
7031
  var _object$parsedStyle = object.parsedStyle,
6732
7032
  _object$parsedStyle$d = _object$parsedStyle.defX,
6733
7033
  defX = _object$parsedStyle$d === void 0 ? 0 : _object$parsedStyle$d,
@@ -6739,7 +7039,7 @@ function commandsToPathString(commands, object, applyLocalTransform) {
6739
7039
  if (cur[0] === 'M' || cur[0] === 'L') {
6740
7040
  var p = vec3.fromValues(cur[1] - defX, cur[2] - defY, 0);
6741
7041
 
6742
- if (applyLocalTransform) {
7042
+ if (transform) {
6743
7043
  vec3.transformMat4(p, p, transform);
6744
7044
  }
6745
7045
 
@@ -6751,7 +7051,7 @@ function commandsToPathString(commands, object, applyLocalTransform) {
6751
7051
  var p2 = vec3.fromValues(cur[3] - defX, cur[4] - defY, 0);
6752
7052
  var p3 = vec3.fromValues(cur[5] - defX, cur[6] - defY, 0);
6753
7053
 
6754
- if (applyLocalTransform) {
7054
+ if (transform) {
6755
7055
  vec3.transformMat4(p1, p1, transform);
6756
7056
  vec3.transformMat4(p2, p2, transform);
6757
7057
  vec3.transformMat4(p3, p3, transform);
@@ -6761,7 +7061,7 @@ function commandsToPathString(commands, object, applyLocalTransform) {
6761
7061
  } else if (cur[0] === 'A') {
6762
7062
  var c = vec3.fromValues(cur[6] - defX, cur[7] - defY, 0);
6763
7063
 
6764
- if (applyLocalTransform) {
7064
+ if (transform) {
6765
7065
  vec3.transformMat4(c, c, transform);
6766
7066
  }
6767
7067
 
@@ -6825,9 +7125,9 @@ function rectToCommands(width, height, x, y, radius) {
6825
7125
  */
6826
7126
 
6827
7127
 
6828
- function convertToPath(object, applyLocalTransform) {
6829
- if (applyLocalTransform === void 0) {
6830
- applyLocalTransform = true;
7128
+ function convertToPath(object, transform) {
7129
+ if (transform === void 0) {
7130
+ transform = object.getLocalTransform();
6831
7131
  }
6832
7132
 
6833
7133
  var commands = [];
@@ -6896,7 +7196,7 @@ function convertToPath(object, applyLocalTransform) {
6896
7196
  }
6897
7197
 
6898
7198
  if (commands.length) {
6899
- return commandsToPathString(commands, object, applyLocalTransform);
7199
+ return commandsToPathString(commands, object, transform);
6900
7200
  }
6901
7201
  }
6902
7202
  function translatePathToString(pathArray, x, y, startOffsetX, startOffsetY, endOffsetX, endOffsetY) {
@@ -6917,8 +7217,7 @@ function translatePathToString(pathArray, x, y, startOffsetX, startOffsetY, endO
6917
7217
  }
6918
7218
 
6919
7219
  var newValue = pathArray.map(function (params, i) {
6920
- var command = params[0]; // @ts-ignore
6921
-
7220
+ var command = params[0];
6922
7221
  var isClosed = pathArray[pathArray.length - 1][0] === 'Z';
6923
7222
  var offsetX = i === pathArray.length - (isClosed ? 2 : 1) ? endOffsetX : 0;
6924
7223
  var offsetY = i === pathArray.length - (isClosed ? 2 : 1) ? endOffsetY : 0;
@@ -8560,7 +8859,7 @@ var BUILT_IN_PROPERTIES = [{
8560
8859
  n: 'textAlign',
8561
8860
  l: true,
8562
8861
  inh: true,
8563
- k: ['start', 'center', 'end', 'left', 'right'],
8862
+ k: ['start', 'center', 'middle', 'end', 'left', 'right'],
8564
8863
  d: 'start'
8565
8864
  }, // {
8566
8865
  // n: 'whiteSpace',
@@ -8672,12 +8971,10 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
8672
8971
  attributeNames.forEach(function (attributeName) {
8673
8972
  var _propertyMetadataCach;
8674
8973
 
8675
- var _formatAttribute = formatAttribute(attributeName, attributes[attributeName]),
8676
- name = _formatAttribute[0],
8677
- value = _formatAttribute[1];
8974
+ var name = formatAttributeName(attributeName);
8678
8975
 
8679
8976
  if (!skipUpdateAttribute) {
8680
- object.attributes[name] = value;
8977
+ object.attributes[name] = attributes[attributeName];
8681
8978
  }
8682
8979
 
8683
8980
  if (!needUpdateGeometry && ((_propertyMetadataCach = propertyMetadataCache[name]) === null || _propertyMetadataCach === void 0 ? void 0 : _propertyMetadataCach.l)) {
@@ -9461,7 +9758,11 @@ var EventTarget = /*#__PURE__*/function () {
9461
9758
  */
9462
9759
  ;
9463
9760
 
9464
- _proto.dispatchEvent = function dispatchEvent(e) {
9761
+ _proto.dispatchEvent = function dispatchEvent(e, skipPropagate) {
9762
+ if (skipPropagate === void 0) {
9763
+ skipPropagate = false;
9764
+ }
9765
+
9465
9766
  if (!(e instanceof FederatedEvent)) {
9466
9767
  throw new Error('DisplayObject cannot propagate events outside of the Federated Events API');
9467
9768
  } // should account for Element / Document / Canvas
@@ -9491,8 +9792,12 @@ var EventTarget = /*#__PURE__*/function () {
9491
9792
 
9492
9793
  e.defaultPrevented = false;
9493
9794
  e.path = [];
9494
- e.target = this;
9495
- (_e$manager = e.manager) === null || _e$manager === void 0 ? void 0 : _e$manager.dispatchEvent(e);
9795
+
9796
+ if (!skipPropagate) {
9797
+ e.target = this;
9798
+ }
9799
+
9800
+ (_e$manager = e.manager) === null || _e$manager === void 0 ? void 0 : _e$manager.dispatchEvent(e, e.type, skipPropagate);
9496
9801
  }
9497
9802
 
9498
9803
  return !e.defaultPrevented;
@@ -10812,9 +11117,7 @@ var Element = /*#__PURE__*/function (_Node) {
10812
11117
  var value = this.attributes[name];
10813
11118
 
10814
11119
  if (value === undefined) {
10815
- var _formatAttribute = formatAttribute(name, ''),
10816
- attributeName = _formatAttribute[0];
10817
-
11120
+ var attributeName = formatAttributeName(name);
10818
11121
  value = this.attributes[attributeName]; // if the given attribute does not exist, the value returned will either be null or ""
10819
11122
 
10820
11123
  return isNil(value) ? null : value;
@@ -11223,6 +11526,7 @@ var DEFAULT_PARSED_STYLE_PROPS = {
11223
11526
  filter: [],
11224
11527
  shadowType: 'outer'
11225
11528
  };
11529
+ var INHERITABLE_STYLE_PROPS = ['opacity', 'fillOpacity', 'strokeOpacity', 'transformOrigin', 'visibility', 'pointerEvents', 'lineWidth', 'lineCap', 'lineJoin', 'increasedLineWidthForHitTesting', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'textAlign', 'textBaseline', 'textTransform'];
11226
11530
  /**
11227
11531
  * prototype chains: DisplayObject -> Element -> Node -> EventTarget
11228
11532
  *
@@ -11262,6 +11566,7 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
11262
11566
 
11263
11567
  _this.config = void 0;
11264
11568
  _this.isCustomElement = false;
11569
+ _this.isMutationObserved = false;
11265
11570
  _this.activeAnimations = [];
11266
11571
 
11267
11572
  _this.getClip = function () {
@@ -11396,14 +11701,7 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
11396
11701
 
11397
11702
  runtime.styleValueRegistry.processProperties(this, attributes, {
11398
11703
  forceUpdateGeometry: true,
11399
- usedAttributes: [// 'anchor',
11400
- // 'transform',
11401
- // 'zIndex',
11402
- // 'filter',
11403
- // 'shadowType',
11404
- // 'fill',
11405
- // 'stroke',
11406
- 'opacity', 'fillOpacity', 'strokeOpacity', 'transformOrigin', 'visibility', 'pointerEvents', 'lineWidth', 'lineCap', 'lineJoin', 'increasedLineWidthForHitTesting', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'textAlign', 'textBaseline', 'textTransform']
11704
+ usedAttributes: INHERITABLE_STYLE_PROPS
11407
11705
  }); // redraw at next frame
11408
11706
 
11409
11707
  renderable.dirty = true;
@@ -11414,19 +11712,16 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
11414
11712
  force = false;
11415
11713
  }
11416
11714
 
11417
- var _formatAttribute = formatAttribute(name, value),
11418
- attributeName = _formatAttribute[0],
11419
- attributeValue = _formatAttribute[1]; // ignore undefined value
11420
-
11715
+ var attributeName = formatAttributeName(name); // ignore undefined value
11421
11716
 
11422
11717
  if (isUndefined(value)) {
11423
11718
  return;
11424
11719
  }
11425
11720
 
11426
- if (force || attributeValue !== this.attributes[attributeName]) {
11427
- this.internalSetAttribute(attributeName, attributeValue);
11721
+ if (force || value !== this.attributes[attributeName]) {
11722
+ this.internalSetAttribute(attributeName, value);
11428
11723
 
11429
- _Element.prototype.setAttribute.call(this, attributeName, attributeValue);
11724
+ _Element.prototype.setAttribute.call(this, attributeName, value);
11430
11725
  }
11431
11726
  }
11432
11727
  /**
@@ -11456,7 +11751,13 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
11456
11751
  mutationEvent.attrName = name;
11457
11752
  mutationEvent.prevParsedValue = oldParsedValue;
11458
11753
  mutationEvent.newParsedValue = newParsedValue;
11459
- this.dispatchEvent(mutationEvent);
11754
+
11755
+ if (this.isMutationObserved) {
11756
+ this.dispatchEvent(mutationEvent);
11757
+ } else {
11758
+ mutationEvent.target = this;
11759
+ this.ownerDocument.defaultView.dispatchEvent(mutationEvent, true);
11760
+ }
11460
11761
  }
11461
11762
 
11462
11763
  if ((this.isCustomElement && this.isConnected || !this.isCustomElement) && this.attributeChangedCallback) {
@@ -12513,7 +12814,11 @@ var Line = /*#__PURE__*/function (_DisplayObject) {
12513
12814
  marker.setLocalPosition(ox + Math.cos(rad) * offset, oy + Math.sin(rad) * offset);
12514
12815
  };
12515
12816
 
12516
- _proto.getPoint = function getPoint(ratio) {
12817
+ _proto.getPoint = function getPoint(ratio, inWorldSpace) {
12818
+ if (inWorldSpace === void 0) {
12819
+ inWorldSpace = false;
12820
+ }
12821
+
12517
12822
  // TODO: account for z1/z2 in 3D line
12518
12823
  var _this$parsedStyle3 = this.parsedStyle,
12519
12824
  x1 = _this$parsedStyle3.x1,
@@ -12527,13 +12832,17 @@ var Line = /*#__PURE__*/function (_DisplayObject) {
12527
12832
  x = _LineUtil$pointAt.x,
12528
12833
  y = _LineUtil$pointAt.y;
12529
12834
 
12530
- var transformed = vec3.transformMat4(vec3.create(), vec3.fromValues(x - defX, y - defY, 0), this.getLocalTransform()); // apply local transformation
12835
+ var transformed = vec3.transformMat4(vec3.create(), vec3.fromValues(x - defX, y - defY, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform()); // apply local transformation
12531
12836
 
12532
12837
  return new Point(transformed[0], transformed[1]);
12533
12838
  };
12534
12839
 
12535
- _proto.getPointAtLength = function getPointAtLength(distance) {
12536
- return this.getPoint(distance / this.getTotalLength());
12840
+ _proto.getPointAtLength = function getPointAtLength(distance, inWorldSpace) {
12841
+ if (inWorldSpace === void 0) {
12842
+ inWorldSpace = false;
12843
+ }
12844
+
12845
+ return this.getPoint(distance / this.getTotalLength(), inWorldSpace);
12537
12846
  };
12538
12847
 
12539
12848
  _proto.getTotalLength = function getTotalLength() {
@@ -12730,7 +13039,11 @@ var Path = /*#__PURE__*/function (_DisplayObject) {
12730
13039
  */
12731
13040
  ;
12732
13041
 
12733
- _proto.getPointAtLength = function getPointAtLength$1(distance) {
13042
+ _proto.getPointAtLength = function getPointAtLength$1(distance, inWorldSpace) {
13043
+ if (inWorldSpace === void 0) {
13044
+ inWorldSpace = false;
13045
+ }
13046
+
12734
13047
  var _this$parsedStyle4 = this.parsedStyle,
12735
13048
  defX = _this$parsedStyle4.defX,
12736
13049
  defY = _this$parsedStyle4.defY,
@@ -12740,7 +13053,7 @@ var Path = /*#__PURE__*/function (_DisplayObject) {
12740
13053
  x = _getPointAtLength2.x,
12741
13054
  y = _getPointAtLength2.y;
12742
13055
 
12743
- var transformed = vec3.transformMat4(vec3.create(), vec3.fromValues(x - defX, y - defY, 0), this.getLocalTransform()); // apply local transformation
13056
+ var transformed = vec3.transformMat4(vec3.create(), vec3.fromValues(x - defX, y - defY, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform()); // apply local transformation
12744
13057
 
12745
13058
  return new Point(transformed[0], transformed[1]);
12746
13059
  }
@@ -12749,8 +13062,12 @@ var Path = /*#__PURE__*/function (_DisplayObject) {
12749
13062
  */
12750
13063
  ;
12751
13064
 
12752
- _proto.getPoint = function getPoint(ratio) {
12753
- return this.getPointAtLength(ratio * getOrCalculatePathTotalLength(this));
13065
+ _proto.getPoint = function getPoint(ratio, inWorldSpace) {
13066
+ if (inWorldSpace === void 0) {
13067
+ inWorldSpace = false;
13068
+ }
13069
+
13070
+ return this.getPointAtLength(ratio * getOrCalculatePathTotalLength(this), inWorldSpace);
12754
13071
  }
12755
13072
  /**
12756
13073
  * Get start tangent vector
@@ -13009,11 +13326,19 @@ var Polyline = /*#__PURE__*/function (_Polygon) {
13009
13326
  return this.parsedStyle.points.totalLength;
13010
13327
  };
13011
13328
 
13012
- _proto.getPointAtLength = function getPointAtLength(distance) {
13013
- return this.getPoint(distance / this.getTotalLength());
13329
+ _proto.getPointAtLength = function getPointAtLength(distance, inWorldSpace) {
13330
+ if (inWorldSpace === void 0) {
13331
+ inWorldSpace = false;
13332
+ }
13333
+
13334
+ return this.getPoint(distance / this.getTotalLength(), inWorldSpace);
13014
13335
  };
13015
13336
 
13016
- _proto.getPoint = function getPoint(ratio) {
13337
+ _proto.getPoint = function getPoint(ratio, inWorldSpace) {
13338
+ if (inWorldSpace === void 0) {
13339
+ inWorldSpace = false;
13340
+ }
13341
+
13017
13342
  var _this$parsedStyle = this.parsedStyle,
13018
13343
  defX = _this$parsedStyle.defX,
13019
13344
  defY = _this$parsedStyle.defY,
@@ -13033,7 +13358,7 @@ var Polyline = /*#__PURE__*/function (_Polygon) {
13033
13358
  x = _LineUtil$pointAt.x,
13034
13359
  y = _LineUtil$pointAt.y;
13035
13360
 
13036
- var transformed = vec3.transformMat4(vec3.create(), vec3.fromValues(x - defX, y - defY, 0), this.getLocalTransform()); // apply local transformation
13361
+ var transformed = vec3.transformMat4(vec3.create(), vec3.fromValues(x - defX, y - defY, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform()); // apply local transformation
13037
13362
 
13038
13363
  return new Point(transformed[0], transformed[1]);
13039
13364
  };
@@ -14230,7 +14555,7 @@ var TextUpdater = /*#__PURE__*/function () {
14230
14555
  var anchor = [0, 1];
14231
14556
  var lineXOffset = 0;
14232
14557
 
14233
- if (textAlign === 'center') {
14558
+ if (textAlign === 'center' || textAlign === 'middle') {
14234
14559
  lineXOffset = lineWidth / 2;
14235
14560
  anchor = [0.5, 1];
14236
14561
  } else if (textAlign === 'right' || textAlign === 'end') {
@@ -14955,10 +15280,20 @@ var EventService = /*#__PURE__*/function () {
14955
15280
  }
14956
15281
  };
14957
15282
 
14958
- _proto.dispatchEvent = function dispatchEvent(e, type) {
14959
- e.propagationStopped = false;
14960
- e.propagationImmediatelyStopped = false;
14961
- this.propagate(e, type);
15283
+ _proto.dispatchEvent = function dispatchEvent(e, type, skipPropagate) {
15284
+ // Canvas should skip
15285
+ if (!skipPropagate) {
15286
+ e.propagationStopped = false;
15287
+ e.propagationImmediatelyStopped = false;
15288
+ this.propagate(e, type);
15289
+ } else {
15290
+ // target phase
15291
+ e.eventPhase = e.AT_TARGET;
15292
+ var canvas = this.rootTarget.defaultView || null;
15293
+ e.currentTarget = canvas;
15294
+ this.notifyListeners(e, type);
15295
+ }
15296
+
14962
15297
  this.emitter.emit(type || e.type, e);
14963
15298
  };
14964
15299
 
@@ -15765,10 +16100,11 @@ var RenderingService = /*#__PURE__*/function () {
15765
16100
 
15766
16101
  if (renderOrderChanged) {
15767
16102
  displayObject.forEach(function (child) {
16103
+ _this2.renderOrderChangedEvent.target = child;
15768
16104
  _this2.renderOrderChangedEvent.detail = {
15769
16105
  renderOrder: child.sortable.renderOrder
15770
16106
  };
15771
- child.dispatchEvent(_this2.renderOrderChangedEvent);
16107
+ child.ownerDocument.defaultView.dispatchEvent(_this2.renderOrderChangedEvent, true);
15772
16108
  });
15773
16109
  }
15774
16110
  };
@@ -16429,9 +16765,10 @@ var DefaultSceneGraphService = /*#__PURE__*/function () {
16429
16765
  var set = new Set();
16430
16766
 
16431
16767
  var trigger = function trigger(element, detail) {
16432
- if (!set.has(element.entity)) {
16768
+ if (element.isConnected && !set.has(element.entity)) {
16433
16769
  _this2.boundsChangedEvent.detail = detail;
16434
- element.dispatchEvent(_this2.boundsChangedEvent);
16770
+ _this2.boundsChangedEvent.target = element;
16771
+ element.ownerDocument.defaultView.dispatchEvent(_this2.boundsChangedEvent, true);
16435
16772
  set.add(element.entity);
16436
16773
  }
16437
16774
  };
@@ -16449,6 +16786,7 @@ var DefaultSceneGraphService = /*#__PURE__*/function () {
16449
16786
  }
16450
16787
  });
16451
16788
  this.pendingEvents = [];
16789
+ set.clear();
16452
16790
  };
16453
16791
 
16454
16792
  _proto.dirtifyToRoot = function dirtifyToRoot(element, affectChildren) {
@@ -17099,7 +17437,7 @@ var TextService = /*#__PURE__*/function () {
17099
17437
  lineMetrics: lineWidths.map(function (width, i) {
17100
17438
  var offsetX = 0; // handle horizontal text align
17101
17439
 
17102
- if (textAlign === 'center') {
17440
+ if (textAlign === 'center' || textAlign === 'middle') {
17103
17441
  offsetX -= width / 2;
17104
17442
  } else if (textAlign === 'right' || textAlign === 'end') {
17105
17443
  offsetX -= width;
@@ -17929,21 +18267,14 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
17929
18267
 
17930
18268
  var _proto = PrepareRendererPlugin.prototype;
17931
18269
 
17932
- _proto.pushToSync = function pushToSync(list) {
17933
- var _this = this;
17934
-
17935
- list.forEach(function (i) {
17936
- _this.toSync.add(i);
17937
- });
17938
- } // private isFirstTimeRendering = true;
17939
- ;
17940
-
18270
+ // private isFirstTimeRendering = true;
17941
18271
  _proto.apply = function apply(context) {
17942
- var _this2 = this;
18272
+ var _this = this;
17943
18273
 
17944
18274
  var renderingService = context.renderingService,
17945
18275
  renderingContext = context.renderingContext,
17946
18276
  rBushRoot = context.rBushRoot;
18277
+ var canvas = renderingContext.root.ownerDocument.defaultView;
17947
18278
  this.rBush = rBushRoot;
17948
18279
 
17949
18280
  var handleAttributeChanged = function handleAttributeChanged(e) {
@@ -17958,20 +18289,26 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
17958
18289
 
17959
18290
  if (affectChildren) {
17960
18291
  object.forEach(function (node) {
17961
- _this2.pushToSync([node]);
18292
+ _this.toSync.add(node);
17962
18293
  });
17963
18294
  }
17964
18295
 
17965
- _this2.pushToSync(e.composedPath().slice(0, -2));
18296
+ var p = object;
18297
+
18298
+ while (p) {
18299
+ if (p.renderable) {
18300
+ _this.toSync.add(p);
18301
+ }
18302
+
18303
+ p = p.parentElement;
18304
+ } // this.pushToSync(e.composedPath().slice(0, -2) as DisplayObject[]);
18305
+
17966
18306
 
17967
18307
  renderingService.dirtify();
17968
18308
  };
17969
18309
 
17970
18310
  var handleMounted = function handleMounted(e) {
17971
- var object = e.target;
17972
-
17973
- _this2.pushToSync(e.composedPath().slice(0, -2)); // recalc style values
17974
-
18311
+ var object = e.target; // recalc style values
17975
18312
 
17976
18313
  runtime.styleValueRegistry.recalc(object);
17977
18314
  runtime.sceneGraphService.dirtifyToRoot(object);
@@ -17983,12 +18320,12 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
17983
18320
  var rBushNode = object.rBushNode;
17984
18321
 
17985
18322
  if (rBushNode.aabb) {
17986
- _this2.rBush.remove(rBushNode.aabb);
18323
+ _this.rBush.remove(rBushNode.aabb);
17987
18324
  }
17988
18325
 
17989
- _this2.toSync.delete(object);
18326
+ _this.toSync.delete(object);
17990
18327
 
17991
- runtime.sceneGraphService.dirtifyToRoot(e.target);
18328
+ runtime.sceneGraphService.dirtifyToRoot(object);
17992
18329
  renderingService.dirtify();
17993
18330
  };
17994
18331
 
@@ -17997,10 +18334,10 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
17997
18334
  while (1) {
17998
18335
  switch (_context.prev = _context.next) {
17999
18336
  case 0:
18000
- renderingContext.root.addEventListener(ElementEvent.MOUNTED, handleMounted);
18001
- renderingContext.root.addEventListener(ElementEvent.UNMOUNTED, handleUnmounted);
18002
- renderingContext.root.addEventListener(ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
18003
- renderingContext.root.addEventListener(ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
18337
+ canvas.addEventListener(ElementEvent.MOUNTED, handleMounted);
18338
+ canvas.addEventListener(ElementEvent.UNMOUNTED, handleUnmounted);
18339
+ canvas.addEventListener(ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
18340
+ canvas.addEventListener(ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
18004
18341
 
18005
18342
  case 4:
18006
18343
  case "end":
@@ -18010,10 +18347,10 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
18010
18347
  }, _callee);
18011
18348
  })));
18012
18349
  renderingService.hooks.destroy.tap(PrepareRendererPlugin.tag, function () {
18013
- renderingContext.root.removeEventListener(ElementEvent.MOUNTED, handleMounted);
18014
- renderingContext.root.removeEventListener(ElementEvent.UNMOUNTED, handleUnmounted);
18015
- renderingContext.root.removeEventListener(ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
18016
- renderingContext.root.removeEventListener(ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
18350
+ canvas.removeEventListener(ElementEvent.MOUNTED, handleMounted);
18351
+ canvas.removeEventListener(ElementEvent.UNMOUNTED, handleUnmounted);
18352
+ canvas.removeEventListener(ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
18353
+ canvas.removeEventListener(ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
18017
18354
  });
18018
18355
  renderingService.hooks.endFrame.tap(PrepareRendererPlugin.tag, function () {
18019
18356
  // if (this.isFirstTimeRendering) {
@@ -18023,12 +18360,12 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
18023
18360
  // } else {
18024
18361
  // this.syncRTree();
18025
18362
  // }
18026
- _this2.syncRTree();
18363
+ _this.syncRTree();
18027
18364
  });
18028
18365
  };
18029
18366
 
18030
18367
  _proto.syncRTree = function syncRTree() {
18031
- var _this3 = this;
18368
+ var _this2 = this;
18032
18369
 
18033
18370
  // bounds changed, need re-inserting its children
18034
18371
  var bulk = [];
@@ -18039,7 +18376,7 @@ var PrepareRendererPlugin = /*#__PURE__*/function () {
18039
18376
  var rBushNode = node.rBushNode; // clear dirty node
18040
18377
 
18041
18378
  if (rBushNode && rBushNode.aabb) {
18042
- _this3.rBush.remove(rBushNode.aabb);
18379
+ _this2.rBush.remove(rBushNode.aabb);
18043
18380
  }
18044
18381
 
18045
18382
  var renderBounds = node.getRenderBounds();
@@ -18102,8 +18439,8 @@ var DEFAULT_CAMERA_FAR = 1000;
18102
18439
  * reuse custom event preventing from re-create them in every frame
18103
18440
  */
18104
18441
 
18105
- var mountEvent = new CustomEvent(ElementEvent.MOUNTED);
18106
- var unmountEvent = new CustomEvent(ElementEvent.UNMOUNTED);
18442
+ var mountedEvent = new CustomEvent(ElementEvent.MOUNTED);
18443
+ var unmountedEvent = new CustomEvent(ElementEvent.UNMOUNTED);
18107
18444
  var beforeRenderEvent = new CustomEvent(CanvasEvent.BEFORE_RENDER);
18108
18445
  var afterRenderEvent = new CustomEvent(CanvasEvent.AFTER_RENDER);
18109
18446
  /**
@@ -18618,13 +18955,20 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
18618
18955
 
18619
18956
  path.reverse().forEach(function (child) {
18620
18957
  // trigger before unmounted
18621
- if (child instanceof CustomElement) {
18958
+ if (child.isCustomElement) {
18622
18959
  if (child.disconnectedCallback) {
18623
18960
  child.disconnectedCallback();
18624
18961
  }
18625
18962
  }
18626
18963
 
18627
- child.dispatchEvent(unmountEvent); // skip document.documentElement
18964
+ if (child.isMutationObserved) {
18965
+ child.dispatchEvent(unmountedEvent);
18966
+ } else {
18967
+ unmountedEvent.target = child;
18968
+
18969
+ _this5.dispatchEvent(unmountedEvent, true);
18970
+ } // skip document.documentElement
18971
+
18628
18972
 
18629
18973
  if (child !== _this5.document.documentElement) {
18630
18974
  child.ownerDocument = null;
@@ -18643,9 +18987,17 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
18643
18987
  if (!child.isConnected) {
18644
18988
  child.ownerDocument = _this6.document;
18645
18989
  child.isConnected = true;
18646
- child.dispatchEvent(mountEvent); // trigger after mounted
18647
18990
 
18648
- if (child instanceof CustomElement) {
18991
+ if (child.isMutationObserved) {
18992
+ child.dispatchEvent(mountedEvent);
18993
+ } else {
18994
+ mountedEvent.target = child;
18995
+
18996
+ _this6.dispatchEvent(mountedEvent, true);
18997
+ } // trigger after mounted
18998
+
18999
+
19000
+ if (child.isCustomElement) {
18649
19001
  if (child.connectedCallback) {
18650
19002
  child.connectedCallback();
18651
19003
  }
@@ -18721,4 +19073,4 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
18721
19073
  return Canvas;
18722
19074
  }(EventTarget);
18723
19075
 
18724
- export { AABB, AbstractRenderer, AbstractRendererPlugin, BUILT_IN_PROPERTIES, CSS, CSSGradientValue, CSSKeywordValue, CSSRGB, CSSStyleValue, CSSUnitValue, Camera, CameraEvent, CameraProjectionMode, CameraTrackingMode, CameraType, Canvas, CanvasEvent, Circle, CircleUpdater, CustomElement, CustomElementRegistry, CustomEvent, DefaultSceneGraphSelector, DefaultSceneGraphService, DisplayObject, DisplayObjectPool, Document, ERROR_MSG_METHOD_NOT_IMPLEMENTED, Element, ElementEvent, Ellipse, EllipseUpdater, EventService, EventTarget, FederatedEvent, FederatedMouseEvent, FederatedPointerEvent, FederatedWheelEvent, Frustum, GradientType, Group, HTML, Image, Line, LineUpdater, Mask, MutationEvent, Node, OffscreenCanvasCreator, Path, PathUpdater, Plane, Point, Polygon, Polyline, PolylineUpdater, PropertySyntax, Rect, RectUpdater, Rectangle, RenderReason, RenderingService, Shape, Strategy, Text, TextService, TextUpdater, UnitType, computeLinearGradient, computeRadialGradient, convertToPath, createVec3, decompose, definedProps, deg2rad, deg2turn, findClosestClipPathTarget, getAngle, getEuler, getOrCalculatePathTotalLength, grad2deg, isBrowser, isFillOrStrokeAffected, isPattern, mergeColors, parseColor, parseLength, parsePath, propertyMetadataCache, rad2deg, resetEntityCounter, runtime, setDOMSize, translatePathToString, turn2deg };
19076
+ export { AABB, AbstractRenderer, AbstractRendererPlugin, BUILT_IN_PROPERTIES, CSS, CSSGradientValue, CSSKeywordValue, CSSRGB, CSSStyleValue, CSSUnitValue, Camera, CameraEvent, CameraProjectionMode, CameraTrackingMode, CameraType, Canvas, CanvasEvent, Circle, CircleUpdater, CustomElement, CustomElementRegistry, CustomEvent, DefaultSceneGraphSelector, DefaultSceneGraphService, DisplayObject, DisplayObjectPool, Document, ERROR_MSG_METHOD_NOT_IMPLEMENTED, Element, ElementEvent, Ellipse, EllipseUpdater, EventService, EventTarget, FederatedEvent, FederatedMouseEvent, FederatedPointerEvent, FederatedWheelEvent, Frustum, GradientType, Group, HTML, Image, Line, LineUpdater, Mask, MutationEvent, Node, OffscreenCanvasCreator, Path, PathUpdater, Plane, Point, Polygon, Polyline, PolylineUpdater, PropertySyntax, Rect, RectUpdater, Rectangle, RenderReason, RenderingService, Shape, Strategy, Text, TextService, TextUpdater, UnitType, computeLinearGradient, computeRadialGradient, convertToPath, createVec3, decompose, definedProps, deg2rad, deg2turn, findClosestClipPathTarget, fromRotationTranslationScale, getAngle, getEuler, getOrCalculatePathTotalLength, grad2deg, isBrowser, isFillOrStrokeAffected, isPattern, mergeColors, parseColor, parseLength, parsePath, propertyMetadataCache, rad2deg, resetEntityCounter, runtime, setDOMSize, translatePathToString, turn2deg };