SVG nesting tool
npm install svgnest-mjsA modern ES module for irregular shape nesting using a genetic algorithm. Based on the original SVGNest by Jack000.
``javascript
import SvgNest from 'svgnest';
const nest = new SvgNest();
// 1. Load your SVG
const root = nest.parseSvg(svgString);
// 2. Select the container (bin) element
const bin = root.querySelector('#bin');
nest.setBin(bin);
// 3. Configure (optional)
nest.config({
spacing: 10,
rotations: 4,
populationSize: 10
});
// 4. Start nesting
nest.start(
(progress) => console.log(NFP Progress: ${progress * 100}%),Placed ${placedCount}/${totalCount} at ${efficiency * 100}% efficiency
(svgList, efficiency, placedCount, totalCount) => {
if (svgList) {
console.log();
document.body.appendChild(svgList[0]);
}
}
);
// 5. Stop when satisfied
// nest.stop();
``