{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tilt-card",
  "title": "Tilt card",
  "description": "Tilts toward the pointer on a spring with a moving glare, a shifting shadow and layers that float at their own depth.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json"
  ],
  "files": [
    {
      "path": "registry/components/cards/tilt-card.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { motion, useMotionTemplate, useMotionValue, useReducedMotion, useSpring, useTransform, type MotionValue } from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { GooduiTokens, follow } from \"@/lib/goodui-motion\"\n\nconst CSS = `\n.pc-tilt-foil{mix-blend-mode:hard-light;background-image:var(--pc-grain),repeating-linear-gradient(115deg,oklch(.72 .2 20),oklch(.85 .17 95) 6%,oklch(.8 .19 165) 12%,oklch(.68 .19 245) 18%,oklch(.66 .22 310) 24%,oklch(.72 .2 380) 30%);background-size:160px 160px,240% 240%}\n.pc-tilt-edge{padding:1px;-webkit-mask:linear-gradient(#000 0 0) content-box exclude,linear-gradient(#000 0 0);mask:linear-gradient(#000 0 0) content-box exclude,linear-gradient(#000 0 0)}\n`\n\nconst TiltContext = React.createContext<{ x: MotionValue<number>; y: MotionValue<number> } | null>(null)\n\nexport type TiltCardProps = Omit<React.HTMLAttributes<HTMLDivElement>, \"onDrag\" | \"onDragStart\" | \"onDragEnd\" | \"onAnimationStart\"> & {\n  /** Maximum tilt in degrees. */\n  maxTilt?: number\n  /** Scale while hovered. */\n  scale?: number\n  /** Show a light glare that follows the pointer. */\n  glare?: boolean\n  /** Peak opacity of the glare. */\n  glareOpacity?: number\n  /** Holographic foil that shifts its colors with the tilt. */\n  foil?: boolean\n  /** Peak opacity of the foil. */\n  foilOpacity?: number\n  /** A bright rim that follows the pointer around the card's edge. Follows `glare` by default. */\n  specular?: boolean\n  /** Sways gently on its own until a pointer takes over, so touch screens and still pages see it move. */\n  autoplay?: boolean\n  /** CSS perspective in px; lower is more dramatic. */\n  perspective?: number\n  /** Keep the card flat (no tilt, glare or scale). */\n  disabled?: boolean\n  /** Classes for the outer element that holds the perspective and receives the pointer. */\n  containerClassName?: string\n}\n\n/**\n * Tilts toward the pointer on a spring, with glare, a specular rim, optional holographic foil and a shadow that shifts\n * with the tilt. Children wrapped in TiltCardLayer float and slide at their own depth. Touch and reduced motion get a\n * flat card unless `autoplay` is on (reduced motion stays flat).\n */\nexport function TiltCard({\n  maxTilt = 10,\n  scale = 1.02,\n  glare = true,\n  glareOpacity = 0.35,\n  foil = false,\n  foilOpacity = 0.7,\n  specular: specularProp,\n  autoplay = false,\n  perspective = 900,\n  disabled = false,\n  containerClassName,\n  className,\n  style,\n  children,\n  ...props\n}: TiltCardProps) {\n  const reduce = useReducedMotion() ?? false\n  const enabled = !reduce && !disabled\n  const specular = specularProp ?? glare\n  const px = useMotionValue(0.5)\n  const py = useMotionValue(0.5)\n  const hover = useMotionValue(0)\n  const sx = useSpring(px, follow)\n  const sy = useSpring(py, follow)\n  const sh = useSpring(hover, follow)\n\n  const rotateX = useTransform(sy, [0, 1], [maxTilt, -maxTilt])\n  const rotateY = useTransform(sx, [0, 1], [-maxTilt, maxTilt])\n  const s = useTransform(sh, [0, 1], [1, scale])\n  const gx = useTransform(sx, (v) => `${v * 100}%`)\n  const gy = useTransform(sy, (v) => `${v * 100}%`)\n  const glareBg = useMotionTemplate`radial-gradient(circle at ${gx} ${gy}, rgb(255 255 255 / ${glareOpacity}), transparent 60%)`\n  const shadowX = useTransform(sx, [0, 1], [14, -14])\n  const shadowY = useTransform(sy, [0, 1], [18, 2])\n  const shadowA = useTransform(sh, [0, 1], [0, 0.22])\n  const shadow = useMotionTemplate`var(--pc-e2), ${shadowX}px ${shadowY}px 40px -12px hsl(var(--pc-sh) / ${shadowA})`\n  const edgeBg = useMotionTemplate`radial-gradient(180px circle at ${gx} ${gy}, rgb(255 255 255 / .9), color-mix(in oklab, var(--foreground) 35%, transparent) 45%, transparent 75%)`\n  const foilAmount = useTransform(sh, [0, 1], [0, foilOpacity])\n  const fx = useTransform(sx, [0, 1], [\"100%\", \"0%\"])\n  const fy = useTransform(sy, [0, 1], [\"100%\", \"0%\"])\n  const foilPos = useMotionTemplate`0 0, ${fx} ${fy}`\n  const foilMask = useMotionTemplate`radial-gradient(70% 90% at ${gx} ${gy}, #000 15%, rgb(0 0 0 / .25) 70%, transparent)`\n  const depth = React.useMemo(() => ({ x: sx, y: sy }), [sx, sy])\n  const hovering = React.useRef(false)\n  const rootRef = React.useRef<HTMLDivElement>(null)\n\n  const reset = () => {\n    hovering.current = false\n    px.set(0.5)\n    py.set(0.5)\n    hover.set(0)\n  }\n\n  React.useEffect(() => {\n    if (!enabled) reset()\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [enabled])\n\n  // A slow figure-eight while nobody is touching it; paused off-screen.\n  React.useEffect(() => {\n    const el = rootRef.current\n    if (!autoplay || !enabled || !el) return\n    let raf = 0\n    let visible = false\n    const t0 = performance.now()\n    const tick = (t: number) => {\n      raf = requestAnimationFrame(tick)\n      if (hovering.current || document.hidden) return\n      const s = (t - t0) / 1000\n      px.set(0.5 + 0.38 * Math.sin(s * 0.8))\n      py.set(0.5 + 0.3 * Math.sin(s * 1.3))\n      hover.set(0.8)\n    }\n    const io = new IntersectionObserver(([e]) => {\n      const on = !!e?.isIntersecting\n      if (on === visible) return\n      visible = on\n      cancelAnimationFrame(raf)\n      if (on) raf = requestAnimationFrame(tick)\n    })\n    io.observe(el)\n    return () => {\n      cancelAnimationFrame(raf)\n      io.disconnect()\n    }\n  }, [autoplay, enabled, px, py, hover])\n\n  return (\n    <div\n      ref={rootRef}\n      className={cn(\"group/tilt\", containerClassName)}\n      style={{ perspective }}\n      onPointerMove={(e) => {\n        if (!enabled || e.pointerType === \"touch\") return\n        hovering.current = true\n        const r = e.currentTarget.getBoundingClientRect()\n        px.set((e.clientX - r.left) / r.width)\n        py.set((e.clientY - r.top) / r.height)\n        hover.set(1)\n      }}\n      onPointerLeave={reset}\n    >\n      <GooduiTokens />\n      <style href=\"pc-tilt-card\" precedence=\"default\">\n        {CSS}\n      </style>\n      <motion.div\n        className={cn(\"relative rounded-xl border bg-card text-card-foreground\", className)}\n        style={{ ...style, rotateX, rotateY, scale: s, boxShadow: shadow, transformStyle: \"preserve-3d\" }}\n        {...props}\n      >\n        {foil && (\n          <motion.div\n            aria-hidden=\"true\"\n            className=\"pc-tilt-foil pointer-events-none absolute inset-0 rounded-[inherit]\"\n            style={{ opacity: foilAmount, backgroundPosition: foilPos, maskImage: foilMask, WebkitMaskImage: foilMask }}\n          />\n        )}\n        <TiltContext.Provider value={depth}>{children}</TiltContext.Provider>\n        {glare && (\n          <motion.div\n            aria-hidden=\"true\"\n            className=\"pointer-events-none absolute inset-0 rounded-[inherit]\"\n            style={{ background: glareBg, opacity: sh, transform: \"translateZ(1px)\" }}\n          />\n        )}\n        {specular && <motion.div aria-hidden=\"true\" className=\"pc-tilt-edge pointer-events-none absolute -inset-px rounded-[inherit]\" style={{ background: edgeBg, opacity: sh, transform: \"translateZ(2px)\" }} />}\n      </motion.div>\n    </div>\n  )\n}\n\nexport type TiltCardLayerProps = Omit<React.HTMLAttributes<HTMLDivElement>, \"onDrag\" | \"onDragStart\" | \"onDragEnd\" | \"onAnimationStart\"> & {\n  /** How far the layer floats above the card, in px. */\n  depth?: number\n}\n\n/** A child that floats above the tilting card and slides against it for parallax. Keep `overflow: hidden` off the elements between it and the card. */\nexport function TiltCardLayer({ depth = 30, className, style, ...props }: TiltCardLayerProps) {\n  const ctx = React.useContext(TiltContext)\n  const rest = useMotionValue(0.5)\n  const shift = depth * 0.22\n  const x = useTransform(ctx?.x ?? rest, [0, 1], [-shift, shift])\n  const y = useTransform(ctx?.y ?? rest, [0, 1], [-shift, shift])\n  return <motion.div className={cn(className)} style={{ ...style, x, y, z: depth, transformStyle: \"preserve-3d\" }} {...props} />\n}\n",
      "type": "registry:component",
      "target": "components/goodui/tilt-card.tsx"
    }
  ],
  "categories": [
    "components",
    "cards"
  ],
  "type": "registry:component"
}