{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "motion-spotlight-cards",
  "title": "Spotlight cards",
  "description": "A grid of link cards where a soft light follows the mouse and lights the hairline borders nearby.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "components/core/spotlight-cards.tsx",
      "content": "'use client';\n\nimport {\n  motion,\n  type MotionValue,\n  useMotionTemplate,\n  useMotionValue,\n  useSpring,\n  useTransform,\n} from 'motion/react';\nimport { createContext, useContext, useRef, useState } from 'react';\n\nimport { cn } from '@/lib/utils';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\n\nexport type SpotlightTint = 'neutral' | 'primary';\n\ntype SpotlightContextValue = {\n  pointerX: MotionValue<number>;\n  pointerY: MotionValue<number>;\n  tint: SpotlightTint;\n};\n\nconst SpotlightContext = createContext<SpotlightContextValue | null>(null);\n\nfunction useSpotlight() {\n  const context = useContext(SpotlightContext);\n  if (!context) {\n    throw new Error('SpotlightCard must be used inside SpotlightCards');\n  }\n  return context;\n}\n\nconst FOLLOW_SPRING = { stiffness: 600, damping: 50 };\n\nconst EDGE_RADIUS = 220;\n\nconst FILL_RADIUS = 320;\n\nconst TINT_COLORS = {\n  neutral: {\n    edge: 'color-mix(in oklab, var(--foreground) 32%, transparent)',\n    fill: 'color-mix(in oklab, var(--foreground) 3%, transparent)',\n  },\n  primary: {\n    edge: 'color-mix(in oklab, var(--primary) 60%, transparent)',\n    fill: 'color-mix(in oklab, var(--primary) 5%, transparent)',\n  },\n} satisfies Record<SpotlightTint, { edge: string; fill: string }>;\n\nfunction isMouse(event: React.PointerEvent) {\n  return event.pointerType === 'mouse';\n}\n\ntype PointerValues = {\n  x: MotionValue<number>;\n  y: MotionValue<number>;\n};\n\nfunction followedPointerOf(\n  prefersReducedMotion: boolean | null,\n  raw: PointerValues,\n  smooth: PointerValues\n) {\n  if (prefersReducedMotion) {\n    return raw;\n  }\n  return smooth;\n}\n\nexport type SpotlightCardsProps = React.ComponentProps<'div'> & {\n  tint?: SpotlightTint;\n};\n\nexport function SpotlightCards({\n  tint = 'primary',\n  className,\n  children,\n  onPointerMove,\n  onPointerLeave,\n  ...props\n}: SpotlightCardsProps) {\n  const prefersReducedMotion = usePrefersReducedMotion();\n  const [isLit, setIsLit] = useState(false);\n  const rawX = useMotionValue(0);\n  const rawY = useMotionValue(0);\n  const smoothX = useSpring(rawX, FOLLOW_SPRING);\n  const smoothY = useSpring(rawY, FOLLOW_SPRING);\n  const followed = followedPointerOf(\n    prefersReducedMotion,\n    { x: rawX, y: rawY },\n    { x: smoothX, y: smoothY }\n  );\n\n  function follow(event: React.PointerEvent<HTMLDivElement>) {\n    onPointerMove?.(event);\n    if (!isMouse(event)) {\n      return;\n    }\n    rawX.set(event.clientX);\n    rawY.set(event.clientY);\n    if (isLit) {\n      return;\n    }\n    smoothX.jump(event.clientX);\n    smoothY.jump(event.clientY);\n    setIsLit(true);\n  }\n\n  function dim(event: React.PointerEvent<HTMLDivElement>) {\n    onPointerLeave?.(event);\n    setIsLit(false);\n  }\n\n  return (\n    <SpotlightContext.Provider\n      value={{ pointerX: followed.x, pointerY: followed.y, tint }}\n    >\n      <div\n        data-lit={isLit}\n        className={cn('group/spotlight grid gap-3', className)}\n        onPointerMove={follow}\n        onPointerLeave={dim}\n        {...props}\n      >\n        {children}\n      </div>\n    </SpotlightContext.Provider>\n  );\n}\n\nfunction leftOf(element: HTMLElement | null) {\n  if (!element) {\n    return 0;\n  }\n  return element.getBoundingClientRect().left;\n}\n\nfunction topOf(element: HTMLElement | null) {\n  if (!element) {\n    return 0;\n  }\n  return element.getBoundingClientRect().top;\n}\n\nconst LIGHT_LAYER = [\n  'pointer-events-none absolute rounded-[inherit] opacity-0',\n  'transition-opacity duration-150 ease-(--ease-out-strong)',\n  'group-data-[lit=true]/spotlight:opacity-100 group-data-[lit=true]/spotlight:duration-300',\n].join(' ');\n\nconst EDGE_SHAPE = {\n  inset: 'calc(var(--hairline) * -1)',\n  padding: 'var(--hairline)',\n  mask: 'linear-gradient(black, black) content-box exclude, linear-gradient(black, black)',\n  WebkitMask:\n    'linear-gradient(black, black) content-box xor, linear-gradient(black, black)',\n};\n\nconst CARD = [\n  'group/card relative isolate block rounded-xl bg-card text-card-foreground',\n  'hairline-ring ring-border shadow-[0_1px_2px_rgb(0_0_0/0.04)]',\n  'cursor-pointer outline-none transition-[scale] duration-150 ease-(--ease-out-strong) active:scale-[0.97]',\n  'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring',\n].join(' ');\n\nexport type SpotlightCardProps = React.ComponentProps<'a'>;\n\nexport function SpotlightCard({\n  className,\n  children,\n  ...props\n}: SpotlightCardProps) {\n  const { pointerX, pointerY, tint } = useSpotlight();\n  const cardRef = useRef<HTMLAnchorElement>(null);\n  const localX = useTransform(() => {\n    const pointer = pointerX.get();\n    const left = leftOf(cardRef.current);\n    return pointer - left;\n  });\n  const localY = useTransform(() => {\n    const pointer = pointerY.get();\n    const top = topOf(cardRef.current);\n    return pointer - top;\n  });\n  const colors = TINT_COLORS[tint];\n  const edgeLight = useMotionTemplate`radial-gradient(${EDGE_RADIUS}px circle at ${localX}px ${localY}px, ${colors.edge}, transparent)`;\n  const fillLight = useMotionTemplate`radial-gradient(${FILL_RADIUS}px circle at ${localX}px ${localY}px, ${colors.fill}, transparent)`;\n\n  return (\n    <a ref={cardRef} className={cn(CARD, className)} {...props}>\n      <motion.span\n        aria-hidden='true'\n        className={cn(LIGHT_LAYER, 'inset-0')}\n        style={{ background: fillLight }}\n      />\n      <motion.span\n        aria-hidden='true'\n        className={LIGHT_LAYER}\n        style={{ background: edgeLight, ...EDGE_SHAPE }}\n      />\n      <div className='relative flex h-full flex-col'>{children}</div>\n    </a>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/core/spotlight-cards.tsx"
    }
  ],
  "categories": [
    "motion"
  ],
  "type": "registry:component"
}