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

grain-gradient

v2.0.0

Published

Lightweight WebGL shader utilities for mesh and grain gradients.

Readme

grain-gradient

Lightweight TypeScript helpers for WebGL shader mesh + grain gradients.

v2 is WebGL-only. The library now renders through a single WebGL fragment shader. CSS/SVG gradient generation APIs from v1 (createGrainGradientCSS, createMeshGradient, createTurbulenceNoise, createAndroidCanvasFallbackStyle, and related Android/canvas fallback helpers) have been removed.

grain-gradient playground preview

Open the playground

Installation

npm i grain-gradient

WebGL shader renderer

grain-gradient renders both the mesh gradient and the grain texture in one WebGL fragment shader. The React component keeps only a minimal baseColor background behind the canvas, so SSR and unsupported WebGL environments do not render a blank transparent box.

import { GrainGradient, presets } from "grain-gradient/react";

export function Hero() {
  return (
    <GrainGradient
      {...presets["Aurora Citrus"]}
      motionPreset="drift"
      motionSpeed={38}
      motionIntensity={46}
      swirl={30}
      opacity={0.22}
      style={{ minHeight: "100vh" }}
    />
  );
}

The component creates a <canvas> context on the client. If WebGL is unavailable or the WebGL context is lost, the component keeps only the baseColor background; it does not provide a CSS/SVG or 2D canvas fallback.

In SSR frameworks such as Next.js, render it from a client boundary ("use client") or with a dynamic import using ssr: false.

import dynamic from "next/dynamic";

const GrainGradient = dynamic(
  () => import("grain-gradient/react").then((mod) => mod.GrainGradient),
  { ssr: false },
);

Framework-agnostic renderer

import { createWebGLMeshRenderer } from "grain-gradient";

const canvas = document.querySelector("canvas")!;
const renderer = createWebGLMeshRenderer(canvas, {
  colors: ["#c2e812", "#ff7f11", "#ee4266", "#2a1e5c"],
  motionPreset: "drift",
  motionSpeed: 38,
  motionIntensity: 46,
  opacity: 0.22,
});

renderer?.start();

Call renderer.update(options) when controls change, renderer.resize() when the canvas layout changes, and renderer.destroy() during cleanup.

Performance defaults

Animated fullscreen rendering is tuned conservatively by default:

  • fps: 30
  • maxPixelRatio: 1.25
  • motionMaxPixelRatio: 0.75
  • pauseWhenHidden: true

Raise these only when you need sharper or smoother animated rendering.

Development

  • npm run build: compile the TypeScript source to dist/
  • npm run build:playground: build the Vite React playground to dist-playground/
  • npm run test: run the Node test suite after building
  • npm run lint: check the codebase with oxlint
  • npm run format:check: verify formatting with oxfmt
  • npm run playground: open the Vite playground at /

Local playground

Run the Vite-powered playground with hot reload:

npm run dev

Then open http://localhost:5173/.