{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"text-spotlight","type":"registry:ui","title":"Text Spotlight","description":"Dimmed text with a soft, gradient-lit spotlight that trails your cursor and drifts on its own when idle.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/text-spotlight.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef, type CSSProperties } from \"react\";\n\nexport interface TextSpotlightProps {\n  text: string;\n  /** Spotlight radius, in px. */\n  radius?: number;\n  /** Opacity of the unlit text, 0–1. */\n  dim?: number;\n  /** Lit gradient start color. */\n  from?: string;\n  /** Lit gradient end color. */\n  to?: string;\n  /** Follow lag, 0 = instant, closer to 1 = floatier. */\n  smoothing?: number;\n  /** Drift the light on its own while the pointer is away. */\n  autoPlay?: boolean;\n  className?: string;\n}\n\nexport function TextSpotlight({\n  text,\n  radius = 180,\n  dim = 0.14,\n  from = \"#a3e635\",\n  to = \"#22d3ee\",\n  smoothing = 0.85,\n  autoPlay = true,\n  className,\n}: TextSpotlightProps) {\n  const root = useRef<HTMLDivElement>(null);\n  const opts = useRef({ smoothing, autoPlay });\n  useEffect(() => {\n    opts.current = { smoothing, autoPlay };\n  }, [smoothing, autoPlay]);\n\n  useEffect(() => {\n    const el = root.current;\n    if (!el) return;\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const cur = { x: -9999, y: -9999, o: 0 };\n    const target = { x: 0, y: 0, inside: false };\n    let raf = 0;\n\n    const onMove = (e: PointerEvent) => {\n      const r = el.getBoundingClientRect();\n      target.x = e.clientX - r.left;\n      target.y = e.clientY - r.top;\n      if (!target.inside && cur.o < 0.05) {\n        cur.x = target.x;\n        cur.y = target.y;\n      }\n      target.inside = true;\n    };\n    const onLeave = () => (target.inside = false);\n\n    const tick = (t: number) => {\n      raf = requestAnimationFrame(tick);\n      const { smoothing: s, autoPlay: auto } = opts.current;\n      const w = el.offsetWidth;\n      const h = el.offsetHeight;\n      if (!target.inside && auto) {\n        const k = reduced ? 0 : t / 1000;\n        target.x = w * (0.5 + 0.42 * Math.sin(k * 0.55));\n        target.y = h * (0.5 + 0.38 * Math.sin(k * 0.9 + 1.3));\n        if (cur.x < -999) {\n          cur.x = target.x;\n          cur.y = target.y;\n        }\n      }\n      const f = reduced ? 1 : 1 - Math.min(Math.max(s, 0), 0.98);\n      cur.x += (target.x - cur.x) * f;\n      cur.y += (target.y - cur.y) * f;\n      cur.o += ((target.inside || auto ? 1 : 0) - cur.o) * 0.08;\n      el.style.setProperty(\"--ts-x\", `${cur.x.toFixed(1)}px`);\n      el.style.setProperty(\"--ts-y\", `${cur.y.toFixed(1)}px`);\n      el.style.setProperty(\"--ts-o\", cur.o.toFixed(3));\n    };\n    const io = new IntersectionObserver(([e]) => {\n      cancelAnimationFrame(raf);\n      if (e.isIntersecting) raf = requestAnimationFrame(tick);\n    });\n    el.addEventListener(\"pointermove\", onMove);\n    el.addEventListener(\"pointerleave\", onLeave);\n    io.observe(el);\n    return () => {\n      io.disconnect();\n      cancelAnimationFrame(raf);\n      el.removeEventListener(\"pointermove\", onMove);\n      el.removeEventListener(\"pointerleave\", onLeave);\n    };\n  }, []);\n\n  const mask = `radial-gradient(circle ${radius}px at var(--ts-x) var(--ts-y), #000 0%, rgba(0,0,0,.6) 45%, transparent 100%)`;\n\n  return (\n    <div\n      ref={root}\n      className={className}\n      style={{ position: \"relative\", \"--ts-x\": \"-9999px\", \"--ts-y\": \"-9999px\", \"--ts-o\": 0 } as CSSProperties}\n    >\n      <span className=\"sr-only\">{text}</span>\n      <span aria-hidden style={{ opacity: dim }}>\n        {text}\n      </span>\n      <span\n        aria-hidden\n        style={{\n          position: \"absolute\",\n          inset: 0,\n          pointerEvents: \"none\",\n          color: \"transparent\",\n          backgroundImage: `linear-gradient(120deg, ${from}, ${to})`,\n          WebkitBackgroundClip: \"text\",\n          backgroundClip: \"text\",\n          WebkitMaskImage: mask,\n          maskImage: mask,\n          opacity: \"var(--ts-o)\",\n          filter: `drop-shadow(0 0 16px color-mix(in srgb, ${from} 45%, transparent))`,\n        }}\n      >\n        {text}\n      </span>\n    </div>\n  );\n}\n"}]}