{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "gallery-grid-expand",
  "type": "registry:component",
  "title": "Gallery Grid Expand",
  "description": "A grid of image cards. Opening a card grows it from its own spot to fill the grid with the title and caption; Back or Escape shrinks it back into place.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "components",
    "gallery",
    "grid",
    "expand",
    "shared layout",
    "lightbox",
    "cards"
  ],
  "docs": "https://hyperblur.dev/effects/gallery-grid-expand",
  "files": [
    {
      "path": "registry/hyperblur/gallery-grid-expand.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/gallery-grid-expand.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type GalleryGridExpandImage = { src?: string; title: string; caption?: string };\n\nexport interface GalleryGridExpandProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\"> {\n  images?: GalleryGridExpandImage[];\n  value?: number | null;\n  defaultValue?: number | null;\n  onChange?: (index: number | null) => void;\n  columns?: number;\n  gap?: number;\n  ratio?: string;\n  idle?: boolean;\n  accent?: string;\n  label?: string;\n}\n\nconst sampleImages: GalleryGridExpandImage[] = [\n  { title: \"Dune Hour\", caption: \"Erg Chebbi, Morocco. Shot from the ridge twenty minutes before sunset.\" },\n  { title: \"Harbor Lights\", caption: \"Lisbon, Portugal. The waterfront an hour after the rain stopped.\" },\n  { title: \"Glacier Line\", caption: \"Jokulsarlon, Iceland. Icebergs drifting out toward the sea.\" },\n  { title: \"Pine Ridge\", caption: \"Cascade Range, Oregon. Morning fog lifting off the valley.\" },\n  { title: \"Polar Night\", caption: \"Tromso, Norway. A quiet aurora over the fjord at 1 a.m.\" },\n  { title: \"Sun Room\", caption: \"Brooklyn studio. Clay, glass and the first light of the day.\" },\n];\n\nfunction mix(n: number) {\n  let x = Math.imul((n + 7) | 0, 0x9e3779b1) >>> 0;\n  x = Math.imul(x ^ (x >>> 16), 0x85ebca6b) >>> 0;\n  x = Math.imul(x ^ (x >>> 13), 0xc2b2ae35) >>> 0;\n  return (x ^ (x >>> 16)) >>> 0;\n}\n\nfunction sky(a: string, b: string, c: string) {\n  return `<defs><linearGradient id=\"s\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"${a}\"/><stop offset=\"0.62\" stop-color=\"${b}\"/><stop offset=\"1\" stop-color=\"${c}\"/></linearGradient></defs><rect width=\"320\" height=\"240\" fill=\"url(#s)\"/>`;\n}\n\nfunction sceneSvg(k: number) {\n  let b = \"\";\n  if (k === 0) {\n    b =\n      sky(\"#ffd28f\", \"#f2866b\", \"#8a4a7c\") +\n      '<circle cx=\"214\" cy=\"98\" r=\"54\" fill=\"#fff3cf\" opacity=\"0.18\"/><circle cx=\"214\" cy=\"98\" r=\"30\" fill=\"#fff3cf\"/><path d=\"M0 168 Q90 122 172 160 T320 150 V240 H0Z\" fill=\"#dc8752\"/><path d=\"M0 198 Q110 160 204 194 T320 186 V240 H0Z\" fill=\"#ab5840\"/><path d=\"M0 224 Q120 200 236 222 T320 216 V240 H0Z\" fill=\"#6f3437\"/>';\n  } else if (k === 1) {\n    b = sky(\"#0c1230\", \"#28205e\", \"#5c2c6c\") + '<circle cx=\"258\" cy=\"48\" r=\"13\" fill=\"#fff1d6\"/>';\n    for (let i = 0; i < 18; i += 1) {\n      const v = mix(i + 40);\n      b += `<circle cx=\"${v % 320}\" cy=\"${mix(i + 90) % 90}\" r=\"${(0.6 + (v % 4) / 5).toFixed(2)}\" fill=\"#ffffff\" opacity=\"0.7\"/>`;\n    }\n    for (let i = 0; i < 10; i += 1) {\n      const x = i * 34 - 6;\n      const w = 30 + (mix(i) % 10);\n      const h = 70 + (mix(i + 20) % 96);\n      b += `<rect x=\"${x}\" y=\"${222 - h}\" width=\"${w}\" height=\"${h}\" fill=\"#161333\"/>`;\n      for (let r = 0; r < Math.floor((h - 12) / 14); r += 1) {\n        for (let c = 0; c < Math.floor((w - 8) / 9); c += 1) {\n          const q = mix(i * 97 + r * 13 + c);\n          if (q % 3 === 0) b += `<rect x=\"${x + 5 + c * 9}\" y=\"${230 - h + r * 14}\" width=\"4\" height=\"6\" fill=\"${q % 2 ? \"#ffcf7a\" : \"#ff9f86\"}\"/>`;\n        }\n      }\n    }\n    b += '<rect y=\"222\" width=\"320\" height=\"18\" fill=\"#0b0a1f\"/><rect x=\"40\" y=\"228\" width=\"60\" height=\"2\" fill=\"#ffcf7a\" opacity=\"0.35\"/><rect x=\"190\" y=\"232\" width=\"80\" height=\"2\" fill=\"#ff9f86\" opacity=\"0.3\"/>';\n  } else if (k === 2) {\n    b =\n      sky(\"#d9efff\", \"#86bde8\", \"#2f6fa8\") +\n      '<polygon points=\"0,150 46,96 82,128 124,78 170,134 214,92 262,140 320,104 320,170 0,170\" fill=\"#f4fbff\"/><polygon points=\"46,96 60,150 30,150\" fill=\"#c4def2\"/><polygon points=\"124,78 142,150 104,150\" fill=\"#c4def2\"/><polygon points=\"214,92 230,150 196,150\" fill=\"#c4def2\"/><rect y=\"164\" width=\"320\" height=\"76\" fill=\"#17508a\"/><path d=\"M0 182 Q40 176 80 182 T160 182 T240 182 T320 182\" stroke=\"#8ec6f0\" stroke-width=\"2\" fill=\"none\" opacity=\"0.5\"/><path d=\"M0 204 Q40 198 80 204 T160 204 T240 204 T320 204\" stroke=\"#8ec6f0\" stroke-width=\"2\" fill=\"none\" opacity=\"0.35\"/><polygon points=\"88,176 126,176 116,190 96,190\" fill=\"#e8f6ff\"/><polygon points=\"220,196 268,196 256,212 230,212\" fill=\"#d2ecff\"/>';\n  } else if (k === 3) {\n    b = sky(\"#e4ece4\", \"#a9c2b2\", \"#6f8f7e\");\n    const rows: [number, number, string][] = [\n      [120, 50, \"#86a596\"],\n      [150, 62, \"#4b6d5d\"],\n      [186, 78, \"#22392f\"],\n    ];\n    rows.forEach(([base, tall, fill], r) => {\n      for (let i = 0; i < 12; i += 1) {\n        const x = i * 30 + (mix(r * 31 + i) % 18) - 10;\n        const h = tall - 14 + (mix(r * 57 + i) % 28);\n        b += `<polygon points=\"${x},${base - h} ${x - 15},${base + 6} ${x + 15},${base + 6}\" fill=\"${fill}\"/>`;\n      }\n      b += `<rect y=\"${base + 4}\" width=\"320\" height=\"${240 - base}\" fill=\"${fill}\"/>`;\n      if (r === 0) b += '<rect y=\"118\" width=\"320\" height=\"30\" fill=\"#e4ece4\" opacity=\"0.55\"/>';\n    });\n  } else if (k === 4) {\n    b =\n      sky(\"#040a18\", \"#0b1d38\", \"#12304a\") +\n      '<path d=\"M0 96 C70 40 160 126 320 56 L320 104 C170 168 92 84 0 146Z\" fill=\"#3ef0a8\" opacity=\"0.32\"/><path d=\"M0 70 C90 30 170 96 320 30 L320 60 C180 120 96 60 0 110Z\" fill=\"#8f6bff\" opacity=\"0.22\"/><path d=\"M40 110 C120 76 200 140 300 90\" stroke=\"#9fffd6\" stroke-width=\"3\" fill=\"none\" opacity=\"0.4\"/>';\n    for (let i = 0; i < 26; i += 1) {\n      const v = mix(i + 300);\n      b += `<circle cx=\"${v % 320}\" cy=\"${mix(i + 500) % 120}\" r=\"${(0.5 + (v % 3) / 4).toFixed(2)}\" fill=\"#ffffff\" opacity=\"0.75\"/>`;\n    }\n    b +=\n      '<polygon points=\"0,200 60,140 104,176 160,120 220,180 266,150 320,190 320,240 0,240\" fill=\"#0a1626\"/><polygon points=\"160,120 176,136 168,134 160,142 152,134 146,134\" fill=\"#dfeaf5\"/><polygon points=\"60,140 72,152 60,150 50,152\" fill=\"#dfeaf5\"/><rect y=\"214\" width=\"320\" height=\"26\" fill=\"#06101d\"/>';\n  } else {\n    b =\n      '<defs><radialGradient id=\"s\" cx=\"0.32\" cy=\"0.3\" r=\"0.9\"><stop offset=\"0\" stop-color=\"#ffe2c8\"/><stop offset=\"0.55\" stop-color=\"#e09a7c\"/><stop offset=\"1\" stop-color=\"#7c4648\"/></radialGradient><radialGradient id=\"o\" cx=\"0.35\" cy=\"0.3\" r=\"0.75\"><stop offset=\"0\" stop-color=\"#fff6ea\"/><stop offset=\"1\" stop-color=\"#c46f58\"/></radialGradient></defs><rect width=\"320\" height=\"240\" fill=\"url(#s)\"/><path d=\"M188 240 V112 A52 52 0 0 1 292 112 V240Z\" fill=\"#f6c9a8\" opacity=\"0.55\"/><rect x=\"40\" y=\"176\" width=\"140\" height=\"64\" fill=\"#5d3236\"/><rect x=\"40\" y=\"170\" width=\"140\" height=\"8\" fill=\"#7a4447\"/><circle cx=\"110\" cy=\"138\" r=\"32\" fill=\"url(#o)\"/><rect x=\"150\" y=\"128\" width=\"16\" height=\"42\" rx=\"3\" fill=\"#2f2a44\"/><ellipse cx=\"158\" cy=\"128\" rx=\"8\" ry=\"3\" fill=\"#4a4366\"/>';\n  }\n  return `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 320 240\" preserveAspectRatio=\"xMidYMid slice\">${b}</svg>`;\n}\n\nconst sceneCache = new Map<number, string>();\n\nfunction sceneUrl(index: number) {\n  const k = ((index % 6) + 6) % 6;\n  let url = sceneCache.get(k);\n  if (!url) {\n    url = `url(\"data:image/svg+xml,${encodeURIComponent(sceneSvg(k))}\")`;\n    sceneCache.set(k, url);\n  }\n  return url;\n}\n\nfunction imageUrl(src: string | undefined, index: number) {\n  return src ? `url(${JSON.stringify(src)})` : sceneUrl(index);\n}\n\nconst css = `\n.hb-zw4 {\n  --hb-zw4-accent: #2f7bff;\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  color: #ededed;\n  font-family: inherit;\n  container-type: inline-size;\n}\n.hb-zw4 *, .hb-zw4 *::before, .hb-zw4 *::after { box-sizing: border-box; }\n.hb-zw4-grid {\n  display: grid;\n  grid-template-columns: repeat(var(--hb-zw4-cols), minmax(0, 1fr));\n  gap: var(--hb-zw4-gap);\n  margin: 0;\n  padding: 0;\n  list-style: none;\n}\n.hb-zw4-grid li { margin: 0; padding: 0; min-width: 0; }\n.hb-zw4-card {\n  position: relative;\n  display: block;\n  width: 100%;\n  aspect-ratio: var(--hb-zw4-ratio);\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 10px;\n  overflow: hidden;\n  background: #171717;\n  color: inherit;\n  font: inherit;\n  text-align: left;\n  cursor: pointer;\n  outline: none;\n  transition: opacity 0.35s ease, transform 0.3s cubic-bezier(0.2, 0.7, 0.2, 1);\n}\n.hb-zw4-card:hover { transform: translateY(-2px); }\n.hb-zw4-card:focus-visible { box-shadow: 0 0 0 2px var(--hb-zw4-accent); }\n.hb-zw4-card::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  border-radius: inherit;\n  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.07);\n  background: linear-gradient(180deg, transparent 50%, rgba(0, 0, 0, 0.55));\n  pointer-events: none;\n}\n.hb-zw4-cbg {\n  position: absolute;\n  inset: 0;\n  background-size: cover;\n  background-position: center;\n  transition: transform 0.5s cubic-bezier(0.2, 0.7, 0.2, 1);\n}\n.hb-zw4-card:hover .hb-zw4-cbg { transform: scale(1.06); }\n.hb-zw4-ctitle {\n  position: absolute;\n  left: 8px;\n  right: 8px;\n  bottom: 6px;\n  z-index: 1;\n  font-size: 0.74em;\n  font-weight: 500;\n  white-space: nowrap;\n  overflow: hidden;\n  text-overflow: ellipsis;\n}\n.hb-zw4[data-open=\"true\"] .hb-zw4-card { opacity: 0.25; transform: none; }\n.hb-zw4-panel {\n  position: absolute;\n  inset: 0;\n  z-index: 5;\n  overflow: hidden;\n  border-radius: 14px;\n  background: #111111;\n  clip-path: inset(0 0 0 0 round 14px);\n}\n.hb-zw4-pimg {\n  position: absolute;\n  inset: 0;\n  transform-origin: 50% 50%;\n}\n.hb-zw4-layer {\n  position: absolute;\n  inset: 0;\n  background-size: cover;\n  background-position: center;\n  opacity: 0;\n  transition: opacity 0.45s ease;\n}\n.hb-zw4-layer[data-on=\"true\"] { opacity: 1; }\n.hb-zw4-info {\n  position: absolute;\n  inset: 0;\n  display: flex;\n  flex-direction: column;\n  justify-content: space-between;\n  padding: 10px 12px 12px;\n  background: linear-gradient(180deg, rgba(0, 0, 0, 0.35) 0%, transparent 32%, transparent 45%, rgba(0, 0, 0, 0.78) 100%);\n  opacity: 0;\n  transition: opacity 0.25s ease;\n}\n.hb-zw4-panel[data-phase=\"open\"] .hb-zw4-info { opacity: 1; transition: opacity 0.4s 0.22s ease; }\n.hb-zw4-top, .hb-zw4-bottom { display: flex; align-items: center; justify-content: space-between; gap: 10px; }\n.hb-zw4-bottom { align-items: flex-end; }\n.hb-zw4-text { min-width: 0; }\n.hb-zw4-index {\n  margin: 0 0 3px;\n  font-size: 0.68em;\n  letter-spacing: 0.12em;\n  font-variant-numeric: tabular-nums;\n  color: rgba(237, 237, 237, 0.7);\n}\n.hb-zw4-title { margin: 0; font-size: 1.3em; font-weight: 600; line-height: 1.15; letter-spacing: -0.015em; }\n.hb-zw4-caption {\n  margin: 4px 0 0;\n  max-width: 34em;\n  font-size: 0.8em;\n  line-height: 1.4;\n  color: rgba(237, 237, 237, 0.78);\n  display: -webkit-box;\n  -webkit-line-clamp: 2;\n  -webkit-box-orient: vertical;\n  overflow: hidden;\n}\n.hb-zw4-btn {\n  display: inline-flex;\n  align-items: center;\n  gap: 6px;\n  height: 28px;\n  margin: 0;\n  padding: 0 11px 0 8px;\n  border: 1px solid rgba(255, 255, 255, 0.18);\n  border-radius: 999px;\n  background: rgba(10, 10, 10, 0.55);\n  -webkit-backdrop-filter: blur(8px);\n  backdrop-filter: blur(8px);\n  color: #ededed;\n  font: inherit;\n  font-size: 0.78em;\n  cursor: pointer;\n  transition: background-color 0.2s ease;\n}\n.hb-zw4-btn:hover { background: rgba(10, 10, 10, 0.8); }\n.hb-zw4-btn:focus-visible { outline: 2px solid var(--hb-zw4-accent); outline-offset: 2px; }\n.hb-zw4-btn svg { width: 13px; height: 13px; flex: none; }\n.hb-zw4-round { width: 28px; padding: 0; justify-content: center; }\n.hb-zw4-pair { display: flex; gap: 6px; flex: none; }\n@container (max-width: 260px) {\n  .hb-zw4-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-zw4-card, .hb-zw4-cbg, .hb-zw4-layer, .hb-zw4-info, .hb-zw4-btn { transition: none !important; }\n  .hb-zw4-card:hover, .hb-zw4-card:hover .hb-zw4-cbg { transform: none; }\n}\n`;\n\nfunction Icon({ d }: { d: string }) {\n  return (\n    <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\">\n      <path d={d} stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\n\nconst EASE = \"cubic-bezier(0.2, 0.8, 0.2, 1)\";\nconst DURATION = 560;\n\nexport function GalleryGridExpand({\n  images,\n  value,\n  defaultValue = null,\n  onChange,\n  columns = 3,\n  gap = 8,\n  ratio = \"4 / 3\",\n  idle = true,\n  accent = \"#2f7bff\",\n  label = \"Gallery\",\n  className,\n  style,\n  onKeyDown,\n  ...rest\n}: GalleryGridExpandProps) {\n  const list = images && images.length ? images : sampleImages;\n  const n = list.length;\n  const [inner, setInner] = React.useState<number | null>(defaultValue);\n  const raw = value !== undefined ? value : inner;\n  const open = raw === null || raw < 0 || raw >= n ? null : raw;\n  const [prevOpen, setPrevOpen] = React.useState<number | null>(open);\n  const [shown, setShown] = React.useState<number | null>(open);\n  const [hover, setHover] = React.useState(false);\n  const [focused, setFocused] = React.useState(false);\n  const [visible, setVisible] = React.useState(true);\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const panelRef = React.useRef<HTMLDivElement>(null);\n  const imgRef = React.useRef<HTMLDivElement>(null);\n  const backRef = React.useRef<HTMLButtonElement>(null);\n  const cardRefs = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const lastOpen = React.useRef<number | null>(open);\n  const userAction = React.useRef(false);\n  const idleOpened = React.useRef(false);\n  const lastIdle = React.useRef(-1);\n\n  if (open !== prevOpen) {\n    setPrevOpen(open);\n    if (open !== null) setShown(open);\n  }\n\n  React.useEffect(() => {\n    const el = rootRef.current;\n    if (!el || typeof IntersectionObserver === \"undefined\") return;\n    const io = new IntersectionObserver(([entry]) => setVisible(entry.isIntersecting));\n    io.observe(el);\n    return () => io.disconnect();\n  }, []);\n\n  const request = React.useCallback(\n    (next: number | null, fromUser: boolean) => {\n      userAction.current = fromUser;\n      if (fromUser) idleOpened.current = false;\n      if (value === undefined) setInner(next);\n      if (fromUser) onChange?.(next);\n    },\n    [value, onChange],\n  );\n\n  React.useLayoutEffect(() => {\n    const before = lastOpen.current;\n    lastOpen.current = open;\n    const root = rootRef.current;\n    const panel = panelRef.current;\n    const img = imgRef.current;\n    if (!root || !panel || !img) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const geometry = (i: number) => {\n      const card = cardRefs.current[i];\n      const rr = root.getBoundingClientRect();\n      if (!card || rr.width === 0 || rr.height === 0) return null;\n      const cr = card.getBoundingClientRect();\n      const x = cr.left - rr.left;\n      const y = cr.top - rr.top;\n      const s = Math.max(cr.width / rr.width, cr.height / rr.height);\n      const dx = x + cr.width / 2 - rr.width / 2;\n      const dy = y + cr.height / 2 - rr.height / 2;\n      return {\n        clip: `inset(${y.toFixed(1)}px ${(rr.width - x - cr.width).toFixed(1)}px ${(rr.height - y - cr.height).toFixed(1)}px ${x.toFixed(1)}px round 10px)`,\n        transform: `translate(${dx.toFixed(1)}px, ${dy.toFixed(1)}px) scale(${s.toFixed(4)})`,\n      };\n    };\n    const full = { clip: \"inset(0px 0px 0px 0px round 14px)\", transform: \"translate(0px, 0px) scale(1)\" };\n    const apply = (g: { clip: string; transform: string }, animate: boolean) => {\n      const t = animate && !reduce ? `clip-path ${DURATION}ms ${EASE}, transform ${DURATION}ms ${EASE}` : \"none\";\n      panel.style.transition = t;\n      img.style.transition = t;\n      panel.style.clipPath = g.clip;\n      img.style.transform = g.transform;\n    };\n\n    if (open !== null && before === null) {\n      const g = geometry(open);\n      if (g) {\n        apply(g, false);\n        panel.dataset.phase = \"from\";\n        void panel.getBoundingClientRect();\n      }\n      apply(full, true);\n      panel.dataset.phase = \"open\";\n      if (userAction.current) backRef.current?.focus({ preventScroll: true });\n      return;\n    }\n    if (open === null && before !== null) {\n      const g = geometry(before);\n      panel.dataset.phase = \"closing\";\n      if (userAction.current) cardRefs.current[before]?.focus({ preventScroll: true });\n      if (g && !reduce) {\n        apply(g, true);\n        const t = window.setTimeout(() => {\n          if (lastOpen.current === null) setShown(null);\n        }, DURATION + 20);\n        return () => window.clearTimeout(t);\n      }\n      setShown(null);\n    }\n  }, [open]);\n\n  React.useEffect(() => {\n    if (!idle || value !== undefined || hover || focused || !visible || n < 1) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    if (open !== null && !idleOpened.current) return;\n    const t = window.setTimeout(\n      () => {\n        if (open === null) {\n          idleOpened.current = true;\n          userAction.current = false;\n          lastIdle.current = (lastIdle.current + 1) % n;\n          setInner(lastIdle.current);\n        } else {\n          userAction.current = false;\n          setInner(null);\n        }\n      },\n      open === null ? 1500 : 2600,\n    );\n    return () => window.clearTimeout(t);\n  }, [idle, value, hover, focused, visible, open, n]);\n\n\n  const keyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    onKeyDown?.(e);\n    if (e.defaultPrevented) return;\n    if (open !== null) {\n      if (e.key === \"Escape\") {\n        e.preventDefault();\n        request(null, true);\n      } else if (e.key === \"ArrowRight\") {\n        e.preventDefault();\n        request((open + 1) % n, true);\n      } else if (e.key === \"ArrowLeft\") {\n        e.preventDefault();\n        request((open - 1 + n) % n, true);\n      }\n      return;\n    }\n    const i = cardRefs.current.findIndex((el) => el === document.activeElement);\n    if (i < 0) return;\n    const cols = Math.max(1, Math.min(columns, n));\n    let next: number | null = null;\n    if (e.key === \"ArrowRight\") next = i + 1;\n    else if (e.key === \"ArrowLeft\") next = i - 1;\n    else if (e.key === \"ArrowDown\") next = i + cols;\n    else if (e.key === \"ArrowUp\") next = i - cols;\n    else if (e.key === \"Home\") next = 0;\n    else if (e.key === \"End\") next = n - 1;\n    if (next === null || next < 0 || next >= n) return;\n    e.preventDefault();\n    cardRefs.current[next]?.focus();\n  };\n\n  const item = shown !== null ? list[shown] : null;\n\n  return (\n    <div\n      ref={rootRef}\n      role=\"region\"\n      aria-roledescription=\"gallery\"\n      aria-label={label}\n      data-open={open !== null ? \"true\" : \"false\"}\n      className={className ? `hb-zw4 ${className}` : \"hb-zw4\"}\n      style={\n        {\n          \"--hb-zw4-accent\": accent,\n          \"--hb-zw4-cols\": columns,\n          \"--hb-zw4-gap\": `${gap}px`,\n          \"--hb-zw4-ratio\": ratio,\n          ...style,\n        } as React.CSSProperties\n      }\n      onPointerEnter={(e) => {\n        if (e.pointerType === \"mouse\") setHover(true);\n      }}\n      onPointerLeave={() => setHover(false)}\n      onFocus={() => setFocused(true)}\n      onBlur={(e) => {\n        if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setFocused(false);\n      }}\n      onKeyDown={keyDown}\n      {...rest}\n    >\n      <style href=\"hb-gallery-grid-expand\" precedence=\"default\">\n        {css}\n      </style>\n      <ul className=\"hb-zw4-grid\">\n        {list.map((img, i) => (\n          <li key={i}>\n            <button\n              ref={(el) => {\n                cardRefs.current[i] = el;\n              }}\n              type=\"button\"\n              className=\"hb-zw4-card\"\n              aria-label={`Open ${img.title}`}\n              aria-expanded={open === i}\n              tabIndex={open !== null ? -1 : 0}\n              onClick={() => request(i, true)}\n            >\n              <span className=\"hb-zw4-cbg\" style={{ backgroundImage: imageUrl(img.src, i) }} />\n              <span className=\"hb-zw4-ctitle\">{img.title}</span>\n            </button>\n          </li>\n        ))}\n      </ul>\n      {item !== null && shown !== null ? (\n        <div\n          ref={panelRef}\n          className=\"hb-zw4-panel\"\n          role=\"dialog\"\n          aria-label={item.title}\n          data-phase=\"from\"\n        >\n          <div ref={imgRef} className=\"hb-zw4-pimg\">\n            {list.map((img, i) => (\n              <div\n                key={i}\n                className=\"hb-zw4-layer\"\n                data-on={i === shown ? \"true\" : \"false\"}\n                style={{ backgroundImage: imageUrl(img.src, i) }}\n              />\n            ))}\n          </div>\n          <div className=\"hb-zw4-info\">\n            <div className=\"hb-zw4-top\">\n              <button ref={backRef} type=\"button\" className=\"hb-zw4-btn\" onClick={() => request(null, true)}>\n                <Icon d=\"M10 3.5 5.5 8 10 12.5\" />\n                Back\n              </button>\n            </div>\n            <div className=\"hb-zw4-bottom\">\n              <div className=\"hb-zw4-text\" aria-live=\"polite\">\n                <p className=\"hb-zw4-index\">\n                  {String(shown + 1).padStart(2, \"0\")} / {String(n).padStart(2, \"0\")}\n                </p>\n                <p className=\"hb-zw4-title\">{item.title}</p>\n                {item.caption ? <p className=\"hb-zw4-caption\">{item.caption}</p> : null}\n              </div>\n              {n > 1 ? (\n                <div className=\"hb-zw4-pair\">\n                  <button\n                    type=\"button\"\n                    className=\"hb-zw4-btn hb-zw4-round\"\n                    aria-label=\"Previous image\"\n                    onClick={() => request(((shown - 1) % n + n) % n, true)}\n                  >\n                    <Icon d=\"M10 3.5 5.5 8 10 12.5\" />\n                  </button>\n                  <button\n                    type=\"button\"\n                    className=\"hb-zw4-btn hb-zw4-round\"\n                    aria-label=\"Next image\"\n                    onClick={() => request((shown + 1) % n, true)}\n                  >\n                    <Icon d=\"M6 3.5 10.5 8 6 12.5\" />\n                  </button>\n                </div>\n              ) : null}\n            </div>\n          </div>\n        </div>\n      ) : null}\n    </div>\n  );\n}\n"
    }
  ]
}