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

@frapx/tool-capture

v0.3.0

Published

Browser frame export for @frapx/fx-canvas, @frapx/fx-passes and @frapx/fx-particles — deterministic PNG sequences (8-bit or 16-bit) written to a folder or a ZIP, with no dependencies.

Readme

@frapx/tool-capture

Browser frame export for @frapx/fx-canvas, @frapx/fx-passes and @frapx/fx-particles: render a deterministic PNG sequence (8-bit, or 16-bit from a float buffer) and write it to a folder or a single ZIP. No dependencies.

It drives an instance through setTime() and captureFrame(), so frame n always shows the scene at n / fps seconds no matter how slow the GPU is. To render from the command line instead of a browser tab, see @frapx/tool-render. In-browser video encoding (WebCodecs + a muxer) is planned for a later version.

Install

pnpm add @frapx/fx-canvas @frapx/tool-capture

Usage

import { createShaderBackground } from "@frapx/fx-canvas";
import { captureSequence, createZipSink, downloadBlob } from "@frapx/tool-capture";

const fx = createShaderBackground({
  target: ".stage",
  fragment,
  clock: "manual",
  resolution: [3840, 2160]
});

button.addEventListener("click", async () => {
  const zip = await captureSequence(fx, {
    sink: createZipSink(),
    fps: 30,
    frameCount: 90,
    onProgress: ({ completed, total }) => console.info(`${completed}/${total}`)
  });
  downloadBlob(zip, "frames.zip");
});

captureSequence() switches the instance to its manual clock for the export and restores the previous clock afterwards, so a live realtime background can be exported too; it then resumes from the time of the last exported frame. Pointer input, visibility and reduced motion never affect the frames.

Writing to a folder

In Chromium-based browsers, write frames straight to a folder instead of holding them in memory. Call pickDirectorySink() from a click handler:

import { canPickDirectory, captureSequence, pickDirectorySink } from "@frapx/tool-capture";

if (canPickDirectory()) {
  const sink = await pickDirectorySink(); // rejects with AbortError if dismissed
  await captureSequence(fx, { sink, fps: 30, frameCount: 900 });
}

Use createDirectorySink(handle) when you already have a FileSystemDirectoryHandle.

16-bit PNG

format: "png16" reads the float feedback buffer instead of the 8-bit canvas, so smooth gradients keep more than 256 steps. The instance needs a float buffer, and should fail rather than fall back to 8 bits:

const fx = createShaderBackground({
  target: ".stage",
  fragment,
  clock: "manual",
  resolution: [3840, 2160],
  feedback: { format: "rgba16f", formatFallback: false }
});

await captureSequence(fx, { sink, fps: 30, frameCount: 90, format: "png16" });

The buffer is half float, so the precision near 1.0 is about 11 bits; near black it is finer. Values are clamped to 0–1 and stored as the shader wrote them, with no color conversion. Encoding is CPU work: a 4K frame took about 0.7 s and 4 MB, against 0.08 s and 1.8 MB for 8-bit (Apple Silicon, Chrome).

Rendering from the command line

registerRenderTarget() lets @frapx/tool-render render the page headlessly with frapx-render, resuming interrupted renders and encoding with ffmpeg. It only sets a global, so it can stay in production builds:

import { registerRenderTarget } from "@frapx/tool-capture";

registerRenderTarget(fx, {
  fps: 30,
  duration: 24,
  resolution: [3840, 2160],
  prepare({ params }) {
    fx.setUniform("quality", Number(params.quality ?? 1));
  }
});
frapx-render dist --out frames --set quality=2

resolution is the default render size; frapx-render --resolution overrides it. Without either, the page renders at its own size, which in the headless browser is the 1280 × 720 viewport, so a page meant for video should declare one. prepare({ params, fps, format, resolution }) runs before each render job, with the size the job renders at. Pass a getter (() => fx) when the page replaces its instance. Registering again replaces the previous registration; the returned function removes it.

API

captureSequence(target, options): Promise<TResult>

Renders frames startFrame to startFrame + frameCount - 1 and writes each one to options.sink, then resolves with the sink's close() result (the ZIP Blob for createZipSink()).

| Option | Default | | | --- | --- | --- | | sink | required | Where frames go. See Sinks. | | fps | required | Frame n is drawn at n / fps seconds. | | frameCount | required | Number of frames to write. | | startFrame | 0 | First frame number. Frame numbers name the files and set the time, so for shaders that depend only on time, a range split across several runs matches a single run. Feedback history does not carry over between runs. | | format | "png" | "png" (8-bit canvas) or "png16" (16-bit from the float buffer). | | fileName | frame_00000.png | (frame) => string. Must be a plain file name for folder sinks. | | resetFeedback | true | Clears feedback history before the first frame, so repeated exports start from the same state. | | signal | | An AbortSignal. Aborting rejects with signal.reason. | | onBeforeFrame | | ({ frame, time }) => void \| Promise<void>. Runs after the time is set and before the frame is drawn, e.g. to set uniforms. | | onProgress | | ({ frame, time, completed, total }) => void. |

u_delta is 1 / fps on every frame, including the first. When an export fails or is aborted, the sink's abort() runs and the promise rejects; frames already written to a folder stay there.

The target only needs ready, canvas, clock, setClock(), setTime(), captureFrame() and optionally resetFeedback() (the CaptureTarget type). @frapx/fx-canvas, @frapx/fx-passes and @frapx/fx-particles instances fit as is; this package depends on none of them. The export's signal is passed to captureFrame(), so an fx-passes frame accumulating many samples, or an fx-particles frame catching up on its simulation, stops part-way.

Sinks

| Export | Result | | | --- | --- | --- | | createZipSink({ date? }) | Blob | One uncompressed ZIP held in memory. PNGs are already compressed, so storing them costs nothing. Writes ZIP64 records past 4 GiB or 65,535 frames, but long 4K exports can exceed available memory; prefer a folder there. | | pickDirectorySink() | void | Opens the folder picker (File System Access API, Chromium only). Rejects with AbortError when dismissed and NotSupportedError where unavailable. | | createDirectorySink(handle) | void | Writes into a FileSystemDirectoryHandle, replacing files with the same name. |

canPickDirectory() reports whether the picker exists. Write your own sink by implementing FrameSink<TResult>: write(name, blob), close() and an optional abort(reason).

Utilities

  • encodePng16(pixels, width, height): Promise<Blob> encodes RGBA floats (top row first, as captureFrame({ format: "rgba16f" }) returns them) as a 16-bit PNG, using the platform CompressionStream.
  • downloadBlob(blob, fileName) saves a Blob through the browser's download flow.

Example

examples/vite-capture exports a raymarched scene as 8-bit or 16-bit PNGs to a folder or a ZIP:

pnpm --filter @frapx/example-vite-capture dev