{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"halo-rings","type":"registry:ui","title":"Halo Rings","description":"Concentric glowing rings spin at their own pace, breathe, and bend toward the cursor.","dependencies":[],"registryDependencies":["utils"],"files":[{"path":"registry/ui/halo-rings.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface HaloRingsProps {\n  /** Number of concentric rings. */\n  rings?: number;\n  /** Color of the innermost ring. */\n  colorFrom?: string;\n  /** Color of the outermost ring. */\n  colorTo?: string;\n  /** Rotation speed multiplier. */\n  speed?: number;\n  /** How far rings bend toward the cursor, in px. */\n  pull?: number;\n  /** Stroke width in px. */\n  lineWidth?: number;\n  className?: string;\n}\n\nconst rgb = (hex: string) => {\n  const n = parseInt(hex.replace(\"#\", \"\").padEnd(6, \"0\").slice(0, 6), 16);\n  return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n};\nconst TAU = Math.PI * 2;\nconst SEG = 160;\n\nexport function HaloRings({\n  rings = 7,\n  colorFrom = \"#22d3ee\",\n  colorTo = \"#a855f7\",\n  speed = 1,\n  pull = 34,\n  lineWidth = 2,\n  className,\n}: HaloRingsProps) {\n  const ref = useRef<HTMLCanvasElement>(null);\n\n  useEffect(() => {\n    const canvas = ref.current!;\n    const ctx = canvas.getContext(\"2d\")!;\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const a = rgb(colorFrom);\n    const b = rgb(colorTo);\n    const ring = Array.from({ length: rings }, (_, i) => {\n      const k = rings > 1 ? i / (rings - 1) : 0;\n      const c = a.map((v, j) => Math.round(v + (b[j] - v) * k)).join(\",\");\n      // Alternate directions, deterministic speeds so it looks the same every load.\n      const dir = i % 2 ? -1 : 1;\n      const rand = Math.abs(Math.sin(i * 12.9898 + 1) * 43758.5453) % 1;\n      return { k, c, dir, rate: dir * (0.2 + 0.5 * rand), rot: i * 1.7 };\n    });\n    const m = { x: 0, y: 0, tx: 0, ty: 0, on: 0, ton: 0 };\n    let w = 0;\n    let h = 0;\n    let raf = 0;\n    let visible = true;\n    let prev = performance.now();\n    let t = 0;\n\n    const frame = () => {\n      m.x += (m.tx - m.x) * 0.08;\n      m.y += (m.ty - m.y) * 0.08;\n      m.on += (m.ton - m.on) * 0.05;\n      ctx.clearRect(0, 0, w, h);\n      ctx.globalCompositeOperation = \"lighter\";\n      ctx.lineCap = \"round\";\n      const cx = w / 2;\n      const cy = h / 2;\n      const min = Math.min(w, h);\n      const r0 = min * 0.17;\n      const r1 = min * 0.46;\n      const mdx = m.x - cx;\n      const mdy = m.y - cy;\n      const md = Math.hypot(mdx, mdy);\n      const ma = Math.atan2(mdy, mdx);\n      for (let i = 0; i < ring.length; i++) {\n        const R = ring[i];\n        const base = r0 + (r1 - r0) * R.k + Math.sin(t * 1.4 - i * 0.6) * 3;\n        // Rings near the cursor distance bend the most, bulging outward or inward toward it.\n        const reach = m.on * pull * Math.sign(md - base) * Math.exp(-Math.abs(md - base) / (min * 0.2));\n        ctx.beginPath();\n        for (let s = 0; s <= SEG; s++) {\n          const th = (s / SEG) * TAU;\n          let da = Math.abs(th - ma) % TAU;\n          if (da > Math.PI) da = TAU - da;\n          const r = base + reach * Math.exp(-(da * da) / 0.3) + Math.sin(th * 3 + t * (1 + R.k) + i) * 2.2;\n          const x = cx + Math.cos(th) * r;\n          const y = cy + Math.sin(th) * r;\n          if (s) ctx.lineTo(x, y);\n          else ctx.moveTo(x, y);\n        }\n        // Soft bloom pass, then a rotating comet gradient on top.\n        ctx.strokeStyle = `rgba(${R.c},0.045)`;\n        ctx.lineWidth = lineWidth * 7;\n        ctx.stroke();\n        ctx.strokeStyle = `rgba(${R.c},0.12)`;\n        ctx.lineWidth = lineWidth;\n        ctx.stroke();\n        const g = ctx.createConicGradient(R.rot, cx, cy);\n        const head = `rgba(${R.c},1)`;\n        const tail = `rgba(${R.c},0)`;\n        if (R.dir > 0) {\n          g.addColorStop(0, tail);\n          g.addColorStop(0.55, tail);\n          g.addColorStop(0.97, head);\n          g.addColorStop(1, \"rgba(255,255,255,1)\");\n        } else {\n          g.addColorStop(0, \"rgba(255,255,255,1)\");\n          g.addColorStop(0.03, head);\n          g.addColorStop(0.45, tail);\n          g.addColorStop(1, tail);\n        }\n        ctx.strokeStyle = g;\n        ctx.lineWidth = lineWidth * 1.4;\n        ctx.stroke();\n      }\n      ctx.globalCompositeOperation = \"source-over\";\n    };\n\n    const loop = (now: number) => {\n      const dt = Math.min(now - prev, 50) / 1000;\n      prev = now;\n      t += dt;\n      for (const R of ring) R.rot += R.rate * speed * dt;\n      frame();\n      raf = visible ? requestAnimationFrame(loop) : 0;\n    };\n\n    const resize = () => {\n      const dpr = Math.min(window.devicePixelRatio || 1, 2);\n      w = canvas.offsetWidth;\n      h = canvas.offsetHeight;\n      canvas.width = Math.round(w * dpr);\n      canvas.height = Math.round(h * dpr);\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      m.x = m.tx = w / 2;\n      m.y = m.ty = h / 2;\n      frame();\n    };\n    const onMove = (e: PointerEvent) => {\n      const r = canvas.getBoundingClientRect();\n      m.tx = e.clientX - r.left;\n      m.ty = e.clientY - r.top;\n      m.ton = 1;\n      if (reduced) frame();\n    };\n    const onLeave = () => (m.ton = 0);\n\n    const ro = new ResizeObserver(resize);\n    ro.observe(canvas);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible && !raf && !reduced) {\n        prev = performance.now();\n        raf = requestAnimationFrame(loop);\n      }\n    });\n    io.observe(canvas);\n    const host = canvas.parentElement ?? canvas;\n    host.addEventListener(\"pointermove\", onMove, { passive: true });\n    host.addEventListener(\"pointerleave\", onLeave);\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      host.removeEventListener(\"pointermove\", onMove);\n      host.removeEventListener(\"pointerleave\", onLeave);\n    };\n  }, [rings, colorFrom, colorTo, speed, pull, lineWidth]);\n\n  return (\n    <canvas\n      ref={ref}\n      aria-hidden\n      className={cn(\"pointer-events-none\", className)}\n      style={{ position: \"absolute\", inset: 0, width: \"100%\", height: \"100%\" }}\n    />\n  );\n}\n"}]}