svg-path-commander 2.0.4 → 2.0.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/cypress/e2e/svg-path-commander.spec.ts +49 -6
- package/dist/svg-path-commander.cjs +1 -1
- package/dist/svg-path-commander.cjs.map +1 -1
- package/dist/svg-path-commander.d.ts +6 -5
- package/dist/svg-path-commander.js +1 -1
- package/dist/svg-path-commander.js.map +1 -1
- package/dist/svg-path-commander.mjs +351 -341
- package/dist/svg-path-commander.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/interface.ts +5 -5
- package/src/util/isPathArray.ts +7 -2
- package/src/util/isValidPath.ts +1 -1
- package/src/util/shapeParams.ts +16 -0
- package/src/util/shapeToPath.ts +19 -147
- package/src/util/shapeToPathArray.ts +179 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var N = (e, t, n) => (
|
|
4
|
-
const
|
|
1
|
+
var Gt = Object.defineProperty;
|
|
2
|
+
var te = (e, t, n) => t in e ? Gt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var N = (e, t, n) => (te(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
4
|
+
const mt = {
|
|
5
5
|
origin: [0, 0, 0],
|
|
6
6
|
round: 4
|
|
7
|
-
},
|
|
7
|
+
}, k = "SVGPathCommander Error", U = {
|
|
8
8
|
a: 7,
|
|
9
9
|
c: 6,
|
|
10
10
|
h: 1,
|
|
@@ -16,12 +16,12 @@ const at = {
|
|
|
16
16
|
t: 2,
|
|
17
17
|
v: 1,
|
|
18
18
|
z: 0
|
|
19
|
-
},
|
|
19
|
+
}, Tt = (e) => {
|
|
20
20
|
let t = e.pathValue[e.segmentStart], n = t.toLowerCase();
|
|
21
21
|
const { data: r } = e;
|
|
22
|
-
for (; r.length >=
|
|
22
|
+
for (; r.length >= U[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, U[n])]), !!U[n]); )
|
|
23
23
|
;
|
|
24
|
-
},
|
|
24
|
+
}, ee = (e) => {
|
|
25
25
|
const { index: t, pathValue: n } = e, r = n.charCodeAt(t);
|
|
26
26
|
if (r === 48) {
|
|
27
27
|
e.param = 0, e.index += 1;
|
|
@@ -31,21 +31,21 @@ const at = {
|
|
|
31
31
|
e.param = 1, e.index += 1;
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
|
-
e.err = `${
|
|
35
|
-
}, D = (e) => e >= 48 && e <= 57,
|
|
34
|
+
e.err = `${k}: invalid Arc flag "${n[t]}", expecting 0 or 1 at index ${t}`;
|
|
35
|
+
}, D = (e) => e >= 48 && e <= 57, R = "Invalid path value", ne = (e) => {
|
|
36
36
|
const { max: t, pathValue: n, index: r } = e;
|
|
37
37
|
let s = r, i = !1, o = !1, a = !1, l = !1, c;
|
|
38
38
|
if (s >= t) {
|
|
39
|
-
e.err = `${
|
|
39
|
+
e.err = `${k}: ${R} at index ${s}, "pathValue" is missing param`;
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
if (c = n.charCodeAt(s), (c === 43 || c === 45) && (s += 1, c = n.charCodeAt(s)), !D(c) && c !== 46) {
|
|
43
|
-
e.err = `${
|
|
43
|
+
e.err = `${k}: ${R} at index ${s}, "${n[s]}" is not a number`;
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
if (c !== 46) {
|
|
47
47
|
if (i = c === 48, s += 1, c = n.charCodeAt(s), i && s < t && c && D(c)) {
|
|
48
|
-
e.err = `${
|
|
48
|
+
e.err = `${k}: ${R} at index ${r}, "${n[r]}" illegal number`;
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
51
|
for (; s < t && D(n.charCodeAt(s)); )
|
|
@@ -59,19 +59,19 @@ const at = {
|
|
|
59
59
|
}
|
|
60
60
|
if (c === 101 || c === 69) {
|
|
61
61
|
if (l && !o && !a) {
|
|
62
|
-
e.err = `${
|
|
62
|
+
e.err = `${k}: ${R} at index ${s}, "${n[s]}" invalid float exponent`;
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
65
|
if (s += 1, c = n.charCodeAt(s), (c === 43 || c === 45) && (s += 1), s < t && D(n.charCodeAt(s)))
|
|
66
66
|
for (; s < t && D(n.charCodeAt(s)); )
|
|
67
67
|
s += 1;
|
|
68
68
|
else {
|
|
69
|
-
e.err = `${
|
|
69
|
+
e.err = `${k}: ${R} at index ${s}, "${n[s]}" invalid integer exponent`;
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
e.index = s, e.param = +e.pathValue.slice(r, s);
|
|
74
|
-
},
|
|
74
|
+
}, se = (e) => [
|
|
75
75
|
// Special spaces
|
|
76
76
|
5760,
|
|
77
77
|
6158,
|
|
@@ -101,11 +101,11 @@ const at = {
|
|
|
101
101
|
11,
|
|
102
102
|
12,
|
|
103
103
|
160
|
|
104
|
-
].includes(e),
|
|
104
|
+
].includes(e), V = (e) => {
|
|
105
105
|
const { pathValue: t, max: n } = e;
|
|
106
|
-
for (; e.index < n &&
|
|
106
|
+
for (; e.index < n && se(t.charCodeAt(e.index)); )
|
|
107
107
|
e.index += 1;
|
|
108
|
-
},
|
|
108
|
+
}, re = (e) => {
|
|
109
109
|
switch (e | 32) {
|
|
110
110
|
case 109:
|
|
111
111
|
case 122:
|
|
@@ -121,53 +121,53 @@ const at = {
|
|
|
121
121
|
default:
|
|
122
122
|
return !1;
|
|
123
123
|
}
|
|
124
|
-
},
|
|
125
|
-
const { max: t, pathValue: n, index: r } = e, s = n.charCodeAt(r), i =
|
|
126
|
-
if (e.segmentStart = r, !
|
|
127
|
-
e.err = `${
|
|
124
|
+
}, ie = (e) => D(e) || e === 43 || e === 45 || e === 46, oe = (e) => (e | 32) === 97, jt = (e) => {
|
|
125
|
+
const { max: t, pathValue: n, index: r } = e, s = n.charCodeAt(r), i = U[n[r].toLowerCase()];
|
|
126
|
+
if (e.segmentStart = r, !re(s)) {
|
|
127
|
+
e.err = `${k}: ${R} "${n[r]}" is not a path command`;
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
130
|
-
if (e.index += 1,
|
|
131
|
-
|
|
130
|
+
if (e.index += 1, V(e), e.data = [], !i) {
|
|
131
|
+
Tt(e);
|
|
132
132
|
return;
|
|
133
133
|
}
|
|
134
134
|
for (; ; ) {
|
|
135
135
|
for (let o = i; o > 0; o -= 1) {
|
|
136
|
-
if (
|
|
136
|
+
if (oe(s) && (o === 3 || o === 4) ? ee(e) : ne(e), e.err.length)
|
|
137
137
|
return;
|
|
138
|
-
e.data.push(e.param),
|
|
138
|
+
e.data.push(e.param), V(e), e.index < t && n.charCodeAt(e.index) === 44 && (e.index += 1, V(e));
|
|
139
139
|
}
|
|
140
|
-
if (e.index >= e.max || !
|
|
140
|
+
if (e.index >= e.max || !ie(n.charCodeAt(e.index)))
|
|
141
141
|
break;
|
|
142
142
|
}
|
|
143
|
-
|
|
143
|
+
Tt(e);
|
|
144
144
|
};
|
|
145
|
-
class
|
|
145
|
+
class zt {
|
|
146
146
|
constructor(t) {
|
|
147
147
|
this.segments = [], this.pathValue = t, this.max = t.length, this.index = 0, this.param = 0, this.segmentStart = 0, this.data = [], this.err = "";
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
-
const
|
|
150
|
+
const _ = (e) => Array.isArray(e) && e.every((t) => {
|
|
151
151
|
const n = t[0].toLowerCase();
|
|
152
|
-
return
|
|
153
|
-
}),
|
|
154
|
-
if (
|
|
152
|
+
return U[n] === t.length - 1 && "achlmqstvz".includes(n) && t.slice(1).every(Number.isFinite);
|
|
153
|
+
}) && e.length > 0, Z = (e) => {
|
|
154
|
+
if (_(e))
|
|
155
155
|
return [...e];
|
|
156
|
-
const t = new
|
|
157
|
-
for (
|
|
158
|
-
|
|
156
|
+
const t = new zt(e);
|
|
157
|
+
for (V(t); t.index < t.max && !t.err.length; )
|
|
158
|
+
jt(t);
|
|
159
159
|
if (t.err && t.err.length)
|
|
160
160
|
throw TypeError(t.err);
|
|
161
161
|
return t.segments;
|
|
162
|
-
},
|
|
162
|
+
}, ce = (e) => {
|
|
163
163
|
const t = e.length;
|
|
164
164
|
let n = -1, r, s = e[t - 1], i = 0;
|
|
165
165
|
for (; ++n < t; )
|
|
166
166
|
r = s, s = e[n], i += r[1] * s[0] - r[0] * s[1];
|
|
167
167
|
return i / 2;
|
|
168
|
-
},
|
|
169
|
-
var
|
|
170
|
-
const
|
|
168
|
+
}, W = (e, t) => Math.sqrt((e[0] - t[0]) * (e[0] - t[0]) + (e[1] - t[1]) * (e[1] - t[1])), le = (e) => e.reduce((t, n, r) => r ? t + W(e[r - 1], n) : 0, 0);
|
|
169
|
+
var ae = Object.defineProperty, me = (e, t, n) => t in e ? ae(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, C = (e, t, n) => (me(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
170
|
+
const he = {
|
|
171
171
|
a: 1,
|
|
172
172
|
b: 0,
|
|
173
173
|
c: 0,
|
|
@@ -192,13 +192,13 @@ const me = {
|
|
|
192
192
|
m44: 1,
|
|
193
193
|
is2D: !0,
|
|
194
194
|
isIdentity: !0
|
|
195
|
-
},
|
|
195
|
+
}, It = (e) => (e instanceof Float64Array || e instanceof Float32Array || Array.isArray(e) && e.every((t) => typeof t == "number")) && [6, 16].some((t) => e.length === t), Dt = (e) => e instanceof DOMMatrix || e instanceof v || typeof e == "object" && Object.keys(he).every((t) => e && t in e), G = (e) => {
|
|
196
196
|
const t = new v(), n = Array.from(e);
|
|
197
|
-
if (!
|
|
197
|
+
if (!It(n))
|
|
198
198
|
throw TypeError(`CSSMatrix: "${n.join(",")}" must be an array with 6/16 numbers.`);
|
|
199
199
|
if (n.length === 16) {
|
|
200
|
-
const [r, s, i, o, a, l, c, m,
|
|
201
|
-
t.m11 = r, t.a = r, t.m21 = a, t.c = a, t.m31 =
|
|
200
|
+
const [r, s, i, o, a, l, c, m, u, y, g, f, h, x, p, b] = n;
|
|
201
|
+
t.m11 = r, t.a = r, t.m21 = a, t.c = a, t.m31 = u, t.m41 = h, t.e = h, t.m12 = s, t.b = s, t.m22 = l, t.d = l, t.m32 = y, t.m42 = x, t.f = x, t.m13 = i, t.m23 = c, t.m33 = g, t.m43 = p, t.m14 = o, t.m24 = m, t.m34 = f, t.m44 = b;
|
|
202
202
|
} else if (n.length === 6) {
|
|
203
203
|
const [r, s, i, o, a, l] = n;
|
|
204
204
|
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 = a, t.e = a, t.m42 = l, t.f = l;
|
|
@@ -225,7 +225,7 @@ const me = {
|
|
|
225
225
|
e.m44
|
|
226
226
|
]);
|
|
227
227
|
throw TypeError(`CSSMatrix: "${JSON.stringify(e)}" is not a DOMMatrix / CSSMatrix / JSON compatible object.`);
|
|
228
|
-
},
|
|
228
|
+
}, Ft = (e) => {
|
|
229
229
|
if (typeof e != "string")
|
|
230
230
|
throw TypeError(`CSSMatrix: "${JSON.stringify(e)}" is not a string.`);
|
|
231
231
|
const t = String(e).replace(/\s/g, "");
|
|
@@ -235,33 +235,33 @@ const me = {
|
|
|
235
235
|
const [i, o] = s.split("(");
|
|
236
236
|
if (!o)
|
|
237
237
|
throw TypeError(r);
|
|
238
|
-
const a = o.split(",").map((
|
|
239
|
-
if (i === "perspective" && l && [c, m].every((
|
|
238
|
+
const a = o.split(",").map((f) => f.includes("rad") ? parseFloat(f) * (180 / Math.PI) : parseFloat(f)), [l, c, m, u] = a, y = [l, c, m], g = [l, c, m, u];
|
|
239
|
+
if (i === "perspective" && l && [c, m].every((f) => f === void 0))
|
|
240
240
|
n.m34 = -1 / l;
|
|
241
|
-
else if (i.includes("matrix") && [6, 16].includes(a.length) && a.every((
|
|
242
|
-
const
|
|
243
|
-
n = n.multiply(G(
|
|
244
|
-
} else if (i === "translate3d" && y.every((
|
|
241
|
+
else if (i.includes("matrix") && [6, 16].includes(a.length) && a.every((f) => !Number.isNaN(+f))) {
|
|
242
|
+
const f = a.map((h) => Math.abs(h) < 1e-6 ? 0 : h);
|
|
243
|
+
n = n.multiply(G(f));
|
|
244
|
+
} else if (i === "translate3d" && y.every((f) => !Number.isNaN(+f)))
|
|
245
245
|
n = n.translate(l, c, m);
|
|
246
246
|
else if (i === "translate" && l && m === void 0)
|
|
247
247
|
n = n.translate(l, c || 0, 0);
|
|
248
|
-
else if (i === "rotate3d" && g.every((
|
|
249
|
-
n = n.rotateAxisAngle(l, c, m,
|
|
250
|
-
else if (i === "rotate" && l && [c, m].every((
|
|
248
|
+
else if (i === "rotate3d" && g.every((f) => !Number.isNaN(+f)) && u)
|
|
249
|
+
n = n.rotateAxisAngle(l, c, m, u);
|
|
250
|
+
else if (i === "rotate" && l && [c, m].every((f) => f === void 0))
|
|
251
251
|
n = n.rotate(0, 0, l);
|
|
252
|
-
else if (i === "scale3d" && y.every((
|
|
252
|
+
else if (i === "scale3d" && y.every((f) => !Number.isNaN(+f)) && y.some((f) => f !== 1))
|
|
253
253
|
n = n.scale(l, c, m);
|
|
254
254
|
else if (i === "scale" && !Number.isNaN(l) && l !== 1 && m === void 0) {
|
|
255
|
-
const
|
|
256
|
-
n = n.scale(l,
|
|
255
|
+
const f = Number.isNaN(+c) ? l : c;
|
|
256
|
+
n = n.scale(l, f, 1);
|
|
257
257
|
} else if (i === "skew" && (l || !Number.isNaN(l) && c) && m === void 0)
|
|
258
258
|
n = n.skew(l, c || 0);
|
|
259
|
-
else if (["translate", "rotate", "scale", "skew"].some((
|
|
259
|
+
else if (["translate", "rotate", "scale", "skew"].some((f) => i.includes(f)) && /[XYZ]/.test(i) && l && [c, m].every((f) => f === void 0))
|
|
260
260
|
if (i === "skewX" || i === "skewY")
|
|
261
261
|
n = n[i](l);
|
|
262
262
|
else {
|
|
263
|
-
const
|
|
264
|
-
n = n[
|
|
263
|
+
const f = i.replace(/[XYZ]/, ""), h = i.replace(f, ""), x = ["X", "Y", "Z"].indexOf(h), p = f === "scale" ? 1 : 0, b = [x === 0 ? l : p, x === 1 ? l : p, x === 2 ? l : p];
|
|
264
|
+
n = n[f](...b);
|
|
265
265
|
}
|
|
266
266
|
else
|
|
267
267
|
throw TypeError(r);
|
|
@@ -283,28 +283,28 @@ const me = {
|
|
|
283
283
|
e.m42,
|
|
284
284
|
e.m43,
|
|
285
285
|
e.m44
|
|
286
|
-
],
|
|
286
|
+
], Rt = (e, t, n) => {
|
|
287
287
|
const r = new v();
|
|
288
288
|
return r.m41 = e, r.e = e, r.m42 = t, r.f = t, r.m43 = n, r;
|
|
289
|
-
},
|
|
290
|
-
const r = new v(), s = Math.PI / 180, i = e * s, o = t * s, a = n * s, l = Math.cos(i), c = -Math.sin(i), m = Math.cos(o),
|
|
291
|
-
r.m11 =
|
|
292
|
-
const x = c *
|
|
289
|
+
}, Xt = (e, t, n) => {
|
|
290
|
+
const r = new v(), s = Math.PI / 180, i = e * s, o = t * s, a = n * s, l = Math.cos(i), c = -Math.sin(i), m = Math.cos(o), u = -Math.sin(o), y = Math.cos(a), g = -Math.sin(a), f = m * y, h = -m * g;
|
|
291
|
+
r.m11 = f, r.a = f, r.m12 = h, r.b = h, r.m13 = u;
|
|
292
|
+
const x = c * u * y + l * g;
|
|
293
293
|
r.m21 = x, r.c = x;
|
|
294
|
-
const p = l * y - c *
|
|
295
|
-
return r.m22 = p, r.d = p, r.m23 = -c * m, r.m31 = c * g - l *
|
|
294
|
+
const p = l * y - c * u * g;
|
|
295
|
+
return r.m22 = p, r.d = p, r.m23 = -c * m, r.m31 = c * g - l * u * y, r.m32 = c * y + l * u * g, r.m33 = l * m, r;
|
|
296
296
|
}, Qt = (e, t, n, r) => {
|
|
297
297
|
const s = new v(), i = Math.sqrt(e * e + t * t + n * n);
|
|
298
298
|
if (i === 0)
|
|
299
299
|
return s;
|
|
300
|
-
const o = e / i, a = t / i, l = n / i, c = r * (Math.PI / 360), m = Math.sin(c),
|
|
300
|
+
const o = e / i, a = t / i, l = n / i, c = r * (Math.PI / 360), m = Math.sin(c), u = Math.cos(c), y = m * m, g = o * o, f = a * a, h = l * l, x = 1 - 2 * (f + h) * y;
|
|
301
301
|
s.m11 = x, s.a = x;
|
|
302
|
-
const p = 2 * (o * a * y + l * m *
|
|
303
|
-
s.m12 = p, s.b = p, s.m13 = 2 * (o * l * y - a * m *
|
|
304
|
-
const b = 2 * (a * o * y - l * m *
|
|
302
|
+
const p = 2 * (o * a * y + l * m * u);
|
|
303
|
+
s.m12 = p, s.b = p, s.m13 = 2 * (o * l * y - a * m * u);
|
|
304
|
+
const b = 2 * (a * o * y - l * m * u);
|
|
305
305
|
s.m21 = b, s.c = b;
|
|
306
|
-
const A = 1 - 2 * (
|
|
307
|
-
return s.m22 = A, s.d = A, s.m23 = 2 * (a * l * y + o * m *
|
|
306
|
+
const A = 1 - 2 * (h + g) * y;
|
|
307
|
+
return s.m22 = A, s.d = A, s.m23 = 2 * (a * l * y + o * m * u), s.m31 = 2 * (l * o * y + a * m * u), s.m32 = 2 * (l * a * y - o * m * u), s.m33 = 1 - 2 * (g + f) * y, s;
|
|
308
308
|
}, Ht = (e, t, n) => {
|
|
309
309
|
const r = new v();
|
|
310
310
|
return r.m11 = e, r.a = e, r.m22 = t, r.d = t, r.m33 = n, r;
|
|
@@ -319,9 +319,9 @@ const me = {
|
|
|
319
319
|
n.m12 = s, n.b = s;
|
|
320
320
|
}
|
|
321
321
|
return n;
|
|
322
|
-
}, Yt = (e) => ht(e, 0), Bt = (e) => ht(0, e),
|
|
323
|
-
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, a = t.m21 * e.m12 + t.m22 * e.m22 + t.m23 * e.m32 + t.m24 * e.m42, l = t.m21 * e.m13 + t.m22 * e.m23 + t.m23 * e.m33 + t.m24 * e.m43, c = 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,
|
|
324
|
-
return G([n, r, s, i, o, a, l, c, m,
|
|
322
|
+
}, Yt = (e) => ht(e, 0), Bt = (e) => ht(0, e), O = (e, t) => {
|
|
323
|
+
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, a = t.m21 * e.m12 + t.m22 * e.m22 + t.m23 * e.m32 + t.m24 * e.m42, l = t.m21 * e.m13 + t.m22 * e.m23 + t.m23 * e.m33 + t.m24 * e.m43, c = 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, u = 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, f = t.m41 * e.m11 + t.m42 * e.m21 + t.m43 * e.m31 + t.m44 * e.m41, h = 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;
|
|
324
|
+
return G([n, r, s, i, o, a, l, c, m, u, y, g, f, h, x, p]);
|
|
325
325
|
};
|
|
326
326
|
class v {
|
|
327
327
|
/**
|
|
@@ -368,7 +368,7 @@ class v {
|
|
|
368
368
|
* @return the matrix instance
|
|
369
369
|
*/
|
|
370
370
|
setMatrixValue(t) {
|
|
371
|
-
return typeof t == "string" && t.length && t !== "none" ?
|
|
371
|
+
return typeof t == "string" && t.length && t !== "none" ? Ft(t) : Array.isArray(t) || t instanceof Float64Array || t instanceof Float32Array ? G(t) : typeof t == "object" ? Zt(t) : this;
|
|
372
372
|
}
|
|
373
373
|
/**
|
|
374
374
|
* Returns a *Float32Array* containing elements which comprise the matrix.
|
|
@@ -428,7 +428,7 @@ class v {
|
|
|
428
428
|
* @return The resulted matrix.
|
|
429
429
|
*/
|
|
430
430
|
multiply(t) {
|
|
431
|
-
return
|
|
431
|
+
return O(this, t);
|
|
432
432
|
}
|
|
433
433
|
/**
|
|
434
434
|
* The translate method returns a new matrix which is this matrix post
|
|
@@ -444,7 +444,7 @@ class v {
|
|
|
444
444
|
translate(t, n, r) {
|
|
445
445
|
const s = t;
|
|
446
446
|
let i = n, o = r;
|
|
447
|
-
return typeof i > "u" && (i = 0), typeof o > "u" && (o = 0),
|
|
447
|
+
return typeof i > "u" && (i = 0), typeof o > "u" && (o = 0), O(this, Rt(s, i, o));
|
|
448
448
|
}
|
|
449
449
|
/**
|
|
450
450
|
* The scale method returns a new matrix which is this matrix post multiplied by
|
|
@@ -460,7 +460,7 @@ class v {
|
|
|
460
460
|
scale(t, n, r) {
|
|
461
461
|
const s = t;
|
|
462
462
|
let i = n, o = r;
|
|
463
|
-
return typeof i > "u" && (i = t), typeof o > "u" && (o = 1),
|
|
463
|
+
return typeof i > "u" && (i = t), typeof o > "u" && (o = 1), O(this, Ht(s, i, o));
|
|
464
464
|
}
|
|
465
465
|
/**
|
|
466
466
|
* The rotate method returns a new matrix which is this matrix post multiplied
|
|
@@ -476,7 +476,7 @@ class v {
|
|
|
476
476
|
*/
|
|
477
477
|
rotate(t, n, r) {
|
|
478
478
|
let s = t, i = n || 0, o = r || 0;
|
|
479
|
-
return typeof t == "number" && typeof n > "u" && typeof r > "u" && (o = s, s = 0, i = 0),
|
|
479
|
+
return typeof t == "number" && typeof n > "u" && typeof r > "u" && (o = s, s = 0, i = 0), O(this, Xt(s, i, o));
|
|
480
480
|
}
|
|
481
481
|
/**
|
|
482
482
|
* The rotateAxisAngle method returns a new matrix which is this matrix post
|
|
@@ -493,7 +493,7 @@ class v {
|
|
|
493
493
|
rotateAxisAngle(t, n, r, s) {
|
|
494
494
|
if ([t, n, r, s].some((i) => Number.isNaN(+i)))
|
|
495
495
|
throw new TypeError("CSSMatrix: expecting 4 values");
|
|
496
|
-
return
|
|
496
|
+
return O(this, Qt(t, n, r, s));
|
|
497
497
|
}
|
|
498
498
|
/**
|
|
499
499
|
* Specifies a skew transformation along the `x-axis` by the given angle.
|
|
@@ -503,7 +503,7 @@ class v {
|
|
|
503
503
|
* @return The resulted matrix
|
|
504
504
|
*/
|
|
505
505
|
skewX(t) {
|
|
506
|
-
return
|
|
506
|
+
return O(this, Yt(t));
|
|
507
507
|
}
|
|
508
508
|
/**
|
|
509
509
|
* Specifies a skew transformation along the `y-axis` by the given angle.
|
|
@@ -513,7 +513,7 @@ class v {
|
|
|
513
513
|
* @return The resulted matrix
|
|
514
514
|
*/
|
|
515
515
|
skewY(t) {
|
|
516
|
-
return
|
|
516
|
+
return O(this, Bt(t));
|
|
517
517
|
}
|
|
518
518
|
/**
|
|
519
519
|
* Specifies a skew transformation along both the `x-axis` and `y-axis`.
|
|
@@ -524,7 +524,7 @@ class v {
|
|
|
524
524
|
* @return The resulted matrix
|
|
525
525
|
*/
|
|
526
526
|
skew(t, n) {
|
|
527
|
-
return
|
|
527
|
+
return O(this, ht(t, n));
|
|
528
528
|
}
|
|
529
529
|
/**
|
|
530
530
|
* Transforms a specified vector using the matrix, returning a new
|
|
@@ -547,12 +547,12 @@ class v {
|
|
|
547
547
|
};
|
|
548
548
|
}
|
|
549
549
|
}
|
|
550
|
-
C(v, "Translate",
|
|
551
|
-
const
|
|
552
|
-
e.every(([t]) => t === t.toUpperCase()),
|
|
553
|
-
if (
|
|
550
|
+
C(v, "Translate", Rt), C(v, "Rotate", Xt), C(v, "RotateAxisAngle", Qt), C(v, "Scale", Ht), C(v, "SkewX", Yt), C(v, "SkewY", Bt), C(v, "Skew", ht), C(v, "Multiply", O), C(v, "fromArray", G), C(v, "fromMatrix", Zt), C(v, "fromString", Ft), C(v, "toArray", bt), C(v, "isCompatibleArray", It), C(v, "isCompatibleObject", Dt);
|
|
551
|
+
const wt = (e) => _(e) && // `isPathArray` also checks if it's `Array`
|
|
552
|
+
e.every(([t]) => t === t.toUpperCase()), Q = (e) => {
|
|
553
|
+
if (wt(e))
|
|
554
554
|
return [...e];
|
|
555
|
-
const t =
|
|
555
|
+
const t = Z(e);
|
|
556
556
|
let n = 0, r = 0, s = 0, i = 0;
|
|
557
557
|
return t.map((o) => {
|
|
558
558
|
const a = o.slice(1).map(Number), [l] = o, c = l.toUpperCase();
|
|
@@ -576,14 +576,14 @@ e.every(([t]) => t === t.toUpperCase()), H = (e) => {
|
|
|
576
576
|
else if (c === "H")
|
|
577
577
|
m = [c, a[0] + n];
|
|
578
578
|
else {
|
|
579
|
-
const
|
|
580
|
-
m = [c, ...
|
|
579
|
+
const u = a.map((y, g) => y + (g % 2 ? r : n));
|
|
580
|
+
m = [c, ...u];
|
|
581
581
|
}
|
|
582
582
|
else
|
|
583
583
|
m = [c, ...a];
|
|
584
584
|
return c === "Z" ? (n = s, r = i) : c === "H" ? [, n] = m : c === "V" ? [, r] = m : ([n, r] = m.slice(-2), c === "M" && (s = n, i = r)), m;
|
|
585
585
|
});
|
|
586
|
-
},
|
|
586
|
+
}, ue = (e, t) => {
|
|
587
587
|
const [n] = e, { x1: r, y1: s, x2: i, y2: o } = t, a = e.slice(1).map(Number);
|
|
588
588
|
let l = e;
|
|
589
589
|
if ("TQ".includes(n) || (t.qx = null, t.qy = null), n === "H")
|
|
@@ -607,7 +607,7 @@ e.every(([t]) => t === t.toUpperCase()), H = (e) => {
|
|
|
607
607
|
t.qx = c, t.qy = m;
|
|
608
608
|
}
|
|
609
609
|
return l;
|
|
610
|
-
},
|
|
610
|
+
}, vt = (e) => wt(e) && e.every(([t]) => "ACLMQZ".includes(t)), ut = {
|
|
611
611
|
x1: 0,
|
|
612
612
|
y1: 0,
|
|
613
613
|
x2: 0,
|
|
@@ -616,21 +616,21 @@ e.every(([t]) => t === t.toUpperCase()), H = (e) => {
|
|
|
616
616
|
y: 0,
|
|
617
617
|
qx: null,
|
|
618
618
|
qy: null
|
|
619
|
-
},
|
|
620
|
-
if (
|
|
619
|
+
}, z = (e) => {
|
|
620
|
+
if (vt(e))
|
|
621
621
|
return [...e];
|
|
622
|
-
const t =
|
|
622
|
+
const t = Q(e), n = { ...ut }, r = t.length;
|
|
623
623
|
for (let s = 0; s < r; s += 1) {
|
|
624
|
-
t[s], t[s] =
|
|
624
|
+
t[s], t[s] = ue(t[s], n);
|
|
625
625
|
const i = t[s], o = i.length;
|
|
626
626
|
n.x1 = +i[o - 2], n.y1 = +i[o - 1], n.x2 = +i[o - 4] || n.x1, n.y2 = +i[o - 3] || n.y1;
|
|
627
627
|
}
|
|
628
628
|
return t;
|
|
629
|
-
},
|
|
629
|
+
}, j = (e, t, n) => {
|
|
630
630
|
const [r, s] = e, [i, o] = t;
|
|
631
631
|
return [r + (i - r) * n, s + (o - s) * n];
|
|
632
632
|
}, dt = (e, t, n, r, s) => {
|
|
633
|
-
const i =
|
|
633
|
+
const i = W([e, t], [n, r]);
|
|
634
634
|
let o = { x: 0, y: 0 };
|
|
635
635
|
if (typeof s == "number")
|
|
636
636
|
if (s <= 0)
|
|
@@ -638,7 +638,7 @@ e.every(([t]) => t === t.toUpperCase()), H = (e) => {
|
|
|
638
638
|
else if (s >= i)
|
|
639
639
|
o = { x: n, y: r };
|
|
640
640
|
else {
|
|
641
|
-
const [a, l] =
|
|
641
|
+
const [a, l] = j([e, t], [n, r], s / i);
|
|
642
642
|
o = { x: a, y: l };
|
|
643
643
|
}
|
|
644
644
|
return {
|
|
@@ -653,59 +653,59 @@ e.every(([t]) => t === t.toUpperCase()), H = (e) => {
|
|
|
653
653
|
y: Math.max(t, r)
|
|
654
654
|
}
|
|
655
655
|
};
|
|
656
|
-
},
|
|
656
|
+
}, Lt = (e, t) => {
|
|
657
657
|
const { x: n, y: r } = e, { x: s, y: i } = t, o = n * s + r * i, a = Math.sqrt((n ** 2 + r ** 2) * (s ** 2 + i ** 2));
|
|
658
658
|
return (n * i - r * s < 0 ? -1 : 1) * Math.acos(o / a);
|
|
659
|
-
},
|
|
660
|
-
const { abs: m, sin:
|
|
661
|
-
let
|
|
662
|
-
const b = (s % 360 + 360) % 360 * (
|
|
659
|
+
}, fe = (e, t, n, r, s, i, o, a, l, c) => {
|
|
660
|
+
const { abs: m, sin: u, cos: y, sqrt: g, PI: f } = Math;
|
|
661
|
+
let h = m(n), x = m(r);
|
|
662
|
+
const b = (s % 360 + 360) % 360 * (f / 180);
|
|
663
663
|
if (e === a && t === l)
|
|
664
664
|
return { x: e, y: t };
|
|
665
|
-
if (
|
|
665
|
+
if (h === 0 || x === 0)
|
|
666
666
|
return dt(e, t, a, l, c).point;
|
|
667
667
|
const A = (e - a) / 2, d = (t - l) / 2, M = {
|
|
668
|
-
x: y(b) * A +
|
|
669
|
-
y: -
|
|
670
|
-
}, T = M.x ** 2 /
|
|
671
|
-
T > 1 && (
|
|
672
|
-
const
|
|
673
|
-
let
|
|
674
|
-
|
|
675
|
-
const tt = (i !== o ? 1 : -1) * g(
|
|
676
|
-
x: tt * (
|
|
677
|
-
y: tt * (-(x * M.x) /
|
|
668
|
+
x: y(b) * A + u(b) * d,
|
|
669
|
+
y: -u(b) * A + y(b) * d
|
|
670
|
+
}, T = M.x ** 2 / h ** 2 + M.y ** 2 / x ** 2;
|
|
671
|
+
T > 1 && (h *= g(T), x *= g(T));
|
|
672
|
+
const E = h ** 2 * x ** 2 - h ** 2 * M.y ** 2 - x ** 2 * M.x ** 2, H = h ** 2 * M.y ** 2 + x ** 2 * M.x ** 2;
|
|
673
|
+
let F = E / H;
|
|
674
|
+
F = F < 0 ? 0 : F;
|
|
675
|
+
const tt = (i !== o ? 1 : -1) * g(F), S = {
|
|
676
|
+
x: tt * (h * M.y / x),
|
|
677
|
+
y: tt * (-(x * M.x) / h)
|
|
678
678
|
}, et = {
|
|
679
|
-
x: y(b) *
|
|
680
|
-
y:
|
|
681
|
-
},
|
|
682
|
-
x: (M.x -
|
|
683
|
-
y: (M.y -
|
|
684
|
-
}, nt =
|
|
685
|
-
x: (-M.x -
|
|
686
|
-
y: (-M.y -
|
|
679
|
+
x: y(b) * S.x - u(b) * S.y + (e + a) / 2,
|
|
680
|
+
y: u(b) * S.x + y(b) * S.y + (t + l) / 2
|
|
681
|
+
}, Y = {
|
|
682
|
+
x: (M.x - S.x) / h,
|
|
683
|
+
y: (M.y - S.y) / x
|
|
684
|
+
}, nt = Lt({ x: 1, y: 0 }, Y), st = {
|
|
685
|
+
x: (-M.x - S.x) / h,
|
|
686
|
+
y: (-M.y - S.y) / x
|
|
687
687
|
};
|
|
688
|
-
let
|
|
689
|
-
!o &&
|
|
690
|
-
const q = nt +
|
|
688
|
+
let $ = Lt(Y, st);
|
|
689
|
+
!o && $ > 0 ? $ -= 2 * f : o && $ < 0 && ($ += 2 * f), $ %= 2 * f;
|
|
690
|
+
const q = nt + $ * c, B = h * y(q), J = x * u(q);
|
|
691
691
|
return {
|
|
692
|
-
x: y(b) *
|
|
693
|
-
y:
|
|
692
|
+
x: y(b) * B - u(b) * J + et.x,
|
|
693
|
+
y: u(b) * B + y(b) * J + et.y
|
|
694
694
|
};
|
|
695
|
-
},
|
|
695
|
+
}, ye = (e, t, n, r, s, i, o, a, l, c) => {
|
|
696
696
|
const m = typeof c == "number";
|
|
697
|
-
let
|
|
698
|
-
m && c <= 0 && (p = { x:
|
|
697
|
+
let u = e, y = t, g = 0, f = [u, y, g], h = [u, y], x = 0, p = { x: 0, y: 0 }, b = [{ x: u, y }];
|
|
698
|
+
m && c <= 0 && (p = { x: u, y });
|
|
699
699
|
const A = 300;
|
|
700
700
|
for (let d = 0; d <= A; d += 1) {
|
|
701
|
-
if (x = d / A, { x:
|
|
702
|
-
const M = (g - c) / (g -
|
|
701
|
+
if (x = d / A, { x: u, y } = fe(e, t, n, r, s, i, o, a, l, x), b = [...b, { x: u, y }], g += W(h, [u, y]), h = [u, y], m && g > c && c > f[2]) {
|
|
702
|
+
const M = (g - c) / (g - f[2]);
|
|
703
703
|
p = {
|
|
704
|
-
x:
|
|
705
|
-
y:
|
|
704
|
+
x: h[0] * (1 - M) + f[0] * M,
|
|
705
|
+
y: h[1] * (1 - M) + f[1] * M
|
|
706
706
|
};
|
|
707
707
|
}
|
|
708
|
-
|
|
708
|
+
f = [u, y, g];
|
|
709
709
|
}
|
|
710
710
|
return m && c >= g && (p = { x: a, y: l }), {
|
|
711
711
|
length: g,
|
|
@@ -719,26 +719,26 @@ e.every(([t]) => t === t.toUpperCase()), H = (e) => {
|
|
|
719
719
|
y: Math.max(...b.map((d) => d.y))
|
|
720
720
|
}
|
|
721
721
|
};
|
|
722
|
-
},
|
|
722
|
+
}, ge = (e, t, n, r, s, i, o, a, l) => {
|
|
723
723
|
const c = 1 - l;
|
|
724
724
|
return {
|
|
725
725
|
x: c ** 3 * e + 3 * c ** 2 * l * n + 3 * c * l ** 2 * s + l ** 3 * o,
|
|
726
726
|
y: c ** 3 * t + 3 * c ** 2 * l * r + 3 * c * l ** 2 * i + l ** 3 * a
|
|
727
727
|
};
|
|
728
|
-
},
|
|
728
|
+
}, xe = (e, t, n, r, s, i, o, a, l) => {
|
|
729
729
|
const c = typeof l == "number";
|
|
730
|
-
let m = e,
|
|
731
|
-
c && l <= 0 && (x = { x: m, y:
|
|
730
|
+
let m = e, u = t, y = 0, g = [m, u, y], f = [m, u], h = 0, x = { x: 0, y: 0 }, p = [{ x: m, y: u }];
|
|
731
|
+
c && l <= 0 && (x = { x: m, y: u });
|
|
732
732
|
const b = 300;
|
|
733
733
|
for (let A = 0; A <= b; A += 1) {
|
|
734
|
-
if (
|
|
734
|
+
if (h = A / b, { x: m, y: u } = ge(e, t, n, r, s, i, o, a, h), p = [...p, { x: m, y: u }], y += W(f, [m, u]), f = [m, u], c && y > l && l > g[2]) {
|
|
735
735
|
const d = (y - l) / (y - g[2]);
|
|
736
736
|
x = {
|
|
737
|
-
x:
|
|
738
|
-
y:
|
|
737
|
+
x: f[0] * (1 - d) + g[0] * d,
|
|
738
|
+
y: f[1] * (1 - d) + g[1] * d
|
|
739
739
|
};
|
|
740
740
|
}
|
|
741
|
-
g = [m,
|
|
741
|
+
g = [m, u, y];
|
|
742
742
|
}
|
|
743
743
|
return c && l >= y && (x = { x: o, y: a }), {
|
|
744
744
|
length: y,
|
|
@@ -752,59 +752,59 @@ e.every(([t]) => t === t.toUpperCase()), H = (e) => {
|
|
|
752
752
|
y: Math.max(...p.map((A) => A.y))
|
|
753
753
|
}
|
|
754
754
|
};
|
|
755
|
-
},
|
|
755
|
+
}, pe = (e, t, n, r, s, i, o) => {
|
|
756
756
|
const a = 1 - o;
|
|
757
757
|
return {
|
|
758
758
|
x: a ** 2 * e + 2 * a * o * n + o ** 2 * s,
|
|
759
759
|
y: a ** 2 * t + 2 * a * o * r + o ** 2 * i
|
|
760
760
|
};
|
|
761
|
-
},
|
|
761
|
+
}, be = (e, t, n, r, s, i, o) => {
|
|
762
762
|
const a = typeof o == "number";
|
|
763
|
-
let l = e, c = t, m = 0,
|
|
764
|
-
a && o <= 0 && (
|
|
763
|
+
let l = e, c = t, m = 0, u = [l, c, m], y = [l, c], g = 0, f = { x: 0, y: 0 }, h = [{ x: l, y: c }];
|
|
764
|
+
a && o <= 0 && (f = { x: l, y: c });
|
|
765
765
|
const x = 300;
|
|
766
766
|
for (let p = 0; p <= x; p += 1) {
|
|
767
|
-
if (g = p / x, { x: l, y: c } =
|
|
768
|
-
const b = (m - o) / (m -
|
|
769
|
-
|
|
770
|
-
x: y[0] * (1 - b) +
|
|
771
|
-
y: y[1] * (1 - b) +
|
|
767
|
+
if (g = p / x, { x: l, y: c } = pe(e, t, n, r, s, i, g), h = [...h, { x: l, y: c }], m += W(y, [l, c]), y = [l, c], a && m > o && o > u[2]) {
|
|
768
|
+
const b = (m - o) / (m - u[2]);
|
|
769
|
+
f = {
|
|
770
|
+
x: y[0] * (1 - b) + u[0] * b,
|
|
771
|
+
y: y[1] * (1 - b) + u[1] * b
|
|
772
772
|
};
|
|
773
773
|
}
|
|
774
|
-
|
|
774
|
+
u = [l, c, m];
|
|
775
775
|
}
|
|
776
|
-
return a && o >= m && (
|
|
776
|
+
return a && o >= m && (f = { x: s, y: i }), {
|
|
777
777
|
length: m,
|
|
778
|
-
point:
|
|
778
|
+
point: f,
|
|
779
779
|
min: {
|
|
780
|
-
x: Math.min(...
|
|
781
|
-
y: Math.min(...
|
|
780
|
+
x: Math.min(...h.map((p) => p.x)),
|
|
781
|
+
y: Math.min(...h.map((p) => p.y))
|
|
782
782
|
},
|
|
783
783
|
max: {
|
|
784
|
-
x: Math.max(...
|
|
785
|
-
y: Math.max(...
|
|
784
|
+
x: Math.max(...h.map((p) => p.x)),
|
|
785
|
+
y: Math.max(...h.map((p) => p.y))
|
|
786
786
|
}
|
|
787
787
|
};
|
|
788
788
|
}, ft = (e, t) => {
|
|
789
|
-
const n =
|
|
790
|
-
let s, i = [], o, a = 0, l = 0, c = 0, m = 0,
|
|
789
|
+
const n = z(e), r = typeof t == "number";
|
|
790
|
+
let s, i = [], o, a = 0, l = 0, c = 0, m = 0, u, y = [], g = [], f = 0, h = { x: 0, y: 0 }, x = h, p = h, b = h, A = 0;
|
|
791
791
|
for (let d = 0, M = n.length; d < M; d += 1)
|
|
792
|
-
|
|
792
|
+
u = n[d], [o] = u, s = o === "M", i = s ? i : [a, l, ...u.slice(1)], s ? ([, c, m] = u, h = { x: c, y: m }, x = h, f = 0, r && t < 1e-3 && (b = h)) : o === "L" ? { length: f, min: h, max: x, point: p } = dt(
|
|
793
793
|
...i,
|
|
794
794
|
(t || 0) - A
|
|
795
|
-
) : o === "A" ? { length:
|
|
795
|
+
) : o === "A" ? { length: f, min: h, max: x, point: p } = ye(
|
|
796
796
|
...i,
|
|
797
797
|
(t || 0) - A
|
|
798
|
-
) : o === "C" ? { length:
|
|
798
|
+
) : o === "C" ? { length: f, min: h, max: x, point: p } = xe(
|
|
799
799
|
...i,
|
|
800
800
|
(t || 0) - A
|
|
801
|
-
) : o === "Q" ? { length:
|
|
801
|
+
) : o === "Q" ? { length: f, min: h, max: x, point: p } = be(
|
|
802
802
|
...i,
|
|
803
803
|
(t || 0) - A
|
|
804
|
-
) : o === "Z" && (i = [a, l, c, m], { length:
|
|
804
|
+
) : o === "Z" && (i = [a, l, c, m], { length: f, min: h, max: x, point: p } = dt(
|
|
805
805
|
...i,
|
|
806
806
|
(t || 0) - A
|
|
807
|
-
)), r && A < t && A +
|
|
807
|
+
)), r && A < t && A + f >= t && (b = p), g = [...g, x], y = [...y, h], A += f, [a, l] = o !== "Z" ? u.slice(-2) : [c, m];
|
|
808
808
|
return r && t >= A && (b = { x: a, y: l }), {
|
|
809
809
|
length: A,
|
|
810
810
|
point: b,
|
|
@@ -817,7 +817,7 @@ e.every(([t]) => t === t.toUpperCase()), H = (e) => {
|
|
|
817
817
|
y: Math.max(...g.map((d) => d.y))
|
|
818
818
|
}
|
|
819
819
|
};
|
|
820
|
-
},
|
|
820
|
+
}, kt = (e) => {
|
|
821
821
|
if (!e)
|
|
822
822
|
return {
|
|
823
823
|
x: 0,
|
|
@@ -855,38 +855,38 @@ e.every(([t]) => t === t.toUpperCase()), H = (e) => {
|
|
|
855
855
|
t[n] = "A", e.splice(s += 1, 0, ["C", ...r.splice(0, 6)]);
|
|
856
856
|
e.splice(n, 1);
|
|
857
857
|
}
|
|
858
|
-
}, Jt = (e) =>
|
|
858
|
+
}, Jt = (e) => vt(e) && e.every(([t]) => "MC".includes(t)), rt = (e, t, n) => {
|
|
859
859
|
const r = e * Math.cos(n) - t * Math.sin(n), s = e * Math.sin(n) + t * Math.cos(n);
|
|
860
860
|
return { x: r, y: s };
|
|
861
861
|
}, Ut = (e, t, n, r, s, i, o, a, l, c) => {
|
|
862
|
-
let m = e,
|
|
862
|
+
let m = e, u = t, y = n, g = r, f = a, h = l;
|
|
863
863
|
const x = Math.PI * 120 / 180, p = Math.PI / 180 * (+s || 0);
|
|
864
|
-
let b = [], A, d, M, T,
|
|
864
|
+
let b = [], A, d, M, T, E;
|
|
865
865
|
if (c)
|
|
866
|
-
[d, M, T,
|
|
866
|
+
[d, M, T, E] = c;
|
|
867
867
|
else {
|
|
868
|
-
A = rt(m,
|
|
869
|
-
const P = (m -
|
|
870
|
-
let
|
|
871
|
-
|
|
872
|
-
const xt = y * y, pt = g * g,
|
|
873
|
-
T =
|
|
868
|
+
A = rt(m, u, -p), m = A.x, u = A.y, A = rt(f, h, -p), f = A.x, h = A.y;
|
|
869
|
+
const P = (m - f) / 2, L = (u - h) / 2;
|
|
870
|
+
let I = P * P / (y * y) + L * L / (g * g);
|
|
871
|
+
I > 1 && (I = Math.sqrt(I), y *= I, g *= I);
|
|
872
|
+
const xt = y * y, pt = g * g, Ct = (i === o ? -1 : 1) * Math.sqrt(Math.abs((xt * pt - xt * L * L - pt * P * P) / (xt * L * L + pt * P * P)));
|
|
873
|
+
T = Ct * y * L / g + (m + f) / 2, E = Ct * -g * P / y + (u + h) / 2, d = Math.asin(((u - E) / g * 10 ** 9 >> 0) / 10 ** 9), M = Math.asin(((h - E) / g * 10 ** 9 >> 0) / 10 ** 9), d = m < T ? Math.PI - d : d, M = f < T ? Math.PI - M : M, d < 0 && (d = Math.PI * 2 + d), M < 0 && (M = Math.PI * 2 + M), o && d > M && (d -= Math.PI * 2), !o && M > d && (M -= Math.PI * 2);
|
|
874
874
|
}
|
|
875
|
-
let
|
|
876
|
-
if (Math.abs(
|
|
877
|
-
const P = M, L =
|
|
878
|
-
M = d + x * (o && M > d ? 1 : -1),
|
|
875
|
+
let H = M - d;
|
|
876
|
+
if (Math.abs(H) > x) {
|
|
877
|
+
const P = M, L = f, I = h;
|
|
878
|
+
M = d + x * (o && M > d ? 1 : -1), f = T + y * Math.cos(M), h = E + g * Math.sin(M), b = Ut(f, h, y, g, s, 0, o, L, I, [M, P, T, E]);
|
|
879
879
|
}
|
|
880
|
-
|
|
881
|
-
const
|
|
882
|
-
if (q[0] = 2 *
|
|
883
|
-
return [...q, ...
|
|
884
|
-
b = [...q, ...
|
|
880
|
+
H = M - d;
|
|
881
|
+
const F = Math.cos(d), tt = Math.sin(d), S = Math.cos(M), et = Math.sin(M), Y = Math.tan(H / 4), nt = 4 / 3 * y * Y, st = 4 / 3 * g * Y, $ = [m, u], q = [m + nt * tt, u - st * F], B = [f + nt * et, h - st * S], J = [f, h];
|
|
882
|
+
if (q[0] = 2 * $[0] - q[0], q[1] = 2 * $[1] - q[1], c)
|
|
883
|
+
return [...q, ...B, ...J, ...b];
|
|
884
|
+
b = [...q, ...B, ...J, ...b];
|
|
885
885
|
const gt = [];
|
|
886
886
|
for (let P = 0, L = b.length; P < L; P += 1)
|
|
887
887
|
gt[P] = P % 2 ? rt(b[P - 1], b[P], p).y : rt(b[P], b[P + 1], p).x;
|
|
888
888
|
return gt;
|
|
889
|
-
},
|
|
889
|
+
}, de = (e, t, n, r, s, i) => {
|
|
890
890
|
const o = 0.3333333333333333, a = 2 / 3;
|
|
891
891
|
return [
|
|
892
892
|
o * e + a * n,
|
|
@@ -901,15 +901,15 @@ e.every(([t]) => t === t.toUpperCase()), H = (e) => {
|
|
|
901
901
|
i
|
|
902
902
|
// x,y
|
|
903
903
|
];
|
|
904
|
-
},
|
|
904
|
+
}, St = (e, t, n, r) => [...j([e, t], [n, r], 0.5), n, r, n, r], ot = (e, t) => {
|
|
905
905
|
const [n] = e, r = e.slice(1).map(Number), [s, i] = r;
|
|
906
906
|
let o;
|
|
907
907
|
const { x1: a, y1: l, x: c, y: m } = t;
|
|
908
|
-
return "TQ".includes(n) || (t.qx = null, t.qy = null), n === "M" ? (t.x = s, t.y = i, e) : n === "A" ? (o = [a, l, ...r], ["C", ...Ut(...o)]) : n === "Q" ? (t.qx = s, t.qy = i, o = [a, l, ...r], ["C", ...
|
|
908
|
+
return "TQ".includes(n) || (t.qx = null, t.qy = null), n === "M" ? (t.x = s, t.y = i, e) : n === "A" ? (o = [a, l, ...r], ["C", ...Ut(...o)]) : n === "Q" ? (t.qx = s, t.qy = i, o = [a, l, ...r], ["C", ...de(...o)]) : n === "L" ? ["C", ...St(a, l, s, i)] : n === "Z" ? ["C", ...St(a, l, c, m)] : e;
|
|
909
909
|
}, ct = (e) => {
|
|
910
910
|
if (Jt(e))
|
|
911
911
|
return [...e];
|
|
912
|
-
const t =
|
|
912
|
+
const t = z(e), n = { ...ut }, r = [];
|
|
913
913
|
let s = "", i = t.length;
|
|
914
914
|
for (let o = 0; o < i; o += 1) {
|
|
915
915
|
[s] = t[o], r[o] = s, t[o] = ot(t[o], n), Mt(t, r, o), i = t.length;
|
|
@@ -917,30 +917,30 @@ e.every(([t]) => t === t.toUpperCase()), H = (e) => {
|
|
|
917
917
|
n.x1 = +a[l - 2], n.y1 = +a[l - 1], n.x2 = +a[l - 4] || n.x1, n.y2 = +a[l - 3] || n.y1;
|
|
918
918
|
}
|
|
919
919
|
return t;
|
|
920
|
-
},
|
|
920
|
+
}, Me = (e, t, n, r, s, i, o, a) => 3 * ((a - t) * (n + s) - (o - e) * (r + i) + r * (e - s) - n * (t - i) + a * (s + e / 3) - o * (i + t / 3)) / 20, Vt = (e) => {
|
|
921
921
|
let t = 0, n = 0, r = 0;
|
|
922
922
|
return ct(e).map((s) => {
|
|
923
923
|
switch (s[0]) {
|
|
924
924
|
case "M":
|
|
925
925
|
return [, t, n] = s, 0;
|
|
926
926
|
default:
|
|
927
|
-
return r =
|
|
927
|
+
return r = Me(t, n, ...s.slice(1)), [t, n] = s.slice(-2), r;
|
|
928
928
|
}
|
|
929
929
|
}).reduce((s, i) => s + i, 0);
|
|
930
|
-
},
|
|
931
|
-
const n =
|
|
932
|
-
let r = [...n], s =
|
|
933
|
-
const [c, m] = l.slice(-2),
|
|
930
|
+
}, X = (e) => ft(e).length, Ae = (e) => Vt(ct(e)) >= 0, K = (e, t) => ft(e, t).point, Pt = (e, t) => {
|
|
931
|
+
const n = Z(e);
|
|
932
|
+
let r = [...n], s = X(r), i = r.length - 1, o = 0, a = 0, l = n[0];
|
|
933
|
+
const [c, m] = l.slice(-2), u = { x: c, y: m };
|
|
934
934
|
if (i <= 0 || !t || !Number.isFinite(t))
|
|
935
935
|
return {
|
|
936
936
|
segment: l,
|
|
937
937
|
index: 0,
|
|
938
938
|
length: a,
|
|
939
|
-
point:
|
|
939
|
+
point: u,
|
|
940
940
|
lengthAtSegment: o
|
|
941
941
|
};
|
|
942
942
|
if (t >= s)
|
|
943
|
-
return r = n.slice(0, -1), o =
|
|
943
|
+
return r = n.slice(0, -1), o = X(r), a = s - o, {
|
|
944
944
|
segment: n[i],
|
|
945
945
|
index: i,
|
|
946
946
|
length: a,
|
|
@@ -948,7 +948,7 @@ e.every(([t]) => t === t.toUpperCase()), H = (e) => {
|
|
|
948
948
|
};
|
|
949
949
|
const y = [];
|
|
950
950
|
for (; i > 0; )
|
|
951
|
-
l = r[i], r = r.slice(0, -1), o =
|
|
951
|
+
l = r[i], r = r.slice(0, -1), o = X(r), a = s - o, s = o, y.push({
|
|
952
952
|
segment: l,
|
|
953
953
|
index: i,
|
|
954
954
|
length: a,
|
|
@@ -956,41 +956,31 @@ e.every(([t]) => t === t.toUpperCase()), H = (e) => {
|
|
|
956
956
|
}), i -= 1;
|
|
957
957
|
return y.find(({ lengthAtSegment: g }) => g <= t);
|
|
958
958
|
}, yt = (e, t) => {
|
|
959
|
-
const n =
|
|
959
|
+
const n = Z(e), r = z(n), s = X(n), i = (d) => {
|
|
960
960
|
const M = d.x - t.x, T = d.y - t.y;
|
|
961
961
|
return M * M + T * T;
|
|
962
962
|
};
|
|
963
|
-
let o = 8, a, l = { x: 0, y: 0 }, c = 0, m = 0,
|
|
963
|
+
let o = 8, a, l = { x: 0, y: 0 }, c = 0, m = 0, u = 1 / 0;
|
|
964
964
|
for (let d = 0; d <= s; d += o)
|
|
965
|
-
a =
|
|
965
|
+
a = K(r, d), c = i(a), c < u && (l = a, m = d, u = c);
|
|
966
966
|
o /= 2;
|
|
967
|
-
let y, g,
|
|
967
|
+
let y, g, f = 0, h = 0, x = 0, p = 0;
|
|
968
968
|
for (; o > 0.5; )
|
|
969
|
-
|
|
970
|
-
const b =
|
|
969
|
+
f = m - o, y = K(r, f), x = i(y), h = m + o, g = K(r, h), p = i(g), f >= 0 && x < u ? (l = y, m = f, u = x) : h <= s && p < u ? (l = g, m = h, u = p) : o /= 2;
|
|
970
|
+
const b = Pt(n, m), A = Math.sqrt(u);
|
|
971
971
|
return { closest: l, distance: A, segment: b };
|
|
972
|
-
},
|
|
972
|
+
}, Ne = (e, t) => yt(e, t).closest, we = (e, t) => yt(e, t).segment, ve = (e, t) => Pt(e, t).segment, Pe = (e, t) => {
|
|
973
973
|
const { distance: n } = yt(e, t);
|
|
974
974
|
return Math.abs(n) < 1e-3;
|
|
975
|
-
},
|
|
976
|
-
if (typeof e != "string")
|
|
975
|
+
}, Kt = (e) => {
|
|
976
|
+
if (typeof e != "string" || !e.length)
|
|
977
977
|
return !1;
|
|
978
|
-
const t = new
|
|
979
|
-
for (
|
|
980
|
-
|
|
978
|
+
const t = new zt(e);
|
|
979
|
+
for (V(t); t.index < t.max && !t.err.length; )
|
|
980
|
+
jt(t);
|
|
981
981
|
return !t.err.length && "mM".includes(t.segments[0][0]);
|
|
982
|
-
},
|
|
983
|
-
e.slice(1).every(([t]) => t === t.toLowerCase()), lt =
|
|
984
|
-
let { round: n } = at;
|
|
985
|
-
if (t === "off" || n === "off")
|
|
986
|
-
return [...e];
|
|
987
|
-
n = typeof t == "number" && t >= 0 ? t : n;
|
|
988
|
-
const r = typeof n == "number" && n >= 1 ? 10 ** n : 1;
|
|
989
|
-
return e.map((s) => {
|
|
990
|
-
const i = s.slice(1).map(Number).map((o) => n ? Math.round(o * r) / r : Math.round(o));
|
|
991
|
-
return [s[0], ...i];
|
|
992
|
-
});
|
|
993
|
-
}, Z = (e, t) => lt(e, t).map((n) => n[0] + n.slice(1).join(" ")).join(""), St = {
|
|
982
|
+
}, _t = (e) => _(e) && // `isPathArray` checks if it's `Array`
|
|
983
|
+
e.slice(1).every(([t]) => t === t.toLowerCase()), lt = {
|
|
994
984
|
line: ["x1", "y1", "x2", "y2"],
|
|
995
985
|
circle: ["cx", "cy", "r"],
|
|
996
986
|
ellipse: ["cx", "cy", "rx", "ry"],
|
|
@@ -998,36 +988,36 @@ e.slice(1).every(([t]) => t === t.toLowerCase()), lt = (e, t) => {
|
|
|
998
988
|
polygon: ["points"],
|
|
999
989
|
polyline: ["points"],
|
|
1000
990
|
glyph: ["d"]
|
|
1001
|
-
},
|
|
1002
|
-
|
|
1003
|
-
return [
|
|
991
|
+
}, Ce = (e) => {
|
|
992
|
+
let { x1: t, y1: n, x2: r, y2: s } = e;
|
|
993
|
+
return [t, n, r, s] = [t, n, r, s].map((i) => +i), [
|
|
1004
994
|
["M", t, n],
|
|
1005
995
|
["L", r, s]
|
|
1006
996
|
];
|
|
1007
|
-
},
|
|
1008
|
-
const t = [], n = (e.points || "").trim().split(/[\s|,]/).map(
|
|
997
|
+
}, Te = (e) => {
|
|
998
|
+
const t = [], n = (e.points || "").trim().split(/[\s|,]/).map((s) => +s);
|
|
1009
999
|
let r = 0;
|
|
1010
1000
|
for (; r < n.length; )
|
|
1011
1001
|
t.push([r ? "L" : "M", n[r], n[r + 1]]), r += 2;
|
|
1012
1002
|
return e.type === "polygon" ? [...t, ["z"]] : t;
|
|
1013
|
-
},
|
|
1014
|
-
|
|
1015
|
-
return [
|
|
1003
|
+
}, Le = (e) => {
|
|
1004
|
+
let { cx: t, cy: n, r } = e;
|
|
1005
|
+
return [t, n, r] = [t, n, r].map((s) => +s), [
|
|
1016
1006
|
["M", t - r, n],
|
|
1017
1007
|
["a", r, r, 0, 1, 0, 2 * r, 0],
|
|
1018
1008
|
["a", r, r, 0, 1, 0, -2 * r, 0]
|
|
1019
1009
|
];
|
|
1020
|
-
},
|
|
1021
|
-
|
|
1022
|
-
return [
|
|
1010
|
+
}, ke = (e) => {
|
|
1011
|
+
let { cx: t, cy: n } = e, r = e.rx || 0, s = e.ry || r;
|
|
1012
|
+
return [t, n, r, s] = [t, n, r, s].map((i) => +i), [
|
|
1023
1013
|
["M", t - r, n],
|
|
1024
1014
|
["a", r, s, 0, 1, 0, 2 * r, 0],
|
|
1025
1015
|
["a", r, s, 0, 1, 0, -2 * r, 0]
|
|
1026
1016
|
];
|
|
1027
|
-
},
|
|
1017
|
+
}, Se = (e) => {
|
|
1028
1018
|
const t = +e.x || 0, n = +e.y || 0, r = +e.width, s = +e.height;
|
|
1029
|
-
let i = +e.rx, o = +e.ry;
|
|
1030
|
-
return i || o ? (i
|
|
1019
|
+
let i = +(e.rx || 0), o = +(e.ry || i);
|
|
1020
|
+
return i || o ? (i * 2 > r && (i -= (i * 2 - r) / 2), o * 2 > s && (o -= (o * 2 - s) / 2), [
|
|
1031
1021
|
["M", t + i, n],
|
|
1032
1022
|
["h", r - i * 2],
|
|
1033
1023
|
["s", i, 0, i, o],
|
|
@@ -1038,35 +1028,55 @@ e.slice(1).every(([t]) => t === t.toLowerCase()), lt = (e, t) => {
|
|
|
1038
1028
|
["v", -s + o * 2],
|
|
1039
1029
|
["s", 0, -o, i, -o]
|
|
1040
1030
|
]) : [["M", t, n], ["h", r], ["v", s], ["H", t], ["Z"]];
|
|
1041
|
-
},
|
|
1031
|
+
}, Wt = (e, t) => {
|
|
1032
|
+
const r = (t || document).defaultView || /* istanbul ignore next */
|
|
1033
|
+
window, s = Object.keys(lt), i = e instanceof r.SVGElement, o = i ? e.tagName : null;
|
|
1034
|
+
if (o && [...s, "path"].every((u) => o !== u))
|
|
1035
|
+
throw TypeError(`${k}: "${o}" is not SVGElement`);
|
|
1036
|
+
const a = i ? o : e.type, l = lt[a], c = { type: a };
|
|
1037
|
+
i ? l.forEach((u) => {
|
|
1038
|
+
c[u] = e.getAttribute(u);
|
|
1039
|
+
}) : Object.assign(c, e);
|
|
1040
|
+
let m = [];
|
|
1041
|
+
return a === "circle" ? m = Le(c) : a === "ellipse" ? m = ke(c) : ["polyline", "polygon"].includes(a) ? m = Te(c) : a === "rect" ? m = Se(c) : a === "line" ? m = Ce(c) : ["glyph", "path"].includes(a) && (m = Z(i ? e.getAttribute("d") || "" : e.d || "")), _(m) && m.length ? m : !1;
|
|
1042
|
+
}, at = (e, t) => {
|
|
1043
|
+
let { round: n } = mt;
|
|
1044
|
+
if (t === "off" || n === "off")
|
|
1045
|
+
return [...e];
|
|
1046
|
+
n = typeof t == "number" && t >= 0 ? t : n;
|
|
1047
|
+
const r = typeof n == "number" && n >= 1 ? 10 ** n : 1;
|
|
1048
|
+
return e.map((s) => {
|
|
1049
|
+
const i = s.slice(1).map(Number).map((o) => n ? Math.round(o * r) / r : Math.round(o));
|
|
1050
|
+
return [s[0], ...i];
|
|
1051
|
+
});
|
|
1052
|
+
}, At = (e, t) => at(e, t).map((n) => n[0] + n.slice(1).join(" ")).join(""), $e = (e, t, n) => {
|
|
1042
1053
|
const r = n || document, s = r.defaultView || /* istanbul ignore next */
|
|
1043
|
-
window, i = Object.keys(
|
|
1054
|
+
window, i = Object.keys(lt), o = e instanceof s.SVGElement, a = o ? e.tagName : null;
|
|
1055
|
+
if (a === "path")
|
|
1056
|
+
throw TypeError(`${k}: "${a}" is already SVGPathElement`);
|
|
1044
1057
|
if (a && i.every((h) => a !== h))
|
|
1045
|
-
throw TypeError(`${
|
|
1046
|
-
const l = r.createElementNS("http://www.w3.org/2000/svg", "path"), c = o ? a : e.type, m =
|
|
1047
|
-
o ? (m.forEach((h) => {
|
|
1048
|
-
|
|
1049
|
-
}), Object.values(e.attributes).forEach(({ name: h, value:
|
|
1050
|
-
m.includes(h) || l.setAttribute(h,
|
|
1051
|
-
})) : (Object.assign(
|
|
1058
|
+
throw TypeError(`${k}: "${a}" is not SVGElement`);
|
|
1059
|
+
const l = r.createElementNS("http://www.w3.org/2000/svg", "path"), c = o ? a : e.type, m = lt[c], u = { type: c }, y = mt.round, g = Wt(e, r), f = g && g.length ? At(g, y) : "";
|
|
1060
|
+
return o ? (m.forEach((h) => {
|
|
1061
|
+
u[h] = e.getAttribute(h);
|
|
1062
|
+
}), Object.values(e.attributes).forEach(({ name: h, value: x }) => {
|
|
1063
|
+
m.includes(h) || l.setAttribute(h, x);
|
|
1064
|
+
})) : (Object.assign(u, e), Object.keys(u).forEach((h) => {
|
|
1052
1065
|
!m.includes(h) && h !== "type" && l.setAttribute(
|
|
1053
|
-
h.replace(/[A-Z]/g, (
|
|
1054
|
-
|
|
1066
|
+
h.replace(/[A-Z]/g, (x) => `-${x.toLowerCase()}`),
|
|
1067
|
+
u[h]
|
|
1055
1068
|
);
|
|
1056
|
-
}));
|
|
1057
|
-
|
|
1058
|
-
const g = at.round;
|
|
1059
|
-
return c === "circle" ? y = Z(Te(f), g) : c === "ellipse" ? y = Z(Le(f), g) : ["polyline", "polygon"].includes(c) ? y = Z(Ce(f), g) : c === "rect" ? y = Z(ke(f), g) : c === "line" ? y = Z(Pe(f), g) : c === "glyph" && (y = o ? e.getAttribute("d") : e.d), _t(y) ? (l.setAttribute("d", y), t && o && (e.before(l, e), e.remove()), l) : !1;
|
|
1060
|
-
}, qt = (e) => {
|
|
1069
|
+
})), Kt(f) ? (l.setAttribute("d", f), t && o && (e.before(l, e), e.remove()), l) : !1;
|
|
1070
|
+
}, $t = (e) => {
|
|
1061
1071
|
const t = [];
|
|
1062
1072
|
let n, r = -1;
|
|
1063
1073
|
return e.forEach((s) => {
|
|
1064
1074
|
s[0] === "M" ? (n = [s], r += 1) : n = [...n, s], t[r] = n;
|
|
1065
1075
|
}), t;
|
|
1066
|
-
},
|
|
1067
|
-
if (
|
|
1076
|
+
}, Nt = (e) => {
|
|
1077
|
+
if (_t(e))
|
|
1068
1078
|
return [...e];
|
|
1069
|
-
const t =
|
|
1079
|
+
const t = Z(e);
|
|
1070
1080
|
let n = 0, r = 0, s = 0, i = 0;
|
|
1071
1081
|
return t.map((o) => {
|
|
1072
1082
|
const a = o.slice(1).map(Number), [l] = o, c = l.toLowerCase();
|
|
@@ -1090,39 +1100,39 @@ e.slice(1).every(([t]) => t === t.toLowerCase()), lt = (e, t) => {
|
|
|
1090
1100
|
else if (c === "h")
|
|
1091
1101
|
m = [c, a[0] - n];
|
|
1092
1102
|
else {
|
|
1093
|
-
const y = a.map((g,
|
|
1103
|
+
const y = a.map((g, f) => g - (f % 2 ? r : n));
|
|
1094
1104
|
m = [c, ...y];
|
|
1095
1105
|
}
|
|
1096
1106
|
else
|
|
1097
1107
|
l === "m" && (s = a[0] + n, i = a[1] + r), m = [c, ...a];
|
|
1098
|
-
const
|
|
1099
|
-
return c === "z" ? (n = s, r = i) : c === "h" ? n += m[1] : c === "v" ? r += m[1] : (n += m[
|
|
1108
|
+
const u = m.length;
|
|
1109
|
+
return c === "z" ? (n = s, r = i) : c === "h" ? n += m[1] : c === "v" ? r += m[1] : (n += m[u - 2], r += m[u - 1]), m;
|
|
1100
1110
|
});
|
|
1101
1111
|
}, qe = (e, t, n, r) => {
|
|
1102
|
-
const [s] = e, i = (p) => Math.round(p * 10 ** 4) / 10 ** 4, o = e.slice(1).map((p) => +p), a = t.slice(1).map((p) => +p), { x1: l, y1: c, x2: m, y2:
|
|
1103
|
-
let
|
|
1104
|
-
const [
|
|
1112
|
+
const [s] = e, i = (p) => Math.round(p * 10 ** 4) / 10 ** 4, o = e.slice(1).map((p) => +p), a = t.slice(1).map((p) => +p), { x1: l, y1: c, x2: m, y2: u, x: y, y: g } = n;
|
|
1113
|
+
let f = e;
|
|
1114
|
+
const [h, x] = a.slice(-2);
|
|
1105
1115
|
if ("TQ".includes(s) || (n.qx = null, n.qy = null), ["V", "H", "S", "T", "Z"].includes(s))
|
|
1106
|
-
|
|
1116
|
+
f = [s, ...o];
|
|
1107
1117
|
else if (s === "L")
|
|
1108
|
-
i(y) === i(
|
|
1118
|
+
i(y) === i(h) ? f = ["V", x] : i(g) === i(x) && (f = ["H", h]);
|
|
1109
1119
|
else if (s === "C") {
|
|
1110
1120
|
const [p, b] = a;
|
|
1111
|
-
"CS".includes(r) && (i(p) === i(l * 2 - m) && i(b) === i(c * 2 -
|
|
1121
|
+
"CS".includes(r) && (i(p) === i(l * 2 - m) && i(b) === i(c * 2 - u) || i(l) === i(m * 2 - y) && i(c) === i(u * 2 - g)) && (f = ["S", ...a.slice(-4)]), n.x1 = p, n.y1 = b;
|
|
1112
1122
|
} else if (s === "Q") {
|
|
1113
1123
|
const [p, b] = a;
|
|
1114
|
-
n.qx = p, n.qy = b, "QT".includes(r) && (i(p) === i(l * 2 - m) && i(b) === i(c * 2 -
|
|
1124
|
+
n.qx = p, n.qy = b, "QT".includes(r) && (i(p) === i(l * 2 - m) && i(b) === i(c * 2 - u) || i(l) === i(m * 2 - y) && i(c) === i(u * 2 - g)) && (f = ["T", ...a.slice(-2)]);
|
|
1115
1125
|
}
|
|
1116
|
-
return
|
|
1117
|
-
},
|
|
1118
|
-
const n =
|
|
1119
|
-
let a = "", l = "", c = 0, m = 0,
|
|
1120
|
-
for (let
|
|
1121
|
-
[a] = n[
|
|
1122
|
-
const x = n[
|
|
1126
|
+
return f;
|
|
1127
|
+
}, qt = (e, t) => {
|
|
1128
|
+
const n = Q(e), r = z(n), s = { ...ut }, i = [], o = n.length;
|
|
1129
|
+
let a = "", l = "", c = 0, m = 0, u = 0, y = 0;
|
|
1130
|
+
for (let h = 0; h < o; h += 1) {
|
|
1131
|
+
[a] = n[h], i[h] = a, h && (l = i[h - 1]), n[h] = qe(n[h], r[h], s, l);
|
|
1132
|
+
const x = n[h], p = x.length;
|
|
1123
1133
|
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, a) {
|
|
1124
1134
|
case "Z":
|
|
1125
|
-
c =
|
|
1135
|
+
c = u, m = y;
|
|
1126
1136
|
break;
|
|
1127
1137
|
case "H":
|
|
1128
1138
|
[, c] = x;
|
|
@@ -1131,19 +1141,19 @@ e.slice(1).every(([t]) => t === t.toLowerCase()), lt = (e, t) => {
|
|
|
1131
1141
|
[, m] = x;
|
|
1132
1142
|
break;
|
|
1133
1143
|
default:
|
|
1134
|
-
[c, m] = x.slice(-2).map(Number), a === "M" && (
|
|
1144
|
+
[c, m] = x.slice(-2).map(Number), a === "M" && (u = c, y = m);
|
|
1135
1145
|
}
|
|
1136
1146
|
s.x = c, s.y = m;
|
|
1137
1147
|
}
|
|
1138
|
-
const g =
|
|
1139
|
-
return g.map((
|
|
1140
|
-
},
|
|
1148
|
+
const g = at(n, t), f = at(Nt(n), t);
|
|
1149
|
+
return g.map((h, x) => x ? h.join("").length < f[x].join("").length ? h : f[x] : h);
|
|
1150
|
+
}, Oe = (e) => {
|
|
1141
1151
|
const t = e.slice(1).map(
|
|
1142
1152
|
(n, r, s) => r ? [...s[r - 1].slice(-2), ...n.slice(1)] : [...e[0].slice(1), ...n.slice(1)]
|
|
1143
1153
|
).map((n) => n.map((r, s) => n[n.length - s - 2 * (1 - s % 2)])).reverse();
|
|
1144
1154
|
return [["M", ...t[0].slice(0, 2)], ...t.map((n) => ["C", ...n.slice(2)])];
|
|
1145
1155
|
}, it = (e) => {
|
|
1146
|
-
const t =
|
|
1156
|
+
const t = Q(e), n = t.slice(-1)[0][0] === "Z", r = z(t).map((s, i) => {
|
|
1147
1157
|
const [o, a] = s.slice(-2).map(Number);
|
|
1148
1158
|
return {
|
|
1149
1159
|
seg: t[i],
|
|
@@ -1158,93 +1168,93 @@ e.slice(1).every(([t]) => t === t.toLowerCase()), lt = (e, t) => {
|
|
|
1158
1168
|
// y
|
|
1159
1169
|
};
|
|
1160
1170
|
}).map((s, i, o) => {
|
|
1161
|
-
const a = s.seg, l = s.n, c = i && o[i - 1], m = o[i + 1],
|
|
1162
|
-
let
|
|
1163
|
-
switch (
|
|
1171
|
+
const a = s.seg, l = s.n, c = i && o[i - 1], m = o[i + 1], u = s.c, y = o.length, g = i ? o[i - 1].x : o[y - 1].x, f = i ? o[i - 1].y : o[y - 1].y;
|
|
1172
|
+
let h = [];
|
|
1173
|
+
switch (u) {
|
|
1164
1174
|
case "M":
|
|
1165
|
-
|
|
1175
|
+
h = n ? ["Z"] : [u, g, f];
|
|
1166
1176
|
break;
|
|
1167
1177
|
case "A":
|
|
1168
|
-
|
|
1178
|
+
h = [u, ...a.slice(1, -3), a[5] === 1 ? 0 : 1, g, f];
|
|
1169
1179
|
break;
|
|
1170
1180
|
case "C":
|
|
1171
|
-
m && m.c === "S" ?
|
|
1181
|
+
m && m.c === "S" ? h = ["S", a[1], a[2], g, f] : h = [u, a[3], a[4], a[1], a[2], g, f];
|
|
1172
1182
|
break;
|
|
1173
1183
|
case "S":
|
|
1174
|
-
c && "CS".includes(c.c) && (!m || m.c !== "S") ?
|
|
1184
|
+
c && "CS".includes(c.c) && (!m || m.c !== "S") ? h = ["C", l[3], l[4], l[1], l[2], g, f] : h = [u, l[1], l[2], g, f];
|
|
1175
1185
|
break;
|
|
1176
1186
|
case "Q":
|
|
1177
|
-
m && m.c === "T" ?
|
|
1187
|
+
m && m.c === "T" ? h = ["T", g, f] : h = [u, ...a.slice(1, -2), g, f];
|
|
1178
1188
|
break;
|
|
1179
1189
|
case "T":
|
|
1180
|
-
c && "QT".includes(c.c) && (!m || m.c !== "T") ?
|
|
1190
|
+
c && "QT".includes(c.c) && (!m || m.c !== "T") ? h = ["Q", l[1], l[2], g, f] : h = [u, g, f];
|
|
1181
1191
|
break;
|
|
1182
1192
|
case "Z":
|
|
1183
|
-
|
|
1193
|
+
h = ["M", g, f];
|
|
1184
1194
|
break;
|
|
1185
1195
|
case "H":
|
|
1186
|
-
|
|
1196
|
+
h = [u, g];
|
|
1187
1197
|
break;
|
|
1188
1198
|
case "V":
|
|
1189
|
-
|
|
1199
|
+
h = [u, f];
|
|
1190
1200
|
break;
|
|
1191
1201
|
default:
|
|
1192
|
-
|
|
1202
|
+
h = [u, ...a.slice(1, -2), g, f];
|
|
1193
1203
|
}
|
|
1194
|
-
return
|
|
1204
|
+
return h;
|
|
1195
1205
|
});
|
|
1196
1206
|
return n ? r.reverse() : [r[0], ...r.slice(1).reverse()];
|
|
1197
|
-
},
|
|
1207
|
+
}, Ee = (e) => {
|
|
1198
1208
|
let t = new v();
|
|
1199
1209
|
const { origin: n } = e, [r, s] = n, { translate: i } = e, { rotate: o } = e, { skew: a } = e, { scale: l } = e;
|
|
1200
1210
|
return Array.isArray(i) && i.length >= 2 && i.every((c) => !Number.isNaN(+c)) && i.some((c) => c !== 0) ? t = t.translate(...i) : typeof i == "number" && !Number.isNaN(i) && (t = t.translate(i)), (o || a || l) && (t = t.translate(r, s), Array.isArray(o) && o.length >= 2 && o.every((c) => !Number.isNaN(+c)) && o.some((c) => c !== 0) ? t = t.rotate(...o) : typeof o == "number" && !Number.isNaN(o) && (t = t.rotate(o)), Array.isArray(a) && a.length === 2 && a.every((c) => !Number.isNaN(+c)) && a.some((c) => c !== 0) ? (t = a[0] ? t.skewX(a[0]) : t, t = a[1] ? t.skewY(a[1]) : t) : typeof a == "number" && !Number.isNaN(a) && (t = t.skewX(a)), Array.isArray(l) && l.length >= 2 && l.every((c) => !Number.isNaN(+c)) && l.some((c) => c !== 1) ? t = t.scale(...l) : typeof l == "number" && !Number.isNaN(l) && (t = t.scale(l)), t = t.translate(-r, -s)), t;
|
|
1201
|
-
},
|
|
1211
|
+
}, je = (e, t) => {
|
|
1202
1212
|
let n = v.Translate(...t.slice(0, -1));
|
|
1203
1213
|
return [, , , n.m44] = t, n = e.multiply(n), [n.m41, n.m42, n.m43, n.m44];
|
|
1204
1214
|
}, Ot = (e, t, n) => {
|
|
1205
|
-
const [r, s, i] = n, [o, a, l] =
|
|
1215
|
+
const [r, s, i] = n, [o, a, l] = je(e, [...t, 0, 1]), c = o - r, m = a - s, u = l - i;
|
|
1206
1216
|
return [
|
|
1207
1217
|
// protect against division by ZERO
|
|
1208
|
-
c * (Math.abs(i) / Math.abs(
|
|
1209
|
-
m * (Math.abs(i) / Math.abs(
|
|
1218
|
+
c * (Math.abs(i) / Math.abs(u) || 1) + r,
|
|
1219
|
+
m * (Math.abs(i) / Math.abs(u) || 1) + s
|
|
1210
1220
|
];
|
|
1211
|
-
},
|
|
1221
|
+
}, Et = (e, t) => {
|
|
1212
1222
|
let n = 0, r = 0, s, i, o, a, l, c;
|
|
1213
|
-
const m =
|
|
1214
|
-
if (!t ||
|
|
1223
|
+
const m = Q(e), u = t && Object.keys(t);
|
|
1224
|
+
if (!t || u && !u.length)
|
|
1215
1225
|
return [...m];
|
|
1216
|
-
const y =
|
|
1226
|
+
const y = z(m);
|
|
1217
1227
|
if (!t.origin) {
|
|
1218
|
-
const { origin: M } =
|
|
1228
|
+
const { origin: M } = mt;
|
|
1219
1229
|
Object.assign(t, { origin: M });
|
|
1220
1230
|
}
|
|
1221
|
-
const g =
|
|
1231
|
+
const g = Ee(t), { origin: f } = t, h = { ...ut };
|
|
1222
1232
|
let x = [], p = 0, b = "", A = [];
|
|
1223
1233
|
const d = [];
|
|
1224
1234
|
if (!g.isIdentity) {
|
|
1225
1235
|
for (s = 0, o = m.length; s < o; s += 1) {
|
|
1226
|
-
x = m[s], m[s] && ([b] = x), d[s] = b, b === "A" && (x = ot(y[s],
|
|
1236
|
+
x = m[s], m[s] && ([b] = x), d[s] = b, b === "A" && (x = ot(y[s], h), m[s] = ot(y[s], h), Mt(m, d, s), y[s] = ot(y[s], h), Mt(y, d, s), o = Math.max(m.length, y.length)), x = y[s], p = x.length, h.x1 = +x[p - 2], h.y1 = +x[p - 1], h.x2 = +x[p - 4] || h.x1, h.y2 = +x[p - 3] || h.y1;
|
|
1227
1237
|
const M = {
|
|
1228
1238
|
s: m[s],
|
|
1229
1239
|
c: m[s][0],
|
|
1230
|
-
x:
|
|
1231
|
-
y:
|
|
1240
|
+
x: h.x1,
|
|
1241
|
+
y: h.y1
|
|
1232
1242
|
};
|
|
1233
1243
|
A = [...A, M];
|
|
1234
1244
|
}
|
|
1235
1245
|
return A.map((M) => {
|
|
1236
1246
|
if (b = M.c, x = M.s, b === "L" || b === "H" || b === "V")
|
|
1237
|
-
return [l, c] = Ot(g, [M.x, M.y],
|
|
1247
|
+
return [l, c] = Ot(g, [M.x, M.y], f), n !== l && r !== c ? x = ["L", l, c] : r === c ? x = ["H", l] : n === l && (x = ["V", c]), n = l, r = c, x;
|
|
1238
1248
|
for (i = 1, a = x.length; i < a; i += 2)
|
|
1239
|
-
[n, r] = Ot(g, [+x[i], +x[i + 1]],
|
|
1249
|
+
[n, r] = Ot(g, [+x[i], +x[i + 1]], f), x[i] = n, x[i + 1] = r;
|
|
1240
1250
|
return x;
|
|
1241
1251
|
});
|
|
1242
1252
|
}
|
|
1243
1253
|
return [...m];
|
|
1244
|
-
},
|
|
1245
|
-
const n = e.slice(0, 2), r = e.slice(2, 4), s = e.slice(4, 6), i = e.slice(6, 8), o =
|
|
1254
|
+
}, ze = (e) => {
|
|
1255
|
+
const n = e.slice(0, 2), r = e.slice(2, 4), s = e.slice(4, 6), i = e.slice(6, 8), o = j(n, r, 0.5), a = j(r, s, 0.5), l = j(s, i, 0.5), c = j(o, a, 0.5), m = j(a, l, 0.5), u = j(c, m, 0.5);
|
|
1246
1256
|
return [
|
|
1247
|
-
["C", ...o, ...c, ...
|
|
1257
|
+
["C", ...o, ...c, ...u],
|
|
1248
1258
|
["C", ...m, ...l, ...i]
|
|
1249
1259
|
];
|
|
1250
1260
|
};
|
|
@@ -1257,27 +1267,27 @@ class w {
|
|
|
1257
1267
|
constructor(t, n) {
|
|
1258
1268
|
const r = n || {}, s = typeof t > "u";
|
|
1259
1269
|
if (s || !t.length)
|
|
1260
|
-
throw TypeError(`${
|
|
1261
|
-
const i =
|
|
1270
|
+
throw TypeError(`${k}: "pathValue" is ${s ? "undefined" : "empty"}`);
|
|
1271
|
+
const i = Z(t);
|
|
1262
1272
|
this.segments = i;
|
|
1263
|
-
const { width: o, height: a, cx: l, cy: c, cz: m } = this.getBBox(), { round:
|
|
1273
|
+
const { width: o, height: a, cx: l, cy: c, cz: m } = this.getBBox(), { round: u, origin: y } = r;
|
|
1264
1274
|
let g;
|
|
1265
|
-
if (
|
|
1266
|
-
const
|
|
1267
|
-
g =
|
|
1275
|
+
if (u === "auto") {
|
|
1276
|
+
const h = `${Math.floor(Math.max(o, a))}`.length;
|
|
1277
|
+
g = h >= 4 ? 0 : 4 - h;
|
|
1268
1278
|
} else
|
|
1269
|
-
Number.isInteger(
|
|
1270
|
-
let
|
|
1279
|
+
Number.isInteger(u) || u === "off" ? g = u : g = mt.round;
|
|
1280
|
+
let f;
|
|
1271
1281
|
if (Array.isArray(y) && y.length >= 2) {
|
|
1272
|
-
const [
|
|
1273
|
-
|
|
1274
|
-
Number.isNaN(
|
|
1282
|
+
const [h, x, p] = y.map(Number);
|
|
1283
|
+
f = [
|
|
1284
|
+
Number.isNaN(h) ? l : h,
|
|
1275
1285
|
Number.isNaN(x) ? c : x,
|
|
1276
1286
|
Number.isNaN(p) ? m : p
|
|
1277
1287
|
];
|
|
1278
1288
|
} else
|
|
1279
|
-
|
|
1280
|
-
return this.round = g, this.origin =
|
|
1289
|
+
f = [l, c, m];
|
|
1290
|
+
return this.round = g, this.origin = f, this;
|
|
1281
1291
|
}
|
|
1282
1292
|
/**
|
|
1283
1293
|
* Returns the path bounding box, equivalent to native `path.getBBox()`.
|
|
@@ -1286,7 +1296,7 @@ class w {
|
|
|
1286
1296
|
* @returns the pathBBox
|
|
1287
1297
|
*/
|
|
1288
1298
|
getBBox() {
|
|
1289
|
-
return
|
|
1299
|
+
return kt(this.segments);
|
|
1290
1300
|
}
|
|
1291
1301
|
/**
|
|
1292
1302
|
* Returns the total path length, equivalent to native `path.getTotalLength()`.
|
|
@@ -1295,7 +1305,7 @@ class w {
|
|
|
1295
1305
|
* @returns the path total length
|
|
1296
1306
|
*/
|
|
1297
1307
|
getTotalLength() {
|
|
1298
|
-
return
|
|
1308
|
+
return X(this.segments);
|
|
1299
1309
|
}
|
|
1300
1310
|
/**
|
|
1301
1311
|
* Returns an `{x,y}` point in the path stroke at a given length,
|
|
@@ -1306,7 +1316,7 @@ class w {
|
|
|
1306
1316
|
* @returns the requested point
|
|
1307
1317
|
*/
|
|
1308
1318
|
getPointAtLength(t) {
|
|
1309
|
-
return
|
|
1319
|
+
return K(this.segments, t);
|
|
1310
1320
|
}
|
|
1311
1321
|
/**
|
|
1312
1322
|
* Convert path to absolute values
|
|
@@ -1315,7 +1325,7 @@ class w {
|
|
|
1315
1325
|
*/
|
|
1316
1326
|
toAbsolute() {
|
|
1317
1327
|
const { segments: t } = this;
|
|
1318
|
-
return this.segments =
|
|
1328
|
+
return this.segments = Q(t), this;
|
|
1319
1329
|
}
|
|
1320
1330
|
/**
|
|
1321
1331
|
* Convert path to relative values
|
|
@@ -1324,7 +1334,7 @@ class w {
|
|
|
1324
1334
|
*/
|
|
1325
1335
|
toRelative() {
|
|
1326
1336
|
const { segments: t } = this;
|
|
1327
|
-
return this.segments =
|
|
1337
|
+
return this.segments = Nt(t), this;
|
|
1328
1338
|
}
|
|
1329
1339
|
/**
|
|
1330
1340
|
* Convert path to cubic-bezier values. In addition, un-necessary `Z`
|
|
@@ -1344,7 +1354,7 @@ class w {
|
|
|
1344
1354
|
*/
|
|
1345
1355
|
reverse(t) {
|
|
1346
1356
|
this.toAbsolute();
|
|
1347
|
-
const { segments: n } = this, r =
|
|
1357
|
+
const { segments: n } = this, r = $t(n), s = r.length > 1 ? r : !1, i = s ? [...s].map((a, l) => t ? l ? it(a) : [...a] : it(a)) : [...n];
|
|
1348
1358
|
let o = [];
|
|
1349
1359
|
return s ? o = i.flat(1) : o = t ? n : it(n), this.segments = [...o], this;
|
|
1350
1360
|
}
|
|
@@ -1357,7 +1367,7 @@ class w {
|
|
|
1357
1367
|
*/
|
|
1358
1368
|
normalize() {
|
|
1359
1369
|
const { segments: t } = this;
|
|
1360
|
-
return this.segments =
|
|
1370
|
+
return this.segments = z(t), this;
|
|
1361
1371
|
}
|
|
1362
1372
|
/**
|
|
1363
1373
|
* Optimize `pathArray` values:
|
|
@@ -1369,7 +1379,7 @@ class w {
|
|
|
1369
1379
|
*/
|
|
1370
1380
|
optimize() {
|
|
1371
1381
|
const { segments: t } = this;
|
|
1372
|
-
return this.segments =
|
|
1382
|
+
return this.segments = qt(t, this.round), this;
|
|
1373
1383
|
}
|
|
1374
1384
|
/**
|
|
1375
1385
|
* Transform path using values from an `Object` defined as `transformObject`.
|
|
@@ -1394,7 +1404,7 @@ class w {
|
|
|
1394
1404
|
o.origin = [Number.isNaN(l) ? r : l, Number.isNaN(c) ? s : c, m || i];
|
|
1395
1405
|
} else
|
|
1396
1406
|
o.origin = [r, s, i];
|
|
1397
|
-
return this.segments =
|
|
1407
|
+
return this.segments = Et(n, o), this;
|
|
1398
1408
|
}
|
|
1399
1409
|
/**
|
|
1400
1410
|
* Rotate path 180deg vertically
|
|
@@ -1420,11 +1430,11 @@ class w {
|
|
|
1420
1430
|
* @return the path string
|
|
1421
1431
|
*/
|
|
1422
1432
|
toString() {
|
|
1423
|
-
return
|
|
1433
|
+
return At(this.segments, this.round);
|
|
1424
1434
|
}
|
|
1425
1435
|
}
|
|
1426
1436
|
// bring main utilities to front
|
|
1427
|
-
N(w, "CSSMatrix", v), N(w, "getPathBBox",
|
|
1437
|
+
N(w, "CSSMatrix", v), N(w, "getPathBBox", kt), N(w, "getPathArea", Vt), N(w, "getTotalLength", X), N(w, "getDrawDirection", Ae), N(w, "getPointAtLength", K), N(w, "pathLengthFactory", ft), N(w, "getPropertiesAtLength", Pt), N(w, "getPropertiesAtPoint", yt), N(w, "polygonLength", le), N(w, "polygonArea", ce), N(w, "getClosestPoint", Ne), N(w, "getSegmentOfPoint", we), N(w, "getSegmentAtLength", ve), N(w, "isPointInStroke", Pe), N(w, "isValidPath", Kt), N(w, "isPathArray", _), N(w, "isAbsoluteArray", wt), N(w, "isRelativeArray", _t), N(w, "isCurveArray", Jt), N(w, "isNormalizedArray", vt), N(w, "shapeToPath", $e), N(w, "shapeToPathArray", Wt), N(w, "parsePathString", Z), N(w, "roundPath", at), N(w, "splitPath", $t), N(w, "splitCubic", ze), N(w, "optimizePath", qt), N(w, "reverseCurve", Oe), N(w, "reversePath", it), N(w, "normalizePath", z), N(w, "transformPath", Et), N(w, "pathToAbsolute", Q), N(w, "pathToRelative", Nt), N(w, "pathToCurve", ct), N(w, "pathToString", At);
|
|
1428
1438
|
export {
|
|
1429
1439
|
w as default
|
|
1430
1440
|
};
|