@antv/g 5.2.0 → 5.2.3

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.
package/dist/index.esm.js CHANGED
@@ -5,11 +5,11 @@ export { default as RBush } from 'rbush';
5
5
  import 'reflect-metadata';
6
6
  import { __decorate, __param, __metadata } from 'tslib';
7
7
  import { vec3, mat3, mat4, quat, vec4 } from 'gl-matrix';
8
- import { Cubic as Cubic$1, Polyline as Polyline$1, Line as Line$1 } from '@antv/g-math';
9
8
  import { EventEmitter } from 'eventemitter3';
10
9
  import { color } from 'd3-color';
11
- import memoize from 'lodash.memoize';
12
- import { path2Absolute, path2Curve, path2Segments } from '@antv/util';
10
+ import { memoize } from 'lodash-es';
11
+ import { normalizePath, path2Curve, getPathBBoxTotalLength, equalizeSegments, getDrawDirection, reverseCurve, clonePath, getRotatedCurve, getPointAtLength } from '@antv/util';
12
+ import { Polyline as Polyline$1, Line as Line$1 } from '@antv/g-math';
13
13
  import { requestAnimationFrame as requestAnimationFrame$1, cancelAnimationFrame as cancelAnimationFrame$1 } from 'request-animation-frame-polyfill';
14
14
 
15
15
  function _regeneratorRuntime() {
@@ -413,7 +413,7 @@ function _createClass(Constructor, protoProps, staticProps) {
413
413
  }
414
414
 
415
415
  function _extends() {
416
- _extends = Object.assign || function (target) {
416
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
417
417
  for (var i = 1; i < arguments.length; i++) {
418
418
  var source = arguments[i];
419
419
 
@@ -426,7 +426,6 @@ function _extends() {
426
426
 
427
427
  return target;
428
428
  };
429
-
430
429
  return _extends.apply(this, arguments);
431
430
  }
432
431
 
@@ -438,11 +437,10 @@ function _inheritsLoose(subClass, superClass) {
438
437
  }
439
438
 
440
439
  function _setPrototypeOf(o, p) {
441
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
440
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
442
441
  o.__proto__ = p;
443
442
  return o;
444
443
  };
445
-
446
444
  return _setPrototypeOf(o, p);
447
445
  }
448
446
 
@@ -461,7 +459,7 @@ function _isNativeReflectConstruct() {
461
459
 
462
460
  function _construct(Parent, args, Class) {
463
461
  if (_isNativeReflectConstruct()) {
464
- _construct = Reflect.construct;
462
+ _construct = Reflect.construct.bind();
465
463
  } else {
466
464
  _construct = function _construct(Parent, args, Class) {
467
465
  var a = [null];
@@ -2583,210 +2581,134 @@ var Shape;
2583
2581
 
2584
2582
  var CanvasConfig = Syringe.defineToken('CanvasConfig');
2585
2583
 
2586
- /**
2587
- * implements morph animation with cubic splitting
2588
- * @see http://thednp.github.io/kute.js/svgCubicMorph.html
2589
- */
2584
+ function hasArcOrBezier(path) {
2585
+ var hasArc = false;
2586
+ var count = path.length;
2590
2587
 
2591
- function midPoint(a, b, t) {
2592
- var ax = a[0];
2593
- var ay = a[1];
2594
- var bx = b[0];
2595
- var by = b[1];
2596
- return [ax + (bx - ax) * t, ay + (by - ay) * t];
2597
- }
2588
+ for (var i = 0; i < count; i++) {
2589
+ var params = path[i];
2590
+ var cmd = params[0];
2591
+
2592
+ if (cmd === 'C' || cmd === 'A' || cmd === 'Q') {
2593
+ hasArc = true;
2594
+ break;
2595
+ }
2596
+ }
2598
2597
 
2599
- function splitCubic(pts, t) {
2600
- if (t === void 0) {
2601
- t = 0.5;
2602
- }
2603
-
2604
- var p0 = pts.slice(0, 2);
2605
- var p1 = pts.slice(2, 4);
2606
- var p2 = pts.slice(4, 6);
2607
- var p3 = pts.slice(6, 8);
2608
- var p4 = midPoint(p0, p1, t);
2609
- var p5 = midPoint(p1, p2, t);
2610
- var p6 = midPoint(p2, p3, t);
2611
- var p7 = midPoint(p4, p5, t);
2612
- var p8 = midPoint(p5, p6, t);
2613
- var p9 = midPoint(p7, p8, t);
2614
- return [// @ts-ignore
2615
- ['C'].concat(p4, p7, p9), // @ts-ignore
2616
- ['C'].concat(p8, p6, p3)];
2598
+ return hasArc;
2617
2599
  }
2600
+ function extractPolygons(pathArray) {
2601
+ var polygons = [];
2602
+ var polylines = [];
2603
+ var points = []; // 防止第一个命令不是 'M'
2618
2604
 
2619
- function getCurveArray(segments) {
2620
- return segments.map(function (segment, i, pathArray) {
2621
- // @ts-ignore
2622
- var segmentData = i && pathArray[i - 1].slice(-2).concat(segment.slice(1)); // @ts-ignore
2605
+ for (var i = 0; i < pathArray.length; i++) {
2606
+ var params = pathArray[i];
2607
+ var cmd = params[0];
2623
2608
 
2624
- var curveLength = i ? Cubic$1.length.apply(Cubic$1, segmentData) : 0;
2625
- var subsegs;
2609
+ if (cmd === 'M') {
2610
+ // 遇到 'M' 判定是否是新数组,新数组中没有点
2611
+ if (points.length) {
2612
+ // 如果存在点,则说明没有遇到 'Z',开始了一个新的多边形
2613
+ polylines.push(points);
2614
+ points = []; // 创建新的点
2615
+ }
2616
+
2617
+ points.push([params[1], params[2]]);
2618
+ } else if (cmd === 'Z') {
2619
+ if (points.length) {
2620
+ // 存在点
2621
+ polygons.push(points);
2622
+ points = []; // 开始新的点集合
2623
+ } // 如果不存在点,同时 'Z',则说明是错误,不处理
2626
2624
 
2627
- if (i) {
2628
- // must be [segment,segment]
2629
- subsegs = curveLength ? splitCubic(segmentData) : [segment, segment];
2630
2625
  } else {
2631
- subsegs = [segment];
2626
+ points.push([params[1], params[2]]);
2632
2627
  }
2628
+ } // 说明 points 未放入 polygons 或者 polyline
2629
+ // 仅当只有一个 M,没有 Z 时会发生这种情况
2633
2630
 
2634
- return {
2635
- s: segment,
2636
- ss: subsegs,
2637
- l: curveLength
2638
- };
2639
- });
2640
- }
2641
2631
 
2642
- function equalizeSegments(path1, path2, TL) {
2643
- var c1 = getCurveArray(path1);
2644
- var c2 = getCurveArray(path2);
2645
- var L1 = c1.length;
2646
- var L2 = c2.length;
2647
- var l1 = c1.filter(function (x) {
2648
- return x.l;
2649
- }).length;
2650
- var l2 = c2.filter(function (x) {
2651
- return x.l;
2652
- }).length;
2653
- var m1 = c1.filter(function (x) {
2654
- return x.l;
2655
- }).reduce(function (a, _ref) {
2656
- var l = _ref.l;
2657
- return a + l;
2658
- }, 0) / l1 || 0;
2659
- var m2 = c2.filter(function (x) {
2660
- return x.l;
2661
- }).reduce(function (a, _ref2) {
2662
- var l = _ref2.l;
2663
- return a + l;
2664
- }, 0) / l2 || 0;
2665
- var tl = TL || Math.max(L1, L2);
2666
- var mm = [m1, m2];
2667
- var dif = [tl - L1, tl - L2];
2668
- var canSplit = 0;
2669
- var result = [c1, c2].map(function (x, i) {
2670
- return (// @ts-ignore
2671
- x.l === tl ? x.map(function (y) {
2672
- return y.s;
2673
- }) : x.map(function (y, j) {
2674
- canSplit = j && dif[i] && y.l >= mm[i];
2675
- dif[i] -= canSplit ? 1 : 0;
2676
- return canSplit ? y.ss : [y.s];
2677
- }).flat()
2678
- );
2679
- });
2680
- return result[0].length === result[1].length ? result : equalizeSegments(result[0], result[1], tl);
2681
- }
2682
- function getDrawDirection(pathArray) {
2683
- return getPathArea(pathArray) >= 0;
2632
+ if (points.length > 0) {
2633
+ polylines.push(points);
2634
+ }
2635
+
2636
+ return {
2637
+ polygons: polygons,
2638
+ polylines: polylines
2639
+ };
2684
2640
  }
2685
2641
 
2686
- function getCubicSegArea(x0, y0, x1, y1, x2, y2, x3, y3) {
2687
- // https://stackoverflow.com/a/15845996
2688
- return 3 * ((y3 - y0) * (x1 + x2) - (x3 - x0) * (y1 + y2) + y1 * (x0 - x2) - x1 * (y0 - y2) + y3 * (x2 + x0 / 3) - x3 * (y2 + y0 / 3)) / 20;
2642
+ function isSamePoint(point1, point2) {
2643
+ return point1[0] === point2[0] && point1[1] === point2[1];
2689
2644
  }
2690
2645
 
2691
- function getPathArea(pathArray) {
2692
- var x = 0;
2693
- var y = 0;
2694
- var mx = 0;
2695
- var my = 0;
2696
- var len = 0;
2697
- return pathArray.map(function (seg) {
2698
- switch (seg[0]) {
2646
+ function path2Segments(path) {
2647
+ var segments = [];
2648
+ var currentPoint = null; // 当前图形
2649
+
2650
+ var nextParams = null; // 下一节点的 path 参数
2651
+ // let startMovePoint = null; // 开始 M 的点,可能会有多个
2652
+
2653
+ var lastStartMovePointIndex = 0; // 最近一个开始点 M 的索引
2654
+
2655
+ var count = path.length;
2656
+
2657
+ for (var i = 0; i < count; i++) {
2658
+ var params = path[i];
2659
+ nextParams = path[i + 1];
2660
+ var command = params[0]; // 数学定义上的参数,便于后面的计算
2661
+
2662
+ var segment = {
2663
+ command: command,
2664
+ prePoint: currentPoint,
2665
+ params: params,
2666
+ startTangent: null,
2667
+ endTangent: null
2668
+ };
2669
+
2670
+ switch (command) {
2699
2671
  case 'M':
2700
- case 'Z':
2701
- mx = seg[0] === 'M' ? seg[1] : mx;
2702
- my = seg[0] === 'M' ? seg[2] : my;
2703
- x = mx;
2704
- y = my;
2705
- return 0;
2672
+ // startMovePoint = [params[1], params[2]];
2673
+ lastStartMovePointIndex = i;
2674
+ break;
2675
+ }
2706
2676
 
2707
- default:
2708
- // @ts-ignore
2709
- len = getCubicSegArea.apply(0, [x, y].concat(seg.slice(1)));
2710
-
2711
- var _seg$slice = seg.slice(-2);
2712
-
2713
- x = _seg$slice[0];
2714
- y = _seg$slice[1];
2715
- return len;
2716
- }
2717
- }).reduce(function (a, b) {
2718
- return a + b;
2719
- }, 0);
2720
- } // reverse CURVE based pathArray segments only
2721
-
2722
- function reverseCurve(pathArray) {
2723
- var rotatedCurve = pathArray.slice(1).map(function (x, i, curveOnly) {
2724
- return (// @ts-ignore
2725
- !i ? pathArray[0].slice(1).concat(x.slice(1)) : curveOnly[i - 1].slice(-2).concat(x.slice(1))
2726
- );
2727
- }) // @ts-ignore
2728
- .map(function (x) {
2729
- return x.map(function (y, i) {
2730
- return x[x.length - i - 2 * (1 - i % 2)];
2731
- });
2732
- }).reverse(); // @ts-ignore
2677
+ var len = params.length;
2678
+ currentPoint = [params[len - 2], params[len - 1]]; // @ts-ignore
2733
2679
 
2734
- return [['M'].concat(rotatedCurve[0].slice(0, 2))].concat(rotatedCurve.map(function (x) {
2735
- return ['C'].concat(x.slice(2));
2736
- }));
2737
- }
2738
- function clonePath(pathArray) {
2739
- // @ts-ignore
2740
- return pathArray.map(function (x) {
2741
- if (Array.isArray(x)) {
2742
- // @ts-ignore
2743
- return clonePath(x);
2680
+ segment.currentPoint = currentPoint; // 如果当前点与最近一个 M 点相同,则最近一个 M 点的前一个点为当前点的前一个点
2681
+
2682
+ if (segments[lastStartMovePointIndex] && isSamePoint(currentPoint, segments[lastStartMovePointIndex].currentPoint)) {
2683
+ segments[lastStartMovePointIndex].prePoint = segment.prePoint;
2744
2684
  }
2745
2685
 
2746
- return !Number.isNaN(+x) ? +x : x;
2747
- });
2748
- }
2686
+ var nextPoint = nextParams ? [nextParams[nextParams.length - 2], nextParams[nextParams.length - 1]] : null; // @ts-ignore
2687
+
2688
+ segment.nextPoint = nextPoint; // Add startTangent and endTangent
2749
2689
 
2750
- function getRotations(a) {
2751
- var segCount = a.length;
2752
- var pointCount = segCount - 1;
2753
- return a.map(function (f, idx) {
2754
- return a.map(function (p, i) {
2755
- var oldSegIdx = idx + i;
2756
- var seg;
2690
+ var prePoint = segment.prePoint;
2757
2691
 
2758
- if (i === 0 || a[oldSegIdx] && a[oldSegIdx][0] === 'M') {
2759
- seg = a[oldSegIdx]; // @ts-ignore
2692
+ if (command === 'C') {
2693
+ // 三次贝塞尔曲线有两个控制点
2694
+ var cp1 = [params[1], params[2]];
2695
+ var cp2 = [params[3], params[4]];
2696
+ segment.startTangent = [prePoint[0] - cp1[0], prePoint[1] - cp1[1]];
2697
+ segment.endTangent = [currentPoint[0] - cp2[0], currentPoint[1] - cp2[1]]; // horizontal line, eg. ['C', 100, 100, 100, 100, 200, 200]
2760
2698
 
2761
- return ['M'].concat(seg.slice(-2));
2699
+ if (segment.startTangent[0] === 0 && segment.startTangent[1] === 0) {
2700
+ segment.startTangent = [cp1[0] - cp2[0], cp1[1] - cp2[1]];
2762
2701
  }
2763
2702
 
2764
- if (oldSegIdx >= segCount) oldSegIdx -= pointCount;
2765
- return a[oldSegIdx];
2766
- });
2767
- });
2768
- }
2703
+ if (segment.endTangent[0] === 0 && segment.endTangent[1] === 0) {
2704
+ segment.endTangent = [cp2[0] - cp1[0], cp2[1] - cp1[1]];
2705
+ }
2706
+ }
2769
2707
 
2770
- function distanceSquareRoot(a, b) {
2771
- return Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]));
2772
- }
2708
+ segments.push(segment);
2709
+ }
2773
2710
 
2774
- function getRotatedCurve(a, b) {
2775
- var segCount = a.length - 1;
2776
- var lineLengths = [];
2777
- var computedIndex = 0;
2778
- var sumLensSqrd = 0;
2779
- var rotations = getRotations(a);
2780
- rotations.forEach(function (r, i) {
2781
- a.slice(1).forEach(function (s, j) {
2782
- // @ts-ignore
2783
- sumLensSqrd += distanceSquareRoot(a[(i + j) % segCount].slice(-2), b[j % segCount].slice(-2));
2784
- });
2785
- lineLengths[i] = sumLensSqrd;
2786
- sumLensSqrd = 0;
2787
- });
2788
- computedIndex = lineLengths.indexOf(Math.min.apply(null, lineLengths));
2789
- return rotations[computedIndex];
2711
+ return segments;
2790
2712
  }
2791
2713
 
2792
2714
  function commandsToPathString(commands, object, applyLocalTransform) {
@@ -2971,6 +2893,37 @@ function convertToPath(object, applyLocalTransform) {
2971
2893
  return commandsToPathString(commands, object, applyLocalTransform);
2972
2894
  }
2973
2895
  }
2896
+ function translatePathToString(pathArray, x, y) {
2897
+ var newValue = pathArray.map(function (params) {
2898
+ var command = params[0];
2899
+
2900
+ switch (command) {
2901
+ case 'M':
2902
+ return "M " + (params[1] - x) + "," + (params[2] - y);
2903
+
2904
+ case 'L':
2905
+ return "L " + (params[1] - x) + "," + (params[2] - y);
2906
+
2907
+ case 'Q':
2908
+ return "Q " + (params[1] - x) + " " + (params[2] - y) + "," + (params[3] - x) + " " + (params[4] - y);
2909
+
2910
+ case 'C':
2911
+ return "C " + (params[1] - x) + " " + (params[2] - y) + "," + (params[3] - x) + " " + (params[4] - y) + "," + (params[5] - x) + " " + (params[6] - y);
2912
+
2913
+ case 'A':
2914
+ return "A " + params[1] + " " + params[2] + " " + params[3] + " " + params[4] + " " + params[5] + " " + (params[6] - x) + " " + (params[7] - y);
2915
+
2916
+ case 'Z':
2917
+ return 'Z';
2918
+ }
2919
+ }).join(' ');
2920
+
2921
+ if (~newValue.indexOf('NaN')) {
2922
+ return '';
2923
+ }
2924
+
2925
+ return newValue;
2926
+ }
2974
2927
 
2975
2928
  // @ts-nocheck
2976
2929
  // interface HookInterceptor<T, R, AdditionalOptions = UnsetAdditionalOptions> {
@@ -8205,31 +8158,40 @@ function mergeNumberLists(left, right) {
8205
8158
  }
8206
8159
 
8207
8160
  function parsePath(path, object) {
8208
- var absolutePath = path2Absolute(path);
8161
+ var absolutePath;
8162
+
8163
+ try {
8164
+ absolutePath = normalizePath(path);
8165
+ } catch (e) {
8166
+ absolutePath = normalizePath('');
8167
+ console.error("[g]: Invalid SVG Path definition: " + path);
8168
+ }
8169
+
8209
8170
  var hasArc = hasArcOrBezier(absolutePath);
8210
- var clonedAbsolutePath = absolutePath.slice();
8211
8171
 
8212
- var _extractPolygons = extractPolygons(clonedAbsolutePath),
8172
+ var _extractPolygons = extractPolygons(absolutePath),
8213
8173
  polygons = _extractPolygons.polygons,
8214
8174
  polylines = _extractPolygons.polylines; // convert to curves to do morphing & picking later
8215
8175
  // @see http://thednp.github.io/kute.js/svgCubicMorph.html
8216
8176
 
8217
8177
 
8218
- var _path2Curve = path2Curve(clonedAbsolutePath, true),
8178
+ var _path2Curve = path2Curve(absolutePath, true),
8219
8179
  curve = _path2Curve[0],
8220
- zCommandIndexes = _path2Curve[1];
8180
+ zCommandIndexes = _path2Curve[1]; // for later use
8221
8181
 
8222
- var segments = path2Segments(clonedAbsolutePath);
8223
8182
 
8224
- var _calcLength = calcLength(curve),
8225
- totalLength = _calcLength.totalLength,
8226
- curveSegments = _calcLength.curveSegments;
8183
+ var segments = path2Segments(curve);
8227
8184
 
8228
- var rect = getPathBBox(curve);
8185
+ var _getPathBBoxTotalLeng = getPathBBoxTotalLength(absolutePath),
8186
+ x = _getPathBBoxTotalLeng.x,
8187
+ y = _getPathBBoxTotalLeng.y,
8188
+ width = _getPathBBoxTotalLeng.width,
8189
+ height = _getPathBBoxTotalLeng.height,
8190
+ length = _getPathBBoxTotalLeng.length;
8229
8191
 
8230
8192
  if (object) {
8231
- object.parsedStyle.defX = rect.x;
8232
- object.parsedStyle.defY = rect.y;
8193
+ object.parsedStyle.defX = x;
8194
+ object.parsedStyle.defY = y;
8233
8195
  }
8234
8196
 
8235
8197
  return {
@@ -8239,158 +8201,11 @@ function parsePath(path, object) {
8239
8201
  polygons: polygons,
8240
8202
  polylines: polylines,
8241
8203
  curve: curve,
8242
- totalLength: totalLength,
8243
- curveSegments: curveSegments,
8204
+ totalLength: length,
8244
8205
  zCommandIndexes: zCommandIndexes,
8245
- rect: rect
8206
+ rect: new Rectangle(x, y, width, height)
8246
8207
  };
8247
8208
  }
8248
-
8249
- function hasArcOrBezier(path) {
8250
- var hasArc = false;
8251
- var count = path.length;
8252
-
8253
- for (var i = 0; i < count; i++) {
8254
- var params = path[i];
8255
- var cmd = params[0];
8256
-
8257
- if (cmd === 'C' || cmd === 'A' || cmd === 'Q') {
8258
- hasArc = true;
8259
- break;
8260
- }
8261
- }
8262
-
8263
- return hasArc;
8264
- }
8265
-
8266
- function extractPolygons(pathArray) {
8267
- var polygons = [];
8268
- var polylines = [];
8269
- var points = []; // 防止第一个命令不是 'M'
8270
-
8271
- for (var i = 0; i < pathArray.length; i++) {
8272
- var params = pathArray[i];
8273
- var cmd = params[0];
8274
-
8275
- if (cmd === 'M') {
8276
- // 遇到 'M' 判定是否是新数组,新数组中没有点
8277
- if (points.length) {
8278
- // 如果存在点,则说明没有遇到 'Z',开始了一个新的多边形
8279
- polylines.push(points);
8280
- points = []; // 创建新的点
8281
- }
8282
-
8283
- points.push([params[1], params[2]]);
8284
- } else if (cmd === 'Z') {
8285
- if (points.length) {
8286
- // 存在点
8287
- polygons.push(points);
8288
- points = []; // 开始新的点集合
8289
- } // 如果不存在点,同时 'Z',则说明是错误,不处理
8290
-
8291
- } else {
8292
- points.push([params[1], params[2]]);
8293
- }
8294
- } // 说明 points 未放入 polygons 或者 polyline
8295
- // 仅当只有一个 M,没有 Z 时会发生这种情况
8296
-
8297
-
8298
- if (points.length > 0) {
8299
- polylines.push(points);
8300
- }
8301
-
8302
- return {
8303
- polygons: polygons,
8304
- polylines: polylines
8305
- };
8306
- }
8307
-
8308
- function calcLength(curve) {
8309
- var totalLength = 0;
8310
- var tempLength = 0; // 每段 curve 对应起止点的长度比例列表,形如: [[0, 0.25], [0.25, 0.6]. [0.6, 0.9], [0.9, 1]]
8311
-
8312
- var curveSegments = [];
8313
- var segmentT;
8314
- var segmentL;
8315
- var segmentN;
8316
- var l;
8317
-
8318
- if (!curve) {
8319
- return {
8320
- curveSegments: [],
8321
- totalLength: totalLength
8322
- };
8323
- }
8324
-
8325
- curve.forEach(function (segment, i) {
8326
- segmentN = curve[i + 1];
8327
- l = segment.length;
8328
-
8329
- if (segmentN) {
8330
- totalLength += Cubic$1.length(segment[l - 2], segment[l - 1], segmentN[1], segmentN[2], segmentN[3], segmentN[4], segmentN[5], segmentN[6]) || 0;
8331
- }
8332
- });
8333
-
8334
- if (totalLength === 0) {
8335
- return {
8336
- curveSegments: [],
8337
- totalLength: totalLength
8338
- };
8339
- }
8340
-
8341
- curve.forEach(function (segment, i) {
8342
- segmentN = curve[i + 1];
8343
- l = segment.length;
8344
-
8345
- if (segmentN) {
8346
- segmentT = [];
8347
- segmentT[0] = tempLength / totalLength;
8348
- segmentL = Cubic$1.length(segment[l - 2], segment[l - 1], segmentN[1], segmentN[2], segmentN[3], segmentN[4], segmentN[5], segmentN[6]); // 当 path 不连续时,segmentL 可能为空,为空时需要作为 0 处理
8349
-
8350
- tempLength += segmentL || 0;
8351
- segmentT[1] = tempLength / totalLength;
8352
- curveSegments.push(segmentT);
8353
- }
8354
- });
8355
- return {
8356
- curveSegments: curveSegments,
8357
- totalLength: totalLength
8358
- };
8359
- }
8360
-
8361
- function getPathBBox(segments) {
8362
- var x = 0;
8363
- var y = 0;
8364
- var X = [];
8365
- var Y = [];
8366
- segments.forEach(function (segment) {
8367
- var _segment$slice = segment.slice(-2),
8368
- s1 = _segment$slice[0],
8369
- s2 = _segment$slice[1];
8370
-
8371
- if (segment[0] === 'M') {
8372
- x = s1;
8373
- y = s2;
8374
- X.push(s1);
8375
- Y.push(s2);
8376
- } else if (segment[0] === 'C') {
8377
- // @ts-ignore
8378
- var dim = Cubic$1.box.apply(Cubic$1, [x, y].concat(segment.slice(1)));
8379
- X = X.concat(dim.x, dim.x + dim.width);
8380
- Y = Y.concat(dim.y, dim.y + dim.height);
8381
- x = s1;
8382
- y = s2;
8383
- }
8384
- });
8385
- var xTop = Math.min.apply(0, X);
8386
- var yTop = Math.min.apply(0, Y);
8387
- var xBot = Math.max.apply(0, X);
8388
- var yBot = Math.max.apply(0, Y);
8389
- var width = xBot - xTop;
8390
- var height = yBot - yTop;
8391
- return new Rectangle(xTop, yTop, width, height);
8392
- }
8393
-
8394
8209
  function mergePaths(left, right, object) {
8395
8210
  var curve1 = left.curve;
8396
8211
  var curve2 = right.curve;
@@ -12328,37 +12143,13 @@ var Path = /*#__PURE__*/function (_DisplayObject) {
12328
12143
  ;
12329
12144
 
12330
12145
  _proto.getPoint = function getPoint(ratio) {
12331
- var subt = 0;
12332
- var index = 0;
12333
- var curve = this.parsedStyle.path.curve;
12334
-
12335
- if (!this.parsedStyle.path.curveSegments.length) {
12336
- if (curve) {
12337
- return new Point(curve[0][1], curve[0][2]);
12338
- }
12146
+ var _this$parsedStyle$pat = this.parsedStyle.path,
12147
+ totalLength = _this$parsedStyle$pat.totalLength,
12148
+ absolutePath = _this$parsedStyle$pat.absolutePath;
12339
12149
 
12340
- return null;
12341
- }
12342
-
12343
- this.parsedStyle.path.curveSegments.forEach(function (v, i) {
12344
- if (ratio >= v[0] && ratio <= v[1]) {
12345
- subt = (ratio - v[0]) / (v[1] - v[0]);
12346
- index = i;
12347
- }
12348
- });
12349
- var seg = curve[index];
12350
-
12351
- if (isNil(seg) || isNil(index)) {
12352
- return null;
12353
- }
12354
-
12355
- var l = seg.length;
12356
- var nextSeg = curve[index + 1];
12357
-
12358
- var _CubicUtil$pointAt = Cubic$1.pointAt( // @ts-ignore
12359
- seg[l - 2], seg[l - 1], nextSeg[1], nextSeg[2], nextSeg[3], nextSeg[4], nextSeg[5], nextSeg[6], subt),
12360
- x = _CubicUtil$pointAt.x,
12361
- y = _CubicUtil$pointAt.y;
12150
+ var _getPointAtLength = getPointAtLength(absolutePath, ratio * totalLength),
12151
+ x = _getPointAtLength.x,
12152
+ y = _getPointAtLength.y;
12362
12153
 
12363
12154
  return new Point(x, y);
12364
12155
  }
@@ -18426,143 +18217,6 @@ PathUpdater = __decorate([singleton({
18426
18217
  named: Shape.PATH
18427
18218
  }
18428
18219
  })], PathUpdater);
18429
- // let xArr = [];
18430
- // let yArr = [];
18431
- // const segmentsWithAngle = [];
18432
- // for (let i = 0; i < segments.length; i++) {
18433
- // const segment = segments[i];
18434
- // const { currentPoint, params, prePoint } = segment;
18435
- // let box;
18436
- // switch (segment.command) {
18437
- // case 'Q':
18438
- // box = QuadUtil.box(prePoint[0], prePoint[1], params[1], params[2], params[3], params[4]);
18439
- // break;
18440
- // case 'C':
18441
- // box = CubicUtil.box(
18442
- // prePoint[0],
18443
- // prePoint[1],
18444
- // params[1],
18445
- // params[2],
18446
- // params[3],
18447
- // params[4],
18448
- // params[5],
18449
- // params[6],
18450
- // );
18451
- // break;
18452
- // case 'A':
18453
- // // eslint-disable-next-line no-case-declarations
18454
- // const { arcParams } = segment;
18455
- // box = EllipseArcUtil.box(
18456
- // arcParams.cx,
18457
- // arcParams.cy,
18458
- // arcParams.rx,
18459
- // arcParams.ry,
18460
- // arcParams.xRotation,
18461
- // arcParams.startAngle,
18462
- // arcParams.endAngle,
18463
- // );
18464
- // break;
18465
- // default:
18466
- // xArr.push(currentPoint[0]);
18467
- // yArr.push(currentPoint[1]);
18468
- // break;
18469
- // }
18470
- // if (box) {
18471
- // segment.box = box;
18472
- // xArr.push(box.x, box.x + box.width);
18473
- // yArr.push(box.y, box.y + box.height);
18474
- // }
18475
- // if (
18476
- // lineWidth &&
18477
- // (segment.command === 'L' || segment.command === 'M') &&
18478
- // segment.prePoint &&
18479
- // segment.nextPoint
18480
- // ) {
18481
- // segmentsWithAngle.push(segment);
18482
- // }
18483
- // }
18484
- // // bbox calculation should ignore NaN for path attribute
18485
- // // ref: https://github.com/antvis/g/issues/210
18486
- // xArr = xArr.filter((item) => !Number.isNaN(item));
18487
- // yArr = yArr.filter((item) => !Number.isNaN(item));
18488
- // let minX = min(xArr);
18489
- // let minY = min(yArr);
18490
- // let maxX = max(xArr);
18491
- // let maxY = max(yArr);
18492
- // if (segmentsWithAngle.length === 0) {
18493
- // return {
18494
- // x: minX,
18495
- // y: minY,
18496
- // width: maxX - minX,
18497
- // height: maxY - minY,
18498
- // };
18499
- // }
18500
- // for (let i = 0; i < segmentsWithAngle.length; i++) {
18501
- // const segment = segmentsWithAngle[i];
18502
- // const { currentPoint } = segment;
18503
- // let extra;
18504
- // if (currentPoint[0] === minX) {
18505
- // extra = getExtraFromSegmentWithAngle(segment, lineWidth);
18506
- // minX -= extra.xExtra;
18507
- // } else if (currentPoint[0] === maxX) {
18508
- // extra = getExtraFromSegmentWithAngle(segment, lineWidth);
18509
- // maxX += extra.xExtra;
18510
- // }
18511
- // if (currentPoint[1] === minY) {
18512
- // extra = getExtraFromSegmentWithAngle(segment, lineWidth);
18513
- // minY -= extra.yExtra;
18514
- // } else if (currentPoint[1] === maxY) {
18515
- // extra = getExtraFromSegmentWithAngle(segment, lineWidth);
18516
- // maxY += extra.yExtra;
18517
- // }
18518
- // }
18519
- // return {
18520
- // x: minX,
18521
- // y: minY,
18522
- // width: maxX - minX,
18523
- // height: maxY - minY,
18524
- // };
18525
- // }
18526
- // function getExtraFromSegmentWithAngle(segment: any, lineWidth: number) {
18527
- // const { prePoint, currentPoint, nextPoint } = segment;
18528
- // const currentAndPre =
18529
- // Math.pow(currentPoint[0] - prePoint[0], 2) + Math.pow(currentPoint[1] - prePoint[1], 2);
18530
- // const currentAndNext =
18531
- // Math.pow(currentPoint[0] - nextPoint[0], 2) + Math.pow(currentPoint[1] - nextPoint[1], 2);
18532
- // const preAndNext =
18533
- // Math.pow(prePoint[0] - nextPoint[0], 2) + Math.pow(prePoint[1] - nextPoint[1], 2);
18534
- // // 以 currentPoint 为顶点的夹角
18535
- // const currentAngle = Math.acos(
18536
- // (currentAndPre + currentAndNext - preAndNext) /
18537
- // (2 * Math.sqrt(currentAndPre) * Math.sqrt(currentAndNext)),
18538
- // );
18539
- // // 夹角为空、 0 或 PI 时,不需要计算夹角处的额外宽度
18540
- // // 注意: 由于计算精度问题,夹角为 0 的情况计算出来的角度可能是一个很小的值,还需要判断其与 0 是否近似相等
18541
- // if (!currentAngle || Math.sin(currentAngle) === 0 || isNumberEqual(currentAngle, 0)) {
18542
- // return {
18543
- // xExtra: 0,
18544
- // yExtra: 0,
18545
- // };
18546
- // }
18547
- // let xAngle = Math.abs(Math.atan2(nextPoint[1] - currentPoint[1], nextPoint[0] - currentPoint[0]));
18548
- // let yAngle = Math.abs(Math.atan2(nextPoint[0] - currentPoint[0], nextPoint[1] - currentPoint[1]));
18549
- // // 将夹角转为锐角
18550
- // xAngle = xAngle > Math.PI / 2 ? Math.PI - xAngle : xAngle;
18551
- // yAngle = yAngle > Math.PI / 2 ? Math.PI - yAngle : yAngle;
18552
- // // 这里不考虑在水平和垂直方向的投影,直接使用最大差值
18553
- // // 由于上层统一加减了二分之一线宽,这里需要进行弥补
18554
- // const extra = {
18555
- // // 水平方向投影
18556
- // xExtra:
18557
- // Math.cos(currentAngle / 2 - xAngle) * ((lineWidth / 2) * (1 / Math.sin(currentAngle / 2))) -
18558
- // lineWidth / 2 || 0,
18559
- // // 垂直方向投影
18560
- // yExtra:
18561
- // Math.cos(yAngle - currentAngle / 2) * ((lineWidth / 2) * (1 / Math.sin(currentAngle / 2))) -
18562
- // lineWidth / 2 || 0,
18563
- // };
18564
- // return extra;
18565
- // }
18566
18220
 
18567
18221
  /**
18568
18222
  * @see /zh/docs/api/basic/display-object#clippath
@@ -19015,7 +18669,6 @@ var CSSPropertyPath = /*#__PURE__*/function () {
19015
18669
  polylines: [],
19016
18670
  curve: [],
19017
18671
  totalLength: 0,
19018
- curveSegments: [],
19019
18672
  zCommandIndexes: [],
19020
18673
  rect: new Rectangle(0, 0, 0, 0)
19021
18674
  };
@@ -20144,8 +19797,16 @@ var DefaultStyleValueRegistry = /*#__PURE__*/function () {
20144
19797
 
20145
19798
  var center = vec3.fromValues((1 - (anchor && anchor[0].value || 0) * 2) * width / 2 + offsetX, (1 - (anchor && anchor[1].value || 0) * 2) * height / 2 + offsetY, (1 - (anchor && ((_anchor$ = anchor[2]) === null || _anchor$ === void 0 ? void 0 : _anchor$.value) || 0) * 2) * halfExtents[2] + offsetZ); // update geometry's AABB
20146
19799
 
20147
- geometry.contentBounds.update(center, halfExtents);
20148
- var halfLineWidth = (((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + ((increasedLineWidthForHitTesting === null || increasedLineWidthForHitTesting === void 0 ? void 0 : increasedLineWidthForHitTesting.value) || 0)) / 2; // append border
19800
+ geometry.contentBounds.update(center, halfExtents); // @see https://github.molgen.mpg.de/git-mirror/cairo/blob/master/src/cairo-stroke-style.c#L97..L128
19801
+
19802
+ var expansion = object.nodeName === Shape.POLYLINE || object.nodeName === Shape.POLYGON || object.nodeName === Shape.PATH ? Math.SQRT2 : 0.5; // if (lineCap?.value === 'square') {
19803
+ // expansion = Math.SQRT1_2;
19804
+ // }
19805
+ // if (lineJoin?.value === 'miter' && expansion < Math.SQRT2 * miterLimit) {
19806
+ // expansion = Math.SQRT1_2 * miterLimit;
19807
+ // }
19808
+
19809
+ var halfLineWidth = (((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + ((increasedLineWidthForHitTesting === null || increasedLineWidthForHitTesting === void 0 ? void 0 : increasedLineWidthForHitTesting.value) || 0)) * expansion; // append border
20149
19810
 
20150
19811
  vec3.add(halfExtents, halfExtents, vec3.fromValues(halfLineWidth, halfLineWidth, 0));
20151
19812
  geometry.renderBounds.update(center, halfExtents); // account for shadow, only support constant value now
@@ -21840,4 +21501,4 @@ var Canvas = /*#__PURE__*/function (_EventTarget) {
21840
21501
  GlobalContainer.load(containerModule);
21841
21502
  var layoutEngine = GlobalContainer.get(LayoutEngine);
21842
21503
 
21843
- export { AABB, AbstractLayoutDefinition, AbstractRenderer, Animation, AnimationEffectTiming, AnimationEvent, AnimationTimeline, AsyncParallelHook, AsyncSeriesWaterfallHook, BUILT_IN_PROPERTIES, BaseType, BoundingSphere, CSS, CSSColorValue, CSSGradientValue, CSSKeywordValue, CSSMathInvert, CSSMathMax, CSSMathMin, CSSMathNegate, CSSMathOperator, CSSMathProduct, CSSMathSum, CSSMathValue, CSSMathVariadic, CSSNumericValue, CSSNumericValueType, CSSProperty, CSSPropertyAngle, CSSPropertyClipPath, CSSPropertyColor, CSSPropertyFilter, CSSPropertyLengthOrPercentage, CSSPropertyLengthOrPercentage12, CSSPropertyLengthOrPercentage14, CSSPropertyLocalPosition, CSSPropertyOffsetDistance, CSSPropertyOffsetPath, CSSPropertyOpacity, CSSPropertyPath, CSSPropertyPoints, CSSPropertyShadowBlur, CSSPropertySyntaxFactory, CSSPropertyText, CSSPropertyTextTransform, CSSPropertyTransform, CSSPropertyTransformOrigin, CSSPropertyZIndex, CSSRGB, CSSStyleValue, CSSStyleValueType, CSSUnitValue, Camera, CameraEvent, CameraProjectionMode, CameraTrackingMode, CameraType, Canvas, CanvasConfig, CanvasEvent, Circle, CircleUpdater, ContextNode, ContextService, Cullable, CustomElement, CustomElementRegistry, CustomEvent, DCHECK, DCHECK_EQ, DCHECK_NE, DELEGATION_SPLITTER, DefaultCamera, DefaultSceneGraphSelector, DefaultSceneGraphService, DefaultStyleValueRegistry, Deferred, DisplayObject, DisplayObjectPool, Document, EasingFunctions, Element, ElementEvent, Ellipse, EllipseUpdater, EventService, EventTarget, FederatedEvent, FederatedMouseEvent, FederatedPointerEvent, FederatedWheelEvent, FragmentResult, FragmentResultFactory, FragmentResultOptions, Frustum, Geometry, GeometryAABBUpdater, GeometryUpdaterFactory, GradientType, Group, HTML, Image, KeyframeEffect, LayoutChildren, LayoutChildrenFactory, LayoutChildrenOptions, LayoutContext, LayoutContextFactory, LayoutContextOptions, LayoutEdges, LayoutEdgesFactory, LayoutEdgesOptions, LayoutEngine, LayoutFragment, LayoutFragmentFactory, LayoutFragmentOptions, LayoutObject, LayoutRegistry, LayoutTaskType, Line, LineUpdater, MOUSE_POINTER_ID, Mask, MutationEvent, MutationObserver, MutationRecord, Nested, Node, ObjectTyped, Odeg, OffscreenCanvasCreator, Opx, ParenLess, Path, PathUpdater, Plane, Point, Polygon, Polyline, PolylineUpdater, PropertyName, PropertySyntax, RBushNode, RBushRoot, Ray, Rect, RectUpdater, Rectangle, Registration, RenderReason, Renderable, RenderingContext, RenderingPluginContribution, RenderingService, SceneGraphSelector, SceneGraphSelectorFactory, SceneGraphService, Shape, Sortable, Strategy, StyleValueRegistry, SyncHook, SyncWaterfallHook, TOUCH_TO_POINTER, Text, TextService, TextUpdater, Transform, UnitCategory, UnitType, ValueRange, baseTypeToString, camelCase, clamp, clampedMergeNumbers, cleanExistedCanvas, clonePath, colorStopToString, compareAnimations, computeLinearGradient, computeRadialGradient, convertAngleUnit, convertEffectInput, convertPercentUnit, convertToDash, convertToPath, createVec3, decompose, deg2rad, deg2turn, dirtifyToRoot, equalSet, equalizeSegments, formatAttribute, fromRotationTranslationScale, getAngle, getDrawDirection, getEasingFunction, getEuler, getHeight, getPathArea, getRotatedCurve, getRotationInRadians, getScaling, getStyle, getTranslation, getWidth, grad2deg, isBoolean, isBrowser, isComparison, isFunction, isNil, isNumber, isObject, isPattern, isString, isUndefined, layoutEngine, makePerspective, makeQuerablePromise, makeTiming, mergeColors, mergeDimensionList, mergeDimensions, mergeNumberLists, mergeNumbers, mergePaths, mergeTransforms, normalizeKeyframes, normalizeTimingInput, numberToString, numericTimingToObject, parseAngle, parseColor, parseDimension, parseDimensionArray, parseFilter, parseGradient, parseLength, parseLengthOrPercentage, parseNumber, parseNumberList, parseParam, parsePath, parsePoints, parseTransform, parseTransformOrigin, parserPercentage, rad2deg, reverseCurve, setDOMSize, sortByZIndex, toFontString, turn2deg, typeCheck, unitTypeToBaseType };
21504
+ export { AABB, AbstractLayoutDefinition, AbstractRenderer, Animation, AnimationEffectTiming, AnimationEvent, AnimationTimeline, AsyncParallelHook, AsyncSeriesWaterfallHook, BUILT_IN_PROPERTIES, BaseType, BoundingSphere, CSS, CSSColorValue, CSSGradientValue, CSSKeywordValue, CSSMathInvert, CSSMathMax, CSSMathMin, CSSMathNegate, CSSMathOperator, CSSMathProduct, CSSMathSum, CSSMathValue, CSSMathVariadic, CSSNumericValue, CSSNumericValueType, CSSProperty, CSSPropertyAngle, CSSPropertyClipPath, CSSPropertyColor, CSSPropertyFilter, CSSPropertyLengthOrPercentage, CSSPropertyLengthOrPercentage12, CSSPropertyLengthOrPercentage14, CSSPropertyLocalPosition, CSSPropertyOffsetDistance, CSSPropertyOffsetPath, CSSPropertyOpacity, CSSPropertyPath, CSSPropertyPoints, CSSPropertyShadowBlur, CSSPropertySyntaxFactory, CSSPropertyText, CSSPropertyTextTransform, CSSPropertyTransform, CSSPropertyTransformOrigin, CSSPropertyZIndex, CSSRGB, CSSStyleValue, CSSStyleValueType, CSSUnitValue, Camera, CameraEvent, CameraProjectionMode, CameraTrackingMode, CameraType, Canvas, CanvasConfig, CanvasEvent, Circle, CircleUpdater, ContextNode, ContextService, Cullable, CustomElement, CustomElementRegistry, CustomEvent, DCHECK, DCHECK_EQ, DCHECK_NE, DELEGATION_SPLITTER, DefaultCamera, DefaultSceneGraphSelector, DefaultSceneGraphService, DefaultStyleValueRegistry, Deferred, DisplayObject, DisplayObjectPool, Document, EasingFunctions, Element, ElementEvent, Ellipse, EllipseUpdater, EventService, EventTarget, FederatedEvent, FederatedMouseEvent, FederatedPointerEvent, FederatedWheelEvent, FragmentResult, FragmentResultFactory, FragmentResultOptions, Frustum, Geometry, GeometryAABBUpdater, GeometryUpdaterFactory, GradientType, Group, HTML, Image, KeyframeEffect, LayoutChildren, LayoutChildrenFactory, LayoutChildrenOptions, LayoutContext, LayoutContextFactory, LayoutContextOptions, LayoutEdges, LayoutEdgesFactory, LayoutEdgesOptions, LayoutEngine, LayoutFragment, LayoutFragmentFactory, LayoutFragmentOptions, LayoutObject, LayoutRegistry, LayoutTaskType, Line, LineUpdater, MOUSE_POINTER_ID, Mask, MutationEvent, MutationObserver, MutationRecord, Nested, Node, ObjectTyped, Odeg, OffscreenCanvasCreator, Opx, ParenLess, Path, PathUpdater, Plane, Point, Polygon, Polyline, PolylineUpdater, PropertyName, PropertySyntax, RBushNode, RBushRoot, Ray, Rect, RectUpdater, Rectangle, Registration, RenderReason, Renderable, RenderingContext, RenderingPluginContribution, RenderingService, SceneGraphSelector, SceneGraphSelectorFactory, SceneGraphService, Shape, Sortable, Strategy, StyleValueRegistry, SyncHook, SyncWaterfallHook, TOUCH_TO_POINTER, Text, TextService, TextUpdater, Transform, UnitCategory, UnitType, ValueRange, baseTypeToString, camelCase, clamp, clampedMergeNumbers, cleanExistedCanvas, colorStopToString, compareAnimations, computeLinearGradient, computeRadialGradient, convertAngleUnit, convertEffectInput, convertPercentUnit, convertToDash, convertToPath, createVec3, decompose, deg2rad, deg2turn, dirtifyToRoot, equalSet, extractPolygons, formatAttribute, fromRotationTranslationScale, getAngle, getEasingFunction, getEuler, getHeight, getRotationInRadians, getScaling, getStyle, getTranslation, getWidth, grad2deg, hasArcOrBezier, isBoolean, isBrowser, isComparison, isFunction, isNil, isNumber, isObject, isPattern, isString, isUndefined, layoutEngine, makePerspective, makeQuerablePromise, makeTiming, mergeColors, mergeDimensionList, mergeDimensions, mergeNumberLists, mergeNumbers, mergePaths, mergeTransforms, normalizeKeyframes, normalizeTimingInput, numberToString, numericTimingToObject, parseAngle, parseColor, parseDimension, parseDimensionArray, parseFilter, parseGradient, parseLength, parseLengthOrPercentage, parseNumber, parseNumberList, parseParam, parsePath, parsePoints, parseTransform, parseTransformOrigin, parserPercentage, path2Segments, rad2deg, setDOMSize, sortByZIndex, toFontString, translatePathToString, turn2deg, typeCheck, unitTypeToBaseType };