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

diths

v0.1.0

Published

Pure TypeScript dithering library for browsers (vanilla & React), Bun, and Node — built with tsdown.

Readme

diths

Pure TypeScript dithering library with deterministic, pixel-exact output across browsers (vanilla & React), Bun, and Node. Zero runtime dependencies, lazy-loaded codecs, built with tsdown.

Install

npm install diths
# or
bun add diths

Quick Start

Vanilla Browser

import { dither, generate } from "diths";

// Dither an <img>, <canvas>, File/Blob, ImageData, or URL
const out = await dither(document.querySelector("img")!, "risograph");

// Draw directly onto a canvas (no PNG round trip)
out.drawTo(document.querySelector("canvas")!, { scale: 2 });

// Or export to PNG, GIF, SVG, WebP, JPEG, BMP, TIFF, Blob, or data URL
const blob = await out.toBlob("png");
const svg = await out.toSVG({ svgShape: "circle" });

// Generate procedural dither art with no input image
const orb = await generate("sphere", { preset: "mac-classic", canvasWidth: 640, canvasHeight: 640 });

React (diths/react)

react is an optional peer dependency (>=18) — vanilla browser, Bun, and Node users never pull React.

import { DitherCanvas, DitherImage, useDither, useGenerate } from "diths/react";

// Direct canvas rendering (fast interactive updates)
export function PhotoPreview({ file }: { file: File }) {
  return <DitherCanvas src={file} options={{ preset: "risograph", maxDim: 640 }} scale={2} />;
}

// Encoded <img> rendering with fallback
export function ProceduralBadge() {
  return (
    <DitherImage
      pattern="sphere"
      options={{ preset: "gameboy", canvasWidth: 240, canvasHeight: 240 }}
      format="png"
      alt="Game Boy sphere"
      fallback={<span>Rendering…</span>}
    />
  );
}

// Hooks for custom UIs (with automatic race-condition cancellation & stable options)
export function Inspector({ src }: { src: string }) {
  const { result, loading, error } = useDither(src, { algorithm: "atkinson", palette: "bw" });
  if (loading) return <p>Dithering…</p>;
  if (error) return <p>{error.message}</p>;
  return <p>Colors: {result?.palette.join(", ")}</p>;
}

Bun & Node

import { animate, compare, diff, dither, inspect } from "diths";
import { writeFile } from "node:fs/promises";

// Dither a local file and save as PNG
const out = await dither("photo.jpg", { preset: "risograph", maxDim: 960 });
await writeFile("out.png", await out.toPNG());

// Render a seamless looping procedural GIF, APNG, or Animated WebP (smallest)
const loop = await animate("sphere", { preset: "mac-classic", canvasWidth: 320, canvasHeight: 320, frames: 24, fps: 16 });
await writeFile("loop.webp", await loop.toWebP());
await writeFile("loop.apng", await loop.toAPNG());
await writeFile("loop.gif", await loop.toGIF());

// Build a labeled contact sheet comparing presets
const sheet = await compare("photo.jpg", { presets: ["mac-classic", "risograph", "gameboy", "manga"] });
await writeFile("sheet.png", await sheet.toPNG());

// Diff two images and generate a highlight heatmap
const delta = await diff(before, after);
await writeFile("diff.png", await delta.highlight().toPNG());

// Analyze an image and get preset recommendations
const info = await inspect("photo.jpg");

Web Worker (diths/worker)

Keep large images off the main thread in browsers:

// dither.worker.ts
import { serveWorker } from "diths/worker";
serveWorker();
import { connectWorker } from "diths/worker";

const worker = connectWorker(new Worker(new URL("./dither.worker.ts", import.meta.url), { type: "module" }));
const out = await worker.dither(document.querySelector("img")!, "manga");
// Works with React too: <DitherCanvas src={file} options="manga" worker={worker} />

Entry Points

| Import | Purpose | | --- | --- | | diths | Core library (dither, generate, animate, compare, diff, inspect, recipe, catalogs, codecs, worker helpers) | | diths/react | React hooks (useDither, useGenerate) and components (<DitherCanvas />, <DitherImage />) | | diths/worker | Web Worker bridge (connectWorker, serveWorker) |

What's Inside

  • 24 Dithering Algorithms: Floyd-Steinberg, Atkinson, Jarvis-Judice-Ninke, Stucki, Burkes, Sierra, Sierra Two-Row, Sierra Lite, Ostromoukhov, Bayer 2×2 / 4×4 / 8×8 / 16×16, Halftone, Clustered Dot, Diagonal / Horizontal / Vertical Lines, Crosshatch, Blue Noise, Interleaved Gradient Noise (IGN), Riemersma, Random, Threshold.
  • 29 Built-in Palettes + custom hex arrays + Oklab adaptive palette extraction (autoPalette).
  • 16 Curated Presets: mac-classic, risograph, gameboy, manga, woodcut, editorial-print, crt-amber, blueprint, halftone-zine, lo-fi-photo, and more.
  • 10 Procedural Generators: linear-gradient, radial-gradient, mesh, sphere, waves, noise, rings, plasma, checkerboard, inflate.
  • Pure-TS Codecs (Lazy-Loaded): PNG (with optional Zopfli + grayscale optimization), APNG (encode & decode), GIF (still & animated), WebP (lossless still & animated VP8L encode & decode), JPEG, BMP, TIFF, and compact vector SVG.

License

MIT