{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "spotlight-card",
  "type": "registry:component",
  "title": "Spotlight Card",
  "description": "A card lit by a soft radial spotlight that follows the pointer and catches the border. Wrap several in SpotlightGroup and one light spans the whole row.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "hover",
    "card",
    "spotlight",
    "hover",
    "pointer",
    "border",
    "glow"
  ],
  "docs": "https://hyperblur.dev/effects/spotlight-card",
  "files": [
    {
      "path": "registry/hyperblur/spotlight-card.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/spotlight-card.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface SpotlightCardProps extends React.HTMLAttributes<HTMLDivElement> {\n  children?: React.ReactNode;\n  color?: string;\n  size?: number;\n  radius?: number;\n  borderWidth?: number;\n  idle?: number;\n}\n\nexport interface SpotlightGroupProps extends React.HTMLAttributes<HTMLDivElement> {\n  children?: React.ReactNode;\n}\n\nconst css = `\n.hb-spc {\n  --hb-spc-x: 50%;\n  --hb-spc-y: 0%;\n  position: relative;\n  box-sizing: border-box;\n  isolation: isolate;\n  overflow: hidden;\n  border-radius: var(--hb-spc-r);\n  background: #0f0f10;\n  color: #ededed;\n  font-family: inherit;\n  box-shadow: inset 0 0 0 var(--hb-spc-bw) rgba(255, 255, 255, 0.07);\n}\n.hb-spc *, .hb-spc *::before, .hb-spc *::after { box-sizing: border-box; }\n.hb-spc::before, .hb-spc::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  border-radius: inherit;\n  pointer-events: none;\n  opacity: 0;\n  transition: opacity .45s ease;\n}\n.hb-spc::before {\n  z-index: -1;\n  background: radial-gradient(var(--hb-spc-sz) circle at var(--hb-spc-x) var(--hb-spc-y), color-mix(in srgb, var(--hb-spc-c) 20%, transparent), transparent 70%);\n}\n.hb-spc::after {\n  z-index: 2;\n  padding: var(--hb-spc-bw);\n  background: radial-gradient(calc(var(--hb-spc-sz) * 0.75) circle at var(--hb-spc-x) var(--hb-spc-y), var(--hb-spc-c), color-mix(in srgb, var(--hb-spc-c) 30%, transparent) 40%, transparent 72%);\n  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);\n  -webkit-mask-composite: xor;\n  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);\n}\n.hb-spc::before { opacity: var(--hb-spc-idle); }\n.hb-spc::after { opacity: calc(var(--hb-spc-idle) * 0.8); }\n.hb-spc[data-on]::before, .hb-spc[data-on]::after { opacity: 1; transition: opacity .2s ease; }\n.hb-spc-group { position: relative; }\n@media (hover: none) {\n  .hb-spc::before, .hb-spc::after { opacity: 1; }\n  .hb-spc::before {\n    background: radial-gradient(var(--hb-spc-sz) circle at 30% 0%, color-mix(in srgb, var(--hb-spc-c) 14%, transparent), transparent 70%);\n  }\n  .hb-spc::after {\n    background: radial-gradient(calc(var(--hb-spc-sz) * 0.75) circle at 30% 0%, var(--hb-spc-c), color-mix(in srgb, var(--hb-spc-c) 25%, transparent) 40%, transparent 72%);\n  }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-spc::before, .hb-spc::after { transition: none; }\n}\n`;\n\nconst GroupContext = React.createContext(false);\n\nfunction unlight(card: HTMLElement) {\n  card.removeAttribute(\"data-on\");\n  card.style.removeProperty(\"--hb-spc-x\");\n  card.style.removeProperty(\"--hb-spc-y\");\n}\n\nfunction place(card: HTMLElement, x: number, y: number) {\n  const r = card.getBoundingClientRect();\n  card.style.setProperty(\"--hb-spc-x\", `${(x - r.left).toFixed(1)}px`);\n  card.style.setProperty(\"--hb-spc-y\", `${(y - r.top).toFixed(1)}px`);\n}\n\nfunction useRafPointer(apply: (x: number, y: number) => void) {\n  const frame = React.useRef(0);\n  const point = React.useRef({ x: 0, y: 0 });\n  const latest = React.useRef(apply);\n\n  React.useEffect(() => {\n    latest.current = apply;\n  });\n\n  React.useEffect(() => () => cancelAnimationFrame(frame.current), []);\n\n  return React.useCallback((x: number, y: number) => {\n    point.current = { x, y };\n    if (frame.current) return;\n    frame.current = requestAnimationFrame(() => {\n      frame.current = 0;\n      latest.current(point.current.x, point.current.y);\n    });\n  }, []);\n}\n\nexport function SpotlightGroup({\n  children,\n  className = \"\",\n  onPointerMove,\n  onPointerLeave,\n  ...rest\n}: SpotlightGroupProps) {\n  const ref = React.useRef<HTMLDivElement>(null);\n\n  const schedule = useRafPointer((x, y) => {\n    const el = ref.current;\n    if (!el) return;\n    el.querySelectorAll<HTMLElement>(\".hb-spc\").forEach((card) => {\n      place(card, x, y);\n      card.setAttribute(\"data-on\", \"\");\n    });\n  });\n\n  function handleMove(e: React.PointerEvent<HTMLDivElement>) {\n    onPointerMove?.(e);\n    if (e.pointerType === \"touch\") return;\n    schedule(e.clientX, e.clientY);\n  }\n\n  function handleLeave(e: React.PointerEvent<HTMLDivElement>) {\n    onPointerLeave?.(e);\n    const el = ref.current;\n    if (!el) return;\n    el.querySelectorAll<HTMLElement>(\".hb-spc\").forEach(unlight);\n  }\n\n  return (\n    <GroupContext.Provider value={true}>\n      <div ref={ref} className={`hb-spc-group ${className}`} onPointerMove={handleMove} onPointerLeave={handleLeave} {...rest}>\n        {children}\n      </div>\n    </GroupContext.Provider>\n  );\n}\n\nexport function SpotlightCard({\n  children,\n  color = \"#7fb3ff\",\n  size = 320,\n  radius = 16,\n  borderWidth = 1,\n  idle = 0.35,\n  className = \"\",\n  style,\n  onPointerMove,\n  onPointerLeave,\n  ...rest\n}: SpotlightCardProps) {\n  const grouped = React.useContext(GroupContext);\n  const ref = React.useRef<HTMLDivElement>(null);\n\n  const schedule = useRafPointer((x, y) => {\n    const el = ref.current;\n    if (!el) return;\n    place(el, x, y);\n    el.setAttribute(\"data-on\", \"\");\n  });\n\n  function handleMove(e: React.PointerEvent<HTMLDivElement>) {\n    onPointerMove?.(e);\n    if (grouped || e.pointerType === \"touch\") return;\n    schedule(e.clientX, e.clientY);\n  }\n\n  function handleLeave(e: React.PointerEvent<HTMLDivElement>) {\n    onPointerLeave?.(e);\n    if (grouped) return;\n    if (ref.current) unlight(ref.current);\n  }\n\n  const vars = {\n    \"--hb-spc-c\": color,\n    \"--hb-spc-sz\": `${Math.max(40, size)}px`,\n    \"--hb-spc-r\": `${Math.max(0, radius)}px`,\n    \"--hb-spc-bw\": `${Math.max(0, borderWidth)}px`,\n    \"--hb-spc-idle\": Math.min(1, Math.max(0, idle)).toFixed(2),\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <div ref={ref} className={`hb-spc ${className}`} style={vars} onPointerMove={handleMove} onPointerLeave={handleLeave} {...rest}>\n      <style href=\"hb-spotlight-card\" precedence=\"default\">{css}</style>\n      {children}\n    </div>\n  );\n}\n"
    }
  ]
}