{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hover-reveal",
  "title": "Hover Reveal",
  "description": "A second layer seen through a soft circle that follows the pointer.",
  "registryDependencies": [
    "@corsair-ui/utils"
  ],
  "files": [
    {
      "path": "registry/default/ui/hover-reveal.tsx",
      "content": "\"use client\";\n\nimport {\n  useEffect,\n  useMemo,\n  useRef,\n  useState,\n  type ComponentProps,\n  type CSSProperties,\n  type PointerEvent,\n  type ReactNode,\n  type Ref,\n} from \"react\";\nimport { cn } from \"@/registry/default/lib/utils\";\n\nfunction mergeRefs<T>(...refs: (Ref<T> | undefined)[]) {\n  return (node: T | null) => {\n    for (const ref of refs) {\n      if (typeof ref === \"function\") ref(node);\n      else if (ref) ref.current = node;\n    }\n  };\n}\n\nfunction prefersReducedMotion() {\n  return window.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches === true;\n}\n\n// How quickly the circle grows and shrinks: the time constant of an ease-out, in ms.\nconst EASE_MS = 90;\n\ninterface HoverRevealProps extends ComponentProps<\"div\"> {\n  /** The layer shown through the circle. Decorative: it is hidden from screen readers. */\n  reveal: ReactNode;\n  /** Radius of the circle, in px. */\n  radius?: number;\n  /** From 0 to 1: 0 gives a crisp edge, 1 fades from the centre out. */\n  softness?: number;\n  /** Classes for the revealed layer. */\n  revealClassName?: string;\n}\n\n/**\n * A second layer seen through a soft circle that follows the pointer: a\n * photo under a sketch, colour under greyscale, the answer under the\n * question. The circle opens when the pointer comes in and closes when it\n * leaves; it moves by writing CSS variables once per frame, so nothing\n * re-renders. Touch screens only see the base layer. The revealed layer is\n * hidden from screen readers and cannot take focus or clicks, so the base\n * (`children`) has to carry the meaning. With `prefers-reduced-motion` the\n * circle opens and closes at once.\n *\n * @example\n * <HoverReveal\n *   className=\"aspect-video rounded-xl\"\n *   reveal={<img src=\"/chart-colour.jpg\" alt=\"\" className=\"size-full object-cover\" />}\n * >\n *   <img src=\"/chart-sketch.jpg\" alt=\"A sea chart of the bay\" className=\"size-full object-cover\" />\n * </HoverReveal>\n */\nfunction HoverReveal({\n  reveal,\n  radius = 120,\n  softness = 0.4,\n  revealClassName,\n  className,\n  children,\n  onPointerEnter,\n  onPointerMove,\n  onPointerLeave,\n  ref,\n  ...props\n}: HoverRevealProps) {\n  const [active, setActive] = useState(false);\n  const root = useRef<HTMLDivElement>(null);\n  const mergedRef = useMemo(() => mergeRefs(ref, root), [ref]);\n  const frame = useRef(0);\n  const motion = useRef({ x: 0, y: 0, r: 0, target: 0, last: 0 });\n\n  useEffect(() => () => cancelAnimationFrame(frame.current), []);\n\n  // Grows or shrinks the circle toward its target, and writes the position.\n  const tick = (now: number) => {\n    frame.current = 0;\n    const node = root.current;\n    if (!node) return;\n    const state = motion.current;\n    const elapsed = state.last ? now - state.last : 16;\n    state.last = now;\n    state.r += (state.target - state.r) * (1 - Math.exp(-elapsed / EASE_MS));\n    if (Math.abs(state.target - state.r) < 0.5) state.r = state.target;\n    node.style.setProperty(\"--hover-reveal-x\", `${state.x}px`);\n    node.style.setProperty(\"--hover-reveal-y\", `${state.y}px`);\n    node.style.setProperty(\"--hover-reveal-r\", `${state.r}px`);\n    if (state.r !== state.target) frame.current = requestAnimationFrame(tick);\n    else state.last = 0;\n  };\n\n  const schedule = () => {\n    if (!frame.current) frame.current = requestAnimationFrame(tick);\n  };\n\n  const track = (event: PointerEvent<HTMLDivElement>) => {\n    const bounds = event.currentTarget.getBoundingClientRect();\n    motion.current.x = event.clientX - bounds.left;\n    motion.current.y = event.clientY - bounds.top;\n  };\n\n  const handlePointerEnter = (event: PointerEvent<HTMLDivElement>) => {\n    onPointerEnter?.(event);\n    if (event.pointerType === \"touch\") return;\n    track(event);\n    motion.current.target = radius;\n    if (prefersReducedMotion()) motion.current.r = radius;\n    setActive(true);\n    schedule();\n  };\n\n  const handlePointerMove = (event: PointerEvent<HTMLDivElement>) => {\n    onPointerMove?.(event);\n    if (event.pointerType === \"touch\") return;\n    track(event);\n    // A pointer that was already inside when the page loaded never \"entered\".\n    if (!active) {\n      motion.current.target = radius;\n      if (prefersReducedMotion()) motion.current.r = radius;\n      setActive(true);\n    }\n    schedule();\n  };\n\n  const handlePointerLeave = (event: PointerEvent<HTMLDivElement>) => {\n    onPointerLeave?.(event);\n    if (event.pointerType === \"touch\") return;\n    motion.current.target = 0;\n    if (prefersReducedMotion()) motion.current.r = 0;\n    setActive(false);\n    schedule();\n  };\n\n  const edge = Math.round((1 - Math.min(Math.max(softness, 0), 1)) * 100);\n  const mask = `radial-gradient(circle var(--hover-reveal-r, 0px) at var(--hover-reveal-x, 50%) var(--hover-reveal-y, 50%), #000 ${edge}%, transparent 100%)`;\n\n  return (\n    <div\n      ref={mergedRef}\n      data-slot=\"hover-reveal\"\n      data-state={active ? \"active\" : \"idle\"}\n      className={cn(\"relative isolate overflow-hidden\", className)}\n      onPointerEnter={handlePointerEnter}\n      onPointerMove={handlePointerMove}\n      onPointerLeave={handlePointerLeave}\n      {...props}\n    >\n      {children}\n      <div\n        aria-hidden=\"true\"\n        inert\n        data-slot=\"hover-reveal-layer\"\n        className={cn(\"pointer-events-none absolute inset-0\", revealClassName)}\n        style={{ maskImage: mask, WebkitMaskImage: mask } as CSSProperties}\n      >\n        {reveal}\n      </div>\n    </div>\n  );\n}\n\nexport { HoverReveal, type HoverRevealProps };\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "creative"
  ],
  "type": "registry:ui"
}