This is a major release of p5.plotSvg, focused on p5.js add-on support and expanded p5.js version compatibility.
Highlights of this release:
- Adds support for the p5.js add-on API style, including instance methods such as
sketch.beginRecordSvg()and
sketch.endRecordSvg(). - Supports both p5.js v1 and p5.js v2 workflows, with testing against p5.js v1.11.13 and p5.js v2.3.0.
- Preserves backward compatibility with existing script-tag usage, the
p5plotSvgnamespace, and legacy global
functions. - Adds generated browser and ESM builds in
dist/, while keeping the legacylib/p5.plotSvg.jspath available
for existing CDN users. - Expands automated browser tests for p5 v1/v2, global mode, instance mode, generated package builds, SVG
escaping, path output, and Smorgasbord regression fixtures.
Distinctive p5.plotSvg features:
- Plotter-oriented SVG output: exports clean path geometry intended for pen plotters, laser cutters, CNC tools,
and related vector workflows. - Export-on-demand workflow: captures SVG only when
beginRecordSvg()/endRecordSvg()are active, so normal
animated sketches keep running at canvas speed. - Backward-compatible API: supports legacy global functions, the
p5plotSvgnamespace, and newer add-on-style
p5 instance methods. - Instance-mode support: works in both p5 global mode and instance mode.
- SVG grouping tools: supports named SVG groups, optional Inkscape-compatible layer metadata, group merging, and
stroke-color grouping for multi-pen workflows. - Transform handling options: can preserve transform hierarchies as SVG groups or flatten transforms into per-
element matrix attributes. - Decimal precision controls: lets users tune coordinate and transform precision to balance file size and
numeric fidelity. - Numeric safety rails: detects malformed numeric values such as
NaNandInfinity, with configurable
sanitize-or-skip behavior. - Large-coordinate protection: clamps extremely large finite coordinate values by default, with configurable
clamp magnitude. - No-op path filtering: omits degenerate SVG paths such as empty, move-only, and move/close-only paths.
- SVG escaping and validation: escapes user-provided text and attributes and validates injected XML names.
- Extension hooks: exposes experimental command, attribute, header, and
<defs>injection hooks for advanced
users and companion tools. - Regression-tested output: includes Playwright browser tests covering p5 v1/v2, global/instance mode, package
builds, path data, escaping, and broad, kitchen-sink-style Smorgasbord examples.
Known ongoing work:
- Full support for p5.js v2’s revised curve and spline implementations is still in progress.
- Exporting text as SVG outlines is still planned but not yet implemented.
clip(),beginClip(), andendClip()remain intentionally unsupported for SVG export, because plotter-safe
clipping requires extensive computational geometry and path splitting.