{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "animated-wash",
  "title": "AnimatedWash",
  "description": "WebGL grain-gradient shader wash rising from the bottom edge, colored by currentColor with a hover lift. Adapted from paper-design/shaders (Apache-2.0).",
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "src/components/animated-wash/animated-wash.tsx",
      "content": "\"use client\";\n\n/*\n * Adapted from paper-design/shaders (GrainGradient concept)\n * https://github.com/paper-design/shaders — Apache-2.0.\n *\n * Neon UI fork: a single-purpose WebGL wash — a color gradient rising from\n * the bottom edge, dithered with animated grain. Color comes from\n * currentColor at mount (same contract as NeonLoader), so the status hue\n * or theme drives it with zero props. Hovering the nearest interactive\n * ancestor lifts and warms the field. Static under reduced motion.\n * The GLSL lives in animated-wash-shader.ts.\n */\n\nimport { useEffect, useRef } from \"react\";\nimport type { ComponentProps } from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\nimport { WASH_FRAGMENT, WASH_VERTEX } from \"./animated-wash-shader\";\n\nexport type AnimatedWashProps = Omit<ComponentProps<\"canvas\">, \"children\"> & {\n  /** Grain refresh speed multiplier; 0 freezes the field. */\n  speed?: number;\n  /** 0-1 strength of the smooth gradient under the grain. */\n  intensity?: number;\n  /** 0-1 grain strength over the gradient. */\n  noise?: number;\n  /** Grain cell size in device pixels; bigger reads chunkier. */\n  grainSize?: number;\n};\n\n/** How fast the hover lift eases toward its target each frame. */\nconst LIFT_EASE = 0.08;\n\n/**\n * Seconds for a dial change to close ~63% of its gap — uniforms ease\n * toward their targets each frame, so a dragged slider glides\n * instead of snapping.\n */\nconst SMOOTH_TAU = 0.12;\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.9, 0.6];\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 AnimatedWash = ({\n  className,\n  grainSize = 3,\n  intensity = 0.2,\n  noise = 0.35,\n  speed = 1,\n  ...props\n}: AnimatedWashProps) => {\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 dial values, persisting across prop-driven re-inits.\n  const smoothedRef = useRef<Record<string, number> | null>(null);\n\n  useEffect(() => {\n    const canvas = canvasRef.current;\n\n    if (!canvas) {\n      return;\n    }\n\n    const gl = canvas.getContext(\"webgl\", {\n      alpha: true,\n      premultipliedAlpha: true,\n    });\n\n    if (!gl) {\n      return;\n    }\n\n    const vertex = compile(gl, gl.VERTEX_SHADER, WASH_VERTEX);\n    const fragment = compile(gl, gl.FRAGMENT_SHADER, WASH_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 uIntensity = gl.getUniformLocation(program, \"u_intensity\");\n    const uNoise = gl.getUniformLocation(program, \"u_noise\");\n    const uGrain = gl.getUniformLocation(program, \"u_grain\");\n    const uLift = gl.getUniformLocation(program, \"u_lift\");\n    const uColor = gl.getUniformLocation(program, \"u_color\");\n\n    const color = parseColor(getComputedStyle(canvas).color);\n    gl.uniform3f(uColor, color[0], color[1], color[2]);\n    const targets: Record<string, number> = {\n      grainSize,\n      intensity,\n      noise,\n      speed,\n    };\n\n    smoothedRef.current ??= { ...targets };\n    const smoothed = smoothedRef.current;\n\n    /** Ease every dial 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(uIntensity, smoothed.intensity ?? intensity);\n      gl.uniform1f(uNoise, smoothed.noise ?? noise);\n      gl.uniform1f(uGrain, smoothed.grainSize ?? grainSize);\n    };\n    gl.uniform1f(uLift, 0);\n\n    const dpr = Math.min(window.devicePixelRatio || 1, 2);\n    let frame = 0;\n    let lift = 0;\n    let liftTarget = 0;\n    let staticFrame = false;\n\n    const renderStatic = () => {\n      applyUniforms(1);\n      gl.uniform1f(uTime, 1);\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    // React to hover on the nearest interactive ancestor (the card link),\n    // falling back to the direct parent.\n    const hoverHost =\n      canvas.closest(\"a, button, [data-wash-hover]\") ?? canvas.parentElement;\n    const raiseLift = () => {\n      liftTarget = 1;\n    };\n    const dropLift = () => {\n      liftTarget = 0;\n    };\n    hoverHost?.addEventListener(\"pointerenter\", raiseLift);\n    hoverHost?.addEventListener(\"pointerleave\", dropLift);\n\n    const draw = (now: number) => {\n      const last = lastFrameRef.current ?? now;\n      lastFrameRef.current = now;\n      // Skip GL work while hidden — keep the loop alive, drop the cost.\n      if (!(canvas.checkVisibility?.() ?? true)) {\n        frame = requestAnimationFrame(draw);\n        return;\n      }\n\n      lift += (liftTarget - lift) * LIFT_EASE;\n      gl.uniform1f(uLift, lift);\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 cleanupHover = () => {\n      hoverHost?.removeEventListener(\"pointerenter\", raiseLift);\n      hoverHost?.removeEventListener(\"pointerleave\", dropLift);\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 () => {\n        cleanupHover();\n        dispose();\n      };\n    }\n\n    frame = requestAnimationFrame(draw);\n\n    return () => {\n      cancelAnimationFrame(frame);\n      cleanupHover();\n      dispose();\n    };\n  }, [grainSize, intensity, noise, speed]);\n\n  return (\n    <canvas\n      aria-hidden=\"true\"\n      className={cn(\"size-full\", className)}\n      data-slot=\"animated-wash\"\n      ref={canvasRef}\n      {...props}\n    />\n  );\n};\n",
      "type": "registry:component"
    },
    {
      "path": "src/components/animated-wash/animated-wash-shader.ts",
      "content": "/*\n * Adapted from paper-design/shaders (GrainGradient concept)\n * https://github.com/paper-design/shaders — Apache-2.0.\n *\n * The visual shader for AnimatedWash, kept separate from the React mount.\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_intensity (float): 0-1 strength of the smooth gradient under the grain\n * - u_noise (float): 0-1 grain strength over the gradient\n * - u_grain (float): grain cell size in device pixels\n * - u_lift (float): 0-1 hover lift; raises the field and brightens it\n * - u_color (vec3): wash color, sampled from currentColor at mount\n */\n\nexport const WASH_VERTEX = `\nattribute vec2 a_position;\nvoid main() {\n  gl_Position = vec4(a_position, 0.0, 1.0);\n}\n`;\n\nexport const WASH_FRAGMENT = `\nprecision mediump float;\nuniform vec2 u_resolution;\nuniform float u_time;\nuniform float u_intensity;\nuniform float u_noise;\nuniform float u_grain;\nuniform float u_lift;\nuniform vec3 u_color;\n\nfloat hash(vec2 p) {\n  return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);\n}\n\nvoid main() {\n  vec2 uv = gl_FragCoord.xy / u_resolution;\n  // Dense at the bottom, dissolving upward; hover lifts the field.\n  float grad = pow(clamp(1.0 - uv.y + u_lift * 0.18, 0.0, 1.0), 3.2);\n\n  // Chunky grain cells. Each cell crossfades between its current and\n  // next roll, so the field breathes instead of strobing; a per-cell\n  // phase offset desynchronizes neighbours.\n  vec2 cell = floor(gl_FragCoord.xy / max(u_grain, 1.0));\n  float phase = hash(cell) * 6.2831;\n  float t = u_time * 1.4 + phase;\n  float tick = floor(t);\n  float f = smoothstep(0.0, 1.0, fract(t));\n  float g1 = hash(cell + vec2(tick * 0.37, tick * 0.11));\n  float g2 = hash(cell + vec2((tick + 1.0) * 0.37, (tick + 1.0) * 0.11));\n  float g = mix(g1, g2, f);\n\n  // Grain survives where its roll beats the local density threshold —\n  // a soft threshold, so specks fade in and out instead of popping.\n  float grain = smoothstep(1.0 - grad * 0.85 - 0.12, 1.0 - grad * 0.85, g) *\n    (0.35 + 0.65 * g);\n  // Kept quiet: the wash is atmosphere, never a surface. Hover warms it.\n  float alpha = (grad * u_intensity + grain * grad * u_noise) *\n    (0.22 + u_lift * 0.14);\n\n  gl_FragColor = vec4(u_color * alpha, alpha);\n}\n`;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}