svg-path-commander 1.0.5 → 2.0.0-alpha2
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 +26 -4
- package/dist/svg-path-commander.cjs +2 -0
- package/dist/svg-path-commander.cjs.map +1 -0
- package/dist/svg-path-commander.d.ts +454 -0
- package/dist/svg-path-commander.js +2 -3762
- package/dist/svg-path-commander.js.map +1 -0
- package/dist/svg-path-commander.mjs +1194 -0
- package/dist/svg-path-commander.mjs.map +1 -0
- package/package.json +39 -42
- package/src/convert/pathToAbsolute.ts +101 -0
- package/src/convert/{pathToCurve.js → pathToCurve.ts} +12 -14
- package/src/convert/pathToRelative.ts +92 -0
- package/src/convert/pathToString.ts +17 -0
- package/src/{svg-path-commander.js → index.ts} +143 -66
- package/src/interface.ts +129 -0
- package/src/math/distanceSquareRoot.ts +13 -0
- package/src/math/midPoint.ts +16 -0
- package/src/math/{polygonArea.js → polygonArea.ts} +6 -4
- package/src/math/{polygonLength.js → polygonLength.ts} +5 -3
- package/src/math/rotateVector.ts +16 -0
- package/src/options/options.ts +9 -0
- package/src/parser/error.ts +2 -0
- package/src/parser/finalizeSegment.ts +31 -0
- package/src/parser/{invalidPathValue.js → invalidPathValue.ts} +0 -0
- package/src/parser/{isArcCommand.js → isArcCommand.ts} +5 -4
- package/src/parser/isDigit.ts +12 -0
- package/src/parser/isDigitStart.ts +14 -0
- package/src/parser/isPathCommand.ts +28 -0
- package/src/parser/isSpace.ts +23 -0
- package/src/parser/paramsCount.ts +16 -0
- package/src/parser/paramsParser.ts +14 -0
- package/src/parser/{parsePathString.js → parsePathString.ts} +13 -7
- package/src/parser/pathParser.ts +29 -0
- package/src/parser/{scanFlag.js → scanFlag.ts} +8 -5
- package/src/parser/{scanParam.js → scanParam.ts} +12 -11
- package/src/parser/{scanSegment.js → scanSegment.ts} +9 -5
- package/src/parser/{skipSpaces.js → skipSpaces.ts} +5 -3
- package/src/process/{arcToCubic.js → arcToCubic.ts} +42 -28
- package/src/process/fixArc.ts +23 -0
- package/src/process/getSVGMatrix.ts +70 -0
- package/src/process/lineToCubic.ts +17 -0
- package/src/process/{normalizePath.js → normalizePath.ts} +10 -10
- package/src/process/normalizeSegment.ts +47 -0
- package/src/process/{optimizePath.js → optimizePath.ts} +18 -21
- package/src/process/{projection2d.js → projection2d.ts} +16 -15
- package/src/process/quadToCubic.ts +31 -0
- package/src/process/reverseCurve.ts +21 -0
- package/src/process/reversePath.ts +101 -0
- package/src/process/roundPath.ts +29 -0
- package/src/process/segmentToCubic.ts +46 -0
- package/src/process/shortenSegment.ts +79 -0
- package/src/process/splitCubic.ts +28 -0
- package/src/process/{splitPath.js → splitPath.ts} +9 -8
- package/src/process/{transformPath.js → transformPath.ts} +55 -48
- package/src/types.ts +193 -0
- package/src/util/getClosestPoint.ts +15 -0
- package/src/util/{getDrawDirection.js → getDrawDirection.ts} +7 -4
- package/src/util/getPathArea.ts +70 -0
- package/src/util/{getPathBBox.js → getPathBBox.ts} +16 -5
- package/src/util/getPointAtLength.ts +14 -0
- package/src/util/{getPropertiesAtLength.js → getPropertiesAtLength.ts} +28 -19
- package/src/util/{getPropertiesAtPoint.js → getPropertiesAtPoint.ts} +16 -12
- package/src/util/getSegmentAtLength.ts +15 -0
- package/src/util/getSegmentOfPoint.ts +18 -0
- package/src/util/{getTotalLength.js → getTotalLength.ts} +6 -4
- package/src/util/isAbsoluteArray.ts +18 -0
- package/src/util/{isCurveArray.js → isCurveArray.ts} +6 -4
- package/src/util/{isNormalizedArray.js → isNormalizedArray.ts} +4 -2
- package/src/util/isPathArray.ts +19 -0
- package/src/util/isPointInStroke.ts +15 -0
- package/src/util/isRelativeArray.ts +18 -0
- package/src/util/{isValidPath.js → isValidPath.ts} +5 -4
- package/src/util/{pathLengthFactory.js → pathLengthFactory.ts} +38 -31
- package/src/util/{segmentArcFactory.js → segmentArcFactory.ts} +71 -55
- package/src/util/segmentCubicFactory.ts +114 -0
- package/src/util/{segmentLineFactory.js → segmentLineFactory.ts} +10 -8
- package/src/util/{segmentQuadFactory.js → segmentQuadFactory.ts} +47 -32
- package/src/util/shapeToPath.ts +214 -0
- package/dist/svg-path-commander.es5.js +0 -3875
- package/dist/svg-path-commander.es5.min.js +0 -2
- package/dist/svg-path-commander.esm.js +0 -3754
- package/dist/svg-path-commander.esm.min.js +0 -2
- package/dist/svg-path-commander.min.js +0 -2
- package/src/convert/pathToAbsolute.js +0 -86
- package/src/convert/pathToRelative.js +0 -84
- package/src/convert/pathToString.js +0 -14
- package/src/index.js +0 -10
- package/src/math/distanceSquareRoot.js +0 -14
- package/src/math/epsilon.js +0 -8
- package/src/math/midPoint.js +0 -13
- package/src/math/rotateVector.js +0 -14
- package/src/options/options.js +0 -10
- package/src/parser/error.js +0 -2
- package/src/parser/finalizeSegment.js +0 -28
- package/src/parser/isDigit.js +0 -9
- package/src/parser/isDigitStart.js +0 -13
- package/src/parser/isPathCommand.js +0 -25
- package/src/parser/isSpace.js +0 -16
- package/src/parser/paramsCount.js +0 -9
- package/src/parser/paramsParser.js +0 -8
- package/src/parser/pathParser.js +0 -24
- package/src/process/clonePath.js +0 -9
- package/src/process/fixArc.js +0 -21
- package/src/process/fixPath.js +0 -31
- package/src/process/getSVGMatrix.js +0 -61
- package/src/process/lineToCubic.js +0 -30
- package/src/process/normalizeSegment.js +0 -45
- package/src/process/quadToCubic.js +0 -22
- package/src/process/reverseCurve.js +0 -18
- package/src/process/reversePath.js +0 -89
- package/src/process/roundPath.js +0 -26
- package/src/process/segmentToCubic.js +0 -46
- package/src/process/shortenSegment.js +0 -58
- package/src/process/splitCubic.js +0 -26
- package/src/util/getClosestPoint.js +0 -12
- package/src/util/getPathArea.js +0 -47
- package/src/util/getPointAtLength.js +0 -12
- package/src/util/getSegmentAtLength.js +0 -11
- package/src/util/getSegmentOfPoint.js +0 -12
- package/src/util/isAbsoluteArray.js +0 -14
- package/src/util/isPathArray.js +0 -14
- package/src/util/isPointInStroke.js +0 -13
- package/src/util/isRelativeArray.js +0 -14
- package/src/util/segmentCubicFactory.js +0 -97
- package/src/util/shapeToPath.js +0 -204
- package/src/util/util.js +0 -82
- package/src/version.js +0 -8
- package/types/index.d.ts +0 -120
- package/types/more/modules.ts +0 -82
- package/types/more/svg.d.ts +0 -211
- package/types/svg-path-commander.d.ts +0 -1089
|
@@ -0,0 +1,1194 @@
|
|
|
1
|
+
const at = {
|
|
2
|
+
origin: [0, 0, 0],
|
|
3
|
+
round: 4
|
|
4
|
+
}, q = "SVGPathCommander Error", B = {
|
|
5
|
+
a: 7,
|
|
6
|
+
c: 6,
|
|
7
|
+
h: 1,
|
|
8
|
+
l: 2,
|
|
9
|
+
m: 2,
|
|
10
|
+
r: 4,
|
|
11
|
+
q: 4,
|
|
12
|
+
s: 4,
|
|
13
|
+
t: 2,
|
|
14
|
+
v: 1,
|
|
15
|
+
z: 0
|
|
16
|
+
}, Ct = (e) => {
|
|
17
|
+
let t = e.pathValue[e.segmentStart], n = t.toLowerCase();
|
|
18
|
+
const { data: r } = e;
|
|
19
|
+
for (; r.length >= B[n] && (n === "m" && r.length > 2 ? (e.segments.push([t, ...r.splice(0, 2)]), n = "l", t = t === "m" ? "l" : "L") : e.segments.push([t, ...r.splice(0, B[n])]), !!B[n]); )
|
|
20
|
+
;
|
|
21
|
+
}, Ut = (e) => {
|
|
22
|
+
const { index: t, pathValue: n } = e, r = n.charCodeAt(t);
|
|
23
|
+
if (r === 48) {
|
|
24
|
+
e.param = 0, e.index += 1;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (r === 49) {
|
|
28
|
+
e.param = 1, e.index += 1;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
e.err = `${q}: invalid Arc flag "${n[t]}", expecting 0 or 1 at index ${t}`;
|
|
32
|
+
}, I = (e) => e >= 48 && e <= 57, D = "Invalid path value", Kt = (e) => {
|
|
33
|
+
const { max: t, pathValue: n, index: r } = e;
|
|
34
|
+
let s = r, i = !1, o = !1, l = !1, c = !1, a;
|
|
35
|
+
if (s >= t) {
|
|
36
|
+
e.err = `${q}: ${D} at index ${s}, "pathValue" is missing param`;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (a = n.charCodeAt(s), (a === 43 || a === 45) && (s += 1, a = n.charCodeAt(s)), !I(a) && a !== 46) {
|
|
40
|
+
e.err = `${q}: ${D} at index ${s}, "${n[s]}" is not a number`;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (a !== 46) {
|
|
44
|
+
if (i = a === 48, s += 1, a = n.charCodeAt(s), i && s < t && a && I(a)) {
|
|
45
|
+
e.err = `${q}: ${D} at index ${r}, "${n[r]}" illegal number`;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
for (; s < t && I(n.charCodeAt(s)); )
|
|
49
|
+
s += 1, o = !0;
|
|
50
|
+
a = n.charCodeAt(s);
|
|
51
|
+
}
|
|
52
|
+
if (a === 46) {
|
|
53
|
+
for (c = !0, s += 1; I(n.charCodeAt(s)); )
|
|
54
|
+
s += 1, l = !0;
|
|
55
|
+
a = n.charCodeAt(s);
|
|
56
|
+
}
|
|
57
|
+
if (a === 101 || a === 69) {
|
|
58
|
+
if (c && !o && !l) {
|
|
59
|
+
e.err = `${q}: ${D} at index ${s}, "${n[s]}" invalid float exponent`;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (s += 1, a = n.charCodeAt(s), (a === 43 || a === 45) && (s += 1), s < t && I(n.charCodeAt(s)))
|
|
63
|
+
for (; s < t && I(n.charCodeAt(s)); )
|
|
64
|
+
s += 1;
|
|
65
|
+
else {
|
|
66
|
+
e.err = `${q}: ${D} at index ${s}, "${n[s]}" invalid integer exponent`;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
e.index = s, e.param = +e.pathValue.slice(r, s);
|
|
71
|
+
}, _t = (e) => [
|
|
72
|
+
5760,
|
|
73
|
+
6158,
|
|
74
|
+
8192,
|
|
75
|
+
8193,
|
|
76
|
+
8194,
|
|
77
|
+
8195,
|
|
78
|
+
8196,
|
|
79
|
+
8197,
|
|
80
|
+
8198,
|
|
81
|
+
8199,
|
|
82
|
+
8200,
|
|
83
|
+
8201,
|
|
84
|
+
8202,
|
|
85
|
+
8239,
|
|
86
|
+
8287,
|
|
87
|
+
12288,
|
|
88
|
+
65279,
|
|
89
|
+
10,
|
|
90
|
+
13,
|
|
91
|
+
8232,
|
|
92
|
+
8233,
|
|
93
|
+
32,
|
|
94
|
+
9,
|
|
95
|
+
11,
|
|
96
|
+
12,
|
|
97
|
+
160
|
|
98
|
+
].includes(e), G = (e) => {
|
|
99
|
+
const { pathValue: t, max: n } = e;
|
|
100
|
+
for (; e.index < n && _t(t.charCodeAt(e.index)); )
|
|
101
|
+
e.index += 1;
|
|
102
|
+
}, Wt = (e) => {
|
|
103
|
+
switch (e | 32) {
|
|
104
|
+
case 109:
|
|
105
|
+
case 122:
|
|
106
|
+
case 108:
|
|
107
|
+
case 104:
|
|
108
|
+
case 118:
|
|
109
|
+
case 99:
|
|
110
|
+
case 115:
|
|
111
|
+
case 113:
|
|
112
|
+
case 116:
|
|
113
|
+
case 97:
|
|
114
|
+
return !0;
|
|
115
|
+
default:
|
|
116
|
+
return !1;
|
|
117
|
+
}
|
|
118
|
+
}, te = (e) => I(e) || e === 43 || e === 45 || e === 46, ee = (e) => (e | 32) === 97, Vt = (e) => {
|
|
119
|
+
const { max: t, pathValue: n, index: r } = e, s = n.charCodeAt(r), i = B[n[r].toLowerCase()];
|
|
120
|
+
if (e.segmentStart = r, !Wt(s)) {
|
|
121
|
+
e.err = `${q}: ${D} "${n[r]}" is not a path command`;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (e.index += 1, G(e), e.data = [], !i) {
|
|
125
|
+
Ct(e);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
for (; ; ) {
|
|
129
|
+
for (let o = i; o > 0; o -= 1) {
|
|
130
|
+
if (ee(s) && (o === 3 || o === 4) ? Ut(e) : Kt(e), e.err.length)
|
|
131
|
+
return;
|
|
132
|
+
e.data.push(e.param), G(e), e.index < t && n.charCodeAt(e.index) === 44 && (e.index += 1, G(e));
|
|
133
|
+
}
|
|
134
|
+
if (e.index >= e.max || !te(n.charCodeAt(e.index)))
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
Ct(e);
|
|
138
|
+
};
|
|
139
|
+
class Ot {
|
|
140
|
+
constructor(t) {
|
|
141
|
+
this.segments = [], this.pathValue = t, this.max = t.length, this.index = 0, this.param = 0, this.segmentStart = 0, this.data = [], this.err = "";
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const ct = (e) => Array.isArray(e) && e.every((t) => {
|
|
145
|
+
const n = t[0].toLowerCase();
|
|
146
|
+
return B[n] === t.length - 1 && "achlmqstvz".includes(n);
|
|
147
|
+
}), R = (e) => {
|
|
148
|
+
if (ct(e))
|
|
149
|
+
return [...e];
|
|
150
|
+
const t = new Ot(e);
|
|
151
|
+
for (G(t); t.index < t.max && !t.err.length; )
|
|
152
|
+
Vt(t);
|
|
153
|
+
if (t.err && t.err.length)
|
|
154
|
+
throw TypeError(t.err);
|
|
155
|
+
return t.segments;
|
|
156
|
+
}, ne = (e) => {
|
|
157
|
+
const t = e.length;
|
|
158
|
+
let n = -1, r, s = e[t - 1], i = 0;
|
|
159
|
+
for (; ++n < t; )
|
|
160
|
+
r = s, s = e[n], i += r[1] * s[0] - r[0] * s[1];
|
|
161
|
+
return i / 2;
|
|
162
|
+
}, U = (e, t) => Math.sqrt((e[0] - t[0]) * (e[0] - t[0]) + (e[1] - t[1]) * (e[1] - t[1])), se = (e) => e.reduce((t, n, r) => r ? t + U(e[r - 1], n) : 0, 0);
|
|
163
|
+
var re = Object.defineProperty, ie = (e, t, n) => t in e ? re(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, C = (e, t, n) => (ie(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
164
|
+
const oe = {
|
|
165
|
+
a: 1,
|
|
166
|
+
b: 0,
|
|
167
|
+
c: 0,
|
|
168
|
+
d: 1,
|
|
169
|
+
e: 0,
|
|
170
|
+
f: 0,
|
|
171
|
+
m11: 1,
|
|
172
|
+
m12: 0,
|
|
173
|
+
m13: 0,
|
|
174
|
+
m14: 0,
|
|
175
|
+
m21: 0,
|
|
176
|
+
m22: 1,
|
|
177
|
+
m23: 0,
|
|
178
|
+
m24: 0,
|
|
179
|
+
m31: 0,
|
|
180
|
+
m32: 0,
|
|
181
|
+
m33: 1,
|
|
182
|
+
m34: 0,
|
|
183
|
+
m41: 0,
|
|
184
|
+
m42: 0,
|
|
185
|
+
m43: 0,
|
|
186
|
+
m44: 1,
|
|
187
|
+
is2D: !0,
|
|
188
|
+
isIdentity: !0
|
|
189
|
+
}, zt = (e) => (e instanceof Float64Array || e instanceof Float32Array || Array.isArray(e) && e.every((t) => typeof t == "number")) && [6, 16].some((t) => e.length === t), It = (e) => e instanceof DOMMatrix || e instanceof N || typeof e == "object" && Object.keys(oe).every((t) => e && t in e), K = (e) => {
|
|
190
|
+
const t = new N(), n = Array.from(e);
|
|
191
|
+
if (!zt(n))
|
|
192
|
+
throw TypeError(`CSSMatrix: "${n.join(",")}" must be an array with 6/16 numbers.`);
|
|
193
|
+
if (n.length === 16) {
|
|
194
|
+
const [r, s, i, o, l, c, a, m, f, y, g, h, u, x, p, d] = n;
|
|
195
|
+
t.m11 = r, t.a = r, t.m21 = l, t.c = l, t.m31 = f, t.m41 = u, t.e = u, t.m12 = s, t.b = s, t.m22 = c, t.d = c, t.m32 = y, t.m42 = x, t.f = x, t.m13 = i, t.m23 = a, t.m33 = g, t.m43 = p, t.m14 = o, t.m24 = m, t.m34 = h, t.m44 = d;
|
|
196
|
+
} else if (n.length === 6) {
|
|
197
|
+
const [r, s, i, o, l, c] = n;
|
|
198
|
+
t.m11 = r, t.a = r, t.m12 = s, t.b = s, t.m21 = i, t.c = i, t.m22 = o, t.d = o, t.m41 = l, t.e = l, t.m42 = c, t.f = c;
|
|
199
|
+
}
|
|
200
|
+
return t;
|
|
201
|
+
}, jt = (e) => {
|
|
202
|
+
if (It(e))
|
|
203
|
+
return K([
|
|
204
|
+
e.m11,
|
|
205
|
+
e.m12,
|
|
206
|
+
e.m13,
|
|
207
|
+
e.m14,
|
|
208
|
+
e.m21,
|
|
209
|
+
e.m22,
|
|
210
|
+
e.m23,
|
|
211
|
+
e.m24,
|
|
212
|
+
e.m31,
|
|
213
|
+
e.m32,
|
|
214
|
+
e.m33,
|
|
215
|
+
e.m34,
|
|
216
|
+
e.m41,
|
|
217
|
+
e.m42,
|
|
218
|
+
e.m43,
|
|
219
|
+
e.m44
|
|
220
|
+
]);
|
|
221
|
+
throw TypeError(`CSSMatrix: "${JSON.stringify(e)}" is not a DOMMatrix / CSSMatrix / JSON compatible object.`);
|
|
222
|
+
}, Et = (e) => {
|
|
223
|
+
if (typeof e != "string")
|
|
224
|
+
throw TypeError(`CSSMatrix: "${JSON.stringify(e)}" is not a string.`);
|
|
225
|
+
const t = String(e).replace(/\s/g, "");
|
|
226
|
+
let n = new N();
|
|
227
|
+
const r = `CSSMatrix: invalid transform string "${e}"`;
|
|
228
|
+
return t.split(")").filter((s) => s).forEach((s) => {
|
|
229
|
+
const [i, o] = s.split("(");
|
|
230
|
+
if (!o)
|
|
231
|
+
throw TypeError(r);
|
|
232
|
+
const l = o.split(",").map((h) => h.includes("rad") ? parseFloat(h) * (180 / Math.PI) : parseFloat(h)), [c, a, m, f] = l, y = [c, a, m], g = [c, a, m, f];
|
|
233
|
+
if (i === "perspective" && c && [a, m].every((h) => h === void 0))
|
|
234
|
+
n.m34 = -1 / c;
|
|
235
|
+
else if (i.includes("matrix") && [6, 16].includes(l.length) && l.every((h) => !Number.isNaN(+h))) {
|
|
236
|
+
const h = l.map((u) => Math.abs(u) < 1e-6 ? 0 : u);
|
|
237
|
+
n = n.multiply(K(h));
|
|
238
|
+
} else if (i === "translate3d" && y.every((h) => !Number.isNaN(+h)))
|
|
239
|
+
n = n.translate(c, a, m);
|
|
240
|
+
else if (i === "translate" && c && m === void 0)
|
|
241
|
+
n = n.translate(c, a || 0, 0);
|
|
242
|
+
else if (i === "rotate3d" && g.every((h) => !Number.isNaN(+h)) && f)
|
|
243
|
+
n = n.rotateAxisAngle(c, a, m, f);
|
|
244
|
+
else if (i === "rotate" && c && [a, m].every((h) => h === void 0))
|
|
245
|
+
n = n.rotate(0, 0, c);
|
|
246
|
+
else if (i === "scale3d" && y.every((h) => !Number.isNaN(+h)) && y.some((h) => h !== 1))
|
|
247
|
+
n = n.scale(c, a, m);
|
|
248
|
+
else if (i === "scale" && !Number.isNaN(c) && c !== 1 && m === void 0) {
|
|
249
|
+
const h = Number.isNaN(+a) ? c : a;
|
|
250
|
+
n = n.scale(c, h, 1);
|
|
251
|
+
} else if (i === "skew" && (c || !Number.isNaN(c) && a) && m === void 0)
|
|
252
|
+
n = n.skew(c, a || 0);
|
|
253
|
+
else if (["translate", "rotate", "scale", "skew"].some((h) => i.includes(h)) && /[XYZ]/.test(i) && c && [a, m].every((h) => h === void 0))
|
|
254
|
+
if (i === "skewX" || i === "skewY")
|
|
255
|
+
n = n[i](c);
|
|
256
|
+
else {
|
|
257
|
+
const h = i.replace(/[XYZ]/, ""), u = i.replace(h, ""), x = ["X", "Y", "Z"].indexOf(u), p = h === "scale" ? 1 : 0, d = [x === 0 ? c : p, x === 1 ? c : p, x === 2 ? c : p];
|
|
258
|
+
n = n[h](...d);
|
|
259
|
+
}
|
|
260
|
+
else
|
|
261
|
+
throw TypeError(r);
|
|
262
|
+
}), n;
|
|
263
|
+
}, xt = (e, t) => t ? [e.a, e.b, e.c, e.d, e.e, e.f] : [
|
|
264
|
+
e.m11,
|
|
265
|
+
e.m12,
|
|
266
|
+
e.m13,
|
|
267
|
+
e.m14,
|
|
268
|
+
e.m21,
|
|
269
|
+
e.m22,
|
|
270
|
+
e.m23,
|
|
271
|
+
e.m24,
|
|
272
|
+
e.m31,
|
|
273
|
+
e.m32,
|
|
274
|
+
e.m33,
|
|
275
|
+
e.m34,
|
|
276
|
+
e.m41,
|
|
277
|
+
e.m42,
|
|
278
|
+
e.m43,
|
|
279
|
+
e.m44
|
|
280
|
+
], Dt = (e, t, n) => {
|
|
281
|
+
const r = new N();
|
|
282
|
+
return r.m41 = e, r.e = e, r.m42 = t, r.f = t, r.m43 = n, r;
|
|
283
|
+
}, Zt = (e, t, n) => {
|
|
284
|
+
const r = new N(), s = Math.PI / 180, i = e * s, o = t * s, l = n * s, c = Math.cos(i), a = -Math.sin(i), m = Math.cos(o), f = -Math.sin(o), y = Math.cos(l), g = -Math.sin(l), h = m * y, u = -m * g;
|
|
285
|
+
r.m11 = h, r.a = h, r.m12 = u, r.b = u, r.m13 = f;
|
|
286
|
+
const x = a * f * y + c * g;
|
|
287
|
+
r.m21 = x, r.c = x;
|
|
288
|
+
const p = c * y - a * f * g;
|
|
289
|
+
return r.m22 = p, r.d = p, r.m23 = -a * m, r.m31 = a * g - c * f * y, r.m32 = a * y + c * f * g, r.m33 = c * m, r;
|
|
290
|
+
}, Rt = (e, t, n, r) => {
|
|
291
|
+
const s = new N(), i = Math.sqrt(e * e + t * t + n * n);
|
|
292
|
+
if (i === 0)
|
|
293
|
+
return s;
|
|
294
|
+
const o = e / i, l = t / i, c = n / i, a = r * (Math.PI / 360), m = Math.sin(a), f = Math.cos(a), y = m * m, g = o * o, h = l * l, u = c * c, x = 1 - 2 * (h + u) * y;
|
|
295
|
+
s.m11 = x, s.a = x;
|
|
296
|
+
const p = 2 * (o * l * y + c * m * f);
|
|
297
|
+
s.m12 = p, s.b = p, s.m13 = 2 * (o * c * y - l * m * f);
|
|
298
|
+
const d = 2 * (l * o * y - c * m * f);
|
|
299
|
+
s.m21 = d, s.c = d;
|
|
300
|
+
const A = 1 - 2 * (u + g) * y;
|
|
301
|
+
return s.m22 = A, s.d = A, s.m23 = 2 * (l * c * y + o * m * f), s.m31 = 2 * (c * o * y + l * m * f), s.m32 = 2 * (c * l * y - o * m * f), s.m33 = 1 - 2 * (g + h) * y, s;
|
|
302
|
+
}, Xt = (e, t, n) => {
|
|
303
|
+
const r = new N();
|
|
304
|
+
return r.m11 = e, r.a = e, r.m22 = t, r.d = t, r.m33 = n, r;
|
|
305
|
+
}, lt = (e, t) => {
|
|
306
|
+
const n = new N();
|
|
307
|
+
if (e) {
|
|
308
|
+
const r = e * Math.PI / 180, s = Math.tan(r);
|
|
309
|
+
n.m21 = s, n.c = s;
|
|
310
|
+
}
|
|
311
|
+
if (t) {
|
|
312
|
+
const r = t * Math.PI / 180, s = Math.tan(r);
|
|
313
|
+
n.m12 = s, n.b = s;
|
|
314
|
+
}
|
|
315
|
+
return n;
|
|
316
|
+
}, Ft = (e) => lt(e, 0), Qt = (e) => lt(0, e), k = (e, t) => {
|
|
317
|
+
const n = t.m11 * e.m11 + t.m12 * e.m21 + t.m13 * e.m31 + t.m14 * e.m41, r = t.m11 * e.m12 + t.m12 * e.m22 + t.m13 * e.m32 + t.m14 * e.m42, s = t.m11 * e.m13 + t.m12 * e.m23 + t.m13 * e.m33 + t.m14 * e.m43, i = t.m11 * e.m14 + t.m12 * e.m24 + t.m13 * e.m34 + t.m14 * e.m44, o = t.m21 * e.m11 + t.m22 * e.m21 + t.m23 * e.m31 + t.m24 * e.m41, l = t.m21 * e.m12 + t.m22 * e.m22 + t.m23 * e.m32 + t.m24 * e.m42, c = t.m21 * e.m13 + t.m22 * e.m23 + t.m23 * e.m33 + t.m24 * e.m43, a = t.m21 * e.m14 + t.m22 * e.m24 + t.m23 * e.m34 + t.m24 * e.m44, m = t.m31 * e.m11 + t.m32 * e.m21 + t.m33 * e.m31 + t.m34 * e.m41, f = t.m31 * e.m12 + t.m32 * e.m22 + t.m33 * e.m32 + t.m34 * e.m42, y = t.m31 * e.m13 + t.m32 * e.m23 + t.m33 * e.m33 + t.m34 * e.m43, g = t.m31 * e.m14 + t.m32 * e.m24 + t.m33 * e.m34 + t.m34 * e.m44, h = t.m41 * e.m11 + t.m42 * e.m21 + t.m43 * e.m31 + t.m44 * e.m41, u = t.m41 * e.m12 + t.m42 * e.m22 + t.m43 * e.m32 + t.m44 * e.m42, x = t.m41 * e.m13 + t.m42 * e.m23 + t.m43 * e.m33 + t.m44 * e.m43, p = t.m41 * e.m14 + t.m42 * e.m24 + t.m43 * e.m34 + t.m44 * e.m44;
|
|
318
|
+
return K([n, r, s, i, o, l, c, a, m, f, y, g, h, u, x, p]);
|
|
319
|
+
};
|
|
320
|
+
class N {
|
|
321
|
+
constructor(t) {
|
|
322
|
+
return this.a = 1, this.b = 0, this.c = 0, this.d = 1, this.e = 0, this.f = 0, this.m11 = 1, this.m12 = 0, this.m13 = 0, this.m14 = 0, this.m21 = 0, this.m22 = 1, this.m23 = 0, this.m24 = 0, this.m31 = 0, this.m32 = 0, this.m33 = 1, this.m34 = 0, this.m41 = 0, this.m42 = 0, this.m43 = 0, this.m44 = 1, t ? this.setMatrixValue(t) : this;
|
|
323
|
+
}
|
|
324
|
+
get isIdentity() {
|
|
325
|
+
return this.m11 === 1 && this.m12 === 0 && this.m13 === 0 && this.m14 === 0 && this.m21 === 0 && this.m22 === 1 && this.m23 === 0 && this.m24 === 0 && this.m31 === 0 && this.m32 === 0 && this.m33 === 1 && this.m34 === 0 && this.m41 === 0 && this.m42 === 0 && this.m43 === 0 && this.m44 === 1;
|
|
326
|
+
}
|
|
327
|
+
get is2D() {
|
|
328
|
+
return this.m31 === 0 && this.m32 === 0 && this.m33 === 1 && this.m34 === 0 && this.m43 === 0 && this.m44 === 1;
|
|
329
|
+
}
|
|
330
|
+
setMatrixValue(t) {
|
|
331
|
+
return typeof t == "string" && t.length && t !== "none" ? Et(t) : Array.isArray(t) || t instanceof Float64Array || t instanceof Float32Array ? K(t) : typeof t == "object" ? jt(t) : this;
|
|
332
|
+
}
|
|
333
|
+
toFloat32Array(t) {
|
|
334
|
+
return Float32Array.from(xt(this, t));
|
|
335
|
+
}
|
|
336
|
+
toFloat64Array(t) {
|
|
337
|
+
return Float64Array.from(xt(this, t));
|
|
338
|
+
}
|
|
339
|
+
toString() {
|
|
340
|
+
const { is2D: t } = this, n = this.toFloat64Array(t).join(", ");
|
|
341
|
+
return `${t ? "matrix" : "matrix3d"}(${n})`;
|
|
342
|
+
}
|
|
343
|
+
toJSON() {
|
|
344
|
+
const { is2D: t, isIdentity: n } = this;
|
|
345
|
+
return { ...this, is2D: t, isIdentity: n };
|
|
346
|
+
}
|
|
347
|
+
multiply(t) {
|
|
348
|
+
return k(this, t);
|
|
349
|
+
}
|
|
350
|
+
translate(t, n, r) {
|
|
351
|
+
const s = t;
|
|
352
|
+
let i = n, o = r;
|
|
353
|
+
return typeof i > "u" && (i = 0), typeof o > "u" && (o = 0), k(this, Dt(s, i, o));
|
|
354
|
+
}
|
|
355
|
+
scale(t, n, r) {
|
|
356
|
+
const s = t;
|
|
357
|
+
let i = n, o = r;
|
|
358
|
+
return typeof i > "u" && (i = t), typeof o > "u" && (o = 1), k(this, Xt(s, i, o));
|
|
359
|
+
}
|
|
360
|
+
rotate(t, n, r) {
|
|
361
|
+
let s = t, i = n || 0, o = r || 0;
|
|
362
|
+
return typeof t == "number" && typeof n > "u" && typeof r > "u" && (o = s, s = 0, i = 0), k(this, Zt(s, i, o));
|
|
363
|
+
}
|
|
364
|
+
rotateAxisAngle(t, n, r, s) {
|
|
365
|
+
if ([t, n, r, s].some((i) => Number.isNaN(+i)))
|
|
366
|
+
throw new TypeError("CSSMatrix: expecting 4 values");
|
|
367
|
+
return k(this, Rt(t, n, r, s));
|
|
368
|
+
}
|
|
369
|
+
skewX(t) {
|
|
370
|
+
return k(this, Ft(t));
|
|
371
|
+
}
|
|
372
|
+
skewY(t) {
|
|
373
|
+
return k(this, Qt(t));
|
|
374
|
+
}
|
|
375
|
+
skew(t, n) {
|
|
376
|
+
return k(this, lt(t, n));
|
|
377
|
+
}
|
|
378
|
+
transformPoint(t) {
|
|
379
|
+
const n = this.m11 * t.x + this.m21 * t.y + this.m31 * t.z + this.m41 * t.w, r = this.m12 * t.x + this.m22 * t.y + this.m32 * t.z + this.m42 * t.w, s = this.m13 * t.x + this.m23 * t.y + this.m33 * t.z + this.m43 * t.w, i = this.m14 * t.x + this.m24 * t.y + this.m34 * t.z + this.m44 * t.w;
|
|
380
|
+
return t instanceof DOMPoint ? new DOMPoint(n, r, s, i) : {
|
|
381
|
+
x: n,
|
|
382
|
+
y: r,
|
|
383
|
+
z: s,
|
|
384
|
+
w: i
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
C(N, "Translate", Dt), C(N, "Rotate", Zt), C(N, "RotateAxisAngle", Rt), C(N, "Scale", Xt), C(N, "SkewX", Ft), C(N, "SkewY", Qt), C(N, "Skew", lt), C(N, "Multiply", k), C(N, "fromArray", K), C(N, "fromMatrix", jt), C(N, "fromString", Et), C(N, "toArray", xt), C(N, "isCompatibleArray", zt), C(N, "isCompatibleObject", It);
|
|
389
|
+
const Mt = (e) => ct(e) && e.every(([t]) => t === t.toUpperCase()), X = (e) => {
|
|
390
|
+
if (Mt(e))
|
|
391
|
+
return [...e];
|
|
392
|
+
const t = R(e);
|
|
393
|
+
let n = 0, r = 0, s = 0, i = 0;
|
|
394
|
+
return t.map((o) => {
|
|
395
|
+
const l = o.slice(1).map(Number), [c] = o, a = c.toUpperCase();
|
|
396
|
+
if (c === "M")
|
|
397
|
+
return [n, r] = l, s = n, i = r, ["M", n, r];
|
|
398
|
+
let m = [];
|
|
399
|
+
if (c !== a)
|
|
400
|
+
if (a === "A")
|
|
401
|
+
m = [
|
|
402
|
+
a,
|
|
403
|
+
l[0],
|
|
404
|
+
l[1],
|
|
405
|
+
l[2],
|
|
406
|
+
l[3],
|
|
407
|
+
l[4],
|
|
408
|
+
l[5] + n,
|
|
409
|
+
l[6] + r
|
|
410
|
+
];
|
|
411
|
+
else if (a === "V")
|
|
412
|
+
m = [a, l[0] + r];
|
|
413
|
+
else if (a === "H")
|
|
414
|
+
m = [a, l[0] + n];
|
|
415
|
+
else {
|
|
416
|
+
const f = l.map((y, g) => y + (g % 2 ? r : n));
|
|
417
|
+
m = [a, ...f];
|
|
418
|
+
}
|
|
419
|
+
else
|
|
420
|
+
m = [a, ...l];
|
|
421
|
+
return a === "Z" ? (n = s, r = i) : a === "H" ? [, n] = m : a === "V" ? [, r] = m : ([n, r] = m.slice(-2), a === "M" && (s = n, i = r)), m;
|
|
422
|
+
});
|
|
423
|
+
}, ae = (e, t) => {
|
|
424
|
+
const [n] = e, { x1: r, y1: s, x2: i, y2: o } = t, l = e.slice(1).map(Number);
|
|
425
|
+
let c = e;
|
|
426
|
+
if ("TQ".includes(n) || (t.qx = null, t.qy = null), n === "H")
|
|
427
|
+
c = ["L", e[1], s];
|
|
428
|
+
else if (n === "V")
|
|
429
|
+
c = ["L", r, e[1]];
|
|
430
|
+
else if (n === "S") {
|
|
431
|
+
const a = r * 2 - i, m = s * 2 - o;
|
|
432
|
+
t.x1 = a, t.y1 = m, c = ["C", a, m, ...l];
|
|
433
|
+
} else if (n === "T") {
|
|
434
|
+
const a = r * 2 - (t.qx ? t.qx : 0), m = s * 2 - (t.qy ? t.qy : 0);
|
|
435
|
+
t.qx = a, t.qy = m, c = ["Q", a, m, ...l];
|
|
436
|
+
} else if (n === "Q") {
|
|
437
|
+
const [a, m] = l;
|
|
438
|
+
t.qx = a, t.qy = m;
|
|
439
|
+
}
|
|
440
|
+
return c;
|
|
441
|
+
}, At = (e) => Mt(e) && e.every(([t]) => "ACLMQZ".includes(t)), mt = {
|
|
442
|
+
x1: 0,
|
|
443
|
+
y1: 0,
|
|
444
|
+
x2: 0,
|
|
445
|
+
y2: 0,
|
|
446
|
+
x: 0,
|
|
447
|
+
y: 0,
|
|
448
|
+
qx: null,
|
|
449
|
+
qy: null
|
|
450
|
+
}, O = (e) => {
|
|
451
|
+
if (At(e))
|
|
452
|
+
return [...e];
|
|
453
|
+
const t = X(e), n = { ...mt }, r = t.length;
|
|
454
|
+
for (let s = 0; s < r; s += 1) {
|
|
455
|
+
t[s], t[s] = ae(t[s], n);
|
|
456
|
+
const i = t[s], o = i.length;
|
|
457
|
+
n.x1 = +i[o - 2], n.y1 = +i[o - 1], n.x2 = +i[o - 4] || n.x1, n.y2 = +i[o - 3] || n.y1;
|
|
458
|
+
}
|
|
459
|
+
return t;
|
|
460
|
+
}, V = (e, t, n) => {
|
|
461
|
+
const [r, s] = e, [i, o] = t;
|
|
462
|
+
return [r + (i - r) * n, s + (o - s) * n];
|
|
463
|
+
}, pt = (e, t, n, r, s) => {
|
|
464
|
+
const i = U([e, t], [n, r]);
|
|
465
|
+
let o = { x: 0, y: 0 };
|
|
466
|
+
if (typeof s == "number")
|
|
467
|
+
if (s <= 0)
|
|
468
|
+
o = { x: e, y: t };
|
|
469
|
+
else if (s >= i)
|
|
470
|
+
o = { x: n, y: r };
|
|
471
|
+
else {
|
|
472
|
+
const [l, c] = V([e, t], [n, r], s / i);
|
|
473
|
+
o = { x: l, y: c };
|
|
474
|
+
}
|
|
475
|
+
return {
|
|
476
|
+
length: i,
|
|
477
|
+
point: o,
|
|
478
|
+
min: {
|
|
479
|
+
x: Math.min(e, n),
|
|
480
|
+
y: Math.min(t, r)
|
|
481
|
+
},
|
|
482
|
+
max: {
|
|
483
|
+
x: Math.max(e, n),
|
|
484
|
+
y: Math.max(t, r)
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
}, wt = (e, t) => {
|
|
488
|
+
const { x: n, y: r } = e, { x: s, y: i } = t, o = n * s + r * i, l = Math.sqrt((n ** 2 + r ** 2) * (s ** 2 + i ** 2));
|
|
489
|
+
return (n * i - r * s < 0 ? -1 : 1) * Math.acos(o / l);
|
|
490
|
+
}, ce = (e, t, n, r, s, i, o, l, c, a) => {
|
|
491
|
+
const { abs: m, sin: f, cos: y, sqrt: g, PI: h } = Math;
|
|
492
|
+
let u = m(n), x = m(r);
|
|
493
|
+
const d = (s % 360 + 360) % 360 * (h / 180);
|
|
494
|
+
if (e === l && t === c)
|
|
495
|
+
return { x: e, y: t };
|
|
496
|
+
if (u === 0 || x === 0)
|
|
497
|
+
return pt(e, t, l, c, a).point;
|
|
498
|
+
const A = (e - l) / 2, b = (t - c) / 2, M = {
|
|
499
|
+
x: y(d) * A + f(d) * b,
|
|
500
|
+
y: -f(d) * A + y(d) * b
|
|
501
|
+
}, w = M.x ** 2 / u ** 2 + M.y ** 2 / x ** 2;
|
|
502
|
+
w > 1 && (u *= g(w), x *= g(w));
|
|
503
|
+
const $ = u ** 2 * x ** 2 - u ** 2 * M.y ** 2 - x ** 2 * M.x ** 2, F = u ** 2 * M.y ** 2 + x ** 2 * M.x ** 2;
|
|
504
|
+
let E = $ / F;
|
|
505
|
+
E = E < 0 ? 0 : E;
|
|
506
|
+
const _ = (i !== o ? 1 : -1) * g(E), S = {
|
|
507
|
+
x: _ * (u * M.y / x),
|
|
508
|
+
y: _ * (-(x * M.x) / u)
|
|
509
|
+
}, W = {
|
|
510
|
+
x: y(d) * S.x - f(d) * S.y + (e + l) / 2,
|
|
511
|
+
y: f(d) * S.x + y(d) * S.y + (t + c) / 2
|
|
512
|
+
}, Q = {
|
|
513
|
+
x: (M.x - S.x) / u,
|
|
514
|
+
y: (M.y - S.y) / x
|
|
515
|
+
}, tt = wt({ x: 1, y: 0 }, Q), et = {
|
|
516
|
+
x: (-M.x - S.x) / u,
|
|
517
|
+
y: (-M.y - S.y) / x
|
|
518
|
+
};
|
|
519
|
+
let T = wt(Q, et);
|
|
520
|
+
!o && T > 0 ? T -= 2 * h : o && T < 0 && (T += 2 * h), T %= 2 * h;
|
|
521
|
+
const L = tt + T * a, H = u * y(L), Y = x * f(L);
|
|
522
|
+
return {
|
|
523
|
+
x: y(d) * H - f(d) * Y + W.x,
|
|
524
|
+
y: f(d) * H + y(d) * Y + W.y
|
|
525
|
+
};
|
|
526
|
+
}, le = (e, t, n, r, s, i, o, l, c, a) => {
|
|
527
|
+
const m = typeof a == "number";
|
|
528
|
+
let f = e, y = t, g = 0, h = [f, y, g], u = [f, y], x = 0, p = { x: 0, y: 0 }, d = [{ x: f, y }];
|
|
529
|
+
m && a <= 0 && (p = { x: f, y });
|
|
530
|
+
const A = 300;
|
|
531
|
+
for (let b = 0; b <= A; b += 1) {
|
|
532
|
+
if (x = b / A, { x: f, y } = ce(e, t, n, r, s, i, o, l, c, x), d = [...d, { x: f, y }], g += U(u, [f, y]), u = [f, y], m && g > a && a > h[2]) {
|
|
533
|
+
const M = (g - a) / (g - h[2]);
|
|
534
|
+
p = {
|
|
535
|
+
x: u[0] * (1 - M) + h[0] * M,
|
|
536
|
+
y: u[1] * (1 - M) + h[1] * M
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
h = [f, y, g];
|
|
540
|
+
}
|
|
541
|
+
return m && a >= g && (p = { x: l, y: c }), {
|
|
542
|
+
length: g,
|
|
543
|
+
point: p,
|
|
544
|
+
min: {
|
|
545
|
+
x: Math.min(...d.map((b) => b.x)),
|
|
546
|
+
y: Math.min(...d.map((b) => b.y))
|
|
547
|
+
},
|
|
548
|
+
max: {
|
|
549
|
+
x: Math.max(...d.map((b) => b.x)),
|
|
550
|
+
y: Math.max(...d.map((b) => b.y))
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
}, me = (e, t, n, r, s, i, o, l, c) => {
|
|
554
|
+
const a = 1 - c;
|
|
555
|
+
return {
|
|
556
|
+
x: a ** 3 * e + 3 * a ** 2 * c * n + 3 * a * c ** 2 * s + c ** 3 * o,
|
|
557
|
+
y: a ** 3 * t + 3 * a ** 2 * c * r + 3 * a * c ** 2 * i + c ** 3 * l
|
|
558
|
+
};
|
|
559
|
+
}, he = (e, t, n, r, s, i, o, l, c) => {
|
|
560
|
+
const a = typeof c == "number";
|
|
561
|
+
let m = e, f = t, y = 0, g = [m, f, y], h = [m, f], u = 0, x = { x: 0, y: 0 }, p = [{ x: m, y: f }];
|
|
562
|
+
a && c <= 0 && (x = { x: m, y: f });
|
|
563
|
+
const d = 300;
|
|
564
|
+
for (let A = 0; A <= d; A += 1) {
|
|
565
|
+
if (u = A / d, { x: m, y: f } = me(e, t, n, r, s, i, o, l, u), p = [...p, { x: m, y: f }], y += U(h, [m, f]), h = [m, f], a && y > c && c > g[2]) {
|
|
566
|
+
const b = (y - c) / (y - g[2]);
|
|
567
|
+
x = {
|
|
568
|
+
x: h[0] * (1 - b) + g[0] * b,
|
|
569
|
+
y: h[1] * (1 - b) + g[1] * b
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
g = [m, f, y];
|
|
573
|
+
}
|
|
574
|
+
return a && c >= y && (x = { x: o, y: l }), {
|
|
575
|
+
length: y,
|
|
576
|
+
point: x,
|
|
577
|
+
min: {
|
|
578
|
+
x: Math.min(...p.map((A) => A.x)),
|
|
579
|
+
y: Math.min(...p.map((A) => A.y))
|
|
580
|
+
},
|
|
581
|
+
max: {
|
|
582
|
+
x: Math.max(...p.map((A) => A.x)),
|
|
583
|
+
y: Math.max(...p.map((A) => A.y))
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
}, ue = (e, t, n, r, s, i, o) => {
|
|
587
|
+
const l = 1 - o;
|
|
588
|
+
return {
|
|
589
|
+
x: l ** 2 * e + 2 * l * o * n + o ** 2 * s,
|
|
590
|
+
y: l ** 2 * t + 2 * l * o * r + o ** 2 * i
|
|
591
|
+
};
|
|
592
|
+
}, fe = (e, t, n, r, s, i, o) => {
|
|
593
|
+
const l = typeof o == "number";
|
|
594
|
+
let c = e, a = t, m = 0, f = [c, a, m], y = [c, a], g = 0, h = { x: 0, y: 0 }, u = [{ x: c, y: a }];
|
|
595
|
+
l && o <= 0 && (h = { x: c, y: a });
|
|
596
|
+
const x = 300;
|
|
597
|
+
for (let p = 0; p <= x; p += 1) {
|
|
598
|
+
if (g = p / x, { x: c, y: a } = ue(e, t, n, r, s, i, g), u = [...u, { x: c, y: a }], m += U(y, [c, a]), y = [c, a], l && m > o && o > f[2]) {
|
|
599
|
+
const d = (m - o) / (m - f[2]);
|
|
600
|
+
h = {
|
|
601
|
+
x: y[0] * (1 - d) + f[0] * d,
|
|
602
|
+
y: y[1] * (1 - d) + f[1] * d
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
f = [c, a, m];
|
|
606
|
+
}
|
|
607
|
+
return l && o >= m && (h = { x: s, y: i }), {
|
|
608
|
+
length: m,
|
|
609
|
+
point: h,
|
|
610
|
+
min: {
|
|
611
|
+
x: Math.min(...u.map((p) => p.x)),
|
|
612
|
+
y: Math.min(...u.map((p) => p.y))
|
|
613
|
+
},
|
|
614
|
+
max: {
|
|
615
|
+
x: Math.max(...u.map((p) => p.x)),
|
|
616
|
+
y: Math.max(...u.map((p) => p.y))
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
}, ht = (e, t) => {
|
|
620
|
+
const n = O(e), r = typeof t == "number";
|
|
621
|
+
let s, i = [], o, l = 0, c = 0, a = 0, m = 0, f, y = [], g = [], h = 0, u = { x: 0, y: 0 }, x = u, p = u, d = u, A = 0;
|
|
622
|
+
for (let b = 0, M = n.length; b < M; b += 1)
|
|
623
|
+
f = n[b], [o] = f, s = o === "M", i = s ? i : [l, c, ...f.slice(1)], s ? ([, a, m] = f, u = { x: a, y: m }, x = u, h = 0, r && t < 1e-3 && (d = u)) : o === "L" ? { length: h, min: u, max: x, point: p } = pt(
|
|
624
|
+
...i,
|
|
625
|
+
(t || 0) - A
|
|
626
|
+
) : o === "A" ? { length: h, min: u, max: x, point: p } = le(
|
|
627
|
+
...i,
|
|
628
|
+
(t || 0) - A
|
|
629
|
+
) : o === "C" ? { length: h, min: u, max: x, point: p } = he(
|
|
630
|
+
...i,
|
|
631
|
+
(t || 0) - A
|
|
632
|
+
) : o === "Q" ? { length: h, min: u, max: x, point: p } = fe(
|
|
633
|
+
...i,
|
|
634
|
+
(t || 0) - A
|
|
635
|
+
) : o === "Z" && (i = [l, c, a, m], { length: h, min: u, max: x, point: p } = pt(
|
|
636
|
+
...i,
|
|
637
|
+
(t || 0) - A
|
|
638
|
+
)), r && A < t && A + h >= t && (d = p), g = [...g, x], y = [...y, u], A += h, [l, c] = o !== "Z" ? f.slice(-2) : [a, m];
|
|
639
|
+
return r && t >= A && (d = { x: l, y: c }), {
|
|
640
|
+
length: A,
|
|
641
|
+
point: d,
|
|
642
|
+
min: {
|
|
643
|
+
x: Math.min(...y.map((b) => b.x)),
|
|
644
|
+
y: Math.min(...y.map((b) => b.y))
|
|
645
|
+
},
|
|
646
|
+
max: {
|
|
647
|
+
x: Math.max(...g.map((b) => b.x)),
|
|
648
|
+
y: Math.max(...g.map((b) => b.y))
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
}, vt = (e) => {
|
|
652
|
+
if (!e)
|
|
653
|
+
return {
|
|
654
|
+
x: 0,
|
|
655
|
+
y: 0,
|
|
656
|
+
width: 0,
|
|
657
|
+
height: 0,
|
|
658
|
+
x2: 0,
|
|
659
|
+
y2: 0,
|
|
660
|
+
cx: 0,
|
|
661
|
+
cy: 0,
|
|
662
|
+
cz: 0
|
|
663
|
+
};
|
|
664
|
+
const {
|
|
665
|
+
min: { x: t, y: n },
|
|
666
|
+
max: { x: r, y: s }
|
|
667
|
+
} = ht(e), i = r - t, o = s - n;
|
|
668
|
+
return {
|
|
669
|
+
width: i,
|
|
670
|
+
height: o,
|
|
671
|
+
x: t,
|
|
672
|
+
y: n,
|
|
673
|
+
x2: r,
|
|
674
|
+
y2: s,
|
|
675
|
+
cx: t + i / 2,
|
|
676
|
+
cy: n + o / 2,
|
|
677
|
+
cz: Math.max(i, o) + Math.min(i, o) / 2
|
|
678
|
+
};
|
|
679
|
+
}, dt = (e, t, n) => {
|
|
680
|
+
if (e[n].length > 7) {
|
|
681
|
+
e[n].shift();
|
|
682
|
+
const r = e[n];
|
|
683
|
+
let s = n;
|
|
684
|
+
for (; r.length; )
|
|
685
|
+
t[n] = "A", e.splice(s += 1, 0, ["C", ...r.splice(0, 6)]);
|
|
686
|
+
e.splice(n, 1);
|
|
687
|
+
}
|
|
688
|
+
}, Ht = (e) => At(e) && e.every(([t]) => "MC".includes(t)), nt = (e, t, n) => {
|
|
689
|
+
const r = e * Math.cos(n) - t * Math.sin(n), s = e * Math.sin(n) + t * Math.cos(n);
|
|
690
|
+
return { x: r, y: s };
|
|
691
|
+
}, Yt = (e, t, n, r, s, i, o, l, c, a) => {
|
|
692
|
+
let m = e, f = t, y = n, g = r, h = l, u = c;
|
|
693
|
+
const x = Math.PI * 120 / 180, p = Math.PI / 180 * (+s || 0);
|
|
694
|
+
let d = [], A, b, M, w, $;
|
|
695
|
+
if (a)
|
|
696
|
+
[b, M, w, $] = a;
|
|
697
|
+
else {
|
|
698
|
+
A = nt(m, f, -p), m = A.x, f = A.y, A = nt(h, u, -p), h = A.x, u = A.y;
|
|
699
|
+
const P = (m - h) / 2, v = (f - u) / 2;
|
|
700
|
+
let z = P * P / (y * y) + v * v / (g * g);
|
|
701
|
+
z > 1 && (z = Math.sqrt(z), y *= z, g *= z);
|
|
702
|
+
const yt = y * y, gt = g * g, Pt = (i === o ? -1 : 1) * Math.sqrt(Math.abs((yt * gt - yt * v * v - gt * P * P) / (yt * v * v + gt * P * P)));
|
|
703
|
+
w = Pt * y * v / g + (m + h) / 2, $ = Pt * -g * P / y + (f + u) / 2, b = Math.asin(((f - $) / g * 10 ** 9 >> 0) / 10 ** 9), M = Math.asin(((u - $) / g * 10 ** 9 >> 0) / 10 ** 9), b = m < w ? Math.PI - b : b, M = h < w ? Math.PI - M : M, b < 0 && (b = Math.PI * 2 + b), M < 0 && (M = Math.PI * 2 + M), o && b > M && (b -= Math.PI * 2), !o && M > b && (M -= Math.PI * 2);
|
|
704
|
+
}
|
|
705
|
+
let F = M - b;
|
|
706
|
+
if (Math.abs(F) > x) {
|
|
707
|
+
const P = M, v = h, z = u;
|
|
708
|
+
M = b + x * (o && M > b ? 1 : -1), h = w + y * Math.cos(M), u = $ + g * Math.sin(M), d = Yt(h, u, y, g, s, 0, o, v, z, [M, P, w, $]);
|
|
709
|
+
}
|
|
710
|
+
F = M - b;
|
|
711
|
+
const E = Math.cos(b), _ = Math.sin(b), S = Math.cos(M), W = Math.sin(M), Q = Math.tan(F / 4), tt = 4 / 3 * y * Q, et = 4 / 3 * g * Q, T = [m, f], L = [m + tt * _, f - et * E], H = [h + tt * W, u - et * S], Y = [h, u];
|
|
712
|
+
if (L[0] = 2 * T[0] - L[0], L[1] = 2 * T[1] - L[1], a)
|
|
713
|
+
return [...L, ...H, ...Y, ...d];
|
|
714
|
+
d = [...L, ...H, ...Y, ...d];
|
|
715
|
+
const ft = [];
|
|
716
|
+
for (let P = 0, v = d.length; P < v; P += 1)
|
|
717
|
+
ft[P] = P % 2 ? nt(d[P - 1], d[P], p).y : nt(d[P], d[P + 1], p).x;
|
|
718
|
+
return ft;
|
|
719
|
+
}, ye = (e, t, n, r, s, i) => {
|
|
720
|
+
const o = 0.3333333333333333, l = 2 / 3;
|
|
721
|
+
return [
|
|
722
|
+
o * e + l * n,
|
|
723
|
+
o * t + l * r,
|
|
724
|
+
o * s + l * n,
|
|
725
|
+
o * i + l * r,
|
|
726
|
+
s,
|
|
727
|
+
i
|
|
728
|
+
];
|
|
729
|
+
}, St = (e, t, n, r) => [...V([e, t], [n, r], 0.5), n, r, n, r], rt = (e, t) => {
|
|
730
|
+
const [n] = e, r = e.slice(1).map(Number), [s, i] = r;
|
|
731
|
+
let o;
|
|
732
|
+
const { x1: l, y1: c, x: a, y: m } = t;
|
|
733
|
+
return "TQ".includes(n) || (t.qx = null, t.qy = null), n === "M" ? (t.x = s, t.y = i, e) : n === "A" ? (o = [l, c, ...r], ["C", ...Yt(...o)]) : n === "Q" ? (t.qx = s, t.qy = i, o = [l, c, ...r], ["C", ...ye(...o)]) : n === "L" ? ["C", ...St(l, c, s, i)] : n === "Z" ? ["C", ...St(l, c, a, m)] : e;
|
|
734
|
+
}, it = (e) => {
|
|
735
|
+
if (Ht(e))
|
|
736
|
+
return [...e];
|
|
737
|
+
const t = O(e), n = { ...mt }, r = [];
|
|
738
|
+
let s = "", i = t.length;
|
|
739
|
+
for (let o = 0; o < i; o += 1) {
|
|
740
|
+
[s] = t[o], r[o] = s, t[o] = rt(t[o], n), dt(t, r, o), i = t.length;
|
|
741
|
+
const l = t[o], c = l.length;
|
|
742
|
+
n.x1 = +l[c - 2], n.y1 = +l[c - 1], n.x2 = +l[c - 4] || n.x1, n.y2 = +l[c - 3] || n.y1;
|
|
743
|
+
}
|
|
744
|
+
return t;
|
|
745
|
+
}, ge = (e, t, n, r, s, i, o, l) => 3 * ((l - t) * (n + s) - (o - e) * (r + i) + r * (e - s) - n * (t - i) + l * (s + e / 3) - o * (i + t / 3)) / 20, Bt = (e) => {
|
|
746
|
+
let t = 0, n = 0, r = 0;
|
|
747
|
+
return it(e).map((s) => {
|
|
748
|
+
switch (s[0]) {
|
|
749
|
+
case "M":
|
|
750
|
+
return [, t, n] = s, 0;
|
|
751
|
+
default:
|
|
752
|
+
return r = ge(t, n, ...s.slice(1)), [t, n] = s.slice(-2), r;
|
|
753
|
+
}
|
|
754
|
+
}).reduce((s, i) => s + i, 0);
|
|
755
|
+
}, Z = (e) => ht(e).length, xe = (e) => Bt(it(e)) >= 0, J = (e, t) => ht(e, t).point, Nt = (e, t) => {
|
|
756
|
+
const n = R(e);
|
|
757
|
+
let r = [...n], s = Z(r), i = r.length - 1, o = 0, l = 0, c = n[0];
|
|
758
|
+
const [a, m] = c.slice(-2), f = { x: a, y: m };
|
|
759
|
+
if (i <= 0 || !t || !Number.isFinite(t))
|
|
760
|
+
return {
|
|
761
|
+
segment: c,
|
|
762
|
+
index: 0,
|
|
763
|
+
length: l,
|
|
764
|
+
point: f,
|
|
765
|
+
lengthAtSegment: o
|
|
766
|
+
};
|
|
767
|
+
if (t >= s)
|
|
768
|
+
return r = n.slice(0, -1), o = Z(r), l = s - o, {
|
|
769
|
+
segment: n[i],
|
|
770
|
+
index: i,
|
|
771
|
+
length: l,
|
|
772
|
+
lengthAtSegment: o
|
|
773
|
+
};
|
|
774
|
+
const y = [];
|
|
775
|
+
for (; i > 0; )
|
|
776
|
+
c = r[i], r = r.slice(0, -1), o = Z(r), l = s - o, s = o, y.push({
|
|
777
|
+
segment: c,
|
|
778
|
+
index: i,
|
|
779
|
+
length: l,
|
|
780
|
+
lengthAtSegment: o
|
|
781
|
+
}), i -= 1;
|
|
782
|
+
return y.find(({ lengthAtSegment: g }) => g <= t);
|
|
783
|
+
}, ut = (e, t) => {
|
|
784
|
+
const n = R(e), r = O(n), s = Z(n), i = (b) => {
|
|
785
|
+
const M = b.x - t.x, w = b.y - t.y;
|
|
786
|
+
return M * M + w * w;
|
|
787
|
+
};
|
|
788
|
+
let o = 8, l, c = { x: 0, y: 0 }, a = 0, m = 0, f = 1 / 0;
|
|
789
|
+
for (let b = 0; b <= s; b += o)
|
|
790
|
+
l = J(r, b), a = i(l), a < f && (c = l, m = b, f = a);
|
|
791
|
+
o /= 2;
|
|
792
|
+
let y, g, h = 0, u = 0, x = 0, p = 0;
|
|
793
|
+
for (; o > 0.5; )
|
|
794
|
+
h = m - o, y = J(r, h), x = i(y), u = m + o, g = J(r, u), p = i(g), h >= 0 && x < f ? (c = y, m = h, f = x) : u <= s && p < f ? (c = g, m = u, f = p) : o /= 2;
|
|
795
|
+
const d = Nt(n, m), A = Math.sqrt(f);
|
|
796
|
+
return { closest: c, distance: A, segment: d };
|
|
797
|
+
}, pe = (e, t) => ut(e, t).closest, de = (e, t) => ut(e, t).segment, be = (e, t) => Nt(e, t).segment, Me = (e, t) => {
|
|
798
|
+
const { distance: n } = ut(e, t);
|
|
799
|
+
return Math.abs(n) < 1e-3;
|
|
800
|
+
}, Gt = (e) => {
|
|
801
|
+
if (typeof e != "string")
|
|
802
|
+
return !1;
|
|
803
|
+
const t = new Ot(e);
|
|
804
|
+
for (G(t); t.index < t.max && !t.err.length; )
|
|
805
|
+
Vt(t);
|
|
806
|
+
return !t.err.length && "mM".includes(t.segments[0][0]);
|
|
807
|
+
}, Jt = (e) => ct(e) && e.slice(1).every(([t]) => t === t.toLowerCase()), ot = (e, t) => {
|
|
808
|
+
let { round: n } = at;
|
|
809
|
+
if (t === "off" || n === "off")
|
|
810
|
+
return [...e];
|
|
811
|
+
n = typeof t == "number" && t >= 0 ? t : n;
|
|
812
|
+
const r = typeof n == "number" && n >= 1 ? 10 ** n : 1;
|
|
813
|
+
return e.map((s) => {
|
|
814
|
+
const i = s.slice(1).map(Number).map((o) => n ? Math.round(o * r) / r : Math.round(o));
|
|
815
|
+
return [s[0], ...i];
|
|
816
|
+
});
|
|
817
|
+
}, j = (e, t) => ot(e, t).map((n) => n[0] + n.slice(1).join(" ")).join(""), Tt = {
|
|
818
|
+
line: ["x1", "y1", "x2", "y2"],
|
|
819
|
+
circle: ["cx", "cy", "r"],
|
|
820
|
+
ellipse: ["cx", "cy", "rx", "ry"],
|
|
821
|
+
rect: ["width", "height", "x", "y", "rx", "ry"],
|
|
822
|
+
polygon: ["points"],
|
|
823
|
+
polyline: ["points"],
|
|
824
|
+
glyph: ["d"]
|
|
825
|
+
}, Ae = (e) => {
|
|
826
|
+
const { x1: t, y1: n, x2: r, y2: s } = e;
|
|
827
|
+
return [
|
|
828
|
+
["M", t, n],
|
|
829
|
+
["L", r, s]
|
|
830
|
+
];
|
|
831
|
+
}, Ne = (e) => {
|
|
832
|
+
const t = [], n = (e.points || "").trim().split(/[\s|,]/).map(Number);
|
|
833
|
+
let r = 0;
|
|
834
|
+
for (; r < n.length; )
|
|
835
|
+
t.push([r ? "L" : "M", n[r], n[r + 1]]), r += 2;
|
|
836
|
+
return e.type === "polygon" ? [...t, ["z"]] : t;
|
|
837
|
+
}, Pe = (e) => {
|
|
838
|
+
const { cx: t, cy: n, r } = e;
|
|
839
|
+
return [
|
|
840
|
+
["M", t - r, n],
|
|
841
|
+
["a", r, r, 0, 1, 0, 2 * r, 0],
|
|
842
|
+
["a", r, r, 0, 1, 0, -2 * r, 0]
|
|
843
|
+
];
|
|
844
|
+
}, Ce = (e) => {
|
|
845
|
+
const { cx: t, cy: n, rx: r, ry: s } = e;
|
|
846
|
+
return [
|
|
847
|
+
["M", t - r, n],
|
|
848
|
+
["a", r, s, 0, 1, 0, 2 * r, 0],
|
|
849
|
+
["a", r, s, 0, 1, 0, -2 * r, 0]
|
|
850
|
+
];
|
|
851
|
+
}, we = (e) => {
|
|
852
|
+
const t = +e.x || 0, n = +e.y || 0, r = +e.width, s = +e.height;
|
|
853
|
+
let i = +e.rx, o = +e.ry;
|
|
854
|
+
return i || o ? (i = i || o, o = o || i, i * 2 > r && (i -= (i * 2 - r) / 2), o * 2 > s && (o -= (o * 2 - s) / 2), [
|
|
855
|
+
["M", t + i, n],
|
|
856
|
+
["h", r - i * 2],
|
|
857
|
+
["s", i, 0, i, o],
|
|
858
|
+
["v", s - o * 2],
|
|
859
|
+
["s", 0, o, -i, o],
|
|
860
|
+
["h", -r + i * 2],
|
|
861
|
+
["s", -i, 0, -i, -o],
|
|
862
|
+
["v", -s + o * 2],
|
|
863
|
+
["s", 0, -o, i, -o]
|
|
864
|
+
]) : [["M", t, n], ["h", r], ["v", s], ["H", t], ["Z"]];
|
|
865
|
+
}, ve = (e, t, n) => {
|
|
866
|
+
const r = n || document, s = r.defaultView || window, i = Object.keys(Tt), o = e instanceof s.SVGElement, l = o ? e.tagName : null;
|
|
867
|
+
if (l && i.every((h) => l !== h))
|
|
868
|
+
throw TypeError(`${q}: "${l}" is not SVGElement`);
|
|
869
|
+
const c = r.createElementNS("http://www.w3.org/2000/svg", "path"), a = o ? l : e.type, m = Tt[a], f = { type: a };
|
|
870
|
+
o ? (m.forEach((h) => {
|
|
871
|
+
m.includes(h) && (f[h] = e.getAttribute(h));
|
|
872
|
+
}), Object.values(e.attributes).forEach(({ name: h, value: u }) => {
|
|
873
|
+
m.includes(h) || c.setAttribute(h, u);
|
|
874
|
+
})) : (Object.assign(f, e), Object.keys(f).forEach((h) => {
|
|
875
|
+
!m.includes(h) && h !== "type" && c.setAttribute(
|
|
876
|
+
h.replace(/[A-Z]/g, (u) => `-${u.toLowerCase()}`),
|
|
877
|
+
f[h]
|
|
878
|
+
);
|
|
879
|
+
}));
|
|
880
|
+
let y = "";
|
|
881
|
+
const g = at.round;
|
|
882
|
+
return a === "circle" ? y = j(Pe(f), g) : a === "ellipse" ? y = j(Ce(f), g) : ["polyline", "polygon"].includes(a) ? y = j(Ne(f), g) : a === "rect" ? y = j(we(f), g) : a === "line" ? y = j(Ae(f), g) : a === "glyph" && (y = o ? e.getAttribute("d") : e.d), Gt(y) ? (c.setAttribute("d", y), t && o && (e.before(c, e), e.remove()), c) : !1;
|
|
883
|
+
}, Lt = (e) => {
|
|
884
|
+
const t = [];
|
|
885
|
+
let n, r = -1;
|
|
886
|
+
return e.forEach((s) => {
|
|
887
|
+
s[0] === "M" ? (n = [s], r += 1) : n = [...n, s], t[r] = n;
|
|
888
|
+
}), t;
|
|
889
|
+
}, bt = (e) => {
|
|
890
|
+
if (Jt(e))
|
|
891
|
+
return [...e];
|
|
892
|
+
const t = R(e);
|
|
893
|
+
let n = 0, r = 0, s = 0, i = 0;
|
|
894
|
+
return t.map((o) => {
|
|
895
|
+
const l = o.slice(1).map(Number), [c] = o, a = c.toLowerCase();
|
|
896
|
+
if (c === "M")
|
|
897
|
+
return [n, r] = l, s = n, i = r, ["M", n, r];
|
|
898
|
+
let m = [];
|
|
899
|
+
if (c !== a)
|
|
900
|
+
if (a === "a")
|
|
901
|
+
m = [
|
|
902
|
+
a,
|
|
903
|
+
l[0],
|
|
904
|
+
l[1],
|
|
905
|
+
l[2],
|
|
906
|
+
l[3],
|
|
907
|
+
l[4],
|
|
908
|
+
l[5] - n,
|
|
909
|
+
l[6] - r
|
|
910
|
+
];
|
|
911
|
+
else if (a === "v")
|
|
912
|
+
m = [a, l[0] - r];
|
|
913
|
+
else if (a === "h")
|
|
914
|
+
m = [a, l[0] - n];
|
|
915
|
+
else {
|
|
916
|
+
const y = l.map((g, h) => g - (h % 2 ? r : n));
|
|
917
|
+
m = [a, ...y];
|
|
918
|
+
}
|
|
919
|
+
else
|
|
920
|
+
c === "m" && (s = l[0] + n, i = l[1] + r), m = [a, ...l];
|
|
921
|
+
const f = m.length;
|
|
922
|
+
return a === "z" ? (n = s, r = i) : a === "h" ? n += m[1] : a === "v" ? r += m[1] : (n += m[f - 2], r += m[f - 1]), m;
|
|
923
|
+
});
|
|
924
|
+
}, Se = (e, t, n, r) => {
|
|
925
|
+
const [s] = e, i = (p) => Math.round(p * 10 ** 4) / 10 ** 4, o = e.slice(1).map((p) => +p), l = t.slice(1).map((p) => +p), { x1: c, y1: a, x2: m, y2: f, x: y, y: g } = n;
|
|
926
|
+
let h = e;
|
|
927
|
+
const [u, x] = l.slice(-2);
|
|
928
|
+
if ("TQ".includes(s) || (n.qx = null, n.qy = null), ["V", "H", "S", "T", "Z"].includes(s))
|
|
929
|
+
h = [s, ...o];
|
|
930
|
+
else if (s === "L")
|
|
931
|
+
i(y) === i(u) ? h = ["V", x] : i(g) === i(x) && (h = ["H", u]);
|
|
932
|
+
else if (s === "C") {
|
|
933
|
+
const [p, d] = l;
|
|
934
|
+
"CS".includes(r) && (i(p) === i(c * 2 - m) && i(d) === i(a * 2 - f) || i(c) === i(m * 2 - y) && i(a) === i(f * 2 - g)) && (h = ["S", ...l.slice(-4)]), n.x1 = p, n.y1 = d;
|
|
935
|
+
} else if (s === "Q") {
|
|
936
|
+
const [p, d] = l;
|
|
937
|
+
n.qx = p, n.qy = d, "QT".includes(r) && (i(p) === i(c * 2 - m) && i(d) === i(a * 2 - f) || i(c) === i(m * 2 - y) && i(a) === i(f * 2 - g)) && (h = ["T", ...l.slice(-2)]);
|
|
938
|
+
}
|
|
939
|
+
return h;
|
|
940
|
+
}, kt = (e, t) => {
|
|
941
|
+
const n = X(e), r = O(n), s = { ...mt }, i = [], o = n.length;
|
|
942
|
+
let l = "", c = "", a = 0, m = 0, f = 0, y = 0;
|
|
943
|
+
for (let u = 0; u < o; u += 1) {
|
|
944
|
+
[l] = n[u], i[u] = l, u && (c = i[u - 1]), n[u] = Se(n[u], r[u], s, c);
|
|
945
|
+
const x = n[u], p = x.length;
|
|
946
|
+
switch (s.x1 = +x[p - 2], s.y1 = +x[p - 1], s.x2 = +x[p - 4] || s.x1, s.y2 = +x[p - 3] || s.y1, l) {
|
|
947
|
+
case "Z":
|
|
948
|
+
a = f, m = y;
|
|
949
|
+
break;
|
|
950
|
+
case "H":
|
|
951
|
+
[, a] = x;
|
|
952
|
+
break;
|
|
953
|
+
case "V":
|
|
954
|
+
[, m] = x;
|
|
955
|
+
break;
|
|
956
|
+
default:
|
|
957
|
+
[a, m] = x.slice(-2).map(Number), l === "M" && (f = a, y = m);
|
|
958
|
+
}
|
|
959
|
+
s.x = a, s.y = m;
|
|
960
|
+
}
|
|
961
|
+
const g = ot(n, t), h = ot(bt(n), t);
|
|
962
|
+
return g.map((u, x) => x ? u.join("").length < h[x].join("").length ? u : h[x] : u);
|
|
963
|
+
}, Te = (e) => {
|
|
964
|
+
const t = e.slice(1).map(
|
|
965
|
+
(n, r, s) => r ? [...s[r - 1].slice(-2), ...n.slice(1)] : [...e[0].slice(1), ...n.slice(1)]
|
|
966
|
+
).map((n) => n.map((r, s) => n[n.length - s - 2 * (1 - s % 2)])).reverse();
|
|
967
|
+
return [["M", ...t[0].slice(0, 2)], ...t.map((n) => ["C", ...n.slice(2)])];
|
|
968
|
+
}, st = (e) => {
|
|
969
|
+
const t = X(e), n = t.slice(-1)[0][0] === "Z", r = O(t).map((s, i) => {
|
|
970
|
+
const [o, l] = s.slice(-2).map(Number);
|
|
971
|
+
return {
|
|
972
|
+
seg: t[i],
|
|
973
|
+
n: s,
|
|
974
|
+
c: t[i][0],
|
|
975
|
+
x: o,
|
|
976
|
+
y: l
|
|
977
|
+
};
|
|
978
|
+
}).map((s, i, o) => {
|
|
979
|
+
const l = s.seg, c = s.n, a = i && o[i - 1], m = o[i + 1], f = s.c, y = o.length, g = i ? o[i - 1].x : o[y - 1].x, h = i ? o[i - 1].y : o[y - 1].y;
|
|
980
|
+
let u = [];
|
|
981
|
+
switch (f) {
|
|
982
|
+
case "M":
|
|
983
|
+
u = n ? ["Z"] : [f, g, h];
|
|
984
|
+
break;
|
|
985
|
+
case "A":
|
|
986
|
+
u = [f, ...l.slice(1, -3), l[5] === 1 ? 0 : 1, g, h];
|
|
987
|
+
break;
|
|
988
|
+
case "C":
|
|
989
|
+
m && m.c === "S" ? u = ["S", l[1], l[2], g, h] : u = [f, l[3], l[4], l[1], l[2], g, h];
|
|
990
|
+
break;
|
|
991
|
+
case "S":
|
|
992
|
+
a && "CS".includes(a.c) && (!m || m.c !== "S") ? u = ["C", c[3], c[4], c[1], c[2], g, h] : u = [f, c[1], c[2], g, h];
|
|
993
|
+
break;
|
|
994
|
+
case "Q":
|
|
995
|
+
m && m.c === "T" ? u = ["T", g, h] : u = [f, ...l.slice(1, -2), g, h];
|
|
996
|
+
break;
|
|
997
|
+
case "T":
|
|
998
|
+
a && "QT".includes(a.c) && (!m || m.c !== "T") ? u = ["Q", c[1], c[2], g, h] : u = [f, g, h];
|
|
999
|
+
break;
|
|
1000
|
+
case "Z":
|
|
1001
|
+
u = ["M", g, h];
|
|
1002
|
+
break;
|
|
1003
|
+
case "H":
|
|
1004
|
+
u = [f, g];
|
|
1005
|
+
break;
|
|
1006
|
+
case "V":
|
|
1007
|
+
u = [f, h];
|
|
1008
|
+
break;
|
|
1009
|
+
default:
|
|
1010
|
+
u = [f, ...l.slice(1, -2), g, h];
|
|
1011
|
+
}
|
|
1012
|
+
return u;
|
|
1013
|
+
});
|
|
1014
|
+
return n ? r.reverse() : [r[0], ...r.slice(1).reverse()];
|
|
1015
|
+
}, Le = (e) => {
|
|
1016
|
+
let t = new N();
|
|
1017
|
+
const { origin: n } = e, [r, s] = n, { translate: i } = e, { rotate: o } = e, { skew: l } = e, { scale: c } = e;
|
|
1018
|
+
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, s), 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((a) => !Number.isNaN(+a)) && 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((a) => !Number.isNaN(+a)) && c.some((a) => a !== 1) ? t = t.scale(...c) : typeof c == "number" && !Number.isNaN(c) && (t = t.scale(c)), t = t.translate(-r, -s)), t;
|
|
1019
|
+
}, ke = (e, t) => {
|
|
1020
|
+
let n = N.Translate(...t.slice(0, -1));
|
|
1021
|
+
return [, , , n.m44] = t, n = e.multiply(n), [n.m41, n.m42, n.m43, n.m44];
|
|
1022
|
+
}, qt = (e, t, n) => {
|
|
1023
|
+
const [r, s, i] = n, [o, l, c] = ke(e, [...t, 0, 1]), a = o - r, m = l - s, f = c - i;
|
|
1024
|
+
return [
|
|
1025
|
+
a * (Math.abs(i) / Math.abs(f) || 1) + r,
|
|
1026
|
+
m * (Math.abs(i) / Math.abs(f) || 1) + s
|
|
1027
|
+
];
|
|
1028
|
+
}, $t = (e, t) => {
|
|
1029
|
+
let n = 0, r = 0, s, i, o, l, c, a;
|
|
1030
|
+
const m = X(e), f = t && Object.keys(t);
|
|
1031
|
+
if (!t || f && !f.length)
|
|
1032
|
+
return [...m];
|
|
1033
|
+
const y = O(m);
|
|
1034
|
+
if (!t.origin) {
|
|
1035
|
+
const { origin: M } = at;
|
|
1036
|
+
Object.assign(t, { origin: M });
|
|
1037
|
+
}
|
|
1038
|
+
const g = Le(t), { origin: h } = t, u = { ...mt };
|
|
1039
|
+
let x = [], p = 0, d = "", A = [];
|
|
1040
|
+
const b = [];
|
|
1041
|
+
if (!g.isIdentity) {
|
|
1042
|
+
for (s = 0, o = m.length; s < o; s += 1) {
|
|
1043
|
+
x = m[s], m[s] && ([d] = x), b[s] = d, d === "A" && (x = rt(y[s], u), m[s] = rt(y[s], u), dt(m, b, s), y[s] = rt(y[s], u), dt(y, b, s), o = Math.max(m.length, y.length)), x = y[s], p = x.length, u.x1 = +x[p - 2], u.y1 = +x[p - 1], u.x2 = +x[p - 4] || u.x1, u.y2 = +x[p - 3] || u.y1;
|
|
1044
|
+
const M = {
|
|
1045
|
+
s: m[s],
|
|
1046
|
+
c: m[s][0],
|
|
1047
|
+
x: u.x1,
|
|
1048
|
+
y: u.y1
|
|
1049
|
+
};
|
|
1050
|
+
A = [...A, M];
|
|
1051
|
+
}
|
|
1052
|
+
return A.map((M) => {
|
|
1053
|
+
if (d = M.c, x = M.s, d === "L" || d === "H" || d === "V")
|
|
1054
|
+
return [c, a] = qt(g, [M.x, M.y], h), n !== c && r !== a ? x = ["L", c, a] : r === a ? x = ["H", c] : n === c && (x = ["V", a]), n = c, r = a, x;
|
|
1055
|
+
for (i = 1, l = x.length; i < l; i += 2)
|
|
1056
|
+
[n, r] = qt(g, [+x[i], +x[i + 1]], h), x[i] = n, x[i + 1] = r;
|
|
1057
|
+
return x;
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
return [...m];
|
|
1061
|
+
}, qe = (e) => {
|
|
1062
|
+
const n = e.slice(0, 2), r = e.slice(2, 4), s = e.slice(4, 6), i = e.slice(6, 8), o = V(n, r, 0.5), l = V(r, s, 0.5), c = V(s, i, 0.5), a = V(o, l, 0.5), m = V(l, c, 0.5), f = V(a, m, 0.5);
|
|
1063
|
+
return [
|
|
1064
|
+
["C", ...o, ...a, ...f],
|
|
1065
|
+
["C", ...m, ...c, ...i]
|
|
1066
|
+
];
|
|
1067
|
+
};
|
|
1068
|
+
class $e {
|
|
1069
|
+
static CSSMatrix = N;
|
|
1070
|
+
static getPathBBox = vt;
|
|
1071
|
+
static getPathArea = Bt;
|
|
1072
|
+
static getTotalLength = Z;
|
|
1073
|
+
static getDrawDirection = xe;
|
|
1074
|
+
static getPointAtLength = J;
|
|
1075
|
+
static pathLengthFactory = ht;
|
|
1076
|
+
static getPropertiesAtLength = Nt;
|
|
1077
|
+
static getPropertiesAtPoint = ut;
|
|
1078
|
+
static polygonLength = se;
|
|
1079
|
+
static polygonArea = ne;
|
|
1080
|
+
static getClosestPoint = pe;
|
|
1081
|
+
static getSegmentOfPoint = de;
|
|
1082
|
+
static getSegmentAtLength = be;
|
|
1083
|
+
static isPointInStroke = Me;
|
|
1084
|
+
static isValidPath = Gt;
|
|
1085
|
+
static isPathArray = ct;
|
|
1086
|
+
static isAbsoluteArray = Mt;
|
|
1087
|
+
static isRelativeArray = Jt;
|
|
1088
|
+
static isCurveArray = Ht;
|
|
1089
|
+
static isNormalizedArray = At;
|
|
1090
|
+
static shapeToPath = ve;
|
|
1091
|
+
static parsePathString = R;
|
|
1092
|
+
static roundPath = ot;
|
|
1093
|
+
static splitPath = Lt;
|
|
1094
|
+
static splitCubic = qe;
|
|
1095
|
+
static optimizePath = kt;
|
|
1096
|
+
static reverseCurve = Te;
|
|
1097
|
+
static reversePath = st;
|
|
1098
|
+
static normalizePath = O;
|
|
1099
|
+
static transformPath = $t;
|
|
1100
|
+
static pathToAbsolute = X;
|
|
1101
|
+
static pathToRelative = bt;
|
|
1102
|
+
static pathToCurve = it;
|
|
1103
|
+
static pathToString = j;
|
|
1104
|
+
constructor(t, n) {
|
|
1105
|
+
const r = n || {}, s = typeof t > "u";
|
|
1106
|
+
if (s || !t.length)
|
|
1107
|
+
throw TypeError(`${q}: "pathValue" is ${s ? "undefined" : "empty"}`);
|
|
1108
|
+
const i = R(t);
|
|
1109
|
+
this.segments = i;
|
|
1110
|
+
const { width: o, height: l, cx: c, cy: a, cz: m } = this.getBBox(), { round: f, origin: y } = r;
|
|
1111
|
+
let g;
|
|
1112
|
+
if (f === "auto") {
|
|
1113
|
+
const u = `${Math.floor(Math.max(o, l))}`.length;
|
|
1114
|
+
g = u >= 4 ? 0 : 4 - u;
|
|
1115
|
+
} else
|
|
1116
|
+
Number.isInteger(f) || f === "off" ? g = f : g = at.round;
|
|
1117
|
+
let h;
|
|
1118
|
+
if (Array.isArray(y) && y.length >= 2) {
|
|
1119
|
+
const [u, x, p] = y.map(Number);
|
|
1120
|
+
h = [
|
|
1121
|
+
Number.isNaN(u) ? c : u,
|
|
1122
|
+
Number.isNaN(x) ? a : x,
|
|
1123
|
+
Number.isNaN(p) ? m : p
|
|
1124
|
+
];
|
|
1125
|
+
} else
|
|
1126
|
+
h = [c, a, m];
|
|
1127
|
+
return this.round = g, this.origin = h, this;
|
|
1128
|
+
}
|
|
1129
|
+
getBBox() {
|
|
1130
|
+
return vt(this.segments);
|
|
1131
|
+
}
|
|
1132
|
+
getTotalLength() {
|
|
1133
|
+
return Z(this.segments);
|
|
1134
|
+
}
|
|
1135
|
+
getPointAtLength(t) {
|
|
1136
|
+
return J(this.segments, t);
|
|
1137
|
+
}
|
|
1138
|
+
toAbsolute() {
|
|
1139
|
+
const { segments: t } = this;
|
|
1140
|
+
return this.segments = X(t), this;
|
|
1141
|
+
}
|
|
1142
|
+
toRelative() {
|
|
1143
|
+
const { segments: t } = this;
|
|
1144
|
+
return this.segments = bt(t), this;
|
|
1145
|
+
}
|
|
1146
|
+
toCurve() {
|
|
1147
|
+
const { segments: t } = this;
|
|
1148
|
+
return this.segments = it(t), this;
|
|
1149
|
+
}
|
|
1150
|
+
reverse(t) {
|
|
1151
|
+
this.toAbsolute();
|
|
1152
|
+
const { segments: n } = this, r = Lt(n), s = r.length > 1 ? r : !1, i = s ? [...s].map((l, c) => t ? c ? st(l) : [...l] : st(l)) : [...n];
|
|
1153
|
+
let o = [];
|
|
1154
|
+
return s ? o = i.flat(1) : o = t ? n : st(n), this.segments = [...o], this;
|
|
1155
|
+
}
|
|
1156
|
+
normalize() {
|
|
1157
|
+
const { segments: t } = this;
|
|
1158
|
+
return this.segments = O(t), this;
|
|
1159
|
+
}
|
|
1160
|
+
optimize() {
|
|
1161
|
+
const { segments: t } = this;
|
|
1162
|
+
return this.segments = kt(t, this.round), this;
|
|
1163
|
+
}
|
|
1164
|
+
transform(t) {
|
|
1165
|
+
if (!t || typeof t != "object" || typeof t == "object" && !["translate", "rotate", "skew", "scale"].some((c) => c in t))
|
|
1166
|
+
return this;
|
|
1167
|
+
const {
|
|
1168
|
+
segments: n,
|
|
1169
|
+
origin: [r, s, i]
|
|
1170
|
+
} = this, o = {};
|
|
1171
|
+
for (const [c, a] of Object.entries(t))
|
|
1172
|
+
c === "skew" && Array.isArray(a) || (c === "rotate" || c === "translate" || c === "origin" || c === "scale") && Array.isArray(a) ? o[c] = a.map(Number) : c !== "origin" && typeof Number(a) == "number" && (o[c] = Number(a));
|
|
1173
|
+
const { origin: l } = o;
|
|
1174
|
+
if (Array.isArray(l) && l.length >= 2) {
|
|
1175
|
+
const [c, a, m] = l.map(Number);
|
|
1176
|
+
o.origin = [Number.isNaN(c) ? r : c, Number.isNaN(a) ? s : a, m || i];
|
|
1177
|
+
} else
|
|
1178
|
+
o.origin = [r, s, i];
|
|
1179
|
+
return this.segments = $t(n, o), this;
|
|
1180
|
+
}
|
|
1181
|
+
flipX() {
|
|
1182
|
+
return this.transform({ rotate: [0, 180, 0] }), this;
|
|
1183
|
+
}
|
|
1184
|
+
flipY() {
|
|
1185
|
+
return this.transform({ rotate: [180, 0, 0] }), this;
|
|
1186
|
+
}
|
|
1187
|
+
toString() {
|
|
1188
|
+
return j(this.segments, this.round);
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
export {
|
|
1192
|
+
$e as default
|
|
1193
|
+
};
|
|
1194
|
+
//# sourceMappingURL=svg-path-commander.mjs.map
|