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

@thorvg/webcanvas

v1.0.1

Published

A TypeScript WebCanvas API for ThorVG - High-performance vector graphics rendering

Readme

ThorVG for Web

npm

@thorvg/webcanvas

A high-performance TypeScript Canvas API for ThorVG, providing an object-oriented interface with fluent API pattern for vector graphics rendering using WebAssembly.

Installation

  • Import from CDN
<script src="https://unpkg.com/@thorvg/webcanvas@latest/dist/webcanvas.js"></script>
  • Install from NPM
npm install @thorvg/webcanvas

Contents

Quick Start

ThorVG renders vector shapes to a given canvas buffer. The following is a quick start to show you how to use the essential APIs.

First, you should initialize the ThorVG engine:

import ThorVG from '@thorvg/webcanvas';

const TVG = await ThorVG.init({ renderer: 'gl' });  // WebGL renderer

Then it would be best if you prepared an empty canvas for drawing on it:

const canvas = new TVG.Canvas('#canvas', {
  width: 800,
  height: 600
});

Next you can draw multiple shapes on the canvas:

const rect = new TVG.Shape();                              // generate a shape
rect.appendRect(50, 50, 200, 200, { rx: 20, ry: 20 });    // define it as a rounded rectangle (x, y, w, h, rx, ry)
rect.fill(100, 100, 100);                                  // set its color (r, g, b)
canvas.add(rect);                                          // add the rectangle to the canvas

const circle = new TVG.Shape();                            // generate a shape
circle.appendCircle(400, 400, 100, 100);                   // define it as a circle (cx, cy, rx, ry)

const fill = new TVG.RadialGradient(400, 400, 150);       // generate a radial gradient (cx, cy, radius)

fill.setStops(                                             // set the gradient colors info
  [0.0, [255, 255, 255, 255]],                             // 1st color values (offset, [r, g, b, a])
  [1.0, [0, 0, 0, 255]]                                    // 2nd color values (offset, [r, g, b, a])
);

circle.fill(fill);                                         // set the circle fill
canvas.add(circle);                                        // add the circle to the canvas

This code generates the following result:

You can also draw your own shapes and use dashed stroking:

const path = new TVG.Shape();                              // generate a path
path.moveTo(199, 34);                                      // set sequential path coordinates
path.lineTo(253, 143);
path.lineTo(374, 160);
path.lineTo(287, 244);
path.lineTo(307, 365);
path.lineTo(199, 309);
path.lineTo(97, 365);
path.lineTo(112, 245);
path.lineTo(26, 161);
path.lineTo(146, 143);
path.close();

path.fill(150, 150, 255);                                  // path color

path.stroke({
  width: 3,                                                // stroke width
  color: [0, 0, 255, 255],                                 // stroke color (r, g, b, a)
  cap: TVG.StrokeCap.Round,                                // stroke cap style
  join: TVG.StrokeJoin.Round,                              // stroke join style
  dash: [10, 10]                                           // stroke dash pattern (line, gap)
});

canvas.add(path);                                          // add the path to the canvas

The code generates the following result:

Now begin rendering & finish it at a particular time:

canvas.render();

Then you can acquire the rendered image from the canvas element.

Lastly, terminate the engine after its usage:

TVG.term();

Back to contents

Render Backends

ThorVG WebCanvas supports both WebGL and the next-generation WebGPU, optimized for modern browsers and high-performance rendering pipelines. Designed to empower developers with cutting-edge graphics capabilities.

| Backend | Browser Support | |---------|-----------------| | WebGL (gl) | Chrome/Firefox/Safari 90+ | | WebGPU (wg) | Chrome/Edge 113+/Firefox 141+/Safari 26+ |

Backend-Specific Initialization

// WebGL renderer
const TVG = await ThorVG.init({ renderer: 'gl' });

// WebGPU renderer (requires async init)
const TVG = await ThorVG.init({ renderer: 'wg' });

Back to contents

Memory Management

WebCanvas provides automatic memory management through FinalizationRegistry, but you can also manage memory explicitly:

// Automatic cleanup when GC runs
const shape = new TVG.Shape();
canvas.add(shape);
shape = null; // Call dispose()

// Automatic cleanup on page unload (registry.ts)
window.addEventListener('beforeunload', () => {
  if (hasModule()) {
    const Module = getModule();
    Module.term(); // Terminate WASM
  }
});

// Explicit cleanup (recommended for predictable memory management)
shape.dispose();
picture.dispose();
animation.dispose();

// Terminate WASM module (call this when done)
TVG.term();

Back to contents

Documentation

Back to contents

Examples

Back to contents