v160 · dom · svg
Path morph
Morphing between two arbitrary SVG shapes is the classic reason data-viz libraries ship a path parser: a circle made of arcs and a star made of lines have nothing in common until you normalise them. Here the browser does the hard part — getPathData({normalize: true}) turns both into absolute M/L/C/Z — and this page only converts lines to cubics, splits curves until the counts match, and interpolates numbers into setPathData().
Pick two shapes
the pipeline
const a = probeA.getPathData({ normalize: true }); // arcs, q, h/v… → M L C Z
const b = probeB.getPathData({ normalize: true });
const ca = toCubics(a), cb = toCubics(b); // L → C (controls at 1/3, 2/3)
equalise(ca, cb); // split the longest curve at t = 0.5
// until both have the same count
slider.oninput = () => shape.setPathData(lerp(ca, cb, t)); // numbers in, path out
What the API saves you: parsing twenty command letters, resolving relative coordinates, expanding S/T reflections and converting arcs to Béziers — and the string building on every frame. What it does not do: choose matching start points or winding, so a star and a circle can twist as they morph. That alignment step stays in your code.