{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bg-vortex",
  "type": "registry:component",
  "title": "Vortex Tunnel",
  "description": "Segmented rings rush toward the viewer through a twisting tunnel whose far end sways, with sparks spiraling along the walls and a glowing core.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "background",
    "vortex",
    "tunnel",
    "spiral",
    "canvas",
    "warp"
  ],
  "docs": "https://hyperblur.dev/effects/bg-vortex",
  "files": [
    {
      "path": "registry/hyperblur/bg-vortex.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/bg-vortex.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BgVortexProps extends React.HTMLAttributes<HTMLDivElement> {\n  color?: string;\n  accent?: string;\n  background?: string;\n  rings?: number;\n  twist?: number;\n  sparks?: number;\n  speed?: number;\n  children?: React.ReactNode;\n}\n\nconst css = `\n.hb-ve12 { position: absolute; inset: 0; overflow: hidden; pointer-events: none; box-sizing: border-box; }\n.hb-ve12-c { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }\n.hb-ve12-in { position: relative; z-index: 1; width: 100%; height: 100%; pointer-events: auto; font-family: inherit; }\n`;\n\nfunction rgbOf(value: string, fallback: [number, number, number]): [number, number, number] {\n  const raw = value.trim().replace(\"#\", \"\");\n  const hex = raw.length === 3 ? raw.split(\"\").map((c) => c + c).join(\"\") : raw;\n  const n = parseInt(hex.slice(0, 6), 16);\n  if (hex.length < 6 || Number.isNaN(n)) return fallback;\n  return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n}\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 BgVortex({\n  color = \"#3a2a8f\",\n  accent = \"#7fb3ff\",\n  background = \"#040409\",\n  rings = 32,\n  twist = 2.4,\n  sparks = 160,\n  speed = 1,\n  className = \"\",\n  style,\n  children,\n  ...rest\n}: BgVortexProps) {\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    if (!wrap || !canvas || !ctx) return;\n    const g: CanvasRenderingContext2D = ctx;\n    const el: HTMLDivElement = wrap;\n    const cv: HTMLCanvasElement = canvas;\n\n    const ca = rgbOf(color, [58, 42, 143]);\n    const cb = rgbOf(accent, [127, 179, 255]);\n    const nr = Math.max(8, Math.min(80, Math.round(rings)));\n    const ns = Math.max(0, Math.min(600, Math.round(sparks)));\n    const sp = Array.from({ length: ns }, (_, i) => ({\n      a: rnd(i * 4 + 1) * 6.283,\n      z: rnd(i * 4 + 2),\n      v: 0.6 + rnd(i * 4 + 3) * 0.8,\n      r: 0.75 + rnd(i * 4 + 4) * 0.35,\n    }));\n\n    let w = 0;\n    let h = 0;\n    let t = 0;\n\n    function mix(k: number, a: number) {\n      return `rgba(${Math.round(ca[0] + (cb[0] - ca[0]) * k)},${Math.round(ca[1] + (cb[1] - ca[1]) * k)},${Math.round(ca[2] + (cb[2] - ca[2]) * k)},${a.toFixed(3)})`;\n    }\n\n    function proj(z: number) {\n      return 1 / (0.09 + (1 - z) * 2.4);\n    }\n\n    function center(z: number): [number, number] {\n      const far = 1 - z;\n      return [\n        w / 2 + Math.sin(t * 0.31) * w * 0.09 * far * far + Math.sin(t * 0.17 + 1) * w * 0.03 * far,\n        h / 2 + Math.cos(t * 0.23) * h * 0.08 * far * far,\n      ];\n    }\n\n    function render() {\n      if (!w || !h) return;\n      g.fillStyle = background;\n      g.fillRect(0, 0, w, h);\n      const R = Math.max(w, h) * 0.16;\n      const flow = t * 0.07;\n      g.lineCap = \"round\";\n      g.globalCompositeOperation = \"lighter\";\n      for (let i = 0; i < nr; i++) {\n        const z = (i / nr + flow) % 1;\n        const r = R * proj(z);\n        if (r > Math.max(w, h) * 1.4) continue;\n        const [cx, cy] = center(z);\n        const fade = Math.min(1, z / 0.25) * Math.min(1, (1 - z) / 0.22);\n        if (fade <= 0.01) continue;\n        const rot = t * 0.35 + z * twist * 3.14159;\n        const segs = 14;\n        const arc = (6.2832 / segs) * 0.56;\n        g.strokeStyle = mix(z, fade * (0.35 + z * 0.5));\n        g.lineWidth = 0.6 + z * z * 5;\n        g.beginPath();\n        for (let s = 0; s < segs; s++) {\n          const a0 = rot + (s * 6.2832) / segs;\n          g.moveTo(cx + Math.cos(a0) * r, cy + Math.sin(a0) * r);\n          g.arc(cx, cy, r, a0, a0 + arc);\n        }\n        g.stroke();\n      }\n      g.lineWidth = 1.2;\n      for (const s of sp) {\n        const z0 = (s.z + flow * s.v * 1.4) % 1;\n        const z1 = Math.max(0, z0 - 0.025);\n        const fade = Math.min(1, z0 / 0.3) * Math.min(1, (1 - z0) / 0.12);\n        if (fade <= 0.01) continue;\n        const a0 = s.a + t * 0.35 + z0 * twist * 3.14159;\n        const a1 = s.a + t * 0.35 + z1 * twist * 3.14159;\n        const [x0, y0] = center(z0);\n        const [x1, y1] = center(z1);\n        const r0 = R * proj(z0) * s.r;\n        const r1 = R * proj(z1) * s.r;\n        g.strokeStyle = mix(0.6 + z0 * 0.4, fade * 0.8);\n        g.beginPath();\n        g.moveTo(x1 + Math.cos(a1) * r1, y1 + Math.sin(a1) * r1);\n        g.lineTo(x0 + Math.cos(a0) * r0, y0 + Math.sin(a0) * r0);\n        g.stroke();\n      }\n      g.globalCompositeOperation = \"source-over\";\n      const [ex, ey] = center(0);\n      const core = g.createRadialGradient(ex, ey, 0, ex, ey, R * 0.9);\n      core.addColorStop(0, mix(1, 0.35));\n      core.addColorStop(0.25, mix(0.5, 0.12));\n      core.addColorStop(1, \"rgba(0,0,0,0)\");\n      g.globalCompositeOperation = \"lighter\";\n      g.fillStyle = core;\n      g.fillRect(0, 0, w, h);\n      g.globalCompositeOperation = \"source-over\";\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 still() {\n      t = 3;\n      render();\n    }\n\n    function resize() {\n      const nw = el.clientWidth;\n      const nh = el.clientHeight;\n      if (!nw || !nh) return;\n      const dpr = Math.min(2, window.devicePixelRatio || 1);\n      w = nw;\n      h = nh;\n      cv.width = Math.max(1, Math.round(w * dpr));\n      cv.height = Math.max(1, Math.round(h * dpr));\n      g.setTransform(dpr, 0, 0, dpr, 0, 0);\n      if (motion.matches) still();\n      else render();\n    }\n\n    function frame(now: number) {\n      const dt = Math.min(0.05, (now - prev) / 1000);\n      prev = now;\n      t += dt * speed;\n      render();\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    const ro = new ResizeObserver(resize);\n    const io = new IntersectionObserver((entries) => {\n      visible = entries[entries.length - 1].isIntersecting;\n      sync();\n    });\n    ro.observe(el);\n    io.observe(el);\n    document.addEventListener(\"visibilitychange\", sync);\n    motion.addEventListener(\"change\", sync);\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    };\n  }, [color, accent, background, rings, twist, sparks, speed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-ve12 ${className}`} style={{ background, ...style }} {...rest}>\n      <style href=\"hb-bg-vortex\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-ve12-c\" aria-hidden=\"true\" />\n      {children ? <div className=\"hb-ve12-in\">{children}</div> : null}\n    </div>\n  );\n}\n"
    }
  ]
}