svg-path-commander 2.1.10 → 2.2.0
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 +106 -0
- package/CHANGELOG.md +25 -0
- package/README.md +45 -3
- package/dist/index.d.ts +733 -0
- package/dist/index.js +4674 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +3 -0
- package/dist/index.min.js.map +1 -0
- package/dist/util.d.ts +1261 -0
- package/dist/util.js +4277 -0
- package/dist/util.js.map +1 -0
- package/package.json +29 -26
- package/tsdown.config.ts +75 -0
- package/dist/svg-path-commander.cjs +0 -2
- package/dist/svg-path-commander.cjs.map +0 -1
- package/dist/svg-path-commander.d.cts +0 -1347
- package/dist/svg-path-commander.d.ts +0 -1347
- package/dist/svg-path-commander.js +0 -2
- package/dist/svg-path-commander.js.map +0 -1
- package/dist/svg-path-commander.mjs +0 -2
- package/dist/svg-path-commander.mjs.map +0 -1
package/AGENTS.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# AGENTS.md — SVGPathCommander
|
|
2
|
+
|
|
3
|
+
## Project Overview
|
|
4
|
+
|
|
5
|
+
SVGPathCommander v2.2.0 — TypeScript library for manipulating SVG `<path>` `d` attributes. Works in browser and Node.js.
|
|
6
|
+
|
|
7
|
+
## Commands
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm install # Install dependencies
|
|
11
|
+
pnpm dev # Serve docs on localhost:3000
|
|
12
|
+
pnpm test # Run all tests (vitest + happy-dom)
|
|
13
|
+
pnpm test-ui # Run tests with UI
|
|
14
|
+
pnpm test -- -t "Test name" # Run a single test by name
|
|
15
|
+
pnpm test -- class.test.ts # Run a single test file
|
|
16
|
+
pnpm lint # Deno lint + tsc type check
|
|
17
|
+
pnpm lint:ts # Deno lint only
|
|
18
|
+
pnpm fix:ts # Deno lint --fix
|
|
19
|
+
pnpm format # Deno format
|
|
20
|
+
pnpm build # Build with tsdown
|
|
21
|
+
pnpm check:ts # tsc --noEmit (type check only)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Tech Stack
|
|
25
|
+
|
|
26
|
+
- **Language:** TypeScript (strict, ES2020 target, `allowImportingTsExtensions`)
|
|
27
|
+
- **Package manager:** pnpm (v10.33.0)
|
|
28
|
+
- **Build:** tsdown (ESM + UMD outputs)
|
|
29
|
+
- **Test:** Vitest + happy-dom (Istanbul coverage)
|
|
30
|
+
- **Lint/Format:** Deno (`deno lint`, `deno fmt`)
|
|
31
|
+
- **Dependency:** `@thednp/dommatrix` (DOMMatrix shim)
|
|
32
|
+
|
|
33
|
+
## Source Structure (`src/`)
|
|
34
|
+
|
|
35
|
+
| Directory | Purpose |
|
|
36
|
+
|---|---|
|
|
37
|
+
| `index.ts` | Main entry — exports SVGPathCommander class + all types |
|
|
38
|
+
| `main.ts` | SVGPathCommander class (core, chainable instance methods) |
|
|
39
|
+
| `types.ts` | TypeScript type definitions (PathCommand, PathSegment, PathArray, etc.) |
|
|
40
|
+
| `interface.ts` | Interfaces (Options, TransformObject, PathBBox, shape attrs) |
|
|
41
|
+
| `util.ts` | Re-export of all static methods (tree-shakeable entry) |
|
|
42
|
+
| `convert/` | Path format conversion (absolute, relative, curve, string) |
|
|
43
|
+
| `parser/` | SVG path string tokenizer/scanner |
|
|
44
|
+
| `process/` | Manipulation algorithms (normalize, optimize, reverse, transform, etc.) |
|
|
45
|
+
| `math/` | Low-level math (bezier, cubic, quad, line, arc, polygon tools) |
|
|
46
|
+
| `morph/` | Path morphing (equalize, split, sample, classify, match) |
|
|
47
|
+
| `util/` | Query helpers (bbox, length, point-at-length, intersection, etc.) |
|
|
48
|
+
| `options/` | Default configuration |
|
|
49
|
+
|
|
50
|
+
## Code Conventions
|
|
51
|
+
|
|
52
|
+
### Imports
|
|
53
|
+
- Use `.ts` extension on all imports: `import { foo } from "./bar.ts"`
|
|
54
|
+
- Path alias `~/*` maps to `src/` (e.g., `import SVGPathCommander from '~/index'`)
|
|
55
|
+
- Group imports: external libs → internal modules → types
|
|
56
|
+
- Use `import type` for type-only imports
|
|
57
|
+
|
|
58
|
+
### Formatting & Linting
|
|
59
|
+
- **No comments** unless explicitly asked
|
|
60
|
+
- Run `pnpm format` then `pnpm lint:ts` before committing
|
|
61
|
+
- Deno formatter and linter enforced (`deno fmt`, `deno lint`)
|
|
62
|
+
|
|
63
|
+
### TypeScript
|
|
64
|
+
- Strict mode enabled — no `any`, no implicit `any`
|
|
65
|
+
- `noUnusedLocals` and `noUnusedParameters` enforced
|
|
66
|
+
- `noImplicitReturns` enforced
|
|
67
|
+
- `allowImportingTsExtensions` — always include `.ts` in imports
|
|
68
|
+
- Use `type` aliases for unions, `interface` for object shapes
|
|
69
|
+
|
|
70
|
+
### Naming Conventions
|
|
71
|
+
- **Classes:** PascalCase (`SVGPathCommander`, `PathParser`)
|
|
72
|
+
- **Functions/Methods:** camelCase (`parsePathString`, `normalizePath`)
|
|
73
|
+
- **Types:** PascalCase ending in semantic suffix (`PathArray`, `NormalSegment`, `IteratorCallback`)
|
|
74
|
+
- **Command types:** Suffix with `Command`/`Segment` (`AbsoluteCommand`, `MSegment`)
|
|
75
|
+
- **Constants:** camelCase for module-level constants (`defaultOptions`, `distanceEpsilon`)
|
|
76
|
+
- **Test descriptions:** Start with `Test` (`Test init with no parameter`)
|
|
77
|
+
|
|
78
|
+
### Error Handling
|
|
79
|
+
- Throw `TypeError` with descriptive message for invalid inputs
|
|
80
|
+
- Use the shared `error` prefix from `~/util/error.ts`
|
|
81
|
+
- Validate inputs early, fail fast with clear messages
|
|
82
|
+
- Static methods return safe defaults for empty/invalid input (e.g., `getPathBBox('')`)
|
|
83
|
+
|
|
84
|
+
### Class Design
|
|
85
|
+
- Instance methods are chainable — always `return this`
|
|
86
|
+
- Expose functionality as both instance methods and static methods
|
|
87
|
+
- Use getters for computed properties (`get bbox()`, `get length()`)
|
|
88
|
+
- Instance options validated in constructor with fallback to `defaultOptions`
|
|
89
|
+
|
|
90
|
+
### Testing
|
|
91
|
+
- Tests run with happy-dom (headless browser simulation)
|
|
92
|
+
- Fixtures in `test/fixtures/`
|
|
93
|
+
- Two test files: `test/class.test.ts` (instance API), `test/static.test.ts` (static methods)
|
|
94
|
+
- Tests render actual SVG and verify `d` attribute output
|
|
95
|
+
- Use `vi.waitFor()` for async DOM queries (timeout: 200ms)
|
|
96
|
+
- Use `expect().to.deep.equal()` for object comparison, `expect().to.equal()` for primitives
|
|
97
|
+
- Coverage provider: Istanbul
|
|
98
|
+
|
|
99
|
+
## Build Outputs
|
|
100
|
+
|
|
101
|
+
| File | Description |
|
|
102
|
+
|---|---|
|
|
103
|
+
| `dist/index.min.js` | UMD bundle (minified, browser-ready, includes dommatrix) |
|
|
104
|
+
| `dist/index.js` | ESM bundle (tree-shakeable, neutral platform) |
|
|
105
|
+
| `dist/util.js` | Static methods only (tree-shakeable) |
|
|
106
|
+
| `dist/index.d.ts` | Type declarations |
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [2.2.0] - 2026-04-06
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- **Path intersection** — `pathsIntersection()`, `boundingBoxIntersect()`, `isPointInsideBBox()`
|
|
7
|
+
- **Path equalization** — `equalizePaths()`, `equalizeSegments()` for matching segment counts
|
|
8
|
+
- Full JSDoc coverage with `@param`, `@returns`, `@example` tags
|
|
9
|
+
- New demo page for path morphing
|
|
10
|
+
- `polyonArea` utility
|
|
11
|
+
- `isMultiPath()`, `isClosedPath()`, `isPolygonArray()` and `isPolylineArray` utilities
|
|
12
|
+
- CHANGELOG.md and AGENTS.md
|
|
13
|
+
|
|
14
|
+
### Removed
|
|
15
|
+
- badge workflow and script in package.json
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
- **pathToCurve** inconsistencies
|
|
19
|
+
- reworked all exports as named exports
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- Added a separate export for utilities in `svg-path-commander/util`
|
|
23
|
+
- Migrated test runner from Playwright to happy-dom
|
|
24
|
+
- updated tests
|
|
25
|
+
- tsdown bundler
|
package/README.md
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
# SVGPathCommander
|
|
2
|
+
|
|
2
3
|
[](https://coveralls.io/github/thednp/svg-path-commander)
|
|
3
4
|
[](https://github.com/thednp/svg-path-commander/actions/workflows/ci.yml)
|
|
4
5
|
[](https://www.npmjs.com/package/svg-path-commander)
|
|
5
6
|
[](http://npm-stat.com/charts.html?svg-path-commander)
|
|
6
7
|
[](https://www.jsdelivr.com/package/npm/svg-path-commander)
|
|
7
|
-
|
|
8
|
-
[](https://vitest.dev/)
|
|
9
|
-
[](https://vitejs.dev/)
|
|
8
|
+
|
|
10
9
|
|
|
11
10
|

|
|
12
11
|
|
|
@@ -40,10 +39,17 @@ This library is available on [CDN](https://www.jsdelivr.com/package/npm/svg-path
|
|
|
40
39
|
|
|
41
40
|
```
|
|
42
41
|
npm install svg-path-commander
|
|
42
|
+
# or pnpm/bun/deno add svg-path-commander
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
# CDN
|
|
47
|
+
Version 2.2.0+
|
|
48
|
+
```html
|
|
49
|
+
<script src="https://cdn.jsdelivr.net/npm/svg-path-commander/dist/index.min.js">
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Versions before 2.2.0
|
|
47
53
|
```html
|
|
48
54
|
<script src="https://cdn.jsdelivr.net/npm/svg-path-commander/dist/svg-path-commander.js">
|
|
49
55
|
```
|
|
@@ -230,6 +236,42 @@ const myPathBBox = SVGPathCommander.getPathBBox('M0 0L50 0L25 50z');
|
|
|
230
236
|
// result => {width: 50, height: 50, x: 0, y: 0, x2: 50, y2: 50, cx: 25, cy: 25, cz: 75}
|
|
231
237
|
```
|
|
232
238
|
|
|
239
|
+
Find intersection points between two paths:
|
|
240
|
+
```js
|
|
241
|
+
const count = SVGPathCommander.pathsIntersection(
|
|
242
|
+
'M0 50C0 0,100 0,100 50',
|
|
243
|
+
'M50 0C100 0,100 100,50 100',
|
|
244
|
+
true
|
|
245
|
+
);
|
|
246
|
+
// result => 1
|
|
247
|
+
|
|
248
|
+
const points = SVGPathCommander.pathsIntersection(
|
|
249
|
+
'M0 50C0 0,100 0,100 50',
|
|
250
|
+
'M50 0C100 0,100 100,50 100',
|
|
251
|
+
false
|
|
252
|
+
);
|
|
253
|
+
// result => [{ x: 50, y: 25, t1: 0.5, t2: 0.5 }]
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Equalize two paths for morphing (single subpath):
|
|
257
|
+
```js
|
|
258
|
+
const [eq1, eq2] = SVGPathCommander.equalizeSegments(
|
|
259
|
+
'M0 0L100 0L50 100Z',
|
|
260
|
+
'M0 0L100 0L100 100L0 100Z'
|
|
261
|
+
);
|
|
262
|
+
// eq1.length === eq2.length — ready for morphing
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Equalize two paths for morphing (single or multi subpath):
|
|
266
|
+
```js
|
|
267
|
+
const [eq1, eq2] = SVGPathCommander.equalizePaths(
|
|
268
|
+
'M0 0L100 0L50 100Z',
|
|
269
|
+
'M0 0L100 0L100 100L0 100Z',
|
|
270
|
+
{ close: true }
|
|
271
|
+
);
|
|
272
|
+
// Both paths now have the same number of segments
|
|
273
|
+
```
|
|
274
|
+
|
|
233
275
|
# WIKI
|
|
234
276
|
For developer guidelines, and a complete list of static methods, head over to the [wiki pages](https://github.com/thednp/svg-path-commander/wiki).
|
|
235
277
|
|