{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bg-prism-burst",
  "type": "registry:component",
  "title": "Prism Burst",
  "description": "A slowly rotating burst of light rays that split into spectrum colors from a bright core that follows the pointer.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "background",
    "prism",
    "rays",
    "spectrum",
    "canvas",
    "pointer"
  ],
  "docs": "https://hyperblur.dev/effects/bg-prism-burst",
  "files": [
    {
      "path": "registry/hyperblur/bg-prism-burst.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/bg-prism-burst.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BgPrismBurstProps extends React.HTMLAttributes<HTMLDivElement> {\n  accent?: string;\n  background?: string;\n  rays?: number;\n  spread?: number;\n  intensity?: number;\n  speed?: number;\n  children?: React.ReactNode;\n}\n\nconst css = `\n.hb-qp6 { position: absolute; inset: 0; overflow: hidden; pointer-events: none; box-sizing: border-box; }\n.hb-qp6-c { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }\n.hb-qp6-in { position: relative; z-index: 1; width: 100%; height: 100%; pointer-events: auto; font-family: inherit; }\n`;\n\nconst spectrum = [\"#ff3b4e\", \"#ff8a2a\", \"#ffe14a\", \"#3dff8f\", \"#2fb4ff\", \"#5b5bff\", \"#b04dff\"];\n\nfunction rnd(i: number) {\n  let x = Math.imul(i ^ 0x9e3779b9, 0x85ebca6b);\n  x ^= x >>> 13;\n  x = Math.imul(x, 0xc2b2ae35);\n  x ^= x >>> 16;\n  return (x >>> 0) / 4294967296;\n}\n\nexport function BgPrismBurst({\n  accent = \"#cfe0ff\",\n  background = \"#050508\",\n  rays = 22,\n  spread = 1,\n  intensity = 1,\n  speed = 1,\n  children,\n  className = \"\",\n  style,\n  ...rest\n}: BgPrismBurstProps) {\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 host = wrap?.parentElement;\n    const canvas = canvasRef.current;\n    const ctx = canvas?.getContext(\"2d\");\n    const off = document.createElement(\"canvas\");\n    const octx = off.getContext(\"2d\");\n    if (!wrap || !host || !canvas || !ctx || !octx) return;\n\n    const motion = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    const N = Math.max(4, Math.min(60, Math.round(rays)));\n    const S = spectrum.length;\n\n    let w = 0;\n    let h = 0;\n    let dpr = 1;\n    let t = 0;\n    let inside = false;\n    let tx = 0;\n    let ty = 0;\n    let px = 0;\n    let py = 0;\n    let placed = false;\n    let visible = true;\n    let raf = 0;\n    let prev = 0;\n\n    function idleX(tt: number) {\n      return w * (0.5 + 0.22 * Math.sin(tt * 0.23 + 0.5));\n    }\n    function idleY(tt: number) {\n      return h * (0.42 + 0.16 * Math.sin(tt * 0.31 + 1.7));\n    }\n\n    function track(dt: number) {\n      const gx = inside ? tx : idleX(t);\n      const gy = inside ? ty : idleY(t);\n      if (!placed || dt === 0) {\n        px = gx;\n        py = gy;\n        placed = true;\n        return;\n      }\n      const k = 1 - Math.exp(-dt * (inside ? 6 : 1.4));\n      px += (gx - px) * k;\n      py += (gy - py) * k;\n    }\n\n    function draw() {\n      if (!w || !h) return;\n      const far = Math.hypot(Math.max(px, w - px), Math.max(py, h - py)) * 1.05;\n      octx!.setTransform(dpr, 0, 0, dpr, 0, 0);\n      octx!.globalCompositeOperation = \"source-over\";\n      octx!.globalAlpha = 1;\n      octx!.clearRect(0, 0, w, h);\n      octx!.globalCompositeOperation = \"lighter\";\n      const spin = t * 0.06;\n      for (let r = 0; r < N; r++) {\n        const seed = r * 17 + 3;\n        const a = (r / N) * Math.PI * 2 + spin + (rnd(seed) - 0.5) * (Math.PI / N);\n        const width = (0.03 + 0.07 * rnd(seed + 1)) * spread;\n        const len = far * (0.45 + 0.55 * rnd(seed + 2)) * (0.82 + 0.18 * Math.sin(t * (0.5 + rnd(seed + 3)) + r * 1.3));\n        const power = (0.35 + 0.65 * rnd(seed + 4)) * (0.75 + 0.25 * Math.sin(t * 0.9 + r * 2.1));\n        const band = (width * 2.5) / S;\n        for (let s = 0; s < S; s++) {\n          const a0 = a + (s / S - 0.5) * width * 1.8;\n          const a1 = a0 + band;\n          octx!.globalAlpha = 0.24 * power * intensity;\n          octx!.fillStyle = spectrum[s];\n          octx!.beginPath();\n          octx!.moveTo(px, py);\n          octx!.lineTo(px + Math.cos(a0) * len, py + Math.sin(a0) * len);\n          octx!.lineTo(px + Math.cos(a1) * len, py + Math.sin(a1) * len);\n          octx!.closePath();\n          octx!.fill();\n        }\n        octx!.globalAlpha = 0.12 * power * intensity;\n        octx!.fillStyle = \"#ffffff\";\n        octx!.beginPath();\n        octx!.moveTo(px, py);\n        octx!.lineTo(px + Math.cos(a - width * 0.12) * len * 0.6, py + Math.sin(a - width * 0.12) * len * 0.6);\n        octx!.lineTo(px + Math.cos(a + width * 0.12) * len * 0.6, py + Math.sin(a + width * 0.12) * len * 0.6);\n        octx!.closePath();\n        octx!.fill();\n      }\n      octx!.globalCompositeOperation = \"destination-in\";\n      octx!.globalAlpha = 1;\n      const mask = octx!.createRadialGradient(px, py, 0, px, py, far);\n      mask.addColorStop(0, \"rgba(0,0,0,1)\");\n      mask.addColorStop(0.35, \"rgba(0,0,0,0.75)\");\n      mask.addColorStop(1, \"rgba(0,0,0,0)\");\n      octx!.fillStyle = mask;\n      octx!.fillRect(0, 0, w, h);\n\n      ctx!.globalCompositeOperation = \"source-over\";\n      ctx!.globalAlpha = 1;\n      ctx!.fillStyle = background;\n      ctx!.fillRect(0, 0, w, h);\n      ctx!.globalCompositeOperation = \"lighter\";\n      ctx!.setTransform(1, 0, 0, 1, 0, 0);\n      ctx!.drawImage(off, 0, 0);\n      ctx!.setTransform(dpr, 0, 0, dpr, 0, 0);\n\n      const halo = Math.min(w, h) * 0.5;\n      const hg = ctx!.createRadialGradient(px, py, 0, px, py, halo);\n      hg.addColorStop(0, accent);\n      hg.addColorStop(0.4, \"rgba(0,0,0,0)\");\n      ctx!.globalAlpha = 0.35 * intensity;\n      ctx!.fillStyle = hg;\n      ctx!.fillRect(px - halo, py - halo, halo * 2, halo * 2);\n\n      const core = Math.min(w, h) * 0.07 * (0.92 + 0.08 * Math.sin(t * 2.2));\n      const cg = ctx!.createRadialGradient(px, py, 0, px, py, core);\n      cg.addColorStop(0, \"#ffffff\");\n      cg.addColorStop(0.35, accent);\n      cg.addColorStop(1, \"rgba(0,0,0,0)\");\n      ctx!.globalAlpha = 0.95;\n      ctx!.fillStyle = cg;\n      ctx!.fillRect(px - core, py - core, core * 2, core * 2);\n\n      const ring = Math.min(w, h) * 0.22;\n      ctx!.globalAlpha = 0.1 * intensity;\n      ctx!.strokeStyle = accent;\n      ctx!.lineWidth = 1;\n      ctx!.beginPath();\n      ctx!.arc(px, py, ring, 0, Math.PI * 2);\n      ctx!.stroke();\n\n      const fx = w / 2 + (w / 2 - px) * 0.6;\n      const fy = h / 2 + (h / 2 - py) * 0.6;\n      for (let i = 0; i < 3; i++) {\n        const k = 0.35 + i * 0.32;\n        const x = px + (fx - px) * k;\n        const y = py + (fy - py) * k;\n        const rr = Math.min(w, h) * (0.025 + 0.02 * i);\n        ctx!.globalAlpha = 0.1 * intensity;\n        ctx!.fillStyle = spectrum[(i * 2 + 1) % S];\n        ctx!.beginPath();\n        ctx!.arc(x, y, rr, 0, Math.PI * 2);\n        ctx!.fill();\n      }\n      ctx!.globalAlpha = 1;\n      ctx!.globalCompositeOperation = \"source-over\";\n    }\n\n    function still() {\n      t = 6;\n      inside = false;\n      placed = false;\n      track(0);\n      draw();\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      dpr = Math.min(2, window.devicePixelRatio || 1);\n      w = nw;\n      h = nh;\n      canvas.width = Math.max(1, Math.round(w * dpr));\n      canvas.height = Math.max(1, Math.round(h * dpr));\n      off.width = canvas.width;\n      off.height = canvas.height;\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      if (motion.matches) still();\n      else {\n        track(0);\n        draw();\n      }\n    }\n\n    function frame(now: number) {\n      const dt = Math.min(0.033, (now - prev) / 1000);\n      prev = now;\n      t += dt * speed;\n      track(dt);\n      draw();\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      if (motion.matches) still();\n    }\n\n    function move(e: PointerEvent) {\n      if (!host || motion.matches) return;\n      const rect = host.getBoundingClientRect();\n      const sx = rect.width ? host.clientWidth / rect.width : 1;\n      const sy = rect.height ? host.clientHeight / rect.height : 1;\n      tx = (e.clientX - rect.left) * sx;\n      ty = (e.clientY - rect.top) * sy;\n      inside = true;\n    }\n\n    function leave(e: PointerEvent) {\n      if (e.type === \"pointerup\" && e.pointerType === \"mouse\") return;\n      inside = false;\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\", sync);\n    host.addEventListener(\"pointermove\", move, { passive: true });\n    host.addEventListener(\"pointerdown\", move, { passive: true });\n    host.addEventListener(\"pointerleave\", leave);\n    host.addEventListener(\"pointerup\", leave);\n    host.addEventListener(\"pointercancel\", leave);\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\", sync);\n      host.removeEventListener(\"pointermove\", move);\n      host.removeEventListener(\"pointerdown\", move);\n      host.removeEventListener(\"pointerleave\", leave);\n      host.removeEventListener(\"pointerup\", leave);\n      host.removeEventListener(\"pointercancel\", leave);\n    };\n  }, [accent, background, rays, spread, intensity, speed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-qp6 ${className}`} style={style} {...rest}>\n      <style href=\"hb-bg-prism-burst\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-qp6-c\" aria-hidden=\"true\" />\n      {children ? <div className=\"hb-qp6-in\">{children}</div> : null}\n    </div>\n  );\n}\n"
    }
  ]
}