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

webgraphiclibrary

v2.0.0-beta.1

Published

Small, type-safe WebGL utilities for low-level rendering workflows.

Readme

webgraphiclibrary

Small, type-safe WebGL utilities for people who still like working close to the graphics API.

webgraphiclibrary is not a scene graph, renderer, game engine, or replacement for Three.js. It is a set of focused wrappers around WebGL resources that are easy to reason about, easy to clean up, and small enough to drop into rendering experiments, post-processing pipelines, teaching projects, and custom engines.

The first v2 module is the framebuffer wrapper. It turns the noisy WebGL framebuffer setup flow into a small lifecycle API while keeping the underlying WebGL objects available when you need direct control.

Framebuffer workflow

Project snapshots

The screenshots below are generated with Playwright from this repository's current API examples and verification commands.

Scoped framebuffer code snippet

Release verification terminal

Framebuffer workflow card

Install

npm install webgraphiclibrary@beta
pnpm add webgraphiclibrary@beta

Imports

import { Framebuffer } from "webgraphiclibrary/fbo";
import { WebGLError } from "webgraphiclibrary/core";

The package uses subpath exports so each module stays explicit. The current beta exports:

  • webgraphiclibrary/fbo
  • webgraphiclibrary/core

Framebuffer quick start

import { Framebuffer } from "webgraphiclibrary/fbo";

const canvas = document.querySelector("canvas");
if (!(canvas instanceof HTMLCanvasElement)) {
  throw new Error("Canvas element was not found.");
}

const gl = canvas.getContext("webgl");
if (gl === null) {
  throw new Error("WebGL is not available.");
}

const fbo = new Framebuffer(gl, {
  width: 512,
  height: 512,
  depth: true
});

fbo.withBound(() => {
  gl.viewport(0, 0, fbo.width, fbo.height);
  gl.clearColor(0, 0, 0, 1);
  gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

  // Draw the off-screen scene here.
});

gl.viewport(0, 0, canvas.width, canvas.height);
gl.bindTexture(gl.TEXTURE_2D, fbo.texture);

// Draw a fullscreen quad here and sample fbo.texture in the fragment shader.

fbo.dispose();

Framebuffer API

new Framebuffer(gl, options)

Creates a color framebuffer target backed by a WebGLTexture.

const fbo = new Framebuffer(gl, {
  width: 1024,
  height: 1024,
  depth: true
});

Options:

| Option | Type | Default | Notes | | ---------------- | --------- | ------------------ | -------------------------------------------- | | width | number | required | Positive integer width in pixels | | height | number | required | Positive integer height in pixels | | internalFormat | number | gl.RGBA | Texture internal format | | format | number | gl.RGBA | Texture data format | | type | number | gl.UNSIGNED_BYTE | Texture data type | | minFilter | number | gl.LINEAR | Texture minification filter | | magFilter | number | gl.LINEAR | Texture magnification filter | | wrapS | number | gl.CLAMP_TO_EDGE | Horizontal texture wrapping | | wrapT | number | gl.CLAMP_TO_EDGE | Vertical texture wrapping | | depth | boolean | false | Adds a DEPTH_COMPONENT16 renderbuffer | | stencil | boolean | false | Adds a combined DEPTH_STENCIL renderbuffer |

Properties

| Property | Type | Notes | | -------------- | ------------------------------------------------- | --------------------------------- | | gl | WebGLRenderingContext \| WebGL2RenderingContext | Context passed to the constructor | | width | number | Current framebuffer width | | height | number | Current framebuffer height | | framebuffer | WebGLFramebuffer | Underlying framebuffer object | | texture | WebGLTexture | Color attachment texture | | renderbuffer | WebGLRenderbuffer \| null | Depth or depth-stencil storage | | disposed | boolean | true after disposal |

Methods

bind()

Binds the framebuffer so future draw calls write into texture.

unbind()

Binds the default screen framebuffer.

withBound(render)

Binds the framebuffer, runs the callback, and unbinds in a finally block. This keeps render passes compact and still makes the WebGL state change explicit.

fbo.withBound(() => {
  renderScene();
});

resize({ width, height })

Reallocates texture and renderbuffer storage while keeping the same framebuffer object.

fbo.resize({ width: canvas.width, height: canvas.height });

resizeToCanvas(canvas)

Convenience wrapper for matching a framebuffer to a canvas backing-store size.

fbo.resizeToCanvas(canvas);

readPixels()

Reads the color attachment into a Uint8Array of length width * height * 4.

const pixels = fbo.readPixels();
const firstPixel = pixels.slice(0, 4);

dispose()

Deletes the framebuffer, color texture, and optional renderbuffer. Disposal is idempotent, so repeated calls are safe.

Compatibility alias

The v2 API prefers the descriptive Framebuffer name, but the shorter FBO alias is exported too:

import { FBO } from "webgraphiclibrary/fbo";

const target = new FBO(gl, { width: 512, height: 512 });

Error behavior

The library throws early for invalid usage:

  • non-WebGL context values
  • non-integer or non-positive dimensions
  • failed WebGL resource allocation
  • incomplete framebuffer status
  • use after dispose()

Base WebGL-related failures extend WebGLError. Use-after-dispose failures throw DisposedResourceError.

Development

pnpm install
pnpm lint
pnpm typecheck
pnpm test
pnpm build
pnpm screenshots

pnpm prepublishOnly runs the full local release check: lint, typecheck, tests, and build.

pnpm screenshots regenerates the README screenshots with Playwright.

npm package

The current release target is the beta package:

npm publish --tag beta

The package ships compiled ESM output, TypeScript declarations, README assets, and examples.

Roadmap

The older WebGraphicLibrary packages are being rebuilt around the same small, typed-resource approach. The next modules are:

  • shader compilation
  • program linking and uniform helpers
  • typed vertex/index buffers
  • texture upload helpers
  • texture display debugging utilities

Sprite-style helpers are intentionally outside the first v2 scope. They fit better as examples built on top of the low-level modules.

Related repositories

This repository is the new home for the v2 work. The original package repositories are still useful for history and comparison:

| Repository | Notes | | -------------------------------------------------------------------------------------------------------- | -------------------------------- | | WebGraphicLibrary-fixedbaseoperator | Original framebuffer/FBO package | | WebGraphicLibrary-texture-display | Texture display helper | | WebGraphicLibrary-buffer | WebGL buffer wrapper | | WebGraphicLibrary-sprite | Sprite template package | | webgraphiclibrary-program | WebGL program wrapper | | WebGraphicLibrary-texture | WebGL texture wrapper | | WebGraphicLibrary-context | Canvas context helper | | WebGraphicLibrary-shader | WebGL shader wrapper |

License

MIT