{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tilted-card",
  "title": "Tilted Card",
  "description": "A showcase card with strong tilt and depth for a picture or a pass: a floating caption, a foil sheen, parts on separate planes or a notched ticket, with text sharp at rest.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "registry/miseui/ui/tilted-card.tsx",
      "content": "import type * as React from \"react\"\nimport { useRef } from \"react\"\nimport { motion, useReducedMotion, useSpring, useTransform } from \"motion/react\"\nimport { GlareFace, LayersFace, PassFace, PhotoFace, TiltLayer, TiltLiftContext, type TiltLayerProps } from \"@/registry/miseui/ui/tilted-card-parts\"\nimport { clampTilt, MAX_TILT_DEGREES, PERSPECTIVE_PX, tiltFromPointer, tiltTransform } from \"@/registry/miseui/ui/tilted-card-math\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\n\ntype TiltedCardVariant = \"photo\" | \"glare\" | \"layers\" | \"pass\"\ntype TiltedCardEffect = \"drag\"\n\nconst FINE_POINTER_QUERY = \"(hover: hover) and (pointer: fine)\"\nconst TILT_SPRING = { bounce: 0, visualDuration: 0.35 }\n\ntype TiltedCardProps = Omit<React.ComponentProps<\"div\">, \"ref\"> & {\n  /** `photo` a picture with a caption floating above it, `glare` a foil sheen that sweeps with the angle, `layers` parts on planes through `TiltLayer`, `pass` a ticket with a notched fold. */\n  variant?: TiltedCardVariant\n  /** `drag` lets a finger holding the card tilt it. The page still scrolls vertically, and it settles on release. */\n  effect?: TiltedCardEffect\n  /** Degrees at the edge, 12 at most: past that a corner leaves the reserved room. */\n  maxTilt?: number\n  /** `photo`: the line that floats above the picture. */\n  caption?: React.ReactNode\n  /** `pass`: what sits below the fold. */\n  stub?: React.ReactNode\n  /** `pass`: small terms at the foot of the stub. */\n  finePrint?: React.ReactNode\n}\n\nfunction useTilt(maxTilt: number, dragEffect: boolean) {\n  const reduceMotion = useReducedMotion()\n  const rotateX = useSpring(0, TILT_SPRING)\n  const rotateY = useSpring(0, TILT_SPRING)\n  const lift = useSpring(0, TILT_SPRING)\n  const held = useRef(false)\n\n  const aim = (event: React.PointerEvent<HTMLDivElement>) => {\n    // Measured on the still wrapper: reading the turning card would feed its own motion back into the pointer position.\n    const box = event.currentTarget.getBoundingClientRect()\n    const tilt = tiltFromPointer(event.clientX - box.left, event.clientY - box.top, box.width, box.height, maxTilt)\n    rotateX.set(tilt.rotateX)\n    rotateY.set(tilt.rotateY)\n    lift.set(1)\n  }\n  const settle = () => {\n    held.current = false\n    rotateX.set(0)\n    rotateY.set(0)\n    lift.set(0)\n  }\n  const handlers = {\n    onPointerDown: (event: React.PointerEvent<HTMLDivElement>) => {\n      if (!dragEffect || reduceMotion || event.pointerType === \"mouse\") return\n      // No pointer capture. A captured touch retargets its click at this wrapper and a link inside would stop working.\n      held.current = true\n      aim(event)\n    },\n    onPointerMove: (event: React.PointerEvent<HTMLDivElement>) => {\n      if (reduceMotion) return\n      if (held.current || (event.pointerType === \"mouse\" && window.matchMedia(FINE_POINTER_QUERY).matches)) aim(event)\n    },\n    onPointerUp: (event: React.PointerEvent<HTMLDivElement>) => {\n      if (event.pointerType !== \"mouse\") settle()\n    },\n    onPointerCancel: settle,\n    onPointerLeave: settle,\n  }\n  return { rotateX, rotateY, lift, handlers }\n}\n\nfunction TiltedCard({\n  variant = \"photo\",\n  effect,\n  maxTilt = MAX_TILT_DEGREES,\n  caption,\n  stub,\n  finePrint,\n  className,\n  style,\n  children,\n  onPointerDown,\n  onPointerMove,\n  onPointerUp,\n  onPointerCancel,\n  onPointerLeave,\n  ...props\n}: TiltedCardProps) {\n  const limit = clampTilt(maxTilt)\n  const { rotateX, rotateY, lift, handlers } = useTilt(limit, effect === \"drag\")\n  const transform = useTransform([rotateX, rotateY], ([x, y]) => tiltTransform(x as number, y as number))\n  return (\n    <div\n      {...props}\n      data-slot=\"tilted-card\"\n      data-variant={variant}\n      data-effect={effect}\n      // The padding is the room a corner swings through at full tilt, so a card in a narrow cell never widens the page.\n      className={cn(\"min-w-0 p-2\", effect === \"drag\" && \"touch-pan-y\", className)}\n      style={{ perspective: PERSPECTIVE_PX, ...style }}\n      onPointerDown={(event) => {\n        onPointerDown?.(event)\n        handlers.onPointerDown(event)\n      }}\n      onPointerMove={(event) => {\n        onPointerMove?.(event)\n        handlers.onPointerMove(event)\n      }}\n      onPointerUp={(event) => {\n        onPointerUp?.(event)\n        handlers.onPointerUp(event)\n      }}\n      onPointerCancel={(event) => {\n        onPointerCancel?.(event)\n        handlers.onPointerCancel()\n      }}\n      onPointerLeave={(event) => {\n        onPointerLeave?.(event)\n        handlers.onPointerLeave()\n      }}\n    >\n      <TiltLiftContext.Provider value={lift}>\n        <motion.div data-slot=\"tilted-card-surface\" className=\"relative\" style={{ transform, transformStyle: \"preserve-3d\" }}>\n          <div aria-hidden=\"true\" className=\"absolute inset-0 rounded-2xl shadow-[0_1px_2px_rgb(0_0_0/0.06),0_12px_24px_-16px_rgb(0_0_0/0.28)] dark:shadow-[0_1px_2px_rgb(0_0_0/0.5),0_12px_24px_-16px_rgb(0_0_0/0.8)]\" />\n          <motion.div aria-hidden=\"true\" data-slot=\"tilted-card-shadow\" className=\"absolute inset-0 rounded-2xl shadow-[0_24px_48px_-16px_rgb(0_0_0/0.3)] dark:shadow-[0_24px_48px_-16px_rgb(0_0_0/0.8)]\" style={{ opacity: lift }} />\n          {variant === \"photo\" ? <PhotoFace caption={caption}>{children}</PhotoFace> : null}\n          {variant === \"glare\" ? <GlareFace rotateX={rotateX} rotateY={rotateY} lift={lift} maxTilt={limit}>{children}</GlareFace> : null}\n          {variant === \"layers\" ? <LayersFace>{children}</LayersFace> : null}\n          {variant === \"pass\" ? <PassFace stub={stub} finePrint={finePrint}>{children}</PassFace> : null}\n        </motion.div>\n      </TiltLiftContext.Provider>\n    </div>\n  )\n}\n\nexport { TiltedCard, TiltLayer, type TiltedCardProps, type TiltedCardVariant, type TiltedCardEffect, type TiltLayerProps }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/miseui/ui/tilted-card-math.ts",
      "content": "export const MAX_TILT_DEGREES = 12\r\nexport const PERSPECTIVE_PX = 1000\r\n/** Padding on the still wrapper. It is what keeps a corner at full tilt inside the box, see `tiltReach`. */\r\nexport const TILT_RESERVE_PX = 8\r\n\r\nconst RADIANS = Math.PI / 180\r\nconst REST_EPSILON = 0.01\r\n\r\nexport function clampTilt(degrees: number) {\r\n  if (!Number.isFinite(degrees)) return MAX_TILT_DEGREES\r\n  return Math.min(Math.max(degrees, 0), MAX_TILT_DEGREES)\r\n}\r\n\r\nexport interface Tilt {\r\n  rotateX: number\r\n  rotateY: number\r\n}\r\n\r\n/**\r\n * The edge under the pointer comes forward. Tilting it away would slide the card out from under a pointer near that\r\n * edge. Positions are read from a wrapper that never moves, so the share is stable as the card turns.\r\n */\r\nexport function tiltFromPointer(x: number, y: number, width: number, height: number, maxTilt: number): Tilt {\r\n  if (width <= 0 || height <= 0) return { rotateX: 0, rotateY: 0 }\r\n  const shareX = Math.min(Math.max(x / width - 0.5, -0.5), 0.5)\r\n  const shareY = Math.min(Math.max(y / height - 0.5, -0.5), 0.5)\r\n  return { rotateX: shareY * 2 * maxTilt, rotateY: -shareX * 2 * maxTilt }\r\n}\r\n\r\n/**\r\n * Returns \"none\" at rest instead of a zero rotation. Any 3D transform puts the card on its own layer, which leaves text\r\n * softer on a low-density screen, and text has to be sharp whenever nobody is touching the card.\r\n */\r\nexport function tiltTransform(rotateX: number, rotateY: number) {\r\n  if (Math.abs(rotateX) < REST_EPSILON && Math.abs(rotateY) < REST_EPSILON) return \"none\"\r\n  return `rotateX(${rotateX.toFixed(3)}deg) rotateY(${rotateY.toFixed(3)}deg)`\r\n}\r\n\r\nexport function layerTransform(depth: number, lift: number) {\r\n  const distance = depth * lift\r\n  return Math.abs(distance) < REST_EPSILON ? \"none\" : `translateZ(${distance.toFixed(2)}px)`\r\n}\r\n\r\n/** Turning the card sweeps the band across it. Rests on none, so a card nobody touches holds no extra transform. */\r\nexport function glareTransform(rotateX: number, rotateY: number, maxTilt: number) {\r\n  if (maxTilt <= 0 || (Math.abs(rotateX) < REST_EPSILON && Math.abs(rotateY) < REST_EPSILON)) return \"none\"\r\n  return `translate(${((rotateY / maxTilt) * -28).toFixed(2)}%, ${((rotateX / maxTilt) * 18).toFixed(2)}%)`\r\n}\r\n\r\n/** How far outside its own box a point at (x, y, depth), measured from the card centre, lands on screen at the given tilt. */\r\nexport function projectCorner(x: number, y: number, depth: number, { rotateX, rotateY }: Tilt, perspective = PERSPECTIVE_PX) {\r\n  const sinX = Math.sin(rotateX * RADIANS)\r\n  const cosX = Math.cos(rotateX * RADIANS)\r\n  const sinY = Math.sin(rotateY * RADIANS)\r\n  const cosY = Math.cos(rotateY * RADIANS)\r\n  const y1 = y * cosX - depth * sinX\r\n  const z1 = y * sinX + depth * cosX\r\n  const x2 = x * cosY + z1 * sinY\r\n  const z2 = -x * sinY + z1 * cosY\r\n  const scale = perspective / (perspective - z2)\r\n  return { x: x2 * scale, y: y1 * scale }\r\n}\r\n\r\n/** The largest distance any corner of a width by height card passes its resting edge, over all full-tilt poses. */\r\nexport function tiltReach(width: number, height: number, maxTilt: number, perspective = PERSPECTIVE_PX) {\r\n  const poses = [-maxTilt, maxTilt].flatMap((rotateX) => [-maxTilt, maxTilt].map((rotateY) => ({ rotateX, rotateY })))\r\n  const corners = [-1, 1].flatMap((sx) => [-1, 1].map((sy) => [(sx * width) / 2, (sy * height) / 2] as const))\r\n  return poses.reduce((reach, pose) => {\r\n    return corners.reduce((widest, [x, y]) => {\r\n      const { x: px, y: py } = projectCorner(x, y, 0, pose, perspective)\r\n      return Math.max(widest, Math.abs(px) - width / 2, Math.abs(py) - height / 2)\r\n    }, reach)\r\n  }, 0)\r\n}\r\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/miseui/ui/tilted-card-parts.tsx",
      "content": "import type * as React from \"react\"\r\nimport { createContext, useContext } from \"react\"\r\nimport { motion, useMotionValue, useTransform, type MotionValue } from \"motion/react\"\r\nimport { glareTransform, layerTransform } from \"@/registry/miseui/ui/tilted-card-math\"\r\nimport { cn } from \"@/registry/miseui/lib/utils\"\r\n\r\n/** 0 at rest, 1 while tilted. Layers and the sheen read it, so everything reaches rest together and text ends up sharp. */\r\nexport const TiltLiftContext = createContext<MotionValue<number> | null>(null)\r\n\r\nconst NOTCH_EDGE = \"transparent 6.5px, #000 7px\"\r\nconst NOTCH_BOTTOM: React.CSSProperties = {\r\n  maskImage: `radial-gradient(circle 7px at 0 100%, ${NOTCH_EDGE}), radial-gradient(circle 7px at 100% 100%, ${NOTCH_EDGE})`,\r\n  maskComposite: \"intersect\",\r\n}\r\nconst NOTCH_TOP: React.CSSProperties = {\r\n  maskImage: `radial-gradient(circle 7px at 0 0, ${NOTCH_EDGE}), radial-gradient(circle 7px at 100% 0, ${NOTCH_EDGE})`,\r\n  maskComposite: \"intersect\",\r\n}\r\n/** A white core between two faint darker flanks: that pair reads as foil on a light card, where white alone cannot show. No hue, so never a rainbow. */\r\nconst SHEEN_IMAGE = [\r\n  \"linear-gradient(112deg, transparent 30%, color-mix(in oklab, var(--foreground) 7%, transparent) 41%, rgb(255 255 255 / var(--mise-sheen)) 50%, color-mix(in oklab, var(--foreground) 7%, transparent) 59%, transparent 70%)\",\r\n  \"linear-gradient(112deg, transparent 66%, rgb(255 255 255 / calc(var(--mise-sheen) * 0.5)) 70%, transparent 74%)\",\r\n].join(\",\")\r\n\r\ninterface TiltLayerProps extends Omit<React.ComponentProps<\"div\">, \"ref\" | \"style\" | \"onAnimationStart\" | \"onDrag\" | \"onDragEnd\" | \"onDragStart\"> {\r\n  /** Pixels toward the viewer while the card is tilted. Past about 48 a part near the edge passes the reserved room. */\r\n  depth?: number\r\n}\r\n\r\n/** A part on its own plane. Lies flat at rest, so its text is as sharp as anything else on the page. */\r\nfunction TiltLayer({ depth = 24, className, children, ...props }: TiltLayerProps) {\r\n  const contextLift = useContext(TiltLiftContext)\r\n  const idleLift = useMotionValue(0)\r\n  const lift = contextLift ?? idleLift\r\n  const transform = useTransform(lift, (value) => layerTransform(depth, value))\r\n  return (\r\n    <motion.div {...props} data-slot=\"tilt-layer\" data-depth={depth} className={className} style={{ transform, transformStyle: \"preserve-3d\" }}>\r\n      {children}\r\n    </motion.div>\r\n  )\r\n}\r\n\r\ninterface PhotoFaceProps {\r\n  caption?: React.ReactNode\r\n  children: React.ReactNode\r\n}\r\n\r\n/** The clip sits on the picture alone: overflow on the turning surface would flatten the caption back into the card. */\r\nfunction PhotoFace({ caption, children }: PhotoFaceProps) {\r\n  return (\r\n    <>\r\n      <div data-slot=\"tilted-card-picture\" className=\"overflow-hidden rounded-2xl\">\r\n        {children}\r\n      </div>\r\n      {caption ? (\r\n        <TiltLayer depth={40} className=\"absolute start-3 end-3 bottom-3 flex\">\r\n          <div data-slot=\"tilted-card-caption\" className=\"min-w-0 rounded-lg bg-background px-3 py-2 text-[13px] text-foreground shadow-md shadow-black/15 dark:shadow-black/40\">\r\n            {caption}\r\n          </div>\r\n        </TiltLayer>\r\n      ) : null}\r\n    </>\r\n  )\r\n}\r\n\r\ninterface GlareFaceProps {\r\n  rotateX: MotionValue<number>\r\n  rotateY: MotionValue<number>\r\n  lift: MotionValue<number>\r\n  maxTilt: number\r\n  children: React.ReactNode\r\n}\r\n\r\nfunction GlareFace({ rotateX, rotateY, lift, maxTilt, children }: GlareFaceProps) {\r\n  const transform = useTransform([rotateX, rotateY], ([x, y]) => glareTransform(x as number, y as number, maxTilt))\r\n  return (\r\n    <div data-slot=\"tilted-card-foil\" className=\"relative overflow-hidden rounded-2xl border bg-card text-card-foreground\">\r\n      {children}\r\n      <motion.div\r\n        aria-hidden=\"true\"\r\n        data-slot=\"tilted-card-sheen\"\r\n        className=\"pointer-events-none absolute -inset-[60%] [--mise-sheen:0.75] dark:[--mise-sheen:0.14]\"\r\n        style={{ backgroundImage: SHEEN_IMAGE, opacity: lift, transform }}\r\n      />\r\n    </div>\r\n  )\r\n}\r\n\r\n/** A plain wrapper div around a layer would flatten it back into the card, so every ancestor of a layer keeps 3D. */\r\nconst KEEP_3D = \"[&_:has([data-slot=tilt-layer])]:[transform-style:preserve-3d]\"\r\n\r\nfunction LayersFace({ children }: { children: React.ReactNode }) {\r\n  return (\r\n    <div data-slot=\"tilted-card-plate\" className={cn(\"relative rounded-2xl border bg-card text-card-foreground [transform-style:preserve-3d]\", KEEP_3D)}>\r\n      {children}\r\n    </div>\r\n  )\r\n}\r\n\r\ninterface PassFaceProps {\r\n  stub?: React.ReactNode\r\n  finePrint?: React.ReactNode\r\n  children: React.ReactNode\r\n}\r\n\r\n/** Each half cuts its own corners at the seam, so the notches stay on the fold however tall either half grows. */\r\nfunction PassFace({ stub, finePrint, children }: PassFaceProps) {\r\n  return (\r\n    <div data-slot=\"tilted-card-pass\" className=\"relative grid grid-cols-[minmax(0,1fr)] text-card-foreground\">\r\n      <div data-slot=\"tilted-card-pass-main\" className=\"rounded-t-2xl bg-card p-4 dark:bg-muted\" style={NOTCH_BOTTOM}>\r\n        {children}\r\n      </div>\r\n      <div data-slot=\"tilted-card-pass-stub\" className=\"grid gap-2 rounded-b-2xl border-t border-dashed border-border bg-card p-4 dark:bg-muted\" style={NOTCH_TOP}>\r\n        {stub}\r\n        {finePrint ? <p className={cn(\"text-xs text-muted-foreground\")}>{finePrint}</p> : null}\r\n      </div>\r\n    </div>\r\n  )\r\n}\r\n\r\nexport { GlareFace, LayersFace, PassFace, PhotoFace, TiltLayer, type TiltLayerProps }\r\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "interactions"
  ],
  "type": "registry:ui"
}