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/util.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* SVGPathCommander v2.3.
|
|
2
|
+
* SVGPathCommander UTIL 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
|
-
|
|
7
|
+
// src/math/midPoint.ts
|
|
8
8
|
/**
|
|
9
9
|
* Returns the coordinates of a specified distance
|
|
10
10
|
* ratio between two points.
|
|
@@ -17,8 +17,7 @@ import CSSMatrix from "@thednp/dommatrix";
|
|
|
17
17
|
const midPoint = ([ax, ay], [bx, by], t) => {
|
|
18
18
|
return [ax + (bx - ax) * t, ay + (by - ay) * t];
|
|
19
19
|
};
|
|
20
|
-
|
|
21
|
-
//#region src/math/distanceSquareRoot.ts
|
|
20
|
+
// src/math/distanceSquareRoot.ts
|
|
22
21
|
/**
|
|
23
22
|
* Returns the square root of the distance
|
|
24
23
|
* between two given points.
|
|
@@ -30,8 +29,7 @@ const midPoint = ([ax, ay], [bx, by], t) => {
|
|
|
30
29
|
const distanceSquareRoot = (a, b) => {
|
|
31
30
|
return Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]));
|
|
32
31
|
};
|
|
33
|
-
|
|
34
|
-
//#region src/math/lineTools.ts
|
|
32
|
+
// src/math/lineTools.ts
|
|
35
33
|
/**
|
|
36
34
|
* Returns length for line segments (MoveTo, LineTo).
|
|
37
35
|
*
|
|
@@ -103,8 +101,7 @@ const lineTools = {
|
|
|
103
101
|
getLineLength,
|
|
104
102
|
getPointAtLineLength
|
|
105
103
|
};
|
|
106
|
-
|
|
107
|
-
//#region src/math/bezier.ts
|
|
104
|
+
// src/math/bezier.ts
|
|
108
105
|
/**
|
|
109
106
|
* Tools from bezier.js by Mike 'Pomax' Kamermans
|
|
110
107
|
* @see https://github.com/Pomax/bezierjs
|
|
@@ -393,8 +390,7 @@ const bezierTools = {
|
|
|
393
390
|
minmaxQ,
|
|
394
391
|
Tvalues
|
|
395
392
|
};
|
|
396
|
-
|
|
397
|
-
//#region src/math/arcTools.ts
|
|
393
|
+
// src/math/arcTools.ts
|
|
398
394
|
/**
|
|
399
395
|
* Returns the signed arc length of an ellipse segment from angle `0` up to
|
|
400
396
|
* the given `theta` angle, by integrating the curve speed
|
|
@@ -660,7 +656,7 @@ const getPointAtArcLength = (x1, y1, RX, RY, angle, LAF, SF, x, y, distance) =>
|
|
|
660
656
|
const getArcBBox = (x1, y1, RX, RY, angle, LAF, SF, x, y) => {
|
|
661
657
|
const { center, rx, ry, startAngle, endAngle } = getArcProps(x1, y1, RX, RY, angle, LAF, SF, x, y);
|
|
662
658
|
const deltaAngle = endAngle - startAngle;
|
|
663
|
-
const { min, max, tan, atan2, PI } = Math;
|
|
659
|
+
const { min, max, tan, atan2, cos, PI } = Math;
|
|
664
660
|
const { x: cx, y: cy } = center;
|
|
665
661
|
const alpha = angle * PI / 180;
|
|
666
662
|
const tangent = tan(alpha);
|
|
@@ -673,6 +669,11 @@ const getArcBBox = (x1, y1, RX, RY, angle, LAF, SF, x, y) => {
|
|
|
673
669
|
const angle2 = theta + PI;
|
|
674
670
|
const angle3 = atan2(ry, rx * tangent);
|
|
675
671
|
const angle4 = angle3 + PI;
|
|
672
|
+
const flipped = cos(alpha) < 0;
|
|
673
|
+
const rightAngle = flipped ? angle2 : angle1;
|
|
674
|
+
const leftAngle = flipped ? angle1 : angle2;
|
|
675
|
+
const topAngle = flipped ? angle3 : angle4;
|
|
676
|
+
const bottomAngle = flipped ? angle4 : angle3;
|
|
676
677
|
const xArray = [x];
|
|
677
678
|
const yArray = [y];
|
|
678
679
|
let xMin = min(x1, x);
|
|
@@ -690,22 +691,22 @@ const getArcBBox = (x1, y1, RX, RY, angle, LAF, SF, x, y) => {
|
|
|
690
691
|
* otherwise exclude elliptic extreme points
|
|
691
692
|
*/
|
|
692
693
|
if (pP2[0] > xMax || pP3[0] > xMax) {
|
|
693
|
-
const p1 = arcPoint(cx, cy, rx, ry, alpha,
|
|
694
|
+
const p1 = arcPoint(cx, cy, rx, ry, alpha, rightAngle);
|
|
694
695
|
xArray.push(p1[0]);
|
|
695
696
|
yArray.push(p1[1]);
|
|
696
697
|
}
|
|
697
698
|
if (pP2[0] < xMin || pP3[0] < xMin) {
|
|
698
|
-
const p2 = arcPoint(cx, cy, rx, ry, alpha,
|
|
699
|
+
const p2 = arcPoint(cx, cy, rx, ry, alpha, leftAngle);
|
|
699
700
|
xArray.push(p2[0]);
|
|
700
701
|
yArray.push(p2[1]);
|
|
701
702
|
}
|
|
702
703
|
if (pP2[1] < yMin || pP3[1] < yMin) {
|
|
703
|
-
const p4 = arcPoint(cx, cy, rx, ry, alpha,
|
|
704
|
+
const p4 = arcPoint(cx, cy, rx, ry, alpha, topAngle);
|
|
704
705
|
xArray.push(p4[0]);
|
|
705
706
|
yArray.push(p4[1]);
|
|
706
707
|
}
|
|
707
708
|
if (pP2[1] > yMax || pP3[1] > yMax) {
|
|
708
|
-
const p3 = arcPoint(cx, cy, rx, ry, alpha,
|
|
709
|
+
const p3 = arcPoint(cx, cy, rx, ry, alpha, bottomAngle);
|
|
709
710
|
xArray.push(p3[0]);
|
|
710
711
|
yArray.push(p3[1]);
|
|
711
712
|
}
|
|
@@ -732,8 +733,7 @@ const arcTools = {
|
|
|
732
733
|
getArcProps,
|
|
733
734
|
getPointAtArcLength
|
|
734
735
|
};
|
|
735
|
-
|
|
736
|
-
//#region src/math/cubicTools.ts
|
|
736
|
+
// src/math/cubicTools.ts
|
|
737
737
|
/**
|
|
738
738
|
* Returns a point at a given length of a CubicBezier segment.
|
|
739
739
|
*
|
|
@@ -864,8 +864,7 @@ const cubicTools = {
|
|
|
864
864
|
getPointAtCubicLength,
|
|
865
865
|
getPointAtCubicSegmentLength
|
|
866
866
|
};
|
|
867
|
-
|
|
868
|
-
//#region src/math/quadTools.ts
|
|
867
|
+
// src/math/quadTools.ts
|
|
869
868
|
/**
|
|
870
869
|
* Returns the {x,y} coordinates of a point at a
|
|
871
870
|
* given length of a quadratic-bezier segment.
|
|
@@ -985,8 +984,7 @@ const quadTools = {
|
|
|
985
984
|
getQuadBBox,
|
|
986
985
|
getQuadLength
|
|
987
986
|
};
|
|
988
|
-
|
|
989
|
-
//#region src/math/polygonTools.ts
|
|
987
|
+
// src/math/polygonTools.ts
|
|
990
988
|
/**
|
|
991
989
|
* d3-polygon-area
|
|
992
990
|
* @see https://github.com/d3/d3-polygon
|
|
@@ -1048,8 +1046,7 @@ const polygonTools = {
|
|
|
1048
1046
|
polygonLength,
|
|
1049
1047
|
polygonCentroid
|
|
1050
1048
|
};
|
|
1051
|
-
|
|
1052
|
-
//#region src/math/rotateVector.ts
|
|
1049
|
+
// src/math/rotateVector.ts
|
|
1053
1050
|
/**
|
|
1054
1051
|
* Returns an {x,y} vector rotated by a given
|
|
1055
1052
|
* angle in radian.
|
|
@@ -1066,8 +1063,7 @@ const rotateVector = (x, y, rad) => {
|
|
|
1066
1063
|
y: x * sin(rad) + y * cos(rad)
|
|
1067
1064
|
};
|
|
1068
1065
|
};
|
|
1069
|
-
|
|
1070
|
-
//#region src/math/roundTo.ts
|
|
1066
|
+
// src/math/roundTo.ts
|
|
1071
1067
|
/**
|
|
1072
1068
|
* Rounds a number to the specified number of decimal places.
|
|
1073
1069
|
*
|
|
@@ -1079,8 +1075,7 @@ const roundTo = (n, round) => {
|
|
|
1079
1075
|
const pow = round >= 1 ? 10 ** round : 1;
|
|
1080
1076
|
return round > 0 ? Math.round(n * pow) / pow : Math.round(n);
|
|
1081
1077
|
};
|
|
1082
|
-
|
|
1083
|
-
//#region src/parser/paramsCount.ts
|
|
1078
|
+
// src/parser/paramsCount.ts
|
|
1084
1079
|
/** Segment params length */
|
|
1085
1080
|
const paramsCounts = {
|
|
1086
1081
|
a: 7,
|
|
@@ -1095,8 +1090,7 @@ const paramsCounts = {
|
|
|
1095
1090
|
v: 1,
|
|
1096
1091
|
z: 0
|
|
1097
1092
|
};
|
|
1098
|
-
|
|
1099
|
-
//#region src/parser/finalizeSegment.ts
|
|
1093
|
+
// src/parser/finalizeSegment.ts
|
|
1100
1094
|
/**
|
|
1101
1095
|
* Breaks the parsing of a pathString once a segment is finalized.
|
|
1102
1096
|
*
|
|
@@ -1128,12 +1122,10 @@ const finalizeSegment = (path) => {
|
|
|
1128
1122
|
if (!paramsCounts[relativeCommand]) break;
|
|
1129
1123
|
}
|
|
1130
1124
|
};
|
|
1131
|
-
|
|
1132
|
-
//#region src/util/error.ts
|
|
1125
|
+
// src/util/error.ts
|
|
1133
1126
|
/** Error prefix used in all SVGPathCommander TypeError messages. */
|
|
1134
1127
|
const error = "SVGPathCommanderError";
|
|
1135
|
-
|
|
1136
|
-
//#region src/parser/scanFlag.ts
|
|
1128
|
+
// src/parser/scanFlag.ts
|
|
1137
1129
|
/**
|
|
1138
1130
|
* Validates an A (arc-to) specific path command value.
|
|
1139
1131
|
* Usually a `large-arc-flag` or `sweep-flag`.
|
|
@@ -1155,8 +1147,7 @@ const scanFlag = (path) => {
|
|
|
1155
1147
|
}
|
|
1156
1148
|
path.err = `${error}: invalid Arc flag "${pathValue[index]}", expecting 0 or 1 at index ${index}`;
|
|
1157
1149
|
};
|
|
1158
|
-
|
|
1159
|
-
//#region src/parser/isDigit.ts
|
|
1150
|
+
// src/parser/isDigit.ts
|
|
1160
1151
|
/**
|
|
1161
1152
|
* Checks if a character is a digit.
|
|
1162
1153
|
*
|
|
@@ -1166,12 +1157,10 @@ const scanFlag = (path) => {
|
|
|
1166
1157
|
const isDigit = (code) => {
|
|
1167
1158
|
return code >= 48 && code <= 57;
|
|
1168
1159
|
};
|
|
1169
|
-
|
|
1170
|
-
//#region src/parser/invalidPathValue.ts
|
|
1160
|
+
// src/parser/invalidPathValue.ts
|
|
1171
1161
|
/** Error message prefix used when a path string cannot be parsed. */
|
|
1172
1162
|
const invalidPathValue = "Invalid path value";
|
|
1173
|
-
|
|
1174
|
-
//#region src/parser/scanParam.ts
|
|
1163
|
+
// src/parser/scanParam.ts
|
|
1175
1164
|
/**
|
|
1176
1165
|
* Validates every character of the path string,
|
|
1177
1166
|
* every path command, negative numbers or floating point numbers.
|
|
@@ -1294,8 +1283,7 @@ const scanNumber = (str, start, end) => {
|
|
|
1294
1283
|
if (scale >= 0) return sign * param * 10 ** scale;
|
|
1295
1284
|
return sign * param / 10 ** -scale;
|
|
1296
1285
|
};
|
|
1297
|
-
|
|
1298
|
-
//#region src/parser/isSpace.ts
|
|
1286
|
+
// src/parser/isSpace.ts
|
|
1299
1287
|
/**
|
|
1300
1288
|
* Checks if the character is a space.
|
|
1301
1289
|
*
|
|
@@ -1332,8 +1320,7 @@ const isSpace = (ch) => {
|
|
|
1332
1320
|
160
|
|
1333
1321
|
].includes(ch);
|
|
1334
1322
|
};
|
|
1335
|
-
|
|
1336
|
-
//#region src/parser/skipSpaces.ts
|
|
1323
|
+
// src/parser/skipSpaces.ts
|
|
1337
1324
|
/**
|
|
1338
1325
|
* Points the parser to the next character in the
|
|
1339
1326
|
* path string every time it encounters any kind of
|
|
@@ -1345,8 +1332,7 @@ const skipSpaces = (path) => {
|
|
|
1345
1332
|
const { pathValue, max } = path;
|
|
1346
1333
|
while (path.index < max && isSpace(pathValue.charCodeAt(path.index))) path.index += 1;
|
|
1347
1334
|
};
|
|
1348
|
-
|
|
1349
|
-
//#region src/parser/isPathCommand.ts
|
|
1335
|
+
// src/parser/isPathCommand.ts
|
|
1350
1336
|
/**
|
|
1351
1337
|
* Checks if the character is a path command.
|
|
1352
1338
|
*
|
|
@@ -1368,8 +1354,7 @@ const isPathCommand = (code) => {
|
|
|
1368
1354
|
default: return false;
|
|
1369
1355
|
}
|
|
1370
1356
|
};
|
|
1371
|
-
|
|
1372
|
-
//#region src/parser/isDigitStart.ts
|
|
1357
|
+
// src/parser/isDigitStart.ts
|
|
1373
1358
|
/**
|
|
1374
1359
|
* Checks if the character is or belongs to a number.
|
|
1375
1360
|
* [0-9]|+|-|.
|
|
@@ -1380,8 +1365,7 @@ const isPathCommand = (code) => {
|
|
|
1380
1365
|
const isDigitStart = (code) => {
|
|
1381
1366
|
return isDigit(code) || code === 43 || code === 45 || code === 46;
|
|
1382
1367
|
};
|
|
1383
|
-
|
|
1384
|
-
//#region src/parser/isArcCommand.ts
|
|
1368
|
+
// src/parser/isArcCommand.ts
|
|
1385
1369
|
/**
|
|
1386
1370
|
* Checks if the character is an A (arc-to) path command.
|
|
1387
1371
|
*
|
|
@@ -1391,8 +1375,7 @@ const isDigitStart = (code) => {
|
|
|
1391
1375
|
const isArcCommand = (code) => {
|
|
1392
1376
|
return (code | 32) === 97;
|
|
1393
1377
|
};
|
|
1394
|
-
|
|
1395
|
-
//#region src/parser/isMoveCommand.ts
|
|
1378
|
+
// src/parser/isMoveCommand.ts
|
|
1396
1379
|
/**
|
|
1397
1380
|
* Checks if the character is a MoveTo command.
|
|
1398
1381
|
*
|
|
@@ -1406,8 +1389,7 @@ const isMoveCommand = (code) => {
|
|
|
1406
1389
|
default: return false;
|
|
1407
1390
|
}
|
|
1408
1391
|
};
|
|
1409
|
-
|
|
1410
|
-
//#region src/parser/scanSegment.ts
|
|
1392
|
+
// src/parser/scanSegment.ts
|
|
1411
1393
|
/**
|
|
1412
1394
|
* Scans every character in the path string to determine
|
|
1413
1395
|
* where a segment starts and where it ends.
|
|
@@ -1452,8 +1434,7 @@ const scanSegment = (path) => {
|
|
|
1452
1434
|
}
|
|
1453
1435
|
finalizeSegment(path);
|
|
1454
1436
|
};
|
|
1455
|
-
|
|
1456
|
-
//#region src/parser/pathParser.ts
|
|
1437
|
+
// src/parser/pathParser.ts
|
|
1457
1438
|
/**
|
|
1458
1439
|
* The `PathParser` is used by the `parsePathString` static method
|
|
1459
1440
|
* to generate a `pathArray`.
|
|
@@ -1472,8 +1453,7 @@ var PathParser = class {
|
|
|
1472
1453
|
this.err = "";
|
|
1473
1454
|
}
|
|
1474
1455
|
};
|
|
1475
|
-
|
|
1476
|
-
//#region src/parser/parsePathString.ts
|
|
1456
|
+
// src/parser/parsePathString.ts
|
|
1477
1457
|
/**
|
|
1478
1458
|
* Parses a path string value and returns an array
|
|
1479
1459
|
* of segments we like to call `PathArray`.
|
|
@@ -1504,8 +1484,7 @@ const parsePathString = (pathInput) => {
|
|
|
1504
1484
|
} else throw TypeError(path.err);
|
|
1505
1485
|
return path.segments;
|
|
1506
1486
|
};
|
|
1507
|
-
|
|
1508
|
-
//#region src/process/absolutizeSegment.ts
|
|
1487
|
+
// src/process/absolutizeSegment.ts
|
|
1509
1488
|
/**
|
|
1510
1489
|
* Returns an absolute segment of a `PathArray` object.
|
|
1511
1490
|
*
|
|
@@ -1552,8 +1531,7 @@ const absolutizeSegment = (segment, index, lastX, lastY) => {
|
|
|
1552
1531
|
return [absCommand].concat(absValues);
|
|
1553
1532
|
}
|
|
1554
1533
|
};
|
|
1555
|
-
|
|
1556
|
-
//#region src/process/iterate.ts
|
|
1534
|
+
// src/process/iterate.ts
|
|
1557
1535
|
/**
|
|
1558
1536
|
* Iterates over a `PathArray`, executing a callback for each segment.
|
|
1559
1537
|
* The callback can:
|
|
@@ -1614,8 +1592,7 @@ const iterate = (path, iterator) => {
|
|
|
1614
1592
|
}
|
|
1615
1593
|
return path;
|
|
1616
1594
|
};
|
|
1617
|
-
|
|
1618
|
-
//#region src/convert/pathToAbsolute.ts
|
|
1595
|
+
// src/convert/pathToAbsolute.ts
|
|
1619
1596
|
/**
|
|
1620
1597
|
* Parses a path string value or object and returns an array
|
|
1621
1598
|
* of segments, all converted to absolute values.
|
|
@@ -1633,8 +1610,7 @@ const pathToAbsolute = (pathInput) => {
|
|
|
1633
1610
|
const path = parsePathString(pathInput);
|
|
1634
1611
|
return iterate(path, absolutizeSegment);
|
|
1635
1612
|
};
|
|
1636
|
-
|
|
1637
|
-
//#region src/process/relativizeSegment.ts
|
|
1613
|
+
// src/process/relativizeSegment.ts
|
|
1638
1614
|
/**
|
|
1639
1615
|
* Returns a relative segment of a `PathArray` object.
|
|
1640
1616
|
*
|
|
@@ -1672,8 +1648,7 @@ const relativizeSegment = (segment, index, lastX, lastY) => {
|
|
|
1672
1648
|
return [relCommand].concat(relValues);
|
|
1673
1649
|
}
|
|
1674
1650
|
};
|
|
1675
|
-
|
|
1676
|
-
//#region src/convert/pathToRelative.ts
|
|
1651
|
+
// src/convert/pathToRelative.ts
|
|
1677
1652
|
/**
|
|
1678
1653
|
* Parses a path string value or object and returns an array
|
|
1679
1654
|
* of segments, all converted to relative values.
|
|
@@ -1691,8 +1666,7 @@ const pathToRelative = (pathInput) => {
|
|
|
1691
1666
|
const path = parsePathString(pathInput);
|
|
1692
1667
|
return iterate(path, relativizeSegment);
|
|
1693
1668
|
};
|
|
1694
|
-
|
|
1695
|
-
//#region src/process/arcToCubic.ts
|
|
1669
|
+
// src/process/arcToCubic.ts
|
|
1696
1670
|
/**
|
|
1697
1671
|
* Converts A (arc-to) segments to C (cubic-bezier-to).
|
|
1698
1672
|
*
|
|
@@ -1804,8 +1778,7 @@ const arcToCubic = (X1, Y1, RX, RY, angle, LAF, SF, X2, Y2, recursive) => {
|
|
|
1804
1778
|
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;
|
|
1805
1779
|
return newres;
|
|
1806
1780
|
};
|
|
1807
|
-
|
|
1808
|
-
//#region src/process/quadToCubic.ts
|
|
1781
|
+
// src/process/quadToCubic.ts
|
|
1809
1782
|
/**
|
|
1810
1783
|
* Converts a Q (quadratic-bezier) segment to C (cubic-bezier).
|
|
1811
1784
|
*
|
|
@@ -1829,8 +1802,7 @@ const quadToCubic = (x1, y1, qx, qy, x2, y2) => {
|
|
|
1829
1802
|
y2
|
|
1830
1803
|
];
|
|
1831
1804
|
};
|
|
1832
|
-
|
|
1833
|
-
//#region src/process/lineToCubic.ts
|
|
1805
|
+
// src/process/lineToCubic.ts
|
|
1834
1806
|
/**
|
|
1835
1807
|
* Converts an L (line-to) segment to C (cubic-bezier).
|
|
1836
1808
|
*
|
|
@@ -1852,8 +1824,7 @@ const lineToCubic = (x1, y1, x2, y2) => {
|
|
|
1852
1824
|
y2
|
|
1853
1825
|
];
|
|
1854
1826
|
};
|
|
1855
|
-
|
|
1856
|
-
//#region src/process/segmentToCubic.ts
|
|
1827
|
+
// src/process/segmentToCubic.ts
|
|
1857
1828
|
/**
|
|
1858
1829
|
* Converts any segment to C (cubic-bezier).
|
|
1859
1830
|
*
|
|
@@ -1885,20 +1856,20 @@ const segmentToCubic = (segment, params) => {
|
|
|
1885
1856
|
else if (pathCommand === "Z") return ["C"].concat(lineToCubic(px1, py1, params.mx, params.my));
|
|
1886
1857
|
return segment;
|
|
1887
1858
|
};
|
|
1888
|
-
|
|
1889
|
-
//#region src/process/normalizeSegment.ts
|
|
1859
|
+
// src/process/normalizeSegment.ts
|
|
1890
1860
|
/**
|
|
1891
1861
|
* Normalizes a single segment of a `pathArray` object.
|
|
1892
1862
|
*
|
|
1893
1863
|
* @param segment the segment object
|
|
1894
1864
|
* @param params the normalization parameters
|
|
1865
|
+
* @param prevCommand the command of the previous segment
|
|
1895
1866
|
* @returns the normalized segment
|
|
1896
1867
|
*/
|
|
1897
|
-
const normalizeSegment = (segment, params) => {
|
|
1868
|
+
const normalizeSegment = (segment, params, prevCommand) => {
|
|
1898
1869
|
const [pathCommand] = segment;
|
|
1899
1870
|
const absCommand = pathCommand.toUpperCase();
|
|
1900
1871
|
const isRelative = pathCommand !== absCommand;
|
|
1901
|
-
const {
|
|
1872
|
+
const { x, y } = params;
|
|
1902
1873
|
const values = segment.slice(1);
|
|
1903
1874
|
let absValues = values.map((n, j) => n + (isRelative ? j % 2 ? y : x : 0));
|
|
1904
1875
|
if (!"TQ".includes(absCommand)) {
|
|
@@ -1911,11 +1882,11 @@ const normalizeSegment = (segment, params) => {
|
|
|
1911
1882
|
} else if (absCommand === "H") return [
|
|
1912
1883
|
"L",
|
|
1913
1884
|
segment[1] + (isRelative ? x : 0),
|
|
1914
|
-
|
|
1885
|
+
y
|
|
1915
1886
|
];
|
|
1916
1887
|
else if (absCommand === "V") return [
|
|
1917
1888
|
"L",
|
|
1918
|
-
|
|
1889
|
+
x,
|
|
1919
1890
|
segment[1] + (isRelative ? y : 0)
|
|
1920
1891
|
];
|
|
1921
1892
|
else if (absCommand === "L") return [
|
|
@@ -1930,18 +1901,15 @@ const normalizeSegment = (segment, params) => {
|
|
|
1930
1901
|
];
|
|
1931
1902
|
else if (absCommand === "C") return ["C"].concat(absValues);
|
|
1932
1903
|
else if (absCommand === "S") {
|
|
1933
|
-
const
|
|
1934
|
-
const y1 = py1 * 2 - py2;
|
|
1935
|
-
params.x1 = x1;
|
|
1936
|
-
params.y1 = y1;
|
|
1904
|
+
const canReflect = prevCommand != null && "CS".includes(prevCommand);
|
|
1937
1905
|
return [
|
|
1938
1906
|
"C",
|
|
1939
|
-
|
|
1940
|
-
|
|
1907
|
+
canReflect && params.x2 != null ? x * 2 - params.x2 : x,
|
|
1908
|
+
canReflect && params.y2 != null ? y * 2 - params.y2 : y
|
|
1941
1909
|
].concat(absValues);
|
|
1942
1910
|
} else if (absCommand === "T") {
|
|
1943
|
-
const qx = params.qx != null ?
|
|
1944
|
-
const qy = params.qy != null ?
|
|
1911
|
+
const qx = params.qx != null ? x * 2 - params.qx : x;
|
|
1912
|
+
const qy = params.qy != null ? y * 2 - params.qy : y;
|
|
1945
1913
|
params.qx = qx;
|
|
1946
1914
|
params.qy = qy;
|
|
1947
1915
|
return [
|
|
@@ -1957,8 +1925,7 @@ const normalizeSegment = (segment, params) => {
|
|
|
1957
1925
|
} else if (absCommand === "Z") return ["Z"];
|
|
1958
1926
|
return segment;
|
|
1959
1927
|
};
|
|
1960
|
-
|
|
1961
|
-
//#region src/parser/paramsParser.ts
|
|
1928
|
+
// src/parser/paramsParser.ts
|
|
1962
1929
|
/**
|
|
1963
1930
|
* Default parser parameters object used to track position state
|
|
1964
1931
|
* while iterating through path segments.
|
|
@@ -1968,15 +1935,14 @@ const paramsParser = {
|
|
|
1968
1935
|
my: 0,
|
|
1969
1936
|
x1: 0,
|
|
1970
1937
|
y1: 0,
|
|
1971
|
-
x2:
|
|
1972
|
-
y2:
|
|
1938
|
+
x2: null,
|
|
1939
|
+
y2: null,
|
|
1973
1940
|
x: 0,
|
|
1974
1941
|
y: 0,
|
|
1975
1942
|
qx: null,
|
|
1976
1943
|
qy: null
|
|
1977
1944
|
};
|
|
1978
|
-
|
|
1979
|
-
//#region src/convert/pathToCurve.ts
|
|
1945
|
+
// src/convert/pathToCurve.ts
|
|
1980
1946
|
/**
|
|
1981
1947
|
* Parses a path string or PathArray and returns a new one
|
|
1982
1948
|
* in which all segments are converted to cubic-bezier.
|
|
@@ -1993,10 +1959,11 @@ const paramsParser = {
|
|
|
1993
1959
|
const pathToCurve = (pathInput) => {
|
|
1994
1960
|
const params = { ...paramsParser };
|
|
1995
1961
|
const path = parsePathString(pathInput);
|
|
1962
|
+
let prevCommand = null;
|
|
1996
1963
|
return iterate(path, (seg, index, lastX, lastY) => {
|
|
1997
1964
|
params.x = lastX;
|
|
1998
1965
|
params.y = lastY;
|
|
1999
|
-
const normalSegment = normalizeSegment(seg, params);
|
|
1966
|
+
const normalSegment = normalizeSegment(seg, params, prevCommand);
|
|
2000
1967
|
if (normalSegment[0] === "M") {
|
|
2001
1968
|
params.mx = normalSegment[1];
|
|
2002
1969
|
params.my = normalSegment[2];
|
|
@@ -2009,13 +1976,18 @@ const pathToCurve = (pathInput) => {
|
|
|
2009
1976
|
const seglen = result.length;
|
|
2010
1977
|
params.x1 = +result[seglen - 2];
|
|
2011
1978
|
params.y1 = +result[seglen - 1];
|
|
2012
|
-
|
|
2013
|
-
|
|
1979
|
+
if (normalSegment[0] === "C") {
|
|
1980
|
+
params.x2 = +result[seglen - 4];
|
|
1981
|
+
params.y2 = +result[seglen - 3];
|
|
1982
|
+
} else {
|
|
1983
|
+
params.x2 = null;
|
|
1984
|
+
params.y2 = null;
|
|
1985
|
+
}
|
|
1986
|
+
prevCommand = normalSegment[0];
|
|
2014
1987
|
return result;
|
|
2015
1988
|
});
|
|
2016
1989
|
};
|
|
2017
|
-
|
|
2018
|
-
//#region src/options/options.ts
|
|
1990
|
+
// src/options/options.ts
|
|
2019
1991
|
/** SVGPathCommander default options */
|
|
2020
1992
|
const defaultOptions = {
|
|
2021
1993
|
origin: [
|
|
@@ -2025,8 +1997,7 @@ const defaultOptions = {
|
|
|
2025
1997
|
],
|
|
2026
1998
|
round: 4
|
|
2027
1999
|
};
|
|
2028
|
-
|
|
2029
|
-
//#region src/convert/pathToString.ts
|
|
2000
|
+
// src/convert/pathToString.ts
|
|
2030
2001
|
/**
|
|
2031
2002
|
* Returns a valid `d` attribute string value created
|
|
2032
2003
|
* by rounding values and concatenating the PathArray segments.
|
|
@@ -2064,8 +2035,7 @@ const pathToString = (path, roundOption) => {
|
|
|
2064
2035
|
}
|
|
2065
2036
|
return result;
|
|
2066
2037
|
};
|
|
2067
|
-
|
|
2068
|
-
//#region src/util/getPathBBox.ts
|
|
2038
|
+
// src/util/getPathBBox.ts
|
|
2069
2039
|
/**
|
|
2070
2040
|
* Calculates the bounding box of a path.
|
|
2071
2041
|
*
|
|
@@ -2188,8 +2158,7 @@ const getPathBBox = (pathInput) => {
|
|
|
2188
2158
|
cz: Math.max(width, height) + Math.min(width, height) / 2
|
|
2189
2159
|
};
|
|
2190
2160
|
};
|
|
2191
|
-
|
|
2192
|
-
//#region src/util/getTotalLength.ts
|
|
2161
|
+
// src/util/getTotalLength.ts
|
|
2193
2162
|
/**
|
|
2194
2163
|
* Returns the total length of a path, equivalent to `shape.getTotalLength()`.
|
|
2195
2164
|
*
|
|
@@ -2254,12 +2223,10 @@ const getTotalLength = (pathInput) => {
|
|
|
2254
2223
|
});
|
|
2255
2224
|
return totalLength;
|
|
2256
2225
|
};
|
|
2257
|
-
|
|
2258
|
-
//#region src/util/distanceEpsilon.ts
|
|
2226
|
+
// src/util/distanceEpsilon.ts
|
|
2259
2227
|
/** Small threshold value used for floating-point distance comparisons in path calculations. */
|
|
2260
2228
|
const DISTANCE_EPSILON = 1e-5;
|
|
2261
|
-
|
|
2262
|
-
//#region src/process/normalizePath.ts
|
|
2229
|
+
// src/process/normalizePath.ts
|
|
2263
2230
|
/**
|
|
2264
2231
|
* Parses a path string or PathArray, then iterates the result for:
|
|
2265
2232
|
* * converting segments to absolute values
|
|
@@ -2277,20 +2244,26 @@ const DISTANCE_EPSILON = 1e-5;
|
|
|
2277
2244
|
const normalizePath = (pathInput) => {
|
|
2278
2245
|
const path = parsePathString(pathInput);
|
|
2279
2246
|
const params = { ...paramsParser };
|
|
2247
|
+
let prevCommand = null;
|
|
2280
2248
|
return iterate(path, (seg, _, lastX, lastY) => {
|
|
2281
2249
|
params.x = lastX;
|
|
2282
2250
|
params.y = lastY;
|
|
2283
|
-
const result = normalizeSegment(seg, params);
|
|
2251
|
+
const result = normalizeSegment(seg, params, prevCommand);
|
|
2284
2252
|
const seglen = result.length;
|
|
2285
2253
|
params.x1 = +result[seglen - 2];
|
|
2286
2254
|
params.y1 = +result[seglen - 1];
|
|
2287
|
-
|
|
2288
|
-
|
|
2255
|
+
if (result[0] === "C" || result[0] === "Q") {
|
|
2256
|
+
params.x2 = +result[seglen - 4];
|
|
2257
|
+
params.y2 = +result[seglen - 3];
|
|
2258
|
+
} else {
|
|
2259
|
+
params.x2 = null;
|
|
2260
|
+
params.y2 = null;
|
|
2261
|
+
}
|
|
2262
|
+
prevCommand = result[0];
|
|
2289
2263
|
return result;
|
|
2290
2264
|
});
|
|
2291
2265
|
};
|
|
2292
|
-
|
|
2293
|
-
//#region src/util/getPointAtLength.ts
|
|
2266
|
+
// src/util/getPointAtLength.ts
|
|
2294
2267
|
/**
|
|
2295
2268
|
* Returns [x,y] coordinates of a point at a given length along a path.
|
|
2296
2269
|
*
|
|
@@ -2357,8 +2330,7 @@ const getPointAtLength = (pathInput, distance) => {
|
|
|
2357
2330
|
});
|
|
2358
2331
|
return POINT;
|
|
2359
2332
|
};
|
|
2360
|
-
|
|
2361
|
-
//#region src/util/getPropertiesAtLength.ts
|
|
2333
|
+
// src/util/getPropertiesAtLength.ts
|
|
2362
2334
|
/**
|
|
2363
2335
|
* Returns the segment, its index and length as well as
|
|
2364
2336
|
* the length to that segment at a given length in a path.
|
|
@@ -2410,8 +2382,7 @@ const getPropertiesAtLength = (pathInput, distance) => {
|
|
|
2410
2382
|
}
|
|
2411
2383
|
return segments.find(({ lengthAtSegment: l }) => l <= distance);
|
|
2412
2384
|
};
|
|
2413
|
-
|
|
2414
|
-
//#region src/util/getPropertiesAtPoint.ts
|
|
2385
|
+
// src/util/getPropertiesAtPoint.ts
|
|
2415
2386
|
/**
|
|
2416
2387
|
* Returns the point and segment in path closest to a given point as well as
|
|
2417
2388
|
* the distance to the path stroke.
|
|
@@ -2481,8 +2452,7 @@ const getPropertiesAtPoint = (pathInput, point) => {
|
|
|
2481
2452
|
segment
|
|
2482
2453
|
};
|
|
2483
2454
|
};
|
|
2484
|
-
|
|
2485
|
-
//#region src/util/getClosestPoint.ts
|
|
2455
|
+
// src/util/getClosestPoint.ts
|
|
2486
2456
|
/**
|
|
2487
2457
|
* Returns the point in path closest to a given point.
|
|
2488
2458
|
*
|
|
@@ -2493,8 +2463,7 @@ const getPropertiesAtPoint = (pathInput, point) => {
|
|
|
2493
2463
|
const getClosestPoint = (pathInput, point) => {
|
|
2494
2464
|
return getPropertiesAtPoint(pathInput, point).closest;
|
|
2495
2465
|
};
|
|
2496
|
-
|
|
2497
|
-
//#region src/util/getPathArea.ts
|
|
2466
|
+
// src/util/getPathArea.ts
|
|
2498
2467
|
/**
|
|
2499
2468
|
* Returns the area of a single cubic-bezier segment.
|
|
2500
2469
|
*
|
|
@@ -2545,8 +2514,7 @@ const getPathArea = (path) => {
|
|
|
2545
2514
|
}
|
|
2546
2515
|
}).reduce((a, b) => a + b, 0);
|
|
2547
2516
|
};
|
|
2548
|
-
|
|
2549
|
-
//#region src/util/getDrawDirection.ts
|
|
2517
|
+
// src/util/getDrawDirection.ts
|
|
2550
2518
|
/**
|
|
2551
2519
|
* Check if a path is drawn clockwise and returns true if so,
|
|
2552
2520
|
* false otherwise.
|
|
@@ -2557,8 +2525,7 @@ const getPathArea = (path) => {
|
|
|
2557
2525
|
const getDrawDirection = (path) => {
|
|
2558
2526
|
return getPathArea(pathToCurve(path)) >= 0;
|
|
2559
2527
|
};
|
|
2560
|
-
|
|
2561
|
-
//#region src/util/getSegmentAtLength.ts
|
|
2528
|
+
// src/util/getSegmentAtLength.ts
|
|
2562
2529
|
/**
|
|
2563
2530
|
* Returns the segment at a given length.
|
|
2564
2531
|
*
|
|
@@ -2569,8 +2536,7 @@ const getDrawDirection = (path) => {
|
|
|
2569
2536
|
const getSegmentAtLength = (pathInput, distance) => {
|
|
2570
2537
|
return getPropertiesAtLength(pathInput, distance).segment;
|
|
2571
2538
|
};
|
|
2572
|
-
|
|
2573
|
-
//#region src/util/getSegmentOfPoint.ts
|
|
2539
|
+
// src/util/getSegmentOfPoint.ts
|
|
2574
2540
|
/**
|
|
2575
2541
|
* Returns the path segment which contains a given point.
|
|
2576
2542
|
*
|
|
@@ -2581,8 +2547,7 @@ const getSegmentAtLength = (pathInput, distance) => {
|
|
|
2581
2547
|
const getSegmentOfPoint = (path, point) => {
|
|
2582
2548
|
return getPropertiesAtPoint(path, point).segment;
|
|
2583
2549
|
};
|
|
2584
|
-
|
|
2585
|
-
//#region src/util/isPathArray.ts
|
|
2550
|
+
// src/util/isPathArray.ts
|
|
2586
2551
|
/**
|
|
2587
2552
|
* Iterates an array to check if it's an actual `pathArray`.
|
|
2588
2553
|
*
|
|
@@ -2595,8 +2560,7 @@ const isPathArray = (path) => {
|
|
|
2595
2560
|
return paramsCounts[lk] === seg.length - 1 && "achlmqstvz".includes(lk) && seg.slice(1).every(Number.isFinite);
|
|
2596
2561
|
}) && path.length > 0;
|
|
2597
2562
|
};
|
|
2598
|
-
|
|
2599
|
-
//#region src/util/isAbsoluteArray.ts
|
|
2563
|
+
// src/util/isAbsoluteArray.ts
|
|
2600
2564
|
/**
|
|
2601
2565
|
* Iterates an array to check if it's a `pathArray`
|
|
2602
2566
|
* with all absolute values.
|
|
@@ -2607,8 +2571,7 @@ const isPathArray = (path) => {
|
|
|
2607
2571
|
const isAbsoluteArray = (path) => {
|
|
2608
2572
|
return isPathArray(path) && path.every(([x]) => x === x.toUpperCase());
|
|
2609
2573
|
};
|
|
2610
|
-
|
|
2611
|
-
//#region src/util/isNormalizedArray.ts
|
|
2574
|
+
// src/util/isNormalizedArray.ts
|
|
2612
2575
|
/**
|
|
2613
2576
|
* Iterates an array to check if it's a `pathArray`
|
|
2614
2577
|
* with all segments in non-shorthand notation
|
|
@@ -2620,8 +2583,7 @@ const isAbsoluteArray = (path) => {
|
|
|
2620
2583
|
const isNormalizedArray = (path) => {
|
|
2621
2584
|
return isAbsoluteArray(path) && path.every(([pc]) => "ACLMQZ".includes(pc));
|
|
2622
2585
|
};
|
|
2623
|
-
|
|
2624
|
-
//#region src/util/isCurveArray.ts
|
|
2586
|
+
// src/util/isCurveArray.ts
|
|
2625
2587
|
/**
|
|
2626
2588
|
* Iterates an array to check if it's a `pathArray`
|
|
2627
2589
|
* with all C (cubic bezier) segments.
|
|
@@ -2632,8 +2594,7 @@ const isNormalizedArray = (path) => {
|
|
|
2632
2594
|
const isCurveArray = (path) => {
|
|
2633
2595
|
return isNormalizedArray(path) && path.every(([pc]) => "MC".includes(pc));
|
|
2634
2596
|
};
|
|
2635
|
-
|
|
2636
|
-
//#region src/util/isPointInStroke.ts
|
|
2597
|
+
// src/util/isPointInStroke.ts
|
|
2637
2598
|
/**
|
|
2638
2599
|
* Checks if a given point is in the stroke of a path.
|
|
2639
2600
|
*
|
|
@@ -2645,8 +2606,7 @@ const isPointInStroke = (pathInput, point) => {
|
|
|
2645
2606
|
const { distance } = getPropertiesAtPoint(pathInput, point);
|
|
2646
2607
|
return Math.abs(distance) < DISTANCE_EPSILON;
|
|
2647
2608
|
};
|
|
2648
|
-
|
|
2649
|
-
//#region src/util/isPolygonArray.ts
|
|
2609
|
+
// src/util/isPolygonArray.ts
|
|
2650
2610
|
/**
|
|
2651
2611
|
* Checks if a path is a polygon (only M, L, H, V, Z commands).
|
|
2652
2612
|
* @param pathArray PathArray (pre-normalize if needed)
|
|
@@ -2655,8 +2615,7 @@ const isPointInStroke = (pathInput, point) => {
|
|
|
2655
2615
|
const isPolygonArray = (path) => {
|
|
2656
2616
|
return isNormalizedArray(path) && path.every(([pc]) => "MLVHZ".includes(pc));
|
|
2657
2617
|
};
|
|
2658
|
-
|
|
2659
|
-
//#region src/util/isPolylineArray.ts
|
|
2618
|
+
// src/util/isPolylineArray.ts
|
|
2660
2619
|
/**
|
|
2661
2620
|
* Checks if a path is a polyline (only M, L, H, V commands).
|
|
2662
2621
|
* @param pathArray PathArray (pre-normalize if needed)
|
|
@@ -2665,8 +2624,7 @@ const isPolygonArray = (path) => {
|
|
|
2665
2624
|
function isPolylineArray(path) {
|
|
2666
2625
|
return isNormalizedArray(path) && path.every(([pc]) => "MLVH".includes(pc));
|
|
2667
2626
|
}
|
|
2668
|
-
|
|
2669
|
-
//#region src/util/isRelativeArray.ts
|
|
2627
|
+
// src/util/isRelativeArray.ts
|
|
2670
2628
|
/**
|
|
2671
2629
|
* Iterates an array to check if it's a `pathArray`
|
|
2672
2630
|
* with relative values.
|
|
@@ -2677,8 +2635,7 @@ function isPolylineArray(path) {
|
|
|
2677
2635
|
const isRelativeArray = (path) => {
|
|
2678
2636
|
return isPathArray(path) && path.slice(1).every(([pc]) => pc === pc.toLowerCase());
|
|
2679
2637
|
};
|
|
2680
|
-
|
|
2681
|
-
//#region src/util/isValidPath.ts
|
|
2638
|
+
// src/util/isValidPath.ts
|
|
2682
2639
|
/**
|
|
2683
2640
|
* Parses a path string value to determine its validity
|
|
2684
2641
|
* then returns true if it's valid or false otherwise.
|
|
@@ -2693,8 +2650,7 @@ const isValidPath = (pathString) => {
|
|
|
2693
2650
|
while (path.index < path.max && !path.err.length) scanSegment(path);
|
|
2694
2651
|
return !path.err.length && "mM".includes(path.segments[0][0]);
|
|
2695
2652
|
};
|
|
2696
|
-
|
|
2697
|
-
//#region src/util/isMultiPath.ts
|
|
2653
|
+
// src/util/isMultiPath.ts
|
|
2698
2654
|
/**
|
|
2699
2655
|
* Determines if an SVG path contains multiple subpaths.
|
|
2700
2656
|
* Accepts path string or PathArray.
|
|
@@ -2716,8 +2672,7 @@ const isMultiPath = (path) => {
|
|
|
2716
2672
|
}
|
|
2717
2673
|
throw new TypeError(error + ": expected string or PathArray");
|
|
2718
2674
|
};
|
|
2719
|
-
|
|
2720
|
-
//#region src/util/isClosedPath.ts
|
|
2675
|
+
// src/util/isClosedPath.ts
|
|
2721
2676
|
/**
|
|
2722
2677
|
* Check if a PathArray is closed, which means its last segment is a Z.
|
|
2723
2678
|
* @param path
|
|
@@ -2726,8 +2681,7 @@ const isMultiPath = (path) => {
|
|
|
2726
2681
|
const isClosedPath = (path) => {
|
|
2727
2682
|
return path[path.length - 1][0].toUpperCase() === "Z";
|
|
2728
2683
|
};
|
|
2729
|
-
|
|
2730
|
-
//#region src/util/shapeParams.ts
|
|
2684
|
+
// src/util/shapeParams.ts
|
|
2731
2685
|
/**
|
|
2732
2686
|
* Supported shapes and their specific parameters.
|
|
2733
2687
|
*/
|
|
@@ -2761,8 +2715,7 @@ const shapeParams = {
|
|
|
2761
2715
|
polyline: ["points"],
|
|
2762
2716
|
glyph: ["d"]
|
|
2763
2717
|
};
|
|
2764
|
-
|
|
2765
|
-
//#region src/util/isElement.ts
|
|
2718
|
+
// src/util/isElement.ts
|
|
2766
2719
|
/**
|
|
2767
2720
|
* Checks if a value is a DOM Element.
|
|
2768
2721
|
*
|
|
@@ -2770,8 +2723,7 @@ const shapeParams = {
|
|
|
2770
2723
|
* @returns True if the value is a DOM Element (nodeType === 1)
|
|
2771
2724
|
*/
|
|
2772
2725
|
const isElement = (node) => node !== void 0 && node !== null && typeof node === "object" && node.nodeType === 1;
|
|
2773
|
-
|
|
2774
|
-
//#region src/util/shapeToPathArray.ts
|
|
2726
|
+
// src/util/shapeToPathArray.ts
|
|
2775
2727
|
/**
|
|
2776
2728
|
* Returns a new PathArray from line attributes.
|
|
2777
2729
|
*
|
|
@@ -3031,8 +2983,7 @@ const shapeToPathArray = (element) => {
|
|
|
3031
2983
|
if (isPathArray(pathArray) && pathArray.length) return pathArray;
|
|
3032
2984
|
return false;
|
|
3033
2985
|
};
|
|
3034
|
-
|
|
3035
|
-
//#region src/util/shapeToPath.ts
|
|
2986
|
+
// src/util/shapeToPath.ts
|
|
3036
2987
|
/**
|
|
3037
2988
|
* Returns a new `<path>` element created from attributes of a `<line>`, `<polyline>`,
|
|
3038
2989
|
* `<polygon>`, `<rect>`, `<ellipse>`, `<circle>` or `<glyph>`. If `replace` parameter
|
|
@@ -3100,8 +3051,7 @@ const shapeToPath = (element, replace, ownerDocument) => {
|
|
|
3100
3051
|
}
|
|
3101
3052
|
return false;
|
|
3102
3053
|
};
|
|
3103
|
-
|
|
3104
|
-
//#region src/process/shortenSegment.ts
|
|
3054
|
+
// src/process/shortenSegment.ts
|
|
3105
3055
|
/**
|
|
3106
3056
|
* Shorten a single segment of a `pathArray` object.
|
|
3107
3057
|
*
|
|
@@ -3116,7 +3066,7 @@ const shortenSegment = (segment, normalSegment, params, prevCommand) => {
|
|
|
3116
3066
|
const { round: defaultRound } = defaultOptions;
|
|
3117
3067
|
const round = typeof defaultRound === "number" ? defaultRound : 4;
|
|
3118
3068
|
const normalValues = normalSegment.slice(1);
|
|
3119
|
-
const {
|
|
3069
|
+
const { x2, y2, x, y } = params;
|
|
3120
3070
|
const [nx, ny] = normalValues.slice(-2);
|
|
3121
3071
|
const result = segment;
|
|
3122
3072
|
if (!"TQ".includes(pathCommand)) {
|
|
@@ -3128,9 +3078,7 @@ const shortenSegment = (segment, normalSegment, params, prevCommand) => {
|
|
|
3128
3078
|
else if (roundTo(y, round) === roundTo(ny, round)) return ["H", nx];
|
|
3129
3079
|
} else if (pathCommand === "C") {
|
|
3130
3080
|
const [nx1, ny1] = normalValues;
|
|
3131
|
-
|
|
3132
|
-
params.y1 = ny1;
|
|
3133
|
-
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 [
|
|
3081
|
+
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 [
|
|
3134
3082
|
"S",
|
|
3135
3083
|
normalValues[2],
|
|
3136
3084
|
normalValues[3],
|
|
@@ -3141,7 +3089,7 @@ const shortenSegment = (segment, normalSegment, params, prevCommand) => {
|
|
|
3141
3089
|
const [qx, qy] = normalValues;
|
|
3142
3090
|
params.qx = qx;
|
|
3143
3091
|
params.qy = qy;
|
|
3144
|
-
if ("QT".includes(prevCommand) && roundTo(qx, round) === roundTo(
|
|
3092
|
+
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 [
|
|
3145
3093
|
"T",
|
|
3146
3094
|
normalValues[2],
|
|
3147
3095
|
normalValues[3]
|
|
@@ -3149,8 +3097,7 @@ const shortenSegment = (segment, normalSegment, params, prevCommand) => {
|
|
|
3149
3097
|
}
|
|
3150
3098
|
return result;
|
|
3151
3099
|
};
|
|
3152
|
-
|
|
3153
|
-
//#region src/process/roundSegment.ts
|
|
3100
|
+
// src/process/roundSegment.ts
|
|
3154
3101
|
/**
|
|
3155
3102
|
* Rounds the numeric values of a path segment to the specified precision.
|
|
3156
3103
|
*
|
|
@@ -3162,8 +3109,7 @@ const roundSegment = (segment, roundOption) => {
|
|
|
3162
3109
|
const values = segment.slice(1).map((n) => roundTo(n, roundOption));
|
|
3163
3110
|
return [segment[0]].concat(values);
|
|
3164
3111
|
};
|
|
3165
|
-
|
|
3166
|
-
//#region src/process/optimizePath.ts
|
|
3112
|
+
// src/process/optimizePath.ts
|
|
3167
3113
|
/**
|
|
3168
3114
|
* Optimizes a PathArray:
|
|
3169
3115
|
* * converts segments to shorthand if possible
|
|
@@ -3189,12 +3135,12 @@ const optimizePath = (pathInput, roundOption) => {
|
|
|
3189
3135
|
return iterate(path, (seg, i, lastX, lastY) => {
|
|
3190
3136
|
optimParams.x = lastX;
|
|
3191
3137
|
optimParams.y = lastY;
|
|
3192
|
-
const normalizedSegment = normalizeSegment(seg, optimParams);
|
|
3193
3138
|
let result = seg;
|
|
3194
3139
|
pathCommand = seg[0];
|
|
3195
3140
|
allPathCommands[i] = pathCommand;
|
|
3141
|
+
if (i) prevCommand = allPathCommands[i - 1];
|
|
3142
|
+
const normalizedSegment = normalizeSegment(seg, optimParams, i ? prevCommand : null);
|
|
3196
3143
|
if (i) {
|
|
3197
|
-
prevCommand = allPathCommands[i - 1];
|
|
3198
3144
|
const shortSegment = shortenSegment(seg, normalizedSegment, optimParams, prevCommand);
|
|
3199
3145
|
const absSegment = roundSegment(shortSegment, round);
|
|
3200
3146
|
const absString = absSegment.join("");
|
|
@@ -3206,31 +3152,48 @@ const optimizePath = (pathInput, roundOption) => {
|
|
|
3206
3152
|
const seglen = normalizedSegment.length;
|
|
3207
3153
|
optimParams.x1 = +normalizedSegment[seglen - 2];
|
|
3208
3154
|
optimParams.y1 = +normalizedSegment[seglen - 1];
|
|
3209
|
-
|
|
3210
|
-
|
|
3155
|
+
if (normalizedSegment[0] === "C" || normalizedSegment[0] === "Q") {
|
|
3156
|
+
optimParams.x2 = +normalizedSegment[seglen - 4];
|
|
3157
|
+
optimParams.y2 = +normalizedSegment[seglen - 3];
|
|
3158
|
+
} else {
|
|
3159
|
+
optimParams.x2 = null;
|
|
3160
|
+
optimParams.y2 = null;
|
|
3161
|
+
}
|
|
3211
3162
|
return result;
|
|
3212
3163
|
});
|
|
3213
3164
|
};
|
|
3214
|
-
|
|
3215
|
-
//#region src/process/reversePath.ts
|
|
3165
|
+
// src/process/reversePath.ts
|
|
3216
3166
|
/**
|
|
3217
|
-
* Reverses
|
|
3167
|
+
* Reverses the segments of a single sub-path and returns a new PathArray
|
|
3218
3168
|
* with absolute values.
|
|
3219
3169
|
*
|
|
3220
|
-
* @param
|
|
3170
|
+
* @param absolutePath - The absolute PathArray of a single sub-path
|
|
3221
3171
|
* @returns The reversed PathArray
|
|
3222
|
-
*
|
|
3223
|
-
* @example
|
|
3224
|
-
* ```ts
|
|
3225
|
-
* reversePath([['M', 0, 0], ['L', 100, 0], ['L', 100, 100], ['L', 0, 100], ['Z']])
|
|
3226
|
-
* // => [['M', 0, 100], ['L', 0, 0], ['L', 100, 0], ['L', 100, 100], ['Z']]
|
|
3227
|
-
* ```
|
|
3228
3172
|
*/
|
|
3229
|
-
const
|
|
3230
|
-
const absolutePath = pathToAbsolute(pathInput);
|
|
3173
|
+
const reverseSubPath = (absolutePath) => {
|
|
3231
3174
|
const normalizedPath = normalizePath(absolutePath);
|
|
3232
3175
|
const pLen = absolutePath.length;
|
|
3233
3176
|
const isClosed = absolutePath[pLen - 1][0] === "Z";
|
|
3177
|
+
const endPoints = [];
|
|
3178
|
+
let endX = 0;
|
|
3179
|
+
let endY = 0;
|
|
3180
|
+
let subX = 0;
|
|
3181
|
+
let subY = 0;
|
|
3182
|
+
for (const seg of normalizedPath) {
|
|
3183
|
+
if (seg[0] === "M") {
|
|
3184
|
+
subX = +seg[1];
|
|
3185
|
+
subY = +seg[2];
|
|
3186
|
+
endX = subX;
|
|
3187
|
+
endY = subY;
|
|
3188
|
+
} else if (seg[0] === "Z") {
|
|
3189
|
+
endX = subX;
|
|
3190
|
+
endY = subY;
|
|
3191
|
+
} else {
|
|
3192
|
+
endX = +seg[seg.length - 2];
|
|
3193
|
+
endY = +seg[seg.length - 1];
|
|
3194
|
+
}
|
|
3195
|
+
endPoints.push([endX, endY]);
|
|
3196
|
+
}
|
|
3234
3197
|
const reversedPath = iterate(absolutePath, (segment, i) => {
|
|
3235
3198
|
const normalizedSegment = normalizedPath[i];
|
|
3236
3199
|
const prevSeg = i && absolutePath[i - 1];
|
|
@@ -3238,7 +3201,7 @@ const reversePath = (pathInput) => {
|
|
|
3238
3201
|
const nextSeg = absolutePath[i + 1];
|
|
3239
3202
|
const nextCommand = nextSeg && nextSeg[0];
|
|
3240
3203
|
const pathCommand = segment[0];
|
|
3241
|
-
const [x, y] =
|
|
3204
|
+
const [x, y] = endPoints[i ? i - 1 : pLen - 1];
|
|
3242
3205
|
let result = segment;
|
|
3243
3206
|
switch (pathCommand) {
|
|
3244
3207
|
case "M":
|
|
@@ -3279,17 +3242,17 @@ const reversePath = (pathInput) => {
|
|
|
3279
3242
|
];
|
|
3280
3243
|
break;
|
|
3281
3244
|
case "S":
|
|
3282
|
-
if (
|
|
3283
|
-
|
|
3284
|
-
normalizedSegment[3],
|
|
3285
|
-
normalizedSegment[4],
|
|
3245
|
+
if (nextSeg && nextCommand === "S") result = [
|
|
3246
|
+
pathCommand,
|
|
3286
3247
|
normalizedSegment[1],
|
|
3287
3248
|
normalizedSegment[2],
|
|
3288
3249
|
x,
|
|
3289
3250
|
y
|
|
3290
3251
|
];
|
|
3291
3252
|
else result = [
|
|
3292
|
-
|
|
3253
|
+
"C",
|
|
3254
|
+
normalizedSegment[3],
|
|
3255
|
+
normalizedSegment[4],
|
|
3293
3256
|
normalizedSegment[1],
|
|
3294
3257
|
normalizedSegment[2],
|
|
3295
3258
|
x,
|
|
@@ -3343,8 +3306,39 @@ const reversePath = (pathInput) => {
|
|
|
3343
3306
|
});
|
|
3344
3307
|
return isClosed ? reversedPath.reverse() : [reversedPath[0]].concat(reversedPath.slice(1).reverse());
|
|
3345
3308
|
};
|
|
3346
|
-
|
|
3347
|
-
|
|
3309
|
+
/**
|
|
3310
|
+
* Reverses all segments of a PathArray and returns a new PathArray
|
|
3311
|
+
* with absolute values.
|
|
3312
|
+
*
|
|
3313
|
+
* Every sub-path is reversed on its own, so the `M` and the `Z` of a
|
|
3314
|
+
* sub-path are swapped with each other and the sub-paths keep their
|
|
3315
|
+
* original order.
|
|
3316
|
+
*
|
|
3317
|
+
* @param pathInput - The source PathArray
|
|
3318
|
+
* @returns The reversed PathArray
|
|
3319
|
+
*
|
|
3320
|
+
* @example
|
|
3321
|
+
* ```ts
|
|
3322
|
+
* reversePath([['M', 0, 0], ['L', 100, 0], ['L', 100, 100], ['L', 0, 100], ['Z']])
|
|
3323
|
+
* // => [['M', 0, 100], ['L', 0, 0], ['L', 100, 0], ['L', 100, 100], ['Z']]
|
|
3324
|
+
* ```
|
|
3325
|
+
*/
|
|
3326
|
+
const reversePath = (pathInput) => {
|
|
3327
|
+
const absolutePath = pathToAbsolute(pathInput);
|
|
3328
|
+
const subPaths = [];
|
|
3329
|
+
let subPath = [];
|
|
3330
|
+
for (const segment of absolutePath) {
|
|
3331
|
+
if (segment[0] === "M" && subPath.length) {
|
|
3332
|
+
subPaths.push(subPath);
|
|
3333
|
+
subPath = [];
|
|
3334
|
+
}
|
|
3335
|
+
subPath.push(segment);
|
|
3336
|
+
}
|
|
3337
|
+
if (subPath.length) subPaths.push(subPath);
|
|
3338
|
+
const reversed = subPaths.map((path) => reverseSubPath(path));
|
|
3339
|
+
return reversed.length === 1 ? reversed[0] : reversed.flat();
|
|
3340
|
+
};
|
|
3341
|
+
// src/process/splitPath.ts
|
|
3348
3342
|
/**
|
|
3349
3343
|
* Split a path string or PathArray into an array of sub-paths.
|
|
3350
3344
|
*
|
|
@@ -3410,8 +3404,7 @@ const splitPath = (pathInput) => {
|
|
|
3410
3404
|
});
|
|
3411
3405
|
return composite;
|
|
3412
3406
|
};
|
|
3413
|
-
|
|
3414
|
-
//#region src/process/getSVGMatrix.ts
|
|
3407
|
+
// src/process/getSVGMatrix.ts
|
|
3415
3408
|
/**
|
|
3416
3409
|
* Returns a transformation matrix to apply to `<path>` elements.
|
|
3417
3410
|
*
|
|
@@ -3444,8 +3437,7 @@ const getSVGMatrix = (transform) => {
|
|
|
3444
3437
|
}
|
|
3445
3438
|
return matrix;
|
|
3446
3439
|
};
|
|
3447
|
-
|
|
3448
|
-
//#region src/process/projection2d.ts
|
|
3440
|
+
// src/process/projection2d.ts
|
|
3449
3441
|
/**
|
|
3450
3442
|
* Transforms a specified point using a matrix, returning a new
|
|
3451
3443
|
* Tuple *Object* comprising of the transformed point.
|
|
@@ -3501,8 +3493,7 @@ const projection2d = (m, point2D, origin) => {
|
|
|
3501
3493
|
const relativePositionZ = z - originZ;
|
|
3502
3494
|
return [relativePositionX * (Math.abs(originZ) / Math.abs(relativePositionZ) || 1) + originX, relativePositionY * (Math.abs(originZ) / Math.abs(relativePositionZ) || 1) + originY];
|
|
3503
3495
|
};
|
|
3504
|
-
|
|
3505
|
-
//#region src/process/transformPath.ts
|
|
3496
|
+
// src/process/transformPath.ts
|
|
3506
3497
|
/**
|
|
3507
3498
|
* Applies a 2D transformation to a `PathArray` in a single pass, without
|
|
3508
3499
|
* absolutizing or copying each segment, returning a new absolute `PathArray`.
|
|
@@ -3726,8 +3717,7 @@ const transformPath = (pathInput, transform) => {
|
|
|
3726
3717
|
return result;
|
|
3727
3718
|
});
|
|
3728
3719
|
};
|
|
3729
|
-
|
|
3730
|
-
//#region src/process/reverseCurve.ts
|
|
3720
|
+
// src/process/reverseCurve.ts
|
|
3731
3721
|
/**
|
|
3732
3722
|
* Reverses all segments of a `pathArray`
|
|
3733
3723
|
* which consists of only C (cubic-bezier) path commands.
|
|
@@ -3739,8 +3729,7 @@ const reverseCurve = (path) => {
|
|
|
3739
3729
|
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();
|
|
3740
3730
|
return [["M"].concat(rotatedCurve[0].slice(0, 2))].concat(rotatedCurve.map((x) => ["C"].concat(x.slice(2))));
|
|
3741
3731
|
};
|
|
3742
|
-
|
|
3743
|
-
//#region src/process/roundPath.ts
|
|
3732
|
+
// src/process/roundPath.ts
|
|
3744
3733
|
/**
|
|
3745
3734
|
* Rounds the values of a `pathArray` instance to
|
|
3746
3735
|
* a specified amount of decimals and returns it.
|
|
@@ -3757,8 +3746,7 @@ const roundPath = (path, roundOption) => {
|
|
|
3757
3746
|
return roundSegment(segment, round);
|
|
3758
3747
|
});
|
|
3759
3748
|
};
|
|
3760
|
-
|
|
3761
|
-
//#region src/morph/fixPath.ts
|
|
3749
|
+
// src/morph/fixPath.ts
|
|
3762
3750
|
/**
|
|
3763
3751
|
* Checks a `PathArray` for an unnecessary `Z` segment
|
|
3764
3752
|
* and removes it. The `PathArray` is modified in place.
|
|
@@ -3784,8 +3772,7 @@ const fixPath = (pathInput) => {
|
|
|
3784
3772
|
if (mx === x && my === y) pathArray.splice(length - 1, 1);
|
|
3785
3773
|
}
|
|
3786
3774
|
};
|
|
3787
|
-
|
|
3788
|
-
//#region src/morph/splitCubicSegment.ts
|
|
3775
|
+
// src/morph/splitCubicSegment.ts
|
|
3789
3776
|
/**
|
|
3790
3777
|
* Split a cubic Bézier into two cubics at parameter t [0–1].
|
|
3791
3778
|
*
|
|
@@ -3827,8 +3814,7 @@ function splitCubicSegment(x1, y1, x2, y2, x3, y3, x4, y4, t) {
|
|
|
3827
3814
|
y4
|
|
3828
3815
|
]];
|
|
3829
3816
|
}
|
|
3830
|
-
|
|
3831
|
-
//#region src/morph/pathToPolyline.ts
|
|
3817
|
+
// src/morph/pathToPolyline.ts
|
|
3832
3818
|
/**
|
|
3833
3819
|
* Converts any `PolyLineArray`/`PolygonArray` path (closed or open) to an explicit polyline (M + L*).
|
|
3834
3820
|
* If the path is closed (has Z), the Z is replaced with an explicit L back to the initial M point.
|
|
@@ -3854,8 +3840,7 @@ const pathToPolyline = (path) => {
|
|
|
3854
3840
|
}
|
|
3855
3841
|
return result;
|
|
3856
3842
|
};
|
|
3857
|
-
|
|
3858
|
-
//#region src/morph/splitLineToCount.ts
|
|
3843
|
+
// src/morph/splitLineToCount.ts
|
|
3859
3844
|
/**
|
|
3860
3845
|
* Split a line segment into `count` smaller segments of equal length
|
|
3861
3846
|
* using the same repeated front-cutting strategy as splitCubicToCount.
|
|
@@ -3898,8 +3883,7 @@ function splitLineToCount(x1, y1, x2, y2, count) {
|
|
|
3898
3883
|
}
|
|
3899
3884
|
return result;
|
|
3900
3885
|
}
|
|
3901
|
-
|
|
3902
|
-
//#region src/morph/getPathSplits.ts
|
|
3886
|
+
// src/morph/getPathSplits.ts
|
|
3903
3887
|
/**
|
|
3904
3888
|
* Determine the right amount of splits for each segment in a given PathArray
|
|
3905
3889
|
* and for a target total amount of sub-segments.
|
|
@@ -3964,8 +3948,7 @@ function getPathSplits(path, target) {
|
|
|
3964
3948
|
}
|
|
3965
3949
|
return splits;
|
|
3966
3950
|
}
|
|
3967
|
-
|
|
3968
|
-
//#region src/morph/splitLinePathToCount.ts
|
|
3951
|
+
// src/morph/splitLinePathToCount.ts
|
|
3969
3952
|
/**
|
|
3970
3953
|
* Splits a PolylineArray so that it has exactly `target` line segments.
|
|
3971
3954
|
*
|
|
@@ -4001,8 +3984,7 @@ function splitLinePathToCount(path, target) {
|
|
|
4001
3984
|
if (newPath.length !== target) console.warn(`${error}: requested ${target} segments, got ${newPath.length}. Adjusted on last segment.`);
|
|
4002
3985
|
return newPath;
|
|
4003
3986
|
}
|
|
4004
|
-
|
|
4005
|
-
//#region src/morph/splitCubicToCount.ts
|
|
3987
|
+
// src/morph/splitCubicToCount.ts
|
|
4006
3988
|
/**
|
|
4007
3989
|
* Split a cubic Bézier into `count` segments of roughly equal parameter length.
|
|
4008
3990
|
* Does NOT mutate input parameters.
|
|
@@ -4048,8 +4030,7 @@ function splitCubicToCount(x1, y1, x2, y2, x3, y3, x4, y4, count) {
|
|
|
4048
4030
|
}
|
|
4049
4031
|
return result;
|
|
4050
4032
|
}
|
|
4051
|
-
|
|
4052
|
-
//#region src/morph/splitCurvePathToCount.ts
|
|
4033
|
+
// src/morph/splitCurvePathToCount.ts
|
|
4053
4034
|
/**
|
|
4054
4035
|
* Splits a CurveArray so that it has exactly `target` cubic segments.
|
|
4055
4036
|
*
|
|
@@ -4090,8 +4071,7 @@ function splitCurvePathToCount(path, target) {
|
|
|
4090
4071
|
if (newPath.length !== target) console.warn(`${error}: requested ${target} segments, got ${newPath.length}.`);
|
|
4091
4072
|
return newPath;
|
|
4092
4073
|
}
|
|
4093
|
-
|
|
4094
|
-
//#region src/morph/samplePolygon.ts
|
|
4074
|
+
// src/morph/samplePolygon.ts
|
|
4095
4075
|
/**
|
|
4096
4076
|
* Samples points from a path to form a polygon approximation.
|
|
4097
4077
|
* Collects endpoints of each segment (M start + ends of L/C/etc).
|
|
@@ -4117,8 +4097,7 @@ function samplePolygon(path) {
|
|
|
4117
4097
|
});
|
|
4118
4098
|
return points;
|
|
4119
4099
|
}
|
|
4120
|
-
|
|
4121
|
-
//#region src/morph/getRotatedPath.ts
|
|
4100
|
+
// src/morph/getRotatedPath.ts
|
|
4122
4101
|
/**
|
|
4123
4102
|
* Returns all possible rotations of a path (line or curve) by shifting the start point.
|
|
4124
4103
|
* Each rotation is a new PathArray starting at a different original segment.
|
|
@@ -4183,8 +4162,7 @@ function getRotatedPath(pathA, pathB, computedRotations) {
|
|
|
4183
4162
|
}
|
|
4184
4163
|
return rotations[bestIndex];
|
|
4185
4164
|
}
|
|
4186
|
-
|
|
4187
|
-
//#region src/morph/equalizeSegments.ts
|
|
4165
|
+
// src/morph/equalizeSegments.ts
|
|
4188
4166
|
const equalizeSegmentsDefaults = {
|
|
4189
4167
|
mode: "auto",
|
|
4190
4168
|
sampleSize: 10,
|
|
@@ -4257,8 +4235,7 @@ const equalizeSegments = (path1, path2, initialCfg = {}) => {
|
|
|
4257
4235
|
}
|
|
4258
4236
|
return [equalP1, equalP2];
|
|
4259
4237
|
};
|
|
4260
|
-
|
|
4261
|
-
//#region src/intersect/isPointInsideBBox.ts
|
|
4238
|
+
// src/intersect/isPointInsideBBox.ts
|
|
4262
4239
|
/**
|
|
4263
4240
|
* Checks if a point is inside a bounding box.
|
|
4264
4241
|
*
|
|
@@ -4270,8 +4247,7 @@ const isPointInsideBBox = (bbox, [x, y]) => {
|
|
|
4270
4247
|
const [minX, minY, maxX, maxY] = bbox;
|
|
4271
4248
|
return x >= minX && x <= maxX && y >= minY && y <= maxY;
|
|
4272
4249
|
};
|
|
4273
|
-
|
|
4274
|
-
//#region src/intersect/boundingBoxIntersect.ts
|
|
4250
|
+
// src/intersect/boundingBoxIntersect.ts
|
|
4275
4251
|
/**
|
|
4276
4252
|
* Checks if two bounding boxes intersect.
|
|
4277
4253
|
*
|
|
@@ -4284,8 +4260,7 @@ const boundingBoxIntersect = (a, b) => {
|
|
|
4284
4260
|
const [bx1, by1, bx2, by2] = b;
|
|
4285
4261
|
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);
|
|
4286
4262
|
};
|
|
4287
|
-
|
|
4288
|
-
//#region src/morph/createPlaceholder.ts
|
|
4263
|
+
// src/morph/createPlaceholder.ts
|
|
4289
4264
|
/**
|
|
4290
4265
|
* Create a degenerate `PathArray` at a given coordinate
|
|
4291
4266
|
* to serve as a pair for another `PathArray`.
|
|
@@ -4323,8 +4298,7 @@ const createPlaceholder = ([atx, aty]) => {
|
|
|
4323
4298
|
["Z"]
|
|
4324
4299
|
];
|
|
4325
4300
|
};
|
|
4326
|
-
|
|
4327
|
-
//#region src/morph/matchPaths.ts
|
|
4301
|
+
// src/morph/matchPaths.ts
|
|
4328
4302
|
function getBestMatch(target, candidates) {
|
|
4329
4303
|
const targetBBox = target.bbox;
|
|
4330
4304
|
const potentialCandidates = [];
|
|
@@ -4400,8 +4374,7 @@ function matchPaths(fromPaths, toPaths) {
|
|
|
4400
4374
|
}
|
|
4401
4375
|
return pairs;
|
|
4402
4376
|
}
|
|
4403
|
-
|
|
4404
|
-
//#region src/morph/classifyPaths.ts
|
|
4377
|
+
// src/morph/classifyPaths.ts
|
|
4405
4378
|
/**
|
|
4406
4379
|
* Classifies paths into outer (containing) and inner (hole) paths.
|
|
4407
4380
|
*
|
|
@@ -4430,8 +4403,7 @@ const classifyPaths = (paths) => {
|
|
|
4430
4403
|
inners
|
|
4431
4404
|
};
|
|
4432
4405
|
};
|
|
4433
|
-
|
|
4434
|
-
//#region src/morph/equalizePaths.ts
|
|
4406
|
+
// src/morph/equalizePaths.ts
|
|
4435
4407
|
const equalizePathsDefaults = {
|
|
4436
4408
|
mode: "auto",
|
|
4437
4409
|
roundValues: 4,
|
|
@@ -4482,8 +4454,7 @@ const equalizePaths = (pathInput1, pathInput2, initialCfg = {}) => {
|
|
|
4482
4454
|
}
|
|
4483
4455
|
return [equalizedPairs.map((p) => p[0]).flat(), equalizedPairs.map((p) => p[1]).flat()];
|
|
4484
4456
|
};
|
|
4485
|
-
|
|
4486
|
-
//#region src/intersect/interHelper.ts
|
|
4457
|
+
// src/intersect/interHelper.ts
|
|
4487
4458
|
const intersect = (x1, y1, x2, y2, x3, y3, x4, y4) => {
|
|
4488
4459
|
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;
|
|
4489
4460
|
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);
|
|
@@ -4548,8 +4519,7 @@ const interHelper = (bez1, bez2, config) => {
|
|
|
4548
4519
|
}
|
|
4549
4520
|
return res;
|
|
4550
4521
|
};
|
|
4551
|
-
|
|
4552
|
-
//#region src/intersect/pathIntersection.ts
|
|
4522
|
+
// src/intersect/pathIntersection.ts
|
|
4553
4523
|
/**
|
|
4554
4524
|
* Finds intersection points between two paths.
|
|
4555
4525
|
*
|
|
@@ -4655,7 +4625,6 @@ const pathsIntersection = (pathInput1, pathInput2, justCount = true) => {
|
|
|
4655
4625
|
}
|
|
4656
4626
|
return justCount ? countResult : pointsResult;
|
|
4657
4627
|
};
|
|
4658
|
-
//#endregion
|
|
4659
4628
|
export { PathParser, absolutizeSegment, arcToCubic, arcTools, bezierTools, boundingBoxIntersect, cubicTools, DISTANCE_EPSILON as distanceEpsilon, distanceSquareRoot, equalizePaths, equalizeSegments, finalizeSegment, fixPath, getClosestPoint, getDrawDirection, getPathArea, getPathBBox, getPointAtLength, getPropertiesAtLength, getPropertiesAtPoint, getSVGMatrix, getSegmentAtLength, getSegmentOfPoint, getTotalLength, invalidPathValue, isAbsoluteArray, isArcCommand, isClosedPath, isCurveArray, isDigit, isDigitStart, isMoveCommand, isMultiPath, isNormalizedArray, isPathArray, isPathCommand, isPointInStroke, isPointInsideBBox, isPolygonArray, isPolylineArray, isRelativeArray, isSpace, isValidPath, iterate, lineToCubic, lineTools, midPoint, normalizePath, normalizeSegment, optimizePath, paramsCounts, paramsParser, parsePathString, pathToAbsolute, pathToCurve, pathToRelative, pathToString, pathsIntersection, polygonTools, projection2d, quadToCubic, quadTools, relativizeSegment, reverseCurve, reversePath, rotateVector, roundPath, roundSegment, roundTo, scanFlag, scanParam, scanSegment, segmentToCubic, shapeParams, shapeToPath, shapeToPathArray, shortenSegment, skipSpaces, splitCubicSegment, splitPath, transformPath };
|
|
4660
4629
|
|
|
4661
4630
|
//# sourceMappingURL=util.js.map
|