{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tilt-card",
  "title": "Tilt Card",
  "description": "A card that tilts toward the pointer, with layers at different depths and a glare spot.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://spotcheckui.com/r/spotcheck-base.json",
    "https://spotcheckui.com/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/spotcheck/components/spotcheck/tilt-card.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { motion, useMotionTemplate, useMotionValue, useSpring, useTransform } from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { useReducedMotion } from \"@/registry/spotcheck/hooks/use-reduced-motion\"\n\nconst MAX_TILT_X = 18\nconst MAX_TILT_Y = 22\nconst SPRING = { stiffness: 200, damping: 16 }\nconst GLARE_RANGE = 14\nconst MAX_GLARE = 0.9\nconst HOVER_QUERY = \"(hover: hover) and (pointer: fine)\"\n\nconst TiltContext = React.createContext(false)\n\nfunction subscribeToHover(onChange: () => void) {\n  const media = window.matchMedia(HOVER_QUERY)\n  media.addEventListener(\"change\", onChange)\n  return () => media.removeEventListener(\"change\", onChange)\n}\n\nfunction useCanHover() {\n  return React.useSyncExternalStore(\n    subscribeToHover,\n    () => window.matchMedia(HOVER_QUERY).matches,\n    () => false,\n  )\n}\n\n/** Degrees to tilt for a pointer at fractions of the stage, from -0.5 to 0.5 on each side. */\nexport function tiltFor(pointerX: number, pointerY: number) {\n  return { x: -pointerY * MAX_TILT_X, y: pointerX * MAX_TILT_Y }\n}\n\ntype TiltCardProps = React.ComponentProps<\"div\">\n\nexport function TiltCard({ className, children, ...props }: TiltCardProps) {\n  const reduced = useReducedMotion()\n  const canHover = useCanHover()\n  const flat = reduced || !canHover\n\n  const stage = React.useRef<HTMLDivElement>(null)\n  const targetX = useMotionValue(0)\n  const targetY = useMotionValue(0)\n  const glareX = useMotionValue(50)\n  const glareY = useMotionValue(50)\n  const rotateX = useSpring(targetX, SPRING)\n  const rotateY = useSpring(targetY, SPRING)\n  const glare = useTransform(() => Math.min(MAX_GLARE, (Math.abs(rotateX.get()) + Math.abs(rotateY.get())) / GLARE_RANGE))\n  const background = useMotionTemplate`radial-gradient(circle at ${glareX}% ${glareY}%, color-mix(in srgb, var(--highlight) 42%, transparent), transparent 58%)`\n\n  const onPointerMove = (event: React.PointerEvent<HTMLDivElement>) => {\n    const box = stage.current?.getBoundingClientRect()\n    if (flat || event.pointerType === \"touch\" || !box || box.width === 0) return\n    const fractionX = (event.clientX - box.left) / box.width - 0.5\n    const fractionY = (event.clientY - box.top) / box.height - 0.5\n    const tilt = tiltFor(fractionX, fractionY)\n    targetX.set(tilt.x)\n    targetY.set(tilt.y)\n    glareX.set((fractionX + 0.5) * 100)\n    glareY.set((fractionY + 0.5) * 100)\n  }\n\n  const onPointerLeave = () => {\n    targetX.set(0)\n    targetY.set(0)\n  }\n\n  return (\n    <TiltContext.Provider value={flat}>\n      <div\n        ref={stage}\n        className={cn(\"grid min-w-0 touch-pan-y place-items-center px-2 pt-5.5 pb-2.5 font-(family-name:--f-body)\", !flat && \"perspective-[900px]\")}\n        onPointerMove={onPointerMove}\n        onPointerLeave={onPointerLeave}\n      >\n        <motion.div\n          data-testid=\"tilt-card\"\n          className={cn(\n            \"border-ink bg-raise relative flex w-[min(300px,100%)] flex-col gap-3.5 border-(length:--rule) p-5 shadow-[8px_8px_0_var(--ink)]\",\n            !flat && \"transform-3d\",\n            className,\n          )}\n          style={flat ? undefined : { rotateX, rotateY }}\n          {...(props as React.ComponentProps<typeof motion.div>)}\n        >\n          {children}\n          {!flat && (\n            <motion.div\n              aria-hidden\n              data-part=\"glare\"\n              className=\"pointer-events-none absolute inset-0\"\n              style={{ opacity: glare, background }}\n            />\n          )}\n        </motion.div>\n      </div>\n    </TiltContext.Provider>\n  )\n}\n\ntype TiltLayerProps = React.ComponentProps<\"div\"> & {\n  /** How far the layer floats above the card, in pixels. */\n  depth?: number\n}\n\nexport function TiltLayer({ depth = 0, className, style, ...props }: TiltLayerProps) {\n  const flat = React.useContext(TiltContext)\n\n  return (\n    <div\n      className={cn(!flat && \"transform-3d\", className)}\n      style={flat ? style : { ...style, transform: `translateZ(${depth}px)` }}\n      {...props}\n    />\n  )\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "depth"
  ],
  "type": "registry:component"
}