{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "mesh-gradient",
  "title": "MeshGradient",
  "description": "The Neon brand-deck gradient as a live WebGL surface: a defocused warm color field drifting over near-black.",
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "src/components/mesh-gradient/mesh-gradient.tsx",
      "content": "\"use client\";\n\n/*\n * MeshGradient: the Neon brand-deck gradient as a live WebGL surface —\n * a defocused warm color field (moss, ember, gold, and a yellow-green\n * bloom) drifting over near-black. A brand background for heroes,\n * covers, and marketing moments. Static single frame under reduced\n * motion. GLSL lives in mesh-gradient-shader.ts.\n */\n\nimport { useEffect, useRef } from \"react\";\nimport type { ComponentProps } from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\nimport { MESH_FRAGMENT, MESH_VERTEX } from \"./mesh-gradient-shader\";\n\nexport type MeshGradientPalette = [\n  base: string,\n  moss: string,\n  ember: string,\n  gold: string,\n  bloom: string,\n];\n\nexport type MeshGradientProps = Omit<ComponentProps<\"canvas\">, \"children\"> & {\n  /** Animation speed multiplier; 0 freezes the field. */\n  speed?: number;\n  /** 0-1 domain warp — how organic the blob edges get. */\n  warp?: number;\n  /** 0-1 dither strength; keeps soft falloffs from banding. */\n  grain?: number;\n  /** Brightness multiplier on the bloom blob. */\n  glow?: number;\n  /** The field, painted back to front: [base, moss, ember, gold, bloom]. */\n  colors?: MeshGradientPalette;\n};\n\n/**\n * Seconds for a dial or palette change to close ~63% of its gap —\n * uniforms ease toward their targets each frame, so a dragged slider\n * or a palette switch glides instead of snapping.\n */\nconst SMOOTH_TAU = 0.12;\n\nconst DEFAULT_COLORS: MeshGradientPalette = [\n  \"#0b0b08\",\n  \"#2c4a33\",\n  \"#a85f1b\",\n  \"#edbf4e\",\n  \"#eef2a0\",\n];\n\nconst parseColor = (css: string): [number, number, number] => {\n  const probe = document.createElement(\"canvas\");\n  probe.width = 1;\n  probe.height = 1;\n  const context = probe.getContext(\"2d\");\n\n  if (!context) {\n    return [0, 0, 0];\n  }\n\n  context.fillStyle = css;\n  context.fillRect(0, 0, 1, 1);\n  const [r, g, b] = context.getImageData(0, 0, 1, 1).data;\n  return [(r ?? 0) / 255, (g ?? 0) / 255, (b ?? 0) / 255];\n};\n\nconst warnDev = (message: string) => {\n  if (typeof process !== \"undefined\" && process.env.NODE_ENV !== \"production\") {\n    console.warn(message);\n  }\n};\n\nconst compile = (\n  gl: WebGLRenderingContext,\n  type: number,\n  source: string\n): WebGLShader | null => {\n  const shader = gl.createShader(type);\n\n  if (!shader) {\n    return null;\n  }\n\n  gl.shaderSource(shader, source);\n  gl.compileShader(shader);\n\n  if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n    warnDev(\n      `neon-ui: shader compile failed: ${gl.getShaderInfoLog(shader) ?? \"unknown\"}`\n    );\n    gl.deleteShader(shader);\n    return null;\n  }\n\n  return shader;\n};\n\nexport const MeshGradient = ({\n  className,\n  colors = DEFAULT_COLORS,\n  glow = 1,\n  grain = 0.5,\n  speed = 0.6,\n  warp = 0.4,\n  ...props\n}: MeshGradientProps) => {\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  // Shader time, accumulated frame by frame so a speed change scales\n  // the flow from here instead of teleporting the whole field.\n  const phaseRef = useRef(0);\n  const lastFrameRef = useRef<number | null>(null);\n  // Smoothed uniform values, persisting across prop-driven re-inits.\n  const smoothedRef = useRef<Record<string, number> | null>(null);\n  const [base, moss, ember, gold, bloom] = colors;\n\n  useEffect(() => {\n    const canvas = canvasRef.current;\n    const gl = canvas?.getContext(\"webgl\", { alpha: false });\n\n    if (!(canvas && gl)) {\n      return;\n    }\n\n    const vertex = compile(gl, gl.VERTEX_SHADER, MESH_VERTEX);\n    const fragment = compile(gl, gl.FRAGMENT_SHADER, MESH_FRAGMENT);\n    const program = gl.createProgram();\n\n    if (!(vertex && fragment && program)) {\n      if (vertex) {\n        gl.deleteShader(vertex);\n      }\n      if (fragment) {\n        gl.deleteShader(fragment);\n      }\n      return;\n    }\n\n    gl.attachShader(program, vertex);\n    gl.attachShader(program, fragment);\n    gl.linkProgram(program);\n\n    if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n      warnDev(\n        `neon-ui: program link failed: ${gl.getProgramInfoLog(program) ?? \"unknown\"}`\n      );\n      gl.deleteProgram(program);\n      gl.deleteShader(vertex);\n      gl.deleteShader(fragment);\n      return;\n    }\n\n    // oxlint-disable-next-line react/react-compiler -- WebGL method, not a React hook\n    gl.useProgram(program);\n\n    const quad = gl.createBuffer();\n    gl.bindBuffer(gl.ARRAY_BUFFER, quad);\n    gl.bufferData(\n      gl.ARRAY_BUFFER,\n      new Float32Array([-1, -1, 3, -1, -1, 3]),\n      gl.STATIC_DRAW\n    );\n    const position = gl.getAttribLocation(program, \"a_position\");\n    gl.enableVertexAttribArray(position);\n    gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);\n\n    const uResolution = gl.getUniformLocation(program, \"u_resolution\");\n    const uTime = gl.getUniformLocation(program, \"u_time\");\n    const uWarp = gl.getUniformLocation(program, \"u_warp\");\n    const uGrain = gl.getUniformLocation(program, \"u_grain\");\n    const uGlow = gl.getUniformLocation(program, \"u_glow\");\n\n    const palette = [\n      [\"u_base\", base],\n      [\"u_moss\", moss],\n      [\"u_ember\", ember],\n      [\"u_gold\", gold],\n      [\"u_bloom\", bloom],\n    ] as const;\n\n    const targets: Record<string, number> = { glow, grain, speed, warp };\n\n    for (const [name, css] of palette) {\n      const [r, g, b] = parseColor(css);\n      targets[`${name}_r`] = r;\n      targets[`${name}_g`] = g;\n      targets[`${name}_b`] = b;\n    }\n\n    smoothedRef.current ??= { ...targets };\n    const smoothed = smoothedRef.current;\n    const colorLocations = palette.map(([name]) =>\n      gl.getUniformLocation(program, name)\n    );\n\n    /** Ease every uniform toward its target and upload; k=1 snaps. */\n    const applyUniforms = (k: number) => {\n      for (const key of Object.keys(targets)) {\n        const current = smoothed[key] ?? targets[key] ?? 0;\n        smoothed[key] = current + ((targets[key] ?? 0) - current) * k;\n      }\n\n      gl.uniform1f(uWarp, smoothed.warp ?? warp);\n      gl.uniform1f(uGrain, smoothed.grain ?? grain);\n      gl.uniform1f(uGlow, smoothed.glow ?? glow);\n\n      for (const [index, [name]] of palette.entries()) {\n        gl.uniform3f(\n          colorLocations[index] ?? null,\n          smoothed[`${name}_r`] ?? 0,\n          smoothed[`${name}_g`] ?? 0,\n          smoothed[`${name}_b`] ?? 0\n        );\n      }\n    };\n\n    const dpr = Math.min(window.devicePixelRatio || 1, 2);\n    let frame = 0;\n    let staticFrame = false;\n\n    const renderStatic = () => {\n      applyUniforms(1);\n      gl.uniform1f(uTime, 11);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n    };\n\n    const resize = () => {\n      const width = Math.max(1, Math.round(canvas.clientWidth * dpr));\n      const height = Math.max(1, Math.round(canvas.clientHeight * dpr));\n\n      if (canvas.width !== width || canvas.height !== height) {\n        canvas.width = width;\n        canvas.height = height;\n        gl.viewport(0, 0, width, height);\n      }\n\n      gl.uniform2f(uResolution, canvas.width, canvas.height);\n    };\n\n    const observer = new ResizeObserver(() => {\n      resize();\n\n      if (staticFrame) {\n        renderStatic();\n      }\n    });\n    observer.observe(canvas);\n    resize();\n\n    const dispose = () => {\n      observer.disconnect();\n      gl.deleteBuffer(quad);\n      gl.deleteProgram(program);\n      gl.deleteShader(vertex);\n      gl.deleteShader(fragment);\n    };\n\n    const draw = (now: number) => {\n      const last = lastFrameRef.current ?? now;\n      lastFrameRef.current = now;\n      // Skip GL work while hidden (e.g. behind a docs Code overlay's\n      // visibility:hidden panel) — keep the loop alive, drop the cost.\n      if (!(canvas.checkVisibility?.() ?? true)) {\n        frame = requestAnimationFrame(draw);\n        return;\n      }\n\n      const dt = (now - last) / 1000;\n      applyUniforms(1 - Math.exp(-dt / SMOOTH_TAU));\n      phaseRef.current += dt * (smoothed.speed ?? speed);\n      gl.uniform1f(uTime, phaseRef.current);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n      frame = requestAnimationFrame(draw);\n    };\n\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n\n    if (reduced.matches || speed === 0) {\n      staticFrame = true;\n      resize();\n      renderStatic();\n      return dispose;\n    }\n\n    frame = requestAnimationFrame(draw);\n\n    return () => {\n      cancelAnimationFrame(frame);\n      dispose();\n    };\n  }, [base, bloom, ember, glow, gold, grain, moss, speed, warp]);\n\n  return (\n    <canvas\n      aria-hidden=\"true\"\n      className={cn(\"size-full\", className)}\n      data-slot=\"mesh-gradient\"\n      ref={canvasRef}\n      {...props}\n    />\n  );\n};\n",
      "type": "registry:component"
    },
    {
      "path": "src/components/mesh-gradient/mesh-gradient-shader.ts",
      "content": "/*\n * The visual shader for MeshGradient, kept separate from the React\n * mount.\n *\n * A recreation of the Neon brand-deck gradient: a defocused color\n * field on a near-black base, studied blob by blob from the slide —\n *\n * - a large bright yellow-green bloom left of center\n * - a golden lobe pinned to the top-right corner\n * - a burnt ember mass across the right middle\n * - deep moss green in the top-left corner\n * - the warm black base showing through between the blobs\n *\n * The source slide also carries a dark scrim along the bottom for its\n * copy; that is deliberately NOT part of the field — text protection\n * is the consumer's overlay, not the gradient's.\n *\n * Each region is a gaussian blob with its own slow orbit; a gentle\n * value-noise warp keeps the edges organic, and a fine dither kills\n * the banding that soft falloffs otherwise show on 8-bit displays.\n *\n * Fragment shader uniforms:\n * - u_resolution (vec2): canvas resolution in pixels\n * - u_time (float): animation time in seconds (pre-multiplied by speed)\n * - u_warp (float): 0-1 domain warp on the blob field\n * - u_grain (float): 0-1 dither strength\n * - u_glow (float): brightness multiplier on the bloom blob\n * - u_base / u_moss / u_ember / u_gold / u_bloom (vec3): the palette,\n *   painted in that order from back to front\n */\n\nexport const MESH_VERTEX = `\nattribute vec2 a_position;\nvoid main() {\n  gl_Position = vec4(a_position, 0.0, 1.0);\n}\n`;\n\nexport const MESH_FRAGMENT = `\nprecision mediump float;\nuniform vec2 u_resolution;\nuniform float u_time;\nuniform float u_warp;\nuniform float u_grain;\nuniform float u_glow;\nuniform vec3 u_base;\nuniform vec3 u_moss;\nuniform vec3 u_ember;\nuniform vec3 u_gold;\nuniform vec3 u_bloom;\n\nfloat hash(vec2 p) {\n  return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);\n}\n\nfloat vnoise(vec2 p) {\n  vec2 i = floor(p);\n  vec2 f = smoothstep(0.0, 1.0, fract(p));\n  float a = hash(i);\n  float b = hash(i + vec2(1.0, 0.0));\n  float c = hash(i + vec2(0.0, 1.0));\n  float d = hash(i + vec2(1.0, 1.0));\n  return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);\n}\n\n/* Gaussian falloff: 1 at the center, soft shoulder, long tail. The\n   stretch squashes distance per axis, elongating the blob. */\nfloat blob(vec2 p, vec2 center, float radius, vec2 stretch) {\n  vec2 d = (p - center) / stretch;\n  return exp(-dot(d, d) / (radius * radius));\n}\n\n/* A slow elliptical orbit unique to each blob — fast enough that the\n   field visibly breathes at speed 1 and clearly flows at speed 3. */\nvec2 orbit(float t, float phase, float amount) {\n  return vec2(cos(t * 0.34 + phase), sin(t * 0.23 + phase * 1.7)) * amount;\n}\n\nvoid main() {\n  float aspect = u_resolution.x / u_resolution.y;\n  vec2 uv = gl_FragCoord.xy / u_resolution;\n  vec2 p = vec2(uv.x * aspect, uv.y);\n  float t = u_time;\n\n  // Organic edges: push the sample point around with slow value noise.\n  vec2 warp = vec2(\n    vnoise(p * 1.4 + vec2(t * 0.1, 0.0)),\n    vnoise(p * 1.4 + vec2(7.3, t * 0.085))\n  );\n  p += (warp - 0.5) * u_warp * 0.55;\n\n  // Paint back to front, each blob mixing toward its own color; the\n  // moss corner goes last so the bloom's halo never washes it out.\n  vec3 color = u_base;\n\n  float gold = blob(\n    p, vec2(1.02 * aspect, 1.0) + orbit(t, 4.2, 0.07), 0.62, vec2(1.15, 1.0));\n  color = mix(color, u_gold, min(gold * 1.1, 1.0));\n\n  float bloom = blob(\n    p, vec2(0.36 * aspect, 0.64) + orbit(t, 5.6, 0.11), 0.55, vec2(1.3, 1.0));\n  color = mix(color, u_bloom * u_glow, min(bloom * 1.25, 1.0));\n\n  float ember = blob(\n    p, vec2(0.78 * aspect, 0.46) + orbit(t, 2.1, 0.09), 0.55, vec2(1.2, 1.0));\n  color = mix(color, u_ember, min(ember * 0.9, 1.0));\n\n  float moss = blob(\n    p, vec2(0.0, 1.06) + orbit(t, 0.0, 0.05), 0.42, vec2(1.0, 1.25));\n  color = mix(color, u_moss, min(moss * 0.95, 1.0));\n\n  // Fine dither so the soft falloffs don't band on 8-bit displays.\n  color += (hash(gl_FragCoord.xy) - 0.5) * (u_grain * 0.035);\n\n  gl_FragColor = vec4(color, 1.0);\n}\n`;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}