svg-path-commander 2.4.0 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +11 -11
- package/dist/index.d.ts +0 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -21
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +1 -1
- package/dist/util.d.ts +0 -5
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +15 -20
- package/dist/util.js.map +1 -1
- package/package.json +8 -17
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","names":["findSegmentIndex","toSegments","reverseSubPath","distanceEpsilon"],"sources":["../src/math/lineTools.ts","../src/math/bezier.ts","../src/math/arcTools.ts","../src/math/cubicTools.ts","../src/math/quadTools.ts","../src/math/distanceSquareRoot.ts","../src/math/polygonTools.ts","../src/math/midPoint.ts","../src/math/rotateVector.ts","../src/math/roundTo.ts","../src/parser/paramsCount.ts","../src/parser/finalizeSegment.ts","../src/util/error.ts","../src/parser/scanFlag.ts","../src/parser/isDigit.ts","../src/parser/invalidPathValue.ts","../src/parser/scanParam.ts","../src/parser/isSpace.ts","../src/parser/skipSpaces.ts","../src/parser/isPathCommand.ts","../src/parser/isDigitStart.ts","../src/parser/isArcCommand.ts","../src/parser/isMoveCommand.ts","../src/parser/scanSegment.ts","../src/parser/pathParser.ts","../src/parser/parsePathString.ts","../src/process/absolutizeSegment.ts","../src/process/iterate.ts","../src/convert/pathToAbsolute.ts","../src/process/relativizeSegment.ts","../src/convert/pathToRelative.ts","../src/process/lineToCubic.ts","../src/process/arcToCubic.ts","../src/process/quadToCubic.ts","../src/process/segmentToCubic.ts","../src/process/normalizeSegment.ts","../src/parser/paramsParser.ts","../src/convert/pathToCurve.ts","../src/options/options.ts","../src/convert/pathToString.ts","../src/util/getPathBBox.ts","../src/util/measureSegments.ts","../src/util/getTotalLength.ts","../src/util/distanceEpsilon.ts","../src/util/pathLengthTable.ts","../src/util/segmentFrame.ts","../src/util/getPropertiesAtLength.ts","../src/util/getPropertiesAtPoint.ts","../src/util/getClosestPoint.ts","../src/util/getPathArea.ts","../src/util/getDrawDirection.ts","../src/process/normalizePath.ts","../src/util/getPointAtLength.ts","../src/util/getSegmentAtLength.ts","../src/util/getSegmentOfPoint.ts","../src/util/isPathArray.ts","../src/util/isAbsoluteArray.ts","../src/util/isNormalizedArray.ts","../src/util/isCurveArray.ts","../src/util/isPointInStroke.ts","../src/process/flattenPath.ts","../src/math/distanceToSegment.ts","../src/math/pointInPolygon.ts","../src/util/isPointInPath.ts","../src/util/isPolygonArray.ts","../src/util/isPolylineArray.ts","../src/util/isRelativeArray.ts","../src/util/isValidPath.ts","../src/util/isMultiPath.ts","../src/util/isClosedPath.ts","../src/util/shapeParams.ts","../src/util/isElement.ts","../src/util/shapeToPathArray.ts","../src/util/shapeToPath.ts","../src/process/offsetNodes.ts","../src/process/offsetJoin.ts","../src/process/offsetPath.ts","../src/process/shortenSegment.ts","../src/process/roundSegment.ts","../src/process/segmentStringLength.ts","../src/process/optimizePath.ts","../src/process/joinPath.ts","../src/process/reversePath.ts","../src/process/splitPath.ts","../src/process/reverseSubPath.ts","../src/process/getSVGMatrix.ts","../src/process/projection2d.ts","../src/process/transformPath.ts","../src/process/reverseCurve.ts","../src/process/roundPath.ts","../src/process/splitSubPaths.ts","../src/process/samplePath.ts","../src/process/douglasPeucker.ts","../src/process/fitCubic.ts","../src/process/simplifyPath.ts","../src/morph/fixPath.ts","../src/morph/splitCubicSegment.ts","../src/morph/pathToPolyline.ts","../src/morph/splitLineToCount.ts","../src/morph/getPathSplits.ts","../src/morph/splitLinePathToCount.ts","../src/morph/splitCubicToCount.ts","../src/morph/splitCurvePathToCount.ts","../src/morph/samplePolygon.ts","../src/morph/getRotatedPath.ts","../src/morph/resamplePath.ts","../src/morph/equalizeSegments.ts","../src/intersect/isPointInsideBBox.ts","../src/intersect/boundingBoxIntersect.ts","../src/morph/createPlaceholder.ts","../src/morph/matchPaths.ts","../src/morph/classifyPaths.ts","../src/morph/equalizePaths.ts","../src/morph/equalize.ts","../src/intersect/interHelper.ts","../src/intersect/pathIntersection.ts"],"sourcesContent":["/**\n * Returns length for line segments (MoveTo, LineTo).\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns the line segment length\n */\nconst getLineLength = (x1: number, y1: number, x2: number, y2: number): number => {\n const dx = x1 - x2;\n const dy = y1 - y2;\n return Math.sqrt(dx * dx + dy * dy);\n};\n\n/**\n * Returns a point along the line segments (MoveTo, LineTo).\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @param distance the distance to point in [0-1] range\n * @returns the point at length\n */\nconst getPointAtLineLength = (\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n distance?: number,\n): { x: number; y: number } => {\n let point = { x: x1, y: y1 };\n\n /* istanbul ignore else */\n if (typeof distance === \"number\") {\n const length = getLineLength(x1, y1, x2, y2);\n if (distance <= 0) {\n point = { x: x1, y: y1 };\n } else if (distance >= length) {\n point = { x: x2, y: y2 };\n } else {\n const ratio = distance / length;\n point = { x: x1 + (x2 - x1) * ratio, y: y1 + (y2 - y1) * ratio };\n }\n }\n return point;\n};\n\n/**\n * Returns bounding box for line segments (MoveTo, LineTo).\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns the bounding box for line segments\n */\nconst getLineBBox = (\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n): [number, number, number, number] => {\n const { min, max } = Math;\n\n return [min(x1, x2), min(y1, y2), max(x1, x2), max(y1, y2)] as [number, number, number, number];\n};\n\n/** The tools for line segment computation. */\nconst lineTools = {\n getLineBBox,\n getLineLength,\n getPointAtLineLength,\n};\n\nexport { getLineBBox, getLineLength, getPointAtLineLength, lineTools };\n","import type {\n CubicCoordinates,\n CubicPoints,\n DeriveCallback,\n DerivedCubicPoints,\n DerivedPoint,\n DerivedQuadPoints,\n PointTuple,\n QuadCoordinates,\n QuadPoints,\n} from \"../types.ts\";\n\n/**\n * Tools from bezier.js by Mike 'Pomax' Kamermans\n * @see https://github.com/Pomax/bezierjs\n */\n\nconst Tvalues = [\n -0.06405689286260563, 0.06405689286260563, -0.1911188674736163, 0.1911188674736163,\n -0.3150426796961634, 0.3150426796961634, -0.4337935076260451, 0.4337935076260451,\n -0.5454214713888396, 0.5454214713888396, -0.6480936519369755, 0.6480936519369755,\n -0.7401241915785544, 0.7401241915785544, -0.820001985973903, 0.820001985973903,\n -0.8864155270044011, 0.8864155270044011, -0.9382745520027328, 0.9382745520027328,\n -0.9747285559713095, 0.9747285559713095, -0.9951872199970213, 0.9951872199970213,\n];\n\n/** The weights for the 32-point Gauss-Legendre quadrature. */\nconst Cvalues = [\n 0.12793819534675216, 0.12793819534675216, 0.1258374563468283, 0.1258374563468283,\n 0.12167047292780339, 0.12167047292780339, 0.1155056680537256, 0.1155056680537256,\n 0.10744427011596563, 0.10744427011596563, 0.09761865210411388, 0.09761865210411388,\n 0.08619016153195327, 0.08619016153195327, 0.0733464814110803, 0.0733464814110803,\n 0.05929858491543678, 0.05929858491543678, 0.04427743881741981, 0.04427743881741981,\n 0.028531388628933663, 0.028531388628933663, 0.0123412297999872, 0.0123412297999872,\n];\n\n/**\n * @param points\n * @returns\n */\nconst deriveBezier = (\n points: QuadPoints | CubicPoints,\n): (DerivedQuadPoints | DerivedCubicPoints)[] => {\n const dpoints = [] as (DerivedCubicPoints | DerivedQuadPoints)[];\n for (let p = points, d = p.length, c = d - 1; d > 1; d -= 1, c -= 1) {\n const list = [] as unknown as DerivedCubicPoints | DerivedQuadPoints;\n for (let j = 0; j < c; j += 1) {\n list.push({\n x: c * (p[j + 1].x - p[j].x),\n y: c * (p[j + 1].y - p[j].y),\n t: 0,\n });\n }\n dpoints.push(list);\n p = list;\n }\n return dpoints;\n};\n\n/**\n * @param points\n * @param t\n */\nconst computeBezier = (points: DerivedQuadPoints | DerivedCubicPoints, t: number): DerivedPoint => {\n // shortcuts\n /* istanbul ignore next */\n if (t === 0) {\n points[0].t = 0;\n return points[0];\n }\n\n const order = points.length - 1;\n\n /* istanbul ignore next */\n if (t === 1) {\n points[order].t = 1;\n return points[order];\n }\n\n const mt = 1 - t;\n let p = points as typeof points | [DerivedPoint, DerivedPoint, DerivedPoint, DerivedPoint];\n\n // constant?\n /* istanbul ignore next */\n if (order === 0) {\n points[0].t = t;\n return points[0];\n }\n\n // linear?\n /* istanbul ignore else */\n if (order === 1) {\n return {\n x: mt * p[0].x + t * p[1].x,\n y: mt * p[0].y + t * p[1].y,\n t,\n };\n }\n\n // quadratic/cubic curve?\n const mt2 = mt * mt;\n const t2 = t * t;\n let a = 0;\n let b = 0;\n let c = 0;\n let d = 0;\n /* istanbul ignore else */\n if (order === 2) {\n p = [p[0], p[1], p[2], { x: 0, y: 0 } as DerivedPoint];\n a = mt2;\n b = mt * t * 2;\n c = t2;\n } else if (order === 3) {\n a = mt2 * mt;\n b = mt2 * t * 3;\n c = mt * t2 * 3;\n d = t * t2;\n }\n return {\n x: a * p[0].x + b * p[1].x + c * p[2].x + d * p[3].x,\n y: a * p[0].y + b * p[1].y + c * p[2].y + d * p[3].y,\n t,\n };\n};\n\n/**\n * Calculates the speed (derivative magnitude) of a Bezier curve at parameter `t`.\n *\n * @param derivativeFn the curve derivative function\n * @param t the sampled point ratio in `[0-1]`\n * @returns the curve speed at parameter `t`\n */\nconst calculateBezier = (derivativeFn: DeriveCallback, t: number): number => {\n const d = derivativeFn(t);\n const l = d.x * d.x + d.y * d.y;\n\n return Math.sqrt(l);\n};\n\n/**\n * Returns the total arc length of a Bezier segment.\n *\n * @param derivativeFn the curve derivative function\n * @returns the total arc length\n */\nconst bezierLength = (derivativeFn: DeriveCallback): number => {\n return bezierLengthAtT(derivativeFn, 1);\n};\n\n/**\n * Returns the arc length of a Bezier segment from its start point\n * up to a given `t` ratio, by integrating the curve speed `|B'(t)|`\n * over the `[0, t]` interval with Gauss-Legendre quadrature.\n *\n * @param derivativeFn the curve derivative function\n * @param t the sampled point ratio in `[0-1]`\n * @returns the arc length up to parameter `t`\n */\nconst bezierLengthAtT = (derivativeFn: DeriveCallback, t: number): number => {\n const z = t / 2;\n const len = Tvalues.length;\n\n let sum = 0;\n\n for (let i = 0, tMid; i < len; i++) {\n tMid = z * Tvalues[i] + z;\n sum += Cvalues[i] * calculateBezier(derivativeFn, tMid);\n }\n return z * sum;\n};\n\n/**\n * Returns the speed of a Bezier segment at a given ratio, without allocating\n * a point for it.\n *\n * The quadrature of the length samples the speed of the curve at every one of\n * its points, and a point per sample is a lot of garbage for a long path. The\n * arithmetic is the one of `computeBezier`, so the length of a curve is the\n * same.\n *\n * @param points the control points of the derivative of the curve\n * @param t the sampled point ratio\n * @returns the speed of the curve at the ratio\n */\nconst bezierSpeed = (points: DerivedQuadPoints | DerivedCubicPoints, t: number): number => {\n const order = points.length - 1;\n const mt = 1 - t;\n\n // a linear derivative, the derivative of a quadratic\n if (order === 1) {\n const x = mt * points[0].x + t * points[1].x;\n const y = mt * points[0].y + t * points[1].y;\n return Math.sqrt(x * x + y * y);\n }\n\n // a quadratic derivative, the derivative of a cubic\n if (order === 2) {\n const mt2 = mt * mt;\n const t2 = t * t;\n const a = mt2;\n const b = mt * t * 2;\n const c = t2;\n const x = a * points[0].x + b * points[1].x + c * points[2].x;\n const y = a * points[0].y + b * points[1].y + c * points[2].y;\n return Math.sqrt(x * x + y * y);\n }\n\n // any other derivative is computed the general way\n const d = computeBezier(points, t);\n return Math.sqrt(d.x * d.x + d.y * d.y);\n};\n\n/**\n * Returns the arc length of a Bezier segment from its start point\n * up to a given `t` ratio, from the control points of its derivative.\n *\n * The integration of the speed `|B'(t)|` over the `[0, t]` interval is done\n * with the Gauss-Legendre quadrature, and the speed is computed without\n * allocating a point for it.\n *\n * @param points the control points of the derivative of the curve\n * @param t the sampled point ratio in `[0-1]`\n * @returns the arc length up to parameter `t`\n */\nconst bezierLengthAtPoints = (\n points: DerivedQuadPoints | DerivedCubicPoints,\n t: number,\n): number => {\n const z = t / 2;\n const len = Tvalues.length;\n\n let sum = 0;\n\n for (let i = 0, tMid; i < len; i++) {\n tMid = z * Tvalues[i] + z;\n sum += Cvalues[i] * bezierSpeed(points, tMid);\n }\n return z * sum;\n};\n\n/**\n * Builds the Bezier points array from a curve coordinates array.\n * @param curve cubic / quad bezier segment\n */\nconst getBezierPoints = (curve: CubicCoordinates | QuadCoordinates): CubicPoints | QuadPoints => {\n const points = [] as unknown as CubicPoints | QuadPoints;\n for (let idx = 0, len = curve.length, step = 2; idx < len; idx += step) {\n points.push({\n x: curve[idx],\n y: curve[idx + 1],\n });\n }\n return points;\n};\n\n/**\n * Returns the arc length of a Bezier segment from its start point\n * up to a given `t` ratio, for the segment given by its coordinates.\n *\n * @param curve cubic / quad bezier segment\n * @param t the sampled point ratio in `[0-1]`\n * @returns the arc length up to parameter `t`\n */\nconst getBezierLengthAtT = (curve: CubicCoordinates | QuadCoordinates, t: number): number => {\n const dpoints = deriveBezier(getBezierPoints(curve));\n return bezierLengthAtPoints(dpoints[0], t);\n};\n\n/**\n * Returns the `t` parameter of a Bezier segment at which the cumulative\n * arc length equals the given `distance`, found by interval bisection.\n *\n * @param curve cubic / quad bezier segment\n * @param distance the distance along the segment in `[0, length]`\n * @returns the `t` parameter in `[0-1]`\n */\nconst getTAtBezierLength = (\n curve: CubicCoordinates | QuadCoordinates,\n distance: number,\n): number => {\n const dpoints = deriveBezier(getBezierPoints(curve));\n const points = dpoints[0];\n let lo = 0;\n let hi = 1;\n for (let i = 0; i < 25; i += 1) {\n const mid = (lo + hi) / 2;\n if (bezierLengthAtPoints(points, mid) < distance) {\n lo = mid;\n } else {\n hi = mid;\n }\n }\n return (lo + hi) / 2;\n};\n\n/**\n * Returns the length of CubicBezier / Quad segment.\n * @param curve cubic / quad bezier segment\n */\nconst getBezierLength = (curve: CubicCoordinates | QuadCoordinates): number => {\n const points = getBezierPoints(curve);\n const dpoints = deriveBezier(points);\n return bezierLengthAtPoints(dpoints[0], 1);\n};\n\n// Precision for consider cubic polynom as quadratic one\n/** The precision threshold to consider a cubic polynomial as quadratic. */\nconst CBEZIER_MINMAX_EPSILON = 0.00000001;\n\n/**\n * Returns the most extreme points in a Quad Bezier segment.\n * @param A an array which consist of X/Y values\n */\n// https://github.com/kpym/SVGPathy/blob/acd1a50c626b36d81969f6e98e8602e128ba4302/lib/box.js#L89\nconst minmaxQ = ([v1, cp, v2]: [number, number, number]): PointTuple => {\n const min = Math.min(v1, v2);\n const max = Math.max(v1, v2);\n\n /* istanbul ignore next */\n if (cp >= v1 ? v2 >= cp : v2 <= cp) {\n // if no extremum in ]0,1[\n return [min, max] as PointTuple;\n }\n\n // check if the extremum E is min or max\n const E = (v1 * v2 - cp * cp) / (v1 - 2 * cp + v2);\n return (E < min ? [E, max] : [min, E]) as PointTuple;\n};\n\n/**\n * Returns the most extreme points in a Cubic Bezier segment.\n * @param A an array which consist of X/Y values\n * @see https://github.com/kpym/SVGPathy/blob/acd1a50c626b36d81969f6e98e8602e128ba4302/lib/box.js#L127\n */\nconst minmaxC = ([v1, cp1, cp2, v2]: [number, number, number, number]): PointTuple => {\n const K = v1 - 3 * cp1 + 3 * cp2 - v2;\n\n // if the polynomial is (almost) quadratic and not cubic\n /* istanbul ignore next */\n if (Math.abs(K) < CBEZIER_MINMAX_EPSILON) {\n if (v1 === v2 && v1 === cp1) {\n // no curve, point targeting same location\n return [v1, v2] as PointTuple;\n }\n\n return minmaxQ([v1, -0.5 * v1 + 1.5 * cp1, v1 - 3 * cp1 + 3 * cp2]);\n }\n\n // the reduced discriminant of the derivative\n const T = -v1 * cp2 + v1 * v2 - cp1 * cp2 - cp1 * v2 + cp1 * cp1 + cp2 * cp2;\n\n // if the polynomial is monotone in [0,1]\n if (T <= 0) {\n return [Math.min(v1, v2), Math.max(v1, v2)] as PointTuple;\n }\n const S = Math.sqrt(T);\n\n // potential extrema\n let min = Math.min(v1, v2);\n let max = Math.max(v1, v2);\n\n const L = v1 - 2 * cp1 + cp2;\n // check local extrema\n for (let R = (L + S) / K, i = 1; i <= 2; R = (L - S) / K, i++) {\n // istanbul ignore next\n if (R > 0 && R < 1) {\n // if the extrema is for R in [0,1]\n const Q =\n v1 * (1 - R) * (1 - R) * (1 - R) +\n cp1 * 3 * (1 - R) * (1 - R) * R +\n cp2 * 3 * (1 - R) * R * R +\n v2 * R * R * R;\n if (Q < min) {\n min = Q;\n }\n if (Q > max) {\n max = Q;\n }\n }\n }\n\n return [min, max] as PointTuple;\n};\n/** The tools for Bezier curve computation. */\nconst bezierTools = {\n bezierLength,\n bezierLengthAtT,\n calculateBezier,\n CBEZIER_MINMAX_EPSILON,\n computeBezier,\n Cvalues,\n deriveBezier,\n getBezierLength,\n getBezierLengthAtT,\n getBezierPoints,\n getTAtBezierLength,\n minmaxC,\n minmaxQ,\n Tvalues,\n};\n\nexport {\n bezierLength,\n bezierLengthAtT,\n bezierTools,\n calculateBezier,\n CBEZIER_MINMAX_EPSILON,\n computeBezier,\n Cvalues,\n deriveBezier,\n getBezierLength,\n getBezierLengthAtT,\n getBezierPoints,\n getTAtBezierLength,\n minmaxC,\n minmaxQ,\n Tvalues,\n};\n","import { getPointAtLineLength } from \"./lineTools.ts\";\nimport { Cvalues, Tvalues } from \"./bezier.ts\";\nimport type { Point, PointTuple } from \"../types.ts\";\n\n/**\n * Returns the signed arc length of an ellipse segment from angle `0` up to\n * the given `theta` angle, by integrating the curve speed\n * `|sqrt(rx^2 * sin^2(phi) + ry^2 * cos^2(phi))|` over the `[0, theta]`\n * interval with Gauss-Legendre quadrature.\n *\n * @param rx radius along X axis\n * @param ry radius along Y axis\n * @param theta the angle in radians\n * @returns the signed arc length\n */\nconst arcLengthAtAngle = (rx: number, ry: number, theta: number): number => {\n const sign = theta < 0 ? -1 : 1;\n const absTheta = Math.abs(theta);\n const step = Math.PI / 2;\n\n let total = 0;\n let remaining = absTheta;\n let offset = 0;\n\n while (remaining > 0) {\n const span = Math.min(step, remaining);\n const z = span / 2;\n\n let sum = 0;\n for (let i = 0, len = Tvalues.length; i < len; i += 1) {\n const phi = offset + z * Tvalues[i] + z;\n sum += Cvalues[i] * Math.sqrt((rx * Math.sin(phi)) ** 2 + (ry * Math.cos(phi)) ** 2);\n }\n total += z * sum;\n offset += span;\n remaining -= span;\n }\n return sign * total;\n};\n\n/**\n * Returns the signed arc length of an ellipse segment between two angles.\n * @param rx radius along X axis\n * @param ry radius along Y axis\n * @param from the start angle in radians\n * @param to the end angle in radians\n * @returns the signed arc length\n */\nconst arcLengthBetween = (rx: number, ry: number, from: number, to: number): number => {\n return arcLengthAtAngle(rx, ry, to) - arcLengthAtAngle(rx, ry, from);\n};\n\n/**\n * Returns the Arc segment length.\n * @param rx radius along X axis\n * @param ry radius along Y axis\n * @param theta the angle in radians\n * @returns the arc length\n */\nconst arcLength = (rx: number, ry: number, theta: number): number => {\n return Math.abs(arcLengthAtAngle(rx, ry, theta));\n};\n\n/**\n * Find point on ellipse at given angle around ellipse (theta);\n * @param cx the center X\n * @param cy the center Y\n * @param rx the radius X\n * @param ry the radius Y\n * @param alpha the arc rotation angle in radians\n * @param theta the arc sweep angle in radians\n * @returns a point around ellipse at given angle\n */\nconst arcPoint = (\n cx: number,\n cy: number,\n rx: number,\n ry: number,\n alpha: number,\n theta: number,\n): PointTuple => {\n const { sin, cos } = Math;\n // theta is angle in radians around arc\n // alpha is angle of rotation of ellipse in radians\n const cosA = cos(alpha);\n const sinA = sin(alpha);\n const x = rx * cos(theta);\n const y = ry * sin(theta);\n\n return [cx + cosA * x - sinA * y, cy + sinA * x + cosA * y] as PointTuple;\n};\n\n/**\n * Returns the angle between two points.\n * @param v0 starting point\n * @param v1 ending point\n * @returns the angle in radian\n */\nconst angleBetween = (v0: Point, v1: Point): number => {\n const { x: v0x, y: v0y } = v0;\n const { x: v1x, y: v1y } = v1;\n const p = v0x * v1x + v0y * v1y;\n const n = Math.sqrt((v0x ** 2 + v0y ** 2) * (v1x ** 2 + v1y ** 2));\n const sign = v0x * v1y - v0y * v1x < 0 ? -1 : 1;\n // the cosine of an angle is in the [-1-1] range, the rounding of the\n // division can push it out of it and `acos` of a value under -1 is NaN\n return sign * Math.acos(Math.min(1, Math.max(-1, p / n)));\n};\n\n/**\n * Returns the following properties for an Arc segment: center, start angle,\n * end angle, and radiuses on X and Y axis.\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param RX the radius on X axis\n * @param RY the radius on Y axis\n * @param angle the ellipse rotation in degrees\n * @param LAF the large arc flag\n * @param SF the sweep flag\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns properties specific to Arc segments\n */\nconst getArcProps = (\n x1: number,\n y1: number,\n RX: number,\n RY: number,\n angle: number,\n LAF: number,\n SF: number,\n x: number,\n y: number,\n): {\n rx: number;\n ry: number;\n startAngle: number;\n endAngle: number;\n center: { x: number; y: number };\n} => {\n const { abs, sin, cos, sqrt, PI } = Math;\n let rx = abs(RX);\n let ry = abs(RY);\n const xRot = ((angle % 360) + 360) % 360;\n const xRotRad = xRot * (PI / 180);\n\n // istanbul ignore next\n if (x1 === x && y1 === y) {\n return {\n rx,\n ry,\n startAngle: 0,\n endAngle: 0,\n center: { x, y },\n };\n }\n\n if (rx === 0 || ry === 0) {\n return {\n rx,\n ry,\n startAngle: 0,\n endAngle: 0,\n center: { x: (x + x1) / 2, y: (y + y1) / 2 },\n };\n }\n\n const dx = (x1 - x) / 2;\n const dy = (y1 - y) / 2;\n\n const transformedPoint = {\n x: cos(xRotRad) * dx + sin(xRotRad) * dy,\n y: -sin(xRotRad) * dx + cos(xRotRad) * dy,\n };\n\n const radiiCheck = transformedPoint.x ** 2 / rx ** 2 + transformedPoint.y ** 2 / ry ** 2;\n\n if (radiiCheck > 1) {\n rx *= sqrt(radiiCheck);\n ry *= sqrt(radiiCheck);\n }\n\n const cSquareNumerator =\n rx ** 2 * ry ** 2 - rx ** 2 * transformedPoint.y ** 2 - ry ** 2 * transformedPoint.x ** 2;\n const cSquareRootDenom = rx ** 2 * transformedPoint.y ** 2 + ry ** 2 * transformedPoint.x ** 2;\n\n let cRadicand = cSquareNumerator / cSquareRootDenom;\n /* istanbul ignore next */\n cRadicand = cRadicand < 0 ? 0 : cRadicand;\n const cCoef = (LAF !== SF ? 1 : -1) * sqrt(cRadicand);\n const transformedCenter = {\n x: cCoef * ((rx * transformedPoint.y) / ry),\n y: cCoef * (-(ry * transformedPoint.x) / rx),\n };\n\n const center = {\n x: cos(xRotRad) * transformedCenter.x - sin(xRotRad) * transformedCenter.y + (x1 + x) / 2,\n y: sin(xRotRad) * transformedCenter.x + cos(xRotRad) * transformedCenter.y + (y1 + y) / 2,\n };\n\n const startVector = {\n x: (transformedPoint.x - transformedCenter.x) / rx,\n y: (transformedPoint.y - transformedCenter.y) / ry,\n };\n\n const startAngle = angleBetween({ x: 1, y: 0 }, startVector);\n\n const endVector = {\n x: (-transformedPoint.x - transformedCenter.x) / rx,\n y: (-transformedPoint.y - transformedCenter.y) / ry,\n };\n\n let sweepAngle = angleBetween(startVector, endVector);\n if (!SF && sweepAngle > 0) {\n sweepAngle -= 2 * PI;\n } else if (SF && sweepAngle < 0) {\n sweepAngle += 2 * PI;\n }\n sweepAngle %= 2 * PI;\n\n const endAngle = startAngle + sweepAngle;\n\n // point.ellipticalArcStartAngle = startAngle;\n // point.ellipticalArcEndAngle = startAngle + sweepAngle;\n // point.ellipticalArcAngle = alpha;\n\n // point.ellipticalArcCenter = center;\n // point.resultantRx = rx;\n // point.resultantRy = ry;\n\n return {\n center,\n startAngle,\n endAngle,\n rx,\n ry,\n };\n};\n\n/**\n * Returns the length of an Arc segment.\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param c1x the first control point X\n * @param c1y the first control point Y\n * @param c2x the second control point X\n * @param c2y the second control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns the length of the Arc segment\n */\nconst getArcLength = (\n x1: number,\n y1: number,\n RX: number,\n RY: number,\n angle: number,\n LAF: number,\n SF: number,\n x: number,\n y: number,\n): number => {\n const { abs } = Math;\n // a zero radius is treated as a straight line to the end point\n if (RX === 0 || RY === 0) {\n return abs(Math.sqrt((x - x1) ** 2 + (y - y1) ** 2));\n }\n const { rx, ry, startAngle, endAngle } = getArcProps(x1, y1, RX, RY, angle, LAF, SF, x, y);\n return Math.abs(arcLengthBetween(rx, ry, startAngle, endAngle));\n};\n\n/**\n * Returns a point along an Arc segment at a given distance.\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param RX the radius on X axis\n * @param RY the radius on Y axis\n * @param angle the ellipse rotation in degrees\n * @param LAF the large arc flag\n * @param SF the sweep flag\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @param distance the distance along the arc\n * @returns a point along the Arc segment\n */\nconst getPointAtArcLength = (\n x1: number,\n y1: number,\n RX: number,\n RY: number,\n angle: number,\n LAF: number,\n SF: number,\n x: number,\n y: number,\n distance?: number,\n): { x: number; y: number } => {\n let point = { x: x1, y: y1 };\n const { center, rx, ry, startAngle, endAngle } = getArcProps(\n x1,\n y1,\n RX,\n RY,\n angle,\n LAF,\n SF,\n x,\n y,\n );\n\n /* istanbul ignore else */\n if (typeof distance === \"number\") {\n const sweepAngle = endAngle - startAngle;\n const length = Math.abs(arcLengthBetween(rx, ry, startAngle, endAngle));\n // a zero radius is treated as a straight line to the end point\n if (rx === 0 || ry === 0) {\n return getPointAtLineLength(x1, y1, x, y, distance);\n }\n if (distance <= 0) {\n point = { x: x1, y: y1 };\n } else if (distance >= length) {\n point = { x, y };\n } else {\n const { PI, cos, sin } = Math;\n const xRot = ((angle % 360) + 360) % 360;\n const xRotRad = xRot * (PI / 180);\n\n let lo = 0;\n let hi = 1;\n for (let i = 0; i < 25; i += 1) {\n const mid = (lo + hi) / 2;\n if (\n Math.abs(arcLengthBetween(rx, ry, startAngle, startAngle + sweepAngle * mid)) < distance\n ) {\n lo = mid;\n } else {\n hi = mid;\n }\n }\n const alpha = startAngle + sweepAngle * ((lo + hi) / 2);\n const ellipseComponentX = rx * cos(alpha);\n const ellipseComponentY = ry * sin(alpha);\n\n point = {\n x: cos(xRotRad) * ellipseComponentX - sin(xRotRad) * ellipseComponentY + center.x,\n y: sin(xRotRad) * ellipseComponentX + cos(xRotRad) * ellipseComponentY + center.y,\n };\n }\n }\n\n return point;\n};\n\n/**\n * Returns the extrema for an Arc segment in the following format:\n * [MIN_X, MIN_Y, MAX_X, MAX_Y]\n *\n * @see https://github.com/herrstrietzel/svg-pathdata-getbbox\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param RX the radius on X axis\n * @param RY the radius on Y axis\n * @param angle the ellipse rotation in degrees\n * @param LAF the large arc flag\n * @param SF the sweep flag\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns the extrema of the Arc segment\n */\nconst getArcBBox = (\n x1: number,\n y1: number,\n RX: number,\n RY: number,\n angle: number,\n LAF: number,\n SF: number,\n x: number,\n y: number,\n): [number, number, number, number] => {\n const { min, max, tan, atan2, cos, PI } = Math;\n\n // an arc with the same start and end point is omitted by the spec\n if (x1 === x && y1 === y) {\n return [x1, y1, x, y];\n }\n\n // a zero radius is a straight line to the end point\n if (RX === 0 || RY === 0) {\n return [min(x1, x), min(y1, y), max(x1, x), max(y1, y)];\n }\n\n const { center, rx, ry, startAngle, endAngle } = getArcProps(\n x1,\n y1,\n RX,\n RY,\n angle,\n LAF,\n SF,\n x,\n y,\n );\n const deltaAngle = endAngle - startAngle;\n\n // circle/elipse center coordinates\n const { x: cx, y: cy } = center;\n\n // rotation to radians\n const alpha = (angle * PI) / 180;\n const tangent = tan(alpha);\n\n /**\n * find min/max from zeroes of directional derivative along x and y\n * along x axis\n */\n const theta = atan2(-ry * tangent, rx);\n const angle1 = theta;\n const angle2 = theta + PI;\n const angle3 = atan2(ry, rx * tangent);\n const angle4 = angle3 + PI;\n // the extremum points swap sides when the ellipse is rotated by more\n // than 90 degrees, the sign of `cos(alpha)` tells which one is which\n const flipped = cos(alpha) < 0;\n const rightAngle = flipped ? angle2 : angle1;\n const leftAngle = flipped ? angle1 : angle2;\n const topAngle = flipped ? angle3 : angle4;\n const bottomAngle = flipped ? angle4 : angle3;\n // the endpoints of the arc and the extrema of the ellipse it sweeps over\n const xArray = [x1, x];\n const yArray = [y1, y];\n\n // the span of the sweep and its direction\n const span = Math.abs(deltaAngle);\n const clockwise = deltaAngle >= 0;\n\n /**\n * tells if an extremum of the ellipse is on the arc, the offset of the\n * extremum is measured from the start of the arc, in the direction of\n * the sweep\n */\n const isOnArc = (extremum: number): boolean => {\n const offset = clockwise\n ? (((extremum - startAngle) % (2 * PI)) + 2 * PI) % (2 * PI)\n : (((startAngle - extremum) % (2 * PI)) + 2 * PI) % (2 * PI);\n return offset <= span + 1e-9;\n };\n\n // right\n if (isOnArc(rightAngle)) {\n const p = arcPoint(cx, cy, rx, ry, alpha, rightAngle);\n xArray.push(p[0]);\n yArray.push(p[1]);\n }\n\n // left\n if (isOnArc(leftAngle)) {\n const p = arcPoint(cx, cy, rx, ry, alpha, leftAngle);\n xArray.push(p[0]);\n yArray.push(p[1]);\n }\n\n // top\n if (isOnArc(topAngle)) {\n const p = arcPoint(cx, cy, rx, ry, alpha, topAngle);\n xArray.push(p[0]);\n yArray.push(p[1]);\n }\n\n // bottom\n if (isOnArc(bottomAngle)) {\n const p = arcPoint(cx, cy, rx, ry, alpha, bottomAngle);\n xArray.push(p[0]);\n yArray.push(p[1]);\n }\n\n return [min(...xArray), min(...yArray), max(...xArray), max(...yArray)] as [\n number,\n number,\n number,\n number,\n ];\n};\n\n/** The tools for elliptical arc computation. */\nconst arcTools = {\n angleBetween,\n arcLength,\n arcLengthAtAngle,\n arcLengthBetween,\n arcPoint,\n getArcBBox,\n getArcLength,\n getArcProps,\n getPointAtArcLength,\n};\n\nexport {\n angleBetween,\n arcLength,\n arcLengthAtAngle,\n arcLengthBetween,\n arcPoint,\n arcTools,\n getArcBBox,\n getArcLength,\n getArcProps,\n getPointAtArcLength,\n};\n","import { getBezierLength, getTAtBezierLength, minmaxC } from \"./bezier.ts\";\nimport type { BBoxMaxima, CubicCoordinates } from \"../types.ts\";\n\n/**\n * Returns a point at a given length of a CubicBezier segment.\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param c1x the first control point X\n * @param c1y the first control point Y\n * @param c2x the second control point X\n * @param c2y the second control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @param t a [0-1] ratio\n * @returns the point at cubic-bezier segment length\n */\nconst getPointAtCubicSegmentLength = (\n [x1, y1, c1x, c1y, c2x, c2y, x2, y2]: CubicCoordinates,\n t: number,\n): { x: number; y: number } => {\n const t1 = 1 - t;\n return {\n x: t1 ** 3 * x1 + 3 * t1 ** 2 * t * c1x + 3 * t1 * t ** 2 * c2x + t ** 3 * x2,\n y: t1 ** 3 * y1 + 3 * t1 ** 2 * t * c1y + 3 * t1 * t ** 2 * c2y + t ** 3 * y2,\n };\n};\n\n/**\n * Returns the length of a CubicBezier segment.\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param c1x the first control point X\n * @param c1y the first control point Y\n * @param c2x the second control point X\n * @param c2y the second control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns the CubicBezier segment length\n */\nconst getCubicLength = (\n x1: number,\n y1: number,\n c1x: number,\n c1y: number,\n c2x: number,\n c2y: number,\n x2: number,\n y2: number,\n): number => {\n return getBezierLength([x1, y1, c1x, c1y, c2x, c2y, x2, y2]);\n};\n\n/**\n * Returns the point along a CubicBezier segment at a given distance.\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param c1x the first control point X\n * @param c1y the first control point Y\n * @param c2x the second control point X\n * @param c2y the second control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @param distance the distance to look at\n * @returns the point at CubicBezier length\n */\nconst getPointAtCubicLength = (\n x1: number,\n y1: number,\n c1x: number,\n c1y: number,\n c2x: number,\n c2y: number,\n x2: number,\n y2: number,\n distance?: number,\n): { x: number; y: number } => {\n const distanceIsNumber = typeof distance === \"number\";\n let point = { x: x1, y: y1 };\n /* istanbul ignore else */\n if (distanceIsNumber) {\n const coords = [x1, y1, c1x, c1y, c2x, c2y, x2, y2] as CubicCoordinates;\n const currentLength = getBezierLength(coords);\n if (distance <= 0) {\n // first point already defined\n } else if (distance >= currentLength) {\n point = { x: x2, y: y2 };\n } else {\n const t = getTAtBezierLength(coords, distance);\n point = getPointAtCubicSegmentLength(coords, t);\n }\n }\n return point;\n};\n\n/**\n * Returns the bounding box of a CubicBezier segment in the following format:\n * [MIN_X, MIN_Y, MAX_X, MAX_Y]\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param c1x the first control point X\n * @param c1y the first control point Y\n * @param c2x the second control point X\n * @param c2y the second control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns the extrema of the CubicBezier segment\n */\nconst getCubicBBox = (\n x1: number,\n y1: number,\n c1x: number,\n c1y: number,\n c2x: number,\n c2y: number,\n x2: number,\n y2: number,\n): BBoxMaxima => {\n const cxMinMax = minmaxC([x1, c1x, c2x, x2]);\n const cyMinMax = minmaxC([y1, c1y, c2y, y2]);\n\n return [cxMinMax[0], cyMinMax[0], cxMinMax[1], cyMinMax[1]];\n};\n\n/** The tools for cubic Bezier computation. */\nconst cubicTools = {\n getCubicBBox,\n getCubicLength,\n getPointAtCubicLength,\n getPointAtCubicSegmentLength,\n};\n\nexport {\n cubicTools,\n getCubicBBox,\n getCubicLength,\n getPointAtCubicLength,\n getPointAtCubicSegmentLength,\n};\n","import { getBezierLength, getTAtBezierLength, minmaxQ } from \"./bezier.ts\";\nimport type { QuadCoordinates } from \"../types.ts\";\n\n/**\n * Returns the {x,y} coordinates of a point at a\n * given length of a quadratic-bezier segment.\n *\n * @see https://github.com/substack/point-at-length\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param cx the control point X\n * @param cy the control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @param t a [0-1] ratio\n * @returns the requested {x,y} coordinates\n */\nconst getPointAtQuadSegmentLength = (\n [x1, y1, cx, cy, x2, y2]: QuadCoordinates,\n t: number,\n): { x: number; y: number } => {\n const t1 = 1 - t;\n return {\n x: t1 ** 2 * x1 + 2 * t1 * t * cx + t ** 2 * x2,\n y: t1 ** 2 * y1 + 2 * t1 * t * cy + t ** 2 * y2,\n };\n};\n\n/**\n * Returns the length of a QuadraticBezier segment.\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param cx the control point X\n * @param cy the control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns the QuadraticBezier segment length\n */\nconst getQuadLength = (\n x1: number,\n y1: number,\n cx: number,\n cy: number,\n x2: number,\n y2: number,\n): number => {\n return getBezierLength([x1, y1, cx, cy, x2, y2]);\n};\n\n/**\n * Returns the point along a QuadraticBezier segment at a given distance.\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param cx the control point X\n * @param cy the control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @param distance the distance to look at\n * @returns the point at QuadraticBezier length\n */\nconst getPointAtQuadLength = (\n x1: number,\n y1: number,\n cx: number,\n cy: number,\n x2: number,\n y2: number,\n distance?: number,\n): { x: number; y: number } => {\n const distanceIsNumber = typeof distance === \"number\";\n let point = { x: x1, y: y1 };\n\n /* istanbul ignore else */\n if (distanceIsNumber) {\n const coords = [x1, y1, cx, cy, x2, y2] as QuadCoordinates;\n const currentLength = getBezierLength(coords);\n if (distance <= 0) {\n // first point already defined\n } else if (distance >= currentLength) {\n point = { x: x2, y: y2 };\n } else {\n const t = getTAtBezierLength(coords, distance);\n point = getPointAtQuadSegmentLength(coords, t);\n }\n }\n return point;\n};\n\n/**\n * Returns the bounding box of a QuadraticBezier segment in the following format:\n * [MIN_X, MIN_Y, MAX_X, MAX_Y]\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param cx the control point X\n * @param cy the control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns the extrema of the QuadraticBezier segment\n */\nconst getQuadBBox = (\n x1: number,\n y1: number,\n cx: number,\n cy: number,\n x2: number,\n y2: number,\n): [number, number, number, number] => {\n const cxMinMax = minmaxQ([x1, cx, x2]);\n const cyMinMax = minmaxQ([y1, cy, y2]);\n return [cxMinMax[0], cyMinMax[0], cxMinMax[1], cyMinMax[1]] as [number, number, number, number];\n};\n/** The tools for quadratic Bezier computation. */\nconst quadTools = {\n getPointAtQuadLength,\n getPointAtQuadSegmentLength,\n getQuadBBox,\n getQuadLength,\n};\n\nexport { getPointAtQuadLength, getPointAtQuadSegmentLength, getQuadBBox, getQuadLength, quadTools };\n","import type { PointTuple } from \"../types.ts\";\n\n/**\n * Returns the square root of the distance\n * between two given points.\n *\n * @param a the first point coordinates\n * @param b the second point coordinates\n * @returns the distance value\n */\nexport const distanceSquareRoot = (a: PointTuple, b: PointTuple): number => {\n return Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]));\n};\n","import { distanceSquareRoot } from \"./distanceSquareRoot.ts\";\nimport type { PointTuple } from \"../types.ts\";\n\n/**\n * d3-polygon-area\n * @see https://github.com/d3/d3-polygon\n *\n * Returns the area of a polygon.\n *\n * @param polygon Array of [x, y]\n * @returns Signed area\n */\nconst polygonArea = (polygon: PointTuple[]): number => {\n const n = polygon.length;\n let i = -1;\n let a: PointTuple;\n let b = polygon[n - 1];\n let area = 0;\n\n while (++i < n) {\n a = b;\n b = polygon[i];\n area += a[1] * b[0] - a[0] * b[1];\n }\n\n return area / 2;\n};\n\n/**\n * d3-polygon-length\n * https://github.com/d3/d3-polygon\n *\n * Returns the perimeter of a polygon.\n *\n * @param polygon an array of coordinates\n * @returns the polygon length\n */\nconst polygonLength = (polygon: PointTuple[]): number => {\n return polygon.reduce((length, point, i) => {\n if (i) {\n return length + distanceSquareRoot(polygon[i - 1], point);\n }\n return 0;\n }, 0);\n};\n\n/**\n * Computes the centroid (geometric center) of a polygon.\n * Uses average of all endpoint coordinates (robust for polygons and curves).\n *\n * @param polygon A polygon with consists of [x, y] tuples\n * @returns [x, y] centroid\n */\nconst polygonCentroid = (polygon: PointTuple[]): PointTuple => {\n if (polygon.length === 0) return [0, 0];\n\n let sumX = 0;\n let sumY = 0;\n\n for (const [x, y] of polygon) {\n sumX += x;\n sumY += y;\n }\n\n const count = polygon.length;\n return [sumX / count, sumY / count];\n};\n\n/** The tools for polygon computation. */\nconst polygonTools = {\n polygonArea,\n polygonLength,\n polygonCentroid,\n};\n\nexport { polygonArea, polygonCentroid, polygonLength, polygonTools };\n","import type { PointTuple } from \"../types.ts\";\n\n/**\n * Returns the coordinates of a specified distance\n * ratio between two points.\n *\n * @param a the first point coordinates\n * @param b the second point coordinates\n * @param t the ratio\n * @returns the midpoint coordinates\n */\nexport const midPoint = ([ax, ay]: PointTuple, [bx, by]: PointTuple, t: number): PointTuple => {\n return [ax + (bx - ax) * t, ay + (by - ay) * t];\n};\n","/**\n * Returns an {x,y} vector rotated by a given\n * angle in radian.\n *\n * @param x the initial vector x\n * @param y the initial vector y\n * @param rad the radian vector angle\n * @returns the rotated vector\n */\nexport const rotateVector = (x: number, y: number, rad: number): { x: number; y: number } => {\n const { sin, cos } = Math;\n const X = x * cos(rad) - y * sin(rad);\n const Y = x * sin(rad) + y * cos(rad);\n return { x: X, y: Y };\n};\n","/**\n * Rounds a number to the specified number of decimal places.\n *\n * @param n - The number to round\n * @param round - Number of decimal places\n * @returns The rounded number\n */\nexport const roundTo = (n: number, round: number): number => {\n const pow = round >= 1 ? 10 ** round : 1;\n\n return round > 0 ? Math.round(n * pow) / pow : Math.round(n);\n};\n","/** Segment params length */\n\nexport const paramsCounts = {\n a: 7,\n c: 6,\n h: 1,\n l: 2,\n m: 2,\n r: 4,\n q: 4,\n s: 4,\n t: 2,\n v: 1,\n z: 0,\n};\n\n/**\n * The number of parameters of every command, by character code.\n *\n * The parser looks the number of the parameters of a command up for every\n * segment it scans, and the lookup by character code spares it the\n * lowercasing of the command and the lookup of the string.\n *\n * @internal\n */\nexport const paramsCountsByCode = new Uint8Array(128);\n\nfor (const [command, count] of Object.entries(paramsCounts)) {\n const code = command.charCodeAt(0);\n paramsCountsByCode[code] = count;\n // the uppercase command is the lowercase one, 32 characters higher\n paramsCountsByCode[code - 32] = count;\n}\n","import { paramsCountsByCode } from \"./paramsCount.ts\";\nimport type { PathParser } from \"./pathParser.ts\";\nimport type { PathCommand, PathSegment } from \"../types.ts\";\n\n/**\n * Breaks the parsing of a pathString once a segment is finalized.\n *\n * @param path - The PathParser instance\n */\nexport const finalizeSegment = (path: PathParser): void => {\n let pathCommand = path.pathValue[path.segmentStart] as PathCommand;\n const { data } = path;\n let index = 0;\n // the number of parameters of the command, by character code\n let paramCount = paramsCountsByCode[pathCommand.charCodeAt(0) | 0x20];\n // a moveto is the only command that can be overloaded\n let isMove = pathCommand === \"m\" || pathCommand === \"M\";\n\n while (data.length - index >= paramCount) {\n // overloaded `moveTo`\n // https://github.com/rveciana/svg-path-properties/blob/master/src/parse.ts\n if (isMove && data.length - index > 2) {\n // oxlint-disable-next-line unicorn/no-new-array -- preallocated for a faster fill\n const segment = new Array<number | PathCommand>(3);\n segment[0] = pathCommand;\n segment[1] = data[index] as number;\n segment[2] = data[index + 1] as number;\n path.segments.push(segment as PathSegment);\n index += 2;\n isMove = false;\n pathCommand = pathCommand === \"m\" ? \"l\" : \"L\";\n // the lineto has two parameters\n paramCount = 2;\n } else {\n // oxlint-disable-next-line unicorn/no-new-array -- preallocated for a faster fill\n const segment = new Array<number | PathCommand>(paramCount + 1);\n segment[0] = pathCommand;\n for (let i = 0; i < paramCount; i += 1) {\n segment[i + 1] = data[index + i] as number;\n }\n path.segments.push(segment as PathSegment);\n index += paramCount;\n }\n\n if (!paramCount) {\n break;\n }\n }\n};\n","/** Error prefix used in all SVGPathCommander TypeError messages. */\nexport const error = \"SVGPathCommanderError\";\n","import { error } from \"../util/error.ts\";\nimport type { PathParser } from \"./pathParser.ts\";\n\n/**\n * Validates an A (arc-to) specific path command value.\n * Usually a `large-arc-flag` or `sweep-flag`.\n *\n * @param path - The PathParser instance\n */\nexport const scanFlag = (path: PathParser) => {\n const { index, pathValue } = path;\n const code = pathValue.charCodeAt(index);\n\n if (code === 0x30 /* 0 */) {\n path.param = 0;\n path.index += 1;\n return;\n }\n\n if (code === 0x31 /* 1 */) {\n path.param = 1;\n path.index += 1;\n return;\n }\n\n path.err = `${error}: invalid Arc flag \"${pathValue[index]}\", expecting 0 or 1 at index ${index}`;\n};\n","import type { DigitNumber } from \"../types.ts\";\n\n/**\n * Checks if a character is a digit.\n *\n * @param code the character to check\n * @returns check result\n */\nexport const isDigit = (code: number): code is DigitNumber => {\n return code >= 48 && code <= 57; // 0..9\n};\n","/** Error message prefix used when a path string cannot be parsed. */\nexport const invalidPathValue = \"Invalid path value\";\n","import { isDigit } from \"./isDigit.ts\";\nimport { invalidPathValue } from \"./invalidPathValue.ts\";\nimport { error } from \"../util/error.ts\";\nimport type { PathParser } from \"./pathParser.ts\";\n\n/**\n * Validates every character of the path string,\n * every path command, negative numbers or floating point numbers.\n *\n * @param path - The PathParser instance\n */\nexport const scanParam = (path: PathParser) => {\n const { max, pathValue, index: start } = path;\n let index = start;\n let hasCeiling = false;\n let hasDecimal = false;\n let hasDot = false;\n let ch;\n\n if (index >= max) {\n path.err = `${error}: ${invalidPathValue} at index ${index}, \"pathValue\" is missing param`;\n return;\n }\n ch = pathValue.charCodeAt(index);\n\n if (ch === 0x2b /* + */ || ch === 0x2d /* - */) {\n index += 1;\n // ch = (index < max) ? pathValue.charCodeAt(index) : 0;\n ch = pathValue.charCodeAt(index);\n }\n\n // This logic is shamelessly borrowed from Esprima\n // https://github.com/ariya/esprimas\n if (!isDigit(ch) && ch !== 0x2e /* . */) {\n // path.err = 'SvgPath: param should start with 0..9 or `.` (at pos ' + index + ')';\n path.err = `${error}: ${invalidPathValue} at index ${index}, \"${\n pathValue[index]\n }\" is not a number`;\n return;\n }\n\n if (ch !== 0x2e /* . */) {\n index += 1;\n\n ch = pathValue.charCodeAt(index);\n\n while (index < max && isDigit(pathValue.charCodeAt(index))) {\n index += 1;\n hasCeiling = true;\n }\n\n ch = pathValue.charCodeAt(index);\n }\n\n if (ch === 0x2e /* . */) {\n hasDot = true;\n index += 1;\n while (isDigit(pathValue.charCodeAt(index))) {\n index += 1;\n hasDecimal = true;\n }\n\n ch = pathValue.charCodeAt(index);\n }\n\n if (ch === 0x65 /* e */ || ch === 0x45 /* E */) {\n if (hasDot && !hasCeiling && !hasDecimal) {\n path.err = `${error}: ${invalidPathValue} at index ${index}, \"${\n pathValue[index]\n }\" invalid float exponent`;\n return;\n }\n\n index += 1;\n\n ch = pathValue.charCodeAt(index);\n\n if (ch === 0x2b /* + */ || ch === 0x2d /* - */) {\n index += 1;\n }\n if (index < max && isDigit(pathValue.charCodeAt(index))) {\n while (index < max && isDigit(pathValue.charCodeAt(index))) {\n index += 1;\n }\n } else {\n path.err = `${error}: ${invalidPathValue} at index ${index}, \"${\n pathValue[index]\n }\" invalid integer exponent`;\n return;\n }\n }\n\n path.index = index;\n path.param = scanNumber(pathValue, start, index);\n // a number that overflows the double range is not a valid path value\n if (!Number.isFinite(path.param)) {\n path.err = `${error}: ${invalidPathValue} at index ${start}, \"${pathValue.slice(\n start,\n index,\n )}\" is not a finite number`;\n }\n};\n\n/**\n * Converts a validated number substring to a Number without\n * allocating a new string, matching `+str.slice(start, end)`.\n *\n * Falls back to the native conversion when the value cannot be\n * represented exactly with plain double arithmetic (more than 15\n * significant digits or an exponent beyond +-22).\n *\n * @param str - the path string\n * @param start - the index of the first char of the number\n * @param end - the index after the last char of the number\n * @returns the parsed number\n */\nconst scanNumber = (str: string, start: number, end: number): number => {\n let i = start;\n let sign = 1;\n let param = 0;\n let decimals = 0;\n let sigDigits = 0;\n let inFraction = false;\n let expSign = 1;\n let exp = 0;\n\n const ch = str.charCodeAt(i);\n if (ch === 0x2b /* + */) {\n i += 1;\n } else if (ch === 0x2d /* - */) {\n sign = -1;\n i += 1;\n }\n\n for (; i < end; i += 1) {\n const code = str.charCodeAt(i);\n if (code === 0x2e /* . */) {\n inFraction = true;\n } else if (code === 0x65 /* e */ || code === 0x45 /* E */) {\n i += 1;\n const expCode = str.charCodeAt(i);\n if (expCode === 0x2b /* + */) {\n i += 1;\n } else if (expCode === 0x2d /* - */) {\n expSign = -1;\n i += 1;\n }\n for (; i < end; i += 1) {\n exp = exp * 10 + (str.charCodeAt(i) - 0x30);\n }\n } else {\n const digit = code - 0x30;\n if (digit !== 0 || param !== 0) {\n sigDigits += 1;\n }\n param = param * 10 + digit;\n if (inFraction) {\n decimals += 1;\n }\n }\n }\n\n if (sigDigits > 15 || sigDigits === 0) {\n return +str.slice(start, end);\n }\n\n const scale = expSign * exp - decimals;\n if (scale > 22 || scale < -22) {\n return +str.slice(start, end);\n }\n\n if (scale >= 0) {\n return sign * param * 10 ** scale;\n }\n return (sign * param) / 10 ** -scale;\n};\n","import type { SpaceNumber } from \"../types.ts\";\n\n/**\n * The characters the SVG path grammar accepts as white space.\n *\n * The set is built once, at module level: the parser calls `isSpace` for\n * every single character of a path, and building the list on every call\n * made the tokenizer allocate its way through a path.\n */\nconst spaces = new Set<number>([\n // Special spaces\n 0x1680, 0x180e, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009,\n 0x200a, 0x202f, 0x205f, 0x3000, 0xfeff,\n // Line terminators\n 0x0a, 0x0d, 0x2028, 0x2029,\n // White spaces\n 0x20, 0x09, 0x0b, 0x0c, 0xa0,\n]);\n\n/**\n * Checks if the character is a space.\n *\n * @param ch the character to check\n * @returns check result\n */\n\nexport const isSpace = (ch: number): ch is SpaceNumber => {\n return spaces.has(ch);\n};\n","import { isSpace } from \"./isSpace.ts\";\nimport type { PathParser } from \"./pathParser.ts\";\n\n/**\n * Points the parser to the next character in the\n * path string every time it encounters any kind of\n * space character.\n *\n * @param path - The PathParser instance\n */\nexport const skipSpaces = (path: PathParser): void => {\n const { pathValue, max } = path;\n while (path.index < max && isSpace(pathValue.charCodeAt(path.index))) {\n path.index += 1;\n }\n};\n","import type { PathCommandNumber } from \"../types.ts\";\n\n/**\n * Checks if the character is a path command.\n *\n * @param code the character to check\n * @returns check result\n */\nexport const isPathCommand = (code: number): code is PathCommandNumber => {\n // eslint-disable-next-line no-bitwise -- Impossible to satisfy\n switch (code | 0x20) {\n case 0x6d /* m */:\n case 0x7a /* z */:\n case 0x6c /* l */:\n case 0x68 /* h */:\n case 0x76 /* v */:\n case 0x63 /* c */:\n case 0x73 /* s */:\n case 0x71 /* q */:\n case 0x74 /* t */:\n case 0x61 /* a */:\n // case 0x72/* r */:\n return true;\n default:\n return false;\n }\n};\n","import { isDigit } from \"./isDigit.ts\";\nimport type { DigitNumber } from \"../types.ts\";\n\n/**\n * Checks if the character is or belongs to a number.\n * [0-9]|+|-|.\n *\n * @param code the character to check\n * @returns check result\n */\nexport const isDigitStart = (code: number): code is DigitNumber | 0x2b | 0x2d | 0x2e => {\n return (\n isDigit(code) /* 0..9 */ || code === 0x2b /* + */ || code === 0x2d /* - */ || code === 0x2e\n ); /* . */\n};\n","/**\n * Checks if the character is an A (arc-to) path command.\n *\n * @param code the character to check\n * @returns check result\n */\nexport const isArcCommand = (code: number): code is 0x61 => {\n // eslint-disable-next-line no-bitwise -- Impossible to satisfy\n return (code | 0x20) === 0x61;\n};\n","/**\n * Checks if the character is a MoveTo command.\n *\n * @param code the character to check\n * @returns check result\n */\nexport const isMoveCommand = (code: number): code is 0x6d | 0x4d => {\n // eslint-disable-next-line no-bitwise -- Impossible to satisfy\n switch (code | 0x20) {\n case 0x6d /* m */:\n case 0x4d /* M */:\n return true;\n default:\n return false;\n }\n};\n","import { finalizeSegment } from \"./finalizeSegment.ts\";\nimport { paramsCountsByCode } from \"./paramsCount.ts\";\nimport { scanFlag } from \"./scanFlag.ts\";\nimport { scanParam } from \"./scanParam.ts\";\nimport { skipSpaces } from \"./skipSpaces.ts\";\nimport { isPathCommand } from \"./isPathCommand.ts\";\nimport { isDigitStart } from \"./isDigitStart.ts\";\nimport { isArcCommand } from \"./isArcCommand.ts\";\nimport { isMoveCommand } from \"./isMoveCommand.ts\";\nimport { invalidPathValue } from \"./invalidPathValue.ts\";\nimport { error } from \"../util/error.ts\";\n\nimport type { PathParser } from \"./pathParser.ts\";\nimport type { PathSegment } from \"../types.ts\";\n\n/**\n * Scans every character in the path string to determine\n * where a segment starts and where it ends.\n *\n * @param path - The PathParser instance\n */\nexport const scanSegment = (path: PathParser) => {\n const { max, pathValue, index, segments } = path;\n const cmdCode = pathValue.charCodeAt(index);\n const reqParams = paramsCountsByCode[cmdCode];\n\n path.segmentStart = index;\n\n // segments always start with a path command\n if (!isPathCommand(cmdCode)) {\n path.err = `${error}: ${invalidPathValue} \"${\n pathValue[index]\n }\" is not a path command at index ${index}`;\n return;\n }\n\n // after a Z segment, we only expect a MoveTo path command\n const lastSegment = segments[segments.length - 1] as PathSegment | undefined;\n if (!isMoveCommand(cmdCode) && lastSegment?.[0]?.toLocaleLowerCase() === \"z\") {\n path.err = `${error}: ${invalidPathValue} \"${\n pathValue[index]\n }\" is not a MoveTo path command at index ${index}`;\n return;\n }\n\n path.index += 1;\n skipSpaces(path);\n\n path.data = [];\n\n if (!reqParams) {\n // Z\n finalizeSegment(path);\n return;\n }\n\n for (;;) {\n for (let i = reqParams; i > 0; i -= 1) {\n if (isArcCommand(cmdCode) && (i === 3 || i === 4)) scanFlag(path);\n else scanParam(path);\n\n if (path.err.length) {\n return;\n }\n path.data.push(path.param);\n\n skipSpaces(path);\n\n // after ',' param is mandatory\n if (path.index < max && pathValue.charCodeAt(path.index) === 0x2c /* , */) {\n path.index += 1;\n skipSpaces(path);\n }\n }\n\n if (path.index >= path.max) {\n break;\n }\n\n // Stop on next segment\n if (!isDigitStart(pathValue.charCodeAt(path.index))) {\n break;\n }\n }\n\n finalizeSegment(path);\n};\n","import type { PathArray, PathSegment } from \"../types.ts\";\n\n/**\n * The `PathParser` is used by the `parsePathString` static method\n * to generate a `pathArray`.\n *\n * @param pathString - The SVG path string to parse\n */\nexport class PathParser {\n declare segments: PathArray | PathSegment[];\n declare pathValue: string;\n declare max: number;\n declare index: number;\n declare param: number;\n declare segmentStart: number;\n declare data: (string | number)[];\n declare err: string;\n\n constructor(pathString: string) {\n this.segments = [];\n this.pathValue = pathString;\n this.max = pathString.length;\n this.index = 0;\n this.param = 0.0;\n this.segmentStart = 0;\n this.data = [];\n this.err = \"\";\n }\n}\n","import { scanSegment } from \"./scanSegment.ts\";\nimport { skipSpaces } from \"./skipSpaces.ts\";\nimport { PathParser } from \"./pathParser.ts\";\nimport type { MSegment, PathArray } from \"../types.ts\";\nimport { error } from \"../util/error.ts\";\n\n/**\n * Parses a path string value and returns an array\n * of segments we like to call `PathArray`.\n *\n * If parameter value is already a `PathArray`,\n * return a clone of it.\n *\n * A path must begin with a moveto command, so a path that starts with another\n * command is in error. A leading relative moveto is a pair of absolute\n * coordinates, so it is rewritten as an absolute one.\n *\n * @example\n * parsePathString(\"M 0 0L50 50\")\n * // => [[\"M\",0,0],[\"L\",50,50]]\n *\n * @param pathInput the string to be parsed\n * @returns the resulted `pathArray` or error string\n */\nexport const parsePathString = <T extends PathArray>(pathInput: string | T): PathArray => {\n let path: PathArray;\n\n if (typeof pathInput !== \"string\") {\n path = pathInput.slice(0) as T;\n } else {\n const parser = new PathParser(pathInput);\n\n skipSpaces(parser);\n\n while (parser.index < parser.max && !parser.err.length) {\n scanSegment(parser);\n }\n\n // handle errors first\n if (parser.err.length) {\n throw TypeError(parser.err);\n }\n\n path = parser.segments as PathArray;\n }\n\n const first = path[0];\n // an empty path has no first segment\n if (!first) return path;\n\n // a malformed segment is reported by its index\n if (typeof first[0] !== \"string\") {\n throw new TypeError(`${error}: invalid path segment at index 0`);\n }\n\n if (first[0] === \"m\") {\n /**\n * force absolute first M\n * getPathBBox calculation requires first segment to be absolute\n * @see https://github.com/thednp/svg-path-commander/pull/49\n */\n // the copy keeps the caller's array untouched\n path[0] = [\"M\", first[1], first[2]] as MSegment;\n } else if (first[0] !== \"M\") {\n throw new TypeError(`${error}: path data must begin with a moveto command`);\n }\n\n return path;\n};\n","import type {\n AbsoluteCommand,\n AbsoluteSegment,\n ASegment,\n CSegment,\n HSegment,\n LSegment,\n MSegment,\n PathSegment,\n QSegment,\n SSegment,\n TSegment,\n VSegment,\n} from \"../types.ts\";\n\n/**\n * Returns an absolute segment of a `PathArray` object.\n *\n * The current point of a path starts at the origin, so the first segment\n * of a path is absolutized against `[0, 0]`: a relative moveto at the\n * start of a path is an absolute one, as the SVG spec requires.\n *\n * @param segment the segment object\n * @param _index the segment index\n * @param lastX the last known X value\n * @param lastY the last known Y value\n * @returns the absolute segment\n */\nexport const absolutizeSegment = (\n segment: PathSegment,\n _index: number,\n lastX: number,\n lastY: number,\n): AbsoluteSegment => {\n const [pathCommand] = segment;\n const absCommand = pathCommand.toUpperCase() as AbsoluteCommand;\n const isAbsolute = absCommand === pathCommand;\n\n // an absolute segment is already absolute\n /* istanbul ignore else */\n if (isAbsolute) return segment as MSegment | AbsoluteSegment;\n // const values = segment.slice(1) as number[];\n if (absCommand === \"A\") {\n return [\n absCommand,\n segment[1],\n segment[2],\n segment[3],\n segment[4],\n segment[5],\n (segment as ASegment)[6] + lastX,\n (segment as ASegment)[7] + lastY,\n ] as ASegment;\n } else if (absCommand === \"V\") {\n return [absCommand, (segment as VSegment)[1] + lastY] as VSegment;\n } else if (absCommand === \"H\") {\n return [absCommand, (segment as HSegment)[1] + lastX] as HSegment;\n } else if (absCommand === \"L\") {\n return [\n absCommand,\n (segment as LSegment)[1] + lastX,\n (segment as LSegment)[2] + lastY,\n ] as LSegment;\n } else if (absCommand === \"C\") {\n return [\n absCommand,\n (segment as CSegment)[1] + lastX,\n (segment as CSegment)[2] + lastY,\n (segment as CSegment)[3] + lastX,\n (segment as CSegment)[4] + lastY,\n (segment as CSegment)[5] + lastX,\n (segment as CSegment)[6] + lastY,\n ] as CSegment;\n } else {\n // use brakets for `eslint: no-case-declaration`\n // https://stackoverflow.com/a/50753272/803358\n const absValues = [] as number[];\n const seglen = segment.length;\n for (let j = 1; j < seglen; j += 1) {\n absValues.push((segment[j] as number) + (j % 2 ? lastX : lastY));\n }\n // for s, q, t\n return [absCommand as typeof absCommand | number].concat(absValues) as\n | MSegment\n | QSegment\n | TSegment\n | SSegment\n | CSegment;\n }\n};\n","// import paramsParser from \"../parser/paramsParser.ts\";\nimport type { AbsoluteCommand, IteratorCallback, PathArray } from \"../types.ts\";\nimport { error } from \"../util/error.ts\";\n\n/**\n * Iterates over a `PathArray`, executing a callback for each segment.\n * The callback can:\n * - Read current position (`x`, `y`)\n * - Modify the segment (return new segment)\n * - Stop early (return `false`)\n *\n * The iterator maintains accurate current point (`x`, `y`) and subpath start (`mx`, `my`)\n * while correctly handling relative/absolute commands, including H/V and Z.\n *\n * **Important**: If the callback returns a new segment with more coordinates (e.g., Q → C),\n * the path length may increase, and iteration will continue over new segments.\n *\n * @template T - Specific PathArray type (e.g., CurveArray, PolylineArray)\n * @param path - The source `PathArray` to iterate over\n * @param iterator - Callback function for each segment\n * @param iterator.segment - Current path segment\n * @param iterator.index - Index of current segment\n * @param iterator.x - Current X position (after applying relative offset)\n * @param iterator.y - Current Y position (after applying relative offset)\n * @returns The modified `path` (or original if no changes)\n *\n * @example\n * iterate(path, (seg, i, x, y) => {\n * if (seg[0] === 'L') return ['C', x, y, seg[1], seg[2], seg[1], seg[2]];\n * });\n */\nexport const iterate = <T extends PathArray>(path: T, iterator: IteratorCallback<T>): T => {\n let x = 0;\n let y = 0;\n let mx = 0;\n let my = 0;\n\n let i = 0;\n while (i < path.length) {\n const segment = path[i];\n const pathCommand = segment[0];\n if (typeof pathCommand !== \"string\") {\n throw new TypeError(`${error}: invalid path segment at index ${i}`);\n }\n const commandCode = pathCommand.charCodeAt(0);\n const isRelative = commandCode >= 97; // a-z\n const absCommand = (\n isRelative ? String.fromCharCode(commandCode - 32) : pathCommand\n ) as AbsoluteCommand;\n\n const iteratorResult = iterator(segment, i, x, y);\n // some methods like getPointAtLength would like to break\n // when task is complete\n if (iteratorResult === false) {\n break;\n }\n\n // segment = path[i];\n if (absCommand === \"Z\") {\n x = mx;\n y = my;\n } else if (absCommand === \"H\") {\n x = (segment[1] as number) + (isRelative ? x : 0);\n } else if (absCommand === \"V\") {\n y = (segment[1] as number) + (isRelative ? y : 0);\n } else {\n const segLen = segment.length;\n\n x = (segment[segLen - 2] as number) + (isRelative ? x : 0);\n y = (segment[segLen - 1] as number) + (isRelative ? y : 0);\n\n if (absCommand === \"M\") {\n mx = x;\n my = y;\n }\n }\n\n if (iteratorResult) {\n path[i] = iteratorResult;\n }\n\n i += 1;\n }\n return path as T;\n};\n","import type { AbsoluteArray, PathArray } from \"../types.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { absolutizeSegment } from \"../process/absolutizeSegment.ts\";\nimport { iterate } from \"../process/iterate.ts\";\n\n/**\n * Parses a path string value or object and returns an array\n * of segments, all converted to absolute values.\n *\n * @param pathInput - The path string or PathArray\n * @returns The resulted PathArray with absolute values\n *\n * @example\n * ```ts\n * pathToAbsolute('M10 10l80 80')\n * // => [['M', 10, 10], ['L', 90, 90]]\n * ```\n */\nexport const pathToAbsolute = <T extends PathArray>(pathInput: string | T): AbsoluteArray => {\n const path = parsePathString(pathInput);\n\n return iterate(path, absolutizeSegment) as AbsoluteArray;\n};\n","import type {\n aSegment,\n cSegment,\n hSegment,\n lSegment,\n MSegment,\n PathSegment,\n qSegment,\n RelativeCommand,\n RelativeSegment,\n sSegment,\n tSegment,\n vSegment,\n} from \"../types.ts\";\n\n/**\n * Returns a relative segment of a `PathArray` object.\n *\n * @param segment the segment object\n * @param index the segment index\n * @param lastX the last known X value\n * @param lastY the last known Y value\n * @returns the relative segment\n */\nexport const relativizeSegment = (\n segment: PathSegment,\n index: number,\n lastX: number,\n lastY: number,\n): MSegment | RelativeSegment => {\n const [pathCommand] = segment;\n const relCommand = pathCommand.toLowerCase() as RelativeCommand;\n const isRelative = pathCommand === relCommand;\n\n /* istanbul ignore else */\n if (index === 0 || isRelative) return segment as MSegment | RelativeSegment;\n\n if (relCommand === \"a\") {\n return [\n relCommand,\n segment[1],\n segment[2],\n segment[3],\n segment[4],\n segment[5],\n (segment as aSegment)[6] - lastX,\n (segment as aSegment)[7] - lastY,\n ] as aSegment;\n } else if (relCommand === \"v\") {\n return [relCommand, (segment as vSegment)[1] - lastY] as vSegment;\n } else if (relCommand === \"h\") {\n return [relCommand, (segment as hSegment)[1] - lastX] as hSegment;\n } else if (relCommand === \"l\") {\n return [\n relCommand,\n (segment as lSegment)[1] - lastX,\n (segment as lSegment)[2] - lastY,\n ] as lSegment;\n } else {\n // use brakets for `eslint: no-case-declaration`\n // https://stackoverflow.com/a/50753272/803358\n const relValues = [] as number[];\n const seglen = segment.length;\n for (let j = 1; j < seglen; j += 1) {\n relValues.push((segment[j] as number) - (j % 2 ? lastX : lastY));\n }\n // for c, s, q, t\n return [relCommand as RelativeCommand | number].concat(relValues) as\n | qSegment\n | tSegment\n | sSegment\n | cSegment;\n }\n};\n","import type { PathArray, RelativeArray } from \"../types.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { iterate } from \"../process/iterate.ts\";\nimport { relativizeSegment } from \"../process/relativizeSegment.ts\";\n\n/**\n * Parses a path string value or object and returns an array\n * of segments, all converted to relative values.\n *\n * @param pathInput - The path string or PathArray\n * @returns The resulted PathArray with relative values\n *\n * @example\n * ```ts\n * pathToRelative('M10 10L90 90')\n * // => [['M', 10, 10], ['l', 80, 80]]\n * ```\n */\nexport const pathToRelative = <T extends PathArray>(pathInput: string | T): RelativeArray => {\n const path = parsePathString(pathInput);\n\n return iterate(path, relativizeSegment) as RelativeArray;\n};\n","import { midPoint } from \"../math/midPoint.ts\";\n\n/**\n * Converts an L (line-to) segment to C (cubic-bezier).\n *\n * @param x1 line start x\n * @param y1 line start y\n * @param x2 line end x\n * @param y2 line end y\n * @returns the cubic-bezier segment\n */\nexport const lineToCubic = (x1: number, y1: number, x2: number, y2: number): number[] => {\n const c1 = midPoint([x1, y1], [x2, y2], 1.0 / 3.0);\n const c2 = midPoint([x1, y1], [x2, y2], 2.0 / 3.0);\n return [c1[0], c1[1], c2[0], c2[1], x2, y2];\n};\n","import { rotateVector } from \"../math/rotateVector.ts\";\nimport { lineToCubic } from \"./lineToCubic.ts\";\n\n/**\n * Converts A (arc-to) segments to C (cubic-bezier-to).\n *\n * For more information of where this math came from visit:\n * http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes\n *\n * @param X1 the starting x position\n * @param Y1 the starting y position\n * @param RX x-radius of the arc\n * @param RY y-radius of the arc\n * @param angle x-axis-rotation of the arc\n * @param LAF large-arc-flag of the arc\n * @param SF sweep-flag of the arc\n * @param X2 the ending x position\n * @param Y2 the ending y position\n * @param recursive the parameters needed to split arc into 2 segments\n * @returns the resulting cubic-bezier segment(s)\n */\nexport const arcToCubic = (\n X1: number,\n Y1: number,\n RX: number,\n RY: number,\n angle: number,\n LAF: number,\n SF: number,\n X2: number,\n Y2: number,\n recursive?: [number, number, number, number],\n): number[] => {\n let x1 = X1;\n let y1 = Y1;\n // a negative radius is an error, the absolute value is used\n let rx = Math.abs(RX);\n let ry = Math.abs(RY);\n let x2 = X2;\n let y2 = Y2;\n // for more information of where this Math came from visit:\n // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes\n const d120 = (Math.PI * 120) / 180;\n\n // a zero radius is treated as a straight line to the end point\n if (!recursive && (rx === 0 || ry === 0)) {\n return lineToCubic(X1, Y1, X2, Y2);\n }\n\n const rad = (Math.PI / 180) * (+angle || 0);\n let res = [] as number[];\n let xy;\n let f1;\n let f2;\n let cx;\n let cy;\n\n if (!recursive) {\n xy = rotateVector(x1, y1, -rad);\n x1 = xy.x;\n y1 = xy.y;\n xy = rotateVector(x2, y2, -rad);\n x2 = xy.x;\n y2 = xy.y;\n\n const x = (x1 - x2) / 2;\n const y = (y1 - y2) / 2;\n let h = (x * x) / (rx * rx) + (y * y) / (ry * ry);\n if (h > 1) {\n h = Math.sqrt(h);\n rx *= h;\n ry *= h;\n }\n const rx2 = rx * rx;\n const ry2 = ry * ry;\n\n const k =\n (LAF === SF ? -1 : 1) *\n Math.sqrt(Math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x)));\n\n cx = (k * rx * y) / ry + (x1 + x2) / 2;\n cy = (k * -ry * x) / rx + (y1 + y2) / 2;\n // eslint-disable-next-line no-bitwise -- Impossible to satisfy no-bitwise\n f1 = Math.asin(((((y1 - cy) / ry) * 10 ** 9) >> 0) / 10 ** 9);\n // eslint-disable-next-line no-bitwise -- Impossible to satisfy no-bitwise\n f2 = Math.asin(((((y2 - cy) / ry) * 10 ** 9) >> 0) / 10 ** 9);\n\n f1 = x1 < cx ? Math.PI - f1 : f1;\n f2 = x2 < cx ? Math.PI - f2 : f2;\n if (f1 < 0) f1 = Math.PI * 2 + f1;\n if (f2 < 0) f2 = Math.PI * 2 + f2;\n if (SF && f1 > f2) {\n f1 -= Math.PI * 2;\n }\n if (!SF && f2 > f1) {\n f2 -= Math.PI * 2;\n }\n } else {\n [f1, f2, cx, cy] = recursive;\n }\n let df = f2 - f1;\n if (Math.abs(df) > d120) {\n const f2old = f2;\n const x2old = x2;\n const y2old = y2;\n f2 = f1 + d120 * (SF && f2 > f1 ? 1 : -1);\n x2 = cx + rx * Math.cos(f2);\n y2 = cy + ry * Math.sin(f2);\n res = arcToCubic(x2, y2, rx, ry, angle, 0, SF, x2old, y2old, [f2, f2old, cx, cy]);\n }\n df = f2 - f1;\n const c1 = Math.cos(f1);\n const s1 = Math.sin(f1);\n const c2 = Math.cos(f2);\n const s2 = Math.sin(f2);\n const t = Math.tan(df / 4);\n const hx = (4 / 3) * rx * t;\n const hy = (4 / 3) * ry * t;\n const m1 = [x1, y1];\n const m2 = [x1 + hx * s1, y1 - hy * c1];\n const m3 = [x2 + hx * s2, y2 - hy * c2];\n const m4 = [x2, y2];\n m2[0] = 2 * m1[0] - m2[0];\n m2[1] = 2 * m1[1] - m2[1];\n if (recursive) {\n return [m2[0], m2[1], m3[0], m3[1], m4[0], m4[1]].concat(res);\n }\n res = [m2[0], m2[1], m3[0], m3[1], m4[0], m4[1]].concat(res);\n const newres = [];\n for (let i = 0, ii = res.length; i < ii; i += 1) {\n newres[i] =\n i % 2 ? rotateVector(res[i - 1], res[i], rad).y : rotateVector(res[i], res[i + 1], rad).x;\n }\n return newres;\n};\n","/**\n * Converts a Q (quadratic-bezier) segment to C (cubic-bezier).\n *\n * @param x1 curve start x\n * @param y1 curve start y\n * @param qx control point x\n * @param qy control point y\n * @param x2 curve end x\n * @param y2 curve end y\n * @returns the cubic-bezier segment\n */\nexport const quadToCubic = (\n x1: number,\n y1: number,\n qx: number,\n qy: number,\n x2: number,\n y2: number,\n): [number, number, number, number, number, number] => {\n const r13 = 1 / 3;\n const r23 = 2 / 3;\n return [\n r13 * x1 + r23 * qx, // cpx1\n r13 * y1 + r23 * qy, // cpy1\n r13 * x2 + r23 * qx, // cpx2\n r13 * y2 + r23 * qy, // cpy2\n x2,\n y2, // x,y\n ];\n};\n","import { arcToCubic } from \"./arcToCubic.ts\";\nimport { quadToCubic } from \"./quadToCubic.ts\";\nimport { lineToCubic } from \"./lineToCubic.ts\";\nimport type { CSegment, PathSegment } from \"../types.ts\";\nimport type { ParserParams } from \"../interface.ts\";\n\n/**\n * Converts any segment to C (cubic-bezier).\n *\n * A segment that is already a cubic, or a command the converter does not\n * handle, is returned unchanged.\n *\n * @param segment the source segment\n * @param params the source segment parameters\n * @returns the cubic-bezier segment\n */\nexport const segmentToCubic = (segment: PathSegment, params: ParserParams): PathSegment => {\n const pathCommand = segment[0];\n const values = segment.slice(1).map(Number);\n const [x, y] = values;\n // let args;\n // const { x1: px1, y1: py1, x: px, y: py } = params;\n const { x1: px1, y1: py1 } = params;\n\n if (!\"TQ\".includes(pathCommand)) {\n params.qx = null;\n params.qy = null;\n }\n\n if (pathCommand === \"M\") {\n params.mx = x;\n params.my = y;\n params.x = x;\n params.y = y;\n return segment;\n } else if (pathCommand === \"A\") {\n return [\"C\" as string | number].concat(\n arcToCubic(\n px1,\n py1,\n values[0],\n values[1],\n values[2],\n values[3],\n values[4],\n values[5],\n values[6],\n ),\n ) as CSegment;\n } else if (pathCommand === \"Q\") {\n params.qx = x;\n params.qy = y;\n return [\"C\" as string | number].concat(\n quadToCubic(px1, py1, values[0], values[1], values[2], values[3]),\n ) as CSegment;\n } else if (pathCommand === \"L\") {\n return [\"C\" as string | number].concat(lineToCubic(px1, py1, x, y)) as CSegment;\n } else if (pathCommand === \"Z\") {\n return [\"C\" as string | number].concat(lineToCubic(px1, py1, params.mx, params.my)) as CSegment;\n }\n\n return segment;\n};\n","import type { ParserParams } from \"../interface.ts\";\nimport type {\n ASegment,\n CSegment,\n LSegment,\n MSegment,\n NormalSegment,\n PathCommand,\n PathSegment,\n QSegment,\n} from \"../types.ts\";\n\n/**\n * Normalizes a single segment of a `pathArray` object.\n *\n * @param segment the segment object\n * @param params the normalization parameters\n * @param prevCommand the command of the previous segment\n * @returns the normalized segment\n */\nexport const normalizeSegment = (\n segment: PathSegment,\n params: ParserParams,\n prevCommand?: PathCommand | null,\n): NormalSegment => {\n const [pathCommand] = segment;\n const absCommand = pathCommand.toUpperCase();\n const isRelative = pathCommand !== absCommand;\n const { x, y } = params;\n\n if (!\"TQ\".includes(absCommand)) {\n // optional but good to be cautious\n params.qx = null;\n params.qy = null;\n }\n\n // the absolute value of a parameter of the segment: the x and the y\n // parameters alternate\n const absolute = (index: number): number => {\n const value = segment[index] as number;\n if (!isRelative) return value;\n return index % 2 === 1 ? value + x : value + y;\n };\n\n // istanbul ignore else\n if (absCommand === \"A\") {\n // the parameters of an arc that are not points are not offset, only its\n // end point is\n return [\n \"A\",\n segment[1],\n segment[2],\n segment[3],\n segment[4],\n segment[5],\n (segment[6] as number) + (isRelative ? x : 0),\n (segment[7] as number) + (isRelative ? y : 0),\n ] as ASegment;\n } else if (absCommand === \"H\") {\n return [\"L\", absolute(1), y] as LSegment;\n } else if (absCommand === \"V\") {\n // the only parameter of a vertical line is a y coordinate\n return [\"L\", x, (segment[1] as number) + (isRelative ? y : 0)] as LSegment;\n } else if (absCommand === \"L\") {\n return [\"L\", absolute(1), absolute(2)] as LSegment;\n } else if (absCommand === \"M\") {\n return [\"M\", absolute(1), absolute(2)] as MSegment;\n } else if (absCommand === \"C\") {\n return [\n \"C\",\n absolute(1),\n absolute(2),\n absolute(3),\n absolute(4),\n absolute(5),\n absolute(6),\n ] as CSegment;\n } else if (absCommand === \"S\") {\n // the control point is only reflected when the previous segment\n // is a cubic, otherwise it coincides with the current point\n const canReflect = prevCommand != null && \"CS\".includes(prevCommand);\n const x1 = canReflect && params.x2 != null ? x * 2 - params.x2 : x;\n const y1 = canReflect && params.y2 != null ? y * 2 - params.y2 : y;\n return [\"C\", x1, y1, absolute(1), absolute(2), absolute(3), absolute(4)] as CSegment;\n } else if (absCommand === \"T\") {\n // keep null check #64\n const qx = params.qx != null ? x * 2 - params.qx : x;\n const qy = params.qy != null ? y * 2 - params.qy : y;\n params.qx = qx;\n params.qy = qy;\n return [\"Q\", qx, qy, absolute(1), absolute(2)] as QSegment;\n } else if (absCommand === \"Q\") {\n const nqx = absolute(1);\n const nqy = absolute(2);\n params.qx = nqx;\n params.qy = nqy;\n return [\"Q\", nqx, nqy, absolute(3), absolute(4)] as QSegment;\n } else if (absCommand === \"Z\") {\n return [\"Z\"] as NormalSegment;\n }\n\n // istanbul ignore next\n return segment as NormalSegment;\n};\n","import type { ParserParams } from \"../interface.ts\";\n\n/**\n * Default parser parameters object used to track position state\n * while iterating through path segments.\n */\nexport const paramsParser: ParserParams = {\n mx: 0,\n my: 0,\n x1: 0,\n y1: 0,\n x2: null,\n y2: null,\n x: 0,\n y: 0,\n qx: null,\n qy: null,\n};\n","import { segmentToCubic } from \"../process/segmentToCubic.ts\";\nimport type { AbsoluteCommand, CSegment, CurveArray, PathArray, PathCommand } from \"../types.ts\";\nimport { iterate } from \"../process/iterate.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { normalizeSegment } from \"../process/normalizeSegment.ts\";\nimport { paramsParser } from \"../parser/paramsParser.ts\";\n\n/**\n * Parses a path string or PathArray and returns a new one\n * in which all segments are converted to cubic-bezier.\n *\n * @param pathInput - The path string or PathArray\n * @returns The resulted CurveArray with all segments as cubic beziers\n *\n * @example\n * ```ts\n * pathToCurve('M10 50q15 -25 30 0')\n * // => [['M', 10, 50], ['C', 20, 33.3333, 30, 33.3333, 40, 50]]\n * ```\n */\nexport const pathToCurve = <T extends PathArray>(pathInput: string | T): CurveArray => {\n const params = { ...paramsParser };\n const path = parsePathString(pathInput);\n let prevCommand: PathCommand | null = null;\n // let mx = 0;\n // let my = 0;\n\n return iterate(path, (seg, index, lastX, lastY) => {\n params.x = lastX;\n params.y = lastY;\n const normalSegment = normalizeSegment(seg, params, prevCommand);\n if (normalSegment[0] === \"M\") {\n params.mx = normalSegment[1];\n params.my = normalSegment[2];\n }\n let result = segmentToCubic(normalSegment, params);\n const isLongArc = result[0] === \"C\" && result.length > 7;\n\n if (isLongArc) {\n // an arc of more than 120 degrees is converted to more than one cubic\n // segment, the first one stays in place and the rest are inserted\n // after it, one segment each\n const values = result as unknown as (number | AbsoluteCommand)[];\n const segments: CSegment[] = [];\n for (let i = 7; i < values.length; i += 6) {\n segments.push([\"C\" as AbsoluteCommand | number].concat(values.slice(i, i + 6)) as CSegment);\n }\n path.splice(index + 1, 0, ...segments);\n result = values.slice(0, 7) as CSegment;\n }\n\n const seglen = result.length;\n params.x1 = +result[seglen - 2];\n params.y1 = +result[seglen - 1];\n // only cubic segments carry a reflectable control point, quadratics\n // are converted to cubics, so their control point is not reflectable\n if (normalSegment[0] === \"C\") {\n params.x2 = +result[seglen - 4];\n params.y2 = +result[seglen - 3];\n } else {\n params.x2 = null;\n params.y2 = null;\n }\n prevCommand = normalSegment[0];\n\n return result;\n }) as CurveArray;\n};\n","import type { Options } from \"../interface.ts\";\n\n/** SVGPathCommander default options */\nexport const defaultOptions: Options = {\n origin: [0, 0, 0],\n round: 4,\n};\n","import type { PathArray } from \"../types.ts\";\nimport { defaultOptions } from \"../options/options.ts\";\n\n/**\n * Returns a valid `d` attribute string value created\n * by rounding values and concatenating the PathArray segments.\n *\n * @param path - The PathArray object\n * @param roundOption - Amount of decimals to round values to, or \"off\"\n * @returns The concatenated path string\n *\n * @example\n * ```ts\n * pathToString([['M', 10, 10], ['L', 90, 90]], 2)\n * // => 'M10 10L90 90'\n * ```\n */\nexport const pathToString = <T extends PathArray>(\n path: T,\n roundOption?: number | \"off\",\n): string => {\n const pathLen = path.length;\n let { round } = defaultOptions;\n let segment = path[0] as PathArray[number];\n let result = \"\";\n\n // allow for ZERO decimals\n round =\n roundOption === \"off\"\n ? roundOption\n : typeof roundOption === \"number\" && roundOption >= 0\n ? roundOption\n : typeof round === \"number\" && round >= 0\n ? round\n : \"off\";\n\n const pow = round === \"off\" ? 0 : 10 ** round;\n\n for (let i = 0; i < pathLen; i += 1) {\n segment = path[i];\n const pathCommand = segment[0] as string;\n const segLen = segment.length;\n result += pathCommand;\n if (round === \"off\") {\n for (let j = 1; j < segLen; j += 1) {\n result += segment[j] as number;\n if (j !== segLen - 1) result += \" \";\n }\n } else {\n for (let j = 1; j < segLen; j += 1) {\n result += Math.round((segment[j] as number) * pow) / pow;\n if (j !== segLen - 1) result += \" \";\n }\n }\n }\n\n return result;\n};\n","import { iterate } from \"../process/iterate.ts\";\nimport type { PathBBox } from \"../interface.ts\";\nimport type { LSegment, MSegment, PathArray } from \"../types.ts\";\nimport { getLineBBox } from \"../math/lineTools.ts\";\nimport { getArcBBox } from \"../math/arcTools.ts\";\nimport { getCubicBBox } from \"../math/cubicTools.ts\";\nimport { getQuadBBox } from \"../math/quadTools.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { absolutizeSegment } from \"../process/absolutizeSegment.ts\";\n\n/**\n * The bounding box of an empty path.\n */\nconst emptyBBox = {\n x: 0,\n y: 0,\n width: 0,\n height: 0,\n x2: 0,\n y2: 0,\n cx: 0,\n cy: 0,\n cz: 0,\n};\n\n/**\n * Calculates the bounding box of a path.\n *\n * @param pathInput - The path string or PathArray\n * @returns An object with width, height, x, y, x2, y2, cx, cy, cz properties\n *\n * @example\n * ```ts\n * getPathBBox('M0 0L100 0L100 100L0 100Z')\n * // => { x: 0, y: 0, width: 100, height: 100, x2: 100, y2: 100, cx: 50, cy: 50, cz: 150 }\n * ```\n */\nexport const getPathBBox = <T extends PathArray>(\n pathInput: T | string,\n): {\n x: number;\n y: number;\n width: number;\n height: number;\n x2: number;\n y2: number;\n cx: number;\n cy: number;\n cz: number;\n} => {\n if (!pathInput) {\n return { ...emptyBBox };\n }\n\n const path = parsePathString(pathInput);\n\n // an empty path has no bounds, but it still needs a usable result\n if (!path.length) {\n return { ...emptyBBox };\n }\n\n let pathCommand = \"M\";\n let mx = 0;\n let my = 0;\n const { max, min } = Math;\n let xMin = Infinity;\n let yMin = Infinity;\n let xMax = -Infinity;\n let yMax = -Infinity;\n let minX = 0;\n let minY = 0;\n let maxX = 0;\n let maxY = 0;\n let paramX1 = 0;\n let paramY1 = 0;\n let paramX2 = 0;\n let paramY2 = 0;\n // keep null check #64\n let paramQX: number | null = null;\n let paramQY: number | null = null;\n\n iterate(path, (seg, index, lastX, lastY) => {\n [pathCommand] = seg;\n const commandCode = pathCommand.charCodeAt(0);\n const isRelative = commandCode >= 97; // a-z\n const absCommand = (\n isRelative ? String.fromCharCode(commandCode - 32) : pathCommand\n ) as typeof pathCommand;\n const absoluteSegment = isRelative ? absolutizeSegment(seg, index, lastX, lastY) : seg;\n\n const normalSegment =\n absCommand === \"V\"\n ? ([\"L\", lastX, absoluteSegment[1]] as LSegment)\n : absCommand === \"H\"\n ? ([\"L\", absoluteSegment[1], lastY] as LSegment)\n : absoluteSegment;\n\n [pathCommand] = normalSegment;\n\n if (absCommand !== \"T\" && absCommand !== \"Q\") {\n // keep null check #64\n paramQX = null;\n paramQY = null;\n }\n\n // this segment is always ZERO\n /* istanbul ignore else */\n if (pathCommand === \"M\") {\n [, mx, my] = normalSegment as MSegment;\n minX = mx;\n minY = my;\n maxX = mx;\n maxY = my;\n } else if (pathCommand === \"L\") {\n [minX, minY, maxX, maxY] = getLineBBox(\n lastX,\n lastY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n );\n } else if (pathCommand === \"A\") {\n [minX, minY, maxX, maxY] = getArcBBox(\n lastX,\n lastY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n normalSegment[3] as number,\n normalSegment[4] as number,\n normalSegment[5] as number,\n normalSegment[6] as number,\n normalSegment[7] as number,\n );\n } else if (pathCommand === \"S\") {\n const cp1x = paramX1 * 2 - paramX2;\n const cp1y = paramY1 * 2 - paramY2;\n\n [minX, minY, maxX, maxY] = getCubicBBox(\n lastX,\n lastY,\n cp1x,\n cp1y,\n normalSegment[1] as number,\n normalSegment[2] as number,\n normalSegment[3] as number,\n normalSegment[4] as number,\n );\n } else if (pathCommand === \"C\") {\n [minX, minY, maxX, maxY] = getCubicBBox(\n lastX,\n lastY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n normalSegment[3] as number,\n normalSegment[4] as number,\n normalSegment[5] as number,\n normalSegment[6] as number,\n );\n } else if (pathCommand === \"T\") {\n // keep null check #64\n paramQX = paramQX === null ? lastX : paramX1 * 2 - paramQX;\n paramQY = paramQY === null ? lastY : paramY1 * 2 - paramQY;\n [minX, minY, maxX, maxY] = getQuadBBox(\n lastX,\n lastY,\n paramQX,\n paramQY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n );\n } else if (pathCommand === \"Q\") {\n paramQX = normalSegment[1] as number;\n paramQY = normalSegment[2] as number;\n [minX, minY, maxX, maxY] = getQuadBBox(\n lastX,\n lastY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n normalSegment[3] as number,\n normalSegment[4] as number,\n );\n } else if (pathCommand === \"Z\") {\n [minX, minY, maxX, maxY] = getLineBBox(lastX, lastY, mx, my);\n }\n xMin = min(minX, xMin);\n yMin = min(minY, yMin);\n xMax = max(maxX, xMax);\n yMax = max(maxY, yMax);\n\n // update params\n if (pathCommand === \"Z\") {\n paramX1 = mx;\n paramY1 = my;\n } else {\n const segLen = normalSegment.length;\n paramX1 = normalSegment[segLen - 2] as number;\n paramY1 = normalSegment[segLen - 1] as number;\n }\n if (pathCommand === \"C\") {\n paramX2 = normalSegment[3] as number;\n paramY2 = normalSegment[4] as number;\n } else if (pathCommand === \"S\") {\n paramX2 = normalSegment[1] as number;\n paramY2 = normalSegment[2] as number;\n } else {\n paramX2 = paramX1;\n paramY2 = paramY1;\n }\n });\n\n const width = xMax - xMin;\n const height = yMax - yMin;\n\n return {\n width,\n height,\n x: xMin,\n y: yMin,\n x2: xMax,\n y2: yMax,\n cx: xMin + width / 2,\n cy: yMin + height / 2,\n // an estimated guess\n cz: Math.max(width, height) + Math.min(width, height) / 2,\n } satisfies PathBBox;\n};\n","import type {\n CSegment,\n LSegment,\n NormalSegment,\n PathArray,\n PathSegment,\n QSegment,\n} from \"../types.ts\";\nimport { getLineLength } from \"../math/lineTools.ts\";\nimport { getArcLength } from \"../math/arcTools.ts\";\nimport { getCubicLength } from \"../math/cubicTools.ts\";\nimport { getQuadLength } from \"../math/quadTools.ts\";\nimport { iterate } from \"../process/iterate.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { absolutizeSegment } from \"../process/absolutizeSegment.ts\";\n\n/**\n * The measured properties of a single path segment.\n */\nexport type SegmentMeasure = {\n /** the original (non-normalized) segment */\n segment: PathSegment;\n /** the index of the segment in the path */\n index: number;\n /** the length of the segment itself */\n length: number;\n /** the accumulated length of all segments before this one */\n lengthAtSegment: number;\n /** the absolute X coordinate the segment starts at */\n startX: number;\n /** the absolute Y coordinate the segment starts at */\n startY: number;\n /** the absolute X coordinate the segment ends at */\n endX: number;\n /** the absolute Y coordinate the segment ends at */\n endY: number;\n /** the absolute segment, with the shorthand commands expanded */\n geometry: NormalSegment;\n};\n\n/**\n * Measures every segment of a path in a single pass.\n *\n * This is the one source of truth for the length math: it absolutises relative\n * segments, rewrites `H`/`V` to `L` and carries the reflectable control-point\n * state for `S`/`T`, exactly like `getTotalLength` does. Every consumer that\n * needs per-segment lengths reads them from here so they cannot disagree with\n * each other.\n *\n * @param pathInput - the target path string or `PathArray`\n * @returns the measured segments, in path order\n */\nexport const measureSegments = (pathInput: string | PathArray): SegmentMeasure[] => {\n const path = parsePathString(pathInput);\n const measures: SegmentMeasure[] = [];\n let paramX1 = 0;\n let paramY1 = 0;\n let paramX2 = 0;\n let paramY2 = 0;\n // keep null check #64\n let paramQX: number | null = null;\n let paramQY: number | null = null;\n let pathCommand = \"M\";\n let mx = 0;\n let my = 0;\n let totalLength = 0;\n\n iterate(path, (seg, index, lastX, lastY) => {\n pathCommand = seg[0] as string;\n const absCommand = pathCommand.toUpperCase();\n const isRelative = absCommand !== pathCommand;\n const absoluteSegment = isRelative\n ? absolutizeSegment(seg, index, lastX, lastY)\n : (seg as typeof seg);\n\n const normalSegment =\n absCommand === \"V\"\n ? ([\"L\", lastX, absoluteSegment[1]] as LSegment)\n : absCommand === \"H\"\n ? ([\"L\", absoluteSegment[1], lastY] as LSegment)\n : absoluteSegment;\n pathCommand = normalSegment[0] as string;\n\n if (!\"TQ\".includes(absCommand)) {\n // keep null check #64\n paramQX = null;\n paramQY = null;\n }\n\n let length = 0;\n // the absolute segment, with the shorthand commands expanded: the\n // reflected control point of an `S` or a `T` is resolved here, so the\n // geometry and the length of a segment always agree\n let geometry = normalSegment as NormalSegment;\n\n // this segment is always ZERO\n /* istanbul ignore else */\n if (pathCommand === \"M\") {\n // remember mx, my for Z\n mx = normalSegment[1] as number;\n my = normalSegment[2] as number;\n } else if (pathCommand === \"L\") {\n length = getLineLength(lastX, lastY, normalSegment[1] as number, normalSegment[2] as number);\n } else if (pathCommand === \"A\") {\n length = getArcLength(\n lastX,\n lastY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n normalSegment[3] as number,\n normalSegment[4] as number,\n normalSegment[5] as number,\n normalSegment[6] as number,\n normalSegment[7] as number,\n );\n } else if (pathCommand === \"S\") {\n const cp1x = paramX1 * 2 - paramX2;\n const cp1y = paramY1 * 2 - paramY2;\n\n geometry = [\n \"C\",\n cp1x,\n cp1y,\n normalSegment[1] as number,\n normalSegment[2] as number,\n normalSegment[3] as number,\n normalSegment[4] as number,\n ] as CSegment;\n length = getCubicLength(\n lastX,\n lastY,\n cp1x,\n cp1y,\n normalSegment[1] as number,\n normalSegment[2] as number,\n normalSegment[3] as number,\n normalSegment[4] as number,\n );\n } else if (pathCommand === \"C\") {\n length = getCubicLength(\n lastX,\n lastY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n normalSegment[3] as number,\n normalSegment[4] as number,\n normalSegment[5] as number,\n normalSegment[6] as number,\n );\n } else if (pathCommand === \"T\") {\n // keep null check #64\n paramQX = paramQX === null ? lastX : paramX1 * 2 - paramQX;\n paramQY = paramQY === null ? lastY : paramY1 * 2 - paramQY;\n geometry = [\n \"Q\",\n paramQX,\n paramQY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n ] as QSegment;\n length = getQuadLength(\n lastX,\n lastY,\n paramQX,\n paramQY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n );\n } else if (pathCommand === \"Q\") {\n paramQX = normalSegment[1] as number;\n paramQY = normalSegment[2] as number;\n length = getQuadLength(\n lastX,\n lastY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n normalSegment[3] as number,\n normalSegment[4] as number,\n );\n } else if (pathCommand === \"Z\") {\n length = getLineLength(lastX, lastY, mx, my);\n }\n\n // the close segment returns to the start of the sub-path\n const endX = pathCommand === \"Z\" ? mx : (geometry[geometry.length - 2] as number);\n const endY = pathCommand === \"Z\" ? my : (geometry[geometry.length - 1] as number);\n\n measures.push({\n segment: seg,\n index,\n length,\n lengthAtSegment: totalLength,\n startX: lastX,\n startY: lastY,\n endX,\n endY,\n geometry,\n });\n totalLength += length;\n\n // update params\n if (pathCommand === \"Z\") {\n paramX1 = mx;\n paramY1 = my;\n } else {\n paramX1 = normalSegment[normalSegment.length - 2] as number;\n paramY1 = normalSegment[normalSegment.length - 1] as number;\n }\n if (pathCommand === \"C\") {\n paramX2 = normalSegment[3] as number;\n paramY2 = normalSegment[4] as number;\n } else if (pathCommand === \"S\") {\n paramX2 = normalSegment[1] as number;\n paramY2 = normalSegment[2] as number;\n } else {\n paramX2 = paramX1;\n paramY2 = paramY1;\n }\n });\n\n return measures;\n};\n","import type { PathArray } from \"../types.ts\";\nimport { measureSegments } from \"./measureSegments.ts\";\n\n/**\n * Returns the total length of a path, equivalent to `shape.getTotalLength()`.\n *\n * @param pathInput - The target path string or PathArray\n * @returns the total length of the path\n *\n * @example\n * ```ts\n * getTotalLength('M0 0L100 0L100 100L0 100Z')\n * // => 400\n * ```\n */\nexport const getTotalLength = <T extends PathArray>(pathInput: string | T): number => {\n const measures = measureSegments(pathInput);\n const last = measures[measures.length - 1];\n return last ? last.lengthAtSegment + last.length : 0;\n};\n","/** Small threshold value used for floating-point distance comparisons in path calculations. */\nconst DISTANCE_EPSILON = 0.00001;\n\nexport default DISTANCE_EPSILON;\n","import type { NormalArray, PointTuple } from \"../types.ts\";\nimport type { SegmentMeasure } from \"./measureSegments.ts\";\nimport { getLineLength, getPointAtLineLength } from \"../math/lineTools.ts\";\nimport { getArcLength, getPointAtArcLength } from \"../math/arcTools.ts\";\nimport { getCubicLength, getPointAtCubicLength } from \"../math/cubicTools.ts\";\nimport { getPointAtQuadLength, getQuadLength } from \"../math/quadTools.ts\";\nimport DISTANCE_EPSILON from \"./distanceEpsilon.ts\";\n\n/**\n * The length table of a normalized path.\n *\n * The table holds the length of every segment and the length accumulated\n * before it, so a point at any distance can be found with a binary search\n * over the accumulated lengths instead of a walk over the whole path.\n */\nexport type PathLengthTable = {\n /** the measured segments, in path order */\n measures: SegmentMeasure[];\n /** the total length of the path */\n totalLength: number;\n /** the X coordinate the path starts at */\n startX: number;\n /** the Y coordinate the path starts at */\n startY: number;\n /** whether the path is a loop, so it ends where it starts */\n isLoop: boolean;\n};\n\n/**\n * Measures every segment of a normalized path in a single pass.\n *\n * A normalized path holds absolute `M`, `L`, `C`, `Q`, `A` and `Z` segments\n * only, so no relative offsets and no shorthand control point reflections\n * have to be resolved here — the length of a segment is exactly the length\n * the point lookup at that distance will use.\n *\n * @param path - the normalized path to measure\n * @returns the length table of the path\n */\nexport const buildPathLengthTable = (path: NormalArray): PathLengthTable => {\n const measures: SegmentMeasure[] = [];\n let x = 0;\n let y = 0;\n let mx = 0;\n let my = 0;\n let totalLength = 0;\n let movetoCount = 0;\n\n for (const [index, segment] of path.entries()) {\n const command = segment[0];\n const measure: SegmentMeasure = {\n segment,\n index,\n startX: x,\n startY: y,\n endX: x,\n endY: y,\n length: 0,\n lengthAtSegment: totalLength,\n geometry: segment,\n };\n\n // a normalized path holds no other command than the ones handled here\n /* istanbul ignore else */\n if (command === \"M\") {\n mx = segment[1] as number;\n my = segment[2] as number;\n measure.endX = mx;\n measure.endY = my;\n movetoCount += 1;\n } else if (command === \"L\") {\n measure.endX = segment[1] as number;\n measure.endY = segment[2] as number;\n measure.length = getLineLength(x, y, measure.endX, measure.endY);\n } else if (command === \"C\") {\n measure.endX = segment[5] as number;\n measure.endY = segment[6] as number;\n measure.length = getCubicLength(\n x,\n y,\n segment[1] as number,\n segment[2] as number,\n segment[3] as number,\n segment[4] as number,\n measure.endX,\n measure.endY,\n );\n } else if (command === \"Q\") {\n measure.endX = segment[3] as number;\n measure.endY = segment[4] as number;\n measure.length = getQuadLength(\n x,\n y,\n segment[1] as number,\n segment[2] as number,\n measure.endX,\n measure.endY,\n );\n } else if (command === \"A\") {\n measure.endX = segment[6] as number;\n measure.endY = segment[7] as number;\n measure.length = getArcLength(\n x,\n y,\n segment[1] as number,\n segment[2] as number,\n segment[3] as number,\n segment[4] as number,\n segment[5] as number,\n measure.endX,\n measure.endY,\n );\n } else if (command === \"Z\") {\n // the segment closes back to the start of the sub-path\n measure.endX = mx;\n measure.endY = my;\n measure.length = getLineLength(x, y, mx, my);\n }\n\n measures.push(measure);\n totalLength += measure.length;\n x = measure.endX;\n y = measure.endY;\n }\n\n const [startX, startY] = (path[0]?.slice(1) ?? []) as PointTuple;\n const last = measures[measures.length - 1];\n // a path with a single sub-path that ends where it starts is a loop, so\n // the point before the start of the path is the point before its end\n const isLoop =\n movetoCount === 1 &&\n !!last &&\n Math.hypot(last.endX - startX, last.endY - startY) <= DISTANCE_EPSILON;\n\n return { measures, totalLength, startX, startY, isLoop };\n};\n\n/**\n * Builds the length table of a path from the shared measure pass.\n *\n * The measure pass resolves the relative offsets and the shorthand control\n * point reflections of a path and holds the length of every segment, so the\n * table can be built from it without measuring the path a second time. The\n * measures of the pass are the measures of the table: the geometry of a\n * measure is the normalized segment, so the table holds the same segments and\n * the same lengths as the one built from a normalized path.\n *\n * @param segmentMeasures - the measured segments of the path\n * @returns the length table of the path\n */\nexport const buildPathLengthTableFromMeasures = (\n segmentMeasures: SegmentMeasure[],\n): PathLengthTable => {\n let movetoCount = 0;\n\n for (const measure of segmentMeasures) {\n if (measure.geometry[0] === \"M\") movetoCount += 1;\n }\n\n const first = segmentMeasures[0];\n const last = segmentMeasures[segmentMeasures.length - 1];\n // the path starts at the point of its first moveto\n const startX = first?.endX ?? 0;\n const startY = first?.endY ?? 0;\n const totalLength = last ? last.lengthAtSegment + last.length : 0;\n // a path with a single sub-path that ends where it starts is a loop, so\n // the point before the start of the path is the point before its end\n const isLoop =\n movetoCount === 1 &&\n !!last &&\n Math.hypot(last.endX - startX, last.endY - startY) <= DISTANCE_EPSILON;\n\n return { measures: segmentMeasures, totalLength, startX, startY, isLoop };\n};\n\n/**\n * Returns the point of a measured path at a given distance.\n *\n * The segment is found with a binary search over the accumulated lengths:\n * it is the last segment whose accumulated length is still below the\n * distance, which is the same segment the linear walk over the path would\n * have stopped at.\n *\n * @param table - the length table of the path\n * @param distance - the distance along the path\n * @returns the requested {x, y} point coordinates\n */\nexport const getPointAtTable = (\n table: PathLengthTable,\n distance?: number,\n): { x: number; y: number } => {\n const { measures, startX, startY } = table;\n\n // an empty path has no point to return\n if (!measures.length) return { x: 0, y: 0 };\n\n // a missing, a negative or a not-a-number distance has no point to look\n // for, the path starts there\n if (typeof distance !== \"number\" || Number.isNaN(distance) || distance < DISTANCE_EPSILON) {\n return { x: startX, y: startY };\n }\n\n // the last segment whose accumulated length is below the distance\n let low = 0;\n let high = measures.length - 1;\n while (low < high) {\n const mid = (low + high + 1) >> 1;\n if (measures[mid].lengthAtSegment < distance) {\n low = mid;\n } else {\n high = mid - 1;\n }\n }\n\n const measure = measures[low];\n const { geometry: segment, startX: x1, startY: y1, endX, endY } = measure;\n const command = segment[0];\n // the distance within the segment\n const offset = distance - measure.lengthAtSegment;\n\n // a normalized path holds no other command than the ones handled here\n /* istanbul ignore else */\n if (command === \"M\") {\n return { x: endX, y: endY };\n }\n if (command === \"L\") {\n return getPointAtLineLength(x1, y1, endX, endY, offset);\n }\n if (command === \"C\") {\n return getPointAtCubicLength(\n x1,\n y1,\n segment[1] as number,\n segment[2] as number,\n segment[3] as number,\n segment[4] as number,\n endX,\n endY,\n offset,\n );\n }\n if (command === \"Q\") {\n return getPointAtQuadLength(\n x1,\n y1,\n segment[1] as number,\n segment[2] as number,\n endX,\n endY,\n offset,\n );\n }\n if (command === \"A\") {\n return getPointAtArcLength(\n x1,\n y1,\n segment[1] as number,\n segment[2] as number,\n segment[3] as number,\n segment[4] as number,\n segment[5] as number,\n endX,\n endY,\n offset,\n );\n }\n // the close segment returns to the start of the sub-path\n return getPointAtLineLength(x1, y1, endX, endY, offset);\n};\n","import type { CubicCoordinates, NormalSegment, Point, QuadCoordinates } from \"../types.ts\";\nimport {\n computeBezier,\n deriveBezier,\n getBezierPoints,\n getTAtBezierLength,\n} from \"../math/bezier.ts\";\nimport { getPointAtCubicSegmentLength } from \"../math/cubicTools.ts\";\nimport { getPointAtQuadSegmentLength } from \"../math/quadTools.ts\";\nimport { arcLengthBetween, getArcProps } from \"../math/arcTools.ts\";\n\n/**\n * The frame of a path at a given length: the point, the direction of the path\n * at that point (the tangent), the perpendicular to it (the normal) and the\n * angle of the tangent.\n */\nexport type PathFrame = {\n /** The point at the given length. */\n point: Point;\n /** The unit tangent vector at the given length. */\n tangent: Point;\n /** The unit normal vector at the given length, the left normal of the tangent. */\n normal: Point;\n /** The angle of the tangent at the given length, in degrees. */\n angle: number;\n};\n\n/**\n * Returns a value without a negative zero.\n *\n * The negative zero is a valid number, but it is a surprise in a result:\n * `Object.is(-0, 0)` is false, so a deep comparison of two equal frames\n * would fail.\n *\n * @param value the value to clean\n * @returns the value without a negative zero\n */\nexport const cleanZero = (value: number): number => (value === 0 ? 0 : value);\n\n/**\n * Returns the unit vector of a direction.\n *\n * A direction without a length has no unit vector, so the zero vector is\n * returned for it.\n *\n * @param x the X component of the direction\n * @param y the Y component of the direction\n * @returns the unit vector of the direction\n */\nconst normalizeVector = (x: number, y: number): Point => {\n const length = Math.sqrt(x * x + y * y);\n return length > 0 ? { x: cleanZero(x / length), y: cleanZero(y / length) } : { x: 0, y: 0 };\n};\n\n/**\n * Returns the frame of a point with a given direction.\n *\n * The normal is the left normal of the tangent, so it points to the left of\n * the direction of the path, and the angle is the angle of the tangent in\n * degrees, in the `-180` to `180` range.\n *\n * @param point the point of the frame\n * @param x the X component of the direction\n * @param y the Y component of the direction\n * @returns the frame of the point\n */\nconst frameFrom = (point: Point, x: number, y: number): PathFrame => {\n const tangent = normalizeVector(x, y);\n return {\n point: { x: cleanZero(point.x), y: cleanZero(point.y) },\n tangent,\n normal: { x: cleanZero(-tangent.y), y: cleanZero(tangent.x) },\n angle: (Math.atan2(tangent.y, tangent.x) * 180) / Math.PI,\n };\n};\n\n/**\n * Returns the frame of a line segment at a given distance.\n *\n * @param startX the X coordinate the segment starts at\n * @param startY the Y coordinate the segment starts at\n * @param endX the X coordinate the segment ends at\n * @param endY the Y coordinate the segment ends at\n * @param offset the distance from the start of the segment\n * @param length the length of the segment\n * @returns the frame of the segment\n */\nconst lineFrame = (\n startX: number,\n startY: number,\n endX: number,\n endY: number,\n offset: number,\n length: number,\n): PathFrame => {\n const dx = endX - startX;\n const dy = endY - startY;\n const ratio = length > 0 ? Math.min(Math.max(offset / length, 0), 1) : 0;\n return frameFrom({ x: startX + dx * ratio, y: startY + dy * ratio }, dx, dy);\n};\n\n/**\n * Returns the frame of a cubic Bezier segment at a given distance.\n *\n * The `t` ratio of the point is found once and shared with the tangent, so\n * the point and the frame always describe the very same spot on the curve.\n *\n * @param coords the coordinates of the segment\n * @param offset the distance from the start of the segment\n * @param length the length of the segment\n * @returns the frame of the segment\n */\nconst cubicFrame = (coords: CubicCoordinates, offset: number, length: number): PathFrame => {\n const t = offset <= 0 ? 0 : offset >= length ? 1 : getTAtBezierLength(coords, offset);\n const point = getPointAtCubicSegmentLength(coords, t);\n // the first derivative level holds the control points of the derivative\n const derivative = computeBezier(deriveBezier(getBezierPoints(coords))[0], t);\n return frameFrom(point, derivative.x, derivative.y);\n};\n\n/**\n * Returns the frame of a quadratic Bezier segment at a given distance.\n *\n * @param coords the coordinates of the segment\n * @param offset the distance from the start of the segment\n * @param length the length of the segment\n * @returns the frame of the segment\n */\nconst quadFrame = (coords: QuadCoordinates, offset: number, length: number): PathFrame => {\n const t = offset <= 0 ? 0 : offset >= length ? 1 : getTAtBezierLength(coords, offset);\n const point = getPointAtQuadSegmentLength(coords, t);\n const derivative = computeBezier(deriveBezier(getBezierPoints(coords))[0], t);\n return frameFrom(point, derivative.x, derivative.y);\n};\n\n/**\n * Returns the frame of an elliptical arc segment at a given distance.\n *\n * The parametric angle of the arc is found once and shared with the tangent,\n * which is the derivative of the ellipse at that angle.\n *\n * @param startX the X coordinate the segment starts at\n * @param startY the Y coordinate the segment starts at\n * @param RX the radius on X axis\n * @param RY the radius on Y axis\n * @param rotation the ellipse rotation in degrees\n * @param LAF the large arc flag\n * @param SF the sweep flag\n * @param endX the X coordinate the segment ends at\n * @param endY the Y coordinate the segment ends at\n * @param offset the distance from the start of the segment\n * @param length the length of the segment\n * @returns the frame of the segment\n */\nconst arcFrame = (\n startX: number,\n startY: number,\n RX: number,\n RY: number,\n rotation: number,\n LAF: number,\n SF: number,\n endX: number,\n endY: number,\n offset: number,\n length: number,\n): PathFrame => {\n const { center, rx, ry, startAngle, endAngle } = getArcProps(\n startX,\n startY,\n RX,\n RY,\n rotation,\n LAF,\n SF,\n endX,\n endY,\n );\n\n // a zero radius is treated as a straight line to the end point\n if (rx === 0 || ry === 0) {\n return lineFrame(startX, startY, endX, endY, offset, length);\n }\n\n const sweepAngle = endAngle - startAngle;\n const { PI, cos, sin } = Math;\n const xRot = ((rotation % 360) + 360) % 360;\n const xRotRad = xRot * (PI / 180);\n\n // the tangent of the ellipse at the parametric angle, before the rotation\n const tangentAt = (alpha: number): Point => {\n const cosA = cos(alpha);\n const sinA = sin(alpha);\n return {\n x: -cos(xRotRad) * rx * sinA - sin(xRotRad) * ry * cosA,\n y: -sin(xRotRad) * rx * sinA + cos(xRotRad) * ry * cosA,\n };\n };\n\n const pointAt = (alpha: number): Point => {\n const ellipseX = rx * cos(alpha);\n const ellipseY = ry * sin(alpha);\n return {\n x: cos(xRotRad) * ellipseX - sin(xRotRad) * ellipseY + center.x,\n y: sin(xRotRad) * ellipseX + cos(xRotRad) * ellipseY + center.y,\n };\n };\n\n // an arc without a sweep has no direction\n if (length <= 0) {\n return frameFrom({ x: startX, y: startY }, 0, 0);\n }\n\n // the arc is drawn in the direction of the sweep, so the tangent points\n // the other way when the sweep is negative\n const direction = sweepAngle < 0 ? -1 : 1;\n\n if (offset <= 0) {\n const tangent = tangentAt(startAngle);\n return frameFrom({ x: startX, y: startY }, direction * tangent.x, direction * tangent.y);\n }\n\n if (offset >= length) {\n const tangent = tangentAt(endAngle);\n return frameFrom({ x: endX, y: endY }, direction * tangent.x, direction * tangent.y);\n }\n\n // the parametric angle at the given distance, found by interval bisection\n let lo = 0;\n let hi = 1;\n for (let i = 0; i < 25; i += 1) {\n const mid = (lo + hi) / 2;\n if (Math.abs(arcLengthBetween(rx, ry, startAngle, startAngle + sweepAngle * mid)) < offset) {\n lo = mid;\n } else {\n hi = mid;\n }\n }\n const alpha = startAngle + sweepAngle * ((lo + hi) / 2);\n const tangent = tangentAt(alpha);\n return frameFrom(pointAt(alpha), direction * tangent.x, direction * tangent.y);\n};\n\n/**\n * Returns the frame of a path segment at a given distance.\n *\n * The segment has to be an absolute one, with the shorthand commands\n * expanded, so the geometry and the length of the segment agree.\n *\n * @param geometry the absolute segment\n * @param startX the X coordinate the segment starts at\n * @param startY the Y coordinate the segment starts at\n * @param endX the X coordinate the segment ends at\n * @param endY the Y coordinate the segment ends at\n * @param offset the distance from the start of the segment\n * @param length the length of the segment\n * @returns the frame of the segment\n */\nexport const getSegmentFrame = (\n geometry: NormalSegment,\n startX: number,\n startY: number,\n endX: number,\n endY: number,\n offset: number,\n length: number,\n): PathFrame => {\n const command = geometry[0];\n\n // a moveto has no direction, it only holds the start of a sub-path\n if (command === \"M\") {\n return frameFrom({ x: endX, y: endY }, 0, 0);\n }\n\n if (command === \"L\" || command === \"Z\") {\n return lineFrame(startX, startY, endX, endY, offset, length);\n }\n\n if (command === \"C\") {\n const coords = [\n startX,\n startY,\n geometry[1] as number,\n geometry[2] as number,\n geometry[3] as number,\n geometry[4] as number,\n endX,\n endY,\n ] as CubicCoordinates;\n return cubicFrame(coords, offset, length);\n }\n\n if (command === \"Q\") {\n const coords = [\n startX,\n startY,\n geometry[1] as number,\n geometry[2] as number,\n endX,\n endY,\n ] as QuadCoordinates;\n return quadFrame(coords, offset, length);\n }\n\n return arcFrame(\n startX,\n startY,\n geometry[1] as number,\n geometry[2] as number,\n geometry[3] as number,\n geometry[4] as number,\n geometry[5] as number,\n endX,\n endY,\n offset,\n length,\n );\n};\n","import type { PathArray, PathSegment } from \"../types.ts\";\nimport type { SegmentProperties } from \"../interface.ts\";\nimport type { SegmentMeasure } from \"./measureSegments.ts\";\nimport type { PathFrame } from \"./segmentFrame.ts\";\nimport { measureSegments } from \"./measureSegments.ts\";\nimport { getSegmentFrame } from \"./segmentFrame.ts\";\n\n/**\n * Returns the length of a measured segment.\n *\n * The length is taken from the accumulated lengths, the total up to the\n * segment minus the total before it, and not from the length the segment\n * was measured with: the two differ in the last bits, and this keeps the\n * result identical to the one the previous implementation returned.\n *\n * @param measure - the measured segment\n * @returns the length of the segment\n */\nconst segmentLength = (measure: SegmentMeasure): number =>\n measure.lengthAtSegment + measure.length - measure.lengthAtSegment;\n\n/**\n * Returns the frame of a measured segment at a given distance.\n *\n * @param measure - the measured segment\n * @param offset - the distance from the start of the segment\n * @returns the frame of the segment\n */\nconst frameOf = (measure: SegmentMeasure | undefined, offset = 0): PathFrame => {\n // an empty path has no frame, but the result still has to be well formed\n if (!measure) {\n return {\n point: { x: 0, y: 0 },\n tangent: { x: 0, y: 0 },\n normal: { x: 0, y: 0 },\n angle: 0,\n };\n }\n return getSegmentFrame(\n measure.geometry,\n measure.startX,\n measure.startY,\n measure.endX,\n measure.endY,\n offset,\n measure.length,\n );\n};\n\nexport const getPropertiesFromMeasure = (\n measure: SegmentMeasure,\n offset: number,\n): SegmentProperties => ({\n segment: measure.segment,\n index: measure.index,\n length: segmentLength(measure),\n lengthAtSegment: measure.lengthAtSegment,\n ...frameOf(measure, offset),\n});\n\n/**\n * Returns the segment, its index and length as well as\n * the length to that segment at a given length in a path.\n *\n * The point at the given length is returned with the frame of the path at\n * that point: the unit tangent vector, the unit normal vector and the angle\n * of the tangent in degrees.\n *\n * @param measures - the measured segments of the path\n * @param distance - the given length\n * @returns the requested properties\n */\nexport const getPropertiesFromMeasures = (\n measures: SegmentMeasure[],\n distance?: number,\n): SegmentProperties => {\n const lastIndex = measures.length - 1;\n\n // an empty path has no segment, but the result still has to be well formed\n const segment = (measures[0]?.segment ?? [\"M\", 0, 0]) as PathSegment;\n\n // If the path is empty, return 0.\n // an infinite distance is not an error, it is out of range and clamps\n // to the last segment like any other out of range distance\n if (lastIndex <= 0 || !distance || distance < 0) {\n return {\n segment,\n index: 0,\n length: 0,\n lengthAtSegment: 0,\n ...frameOf(measures[0]),\n };\n }\n\n const last = measures[lastIndex];\n const pathLength = last.lengthAtSegment + last.length;\n\n if (distance >= pathLength) {\n return {\n segment: last.segment,\n index: last.index,\n length: segmentLength(last),\n lengthAtSegment: last.lengthAtSegment,\n ...frameOf(last, distance - last.lengthAtSegment),\n };\n }\n\n // the segment is the last one whose accumulated length does not exceed\n // the distance, a zero length segment wins over the one before it\n // the first drawable segment always starts at the length zero, so it is\n // the fallback when no later segment matches\n let index = 1;\n for (let i = lastIndex; i > 0; i--) {\n if (measures[i].lengthAtSegment <= distance) {\n index = i;\n break;\n }\n }\n\n const measure = measures[index];\n return {\n segment: measure.segment,\n index: measure.index,\n length: segmentLength(measure),\n lengthAtSegment: measure.lengthAtSegment,\n ...frameOf(measure, distance - measure.lengthAtSegment),\n };\n};\n\n/**\n * Returns the segment, its index and length as well as\n * the length to that segment at a given length in a path.\n *\n * The point at the given length is returned with the frame of the path at\n * that point: the unit tangent vector, the unit normal vector and the angle\n * of the tangent in degrees.\n *\n * @param pathInput target `pathArray`\n * @param distance the given length\n * @returns the requested properties\n */\nexport const getPropertiesAtLength = <T extends PathArray>(\n pathInput: string | T,\n distance?: number,\n): SegmentProperties => {\n // one pass over the path, the measure table holds the length of every\n // segment and the length accumulated before it\n return getPropertiesFromMeasures(measureSegments(pathInput), distance);\n};\n","import type { PathArray, Point } from \"../types.ts\";\nimport type { PointProperties } from \"../interface.ts\";\nimport type { SegmentMeasure } from \"./measureSegments.ts\";\nimport { buildPathLengthTableFromMeasures, getPointAtTable } from \"./pathLengthTable.ts\";\nimport { getPropertiesFromMeasure } from \"./getPropertiesAtLength.ts\";\nimport { measureSegments } from \"./measureSegments.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\n\n/**\n * The relative difference below which two distances are the same.\n *\n * The distance of a point to a path is squared, so the noise of the floating\n * point arithmetic is relative to the distance itself. A path that runs at\n * a constant distance from the point — a circle around it — has no minimum at\n * all, and the noise of the samples must not be read as one.\n */\nconst distanceEpsilon = 1e-7;\n\n/**\n * The precision of the refinement of the closest point.\n *\n * The precision is relative to the length of the path: a path of a few units\n * needs a finer precision than a path of thousands of units, and the answer\n * of a short path is expected to be as exact as the answer of a long one. The\n * relative floor is capped, so a very long path does not trade the accuracy\n * of its distance for a path-relative length precision.\n */\nconst precisionShare = 1e-9;\nconst maxPrecisionFloor = 1e-6;\n\n/**\n * The number of samples of the coarse scan of a short path.\n *\n * The scan of the path is spread over its length, so a short path is sampled\n * more densely than a long one: the place where the path passes closest to\n * the point must not fall between two samples of the scan.\n */\nconst minSamples = 64;\n\n/**\n * The maximum number of samples of the coarse scan of a path.\n *\n * The scan is dense enough to find the place where the path passes closest\n * to the point, but it stays bounded for a long path: the length of the path\n * is divided into this many intervals at most.\n */\nconst maxSamples = 4096;\n\n/**\n * The step of the coarse scan of a long path, in units of length.\n */\nconst maxScanStep = 8;\n\n/**\n * Finds the index of the segment a distance falls into.\n *\n * The segment is the last one whose accumulated length is below the\n * distance, the same segment the lookup of a point at that distance uses.\n *\n * @param measures - the measured segments of the path\n * @param distance - the distance along the path\n * @returns the index of the segment\n */\nconst findSegmentIndex = (measures: SegmentMeasure[], distance: number): number => {\n if (distance <= 0) return 0;\n\n let low = 0;\n let high = measures.length - 1;\n while (low < high) {\n const mid = (low + high + 1) >> 1;\n if (measures[mid].lengthAtSegment <= distance) {\n low = mid;\n } else {\n high = mid - 1;\n }\n }\n return low;\n};\n\n/**\n * Returns the closest point of a straight segment.\n *\n * The projection of the point on the line of the segment is the closest\n * point of the segment when it falls on the segment, and the closest end of\n * the segment when it does not. The projection is computed along the direction\n * of the segment, so a point that is on the segment is answered with itself.\n *\n * @param point - the point to project\n * @param startX - the X coordinate of the start of the segment\n * @param startY - the Y coordinate of the start of the segment\n * @param endX - the X coordinate of the end of the segment\n * @param endY - the Y coordinate of the end of the segment\n * @returns the closest point of the segment and its position on the segment\n */\nconst projectOnSegment = (\n point: Point,\n startX: number,\n startY: number,\n endX: number,\n endY: number,\n): { point: Point; ratio: number } => {\n const dx = endX - startX;\n const dy = endY - startY;\n const length = Math.hypot(dx, dy);\n // a segment without a length is a point\n /* istanbul ignore next */\n if (!length) return { point: { x: startX, y: startY }, ratio: 0 };\n\n // the projection has to be on the segment\n const ratio = ((point.x - startX) * dx + (point.y - startY) * dy) / (length * length);\n const clamped = Math.max(0, Math.min(1, ratio));\n return {\n point: { x: startX + dx * clamped, y: startY + dy * clamped },\n ratio: clamped,\n };\n};\n\n/**\n * Returns the point and segment in path closest to a given point as well as\n * the distance to the path stroke.\n *\n * @see https://bl.ocks.org/mbostock/8027637\n *\n * @param pathInput target `pathArray`\n * @param point the given point\n * @returns the requested properties\n */\nexport const getPropertiesAtPoint = <T extends PathArray>(\n pathInput: string | T,\n point: Point,\n): PointProperties => {\n const path = parsePathString(pathInput);\n // an empty path has no closest point\n if (!path.length) {\n return { closest: { x: 0, y: 0 }, distance: Infinity };\n }\n // one pass over the path, the measure table holds the length of every\n // segment and the length accumulated before it\n const segmentMeasures = measureSegments(path);\n const table = buildPathLengthTableFromMeasures(segmentMeasures);\n const pathLength = table.totalLength;\n // a loop ends where it starts, so the search can walk over the end of the\n // path and find the other side of the join\n const isLoop = table.isLoop;\n const distanceTo = (p: Point) => {\n const dx = p.x - point.x;\n const dy = p.y - point.y;\n return dx * dx + dy * dy;\n };\n // the step of the coarse scan, in units of length: a path that is shorter\n // than the step would be sampled at its ends only, so the step is a share\n // of the length of the path — a short path is sampled more densely, so the\n // place where the path passes closest to the point is not missed. The step\n // grows again for a very long path, so the number of samples stays bounded\n const scanStep = pathLength\n ? Math.max(pathLength / maxSamples, Math.min(maxScanStep, pathLength / minSamples))\n : maxScanStep;\n // the local minima of the scanned distance are the places where the path\n // passes near the point: a path can pass near it more than once — a closed\n // sub-path returns to its own start, so the point is sampled twice — and\n // every one of those places has to be searched\n const candidates: { length: number; distance: number; point: Point }[] = [];\n let bestLength = 0;\n let bestDistance = Infinity;\n let bestPoint: Point = { x: 0, y: 0 };\n let previousDistance = Infinity;\n let lastLength = 0;\n let lastDistance = Infinity;\n let lastPoint: Point = { x: 0, y: 0 };\n let lastScannedLength = -1;\n\n // the scan of the path: every sample is a point of the path, and the\n // distance to the point is measured\n const scan = (scanLength: number) => {\n if (scanLength <= lastScannedLength) return;\n lastScannedLength = scanLength;\n const scanPoint = getPointAtTable(table, scanLength);\n const scanDistance = distanceTo(scanPoint);\n\n // the last sample is a local minimum when the distance starts to grow\n // and it was not growing before it\n if (\n lastDistance < scanDistance - scanDistance * distanceEpsilon &&\n lastDistance <= previousDistance + previousDistance * distanceEpsilon\n ) {\n candidates.push({\n length: lastLength,\n distance: lastDistance,\n point: lastPoint,\n });\n }\n\n previousDistance = lastDistance;\n lastLength = scanLength;\n lastDistance = scanDistance;\n lastPoint = scanPoint;\n\n if (scanDistance < bestDistance) {\n bestLength = scanLength;\n bestDistance = scanDistance;\n bestPoint = scanPoint;\n }\n };\n\n // every segment is scanned on its own, so a short segment between two long\n // ones cannot fall between two samples of a scan of the whole path\n for (const measure of segmentMeasures) {\n const segmentStart = measure.lengthAtSegment;\n const segmentEnd = segmentStart + measure.length;\n for (let scanLength = segmentStart; scanLength < segmentEnd; scanLength += scanStep) {\n scan(scanLength);\n }\n scan(segmentEnd);\n }\n\n // the path can end with a minimum too\n if (lastDistance < previousDistance - previousDistance * distanceEpsilon) {\n candidates.push({\n length: lastLength,\n distance: lastDistance,\n point: lastPoint,\n });\n }\n\n // the binary search for the precise estimate, around one length\n const refine = (start: { length: number; distance: number; point: Point }) => {\n let { length, distance } = start;\n let closest = start.point;\n let precision = scanStep / 2;\n let beforeLength = 0;\n let afterLength = 0;\n // the search cannot go below the precision of the arithmetic, so the\n // precision is a share of the length of the path with an absolute cap\n const precisionFloor = Math.min(Math.max(pathLength * precisionShare, 1e-9), maxPrecisionFloor);\n\n while (precision > precisionFloor) {\n beforeLength = length - precision;\n afterLength = length + precision;\n // a loop is walked over its end, an open path is not\n if (beforeLength < 0) {\n beforeLength = isLoop ? beforeLength + pathLength : -1;\n }\n if (afterLength > pathLength) {\n afterLength = isLoop ? afterLength - pathLength : pathLength + 1;\n }\n\n const before =\n beforeLength >= 0 && beforeLength <= pathLength\n ? getPointAtTable(table, beforeLength)\n : null;\n const after =\n afterLength >= 0 && afterLength <= pathLength ? getPointAtTable(table, afterLength) : null;\n const beforeDistance = before ? distanceTo(before) : Infinity;\n const afterDistance = after ? distanceTo(after) : Infinity;\n\n if (before && beforeDistance < distance) {\n closest = before;\n length = beforeLength;\n distance = beforeDistance;\n } else if (after && afterDistance < distance) {\n closest = after;\n length = afterLength;\n distance = afterDistance;\n } else {\n precision /= 2;\n }\n }\n\n // the walk approximates the closest point, so the answer is snapped to\n // the exact projection of the point on the straight segment it is on\n const measure = segmentMeasures[findSegmentIndex(segmentMeasures, length)];\n const command = measure.geometry[0];\n if (command === \"L\" || command === \"Z\") {\n const { point: projected, ratio } = projectOnSegment(\n point,\n measure.startX,\n measure.startY,\n measure.endX,\n measure.endY,\n );\n const dx = point.x - projected.x;\n const dy = point.y - projected.y;\n const projectedDistance = dx * dx + dy * dy;\n if (projectedDistance < distance) {\n closest = projected;\n distance = projectedDistance;\n length = measure.lengthAtSegment + ratio * measure.length;\n }\n }\n\n return { closest, distance, length, measure };\n };\n\n // the best sample of the scan is searched first: it is not a local minimum\n // of the distance when the path runs at a constant distance from the point\n const best = refine({\n length: bestLength,\n distance: bestDistance,\n point: bestPoint,\n });\n let closest = best.closest;\n let closestDistance = best.distance;\n let closestLength = best.length;\n let closestMeasure = best.measure;\n\n // the other places where the path passes near the point, the closest ones\n // first: the sampled distance of a place is an upper bound of the distance\n // of the path there, so a place that is not closer than the answer can\n // still be the one that answers it\n candidates.sort((a, b) => a.distance - b.distance);\n for (const candidate of candidates) {\n const refined = refine(candidate);\n if (refined.distance < closestDistance) {\n closest = refined.closest;\n closestDistance = refined.distance;\n closestLength = refined.length;\n closestMeasure = refined.measure;\n }\n }\n\n for (const measure of segmentMeasures) {\n const command = measure.geometry[0];\n let projected: Point;\n let ratio = 0;\n if (command === \"M\") {\n projected = { x: measure.endX, y: measure.endY };\n } else if (command === \"L\" || command === \"Z\") {\n const projection = projectOnSegment(\n point,\n measure.startX,\n measure.startY,\n measure.endX,\n measure.endY,\n );\n projected = projection.point;\n ratio = projection.ratio;\n } else {\n continue;\n }\n\n const dx = point.x - projected.x;\n const dy = point.y - projected.y;\n const projectedDistance = dx * dx + dy * dy;\n if (!Number.isFinite(projectedDistance) || projectedDistance >= closestDistance) continue;\n\n const projectedLength = measure.lengthAtSegment + ratio * measure.length;\n\n closest = projected;\n closestDistance = projectedDistance;\n closestLength = projectedLength;\n closestMeasure = measure;\n }\n\n const segment = getPropertiesFromMeasure(\n closestMeasure,\n Math.max(0, Math.min(closestMeasure.length, closestLength - closestMeasure.lengthAtSegment)),\n );\n\n return { closest, distance: Math.sqrt(closestDistance), segment };\n};\n","import type { PathArray } from \"../types.ts\";\nimport { getPropertiesAtPoint } from \"./getPropertiesAtPoint.ts\";\n\n/**\n * Returns the point in path closest to a given point.\n *\n * @param pathInput target `pathArray`\n * @param point the given point\n * @returns the best match\n */\nexport const getClosestPoint = (\n pathInput: string | PathArray,\n point: { x: number; y: number },\n): { x: number; y: number } => {\n return getPropertiesAtPoint(pathInput, point).closest;\n};\n","import { pathToCurve } from \"../convert/pathToCurve.ts\";\nimport type { CurveArray, PathArray, PointTuple } from \"../types.ts\";\n\n/**\n * Returns the area of a single cubic-bezier segment.\n *\n * http://objectmix.com/graphics/133553-area-closed-bezier-curve.html\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param c1x the first control point X\n * @param c1y the first control point Y\n * @param c2x the second control point X\n * @param c2y the second control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns the area of the cubic-bezier segment\n */\nconst getCubicSegArea = (\n x1: number,\n y1: number,\n c1x: number,\n c1y: number,\n c2x: number,\n c2y: number,\n x2: number,\n y2: number,\n) => {\n return (\n (3 *\n ((y2 - y1) * (c1x + c2x) -\n (x2 - x1) * (c1y + c2y) +\n c1y * (x1 - c2x) -\n c1x * (y1 - c2y) +\n y2 * (c2x + x1 / 3) -\n x2 * (c2y + y1 / 3))) /\n 20\n );\n};\n\n/**\n * Returns the signed area of a shape.\n *\n * @author Jürg Lehni & Jonathan Puckey\n *\n * @see https://github.com/paperjs/paper.js/blob/develop/src/path/Path.js\n *\n * @param path - The shape PathArray\n * @returns The signed area of the shape (positive for clockwise, negative for counter-clockwise)\n *\n * @example\n * ```ts\n * getPathArea([['M', 0, 0], ['L', 100, 0], ['L', 100, 100], ['L', 0, 100], ['Z']])\n * // => 10000 (clockwise square)\n * ```\n */\nexport const getPathArea = <T extends PathArray | string>(path: T): number =>\n getCurveArea(pathToCurve(path));\n\n/**\n * Returns the signed area of a path that is already made of cubic beziers.\n *\n * The conversion is the expensive part of the area calculation, so it is\n * kept out of this function: a caller that already has a curve array does\n * not have to convert it a second time.\n *\n * @param path - The curve PathArray\n * @returns The signed area of the shape\n */\nexport const getCurveArea = (path: CurveArray): number => {\n let x = 0;\n let y = 0;\n let len = 0;\n\n return path\n .map((seg) => {\n switch (seg[0]) {\n case \"M\":\n [, x, y] = seg;\n return 0;\n default:\n len = getCubicSegArea(x, y, seg[1], seg[2], seg[3], seg[4], seg[5], seg[6]);\n [x, y] = seg.slice(-2) as PointTuple;\n return len;\n }\n })\n .reduce((a, b) => a + b, 0);\n};\n","import { getCurveArea } from \"./getPathArea.ts\";\nimport { pathToCurve } from \"../convert/pathToCurve.ts\";\nimport type { PathArray } from \"../types.ts\";\n\n/**\n * Check if a path is drawn clockwise and returns true if so,\n * false otherwise.\n *\n * @param path the path string or `pathArray`\n * @returns true when clockwise or false if not\n */\nexport const getDrawDirection = (path: string | PathArray): boolean => {\n return getCurveArea(pathToCurve(path)) >= 0;\n};\n","import type { NormalArray, PathArray, PathCommand } from \"../types.ts\";\nimport { normalizeSegment } from \"./normalizeSegment.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { paramsParser } from \"../parser/paramsParser.ts\";\nimport { iterate } from \"./iterate.ts\";\n\n/**\n * Parses a path string or PathArray, then iterates the result for:\n * * converting segments to absolute values\n * * converting shorthand commands to their non-shorthand notation\n *\n * @param pathInput - The path string or PathArray\n * @returns The normalized PathArray\n *\n * @example\n * ```ts\n * normalizePath('M10 90s20 -80 40 -80s20 80 40 80')\n * // => [['M', 10, 90], ['C', 10, 90, 30, 10, 50, 10], ['C', 70, 10, 70, 90, 90, 90]]\n * ```\n */\nexport const normalizePath = <T extends string | PathArray>(pathInput: T): NormalArray => {\n const path = parsePathString(pathInput);\n const params = { ...paramsParser };\n let prevCommand: PathCommand | null = null;\n\n return iterate(path, (seg, _, lastX, lastY) => {\n params.x = lastX;\n params.y = lastY;\n const result = normalizeSegment(seg, params, prevCommand);\n\n const seglen = result.length;\n params.x1 = +result[seglen - 2];\n params.y1 = +result[seglen - 1];\n // only cubic and quadratic segments carry a reflectable control point\n if (result[0] === \"C\" || result[0] === \"Q\") {\n params.x2 = +result[seglen - 4];\n params.y2 = +result[seglen - 3];\n } else {\n params.x2 = null;\n params.y2 = null;\n }\n prevCommand = result[0];\n\n return result;\n }) as NormalArray;\n};\n","import type { NormalArray, PathArray } from \"../types.ts\";\nimport { normalizePath } from \"../process/normalizePath.ts\";\nimport { buildPathLengthTable, getPointAtTable } from \"./pathLengthTable.ts\";\n\n/**\n * Returns [x,y] coordinates of a point at a given length along a path.\n *\n * @param pathInput - The PathArray or path string to look into\n * @param distance - The distance along the path\n * @returns The requested {x, y} point coordinates\n *\n * @example\n * ```ts\n * getPointAtLength('M0 0L100 0L100 100Z', 50)\n * // => { x: 50, y: 0 }\n * ```\n */\nexport const getPointAtLength = <T extends PathArray>(\n pathInput: string | T,\n distance?: number,\n): { x: number; y: number } => {\n return getPointAtNormalizedLength(normalizePath(pathInput), distance);\n};\n\n/**\n * Returns [x,y] coordinates of a point at a given length along a path\n * that is already normalized.\n *\n * The normalization is the expensive part of the lookup, so it is kept\n * out of this function: a caller that already has a normalized path does\n * not have to normalize it again for every point it looks up.\n *\n * @param path - The normalized PathArray to look into\n * @param distance - The distance along the path\n * @returns The requested {x, y} point coordinates\n */\nexport const getPointAtNormalizedLength = (\n path: NormalArray,\n distance?: number,\n): { x: number; y: number } => {\n return getPointAtTable(buildPathLengthTable(path), distance);\n};\n","import type { PathArray, PathSegment } from \"../types.ts\";\nimport { getPropertiesAtLength } from \"./getPropertiesAtLength.ts\";\n\n/**\n * Returns the segment at a given length.\n *\n * @param pathInput the target `pathArray`\n * @param distance the distance in path to look at\n * @returns the requested segment\n */\nexport const getSegmentAtLength = <T extends PathArray>(\n pathInput: string | T,\n distance?: number,\n): PathSegment | undefined => {\n return getPropertiesAtLength(pathInput, distance).segment;\n};\n","import type { SegmentProperties } from \"../interface.ts\";\nimport type { PathArray } from \"../types.ts\";\nimport { getPropertiesAtPoint } from \"./getPropertiesAtPoint.ts\";\n\n/**\n * Returns the path segment which contains a given point.\n *\n * @param path the `pathArray` to look into\n * @param point the point of the shape to look for\n * @returns the requested segment\n */\nexport const getSegmentOfPoint = <T extends PathArray>(\n path: string | T,\n point: { x: number; y: number },\n): SegmentProperties | undefined => {\n return getPropertiesAtPoint(path, point).segment;\n};\n","import type { PathArray, PathSegment, RelativeCommand } from \"../types.ts\";\nimport { paramsCounts } from \"../parser/paramsCount.ts\";\n\n/**\n * Iterates an array to check if it's an actual `pathArray`.\n *\n * @param path the `pathArray` to be checked\n * @returns iteration result\n */\nexport const isPathArray = (path: unknown): path is PathArray => {\n return (\n Array.isArray(path) &&\n path.every((seg: PathSegment) => {\n const command = (seg as PathSegment | undefined)?.[0];\n if (typeof command !== \"string\") return false;\n const lk = command.toLowerCase() as RelativeCommand;\n return (\n paramsCounts[lk] === seg.length - 1 &&\n \"achlmqstvz\".includes(lk) &&\n (seg.slice(1) as unknown[]).every(Number.isFinite)\n );\n }) &&\n path.length > 0\n );\n};\n","import type { AbsoluteArray } from \"../types.ts\";\nimport { isPathArray } from \"./isPathArray.ts\";\n\n/**\n * Iterates an array to check if it's a `pathArray`\n * with all absolute values.\n *\n * @param path the `pathArray` to be checked\n * @returns iteration result\n */\nexport const isAbsoluteArray = (path: unknown): path is AbsoluteArray => {\n return (\n isPathArray(path) &&\n // `isPathArray` also checks if it's `Array`\n path.every(([x]) => x === x.toUpperCase())\n );\n};\n","import type { NormalArray } from \"../types.ts\";\nimport { isAbsoluteArray } from \"./isAbsoluteArray.ts\";\n\n/**\n * Iterates an array to check if it's a `pathArray`\n * with all segments in non-shorthand notation\n * with absolute values.\n *\n * @param path - the array to be checked\n * @returns true if the array is a normalized path array\n */\nexport const isNormalizedArray = (path: unknown): path is NormalArray => {\n // `isAbsoluteArray` also checks if it's `Array`\n return isAbsoluteArray(path) && path.every(([pc]) => \"ACLMQZ\".includes(pc));\n};\n","import type { CurveArray } from \"../types.ts\";\nimport { isNormalizedArray } from \"./isNormalizedArray.ts\";\n\n/**\n * Iterates an array to check if it's a `pathArray`\n * with all C (cubic bezier) segments.\n *\n * @param path the `Array` to be checked\n * @returns iteration result\n */\nexport const isCurveArray = (path: unknown): path is CurveArray => {\n // `isPathArray` also checks if it's `Array`\n return isNormalizedArray(path) && path.every(([pc]) => \"MC\".includes(pc));\n};\n","import type { PathArray, Point } from \"../types.ts\";\nimport type { StrokeOptions } from \"../interface.ts\";\nimport { getPropertiesAtPoint } from \"./getPropertiesAtPoint.ts\";\nimport { error } from \"./error.ts\";\nimport DISTANCE_EPSILON from \"./distanceEpsilon.ts\";\n\n/**\n * Checks if a given point is in the stroke of a path.\n *\n * Without a width the point has to be on the path itself, within the\n * distance epsilon of it. With a width the stroke is the band around the\n * path: the point is in the stroke when it is at most half the width away\n * from the path. The ends of an open path are treated as if the stroke had\n * round caps, so a point beyond the end of the path is in the stroke too.\n *\n * @param pathInput target path\n * @param point the given `{x,y}` point\n * @param options the options of the test\n * @returns the query result\n *\n * @example\n * ```ts\n * isPointInStroke('M0 0L100 0', { x: 50, y: 0 });\n * // => true\n * isPointInStroke('M0 0L100 0', { x: 50, y: 5 }, { width: 10 });\n * // => true\n * ```\n */\nexport const isPointInStroke = <T extends PathArray>(\n pathInput: string | T,\n point: Point,\n options?: StrokeOptions,\n): boolean => {\n const { width = 0 } = options ?? {};\n\n if (typeof width !== \"number\" || !Number.isFinite(width) || width < 0) {\n throw TypeError(`${error}: width must be a number greater than or equal to 0`);\n }\n\n const { distance } = getPropertiesAtPoint(pathInput, point);\n\n // without a width the point has to be on the path itself\n if (!width) return distance < DISTANCE_EPSILON;\n\n // the stroke is the band around the path\n return distance <= width / 2;\n};\n","import type { CubicCoordinates, CurveArray, Point } from \"../types.ts\";\nimport { getPointAtCubicSegmentLength } from \"../math/cubicTools.ts\";\n\n/**\n * Returns the number of intervals a cubic segment is split into.\n *\n * The second differences of the control points bound the distance of the\n * curve to its chord, and the distance of a piece of the curve to the chord\n * of the piece falls with the square of the number of the pieces, so the\n * number of the intervals is the square root of the ratio of the bound to\n * the tolerance.\n *\n * @param coords - the coordinates of the cubic segment\n * @param tolerance - the maximum distance between the curve and its chords\n * @returns the number of intervals\n */\nconst getIntervalCount = (coords: CubicCoordinates, tolerance: number): number => {\n const [x1, y1, c1x, c1y, c2x, c2y, x2, y2] = coords;\n // the second differences of the control points\n const d1 = Math.hypot(x1 - 2 * c1x + c2x, y1 - 2 * c1y + c2y);\n const d2 = Math.hypot(c1x - 2 * c2x + x2, c1y - 2 * c2y + y2);\n // the bound of the distance of the curve to its chord\n const flatness = 0.75 * Math.max(d1, d2);\n // a straight segment is one interval\n if (flatness <= tolerance) return 1;\n\n return Math.ceil(Math.sqrt(flatness / tolerance));\n};\n\n/**\n * Flattens a path into polygons, one for every sub-path.\n *\n * The curves of the path are split into chords that stay within the\n * tolerance of the curve, and every sub-path is closed, the way a fill\n * closes an open path.\n *\n * @param path - the curve path to flatten\n * @param tolerance - the maximum distance between the curve and its chords\n * @returns the polygons of the path\n */\nexport const flattenPath = (path: CurveArray, tolerance: number): Point[][] => {\n const polygons: Point[][] = [];\n let points: Point[] = [];\n let current: Point = { x: 0, y: 0 };\n\n for (const segment of path) {\n if (segment[0] === \"M\") {\n // the sub-path before this one is closed\n if (points.length > 1) polygons.push(points);\n current = { x: segment[1] as number, y: segment[2] as number };\n points = [current];\n continue;\n }\n\n // a curve path holds no other command than the cubic\n const coords = [\n current.x,\n current.y,\n segment[1] as number,\n segment[2] as number,\n segment[3] as number,\n segment[4] as number,\n segment[5] as number,\n segment[6] as number,\n ] as CubicCoordinates;\n const count = getIntervalCount(coords, tolerance);\n\n for (let i = 1; i <= count; i += 1) {\n const point = getPointAtCubicSegmentLength(coords, i / count);\n points.push(point);\n }\n current = { x: segment[5] as number, y: segment[6] as number };\n }\n\n // the last sub-path is closed too\n if (points.length > 1) polygons.push(points);\n\n return polygons;\n};\n","import type { Point } from \"../types.ts\";\n\n/**\n * Returns the distance from a point to a line segment.\n *\n * The distance is the one to the segment, not to the infinite line: a point\n * beyond the end of the segment is at the distance to that end.\n *\n * @param point - the point to measure\n * @param start - the start of the segment\n * @param end - the end of the segment\n * @returns the distance from the point to the segment\n */\nexport const distanceToSegment = (point: Point, start: Point, end: Point): number => {\n const dx = end.x - start.x;\n const dy = end.y - start.y;\n const lengthSquared = dx * dx + dy * dy;\n // a segment without a length is a point\n if (lengthSquared === 0) {\n const px = point.x - start.x;\n const py = point.y - start.y;\n return Math.sqrt(px * px + py * py);\n }\n let ratio = ((point.x - start.x) * dx + (point.y - start.y) * dy) / lengthSquared;\n ratio = ratio < 0 ? 0 : ratio > 1 ? 1 : ratio;\n const px = point.x - (start.x + dx * ratio);\n const py = point.y - (start.y + dy * ratio);\n return Math.sqrt(px * px + py * py);\n};\n","import type { Point } from \"../types.ts\";\nimport { distanceToSegment } from \"./distanceToSegment.ts\";\n\n/**\n * Returns the number of times a ray from a point crosses a polygon.\n *\n * The ray goes to the right, so every edge of the polygon that crosses the\n * height of the point after it is counted. The parity of the count is the\n * answer of the `evenodd` fill rule.\n *\n * @param polygon - the polygon to test\n * @param point - the point to test\n * @returns the number of crossings\n */\nexport const getPolygonCrossings = (polygon: Point[], point: Point): number => {\n const { x, y } = point;\n const count = polygon.length;\n let crossings = 0;\n\n for (let i = 0; i < count; i += 1) {\n const j = (i + 1) % count;\n const current = polygon[i];\n const next = polygon[j];\n // the edge is on one side of the height of the point, it does not cross\n if (current.y > y === next.y > y) continue;\n // the X of the edge at the height of the point\n const at = ((next.x - current.x) * (y - current.y)) / (next.y - current.y) + current.x;\n // the crossing is after the point, the ray reaches it\n if (x < at) crossings += 1;\n }\n\n return crossings;\n};\n\n/**\n * Returns the winding number of a polygon around a point.\n *\n * Every edge that crosses the height of the point counts, the direction of\n * the crossing decides the sign of the count. The winding number is zero\n * outside of the polygon and it is not zero inside of it, whatever the\n * direction of the polygon is, so its sign is the direction of the shape.\n *\n * @param polygon - the polygon to test\n * @param point - the point to test\n * @returns the winding number\n */\nexport const getPolygonWindingNumber = (polygon: Point[], point: Point): number => {\n const { x, y } = point;\n const count = polygon.length;\n let winding = 0;\n\n for (let i = 0; i < count; i += 1) {\n const j = (i + 1) % count;\n const current = polygon[i];\n const next = polygon[j];\n // the side of the point relative to the edge\n const side = (next.x - current.x) * (y - current.y) - (next.y - current.y) * (x - current.x);\n if (current.y <= y) {\n // an upward crossing\n if (next.y > y && side > 0) winding += 1;\n } else if (next.y <= y && side < 0) {\n // a downward crossing\n winding -= 1;\n }\n }\n\n return winding;\n};\n\n/**\n * Checks if a point is on the boundary of a polygon.\n *\n * @param polygon - the polygon to test\n * @param point - the point to test\n * @param epsilon - the maximum distance to the boundary\n * @returns whether the point is on the boundary\n */\nexport const isPointOnPolygon = (polygon: Point[], point: Point, epsilon: number): boolean => {\n const count = polygon.length;\n\n for (let i = 0; i < count; i += 1) {\n const j = (i + 1) % count;\n if (distanceToSegment(point, polygon[i], polygon[j]) <= epsilon) {\n return true;\n }\n }\n\n return false;\n};\n","import type { PathArray, Point } from \"../types.ts\";\nimport type { PointInPathOptions } from \"../interface.ts\";\nimport { pathToCurve } from \"../convert/pathToCurve.ts\";\nimport { flattenPath } from \"../process/flattenPath.ts\";\nimport {\n getPolygonCrossings,\n getPolygonWindingNumber,\n isPointOnPolygon,\n} from \"../math/pointInPolygon.ts\";\nimport { error } from \"./error.ts\";\n\n/**\n * The distance a point can be from the boundary of a shape and still be on it.\n *\n * The tolerance of the flattening is the error of the approximation, not the\n * width of the boundary, so the boundary is tested with a tight distance.\n */\nconst boundaryEpsilon = 1e-9;\n\n/**\n * Checks if a given point is inside a path.\n *\n * The path is flattened into polygons and the point is tested against them\n * with the fill rule of the path: the `nonzero` rule counts the windings of\n * the polygons around the point, the `evenodd` rule counts the crossings of\n * the polygons with a ray from the point. A point on the boundary of the\n * shape is inside of it, the way the browser answers it.\n *\n * The curves of the path are approximated with chords that stay within the\n * tolerance of the curve, so the answer is exact except for the points that\n * are within the tolerance of the boundary of a curve.\n *\n * @param pathInput target path\n * @param point the given `{x,y}` point\n * @param options the options of the test\n * @returns the query result\n *\n * @example\n * ```ts\n * isPointInPath('M0 0L100 0L100 100L0 100Z', { x: 50, y: 50 });\n * // => true\n * ```\n */\nexport const isPointInPath = <T extends PathArray>(\n pathInput: string | T,\n point: Point,\n options?: PointInPathOptions,\n): boolean => {\n const { fillRule = \"nonzero\", tolerance = 0.1 } = options ?? {};\n\n if (fillRule !== \"nonzero\" && fillRule !== \"evenodd\") {\n throw TypeError(`${error}: fillRule must be \"nonzero\" or \"evenodd\"`);\n }\n if (typeof tolerance !== \"number\" || !Number.isFinite(tolerance) || tolerance <= 0) {\n throw TypeError(`${error}: tolerance must be a positive number`);\n }\n\n const path = pathToCurve(pathInput);\n // an empty path has no inside\n if (!path.length) return false;\n\n const polygons = flattenPath(path, tolerance);\n let crossings = 0;\n let winding = 0;\n\n for (const polygon of polygons) {\n // a point on the boundary of the shape is inside of it\n if (isPointOnPolygon(polygon, point, boundaryEpsilon)) return true;\n crossings += getPolygonCrossings(polygon, point);\n winding += getPolygonWindingNumber(polygon, point);\n }\n\n return fillRule === \"evenodd\" ? crossings % 2 === 1 : winding !== 0;\n};\n","import { isNormalizedArray } from \"./isNormalizedArray.ts\";\nimport type { PathArray, PolygonArray } from \"../types.ts\";\n/**\n * Checks if a path is a polygon (only M, L, H, V, Z commands).\n * @param pathArray PathArray (pre-normalize if needed)\n * @returns boolean\n */\nexport const isPolygonArray = (path: PathArray): path is PolygonArray => {\n return isNormalizedArray(path) && path.every(([pc]) => \"MLVHZ\".includes(pc));\n};\n","import { isNormalizedArray } from \"./isNormalizedArray.ts\";\nimport type { PathArray, PolylineArray } from \"../types.ts\";\n/**\n * Checks if a path is a polyline (only M, L, H, V commands).\n * @param pathArray PathArray (pre-normalize if needed)\n * @returns boolean\n */\nexport function isPolylineArray(path: PathArray): path is PolylineArray {\n return isNormalizedArray(path) && path.every(([pc]) => \"MLVH\".includes(pc));\n}\n","import type { RelativeArray } from \"../types.ts\";\nimport { isPathArray } from \"./isPathArray.ts\";\n\n/**\n * Iterates an array to check if it's a `pathArray`\n * with relative values.\n *\n * @param path the `pathArray` to be checked\n * @returns iteration result\n */\nexport const isRelativeArray = (path: unknown): path is RelativeArray => {\n return (\n isPathArray(path) &&\n // `isPathArray` checks if it's `Array`\n path.slice(1).every(([pc]) => pc === pc.toLowerCase())\n );\n};\n","import { scanSegment } from \"../parser/scanSegment.ts\";\nimport { skipSpaces } from \"../parser/skipSpaces.ts\";\nimport { PathParser } from \"../parser/pathParser.ts\";\n\n/**\n * Parses a path string value to determine its validity\n * then returns true if it's valid or false otherwise.\n *\n * @param pathString the path string to be parsed\n * @returns the path string validity\n */\nexport const isValidPath = (pathString: string): boolean => {\n if (typeof pathString !== \"string\" || !pathString.length) {\n return false;\n }\n\n const path = new PathParser(pathString);\n\n skipSpaces(path);\n\n while (path.index < path.max && !path.err.length) {\n scanSegment(path);\n }\n\n return !path.err.length && !!path.segments.length && \"mM\".includes(path.segments[0][0]);\n};\n","import type { PathArray } from \"../types.ts\";\nimport { error } from \"./error.ts\";\nimport { isPathArray } from \"./isPathArray.ts\";\n\n/**\n * Determines if an SVG path contains multiple subpaths.\n * Accepts path string or PathArray.\n * @param path - 'M10,10 L20,20 Z M30,30 L40,40' → true\n * @returns boolean\n */\nexport const isMultiPath = <T extends PathArray>(path: string | T): boolean => {\n if (typeof path === \"string\") {\n // Count all 'M' and 'm' occurrences\n const matches = path.match(/[Mm]/g);\n return matches ? matches.length > 1 : false;\n }\n\n // a value that is not a path at all is a type error\n if (!Array.isArray(path)) {\n throw new TypeError(error + \": expected string or PathArray\");\n }\n\n // an empty path and a malformed path have no sub-paths\n if (!isPathArray(path)) return false;\n\n let moveCount = 0;\n for (const segment of path) {\n if (segment[0].toUpperCase() === \"M\") {\n moveCount++;\n if (moveCount > 1) return true;\n }\n }\n return false;\n};\n","import type { PathArray } from \"../types.ts\";\n\n/**\n * Check if a PathArray is closed, which means its last segment is a Z.\n * @param path\n * @returns true if the path is closed\n */\nexport const isClosedPath = <T extends PathArray>(path: T): boolean => {\n if (!path.length) return false;\n return path[path.length - 1][0].toUpperCase() === \"Z\";\n};\n","import type { ShapeParams } from \"../interface.ts\";\n\n/**\n * Supported shapes and their specific parameters.\n */\nexport const shapeParams: ShapeParams = {\n line: [\"x1\", \"y1\", \"x2\", \"y2\"],\n circle: [\"cx\", \"cy\", \"r\"],\n ellipse: [\"cx\", \"cy\", \"rx\", \"ry\"],\n rect: [\"width\", \"height\", \"x\", \"y\", \"rx\", \"ry\"],\n polygon: [\"points\"],\n polyline: [\"points\"],\n glyph: [\"d\"],\n};\n","/**\n * Checks if a value is a DOM Element.\n *\n * @param node - The value to check\n * @returns True if the value is a DOM Element (nodeType === 1)\n */\nexport const isElement = (node?: unknown): node is Element =>\n node !== undefined && node !== null && typeof node === \"object\" && (node as Node).nodeType === 1; // ELEMENT_NODE\n","import type {\n CircleAttr,\n EllipseAttr,\n GlyphAttr,\n LineAttr,\n PolyAttr,\n RectAttr,\n ShapeParams,\n} from \"../interface.ts\";\nimport type { PathArray, PathSegment, ShapeOps, ShapeTypes } from \"../types.ts\";\nimport { error } from \"./error.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { shapeParams } from \"./shapeParams.ts\";\nimport { isPathArray } from \"./isPathArray.ts\";\nimport { isElement } from \"./isElement.ts\";\n\n/**\n * Returns a new PathArray from line attributes.\n *\n * @param attr - Shape configuration with x1, y1, x2, y2\n * @returns A new line PathArray\n *\n * @example\n * ```ts\n * getLinePath({ x1: 0, y1: 0, x2: 100, y2: 100 })\n * // => [['M', 0, 0], ['L', 100, 100]]\n * ```\n */\nexport const getLinePath = (attr: LineAttr): PathArray => {\n let { x1, y1, x2, y2 } = attr;\n [x1, y1, x2, y2] = [x1, y1, x2, y2].map((a) => +a);\n return [\n [\"M\", x1, y1],\n [\"L\", x2, y2],\n ];\n};\n\n/**\n * Returns a new PathArray from polyline/polygon attributes.\n *\n * @param attr - Shape configuration with points string\n * @returns A new polygon/polyline PathArray\n *\n * @example\n * ```ts\n * getPolyPath({ type: 'polygon', points: '0,0 100,0 100,100 0,100' })\n * // => [['M', 0, 0], ['L', 100, 0], ['L', 100, 100], ['L', 0, 100], ['z']]\n * ```\n */\nexport const getPolyPath = (attr: PolyAttr): PathArray => {\n const pathArray = [] as PathSegment[];\n const points = (attr.points || \"\")\n .trim()\n .split(/[\\s|,]/)\n .map((a) => +a);\n\n let index = 0;\n while (index + 1 < points.length) {\n const x = points[index] as number;\n const y = points[index + 1] as number;\n // a pair without both coordinates, or with invalid ones, is dropped\n if (Number.isFinite(x) && Number.isFinite(y)) {\n pathArray.push([pathArray.length ? \"L\" : \"M\", x, y]);\n }\n index += 2;\n }\n\n return (\n attr.type === \"polygon\" && pathArray.length ? [...pathArray, [\"z\"]] : pathArray\n ) as PathArray;\n};\n\n/**\n * Returns a new PathArray from circle attributes.\n *\n * @param attr - Shape configuration with cx, cy, r\n * @returns A circle PathArray\n *\n * @example\n * ```ts\n * getCirclePath({ cx: 50, cy: 50, r: 25 })\n * // => [['M', 25, 50], ['a', 25, 25, 0, 1, 0, 50, 0], ['a', 25, 25, 0, 1, 0, -50, 0]]\n * ```\n */\nexport const getCirclePath = (attr: CircleAttr): PathArray => {\n let { cx, cy, r } = attr;\n [cx, cy, r] = [cx, cy, r].map((a) => +a);\n\n return [\n [\"M\", cx - r, cy],\n [\"a\", r, r, 0, 1, 0, 2 * r, 0],\n [\"a\", r, r, 0, 1, 0, -2 * r, 0],\n ];\n};\n\n/**\n * Returns a new PathArray from ellipse attributes.\n *\n * @param attr - Shape configuration with cx, cy, rx, ry\n * @returns An ellipse PathArray\n *\n * @example\n * ```ts\n * getEllipsePath({ cx: 50, cy: 50, rx: 30, ry: 20 })\n * // => [['M', 20, 50], ['a', 30, 20, 0, 1, 0, 60, 0], ['a', 30, 20, 0, 1, 0, -60, 0]]\n * ```\n */\nexport const getEllipsePath = (attr: EllipseAttr): PathArray => {\n let { cx, cy } = attr;\n let rx = attr.rx || 0;\n let ry = attr.ry || rx;\n [cx, cy, rx, ry] = [cx, cy, rx, ry].map((a) => +a);\n\n return [\n [\"M\", cx - rx, cy],\n [\"a\", rx, ry, 0, 1, 0, 2 * rx, 0],\n [\"a\", rx, ry, 0, 1, 0, -2 * rx, 0],\n ];\n};\n\n/**\n * Returns a new PathArray from rect attributes.\n *\n * The corners of a rounded rectangle are elliptical arcs, one for every\n * corner, and the radius of the corners follows the rules of the spec: a\n * missing radius takes the value of the other one, an explicit zero\n * disables the rounding and a radius bigger than half of the size of the\n * rectangle is clamped to it.\n *\n * @param attr - Object with x, y, width, height, and optional rx/ry\n * @returns A new PathArray from `<rect>` attributes\n *\n * @example\n * ```ts\n * getRectanglePath({ x: 0, y: 0, width: 100, height: 50, ry: 10 })\n * // => [['M', 10, 0], ['h', 80], ['a', 10, 10, 0, 0, 1, 10, 10], ...]\n * ```\n */\nexport const getRectanglePath = (attr: RectAttr): PathArray => {\n const x = +attr.x || 0;\n const y = +attr.y || 0;\n const w = +attr.width;\n const h = +attr.height;\n // a missing radius takes the value of the other one\n const rxValue = attr.rx === undefined || attr.rx === null ? undefined : +attr.rx;\n const ryValue = attr.ry === undefined || attr.ry === null ? undefined : +attr.ry;\n let rx = rxValue ?? ryValue ?? 0;\n let ry = ryValue ?? rxValue ?? 0;\n\n // Validity checks from http://www.w3.org/TR/SVG/shapes.html#RectElement:\n if (rx > 0 && ry > 0) {\n // the radius of a corner cannot be bigger than half of the size of the\n // rectangle\n rx = Math.min(rx, w / 2);\n ry = Math.min(ry, h / 2);\n\n return [\n [\"M\", x + rx, y],\n [\"h\", w - rx * 2],\n [\"a\", rx, ry, 0, 0, 1, rx, ry],\n [\"v\", h - ry * 2],\n [\"a\", rx, ry, 0, 0, 1, -rx, ry],\n [\"h\", -w + rx * 2],\n [\"a\", rx, ry, 0, 0, 1, -rx, -ry],\n [\"v\", -h + ry * 2],\n [\"a\", rx, ry, 0, 0, 1, rx, -ry],\n [\"Z\"],\n ];\n }\n\n return [[\"M\", x, y], [\"h\", w], [\"v\", h], [\"H\", x], [\"Z\"]];\n};\n\n/**\n * Returns a new `pathArray` created from attributes of a `<line>`, `<polyline>`,\n * `<polygon>`, `<rect>`, `<ellipse>`, `<circle>`, <path> or `<glyph>`.\n *\n * It can also work with an options object, see the type below\n * @see ShapeOps\n *\n * @param element target shape\n * @returns the newly created `<path>` element\n */\nexport const shapeToPathArray = (element: ShapeTypes | ShapeOps): false | PathArray => {\n const supportedShapes = Object.keys(shapeParams) as (keyof ShapeParams)[];\n const targetIsElement = isElement(element);\n const tagName = targetIsElement ? element.tagName : null;\n\n if (tagName && [...supportedShapes, \"path\"].every((s) => tagName !== s)) {\n throw TypeError(`${error}: \"${tagName}\" is not SVGElement`);\n }\n\n const type = (targetIsElement ? tagName : (element as ShapeOps).type) as ShapeOps[\"type\"];\n const shapeAttrs = shapeParams[type] as string[];\n const config = { type } as Record<string, string>;\n\n if (targetIsElement) {\n shapeAttrs.forEach((p) => {\n config[p] = element.getAttribute(p) as string;\n });\n } else {\n Object.assign(config, element);\n }\n\n // set d\n let pathArray = [] as unknown as PathArray;\n\n /* istanbul ignore else */\n if (type === \"circle\") {\n pathArray = getCirclePath(config as unknown as CircleAttr);\n } else if (type === \"ellipse\") {\n pathArray = getEllipsePath(config as unknown as EllipseAttr);\n } else if ([\"polyline\", \"polygon\"].includes(type)) {\n pathArray = getPolyPath(config as unknown as PolyAttr);\n } else if (type === \"rect\") {\n pathArray = getRectanglePath(config as unknown as RectAttr);\n } else if (type === \"line\") {\n pathArray = getLinePath(config as unknown as LineAttr);\n } else if ([\"glyph\", \"path\"].includes(type)) {\n pathArray = parsePathString(\n targetIsElement\n ? element.getAttribute(\"d\") || /* istanbul ignore next */ \"\"\n : (element as GlyphAttr).d || \"\",\n );\n }\n\n // replace target element\n if (isPathArray(pathArray) && pathArray.length) {\n return pathArray;\n }\n return false;\n};\n","import type { ShapeParams } from \"../interface.ts\";\nimport type { ShapeOps, ShapeTypes } from \"../types.ts\";\nimport { pathToString } from \"../convert/pathToString.ts\";\nimport { defaultOptions } from \"../options/options.ts\";\nimport { error } from \"./error.ts\";\nimport { isValidPath } from \"./isValidPath.ts\";\nimport { isElement } from \"./isElement.ts\";\nimport { shapeToPathArray } from \"./shapeToPathArray.ts\";\nimport { shapeParams } from \"./shapeParams.ts\";\n\n/**\n * Returns a new `<path>` element created from attributes of a `<line>`, `<polyline>`,\n * `<polygon>`, `<rect>`, `<ellipse>`, `<circle>` or `<glyph>`. If `replace` parameter\n * is `true`, it will replace the target. The default `ownerDocument` is your current\n * `document` browser page, if you want to use in server-side using `jsdom`, you can\n * pass the `jsdom` `document` to `ownDocument`.\n *\n * It can also work with an options object, see the type below\n * @see ShapeOps\n *\n * The newly created `<path>` element keeps all non-specific\n * attributes like `class`, `fill`, etc.\n *\n * @param element - Target shape element or shape options object\n * @param replace - Option to replace target element\n * @param ownerDocument - Document for creating the element\n * @returns The newly created `<path>` element, or false if the path is invalid\n *\n * @example\n * ```ts\n * const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle')\n * circle.setAttribute('cx', '50')\n * circle.setAttribute('cy', '50')\n * circle.setAttribute('r', '25')\n * const path = shapeToPath(circle)\n * path.getAttribute('d')\n * // => 'M50 25A25 25 0 1 1 50 75A25 25 0 1 1 50 25Z'\n * ```\n */\nexport const shapeToPath = (\n element: ShapeTypes | ShapeOps,\n replace?: boolean,\n ownerDocument?: Document,\n): SVGPathElement | false => {\n const doc = ownerDocument || document;\n const supportedShapes = Object.keys(shapeParams) as (keyof ShapeParams)[];\n const targetIsElement = isElement(element);\n const tagName = targetIsElement ? element.tagName : null;\n\n if (tagName === \"path\") {\n throw TypeError(`${error}: \"${tagName}\" is already SVGPathElement`);\n }\n if (tagName && supportedShapes.every((s) => tagName !== s)) {\n throw TypeError(`${error}: \"${tagName}\" is not SVGElement`);\n }\n\n const path = doc.createElementNS(\"http://www.w3.org/2000/svg\", \"path\");\n const type = (targetIsElement ? tagName : (element as ShapeOps).type) as ShapeOps[\"type\"];\n const shapeAttrs = shapeParams[type] as string[];\n const config = { type } as Record<string, string>;\n\n // set d\n const round = defaultOptions.round as number;\n const pathArray = shapeToPathArray(element);\n const description = pathArray && pathArray.length ? pathToString(pathArray, round) : \"\";\n\n if (targetIsElement) {\n shapeAttrs.forEach((p) => {\n config[p] = element.getAttribute(p) as string;\n });\n // set no-specific shape attributes: fill, stroke, etc\n for (let i = 0; i < element.attributes.length; i++) {\n const attr = element.attributes[i];\n if (attr && !shapeAttrs.includes(attr.name)) {\n path.setAttribute(attr.name, attr.value);\n }\n }\n } else {\n Object.assign(config, element);\n // set no-specific shape attributes: fill, stroke, etc\n Object.keys(config).forEach((k) => {\n if (!shapeAttrs.includes(k) && k !== \"type\") {\n path.setAttribute(\n k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`),\n config[k],\n );\n }\n });\n }\n\n // replace target element\n if (isValidPath(description)) {\n path.setAttribute(\"d\", description);\n if (replace && targetIsElement) {\n element.before(path, element);\n element.remove();\n }\n return path;\n }\n return false;\n};\n","import type { SegmentMeasure } from \"../util/measureSegments.ts\";\nimport { getSegmentFrame } from \"../util/segmentFrame.ts\";\n\n/**\n * A point of a path with the direction of the path at that point.\n */\nexport type OffsetNode = {\n /** The X coordinate of the point. */\n x: number;\n /** The Y coordinate of the point. */\n y: number;\n /** The X component of the unit tangent. */\n tx: number;\n /** The Y component of the unit tangent. */\n ty: number;\n /** Whether a join precedes this node. */\n corner: boolean;\n};\n\n/**\n * Returns the sampled points of the drawable segments of a sub-path.\n *\n * A line gives its two end points, a curve gives `steps` samples spread\n * evenly over its length. The tangent of every sample is the tangent of the\n * path at that point, so the normal of the sample is the direction the path\n * is offset to.\n *\n * The first point of a segment is a corner when the segment follows another\n * one, and the closing segment of a closed sub-path ends with a corner that\n * joins the last segment to the first one.\n *\n * @param measures - the measured segments of the sub-path\n * @param steps - the number of the intervals a curve is sampled with\n * @returns the sampled points of the sub-path\n */\nexport const getOffsetNodes = (measures: SegmentMeasure[], steps: number): OffsetNode[] => {\n const nodes: OffsetNode[] = [];\n\n for (const measure of measures) {\n const command = measure.geometry[0];\n // the moveto only holds the start of the sub-path\n if (command === \"M\") continue;\n // a segment without a length does not move the path\n if (measure.length <= 0) continue;\n const isFirst = nodes.length === 0;\n\n if (command === \"L\" || command === \"Z\") {\n const dx = measure.endX - measure.startX;\n const dy = measure.endY - measure.startY;\n const length = Math.sqrt(dx * dx + dy * dy);\n const tx = dx / length;\n const ty = dy / length;\n nodes.push({\n x: measure.startX,\n y: measure.startY,\n tx,\n ty,\n corner: !isFirst,\n });\n nodes.push({ x: measure.endX, y: measure.endY, tx, ty, corner: false });\n continue;\n }\n\n for (let i = 0; i <= steps; i += 1) {\n const frame = getSegmentFrame(\n measure.geometry,\n measure.startX,\n measure.startY,\n measure.endX,\n measure.endY,\n (measure.length * i) / steps,\n measure.length,\n );\n nodes.push({\n x: frame.point.x,\n y: frame.point.y,\n tx: frame.tangent.x,\n ty: frame.tangent.y,\n corner: !isFirst && i === 0,\n });\n }\n }\n\n // a closed sub-path ends with the corner that joins the closing segment\n // to the first segment of the sub-path\n const last = measures[measures.length - 1];\n if (nodes.length && last && last.geometry[0] === \"Z\") {\n const first = nodes[0];\n nodes.push({\n x: first.x,\n y: first.y,\n tx: first.tx,\n ty: first.ty,\n corner: true,\n });\n }\n\n return nodes;\n};\n","import type { PointTuple } from \"../types.ts\";\nimport type { OffsetCap, OffsetJoin } from \"../interface.ts\";\n\n/**\n * A point of an offset path with the direction of the path at that point.\n */\nexport type OffsetPoint = {\n /** The X coordinate of the point. */\n x: number;\n /** The Y coordinate of the point. */\n y: number;\n /** The X component of the unit tangent. */\n tx: number;\n /** The Y component of the unit tangent. */\n ty: number;\n};\n\n/**\n * The angle of an arc of a round join or a round cap, in radians.\n *\n * The arcs are emitted as straight lines, and the smaller the angle the\n * closer the result is to the arc it stands for.\n */\nconst arcStep = Math.PI / 8;\n\n/**\n * Returns the signed angle between two directions, in radians.\n *\n * The angle is the turn of the path at a corner: it is positive when the\n * path turns towards the positive angle direction, and it is in the `-PI` to\n * `PI` range.\n *\n * @param from - the direction the path comes from\n * @param to - the direction the path goes to\n * @returns the signed angle between the two directions\n */\nexport const signedTurn = (from: OffsetPoint, to: OffsetPoint): number => {\n const dot = from.tx * to.tx + from.ty * to.ty;\n const cross = from.tx * to.ty - from.ty * to.tx;\n return Math.atan2(cross, dot);\n};\n\n/**\n * Returns the intersection of two lines, if they have one.\n *\n * @param x1 - the X coordinate of the first point\n * @param y1 - the Y coordinate of the first point\n * @param dx1 - the X component of the direction of the first line\n * @param dy1 - the Y component of the direction of the first line\n * @param x2 - the X coordinate of the second point\n * @param y2 - the Y coordinate of the second point\n * @param dx2 - the X component of the direction of the second line\n * @param dy2 - the Y component of the direction of the second line\n * @returns the intersection of the two lines, or `null`\n */\nexport const intersectLines = (\n x1: number,\n y1: number,\n dx1: number,\n dy1: number,\n x2: number,\n y2: number,\n dx2: number,\n dy2: number,\n): PointTuple | null => {\n const denominator = dx1 * dy2 - dy1 * dx2;\n // parallel lines have no intersection\n if (Math.abs(denominator) < 1e-12) return null;\n const ratio = ((x2 - x1) * dy2 - (y2 - y1) * dx2) / denominator;\n return [x1 + dx1 * ratio, y1 + dy1 * ratio];\n};\n\n/**\n * Returns the points of a join between two offset lines.\n *\n * The join is placed on the outer side of a corner, where the two offset\n * lines do not cross: the `miter` join is the intersection of the two\n * lines, the `bevel` join is the straight line between the two offset\n * points and the `round` join is an arc of the offset radius around the\n * corner.\n *\n * @param cornerX - the X coordinate of the corner of the path\n * @param cornerY - the Y coordinate of the corner of the path\n * @param from - the end of the incoming offset line\n * @param to - the start of the outgoing offset line\n * @param distance - the offset distance\n * @param join - the join type\n * @param miterLimit - the ratio of the miter length to the offset distance\n * @returns the points of the join\n */\nexport const getJoinPoints = (\n cornerX: number,\n cornerY: number,\n from: OffsetPoint,\n to: OffsetPoint,\n distance: number,\n join: OffsetJoin,\n miterLimit: number,\n): PointTuple[] => {\n if (join === \"round\") {\n const turn = signedTurn(from, to);\n const startAngle = Math.atan2(from.y - cornerY, from.x - cornerX);\n const steps = Math.max(1, Math.ceil(Math.abs(turn) / arcStep));\n const points: PointTuple[] = [];\n for (let i = 1; i < steps; i += 1) {\n const angle = startAngle + (turn * i) / steps;\n points.push([cornerX + Math.cos(angle) * distance, cornerY + Math.sin(angle) * distance]);\n }\n return points;\n }\n\n if (join === \"miter\") {\n const miter = intersectLines(from.x, from.y, from.tx, from.ty, to.x, to.y, to.tx, to.ty);\n if (miter) {\n const miterLength = Math.hypot(miter[0] - cornerX, miter[1] - cornerY);\n // the miter is too long, the corner is beveled instead\n if (miterLength <= miterLimit * distance) return [miter];\n }\n }\n\n return [];\n};\n\n/**\n * Returns the points of a cap at the end of an open path.\n *\n * The `butt` cap is the straight line between the two offset points, the\n * `square` cap extends the path by the offset distance and the `round` cap\n * is a half circle of the offset radius around the end of the path.\n *\n * @param centerX - the X coordinate of the end of the path\n * @param centerY - the Y coordinate of the end of the path\n * @param from - the first offset point of the cap\n * @param to - the last offset point of the cap\n * @param distance - the offset distance\n * @param cap - the cap type\n * @param extensionX - the X component of the direction the cap extends to\n * @param extensionY - the Y component of the direction the cap extends to\n * @returns the points of the cap\n */\nexport const getCapPoints = (\n centerX: number,\n centerY: number,\n from: PointTuple,\n to: PointTuple,\n distance: number,\n cap: OffsetCap,\n extensionX: number,\n extensionY: number,\n): PointTuple[] => {\n if (cap === \"butt\") return [];\n\n if (cap === \"square\") {\n // the cap is extended by the offset distance, along the direction of\n // the path\n return [\n [from[0] + extensionX * distance, from[1] + extensionY * distance],\n [to[0] + extensionX * distance, to[1] + extensionY * distance],\n ];\n }\n\n // the cap is a half circle, it sweeps from the first offset point to the\n // last one around the end of the path\n const startAngle = Math.atan2(from[1] - centerY, from[0] - centerX);\n const sweep = -Math.PI;\n const steps = Math.max(1, Math.ceil(Math.abs(sweep) / arcStep));\n const points: PointTuple[] = [];\n for (let i = 1; i < steps; i += 1) {\n const angle = startAngle + (sweep * i) / steps;\n points.push([centerX + Math.cos(angle) * distance, centerY + Math.sin(angle) * distance]);\n }\n return points;\n};\n","import type { PathArray, PathSegment, PointTuple } from \"../types.ts\";\nimport type { OffsetCap, OffsetJoin, OffsetOptions, OffsetSide } from \"../interface.ts\";\nimport { error } from \"../util/error.ts\";\nimport { measureSegments } from \"../util/measureSegments.ts\";\nimport type { SegmentMeasure } from \"../util/measureSegments.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { polygonArea } from \"../math/polygonTools.ts\";\nimport { roundTo } from \"../math/roundTo.ts\";\nimport { cleanZero } from \"../util/segmentFrame.ts\";\nimport { getOffsetNodes } from \"./offsetNodes.ts\";\nimport type { OffsetNode } from \"./offsetNodes.ts\";\nimport { getCapPoints, getJoinPoints, intersectLines, signedTurn } from \"./offsetJoin.ts\";\nimport type { OffsetPoint } from \"./offsetJoin.ts\";\n\n/**\n * The options of the path offsetting, with the defaults applied.\n */\ntype ResolvedOptions = {\n /** The side of the path to offset. */\n side: OffsetSide;\n /** The join type at a corner. */\n join: OffsetJoin;\n /** The ratio of the miter length to the offset distance. */\n miterLimit: number;\n /** The cap type at the end of an open path. */\n cap: OffsetCap;\n /** The number of the intervals a curve is sampled with. */\n steps: number;\n /** The number of the decimals of the result. */\n precision: number;\n};\n\n/** The sides an offset can be created on. */\nconst sides: OffsetSide[] = [\"left\", \"right\", \"both\"];\n/** The join types of an offset. */\nconst joins: OffsetJoin[] = [\"round\", \"miter\", \"bevel\"];\n/** The cap types of an offset. */\nconst caps: OffsetCap[] = [\"butt\", \"square\", \"round\"];\n\n/**\n * Returns the options of the path offsetting, with the defaults applied.\n *\n * @param options - the options of the offset\n * @returns the resolved options\n */\nconst resolveOptions = (options: OffsetOptions): ResolvedOptions => {\n const {\n side = \"left\",\n join = \"miter\",\n miterLimit = 4,\n cap = \"butt\",\n steps = 16,\n precision = 4,\n } = options;\n\n if (!sides.includes(side)) {\n throw TypeError(`${error}: side must be one of \"left\", \"right\" or \"both\"`);\n }\n if (!joins.includes(join)) {\n throw TypeError(`${error}: join must be one of \"round\", \"miter\" or \"bevel\"`);\n }\n if (!caps.includes(cap)) {\n throw TypeError(`${error}: cap must be one of \"butt\", \"square\" or \"round\"`);\n }\n if (typeof miterLimit !== \"number\" || !Number.isFinite(miterLimit) || miterLimit <= 0) {\n throw TypeError(`${error}: miterLimit must be a positive number`);\n }\n if (!Number.isInteger(steps) || steps < 1) {\n throw TypeError(`${error}: steps must be an integer greater than 0`);\n }\n if (!Number.isInteger(precision) || precision < 0) {\n throw TypeError(`${error}: precision must be an integer of 0 or more`);\n }\n\n return { side, join, miterLimit, cap, steps, precision };\n};\n\n/**\n * Groups the measured segments of a path into its sub-paths.\n *\n * @param measures - the measured segments of the path\n * @returns the measured segments of every sub-path\n */\nconst groupSubPaths = (measures: SegmentMeasure[]): SegmentMeasure[][] => {\n const groups: SegmentMeasure[][] = [];\n let group: SegmentMeasure[] = [];\n\n for (const measure of measures) {\n if (measure.geometry[0] === \"M\" && group.length) {\n groups.push(group);\n group = [];\n }\n group.push(measure);\n }\n if (group.length) groups.push(group);\n\n return groups;\n};\n\n/**\n * Returns the offset polyline of one side of a sub-path.\n *\n * Every node is shifted along the normal of the path. At a corner the two\n * offset lines meet: on the outer side of the turn the join is applied, and\n * on the inner side of the turn the offset lines cross before the corner, so\n * the curve is trimmed at their intersection.\n *\n * @param nodes - the sampled points of the sub-path\n * @param side - `1` for the left side of the path, `-1` for the right side\n * @param distance - the offset distance\n * @param options - the resolved options of the offset\n * @param closed - whether the sub-path is closed\n * @returns the points of the offset polyline\n */\nconst buildSidePolyline = (\n nodes: OffsetNode[],\n side: number,\n distance: number,\n options: ResolvedOptions,\n closed: boolean,\n): PointTuple[] => {\n const { join, miterLimit } = options;\n const offsets: OffsetPoint[] = nodes.map((node) => ({\n x: node.x - side * node.ty * distance,\n y: node.y + side * node.tx * distance,\n tx: node.tx,\n ty: node.ty,\n }));\n const points: PointTuple[] = [[offsets[0].x, offsets[0].y]];\n\n for (let i = 1; i < offsets.length; i += 1) {\n const from = offsets[i - 1];\n const to = offsets[i];\n let trimmed = false;\n\n if (nodes[i].corner) {\n const turn = signedTurn(from, to);\n if (Math.abs(turn) > 1e-9) {\n if (side * turn < 0) {\n points.push(\n ...getJoinPoints(nodes[i].x, nodes[i].y, from, to, distance, join, miterLimit),\n );\n } else {\n const intersection = intersectLines(\n from.x,\n from.y,\n from.tx,\n from.ty,\n to.x,\n to.y,\n to.tx,\n to.ty,\n );\n if (intersection) {\n points[points.length - 1] = intersection;\n // the closing corner of a closed sub-path trims the first point\n // of the path as well\n if (closed && i === offsets.length - 1) points[0] = intersection;\n trimmed = true;\n }\n }\n }\n }\n\n if (!trimmed) {\n const point: PointTuple = [to.x, to.y];\n // a corner without a turn does not move the path\n if (!samePoint(points[points.length - 1], point)) points.push(point);\n }\n }\n\n return points;\n};\n\n/**\n * Returns whether two points are the same point.\n *\n * @param a - the first point\n * @param b - the second point\n * @returns whether the points are the same\n */\nconst samePoint = (a: PointTuple, b: PointTuple): boolean =>\n Math.abs(a[0] - b[0]) < 1e-9 && Math.abs(a[1] - b[1]) < 1e-9;\n\n/**\n * Returns a coordinate of the result, rounded and without a negative zero.\n *\n * @param value - the coordinate\n * @param precision - the number of the decimals of the result\n * @returns the rounded coordinate\n */\nconst roundCoordinate = (value: number, precision: number): number =>\n cleanZero(roundTo(value, precision));\n\n/**\n * Returns the segments of an offset polyline.\n *\n * @param points - the points of the polyline\n * @param closed - whether the polyline is closed\n * @param precision - the number of the decimals of the result\n * @returns the segments of the polyline\n */\nconst toSegments = (points: PointTuple[], closed: boolean, precision: number): PathSegment[] => {\n const last = points[points.length - 1];\n // a closed polyline ends where it starts, the closing segment is enough\n const list =\n closed && points.length > 1 && samePoint(points[0], last) ? points.slice(0, -1) : points;\n const segments: PathSegment[] = [];\n\n // the polyline always holds at least one point\n /* istanbul ignore next */\n if (!list.length) return segments;\n\n segments.push([\n \"M\",\n roundCoordinate(list[0][0], precision),\n roundCoordinate(list[0][1], precision),\n ]);\n for (let i = 1; i < list.length; i += 1) {\n segments.push([\n \"L\",\n roundCoordinate(list[i][0], precision),\n roundCoordinate(list[i][1], precision),\n ]);\n }\n if (closed) segments.push([\"Z\"]);\n\n return segments;\n};\n\n/**\n * Offsets a path along its normals.\n *\n * The path is sampled along its length, every sample is shifted along the\n * normal of the path and the result is a path of straight lines. The\n * corners of the path are joined with the `join` option, and the ends of an\n * open path are capped with the `cap` option.\n *\n * The `side` option is literal: the left side is the left normal of the\n * direction of travel, the same normal `getPropertiesAtLength()` returns.\n * The `both` side is the outline of the stroke, the band between the two\n * sides of the path.\n *\n * The offset is not cleaned up: an offset distance larger than the local\n * radius of curvature of the path produces a self-crossing curve.\n *\n * @param pathInput - the path string or `PathArray`\n * @param distance - the offset distance\n * @param options - the options of the offset\n * @returns the offset path\n *\n * @example\n * ```ts\n * offsetPath('M0 0L100 0', 10)\n * // => [['M', 0, 10], ['L', 100, 10]]\n * ```\n */\nexport const offsetPath = <T extends PathArray>(\n pathInput: string | T,\n distance: number,\n options?: OffsetOptions,\n): PathArray => {\n if (typeof distance !== \"number\" || !Number.isFinite(distance)) {\n throw TypeError(`${error}: distance must be a number`);\n }\n if (distance < 0) {\n throw TypeError(`${error}: distance must be a positive number`);\n }\n\n const resolved = resolveOptions(options ?? {});\n // a path without an offset is the path itself\n if (distance === 0) return parsePathString(pathInput) as PathArray;\n\n const measures = measureSegments(pathInput);\n const groups = groupSubPaths(measures);\n const result: PathSegment[] = [];\n\n for (const group of groups) {\n const nodes = getOffsetNodes(group, resolved.steps);\n const last = group[group.length - 1];\n const closed = Boolean(last && last.geometry[0] === \"Z\");\n\n // a sub-path without a drawable segment keeps its moveto\n if (!nodes.length) {\n const first = group[0];\n result.push([\"M\", first.endX, first.endY]);\n continue;\n }\n\n if (resolved.side === \"both\") {\n const left = buildSidePolyline(nodes, 1, distance, resolved, closed);\n const right = buildSidePolyline(nodes, -1, distance, resolved, closed);\n\n if (closed) {\n // the outline of a closed path is the outer ring and the inner ring,\n // the inner one is reversed so it is a hole\n const leftArea = Math.abs(polygonArea(left));\n const rightArea = Math.abs(polygonArea(right));\n const outer = leftArea >= rightArea ? left : right;\n const inner = leftArea >= rightArea ? right : left;\n result.push(...toSegments(outer, true, resolved.precision));\n result.push(...toSegments([...inner].reverse(), true, resolved.precision));\n continue;\n }\n\n // the outline of an open path is the left side, the cap at the end of\n // the path, the right side backwards and the cap at the start\n const start = nodes[0];\n const end = nodes[nodes.length - 1];\n const endCap = getCapPoints(\n end.x,\n end.y,\n left[left.length - 1],\n right[right.length - 1],\n distance,\n resolved.cap,\n end.tx,\n end.ty,\n );\n const startCap = getCapPoints(\n start.x,\n start.y,\n right[0],\n left[0],\n distance,\n resolved.cap,\n -start.tx,\n -start.ty,\n );\n const ring = [...left, ...endCap, ...[...right].reverse(), ...startCap];\n result.push(...toSegments(ring, true, resolved.precision));\n continue;\n }\n\n const side = resolved.side === \"left\" ? 1 : -1;\n const polyline = buildSidePolyline(nodes, side, distance, resolved, closed);\n result.push(...toSegments(polyline, closed, resolved.precision));\n }\n\n return result as PathArray;\n};\n","import { defaultOptions } from \"../options/options.ts\";\nimport type { ParserParams } from \"../interface.ts\";\nimport { roundTo } from \"../math/roundTo.ts\";\nimport type {\n AbsoluteSegment,\n NormalSegment,\n PathCommand,\n ShortSegment,\n SSegment,\n TSegment,\n} from \"../types.ts\";\n\n/**\n * Shorten a single segment of a `pathArray` object.\n *\n * @param segment the `absoluteSegment` object\n * @param normalSegment the `normalSegment` object\n * @param params the coordinates of the previous segment\n * @param prevCommand the path command of the previous segment\n * @returns the shortened segment\n */\nexport const shortenSegment = (\n segment: AbsoluteSegment,\n normalSegment: NormalSegment,\n params: ParserParams,\n prevCommand: PathCommand,\n): ShortSegment => {\n const [pathCommand] = segment;\n const { round: defaultRound } = defaultOptions;\n const round = typeof defaultRound === \"number\" ? defaultRound : /* istanbul ignore next */ 4;\n const normalValues = normalSegment.slice(1) as number[];\n const { x2, y2, x, y } = params;\n const [nx, ny] = normalValues.slice(-2);\n const result = segment;\n\n if (!\"TQ\".includes(pathCommand)) {\n // optional but good to be cautious\n params.qx = null;\n params.qy = null;\n }\n\n if (pathCommand === \"L\") {\n if (roundTo(x, round) === roundTo(nx, round)) {\n return [\"V\", ny];\n } else if (roundTo(y, round) === roundTo(ny, round)) {\n return [\"H\", nx];\n }\n } else if (pathCommand === \"C\") {\n const [nx1, ny1] = normalValues;\n\n if (\n \"CS\".includes(prevCommand) &&\n x2 != null &&\n y2 != null &&\n roundTo(nx1, round) === roundTo(x * 2 - x2, round) &&\n roundTo(ny1, round) === roundTo(y * 2 - y2, round)\n ) {\n return [\"S\", normalValues[2], normalValues[3], normalValues[4], normalValues[5]] as SSegment;\n }\n } else if (pathCommand === \"Q\") {\n const [qx, qy] = normalValues;\n params.qx = qx;\n params.qy = qy;\n\n if (\n \"QT\".includes(prevCommand) &&\n x2 != null &&\n y2 != null &&\n roundTo(qx, round) === roundTo(x * 2 - x2, round) &&\n roundTo(qy, round) === roundTo(y * 2 - y2, round)\n ) {\n return [\"T\", normalValues[2], normalValues[3]] as TSegment;\n }\n }\n\n // ['V', 'H', 'S', 'T', 'Z'].includes(pathCommand)\n return result as ShortSegment;\n};\n","import type { PathSegment } from \"../types.ts\";\nimport { roundTo } from \"../math/roundTo.ts\";\n\n/**\n * Rounds the numeric values of a path segment to the specified precision.\n *\n * @param segment - The path segment to round\n * @param roundOption - Number of decimal places\n * @returns The rounded segment\n */\nexport const roundSegment = <T extends PathSegment>(segment: T, roundOption: number): T => {\n // the rounded segment is built in one pass: a copy of the segment, a map\n // over its values and a concatenation would allocate three arrays\n const result = new Array(segment.length) as unknown as T;\n for (let i = 0; i < segment.length; i += 1) {\n result[i] = (i === 0 ? segment[0] : roundTo(segment[i] as number, roundOption)) as T[number];\n }\n return result;\n};\n","import type { PathSegment } from \"../types.ts\";\n\n/**\n * Returns the length of the string representation of a path segment.\n *\n * The string of a segment is its command followed by its values, without a\n * separator, so its length is the length of the command plus the length of\n * every value. The string itself is not needed to know its length, so it is\n * not built.\n *\n * @param segment - The path segment to measure\n * @returns The length of the string of the segment\n */\nexport const segmentStringLength = (segment: PathSegment): number => {\n let length = String(segment[0]).length;\n for (let i = 1; i < segment.length; i += 1) {\n length += String(segment[i]).length;\n }\n return length;\n};\n","import type { AbsoluteSegment, PathArray, PathCommand, PathSegment } from \"../types.ts\";\nimport { pathToAbsolute } from \"../convert/pathToAbsolute.ts\";\nimport { shortenSegment } from \"./shortenSegment.ts\";\nimport { paramsParser } from \"../parser/paramsParser.ts\";\nimport { iterate } from \"./iterate.ts\";\nimport { normalizeSegment } from \"./normalizeSegment.ts\";\nimport { relativizeSegment } from \"./relativizeSegment.ts\";\nimport { roundSegment } from \"./roundSegment.ts\";\nimport { segmentStringLength } from \"./segmentStringLength.ts\";\n\n/**\n * Optimizes a PathArray:\n * * converts segments to shorthand if possible\n * * selects shortest representation from absolute and relative forms\n *\n * @param pathInput - A path string or PathArray\n * @param roundOption - Number of decimal places for rounding\n * @returns The optimized PathArray\n *\n * @example\n * ```ts\n * optimizePath('M10 10L10 10L90 90', 2)\n * // => [['M', 10, 10], ['v', 0], ['l', 80, 80]]\n * ```\n */\nexport const optimizePath = <T extends string | PathArray>(\n pathInput: T,\n roundOption?: number,\n): PathArray => {\n const path = pathToAbsolute(pathInput);\n // allow for ZERO decimals or use an aggressive value of 2\n const round = typeof roundOption === \"number\" && roundOption >= 0 ? roundOption : 2;\n // this utility overrides the iterator params\n const optimParams = { ...paramsParser };\n\n const allPathCommands = [] as PathCommand[];\n let pathCommand = \"M\" as PathCommand;\n let prevCommand = \"Z\" as PathCommand;\n\n return iterate(path, (seg, i, lastX, lastY) => {\n optimParams.x = lastX;\n optimParams.y = lastY;\n let result: PathSegment = seg;\n pathCommand = seg[0];\n\n // Save current path command\n allPathCommands[i] = pathCommand;\n if (i) {\n // Get previous path command for `shortenSegment`\n prevCommand = allPathCommands[i - 1];\n }\n const normalizedSegment = normalizeSegment(seg, optimParams, i ? prevCommand : null);\n if (i) {\n const shortSegment = shortenSegment(\n seg as AbsoluteSegment,\n normalizedSegment,\n optimParams,\n prevCommand,\n );\n const absSegment = roundSegment(shortSegment, round);\n const absLength = segmentStringLength(absSegment);\n const relativeSegment = relativizeSegment(shortSegment, i, lastX, lastY);\n const relSegment = roundSegment(relativeSegment, round);\n const relLength = segmentStringLength(relSegment);\n result = absLength < relLength ? absSegment : relSegment;\n }\n\n const seglen = normalizedSegment.length;\n optimParams.x1 = +normalizedSegment[seglen - 2];\n optimParams.y1 = +normalizedSegment[seglen - 1];\n // only cubic and quadratic segments carry a reflectable control point\n if (normalizedSegment[0] === \"C\" || normalizedSegment[0] === \"Q\") {\n optimParams.x2 = +normalizedSegment[seglen - 4];\n optimParams.y2 = +normalizedSegment[seglen - 3];\n } else {\n optimParams.x2 = null;\n optimParams.y2 = null;\n }\n\n return result;\n });\n};\n","import type { PathArray } from \"../types.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { pathToAbsolute } from \"../convert/pathToAbsolute.ts\";\n\n/**\n * Joins two paths into a single path with two sub-paths.\n *\n * Both paths have to be valid paths, so they begin with a moveto command,\n * and the result holds absolute values.\n *\n * @param pathA - the first path string or `PathArray`\n * @param pathB - the second path string or `PathArray`\n * @returns the joined path\n *\n * @example\n * ```ts\n * joinPath('M0 0L100 0', 'M0 100L100 100')\n * // => [\n * // ['M', 0, 0], ['L', 100, 0],\n * // ['M', 0, 100], ['L', 100, 100]\n * // ]\n * ```\n */\nexport const joinPath = (pathA: string | PathArray, pathB: string | PathArray): PathArray => {\n const first = pathToAbsolute(parsePathString(pathA));\n const second = pathToAbsolute(parsePathString(pathB));\n\n return [...first, ...second] as PathArray;\n};\n","import type {\n // ASegment,\n CSegment,\n // HSegment,\n // MSegment,\n PathArray,\n PathSegment,\n PointTuple,\n QSegment,\n SSegment,\n TSegment,\n // VSegment,\n} from \"../types.ts\";\nimport { pathToAbsolute } from \"../convert/pathToAbsolute.ts\";\nimport { normalizePath } from \"./normalizePath.ts\";\nimport { iterate } from \"./iterate.ts\";\n\n/**\n * Reverses the segments of a single sub-path and returns a new PathArray\n * with absolute values.\n *\n * @param absolutePath - The absolute PathArray of a single sub-path\n * @returns The reversed PathArray\n */\nconst reverseSubPath = (absolutePath: PathArray): PathArray => {\n const normalizedPath = normalizePath(absolutePath);\n const pLen = absolutePath.length;\n const isClosed = absolutePath[pLen - 1][0] === \"Z\";\n\n // the end point of every normalized segment, the closing point of a\n // subpath is its starting point, so a segment following a `Z` starts\n // where the `Z` ends, not where the previous segment ended\n const endPoints: PointTuple[] = [];\n let endX = 0;\n let endY = 0;\n let subX = 0;\n let subY = 0;\n for (const seg of normalizedPath) {\n if (seg[0] === \"M\") {\n subX = +seg[1];\n subY = +seg[2];\n endX = subX;\n endY = subY;\n } else if (seg[0] === \"Z\") {\n endX = subX;\n endY = subY;\n } else {\n endX = +seg[seg.length - 2];\n endY = +seg[seg.length - 1];\n }\n endPoints.push([endX, endY]);\n }\n\n const reversedPath = iterate(absolutePath, (segment, i) => {\n const normalizedSegment = normalizedPath[i];\n const prevSeg = i && absolutePath[i - 1];\n const prevCommand = prevSeg && prevSeg[0];\n const nextSeg = absolutePath[i + 1];\n const nextCommand = nextSeg && nextSeg[0];\n const pathCommand = segment[0];\n const [x, y] = endPoints[i ? i - 1 : pLen - 1];\n let result = segment;\n\n switch (pathCommand) {\n case \"M\":\n result = isClosed ? [\"Z\"] : [pathCommand, x, y];\n break;\n case \"A\":\n result = [\n pathCommand,\n segment[1],\n segment[2],\n segment[3],\n segment[4],\n segment[5] === 1 ? 0 : 1,\n x,\n y,\n ];\n break;\n case \"C\":\n if (nextSeg && nextCommand === \"S\") {\n result = [\"S\", segment[1], segment[2], x, y];\n } else {\n result = [pathCommand, segment[3], segment[4], segment[1], segment[2], x, y];\n }\n break;\n case \"S\":\n // the control points can stay implicit only when the next segment\n // is an `S` as well, the reflected control point of the reversed\n // segment is then recovered from the previous segment of the\n // reversed path\n if (nextSeg && nextCommand === \"S\") {\n result = [pathCommand, normalizedSegment[1], normalizedSegment[2], x, y] as SSegment;\n } else {\n result = [\n \"C\",\n normalizedSegment[3],\n normalizedSegment[4],\n normalizedSegment[1],\n normalizedSegment[2],\n x,\n y,\n ] as CSegment;\n }\n break;\n case \"Q\":\n if (nextSeg && nextCommand === \"T\") {\n result = [\"T\", x, y] as TSegment;\n } else {\n result = [pathCommand, segment[1], segment[2], x, y];\n }\n break;\n case \"T\": {\n // the `T` shorthand reflects the control point of the previous\n // segment of the *reversed* path, which is the original successor\n // - when that successor is a `Q`, the shorthand would reflect the\n // `Q`'s control point instead of this segment's own control point\n // and silently change the curve\n const prevIsQuad = Boolean(prevCommand && \"QT\".includes(prevCommand));\n const nextIsT = Boolean(nextSeg && nextCommand === \"T\");\n const nextIsQuad = Boolean(nextSeg && nextCommand === \"Q\");\n if (nextIsT || (!prevIsQuad && !nextIsQuad)) {\n result = [pathCommand, x, y] as TSegment;\n } else {\n result = [\"Q\", normalizedSegment[1], normalizedSegment[2], x, y] as QSegment;\n }\n break;\n }\n case \"Z\":\n result = [\"M\", x, y];\n break;\n case \"H\":\n result = [pathCommand, x];\n break;\n case \"V\":\n result = [pathCommand, y];\n break;\n default:\n result = [pathCommand as typeof pathCommand | number].concat(\n segment.slice(1, -2),\n x,\n y,\n ) as typeof segment;\n }\n\n return result;\n });\n\n return (\n isClosed\n ? reversedPath.reverse()\n : [reversedPath[0] as PathSegment].concat(reversedPath.slice(1).reverse())\n ) as PathArray;\n};\n\n/**\n * Reverses all segments of a PathArray and returns a new PathArray\n * with absolute values.\n *\n * Every sub-path is reversed on its own, so the `M` and the `Z` of a\n * sub-path are swapped with each other and the sub-paths keep their\n * original order.\n *\n * @param pathInput - The source PathArray\n * @returns The reversed PathArray\n *\n * @example\n * ```ts\n * reversePath([['M', 0, 0], ['L', 100, 0], ['L', 100, 100], ['L', 0, 100], ['Z']])\n * // => [['M', 0, 100], ['L', 100, 100], ['L', 100, 0], ['L', 0, 0], ['Z']]\n * ```\n */\nexport const reversePath = <T extends PathArray>(pathInput: T | string): T => {\n const absolutePath = pathToAbsolute(pathInput);\n const subPaths: PathSegment[][] = [];\n let subPath: PathSegment[] = [];\n\n for (const segment of absolutePath) {\n if (segment[0] === \"M\" && subPath.length) {\n subPaths.push(subPath);\n subPath = [];\n }\n subPath.push(segment);\n }\n if (subPath.length) {\n subPaths.push(subPath);\n }\n\n const reversed = subPaths.map((path) => reverseSubPath(path as PathArray));\n\n return (reversed.length === 1 ? reversed[0] : reversed.flat()) as T;\n};\n","// import paramsParser from \"../parser/paramsParser.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport type {\n AbsoluteCommand,\n HSegment,\n MSegment,\n PathArray,\n PathSegment,\n PointTuple,\n VSegment,\n} from \"../types.ts\";\nimport { iterate } from \"./iterate.ts\";\nimport { absolutizeSegment } from \"./absolutizeSegment.ts\";\n\n/**\n * Split a path string or PathArray into an array of sub-paths.\n *\n * In the process, values are converted to absolute\n * for visual consistency.\n *\n * A path must begin with a moveto command, so a path that does not is\n * rejected by the parser.\n *\n * @param pathInput - The source path string or PathArray\n * @returns An array of sub-path PathArrays\n *\n * @example\n * ```ts\n * splitPath('M0 0L100 0ZM200 0L300 0Z')\n * // => [\n * // [['M', 0, 0], ['L', 100, 0], ['Z']],\n * // [['M', 200, 0], ['L', 300, 0], ['Z']]\n * // ]\n * ```\n */\nexport const splitPath = <T extends PathArray>(pathInput: T | string): T[] => {\n const composite: T[] = [];\n const parsedPath = parsePathString(pathInput);\n const segments: PathArray = parsedPath;\n let path = [] as unknown as T;\n let pi = -1;\n let x = 0;\n let y = 0;\n let mx = 0;\n let my = 0;\n\n iterate(segments, (seg, _index, prevX, prevY) => {\n const cmd = seg[0];\n const absCommand = cmd.toUpperCase() as AbsoluteCommand;\n const isRelative = cmd === cmd.toLowerCase();\n const values = seg.slice(1) as number[];\n\n if (absCommand === \"M\") {\n pi += 1;\n\n [x, y] = values as PointTuple;\n x += isRelative ? prevX : 0;\n y += isRelative ? prevY : 0;\n mx = x;\n my = y;\n // the moveto is always absolute, even when the source is relative\n path = [[\"M\", x, y] as MSegment] as unknown as T;\n } else {\n if (absCommand === \"Z\") {\n x = mx;\n y = my;\n } else if (absCommand === \"H\") {\n [, x] = seg as HSegment;\n x += isRelative ? prevX : /* istanbul ignore next */ 0;\n } else if (absCommand === \"V\") {\n [, y] = seg as VSegment;\n y += isRelative ? prevY : /* istanbul ignore next */ 0;\n } else {\n [x, y] = seg.slice(-2) as PointTuple;\n x += isRelative ? prevX : 0;\n y += isRelative ? prevY : 0;\n }\n path.push(absolutizeSegment(seg, _index, prevX, prevY) as PathSegment);\n }\n\n composite[pi] = path;\n });\n\n return composite;\n};\nexport default splitPath;\n","import type { PathArray } from \"../types.ts\";\nimport { error } from \"../util/error.ts\";\nimport { splitPath } from \"./splitPath.ts\";\nimport { reversePath } from \"./reversePath.ts\";\n\n/**\n * Reverses the sub-path at a given index of a path.\n *\n * The other sub-paths are left untouched, and the result holds absolute\n * values.\n *\n * @param pathInput - the path string or `PathArray`\n * @param index - the zero-based index of the sub-path to reverse\n * @returns the path with the sub-path reversed\n *\n * @example\n * ```ts\n * reverseSubPath('M0 0L100 0ZM0 100L100 100', 1)\n * // => [\n * // ['M', 0, 0], ['L', 100, 0], ['Z'],\n * // ['M', 100, 100], ['L', 0, 100]\n * // ]\n * ```\n */\nexport const reverseSubPath = (pathInput: string | PathArray, index: number): PathArray => {\n const subPaths = splitPath(pathInput);\n\n if (!Number.isInteger(index) || index < 0 || index >= subPaths.length) {\n throw TypeError(`${error}: index must be a number within the range of the sub-paths`);\n }\n\n const reversed = reversePath(subPaths[index] as PathArray);\n\n return [...subPaths.slice(0, index), reversed, ...subPaths.slice(index + 1)].flat() as PathArray;\n};\n","import CSSMatrix from \"@thednp/dommatrix\";\nimport { defaultOptions } from \"../options/options.ts\";\nimport type { TransformObject } from \"../interface.ts\";\n\n/**\n * Returns a transformation matrix to apply to `<path>` elements.\n *\n * @see TransformObject\n *\n * @param transform the `transformObject`\n * @returns a new transformation matrix\n */\nexport const getSVGMatrix = (transform: Partial<TransformObject>): CSSMatrix => {\n let matrix = new CSSMatrix();\n // the transform origin is always needed, fall back to the default one\n const origin = (transform.origin ?? defaultOptions.origin) as [number, number, number];\n const [originX, originY] = origin;\n const { translate, rotate, skew, scale } = transform;\n\n // set translate\n if (\n Array.isArray(translate) &&\n translate.length >= 2 &&\n translate.every((x) => !Number.isNaN(+x)) &&\n translate.some((x) => x !== 0)\n ) {\n matrix = matrix.translate(...(translate as [number, number, number?]));\n } else if (typeof translate === \"number\" && !Number.isNaN(translate)) {\n matrix = matrix.translate(translate);\n }\n\n if (rotate || skew || scale) {\n // set SVG transform-origin, always defined\n matrix = matrix.translate(originX, originY);\n\n // set rotation\n if (\n Array.isArray(rotate) &&\n rotate.length >= 2 &&\n rotate.every((x) => !Number.isNaN(+x)) &&\n rotate.some((x) => x !== 0)\n ) {\n matrix = matrix.rotate(...(rotate as [number, number, number?]));\n } else if (typeof rotate === \"number\" && !Number.isNaN(rotate)) {\n matrix = matrix.rotate(rotate);\n }\n\n // set skew(s)\n if (\n Array.isArray(skew) &&\n skew.length === 2 &&\n skew.every((x) => !Number.isNaN(+x)) &&\n skew.some((x) => x !== 0)\n ) {\n matrix = skew[0] ? matrix.skewX(skew[0]) : matrix;\n matrix = skew[1] ? matrix.skewY(skew[1]) : matrix;\n } else if (typeof skew === \"number\" && !Number.isNaN(skew)) {\n matrix = matrix.skewX(skew);\n }\n\n // set scale\n if (\n Array.isArray(scale) &&\n scale.length >= 2 &&\n scale.every((x) => !Number.isNaN(+x)) &&\n scale.some((x) => x !== 1)\n ) {\n matrix = matrix.scale(...(scale as [number, number, number?]));\n } else if (typeof scale === \"number\" && !Number.isNaN(scale)) {\n matrix = matrix.scale(scale);\n }\n // set SVG transform-origin\n matrix = matrix.translate(-originX, -originY);\n }\n\n return matrix;\n};\n","import CSSMatrix from \"@thednp/dommatrix\";\nimport type { PointTuple } from \"../types.ts\";\n\n/**\n * Transforms a specified point using a matrix, returning a new\n * Tuple *Object* comprising of the transformed point.\n * Neither the matrix nor the original point are altered.\n *\n * @copyright thednp © 2021\n *\n * @param cssm CSSMatrix instance\n * @param v Tuple\n * @returns the resulting Tuple\n */\nconst translatePoint = (\n cssm: CSSMatrix,\n v: [number, number, number, number],\n): [number, number, number, number] => {\n if (cssm.is2D) {\n return [\n cssm.a * v[0] + cssm.c * v[1] + cssm.e * v[3],\n cssm.b * v[0] + cssm.d * v[1] + cssm.f * v[3],\n 0,\n 1,\n ];\n }\n\n let m = CSSMatrix.Translate(v[0], v[1], v[2]);\n\n [, , , m.m44] = v;\n m = cssm.multiply(m);\n\n return [m.m41, m.m42, m.m43, m.m44];\n};\n\n/**\n * Returns the [x,y] projected coordinates for a given an [x,y] point\n * and an [x,y,z] perspective origin point.\n *\n * Equation found here =>\n * http://en.wikipedia.org/wiki/3D_projection#Diagram\n * Details =>\n * https://stackoverflow.com/questions/23792505/predicted-rendering-of-css-3d-transformed-pixel\n *\n * @param m the transformation matrix\n * @param point2D the initial [x,y] coordinates\n * @param origin the [x,y,z] transform origin\n * @returns the projected [x,y] coordinates\n */\nexport const projection2d = (\n m: CSSMatrix,\n point2D: PointTuple,\n origin: [number, number, number],\n): PointTuple => {\n const [originX, originY, originZ] = origin;\n const [x, y, z] = translatePoint(m, [point2D[0], point2D[1], 0, 1]);\n\n const relativePositionX = x - originX;\n const relativePositionY = y - originY;\n const relativePositionZ = z - originZ;\n\n // protect against division by ZERO, and against a zero origin distance\n // which means there is no perspective scaling at all\n const numerator = Math.abs(originZ);\n const denominator = Math.abs(relativePositionZ);\n const factor = numerator === 0 || denominator === 0 ? 1 : numerator / denominator;\n\n return [relativePositionX * factor + originX, relativePositionY * factor + originY];\n};\n","import { getSVGMatrix } from \"./getSVGMatrix.ts\";\nimport { projection2d } from \"./projection2d.ts\";\nimport { defaultOptions } from \"../options/options.ts\";\nimport type {\n AbsoluteArray,\n AbsoluteCommand,\n AbsoluteSegment,\n CSegment,\n HSegment,\n LSegment,\n PathArray,\n PathSegment,\n VSegment,\n} from \"../types.ts\";\nimport type { TransformObject } from \"../interface.ts\";\nimport { iterate } from \"./iterate.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { absolutizeSegment } from \"./absolutizeSegment.ts\";\nimport { arcToCubic } from \"./arcToCubic.ts\";\n\n/**\n * Applies a 2D transformation to a `PathArray` in a single pass, without\n * absolutizing or copying each segment, returning a new absolute `PathArray`.\n *\n * @param path the parsed path value\n * @param a the `a` value of the matrix\n * @param b the `b` value of the matrix\n * @param c the `c` value of the matrix\n * @param d the `d` value of the matrix\n * @param e the `e` value of the matrix\n * @param f the `f` value of the matrix\n * @param originX the transform origin `x` value\n * @param originY the transform origin `y` value\n * @returns the transformed absolute path\n */\nconst transform2D = (\n path: PathArray,\n a: number,\n b: number,\n c: number,\n d: number,\n e: number,\n f: number,\n originX: number,\n originY: number,\n): AbsoluteArray => {\n const result = [] as unknown as AbsoluteArray;\n let x = 0;\n let y = 0;\n let lx = 0;\n let ly = 0;\n let ox = 0;\n let oy = 0;\n let omx = 0;\n let omy = 0;\n\n for (let i = 0, len = path.length; i < len; i += 1) {\n const seg = path[i] as PathSegment;\n const pathCommand = seg[0] as string;\n const commandCode = pathCommand.charCodeAt(0);\n const isRelative = commandCode >= 97;\n const absCommand = (\n isRelative ? String.fromCharCode(commandCode - 32) : pathCommand\n ) as AbsoluteCommand;\n // the parser rewrites a leading relative moveto as an absolute one, so\n // the first segment is always absolute here\n const outCommand = absCommand;\n\n if (absCommand === \"Z\") {\n result.push([\"Z\"] as AbsoluteSegment);\n ox = omx;\n oy = omy;\n continue;\n }\n\n if (absCommand === \"V\") {\n const absY = (seg[1] as number) + (isRelative ? oy : 0);\n lx = a * ox + c * absY + e - originX + originX;\n ly = b * ox + d * absY + f - originY + originY;\n /* istanbul ignore else */\n if (x !== lx && y !== ly) {\n result.push([\"L\", lx, ly] as LSegment);\n } else if (y === ly) {\n result.push([\"H\", lx] as HSegment);\n } else if (x === lx) {\n result.push([\"V\", ly] as VSegment);\n } else {\n result.push([\"L\", ox, absY] as LSegment);\n }\n oy = absY;\n x = lx;\n y = ly;\n continue;\n }\n\n if (absCommand === \"H\") {\n const absX = (seg[1] as number) + (isRelative ? ox : 0);\n lx = a * absX + c * oy + e - originX + originX;\n ly = b * absX + d * oy + f - originY + originY;\n /* istanbul ignore else */\n if (x !== lx && y !== ly) {\n result.push([\"L\", lx, ly] as LSegment);\n } else if (y === ly) {\n result.push([\"H\", lx] as HSegment);\n } else if (x === lx) {\n result.push([\"V\", ly] as VSegment);\n } else {\n result.push([\"L\", absX, oy] as LSegment);\n }\n ox = absX;\n x = lx;\n y = ly;\n continue;\n }\n\n if (absCommand === \"A\") {\n const absX = (seg[6] as number) + (isRelative ? ox : 0);\n const absY = (seg[7] as number) + (isRelative ? oy : 0);\n const cubics = arcToCubic(\n ox,\n oy,\n seg[1] as number,\n seg[2] as number,\n seg[3] as number,\n seg[4] as number,\n seg[5] as number,\n absX,\n absY,\n );\n const cubicsLen = cubics.length;\n let k = 0;\n /* istanbul ignore else */\n if (cubicsLen > 0) {\n do {\n const piece = [\"C\"] as unknown as CSegment;\n const end = k + 6;\n for (let j = k; j < end; j += 2) {\n lx = a * cubics[j] + c * cubics[j + 1] + e - originX + originX;\n ly = b * cubics[j] + d * cubics[j + 1] + f - originY + originY;\n piece.push(lx, ly);\n }\n result.push(piece);\n k = end;\n } while (k < cubicsLen);\n } else {\n /* istanbul ignore next */\n result.push([\"C\"] as unknown as AbsoluteSegment);\n }\n /* istanbul ignore else */\n if (cubicsLen > 0) {\n ox = cubics[cubicsLen - 2];\n oy = cubics[cubicsLen - 1];\n } else {\n /* istanbul ignore next */\n ox = absX;\n /* istanbul ignore next */\n oy = absY;\n }\n x = lx;\n y = ly;\n continue;\n }\n\n if (absCommand === \"L\") {\n const absX = (seg[1] as number) + (isRelative ? ox : 0);\n const absY = (seg[2] as number) + (isRelative ? oy : 0);\n lx = a * absX + c * absY + e - originX + originX;\n ly = b * absX + d * absY + f - originY + originY;\n /* istanbul ignore else */\n if (x !== lx && y !== ly) {\n result.push([\"L\", lx, ly] as LSegment);\n } else if (y === ly) {\n result.push([\"H\", lx] as HSegment);\n } else if (x === lx) {\n result.push([\"V\", ly] as VSegment);\n } else {\n result.push([\"L\", absX, absY] as LSegment);\n }\n ox = absX;\n oy = absY;\n x = lx;\n y = ly;\n continue;\n }\n\n {\n const piece = [outCommand] as [AbsoluteCommand, ...number[]];\n const segLen = seg.length;\n for (let j = 1; j < segLen; j += 2) {\n const absX = (seg[j] as number) + (isRelative ? ox : 0);\n const absY = (seg[j + 1] as number) + (isRelative ? oy : 0);\n lx = a * absX + c * absY + e - originX + originX;\n ly = b * absX + d * absY + f - originY + originY;\n piece.push(lx, ly);\n }\n result.push(piece as AbsoluteSegment);\n ox = (seg[segLen - 2] as number) + (isRelative ? ox : 0);\n oy = (seg[segLen - 1] as number) + (isRelative ? oy : 0);\n if (absCommand === \"M\") {\n omx = ox;\n omy = oy;\n }\n x = lx;\n y = ly;\n }\n }\n\n return result;\n};\n\n/**\n * Apply a 2D / 3D transformation to a PathArray.\n *\n * Since SVGElement doesn't support 3D transformation, this function\n * creates a 2D projection of the path element.\n *\n * @param pathInput - The PathArray or path string to transform\n * @param transform - The transform functions object (translate, rotate, skew, scale, origin)\n * @returns The transformed PathArray\n *\n * @example\n * ```ts\n * transformPath('M0 0L100 0L100 100L0 100Z', { translate: [10, 20], scale: 2 })\n * // => [['M', 10, 20], ['H', 210], ['V', 220], ['H', 10], ['Z']]\n * ```\n */\nexport const transformPath = <T extends PathArray>(\n pathInput: T | string,\n transform?: Partial<TransformObject>,\n): T | AbsoluteArray => {\n // transform uses it's own set of params\n const path = parsePathString(pathInput);\n const transformProps = transform && Object.keys(transform);\n\n // when used as a static method, invalidate somehow\n if (!transform || (transformProps && !transformProps.length)) {\n return path.slice(0) as T;\n }\n\n // transform origin is extremely important, the caller's object must not\n // be modified and the global default must not be aliased\n const origin = (transform.origin ?? defaultOptions.origin).slice(0) as [number, number, number];\n const matrixInstance = getSVGMatrix({ ...transform, origin });\n\n if (matrixInstance.isIdentity) return path.slice(0) as T;\n\n if (matrixInstance.is2D) {\n return transform2D(\n path,\n matrixInstance.a,\n matrixInstance.b,\n matrixInstance.c,\n matrixInstance.d,\n matrixInstance.e,\n matrixInstance.f,\n origin[0],\n origin[1],\n );\n }\n\n // last x and y transformed values\n let x = 0;\n let y = 0;\n // new x and y transformed\n let lx = 0;\n let ly = 0;\n // segment params iteration index and length\n let j = 0;\n let jj = 0;\n\n return iterate(path, (seg, index, lastX, lastY) => {\n const [pathCommand] = seg;\n const absCommand = pathCommand.toUpperCase();\n const isRelative = absCommand !== pathCommand;\n const absoluteSegment = isRelative\n ? absolutizeSegment(seg, index, lastX, lastY)\n : (seg.slice(0) as AbsoluteSegment);\n\n let result =\n absCommand === \"A\"\n ? ([\"C\" as string | number].concat(\n arcToCubic(\n lastX,\n lastY,\n absoluteSegment[1] as number,\n absoluteSegment[2] as number,\n absoluteSegment[3] as number,\n absoluteSegment[4] as number,\n absoluteSegment[5] as number,\n absoluteSegment[6] as number,\n absoluteSegment[7] as number,\n ),\n ) as CSegment)\n : absCommand === \"V\"\n ? ([\"L\", lastX, absoluteSegment[1]] as LSegment)\n : absCommand === \"H\"\n ? ([\"L\", absoluteSegment[1], lastY] as LSegment)\n : absoluteSegment;\n\n // update pathCommand\n const isLongArc = result[0] === \"C\" && result.length > 7;\n\n if (isLongArc) {\n const tempSegment = result.slice(0, 7) as CSegment;\n path.splice(\n index + 1,\n 0,\n [\"C\" as (typeof result)[0] | number].concat(result.slice(7)) as CSegment,\n );\n result = tempSegment;\n }\n\n if (result[0] === \"L\") {\n [lx, ly] = projection2d(\n matrixInstance,\n [(result as LSegment)[1], (result as LSegment)[2]],\n origin,\n );\n\n /* istanbul ignore else */\n if (x !== lx && y !== ly) {\n result = [\"L\", lx, ly];\n } else if (y === ly) {\n result = [\"H\", lx];\n } else if (x === lx) {\n result = [\"V\", ly];\n }\n } else {\n for (j = 1, jj = result.length; j < jj; j += 2) {\n [lx, ly] = projection2d(matrixInstance, [+result[j], +result[j + 1]], origin);\n result[j] = lx;\n result[j + 1] = ly;\n }\n }\n // now update x and y\n x = lx;\n y = ly;\n\n return result;\n }) as AbsoluteArray;\n};\n","import type { CSegment, CurveArray, MSegment, PathCommand } from \"../types.ts\";\n\n/**\n * Reverses all segments of a `pathArray`\n * which consists of only C (cubic-bezier) path commands.\n *\n * @param path the source `pathArray`\n * @returns the reversed `pathArray`\n */\nexport const reverseCurve = (path: CurveArray): CurveArray => {\n const rotatedCurve = path\n .slice(1)\n .map((x, i, curveOnly) =>\n !i\n ? path[0].slice(1).concat(x.slice(1) as number[])\n : curveOnly[i - 1].slice(-2).concat(x.slice(1)),\n )\n .map((x) => x.map((_, i) => x[x.length - i - 2 * (1 - (i % 2))]))\n .reverse() as (MSegment | CSegment)[];\n\n return [[\"M\" as PathCommand | number].concat(rotatedCurve[0].slice(0, 2))].concat(\n rotatedCurve.map((x) => [\"C\" as PathCommand | number].concat(x.slice(2))),\n ) as CurveArray;\n};\n","import type { PathArray } from \"../types.ts\";\nimport { defaultOptions } from \"../options/options.ts\";\nimport { iterate } from \"./iterate.ts\";\nimport { roundSegment } from \"./roundSegment.ts\";\n\n/**\n * Rounds the values of a `pathArray` instance to\n * a specified amount of decimals and returns it.\n *\n * @param path the source `pathArray`\n * @param roundOption the amount of decimals to round numbers to\n * @returns the resulted `pathArray` with rounded values\n */\nexport const roundPath = <T extends PathArray>(path: T, roundOption?: number | \"off\"): T => {\n let { round } = defaultOptions;\n // allow for ZERO decimals\n round =\n roundOption === \"off\"\n ? roundOption\n : typeof roundOption === \"number\" && roundOption >= 0\n ? roundOption\n : typeof round === \"number\" && round >= 0\n ? round\n : \"off\";\n\n /* istanbul ignore else */\n if (round === \"off\") return path.slice(0) as T;\n\n // the caller's array must not be modified in place\n return iterate(path.slice(0) as T, (segment) => {\n return roundSegment(segment, round);\n });\n};\n","import type { NormalArray } from \"../types.ts\";\n\n/**\n * Splits a normalized path into its sub-paths.\n *\n * A sub-path begins with a moveto command, so the path is split at every\n * moveto: the close segment of a sub-path belongs to the sub-path it closes.\n *\n * @param path - the normalized path to split\n * @returns the sub-paths of the path\n *\n * @example\n * ```ts\n * splitSubPaths([[\"M\", 0, 0], [\"L\", 10, 0], [\"Z\"], [\"M\", 20, 0], [\"L\", 30, 0]]);\n * // => [\n * // [[\"M\", 0, 0], [\"L\", 10, 0], [\"Z\"]],\n * // [[\"M\", 20, 0], [\"L\", 30, 0]],\n * // ]\n * ```\n */\nexport const splitSubPaths = (path: NormalArray): NormalArray[] => {\n const result: NormalArray[] = [];\n let current: NormalArray = [] as unknown as NormalArray;\n for (const segment of path) {\n if (segment[0] === \"M\") {\n // the path is not empty, so the first sub-path is never missing\n if (current.length) result.push(current);\n current = [segment] as unknown as NormalArray;\n } else {\n current.push(segment);\n }\n }\n if (current.length) result.push(current);\n return result;\n};\n","import type { CubicCoordinates, NormalArray, Point, QuadCoordinates } from \"../types.ts\";\nimport { buildPathLengthTable } from \"../util/pathLengthTable.ts\";\nimport { getPointAtCubicSegmentLength } from \"../math/cubicTools.ts\";\nimport { getPointAtQuadSegmentLength } from \"../math/quadTools.ts\";\nimport { arcPoint, getArcProps } from \"../math/arcTools.ts\";\n\n/**\n * Returns the number of samples of a segment.\n *\n * The samples are spread over the parameter of the segment, so their number\n * grows with the length of the segment: a straight segment needs none, a\n * curve needs one every step.\n *\n * @param length - the length of the segment\n * @param step - the maximum distance between two samples\n * @returns the number of samples of the segment\n */\nconst sampleCount = (length: number, step: number): number => Math.max(2, Math.ceil(length / step));\n\n/**\n * Returns the points of a normalized path, sampled along its segments.\n *\n * The samples are the points the simplification measures: they sit on the\n * path itself, so the distance between the path and the result is measured\n * against the path and not against an approximation of it.\n *\n * A straight segment needs no sample of its own, the chord of a straight\n * segment is the segment: the same goes for the close segment, the\n * deviation of a chord from a straight line is at its ends and the ends are\n * the samples of the segments around it.\n *\n * @param path - the normalized path to sample\n * @param step - the maximum distance between two samples\n * @returns the samples of the path, in path order\n */\nexport const samplePath = (path: NormalArray, step: number): Point[] => {\n const { measures } = buildPathLengthTable(path);\n const samples: Point[] = [];\n\n for (const measure of measures) {\n const { geometry: segment, startX, startY, endX, endY, length } = measure;\n const command = segment[0];\n\n if (command === \"Z\") {\n // the close segment returns to the start of the sub-path\n samples.push({ x: endX, y: endY });\n continue;\n }\n\n if (command === \"M\" || command === \"L\") {\n samples.push({ x: endX, y: endY });\n } else if (command === \"C\") {\n const count = sampleCount(length, step);\n const coords = [\n startX,\n startY,\n segment[1] as number,\n segment[2] as number,\n segment[3] as number,\n segment[4] as number,\n endX,\n endY,\n ] as CubicCoordinates;\n for (let i = 1; i < count; i += 1) {\n samples.push(getPointAtCubicSegmentLength(coords, i / count));\n }\n // the last sample of a segment is its end point\n samples.push({ x: endX, y: endY });\n } else if (command === \"Q\") {\n const count = sampleCount(length, step);\n const coords = [\n startX,\n startY,\n segment[1] as number,\n segment[2] as number,\n endX,\n endY,\n ] as QuadCoordinates;\n for (let i = 1; i < count; i += 1) {\n samples.push(getPointAtQuadSegmentLength(coords, i / count));\n }\n samples.push({ x: endX, y: endY });\n } else {\n // a normalized path holds no other command than the ones handled here\n const rx = segment[1] as number;\n const ry = segment[2] as number;\n const angle = segment[3] as number;\n // a zero radius is a straight line to the end point\n if (rx === 0 || ry === 0) {\n samples.push({ x: endX, y: endY });\n continue;\n }\n const {\n center,\n rx: radiusX,\n ry: radiusY,\n startAngle,\n endAngle,\n } = getArcProps(\n startX,\n startY,\n rx,\n ry,\n angle,\n segment[4] as number,\n segment[5] as number,\n endX,\n endY,\n );\n const count = sampleCount(length, step);\n const alpha = (((angle % 360) + 360) % 360) * (Math.PI / 180);\n const sweep = endAngle - startAngle;\n for (let i = 1; i < count; i += 1) {\n const [x, y] = arcPoint(\n center.x,\n center.y,\n radiusX,\n radiusY,\n alpha,\n startAngle + (sweep * i) / count,\n );\n samples.push({ x, y });\n }\n samples.push({ x: endX, y: endY });\n }\n }\n\n return samples;\n};\n","import type { Point } from \"../types.ts\";\nimport { distanceToSegment } from \"../math/distanceToSegment.ts\";\n\n/**\n * Returns the indexes of the points that have to be kept to approximate a\n * polyline within a given tolerance, with the Douglas-Peucker algorithm.\n *\n * The first and the last point of the polyline are always kept, the points\n * in between are kept when they are further from the chord between the two\n * points around them than the tolerance.\n *\n * @see https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm\n *\n * @param points - the points of the polyline\n * @param tolerance - the maximum distance from the simplified polyline\n * @returns the indexes of the points to keep, in order\n */\nexport const douglasPeucker = (points: Point[], tolerance: number): number[] => {\n // a polyline of one or two points is already simple enough\n if (points.length < 3) return points.map((_point, index) => index);\n\n const keep = points.map(() => false);\n keep[0] = true;\n keep[points.length - 1] = true;\n\n // the pairs of points to measure, as a stack: the recursion of the\n // original algorithm would blow the stack on a long polyline\n const stack: number[] = [0, points.length - 1];\n while (stack.length) {\n const last = stack.pop() as number;\n const first = stack.pop() as number;\n const start = points[first];\n const end = points[last];\n let maxDistance = 0;\n let index = -1;\n for (let i = first + 1; i < last; i += 1) {\n const distance = distanceToSegment(points[i], start, end);\n if (distance > maxDistance) {\n maxDistance = distance;\n index = i;\n }\n }\n if (index === -1 || maxDistance <= tolerance) continue;\n\n keep[index] = true;\n const span = last - first;\n // a split at the edge of the range would make the recursion as deep as\n // the range is long, so the range is split in the middle as well\n const edge = span >> 3;\n if (span > 8 && (index - first < edge || last - index < edge)) {\n const middle = first + (span >> 1);\n // the range is split in three, at the worst point and in the middle:\n // the middle is a corner of the result, so it is kept\n keep[middle] = true;\n // the three parts of the range do not overlap\n if (index < middle) {\n stack.push(middle, last, index, middle, first, index);\n } else {\n stack.push(index, last, middle, index, first, middle);\n }\n } else {\n stack.push(index, last, first, index);\n }\n }\n\n return points.map((_point, index) => index).filter((index) => keep[index]);\n};\n","import type { CSegment, Point } from \"../types.ts\";\n\nconst MAX_ITERATIONS = 4;\n\nconst subtract = (a: Point, b: Point): Point => ({ x: a.x - b.x, y: a.y - b.y });\nconst add = (a: Point, b: Point): Point => ({ x: a.x + b.x, y: a.y + b.y });\nconst scale = (point: Point, value: number): Point => ({\n x: point.x * value,\n y: point.y * value,\n});\nconst dot = (a: Point, b: Point): number => a.x * b.x + a.y * b.y;\nconst distance = (a: Point, b: Point): number => Math.hypot(a.x - b.x, a.y - b.y);\nconst normalize = (point: Point): Point => {\n const length = Math.hypot(point.x, point.y);\n return length ? scale(point, 1 / length) : { x: 0, y: 0 };\n};\nconst negate = (point: Point): Point => ({ x: -point.x, y: -point.y });\n\nconst chordParameters = (points: Point[]): number[] => {\n const parameters = [0];\n for (let i = 1; i < points.length; i += 1) {\n parameters.push(parameters[i - 1] + distance(points[i - 1], points[i]));\n }\n const total = parameters[parameters.length - 1];\n return parameters.map((parameter) => parameter / total);\n};\n\nconst evaluate = (curve: Point[], t: number): Point => {\n const u = 1 - t;\n return add(\n add(scale(curve[0], u ** 3), scale(curve[1], 3 * u * u * t)),\n add(scale(curve[2], 3 * u * t * t), scale(curve[3], t ** 3)),\n );\n};\n\nconst generateCurve = (\n points: Point[],\n parameters: number[],\n leftTangent: Point,\n rightTangent: Point,\n): Point[] => {\n const first = points[0];\n const last = points[points.length - 1];\n const segmentLength = distance(first, last);\n\n if (points.length === 2) {\n const handle = segmentLength / 3;\n return [\n first,\n add(first, scale(leftTangent, handle)),\n add(last, scale(rightTangent, handle)),\n last,\n ];\n }\n\n let c00 = 0;\n let c01 = 0;\n let c11 = 0;\n let x0 = 0;\n let x1 = 0;\n\n for (let i = 0; i < points.length; i += 1) {\n const t = parameters[i];\n const u = 1 - t;\n const b0 = u ** 3;\n const b1 = 3 * u * u * t;\n const b2 = 3 * u * t * t;\n const b3 = t ** 3;\n const a0 = scale(leftTangent, b1);\n const a1 = scale(rightTangent, b2);\n const tmp = subtract(points[i], add(scale(first, b0 + b1), scale(last, b2 + b3)));\n c00 += dot(a0, a0);\n c01 += dot(a0, a1);\n c11 += dot(a1, a1);\n x0 += dot(a0, tmp);\n x1 += dot(a1, tmp);\n }\n\n const determinant = c00 * c11 - c01 * c01;\n let alphaLeft = determinant ? (x0 * c11 - x1 * c01) / determinant : 0;\n let alphaRight = determinant ? (c00 * x1 - c01 * x0) / determinant : 0;\n const epsilon = 1e-6 * segmentLength;\n if (alphaLeft < epsilon || alphaRight < epsilon) {\n alphaLeft = segmentLength / 3;\n alphaRight = alphaLeft;\n }\n\n return [\n first,\n add(first, scale(leftTangent, alphaLeft)),\n add(last, scale(rightTangent, alphaRight)),\n last,\n ];\n};\n\nconst findMaxError = (\n points: Point[],\n curve: Point[],\n parameters: number[],\n): { error: number; split: number } => {\n let error = 0;\n let split = points.length >> 1;\n for (let i = 1; i < points.length - 1; i += 1) {\n const point = evaluate(curve, parameters[i]);\n const current = (point.x - points[i].x) ** 2 + (point.y - points[i].y) ** 2;\n if (current > error) {\n error = current;\n split = i;\n }\n }\n return { error, split };\n};\n\nconst refineParameter = (curve: Point[], point: Point, parameter: number): number => {\n const t = parameter;\n const u = 1 - t;\n const q = evaluate(curve, t);\n const q1 = add(\n add(\n scale(subtract(curve[1], curve[0]), 3 * u * u),\n scale(subtract(curve[2], curve[1]), 6 * u * t),\n ),\n scale(subtract(curve[3], curve[2]), 3 * t * t),\n );\n const q2 = add(\n scale(add(subtract(curve[2], scale(curve[1], 2)), curve[0]), 6 * u),\n scale(add(subtract(curve[3], scale(curve[2], 2)), curve[1]), 6 * t),\n );\n const difference = subtract(q, point);\n const denominator = dot(q1, q1) + dot(q2, difference);\n return denominator ? t - dot(q1, difference) / denominator : t;\n};\n\nconst reparameterize = (curve: Point[], points: Point[], parameters: number[]): number[] =>\n parameters.map((parameter, index) =>\n index === 0 || index === points.length - 1\n ? parameter\n : refineParameter(curve, points[index], parameter),\n );\n\nconst toSegments = (curves: Point[][]): CSegment[] =>\n curves.map((curve) => [\n \"C\",\n curve[1].x,\n curve[1].y,\n curve[2].x,\n curve[2].y,\n curve[3].x,\n curve[3].y,\n ]);\n\nexport const fitCubic = (points: Point[], tolerance: number): CSegment[] => {\n const error = tolerance * tolerance;\n const curves: Point[][] = [];\n\n const fit = (range: Point[], leftTangent: Point, rightTangent: Point): void => {\n const parameters = chordParameters(range);\n let curve = generateCurve(range, parameters, leftTangent, rightTangent);\n let maximum = findMaxError(range, curve, parameters);\n\n if (maximum.error <= error || range.length === 2) {\n curves.push(curve);\n return;\n }\n\n let currentParameters = parameters;\n for (let i = 0; i < MAX_ITERATIONS; i += 1) {\n currentParameters = reparameterize(curve, range, currentParameters);\n curve = generateCurve(range, currentParameters, leftTangent, rightTangent);\n maximum = findMaxError(range, curve, currentParameters);\n if (maximum.error <= error) {\n curves.push(curve);\n return;\n }\n }\n\n const split = maximum.split;\n const centerTangent = normalize(subtract(range[split - 1], range[split + 1]));\n fit(range.slice(0, split + 1), leftTangent, centerTangent);\n fit(range.slice(split), negate(centerTangent), rightTangent);\n };\n\n fit(\n points,\n normalize(subtract(points[1], points[0])),\n normalize(subtract(points[points.length - 2], points[points.length - 1])),\n );\n return toSegments(curves);\n};\n","import type { LSegment, MSegment, PathArray, ZSegment } from \"../types.ts\";\nimport type { SimplifyOptions } from \"../interface.ts\";\nimport { error } from \"../util/error.ts\";\nimport { normalizePath } from \"./normalizePath.ts\";\nimport { splitSubPaths } from \"./splitSubPaths.ts\";\nimport { buildPathLengthTable } from \"../util/pathLengthTable.ts\";\nimport { samplePath } from \"./samplePath.ts\";\nimport { douglasPeucker } from \"./douglasPeucker.ts\";\nimport { fitCubic } from \"./fitCubic.ts\";\n\n/**\n * The default tolerance of the simplification.\n */\nconst defaultTolerance = 1;\n\n/**\n * The maximum number of samples of a path.\n *\n * The samples are the measurements of the algorithm, so their number grows\n * with the length of the path and shrinks with the tolerance: a very long\n * path with a very small tolerance would need millions of samples, so the\n * sampling is capped and the step grows to fit.\n */\nconst MAX_SAMPLES = 20000;\n\n/**\n * The share of the tolerance the samples are spread with.\n *\n * The curve is sampled with a step of a sixteenth of the tolerance, so the\n * deviation of the curve between two samples is a fraction of the tolerance\n * itself: a range is only accepted when the curve stays within four fifths\n * of the tolerance from the chord, so the result cannot exceed it.\n */\nconst SAMPLE_SHARE = 16;\n\n/**\n * The share of the tolerance a range of the path may use.\n *\n * The samples are a discretization of the path, so the deviation between two\n * samples is not measured: the range is accepted at four fifths of the\n * tolerance, so the result stays within the tolerance even when the curve\n * bulges a little between two samples.\n */\nconst ACCEPTANCE = 0.8;\n\n/**\n * Simplifies a path within a geometric tolerance.\n *\n * Straight-line runs are reduced with Douglas-Peucker. Curve runs are fitted\n * with cubic Béziers, while arcs and original curves are preserved whenever\n * fitting would not reduce the segment count. Every source sub-path and its\n * closure are retained.\n *\n * The tolerance is the target geometric error of the sampled fitting. A\n * smaller tolerance keeps more detail, a bigger one removes more.\n *\n * @param pathInput - the target path string or PathArray\n * @param options - the tolerance of the simplification, or the options\n * @returns the simplified path\n *\n * @example\n * ```ts\n * simplifyPath(\"M0 0L10 0L20 0L30 0\", 1)\n * // => [['M', 0, 0], ['L', 30, 0]]\n * ```\n */\nexport const simplifyPath = (\n pathInput: string | PathArray,\n options?: number | SimplifyOptions,\n): PathArray => {\n const tolerance =\n typeof options === \"number\" ? options : (options?.tolerance ?? defaultTolerance);\n\n if (!Number.isFinite(tolerance) || tolerance <= 0) {\n throw new TypeError(`${error}: tolerance must be a positive number`);\n }\n\n const normalized = normalizePath(pathInput);\n if (!normalized.length) return [] as unknown as PathArray;\n\n const result: PathArray = [] as unknown as PathArray;\n for (const subPath of splitSubPaths(normalized)) {\n const closed = subPath[subPath.length - 1][0] === \"Z\";\n const straight = subPath\n .slice(1)\n .every(\n (segment) =>\n segment[0] === \"L\" ||\n segment[0] === \"Z\" ||\n (segment[0] === \"A\" && (segment[1] === 0 || segment[2] === 0)),\n );\n const { totalLength } = buildPathLengthTable(subPath);\n const step = Math.max(tolerance / SAMPLE_SHARE, totalLength / MAX_SAMPLES);\n const samples = samplePath(subPath, step);\n const start = samples[0];\n\n if (straight) {\n const kept = douglasPeucker(samples, tolerance * ACCEPTANCE);\n result.push([\"M\", start.x, start.y] as MSegment);\n const end = closed ? kept.length - 1 : kept.length;\n for (let i = 1; i < end; i += 1) {\n const point = samples[kept[i]];\n result.push([\"L\", point.x, point.y] as LSegment);\n }\n if (closed) result.push([\"Z\"] as ZSegment);\n continue;\n }\n\n const originalCount = subPath.length - 1 - (closed ? 1 : 0);\n const points = samples.filter(\n (point, index) =>\n index === 0 || point.x !== samples[index - 1].x || point.y !== samples[index - 1].y,\n );\n const curves =\n originalCount > 1 && points.length > 1 ? fitCubic(points, tolerance * ACCEPTANCE) : [];\n\n if (!curves.length || curves.length >= originalCount) {\n result.push(...subPath);\n continue;\n }\n\n result.push([\"M\", start.x, start.y] as MSegment, ...curves);\n if (closed) result.push([\"Z\"] as ZSegment);\n }\n\n return result;\n};\n","// src/morph/fixPath.ts\nimport type { PathArray } from \"../types.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { normalizePath } from \"../process/normalizePath.ts\";\nimport { isClosedPath } from \"../util/isClosedPath.ts\";\n\n/**\n * Checks a `PathArray` for an unnecessary `Z` segment\n * and returns a copy without it. The input is not modified.\n * In short, if the segment before `Z` extends to `M`,\n * the `Z` segment must be removed.\n *\n * The `pathInput` must be a single path, without\n * sub-paths. For multi-path `<path>` elements,\n * use `splitPath` first and apply this utility on each\n * sub-path separately.\n *\n * @param pathInput the `pathArray` source\n * @returns the fixed path\n */\nexport const fixPath = <T extends PathArray>(pathInput: T | string): PathArray => {\n const pathArray = parsePathString(pathInput);\n\n /* istanbul ignore else */\n if (isClosedPath(pathArray)) {\n const normalArray = normalizePath(pathArray);\n const length = pathArray.length;\n const segBeforeZ = length - 2;\n const [mx, my] = normalArray[0].slice(1);\n const [x, y] = normalArray[segBeforeZ].slice(-2);\n\n if (mx === x && my === y) {\n pathArray.splice(length - 1, 1);\n }\n }\n\n return pathArray;\n};\n","// src/morph/splitCubicSegment.ts\n\nimport { midPoint } from \"../math/midPoint.ts\";\nimport type { CubicCoordinates } from \"../types.ts\";\n\n/**\n * Split a cubic Bézier into two cubics at parameter t [0–1].\n *\n * @param x1 - Start point X\n * @param y1 - Start point Y\n * @param x2 - First control point X\n * @param y2 - First control point Y\n * @param x3 - Second control point X\n * @param y3 - Second control point Y\n * @param x4 - End point X\n * @param y4 - End point Y\n * @param t - Parameter in range [0, 1] at which to split\n * @returns Array of two cubic segments, each as [x1,y1, x2,y2, x3,y3, x4,y4]\n */\nexport function splitCubicSegment(\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n x3: number,\n y3: number,\n x4: number,\n y4: number,\n t: number,\n): [CubicCoordinates, CubicCoordinates] {\n const [px01, py01] = midPoint([x1, y1], [x2, y2], t);\n const [px12, py12] = midPoint([x2, y2], [x3, y3], t);\n const [px23, py23] = midPoint([x3, y3], [x4, y4], t);\n\n const [cx0, cy0] = midPoint([px01, py01], [px12, py12], t);\n const [cx1, cy1] = midPoint([px12, py12], [px23, py23], t);\n\n const [px, py] = midPoint([cx0, cy0], [cx1, cy1], t);\n\n return [\n [x1, y1, px01, py01, cx0, cy0, px, py], // first segment\n [px, py, cx1, cy1, px23, py23, x4, y4], // second segment\n ];\n}\n","// src/convert/pathToPolyline.ts\nimport type {\n LSegment,\n PointTuple,\n PolygonArray,\n PolylineArray,\n // PathArray,\n} from \"../types.ts\";\nimport { normalizePath } from \"../process/normalizePath.ts\";\nimport { isPolygonArray } from \"../util/isPolygonArray.ts\";\nimport { isPolylineArray } from \"../util/isPolylineArray.ts\";\nimport { isClosedPath } from \"../util/isClosedPath.ts\";\nimport { error } from \"../util/error.ts\";\n\n/**\n * Converts any `PolyLineArray`/`PolygonArray` path (closed or open) to an explicit polyline (M + L*).\n * If the path is closed (has Z), the Z is replaced with an explicit L back to the initial M point.\n * This allows uniform processing without special-casing Z.\n *\n * @param path string or PathArray\n * @returns PolylineArray (M + L*) — never contains Z\n */\nexport const pathToPolyline = <T extends PolygonArray | PolylineArray>(\n path: string | T,\n): PolylineArray => {\n const normal = normalizePath(path);\n if (!isPolygonArray(normal) && !isPolylineArray(normal)) {\n throw TypeError(`${error}: pathValue is not a polyline/polygon`);\n }\n\n // If not closed, return as-is (already a polyline)\n if (!isClosedPath(normal)) {\n return normal as PolylineArray;\n }\n\n // Closed → replace Z with explicit L to initial M\n const result: PolylineArray = [normal[0]]; // Keep M\n const [mx, my] = normal[0].slice(1) as PointTuple;\n\n for (let i = 1; i < normal.length; i++) {\n const seg = normal[i];\n if (seg[0].toUpperCase() === \"Z\") {\n result.push([\"L\", mx, my]);\n } else {\n result.push(seg as LSegment);\n }\n }\n\n return result;\n};\n","// src/morph/splitLineToCount.ts\n\n/**\n * Split a line segment into `count` smaller segments of equal length\n * using the same repeated front-cutting strategy as splitCubicToCount.\n *\n * Does NOT mutate input.\n *\n * @param x1 - Start point X\n * @param y1 - Start point Y\n * @param x2 - End point X\n * @param y2 - End point Y\n * @param count - Number of segments to split into\n * @returns Array of `count` line segments, each as [x1, y1, x2, y2]\n */\nexport default function splitLineToCount(\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n count: number,\n): Array<[number, number, number, number]> {\n if (count <= 1) return [[x1, y1, x2, y2]];\n\n const result: Array<[number, number, number, number]> = [];\n\n let currentX = x1;\n let currentY = y1;\n\n // Loop count times to produce count segments\n // We generate points at 1/count, 2/count, ..., count/count\n let i = 0;\n while (i < count) {\n const t = 1 / (count - i);\n // cut the *remaining* part of the segment, so every piece has the\n // same length\n const nextX = currentX + t * (x2 - currentX);\n const nextY = currentY + t * (y2 - currentY);\n\n result.push([currentX, currentY, nextX, nextY]);\n\n currentX = nextX;\n currentY = nextY;\n i++;\n }\n\n return result;\n}\n","// src/morph/getPathSplits.ts\n\nimport type { CurveArray, PointTuple, PolylineArray } from \"../types.ts\";\nimport { measureSegments } from \"../util/measureSegments.ts\";\nimport { error } from \"../util/error.ts\";\n\n/**\n * Determine the right amount of splits for each segment in a given PathArray\n * and for a target total amount of sub-segments.\n * For a triangle path \"M0,0 L600,300 L0,600 Z\" we have 3 equal lines,\n * we can easily do 4 splits per line and go to town, however, most triangles\n * are not even so we need to take side lengths into account.\n * @param path The target PathArray\n * @param target The total amount of sub-segments\n * @returns an array of numbers reprezenting the sub-segment count for each segment\n */\nexport function getPathSplits<T extends PolylineArray | CurveArray>(\n path: T,\n target: number,\n): number[] {\n if (!Number.isFinite(target)) {\n throw new TypeError(`${error}: target must be a finite number`);\n }\n if (target < 2) throw new TypeError(`${error}: target must be >= 2`);\n\n // one measurement pass gives the length of every segment and the total\n const measures = measureSegments(path);\n const segmentCount = measures.length;\n if (!segmentCount) return [];\n\n const lengths = measures.map(({ length }) => length);\n const totalLength = lengths.reduce((total, length) => total + length, 0);\n if (!totalLength) return Array(segmentCount).fill(1);\n\n // the leading `M` counts as one split and every other segment needs at\n // least one, so the smallest reachable total is one split per segment\n const effectiveTarget = Math.max(Math.floor(target), segmentCount);\n const idealSegLen = totalLength / effectiveTarget;\n\n const splits: number[] = Array(segmentCount).fill(1);\n\n // First pass: distribute the splits proportionally to the segment lengths\n let totalAllocated = 1; // 1 stands for first M segment\n\n for (let i = 1; i < segmentCount; i += 1) {\n const segLen = lengths[i];\n const desired = segLen > idealSegLen ? Math.round(segLen / idealSegLen) : 1;\n\n splits[i] = desired;\n totalAllocated += desired;\n }\n\n // Second pass: adjust to hit the exact target\n let diff = effectiveTarget - totalAllocated;\n\n if (diff !== 0) {\n const candidates: PointTuple[] = [];\n for (let i = 1; i < segmentCount; i += 1) {\n if (lengths[i] > 0) {\n candidates.push([i, lengths[i]]);\n }\n }\n\n if (diff < 0) {\n // take the extra splits away from the shortest segments first\n candidates.sort((a, b) => a[1] - b[1]);\n while (diff < 0) {\n let changed = false;\n for (const [index] of candidates) {\n if (splits[index] > 1) {\n splits[index] -= 1;\n diff += 1;\n changed = true;\n if (diff === 0) break;\n }\n }\n // nothing left to give away - the target cannot be reached\n /* istanbul ignore if - the clamp above makes this unreachable */\n if (!changed) break;\n }\n } else {\n // give the extra splits to the longest segments first\n candidates.sort((a, b) => b[1] - a[1]);\n while (diff > 0) {\n for (const [index] of candidates) {\n splits[index] += 1;\n diff -= 1;\n if (diff === 0) break;\n }\n }\n }\n }\n return splits;\n}\n","// src/morph/splitLinePathToCount.ts\n\nimport type { PointTuple, PolylineArray } from \"../types.ts\";\nimport splitLineToCount from \"./splitLineToCount.ts\";\nimport { getPathSplits } from \"./getPathSplits.ts\";\nimport { error } from \"../util/error.ts\";\n\n/**\n * Splits a PolylineArray so that it has exactly `target` line segments.\n *\n * @param path - The polyline array to split\n * @param target - The desired number of line segments\n * @returns The modified polyline array with the target segment count\n */\nexport function splitLinePathToCount<T extends PolylineArray>(path: T, target: number): T {\n if (path.length < 2 || target <= 1) return path;\n\n const splits = getPathSplits(path, target);\n let totalAdded = 0;\n\n const newPath = [path[0]] as unknown as T;\n const pathLen = path.length;\n let currentX = path[0][1];\n let currentY = path[0][2];\n\n // Build path using splits\n for (let i = 1; i < pathLen; i++) {\n const seg = path[i];\n const [endX, endY] = seg.slice(1) as PointTuple;\n\n const count = splits[i];\n\n // istanbul ignore else\n if (count >= 1) {\n const subLines = splitLineToCount(currentX, currentY, endX, endY, count);\n\n for (const sub of subLines) {\n newPath.push([\"L\", sub[2], sub[3]]);\n totalAdded++;\n }\n }\n\n currentX = endX;\n currentY = endY;\n }\n\n // Final safety: if somehow still wrong, log it\n // istanbul ignore if - this might possibly be impossible to test\n if (newPath.length !== target) {\n console.warn(\n `${error}: requested ${target} segments, got ${newPath.length}. Adjusted on last segment.`,\n );\n }\n\n return newPath;\n}\n","// src/morph/splitCubicToCount.ts\n\nimport type { CubicCoordinates } from \"../types.ts\";\nimport { splitCubicSegment } from \"./splitCubicSegment.ts\";\n\n/**\n * Split a cubic Bézier into `count` segments of roughly equal parameter length.\n * Does NOT mutate input parameters.\n *\n * @param x1 - Start point X\n * @param y1 - Start point Y\n * @param x2 - First control point X\n * @param y2 - First control point Y\n * @param x3 - Second control point X\n * @param y3 - Second control point Y\n * @param x4 - End point X\n * @param y4 - End point Y\n * @param count - Number of segments to split into\n * @returns Array of `count` cubic segments, each as [x1,y1,x2,y2,x3,y3,x4,y4]\n */\nexport function splitCubicToCount(\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n x3: number,\n y3: number,\n x4: number,\n y4: number,\n count: number,\n): Array<CubicCoordinates> {\n if (count <= 1) return [[x1, y1, x2, y2, x3, y3, x4, y4]];\n\n const result: Array<CubicCoordinates> = [];\n\n // Work on local copies to avoid mutating inputs\n let cx1 = x1;\n let cy1 = y1;\n let cx2 = x2;\n let cy2 = y2;\n let cx3 = x3;\n let cy3 = y3;\n let cx4 = x4;\n let cy4 = y4;\n\n let i = 0;\n while (i < count) {\n const t = 1 / (count - i);\n const [first, second] = splitCubicSegment(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4, t);\n\n result.push(first);\n\n // Update working curve to the remaining (second) part\n [cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4] = second;\n i++;\n }\n\n return result;\n}\n","// src/morph/splitCubicPathToCount.ts\nimport type { CSegment, CurveArray, PointTuple } from \"../types.ts\";\nimport { splitCubicToCount } from \"./splitCubicToCount.ts\";\nimport { getPathSplits } from \"./getPathSplits.ts\";\nimport { error } from \"../util/error.ts\";\n\n/**\n * Splits a CurveArray so that it has exactly `target` cubic segments.\n *\n * @param path - The curve array to split\n * @param target - The desired number of cubic segments\n * @returns The modified curve array with the target segment count\n */\nexport function splitCurvePathToCount<T extends CurveArray>(path: T, target: number): T {\n // istanbul ignore else\n if (path.length < 2 || target <= 1) return path;\n\n const splits = getPathSplits(path, target);\n let totalAdded = 0;\n\n const newPath = [path[0]] as unknown as T; // keep M\n const pathLen = path.length;\n let currentX = path[0][1];\n let currentY = path[0][2];\n\n for (let i = 1; i < pathLen; i++) {\n const seg = path[i] as CSegment; /*| ZSegment*/\n const [endX, endY] = seg.slice(-2) as PointTuple;\n\n const count = splits[i];\n\n // istanbul ignore else\n if (count >= 1) {\n const subs = splitCubicToCount(\n currentX,\n currentY,\n seg[1],\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n seg[6],\n count,\n );\n\n for (const sub of subs) {\n newPath.push([\"C\", sub[2], sub[3], sub[4], sub[5], sub[6], sub[7]]);\n totalAdded++;\n }\n }\n currentX = endX;\n currentY = endY;\n }\n\n // Final safety: if somehow still wrong, log it\n // istanbul ignore if\n if (newPath.length !== target) {\n console.warn(`${error}: requested ${target} segments, got ${newPath.length}.`);\n }\n\n return newPath;\n}\n","// src/morph/samplePolygon.ts\n\nimport { error } from \"../util/error.ts\";\nimport { iterate } from \"../process/iterate.ts\";\nimport type { NormalArray, PointTuple } from \"../types.ts\";\n\n/**\n * Samples points from a path to form a polygon approximation.\n * Collects endpoints of each segment (M start + ends of L/C/etc).\n *\n * @param path `PolygonPathArray` or `CurvePathArray`\n * @returns Array of [x, y] points\n */\nexport function samplePolygon<T extends NormalArray>(path: T): PointTuple[] {\n const points: PointTuple[] = [];\n\n let [mx, my] = [0, 0];\n\n iterate(path, (seg) => {\n const cmd = seg[0];\n if (cmd === \"M\") {\n [mx, my] = [seg[1] as number, seg[2] as number];\n points.push([mx, my]);\n } else if (cmd === \"L\") {\n points.push([seg[1] as number, seg[2] as number]);\n } else if (cmd === \"C\") {\n points.push([seg[5] as number, seg[6] as number]);\n } else if (cmd === \"Q\") {\n points.push([seg[3] as number, seg[4] as number]);\n } else if (cmd === \"A\") {\n points.push([seg[6] as number, seg[7] as number]);\n } else if (cmd === \"Z\") {\n points.push([mx, my]);\n } else {\n throw new TypeError(`${error}: path command \"${String(cmd)}\" is not supported`);\n }\n });\n\n return points;\n}\n","// src/morph/getRotatedPath.ts\n\nimport type {\n CSegment,\n // CurveArray,\n LSegment,\n MorphPathArray,\n MSegment,\n PathSegment,\n // PolylineArray,\n ZSegment,\n} from \"../types.ts\";\nimport { error } from \"../util/error.ts\";\n\n/**\n * Returns a single rotation of a path (line or curve) by shifting the start point.\n * The rotation starts at the end of the segment at `idx` and continues with the\n * following segments, wrapping around the end of the path.\n *\n * @param a PathArray (M + L/C + optional Z) — must be single subpath, normalized\n * @param idx the index of the segment the rotation starts at\n * @returns PathArray — the rotation of the path\n */\nexport function getRotation<T extends MorphPathArray>(a: T, idx: number): T {\n const pathLen = a.length;\n const pointCount = pathLen - 1;\n const path = [] as unknown as T;\n\n for (let i = 0; i < pathLen; i++) {\n let oldSegIdx = idx + i;\n let seg: LSegment | CSegment | MSegment | ZSegment;\n\n if (i === 0 || (a[oldSegIdx] && a[oldSegIdx][0] === \"M\")) {\n seg = a[oldSegIdx];\n path.push([\"M\", ...seg.slice(-2)] as MSegment);\n continue;\n }\n if (oldSegIdx >= pathLen) {\n oldSegIdx -= pointCount;\n }\n path.push(a[oldSegIdx] as never);\n }\n return path;\n}\n\n/**\n * Returns all possible rotations of a path (line or curve) by shifting the start point.\n * Each rotation is a new PathArray starting at a different original segment.\n *\n * @param path PathArray (M + L/C + optional Z) — must be single subpath, normalized\n * @returns PathArray[] — array of all possible rotations\n */\nexport function getRotations<T extends MorphPathArray>(a: T): T[] {\n const pathLen = a.length;\n const result = [] as T[];\n\n for (let idx = 0; idx < pathLen; idx++) {\n result.push(getRotation(a, idx));\n }\n return result;\n}\n\nconst getSegmentDistanceSquared = (a: PathSegment, b: PathSegment): number => {\n let distance = 0;\n for (let i = 1; i < a.length; i += 1) {\n const delta = Number(a[i]) - Number(b[i]);\n distance += delta * delta;\n }\n return distance;\n};\n\nconst getStartDistanceSquared = (a: PathSegment, b: PathSegment): number => {\n const dx = Number(a[a.length - 2]) - Number(b[b.length - 2]);\n const dy = Number(a[a.length - 1]) - Number(b[b.length - 1]);\n return dx * dx + dy * dy;\n};\n\n/**\n * Finds the rotation of `pathA` that matches `pathB` best by minimizing the sum\n * of squared distances between all corresponding coordinates, including the\n * control points of the curves.\n *\n * The rotations are not materialized: the segment at index `j` of the rotation\n * that starts at `idx` is the segment at index `1 + ((idx + i - 1) mod\n * pointCount)` of the source path, so the sum can be computed from the source\n * path alone.\n *\n * A rotation whose running sum is already worse than the best rotation found so\n * far cannot become the best one — the terms of the sum are squared distances,\n * so the sum only grows — and the rotation is dropped right there.\n *\n * The rotations are checked in the order of their first term, the distance\n * between the start of the rotation and the start of the reference path: the\n * rotation that matches best is usually the one that starts closest, so it is\n * usually found early and the rest of the rotations are dropped right away.\n *\n * @param pathA the path to rotate\n * @param pathB the reference path\n * @returns the index of the best rotation\n */\nconst getBestRotationIndex = <T extends MorphPathArray>(pathA: T, pathB: T): number => {\n const pathLen = pathA.length;\n const pointCount = pathLen - 1;\n\n const firstTerms: number[] = [];\n const order: number[] = [];\n for (let idx = 0; idx < pathLen; idx++) {\n firstTerms.push(getStartDistanceSquared(pathA[idx], pathB[0]));\n order.push(idx);\n }\n order.sort((a, b) => {\n const first = firstTerms[a];\n const second = firstTerms[b];\n if (first < second) return -1;\n if (first > second) return 1;\n return a - b;\n });\n\n let bestIndex = 0;\n let minDistanceSq = Infinity;\n\n for (const idx of order) {\n let sumDistSq = firstTerms[idx];\n if (sumDistSq > minDistanceSq) continue;\n\n for (let i = 1; i < pathLen; i++) {\n const j = 1 + ((idx + i - 1) % pointCount);\n sumDistSq += getSegmentDistanceSquared(pathA[j], pathB[i]);\n if (sumDistSq > minDistanceSq) break;\n }\n\n if (sumDistSq < minDistanceSq || (sumDistSq === minDistanceSq && idx < bestIndex)) {\n minDistanceSq = sumDistSq;\n bestIndex = idx;\n }\n }\n\n return bestIndex;\n};\n\n/**\n * Finds the best rotation of pathA to match pathB by minimizing the sum of squared distances\n * between corresponding coordinates, including curve control points.\n *\n * Works with both polygon (L) and curve (C) arrays.\n *\n * @param pathA PathArray to rotate (will be modified in rotation options)\n * @param pathB PathArray reference (fixed)\n * @returns PathArray — best rotation of pathA\n */\nexport function getRotatedPath<T extends MorphPathArray>(\n pathA: T,\n pathB: T,\n computedRotations?: T[],\n): T {\n const segCountA = pathA.length;\n const segCountB = pathB.length;\n\n if (segCountA !== segCountB) {\n throw new TypeError(error + \": paths must have the same number of segments after equalization\");\n }\n\n if (computedRotations) {\n let bestIndex = 0;\n let minDistanceSq = Infinity;\n\n for (let ri = 0; ri < computedRotations.length; ri++) {\n const rotation = computedRotations[ri];\n let sumDistSq = 0;\n\n for (let i = 0; i < rotation.length; i++) {\n sumDistSq += getSegmentDistanceSquared(rotation[i], pathB[i]);\n }\n\n if (sumDistSq < minDistanceSq) {\n minDistanceSq = sumDistSq;\n bestIndex = ri;\n }\n }\n\n return computedRotations[bestIndex];\n }\n\n return getRotation(pathA, getBestRotationIndex(pathA, pathB));\n}\n","import type {\n CSegment,\n CubicCoordinates,\n CurveArray,\n LSegment,\n MorphPathArray,\n MSegment,\n NormalArray,\n PathArray,\n PathSegment,\n Point,\n PolylineArray,\n} from \"../types.ts\";\nimport type { PathLengthTable } from \"../util/pathLengthTable.ts\";\nimport type { SegmentMeasure } from \"../util/measureSegments.ts\";\nimport { buildPathLengthTable } from \"../util/pathLengthTable.ts\";\nimport { getSegmentFrame } from \"../util/segmentFrame.ts\";\nimport { normalizePath } from \"../process/normalizePath.ts\";\nimport { splitSubPaths } from \"../process/splitSubPaths.ts\";\nimport { pathToCurve } from \"../convert/pathToCurve.ts\";\nimport { getTAtBezierLength } from \"../math/bezier.ts\";\nimport { splitCubicSegment } from \"./splitCubicSegment.ts\";\n\n/**\n * The share of a span used by the control points of a fallback curve.\n */\nconst CONTROL_SHARE = 3;\n\n/**\n * The distance below which two lengths are the same.\n */\nconst LENGTH_EPSILON = 1e-9;\n\n/**\n * The frame of a path at a given length: the point, the direction the path\n * comes from and the direction it goes to.\n *\n * The two directions are the same on a smooth spot of the path and they\n * differ on a corner, where the path changes its direction abruptly.\n */\ntype ResampleFrame = {\n /** the point at the given length */\n point: Point;\n /** the direction of the path at the point, from the point backwards */\n incoming: Point;\n /** the direction of the path at the point, from the point forwards */\n outgoing: Point;\n};\n\n/**\n * Distributes a number of intervals among a number of spans.\n *\n * The intervals are shared in proportion to the length of the spans, so the\n * spacing of the intervals stays the same over the whole path. The spans\n * that lose a fraction of an interval share it out, the one with the\n * biggest fraction gets it.\n *\n * @param lengths - the length of every span\n * @param extra - the number of intervals to distribute\n * @returns the number of extra intervals of every span\n */\nconst distributeIntervals = (lengths: number[], extra: number): number[] => {\n const shares = lengths.map(() => 0);\n if (extra <= 0) return shares;\n\n const total = lengths.reduce((sum, length) => sum + length, 0);\n // the spans cover the whole path, so their length is the length of the path\n /* istanbul ignore if */\n if (total <= 0) return shares;\n\n const remainders: { index: number; remainder: number }[] = [];\n let used = 0;\n for (let i = 0; i < lengths.length; i += 1) {\n const exact = (lengths[i] / total) * extra;\n const whole = Math.floor(exact);\n shares[i] = whole;\n used += whole;\n remainders.push({ index: i, remainder: exact - whole });\n }\n\n remainders.sort((a, b) => b.remainder - a.remainder || a.index - b.index);\n let left = extra - used;\n for (let i = 0; left > 0 && remainders.length; i = (i + 1) % remainders.length) {\n shares[remainders[i].index] += 1;\n left -= 1;\n }\n return shares;\n};\n\n/**\n * Builds the lengths of the knots of a resampled path.\n *\n * The source segment boundaries are knots too, so every result span belongs\n * to one source segment. The intervals between the boundaries are shared in\n * proportion to their length, so the spacing of the knots stays the same over\n * the whole path.\n *\n * When the source segments do not fit into the requested intervals, the knots\n * are spread evenly and the shape of the path is approximated by its chords.\n *\n * @param totalLength - the length of the path\n * @param intervals - the number of intervals of the result\n * @param boundaries - the length of every source segment boundary\n * @returns the length of every knot of the result, in path order\n */\nconst buildKnots = (totalLength: number, intervals: number, boundaries: number[]): number[] => {\n const breakpoints = [0];\n for (const boundary of boundaries) {\n if (boundary > breakpoints[breakpoints.length - 1] + LENGTH_EPSILON) {\n breakpoints.push(boundary);\n }\n }\n breakpoints.push(totalLength);\n\n const spanCount = breakpoints.length - 1;\n const knots: number[] = [];\n\n // the source segments do not fit: the knots are spread evenly\n if (spanCount > intervals) {\n for (let i = 0; i <= intervals; i += 1) {\n knots.push((totalLength * i) / intervals);\n }\n return knots;\n }\n\n const lengths = breakpoints.slice(1).map((value, index) => value - breakpoints[index]);\n const shares = distributeIntervals(lengths, intervals - spanCount);\n\n for (let i = 0; i < spanCount; i += 1) {\n const from = breakpoints[i];\n const to = breakpoints[i + 1];\n const count = shares[i] + 1;\n for (let j = 0; j < count; j += 1) {\n knots.push(from + ((to - from) * j) / count);\n }\n }\n knots.push(totalLength);\n return knots;\n};\n\n/**\n * Finds the index of the segment a distance falls into.\n *\n * The segment is the last one whose accumulated length is below the\n * distance, the same segment the linear walk over the path would have\n * stopped at. A distance at the end of a segment belongs to the segment\n * before it, so the frame at that distance is the frame at the end of the\n * segment.\n *\n * @param measures - the measured segments of the path\n * @param distance - the distance along the path\n * @returns the index of the segment\n */\nconst findSegmentIndex = (measures: SegmentMeasure[], distance: number): number => {\n let low = 0;\n let high = measures.length - 1;\n while (low < high) {\n const mid = (low + high + 1) >> 1;\n if (measures[mid].lengthAtSegment < distance) {\n low = mid;\n } else {\n high = mid - 1;\n }\n }\n return low;\n};\n\n/**\n * Returns the direction of the path after a segment.\n *\n * The segments without a direction are skipped, so the direction of the\n * path is the direction of the first segment that has one.\n *\n * @param measures - the measured segments of the path\n * @param index - the index of the segment\n * @returns the direction of the path, or `null` when the path has none\n */\nconst findNextDirection = (measures: SegmentMeasure[], index: number): Point | null => {\n for (let i = index + 1; i < measures.length; i += 1) {\n const measure = measures[i];\n if (measure.length <= 0) continue;\n const tangent = getSegmentFrame(\n measure.geometry,\n measure.startX,\n measure.startY,\n measure.endX,\n measure.endY,\n 0,\n measure.length,\n ).tangent;\n if (tangent.x || tangent.y) return tangent;\n }\n return null;\n};\n\n/**\n * The share of the length of a path the end of the path can be over.\n *\n * The length of a path is the sum of the lengths of its segments, so the end\n * of the path can be a fraction over the end of its last segment. The point\n * at the end of the path is the end point of the path, not a point a\n * fraction before it.\n */\nconst END_EPSILON = 1e-9;\n\n/**\n * Returns the frame of a path at a given length.\n *\n * @param table - the length table of the path\n * @param distance - the distance along the path\n * @returns the frame of the path at the given length\n */\nconst getFrameAt = (table: PathLengthTable, distance: number): ResampleFrame => {\n const { measures, totalLength } = table;\n const index = findSegmentIndex(measures, distance);\n const measure = measures[index];\n const rawOffset = distance - measure.lengthAtSegment;\n const atEnd = totalLength - distance <= totalLength * END_EPSILON;\n const offset = atEnd ? measure.length : Math.min(Math.max(rawOffset, 0), measure.length);\n\n const frame = getSegmentFrame(\n measure.geometry,\n measure.startX,\n measure.startY,\n measure.endX,\n measure.endY,\n offset,\n measure.length,\n );\n\n // at the end of a segment the path continues with the next one, which can\n // have another direction: that is a corner\n let outgoing = frame.tangent;\n if (offset >= measure.length) {\n const next = findNextDirection(measures, index);\n if (next) outgoing = next;\n }\n\n return { point: frame.point, incoming: frame.tangent, outgoing };\n};\n\n/**\n * Returns the control lengths of a fallback curve.\n *\n * @param fromLength - the length of the start of the span\n * @param toLength - the length of the end of the span\n * @param from - the frame at the start of the span\n * @param to - the frame at the end of the span\n * @returns the length of the control point at each end of the span\n */\nconst getFallbackCurveControls = (\n fromLength: number,\n toLength: number,\n from: ResampleFrame,\n to: ResampleFrame,\n): { start: number; end: number } => {\n const span = Math.max(0, toLength - fromLength);\n const fallback = span / CONTROL_SHARE;\n const hasFromDirection = from.outgoing.x !== 0 || from.outgoing.y !== 0;\n const hasToDirection = to.incoming.x !== 0 || to.incoming.y !== 0;\n return {\n start: hasFromDirection ? fallback : 0,\n end: hasToDirection ? fallback : 0,\n };\n};\n\n/**\n * Returns the internal boundaries of the measured source segments.\n *\n * @param measures - the measured segments of the path\n * @param totalLength - the length of the path\n * @returns the length of every internal segment boundary\n */\nconst getSegmentBoundaries = (measures: SegmentMeasure[], totalLength: number): number[] => {\n const boundaries: number[] = [];\n for (const measure of measures) {\n if (measure.geometry[0] === \"M\" || measure.length <= 0) continue;\n const end = measure.lengthAtSegment + measure.length;\n if (end > LENGTH_EPSILON && end < totalLength - LENGTH_EPSILON) {\n boundaries.push(end);\n }\n }\n return boundaries;\n};\n\n/**\n * Finds the source curve that holds a distance.\n *\n * @param measures - the measured curve segments of the path\n * @param distance - the distance along the path\n * @returns the index of the curve segment\n */\nconst findCurveSegmentIndex = (measures: SegmentMeasure[], distance: number): number => {\n let low = 0;\n let high = measures.length - 1;\n let result = 0;\n while (low <= high) {\n const mid = (low + high) >> 1;\n if (measures[mid].lengthAtSegment <= distance) {\n result = mid;\n low = mid + 1;\n } else {\n high = mid - 1;\n }\n }\n return result;\n};\n\n/**\n * Extracts the exact cubic curve of a source span.\n *\n * @param measures - the measured curve segments of the path\n * @param fromLength - the length of the start of the span\n * @param toLength - the length of the end of the span\n * @returns the exact cubic segment, or `null` when the span crosses a source boundary\n */\nconst getExactCurveSegment = (\n measures: SegmentMeasure[],\n fromLength: number,\n toLength: number,\n): CSegment | null => {\n const index = findCurveSegmentIndex(measures, fromLength);\n const measure = measures[index];\n const segmentStart = measure.lengthAtSegment;\n const segmentEnd = segmentStart + measure.length;\n if (toLength > segmentEnd + LENGTH_EPSILON) return null;\n\n const geometry = measure.geometry as CSegment;\n const coordinates = [\n measure.startX,\n measure.startY,\n geometry[1],\n geometry[2],\n geometry[3],\n geometry[4],\n measure.endX,\n measure.endY,\n ] as CubicCoordinates;\n\n const fromOffset = fromLength - segmentStart;\n const toOffset = toLength - segmentStart;\n const t0 =\n fromOffset <= LENGTH_EPSILON\n ? 0\n : getTAtBezierLength(coordinates, Math.min(fromOffset, measure.length));\n const t1 =\n toOffset >= measure.length - LENGTH_EPSILON\n ? 1\n : getTAtBezierLength(coordinates, Math.max(0, toOffset));\n\n let span: CubicCoordinates;\n if (t0 <= 0) {\n const [first] = splitCubicSegment(...coordinates, t1);\n span = first;\n } else {\n const [, tail] = splitCubicSegment(...coordinates, t0);\n const ratio = Math.max(0, Math.min(1, (t1 - t0) / (1 - t0)));\n const [first] = splitCubicSegment(...tail, ratio);\n span = first;\n }\n\n return [\"C\", span[2], span[3], span[4], span[5], span[6], span[7]];\n};\n\n/**\n * Resamples a measured path to a given number of points, spread evenly by\n * length.\n *\n * The path is measured along its length and the points of the result are\n * spread evenly over it, so the distance between two points of the result\n * is the same over the whole path. The source segment boundaries are points\n * of the result too, so the shape of the path keeps its vertices.\n *\n * The result is a polyline, or a path of cubic Bezier segments when the\n * curve mode is used. Every cubic of the result is the exact piece of the\n * source curve between two knots.\n *\n * @param table - the length table of the path\n * @param count - the number of points of the result\n * @param mode - the type of the segments of the result\n * @returns the resampled path\n */\nexport const resampleFromTable = (\n table: PathLengthTable,\n count: number,\n mode: \"line\" | \"curve\",\n): MorphPathArray => {\n const { measures, totalLength } = table;\n if (!measures.length) return [] as unknown as MorphPathArray;\n\n const points = Math.max(1, Math.floor(count));\n const intervals = points - 1;\n\n // a path without a length is a point\n if (totalLength <= 0) {\n return [[\"M\", measures[0].endX, measures[0].endY]] as unknown as MorphPathArray;\n }\n\n // a single point is the start of the path\n if (intervals <= 0) {\n return [[\"M\", table.startX, table.startY]] as unknown as MorphPathArray;\n }\n\n const boundaries = getSegmentBoundaries(measures, totalLength);\n const knots = buildKnots(totalLength, intervals, boundaries);\n const frames = knots.map((knot) => getFrameAt(table, knot));\n const curveMeasures =\n mode === \"curve\"\n ? measures.filter((measure) => measure.geometry[0] === \"C\" && measure.length > LENGTH_EPSILON)\n : [];\n\n const start = frames[0].point;\n const result: (MSegment | LSegment | CSegment)[] = [[\"M\", start.x, start.y] as MSegment];\n\n for (let i = 1; i < knots.length; i += 1) {\n const from = frames[i - 1];\n const to = frames[i];\n if (mode === \"curve\") {\n const exact = getExactCurveSegment(curveMeasures, knots[i - 1], knots[i]);\n if (exact) {\n result.push(exact);\n continue;\n }\n\n const controls = getFallbackCurveControls(knots[i - 1], knots[i], from, to);\n const c1x = from.point.x + from.outgoing.x * controls.start;\n const c1y = from.point.y + from.outgoing.y * controls.start;\n const c2x = to.point.x - to.incoming.x * controls.end;\n const c2y = to.point.y - to.incoming.y * controls.end;\n result.push([\"C\", c1x, c1y, c2x, c2y, to.point.x, to.point.y] as CSegment);\n } else {\n result.push([\"L\", to.point.x, to.point.y] as LSegment);\n }\n }\n\n return mode === \"curve\"\n ? (result as unknown as CurveArray)\n : (result as unknown as PolylineArray);\n};\n\n/**\n * Resamples a normalized sub-path to a given number of points, spread evenly\n * by length.\n *\n * @param path - the normalized sub-path to resample\n * @param count - the number of points of the result\n * @param mode - the type of the segments of the result\n * @returns the resampled path\n */\nexport const resampleNormalizedPath = (\n path: NormalArray,\n count: number,\n mode: \"line\" | \"curve\",\n): MorphPathArray => {\n const source = mode === \"curve\" ? pathToCurve(path as PathArray) : path;\n return resampleFromTable(buildPathLengthTable(source as NormalArray), count, mode);\n};\n\n/**\n * Resamples a path to a given number of points, spread evenly by length.\n *\n * The path is measured along its length and the points of the result are\n * spread evenly over it, so the distance between two points of the result\n * is the same over the whole path. The source segment boundaries are points\n * of the result too, so the shape of the path keeps its vertices.\n *\n * Every sub-path of the path is resampled on its own, so the sub-paths of\n * the result are the sub-paths of the source: a path with several sub-paths\n * keeps its shape, the points of a sub-path are not shared with the others.\n *\n * The result is a polyline, or a path of cubic Bezier segments when the\n * curve mode is used. Every cubic of the result is the exact piece of the\n * source curve between two knots.\n *\n * @param pathInput - the target path string or PathArray\n * @param count - the number of points of every sub-path of the result\n * @param mode - the type of the segments of the result\n * @returns the resampled path\n *\n * @example\n * ```ts\n * resamplePath(\"M0 0L100 0L100 100\", 3)\n * // => [['M', 0, 0], ['L', 100, 0], ['L', 100, 100]]\n * ```\n */\nexport const resamplePath = (\n pathInput: string | PathArray,\n count: number,\n mode: \"line\" | \"curve\" = \"line\",\n): PathArray => {\n const path = normalizePath(pathInput);\n const result: PathSegment[] = [];\n // every sub-path is resampled on its own, so the sub-paths of the result\n // are the sub-paths of the source\n for (const subPath of splitSubPaths(path)) {\n result.push(...(resampleNormalizedPath(subPath, count, mode) as PathSegment[]));\n }\n // the result of a multi-subpath source holds several moveto commands, so\n // its public type is a path array and not a single morph path\n return result as unknown as PathArray;\n};\n","// src/morph/equalizeSegments.ts\nimport type {\n CurveArray,\n EqualizationOptions,\n MorphPathArray,\n PathArray,\n Point,\n PolylineArray,\n} from \"../types.ts\";\nimport { pathToCurve } from \"../convert/pathToCurve.ts\";\nimport { pathToPolyline } from \"./pathToPolyline.ts\";\nimport { reversePath } from \"../process/reversePath.ts\";\nimport { normalizePath } from \"../process/normalizePath.ts\";\nimport { splitLinePathToCount } from \"./splitLinePathToCount.ts\";\nimport { splitCurvePathToCount } from \"./splitCurvePathToCount.ts\";\nimport { samplePolygon } from \"./samplePolygon.ts\";\nimport { polygonArea } from \"../math/polygonTools.ts\";\nimport { getRotatedPath } from \"./getRotatedPath.ts\";\nimport { fixPath } from \"./fixPath.ts\";\nimport { isPolygonArray } from \"../util/isPolygonArray.ts\";\nimport { isPolylineArray } from \"../util/isPolylineArray.ts\";\nimport { getTotalLength } from \"../util/getTotalLength.ts\";\nimport { isClosedPath } from \"../util/isClosedPath.ts\";\nimport { roundPath } from \"../process/roundPath.ts\";\nimport { resampleFromTable } from \"./resamplePath.ts\";\nimport { buildPathLengthTable } from \"../util/pathLengthTable.ts\";\nimport type { PathLengthTable } from \"../util/pathLengthTable.ts\";\n\nconst equalizeSegmentsDefaults: EqualizationOptions = {\n mode: \"auto\", // \"line\" | \"curve\" | \"auto\"\n strategy: \"segment\", // \"segment\" | \"arcLength\"\n align: true,\n sampleSize: 10, // for line option\n roundValues: 4, // 4 decimals\n reverse: true,\n target: undefined,\n};\n\n/**\n * Returns the start and the end point of a path.\n *\n * A closed path ends at the start of its sub-path, so the end point of a\n * path that ends with a close command is the start of the sub-path it\n * belongs to.\n *\n * @param path - the path to read\n * @returns the start and the end point of the path\n */\nexport const getPathEnds = (path: PathArray): { start: Point; end: Point } => {\n const first = path[0];\n const start = { x: first[1] as number, y: first[2] as number };\n let subStart = start;\n let end = start;\n for (const segment of path) {\n const command = segment[0];\n if (command === \"M\") {\n subStart = { x: segment[1] as number, y: segment[2] as number };\n end = subStart;\n } else if (command === \"Z\") {\n end = subStart;\n } else {\n end = {\n x: segment[segment.length - 2] as number,\n y: segment[segment.length - 1] as number,\n };\n }\n }\n return { start, end };\n};\n\n/**\n * Returns the distance between two points.\n *\n * @param a - the first point\n * @param b - the second point\n * @returns the distance between the points\n */\nexport const getDistance = (a: Point, b: Point): number => Math.hypot(a.x - b.x, a.y - b.y);\n\n/**\n * Returns the number of points the arc length strategy uses.\n *\n * The number of points of the result is the number of the segments of the\n * bigger path, so every source segment can have its own span in the result.\n *\n * @param table1 - the length table of the first path\n * @param table2 - the length table of the second path\n * @param target - the requested number of points\n * @returns the number of points of the result\n */\nconst getArcLengthCount = (\n table1: PathLengthTable,\n table2: PathLengthTable,\n target?: number,\n): number => {\n if (typeof target === \"number\") return Math.max(2, Math.floor(target));\n\n return Math.max(table1.measures.length, table2.measures.length, 2);\n};\n\n/**\n * Equalizes two paths for morphing (single subpath only).\n *\n * @see https://minus-ze.ro/posts/morphing-arbitrary-paths-in-svg/\n * @param path1 - First path string or PathArray\n * @param path2 - Second path string or PathArray\n * @param initialCfg - Equalization options\n * @returns Tuple of two equalized MorphPathArrays\n *\n * @example\n * ```ts\n * const [eq1, eq2] = equalizeSegments('M0 0L100 0L50 100Z', 'M0 0L100 0L100 100L0 100Z')\n * // eq1.length === eq2.length\n * ```\n */\nexport const equalizeSegments = (\n path1: PathArray | string,\n path2: PathArray | string,\n initialCfg: EqualizationOptions = {},\n): [MorphPathArray, MorphPathArray] => {\n const {\n align,\n close,\n mode,\n reverse,\n roundValues,\n strategy,\n target: initialTarget,\n } = { ...equalizeSegmentsDefaults, ...initialCfg };\n const normalized1 = normalizePath(path1);\n const normalized2 = normalizePath(path2);\n const shouldClose = close ?? (isClosedPath(normalized1) || isClosedPath(normalized2));\n let p1 = fixPath(normalized1) as MorphPathArray;\n let p2 = fixPath(normalized2) as MorphPathArray;\n\n const bothPoly =\n (isPolygonArray(p1) || isPolylineArray(p1)) && (isPolygonArray(p2) || isPolylineArray(p2));\n\n // Sample and check draw direction\n const area1 = polygonArea(samplePolygon(p1));\n const area2 = polygonArea(samplePolygon(p2));\n\n if (reverse !== false && Math.sign(area1) !== Math.sign(area2)) {\n if (reverse === \"auto\") {\n // the path that is reversed is the one that leaves the two paths\n // closest to each other\n const ends1 = getPathEnds(p1);\n const ends2 = getPathEnds(p2);\n if (getDistance(ends1.end, ends2.start) < getDistance(ends1.start, ends2.end)) {\n p1 = reversePath(p1);\n } else {\n p2 = reversePath(p2);\n }\n } else {\n p2 = reversePath(p2);\n }\n }\n\n if (strategy === \"arcLength\") {\n const resampleMode =\n mode === \"curve\" ? \"curve\" : mode === \"line\" ? \"line\" : bothPoly ? \"line\" : \"curve\";\n // curve mode works on cubic source segments, so every result span can be\n // an exact piece of one source curve\n const source1 = resampleMode === \"curve\" ? pathToCurve(p1) : p1;\n const source2 = resampleMode === \"curve\" ? pathToCurve(p2) : p2;\n const table1 = buildPathLengthTable(source1);\n const table2 = buildPathLengthTable(source2);\n const count = getArcLengthCount(table1, table2, initialTarget);\n let equalP1 = resampleFromTable(table1, count, resampleMode);\n let equalP2 = resampleFromTable(table2, count, resampleMode);\n\n // Point alignment\n if (align !== false) equalP2 = getRotatedPath(equalP2, equalP1);\n\n if (typeof roundValues === \"number\" && roundValues !== 4) {\n equalP1 = roundPath(equalP1, roundValues);\n equalP2 = roundPath(equalP2, roundValues);\n }\n\n if (shouldClose) {\n equalP1.push([\"Z\"] as never);\n equalP2.push([\"Z\"] as never);\n }\n\n return [equalP1, equalP2];\n }\n\n let bothPolyline = bothPoly;\n if (bothPolyline && mode !== \"curve\") {\n p1 = pathToPolyline(p1 as PolylineArray);\n p2 = pathToPolyline(p2 as PolylineArray);\n } else {\n bothPolyline = false;\n p1 = pathToCurve(p1);\n p2 = pathToCurve(p2);\n }\n\n // Get segment counts\n const segCount1 = p1.length;\n const segCount2 = p2.length;\n const minTarget = Math.max(segCount1, segCount2);\n let target = minTarget;\n\n if (typeof initialTarget !== \"number\") {\n const len1 = getTotalLength(p1);\n const len2 = getTotalLength(p2);\n const avgLen = (len1 + len2) / 2;\n const maxSegCount = Math.max(segCount1, segCount2);\n const avgSegLen = avgLen / maxSegCount;\n const idealSegCount = Math.max(minTarget, Math.round(avgLen / Math.max(avgSegLen, 1)));\n target = Math.min(idealSegCount, Math.max(segCount1, segCount2) * 3);\n } else {\n if (initialTarget >= minTarget) target = initialTarget;\n else {\n console.warn(\n 'equalizeSegments \"target\" option: ' + initialTarget + \", expected >= \" + minTarget,\n );\n }\n }\n\n let equalP1: MorphPathArray = p1;\n let equalP2: MorphPathArray = p2;\n\n if (bothPolyline) {\n equalP1 = splitLinePathToCount(p1 as PolylineArray, target) as MorphPathArray;\n equalP2 = splitLinePathToCount(p2 as PolylineArray, target) as MorphPathArray;\n } else {\n equalP1 = splitCurvePathToCount(p1 as CurveArray, target) as MorphPathArray;\n equalP2 = splitCurvePathToCount(p2 as CurveArray, target) as MorphPathArray;\n }\n\n // Point alignment\n if (align !== false) equalP2 = getRotatedPath(equalP2, equalP1);\n\n if (typeof roundValues === \"number\" && roundValues !== 4) {\n equalP1 = roundPath(equalP1, roundValues);\n equalP2 = roundPath(equalP2, roundValues);\n }\n\n if (shouldClose) {\n equalP1.push([\"Z\"] as never);\n equalP2.push([\"Z\"] as never);\n }\n\n return [equalP1, equalP2];\n};\n","import type { BBoxMaxima, PointTuple } from \"../types.ts\";\n\n/**\n * Checks if a point is inside a bounding box.\n *\n * @param bbox - The bounding box as [minX, minY, maxX, maxY]\n * @param point - The point as [x, y]\n * @returns True if the point is inside or on the edge of the bounding box\n */\nexport const isPointInsideBBox = (bbox: BBoxMaxima, [x, y]: PointTuple): boolean => {\n const [minX, minY, maxX, maxY] = bbox;\n return x >= minX && x <= maxX && y >= minY && y <= maxY;\n};\n","import type { BBoxMaxima } from \"../types.ts\";\n\nimport { isPointInsideBBox } from \"./isPointInsideBBox.ts\";\n\n/**\n * Checks if two bounding boxes intersect.\n *\n * @param a - First bounding box as [minX, minY, maxX, maxY]\n * @param b - Second bounding box as [minX, minY, maxX, maxY]\n * @returns True if the bounding boxes overlap\n */\nexport const boundingBoxIntersect = (a: BBoxMaxima, b: BBoxMaxima): boolean => {\n const [ax1, ay1, ax2, ay2] = a;\n const [bx1, by1, bx2, by2] = b;\n // return ax1 <= bx2 && ax2 >= bx1 && ay1 <= by2 && ay2 >= by1;\n return (\n isPointInsideBBox(b, [ax1, ay1]) ||\n isPointInsideBBox(b, [ax2, ay1]) ||\n isPointInsideBBox(b, [ax1, ay2]) ||\n isPointInsideBBox(b, [ax2, ay2]) ||\n isPointInsideBBox(a, [bx1, by1]) ||\n isPointInsideBBox(a, [bx2, by1]) ||\n isPointInsideBBox(a, [bx1, by2]) ||\n isPointInsideBBox(a, [bx2, by2]) ||\n // edge overlap without corner inside\n (((ax1 < bx2 && ax1 > bx1) || (bx1 < ax2 && bx1 > ax1)) &&\n ((ay1 < by2 && ay1 > by1) || (by1 < ay2 && by1 > ay1)))\n );\n};\n","import type { NormalArray } from \"../types.ts\";\n\n/**\n * Create a degenerate `PathArray` at a given coordinate\n * to serve as a pair for another `PathArray`.\n * @param param0 An [x, y] tuple for the coordinate\n * @returns A new degenerate `PathArray`\n */\nexport const createPlaceholder = ([atx, aty]: [number, number]): NormalArray => {\n // Tiny square at point\n const r = 0.001;\n return [\n [\"M\", atx, aty],\n [\"L\", atx + r, aty],\n [\"L\", atx + r, aty + r],\n [\"L\", atx, aty + r],\n [\"L\", atx, aty],\n [\"Z\"],\n ];\n};\n","import type { NormalArray, PathFeature, PointTuple } from \"../types.ts\";\nimport { isPointInsideBBox } from \"../intersect/isPointInsideBBox.ts\";\nimport { boundingBoxIntersect } from \"../intersect/boundingBoxIntersect.ts\";\nimport { createPlaceholder } from \"./createPlaceholder.ts\";\n\ninterface CandidateScore {\n index: number;\n hasOverlap: boolean;\n boxIntersect: boolean;\n sizeDifference: number;\n centeredDistance: number;\n}\n\nfunction getBestMatch(target: PathFeature, candidates: PathFeature[]): PathFeature | null {\n const targetBBox = target.bbox;\n\n // Single pass: collect metrics for every candidate\n const potentialCandidates: CandidateScore[] = [];\n\n for (let i = 0; i < candidates.length; i++) {\n const { bbox, size } = candidates[i];\n\n const dx = targetBBox.cx - bbox.cx;\n const dy = targetBBox.cy - bbox.cy;\n const centeredDistance = Math.sqrt(dx * dx + dy * dy);\n\n const sizeDifference = Math.abs(target.size - size) / Math.max(target.size, size, 1e-6);\n\n const hasOverlap =\n isPointInsideBBox(\n [targetBBox.x, targetBBox.y, targetBBox.x2, targetBBox.y2],\n [bbox.cx, bbox.cy],\n ) || isPointInsideBBox([bbox.x, bbox.y, bbox.x2, bbox.y2], [targetBBox.cx, targetBBox.cy]);\n\n const boxIntersect = boundingBoxIntersect(\n [targetBBox.x, targetBBox.y, targetBBox.x2, targetBBox.y2],\n [bbox.x, bbox.y, bbox.x2, bbox.y2],\n );\n\n potentialCandidates.push({\n index: i,\n hasOverlap,\n boxIntersect,\n sizeDifference,\n centeredDistance,\n });\n }\n\n // Filter phase: strict overlap — pick smallest distance\n const overlaping = potentialCandidates.filter((c) => c.hasOverlap && c.boxIntersect);\n if (overlaping.length > 0) {\n let best = overlaping[0];\n for (let i = 1; i < overlaping.length; i++) {\n if (overlaping[i].centeredDistance < best.centeredDistance) {\n best = overlaping[i];\n }\n }\n return candidates.splice(best.index, 1)[0];\n }\n\n return null;\n}\n\n/**\n * The result of matching two sets of path features.\n */\nexport type PathFeatureMatch = {\n /** the matched feature pairs */\n pairs: [PathFeature, PathFeature][];\n /** the source features without a match */\n unmatchedFrom: PathFeature[];\n /** the target features without a match */\n unmatchedTo: PathFeature[];\n};\n\n/**\n * Matches path features by proximity and size similarity.\n *\n * @param fromPaths - Source path features to match from\n * @param toPaths - Target path features to match to\n * @returns the matched pairs and the unmatched features\n */\nexport function matchPathFeatures(\n fromPaths: PathFeature[],\n toPaths: PathFeature[],\n): PathFeatureMatch {\n // the caller's arrays must not be sorted or emptied\n const from = [...fromPaths].sort((a, b) => b.size - a.size);\n const to = [...toPaths].sort((a, b) => b.size - a.size);\n const pairs: [PathFeature, PathFeature][] = [];\n const unmatchedFrom: PathFeature[] = [];\n\n while (from.length > 0) {\n const fromPath = from.shift()!;\n const bestTo = getBestMatch(fromPath, to);\n if (bestTo) pairs.push([fromPath, bestTo]);\n else unmatchedFrom.push(fromPath);\n }\n\n return { pairs, unmatchedFrom, unmatchedTo: to };\n}\n\n/**\n * Matches paths from two sets by proximity and size similarity.\n * Unmatched paths receive placeholder paths at their centroid.\n *\n * @param fromPaths - Source path features to match from\n * @param toPaths - Target path features to match to\n * @returns Array of paired NormalArrays [from, to]\n */\nexport function matchPaths(\n fromPaths: PathFeature[],\n toPaths: PathFeature[],\n): [NormalArray, NormalArray][] {\n const { pairs, unmatchedFrom, unmatchedTo } = matchPathFeatures(fromPaths, toPaths);\n const result: [NormalArray, NormalArray][] = pairs.map(([from, to]) => [from.path, to.path]);\n\n for (const from of unmatchedFrom) {\n const fromCentroid: PointTuple = [from.bbox.cx, from.bbox.cy];\n result.push([from.path, createPlaceholder(fromCentroid)]);\n }\n\n for (const to of unmatchedTo) {\n const toCentroid: PointTuple = [to.bbox.cx, to.bbox.cy];\n result.push([createPlaceholder(toCentroid), to.path]);\n }\n\n return result;\n}\n","import type { NormalArray, PathFeature } from \"../types.ts\";\nimport { getPathBBox } from \"../util/getPathBBox.ts\";\nimport { polygonArea } from \"../math/polygonTools.ts\";\nimport { samplePolygon } from \"./samplePolygon.ts\";\nimport { isPolygonArray } from \"../util/isPolygonArray.ts\";\nimport { isPolylineArray } from \"../util/isPolylineArray.ts\";\nimport { isPointInsideBBox } from \"../intersect/isPointInsideBBox.ts\";\n\n/**\n * Classifies paths into outer (containing) and inner (hole) paths.\n *\n * A path is an inner path when it is contained by another path of the\n * same set. The winding of a contour is not used for the classification:\n * the shoelace sign only tells the direction of the contour, and in the\n * SVG coordinate system (y pointing down) the usual outer contour has a\n * *negative* signed area.\n *\n * @param paths - Array of normalized path arrays to classify\n * @returns Object with `outers` (containing shapes) and `inners` (holes)\n */\nexport const classifyPaths = (\n paths: NormalArray[],\n): {\n outers: PathFeature[];\n inners: PathFeature[];\n} => {\n const features: PathFeature[] = paths.map((path) => {\n const signedArea = polygonArea(samplePolygon(path));\n const bbox = getPathBBox(path);\n return {\n isPoly: isPolygonArray(path) || isPolylineArray(path),\n size: bbox.width * bbox.height,\n path,\n signedArea,\n area: Math.abs(signedArea),\n bbox,\n };\n });\n\n const outers: PathFeature[] = [];\n const inners: PathFeature[] = [];\n\n for (const feature of features) {\n // a hole is a path contained by a bigger path of the same set\n const isInner = features.some(\n (other) =>\n other !== feature &&\n other.area > feature.area &&\n isPointInsideBBox(\n [other.bbox.x, other.bbox.y, other.bbox.x2, other.bbox.y2],\n [feature.bbox.cx, feature.bbox.cy],\n ),\n );\n\n if (isInner) {\n inners.push(feature);\n } else {\n outers.push(feature);\n }\n }\n\n return { outers, inners };\n};\n","import type {\n NormalArray,\n PathArray,\n PathFeature,\n PathsEqualizationOptions,\n PointTuple,\n} from \"../types.ts\";\nimport { isMultiPath } from \"../util/isMultiPath.ts\";\nimport { splitPath } from \"../process/splitPath.ts\";\nimport { equalizeSegments, getDistance, getPathEnds } from \"./equalizeSegments.ts\";\nimport { matchPathFeatures } from \"./matchPaths.ts\";\nimport { createPlaceholder } from \"./createPlaceholder.ts\";\nimport { normalizePath } from \"../process/normalizePath.ts\";\nimport { reversePath } from \"../process/reversePath.ts\";\nimport { polygonArea } from \"../math/polygonTools.ts\";\nimport { samplePolygon } from \"./samplePolygon.ts\";\nimport { classifyPaths } from \"./classifyPaths.ts\";\nimport { getPathArea } from \"../util/getPathArea.ts\";\n\nconst equalizePathsDefaults: PathsEqualizationOptions = {\n mode: \"auto\", // \"line\" | \"curve\" | \"auto\"\n strategy: \"segment\", // \"segment\" | \"arcLength\"\n align: true,\n roundValues: 4, // 4 decimals\n sampleSize: 10,\n};\n\nconst getPrimaryOuter = (outers: PathFeature[]): PathFeature | undefined => {\n let primary: PathFeature | undefined;\n for (const outer of outers) {\n if (!primary || outer.size > primary.size) primary = outer;\n }\n return primary;\n};\n\nconst getOuterDirection = (outers: PathFeature[]): number => {\n const primary = getPrimaryOuter(outers);\n if (!primary) return 0;\n return Math.sign(getPathArea(primary.path));\n};\n\n/**\n * Equalizes two paths for morphing (single/multi subpath).\n *\n * Multi-subpath paths are reversed as whole paths, so an outer contour keeps\n * its relationship with its holes. Outer contours only match outer contours\n * and holes only match holes: an unmatched contour collapses at its own\n * centroid instead of taking the opposite fill role.\n *\n * @see https://minus-ze.ro/posts/morphing-arbitrary-paths-in-svg/\n * @param pathInput1 - First path string or PathArray\n * @param pathInput2 - Second path string or PathArray\n * @param initialCfg - Configuration options for equalization\n * @returns Tuple of two equalized PathArrays\n *\n * @example\n * ```ts\n * const [eq1, eq2] = equalizePaths('M0 0L100 0L50 100Z', 'M0 0L100 0L100 100L0 100Z')\n * // eq1.length === eq2.length — ready for morphing\n * ```\n */\nexport const equalizePaths = (\n pathInput1: string | PathArray,\n pathInput2: string | PathArray,\n initialCfg: PathsEqualizationOptions = {},\n): [PathArray, PathArray] => {\n const cfg = { ...equalizePathsDefaults, ...initialCfg };\n const p1 = normalizePath(pathInput1);\n const p2 = normalizePath(pathInput2);\n\n const multi1 = isMultiPath(p1);\n const multi2 = isMultiPath(p2);\n\n if (!multi1 && !multi2) {\n // Single subpath — use fast path\n return equalizeSegments(p1, p2, cfg);\n }\n\n let path1 = p1;\n let path2 = p2;\n let multiPath1 = splitPath(path1);\n let multiPath2 = splitPath(path2);\n let classified1 = classifyPaths(multiPath1);\n let classified2 = classifyPaths(multiPath2);\n\n if (cfg.reverse === undefined) {\n const globalArea1 = polygonArea(samplePolygon(p1));\n const globalArea2 = polygonArea(samplePolygon(p2));\n\n if (Math.sign(globalArea1) < 0) path1 = reversePath(path1);\n if (Math.sign(globalArea2) < 0) path2 = reversePath(path2);\n } else if (cfg.reverse === true || cfg.reverse === \"auto\") {\n const direction1 = getOuterDirection(classified1.outers);\n const direction2 = getOuterDirection(classified2.outers);\n\n if (direction1 && direction2 && direction1 !== direction2) {\n let reverseFirst = false;\n\n if (cfg.reverse === \"auto\") {\n const outer1 = getPrimaryOuter(classified1.outers)!;\n const outer2 = getPrimaryOuter(classified2.outers)!;\n const ends1 = getPathEnds(outer1.path);\n const ends2 = getPathEnds(outer2.path);\n reverseFirst = getDistance(ends1.end, ends2.start) < getDistance(ends1.start, ends2.end);\n }\n\n if (reverseFirst) path1 = reversePath(path1);\n else path2 = reversePath(path2);\n }\n }\n\n if (path1 !== p1 || path2 !== p2) {\n multiPath1 = splitPath(path1);\n multiPath2 = splitPath(path2);\n classified1 = classifyPaths(multiPath1);\n classified2 = classifyPaths(multiPath2);\n }\n\n const outerMatches = matchPathFeatures(classified1.outers, classified2.outers);\n const innerMatches = matchPathFeatures(classified1.inners, classified2.inners);\n const featurePairs = [...outerMatches.pairs, ...innerMatches.pairs];\n const contourPairs: [NormalArray, NormalArray][] = featurePairs.map(([from, to]) => [\n from.path,\n to.path,\n ]);\n\n for (const feature of [...outerMatches.unmatchedFrom, ...innerMatches.unmatchedFrom]) {\n const centroid: PointTuple = [feature.bbox.cx, feature.bbox.cy];\n contourPairs.push([feature.path, createPlaceholder(centroid)]);\n }\n\n for (const feature of [...outerMatches.unmatchedTo, ...innerMatches.unmatchedTo]) {\n const centroid: PointTuple = [feature.bbox.cx, feature.bbox.cy];\n contourPairs.push([createPlaceholder(centroid), feature.path]);\n }\n\n const equalizedPairs: [PathArray, PathArray][] = [];\n\n for (const [from, to] of contourPairs) {\n const [eqFrom, eqTo] = equalizeSegments(from, to, {\n ...cfg,\n reverse: false,\n });\n equalizedPairs.push([eqFrom, eqTo]);\n }\n\n // Reassemble into final morphable paths\n const finalFrom = equalizedPairs.map((p) => p[0]).flat() as PathArray;\n const finalTo = equalizedPairs.map((p) => p[1]).flat() as PathArray;\n\n return [finalFrom, finalTo];\n};\n","// src/morph/equalize.ts\nimport type { EqualizeOptions, PathArray } from \"../types.ts\";\nimport { isMultiPath } from \"../util/isMultiPath.ts\";\nimport { normalizePath } from \"../process/normalizePath.ts\";\nimport { equalizePaths } from \"./equalizePaths.ts\";\nimport { equalizeSegments } from \"./equalizeSegments.ts\";\nimport { error } from \"../util/error.ts\";\n\nconst equalizeDefaults: EqualizeOptions = {\n points: \"auto\",\n strategy: \"segment\",\n align: true,\n reverse: \"auto\",\n mode: \"auto\",\n roundValues: 4,\n};\n\n/**\n * Equalizes two paths for morphing.\n *\n * The two paths are brought to the same shape, so they can be morphed into\n * each other: they hold the same number of segments of the same type, their\n * winding is the same and their points are aligned.\n *\n * A path with a single sub-path is equalized on its own, a path with more\n * sub-paths is split into sub-paths, the sub-paths are matched by their\n * shape and every pair is equalized on its own. Multi-subpath paths are\n * reversed as whole paths, so an outer contour keeps its relationship with\n * its holes. Outer contours only match outer contours and holes only match\n * holes: an unmatched contour collapses at its own centroid instead of\n * taking the opposite fill role.\n *\n * The `strategy` option decides how the points of the paths are placed:\n * - `segment` splits the segments of the paths, so the points of the result\n * are the points of the paths;\n * - `arcLength` distributes the points of the result along the length of\n * the paths. The source segment boundaries and corners are points of the\n * result too when the requested count allows it, so the shape of the paths\n * keeps its vertices.\n *\n * The `points` option is the number of points of the result. The automatic\n * mode uses the number of points of the bigger path.\n *\n * The `reverse` option decides what happens when the two paths draw in\n * opposite directions: `true` reverses the second path, `false` leaves the\n * paths as they are and `auto` reverses the path that leaves the two paths\n * closest to each other.\n *\n * @see https://minus-ze.ro/posts/morphing-arbitrary-paths-in-svg/\n *\n * @param pathInput1 - First path string or PathArray\n * @param pathInput2 - Second path string or PathArray\n * @param initialCfg - Configuration options for equalization\n * @returns Tuple of two equalized PathArrays\n *\n * @example\n * ```ts\n * const [eq1, eq2] = equalize('M0 0L100 0L50 100Z', 'M0 0L100 0L100 100L0 100Z')\n * // eq1.length === eq2.length — ready for morphing\n * ```\n */\nexport const equalize = (\n pathInput1: string | PathArray,\n pathInput2: string | PathArray,\n initialCfg: EqualizeOptions = {},\n): [PathArray, PathArray] => {\n const { align, close, mode, points, reverse, roundValues, strategy } = {\n ...equalizeDefaults,\n ...initialCfg,\n };\n\n if (typeof points === \"number\" && (!Number.isFinite(points) || points < 2)) {\n throw new TypeError(`${error}: points must be a number greater than 1`);\n }\n\n const p1 = normalizePath(pathInput1);\n const p2 = normalizePath(pathInput2);\n\n // a path with more than one sub-path is split and matched first\n if (isMultiPath(p1) || isMultiPath(p2)) {\n return equalizePaths(p1, p2, {\n align,\n close,\n mode,\n reverse,\n roundValues,\n strategy,\n target: typeof points === \"number\" ? points : undefined,\n });\n }\n\n return equalizeSegments(p1, p2, {\n align,\n close,\n mode,\n reverse,\n roundValues,\n strategy,\n target: typeof points === \"number\" ? points : undefined,\n });\n};\n","import type {\n CubicCoordinates,\n IntersectionOptions,\n IntersectionPoint,\n PointAtLength,\n} from \"../types.ts\";\nimport { getCubicBBox, getCubicLength, getPointAtCubicLength } from \"../math/cubicTools.ts\";\nimport distanceEpsilon from \"../util/distanceEpsilon.ts\";\nimport { roundTo } from \"../math/roundTo.ts\";\nimport { boundingBoxIntersect } from \"./boundingBoxIntersect.ts\";\n\nconst intersect = (\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n x3: number,\n y3: number,\n x4: number,\n y4: number,\n) => {\n if (\n Math.max(x1, x2) < Math.min(x3, x4) ||\n Math.min(x1, x2) > Math.max(x3, x4) ||\n Math.max(y1, y2) < Math.min(y3, y4) ||\n Math.min(y1, y2) > Math.max(y3, y4)\n ) {\n return;\n }\n const nx = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4),\n ny = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4),\n denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);\n\n if (!denominator) {\n return;\n }\n const px = nx / denominator,\n py = ny / denominator,\n px2 = roundTo(px, 2),\n py2 = roundTo(py, 2);\n if (\n px2 < roundTo(Math.min(x1, x2), 2) ||\n px2 > roundTo(Math.max(x1, x2), 2) ||\n px2 < roundTo(Math.min(x3, x4), 2) ||\n px2 > roundTo(Math.max(x3, x4), 2) ||\n py2 < roundTo(Math.min(y1, y2), 2) ||\n py2 > roundTo(Math.max(y1, y2), 2) ||\n py2 < roundTo(Math.min(y3, y4), 2) ||\n py2 > roundTo(Math.max(y3, y4), 2)\n ) {\n return;\n }\n return { x: px, y: py };\n};\n\n/**\n * Returns the intersection point(s) of two cubic Bezier curves.\n *\n * @param bez1 the coordinates of the first cubic Bezier segment\n * @param bez2 the coordinates of the second cubic Bezier segment\n * @param config optional intersection options\n * @returns the intersection points, or `undefined` if the curves do not intersect\n */\nexport const interHelper = (\n bez1: CubicCoordinates,\n bez2: CubicCoordinates,\n config?: IntersectionOptions,\n) => {\n const bbox1 = getCubicBBox(...bez1);\n const bbox2 = getCubicBBox(...bez2);\n const { justCount, epsilon } = Object.assign(\n {\n justCount: true,\n epsilon: distanceEpsilon,\n },\n config,\n );\n\n if (!boundingBoxIntersect(bbox1, bbox2)) {\n return justCount ? 0 : ([] as IntersectionPoint[]);\n }\n const l1 = getCubicLength(...bez1),\n l2 = getCubicLength(...bez2),\n n1 = Math.max((l1 / 5) >> 0, 1),\n n2 = Math.max((l2 / 5) >> 0, 1),\n points1: PointAtLength[] = [],\n points2: PointAtLength[] = [],\n xy: Record<string, string> = {};\n // deno-lint-ignore prefer-const\n let res = justCount ? 0 : ([] as IntersectionPoint[]);\n for (let i = 0; i < n1 + 1; i++) {\n const p = getPointAtCubicLength(...bez1, (i / n1) * l1);\n points1.push({ x: p.x, y: p.y, t: i / n1 });\n }\n for (let i = 0; i < n2 + 1; i++) {\n const p = getPointAtCubicLength(...bez2, (i / n2) * l2);\n points2.push({ x: p.x, y: p.y, t: i / n2 });\n }\n for (let i = 0; i < n1; i++) {\n for (let j = 0; j < n2; j++) {\n const maxLimit = 1 + epsilon,\n di = points1[i],\n di1 = points1[i + 1],\n dj = points2[j],\n dj1 = points2[j + 1],\n ci = Math.abs(di1.x - di.x) < 0.001 ? \"y\" : \"x\",\n cj = Math.abs(dj1.x - dj.x) < 0.001 ? \"y\" : \"x\",\n is = intersect(di.x, di.y, di1.x, di1.y, dj.x, dj.y, dj1.x, dj1.y);\n if (is) {\n // istanbul ignore next 2\n if (xy[is.x.toFixed(4)] == is.y.toFixed(4)) {\n continue;\n }\n xy[is.x.toFixed(4)] = is.y.toFixed(4);\n const t1 = di.t + Math.abs((is[ci] - di[ci]) / (di1[ci] - di[ci])) * (di1.t - di.t),\n t2 = dj.t + Math.abs((is[cj] - dj[cj]) / (dj1[cj] - dj[cj])) * (dj1.t - dj.t);\n\n // istanbul ignore else\n if (t1 >= 0 && t1 <= maxLimit && t2 >= 0 && t2 <= maxLimit) {\n if (justCount) {\n (res as number)++;\n } else {\n (res as IntersectionPoint[]).push({\n x: is.x,\n y: is.y,\n t1: Math.min(t1, 1),\n t2: Math.min(t2, 1),\n });\n }\n }\n }\n }\n }\n return res;\n};\n","import type { CubicCoordinates, IntersectionPoint, PathArray } from \"../types.ts\";\nimport { pathToCurve } from \"../convert/pathToCurve.ts\";\nimport { interHelper } from \"./interHelper.ts\";\n\n/**\n * Finds intersection points between two paths.\n *\n * @param pathInput1 - First path string or PathArray\n * @param pathInput2 - Second path string or PathArray\n * @param justCount - If true, returns the count of intersections; if false, returns the intersection points\n * @returns The number of intersections (when justCount is true) or an array of IntersectionPoint objects\n *\n * @example\n * ```ts\n * pathsIntersection('M0 50C0 0,100 0,100 50', 'M50 0C100 0,100 100,50 100', true)\n * // => 1\n * pathsIntersection('M0 50C0 0,100 0,100 50', 'M50 0C100 0,100 100,50 100', false)\n * // => [{ x: 80.4136, y: 19.5864, t1: 0.7262, t2: 0.2738 }]\n * ```\n */\nexport const pathsIntersection = <T extends string | PathArray>(\n pathInput1: T,\n pathInput2: T,\n justCount = /* istanbul ignore next */ true,\n): number | IntersectionPoint[] => {\n const path1 = pathToCurve(pathInput1);\n const path2 = pathToCurve(pathInput2);\n let x1 = 0,\n y1 = 0,\n x2 = 0,\n y2 = 0,\n x1m = 0,\n y1m = 0,\n x2m = 0,\n y2m = 0,\n bez1: CubicCoordinates = [x1, y1, x1, y1, x1m, y1m, x1m, y1m],\n bez2: CubicCoordinates = [x2, y2, x2, y2, x2m, y2m, x2m, y2m],\n countResult = 0;\n const pointsResult: IntersectionPoint[] = [];\n const pathLen1 = path1.length;\n const pathLen2 = path2.length;\n\n for (let i = 0; i < pathLen1; i++) {\n const seg1 = path1[i];\n if (seg1[0] == \"M\") {\n x1 = seg1[1];\n y1 = seg1[2];\n x1m = x1;\n y1m = y1;\n } else {\n /* istanbul ignore else */\n if (seg1[0] == \"C\") {\n bez1 = [x1, y1, seg1[1], seg1[2], seg1[3], seg1[4], seg1[5], seg1[6]];\n x1 = bez1[6];\n y1 = bez1[7];\n } else {\n bez1 = [x1, y1, x1, y1, x1m, y1m, x1m, y1m];\n x1 = x1m;\n y1 = y1m;\n }\n for (let j = 0; j < pathLen2; j++) {\n const seg2 = path2[j];\n // istanbul ignore else\n if (seg2[0] == \"M\") {\n x2 = seg2[1];\n y2 = seg2[2];\n x2m = x2;\n y2m = y2;\n } else if (seg2[0] == \"C\") {\n bez2 = [x2, y2, seg2[1], seg2[2], seg2[3], seg2[4], seg2[5], seg2[6]];\n x2 = bez2[6];\n y2 = bez2[7];\n // dead code, pathToCurve is almost always made of M/C\n // } else {\n // bez2 = [x2, y2, x2, y2, x2m, y2m, x2m, y2m];\n // x2 = x2m;\n // y2 = y2m;\n }\n const intr = interHelper(bez1, bez2, { justCount });\n if (justCount) {\n // (res as number) += intr;\n countResult += intr as number;\n } else {\n // Include additional segment properties, maybe not\n // const kk = (intr as IntersectionPoint[]).length;\n // for (let k = 0; k < kk; k++) {\n // intr[k].segment1 = i;\n // intr[k].segment2 = j;\n // intr[k].bez1 = bez1;\n // intr[k].bez2 = bez2;\n // }\n // (res as IntersectionPoint[]) = (res as IntersectionPoint[]).concat(intr);\n pointsResult.push(...(intr as IntersectionPoint[]));\n }\n }\n }\n }\n return justCount ? countResult : pointsResult;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AASA,MAAM,iBAAiB,IAAY,IAAY,IAAY,OAAuB;CAChF,MAAM,KAAK,KAAK;CAChB,MAAM,KAAK,KAAK;CAChB,OAAO,KAAK,KAAK,KAAK,KAAK,KAAK,EAAE;AACpC;;;;;;;;;;;AAYA,MAAM,wBACJ,IACA,IACA,IACA,IACA,aAC6B;CAC7B,IAAI,QAAQ;EAAE,GAAG;EAAI,GAAG;CAAG;CAG3B,IAAI,OAAO,aAAa,UAAU;EAChC,MAAM,SAAS,cAAc,IAAI,IAAI,IAAI,EAAE;EAC3C,IAAI,YAAY,GACd,QAAQ;GAAE,GAAG;GAAI,GAAG;EAAG;OAClB,IAAI,YAAY,QACrB,QAAQ;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;GACA,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,KAAK;IACjC,MAAM,OAAO,MAAM;IAEnB,IAAI,KAAK,MAAM,KAAK;KAClB,KAAK,KAAK;KACV,KAAK,KAAK;KACV,MAAM;KACN,MAAM;IACR,OAAO,IAAI,KAAK,MAAM,KAAK;KACzB,OAAO;MAAC;MAAI;MAAI,KAAK;MAAI,KAAK;MAAI,KAAK;MAAI,KAAK;MAAI,KAAK;MAAI,KAAK;KAAE;KACpE,KAAK,KAAK;KACV,KAAK,KAAK;IAMZ;IACA,MAAM,OAAO,YAAY,MAAM,MAAM,EAAE,UAAU,CAAC;IAClD,IAAI,WAEF,eAAe;SAWf,aAAa,KAAK,GAAI,IAA4B;GAEtD;EACF;CACF;CACA,OAAO,YAAY,cAAc;AACnC"}
|
|
1
|
+
{"version":3,"file":"util.js","names":["findSegmentIndex","toSegments","reverseSubPath","distanceEpsilon"],"sources":["../src/math/lineTools.ts","../src/math/bezier.ts","../src/math/arcTools.ts","../src/math/cubicTools.ts","../src/math/quadTools.ts","../src/math/distanceSquareRoot.ts","../src/math/polygonTools.ts","../src/math/midPoint.ts","../src/math/rotateVector.ts","../src/math/roundTo.ts","../src/parser/paramsCount.ts","../src/parser/finalizeSegment.ts","../src/util/error.ts","../src/parser/scanFlag.ts","../src/parser/isDigit.ts","../src/parser/invalidPathValue.ts","../src/parser/scanParam.ts","../src/parser/isSpace.ts","../src/parser/skipSpaces.ts","../src/parser/isPathCommand.ts","../src/parser/isDigitStart.ts","../src/parser/isArcCommand.ts","../src/parser/isMoveCommand.ts","../src/parser/scanSegment.ts","../src/parser/pathParser.ts","../src/parser/parsePathString.ts","../src/process/absolutizeSegment.ts","../src/process/iterate.ts","../src/convert/pathToAbsolute.ts","../src/process/relativizeSegment.ts","../src/convert/pathToRelative.ts","../src/process/lineToCubic.ts","../src/process/arcToCubic.ts","../src/process/quadToCubic.ts","../src/process/segmentToCubic.ts","../src/process/normalizeSegment.ts","../src/parser/paramsParser.ts","../src/convert/pathToCurve.ts","../src/options/options.ts","../src/convert/pathToString.ts","../src/util/getPathBBox.ts","../src/util/measureSegments.ts","../src/util/getTotalLength.ts","../src/util/distanceEpsilon.ts","../src/util/pathLengthTable.ts","../src/util/segmentFrame.ts","../src/util/getPropertiesAtLength.ts","../src/util/getPropertiesAtPoint.ts","../src/util/getClosestPoint.ts","../src/util/getPathArea.ts","../src/util/getDrawDirection.ts","../src/process/normalizePath.ts","../src/util/getPointAtLength.ts","../src/util/getSegmentAtLength.ts","../src/util/getSegmentOfPoint.ts","../src/util/isPathArray.ts","../src/util/isAbsoluteArray.ts","../src/util/isNormalizedArray.ts","../src/util/isCurveArray.ts","../src/util/isPointInStroke.ts","../src/process/flattenPath.ts","../src/math/distanceToSegment.ts","../src/math/pointInPolygon.ts","../src/util/isPointInPath.ts","../src/util/isPolygonArray.ts","../src/util/isPolylineArray.ts","../src/util/isRelativeArray.ts","../src/util/isValidPath.ts","../src/util/isMultiPath.ts","../src/util/isClosedPath.ts","../src/util/shapeParams.ts","../src/util/isElement.ts","../src/util/shapeToPathArray.ts","../src/util/shapeToPath.ts","../src/process/offsetNodes.ts","../src/process/offsetJoin.ts","../src/process/offsetPath.ts","../src/process/shortenSegment.ts","../src/process/roundSegment.ts","../src/process/segmentStringLength.ts","../src/process/optimizePath.ts","../src/process/joinPath.ts","../src/process/reversePath.ts","../src/process/splitPath.ts","../src/process/reverseSubPath.ts","../src/process/getSVGMatrix.ts","../src/process/projection2d.ts","../src/process/transformPath.ts","../src/process/reverseCurve.ts","../src/process/roundPath.ts","../src/process/splitSubPaths.ts","../src/process/samplePath.ts","../src/process/douglasPeucker.ts","../src/process/fitCubic.ts","../src/process/simplifyPath.ts","../src/morph/fixPath.ts","../src/morph/splitCubicSegment.ts","../src/morph/pathToPolyline.ts","../src/morph/splitLineToCount.ts","../src/morph/getPathSplits.ts","../src/morph/splitLinePathToCount.ts","../src/morph/splitCubicToCount.ts","../src/morph/splitCurvePathToCount.ts","../src/morph/samplePolygon.ts","../src/morph/getRotatedPath.ts","../src/morph/resamplePath.ts","../src/morph/equalizeSegments.ts","../src/intersect/isPointInsideBBox.ts","../src/intersect/boundingBoxIntersect.ts","../src/morph/createPlaceholder.ts","../src/morph/matchPaths.ts","../src/morph/classifyPaths.ts","../src/morph/equalizePaths.ts","../src/morph/equalize.ts","../src/intersect/interHelper.ts","../src/intersect/pathIntersection.ts"],"sourcesContent":["/**\n * Returns length for line segments (MoveTo, LineTo).\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns the line segment length\n */\nconst getLineLength = (x1: number, y1: number, x2: number, y2: number): number => {\n const dx = x1 - x2;\n const dy = y1 - y2;\n return Math.sqrt(dx * dx + dy * dy);\n};\n\n/**\n * Returns a point along the line segments (MoveTo, LineTo).\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @param distance the distance to point in [0-1] range\n * @returns the point at length\n */\nconst getPointAtLineLength = (\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n distance?: number,\n): { x: number; y: number } => {\n let point = { x: x1, y: y1 };\n\n /* istanbul ignore else */\n if (typeof distance === \"number\") {\n const length = getLineLength(x1, y1, x2, y2);\n if (distance <= 0) {\n point = { x: x1, y: y1 };\n } else if (distance >= length) {\n point = { x: x2, y: y2 };\n } else {\n const ratio = distance / length;\n point = { x: x1 + (x2 - x1) * ratio, y: y1 + (y2 - y1) * ratio };\n }\n }\n return point;\n};\n\n/**\n * Returns bounding box for line segments (MoveTo, LineTo).\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns the bounding box for line segments\n */\nconst getLineBBox = (\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n): [number, number, number, number] => {\n const { min, max } = Math;\n\n return [min(x1, x2), min(y1, y2), max(x1, x2), max(y1, y2)] as [number, number, number, number];\n};\n\n/** The tools for line segment computation. */\nconst lineTools = {\n getLineBBox,\n getLineLength,\n getPointAtLineLength,\n};\n\nexport { getLineBBox, getLineLength, getPointAtLineLength, lineTools };\n","import type {\n CubicCoordinates,\n CubicPoints,\n DeriveCallback,\n DerivedCubicPoints,\n DerivedPoint,\n DerivedQuadPoints,\n PointTuple,\n QuadCoordinates,\n QuadPoints,\n} from \"../types.ts\";\n\n/**\n * Tools from bezier.js by Mike 'Pomax' Kamermans\n * @see https://github.com/Pomax/bezierjs\n */\n\nconst Tvalues = [\n -0.06405689286260563, 0.06405689286260563, -0.1911188674736163, 0.1911188674736163,\n -0.3150426796961634, 0.3150426796961634, -0.4337935076260451, 0.4337935076260451,\n -0.5454214713888396, 0.5454214713888396, -0.6480936519369755, 0.6480936519369755,\n -0.7401241915785544, 0.7401241915785544, -0.820001985973903, 0.820001985973903,\n -0.8864155270044011, 0.8864155270044011, -0.9382745520027328, 0.9382745520027328,\n -0.9747285559713095, 0.9747285559713095, -0.9951872199970213, 0.9951872199970213,\n];\n\n/** The weights for the 32-point Gauss-Legendre quadrature. */\nconst Cvalues = [\n 0.12793819534675216, 0.12793819534675216, 0.1258374563468283, 0.1258374563468283,\n 0.12167047292780339, 0.12167047292780339, 0.1155056680537256, 0.1155056680537256,\n 0.10744427011596563, 0.10744427011596563, 0.09761865210411388, 0.09761865210411388,\n 0.08619016153195327, 0.08619016153195327, 0.0733464814110803, 0.0733464814110803,\n 0.05929858491543678, 0.05929858491543678, 0.04427743881741981, 0.04427743881741981,\n 0.028531388628933663, 0.028531388628933663, 0.0123412297999872, 0.0123412297999872,\n];\n\n/**\n * @param points\n * @returns\n */\nconst deriveBezier = (\n points: QuadPoints | CubicPoints,\n): (DerivedQuadPoints | DerivedCubicPoints)[] => {\n const dpoints = [] as (DerivedCubicPoints | DerivedQuadPoints)[];\n for (let p = points, d = p.length, c = d - 1; d > 1; d -= 1, c -= 1) {\n const list = [] as unknown as DerivedCubicPoints | DerivedQuadPoints;\n for (let j = 0; j < c; j += 1) {\n list.push({\n x: c * (p[j + 1].x - p[j].x),\n y: c * (p[j + 1].y - p[j].y),\n t: 0,\n });\n }\n dpoints.push(list);\n p = list;\n }\n return dpoints;\n};\n\n/**\n * @param points\n * @param t\n */\nconst computeBezier = (points: DerivedQuadPoints | DerivedCubicPoints, t: number): DerivedPoint => {\n // shortcuts\n /* istanbul ignore next */\n if (t === 0) {\n points[0].t = 0;\n return points[0];\n }\n\n const order = points.length - 1;\n\n /* istanbul ignore next */\n if (t === 1) {\n points[order].t = 1;\n return points[order];\n }\n\n const mt = 1 - t;\n let p = points as typeof points | [DerivedPoint, DerivedPoint, DerivedPoint, DerivedPoint];\n\n // constant?\n /* istanbul ignore next */\n if (order === 0) {\n points[0].t = t;\n return points[0];\n }\n\n // linear?\n /* istanbul ignore else */\n if (order === 1) {\n return {\n x: mt * p[0].x + t * p[1].x,\n y: mt * p[0].y + t * p[1].y,\n t,\n };\n }\n\n // quadratic/cubic curve?\n const mt2 = mt * mt;\n const t2 = t * t;\n let a = 0;\n let b = 0;\n let c = 0;\n let d = 0;\n /* istanbul ignore else */\n if (order === 2) {\n p = [p[0], p[1], p[2], { x: 0, y: 0 } as DerivedPoint];\n a = mt2;\n b = mt * t * 2;\n c = t2;\n } else if (order === 3) {\n a = mt2 * mt;\n b = mt2 * t * 3;\n c = mt * t2 * 3;\n d = t * t2;\n }\n return {\n x: a * p[0].x + b * p[1].x + c * p[2].x + d * p[3].x,\n y: a * p[0].y + b * p[1].y + c * p[2].y + d * p[3].y,\n t,\n };\n};\n\n/**\n * Calculates the speed (derivative magnitude) of a Bezier curve at parameter `t`.\n *\n * @param derivativeFn the curve derivative function\n * @param t the sampled point ratio in `[0-1]`\n * @returns the curve speed at parameter `t`\n */\nconst calculateBezier = (derivativeFn: DeriveCallback, t: number): number => {\n const d = derivativeFn(t);\n const l = d.x * d.x + d.y * d.y;\n\n return Math.sqrt(l);\n};\n\n/**\n * Returns the total arc length of a Bezier segment.\n *\n * @param derivativeFn the curve derivative function\n * @returns the total arc length\n */\nconst bezierLength = (derivativeFn: DeriveCallback): number => {\n return bezierLengthAtT(derivativeFn, 1);\n};\n\n/**\n * Returns the arc length of a Bezier segment from its start point\n * up to a given `t` ratio, by integrating the curve speed `|B'(t)|`\n * over the `[0, t]` interval with Gauss-Legendre quadrature.\n *\n * @param derivativeFn the curve derivative function\n * @param t the sampled point ratio in `[0-1]`\n * @returns the arc length up to parameter `t`\n */\nconst bezierLengthAtT = (derivativeFn: DeriveCallback, t: number): number => {\n const z = t / 2;\n const len = Tvalues.length;\n\n let sum = 0;\n\n for (let i = 0, tMid; i < len; i++) {\n tMid = z * Tvalues[i] + z;\n sum += Cvalues[i] * calculateBezier(derivativeFn, tMid);\n }\n return z * sum;\n};\n\n/**\n * Returns the speed of a Bezier segment at a given ratio, without allocating\n * a point for it.\n *\n * The quadrature of the length samples the speed of the curve at every one of\n * its points, and a point per sample is a lot of garbage for a long path. The\n * arithmetic is the one of `computeBezier`, so the length of a curve is the\n * same.\n *\n * @param points the control points of the derivative of the curve\n * @param t the sampled point ratio\n * @returns the speed of the curve at the ratio\n */\nconst bezierSpeed = (points: DerivedQuadPoints | DerivedCubicPoints, t: number): number => {\n const order = points.length - 1;\n const mt = 1 - t;\n\n // a linear derivative, the derivative of a quadratic\n if (order === 1) {\n const x = mt * points[0].x + t * points[1].x;\n const y = mt * points[0].y + t * points[1].y;\n return Math.sqrt(x * x + y * y);\n }\n\n // a quadratic derivative, the derivative of a cubic\n if (order === 2) {\n const mt2 = mt * mt;\n const t2 = t * t;\n const a = mt2;\n const b = mt * t * 2;\n const c = t2;\n const x = a * points[0].x + b * points[1].x + c * points[2].x;\n const y = a * points[0].y + b * points[1].y + c * points[2].y;\n return Math.sqrt(x * x + y * y);\n }\n\n // any other derivative is computed the general way\n const d = computeBezier(points, t);\n return Math.sqrt(d.x * d.x + d.y * d.y);\n};\n\n/**\n * Returns the arc length of a Bezier segment from its start point\n * up to a given `t` ratio, from the control points of its derivative.\n *\n * The integration of the speed `|B'(t)|` over the `[0, t]` interval is done\n * with the Gauss-Legendre quadrature, and the speed is computed without\n * allocating a point for it.\n *\n * @param points the control points of the derivative of the curve\n * @param t the sampled point ratio in `[0-1]`\n * @returns the arc length up to parameter `t`\n */\nconst bezierLengthAtPoints = (\n points: DerivedQuadPoints | DerivedCubicPoints,\n t: number,\n): number => {\n const z = t / 2;\n const len = Tvalues.length;\n\n let sum = 0;\n\n for (let i = 0, tMid; i < len; i++) {\n tMid = z * Tvalues[i] + z;\n sum += Cvalues[i] * bezierSpeed(points, tMid);\n }\n return z * sum;\n};\n\n/**\n * Builds the Bezier points array from a curve coordinates array.\n * @param curve cubic / quad bezier segment\n */\nconst getBezierPoints = (curve: CubicCoordinates | QuadCoordinates): CubicPoints | QuadPoints => {\n const points = [] as unknown as CubicPoints | QuadPoints;\n for (let idx = 0, len = curve.length, step = 2; idx < len; idx += step) {\n points.push({\n x: curve[idx],\n y: curve[idx + 1],\n });\n }\n return points;\n};\n\n/**\n * Returns the arc length of a Bezier segment from its start point\n * up to a given `t` ratio, for the segment given by its coordinates.\n *\n * @param curve cubic / quad bezier segment\n * @param t the sampled point ratio in `[0-1]`\n * @returns the arc length up to parameter `t`\n */\nconst getBezierLengthAtT = (curve: CubicCoordinates | QuadCoordinates, t: number): number => {\n const dpoints = deriveBezier(getBezierPoints(curve));\n return bezierLengthAtPoints(dpoints[0], t);\n};\n\n/**\n * Returns the `t` parameter of a Bezier segment at which the cumulative\n * arc length equals the given `distance`, found by interval bisection.\n *\n * @param curve cubic / quad bezier segment\n * @param distance the distance along the segment in `[0, length]`\n * @returns the `t` parameter in `[0-1]`\n */\nconst getTAtBezierLength = (\n curve: CubicCoordinates | QuadCoordinates,\n distance: number,\n): number => {\n const dpoints = deriveBezier(getBezierPoints(curve));\n const points = dpoints[0];\n let lo = 0;\n let hi = 1;\n for (let i = 0; i < 25; i += 1) {\n const mid = (lo + hi) / 2;\n if (bezierLengthAtPoints(points, mid) < distance) {\n lo = mid;\n } else {\n hi = mid;\n }\n }\n return (lo + hi) / 2;\n};\n\n/**\n * Returns the length of CubicBezier / Quad segment.\n * @param curve cubic / quad bezier segment\n */\nconst getBezierLength = (curve: CubicCoordinates | QuadCoordinates): number => {\n const points = getBezierPoints(curve);\n const dpoints = deriveBezier(points);\n return bezierLengthAtPoints(dpoints[0], 1);\n};\n\n// Precision for consider cubic polynom as quadratic one\n/** The precision threshold to consider a cubic polynomial as quadratic. */\nconst CBEZIER_MINMAX_EPSILON = 0.00000001;\n\n/**\n * Returns the most extreme points in a Quad Bezier segment.\n * @param A an array which consist of X/Y values\n */\n// https://github.com/kpym/SVGPathy/blob/acd1a50c626b36d81969f6e98e8602e128ba4302/lib/box.js#L89\nconst minmaxQ = ([v1, cp, v2]: [number, number, number]): PointTuple => {\n const min = Math.min(v1, v2);\n const max = Math.max(v1, v2);\n\n /* istanbul ignore next */\n if (cp >= v1 ? v2 >= cp : v2 <= cp) {\n // if no extremum in ]0,1[\n return [min, max] as PointTuple;\n }\n\n // check if the extremum E is min or max\n const E = (v1 * v2 - cp * cp) / (v1 - 2 * cp + v2);\n return (E < min ? [E, max] : [min, E]) as PointTuple;\n};\n\n/**\n * Returns the most extreme points in a Cubic Bezier segment.\n * @param A an array which consist of X/Y values\n * @see https://github.com/kpym/SVGPathy/blob/acd1a50c626b36d81969f6e98e8602e128ba4302/lib/box.js#L127\n */\nconst minmaxC = ([v1, cp1, cp2, v2]: [number, number, number, number]): PointTuple => {\n const K = v1 - 3 * cp1 + 3 * cp2 - v2;\n\n // if the polynomial is (almost) quadratic and not cubic\n /* istanbul ignore next */\n if (Math.abs(K) < CBEZIER_MINMAX_EPSILON) {\n if (v1 === v2 && v1 === cp1) {\n // no curve, point targeting same location\n return [v1, v2] as PointTuple;\n }\n\n return minmaxQ([v1, -0.5 * v1 + 1.5 * cp1, v1 - 3 * cp1 + 3 * cp2]);\n }\n\n // the reduced discriminant of the derivative\n const T = -v1 * cp2 + v1 * v2 - cp1 * cp2 - cp1 * v2 + cp1 * cp1 + cp2 * cp2;\n\n // if the polynomial is monotone in [0,1]\n if (T <= 0) {\n return [Math.min(v1, v2), Math.max(v1, v2)] as PointTuple;\n }\n const S = Math.sqrt(T);\n\n // potential extrema\n let min = Math.min(v1, v2);\n let max = Math.max(v1, v2);\n\n const L = v1 - 2 * cp1 + cp2;\n // check local extrema\n for (let R = (L + S) / K, i = 1; i <= 2; R = (L - S) / K, i++) {\n // istanbul ignore next\n if (R > 0 && R < 1) {\n // if the extrema is for R in [0,1]\n const Q =\n v1 * (1 - R) * (1 - R) * (1 - R) +\n cp1 * 3 * (1 - R) * (1 - R) * R +\n cp2 * 3 * (1 - R) * R * R +\n v2 * R * R * R;\n if (Q < min) {\n min = Q;\n }\n if (Q > max) {\n max = Q;\n }\n }\n }\n\n return [min, max] as PointTuple;\n};\n/** The tools for Bezier curve computation. */\nconst bezierTools = {\n bezierLength,\n bezierLengthAtT,\n calculateBezier,\n CBEZIER_MINMAX_EPSILON,\n computeBezier,\n Cvalues,\n deriveBezier,\n getBezierLength,\n getBezierLengthAtT,\n getBezierPoints,\n getTAtBezierLength,\n minmaxC,\n minmaxQ,\n Tvalues,\n};\n\nexport {\n bezierLength,\n bezierLengthAtT,\n bezierTools,\n calculateBezier,\n CBEZIER_MINMAX_EPSILON,\n computeBezier,\n Cvalues,\n deriveBezier,\n getBezierLength,\n getBezierLengthAtT,\n getBezierPoints,\n getTAtBezierLength,\n minmaxC,\n minmaxQ,\n Tvalues,\n};\n","import { getPointAtLineLength } from \"./lineTools.ts\";\nimport { Cvalues, Tvalues } from \"./bezier.ts\";\nimport type { Point, PointTuple } from \"../types.ts\";\n\n/**\n * Returns the signed arc length of an ellipse segment from angle `0` up to\n * the given `theta` angle, by integrating the curve speed\n * `|sqrt(rx^2 * sin^2(phi) + ry^2 * cos^2(phi))|` over the `[0, theta]`\n * interval with Gauss-Legendre quadrature.\n *\n * @param rx radius along X axis\n * @param ry radius along Y axis\n * @param theta the angle in radians\n * @returns the signed arc length\n */\nconst arcLengthAtAngle = (rx: number, ry: number, theta: number): number => {\n const sign = theta < 0 ? -1 : 1;\n const absTheta = Math.abs(theta);\n const step = Math.PI / 2;\n\n let total = 0;\n let remaining = absTheta;\n let offset = 0;\n\n while (remaining > 0) {\n const span = Math.min(step, remaining);\n const z = span / 2;\n\n let sum = 0;\n for (let i = 0, len = Tvalues.length; i < len; i += 1) {\n const phi = offset + z * Tvalues[i] + z;\n sum += Cvalues[i] * Math.sqrt((rx * Math.sin(phi)) ** 2 + (ry * Math.cos(phi)) ** 2);\n }\n total += z * sum;\n offset += span;\n remaining -= span;\n }\n return sign * total;\n};\n\n/**\n * Returns the signed arc length of an ellipse segment between two angles.\n * @param rx radius along X axis\n * @param ry radius along Y axis\n * @param from the start angle in radians\n * @param to the end angle in radians\n * @returns the signed arc length\n */\nconst arcLengthBetween = (rx: number, ry: number, from: number, to: number): number => {\n return arcLengthAtAngle(rx, ry, to) - arcLengthAtAngle(rx, ry, from);\n};\n\n/**\n * Returns the Arc segment length.\n * @param rx radius along X axis\n * @param ry radius along Y axis\n * @param theta the angle in radians\n * @returns the arc length\n */\nconst arcLength = (rx: number, ry: number, theta: number): number => {\n return Math.abs(arcLengthAtAngle(rx, ry, theta));\n};\n\n/**\n * Find point on ellipse at given angle around ellipse (theta);\n * @param cx the center X\n * @param cy the center Y\n * @param rx the radius X\n * @param ry the radius Y\n * @param alpha the arc rotation angle in radians\n * @param theta the arc sweep angle in radians\n * @returns a point around ellipse at given angle\n */\nconst arcPoint = (\n cx: number,\n cy: number,\n rx: number,\n ry: number,\n alpha: number,\n theta: number,\n): PointTuple => {\n const { sin, cos } = Math;\n // theta is angle in radians around arc\n // alpha is angle of rotation of ellipse in radians\n const cosA = cos(alpha);\n const sinA = sin(alpha);\n const x = rx * cos(theta);\n const y = ry * sin(theta);\n\n return [cx + cosA * x - sinA * y, cy + sinA * x + cosA * y] as PointTuple;\n};\n\n/**\n * Returns the angle between two points.\n * @param v0 starting point\n * @param v1 ending point\n * @returns the angle in radian\n */\nconst angleBetween = (v0: Point, v1: Point): number => {\n const { x: v0x, y: v0y } = v0;\n const { x: v1x, y: v1y } = v1;\n const p = v0x * v1x + v0y * v1y;\n const n = Math.sqrt((v0x ** 2 + v0y ** 2) * (v1x ** 2 + v1y ** 2));\n const sign = v0x * v1y - v0y * v1x < 0 ? -1 : 1;\n // the cosine of an angle is in the [-1-1] range, the rounding of the\n // division can push it out of it and `acos` of a value under -1 is NaN\n return sign * Math.acos(Math.min(1, Math.max(-1, p / n)));\n};\n\n/**\n * Returns the following properties for an Arc segment: center, start angle,\n * end angle, and radiuses on X and Y axis.\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param RX the radius on X axis\n * @param RY the radius on Y axis\n * @param angle the ellipse rotation in degrees\n * @param LAF the large arc flag\n * @param SF the sweep flag\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns properties specific to Arc segments\n */\nconst getArcProps = (\n x1: number,\n y1: number,\n RX: number,\n RY: number,\n angle: number,\n LAF: number,\n SF: number,\n x: number,\n y: number,\n): {\n rx: number;\n ry: number;\n startAngle: number;\n endAngle: number;\n center: { x: number; y: number };\n} => {\n const { abs, sin, cos, sqrt, PI } = Math;\n let rx = abs(RX);\n let ry = abs(RY);\n const xRot = ((angle % 360) + 360) % 360;\n const xRotRad = xRot * (PI / 180);\n\n // istanbul ignore next\n if (x1 === x && y1 === y) {\n return {\n rx,\n ry,\n startAngle: 0,\n endAngle: 0,\n center: { x, y },\n };\n }\n\n if (rx === 0 || ry === 0) {\n return {\n rx,\n ry,\n startAngle: 0,\n endAngle: 0,\n center: { x: (x + x1) / 2, y: (y + y1) / 2 },\n };\n }\n\n const dx = (x1 - x) / 2;\n const dy = (y1 - y) / 2;\n\n const transformedPoint = {\n x: cos(xRotRad) * dx + sin(xRotRad) * dy,\n y: -sin(xRotRad) * dx + cos(xRotRad) * dy,\n };\n\n const radiiCheck = transformedPoint.x ** 2 / rx ** 2 + transformedPoint.y ** 2 / ry ** 2;\n\n if (radiiCheck > 1) {\n rx *= sqrt(radiiCheck);\n ry *= sqrt(radiiCheck);\n }\n\n const cSquareNumerator =\n rx ** 2 * ry ** 2 - rx ** 2 * transformedPoint.y ** 2 - ry ** 2 * transformedPoint.x ** 2;\n const cSquareRootDenom = rx ** 2 * transformedPoint.y ** 2 + ry ** 2 * transformedPoint.x ** 2;\n\n let cRadicand = cSquareNumerator / cSquareRootDenom;\n /* istanbul ignore next */\n cRadicand = cRadicand < 0 ? 0 : cRadicand;\n const cCoef = (LAF !== SF ? 1 : -1) * sqrt(cRadicand);\n const transformedCenter = {\n x: cCoef * ((rx * transformedPoint.y) / ry),\n y: cCoef * (-(ry * transformedPoint.x) / rx),\n };\n\n const center = {\n x: cos(xRotRad) * transformedCenter.x - sin(xRotRad) * transformedCenter.y + (x1 + x) / 2,\n y: sin(xRotRad) * transformedCenter.x + cos(xRotRad) * transformedCenter.y + (y1 + y) / 2,\n };\n\n const startVector = {\n x: (transformedPoint.x - transformedCenter.x) / rx,\n y: (transformedPoint.y - transformedCenter.y) / ry,\n };\n\n const startAngle = angleBetween({ x: 1, y: 0 }, startVector);\n\n const endVector = {\n x: (-transformedPoint.x - transformedCenter.x) / rx,\n y: (-transformedPoint.y - transformedCenter.y) / ry,\n };\n\n let sweepAngle = angleBetween(startVector, endVector);\n if (!SF && sweepAngle > 0) {\n sweepAngle -= 2 * PI;\n } else if (SF && sweepAngle < 0) {\n sweepAngle += 2 * PI;\n }\n sweepAngle %= 2 * PI;\n\n const endAngle = startAngle + sweepAngle;\n\n // point.ellipticalArcStartAngle = startAngle;\n // point.ellipticalArcEndAngle = startAngle + sweepAngle;\n // point.ellipticalArcAngle = alpha;\n\n // point.ellipticalArcCenter = center;\n // point.resultantRx = rx;\n // point.resultantRy = ry;\n\n return {\n center,\n startAngle,\n endAngle,\n rx,\n ry,\n };\n};\n\n/**\n * Returns the length of an Arc segment.\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param c1x the first control point X\n * @param c1y the first control point Y\n * @param c2x the second control point X\n * @param c2y the second control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns the length of the Arc segment\n */\nconst getArcLength = (\n x1: number,\n y1: number,\n RX: number,\n RY: number,\n angle: number,\n LAF: number,\n SF: number,\n x: number,\n y: number,\n): number => {\n const { abs } = Math;\n // a zero radius is treated as a straight line to the end point\n if (RX === 0 || RY === 0) {\n return abs(Math.sqrt((x - x1) ** 2 + (y - y1) ** 2));\n }\n const { rx, ry, startAngle, endAngle } = getArcProps(x1, y1, RX, RY, angle, LAF, SF, x, y);\n return Math.abs(arcLengthBetween(rx, ry, startAngle, endAngle));\n};\n\n/**\n * Returns a point along an Arc segment at a given distance.\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param RX the radius on X axis\n * @param RY the radius on Y axis\n * @param angle the ellipse rotation in degrees\n * @param LAF the large arc flag\n * @param SF the sweep flag\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @param distance the distance along the arc\n * @returns a point along the Arc segment\n */\nconst getPointAtArcLength = (\n x1: number,\n y1: number,\n RX: number,\n RY: number,\n angle: number,\n LAF: number,\n SF: number,\n x: number,\n y: number,\n distance?: number,\n): { x: number; y: number } => {\n let point = { x: x1, y: y1 };\n const { center, rx, ry, startAngle, endAngle } = getArcProps(\n x1,\n y1,\n RX,\n RY,\n angle,\n LAF,\n SF,\n x,\n y,\n );\n\n /* istanbul ignore else */\n if (typeof distance === \"number\") {\n const sweepAngle = endAngle - startAngle;\n const length = Math.abs(arcLengthBetween(rx, ry, startAngle, endAngle));\n // a zero radius is treated as a straight line to the end point\n if (rx === 0 || ry === 0) {\n return getPointAtLineLength(x1, y1, x, y, distance);\n }\n if (distance <= 0) {\n point = { x: x1, y: y1 };\n } else if (distance >= length) {\n point = { x, y };\n } else {\n const { PI, cos, sin } = Math;\n const xRot = ((angle % 360) + 360) % 360;\n const xRotRad = xRot * (PI / 180);\n\n let lo = 0;\n let hi = 1;\n for (let i = 0; i < 25; i += 1) {\n const mid = (lo + hi) / 2;\n if (\n Math.abs(arcLengthBetween(rx, ry, startAngle, startAngle + sweepAngle * mid)) < distance\n ) {\n lo = mid;\n } else {\n hi = mid;\n }\n }\n const alpha = startAngle + sweepAngle * ((lo + hi) / 2);\n const ellipseComponentX = rx * cos(alpha);\n const ellipseComponentY = ry * sin(alpha);\n\n point = {\n x: cos(xRotRad) * ellipseComponentX - sin(xRotRad) * ellipseComponentY + center.x,\n y: sin(xRotRad) * ellipseComponentX + cos(xRotRad) * ellipseComponentY + center.y,\n };\n }\n }\n\n return point;\n};\n\n/**\n * Returns the extrema for an Arc segment in the following format:\n * [MIN_X, MIN_Y, MAX_X, MAX_Y]\n *\n * @see https://github.com/herrstrietzel/svg-pathdata-getbbox\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param RX the radius on X axis\n * @param RY the radius on Y axis\n * @param angle the ellipse rotation in degrees\n * @param LAF the large arc flag\n * @param SF the sweep flag\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns the extrema of the Arc segment\n */\nconst getArcBBox = (\n x1: number,\n y1: number,\n RX: number,\n RY: number,\n angle: number,\n LAF: number,\n SF: number,\n x: number,\n y: number,\n): [number, number, number, number] => {\n const { min, max, tan, atan2, cos, PI } = Math;\n\n // an arc with the same start and end point is omitted by the spec\n if (x1 === x && y1 === y) {\n return [x1, y1, x, y];\n }\n\n // a zero radius is a straight line to the end point\n if (RX === 0 || RY === 0) {\n return [min(x1, x), min(y1, y), max(x1, x), max(y1, y)];\n }\n\n const { center, rx, ry, startAngle, endAngle } = getArcProps(\n x1,\n y1,\n RX,\n RY,\n angle,\n LAF,\n SF,\n x,\n y,\n );\n const deltaAngle = endAngle - startAngle;\n\n // circle/elipse center coordinates\n const { x: cx, y: cy } = center;\n\n // rotation to radians\n const alpha = (angle * PI) / 180;\n const tangent = tan(alpha);\n\n /**\n * find min/max from zeroes of directional derivative along x and y\n * along x axis\n */\n const theta = atan2(-ry * tangent, rx);\n const angle1 = theta;\n const angle2 = theta + PI;\n const angle3 = atan2(ry, rx * tangent);\n const angle4 = angle3 + PI;\n // the extremum points swap sides when the ellipse is rotated by more\n // than 90 degrees, the sign of `cos(alpha)` tells which one is which\n const flipped = cos(alpha) < 0;\n const rightAngle = flipped ? angle2 : angle1;\n const leftAngle = flipped ? angle1 : angle2;\n const topAngle = flipped ? angle3 : angle4;\n const bottomAngle = flipped ? angle4 : angle3;\n // the endpoints of the arc and the extrema of the ellipse it sweeps over\n const xArray = [x1, x];\n const yArray = [y1, y];\n\n // the span of the sweep and its direction\n const span = Math.abs(deltaAngle);\n const clockwise = deltaAngle >= 0;\n\n /**\n * tells if an extremum of the ellipse is on the arc, the offset of the\n * extremum is measured from the start of the arc, in the direction of\n * the sweep\n */\n const isOnArc = (extremum: number): boolean => {\n const offset = clockwise\n ? (((extremum - startAngle) % (2 * PI)) + 2 * PI) % (2 * PI)\n : (((startAngle - extremum) % (2 * PI)) + 2 * PI) % (2 * PI);\n return offset <= span + 1e-9;\n };\n\n // right\n if (isOnArc(rightAngle)) {\n const p = arcPoint(cx, cy, rx, ry, alpha, rightAngle);\n xArray.push(p[0]);\n yArray.push(p[1]);\n }\n\n // left\n if (isOnArc(leftAngle)) {\n const p = arcPoint(cx, cy, rx, ry, alpha, leftAngle);\n xArray.push(p[0]);\n yArray.push(p[1]);\n }\n\n // top\n if (isOnArc(topAngle)) {\n const p = arcPoint(cx, cy, rx, ry, alpha, topAngle);\n xArray.push(p[0]);\n yArray.push(p[1]);\n }\n\n // bottom\n if (isOnArc(bottomAngle)) {\n const p = arcPoint(cx, cy, rx, ry, alpha, bottomAngle);\n xArray.push(p[0]);\n yArray.push(p[1]);\n }\n\n return [min(...xArray), min(...yArray), max(...xArray), max(...yArray)] as [\n number,\n number,\n number,\n number,\n ];\n};\n\n/** The tools for elliptical arc computation. */\nconst arcTools = {\n angleBetween,\n arcLength,\n arcLengthAtAngle,\n arcLengthBetween,\n arcPoint,\n getArcBBox,\n getArcLength,\n getArcProps,\n getPointAtArcLength,\n};\n\nexport {\n angleBetween,\n arcLength,\n arcLengthAtAngle,\n arcLengthBetween,\n arcPoint,\n arcTools,\n getArcBBox,\n getArcLength,\n getArcProps,\n getPointAtArcLength,\n};\n","import { getBezierLength, getTAtBezierLength, minmaxC } from \"./bezier.ts\";\nimport type { BBoxMaxima, CubicCoordinates } from \"../types.ts\";\n\n/**\n * Returns a point at a given length of a CubicBezier segment.\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param c1x the first control point X\n * @param c1y the first control point Y\n * @param c2x the second control point X\n * @param c2y the second control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @param t a [0-1] ratio\n * @returns the point at cubic-bezier segment length\n */\nconst getPointAtCubicSegmentLength = (\n [x1, y1, c1x, c1y, c2x, c2y, x2, y2]: CubicCoordinates,\n t: number,\n): { x: number; y: number } => {\n const t1 = 1 - t;\n return {\n x: t1 ** 3 * x1 + 3 * t1 ** 2 * t * c1x + 3 * t1 * t ** 2 * c2x + t ** 3 * x2,\n y: t1 ** 3 * y1 + 3 * t1 ** 2 * t * c1y + 3 * t1 * t ** 2 * c2y + t ** 3 * y2,\n };\n};\n\n/**\n * Returns the length of a CubicBezier segment.\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param c1x the first control point X\n * @param c1y the first control point Y\n * @param c2x the second control point X\n * @param c2y the second control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns the CubicBezier segment length\n */\nconst getCubicLength = (\n x1: number,\n y1: number,\n c1x: number,\n c1y: number,\n c2x: number,\n c2y: number,\n x2: number,\n y2: number,\n): number => {\n return getBezierLength([x1, y1, c1x, c1y, c2x, c2y, x2, y2]);\n};\n\n/**\n * Returns the point along a CubicBezier segment at a given distance.\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param c1x the first control point X\n * @param c1y the first control point Y\n * @param c2x the second control point X\n * @param c2y the second control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @param distance the distance to look at\n * @returns the point at CubicBezier length\n */\nconst getPointAtCubicLength = (\n x1: number,\n y1: number,\n c1x: number,\n c1y: number,\n c2x: number,\n c2y: number,\n x2: number,\n y2: number,\n distance?: number,\n): { x: number; y: number } => {\n const distanceIsNumber = typeof distance === \"number\";\n let point = { x: x1, y: y1 };\n /* istanbul ignore else */\n if (distanceIsNumber) {\n const coords = [x1, y1, c1x, c1y, c2x, c2y, x2, y2] as CubicCoordinates;\n const currentLength = getBezierLength(coords);\n if (distance <= 0) {\n // first point already defined\n } else if (distance >= currentLength) {\n point = { x: x2, y: y2 };\n } else {\n const t = getTAtBezierLength(coords, distance);\n point = getPointAtCubicSegmentLength(coords, t);\n }\n }\n return point;\n};\n\n/**\n * Returns the bounding box of a CubicBezier segment in the following format:\n * [MIN_X, MIN_Y, MAX_X, MAX_Y]\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param c1x the first control point X\n * @param c1y the first control point Y\n * @param c2x the second control point X\n * @param c2y the second control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns the extrema of the CubicBezier segment\n */\nconst getCubicBBox = (\n x1: number,\n y1: number,\n c1x: number,\n c1y: number,\n c2x: number,\n c2y: number,\n x2: number,\n y2: number,\n): BBoxMaxima => {\n const cxMinMax = minmaxC([x1, c1x, c2x, x2]);\n const cyMinMax = minmaxC([y1, c1y, c2y, y2]);\n\n return [cxMinMax[0], cyMinMax[0], cxMinMax[1], cyMinMax[1]];\n};\n\n/** The tools for cubic Bezier computation. */\nconst cubicTools = {\n getCubicBBox,\n getCubicLength,\n getPointAtCubicLength,\n getPointAtCubicSegmentLength,\n};\n\nexport {\n cubicTools,\n getCubicBBox,\n getCubicLength,\n getPointAtCubicLength,\n getPointAtCubicSegmentLength,\n};\n","import { getBezierLength, getTAtBezierLength, minmaxQ } from \"./bezier.ts\";\nimport type { QuadCoordinates } from \"../types.ts\";\n\n/**\n * Returns the {x,y} coordinates of a point at a\n * given length of a quadratic-bezier segment.\n *\n * @see https://github.com/substack/point-at-length\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param cx the control point X\n * @param cy the control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @param t a [0-1] ratio\n * @returns the requested {x,y} coordinates\n */\nconst getPointAtQuadSegmentLength = (\n [x1, y1, cx, cy, x2, y2]: QuadCoordinates,\n t: number,\n): { x: number; y: number } => {\n const t1 = 1 - t;\n return {\n x: t1 ** 2 * x1 + 2 * t1 * t * cx + t ** 2 * x2,\n y: t1 ** 2 * y1 + 2 * t1 * t * cy + t ** 2 * y2,\n };\n};\n\n/**\n * Returns the length of a QuadraticBezier segment.\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param cx the control point X\n * @param cy the control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns the QuadraticBezier segment length\n */\nconst getQuadLength = (\n x1: number,\n y1: number,\n cx: number,\n cy: number,\n x2: number,\n y2: number,\n): number => {\n return getBezierLength([x1, y1, cx, cy, x2, y2]);\n};\n\n/**\n * Returns the point along a QuadraticBezier segment at a given distance.\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param cx the control point X\n * @param cy the control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @param distance the distance to look at\n * @returns the point at QuadraticBezier length\n */\nconst getPointAtQuadLength = (\n x1: number,\n y1: number,\n cx: number,\n cy: number,\n x2: number,\n y2: number,\n distance?: number,\n): { x: number; y: number } => {\n const distanceIsNumber = typeof distance === \"number\";\n let point = { x: x1, y: y1 };\n\n /* istanbul ignore else */\n if (distanceIsNumber) {\n const coords = [x1, y1, cx, cy, x2, y2] as QuadCoordinates;\n const currentLength = getBezierLength(coords);\n if (distance <= 0) {\n // first point already defined\n } else if (distance >= currentLength) {\n point = { x: x2, y: y2 };\n } else {\n const t = getTAtBezierLength(coords, distance);\n point = getPointAtQuadSegmentLength(coords, t);\n }\n }\n return point;\n};\n\n/**\n * Returns the bounding box of a QuadraticBezier segment in the following format:\n * [MIN_X, MIN_Y, MAX_X, MAX_Y]\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param cx the control point X\n * @param cy the control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns the extrema of the QuadraticBezier segment\n */\nconst getQuadBBox = (\n x1: number,\n y1: number,\n cx: number,\n cy: number,\n x2: number,\n y2: number,\n): [number, number, number, number] => {\n const cxMinMax = minmaxQ([x1, cx, x2]);\n const cyMinMax = minmaxQ([y1, cy, y2]);\n return [cxMinMax[0], cyMinMax[0], cxMinMax[1], cyMinMax[1]] as [number, number, number, number];\n};\n/** The tools for quadratic Bezier computation. */\nconst quadTools = {\n getPointAtQuadLength,\n getPointAtQuadSegmentLength,\n getQuadBBox,\n getQuadLength,\n};\n\nexport { getPointAtQuadLength, getPointAtQuadSegmentLength, getQuadBBox, getQuadLength, quadTools };\n","import type { PointTuple } from \"../types.ts\";\n\n/**\n * Returns the square root of the distance\n * between two given points.\n *\n * @param a the first point coordinates\n * @param b the second point coordinates\n * @returns the distance value\n */\nexport const distanceSquareRoot = (a: PointTuple, b: PointTuple): number => {\n return Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]));\n};\n","import { distanceSquareRoot } from \"./distanceSquareRoot.ts\";\nimport type { PointTuple } from \"../types.ts\";\n\n/**\n * d3-polygon-area\n * @see https://github.com/d3/d3-polygon\n *\n * Returns the area of a polygon.\n *\n * @param polygon Array of [x, y]\n * @returns Signed area\n */\nconst polygonArea = (polygon: PointTuple[]): number => {\n const n = polygon.length;\n let i = -1;\n let a: PointTuple;\n let b = polygon[n - 1];\n let area = 0;\n\n while (++i < n) {\n a = b;\n b = polygon[i];\n area += a[1] * b[0] - a[0] * b[1];\n }\n\n return area / 2;\n};\n\n/**\n * d3-polygon-length\n * https://github.com/d3/d3-polygon\n *\n * Returns the perimeter of a polygon.\n *\n * @param polygon an array of coordinates\n * @returns the polygon length\n */\nconst polygonLength = (polygon: PointTuple[]): number => {\n return polygon.reduce((length, point, i) => {\n if (i) {\n return length + distanceSquareRoot(polygon[i - 1], point);\n }\n return 0;\n }, 0);\n};\n\n/**\n * Computes the centroid (geometric center) of a polygon.\n * Uses average of all endpoint coordinates (robust for polygons and curves).\n *\n * @param polygon A polygon with consists of [x, y] tuples\n * @returns [x, y] centroid\n */\nconst polygonCentroid = (polygon: PointTuple[]): PointTuple => {\n if (polygon.length === 0) return [0, 0];\n\n let sumX = 0;\n let sumY = 0;\n\n for (const [x, y] of polygon) {\n sumX += x;\n sumY += y;\n }\n\n const count = polygon.length;\n return [sumX / count, sumY / count];\n};\n\n/** The tools for polygon computation. */\nconst polygonTools = {\n polygonArea,\n polygonLength,\n polygonCentroid,\n};\n\nexport { polygonArea, polygonCentroid, polygonLength, polygonTools };\n","import type { PointTuple } from \"../types.ts\";\n\n/**\n * Returns the coordinates of a specified distance\n * ratio between two points.\n *\n * @param a the first point coordinates\n * @param b the second point coordinates\n * @param t the ratio\n * @returns the midpoint coordinates\n */\nexport const midPoint = ([ax, ay]: PointTuple, [bx, by]: PointTuple, t: number): PointTuple => {\n return [ax + (bx - ax) * t, ay + (by - ay) * t];\n};\n","/**\n * Returns an {x,y} vector rotated by a given\n * angle in radian.\n *\n * @param x the initial vector x\n * @param y the initial vector y\n * @param rad the radian vector angle\n * @returns the rotated vector\n */\nexport const rotateVector = (x: number, y: number, rad: number): { x: number; y: number } => {\n const { sin, cos } = Math;\n const X = x * cos(rad) - y * sin(rad);\n const Y = x * sin(rad) + y * cos(rad);\n return { x: X, y: Y };\n};\n","/**\n * Rounds a number to the specified number of decimal places.\n *\n * @param n - The number to round\n * @param round - Number of decimal places\n * @returns The rounded number\n */\nexport const roundTo = (n: number, round: number): number => {\n const pow = round >= 1 ? 10 ** round : 1;\n\n return round > 0 ? Math.round(n * pow) / pow : Math.round(n);\n};\n","/** Segment params length */\n\nexport const paramsCounts = {\n a: 7,\n c: 6,\n h: 1,\n l: 2,\n m: 2,\n r: 4,\n q: 4,\n s: 4,\n t: 2,\n v: 1,\n z: 0,\n};\n\n/**\n * The number of parameters of every command, by character code.\n *\n * The parser looks the number of the parameters of a command up for every\n * segment it scans, and the lookup by character code spares it the\n * lowercasing of the command and the lookup of the string.\n *\n * @internal\n */\nexport const paramsCountsByCode = new Uint8Array(128);\n\nfor (const [command, count] of Object.entries(paramsCounts)) {\n const code = command.charCodeAt(0);\n paramsCountsByCode[code] = count;\n // the uppercase command is the lowercase one, 32 characters higher\n paramsCountsByCode[code - 32] = count;\n}\n","import { paramsCountsByCode } from \"./paramsCount.ts\";\nimport type { PathParser } from \"./pathParser.ts\";\nimport type { PathCommand, PathSegment } from \"../types.ts\";\n\n/**\n * Breaks the parsing of a pathString once a segment is finalized.\n *\n * @param path - The PathParser instance\n */\nexport const finalizeSegment = (path: PathParser): void => {\n let pathCommand = path.pathValue[path.segmentStart] as PathCommand;\n const { data } = path;\n let index = 0;\n // the number of parameters of the command, by character code\n let paramCount = paramsCountsByCode[pathCommand.charCodeAt(0) | 0x20];\n // a moveto is the only command that can be overloaded\n let isMove = pathCommand === \"m\" || pathCommand === \"M\";\n\n while (data.length - index >= paramCount) {\n // overloaded `moveTo`\n // https://github.com/rveciana/svg-path-properties/blob/master/src/parse.ts\n if (isMove && data.length - index > 2) {\n // oxlint-disable-next-line unicorn/no-new-array -- preallocated for a faster fill\n const segment = new Array<number | PathCommand>(3);\n segment[0] = pathCommand;\n segment[1] = data[index] as number;\n segment[2] = data[index + 1] as number;\n path.segments.push(segment as PathSegment);\n index += 2;\n isMove = false;\n pathCommand = pathCommand === \"m\" ? \"l\" : \"L\";\n // the lineto has two parameters\n paramCount = 2;\n } else {\n // oxlint-disable-next-line unicorn/no-new-array -- preallocated for a faster fill\n const segment = new Array<number | PathCommand>(paramCount + 1);\n segment[0] = pathCommand;\n for (let i = 0; i < paramCount; i += 1) {\n segment[i + 1] = data[index + i] as number;\n }\n path.segments.push(segment as PathSegment);\n index += paramCount;\n }\n\n if (!paramCount) {\n break;\n }\n }\n};\n","/** Error prefix used in all SVGPathCommander TypeError messages. */\nexport const error = \"SVGPathCommanderError\";\n","import { error } from \"../util/error.ts\";\nimport type { PathParser } from \"./pathParser.ts\";\n\n/**\n * Validates an A (arc-to) specific path command value.\n * Usually a `large-arc-flag` or `sweep-flag`.\n *\n * @param path - The PathParser instance\n */\nexport const scanFlag = (path: PathParser) => {\n const { index, pathValue } = path;\n const code = pathValue.charCodeAt(index);\n\n if (code === 0x30 /* 0 */) {\n path.param = 0;\n path.index += 1;\n return;\n }\n\n if (code === 0x31 /* 1 */) {\n path.param = 1;\n path.index += 1;\n return;\n }\n\n path.err = `${error}: invalid Arc flag \"${pathValue[index]}\", expecting 0 or 1 at index ${index}`;\n};\n","import type { DigitNumber } from \"../types.ts\";\n\n/**\n * Checks if a character is a digit.\n *\n * @param code the character to check\n * @returns check result\n */\nexport const isDigit = (code: number): code is DigitNumber => {\n return code >= 48 && code <= 57; // 0..9\n};\n","/** Error message prefix used when a path string cannot be parsed. */\nexport const invalidPathValue = \"Invalid path value\";\n","import { isDigit } from \"./isDigit.ts\";\nimport { invalidPathValue } from \"./invalidPathValue.ts\";\nimport { error } from \"../util/error.ts\";\nimport type { PathParser } from \"./pathParser.ts\";\n\n/**\n * Validates every character of the path string,\n * every path command, negative numbers or floating point numbers.\n *\n * @param path - The PathParser instance\n */\nexport const scanParam = (path: PathParser) => {\n const { max, pathValue, index: start } = path;\n let index = start;\n let hasCeiling = false;\n let hasDecimal = false;\n let hasDot = false;\n let ch;\n\n if (index >= max) {\n path.err = `${error}: ${invalidPathValue} at index ${index}, \"pathValue\" is missing param`;\n return;\n }\n ch = pathValue.charCodeAt(index);\n\n if (ch === 0x2b /* + */ || ch === 0x2d /* - */) {\n index += 1;\n // ch = (index < max) ? pathValue.charCodeAt(index) : 0;\n ch = pathValue.charCodeAt(index);\n }\n\n // This logic is shamelessly borrowed from Esprima\n // https://github.com/ariya/esprimas\n if (!isDigit(ch) && ch !== 0x2e /* . */) {\n // path.err = 'SvgPath: param should start with 0..9 or `.` (at pos ' + index + ')';\n path.err = `${error}: ${invalidPathValue} at index ${index}, \"${\n pathValue[index]\n }\" is not a number`;\n return;\n }\n\n if (ch !== 0x2e /* . */) {\n index += 1;\n\n ch = pathValue.charCodeAt(index);\n\n while (index < max && isDigit(pathValue.charCodeAt(index))) {\n index += 1;\n hasCeiling = true;\n }\n\n ch = pathValue.charCodeAt(index);\n }\n\n if (ch === 0x2e /* . */) {\n hasDot = true;\n index += 1;\n while (isDigit(pathValue.charCodeAt(index))) {\n index += 1;\n hasDecimal = true;\n }\n\n ch = pathValue.charCodeAt(index);\n }\n\n if (ch === 0x65 /* e */ || ch === 0x45 /* E */) {\n if (hasDot && !hasCeiling && !hasDecimal) {\n path.err = `${error}: ${invalidPathValue} at index ${index}, \"${\n pathValue[index]\n }\" invalid float exponent`;\n return;\n }\n\n index += 1;\n\n ch = pathValue.charCodeAt(index);\n\n if (ch === 0x2b /* + */ || ch === 0x2d /* - */) {\n index += 1;\n }\n if (index < max && isDigit(pathValue.charCodeAt(index))) {\n while (index < max && isDigit(pathValue.charCodeAt(index))) {\n index += 1;\n }\n } else {\n path.err = `${error}: ${invalidPathValue} at index ${index}, \"${\n pathValue[index]\n }\" invalid integer exponent`;\n return;\n }\n }\n\n path.index = index;\n path.param = scanNumber(pathValue, start, index);\n // a number that overflows the double range is not a valid path value\n if (!Number.isFinite(path.param)) {\n path.err = `${error}: ${invalidPathValue} at index ${start}, \"${pathValue.slice(\n start,\n index,\n )}\" is not a finite number`;\n }\n};\n\n/**\n * Converts a validated number substring to a Number without\n * allocating a new string, matching `+str.slice(start, end)`.\n *\n * Falls back to the native conversion when the value cannot be\n * represented exactly with plain double arithmetic (more than 15\n * significant digits or an exponent beyond +-22).\n *\n * @param str - the path string\n * @param start - the index of the first char of the number\n * @param end - the index after the last char of the number\n * @returns the parsed number\n */\nconst scanNumber = (str: string, start: number, end: number): number => {\n let i = start;\n let sign = 1;\n let param = 0;\n let decimals = 0;\n let sigDigits = 0;\n let inFraction = false;\n let expSign = 1;\n let exp = 0;\n\n const ch = str.charCodeAt(i);\n if (ch === 0x2b /* + */) {\n i += 1;\n } else if (ch === 0x2d /* - */) {\n sign = -1;\n i += 1;\n }\n\n for (; i < end; i += 1) {\n const code = str.charCodeAt(i);\n if (code === 0x2e /* . */) {\n inFraction = true;\n } else if (code === 0x65 /* e */ || code === 0x45 /* E */) {\n i += 1;\n const expCode = str.charCodeAt(i);\n if (expCode === 0x2b /* + */) {\n i += 1;\n } else if (expCode === 0x2d /* - */) {\n expSign = -1;\n i += 1;\n }\n for (; i < end; i += 1) {\n exp = exp * 10 + (str.charCodeAt(i) - 0x30);\n }\n } else {\n const digit = code - 0x30;\n if (digit !== 0 || param !== 0) {\n sigDigits += 1;\n }\n param = param * 10 + digit;\n if (inFraction) {\n decimals += 1;\n }\n }\n }\n\n if (sigDigits > 15 || sigDigits === 0) {\n return +str.slice(start, end);\n }\n\n const scale = expSign * exp - decimals;\n if (scale > 22 || scale < -22) {\n return +str.slice(start, end);\n }\n\n if (scale >= 0) {\n return sign * param * 10 ** scale;\n }\n return (sign * param) / 10 ** -scale;\n};\n","import type { SpaceNumber } from \"../types.ts\";\n\n/**\n * The characters the SVG path grammar accepts as white space.\n *\n * The set is built once, at module level: the parser calls `isSpace` for\n * every single character of a path, and building the list on every call\n * made the tokenizer allocate its way through a path.\n */\nconst spaces = new Set<number>([\n // Special spaces\n 0x1680, 0x180e, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009,\n 0x200a, 0x202f, 0x205f, 0x3000, 0xfeff,\n // Line terminators\n 0x0a, 0x0d, 0x2028, 0x2029,\n // White spaces\n 0x20, 0x09, 0x0b, 0x0c, 0xa0,\n]);\n\n/**\n * Checks if the character is a space.\n *\n * @param ch the character to check\n * @returns check result\n */\n\nexport const isSpace = (ch: number): ch is SpaceNumber => {\n return spaces.has(ch);\n};\n","import { isSpace } from \"./isSpace.ts\";\nimport type { PathParser } from \"./pathParser.ts\";\n\n/**\n * Points the parser to the next character in the\n * path string every time it encounters any kind of\n * space character.\n *\n * @param path - The PathParser instance\n */\nexport const skipSpaces = (path: PathParser): void => {\n const { pathValue, max } = path;\n while (path.index < max && isSpace(pathValue.charCodeAt(path.index))) {\n path.index += 1;\n }\n};\n","import type { PathCommandNumber } from \"../types.ts\";\n\n/**\n * Checks if the character is a path command.\n *\n * @param code the character to check\n * @returns check result\n */\nexport const isPathCommand = (code: number): code is PathCommandNumber => {\n // eslint-disable-next-line no-bitwise -- Impossible to satisfy\n switch (code | 0x20) {\n case 0x6d /* m */:\n case 0x7a /* z */:\n case 0x6c /* l */:\n case 0x68 /* h */:\n case 0x76 /* v */:\n case 0x63 /* c */:\n case 0x73 /* s */:\n case 0x71 /* q */:\n case 0x74 /* t */:\n case 0x61 /* a */:\n // case 0x72/* r */:\n return true;\n default:\n return false;\n }\n};\n","import { isDigit } from \"./isDigit.ts\";\nimport type { DigitNumber } from \"../types.ts\";\n\n/**\n * Checks if the character is or belongs to a number.\n * [0-9]|+|-|.\n *\n * @param code the character to check\n * @returns check result\n */\nexport const isDigitStart = (code: number): code is DigitNumber | 0x2b | 0x2d | 0x2e => {\n return (\n isDigit(code) /* 0..9 */ || code === 0x2b /* + */ || code === 0x2d /* - */ || code === 0x2e\n ); /* . */\n};\n","/**\n * Checks if the character is an A (arc-to) path command.\n *\n * @param code the character to check\n * @returns check result\n */\nexport const isArcCommand = (code: number): code is 0x61 => {\n // eslint-disable-next-line no-bitwise -- Impossible to satisfy\n return (code | 0x20) === 0x61;\n};\n","/**\n * Checks if the character is a MoveTo command.\n *\n * @param code the character to check\n * @returns check result\n */\nexport const isMoveCommand = (code: number): code is 0x6d | 0x4d => {\n // eslint-disable-next-line no-bitwise -- Impossible to satisfy\n switch (code | 0x20) {\n case 0x6d /* m */:\n case 0x4d /* M */:\n return true;\n default:\n return false;\n }\n};\n","import { finalizeSegment } from \"./finalizeSegment.ts\";\nimport { paramsCountsByCode } from \"./paramsCount.ts\";\nimport { scanFlag } from \"./scanFlag.ts\";\nimport { scanParam } from \"./scanParam.ts\";\nimport { skipSpaces } from \"./skipSpaces.ts\";\nimport { isPathCommand } from \"./isPathCommand.ts\";\nimport { isDigitStart } from \"./isDigitStart.ts\";\nimport { isArcCommand } from \"./isArcCommand.ts\";\nimport { isMoveCommand } from \"./isMoveCommand.ts\";\nimport { invalidPathValue } from \"./invalidPathValue.ts\";\nimport { error } from \"../util/error.ts\";\n\nimport type { PathParser } from \"./pathParser.ts\";\nimport type { PathSegment } from \"../types.ts\";\n\n/**\n * Scans every character in the path string to determine\n * where a segment starts and where it ends.\n *\n * @param path - The PathParser instance\n */\nexport const scanSegment = (path: PathParser) => {\n const { max, pathValue, index, segments } = path;\n const cmdCode = pathValue.charCodeAt(index);\n const reqParams = paramsCountsByCode[cmdCode];\n\n path.segmentStart = index;\n\n // segments always start with a path command\n if (!isPathCommand(cmdCode)) {\n path.err = `${error}: ${invalidPathValue} \"${\n pathValue[index]\n }\" is not a path command at index ${index}`;\n return;\n }\n\n // after a Z segment, we only expect a MoveTo path command\n const lastSegment = segments[segments.length - 1] as PathSegment | undefined;\n if (!isMoveCommand(cmdCode) && lastSegment?.[0]?.toLocaleLowerCase() === \"z\") {\n path.err = `${error}: ${invalidPathValue} \"${\n pathValue[index]\n }\" is not a MoveTo path command at index ${index}`;\n return;\n }\n\n path.index += 1;\n skipSpaces(path);\n\n path.data = [];\n\n if (!reqParams) {\n // Z\n finalizeSegment(path);\n return;\n }\n\n for (;;) {\n for (let i = reqParams; i > 0; i -= 1) {\n if (isArcCommand(cmdCode) && (i === 3 || i === 4)) scanFlag(path);\n else scanParam(path);\n\n if (path.err.length) {\n return;\n }\n path.data.push(path.param);\n\n skipSpaces(path);\n\n // after ',' param is mandatory\n if (path.index < max && pathValue.charCodeAt(path.index) === 0x2c /* , */) {\n path.index += 1;\n skipSpaces(path);\n }\n }\n\n if (path.index >= path.max) {\n break;\n }\n\n // Stop on next segment\n if (!isDigitStart(pathValue.charCodeAt(path.index))) {\n break;\n }\n }\n\n finalizeSegment(path);\n};\n","import type { PathArray, PathSegment } from \"../types.ts\";\n\n/**\n * The `PathParser` is used by the `parsePathString` static method\n * to generate a `pathArray`.\n *\n * @param pathString - The SVG path string to parse\n */\nexport class PathParser {\n declare segments: PathArray | PathSegment[];\n declare pathValue: string;\n declare max: number;\n declare index: number;\n declare param: number;\n declare segmentStart: number;\n declare data: (string | number)[];\n declare err: string;\n\n constructor(pathString: string) {\n this.segments = [];\n this.pathValue = pathString;\n this.max = pathString.length;\n this.index = 0;\n this.param = 0.0;\n this.segmentStart = 0;\n this.data = [];\n this.err = \"\";\n }\n}\n","import { scanSegment } from \"./scanSegment.ts\";\nimport { skipSpaces } from \"./skipSpaces.ts\";\nimport { PathParser } from \"./pathParser.ts\";\nimport type { MSegment, PathArray } from \"../types.ts\";\nimport { error } from \"../util/error.ts\";\n\n/**\n * Parses a path string value and returns an array\n * of segments we like to call `PathArray`.\n *\n * If parameter value is already a `PathArray`,\n * return a clone of it.\n *\n * A path must begin with a moveto command, so a path that starts with another\n * command is in error. A leading relative moveto is a pair of absolute\n * coordinates, so it is rewritten as an absolute one.\n *\n * @example\n * parsePathString(\"M 0 0L50 50\")\n * // => [[\"M\",0,0],[\"L\",50,50]]\n *\n * @param pathInput the string to be parsed\n * @returns the resulted `pathArray` or error string\n */\nexport const parsePathString = <T extends PathArray>(pathInput: string | T): PathArray => {\n let path: PathArray;\n\n if (typeof pathInput !== \"string\") {\n path = pathInput.slice(0) as T;\n } else {\n const parser = new PathParser(pathInput);\n\n skipSpaces(parser);\n\n while (parser.index < parser.max && !parser.err.length) {\n scanSegment(parser);\n }\n\n // handle errors first\n if (parser.err.length) {\n throw TypeError(parser.err);\n }\n\n path = parser.segments as PathArray;\n }\n\n const first = path[0];\n // an empty path has no first segment\n if (!first) return path;\n\n // a malformed segment is reported by its index\n if (typeof first[0] !== \"string\") {\n throw new TypeError(`${error}: invalid path segment at index 0`);\n }\n\n if (first[0] === \"m\") {\n /**\n * force absolute first M\n * getPathBBox calculation requires first segment to be absolute\n * @see https://github.com/thednp/svg-path-commander/pull/49\n */\n // the copy keeps the caller's array untouched\n path[0] = [\"M\", first[1], first[2]] as MSegment;\n } else if (first[0] !== \"M\") {\n throw new TypeError(`${error}: path data must begin with a moveto command`);\n }\n\n return path;\n};\n","import type {\n AbsoluteCommand,\n AbsoluteSegment,\n ASegment,\n CSegment,\n HSegment,\n LSegment,\n MSegment,\n PathSegment,\n QSegment,\n SSegment,\n TSegment,\n VSegment,\n} from \"../types.ts\";\n\n/**\n * Returns an absolute segment of a `PathArray` object.\n *\n * The current point of a path starts at the origin, so the first segment\n * of a path is absolutized against `[0, 0]`: a relative moveto at the\n * start of a path is an absolute one, as the SVG spec requires.\n *\n * @param segment the segment object\n * @param _index the segment index\n * @param lastX the last known X value\n * @param lastY the last known Y value\n * @returns the absolute segment\n */\nexport const absolutizeSegment = (\n segment: PathSegment,\n _index: number,\n lastX: number,\n lastY: number,\n): AbsoluteSegment => {\n const [pathCommand] = segment;\n const absCommand = pathCommand.toUpperCase() as AbsoluteCommand;\n const isAbsolute = absCommand === pathCommand;\n\n // an absolute segment is already absolute\n /* istanbul ignore else */\n if (isAbsolute) return segment as MSegment | AbsoluteSegment;\n // const values = segment.slice(1) as number[];\n if (absCommand === \"A\") {\n return [\n absCommand,\n segment[1],\n segment[2],\n segment[3],\n segment[4],\n segment[5],\n (segment as ASegment)[6] + lastX,\n (segment as ASegment)[7] + lastY,\n ] as ASegment;\n } else if (absCommand === \"V\") {\n return [absCommand, (segment as VSegment)[1] + lastY] as VSegment;\n } else if (absCommand === \"H\") {\n return [absCommand, (segment as HSegment)[1] + lastX] as HSegment;\n } else if (absCommand === \"L\") {\n return [\n absCommand,\n (segment as LSegment)[1] + lastX,\n (segment as LSegment)[2] + lastY,\n ] as LSegment;\n } else if (absCommand === \"C\") {\n return [\n absCommand,\n (segment as CSegment)[1] + lastX,\n (segment as CSegment)[2] + lastY,\n (segment as CSegment)[3] + lastX,\n (segment as CSegment)[4] + lastY,\n (segment as CSegment)[5] + lastX,\n (segment as CSegment)[6] + lastY,\n ] as CSegment;\n } else {\n // use brakets for `eslint: no-case-declaration`\n // https://stackoverflow.com/a/50753272/803358\n const absValues = [] as number[];\n const seglen = segment.length;\n for (let j = 1; j < seglen; j += 1) {\n absValues.push((segment[j] as number) + (j % 2 ? lastX : lastY));\n }\n // for s, q, t\n return [absCommand as typeof absCommand | number].concat(absValues) as\n | MSegment\n | QSegment\n | TSegment\n | SSegment\n | CSegment;\n }\n};\n","// import paramsParser from \"../parser/paramsParser.ts\";\nimport type { AbsoluteCommand, IteratorCallback, PathArray } from \"../types.ts\";\nimport { error } from \"../util/error.ts\";\n\n/**\n * Iterates over a `PathArray`, executing a callback for each segment.\n * The callback can:\n * - Read current position (`x`, `y`)\n * - Modify the segment (return new segment)\n * - Stop early (return `false`)\n *\n * The iterator maintains accurate current point (`x`, `y`) and subpath start (`mx`, `my`)\n * while correctly handling relative/absolute commands, including H/V and Z.\n *\n * **Important**: If the callback returns a new segment with more coordinates (e.g., Q → C),\n * the path length may increase, and iteration will continue over new segments.\n *\n * @template T - Specific PathArray type (e.g., CurveArray, PolylineArray)\n * @param path - The source `PathArray` to iterate over\n * @param iterator - Callback function for each segment\n * @param iterator.segment - Current path segment\n * @param iterator.index - Index of current segment\n * @param iterator.x - Current X position (after applying relative offset)\n * @param iterator.y - Current Y position (after applying relative offset)\n * @returns The modified `path` (or original if no changes)\n *\n * @example\n * iterate(path, (seg, i, x, y) => {\n * if (seg[0] === 'L') return ['C', x, y, seg[1], seg[2], seg[1], seg[2]];\n * });\n */\nexport const iterate = <T extends PathArray>(path: T, iterator: IteratorCallback<T>): T => {\n let x = 0;\n let y = 0;\n let mx = 0;\n let my = 0;\n\n let i = 0;\n while (i < path.length) {\n const segment = path[i];\n const pathCommand = segment[0];\n if (typeof pathCommand !== \"string\") {\n throw new TypeError(`${error}: invalid path segment at index ${i}`);\n }\n const commandCode = pathCommand.charCodeAt(0);\n const isRelative = commandCode >= 97; // a-z\n const absCommand = (\n isRelative ? String.fromCharCode(commandCode - 32) : pathCommand\n ) as AbsoluteCommand;\n\n const iteratorResult = iterator(segment, i, x, y);\n // some methods like getPointAtLength would like to break\n // when task is complete\n if (iteratorResult === false) {\n break;\n }\n\n // segment = path[i];\n if (absCommand === \"Z\") {\n x = mx;\n y = my;\n } else if (absCommand === \"H\") {\n x = (segment[1] as number) + (isRelative ? x : 0);\n } else if (absCommand === \"V\") {\n y = (segment[1] as number) + (isRelative ? y : 0);\n } else {\n const segLen = segment.length;\n\n x = (segment[segLen - 2] as number) + (isRelative ? x : 0);\n y = (segment[segLen - 1] as number) + (isRelative ? y : 0);\n\n if (absCommand === \"M\") {\n mx = x;\n my = y;\n }\n }\n\n if (iteratorResult) {\n path[i] = iteratorResult;\n }\n\n i += 1;\n }\n return path as T;\n};\n","import type { AbsoluteArray, PathArray } from \"../types.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { absolutizeSegment } from \"../process/absolutizeSegment.ts\";\nimport { iterate } from \"../process/iterate.ts\";\n\n/**\n * Parses a path string value or object and returns an array\n * of segments, all converted to absolute values.\n *\n * @param pathInput - The path string or PathArray\n * @returns The resulted PathArray with absolute values\n *\n * @example\n * ```ts\n * pathToAbsolute('M10 10l80 80')\n * // => [['M', 10, 10], ['L', 90, 90]]\n * ```\n */\nexport const pathToAbsolute = <T extends PathArray>(pathInput: string | T): AbsoluteArray => {\n const path = parsePathString(pathInput);\n\n return iterate(path, absolutizeSegment) as AbsoluteArray;\n};\n","import type {\n aSegment,\n cSegment,\n hSegment,\n lSegment,\n MSegment,\n PathSegment,\n qSegment,\n RelativeCommand,\n RelativeSegment,\n sSegment,\n tSegment,\n vSegment,\n} from \"../types.ts\";\n\n/**\n * Returns a relative segment of a `PathArray` object.\n *\n * @param segment the segment object\n * @param index the segment index\n * @param lastX the last known X value\n * @param lastY the last known Y value\n * @returns the relative segment\n */\nexport const relativizeSegment = (\n segment: PathSegment,\n index: number,\n lastX: number,\n lastY: number,\n): MSegment | RelativeSegment => {\n const [pathCommand] = segment;\n const relCommand = pathCommand.toLowerCase() as RelativeCommand;\n const isRelative = pathCommand === relCommand;\n\n /* istanbul ignore else */\n if (index === 0 || isRelative) return segment as MSegment | RelativeSegment;\n\n if (relCommand === \"a\") {\n return [\n relCommand,\n segment[1],\n segment[2],\n segment[3],\n segment[4],\n segment[5],\n (segment as aSegment)[6] - lastX,\n (segment as aSegment)[7] - lastY,\n ] as aSegment;\n } else if (relCommand === \"v\") {\n return [relCommand, (segment as vSegment)[1] - lastY] as vSegment;\n } else if (relCommand === \"h\") {\n return [relCommand, (segment as hSegment)[1] - lastX] as hSegment;\n } else if (relCommand === \"l\") {\n return [\n relCommand,\n (segment as lSegment)[1] - lastX,\n (segment as lSegment)[2] - lastY,\n ] as lSegment;\n } else {\n // use brakets for `eslint: no-case-declaration`\n // https://stackoverflow.com/a/50753272/803358\n const relValues = [] as number[];\n const seglen = segment.length;\n for (let j = 1; j < seglen; j += 1) {\n relValues.push((segment[j] as number) - (j % 2 ? lastX : lastY));\n }\n // for c, s, q, t\n return [relCommand as RelativeCommand | number].concat(relValues) as\n | qSegment\n | tSegment\n | sSegment\n | cSegment;\n }\n};\n","import type { PathArray, RelativeArray } from \"../types.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { iterate } from \"../process/iterate.ts\";\nimport { relativizeSegment } from \"../process/relativizeSegment.ts\";\n\n/**\n * Parses a path string value or object and returns an array\n * of segments, all converted to relative values.\n *\n * @param pathInput - The path string or PathArray\n * @returns The resulted PathArray with relative values\n *\n * @example\n * ```ts\n * pathToRelative('M10 10L90 90')\n * // => [['M', 10, 10], ['l', 80, 80]]\n * ```\n */\nexport const pathToRelative = <T extends PathArray>(pathInput: string | T): RelativeArray => {\n const path = parsePathString(pathInput);\n\n return iterate(path, relativizeSegment) as RelativeArray;\n};\n","import { midPoint } from \"../math/midPoint.ts\";\n\n/**\n * Converts an L (line-to) segment to C (cubic-bezier).\n *\n * @param x1 line start x\n * @param y1 line start y\n * @param x2 line end x\n * @param y2 line end y\n * @returns the cubic-bezier segment\n */\nexport const lineToCubic = (x1: number, y1: number, x2: number, y2: number): number[] => {\n const c1 = midPoint([x1, y1], [x2, y2], 1.0 / 3.0);\n const c2 = midPoint([x1, y1], [x2, y2], 2.0 / 3.0);\n return [c1[0], c1[1], c2[0], c2[1], x2, y2];\n};\n","import { rotateVector } from \"../math/rotateVector.ts\";\nimport { lineToCubic } from \"./lineToCubic.ts\";\n\n/**\n * Converts A (arc-to) segments to C (cubic-bezier-to).\n *\n * For more information of where this math came from visit:\n * http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes\n *\n * @param X1 the starting x position\n * @param Y1 the starting y position\n * @param RX x-radius of the arc\n * @param RY y-radius of the arc\n * @param angle x-axis-rotation of the arc\n * @param LAF large-arc-flag of the arc\n * @param SF sweep-flag of the arc\n * @param X2 the ending x position\n * @param Y2 the ending y position\n * @param recursive the parameters needed to split arc into 2 segments\n * @returns the resulting cubic-bezier segment(s)\n */\nexport const arcToCubic = (\n X1: number,\n Y1: number,\n RX: number,\n RY: number,\n angle: number,\n LAF: number,\n SF: number,\n X2: number,\n Y2: number,\n recursive?: [number, number, number, number],\n): number[] => {\n let x1 = X1;\n let y1 = Y1;\n // a negative radius is an error, the absolute value is used\n let rx = Math.abs(RX);\n let ry = Math.abs(RY);\n let x2 = X2;\n let y2 = Y2;\n // for more information of where this Math came from visit:\n // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes\n const d120 = (Math.PI * 120) / 180;\n\n // a zero radius is treated as a straight line to the end point\n if (!recursive && (rx === 0 || ry === 0)) {\n return lineToCubic(X1, Y1, X2, Y2);\n }\n\n const rad = (Math.PI / 180) * (+angle || 0);\n let res = [] as number[];\n let xy;\n let f1;\n let f2;\n let cx;\n let cy;\n\n if (!recursive) {\n xy = rotateVector(x1, y1, -rad);\n x1 = xy.x;\n y1 = xy.y;\n xy = rotateVector(x2, y2, -rad);\n x2 = xy.x;\n y2 = xy.y;\n\n const x = (x1 - x2) / 2;\n const y = (y1 - y2) / 2;\n let h = (x * x) / (rx * rx) + (y * y) / (ry * ry);\n if (h > 1) {\n h = Math.sqrt(h);\n rx *= h;\n ry *= h;\n }\n const rx2 = rx * rx;\n const ry2 = ry * ry;\n\n const k =\n (LAF === SF ? -1 : 1) *\n Math.sqrt(Math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x)));\n\n cx = (k * rx * y) / ry + (x1 + x2) / 2;\n cy = (k * -ry * x) / rx + (y1 + y2) / 2;\n // eslint-disable-next-line no-bitwise -- Impossible to satisfy no-bitwise\n f1 = Math.asin(((((y1 - cy) / ry) * 10 ** 9) >> 0) / 10 ** 9);\n // eslint-disable-next-line no-bitwise -- Impossible to satisfy no-bitwise\n f2 = Math.asin(((((y2 - cy) / ry) * 10 ** 9) >> 0) / 10 ** 9);\n\n f1 = x1 < cx ? Math.PI - f1 : f1;\n f2 = x2 < cx ? Math.PI - f2 : f2;\n if (f1 < 0) f1 = Math.PI * 2 + f1;\n if (f2 < 0) f2 = Math.PI * 2 + f2;\n if (SF && f1 > f2) {\n f1 -= Math.PI * 2;\n }\n if (!SF && f2 > f1) {\n f2 -= Math.PI * 2;\n }\n } else {\n [f1, f2, cx, cy] = recursive;\n }\n let df = f2 - f1;\n if (Math.abs(df) > d120) {\n const f2old = f2;\n const x2old = x2;\n const y2old = y2;\n f2 = f1 + d120 * (SF && f2 > f1 ? 1 : -1);\n x2 = cx + rx * Math.cos(f2);\n y2 = cy + ry * Math.sin(f2);\n res = arcToCubic(x2, y2, rx, ry, angle, 0, SF, x2old, y2old, [f2, f2old, cx, cy]);\n }\n df = f2 - f1;\n const c1 = Math.cos(f1);\n const s1 = Math.sin(f1);\n const c2 = Math.cos(f2);\n const s2 = Math.sin(f2);\n const t = Math.tan(df / 4);\n const hx = (4 / 3) * rx * t;\n const hy = (4 / 3) * ry * t;\n const m1 = [x1, y1];\n const m2 = [x1 + hx * s1, y1 - hy * c1];\n const m3 = [x2 + hx * s2, y2 - hy * c2];\n const m4 = [x2, y2];\n m2[0] = 2 * m1[0] - m2[0];\n m2[1] = 2 * m1[1] - m2[1];\n if (recursive) {\n return [m2[0], m2[1], m3[0], m3[1], m4[0], m4[1]].concat(res);\n }\n res = [m2[0], m2[1], m3[0], m3[1], m4[0], m4[1]].concat(res);\n const newres = [];\n for (let i = 0, ii = res.length; i < ii; i += 1) {\n newres[i] =\n i % 2 ? rotateVector(res[i - 1], res[i], rad).y : rotateVector(res[i], res[i + 1], rad).x;\n }\n return newres;\n};\n","/**\n * Converts a Q (quadratic-bezier) segment to C (cubic-bezier).\n *\n * @param x1 curve start x\n * @param y1 curve start y\n * @param qx control point x\n * @param qy control point y\n * @param x2 curve end x\n * @param y2 curve end y\n * @returns the cubic-bezier segment\n */\nexport const quadToCubic = (\n x1: number,\n y1: number,\n qx: number,\n qy: number,\n x2: number,\n y2: number,\n): [number, number, number, number, number, number] => {\n const r13 = 1 / 3;\n const r23 = 2 / 3;\n return [\n r13 * x1 + r23 * qx, // cpx1\n r13 * y1 + r23 * qy, // cpy1\n r13 * x2 + r23 * qx, // cpx2\n r13 * y2 + r23 * qy, // cpy2\n x2,\n y2, // x,y\n ];\n};\n","import { arcToCubic } from \"./arcToCubic.ts\";\nimport { quadToCubic } from \"./quadToCubic.ts\";\nimport { lineToCubic } from \"./lineToCubic.ts\";\nimport type { CSegment, PathSegment } from \"../types.ts\";\nimport type { ParserParams } from \"../interface.ts\";\n\n/**\n * Converts any segment to C (cubic-bezier).\n *\n * A segment that is already a cubic, or a command the converter does not\n * handle, is returned unchanged.\n *\n * @param segment the source segment\n * @param params the source segment parameters\n * @returns the cubic-bezier segment\n */\nexport const segmentToCubic = (segment: PathSegment, params: ParserParams): PathSegment => {\n const pathCommand = segment[0];\n const values = segment.slice(1).map(Number);\n const [x, y] = values;\n // let args;\n // const { x1: px1, y1: py1, x: px, y: py } = params;\n const { x1: px1, y1: py1 } = params;\n\n if (!\"TQ\".includes(pathCommand)) {\n params.qx = null;\n params.qy = null;\n }\n\n if (pathCommand === \"M\") {\n params.mx = x;\n params.my = y;\n params.x = x;\n params.y = y;\n return segment;\n } else if (pathCommand === \"A\") {\n return [\"C\" as string | number].concat(\n arcToCubic(\n px1,\n py1,\n values[0],\n values[1],\n values[2],\n values[3],\n values[4],\n values[5],\n values[6],\n ),\n ) as CSegment;\n } else if (pathCommand === \"Q\") {\n params.qx = x;\n params.qy = y;\n return [\"C\" as string | number].concat(\n quadToCubic(px1, py1, values[0], values[1], values[2], values[3]),\n ) as CSegment;\n } else if (pathCommand === \"L\") {\n return [\"C\" as string | number].concat(lineToCubic(px1, py1, x, y)) as CSegment;\n } else if (pathCommand === \"Z\") {\n return [\"C\" as string | number].concat(lineToCubic(px1, py1, params.mx, params.my)) as CSegment;\n }\n\n return segment;\n};\n","import type { ParserParams } from \"../interface.ts\";\nimport type {\n ASegment,\n CSegment,\n LSegment,\n MSegment,\n NormalSegment,\n PathCommand,\n PathSegment,\n QSegment,\n} from \"../types.ts\";\n\n/**\n * Normalizes a single segment of a `pathArray` object.\n *\n * @param segment the segment object\n * @param params the normalization parameters\n * @param prevCommand the command of the previous segment\n * @returns the normalized segment\n */\nexport const normalizeSegment = (\n segment: PathSegment,\n params: ParserParams,\n prevCommand?: PathCommand | null,\n): NormalSegment => {\n const [pathCommand] = segment;\n const absCommand = pathCommand.toUpperCase();\n const isRelative = pathCommand !== absCommand;\n const { x, y } = params;\n\n if (!\"TQ\".includes(absCommand)) {\n // optional but good to be cautious\n params.qx = null;\n params.qy = null;\n }\n\n // the absolute value of a parameter of the segment: the x and the y\n // parameters alternate\n const absolute = (index: number): number => {\n const value = segment[index] as number;\n if (!isRelative) return value;\n return index % 2 === 1 ? value + x : value + y;\n };\n\n // istanbul ignore else\n if (absCommand === \"A\") {\n // the parameters of an arc that are not points are not offset, only its\n // end point is\n return [\n \"A\",\n segment[1],\n segment[2],\n segment[3],\n segment[4],\n segment[5],\n (segment[6] as number) + (isRelative ? x : 0),\n (segment[7] as number) + (isRelative ? y : 0),\n ] as ASegment;\n } else if (absCommand === \"H\") {\n return [\"L\", absolute(1), y] as LSegment;\n } else if (absCommand === \"V\") {\n // the only parameter of a vertical line is a y coordinate\n return [\"L\", x, (segment[1] as number) + (isRelative ? y : 0)] as LSegment;\n } else if (absCommand === \"L\") {\n return [\"L\", absolute(1), absolute(2)] as LSegment;\n } else if (absCommand === \"M\") {\n return [\"M\", absolute(1), absolute(2)] as MSegment;\n } else if (absCommand === \"C\") {\n return [\n \"C\",\n absolute(1),\n absolute(2),\n absolute(3),\n absolute(4),\n absolute(5),\n absolute(6),\n ] as CSegment;\n } else if (absCommand === \"S\") {\n // the control point is only reflected when the previous segment\n // is a cubic, otherwise it coincides with the current point\n const canReflect = prevCommand != null && \"CS\".includes(prevCommand);\n const x1 = canReflect && params.x2 != null ? x * 2 - params.x2 : x;\n const y1 = canReflect && params.y2 != null ? y * 2 - params.y2 : y;\n return [\"C\", x1, y1, absolute(1), absolute(2), absolute(3), absolute(4)] as CSegment;\n } else if (absCommand === \"T\") {\n // keep null check #64\n const qx = params.qx != null ? x * 2 - params.qx : x;\n const qy = params.qy != null ? y * 2 - params.qy : y;\n params.qx = qx;\n params.qy = qy;\n return [\"Q\", qx, qy, absolute(1), absolute(2)] as QSegment;\n } else if (absCommand === \"Q\") {\n const nqx = absolute(1);\n const nqy = absolute(2);\n params.qx = nqx;\n params.qy = nqy;\n return [\"Q\", nqx, nqy, absolute(3), absolute(4)] as QSegment;\n } else if (absCommand === \"Z\") {\n return [\"Z\"] as NormalSegment;\n }\n\n // istanbul ignore next\n return segment as NormalSegment;\n};\n","import type { ParserParams } from \"../interface.ts\";\n\n/**\n * Default parser parameters object used to track position state\n * while iterating through path segments.\n */\nexport const paramsParser: ParserParams = {\n mx: 0,\n my: 0,\n x1: 0,\n y1: 0,\n x2: null,\n y2: null,\n x: 0,\n y: 0,\n qx: null,\n qy: null,\n};\n","import { segmentToCubic } from \"../process/segmentToCubic.ts\";\nimport type { AbsoluteCommand, CSegment, CurveArray, PathArray, PathCommand } from \"../types.ts\";\nimport { iterate } from \"../process/iterate.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { normalizeSegment } from \"../process/normalizeSegment.ts\";\nimport { paramsParser } from \"../parser/paramsParser.ts\";\n\n/**\n * Parses a path string or PathArray and returns a new one\n * in which all segments are converted to cubic-bezier.\n *\n * @param pathInput - The path string or PathArray\n * @returns The resulted CurveArray with all segments as cubic beziers\n *\n * @example\n * ```ts\n * pathToCurve('M10 50q15 -25 30 0')\n * // => [['M', 10, 50], ['C', 20, 33.3333, 30, 33.3333, 40, 50]]\n * ```\n */\nexport const pathToCurve = <T extends PathArray>(pathInput: string | T): CurveArray => {\n const params = { ...paramsParser };\n const path = parsePathString(pathInput);\n let prevCommand: PathCommand | null = null;\n // let mx = 0;\n // let my = 0;\n\n return iterate(path, (seg, index, lastX, lastY) => {\n params.x = lastX;\n params.y = lastY;\n const normalSegment = normalizeSegment(seg, params, prevCommand);\n if (normalSegment[0] === \"M\") {\n params.mx = normalSegment[1];\n params.my = normalSegment[2];\n }\n let result = segmentToCubic(normalSegment, params);\n const isLongArc = result[0] === \"C\" && result.length > 7;\n\n if (isLongArc) {\n // an arc of more than 120 degrees is converted to more than one cubic\n // segment, the first one stays in place and the rest are inserted\n // after it, one segment each\n const values = result as unknown as (number | AbsoluteCommand)[];\n const segments: CSegment[] = [];\n for (let i = 7; i < values.length; i += 6) {\n segments.push([\"C\" as AbsoluteCommand | number].concat(values.slice(i, i + 6)) as CSegment);\n }\n path.splice(index + 1, 0, ...segments);\n result = values.slice(0, 7) as CSegment;\n }\n\n const seglen = result.length;\n params.x1 = +result[seglen - 2];\n params.y1 = +result[seglen - 1];\n // only cubic segments carry a reflectable control point, quadratics\n // are converted to cubics, so their control point is not reflectable\n if (normalSegment[0] === \"C\") {\n params.x2 = +result[seglen - 4];\n params.y2 = +result[seglen - 3];\n } else {\n params.x2 = null;\n params.y2 = null;\n }\n prevCommand = normalSegment[0];\n\n return result;\n }) as CurveArray;\n};\n","import type { Options } from \"../interface.ts\";\n\n/** SVGPathCommander default options */\nexport const defaultOptions: Options = {\n origin: [0, 0, 0],\n round: 4,\n};\n","import type { PathArray } from \"../types.ts\";\nimport { defaultOptions } from \"../options/options.ts\";\n\n/**\n * Returns a valid `d` attribute string value created\n * by rounding values and concatenating the PathArray segments.\n *\n * @param path - The PathArray object\n * @param roundOption - Amount of decimals to round values to, or \"off\"\n * @returns The concatenated path string\n *\n * @example\n * ```ts\n * pathToString([['M', 10, 10], ['L', 90, 90]], 2)\n * // => 'M10 10L90 90'\n * ```\n */\nexport const pathToString = <T extends PathArray>(\n path: T,\n roundOption?: number | \"off\",\n): string => {\n const pathLen = path.length;\n let { round } = defaultOptions;\n let segment = path[0] as PathArray[number];\n let result = \"\";\n\n // allow for ZERO decimals\n round =\n roundOption === \"off\"\n ? roundOption\n : typeof roundOption === \"number\" && roundOption >= 0\n ? roundOption\n : typeof round === \"number\" && round >= 0\n ? round\n : \"off\";\n\n const pow = round === \"off\" ? 0 : 10 ** round;\n\n for (let i = 0; i < pathLen; i += 1) {\n segment = path[i];\n const pathCommand = segment[0] as string;\n const segLen = segment.length;\n result += pathCommand;\n if (round === \"off\") {\n for (let j = 1; j < segLen; j += 1) {\n result += segment[j] as number;\n if (j !== segLen - 1) result += \" \";\n }\n } else {\n for (let j = 1; j < segLen; j += 1) {\n result += Math.round((segment[j] as number) * pow) / pow;\n if (j !== segLen - 1) result += \" \";\n }\n }\n }\n\n return result;\n};\n","import { iterate } from \"../process/iterate.ts\";\nimport type { PathBBox } from \"../interface.ts\";\nimport type { LSegment, MSegment, PathArray } from \"../types.ts\";\nimport { getLineBBox } from \"../math/lineTools.ts\";\nimport { getArcBBox } from \"../math/arcTools.ts\";\nimport { getCubicBBox } from \"../math/cubicTools.ts\";\nimport { getQuadBBox } from \"../math/quadTools.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { absolutizeSegment } from \"../process/absolutizeSegment.ts\";\n\n/**\n * The bounding box of an empty path.\n */\nconst emptyBBox = {\n x: 0,\n y: 0,\n width: 0,\n height: 0,\n x2: 0,\n y2: 0,\n cx: 0,\n cy: 0,\n cz: 0,\n};\n\n/**\n * Calculates the bounding box of a path.\n *\n * @param pathInput - The path string or PathArray\n * @returns An object with width, height, x, y, x2, y2, cx, cy, cz properties\n *\n * @example\n * ```ts\n * getPathBBox('M0 0L100 0L100 100L0 100Z')\n * // => { x: 0, y: 0, width: 100, height: 100, x2: 100, y2: 100, cx: 50, cy: 50, cz: 150 }\n * ```\n */\nexport const getPathBBox = <T extends PathArray>(\n pathInput: T | string,\n): {\n x: number;\n y: number;\n width: number;\n height: number;\n x2: number;\n y2: number;\n cx: number;\n cy: number;\n cz: number;\n} => {\n if (!pathInput) {\n return { ...emptyBBox };\n }\n\n const path = parsePathString(pathInput);\n\n // an empty path has no bounds, but it still needs a usable result\n if (!path.length) {\n return { ...emptyBBox };\n }\n\n let pathCommand = \"M\";\n let mx = 0;\n let my = 0;\n const { max, min } = Math;\n let xMin = Infinity;\n let yMin = Infinity;\n let xMax = -Infinity;\n let yMax = -Infinity;\n let minX = 0;\n let minY = 0;\n let maxX = 0;\n let maxY = 0;\n let paramX1 = 0;\n let paramY1 = 0;\n let paramX2 = 0;\n let paramY2 = 0;\n // keep null check #64\n let paramQX: number | null = null;\n let paramQY: number | null = null;\n\n iterate(path, (seg, index, lastX, lastY) => {\n [pathCommand] = seg;\n const commandCode = pathCommand.charCodeAt(0);\n const isRelative = commandCode >= 97; // a-z\n const absCommand = (\n isRelative ? String.fromCharCode(commandCode - 32) : pathCommand\n ) as typeof pathCommand;\n const absoluteSegment = isRelative ? absolutizeSegment(seg, index, lastX, lastY) : seg;\n\n const normalSegment =\n absCommand === \"V\"\n ? ([\"L\", lastX, absoluteSegment[1]] as LSegment)\n : absCommand === \"H\"\n ? ([\"L\", absoluteSegment[1], lastY] as LSegment)\n : absoluteSegment;\n\n [pathCommand] = normalSegment;\n\n if (absCommand !== \"T\" && absCommand !== \"Q\") {\n // keep null check #64\n paramQX = null;\n paramQY = null;\n }\n\n // this segment is always ZERO\n /* istanbul ignore else */\n if (pathCommand === \"M\") {\n [, mx, my] = normalSegment as MSegment;\n minX = mx;\n minY = my;\n maxX = mx;\n maxY = my;\n } else if (pathCommand === \"L\") {\n [minX, minY, maxX, maxY] = getLineBBox(\n lastX,\n lastY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n );\n } else if (pathCommand === \"A\") {\n [minX, minY, maxX, maxY] = getArcBBox(\n lastX,\n lastY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n normalSegment[3] as number,\n normalSegment[4] as number,\n normalSegment[5] as number,\n normalSegment[6] as number,\n normalSegment[7] as number,\n );\n } else if (pathCommand === \"S\") {\n const cp1x = paramX1 * 2 - paramX2;\n const cp1y = paramY1 * 2 - paramY2;\n\n [minX, minY, maxX, maxY] = getCubicBBox(\n lastX,\n lastY,\n cp1x,\n cp1y,\n normalSegment[1] as number,\n normalSegment[2] as number,\n normalSegment[3] as number,\n normalSegment[4] as number,\n );\n } else if (pathCommand === \"C\") {\n [minX, minY, maxX, maxY] = getCubicBBox(\n lastX,\n lastY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n normalSegment[3] as number,\n normalSegment[4] as number,\n normalSegment[5] as number,\n normalSegment[6] as number,\n );\n } else if (pathCommand === \"T\") {\n // keep null check #64\n paramQX = paramQX === null ? lastX : paramX1 * 2 - paramQX;\n paramQY = paramQY === null ? lastY : paramY1 * 2 - paramQY;\n [minX, minY, maxX, maxY] = getQuadBBox(\n lastX,\n lastY,\n paramQX,\n paramQY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n );\n } else if (pathCommand === \"Q\") {\n paramQX = normalSegment[1] as number;\n paramQY = normalSegment[2] as number;\n [minX, minY, maxX, maxY] = getQuadBBox(\n lastX,\n lastY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n normalSegment[3] as number,\n normalSegment[4] as number,\n );\n } else if (pathCommand === \"Z\") {\n [minX, minY, maxX, maxY] = getLineBBox(lastX, lastY, mx, my);\n }\n xMin = min(minX, xMin);\n yMin = min(minY, yMin);\n xMax = max(maxX, xMax);\n yMax = max(maxY, yMax);\n\n // update params\n if (pathCommand === \"Z\") {\n paramX1 = mx;\n paramY1 = my;\n } else {\n const segLen = normalSegment.length;\n paramX1 = normalSegment[segLen - 2] as number;\n paramY1 = normalSegment[segLen - 1] as number;\n }\n if (pathCommand === \"C\") {\n paramX2 = normalSegment[3] as number;\n paramY2 = normalSegment[4] as number;\n } else if (pathCommand === \"S\") {\n paramX2 = normalSegment[1] as number;\n paramY2 = normalSegment[2] as number;\n } else {\n paramX2 = paramX1;\n paramY2 = paramY1;\n }\n });\n\n const width = xMax - xMin;\n const height = yMax - yMin;\n\n return {\n width,\n height,\n x: xMin,\n y: yMin,\n x2: xMax,\n y2: yMax,\n cx: xMin + width / 2,\n cy: yMin + height / 2,\n // an estimated guess\n cz: Math.max(width, height) + Math.min(width, height) / 2,\n } satisfies PathBBox;\n};\n","import type {\n CSegment,\n LSegment,\n NormalSegment,\n PathArray,\n PathSegment,\n QSegment,\n} from \"../types.ts\";\nimport { getLineLength } from \"../math/lineTools.ts\";\nimport { getArcLength } from \"../math/arcTools.ts\";\nimport { getCubicLength } from \"../math/cubicTools.ts\";\nimport { getQuadLength } from \"../math/quadTools.ts\";\nimport { iterate } from \"../process/iterate.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { absolutizeSegment } from \"../process/absolutizeSegment.ts\";\n\n/**\n * The measured properties of a single path segment.\n */\nexport type SegmentMeasure = {\n /** the original (non-normalized) segment */\n segment: PathSegment;\n /** the index of the segment in the path */\n index: number;\n /** the length of the segment itself */\n length: number;\n /** the accumulated length of all segments before this one */\n lengthAtSegment: number;\n /** the absolute X coordinate the segment starts at */\n startX: number;\n /** the absolute Y coordinate the segment starts at */\n startY: number;\n /** the absolute X coordinate the segment ends at */\n endX: number;\n /** the absolute Y coordinate the segment ends at */\n endY: number;\n /** the absolute segment, with the shorthand commands expanded */\n geometry: NormalSegment;\n};\n\n/**\n * Measures every segment of a path in a single pass.\n *\n * This is the one source of truth for the length math: it absolutises relative\n * segments, rewrites `H`/`V` to `L` and carries the reflectable control-point\n * state for `S`/`T`, exactly like `getTotalLength` does. Every consumer that\n * needs per-segment lengths reads them from here so they cannot disagree with\n * each other.\n *\n * @param pathInput - the target path string or `PathArray`\n * @returns the measured segments, in path order\n */\nexport const measureSegments = (pathInput: string | PathArray): SegmentMeasure[] => {\n const path = parsePathString(pathInput);\n const measures: SegmentMeasure[] = [];\n let paramX1 = 0;\n let paramY1 = 0;\n let paramX2 = 0;\n let paramY2 = 0;\n // keep null check #64\n let paramQX: number | null = null;\n let paramQY: number | null = null;\n let pathCommand = \"M\";\n let mx = 0;\n let my = 0;\n let totalLength = 0;\n\n iterate(path, (seg, index, lastX, lastY) => {\n pathCommand = seg[0] as string;\n const absCommand = pathCommand.toUpperCase();\n const isRelative = absCommand !== pathCommand;\n const absoluteSegment = isRelative\n ? absolutizeSegment(seg, index, lastX, lastY)\n : (seg as typeof seg);\n\n const normalSegment =\n absCommand === \"V\"\n ? ([\"L\", lastX, absoluteSegment[1]] as LSegment)\n : absCommand === \"H\"\n ? ([\"L\", absoluteSegment[1], lastY] as LSegment)\n : absoluteSegment;\n pathCommand = normalSegment[0] as string;\n\n if (!\"TQ\".includes(absCommand)) {\n // keep null check #64\n paramQX = null;\n paramQY = null;\n }\n\n let length = 0;\n // the absolute segment, with the shorthand commands expanded: the\n // reflected control point of an `S` or a `T` is resolved here, so the\n // geometry and the length of a segment always agree\n let geometry = normalSegment as NormalSegment;\n\n // this segment is always ZERO\n /* istanbul ignore else */\n if (pathCommand === \"M\") {\n // remember mx, my for Z\n mx = normalSegment[1] as number;\n my = normalSegment[2] as number;\n } else if (pathCommand === \"L\") {\n length = getLineLength(lastX, lastY, normalSegment[1] as number, normalSegment[2] as number);\n } else if (pathCommand === \"A\") {\n length = getArcLength(\n lastX,\n lastY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n normalSegment[3] as number,\n normalSegment[4] as number,\n normalSegment[5] as number,\n normalSegment[6] as number,\n normalSegment[7] as number,\n );\n } else if (pathCommand === \"S\") {\n const cp1x = paramX1 * 2 - paramX2;\n const cp1y = paramY1 * 2 - paramY2;\n\n geometry = [\n \"C\",\n cp1x,\n cp1y,\n normalSegment[1] as number,\n normalSegment[2] as number,\n normalSegment[3] as number,\n normalSegment[4] as number,\n ] as CSegment;\n length = getCubicLength(\n lastX,\n lastY,\n cp1x,\n cp1y,\n normalSegment[1] as number,\n normalSegment[2] as number,\n normalSegment[3] as number,\n normalSegment[4] as number,\n );\n } else if (pathCommand === \"C\") {\n length = getCubicLength(\n lastX,\n lastY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n normalSegment[3] as number,\n normalSegment[4] as number,\n normalSegment[5] as number,\n normalSegment[6] as number,\n );\n } else if (pathCommand === \"T\") {\n // keep null check #64\n paramQX = paramQX === null ? lastX : paramX1 * 2 - paramQX;\n paramQY = paramQY === null ? lastY : paramY1 * 2 - paramQY;\n geometry = [\n \"Q\",\n paramQX,\n paramQY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n ] as QSegment;\n length = getQuadLength(\n lastX,\n lastY,\n paramQX,\n paramQY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n );\n } else if (pathCommand === \"Q\") {\n paramQX = normalSegment[1] as number;\n paramQY = normalSegment[2] as number;\n length = getQuadLength(\n lastX,\n lastY,\n normalSegment[1] as number,\n normalSegment[2] as number,\n normalSegment[3] as number,\n normalSegment[4] as number,\n );\n } else if (pathCommand === \"Z\") {\n length = getLineLength(lastX, lastY, mx, my);\n }\n\n // the close segment returns to the start of the sub-path\n const endX = pathCommand === \"Z\" ? mx : (geometry[geometry.length - 2] as number);\n const endY = pathCommand === \"Z\" ? my : (geometry[geometry.length - 1] as number);\n\n measures.push({\n segment: seg,\n index,\n length,\n lengthAtSegment: totalLength,\n startX: lastX,\n startY: lastY,\n endX,\n endY,\n geometry,\n });\n totalLength += length;\n\n // update params\n if (pathCommand === \"Z\") {\n paramX1 = mx;\n paramY1 = my;\n } else {\n paramX1 = normalSegment[normalSegment.length - 2] as number;\n paramY1 = normalSegment[normalSegment.length - 1] as number;\n }\n if (pathCommand === \"C\") {\n paramX2 = normalSegment[3] as number;\n paramY2 = normalSegment[4] as number;\n } else if (pathCommand === \"S\") {\n paramX2 = normalSegment[1] as number;\n paramY2 = normalSegment[2] as number;\n } else {\n paramX2 = paramX1;\n paramY2 = paramY1;\n }\n });\n\n return measures;\n};\n","import type { PathArray } from \"../types.ts\";\nimport { measureSegments } from \"./measureSegments.ts\";\n\n/**\n * Returns the total length of a path, equivalent to `shape.getTotalLength()`.\n *\n * @param pathInput - The target path string or PathArray\n * @returns the total length of the path\n *\n * @example\n * ```ts\n * getTotalLength('M0 0L100 0L100 100L0 100Z')\n * // => 400\n * ```\n */\nexport const getTotalLength = <T extends PathArray>(pathInput: string | T): number => {\n const measures = measureSegments(pathInput);\n const last = measures[measures.length - 1];\n return last ? last.lengthAtSegment + last.length : 0;\n};\n","/** Small threshold value used for floating-point distance comparisons in path calculations. */\nconst DISTANCE_EPSILON = 0.00001;\n\nexport default DISTANCE_EPSILON;\n","import type { NormalArray, PointTuple } from \"../types.ts\";\nimport type { SegmentMeasure } from \"./measureSegments.ts\";\nimport { getLineLength, getPointAtLineLength } from \"../math/lineTools.ts\";\nimport { getArcLength, getPointAtArcLength } from \"../math/arcTools.ts\";\nimport { getCubicLength, getPointAtCubicLength } from \"../math/cubicTools.ts\";\nimport { getPointAtQuadLength, getQuadLength } from \"../math/quadTools.ts\";\nimport DISTANCE_EPSILON from \"./distanceEpsilon.ts\";\n\n/**\n * The length table of a normalized path.\n *\n * The table holds the length of every segment and the length accumulated\n * before it, so a point at any distance can be found with a binary search\n * over the accumulated lengths instead of a walk over the whole path.\n */\nexport type PathLengthTable = {\n /** the measured segments, in path order */\n measures: SegmentMeasure[];\n /** the total length of the path */\n totalLength: number;\n /** the X coordinate the path starts at */\n startX: number;\n /** the Y coordinate the path starts at */\n startY: number;\n /** whether the path is a loop, so it ends where it starts */\n isLoop: boolean;\n};\n\n/**\n * Measures every segment of a normalized path in a single pass.\n *\n * A normalized path holds absolute `M`, `L`, `C`, `Q`, `A` and `Z` segments\n * only, so no relative offsets and no shorthand control point reflections\n * have to be resolved here — the length of a segment is exactly the length\n * the point lookup at that distance will use.\n *\n * @param path - the normalized path to measure\n * @returns the length table of the path\n */\nexport const buildPathLengthTable = (path: NormalArray): PathLengthTable => {\n const measures: SegmentMeasure[] = [];\n let x = 0;\n let y = 0;\n let mx = 0;\n let my = 0;\n let totalLength = 0;\n let movetoCount = 0;\n\n for (const [index, segment] of path.entries()) {\n const command = segment[0];\n const measure: SegmentMeasure = {\n segment,\n index,\n startX: x,\n startY: y,\n endX: x,\n endY: y,\n length: 0,\n lengthAtSegment: totalLength,\n geometry: segment,\n };\n\n // a normalized path holds no other command than the ones handled here\n /* istanbul ignore else */\n if (command === \"M\") {\n mx = segment[1] as number;\n my = segment[2] as number;\n measure.endX = mx;\n measure.endY = my;\n movetoCount += 1;\n } else if (command === \"L\") {\n measure.endX = segment[1] as number;\n measure.endY = segment[2] as number;\n measure.length = getLineLength(x, y, measure.endX, measure.endY);\n } else if (command === \"C\") {\n measure.endX = segment[5] as number;\n measure.endY = segment[6] as number;\n measure.length = getCubicLength(\n x,\n y,\n segment[1] as number,\n segment[2] as number,\n segment[3] as number,\n segment[4] as number,\n measure.endX,\n measure.endY,\n );\n } else if (command === \"Q\") {\n measure.endX = segment[3] as number;\n measure.endY = segment[4] as number;\n measure.length = getQuadLength(\n x,\n y,\n segment[1] as number,\n segment[2] as number,\n measure.endX,\n measure.endY,\n );\n } else if (command === \"A\") {\n measure.endX = segment[6] as number;\n measure.endY = segment[7] as number;\n measure.length = getArcLength(\n x,\n y,\n segment[1] as number,\n segment[2] as number,\n segment[3] as number,\n segment[4] as number,\n segment[5] as number,\n measure.endX,\n measure.endY,\n );\n } else if (command === \"Z\") {\n // the segment closes back to the start of the sub-path\n measure.endX = mx;\n measure.endY = my;\n measure.length = getLineLength(x, y, mx, my);\n }\n\n measures.push(measure);\n totalLength += measure.length;\n x = measure.endX;\n y = measure.endY;\n }\n\n const [startX, startY] = (path[0]?.slice(1) ?? []) as PointTuple;\n const last = measures[measures.length - 1];\n // a path with a single sub-path that ends where it starts is a loop, so\n // the point before the start of the path is the point before its end\n const isLoop =\n movetoCount === 1 &&\n !!last &&\n Math.hypot(last.endX - startX, last.endY - startY) <= DISTANCE_EPSILON;\n\n return { measures, totalLength, startX, startY, isLoop };\n};\n\n/**\n * Builds the length table of a path from the shared measure pass.\n *\n * The measure pass resolves the relative offsets and the shorthand control\n * point reflections of a path and holds the length of every segment, so the\n * table can be built from it without measuring the path a second time. The\n * measures of the pass are the measures of the table: the geometry of a\n * measure is the normalized segment, so the table holds the same segments and\n * the same lengths as the one built from a normalized path.\n *\n * @param segmentMeasures - the measured segments of the path\n * @returns the length table of the path\n */\nexport const buildPathLengthTableFromMeasures = (\n segmentMeasures: SegmentMeasure[],\n): PathLengthTable => {\n let movetoCount = 0;\n\n for (const measure of segmentMeasures) {\n if (measure.geometry[0] === \"M\") movetoCount += 1;\n }\n\n const first = segmentMeasures[0];\n const last = segmentMeasures[segmentMeasures.length - 1];\n // the path starts at the point of its first moveto\n const startX = first?.endX ?? 0;\n const startY = first?.endY ?? 0;\n const totalLength = last ? last.lengthAtSegment + last.length : 0;\n // a path with a single sub-path that ends where it starts is a loop, so\n // the point before the start of the path is the point before its end\n const isLoop =\n movetoCount === 1 &&\n !!last &&\n Math.hypot(last.endX - startX, last.endY - startY) <= DISTANCE_EPSILON;\n\n return { measures: segmentMeasures, totalLength, startX, startY, isLoop };\n};\n\n/**\n * Returns the point of a measured path at a given distance.\n *\n * The segment is found with a binary search over the accumulated lengths:\n * it is the last segment whose accumulated length is still below the\n * distance, which is the same segment the linear walk over the path would\n * have stopped at.\n *\n * @param table - the length table of the path\n * @param distance - the distance along the path\n * @returns the requested {x, y} point coordinates\n */\nexport const getPointAtTable = (\n table: PathLengthTable,\n distance?: number,\n): { x: number; y: number } => {\n const { measures, startX, startY } = table;\n\n // an empty path has no point to return\n if (!measures.length) return { x: 0, y: 0 };\n\n // a missing, a negative or a not-a-number distance has no point to look\n // for, the path starts there\n if (typeof distance !== \"number\" || Number.isNaN(distance) || distance < DISTANCE_EPSILON) {\n return { x: startX, y: startY };\n }\n\n // the last segment whose accumulated length is below the distance\n let low = 0;\n let high = measures.length - 1;\n while (low < high) {\n const mid = (low + high + 1) >> 1;\n if (measures[mid].lengthAtSegment < distance) {\n low = mid;\n } else {\n high = mid - 1;\n }\n }\n\n const measure = measures[low];\n const { geometry: segment, startX: x1, startY: y1, endX, endY } = measure;\n const command = segment[0];\n // the distance within the segment\n const offset = distance - measure.lengthAtSegment;\n\n // a normalized path holds no other command than the ones handled here\n /* istanbul ignore else */\n if (command === \"M\") {\n return { x: endX, y: endY };\n }\n if (command === \"L\") {\n return getPointAtLineLength(x1, y1, endX, endY, offset);\n }\n if (command === \"C\") {\n return getPointAtCubicLength(\n x1,\n y1,\n segment[1] as number,\n segment[2] as number,\n segment[3] as number,\n segment[4] as number,\n endX,\n endY,\n offset,\n );\n }\n if (command === \"Q\") {\n return getPointAtQuadLength(\n x1,\n y1,\n segment[1] as number,\n segment[2] as number,\n endX,\n endY,\n offset,\n );\n }\n if (command === \"A\") {\n return getPointAtArcLength(\n x1,\n y1,\n segment[1] as number,\n segment[2] as number,\n segment[3] as number,\n segment[4] as number,\n segment[5] as number,\n endX,\n endY,\n offset,\n );\n }\n // the close segment returns to the start of the sub-path\n return getPointAtLineLength(x1, y1, endX, endY, offset);\n};\n","import type { CubicCoordinates, NormalSegment, Point, QuadCoordinates } from \"../types.ts\";\nimport {\n computeBezier,\n deriveBezier,\n getBezierPoints,\n getTAtBezierLength,\n} from \"../math/bezier.ts\";\nimport { getPointAtCubicSegmentLength } from \"../math/cubicTools.ts\";\nimport { getPointAtQuadSegmentLength } from \"../math/quadTools.ts\";\nimport { arcLengthBetween, getArcProps } from \"../math/arcTools.ts\";\n\n/**\n * The frame of a path at a given length: the point, the direction of the path\n * at that point (the tangent), the perpendicular to it (the normal) and the\n * angle of the tangent.\n */\nexport type PathFrame = {\n /** The point at the given length. */\n point: Point;\n /** The unit tangent vector at the given length. */\n tangent: Point;\n /** The unit normal vector at the given length, the left normal of the tangent. */\n normal: Point;\n /** The angle of the tangent at the given length, in degrees. */\n angle: number;\n};\n\n/**\n * Returns a value without a negative zero.\n *\n * The negative zero is a valid number, but it is a surprise in a result:\n * `Object.is(-0, 0)` is false, so a deep comparison of two equal frames\n * would fail.\n *\n * @param value the value to clean\n * @returns the value without a negative zero\n */\nexport const cleanZero = (value: number): number => (value === 0 ? 0 : value);\n\n/**\n * Returns the unit vector of a direction.\n *\n * A direction without a length has no unit vector, so the zero vector is\n * returned for it.\n *\n * @param x the X component of the direction\n * @param y the Y component of the direction\n * @returns the unit vector of the direction\n */\nconst normalizeVector = (x: number, y: number): Point => {\n const length = Math.sqrt(x * x + y * y);\n return length > 0 ? { x: cleanZero(x / length), y: cleanZero(y / length) } : { x: 0, y: 0 };\n};\n\n/**\n * Returns the frame of a point with a given direction.\n *\n * The normal is the left normal of the tangent, so it points to the left of\n * the direction of the path, and the angle is the angle of the tangent in\n * degrees, in the `-180` to `180` range.\n *\n * @param point the point of the frame\n * @param x the X component of the direction\n * @param y the Y component of the direction\n * @returns the frame of the point\n */\nconst frameFrom = (point: Point, x: number, y: number): PathFrame => {\n const tangent = normalizeVector(x, y);\n return {\n point: { x: cleanZero(point.x), y: cleanZero(point.y) },\n tangent,\n normal: { x: cleanZero(-tangent.y), y: cleanZero(tangent.x) },\n angle: (Math.atan2(tangent.y, tangent.x) * 180) / Math.PI,\n };\n};\n\n/**\n * Returns the frame of a line segment at a given distance.\n *\n * @param startX the X coordinate the segment starts at\n * @param startY the Y coordinate the segment starts at\n * @param endX the X coordinate the segment ends at\n * @param endY the Y coordinate the segment ends at\n * @param offset the distance from the start of the segment\n * @param length the length of the segment\n * @returns the frame of the segment\n */\nconst lineFrame = (\n startX: number,\n startY: number,\n endX: number,\n endY: number,\n offset: number,\n length: number,\n): PathFrame => {\n const dx = endX - startX;\n const dy = endY - startY;\n const ratio = length > 0 ? Math.min(Math.max(offset / length, 0), 1) : 0;\n return frameFrom({ x: startX + dx * ratio, y: startY + dy * ratio }, dx, dy);\n};\n\n/**\n * Returns the frame of a cubic Bezier segment at a given distance.\n *\n * The `t` ratio of the point is found once and shared with the tangent, so\n * the point and the frame always describe the very same spot on the curve.\n *\n * @param coords the coordinates of the segment\n * @param offset the distance from the start of the segment\n * @param length the length of the segment\n * @returns the frame of the segment\n */\nconst cubicFrame = (coords: CubicCoordinates, offset: number, length: number): PathFrame => {\n const t = offset <= 0 ? 0 : offset >= length ? 1 : getTAtBezierLength(coords, offset);\n const point = getPointAtCubicSegmentLength(coords, t);\n // the first derivative level holds the control points of the derivative\n const derivative = computeBezier(deriveBezier(getBezierPoints(coords))[0], t);\n return frameFrom(point, derivative.x, derivative.y);\n};\n\n/**\n * Returns the frame of a quadratic Bezier segment at a given distance.\n *\n * @param coords the coordinates of the segment\n * @param offset the distance from the start of the segment\n * @param length the length of the segment\n * @returns the frame of the segment\n */\nconst quadFrame = (coords: QuadCoordinates, offset: number, length: number): PathFrame => {\n const t = offset <= 0 ? 0 : offset >= length ? 1 : getTAtBezierLength(coords, offset);\n const point = getPointAtQuadSegmentLength(coords, t);\n const derivative = computeBezier(deriveBezier(getBezierPoints(coords))[0], t);\n return frameFrom(point, derivative.x, derivative.y);\n};\n\n/**\n * Returns the frame of an elliptical arc segment at a given distance.\n *\n * The parametric angle of the arc is found once and shared with the tangent,\n * which is the derivative of the ellipse at that angle.\n *\n * @param startX the X coordinate the segment starts at\n * @param startY the Y coordinate the segment starts at\n * @param RX the radius on X axis\n * @param RY the radius on Y axis\n * @param rotation the ellipse rotation in degrees\n * @param LAF the large arc flag\n * @param SF the sweep flag\n * @param endX the X coordinate the segment ends at\n * @param endY the Y coordinate the segment ends at\n * @param offset the distance from the start of the segment\n * @param length the length of the segment\n * @returns the frame of the segment\n */\nconst arcFrame = (\n startX: number,\n startY: number,\n RX: number,\n RY: number,\n rotation: number,\n LAF: number,\n SF: number,\n endX: number,\n endY: number,\n offset: number,\n length: number,\n): PathFrame => {\n const { center, rx, ry, startAngle, endAngle } = getArcProps(\n startX,\n startY,\n RX,\n RY,\n rotation,\n LAF,\n SF,\n endX,\n endY,\n );\n\n // a zero radius is treated as a straight line to the end point\n if (rx === 0 || ry === 0) {\n return lineFrame(startX, startY, endX, endY, offset, length);\n }\n\n const sweepAngle = endAngle - startAngle;\n const { PI, cos, sin } = Math;\n const xRot = ((rotation % 360) + 360) % 360;\n const xRotRad = xRot * (PI / 180);\n\n // the tangent of the ellipse at the parametric angle, before the rotation\n const tangentAt = (alpha: number): Point => {\n const cosA = cos(alpha);\n const sinA = sin(alpha);\n return {\n x: -cos(xRotRad) * rx * sinA - sin(xRotRad) * ry * cosA,\n y: -sin(xRotRad) * rx * sinA + cos(xRotRad) * ry * cosA,\n };\n };\n\n const pointAt = (alpha: number): Point => {\n const ellipseX = rx * cos(alpha);\n const ellipseY = ry * sin(alpha);\n return {\n x: cos(xRotRad) * ellipseX - sin(xRotRad) * ellipseY + center.x,\n y: sin(xRotRad) * ellipseX + cos(xRotRad) * ellipseY + center.y,\n };\n };\n\n // an arc without a sweep has no direction\n if (length <= 0) {\n return frameFrom({ x: startX, y: startY }, 0, 0);\n }\n\n // the arc is drawn in the direction of the sweep, so the tangent points\n // the other way when the sweep is negative\n const direction = sweepAngle < 0 ? -1 : 1;\n\n if (offset <= 0) {\n const tangent = tangentAt(startAngle);\n return frameFrom({ x: startX, y: startY }, direction * tangent.x, direction * tangent.y);\n }\n\n if (offset >= length) {\n const tangent = tangentAt(endAngle);\n return frameFrom({ x: endX, y: endY }, direction * tangent.x, direction * tangent.y);\n }\n\n // the parametric angle at the given distance, found by interval bisection\n let lo = 0;\n let hi = 1;\n for (let i = 0; i < 25; i += 1) {\n const mid = (lo + hi) / 2;\n if (Math.abs(arcLengthBetween(rx, ry, startAngle, startAngle + sweepAngle * mid)) < offset) {\n lo = mid;\n } else {\n hi = mid;\n }\n }\n const alpha = startAngle + sweepAngle * ((lo + hi) / 2);\n const tangent = tangentAt(alpha);\n return frameFrom(pointAt(alpha), direction * tangent.x, direction * tangent.y);\n};\n\n/**\n * Returns the frame of a path segment at a given distance.\n *\n * The segment has to be an absolute one, with the shorthand commands\n * expanded, so the geometry and the length of the segment agree.\n *\n * @param geometry the absolute segment\n * @param startX the X coordinate the segment starts at\n * @param startY the Y coordinate the segment starts at\n * @param endX the X coordinate the segment ends at\n * @param endY the Y coordinate the segment ends at\n * @param offset the distance from the start of the segment\n * @param length the length of the segment\n * @returns the frame of the segment\n */\nexport const getSegmentFrame = (\n geometry: NormalSegment,\n startX: number,\n startY: number,\n endX: number,\n endY: number,\n offset: number,\n length: number,\n): PathFrame => {\n const command = geometry[0];\n\n // a moveto has no direction, it only holds the start of a sub-path\n if (command === \"M\") {\n return frameFrom({ x: endX, y: endY }, 0, 0);\n }\n\n if (command === \"L\" || command === \"Z\") {\n return lineFrame(startX, startY, endX, endY, offset, length);\n }\n\n if (command === \"C\") {\n const coords = [\n startX,\n startY,\n geometry[1] as number,\n geometry[2] as number,\n geometry[3] as number,\n geometry[4] as number,\n endX,\n endY,\n ] as CubicCoordinates;\n return cubicFrame(coords, offset, length);\n }\n\n if (command === \"Q\") {\n const coords = [\n startX,\n startY,\n geometry[1] as number,\n geometry[2] as number,\n endX,\n endY,\n ] as QuadCoordinates;\n return quadFrame(coords, offset, length);\n }\n\n return arcFrame(\n startX,\n startY,\n geometry[1] as number,\n geometry[2] as number,\n geometry[3] as number,\n geometry[4] as number,\n geometry[5] as number,\n endX,\n endY,\n offset,\n length,\n );\n};\n","import type { PathArray, PathSegment } from \"../types.ts\";\nimport type { SegmentProperties } from \"../interface.ts\";\nimport type { SegmentMeasure } from \"./measureSegments.ts\";\nimport type { PathFrame } from \"./segmentFrame.ts\";\nimport { measureSegments } from \"./measureSegments.ts\";\nimport { getSegmentFrame } from \"./segmentFrame.ts\";\n\n/**\n * Returns the length of a measured segment.\n *\n * The length is taken from the accumulated lengths, the total up to the\n * segment minus the total before it, and not from the length the segment\n * was measured with: the two differ in the last bits, and this keeps the\n * result identical to the one the previous implementation returned.\n *\n * @param measure - the measured segment\n * @returns the length of the segment\n */\nconst segmentLength = (measure: SegmentMeasure): number =>\n measure.lengthAtSegment + measure.length - measure.lengthAtSegment;\n\n/**\n * Returns the frame of a measured segment at a given distance.\n *\n * @param measure - the measured segment\n * @param offset - the distance from the start of the segment\n * @returns the frame of the segment\n */\nconst frameOf = (measure: SegmentMeasure | undefined, offset = 0): PathFrame => {\n // an empty path has no frame, but the result still has to be well formed\n if (!measure) {\n return {\n point: { x: 0, y: 0 },\n tangent: { x: 0, y: 0 },\n normal: { x: 0, y: 0 },\n angle: 0,\n };\n }\n return getSegmentFrame(\n measure.geometry,\n measure.startX,\n measure.startY,\n measure.endX,\n measure.endY,\n offset,\n measure.length,\n );\n};\n\nexport const getPropertiesFromMeasure = (\n measure: SegmentMeasure,\n offset: number,\n): SegmentProperties => ({\n segment: measure.segment,\n index: measure.index,\n length: segmentLength(measure),\n lengthAtSegment: measure.lengthAtSegment,\n ...frameOf(measure, offset),\n});\n\n/**\n * Returns the segment, its index and length as well as\n * the length to that segment at a given length in a path.\n *\n * The point at the given length is returned with the frame of the path at\n * that point: the unit tangent vector, the unit normal vector and the angle\n * of the tangent in degrees.\n *\n * @param measures - the measured segments of the path\n * @param distance - the given length\n * @returns the requested properties\n */\nexport const getPropertiesFromMeasures = (\n measures: SegmentMeasure[],\n distance?: number,\n): SegmentProperties => {\n const lastIndex = measures.length - 1;\n\n // an empty path has no segment, but the result still has to be well formed\n const segment = (measures[0]?.segment ?? [\"M\", 0, 0]) as PathSegment;\n\n // If the path is empty, return 0.\n // an infinite distance is not an error, it is out of range and clamps\n // to the last segment like any other out of range distance\n if (lastIndex <= 0 || !distance || distance < 0) {\n return {\n segment,\n index: 0,\n length: 0,\n lengthAtSegment: 0,\n ...frameOf(measures[0]),\n };\n }\n\n const last = measures[lastIndex];\n const pathLength = last.lengthAtSegment + last.length;\n\n if (distance >= pathLength) {\n return {\n segment: last.segment,\n index: last.index,\n length: segmentLength(last),\n lengthAtSegment: last.lengthAtSegment,\n ...frameOf(last, distance - last.lengthAtSegment),\n };\n }\n\n // the segment is the last one whose accumulated length does not exceed\n // the distance, a zero length segment wins over the one before it\n // the first drawable segment always starts at the length zero, so it is\n // the fallback when no later segment matches\n let index = 1;\n for (let i = lastIndex; i > 0; i--) {\n if (measures[i].lengthAtSegment <= distance) {\n index = i;\n break;\n }\n }\n\n const measure = measures[index];\n return {\n segment: measure.segment,\n index: measure.index,\n length: segmentLength(measure),\n lengthAtSegment: measure.lengthAtSegment,\n ...frameOf(measure, distance - measure.lengthAtSegment),\n };\n};\n\n/**\n * Returns the segment, its index and length as well as\n * the length to that segment at a given length in a path.\n *\n * The point at the given length is returned with the frame of the path at\n * that point: the unit tangent vector, the unit normal vector and the angle\n * of the tangent in degrees.\n *\n * @param pathInput target `pathArray`\n * @param distance the given length\n * @returns the requested properties\n */\nexport const getPropertiesAtLength = <T extends PathArray>(\n pathInput: string | T,\n distance?: number,\n): SegmentProperties => {\n // one pass over the path, the measure table holds the length of every\n // segment and the length accumulated before it\n return getPropertiesFromMeasures(measureSegments(pathInput), distance);\n};\n","import type { PathArray, Point } from \"../types.ts\";\nimport type { PointProperties } from \"../interface.ts\";\nimport type { SegmentMeasure } from \"./measureSegments.ts\";\nimport { buildPathLengthTableFromMeasures, getPointAtTable } from \"./pathLengthTable.ts\";\nimport { getPropertiesFromMeasure } from \"./getPropertiesAtLength.ts\";\nimport { measureSegments } from \"./measureSegments.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\n\n/**\n * The relative difference below which two distances are the same.\n *\n * The distance of a point to a path is squared, so the noise of the floating\n * point arithmetic is relative to the distance itself. A path that runs at\n * a constant distance from the point — a circle around it — has no minimum at\n * all, and the noise of the samples must not be read as one.\n */\nconst distanceEpsilon = 1e-7;\n\n/**\n * The precision of the refinement of the closest point.\n *\n * The precision is relative to the length of the path: a path of a few units\n * needs a finer precision than a path of thousands of units, and the answer\n * of a short path is expected to be as exact as the answer of a long one. The\n * relative floor is capped, so a very long path does not trade the accuracy\n * of its distance for a path-relative length precision.\n */\nconst precisionShare = 1e-9;\nconst maxPrecisionFloor = 1e-6;\n\n/**\n * The number of samples of the coarse scan of a short path.\n *\n * The scan of the path is spread over its length, so a short path is sampled\n * more densely than a long one: the place where the path passes closest to\n * the point must not fall between two samples of the scan.\n */\nconst minSamples = 64;\n\n/**\n * The maximum number of samples of the coarse scan of a path.\n *\n * The scan is dense enough to find the place where the path passes closest\n * to the point, but it stays bounded for a long path: the length of the path\n * is divided into this many intervals at most.\n */\nconst maxSamples = 4096;\n\n/**\n * The step of the coarse scan of a long path, in units of length.\n */\nconst maxScanStep = 8;\n\n/**\n * Finds the index of the segment a distance falls into.\n *\n * The segment is the last one whose accumulated length is below the\n * distance, the same segment the lookup of a point at that distance uses.\n *\n * @param measures - the measured segments of the path\n * @param distance - the distance along the path\n * @returns the index of the segment\n */\nconst findSegmentIndex = (measures: SegmentMeasure[], distance: number): number => {\n if (distance <= 0) return 0;\n\n let low = 0;\n let high = measures.length - 1;\n while (low < high) {\n const mid = (low + high + 1) >> 1;\n if (measures[mid].lengthAtSegment <= distance) {\n low = mid;\n } else {\n high = mid - 1;\n }\n }\n return low;\n};\n\n/**\n * Returns the closest point of a straight segment.\n *\n * The projection of the point on the line of the segment is the closest\n * point of the segment when it falls on the segment, and the closest end of\n * the segment when it does not. The projection is computed along the direction\n * of the segment, so a point that is on the segment is answered with itself.\n *\n * @param point - the point to project\n * @param startX - the X coordinate of the start of the segment\n * @param startY - the Y coordinate of the start of the segment\n * @param endX - the X coordinate of the end of the segment\n * @param endY - the Y coordinate of the end of the segment\n * @returns the closest point of the segment and its position on the segment\n */\nconst projectOnSegment = (\n point: Point,\n startX: number,\n startY: number,\n endX: number,\n endY: number,\n): { point: Point; ratio: number } => {\n const dx = endX - startX;\n const dy = endY - startY;\n const length = Math.hypot(dx, dy);\n // a segment without a length is a point\n /* istanbul ignore next */\n if (!length) return { point: { x: startX, y: startY }, ratio: 0 };\n\n // the projection has to be on the segment\n const ratio = ((point.x - startX) * dx + (point.y - startY) * dy) / (length * length);\n const clamped = Math.max(0, Math.min(1, ratio));\n return {\n point: { x: startX + dx * clamped, y: startY + dy * clamped },\n ratio: clamped,\n };\n};\n\n/**\n * Returns the point and segment in path closest to a given point as well as\n * the distance to the path stroke.\n *\n * @see https://bl.ocks.org/mbostock/8027637\n *\n * @param pathInput target `pathArray`\n * @param point the given point\n * @returns the requested properties\n */\nexport const getPropertiesAtPoint = <T extends PathArray>(\n pathInput: string | T,\n point: Point,\n): PointProperties => {\n const path = parsePathString(pathInput);\n // an empty path has no closest point\n if (!path.length) {\n return { closest: { x: 0, y: 0 }, distance: Infinity };\n }\n // one pass over the path, the measure table holds the length of every\n // segment and the length accumulated before it\n const segmentMeasures = measureSegments(path);\n const table = buildPathLengthTableFromMeasures(segmentMeasures);\n const pathLength = table.totalLength;\n // a loop ends where it starts, so the search can walk over the end of the\n // path and find the other side of the join\n const isLoop = table.isLoop;\n const distanceTo = (p: Point) => {\n const dx = p.x - point.x;\n const dy = p.y - point.y;\n return dx * dx + dy * dy;\n };\n // the step of the coarse scan, in units of length: a path that is shorter\n // than the step would be sampled at its ends only, so the step is a share\n // of the length of the path — a short path is sampled more densely, so the\n // place where the path passes closest to the point is not missed. The step\n // grows again for a very long path, so the number of samples stays bounded\n const scanStep = pathLength\n ? Math.max(pathLength / maxSamples, Math.min(maxScanStep, pathLength / minSamples))\n : maxScanStep;\n // the local minima of the scanned distance are the places where the path\n // passes near the point: a path can pass near it more than once — a closed\n // sub-path returns to its own start, so the point is sampled twice — and\n // every one of those places has to be searched\n const candidates: { length: number; distance: number; point: Point }[] = [];\n let bestLength = 0;\n let bestDistance = Infinity;\n let bestPoint: Point = { x: 0, y: 0 };\n let previousDistance = Infinity;\n let lastLength = 0;\n let lastDistance = Infinity;\n let lastPoint: Point = { x: 0, y: 0 };\n let lastScannedLength = -1;\n\n // the scan of the path: every sample is a point of the path, and the\n // distance to the point is measured\n const scan = (scanLength: number) => {\n if (scanLength <= lastScannedLength) return;\n lastScannedLength = scanLength;\n const scanPoint = getPointAtTable(table, scanLength);\n const scanDistance = distanceTo(scanPoint);\n\n // the last sample is a local minimum when the distance starts to grow\n // and it was not growing before it\n if (\n lastDistance < scanDistance - scanDistance * distanceEpsilon &&\n lastDistance <= previousDistance + previousDistance * distanceEpsilon\n ) {\n candidates.push({\n length: lastLength,\n distance: lastDistance,\n point: lastPoint,\n });\n }\n\n previousDistance = lastDistance;\n lastLength = scanLength;\n lastDistance = scanDistance;\n lastPoint = scanPoint;\n\n if (scanDistance < bestDistance) {\n bestLength = scanLength;\n bestDistance = scanDistance;\n bestPoint = scanPoint;\n }\n };\n\n // every segment is scanned on its own, so a short segment between two long\n // ones cannot fall between two samples of a scan of the whole path\n for (const measure of segmentMeasures) {\n const segmentStart = measure.lengthAtSegment;\n const segmentEnd = segmentStart + measure.length;\n for (let scanLength = segmentStart; scanLength < segmentEnd; scanLength += scanStep) {\n scan(scanLength);\n }\n scan(segmentEnd);\n }\n\n // the path can end with a minimum too\n if (lastDistance < previousDistance - previousDistance * distanceEpsilon) {\n candidates.push({\n length: lastLength,\n distance: lastDistance,\n point: lastPoint,\n });\n }\n\n // the binary search for the precise estimate, around one length\n const refine = (start: { length: number; distance: number; point: Point }) => {\n let { length, distance } = start;\n let closest = start.point;\n let precision = scanStep / 2;\n let beforeLength = 0;\n let afterLength = 0;\n // the search cannot go below the precision of the arithmetic, so the\n // precision is a share of the length of the path with an absolute cap\n const precisionFloor = Math.min(Math.max(pathLength * precisionShare, 1e-9), maxPrecisionFloor);\n\n while (precision > precisionFloor) {\n beforeLength = length - precision;\n afterLength = length + precision;\n // a loop is walked over its end, an open path is not\n if (beforeLength < 0) {\n beforeLength = isLoop ? beforeLength + pathLength : -1;\n }\n if (afterLength > pathLength) {\n afterLength = isLoop ? afterLength - pathLength : pathLength + 1;\n }\n\n const before =\n beforeLength >= 0 && beforeLength <= pathLength\n ? getPointAtTable(table, beforeLength)\n : null;\n const after =\n afterLength >= 0 && afterLength <= pathLength ? getPointAtTable(table, afterLength) : null;\n const beforeDistance = before ? distanceTo(before) : Infinity;\n const afterDistance = after ? distanceTo(after) : Infinity;\n\n if (before && beforeDistance < distance) {\n closest = before;\n length = beforeLength;\n distance = beforeDistance;\n } else if (after && afterDistance < distance) {\n closest = after;\n length = afterLength;\n distance = afterDistance;\n } else {\n precision /= 2;\n }\n }\n\n // the walk approximates the closest point, so the answer is snapped to\n // the exact projection of the point on the straight segment it is on\n const measure = segmentMeasures[findSegmentIndex(segmentMeasures, length)];\n const command = measure.geometry[0];\n if (command === \"L\" || command === \"Z\") {\n const { point: projected, ratio } = projectOnSegment(\n point,\n measure.startX,\n measure.startY,\n measure.endX,\n measure.endY,\n );\n const dx = point.x - projected.x;\n const dy = point.y - projected.y;\n const projectedDistance = dx * dx + dy * dy;\n if (projectedDistance < distance) {\n closest = projected;\n distance = projectedDistance;\n length = measure.lengthAtSegment + ratio * measure.length;\n }\n }\n\n return { closest, distance, length, measure };\n };\n\n // the best sample of the scan is searched first: it is not a local minimum\n // of the distance when the path runs at a constant distance from the point\n const best = refine({\n length: bestLength,\n distance: bestDistance,\n point: bestPoint,\n });\n let closest = best.closest;\n let closestDistance = best.distance;\n let closestLength = best.length;\n let closestMeasure = best.measure;\n\n // the other places where the path passes near the point, the closest ones\n // first: the sampled distance of a place is an upper bound of the distance\n // of the path there, so a place that is not closer than the answer can\n // still be the one that answers it\n candidates.sort((a, b) => a.distance - b.distance);\n for (const candidate of candidates) {\n const refined = refine(candidate);\n if (refined.distance < closestDistance) {\n closest = refined.closest;\n closestDistance = refined.distance;\n closestLength = refined.length;\n closestMeasure = refined.measure;\n }\n }\n\n for (const measure of segmentMeasures) {\n const command = measure.geometry[0];\n let projected: Point;\n let ratio = 0;\n if (command === \"M\") {\n projected = { x: measure.endX, y: measure.endY };\n } else if (command === \"L\" || command === \"Z\") {\n const projection = projectOnSegment(\n point,\n measure.startX,\n measure.startY,\n measure.endX,\n measure.endY,\n );\n projected = projection.point;\n ratio = projection.ratio;\n } else {\n continue;\n }\n\n const dx = point.x - projected.x;\n const dy = point.y - projected.y;\n const projectedDistance = dx * dx + dy * dy;\n if (!Number.isFinite(projectedDistance) || projectedDistance >= closestDistance) continue;\n\n const projectedLength = measure.lengthAtSegment + ratio * measure.length;\n\n closest = projected;\n closestDistance = projectedDistance;\n closestLength = projectedLength;\n closestMeasure = measure;\n }\n\n const segment = getPropertiesFromMeasure(\n closestMeasure,\n Math.max(0, Math.min(closestMeasure.length, closestLength - closestMeasure.lengthAtSegment)),\n );\n\n return { closest, distance: Math.sqrt(closestDistance), segment };\n};\n","import type { PathArray } from \"../types.ts\";\nimport { getPropertiesAtPoint } from \"./getPropertiesAtPoint.ts\";\n\n/**\n * Returns the point in path closest to a given point.\n *\n * @param pathInput target `pathArray`\n * @param point the given point\n * @returns the best match\n */\nexport const getClosestPoint = (\n pathInput: string | PathArray,\n point: { x: number; y: number },\n): { x: number; y: number } => {\n return getPropertiesAtPoint(pathInput, point).closest;\n};\n","import { pathToCurve } from \"../convert/pathToCurve.ts\";\nimport type { CurveArray, PathArray, PointTuple } from \"../types.ts\";\n\n/**\n * Returns the area of a single cubic-bezier segment.\n *\n * http://objectmix.com/graphics/133553-area-closed-bezier-curve.html\n *\n * @param x1 the starting point X\n * @param y1 the starting point Y\n * @param c1x the first control point X\n * @param c1y the first control point Y\n * @param c2x the second control point X\n * @param c2y the second control point Y\n * @param x2 the ending point X\n * @param y2 the ending point Y\n * @returns the area of the cubic-bezier segment\n */\nconst getCubicSegArea = (\n x1: number,\n y1: number,\n c1x: number,\n c1y: number,\n c2x: number,\n c2y: number,\n x2: number,\n y2: number,\n) => {\n return (\n (3 *\n ((y2 - y1) * (c1x + c2x) -\n (x2 - x1) * (c1y + c2y) +\n c1y * (x1 - c2x) -\n c1x * (y1 - c2y) +\n y2 * (c2x + x1 / 3) -\n x2 * (c2y + y1 / 3))) /\n 20\n );\n};\n\n/**\n * Returns the signed area of a shape.\n *\n * @author Jürg Lehni & Jonathan Puckey\n *\n * @see https://github.com/paperjs/paper.js/blob/develop/src/path/Path.js\n *\n * @param path - The shape PathArray\n * @returns The signed area of the shape (positive for clockwise, negative for counter-clockwise)\n *\n * @example\n * ```ts\n * getPathArea([['M', 0, 0], ['L', 100, 0], ['L', 100, 100], ['L', 0, 100], ['Z']])\n * // => 10000 (clockwise square)\n * ```\n */\nexport const getPathArea = <T extends PathArray | string>(path: T): number =>\n getCurveArea(pathToCurve(path));\n\n/**\n * Returns the signed area of a path that is already made of cubic beziers.\n *\n * The conversion is the expensive part of the area calculation, so it is\n * kept out of this function: a caller that already has a curve array does\n * not have to convert it a second time.\n *\n * @param path - The curve PathArray\n * @returns The signed area of the shape\n */\nexport const getCurveArea = (path: CurveArray): number => {\n let x = 0;\n let y = 0;\n let len = 0;\n\n return path\n .map((seg) => {\n switch (seg[0]) {\n case \"M\":\n [, x, y] = seg;\n return 0;\n default:\n len = getCubicSegArea(x, y, seg[1], seg[2], seg[3], seg[4], seg[5], seg[6]);\n [x, y] = seg.slice(-2) as PointTuple;\n return len;\n }\n })\n .reduce((a, b) => a + b, 0);\n};\n","import { getCurveArea } from \"./getPathArea.ts\";\nimport { pathToCurve } from \"../convert/pathToCurve.ts\";\nimport type { PathArray } from \"../types.ts\";\n\n/**\n * Check if a path is drawn clockwise and returns true if so,\n * false otherwise.\n *\n * @param path the path string or `pathArray`\n * @returns true when clockwise or false if not\n */\nexport const getDrawDirection = (path: string | PathArray): boolean => {\n return getCurveArea(pathToCurve(path)) >= 0;\n};\n","import type { NormalArray, PathArray, PathCommand } from \"../types.ts\";\nimport { normalizeSegment } from \"./normalizeSegment.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { paramsParser } from \"../parser/paramsParser.ts\";\nimport { iterate } from \"./iterate.ts\";\n\n/**\n * Parses a path string or PathArray, then iterates the result for:\n * * converting segments to absolute values\n * * converting shorthand commands to their non-shorthand notation\n *\n * @param pathInput - The path string or PathArray\n * @returns The normalized PathArray\n *\n * @example\n * ```ts\n * normalizePath('M10 90s20 -80 40 -80s20 80 40 80')\n * // => [['M', 10, 90], ['C', 10, 90, 30, 10, 50, 10], ['C', 70, 10, 70, 90, 90, 90]]\n * ```\n */\nexport const normalizePath = <T extends string | PathArray>(pathInput: T): NormalArray => {\n const path = parsePathString(pathInput);\n const params = { ...paramsParser };\n let prevCommand: PathCommand | null = null;\n\n return iterate(path, (seg, _, lastX, lastY) => {\n params.x = lastX;\n params.y = lastY;\n const result = normalizeSegment(seg, params, prevCommand);\n\n const seglen = result.length;\n params.x1 = +result[seglen - 2];\n params.y1 = +result[seglen - 1];\n // only cubic and quadratic segments carry a reflectable control point\n if (result[0] === \"C\" || result[0] === \"Q\") {\n params.x2 = +result[seglen - 4];\n params.y2 = +result[seglen - 3];\n } else {\n params.x2 = null;\n params.y2 = null;\n }\n prevCommand = result[0];\n\n return result;\n }) as NormalArray;\n};\n","import type { NormalArray, PathArray } from \"../types.ts\";\nimport { normalizePath } from \"../process/normalizePath.ts\";\nimport { buildPathLengthTable, getPointAtTable } from \"./pathLengthTable.ts\";\n\n/**\n * Returns [x,y] coordinates of a point at a given length along a path.\n *\n * @param pathInput - The PathArray or path string to look into\n * @param distance - The distance along the path\n * @returns The requested {x, y} point coordinates\n *\n * @example\n * ```ts\n * getPointAtLength('M0 0L100 0L100 100Z', 50)\n * // => { x: 50, y: 0 }\n * ```\n */\nexport const getPointAtLength = <T extends PathArray>(\n pathInput: string | T,\n distance?: number,\n): { x: number; y: number } => {\n return getPointAtNormalizedLength(normalizePath(pathInput), distance);\n};\n\n/**\n * Returns [x,y] coordinates of a point at a given length along a path\n * that is already normalized.\n *\n * The normalization is the expensive part of the lookup, so it is kept\n * out of this function: a caller that already has a normalized path does\n * not have to normalize it again for every point it looks up.\n *\n * @param path - The normalized PathArray to look into\n * @param distance - The distance along the path\n * @returns The requested {x, y} point coordinates\n */\nexport const getPointAtNormalizedLength = (\n path: NormalArray,\n distance?: number,\n): { x: number; y: number } => {\n return getPointAtTable(buildPathLengthTable(path), distance);\n};\n","import type { PathArray, PathSegment } from \"../types.ts\";\nimport { getPropertiesAtLength } from \"./getPropertiesAtLength.ts\";\n\n/**\n * Returns the segment at a given length.\n *\n * @param pathInput the target `pathArray`\n * @param distance the distance in path to look at\n * @returns the requested segment\n */\nexport const getSegmentAtLength = <T extends PathArray>(\n pathInput: string | T,\n distance?: number,\n): PathSegment | undefined => {\n return getPropertiesAtLength(pathInput, distance).segment;\n};\n","import type { SegmentProperties } from \"../interface.ts\";\nimport type { PathArray } from \"../types.ts\";\nimport { getPropertiesAtPoint } from \"./getPropertiesAtPoint.ts\";\n\n/**\n * Returns the path segment which contains a given point.\n *\n * @param path the `pathArray` to look into\n * @param point the point of the shape to look for\n * @returns the requested segment\n */\nexport const getSegmentOfPoint = <T extends PathArray>(\n path: string | T,\n point: { x: number; y: number },\n): SegmentProperties | undefined => {\n return getPropertiesAtPoint(path, point).segment;\n};\n","import type { PathArray, PathSegment, RelativeCommand } from \"../types.ts\";\nimport { paramsCounts } from \"../parser/paramsCount.ts\";\n\n/**\n * Iterates an array to check if it's an actual `pathArray`.\n *\n * @param path the `pathArray` to be checked\n * @returns iteration result\n */\nexport const isPathArray = (path: unknown): path is PathArray => {\n return (\n Array.isArray(path) &&\n path.every((seg: PathSegment) => {\n const command = (seg as PathSegment | undefined)?.[0];\n if (typeof command !== \"string\") return false;\n const lk = command.toLowerCase() as RelativeCommand;\n return (\n paramsCounts[lk] === seg.length - 1 &&\n \"achlmqstvz\".includes(lk) &&\n (seg.slice(1) as unknown[]).every(Number.isFinite)\n );\n }) &&\n path.length > 0\n );\n};\n","import type { AbsoluteArray } from \"../types.ts\";\nimport { isPathArray } from \"./isPathArray.ts\";\n\n/**\n * Iterates an array to check if it's a `pathArray`\n * with all absolute values.\n *\n * @param path the `pathArray` to be checked\n * @returns iteration result\n */\nexport const isAbsoluteArray = (path: unknown): path is AbsoluteArray => {\n return (\n isPathArray(path) &&\n // `isPathArray` also checks if it's `Array`\n path.every(([x]) => x === x.toUpperCase())\n );\n};\n","import type { NormalArray } from \"../types.ts\";\nimport { isAbsoluteArray } from \"./isAbsoluteArray.ts\";\n\n/**\n * Iterates an array to check if it's a `pathArray`\n * with all segments in non-shorthand notation\n * with absolute values.\n *\n * @param path - the array to be checked\n * @returns true if the array is a normalized path array\n */\nexport const isNormalizedArray = (path: unknown): path is NormalArray => {\n // `isAbsoluteArray` also checks if it's `Array`\n return isAbsoluteArray(path) && path.every(([pc]) => \"ACLMQZ\".includes(pc));\n};\n","import type { CurveArray } from \"../types.ts\";\nimport { isNormalizedArray } from \"./isNormalizedArray.ts\";\n\n/**\n * Iterates an array to check if it's a `pathArray`\n * with all C (cubic bezier) segments.\n *\n * @param path the `Array` to be checked\n * @returns iteration result\n */\nexport const isCurveArray = (path: unknown): path is CurveArray => {\n // `isPathArray` also checks if it's `Array`\n return isNormalizedArray(path) && path.every(([pc]) => \"MC\".includes(pc));\n};\n","import type { PathArray, Point } from \"../types.ts\";\nimport type { StrokeOptions } from \"../interface.ts\";\nimport { getPropertiesAtPoint } from \"./getPropertiesAtPoint.ts\";\nimport { error } from \"./error.ts\";\nimport DISTANCE_EPSILON from \"./distanceEpsilon.ts\";\n\n/**\n * Checks if a given point is in the stroke of a path.\n *\n * Without a width the point has to be on the path itself, within the\n * distance epsilon of it. With a width the stroke is the band around the\n * path: the point is in the stroke when it is at most half the width away\n * from the path. The ends of an open path are treated as if the stroke had\n * round caps, so a point beyond the end of the path is in the stroke too.\n *\n * @param pathInput target path\n * @param point the given `{x,y}` point\n * @param options the options of the test\n * @returns the query result\n *\n * @example\n * ```ts\n * isPointInStroke('M0 0L100 0', { x: 50, y: 0 });\n * // => true\n * isPointInStroke('M0 0L100 0', { x: 50, y: 5 }, { width: 10 });\n * // => true\n * ```\n */\nexport const isPointInStroke = <T extends PathArray>(\n pathInput: string | T,\n point: Point,\n options?: StrokeOptions,\n): boolean => {\n const { width = 0 } = options ?? {};\n\n if (typeof width !== \"number\" || !Number.isFinite(width) || width < 0) {\n throw TypeError(`${error}: width must be a number greater than or equal to 0`);\n }\n\n const { distance } = getPropertiesAtPoint(pathInput, point);\n\n // without a width the point has to be on the path itself\n if (!width) return distance < DISTANCE_EPSILON;\n\n // the stroke is the band around the path\n return distance <= width / 2;\n};\n","import type { CubicCoordinates, CurveArray, Point } from \"../types.ts\";\nimport { getPointAtCubicSegmentLength } from \"../math/cubicTools.ts\";\n\n/**\n * Returns the number of intervals a cubic segment is split into.\n *\n * The second differences of the control points bound the distance of the\n * curve to its chord, and the distance of a piece of the curve to the chord\n * of the piece falls with the square of the number of the pieces, so the\n * number of the intervals is the square root of the ratio of the bound to\n * the tolerance.\n *\n * @param coords - the coordinates of the cubic segment\n * @param tolerance - the maximum distance between the curve and its chords\n * @returns the number of intervals\n */\nconst getIntervalCount = (coords: CubicCoordinates, tolerance: number): number => {\n const [x1, y1, c1x, c1y, c2x, c2y, x2, y2] = coords;\n // the second differences of the control points\n const d1 = Math.hypot(x1 - 2 * c1x + c2x, y1 - 2 * c1y + c2y);\n const d2 = Math.hypot(c1x - 2 * c2x + x2, c1y - 2 * c2y + y2);\n // the bound of the distance of the curve to its chord\n const flatness = 0.75 * Math.max(d1, d2);\n // a straight segment is one interval\n if (flatness <= tolerance) return 1;\n\n return Math.ceil(Math.sqrt(flatness / tolerance));\n};\n\n/**\n * Flattens a path into polygons, one for every sub-path.\n *\n * The curves of the path are split into chords that stay within the\n * tolerance of the curve, and every sub-path is closed, the way a fill\n * closes an open path.\n *\n * @param path - the curve path to flatten\n * @param tolerance - the maximum distance between the curve and its chords\n * @returns the polygons of the path\n */\nexport const flattenPath = (path: CurveArray, tolerance: number): Point[][] => {\n const polygons: Point[][] = [];\n let points: Point[] = [];\n let current: Point = { x: 0, y: 0 };\n\n for (const segment of path) {\n if (segment[0] === \"M\") {\n // the sub-path before this one is closed\n if (points.length > 1) polygons.push(points);\n current = { x: segment[1] as number, y: segment[2] as number };\n points = [current];\n continue;\n }\n\n // a curve path holds no other command than the cubic\n const coords = [\n current.x,\n current.y,\n segment[1] as number,\n segment[2] as number,\n segment[3] as number,\n segment[4] as number,\n segment[5] as number,\n segment[6] as number,\n ] as CubicCoordinates;\n const count = getIntervalCount(coords, tolerance);\n\n for (let i = 1; i <= count; i += 1) {\n const point = getPointAtCubicSegmentLength(coords, i / count);\n points.push(point);\n }\n current = { x: segment[5] as number, y: segment[6] as number };\n }\n\n // the last sub-path is closed too\n if (points.length > 1) polygons.push(points);\n\n return polygons;\n};\n","import type { Point } from \"../types.ts\";\n\n/**\n * Returns the distance from a point to a line segment.\n *\n * The distance is the one to the segment, not to the infinite line: a point\n * beyond the end of the segment is at the distance to that end.\n *\n * @param point - the point to measure\n * @param start - the start of the segment\n * @param end - the end of the segment\n * @returns the distance from the point to the segment\n */\nexport const distanceToSegment = (point: Point, start: Point, end: Point): number => {\n const dx = end.x - start.x;\n const dy = end.y - start.y;\n const lengthSquared = dx * dx + dy * dy;\n // a segment without a length is a point\n if (lengthSquared === 0) {\n const px = point.x - start.x;\n const py = point.y - start.y;\n return Math.sqrt(px * px + py * py);\n }\n let ratio = ((point.x - start.x) * dx + (point.y - start.y) * dy) / lengthSquared;\n ratio = ratio < 0 ? 0 : ratio > 1 ? 1 : ratio;\n const px = point.x - (start.x + dx * ratio);\n const py = point.y - (start.y + dy * ratio);\n return Math.sqrt(px * px + py * py);\n};\n","import type { Point } from \"../types.ts\";\nimport { distanceToSegment } from \"./distanceToSegment.ts\";\n\n/**\n * Returns the number of times a ray from a point crosses a polygon.\n *\n * The ray goes to the right, so every edge of the polygon that crosses the\n * height of the point after it is counted. The parity of the count is the\n * answer of the `evenodd` fill rule.\n *\n * @param polygon - the polygon to test\n * @param point - the point to test\n * @returns the number of crossings\n */\nexport const getPolygonCrossings = (polygon: Point[], point: Point): number => {\n const { x, y } = point;\n const count = polygon.length;\n let crossings = 0;\n\n for (let i = 0; i < count; i += 1) {\n const j = (i + 1) % count;\n const current = polygon[i];\n const next = polygon[j];\n // the edge is on one side of the height of the point, it does not cross\n if (current.y > y === next.y > y) continue;\n // the X of the edge at the height of the point\n const at = ((next.x - current.x) * (y - current.y)) / (next.y - current.y) + current.x;\n // the crossing is after the point, the ray reaches it\n if (x < at) crossings += 1;\n }\n\n return crossings;\n};\n\n/**\n * Returns the winding number of a polygon around a point.\n *\n * Every edge that crosses the height of the point counts, the direction of\n * the crossing decides the sign of the count. The winding number is zero\n * outside of the polygon and it is not zero inside of it, whatever the\n * direction of the polygon is, so its sign is the direction of the shape.\n *\n * @param polygon - the polygon to test\n * @param point - the point to test\n * @returns the winding number\n */\nexport const getPolygonWindingNumber = (polygon: Point[], point: Point): number => {\n const { x, y } = point;\n const count = polygon.length;\n let winding = 0;\n\n for (let i = 0; i < count; i += 1) {\n const j = (i + 1) % count;\n const current = polygon[i];\n const next = polygon[j];\n // the side of the point relative to the edge\n const side = (next.x - current.x) * (y - current.y) - (next.y - current.y) * (x - current.x);\n if (current.y <= y) {\n // an upward crossing\n if (next.y > y && side > 0) winding += 1;\n } else if (next.y <= y && side < 0) {\n // a downward crossing\n winding -= 1;\n }\n }\n\n return winding;\n};\n\n/**\n * Checks if a point is on the boundary of a polygon.\n *\n * @param polygon - the polygon to test\n * @param point - the point to test\n * @param epsilon - the maximum distance to the boundary\n * @returns whether the point is on the boundary\n */\nexport const isPointOnPolygon = (polygon: Point[], point: Point, epsilon: number): boolean => {\n const count = polygon.length;\n\n for (let i = 0; i < count; i += 1) {\n const j = (i + 1) % count;\n if (distanceToSegment(point, polygon[i], polygon[j]) <= epsilon) {\n return true;\n }\n }\n\n return false;\n};\n","import type { PathArray, Point } from \"../types.ts\";\nimport type { PointInPathOptions } from \"../interface.ts\";\nimport { pathToCurve } from \"../convert/pathToCurve.ts\";\nimport { flattenPath } from \"../process/flattenPath.ts\";\nimport {\n getPolygonCrossings,\n getPolygonWindingNumber,\n isPointOnPolygon,\n} from \"../math/pointInPolygon.ts\";\nimport { error } from \"./error.ts\";\n\n/**\n * The distance a point can be from the boundary of a shape and still be on it.\n *\n * The tolerance of the flattening is the error of the approximation, not the\n * width of the boundary, so the boundary is tested with a tight distance.\n */\nconst boundaryEpsilon = 1e-9;\n\n/**\n * Checks if a given point is inside a path.\n *\n * The path is flattened into polygons and the point is tested against them\n * with the fill rule of the path: the `nonzero` rule counts the windings of\n * the polygons around the point, the `evenodd` rule counts the crossings of\n * the polygons with a ray from the point. A point on the boundary of the\n * shape is inside of it, the way the browser answers it.\n *\n * The curves of the path are approximated with chords that stay within the\n * tolerance of the curve, so the answer is exact except for the points that\n * are within the tolerance of the boundary of a curve.\n *\n * @param pathInput target path\n * @param point the given `{x,y}` point\n * @param options the options of the test\n * @returns the query result\n *\n * @example\n * ```ts\n * isPointInPath('M0 0L100 0L100 100L0 100Z', { x: 50, y: 50 });\n * // => true\n * ```\n */\nexport const isPointInPath = <T extends PathArray>(\n pathInput: string | T,\n point: Point,\n options?: PointInPathOptions,\n): boolean => {\n const { fillRule = \"nonzero\", tolerance = 0.1 } = options ?? {};\n\n if (fillRule !== \"nonzero\" && fillRule !== \"evenodd\") {\n throw TypeError(`${error}: fillRule must be \"nonzero\" or \"evenodd\"`);\n }\n if (typeof tolerance !== \"number\" || !Number.isFinite(tolerance) || tolerance <= 0) {\n throw TypeError(`${error}: tolerance must be a positive number`);\n }\n\n const path = pathToCurve(pathInput);\n // an empty path has no inside\n if (!path.length) return false;\n\n const polygons = flattenPath(path, tolerance);\n let crossings = 0;\n let winding = 0;\n\n for (const polygon of polygons) {\n // a point on the boundary of the shape is inside of it\n if (isPointOnPolygon(polygon, point, boundaryEpsilon)) return true;\n crossings += getPolygonCrossings(polygon, point);\n winding += getPolygonWindingNumber(polygon, point);\n }\n\n return fillRule === \"evenodd\" ? crossings % 2 === 1 : winding !== 0;\n};\n","import { isNormalizedArray } from \"./isNormalizedArray.ts\";\nimport type { PathArray, PolygonArray } from \"../types.ts\";\n/**\n * Checks if a path is a polygon (only M, L, H, V, Z commands).\n * @param pathArray PathArray (pre-normalize if needed)\n * @returns boolean\n */\nexport const isPolygonArray = (path: PathArray): path is PolygonArray => {\n return isNormalizedArray(path) && path.every(([pc]) => \"MLVHZ\".includes(pc));\n};\n","import { isNormalizedArray } from \"./isNormalizedArray.ts\";\nimport type { PathArray, PolylineArray } from \"../types.ts\";\n/**\n * Checks if a path is a polyline (only M, L, H, V commands).\n * @param pathArray PathArray (pre-normalize if needed)\n * @returns boolean\n */\nexport function isPolylineArray(path: PathArray): path is PolylineArray {\n return isNormalizedArray(path) && path.every(([pc]) => \"MLVH\".includes(pc));\n}\n","import type { RelativeArray } from \"../types.ts\";\nimport { isPathArray } from \"./isPathArray.ts\";\n\n/**\n * Iterates an array to check if it's a `pathArray`\n * with relative values.\n *\n * @param path the `pathArray` to be checked\n * @returns iteration result\n */\nexport const isRelativeArray = (path: unknown): path is RelativeArray => {\n return (\n isPathArray(path) &&\n // `isPathArray` checks if it's `Array`\n path.slice(1).every(([pc]) => pc === pc.toLowerCase())\n );\n};\n","import { scanSegment } from \"../parser/scanSegment.ts\";\nimport { skipSpaces } from \"../parser/skipSpaces.ts\";\nimport { PathParser } from \"../parser/pathParser.ts\";\n\n/**\n * Parses a path string value to determine its validity\n * then returns true if it's valid or false otherwise.\n *\n * @param pathString the path string to be parsed\n * @returns the path string validity\n */\nexport const isValidPath = (pathString: string): boolean => {\n if (typeof pathString !== \"string\" || !pathString.length) {\n return false;\n }\n\n const path = new PathParser(pathString);\n\n skipSpaces(path);\n\n while (path.index < path.max && !path.err.length) {\n scanSegment(path);\n }\n\n return !path.err.length && !!path.segments.length && \"mM\".includes(path.segments[0][0]);\n};\n","import type { PathArray } from \"../types.ts\";\nimport { error } from \"./error.ts\";\nimport { isPathArray } from \"./isPathArray.ts\";\n\n/**\n * Determines if an SVG path contains multiple subpaths.\n * Accepts path string or PathArray.\n * @param path - 'M10,10 L20,20 Z M30,30 L40,40' → true\n * @returns boolean\n */\nexport const isMultiPath = <T extends PathArray>(path: string | T): boolean => {\n if (typeof path === \"string\") {\n // Count all 'M' and 'm' occurrences\n const matches = path.match(/[Mm]/g);\n return matches ? matches.length > 1 : false;\n }\n\n // a value that is not a path at all is a type error\n if (!Array.isArray(path)) {\n throw new TypeError(error + \": expected string or PathArray\");\n }\n\n // an empty path and a malformed path have no sub-paths\n if (!isPathArray(path)) return false;\n\n let moveCount = 0;\n for (const segment of path) {\n if (segment[0].toUpperCase() === \"M\") {\n moveCount++;\n if (moveCount > 1) return true;\n }\n }\n return false;\n};\n","import type { PathArray } from \"../types.ts\";\n\n/**\n * Check if a PathArray is closed, which means its last segment is a Z.\n * @param path\n * @returns true if the path is closed\n */\nexport const isClosedPath = <T extends PathArray>(path: T): boolean => {\n if (!path.length) return false;\n return path[path.length - 1][0].toUpperCase() === \"Z\";\n};\n","import type { ShapeParams } from \"../interface.ts\";\n\n/**\n * Supported shapes and their specific parameters.\n */\nexport const shapeParams: ShapeParams = {\n line: [\"x1\", \"y1\", \"x2\", \"y2\"],\n circle: [\"cx\", \"cy\", \"r\"],\n ellipse: [\"cx\", \"cy\", \"rx\", \"ry\"],\n rect: [\"width\", \"height\", \"x\", \"y\", \"rx\", \"ry\"],\n polygon: [\"points\"],\n polyline: [\"points\"],\n glyph: [\"d\"],\n};\n","/**\n * Checks if a value is a DOM Element.\n *\n * @param node - The value to check\n * @returns True if the value is a DOM Element (nodeType === 1)\n */\nexport const isElement = (node?: unknown): node is Element =>\n node !== undefined && node !== null && typeof node === \"object\" && (node as Node).nodeType === 1; // ELEMENT_NODE\n","import type {\n CircleAttr,\n EllipseAttr,\n GlyphAttr,\n LineAttr,\n PolyAttr,\n RectAttr,\n ShapeParams,\n} from \"../interface.ts\";\nimport type { PathArray, PathSegment, ShapeOps, ShapeTypes } from \"../types.ts\";\nimport { error } from \"./error.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { shapeParams } from \"./shapeParams.ts\";\nimport { isPathArray } from \"./isPathArray.ts\";\nimport { isElement } from \"./isElement.ts\";\n\n/**\n * Returns a new PathArray from line attributes.\n *\n * @param attr - Shape configuration with x1, y1, x2, y2\n * @returns A new line PathArray\n *\n * @example\n * ```ts\n * getLinePath({ x1: 0, y1: 0, x2: 100, y2: 100 })\n * // => [['M', 0, 0], ['L', 100, 100]]\n * ```\n */\nexport const getLinePath = (attr: LineAttr): PathArray => {\n let { x1, y1, x2, y2 } = attr;\n [x1, y1, x2, y2] = [x1, y1, x2, y2].map((a) => +a);\n return [\n [\"M\", x1, y1],\n [\"L\", x2, y2],\n ];\n};\n\n/**\n * Returns a new PathArray from polyline/polygon attributes.\n *\n * @param attr - Shape configuration with points string\n * @returns A new polygon/polyline PathArray\n *\n * @example\n * ```ts\n * getPolyPath({ type: 'polygon', points: '0,0 100,0 100,100 0,100' })\n * // => [['M', 0, 0], ['L', 100, 0], ['L', 100, 100], ['L', 0, 100], ['z']]\n * ```\n */\nexport const getPolyPath = (attr: PolyAttr): PathArray => {\n const pathArray = [] as PathSegment[];\n const points = (attr.points || \"\")\n .trim()\n .split(/[\\s|,]/)\n .map((a) => +a);\n\n let index = 0;\n while (index + 1 < points.length) {\n const x = points[index] as number;\n const y = points[index + 1] as number;\n // a pair without both coordinates, or with invalid ones, is dropped\n if (Number.isFinite(x) && Number.isFinite(y)) {\n pathArray.push([pathArray.length ? \"L\" : \"M\", x, y]);\n }\n index += 2;\n }\n\n return (\n attr.type === \"polygon\" && pathArray.length ? [...pathArray, [\"z\"]] : pathArray\n ) as PathArray;\n};\n\n/**\n * Returns a new PathArray from circle attributes.\n *\n * @param attr - Shape configuration with cx, cy, r\n * @returns A circle PathArray\n *\n * @example\n * ```ts\n * getCirclePath({ cx: 50, cy: 50, r: 25 })\n * // => [['M', 25, 50], ['a', 25, 25, 0, 1, 0, 50, 0], ['a', 25, 25, 0, 1, 0, -50, 0]]\n * ```\n */\nexport const getCirclePath = (attr: CircleAttr): PathArray => {\n let { cx, cy, r } = attr;\n [cx, cy, r] = [cx, cy, r].map((a) => +a);\n\n return [\n [\"M\", cx - r, cy],\n [\"a\", r, r, 0, 1, 0, 2 * r, 0],\n [\"a\", r, r, 0, 1, 0, -2 * r, 0],\n ];\n};\n\n/**\n * Returns a new PathArray from ellipse attributes.\n *\n * @param attr - Shape configuration with cx, cy, rx, ry\n * @returns An ellipse PathArray\n *\n * @example\n * ```ts\n * getEllipsePath({ cx: 50, cy: 50, rx: 30, ry: 20 })\n * // => [['M', 20, 50], ['a', 30, 20, 0, 1, 0, 60, 0], ['a', 30, 20, 0, 1, 0, -60, 0]]\n * ```\n */\nexport const getEllipsePath = (attr: EllipseAttr): PathArray => {\n let { cx, cy } = attr;\n let rx = attr.rx || 0;\n let ry = attr.ry || rx;\n [cx, cy, rx, ry] = [cx, cy, rx, ry].map((a) => +a);\n\n return [\n [\"M\", cx - rx, cy],\n [\"a\", rx, ry, 0, 1, 0, 2 * rx, 0],\n [\"a\", rx, ry, 0, 1, 0, -2 * rx, 0],\n ];\n};\n\n/**\n * Returns a new PathArray from rect attributes.\n *\n * The corners of a rounded rectangle are elliptical arcs, one for every\n * corner, and the radius of the corners follows the rules of the spec: a\n * missing radius takes the value of the other one, an explicit zero\n * disables the rounding and a radius bigger than half of the size of the\n * rectangle is clamped to it.\n *\n * @param attr - Object with x, y, width, height, and optional rx/ry\n * @returns A new PathArray from `<rect>` attributes\n *\n * @example\n * ```ts\n * getRectanglePath({ x: 0, y: 0, width: 100, height: 50, ry: 10 })\n * // => [['M', 10, 0], ['h', 80], ['a', 10, 10, 0, 0, 1, 10, 10], ...]\n * ```\n */\nexport const getRectanglePath = (attr: RectAttr): PathArray => {\n const x = +attr.x || 0;\n const y = +attr.y || 0;\n const w = +attr.width;\n const h = +attr.height;\n // a missing radius takes the value of the other one\n const rxValue = attr.rx === undefined || attr.rx === null ? undefined : +attr.rx;\n const ryValue = attr.ry === undefined || attr.ry === null ? undefined : +attr.ry;\n let rx = rxValue ?? ryValue ?? 0;\n let ry = ryValue ?? rxValue ?? 0;\n\n // Validity checks from http://www.w3.org/TR/SVG/shapes.html#RectElement:\n if (rx > 0 && ry > 0) {\n // the radius of a corner cannot be bigger than half of the size of the\n // rectangle\n rx = Math.min(rx, w / 2);\n ry = Math.min(ry, h / 2);\n\n return [\n [\"M\", x + rx, y],\n [\"h\", w - rx * 2],\n [\"a\", rx, ry, 0, 0, 1, rx, ry],\n [\"v\", h - ry * 2],\n [\"a\", rx, ry, 0, 0, 1, -rx, ry],\n [\"h\", -w + rx * 2],\n [\"a\", rx, ry, 0, 0, 1, -rx, -ry],\n [\"v\", -h + ry * 2],\n [\"a\", rx, ry, 0, 0, 1, rx, -ry],\n [\"Z\"],\n ];\n }\n\n return [[\"M\", x, y], [\"h\", w], [\"v\", h], [\"H\", x], [\"Z\"]];\n};\n\n/**\n * Returns a new `pathArray` created from attributes of a `<line>`, `<polyline>`,\n * `<polygon>`, `<rect>`, `<ellipse>`, `<circle>`, <path> or `<glyph>`.\n *\n * It can also work with an options object, see the type below\n * @see ShapeOps\n *\n * @param element target shape\n * @returns the newly created `<path>` element\n */\nexport const shapeToPathArray = (element: ShapeTypes | ShapeOps): false | PathArray => {\n const supportedShapes = Object.keys(shapeParams) as (keyof ShapeParams)[];\n const targetIsElement = isElement(element);\n const tagName = targetIsElement ? element.tagName : null;\n\n if (tagName && [...supportedShapes, \"path\"].every((s) => tagName !== s)) {\n throw TypeError(`${error}: \"${tagName}\" is not SVGElement`);\n }\n\n const type = (targetIsElement ? tagName : (element as ShapeOps).type) as ShapeOps[\"type\"];\n const shapeAttrs = shapeParams[type] as string[];\n const config = { type } as Record<string, string>;\n\n if (targetIsElement) {\n shapeAttrs.forEach((p) => {\n config[p] = element.getAttribute(p) as string;\n });\n } else {\n Object.assign(config, element);\n }\n\n // set d\n let pathArray = [] as unknown as PathArray;\n\n /* istanbul ignore else */\n if (type === \"circle\") {\n pathArray = getCirclePath(config as unknown as CircleAttr);\n } else if (type === \"ellipse\") {\n pathArray = getEllipsePath(config as unknown as EllipseAttr);\n } else if ([\"polyline\", \"polygon\"].includes(type)) {\n pathArray = getPolyPath(config as unknown as PolyAttr);\n } else if (type === \"rect\") {\n pathArray = getRectanglePath(config as unknown as RectAttr);\n } else if (type === \"line\") {\n pathArray = getLinePath(config as unknown as LineAttr);\n } else if ([\"glyph\", \"path\"].includes(type)) {\n pathArray = parsePathString(\n targetIsElement\n ? element.getAttribute(\"d\") || /* istanbul ignore next */ \"\"\n : (element as GlyphAttr).d || \"\",\n );\n }\n\n // replace target element\n if (isPathArray(pathArray) && pathArray.length) {\n return pathArray;\n }\n return false;\n};\n","import type { ShapeParams } from \"../interface.ts\";\nimport type { ShapeOps, ShapeTypes } from \"../types.ts\";\nimport { pathToString } from \"../convert/pathToString.ts\";\nimport { defaultOptions } from \"../options/options.ts\";\nimport { error } from \"./error.ts\";\nimport { isValidPath } from \"./isValidPath.ts\";\nimport { isElement } from \"./isElement.ts\";\nimport { shapeToPathArray } from \"./shapeToPathArray.ts\";\nimport { shapeParams } from \"./shapeParams.ts\";\n\n/**\n * Returns a new `<path>` element created from attributes of a `<line>`, `<polyline>`,\n * `<polygon>`, `<rect>`, `<ellipse>`, `<circle>` or `<glyph>`. If `replace` parameter\n * is `true`, it will replace the target. The default `ownerDocument` is your current\n * `document` browser page, if you want to use in server-side using `jsdom`, you can\n * pass the `jsdom` `document` to `ownDocument`.\n *\n * It can also work with an options object, see the type below\n * @see ShapeOps\n *\n * The newly created `<path>` element keeps all non-specific\n * attributes like `class`, `fill`, etc.\n *\n * @param element - Target shape element or shape options object\n * @param replace - Option to replace target element\n * @param ownerDocument - Document for creating the element\n * @returns The newly created `<path>` element, or false if the path is invalid\n *\n * @example\n * ```ts\n * const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle')\n * circle.setAttribute('cx', '50')\n * circle.setAttribute('cy', '50')\n * circle.setAttribute('r', '25')\n * const path = shapeToPath(circle)\n * path.getAttribute('d')\n * // => 'M50 25A25 25 0 1 1 50 75A25 25 0 1 1 50 25Z'\n * ```\n */\nexport const shapeToPath = (\n element: ShapeTypes | ShapeOps,\n replace?: boolean,\n ownerDocument?: Document,\n): SVGPathElement | false => {\n const doc = ownerDocument || document;\n const supportedShapes = Object.keys(shapeParams) as (keyof ShapeParams)[];\n const targetIsElement = isElement(element);\n const tagName = targetIsElement ? element.tagName : null;\n\n if (tagName === \"path\") {\n throw TypeError(`${error}: \"${tagName}\" is already SVGPathElement`);\n }\n if (tagName && supportedShapes.every((s) => tagName !== s)) {\n throw TypeError(`${error}: \"${tagName}\" is not SVGElement`);\n }\n\n const path = doc.createElementNS(\"http://www.w3.org/2000/svg\", \"path\");\n const type = (targetIsElement ? tagName : (element as ShapeOps).type) as ShapeOps[\"type\"];\n const shapeAttrs = shapeParams[type] as string[];\n const config = { type } as Record<string, string>;\n\n // set d\n const round = defaultOptions.round as number;\n const pathArray = shapeToPathArray(element);\n const description = pathArray && pathArray.length ? pathToString(pathArray, round) : \"\";\n\n if (targetIsElement) {\n shapeAttrs.forEach((p) => {\n config[p] = element.getAttribute(p) as string;\n });\n // set no-specific shape attributes: fill, stroke, etc\n for (let i = 0; i < element.attributes.length; i++) {\n const attr = element.attributes[i];\n if (attr && !shapeAttrs.includes(attr.name)) {\n path.setAttribute(attr.name, attr.value);\n }\n }\n } else {\n Object.assign(config, element);\n // set no-specific shape attributes: fill, stroke, etc\n Object.keys(config).forEach((k) => {\n if (!shapeAttrs.includes(k) && k !== \"type\") {\n path.setAttribute(\n k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`),\n config[k],\n );\n }\n });\n }\n\n // replace target element\n if (isValidPath(description)) {\n path.setAttribute(\"d\", description);\n if (replace && targetIsElement) {\n element.before(path, element);\n element.remove();\n }\n return path;\n }\n return false;\n};\n","import type { SegmentMeasure } from \"../util/measureSegments.ts\";\nimport { getSegmentFrame } from \"../util/segmentFrame.ts\";\n\n/**\n * A point of a path with the direction of the path at that point.\n */\nexport type OffsetNode = {\n /** The X coordinate of the point. */\n x: number;\n /** The Y coordinate of the point. */\n y: number;\n /** The X component of the unit tangent. */\n tx: number;\n /** The Y component of the unit tangent. */\n ty: number;\n /** Whether a join precedes this node. */\n corner: boolean;\n};\n\n/**\n * Returns the sampled points of the drawable segments of a sub-path.\n *\n * A line gives its two end points, a curve gives `steps` samples spread\n * evenly over its length. The tangent of every sample is the tangent of the\n * path at that point, so the normal of the sample is the direction the path\n * is offset to.\n *\n * The first point of a segment is a corner when the segment follows another\n * one, and the closing segment of a closed sub-path ends with a corner that\n * joins the last segment to the first one.\n *\n * @param measures - the measured segments of the sub-path\n * @param steps - the number of the intervals a curve is sampled with\n * @returns the sampled points of the sub-path\n */\nexport const getOffsetNodes = (measures: SegmentMeasure[], steps: number): OffsetNode[] => {\n const nodes: OffsetNode[] = [];\n\n for (const measure of measures) {\n const command = measure.geometry[0];\n // the moveto only holds the start of the sub-path\n if (command === \"M\") continue;\n // a segment without a length does not move the path\n if (measure.length <= 0) continue;\n const isFirst = nodes.length === 0;\n\n if (command === \"L\" || command === \"Z\") {\n const dx = measure.endX - measure.startX;\n const dy = measure.endY - measure.startY;\n const length = Math.sqrt(dx * dx + dy * dy);\n const tx = dx / length;\n const ty = dy / length;\n nodes.push({\n x: measure.startX,\n y: measure.startY,\n tx,\n ty,\n corner: !isFirst,\n });\n nodes.push({ x: measure.endX, y: measure.endY, tx, ty, corner: false });\n continue;\n }\n\n for (let i = 0; i <= steps; i += 1) {\n const frame = getSegmentFrame(\n measure.geometry,\n measure.startX,\n measure.startY,\n measure.endX,\n measure.endY,\n (measure.length * i) / steps,\n measure.length,\n );\n nodes.push({\n x: frame.point.x,\n y: frame.point.y,\n tx: frame.tangent.x,\n ty: frame.tangent.y,\n corner: !isFirst && i === 0,\n });\n }\n }\n\n // a closed sub-path ends with the corner that joins the closing segment\n // to the first segment of the sub-path\n const last = measures[measures.length - 1];\n if (nodes.length && last && last.geometry[0] === \"Z\") {\n const first = nodes[0];\n nodes.push({\n x: first.x,\n y: first.y,\n tx: first.tx,\n ty: first.ty,\n corner: true,\n });\n }\n\n return nodes;\n};\n","import type { PointTuple } from \"../types.ts\";\nimport type { OffsetCap, OffsetJoin } from \"../interface.ts\";\n\n/**\n * A point of an offset path with the direction of the path at that point.\n */\nexport type OffsetPoint = {\n /** The X coordinate of the point. */\n x: number;\n /** The Y coordinate of the point. */\n y: number;\n /** The X component of the unit tangent. */\n tx: number;\n /** The Y component of the unit tangent. */\n ty: number;\n};\n\n/**\n * The angle of an arc of a round join or a round cap, in radians.\n *\n * The arcs are emitted as straight lines, and the smaller the angle the\n * closer the result is to the arc it stands for.\n */\nconst arcStep = Math.PI / 8;\n\n/**\n * Returns the signed angle between two directions, in radians.\n *\n * The angle is the turn of the path at a corner: it is positive when the\n * path turns towards the positive angle direction, and it is in the `-PI` to\n * `PI` range.\n *\n * @param from - the direction the path comes from\n * @param to - the direction the path goes to\n * @returns the signed angle between the two directions\n */\nexport const signedTurn = (from: OffsetPoint, to: OffsetPoint): number => {\n const dot = from.tx * to.tx + from.ty * to.ty;\n const cross = from.tx * to.ty - from.ty * to.tx;\n return Math.atan2(cross, dot);\n};\n\n/**\n * Returns the intersection of two lines, if they have one.\n *\n * @param x1 - the X coordinate of the first point\n * @param y1 - the Y coordinate of the first point\n * @param dx1 - the X component of the direction of the first line\n * @param dy1 - the Y component of the direction of the first line\n * @param x2 - the X coordinate of the second point\n * @param y2 - the Y coordinate of the second point\n * @param dx2 - the X component of the direction of the second line\n * @param dy2 - the Y component of the direction of the second line\n * @returns the intersection of the two lines, or `null`\n */\nexport const intersectLines = (\n x1: number,\n y1: number,\n dx1: number,\n dy1: number,\n x2: number,\n y2: number,\n dx2: number,\n dy2: number,\n): PointTuple | null => {\n const denominator = dx1 * dy2 - dy1 * dx2;\n // parallel lines have no intersection\n if (Math.abs(denominator) < 1e-12) return null;\n const ratio = ((x2 - x1) * dy2 - (y2 - y1) * dx2) / denominator;\n return [x1 + dx1 * ratio, y1 + dy1 * ratio];\n};\n\n/**\n * Returns the points of a join between two offset lines.\n *\n * The join is placed on the outer side of a corner, where the two offset\n * lines do not cross: the `miter` join is the intersection of the two\n * lines, the `bevel` join is the straight line between the two offset\n * points and the `round` join is an arc of the offset radius around the\n * corner.\n *\n * @param cornerX - the X coordinate of the corner of the path\n * @param cornerY - the Y coordinate of the corner of the path\n * @param from - the end of the incoming offset line\n * @param to - the start of the outgoing offset line\n * @param distance - the offset distance\n * @param join - the join type\n * @param miterLimit - the ratio of the miter length to the offset distance\n * @returns the points of the join\n */\nexport const getJoinPoints = (\n cornerX: number,\n cornerY: number,\n from: OffsetPoint,\n to: OffsetPoint,\n distance: number,\n join: OffsetJoin,\n miterLimit: number,\n): PointTuple[] => {\n if (join === \"round\") {\n const turn = signedTurn(from, to);\n const startAngle = Math.atan2(from.y - cornerY, from.x - cornerX);\n const steps = Math.max(1, Math.ceil(Math.abs(turn) / arcStep));\n const points: PointTuple[] = [];\n for (let i = 1; i < steps; i += 1) {\n const angle = startAngle + (turn * i) / steps;\n points.push([cornerX + Math.cos(angle) * distance, cornerY + Math.sin(angle) * distance]);\n }\n return points;\n }\n\n if (join === \"miter\") {\n const miter = intersectLines(from.x, from.y, from.tx, from.ty, to.x, to.y, to.tx, to.ty);\n if (miter) {\n const miterLength = Math.hypot(miter[0] - cornerX, miter[1] - cornerY);\n // the miter is too long, the corner is beveled instead\n if (miterLength <= miterLimit * distance) return [miter];\n }\n }\n\n return [];\n};\n\n/**\n * Returns the points of a cap at the end of an open path.\n *\n * The `butt` cap is the straight line between the two offset points, the\n * `square` cap extends the path by the offset distance and the `round` cap\n * is a half circle of the offset radius around the end of the path.\n *\n * @param centerX - the X coordinate of the end of the path\n * @param centerY - the Y coordinate of the end of the path\n * @param from - the first offset point of the cap\n * @param to - the last offset point of the cap\n * @param distance - the offset distance\n * @param cap - the cap type\n * @param extensionX - the X component of the direction the cap extends to\n * @param extensionY - the Y component of the direction the cap extends to\n * @returns the points of the cap\n */\nexport const getCapPoints = (\n centerX: number,\n centerY: number,\n from: PointTuple,\n to: PointTuple,\n distance: number,\n cap: OffsetCap,\n extensionX: number,\n extensionY: number,\n): PointTuple[] => {\n if (cap === \"butt\") return [];\n\n if (cap === \"square\") {\n // the cap is extended by the offset distance, along the direction of\n // the path\n return [\n [from[0] + extensionX * distance, from[1] + extensionY * distance],\n [to[0] + extensionX * distance, to[1] + extensionY * distance],\n ];\n }\n\n // the cap is a half circle, it sweeps from the first offset point to the\n // last one around the end of the path\n const startAngle = Math.atan2(from[1] - centerY, from[0] - centerX);\n const sweep = -Math.PI;\n const steps = Math.max(1, Math.ceil(Math.abs(sweep) / arcStep));\n const points: PointTuple[] = [];\n for (let i = 1; i < steps; i += 1) {\n const angle = startAngle + (sweep * i) / steps;\n points.push([centerX + Math.cos(angle) * distance, centerY + Math.sin(angle) * distance]);\n }\n return points;\n};\n","import type { PathArray, PathSegment, PointTuple } from \"../types.ts\";\nimport type { OffsetCap, OffsetJoin, OffsetOptions, OffsetSide } from \"../interface.ts\";\nimport { error } from \"../util/error.ts\";\nimport { measureSegments } from \"../util/measureSegments.ts\";\nimport type { SegmentMeasure } from \"../util/measureSegments.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { polygonArea } from \"../math/polygonTools.ts\";\nimport { roundTo } from \"../math/roundTo.ts\";\nimport { cleanZero } from \"../util/segmentFrame.ts\";\nimport { getOffsetNodes } from \"./offsetNodes.ts\";\nimport type { OffsetNode } from \"./offsetNodes.ts\";\nimport { getCapPoints, getJoinPoints, intersectLines, signedTurn } from \"./offsetJoin.ts\";\nimport type { OffsetPoint } from \"./offsetJoin.ts\";\n\n/**\n * The options of the path offsetting, with the defaults applied.\n */\ntype ResolvedOptions = {\n /** The side of the path to offset. */\n side: OffsetSide;\n /** The join type at a corner. */\n join: OffsetJoin;\n /** The ratio of the miter length to the offset distance. */\n miterLimit: number;\n /** The cap type at the end of an open path. */\n cap: OffsetCap;\n /** The number of the intervals a curve is sampled with. */\n steps: number;\n /** The number of the decimals of the result. */\n precision: number;\n};\n\n/** The sides an offset can be created on. */\nconst sides: OffsetSide[] = [\"left\", \"right\", \"both\"];\n/** The join types of an offset. */\nconst joins: OffsetJoin[] = [\"round\", \"miter\", \"bevel\"];\n/** The cap types of an offset. */\nconst caps: OffsetCap[] = [\"butt\", \"square\", \"round\"];\n\n/**\n * Returns the options of the path offsetting, with the defaults applied.\n *\n * @param options - the options of the offset\n * @returns the resolved options\n */\nconst resolveOptions = (options: OffsetOptions): ResolvedOptions => {\n const {\n side = \"left\",\n join = \"miter\",\n miterLimit = 4,\n cap = \"butt\",\n steps = 16,\n precision = 4,\n } = options;\n\n if (!sides.includes(side)) {\n throw TypeError(`${error}: side must be one of \"left\", \"right\" or \"both\"`);\n }\n if (!joins.includes(join)) {\n throw TypeError(`${error}: join must be one of \"round\", \"miter\" or \"bevel\"`);\n }\n if (!caps.includes(cap)) {\n throw TypeError(`${error}: cap must be one of \"butt\", \"square\" or \"round\"`);\n }\n if (typeof miterLimit !== \"number\" || !Number.isFinite(miterLimit) || miterLimit <= 0) {\n throw TypeError(`${error}: miterLimit must be a positive number`);\n }\n if (!Number.isInteger(steps) || steps < 1) {\n throw TypeError(`${error}: steps must be an integer greater than 0`);\n }\n if (!Number.isInteger(precision) || precision < 0) {\n throw TypeError(`${error}: precision must be an integer of 0 or more`);\n }\n\n return { side, join, miterLimit, cap, steps, precision };\n};\n\n/**\n * Groups the measured segments of a path into its sub-paths.\n *\n * @param measures - the measured segments of the path\n * @returns the measured segments of every sub-path\n */\nconst groupSubPaths = (measures: SegmentMeasure[]): SegmentMeasure[][] => {\n const groups: SegmentMeasure[][] = [];\n let group: SegmentMeasure[] = [];\n\n for (const measure of measures) {\n if (measure.geometry[0] === \"M\" && group.length) {\n groups.push(group);\n group = [];\n }\n group.push(measure);\n }\n if (group.length) groups.push(group);\n\n return groups;\n};\n\n/**\n * Returns the offset polyline of one side of a sub-path.\n *\n * Every node is shifted along the normal of the path. At a corner the two\n * offset lines meet: on the outer side of the turn the join is applied, and\n * on the inner side of the turn the offset lines cross before the corner, so\n * the curve is trimmed at their intersection.\n *\n * @param nodes - the sampled points of the sub-path\n * @param side - `1` for the left side of the path, `-1` for the right side\n * @param distance - the offset distance\n * @param options - the resolved options of the offset\n * @param closed - whether the sub-path is closed\n * @returns the points of the offset polyline\n */\nconst buildSidePolyline = (\n nodes: OffsetNode[],\n side: number,\n distance: number,\n options: ResolvedOptions,\n closed: boolean,\n): PointTuple[] => {\n const { join, miterLimit } = options;\n const offsets: OffsetPoint[] = nodes.map((node) => ({\n x: node.x - side * node.ty * distance,\n y: node.y + side * node.tx * distance,\n tx: node.tx,\n ty: node.ty,\n }));\n const points: PointTuple[] = [[offsets[0].x, offsets[0].y]];\n\n for (let i = 1; i < offsets.length; i += 1) {\n const from = offsets[i - 1];\n const to = offsets[i];\n let trimmed = false;\n\n if (nodes[i].corner) {\n const turn = signedTurn(from, to);\n if (Math.abs(turn) > 1e-9) {\n if (side * turn < 0) {\n points.push(\n ...getJoinPoints(nodes[i].x, nodes[i].y, from, to, distance, join, miterLimit),\n );\n } else {\n const intersection = intersectLines(\n from.x,\n from.y,\n from.tx,\n from.ty,\n to.x,\n to.y,\n to.tx,\n to.ty,\n );\n if (intersection) {\n points[points.length - 1] = intersection;\n // the closing corner of a closed sub-path trims the first point\n // of the path as well\n if (closed && i === offsets.length - 1) points[0] = intersection;\n trimmed = true;\n }\n }\n }\n }\n\n if (!trimmed) {\n const point: PointTuple = [to.x, to.y];\n // a corner without a turn does not move the path\n if (!samePoint(points[points.length - 1], point)) points.push(point);\n }\n }\n\n return points;\n};\n\n/**\n * Returns whether two points are the same point.\n *\n * @param a - the first point\n * @param b - the second point\n * @returns whether the points are the same\n */\nconst samePoint = (a: PointTuple, b: PointTuple): boolean =>\n Math.abs(a[0] - b[0]) < 1e-9 && Math.abs(a[1] - b[1]) < 1e-9;\n\n/**\n * Returns a coordinate of the result, rounded and without a negative zero.\n *\n * @param value - the coordinate\n * @param precision - the number of the decimals of the result\n * @returns the rounded coordinate\n */\nconst roundCoordinate = (value: number, precision: number): number =>\n cleanZero(roundTo(value, precision));\n\n/**\n * Returns the segments of an offset polyline.\n *\n * @param points - the points of the polyline\n * @param closed - whether the polyline is closed\n * @param precision - the number of the decimals of the result\n * @returns the segments of the polyline\n */\nconst toSegments = (points: PointTuple[], closed: boolean, precision: number): PathSegment[] => {\n const last = points[points.length - 1];\n // a closed polyline ends where it starts, the closing segment is enough\n const list =\n closed && points.length > 1 && samePoint(points[0], last) ? points.slice(0, -1) : points;\n const segments: PathSegment[] = [];\n\n // the polyline always holds at least one point\n /* istanbul ignore next */\n if (!list.length) return segments;\n\n segments.push([\n \"M\",\n roundCoordinate(list[0][0], precision),\n roundCoordinate(list[0][1], precision),\n ]);\n for (let i = 1; i < list.length; i += 1) {\n segments.push([\n \"L\",\n roundCoordinate(list[i][0], precision),\n roundCoordinate(list[i][1], precision),\n ]);\n }\n if (closed) segments.push([\"Z\"]);\n\n return segments;\n};\n\n/**\n * Offsets a path along its normals.\n *\n * The path is sampled along its length, every sample is shifted along the\n * normal of the path and the result is a path of straight lines. The\n * corners of the path are joined with the `join` option, and the ends of an\n * open path are capped with the `cap` option.\n *\n * The `side` option is literal: the left side is the left normal of the\n * direction of travel, the same normal `getPropertiesAtLength()` returns.\n * The `both` side is the outline of the stroke, the band between the two\n * sides of the path.\n *\n * The offset is not cleaned up: an offset distance larger than the local\n * radius of curvature of the path produces a self-crossing curve.\n *\n * @param pathInput - the path string or `PathArray`\n * @param distance - the offset distance\n * @param options - the options of the offset\n * @returns the offset path\n *\n * @example\n * ```ts\n * offsetPath('M0 0L100 0', 10)\n * // => [['M', 0, 10], ['L', 100, 10]]\n * ```\n */\nexport const offsetPath = <T extends PathArray>(\n pathInput: string | T,\n distance: number,\n options?: OffsetOptions,\n): PathArray => {\n if (typeof distance !== \"number\" || !Number.isFinite(distance)) {\n throw TypeError(`${error}: distance must be a number`);\n }\n if (distance < 0) {\n throw TypeError(`${error}: distance must be a positive number`);\n }\n\n const resolved = resolveOptions(options ?? {});\n // a path without an offset is the path itself\n if (distance === 0) return parsePathString(pathInput) as PathArray;\n\n const measures = measureSegments(pathInput);\n const groups = groupSubPaths(measures);\n const result: PathSegment[] = [];\n\n for (const group of groups) {\n const nodes = getOffsetNodes(group, resolved.steps);\n const last = group[group.length - 1];\n const closed = Boolean(last && last.geometry[0] === \"Z\");\n\n // a sub-path without a drawable segment keeps its moveto\n if (!nodes.length) {\n const first = group[0];\n result.push([\"M\", first.endX, first.endY]);\n continue;\n }\n\n if (resolved.side === \"both\") {\n const left = buildSidePolyline(nodes, 1, distance, resolved, closed);\n const right = buildSidePolyline(nodes, -1, distance, resolved, closed);\n\n if (closed) {\n // the outline of a closed path is the outer ring and the inner ring,\n // the inner one is reversed so it is a hole\n const leftArea = Math.abs(polygonArea(left));\n const rightArea = Math.abs(polygonArea(right));\n const outer = leftArea >= rightArea ? left : right;\n const inner = leftArea >= rightArea ? right : left;\n result.push(...toSegments(outer, true, resolved.precision));\n result.push(...toSegments([...inner].reverse(), true, resolved.precision));\n continue;\n }\n\n // the outline of an open path is the left side, the cap at the end of\n // the path, the right side backwards and the cap at the start\n const start = nodes[0];\n const end = nodes[nodes.length - 1];\n const endCap = getCapPoints(\n end.x,\n end.y,\n left[left.length - 1],\n right[right.length - 1],\n distance,\n resolved.cap,\n end.tx,\n end.ty,\n );\n const startCap = getCapPoints(\n start.x,\n start.y,\n right[0],\n left[0],\n distance,\n resolved.cap,\n -start.tx,\n -start.ty,\n );\n const ring = [...left, ...endCap, ...[...right].reverse(), ...startCap];\n result.push(...toSegments(ring, true, resolved.precision));\n continue;\n }\n\n const side = resolved.side === \"left\" ? 1 : -1;\n const polyline = buildSidePolyline(nodes, side, distance, resolved, closed);\n result.push(...toSegments(polyline, closed, resolved.precision));\n }\n\n return result as PathArray;\n};\n","import { defaultOptions } from \"../options/options.ts\";\nimport type { ParserParams } from \"../interface.ts\";\nimport { roundTo } from \"../math/roundTo.ts\";\nimport type {\n AbsoluteSegment,\n NormalSegment,\n PathCommand,\n ShortSegment,\n SSegment,\n TSegment,\n} from \"../types.ts\";\n\n/**\n * Shorten a single segment of a `pathArray` object.\n *\n * @param segment the `absoluteSegment` object\n * @param normalSegment the `normalSegment` object\n * @param params the coordinates of the previous segment\n * @param prevCommand the path command of the previous segment\n * @returns the shortened segment\n */\nexport const shortenSegment = (\n segment: AbsoluteSegment,\n normalSegment: NormalSegment,\n params: ParserParams,\n prevCommand: PathCommand,\n): ShortSegment => {\n const [pathCommand] = segment;\n const { round: defaultRound } = defaultOptions;\n const round = typeof defaultRound === \"number\" ? defaultRound : /* istanbul ignore next */ 4;\n const normalValues = normalSegment.slice(1) as number[];\n const { x2, y2, x, y } = params;\n const [nx, ny] = normalValues.slice(-2);\n const result = segment;\n\n if (!\"TQ\".includes(pathCommand)) {\n // optional but good to be cautious\n params.qx = null;\n params.qy = null;\n }\n\n if (pathCommand === \"L\") {\n if (roundTo(x, round) === roundTo(nx, round)) {\n return [\"V\", ny];\n } else if (roundTo(y, round) === roundTo(ny, round)) {\n return [\"H\", nx];\n }\n } else if (pathCommand === \"C\") {\n const [nx1, ny1] = normalValues;\n\n if (\n \"CS\".includes(prevCommand) &&\n x2 != null &&\n y2 != null &&\n roundTo(nx1, round) === roundTo(x * 2 - x2, round) &&\n roundTo(ny1, round) === roundTo(y * 2 - y2, round)\n ) {\n return [\"S\", normalValues[2], normalValues[3], normalValues[4], normalValues[5]] as SSegment;\n }\n } else if (pathCommand === \"Q\") {\n const [qx, qy] = normalValues;\n params.qx = qx;\n params.qy = qy;\n\n if (\n \"QT\".includes(prevCommand) &&\n x2 != null &&\n y2 != null &&\n roundTo(qx, round) === roundTo(x * 2 - x2, round) &&\n roundTo(qy, round) === roundTo(y * 2 - y2, round)\n ) {\n return [\"T\", normalValues[2], normalValues[3]] as TSegment;\n }\n }\n\n // ['V', 'H', 'S', 'T', 'Z'].includes(pathCommand)\n return result as ShortSegment;\n};\n","import type { PathSegment } from \"../types.ts\";\nimport { roundTo } from \"../math/roundTo.ts\";\n\n/**\n * Rounds the numeric values of a path segment to the specified precision.\n *\n * @param segment - The path segment to round\n * @param roundOption - Number of decimal places\n * @returns The rounded segment\n */\nexport const roundSegment = <T extends PathSegment>(segment: T, roundOption: number): T => {\n // the rounded segment is built in one pass: a copy of the segment, a map\n // over its values and a concatenation would allocate three arrays\n const result = Array.from({ length: segment.length }) as unknown as T;\n for (let i = 0; i < segment.length; i += 1) {\n result[i] = (i === 0 ? segment[0] : roundTo(segment[i] as number, roundOption)) as T[number];\n }\n return result;\n};\n","import type { PathSegment } from \"../types.ts\";\n\n/**\n * Returns the length of the string representation of a path segment.\n *\n * The string of a segment is its command followed by its values, without a\n * separator, so its length is the length of the command plus the length of\n * every value. The string itself is not needed to know its length, so it is\n * not built.\n *\n * @param segment - The path segment to measure\n * @returns The length of the string of the segment\n */\nexport const segmentStringLength = (segment: PathSegment): number => {\n let length = String(segment[0]).length;\n for (let i = 1; i < segment.length; i += 1) {\n length += String(segment[i]).length;\n }\n return length;\n};\n","import type { AbsoluteSegment, PathArray, PathCommand, PathSegment } from \"../types.ts\";\nimport { pathToAbsolute } from \"../convert/pathToAbsolute.ts\";\nimport { shortenSegment } from \"./shortenSegment.ts\";\nimport { paramsParser } from \"../parser/paramsParser.ts\";\nimport { iterate } from \"./iterate.ts\";\nimport { normalizeSegment } from \"./normalizeSegment.ts\";\nimport { relativizeSegment } from \"./relativizeSegment.ts\";\nimport { roundSegment } from \"./roundSegment.ts\";\nimport { segmentStringLength } from \"./segmentStringLength.ts\";\n\n/**\n * Optimizes a PathArray:\n * * converts segments to shorthand if possible\n * * selects shortest representation from absolute and relative forms\n *\n * @param pathInput - A path string or PathArray\n * @param roundOption - Number of decimal places for rounding\n * @returns The optimized PathArray\n *\n * @example\n * ```ts\n * optimizePath('M10 10L10 10L90 90', 2)\n * // => [['M', 10, 10], ['v', 0], ['l', 80, 80]]\n * ```\n */\nexport const optimizePath = <T extends string | PathArray>(\n pathInput: T,\n roundOption?: number,\n): PathArray => {\n const path = pathToAbsolute(pathInput);\n // allow for ZERO decimals or use an aggressive value of 2\n const round = typeof roundOption === \"number\" && roundOption >= 0 ? roundOption : 2;\n // this utility overrides the iterator params\n const optimParams = { ...paramsParser };\n\n const allPathCommands = [] as PathCommand[];\n let pathCommand = \"M\" as PathCommand;\n let prevCommand = \"Z\" as PathCommand;\n\n return iterate(path, (seg, i, lastX, lastY) => {\n optimParams.x = lastX;\n optimParams.y = lastY;\n let result: PathSegment = seg;\n pathCommand = seg[0];\n\n // Save current path command\n allPathCommands[i] = pathCommand;\n if (i) {\n // Get previous path command for `shortenSegment`\n prevCommand = allPathCommands[i - 1];\n }\n const normalizedSegment = normalizeSegment(seg, optimParams, i ? prevCommand : null);\n if (i) {\n const shortSegment = shortenSegment(\n seg as AbsoluteSegment,\n normalizedSegment,\n optimParams,\n prevCommand,\n );\n const absSegment = roundSegment(shortSegment, round);\n const absLength = segmentStringLength(absSegment);\n const relativeSegment = relativizeSegment(shortSegment, i, lastX, lastY);\n const relSegment = roundSegment(relativeSegment, round);\n const relLength = segmentStringLength(relSegment);\n result = absLength < relLength ? absSegment : relSegment;\n }\n\n const seglen = normalizedSegment.length;\n optimParams.x1 = +normalizedSegment[seglen - 2];\n optimParams.y1 = +normalizedSegment[seglen - 1];\n // only cubic and quadratic segments carry a reflectable control point\n if (normalizedSegment[0] === \"C\" || normalizedSegment[0] === \"Q\") {\n optimParams.x2 = +normalizedSegment[seglen - 4];\n optimParams.y2 = +normalizedSegment[seglen - 3];\n } else {\n optimParams.x2 = null;\n optimParams.y2 = null;\n }\n\n return result;\n });\n};\n","import type { PathArray } from \"../types.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { pathToAbsolute } from \"../convert/pathToAbsolute.ts\";\n\n/**\n * Joins two paths into a single path with two sub-paths.\n *\n * Both paths have to be valid paths, so they begin with a moveto command,\n * and the result holds absolute values.\n *\n * @param pathA - the first path string or `PathArray`\n * @param pathB - the second path string or `PathArray`\n * @returns the joined path\n *\n * @example\n * ```ts\n * joinPath('M0 0L100 0', 'M0 100L100 100')\n * // => [\n * // ['M', 0, 0], ['L', 100, 0],\n * // ['M', 0, 100], ['L', 100, 100]\n * // ]\n * ```\n */\nexport const joinPath = (pathA: string | PathArray, pathB: string | PathArray): PathArray => {\n const first = pathToAbsolute(parsePathString(pathA));\n const second = pathToAbsolute(parsePathString(pathB));\n\n return [...first, ...second] as PathArray;\n};\n","import type {\n // ASegment,\n CSegment,\n // HSegment,\n // MSegment,\n PathArray,\n PathSegment,\n PointTuple,\n QSegment,\n SSegment,\n TSegment,\n // VSegment,\n} from \"../types.ts\";\nimport { pathToAbsolute } from \"../convert/pathToAbsolute.ts\";\nimport { normalizePath } from \"./normalizePath.ts\";\nimport { iterate } from \"./iterate.ts\";\n\n/**\n * Reverses the segments of a single sub-path and returns a new PathArray\n * with absolute values.\n *\n * @param absolutePath - The absolute PathArray of a single sub-path\n * @returns The reversed PathArray\n */\nconst reverseSubPath = (absolutePath: PathArray): PathArray => {\n const normalizedPath = normalizePath(absolutePath);\n const pLen = absolutePath.length;\n const isClosed = absolutePath[pLen - 1][0] === \"Z\";\n\n // the end point of every normalized segment, the closing point of a\n // subpath is its starting point, so a segment following a `Z` starts\n // where the `Z` ends, not where the previous segment ended\n const endPoints: PointTuple[] = [];\n let endX = 0;\n let endY = 0;\n let subX = 0;\n let subY = 0;\n for (const seg of normalizedPath) {\n if (seg[0] === \"M\") {\n subX = +seg[1];\n subY = +seg[2];\n endX = subX;\n endY = subY;\n } else if (seg[0] === \"Z\") {\n endX = subX;\n endY = subY;\n } else {\n endX = +seg[seg.length - 2];\n endY = +seg[seg.length - 1];\n }\n endPoints.push([endX, endY]);\n }\n\n const reversedPath = iterate(absolutePath, (segment, i) => {\n const normalizedSegment = normalizedPath[i];\n const prevSeg = i && absolutePath[i - 1];\n const prevCommand = prevSeg && prevSeg[0];\n const nextSeg = absolutePath[i + 1];\n const nextCommand = nextSeg && nextSeg[0];\n const pathCommand = segment[0];\n const [x, y] = endPoints[i ? i - 1 : pLen - 1];\n let result = segment;\n\n switch (pathCommand) {\n case \"M\":\n result = isClosed ? [\"Z\"] : [pathCommand, x, y];\n break;\n case \"A\":\n result = [\n pathCommand,\n segment[1],\n segment[2],\n segment[3],\n segment[4],\n segment[5] === 1 ? 0 : 1,\n x,\n y,\n ];\n break;\n case \"C\":\n if (nextSeg && nextCommand === \"S\") {\n result = [\"S\", segment[1], segment[2], x, y];\n } else {\n result = [pathCommand, segment[3], segment[4], segment[1], segment[2], x, y];\n }\n break;\n case \"S\":\n // the control points can stay implicit only when the next segment\n // is an `S` as well, the reflected control point of the reversed\n // segment is then recovered from the previous segment of the\n // reversed path\n if (nextSeg && nextCommand === \"S\") {\n result = [pathCommand, normalizedSegment[1], normalizedSegment[2], x, y] as SSegment;\n } else {\n result = [\n \"C\",\n normalizedSegment[3],\n normalizedSegment[4],\n normalizedSegment[1],\n normalizedSegment[2],\n x,\n y,\n ] as CSegment;\n }\n break;\n case \"Q\":\n if (nextSeg && nextCommand === \"T\") {\n result = [\"T\", x, y] as TSegment;\n } else {\n result = [pathCommand, segment[1], segment[2], x, y];\n }\n break;\n case \"T\": {\n // the `T` shorthand reflects the control point of the previous\n // segment of the *reversed* path, which is the original successor\n // - when that successor is a `Q`, the shorthand would reflect the\n // `Q`'s control point instead of this segment's own control point\n // and silently change the curve\n const prevIsQuad = Boolean(prevCommand && \"QT\".includes(prevCommand));\n const nextIsT = Boolean(nextSeg && nextCommand === \"T\");\n const nextIsQuad = Boolean(nextSeg && nextCommand === \"Q\");\n if (nextIsT || (!prevIsQuad && !nextIsQuad)) {\n result = [pathCommand, x, y] as TSegment;\n } else {\n result = [\"Q\", normalizedSegment[1], normalizedSegment[2], x, y] as QSegment;\n }\n break;\n }\n case \"Z\":\n result = [\"M\", x, y];\n break;\n case \"H\":\n result = [pathCommand, x];\n break;\n case \"V\":\n result = [pathCommand, y];\n break;\n default:\n result = [pathCommand as typeof pathCommand | number].concat(\n segment.slice(1, -2),\n x,\n y,\n ) as typeof segment;\n }\n\n return result;\n });\n\n return (\n isClosed\n ? reversedPath.reverse()\n : [reversedPath[0] as PathSegment].concat(reversedPath.slice(1).reverse())\n ) as PathArray;\n};\n\n/**\n * Reverses all segments of a PathArray and returns a new PathArray\n * with absolute values.\n *\n * Every sub-path is reversed on its own, so the `M` and the `Z` of a\n * sub-path are swapped with each other and the sub-paths keep their\n * original order.\n *\n * @param pathInput - The source PathArray\n * @returns The reversed PathArray\n *\n * @example\n * ```ts\n * reversePath([['M', 0, 0], ['L', 100, 0], ['L', 100, 100], ['L', 0, 100], ['Z']])\n * // => [['M', 0, 100], ['L', 100, 100], ['L', 100, 0], ['L', 0, 0], ['Z']]\n * ```\n */\nexport const reversePath = <T extends PathArray>(pathInput: T | string): T => {\n const absolutePath = pathToAbsolute(pathInput);\n const subPaths: PathSegment[][] = [];\n let subPath: PathSegment[] = [];\n\n for (const segment of absolutePath) {\n if (segment[0] === \"M\" && subPath.length) {\n subPaths.push(subPath);\n subPath = [];\n }\n subPath.push(segment);\n }\n if (subPath.length) {\n subPaths.push(subPath);\n }\n\n const reversed = subPaths.map((path) => reverseSubPath(path as PathArray));\n\n return (reversed.length === 1 ? reversed[0] : reversed.flat()) as T;\n};\n","// import paramsParser from \"../parser/paramsParser.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport type {\n AbsoluteCommand,\n HSegment,\n MSegment,\n PathArray,\n PathSegment,\n PointTuple,\n VSegment,\n} from \"../types.ts\";\nimport { iterate } from \"./iterate.ts\";\nimport { absolutizeSegment } from \"./absolutizeSegment.ts\";\n\n/**\n * Split a path string or PathArray into an array of sub-paths.\n *\n * In the process, values are converted to absolute\n * for visual consistency.\n *\n * A path must begin with a moveto command, so a path that does not is\n * rejected by the parser.\n *\n * @param pathInput - The source path string or PathArray\n * @returns An array of sub-path PathArrays\n *\n * @example\n * ```ts\n * splitPath('M0 0L100 0ZM200 0L300 0Z')\n * // => [\n * // [['M', 0, 0], ['L', 100, 0], ['Z']],\n * // [['M', 200, 0], ['L', 300, 0], ['Z']]\n * // ]\n * ```\n */\nexport const splitPath = <T extends PathArray>(pathInput: T | string): T[] => {\n const composite: T[] = [];\n const parsedPath = parsePathString(pathInput);\n const segments: PathArray = parsedPath;\n let path = [] as unknown as T;\n let pi = -1;\n let x = 0;\n let y = 0;\n let mx = 0;\n let my = 0;\n\n iterate(segments, (seg, _index, prevX, prevY) => {\n const cmd = seg[0];\n const absCommand = cmd.toUpperCase() as AbsoluteCommand;\n const isRelative = cmd === cmd.toLowerCase();\n const values = seg.slice(1) as number[];\n\n if (absCommand === \"M\") {\n pi += 1;\n\n [x, y] = values as PointTuple;\n x += isRelative ? prevX : 0;\n y += isRelative ? prevY : 0;\n mx = x;\n my = y;\n // the moveto is always absolute, even when the source is relative\n path = [[\"M\", x, y] as MSegment] as unknown as T;\n } else {\n if (absCommand === \"Z\") {\n x = mx;\n y = my;\n } else if (absCommand === \"H\") {\n [, x] = seg as HSegment;\n x += isRelative ? prevX : /* istanbul ignore next */ 0;\n } else if (absCommand === \"V\") {\n [, y] = seg as VSegment;\n y += isRelative ? prevY : /* istanbul ignore next */ 0;\n } else {\n [x, y] = seg.slice(-2) as PointTuple;\n x += isRelative ? prevX : 0;\n y += isRelative ? prevY : 0;\n }\n path.push(absolutizeSegment(seg, _index, prevX, prevY) as PathSegment);\n }\n\n composite[pi] = path;\n });\n\n return composite;\n};\nexport default splitPath;\n","import type { PathArray } from \"../types.ts\";\nimport { error } from \"../util/error.ts\";\nimport { splitPath } from \"./splitPath.ts\";\nimport { reversePath } from \"./reversePath.ts\";\n\n/**\n * Reverses the sub-path at a given index of a path.\n *\n * The other sub-paths are left untouched, and the result holds absolute\n * values.\n *\n * @param pathInput - the path string or `PathArray`\n * @param index - the zero-based index of the sub-path to reverse\n * @returns the path with the sub-path reversed\n *\n * @example\n * ```ts\n * reverseSubPath('M0 0L100 0ZM0 100L100 100', 1)\n * // => [\n * // ['M', 0, 0], ['L', 100, 0], ['Z'],\n * // ['M', 100, 100], ['L', 0, 100]\n * // ]\n * ```\n */\nexport const reverseSubPath = (pathInput: string | PathArray, index: number): PathArray => {\n const subPaths = splitPath(pathInput);\n\n if (!Number.isInteger(index) || index < 0 || index >= subPaths.length) {\n throw TypeError(`${error}: index must be a number within the range of the sub-paths`);\n }\n\n const reversed = reversePath(subPaths[index] as PathArray);\n\n return [...subPaths.slice(0, index), reversed, ...subPaths.slice(index + 1)].flat() as PathArray;\n};\n","import CSSMatrix from \"@thednp/dommatrix\";\nimport { defaultOptions } from \"../options/options.ts\";\nimport type { TransformObject } from \"../interface.ts\";\n\n/**\n * Returns a transformation matrix to apply to `<path>` elements.\n *\n * @see TransformObject\n *\n * @param transform the `transformObject`\n * @returns a new transformation matrix\n */\nexport const getSVGMatrix = (transform: Partial<TransformObject>): CSSMatrix => {\n let matrix = new CSSMatrix();\n // the transform origin is always needed, fall back to the default one\n const origin = (transform.origin ?? defaultOptions.origin) as [number, number, number];\n const [originX, originY] = origin;\n const { translate, rotate, skew, scale } = transform;\n\n // set translate\n if (\n Array.isArray(translate) &&\n translate.length >= 2 &&\n translate.every((x) => !Number.isNaN(+x)) &&\n translate.some((x) => x !== 0)\n ) {\n matrix = matrix.translate(...(translate as [number, number, number?]));\n } else if (typeof translate === \"number\" && !Number.isNaN(translate)) {\n matrix = matrix.translate(translate);\n }\n\n if (rotate || skew || scale) {\n // set SVG transform-origin, always defined\n matrix = matrix.translate(originX, originY);\n\n // set rotation\n if (\n Array.isArray(rotate) &&\n rotate.length >= 2 &&\n rotate.every((x) => !Number.isNaN(+x)) &&\n rotate.some((x) => x !== 0)\n ) {\n matrix = matrix.rotate(...(rotate as [number, number, number?]));\n } else if (typeof rotate === \"number\" && !Number.isNaN(rotate)) {\n matrix = matrix.rotate(rotate);\n }\n\n // set skew(s)\n if (\n Array.isArray(skew) &&\n skew.length === 2 &&\n skew.every((x) => !Number.isNaN(+x)) &&\n skew.some((x) => x !== 0)\n ) {\n matrix = skew[0] ? matrix.skewX(skew[0]) : matrix;\n matrix = skew[1] ? matrix.skewY(skew[1]) : matrix;\n } else if (typeof skew === \"number\" && !Number.isNaN(skew)) {\n matrix = matrix.skewX(skew);\n }\n\n // set scale\n if (\n Array.isArray(scale) &&\n scale.length >= 2 &&\n scale.every((x) => !Number.isNaN(+x)) &&\n scale.some((x) => x !== 1)\n ) {\n matrix = matrix.scale(...(scale as [number, number, number?]));\n } else if (typeof scale === \"number\" && !Number.isNaN(scale)) {\n matrix = matrix.scale(scale);\n }\n // set SVG transform-origin\n matrix = matrix.translate(-originX, -originY);\n }\n\n return matrix;\n};\n","import CSSMatrix from \"@thednp/dommatrix\";\nimport type { PointTuple } from \"../types.ts\";\n\n/**\n * Transforms a specified point using a matrix, returning a new\n * Tuple *Object* comprising of the transformed point.\n * Neither the matrix nor the original point are altered.\n *\n * @copyright thednp © 2021\n *\n * @param cssm CSSMatrix instance\n * @param v Tuple\n * @returns the resulting Tuple\n */\nconst translatePoint = (\n cssm: CSSMatrix,\n v: [number, number, number, number],\n): [number, number, number, number] => {\n if (cssm.is2D) {\n return [\n cssm.a * v[0] + cssm.c * v[1] + cssm.e * v[3],\n cssm.b * v[0] + cssm.d * v[1] + cssm.f * v[3],\n 0,\n 1,\n ];\n }\n\n let m = CSSMatrix.Translate(v[0], v[1], v[2]);\n\n [, , , m.m44] = v;\n m = cssm.multiply(m);\n\n return [m.m41, m.m42, m.m43, m.m44];\n};\n\n/**\n * Returns the [x,y] projected coordinates for a given an [x,y] point\n * and an [x,y,z] perspective origin point.\n *\n * Equation found here =>\n * http://en.wikipedia.org/wiki/3D_projection#Diagram\n * Details =>\n * https://stackoverflow.com/questions/23792505/predicted-rendering-of-css-3d-transformed-pixel\n *\n * @param m the transformation matrix\n * @param point2D the initial [x,y] coordinates\n * @param origin the [x,y,z] transform origin\n * @returns the projected [x,y] coordinates\n */\nexport const projection2d = (\n m: CSSMatrix,\n point2D: PointTuple,\n origin: [number, number, number],\n): PointTuple => {\n const [originX, originY, originZ] = origin;\n const [x, y, z] = translatePoint(m, [point2D[0], point2D[1], 0, 1]);\n\n const relativePositionX = x - originX;\n const relativePositionY = y - originY;\n const relativePositionZ = z - originZ;\n\n // protect against division by ZERO, and against a zero origin distance\n // which means there is no perspective scaling at all\n const numerator = Math.abs(originZ);\n const denominator = Math.abs(relativePositionZ);\n const factor = numerator === 0 || denominator === 0 ? 1 : numerator / denominator;\n\n return [relativePositionX * factor + originX, relativePositionY * factor + originY];\n};\n","import { getSVGMatrix } from \"./getSVGMatrix.ts\";\nimport { projection2d } from \"./projection2d.ts\";\nimport { defaultOptions } from \"../options/options.ts\";\nimport type {\n AbsoluteArray,\n AbsoluteCommand,\n AbsoluteSegment,\n CSegment,\n HSegment,\n LSegment,\n PathArray,\n PathSegment,\n VSegment,\n} from \"../types.ts\";\nimport type { TransformObject } from \"../interface.ts\";\nimport { iterate } from \"./iterate.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { absolutizeSegment } from \"./absolutizeSegment.ts\";\nimport { arcToCubic } from \"./arcToCubic.ts\";\n\n/**\n * Applies a 2D transformation to a `PathArray` in a single pass, without\n * absolutizing or copying each segment, returning a new absolute `PathArray`.\n *\n * @param path the parsed path value\n * @param a the `a` value of the matrix\n * @param b the `b` value of the matrix\n * @param c the `c` value of the matrix\n * @param d the `d` value of the matrix\n * @param e the `e` value of the matrix\n * @param f the `f` value of the matrix\n * @param originX the transform origin `x` value\n * @param originY the transform origin `y` value\n * @returns the transformed absolute path\n */\nconst transform2D = (\n path: PathArray,\n a: number,\n b: number,\n c: number,\n d: number,\n e: number,\n f: number,\n originX: number,\n originY: number,\n): AbsoluteArray => {\n const result = [] as unknown as AbsoluteArray;\n let x = 0;\n let y = 0;\n let lx = 0;\n let ly = 0;\n let ox = 0;\n let oy = 0;\n let omx = 0;\n let omy = 0;\n\n for (let i = 0, len = path.length; i < len; i += 1) {\n const seg = path[i] as PathSegment;\n const pathCommand = seg[0] as string;\n const commandCode = pathCommand.charCodeAt(0);\n const isRelative = commandCode >= 97;\n const absCommand = (\n isRelative ? String.fromCharCode(commandCode - 32) : pathCommand\n ) as AbsoluteCommand;\n // the parser rewrites a leading relative moveto as an absolute one, so\n // the first segment is always absolute here\n const outCommand = absCommand;\n\n if (absCommand === \"Z\") {\n result.push([\"Z\"] as AbsoluteSegment);\n ox = omx;\n oy = omy;\n continue;\n }\n\n if (absCommand === \"V\") {\n const absY = (seg[1] as number) + (isRelative ? oy : 0);\n lx = a * ox + c * absY + e - originX + originX;\n ly = b * ox + d * absY + f - originY + originY;\n /* istanbul ignore else */\n if (x !== lx && y !== ly) {\n result.push([\"L\", lx, ly] as LSegment);\n } else if (y === ly) {\n result.push([\"H\", lx] as HSegment);\n } else if (x === lx) {\n result.push([\"V\", ly] as VSegment);\n } else {\n result.push([\"L\", ox, absY] as LSegment);\n }\n oy = absY;\n x = lx;\n y = ly;\n continue;\n }\n\n if (absCommand === \"H\") {\n const absX = (seg[1] as number) + (isRelative ? ox : 0);\n lx = a * absX + c * oy + e - originX + originX;\n ly = b * absX + d * oy + f - originY + originY;\n /* istanbul ignore else */\n if (x !== lx && y !== ly) {\n result.push([\"L\", lx, ly] as LSegment);\n } else if (y === ly) {\n result.push([\"H\", lx] as HSegment);\n } else if (x === lx) {\n result.push([\"V\", ly] as VSegment);\n } else {\n result.push([\"L\", absX, oy] as LSegment);\n }\n ox = absX;\n x = lx;\n y = ly;\n continue;\n }\n\n if (absCommand === \"A\") {\n const absX = (seg[6] as number) + (isRelative ? ox : 0);\n const absY = (seg[7] as number) + (isRelative ? oy : 0);\n const cubics = arcToCubic(\n ox,\n oy,\n seg[1] as number,\n seg[2] as number,\n seg[3] as number,\n seg[4] as number,\n seg[5] as number,\n absX,\n absY,\n );\n const cubicsLen = cubics.length;\n let k = 0;\n /* istanbul ignore else */\n if (cubicsLen > 0) {\n do {\n const piece = [\"C\"] as unknown as CSegment;\n const end = k + 6;\n for (let j = k; j < end; j += 2) {\n lx = a * cubics[j] + c * cubics[j + 1] + e - originX + originX;\n ly = b * cubics[j] + d * cubics[j + 1] + f - originY + originY;\n piece.push(lx, ly);\n }\n result.push(piece);\n k = end;\n } while (k < cubicsLen);\n } else {\n /* istanbul ignore next */\n result.push([\"C\"] as unknown as AbsoluteSegment);\n }\n /* istanbul ignore else */\n if (cubicsLen > 0) {\n ox = cubics[cubicsLen - 2];\n oy = cubics[cubicsLen - 1];\n } else {\n /* istanbul ignore next */\n ox = absX;\n /* istanbul ignore next */\n oy = absY;\n }\n x = lx;\n y = ly;\n continue;\n }\n\n if (absCommand === \"L\") {\n const absX = (seg[1] as number) + (isRelative ? ox : 0);\n const absY = (seg[2] as number) + (isRelative ? oy : 0);\n lx = a * absX + c * absY + e - originX + originX;\n ly = b * absX + d * absY + f - originY + originY;\n /* istanbul ignore else */\n if (x !== lx && y !== ly) {\n result.push([\"L\", lx, ly] as LSegment);\n } else if (y === ly) {\n result.push([\"H\", lx] as HSegment);\n } else if (x === lx) {\n result.push([\"V\", ly] as VSegment);\n } else {\n result.push([\"L\", absX, absY] as LSegment);\n }\n ox = absX;\n oy = absY;\n x = lx;\n y = ly;\n continue;\n }\n\n {\n const piece = [outCommand] as [AbsoluteCommand, ...number[]];\n const segLen = seg.length;\n for (let j = 1; j < segLen; j += 2) {\n const absX = (seg[j] as number) + (isRelative ? ox : 0);\n const absY = (seg[j + 1] as number) + (isRelative ? oy : 0);\n lx = a * absX + c * absY + e - originX + originX;\n ly = b * absX + d * absY + f - originY + originY;\n piece.push(lx, ly);\n }\n result.push(piece as AbsoluteSegment);\n ox = (seg[segLen - 2] as number) + (isRelative ? ox : 0);\n oy = (seg[segLen - 1] as number) + (isRelative ? oy : 0);\n if (absCommand === \"M\") {\n omx = ox;\n omy = oy;\n }\n x = lx;\n y = ly;\n }\n }\n\n return result;\n};\n\n/**\n * Apply a 2D / 3D transformation to a PathArray.\n *\n * Since SVGElement doesn't support 3D transformation, this function\n * creates a 2D projection of the path element.\n *\n * @param pathInput - The PathArray or path string to transform\n * @param transform - The transform functions object (translate, rotate, skew, scale, origin)\n * @returns The transformed PathArray\n *\n * @example\n * ```ts\n * transformPath('M0 0L100 0L100 100L0 100Z', { translate: [10, 20], scale: 2 })\n * // => [['M', 10, 20], ['H', 210], ['V', 220], ['H', 10], ['Z']]\n * ```\n */\nexport const transformPath = <T extends PathArray>(\n pathInput: T | string,\n transform?: Partial<TransformObject>,\n): T | AbsoluteArray => {\n // transform uses it's own set of params\n const path = parsePathString(pathInput);\n const transformProps = transform && Object.keys(transform);\n\n // when used as a static method, invalidate somehow\n if (!transform || (transformProps && !transformProps.length)) {\n return path.slice(0) as T;\n }\n\n // transform origin is extremely important, the caller's object must not\n // be modified and the global default must not be aliased\n const origin = (transform.origin ?? defaultOptions.origin).slice(0) as [number, number, number];\n const matrixInstance = getSVGMatrix({ ...transform, origin });\n\n if (matrixInstance.isIdentity) return path.slice(0) as T;\n\n if (matrixInstance.is2D) {\n return transform2D(\n path,\n matrixInstance.a,\n matrixInstance.b,\n matrixInstance.c,\n matrixInstance.d,\n matrixInstance.e,\n matrixInstance.f,\n origin[0],\n origin[1],\n );\n }\n\n // last x and y transformed values\n let x = 0;\n let y = 0;\n // new x and y transformed\n let lx = 0;\n let ly = 0;\n // segment params iteration index and length\n let j = 0;\n let jj = 0;\n\n return iterate(path, (seg, index, lastX, lastY) => {\n const [pathCommand] = seg;\n const absCommand = pathCommand.toUpperCase();\n const isRelative = absCommand !== pathCommand;\n const absoluteSegment = isRelative\n ? absolutizeSegment(seg, index, lastX, lastY)\n : (seg.slice(0) as AbsoluteSegment);\n\n let result =\n absCommand === \"A\"\n ? ([\"C\" as string | number].concat(\n arcToCubic(\n lastX,\n lastY,\n absoluteSegment[1] as number,\n absoluteSegment[2] as number,\n absoluteSegment[3] as number,\n absoluteSegment[4] as number,\n absoluteSegment[5] as number,\n absoluteSegment[6] as number,\n absoluteSegment[7] as number,\n ),\n ) as CSegment)\n : absCommand === \"V\"\n ? ([\"L\", lastX, absoluteSegment[1]] as LSegment)\n : absCommand === \"H\"\n ? ([\"L\", absoluteSegment[1], lastY] as LSegment)\n : absoluteSegment;\n\n // update pathCommand\n const isLongArc = result[0] === \"C\" && result.length > 7;\n\n if (isLongArc) {\n const tempSegment = result.slice(0, 7) as CSegment;\n path.splice(\n index + 1,\n 0,\n [\"C\" as (typeof result)[0] | number].concat(result.slice(7)) as CSegment,\n );\n result = tempSegment;\n }\n\n if (result[0] === \"L\") {\n [lx, ly] = projection2d(\n matrixInstance,\n [(result as LSegment)[1], (result as LSegment)[2]],\n origin,\n );\n\n /* istanbul ignore else */\n if (x !== lx && y !== ly) {\n result = [\"L\", lx, ly];\n } else if (y === ly) {\n result = [\"H\", lx];\n } else if (x === lx) {\n result = [\"V\", ly];\n }\n } else {\n for (j = 1, jj = result.length; j < jj; j += 2) {\n [lx, ly] = projection2d(matrixInstance, [+result[j], +result[j + 1]], origin);\n result[j] = lx;\n result[j + 1] = ly;\n }\n }\n // now update x and y\n x = lx;\n y = ly;\n\n return result;\n }) as AbsoluteArray;\n};\n","import type { CSegment, CurveArray, MSegment, PathCommand } from \"../types.ts\";\n\n/**\n * Reverses all segments of a `pathArray`\n * which consists of only C (cubic-bezier) path commands.\n *\n * @param path the source `pathArray`\n * @returns the reversed `pathArray`\n */\nexport const reverseCurve = (path: CurveArray): CurveArray => {\n const rotatedCurve = path\n .slice(1)\n .map((x, i, curveOnly) =>\n !i\n ? path[0].slice(1).concat(x.slice(1) as number[])\n : curveOnly[i - 1].slice(-2).concat(x.slice(1)),\n )\n .map((x) => x.map((_, i) => x[x.length - i - 2 * (1 - (i % 2))]))\n .reverse() as (MSegment | CSegment)[];\n\n return [[\"M\" as PathCommand | number].concat(rotatedCurve[0].slice(0, 2))].concat(\n rotatedCurve.map((x) => [\"C\" as PathCommand | number].concat(x.slice(2))),\n ) as CurveArray;\n};\n","import type { PathArray } from \"../types.ts\";\nimport { defaultOptions } from \"../options/options.ts\";\nimport { iterate } from \"./iterate.ts\";\nimport { roundSegment } from \"./roundSegment.ts\";\n\n/**\n * Rounds the values of a `pathArray` instance to\n * a specified amount of decimals and returns it.\n *\n * @param path the source `pathArray`\n * @param roundOption the amount of decimals to round numbers to\n * @returns the resulted `pathArray` with rounded values\n */\nexport const roundPath = <T extends PathArray>(path: T, roundOption?: number | \"off\"): T => {\n let { round } = defaultOptions;\n // allow for ZERO decimals\n round =\n roundOption === \"off\"\n ? roundOption\n : typeof roundOption === \"number\" && roundOption >= 0\n ? roundOption\n : typeof round === \"number\" && round >= 0\n ? round\n : \"off\";\n\n /* istanbul ignore else */\n if (round === \"off\") return path.slice(0) as T;\n\n // the caller's array must not be modified in place\n return iterate(path.slice(0) as T, (segment) => {\n return roundSegment(segment, round);\n });\n};\n","import type { NormalArray } from \"../types.ts\";\n\n/**\n * Splits a normalized path into its sub-paths.\n *\n * A sub-path begins with a moveto command, so the path is split at every\n * moveto: the close segment of a sub-path belongs to the sub-path it closes.\n *\n * @param path - the normalized path to split\n * @returns the sub-paths of the path\n *\n * @example\n * ```ts\n * splitSubPaths([[\"M\", 0, 0], [\"L\", 10, 0], [\"Z\"], [\"M\", 20, 0], [\"L\", 30, 0]]);\n * // => [\n * // [[\"M\", 0, 0], [\"L\", 10, 0], [\"Z\"]],\n * // [[\"M\", 20, 0], [\"L\", 30, 0]],\n * // ]\n * ```\n */\nexport const splitSubPaths = (path: NormalArray): NormalArray[] => {\n const result: NormalArray[] = [];\n let current: NormalArray = [] as unknown as NormalArray;\n for (const segment of path) {\n if (segment[0] === \"M\") {\n // the path is not empty, so the first sub-path is never missing\n if (current.length) result.push(current);\n current = [segment] as unknown as NormalArray;\n } else {\n current.push(segment);\n }\n }\n if (current.length) result.push(current);\n return result;\n};\n","import type { CubicCoordinates, NormalArray, Point, QuadCoordinates } from \"../types.ts\";\nimport { buildPathLengthTable } from \"../util/pathLengthTable.ts\";\nimport { getPointAtCubicSegmentLength } from \"../math/cubicTools.ts\";\nimport { getPointAtQuadSegmentLength } from \"../math/quadTools.ts\";\nimport { arcPoint, getArcProps } from \"../math/arcTools.ts\";\n\n/**\n * Returns the number of samples of a segment.\n *\n * The samples are spread over the parameter of the segment, so their number\n * grows with the length of the segment: a straight segment needs none, a\n * curve needs one every step.\n *\n * @param length - the length of the segment\n * @param step - the maximum distance between two samples\n * @returns the number of samples of the segment\n */\nconst sampleCount = (length: number, step: number): number => Math.max(2, Math.ceil(length / step));\n\n/**\n * Returns the points of a normalized path, sampled along its segments.\n *\n * The samples are the points the simplification measures: they sit on the\n * path itself, so the distance between the path and the result is measured\n * against the path and not against an approximation of it.\n *\n * A straight segment needs no sample of its own, the chord of a straight\n * segment is the segment: the same goes for the close segment, the\n * deviation of a chord from a straight line is at its ends and the ends are\n * the samples of the segments around it.\n *\n * @param path - the normalized path to sample\n * @param step - the maximum distance between two samples\n * @returns the samples of the path, in path order\n */\nexport const samplePath = (path: NormalArray, step: number): Point[] => {\n const { measures } = buildPathLengthTable(path);\n const samples: Point[] = [];\n\n for (const measure of measures) {\n const { geometry: segment, startX, startY, endX, endY, length } = measure;\n const command = segment[0];\n\n if (command === \"Z\") {\n // the close segment returns to the start of the sub-path\n samples.push({ x: endX, y: endY });\n continue;\n }\n\n if (command === \"M\" || command === \"L\") {\n samples.push({ x: endX, y: endY });\n } else if (command === \"C\") {\n const count = sampleCount(length, step);\n const coords = [\n startX,\n startY,\n segment[1] as number,\n segment[2] as number,\n segment[3] as number,\n segment[4] as number,\n endX,\n endY,\n ] as CubicCoordinates;\n for (let i = 1; i < count; i += 1) {\n samples.push(getPointAtCubicSegmentLength(coords, i / count));\n }\n // the last sample of a segment is its end point\n samples.push({ x: endX, y: endY });\n } else if (command === \"Q\") {\n const count = sampleCount(length, step);\n const coords = [\n startX,\n startY,\n segment[1] as number,\n segment[2] as number,\n endX,\n endY,\n ] as QuadCoordinates;\n for (let i = 1; i < count; i += 1) {\n samples.push(getPointAtQuadSegmentLength(coords, i / count));\n }\n samples.push({ x: endX, y: endY });\n } else {\n // a normalized path holds no other command than the ones handled here\n const rx = segment[1] as number;\n const ry = segment[2] as number;\n const angle = segment[3] as number;\n // a zero radius is a straight line to the end point\n if (rx === 0 || ry === 0) {\n samples.push({ x: endX, y: endY });\n continue;\n }\n const {\n center,\n rx: radiusX,\n ry: radiusY,\n startAngle,\n endAngle,\n } = getArcProps(\n startX,\n startY,\n rx,\n ry,\n angle,\n segment[4] as number,\n segment[5] as number,\n endX,\n endY,\n );\n const count = sampleCount(length, step);\n const alpha = (((angle % 360) + 360) % 360) * (Math.PI / 180);\n const sweep = endAngle - startAngle;\n for (let i = 1; i < count; i += 1) {\n const [x, y] = arcPoint(\n center.x,\n center.y,\n radiusX,\n radiusY,\n alpha,\n startAngle + (sweep * i) / count,\n );\n samples.push({ x, y });\n }\n samples.push({ x: endX, y: endY });\n }\n }\n\n return samples;\n};\n","import type { Point } from \"../types.ts\";\nimport { distanceToSegment } from \"../math/distanceToSegment.ts\";\n\n/**\n * Returns the indexes of the points that have to be kept to approximate a\n * polyline within a given tolerance, with the Douglas-Peucker algorithm.\n *\n * The first and the last point of the polyline are always kept, the points\n * in between are kept when they are further from the chord between the two\n * points around them than the tolerance.\n *\n * @see https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm\n *\n * @param points - the points of the polyline\n * @param tolerance - the maximum distance from the simplified polyline\n * @returns the indexes of the points to keep, in order\n */\nexport const douglasPeucker = (points: Point[], tolerance: number): number[] => {\n // a polyline of one or two points is already simple enough\n if (points.length < 3) return points.map((_point, index) => index);\n\n const keep = points.map(() => false);\n keep[0] = true;\n keep[points.length - 1] = true;\n\n // the pairs of points to measure, as a stack: the recursion of the\n // original algorithm would blow the stack on a long polyline\n const stack: number[] = [0, points.length - 1];\n while (stack.length) {\n const last = stack.pop() as number;\n const first = stack.pop() as number;\n const start = points[first];\n const end = points[last];\n let maxDistance = 0;\n let index = -1;\n for (let i = first + 1; i < last; i += 1) {\n const distance = distanceToSegment(points[i], start, end);\n if (distance > maxDistance) {\n maxDistance = distance;\n index = i;\n }\n }\n if (index === -1 || maxDistance <= tolerance) continue;\n\n keep[index] = true;\n const span = last - first;\n // a split at the edge of the range would make the recursion as deep as\n // the range is long, so the range is split in the middle as well\n const edge = span >> 3;\n if (span > 8 && (index - first < edge || last - index < edge)) {\n const middle = first + (span >> 1);\n // the range is split in three, at the worst point and in the middle:\n // the middle is a corner of the result, so it is kept\n keep[middle] = true;\n // the three parts of the range do not overlap\n if (index < middle) {\n stack.push(middle, last, index, middle, first, index);\n } else {\n stack.push(index, last, middle, index, first, middle);\n }\n } else {\n stack.push(index, last, first, index);\n }\n }\n\n return points.map((_point, index) => index).filter((index) => keep[index]);\n};\n","import type { CSegment, Point } from \"../types.ts\";\n\nconst MAX_ITERATIONS = 4;\n\nconst subtract = (a: Point, b: Point): Point => ({ x: a.x - b.x, y: a.y - b.y });\nconst add = (a: Point, b: Point): Point => ({ x: a.x + b.x, y: a.y + b.y });\nconst scale = (point: Point, value: number): Point => ({\n x: point.x * value,\n y: point.y * value,\n});\nconst dot = (a: Point, b: Point): number => a.x * b.x + a.y * b.y;\nconst distance = (a: Point, b: Point): number => Math.hypot(a.x - b.x, a.y - b.y);\nconst normalize = (point: Point): Point => {\n const length = Math.hypot(point.x, point.y);\n return length ? scale(point, 1 / length) : { x: 0, y: 0 };\n};\nconst negate = (point: Point): Point => ({ x: -point.x, y: -point.y });\n\nconst chordParameters = (points: Point[]): number[] => {\n const parameters = [0];\n for (let i = 1; i < points.length; i += 1) {\n parameters.push(parameters[i - 1] + distance(points[i - 1], points[i]));\n }\n const total = parameters[parameters.length - 1];\n return parameters.map((parameter) => parameter / total);\n};\n\nconst evaluate = (curve: Point[], t: number): Point => {\n const u = 1 - t;\n return add(\n add(scale(curve[0], u ** 3), scale(curve[1], 3 * u * u * t)),\n add(scale(curve[2], 3 * u * t * t), scale(curve[3], t ** 3)),\n );\n};\n\nconst generateCurve = (\n points: Point[],\n parameters: number[],\n leftTangent: Point,\n rightTangent: Point,\n): Point[] => {\n const first = points[0];\n const last = points[points.length - 1];\n const segmentLength = distance(first, last);\n\n if (points.length === 2) {\n const handle = segmentLength / 3;\n return [\n first,\n add(first, scale(leftTangent, handle)),\n add(last, scale(rightTangent, handle)),\n last,\n ];\n }\n\n let c00 = 0;\n let c01 = 0;\n let c11 = 0;\n let x0 = 0;\n let x1 = 0;\n\n for (let i = 0; i < points.length; i += 1) {\n const t = parameters[i];\n const u = 1 - t;\n const b0 = u ** 3;\n const b1 = 3 * u * u * t;\n const b2 = 3 * u * t * t;\n const b3 = t ** 3;\n const a0 = scale(leftTangent, b1);\n const a1 = scale(rightTangent, b2);\n const tmp = subtract(points[i], add(scale(first, b0 + b1), scale(last, b2 + b3)));\n c00 += dot(a0, a0);\n c01 += dot(a0, a1);\n c11 += dot(a1, a1);\n x0 += dot(a0, tmp);\n x1 += dot(a1, tmp);\n }\n\n const determinant = c00 * c11 - c01 * c01;\n let alphaLeft = determinant ? (x0 * c11 - x1 * c01) / determinant : 0;\n let alphaRight = determinant ? (c00 * x1 - c01 * x0) / determinant : 0;\n const epsilon = 1e-6 * segmentLength;\n if (alphaLeft < epsilon || alphaRight < epsilon) {\n alphaLeft = segmentLength / 3;\n alphaRight = alphaLeft;\n }\n\n return [\n first,\n add(first, scale(leftTangent, alphaLeft)),\n add(last, scale(rightTangent, alphaRight)),\n last,\n ];\n};\n\nconst findMaxError = (\n points: Point[],\n curve: Point[],\n parameters: number[],\n): { error: number; split: number } => {\n let error = 0;\n let split = points.length >> 1;\n for (let i = 1; i < points.length - 1; i += 1) {\n const point = evaluate(curve, parameters[i]);\n const current = (point.x - points[i].x) ** 2 + (point.y - points[i].y) ** 2;\n if (current > error) {\n error = current;\n split = i;\n }\n }\n return { error, split };\n};\n\nconst refineParameter = (curve: Point[], point: Point, parameter: number): number => {\n const t = parameter;\n const u = 1 - t;\n const q = evaluate(curve, t);\n const q1 = add(\n add(\n scale(subtract(curve[1], curve[0]), 3 * u * u),\n scale(subtract(curve[2], curve[1]), 6 * u * t),\n ),\n scale(subtract(curve[3], curve[2]), 3 * t * t),\n );\n const q2 = add(\n scale(add(subtract(curve[2], scale(curve[1], 2)), curve[0]), 6 * u),\n scale(add(subtract(curve[3], scale(curve[2], 2)), curve[1]), 6 * t),\n );\n const difference = subtract(q, point);\n const denominator = dot(q1, q1) + dot(q2, difference);\n return denominator ? t - dot(q1, difference) / denominator : t;\n};\n\nconst reparameterize = (curve: Point[], points: Point[], parameters: number[]): number[] =>\n parameters.map((parameter, index) =>\n index === 0 || index === points.length - 1\n ? parameter\n : refineParameter(curve, points[index], parameter),\n );\n\nconst toSegments = (curves: Point[][]): CSegment[] =>\n curves.map((curve) => [\n \"C\",\n curve[1].x,\n curve[1].y,\n curve[2].x,\n curve[2].y,\n curve[3].x,\n curve[3].y,\n ]);\n\nexport const fitCubic = (points: Point[], tolerance: number): CSegment[] => {\n const error = tolerance * tolerance;\n const curves: Point[][] = [];\n\n const fit = (range: Point[], leftTangent: Point, rightTangent: Point): void => {\n const parameters = chordParameters(range);\n let curve = generateCurve(range, parameters, leftTangent, rightTangent);\n let maximum = findMaxError(range, curve, parameters);\n\n if (maximum.error <= error || range.length === 2) {\n curves.push(curve);\n return;\n }\n\n let currentParameters = parameters;\n for (let i = 0; i < MAX_ITERATIONS; i += 1) {\n currentParameters = reparameterize(curve, range, currentParameters);\n curve = generateCurve(range, currentParameters, leftTangent, rightTangent);\n maximum = findMaxError(range, curve, currentParameters);\n if (maximum.error <= error) {\n curves.push(curve);\n return;\n }\n }\n\n const split = maximum.split;\n const centerTangent = normalize(subtract(range[split - 1], range[split + 1]));\n fit(range.slice(0, split + 1), leftTangent, centerTangent);\n fit(range.slice(split), negate(centerTangent), rightTangent);\n };\n\n fit(\n points,\n normalize(subtract(points[1], points[0])),\n normalize(subtract(points[points.length - 2], points[points.length - 1])),\n );\n return toSegments(curves);\n};\n","import type { LSegment, MSegment, PathArray, ZSegment } from \"../types.ts\";\nimport type { SimplifyOptions } from \"../interface.ts\";\nimport { error } from \"../util/error.ts\";\nimport { normalizePath } from \"./normalizePath.ts\";\nimport { splitSubPaths } from \"./splitSubPaths.ts\";\nimport { buildPathLengthTable } from \"../util/pathLengthTable.ts\";\nimport { samplePath } from \"./samplePath.ts\";\nimport { douglasPeucker } from \"./douglasPeucker.ts\";\nimport { fitCubic } from \"./fitCubic.ts\";\n\n/**\n * The default tolerance of the simplification.\n */\nconst defaultTolerance = 1;\n\n/**\n * The maximum number of samples of a path.\n *\n * The samples are the measurements of the algorithm, so their number grows\n * with the length of the path and shrinks with the tolerance: a very long\n * path with a very small tolerance would need millions of samples, so the\n * sampling is capped and the step grows to fit.\n */\nconst MAX_SAMPLES = 20000;\n\n/**\n * The share of the tolerance the samples are spread with.\n *\n * The curve is sampled with a step of a sixteenth of the tolerance, so the\n * deviation of the curve between two samples is a fraction of the tolerance\n * itself: a range is only accepted when the curve stays within four fifths\n * of the tolerance from the chord, so the result cannot exceed it.\n */\nconst SAMPLE_SHARE = 16;\n\n/**\n * The share of the tolerance a range of the path may use.\n *\n * The samples are a discretization of the path, so the deviation between two\n * samples is not measured: the range is accepted at four fifths of the\n * tolerance, so the result stays within the tolerance even when the curve\n * bulges a little between two samples.\n */\nconst ACCEPTANCE = 0.8;\n\n/**\n * Simplifies a path within a geometric tolerance.\n *\n * Straight-line runs are reduced with Douglas-Peucker. Curve runs are fitted\n * with cubic Béziers, while arcs and original curves are preserved whenever\n * fitting would not reduce the segment count. Every source sub-path and its\n * closure are retained.\n *\n * The tolerance is the target geometric error of the sampled fitting. A\n * smaller tolerance keeps more detail, a bigger one removes more.\n *\n * @param pathInput - the target path string or PathArray\n * @param options - the tolerance of the simplification, or the options\n * @returns the simplified path\n *\n * @example\n * ```ts\n * simplifyPath(\"M0 0L10 0L20 0L30 0\", 1)\n * // => [['M', 0, 0], ['L', 30, 0]]\n * ```\n */\nexport const simplifyPath = (\n pathInput: string | PathArray,\n options?: number | SimplifyOptions,\n): PathArray => {\n const tolerance =\n typeof options === \"number\" ? options : (options?.tolerance ?? defaultTolerance);\n\n if (!Number.isFinite(tolerance) || tolerance <= 0) {\n throw new TypeError(`${error}: tolerance must be a positive number`);\n }\n\n const normalized = normalizePath(pathInput);\n if (!normalized.length) return [] as unknown as PathArray;\n\n const result: PathArray = [] as unknown as PathArray;\n for (const subPath of splitSubPaths(normalized)) {\n const closed = subPath[subPath.length - 1][0] === \"Z\";\n const straight = subPath\n .slice(1)\n .every(\n (segment) =>\n segment[0] === \"L\" ||\n segment[0] === \"Z\" ||\n (segment[0] === \"A\" && (segment[1] === 0 || segment[2] === 0)),\n );\n const { totalLength } = buildPathLengthTable(subPath);\n const step = Math.max(tolerance / SAMPLE_SHARE, totalLength / MAX_SAMPLES);\n const samples = samplePath(subPath, step);\n const start = samples[0];\n\n if (straight) {\n const kept = douglasPeucker(samples, tolerance * ACCEPTANCE);\n result.push([\"M\", start.x, start.y] as MSegment);\n const end = closed ? kept.length - 1 : kept.length;\n for (let i = 1; i < end; i += 1) {\n const point = samples[kept[i]];\n result.push([\"L\", point.x, point.y] as LSegment);\n }\n if (closed) result.push([\"Z\"] as ZSegment);\n continue;\n }\n\n const originalCount = subPath.length - 1 - (closed ? 1 : 0);\n const points = samples.filter(\n (point, index) =>\n index === 0 || point.x !== samples[index - 1].x || point.y !== samples[index - 1].y,\n );\n const curves =\n originalCount > 1 && points.length > 1 ? fitCubic(points, tolerance * ACCEPTANCE) : [];\n\n if (!curves.length || curves.length >= originalCount) {\n result.push(...subPath);\n continue;\n }\n\n result.push([\"M\", start.x, start.y] as MSegment, ...curves);\n if (closed) result.push([\"Z\"] as ZSegment);\n }\n\n return result;\n};\n","// src/morph/fixPath.ts\nimport type { PathArray } from \"../types.ts\";\nimport { parsePathString } from \"../parser/parsePathString.ts\";\nimport { normalizePath } from \"../process/normalizePath.ts\";\nimport { isClosedPath } from \"../util/isClosedPath.ts\";\n\n/**\n * Checks a `PathArray` for an unnecessary `Z` segment\n * and returns a copy without it. The input is not modified.\n * In short, if the segment before `Z` extends to `M`,\n * the `Z` segment must be removed.\n *\n * The `pathInput` must be a single path, without\n * sub-paths. For multi-path `<path>` elements,\n * use `splitPath` first and apply this utility on each\n * sub-path separately.\n *\n * @param pathInput the `pathArray` source\n * @returns the fixed path\n */\nexport const fixPath = <T extends PathArray>(pathInput: T | string): PathArray => {\n const pathArray = parsePathString(pathInput);\n\n /* istanbul ignore else */\n if (isClosedPath(pathArray)) {\n const normalArray = normalizePath(pathArray);\n const length = pathArray.length;\n const segBeforeZ = length - 2;\n const [mx, my] = normalArray[0].slice(1);\n const [x, y] = normalArray[segBeforeZ].slice(-2);\n\n if (mx === x && my === y) {\n pathArray.splice(length - 1, 1);\n }\n }\n\n return pathArray;\n};\n","// src/morph/splitCubicSegment.ts\n\nimport { midPoint } from \"../math/midPoint.ts\";\nimport type { CubicCoordinates } from \"../types.ts\";\n\n/**\n * Split a cubic Bézier into two cubics at parameter t [0–1].\n *\n * @param x1 - Start point X\n * @param y1 - Start point Y\n * @param x2 - First control point X\n * @param y2 - First control point Y\n * @param x3 - Second control point X\n * @param y3 - Second control point Y\n * @param x4 - End point X\n * @param y4 - End point Y\n * @param t - Parameter in range [0, 1] at which to split\n * @returns Array of two cubic segments, each as [x1,y1, x2,y2, x3,y3, x4,y4]\n */\nexport function splitCubicSegment(\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n x3: number,\n y3: number,\n x4: number,\n y4: number,\n t: number,\n): [CubicCoordinates, CubicCoordinates] {\n const [px01, py01] = midPoint([x1, y1], [x2, y2], t);\n const [px12, py12] = midPoint([x2, y2], [x3, y3], t);\n const [px23, py23] = midPoint([x3, y3], [x4, y4], t);\n\n const [cx0, cy0] = midPoint([px01, py01], [px12, py12], t);\n const [cx1, cy1] = midPoint([px12, py12], [px23, py23], t);\n\n const [px, py] = midPoint([cx0, cy0], [cx1, cy1], t);\n\n return [\n [x1, y1, px01, py01, cx0, cy0, px, py], // first segment\n [px, py, cx1, cy1, px23, py23, x4, y4], // second segment\n ];\n}\n","// src/convert/pathToPolyline.ts\nimport type {\n LSegment,\n PointTuple,\n PolygonArray,\n PolylineArray,\n // PathArray,\n} from \"../types.ts\";\nimport { normalizePath } from \"../process/normalizePath.ts\";\nimport { isPolygonArray } from \"../util/isPolygonArray.ts\";\nimport { isPolylineArray } from \"../util/isPolylineArray.ts\";\nimport { isClosedPath } from \"../util/isClosedPath.ts\";\nimport { error } from \"../util/error.ts\";\n\n/**\n * Converts any `PolyLineArray`/`PolygonArray` path (closed or open) to an explicit polyline (M + L*).\n * If the path is closed (has Z), the Z is replaced with an explicit L back to the initial M point.\n * This allows uniform processing without special-casing Z.\n *\n * @param path string or PathArray\n * @returns PolylineArray (M + L*) — never contains Z\n */\nexport const pathToPolyline = <T extends PolygonArray | PolylineArray>(\n path: string | T,\n): PolylineArray => {\n const normal = normalizePath(path);\n if (!isPolygonArray(normal) && !isPolylineArray(normal)) {\n throw TypeError(`${error}: pathValue is not a polyline/polygon`);\n }\n\n // If not closed, return as-is (already a polyline)\n if (!isClosedPath(normal)) {\n return normal as PolylineArray;\n }\n\n // Closed → replace Z with explicit L to initial M\n const result: PolylineArray = [normal[0]]; // Keep M\n const [mx, my] = normal[0].slice(1) as PointTuple;\n\n for (let i = 1; i < normal.length; i++) {\n const seg = normal[i];\n if (seg[0].toUpperCase() === \"Z\") {\n result.push([\"L\", mx, my]);\n } else {\n result.push(seg as LSegment);\n }\n }\n\n return result;\n};\n","// src/morph/splitLineToCount.ts\n\n/**\n * Split a line segment into `count` smaller segments of equal length\n * using the same repeated front-cutting strategy as splitCubicToCount.\n *\n * Does NOT mutate input.\n *\n * @param x1 - Start point X\n * @param y1 - Start point Y\n * @param x2 - End point X\n * @param y2 - End point Y\n * @param count - Number of segments to split into\n * @returns Array of `count` line segments, each as [x1, y1, x2, y2]\n */\nexport default function splitLineToCount(\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n count: number,\n): Array<[number, number, number, number]> {\n if (count <= 1) return [[x1, y1, x2, y2]];\n\n const result: Array<[number, number, number, number]> = [];\n\n let currentX = x1;\n let currentY = y1;\n\n // Loop count times to produce count segments\n // We generate points at 1/count, 2/count, ..., count/count\n let i = 0;\n while (i < count) {\n const t = 1 / (count - i);\n // cut the *remaining* part of the segment, so every piece has the\n // same length\n const nextX = currentX + t * (x2 - currentX);\n const nextY = currentY + t * (y2 - currentY);\n\n result.push([currentX, currentY, nextX, nextY]);\n\n currentX = nextX;\n currentY = nextY;\n i++;\n }\n\n return result;\n}\n","// src/morph/getPathSplits.ts\n\nimport type { CurveArray, PointTuple, PolylineArray } from \"../types.ts\";\nimport { measureSegments } from \"../util/measureSegments.ts\";\nimport { error } from \"../util/error.ts\";\n\n/**\n * Determine the right amount of splits for each segment in a given PathArray\n * and for a target total amount of sub-segments.\n * For a triangle path \"M0,0 L600,300 L0,600 Z\" we have 3 equal lines,\n * we can easily do 4 splits per line and go to town, however, most triangles\n * are not even so we need to take side lengths into account.\n * @param path The target PathArray\n * @param target The total amount of sub-segments\n * @returns an array of numbers reprezenting the sub-segment count for each segment\n */\nexport function getPathSplits<T extends PolylineArray | CurveArray>(\n path: T,\n target: number,\n): number[] {\n if (!Number.isFinite(target)) {\n throw new TypeError(`${error}: target must be a finite number`);\n }\n if (target < 2) throw new TypeError(`${error}: target must be >= 2`);\n\n // one measurement pass gives the length of every segment and the total\n const measures = measureSegments(path);\n const segmentCount = measures.length;\n if (!segmentCount) return [];\n\n const lengths = measures.map(({ length }) => length);\n const totalLength = lengths.reduce((total, length) => total + length, 0);\n if (!totalLength) return Array(segmentCount).fill(1);\n\n // the leading `M` counts as one split and every other segment needs at\n // least one, so the smallest reachable total is one split per segment\n const effectiveTarget = Math.max(Math.floor(target), segmentCount);\n const idealSegLen = totalLength / effectiveTarget;\n\n const splits: number[] = Array(segmentCount).fill(1);\n\n // First pass: distribute the splits proportionally to the segment lengths\n let totalAllocated = 1; // 1 stands for first M segment\n\n for (let i = 1; i < segmentCount; i += 1) {\n const segLen = lengths[i];\n const desired = segLen > idealSegLen ? Math.round(segLen / idealSegLen) : 1;\n\n splits[i] = desired;\n totalAllocated += desired;\n }\n\n // Second pass: adjust to hit the exact target\n let diff = effectiveTarget - totalAllocated;\n\n if (diff !== 0) {\n const candidates: PointTuple[] = [];\n for (let i = 1; i < segmentCount; i += 1) {\n if (lengths[i] > 0) {\n candidates.push([i, lengths[i]]);\n }\n }\n\n if (diff < 0) {\n // take the extra splits away from the shortest segments first\n candidates.sort((a, b) => a[1] - b[1]);\n while (diff < 0) {\n let changed = false;\n for (const [index] of candidates) {\n if (splits[index] > 1) {\n splits[index] -= 1;\n diff += 1;\n changed = true;\n if (diff === 0) break;\n }\n }\n // nothing left to give away - the target cannot be reached\n /* istanbul ignore if - the clamp above makes this unreachable */\n if (!changed) break;\n }\n } else {\n // give the extra splits to the longest segments first\n candidates.sort((a, b) => b[1] - a[1]);\n while (diff > 0) {\n for (const [index] of candidates) {\n splits[index] += 1;\n diff -= 1;\n if (diff === 0) break;\n }\n }\n }\n }\n return splits;\n}\n","// src/morph/splitLinePathToCount.ts\n\nimport type { PointTuple, PolylineArray } from \"../types.ts\";\nimport splitLineToCount from \"./splitLineToCount.ts\";\nimport { getPathSplits } from \"./getPathSplits.ts\";\nimport { error } from \"../util/error.ts\";\n\n/**\n * Splits a PolylineArray so that it has exactly `target` line segments.\n *\n * @param path - The polyline array to split\n * @param target - The desired number of line segments\n * @returns The modified polyline array with the target segment count\n */\nexport function splitLinePathToCount<T extends PolylineArray>(path: T, target: number): T {\n if (path.length < 2 || target <= 1) return path;\n\n const splits = getPathSplits(path, target);\n let totalAdded = 0;\n\n const newPath = [path[0]] as unknown as T;\n const pathLen = path.length;\n let currentX = path[0][1];\n let currentY = path[0][2];\n\n // Build path using splits\n for (let i = 1; i < pathLen; i++) {\n const seg = path[i];\n const [endX, endY] = seg.slice(1) as PointTuple;\n\n const count = splits[i];\n\n // istanbul ignore else\n if (count >= 1) {\n const subLines = splitLineToCount(currentX, currentY, endX, endY, count);\n\n for (const sub of subLines) {\n newPath.push([\"L\", sub[2], sub[3]]);\n totalAdded++;\n }\n }\n\n currentX = endX;\n currentY = endY;\n }\n\n // Final safety: if somehow still wrong, log it\n // istanbul ignore if - this might possibly be impossible to test\n if (newPath.length !== target) {\n console.warn(\n `${error}: requested ${target} segments, got ${newPath.length}. Adjusted on last segment.`,\n );\n }\n\n return newPath;\n}\n","// src/morph/splitCubicToCount.ts\n\nimport type { CubicCoordinates } from \"../types.ts\";\nimport { splitCubicSegment } from \"./splitCubicSegment.ts\";\n\n/**\n * Split a cubic Bézier into `count` segments of roughly equal parameter length.\n * Does NOT mutate input parameters.\n *\n * @param x1 - Start point X\n * @param y1 - Start point Y\n * @param x2 - First control point X\n * @param y2 - First control point Y\n * @param x3 - Second control point X\n * @param y3 - Second control point Y\n * @param x4 - End point X\n * @param y4 - End point Y\n * @param count - Number of segments to split into\n * @returns Array of `count` cubic segments, each as [x1,y1,x2,y2,x3,y3,x4,y4]\n */\nexport function splitCubicToCount(\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n x3: number,\n y3: number,\n x4: number,\n y4: number,\n count: number,\n): Array<CubicCoordinates> {\n if (count <= 1) return [[x1, y1, x2, y2, x3, y3, x4, y4]];\n\n const result: Array<CubicCoordinates> = [];\n\n // Work on local copies to avoid mutating inputs\n let cx1 = x1;\n let cy1 = y1;\n let cx2 = x2;\n let cy2 = y2;\n let cx3 = x3;\n let cy3 = y3;\n let cx4 = x4;\n let cy4 = y4;\n\n let i = 0;\n while (i < count) {\n const t = 1 / (count - i);\n const [first, second] = splitCubicSegment(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4, t);\n\n result.push(first);\n\n // Update working curve to the remaining (second) part\n [cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4] = second;\n i++;\n }\n\n return result;\n}\n","// src/morph/splitCubicPathToCount.ts\nimport type { CSegment, CurveArray, PointTuple } from \"../types.ts\";\nimport { splitCubicToCount } from \"./splitCubicToCount.ts\";\nimport { getPathSplits } from \"./getPathSplits.ts\";\nimport { error } from \"../util/error.ts\";\n\n/**\n * Splits a CurveArray so that it has exactly `target` cubic segments.\n *\n * @param path - The curve array to split\n * @param target - The desired number of cubic segments\n * @returns The modified curve array with the target segment count\n */\nexport function splitCurvePathToCount<T extends CurveArray>(path: T, target: number): T {\n // istanbul ignore else\n if (path.length < 2 || target <= 1) return path;\n\n const splits = getPathSplits(path, target);\n let totalAdded = 0;\n\n const newPath = [path[0]] as unknown as T; // keep M\n const pathLen = path.length;\n let currentX = path[0][1];\n let currentY = path[0][2];\n\n for (let i = 1; i < pathLen; i++) {\n const seg = path[i] as CSegment; /*| ZSegment*/\n const [endX, endY] = seg.slice(-2) as PointTuple;\n\n const count = splits[i];\n\n // istanbul ignore else\n if (count >= 1) {\n const subs = splitCubicToCount(\n currentX,\n currentY,\n seg[1],\n seg[2],\n seg[3],\n seg[4],\n seg[5],\n seg[6],\n count,\n );\n\n for (const sub of subs) {\n newPath.push([\"C\", sub[2], sub[3], sub[4], sub[5], sub[6], sub[7]]);\n totalAdded++;\n }\n }\n currentX = endX;\n currentY = endY;\n }\n\n // Final safety: if somehow still wrong, log it\n // istanbul ignore if\n if (newPath.length !== target) {\n console.warn(`${error}: requested ${target} segments, got ${newPath.length}.`);\n }\n\n return newPath;\n}\n","// src/morph/samplePolygon.ts\n\nimport { error } from \"../util/error.ts\";\nimport { iterate } from \"../process/iterate.ts\";\nimport type { NormalArray, PointTuple } from \"../types.ts\";\n\n/**\n * Samples points from a path to form a polygon approximation.\n * Collects endpoints of each segment (M start + ends of L/C/etc).\n *\n * @param path `PolygonPathArray` or `CurvePathArray`\n * @returns Array of [x, y] points\n */\nexport function samplePolygon<T extends NormalArray>(path: T): PointTuple[] {\n const points: PointTuple[] = [];\n\n let [mx, my] = [0, 0];\n\n iterate(path, (seg) => {\n const cmd = seg[0];\n if (cmd === \"M\") {\n [mx, my] = [seg[1] as number, seg[2] as number];\n points.push([mx, my]);\n } else if (cmd === \"L\") {\n points.push([seg[1] as number, seg[2] as number]);\n } else if (cmd === \"C\") {\n points.push([seg[5] as number, seg[6] as number]);\n } else if (cmd === \"Q\") {\n points.push([seg[3] as number, seg[4] as number]);\n } else if (cmd === \"A\") {\n points.push([seg[6] as number, seg[7] as number]);\n } else if (cmd === \"Z\") {\n points.push([mx, my]);\n } else {\n throw new TypeError(`${error}: path command \"${String(cmd)}\" is not supported`);\n }\n });\n\n return points;\n}\n","// src/morph/getRotatedPath.ts\n\nimport type {\n CSegment,\n // CurveArray,\n LSegment,\n MorphPathArray,\n MSegment,\n PathSegment,\n // PolylineArray,\n ZSegment,\n} from \"../types.ts\";\nimport { error } from \"../util/error.ts\";\n\n/**\n * Returns a single rotation of a path (line or curve) by shifting the start point.\n * The rotation starts at the end of the segment at `idx` and continues with the\n * following segments, wrapping around the end of the path.\n *\n * @param a PathArray (M + L/C + optional Z) — must be single subpath, normalized\n * @param idx the index of the segment the rotation starts at\n * @returns PathArray — the rotation of the path\n */\nexport function getRotation<T extends MorphPathArray>(a: T, idx: number): T {\n const pathLen = a.length;\n const pointCount = pathLen - 1;\n const path = [] as unknown as T;\n\n for (let i = 0; i < pathLen; i++) {\n let oldSegIdx = idx + i;\n let seg: LSegment | CSegment | MSegment | ZSegment;\n\n if (i === 0 || (a[oldSegIdx] && a[oldSegIdx][0] === \"M\")) {\n seg = a[oldSegIdx];\n path.push([\"M\", ...seg.slice(-2)] as MSegment);\n continue;\n }\n if (oldSegIdx >= pathLen) {\n oldSegIdx -= pointCount;\n }\n path.push(a[oldSegIdx] as never);\n }\n return path;\n}\n\n/**\n * Returns all possible rotations of a path (line or curve) by shifting the start point.\n * Each rotation is a new PathArray starting at a different original segment.\n *\n * @param path PathArray (M + L/C + optional Z) — must be single subpath, normalized\n * @returns PathArray[] — array of all possible rotations\n */\nexport function getRotations<T extends MorphPathArray>(a: T): T[] {\n const pathLen = a.length;\n const result = [] as T[];\n\n for (let idx = 0; idx < pathLen; idx++) {\n result.push(getRotation(a, idx));\n }\n return result;\n}\n\nconst getSegmentDistanceSquared = (a: PathSegment, b: PathSegment): number => {\n let distance = 0;\n for (let i = 1; i < a.length; i += 1) {\n const delta = Number(a[i]) - Number(b[i]);\n distance += delta * delta;\n }\n return distance;\n};\n\nconst getStartDistanceSquared = (a: PathSegment, b: PathSegment): number => {\n const dx = Number(a[a.length - 2]) - Number(b[b.length - 2]);\n const dy = Number(a[a.length - 1]) - Number(b[b.length - 1]);\n return dx * dx + dy * dy;\n};\n\n/**\n * Finds the rotation of `pathA` that matches `pathB` best by minimizing the sum\n * of squared distances between all corresponding coordinates, including the\n * control points of the curves.\n *\n * The rotations are not materialized: the segment at index `j` of the rotation\n * that starts at `idx` is the segment at index `1 + ((idx + i - 1) mod\n * pointCount)` of the source path, so the sum can be computed from the source\n * path alone.\n *\n * A rotation whose running sum is already worse than the best rotation found so\n * far cannot become the best one — the terms of the sum are squared distances,\n * so the sum only grows — and the rotation is dropped right there.\n *\n * The rotations are checked in the order of their first term, the distance\n * between the start of the rotation and the start of the reference path: the\n * rotation that matches best is usually the one that starts closest, so it is\n * usually found early and the rest of the rotations are dropped right away.\n *\n * @param pathA the path to rotate\n * @param pathB the reference path\n * @returns the index of the best rotation\n */\nconst getBestRotationIndex = <T extends MorphPathArray>(pathA: T, pathB: T): number => {\n const pathLen = pathA.length;\n const pointCount = pathLen - 1;\n\n const firstTerms: number[] = [];\n const order: number[] = [];\n for (let idx = 0; idx < pathLen; idx++) {\n firstTerms.push(getStartDistanceSquared(pathA[idx], pathB[0]));\n order.push(idx);\n }\n order.sort((a, b) => {\n const first = firstTerms[a];\n const second = firstTerms[b];\n if (first < second) return -1;\n if (first > second) return 1;\n return a - b;\n });\n\n let bestIndex = 0;\n let minDistanceSq = Infinity;\n\n for (const idx of order) {\n let sumDistSq = firstTerms[idx];\n if (sumDistSq > minDistanceSq) continue;\n\n for (let i = 1; i < pathLen; i++) {\n const j = 1 + ((idx + i - 1) % pointCount);\n sumDistSq += getSegmentDistanceSquared(pathA[j], pathB[i]);\n if (sumDistSq > minDistanceSq) break;\n }\n\n if (sumDistSq < minDistanceSq || (sumDistSq === minDistanceSq && idx < bestIndex)) {\n minDistanceSq = sumDistSq;\n bestIndex = idx;\n }\n }\n\n return bestIndex;\n};\n\n/**\n * Finds the best rotation of pathA to match pathB by minimizing the sum of squared distances\n * between corresponding coordinates, including curve control points.\n *\n * Works with both polygon (L) and curve (C) arrays.\n *\n * @param pathA PathArray to rotate (will be modified in rotation options)\n * @param pathB PathArray reference (fixed)\n * @returns PathArray — best rotation of pathA\n */\nexport function getRotatedPath<T extends MorphPathArray>(\n pathA: T,\n pathB: T,\n computedRotations?: T[],\n): T {\n const segCountA = pathA.length;\n const segCountB = pathB.length;\n\n if (segCountA !== segCountB) {\n throw new TypeError(error + \": paths must have the same number of segments after equalization\");\n }\n\n if (computedRotations) {\n let bestIndex = 0;\n let minDistanceSq = Infinity;\n\n for (let ri = 0; ri < computedRotations.length; ri++) {\n const rotation = computedRotations[ri];\n let sumDistSq = 0;\n\n for (let i = 0; i < rotation.length; i++) {\n sumDistSq += getSegmentDistanceSquared(rotation[i], pathB[i]);\n }\n\n if (sumDistSq < minDistanceSq) {\n minDistanceSq = sumDistSq;\n bestIndex = ri;\n }\n }\n\n return computedRotations[bestIndex];\n }\n\n return getRotation(pathA, getBestRotationIndex(pathA, pathB));\n}\n","import type {\n CSegment,\n CubicCoordinates,\n CurveArray,\n LSegment,\n MorphPathArray,\n MSegment,\n NormalArray,\n PathArray,\n PathSegment,\n Point,\n PolylineArray,\n} from \"../types.ts\";\nimport type { PathLengthTable } from \"../util/pathLengthTable.ts\";\nimport type { SegmentMeasure } from \"../util/measureSegments.ts\";\nimport { buildPathLengthTable } from \"../util/pathLengthTable.ts\";\nimport { getSegmentFrame } from \"../util/segmentFrame.ts\";\nimport { normalizePath } from \"../process/normalizePath.ts\";\nimport { splitSubPaths } from \"../process/splitSubPaths.ts\";\nimport { pathToCurve } from \"../convert/pathToCurve.ts\";\nimport { getTAtBezierLength } from \"../math/bezier.ts\";\nimport { splitCubicSegment } from \"./splitCubicSegment.ts\";\n\n/**\n * The share of a span used by the control points of a fallback curve.\n */\nconst CONTROL_SHARE = 3;\n\n/**\n * The distance below which two lengths are the same.\n */\nconst LENGTH_EPSILON = 1e-9;\n\n/**\n * The frame of a path at a given length: the point, the direction the path\n * comes from and the direction it goes to.\n *\n * The two directions are the same on a smooth spot of the path and they\n * differ on a corner, where the path changes its direction abruptly.\n */\ntype ResampleFrame = {\n /** the point at the given length */\n point: Point;\n /** the direction of the path at the point, from the point backwards */\n incoming: Point;\n /** the direction of the path at the point, from the point forwards */\n outgoing: Point;\n};\n\n/**\n * Distributes a number of intervals among a number of spans.\n *\n * The intervals are shared in proportion to the length of the spans, so the\n * spacing of the intervals stays the same over the whole path. The spans\n * that lose a fraction of an interval share it out, the one with the\n * biggest fraction gets it.\n *\n * @param lengths - the length of every span\n * @param extra - the number of intervals to distribute\n * @returns the number of extra intervals of every span\n */\nconst distributeIntervals = (lengths: number[], extra: number): number[] => {\n const shares = lengths.map(() => 0);\n if (extra <= 0) return shares;\n\n const total = lengths.reduce((sum, length) => sum + length, 0);\n // the spans cover the whole path, so their length is the length of the path\n /* istanbul ignore if */\n if (total <= 0) return shares;\n\n const remainders: { index: number; remainder: number }[] = [];\n let used = 0;\n for (let i = 0; i < lengths.length; i += 1) {\n const exact = (lengths[i] / total) * extra;\n const whole = Math.floor(exact);\n shares[i] = whole;\n used += whole;\n remainders.push({ index: i, remainder: exact - whole });\n }\n\n remainders.sort((a, b) => b.remainder - a.remainder || a.index - b.index);\n let left = extra - used;\n for (let i = 0; left > 0 && remainders.length; i = (i + 1) % remainders.length) {\n shares[remainders[i].index] += 1;\n left -= 1;\n }\n return shares;\n};\n\n/**\n * Builds the lengths of the knots of a resampled path.\n *\n * The source segment boundaries are knots too, so every result span belongs\n * to one source segment. The intervals between the boundaries are shared in\n * proportion to their length, so the spacing of the knots stays the same over\n * the whole path.\n *\n * When the source segments do not fit into the requested intervals, the knots\n * are spread evenly and the shape of the path is approximated by its chords.\n *\n * @param totalLength - the length of the path\n * @param intervals - the number of intervals of the result\n * @param boundaries - the length of every source segment boundary\n * @returns the length of every knot of the result, in path order\n */\nconst buildKnots = (totalLength: number, intervals: number, boundaries: number[]): number[] => {\n const breakpoints = [0];\n for (const boundary of boundaries) {\n if (boundary > breakpoints[breakpoints.length - 1] + LENGTH_EPSILON) {\n breakpoints.push(boundary);\n }\n }\n breakpoints.push(totalLength);\n\n const spanCount = breakpoints.length - 1;\n const knots: number[] = [];\n\n // the source segments do not fit: the knots are spread evenly\n if (spanCount > intervals) {\n for (let i = 0; i <= intervals; i += 1) {\n knots.push((totalLength * i) / intervals);\n }\n return knots;\n }\n\n const lengths = breakpoints.slice(1).map((value, index) => value - breakpoints[index]);\n const shares = distributeIntervals(lengths, intervals - spanCount);\n\n for (let i = 0; i < spanCount; i += 1) {\n const from = breakpoints[i];\n const to = breakpoints[i + 1];\n const count = shares[i] + 1;\n for (let j = 0; j < count; j += 1) {\n knots.push(from + ((to - from) * j) / count);\n }\n }\n knots.push(totalLength);\n return knots;\n};\n\n/**\n * Finds the index of the segment a distance falls into.\n *\n * The segment is the last one whose accumulated length is below the\n * distance, the same segment the linear walk over the path would have\n * stopped at. A distance at the end of a segment belongs to the segment\n * before it, so the frame at that distance is the frame at the end of the\n * segment.\n *\n * @param measures - the measured segments of the path\n * @param distance - the distance along the path\n * @returns the index of the segment\n */\nconst findSegmentIndex = (measures: SegmentMeasure[], distance: number): number => {\n let low = 0;\n let high = measures.length - 1;\n while (low < high) {\n const mid = (low + high + 1) >> 1;\n if (measures[mid].lengthAtSegment < distance) {\n low = mid;\n } else {\n high = mid - 1;\n }\n }\n return low;\n};\n\n/**\n * Returns the direction of the path after a segment.\n *\n * The segments without a direction are skipped, so the direction of the\n * path is the direction of the first segment that has one.\n *\n * @param measures - the measured segments of the path\n * @param index - the index of the segment\n * @returns the direction of the path, or `null` when the path has none\n */\nconst findNextDirection = (measures: SegmentMeasure[], index: number): Point | null => {\n for (let i = index + 1; i < measures.length; i += 1) {\n const measure = measures[i];\n if (measure.length <= 0) continue;\n const tangent = getSegmentFrame(\n measure.geometry,\n measure.startX,\n measure.startY,\n measure.endX,\n measure.endY,\n 0,\n measure.length,\n ).tangent;\n if (tangent.x || tangent.y) return tangent;\n }\n return null;\n};\n\n/**\n * The share of the length of a path the end of the path can be over.\n *\n * The length of a path is the sum of the lengths of its segments, so the end\n * of the path can be a fraction over the end of its last segment. The point\n * at the end of the path is the end point of the path, not a point a\n * fraction before it.\n */\nconst END_EPSILON = 1e-9;\n\n/**\n * Returns the frame of a path at a given length.\n *\n * @param table - the length table of the path\n * @param distance - the distance along the path\n * @returns the frame of the path at the given length\n */\nconst getFrameAt = (table: PathLengthTable, distance: number): ResampleFrame => {\n const { measures, totalLength } = table;\n const index = findSegmentIndex(measures, distance);\n const measure = measures[index];\n const rawOffset = distance - measure.lengthAtSegment;\n const atEnd = totalLength - distance <= totalLength * END_EPSILON;\n const offset = atEnd ? measure.length : Math.min(Math.max(rawOffset, 0), measure.length);\n\n const frame = getSegmentFrame(\n measure.geometry,\n measure.startX,\n measure.startY,\n measure.endX,\n measure.endY,\n offset,\n measure.length,\n );\n\n // at the end of a segment the path continues with the next one, which can\n // have another direction: that is a corner\n let outgoing = frame.tangent;\n if (offset >= measure.length) {\n const next = findNextDirection(measures, index);\n if (next) outgoing = next;\n }\n\n return { point: frame.point, incoming: frame.tangent, outgoing };\n};\n\n/**\n * Returns the control lengths of a fallback curve.\n *\n * @param fromLength - the length of the start of the span\n * @param toLength - the length of the end of the span\n * @param from - the frame at the start of the span\n * @param to - the frame at the end of the span\n * @returns the length of the control point at each end of the span\n */\nconst getFallbackCurveControls = (\n fromLength: number,\n toLength: number,\n from: ResampleFrame,\n to: ResampleFrame,\n): { start: number; end: number } => {\n const span = Math.max(0, toLength - fromLength);\n const fallback = span / CONTROL_SHARE;\n const hasFromDirection = from.outgoing.x !== 0 || from.outgoing.y !== 0;\n const hasToDirection = to.incoming.x !== 0 || to.incoming.y !== 0;\n return {\n start: hasFromDirection ? fallback : 0,\n end: hasToDirection ? fallback : 0,\n };\n};\n\n/**\n * Returns the internal boundaries of the measured source segments.\n *\n * @param measures - the measured segments of the path\n * @param totalLength - the length of the path\n * @returns the length of every internal segment boundary\n */\nconst getSegmentBoundaries = (measures: SegmentMeasure[], totalLength: number): number[] => {\n const boundaries: number[] = [];\n for (const measure of measures) {\n if (measure.geometry[0] === \"M\" || measure.length <= 0) continue;\n const end = measure.lengthAtSegment + measure.length;\n if (end > LENGTH_EPSILON && end < totalLength - LENGTH_EPSILON) {\n boundaries.push(end);\n }\n }\n return boundaries;\n};\n\n/**\n * Finds the source curve that holds a distance.\n *\n * @param measures - the measured curve segments of the path\n * @param distance - the distance along the path\n * @returns the index of the curve segment\n */\nconst findCurveSegmentIndex = (measures: SegmentMeasure[], distance: number): number => {\n let low = 0;\n let high = measures.length - 1;\n let result = 0;\n while (low <= high) {\n const mid = (low + high) >> 1;\n if (measures[mid].lengthAtSegment <= distance) {\n result = mid;\n low = mid + 1;\n } else {\n high = mid - 1;\n }\n }\n return result;\n};\n\n/**\n * Extracts the exact cubic curve of a source span.\n *\n * @param measures - the measured curve segments of the path\n * @param fromLength - the length of the start of the span\n * @param toLength - the length of the end of the span\n * @returns the exact cubic segment, or `null` when the span crosses a source boundary\n */\nconst getExactCurveSegment = (\n measures: SegmentMeasure[],\n fromLength: number,\n toLength: number,\n): CSegment | null => {\n const index = findCurveSegmentIndex(measures, fromLength);\n const measure = measures[index];\n const segmentStart = measure.lengthAtSegment;\n const segmentEnd = segmentStart + measure.length;\n if (toLength > segmentEnd + LENGTH_EPSILON) return null;\n\n const geometry = measure.geometry as CSegment;\n const coordinates = [\n measure.startX,\n measure.startY,\n geometry[1],\n geometry[2],\n geometry[3],\n geometry[4],\n measure.endX,\n measure.endY,\n ] as CubicCoordinates;\n\n const fromOffset = fromLength - segmentStart;\n const toOffset = toLength - segmentStart;\n const t0 =\n fromOffset <= LENGTH_EPSILON\n ? 0\n : getTAtBezierLength(coordinates, Math.min(fromOffset, measure.length));\n const t1 =\n toOffset >= measure.length - LENGTH_EPSILON\n ? 1\n : getTAtBezierLength(coordinates, Math.max(0, toOffset));\n\n let span: CubicCoordinates;\n if (t0 <= 0) {\n const [first] = splitCubicSegment(...coordinates, t1);\n span = first;\n } else {\n const [, tail] = splitCubicSegment(...coordinates, t0);\n const ratio = Math.max(0, Math.min(1, (t1 - t0) / (1 - t0)));\n const [first] = splitCubicSegment(...tail, ratio);\n span = first;\n }\n\n return [\"C\", span[2], span[3], span[4], span[5], span[6], span[7]];\n};\n\n/**\n * Resamples a measured path to a given number of points, spread evenly by\n * length.\n *\n * The path is measured along its length and the points of the result are\n * spread evenly over it, so the distance between two points of the result\n * is the same over the whole path. The source segment boundaries are points\n * of the result too, so the shape of the path keeps its vertices.\n *\n * The result is a polyline, or a path of cubic Bezier segments when the\n * curve mode is used. Every cubic of the result is the exact piece of the\n * source curve between two knots.\n *\n * @param table - the length table of the path\n * @param count - the number of points of the result\n * @param mode - the type of the segments of the result\n * @returns the resampled path\n */\nexport const resampleFromTable = (\n table: PathLengthTable,\n count: number,\n mode: \"line\" | \"curve\",\n): MorphPathArray => {\n const { measures, totalLength } = table;\n if (!measures.length) return [] as unknown as MorphPathArray;\n\n const points = Math.max(1, Math.floor(count));\n const intervals = points - 1;\n\n // a path without a length is a point\n if (totalLength <= 0) {\n return [[\"M\", measures[0].endX, measures[0].endY]] as unknown as MorphPathArray;\n }\n\n // a single point is the start of the path\n if (intervals <= 0) {\n return [[\"M\", table.startX, table.startY]] as unknown as MorphPathArray;\n }\n\n const boundaries = getSegmentBoundaries(measures, totalLength);\n const knots = buildKnots(totalLength, intervals, boundaries);\n const frames = knots.map((knot) => getFrameAt(table, knot));\n const curveMeasures =\n mode === \"curve\"\n ? measures.filter((measure) => measure.geometry[0] === \"C\" && measure.length > LENGTH_EPSILON)\n : [];\n\n const start = frames[0].point;\n const result: (MSegment | LSegment | CSegment)[] = [[\"M\", start.x, start.y] as MSegment];\n\n for (let i = 1; i < knots.length; i += 1) {\n const from = frames[i - 1];\n const to = frames[i];\n if (mode === \"curve\") {\n const exact = getExactCurveSegment(curveMeasures, knots[i - 1], knots[i]);\n if (exact) {\n result.push(exact);\n continue;\n }\n\n const controls = getFallbackCurveControls(knots[i - 1], knots[i], from, to);\n const c1x = from.point.x + from.outgoing.x * controls.start;\n const c1y = from.point.y + from.outgoing.y * controls.start;\n const c2x = to.point.x - to.incoming.x * controls.end;\n const c2y = to.point.y - to.incoming.y * controls.end;\n result.push([\"C\", c1x, c1y, c2x, c2y, to.point.x, to.point.y] as CSegment);\n } else {\n result.push([\"L\", to.point.x, to.point.y] as LSegment);\n }\n }\n\n return mode === \"curve\"\n ? (result as unknown as CurveArray)\n : (result as unknown as PolylineArray);\n};\n\n/**\n * Resamples a normalized sub-path to a given number of points, spread evenly\n * by length.\n *\n * @param path - the normalized sub-path to resample\n * @param count - the number of points of the result\n * @param mode - the type of the segments of the result\n * @returns the resampled path\n */\nexport const resampleNormalizedPath = (\n path: NormalArray,\n count: number,\n mode: \"line\" | \"curve\",\n): MorphPathArray => {\n const source = mode === \"curve\" ? pathToCurve(path as PathArray) : path;\n return resampleFromTable(buildPathLengthTable(source as NormalArray), count, mode);\n};\n\n/**\n * Resamples a path to a given number of points, spread evenly by length.\n *\n * The path is measured along its length and the points of the result are\n * spread evenly over it, so the distance between two points of the result\n * is the same over the whole path. The source segment boundaries are points\n * of the result too, so the shape of the path keeps its vertices.\n *\n * Every sub-path of the path is resampled on its own, so the sub-paths of\n * the result are the sub-paths of the source: a path with several sub-paths\n * keeps its shape, the points of a sub-path are not shared with the others.\n *\n * The result is a polyline, or a path of cubic Bezier segments when the\n * curve mode is used. Every cubic of the result is the exact piece of the\n * source curve between two knots.\n *\n * @param pathInput - the target path string or PathArray\n * @param count - the number of points of every sub-path of the result\n * @param mode - the type of the segments of the result\n * @returns the resampled path\n *\n * @example\n * ```ts\n * resamplePath(\"M0 0L100 0L100 100\", 3)\n * // => [['M', 0, 0], ['L', 100, 0], ['L', 100, 100]]\n * ```\n */\nexport const resamplePath = (\n pathInput: string | PathArray,\n count: number,\n mode: \"line\" | \"curve\" = \"line\",\n): PathArray => {\n const path = normalizePath(pathInput);\n const result: PathSegment[] = [];\n // every sub-path is resampled on its own, so the sub-paths of the result\n // are the sub-paths of the source\n for (const subPath of splitSubPaths(path)) {\n result.push(...(resampleNormalizedPath(subPath, count, mode) as PathSegment[]));\n }\n // the result of a multi-subpath source holds several moveto commands, so\n // its public type is a path array and not a single morph path\n return result as unknown as PathArray;\n};\n","// src/morph/equalizeSegments.ts\nimport type {\n CurveArray,\n EqualizationOptions,\n MorphPathArray,\n PathArray,\n Point,\n PolylineArray,\n} from \"../types.ts\";\nimport { pathToCurve } from \"../convert/pathToCurve.ts\";\nimport { pathToPolyline } from \"./pathToPolyline.ts\";\nimport { reversePath } from \"../process/reversePath.ts\";\nimport { normalizePath } from \"../process/normalizePath.ts\";\nimport { splitLinePathToCount } from \"./splitLinePathToCount.ts\";\nimport { splitCurvePathToCount } from \"./splitCurvePathToCount.ts\";\nimport { samplePolygon } from \"./samplePolygon.ts\";\nimport { polygonArea } from \"../math/polygonTools.ts\";\nimport { getRotatedPath } from \"./getRotatedPath.ts\";\nimport { fixPath } from \"./fixPath.ts\";\nimport { isPolygonArray } from \"../util/isPolygonArray.ts\";\nimport { isPolylineArray } from \"../util/isPolylineArray.ts\";\nimport { getTotalLength } from \"../util/getTotalLength.ts\";\nimport { isClosedPath } from \"../util/isClosedPath.ts\";\nimport { roundPath } from \"../process/roundPath.ts\";\nimport { resampleFromTable } from \"./resamplePath.ts\";\nimport { buildPathLengthTable } from \"../util/pathLengthTable.ts\";\nimport type { PathLengthTable } from \"../util/pathLengthTable.ts\";\n\nconst equalizeSegmentsDefaults: EqualizationOptions = {\n mode: \"auto\", // \"line\" | \"curve\" | \"auto\"\n strategy: \"segment\", // \"segment\" | \"arcLength\"\n align: true,\n sampleSize: 10, // for line option\n roundValues: 4, // 4 decimals\n reverse: true,\n target: undefined,\n};\n\n/**\n * Returns the start and the end point of a path.\n *\n * A closed path ends at the start of its sub-path, so the end point of a\n * path that ends with a close command is the start of the sub-path it\n * belongs to.\n *\n * @param path - the path to read\n * @returns the start and the end point of the path\n */\nexport const getPathEnds = (path: PathArray): { start: Point; end: Point } => {\n const first = path[0];\n const start = { x: first[1] as number, y: first[2] as number };\n let subStart = start;\n let end = start;\n for (const segment of path) {\n const command = segment[0];\n if (command === \"M\") {\n subStart = { x: segment[1] as number, y: segment[2] as number };\n end = subStart;\n } else if (command === \"Z\") {\n end = subStart;\n } else {\n end = {\n x: segment[segment.length - 2] as number,\n y: segment[segment.length - 1] as number,\n };\n }\n }\n return { start, end };\n};\n\n/**\n * Returns the distance between two points.\n *\n * @param a - the first point\n * @param b - the second point\n * @returns the distance between the points\n */\nexport const getDistance = (a: Point, b: Point): number => Math.hypot(a.x - b.x, a.y - b.y);\n\n/**\n * Returns the number of points the arc length strategy uses.\n *\n * The number of points of the result is the number of the segments of the\n * bigger path, so every source segment can have its own span in the result.\n *\n * @param table1 - the length table of the first path\n * @param table2 - the length table of the second path\n * @param target - the requested number of points\n * @returns the number of points of the result\n */\nconst getArcLengthCount = (\n table1: PathLengthTable,\n table2: PathLengthTable,\n target?: number,\n): number => {\n if (typeof target === \"number\") return Math.max(2, Math.floor(target));\n\n return Math.max(table1.measures.length, table2.measures.length, 2);\n};\n\n/**\n * Equalizes two paths for morphing (single subpath only).\n *\n * @see https://minus-ze.ro/posts/morphing-arbitrary-paths-in-svg/\n * @param path1 - First path string or PathArray\n * @param path2 - Second path string or PathArray\n * @param initialCfg - Equalization options\n * @returns Tuple of two equalized MorphPathArrays\n *\n * @example\n * ```ts\n * const [eq1, eq2] = equalizeSegments('M0 0L100 0L50 100Z', 'M0 0L100 0L100 100L0 100Z')\n * // eq1.length === eq2.length\n * ```\n */\nexport const equalizeSegments = (\n path1: PathArray | string,\n path2: PathArray | string,\n initialCfg: EqualizationOptions = {},\n): [MorphPathArray, MorphPathArray] => {\n const {\n align,\n close,\n mode,\n reverse,\n roundValues,\n strategy,\n target: initialTarget,\n } = { ...equalizeSegmentsDefaults, ...initialCfg };\n const normalized1 = normalizePath(path1);\n const normalized2 = normalizePath(path2);\n const shouldClose = close ?? (isClosedPath(normalized1) || isClosedPath(normalized2));\n let p1 = fixPath(normalized1) as MorphPathArray;\n let p2 = fixPath(normalized2) as MorphPathArray;\n\n const bothPoly =\n (isPolygonArray(p1) || isPolylineArray(p1)) && (isPolygonArray(p2) || isPolylineArray(p2));\n\n // Sample and check draw direction\n const area1 = polygonArea(samplePolygon(p1));\n const area2 = polygonArea(samplePolygon(p2));\n\n if (reverse !== false && Math.sign(area1) !== Math.sign(area2)) {\n if (reverse === \"auto\") {\n // the path that is reversed is the one that leaves the two paths\n // closest to each other\n const ends1 = getPathEnds(p1);\n const ends2 = getPathEnds(p2);\n if (getDistance(ends1.end, ends2.start) < getDistance(ends1.start, ends2.end)) {\n p1 = reversePath(p1);\n } else {\n p2 = reversePath(p2);\n }\n } else {\n p2 = reversePath(p2);\n }\n }\n\n if (strategy === \"arcLength\") {\n const resampleMode =\n mode === \"curve\" ? \"curve\" : mode === \"line\" ? \"line\" : bothPoly ? \"line\" : \"curve\";\n // curve mode works on cubic source segments, so every result span can be\n // an exact piece of one source curve\n const source1 = resampleMode === \"curve\" ? pathToCurve(p1) : p1;\n const source2 = resampleMode === \"curve\" ? pathToCurve(p2) : p2;\n const table1 = buildPathLengthTable(source1);\n const table2 = buildPathLengthTable(source2);\n const count = getArcLengthCount(table1, table2, initialTarget);\n let equalP1 = resampleFromTable(table1, count, resampleMode);\n let equalP2 = resampleFromTable(table2, count, resampleMode);\n\n // Point alignment\n if (align !== false) equalP2 = getRotatedPath(equalP2, equalP1);\n\n if (typeof roundValues === \"number\" && roundValues !== 4) {\n equalP1 = roundPath(equalP1, roundValues);\n equalP2 = roundPath(equalP2, roundValues);\n }\n\n if (shouldClose) {\n equalP1.push([\"Z\"] as never);\n equalP2.push([\"Z\"] as never);\n }\n\n return [equalP1, equalP2];\n }\n\n let bothPolyline = bothPoly;\n if (bothPolyline && mode !== \"curve\") {\n p1 = pathToPolyline(p1 as PolylineArray);\n p2 = pathToPolyline(p2 as PolylineArray);\n } else {\n bothPolyline = false;\n p1 = pathToCurve(p1);\n p2 = pathToCurve(p2);\n }\n\n // Get segment counts\n const segCount1 = p1.length;\n const segCount2 = p2.length;\n const minTarget = Math.max(segCount1, segCount2);\n let target = minTarget;\n\n if (typeof initialTarget !== \"number\") {\n const len1 = getTotalLength(p1);\n const len2 = getTotalLength(p2);\n const avgLen = (len1 + len2) / 2;\n const maxSegCount = Math.max(segCount1, segCount2);\n const avgSegLen = avgLen / maxSegCount;\n const idealSegCount = Math.max(minTarget, Math.round(avgLen / Math.max(avgSegLen, 1)));\n target = Math.min(idealSegCount, Math.max(segCount1, segCount2) * 3);\n } else {\n if (initialTarget >= minTarget) target = initialTarget;\n else {\n console.warn(\n 'equalizeSegments \"target\" option: ' + initialTarget + \", expected >= \" + minTarget,\n );\n }\n }\n\n let equalP1: MorphPathArray = p1;\n let equalP2: MorphPathArray = p2;\n\n if (bothPolyline) {\n equalP1 = splitLinePathToCount(p1 as PolylineArray, target) as MorphPathArray;\n equalP2 = splitLinePathToCount(p2 as PolylineArray, target) as MorphPathArray;\n } else {\n equalP1 = splitCurvePathToCount(p1 as CurveArray, target) as MorphPathArray;\n equalP2 = splitCurvePathToCount(p2 as CurveArray, target) as MorphPathArray;\n }\n\n // Point alignment\n if (align !== false) equalP2 = getRotatedPath(equalP2, equalP1);\n\n if (typeof roundValues === \"number\" && roundValues !== 4) {\n equalP1 = roundPath(equalP1, roundValues);\n equalP2 = roundPath(equalP2, roundValues);\n }\n\n if (shouldClose) {\n equalP1.push([\"Z\"] as never);\n equalP2.push([\"Z\"] as never);\n }\n\n return [equalP1, equalP2];\n};\n","import type { BBoxMaxima, PointTuple } from \"../types.ts\";\n\n/**\n * Checks if a point is inside a bounding box.\n *\n * @param bbox - The bounding box as [minX, minY, maxX, maxY]\n * @param point - The point as [x, y]\n * @returns True if the point is inside or on the edge of the bounding box\n */\nexport const isPointInsideBBox = (bbox: BBoxMaxima, [x, y]: PointTuple): boolean => {\n const [minX, minY, maxX, maxY] = bbox;\n return x >= minX && x <= maxX && y >= minY && y <= maxY;\n};\n","import type { BBoxMaxima } from \"../types.ts\";\n\nimport { isPointInsideBBox } from \"./isPointInsideBBox.ts\";\n\n/**\n * Checks if two bounding boxes intersect.\n *\n * @param a - First bounding box as [minX, minY, maxX, maxY]\n * @param b - Second bounding box as [minX, minY, maxX, maxY]\n * @returns True if the bounding boxes overlap\n */\nexport const boundingBoxIntersect = (a: BBoxMaxima, b: BBoxMaxima): boolean => {\n const [ax1, ay1, ax2, ay2] = a;\n const [bx1, by1, bx2, by2] = b;\n // return ax1 <= bx2 && ax2 >= bx1 && ay1 <= by2 && ay2 >= by1;\n return (\n isPointInsideBBox(b, [ax1, ay1]) ||\n isPointInsideBBox(b, [ax2, ay1]) ||\n isPointInsideBBox(b, [ax1, ay2]) ||\n isPointInsideBBox(b, [ax2, ay2]) ||\n isPointInsideBBox(a, [bx1, by1]) ||\n isPointInsideBBox(a, [bx2, by1]) ||\n isPointInsideBBox(a, [bx1, by2]) ||\n isPointInsideBBox(a, [bx2, by2]) ||\n // edge overlap without corner inside\n (((ax1 < bx2 && ax1 > bx1) || (bx1 < ax2 && bx1 > ax1)) &&\n ((ay1 < by2 && ay1 > by1) || (by1 < ay2 && by1 > ay1)))\n );\n};\n","import type { NormalArray } from \"../types.ts\";\n\n/**\n * Create a degenerate `PathArray` at a given coordinate\n * to serve as a pair for another `PathArray`.\n * @param param0 An [x, y] tuple for the coordinate\n * @returns A new degenerate `PathArray`\n */\nexport const createPlaceholder = ([atx, aty]: [number, number]): NormalArray => {\n // Tiny square at point\n const r = 0.001;\n return [\n [\"M\", atx, aty],\n [\"L\", atx + r, aty],\n [\"L\", atx + r, aty + r],\n [\"L\", atx, aty + r],\n [\"L\", atx, aty],\n [\"Z\"],\n ];\n};\n","import type { NormalArray, PathFeature, PointTuple } from \"../types.ts\";\nimport { isPointInsideBBox } from \"../intersect/isPointInsideBBox.ts\";\nimport { boundingBoxIntersect } from \"../intersect/boundingBoxIntersect.ts\";\nimport { createPlaceholder } from \"./createPlaceholder.ts\";\n\ninterface CandidateScore {\n index: number;\n hasOverlap: boolean;\n boxIntersect: boolean;\n sizeDifference: number;\n centeredDistance: number;\n}\n\nfunction getBestMatch(target: PathFeature, candidates: PathFeature[]): PathFeature | null {\n const targetBBox = target.bbox;\n\n // Single pass: collect metrics for every candidate\n const potentialCandidates: CandidateScore[] = [];\n\n for (let i = 0; i < candidates.length; i++) {\n const { bbox, size } = candidates[i];\n\n const dx = targetBBox.cx - bbox.cx;\n const dy = targetBBox.cy - bbox.cy;\n const centeredDistance = Math.sqrt(dx * dx + dy * dy);\n\n const sizeDifference = Math.abs(target.size - size) / Math.max(target.size, size, 1e-6);\n\n const hasOverlap =\n isPointInsideBBox(\n [targetBBox.x, targetBBox.y, targetBBox.x2, targetBBox.y2],\n [bbox.cx, bbox.cy],\n ) || isPointInsideBBox([bbox.x, bbox.y, bbox.x2, bbox.y2], [targetBBox.cx, targetBBox.cy]);\n\n const boxIntersect = boundingBoxIntersect(\n [targetBBox.x, targetBBox.y, targetBBox.x2, targetBBox.y2],\n [bbox.x, bbox.y, bbox.x2, bbox.y2],\n );\n\n potentialCandidates.push({\n index: i,\n hasOverlap,\n boxIntersect,\n sizeDifference,\n centeredDistance,\n });\n }\n\n // Filter phase: strict overlap — pick smallest distance\n const overlaping = potentialCandidates.filter((c) => c.hasOverlap && c.boxIntersect);\n if (overlaping.length > 0) {\n let best = overlaping[0];\n for (let i = 1; i < overlaping.length; i++) {\n if (overlaping[i].centeredDistance < best.centeredDistance) {\n best = overlaping[i];\n }\n }\n return candidates.splice(best.index, 1)[0];\n }\n\n return null;\n}\n\n/**\n * The result of matching two sets of path features.\n */\nexport type PathFeatureMatch = {\n /** the matched feature pairs */\n pairs: [PathFeature, PathFeature][];\n /** the source features without a match */\n unmatchedFrom: PathFeature[];\n /** the target features without a match */\n unmatchedTo: PathFeature[];\n};\n\n/**\n * Matches path features by proximity and size similarity.\n *\n * @param fromPaths - Source path features to match from\n * @param toPaths - Target path features to match to\n * @returns the matched pairs and the unmatched features\n */\nexport function matchPathFeatures(\n fromPaths: PathFeature[],\n toPaths: PathFeature[],\n): PathFeatureMatch {\n // the caller's arrays must not be sorted or emptied\n const from = [...fromPaths].sort((a, b) => b.size - a.size);\n const to = [...toPaths].sort((a, b) => b.size - a.size);\n const pairs: [PathFeature, PathFeature][] = [];\n const unmatchedFrom: PathFeature[] = [];\n\n while (from.length > 0) {\n const fromPath = from.shift()!;\n const bestTo = getBestMatch(fromPath, to);\n if (bestTo) pairs.push([fromPath, bestTo]);\n else unmatchedFrom.push(fromPath);\n }\n\n return { pairs, unmatchedFrom, unmatchedTo: to };\n}\n\n/**\n * Matches paths from two sets by proximity and size similarity.\n * Unmatched paths receive placeholder paths at their centroid.\n *\n * @param fromPaths - Source path features to match from\n * @param toPaths - Target path features to match to\n * @returns Array of paired NormalArrays [from, to]\n */\nexport function matchPaths(\n fromPaths: PathFeature[],\n toPaths: PathFeature[],\n): [NormalArray, NormalArray][] {\n const { pairs, unmatchedFrom, unmatchedTo } = matchPathFeatures(fromPaths, toPaths);\n const result: [NormalArray, NormalArray][] = pairs.map(([from, to]) => [from.path, to.path]);\n\n for (const from of unmatchedFrom) {\n const fromCentroid: PointTuple = [from.bbox.cx, from.bbox.cy];\n result.push([from.path, createPlaceholder(fromCentroid)]);\n }\n\n for (const to of unmatchedTo) {\n const toCentroid: PointTuple = [to.bbox.cx, to.bbox.cy];\n result.push([createPlaceholder(toCentroid), to.path]);\n }\n\n return result;\n}\n","import type { NormalArray, PathFeature } from \"../types.ts\";\nimport { getPathBBox } from \"../util/getPathBBox.ts\";\nimport { polygonArea } from \"../math/polygonTools.ts\";\nimport { samplePolygon } from \"./samplePolygon.ts\";\nimport { isPolygonArray } from \"../util/isPolygonArray.ts\";\nimport { isPolylineArray } from \"../util/isPolylineArray.ts\";\nimport { isPointInsideBBox } from \"../intersect/isPointInsideBBox.ts\";\n\n/**\n * Classifies paths into outer (containing) and inner (hole) paths.\n *\n * A path is an inner path when it is contained by another path of the\n * same set. The winding of a contour is not used for the classification:\n * the shoelace sign only tells the direction of the contour, and in the\n * SVG coordinate system (y pointing down) the usual outer contour has a\n * *negative* signed area.\n *\n * @param paths - Array of normalized path arrays to classify\n * @returns Object with `outers` (containing shapes) and `inners` (holes)\n */\nexport const classifyPaths = (\n paths: NormalArray[],\n): {\n outers: PathFeature[];\n inners: PathFeature[];\n} => {\n const features: PathFeature[] = paths.map((path) => {\n const signedArea = polygonArea(samplePolygon(path));\n const bbox = getPathBBox(path);\n return {\n isPoly: isPolygonArray(path) || isPolylineArray(path),\n size: bbox.width * bbox.height,\n path,\n signedArea,\n area: Math.abs(signedArea),\n bbox,\n };\n });\n\n const outers: PathFeature[] = [];\n const inners: PathFeature[] = [];\n\n for (const feature of features) {\n // a hole is a path contained by a bigger path of the same set\n const isInner = features.some(\n (other) =>\n other !== feature &&\n other.area > feature.area &&\n isPointInsideBBox(\n [other.bbox.x, other.bbox.y, other.bbox.x2, other.bbox.y2],\n [feature.bbox.cx, feature.bbox.cy],\n ),\n );\n\n if (isInner) {\n inners.push(feature);\n } else {\n outers.push(feature);\n }\n }\n\n return { outers, inners };\n};\n","import type {\n NormalArray,\n PathArray,\n PathFeature,\n PathsEqualizationOptions,\n PointTuple,\n} from \"../types.ts\";\nimport { isMultiPath } from \"../util/isMultiPath.ts\";\nimport { splitPath } from \"../process/splitPath.ts\";\nimport { equalizeSegments, getDistance, getPathEnds } from \"./equalizeSegments.ts\";\nimport { matchPathFeatures } from \"./matchPaths.ts\";\nimport { createPlaceholder } from \"./createPlaceholder.ts\";\nimport { normalizePath } from \"../process/normalizePath.ts\";\nimport { reversePath } from \"../process/reversePath.ts\";\nimport { polygonArea } from \"../math/polygonTools.ts\";\nimport { samplePolygon } from \"./samplePolygon.ts\";\nimport { classifyPaths } from \"./classifyPaths.ts\";\nimport { getPathArea } from \"../util/getPathArea.ts\";\n\nconst equalizePathsDefaults: PathsEqualizationOptions = {\n mode: \"auto\", // \"line\" | \"curve\" | \"auto\"\n strategy: \"segment\", // \"segment\" | \"arcLength\"\n align: true,\n roundValues: 4, // 4 decimals\n sampleSize: 10,\n};\n\nconst getPrimaryOuter = (outers: PathFeature[]): PathFeature | undefined => {\n let primary: PathFeature | undefined;\n for (const outer of outers) {\n if (!primary || outer.size > primary.size) primary = outer;\n }\n return primary;\n};\n\nconst getOuterDirection = (outers: PathFeature[]): number => {\n const primary = getPrimaryOuter(outers);\n if (!primary) return 0;\n return Math.sign(getPathArea(primary.path));\n};\n\n/**\n * Equalizes two paths for morphing (single/multi subpath).\n *\n * Multi-subpath paths are reversed as whole paths, so an outer contour keeps\n * its relationship with its holes. Outer contours only match outer contours\n * and holes only match holes: an unmatched contour collapses at its own\n * centroid instead of taking the opposite fill role.\n *\n * @see https://minus-ze.ro/posts/morphing-arbitrary-paths-in-svg/\n * @param pathInput1 - First path string or PathArray\n * @param pathInput2 - Second path string or PathArray\n * @param initialCfg - Configuration options for equalization\n * @returns Tuple of two equalized PathArrays\n *\n * @example\n * ```ts\n * const [eq1, eq2] = equalizePaths('M0 0L100 0L50 100Z', 'M0 0L100 0L100 100L0 100Z')\n * // eq1.length === eq2.length — ready for morphing\n * ```\n */\nexport const equalizePaths = (\n pathInput1: string | PathArray,\n pathInput2: string | PathArray,\n initialCfg: PathsEqualizationOptions = {},\n): [PathArray, PathArray] => {\n const cfg = { ...equalizePathsDefaults, ...initialCfg };\n const p1 = normalizePath(pathInput1);\n const p2 = normalizePath(pathInput2);\n\n const multi1 = isMultiPath(p1);\n const multi2 = isMultiPath(p2);\n\n if (!multi1 && !multi2) {\n // Single subpath — use fast path\n return equalizeSegments(p1, p2, cfg);\n }\n\n let path1 = p1;\n let path2 = p2;\n let multiPath1 = splitPath(path1);\n let multiPath2 = splitPath(path2);\n let classified1 = classifyPaths(multiPath1);\n let classified2 = classifyPaths(multiPath2);\n\n if (cfg.reverse === undefined) {\n const globalArea1 = polygonArea(samplePolygon(p1));\n const globalArea2 = polygonArea(samplePolygon(p2));\n\n if (Math.sign(globalArea1) < 0) path1 = reversePath(path1);\n if (Math.sign(globalArea2) < 0) path2 = reversePath(path2);\n } else if (cfg.reverse === true || cfg.reverse === \"auto\") {\n const direction1 = getOuterDirection(classified1.outers);\n const direction2 = getOuterDirection(classified2.outers);\n\n if (direction1 && direction2 && direction1 !== direction2) {\n let reverseFirst = false;\n\n if (cfg.reverse === \"auto\") {\n const outer1 = getPrimaryOuter(classified1.outers)!;\n const outer2 = getPrimaryOuter(classified2.outers)!;\n const ends1 = getPathEnds(outer1.path);\n const ends2 = getPathEnds(outer2.path);\n reverseFirst = getDistance(ends1.end, ends2.start) < getDistance(ends1.start, ends2.end);\n }\n\n if (reverseFirst) path1 = reversePath(path1);\n else path2 = reversePath(path2);\n }\n }\n\n if (path1 !== p1 || path2 !== p2) {\n multiPath1 = splitPath(path1);\n multiPath2 = splitPath(path2);\n classified1 = classifyPaths(multiPath1);\n classified2 = classifyPaths(multiPath2);\n }\n\n const outerMatches = matchPathFeatures(classified1.outers, classified2.outers);\n const innerMatches = matchPathFeatures(classified1.inners, classified2.inners);\n const featurePairs = [...outerMatches.pairs, ...innerMatches.pairs];\n const contourPairs: [NormalArray, NormalArray][] = featurePairs.map(([from, to]) => [\n from.path,\n to.path,\n ]);\n\n for (const feature of [...outerMatches.unmatchedFrom, ...innerMatches.unmatchedFrom]) {\n const centroid: PointTuple = [feature.bbox.cx, feature.bbox.cy];\n contourPairs.push([feature.path, createPlaceholder(centroid)]);\n }\n\n for (const feature of [...outerMatches.unmatchedTo, ...innerMatches.unmatchedTo]) {\n const centroid: PointTuple = [feature.bbox.cx, feature.bbox.cy];\n contourPairs.push([createPlaceholder(centroid), feature.path]);\n }\n\n const equalizedPairs: [PathArray, PathArray][] = [];\n\n for (const [from, to] of contourPairs) {\n const [eqFrom, eqTo] = equalizeSegments(from, to, {\n ...cfg,\n reverse: false,\n });\n equalizedPairs.push([eqFrom, eqTo]);\n }\n\n // Reassemble into final morphable paths\n const finalFrom = equalizedPairs.map((p) => p[0]).flat() as PathArray;\n const finalTo = equalizedPairs.map((p) => p[1]).flat() as PathArray;\n\n return [finalFrom, finalTo];\n};\n","// src/morph/equalize.ts\nimport type { EqualizeOptions, PathArray } from \"../types.ts\";\nimport { isMultiPath } from \"../util/isMultiPath.ts\";\nimport { normalizePath } from \"../process/normalizePath.ts\";\nimport { equalizePaths } from \"./equalizePaths.ts\";\nimport { equalizeSegments } from \"./equalizeSegments.ts\";\nimport { error } from \"../util/error.ts\";\n\nconst equalizeDefaults: EqualizeOptions = {\n points: \"auto\",\n strategy: \"segment\",\n align: true,\n reverse: \"auto\",\n mode: \"auto\",\n roundValues: 4,\n};\n\n/**\n * Equalizes two paths for morphing.\n *\n * The two paths are brought to the same shape, so they can be morphed into\n * each other: they hold the same number of segments of the same type, their\n * winding is the same and their points are aligned.\n *\n * A path with a single sub-path is equalized on its own, a path with more\n * sub-paths is split into sub-paths, the sub-paths are matched by their\n * shape and every pair is equalized on its own. Multi-subpath paths are\n * reversed as whole paths, so an outer contour keeps its relationship with\n * its holes. Outer contours only match outer contours and holes only match\n * holes: an unmatched contour collapses at its own centroid instead of\n * taking the opposite fill role.\n *\n * The `strategy` option decides how the points of the paths are placed:\n * - `segment` splits the segments of the paths, so the points of the result\n * are the points of the paths;\n * - `arcLength` distributes the points of the result along the length of\n * the paths. The source segment boundaries and corners are points of the\n * result too when the requested count allows it, so the shape of the paths\n * keeps its vertices.\n *\n * The `points` option is the number of points of the result. The automatic\n * mode uses the number of points of the bigger path.\n *\n * The `reverse` option decides what happens when the two paths draw in\n * opposite directions: `true` reverses the second path, `false` leaves the\n * paths as they are and `auto` reverses the path that leaves the two paths\n * closest to each other.\n *\n * @see https://minus-ze.ro/posts/morphing-arbitrary-paths-in-svg/\n *\n * @param pathInput1 - First path string or PathArray\n * @param pathInput2 - Second path string or PathArray\n * @param initialCfg - Configuration options for equalization\n * @returns Tuple of two equalized PathArrays\n *\n * @example\n * ```ts\n * const [eq1, eq2] = equalize('M0 0L100 0L50 100Z', 'M0 0L100 0L100 100L0 100Z')\n * // eq1.length === eq2.length — ready for morphing\n * ```\n */\nexport const equalize = (\n pathInput1: string | PathArray,\n pathInput2: string | PathArray,\n initialCfg: EqualizeOptions = {},\n): [PathArray, PathArray] => {\n const { align, close, mode, points, reverse, roundValues, strategy } = {\n ...equalizeDefaults,\n ...initialCfg,\n };\n\n if (typeof points === \"number\" && (!Number.isFinite(points) || points < 2)) {\n throw new TypeError(`${error}: points must be a number greater than 1`);\n }\n\n const p1 = normalizePath(pathInput1);\n const p2 = normalizePath(pathInput2);\n\n // a path with more than one sub-path is split and matched first\n if (isMultiPath(p1) || isMultiPath(p2)) {\n return equalizePaths(p1, p2, {\n align,\n close,\n mode,\n reverse,\n roundValues,\n strategy,\n target: typeof points === \"number\" ? points : undefined,\n });\n }\n\n return equalizeSegments(p1, p2, {\n align,\n close,\n mode,\n reverse,\n roundValues,\n strategy,\n target: typeof points === \"number\" ? points : undefined,\n });\n};\n","import type {\n CubicCoordinates,\n IntersectionOptions,\n IntersectionPoint,\n PointAtLength,\n} from \"../types.ts\";\nimport { getCubicBBox, getCubicLength, getPointAtCubicLength } from \"../math/cubicTools.ts\";\nimport distanceEpsilon from \"../util/distanceEpsilon.ts\";\nimport { roundTo } from \"../math/roundTo.ts\";\nimport { boundingBoxIntersect } from \"./boundingBoxIntersect.ts\";\n\nconst intersect = (\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n x3: number,\n y3: number,\n x4: number,\n y4: number,\n) => {\n if (\n Math.max(x1, x2) < Math.min(x3, x4) ||\n Math.min(x1, x2) > Math.max(x3, x4) ||\n Math.max(y1, y2) < Math.min(y3, y4) ||\n Math.min(y1, y2) > Math.max(y3, y4)\n ) {\n return;\n }\n const nx = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4),\n ny = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4),\n denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);\n\n if (!denominator) {\n return;\n }\n const px = nx / denominator,\n py = ny / denominator,\n px2 = roundTo(px, 2),\n py2 = roundTo(py, 2);\n if (\n px2 < roundTo(Math.min(x1, x2), 2) ||\n px2 > roundTo(Math.max(x1, x2), 2) ||\n px2 < roundTo(Math.min(x3, x4), 2) ||\n px2 > roundTo(Math.max(x3, x4), 2) ||\n py2 < roundTo(Math.min(y1, y2), 2) ||\n py2 > roundTo(Math.max(y1, y2), 2) ||\n py2 < roundTo(Math.min(y3, y4), 2) ||\n py2 > roundTo(Math.max(y3, y4), 2)\n ) {\n return;\n }\n return { x: px, y: py };\n};\n\n/**\n * Returns the intersection point(s) of two cubic Bezier curves.\n *\n * @param bez1 the coordinates of the first cubic Bezier segment\n * @param bez2 the coordinates of the second cubic Bezier segment\n * @param config optional intersection options\n * @returns the intersection points, or `undefined` if the curves do not intersect\n */\nexport const interHelper = (\n bez1: CubicCoordinates,\n bez2: CubicCoordinates,\n config?: IntersectionOptions,\n) => {\n const bbox1 = getCubicBBox(...bez1);\n const bbox2 = getCubicBBox(...bez2);\n const { justCount, epsilon } = Object.assign(\n {\n justCount: true,\n epsilon: distanceEpsilon,\n },\n config,\n );\n\n if (!boundingBoxIntersect(bbox1, bbox2)) {\n return justCount ? 0 : ([] as IntersectionPoint[]);\n }\n const l1 = getCubicLength(...bez1),\n l2 = getCubicLength(...bez2),\n n1 = Math.max((l1 / 5) >> 0, 1),\n n2 = Math.max((l2 / 5) >> 0, 1),\n points1: PointAtLength[] = [],\n points2: PointAtLength[] = [],\n xy: Record<string, string> = {};\n // deno-lint-ignore prefer-const\n let res = justCount ? 0 : ([] as IntersectionPoint[]);\n for (let i = 0; i < n1 + 1; i++) {\n const p = getPointAtCubicLength(...bez1, (i / n1) * l1);\n points1.push({ x: p.x, y: p.y, t: i / n1 });\n }\n for (let i = 0; i < n2 + 1; i++) {\n const p = getPointAtCubicLength(...bez2, (i / n2) * l2);\n points2.push({ x: p.x, y: p.y, t: i / n2 });\n }\n for (let i = 0; i < n1; i++) {\n for (let j = 0; j < n2; j++) {\n const maxLimit = 1 + epsilon,\n di = points1[i],\n di1 = points1[i + 1],\n dj = points2[j],\n dj1 = points2[j + 1],\n ci = Math.abs(di1.x - di.x) < 0.001 ? \"y\" : \"x\",\n cj = Math.abs(dj1.x - dj.x) < 0.001 ? \"y\" : \"x\",\n is = intersect(di.x, di.y, di1.x, di1.y, dj.x, dj.y, dj1.x, dj1.y);\n if (is) {\n // istanbul ignore next 2\n if (xy[is.x.toFixed(4)] == is.y.toFixed(4)) {\n continue;\n }\n xy[is.x.toFixed(4)] = is.y.toFixed(4);\n const t1 = di.t + Math.abs((is[ci] - di[ci]) / (di1[ci] - di[ci])) * (di1.t - di.t),\n t2 = dj.t + Math.abs((is[cj] - dj[cj]) / (dj1[cj] - dj[cj])) * (dj1.t - dj.t);\n\n // istanbul ignore else\n if (t1 >= 0 && t1 <= maxLimit && t2 >= 0 && t2 <= maxLimit) {\n if (justCount) {\n (res as number)++;\n } else {\n (res as IntersectionPoint[]).push({\n x: is.x,\n y: is.y,\n t1: Math.min(t1, 1),\n t2: Math.min(t2, 1),\n });\n }\n }\n }\n }\n }\n return res;\n};\n","import type { CubicCoordinates, IntersectionPoint, PathArray } from \"../types.ts\";\nimport { pathToCurve } from \"../convert/pathToCurve.ts\";\nimport { interHelper } from \"./interHelper.ts\";\n\n/**\n * Finds intersection points between two paths.\n *\n * @param pathInput1 - First path string or PathArray\n * @param pathInput2 - Second path string or PathArray\n * @param justCount - If true, returns the count of intersections; if false, returns the intersection points\n * @returns The number of intersections (when justCount is true) or an array of IntersectionPoint objects\n *\n * @example\n * ```ts\n * pathsIntersection('M0 50C0 0,100 0,100 50', 'M50 0C100 0,100 100,50 100', true)\n * // => 1\n * pathsIntersection('M0 50C0 0,100 0,100 50', 'M50 0C100 0,100 100,50 100', false)\n * // => [{ x: 80.4136, y: 19.5864, t1: 0.7262, t2: 0.2738 }]\n * ```\n */\nexport const pathsIntersection = <T extends string | PathArray>(\n pathInput1: T,\n pathInput2: T,\n justCount = /* istanbul ignore next */ true,\n): number | IntersectionPoint[] => {\n const path1 = pathToCurve(pathInput1);\n const path2 = pathToCurve(pathInput2);\n let x1 = 0,\n y1 = 0,\n x2 = 0,\n y2 = 0,\n x1m = 0,\n y1m = 0,\n x2m = 0,\n y2m = 0,\n bez1: CubicCoordinates = [x1, y1, x1, y1, x1m, y1m, x1m, y1m],\n bez2: CubicCoordinates = [x2, y2, x2, y2, x2m, y2m, x2m, y2m],\n countResult = 0;\n const pointsResult: IntersectionPoint[] = [];\n const pathLen1 = path1.length;\n const pathLen2 = path2.length;\n\n for (let i = 0; i < pathLen1; i++) {\n const seg1 = path1[i];\n if (seg1[0] == \"M\") {\n x1 = seg1[1];\n y1 = seg1[2];\n x1m = x1;\n y1m = y1;\n } else {\n /* istanbul ignore else */\n if (seg1[0] == \"C\") {\n bez1 = [x1, y1, seg1[1], seg1[2], seg1[3], seg1[4], seg1[5], seg1[6]];\n x1 = bez1[6];\n y1 = bez1[7];\n } else {\n bez1 = [x1, y1, x1, y1, x1m, y1m, x1m, y1m];\n x1 = x1m;\n y1 = y1m;\n }\n for (let j = 0; j < pathLen2; j++) {\n const seg2 = path2[j];\n // istanbul ignore else\n if (seg2[0] == \"M\") {\n x2 = seg2[1];\n y2 = seg2[2];\n x2m = x2;\n y2m = y2;\n } else if (seg2[0] == \"C\") {\n bez2 = [x2, y2, seg2[1], seg2[2], seg2[3], seg2[4], seg2[5], seg2[6]];\n x2 = bez2[6];\n y2 = bez2[7];\n // dead code, pathToCurve is almost always made of M/C\n // } else {\n // bez2 = [x2, y2, x2, y2, x2m, y2m, x2m, y2m];\n // x2 = x2m;\n // y2 = y2m;\n }\n const intr = interHelper(bez1, bez2, { justCount });\n if (justCount) {\n // (res as number) += intr;\n countResult += intr as number;\n } else {\n // Include additional segment properties, maybe not\n // const kk = (intr as IntersectionPoint[]).length;\n // for (let k = 0; k < kk; k++) {\n // intr[k].segment1 = i;\n // intr[k].segment2 = j;\n // intr[k].bez1 = bez1;\n // intr[k].bez2 = bez2;\n // }\n // (res as IntersectionPoint[]) = (res as IntersectionPoint[]).concat(intr);\n pointsResult.push(...(intr as IntersectionPoint[]));\n }\n }\n }\n }\n return justCount ? countResult : pointsResult;\n};\n"],"mappings":";;;;;;;;;;;AASA,MAAM,iBAAiB,IAAY,IAAY,IAAY,OAAuB;CAChF,MAAM,KAAK,KAAK;CAChB,MAAM,KAAK,KAAK;CAChB,OAAO,KAAK,KAAK,KAAK,KAAK,KAAK,EAAE;AACpC;;;;;;;;;;;AAYA,MAAM,wBACJ,IACA,IACA,IACA,IACA,aAC6B;CAC7B,IAAI,QAAQ;EAAE,GAAG;EAAI,GAAG;CAAG;CAG3B,IAAI,OAAO,aAAa,UAAU;EAChC,MAAM,SAAS,cAAc,IAAI,IAAI,IAAI,EAAE;EAC3C,I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