{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "carousel-lightbox",
  "type": "registry:component",
  "title": "Carousel Lightbox",
  "description": "A thumbnail strip where each image opens in a lightbox. The picture zooms out of its thumbnail and flies back on close, with previous and next, Escape and a focus trap.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "components",
    "carousel",
    "lightbox",
    "gallery",
    "thumbnails",
    "zoom",
    "modal"
  ],
  "docs": "https://hyperblur.dev/effects/carousel-lightbox",
  "files": [
    {
      "path": "registry/hyperblur/carousel-lightbox.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/carousel-lightbox.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { createPortal } from \"react-dom\";\n\nexport interface LightboxImage {\n  src?: string;\n  alt?: string;\n  caption?: string;\n}\n\nexport interface CarouselLightboxProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"children\"> {\n  images?: LightboxImage[];\n  accent?: string;\n  thumbWidth?: number;\n}\n\nconst palette = [\n  [\"#f6a85b\", \"#5b2a86\"],\n  [\"#9fd3e6\", \"#2a4a6b\"],\n  [\"#2b3b66\", \"#0a0f1f\"],\n  [\"#f2c6a0\", \"#b4505a\"],\n  [\"#a6e3b4\", \"#14593f\"],\n  [\"#c9b6ff\", \"#2b2a6e\"],\n  [\"#ffd37a\", \"#c4452f\"],\n  [\"#7fe0e0\", \"#123b55\"],\n];\n\nconst defaults: LightboxImage[] = [\n  { alt: \"Dune light\", caption: \"Dune light, Namib coast\" },\n  { alt: \"Harbor fog\", caption: \"Harbor fog before the first ferry\" },\n  { alt: \"Night orchard\", caption: \"Night orchard, long exposure\" },\n  { alt: \"Rose cliffs\", caption: \"Rose cliffs at low tide\" },\n  { alt: \"Fern valley\", caption: \"Fern valley after rain\" },\n  { alt: \"Violet pass\", caption: \"Violet pass above the cloud line\" },\n  { alt: \"Ember road\", caption: \"Ember road, late August\" },\n  { alt: \"Glass bay\", caption: \"Glass bay at slack water\" },\n];\n\nfunction hash(n: number) {\n  let h = Math.imul(n + 1, 374761393);\n  h = Math.imul(h ^ (h >>> 13), 1274126177);\n  return (h ^ (h >>> 16)) >>> 0;\n}\n\nfunction Scene({ index, image }: { index: number; image: LightboxImage }) {\n  if (image.src) {\n    return (\n      <div\n        className=\"hb-za1-scene hb-za1-img\"\n        role=\"img\"\n        aria-label={image.alt ?? \"\"}\n        style={{ backgroundImage: `url(${JSON.stringify(image.src)})` }}\n      />\n    );\n  }\n  const h = hash(index);\n  const [c1, c2] = palette[index % palette.length];\n  const sx = 70 + (h % 260);\n  const sy = 64 + ((h >>> 8) % 60);\n  const r = 20 + ((h >>> 16) % 22);\n  const a = 180 + ((h >>> 4) % 50);\n  const b = 215 + ((h >>> 12) % 40);\n  return (\n    <div\n      className=\"hb-za1-scene\"\n      role=\"img\"\n      aria-label={image.alt ?? \"\"}\n      style={{ background: `linear-gradient(165deg, ${c1}, ${c2})` }}\n    >\n      <svg viewBox=\"0 0 400 300\" preserveAspectRatio=\"xMidYMid slice\" aria-hidden=\"true\">\n        <circle cx={sx} cy={sy} r={r.toFixed(1)} fill=\"#ffffff\" fillOpacity=\"0.82\" />\n        <circle cx={sx} cy={sy} r={(r * 2).toFixed(1)} fill=\"#ffffff\" fillOpacity=\"0.1\" />\n        <path\n          d={`M0 ${a} Q 100 ${a - 56} 200 ${a - 12} T 400 ${a - 34} V300 H0Z`}\n          fill=\"#000000\"\n          fillOpacity=\"0.22\"\n        />\n        <path\n          d={`M0 ${b} Q 120 ${b - 44} 230 ${b - 6} T 400 ${b - 22} V300 H0Z`}\n          fill=\"#000000\"\n          fillOpacity=\"0.38\"\n        />\n      </svg>\n    </div>\n  );\n}\n\nconst css = `\n.hb-za1 {\n  --hb-za1-c: #2f7bff;\n  --hb-za1-w: 112px;\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  font-family: inherit;\n  color: #ededed;\n}\n.hb-za1 *, .hb-za1 *::before, .hb-za1 *::after { box-sizing: border-box; }\n.hb-za1-strip {\n  display: flex;\n  gap: 10px;\n  padding: 4px;\n  overflow-x: auto;\n  scroll-snap-type: x mandatory;\n  scrollbar-width: none;\n  -webkit-overflow-scrolling: touch;\n}\n.hb-za1-strip::-webkit-scrollbar { display: none; }\n.hb-za1-thumb {\n  position: relative;\n  flex: 0 0 var(--hb-za1-w);\n  aspect-ratio: 4 / 3;\n  margin: 0;\n  padding: 0;\n  overflow: hidden;\n  font: inherit;\n  color: inherit;\n  background: #171717;\n  border: 1px solid #262626;\n  border-radius: 10px;\n  cursor: zoom-in;\n  scroll-snap-align: start;\n  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), border-color 0.2s ease, box-shadow 0.25s ease;\n}\n.hb-za1-thumb:hover { transform: translateY(-2px); border-color: #3a3a3a; }\n.hb-za1-thumb:focus-visible { outline: 2px solid var(--hb-za1-c); outline-offset: 2px; }\n.hb-za1-thumb[data-open=\"true\"] { visibility: hidden; }\n.hb-za1-thumb::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  pointer-events: none;\n  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.28) 50%, transparent 65%);\n  transform: translateX(-120%);\n  animation: hb-za1-glint 7s ease-in-out infinite;\n  animation-delay: calc(var(--hb-za1-i, 0) * 0.55s);\n}\n.hb-za1-scene { position: absolute; inset: 0; overflow: hidden; }\n.hb-za1-scene svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }\n.hb-za1-img { background-size: cover; background-position: center; user-select: none; }\n.hb-za1-nav {\n  position: absolute;\n  top: 50%;\n  z-index: 2;\n  display: grid;\n  place-items: center;\n  width: 28px;\n  height: 28px;\n  margin: -14px 0 0;\n  padding: 0;\n  color: #ededed;\n  background: rgba(10, 10, 10, 0.78);\n  border: 1px solid #333333;\n  border-radius: 999px;\n  cursor: pointer;\n  backdrop-filter: blur(6px);\n  -webkit-backdrop-filter: blur(6px);\n  transition: opacity 0.2s ease, transform 0.2s ease, background 0.2s ease;\n}\n.hb-za1-nav:hover { background: #1c1c1c; }\n.hb-za1-nav:focus-visible { outline: 2px solid var(--hb-za1-c); outline-offset: 2px; }\n.hb-za1-nav[data-side=\"prev\"] { left: -6px; }\n.hb-za1-nav[data-side=\"next\"] { right: -6px; }\n.hb-za1-nav:disabled { opacity: 0; pointer-events: none; transform: scale(0.8); }\n.hb-za1-nav svg { width: 14px; height: 14px; }\n.hb-za1-box {\n  position: fixed;\n  inset: 0;\n  z-index: 2147483000;\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: center;\n  gap: 14px;\n  font-family: inherit;\n  color: #ededed;\n  outline: none;\n}\n.hb-za1-box *, .hb-za1-box *::before, .hb-za1-box *::after { box-sizing: border-box; }\n.hb-za1-scrim {\n  position: absolute;\n  inset: 0;\n  background: rgba(4, 4, 6, 0.86);\n  backdrop-filter: blur(10px);\n  -webkit-backdrop-filter: blur(10px);\n  opacity: 1;\n  transition: opacity 0.3s ease;\n  animation: hb-za1-fade 0.3s ease;\n}\n.hb-za1-box[data-closing=\"true\"] .hb-za1-scrim,\n.hb-za1-box[data-closing=\"true\"] .hb-za1-ui { opacity: 0; }\n.hb-za1-stage {\n  position: relative;\n  z-index: 1;\n  width: min(92vw, calc((100vh - 170px) * 1.3333), 760px);\n  aspect-ratio: 4 / 3;\n  overflow: hidden;\n  background: #171717;\n  border-radius: 14px;\n  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.08);\n  transform-origin: 0 0;\n}\n.hb-za1-slide { position: absolute; inset: 0; }\n.hb-za1-slide[data-swap=\"next\"] { animation: hb-za1-in-next 0.4s cubic-bezier(0.2, 0.8, 0.2, 1); }\n.hb-za1-slide[data-swap=\"prev\"] { animation: hb-za1-in-prev 0.4s cubic-bezier(0.2, 0.8, 0.2, 1); }\n.hb-za1-ui { transition: opacity 0.25s ease; animation: hb-za1-fade 0.4s ease 0.1s backwards; }\n.hb-za1-cap {\n  position: relative;\n  z-index: 1;\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  gap: 2px;\n  max-width: 92vw;\n  text-align: center;\n  pointer-events: none;\n}\n.hb-za1-pane { position: absolute; inset: 0; pointer-events: none; z-index: 2; }\n.hb-za1-pane .hb-za1-btn { pointer-events: auto; }\n.hb-za1-cap b { font-size: 14px; font-weight: 600; }\n.hb-za1-cap span { font-size: 12px; color: #a1a1a1; font-variant-numeric: tabular-nums; }\n.hb-za1-btn {\n  position: absolute;\n  z-index: 2;\n  display: grid;\n  place-items: center;\n  width: 42px;\n  height: 42px;\n  margin: 0;\n  padding: 0;\n  color: #ededed;\n  background: rgba(255, 255, 255, 0.08);\n  border: 1px solid rgba(255, 255, 255, 0.14);\n  border-radius: 999px;\n  cursor: pointer;\n  transition: background 0.2s ease, transform 0.2s ease, opacity 0.2s ease;\n}\n.hb-za1-btn:hover { background: rgba(255, 255, 255, 0.16); }\n.hb-za1-btn:active { transform: scale(0.94); }\n.hb-za1-btn:focus-visible { outline: 2px solid var(--hb-za1-c); outline-offset: 2px; }\n.hb-za1-btn:disabled { opacity: 0.25; cursor: default; }\n.hb-za1-btn svg { width: 18px; height: 18px; }\n.hb-za1-btn[data-role=\"close\"] { top: 18px; right: 18px; }\n.hb-za1-btn[data-role=\"prev\"] { left: 18px; top: 50%; margin-top: -21px; }\n.hb-za1-btn[data-role=\"next\"] { right: 18px; top: 50%; margin-top: -21px; }\n@keyframes hb-za1-glint {\n  0%, 70%, 100% { transform: translateX(-120%); }\n  85% { transform: translateX(120%); }\n}\n@keyframes hb-za1-fade { from { opacity: 0; } to { opacity: 1; } }\n@keyframes hb-za1-in-next { from { opacity: 0; transform: translateX(36px) scale(1.04); } to { opacity: 1; transform: none; } }\n@keyframes hb-za1-in-prev { from { opacity: 0; transform: translateX(-36px) scale(1.04); } to { opacity: 1; transform: none; } }\n@media (max-width: 560px) {\n  .hb-za1-btn[data-role=\"prev\"] { left: 8px; }\n  .hb-za1-btn[data-role=\"next\"] { right: 8px; }\n  .hb-za1-btn[data-role=\"close\"] { top: 10px; right: 10px; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-za1-thumb, .hb-za1-nav, .hb-za1-scrim, .hb-za1-ui, .hb-za1-btn { transition: none; animation: none; }\n  .hb-za1-thumb::after, .hb-za1-slide { animation: none !important; }\n}\n`;\n\nconst easing = \"cubic-bezier(0.2, 0.8, 0.2, 1)\";\n\nfunction reducedMotion() {\n  return typeof window !== \"undefined\" && window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n}\n\nfunction flipFrame(from: DOMRect, to: DOMRect) {\n  const dx = from.left - to.left;\n  const dy = from.top - to.top;\n  const sx = from.width / to.width;\n  const sy = from.height / to.height;\n  return `translate(${dx.toFixed(2)}px, ${dy.toFixed(2)}px) scale(${sx.toFixed(4)}, ${sy.toFixed(4)})`;\n}\n\nexport function CarouselLightbox({\n  images,\n  accent = \"#2f7bff\",\n  thumbWidth = 112,\n  className = \"\",\n  style,\n  ...rest\n}: CarouselLightboxProps) {\n  const items = images && images.length ? images : defaults;\n  const total = items.length;\n  const [open, setOpen] = React.useState<number | null>(null);\n  const [closing, setClosing] = React.useState(false);\n  const [swap, setSwap] = React.useState<\"next\" | \"prev\" | null>(null);\n  const [edges, setEdges] = React.useState({ start: true, end: false });\n  const stripRef = React.useRef<HTMLDivElement>(null);\n  const thumbs = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const originRect = React.useRef<DOMRect | null>(null);\n  const stageRef = React.useRef<HTMLDivElement>(null);\n  const boxRef = React.useRef<HTMLDivElement>(null);\n  const closeRef = React.useRef<HTMLButtonElement>(null);\n  const wasOpen = React.useRef(false);\n  const isOpen = open !== null;\n\n  const measure = React.useCallback(() => {\n    const el = stripRef.current;\n    if (!el) return;\n    const start = el.scrollLeft <= 2;\n    const end = el.scrollLeft + el.clientWidth >= el.scrollWidth - 2;\n    setEdges((prev) => (prev.start === start && prev.end === end ? prev : { start, end }));\n  }, []);\n\n  React.useEffect(() => {\n    measure();\n    const el = stripRef.current;\n    if (!el || typeof ResizeObserver === \"undefined\") return;\n    const ro = new ResizeObserver(measure);\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, [measure, total, thumbWidth]);\n\n  React.useLayoutEffect(() => {\n    if (isOpen && !wasOpen.current) {\n      const stage = stageRef.current;\n      const from = originRect.current;\n      if (stage && from && !reducedMotion()) {\n        const to = stage.getBoundingClientRect();\n        stage.animate([{ transform: flipFrame(from, to) }, { transform: \"none\" }], {\n          duration: 440,\n          easing,\n        });\n      }\n      closeRef.current?.focus({ preventScroll: true });\n    }\n    wasOpen.current = isOpen;\n  }, [isOpen]);\n\n  React.useEffect(() => {\n    if (open === null) return;\n    const strip = stripRef.current;\n    const th = thumbs.current[open];\n    if (!strip || !th) return;\n    const left = th.offsetLeft - (strip.clientWidth - th.offsetWidth) / 2;\n    strip.scrollTo({ left: Math.max(0, left), behavior: \"auto\" });\n  }, [open]);\n\n  function openAt(i: number) {\n    const th = thumbs.current[i];\n    if (!th) return;\n    originRect.current = th.getBoundingClientRect();\n    setSwap(null);\n    setClosing(false);\n    setOpen(i);\n  }\n\n  function finish() {\n    const idx = open;\n    setOpen(null);\n    setClosing(false);\n    setSwap(null);\n    if (idx !== null) thumbs.current[idx]?.focus({ preventScroll: true });\n  }\n\n  function close() {\n    if (open === null || closing) return;\n    const stage = stageRef.current;\n    const th = thumbs.current[open];\n    if (!stage || !th || reducedMotion()) {\n      finish();\n      return;\n    }\n    stage.getAnimations().forEach((a) => a.cancel());\n    const to = stage.getBoundingClientRect();\n    const from = th.getBoundingClientRect();\n    setClosing(true);\n    const anim = stage.animate([{ transform: \"none\" }, { transform: flipFrame(from, to) }], {\n      duration: 340,\n      easing,\n      fill: \"forwards\",\n    });\n    anim.onfinish = finish;\n  }\n\n  function go(step: 1 | -1) {\n    if (open === null || closing) return;\n    const next = open + step;\n    if (next < 0 || next >= total) return;\n    setSwap(step === 1 ? \"next\" : \"prev\");\n    setOpen(next);\n  }\n\n  function onBoxKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {\n    if (e.key === \"Escape\") {\n      e.preventDefault();\n      close();\n    } else if (e.key === \"ArrowRight\") {\n      e.preventDefault();\n      go(1);\n    } else if (e.key === \"ArrowLeft\") {\n      e.preventDefault();\n      go(-1);\n    } else if (e.key === \"Tab\") {\n      const nodes = boxRef.current?.querySelectorAll<HTMLButtonElement>(\"button:not([disabled])\");\n      if (!nodes || !nodes.length) {\n        e.preventDefault();\n        return;\n      }\n      const first = nodes[0];\n      const last = nodes[nodes.length - 1];\n      const active = document.activeElement;\n      if (e.shiftKey && (active === first || active === boxRef.current)) {\n        e.preventDefault();\n        last.focus();\n      } else if (!e.shiftKey && active === last) {\n        e.preventDefault();\n        first.focus();\n      }\n    }\n  }\n\n  function nudge(dir: 1 | -1) {\n    const el = stripRef.current;\n    if (!el) return;\n    el.scrollBy({ left: dir * el.clientWidth * 0.8, behavior: reducedMotion() ? \"auto\" : \"smooth\" });\n  }\n\n  const vars = {\n    \"--hb-za1-c\": accent,\n    \"--hb-za1-w\": `${thumbWidth}px`,\n    ...style,\n  } as React.CSSProperties;\n\n  const current = open !== null ? items[open] : null;\n\n  return (\n    <div className={`hb-za1 ${className}`} style={vars} {...rest}>\n      <style href=\"hb-carousel-lightbox\" precedence=\"default\">{css}</style>\n      <button\n        type=\"button\"\n        className=\"hb-za1-nav\"\n        data-side=\"prev\"\n        aria-label=\"Scroll thumbnails left\"\n        disabled={edges.start}\n        onClick={() => nudge(-1)}\n      >\n        <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n          <path d=\"M10 3 5 8l5 5\" />\n        </svg>\n      </button>\n      <div\n        ref={stripRef}\n        className=\"hb-za1-strip\"\n        role=\"group\"\n        aria-label=\"Image thumbnails\"\n        onScroll={measure}\n      >\n        {items.map((image, i) => (\n          <button\n            key={i}\n            ref={(el) => {\n              thumbs.current[i] = el;\n            }}\n            type=\"button\"\n            className=\"hb-za1-thumb\"\n            data-open={open === i ? \"true\" : undefined}\n            style={{ \"--hb-za1-i\": i } as React.CSSProperties}\n            aria-label={`Open ${image.alt ?? `image ${i + 1}`}`}\n            aria-haspopup=\"dialog\"\n            onClick={() => openAt(i)}\n          >\n            <Scene index={i} image={image} />\n          </button>\n        ))}\n      </div>\n      <button\n        type=\"button\"\n        className=\"hb-za1-nav\"\n        data-side=\"next\"\n        aria-label=\"Scroll thumbnails right\"\n        disabled={edges.end}\n        onClick={() => nudge(1)}\n      >\n        <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n          <path d=\"m6 3 5 5-5 5\" />\n        </svg>\n      </button>\n      {isOpen && current && typeof document !== \"undefined\"\n        ? createPortal(\n            <div\n              ref={boxRef}\n              className=\"hb-za1-box\"\n              role=\"dialog\"\n              aria-modal=\"true\"\n              aria-label={current.alt ?? \"Image viewer\"}\n              tabIndex={-1}\n              data-closing={closing}\n              style={{ \"--hb-za1-c\": accent } as React.CSSProperties}\n              onKeyDown={onBoxKeyDown}\n            >\n              <style href=\"hb-carousel-lightbox\" precedence=\"default\">{css}</style>\n              <div className=\"hb-za1-scrim\" onClick={close} />\n              <div ref={stageRef} className=\"hb-za1-stage\">\n                <div key={open} className=\"hb-za1-slide\" data-swap={swap ?? undefined}>\n                  <Scene index={open} image={current} />\n                </div>\n              </div>\n              <div className=\"hb-za1-pane hb-za1-ui\">\n                <button ref={closeRef} type=\"button\" className=\"hb-za1-btn\" data-role=\"close\" aria-label=\"Close viewer\" onClick={close}>\n                  <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                    <path d=\"m3.5 3.5 9 9M12.5 3.5l-9 9\" />\n                  </svg>\n                </button>\n                <button type=\"button\" className=\"hb-za1-btn\" data-role=\"prev\" aria-label=\"Previous image\" disabled={open === 0} onClick={() => go(-1)}>\n                  <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                    <path d=\"M10 3 5 8l5 5\" />\n                  </svg>\n                </button>\n                <button type=\"button\" className=\"hb-za1-btn\" data-role=\"next\" aria-label=\"Next image\" disabled={open === total - 1} onClick={() => go(1)}>\n                  <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                    <path d=\"m6 3 5 5-5 5\" />\n                  </svg>\n                </button>\n              </div>\n              <div className=\"hb-za1-cap hb-za1-ui\" aria-live=\"polite\">\n                <b>{current.caption ?? current.alt ?? \"\"}</b>\n                <span>\n                  {open + 1} / {total}\n                </span>\n              </div>\n            </div>,\n            document.body,\n          )\n        : null}\n    </div>\n  );\n}\n"
    }
  ]
}