{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "flip-book",
  "title": "Flip Book",
  "author": "VenusUI",
  "description": "A 3D book whose pages turn with buttons, a click or the arrow keys.",
  "dependencies": [
    "lucide-react"
  ],
  "files": [
    {
      "path": "registry/default/ui/flip-book.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ChevronLeft, ChevronRight } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface FlipBookProps extends React.ComponentProps<\"div\"> {\n  /** Pages in order. The first is the front cover; pages then pair up as left and right. */\n  pages: React.ReactNode[]\n  /** Accessible name, e.g. the book's title. */\n  label: string\n}\n\n/**\n * A book whose pages turn in 3D. Use the buttons, click the left or right\n * page, or focus the book and press the arrow keys. Only the open spread is\n * exposed to screen readers. With reduced motion pages turn instantly.\n */\nfunction FlipBook({ pages, label, className, ...props }: FlipBookProps) {\n  const leaves = Math.ceil(pages.length / 2)\n  const [turned, setTurned] = React.useState(0)\n\n  const go = (delta: number) => setTurned((t) => Math.min(leaves, Math.max(0, t + delta)))\n\n  // Visible pages: the back of the last turned leaf (left) and the front of the next (right).\n  const leftPage = turned > 0 ? 2 * turned - 1 : null\n  const rightPage = turned < leaves ? 2 * turned : null\n  const visible = [leftPage, rightPage].filter((p): p is number => p !== null && p < pages.length)\n  const status =\n    visible.length === 0 ? \"\" : visible.length === 1 ? `Page ${visible[0] + 1} of ${pages.length}` : `Pages ${visible[0] + 1}–${visible[1] + 1} of ${pages.length}`\n\n  // A closed book sits centered; an open one is centered on its spine.\n  const shift = turned === 0 ? \"-25%\" : turned === leaves ? \"25%\" : \"0%\"\n\n  const pageFace = \"absolute inset-0 overflow-hidden bg-[#fdfbf6] text-neutral-800 backface-hidden\"\n\n  return (\n    <div data-slot=\"flip-book\" className={cn(\"flex w-full max-w-3xl flex-col items-center gap-5\", className)} {...props}>\n      <div\n        role=\"group\"\n        aria-roledescription=\"book\"\n        aria-label={`${label}. Use the left and right arrow keys to turn pages.`}\n        tabIndex={0}\n        onKeyDown={(event) => {\n          if (event.key === \"ArrowRight\") {\n            event.preventDefault()\n            go(1)\n          } else if (event.key === \"ArrowLeft\") {\n            event.preventDefault()\n            go(-1)\n          }\n        }}\n        className=\"relative aspect-[3/2] w-full rounded-md outline-none perspective-[2200px] focus-visible:ring-3 focus-visible:ring-ring/50\"\n      >\n        <div\n          className=\"absolute inset-0 transition-transform duration-700 ease-[cubic-bezier(0.45,0.05,0.25,1)] transform-3d motion-reduce:transition-none\"\n          style={{ transform: `translateX(${shift})` }}\n        >\n          {Array.from({ length: leaves }, (_, i) => {\n            const isTurned = i < turned\n            const front = 2 * i\n            const back = 2 * i + 1\n            return (\n              <div\n                key={i}\n                onClick={() => go(isTurned ? -1 : 1)}\n                className=\"absolute top-0 left-1/2 h-full w-1/2 cursor-pointer origin-left transition-transform duration-700 ease-[cubic-bezier(0.45,0.05,0.25,1)] transform-3d motion-reduce:transition-none\"\n                style={{\n                  transform: isTurned ? \"rotateY(-180deg)\" : \"rotateY(0deg)\",\n                  zIndex: isTurned ? i + 1 : leaves - i,\n                }}\n              >\n                {/* Front: a right-hand page. */}\n                <div\n                  aria-hidden={rightPage !== front}\n                  inert={rightPage !== front}\n                  className={cn(pageFace, \"rounded-r-md shadow-[inset_14px_0_18px_-14px_rgb(0_0_0/0.35),0_10px_25px_-12px_rgb(0_0_0/0.4)]\")}\n                >\n                  {pages[front]}\n                </div>\n                {/* Back: a left-hand page. */}\n                <div\n                  aria-hidden={leftPage !== back}\n                  inert={leftPage !== back}\n                  className={cn(pageFace, \"rounded-l-md [transform:rotateY(180deg)] shadow-[inset_-14px_0_18px_-14px_rgb(0_0_0/0.35),0_10px_25px_-12px_rgb(0_0_0/0.4)]\")}\n                >\n                  {pages[back]}\n                </div>\n              </div>\n            )\n          })}\n        </div>\n      </div>\n\n      <div className=\"flex items-center gap-3\">\n        <button\n          type=\"button\"\n          aria-label=\"Previous page\"\n          disabled={turned === 0}\n          onClick={() => go(-1)}\n          className=\"grid size-9 place-items-center rounded-full border outline-none hover:bg-muted focus-visible:ring-3 focus-visible:ring-ring/50 disabled:opacity-40\"\n        >\n          <ChevronLeft aria-hidden=\"true\" className=\"size-4\" />\n        </button>\n        <p aria-live=\"polite\" className=\"min-w-36 text-center text-sm text-muted-foreground tabular-nums\">\n          {turned === 0 ? \"Cover\" : turned === leaves ? \"Back cover\" : status}\n        </p>\n        <button\n          type=\"button\"\n          aria-label=\"Next page\"\n          disabled={turned === leaves}\n          onClick={() => go(1)}\n          className=\"grid size-9 place-items-center rounded-full border outline-none hover:bg-muted focus-visible:ring-3 focus-visible:ring-ring/50 disabled:opacity-40\"\n        >\n          <ChevronRight aria-hidden=\"true\" className=\"size-4\" />\n        </button>\n      </div>\n    </div>\n  )\n}\n\nexport { FlipBook }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "interactive",
    "3d"
  ],
  "type": "registry:ui"
}