v160 · dom · svg

Point editor

What SVG editors such as Boxy SVG and SVG-Edit needed a polyfill for: import a path, turn it into points you can grab, and write the edit back. Import here is getPathData({normalize: true}), so arcs and quadratics arrive as plain cubic control points; every drag or arrow-key nudge mutates one number in that array and calls setPathData(). The d string below is never built by this page — it is the browser’s own serialisation.

Chrome 160+ ships this by default. Earlier Chrome/Canary: enable chrome://flags/#enable-experimental-web-platform-features, or launch with --enable-blink-features=SVGPathDataAPI (also --enable-features=SVGPathDataAPI or --enable-experimental-web-platform-features).
Probing this browser…

Import a shape

Path editing canvas. Each handle is a focusable button; arrow keys move it, Shift with arrows moves 10 units.
Import a shape to start editing.
d =

the editor loop

// import: one call turns any path into M/L/C/Z with explicit control points
let model = path.getPathData({ normalize: true });

// edit: points are just numbers in plain objects
model[i].values[k] = x;  model[i].values[k + 1] = y;

// write back: no string building, no parser
path.setPathData(model);
path.getAttribute("d");   // the browser's serialisation of your model

// setPathData goes through the attribute pipeline,
// so MutationObserver sees attributeName === "d"

Why normalise on import? An editor that keeps h, q or a has to understand twenty command letters and their implied points; after normalisation every handle is either an endpoint or a cubic control point. The trade-off: arcs become cubic approximations and the original command letters are gone, so the segment inspector shows both forms.

see also