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

v1.2.0

Published

Lightweight TypeScript utilities for mesh and grain gradients.

Readme

grain-gradient

Lightweight TypeScript helpers for mesh + grain gradients.

grain-gradient playground preview

Open the playground

Installation

npm i grain-gradient

Core CSS

import { createGrainGradientCSS, presets } from "grain-gradient";

const css = createGrainGradientCSS({
  ...presets["Aurora Citrus"],
  motionPreset: "drift",
  motionSpeed: 38,
  motionIntensity: 46,
  swirl: 30,
});

grain-gradient has no runtime dependencies. The core entry does not import React.

The core API, playground, and React helper can switch to a Canvas-generated PNG grain fallback for Android Chrome device testing. The fallback helpers are SSR-safe: SVG grain is rendered first, then Canvas grain can be applied after hydration when Android Chrome is detected.

import { createAndroidCanvasFallbackStyle } from "grain-gradient";

const fallback = createAndroidCanvasFallbackStyle({ androidCanvasFallback: "auto" });
if (fallback) Object.assign(grainLayer.style, fallback);

auto is resolved where the helper runs. If you are exporting static CSS on a non-Android browser and want the Canvas fallback included, use androidCanvasFallback: "on" for that export.

For CSS generated with createGrainGradientCSS(), apply those values to the generated ::after grain layer as a CSS override.

See API reference for all core functions, React helpers, options, and presets.

React

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

export function Hero() {
  return (
    <GrainGradient
      colors={["#c2e812", "#ff7f11", "#ee4266", "#2a1e5c"]}
      motionPreset="drift"
      motionSpeed={38}
      motionIntensity={46}
      swirl={30}
      androidCanvasFallback="auto"
      style={{ minHeight: "100vh" }}
    />
  );
}

For SSR frameworks, pass the request user agent as a hint so auto can use the same Android Chrome detection after hydration:

import { headers } from "next/headers";
import { GrainGradient } from "grain-gradient/react";

export default async function Page() {
  const userAgent = (await headers()).get("user-agent");

  return <GrainGradient androidCanvasFallback="auto" androidCanvasFallbackUserAgent={userAgent} />;
}

React is a peer dependency via the grain-gradient/react subpath.

WebGL experimental

For continuously animated mesh backgrounds, use the optional WebGL renderer. The default CSS/SVG renderer remains the SSR-safe fallback.

The WebGL React component is client-only because it creates a <canvas> context. In SSR frameworks such as Next.js, render it from a client boundary ("use client") or a dynamic import with ssr: false, and keep CSS/SVG available as the fallback for server output, static exports, unsupported browsers, and lost WebGL contexts.

import { WebGLGrainGradient } from "grain-gradient/webgl/react";

export function AnimatedHero() {
  return (
    <WebGLGrainGradient
      colors={["#c2e812", "#ff7f11", "#ee4266", "#2a1e5c"]}
      motionPreset="drift"
      motionSpeed={38}
      motionIntensity={46}
      // Caps static canvas pixel density for high-DPI performance.
      maxPixelRatio={1.25}
      // Motion defaults are already lightweight: fps=30, motionMaxPixelRatio=0.75.
      style={{ minHeight: "100vh" }}
    />
  );
}
import dynamic from "next/dynamic";

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

Use CSS/SVG for static backgrounds and exports; use WebGL as the default choice when smooth continuous mesh animation matters. WebGL renders once and stops when motion is disabled. When motion is enabled, the defaults are tuned for full-screen performance: fps: 30 and motionMaxPixelRatio: 0.75. Raise them only when you need smoother motion or sharper animated rendering. maxPixelRatio can stay a little higher for static sharpness.

// Explicit lightweight animated fullscreen preset, matching the defaults
<WebGLGrainGradient motionPreset="drift" motionSpeed={35} fps={30} motionMaxPixelRatio={0.75} />

Development

  • npm run build: compile the TypeScript source to dist/
  • 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 /playground/

Local playground

Run the Vite-powered playground with hot reload:

npm run dev

Then open http://localhost:5173/playground/ to tune presets, colors, and grain settings live.

Use npm run playground to start Vite and open the playground automatically.