svg-path-commander 2.3.5 → 2.4.1

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