@thi.ng/hiccup-svg
Version:
SVG element functions for @thi.ng/hiccup & related tooling
46 lines (45 loc) • 1.01 kB
JavaScript
import { fattribs, ff, fpoint, fpoints } from "./format.js";
const DEG = 180 / Math.PI;
const path = (segments, attribs, ...body) => {
let res = [];
for (let seg of segments) {
res.push(seg[0]);
switch (seg[0].toLowerCase()) {
case "a":
res.push(
[
// rx
ff(seg[1]),
// ry
ff(seg[2]),
// x-axis (theta)
ff(seg[3] * DEG),
// xl
seg[4] ? 1 : 0,
// clockwise
seg[5] ? 1 : 0,
// target xy
ff(seg[6][0]),
ff(seg[6][1])
].join(",")
);
break;
case "h":
case "v":
res.push(ff(seg[1]));
break;
case "m":
case "l":
res.push(fpoint(seg[1]));
break;
case "z":
break;
default:
res.push(fpoints(seg.slice(1), ","));
}
}
return ["path", fattribs({ d: res.join(""), ...attribs }), ...body];
};
export {
path
};