svg-path-commander 2.3.1 → 2.3.2

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/util.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * SVGPathCommander v2.3.1 (http://thednp.github.io/svg-path-commander)
2
+ * SVGPathCommander v2.3.2 (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
  */
package/dist/util.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * SVGPathCommander v2.3.1 (http://thednp.github.io/svg-path-commander)
2
+ * SVGPathCommander v2.3.2 (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
  */
@@ -1940,8 +1940,8 @@ const normalizeSegment = (segment, params) => {
1940
1940
  y1
1941
1941
  ].concat(absValues);
1942
1942
  } else if (absCommand === "T") {
1943
- const qx = px1 * 2 - (params.qx ? params.qx : 0);
1944
- const qy = py1 * 2 - (params.qy ? params.qy : 0);
1943
+ const qx = params.qx != null ? px1 * 2 - params.qx : px1;
1944
+ const qy = params.qy != null ? py1 * 2 - params.qy : py1;
1945
1945
  params.qx = qx;
1946
1946
  params.qy = qy;
1947
1947
  return [
@@ -2107,8 +2107,8 @@ const getPathBBox = (pathInput) => {
2107
2107
  let paramY1 = 0;
2108
2108
  let paramX2 = 0;
2109
2109
  let paramY2 = 0;
2110
- let paramQX = 0;
2111
- let paramQY = 0;
2110
+ let paramQX = null;
2111
+ let paramQY = null;
2112
2112
  iterate(path, (seg, index, lastX, lastY) => {
2113
2113
  [pathCommand] = seg;
2114
2114
  const commandCode = pathCommand.charCodeAt(0);
@@ -2126,8 +2126,8 @@ const getPathBBox = (pathInput) => {
2126
2126
  ] : absoluteSegment;
2127
2127
  [pathCommand] = normalSegment;
2128
2128
  if (absCommand !== "T" && absCommand !== "Q") {
2129
- paramQX = 0;
2130
- paramQY = 0;
2129
+ paramQX = null;
2130
+ paramQY = null;
2131
2131
  }
2132
2132
  if (pathCommand === "M") {
2133
2133
  [, mx, my] = normalSegment;
@@ -2143,8 +2143,8 @@ const getPathBBox = (pathInput) => {
2143
2143
  [minX, minY, maxX, maxY] = getCubicBBox(lastX, lastY, cp1x, cp1y, normalSegment[1], normalSegment[2], normalSegment[3], normalSegment[4]);
2144
2144
  } else if (pathCommand === "C") [minX, minY, maxX, maxY] = getCubicBBox(lastX, lastY, normalSegment[1], normalSegment[2], normalSegment[3], normalSegment[4], normalSegment[5], normalSegment[6]);
2145
2145
  else if (pathCommand === "T") {
2146
- paramQX = paramX1 * 2 - paramQX;
2147
- paramQY = paramY1 * 2 - paramQY;
2146
+ paramQX = paramQX === null ? lastX : paramX1 * 2 - paramQX;
2147
+ paramQY = paramQY === null ? lastY : paramY1 * 2 - paramQY;
2148
2148
  [minX, minY, maxX, maxY] = getQuadBBox(lastX, lastY, paramQX, paramQY, normalSegment[1], normalSegment[2]);
2149
2149
  } else if (pathCommand === "Q") {
2150
2150
  paramQX = normalSegment[1];
@@ -2208,8 +2208,8 @@ const getTotalLength = (pathInput) => {
2208
2208
  let paramY1 = 0;
2209
2209
  let paramX2 = 0;
2210
2210
  let paramY2 = 0;
2211
- let paramQX = 0;
2212
- let paramQY = 0;
2211
+ let paramQX = null;
2212
+ let paramQY = null;
2213
2213
  let pathCommand = "M";
2214
2214
  let mx = 0;
2215
2215
  let my = 0;
@@ -2229,8 +2229,8 @@ const getTotalLength = (pathInput) => {
2229
2229
  ] : absoluteSegment;
2230
2230
  [pathCommand] = normalSegment;
2231
2231
  if (!"TQ".includes(absCommand)) {
2232
- paramQX = 0;
2233
- paramQY = 0;
2232
+ paramQX = null;
2233
+ paramQY = null;
2234
2234
  }
2235
2235
  if (pathCommand === "M") [, mx, my] = normalSegment;
2236
2236
  else if (pathCommand === "L") totalLength += getLineLength(lastX, lastY, normalSegment[1], normalSegment[2]);
@@ -2241,8 +2241,8 @@ const getTotalLength = (pathInput) => {
2241
2241
  totalLength += getCubicLength(lastX, lastY, cp1x, cp1y, normalSegment[1], normalSegment[2], normalSegment[3], normalSegment[4]);
2242
2242
  } else if (pathCommand === "C") totalLength += getCubicLength(lastX, lastY, normalSegment[1], normalSegment[2], normalSegment[3], normalSegment[4], normalSegment[5], normalSegment[6]);
2243
2243
  else if (pathCommand === "T") {
2244
- paramQX = paramX1 * 2 - paramQX;
2245
- paramQY = paramY1 * 2 - paramQY;
2244
+ paramQX = paramQX === null ? lastX : paramX1 * 2 - paramQX;
2245
+ paramQY = paramQY === null ? lastY : paramY1 * 2 - paramQY;
2246
2246
  totalLength += getQuadLength(lastX, lastY, paramQX, paramQY, normalSegment[1], normalSegment[2]);
2247
2247
  } else if (pathCommand === "Q") {
2248
2248
  paramQX = normalSegment[1];
@@ -2714,7 +2714,7 @@ const isMultiPath = (path) => {
2714
2714
  }
2715
2715
  return false;
2716
2716
  }
2717
- throw new TypeError("SVGPathCommanderError: expected string or PathArray");
2717
+ throw new TypeError(error + ": expected string or PathArray");
2718
2718
  };
2719
2719
  //#endregion
2720
2720
  //#region src/util/isClosedPath.ts
@@ -4160,7 +4160,7 @@ function getRotations(a) {
4160
4160
  */
4161
4161
  function getRotatedPath(pathA, pathB, computedRotations) {
4162
4162
  const rotations = computedRotations || getRotations(pathA);
4163
- if (pathA.length !== pathB.length) throw new TypeError("SVGPathCommanderError: paths must have the same number of segments after equalization");
4163
+ if (pathA.length !== pathB.length) throw new TypeError(error + ": paths must have the same number of segments after equalization");
4164
4164
  let bestIndex = 0;
4165
4165
  let minDistanceSq = Infinity;
4166
4166
  for (let ri = 0; ri < rotations.length; ri++) {
@@ -4535,13 +4535,15 @@ const interHelper = (bez1, bez2, config) => {
4535
4535
  if (xy[is.x.toFixed(4)] == is.y.toFixed(4)) continue;
4536
4536
  xy[is.x.toFixed(4)] = is.y.toFixed(4);
4537
4537
  const t1 = di.t + Math.abs((is[ci] - di[ci]) / (di1[ci] - di[ci])) * (di1.t - di.t), t2 = dj.t + Math.abs((is[cj] - dj[cj]) / (dj1[cj] - dj[cj])) * (dj1.t - dj.t);
4538
- if (t1 >= 0 && t1 <= maxLimit && t2 >= 0 && t2 <= maxLimit) if (justCount) res++;
4539
- else res.push({
4540
- x: is.x,
4541
- y: is.y,
4542
- t1: Math.min(t1, 1),
4543
- t2: Math.min(t2, 1)
4544
- });
4538
+ if (t1 >= 0 && t1 <= maxLimit && t2 >= 0 && t2 <= maxLimit) {
4539
+ if (justCount) res++;
4540
+ else res.push({
4541
+ x: is.x,
4542
+ y: is.y,
4543
+ t1: Math.min(t1, 1),
4544
+ t2: Math.min(t2, 1)
4545
+ });
4546
+ }
4545
4547
  }
4546
4548
  }
4547
4549
  return res;