svg-path-commander 2.2.2 → 2.2.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.d.ts CHANGED
@@ -1,278 +1,505 @@
1
1
  /*!
2
- * SVGPathCommander v2.2.2 (http://thednp.github.io/svg-path-commander)
2
+ * SVGPathCommander v2.2.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
7
  //#region src/interface.d.ts
8
+ /** The properties of a path segment found by segment lookup utilities. */
8
9
  type SegmentProperties = {
10
+ /** The path segment. */
9
11
  segment: PathSegment;
12
+ /** The index of the segment in the path. */
10
13
  index: number;
14
+ /** The length of the segment. */
11
15
  length: number;
16
+ /** The distance from the start of the path to the end of the segment. */
12
17
  lengthAtSegment: number;
13
18
  };
19
+ /** The closest point on the path to a given point, with the distance and optional segment. */
14
20
  type PointProperties = {
21
+ /** The closest point on the path to the given point. */
15
22
  closest: {
23
+ /** The X coordinate of the closest point. */
16
24
  x: number;
25
+ /** The Y coordinate of the closest point. */
17
26
  y: number;
18
27
  };
28
+ /** The distance from the given point to the closest point on the path. */
19
29
  distance: number;
30
+ /** The segment which contains the closest point. */
20
31
  segment?: SegmentProperties;
21
32
  };
33
+ /** The attributes of a `<line>` element read by `shapeToPath`. */
22
34
  type LineAttr = {
35
+ /** The element type. */
23
36
  type: "line";
37
+ /** The X coordinate of the start point. */
24
38
  x1: number;
39
+ /** The Y coordinate of the start point. */
25
40
  y1: number;
41
+ /** The X coordinate of the end point. */
26
42
  x2: number;
43
+ /** The Y coordinate of the end point. */
27
44
  y2: number;
28
45
  [key: string]: string | number;
29
46
  };
47
+ /** The attributes of a `<polygon>` or `<polyline>` element read by `shapeToPath`. */
30
48
  type PolyAttr = {
49
+ /** The element type. */
31
50
  type: "polygon" | "polyline";
51
+ /** The points attribute value. */
32
52
  points: string;
33
53
  [key: string]: string | number;
34
54
  };
55
+ /** The attributes of a `<circle>` element read by `shapeToPath`. */
35
56
  type CircleAttr = {
57
+ /** The element type. */
36
58
  type: "circle";
59
+ /** The X coordinate of the center. */
37
60
  cx: number;
61
+ /** The Y coordinate of the center. */
38
62
  cy: number;
63
+ /** The circle radius. */
39
64
  r: number;
40
65
  [key: string]: string | number;
41
66
  };
67
+ /** The attributes of an `<ellipse>` element read by `shapeToPath`. */
42
68
  type EllipseAttr = {
69
+ /** The element type. */
43
70
  type: "ellipse";
71
+ /** The X coordinate of the center. */
44
72
  cx: number;
73
+ /** The Y coordinate of the center. */
45
74
  cy: number;
75
+ /** The X axis radius. */
46
76
  rx: number;
77
+ /** The Y axis radius. */
47
78
  ry?: number;
48
79
  [key: string]: string | number | undefined;
49
80
  };
81
+ /** The attributes of a `<rect>` element read by `shapeToPath`. */
50
82
  type RectAttr = {
83
+ /** The element type. */
51
84
  type: "rect";
85
+ /** The rectangle width. */
52
86
  width: number;
87
+ /** The rectangle height. */
53
88
  height: number;
89
+ /** The X coordinate of the top-left corner. */
54
90
  x: number;
91
+ /** The Y coordinate of the top-left corner. */
55
92
  y: number;
93
+ /** The X axis corner radius. */
56
94
  rx?: number;
95
+ /** The Y axis corner radius. */
57
96
  ry?: number;
58
97
  [key: string]: string | number | undefined;
59
98
  };
99
+ /** The attributes of a `<glyph>` element read by `shapeToPath`. */
60
100
  type GlyphAttr = {
101
+ /** The element type. */
61
102
  type: "glyph";
103
+ /** The path data of the glyph. */
62
104
  d: string;
63
105
  [key: string]: string | number;
64
106
  };
107
+ /** The parameter names read from each SVG shape element by `shapeToPath`. */
65
108
  type ShapeParams = {
109
+ /** The parameter names read from the `<line>` element. */
66
110
  line: ["x1", "y1", "x2", "y2"];
111
+ /** The parameter names read from the `<circle>` element. */
67
112
  circle: ["cx", "cy", "r"];
113
+ /** The parameter names read from the `<ellipse>` element. */
68
114
  ellipse: ["cx", "cy", "rx", "ry"];
115
+ /** The parameter names read from the `<rect>` element. */
69
116
  rect: ["width", "height", "x", "y", "rx", "ry"];
117
+ /** The parameter names read from the `<polygon>` element. */
70
118
  polygon: ["points"];
119
+ /** The parameter names read from the `<polyline>` element. */
71
120
  polyline: ["points"];
121
+ /** The parameter names read from the `<glyph>` element. */
72
122
  glyph: ["d"];
73
123
  };
124
+ /** The bounding box of a path, equivalent to the native `getBBox()` result. */
74
125
  type PathBBox = {
126
+ /** The width of the bounding box. */
75
127
  width: number;
128
+ /** The height of the bounding box. */
76
129
  height: number;
130
+ /** The X coordinate of the top-left corner. */
77
131
  x: number;
132
+ /** The Y coordinate of the top-left corner. */
78
133
  y: number;
134
+ /** The X coordinate of the bottom-right corner. */
79
135
  x2: number;
136
+ /** The Y coordinate of the bottom-right corner. */
80
137
  y2: number;
138
+ /** The X coordinate of the center. */
81
139
  cx: number;
140
+ /** The Y coordinate of the center. */
82
141
  cy: number;
142
+ /** The Z coordinate of the center, used as transform origin for 3D projections. */
83
143
  cz: number;
84
144
  };
145
+ /** The minimum and maximum points of a segment bounding box. */
85
146
  type SegmentLimits = {
147
+ /** The minimum coordinates of the segment. */
86
148
  min: {
149
+ /** The minimum X coordinate. */
87
150
  x: number;
151
+ /** The minimum Y coordinate. */
88
152
  y: number;
89
153
  };
154
+ /** The maximum coordinates of the segment. */
90
155
  max: {
156
+ /** The maximum X coordinate. */
91
157
  x: number;
158
+ /** The maximum Y coordinate. */
92
159
  y: number;
93
160
  };
94
161
  };
162
+ /** The current state tracked by the SVG path string parser. */
95
163
  type ParserParams = {
164
+ /** The X coordinate of the previous moveto point. */
96
165
  mx: number;
166
+ /** The Y coordinate of the previous moveto point. */
97
167
  my: number;
168
+ /** The X coordinate of the previous control point. */
98
169
  x1: number;
170
+ /** The Y coordinate of the previous control point. */
99
171
  y1: number;
172
+ /** The X coordinate of the second control point. */
100
173
  x2: number;
174
+ /** The Y coordinate of the second control point. */
101
175
  y2: number;
176
+ /** The X coordinate of the current point. */
102
177
  x: number;
178
+ /** The Y coordinate of the current point. */
103
179
  y: number;
180
+ /** The X coordinate of the previous quadratic control point. */
104
181
  qx: number | null;
182
+ /** The Y coordinate of the previous quadratic control point. */
105
183
  qy: number | null;
106
184
  };
185
+ /** The result of a length computation factory: length, point and segment limits. */
107
186
  type LengthFactory = {
187
+ /** The total length of the segment. */
108
188
  length: number;
189
+ /** The point on the segment at the given length. */
109
190
  point: {
191
+ /** The X coordinate of the point at the given length. */
110
192
  x: number;
193
+ /** The Y coordinate of the point at the given length. */
111
194
  y: number;
112
195
  };
196
+ /** The minimum coordinates of the segment. */
113
197
  min: {
198
+ /** The minimum X coordinate of the segment. */
114
199
  x: number;
200
+ /** The minimum Y coordinate of the segment. */
115
201
  y: number;
116
202
  };
203
+ /** The maximum coordinates of the segment. */
117
204
  max: {
205
+ /** The maximum X coordinate of the segment. */
118
206
  x: number;
207
+ /** The maximum Y coordinate of the segment. */
119
208
  y: number;
120
209
  };
121
210
  };
211
+ /** The `SVGPathCommander` instance options. */
122
212
  type Options = {
213
+ /** The amount of decimals to round path values to, or "off" to disable rounding. */
123
214
  round: "off" | number;
215
+ /** The transform origin used for path transformations. */
124
216
  origin: number[];
125
217
  };
218
+ /** A path segment and its transformation context (command letter and coordinates). */
126
219
  type PathTransform = {
220
+ /** The current path segment. */
127
221
  s: PathSegment;
222
+ /** The current path command letter. */
128
223
  c: string;
224
+ /** The current X coordinate. */
129
225
  x: number;
226
+ /** The current Y coordinate. */
130
227
  y: number;
131
228
  };
229
+ /** A transform function object with translate, rotate, scale, skew and origin. */
132
230
  type TransformObject = {
231
+ /** A translate value, a number for all axes or an array of values. */
133
232
  translate: number | number[];
233
+ /** A rotate value, a number for all axes or an array of values. */
134
234
  rotate: number | number[];
235
+ /** A scale value, a number for all axes or an array of values. */
135
236
  scale: number | number[];
237
+ /** A skew value, a number for all axes or an array of values. */
136
238
  skew: number | number[];
239
+ /** The transform origin. */
137
240
  origin: number[];
138
241
  };
242
+ /** The keys of a `TransformObject`. */
139
243
  type TransformProps = keyof TransformObject;
244
+ /** The entries of a `TransformObject` (key-value pairs). */
140
245
  type TransformEntries = [TransformProps, TransformObject[TransformProps]][];
141
246
  //#endregion
142
247
  //#region src/types.d.ts
248
+ /** Whitespace character codes recognized by the SVG path string tokenizer. */
143
249
  type SpaceNumber = 0x1680 | 0x180e | 0x2000 | 0x2001 | 0x2002 | 0x2003 | 0x2004 | 0x2005 | 0x2006 | 0x2007 | 0x2008 | 0x2009 | 0x200a | 0x202f | 0x205f | 0x3000 | 0xfeff | 0x0a | 0x0d | 0x2028 | 0x2029 | 0x20 | 0x09 | 0x0b | 0x0c | 0xa0 | 0x1680;
250
+ /** Character codes of all SVG path command letters. */
144
251
  type PathCommandNumber = 0x6d | 0x7a | 0x6c | 0x68 | 0x76 | 0x63 | 0x73 | 0x71 | 0x74 | 0x61;
252
+ /** Character codes of the decimal digits 0-9. */
145
253
  type DigitNumber = 0x30 | 0x31 | 0x32 | 0x33 | 0x34 | 0x35 | 0x36 | 0x37 | 0x38 | 0x39;
254
+ /** The absolute moveto command letter. */
146
255
  type MCommand = "M";
256
+ /** The relative moveto command letter. */
147
257
  type mCommand = "m";
258
+ /** The absolute lineto command letter. */
148
259
  type LCommand = "L";
260
+ /** The relative lineto command letter. */
149
261
  type lCommand = "l";
262
+ /** The absolute vertical lineto command letter. */
150
263
  type VCommand = "V";
264
+ /** The relative vertical lineto command letter. */
151
265
  type vCommand = "v";
266
+ /** The absolute horizontal lineto command letter. */
152
267
  type HCommand = "H";
268
+ /** The relative horizontal lineto command letter. */
153
269
  type hCommand = "h";
270
+ /** The absolute closepath command letter. */
154
271
  type ZCommand = "Z";
272
+ /** The relative closepath command letter. */
155
273
  type zCommand = "z";
274
+ /** The absolute cubic Bezier command letter. */
156
275
  type CCommand = "C";
276
+ /** The relative cubic Bezier command letter. */
157
277
  type cCommand = "c";
278
+ /** The absolute smooth cubic Bezier command letter. */
158
279
  type SCommand = "S";
280
+ /** The relative smooth cubic Bezier command letter. */
159
281
  type sCommand = "s";
282
+ /** The absolute quadratic Bezier command letter. */
160
283
  type QCommand = "Q";
284
+ /** The relative quadratic Bezier command letter. */
161
285
  type qCommand = "q";
286
+ /** The absolute smooth quadratic Bezier command letter. */
162
287
  type TCommand = "T";
288
+ /** The relative smooth quadratic Bezier command letter. */
163
289
  type tCommand = "t";
290
+ /** The absolute elliptical arc command letter. */
164
291
  type ACommand = "A";
292
+ /** The relative elliptical arc command letter. */
165
293
  type aCommand = "a";
294
+ /** The union of all absolute path command letters. */
166
295
  type AbsoluteCommand = MCommand | LCommand | VCommand | HCommand | ZCommand | CCommand | SCommand | QCommand | TCommand | ACommand;
296
+ /** The union of all relative path command letters. */
167
297
  type RelativeCommand = mCommand | lCommand | vCommand | hCommand | zCommand | cCommand | sCommand | qCommand | tCommand | aCommand;
298
+ /** Any SVG path command letter, absolute or relative. */
168
299
  type PathCommand = AbsoluteCommand | RelativeCommand;
300
+ /** The absolute moveto segment tuple `[M, x, y]`. */
169
301
  type MSegment = [MCommand, number, number];
302
+ /** The relative moveto segment tuple `[m, dx, dy]`. */
170
303
  type mSegment = [mCommand, number, number];
304
+ /** The moveto segment, absolute or relative. */
171
305
  type MoveSegment = MSegment | mSegment;
306
+ /** The absolute lineto segment tuple `[L, x, y]`. */
172
307
  type LSegment = [LCommand, number, number];
308
+ /** The relative lineto segment tuple `[l, dx, dy]`. */
173
309
  type lSegment = [lCommand, number, number];
310
+ /** The lineto segment, absolute or relative. */
174
311
  type LineSegment = LSegment | lSegment;
312
+ /** The absolute vertical lineto segment tuple `[V, y]`. */
175
313
  type VSegment = [VCommand, number];
314
+ /** The relative vertical lineto segment tuple `[v, dy]`. */
176
315
  type vSegment = [vCommand, number];
316
+ /** The vertical lineto segment, absolute or relative. */
177
317
  type VertLineSegment = vSegment | VSegment;
318
+ /** The absolute horizontal lineto segment tuple `[H, x]`. */
178
319
  type HSegment = [HCommand, number];
320
+ /** The relative horizontal lineto segment tuple `[h, dx]`. */
179
321
  type hSegment = [hCommand, number];
322
+ /** The horizontal lineto segment, absolute or relative. */
180
323
  type HorLineSegment = HSegment | hSegment;
324
+ /** The absolute closepath segment tuple `[Z]`. */
181
325
  type ZSegment = [ZCommand];
326
+ /** The relative closepath segment tuple `[z]`. */
182
327
  type zSegment = [zCommand];
328
+ /** The closepath segment, absolute or relative. */
183
329
  type CloseSegment = ZSegment | zSegment;
330
+ /** The absolute cubic Bezier segment tuple `[C, x1, y1, x2, y2, x, y]`. */
184
331
  type CSegment = [CCommand, number, number, number, number, number, number];
332
+ /** The relative cubic Bezier segment tuple `[c, dx1, dy1, dx2, dy2, dx, dy]`. */
185
333
  type cSegment = [cCommand, number, number, number, number, number, number];
334
+ /** The cubic Bezier segment, absolute or relative. */
186
335
  type CubicSegment = CSegment | cSegment;
336
+ /** The absolute smooth cubic Bezier segment tuple `[S, x2, y2, x, y]`. */
187
337
  type SSegment = [SCommand, number, number, number, number];
338
+ /** The relative smooth cubic Bezier segment tuple `[s, dx2, dy2, dx, dy]`. */
188
339
  type sSegment = [sCommand, number, number, number, number];
340
+ /** The smooth cubic Bezier segment, absolute or relative. */
189
341
  type ShortCubicSegment = SSegment | sSegment;
342
+ /** The absolute quadratic Bezier segment tuple `[Q, x1, y1, x, y]`. */
190
343
  type QSegment = [QCommand, number, number, number, number];
344
+ /** The relative quadratic Bezier segment tuple `[q, dx1, dy1, dx, dy]`. */
191
345
  type qSegment = [qCommand, number, number, number, number];
346
+ /** The quadratic Bezier segment, absolute or relative. */
192
347
  type QuadSegment = QSegment | qSegment;
348
+ /** The absolute smooth quadratic Bezier segment tuple `[T, x, y]`. */
193
349
  type TSegment = [TCommand, number, number];
350
+ /** The relative smooth quadratic Bezier segment tuple `[t, dx, dy]`. */
194
351
  type tSegment = [tCommand, number, number];
352
+ /** The smooth quadratic Bezier segment, absolute or relative. */
195
353
  type ShortQuadSegment = TSegment | tSegment;
354
+ /** The absolute elliptical arc segment tuple `[A, rx, ry, xAxisRotation, largeArcFlag, sweepFlag, x, y]`. */
196
355
  type ASegment = [ACommand, number, number, number, number, number, number, number];
356
+ /** The relative elliptical arc segment tuple `[a, rx, ry, xAxisRotation, largeArcFlag, sweepFlag, dx, dy]`. */
197
357
  type aSegment = [aCommand, number, number, number, number, number, number, number];
358
+ /** The elliptical arc segment, absolute or relative. */
198
359
  type ArcSegment = ASegment | aSegment;
360
+ /** Any SVG path command segment. */
199
361
  type PathSegment = MoveSegment | LineSegment | VertLineSegment | HorLineSegment | CloseSegment | CubicSegment | ShortCubicSegment | QuadSegment | ShortQuadSegment | ArcSegment;
362
+ /** Any shorthand or single-coordinate path segment. */
200
363
  type ShortSegment = VertLineSegment | HorLineSegment | ShortCubicSegment | ShortQuadSegment | CloseSegment;
364
+ /** Any absolute path command segment. */
201
365
  type AbsoluteSegment = MSegment | LSegment | VSegment | HSegment | CSegment | SSegment | QSegment | TSegment | ASegment | ZSegment;
366
+ /** Any relative path command segment. */
202
367
  type RelativeSegment = mSegment | lSegment | vSegment | hSegment | cSegment | sSegment | qSegment | tSegment | aSegment | zSegment;
368
+ /** The path segments used by the normalized form (no shorthand commands). */
203
369
  type NormalSegment = MSegment | LSegment | CSegment | QSegment | ASegment | ZSegment;
370
+ /** A parsed SVG path string as an array of path segments. */
204
371
  type PathArray = [MSegment | mSegment, ...PathSegment[]];
372
+ /** A `PathArray` with only absolute path segments. */
205
373
  type AbsoluteArray = [MSegment, ...AbsoluteSegment[]];
374
+ /** A `PathArray` with only relative path segments. */
206
375
  type RelativeArray = [MSegment, ...RelativeSegment[]];
376
+ /** A `PathArray` with only normalized segments (no shorthand commands). */
207
377
  type NormalArray = [MSegment, ...NormalSegment[]];
378
+ /** A `PathArray` with only moveto and cubic Bezier segments. */
208
379
  type CurveArray = [MSegment, ...CSegment[]];
380
+ /** A `CurveArray` ending with a closepath segment. */
209
381
  type ClosedCurveArray = [MSegment, ...CSegment[], ZSegment];
382
+ /** A `PathArray` describing a closed polygon (moveto, lineto and closepath). */
210
383
  type PolygonArray = [MSegment, ...LSegment[], ZSegment];
384
+ /** A `PathArray` describing an open polyline (moveto and lineto). */
211
385
  type PolylineArray = [MSegment, ...LSegment[]];
386
+ /** The `PathArray` shapes supported by path morphing. */
212
387
  type MorphPathArray = PolygonArray | PolylineArray | CurveArray | ClosedCurveArray;
388
+ /** The SVG element types that can be converted to a path. */
213
389
  type ShapeTypes = SVGPolylineElement | SVGPolygonElement | SVGLineElement | SVGEllipseElement | SVGCircleElement | SVGRectElement;
390
+ /** The tag names of the SVG elements that can be converted to a path. */
214
391
  type ShapeTags = "line" | "polyline" | "polygon" | "ellipse" | "circle" | "rect" | "glyph";
392
+ /** The shape attributes mapped to each supported SVG element type. */
215
393
  type ShapeOps = LineAttr | PolyAttr | PolyAttr | EllipseAttr | CircleAttr | RectAttr | GlyphAttr;
394
+ /** A `TransformObject` with a required 3D origin. */
216
395
  type TransformObjectValues = Partial<TransformObject> & {
396
+ /** The transform origin. */
217
397
  origin: [number, number, number];
218
398
  };
399
+ /** A 2D point with `x` and `y` coordinates. */
219
400
  type Point = {
401
+ /** The X coordinate. */
220
402
  x: number;
403
+ /** The Y coordinate. */
221
404
  y: number;
222
405
  };
406
+ /** A 2D point as a tuple `[x, y]`. */
223
407
  type PointTuple = [number, number];
408
+ /** A `Point` with a `t` parameter (a point on a curve at ratio `t`). */
224
409
  type DerivedPoint = Point & {
410
+ /** The parameter ratio in `[0-1]`. */
225
411
  t: number;
226
412
  };
413
+ /** The six points of a quadratic Bezier curve (on-curve and off-curve control points). */
227
414
  type QuadPoints = [Point, Point, Point, Point, Point, Point];
415
+ /** The eight points of a cubic Bezier curve (on-curve and off-curve control points). */
228
416
  type CubicPoints = [Point, Point, Point, Point, Point, Point, Point, Point];
417
+ /** The six derived points of a quadratic Bezier curve, each with a `t` parameter. */
229
418
  type DerivedQuadPoints = [DerivedPoint, DerivedPoint, DerivedPoint, DerivedPoint, DerivedPoint, DerivedPoint];
419
+ /** The eight derived points of a cubic Bezier curve, each with a `t` parameter. */
230
420
  type DerivedCubicPoints = [DerivedPoint, DerivedPoint, DerivedPoint, DerivedPoint, DerivedPoint, DerivedPoint, DerivedPoint, DerivedPoint];
421
+ /** The six coordinates of a quadratic Bezier segment `[x1, y1, cx, cy, x, y]`. */
231
422
  type QuadCoordinates = [number, number, number, number, number, number];
423
+ /** The eight coordinates of a cubic Bezier segment. */
232
424
  type CubicCoordinates = [number, number, number, number, number, number, number, number];
425
+ /** The coordinates of an arc segment (the eight numbers after the command letter). */
233
426
  type ArcCoordinates = [number, number, number, number, number, number, number, number, number];
427
+ /** The four coordinates of a line segment `[x1, y1, x2, y2]`. */
234
428
  type LineCoordinates = [number, number, number, number];
429
+ /** A function that derives a point on a curve at a given `t` ratio. */
235
430
  type DeriveCallback = (t: number) => Point;
431
+ /** A callback invoked for each segment while iterating over a `PathArray`. */
236
432
  type IteratorCallback<T extends PathArray, K extends keyof T = number> = (segment: PathSegment & T[K], index: number, lastX: number, lastY: number) => PathSegment | T[K] | false | void | undefined;
433
+ /** The bounding box extremes `[minX, minY, maxX, maxY]`. */
237
434
  type BBoxMaxima = [minX: number, minY: number, maxX: number, maxY: number];
435
+ /** A point on the path at a given length, including the `t` ratio. */
238
436
  type PointAtLength = {
437
+ /** The X coordinate. */
239
438
  x: number;
439
+ /** The Y coordinate. */
240
440
  y: number;
441
+ /** The parameter ratio in `[0-1]`. */
241
442
  t: number;
242
443
  };
444
+ /** An intersection point between two curves, including both `t` ratios. */
243
445
  type IntersectionPoint = {
446
+ /** The X coordinate of the intersection point. */
244
447
  x: number;
448
+ /** The Y coordinate of the intersection point. */
245
449
  y: number;
450
+ /** The parameter ratio of the first curve. */
246
451
  t1: number;
452
+ /** The parameter ratio of the second curve. */
247
453
  t2: number;
248
454
  };
455
+ /** Options for computing intersections between two curves. */
249
456
  interface IntersectionOptions {
457
+ /** Whether to only count the intersections without computing points. */
250
458
  justCount?: boolean;
459
+ /** The epsilon value used for precision. */
251
460
  epsilon?: number;
252
461
  }
462
+ /** Options for equalizing a single path to a given segment count. */
253
463
  interface PathEqualizationOptions {
254
- /** @default "auto" */
464
+ /** The equalization mode. @default "auto" */
255
465
  mode?: "line" | "curve" | "auto";
466
+ /** The number of sample points for the line mode. */
256
467
  sampleSize?: number;
468
+ /** The amount of decimals to round values to. */
257
469
  roundValues?: number;
470
+ /** Whether to close the path before equalization. */
258
471
  close?: boolean;
259
472
  }
473
+ /** Options for equalizing two paths for morphing. */
260
474
  interface EqualizationOptions {
261
- /** @default "auto" */
475
+ /** The equalization mode. @default "auto" */
262
476
  mode?: "curve" | "auto";
477
+ /** The number of sample points for the line mode. */
263
478
  sampleSize?: number;
479
+ /** The amount of decimals to round values to. */
264
480
  roundValues?: number;
481
+ /** Whether to reverse the second path before equalization. */
265
482
  reverse?: boolean;
483
+ /** Whether to close the path before equalization. */
266
484
  close?: boolean;
485
+ /** The target segment count for both paths. */
267
486
  target?: number;
268
487
  }
488
+ /** `EqualizationOptions` without `reverse` and `target`, used for path pairs. */
269
489
  type PathsEqualizationOptions = Omit<EqualizationOptions, "reverse" | "target">;
490
+ /** The geometric features of a path used for matching during morphing. */
270
491
  interface PathFeature {
492
+ /** Whether the path is a polygon. */
271
493
  isPoly: boolean;
494
+ /** The normalized path array. */
272
495
  path: NormalArray;
496
+ /** The number of segments in the path. */
273
497
  size: number;
498
+ /** The absolute area of the path. */
274
499
  area: number;
500
+ /** The signed area of the path, negative for clockwise direction. */
275
501
  signedArea: number;
502
+ /** The bounding box of the path. */
276
503
  bbox: PathBBox;
277
504
  }
278
505
  //#endregion
@@ -1205,7 +1432,7 @@ declare const equalizePaths: (pathInput1: string | PathArray, pathInput2: string
1205
1432
  * pathsIntersection('M0 50C0 0,100 0,100 50', 'M50 0C100 0,100 100,50 100', true)
1206
1433
  * // => 1
1207
1434
  * pathsIntersection('M0 50C0 0,100 0,100 50', 'M50 0C100 0,100 100,50 100', false)
1208
- * // => [{ x: 50, y: 25, t1: 0.5, t2: 0.5 }]
1435
+ * // => [{ x: 80.4136, y: 19.5864, t1: 0.7262, t2: 0.2738 }]
1209
1436
  * ```
1210
1437
  */
1211
1438
  declare const pathsIntersection: <T extends string | PathArray>(pathInput1: T, pathInput2: T, justCount?: boolean) => number | IntersectionPoint[];
@@ -1242,8 +1469,11 @@ declare const isPointInsideBBox: (bbox: BBoxMaxima, [x, y]: PointTuple) => boole
1242
1469
  * @returns a new SVGPathCommander instance
1243
1470
  */
1244
1471
  declare class SVGPathCommander {
1472
+ /** The parsed PathArray stored on the instance. */
1245
1473
  segments: PathArray;
1474
+ /** The rounding option used for the output path string. */
1246
1475
  round: number | "off";
1476
+ /** The transform origin used for path transformations. */
1247
1477
  origin: [number, number, number];
1248
1478
  /**
1249
1479
  * @constructor
@@ -1251,6 +1481,12 @@ declare class SVGPathCommander {
1251
1481
  * @param config instance options
1252
1482
  */
1253
1483
  constructor(pathValue: string, config?: Partial<Options>);
1484
+ /**
1485
+ * Returns the path bounding box, equivalent to native `path.getBBox()`.
1486
+ *
1487
+ * @public
1488
+ * @returns the pathBBox
1489
+ */
1254
1490
  get bbox(): {
1255
1491
  x: number;
1256
1492
  y: number;
@@ -1262,6 +1498,12 @@ declare class SVGPathCommander {
1262
1498
  cy: number;
1263
1499
  cz: number;
1264
1500
  };
1501
+ /**
1502
+ * Returns the total path length, equivalent to native `path.getTotalLength()`.
1503
+ *
1504
+ * @public
1505
+ * @returns the path total length
1506
+ */
1265
1507
  get length(): number;
1266
1508
  /**
1267
1509
  * Returns the path bounding box, equivalent to native `path.getBBox()`.
@@ -1345,7 +1587,7 @@ declare class SVGPathCommander {
1345
1587
  * @example
1346
1588
  * ```ts
1347
1589
  * new SVGPathCommander('M0 0L100 0L100 100L0 100Z').reverse().toString()
1348
- * // => 'M0 100L0 0L100 0L100 100Z'
1590
+ * // => 'M0 100L100 100L100 0L0 0Z'
1349
1591
  * ```
1350
1592
  *
1351
1593
  * @param onlySubpath - option to reverse all sub-paths except first
@@ -1377,7 +1619,7 @@ declare class SVGPathCommander {
1377
1619
  * @example
1378
1620
  * ```ts
1379
1621
  * new SVGPathCommander('M10 10L10 10L90 90').optimize().toString()
1380
- * // => 'M10 10l0 0 80 80'
1622
+ * // => 'M10 10v0l80 80'
1381
1623
  * ```
1382
1624
  *
1383
1625
  * @returns this for chaining
@@ -1435,8 +1677,14 @@ declare class SVGPathCommander {
1435
1677
  * @returns void
1436
1678
  */
1437
1679
  dispose(): void;
1680
+ /** The default instance options. */
1438
1681
  static options: Options;
1682
+ /**
1683
+ * The DOMMatrix shim used for transformations.
1684
+ * @see https://github.com/thednp/dommatrix
1685
+ */
1439
1686
  static CSSMatrix: typeof CSSMatrix;
1687
+ /** The tools for elliptical arc computation. */
1440
1688
  static arcTools: {
1441
1689
  angleBetween: (v0: Point, v1: Point) => number;
1442
1690
  arcLength: (rx: number, ry: number, theta: number) => number;
@@ -1460,6 +1708,7 @@ declare class SVGPathCommander {
1460
1708
  y: number;
1461
1709
  };
1462
1710
  };
1711
+ /** The tools for Bezier curve computation. */
1463
1712
  static bezierTools: {
1464
1713
  bezierLength: (derivativeFn: DeriveCallback) => number;
1465
1714
  bezierLengthAtT: (derivativeFn: DeriveCallback, t: number) => number;
@@ -1476,6 +1725,7 @@ declare class SVGPathCommander {
1476
1725
  minmaxQ: ([v1, cp, v2]: [number, number, number]) => PointTuple;
1477
1726
  Tvalues: number[];
1478
1727
  };
1728
+ /** The tools for cubic Bezier computation. */
1479
1729
  static cubicTools: {
1480
1730
  getCubicBBox: (x1: number, y1: number, c1x: number, c1y: number, c2x: number, c2y: number, x2: number, y2: number) => BBoxMaxima;
1481
1731
  getCubicLength: (x1: number, y1: number, c1x: number, c1y: number, c2x: number, c2y: number, x2: number, y2: number) => number;
@@ -1488,6 +1738,7 @@ declare class SVGPathCommander {
1488
1738
  y: number;
1489
1739
  };
1490
1740
  };
1741
+ /** The tools for line segment computation. */
1491
1742
  static lineTools: {
1492
1743
  getLineBBox: (x1: number, y1: number, x2: number, y2: number) => [number, number, number, number];
1493
1744
  getLineLength: (x1: number, y1: number, x2: number, y2: number) => number;
@@ -1496,11 +1747,13 @@ declare class SVGPathCommander {
1496
1747
  y: number;
1497
1748
  };
1498
1749
  };
1750
+ /** The tools for polygon computation. */
1499
1751
  static polygonTools: {
1500
1752
  polygonArea: (polygon: PointTuple[]) => number;
1501
1753
  polygonLength: (polygon: PointTuple[]) => number;
1502
1754
  polygonCentroid: (polygon: PointTuple[]) => PointTuple;
1503
1755
  };
1756
+ /** The tools for quadratic Bezier computation. */
1504
1757
  static quadTools: {
1505
1758
  getPointAtQuadLength: (x1: number, y1: number, cx: number, cy: number, x2: number, y2: number, distance?: number) => {
1506
1759
  x: number;
@@ -1513,23 +1766,41 @@ declare class SVGPathCommander {
1513
1766
  getQuadBBox: (x1: number, y1: number, cx: number, cy: number, x2: number, y2: number) => [number, number, number, number];
1514
1767
  getQuadLength: (x1: number, y1: number, cx: number, cy: number, x2: number, y2: number) => number;
1515
1768
  };
1769
+ /** Parses a path string value or object and returns an array */
1516
1770
  static pathToAbsolute: typeof pathToAbsolute;
1771
+ /** Parses a path string value or object and returns an array */
1517
1772
  static pathToRelative: typeof pathToRelative;
1773
+ /** Parses a path string or PathArray and returns a new one */
1518
1774
  static pathToCurve: typeof pathToCurve;
1775
+ /** Returns a valid `d` attribute string value created */
1519
1776
  static pathToString: typeof pathToString;
1777
+ /** Returns the square root of the distance */
1520
1778
  static distanceSquareRoot: typeof distanceSquareRoot;
1779
+ /** Returns the coordinates of a specified distance */
1521
1780
  static midPoint: typeof midPoint;
1781
+ /** Returns an {x,y} vector rotated by a given */
1522
1782
  static rotateVector: typeof rotateVector;
1783
+ /** Rounds a number to the specified number of decimal places. */
1523
1784
  static roundTo: typeof roundTo;
1785
+ /** Parses a path string value and returns an array */
1524
1786
  static parsePathString: typeof parsePathString;
1787
+ /** Breaks the parsing of a pathString once a segment is finalized. */
1525
1788
  static finalizeSegment: typeof finalizeSegment;
1789
+ /** Error message prefix used when a path string cannot be parsed. */
1526
1790
  static invalidPathValue: string;
1791
+ /** Checks if the character is an A (arc-to) path command. */
1527
1792
  static isArcCommand: typeof isArcCommand;
1793
+ /** Checks if a character is a digit. */
1528
1794
  static isDigit: typeof isDigit;
1795
+ /** Checks if the character is or belongs to a number. */
1529
1796
  static isDigitStart: typeof isDigitStart;
1797
+ /** Checks if the character is a MoveTo command. */
1530
1798
  static isMoveCommand: typeof isMoveCommand;
1799
+ /** Checks if the character is a path command. */
1531
1800
  static isPathCommand: typeof isPathCommand;
1801
+ /** Checks if the character is a space. */
1532
1802
  static isSpace: typeof isSpace;
1803
+ /** The number of parameters for each path command. */
1533
1804
  static paramsCount: {
1534
1805
  a: number;
1535
1806
  c: number;
@@ -1543,66 +1814,125 @@ declare class SVGPathCommander {
1543
1814
  v: number;
1544
1815
  z: number;
1545
1816
  };
1817
+ /** Default parser parameters object used to track position state */
1546
1818
  static paramsParser: ParserParams;
1819
+ /** The `PathParser` is used by the `parsePathString` static method */
1547
1820
  static PathParser: typeof PathParser;
1821
+ /** Validates an A (arc-to) specific path command value. */
1548
1822
  static scanFlag: typeof scanFlag;
1823
+ /** Validates every character of the path string, */
1549
1824
  static scanParam: typeof scanParam;
1825
+ /** Scans every character in the path string to determine */
1550
1826
  static scanSegment: typeof scanSegment;
1827
+ /** Points the parser to the next character in the */
1551
1828
  static skipSpaces: typeof skipSpaces;
1829
+ /** Small threshold value used for floating-point distance comparisons in path calculations. */
1552
1830
  static distanceEpsilon: number;
1831
+ /** Checks a `PathArray` for an unnecessary `Z` segment */
1553
1832
  static fixPath: typeof fixPath;
1833
+ /** Returns the point in path closest to a given point. */
1554
1834
  static getClosestPoint: typeof getClosestPoint;
1835
+ /** Check if a path is drawn clockwise and returns true if so, */
1555
1836
  static getDrawDirection: typeof getDrawDirection;
1837
+ /** Returns the area of a single cubic-bezier segment. */
1556
1838
  static getPathArea: typeof getPathArea;
1839
+ /** Calculates the bounding box of a path. */
1557
1840
  static getPathBBox: typeof getPathBBox;
1841
+ /** Returns [x,y] coordinates of a point at a given length along a path. */
1558
1842
  static getPointAtLength: typeof getPointAtLength;
1843
+ /** Returns the segment, its index and length as well as */
1559
1844
  static getPropertiesAtLength: typeof getPropertiesAtLength;
1845
+ /** Returns the point and segment in path closest to a given point as well as */
1560
1846
  static getPropertiesAtPoint: typeof getPropertiesAtPoint;
1847
+ /** Returns the segment at a given length. */
1561
1848
  static getSegmentAtLength: typeof getSegmentAtLength;
1849
+ /** Returns the path segment which contains a given point. */
1562
1850
  static getSegmentOfPoint: typeof getSegmentOfPoint;
1851
+ /** Returns the total length of a path, equivalent to `shape.getTotalLength()`. */
1563
1852
  static getTotalLength: typeof getTotalLength;
1853
+ /** Iterates an array to check if it's a `pathArray` */
1564
1854
  static isAbsoluteArray: typeof isAbsoluteArray;
1855
+ /** Iterates an array to check if it's a `pathArray` */
1565
1856
  static isCurveArray: typeof isCurveArray;
1857
+ /** Checks if a path is a polygon (only M, L, H, V, Z commands). */
1566
1858
  static isPolygonArray: typeof isPolygonArray;
1859
+ /** Iterates an array to check if it's a `pathArray` */
1567
1860
  static isNormalizedArray: typeof isNormalizedArray;
1861
+ /** Iterates an array to check if it's an actual `pathArray`. */
1568
1862
  static isPathArray: typeof isPathArray;
1863
+ /** Checks if a given point is in the stroke of a path. */
1569
1864
  static isPointInStroke: typeof isPointInStroke;
1865
+ /** Iterates an array to check if it's a `pathArray` */
1570
1866
  static isRelativeArray: typeof isRelativeArray;
1867
+ /** Parses a path string value to determine its validity */
1571
1868
  static isValidPath: typeof isValidPath;
1869
+ /** Samples points from a path to form a polygon approximation. */
1572
1870
  static samplePolygon: typeof samplePolygon;
1871
+ /** Supported shapes and their specific parameters. */
1573
1872
  static shapeParams: ShapeParams;
1873
+ /** Returns a new `<path>` element created from attributes of a `<line>`, `<polyline>`, */
1574
1874
  static shapeToPath: typeof shapeToPath;
1875
+ /** Returns a new PathArray from line attributes. */
1575
1876
  static shapeToPathArray: typeof shapeToPathArray;
1877
+ /** Returns an absolute segment of a `PathArray` object. */
1576
1878
  static absolutizeSegment: typeof absolutizeSegment;
1879
+ /** Converts A (arc-to) segments to C (cubic-bezier-to). */
1577
1880
  static arcToCubic: typeof arcToCubic;
1881
+ /** Returns a transformation matrix to apply to `<path>` elements. */
1578
1882
  static getSVGMatrix: typeof getSVGMatrix;
1883
+ /** Iterates over a `PathArray`, executing a callback for each segment. */
1579
1884
  static iterate: typeof iterate;
1885
+ /** Converts an L (line-to) segment to C (cubic-bezier). */
1580
1886
  static lineToCubic: typeof lineToCubic;
1887
+ /** Parses a path string or PathArray, then iterates the result for: */
1581
1888
  static normalizePath: typeof normalizePath;
1889
+ /** Normalizes a single segment of a `pathArray` object. */
1582
1890
  static normalizeSegment: typeof normalizeSegment;
1891
+ /** Optimizes a PathArray: */
1583
1892
  static optimizePath: typeof optimizePath;
1893
+ /** Transforms a specified point using a matrix, returning a new */
1584
1894
  static projection2d: typeof projection2d;
1895
+ /** Converts a Q (quadratic-bezier) segment to C (cubic-bezier). */
1585
1896
  static quadToCubic: typeof quadToCubic;
1897
+ /** Returns a relative segment of a `PathArray` object. */
1586
1898
  static relativizeSegment: typeof relativizeSegment;
1899
+ /** Reverses all segments of a `pathArray` */
1587
1900
  static reverseCurve: typeof reverseCurve;
1901
+ /** Reverses all segments of a PathArray and returns a new PathArray */
1588
1902
  static reversePath: typeof reversePath;
1903
+ /** Rounds the values of a `pathArray` instance to */
1589
1904
  static roundPath: typeof roundPath;
1905
+ /** Rounds the numeric values of a path segment to the specified precision. */
1590
1906
  static roundSegment: typeof roundSegment;
1907
+ /** Converts any segment to C (cubic-bezier). */
1591
1908
  static segmentToCubic: typeof segmentToCubic;
1909
+ /** Shorten a single segment of a `pathArray` object. */
1592
1910
  static shortenSegment: typeof shortenSegment;
1911
+ /** Split a path string or PathArray into an array of sub-paths. */
1593
1912
  static splitPath: typeof splitPath;
1913
+ /** Equalizes two paths for morphing (single/multi subpath). */
1594
1914
  static equalizePaths: typeof equalizePaths;
1915
+ /** Equalizes two paths for morphing (single subpath only). */
1595
1916
  static equalizeSegments: typeof equalizeSegments;
1917
+ /** Split a cubic Bézier into two cubics at parameter t [0–1]. */
1596
1918
  static splitCubicSegment: typeof splitCubicSegment;
1919
+ /** Apply a 2D / 3D transformation to a PathArray. */
1597
1920
  static transformPath: typeof transformPath;
1921
+ /** Checks if a point is inside a bounding box. */
1598
1922
  static isPointInsideBBox: typeof isPointInsideBBox;
1923
+ /** Finds intersection points between two paths. */
1599
1924
  static pathsIntersection: typeof pathsIntersection;
1925
+ /** Checks if two bounding boxes intersect. */
1600
1926
  static boundingBoxIntersect: typeof boundingBoxIntersect;
1927
+ /** Determines if an SVG path contains multiple subpaths. */
1601
1928
  static isMultiPath: typeof isMultiPath;
1929
+ /** Check if a PathArray is closed, which means its last segment is a Z. */
1602
1930
  static isClosedPath: typeof isClosedPath;
1931
+ /** Checks if a path is a polyline (only M, L, H, V commands). */
1603
1932
  static isPolylineArray: typeof isPolylineArray;
1933
+ /** The library version. */
1604
1934
  static version: string;
1605
1935
  }
1606
1936
  //#endregion
1607
- export { ACommand, ASegment, AbsoluteArray, AbsoluteCommand, AbsoluteSegment, ArcCoordinates, ArcSegment, BBoxMaxima, CCommand, CSegment, CircleAttr, CloseSegment, ClosedCurveArray, CubicCoordinates, CubicPoints, CubicSegment, CurveArray, DeriveCallback, DerivedCubicPoints, DerivedPoint, DerivedQuadPoints, DigitNumber, EllipseAttr, EqualizationOptions, GlyphAttr, HCommand, HSegment, HorLineSegment, IntersectionOptions, IntersectionPoint, IteratorCallback, LCommand, LSegment, LengthFactory, LineAttr, LineCoordinates, LineSegment, MCommand, MSegment, MorphPathArray, MoveSegment, NormalArray, NormalSegment, Options, ParserParams, PathArray, PathBBox, PathCommand, PathCommandNumber, PathEqualizationOptions, PathFeature, PathSegment, PathTransform, PathsEqualizationOptions, Point, PointAtLength, PointProperties, PointTuple, PolyAttr, PolygonArray, PolylineArray, QCommand, QSegment, QuadCoordinates, QuadPoints, QuadSegment, RectAttr, RelativeArray, RelativeCommand, RelativeSegment, SCommand, SSegment, SegmentLimits, SegmentProperties, ShapeOps, ShapeParams, ShapeTags, ShapeTypes, ShortCubicSegment, ShortQuadSegment, ShortSegment, SpaceNumber, TCommand, TSegment, TransformEntries, TransformObject, TransformObjectValues, TransformProps, VCommand, VSegment, VertLineSegment, ZCommand, ZSegment, aCommand, aSegment, cCommand, cSegment, SVGPathCommander as default, hCommand, hSegment, lCommand, lSegment, mCommand, mSegment, qCommand, qSegment, sCommand, sSegment, tCommand, tSegment, vCommand, vSegment, zCommand, zSegment };
1937
+ export { ACommand, ASegment, AbsoluteArray, AbsoluteCommand, AbsoluteSegment, ArcCoordinates, ArcSegment, BBoxMaxima, CCommand, CSegment, CircleAttr, CloseSegment, ClosedCurveArray, CubicCoordinates, CubicPoints, CubicSegment, CurveArray, DeriveCallback, DerivedCubicPoints, DerivedPoint, DerivedQuadPoints, DigitNumber, EllipseAttr, EqualizationOptions, GlyphAttr, HCommand, HSegment, HorLineSegment, IntersectionOptions, IntersectionPoint, IteratorCallback, LCommand, LSegment, LengthFactory, LineAttr, LineCoordinates, LineSegment, MCommand, MSegment, MorphPathArray, MoveSegment, NormalArray, NormalSegment, Options, ParserParams, PathArray, PathBBox, PathCommand, PathCommandNumber, PathEqualizationOptions, PathFeature, PathSegment, PathTransform, PathsEqualizationOptions, Point, PointAtLength, PointProperties, PointTuple, PolyAttr, PolygonArray, PolylineArray, QCommand, QSegment, QuadCoordinates, QuadPoints, QuadSegment, RectAttr, RelativeArray, RelativeCommand, RelativeSegment, SCommand, SSegment, SVGPathCommander, SVGPathCommander as default, SegmentLimits, SegmentProperties, ShapeOps, ShapeParams, ShapeTags, ShapeTypes, ShortCubicSegment, ShortQuadSegment, ShortSegment, SpaceNumber, TCommand, TSegment, TransformEntries, TransformObject, TransformObjectValues, TransformProps, VCommand, VSegment, VertLineSegment, ZCommand, ZSegment, aCommand, aSegment, cCommand, cSegment, hCommand, hSegment, lCommand, lSegment, mCommand, mSegment, qCommand, qSegment, sCommand, sSegment, tCommand, tSegment, vCommand, vSegment, zCommand, zSegment };
1608
1938
  //# sourceMappingURL=index.d.ts.map