Extract once, then fan out to several output formats. This keeps geometry and paint-order consistent across artifacts generated in a single run.
DXF
SVG
HTML
PNG
Code
import {
extractIR,
renderIR,
DXFWriter,
SVGWriter,
HTMLWriter,
ImageWriter
} from "@node-projects/layout2vector";
async function exportAll(root) {
const bounds = root.getBoundingClientRect();
const ir = await extractIR(root, {
includeText: true,
includeImages: true,
convertFormControls: true,
includePseudoElements: true
});
const dxf = await renderIR(ir, new DXFWriter({ maxY: Math.ceil(bounds.height) }));
const svg = await renderIR(ir, new SVGWriter({ width: bounds.width, height: bounds.height }));
const html = await renderIR(ir, new HTMLWriter({ width: bounds.width, height: bounds.height }));
const image = await renderIR(ir, new ImageWriter({
width: bounds.width,
height: bounds.height,
scale: 2
}));
await image.finalize();
const pngBytes = image.toBytes();
return { dxf, svg, html, pngBytes };
}