{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "depth-card",
  "title": "Depth Card",
  "description": "A card that tilts toward the pointer in 3D while its image layers shift in depth under a soft spotlight, and its text rises in on hover. No dependencies.",
  "files": [
    {
      "path": "registry/mewo/ui/depth-card.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cn } from \"@/lib/utils\"\n\nexport interface DepthCardLayer {\n  /** Image URL. */\n  image: string\n  /** Parallax multiplier: with the pointer at the card's edge the layer travels `maxTranslation` × `depth` pixels. */\n  depth: number\n}\n\nexport interface DepthCardProps extends Omit<React.ComponentProps<\"div\">, \"title\" | \"onClick\"> {\n  /** Background image URL. Ignored when `layers` is set. */\n  image?: string\n  /** Several images stacked for a deeper parallax, later ones in front. Replaces `image`. */\n  layers?: DepthCardLayer[]\n  /** Heading at the bottom of the card, and its accessible name unless `ariaLabel` is set. It takes the place of the HTML `title` attribute, which the card does not pass on. */\n  title?: string\n  /** Line under the heading. */\n  description?: string\n  /** Card width in pixels. */\n  width?: number\n  /** Card height in pixels. */\n  height?: number\n  /** Tilt in degrees with the pointer at an edge. */\n  maxRotation?: number\n  /** Image travel in pixels with the pointer at an edge, times each layer's depth. */\n  maxTranslation?: number\n  /** Corner radius, as any CSS length. */\n  borderRadius?: string\n  /** Merged onto the block that holds the title and description. */\n  contentClassName?: string\n  /** Called on click. Without `href` it makes the card a button that Enter and Space also press. */\n  onClick?: React.MouseEventHandler<HTMLElement>\n  /** Makes the card a link. */\n  href?: string\n  /** Where the link opens. `_blank` adds `rel=\"noopener noreferrer\"`. */\n  target?: \"_blank\" | \"_self\" | \"_parent\" | \"_top\"\n  /** Describes the image for screen readers. Without it the images are decorative. */\n  imageAlt?: string\n  /** Turn the tilt and the spotlight off on touch-first devices. */\n  disableOnMobile?: boolean\n  /** Accessible name of the card. Defaults to the title. */\n  ariaLabel?: string\n  /** Delay between the title's and the description's reveal, in milliseconds. */\n  staggerDelay?: number\n  /** How the text appears on hover or keyboard focus. */\n  revealAnimation?: \"slide\" | \"fade\" | \"scale\" | \"none\"\n  /** Keep the card flat and the spotlight off when the user prefers reduced motion. */\n  respectReducedMotion?: boolean\n  /** A soft light that follows the pointer. */\n  spotlight?: boolean\n  /** Colour at the centre of the light, as `rgb()` or `rgba()`. Its outer ring is the same colour at a fifth of the alpha. */\n  spotlightColor?: string\n}\n\nexport const DEFAULT_IMAGE = \"https://cataas.com/cat/PRHr1MTVrPmV08W1\"\n\n// The tilt covers 10% of the remaining distance per 60 fps frame. It is applied per elapsed second, so\n// the ease takes the same time at 30, 60 or 144 fps.\nconst EASE_PER_FRAME = 0.1\n// The images are drawn 30% larger than the card, so their parallax never shows an edge.\nconst IMAGE_SCALE = 1.3\n// Every layer stacked on the first is drawn at this opacity, so the one under it shows through.\nconst BACK_LAYER_OPACITY = 0.6\n// Radius of the spotlight in pixels: its circle has faded to nothing this far from the pointer.\nconst SPOTLIGHT_RADIUS = 600\n// The tilt has settled once it is this close to its target, in half-card units.\nconst SETTLE_DISTANCE = 1e-4\n// Frame time is clamped so a hitch or a background tab does not jump the ease.\nconst MIN_FRAME = 1 / 240\nconst MAX_FRAME = 0.05\n\n// Where the title and the description wait until the card is hovered or focused, per reveal style.\nconst REVEAL_HIDDEN = {\n  slide: { title: \"translate-y-4 opacity-90\", description: \"translate-y-4 opacity-0\" },\n  fade: { title: \"opacity-90\", description: \"opacity-0\" },\n  scale: { title: \"scale-95 opacity-90\", description: \"scale-95 opacity-0\" },\n  none: { title: \"\", description: \"\" },\n}\n\ntype Motion = {\n  // Eased pointer position and its target, in −1…1 from the centre (x right, y down).\n  x: number\n  y: number\n  tx: number\n  ty: number\n  // The latest pointer position in client pixels, read on the next frame.\n  clientX: number\n  clientY: number\n  moved: boolean\n  // Spotlight centre in card pixels, and whether it moved since it was last drawn.\n  px: number\n  py: number\n  lit: boolean\n  raf: number\n  last: number\n  // Props the frame reads, synced in an effect.\n  maxRotation: number\n  maxTranslation: number\n  depths: number[]\n  effects: boolean\n  // Set by the setup effect: writes the current pose once.\n  draw: () => void\n}\n\nconst clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value))\n\n/** Share of the remaining distance the tilt covers in `dt` seconds: a tenth per 60 fps frame, at any frame rate. */\nexport function easeFactor(dt: number) {\n  return 1 - Math.pow(1 - EASE_PER_FRAME, dt * 60)\n}\n\n/** The pointer at (`px`, `py`) pixels in a `width` × `height` card, as −1…1 from the centre (x right, y down). */\nexport function pointerTarget(px: number, py: number, width: number, height: number) {\n  return {\n    x: width > 0 ? clamp((px / width - 0.5) * 2, -1, 1) : 0,\n    y: height > 0 ? clamp((py / height - 0.5) * 2, -1, 1) : 0,\n  }\n}\n\n/** The card's tilt in degrees for a pointer at (`x`, `y`): the card dips where the pointer is. */\nexport function cardTilt(x: number, y: number, maxRotation: number) {\n  return { rotateX: -y * maxRotation, rotateY: x * maxRotation }\n}\n\n/** A layer's offset in pixels for a pointer at (`x`, `y`): it slides away from the pointer, deeper layers further. */\nexport function layerShift(x: number, y: number, maxTranslation: number, depth: number) {\n  return { x: -x * maxTranslation * depth, y: -y * maxTranslation * depth }\n}\n\n/** The spotlight's outer stop: the same colour at a fifth of its alpha (0.5 → 0.1 for the default white). */\nexport function fadedStop(color: string) {\n  const m = color.match(/rgba?\\(\\s*([\\d.]+)[,\\s]+([\\d.]+)[,\\s]+([\\d.]+)(?:[,\\s/]+([\\d.]+%?))?\\s*\\)/i)\n  if (!m) return \"rgba(255, 255, 255, 0.1)\"\n  const alpha = m[4] === undefined ? 1 : m[4].endsWith(\"%\") ? parseFloat(m[4]) / 100 : parseFloat(m[4])\n  return `rgba(${m[1]}, ${m[2]}, ${m[3]}, ${+(alpha * 0.2).toFixed(3)})`\n}\n\nfunction useMediaQuery(query: string) {\n  const subscribe = React.useCallback(\n    (onChange: () => void) => {\n      const list = window.matchMedia?.(query)\n      list?.addEventListener(\"change\", onChange)\n      return () => list?.removeEventListener(\"change\", onChange)\n    },\n    [query]\n  )\n  return React.useSyncExternalStore(subscribe, () => window.matchMedia?.(query).matches ?? false, () => false)\n}\n\n/**\n * The spotlight is a fixed radial gradient on an element twice the card's size, moved to the pointer with\n * a transform inside a card-sized layer that clips, blurs and blends it: the light is painted once and the\n * compositor slides it. The tilt and the parallax are transforms too, written from one frame loop that\n * stops as soon as the card has caught up with the pointer or eased back flat.\n */\nexport function DepthCard({\n  image = DEFAULT_IMAGE,\n  layers,\n  title = \"Quiet Ridge\",\n  description = \"First light over the high pass.\",\n  width = 240,\n  height = 320,\n  maxRotation = 20,\n  maxTranslation = 20,\n  borderRadius = \"10px\",\n  contentClassName,\n  onClick,\n  href,\n  target = \"_self\",\n  imageAlt,\n  disableOnMobile = false,\n  ariaLabel,\n  staggerDelay = 75,\n  revealAnimation = \"slide\",\n  respectReducedMotion = true,\n  spotlight = true,\n  spotlightColor = \"rgba(255, 255, 255, 0.5)\",\n  className,\n  style,\n  onFocus,\n  onBlur,\n  onKeyDown,\n  ...props\n}: DepthCardProps) {\n  const reduced = useMediaQuery(\"(prefers-reduced-motion: reduce)\")\n  const coarse = useMediaQuery(\"(hover: none) and (pointer: coarse)\")\n  // Reduced motion, or a touch-first device when asked, keeps the card flat and the spotlight off.\n  const effects = !(respectReducedMotion && reduced) && !(disableOnMobile && coarse)\n  const [active, setActive] = React.useState(false)\n  const stack: DepthCardLayer[] = layers?.length ? layers : image ? [{ image, depth: 1 }] : []\n\n  const cardRef = React.useRef<HTMLDivElement>(null)\n  const layerRefs = React.useRef<(HTMLDivElement | null)[]>([])\n  const spotlightRef = React.useRef<HTMLDivElement>(null)\n  const motionRef = React.useRef<Motion>({\n    x: 0,\n    y: 0,\n    tx: 0,\n    ty: 0,\n    clientX: 0,\n    clientY: 0,\n    moved: false,\n    px: 0,\n    py: 0,\n    lit: false,\n    raf: 0,\n    last: 0,\n    maxRotation,\n    maxTranslation,\n    depths: [],\n    effects,\n    draw: () => {},\n  })\n\n  // The root becomes a new element when the card turns into a link or back, so the setup follows it.\n  const isLink = Boolean(href)\n  React.useLayoutEffect(() => {\n    // The root's ref stays the consumer's, so the root is reached through the card.\n    const card = cardRef.current\n    const root = card?.parentElement\n    if (!card || !root) return\n    const m = motionRef.current\n\n    const draw = () => {\n      const { rotateX, rotateY } = cardTilt(m.x, m.y, m.maxRotation)\n      card.style.transform = `rotateX(${rotateX.toFixed(4)}deg) rotateY(${rotateY.toFixed(4)}deg)`\n      m.depths.forEach((depth, i) => {\n        const layer = layerRefs.current[i]\n        if (!layer) return\n        const shift = layerShift(m.x, m.y, m.maxTranslation, depth)\n        layer.style.transform = `translateX(${shift.x.toFixed(4)}px) translateY(${shift.y.toFixed(4)}px) scale(${IMAGE_SCALE})`\n      })\n      const light = spotlightRef.current\n      if (light && m.lit) {\n        light.style.transform = `translate3d(${m.px.toFixed(2)}px, ${m.py.toFixed(2)}px, 0)`\n        m.lit = false\n      }\n    }\n\n    const tick = (now: number) => {\n      // dt is clamped so a hitch or a tab switch does not jump the ease.\n      const dt = clamp((now - m.last) / 1000, MIN_FRAME, MAX_FRAME)\n      m.last = now\n      if (m.moved) {\n        // Layout is read here, once a frame and before any write, rather than in the pointer listener.\n        const rect = root.getBoundingClientRect()\n        m.px = m.clientX - rect.left\n        m.py = m.clientY - rect.top\n        const target = pointerTarget(m.px, m.py, rect.width, rect.height)\n        m.tx = target.x\n        m.ty = target.y\n        m.lit = true\n        m.moved = false\n      }\n      const k = easeFactor(dt)\n      m.x += (m.tx - m.x) * k\n      m.y += (m.ty - m.y) * k\n      const settled = Math.abs(m.tx - m.x) < SETTLE_DISTANCE && Math.abs(m.ty - m.y) < SETTLE_DISTANCE\n      if (settled) {\n        m.x = m.tx\n        m.y = m.ty\n      }\n      draw()\n      // The loop ends once the card has caught up with a still pointer or eased back flat: at rest it costs nothing.\n      m.raf = settled ? 0 : requestAnimationFrame(tick)\n    }\n\n    const wake = () => {\n      if (m.raf) return\n      // The ease is timed from the moment its target changed.\n      m.last = performance.now()\n      m.raf = requestAnimationFrame(tick)\n    }\n\n    // Passive listeners that only note the pointer; the frame does the rest.\n    const onPointerMove = (event: PointerEvent) => {\n      if (!m.effects) return\n      m.clientX = event.clientX\n      m.clientY = event.clientY\n      m.moved = true\n      wake()\n    }\n    const onPointerEnter = () => setActive(true)\n    const onPointerLeave = () => {\n      setActive(false)\n      m.moved = false\n      m.tx = 0\n      m.ty = 0\n      if (m.effects) wake()\n    }\n    const options: AddEventListenerOptions = { passive: true }\n    root.addEventListener(\"pointermove\", onPointerMove, options)\n    root.addEventListener(\"pointerenter\", onPointerEnter, options)\n    root.addEventListener(\"pointerleave\", onPointerLeave, options)\n    m.draw = draw\n    if (m.x !== m.tx || m.y !== m.ty) wake()\n\n    return () => {\n      root.removeEventListener(\"pointermove\", onPointerMove)\n      root.removeEventListener(\"pointerenter\", onPointerEnter)\n      root.removeEventListener(\"pointerleave\", onPointerLeave)\n      cancelAnimationFrame(m.raf)\n      // StrictMode remounts: a stale id would stop the loop from ever starting again.\n      m.raf = 0\n      m.draw = () => {}\n    }\n  }, [isLink])\n\n  // Props reach the frame loop here, never during render. A stopped loop redraws at once so the card\n  // shows new settings; a running one picks them up on its next frame.\n  React.useLayoutEffect(() => {\n    const m = motionRef.current\n    m.maxRotation = maxRotation\n    m.maxTranslation = maxTranslation\n    m.depths = stack.map((layer) => layer.depth)\n    m.effects = effects\n    if (!effects) {\n      // Effects switched off (reduced motion, a touch-first device): settle flat at once.\n      cancelAnimationFrame(m.raf)\n      m.raf = 0\n      m.x = m.y = m.tx = m.ty = 0\n      m.moved = false\n    }\n    if (!m.raf) m.draw()\n  })\n\n  // The root may be a link, so the handlers take any element; the consumer's are typed for the div.\n  const handleFocus = (event: React.FocusEvent<HTMLElement>) => {\n    onFocus?.(event as React.FocusEvent<HTMLDivElement>)\n    // Keyboard focus reveals the text like a hover does.\n    if (event.currentTarget.matches(\":focus-visible\")) setActive(true)\n  }\n\n  const handleBlur = (event: React.FocusEvent<HTMLElement>) => {\n    onBlur?.(event as React.FocusEvent<HTMLDivElement>)\n    setActive(false)\n  }\n\n  const handleKeyDown = (event: React.KeyboardEvent<HTMLElement>) => {\n    onKeyDown?.(event as React.KeyboardEvent<HTMLDivElement>)\n    if (href || !onClick || event.defaultPrevented) return\n    if (event.key === \"Enter\" || event.key === \" \") {\n      event.preventDefault()\n      event.currentTarget.click()\n    }\n  }\n\n  const hidden = active ? null : REVEAL_HIDDEN[revealAnimation]\n  const textMotion =\n    revealAnimation === \"none\" ? \"transition-none\" : \"transition-[translate,scale,opacity] duration-500 ease-in-out motion-reduce:transition-opacity\"\n  const lightBackground = `radial-gradient(${SPOTLIGHT_RADIUS}px at 50% 50%, ${spotlightColor} 0%, ${fadedStop(spotlightColor)} 40%, transparent 100%)`\n\n  // A div, a button when it has onClick, or a link when it has href. The rest props are typed for the div.\n  const Root = (href ? \"a\" : \"div\") as React.ElementType\n  const kind = href\n    ? { href, target, rel: target === \"_blank\" ? \"noopener noreferrer\" : undefined }\n    : { role: onClick ? \"button\" : undefined, tabIndex: onClick ? 0 : undefined }\n\n  return (\n    <Root\n      data-slot=\"depth-card\"\n      {...kind}\n      aria-label={ariaLabel ?? (title || undefined)}\n      className={cn(\n        \"relative block flex-none cursor-pointer overflow-hidden text-inherit no-underline outline-none perspective-[1000px] [-webkit-tap-highlight-color:transparent] focus-visible:ring-2 focus-visible:ring-foreground/85 focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n        className\n      )}\n      style={{ width, height, borderRadius, ...style }}\n      onClick={onClick}\n      onFocus={handleFocus}\n      onBlur={handleBlur}\n      onKeyDown={handleKeyDown}\n      {...props}\n    >\n      {/* The tilting surface. Its shadow is swapped, not transitioned: the surface's own clip-path hides it anyway. */}\n      <div\n        ref={cardRef}\n        data-slot=\"depth-card-surface\"\n        className={cn(\n          \"relative size-full bg-muted backface-hidden transform-3d will-change-transform\",\n          active ? \"shadow-[0_20px_40px_rgba(0,0,0,0.4)]\" : \"shadow-[0_10px_20px_rgba(0,0,0,0.2)]\"\n        )}\n        style={{ borderRadius, clipPath: `inset(0px round ${borderRadius})` }}\n      >\n        <div className=\"absolute inset-0 overflow-hidden\" style={{ borderRadius }} role={imageAlt ? \"img\" : undefined} aria-label={imageAlt}>\n          {stack.map((layer, i) => (\n            <div\n              key={i}\n              ref={(el) => {\n                layerRefs.current[i] = el\n              }}\n              data-slot=\"depth-card-layer\"\n              // scale(1.3) is IMAGE_SCALE, for the first paint; the frame loop owns the transform after that.\n              className=\"pointer-events-none absolute inset-0 bg-cover bg-center bg-no-repeat backface-hidden will-change-transform [transform:scale(1.3)]\"\n              style={{ backgroundImage: `url(${JSON.stringify(layer.image)})`, zIndex: i, opacity: i === 0 ? 1 : BACK_LAYER_OPACITY }}\n            />\n          ))}\n        </div>\n        {spotlight && (\n          // Card-sized and never transformed: it clips the light to the card, then blurs and blends it,\n          // exactly as a card-sized gradient would be.\n          <div\n            aria-hidden\n            data-slot=\"depth-card-spotlight\"\n            className={cn(\n              \"pointer-events-none absolute inset-0 z-20 overflow-hidden mix-blend-soft-light blur-[2px] transition-opacity duration-300 ease-out\",\n              active && effects ? \"opacity-100\" : \"opacity-0\"\n            )}\n          >\n            {/* Twice the card (capped at the light's 1200px diameter) and centred on the card's corner, so\n                moved to any point of the card it still covers the card. It waits off the card until the\n                pointer first moves over it. */}\n            <div\n              ref={spotlightRef}\n              data-slot=\"depth-card-light\"\n              className=\"absolute top-0 left-0 size-[min(200%,1200px)] -translate-1/2 will-change-transform [transform:translate3d(-100%,-100%,0)]\"\n              style={{ backgroundImage: lightBackground }}\n            />\n          </div>\n        )}\n        <div\n          data-slot=\"depth-card-content\"\n          className={cn(\"absolute inset-0 z-30 flex flex-col justify-end bg-linear-to-t from-black/80 via-black/40 to-black/0 p-6\", contentClassName)}\n        >\n          {/* The text sits on a dark scrim over the photo, so it stays light in either theme. */}\n          {title && (\n            <h3 className={cn(\"mb-2 text-2xl font-bold text-white\", textMotion, revealAnimation === \"scale\" && \"origin-bottom-left\", hidden?.title)}>\n              {title}\n            </h3>\n          )}\n          {description && (\n            <p\n              className={cn(\"text-sm text-gray-200\", textMotion, revealAnimation === \"scale\" && \"origin-top-left\", hidden?.description)}\n              style={{ transitionDelay: `${staggerDelay}ms` }}\n            >\n              {description}\n            </p>\n          )}\n        </div>\n      </div>\n    </Root>\n  )\n}\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "added": "2026-10-28"
  },
  "categories": [
    "card"
  ],
  "type": "registry:ui"
}