# maker.js - svg库

# 1. 介绍

Maker.js, a Microsoft Garage project, is a JavaScript library for creating and sharing modular line drawings for CNC and laser cutters.

官网: https://maker.js.org/ (opens new window)

# 2. 使用

# 2.1. 绘制图形的 outline

示例:

import marker from 'makerjs';

const pathData = 'M 0 0 L 30 0 L 240 0 L 450 0 L 480 0';

const model = maker.importer.fromSVGPathData(pathData);

const outlineModel = maker.model.outline(model, 10, 0);

const simplifyModel = maker.model.simplify(outlineModel);

const outlinePathData = maker.exporter.toSVGPathData(simplifyModel, {
  origin: [0, 0],
});

console.log(outlinePathData); 
// M 0 -10 L 480 -10 A 10 10 0 0 1 480 10 L 0 10 A 10 10 0 0 1 0 -10 Z

参考: svg-path-outline —— GitHub (opens new window)

本章目录