npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

p5.svg-io

v0.1.0

Published

Native SVG export and Import for p5.js using Shape system

Readme

p5.svg-io

[!WARNING] This repository is currently in active development. APIs and behavior are subject to change.

Native SVG export and import support for p5.js using the Shape system and PrimitiveVisitor architecture.

This project is being developed as a GSoC 2026 project and focuses on building a retained rendering pipeline for exporting and importing p5.js sketches as scalable SVG documents.


Guide: SVG Recording Options

p5.SVG.js provides two distinct ways to capture your drawing instructions as SVGs:

1. Functional Capture (buildShape)

Best for synchronous, self-contained drawing blocks. You pass a callback containing your drawing code. Always call buildShape inside a p5.js loop or function context after the canvas is created.

function setup() {
  createCanvas(400, 400);

  const drawing = buildShape(() => {
    background(255);
    fill(255, 0, 0);
    circle(100, 100, 50);
  });

  saveSVG(drawing, 'my-art.svg');
}

2. State-Based Capture (beginRecord & endRecord)

Best when drawing operations span multiple functions, are event-driven, or when wrapping code in a callback is not practical.

function setup() {
  createCanvas(400, 400);
  
  // Start recording
  beginRecord();
  
  background(240);
  fill(0, 0, 255);
  rect(50, 50, 100, 100);
}

function mousePressed() {
  // Stop recording and download the SVG
  const record = endRecord();
  if (record) {
    saveSVG(record, 'interactive-sketch.svg');
  }
}

3. Retrieving the Raw SVG String (getSVG)

If you want to access the raw SVG XML string directly (e.g., to display it on the page or send it to a server) instead of triggering a file download:

function setup() {
  createCanvas(400, 400);

  const drawing = buildShape(() => {
    circle(100, 100, 50);
  });

  const svgString = getSVG(drawing);
  console.log(svgString); // "<svg ...>...</svg>"
}

Best Practices & Warnings

  • Mismatched Pairs: Each call to beginRecord() should have a corresponding endRecord(). Calling endRecord() without first starting a recording will log a warning and return null.
  • No Nesting: Do not call beginRecord() while a recording is already active. Doing so will automatically stop and discard the previous recording, issuing a console warning.
  • Record Nodes: endRecord() returns a recorded tree structure. You must pass this object to saveSVG(record, filename) or getSVG(record) to generate/download the SVG.

Quickstart Installation

Include the p5.js library and the p5.svgExport.min.js addon in your project's index.html file:

<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
  <title>p5.SVG Export Example</title>
  <!-- Load p5.js -->
  <script src="https://raw.esm.sh/pr/p5@02bcb7e/lib/p5.min.js"></script>
  <!-- Load p5.SVG Export Addon -->
  <script src="dist/p5.svgExport.min.js"></script>
</head>
<body>
  <script src="sketch.js"></script>
</body>
</html>

Next, write your p5.js drawing code. Be sure to call buildShape and other addon functions inside setup(), draw(), or event callbacks once the p5.js canvas has been initialized:

// sketch.js
function setup() {
  createCanvas(400, 400);

  // Record drawing commands using buildShape
  const drawing = buildShape(() => {
    circle(100, 100, 50);
    rect(200, 100, 80, 60);
  });

  // Save the recorded drawing as an SVG
  saveSVG(drawing, 'my-art.svg');
}

Design Document

The complete architecture and implementation planning document is available here:

Google Doc - p5.svg-export Design Document

The document covers:

  • recording architecture
  • transform tracking
  • flat vs hierarchical recording
  • visitor pattern export
  • retained rendering structure
  • future extensibility

Local Development

To get started with local development:

  1. Install dependencies:

    npm install
  2. Build the bundle:

    npm run build

This will run Rollup to bundle the addon, outputting the result to the dist/ directory.