{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"streak-rain","type":"registry:ui","title":"Streak Rain","description":"Streaks of light falling like rain across three depth layers, each with a glowing head and fading trail. WebGL.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/streak-rain.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nexport interface StreakRainProps {\n  colorA?: string;\n  colorB?: string;\n  /** Fall speed multiplier. */\n  speed?: number;\n  /** Streak columns per container height (front layer). */\n  density?: number;\n  /** Trail length, in container heights. */\n  length?: number;\n  /** Brightness and bloom. */\n  glow?: number;\n  className?: string;\n}\n\nconst FRAG = `precision highp float;\nuniform vec2 uRes;\nuniform float uTime;\nuniform vec3 uColorA;\nuniform vec3 uColorB;\nuniform float uDensity;\nuniform float uLength;\nuniform float uGlow;\n\nfloat hash(float n){ return fract(sin(n * 91.3458) * 47453.5453); }\n\n// One depth layer of falling streaks. scale > 1 means farther away: thinner, slower, dimmer.\nvec3 layer(vec2 uv, float scale, float seed, float bright){\n  float cols = uDensity * scale;\n  float cx = uv.x * cols + seed * 17.0;\n  float id = floor(cx);\n  float h1 = hash(id + seed);\n  float h2 = hash(id * 1.73 + seed + 3.1);\n  float h3 = hash(id * 2.31 + seed + 7.7);\n  float dx = (fract(cx) - 0.5 - (h3 - 0.5) * 0.6) / cols;\n\n  float len = uLength * mix(0.6, 1.4, h2) / sqrt(scale);\n  float spd = mix(0.35, 0.8, h2) / sqrt(scale);\n  float period = 1.3 + len + h1 * 1.5;\n  float head = 1.1 - fract(uTime * spd / period + h1 * 7.0) * period;\n  float d = uv.y - head;\n  float trail = d > 0.0 ? exp(-d / len) * (1.0 - exp(-d * 60.0)) + exp(-d * 90.0) : exp(d * 140.0);\n\n  float w = 0.0016 / scale * uGlow;\n  float core = exp(-dx * dx / (w * w));\n  float halo = exp(-abs(dx) / (w * 7.0)) * 0.3;\n  float flare = exp(-d * d / 0.0003) * exp(-dx * dx / (w * w * 16.0)) * 0.8;\n  float on = step(0.3, fract(h1 * 13.7 + h2)); // leave some columns empty\n  vec3 tint = mix(uColorA, uColorB, h3);\n  return tint * ((core + halo) * trail + flare) * bright * on;\n}\n\nvoid main(){\n  vec2 uv = gl_FragCoord.xy / uRes.y;\n  vec3 col = layer(uv, 3.4, 5.0, 0.32) + layer(uv, 1.9, 2.0, 0.6) + layer(uv, 1.0, 0.0, 1.0);\n  col *= uGlow;\n  col += vec3(1.0) * pow(max(col.r, max(col.g, col.b)), 3.0) * 0.3;\n  col += (fract(sin(dot(gl_FragCoord.xy, vec2(12.9898, 78.233))) * 43758.5453) - 0.5) / 255.0;\n  col = clamp(col, 0.0, 1.0);\n  gl_FragColor = vec4(col, max(col.r, max(col.g, col.b)));\n}`;\n\nfunction hexToRgb(hex: string) {\n  const n = parseInt(hex.replace(\"#\", \"\").padEnd(6, \"0\").slice(0, 6), 16);\n  return [((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255];\n}\n\ntype SetUniform = (name: string, v: number | number[], size?: number) => void;\n\n/** Full-screen-triangle WebGL runner: sizes to its host, pauses offscreen, one static frame under reduced motion. */\nfunction mountShader(host: HTMLElement, frag: string, frame: (set: SetUniform, dt: number) => void) {\n  const canvas = document.createElement(\"canvas\");\n  canvas.style.cssText = \"position:absolute;inset:0;width:100%;height:100%;display:block\";\n  const gl = canvas.getContext(\"webgl\", { antialias: false, premultipliedAlpha: true });\n  if (!gl) return null;\n  const prog = gl.createProgram()!;\n  const stages: [number, string][] = [\n    [gl.VERTEX_SHADER, \"attribute vec2 p;void main(){gl_Position=vec4(p,0.,1.);}\"],\n    [gl.FRAGMENT_SHADER, frag],\n  ];\n  for (const [type, src] of stages) {\n    const s = gl.createShader(type)!;\n    gl.shaderSource(s, src);\n    gl.compileShader(s);\n    if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) console.warn(gl.getShaderInfoLog(s));\n    gl.attachShader(prog, s);\n  }\n  gl.bindAttribLocation(prog, 0, \"p\");\n  gl.linkProgram(prog);\n  if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) {\n    gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n    return null;\n  }\n  gl.useProgram(prog);\n  gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());\n  gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);\n  gl.enableVertexAttribArray(0);\n  gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);\n  host.appendChild(canvas);\n\n  const locs = new Map<string, WebGLUniformLocation | null>();\n  const setters = [gl.uniform1fv, gl.uniform2fv, gl.uniform3fv, gl.uniform4fv];\n  const set: SetUniform = (name, v, size) => {\n    if (!locs.has(name)) locs.set(name, gl.getUniformLocation(prog, name));\n    const arr = typeof v === \"number\" ? [v] : v;\n    setters[(size ?? arr.length) - 1].call(gl, locs.get(name)!, arr);\n  };\n\n  const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n  let raf = 0;\n  let last = 0;\n  const render = (dt: number) => {\n    set(\"uRes\", [canvas.width, canvas.height]);\n    frame(set, dt);\n    gl.drawArrays(gl.TRIANGLES, 0, 3);\n  };\n  const loop = (now: number) => {\n    render(last ? Math.min((now - last) / 1000, 0.1) : 0);\n    last = now;\n    raf = requestAnimationFrame(loop);\n  };\n  const resize = () => {\n    const dpr = Math.min(window.devicePixelRatio || 1, 2);\n    canvas.width = Math.max(1, Math.round(host.clientWidth * dpr));\n    canvas.height = Math.max(1, Math.round(host.clientHeight * dpr));\n    gl.viewport(0, 0, canvas.width, canvas.height);\n    render(0);\n  };\n  const ro = new ResizeObserver(resize);\n  ro.observe(host);\n  const io = new IntersectionObserver(([e]) => {\n    cancelAnimationFrame(raf);\n    raf = 0;\n    last = 0;\n    if (e.isIntersecting && !reduced) raf = requestAnimationFrame(loop);\n  });\n  io.observe(host);\n\n  return {\n    redraw: () => {\n      if (!raf) render(0);\n    },\n    destroy: () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n      canvas.remove();\n    },\n  };\n}\n\nexport function StreakRain({\n  colorA = \"#67e8f9\",\n  colorB = \"#a78bfa\",\n  speed = 1,\n  density = 12,\n  length = 0.35,\n  glow = 1,\n  className,\n}: StreakRainProps) {\n  const host = useRef<HTMLDivElement>(null);\n  const opts = useRef({ a: hexToRgb(colorA), b: hexToRgb(colorB), speed, density, length, glow });\n  const redraw = useRef<() => void>(undefined);\n\n  useEffect(() => {\n    opts.current = { a: hexToRgb(colorA), b: hexToRgb(colorB), speed, density, length, glow };\n    redraw.current?.();\n  }, [colorA, colorB, speed, density, length, glow]);\n\n  useEffect(() => {\n    let t = 11;\n    const shader = mountShader(host.current!, FRAG, (set, dt) => {\n      const o = opts.current;\n      t += dt * o.speed;\n      set(\"uTime\", t);\n      set(\"uColorA\", o.a);\n      set(\"uColorB\", o.b);\n      set(\"uDensity\", Math.max(o.density, 1));\n      set(\"uLength\", Math.max(o.length, 0.02));\n      set(\"uGlow\", Math.max(o.glow, 0.05));\n    });\n    if (!shader) return;\n    redraw.current = shader.redraw;\n    return () => {\n      redraw.current = undefined;\n      shader.destroy();\n    };\n  }, []);\n\n  return (\n    <div\n      ref={host}\n      aria-hidden\n      className={className}\n      style={{ position: \"absolute\", inset: 0, overflow: \"hidden\", pointerEvents: \"none\" }}\n    />\n  );\n}\n"}]}