{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "orbiting-border-glow",
  "title": "Orbiting Border Glow",
  "description": "A border that a beam of light runs around: a bright conic streak orbits the edge of any card, button or badge, a soft halo of the same light spills outside it, and the beam picks up speed smoothly while you hover.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/orbiting-border-glow/orbiting-border-glow.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface OrbitingBorderGlowProps extends React.ComponentPropsWithoutRef<\"div\"> {\n  /** Beam colours, from its tail to its head. */\n  colors?: [string, string];\n  /** Seconds for one lap. */\n  duration?: number;\n  /** Seconds for one lap while hovered or focused. */\n  hoverDuration?: number;\n  /** Border width in px. */\n  width?: number;\n  /** How far the glow spills outside, in px. 0 turns it off. */\n  glow?: number;\n  /** Two beams on opposite sides instead of one. */\n  twin?: boolean;\n  radius?: number;\n  /** The fill inside the border. */\n  background?: string;\n  /** Colour of the resting border the beam travels along. */\n  track?: string;\n}\n\n// Shows only the padding box: the content box is masked out, leaving a ring.\nconst RING: React.CSSProperties = {\n  mask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n  maskComposite: \"exclude\",\n  WebkitMask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n  WebkitMaskComposite: \"xor\",\n};\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nexport function OrbitingBorderGlow({\n  colors = [\"#7b61ff\", \"#38bdf8\"],\n  duration = 4,\n  hoverDuration = 1.6,\n  width = 1.5,\n  glow = 18,\n  twin = false,\n  radius = 20,\n  background = \"#0f0f11\",\n  track = \"rgba(255,255,255,0.08)\",\n  className,\n  style,\n  children,\n  ...props\n}: OrbitingBorderGlowProps) {\n  const [tail, head] = colors;\n  const reduce = useReducedMotion();\n  const spinners = React.useRef<(HTMLSpanElement | null)[]>([]);\n  const hovered = React.useRef(false);\n  const laps = React.useRef({ duration, hoverDuration });\n  React.useEffect(() => {\n    laps.current = { duration, hoverDuration };\n  }, [duration, hoverDuration]);\n\n  // Spin in JavaScript so the speed can ease up and down on hover without the beam jumping, and only while on screen.\n  React.useEffect(() => {\n    const el = rootRef.current;\n    if (!el || reduce) return;\n    let raf = 0;\n    let angle = 200;\n    let speed = 360 / laps.current.duration;\n    let last = 0;\n    let visible = true;\n    const tick = (now: number) => {\n      const dt = Math.min(0.05, last ? (now - last) / 1000 : 1 / 60);\n      last = now;\n      const target = 360 / (hovered.current ? laps.current.hoverDuration : laps.current.duration);\n      speed += (target - speed) * (1 - Math.exp(-dt * 4));\n      angle = (angle + speed * dt) % 360;\n      for (const sp of spinners.current) if (sp) sp.style.transform = `translate(-50%, -50%) rotate(${angle.toFixed(2)}deg)`;\n      if (visible && !document.hidden) raf = requestAnimationFrame(tick);\n      else last = 0;\n    };\n    const start = () => {\n      cancelAnimationFrame(raf);\n      raf = requestAnimationFrame(tick);\n    };\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible) start();\n    });\n    io.observe(el);\n    const onVis = () => !document.hidden && visible && start();\n    document.addEventListener(\"visibilitychange\", onVis);\n    start();\n    return () => {\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      document.removeEventListener(\"visibilitychange\", onVis);\n    };\n  }, [reduce]);\n  // The spinning square must cover the element's diagonal (plus the glow), and no more: it's redrawn every frame.\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const [size, setSize] = React.useState(0);\n  React.useEffect(() => {\n    const el = rootRef.current;\n    if (!el) return;\n    const observer = new ResizeObserver(() => setSize(Math.ceil(Math.hypot(el.offsetWidth, el.offsetHeight) + glow * 2 + 8)));\n    observer.observe(el);\n    return () => observer.disconnect();\n  }, [glow]);\n  // One conic beam (or two, opposite each other): transparent, then the tail fading into a bright head.\n  const beam = twin\n    ? `conic-gradient(from 0deg, transparent 0deg, ${tail} 50deg, ${head} 82deg, transparent 90deg, transparent 180deg, ${tail} 230deg, ${head} 262deg, transparent 270deg)`\n    : `conic-gradient(from 0deg, transparent 0deg, transparent 230deg, ${tail} 300deg, ${head} 352deg, transparent 360deg)`;\n  const spinner = (i: number, extra?: React.CSSProperties) => (\n    <span\n      ref={(el) => {\n        spinners.current[i] = el;\n      }}\n      aria-hidden=\"true\"\n      className=\"absolute top-1/2 left-1/2 max-w-none\"\n      style={{ width: size, height: size, background: beam, transform: \"translate(-50%, -50%) rotate(200deg)\", ...extra }}\n    />\n  );\n\n  return (\n    <div\n      ref={rootRef}\n      className={cn(\"group/orbit relative isolate\", className)}\n      style={{ borderRadius: radius, padding: width, ...style }}\n      onPointerEnter={() => (hovered.current = true)}\n      onPointerLeave={() => (hovered.current = false)}\n      onFocusCapture={() => (hovered.current = true)}\n      onBlurCapture={() => (hovered.current = false)}\n      {...props}\n    >\n      {/* Halo: a blurred copy of a thicker beam ring. The blur sits on a wrapper, so it applies after the ring's\n          mask and the light spreads softly outward from exactly where the beam is. */}\n      {glow > 0 && (\n        <span aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 -z-10\" style={{ filter: `blur(${glow * 0.55}px)`, opacity: 1 }}>\n          <span className=\"absolute inset-0 overflow-hidden\" style={{ borderRadius: radius, padding: Math.max(5, width * 4), ...RING }}>\n            {spinner(0)}\n          </span>\n        </span>\n      )}\n      {/* Border: the beam shows only in a ring of the given width, masked out of the middle. */}\n      <span\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute inset-0 overflow-hidden\"\n        style={{\n          borderRadius: radius,\n          padding: width,\n          background: track,\n          ...RING,\n        }}\n      >\n        {spinner(1)}\n      </span>\n      <div className=\"relative h-full\" style={{ borderRadius: Math.max(0, radius - width), background }}>\n        {children}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}