{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"glare-hover","type":"registry:ui","title":"Glare Hover","description":"A wrapper that sweeps a band of light across its content on hover and on keyboard focus.","dependencies":["motion"],"registryDependencies":["https://ui.mekaigames.com/r/theme.json"],"files":[{"path":"components/ui/glare-hover.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useAnimate, useReducedMotion } from \"motion/react\";\nimport { useEffect, useEffectEvent, type FocusEvent, type ReactNode } from \"react\";\n\ntype GlareHoverProps = {\n  children: ReactNode;\n  /** Direction of the sweep in degrees, as in a CSS linear-gradient. */\n  angle?: number;\n  /** Width of the band of light, roughly as a percentage of the element. */\n  width?: number;\n  /** Color of the light. */\n  color?: string;\n  /** Strength of the light, from 0 to 1. */\n  opacity?: number;\n  /** Length of one sweep, in seconds. */\n  duration?: number;\n  /** Sweep once shortly after the component mounts. */\n  playOnMount?: boolean;\n  className?: string;\n};\n\n/** Where the band starts on one axis, so it begins fully outside the element. */\nconst startOn = (v: number) => (Math.abs(v) < 0.01 ? 50 : v > 0 ? 100 : 0);\n\n/** A wrapper that sweeps a band of light across its content on hover and on keyboard focus. */\nexport function GlareHover({\n  children,\n  angle = 120,\n  width = 30,\n  color = \"#f4ede3\",\n  opacity = 0.35,\n  duration = 0.8,\n  playOnMount = false,\n  className = \"\",\n}: GlareHoverProps) {\n  const reduce = useReducedMotion();\n  const [glare, animate] = useAnimate<HTMLSpanElement>();\n\n  // The gradient is 2.5 times the element, so moving its position walks the band across and off the other side.\n  const rad = (angle * Math.PI) / 180;\n  const sx = startOn(Math.sin(rad));\n  const sy = startOn(-Math.cos(rad));\n  const from = `${sx}% ${sy}%`;\n  const to = `${100 - sx}% ${100 - sy}%`;\n  const half = Math.max(1, width) / 5;\n  const band = `linear-gradient(${angle}deg, transparent ${50 - half}%, ${color} 50%, transparent ${50 + half}%)`;\n\n  function play() {\n    const el = glare.current;\n    if (!el) return;\n    if (reduce) {\n      // No travelling light: a soft glow fades in and out in place.\n      animate(el, { opacity: [0, opacity * 0.6, 0] }, { duration: 0.6 });\n      return;\n    }\n    animate(el, { backgroundPosition: [from, to] }, { duration, ease: [0.3, 0.1, 0.25, 1] });\n  }\n\n  const playOnce = useEffectEvent(play);\n  useEffect(() => {\n    if (!playOnMount) return;\n    const timer = window.setTimeout(playOnce, 300);\n    return () => window.clearTimeout(timer);\n  }, [playOnMount]);\n\n  function onFocus(e: FocusEvent<HTMLDivElement>) {\n    if (e.target instanceof Element && e.target.matches(\":focus-visible\")) play();\n  }\n\n  return (\n    <div className={`relative isolate ${className}`} onPointerEnter={play} onFocus={onFocus}>\n      {children}\n      <span\n        ref={glare}\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute inset-0 z-10 rounded-[inherit]\"\n        style={{\n          backgroundImage: band,\n          backgroundSize: \"250% 250%\",\n          backgroundRepeat: \"no-repeat\",\n          backgroundPosition: reduce ? \"50% 50%\" : from,\n          opacity: reduce ? 0 : opacity,\n        }}\n      />\n    </div>\n  );\n}\n"}]}