svg-path-commander 0.1.11-alpha1 → 0.1.11-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/dist/svg-path-commander.esm.js +129 -143
- package/dist/svg-path-commander.esm.min.js +2 -2
- package/dist/svg-path-commander.js +131 -148
- package/dist/svg-path-commander.min.js +2 -2
- package/package.json +2 -2
- package/src/svg-path-commander.js +2 -2
- package/src/util/shapeToPath.js +1 -4
- package/types/index.d.ts +33 -72
- package/types/process/getSVGMatrix.d.ts +1 -1
- package/types/process/projection2d.d.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* SVGPathCommander v0.1.
|
|
2
|
+
* SVGPathCommander v0.1.11alpha2 (http://thednp.github.io/svg-path-commander)
|
|
3
3
|
* Copyright 2021 © thednp
|
|
4
4
|
* Licensed under MIT (https://github.com/thednp/svg-path-commander/blob/master/LICENSE)
|
|
5
5
|
*/
|
|
@@ -1236,14 +1236,13 @@ function fixArc(path, allPathCommands, i) {
|
|
|
1236
1236
|
}
|
|
1237
1237
|
|
|
1238
1238
|
// DOMMatrix Static methods
|
|
1239
|
-
// * `fromFloat64Array` and `fromFloat32Array
|
|
1240
|
-
// * `fromArray` a more simple implementation, should also accept
|
|
1241
|
-
// * `fromMatrix` load values from another CSSMatrix/DOMMatrix instance;
|
|
1242
|
-
// * `fromString` parses and loads values from any valid CSS transform string.
|
|
1239
|
+
// * `fromFloat64Array` and `fromFloat32Array are not implemented;
|
|
1240
|
+
// * `fromArray` is a more simple implementation, should also accept Float[32/64]Array;
|
|
1241
|
+
// * `fromMatrix` load values from another CSSMatrix/DOMMatrix instance or JSON object;
|
|
1242
|
+
// * `fromString` parses and loads values from any valid CSS transform string (TransformList).
|
|
1243
1243
|
|
|
1244
1244
|
/**
|
|
1245
|
-
* Creates a new mutable `CSSMatrix`
|
|
1246
|
-
*
|
|
1245
|
+
* Creates a new mutable `CSSMatrix` instance given an array of 16/6 floating point values.
|
|
1247
1246
|
* This static method invalidates arrays that contain non-number elements.
|
|
1248
1247
|
*
|
|
1249
1248
|
* If the array has six values, the result is a 2D matrix; if the array has 16 values,
|
|
@@ -1253,12 +1252,12 @@ function fixArc(path, allPathCommands, i) {
|
|
|
1253
1252
|
* @return {CSSMatrix} the resulted matrix.
|
|
1254
1253
|
*/
|
|
1255
1254
|
function fromArray(array) {
|
|
1256
|
-
if (!array.every((n) => !Number.isNaN(n))) {
|
|
1257
|
-
throw TypeError(`CSSMatrix: "${array}" must only have numbers.`);
|
|
1258
|
-
}
|
|
1259
1255
|
const m = new CSSMatrix();
|
|
1260
1256
|
const a = Array.from(array);
|
|
1261
1257
|
|
|
1258
|
+
if (!a.every((n) => !Number.isNaN(n))) {
|
|
1259
|
+
throw TypeError(`CSSMatrix: "${array}" must only have numbers.`);
|
|
1260
|
+
}
|
|
1262
1261
|
if (a.length === 16) {
|
|
1263
1262
|
const [m11, m12, m13, m14,
|
|
1264
1263
|
m21, m22, m23, m24,
|
|
@@ -1325,17 +1324,12 @@ function fromArray(array) {
|
|
|
1325
1324
|
* Creates a new mutable `CSSMatrix` instance given an existing matrix or a
|
|
1326
1325
|
* `DOMMatrix` instance which provides the values for its properties.
|
|
1327
1326
|
*
|
|
1328
|
-
* @param {CSSMatrix | DOMMatrix |
|
|
1327
|
+
* @param {CSSMatrix | DOMMatrix | CSSMatrix.JSONMatrix} m the source matrix to feed values from.
|
|
1329
1328
|
* @return {CSSMatrix} the resulted matrix.
|
|
1330
1329
|
*/
|
|
1331
1330
|
function fromMatrix(m) {
|
|
1332
|
-
const keys =
|
|
1333
|
-
|
|
1334
|
-
'm21', 'm22', 'm23', 'm24',
|
|
1335
|
-
'm31', 'm32', 'm33', 'm34',
|
|
1336
|
-
'm41', 'm42', 'm43', 'm44'];
|
|
1337
|
-
if ([CSSMatrix, DOMMatrix].some((x) => m instanceof x)
|
|
1338
|
-
|| (typeof m === 'object' && keys.every((k) => k in m))) {
|
|
1331
|
+
const keys = Object.keys(new CSSMatrix());
|
|
1332
|
+
if (typeof m === 'object' && keys.every((k) => k in m)) {
|
|
1339
1333
|
return fromArray(
|
|
1340
1334
|
[m.m11, m.m12, m.m13, m.m14,
|
|
1341
1335
|
m.m21, m.m22, m.m23, m.m24,
|
|
@@ -1343,11 +1337,12 @@ function fromMatrix(m) {
|
|
|
1343
1337
|
m.m41, m.m42, m.m43, m.m44],
|
|
1344
1338
|
);
|
|
1345
1339
|
}
|
|
1346
|
-
throw TypeError(`CSSMatrix: "${m}" is not a DOMMatrix / CSSMatrix compatible object.`);
|
|
1340
|
+
throw TypeError(`CSSMatrix: "${m}" is not a DOMMatrix / CSSMatrix / JSON compatible object.`);
|
|
1347
1341
|
}
|
|
1348
1342
|
|
|
1349
1343
|
/**
|
|
1350
|
-
* Creates a new mutable `CSSMatrix`
|
|
1344
|
+
* Creates a new mutable `CSSMatrix` given any valid CSS transform string,
|
|
1345
|
+
* or what we call `TransformList`:
|
|
1351
1346
|
*
|
|
1352
1347
|
* * `matrix(a, b, c, d, e, f)` - valid matrix() transform function
|
|
1353
1348
|
* * `matrix3d(m11, m12, m13, ...m44)` - valid matrix3d() transform function
|
|
@@ -1365,65 +1360,61 @@ function fromString(source) {
|
|
|
1365
1360
|
const str = String(source).replace(/\s/g, '');
|
|
1366
1361
|
let m = new CSSMatrix();
|
|
1367
1362
|
const invalidStringError = `CSSMatrix: invalid transform string "${source}"`;
|
|
1368
|
-
|
|
1369
|
-
// const
|
|
1370
|
-
//
|
|
1371
|
-
//
|
|
1372
|
-
//
|
|
1373
|
-
//
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1363
|
+
|
|
1364
|
+
// const px = ['perspective'];
|
|
1365
|
+
// const length = ['translate', 'translate3d', 'translateX', 'translateY', 'translateZ'];
|
|
1366
|
+
// const deg = ['rotate', 'rotate3d', 'rotateX', 'rotateY', 'rotateZ', 'skew', 'skewX', 'skewY'];
|
|
1367
|
+
// const abs = ['scale', 'scale3d', 'matrix', 'matrix3d'];
|
|
1368
|
+
// const transformFunctions = px.concat(length, deg, abs);
|
|
1369
|
+
|
|
1370
|
+
str.split(')').filter((f) => f).forEach((tf) => {
|
|
1371
|
+
const [prop, value] = tf.split('(');
|
|
1372
|
+
|
|
1373
|
+
// invalidate empty string
|
|
1374
|
+
if (!value) throw TypeError(invalidStringError);
|
|
1380
1375
|
|
|
1381
1376
|
const components = value.split(',')
|
|
1382
1377
|
.map((n) => (n.includes('rad') ? parseFloat(n) * (180 / Math.PI) : parseFloat(n)));
|
|
1383
|
-
const [x, y, z, a] = components;
|
|
1384
|
-
|
|
1385
|
-
// don't add perspective if is2D
|
|
1386
|
-
if (is2D && (prop === 'matrix3d' // only modify is2D once
|
|
1387
|
-
|| (prop === 'rotate3d' && [x, y].every((n) => !Number.isNaN(+n) && n !== 0) && a)
|
|
1388
|
-
|| (['rotateX', 'rotateY'].includes(prop) && x)
|
|
1389
|
-
|| (prop === 'translate3d' && [x, y, z].every((n) => !Number.isNaN(+n)) && z)
|
|
1390
|
-
|| (prop === 'scale3d' && [x, y, z].every((n) => !Number.isNaN(+n) && n !== x))
|
|
1391
|
-
)) {
|
|
1392
|
-
is2D = false;
|
|
1393
|
-
}
|
|
1394
|
-
return { prop, components };
|
|
1395
|
-
});
|
|
1396
1378
|
|
|
1397
|
-
tramsformObject.forEach((tf) => {
|
|
1398
|
-
const { prop, components } = tf;
|
|
1399
1379
|
const [x, y, z, a] = components;
|
|
1400
1380
|
const xyz = [x, y, z];
|
|
1401
1381
|
const xyza = [x, y, z, a];
|
|
1402
1382
|
|
|
1403
|
-
|
|
1383
|
+
// single number value expected
|
|
1384
|
+
if (prop === 'perspective' && x && [y, z].every((n) => n === undefined)) {
|
|
1404
1385
|
m.m34 = -1 / x;
|
|
1405
|
-
|
|
1386
|
+
// 6/16 number values expected
|
|
1387
|
+
} else if (prop.includes('matrix') && [6, 16].includes(components.length)
|
|
1388
|
+
&& components.every((n) => !Number.isNaN(+n))) {
|
|
1406
1389
|
const values = components.map((n) => (Math.abs(n) < 1e-6 ? 0 : n));
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1390
|
+
m = m.multiply(fromArray(values));
|
|
1391
|
+
// 3 values expected
|
|
1392
|
+
} else if (prop === 'translate3d' && xyz.every((n) => !Number.isNaN(+n))) {
|
|
1393
|
+
m = m.translate(x, y, z);
|
|
1394
|
+
// single/double number value(s) expected
|
|
1395
|
+
} else if (prop === 'translate' && x && z === undefined) {
|
|
1396
|
+
m = m.translate(x, y || 0, 0);
|
|
1397
|
+
// all 4 values expected
|
|
1412
1398
|
} else if (prop === 'rotate3d' && xyza.every((n) => !Number.isNaN(+n)) && a) {
|
|
1413
1399
|
m = m.rotateAxisAngle(x, y, z, a);
|
|
1400
|
+
// single value expected
|
|
1401
|
+
} else if (prop === 'rotate' && x && [y, z].every((n) => n === undefined)) {
|
|
1402
|
+
m = m.rotate(0, 0, x);
|
|
1403
|
+
// 4 values expected
|
|
1414
1404
|
} else if (prop === 'scale3d' && xyz.every((n) => !Number.isNaN(+n)) && xyz.some((n) => n !== 1)) {
|
|
1415
1405
|
m = m.scale(x, y, z);
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
} else if (prop === 'scale' && !Number.isNaN(x) && x !== 1) {
|
|
1406
|
+
// single value expected
|
|
1407
|
+
} else if (prop === 'scale' && !Number.isNaN(x) && x !== 1 && z === undefined) {
|
|
1419
1408
|
const nosy = Number.isNaN(+y);
|
|
1420
1409
|
const sy = nosy ? x : y;
|
|
1421
1410
|
m = m.scale(x, sy, 1);
|
|
1422
|
-
|
|
1423
|
-
|
|
1411
|
+
// single/double value expected
|
|
1412
|
+
} else if (prop === 'skew' && x && z === undefined) {
|
|
1413
|
+
m = m.skewX(x);
|
|
1424
1414
|
m = y ? m.skewY(y) : m;
|
|
1425
|
-
} else if (/[XYZ]/.test(prop) && x)
|
|
1426
|
-
|
|
1415
|
+
} else if (/[XYZ]/.test(prop) && x && [y, z].every((n) => n === undefined) // a single value expected
|
|
1416
|
+
&& ['translate', 'rotate', 'scale', 'skew'].some((p) => prop.includes(p))) {
|
|
1417
|
+
if (['skewX', 'skewY'].includes(prop)) {
|
|
1427
1418
|
// @ts-ignore unfortunately
|
|
1428
1419
|
m = m[prop](x);
|
|
1429
1420
|
} else {
|
|
@@ -1588,7 +1579,8 @@ function RotateAxisAngle(x, y, z, alpha) {
|
|
|
1588
1579
|
|
|
1589
1580
|
/**
|
|
1590
1581
|
* Creates a new `CSSMatrix` for the scale matrix and returns it.
|
|
1591
|
-
* This method is equivalent to the CSS `scale3d()` function
|
|
1582
|
+
* This method is equivalent to the CSS `scale3d()` function, except it doesn't
|
|
1583
|
+
* accept {x, y, z} transform origin parameters.
|
|
1592
1584
|
*
|
|
1593
1585
|
* https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/scale3d
|
|
1594
1586
|
*
|
|
@@ -1683,18 +1675,18 @@ function Multiply(m1, m2) {
|
|
|
1683
1675
|
}
|
|
1684
1676
|
|
|
1685
1677
|
/**
|
|
1686
|
-
* Creates and returns a new `DOMMatrix` compatible
|
|
1687
|
-
* with equivalent instance
|
|
1678
|
+
* Creates and returns a new `DOMMatrix` compatible instance
|
|
1679
|
+
* with equivalent instance.
|
|
1688
1680
|
*
|
|
1689
1681
|
* https://developer.mozilla.org/en-US/docs/Web/API/DOMMatrix
|
|
1690
1682
|
* https://github.com/thednp/DOMMatrix/
|
|
1683
|
+
* @class
|
|
1691
1684
|
*/
|
|
1692
1685
|
|
|
1693
1686
|
class CSSMatrix {
|
|
1694
1687
|
/**
|
|
1695
1688
|
* @constructor
|
|
1696
1689
|
* @param {any} args accepts all parameter configurations:
|
|
1697
|
-
*
|
|
1698
1690
|
* * valid CSS transform string,
|
|
1699
1691
|
* * CSSMatrix/DOMMatrix instance,
|
|
1700
1692
|
* * a 6/16 elements *Array*.
|
|
@@ -1712,15 +1704,8 @@ class CSSMatrix {
|
|
|
1712
1704
|
m.m41 = 0; m.m42 = 0; m.m43 = 0; m.m44 = 1;
|
|
1713
1705
|
|
|
1714
1706
|
if (args && args.length) {
|
|
1715
|
-
|
|
1707
|
+
const ARGS = [16, 6].some((l) => l === args.length) ? args : args[0];
|
|
1716
1708
|
|
|
1717
|
-
if (args instanceof Array) {
|
|
1718
|
-
if ((args[0] instanceof Array && [16, 6].includes(args[0].length))
|
|
1719
|
-
|| typeof args[0] === 'string'
|
|
1720
|
-
|| [CSSMatrix, DOMMatrix].some((x) => args[0] instanceof x)) {
|
|
1721
|
-
[ARGS] = args;
|
|
1722
|
-
}
|
|
1723
|
-
}
|
|
1724
1709
|
return m.setMatrixValue(ARGS);
|
|
1725
1710
|
}
|
|
1726
1711
|
return m;
|
|
@@ -1787,47 +1772,31 @@ class CSSMatrix {
|
|
|
1787
1772
|
setMatrixValue(source) {
|
|
1788
1773
|
const m = this;
|
|
1789
1774
|
|
|
1790
|
-
// new CSSMatrix(CSSMatrix | DOMMatrix)
|
|
1791
|
-
if ([DOMMatrix, CSSMatrix].some((x) => source instanceof x)) {
|
|
1792
|
-
// @ts-ignore
|
|
1793
|
-
return fromMatrix(source);
|
|
1794
|
-
// CSS transform string source
|
|
1795
|
-
} if (typeof source === 'string' && source.length && source !== 'none') {
|
|
1796
|
-
return fromString(source);
|
|
1797
1775
|
// [Arguments list | Array] come here
|
|
1798
|
-
|
|
1776
|
+
if ([Array, Float64Array, Float32Array].some((a) => source instanceof a)) {
|
|
1799
1777
|
return fromArray(source);
|
|
1800
1778
|
}
|
|
1779
|
+
// CSS transform string source - TransformList
|
|
1780
|
+
if (typeof source === 'string' && source.length && source !== 'none') {
|
|
1781
|
+
return fromString(source);
|
|
1782
|
+
}
|
|
1783
|
+
// new CSSMatrix(CSSMatrix | DOMMatrix | JSON)
|
|
1784
|
+
if (typeof source === 'object') {
|
|
1785
|
+
return fromMatrix(source);
|
|
1786
|
+
}
|
|
1801
1787
|
return m;
|
|
1802
1788
|
}
|
|
1803
1789
|
|
|
1804
1790
|
/**
|
|
1805
|
-
*
|
|
1806
|
-
*
|
|
1807
|
-
*
|
|
1808
|
-
* matrix3d *matrix3d(m11, m12, m13, m14, m21, ...)*
|
|
1809
|
-
* matrix *matrix(a, b, c, d, e, f)*
|
|
1810
|
-
*
|
|
1811
|
-
* @return {string} a string representation of the matrix
|
|
1812
|
-
*/
|
|
1813
|
-
toString() {
|
|
1814
|
-
const m = this;
|
|
1815
|
-
const values = m.toArray().join(',');
|
|
1816
|
-
const type = m.is2D ? 'matrix' : 'matrix3d';
|
|
1817
|
-
return `${type}(${values})`;
|
|
1818
|
-
}
|
|
1819
|
-
|
|
1820
|
-
/**
|
|
1821
|
-
* Returns an *Array* containing all 16 elements which comprise the matrix.
|
|
1822
|
-
* The method can return either the elements.
|
|
1823
|
-
*
|
|
1824
|
-
* Other methods make use of this method to feed their output values from this matrix.
|
|
1791
|
+
* Returns an *Array* containing elements which comprise the matrix.
|
|
1792
|
+
* The method can return either the 16 elements or the 6 elements
|
|
1793
|
+
* depending on the value of the `is2D` property.
|
|
1825
1794
|
*
|
|
1826
1795
|
* @return {number[]} an *Array* representation of the matrix
|
|
1827
1796
|
*/
|
|
1828
1797
|
toArray() {
|
|
1829
1798
|
const m = this;
|
|
1830
|
-
const
|
|
1799
|
+
const pow = (10 ** 6);
|
|
1831
1800
|
let result;
|
|
1832
1801
|
|
|
1833
1802
|
if (m.is2D) {
|
|
@@ -1840,21 +1809,39 @@ class CSSMatrix {
|
|
|
1840
1809
|
}
|
|
1841
1810
|
// clean up the numbers
|
|
1842
1811
|
// eslint-disable-next-line -- no-bitwise
|
|
1843
|
-
return result.map((n) => (Math.abs(n) < 1e-6 ? 0 : ((n *
|
|
1812
|
+
return result.map((n) => (Math.abs(n) < 1e-6 ? 0 : ((n * pow) >> 0) / pow));
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
/**
|
|
1816
|
+
* Creates and returns a string representation of the matrix in `CSS` matrix syntax,
|
|
1817
|
+
* using the appropriate `CSS` matrix notation.
|
|
1818
|
+
*
|
|
1819
|
+
* matrix3d *matrix3d(m11, m12, m13, m14, m21, ...)*
|
|
1820
|
+
* matrix *matrix(a, b, c, d, e, f)*
|
|
1821
|
+
*
|
|
1822
|
+
* @return {string} a string representation of the matrix
|
|
1823
|
+
*/
|
|
1824
|
+
toString() {
|
|
1825
|
+
const m = this;
|
|
1826
|
+
const values = m.toArray();
|
|
1827
|
+
const type = m.is2D ? 'matrix' : 'matrix3d';
|
|
1828
|
+
return `${type}(${values})`;
|
|
1844
1829
|
}
|
|
1845
1830
|
|
|
1846
1831
|
/**
|
|
1847
1832
|
* Returns a JSON representation of the `CSSMatrix` instance, a standard *Object*
|
|
1848
|
-
* that includes `{a,b,c,d,e,f}` and `{m11,m12,m13,..m44}` properties
|
|
1849
|
-
*
|
|
1833
|
+
* that includes `{a,b,c,d,e,f}` and `{m11,m12,m13,..m44}` properties as well
|
|
1834
|
+
* as the `is2D` & `isIdentity` properties.
|
|
1850
1835
|
*
|
|
1851
1836
|
* The result can also be used as a second parameter for the `fromMatrix` static method
|
|
1852
|
-
* to load values into
|
|
1837
|
+
* to load values into another matrix instance.
|
|
1853
1838
|
*
|
|
1854
|
-
* @return {
|
|
1839
|
+
* @return {CSSMatrix.JSONMatrix} an *Object* with all matrix values.
|
|
1855
1840
|
*/
|
|
1856
1841
|
toJSON() {
|
|
1857
|
-
|
|
1842
|
+
const m = this;
|
|
1843
|
+
const { is2D, isIdentity } = m;
|
|
1844
|
+
return { ...m, is2D, isIdentity };
|
|
1858
1845
|
}
|
|
1859
1846
|
|
|
1860
1847
|
/**
|
|
@@ -1862,11 +1849,10 @@ class CSSMatrix {
|
|
|
1862
1849
|
* matrix multiplied by the passed matrix, with the passed matrix to the right.
|
|
1863
1850
|
* This matrix is not modified.
|
|
1864
1851
|
*
|
|
1865
|
-
* @param {CSSMatrix | DOMMatrix |
|
|
1852
|
+
* @param {CSSMatrix | DOMMatrix | CSSMatrix.JSONMatrix} m2 CSSMatrix
|
|
1866
1853
|
* @return {CSSMatrix} The resulted matrix.
|
|
1867
1854
|
*/
|
|
1868
1855
|
multiply(m2) {
|
|
1869
|
-
// @ts-ignore - we only access [m11, m12, ... m44] values
|
|
1870
1856
|
return Multiply(this, m2);
|
|
1871
1857
|
}
|
|
1872
1858
|
|
|
@@ -1877,16 +1863,16 @@ class CSSMatrix {
|
|
|
1877
1863
|
* modified.
|
|
1878
1864
|
*
|
|
1879
1865
|
* @param {number} x X component of the translation value.
|
|
1880
|
-
* @param {number
|
|
1881
|
-
* @param {number
|
|
1866
|
+
* @param {number=} y Y component of the translation value.
|
|
1867
|
+
* @param {number=} z Z component of the translation value.
|
|
1882
1868
|
* @return {CSSMatrix} The resulted matrix
|
|
1883
1869
|
*/
|
|
1884
1870
|
translate(x, y, z) {
|
|
1885
1871
|
const X = x;
|
|
1886
1872
|
let Y = y;
|
|
1887
1873
|
let Z = z;
|
|
1888
|
-
if (Z
|
|
1889
|
-
if (Y
|
|
1874
|
+
if (Z === undefined) Z = 0;
|
|
1875
|
+
if (Y === undefined) Y = 0;
|
|
1890
1876
|
return Multiply(this, Translate(X, Y, Z));
|
|
1891
1877
|
}
|
|
1892
1878
|
|
|
@@ -1897,16 +1883,16 @@ class CSSMatrix {
|
|
|
1897
1883
|
* component value is used in its place. This matrix is not modified.
|
|
1898
1884
|
*
|
|
1899
1885
|
* @param {number} x The X component of the scale value.
|
|
1900
|
-
* @param {number
|
|
1901
|
-
* @param {number
|
|
1886
|
+
* @param {number=} y The Y component of the scale value.
|
|
1887
|
+
* @param {number=} z The Z component of the scale value.
|
|
1902
1888
|
* @return {CSSMatrix} The resulted matrix
|
|
1903
1889
|
*/
|
|
1904
1890
|
scale(x, y, z) {
|
|
1905
1891
|
const X = x;
|
|
1906
1892
|
let Y = y;
|
|
1907
1893
|
let Z = z;
|
|
1908
|
-
if (Y
|
|
1909
|
-
if (Z
|
|
1894
|
+
if (Y === undefined) Y = x;
|
|
1895
|
+
if (Z === undefined) Z = 1; // Z must be 1 if undefined
|
|
1910
1896
|
|
|
1911
1897
|
return Multiply(this, Scale(X, Y, Z));
|
|
1912
1898
|
}
|
|
@@ -1919,16 +1905,16 @@ class CSSMatrix {
|
|
|
1919
1905
|
* rotation values are in degrees. This matrix is not modified.
|
|
1920
1906
|
*
|
|
1921
1907
|
* @param {number} rx The X component of the rotation, or Z if Y and Z are null.
|
|
1922
|
-
* @param {number
|
|
1923
|
-
* @param {number
|
|
1908
|
+
* @param {number=} ry The (optional) Y component of the rotation value.
|
|
1909
|
+
* @param {number=} rz The (optional) Z component of the rotation value.
|
|
1924
1910
|
* @return {CSSMatrix} The resulted matrix
|
|
1925
1911
|
*/
|
|
1926
1912
|
rotate(rx, ry, rz) {
|
|
1927
1913
|
let RX = rx;
|
|
1928
1914
|
let RY = ry;
|
|
1929
1915
|
let RZ = rz;
|
|
1930
|
-
if (RY
|
|
1931
|
-
if (RZ
|
|
1916
|
+
if (RY === undefined) RY = 0;
|
|
1917
|
+
if (RZ === undefined) { RZ = RX; RX = 0; }
|
|
1932
1918
|
return Multiply(this, Rotate(RX, RY, RZ));
|
|
1933
1919
|
}
|
|
1934
1920
|
|
|
@@ -1983,8 +1969,8 @@ class CSSMatrix {
|
|
|
1983
1969
|
*
|
|
1984
1970
|
* @copyright thednp © 2021
|
|
1985
1971
|
*
|
|
1986
|
-
* @param {
|
|
1987
|
-
* @return {
|
|
1972
|
+
* @param {CSSMatrix.PointTuple | DOMPoint} v Tuple or DOMPoint
|
|
1973
|
+
* @return {CSSMatrix.PointTuple} the resulting Tuple
|
|
1988
1974
|
*/
|
|
1989
1975
|
transformPoint(v) {
|
|
1990
1976
|
const M = this;
|
|
@@ -2006,8 +1992,8 @@ class CSSMatrix {
|
|
|
2006
1992
|
* {x,y,z,w} Tuple *Object* comprising the transformed vector.
|
|
2007
1993
|
* Neither the matrix nor the original vector are altered.
|
|
2008
1994
|
*
|
|
2009
|
-
* @param {
|
|
2010
|
-
* @return {
|
|
1995
|
+
* @param {CSSMatrix.PointTuple} t Tuple with `{x,y,z,w}` components
|
|
1996
|
+
* @return {CSSMatrix.PointTuple} the resulting Tuple
|
|
2011
1997
|
*/
|
|
2012
1998
|
transform(t) {
|
|
2013
1999
|
const m = this;
|
|
@@ -2026,16 +2012,19 @@ class CSSMatrix {
|
|
|
2026
2012
|
}
|
|
2027
2013
|
|
|
2028
2014
|
// Add Transform Functions to CSSMatrix object
|
|
2029
|
-
|
|
2030
|
-
CSSMatrix
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2015
|
+
// without creating a TypeScript namespace.
|
|
2016
|
+
Object.assign(CSSMatrix, {
|
|
2017
|
+
Translate,
|
|
2018
|
+
Rotate,
|
|
2019
|
+
RotateAxisAngle,
|
|
2020
|
+
Scale,
|
|
2021
|
+
SkewX,
|
|
2022
|
+
SkewY,
|
|
2023
|
+
Multiply,
|
|
2024
|
+
fromArray,
|
|
2025
|
+
fromMatrix,
|
|
2026
|
+
fromString,
|
|
2027
|
+
});
|
|
2039
2028
|
|
|
2040
2029
|
/**
|
|
2041
2030
|
* Returns a transformation matrix to apply to `<path>` elements.
|
|
@@ -2707,7 +2696,7 @@ const shapeParams = {
|
|
|
2707
2696
|
* Returns a new `pathArray` from line attributes.
|
|
2708
2697
|
*
|
|
2709
2698
|
* @param {SVGPathCommander.lineAttr} attr shape configuration
|
|
2710
|
-
* @
|
|
2699
|
+
* @returns {SVGPathCommander.pathArray} a new line `pathArray`
|
|
2711
2700
|
*/
|
|
2712
2701
|
function getLinePath(attr) {
|
|
2713
2702
|
const {
|
|
@@ -2838,9 +2827,6 @@ function shapeToPath(element, replace) {
|
|
|
2838
2827
|
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
2839
2828
|
const type = element.tagName;
|
|
2840
2829
|
const shapeAttrs = shapeParams[type];
|
|
2841
|
-
/** set config
|
|
2842
|
-
* @type {any}
|
|
2843
|
-
*/
|
|
2844
2830
|
const config = {};
|
|
2845
2831
|
config.type = type;
|
|
2846
2832
|
|
|
@@ -2896,7 +2882,7 @@ function reverseCurve(path) {
|
|
|
2896
2882
|
.concat(rotatedCurve.map((x) => ['C'].concat(x.slice(2))));
|
|
2897
2883
|
}
|
|
2898
2884
|
|
|
2899
|
-
var version = "0.1.
|
|
2885
|
+
var version = "0.1.11alpha2";
|
|
2900
2886
|
|
|
2901
2887
|
// @ts-ignore
|
|
2902
2888
|
|
|
@@ -3109,7 +3095,7 @@ class SVGPathCommander {
|
|
|
3109
3095
|
}
|
|
3110
3096
|
}
|
|
3111
3097
|
|
|
3112
|
-
//
|
|
3113
|
-
Object.
|
|
3098
|
+
// Export Util to global
|
|
3099
|
+
Object.assign(SVGPathCommander, Util);
|
|
3114
3100
|
|
|
3115
3101
|
export { SVGPathCommander as default };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// SVGPathCommander v0.1.
|
|
2
|
-
const t={origin:[0,0],decimals:4,round:1},e={a:7,c:6,h:1,l:2,m:2,r:4,q:4,s:4,t:2,v:1,z:0};function n(t){let n=t.pathValue[t.segmentStart],r=n.toLowerCase(),{data:s}=t;for("m"===r&&s.length>2&&(t.segments.push([n,s[0],s[1]]),s=s.slice(2),r="l",n="m"===n?"l":"L");s.length>=e[r]&&(t.segments.push([n].concat(s.splice(0,e[r]))),e[r]););}function r(t){const{index:e}=t,n=t.pathValue.charCodeAt(e);return 48===n?(t.param=0,void(t.index+=1)):49===n?(t.param=1,void(t.index+=1)):void(t.err=`Invalid path value: invalid Arc flag ${n}, expecting 0 or 1 at index ${e}`)}function s(t){return t>=48&&t<=57}function a(t){const{max:e,pathValue:n,index:r}=t;let a,i=r,c=!1,o=!1,m=!1,l=!1;if(i>=e)t.err=`Invalid path value at ${i}: missing param ${n[i]}`;else if(a=n.charCodeAt(i),43!==a&&45!==a||(i+=1,a=i<e?n.charCodeAt(i):0),s(a)||46===a){if(46!==a){if(c=48===a,i+=1,a=i<e?n.charCodeAt(i):0,c&&i<e&&a&&s(a))return void(t.err=`Invalid path value at index ${r}: ${n[r]} illegal number`);for(;i<e&&s(n.charCodeAt(i));)i+=1,o=!0;a=i<e?n.charCodeAt(i):0}if(46===a){for(l=!0,i+=1;s(n.charCodeAt(i));)i+=1,m=!0;a=i<e?n.charCodeAt(i):0}if(101===a||69===a){if(l&&!o&&!m)return void(t.err=`Invalid path value at index ${i}: ${n[i]} invalid float exponent`);if(i+=1,a=i<e?n.charCodeAt(i):0,43!==a&&45!==a||(i+=1),!(i<e&&s(n.charCodeAt(i))))return void(t.err=`Invalid path value at index ${i}: ${n[i]} invalid float exponent`);for(;i<e&&s(n.charCodeAt(i));)i+=1}t.index=i,t.param=+t.pathValue.slice(r,i)}else t.err=`Invalid path value at index ${i}: ${n[i]} is not a number`}function i(t){const{pathValue:e,max:n}=t;for(;t.index<n&&(10===(r=e.charCodeAt(t.index))||13===r||8232===r||8233===r||32===r||9===r||11===r||12===r||160===r||r>=5760&&[5760,6158,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8239,8287,12288,65279].indexOf(r)>=0);)t.index+=1;var r}function c(t){return t>=48&&t<=57||43===t||45===t||46===t}function o(t){const{max:s,pathValue:o,index:m}=t,l=o.charCodeAt(m),u=e[o[m].toLowerCase()];if(t.segmentStart=m,function(t){switch(32|t){case 109:case 122:case 108:case 104:case 118:case 99:case 115:case 113:case 116:case 97:return!0;default:return!1}}(l))if(t.index+=1,i(t),t.data=[],u){for(;;){for(let e=u;e>0;e-=1){if(97!=(32|l)||3!==e&&4!==e?a(t):r(t),t.err.length)return;t.data.push(t.param),i(t),t.index<s&&44===o.charCodeAt(t.index)&&(t.index+=1,i(t))}if(t.index>=t.max)break;if(!c(o.charCodeAt(t.index)))break}n(t)}else n(t);else t.err=`Invalid path value: ${o[m]} not a path command`}function m(t){return Array.isArray(t)?t.map(t=>Array.isArray(t)?m(t):Number.isNaN(+t)?t:+t):t}function l(t){this.segments=[],this.pathValue=t,this.max=t.length,this.index=0,this.param=0,this.segmentStart=0,this.data=[],this.err=""}function u(t){return Array.isArray(t)&&t.every(t=>{const n=t[0].toLowerCase();return e[n]===t.length-1&&/[achlmqstvz]/gi.test(n)})}function h(t){if(u(t))return m(t);const e=new l(""+t);for(i(e);e.index<e.max&&!e.err.length;)o(e);return e.err.length?e.segments=[]:e.segments.length&&("mM".includes(e.segments[0][0])?e.segments[0][0]="M":(e.err="Invalid path value: missing M/m",e.segments=[])),e.segments}function f(t){return Array.isArray(t)&&u(t)&&t.every(t=>t[0]===t[0].toUpperCase())}function y(t){if(f(t))return m(t);const e=h(t),n=e.length,r=[];let s=0,a=0,i=0,c=0,o=0;"M"===e[0][0]&&(s=+e[0][1],a=+e[0][2],i=s,c=a,o+=1,r.push(["M",s,a]));for(let t=o;t<n;t+=1){const n=e[t],[o]=n,m=o.toUpperCase(),l=[];let u=[];if(o!==m)switch(l[0]=m,m){case"A":u=n.slice(1,-2).concat([+n[6]+s,+n[7]+a]);for(let t=0;t<u.length;t+=1)l.push(u[t]);break;case"V":l[1]=+n[1]+a;break;case"H":l[1]=+n[1]+s;break;default:"M"===m&&(i=+n[1]+s,c=+n[2]+a);for(let t=1;t<n.length;t+=1)l.push(+n[t]+(t%2?s:a))}else for(let t=0;t<n.length;t+=1)l.push(n[t]);r.push(l);const h=l.length;switch(m){case"Z":s=i,a=c;break;case"H":s=+l[1];break;case"V":a=+l[1];break;default:s=+l[h-2],a=+l[h-1],"M"===m&&(i=s,c=a)}}return r}function p(t){return Array.isArray(t)&&u(t)&&t.slice(1).every(t=>t[0]===t[0].toLowerCase())}function x(t){if(p(t))return m(t);const e=h(t),n=e.length,r=[];let s=0,a=0,i=0,c=0,o=0;"M"===e[0][0]&&(s=+e[0][1],a=+e[0][2],i=s,c=a,o+=1,r.push(["M",s,a]));for(let t=o;t<n;t+=1){const n=e[t],[o]=n,m=o.toLowerCase(),l=[];let u=[];if(o!==m)switch(l[0]=m,m){case"a":u=n.slice(1,-2).concat([+n[6]-s,+n[7]-a]);for(let t=0;t<u.length;t+=1)l.push(u[t]);break;case"v":l[1]=+n[1]-a;break;default:for(let t=1;t<n.length;t+=1)l.push(+n[t]-(t%2?s:a));"m"===m&&(i=+n[1],c=+n[2])}else{"m"===o&&(i=+n[1]+s,c=+n[2]+a);for(let t=0;t<n.length;t+=1)l.push(n[t])}r.push(l);const h=l.length;switch(l[0]){case"z":s=i,a=c;break;case"h":s+=+l[h-1];break;case"v":a+=+l[h-1];break;default:s+=+r[t][h-2],a+=+r[t][h-1]}}return r}function d(e,n){const{round:r,decimals:s}=t,a=n&&!Number.isNaN(+n)?+n:r&&s;if(!1===n||!r&&!a)return m(e);const i=10**a,c=[],o=e.length;let l,u=0,h=[];for(let t=0;t<o;t+=1){h=e[t],l=[""];for(let t=0;t<h.length;t+=1)t?(u=+h[t],l.push(t&&u%1!=0?Math.round(u*i)/i:u)):l[t]=h[t];c.push(l)}return c}function g(t,e){return d(t,e).map(t=>t[0]+t.slice(1).join(" ")).join("")}function M(t,e,n){const[r]=t,s=t.slice(1);let a=t.slice();if("TQ".includes(t[0])||(e.qx=null,e.qy=null),"H"===r)a=["L",t[1],e.y1];else if("V"===r)a=["L",e.x1,t[1]];else if("S"===r){const{x1:t,y1:r}=function(t,e,n,r,s){return"CS".indexOf(s)>-1?{x1:2*t-n,y1:2*e-r}:{x1:t,y1:e}}(e.x1,e.y1,e.x2,e.y2,n);e.x1=t,e.y1=r,a=["C",t,r].concat(s)}else if("T"===r){const{qx:t,qy:r}=function(t,e,n,r,s){return"QT".indexOf(s)>-1?{qx:2*t-n,qy:2*e-r}:{qx:t,qy:e}}(e.x1,e.y1,e.qx,e.qy,n);e.qx=t,e.qy=r,a=["Q",t,r].concat(s)}else if("Q"===r){const[t,n]=s;e.qx=t,e.qy=n}return a}function b(t){return Array.isArray(t)&&u(t)&&t.every(t=>{const n=t[0].toLowerCase();return e[n]===t.length-1&&"ACLMQZ".includes(t[0])})}function A(t){if(Array.isArray(t)&&b(t))return m(t);const e=y(t),n={x1:0,y1:0,x2:0,y2:0,x:0,y:0,qx:null,qy:null},r=[],s=e.length;let a,i,c="",o="";for(let t=0;t<s;t+=1)[c]=e[t],r[t]=c,t&&(o=r[t-1]),e[t]=M(e[t],n,o),a=e[t],i=a.length,n.x1=+a[i-2],n.y1=+a[i-1],n.x2=+a[i-4]||n.x1,n.y2=+a[i-3]||n.y1;return e}function w(t){const e=y(t),n="Z"===e.slice(-1)[0][0];let r=[],s=0;return r=A(e).map((t,n)=>(s=t.length,{seg:e[n],n:t,c:e[n][0],x:t[s-2],y:t[s-1]})).map((t,e,r)=>{const s=t.seg,a=t.n,i=e&&r[e-1],c=r[e+1]&&r[e+1],o=t.c,m=r.length,l=e?r[e-1].x:r[m-1].x,u=e?r[e-1].y:r[m-1].y;let h=[];switch(o){case"M":h=n?["Z"]:[o,l,u];break;case"A":h=s.slice(0,-3).concat([1===s[5]?0:1,l,u]);break;case"C":h=c&&"S"===c.c?["S",s[1],s[2],l,u]:[o,s[3],s[4],s[1],s[2],l,u];break;case"S":h=i&&"CS".indexOf(i.c)>-1&&(!c||c&&"S"!==c.c)?["C",a[3],a[4],a[1],a[2],l,u]:[o,a[1],a[2],l,u];break;case"Q":h=c&&"T"===c.c?["T",l,u]:s.slice(0,-2).concat([l,u]);break;case"T":h=i&&"QT".indexOf(i.c)>-1&&(!c||c&&"T"!==c.c)?["Q",a[1],a[2],l,u]:[o,l,u];break;case"Z":h=["M",l,u];break;case"H":h=[o,l];break;case"V":h=[o,u];break;default:h=s.slice(0,-2).concat([l,u])}return h}),n?r.reverse():[r[0]].concat(r.slice(1).reverse())}function v(t){return g(y(t),0).replace(/(m|M)/g,"|$1").split("|").map(t=>t.trim()).filter(t=>t)}function N(t,e){const n=d(y(t),e),r=d(x(t),e);return n.map((t,e)=>e?t.join("").length<r[e].join("").length?t:r[e]:t)}function C(t,e,n){return{x:t*Math.cos(n)-e*Math.sin(n),y:t*Math.sin(n)+e*Math.cos(n)}}function S(t,e,n,r,s,a,i,c,o,m){let l=t,u=e,h=n,f=r,y=c,p=o;const x=120*Math.PI/180,d=Math.PI/180*(+s||0);let g,M,b,A,w,v=[];if(m)[M,b,A,w]=m;else{g=C(l,u,-d),l=g.x,u=g.y,g=C(y,p,-d),y=g.x,p=g.y;const t=(l-y)/2,e=(u-p)/2;let n=t*t/(h*h)+e*e/(f*f);n>1&&(n=Math.sqrt(n),h*=n,f*=n);const r=h*h,s=f*f,c=(a===i?-1:1)*Math.sqrt(Math.abs((r*s-r*e*e-s*t*t)/(r*e*e+s*t*t)));A=c*h*e/f+(l+y)/2,w=c*-f*t/h+(u+p)/2,M=(Math.asin((u-w)/f)*10**9>>0)/10**9,b=(Math.asin((p-w)/f)*10**9>>0)/10**9,M=l<A?Math.PI-M:M,b=y<A?Math.PI-b:b,M<0&&(M=2*Math.PI+M),b<0&&(b=2*Math.PI+b),i&&M>b&&(M-=2*Math.PI),!i&&b>M&&(b-=2*Math.PI)}let N=b-M;if(Math.abs(N)>x){const t=b,e=y,n=p;b=M+x*(i&&b>M?1:-1),y=A+h*Math.cos(b),p=w+f*Math.sin(b),v=S(y,p,h,f,s,0,i,e,n,[b,t,A,w])}N=b-M;const k=Math.cos(M),q=Math.sin(M),P=Math.cos(b),I=Math.sin(b),T=Math.tan(N/4),$=4/3*h*T,V=4/3*f*T,z=[l,u],L=[l+$*q,u-V*k],E=[y+$*I,p-V*P],O=[y,p];if(L[0]=2*z[0]-L[0],L[1]=2*z[1]-L[1],m)return[L,E,O].concat(v);v=[L,E,O].concat(v).join().split(",");const j=[];for(let t=0,e=v.length;t<e;t+=1)j[t]=t%2?C(v[t-1],v[t],d).y:C(v[t],v[t+1],d).x;return j}function k(t,e,n,r,s,a){return[1/3*t+2/3*n,1/3*e+2/3*r,1/3*s+2/3*n,1/3*a+2/3*r,s,a]}function q(t,e,n,r,s,a,i,c,o){const m=1-o;return{x:m**3*t+m*m*3*o*n+3*m*o*o*s+o**3*i,y:m**3*e+m*m*3*o*r+3*m*o*o*a+o**3*c}}function P(t,e,n){const[r,s]=t,[a,i]=e;return[r+(a-r)*n,s+(i-s)*n]}function I(t,e,n,r){const s=.5,a=[t,e],i=[n,r],c=P(a,i,s),o=P(i,c,s),m=P(c,o,s),l=P(o,m,s),u=P(m,l,s),h=q.apply(0,a.concat(c,m,u,s)),f=q.apply(0,u.concat(l,o,i,0));return[h.x,h.y,f.x,f.y,n,r]}function T(t,e){"TQ".includes(t[0])||(e.qx=null,e.qy=null);const[n,r]=t.slice(1);switch(t[0]){case"M":return e.x=+n,e.y=+r,t;case"A":return["C"].concat(S.apply(0,[e.x1,e.y1].concat(t.slice(1))));case"Q":return e.qx=+n,e.qy=+r,["C"].concat(k.apply(0,[e.x1,e.y1].concat(t.slice(1))));case"L":return["C"].concat(I(e.x1,e.y1,t[1],t[2]));case"Z":return["C"].concat(I(e.x1,e.y1,e.x,e.y))}return t}function $(t,e,n){if(t[n].length>7){t[n].shift();const r=t[n];let s=n;for(;r.length;)e[n]="A",t.splice(s+=1,0,["C"].concat(r.splice(0,6)));t.splice(n,1)}}function V(t){if(!t.every(t=>!Number.isNaN(t)))throw TypeError(`CSSMatrix: "${t}" must only have numbers.`);const e=new Y,n=Array.from(t);if(16===n.length){const[t,r,s,a,i,c,o,m,l,u,h,f,y,p,x,d]=n;e.m11=t,e.a=t,e.m21=i,e.c=i,e.m31=l,e.m41=y,e.e=y,e.m12=r,e.b=r,e.m22=c,e.d=c,e.m32=u,e.m42=p,e.f=p,e.m13=s,e.m23=o,e.m33=h,e.m43=x,e.m14=a,e.m24=m,e.m34=f,e.m44=d}else{if(6!==n.length)throw new TypeError("CSSMatrix: expecting an Array of 6/16 values.");{const[t,r,s,a,i,c]=n;e.m11=t,e.a=t,e.m12=r,e.b=r,e.m21=s,e.c=s,e.m22=a,e.d=a,e.m41=i,e.e=i,e.m42=c,e.f=c}}return e}function z(t){if([Y,DOMMatrix].some(e=>t instanceof e)||"object"==typeof t&&["m11","m12","m13","m14","m21","m22","m23","m24","m31","m32","m33","m34","m41","m42","m43","m44"].every(e=>e in t))return V([t.m11,t.m12,t.m13,t.m14,t.m21,t.m22,t.m23,t.m24,t.m31,t.m32,t.m33,t.m34,t.m41,t.m42,t.m43,t.m44]);throw TypeError(`CSSMatrix: "${t}" is not a DOMMatrix / CSSMatrix compatible object.`)}function L(t){if("string"!=typeof t)throw TypeError(`CSSMatrix: "${t}" is not a string.`);const e=String(t).replace(/\s/g,"");let n=new Y;const r=`CSSMatrix: invalid transform string "${t}"`;let s=!0;return e.split(")").filter(t=>t).map(t=>{const[e,n]=t.split("(");if(!n)throw TypeError(r);const a=n.split(",").map(t=>t.includes("rad")?parseFloat(t)*(180/Math.PI):parseFloat(t)),[i,c,o,m]=a;return s&&("matrix3d"===e||"rotate3d"===e&&[i,c].every(t=>!Number.isNaN(+t)&&0!==t)&&m||["rotateX","rotateY"].includes(e)&&i||"translate3d"===e&&[i,c,o].every(t=>!Number.isNaN(+t))&&o||"scale3d"===e&&[i,c,o].every(t=>!Number.isNaN(+t)&&t!==i))&&(s=!1),{prop:e,components:a}}).forEach(t=>{const{prop:e,components:a}=t,[i,c,o,m]=a,l=[i,c,o],u=[i,c,o,m];if("perspective"!==e||s)if(e.includes("matrix")){const t=a.map(t=>Math.abs(t)<1e-6?0:t);[6,16].includes(t.length)&&(n=n.multiply(V(t)))}else if(["translate","translate3d"].some(t=>e===t)&&i)n=n.translate(i,c||0,o||0);else if("rotate3d"===e&&u.every(t=>!Number.isNaN(+t))&&m)n=n.rotateAxisAngle(i,c,o,m);else if("scale3d"===e&&l.every(t=>!Number.isNaN(+t))&&l.some(t=>1!==t))n=n.scale(i,c,o);else if("rotate"===e&&i)n=n.rotate(0,0,i);else if("scale"!==e||Number.isNaN(i)||1===i)if("skew"===e&&(i||c))n=i?n.skewX(i):n,n=c?n.skewY(c):n;else{if(!/[XYZ]/.test(e)||!i)throw TypeError(r);if(e.includes("skew"))n=n[e](i);else{const t=e.replace(/[XYZ]/,""),r=e.replace(t,""),s=["X","Y","Z"].indexOf(r),a=[0===s?i:0,1===s?i:0,2===s?i:0];n=n[t](...a)}}else{const t=Number.isNaN(+c)?i:c;n=n.scale(i,t,1)}else n.m34=-1/i}),n}function E(t,e,n){const r=new Y;return r.m41=t,r.e=t,r.m42=e,r.f=e,r.m43=n,r}function O(t,e,n){const r=new Y,s=Math.PI/180,a=t*s,i=e*s,c=n*s,o=Math.cos(a),m=-Math.sin(a),l=Math.cos(i),u=-Math.sin(i),h=Math.cos(c),f=-Math.sin(c),y=l*h,p=-l*f;r.m11=y,r.a=y,r.m12=p,r.b=p,r.m13=u;const x=m*u*h+o*f;r.m21=x,r.c=x;const d=o*h-m*u*f;return r.m22=d,r.d=d,r.m23=-m*l,r.m31=m*f-o*u*h,r.m32=m*h+o*u*f,r.m33=o*l,r}function j(t,e,n,r){const s=new Y,a=r*(Math.PI/360),i=Math.sin(a),c=Math.cos(a),o=i*i,m=Math.sqrt(t*t+e*e+n*n);let l=t,u=e,h=n;0===m?(l=0,u=0,h=1):(l/=m,u/=m,h/=m);const f=l*l,y=u*u,p=h*h,x=1-2*(y+p)*o;s.m11=x,s.a=x;const d=2*(l*u*o+h*i*c);s.m12=d,s.b=d,s.m13=2*(l*h*o-u*i*c);const g=2*(u*l*o-h*i*c);s.m21=g,s.c=g;const M=1-2*(p+f)*o;return s.m22=M,s.d=M,s.m23=2*(u*h*o+l*i*c),s.m31=2*(h*l*o+u*i*c),s.m32=2*(h*u*o-l*i*c),s.m33=1-2*(f+y)*o,s}function D(t,e,n){const r=new Y;return r.m11=t,r.a=t,r.m22=e,r.d=e,r.m33=n,r}function Z(t){const e=new Y,n=t*Math.PI/180,r=Math.tan(n);return e.m21=r,e.c=r,e}function X(t){const e=new Y,n=t*Math.PI/180,r=Math.tan(n);return e.m12=r,e.b=r,e}function Q(t,e){return V([e.m11*t.m11+e.m12*t.m21+e.m13*t.m31+e.m14*t.m41,e.m11*t.m12+e.m12*t.m22+e.m13*t.m32+e.m14*t.m42,e.m11*t.m13+e.m12*t.m23+e.m13*t.m33+e.m14*t.m43,e.m11*t.m14+e.m12*t.m24+e.m13*t.m34+e.m14*t.m44,e.m21*t.m11+e.m22*t.m21+e.m23*t.m31+e.m24*t.m41,e.m21*t.m12+e.m22*t.m22+e.m23*t.m32+e.m24*t.m42,e.m21*t.m13+e.m22*t.m23+e.m23*t.m33+e.m24*t.m43,e.m21*t.m14+e.m22*t.m24+e.m23*t.m34+e.m24*t.m44,e.m31*t.m11+e.m32*t.m21+e.m33*t.m31+e.m34*t.m41,e.m31*t.m12+e.m32*t.m22+e.m33*t.m32+e.m34*t.m42,e.m31*t.m13+e.m32*t.m23+e.m33*t.m33+e.m34*t.m43,e.m31*t.m14+e.m32*t.m24+e.m33*t.m34+e.m34*t.m44,e.m41*t.m11+e.m42*t.m21+e.m43*t.m31+e.m44*t.m41,e.m41*t.m12+e.m42*t.m22+e.m43*t.m32+e.m44*t.m42,e.m41*t.m13+e.m42*t.m23+e.m43*t.m33+e.m44*t.m43,e.m41*t.m14+e.m42*t.m24+e.m43*t.m34+e.m44*t.m44])}class Y{constructor(...t){const e=this;if(e.a=1,e.b=0,e.c=0,e.d=1,e.e=0,e.f=0,e.m11=1,e.m12=0,e.m13=0,e.m14=0,e.m21=0,e.m22=1,e.m23=0,e.m24=0,e.m31=0,e.m32=0,e.m33=1,e.m34=0,e.m41=0,e.m42=0,e.m43=0,e.m44=1,t&&t.length){let n=t;return t instanceof Array&&(t[0]instanceof Array&&[16,6].includes(t[0].length)||"string"==typeof t[0]||[Y,DOMMatrix].some(e=>t[0]instanceof e))&&([n]=t),e.setMatrixValue(n)}return e}set isIdentity(t){this.isIdentity=t}get isIdentity(){const t=this;return 1===t.m11&&0===t.m12&&0===t.m13&&0===t.m14&&0===t.m21&&1===t.m22&&0===t.m23&&0===t.m24&&0===t.m31&&0===t.m32&&1===t.m33&&0===t.m34&&0===t.m41&&0===t.m42&&0===t.m43&&1===t.m44}get is2D(){const t=this;return 0===t.m31&&0===t.m32&&1===t.m33&&0===t.m34&&0===t.m43&&1===t.m44}set is2D(t){this.is2D=t}setMatrixValue(t){return[DOMMatrix,Y].some(e=>t instanceof e)?z(t):"string"==typeof t&&t.length&&"none"!==t?L(t):Array.isArray(t)?V(t):this}toString(){const t=this.toArray().join(",");return`${this.is2D?"matrix":"matrix3d"}(${t})`}toArray(){const t=this;let e;return e=t.is2D?[t.a,t.b,t.c,t.d,t.e,t.f]:[t.m11,t.m12,t.m13,t.m14,t.m21,t.m22,t.m23,t.m24,t.m31,t.m32,t.m33,t.m34,t.m41,t.m42,t.m43,t.m44],e.map(t=>Math.abs(t)<1e-6?0:(t*10**6>>0)/10**6)}toJSON(){return JSON.parse(JSON.stringify(this))}multiply(t){return Q(this,t)}translate(t,e,n){let r=e,s=n;return null==s&&(s=0),null==r&&(r=0),Q(this,E(t,r,s))}scale(t,e,n){let r=e,s=n;return null==r&&(r=t),null==s&&(s=t),Q(this,D(t,r,s))}rotate(t,e,n){let r=t,s=e,a=n;return null==s&&(s=0),null==a&&(a=r,r=0),Q(this,O(r,s,a))}rotateAxisAngle(t,e,n,r){if([t,e,n,r].some(t=>Number.isNaN(t)))throw new TypeError("CSSMatrix: expecting 4 values");return Q(this,j(t,e,n,r))}skewX(t){return Q(this,Z(t))}skewY(t){return Q(this,X(t))}transformPoint(t){let e=E(t.x,t.y,t.z);return e.m44=t.w||1,e=this.multiply(e),{x:e.m41,y:e.m42,z:e.m43,w:e.m44}}transform(t){const e=this,n=e.m11*t.x+e.m12*t.y+e.m13*t.z+e.m14*t.w,r=e.m21*t.x+e.m22*t.y+e.m23*t.z+e.m24*t.w,s=e.m31*t.x+e.m32*t.y+e.m33*t.z+e.m34*t.w,a=e.m41*t.x+e.m42*t.y+e.m43*t.z+e.m44*t.w;return{x:n/a,y:r/a,z:s/a,w:a}}}function H(t){let e=new Y;const{origin:n}=t,r=n[0],s=n[1],{translate:a}=t,{rotate:i}=t,{skew:c}=t,{scale:o}=t;return(Array.isArray(a)&&a.some(t=>0!=+t)||!Number.isNaN(a))&&(e=Array.isArray(a)?e.translate(+a[0]||0,+a[1]||0,+a[2]||0):e.translate(+a||0,0,0)),(i||c||o)&&(e=e.translate(+r,+s),i&&(e=Array.isArray(i)&&i.some(t=>0!=+t)?e.rotate(+i[0]||0,+i[1]||0,+i[2]||0):e.rotate(0,0,+i||0)),Array.isArray(c)&&c.some(t=>0!=+t)&&(Array.isArray(c)?(e=c[0]?e.skewX(+c[0]||0):e,e=c[1]?e.skewY(+c[1]||0):e):e=e.skewX(+c||0)),(!Number.isNaN(o)||Array.isArray(o)&&o.some(t=>1!=+t))&&(e=Array.isArray(o)?e.scale(+o[0]||1,+o[1]||1,+o[2]||1):e.scale(+o||1,+o||1,+o||1)),e=e.translate(-r,-s)),e}function R(t,e,n){const r=t.transformPoint({x:e[0],y:e[1],z:0,w:1}),s=n[0]||0,a=n[1]||0,i=n[2]||0,c=r.x-s,o=r.y-a,m=r.z-i;return[c*(Math.abs(i)/Math.abs(m))+s,o*(Math.abs(i)/Math.abs(m))+a]}function J(t,e){let n,r,s,a,i,c,o,l=0,u=0;const h=y(t),f=A(h),p=H(e),x=Object.keys(e),{origin:d}=e,{a:g,b:M,c:b,d:w,e:v,f:N}=p,C=[g,M,b,w,v,N],S={x1:0,y1:0,x2:0,y2:0,x:0,y:0,qx:null,qy:null};let k=[],q=0,P="",I=[];const V=[];let z=[];if(!p.isIdentity){for(n=0,s=h.length;n<s;n+=1)k=h[n],h[n]&&([P]=k),V[n]=P,"A"!==P||p.is2D&&["skewX","skewY"].find(t=>x.includes(t))||(k=T(f[n],S),h[n]=T(f[n],S),$(h,V,n),f[n]=T(f[n],S),$(f,V,n),s=Math.max(h.length,f.length)),k=f[n],q=k.length,S.x1=+k[q-2],S.y1=+k[q-1],S.x2=+k[q-4]||S.x1,S.y2=+k[q-3]||S.y1,z={s:h[n],c:h[n][0]},"Z"!==P&&(z.x=S.x1,z.y=S.y1),I=I.concat(z);return I.map(t=>{switch(P=t.c,k=t.s,P){case"A":return o=function(t,e,n,r){const s=Math.cos(r*Math.PI/180),a=Math.sin(r*Math.PI/180),i=[e*(t[0]*s+t[2]*a),e*(t[1]*s+t[3]*a),n*(-t[0]*a+t[2]*s),n*(-t[1]*a+t[3]*s)],c=i[0]*i[0]+i[2]*i[2],o=i[1]*i[1]+i[3]*i[3];let m=((i[0]-i[3])*(i[0]-i[3])+(i[2]+i[1])*(i[2]+i[1]))*((i[0]+i[3])*(i[0]+i[3])+(i[2]-i[1])*(i[2]-i[1]));const l=(c+o)/2;if(m<1e-9*l){const t=Math.sqrt(l);return{rx:t,ry:t,ax:0}}const u=i[0]*i[1]+i[2]*i[3];m=Math.sqrt(m);const h=l+m/2,f=l-m/2;let y,p,x=Math.abs(u)<1e-9&&Math.abs(h-o)<1e-9?90:Math.atan(Math.abs(u)>Math.abs(h-o)?(h-c)/u:u/(h-o)*180)/Math.PI;return x>=0?(y=Math.sqrt(h),p=Math.sqrt(f)):(x+=90,y=Math.sqrt(f),p=Math.sqrt(h)),{rx:y,ry:p,ax:x}}(C,k[1],k[2],k[3]),C[0]*C[3]-C[1]*C[2]<0&&(k[5]=+k[5]?0:1),[i,c]=R(p,[k[6],k[7]],d),k=l===i&&u===c||o.rx<1e-9*o.ry||o.ry<1e-9*o.rx?["L",i,c]:[P,o.rx,o.ry,o.ax,k[4],k[5],i,c],l=i,u=c,k;case"L":case"H":case"V":return[i,c]=R(p,[t.x,t.y],d),l!==i&&u!==c?k=["L",i,c]:u===c?k=["H",i]:l===i&&(k=["V",c]),l=i,u=c,k;default:for(r=1,a=k.length;r<a;r+=2)[l,u]=R(p,[k[r],k[r+1]],d),k[r]=l,k[r+1]=u;return k}})}return m(h)}function B(t,e,n,r,s,a,i,c){let o=s-2*n+t-(i-2*s+n),m=2*(n-t)-2*(s-n),l=t-n,u=(-m+Math.sqrt(m*m-4*o*l))/2/o,h=(-m-Math.sqrt(m*m-4*o*l))/2/o;const f=[e,c],y=[t,i];let p;return Math.abs(u)>"1e12"&&(u=.5),Math.abs(h)>"1e12"&&(h=.5),u>0&&u<1&&(p=q(t,e,n,r,s,a,i,c,u),y.push(p.x),f.push(p.y)),h>0&&h<1&&(p=q(t,e,n,r,s,a,i,c,h),y.push(p.x),f.push(p.y)),o=a-2*r+e-(c-2*a+r),m=2*(r-e)-2*(a-r),l=e-r,u=(-m+Math.sqrt(m*m-4*o*l))/2/o,h=(-m-Math.sqrt(m*m-4*o*l))/2/o,Math.abs(u)>"1e12"&&(u=.5),Math.abs(h)>"1e12"&&(h=.5),u>0&&u<1&&(p=q(t,e,n,r,s,a,i,c,u),y.push(p.x),f.push(p.y)),h>0&&h<1&&(p=q(t,e,n,r,s,a,i,c,h),y.push(p.x),f.push(p.y)),{min:{x:Math.min.apply(0,y),y:Math.min.apply(0,f)},max:{x:Math.max.apply(0,y),y:Math.max.apply(0,f)}}}function F(t){return Array.isArray(t)&&u(t)&&t.slice(1).every(t=>"C"===t[0])}function G(t){if(F(t))return m(t);const e=A(t),n={x1:0,y1:0,x2:0,y2:0,x:0,y:0,qx:null,qy:null},r=[];let s="",a=e.length;for(let t=0;t<a;t+=1){const i=e[t],c=i.length;i&&([s]=i),r[t]=s,e[t]=T(i,n),$(e,r,t),a=e.length,n.x1=+i[c-2],n.y1=+i[c-1],n.x2=+i[c-4]||n.x1,n.y2=+i[c-3]||n.y1}return e}function U(t){if(!t)return{x:0,y:0,width:0,height:0,x2:0,y2:0,cx:0,cy:0};const e=G(t);let n=0,r=0,s=[],a=[];e.forEach(t=>{const[e,i]=t.slice(-2);if("M"===t[0])n=+e,r=+i,s.push(e),a.push(i);else{const c=B.apply(0,[n,r].concat(t.slice(1)));s=s.concat(c.min.x,c.max.x),a=a.concat(c.min.y,c.max.y),n=+e,r=+i}});const i=Math.min.apply(0,s),c=Math.min.apply(0,a),o=Math.max.apply(0,s),m=Math.max.apply(0,a),l=o-i,u=m-c;return{width:l,height:u,x:i,y:c,x2:o,y2:m,cx:i+l/2,cy:c+u/2}}function K(t,e,n,r,s,a,i,c){return 3*((c-e)*(n+s)-(i-t)*(r+a)+r*(t-s)-n*(e-a)+c*(s+t/3)-i*(a+e/3))/20}function W(t){let e=0,n=0,r=0,s=0,a=0;return G(t).map(t=>{switch(t[0]){case"M":case"Z":return r="M"===t[0]?t[1]:r,s="M"===t[0]?t[2]:s,e=r,n=s,0;default:return a=K.apply(0,[e,n].concat(t.slice(1))),[e,n]=t.slice(-2),a}}).reduce((t,e)=>t+e,0)}function _(t,e,n,r,s){return s*(s*(-3*t+9*e-9*n+3*r)+6*t-12*e+6*n)-3*t+3*e}function tt(t,e,n,r,s,a,i,c,o){let m=o;(null===o||Number.isNaN(+o))&&(m=1),m>1&&(m=1),m<0&&(m=0);const l=m/2;let u=0,h=0,f=0,y=0;const p=[.2491,.2491,.2335,.2335,.2032,.2032,.1601,.1601,.1069,.1069,.0472,.0472];return[-.1252,.1252,-.3678,.3678,-.5873,.5873,-.7699,.7699,-.9041,.9041,-.9816,.9816].forEach((o,m)=>{u=l*o+l,h=_(t,n,s,i,u),f=_(e,r,a,c,u),y+=p[m]*Math.sqrt(h*h+f*f)}),l*y}Y.Translate=E,Y.Rotate=O,Y.RotateAxisAngle=j,Y.Scale=D,Y.SkewX=Z,Y.SkewY=X,Y.Multiply=Q,Y.fromArray=V,Y.fromMatrix=z,Y.fromString=L;const et={circle:["cx","cy","r"],ellipse:["cx","cy","rx","ry"],rect:["width","height","x","y","rx","ry"],polygon:["points"],polyline:["points"],glyph:[]};const nt={CSSMatrix:Y,parsePathString:h,isPathArray:u,isCurveArray:F,isAbsoluteArray:f,isRelativeArray:p,isNormalizedArray:b,isValidPath:function(t){if("string"!=typeof t)return!1;const e=new l(t);for(i(e);e.index<e.max&&!e.err.length;)o(e);return!e.err.length&&"mM".includes(e.segments[0][0])},pathToAbsolute:y,pathToRelative:x,pathToCurve:G,pathToString:g,getDrawDirection:function(t){return W(G(t))>=0},getPathArea:W,getPathBBox:U,getPathLength:function(t){let e=0;return G(t).forEach((t,n,r)=>{e+="M"===t[0]?0:tt.apply(0,r[n-1].slice(-2).concat(t.slice(1)))}),e},getPointAtLength:function(t,e){let n,r,s,a=0;return G(t).map((t,i,c)=>(r=i?c[i-1].slice(-2).concat(t.slice(1)):t.slice(1),n=i?tt.apply(0,r):0,a+=n,s=0===i?{x:r[0],y:r[1]}:a>e&&e>a-n?q.apply(0,r.concat(1-(a-e)/n)):null,s)).filter(t=>t).slice(-1)[0]},clonePath:m,splitPath:v,roundPath:d,optimizePath:N,reverseCurve:function(t){const e=t.slice(1).map((e,n,r)=>n?r[n-1].slice(-2).concat(e.slice(1)):t[0].slice(1).concat(e.slice(1))).map(t=>t.map((e,n)=>t[t.length-n-2*(1-n%2)])).reverse();return[["M"].concat(e[0].slice(0,2))].concat(e.map(t=>["C"].concat(t.slice(2))))},reversePath:w,normalizePath:A,transformPath:J,getSVGMatrix:H,shapeToPath:function(e,n){if(!Object.keys(et).concat(["glyph"]).some(t=>e.tagName===t))throw TypeError(`shapeToPath: ${e} is not SVGElement`);const r=document.createElementNS("http://www.w3.org/2000/svg","path"),s=e.tagName,a=et[s],i={};let c;i.type=s,a.forEach(t=>{i[t]=e.getAttribute(t)}),Object.values(e.attributes).forEach(({name:t,value:e})=>{a.includes(t)||r.setAttribute(t,e)});const{round:o,decimals:m}=t,l=o&&m?m:null;return"circle"===s?c=g(function(t){const{cx:e,cy:n,r:r}=t;return[["M",e-r,n],["a",r,r,0,1,0,2*r,0],["a",r,r,0,1,0,-2*r,0]]}(i),l):"ellipse"===s?c=g(function(t){const{cx:e,cy:n,rx:r,ry:s}=t;return[["M",e-r,n],["a",r,s,0,1,0,2*r,0],["a",r,s,0,1,0,-2*r,0]]}(i),l):["polyline","polygon"].includes(s)?c=g(function(t){const e=[],n=t.points.split(/[\s|,]/).map(Number);let r=0;for(;r<n.length;)e.push([r?"L":"M",n[r],n[r+1]]),r+=2;return"polygon"===t.type?e.concat([["z"]]):e}(i),l):"rect"===s?c=g(function(t){const e=+t.x||0,n=+t.y||0,r=+t.width,s=+t.height;let a=+t.rx,i=+t.ry;return a||i?(a=a||i,i=i||a,2*a>r&&(a-=(2*a-r)/2),2*i>s&&(i-=(2*i-s)/2),[["M",e+a,n],["h",r-2*a],["s",a,0,a,i],["v",s-2*i],["s",0,i,-a,i],["h",2*a-r],["s",-a,0,-a,-i],["v",2*i-s],["s",0,-i,a,-i]]):[["M",e,n],["h",r],["v",s],["H",e],["Z"]]}(i),l):"line"===s?c=g(function(t){const{x1:e,y1:n,x2:r,y2:s}=t;return[["M",+e,+n],["L",+r,+s]]}(i),l):"glyph"===s&&(c=e.getAttribute("d")),c?(r.setAttribute("d",c),n&&(e.before(r,e),e.remove()),r):null},options:t,Version:"0.1.11alpha1"};class rt{constructor(e,n){const r=n||{};let{round:s}=t;const{round:a}=r;(a&&0==+a||!1===a)&&(s=0);const{decimals:i}=s?r||t:{decimals:!1};return this.round=i,this.segments=h(e),this.pathValue=e,this}toAbsolute(){const{segments:t}=this;return this.segments=y(t),this}toRelative(){const{segments:t}=this;return this.segments=x(t),this}reverse(t){this.toAbsolute();const{segments:e}=this,n=v(this.toString()),r=n.length>1?n:0,s=r&&m(r).map((e,n)=>t?n?w(e):h(e):w(e));let a=[];return a=r?s.flat(1):t?e:w(e),this.segments=m(a),this}normalize(){const{segments:t}=this;return this.segments=A(t),this}optimize(){const{segments:t}=this;return this.segments=N(t,this.round),this}transform(t){if(!t||"object"!=typeof t||"object"==typeof t&&!["translate","rotate","skew","scale"].some(e=>e in t))return this;const e=t||{},{segments:n}=this;if(!e.origin){const t=U(n);e.origin=[+t.cx,+t.cy]}return this.segments=J(n,e),this}flipX(){return this.transform({rotate:[180,0,0]}),this}flipY(){return this.transform({rotate:[0,180,0]}),this}toString(){return g(this.segments,this.round)}}Object.keys(nt).forEach(t=>{rt[t]=nt[t]});export{rt as default};
|
|
1
|
+
// SVGPathCommander v0.1.11alpha2 | thednp © 2021 | MIT-License
|
|
2
|
+
const t={origin:[0,0],decimals:4,round:1},e={a:7,c:6,h:1,l:2,m:2,r:4,q:4,s:4,t:2,v:1,z:0};function n(t){let n=t.pathValue[t.segmentStart],r=n.toLowerCase(),{data:s}=t;for("m"===r&&s.length>2&&(t.segments.push([n,s[0],s[1]]),s=s.slice(2),r="l",n="m"===n?"l":"L");s.length>=e[r]&&(t.segments.push([n].concat(s.splice(0,e[r]))),e[r]););}function r(t){const{index:e}=t,n=t.pathValue.charCodeAt(e);return 48===n?(t.param=0,void(t.index+=1)):49===n?(t.param=1,void(t.index+=1)):void(t.err=`Invalid path value: invalid Arc flag ${n}, expecting 0 or 1 at index ${e}`)}function s(t){return t>=48&&t<=57}function a(t){const{max:e,pathValue:n,index:r}=t;let a,i=r,c=!1,o=!1,m=!1,l=!1;if(i>=e)t.err=`Invalid path value at ${i}: missing param ${n[i]}`;else if(a=n.charCodeAt(i),43!==a&&45!==a||(i+=1,a=i<e?n.charCodeAt(i):0),s(a)||46===a){if(46!==a){if(c=48===a,i+=1,a=i<e?n.charCodeAt(i):0,c&&i<e&&a&&s(a))return void(t.err=`Invalid path value at index ${r}: ${n[r]} illegal number`);for(;i<e&&s(n.charCodeAt(i));)i+=1,o=!0;a=i<e?n.charCodeAt(i):0}if(46===a){for(l=!0,i+=1;s(n.charCodeAt(i));)i+=1,m=!0;a=i<e?n.charCodeAt(i):0}if(101===a||69===a){if(l&&!o&&!m)return void(t.err=`Invalid path value at index ${i}: ${n[i]} invalid float exponent`);if(i+=1,a=i<e?n.charCodeAt(i):0,43!==a&&45!==a||(i+=1),!(i<e&&s(n.charCodeAt(i))))return void(t.err=`Invalid path value at index ${i}: ${n[i]} invalid float exponent`);for(;i<e&&s(n.charCodeAt(i));)i+=1}t.index=i,t.param=+t.pathValue.slice(r,i)}else t.err=`Invalid path value at index ${i}: ${n[i]} is not a number`}function i(t){const{pathValue:e,max:n}=t;for(;t.index<n&&(10===(r=e.charCodeAt(t.index))||13===r||8232===r||8233===r||32===r||9===r||11===r||12===r||160===r||r>=5760&&[5760,6158,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8239,8287,12288,65279].indexOf(r)>=0);)t.index+=1;var r}function c(t){return t>=48&&t<=57||43===t||45===t||46===t}function o(t){const{max:s,pathValue:o,index:m}=t,l=o.charCodeAt(m),h=e[o[m].toLowerCase()];if(t.segmentStart=m,function(t){switch(32|t){case 109:case 122:case 108:case 104:case 118:case 99:case 115:case 113:case 116:case 97:return!0;default:return!1}}(l))if(t.index+=1,i(t),t.data=[],h){for(;;){for(let e=h;e>0;e-=1){if(97!=(32|l)||3!==e&&4!==e?a(t):r(t),t.err.length)return;t.data.push(t.param),i(t),t.index<s&&44===o.charCodeAt(t.index)&&(t.index+=1,i(t))}if(t.index>=t.max)break;if(!c(o.charCodeAt(t.index)))break}n(t)}else n(t);else t.err=`Invalid path value: ${o[m]} not a path command`}function m(t){return Array.isArray(t)?t.map(t=>Array.isArray(t)?m(t):Number.isNaN(+t)?t:+t):t}function l(t){this.segments=[],this.pathValue=t,this.max=t.length,this.index=0,this.param=0,this.segmentStart=0,this.data=[],this.err=""}function h(t){return Array.isArray(t)&&t.every(t=>{const n=t[0].toLowerCase();return e[n]===t.length-1&&/[achlmqstvz]/gi.test(n)})}function u(t){if(h(t))return m(t);const e=new l(""+t);for(i(e);e.index<e.max&&!e.err.length;)o(e);return e.err.length?e.segments=[]:e.segments.length&&("mM".includes(e.segments[0][0])?e.segments[0][0]="M":(e.err="Invalid path value: missing M/m",e.segments=[])),e.segments}function y(t){return Array.isArray(t)&&h(t)&&t.every(t=>t[0]===t[0].toUpperCase())}function f(t){if(y(t))return m(t);const e=u(t),n=e.length,r=[];let s=0,a=0,i=0,c=0,o=0;"M"===e[0][0]&&(s=+e[0][1],a=+e[0][2],i=s,c=a,o+=1,r.push(["M",s,a]));for(let t=o;t<n;t+=1){const n=e[t],[o]=n,m=o.toUpperCase(),l=[];let h=[];if(o!==m)switch(l[0]=m,m){case"A":h=n.slice(1,-2).concat([+n[6]+s,+n[7]+a]);for(let t=0;t<h.length;t+=1)l.push(h[t]);break;case"V":l[1]=+n[1]+a;break;case"H":l[1]=+n[1]+s;break;default:"M"===m&&(i=+n[1]+s,c=+n[2]+a);for(let t=1;t<n.length;t+=1)l.push(+n[t]+(t%2?s:a))}else for(let t=0;t<n.length;t+=1)l.push(n[t]);r.push(l);const u=l.length;switch(m){case"Z":s=i,a=c;break;case"H":s=+l[1];break;case"V":a=+l[1];break;default:s=+l[u-2],a=+l[u-1],"M"===m&&(i=s,c=a)}}return r}function p(t){return Array.isArray(t)&&h(t)&&t.slice(1).every(t=>t[0]===t[0].toLowerCase())}function x(t){if(p(t))return m(t);const e=u(t),n=e.length,r=[];let s=0,a=0,i=0,c=0,o=0;"M"===e[0][0]&&(s=+e[0][1],a=+e[0][2],i=s,c=a,o+=1,r.push(["M",s,a]));for(let t=o;t<n;t+=1){const n=e[t],[o]=n,m=o.toLowerCase(),l=[];let h=[];if(o!==m)switch(l[0]=m,m){case"a":h=n.slice(1,-2).concat([+n[6]-s,+n[7]-a]);for(let t=0;t<h.length;t+=1)l.push(h[t]);break;case"v":l[1]=+n[1]-a;break;default:for(let t=1;t<n.length;t+=1)l.push(+n[t]-(t%2?s:a));"m"===m&&(i=+n[1],c=+n[2])}else{"m"===o&&(i=+n[1]+s,c=+n[2]+a);for(let t=0;t<n.length;t+=1)l.push(n[t])}r.push(l);const u=l.length;switch(l[0]){case"z":s=i,a=c;break;case"h":s+=+l[u-1];break;case"v":a+=+l[u-1];break;default:s+=+r[t][u-2],a+=+r[t][u-1]}}return r}function d(e,n){const{round:r,decimals:s}=t,a=n&&!Number.isNaN(+n)?+n:r&&s;if(!1===n||!r&&!a)return m(e);const i=10**a,c=[],o=e.length;let l,h=0,u=[];for(let t=0;t<o;t+=1){u=e[t],l=[""];for(let t=0;t<u.length;t+=1)t?(h=+u[t],l.push(t&&h%1!=0?Math.round(h*i)/i:h)):l[t]=u[t];c.push(l)}return c}function g(t,e){return d(t,e).map(t=>t[0]+t.slice(1).join(" ")).join("")}function M(t,e,n){const[r]=t,s=t.slice(1);let a=t.slice();if("TQ".includes(t[0])||(e.qx=null,e.qy=null),"H"===r)a=["L",t[1],e.y1];else if("V"===r)a=["L",e.x1,t[1]];else if("S"===r){const{x1:t,y1:r}=function(t,e,n,r,s){return"CS".indexOf(s)>-1?{x1:2*t-n,y1:2*e-r}:{x1:t,y1:e}}(e.x1,e.y1,e.x2,e.y2,n);e.x1=t,e.y1=r,a=["C",t,r].concat(s)}else if("T"===r){const{qx:t,qy:r}=function(t,e,n,r,s){return"QT".indexOf(s)>-1?{qx:2*t-n,qy:2*e-r}:{qx:t,qy:e}}(e.x1,e.y1,e.qx,e.qy,n);e.qx=t,e.qy=r,a=["Q",t,r].concat(s)}else if("Q"===r){const[t,n]=s;e.qx=t,e.qy=n}return a}function b(t){return Array.isArray(t)&&h(t)&&t.every(t=>{const n=t[0].toLowerCase();return e[n]===t.length-1&&"ACLMQZ".includes(t[0])})}function A(t){if(Array.isArray(t)&&b(t))return m(t);const e=f(t),n={x1:0,y1:0,x2:0,y2:0,x:0,y:0,qx:null,qy:null},r=[],s=e.length;let a,i,c="",o="";for(let t=0;t<s;t+=1)[c]=e[t],r[t]=c,t&&(o=r[t-1]),e[t]=M(e[t],n,o),a=e[t],i=a.length,n.x1=+a[i-2],n.y1=+a[i-1],n.x2=+a[i-4]||n.x1,n.y2=+a[i-3]||n.y1;return e}function v(t){const e=f(t),n="Z"===e.slice(-1)[0][0];let r=[],s=0;return r=A(e).map((t,n)=>(s=t.length,{seg:e[n],n:t,c:e[n][0],x:t[s-2],y:t[s-1]})).map((t,e,r)=>{const s=t.seg,a=t.n,i=e&&r[e-1],c=r[e+1]&&r[e+1],o=t.c,m=r.length,l=e?r[e-1].x:r[m-1].x,h=e?r[e-1].y:r[m-1].y;let u=[];switch(o){case"M":u=n?["Z"]:[o,l,h];break;case"A":u=s.slice(0,-3).concat([1===s[5]?0:1,l,h]);break;case"C":u=c&&"S"===c.c?["S",s[1],s[2],l,h]:[o,s[3],s[4],s[1],s[2],l,h];break;case"S":u=i&&"CS".indexOf(i.c)>-1&&(!c||c&&"S"!==c.c)?["C",a[3],a[4],a[1],a[2],l,h]:[o,a[1],a[2],l,h];break;case"Q":u=c&&"T"===c.c?["T",l,h]:s.slice(0,-2).concat([l,h]);break;case"T":u=i&&"QT".indexOf(i.c)>-1&&(!c||c&&"T"!==c.c)?["Q",a[1],a[2],l,h]:[o,l,h];break;case"Z":u=["M",l,h];break;case"H":u=[o,l];break;case"V":u=[o,h];break;default:u=s.slice(0,-2).concat([l,h])}return u}),n?r.reverse():[r[0]].concat(r.slice(1).reverse())}function w(t){return g(f(t),0).replace(/(m|M)/g,"|$1").split("|").map(t=>t.trim()).filter(t=>t)}function C(t,e){const n=d(f(t),e),r=d(x(t),e);return n.map((t,e)=>e?t.join("").length<r[e].join("").length?t:r[e]:t)}function N(t,e,n){return{x:t*Math.cos(n)-e*Math.sin(n),y:t*Math.sin(n)+e*Math.cos(n)}}function k(t,e,n,r,s,a,i,c,o,m){let l=t,h=e,u=n,y=r,f=c,p=o;const x=120*Math.PI/180,d=Math.PI/180*(+s||0);let g,M,b,A,v,w=[];if(m)[M,b,A,v]=m;else{g=N(l,h,-d),l=g.x,h=g.y,g=N(f,p,-d),f=g.x,p=g.y;const t=(l-f)/2,e=(h-p)/2;let n=t*t/(u*u)+e*e/(y*y);n>1&&(n=Math.sqrt(n),u*=n,y*=n);const r=u*u,s=y*y,c=(a===i?-1:1)*Math.sqrt(Math.abs((r*s-r*e*e-s*t*t)/(r*e*e+s*t*t)));A=c*u*e/y+(l+f)/2,v=c*-y*t/u+(h+p)/2,M=(Math.asin((h-v)/y)*10**9>>0)/10**9,b=(Math.asin((p-v)/y)*10**9>>0)/10**9,M=l<A?Math.PI-M:M,b=f<A?Math.PI-b:b,M<0&&(M=2*Math.PI+M),b<0&&(b=2*Math.PI+b),i&&M>b&&(M-=2*Math.PI),!i&&b>M&&(b-=2*Math.PI)}let C=b-M;if(Math.abs(C)>x){const t=b,e=f,n=p;b=M+x*(i&&b>M?1:-1),f=A+u*Math.cos(b),p=v+y*Math.sin(b),w=k(f,p,u,y,s,0,i,e,n,[b,t,A,v])}C=b-M;const S=Math.cos(M),q=Math.sin(M),P=Math.cos(b),I=Math.sin(b),T=Math.tan(C/4),$=4/3*u*T,V=4/3*y*T,z=[l,h],L=[l+$*q,h-V*S],j=[f+$*I,p-V*P],E=[f,p];if(L[0]=2*z[0]-L[0],L[1]=2*z[1]-L[1],m)return[L,j,E].concat(w);w=[L,j,E].concat(w).join().split(",");const O=[];for(let t=0,e=w.length;t<e;t+=1)O[t]=t%2?N(w[t-1],w[t],d).y:N(w[t],w[t+1],d).x;return O}function S(t,e,n,r,s,a){return[1/3*t+2/3*n,1/3*e+2/3*r,1/3*s+2/3*n,1/3*a+2/3*r,s,a]}function q(t,e,n,r,s,a,i,c,o){const m=1-o;return{x:m**3*t+m*m*3*o*n+3*m*o*o*s+o**3*i,y:m**3*e+m*m*3*o*r+3*m*o*o*a+o**3*c}}function P(t,e,n){const[r,s]=t,[a,i]=e;return[r+(a-r)*n,s+(i-s)*n]}function I(t,e,n,r){const s=.5,a=[t,e],i=[n,r],c=P(a,i,s),o=P(i,c,s),m=P(c,o,s),l=P(o,m,s),h=P(m,l,s),u=q.apply(0,a.concat(c,m,h,s)),y=q.apply(0,h.concat(l,o,i,0));return[u.x,u.y,y.x,y.y,n,r]}function T(t,e){"TQ".includes(t[0])||(e.qx=null,e.qy=null);const[n,r]=t.slice(1);switch(t[0]){case"M":return e.x=+n,e.y=+r,t;case"A":return["C"].concat(k.apply(0,[e.x1,e.y1].concat(t.slice(1))));case"Q":return e.qx=+n,e.qy=+r,["C"].concat(S.apply(0,[e.x1,e.y1].concat(t.slice(1))));case"L":return["C"].concat(I(e.x1,e.y1,t[1],t[2]));case"Z":return["C"].concat(I(e.x1,e.y1,e.x,e.y))}return t}function $(t,e,n){if(t[n].length>7){t[n].shift();const r=t[n];let s=n;for(;r.length;)e[n]="A",t.splice(s+=1,0,["C"].concat(r.splice(0,6)));t.splice(n,1)}}function V(t){const e=new Y,n=Array.from(t);if(!n.every(t=>!Number.isNaN(t)))throw TypeError(`CSSMatrix: "${t}" must only have numbers.`);if(16===n.length){const[t,r,s,a,i,c,o,m,l,h,u,y,f,p,x,d]=n;e.m11=t,e.a=t,e.m21=i,e.c=i,e.m31=l,e.m41=f,e.e=f,e.m12=r,e.b=r,e.m22=c,e.d=c,e.m32=h,e.m42=p,e.f=p,e.m13=s,e.m23=o,e.m33=u,e.m43=x,e.m14=a,e.m24=m,e.m34=y,e.m44=d}else{if(6!==n.length)throw new TypeError("CSSMatrix: expecting an Array of 6/16 values.");{const[t,r,s,a,i,c]=n;e.m11=t,e.a=t,e.m12=r,e.b=r,e.m21=s,e.c=s,e.m22=a,e.d=a,e.m41=i,e.e=i,e.m42=c,e.f=c}}return e}function z(t){const e=Object.keys(new Y);if("object"==typeof t&&e.every(e=>e in t))return V([t.m11,t.m12,t.m13,t.m14,t.m21,t.m22,t.m23,t.m24,t.m31,t.m32,t.m33,t.m34,t.m41,t.m42,t.m43,t.m44]);throw TypeError(`CSSMatrix: "${t}" is not a DOMMatrix / CSSMatrix / JSON compatible object.`)}function L(t){if("string"!=typeof t)throw TypeError(`CSSMatrix: "${t}" is not a string.`);const e=String(t).replace(/\s/g,"");let n=new Y;const r=`CSSMatrix: invalid transform string "${t}"`;return e.split(")").filter(t=>t).forEach(t=>{const[e,s]=t.split("(");if(!s)throw TypeError(r);const a=s.split(",").map(t=>t.includes("rad")?parseFloat(t)*(180/Math.PI):parseFloat(t)),[i,c,o,m]=a,l=[i,c,o],h=[i,c,o,m];if("perspective"===e&&i&&[c,o].every(t=>void 0===t))n.m34=-1/i;else if(e.includes("matrix")&&[6,16].includes(a.length)&&a.every(t=>!Number.isNaN(+t))){const t=a.map(t=>Math.abs(t)<1e-6?0:t);n=n.multiply(V(t))}else if("translate3d"===e&&l.every(t=>!Number.isNaN(+t)))n=n.translate(i,c,o);else if("translate"===e&&i&&void 0===o)n=n.translate(i,c||0,0);else if("rotate3d"===e&&h.every(t=>!Number.isNaN(+t))&&m)n=n.rotateAxisAngle(i,c,o,m);else if("rotate"===e&&i&&[c,o].every(t=>void 0===t))n=n.rotate(0,0,i);else if("scale3d"===e&&l.every(t=>!Number.isNaN(+t))&&l.some(t=>1!==t))n=n.scale(i,c,o);else if("scale"!==e||Number.isNaN(i)||1===i||void 0!==o)if("skew"===e&&i&&void 0===o)n=n.skewX(i),n=c?n.skewY(c):n;else{if(!(/[XYZ]/.test(e)&&i&&[c,o].every(t=>void 0===t)&&["translate","rotate","scale","skew"].some(t=>e.includes(t))))throw TypeError(r);if(["skewX","skewY"].includes(e))n=n[e](i);else{const t=e.replace(/[XYZ]/,""),r=e.replace(t,""),s=["X","Y","Z"].indexOf(r),a=[0===s?i:0,1===s?i:0,2===s?i:0];n=n[t](...a)}}else{const t=Number.isNaN(+c)?i:c;n=n.scale(i,t,1)}}),n}function j(t,e,n){const r=new Y;return r.m41=t,r.e=t,r.m42=e,r.f=e,r.m43=n,r}function E(t,e,n){const r=new Y,s=Math.PI/180,a=t*s,i=e*s,c=n*s,o=Math.cos(a),m=-Math.sin(a),l=Math.cos(i),h=-Math.sin(i),u=Math.cos(c),y=-Math.sin(c),f=l*u,p=-l*y;r.m11=f,r.a=f,r.m12=p,r.b=p,r.m13=h;const x=m*h*u+o*y;r.m21=x,r.c=x;const d=o*u-m*h*y;return r.m22=d,r.d=d,r.m23=-m*l,r.m31=m*y-o*h*u,r.m32=m*u+o*h*y,r.m33=o*l,r}function O(t,e,n,r){const s=new Y,a=r*(Math.PI/360),i=Math.sin(a),c=Math.cos(a),o=i*i,m=Math.sqrt(t*t+e*e+n*n);let l=t,h=e,u=n;0===m?(l=0,h=0,u=1):(l/=m,h/=m,u/=m);const y=l*l,f=h*h,p=u*u,x=1-2*(f+p)*o;s.m11=x,s.a=x;const d=2*(l*h*o+u*i*c);s.m12=d,s.b=d,s.m13=2*(l*u*o-h*i*c);const g=2*(h*l*o-u*i*c);s.m21=g,s.c=g;const M=1-2*(p+y)*o;return s.m22=M,s.d=M,s.m23=2*(h*u*o+l*i*c),s.m31=2*(u*l*o+h*i*c),s.m32=2*(u*h*o-l*i*c),s.m33=1-2*(y+f)*o,s}function Z(t,e,n){const r=new Y;return r.m11=t,r.a=t,r.m22=e,r.d=e,r.m33=n,r}function D(t){const e=new Y,n=t*Math.PI/180,r=Math.tan(n);return e.m21=r,e.c=r,e}function X(t){const e=new Y,n=t*Math.PI/180,r=Math.tan(n);return e.m12=r,e.b=r,e}function Q(t,e){return V([e.m11*t.m11+e.m12*t.m21+e.m13*t.m31+e.m14*t.m41,e.m11*t.m12+e.m12*t.m22+e.m13*t.m32+e.m14*t.m42,e.m11*t.m13+e.m12*t.m23+e.m13*t.m33+e.m14*t.m43,e.m11*t.m14+e.m12*t.m24+e.m13*t.m34+e.m14*t.m44,e.m21*t.m11+e.m22*t.m21+e.m23*t.m31+e.m24*t.m41,e.m21*t.m12+e.m22*t.m22+e.m23*t.m32+e.m24*t.m42,e.m21*t.m13+e.m22*t.m23+e.m23*t.m33+e.m24*t.m43,e.m21*t.m14+e.m22*t.m24+e.m23*t.m34+e.m24*t.m44,e.m31*t.m11+e.m32*t.m21+e.m33*t.m31+e.m34*t.m41,e.m31*t.m12+e.m32*t.m22+e.m33*t.m32+e.m34*t.m42,e.m31*t.m13+e.m32*t.m23+e.m33*t.m33+e.m34*t.m43,e.m31*t.m14+e.m32*t.m24+e.m33*t.m34+e.m34*t.m44,e.m41*t.m11+e.m42*t.m21+e.m43*t.m31+e.m44*t.m41,e.m41*t.m12+e.m42*t.m22+e.m43*t.m32+e.m44*t.m42,e.m41*t.m13+e.m42*t.m23+e.m43*t.m33+e.m44*t.m43,e.m41*t.m14+e.m42*t.m24+e.m43*t.m34+e.m44*t.m44])}class Y{constructor(...t){const e=this;if(e.a=1,e.b=0,e.c=0,e.d=1,e.e=0,e.f=0,e.m11=1,e.m12=0,e.m13=0,e.m14=0,e.m21=0,e.m22=1,e.m23=0,e.m24=0,e.m31=0,e.m32=0,e.m33=1,e.m34=0,e.m41=0,e.m42=0,e.m43=0,e.m44=1,t&&t.length){const n=[16,6].some(e=>e===t.length)?t:t[0];return e.setMatrixValue(n)}return e}set isIdentity(t){this.isIdentity=t}get isIdentity(){const t=this;return 1===t.m11&&0===t.m12&&0===t.m13&&0===t.m14&&0===t.m21&&1===t.m22&&0===t.m23&&0===t.m24&&0===t.m31&&0===t.m32&&1===t.m33&&0===t.m34&&0===t.m41&&0===t.m42&&0===t.m43&&1===t.m44}get is2D(){const t=this;return 0===t.m31&&0===t.m32&&1===t.m33&&0===t.m34&&0===t.m43&&1===t.m44}set is2D(t){this.is2D=t}setMatrixValue(t){return[Array,Float64Array,Float32Array].some(e=>t instanceof e)?V(t):"string"==typeof t&&t.length&&"none"!==t?L(t):"object"==typeof t?z(t):this}toArray(){const t=this;let e;return e=t.is2D?[t.a,t.b,t.c,t.d,t.e,t.f]:[t.m11,t.m12,t.m13,t.m14,t.m21,t.m22,t.m23,t.m24,t.m31,t.m32,t.m33,t.m34,t.m41,t.m42,t.m43,t.m44],e.map(t=>Math.abs(t)<1e-6?0:(t*10**6>>0)/10**6)}toString(){const t=this.toArray();return`${this.is2D?"matrix":"matrix3d"}(${t})`}toJSON(){const{is2D:t,isIdentity:e}=this;return{...this,is2D:t,isIdentity:e}}multiply(t){return Q(this,t)}translate(t,e,n){let r=e,s=n;return void 0===s&&(s=0),void 0===r&&(r=0),Q(this,j(t,r,s))}scale(t,e,n){let r=e,s=n;return void 0===r&&(r=t),void 0===s&&(s=1),Q(this,Z(t,r,s))}rotate(t,e,n){let r=t,s=e,a=n;return void 0===s&&(s=0),void 0===a&&(a=r,r=0),Q(this,E(r,s,a))}rotateAxisAngle(t,e,n,r){if([t,e,n,r].some(t=>Number.isNaN(t)))throw new TypeError("CSSMatrix: expecting 4 values");return Q(this,O(t,e,n,r))}skewX(t){return Q(this,D(t))}skewY(t){return Q(this,X(t))}transformPoint(t){let e=j(t.x,t.y,t.z);return e.m44=t.w||1,e=this.multiply(e),{x:e.m41,y:e.m42,z:e.m43,w:e.m44}}transform(t){const e=this,n=e.m11*t.x+e.m12*t.y+e.m13*t.z+e.m14*t.w,r=e.m21*t.x+e.m22*t.y+e.m23*t.z+e.m24*t.w,s=e.m31*t.x+e.m32*t.y+e.m33*t.z+e.m34*t.w,a=e.m41*t.x+e.m42*t.y+e.m43*t.z+e.m44*t.w;return{x:n/a,y:r/a,z:s/a,w:a}}}function H(t){let e=new Y;const{origin:n}=t,r=n[0],s=n[1],{translate:a}=t,{rotate:i}=t,{skew:c}=t,{scale:o}=t;return(Array.isArray(a)&&a.some(t=>0!=+t)||!Number.isNaN(a))&&(e=Array.isArray(a)?e.translate(+a[0]||0,+a[1]||0,+a[2]||0):e.translate(+a||0,0,0)),(i||c||o)&&(e=e.translate(+r,+s),i&&(e=Array.isArray(i)&&i.some(t=>0!=+t)?e.rotate(+i[0]||0,+i[1]||0,+i[2]||0):e.rotate(0,0,+i||0)),Array.isArray(c)&&c.some(t=>0!=+t)&&(Array.isArray(c)?(e=c[0]?e.skewX(+c[0]||0):e,e=c[1]?e.skewY(+c[1]||0):e):e=e.skewX(+c||0)),(!Number.isNaN(o)||Array.isArray(o)&&o.some(t=>1!=+t))&&(e=Array.isArray(o)?e.scale(+o[0]||1,+o[1]||1,+o[2]||1):e.scale(+o||1,+o||1,+o||1)),e=e.translate(-r,-s)),e}function R(t,e,n){const r=t.transformPoint({x:e[0],y:e[1],z:0,w:1}),s=n[0]||0,a=n[1]||0,i=n[2]||0,c=r.x-s,o=r.y-a,m=r.z-i;return[c*(Math.abs(i)/Math.abs(m))+s,o*(Math.abs(i)/Math.abs(m))+a]}function F(t,e){let n,r,s,a,i,c,o,l=0,h=0;const u=f(t),y=A(u),p=H(e),x=Object.keys(e),{origin:d}=e,{a:g,b:M,c:b,d:v,e:w,f:C}=p,N=[g,M,b,v,w,C],k={x1:0,y1:0,x2:0,y2:0,x:0,y:0,qx:null,qy:null};let S=[],q=0,P="",I=[];const V=[];let z=[];if(!p.isIdentity){for(n=0,s=u.length;n<s;n+=1)S=u[n],u[n]&&([P]=S),V[n]=P,"A"!==P||p.is2D&&["skewX","skewY"].find(t=>x.includes(t))||(S=T(y[n],k),u[n]=T(y[n],k),$(u,V,n),y[n]=T(y[n],k),$(y,V,n),s=Math.max(u.length,y.length)),S=y[n],q=S.length,k.x1=+S[q-2],k.y1=+S[q-1],k.x2=+S[q-4]||k.x1,k.y2=+S[q-3]||k.y1,z={s:u[n],c:u[n][0]},"Z"!==P&&(z.x=k.x1,z.y=k.y1),I=I.concat(z);return I.map(t=>{switch(P=t.c,S=t.s,P){case"A":return o=function(t,e,n,r){const s=Math.cos(r*Math.PI/180),a=Math.sin(r*Math.PI/180),i=[e*(t[0]*s+t[2]*a),e*(t[1]*s+t[3]*a),n*(-t[0]*a+t[2]*s),n*(-t[1]*a+t[3]*s)],c=i[0]*i[0]+i[2]*i[2],o=i[1]*i[1]+i[3]*i[3];let m=((i[0]-i[3])*(i[0]-i[3])+(i[2]+i[1])*(i[2]+i[1]))*((i[0]+i[3])*(i[0]+i[3])+(i[2]-i[1])*(i[2]-i[1]));const l=(c+o)/2;if(m<1e-9*l){const t=Math.sqrt(l);return{rx:t,ry:t,ax:0}}const h=i[0]*i[1]+i[2]*i[3];m=Math.sqrt(m);const u=l+m/2,y=l-m/2;let f,p,x=Math.abs(h)<1e-9&&Math.abs(u-o)<1e-9?90:Math.atan(Math.abs(h)>Math.abs(u-o)?(u-c)/h:h/(u-o)*180)/Math.PI;return x>=0?(f=Math.sqrt(u),p=Math.sqrt(y)):(x+=90,f=Math.sqrt(y),p=Math.sqrt(u)),{rx:f,ry:p,ax:x}}(N,S[1],S[2],S[3]),N[0]*N[3]-N[1]*N[2]<0&&(S[5]=+S[5]?0:1),[i,c]=R(p,[S[6],S[7]],d),S=l===i&&h===c||o.rx<1e-9*o.ry||o.ry<1e-9*o.rx?["L",i,c]:[P,o.rx,o.ry,o.ax,S[4],S[5],i,c],l=i,h=c,S;case"L":case"H":case"V":return[i,c]=R(p,[t.x,t.y],d),l!==i&&h!==c?S=["L",i,c]:h===c?S=["H",i]:l===i&&(S=["V",c]),l=i,h=c,S;default:for(r=1,a=S.length;r<a;r+=2)[l,h]=R(p,[S[r],S[r+1]],d),S[r]=l,S[r+1]=h;return S}})}return m(u)}function B(t,e,n,r,s,a,i,c){let o=s-2*n+t-(i-2*s+n),m=2*(n-t)-2*(s-n),l=t-n,h=(-m+Math.sqrt(m*m-4*o*l))/2/o,u=(-m-Math.sqrt(m*m-4*o*l))/2/o;const y=[e,c],f=[t,i];let p;return Math.abs(h)>"1e12"&&(h=.5),Math.abs(u)>"1e12"&&(u=.5),h>0&&h<1&&(p=q(t,e,n,r,s,a,i,c,h),f.push(p.x),y.push(p.y)),u>0&&u<1&&(p=q(t,e,n,r,s,a,i,c,u),f.push(p.x),y.push(p.y)),o=a-2*r+e-(c-2*a+r),m=2*(r-e)-2*(a-r),l=e-r,h=(-m+Math.sqrt(m*m-4*o*l))/2/o,u=(-m-Math.sqrt(m*m-4*o*l))/2/o,Math.abs(h)>"1e12"&&(h=.5),Math.abs(u)>"1e12"&&(u=.5),h>0&&h<1&&(p=q(t,e,n,r,s,a,i,c,h),f.push(p.x),y.push(p.y)),u>0&&u<1&&(p=q(t,e,n,r,s,a,i,c,u),f.push(p.x),y.push(p.y)),{min:{x:Math.min.apply(0,f),y:Math.min.apply(0,y)},max:{x:Math.max.apply(0,f),y:Math.max.apply(0,y)}}}function G(t){return Array.isArray(t)&&h(t)&&t.slice(1).every(t=>"C"===t[0])}function J(t){if(G(t))return m(t);const e=A(t),n={x1:0,y1:0,x2:0,y2:0,x:0,y:0,qx:null,qy:null},r=[];let s="",a=e.length;for(let t=0;t<a;t+=1){const i=e[t],c=i.length;i&&([s]=i),r[t]=s,e[t]=T(i,n),$(e,r,t),a=e.length,n.x1=+i[c-2],n.y1=+i[c-1],n.x2=+i[c-4]||n.x1,n.y2=+i[c-3]||n.y1}return e}function U(t){if(!t)return{x:0,y:0,width:0,height:0,x2:0,y2:0,cx:0,cy:0};const e=J(t);let n=0,r=0,s=[],a=[];e.forEach(t=>{const[e,i]=t.slice(-2);if("M"===t[0])n=+e,r=+i,s.push(e),a.push(i);else{const c=B.apply(0,[n,r].concat(t.slice(1)));s=s.concat(c.min.x,c.max.x),a=a.concat(c.min.y,c.max.y),n=+e,r=+i}});const i=Math.min.apply(0,s),c=Math.min.apply(0,a),o=Math.max.apply(0,s),m=Math.max.apply(0,a),l=o-i,h=m-c;return{width:l,height:h,x:i,y:c,x2:o,y2:m,cx:i+l/2,cy:c+h/2}}function K(t,e,n,r,s,a,i,c){return 3*((c-e)*(n+s)-(i-t)*(r+a)+r*(t-s)-n*(e-a)+c*(s+t/3)-i*(a+e/3))/20}function W(t){let e=0,n=0,r=0,s=0,a=0;return J(t).map(t=>{switch(t[0]){case"M":case"Z":return r="M"===t[0]?t[1]:r,s="M"===t[0]?t[2]:s,e=r,n=s,0;default:return a=K.apply(0,[e,n].concat(t.slice(1))),[e,n]=t.slice(-2),a}}).reduce((t,e)=>t+e,0)}function _(t,e,n,r,s){return s*(s*(-3*t+9*e-9*n+3*r)+6*t-12*e+6*n)-3*t+3*e}function tt(t,e,n,r,s,a,i,c,o){let m=o;(null===o||Number.isNaN(+o))&&(m=1),m>1&&(m=1),m<0&&(m=0);const l=m/2;let h=0,u=0,y=0,f=0;const p=[.2491,.2491,.2335,.2335,.2032,.2032,.1601,.1601,.1069,.1069,.0472,.0472];return[-.1252,.1252,-.3678,.3678,-.5873,.5873,-.7699,.7699,-.9041,.9041,-.9816,.9816].forEach((o,m)=>{h=l*o+l,u=_(t,n,s,i,h),y=_(e,r,a,c,h),f+=p[m]*Math.sqrt(u*u+y*y)}),l*f}Object.assign(Y,{Translate:j,Rotate:E,RotateAxisAngle:O,Scale:Z,SkewX:D,SkewY:X,Multiply:Q,fromArray:V,fromMatrix:z,fromString:L});const et={circle:["cx","cy","r"],ellipse:["cx","cy","rx","ry"],rect:["width","height","x","y","rx","ry"],polygon:["points"],polyline:["points"],glyph:[]};const nt={CSSMatrix:Y,parsePathString:u,isPathArray:h,isCurveArray:G,isAbsoluteArray:y,isRelativeArray:p,isNormalizedArray:b,isValidPath:function(t){if("string"!=typeof t)return!1;const e=new l(t);for(i(e);e.index<e.max&&!e.err.length;)o(e);return!e.err.length&&"mM".includes(e.segments[0][0])},pathToAbsolute:f,pathToRelative:x,pathToCurve:J,pathToString:g,getDrawDirection:function(t){return W(J(t))>=0},getPathArea:W,getPathBBox:U,getPathLength:function(t){let e=0;return J(t).forEach((t,n,r)=>{e+="M"===t[0]?0:tt.apply(0,r[n-1].slice(-2).concat(t.slice(1)))}),e},getPointAtLength:function(t,e){let n,r,s,a=0;return J(t).map((t,i,c)=>(r=i?c[i-1].slice(-2).concat(t.slice(1)):t.slice(1),n=i?tt.apply(0,r):0,a+=n,s=0===i?{x:r[0],y:r[1]}:a>e&&e>a-n?q.apply(0,r.concat(1-(a-e)/n)):null,s)).filter(t=>t).slice(-1)[0]},clonePath:m,splitPath:w,roundPath:d,optimizePath:C,reverseCurve:function(t){const e=t.slice(1).map((e,n,r)=>n?r[n-1].slice(-2).concat(e.slice(1)):t[0].slice(1).concat(e.slice(1))).map(t=>t.map((e,n)=>t[t.length-n-2*(1-n%2)])).reverse();return[["M"].concat(e[0].slice(0,2))].concat(e.map(t=>["C"].concat(t.slice(2))))},reversePath:v,normalizePath:A,transformPath:F,getSVGMatrix:H,shapeToPath:function(e,n){if(!Object.keys(et).concat(["glyph"]).some(t=>e.tagName===t))throw TypeError(`shapeToPath: ${e} is not SVGElement`);const r=document.createElementNS("http://www.w3.org/2000/svg","path"),s=e.tagName,a=et[s],i={};let c;i.type=s,a.forEach(t=>{i[t]=e.getAttribute(t)}),Object.values(e.attributes).forEach(({name:t,value:e})=>{a.includes(t)||r.setAttribute(t,e)});const{round:o,decimals:m}=t,l=o&&m?m:null;return"circle"===s?c=g(function(t){const{cx:e,cy:n,r:r}=t;return[["M",e-r,n],["a",r,r,0,1,0,2*r,0],["a",r,r,0,1,0,-2*r,0]]}(i),l):"ellipse"===s?c=g(function(t){const{cx:e,cy:n,rx:r,ry:s}=t;return[["M",e-r,n],["a",r,s,0,1,0,2*r,0],["a",r,s,0,1,0,-2*r,0]]}(i),l):["polyline","polygon"].includes(s)?c=g(function(t){const e=[],n=t.points.split(/[\s|,]/).map(Number);let r=0;for(;r<n.length;)e.push([r?"L":"M",n[r],n[r+1]]),r+=2;return"polygon"===t.type?e.concat([["z"]]):e}(i),l):"rect"===s?c=g(function(t){const e=+t.x||0,n=+t.y||0,r=+t.width,s=+t.height;let a=+t.rx,i=+t.ry;return a||i?(a=a||i,i=i||a,2*a>r&&(a-=(2*a-r)/2),2*i>s&&(i-=(2*i-s)/2),[["M",e+a,n],["h",r-2*a],["s",a,0,a,i],["v",s-2*i],["s",0,i,-a,i],["h",2*a-r],["s",-a,0,-a,-i],["v",2*i-s],["s",0,-i,a,-i]]):[["M",e,n],["h",r],["v",s],["H",e],["Z"]]}(i),l):"line"===s?c=g(function(t){const{x1:e,y1:n,x2:r,y2:s}=t;return[["M",+e,+n],["L",+r,+s]]}(i),l):"glyph"===s&&(c=e.getAttribute("d")),c?(r.setAttribute("d",c),n&&(e.before(r,e),e.remove()),r):null},options:t,Version:"0.1.11alpha2"};class rt{constructor(e,n){const r=n||{};let{round:s}=t;const{round:a}=r;(a&&0==+a||!1===a)&&(s=0);const{decimals:i}=s?r||t:{decimals:!1};return this.round=i,this.segments=u(e),this.pathValue=e,this}toAbsolute(){const{segments:t}=this;return this.segments=f(t),this}toRelative(){const{segments:t}=this;return this.segments=x(t),this}reverse(t){this.toAbsolute();const{segments:e}=this,n=w(this.toString()),r=n.length>1?n:0,s=r&&m(r).map((e,n)=>t?n?v(e):u(e):v(e));let a=[];return a=r?s.flat(1):t?e:v(e),this.segments=m(a),this}normalize(){const{segments:t}=this;return this.segments=A(t),this}optimize(){const{segments:t}=this;return this.segments=C(t,this.round),this}transform(t){if(!t||"object"!=typeof t||"object"==typeof t&&!["translate","rotate","skew","scale"].some(e=>e in t))return this;const e=t||{},{segments:n}=this;if(!e.origin){const t=U(n);e.origin=[+t.cx,+t.cy]}return this.segments=F(n,e),this}flipX(){return this.transform({rotate:[180,0,0]}),this}flipY(){return this.transform({rotate:[0,180,0]}),this}toString(){return g(this.segments,this.round)}}Object.assign(rt,nt);export{rt as default};
|