{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "polaroid-stack",
  "title": "Polaroid Stack",
  "author": "VenusUI",
  "description": "A stack of instant photos you drag or swipe through; each one develops as it reaches the top.",
  "dependencies": [
    "lucide-react"
  ],
  "files": [
    {
      "path": "registry/default/ui/polaroid-stack.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ArrowRight } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface Polaroid {\n  src: string\n  alt: string\n  /** Handwritten-style caption under the photo. */\n  caption?: string\n}\n\ninterface PolaroidStackProps extends React.ComponentProps<\"div\"> {\n  photos: Polaroid[]\n}\n\nconst THROW_DISTANCE = 90\n/** Resting tilt of the cards under the top one. */\nconst TILTS = [-2, 5, -7, 3]\nconst HANDWRITING = '\"Segoe Print\", \"Bradley Hand\", \"Marker Felt\", \"Chalkboard SE\", cursive'\n\n/**\n * A stack of instant photos. Drag (or swipe) the top photo off the stack to\n * see the next, or use the \"Next photo\" button or the arrow keys. Each photo\n * develops as it reaches the top.\n */\nfunction PolaroidStack({ photos, className, ...props }: PolaroidStackProps) {\n  const [order, setOrder] = React.useState(() => photos.map((_, i) => i))\n  const [drag, setDrag] = React.useState<{ x: number; y: number } | null>(null)\n  const [thrown, setThrown] = React.useState<{ index: number; direction: number } | null>(null)\n  const start = React.useRef({ x: 0, y: 0 })\n\n  const top = order[0]\n  const next = (direction = 1) => {\n    if (thrown || order.length < 2) return\n    setThrown({ index: top, direction })\n    setDrag(null)\n    // Once it has flown off, put it at the bottom of the stack.\n    setTimeout(() => {\n      setOrder((o) => [...o.slice(1), o[0]])\n      setThrown(null)\n    }, 320)\n  }\n\n  const current = photos[top]\n\n  return (\n    <div data-slot=\"polaroid-stack\" className={cn(\"flex w-full max-w-xs flex-col items-center gap-6\", className)} {...props}>\n      <div\n        className=\"relative aspect-[4/5] w-full touch-pan-y select-none\"\n        role=\"group\"\n        aria-roledescription=\"photo stack\"\n        aria-label={`Photo ${top + 1} of ${photos.length}. Arrow keys show the next photo.`}\n        tabIndex={0}\n        onKeyDown={(event) => {\n          if (event.key === \"ArrowRight\" || event.key === \"ArrowDown\") {\n            event.preventDefault()\n            next(1)\n          }\n          if (event.key === \"ArrowLeft\" || event.key === \"ArrowUp\") {\n            event.preventDefault()\n            next(-1)\n          }\n        }}\n      >\n        {order\n          .slice(0, 4)\n          .reverse()\n          .map((photoIndex) => {\n            const depth = order.indexOf(photoIndex)\n            const photo = photos[photoIndex]\n            const isTop = depth === 0\n            const isThrown = thrown?.index === photoIndex\n            const dx = isTop && drag ? drag.x : 0\n            const dy = isTop && drag ? drag.y : 0\n            const transform = isThrown\n              ? `translate(${thrown.direction * 140}%, -10%) rotate(${thrown.direction * 24}deg)`\n              : `translate(${dx}px, ${dy}px) rotate(${TILTS[depth % TILTS.length] + dx * 0.06}deg) scale(${1 - depth * 0.03})`\n            return (\n              <figure\n                key={photoIndex}\n                aria-hidden={!isTop}\n                className={cn(\n                  \"absolute inset-0 m-0 flex flex-col rounded-[3px] bg-[#fbfaf7] p-[6%] pb-0 shadow-[0_1px_2px_rgb(0_0_0/0.15),0_12px_28px_-12px_rgb(0_0_0/0.45)]\",\n                  isTop ? \"cursor-grab active:cursor-grabbing\" : \"pointer-events-none\",\n                  !(isTop && drag) && \"transition-[transform,opacity] duration-300 ease-out motion-reduce:transition-none\",\n                  isThrown && \"opacity-0\"\n                )}\n                style={{ transform, zIndex: 10 - depth }}\n                onPointerDown={(event) => {\n                  if (!isTop || thrown) return\n                  event.currentTarget.setPointerCapture(event.pointerId)\n                  start.current = { x: event.clientX, y: event.clientY }\n                  setDrag({ x: 0, y: 0 })\n                }}\n                onPointerMove={(event) => {\n                  if (!isTop || !drag) return\n                  setDrag({ x: event.clientX - start.current.x, y: (event.clientY - start.current.y) * 0.4 })\n                }}\n                onPointerUp={() => {\n                  if (!isTop || !drag) return\n                  if (Math.abs(drag.x) > THROW_DISTANCE) next(Math.sign(drag.x))\n                  else setDrag(null)\n                }}\n                onPointerCancel={() => setDrag(null)}\n              >\n                <div className=\"relative aspect-square w-full overflow-hidden bg-neutral-200\">\n                  <img\n                    key={isTop ? `top-${order.join()}` : photoIndex}\n                    src={photo.src}\n                    alt={isTop ? photo.alt : \"\"}\n                    draggable={false}\n                    className={cn(\"size-full object-cover\", isTop && \"animate-polaroid-develop motion-reduce:animate-none\")}\n                  />\n                  <span aria-hidden=\"true\" className=\"absolute inset-0 shadow-[inset_0_0_12px_rgb(0_0_0/0.25)]\" />\n                </div>\n                <figcaption\n                  className=\"flex flex-1 items-center justify-center px-1 text-center text-lg leading-tight text-neutral-700\"\n                  style={{ fontFamily: HANDWRITING }}\n                >\n                  {photo.caption}\n                </figcaption>\n              </figure>\n            )\n          })}\n      </div>\n\n      {photos.length > 1 ? (\n        <button\n          type=\"button\"\n          onClick={() => next(1)}\n          className=\"inline-flex items-center gap-1.5 rounded-full border bg-background px-3.5 py-1.5 text-sm font-medium outline-none hover:bg-muted focus-visible:ring-3 focus-visible:ring-ring/50\"\n        >\n          Next photo <ArrowRight aria-hidden=\"true\" className=\"size-4\" />\n        </button>\n      ) : null}\n      <p aria-live=\"polite\" className=\"sr-only\">\n        {current ? `${current.caption ? `${current.caption}. ` : \"\"}${current.alt}` : \"\"}\n      </p>\n    </div>\n  )\n}\n\nexport { PolaroidStack }\n",
      "type": "registry:ui"
    }
  ],
  "cssVars": {
    "theme": {
      "animate-polaroid-develop": "polaroid-develop 1.6s ease-out both"
    }
  },
  "css": {
    "@keyframes polaroid-develop": {
      "from": {
        "filter": "brightness(1.7) saturate(0.15) contrast(0.7) blur(2px)"
      },
      "to": {
        "filter": "none"
      }
    }
  },
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "interactive",
    "cards"
  ],
  "type": "registry:ui"
}