{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "beams",
  "type": "registry:component",
  "title": "Beams",
  "description": "Diagonal light beams sweeping slowly across a dark background, with soft edges and a gentle shimmer. Canvas 2D, additive blending.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "beams",
    "light",
    "background",
    "canvas",
    "glow"
  ],
  "docs": "https://hyperblur.dev/effects/beams",
  "files": [
    {
      "path": "registry/hyperblur/beams.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/beams.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BeamsProps extends React.HTMLAttributes<HTMLDivElement> {\n  color?: string;\n  count?: number;\n  speed?: number;\n  angle?: number;\n  blur?: number;\n  seed?: number;\n}\n\nconst css = `\n.hb-bm { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }\n.hb-bm-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }\n`;\n\ninterface Beam {\n  rot: number;\n  start: number;\n  vel: number;\n  size: number;\n  alpha: number;\n  freq: number;\n  phase: number;\n  gradient: CanvasGradient | null;\n}\n\nfunction rnd(i: number, salt: number, seed: number) {\n  let x = (Math.imul(i + 1, 2654435761) + Math.imul(salt + 1, 40503) + Math.imul(seed | 0, 2246822519)) >>> 0;\n  x = Math.imul((x >>> 16) ^ x, 0x45d9f3b);\n  x = Math.imul((x >>> 16) ^ x, 0x45d9f3b);\n  x = ((x >>> 16) ^ x) >>> 0;\n  return x / 4294967296;\n}\n\nfunction parseColor(ctx: CanvasRenderingContext2D, value: string): [number, number, number] {\n  ctx.fillStyle = \"#2f7bff\";\n  ctx.fillStyle = value;\n  const s = String(ctx.fillStyle);\n  if (s[0] === \"#\") {\n    const n = parseInt(s.slice(1), 16);\n    return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n  }\n  const m = s.match(/[\\d.]+/g);\n  return m && m.length >= 3 ? [Math.round(+m[0]), Math.round(+m[1]), Math.round(+m[2])] : [47, 123, 255];\n}\n\nexport function Beams({\n  color = \"#2f7bff\",\n  count = 6,\n  speed = 1,\n  angle = 25,\n  blur = 0.6,\n  seed = 1,\n  className = \"\",\n  style,\n  ...rest\n}: BeamsProps) {\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 ? canvas.getContext(\"2d\") : null;\n    if (!wrap || !canvas || !ctx) return;\n\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    const total = Math.max(1, Math.round(count));\n    const soft = Math.min(1, Math.max(0, blur));\n    const rgb = parseColor(ctx, color);\n    const core = rgb.map((v) => Math.round(v + (255 - v) * 0.45));\n    const edge = (a: number) => `rgba(${rgb[0]},${rgb[1]},${rgb[2]},${a.toFixed(3)})`;\n    const mid = `rgba(${core[0]},${core[1]},${core[2]},1)`;\n\n    const beams: Beam[] = Array.from({ length: total }, (_, i) => ({\n      rot: ((angle + (rnd(i, 1, seed) - 0.5) * 16) * Math.PI) / 180,\n      start: rnd(i, 2, seed),\n      vel: (0.012 + rnd(i, 3, seed) * 0.022) * (rnd(i, 4, seed) < 0.25 ? -1 : 1),\n      size: 0.05 + rnd(i, 5, seed) * 0.13,\n      alpha: 0.16 + rnd(i, 6, seed) * 0.2,\n      freq: 0.5 + rnd(i, 7, seed) * 0.9,\n      phase: rnd(i, 8, seed) * Math.PI * 2,\n      gradient: null,\n    }));\n\n    let w = 1;\n    let h = 1;\n    let dpr = 1;\n    let diag = 1;\n    let raf = 0;\n    let last = 0;\n    let time = 0;\n    let visible = true;\n\n    const build = () => {\n      for (const b of beams) {\n        const bw = b.size * diag;\n        const g = ctx.createLinearGradient(-bw / 2, 0, bw / 2, 0);\n        const fall = 0.1 + soft * 0.4;\n        const steps = 5;\n        for (let k = 0; k <= steps; k++) {\n          const u = k / steps;\n          const a = u * u * (3 - 2 * u);\n          g.addColorStop(fall * u, edge(a * 0.85));\n          g.addColorStop(1 - fall * u, edge(a * 0.85));\n        }\n        g.addColorStop(0.5, mid);\n        b.gradient = g;\n      }\n    };\n\n    const draw = (t: number) => {\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      ctx.clearRect(0, 0, w, h);\n      ctx.globalCompositeOperation = \"lighter\";\n      const cx = w / 2;\n      const cy = h / 2;\n      for (const b of beams) {\n        const bw = b.size * diag;\n        const pos = (((b.start + b.vel * speed * t) % 1) + 1) % 1;\n        const off = (pos - 0.5) * (diag + bw);\n        const cos = Math.cos(b.rot);\n        const sin = Math.sin(b.rot);\n        const shimmer = 0.78 + 0.14 * Math.sin(t * b.freq + b.phase) + 0.08 * Math.sin(t * b.freq * 2.7 + b.phase * 1.7);\n        ctx.globalAlpha = b.alpha * shimmer;\n        ctx.setTransform(dpr * cos, dpr * sin, -dpr * sin, dpr * cos, dpr * (cx + cos * off), dpr * (cy + sin * off));\n        if (b.gradient) ctx.fillStyle = b.gradient;\n        ctx.fillRect(-bw / 2, -diag / 2, bw, diag);\n      }\n      ctx.globalAlpha = 1;\n      ctx.globalCompositeOperation = \"source-over\";\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n    };\n\n    const active = () => visible && !document.hidden && !reduce.matches;\n\n    const frame = (now: number) => {\n      raf = 0;\n      time += Math.min(0.05, (now - last) / 1000);\n      last = now;\n      draw(time);\n      if (active()) raf = requestAnimationFrame(frame);\n    };\n\n    const sync = () => {\n      if (active()) {\n        if (!raf) {\n          last = performance.now();\n          raf = requestAnimationFrame(frame);\n        }\n      } else {\n        cancelAnimationFrame(raf);\n        raf = 0;\n        draw(time);\n      }\n    };\n\n    const resize = () => {\n      w = Math.max(1, wrap.clientWidth);\n      h = Math.max(1, wrap.clientHeight);\n      dpr = Math.min(2, window.devicePixelRatio || 1);\n      diag = Math.hypot(w, h);\n      canvas.width = Math.round(w * dpr);\n      canvas.height = Math.round(h * dpr);\n      build();\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\n    ro.observe(wrap);\n    io.observe(wrap);\n    document.addEventListener(\"visibilitychange\", sync);\n    reduce.addEventListener(\"change\", sync);\n    resize();\n    sync();\n\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      document.removeEventListener(\"visibilitychange\", sync);\n      reduce.removeEventListener(\"change\", sync);\n    };\n  }, [color, count, speed, angle, blur, seed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-bm ${className}`} style={style} aria-hidden=\"true\" {...rest}>\n      <style href=\"hb-beams\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-bm-canvas\" />\n    </div>\n  );\n}\n"
    }
  ]
}