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

@doenet/prefigure

v0.5.13

Published

Standalone PreFigure WASM compiler for browser and CDN usage

Downloads

867

Readme

@doenet/prefigure

Standalone PreFigure compiler package for browser and CDN usage.

Run the PreFigure Python compiler in the browser via Pyodide + Web Worker. This package can be loaded from NPM or from a CDN (jsDelivr) and provides a full-featured PreFigure XML → SVG compiler without server dependencies.

Attribution

This package includes code adapted from the PreFigure project and its browser playground runtime:

  • Upstream repository: https://github.com/davidaustinm/prefigure
  • Project website: https://prefigure.org

The upstream-derived worker/runtime pieces remain available under the GNU Affero General Public License, version 3 or later. This package is distributed under the same AGPL-3.0-or-later license and preserves attribution to the upstream PreFigure work. See NOTICE.md for package-specific provenance.

Installation

npm install @doenet/prefigure

Or load from CDN:

<script type="module">
  import * as prefigure from 'https://cdn.jsdelivr.net/npm/@doenet/prefigure@latest';
  await prefigure.initPrefigure();
  const result = await prefigure.compilePrefigure(diagramXml, { mode: 'svg' });
</script>

Global API

When loaded in a browser, this package registers:

  • window.initPrefigure(indexURL?)
  • window.prefigure(source, { mode, indexURL })

Both methods return promises.

Example

<script type="module" src="./prefigure.js"></script>
<script type="module">
	await window.initPrefigure();
	const result = await window.prefigure(`<diagram dimensions="(100,100)"></diagram>`);
	console.log(result.svg, result.annotationsXml);
</script>

Browser Runtime Check

Run a local browser runtime check harness that compiles a tiny diagram and checks for non-empty SVG + annotations output:

npm run browser-runtime -w @doenet/prefigure

Then open http://127.0.0.1:4175/.

The page shows PASS when compilePrefigure(...) returns both:

  • SVG containing an <svg> element
  • annotations XML containing <annotations> or <annotation>

Automated Tests

Run package tests:

npm run test -w @doenet/prefigure

Current coverage includes API-level behavior tests for:

  • default index URL resolution
  • initPrefigure() idempotency and conflicting-URL guard
  • compilePrefigure() delegation/result mapping
  • dedicated-worker API wiring and compile delegation behavior

The browser runtime check remains useful as a manual runtime check for real Pyodide+WASM execution.

Wheel Requirement

Builds currently vendor wheels from pyodide_packages/. Before publishing, ensure a matching prefig-<version>-py3-none-any.whl is present there. At runtime, initPrefigure() defaults to loading from ./assets/.

Repository Hygiene

These directories/files in packages/prefigure are generated and safe to delete locally:

  • dist/
  • pyodide_packages/
  • .wireit/
  • src/worker/liblouis/generated/build-no-tables-utf32.js
  • src/worker/liblouis/generated/*.cti
  • src/worker/liblouis/generated/*.ctb
  • src/worker/liblouis/generated/*.uti
  • src/worker/liblouis/generated/*.dis

They are re-created by build/setup scripts and are already ignored by the repository .gitignore.

Maintenance Procedures

First-time setup

npm run setup -w @doenet/prefigure

This downloads:

  • runtime Pyodide wheels and the pinned prefig wheel into pyodide_packages/
  • liblouis JS/tables into src/worker/liblouis/generated/

Normal build + publish checks

npm run build -w @doenet/prefigure
npm run verify-wheel-sync -w @doenet/prefigure

verify-wheel-sync ensures src/worker/compiler-metadata.ts and pyodide_packages/ reference the same prefig wheel.

Upgrade prefig wheel version

  1. Update PREFIG_WHEEL_FILENAME in src/worker/compiler-metadata.ts.
  2. Run npm run setup -w @doenet/prefigure.
  3. Run npm run verify-wheel-sync -w @doenet/prefigure.
  4. Build and run the browser runtime check:
npm run build -w @doenet/prefigure
npm run browser-runtime -w @doenet/prefigure

Upgrade Pyodide runtime packages

  1. Bump pyodide in packages/prefigure/package.json.
  2. Run npm install at repo root.
  3. Run npm run setup -w @doenet/prefigure (reads the new pyodide-lock.json).
  4. Run build + the browser runtime check.

Upgrade liblouis assets

  1. Update LIBLOUIS_REF and hashes in scripts/fetch-liblouis.ts.
  2. Run npm run setup -w @doenet/prefigure.
  3. Run build + the browser runtime check.