{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "image-gallery",
  "type": "registry:item",
  "title": "Image Gallery",
  "description": "A photo gallery: a masonry grid in reading order and a lightbox with previous and next (arrow keys too). Photos come from `items`, or from `src`, a gallery.json that `npx zubra-imager <photos>` writes (sizes in AVIF, WebP and JPEG, alt text, placeholders). `index` is the open photo (-1 when closed) and is two-way.",
  "dependencies": [
    "@zubra/runtime@^5.13.1"
  ],
  "categories": [
    "display"
  ],
  "registryDependencies": [
    "https://zubra-js.github.io/zubra-ui/r/theme.json"
  ],
  "files": [
    {
      "path": "components/image-gallery.js",
      "type": "registry:file",
      "target": "~/src/components/zubra/image-gallery.js",
      "content": "// Generated by zubra from image-gallery.zb. Do not edit.\nimport { $define, $r, $t } from \"@zubra/runtime\";\nimport { effect, onMount } from '@zubra/runtime';\nimport { state as __zubraState, computed as __zubraComputed } from \"@zubra/runtime\";\n\nexport const tag = \"image-gallery\";\n\nexport default $define(tag, {\n  props: {\n    \"items\": { attribute: \"items\", default: [], required: false },\n    \"src\": { attribute: \"src\", default: \"\", required: false },\n    \"index\": { attribute: \"index\", default: -1, required: false, model: true },\n    \"label\": { attribute: \"label\", default: \"Photos\", required: false },\n  },\n  abi: 3,\n  shadow: false,\n  form: false,\n  slots: [],\n  events: [\"indexchange\"],\n  styled: true,\n  styles: \"@layer theme, base, components, utilities;\\n@layer components {\\n@scope (image-gallery) to ([data-zb-slotted=\\\"image-gallery\\\"]) {\\n  :scope { display: block; inline-size: 100%; }\\n  .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--column, 14rem)), 1fr)); grid-auto-rows: 8px; column-gap: var(--gap, 0.75rem); margin: 0; padding: 0; list-style: none; }\\n  .grid > li { align-self: start; }\\n  figure { margin: 0; }\\n  .thumb { display: block; width: 100%; padding: 0; border: 0; border-radius: var(--radius, 0.6rem); overflow: hidden; background: var(--muted, #f4f4f5) center / cover no-repeat; cursor: zoom-in; }\\n  .thumb img { display: block; width: 100%; height: auto; transition: transform var(--duration-normal, 200ms); }\\n  .thumb:hover img { transform: scale(1.03); }\\n  .thumb:focus-visible { outline: 2px solid var(--primary, #18181b); outline-offset: 2px; }\\n  figcaption { padding: 0.35rem 0.1rem 0; color: var(--muted-foreground, #71717a); font-size: 0.875rem; }\\n  .status { color: var(--destructive, #d92d20); }\\n  .lightbox { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #0b0d12f2; color: #f4f4f5; }\\n  .lightbox::backdrop { background: transparent; }\\n  .lightbox[open] { display: grid; grid-template: 1fr auto / 3.5rem 1fr 3.5rem; align-items: center; }\\n  .lightbox figure { grid-area: 1 / 1 / 3 / 4; display: grid; grid-template-rows: 1fr auto; height: 100%; min-height: 0; pointer-events: none; }\\n  .lightbox picture { display: grid; place-items: center; min-height: 0; padding: 3.5rem 3.5rem 0.5rem; }\\n  /* Fits the screen, leaving room for the buttons and the caption. */\\n  .lightbox img { max-width: calc(100vw - 7rem); max-height: calc(100dvh - 8rem); width: auto; height: auto; object-fit: contain; border-radius: calc(var(--radius, 0.625rem) * 0.64); pointer-events: auto; }\\n  .lightbox figcaption { display: flex; justify-content: space-between; gap: 1rem; padding: 0.75rem 1.25rem 1.25rem; color: #e4e4e7; font-size: 1rem; }\\n  .count { color: #a1a1aa; white-space: nowrap; font-variant-numeric: tabular-nums; }\\n  .lightbox button { z-index: 1; display: grid; place-items: center; width: 2.75rem; height: 2.75rem; border: 0; border-radius: 50%; background: #ffffff1f; color: inherit; font-size: 1.6rem; line-height: 1; cursor: pointer; }\\n  .lightbox button:hover { background: #ffffff33; }\\n  .lightbox button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }\\n  .close { position: absolute; top: 0.75rem; right: 0.75rem; }\\n  .prev { grid-area: 1 / 1; justify-self: center; }\\n  .next { grid-area: 1 / 3; justify-self: center; }\\n  @media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; animation-iteration-count: 1 !important; } }\\n}\\n}\\n\",\n  template: \"\\n  <!--[--><!--]-->\\n  <ul class=\\\"grid\\\">\\n    <!--[--><!--]-->\\n  </ul>\\n  <dialog class=\\\"lightbox\\\">\\n    <!--[--><!--]-->\\n    <button type=\\\"button\\\" class=\\\"close\\\" aria-label=\\\"Close\\\">×</button>\\n    <!--[--><!--]-->\\n    <!--[--><!--]-->\\n  </dialog>\\n\",\n  setup($p, $emit) {\nfunction __zubraAssign(signal, value) { signal.set(value); return value }\nfunction __zubraUpdate(signal, delta, prefix) { const old = signal.get(); signal.set(old + delta); return prefix ? old + delta : old }\n                                                  \n\n  const grid = __zubraState(null)\n  const dialog = __zubraState(null)\n  const loaded = __zubraState(null)\n  const failed = __zubraState(false)\n  const pressedBackdrop = __zubraState(false)\n\n  const photos = __zubraComputed(() => ($p.src ? loaded.get() ?? [] : $p.items))\n  const current = __zubraComputed(() => ($p.index >= 0 && $p.index < photos.get().length ? photos.get()[$p.index] : null))\n  // A manifest's URLs are relative to the manifest.\n  const base = __zubraComputed(() => ($p.src && typeof document !== \"undefined\" ? new URL($p.src, document.baseURI) : null))\n  const url = (path) => (base.get() && path && !/^([a-z][a-z0-9+.-]*:|\\/)/i.test(path) ? new URL(path, base.get()).href : path)\n  const srcset = (set) => set ? set.split(\",\").map((entry) => entry.trim().split(/\\s+/)).map(([path, size]) => (size ? `${url(path)} ${size}` : url(path))).join(\", \") : null\n\n  effect(() => {\n    if (!$p.src) return\n    __zubraAssign(failed, false)\n    fetch($p.src)\n      .then((response) => { if (!response.ok) throw new Error(response.statusText); return response.json() })\n      .then((data) => { __zubraAssign(loaded, Array.isArray(data) ? data : data.items ?? []) })\n      .catch(() => { __zubraAssign(failed, true) })\n  })\n\n  // The lightbox follows `index`: open on a photo, closed at -1.\n  effect(() => {\n    if (!dialog.get()) return\n    if (current.get() && !dialog.get().open) dialog.get().showModal()\n    else if (!current.get() && dialog.get().open) dialog.get().close()\n  })\n  function move(by) {\n    if (photos.get().length) $p.index = ($p.index + by + photos.get().length) % photos.get().length\n  }\n\n  // Masonry in reading order: each item spans as many small grid rows as it is tall, so the grid\n  // packs them while the DOM (and Tab) stays left to right, top to bottom.\n  onMount(() => {\n    const ROW = 8\n    const fit = (item) => {\n      const gap = parseFloat(getComputedStyle(grid.get()).columnGap) || 0\n      item.style.gridRowEnd = `span ${Math.max(1, Math.ceil((item.getBoundingClientRect().height + gap) / ROW))}`\n    }\n    const sizes = new ResizeObserver((entries) => entries.forEach((entry) => fit(entry.target)))\n    const watch = () => [...grid.get().children].forEach((item) => sizes.observe(item))\n    watch()\n    const added = new MutationObserver(watch)\n    added.observe(grid.get(), { childList: true })\n    return () => { sizes.disconnect(); added.disconnect() }\n  })\n    return [\n      { path: [0], when: () => $r(failed), blocks: [{ template: \"<p class=\\\"status\\\" role=\\\"status\\\"></p>\", parts: () => [{ path: [0], text: () => \"Couldn't load the photos from \" + $t($p.src) + \".\" }] }, null] },\n      { path: [1], ref: () => (($el) => (__zubraAssign(grid, $el))) },\n      { path: [1], attribute: \"aria-label\", value: () => $p.label },\n      { path: [1, 0], each: () => $r(photos), key: (photo, i) => $r(photo).src, block: { template: \"\\n      <li>\\n        <figure>\\n          <button type=\\\"button\\\" class=\\\"thumb\\\" aria-haspopup=\\\"dialog\\\">\\n            <img sizes=\\\"(max-width: 40rem) 100vw, 30rem\\\" loading=\\\"lazy\\\" decoding=\\\"async\\\">\\n          </button>\\n          <!--[--><!--]-->\\n        </figure>\\n      </li>\\n    \", parts: (photo, i) => [{ path: [0, 0, 0], style: \"background-image\", value: () => ($r(photo).placeholder ? `url(\"${$r(photo).placeholder}\")` : null) }, { path: [0, 0, 0], on: \"click\", handler: () => (() => ($p.index = $r(i))) }, { path: [0, 0, 0, 0], attribute: \"src\", url: true, value: () => (url($r(photo).src)) }, { path: [0, 0, 0, 0], attribute: \"srcset\", srcset: true, value: () => (srcset($r(photo).srcset)) }, { path: [0, 0, 0, 0], attribute: \"width\", value: () => $r(photo).width }, { path: [0, 0, 0, 0], attribute: \"height\", value: () => $r(photo).height }, { path: [0, 0, 0, 0], attribute: \"alt\", value: () => ($r(photo).alt ?? \"\") }, { path: [0, 0, 1], when: () => $r(photo).caption, blocks: [{ template: \"<figcaption></figcaption>\", parts: () => [{ path: [0], text: () => $t($r(photo).caption) }] }, null] }] } },\n      { path: [2], ref: () => (($el) => (__zubraAssign(dialog, $el))) },\n      { path: [2], attribute: \"aria-label\", value: () => ($r(current)?.alt ?? $p.label) },\n      { path: [2], on: \"close\", handler: () => (() => ($p.index = -1)) },\n      { path: [2], on: \"pointerdown\", handler: () => ((event) => (__zubraAssign(pressedBackdrop, event.target === dialog.get()))) },\n      { path: [2], on: \"click\", handler: () => (() => pressedBackdrop.get() && ($p.index = -1)), modifiers: { self: true } },\n      { path: [2], on: \"keydown\", handler: () => (() => move(-1)), modifiers: { prevent: true, keys: [\"ArrowLeft\"] } },\n      { path: [2], on: \"keydown\", handler: () => (() => move(1)), modifiers: { prevent: true, keys: [\"ArrowRight\"] } },\n      { path: [2, 0], when: () => $r(current), blocks: [{ template: \"<figure>\\n      <picture>\\n        <!--[--><!--]-->\\n        <img sizes=\\\"100vw\\\">\\n      </picture>\\n      <figcaption><span></span><span class=\\\"count\\\"></span></figcaption>\\n    </figure>\", parts: () => [{ path: [0, 0, 0], each: () => ($r(current)?.sources ?? []), key: (source, $index) => $r(source).type, block: { template: \"\\n          <source sizes=\\\"100vw\\\">\\n        \", parts: (source, $index) => [{ path: [0], attribute: \"type\", value: () => $r(source).type }, { path: [0], attribute: \"srcset\", srcset: true, value: () => (srcset($r(source).srcset)) }] } }, { path: [0, 0, 1], attribute: \"src\", url: true, value: () => (url(current.get()?.src)) }, { path: [0, 0, 1], attribute: \"srcset\", srcset: true, value: () => (srcset(current.get()?.srcset)) }, { path: [0, 0, 1], attribute: \"width\", value: () => $r(current)?.width }, { path: [0, 0, 1], attribute: \"height\", value: () => $r(current)?.height }, { path: [0, 0, 1], attribute: \"alt\", value: () => ($r(current)?.alt ?? \"\") }, { path: [0, 1, 0], text: () => $t(($r(current)?.caption ?? $r(current)?.alt)) }, { path: [0, 1, 1], text: () => $t(($p.index + 1)) + \" of \" + $t($r(photos).length) }] }, null] },\n      { path: [2, 1], on: \"click\", handler: () => (() => ($p.index = -1)) },\n      { path: [2, 2], when: () => ($r(photos).length > 1), blocks: [{ template: \"<button type=\\\"button\\\" class=\\\"prev\\\" aria-label=\\\"Previous photo\\\">‹</button>\", parts: () => [{ path: [0], on: \"click\", handler: () => (() => move(-1)) }] }, null] },\n      { path: [2, 3], when: () => ($r(photos).length > 1), blocks: [{ template: \"<button type=\\\"button\\\" class=\\\"next\\\" aria-label=\\\"Next photo\\\">›</button>\", parts: () => [{ path: [0], on: \"click\", handler: () => (() => move(1)) }] }, null] },\n    ];\n  },\n});\n"
    }
  ]
}
