svg-path-commander 2.3.0 → 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 +2 -2
- package/CHANGELOG.md +15 -0
- package/README.md +12 -12
- package/dist/index.d.ts +1 -1
- package/dist/index.js +27 -25
- 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 +1 -1
- package/dist/util.js +26 -24
- package/dist/util.js.map +1 -1
- package/package.json +10 -10
package/AGENTS.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Project Overview
|
|
4
4
|
|
|
5
|
-
SVGPathCommander v2.
|
|
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
|
|
|
@@ -40,7 +40,7 @@ deno publish # JSR dry run: deno publish --dry-run --allow-dirty
|
|
|
40
40
|
- **Test:** Vitest + Istanbul coverage (`test/class.test.ts`, `test/static.test.ts`)
|
|
41
41
|
- **Lint/Format:** Deno (`deno lint`, `deno fmt`)
|
|
42
42
|
- **JSR:** `deno.json` publishes as `@thednp/svg-path-commander` — `deno check src`, `deno lint src` and `deno publish --dry-run --allow-dirty` must all pass
|
|
43
|
-
- **Dependency:** `@thednp/dommatrix` (DOMMatrix shim)
|
|
43
|
+
- **Dependency:** `@thednp/dommatrix` `^3.1.1` (DOMMatrix shim)
|
|
44
44
|
|
|
45
45
|
## Source Structure (`src/`)
|
|
46
46
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
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
|
+
|
|
12
|
+
## [2.3.1] - 2026-08-05
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
- Updated `@thednp/dommatrix` to `^3.1.1` — the 3.1.x line carries the shim's matrix-math rework (specialized `translate` / `scale` / `skew` / `multiply` and constructor fast paths), which directly accelerates the 3D transform path through `getSVGMatrix()` and `projection2d()`; 3.1.1 makes `setMatrixValue()` mutate the instance in place and return `this`, matching native `DOMMatrix` (SVGPathCommander does not use `setMatrixValue()`, so output is byte-identical and the 2D single-pass fast path is untouched)
|
|
16
|
+
- Rebuilt `dist` and `docs` bundles
|
|
17
|
+
|
|
3
18
|
## [2.3.0] - 2026-08-04
|
|
4
19
|
|
|
5
20
|
### Added
|
package/README.md
CHANGED
|
@@ -46,23 +46,23 @@ A comparison of **SVGPathCommander** with the [SvgPath](https://github.com/fonte
|
|
|
46
46
|
|
|
47
47
|
| Operation | SVGPathCommander (static) | svgpath | vs svgpath |
|
|
48
48
|
| --- | --- | --- | --- |
|
|
49
|
-
| parse | **7.
|
|
50
|
-
| bbox | **5.
|
|
51
|
-
| transform2d | 1.7 / 1 | 1.
|
|
52
|
-
| transform3d | **14.
|
|
53
|
-
| string |
|
|
49
|
+
| parse | **7.4 / 7** | 9.7 / 9 | **0.8x** |
|
|
50
|
+
| bbox | **5.2 / 4** | 6.8 / 6 | **0.8x** |
|
|
51
|
+
| transform2d | 1.7 / 1 | 1.2 / 1 | 1.4x |
|
|
52
|
+
| transform3d | **14.3 / 11** | n/a | n/a |
|
|
53
|
+
| string | 6.2 / 5 | 5 / 5 | 1.2x |
|
|
54
54
|
|
|
55
55
|
## Instance methods
|
|
56
56
|
|
|
57
57
|
| Operation | SVGPathCommander (instance) | svgpath | vs svgpath |
|
|
58
58
|
| --- | --- | --- | --- |
|
|
59
|
-
| parse | **7 /
|
|
60
|
-
| bbox | **5
|
|
61
|
-
| transform2d |
|
|
62
|
-
| transform3d | **8.
|
|
63
|
-
| string |
|
|
59
|
+
| parse | **7.3 / 7** | 9.7 / 9 | **0.8x** |
|
|
60
|
+
| bbox | **5 / 4** | 6.8 / 6 | **0.7x** |
|
|
61
|
+
| transform2d | 1.3 / 0 | 1.2 / 1 | 1.1x |
|
|
62
|
+
| transform3d | **8.4 / 7** | n/a | n/a |
|
|
63
|
+
| string | 5.9 / 5 | 5 / 5 | 1.2x |
|
|
64
64
|
|
|
65
|
-
Last benchmark run on `2026-08-
|
|
65
|
+
Last benchmark run on `2026-08-05`. Generated by [`scripts/bench.js`](scripts/bench.js); update with `pnpm bench`.
|
|
66
66
|
<!-- BENCH:end -->
|
|
67
67
|
|
|
68
68
|
|
|
@@ -77,7 +77,7 @@ npm install svg-path-commander
|
|
|
77
77
|
# or npx jsr add @thednp/svg-path-commander
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
In a Deno project, install from [JSR](https://jsr.io/@thednp/svg-path-commander) and import the raw TypeScript source directly:
|
|
81
81
|
|
|
82
82
|
```ts
|
|
83
83
|
import SVGPathCommander from "jsr:@thednp/svg-path-commander";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* SVGPathCommander v2.3.
|
|
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.
|
|
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.
|
|
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 -
|
|
1958
|
-
const qy = py1 * 2 -
|
|
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 =
|
|
2114
|
-
let paramQY =
|
|
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 =
|
|
2133
|
-
paramQY =
|
|
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 =
|
|
2215
|
-
let paramQY =
|
|
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 =
|
|
2236
|
-
paramQY =
|
|
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("
|
|
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("
|
|
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)
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
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;
|