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/AGENTS.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Project Overview
4
4
 
5
- SVGPathCommander v2.3.1 — TypeScript library for manipulating SVG `<path>` `d` attributes. Works in browser and Node.js.
5
+ SVGPathCommander v2.3.2 — TypeScript library for manipulating SVG `<path>` `d` attributes. Works in browser and Node.js.
6
6
 
7
7
  ## Commands
8
8
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.3.2] - 2026-09-02
4
+
5
+ ### Fixed
6
+ - `T`/`t` smooth-quadratic shorthand without a preceding `Q`/`q`/`T`/`t` now correctly uses the current point as control point per the SVG spec ([#64](https://github.com/thednp/svg-path-commander/pull/64), thanks @nattyluke) — `normalizeSegment` (`src/process/normalizeSegment.ts:4`), `getPathBBox` (`src/util/getPathBBox.ts:12`) and `getTotalLength` (`src/util/getTotalLength.ts:12`) previously reflected a `0`-defaulted control point, so a `t` following a non-`Q` command (e.g. Illustrator `c...t` output) produced an inflated control/bbox/length (thanks @nattyluke)
7
+
8
+ ### Changed
9
+ - Updated dev dependencies: `@types/node` `^26.4.1`, `vitest` / `@vitest/*` `^4.1.11`, `happy-dom` `^20.12.2`, `vite` `^8.2.2`
10
+ - Rebuilt `dist` and `docs` bundles
11
+
3
12
  ## [2.3.1] - 2026-08-05
4
13
 
5
14
  ### Changed
package/dist/index.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/index.js CHANGED
@@ -1,11 +1,11 @@
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
  */
6
6
  import CSSMatrix from "@thednp/dommatrix";
7
7
  //#region package.json
8
- var version = "2.3.1";
8
+ var version = "2.3.2";
9
9
  //#endregion
10
10
  //#region src/math/midPoint.ts
11
11
  /**
@@ -1954,8 +1954,8 @@ const normalizeSegment = (segment, params) => {
1954
1954
  y1
1955
1955
  ].concat(absValues);
1956
1956
  } else if (absCommand === "T") {
1957
- const qx = px1 * 2 - (params.qx ? params.qx : 0);
1958
- const qy = py1 * 2 - (params.qy ? params.qy : 0);
1957
+ const qx = params.qx != null ? px1 * 2 - params.qx : px1;
1958
+ const qy = params.qy != null ? py1 * 2 - params.qy : py1;
1959
1959
  params.qx = qx;
1960
1960
  params.qy = qy;
1961
1961
  return [
@@ -2110,8 +2110,8 @@ const getPathBBox = (pathInput) => {
2110
2110
  let paramY1 = 0;
2111
2111
  let paramX2 = 0;
2112
2112
  let paramY2 = 0;
2113
- let paramQX = 0;
2114
- let paramQY = 0;
2113
+ let paramQX = null;
2114
+ let paramQY = null;
2115
2115
  iterate(path, (seg, index, lastX, lastY) => {
2116
2116
  [pathCommand] = seg;
2117
2117
  const commandCode = pathCommand.charCodeAt(0);
@@ -2129,8 +2129,8 @@ const getPathBBox = (pathInput) => {
2129
2129
  ] : absoluteSegment;
2130
2130
  [pathCommand] = normalSegment;
2131
2131
  if (absCommand !== "T" && absCommand !== "Q") {
2132
- paramQX = 0;
2133
- paramQY = 0;
2132
+ paramQX = null;
2133
+ paramQY = null;
2134
2134
  }
2135
2135
  if (pathCommand === "M") {
2136
2136
  [, mx, my] = normalSegment;
@@ -2146,8 +2146,8 @@ const getPathBBox = (pathInput) => {
2146
2146
  [minX, minY, maxX, maxY] = getCubicBBox(lastX, lastY, cp1x, cp1y, normalSegment[1], normalSegment[2], normalSegment[3], normalSegment[4]);
2147
2147
  } else if (pathCommand === "C") [minX, minY, maxX, maxY] = getCubicBBox(lastX, lastY, normalSegment[1], normalSegment[2], normalSegment[3], normalSegment[4], normalSegment[5], normalSegment[6]);
2148
2148
  else if (pathCommand === "T") {
2149
- paramQX = paramX1 * 2 - paramQX;
2150
- paramQY = paramY1 * 2 - paramQY;
2149
+ paramQX = paramQX === null ? lastX : paramX1 * 2 - paramQX;
2150
+ paramQY = paramQY === null ? lastY : paramY1 * 2 - paramQY;
2151
2151
  [minX, minY, maxX, maxY] = getQuadBBox(lastX, lastY, paramQX, paramQY, normalSegment[1], normalSegment[2]);
2152
2152
  } else if (pathCommand === "Q") {
2153
2153
  paramQX = normalSegment[1];
@@ -2211,8 +2211,8 @@ const getTotalLength = (pathInput) => {
2211
2211
  let paramY1 = 0;
2212
2212
  let paramX2 = 0;
2213
2213
  let paramY2 = 0;
2214
- let paramQX = 0;
2215
- let paramQY = 0;
2214
+ let paramQX = null;
2215
+ let paramQY = null;
2216
2216
  let pathCommand = "M";
2217
2217
  let mx = 0;
2218
2218
  let my = 0;
@@ -2232,8 +2232,8 @@ const getTotalLength = (pathInput) => {
2232
2232
  ] : absoluteSegment;
2233
2233
  [pathCommand] = normalSegment;
2234
2234
  if (!"TQ".includes(absCommand)) {
2235
- paramQX = 0;
2236
- paramQY = 0;
2235
+ paramQX = null;
2236
+ paramQY = null;
2237
2237
  }
2238
2238
  if (pathCommand === "M") [, mx, my] = normalSegment;
2239
2239
  else if (pathCommand === "L") totalLength += getLineLength(lastX, lastY, normalSegment[1], normalSegment[2]);
@@ -2244,8 +2244,8 @@ const getTotalLength = (pathInput) => {
2244
2244
  totalLength += getCubicLength(lastX, lastY, cp1x, cp1y, normalSegment[1], normalSegment[2], normalSegment[3], normalSegment[4]);
2245
2245
  } else if (pathCommand === "C") totalLength += getCubicLength(lastX, lastY, normalSegment[1], normalSegment[2], normalSegment[3], normalSegment[4], normalSegment[5], normalSegment[6]);
2246
2246
  else if (pathCommand === "T") {
2247
- paramQX = paramX1 * 2 - paramQX;
2248
- paramQY = paramY1 * 2 - paramQY;
2247
+ paramQX = paramQX === null ? lastX : paramX1 * 2 - paramQX;
2248
+ paramQY = paramQY === null ? lastY : paramY1 * 2 - paramQY;
2249
2249
  totalLength += getQuadLength(lastX, lastY, paramQX, paramQY, normalSegment[1], normalSegment[2]);
2250
2250
  } else if (pathCommand === "Q") {
2251
2251
  paramQX = normalSegment[1];
@@ -3108,7 +3108,7 @@ const isMultiPath = (path) => {
3108
3108
  }
3109
3109
  return false;
3110
3110
  }
3111
- throw new TypeError("SVGPathCommanderError: expected string or PathArray");
3111
+ throw new TypeError(error + ": expected string or PathArray");
3112
3112
  };
3113
3113
  //#endregion
3114
3114
  //#region src/util/isPolylineArray.ts
@@ -4163,7 +4163,7 @@ function getRotations(a) {
4163
4163
  */
4164
4164
  function getRotatedPath(pathA, pathB, computedRotations) {
4165
4165
  const rotations = computedRotations || getRotations(pathA);
4166
- if (pathA.length !== pathB.length) throw new TypeError("SVGPathCommanderError: paths must have the same number of segments after equalization");
4166
+ if (pathA.length !== pathB.length) throw new TypeError(error + ": paths must have the same number of segments after equalization");
4167
4167
  let bestIndex = 0;
4168
4168
  let minDistanceSq = Infinity;
4169
4169
  for (let ri = 0; ri < rotations.length; ri++) {
@@ -4538,13 +4538,15 @@ const interHelper = (bez1, bez2, config) => {
4538
4538
  if (xy[is.x.toFixed(4)] == is.y.toFixed(4)) continue;
4539
4539
  xy[is.x.toFixed(4)] = is.y.toFixed(4);
4540
4540
  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);
4541
- if (t1 >= 0 && t1 <= maxLimit && t2 >= 0 && t2 <= maxLimit) if (justCount) res++;
4542
- else res.push({
4543
- x: is.x,
4544
- y: is.y,
4545
- t1: Math.min(t1, 1),
4546
- t2: Math.min(t2, 1)
4547
- });
4541
+ if (t1 >= 0 && t1 <= maxLimit && t2 >= 0 && t2 <= maxLimit) {
4542
+ if (justCount) res++;
4543
+ else res.push({
4544
+ x: is.x,
4545
+ y: is.y,
4546
+ t1: Math.min(t1, 1),
4547
+ t2: Math.min(t2, 1)
4548
+ });
4549
+ }
4548
4550
  }
4549
4551
  }
4550
4552
  return res;