svg-path-commander 2.3.5 → 2.4.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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * SVGPathCommander ESM v2.3.5 (http://thednp.github.io/svg-path-commander)
2
+ * SVGPathCommander ESM v2.4.0 (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
  */
@@ -14,6 +14,54 @@ export type SegmentProperties = {
14
14
  length: number;
15
15
  /** The distance from the start of the path to the end of the segment. */
16
16
  lengthAtSegment: number;
17
+ /** The point at the given length. */
18
+ point: Point;
19
+ /** The unit tangent vector at the given length. */
20
+ tangent: Point;
21
+ /** The unit normal vector at the given length, the left normal of the tangent. */
22
+ normal: Point;
23
+ /** The angle of the tangent at the given length, in degrees. */
24
+ angle: number;
25
+ };
26
+ /** The options of the path simplification. */
27
+ export type SimplifyOptions = {
28
+ /** The target geometric error of the sampled fitting. @default 1 */
29
+ tolerance?: number;
30
+ };
31
+ /** The side of a path an offset is created on. */
32
+ export type OffsetSide = "left" | "right" | "both";
33
+ /** The join type used at a corner of an offset path. */
34
+ export type OffsetJoin = "round" | "miter" | "bevel";
35
+ /** The cap type used at the end of an open offset path. */
36
+ export type OffsetCap = "butt" | "square" | "round";
37
+ /** The options of the path offsetting. */
38
+ export type OffsetOptions = {
39
+ /** The side of the path to offset, the left normal of the direction of travel. @default "left" */
40
+ side?: OffsetSide;
41
+ /** The join type at a corner of the path. @default "miter" */
42
+ join?: OffsetJoin;
43
+ /** The ratio of the miter length to the offset distance. @default 4 */
44
+ miterLimit?: number;
45
+ /** The cap type at the end of an open path. @default "butt" */
46
+ cap?: OffsetCap;
47
+ /** The number of the intervals a curve is sampled with. @default 16 */
48
+ steps?: number;
49
+ /** The number of the decimals of the result. @default 4 */
50
+ precision?: number;
51
+ };
52
+ /** The rule that decides if a point is inside a path. */
53
+ export type FillRule = "nonzero" | "evenodd";
54
+ /** The options of the point in path test. */
55
+ export type PointInPathOptions = {
56
+ /** The fill rule of the path, the SVG `fill-rule` attribute. @default "nonzero" */
57
+ fillRule?: FillRule;
58
+ /** The maximum distance between the path and its polygon approximation. @default 0.1 */
59
+ tolerance?: number;
60
+ };
61
+ /** The options of the point in stroke test. */
62
+ export type StrokeOptions = {
63
+ /** The width of the stroke, the band painted around the path. @default 0 */
64
+ width?: number;
17
65
  };
18
66
  /** The closest point on the path to a given point, with the distance and optional segment. */
19
67
  export type PointProperties = {
@@ -470,26 +518,47 @@ export interface PathEqualizationOptions {
470
518
  sampleSize?: number;
471
519
  /** The amount of decimals to round values to. */
472
520
  roundValues?: number;
473
- /** Whether to close the path before equalization. */
521
+ /** Whether to close the path after equalization. By default, both paths are closed when either input is closed. */
474
522
  close?: boolean;
475
523
  }
476
524
  /** Options for equalizing two paths for morphing. */
477
525
  export interface EqualizationOptions {
478
526
  /** The equalization mode. @default "auto" */
479
- mode?: "curve" | "auto";
527
+ mode?: "auto" | "line" | "curve";
528
+ /** The strategy used to place the points of the equalized paths. @default "segment" */
529
+ strategy?: "segment" | "arcLength";
530
+ /** Whether the paths are aligned by rotation. @default true */
531
+ align?: boolean;
480
532
  /** The number of sample points for the line mode. */
481
533
  sampleSize?: number;
482
534
  /** The amount of decimals to round values to. */
483
535
  roundValues?: number;
484
- /** Whether to reverse the second path before equalization. */
485
- reverse?: boolean;
486
- /** Whether to close the path before equalization. */
536
+ /** Whether to reverse the second path before equalization. @default true */
537
+ reverse?: boolean | "auto";
538
+ /** Whether to close the path after equalization. By default, both paths are closed when either input is closed. */
487
539
  close?: boolean;
488
540
  /** The target segment count for both paths. */
489
541
  target?: number;
490
542
  }
491
- /** `EqualizationOptions` without `reverse` and `target`, used for path pairs. */
492
- export type PathsEqualizationOptions = Omit<EqualizationOptions, "reverse" | "target">;
543
+ /** The options of the multi-subpath equalization. */
544
+ export type PathsEqualizationOptions = EqualizationOptions;
545
+ /** Options for equalizing two paths for morphing with the `equalize` facade. */
546
+ export interface EqualizeOptions {
547
+ /** The number of points of the equalized paths. @default "auto" */
548
+ points?: number | "auto";
549
+ /** The strategy used to place the points of the equalized paths. @default "segment" */
550
+ strategy?: "segment" | "arcLength";
551
+ /** Whether the paths are aligned by rotation. @default true */
552
+ align?: boolean;
553
+ /** Whether a path is reversed to match the winding of the other one. @default "auto" */
554
+ reverse?: boolean | "auto";
555
+ /** The equalization mode. @default "auto" */
556
+ mode?: "auto" | "line" | "curve";
557
+ /** The amount of decimals to round values to. @default 4 */
558
+ roundValues?: number;
559
+ /** Whether to close the paths after equalization. By default, both paths are closed when either input is closed. */
560
+ close?: boolean;
561
+ }
493
562
  /** The geometric features of a path used for matching during morphing. */
494
563
  export interface PathFeature {
495
564
  /** Whether the path is a polygon. */
@@ -583,7 +652,7 @@ declare const pathToRelative: <T extends PathArray>(pathInput: string | T) => Re
583
652
  * @example
584
653
  * ```ts
585
654
  * pathToCurve('M10 50q15 -25 30 0')
586
- * // => [['M', 10, 50], ['C', 25, 25, 40, 50, 40, 50]]
655
+ * // => [['M', 10, 50], ['C', 20, 33.3333, 30, 33.3333, 40, 50]]
587
656
  * ```
588
657
  */
589
658
  declare const pathToCurve: <T extends PathArray>(pathInput: string | T) => CurveArray;
@@ -608,7 +677,11 @@ declare const pathToString: <T extends PathArray>(path: T, roundOption?: number
608
677
  *
609
678
  * If parameter value is already a `PathArray`,
610
679
  * return a clone of it.
611
-
680
+ *
681
+ * A path must begin with a moveto command, so a path that starts with another
682
+ * command is in error. A leading relative moveto is a pair of absolute
683
+ * coordinates, so it is rewritten as an absolute one.
684
+ *
612
685
  * @example
613
686
  * parsePathString("M 0 0L50 50")
614
687
  * // => [["M",0,0],["L",50,50]]
@@ -739,12 +812,12 @@ declare const getPathBBox: <T extends PathArray>(pathInput: T | string) => {
739
812
  * Returns the total length of a path, equivalent to `shape.getTotalLength()`.
740
813
  *
741
814
  * @param pathInput - The target path string or PathArray
742
- * @returns The total length of the path
815
+ * @returns the total length of the path
743
816
  *
744
817
  * @example
745
818
  * ```ts
746
819
  * getTotalLength('M0 0L100 0L100 100L0 100Z')
747
- * // => 300
820
+ * // => 400
748
821
  * ```
749
822
  */
750
823
  declare const getTotalLength: <T extends PathArray>(pathInput: string | T) => number;
@@ -783,7 +856,7 @@ declare const getDrawDirection: (path: string | PathArray) => boolean;
783
856
  * @example
784
857
  * ```ts
785
858
  * getPathArea([['M', 0, 0], ['L', 100, 0], ['L', 100, 100], ['L', 0, 100], ['Z']])
786
- * // => -10000 (counter-clockwise square)
859
+ * // => 10000 (clockwise square)
787
860
  * ```
788
861
  */
789
862
  declare const getPathArea: <T extends PathArray | string>(path: T) => number;
@@ -808,6 +881,10 @@ declare const getPointAtLength: <T extends PathArray>(pathInput: string | T, dis
808
881
  * Returns the segment, its index and length as well as
809
882
  * the length to that segment at a given length in a path.
810
883
  *
884
+ * The point at the given length is returned with the frame of the path at
885
+ * that point: the unit tangent vector, the unit normal vector and the angle
886
+ * of the tangent in degrees.
887
+ *
811
888
  * @param pathInput target `pathArray`
812
889
  * @param distance the given length
813
890
  * @returns the requested properties
@@ -884,14 +961,51 @@ declare const isPathArray: (path: unknown) => path is PathArray;
884
961
  /**
885
962
  * Checks if a given point is in the stroke of a path.
886
963
  *
964
+ * Without a width the point has to be on the path itself, within the
965
+ * distance epsilon of it. With a width the stroke is the band around the
966
+ * path: the point is in the stroke when it is at most half the width away
967
+ * from the path. The ends of an open path are treated as if the stroke had
968
+ * round caps, so a point beyond the end of the path is in the stroke too.
969
+ *
887
970
  * @param pathInput target path
888
971
  * @param point the given `{x,y}` point
972
+ * @param options the options of the test
889
973
  * @returns the query result
974
+ *
975
+ * @example
976
+ * ```ts
977
+ * isPointInStroke('M0 0L100 0', { x: 50, y: 0 });
978
+ * // => true
979
+ * isPointInStroke('M0 0L100 0', { x: 50, y: 5 }, { width: 10 });
980
+ * // => true
981
+ * ```
890
982
  */
891
- declare const isPointInStroke: <T extends PathArray>(pathInput: string | T, point: {
892
- x: number;
893
- y: number;
894
- }) => boolean;
983
+ declare const isPointInStroke: <T extends PathArray>(pathInput: string | T, point: Point, options?: StrokeOptions) => boolean;
984
+ /**
985
+ * Checks if a given point is inside a path.
986
+ *
987
+ * The path is flattened into polygons and the point is tested against them
988
+ * with the fill rule of the path: the `nonzero` rule counts the windings of
989
+ * the polygons around the point, the `evenodd` rule counts the crossings of
990
+ * the polygons with a ray from the point. A point on the boundary of the
991
+ * shape is inside of it, the way the browser answers it.
992
+ *
993
+ * The curves of the path are approximated with chords that stay within the
994
+ * tolerance of the curve, so the answer is exact except for the points that
995
+ * are within the tolerance of the boundary of a curve.
996
+ *
997
+ * @param pathInput target path
998
+ * @param point the given `{x,y}` point
999
+ * @param options the options of the test
1000
+ * @returns the query result
1001
+ *
1002
+ * @example
1003
+ * ```ts
1004
+ * isPointInPath('M0 0L100 0L100 100L0 100Z', { x: 50, y: 50 });
1005
+ * // => true
1006
+ * ```
1007
+ */
1008
+ declare const isPointInPath: <T extends PathArray>(pathInput: string | T, point: Point, options?: PointInPathOptions) => boolean;
895
1009
  /**
896
1010
  * Iterates an array to check if it's a `pathArray`
897
1011
  * with relative values.
@@ -912,8 +1026,6 @@ declare const isValidPath: (pathString: string) => boolean;
912
1026
  * Samples points from a path to form a polygon approximation.
913
1027
  * Collects endpoints of each segment (M start + ends of L/C/etc).
914
1028
  *
915
- * If `sampleSize` parameter is provided, it will return a polygon
916
- * equivalent to the original `PathArray`.
917
1029
  * @param path `PolygonPathArray` or `CurvePathArray`
918
1030
  * @returns Array of [x, y] points
919
1031
  */
@@ -989,7 +1101,7 @@ declare const isClosedPath: <T extends PathArray>(path: T) => boolean;
989
1101
  * @example
990
1102
  * ```ts
991
1103
  * normalizePath('M10 90s20 -80 40 -80s20 80 40 80')
992
- * // => [['M', 10, 90], ['C', 30, 90, 25, 10, 50, 10], ['C', 75, 10, 70, 90, 90, 90]]
1104
+ * // => [['M', 10, 90], ['C', 10, 90, 30, 10, 50, 10], ['C', 70, 10, 70, 90, 90, 90]]
993
1105
  * ```
994
1106
  */
995
1107
  declare const normalizePath: <T extends string | PathArray>(pathInput: T) => NormalArray;
@@ -1005,10 +1117,58 @@ declare const normalizePath: <T extends string | PathArray>(pathInput: T) => Nor
1005
1117
  * @example
1006
1118
  * ```ts
1007
1119
  * optimizePath('M10 10L10 10L90 90', 2)
1008
- * // => [['M', 10, 10], ['l', 0, 0], ['l', 80, 80]]
1120
+ * // => [['M', 10, 10], ['v', 0], ['l', 80, 80]]
1009
1121
  * ```
1010
1122
  */
1011
1123
  declare const optimizePath: <T extends string | PathArray>(pathInput: T, roundOption?: number) => PathArray;
1124
+ /**
1125
+ * Offsets a path along its normals.
1126
+ *
1127
+ * The path is sampled along its length, every sample is shifted along the
1128
+ * normal of the path and the result is a path of straight lines. The
1129
+ * corners of the path are joined with the `join` option, and the ends of an
1130
+ * open path are capped with the `cap` option.
1131
+ *
1132
+ * The `side` option is literal: the left side is the left normal of the
1133
+ * direction of travel, the same normal `getPropertiesAtLength()` returns.
1134
+ * The `both` side is the outline of the stroke, the band between the two
1135
+ * sides of the path.
1136
+ *
1137
+ * The offset is not cleaned up: an offset distance larger than the local
1138
+ * radius of curvature of the path produces a self-crossing curve.
1139
+ *
1140
+ * @param pathInput - the path string or `PathArray`
1141
+ * @param distance - the offset distance
1142
+ * @param options - the options of the offset
1143
+ * @returns the offset path
1144
+ *
1145
+ * @example
1146
+ * ```ts
1147
+ * offsetPath('M0 0L100 0', 10)
1148
+ * // => [['M', 0, 10], ['L', 100, 10]]
1149
+ * ```
1150
+ */
1151
+ declare const offsetPath: <T extends PathArray>(pathInput: string | T, distance: number, options?: OffsetOptions) => PathArray;
1152
+ /**
1153
+ * Joins two paths into a single path with two sub-paths.
1154
+ *
1155
+ * Both paths have to be valid paths, so they begin with a moveto command,
1156
+ * and the result holds absolute values.
1157
+ *
1158
+ * @param pathA - the first path string or `PathArray`
1159
+ * @param pathB - the second path string or `PathArray`
1160
+ * @returns the joined path
1161
+ *
1162
+ * @example
1163
+ * ```ts
1164
+ * joinPath('M0 0L100 0', 'M0 100L100 100')
1165
+ * // => [
1166
+ * // ['M', 0, 0], ['L', 100, 0],
1167
+ * // ['M', 0, 100], ['L', 100, 100]
1168
+ * // ]
1169
+ * ```
1170
+ */
1171
+ declare const joinPath: (pathA: string | PathArray, pathB: string | PathArray) => PathArray;
1012
1172
  /**
1013
1173
  * Reverses all segments of a PathArray and returns a new PathArray
1014
1174
  * with absolute values.
@@ -1023,16 +1183,39 @@ declare const optimizePath: <T extends string | PathArray>(pathInput: T, roundOp
1023
1183
  * @example
1024
1184
  * ```ts
1025
1185
  * reversePath([['M', 0, 0], ['L', 100, 0], ['L', 100, 100], ['L', 0, 100], ['Z']])
1026
- * // => [['M', 0, 100], ['L', 0, 0], ['L', 100, 0], ['L', 100, 100], ['Z']]
1186
+ * // => [['M', 0, 100], ['L', 100, 100], ['L', 100, 0], ['L', 0, 0], ['Z']]
1027
1187
  * ```
1028
1188
  */
1029
1189
  declare const reversePath: <T extends PathArray>(pathInput: T | string) => T;
1190
+ /**
1191
+ * Reverses the sub-path at a given index of a path.
1192
+ *
1193
+ * The other sub-paths are left untouched, and the result holds absolute
1194
+ * values.
1195
+ *
1196
+ * @param pathInput - the path string or `PathArray`
1197
+ * @param index - the zero-based index of the sub-path to reverse
1198
+ * @returns the path with the sub-path reversed
1199
+ *
1200
+ * @example
1201
+ * ```ts
1202
+ * reverseSubPath('M0 0L100 0ZM0 100L100 100', 1)
1203
+ * // => [
1204
+ * // ['M', 0, 0], ['L', 100, 0], ['Z'],
1205
+ * // ['M', 100, 100], ['L', 0, 100]
1206
+ * // ]
1207
+ * ```
1208
+ */
1209
+ declare const reverseSubPath: (pathInput: string | PathArray, index: number) => PathArray;
1030
1210
  /**
1031
1211
  * Split a path string or PathArray into an array of sub-paths.
1032
1212
  *
1033
1213
  * In the process, values are converted to absolute
1034
1214
  * for visual consistency.
1035
1215
  *
1216
+ * A path must begin with a moveto command, so a path that does not is
1217
+ * rejected by the parser.
1218
+ *
1036
1219
  * @param pathInput - The source path string or PathArray
1037
1220
  * @returns An array of sub-path PathArrays
1038
1221
  *
@@ -1059,20 +1242,24 @@ declare const splitPath: <T extends PathArray>(pathInput: T | string) => T[];
1059
1242
  * @example
1060
1243
  * ```ts
1061
1244
  * transformPath('M0 0L100 0L100 100L0 100Z', { translate: [10, 20], scale: 2 })
1062
- * // => [['M', 10, 20], ['L', 210, 20], ['L', 210, 220], ['L', 10, 220], ['Z']]
1245
+ * // => [['M', 10, 20], ['H', 210], ['V', 220], ['H', 10], ['Z']]
1063
1246
  * ```
1064
1247
  */
1065
1248
  declare const transformPath: <T extends PathArray>(pathInput: T | string, transform?: Partial<TransformObject>) => T | AbsoluteArray;
1066
1249
  /**
1067
1250
  * Returns an absolute segment of a `PathArray` object.
1068
1251
  *
1252
+ * The current point of a path starts at the origin, so the first segment
1253
+ * of a path is absolutized against `[0, 0]`: a relative moveto at the
1254
+ * start of a path is an absolute one, as the SVG spec requires.
1255
+ *
1069
1256
  * @param segment the segment object
1070
- * @param index the segment index
1257
+ * @param _index the segment index
1071
1258
  * @param lastX the last known X value
1072
1259
  * @param lastY the last known Y value
1073
1260
  * @returns the absolute segment
1074
1261
  */
1075
- declare const absolutizeSegment: (segment: PathSegment, index: number, lastX: number, lastY: number) => AbsoluteSegment;
1262
+ declare const absolutizeSegment: (segment: PathSegment, _index: number, lastX: number, lastY: number) => AbsoluteSegment;
1076
1263
  /**
1077
1264
  * Converts A (arc-to) segments to C (cubic-bezier-to).
1078
1265
  *
@@ -1095,12 +1282,12 @@ declare const arcToCubic: (X1: number, Y1: number, RX: number, RY: number, angle
1095
1282
  /**
1096
1283
  * Returns a transformation matrix to apply to `<path>` elements.
1097
1284
  *
1098
- * @see TransformObjectValues
1285
+ * @see TransformObject
1099
1286
  *
1100
1287
  * @param transform the `transformObject`
1101
1288
  * @returns a new transformation matrix
1102
1289
  */
1103
- declare const getSVGMatrix: (transform: TransformObjectValues) => CSSMatrix;
1290
+ declare const getSVGMatrix: (transform: Partial<TransformObject>) => CSSMatrix;
1104
1291
  /**
1105
1292
  * Iterates over a `PathArray`, executing a callback for each segment.
1106
1293
  * The callback can:
@@ -1213,11 +1400,14 @@ declare const roundSegment: <T extends PathSegment>(segment: T, roundOption: num
1213
1400
  /**
1214
1401
  * Converts any segment to C (cubic-bezier).
1215
1402
  *
1403
+ * A segment that is already a cubic, or a command the converter does not
1404
+ * handle, is returned unchanged.
1405
+ *
1216
1406
  * @param segment the source segment
1217
1407
  * @param params the source segment parameters
1218
1408
  * @returns the cubic-bezier segment
1219
1409
  */
1220
- declare const segmentToCubic: (segment: PathSegment, params: ParserParams) => MSegment | CSegment;
1410
+ declare const segmentToCubic: (segment: PathSegment, params: ParserParams) => PathSegment;
1221
1411
  /**
1222
1412
  * Shorten a single segment of a `pathArray` object.
1223
1413
  *
@@ -1228,9 +1418,31 @@ declare const segmentToCubic: (segment: PathSegment, params: ParserParams) => MS
1228
1418
  * @returns the shortened segment
1229
1419
  */
1230
1420
  declare const shortenSegment: (segment: AbsoluteSegment, normalSegment: NormalSegment, params: ParserParams, prevCommand: PathCommand) => ShortSegment;
1421
+ /**
1422
+ * Simplifies a path within a geometric tolerance.
1423
+ *
1424
+ * Straight-line runs are reduced with Douglas-Peucker. Curve runs are fitted
1425
+ * with cubic Béziers, while arcs and original curves are preserved whenever
1426
+ * fitting would not reduce the segment count. Every source sub-path and its
1427
+ * closure are retained.
1428
+ *
1429
+ * The tolerance is the target geometric error of the sampled fitting. A
1430
+ * smaller tolerance keeps more detail, a bigger one removes more.
1431
+ *
1432
+ * @param pathInput - the target path string or PathArray
1433
+ * @param options - the tolerance of the simplification, or the options
1434
+ * @returns the simplified path
1435
+ *
1436
+ * @example
1437
+ * ```ts
1438
+ * simplifyPath("M0 0L10 0L20 0L30 0", 1)
1439
+ * // => [['M', 0, 0], ['L', 30, 0]]
1440
+ * ```
1441
+ */
1442
+ declare const simplifyPath: (pathInput: string | PathArray, options?: number | SimplifyOptions) => PathArray;
1231
1443
  /**
1232
1444
  * Checks a `PathArray` for an unnecessary `Z` segment
1233
- * and removes it. The `PathArray` is modified in place.
1445
+ * and returns a copy without it. The input is not modified.
1234
1446
  * In short, if the segment before `Z` extends to `M`,
1235
1447
  * the `Z` segment must be removed.
1236
1448
  *
@@ -1240,9 +1452,9 @@ declare const shortenSegment: (segment: AbsoluteSegment, normalSegment: NormalSe
1240
1452
  * sub-path separately.
1241
1453
  *
1242
1454
  * @param pathInput the `pathArray` source
1243
- * @returns void
1455
+ * @returns the fixed path
1244
1456
  */
1245
- declare const fixPath: <T extends PathArray>(pathInput: T | string) => void;
1457
+ declare const fixPath: <T extends PathArray>(pathInput: T | string) => PathArray;
1246
1458
  /**
1247
1459
  * Split a cubic Bézier into two cubics at parameter t [0–1].
1248
1460
  *
@@ -1277,11 +1489,16 @@ declare const equalizeSegments: (path1: PathArray | string, path2: PathArray | s
1277
1489
  /**
1278
1490
  * Equalizes two paths for morphing (single/multi subpath).
1279
1491
  *
1492
+ * Multi-subpath paths are reversed as whole paths, so an outer contour keeps
1493
+ * its relationship with its holes. Outer contours only match outer contours
1494
+ * and holes only match holes: an unmatched contour collapses at its own
1495
+ * centroid instead of taking the opposite fill role.
1496
+ *
1280
1497
  * @see https://minus-ze.ro/posts/morphing-arbitrary-paths-in-svg/
1281
1498
  * @param pathInput1 - First path string or PathArray
1282
1499
  * @param pathInput2 - Second path string or PathArray
1283
1500
  * @param initialCfg - Configuration options for equalization
1284
- * @returns Tuple of two equalized MorphPathArrays
1501
+ * @returns Tuple of two equalized PathArrays
1285
1502
  *
1286
1503
  * @example
1287
1504
  * ```ts
@@ -1289,7 +1506,80 @@ declare const equalizeSegments: (path1: PathArray | string, path2: PathArray | s
1289
1506
  * // eq1.length === eq2.length — ready for morphing
1290
1507
  * ```
1291
1508
  */
1292
- declare const equalizePaths: (pathInput1: string | PathArray, pathInput2: string | PathArray, initialCfg?: {}) => [MorphPathArray, MorphPathArray];
1509
+ declare const equalizePaths: (pathInput1: string | PathArray, pathInput2: string | PathArray, initialCfg?: PathsEqualizationOptions) => [PathArray, PathArray];
1510
+ /**
1511
+ * Equalizes two paths for morphing.
1512
+ *
1513
+ * The two paths are brought to the same shape, so they can be morphed into
1514
+ * each other: they hold the same number of segments of the same type, their
1515
+ * winding is the same and their points are aligned.
1516
+ *
1517
+ * A path with a single sub-path is equalized on its own, a path with more
1518
+ * sub-paths is split into sub-paths, the sub-paths are matched by their
1519
+ * shape and every pair is equalized on its own. Multi-subpath paths are
1520
+ * reversed as whole paths, so an outer contour keeps its relationship with
1521
+ * its holes. Outer contours only match outer contours and holes only match
1522
+ * holes: an unmatched contour collapses at its own centroid instead of
1523
+ * taking the opposite fill role.
1524
+ *
1525
+ * The `strategy` option decides how the points of the paths are placed:
1526
+ * - `segment` splits the segments of the paths, so the points of the result
1527
+ * are the points of the paths;
1528
+ * - `arcLength` distributes the points of the result along the length of
1529
+ * the paths. The source segment boundaries and corners are points of the
1530
+ * result too when the requested count allows it, so the shape of the paths
1531
+ * keeps its vertices.
1532
+ *
1533
+ * The `points` option is the number of points of the result. The automatic
1534
+ * mode uses the number of points of the bigger path.
1535
+ *
1536
+ * The `reverse` option decides what happens when the two paths draw in
1537
+ * opposite directions: `true` reverses the second path, `false` leaves the
1538
+ * paths as they are and `auto` reverses the path that leaves the two paths
1539
+ * closest to each other.
1540
+ *
1541
+ * @see https://minus-ze.ro/posts/morphing-arbitrary-paths-in-svg/
1542
+ *
1543
+ * @param pathInput1 - First path string or PathArray
1544
+ * @param pathInput2 - Second path string or PathArray
1545
+ * @param initialCfg - Configuration options for equalization
1546
+ * @returns Tuple of two equalized PathArrays
1547
+ *
1548
+ * @example
1549
+ * ```ts
1550
+ * const [eq1, eq2] = equalize('M0 0L100 0L50 100Z', 'M0 0L100 0L100 100L0 100Z')
1551
+ * // eq1.length === eq2.length — ready for morphing
1552
+ * ```
1553
+ */
1554
+ declare const equalize: (pathInput1: string | PathArray, pathInput2: string | PathArray, initialCfg?: EqualizeOptions) => [PathArray, PathArray];
1555
+ /**
1556
+ * Resamples a path to a given number of points, spread evenly by length.
1557
+ *
1558
+ * The path is measured along its length and the points of the result are
1559
+ * spread evenly over it, so the distance between two points of the result
1560
+ * is the same over the whole path. The source segment boundaries are points
1561
+ * of the result too, so the shape of the path keeps its vertices.
1562
+ *
1563
+ * Every sub-path of the path is resampled on its own, so the sub-paths of
1564
+ * the result are the sub-paths of the source: a path with several sub-paths
1565
+ * keeps its shape, the points of a sub-path are not shared with the others.
1566
+ *
1567
+ * The result is a polyline, or a path of cubic Bezier segments when the
1568
+ * curve mode is used. Every cubic of the result is the exact piece of the
1569
+ * source curve between two knots.
1570
+ *
1571
+ * @param pathInput - the target path string or PathArray
1572
+ * @param count - the number of points of every sub-path of the result
1573
+ * @param mode - the type of the segments of the result
1574
+ * @returns the resampled path
1575
+ *
1576
+ * @example
1577
+ * ```ts
1578
+ * resamplePath("M0 0L100 0L100 100", 3)
1579
+ * // => [['M', 0, 0], ['L', 100, 0], ['L', 100, 100]]
1580
+ * ```
1581
+ */
1582
+ declare const resamplePath: (pathInput: string | PathArray, count: number, mode?: "line" | "curve") => PathArray;
1293
1583
  /**
1294
1584
  * Finds intersection points between two paths.
1295
1585
  *
@@ -1406,6 +1696,65 @@ export declare class SVGPathCommander {
1406
1696
  x: number;
1407
1697
  y: number;
1408
1698
  };
1699
+ /**
1700
+ * Returns the properties of the path at a given length: the segment, the
1701
+ * point at that length, the unit tangent vector, the unit normal vector
1702
+ * and the angle of the tangent in degrees.
1703
+ *
1704
+ * @example
1705
+ * ```ts
1706
+ * new SVGPathCommander('M0 0L100 0').getPropertiesAtLength(50)
1707
+ * // => { segment: ['L', 100, 0], index: 1, length: 100, lengthAtSegment: 0,
1708
+ * // point: { x: 50, y: 0 }, tangent: { x: 1, y: 0 },
1709
+ * // normal: { x: 0, y: 1 }, angle: 0 }
1710
+ * ```
1711
+ *
1712
+ * @public
1713
+ * @param length the length
1714
+ * @returns the requested properties
1715
+ */
1716
+ getPropertiesAtLength(length: number): SegmentProperties;
1717
+ /**
1718
+ * Checks if a given point is inside the path.
1719
+ *
1720
+ * The path is flattened into polygons and the point is tested against them
1721
+ * with the fill rule of the path: the `nonzero` rule counts the windings
1722
+ * of the polygons around the point, the `evenodd` rule counts the
1723
+ * crossings of the polygons with a ray from the point. A point on the
1724
+ * boundary of the shape is inside of it.
1725
+ *
1726
+ * @example
1727
+ * ```ts
1728
+ * new SVGPathCommander('M0 0L100 0L100 100L0 100Z').isPointInPath({ x: 50, y: 50 })
1729
+ * // => true
1730
+ * ```
1731
+ *
1732
+ * @public
1733
+ * @param point the given `{x,y}` point
1734
+ * @param options the options of the test
1735
+ * @returns the query result
1736
+ */
1737
+ isPointInPath(point: Point, options?: PointInPathOptions): boolean;
1738
+ /**
1739
+ * Checks if a given point is in the stroke of the path.
1740
+ *
1741
+ * Without a width the point has to be on the path itself, within the
1742
+ * distance epsilon of it. With a width the stroke is the band around the
1743
+ * path: the point is in the stroke when it is at most half the width away
1744
+ * from the path.
1745
+ *
1746
+ * @example
1747
+ * ```ts
1748
+ * new SVGPathCommander('M0 0L100 0').isPointInStroke({ x: 50, y: 5 }, { width: 10 })
1749
+ * // => true
1750
+ * ```
1751
+ *
1752
+ * @public
1753
+ * @param point the given `{x,y}` point
1754
+ * @param options the options of the test
1755
+ * @returns the query result
1756
+ */
1757
+ isPointInStroke(point: Point, options?: StrokeOptions): boolean;
1409
1758
  /**
1410
1759
  * Convert path to absolute values.
1411
1760
  *
@@ -1439,7 +1788,7 @@ export declare class SVGPathCommander {
1439
1788
  * @example
1440
1789
  * ```ts
1441
1790
  * new SVGPathCommander('M10 50q15 -25 30 0').toCurve().toString()
1442
- * // => 'M10 50C25 25 40 50 40 50'
1791
+ * // => 'M10 50C20 33.3333 30 33.3333 40 50'
1443
1792
  * ```
1444
1793
  *
1445
1794
  * @returns this for chaining
@@ -1460,6 +1809,38 @@ export declare class SVGPathCommander {
1460
1809
  * @public
1461
1810
  */
1462
1811
  reverse(onlySubpath?: boolean): this;
1812
+ /**
1813
+ * Reverse the sub-path at a given index of the path.
1814
+ *
1815
+ * The other sub-paths are left untouched.
1816
+ *
1817
+ * @example
1818
+ * ```ts
1819
+ * new SVGPathCommander('M0 0L100 0ZM0 100L100 100').reverseSubPath(1).toString()
1820
+ * // => 'M0 0L100 0ZM100 100L0 100'
1821
+ * ```
1822
+ *
1823
+ * @param index - the zero-based index of the sub-path to reverse
1824
+ * @returns this for chaining
1825
+ * @public
1826
+ */
1827
+ reverseSubPath(index: number): this;
1828
+ /**
1829
+ * Join another path to the path of the instance.
1830
+ *
1831
+ * The result holds two sub-paths and absolute values.
1832
+ *
1833
+ * @example
1834
+ * ```ts
1835
+ * new SVGPathCommander('M0 0L100 0').join('M0 100L100 100').toString()
1836
+ * // => 'M0 0L100 0M0 100L100 100'
1837
+ * ```
1838
+ *
1839
+ * @param path - the path string or `PathArray` to join
1840
+ * @returns this for chaining
1841
+ * @public
1842
+ */
1843
+ join(path: string | PathArray): this;
1463
1844
  /**
1464
1845
  * Normalize path in 2 steps:
1465
1846
  * * convert `pathArray`(s) to absolute values
@@ -1468,7 +1849,7 @@ export declare class SVGPathCommander {
1468
1849
  * @example
1469
1850
  * ```ts
1470
1851
  * new SVGPathCommander('M10 90s20 -80 40 -80s20 80 40 80').normalize().toString()
1471
- * // => 'M10 90C30 90 25 10 50 10C75 10 70 90 90 90'
1852
+ * // => 'M10 90C10 90 30 10 50 10C70 10 70 90 90 90'
1472
1853
  * ```
1473
1854
  *
1474
1855
  * @returns this for chaining
@@ -1491,6 +1872,51 @@ export declare class SVGPathCommander {
1491
1872
  * @public
1492
1873
  */
1493
1874
  optimize(): this;
1875
+ /**
1876
+ * Simplify a path within a geometric tolerance.
1877
+ *
1878
+ * Straight-line runs are reduced with Douglas-Peucker. Curve runs are
1879
+ * fitted with cubic Béziers, while arcs and original curves are preserved
1880
+ * whenever fitting would not reduce the segment count.
1881
+ *
1882
+ * @example
1883
+ * ```ts
1884
+ * new SVGPathCommander('M0 0L10 0L20 0L30 0').simplify(1).toString()
1885
+ * // => 'M0 0L30 0'
1886
+ * ```
1887
+ *
1888
+ * @param options - the tolerance of the simplification, or the options
1889
+ * @returns this for chaining
1890
+ * @public
1891
+ */
1892
+ simplify(options?: number | SimplifyOptions): this;
1893
+ /**
1894
+ * Offset the path along its normals.
1895
+ *
1896
+ * The path is sampled along its length, every sample is shifted along the
1897
+ * normal of the path and the result is a path of straight lines. The
1898
+ * corners of the path are joined and the ends of an open path are capped.
1899
+ *
1900
+ * The `side` option is literal: the left side is the left normal of the
1901
+ * direction of travel, the same normal `getPropertiesAtLength()` returns.
1902
+ * The `both` side is the outline of the stroke, the band between the two
1903
+ * sides of the path.
1904
+ *
1905
+ * The offset is not cleaned up: an offset distance larger than the local
1906
+ * radius of curvature of the path produces a self-crossing curve.
1907
+ *
1908
+ * @example
1909
+ * ```ts
1910
+ * new SVGPathCommander('M0 0L100 0').offset(10).toString()
1911
+ * // => 'M0 10L100 10'
1912
+ * ```
1913
+ *
1914
+ * @param distance - the offset distance
1915
+ * @param options - the options of the offset
1916
+ * @returns this for chaining
1917
+ * @public
1918
+ */
1919
+ offset(distance: number, options?: OffsetOptions): this;
1494
1920
  /**
1495
1921
  * Transform path using values from an `Object` defined as `transformObject`.
1496
1922
  *
@@ -1727,6 +2153,8 @@ export declare class SVGPathCommander {
1727
2153
  static isPathArray: typeof isPathArray;
1728
2154
  /** Checks if a given point is in the stroke of a path. */
1729
2155
  static isPointInStroke: typeof isPointInStroke;
2156
+ /** Checks if a given point is inside a path. */
2157
+ static isPointInPath: typeof isPointInPath;
1730
2158
  /** Iterates an array to check if it's a `pathArray` */
1731
2159
  static isRelativeArray: typeof isRelativeArray;
1732
2160
  /** Parses a path string value to determine its validity */
@@ -1753,6 +2181,8 @@ export declare class SVGPathCommander {
1753
2181
  static normalizePath: typeof normalizePath;
1754
2182
  /** Normalizes a single segment of a `pathArray` object. */
1755
2183
  static normalizeSegment: typeof normalizeSegment;
2184
+ /** Offsets a path along its normals. */
2185
+ static offsetPath: typeof offsetPath;
1756
2186
  /** Optimizes a PathArray: */
1757
2187
  static optimizePath: typeof optimizePath;
1758
2188
  /** Transforms a specified point using a matrix, returning a new */
@@ -1765,6 +2195,10 @@ export declare class SVGPathCommander {
1765
2195
  static reverseCurve: typeof reverseCurve;
1766
2196
  /** Reverses all segments of a PathArray and returns a new PathArray */
1767
2197
  static reversePath: typeof reversePath;
2198
+ /** Reverses the sub-path at a given index of a path. */
2199
+ static reverseSubPath: typeof reverseSubPath;
2200
+ /** Joins two paths into a single path with two sub-paths. */
2201
+ static joinPath: typeof joinPath;
1768
2202
  /** Rounds the values of a `pathArray` instance to */
1769
2203
  static roundPath: typeof roundPath;
1770
2204
  /** Rounds the numeric values of a path segment to the specified precision. */
@@ -1773,12 +2207,18 @@ export declare class SVGPathCommander {
1773
2207
  static segmentToCubic: typeof segmentToCubic;
1774
2208
  /** Shorten a single segment of a `pathArray` object. */
1775
2209
  static shortenSegment: typeof shortenSegment;
2210
+ /** Simplifies straight-line runs and curve runs while preserving sub-paths and closures. */
2211
+ static simplifyPath: typeof simplifyPath;
1776
2212
  /** Split a path string or PathArray into an array of sub-paths. */
1777
2213
  static splitPath: typeof splitPath;
1778
2214
  /** Equalizes two paths for morphing (single/multi subpath). */
1779
2215
  static equalizePaths: typeof equalizePaths;
1780
2216
  /** Equalizes two paths for morphing (single subpath only). */
1781
2217
  static equalizeSegments: typeof equalizeSegments;
2218
+ /** Equalizes two paths for morphing, the recommended entry point. */
2219
+ static equalize: typeof equalize;
2220
+ /** Resamples a path to a given number of points, spread evenly by length. */
2221
+ static resamplePath: typeof resamplePath;
1782
2222
  /** Split a cubic Bézier into two cubics at parameter t [0–1]. */
1783
2223
  static splitCubicSegment: typeof splitCubicSegment;
1784
2224
  /** Apply a 2D / 3D transformation to a PathArray. */