{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "gradient-mesh",
  "type": "registry:ui",
  "title": "Gradient Mesh",
  "description": "A soft, slowly shifting field of colour for a hero or a feature band. A few large blurred glows, each a theme colour, drift on long loops over a base surface, so the band feels alive without anything a reader has to watch. Content goes in `children` and…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "decorative",
    "effect"
  ],
  "dependencies": [],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json",
    "https://ds.interlace.tools/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/effects/gradient-mesh.tsx",
      "target": "components/ui/effects/gradient-mesh.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/gradient-mesh v1.0.0 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/gradient-mesh\n// What changed since: https://ds.interlace.tools/c/gradient-mesh#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — GradientMesh\n *\n * A soft, slowly shifting field of colour for a hero or a feature band. A\n * few large blurred glows, each a theme colour, drift on long loops over a\n * base surface, so the band feels alive without anything a reader has to\n * watch. Content goes in `children` and sits above the glows.\n *\n * ## Built on the theme\n *\n * `colors` takes any CSS colours and defaults to theme tokens (`--primary`,\n * `--chart-2`, `--highlight`, `--chart-4`), so the mesh follows the brand and\n * the colour scheme with no per-theme prop. Each glow is a radial gradient\n * fading to transparent: no blend modes, no SVG filters, nothing that\n * changes between browsers.\n *\n * ## Self-contained motion\n *\n * The drift uses the Web Animations API, so the component ships no keyframes\n * and needs nothing added to the consumer's stylesheet. Each glow moves on\n * `transform` only (composited), on a loop of 18 to 30 seconds, and the loop\n * pauses while the mesh is out of view. Under `prefers-reduced-motion:\n * reduce` the glows hold their resting place.\n *\n * | Rule | Concept                 | Where in this file                                   |\n * | ---- | ----------------------- | ---------------------------------------------------- |\n * | R4   | Extends native el       | `div` props                                          |\n * | R6   | data-slot per part      | gradient-mesh / -glows / -content                     |\n * | R7   | cn + ...rest            | `cn(…, className)` + `{...props}`                     |\n * | R19  | Tokens only             | default colours and base surface are tokens           |\n * | R23  | CLS=0                   | glows are `absolute`, content stays in flow           |\n * | R25  | Client component        | the drift needs `Element.animate`                     |\n */\n\nimport { cn } from '@/lib/utils';\nimport { useReducedMotion } from '@/hooks/use-reduced-motion';\n\nconst DEFAULT_COLORS = [\n  'var(--primary)',\n  'var(--chart-2)',\n  'var(--highlight)',\n  'var(--chart-4)',\n] as const;\n\n/** Resting place and drift path of each glow, as percentages of the mesh. */\nconst PATHS = [\n  { at: [15, 20], drift: [12, 8], seconds: 22 },\n  { at: [80, 25], drift: [-10, 12], seconds: 27 },\n  { at: [60, 80], drift: [8, -10], seconds: 19 },\n  { at: [25, 75], drift: [-8, -6], seconds: 30 },\n  { at: [50, 45], drift: [6, 10], seconds: 25 },\n  { at: [90, 70], drift: [-12, -8], seconds: 21 },\n] as const;\n\nexport interface GradientMeshProps extends React.ComponentPropsWithoutRef<'div'> {\n  /** Up to six CSS colours, one glow each. @default theme primary, chart-2, highlight, chart-4 */\n  colors?: readonly string[];\n  /** How strong the glows are, 0 to 1. @default 0.55 */\n  intensity?: number;\n  /** Glow diameter as a share of the mesh's width. @default 0.6 */\n  spread?: number;\n  /** Set false to hold the glows still even when motion is allowed. @default true */\n  animated?: boolean;\n}\n\nexport function GradientMesh({\n  colors = DEFAULT_COLORS,\n  intensity = 0.55,\n  spread = 0.6,\n  animated = true,\n  className,\n  children,\n  ...props\n}: GradientMeshProps) {\n  const glowsRef = React.useRef<HTMLDivElement>(null);\n  const reduced = useReducedMotion();\n  const moving = animated && !reduced;\n  const palette = colors.slice(0, PATHS.length);\n\n  React.useEffect(() => {\n    const root = glowsRef.current;\n    if (!root || !moving) return;\n    const glows = Array.from(root.children) as HTMLElement[];\n    if (!glows.every((g) => typeof g.animate === 'function')) return;\n    const animations = glows.map((glow, i) => {\n      const path = PATHS[i % PATHS.length]!;\n      const [dx, dy] = path.drift;\n      return glow.animate(\n        [\n          { transform: 'translate(-50%, -50%) translate(0, 0)' },\n          { transform: `translate(-50%, -50%) translate(${dx}%, ${dy}%)` },\n          { transform: `translate(-50%, -50%) translate(${-dy / 2}%, ${dx / 2}%)` },\n          { transform: 'translate(-50%, -50%) translate(0, 0)' },\n        ],\n        { duration: path.seconds * 1000, iterations: Infinity, easing: 'ease-in-out' },\n      );\n    });\n\n    const io =\n      typeof IntersectionObserver === 'undefined'\n        ? null\n        : new IntersectionObserver(([entry]) => {\n            for (const a of animations) {\n              if (entry?.isIntersecting) a.play();\n              else a.pause();\n            }\n          });\n    io?.observe(root);\n\n    return () => {\n      io?.disconnect();\n      for (const a of animations) a.cancel();\n    };\n  }, [moving, palette.length]);\n\n  return (\n    <div\n      data-slot=\"gradient-mesh\"\n      className={cn('bg-background relative isolate overflow-hidden', className)}\n      {...props}\n    >\n      <div\n        ref={glowsRef}\n        aria-hidden\n        data-slot=\"gradient-mesh-glows\"\n        className=\"pointer-events-none absolute inset-0 -z-10\"\n      >\n        {palette.map((color, i) => {\n          const path = PATHS[i]!;\n          return (\n            <span\n              key={i}\n              className=\"absolute aspect-square rounded-full\"\n              style={{\n                left: `${path.at[0]}%`,\n                top: `${path.at[1]}%`,\n                width: `${spread * 100}%`,\n                transform: 'translate(-50%, -50%)',\n                opacity: Math.min(Math.max(intensity, 0), 1),\n                background: `radial-gradient(closest-side, ${color}, transparent)`,\n              }}\n            />\n          );\n        })}\n      </div>\n      {children != null ? (\n        <div data-slot=\"gradient-mesh-content\" className=\"relative\">\n          {children}\n        </div>\n      ) : null}\n    </div>\n  );\n}\n"
    }
  ],
  "meta": {
    "tier": "effect",
    "client": true,
    "minViewport": null,
    "loading": false,
    "version": "1.0.0",
    "since": null
  },
  "docs": "## @interlace/gradient-mesh\n\nInstalled to `components/ui/effects/gradient-mesh.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/effects/gradient-mesh';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/gradient-mesh\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
