svg-path-commander 2.3.3 → 2.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,13 +1,12 @@
1
1
  /*!
2
- * SVGPathCommander v2.3.3 (http://thednp.github.io/svg-path-commander)
2
+ * SVGPathCommander v2.3.4 (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
- //#region package.json
8
- var version = "2.3.3";
9
- //#endregion
10
- //#region src/math/midPoint.ts
7
+ // package.json
8
+ var version = "2.3.4";
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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, angle1);
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, angle2);
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, angle4);
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, angle3);
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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 { x1: px1, y1: py1, x2: px2, y2: py2, x, y } = params;
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
- py1
1897
+ y
1929
1898
  ];
1930
1899
  else if (absCommand === "V") return [
1931
1900
  "L",
1932
- px1,
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 x1 = px1 * 2 - px2;
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
- x1,
1954
- y1
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 ? px1 * 2 - params.qx : px1;
1958
- const qy = params.qy != null ? py1 * 2 - params.qy : py1;
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
- //#endregion
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: 0,
1986
- y2: 0,
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
- //#endregion
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
- params.x2 = +result[seglen - 4] || params.x1;
2027
- params.y2 = +result[seglen - 3] || params.y1;
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- params.x2 = +result[seglen - 4] || params.x1;
2291
- params.y2 = +result[seglen - 3] || params.y1;
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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 { x1, y1, x2, y2, x, y } = params;
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
- params.x1 = nx1;
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(x1 * 2 - x2, round) && roundTo(qy, round) === roundTo(y1 * 2 - y2, round)) return [
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
- //#endregion
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
- //#endregion
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,13 +3180,17 @@ 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
- optimParams.x2 = +normalizedSegment[seglen - 4] || optimParams.x1;
3240
- optimParams.y2 = +normalizedSegment[seglen - 3] || optimParams.y1;
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
- //#endregion
3245
- //#region src/process/reversePath.ts
3193
+ // src/process/reversePath.ts
3246
3194
  /**
3247
3195
  * Reverses all segments of a PathArray and returns a new PathArray
3248
3196
  * with absolute values.
@@ -3261,6 +3209,26 @@ const reversePath = (pathInput) => {
3261
3209
  const normalizedPath = normalizePath(absolutePath);
3262
3210
  const pLen = absolutePath.length;
3263
3211
  const isClosed = absolutePath[pLen - 1][0] === "Z";
3212
+ const endPoints = [];
3213
+ let endX = 0;
3214
+ let endY = 0;
3215
+ let subX = 0;
3216
+ let subY = 0;
3217
+ for (const seg of normalizedPath) {
3218
+ if (seg[0] === "M") {
3219
+ subX = +seg[1];
3220
+ subY = +seg[2];
3221
+ endX = subX;
3222
+ endY = subY;
3223
+ } else if (seg[0] === "Z") {
3224
+ endX = subX;
3225
+ endY = subY;
3226
+ } else {
3227
+ endX = +seg[seg.length - 2];
3228
+ endY = +seg[seg.length - 1];
3229
+ }
3230
+ endPoints.push([endX, endY]);
3231
+ }
3264
3232
  const reversedPath = iterate(absolutePath, (segment, i) => {
3265
3233
  const normalizedSegment = normalizedPath[i];
3266
3234
  const prevSeg = i && absolutePath[i - 1];
@@ -3268,7 +3236,7 @@ const reversePath = (pathInput) => {
3268
3236
  const nextSeg = absolutePath[i + 1];
3269
3237
  const nextCommand = nextSeg && nextSeg[0];
3270
3238
  const pathCommand = segment[0];
3271
- const [x, y] = normalizedPath[i ? i - 1 : pLen - 1].slice(-2);
3239
+ const [x, y] = endPoints[i ? i - 1 : pLen - 1];
3272
3240
  let result = segment;
3273
3241
  switch (pathCommand) {
3274
3242
  case "M":
@@ -3309,17 +3277,17 @@ const reversePath = (pathInput) => {
3309
3277
  ];
3310
3278
  break;
3311
3279
  case "S":
3312
- if (prevCommand && "CS".includes(prevCommand) && (!nextSeg || nextCommand !== "S")) result = [
3313
- "C",
3314
- normalizedSegment[3],
3315
- normalizedSegment[4],
3280
+ if (nextSeg && nextCommand === "S") result = [
3281
+ pathCommand,
3316
3282
  normalizedSegment[1],
3317
3283
  normalizedSegment[2],
3318
3284
  x,
3319
3285
  y
3320
3286
  ];
3321
3287
  else result = [
3322
- pathCommand,
3288
+ "C",
3289
+ normalizedSegment[3],
3290
+ normalizedSegment[4],
3323
3291
  normalizedSegment[1],
3324
3292
  normalizedSegment[2],
3325
3293
  x,
@@ -3373,8 +3341,7 @@ const reversePath = (pathInput) => {
3373
3341
  });
3374
3342
  return isClosed ? reversedPath.reverse() : [reversedPath[0]].concat(reversedPath.slice(1).reverse());
3375
3343
  };
3376
- //#endregion
3377
- //#region src/process/splitPath.ts
3344
+ // src/process/splitPath.ts
3378
3345
  /**
3379
3346
  * Split a path string or PathArray into an array of sub-paths.
3380
3347
  *
@@ -3440,8 +3407,7 @@ const splitPath = (pathInput) => {
3440
3407
  });
3441
3408
  return composite;
3442
3409
  };
3443
- //#endregion
3444
- //#region src/process/getSVGMatrix.ts
3410
+ // src/process/getSVGMatrix.ts
3445
3411
  /**
3446
3412
  * Returns a transformation matrix to apply to `<path>` elements.
3447
3413
  *
@@ -3474,8 +3440,7 @@ const getSVGMatrix = (transform) => {
3474
3440
  }
3475
3441
  return matrix;
3476
3442
  };
3477
- //#endregion
3478
- //#region src/process/projection2d.ts
3443
+ // src/process/projection2d.ts
3479
3444
  /**
3480
3445
  * Transforms a specified point using a matrix, returning a new
3481
3446
  * Tuple *Object* comprising of the transformed point.
@@ -3531,8 +3496,7 @@ const projection2d = (m, point2D, origin) => {
3531
3496
  const relativePositionZ = z - originZ;
3532
3497
  return [relativePositionX * (Math.abs(originZ) / Math.abs(relativePositionZ) || 1) + originX, relativePositionY * (Math.abs(originZ) / Math.abs(relativePositionZ) || 1) + originY];
3533
3498
  };
3534
- //#endregion
3535
- //#region src/process/transformPath.ts
3499
+ // src/process/transformPath.ts
3536
3500
  /**
3537
3501
  * Applies a 2D transformation to a `PathArray` in a single pass, without
3538
3502
  * absolutizing or copying each segment, returning a new absolute `PathArray`.
@@ -3756,8 +3720,7 @@ const transformPath = (pathInput, transform) => {
3756
3720
  return result;
3757
3721
  });
3758
3722
  };
3759
- //#endregion
3760
- //#region src/process/reverseCurve.ts
3723
+ // src/process/reverseCurve.ts
3761
3724
  /**
3762
3725
  * Reverses all segments of a `pathArray`
3763
3726
  * which consists of only C (cubic-bezier) path commands.
@@ -3769,8 +3732,7 @@ const reverseCurve = (path) => {
3769
3732
  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
3733
  return [["M"].concat(rotatedCurve[0].slice(0, 2))].concat(rotatedCurve.map((x) => ["C"].concat(x.slice(2))));
3771
3734
  };
3772
- //#endregion
3773
- //#region src/process/roundPath.ts
3735
+ // src/process/roundPath.ts
3774
3736
  /**
3775
3737
  * Rounds the values of a `pathArray` instance to
3776
3738
  * a specified amount of decimals and returns it.
@@ -3787,8 +3749,7 @@ const roundPath = (path, roundOption) => {
3787
3749
  return roundSegment(segment, round);
3788
3750
  });
3789
3751
  };
3790
- //#endregion
3791
- //#region src/morph/fixPath.ts
3752
+ // src/morph/fixPath.ts
3792
3753
  /**
3793
3754
  * Checks a `PathArray` for an unnecessary `Z` segment
3794
3755
  * and removes it. The `PathArray` is modified in place.
@@ -3814,8 +3775,7 @@ const fixPath = (pathInput) => {
3814
3775
  if (mx === x && my === y) pathArray.splice(length - 1, 1);
3815
3776
  }
3816
3777
  };
3817
- //#endregion
3818
- //#region src/morph/splitCubicSegment.ts
3778
+ // src/morph/splitCubicSegment.ts
3819
3779
  /**
3820
3780
  * Split a cubic Bézier into two cubics at parameter t [0–1].
3821
3781
  *
@@ -3857,8 +3817,7 @@ function splitCubicSegment(x1, y1, x2, y2, x3, y3, x4, y4, t) {
3857
3817
  y4
3858
3818
  ]];
3859
3819
  }
3860
- //#endregion
3861
- //#region src/morph/pathToPolyline.ts
3820
+ // src/morph/pathToPolyline.ts
3862
3821
  /**
3863
3822
  * Converts any `PolyLineArray`/`PolygonArray` path (closed or open) to an explicit polyline (M + L*).
3864
3823
  * If the path is closed (has Z), the Z is replaced with an explicit L back to the initial M point.
@@ -3884,8 +3843,7 @@ const pathToPolyline = (path) => {
3884
3843
  }
3885
3844
  return result;
3886
3845
  };
3887
- //#endregion
3888
- //#region src/morph/splitLineToCount.ts
3846
+ // src/morph/splitLineToCount.ts
3889
3847
  /**
3890
3848
  * Split a line segment into `count` smaller segments of equal length
3891
3849
  * using the same repeated front-cutting strategy as splitCubicToCount.
@@ -3928,8 +3886,7 @@ function splitLineToCount(x1, y1, x2, y2, count) {
3928
3886
  }
3929
3887
  return result;
3930
3888
  }
3931
- //#endregion
3932
- //#region src/morph/getPathSplits.ts
3889
+ // src/morph/getPathSplits.ts
3933
3890
  /**
3934
3891
  * Determine the right amount of splits for each segment in a given PathArray
3935
3892
  * and for a target total amount of sub-segments.
@@ -3994,8 +3951,7 @@ function getPathSplits(path, target) {
3994
3951
  }
3995
3952
  return splits;
3996
3953
  }
3997
- //#endregion
3998
- //#region src/morph/splitLinePathToCount.ts
3954
+ // src/morph/splitLinePathToCount.ts
3999
3955
  /**
4000
3956
  * Splits a PolylineArray so that it has exactly `target` line segments.
4001
3957
  *
@@ -4031,8 +3987,7 @@ function splitLinePathToCount(path, target) {
4031
3987
  if (newPath.length !== target) console.warn(`${error}: requested ${target} segments, got ${newPath.length}. Adjusted on last segment.`);
4032
3988
  return newPath;
4033
3989
  }
4034
- //#endregion
4035
- //#region src/morph/splitCubicToCount.ts
3990
+ // src/morph/splitCubicToCount.ts
4036
3991
  /**
4037
3992
  * Split a cubic Bézier into `count` segments of roughly equal parameter length.
4038
3993
  * Does NOT mutate input parameters.
@@ -4078,8 +4033,7 @@ function splitCubicToCount(x1, y1, x2, y2, x3, y3, x4, y4, count) {
4078
4033
  }
4079
4034
  return result;
4080
4035
  }
4081
- //#endregion
4082
- //#region src/morph/splitCurvePathToCount.ts
4036
+ // src/morph/splitCurvePathToCount.ts
4083
4037
  /**
4084
4038
  * Splits a CurveArray so that it has exactly `target` cubic segments.
4085
4039
  *
@@ -4120,8 +4074,7 @@ function splitCurvePathToCount(path, target) {
4120
4074
  if (newPath.length !== target) console.warn(`${error}: requested ${target} segments, got ${newPath.length}.`);
4121
4075
  return newPath;
4122
4076
  }
4123
- //#endregion
4124
- //#region src/morph/getRotatedPath.ts
4077
+ // src/morph/getRotatedPath.ts
4125
4078
  /**
4126
4079
  * Returns all possible rotations of a path (line or curve) by shifting the start point.
4127
4080
  * Each rotation is a new PathArray starting at a different original segment.
@@ -4186,8 +4139,7 @@ function getRotatedPath(pathA, pathB, computedRotations) {
4186
4139
  }
4187
4140
  return rotations[bestIndex];
4188
4141
  }
4189
- //#endregion
4190
- //#region src/morph/equalizeSegments.ts
4142
+ // src/morph/equalizeSegments.ts
4191
4143
  const equalizeSegmentsDefaults = {
4192
4144
  mode: "auto",
4193
4145
  sampleSize: 10,
@@ -4260,8 +4212,7 @@ const equalizeSegments = (path1, path2, initialCfg = {}) => {
4260
4212
  }
4261
4213
  return [equalP1, equalP2];
4262
4214
  };
4263
- //#endregion
4264
- //#region src/intersect/isPointInsideBBox.ts
4215
+ // src/intersect/isPointInsideBBox.ts
4265
4216
  /**
4266
4217
  * Checks if a point is inside a bounding box.
4267
4218
  *
@@ -4273,8 +4224,7 @@ const isPointInsideBBox = (bbox, [x, y]) => {
4273
4224
  const [minX, minY, maxX, maxY] = bbox;
4274
4225
  return x >= minX && x <= maxX && y >= minY && y <= maxY;
4275
4226
  };
4276
- //#endregion
4277
- //#region src/intersect/boundingBoxIntersect.ts
4227
+ // src/intersect/boundingBoxIntersect.ts
4278
4228
  /**
4279
4229
  * Checks if two bounding boxes intersect.
4280
4230
  *
@@ -4287,8 +4237,7 @@ const boundingBoxIntersect = (a, b) => {
4287
4237
  const [bx1, by1, bx2, by2] = b;
4288
4238
  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
4239
  };
4290
- //#endregion
4291
- //#region src/morph/createPlaceholder.ts
4240
+ // src/morph/createPlaceholder.ts
4292
4241
  /**
4293
4242
  * Create a degenerate `PathArray` at a given coordinate
4294
4243
  * to serve as a pair for another `PathArray`.
@@ -4326,8 +4275,7 @@ const createPlaceholder = ([atx, aty]) => {
4326
4275
  ["Z"]
4327
4276
  ];
4328
4277
  };
4329
- //#endregion
4330
- //#region src/morph/matchPaths.ts
4278
+ // src/morph/matchPaths.ts
4331
4279
  function getBestMatch(target, candidates) {
4332
4280
  const targetBBox = target.bbox;
4333
4281
  const potentialCandidates = [];
@@ -4403,8 +4351,7 @@ function matchPaths(fromPaths, toPaths) {
4403
4351
  }
4404
4352
  return pairs;
4405
4353
  }
4406
- //#endregion
4407
- //#region src/morph/classifyPaths.ts
4354
+ // src/morph/classifyPaths.ts
4408
4355
  /**
4409
4356
  * Classifies paths into outer (containing) and inner (hole) paths.
4410
4357
  *
@@ -4433,8 +4380,7 @@ const classifyPaths = (paths) => {
4433
4380
  inners
4434
4381
  };
4435
4382
  };
4436
- //#endregion
4437
- //#region src/morph/equalizePaths.ts
4383
+ // src/morph/equalizePaths.ts
4438
4384
  const equalizePathsDefaults = {
4439
4385
  mode: "auto",
4440
4386
  roundValues: 4,
@@ -4485,8 +4431,7 @@ const equalizePaths = (pathInput1, pathInput2, initialCfg = {}) => {
4485
4431
  }
4486
4432
  return [equalizedPairs.map((p) => p[0]).flat(), equalizedPairs.map((p) => p[1]).flat()];
4487
4433
  };
4488
- //#endregion
4489
- //#region src/intersect/interHelper.ts
4434
+ // src/intersect/interHelper.ts
4490
4435
  const intersect = (x1, y1, x2, y2, x3, y3, x4, y4) => {
4491
4436
  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
4437
  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 +4496,7 @@ const interHelper = (bez1, bez2, config) => {
4551
4496
  }
4552
4497
  return res;
4553
4498
  };
4554
- //#endregion
4555
- //#region src/intersect/pathIntersection.ts
4499
+ // src/intersect/pathIntersection.ts
4556
4500
  /**
4557
4501
  * Finds intersection points between two paths.
4558
4502
  *
@@ -4658,8 +4602,7 @@ const pathsIntersection = (pathInput1, pathInput2, justCount = true) => {
4658
4602
  }
4659
4603
  return justCount ? countResult : pointsResult;
4660
4604
  };
4661
- //#endregion
4662
- //#region src/main.ts
4605
+ // src/main.ts
4663
4606
  /**
4664
4607
  * Creates a new SVGPathCommander instance with the following properties:
4665
4608
  * * segments: `pathArray`
@@ -5150,10 +5093,8 @@ var SVGPathCommander = class {
5150
5093
  /** The library version. */
5151
5094
  static version = version;
5152
5095
  };
5153
- //#endregion
5154
- //#region src/index.ts
5096
+ // src/index.ts
5155
5097
  var src_default = SVGPathCommander;
5156
- //#endregion
5157
5098
  export { SVGPathCommander, src_default as default };
5158
5099
 
5159
5100
  //# sourceMappingURL=index.js.map