svg-path-commander 2.3.3 → 2.3.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/AGENTS.md +109 -43
- package/CHANGELOG.md +56 -1
- package/LICENSE +0 -0
- package/README.md +374 -345
- package/dist/index.d.ts +134 -270
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +216 -250
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +1 -1
- package/dist/util.d.ts +94 -248
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +212 -243
- package/dist/util.js.map +1 -1
- package/package.json +49 -44
package/dist/index.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* SVGPathCommander v2.3.
|
|
2
|
+
* SVGPathCommander ESM v2.3.5 (http://thednp.github.io/svg-path-commander)
|
|
3
3
|
* Copyright 2026 © thednp
|
|
4
4
|
* Licensed under MIT (https://github.com/thednp/svg-path-commander/blob/master/LICENSE)
|
|
5
5
|
*/
|
|
6
6
|
import CSSMatrix from "@thednp/dommatrix";
|
|
7
|
-
|
|
8
|
-
var version = "2.3.
|
|
9
|
-
|
|
10
|
-
//#region src/math/midPoint.ts
|
|
7
|
+
// package.json
|
|
8
|
+
var version = "2.3.5";
|
|
9
|
+
// src/math/midPoint.ts
|
|
11
10
|
/**
|
|
12
11
|
* Returns the coordinates of a specified distance
|
|
13
12
|
* ratio between two points.
|
|
@@ -20,8 +19,7 @@ var version = "2.3.3";
|
|
|
20
19
|
const midPoint = ([ax, ay], [bx, by], t) => {
|
|
21
20
|
return [ax + (bx - ax) * t, ay + (by - ay) * t];
|
|
22
21
|
};
|
|
23
|
-
|
|
24
|
-
//#region src/math/distanceSquareRoot.ts
|
|
22
|
+
// src/math/distanceSquareRoot.ts
|
|
25
23
|
/**
|
|
26
24
|
* Returns the square root of the distance
|
|
27
25
|
* between two given points.
|
|
@@ -33,8 +31,7 @@ const midPoint = ([ax, ay], [bx, by], t) => {
|
|
|
33
31
|
const distanceSquareRoot = (a, b) => {
|
|
34
32
|
return Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]));
|
|
35
33
|
};
|
|
36
|
-
|
|
37
|
-
//#region src/math/lineTools.ts
|
|
34
|
+
// src/math/lineTools.ts
|
|
38
35
|
/**
|
|
39
36
|
* Returns length for line segments (MoveTo, LineTo).
|
|
40
37
|
*
|
|
@@ -106,8 +103,7 @@ const lineTools = {
|
|
|
106
103
|
getLineLength,
|
|
107
104
|
getPointAtLineLength
|
|
108
105
|
};
|
|
109
|
-
|
|
110
|
-
//#region src/math/bezier.ts
|
|
106
|
+
// src/math/bezier.ts
|
|
111
107
|
/**
|
|
112
108
|
* Tools from bezier.js by Mike 'Pomax' Kamermans
|
|
113
109
|
* @see https://github.com/Pomax/bezierjs
|
|
@@ -396,8 +392,7 @@ const bezierTools = {
|
|
|
396
392
|
minmaxQ,
|
|
397
393
|
Tvalues
|
|
398
394
|
};
|
|
399
|
-
|
|
400
|
-
//#region src/math/arcTools.ts
|
|
395
|
+
// src/math/arcTools.ts
|
|
401
396
|
/**
|
|
402
397
|
* Returns the signed arc length of an ellipse segment from angle `0` up to
|
|
403
398
|
* the given `theta` angle, by integrating the curve speed
|
|
@@ -663,7 +658,7 @@ const getPointAtArcLength = (x1, y1, RX, RY, angle, LAF, SF, x, y, distance) =>
|
|
|
663
658
|
const getArcBBox = (x1, y1, RX, RY, angle, LAF, SF, x, y) => {
|
|
664
659
|
const { center, rx, ry, startAngle, endAngle } = getArcProps(x1, y1, RX, RY, angle, LAF, SF, x, y);
|
|
665
660
|
const deltaAngle = endAngle - startAngle;
|
|
666
|
-
const { min, max, tan, atan2, PI } = Math;
|
|
661
|
+
const { min, max, tan, atan2, cos, PI } = Math;
|
|
667
662
|
const { x: cx, y: cy } = center;
|
|
668
663
|
const alpha = angle * PI / 180;
|
|
669
664
|
const tangent = tan(alpha);
|
|
@@ -676,6 +671,11 @@ const getArcBBox = (x1, y1, RX, RY, angle, LAF, SF, x, y) => {
|
|
|
676
671
|
const angle2 = theta + PI;
|
|
677
672
|
const angle3 = atan2(ry, rx * tangent);
|
|
678
673
|
const angle4 = angle3 + PI;
|
|
674
|
+
const flipped = cos(alpha) < 0;
|
|
675
|
+
const rightAngle = flipped ? angle2 : angle1;
|
|
676
|
+
const leftAngle = flipped ? angle1 : angle2;
|
|
677
|
+
const topAngle = flipped ? angle3 : angle4;
|
|
678
|
+
const bottomAngle = flipped ? angle4 : angle3;
|
|
679
679
|
const xArray = [x];
|
|
680
680
|
const yArray = [y];
|
|
681
681
|
let xMin = min(x1, x);
|
|
@@ -693,22 +693,22 @@ const getArcBBox = (x1, y1, RX, RY, angle, LAF, SF, x, y) => {
|
|
|
693
693
|
* otherwise exclude elliptic extreme points
|
|
694
694
|
*/
|
|
695
695
|
if (pP2[0] > xMax || pP3[0] > xMax) {
|
|
696
|
-
const p1 = arcPoint(cx, cy, rx, ry, alpha,
|
|
696
|
+
const p1 = arcPoint(cx, cy, rx, ry, alpha, rightAngle);
|
|
697
697
|
xArray.push(p1[0]);
|
|
698
698
|
yArray.push(p1[1]);
|
|
699
699
|
}
|
|
700
700
|
if (pP2[0] < xMin || pP3[0] < xMin) {
|
|
701
|
-
const p2 = arcPoint(cx, cy, rx, ry, alpha,
|
|
701
|
+
const p2 = arcPoint(cx, cy, rx, ry, alpha, leftAngle);
|
|
702
702
|
xArray.push(p2[0]);
|
|
703
703
|
yArray.push(p2[1]);
|
|
704
704
|
}
|
|
705
705
|
if (pP2[1] < yMin || pP3[1] < yMin) {
|
|
706
|
-
const p4 = arcPoint(cx, cy, rx, ry, alpha,
|
|
706
|
+
const p4 = arcPoint(cx, cy, rx, ry, alpha, topAngle);
|
|
707
707
|
xArray.push(p4[0]);
|
|
708
708
|
yArray.push(p4[1]);
|
|
709
709
|
}
|
|
710
710
|
if (pP2[1] > yMax || pP3[1] > yMax) {
|
|
711
|
-
const p3 = arcPoint(cx, cy, rx, ry, alpha,
|
|
711
|
+
const p3 = arcPoint(cx, cy, rx, ry, alpha, bottomAngle);
|
|
712
712
|
xArray.push(p3[0]);
|
|
713
713
|
yArray.push(p3[1]);
|
|
714
714
|
}
|
|
@@ -735,8 +735,7 @@ const arcTools = {
|
|
|
735
735
|
getArcProps,
|
|
736
736
|
getPointAtArcLength
|
|
737
737
|
};
|
|
738
|
-
|
|
739
|
-
//#region src/math/cubicTools.ts
|
|
738
|
+
// src/math/cubicTools.ts
|
|
740
739
|
/**
|
|
741
740
|
* Returns a point at a given length of a CubicBezier segment.
|
|
742
741
|
*
|
|
@@ -867,8 +866,7 @@ const cubicTools = {
|
|
|
867
866
|
getPointAtCubicLength,
|
|
868
867
|
getPointAtCubicSegmentLength
|
|
869
868
|
};
|
|
870
|
-
|
|
871
|
-
//#region src/math/quadTools.ts
|
|
869
|
+
// src/math/quadTools.ts
|
|
872
870
|
/**
|
|
873
871
|
* Returns the {x,y} coordinates of a point at a
|
|
874
872
|
* given length of a quadratic-bezier segment.
|
|
@@ -988,8 +986,7 @@ const quadTools = {
|
|
|
988
986
|
getQuadBBox,
|
|
989
987
|
getQuadLength
|
|
990
988
|
};
|
|
991
|
-
|
|
992
|
-
//#region src/math/polygonTools.ts
|
|
989
|
+
// src/math/polygonTools.ts
|
|
993
990
|
/**
|
|
994
991
|
* d3-polygon-area
|
|
995
992
|
* @see https://github.com/d3/d3-polygon
|
|
@@ -1051,8 +1048,7 @@ const polygonTools = {
|
|
|
1051
1048
|
polygonLength,
|
|
1052
1049
|
polygonCentroid
|
|
1053
1050
|
};
|
|
1054
|
-
|
|
1055
|
-
//#region src/math/rotateVector.ts
|
|
1051
|
+
// src/math/rotateVector.ts
|
|
1056
1052
|
/**
|
|
1057
1053
|
* Returns an {x,y} vector rotated by a given
|
|
1058
1054
|
* angle in radian.
|
|
@@ -1069,8 +1065,7 @@ const rotateVector = (x, y, rad) => {
|
|
|
1069
1065
|
y: x * sin(rad) + y * cos(rad)
|
|
1070
1066
|
};
|
|
1071
1067
|
};
|
|
1072
|
-
|
|
1073
|
-
//#region src/math/roundTo.ts
|
|
1068
|
+
// src/math/roundTo.ts
|
|
1074
1069
|
/**
|
|
1075
1070
|
* Rounds a number to the specified number of decimal places.
|
|
1076
1071
|
*
|
|
@@ -1082,8 +1077,7 @@ const roundTo = (n, round) => {
|
|
|
1082
1077
|
const pow = round >= 1 ? 10 ** round : 1;
|
|
1083
1078
|
return round > 0 ? Math.round(n * pow) / pow : Math.round(n);
|
|
1084
1079
|
};
|
|
1085
|
-
|
|
1086
|
-
//#region src/options/options.ts
|
|
1080
|
+
// src/options/options.ts
|
|
1087
1081
|
/** SVGPathCommander default options */
|
|
1088
1082
|
const defaultOptions = {
|
|
1089
1083
|
origin: [
|
|
@@ -1093,8 +1087,7 @@ const defaultOptions = {
|
|
|
1093
1087
|
],
|
|
1094
1088
|
round: 4
|
|
1095
1089
|
};
|
|
1096
|
-
|
|
1097
|
-
//#region src/parser/paramsCount.ts
|
|
1090
|
+
// src/parser/paramsCount.ts
|
|
1098
1091
|
/** Segment params length */
|
|
1099
1092
|
const paramsCounts = {
|
|
1100
1093
|
a: 7,
|
|
@@ -1109,8 +1102,7 @@ const paramsCounts = {
|
|
|
1109
1102
|
v: 1,
|
|
1110
1103
|
z: 0
|
|
1111
1104
|
};
|
|
1112
|
-
|
|
1113
|
-
//#region src/parser/finalizeSegment.ts
|
|
1105
|
+
// src/parser/finalizeSegment.ts
|
|
1114
1106
|
/**
|
|
1115
1107
|
* Breaks the parsing of a pathString once a segment is finalized.
|
|
1116
1108
|
*
|
|
@@ -1142,12 +1134,10 @@ const finalizeSegment = (path) => {
|
|
|
1142
1134
|
if (!paramsCounts[relativeCommand]) break;
|
|
1143
1135
|
}
|
|
1144
1136
|
};
|
|
1145
|
-
|
|
1146
|
-
//#region src/util/error.ts
|
|
1137
|
+
// src/util/error.ts
|
|
1147
1138
|
/** Error prefix used in all SVGPathCommander TypeError messages. */
|
|
1148
1139
|
const error = "SVGPathCommanderError";
|
|
1149
|
-
|
|
1150
|
-
//#region src/parser/scanFlag.ts
|
|
1140
|
+
// src/parser/scanFlag.ts
|
|
1151
1141
|
/**
|
|
1152
1142
|
* Validates an A (arc-to) specific path command value.
|
|
1153
1143
|
* Usually a `large-arc-flag` or `sweep-flag`.
|
|
@@ -1169,8 +1159,7 @@ const scanFlag = (path) => {
|
|
|
1169
1159
|
}
|
|
1170
1160
|
path.err = `${error}: invalid Arc flag "${pathValue[index]}", expecting 0 or 1 at index ${index}`;
|
|
1171
1161
|
};
|
|
1172
|
-
|
|
1173
|
-
//#region src/parser/isDigit.ts
|
|
1162
|
+
// src/parser/isDigit.ts
|
|
1174
1163
|
/**
|
|
1175
1164
|
* Checks if a character is a digit.
|
|
1176
1165
|
*
|
|
@@ -1180,12 +1169,10 @@ const scanFlag = (path) => {
|
|
|
1180
1169
|
const isDigit = (code) => {
|
|
1181
1170
|
return code >= 48 && code <= 57;
|
|
1182
1171
|
};
|
|
1183
|
-
|
|
1184
|
-
//#region src/parser/invalidPathValue.ts
|
|
1172
|
+
// src/parser/invalidPathValue.ts
|
|
1185
1173
|
/** Error message prefix used when a path string cannot be parsed. */
|
|
1186
1174
|
const invalidPathValue = "Invalid path value";
|
|
1187
|
-
|
|
1188
|
-
//#region src/parser/scanParam.ts
|
|
1175
|
+
// src/parser/scanParam.ts
|
|
1189
1176
|
/**
|
|
1190
1177
|
* Validates every character of the path string,
|
|
1191
1178
|
* every path command, negative numbers or floating point numbers.
|
|
@@ -1308,8 +1295,7 @@ const scanNumber = (str, start, end) => {
|
|
|
1308
1295
|
if (scale >= 0) return sign * param * 10 ** scale;
|
|
1309
1296
|
return sign * param / 10 ** -scale;
|
|
1310
1297
|
};
|
|
1311
|
-
|
|
1312
|
-
//#region src/parser/isSpace.ts
|
|
1298
|
+
// src/parser/isSpace.ts
|
|
1313
1299
|
/**
|
|
1314
1300
|
* Checks if the character is a space.
|
|
1315
1301
|
*
|
|
@@ -1346,8 +1332,7 @@ const isSpace = (ch) => {
|
|
|
1346
1332
|
160
|
|
1347
1333
|
].includes(ch);
|
|
1348
1334
|
};
|
|
1349
|
-
|
|
1350
|
-
//#region src/parser/skipSpaces.ts
|
|
1335
|
+
// src/parser/skipSpaces.ts
|
|
1351
1336
|
/**
|
|
1352
1337
|
* Points the parser to the next character in the
|
|
1353
1338
|
* path string every time it encounters any kind of
|
|
@@ -1359,8 +1344,7 @@ const skipSpaces = (path) => {
|
|
|
1359
1344
|
const { pathValue, max } = path;
|
|
1360
1345
|
while (path.index < max && isSpace(pathValue.charCodeAt(path.index))) path.index += 1;
|
|
1361
1346
|
};
|
|
1362
|
-
|
|
1363
|
-
//#region src/parser/isPathCommand.ts
|
|
1347
|
+
// src/parser/isPathCommand.ts
|
|
1364
1348
|
/**
|
|
1365
1349
|
* Checks if the character is a path command.
|
|
1366
1350
|
*
|
|
@@ -1382,8 +1366,7 @@ const isPathCommand = (code) => {
|
|
|
1382
1366
|
default: return false;
|
|
1383
1367
|
}
|
|
1384
1368
|
};
|
|
1385
|
-
|
|
1386
|
-
//#region src/parser/isDigitStart.ts
|
|
1369
|
+
// src/parser/isDigitStart.ts
|
|
1387
1370
|
/**
|
|
1388
1371
|
* Checks if the character is or belongs to a number.
|
|
1389
1372
|
* [0-9]|+|-|.
|
|
@@ -1394,8 +1377,7 @@ const isPathCommand = (code) => {
|
|
|
1394
1377
|
const isDigitStart = (code) => {
|
|
1395
1378
|
return isDigit(code) || code === 43 || code === 45 || code === 46;
|
|
1396
1379
|
};
|
|
1397
|
-
|
|
1398
|
-
//#region src/parser/isArcCommand.ts
|
|
1380
|
+
// src/parser/isArcCommand.ts
|
|
1399
1381
|
/**
|
|
1400
1382
|
* Checks if the character is an A (arc-to) path command.
|
|
1401
1383
|
*
|
|
@@ -1405,8 +1387,7 @@ const isDigitStart = (code) => {
|
|
|
1405
1387
|
const isArcCommand = (code) => {
|
|
1406
1388
|
return (code | 32) === 97;
|
|
1407
1389
|
};
|
|
1408
|
-
|
|
1409
|
-
//#region src/parser/isMoveCommand.ts
|
|
1390
|
+
// src/parser/isMoveCommand.ts
|
|
1410
1391
|
/**
|
|
1411
1392
|
* Checks if the character is a MoveTo command.
|
|
1412
1393
|
*
|
|
@@ -1420,8 +1401,7 @@ const isMoveCommand = (code) => {
|
|
|
1420
1401
|
default: return false;
|
|
1421
1402
|
}
|
|
1422
1403
|
};
|
|
1423
|
-
|
|
1424
|
-
//#region src/parser/scanSegment.ts
|
|
1404
|
+
// src/parser/scanSegment.ts
|
|
1425
1405
|
/**
|
|
1426
1406
|
* Scans every character in the path string to determine
|
|
1427
1407
|
* where a segment starts and where it ends.
|
|
@@ -1466,8 +1446,7 @@ const scanSegment = (path) => {
|
|
|
1466
1446
|
}
|
|
1467
1447
|
finalizeSegment(path);
|
|
1468
1448
|
};
|
|
1469
|
-
|
|
1470
|
-
//#region src/parser/pathParser.ts
|
|
1449
|
+
// src/parser/pathParser.ts
|
|
1471
1450
|
/**
|
|
1472
1451
|
* The `PathParser` is used by the `parsePathString` static method
|
|
1473
1452
|
* to generate a `pathArray`.
|
|
@@ -1486,8 +1465,7 @@ var PathParser = class {
|
|
|
1486
1465
|
this.err = "";
|
|
1487
1466
|
}
|
|
1488
1467
|
};
|
|
1489
|
-
|
|
1490
|
-
//#region src/parser/parsePathString.ts
|
|
1468
|
+
// src/parser/parsePathString.ts
|
|
1491
1469
|
/**
|
|
1492
1470
|
* Parses a path string value and returns an array
|
|
1493
1471
|
* of segments we like to call `PathArray`.
|
|
@@ -1518,8 +1496,7 @@ const parsePathString = (pathInput) => {
|
|
|
1518
1496
|
} else throw TypeError(path.err);
|
|
1519
1497
|
return path.segments;
|
|
1520
1498
|
};
|
|
1521
|
-
|
|
1522
|
-
//#region src/process/absolutizeSegment.ts
|
|
1499
|
+
// src/process/absolutizeSegment.ts
|
|
1523
1500
|
/**
|
|
1524
1501
|
* Returns an absolute segment of a `PathArray` object.
|
|
1525
1502
|
*
|
|
@@ -1566,8 +1543,7 @@ const absolutizeSegment = (segment, index, lastX, lastY) => {
|
|
|
1566
1543
|
return [absCommand].concat(absValues);
|
|
1567
1544
|
}
|
|
1568
1545
|
};
|
|
1569
|
-
|
|
1570
|
-
//#region src/process/iterate.ts
|
|
1546
|
+
// src/process/iterate.ts
|
|
1571
1547
|
/**
|
|
1572
1548
|
* Iterates over a `PathArray`, executing a callback for each segment.
|
|
1573
1549
|
* The callback can:
|
|
@@ -1628,8 +1604,7 @@ const iterate = (path, iterator) => {
|
|
|
1628
1604
|
}
|
|
1629
1605
|
return path;
|
|
1630
1606
|
};
|
|
1631
|
-
|
|
1632
|
-
//#region src/convert/pathToAbsolute.ts
|
|
1607
|
+
// src/convert/pathToAbsolute.ts
|
|
1633
1608
|
/**
|
|
1634
1609
|
* Parses a path string value or object and returns an array
|
|
1635
1610
|
* of segments, all converted to absolute values.
|
|
@@ -1647,8 +1622,7 @@ const pathToAbsolute = (pathInput) => {
|
|
|
1647
1622
|
const path = parsePathString(pathInput);
|
|
1648
1623
|
return iterate(path, absolutizeSegment);
|
|
1649
1624
|
};
|
|
1650
|
-
|
|
1651
|
-
//#region src/process/relativizeSegment.ts
|
|
1625
|
+
// src/process/relativizeSegment.ts
|
|
1652
1626
|
/**
|
|
1653
1627
|
* Returns a relative segment of a `PathArray` object.
|
|
1654
1628
|
*
|
|
@@ -1686,8 +1660,7 @@ const relativizeSegment = (segment, index, lastX, lastY) => {
|
|
|
1686
1660
|
return [relCommand].concat(relValues);
|
|
1687
1661
|
}
|
|
1688
1662
|
};
|
|
1689
|
-
|
|
1690
|
-
//#region src/convert/pathToRelative.ts
|
|
1663
|
+
// src/convert/pathToRelative.ts
|
|
1691
1664
|
/**
|
|
1692
1665
|
* Parses a path string value or object and returns an array
|
|
1693
1666
|
* of segments, all converted to relative values.
|
|
@@ -1705,8 +1678,7 @@ const pathToRelative = (pathInput) => {
|
|
|
1705
1678
|
const path = parsePathString(pathInput);
|
|
1706
1679
|
return iterate(path, relativizeSegment);
|
|
1707
1680
|
};
|
|
1708
|
-
|
|
1709
|
-
//#region src/process/arcToCubic.ts
|
|
1681
|
+
// src/process/arcToCubic.ts
|
|
1710
1682
|
/**
|
|
1711
1683
|
* Converts A (arc-to) segments to C (cubic-bezier-to).
|
|
1712
1684
|
*
|
|
@@ -1818,8 +1790,7 @@ const arcToCubic = (X1, Y1, RX, RY, angle, LAF, SF, X2, Y2, recursive) => {
|
|
|
1818
1790
|
for (let i = 0, ii = res.length; i < ii; i += 1) newres[i] = i % 2 ? rotateVector(res[i - 1], res[i], rad).y : rotateVector(res[i], res[i + 1], rad).x;
|
|
1819
1791
|
return newres;
|
|
1820
1792
|
};
|
|
1821
|
-
|
|
1822
|
-
//#region src/process/quadToCubic.ts
|
|
1793
|
+
// src/process/quadToCubic.ts
|
|
1823
1794
|
/**
|
|
1824
1795
|
* Converts a Q (quadratic-bezier) segment to C (cubic-bezier).
|
|
1825
1796
|
*
|
|
@@ -1843,8 +1814,7 @@ const quadToCubic = (x1, y1, qx, qy, x2, y2) => {
|
|
|
1843
1814
|
y2
|
|
1844
1815
|
];
|
|
1845
1816
|
};
|
|
1846
|
-
|
|
1847
|
-
//#region src/process/lineToCubic.ts
|
|
1817
|
+
// src/process/lineToCubic.ts
|
|
1848
1818
|
/**
|
|
1849
1819
|
* Converts an L (line-to) segment to C (cubic-bezier).
|
|
1850
1820
|
*
|
|
@@ -1866,8 +1836,7 @@ const lineToCubic = (x1, y1, x2, y2) => {
|
|
|
1866
1836
|
y2
|
|
1867
1837
|
];
|
|
1868
1838
|
};
|
|
1869
|
-
|
|
1870
|
-
//#region src/process/segmentToCubic.ts
|
|
1839
|
+
// src/process/segmentToCubic.ts
|
|
1871
1840
|
/**
|
|
1872
1841
|
* Converts any segment to C (cubic-bezier).
|
|
1873
1842
|
*
|
|
@@ -1899,20 +1868,20 @@ const segmentToCubic = (segment, params) => {
|
|
|
1899
1868
|
else if (pathCommand === "Z") return ["C"].concat(lineToCubic(px1, py1, params.mx, params.my));
|
|
1900
1869
|
return segment;
|
|
1901
1870
|
};
|
|
1902
|
-
|
|
1903
|
-
//#region src/process/normalizeSegment.ts
|
|
1871
|
+
// src/process/normalizeSegment.ts
|
|
1904
1872
|
/**
|
|
1905
1873
|
* Normalizes a single segment of a `pathArray` object.
|
|
1906
1874
|
*
|
|
1907
1875
|
* @param segment the segment object
|
|
1908
1876
|
* @param params the normalization parameters
|
|
1877
|
+
* @param prevCommand the command of the previous segment
|
|
1909
1878
|
* @returns the normalized segment
|
|
1910
1879
|
*/
|
|
1911
|
-
const normalizeSegment = (segment, params) => {
|
|
1880
|
+
const normalizeSegment = (segment, params, prevCommand) => {
|
|
1912
1881
|
const [pathCommand] = segment;
|
|
1913
1882
|
const absCommand = pathCommand.toUpperCase();
|
|
1914
1883
|
const isRelative = pathCommand !== absCommand;
|
|
1915
|
-
const {
|
|
1884
|
+
const { x, y } = params;
|
|
1916
1885
|
const values = segment.slice(1);
|
|
1917
1886
|
let absValues = values.map((n, j) => n + (isRelative ? j % 2 ? y : x : 0));
|
|
1918
1887
|
if (!"TQ".includes(absCommand)) {
|
|
@@ -1925,11 +1894,11 @@ const normalizeSegment = (segment, params) => {
|
|
|
1925
1894
|
} else if (absCommand === "H") return [
|
|
1926
1895
|
"L",
|
|
1927
1896
|
segment[1] + (isRelative ? x : 0),
|
|
1928
|
-
|
|
1897
|
+
y
|
|
1929
1898
|
];
|
|
1930
1899
|
else if (absCommand === "V") return [
|
|
1931
1900
|
"L",
|
|
1932
|
-
|
|
1901
|
+
x,
|
|
1933
1902
|
segment[1] + (isRelative ? y : 0)
|
|
1934
1903
|
];
|
|
1935
1904
|
else if (absCommand === "L") return [
|
|
@@ -1944,18 +1913,15 @@ const normalizeSegment = (segment, params) => {
|
|
|
1944
1913
|
];
|
|
1945
1914
|
else if (absCommand === "C") return ["C"].concat(absValues);
|
|
1946
1915
|
else if (absCommand === "S") {
|
|
1947
|
-
const
|
|
1948
|
-
const y1 = py1 * 2 - py2;
|
|
1949
|
-
params.x1 = x1;
|
|
1950
|
-
params.y1 = y1;
|
|
1916
|
+
const canReflect = prevCommand != null && "CS".includes(prevCommand);
|
|
1951
1917
|
return [
|
|
1952
1918
|
"C",
|
|
1953
|
-
|
|
1954
|
-
|
|
1919
|
+
canReflect && params.x2 != null ? x * 2 - params.x2 : x,
|
|
1920
|
+
canReflect && params.y2 != null ? y * 2 - params.y2 : y
|
|
1955
1921
|
].concat(absValues);
|
|
1956
1922
|
} else if (absCommand === "T") {
|
|
1957
|
-
const qx = params.qx != null ?
|
|
1958
|
-
const qy = params.qy != null ?
|
|
1923
|
+
const qx = params.qx != null ? x * 2 - params.qx : x;
|
|
1924
|
+
const qy = params.qy != null ? y * 2 - params.qy : y;
|
|
1959
1925
|
params.qx = qx;
|
|
1960
1926
|
params.qy = qy;
|
|
1961
1927
|
return [
|
|
@@ -1971,8 +1937,7 @@ const normalizeSegment = (segment, params) => {
|
|
|
1971
1937
|
} else if (absCommand === "Z") return ["Z"];
|
|
1972
1938
|
return segment;
|
|
1973
1939
|
};
|
|
1974
|
-
|
|
1975
|
-
//#region src/parser/paramsParser.ts
|
|
1940
|
+
// src/parser/paramsParser.ts
|
|
1976
1941
|
/**
|
|
1977
1942
|
* Default parser parameters object used to track position state
|
|
1978
1943
|
* while iterating through path segments.
|
|
@@ -1982,15 +1947,14 @@ const paramsParser = {
|
|
|
1982
1947
|
my: 0,
|
|
1983
1948
|
x1: 0,
|
|
1984
1949
|
y1: 0,
|
|
1985
|
-
x2:
|
|
1986
|
-
y2:
|
|
1950
|
+
x2: null,
|
|
1951
|
+
y2: null,
|
|
1987
1952
|
x: 0,
|
|
1988
1953
|
y: 0,
|
|
1989
1954
|
qx: null,
|
|
1990
1955
|
qy: null
|
|
1991
1956
|
};
|
|
1992
|
-
|
|
1993
|
-
//#region src/convert/pathToCurve.ts
|
|
1957
|
+
// src/convert/pathToCurve.ts
|
|
1994
1958
|
/**
|
|
1995
1959
|
* Parses a path string or PathArray and returns a new one
|
|
1996
1960
|
* in which all segments are converted to cubic-bezier.
|
|
@@ -2007,10 +1971,11 @@ const paramsParser = {
|
|
|
2007
1971
|
const pathToCurve = (pathInput) => {
|
|
2008
1972
|
const params = { ...paramsParser };
|
|
2009
1973
|
const path = parsePathString(pathInput);
|
|
1974
|
+
let prevCommand = null;
|
|
2010
1975
|
return iterate(path, (seg, index, lastX, lastY) => {
|
|
2011
1976
|
params.x = lastX;
|
|
2012
1977
|
params.y = lastY;
|
|
2013
|
-
const normalSegment = normalizeSegment(seg, params);
|
|
1978
|
+
const normalSegment = normalizeSegment(seg, params, prevCommand);
|
|
2014
1979
|
if (normalSegment[0] === "M") {
|
|
2015
1980
|
params.mx = normalSegment[1];
|
|
2016
1981
|
params.my = normalSegment[2];
|
|
@@ -2023,13 +1988,18 @@ const pathToCurve = (pathInput) => {
|
|
|
2023
1988
|
const seglen = result.length;
|
|
2024
1989
|
params.x1 = +result[seglen - 2];
|
|
2025
1990
|
params.y1 = +result[seglen - 1];
|
|
2026
|
-
|
|
2027
|
-
|
|
1991
|
+
if (normalSegment[0] === "C") {
|
|
1992
|
+
params.x2 = +result[seglen - 4];
|
|
1993
|
+
params.y2 = +result[seglen - 3];
|
|
1994
|
+
} else {
|
|
1995
|
+
params.x2 = null;
|
|
1996
|
+
params.y2 = null;
|
|
1997
|
+
}
|
|
1998
|
+
prevCommand = normalSegment[0];
|
|
2028
1999
|
return result;
|
|
2029
2000
|
});
|
|
2030
2001
|
};
|
|
2031
|
-
|
|
2032
|
-
//#region src/convert/pathToString.ts
|
|
2002
|
+
// src/convert/pathToString.ts
|
|
2033
2003
|
/**
|
|
2034
2004
|
* Returns a valid `d` attribute string value created
|
|
2035
2005
|
* by rounding values and concatenating the PathArray segments.
|
|
@@ -2067,8 +2037,7 @@ const pathToString = (path, roundOption) => {
|
|
|
2067
2037
|
}
|
|
2068
2038
|
return result;
|
|
2069
2039
|
};
|
|
2070
|
-
|
|
2071
|
-
//#region src/util/getPathBBox.ts
|
|
2040
|
+
// src/util/getPathBBox.ts
|
|
2072
2041
|
/**
|
|
2073
2042
|
* Calculates the bounding box of a path.
|
|
2074
2043
|
*
|
|
@@ -2191,8 +2160,7 @@ const getPathBBox = (pathInput) => {
|
|
|
2191
2160
|
cz: Math.max(width, height) + Math.min(width, height) / 2
|
|
2192
2161
|
};
|
|
2193
2162
|
};
|
|
2194
|
-
|
|
2195
|
-
//#region src/util/getTotalLength.ts
|
|
2163
|
+
// src/util/getTotalLength.ts
|
|
2196
2164
|
/**
|
|
2197
2165
|
* Returns the total length of a path, equivalent to `shape.getTotalLength()`.
|
|
2198
2166
|
*
|
|
@@ -2257,12 +2225,10 @@ const getTotalLength = (pathInput) => {
|
|
|
2257
2225
|
});
|
|
2258
2226
|
return totalLength;
|
|
2259
2227
|
};
|
|
2260
|
-
|
|
2261
|
-
//#region src/util/distanceEpsilon.ts
|
|
2228
|
+
// src/util/distanceEpsilon.ts
|
|
2262
2229
|
/** Small threshold value used for floating-point distance comparisons in path calculations. */
|
|
2263
2230
|
const DISTANCE_EPSILON = 1e-5;
|
|
2264
|
-
|
|
2265
|
-
//#region src/process/normalizePath.ts
|
|
2231
|
+
// src/process/normalizePath.ts
|
|
2266
2232
|
/**
|
|
2267
2233
|
* Parses a path string or PathArray, then iterates the result for:
|
|
2268
2234
|
* * converting segments to absolute values
|
|
@@ -2280,20 +2246,26 @@ const DISTANCE_EPSILON = 1e-5;
|
|
|
2280
2246
|
const normalizePath = (pathInput) => {
|
|
2281
2247
|
const path = parsePathString(pathInput);
|
|
2282
2248
|
const params = { ...paramsParser };
|
|
2249
|
+
let prevCommand = null;
|
|
2283
2250
|
return iterate(path, (seg, _, lastX, lastY) => {
|
|
2284
2251
|
params.x = lastX;
|
|
2285
2252
|
params.y = lastY;
|
|
2286
|
-
const result = normalizeSegment(seg, params);
|
|
2253
|
+
const result = normalizeSegment(seg, params, prevCommand);
|
|
2287
2254
|
const seglen = result.length;
|
|
2288
2255
|
params.x1 = +result[seglen - 2];
|
|
2289
2256
|
params.y1 = +result[seglen - 1];
|
|
2290
|
-
|
|
2291
|
-
|
|
2257
|
+
if (result[0] === "C" || result[0] === "Q") {
|
|
2258
|
+
params.x2 = +result[seglen - 4];
|
|
2259
|
+
params.y2 = +result[seglen - 3];
|
|
2260
|
+
} else {
|
|
2261
|
+
params.x2 = null;
|
|
2262
|
+
params.y2 = null;
|
|
2263
|
+
}
|
|
2264
|
+
prevCommand = result[0];
|
|
2292
2265
|
return result;
|
|
2293
2266
|
});
|
|
2294
2267
|
};
|
|
2295
|
-
|
|
2296
|
-
//#region src/util/getPointAtLength.ts
|
|
2268
|
+
// src/util/getPointAtLength.ts
|
|
2297
2269
|
/**
|
|
2298
2270
|
* Returns [x,y] coordinates of a point at a given length along a path.
|
|
2299
2271
|
*
|
|
@@ -2360,8 +2332,7 @@ const getPointAtLength = (pathInput, distance) => {
|
|
|
2360
2332
|
});
|
|
2361
2333
|
return POINT;
|
|
2362
2334
|
};
|
|
2363
|
-
|
|
2364
|
-
//#region src/util/getPropertiesAtLength.ts
|
|
2335
|
+
// src/util/getPropertiesAtLength.ts
|
|
2365
2336
|
/**
|
|
2366
2337
|
* Returns the segment, its index and length as well as
|
|
2367
2338
|
* the length to that segment at a given length in a path.
|
|
@@ -2413,8 +2384,7 @@ const getPropertiesAtLength = (pathInput, distance) => {
|
|
|
2413
2384
|
}
|
|
2414
2385
|
return segments.find(({ lengthAtSegment: l }) => l <= distance);
|
|
2415
2386
|
};
|
|
2416
|
-
|
|
2417
|
-
//#region src/util/getPropertiesAtPoint.ts
|
|
2387
|
+
// src/util/getPropertiesAtPoint.ts
|
|
2418
2388
|
/**
|
|
2419
2389
|
* Returns the point and segment in path closest to a given point as well as
|
|
2420
2390
|
* the distance to the path stroke.
|
|
@@ -2484,8 +2454,7 @@ const getPropertiesAtPoint = (pathInput, point) => {
|
|
|
2484
2454
|
segment
|
|
2485
2455
|
};
|
|
2486
2456
|
};
|
|
2487
|
-
|
|
2488
|
-
//#region src/util/getClosestPoint.ts
|
|
2457
|
+
// src/util/getClosestPoint.ts
|
|
2489
2458
|
/**
|
|
2490
2459
|
* Returns the point in path closest to a given point.
|
|
2491
2460
|
*
|
|
@@ -2496,8 +2465,7 @@ const getPropertiesAtPoint = (pathInput, point) => {
|
|
|
2496
2465
|
const getClosestPoint = (pathInput, point) => {
|
|
2497
2466
|
return getPropertiesAtPoint(pathInput, point).closest;
|
|
2498
2467
|
};
|
|
2499
|
-
|
|
2500
|
-
//#region src/util/getPathArea.ts
|
|
2468
|
+
// src/util/getPathArea.ts
|
|
2501
2469
|
/**
|
|
2502
2470
|
* Returns the area of a single cubic-bezier segment.
|
|
2503
2471
|
*
|
|
@@ -2548,8 +2516,7 @@ const getPathArea = (path) => {
|
|
|
2548
2516
|
}
|
|
2549
2517
|
}).reduce((a, b) => a + b, 0);
|
|
2550
2518
|
};
|
|
2551
|
-
|
|
2552
|
-
//#region src/util/getDrawDirection.ts
|
|
2519
|
+
// src/util/getDrawDirection.ts
|
|
2553
2520
|
/**
|
|
2554
2521
|
* Check if a path is drawn clockwise and returns true if so,
|
|
2555
2522
|
* false otherwise.
|
|
@@ -2560,8 +2527,7 @@ const getPathArea = (path) => {
|
|
|
2560
2527
|
const getDrawDirection = (path) => {
|
|
2561
2528
|
return getPathArea(pathToCurve(path)) >= 0;
|
|
2562
2529
|
};
|
|
2563
|
-
|
|
2564
|
-
//#region src/util/getSegmentAtLength.ts
|
|
2530
|
+
// src/util/getSegmentAtLength.ts
|
|
2565
2531
|
/**
|
|
2566
2532
|
* Returns the segment at a given length.
|
|
2567
2533
|
*
|
|
@@ -2572,8 +2538,7 @@ const getDrawDirection = (path) => {
|
|
|
2572
2538
|
const getSegmentAtLength = (pathInput, distance) => {
|
|
2573
2539
|
return getPropertiesAtLength(pathInput, distance).segment;
|
|
2574
2540
|
};
|
|
2575
|
-
|
|
2576
|
-
//#region src/util/getSegmentOfPoint.ts
|
|
2541
|
+
// src/util/getSegmentOfPoint.ts
|
|
2577
2542
|
/**
|
|
2578
2543
|
* Returns the path segment which contains a given point.
|
|
2579
2544
|
*
|
|
@@ -2584,8 +2549,7 @@ const getSegmentAtLength = (pathInput, distance) => {
|
|
|
2584
2549
|
const getSegmentOfPoint = (path, point) => {
|
|
2585
2550
|
return getPropertiesAtPoint(path, point).segment;
|
|
2586
2551
|
};
|
|
2587
|
-
|
|
2588
|
-
//#region src/util/isPathArray.ts
|
|
2552
|
+
// src/util/isPathArray.ts
|
|
2589
2553
|
/**
|
|
2590
2554
|
* Iterates an array to check if it's an actual `pathArray`.
|
|
2591
2555
|
*
|
|
@@ -2598,8 +2562,7 @@ const isPathArray = (path) => {
|
|
|
2598
2562
|
return paramsCounts[lk] === seg.length - 1 && "achlmqstvz".includes(lk) && seg.slice(1).every(Number.isFinite);
|
|
2599
2563
|
}) && path.length > 0;
|
|
2600
2564
|
};
|
|
2601
|
-
|
|
2602
|
-
//#region src/util/isAbsoluteArray.ts
|
|
2565
|
+
// src/util/isAbsoluteArray.ts
|
|
2603
2566
|
/**
|
|
2604
2567
|
* Iterates an array to check if it's a `pathArray`
|
|
2605
2568
|
* with all absolute values.
|
|
@@ -2610,8 +2573,7 @@ const isPathArray = (path) => {
|
|
|
2610
2573
|
const isAbsoluteArray = (path) => {
|
|
2611
2574
|
return isPathArray(path) && path.every(([x]) => x === x.toUpperCase());
|
|
2612
2575
|
};
|
|
2613
|
-
|
|
2614
|
-
//#region src/util/isNormalizedArray.ts
|
|
2576
|
+
// src/util/isNormalizedArray.ts
|
|
2615
2577
|
/**
|
|
2616
2578
|
* Iterates an array to check if it's a `pathArray`
|
|
2617
2579
|
* with all segments in non-shorthand notation
|
|
@@ -2623,8 +2585,7 @@ const isAbsoluteArray = (path) => {
|
|
|
2623
2585
|
const isNormalizedArray = (path) => {
|
|
2624
2586
|
return isAbsoluteArray(path) && path.every(([pc]) => "ACLMQZ".includes(pc));
|
|
2625
2587
|
};
|
|
2626
|
-
|
|
2627
|
-
//#region src/util/isPolygonArray.ts
|
|
2588
|
+
// src/util/isPolygonArray.ts
|
|
2628
2589
|
/**
|
|
2629
2590
|
* Checks if a path is a polygon (only M, L, H, V, Z commands).
|
|
2630
2591
|
* @param pathArray PathArray (pre-normalize if needed)
|
|
@@ -2633,8 +2594,7 @@ const isNormalizedArray = (path) => {
|
|
|
2633
2594
|
const isPolygonArray = (path) => {
|
|
2634
2595
|
return isNormalizedArray(path) && path.every(([pc]) => "MLVHZ".includes(pc));
|
|
2635
2596
|
};
|
|
2636
|
-
|
|
2637
|
-
//#region src/util/isCurveArray.ts
|
|
2597
|
+
// src/util/isCurveArray.ts
|
|
2638
2598
|
/**
|
|
2639
2599
|
* Iterates an array to check if it's a `pathArray`
|
|
2640
2600
|
* with all C (cubic bezier) segments.
|
|
@@ -2645,8 +2605,7 @@ const isPolygonArray = (path) => {
|
|
|
2645
2605
|
const isCurveArray = (path) => {
|
|
2646
2606
|
return isNormalizedArray(path) && path.every(([pc]) => "MC".includes(pc));
|
|
2647
2607
|
};
|
|
2648
|
-
|
|
2649
|
-
//#region src/util/isPointInStroke.ts
|
|
2608
|
+
// src/util/isPointInStroke.ts
|
|
2650
2609
|
/**
|
|
2651
2610
|
* Checks if a given point is in the stroke of a path.
|
|
2652
2611
|
*
|
|
@@ -2658,8 +2617,7 @@ const isPointInStroke = (pathInput, point) => {
|
|
|
2658
2617
|
const { distance } = getPropertiesAtPoint(pathInput, point);
|
|
2659
2618
|
return Math.abs(distance) < DISTANCE_EPSILON;
|
|
2660
2619
|
};
|
|
2661
|
-
|
|
2662
|
-
//#region src/util/isRelativeArray.ts
|
|
2620
|
+
// src/util/isRelativeArray.ts
|
|
2663
2621
|
/**
|
|
2664
2622
|
* Iterates an array to check if it's a `pathArray`
|
|
2665
2623
|
* with relative values.
|
|
@@ -2670,8 +2628,7 @@ const isPointInStroke = (pathInput, point) => {
|
|
|
2670
2628
|
const isRelativeArray = (path) => {
|
|
2671
2629
|
return isPathArray(path) && path.slice(1).every(([pc]) => pc === pc.toLowerCase());
|
|
2672
2630
|
};
|
|
2673
|
-
|
|
2674
|
-
//#region src/util/isValidPath.ts
|
|
2631
|
+
// src/util/isValidPath.ts
|
|
2675
2632
|
/**
|
|
2676
2633
|
* Parses a path string value to determine its validity
|
|
2677
2634
|
* then returns true if it's valid or false otherwise.
|
|
@@ -2686,8 +2643,7 @@ const isValidPath = (pathString) => {
|
|
|
2686
2643
|
while (path.index < path.max && !path.err.length) scanSegment(path);
|
|
2687
2644
|
return !path.err.length && "mM".includes(path.segments[0][0]);
|
|
2688
2645
|
};
|
|
2689
|
-
|
|
2690
|
-
//#region src/morph/samplePolygon.ts
|
|
2646
|
+
// src/morph/samplePolygon.ts
|
|
2691
2647
|
/**
|
|
2692
2648
|
* Samples points from a path to form a polygon approximation.
|
|
2693
2649
|
* Collects endpoints of each segment (M start + ends of L/C/etc).
|
|
@@ -2713,8 +2669,7 @@ function samplePolygon(path) {
|
|
|
2713
2669
|
});
|
|
2714
2670
|
return points;
|
|
2715
2671
|
}
|
|
2716
|
-
|
|
2717
|
-
//#region src/util/shapeParams.ts
|
|
2672
|
+
// src/util/shapeParams.ts
|
|
2718
2673
|
/**
|
|
2719
2674
|
* Supported shapes and their specific parameters.
|
|
2720
2675
|
*/
|
|
@@ -2748,8 +2703,7 @@ const shapeParams = {
|
|
|
2748
2703
|
polyline: ["points"],
|
|
2749
2704
|
glyph: ["d"]
|
|
2750
2705
|
};
|
|
2751
|
-
|
|
2752
|
-
//#region src/util/isElement.ts
|
|
2706
|
+
// src/util/isElement.ts
|
|
2753
2707
|
/**
|
|
2754
2708
|
* Checks if a value is a DOM Element.
|
|
2755
2709
|
*
|
|
@@ -2757,8 +2711,7 @@ const shapeParams = {
|
|
|
2757
2711
|
* @returns True if the value is a DOM Element (nodeType === 1)
|
|
2758
2712
|
*/
|
|
2759
2713
|
const isElement = (node) => node !== void 0 && node !== null && typeof node === "object" && node.nodeType === 1;
|
|
2760
|
-
|
|
2761
|
-
//#region src/util/shapeToPathArray.ts
|
|
2714
|
+
// src/util/shapeToPathArray.ts
|
|
2762
2715
|
/**
|
|
2763
2716
|
* Returns a new PathArray from line attributes.
|
|
2764
2717
|
*
|
|
@@ -3018,8 +2971,7 @@ const shapeToPathArray = (element) => {
|
|
|
3018
2971
|
if (isPathArray(pathArray) && pathArray.length) return pathArray;
|
|
3019
2972
|
return false;
|
|
3020
2973
|
};
|
|
3021
|
-
|
|
3022
|
-
//#region src/util/shapeToPath.ts
|
|
2974
|
+
// src/util/shapeToPath.ts
|
|
3023
2975
|
/**
|
|
3024
2976
|
* Returns a new `<path>` element created from attributes of a `<line>`, `<polyline>`,
|
|
3025
2977
|
* `<polygon>`, `<rect>`, `<ellipse>`, `<circle>` or `<glyph>`. If `replace` parameter
|
|
@@ -3087,8 +3039,7 @@ const shapeToPath = (element, replace, ownerDocument) => {
|
|
|
3087
3039
|
}
|
|
3088
3040
|
return false;
|
|
3089
3041
|
};
|
|
3090
|
-
|
|
3091
|
-
//#region src/util/isMultiPath.ts
|
|
3042
|
+
// src/util/isMultiPath.ts
|
|
3092
3043
|
/**
|
|
3093
3044
|
* Determines if an SVG path contains multiple subpaths.
|
|
3094
3045
|
* Accepts path string or PathArray.
|
|
@@ -3110,8 +3061,7 @@ const isMultiPath = (path) => {
|
|
|
3110
3061
|
}
|
|
3111
3062
|
throw new TypeError(error + ": expected string or PathArray");
|
|
3112
3063
|
};
|
|
3113
|
-
|
|
3114
|
-
//#region src/util/isPolylineArray.ts
|
|
3064
|
+
// src/util/isPolylineArray.ts
|
|
3115
3065
|
/**
|
|
3116
3066
|
* Checks if a path is a polyline (only M, L, H, V commands).
|
|
3117
3067
|
* @param pathArray PathArray (pre-normalize if needed)
|
|
@@ -3120,8 +3070,7 @@ const isMultiPath = (path) => {
|
|
|
3120
3070
|
function isPolylineArray(path) {
|
|
3121
3071
|
return isNormalizedArray(path) && path.every(([pc]) => "MLVH".includes(pc));
|
|
3122
3072
|
}
|
|
3123
|
-
|
|
3124
|
-
//#region src/util/isClosedPath.ts
|
|
3073
|
+
// src/util/isClosedPath.ts
|
|
3125
3074
|
/**
|
|
3126
3075
|
* Check if a PathArray is closed, which means its last segment is a Z.
|
|
3127
3076
|
* @param path
|
|
@@ -3130,8 +3079,7 @@ function isPolylineArray(path) {
|
|
|
3130
3079
|
const isClosedPath = (path) => {
|
|
3131
3080
|
return path[path.length - 1][0].toUpperCase() === "Z";
|
|
3132
3081
|
};
|
|
3133
|
-
|
|
3134
|
-
//#region src/process/shortenSegment.ts
|
|
3082
|
+
// src/process/shortenSegment.ts
|
|
3135
3083
|
/**
|
|
3136
3084
|
* Shorten a single segment of a `pathArray` object.
|
|
3137
3085
|
*
|
|
@@ -3146,7 +3094,7 @@ const shortenSegment = (segment, normalSegment, params, prevCommand) => {
|
|
|
3146
3094
|
const { round: defaultRound } = defaultOptions;
|
|
3147
3095
|
const round = typeof defaultRound === "number" ? defaultRound : 4;
|
|
3148
3096
|
const normalValues = normalSegment.slice(1);
|
|
3149
|
-
const {
|
|
3097
|
+
const { x2, y2, x, y } = params;
|
|
3150
3098
|
const [nx, ny] = normalValues.slice(-2);
|
|
3151
3099
|
const result = segment;
|
|
3152
3100
|
if (!"TQ".includes(pathCommand)) {
|
|
@@ -3158,9 +3106,7 @@ const shortenSegment = (segment, normalSegment, params, prevCommand) => {
|
|
|
3158
3106
|
else if (roundTo(y, round) === roundTo(ny, round)) return ["H", nx];
|
|
3159
3107
|
} else if (pathCommand === "C") {
|
|
3160
3108
|
const [nx1, ny1] = normalValues;
|
|
3161
|
-
|
|
3162
|
-
params.y1 = ny1;
|
|
3163
|
-
if ("CS".includes(prevCommand) && (roundTo(nx1, round) === roundTo(x1 * 2 - x2, round) && roundTo(ny1, round) === roundTo(y1 * 2 - y2, round) || roundTo(x1, round) === roundTo(x2 * 2 - x, round) && roundTo(y1, round) === roundTo(y2 * 2 - y, round))) return [
|
|
3109
|
+
if ("CS".includes(prevCommand) && x2 != null && y2 != null && roundTo(nx1, round) === roundTo(x * 2 - x2, round) && roundTo(ny1, round) === roundTo(y * 2 - y2, round)) return [
|
|
3164
3110
|
"S",
|
|
3165
3111
|
normalValues[2],
|
|
3166
3112
|
normalValues[3],
|
|
@@ -3171,7 +3117,7 @@ const shortenSegment = (segment, normalSegment, params, prevCommand) => {
|
|
|
3171
3117
|
const [qx, qy] = normalValues;
|
|
3172
3118
|
params.qx = qx;
|
|
3173
3119
|
params.qy = qy;
|
|
3174
|
-
if ("QT".includes(prevCommand) && roundTo(qx, round) === roundTo(
|
|
3120
|
+
if ("QT".includes(prevCommand) && x2 != null && y2 != null && roundTo(qx, round) === roundTo(x * 2 - x2, round) && roundTo(qy, round) === roundTo(y * 2 - y2, round)) return [
|
|
3175
3121
|
"T",
|
|
3176
3122
|
normalValues[2],
|
|
3177
3123
|
normalValues[3]
|
|
@@ -3179,8 +3125,7 @@ const shortenSegment = (segment, normalSegment, params, prevCommand) => {
|
|
|
3179
3125
|
}
|
|
3180
3126
|
return result;
|
|
3181
3127
|
};
|
|
3182
|
-
|
|
3183
|
-
//#region src/process/roundSegment.ts
|
|
3128
|
+
// src/process/roundSegment.ts
|
|
3184
3129
|
/**
|
|
3185
3130
|
* Rounds the numeric values of a path segment to the specified precision.
|
|
3186
3131
|
*
|
|
@@ -3192,8 +3137,7 @@ const roundSegment = (segment, roundOption) => {
|
|
|
3192
3137
|
const values = segment.slice(1).map((n) => roundTo(n, roundOption));
|
|
3193
3138
|
return [segment[0]].concat(values);
|
|
3194
3139
|
};
|
|
3195
|
-
|
|
3196
|
-
//#region src/process/optimizePath.ts
|
|
3140
|
+
// src/process/optimizePath.ts
|
|
3197
3141
|
/**
|
|
3198
3142
|
* Optimizes a PathArray:
|
|
3199
3143
|
* * converts segments to shorthand if possible
|
|
@@ -3219,12 +3163,12 @@ const optimizePath = (pathInput, roundOption) => {
|
|
|
3219
3163
|
return iterate(path, (seg, i, lastX, lastY) => {
|
|
3220
3164
|
optimParams.x = lastX;
|
|
3221
3165
|
optimParams.y = lastY;
|
|
3222
|
-
const normalizedSegment = normalizeSegment(seg, optimParams);
|
|
3223
3166
|
let result = seg;
|
|
3224
3167
|
pathCommand = seg[0];
|
|
3225
3168
|
allPathCommands[i] = pathCommand;
|
|
3169
|
+
if (i) prevCommand = allPathCommands[i - 1];
|
|
3170
|
+
const normalizedSegment = normalizeSegment(seg, optimParams, i ? prevCommand : null);
|
|
3226
3171
|
if (i) {
|
|
3227
|
-
prevCommand = allPathCommands[i - 1];
|
|
3228
3172
|
const shortSegment = shortenSegment(seg, normalizedSegment, optimParams, prevCommand);
|
|
3229
3173
|
const absSegment = roundSegment(shortSegment, round);
|
|
3230
3174
|
const absString = absSegment.join("");
|
|
@@ -3236,31 +3180,48 @@ const optimizePath = (pathInput, roundOption) => {
|
|
|
3236
3180
|
const seglen = normalizedSegment.length;
|
|
3237
3181
|
optimParams.x1 = +normalizedSegment[seglen - 2];
|
|
3238
3182
|
optimParams.y1 = +normalizedSegment[seglen - 1];
|
|
3239
|
-
|
|
3240
|
-
|
|
3183
|
+
if (normalizedSegment[0] === "C" || normalizedSegment[0] === "Q") {
|
|
3184
|
+
optimParams.x2 = +normalizedSegment[seglen - 4];
|
|
3185
|
+
optimParams.y2 = +normalizedSegment[seglen - 3];
|
|
3186
|
+
} else {
|
|
3187
|
+
optimParams.x2 = null;
|
|
3188
|
+
optimParams.y2 = null;
|
|
3189
|
+
}
|
|
3241
3190
|
return result;
|
|
3242
3191
|
});
|
|
3243
3192
|
};
|
|
3244
|
-
|
|
3245
|
-
//#region src/process/reversePath.ts
|
|
3193
|
+
// src/process/reversePath.ts
|
|
3246
3194
|
/**
|
|
3247
|
-
* Reverses
|
|
3195
|
+
* Reverses the segments of a single sub-path and returns a new PathArray
|
|
3248
3196
|
* with absolute values.
|
|
3249
3197
|
*
|
|
3250
|
-
* @param
|
|
3198
|
+
* @param absolutePath - The absolute PathArray of a single sub-path
|
|
3251
3199
|
* @returns The reversed PathArray
|
|
3252
|
-
*
|
|
3253
|
-
* @example
|
|
3254
|
-
* ```ts
|
|
3255
|
-
* reversePath([['M', 0, 0], ['L', 100, 0], ['L', 100, 100], ['L', 0, 100], ['Z']])
|
|
3256
|
-
* // => [['M', 0, 100], ['L', 0, 0], ['L', 100, 0], ['L', 100, 100], ['Z']]
|
|
3257
|
-
* ```
|
|
3258
3200
|
*/
|
|
3259
|
-
const
|
|
3260
|
-
const absolutePath = pathToAbsolute(pathInput);
|
|
3201
|
+
const reverseSubPath = (absolutePath) => {
|
|
3261
3202
|
const normalizedPath = normalizePath(absolutePath);
|
|
3262
3203
|
const pLen = absolutePath.length;
|
|
3263
3204
|
const isClosed = absolutePath[pLen - 1][0] === "Z";
|
|
3205
|
+
const endPoints = [];
|
|
3206
|
+
let endX = 0;
|
|
3207
|
+
let endY = 0;
|
|
3208
|
+
let subX = 0;
|
|
3209
|
+
let subY = 0;
|
|
3210
|
+
for (const seg of normalizedPath) {
|
|
3211
|
+
if (seg[0] === "M") {
|
|
3212
|
+
subX = +seg[1];
|
|
3213
|
+
subY = +seg[2];
|
|
3214
|
+
endX = subX;
|
|
3215
|
+
endY = subY;
|
|
3216
|
+
} else if (seg[0] === "Z") {
|
|
3217
|
+
endX = subX;
|
|
3218
|
+
endY = subY;
|
|
3219
|
+
} else {
|
|
3220
|
+
endX = +seg[seg.length - 2];
|
|
3221
|
+
endY = +seg[seg.length - 1];
|
|
3222
|
+
}
|
|
3223
|
+
endPoints.push([endX, endY]);
|
|
3224
|
+
}
|
|
3264
3225
|
const reversedPath = iterate(absolutePath, (segment, i) => {
|
|
3265
3226
|
const normalizedSegment = normalizedPath[i];
|
|
3266
3227
|
const prevSeg = i && absolutePath[i - 1];
|
|
@@ -3268,7 +3229,7 @@ const reversePath = (pathInput) => {
|
|
|
3268
3229
|
const nextSeg = absolutePath[i + 1];
|
|
3269
3230
|
const nextCommand = nextSeg && nextSeg[0];
|
|
3270
3231
|
const pathCommand = segment[0];
|
|
3271
|
-
const [x, y] =
|
|
3232
|
+
const [x, y] = endPoints[i ? i - 1 : pLen - 1];
|
|
3272
3233
|
let result = segment;
|
|
3273
3234
|
switch (pathCommand) {
|
|
3274
3235
|
case "M":
|
|
@@ -3309,17 +3270,17 @@ const reversePath = (pathInput) => {
|
|
|
3309
3270
|
];
|
|
3310
3271
|
break;
|
|
3311
3272
|
case "S":
|
|
3312
|
-
if (
|
|
3313
|
-
|
|
3314
|
-
normalizedSegment[3],
|
|
3315
|
-
normalizedSegment[4],
|
|
3273
|
+
if (nextSeg && nextCommand === "S") result = [
|
|
3274
|
+
pathCommand,
|
|
3316
3275
|
normalizedSegment[1],
|
|
3317
3276
|
normalizedSegment[2],
|
|
3318
3277
|
x,
|
|
3319
3278
|
y
|
|
3320
3279
|
];
|
|
3321
3280
|
else result = [
|
|
3322
|
-
|
|
3281
|
+
"C",
|
|
3282
|
+
normalizedSegment[3],
|
|
3283
|
+
normalizedSegment[4],
|
|
3323
3284
|
normalizedSegment[1],
|
|
3324
3285
|
normalizedSegment[2],
|
|
3325
3286
|
x,
|
|
@@ -3373,8 +3334,39 @@ const reversePath = (pathInput) => {
|
|
|
3373
3334
|
});
|
|
3374
3335
|
return isClosed ? reversedPath.reverse() : [reversedPath[0]].concat(reversedPath.slice(1).reverse());
|
|
3375
3336
|
};
|
|
3376
|
-
|
|
3377
|
-
|
|
3337
|
+
/**
|
|
3338
|
+
* Reverses all segments of a PathArray and returns a new PathArray
|
|
3339
|
+
* with absolute values.
|
|
3340
|
+
*
|
|
3341
|
+
* Every sub-path is reversed on its own, so the `M` and the `Z` of a
|
|
3342
|
+
* sub-path are swapped with each other and the sub-paths keep their
|
|
3343
|
+
* original order.
|
|
3344
|
+
*
|
|
3345
|
+
* @param pathInput - The source PathArray
|
|
3346
|
+
* @returns The reversed PathArray
|
|
3347
|
+
*
|
|
3348
|
+
* @example
|
|
3349
|
+
* ```ts
|
|
3350
|
+
* reversePath([['M', 0, 0], ['L', 100, 0], ['L', 100, 100], ['L', 0, 100], ['Z']])
|
|
3351
|
+
* // => [['M', 0, 100], ['L', 0, 0], ['L', 100, 0], ['L', 100, 100], ['Z']]
|
|
3352
|
+
* ```
|
|
3353
|
+
*/
|
|
3354
|
+
const reversePath = (pathInput) => {
|
|
3355
|
+
const absolutePath = pathToAbsolute(pathInput);
|
|
3356
|
+
const subPaths = [];
|
|
3357
|
+
let subPath = [];
|
|
3358
|
+
for (const segment of absolutePath) {
|
|
3359
|
+
if (segment[0] === "M" && subPath.length) {
|
|
3360
|
+
subPaths.push(subPath);
|
|
3361
|
+
subPath = [];
|
|
3362
|
+
}
|
|
3363
|
+
subPath.push(segment);
|
|
3364
|
+
}
|
|
3365
|
+
if (subPath.length) subPaths.push(subPath);
|
|
3366
|
+
const reversed = subPaths.map((path) => reverseSubPath(path));
|
|
3367
|
+
return reversed.length === 1 ? reversed[0] : reversed.flat();
|
|
3368
|
+
};
|
|
3369
|
+
// src/process/splitPath.ts
|
|
3378
3370
|
/**
|
|
3379
3371
|
* Split a path string or PathArray into an array of sub-paths.
|
|
3380
3372
|
*
|
|
@@ -3440,8 +3432,7 @@ const splitPath = (pathInput) => {
|
|
|
3440
3432
|
});
|
|
3441
3433
|
return composite;
|
|
3442
3434
|
};
|
|
3443
|
-
|
|
3444
|
-
//#region src/process/getSVGMatrix.ts
|
|
3435
|
+
// src/process/getSVGMatrix.ts
|
|
3445
3436
|
/**
|
|
3446
3437
|
* Returns a transformation matrix to apply to `<path>` elements.
|
|
3447
3438
|
*
|
|
@@ -3474,8 +3465,7 @@ const getSVGMatrix = (transform) => {
|
|
|
3474
3465
|
}
|
|
3475
3466
|
return matrix;
|
|
3476
3467
|
};
|
|
3477
|
-
|
|
3478
|
-
//#region src/process/projection2d.ts
|
|
3468
|
+
// src/process/projection2d.ts
|
|
3479
3469
|
/**
|
|
3480
3470
|
* Transforms a specified point using a matrix, returning a new
|
|
3481
3471
|
* Tuple *Object* comprising of the transformed point.
|
|
@@ -3531,8 +3521,7 @@ const projection2d = (m, point2D, origin) => {
|
|
|
3531
3521
|
const relativePositionZ = z - originZ;
|
|
3532
3522
|
return [relativePositionX * (Math.abs(originZ) / Math.abs(relativePositionZ) || 1) + originX, relativePositionY * (Math.abs(originZ) / Math.abs(relativePositionZ) || 1) + originY];
|
|
3533
3523
|
};
|
|
3534
|
-
|
|
3535
|
-
//#region src/process/transformPath.ts
|
|
3524
|
+
// src/process/transformPath.ts
|
|
3536
3525
|
/**
|
|
3537
3526
|
* Applies a 2D transformation to a `PathArray` in a single pass, without
|
|
3538
3527
|
* absolutizing or copying each segment, returning a new absolute `PathArray`.
|
|
@@ -3756,8 +3745,7 @@ const transformPath = (pathInput, transform) => {
|
|
|
3756
3745
|
return result;
|
|
3757
3746
|
});
|
|
3758
3747
|
};
|
|
3759
|
-
|
|
3760
|
-
//#region src/process/reverseCurve.ts
|
|
3748
|
+
// src/process/reverseCurve.ts
|
|
3761
3749
|
/**
|
|
3762
3750
|
* Reverses all segments of a `pathArray`
|
|
3763
3751
|
* which consists of only C (cubic-bezier) path commands.
|
|
@@ -3769,8 +3757,7 @@ const reverseCurve = (path) => {
|
|
|
3769
3757
|
const rotatedCurve = path.slice(1).map((x, i, curveOnly) => !i ? path[0].slice(1).concat(x.slice(1)) : curveOnly[i - 1].slice(-2).concat(x.slice(1))).map((x) => x.map((_, i) => x[x.length - i - 2 * (1 - i % 2)])).reverse();
|
|
3770
3758
|
return [["M"].concat(rotatedCurve[0].slice(0, 2))].concat(rotatedCurve.map((x) => ["C"].concat(x.slice(2))));
|
|
3771
3759
|
};
|
|
3772
|
-
|
|
3773
|
-
//#region src/process/roundPath.ts
|
|
3760
|
+
// src/process/roundPath.ts
|
|
3774
3761
|
/**
|
|
3775
3762
|
* Rounds the values of a `pathArray` instance to
|
|
3776
3763
|
* a specified amount of decimals and returns it.
|
|
@@ -3787,8 +3774,7 @@ const roundPath = (path, roundOption) => {
|
|
|
3787
3774
|
return roundSegment(segment, round);
|
|
3788
3775
|
});
|
|
3789
3776
|
};
|
|
3790
|
-
|
|
3791
|
-
//#region src/morph/fixPath.ts
|
|
3777
|
+
// src/morph/fixPath.ts
|
|
3792
3778
|
/**
|
|
3793
3779
|
* Checks a `PathArray` for an unnecessary `Z` segment
|
|
3794
3780
|
* and removes it. The `PathArray` is modified in place.
|
|
@@ -3814,8 +3800,7 @@ const fixPath = (pathInput) => {
|
|
|
3814
3800
|
if (mx === x && my === y) pathArray.splice(length - 1, 1);
|
|
3815
3801
|
}
|
|
3816
3802
|
};
|
|
3817
|
-
|
|
3818
|
-
//#region src/morph/splitCubicSegment.ts
|
|
3803
|
+
// src/morph/splitCubicSegment.ts
|
|
3819
3804
|
/**
|
|
3820
3805
|
* Split a cubic Bézier into two cubics at parameter t [0–1].
|
|
3821
3806
|
*
|
|
@@ -3857,8 +3842,7 @@ function splitCubicSegment(x1, y1, x2, y2, x3, y3, x4, y4, t) {
|
|
|
3857
3842
|
y4
|
|
3858
3843
|
]];
|
|
3859
3844
|
}
|
|
3860
|
-
|
|
3861
|
-
//#region src/morph/pathToPolyline.ts
|
|
3845
|
+
// src/morph/pathToPolyline.ts
|
|
3862
3846
|
/**
|
|
3863
3847
|
* Converts any `PolyLineArray`/`PolygonArray` path (closed or open) to an explicit polyline (M + L*).
|
|
3864
3848
|
* If the path is closed (has Z), the Z is replaced with an explicit L back to the initial M point.
|
|
@@ -3884,8 +3868,7 @@ const pathToPolyline = (path) => {
|
|
|
3884
3868
|
}
|
|
3885
3869
|
return result;
|
|
3886
3870
|
};
|
|
3887
|
-
|
|
3888
|
-
//#region src/morph/splitLineToCount.ts
|
|
3871
|
+
// src/morph/splitLineToCount.ts
|
|
3889
3872
|
/**
|
|
3890
3873
|
* Split a line segment into `count` smaller segments of equal length
|
|
3891
3874
|
* using the same repeated front-cutting strategy as splitCubicToCount.
|
|
@@ -3928,8 +3911,7 @@ function splitLineToCount(x1, y1, x2, y2, count) {
|
|
|
3928
3911
|
}
|
|
3929
3912
|
return result;
|
|
3930
3913
|
}
|
|
3931
|
-
|
|
3932
|
-
//#region src/morph/getPathSplits.ts
|
|
3914
|
+
// src/morph/getPathSplits.ts
|
|
3933
3915
|
/**
|
|
3934
3916
|
* Determine the right amount of splits for each segment in a given PathArray
|
|
3935
3917
|
* and for a target total amount of sub-segments.
|
|
@@ -3994,8 +3976,7 @@ function getPathSplits(path, target) {
|
|
|
3994
3976
|
}
|
|
3995
3977
|
return splits;
|
|
3996
3978
|
}
|
|
3997
|
-
|
|
3998
|
-
//#region src/morph/splitLinePathToCount.ts
|
|
3979
|
+
// src/morph/splitLinePathToCount.ts
|
|
3999
3980
|
/**
|
|
4000
3981
|
* Splits a PolylineArray so that it has exactly `target` line segments.
|
|
4001
3982
|
*
|
|
@@ -4031,8 +4012,7 @@ function splitLinePathToCount(path, target) {
|
|
|
4031
4012
|
if (newPath.length !== target) console.warn(`${error}: requested ${target} segments, got ${newPath.length}. Adjusted on last segment.`);
|
|
4032
4013
|
return newPath;
|
|
4033
4014
|
}
|
|
4034
|
-
|
|
4035
|
-
//#region src/morph/splitCubicToCount.ts
|
|
4015
|
+
// src/morph/splitCubicToCount.ts
|
|
4036
4016
|
/**
|
|
4037
4017
|
* Split a cubic Bézier into `count` segments of roughly equal parameter length.
|
|
4038
4018
|
* Does NOT mutate input parameters.
|
|
@@ -4078,8 +4058,7 @@ function splitCubicToCount(x1, y1, x2, y2, x3, y3, x4, y4, count) {
|
|
|
4078
4058
|
}
|
|
4079
4059
|
return result;
|
|
4080
4060
|
}
|
|
4081
|
-
|
|
4082
|
-
//#region src/morph/splitCurvePathToCount.ts
|
|
4061
|
+
// src/morph/splitCurvePathToCount.ts
|
|
4083
4062
|
/**
|
|
4084
4063
|
* Splits a CurveArray so that it has exactly `target` cubic segments.
|
|
4085
4064
|
*
|
|
@@ -4120,8 +4099,7 @@ function splitCurvePathToCount(path, target) {
|
|
|
4120
4099
|
if (newPath.length !== target) console.warn(`${error}: requested ${target} segments, got ${newPath.length}.`);
|
|
4121
4100
|
return newPath;
|
|
4122
4101
|
}
|
|
4123
|
-
|
|
4124
|
-
//#region src/morph/getRotatedPath.ts
|
|
4102
|
+
// src/morph/getRotatedPath.ts
|
|
4125
4103
|
/**
|
|
4126
4104
|
* Returns all possible rotations of a path (line or curve) by shifting the start point.
|
|
4127
4105
|
* Each rotation is a new PathArray starting at a different original segment.
|
|
@@ -4186,8 +4164,7 @@ function getRotatedPath(pathA, pathB, computedRotations) {
|
|
|
4186
4164
|
}
|
|
4187
4165
|
return rotations[bestIndex];
|
|
4188
4166
|
}
|
|
4189
|
-
|
|
4190
|
-
//#region src/morph/equalizeSegments.ts
|
|
4167
|
+
// src/morph/equalizeSegments.ts
|
|
4191
4168
|
const equalizeSegmentsDefaults = {
|
|
4192
4169
|
mode: "auto",
|
|
4193
4170
|
sampleSize: 10,
|
|
@@ -4260,8 +4237,7 @@ const equalizeSegments = (path1, path2, initialCfg = {}) => {
|
|
|
4260
4237
|
}
|
|
4261
4238
|
return [equalP1, equalP2];
|
|
4262
4239
|
};
|
|
4263
|
-
|
|
4264
|
-
//#region src/intersect/isPointInsideBBox.ts
|
|
4240
|
+
// src/intersect/isPointInsideBBox.ts
|
|
4265
4241
|
/**
|
|
4266
4242
|
* Checks if a point is inside a bounding box.
|
|
4267
4243
|
*
|
|
@@ -4273,8 +4249,7 @@ const isPointInsideBBox = (bbox, [x, y]) => {
|
|
|
4273
4249
|
const [minX, minY, maxX, maxY] = bbox;
|
|
4274
4250
|
return x >= minX && x <= maxX && y >= minY && y <= maxY;
|
|
4275
4251
|
};
|
|
4276
|
-
|
|
4277
|
-
//#region src/intersect/boundingBoxIntersect.ts
|
|
4252
|
+
// src/intersect/boundingBoxIntersect.ts
|
|
4278
4253
|
/**
|
|
4279
4254
|
* Checks if two bounding boxes intersect.
|
|
4280
4255
|
*
|
|
@@ -4287,8 +4262,7 @@ const boundingBoxIntersect = (a, b) => {
|
|
|
4287
4262
|
const [bx1, by1, bx2, by2] = b;
|
|
4288
4263
|
return isPointInsideBBox(b, [ax1, ay1]) || isPointInsideBBox(b, [ax2, ay1]) || isPointInsideBBox(b, [ax1, ay2]) || isPointInsideBBox(b, [ax2, ay2]) || isPointInsideBBox(a, [bx1, by1]) || isPointInsideBBox(a, [bx2, by1]) || isPointInsideBBox(a, [bx1, by2]) || isPointInsideBBox(a, [bx2, by2]) || (ax1 < bx2 && ax1 > bx1 || bx1 < ax2 && bx1 > ax1) && (ay1 < by2 && ay1 > by1 || by1 < ay2 && by1 > ay1);
|
|
4289
4264
|
};
|
|
4290
|
-
|
|
4291
|
-
//#region src/morph/createPlaceholder.ts
|
|
4265
|
+
// src/morph/createPlaceholder.ts
|
|
4292
4266
|
/**
|
|
4293
4267
|
* Create a degenerate `PathArray` at a given coordinate
|
|
4294
4268
|
* to serve as a pair for another `PathArray`.
|
|
@@ -4326,8 +4300,7 @@ const createPlaceholder = ([atx, aty]) => {
|
|
|
4326
4300
|
["Z"]
|
|
4327
4301
|
];
|
|
4328
4302
|
};
|
|
4329
|
-
|
|
4330
|
-
//#region src/morph/matchPaths.ts
|
|
4303
|
+
// src/morph/matchPaths.ts
|
|
4331
4304
|
function getBestMatch(target, candidates) {
|
|
4332
4305
|
const targetBBox = target.bbox;
|
|
4333
4306
|
const potentialCandidates = [];
|
|
@@ -4403,8 +4376,7 @@ function matchPaths(fromPaths, toPaths) {
|
|
|
4403
4376
|
}
|
|
4404
4377
|
return pairs;
|
|
4405
4378
|
}
|
|
4406
|
-
|
|
4407
|
-
//#region src/morph/classifyPaths.ts
|
|
4379
|
+
// src/morph/classifyPaths.ts
|
|
4408
4380
|
/**
|
|
4409
4381
|
* Classifies paths into outer (containing) and inner (hole) paths.
|
|
4410
4382
|
*
|
|
@@ -4433,8 +4405,7 @@ const classifyPaths = (paths) => {
|
|
|
4433
4405
|
inners
|
|
4434
4406
|
};
|
|
4435
4407
|
};
|
|
4436
|
-
|
|
4437
|
-
//#region src/morph/equalizePaths.ts
|
|
4408
|
+
// src/morph/equalizePaths.ts
|
|
4438
4409
|
const equalizePathsDefaults = {
|
|
4439
4410
|
mode: "auto",
|
|
4440
4411
|
roundValues: 4,
|
|
@@ -4485,8 +4456,7 @@ const equalizePaths = (pathInput1, pathInput2, initialCfg = {}) => {
|
|
|
4485
4456
|
}
|
|
4486
4457
|
return [equalizedPairs.map((p) => p[0]).flat(), equalizedPairs.map((p) => p[1]).flat()];
|
|
4487
4458
|
};
|
|
4488
|
-
|
|
4489
|
-
//#region src/intersect/interHelper.ts
|
|
4459
|
+
// src/intersect/interHelper.ts
|
|
4490
4460
|
const intersect = (x1, y1, x2, y2, x3, y3, x4, y4) => {
|
|
4491
4461
|
if (Math.max(x1, x2) < Math.min(x3, x4) || Math.min(x1, x2) > Math.max(x3, x4) || Math.max(y1, y2) < Math.min(y3, y4) || Math.min(y1, y2) > Math.max(y3, y4)) return;
|
|
4492
4462
|
const nx = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4), ny = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4), denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
|
|
@@ -4551,8 +4521,7 @@ const interHelper = (bez1, bez2, config) => {
|
|
|
4551
4521
|
}
|
|
4552
4522
|
return res;
|
|
4553
4523
|
};
|
|
4554
|
-
|
|
4555
|
-
//#region src/intersect/pathIntersection.ts
|
|
4524
|
+
// src/intersect/pathIntersection.ts
|
|
4556
4525
|
/**
|
|
4557
4526
|
* Finds intersection points between two paths.
|
|
4558
4527
|
*
|
|
@@ -4658,8 +4627,7 @@ const pathsIntersection = (pathInput1, pathInput2, justCount = true) => {
|
|
|
4658
4627
|
}
|
|
4659
4628
|
return justCount ? countResult : pointsResult;
|
|
4660
4629
|
};
|
|
4661
|
-
|
|
4662
|
-
//#region src/main.ts
|
|
4630
|
+
// src/main.ts
|
|
4663
4631
|
/**
|
|
4664
4632
|
* Creates a new SVGPathCommander instance with the following properties:
|
|
4665
4633
|
* * segments: `pathArray`
|
|
@@ -5150,10 +5118,8 @@ var SVGPathCommander = class {
|
|
|
5150
5118
|
/** The library version. */
|
|
5151
5119
|
static version = version;
|
|
5152
5120
|
};
|
|
5153
|
-
|
|
5154
|
-
//#region src/index.ts
|
|
5121
|
+
// src/index.ts
|
|
5155
5122
|
var src_default = SVGPathCommander;
|
|
5156
|
-
//#endregion
|
|
5157
5123
|
export { SVGPathCommander, src_default as default };
|
|
5158
5124
|
|
|
5159
5125
|
//# sourceMappingURL=index.js.map
|