svg-path-commander 2.1.3 → 2.1.5
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/README.md +4 -4
- package/dist/svg-path-commander.cjs +1 -1
- package/dist/svg-path-commander.cjs.map +1 -1
- package/dist/svg-path-commander.d.ts +755 -830
- package/dist/svg-path-commander.js +1 -1
- package/dist/svg-path-commander.js.map +1 -1
- package/dist/svg-path-commander.mjs +287 -56
- package/dist/svg-path-commander.mjs.map +1 -1
- package/package.json +14 -22
- package/.eslintrc.cjs +0 -225
- package/.prettierrc.json +0 -15
- package/dts.config.ts +0 -15
- package/src/convert/pathToAbsolute.ts +0 -18
- package/src/convert/pathToCurve.ts +0 -43
- package/src/convert/pathToRelative.ts +0 -18
- package/src/convert/pathToString.ts +0 -50
- package/src/index.ts +0 -454
- package/src/interface.ts +0 -130
- package/src/math/arcTools.ts +0 -388
- package/src/math/bezier.ts +0 -261
- package/src/math/cubicTools.ts +0 -123
- package/src/math/distanceSquareRoot.ts +0 -15
- package/src/math/lineTools.ts +0 -61
- package/src/math/midPoint.ts +0 -18
- package/src/math/polygonTools.ts +0 -48
- package/src/math/quadTools.ts +0 -98
- package/src/math/rotateVector.ts +0 -17
- package/src/math/roundTo.ts +0 -7
- package/src/options/options.ts +0 -9
- package/src/parser/error.ts +0 -2
- package/src/parser/finalizeSegment.ts +0 -35
- package/src/parser/invalidPathValue.ts +0 -2
- package/src/parser/isArcCommand.ts +0 -11
- package/src/parser/isDigit.ts +0 -12
- package/src/parser/isDigitStart.ts +0 -14
- package/src/parser/isMoveCommand.ts +0 -17
- package/src/parser/isPathCommand.ts +0 -28
- package/src/parser/isSpace.ts +0 -23
- package/src/parser/paramsCount.ts +0 -16
- package/src/parser/paramsParser.ts +0 -14
- package/src/parser/parsePathString.ts +0 -33
- package/src/parser/pathParser.ts +0 -29
- package/src/parser/scanFlag.ts +0 -29
- package/src/parser/scanParam.ts +0 -102
- package/src/parser/scanSegment.ts +0 -84
- package/src/parser/skipSpaces.ts +0 -17
- package/src/process/absolutizeSegment.ts +0 -67
- package/src/process/arcToCubic.ts +0 -128
- package/src/process/getSVGMatrix.ts +0 -70
- package/src/process/iterate.ts +0 -58
- package/src/process/lineToCubic.ts +0 -17
- package/src/process/normalizePath.ts +0 -33
- package/src/process/normalizeSegment.ts +0 -84
- package/src/process/optimizePath.ts +0 -62
- package/src/process/projection2d.ts +0 -52
- package/src/process/quadToCubic.ts +0 -31
- package/src/process/relativizeSegment.ts +0 -63
- package/src/process/reverseCurve.ts +0 -24
- package/src/process/reversePath.ts +0 -114
- package/src/process/roundPath.ts +0 -33
- package/src/process/roundSegment.ts +0 -9
- package/src/process/segmentToCubic.ts +0 -48
- package/src/process/shortenSegment.ts +0 -71
- package/src/process/splitCubic.ts +0 -29
- package/src/process/splitPath.ts +0 -63
- package/src/process/transformPath.ts +0 -114
- package/src/types.ts +0 -228
- package/src/util/distanceEpsilon.ts +0 -3
- package/src/util/getClosestPoint.ts +0 -15
- package/src/util/getDrawDirection.ts +0 -16
- package/src/util/getPathArea.ts +0 -70
- package/src/util/getPathBBox.ts +0 -171
- package/src/util/getPointAtLength.ts +0 -110
- package/src/util/getPropertiesAtLength.ts +0 -67
- package/src/util/getPropertiesAtPoint.ts +0 -84
- package/src/util/getSegmentAtLength.ts +0 -15
- package/src/util/getSegmentOfPoint.ts +0 -18
- package/src/util/getTotalLength.ts +0 -133
- package/src/util/isAbsoluteArray.ts +0 -18
- package/src/util/isCurveArray.ts +0 -15
- package/src/util/isNormalizedArray.ts +0 -16
- package/src/util/isPathArray.ts +0 -24
- package/src/util/isPointInStroke.ts +0 -16
- package/src/util/isRelativeArray.ts +0 -18
- package/src/util/isValidPath.ts +0 -27
- package/src/util/shapeParams.ts +0 -16
- package/src/util/shapeToPath.ts +0 -86
- package/src/util/shapeToPathArray.ts +0 -183
- package/test/class.test.ts +0 -506
- package/test/fixtures/getMarkup.ts +0 -17
- package/test/fixtures/shapeObjects.ts +0 -11
- package/test/fixtures/shapes.js +0 -104
- package/test/fixtures/simpleShapes.js +0 -87
- package/test/static.test.ts +0 -330
- package/vite.config.mts +0 -41
- package/vitest.config-ui.mts +0 -31
- package/vitest.config.mts +0 -31
|
@@ -400,7 +400,11 @@ const V = {
|
|
|
400
400
|
}, qt = (e) => {
|
|
401
401
|
let t = e.pathValue[e.segmentStart], s = t.toLowerCase();
|
|
402
402
|
const { data: r } = e;
|
|
403
|
-
for (; r.length >= tt[s] && (s === "m" && r.length > 2 ? (e.segments.push(
|
|
403
|
+
for (; r.length >= tt[s] && (s === "m" && r.length > 2 ? (e.segments.push(
|
|
404
|
+
[t].concat(
|
|
405
|
+
r.splice(0, 2)
|
|
406
|
+
)
|
|
407
|
+
), s = "l", t = t === "m" ? "l" : "L") : e.segments.push(
|
|
404
408
|
[t].concat(
|
|
405
409
|
r.splice(0, tt[s])
|
|
406
410
|
)
|
|
@@ -574,7 +578,11 @@ const Q = (e) => {
|
|
|
574
578
|
if (i === "H")
|
|
575
579
|
return [i, e[1] + s];
|
|
576
580
|
if (i === "L")
|
|
577
|
-
return [
|
|
581
|
+
return [
|
|
582
|
+
i,
|
|
583
|
+
e[1] + s,
|
|
584
|
+
e[2] + r
|
|
585
|
+
];
|
|
578
586
|
{
|
|
579
587
|
const l = [], c = e.length;
|
|
580
588
|
for (let a = 1; a < c; a += 1)
|
|
@@ -613,7 +621,11 @@ const Q = (e) => {
|
|
|
613
621
|
if (i === "h")
|
|
614
622
|
return [i, e[1] - s];
|
|
615
623
|
if (i === "l")
|
|
616
|
-
return [
|
|
624
|
+
return [
|
|
625
|
+
i,
|
|
626
|
+
e[1] - s,
|
|
627
|
+
e[2] - r
|
|
628
|
+
];
|
|
617
629
|
{
|
|
618
630
|
const l = [], c = e.length;
|
|
619
631
|
for (let a = 1; a < c; a += 1)
|
|
@@ -637,13 +649,22 @@ const Q = (e) => {
|
|
|
637
649
|
const v = (u - f) / 2, O = (m - y) / 2;
|
|
638
650
|
let X = v * v / (h * h) + O * O / (g * g);
|
|
639
651
|
X > 1 && (X = Math.sqrt(X), h *= X, g *= X);
|
|
640
|
-
const Tt = h * h, $t = g * g, Jt = (i === o ? -1 : 1) * Math.sqrt(
|
|
652
|
+
const Tt = h * h, $t = g * g, Jt = (i === o ? -1 : 1) * Math.sqrt(
|
|
653
|
+
Math.abs(
|
|
654
|
+
(Tt * $t - Tt * O * O - $t * v * v) / (Tt * O * O + $t * v * v)
|
|
655
|
+
)
|
|
656
|
+
);
|
|
641
657
|
C = Jt * h * O / g + (u + f) / 2, I = Jt * -g * v / h + (m + y) / 2, b = Math.asin(((m - I) / g * 10 ** 9 >> 0) / 10 ** 9), L = Math.asin(((y - I) / g * 10 ** 9 >> 0) / 10 ** 9), b = u < C ? Math.PI - b : b, L = f < C ? Math.PI - L : L, b < 0 && (b = Math.PI * 2 + b), L < 0 && (L = Math.PI * 2 + L), o && b > L && (b -= Math.PI * 2), !o && L > b && (L -= Math.PI * 2);
|
|
642
658
|
}
|
|
643
659
|
let R = L - b;
|
|
644
660
|
if (Math.abs(R) > p) {
|
|
645
661
|
const v = L, O = f, X = y;
|
|
646
|
-
L = b + p * (o && L > b ? 1 : -1), f = C + h * Math.cos(L), y = I + g * Math.sin(L), N = Mt(f, y, h, g, n, 0, o, O, X, [
|
|
662
|
+
L = b + p * (o && L > b ? 1 : -1), f = C + h * Math.cos(L), y = I + g * Math.sin(L), N = Mt(f, y, h, g, n, 0, o, O, X, [
|
|
663
|
+
L,
|
|
664
|
+
v,
|
|
665
|
+
C,
|
|
666
|
+
I
|
|
667
|
+
]);
|
|
647
668
|
}
|
|
648
669
|
R = L - b;
|
|
649
670
|
const P = Math.cos(b), z = Math.sin(b), D = Math.cos(L), K = Math.sin(L), q = Math.tan(R / 4), w = 4 / 3 * h * q, $ = 4 / 3 * g * q, E = [u, m], B = [u + w * z, m - $ * P], F = [f + w * K, y - $ * D], G = [f, y];
|
|
@@ -678,19 +699,44 @@ const Q = (e) => {
|
|
|
678
699
|
}, pe = (e, t) => {
|
|
679
700
|
const [s] = e, r = e.slice(1).map(Number), [n, i] = r, { x1: o, y1: l, x: c, y: a } = t;
|
|
680
701
|
return "TQ".includes(s) || (t.qx = null, t.qy = null), s === "M" ? (t.x = n, t.y = i, e) : s === "A" ? ["C"].concat(
|
|
681
|
-
Mt(
|
|
702
|
+
Mt(
|
|
703
|
+
o,
|
|
704
|
+
l,
|
|
705
|
+
r[0],
|
|
706
|
+
r[1],
|
|
707
|
+
r[2],
|
|
708
|
+
r[3],
|
|
709
|
+
r[4],
|
|
710
|
+
r[5],
|
|
711
|
+
r[6]
|
|
712
|
+
)
|
|
682
713
|
) : s === "Q" ? (t.qx = n, t.qy = i, ["C"].concat(
|
|
683
714
|
xe(o, l, r[0], r[1], r[2], r[3])
|
|
684
|
-
)) : s === "L" ? ["C"].concat(
|
|
715
|
+
)) : s === "L" ? ["C"].concat(
|
|
716
|
+
Pt(o, l, n, i)
|
|
717
|
+
) : s === "Z" ? ["C"].concat(
|
|
718
|
+
Pt(o, l, c, a)
|
|
719
|
+
) : e;
|
|
685
720
|
}, wt = (e, t) => {
|
|
686
721
|
const [s] = e, r = s.toUpperCase(), n = s !== r, { x1: i, y1: o, x2: l, y2: c, x: a, y: u } = t, m = e.slice(1);
|
|
687
722
|
let h = m.map((g, f) => g + (n ? f % 2 ? u : a : 0));
|
|
688
723
|
if ("TQ".includes(r) || (t.qx = null, t.qy = null), r === "A")
|
|
689
|
-
return h = m.slice(0, -2).concat(
|
|
724
|
+
return h = m.slice(0, -2).concat(
|
|
725
|
+
m[5] + (n ? a : 0),
|
|
726
|
+
m[6] + (n ? u : 0)
|
|
727
|
+
), ["A"].concat(h);
|
|
690
728
|
if (r === "H")
|
|
691
|
-
return [
|
|
729
|
+
return [
|
|
730
|
+
"L",
|
|
731
|
+
e[1] + (n ? a : 0),
|
|
732
|
+
o
|
|
733
|
+
];
|
|
692
734
|
if (r === "V")
|
|
693
|
-
return [
|
|
735
|
+
return [
|
|
736
|
+
"L",
|
|
737
|
+
i,
|
|
738
|
+
e[1] + (n ? u : 0)
|
|
739
|
+
];
|
|
694
740
|
if (r === "L")
|
|
695
741
|
return [
|
|
696
742
|
"L",
|
|
@@ -738,7 +784,11 @@ const Q = (e) => {
|
|
|
738
784
|
t.x = i, t.y = o;
|
|
739
785
|
const l = wt(r, t);
|
|
740
786
|
let c = pe(l, t);
|
|
741
|
-
c[0] === "C" && c.length > 7 && (s.splice(
|
|
787
|
+
c[0] === "C" && c.length > 7 && (s.splice(
|
|
788
|
+
n + 1,
|
|
789
|
+
0,
|
|
790
|
+
["C"].concat(c.slice(7))
|
|
791
|
+
), c = c.slice(0, 7));
|
|
742
792
|
const u = c.length;
|
|
743
793
|
return t.x1 = +c[u - 2], t.y1 = +c[u - 1], t.x2 = +c[u - 4] || t.x1, t.y2 = +c[u - 3] || t.y1, c;
|
|
744
794
|
});
|
|
@@ -765,7 +815,9 @@ const Q = (e) => {
|
|
|
765
815
|
}
|
|
766
816
|
}
|
|
767
817
|
return i;
|
|
768
|
-
}, Nt = (e, t) => Math.sqrt(
|
|
818
|
+
}, Nt = (e, t) => Math.sqrt(
|
|
819
|
+
(e[0] - t[0]) * (e[0] - t[0]) + (e[1] - t[1]) * (e[1] - t[1])
|
|
820
|
+
), it = (e, t, s, r) => Nt([e, t], [s, r]), Ht = (e, t, s, r, n) => {
|
|
769
821
|
let i = { x: e, y: t };
|
|
770
822
|
if (typeof n == "number") {
|
|
771
823
|
const o = Nt([e, t], [s, r]);
|
|
@@ -843,11 +895,31 @@ const Q = (e) => {
|
|
|
843
895
|
ry: y
|
|
844
896
|
};
|
|
845
897
|
}, _t = (e, t, s, r, n, i, o, l, c) => {
|
|
846
|
-
const { rx: a, ry: u, startAngle: m, endAngle: h } = Lt(
|
|
898
|
+
const { rx: a, ry: u, startAngle: m, endAngle: h } = Lt(
|
|
899
|
+
e,
|
|
900
|
+
t,
|
|
901
|
+
s,
|
|
902
|
+
r,
|
|
903
|
+
n,
|
|
904
|
+
i,
|
|
905
|
+
o,
|
|
906
|
+
l,
|
|
907
|
+
c
|
|
908
|
+
);
|
|
847
909
|
return Ft(a, u, h - m);
|
|
848
910
|
}, be = (e, t, s, r, n, i, o, l, c, a) => {
|
|
849
911
|
let u = { x: e, y: t };
|
|
850
|
-
const { center: m, rx: h, ry: g, startAngle: f, endAngle: y } = Lt(
|
|
912
|
+
const { center: m, rx: h, ry: g, startAngle: f, endAngle: y } = Lt(
|
|
913
|
+
e,
|
|
914
|
+
t,
|
|
915
|
+
s,
|
|
916
|
+
r,
|
|
917
|
+
n,
|
|
918
|
+
i,
|
|
919
|
+
o,
|
|
920
|
+
l,
|
|
921
|
+
c
|
|
922
|
+
);
|
|
851
923
|
if (typeof a == "number") {
|
|
852
924
|
const p = Ft(h, g, y - f);
|
|
853
925
|
if (a <= 0)
|
|
@@ -868,7 +940,17 @@ const Q = (e) => {
|
|
|
868
940
|
}
|
|
869
941
|
return u;
|
|
870
942
|
}, de = (e, t, s, r, n, i, o, l, c) => {
|
|
871
|
-
const { center: a, rx: u, ry: m, startAngle: h, endAngle: g } = Lt(
|
|
943
|
+
const { center: a, rx: u, ry: m, startAngle: h, endAngle: g } = Lt(
|
|
944
|
+
e,
|
|
945
|
+
t,
|
|
946
|
+
s,
|
|
947
|
+
r,
|
|
948
|
+
n,
|
|
949
|
+
i,
|
|
950
|
+
o,
|
|
951
|
+
l,
|
|
952
|
+
c
|
|
953
|
+
), f = g - h, { min: y, max: p, tan: M, atan2: N, PI: x } = Math, { x: b, y: L } = a, C = n * x / 180, I = M(C), R = N(-m * I, u), P = R, z = R + x, D = N(m, u * I), K = D + x;
|
|
872
954
|
let q = y(e, l), w = p(e, l), $ = y(t, c), E = p(t, c);
|
|
873
955
|
const B = g - f * 1e-3, F = Y(b, L, u, m, C, B), G = g - f * 0.999, W = Y(b, L, u, m, C, G);
|
|
874
956
|
if (F[0] > w || W[0] > w) {
|
|
@@ -1034,7 +1116,10 @@ const Q = (e) => {
|
|
|
1034
1116
|
let u = { x: e, y: t };
|
|
1035
1117
|
if (a) {
|
|
1036
1118
|
const m = mt([e, t, s, r, n, i, o, l]);
|
|
1037
|
-
c <= 0 || (c >= m ? u = { x: o, y: l } : u = Ce(
|
|
1119
|
+
c <= 0 || (c >= m ? u = { x: o, y: l } : u = Ce(
|
|
1120
|
+
[e, t, s, r, n, i, o, l],
|
|
1121
|
+
c / m
|
|
1122
|
+
));
|
|
1038
1123
|
}
|
|
1039
1124
|
return u;
|
|
1040
1125
|
}, jt = (e, t, s, r, n, i, o, l) => {
|
|
@@ -1051,7 +1136,10 @@ const Q = (e) => {
|
|
|
1051
1136
|
let c = { x: e, y: t };
|
|
1052
1137
|
if (l) {
|
|
1053
1138
|
const a = mt([e, t, s, r, n, i]);
|
|
1054
|
-
o <= 0 || (o >= a ? c = { x: n, y: i } : c = $e(
|
|
1139
|
+
o <= 0 || (o >= a ? c = { x: n, y: i } : c = $e(
|
|
1140
|
+
[e, t, s, r, n, i],
|
|
1141
|
+
o / a
|
|
1142
|
+
));
|
|
1055
1143
|
}
|
|
1056
1144
|
return c;
|
|
1057
1145
|
}, Qt = (e, t, s, r, n, i) => {
|
|
@@ -1076,7 +1164,13 @@ const Q = (e) => {
|
|
|
1076
1164
|
const u = typeof t == "number";
|
|
1077
1165
|
let m = { x: c, y: a }, h = 0, g = m, f = 0;
|
|
1078
1166
|
return !u || t < bt ? m : (Z(s, (y, p, M, N) => {
|
|
1079
|
-
if ([i] = y, r = i === "M", n = r ? n : [M, N].concat(y.slice(1)), r ? ([, c, a] = y, m = { x: c, y: a }, h = 0) : i === "L" ? (m = Ht(
|
|
1167
|
+
if ([i] = y, r = i === "M", n = r ? n : [M, N].concat(y.slice(1)), r ? ([, c, a] = y, m = { x: c, y: a }, h = 0) : i === "L" ? (m = Ht(
|
|
1168
|
+
n[0],
|
|
1169
|
+
n[1],
|
|
1170
|
+
n[2],
|
|
1171
|
+
n[3],
|
|
1172
|
+
t - f
|
|
1173
|
+
), h = it(n[0], n[1], n[2], n[3])) : i === "A" ? (m = be(
|
|
1080
1174
|
n[0],
|
|
1081
1175
|
n[1],
|
|
1082
1176
|
n[2],
|
|
@@ -1087,7 +1181,17 @@ const Q = (e) => {
|
|
|
1087
1181
|
n[7],
|
|
1088
1182
|
n[8],
|
|
1089
1183
|
t - f
|
|
1090
|
-
), h = _t(
|
|
1184
|
+
), h = _t(
|
|
1185
|
+
n[0],
|
|
1186
|
+
n[1],
|
|
1187
|
+
n[2],
|
|
1188
|
+
n[3],
|
|
1189
|
+
n[4],
|
|
1190
|
+
n[5],
|
|
1191
|
+
n[6],
|
|
1192
|
+
n[7],
|
|
1193
|
+
n[8]
|
|
1194
|
+
)) : i === "C" ? (m = Te(
|
|
1091
1195
|
n[0],
|
|
1092
1196
|
n[1],
|
|
1093
1197
|
n[2],
|
|
@@ -1097,7 +1201,31 @@ const Q = (e) => {
|
|
|
1097
1201
|
n[6],
|
|
1098
1202
|
n[7],
|
|
1099
1203
|
t - f
|
|
1100
|
-
), h = xt(
|
|
1204
|
+
), h = xt(
|
|
1205
|
+
n[0],
|
|
1206
|
+
n[1],
|
|
1207
|
+
n[2],
|
|
1208
|
+
n[3],
|
|
1209
|
+
n[4],
|
|
1210
|
+
n[5],
|
|
1211
|
+
n[6],
|
|
1212
|
+
n[7]
|
|
1213
|
+
)) : i === "Q" ? (m = ze(
|
|
1214
|
+
n[0],
|
|
1215
|
+
n[1],
|
|
1216
|
+
n[2],
|
|
1217
|
+
n[3],
|
|
1218
|
+
n[4],
|
|
1219
|
+
n[5],
|
|
1220
|
+
t - f
|
|
1221
|
+
), h = pt(
|
|
1222
|
+
n[0],
|
|
1223
|
+
n[1],
|
|
1224
|
+
n[2],
|
|
1225
|
+
n[3],
|
|
1226
|
+
n[4],
|
|
1227
|
+
n[5]
|
|
1228
|
+
)) : i === "Z" && (n = [M, N, c, a], m = { x: c, y: a }, h = it(n[0], n[1], n[2], n[3])), [o, l] = n.slice(-2), f < t)
|
|
1101
1229
|
g = m;
|
|
1102
1230
|
else
|
|
1103
1231
|
return !1;
|
|
@@ -1112,7 +1240,12 @@ const Q = (e) => {
|
|
|
1112
1240
|
if ([c] = x, "TQ".includes(p) || (o = 0, l = 0), c === "M")
|
|
1113
1241
|
[, a, u] = x;
|
|
1114
1242
|
else if (c === "L")
|
|
1115
|
-
m += it(
|
|
1243
|
+
m += it(
|
|
1244
|
+
f,
|
|
1245
|
+
y,
|
|
1246
|
+
x[1],
|
|
1247
|
+
x[2]
|
|
1248
|
+
);
|
|
1116
1249
|
else if (c === "A")
|
|
1117
1250
|
m += _t(
|
|
1118
1251
|
f,
|
|
@@ -1188,7 +1321,9 @@ const Q = (e) => {
|
|
|
1188
1321
|
length: l,
|
|
1189
1322
|
lengthAtSegment: o
|
|
1190
1323
|
}), i -= 1;
|
|
1191
|
-
return a.find(
|
|
1324
|
+
return a.find(
|
|
1325
|
+
({ lengthAtSegment: u }) => u <= t
|
|
1326
|
+
);
|
|
1192
1327
|
}, vt = (e, t) => {
|
|
1193
1328
|
const s = Q(e), r = ot(s), n = nt(r), i = (b) => {
|
|
1194
1329
|
const L = b.x - t.x, C = b.y - t.y;
|
|
@@ -1210,7 +1345,16 @@ const Q = (e) => {
|
|
|
1210
1345
|
case "M":
|
|
1211
1346
|
return [, t, s] = n, 0;
|
|
1212
1347
|
default:
|
|
1213
|
-
return r = Ue(
|
|
1348
|
+
return r = Ue(
|
|
1349
|
+
t,
|
|
1350
|
+
s,
|
|
1351
|
+
n[1],
|
|
1352
|
+
n[2],
|
|
1353
|
+
n[3],
|
|
1354
|
+
n[4],
|
|
1355
|
+
n[5],
|
|
1356
|
+
n[6]
|
|
1357
|
+
), [t, s] = n.slice(-2), r;
|
|
1214
1358
|
}
|
|
1215
1359
|
}).reduce((n, i) => n + i, 0);
|
|
1216
1360
|
}, Je = (e) => qe(yt(e)) >= 0, Wt = (e) => {
|
|
@@ -1236,7 +1380,12 @@ const Q = (e) => {
|
|
|
1236
1380
|
if ([s] = w, "TQ".includes(D) || (x = 0, b = 0), s === "M")
|
|
1237
1381
|
[, r, n] = w, m = r, h = n, g = r, f = n;
|
|
1238
1382
|
else if (s === "L")
|
|
1239
|
-
[m, h, g, f] = It(
|
|
1383
|
+
[m, h, g, f] = It(
|
|
1384
|
+
P,
|
|
1385
|
+
z,
|
|
1386
|
+
w[1],
|
|
1387
|
+
w[2]
|
|
1388
|
+
);
|
|
1240
1389
|
else if (s === "A")
|
|
1241
1390
|
[m, h, g, f] = de(
|
|
1242
1391
|
P,
|
|
@@ -1380,8 +1529,10 @@ e.slice(1).every(([t]) => t === t.toLowerCase()), Ie = (e) => {
|
|
|
1380
1529
|
}, rn = (e, t, s) => {
|
|
1381
1530
|
const r = s || document, n = r.defaultView || /* istanbul ignore next */
|
|
1382
1531
|
window, i = Object.keys(ct), o = e instanceof n.SVGElement, l = o ? e.tagName : null;
|
|
1383
|
-
if (l === "path")
|
|
1384
|
-
|
|
1532
|
+
if (l === "path")
|
|
1533
|
+
throw TypeError(`${j}: "${l}" is already SVGPathElement`);
|
|
1534
|
+
if (l && i.every((y) => l !== y))
|
|
1535
|
+
throw TypeError(`${j}: "${l}" is not SVGElement`);
|
|
1385
1536
|
const c = r.createElementNS("http://www.w3.org/2000/svg", "path"), a = o ? l : e.type, u = ct[a], m = { type: a }, h = V.round, g = Ee(e, r), f = g && g.length ? kt(g, h) : "";
|
|
1386
1537
|
return o ? (u.forEach((y) => {
|
|
1387
1538
|
m[y] = e.getAttribute(y);
|
|
@@ -1396,7 +1547,11 @@ e.slice(1).every(([t]) => t === t.toLowerCase()), Ie = (e) => {
|
|
|
1396
1547
|
}, Re = (e) => {
|
|
1397
1548
|
let t = new T();
|
|
1398
1549
|
const { origin: s } = e, [r, n] = s, { translate: i } = e, { rotate: o } = e, { skew: l } = e, { scale: c } = e;
|
|
1399
|
-
return Array.isArray(i) && i.length >= 2 && i.every((a) => !Number.isNaN(+a)) && i.some((a) => a !== 0) ? t = t.translate(...i) : typeof i == "number" && !Number.isNaN(i) && (t = t.translate(i)), (o || l || c) && (t = t.translate(r, n), Array.isArray(o) && o.length >= 2 && o.every((a) => !Number.isNaN(+a)) && o.some((a) => a !== 0) ? t = t.rotate(...o) : typeof o == "number" && !Number.isNaN(o) && (t = t.rotate(o)), Array.isArray(l) && l.length === 2 && l.every(
|
|
1550
|
+
return Array.isArray(i) && i.length >= 2 && i.every((a) => !Number.isNaN(+a)) && i.some((a) => a !== 0) ? t = t.translate(...i) : typeof i == "number" && !Number.isNaN(i) && (t = t.translate(i)), (o || l || c) && (t = t.translate(r, n), Array.isArray(o) && o.length >= 2 && o.every((a) => !Number.isNaN(+a)) && o.some((a) => a !== 0) ? t = t.rotate(...o) : typeof o == "number" && !Number.isNaN(o) && (t = t.rotate(o)), Array.isArray(l) && l.length === 2 && l.every(
|
|
1551
|
+
(a) => !Number.isNaN(+a)
|
|
1552
|
+
) && l.some((a) => a !== 0) ? (t = l[0] ? t.skewX(l[0]) : t, t = l[1] ? t.skewY(l[1]) : t) : typeof l == "number" && !Number.isNaN(l) && (t = t.skewX(l)), Array.isArray(c) && c.length >= 2 && c.every(
|
|
1553
|
+
(a) => !Number.isNaN(+a)
|
|
1554
|
+
) && c.some((a) => a !== 1) ? t = t.scale(...c) : typeof c == "number" && !Number.isNaN(c) && (t = t.scale(c)), t = t.translate(-r, -n)), t;
|
|
1400
1555
|
}, Se = (e, t, s, r) => {
|
|
1401
1556
|
const [n] = e, { round: i } = V, o = typeof i == "number" ? i : (
|
|
1402
1557
|
/* istanbul ignore next */
|
|
@@ -1410,7 +1565,13 @@ e.slice(1).every(([t]) => t === t.toLowerCase()), Ie = (e) => {
|
|
|
1410
1565
|
} else if (n === "C") {
|
|
1411
1566
|
const [M, N] = l;
|
|
1412
1567
|
if (s.x1 = M, s.y1 = N, "CS".includes(r) && (k(M, o) === k(c * 2 - u, o) && k(N, o) === k(a * 2 - m, o) || k(c, o) === k(u * 2 - h, o) && k(a, o) === k(m * 2 - g, o)))
|
|
1413
|
-
return [
|
|
1568
|
+
return [
|
|
1569
|
+
"S",
|
|
1570
|
+
l[2],
|
|
1571
|
+
l[3],
|
|
1572
|
+
l[4],
|
|
1573
|
+
l[5]
|
|
1574
|
+
];
|
|
1414
1575
|
} else if (n === "Q") {
|
|
1415
1576
|
const [M, N] = l;
|
|
1416
1577
|
if (s.qx = M, s.qy = N, "QT".includes(r) && k(M, o) === k(c * 2 - u, o) && k(N, o) === k(a * 2 - m, o))
|
|
@@ -1418,7 +1579,9 @@ e.slice(1).every(([t]) => t === t.toLowerCase()), Ie = (e) => {
|
|
|
1418
1579
|
}
|
|
1419
1580
|
return p;
|
|
1420
1581
|
}, dt = (e, t) => {
|
|
1421
|
-
const s = e.slice(1).map(
|
|
1582
|
+
const s = e.slice(1).map(
|
|
1583
|
+
(r) => k(r, t)
|
|
1584
|
+
);
|
|
1422
1585
|
return [e[0]].concat(s);
|
|
1423
1586
|
}, Xt = (e, t) => {
|
|
1424
1587
|
const s = ht(e), r = typeof t == "number" && t >= 0 ? t : (
|
|
@@ -1432,7 +1595,12 @@ e.slice(1).every(([t]) => t === t.toLowerCase()), Ie = (e) => {
|
|
|
1432
1595
|
let g = c;
|
|
1433
1596
|
if ([o] = c, i[a] = o, a) {
|
|
1434
1597
|
l = i[a - 1];
|
|
1435
|
-
const y = Se(
|
|
1598
|
+
const y = Se(
|
|
1599
|
+
c,
|
|
1600
|
+
h,
|
|
1601
|
+
n,
|
|
1602
|
+
l
|
|
1603
|
+
), p = dt(y, r), M = p.join(""), N = Bt(y, a, u, m), x = dt(N, r), b = x.join("");
|
|
1436
1604
|
g = M.length < b.length ? p : x;
|
|
1437
1605
|
}
|
|
1438
1606
|
const f = h.length;
|
|
@@ -1476,7 +1644,15 @@ e.slice(1).every(([t]) => t === t.toLowerCase()), Ie = (e) => {
|
|
|
1476
1644
|
];
|
|
1477
1645
|
break;
|
|
1478
1646
|
case "C":
|
|
1479
|
-
m && h === "S" ? p = ["S", o[1], o[2], f, y] : p = [
|
|
1647
|
+
m && h === "S" ? p = ["S", o[1], o[2], f, y] : p = [
|
|
1648
|
+
g,
|
|
1649
|
+
o[3],
|
|
1650
|
+
o[4],
|
|
1651
|
+
o[1],
|
|
1652
|
+
o[2],
|
|
1653
|
+
f,
|
|
1654
|
+
y
|
|
1655
|
+
];
|
|
1480
1656
|
break;
|
|
1481
1657
|
case "S":
|
|
1482
1658
|
u && "CS".includes(u) && (!m || h !== "S") ? p = [
|
|
@@ -1487,13 +1663,25 @@ e.slice(1).every(([t]) => t === t.toLowerCase()), Ie = (e) => {
|
|
|
1487
1663
|
c[2],
|
|
1488
1664
|
f,
|
|
1489
1665
|
y
|
|
1490
|
-
] : p = [
|
|
1666
|
+
] : p = [
|
|
1667
|
+
g,
|
|
1668
|
+
c[1],
|
|
1669
|
+
c[2],
|
|
1670
|
+
f,
|
|
1671
|
+
y
|
|
1672
|
+
];
|
|
1491
1673
|
break;
|
|
1492
1674
|
case "Q":
|
|
1493
1675
|
m && h === "T" ? p = ["T", f, y] : p = [g, o[1], o[2], f, y];
|
|
1494
1676
|
break;
|
|
1495
1677
|
case "T":
|
|
1496
|
-
u && "QT".includes(u) && (!m || h !== "T") ? p = [
|
|
1678
|
+
u && "QT".includes(u) && (!m || h !== "T") ? p = [
|
|
1679
|
+
"Q",
|
|
1680
|
+
c[1],
|
|
1681
|
+
c[2],
|
|
1682
|
+
f,
|
|
1683
|
+
y
|
|
1684
|
+
] : p = [g, f, y];
|
|
1497
1685
|
break;
|
|
1498
1686
|
case "Z":
|
|
1499
1687
|
p = ["M", f, y];
|
|
@@ -1505,7 +1693,11 @@ e.slice(1).every(([t]) => t === t.toLowerCase()), Ie = (e) => {
|
|
|
1505
1693
|
p = [g, y];
|
|
1506
1694
|
break;
|
|
1507
1695
|
default:
|
|
1508
|
-
p = [g].concat(
|
|
1696
|
+
p = [g].concat(
|
|
1697
|
+
o.slice(1, -2),
|
|
1698
|
+
f,
|
|
1699
|
+
y
|
|
1700
|
+
);
|
|
1509
1701
|
}
|
|
1510
1702
|
return p;
|
|
1511
1703
|
});
|
|
@@ -1539,35 +1731,46 @@ e.slice(1).every(([t]) => t === t.toLowerCase()), Ie = (e) => {
|
|
|
1539
1731
|
}, Vt = (e, t) => {
|
|
1540
1732
|
let s = 0, r = 0, n = 0, i = 0, o = 0, l = 0, c = "M";
|
|
1541
1733
|
const a = Q(e), u = t && Object.keys(t);
|
|
1542
|
-
if (!t || u && !u.length)
|
|
1734
|
+
if (!t || u && !u.length)
|
|
1735
|
+
return a.slice(0);
|
|
1543
1736
|
t.origin || Object.assign(t, { origin: V.origin });
|
|
1544
1737
|
const m = t.origin, h = Re(t);
|
|
1545
1738
|
return h.isIdentity ? a.slice(0) : Z(a, (g, f, y, p) => {
|
|
1546
1739
|
[c] = g;
|
|
1547
1740
|
const M = c.toUpperCase(), x = M !== c ? at(g, f, y, p) : g.slice(0);
|
|
1548
|
-
let b = M === "A" ? (
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
x[6],
|
|
1560
|
-
x[7]
|
|
1561
|
-
)
|
|
1741
|
+
let b = M === "A" ? ["C"].concat(
|
|
1742
|
+
Mt(
|
|
1743
|
+
y,
|
|
1744
|
+
p,
|
|
1745
|
+
x[1],
|
|
1746
|
+
x[2],
|
|
1747
|
+
x[3],
|
|
1748
|
+
x[4],
|
|
1749
|
+
x[5],
|
|
1750
|
+
x[6],
|
|
1751
|
+
x[7]
|
|
1562
1752
|
)
|
|
1563
1753
|
) : M === "V" ? ["L", y, x[1]] : M === "H" ? ["L", x[1], p] : x;
|
|
1564
1754
|
c = b[0];
|
|
1565
1755
|
const L = c === "C" && b.length > 7, C = L ? b.slice(0, 7) : b.slice(0);
|
|
1566
|
-
if (L && (a.splice(
|
|
1567
|
-
|
|
1756
|
+
if (L && (a.splice(
|
|
1757
|
+
f + 1,
|
|
1758
|
+
0,
|
|
1759
|
+
["C"].concat(
|
|
1760
|
+
b.slice(7)
|
|
1761
|
+
)
|
|
1762
|
+
), b = C), c === "L")
|
|
1763
|
+
[n, i] = Zt(h, [
|
|
1764
|
+
b[1],
|
|
1765
|
+
b[2]
|
|
1766
|
+
], m), s !== n && r !== i ? b = ["L", n, i] : r === i ? b = ["H", n] : s === n && (b = ["V", i]);
|
|
1568
1767
|
else
|
|
1569
1768
|
for (o = 1, l = b.length; o < l; o += 2)
|
|
1570
|
-
[n, i] = Zt(
|
|
1769
|
+
[n, i] = Zt(
|
|
1770
|
+
h,
|
|
1771
|
+
[+b[o], +b[o + 1]],
|
|
1772
|
+
m
|
|
1773
|
+
), b[o] = n, b[o + 1] = i;
|
|
1571
1774
|
return s = n, r = i, b;
|
|
1572
1775
|
});
|
|
1573
1776
|
};
|
|
@@ -1580,7 +1783,9 @@ class A {
|
|
|
1580
1783
|
constructor(t, s) {
|
|
1581
1784
|
const r = s || {}, n = typeof t > "u";
|
|
1582
1785
|
if (n || !t.length)
|
|
1583
|
-
throw TypeError(
|
|
1786
|
+
throw TypeError(
|
|
1787
|
+
`${j}: "pathValue" is ${n ? "undefined" : "empty"}`
|
|
1788
|
+
);
|
|
1584
1789
|
this.segments = Q(t);
|
|
1585
1790
|
const { round: i, origin: o } = r;
|
|
1586
1791
|
let l;
|
|
@@ -1666,7 +1871,6 @@ class A {
|
|
|
1666
1871
|
* @public
|
|
1667
1872
|
*/
|
|
1668
1873
|
reverse(t) {
|
|
1669
|
-
this.toAbsolute();
|
|
1670
1874
|
const { segments: s } = this, r = Yt(s), n = r.length > 1 ? r : !1, i = n ? n.map((l, c) => t ? c ? ft(l) : l.slice(0) : ft(l)) : s.slice(0);
|
|
1671
1875
|
let o = [];
|
|
1672
1876
|
return n ? o = i.flat(1) : o = t ? s : ft(s), this.segments = o.slice(0), this;
|
|
@@ -1714,7 +1918,11 @@ class A {
|
|
|
1714
1918
|
const { origin: l } = o;
|
|
1715
1919
|
if (Array.isArray(l) && l.length >= 2) {
|
|
1716
1920
|
const [c, a, u] = l.map(Number);
|
|
1717
|
-
o.origin = [
|
|
1921
|
+
o.origin = [
|
|
1922
|
+
Number.isNaN(c) ? r : c,
|
|
1923
|
+
Number.isNaN(a) ? n : a,
|
|
1924
|
+
u || i
|
|
1925
|
+
];
|
|
1718
1926
|
} else
|
|
1719
1927
|
o.origin = [r, n, i];
|
|
1720
1928
|
return this.segments = Vt(s, o), this;
|
|
@@ -1747,6 +1955,15 @@ class A {
|
|
|
1747
1955
|
toString() {
|
|
1748
1956
|
return kt(this.segments, this.round);
|
|
1749
1957
|
}
|
|
1958
|
+
/**
|
|
1959
|
+
* Remove the instance.
|
|
1960
|
+
*
|
|
1961
|
+
* @public
|
|
1962
|
+
* @return void
|
|
1963
|
+
*/
|
|
1964
|
+
dispose() {
|
|
1965
|
+
Object.keys(this).forEach((t) => delete this[t]);
|
|
1966
|
+
}
|
|
1750
1967
|
}
|
|
1751
1968
|
d(A, "CSSMatrix", T), d(A, "pathToAbsolute", ht), d(A, "pathToRelative", Kt), d(A, "pathToCurve", yt), d(A, "pathToString", kt), d(A, "arcTools", Be), d(A, "bezierTools", {
|
|
1752
1969
|
Cvalues: Ae,
|
|
@@ -1759,7 +1976,21 @@ d(A, "CSSMatrix", T), d(A, "pathToAbsolute", ht), d(A, "pathToRelative", Kt), d(
|
|
|
1759
1976
|
computeBezier: we,
|
|
1760
1977
|
deriveBezier: Me,
|
|
1761
1978
|
CBEZIER_MINMAX_EPSILON: ve
|
|
1762
|
-
}), d(A, "cubicTools", {
|
|
1979
|
+
}), d(A, "cubicTools", {
|
|
1980
|
+
getCubicLength: xt,
|
|
1981
|
+
getCubicBBox: jt,
|
|
1982
|
+
getPointAtCubicLength: Te,
|
|
1983
|
+
getPointAtCubicSegmentLength: Ce
|
|
1984
|
+
}), d(A, "lineTools", {
|
|
1985
|
+
getPointAtLineLength: Ht,
|
|
1986
|
+
getLineBBox: It,
|
|
1987
|
+
getLineLength: it
|
|
1988
|
+
}), d(A, "quadTools", {
|
|
1989
|
+
getPointAtQuadSegmentLength: $e,
|
|
1990
|
+
getQuadLength: pt,
|
|
1991
|
+
getQuadBBox: Qt,
|
|
1992
|
+
getPointAtQuadLength: ze
|
|
1993
|
+
}), d(A, "polygonTools", { polygonArea: He, polygonLength: Fe }), d(A, "distanceSquareRoot", Nt), d(A, "distanceEpsilon", bt), d(A, "midPoint", H), d(A, "rotateVector", st), d(A, "roundTo", k), d(A, "finalizeSegment", qt), d(A, "invalidPathValue", J), d(A, "isArcCommand", ye), d(A, "isDigit", U), d(A, "isDigitStart", he), d(A, "isMoveCommand", ge), d(A, "isPathCommand", fe), d(A, "isSpace", me), d(A, "paramsCount", tt), d(A, "paramsParser", ut), d(A, "pathParser", Ot), d(A, "scanFlag", ae), d(A, "scanParam", ue), d(A, "scanSegment", Dt), d(A, "skipSpaces", et), d(A, "getPathBBox", Wt), d(A, "getPathArea", qe), d(A, "getTotalLength", nt), d(A, "getDrawDirection", Je), d(A, "getPointAtLength", rt), d(A, "getPropertiesAtLength", Ut), d(A, "getPropertiesAtPoint", vt), d(A, "getClosestPoint", _e), d(A, "getSegmentOfPoint", We), d(A, "getSegmentAtLength", Ke), d(A, "isPointInStroke", Ye), d(A, "isValidPath", Ie), d(A, "isPathArray", Ct), d(A, "isAbsoluteArray", Pe), d(A, "isRelativeArray", Ve), d(A, "isCurveArray", Xe), d(A, "isNormalizedArray", ke), d(A, "shapeToPath", rn), d(A, "shapeToPathArray", Ee), d(A, "shapeParams", ct), d(A, "parsePathString", Q), d(A, "absolutizeSegment", at), d(A, "arcToCubic", Mt), d(A, "getSVGMatrix", Re), d(A, "iterate", Z), d(A, "lineToCubic", Pt), d(A, "normalizePath", ot), d(A, "normalizeSegment", wt), d(A, "optimizePath", Xt), d(A, "projection2d", Zt), d(A, "quadToCubic", xe), d(A, "relativizeSegment", Bt), d(A, "reverseCurve", cn), d(A, "reversePath", ft), d(A, "roundPath", ln), d(A, "roundSegment", dt), d(A, "segmentToCubic", pe), d(A, "shortenSegment", Se), d(A, "splitCubic", an), d(A, "splitPath", Yt), d(A, "transformPath", Vt);
|
|
1763
1994
|
export {
|
|
1764
1995
|
A as default
|
|
1765
1996
|
};
|