{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "light-rays",
  "type": "registry:component",
  "title": "Light Rays",
  "description": "Volumetric light rays fanning out from a point near the top, slowly swaying and pulsing with a radial falloff and additive blending.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "light",
    "rays",
    "canvas",
    "background",
    "volumetric",
    "god-rays",
    "glow"
  ],
  "docs": "https://hyperblur.dev/effects/light-rays",
  "files": [
    {
      "path": "registry/hyperblur/light-rays.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/light-rays.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface LightRaysProps extends React.HTMLAttributes<HTMLDivElement> {\n  color?: string;\n  rays?: number;\n  origin?: \"top\" | \"top-left\" | \"top-right\";\n  speed?: number;\n  spread?: number;\n  intensity?: number;\n  seed?: number;\n}\n\nconst css = `\n.hb-lr { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }\n.hb-lr-c { display: block; width: 100%; height: 100%; mix-blend-mode: screen; }\n`;\n\nconst LAYER_WIDTH = [1, 0.6, 0.3];\nconst LAYER_ALPHA = [0.4, 0.35, 0.35];\n\nfunction rnd(seed: number, i: number) {\n  let x = (Math.imul(i + 1, 0x9e3779b1) + Math.imul(seed | 0, 0x85ebca6b)) >>> 0;\n  x = Math.imul((x >>> 16) ^ x, 0x45d9f3b) >>> 0;\n  x = Math.imul((x >>> 16) ^ x, 0x45d9f3b) >>> 0;\n  x = ((x >>> 16) ^ x) >>> 0;\n  return x / 4294967296;\n}\n\nexport function LightRays({\n  color = \"#2f7bff\",\n  rays = 12,\n  origin = \"top\",\n  speed = 1,\n  spread = 60,\n  intensity = 0.6,\n  seed = 1,\n  className = \"\",\n  style,\n  ...rest\n}: LightRaysProps) {\n  const wrapRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n\n  React.useEffect(() => {\n    const wrap = wrapRef.current;\n    const canvas = canvasRef.current;\n    const ctx = canvas?.getContext(\"2d\");\n    const probe = document.createElement(\"canvas\");\n    probe.width = 1;\n    probe.height = 1;\n    const pctx = probe.getContext(\"2d\", { willReadFrequently: true });\n    if (!wrap || !canvas || !ctx || !pctx) return;\n\n    pctx.fillStyle = \"#000\";\n    pctx.fillStyle = color;\n    pctx.fillRect(0, 0, 1, 1);\n    const rgb = pctx.getImageData(0, 0, 1, 1).data;\n    const tint = `${rgb[0]},${rgb[1]},${rgb[2]}`;\n\n    const n = Math.max(1, Math.min(64, Math.floor(rays)));\n    const TAU = Math.PI * 2;\n    const deg = Math.PI / 180;\n    const sp = Math.max(5, Math.min(170, spread)) * deg;\n    const gain = Math.min(1, Math.max(0, intensity));\n    const spacing = sp / n;\n    const offset = new Float32Array(n);\n    const half = new Float32Array(n);\n    const base = new Float32Array(n);\n    const pulseRate = new Float32Array(n);\n    const swayRate = new Float32Array(n);\n    const phase = new Float32Array(n);\n    for (let i = 0; i < n; i++) {\n      offset[i] = ((i + 0.5) / n - 0.5) * sp + (rnd(seed, i * 8 + 1) - 0.5) * spacing * 0.8;\n      half[i] = spacing * (0.12 + rnd(seed, i * 8 + 2) * 0.38);\n      base[i] = 0.35 + rnd(seed, i * 8 + 3) * 0.65;\n      pulseRate[i] = 0.4 + rnd(seed, i * 8 + 4) * 0.8;\n      swayRate[i] = 0.1 + rnd(seed, i * 8 + 5) * 0.2;\n      phase[i] = rnd(seed, i * 8 + 6) * TAU;\n    }\n\n    let w = 0;\n    let h = 0;\n    let ox = 0;\n    let oy = 0;\n    let aim = Math.PI / 2;\n    let reach = 1;\n    let rayFill: CanvasGradient | null = null;\n    let glowFill: CanvasGradient | null = null;\n    let time = 10 + rnd(seed, 999) * 40;\n\n    function draw(t: number) {\n      if (!ctx || !canvas || !rayFill || !glowFill || !w || !h) return;\n      ctx.clearRect(0, 0, w, h);\n      ctx.globalCompositeOperation = \"lighter\";\n      const tt = t * speed;\n      const turn = Math.sin(tt * 0.12) * sp * 0.07;\n      ctx.fillStyle = rayFill;\n      for (let i = 0; i < n; i++) {\n        const pulse = 0.5 + 0.5 * Math.sin(tt * pulseRate[i] + phase[i]);\n        const a = Math.min(1, base[i] * (0.3 + 0.7 * pulse) * gain * 1.3);\n        const mid = aim + offset[i] + turn + Math.sin(tt * swayRate[i] + phase[i]) * sp * 0.04;\n        for (let l = 0; l < 3; l++) {\n          const hw = half[i] * LAYER_WIDTH[l] * (0.9 + 0.1 * pulse);\n          ctx.globalAlpha = a * LAYER_ALPHA[l];\n          ctx.beginPath();\n          ctx.moveTo(ox, oy);\n          ctx.lineTo(ox + Math.cos(mid - hw) * reach, oy + Math.sin(mid - hw) * reach);\n          ctx.lineTo(ox + Math.cos(mid + hw) * reach, oy + Math.sin(mid + hw) * reach);\n          ctx.closePath();\n          ctx.fill();\n        }\n      }\n      ctx.globalAlpha = Math.min(1, gain * 0.6);\n      ctx.fillStyle = glowFill;\n      ctx.fillRect(0, 0, w, h);\n      ctx.globalAlpha = 1;\n      ctx.globalCompositeOperation = \"source-over\";\n    }\n\n    function resize() {\n      if (!wrap || !canvas || !ctx) return;\n      const nw = wrap.clientWidth;\n      const nh = wrap.clientHeight;\n      if (!nw || !nh) return;\n      w = nw;\n      h = nh;\n      const dpr = Math.min(2, window.devicePixelRatio || 1);\n      canvas.width = Math.max(1, Math.round(w * dpr));\n      canvas.height = Math.max(1, Math.round(h * dpr));\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      let tx = 0.5 * w;\n      if (origin === \"top-left\") {\n        ox = 0.1 * w;\n        tx = 0.55 * w;\n      } else if (origin === \"top-right\") {\n        ox = 0.9 * w;\n        tx = 0.45 * w;\n      } else {\n        ox = 0.5 * w;\n      }\n      oy = -0.1 * h;\n      aim = Math.atan2(h - oy, tx - ox);\n      reach = Math.hypot(w, h) * 1.4;\n      rayFill = ctx.createRadialGradient(ox, oy, 0, ox, oy, reach);\n      rayFill.addColorStop(0, `rgba(${tint},1)`);\n      rayFill.addColorStop(0.2, `rgba(${tint},0.6)`);\n      rayFill.addColorStop(0.55, `rgba(${tint},0.18)`);\n      rayFill.addColorStop(1, `rgba(${tint},0)`);\n      const gr = Math.max(w, h) * 0.55;\n      glowFill = ctx.createRadialGradient(ox, oy, 0, ox, oy, gr);\n      glowFill.addColorStop(0, `rgba(${tint},0.9)`);\n      glowFill.addColorStop(0.4, `rgba(${tint},0.25)`);\n      glowFill.addColorStop(1, `rgba(${tint},0)`);\n      draw(time);\n    }\n\n    const motion = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    let visible = true;\n    let raf = 0;\n    let prev = 0;\n\n    function frame(now: number) {\n      const dt = Math.min(0.05, (now - prev) / 1000);\n      prev = now;\n      time += dt;\n      draw(time);\n      raf = requestAnimationFrame(frame);\n    }\n\n    function sync() {\n      const run = visible && !document.hidden && !motion.matches;\n      if (run && !raf) {\n        prev = performance.now();\n        raf = requestAnimationFrame(frame);\n      } else if (!run && raf) {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n    }\n\n    function onMotion() {\n      sync();\n      draw(time);\n    }\n\n    const ro = new ResizeObserver(resize);\n    const io = new IntersectionObserver((entries) => {\n      visible = entries[entries.length - 1].isIntersecting;\n      sync();\n    });\n    ro.observe(wrap);\n    io.observe(wrap);\n    document.addEventListener(\"visibilitychange\", sync);\n    motion.addEventListener(\"change\", onMotion);\n    resize();\n    sync();\n\n    return () => {\n      if (raf) cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      document.removeEventListener(\"visibilitychange\", sync);\n      motion.removeEventListener(\"change\", onMotion);\n    };\n  }, [color, rays, origin, speed, spread, intensity, seed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-lr ${className}`} style={style} aria-hidden=\"true\" {...rest}>\n      <style href=\"hb-light-rays\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-lr-c\" />\n    </div>\n  );\n}\n"
    }
  ]
}