@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.umd.js CHANGED
@@ -5141,40 +5141,6 @@
5141
5141
  };
5142
5142
  }
5143
5143
 
5144
- /**
5145
- * Returns the bounding box of a shape.
5146
- */
5147
- function getPathBBox(path, options) {
5148
- if (!path) {
5149
- return {
5150
- x: 0,
5151
- y: 0,
5152
- width: 0,
5153
- height: 0,
5154
- x2: 0,
5155
- y2: 0,
5156
- cx: 0,
5157
- cy: 0,
5158
- cz: 0,
5159
- };
5160
- }
5161
- var _a = pathLengthFactory(path, undefined, __assign(__assign({}, options), { length: false })), _b = _a.min, xMin = _b.x, yMin = _b.y, _c = _a.max, xMax = _c.x, yMax = _c.y;
5162
- var width = xMax - xMin;
5163
- var height = yMax - yMin;
5164
- return {
5165
- width: width,
5166
- height: height,
5167
- x: xMin,
5168
- y: yMin,
5169
- x2: xMax,
5170
- y2: yMax,
5171
- cx: xMin + width / 2,
5172
- cy: yMin + height / 2,
5173
- // an estimted guess
5174
- cz: Math.max(width, height) + Math.min(width, height) / 2,
5175
- };
5176
- }
5177
-
5178
5144
  /**
5179
5145
  * Returns the shape total length, or the equivalent to `shape.getTotalLength()`.
5180
5146
  *
@@ -5376,16 +5342,11 @@
5376
5342
  return result[0].length === result[1].length ? result : equalizeSegments(result[0], result[1], tl);
5377
5343
  }
5378
5344
 
5379
- var toString = {}.toString;
5380
- var isType = function (value, type) { return toString.call(value) === '[object ' + type + ']'; };
5381
-
5382
5345
  /**
5383
- * 是否为函数
5384
- * @param {*} fn 对象
5385
- * @return {Boolean} 是否函数
5346
+ * @see https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_isfunction
5386
5347
  */
5387
5348
  var isFunction = (function (value) {
5388
- return isType(value, 'Function');
5349
+ return typeof value === 'function';
5389
5350
  });
5390
5351
 
5391
5352
  // isFinite,
@@ -5397,6 +5358,13 @@
5397
5358
  return value === null || value === undefined;
5398
5359
  };
5399
5360
 
5361
+ var toString = {}.toString;
5362
+ var isType = function (value, type) { return toString.call(value) === '[object ' + type + ']'; };
5363
+
5364
+ var isArray = (function (value) {
5365
+ return Array.isArray ? Array.isArray(value) : isType(value, 'Array');
5366
+ });
5367
+
5400
5368
  var isObject = (function (value) {
5401
5369
  /**
5402
5370
  * isObject({}) => true
@@ -5408,6 +5376,58 @@
5408
5376
  return (value !== null && type === 'object') || type === 'function';
5409
5377
  });
5410
5378
 
5379
+ /**
5380
+ * @param {Array} arr The array to iterate over.
5381
+ * @return {*} Returns the maximum value.
5382
+ * @example
5383
+ *
5384
+ * max([1, 2]);
5385
+ * // => 2
5386
+ *
5387
+ * max([]);
5388
+ * // => undefined
5389
+ *
5390
+ * const data = new Array(1250010).fill(1).map((d,idx) => idx);
5391
+ *
5392
+ * max(data);
5393
+ * // => 1250010
5394
+ * // Math.max(...data) will encounter "Maximum call stack size exceeded" error
5395
+ */
5396
+ var max$1 = (function (arr) {
5397
+ if (!isArray(arr)) {
5398
+ return undefined;
5399
+ }
5400
+ return arr.reduce(function (prev, curr) {
5401
+ return Math.max(prev, curr);
5402
+ }, arr[0]);
5403
+ });
5404
+
5405
+ /**
5406
+ * @param {Array} arr The array to iterate over.
5407
+ * @return {*} Returns the minimum value.
5408
+ * @example
5409
+ *
5410
+ * min([1, 2]);
5411
+ * // => 1
5412
+ *
5413
+ * min([]);
5414
+ * // => undefined
5415
+ *
5416
+ * const data = new Array(1250010).fill(1).map((d,idx) => idx);
5417
+ *
5418
+ * min(data);
5419
+ * // => 1250010
5420
+ * // Math.min(...data) will encounter "Maximum call stack size exceeded" error
5421
+ */
5422
+ var min$1 = (function (arr) {
5423
+ if (!isArray(arr)) {
5424
+ return undefined;
5425
+ }
5426
+ return arr.reduce(function (prev, curr) {
5427
+ return Math.min(prev, curr);
5428
+ }, arr[0]);
5429
+ });
5430
+
5411
5431
  var isString = (function (str) {
5412
5432
  return isType(str, 'String');
5413
5433
  });
@@ -5430,6 +5450,16 @@
5430
5450
  return isType(value, 'Number');
5431
5451
  };
5432
5452
 
5453
+ var PRECISION = 0.00001; // numbers less than this is considered as 0
5454
+ function isNumberEqual(a, b, precision) {
5455
+ if (precision === void 0) { precision = PRECISION; }
5456
+ return Math.abs(a - b) < precision;
5457
+ }
5458
+
5459
+ var mod = function (n, m) {
5460
+ return ((n % m) + m) % m;
5461
+ };
5462
+
5433
5463
  /**
5434
5464
  * 是否是布尔类型
5435
5465
  *
@@ -5945,10 +5975,7 @@
5945
5975
  alias: 'lineWidth'
5946
5976
  },
5947
5977
  textAnchor: {
5948
- alias: 'textAlign',
5949
- values: {
5950
- middle: 'center'
5951
- }
5978
+ alias: 'textAlign'
5952
5979
  },
5953
5980
  src: {
5954
5981
  alias: 'img'
@@ -5958,18 +5985,8 @@
5958
5985
  var attributeName = camelCase(name);
5959
5986
  var map = FORMAT_ATTR_MAP[attributeName];
5960
5987
  attributeName = (map === null || map === void 0 ? void 0 : map.alias) || attributeName;
5961
- return [attributeName, map];
5988
+ return attributeName;
5962
5989
  });
5963
- function formatAttribute(name, value) {
5964
- var _map$values;
5965
-
5966
- var _formatAttributeName = formatAttributeName(name),
5967
- attributeName = _formatAttributeName[0],
5968
- map = _formatAttributeName[1];
5969
-
5970
- 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;
5971
- return [attributeName, attributeValue];
5972
- }
5973
5990
 
5974
5991
  var canvasMap = {};
5975
5992
  var defaultCanvasIdCounter = 0;
@@ -10099,14 +10116,13 @@
10099
10116
  zCommandIndexes = _path2Curve[1]; // for later use
10100
10117
 
10101
10118
 
10102
- var segments = path2Segments(curve); // Only calculate bbox here since we don't need length now.
10119
+ var segments = path2Segments(absolutePath); // Only calculate bbox here since we don't need length now.
10103
10120
 
10104
- var _getPathBBox = getPathBBox(absolutePath),
10121
+ var _getPathBBox = getPathBBox(segments, 0),
10105
10122
  x = _getPathBBox.x,
10106
10123
  y = _getPathBBox.y,
10107
10124
  width = _getPathBBox.width,
10108
- height = _getPathBBox.height; // const { x, y, width, height, length } = getPathBBoxTotalLength(absolutePath);
10109
-
10125
+ height = _getPathBBox.height;
10110
10126
 
10111
10127
  return {
10112
10128
  absolutePath: absolutePath,
@@ -10116,15 +10132,8 @@
10116
10132
  polylines: polylines,
10117
10133
  curve: curve,
10118
10134
  // Delay the calculation of length.
10119
- // totalLength: length,
10120
10135
  totalLength: 0,
10121
10136
  zCommandIndexes: zCommandIndexes,
10122
- // rect: new Rectangle(
10123
- // Number.isFinite(x) ? x : 0,
10124
- // Number.isFinite(y) ? y : 0,
10125
- // Number.isFinite(width) ? width : 0,
10126
- // Number.isFinite(height) ? height : 0,
10127
- // ),
10128
10137
  rect: {
10129
10138
  x: Number.isFinite(x) ? x : 0,
10130
10139
  y: Number.isFinite(y) ? y : 0,
@@ -10176,6 +10185,10 @@
10176
10185
  return Math.sqrt(dx * dx + dy * dy);
10177
10186
  }
10178
10187
 
10188
+ function isNumberEqual$1(v1, v2) {
10189
+ return Math.abs(v1 - v2) < 0.001;
10190
+ }
10191
+
10179
10192
  function getBBoxByArray(xArr, yArr) {
10180
10193
  var minX = Math.min.apply(Math, xArr);
10181
10194
  var minY = Math.min.apply(Math, yArr);
@@ -10188,6 +10201,10 @@
10188
10201
  height: maxY - minY
10189
10202
  };
10190
10203
  }
10204
+
10205
+ function piMod(angle) {
10206
+ return (angle + Math.PI * 2) % (Math.PI * 2);
10207
+ }
10191
10208
  var line = {
10192
10209
  /**
10193
10210
  * 计算线段的包围盒
@@ -10292,6 +10309,687 @@
10292
10309
  return Math.atan2(y2 - y1, x2 - x1);
10293
10310
  }
10294
10311
  };
10312
+ var EPSILON$1 = 0.0001;
10313
+ /**
10314
+ * 使用牛顿切割法求最近的点
10315
+ * @param {number[]} xArr 点的 x 数组
10316
+ * @param {number[]} yArr 点的 y 数组
10317
+ * @param {number} x 指定的点 x
10318
+ * @param {number} y 指定的点 y
10319
+ * @param {Function} tCallback 差值函数
10320
+ */
10321
+
10322
+ function nearestPoint(xArr, yArr, x, y, tCallback, length) {
10323
+ var t = -1;
10324
+ var d = Infinity;
10325
+ var v0 = [x, y];
10326
+ var segNum = 20;
10327
+
10328
+ if (length && length > 200) {
10329
+ segNum = length / 10;
10330
+ }
10331
+
10332
+ var increaseRate = 1 / segNum;
10333
+ var interval = increaseRate / 10;
10334
+
10335
+ for (var i = 0; i <= segNum; i++) {
10336
+ var _t = i * increaseRate;
10337
+
10338
+ var v1 = [tCallback.apply(void 0, xArr.concat([_t])), tCallback.apply(void 0, yArr.concat([_t]))];
10339
+ var d1 = distance(v0[0], v0[1], v1[0], v1[1]);
10340
+
10341
+ if (d1 < d) {
10342
+ t = _t;
10343
+ d = d1;
10344
+ }
10345
+ } // 提前终止
10346
+
10347
+
10348
+ if (t === 0) {
10349
+ return {
10350
+ x: xArr[0],
10351
+ y: yArr[0]
10352
+ };
10353
+ }
10354
+
10355
+ if (t === 1) {
10356
+ var count = xArr.length;
10357
+ return {
10358
+ x: xArr[count - 1],
10359
+ y: yArr[count - 1]
10360
+ };
10361
+ }
10362
+
10363
+ d = Infinity;
10364
+
10365
+ for (var _i = 0; _i < 32; _i++) {
10366
+ if (interval < EPSILON$1) {
10367
+ break;
10368
+ }
10369
+
10370
+ var prev = t - interval;
10371
+ var next = t + interval;
10372
+ var _v = [tCallback.apply(void 0, xArr.concat([prev])), tCallback.apply(void 0, yArr.concat([prev]))];
10373
+
10374
+ var _d = distance(v0[0], v0[1], _v[0], _v[1]);
10375
+
10376
+ if (prev >= 0 && _d < d) {
10377
+ t = prev;
10378
+ d = _d;
10379
+ } else {
10380
+ var v2 = [tCallback.apply(void 0, xArr.concat([next])), tCallback.apply(void 0, yArr.concat([next]))];
10381
+ var d2 = distance(v0[0], v0[1], v2[0], v2[1]);
10382
+
10383
+ if (next <= 1 && d2 < d) {
10384
+ t = next;
10385
+ d = d2;
10386
+ } else {
10387
+ interval *= 0.5;
10388
+ }
10389
+ }
10390
+ }
10391
+
10392
+ return {
10393
+ x: tCallback.apply(void 0, xArr.concat([t])),
10394
+ y: tCallback.apply(void 0, yArr.concat([t]))
10395
+ };
10396
+ } // 近似求解 https://community.khronos.org/t/3d-cubic-bezier-segment-length/62363/2
10397
+
10398
+
10399
+ function snapLength(xArr, yArr) {
10400
+ var totalLength = 0;
10401
+ var count = xArr.length;
10402
+
10403
+ for (var i = 0; i < count; i++) {
10404
+ var x = xArr[i];
10405
+ var y = yArr[i];
10406
+ var nextX = xArr[(i + 1) % count];
10407
+ var nextY = yArr[(i + 1) % count];
10408
+ totalLength += distance(x, y, nextX, nextY);
10409
+ }
10410
+
10411
+ return totalLength / 2;
10412
+ }
10413
+
10414
+ function quadraticAt(p0, p1, p2, t) {
10415
+ var onet = 1 - t;
10416
+ return onet * onet * p0 + 2 * t * onet * p1 + t * t * p2;
10417
+ } // 求极值
10418
+
10419
+
10420
+ function extrema(p0, p1, p2) {
10421
+ var a = p0 + p2 - 2 * p1;
10422
+
10423
+ if (isNumberEqual$1(a, 0)) {
10424
+ return [0.5];
10425
+ }
10426
+
10427
+ var rst = (p0 - p1) / a;
10428
+
10429
+ if (rst <= 1 && rst >= 0) {
10430
+ return [rst];
10431
+ }
10432
+
10433
+ return [];
10434
+ }
10435
+
10436
+ function derivativeAt(p0, p1, p2, t) {
10437
+ return 2 * (1 - t) * (p1 - p0) + 2 * t * (p2 - p1);
10438
+ } // 分割贝塞尔曲线
10439
+
10440
+
10441
+ function divideQuadratic(x1, y1, x2, y2, x3, y3, t) {
10442
+ // 划分点
10443
+ var xt = quadraticAt(x1, x2, x3, t);
10444
+ var yt = quadraticAt(y1, y2, y3, t); // 分割的第一条曲线的控制点
10445
+
10446
+ var controlPoint1 = line.pointAt(x1, y1, x2, y2, t); // 分割的第二条曲线的控制点
10447
+
10448
+ var controlPoint2 = line.pointAt(x2, y2, x3, y3, t);
10449
+ return [[x1, y1, controlPoint1.x, controlPoint1.y, xt, yt], [xt, yt, controlPoint2.x, controlPoint2.y, x3, y3]];
10450
+ } // 使用迭代法取贝塞尔曲线的长度
10451
+
10452
+
10453
+ function quadraticLength(x1, y1, x2, y2, x3, y3, iterationCount) {
10454
+ if (iterationCount === 0) {
10455
+ return (distance(x1, y1, x2, y2) + distance(x2, y2, x3, y3) + distance(x1, y1, x3, y3)) / 2;
10456
+ }
10457
+
10458
+ var quadratics = divideQuadratic(x1, y1, x2, y2, x3, y3, 0.5);
10459
+ var left = quadratics[0];
10460
+ var right = quadratics[1];
10461
+ left.push(iterationCount - 1);
10462
+ right.push(iterationCount - 1);
10463
+ return quadraticLength.apply(void 0, left) + quadraticLength.apply(void 0, right);
10464
+ }
10465
+
10466
+ var quadratic = {
10467
+ box: function box(x1, y1, x2, y2, x3, y3) {
10468
+ var xExtrema = extrema(x1, x2, x3)[0];
10469
+ var yExtrema = extrema(y1, y2, y3)[0]; // 控制点不加入 box 的计算
10470
+
10471
+ var xArr = [x1, x3];
10472
+ var yArr = [y1, y3];
10473
+
10474
+ if (xExtrema !== undefined) {
10475
+ xArr.push(quadraticAt(x1, x2, x3, xExtrema));
10476
+ }
10477
+
10478
+ if (yExtrema !== undefined) {
10479
+ yArr.push(quadraticAt(y1, y2, y3, yExtrema));
10480
+ }
10481
+
10482
+ return getBBoxByArray(xArr, yArr);
10483
+ },
10484
+ length: function length(x1, y1, x2, y2, x3, y3) {
10485
+ return quadraticLength(x1, y1, x2, y2, x3, y3, 3);
10486
+ },
10487
+ nearestPoint: function nearestPoint$1(x1, y1, x2, y2, x3, y3, x0, y0) {
10488
+ return nearestPoint([x1, x2, x3], [y1, y2, y3], x0, y0, quadraticAt);
10489
+ },
10490
+ pointDistance: function pointDistance(x1, y1, x2, y2, x3, y3, x0, y0) {
10491
+ var point = this.nearestPoint(x1, y1, x2, y2, x3, y3, x0, y0);
10492
+ return distance(point.x, point.y, x0, y0);
10493
+ },
10494
+ interpolationAt: quadraticAt,
10495
+ pointAt: function pointAt(x1, y1, x2, y2, x3, y3, t) {
10496
+ return {
10497
+ x: quadraticAt(x1, x2, x3, t),
10498
+ y: quadraticAt(y1, y2, y3, t)
10499
+ };
10500
+ },
10501
+ divide: function divide(x1, y1, x2, y2, x3, y3, t) {
10502
+ return divideQuadratic(x1, y1, x2, y2, x3, y3, t);
10503
+ },
10504
+ tangentAngle: function tangentAngle(x1, y1, x2, y2, x3, y3, t) {
10505
+ var dx = derivativeAt(x1, x2, x3, t);
10506
+ var dy = derivativeAt(y1, y2, y3, t);
10507
+ var angle = Math.atan2(dy, dx);
10508
+ return piMod(angle);
10509
+ }
10510
+ };
10511
+
10512
+ function cubicAt(p0, p1, p2, p3, t) {
10513
+ var onet = 1 - t; // t * t * t 的性能大概是 Math.pow(t, 3) 的三倍
10514
+
10515
+ return onet * onet * onet * p0 + 3 * p1 * t * onet * onet + 3 * p2 * t * t * onet + p3 * t * t * t;
10516
+ }
10517
+
10518
+ function derivativeAt$1(p0, p1, p2, p3, t) {
10519
+ var onet = 1 - t;
10520
+ return 3 * (onet * onet * (p1 - p0) + 2 * onet * t * (p2 - p1) + t * t * (p3 - p2));
10521
+ }
10522
+
10523
+ function extrema$1(p0, p1, p2, p3) {
10524
+ var a = -3 * p0 + 9 * p1 - 9 * p2 + 3 * p3;
10525
+ var b = 6 * p0 - 12 * p1 + 6 * p2;
10526
+ var c = 3 * p1 - 3 * p0;
10527
+ var extremas = [];
10528
+ var t1;
10529
+ var t2;
10530
+ var discSqrt;
10531
+
10532
+ if (isNumberEqual$1(a, 0)) {
10533
+ if (!isNumberEqual$1(b, 0)) {
10534
+ t1 = -c / b;
10535
+
10536
+ if (t1 >= 0 && t1 <= 1) {
10537
+ extremas.push(t1);
10538
+ }
10539
+ }
10540
+ } else {
10541
+ var disc = b * b - 4 * a * c;
10542
+
10543
+ if (isNumberEqual$1(disc, 0)) {
10544
+ extremas.push(-b / (2 * a));
10545
+ } else if (disc > 0) {
10546
+ discSqrt = Math.sqrt(disc);
10547
+ t1 = (-b + discSqrt) / (2 * a);
10548
+ t2 = (-b - discSqrt) / (2 * a);
10549
+
10550
+ if (t1 >= 0 && t1 <= 1) {
10551
+ extremas.push(t1);
10552
+ }
10553
+
10554
+ if (t2 >= 0 && t2 <= 1) {
10555
+ extremas.push(t2);
10556
+ }
10557
+ }
10558
+ }
10559
+
10560
+ return extremas;
10561
+ } // 分割贝塞尔曲线
10562
+
10563
+
10564
+ function divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, t) {
10565
+ // 划分点
10566
+ var xt = cubicAt(x1, x2, x3, x4, t);
10567
+ var yt = cubicAt(y1, y2, y3, y4, t); // 计算两点之间的差值点
10568
+
10569
+ var c1 = line.pointAt(x1, y1, x2, y2, t);
10570
+ var c2 = line.pointAt(x2, y2, x3, y3, t);
10571
+ var c3 = line.pointAt(x3, y3, x4, y4, t);
10572
+ var c12 = line.pointAt(c1.x, c1.y, c2.x, c2.y, t);
10573
+ var c23 = line.pointAt(c2.x, c2.y, c3.x, c3.y, t);
10574
+ return [[x1, y1, c1.x, c1.y, c12.x, c12.y, xt, yt], [xt, yt, c23.x, c23.y, c3.x, c3.y, x4, y4]];
10575
+ } // 使用迭代法取贝塞尔曲线的长度,二阶和三阶分开写,更清晰和便于调试
10576
+
10577
+
10578
+ function cubicLength(x1, y1, x2, y2, x3, y3, x4, y4, iterationCount) {
10579
+ if (iterationCount === 0) {
10580
+ return snapLength([x1, x2, x3, x4], [y1, y2, y3, y4]);
10581
+ }
10582
+
10583
+ var cubics = divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, 0.5);
10584
+ var left = [].concat(cubics[0], [iterationCount - 1]);
10585
+ var right = [].concat(cubics[1], [iterationCount - 1]);
10586
+ return cubicLength.apply(void 0, left) + cubicLength.apply(void 0, right);
10587
+ }
10588
+
10589
+ var cubic = {
10590
+ extrema: extrema$1,
10591
+ box: function box(x1, y1, x2, y2, x3, y3, x4, y4) {
10592
+ var xArr = [x1, x4];
10593
+ var yArr = [y1, y4];
10594
+ var xExtrema = extrema$1(x1, x2, x3, x4);
10595
+ var yExtrema = extrema$1(y1, y2, y3, y4);
10596
+
10597
+ for (var i = 0; i < xExtrema.length; i++) {
10598
+ xArr.push(cubicAt(x1, x2, x3, x4, xExtrema[i]));
10599
+ }
10600
+
10601
+ for (var _i = 0; _i < yExtrema.length; _i++) {
10602
+ yArr.push(cubicAt(y1, y2, y3, y4, yExtrema[_i]));
10603
+ }
10604
+
10605
+ return getBBoxByArray(xArr, yArr);
10606
+ },
10607
+ length: function length(x1, y1, x2, y2, x3, y3, x4, y4) {
10608
+ // 迭代三次,划分成 8 段求长度
10609
+ return cubicLength(x1, y1, x2, y2, x3, y3, x4, y4, 3);
10610
+ },
10611
+ nearestPoint: function nearestPoint$1(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length) {
10612
+ return nearestPoint([x1, x2, x3, x4], [y1, y2, y3, y4], x0, y0, cubicAt, length);
10613
+ },
10614
+ pointDistance: function pointDistance(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length) {
10615
+ var point = this.nearestPoint(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length);
10616
+ return distance(point.x, point.y, x0, y0);
10617
+ },
10618
+ interpolationAt: cubicAt,
10619
+ pointAt: function pointAt(x1, y1, x2, y2, x3, y3, x4, y4, t) {
10620
+ return {
10621
+ x: cubicAt(x1, x2, x3, x4, t),
10622
+ y: cubicAt(y1, y2, y3, y4, t)
10623
+ };
10624
+ },
10625
+ divide: function divide(x1, y1, x2, y2, x3, y3, x4, y4, t) {
10626
+ return divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, t);
10627
+ },
10628
+ tangentAngle: function tangentAngle(x1, y1, x2, y2, x3, y3, x4, y4, t) {
10629
+ var dx = derivativeAt$1(x1, x2, x3, x4, t);
10630
+ var dy = derivativeAt$1(y1, y2, y3, y4, t);
10631
+ return piMod(Math.atan2(dy, dx));
10632
+ }
10633
+ };
10634
+ /**
10635
+ * @fileoverview 椭圆的一些计算,
10636
+ * - 周长计算参考:https://www.mathsisfun.com/geometry/ellipse-perimeter.html
10637
+ * - 距离计算参考:https://wet-robots.ghost.io/simple-method-for-distance-to-ellipse/
10638
+ * @author dxq613@gmail.com
10639
+ */
10640
+
10641
+ function copysign(v1, v2) {
10642
+ var absv = Math.abs(v1);
10643
+ return v2 > 0 ? absv : absv * -1;
10644
+ }
10645
+
10646
+ var ellipse = {
10647
+ /**
10648
+ * 包围盒计算
10649
+ * @param {number} x 椭圆中心 x
10650
+ * @param {number} y 椭圆中心 y
10651
+ * @param {number} rx 椭圆 x 方向半径
10652
+ * @param {number} ry 椭圆 y 方向半径
10653
+ * @return {object} 包围盒
10654
+ */
10655
+ box: function box(x, y, rx, ry) {
10656
+ return {
10657
+ x: x - rx,
10658
+ y: y - ry,
10659
+ width: rx * 2,
10660
+ height: ry * 2
10661
+ };
10662
+ },
10663
+
10664
+ /**
10665
+ * 计算周长,使用近似法
10666
+ * @param {number} x 椭圆中心 x
10667
+ * @param {number} y 椭圆中心 y
10668
+ * @param {number} rx 椭圆 x 方向半径
10669
+ * @param {number} ry 椭圆 y 方向半径
10670
+ * @return {number} 椭圆周长
10671
+ */
10672
+ length: function length(x, y, rx, ry) {
10673
+ return Math.PI * (3 * (rx + ry) - Math.sqrt((3 * rx + ry) * (rx + 3 * ry)));
10674
+ },
10675
+
10676
+ /**
10677
+ * 距离椭圆最近的点
10678
+ * @param {number} x 椭圆中心 x
10679
+ * @param {number} y 椭圆中心 y
10680
+ * @param {number} rx 椭圆 x 方向半径
10681
+ * @param {number} ry 椭圆 y 方向半径
10682
+ * @param {number} x0 指定的点 x
10683
+ * @param {number} y0 指定的点 y
10684
+ * @return {object} 椭圆上距离指定点最近的点
10685
+ */
10686
+ nearestPoint: function nearestPoint(x, y, rx, ry, x0, y0) {
10687
+ var a = rx;
10688
+ var b = ry; // 假如椭圆半径为0则返回圆心
10689
+
10690
+ if (a === 0 || b === 0) {
10691
+ return {
10692
+ x: x,
10693
+ y: y
10694
+ };
10695
+ } // 转换成 0, 0 为中心的椭圆计算
10696
+
10697
+
10698
+ var relativeX = x0 - x;
10699
+ var relativeY = y0 - y;
10700
+ var px = Math.abs(relativeX);
10701
+ var py = Math.abs(relativeY);
10702
+ var squareA = a * a;
10703
+ var squareB = b * b; // const angle0 = Math.atan2(relativeY, relativeX);
10704
+
10705
+ var t = Math.PI / 4;
10706
+ var nearestX = 0; // 椭圆上的任一点
10707
+
10708
+ var nearestY = 0; // 迭代 4 次
10709
+
10710
+ for (var i = 0; i < 4; i++) {
10711
+ nearestX = a * Math.cos(t);
10712
+ nearestY = b * Math.sin(t);
10713
+ var ex = (squareA - squareB) * Math.pow(Math.cos(t), 3) / a;
10714
+ var ey = (squareB - squareA) * Math.pow(Math.sin(t), 3) / b;
10715
+ var rx1 = nearestX - ex;
10716
+ var ry1 = nearestY - ey;
10717
+ var qx = px - ex;
10718
+ var qy = py - ey;
10719
+ var r = Math.hypot(ry1, rx1);
10720
+ var q = Math.hypot(qy, qx);
10721
+ var delta_c = r * Math.asin((rx1 * qy - ry1 * qx) / (r * q));
10722
+ var delta_t = delta_c / Math.sqrt(squareA + squareB - nearestX * nearestX - nearestY * nearestY);
10723
+ t += delta_t;
10724
+ t = Math.min(Math.PI / 2, Math.max(0, t));
10725
+ }
10726
+
10727
+ return {
10728
+ x: x + copysign(nearestX, relativeX),
10729
+ y: y + copysign(nearestY, relativeY)
10730
+ };
10731
+ },
10732
+
10733
+ /**
10734
+ * 点到椭圆最近的距离
10735
+ * @param {number} x 椭圆中心 x
10736
+ * @param {number} y 椭圆中心 y
10737
+ * @param {number} rx 椭圆 x 方向半径
10738
+ * @param {number} ry 椭圆 y 方向半径
10739
+ * @param {number} x0 指定的点 x
10740
+ * @param {number} y0 指定的点 y
10741
+ * @return {number} 点到椭圆的距离
10742
+ */
10743
+ pointDistance: function pointDistance(x, y, rx, ry, x0, y0) {
10744
+ var nearestPoint = this.nearestPoint(x, y, rx, ry, x0, y0);
10745
+ return distance(nearestPoint.x, nearestPoint.y, x0, y0);
10746
+ },
10747
+
10748
+ /**
10749
+ * 根据比例获取点
10750
+ * @param {number} x 椭圆中心 x
10751
+ * @param {number} y 椭圆中心 y
10752
+ * @param {number} rx 椭圆 x 方向半径
10753
+ * @param {number} ry 椭圆 y 方向半径
10754
+ * @param {number} t 指定比例,x轴方向为 0
10755
+ * @return {object} 点
10756
+ */
10757
+ pointAt: function pointAt(x, y, rx, ry, t) {
10758
+ var angle = 2 * Math.PI * t; // 按照角度进行计算,而不按照周长计算
10759
+
10760
+ return {
10761
+ x: x + rx * Math.cos(angle),
10762
+ y: y + ry * Math.sin(angle)
10763
+ };
10764
+ },
10765
+
10766
+ /**
10767
+ * 根据比例计算切线角度
10768
+ * @param {number} x 椭圆中心 x
10769
+ * @param {number} y 椭圆中心 y
10770
+ * @param {number} rx 椭圆 x 方向半径
10771
+ * @param {number} ry 椭圆 y 方向半径
10772
+ * @param {number} t 指定比例 0 - 1 之间,x轴方向为 0。在 0-1 范围之外是循环还是返回 null,还需要调整
10773
+ * @return {number} 角度,在 0 - 2PI 之间
10774
+ */
10775
+ tangentAngle: function tangentAngle(x, y, rx, ry, t) {
10776
+ var angle = 2 * Math.PI * t; // 按照角度进行计算,而不按照周长计算
10777
+ // 直接使用 x,y 的导数计算, x' = -rx * sin(t); y' = ry * cos(t);
10778
+
10779
+ var tangentAngle = Math.atan2(ry * Math.cos(angle), -rx * Math.sin(angle)); // 也可以使用指定点的切线方程计算,成本有些高
10780
+ // const point = this.pointAt(0, 0, rx, ry, t); // 椭圆的切线同椭圆的中心不相关
10781
+ // let tangentAngle = -1 * Math.atan((ry * ry * point.x) / (rx * rx * point.y));
10782
+ // if (angle >= 0 && angle <= Math.PI) {
10783
+ // tangentAngle += Math.PI;
10784
+ // }
10785
+
10786
+ return piMod(tangentAngle);
10787
+ }
10788
+ };
10789
+
10790
+ function derivativeXAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle) {
10791
+ return -1 * rx * Math.cos(xRotation) * Math.sin(angle) - ry * Math.sin(xRotation) * Math.cos(angle);
10792
+ } // 偏导数 y
10793
+
10794
+
10795
+ function derivativeYAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle) {
10796
+ return -1 * rx * Math.sin(xRotation) * Math.sin(angle) + ry * Math.cos(xRotation) * Math.cos(angle);
10797
+ } // x 的极值
10798
+
10799
+
10800
+ function xExtrema(rx, ry, xRotation) {
10801
+ return Math.atan(-ry / rx * Math.tan(xRotation));
10802
+ } // y 的极值
10803
+
10804
+
10805
+ function yExtrema(rx, ry, xRotation) {
10806
+ return Math.atan(ry / (rx * Math.tan(xRotation)));
10807
+ } // 根据角度求 x 坐标
10808
+
10809
+
10810
+ function xAt(cx, cy, rx, ry, xRotation, angle) {
10811
+ return rx * Math.cos(xRotation) * Math.cos(angle) - ry * Math.sin(xRotation) * Math.sin(angle) + cx;
10812
+ } // 根据角度求 y 坐标
10813
+
10814
+
10815
+ function yAt(cx, cy, rx, ry, xRotation, angle) {
10816
+ return rx * Math.sin(xRotation) * Math.cos(angle) + ry * Math.cos(xRotation) * Math.sin(angle) + cy;
10817
+ } // 获取点在椭圆上的角度
10818
+
10819
+
10820
+ function getAngle(rx, ry, x0, y0) {
10821
+ var angle = Math.atan2(y0 * rx, x0 * ry); // 转换到 0 - 2PI 内
10822
+
10823
+ return (angle + Math.PI * 2) % (Math.PI * 2);
10824
+ } // 根据角度获取,x,y
10825
+
10826
+
10827
+ function getPoint(rx, ry, angle) {
10828
+ return {
10829
+ x: rx * Math.cos(angle),
10830
+ y: ry * Math.sin(angle)
10831
+ };
10832
+ } // 旋转
10833
+
10834
+
10835
+ function rotate$1(x, y, angle) {
10836
+ var cos = Math.cos(angle);
10837
+ var sin = Math.sin(angle);
10838
+ return [x * cos - y * sin, x * sin + y * cos];
10839
+ }
10840
+
10841
+ var arc = {
10842
+ /**
10843
+ * 计算包围盒
10844
+ * @param {number} cx 圆心 x
10845
+ * @param {number} cy 圆心 y
10846
+ * @param {number} rx x 轴方向的半径
10847
+ * @param {number} ry y 轴方向的半径
10848
+ * @param {number} xRotation 旋转角度
10849
+ * @param {number} startAngle 起始角度
10850
+ * @param {number} endAngle 结束角度
10851
+ * @return {object} 包围盒对象
10852
+ */
10853
+ box: function box(cx, cy, rx, ry, xRotation, startAngle, endAngle) {
10854
+ var xDim = xExtrema(rx, ry, xRotation);
10855
+ var minX = Infinity;
10856
+ var maxX = -Infinity;
10857
+ var xs = [startAngle, endAngle];
10858
+
10859
+ for (var i = -Math.PI * 2; i <= Math.PI * 2; i += Math.PI) {
10860
+ var xAngle = xDim + i;
10861
+
10862
+ if (startAngle < endAngle) {
10863
+ if (startAngle < xAngle && xAngle < endAngle) {
10864
+ xs.push(xAngle);
10865
+ }
10866
+ } else {
10867
+ if (endAngle < xAngle && xAngle < startAngle) {
10868
+ xs.push(xAngle);
10869
+ }
10870
+ }
10871
+ }
10872
+
10873
+ for (var _i = 0; _i < xs.length; _i++) {
10874
+ var x = xAt(cx, cy, rx, ry, xRotation, xs[_i]);
10875
+
10876
+ if (x < minX) {
10877
+ minX = x;
10878
+ }
10879
+
10880
+ if (x > maxX) {
10881
+ maxX = x;
10882
+ }
10883
+ }
10884
+
10885
+ var yDim = yExtrema(rx, ry, xRotation);
10886
+ var minY = Infinity;
10887
+ var maxY = -Infinity;
10888
+ var ys = [startAngle, endAngle];
10889
+
10890
+ for (var _i2 = -Math.PI * 2; _i2 <= Math.PI * 2; _i2 += Math.PI) {
10891
+ var yAngle = yDim + _i2;
10892
+
10893
+ if (startAngle < endAngle) {
10894
+ if (startAngle < yAngle && yAngle < endAngle) {
10895
+ ys.push(yAngle);
10896
+ }
10897
+ } else {
10898
+ if (endAngle < yAngle && yAngle < startAngle) {
10899
+ ys.push(yAngle);
10900
+ }
10901
+ }
10902
+ }
10903
+
10904
+ for (var _i3 = 0; _i3 < ys.length; _i3++) {
10905
+ var y = yAt(cx, cy, rx, ry, xRotation, ys[_i3]);
10906
+
10907
+ if (y < minY) {
10908
+ minY = y;
10909
+ }
10910
+
10911
+ if (y > maxY) {
10912
+ maxY = y;
10913
+ }
10914
+ }
10915
+
10916
+ return {
10917
+ x: minX,
10918
+ y: minY,
10919
+ width: maxX - minX,
10920
+ height: maxY - minY
10921
+ };
10922
+ },
10923
+
10924
+ /**
10925
+ * 获取圆弧的长度,计算圆弧长度时不考虑旋转角度,
10926
+ * 仅跟 rx, ry, startAngle, endAngle 相关
10927
+ * @param {number} cx 圆心 x
10928
+ * @param {number} cy 圆心 y
10929
+ * @param {number} rx x 轴方向的半径
10930
+ * @param {number} ry y 轴方向的半径
10931
+ * @param {number} xRotation 旋转角度
10932
+ * @param {number} startAngle 起始角度
10933
+ * @param {number} endAngle 结束角度
10934
+ */
10935
+ length: function length(cx, cy, rx, ry, xRotation, startAngle, endAngle) {},
10936
+
10937
+ /**
10938
+ * 获取指定点到圆弧的最近距离的点
10939
+ * @param {number} cx 圆心 x
10940
+ * @param {number} cy 圆心 y
10941
+ * @param {number} rx x 轴方向的半径
10942
+ * @param {number} ry y 轴方向的半径
10943
+ * @param {number} xRotation 旋转角度
10944
+ * @param {number} startAngle 起始角度
10945
+ * @param {number} endAngle 结束角度
10946
+ * @param {number} x0 指定点的 x
10947
+ * @param {number} y0 指定点的 y
10948
+ * @return {object} 到指定点最近距离的点
10949
+ */
10950
+ nearestPoint: function nearestPoint(cx, cy, rx, ry, xRotation, startAngle, endAngle, x0, y0) {
10951
+ // 将最近距离问题转换成到椭圆中心 0,0 没有旋转的椭圆问题
10952
+ var relativeVector = rotate$1(x0 - cx, y0 - cy, -xRotation);
10953
+ var x1 = relativeVector[0],
10954
+ y1 = relativeVector[1]; // 计算点到椭圆的最近的点
10955
+
10956
+ var relativePoint = ellipse.nearestPoint(0, 0, rx, ry, x1, y1); // 获取点在椭圆上的角度
10957
+
10958
+ var angle = getAngle(rx, ry, relativePoint.x, relativePoint.y); // 点没有在圆弧上
10959
+
10960
+ if (angle < startAngle) {
10961
+ // 小于起始圆弧
10962
+ relativePoint = getPoint(rx, ry, startAngle);
10963
+ } else if (angle > endAngle) {
10964
+ // 大于结束圆弧
10965
+ relativePoint = getPoint(rx, ry, endAngle);
10966
+ } // 旋转到 xRotation 的角度
10967
+
10968
+
10969
+ var vector = rotate$1(relativePoint.x, relativePoint.y, xRotation);
10970
+ return {
10971
+ x: vector[0] + cx,
10972
+ y: vector[1] + cy
10973
+ };
10974
+ },
10975
+ pointDistance: function pointDistance(cx, cy, rx, ry, xRotation, startAngle, endAngle, x0, y0) {
10976
+ var nearestPoint = this.nearestPoint(cx, cy, rx, ry, xRotation, startAngle, endAngle, x0, y0);
10977
+ return distance(nearestPoint.x, nearestPoint.y, x0, y0);
10978
+ },
10979
+ pointAt: function pointAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, t) {
10980
+ var angle = (endAngle - startAngle) * t + startAngle;
10981
+ return {
10982
+ x: xAt(cx, cy, rx, ry, xRotation, angle),
10983
+ y: yAt(cx, cy, rx, ry, xRotation, angle)
10984
+ };
10985
+ },
10986
+ tangentAngle: function tangentAngle(cx, cy, rx, ry, xRotation, startAngle, endAngle, t) {
10987
+ var angle = (endAngle - startAngle) * t + startAngle;
10988
+ var dx = derivativeXAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle);
10989
+ var dy = derivativeYAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle);
10990
+ return piMod(Math.atan2(dy, dx));
10991
+ }
10992
+ };
10295
10993
 
10296
10994
  function analyzePoints(points) {
10297
10995
  // 计算每段的长度和总的长度
@@ -11539,16 +12237,23 @@
11539
12237
  };
11540
12238
 
11541
12239
  _proto.postProcessor = function postProcessor(object) {
11542
- if (!object.attributes.offsetPath) {
12240
+ var _object$parsedStyle = object.parsedStyle,
12241
+ offsetPath = _object$parsedStyle.offsetPath,
12242
+ offsetDistance = _object$parsedStyle.offsetDistance;
12243
+
12244
+ if (!offsetPath) {
11543
12245
  return;
11544
12246
  }
11545
12247
 
11546
- var offsetPathNodeName = object.attributes.offsetPath.nodeName;
12248
+ var nodeName = offsetPath.nodeName;
11547
12249
 
11548
- if (offsetPathNodeName === exports.Shape.LINE || offsetPathNodeName === exports.Shape.PATH || offsetPathNodeName === exports.Shape.POLYLINE) {
11549
- var point = object.attributes.offsetPath.getPoint(object.parsedStyle.offsetDistance);
12250
+ if (nodeName === exports.Shape.LINE || nodeName === exports.Shape.PATH || nodeName === exports.Shape.POLYLINE) {
12251
+ // set position in world space
12252
+ var point = offsetPath.getPoint(offsetDistance);
11550
12253
 
11551
12254
  if (point) {
12255
+ object.parsedStyle.defX = point.x;
12256
+ object.parsedStyle.defY = point.y;
11552
12257
  object.setLocalPosition(point.x, point.y);
11553
12258
  }
11554
12259
  }
@@ -11931,7 +12636,7 @@
11931
12636
  return CSSPropertyZIndex;
11932
12637
  }();
11933
12638
 
11934
- function getAngle(angle) {
12639
+ function getAngle$1(angle) {
11935
12640
  if (angle === undefined) {
11936
12641
  return 0;
11937
12642
  } else if (angle > 360 || angle < -360) {
@@ -12743,12 +13448,148 @@
12743
13448
  return point1[0] === point2[0] && point1[1] === point2[1];
12744
13449
  }
12745
13450
 
13451
+ function getPathBBox(segments, lineWidth) {
13452
+ var xArr = [];
13453
+ var yArr = [];
13454
+ var segmentsWithAngle = [];
13455
+
13456
+ for (var i = 0; i < segments.length; i++) {
13457
+ var segment = segments[i];
13458
+ var currentPoint = segment.currentPoint,
13459
+ params = segment.params,
13460
+ prePoint = segment.prePoint;
13461
+ var box = void 0;
13462
+
13463
+ switch (segment.command) {
13464
+ case 'Q':
13465
+ box = quadratic.box(prePoint[0], prePoint[1], params[1], params[2], params[3], params[4]);
13466
+ break;
13467
+
13468
+ case 'C':
13469
+ box = cubic.box(prePoint[0], prePoint[1], params[1], params[2], params[3], params[4], params[5], params[6]);
13470
+ break;
13471
+
13472
+ case 'A':
13473
+ var arcParams = segment.arcParams;
13474
+ box = arc.box(arcParams.cx, arcParams.cy, arcParams.rx, arcParams.ry, arcParams.xRotation, arcParams.startAngle, arcParams.endAngle);
13475
+ break;
13476
+
13477
+ default:
13478
+ xArr.push(currentPoint[0]);
13479
+ yArr.push(currentPoint[1]);
13480
+ break;
13481
+ }
13482
+
13483
+ if (box) {
13484
+ segment.box = box;
13485
+ xArr.push(box.x, box.x + box.width);
13486
+ yArr.push(box.y, box.y + box.height);
13487
+ }
13488
+
13489
+ if (lineWidth && (segment.command === 'L' || segment.command === 'M') && segment.prePoint && segment.nextPoint) {
13490
+ segmentsWithAngle.push(segment);
13491
+ }
13492
+ } // bbox calculation should ignore NaN for path attribute
13493
+ // ref: https://github.com/antvis/g/issues/210
13494
+ // ref: https://github.com/antvis/G2/issues/3109
13495
+
13496
+
13497
+ xArr = xArr.filter(function (item) {
13498
+ return !Number.isNaN(item) && item !== Infinity && item !== -Infinity;
13499
+ });
13500
+ yArr = yArr.filter(function (item) {
13501
+ return !Number.isNaN(item) && item !== Infinity && item !== -Infinity;
13502
+ });
13503
+ var minX = min$1(xArr);
13504
+ var minY = min$1(yArr);
13505
+ var maxX = max$1(xArr);
13506
+ var maxY = max$1(yArr);
13507
+
13508
+ if (segmentsWithAngle.length === 0) {
13509
+ return {
13510
+ x: minX,
13511
+ y: minY,
13512
+ width: maxX - minX,
13513
+ height: maxY - minY
13514
+ };
13515
+ }
13516
+
13517
+ for (var _i = 0; _i < segmentsWithAngle.length; _i++) {
13518
+ var _segment = segmentsWithAngle[_i];
13519
+ var _currentPoint = _segment.currentPoint;
13520
+ var extra = void 0;
13521
+
13522
+ if (_currentPoint[0] === minX) {
13523
+ extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
13524
+ minX = minX - extra.xExtra;
13525
+ } else if (_currentPoint[0] === maxX) {
13526
+ extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
13527
+ maxX = maxX + extra.xExtra;
13528
+ }
13529
+
13530
+ if (_currentPoint[1] === minY) {
13531
+ extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
13532
+ minY = minY - extra.yExtra;
13533
+ } else if (_currentPoint[1] === maxY) {
13534
+ extra = getExtraFromSegmentWithAngle(_segment, lineWidth);
13535
+ maxY = maxY + extra.yExtra;
13536
+ }
13537
+ }
13538
+
13539
+ return {
13540
+ x: minX,
13541
+ y: minY,
13542
+ width: maxX - minX,
13543
+ height: maxY - minY
13544
+ };
13545
+ }
13546
+
13547
+ function getExtraFromSegmentWithAngle(segment, lineWidth) {
13548
+ var prePoint = segment.prePoint,
13549
+ currentPoint = segment.currentPoint,
13550
+ nextPoint = segment.nextPoint;
13551
+ var currentAndPre = Math.pow(currentPoint[0] - prePoint[0], 2) + Math.pow(currentPoint[1] - prePoint[1], 2);
13552
+ var currentAndNext = Math.pow(currentPoint[0] - nextPoint[0], 2) + Math.pow(currentPoint[1] - nextPoint[1], 2);
13553
+ var preAndNext = Math.pow(prePoint[0] - nextPoint[0], 2) + Math.pow(prePoint[1] - nextPoint[1], 2); // 以 currentPoint 为顶点的夹角
13554
+
13555
+ var currentAngle = Math.acos((currentAndPre + currentAndNext - preAndNext) / (2 * Math.sqrt(currentAndPre) * Math.sqrt(currentAndNext))); // 夹角为空、 0 或 PI 时,不需要计算夹角处的额外宽度
13556
+ // 注意: 由于计算精度问题,夹角为 0 的情况计算出来的角度可能是一个很小的值,还需要判断其与 0 是否近似相等
13557
+
13558
+ if (!currentAngle || Math.sin(currentAngle) === 0 || isNumberEqual(currentAngle, 0)) {
13559
+ return {
13560
+ xExtra: 0,
13561
+ yExtra: 0
13562
+ };
13563
+ }
13564
+
13565
+ var xAngle = Math.abs(Math.atan2(nextPoint[1] - currentPoint[1], nextPoint[0] - currentPoint[0]));
13566
+ var yAngle = Math.abs(Math.atan2(nextPoint[0] - currentPoint[0], nextPoint[1] - currentPoint[1])); // 将夹角转为锐角
13567
+
13568
+ xAngle = xAngle > Math.PI / 2 ? Math.PI - xAngle : xAngle;
13569
+ yAngle = yAngle > Math.PI / 2 ? Math.PI - yAngle : yAngle; // 这里不考虑在水平和垂直方向的投影,直接使用最大差值
13570
+ // 由于上层统一加减了二分之一线宽,这里需要进行弥补
13571
+
13572
+ var extra = {
13573
+ // 水平方向投影
13574
+ xExtra: Math.cos(currentAngle / 2 - xAngle) * (lineWidth / 2 * (1 / Math.sin(currentAngle / 2))) - lineWidth / 2 || 0,
13575
+ // 垂直方向投影
13576
+ yExtra: Math.cos(yAngle - currentAngle / 2) * (lineWidth / 2 * (1 / Math.sin(currentAngle / 2))) - lineWidth / 2 || 0
13577
+ };
13578
+ return extra;
13579
+ } // 点对称
13580
+
13581
+
13582
+ function toSymmetry(point, center) {
13583
+ return [center[0] + (center[0] - point[0]), center[1] + (center[1] - point[1])];
13584
+ }
13585
+
12746
13586
  function path2Segments(path) {
12747
13587
  var segments = [];
12748
13588
  var currentPoint = null; // 当前图形
12749
13589
 
12750
13590
  var nextParams = null; // 下一节点的 path 参数
12751
- // let startMovePoint = null; // 开始 M 的点,可能会有多个
13591
+
13592
+ var startMovePoint = null; // 开始 M 的点,可能会有多个
12752
13593
 
12753
13594
  var lastStartMovePointIndex = 0; // 最近一个开始点 M 的索引
12754
13595
 
@@ -12764,18 +13605,43 @@
12764
13605
  prePoint: currentPoint,
12765
13606
  params: params,
12766
13607
  startTangent: null,
12767
- endTangent: null
13608
+ endTangent: null,
13609
+ currentPoint: null,
13610
+ nextPoint: null,
13611
+ arcParams: null
12768
13612
  };
12769
13613
 
12770
13614
  switch (command) {
12771
13615
  case 'M':
12772
- // startMovePoint = [params[1], params[2]];
13616
+ startMovePoint = [params[1], params[2]];
12773
13617
  lastStartMovePointIndex = i;
12774
13618
  break;
13619
+
13620
+ case 'A':
13621
+ var arcParams = getArcParams(currentPoint, params);
13622
+ segment.arcParams = arcParams;
13623
+ break;
12775
13624
  }
12776
13625
 
12777
- var len = params.length;
12778
- currentPoint = [params[len - 2], params[len - 1]]; // @ts-ignore
13626
+ if (command === 'Z') {
13627
+ // 有了 Z 后,当前节点从开始 M 的点开始
13628
+ currentPoint = startMovePoint; // 如果当前点的命令为 Z,相当于当前点为最近一个 M 点,则下一个点直接指向最近一个 M 点的下一个点
13629
+
13630
+ nextParams = path[lastStartMovePointIndex + 1];
13631
+ } else {
13632
+ var len = params.length;
13633
+ currentPoint = [params[len - 2], params[len - 1]];
13634
+ }
13635
+
13636
+ if (nextParams && nextParams[0] === 'Z') {
13637
+ // 如果下一个点的命令为 Z,则下一个点直接指向最近一个 M 点
13638
+ nextParams = path[lastStartMovePointIndex];
13639
+
13640
+ if (segments[lastStartMovePointIndex]) {
13641
+ // 如果下一个点的命令为 Z,则最近一个 M 点的前一个点为当前点
13642
+ segments[lastStartMovePointIndex].prePoint = currentPoint;
13643
+ }
13644
+ }
12779
13645
 
12780
13646
  segment.currentPoint = currentPoint; // 如果当前点与最近一个 M 点相同,则最近一个 M 点的前一个点为当前点的前一个点
12781
13647
 
@@ -12783,13 +13649,36 @@
12783
13649
  segments[lastStartMovePointIndex].prePoint = segment.prePoint;
12784
13650
  }
12785
13651
 
12786
- var nextPoint = nextParams ? [nextParams[nextParams.length - 2], nextParams[nextParams.length - 1]] : null; // @ts-ignore
12787
-
13652
+ var nextPoint = nextParams ? [nextParams[nextParams.length - 2], nextParams[nextParams.length - 1]] : null;
12788
13653
  segment.nextPoint = nextPoint; // Add startTangent and endTangent
12789
13654
 
12790
13655
  var prePoint = segment.prePoint;
12791
13656
 
12792
- if (command === 'C') {
13657
+ if (['L', 'H', 'V'].includes(command)) {
13658
+ segment.startTangent = [prePoint[0] - currentPoint[0], prePoint[1] - currentPoint[1]];
13659
+ segment.endTangent = [currentPoint[0] - prePoint[0], currentPoint[1] - prePoint[1]];
13660
+ } else if (command === 'Q') {
13661
+ // 二次贝塞尔曲线只有一个控制点
13662
+ var cp = [params[1], params[2]]; // 二次贝塞尔曲线的终点为 currentPoint
13663
+
13664
+ segment.startTangent = [prePoint[0] - cp[0], prePoint[1] - cp[1]];
13665
+ segment.endTangent = [currentPoint[0] - cp[0], currentPoint[1] - cp[1]];
13666
+ } else if (command === 'T') {
13667
+ var preSegment = segments[i - 1];
13668
+
13669
+ var _cp = toSymmetry(preSegment.currentPoint, prePoint);
13670
+
13671
+ if (preSegment.command === 'Q') {
13672
+ segment.command = 'Q';
13673
+ segment.startTangent = [prePoint[0] - _cp[0], prePoint[1] - _cp[1]];
13674
+ segment.endTangent = [currentPoint[0] - _cp[0], currentPoint[1] - _cp[1]];
13675
+ } else {
13676
+ // @ts-ignore
13677
+ segment.command = 'TL';
13678
+ segment.startTangent = [prePoint[0] - currentPoint[0], prePoint[1] - currentPoint[1]];
13679
+ segment.endTangent = [currentPoint[0] - prePoint[0], currentPoint[1] - prePoint[1]];
13680
+ }
13681
+ } else if (command === 'C') {
12793
13682
  // 三次贝塞尔曲线有两个控制点
12794
13683
  var cp1 = [params[1], params[2]];
12795
13684
  var cp2 = [params[3], params[4]];
@@ -12803,25 +13692,155 @@
12803
13692
  if (segment.endTangent[0] === 0 && segment.endTangent[1] === 0) {
12804
13693
  segment.endTangent = [cp2[0] - cp1[0], cp2[1] - cp1[1]];
12805
13694
  }
13695
+ } else if (command === 'S') {
13696
+ var _preSegment = segments[i - 1];
13697
+
13698
+ var _cp2 = toSymmetry(_preSegment.currentPoint, prePoint);
13699
+
13700
+ var _cp3 = [params[1], params[2]];
13701
+
13702
+ if (_preSegment.command === 'C') {
13703
+ segment.command = 'C'; // 将 S 命令变换为 C 命令
13704
+
13705
+ segment.startTangent = [prePoint[0] - _cp2[0], prePoint[1] - _cp2[1]];
13706
+ segment.endTangent = [currentPoint[0] - _cp3[0], currentPoint[1] - _cp3[1]];
13707
+ } else {
13708
+ // @ts-ignore
13709
+ segment.command = 'SQ'; // 将 S 命令变换为 SQ 命令
13710
+
13711
+ segment.startTangent = [prePoint[0] - _cp3[0], prePoint[1] - _cp3[1]];
13712
+ segment.endTangent = [currentPoint[0] - _cp3[0], currentPoint[1] - _cp3[1]];
13713
+ }
13714
+ } else if (command === 'A') {
13715
+ var d = 0.001;
13716
+
13717
+ var _ref = segment.arcParams || {},
13718
+ _ref$cx = _ref.cx,
13719
+ cx = _ref$cx === void 0 ? 0 : _ref$cx,
13720
+ _ref$cy = _ref.cy,
13721
+ cy = _ref$cy === void 0 ? 0 : _ref$cy,
13722
+ _ref$rx = _ref.rx,
13723
+ rx = _ref$rx === void 0 ? 0 : _ref$rx,
13724
+ _ref$ry = _ref.ry,
13725
+ ry = _ref$ry === void 0 ? 0 : _ref$ry,
13726
+ _ref$sweepFlag = _ref.sweepFlag,
13727
+ sweepFlag = _ref$sweepFlag === void 0 ? 0 : _ref$sweepFlag,
13728
+ _ref$startAngle = _ref.startAngle,
13729
+ startAngle = _ref$startAngle === void 0 ? 0 : _ref$startAngle,
13730
+ _ref$endAngle = _ref.endAngle,
13731
+ endAngle = _ref$endAngle === void 0 ? 0 : _ref$endAngle;
13732
+
13733
+ if (sweepFlag === 0) {
13734
+ d *= -1;
13735
+ }
13736
+
13737
+ var dx1 = rx * Math.cos(startAngle - d) + cx;
13738
+ var dy1 = ry * Math.sin(startAngle - d) + cy;
13739
+ segment.startTangent = [dx1 - startMovePoint[0], dy1 - startMovePoint[1]];
13740
+ var dx2 = rx * Math.cos(startAngle + endAngle + d) + cx;
13741
+ var dy2 = ry * Math.sin(startAngle + endAngle - d) + cy;
13742
+ segment.endTangent = [prePoint[0] - dx2, prePoint[1] - dy2];
12806
13743
  }
12807
13744
 
12808
13745
  segments.push(segment);
12809
13746
  }
12810
13747
 
12811
13748
  return segments;
13749
+ } // 向量长度
13750
+
13751
+ function vMag(v) {
13752
+ return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
13753
+ } // u.v/|u||v|,计算夹角的余弦值
13754
+
13755
+
13756
+ function vRatio(u, v) {
13757
+ // 当存在一个向量的长度为 0 时,夹角也为 0,即夹角的余弦值为 1
13758
+ return vMag(u) * vMag(v) ? (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v)) : 1;
13759
+ } // 向量角度
13760
+
13761
+
13762
+ function vAngle(u, v) {
13763
+ return (u[0] * v[1] < u[1] * v[0] ? -1 : 1) * Math.acos(vRatio(u, v));
12812
13764
  }
12813
13765
 
12814
- function commandsToPathString(commands, object, applyLocalTransform) {
12815
- if (applyLocalTransform === void 0) {
12816
- applyLocalTransform = true;
13766
+ function getArcParams(startPoint, params) {
13767
+ var rx = params[1];
13768
+ var ry = params[2];
13769
+ var xRotation = mod(deg2rad(params[3]), Math.PI * 2);
13770
+ var arcFlag = params[4];
13771
+ var sweepFlag = params[5]; // 弧形起点坐标
13772
+
13773
+ var x1 = startPoint[0];
13774
+ var y1 = startPoint[1]; // 弧形终点坐标
13775
+
13776
+ var x2 = params[6];
13777
+ var y2 = params[7];
13778
+ var xp = Math.cos(xRotation) * (x1 - x2) / 2.0 + Math.sin(xRotation) * (y1 - y2) / 2.0;
13779
+ var yp = -1 * Math.sin(xRotation) * (x1 - x2) / 2.0 + Math.cos(xRotation) * (y1 - y2) / 2.0;
13780
+ var lambda = xp * xp / (rx * rx) + yp * yp / (ry * ry);
13781
+
13782
+ if (lambda > 1) {
13783
+ rx *= Math.sqrt(lambda);
13784
+ ry *= Math.sqrt(lambda);
12817
13785
  }
12818
13786
 
12819
- var transform;
13787
+ var diff = rx * rx * (yp * yp) + ry * ry * (xp * xp);
13788
+ var f = diff ? Math.sqrt((rx * rx * (ry * ry) - diff) / diff) : 1;
12820
13789
 
12821
- if (applyLocalTransform) {
12822
- transform = object.getLocalTransform();
13790
+ if (arcFlag === sweepFlag) {
13791
+ f *= -1;
12823
13792
  }
12824
13793
 
13794
+ if (isNaN(f)) {
13795
+ f = 0;
13796
+ } // 旋转前的起点坐标,且当长半轴和短半轴的长度为 0 时,坐标按 (0, 0) 处理
13797
+
13798
+
13799
+ var cxp = ry ? f * rx * yp / ry : 0;
13800
+ var cyp = rx ? f * -ry * xp / rx : 0; // 椭圆圆心坐标
13801
+
13802
+ var cx = (x1 + x2) / 2.0 + Math.cos(xRotation) * cxp - Math.sin(xRotation) * cyp;
13803
+ var cy = (y1 + y2) / 2.0 + Math.sin(xRotation) * cxp + Math.cos(xRotation) * cyp; // 起始点的单位向量
13804
+
13805
+ var u = [(xp - cxp) / rx, (yp - cyp) / ry]; // 终止点的单位向量
13806
+
13807
+ var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry]; // 计算起始点和圆心的连线,与 x 轴正方向的夹角
13808
+
13809
+ var theta = vAngle([1, 0], u); // 计算圆弧起始点和终止点与椭圆圆心连线的夹角
13810
+
13811
+ var dTheta = vAngle(u, v);
13812
+
13813
+ if (vRatio(u, v) <= -1) {
13814
+ dTheta = Math.PI;
13815
+ }
13816
+
13817
+ if (vRatio(u, v) >= 1) {
13818
+ dTheta = 0;
13819
+ }
13820
+
13821
+ if (sweepFlag === 0 && dTheta > 0) {
13822
+ dTheta = dTheta - 2 * Math.PI;
13823
+ }
13824
+
13825
+ if (sweepFlag === 1 && dTheta < 0) {
13826
+ dTheta = dTheta + 2 * Math.PI;
13827
+ }
13828
+
13829
+ return {
13830
+ cx: cx,
13831
+ cy: cy,
13832
+ // 弧形的起点和终点相同时,长轴和短轴的长度按 0 处理
13833
+ rx: isSamePoint(startPoint, [x2, y2]) ? 0 : rx,
13834
+ ry: isSamePoint(startPoint, [x2, y2]) ? 0 : ry,
13835
+ startAngle: theta,
13836
+ endAngle: theta + dTheta,
13837
+ xRotation: xRotation,
13838
+ arcFlag: arcFlag,
13839
+ sweepFlag: sweepFlag
13840
+ };
13841
+ }
13842
+
13843
+ function commandsToPathString(commands, object, transform) {
12825
13844
  var _object$parsedStyle = object.parsedStyle,
12826
13845
  _object$parsedStyle$d = _object$parsedStyle.defX,
12827
13846
  defX = _object$parsedStyle$d === void 0 ? 0 : _object$parsedStyle$d,
@@ -12833,7 +13852,7 @@
12833
13852
  if (cur[0] === 'M' || cur[0] === 'L') {
12834
13853
  var p = fromValues$2(cur[1] - defX, cur[2] - defY, 0);
12835
13854
 
12836
- if (applyLocalTransform) {
13855
+ if (transform) {
12837
13856
  transformMat4(p, p, transform);
12838
13857
  }
12839
13858
 
@@ -12845,7 +13864,7 @@
12845
13864
  var p2 = fromValues$2(cur[3] - defX, cur[4] - defY, 0);
12846
13865
  var p3 = fromValues$2(cur[5] - defX, cur[6] - defY, 0);
12847
13866
 
12848
- if (applyLocalTransform) {
13867
+ if (transform) {
12849
13868
  transformMat4(p1, p1, transform);
12850
13869
  transformMat4(p2, p2, transform);
12851
13870
  transformMat4(p3, p3, transform);
@@ -12855,7 +13874,7 @@
12855
13874
  } else if (cur[0] === 'A') {
12856
13875
  var c = fromValues$2(cur[6] - defX, cur[7] - defY, 0);
12857
13876
 
12858
- if (applyLocalTransform) {
13877
+ if (transform) {
12859
13878
  transformMat4(c, c, transform);
12860
13879
  }
12861
13880
 
@@ -12919,9 +13938,9 @@
12919
13938
  */
12920
13939
 
12921
13940
 
12922
- function convertToPath(object, applyLocalTransform) {
12923
- if (applyLocalTransform === void 0) {
12924
- applyLocalTransform = true;
13941
+ function convertToPath(object, transform) {
13942
+ if (transform === void 0) {
13943
+ transform = object.getLocalTransform();
12925
13944
  }
12926
13945
 
12927
13946
  var commands = [];
@@ -12990,7 +14009,7 @@
12990
14009
  }
12991
14010
 
12992
14011
  if (commands.length) {
12993
- return commandsToPathString(commands, object, applyLocalTransform);
14012
+ return commandsToPathString(commands, object, transform);
12994
14013
  }
12995
14014
  }
12996
14015
  function translatePathToString(pathArray, x, y, startOffsetX, startOffsetY, endOffsetX, endOffsetY) {
@@ -13011,8 +14030,7 @@
13011
14030
  }
13012
14031
 
13013
14032
  var newValue = pathArray.map(function (params, i) {
13014
- var command = params[0]; // @ts-ignore
13015
-
14033
+ var command = params[0];
13016
14034
  var isClosed = pathArray[pathArray.length - 1][0] === 'Z';
13017
14035
  var offsetX = i === pathArray.length - (isClosed ? 2 : 1) ? endOffsetX : 0;
13018
14036
  var offsetY = i === pathArray.length - (isClosed ? 2 : 1) ? endOffsetY : 0;
@@ -14654,7 +15672,7 @@
14654
15672
  n: 'textAlign',
14655
15673
  l: true,
14656
15674
  inh: true,
14657
- k: ['start', 'center', 'end', 'left', 'right'],
15675
+ k: ['start', 'center', 'middle', 'end', 'left', 'right'],
14658
15676
  d: 'start'
14659
15677
  }, // {
14660
15678
  // n: 'whiteSpace',
@@ -14766,12 +15784,10 @@
14766
15784
  attributeNames.forEach(function (attributeName) {
14767
15785
  var _propertyMetadataCach;
14768
15786
 
14769
- var _formatAttribute = formatAttribute(attributeName, attributes[attributeName]),
14770
- name = _formatAttribute[0],
14771
- value = _formatAttribute[1];
15787
+ var name = formatAttributeName(attributeName);
14772
15788
 
14773
15789
  if (!skipUpdateAttribute) {
14774
- object.attributes[name] = value;
15790
+ object.attributes[name] = attributes[attributeName];
14775
15791
  }
14776
15792
 
14777
15793
  if (!needUpdateGeometry && ((_propertyMetadataCach = propertyMetadataCache[name]) === null || _propertyMetadataCach === void 0 ? void 0 : _propertyMetadataCach.l)) {
@@ -15907,7 +16923,11 @@
15907
16923
  */
15908
16924
  ;
15909
16925
 
15910
- _proto.dispatchEvent = function dispatchEvent(e) {
16926
+ _proto.dispatchEvent = function dispatchEvent(e, skipPropagate) {
16927
+ if (skipPropagate === void 0) {
16928
+ skipPropagate = false;
16929
+ }
16930
+
15911
16931
  if (!(e instanceof FederatedEvent)) {
15912
16932
  throw new Error('DisplayObject cannot propagate events outside of the Federated Events API');
15913
16933
  } // should account for Element / Document / Canvas
@@ -15937,8 +16957,12 @@
15937
16957
 
15938
16958
  e.defaultPrevented = false;
15939
16959
  e.path = [];
15940
- e.target = this;
15941
- (_e$manager = e.manager) === null || _e$manager === void 0 ? void 0 : _e$manager.dispatchEvent(e);
16960
+
16961
+ if (!skipPropagate) {
16962
+ e.target = this;
16963
+ }
16964
+
16965
+ (_e$manager = e.manager) === null || _e$manager === void 0 ? void 0 : _e$manager.dispatchEvent(e, e.type, skipPropagate);
15942
16966
  }
15943
16967
 
15944
16968
  return !e.defaultPrevented;
@@ -17256,9 +18280,7 @@
17256
18280
  var value = this.attributes[name];
17257
18281
 
17258
18282
  if (value === undefined) {
17259
- var _formatAttribute = formatAttribute(name, ''),
17260
- attributeName = _formatAttribute[0];
17261
-
18283
+ var attributeName = formatAttributeName(name);
17262
18284
  value = this.attributes[attributeName]; // if the given attribute does not exist, the value returned will either be null or ""
17263
18285
 
17264
18286
  return isNil(value) ? null : value;
@@ -17667,6 +18689,7 @@
17667
18689
  filter: [],
17668
18690
  shadowType: 'outer'
17669
18691
  };
18692
+ var INHERITABLE_STYLE_PROPS = ['opacity', 'fillOpacity', 'strokeOpacity', 'transformOrigin', 'visibility', 'pointerEvents', 'lineWidth', 'lineCap', 'lineJoin', 'increasedLineWidthForHitTesting', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'textAlign', 'textBaseline', 'textTransform'];
17670
18693
  /**
17671
18694
  * prototype chains: DisplayObject -> Element -> Node -> EventTarget
17672
18695
  *
@@ -17706,6 +18729,7 @@
17706
18729
 
17707
18730
  _this.config = void 0;
17708
18731
  _this.isCustomElement = false;
18732
+ _this.isMutationObserved = false;
17709
18733
  _this.activeAnimations = [];
17710
18734
 
17711
18735
  _this.getClip = function () {
@@ -17840,14 +18864,7 @@
17840
18864
 
17841
18865
  runtime.styleValueRegistry.processProperties(this, attributes, {
17842
18866
  forceUpdateGeometry: true,
17843
- usedAttributes: [// 'anchor',
17844
- // 'transform',
17845
- // 'zIndex',
17846
- // 'filter',
17847
- // 'shadowType',
17848
- // 'fill',
17849
- // 'stroke',
17850
- 'opacity', 'fillOpacity', 'strokeOpacity', 'transformOrigin', 'visibility', 'pointerEvents', 'lineWidth', 'lineCap', 'lineJoin', 'increasedLineWidthForHitTesting', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'textAlign', 'textBaseline', 'textTransform']
18867
+ usedAttributes: INHERITABLE_STYLE_PROPS
17851
18868
  }); // redraw at next frame
17852
18869
 
17853
18870
  renderable.dirty = true;
@@ -17858,19 +18875,16 @@
17858
18875
  force = false;
17859
18876
  }
17860
18877
 
17861
- var _formatAttribute = formatAttribute(name, value),
17862
- attributeName = _formatAttribute[0],
17863
- attributeValue = _formatAttribute[1]; // ignore undefined value
17864
-
18878
+ var attributeName = formatAttributeName(name); // ignore undefined value
17865
18879
 
17866
18880
  if (isUndefined(value)) {
17867
18881
  return;
17868
18882
  }
17869
18883
 
17870
- if (force || attributeValue !== this.attributes[attributeName]) {
17871
- this.internalSetAttribute(attributeName, attributeValue);
18884
+ if (force || value !== this.attributes[attributeName]) {
18885
+ this.internalSetAttribute(attributeName, value);
17872
18886
 
17873
- _Element.prototype.setAttribute.call(this, attributeName, attributeValue);
18887
+ _Element.prototype.setAttribute.call(this, attributeName, value);
17874
18888
  }
17875
18889
  }
17876
18890
  /**
@@ -17900,7 +18914,13 @@
17900
18914
  mutationEvent.attrName = name;
17901
18915
  mutationEvent.prevParsedValue = oldParsedValue;
17902
18916
  mutationEvent.newParsedValue = newParsedValue;
17903
- this.dispatchEvent(mutationEvent);
18917
+
18918
+ if (this.isMutationObserved) {
18919
+ this.dispatchEvent(mutationEvent);
18920
+ } else {
18921
+ mutationEvent.target = this;
18922
+ this.ownerDocument.defaultView.dispatchEvent(mutationEvent, true);
18923
+ }
17904
18924
  }
17905
18925
 
17906
18926
  if ((this.isCustomElement && this.isConnected || !this.isCustomElement) && this.attributeChangedCallback) {
@@ -18957,7 +19977,11 @@
18957
19977
  marker.setLocalPosition(ox + Math.cos(rad) * offset, oy + Math.sin(rad) * offset);
18958
19978
  };
18959
19979
 
18960
- _proto.getPoint = function getPoint(ratio) {
19980
+ _proto.getPoint = function getPoint(ratio, inWorldSpace) {
19981
+ if (inWorldSpace === void 0) {
19982
+ inWorldSpace = false;
19983
+ }
19984
+
18961
19985
  // TODO: account for z1/z2 in 3D line
18962
19986
  var _this$parsedStyle3 = this.parsedStyle,
18963
19987
  x1 = _this$parsedStyle3.x1,
@@ -18971,13 +19995,17 @@
18971
19995
  x = _LineUtil$pointAt.x,
18972
19996
  y = _LineUtil$pointAt.y;
18973
19997
 
18974
- var transformed = transformMat4(create$2(), fromValues$2(x - defX, y - defY, 0), this.getLocalTransform()); // apply local transformation
19998
+ var transformed = transformMat4(create$2(), fromValues$2(x - defX, y - defY, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform()); // apply local transformation
18975
19999
 
18976
20000
  return new Point(transformed[0], transformed[1]);
18977
20001
  };
18978
20002
 
18979
- _proto.getPointAtLength = function getPointAtLength(distance) {
18980
- return this.getPoint(distance / this.getTotalLength());
20003
+ _proto.getPointAtLength = function getPointAtLength(distance, inWorldSpace) {
20004
+ if (inWorldSpace === void 0) {
20005
+ inWorldSpace = false;
20006
+ }
20007
+
20008
+ return this.getPoint(distance / this.getTotalLength(), inWorldSpace);
18981
20009
  };
18982
20010
 
18983
20011
  _proto.getTotalLength = function getTotalLength() {
@@ -19174,7 +20202,11 @@
19174
20202
  */
19175
20203
  ;
19176
20204
 
19177
- _proto.getPointAtLength = function getPointAtLength$1(distance) {
20205
+ _proto.getPointAtLength = function getPointAtLength$1(distance, inWorldSpace) {
20206
+ if (inWorldSpace === void 0) {
20207
+ inWorldSpace = false;
20208
+ }
20209
+
19178
20210
  var _this$parsedStyle4 = this.parsedStyle,
19179
20211
  defX = _this$parsedStyle4.defX,
19180
20212
  defY = _this$parsedStyle4.defY,
@@ -19184,7 +20216,7 @@
19184
20216
  x = _getPointAtLength2.x,
19185
20217
  y = _getPointAtLength2.y;
19186
20218
 
19187
- var transformed = transformMat4(create$2(), fromValues$2(x - defX, y - defY, 0), this.getLocalTransform()); // apply local transformation
20219
+ var transformed = transformMat4(create$2(), fromValues$2(x - defX, y - defY, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform()); // apply local transformation
19188
20220
 
19189
20221
  return new Point(transformed[0], transformed[1]);
19190
20222
  }
@@ -19193,8 +20225,12 @@
19193
20225
  */
19194
20226
  ;
19195
20227
 
19196
- _proto.getPoint = function getPoint(ratio) {
19197
- return this.getPointAtLength(ratio * getOrCalculatePathTotalLength(this));
20228
+ _proto.getPoint = function getPoint(ratio, inWorldSpace) {
20229
+ if (inWorldSpace === void 0) {
20230
+ inWorldSpace = false;
20231
+ }
20232
+
20233
+ return this.getPointAtLength(ratio * getOrCalculatePathTotalLength(this), inWorldSpace);
19198
20234
  }
19199
20235
  /**
19200
20236
  * Get start tangent vector
@@ -19453,11 +20489,19 @@
19453
20489
  return this.parsedStyle.points.totalLength;
19454
20490
  };
19455
20491
 
19456
- _proto.getPointAtLength = function getPointAtLength(distance) {
19457
- return this.getPoint(distance / this.getTotalLength());
20492
+ _proto.getPointAtLength = function getPointAtLength(distance, inWorldSpace) {
20493
+ if (inWorldSpace === void 0) {
20494
+ inWorldSpace = false;
20495
+ }
20496
+
20497
+ return this.getPoint(distance / this.getTotalLength(), inWorldSpace);
19458
20498
  };
19459
20499
 
19460
- _proto.getPoint = function getPoint(ratio) {
20500
+ _proto.getPoint = function getPoint(ratio, inWorldSpace) {
20501
+ if (inWorldSpace === void 0) {
20502
+ inWorldSpace = false;
20503
+ }
20504
+
19461
20505
  var _this$parsedStyle = this.parsedStyle,
19462
20506
  defX = _this$parsedStyle.defX,
19463
20507
  defY = _this$parsedStyle.defY,
@@ -19477,7 +20521,7 @@
19477
20521
  x = _LineUtil$pointAt.x,
19478
20522
  y = _LineUtil$pointAt.y;
19479
20523
 
19480
- var transformed = transformMat4(create$2(), fromValues$2(x - defX, y - defY, 0), this.getLocalTransform()); // apply local transformation
20524
+ var transformed = transformMat4(create$2(), fromValues$2(x - defX, y - defY, 0), inWorldSpace ? this.getWorldTransform() : this.getLocalTransform()); // apply local transformation
19481
20525
 
19482
20526
  return new Point(transformed[0], transformed[1]);
19483
20527
  };
@@ -20203,7 +21247,7 @@
20203
21247
  ;
20204
21248
 
20205
21249
  _proto.setAzimuth = function setAzimuth(az) {
20206
- this.azimuth = getAngle(az);
21250
+ this.azimuth = getAngle$1(az);
20207
21251
  this.computeMatrix();
20208
21252
 
20209
21253
  this._getAxes();
@@ -20227,7 +21271,7 @@
20227
21271
  ;
20228
21272
 
20229
21273
  _proto.setElevation = function setElevation(el) {
20230
- this.elevation = getAngle(el);
21274
+ this.elevation = getAngle$1(el);
20231
21275
  this.computeMatrix();
20232
21276
 
20233
21277
  this._getAxes();
@@ -20251,7 +21295,7 @@
20251
21295
  ;
20252
21296
 
20253
21297
  _proto.setRoll = function setRoll(angle) {
20254
- this.roll = getAngle(angle);
21298
+ this.roll = getAngle$1(angle);
20255
21299
  this.computeMatrix();
20256
21300
 
20257
21301
  this._getAxes();
@@ -20665,7 +21709,7 @@
20665
21709
  var anchor = [0, 1];
20666
21710
  var lineXOffset = 0;
20667
21711
 
20668
- if (textAlign === 'center') {
21712
+ if (textAlign === 'center' || textAlign === 'middle') {
20669
21713
  lineXOffset = lineWidth / 2;
20670
21714
  anchor = [0.5, 1];
20671
21715
  } else if (textAlign === 'right' || textAlign === 'end') {
@@ -21390,10 +22434,20 @@
21390
22434
  }
21391
22435
  };
21392
22436
 
21393
- _proto.dispatchEvent = function dispatchEvent(e, type) {
21394
- e.propagationStopped = false;
21395
- e.propagationImmediatelyStopped = false;
21396
- this.propagate(e, type);
22437
+ _proto.dispatchEvent = function dispatchEvent(e, type, skipPropagate) {
22438
+ // Canvas should skip
22439
+ if (!skipPropagate) {
22440
+ e.propagationStopped = false;
22441
+ e.propagationImmediatelyStopped = false;
22442
+ this.propagate(e, type);
22443
+ } else {
22444
+ // target phase
22445
+ e.eventPhase = e.AT_TARGET;
22446
+ var canvas = this.rootTarget.defaultView || null;
22447
+ e.currentTarget = canvas;
22448
+ this.notifyListeners(e, type);
22449
+ }
22450
+
21397
22451
  this.emitter.emit(type || e.type, e);
21398
22452
  };
21399
22453
 
@@ -22199,10 +23253,11 @@
22199
23253
 
22200
23254
  if (renderOrderChanged) {
22201
23255
  displayObject.forEach(function (child) {
23256
+ _this2.renderOrderChangedEvent.target = child;
22202
23257
  _this2.renderOrderChangedEvent.detail = {
22203
23258
  renderOrder: child.sortable.renderOrder
22204
23259
  };
22205
- child.dispatchEvent(_this2.renderOrderChangedEvent);
23260
+ child.ownerDocument.defaultView.dispatchEvent(_this2.renderOrderChangedEvent, true);
22206
23261
  });
22207
23262
  }
22208
23263
  };
@@ -22863,9 +23918,10 @@
22863
23918
  var set = new Set();
22864
23919
 
22865
23920
  var trigger = function trigger(element, detail) {
22866
- if (!set.has(element.entity)) {
23921
+ if (element.isConnected && !set.has(element.entity)) {
22867
23922
  _this2.boundsChangedEvent.detail = detail;
22868
- element.dispatchEvent(_this2.boundsChangedEvent);
23923
+ _this2.boundsChangedEvent.target = element;
23924
+ element.ownerDocument.defaultView.dispatchEvent(_this2.boundsChangedEvent, true);
22869
23925
  set.add(element.entity);
22870
23926
  }
22871
23927
  };
@@ -22883,6 +23939,7 @@
22883
23939
  }
22884
23940
  });
22885
23941
  this.pendingEvents = [];
23942
+ set.clear();
22886
23943
  };
22887
23944
 
22888
23945
  _proto.dirtifyToRoot = function dirtifyToRoot(element, affectChildren) {
@@ -23533,7 +24590,7 @@
23533
24590
  lineMetrics: lineWidths.map(function (width, i) {
23534
24591
  var offsetX = 0; // handle horizontal text align
23535
24592
 
23536
- if (textAlign === 'center') {
24593
+ if (textAlign === 'center' || textAlign === 'middle') {
23537
24594
  offsetX -= width / 2;
23538
24595
  } else if (textAlign === 'right' || textAlign === 'end') {
23539
24596
  offsetX -= width;
@@ -24365,21 +25422,14 @@
24365
25422
 
24366
25423
  var _proto = PrepareRendererPlugin.prototype;
24367
25424
 
24368
- _proto.pushToSync = function pushToSync(list) {
24369
- var _this = this;
24370
-
24371
- list.forEach(function (i) {
24372
- _this.toSync.add(i);
24373
- });
24374
- } // private isFirstTimeRendering = true;
24375
- ;
24376
-
25425
+ // private isFirstTimeRendering = true;
24377
25426
  _proto.apply = function apply(context) {
24378
- var _this2 = this;
25427
+ var _this = this;
24379
25428
 
24380
25429
  var renderingService = context.renderingService,
24381
25430
  renderingContext = context.renderingContext,
24382
25431
  rBushRoot = context.rBushRoot;
25432
+ var canvas = renderingContext.root.ownerDocument.defaultView;
24383
25433
  this.rBush = rBushRoot;
24384
25434
 
24385
25435
  var handleAttributeChanged = function handleAttributeChanged(e) {
@@ -24394,20 +25444,26 @@
24394
25444
 
24395
25445
  if (affectChildren) {
24396
25446
  object.forEach(function (node) {
24397
- _this2.pushToSync([node]);
25447
+ _this.toSync.add(node);
24398
25448
  });
24399
25449
  }
24400
25450
 
24401
- _this2.pushToSync(e.composedPath().slice(0, -2));
25451
+ var p = object;
25452
+
25453
+ while (p) {
25454
+ if (p.renderable) {
25455
+ _this.toSync.add(p);
25456
+ }
25457
+
25458
+ p = p.parentElement;
25459
+ } // this.pushToSync(e.composedPath().slice(0, -2) as DisplayObject[]);
25460
+
24402
25461
 
24403
25462
  renderingService.dirtify();
24404
25463
  };
24405
25464
 
24406
25465
  var handleMounted = function handleMounted(e) {
24407
- var object = e.target;
24408
-
24409
- _this2.pushToSync(e.composedPath().slice(0, -2)); // recalc style values
24410
-
25466
+ var object = e.target; // recalc style values
24411
25467
 
24412
25468
  runtime.styleValueRegistry.recalc(object);
24413
25469
  runtime.sceneGraphService.dirtifyToRoot(object);
@@ -24419,12 +25475,12 @@
24419
25475
  var rBushNode = object.rBushNode;
24420
25476
 
24421
25477
  if (rBushNode.aabb) {
24422
- _this2.rBush.remove(rBushNode.aabb);
25478
+ _this.rBush.remove(rBushNode.aabb);
24423
25479
  }
24424
25480
 
24425
- _this2.toSync.delete(object);
25481
+ _this.toSync.delete(object);
24426
25482
 
24427
- runtime.sceneGraphService.dirtifyToRoot(e.target);
25483
+ runtime.sceneGraphService.dirtifyToRoot(object);
24428
25484
  renderingService.dirtify();
24429
25485
  };
24430
25486
 
@@ -24433,10 +25489,10 @@
24433
25489
  while (1) {
24434
25490
  switch (_context.prev = _context.next) {
24435
25491
  case 0:
24436
- renderingContext.root.addEventListener(exports.ElementEvent.MOUNTED, handleMounted);
24437
- renderingContext.root.addEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
24438
- renderingContext.root.addEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
24439
- renderingContext.root.addEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
25492
+ canvas.addEventListener(exports.ElementEvent.MOUNTED, handleMounted);
25493
+ canvas.addEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
25494
+ canvas.addEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
25495
+ canvas.addEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
24440
25496
 
24441
25497
  case 4:
24442
25498
  case "end":
@@ -24446,10 +25502,10 @@
24446
25502
  }, _callee);
24447
25503
  })));
24448
25504
  renderingService.hooks.destroy.tap(PrepareRendererPlugin.tag, function () {
24449
- renderingContext.root.removeEventListener(exports.ElementEvent.MOUNTED, handleMounted);
24450
- renderingContext.root.removeEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
24451
- renderingContext.root.removeEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
24452
- renderingContext.root.removeEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
25505
+ canvas.removeEventListener(exports.ElementEvent.MOUNTED, handleMounted);
25506
+ canvas.removeEventListener(exports.ElementEvent.UNMOUNTED, handleUnmounted);
25507
+ canvas.removeEventListener(exports.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
25508
+ canvas.removeEventListener(exports.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
24453
25509
  });
24454
25510
  renderingService.hooks.endFrame.tap(PrepareRendererPlugin.tag, function () {
24455
25511
  // if (this.isFirstTimeRendering) {
@@ -24459,12 +25515,12 @@
24459
25515
  // } else {
24460
25516
  // this.syncRTree();
24461
25517
  // }
24462
- _this2.syncRTree();
25518
+ _this.syncRTree();
24463
25519
  });
24464
25520
  };
24465
25521
 
24466
25522
  _proto.syncRTree = function syncRTree() {
24467
- var _this3 = this;
25523
+ var _this2 = this;
24468
25524
 
24469
25525
  // bounds changed, need re-inserting its children
24470
25526
  var bulk = [];
@@ -24475,7 +25531,7 @@
24475
25531
  var rBushNode = node.rBushNode; // clear dirty node
24476
25532
 
24477
25533
  if (rBushNode && rBushNode.aabb) {
24478
- _this3.rBush.remove(rBushNode.aabb);
25534
+ _this2.rBush.remove(rBushNode.aabb);
24479
25535
  }
24480
25536
 
24481
25537
  var renderBounds = node.getRenderBounds();
@@ -24536,8 +25592,8 @@
24536
25592
  * reuse custom event preventing from re-create them in every frame
24537
25593
  */
24538
25594
 
24539
- var mountEvent = new CustomEvent(exports.ElementEvent.MOUNTED);
24540
- var unmountEvent = new CustomEvent(exports.ElementEvent.UNMOUNTED);
25595
+ var mountedEvent = new CustomEvent(exports.ElementEvent.MOUNTED);
25596
+ var unmountedEvent = new CustomEvent(exports.ElementEvent.UNMOUNTED);
24541
25597
  var beforeRenderEvent = new CustomEvent(exports.CanvasEvent.BEFORE_RENDER);
24542
25598
  var afterRenderEvent = new CustomEvent(exports.CanvasEvent.AFTER_RENDER);
24543
25599
  /**
@@ -25052,13 +26108,20 @@
25052
26108
 
25053
26109
  path.reverse().forEach(function (child) {
25054
26110
  // trigger before unmounted
25055
- if (child instanceof CustomElement) {
26111
+ if (child.isCustomElement) {
25056
26112
  if (child.disconnectedCallback) {
25057
26113
  child.disconnectedCallback();
25058
26114
  }
25059
26115
  }
25060
26116
 
25061
- child.dispatchEvent(unmountEvent); // skip document.documentElement
26117
+ if (child.isMutationObserved) {
26118
+ child.dispatchEvent(unmountedEvent);
26119
+ } else {
26120
+ unmountedEvent.target = child;
26121
+
26122
+ _this5.dispatchEvent(unmountedEvent, true);
26123
+ } // skip document.documentElement
26124
+
25062
26125
 
25063
26126
  if (child !== _this5.document.documentElement) {
25064
26127
  child.ownerDocument = null;
@@ -25077,9 +26140,17 @@
25077
26140
  if (!child.isConnected) {
25078
26141
  child.ownerDocument = _this6.document;
25079
26142
  child.isConnected = true;
25080
- child.dispatchEvent(mountEvent); // trigger after mounted
25081
26143
 
25082
- if (child instanceof CustomElement) {
26144
+ if (child.isMutationObserved) {
26145
+ child.dispatchEvent(mountedEvent);
26146
+ } else {
26147
+ mountedEvent.target = child;
26148
+
26149
+ _this6.dispatchEvent(mountedEvent, true);
26150
+ } // trigger after mounted
26151
+
26152
+
26153
+ if (child.isCustomElement) {
25083
26154
  if (child.connectedCallback) {
25084
26155
  child.connectedCallback();
25085
26156
  }
@@ -25221,7 +26292,8 @@
25221
26292
  exports.deg2rad = deg2rad;
25222
26293
  exports.deg2turn = deg2turn;
25223
26294
  exports.findClosestClipPathTarget = findClosestClipPathTarget;
25224
- exports.getAngle = getAngle;
26295
+ exports.fromRotationTranslationScale = fromRotationTranslationScale$1;
26296
+ exports.getAngle = getAngle$1;
25225
26297
  exports.getEuler = getEuler;
25226
26298
  exports.getOrCalculatePathTotalLength = getOrCalculatePathTotalLength;
25227
26299
  exports.grad2deg = grad2deg;