{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bg-light-tunnel",
  "type": "registry:component",
  "title": "Light Tunnel",
  "description": "Glowing rounded frames fly out of the distance in an endless tunnel. The vanishing point leans toward the pointer.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "background",
    "tunnel",
    "neon",
    "perspective",
    "canvas",
    "pointer"
  ],
  "docs": "https://hyperblur.dev/effects/bg-light-tunnel",
  "files": [
    {
      "path": "registry/hyperblur/bg-light-tunnel.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/bg-light-tunnel.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BgLightTunnelProps extends React.HTMLAttributes<HTMLDivElement> {\n  color?: string;\n  secondaryColor?: string;\n  rings?: number;\n  speed?: number;\n  thickness?: number;\n  cornerRadius?: number;\n  follow?: number;\n}\n\nconst css = `\n.hb-qj7 { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }\n.hb-qj7-c { display: block; width: 100%; height: 100%; }\n`;\n\nexport function BgLightTunnel({\n  color = \"#2f7bff\",\n  secondaryColor = \"#b16cff\",\n  rings = 22,\n  speed = 1,\n  thickness = 1.6,\n  cornerRadius = 10,\n  follow = 0.7,\n  className = \"\",\n  style,\n  ...rest\n}: BgLightTunnelProps) {\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    if (!wrap || !host || !canvas || !ctx) return;\n\n    const count = Math.max(4, Math.min(80, Math.floor(rings)));\n    let w = 0;\n    let h = 0;\n    let t = 0;\n    let travel = 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\n    function idleX(tt: number) {\n      return w * (0.5 + 0.26 * Math.sin(tt * 0.35));\n    }\n    function idleY(tt: number) {\n      return h * (0.5 + 0.24 * Math.sin(tt * 0.56 + 1.3));\n    }\n\n    function track(dt: number) {\n      const gx = inside ? tx : idleX(t);\n      const gy = inside ? ty : idleY(t);\n      if (!placed) {\n        px = gx;\n        py = gy;\n        placed = true;\n        return;\n      }\n      const k = 1 - Math.exp(-dt * (inside ? 5 : 1.8));\n      px += (gx - px) * k;\n      py += (gy - py) * k;\n    }\n\n    function smooth(a: number, b: number, x: number) {\n      const k = Math.max(0, Math.min(1, (x - a) / (b - a)));\n      return k * k * (3 - 2 * k);\n    }\n\n    function draw() {\n      if (!ctx || !w || !h) return;\n      ctx.clearRect(0, 0, w, h);\n      const cx = w / 2;\n      const cy = h / 2;\n      const vx = cx + (px - cx) * follow;\n      const vy = cy + (py - cy) * follow;\n      ctx.globalCompositeOperation = \"lighter\";\n      const core = ctx.createRadialGradient(vx, vy, 0, vx, vy, Math.min(w, h) * 0.35);\n      core.addColorStop(0, color);\n      core.addColorStop(1, \"rgba(0,0,0,0)\");\n      ctx.globalAlpha = 0.22;\n      ctx.fillStyle = core;\n      ctx.fillRect(0, 0, w, h);\n      ctx.globalAlpha = 0.1;\n      ctx.strokeStyle = color;\n      ctx.lineWidth = 1;\n      ctx.beginPath();\n      ctx.moveTo(vx, vy);\n      ctx.lineTo(0, 0);\n      ctx.moveTo(vx, vy);\n      ctx.lineTo(w, 0);\n      ctx.moveTo(vx, vy);\n      ctx.lineTo(w, h);\n      ctx.moveTo(vx, vy);\n      ctx.lineTo(0, h);\n      ctx.stroke();\n      const order: number[] = [];\n      for (let i = 0; i < count; i++) order.push(i);\n      const depth = (i: number) => {\n        const u = (((i / count - travel) % 1) + 1) % 1;\n        return u;\n      };\n      order.sort((a, b) => depth(b) - depth(a));\n      for (const i of order) {\n        const z = depth(i);\n        const s = 1 / (z * 8 + 0.6);\n        const q = Math.min(1, s / 1.6667);\n        const rx = vx + (cx - vx) * q;\n        const ry = vy + (cy - vy) * q;\n        const hw = (w / 2) * s;\n        const hh = (h / 2) * s;\n        const a = smooth(1, 0.78, z) * smooth(0, 0.07, z);\n        if (a <= 0.01) continue;\n        const lw = thickness * Math.min(3.5, 0.6 + s * 1.6);\n        const c = i % 2 === 0 ? color : secondaryColor;\n        const rad = Math.min(cornerRadius * s, hw, hh);\n        ctx.strokeStyle = c;\n        ctx.beginPath();\n        ctx.roundRect(rx - hw, ry - hh, hw * 2, hh * 2, rad);\n        ctx.globalAlpha = a * 0.16;\n        ctx.lineWidth = lw * 5;\n        ctx.stroke();\n        ctx.globalAlpha = a * 0.3;\n        ctx.lineWidth = lw * 2.2;\n        ctx.stroke();\n        ctx.globalAlpha = a;\n        ctx.lineWidth = lw;\n        ctx.stroke();\n      }\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      const 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      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      if (motion.matches) still();\n      else {\n        track(0);\n        draw();\n      }\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 = 0;\n      travel = 0.02;\n      inside = false;\n      placed = false;\n      track(0);\n      draw();\n    }\n\n    function frame(now: number) {\n      const dt = Math.min(0.05, (now - prev) / 1000);\n      prev = now;\n      t += dt;\n      travel = (travel + dt * 0.11 * speed) % 1;\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  }, [color, secondaryColor, rings, speed, thickness, cornerRadius, follow]);\n\n  return (\n    <div ref={wrapRef} className={`hb-qj7 ${className}`} style={style} aria-hidden=\"true\" {...rest}>\n      <style href=\"hb-bg-light-tunnel\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-qj7-c\" />\n    </div>\n  );\n}\n"
    }
  ]
}