{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "photo-album",
  "title": "Photo Album",
  "description": "A bound photo album with a linen cover that opens and pages that turn in 3D: drag or tap to turn, the page lifts when you near its edge, line indicators jump between spreads, and a captioned lightbox opens on any photo.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/photo-album/photo-album.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface PhotoAlbumPhoto {\n  src: string;\n  alt?: string;\n  caption?: string;\n  date?: string;\n}\n\nexport type PhotoAlbumTheme = \"dark\" | \"light\";\n\nexport interface PhotoAlbumProps extends Omit<React.ComponentPropsWithoutRef<\"div\">, \"children\" | \"title\"> {\n  photos?: PhotoAlbumPhoto[];\n  theme?: PhotoAlbumTheme;\n  /** Cover title, repeated on the title page. */\n  title?: string;\n  subtitle?: string;\n  /** Photo shown in the cover window. Defaults to the first photo. */\n  coverImage?: string;\n  /** Size of one page in px; the album scales down to fit narrower containers. */\n  pageWidth?: number;\n  pageHeight?: number;\n  /** 0–1, how quickly a page settles after it's released. */\n  smoothing?: number;\n  /** Lift the page a little when the pointer nears its outer edge. */\n  peekOnHover?: boolean;\n  showLines?: boolean;\n  enableLightbox?: boolean;\n  /** Start on the first spread instead of the closed cover. */\n  startOpen?: boolean;\n}\n\nconst PALETTES = {\n  dark: {\n    background: \"#080808\",\n    paper: \"#151515\",\n    paperEdge: \"#0E0E0E\",\n    edgeLine: \"rgba(255,255,255,0.07)\",\n    ink: \"rgba(255,255,255,0.86)\",\n    inkMuted: \"rgba(255,255,255,0.42)\",\n    rule: \"rgba(255,255,255,0.12)\",\n    cover: \"#1B1B1B\",\n    coverInk: \"rgba(255,255,255,0.88)\",\n    coverRule: \"rgba(255,255,255,0.18)\",\n    photoBorder: \"rgba(255,255,255,0.06)\",\n    lineColor: \"rgba(255,255,255,0.25)\",\n    activeLineColor: \"#FFFFFF\",\n    bookShadow: \"0 30px 60px rgba(0,0,0,0.55), 0 8px 18px rgba(0,0,0,0.4)\",\n    leafShadow: \"0 10px 30px rgba(0,0,0,0.35)\",\n    spine: \"rgba(0,0,0,0.55)\",\n    shade: \"0,0,0\",\n    lightboxBackground: \"rgba(8,8,8,0.95)\",\n    controlColor: \"rgba(255,255,255,0.8)\",\n    emptyText: \"rgba(255,255,255,0.4)\",\n    emptyBorder: \"1.5px dashed rgba(255,255,255,0.15)\",\n  },\n  light: {\n    background: \"#F5F5F3\",\n    paper: \"#FCFBF8\",\n    paperEdge: \"#E8E6E0\",\n    edgeLine: \"rgba(0,0,0,0.08)\",\n    ink: \"rgba(0,0,0,0.82)\",\n    inkMuted: \"rgba(0,0,0,0.42)\",\n    rule: \"rgba(0,0,0,0.1)\",\n    cover: \"#22211F\",\n    coverInk: \"rgba(255,255,255,0.9)\",\n    coverRule: \"rgba(255,255,255,0.2)\",\n    photoBorder: \"rgba(0,0,0,0.06)\",\n    lineColor: \"rgba(0,0,0,0.2)\",\n    activeLineColor: \"#000000\",\n    bookShadow: \"0 24px 50px rgba(0,0,0,0.12), 0 6px 14px rgba(0,0,0,0.08)\",\n    leafShadow: \"0 10px 26px rgba(0,0,0,0.1)\",\n    spine: \"rgba(0,0,0,0.16)\",\n    shade: \"0,0,0\",\n    lightboxBackground: \"rgba(255,255,255,0.96)\",\n    controlColor: \"rgba(0,0,0,0.75)\",\n    emptyText: \"rgba(0,0,0,0.4)\",\n    emptyBorder: \"1.5px dashed rgba(0,0,0,0.15)\",\n  },\n} as const;\n\ntype Palette = (typeof PALETTES)[PhotoAlbumTheme];\n\nconst DEFAULT_PHOTOS: PhotoAlbumPhoto[] = [\n  {\n    src: \"/demo/1.webp\",\n    caption: \"First light in the living room\",\n    date: \"Jan\",\n  },\n  { src: \"/demo/3.webp\", caption: \"Curtains, late spring\", date: \"Apr\" },\n  { src: \"/demo/2.webp\", caption: \"The long hallway\", date: \"Feb\" },\n  { src: \"/demo/4.webp\", caption: \"Sunday breakfast\", date: \"Mar\" },\n  { src: \"/demo/5.webp\", caption: \"Reading corner\", date: \"May\" },\n  { src: \"/demo/6.webp\", caption: \"Stairs to the studio\", date: \"Jun\" },\n  { src: \"/demo/8.webp\", caption: \"Bath, before guests\", date: \"Jul\" },\n  { src: \"/demo/9.webp\", caption: \"Kitchen at dusk\", date: \"Sep\" },\n  { src: \"/demo/10.webp\", caption: \"Tea by the window\", date: \"Oct\" },\n  { src: \"/demo/20.webp\", caption: \"Last evening in the flat\", date: \"Dec\" },\n];\n\nconst clamp = (v: number, min: number, max: number) => Math.min(Math.max(v, min), max);\n\ntype Side = { kind: \"cover\" } | { kind: \"title\" } | { kind: \"photo\"; index: number; page: number } | { kind: \"blank\" } | { kind: \"back\" };\n\n/** Leaves of the book: the cover, the photo leaves, and the back cover. Each has a front (right-hand) and a back (left-hand) side. */\nfunction buildLeaves(count: number): { front: Side; back: Side }[] {\n  const inner: Side[] = [{ kind: \"title\" }];\n  for (let i = 0; i < count; i++) inner.push({ kind: \"photo\", index: i, page: i + 1 });\n  // The back cover's inside must land on a right-hand page, so the inner run needs an odd length.\n  if (inner.length % 2 === 0) inner.push({ kind: \"blank\" });\n  const leaves: { front: Side; back: Side }[] = [{ front: { kind: \"cover\" }, back: inner[0] }];\n  for (let i = 1; i < inner.length; i += 2) leaves.push({ front: inner[i], back: inner[i + 1] });\n  leaves.push({ front: { kind: \"blank\" }, back: { kind: \"back\" } });\n  return leaves;\n}\n\n/** Rotation of leaf `i` for a book turned `turned` leaves: 0 lies on the right, 1 lies on the left. */\nfunction leafProgress(i: number, turned: number) {\n  return clamp(turned - i, 0, 1);\n}\n\nfunction leafTransform(p: number) {\n  // Fixed precision: the same float can print one digit longer on the server than in the browser.\n  return `perspective(2400px) rotateY(${(-180 * p).toFixed(3)}deg)`;\n}\n\nfunction leafZ(i: number, p: number, count: number) {\n  if (p > 0 && p < 1) return 200;\n  return p >= 1 ? 10 + i : 10 + count - i;\n}\n\n/** Closed at either end the book is one page wide, so it slides to stay centred. */\nfunction bookShift(turned: number, count: number, pageWidth: number) {\n  const front = 1 - clamp(turned, 0, 1);\n  const back = clamp(turned - (count - 1), 0, 1);\n  return (-front + back) * (pageWidth / 2);\n}\n\nfunction edgeShadow(n: number, dir: 1 | -1, palette: Palette) {\n  const layers: string[] = [];\n  for (let k = 1; k <= Math.min(n, 5); k++) layers.push(`${dir * k * 1.5}px ${k * 0.5}px 0 ${k % 2 ? palette.paperEdge : palette.edgeLine}`);\n  return layers.length ? layers.join(\", \") : \"none\";\n}\n\nexport function PhotoAlbum({\n  photos = DEFAULT_PHOTOS,\n  theme = \"dark\",\n  title = \"Quiet Rooms\",\n  subtitle = \"A year at home · 2026\",\n  coverImage,\n  pageWidth = 300,\n  pageHeight = 400,\n  smoothing = 0.1,\n  peekOnHover = true,\n  showLines = true,\n  enableLightbox = true,\n  startOpen = false,\n  className,\n  ...props\n}: PhotoAlbumProps) {\n  const palette = PALETTES[theme];\n  const leaves = React.useMemo(() => buildLeaves(photos.length), [photos.length]);\n  const count = leaves.length;\n  const startAt = startOpen ? 1 : 0;\n\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const bookRef = React.useRef<HTMLDivElement>(null);\n  const leafRefs = React.useRef<(HTMLDivElement | null)[]>([]);\n  const frontShadeRefs = React.useRef<(HTMLDivElement | null)[]>([]);\n  const backShadeRefs = React.useRef<(HTMLDivElement | null)[]>([]);\n  const leftStackRef = React.useRef<HTMLDivElement>(null);\n  const rightStackRef = React.useRef<HTMLDivElement>(null);\n\n  const turnedRef = React.useRef(startAt);\n  const restRef = React.useRef(startAt);\n  const targetRef = React.useRef(startAt);\n  const rafRef = React.useRef<number | null>(null);\n  const wakeRef = React.useRef<() => void>(() => {});\n  const dragRef = React.useRef({\n    active: false,\n    moved: false,\n    startX: 0,\n    startRest: 0,\n    lastX: 0,\n    lastT: 0,\n    velocity: 0,\n    photo: null as number | null,\n  });\n\n  const [scale, setScale] = React.useState(1);\n  const scaleRef = React.useRef(1);\n  const [spread, setSpread] = React.useState(startAt);\n  const [lightboxIndex, setLightboxIndex] = React.useState<number | null>(null);\n  const dialogRef = React.useRef<HTMLDivElement>(null);\n  const closeButtonRef = React.useRef<HTMLButtonElement>(null);\n  const lastFocusedRef = React.useRef<HTMLElement | null>(null);\n\n  const optsRef = React.useRef({\n    smoothing,\n    peekOnHover,\n    enableLightbox,\n    pageWidth,\n    count,\n    palette,\n  });\n  React.useEffect(() => {\n    optsRef.current = {\n      smoothing,\n      peekOnHover,\n      enableLightbox,\n      pageWidth,\n      count,\n      palette,\n    };\n  }, [smoothing, peekOnHover, enableLightbox, pageWidth, count, palette]);\n\n  // Fit the open spread (two pages) into the container.\n  React.useEffect(() => {\n    const el = rootRef.current;\n    if (!el) return;\n    const update = () => {\n      const s = clamp((el.clientWidth - 32) / (pageWidth * 2), 0.3, 1);\n      scaleRef.current = s;\n      setScale(s);\n    };\n    update();\n    const observer = new ResizeObserver(update);\n    observer.observe(el);\n    return () => observer.disconnect();\n  }, [pageWidth]);\n\n  React.useEffect(() => {\n    const paint = (turned: number) => {\n      const { count, pageWidth, palette } = optsRef.current;\n      leafRefs.current.forEach((el, i) => {\n        if (!el) return;\n        const p = leafProgress(i, turned);\n        el.style.transform = leafTransform(p);\n        el.style.zIndex = String(leafZ(i, p, count));\n        const front = frontShadeRefs.current[i];\n        const back = backShadeRefs.current[i];\n        if (front) front.style.opacity = (p < 0.5 ? p * 1.1 : 0).toFixed(3);\n        if (back) back.style.opacity = (p > 0.5 ? (1 - p) * 1.1 : 0).toFixed(3);\n        // Swap faces at the fold ourselves: backface-visibility alone isn't honoured by every WebKit renderer.\n        const lift = p > 0 && p < 1 ? palette.leafShadow : \"none\";\n        if (front?.parentElement) {\n          front.parentElement.style.visibility = p < 0.5 ? \"visible\" : \"hidden\";\n          front.parentElement.style.boxShadow = lift;\n        }\n        if (back?.parentElement) {\n          back.parentElement.style.visibility = p < 0.5 ? \"hidden\" : \"visible\";\n          back.parentElement.style.boxShadow = lift;\n        }\n      });\n      if (bookRef.current) bookRef.current.style.transform = `translateX(${bookShift(turned, count, pageWidth).toFixed(2)}px)`;\n      const onLeft = Math.floor(turned);\n      // One base shadow per side that holds pages; the leaves themselves only cast one while they're in the air.\n      const withBase = (edges: string, has: boolean) => (has ? (edges === \"none\" ? palette.bookShadow : `${edges}, ${palette.bookShadow}`) : \"none\");\n      if (leftStackRef.current) leftStackRef.current.style.boxShadow = withBase(edgeShadow(onLeft - 1, -1, palette), turned >= 0.5);\n      if (rightStackRef.current) rightStackRef.current.style.boxShadow = withBase(edgeShadow(count - Math.ceil(turned) - 1, 1, palette), turned <= count - 0.5);\n    };\n\n    const tick = () => {\n      const drag = dragRef.current;\n      const k = drag.active && drag.moved ? 0.32 : optsRef.current.smoothing;\n      const diff = targetRef.current - turnedRef.current;\n      turnedRef.current += diff * k;\n      const settled = Math.abs(targetRef.current - turnedRef.current) < 0.0008 && !drag.active;\n      if (settled) turnedRef.current = targetRef.current;\n      paint(turnedRef.current);\n      rafRef.current = settled ? null : requestAnimationFrame(tick);\n    };\n\n    wakeRef.current = () => {\n      if (rafRef.current === null) rafRef.current = requestAnimationFrame(tick);\n    };\n    paint(turnedRef.current);\n    return () => {\n      if (rafRef.current) cancelAnimationFrame(rafRef.current);\n      rafRef.current = null;\n    };\n  }, [count]);\n\n  const goTo = React.useCallback((next: number) => {\n    const clamped = clamp(Math.round(next), 0, optsRef.current.count);\n    restRef.current = clamped;\n    targetRef.current = clamped;\n    setSpread(clamped);\n    wakeRef.current();\n  }, []);\n\n  // Pointer: drag to turn, tap a photo for the lightbox, tap a page to turn it, hover an outer edge to peek.\n  React.useEffect(() => {\n    const el = bookRef.current?.parentElement;\n    if (!el) return;\n\n    const pageW = () => optsRef.current.pageWidth * scaleRef.current;\n\n    const onDown = (e: PointerEvent) => {\n      if (e.button !== 0) return;\n      const photoEl = (e.target as HTMLElement).closest<HTMLElement>(\"[data-photo-index]\");\n      dragRef.current = {\n        active: true,\n        moved: false,\n        startX: e.clientX,\n        startRest: restRef.current,\n        lastX: e.clientX,\n        lastT: e.timeStamp,\n        velocity: 0,\n        photo: photoEl ? Number(photoEl.dataset.photoIndex) : null,\n      };\n      el.setPointerCapture(e.pointerId);\n    };\n\n    const onMove = (e: PointerEvent) => {\n      const drag = dragRef.current;\n      if (drag.active) {\n        const dx = e.clientX - drag.startX;\n        if (!drag.moved && Math.abs(dx) > 6) {\n          drag.moved = true;\n          el.style.cursor = \"grabbing\";\n        }\n        if (drag.moved) {\n          const dt = Math.max(e.timeStamp - drag.lastT, 1);\n          drag.velocity = drag.velocity * 0.6 + ((e.clientX - drag.lastX) / dt) * 0.4;\n          drag.lastX = e.clientX;\n          drag.lastT = e.timeStamp;\n          const { count } = optsRef.current;\n          const lo = Math.max(0, drag.startRest - 1);\n          const hi = Math.min(count, drag.startRest + 1);\n          targetRef.current = clamp(drag.startRest - dx / (pageW() * 1.6), lo, hi);\n          wakeRef.current();\n        }\n        return;\n      }\n      if (e.pointerType !== \"mouse\" || !optsRef.current.peekOnHover) return;\n      // Peek: the outer 16% of an open page lifts that page a little.\n      const book = bookRef.current?.getBoundingClientRect();\n      if (!book) return;\n      const rest = restRef.current;\n      const { count } = optsRef.current;\n      const w = pageW();\n      const spineX = book.left + w;\n      const x = e.clientX - spineX;\n      let peek = 0;\n      if (rest < count && x > w * 0.84 && x < w) peek = rest === 0 ? 0.035 : 0.06;\n      else if (rest > 0 && x < -w * 0.84 && x > -w) peek = rest === count ? -0.035 : -0.06;\n      const nextTarget = rest + peek;\n      if (nextTarget !== targetRef.current) {\n        targetRef.current = nextTarget;\n        wakeRef.current();\n      }\n    };\n\n    const onUp = (e: PointerEvent) => {\n      const drag = dragRef.current;\n      if (!drag.active) return;\n      drag.active = false;\n      el.style.cursor = \"\";\n      if (drag.moved) {\n        // A flick finishes the turn even when the page hasn't crossed halfway.\n        const flick = clamp(-drag.velocity * 0.35, -0.45, 0.45);\n        goTo(targetRef.current + flick);\n        return;\n      }\n      const { enableLightbox } = optsRef.current;\n      if (drag.photo !== null && enableLightbox) {\n        setLightboxIndex(drag.photo);\n        return;\n      }\n      const book = bookRef.current?.getBoundingClientRect();\n      if (!book) return;\n      const spineX = book.left + pageW();\n      goTo(restRef.current + (e.clientX >= spineX ? 1 : -1));\n    };\n\n    const onLeave = () => {\n      if (dragRef.current.active) return;\n      if (targetRef.current !== restRef.current) {\n        targetRef.current = restRef.current;\n        wakeRef.current();\n      }\n    };\n\n    el.addEventListener(\"pointerdown\", onDown);\n    el.addEventListener(\"pointermove\", onMove);\n    el.addEventListener(\"pointerup\", onUp);\n    el.addEventListener(\"pointercancel\", onUp);\n    el.addEventListener(\"pointerleave\", onLeave);\n    return () => {\n      el.removeEventListener(\"pointerdown\", onDown);\n      el.removeEventListener(\"pointermove\", onMove);\n      el.removeEventListener(\"pointerup\", onUp);\n      el.removeEventListener(\"pointercancel\", onUp);\n      el.removeEventListener(\"pointerleave\", onLeave);\n    };\n  }, [goTo]);\n\n  React.useEffect(() => {\n    if (lightboxIndex === null) {\n      lastFocusedRef.current?.focus();\n      lastFocusedRef.current = null;\n      return;\n    }\n    lastFocusedRef.current = document.activeElement as HTMLElement | null;\n    closeButtonRef.current?.focus();\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [lightboxIndex !== null]);\n\n  React.useEffect(() => {\n    if (lightboxIndex === null) return;\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") setLightboxIndex(null);\n      else if (e.key === \"ArrowRight\") setLightboxIndex((i) => (i === null ? null : (i + 1) % photos.length));\n      else if (e.key === \"ArrowLeft\") setLightboxIndex((i) => (i === null ? null : (i - 1 + photos.length) % photos.length));\n      else if (e.key === \"Tab\") {\n        const focusables = Array.from(dialogRef.current?.querySelectorAll<HTMLElement>(\"button\") ?? []);\n        if (focusables.length === 0) return;\n        const first = focusables[0];\n        const last = focusables[focusables.length - 1];\n        if (e.shiftKey && document.activeElement === first) {\n          e.preventDefault();\n          last.focus();\n        } else if (!e.shiftKey && document.activeElement === last) {\n          e.preventDefault();\n          first.focus();\n        }\n      }\n    };\n    window.addEventListener(\"keydown\", onKey);\n    return () => window.removeEventListener(\"keydown\", onKey);\n  }, [lightboxIndex, photos.length]);\n\n  const onKeyDown = (e: React.KeyboardEvent) => {\n    if (lightboxIndex !== null) return;\n    if (e.key === \"ArrowRight\") goTo(restRef.current + 1);\n    else if (e.key === \"ArrowLeft\") goTo(restRef.current - 1);\n    else if (e.key === \"Home\") goTo(0);\n    else if (e.key === \"End\") goTo(count);\n    else return;\n    e.preventDefault();\n  };\n\n  if (photos.length === 0) {\n    return (\n      <div\n        className={cn(\"flex h-full w-full items-center justify-center rounded-xl\", className)}\n        style={{\n          minHeight: 300,\n          background: palette.background,\n          border: palette.emptyBorder,\n        }}\n        {...props}\n      >\n        <span className=\"text-center text-sm leading-[1.6]\" style={{ color: palette.emptyText }}>\n          Add photos\n        </span>\n      </div>\n    );\n  }\n\n  const cover = coverImage ?? photos[0].src;\n  const renderSide = (side: Side, align: \"left\" | \"right\") => {\n    const spineShadow = align === \"right\" ? `linear-gradient(90deg, ${palette.spine} 0%, transparent 9%)` : `linear-gradient(270deg, ${palette.spine} 0%, transparent 9%)`;\n    if (side.kind === \"cover\" || side.kind === \"back\") {\n      const isFront = side.kind === \"cover\";\n      return (\n        <div\n          className=\"absolute inset-0 overflow-hidden\"\n          style={{\n            background: palette.cover,\n            borderRadius: align === \"right\" ? \"2px 4px 4px 2px\" : \"4px 2px 2px 4px\",\n          }}\n        >\n          {/* linen weave */}\n          <div\n            className=\"absolute inset-0 opacity-[0.35]\"\n            style={{\n              backgroundImage: \"repeating-linear-gradient(0deg, rgba(255,255,255,0.035) 0 1px, transparent 1px 3px), repeating-linear-gradient(90deg, rgba(0,0,0,0.25) 0 1px, transparent 1px 3px)\",\n            }}\n          />\n          <div className=\"absolute\" style={{ inset: 14, border: `1px solid ${palette.coverRule}` }} />\n          {isFront ? (\n            <div className=\"absolute flex flex-col items-center\" style={{ inset: 14, paddingTop: 40 }}>\n              <div\n                className=\"overflow-hidden\"\n                style={{\n                  width: \"62%\",\n                  aspectRatio: \"4 / 5\",\n                  boxShadow: \"inset 0 0 0 1px rgba(255,255,255,0.12), 0 6px 18px rgba(0,0,0,0.45)\",\n                }}\n              >\n                <img src={cover} alt=\"\" draggable={false} className=\"pointer-events-none block h-full w-full object-cover select-none\" />\n              </div>\n              <div\n                className=\"mt-7 text-center font-light tracking-[0.02em]\"\n                style={{\n                  color: palette.coverInk,\n                  fontSize: 26,\n                  lineHeight: 1.1,\n                }}\n              >\n                {title}\n              </div>\n              <div\n                className=\"mt-2 text-center uppercase\"\n                style={{\n                  color: palette.coverInk,\n                  opacity: 0.55,\n                  fontSize: 9.5,\n                  letterSpacing: \"0.22em\",\n                }}\n              >\n                {subtitle}\n              </div>\n            </div>\n          ) : (\n            <div\n              className=\"absolute inset-x-0 bottom-9 text-center uppercase\"\n              style={{\n                color: palette.coverInk,\n                opacity: 0.4,\n                fontSize: 9,\n                letterSpacing: \"0.3em\",\n              }}\n            >\n              {photos.length} photographs\n            </div>\n          )}\n          <div\n            className=\"absolute inset-0\"\n            style={{\n              background: align === \"right\" ? \"linear-gradient(90deg, rgba(0,0,0,0.35) 0%, transparent 6%)\" : \"linear-gradient(270deg, rgba(0,0,0,0.35) 0%, transparent 6%)\",\n            }}\n          />\n        </div>\n      );\n    }\n    return (\n      <div\n        className=\"absolute inset-0 overflow-hidden\"\n        style={{\n          background: palette.paper,\n          borderRadius: align === \"right\" ? \"0 3px 3px 0\" : \"3px 0 0 3px\",\n        }}\n      >\n        {side.kind === \"title\" && (\n          <div className=\"absolute inset-0 flex flex-col items-center justify-center px-8 text-center\">\n            <div style={{ width: 28, height: 1, background: palette.rule }} />\n            <div className=\"mt-6 font-light\" style={{ color: palette.ink, fontSize: 24, lineHeight: 1.15 }}>\n              {title}\n            </div>\n            <div\n              className=\"mt-2 uppercase\"\n              style={{\n                color: palette.inkMuted,\n                fontSize: 9.5,\n                letterSpacing: \"0.22em\",\n              }}\n            >\n              {subtitle}\n            </div>\n            <div className=\"mt-6\" style={{ width: 28, height: 1, background: palette.rule }} />\n            <div\n              className=\"absolute inset-x-0 bottom-8 tabular-nums\"\n              style={{\n                color: palette.inkMuted,\n                fontSize: 10,\n                letterSpacing: \"0.12em\",\n              }}\n            >\n              {String(photos.length).padStart(2, \"0\")} PHOTOGRAPHS\n            </div>\n          </div>\n        )}\n        {side.kind === \"photo\" && (\n          <div className=\"absolute flex flex-col\" style={{ inset: \"26px 24px 22px\" }}>\n            <div\n              data-photo-index={side.index}\n              className=\"relative min-h-0 flex-1 overflow-hidden\"\n              style={{\n                boxShadow: `0 0 0 1px ${palette.photoBorder}, 0 4px 14px rgba(0,0,0,${theme === \"dark\" ? 0.4 : 0.12})`,\n                cursor: enableLightbox ? \"zoom-in\" : undefined,\n              }}\n            >\n              <img\n                src={photos[side.index].src}\n                alt={photos[side.index].alt || photos[side.index].caption || \"\"}\n                draggable={false}\n                className=\"pointer-events-none block h-full w-full object-cover select-none\"\n              />\n            </div>\n            <div className=\"mt-3.5 flex items-baseline justify-between gap-3\">\n              <span className=\"truncate\" style={{ color: palette.ink, fontSize: 11.5 }}>\n                {photos[side.index].caption}\n              </span>\n              {photos[side.index].date && (\n                <span\n                  className=\"shrink-0 uppercase tabular-nums\"\n                  style={{\n                    color: palette.inkMuted,\n                    fontSize: 9.5,\n                    letterSpacing: \"0.16em\",\n                  }}\n                >\n                  {photos[side.index].date}\n                </span>\n              )}\n            </div>\n            <div\n              className=\"mt-2.5 tabular-nums\"\n              style={{\n                color: palette.inkMuted,\n                fontSize: 9.5,\n                letterSpacing: \"0.12em\",\n                textAlign: align === \"right\" ? \"right\" : \"left\",\n              }}\n            >\n              {String(side.page).padStart(2, \"0\")}\n            </div>\n          </div>\n        )}\n        <div className=\"pointer-events-none absolute inset-0\" style={{ background: spineShadow }} />\n      </div>\n    );\n  };\n\n  const shade = palette.shade;\n  const lines = Array.from({ length: count + 1 }, (_, i) => i);\n  const status = spread === 0 ? \"Front cover\" : spread === count ? \"Back cover\" : `Spread ${spread} of ${count - 1}`;\n\n  return (\n    <div\n      ref={rootRef}\n      className={cn(\"relative flex w-full flex-col items-center justify-center overflow-hidden outline-none\", className)}\n      style={{\n        background: palette.background,\n        minHeight: pageHeight * scale + (showLines ? 140 : 80),\n      }}\n      tabIndex={0}\n      role=\"region\"\n      aria-roledescription=\"photo album\"\n      aria-label={title}\n      onKeyDown={onKeyDown}\n      {...props}\n    >\n      <span className=\"sr-only\" aria-live=\"polite\">\n        {status}\n      </span>\n\n      <div className=\"relative\" style={{ width: pageWidth * 2 * scale, height: pageHeight * scale }}>\n        <div\n          className=\"absolute top-0 left-0 cursor-grab touch-pan-y select-none\"\n          style={{\n            width: pageWidth * 2,\n            height: pageHeight,\n            transform: `scale(${scale})`,\n            transformOrigin: \"0 0\",\n          }}\n        >\n          <div\n            ref={bookRef}\n            className=\"absolute inset-0\"\n            style={{\n              transform: `translateX(${bookShift(startAt, count, pageWidth).toFixed(2)}px)`,\n            }}\n          >\n            {/* page stacks: thin offset edges, one per unturned leaf */}\n            <div ref={leftStackRef} className=\"absolute top-0 left-0 transition-shadow duration-300\" style={{ width: pageWidth, height: pageHeight, borderRadius: 3 }} />\n            <div\n              ref={rightStackRef}\n              className=\"absolute top-0 transition-shadow duration-300\"\n              style={{\n                left: pageWidth,\n                width: pageWidth,\n                height: pageHeight,\n                borderRadius: 3,\n              }}\n            />\n\n            {leaves.map((leaf, i) => {\n              const p = leafProgress(i, startAt);\n              return (\n                <div\n                  key={i}\n                  ref={(el) => {\n                    leafRefs.current[i] = el;\n                  }}\n                  className=\"absolute top-0\"\n                  style={{\n                    left: pageWidth,\n                    width: pageWidth,\n                    height: pageHeight,\n                    transformOrigin: \"0 50%\",\n                    transformStyle: \"preserve-3d\",\n                    transform: leafTransform(p),\n                    zIndex: leafZ(i, p, count),\n                  }}\n                >\n                  <div\n                    className=\"absolute inset-0\"\n                    style={{\n                      visibility: p < 0.5 ? \"visible\" : \"hidden\",\n                      backfaceVisibility: \"hidden\",\n                      WebkitBackfaceVisibility: \"hidden\",\n                      borderRadius: 3,\n                    }}\n                  >\n                    {renderSide(leaf.front, \"right\")}\n                    <div\n                      ref={(el) => {\n                        frontShadeRefs.current[i] = el;\n                      }}\n                      className=\"pointer-events-none absolute inset-0\"\n                      style={{\n                        opacity: 0,\n                        background: `linear-gradient(90deg, rgba(${shade},0.05) 0%, rgba(${shade},0.45) 100%)`,\n                      }}\n                    />\n                  </div>\n                  <div\n                    className=\"absolute inset-0\"\n                    style={{\n                      transform: \"rotateY(180deg)\",\n                      visibility: p < 0.5 ? \"hidden\" : \"visible\",\n                      backfaceVisibility: \"hidden\",\n                      WebkitBackfaceVisibility: \"hidden\",\n                      borderRadius: 3,\n                    }}\n                  >\n                    {renderSide(leaf.back, \"left\")}\n                    <div\n                      ref={(el) => {\n                        backShadeRefs.current[i] = el;\n                      }}\n                      className=\"pointer-events-none absolute inset-0\"\n                      style={{\n                        opacity: 0,\n                        background: `linear-gradient(270deg, rgba(${shade},0.05) 0%, rgba(${shade},0.4) 100%)`,\n                      }}\n                    />\n                  </div>\n                </div>\n              );\n            })}\n          </div>\n        </div>\n      </div>\n\n      {showLines && (\n        <div className=\"mt-12 flex items-center justify-center gap-1.5\" style={{ height: 24 }}>\n          {lines.map((i) => {\n            const isActive = i === spread;\n            return (\n              <button\n                key={i}\n                type=\"button\"\n                onClick={() => goTo(i)}\n                aria-label={i === 0 ? \"Front cover\" : i === count ? \"Back cover\" : `Spread ${i}`}\n                aria-current={isActive ? \"true\" : undefined}\n                className=\"flex h-6 cursor-pointer items-center justify-center border-0 bg-transparent p-0 px-[3px]\"\n              >\n                <span\n                  className=\"block transition-[height,background] duration-[250ms] ease-[ease]\"\n                  style={{\n                    width: 1,\n                    height: isActive ? 20 : 14,\n                    background: isActive ? palette.activeLineColor : palette.lineColor,\n                  }}\n                />\n              </button>\n            );\n          })}\n        </div>\n      )}\n\n      {enableLightbox &&\n        lightboxIndex !== null &&\n        createPortal(\n          <div\n            ref={dialogRef}\n            onClick={() => setLightboxIndex(null)}\n            role=\"dialog\"\n            aria-modal=\"true\"\n            aria-label=\"Photo preview\"\n            className=\"fixed inset-0 z-[999999] flex flex-col items-center justify-center\"\n            style={{ background: palette.lightboxBackground }}\n          >\n            <button\n              ref={closeButtonRef}\n              onClick={(e) => {\n                e.stopPropagation();\n                setLightboxIndex(null);\n              }}\n              aria-label=\"Close\"\n              className=\"absolute top-6 right-8 h-10 w-10 cursor-pointer border-0 bg-transparent text-[28px] leading-none\"\n              style={{ color: palette.controlColor }}\n            >\n              ×\n            </button>\n            {photos.length > 1 && (\n              <>\n                <button\n                  onClick={(e) => {\n                    e.stopPropagation();\n                    setLightboxIndex((lightboxIndex - 1 + photos.length) % photos.length);\n                  }}\n                  aria-label=\"Previous\"\n                  className=\"absolute top-1/2 left-6 h-11 w-11 -translate-y-1/2 cursor-pointer border-0 bg-transparent text-[32px]\"\n                  style={{ color: palette.controlColor }}\n                >\n                  ‹\n                </button>\n                <button\n                  onClick={(e) => {\n                    e.stopPropagation();\n                    setLightboxIndex((lightboxIndex + 1) % photos.length);\n                  }}\n                  aria-label=\"Next\"\n                  className=\"absolute top-1/2 right-6 h-11 w-11 -translate-y-1/2 cursor-pointer border-0 bg-transparent text-[32px]\"\n                  style={{ color: palette.controlColor }}\n                >\n                  ›\n                </button>\n              </>\n            )}\n            <img\n              src={photos[lightboxIndex].src}\n              alt={photos[lightboxIndex].alt || photos[lightboxIndex].caption || \"\"}\n              onClick={(e) => e.stopPropagation()}\n              className=\"max-w-[82%] object-contain\"\n              style={{\n                maxHeight: \"78%\",\n                borderRadius: 4,\n                boxShadow: \"0 20px 60px rgba(0,0,0,0.6)\",\n              }}\n              draggable={false}\n            />\n            {(photos[lightboxIndex].caption || photos[lightboxIndex].date) && (\n              <div className=\"mt-5 flex items-baseline gap-3 text-[13px]\" style={{ color: palette.controlColor }} onClick={(e) => e.stopPropagation()}>\n                <span>{photos[lightboxIndex].caption}</span>\n                <span className=\"text-[11px] tracking-[0.16em] uppercase tabular-nums opacity-60\">\n                  {String(lightboxIndex + 1).padStart(2, \"0\")} / {String(photos.length).padStart(2, \"0\")}\n                </span>\n              </div>\n            )}\n          </div>,\n          document.body,\n        )}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}