JavaScript and React

Integrate the Gradients package with the DOM or React and understand its rendering backends.

Package access

@visualmodo/gradients is an ESM package maintained in Visualmodo’s private GitHub repository. The code examples apply to projects with package access. The generator, catalog API, and MCP are available without installing the SDK.

JavaScript

Use mountGradient with a browser canvas. Give the canvas a CSS width and height, use setParams() to update it, and call unmount() before removing it.

Mount a preset on a canvas
import { mountGradient } from "@visualmodo/gradients";
import { getPreset } from "@visualmodo/gradients/catalog";

const canvas = document.querySelector<HTMLCanvasElement>("#gradient");
const preset = getPreset("copper");
if (!canvas || !preset) throw new Error("Canvas or preset unavailable");

const surface = mountGradient(canvas, preset.config);
surface.setParams({ speed: 0.45 });

// Call surface.unmount() when the view is removed.

React

GradientSurface manages the canvas lifecycle. It fills its parent, so size that parent explicitly. Pass new params when your controls change.

Render a preset in React
import { GradientSurface } from "@visualmodo/gradients/react";
import { getPreset } from "@visualmodo/gradients/catalog";

export function HeroBackground() {
  const preset = getPreset("copper");
  if (!preset) return null;

  return (
    <div style={{ height: 360 }}>
      <GradientSurface params={preset.config} />
    </div>
  );
}

Package exports

Entry relative to @visualmodo/gradientsProvides
.Canvas renderer, material registry and core helpers
/reactReact gradient surface
/components, /components.css, /pixel-dissolveReact backgrounds, interactive components, styles and focused Pixel Dissolve entry
/catalog, /catalog.json, /collections, /materials, /component-catalogPresets, portable preset snapshot, and library metadata
/settingsVersioned settings schema, validation and serialization
/export/png, /export/video, /export/profilesBrowser PNG and video helpers, plus export profiles

Rendering and fallback

The browser renderer uses WebGL2 and can use WebGPU for supported materials and devices. Gradients can show a static CSS representation when GPU rendering is unavailable. The scheduler pauses offscreen work and the surface respects the user’s reduced-motion preference by default.

To embed a scroll-driven gradient in a panel, pass the panel as the scrollContainer. Test the preview and the output format on the browsers where you plan to use the gradient.