Documentation
    Preparing search index...

    Function parseSvgPathData

    • Parses an SVG d attribute into a §51 Path (§50 "SVG import").

      const heart = parseSvgPathData("M 0 0 C 0 -6 10 -6 10 0 C 10 6 0 10 0 16");
      heart.commands.length; // 3

      Coordinates are transcribed verbatim: SVG's Y-down user space is not reconciled with §7a's Y-up world here, because the transform that would do it needs the document's viewBox. See this module's header — it is one exact Path.transform away, and the reasoning is worth reading before assuming this is an oversight.

      The returned path carries the default nonzero Path.fillRule; SVG's fill-rule is a presentation attribute and is not part of path data.

      One coordinate can differ from the document's by a few ulps: the endpoint of a segment that is immediately followed by an A, which is moved onto the arc's computed start so the two do not disagree at a sub-ulp scale and produce a spike §52 refuses. The module header argues it in full.

      Parameters

      • pathData: string

        the d attribute's value; empty or whitespace-only yields an empty path, which is what SVG says such a path draws

      • options: SvgPathParseOptions = {}

        §96 bounds on the untrusted text

      Returns Path

      a fresh path

      FourError UNTRUSTED_INPUT_REJECTED when the text exceeds SvgPathParseOptions.maximumTextLength

      a SyntaxError, naming the offset, for anything the d grammar does not admit — nothing parsed before the error is kept

      a RangeError when maximumTextLength is not a positive number