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

webgl2-sdf

v0.0.9

Published

Fast sdf generator from bezier curves or svg string.

Readme

Bug reports, pull requests and ⭐⭐⭐⭐⭐s are welcome and appreciated!

Overview

An ultra-fast library to generate the signed distance field (sdf) of an array of bezier curves (lines, quadratics, cubics), typically some closed shape(s).

  • dozens of times faster than webgl-sdf-generator for real-time (60+ fps) applications even on slow on-board GPUs

The bezier curves can be given in raw form or as an SVG path string (except, arcs are not supported yet).

Supported path commands: L, Q, C, H, V, S, T, Z l, q, c, h, v, s, t, z

Installation

npm install webgl2-sdf

How so fast?

Two basic concepts are used:

  • dynamically split the bezier curves into line segments up to a specified accuracy - reduces the number of line segments to check
  • divide and pre-filter the number of curve segments within the cells of a 32x32 grid; then each shader only uses the relevant line segments for sdf calculation

Usage

import { getWebGlContext, generateSdf, GLSL_PATTERN1 } from "webgl2-sdf";


function drawSdf() {
    const gl: WebGL2RenderingContext = canvas.getContext(
        'webgl2',
        {
            depth: false, stencil: false, antialias: false,
            premultipliedAlpha: false, preserveDrawingBuffer: true
        }
    );

    const { width: canvasWidth, height: canvasHeight } = canvas.getBoundingClientRect();

    // The first call to `getWebGlContext` caches some context, e.g. compiled shader
    // programs, etc., subsequent calls simply uses the existing cache.
    const glContext = getWebGlContext(gl!);

    // Optional...
    glContext.onContextLoss = onContextLoss;

    const someShape = 
    `
        M 0 0
        L 100 0
        L 100 100
        C 50 100 0 50 0 0
        z
    `;

    try {
        generateSdf(
            glContext!,
            someShape,
            [-50, -50, 150, 150],  // viewBox
            canvasWidth,   // width (of drawing area)
            canvasHeight,  // height (of drawing area)
            50,  // max sdf distance

            // The below options are optional (see function signature for details)
            {
                x: 0, y: 0,  // canvas x, y coordinates; [0,0] is bottom left!
                testInteriorExterior: true,
                calcSdfForInside: true,
                calcSdfForOutside: true,
                customData: [
                    2.0,    // exponent when using default `glslRgbaCalcStr`
                    0, 0, 0
                ],
                colorMask: [true, true, true, true],
                // glslRgbaCalcStr: GLSL_PATTERN1
            }
        );
    } catch (e) {
        console.log(e);
    }
}


function onContextLoss(event: Event) {
    // ... do somethin when context is lost, most likely by re-establishing a new context
    console.log(event);
}

// At the end, **only after you know you'll never call `generateIntoFramebuffer`
// again on the same `WebGL2RenderingContext`**
// freeGlContext(glContext);  // dispose of textures, buffers, shaders, programs, etc.

Recommendations

When calling generateIntoFramebuffer:

  • ensure the drawing width and height has the same aspect ratio as the viewbox else the image will be squashed / stretched
  • the viewbox is given as [x1,y1,x2,y2] and not as [x,y,width,height] as in SVG
  • note the premultipliedAlpha option when calling getContext and set it to your needs
  • if you want to combine a standard CanvasRenderingContext2D with a WebGL2RenderingContext it is best practice to have 2 canvases in your html that is stacked on top of each other

ESM only

This package is ESM only. It can be used in Node.js or in a browser.

License

The MIT License (MIT)

Copyright © 2026 Floris Steenkamp

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.