{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "image-gallery-expand",
  "type": "registry:component",
  "title": "Image Gallery Expand",
  "description": "A row of narrow image strips where the hovered or focused strip widens to reveal its caption. Click or press Enter to select one.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "transitions",
    "image",
    "gallery",
    "accordion",
    "expand",
    "strips",
    "hover"
  ],
  "docs": "https://hyperblur.dev/effects/image-gallery-expand",
  "files": [
    {
      "path": "registry/hyperblur/image-gallery-expand.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/image-gallery-expand.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nconst SCENE_COUNT = 4;\n\nconst SCENE_NAMES = [\"Alpine dusk\", \"Neon district\", \"Tidal lines\", \"Studio light\"];\n\ntype SceneLayer = \"all\" | \"back\" | \"mid\" | \"front\";\n\nfunction mod(n: number, m: number) {\n  return ((n % m) + m) % m;\n}\n\nfunction hash(n: number) {\n  let x = Math.imul(n + 1, 2654435761) >>> 0;\n  x = Math.imul(x ^ (x >>> 15), 2246822519) >>> 0;\n  x = Math.imul(x ^ (x >>> 13), 3266489917) >>> 0;\n  return (x ^ (x >>> 16)) >>> 0;\n}\n\nconst sceneCache = new Map<string, string>();\n\nfunction sceneSvg(k: number, layer: SceneLayer) {\n  const on = (name: string) => layer === \"all\" || layer === name;\n  let s = '<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 320 200\" width=\"320\" height=\"200\">';\n  if (k === 0) {\n    if (on(\"back\")) {\n      s +=\n        '<defs><linearGradient id=\"g\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#ffb36b\"/><stop offset=\"0.5\" stop-color=\"#ff6f91\"/><stop offset=\"1\" stop-color=\"#4b3b8f\"/></linearGradient></defs><rect width=\"320\" height=\"200\" fill=\"url(#g)\"/><circle cx=\"220\" cy=\"96\" r=\"46\" fill=\"#ffe3a8\" opacity=\"0.22\"/><circle cx=\"220\" cy=\"96\" r=\"26\" fill=\"#ffe9bd\"/>';\n    }\n    if (on(\"mid\")) {\n      s +=\n        '<polygon points=\"0,140 50,92 90,122 140,70 200,128 250,96 320,138 320,200 0,200\" fill=\"#6a4a98\"/><polygon points=\"0,158 70,118 130,148 190,110 260,150 320,128 320,200 0,200\" fill=\"#3d2c70\"/>';\n    }\n    if (on(\"front\")) {\n      s += '<path d=\"M0 178 Q80 150 160 172 T320 166 L320 200 L0 200Z\" fill=\"#1b1640\"/>';\n      for (let i = 0; i < 9; i += 1) {\n        const x = 12 + i * 36 + (hash(i + 3) % 14);\n        const h = 26 + (hash(i + 9) % 18);\n        s += `<polygon points=\"${x},${200 - h - 6} ${x - 8},${206 - 6} ${x + 8},${206 - 6}\" fill=\"#120e30\"/><rect x=\"${x - 1}\" y=\"${200 - 8}\" width=\"2\" height=\"8\" fill=\"#120e30\"/>`;\n      }\n    }\n  } else if (k === 1) {\n    if (on(\"back\")) {\n      s +=\n        '<defs><linearGradient id=\"g\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#14183f\"/><stop offset=\"0.55\" stop-color=\"#6a3d8f\"/><stop offset=\"1\" stop-color=\"#ff8a7a\"/></linearGradient></defs><rect width=\"320\" height=\"200\" fill=\"url(#g)\"/><circle cx=\"252\" cy=\"46\" r=\"16\" fill=\"#fff1d6\"/><circle cx=\"259\" cy=\"41\" r=\"14\" fill=\"#3a2f78\" opacity=\"0.4\"/>';\n      for (let i = 0; i < 22; i += 1) {\n        const h = hash(i + 11);\n        s += `<circle cx=\"${h % 320}\" cy=\"${hash(i + 71) % 80}\" r=\"${(0.5 + (h % 5) / 6).toFixed(2)}\" fill=\"#fff\" opacity=\"0.${5 + (h % 4)}\"/>`;\n      }\n    }\n    if (on(\"mid\")) {\n      const fx = [0, 28, 64, 98, 132, 170, 208, 246, 284];\n      const fw = [32, 40, 38, 40, 42, 42, 42, 42, 40];\n      const fh = [96, 120, 88, 130, 104, 126, 92, 118, 100];\n      fx.forEach((x, i) => {\n        s += `<rect x=\"${x}\" y=\"${200 - fh[i]}\" width=\"${fw[i]}\" height=\"${fh[i]}\" fill=\"#3b3182\" opacity=\"0.92\"/>`;\n      });\n    }\n    if (on(\"front\")) {\n      const nx = [-6, 40, 86, 136, 190, 236, 282];\n      const nw = [50, 50, 54, 60, 52, 52, 50];\n      const nh = [74, 100, 64, 92, 110, 70, 90];\n      nx.forEach((x, b) => {\n        s += `<rect x=\"${x}\" y=\"${200 - nh[b]}\" width=\"${nw[b]}\" height=\"${nh[b]}\" fill=\"#16132f\"/>`;\n        const cols = Math.floor((nw[b] - 10) / 11);\n        const rows = Math.floor((nh[b] - 10) / 13);\n        for (let r = 0; r < rows; r += 1) {\n          for (let c = 0; c < cols; c += 1) {\n            const h = hash(b * 100 + r * 10 + c);\n            if (h % 3 !== 0) {\n              s += `<rect x=\"${x + 6 + c * 11}\" y=\"${200 - nh[b] + 8 + r * 13}\" width=\"5\" height=\"7\" fill=\"${h % 4 === 0 ? \"#ff9f80\" : \"#ffd37a\"}\"/>`;\n            }\n          }\n        }\n      });\n    }\n  } else if (k === 2) {\n    if (on(\"back\")) {\n      s +=\n        '<defs><linearGradient id=\"g\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\"><stop offset=\"0\" stop-color=\"#0b1f5c\"/><stop offset=\"0.55\" stop-color=\"#1c7ed6\"/><stop offset=\"1\" stop-color=\"#5ee0c8\"/></linearGradient></defs><rect width=\"320\" height=\"200\" fill=\"url(#g)\"/><circle cx=\"72\" cy=\"52\" r=\"20\" fill=\"#fff\" opacity=\"0.25\"/>';\n    }\n    if (on(\"mid\")) {\n      s +=\n        '<path d=\"M0 110 C60 80 120 140 180 108 S280 90 320 112 V200 H0Z\" fill=\"#fff\" opacity=\"0.16\"/><path d=\"M0 130 C70 100 130 160 200 128 S290 112 320 134 V200 H0Z\" fill=\"#7ee8d3\" opacity=\"0.32\"/>';\n    }\n    if (on(\"front\")) {\n      s +=\n        '<path d=\"M0 156 C80 130 140 184 210 154 S290 142 320 160 V200 H0Z\" fill=\"#0a2f6a\" opacity=\"0.88\"/><path d=\"M0 178 C90 160 160 196 240 176 S300 170 320 182 V200 H0Z\" fill=\"#061a42\"/>';\n    }\n  } else {\n    if (on(\"back\")) {\n      s +=\n        '<defs><radialGradient id=\"g\" cx=\"0.5\" cy=\"0.38\" r=\"0.8\"><stop offset=\"0\" stop-color=\"#ffd9b0\"/><stop offset=\"0.55\" stop-color=\"#ea6f8f\"/><stop offset=\"1\" stop-color=\"#43235f\"/></radialGradient></defs><rect width=\"320\" height=\"200\" fill=\"url(#g)\"/>';\n    }\n    if (on(\"mid\")) {\n      s +=\n        '<circle cx=\"160\" cy=\"100\" r=\"72\" fill=\"none\" stroke=\"#fff\" stroke-width=\"1.5\" opacity=\"0.24\"/><path d=\"M70 120 C60 70 120 40 170 52 C230 64 262 110 236 150 C210 190 100 180 70 120Z\" fill=\"#fff\" opacity=\"0.13\"/>';\n    }\n    if (on(\"front\")) {\n      s +=\n        '<path d=\"M70 200 C74 160 112 148 160 148 C208 148 246 160 250 200Z\" fill=\"#2a1a48\"/><rect x=\"146\" y=\"124\" width=\"28\" height=\"32\" fill=\"#d9987a\"/><ellipse cx=\"160\" cy=\"98\" rx=\"30\" ry=\"35\" fill=\"#f0b698\"/><path d=\"M128 96 C124 62 150 50 172 56 C196 62 198 84 192 98 C186 78 170 72 150 74 C140 76 132 84 128 96Z\" fill=\"#2b1230\"/><circle cx=\"160\" cy=\"160\" r=\"4\" fill=\"#ffd37a\"/>';\n    }\n  }\n  return `${s}</svg>`;\n}\n\nfunction sceneUri(index: number, layer: SceneLayer = \"all\") {\n  const k = mod(index, SCENE_COUNT);\n  const key = `${k}:${layer}`;\n  let uri = sceneCache.get(key);\n  if (!uri) {\n    uri = `data:image/svg+xml,${encodeURIComponent(sceneSvg(k, layer))}`;\n    sceneCache.set(key, uri);\n  }\n  return uri;\n}\n\nfunction cssUrl(list: string[] | null, index: number, layer: SceneLayer = \"all\") {\n  if (list) return `url(${JSON.stringify(list[mod(index, list.length)])})`;\n  return `url(\"${sceneUri(index, layer)}\")`;\n}\n\nfunction cx(base: string, extra?: string) {\n  return extra ? `${base} ${extra}` : base;\n}\n\nfunction rootBox(\n  width: number | string | undefined,\n  height: number | string | undefined,\n  aspect: string,\n  style: React.CSSProperties | undefined,\n): React.CSSProperties {\n  return {\n    width: width ?? \"100%\",\n    ...(height !== undefined ? { height } : { aspectRatio: aspect }),\n    ...style,\n  };\n}\n\nconst motionQuery = \"(prefers-reduced-motion: reduce)\";\n\nfunction subscribeMotion(callback: () => void) {\n  const query = window.matchMedia(motionQuery);\n  query.addEventListener(\"change\", callback);\n  return () => query.removeEventListener(\"change\", callback);\n}\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    subscribeMotion,\n    () => window.matchMedia(motionQuery).matches,\n    () => false,\n  );\n}\n\nfunction useInView(ref: React.RefObject<HTMLElement | null>) {\n  const [visible, setVisible] = React.useState(true);\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el || typeof IntersectionObserver === \"undefined\") return;\n    const observer = new IntersectionObserver((entries) => {\n      const last = entries[entries.length - 1];\n      if (last) setVisible(last.isIntersecting);\n    });\n    observer.observe(el);\n    return () => observer.disconnect();\n  }, [ref]);\n  return visible;\n}\n\nfunction useAutoAdvance(\n  enabled: boolean,\n  interval: number,\n  step: () => void,\n  ref: React.RefObject<HTMLElement | null>,\n  paused: boolean,\n  resetKey: number,\n) {\n  const reduced = useReducedMotion();\n  const visible = useInView(ref);\n  const stepRef = React.useRef(step);\n  React.useEffect(() => {\n    stepRef.current = step;\n  });\n  React.useEffect(() => {\n    if (!enabled || reduced || !visible || paused) return;\n    const id = window.setInterval(() => stepRef.current(), interval);\n    return () => window.clearInterval(id);\n  }, [enabled, reduced, visible, paused, interval, resetKey]);\n}\n\nfunction useSlideIndex(\n  count: number,\n  value: number | undefined,\n  initial: number,\n  onChange?: (index: number) => void,\n) {\n  const [inner, setInner] = React.useState(initial);\n  const controlled = value !== undefined;\n  const current = mod(controlled ? value : inner, count);\n  const set = (next: number) => {\n    const n = mod(next, count);\n    if (n === current) return;\n    if (!controlled) setInner(n);\n    onChange?.(n);\n  };\n  return [current, set] as const;\n}\n\nexport interface ImageGalleryExpandProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n  images?: string[];\n  captions?: string[];\n  alt?: string;\n  width?: number | string;\n  height?: number | string;\n  aspect?: string;\n  index?: number;\n  defaultIndex?: number;\n  onChange?: (index: number) => void;\n  expand?: number;\n  gap?: number;\n  autoPlay?: boolean;\n  interval?: number;\n  accent?: string;\n}\n\nconst css = `\n.hb-qe8 {\n  --hb-qe8-a: #2f7bff;\n  position: relative;\n  display: block;\n  box-sizing: border-box;\n  overflow: hidden;\n  border-radius: 14px;\n  background: #0a0a0a;\n  isolation: isolate;\n  font-family: inherit;\n  user-select: none;\n  -webkit-user-select: none;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-qe8 *, .hb-qe8 *::before, .hb-qe8 *::after { box-sizing: border-box; }\n.hb-qe8:focus-visible { outline: 2px solid var(--hb-qe8-a); outline-offset: 2px; }\n.hb-qe8-layer { position: absolute; inset: 0; }\n.hb-qe8-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  padding: 0;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n  border: 0;\n}\n.hb-qe8 {\n  display: flex;\n  gap: var(--hb-qe8-gap);\n  overflow: visible;\n  background: transparent;\n  border-radius: 0;\n}\n.hb-qe8-strip {\n  position: relative;\n  flex: 1 1 0;\n  min-width: 0;\n  margin: 0;\n  padding: 0;\n  overflow: hidden;\n  color: #fff;\n  font: inherit;\n  text-align: left;\n  background-color: #151515;\n  background-size: cover;\n  background-position: center;\n  border: 0;\n  border-radius: 12px;\n  cursor: pointer;\n  filter: saturate(0.8) brightness(0.78);\n  transition: flex-grow 0.65s cubic-bezier(0.3, 0.8, 0.2, 1), filter 0.45s ease;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-qe8-strip[data-open=\"true\"] { flex-grow: var(--hb-qe8-g); filter: none; }\n.hb-qe8-strip[data-selected=\"true\"] { box-shadow: inset 0 0 0 2px var(--hb-qe8-a); }\n.hb-qe8-strip:focus-visible { outline: 2px solid #fff; outline-offset: -5px; }\n.hb-qe8-shade {\n  position: absolute;\n  inset: 0;\n  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 45%, rgba(0, 0, 0, 0.62) 100%);\n  pointer-events: none;\n}\n.hb-qe8-num {\n  position: absolute;\n  left: 50%;\n  bottom: 12px;\n  font-size: 10px;\n  font-weight: 600;\n  font-variant-numeric: tabular-nums;\n  letter-spacing: 0.06em;\n  color: rgba(255, 255, 255, 0.85);\n  transform: translateX(-50%);\n  transition: opacity 0.25s ease;\n}\n.hb-qe8-strip[data-open=\"true\"] .hb-qe8-num { opacity: 0; }\n.hb-qe8-cap {\n  position: absolute;\n  left: 12px;\n  right: 12px;\n  bottom: 12px;\n  overflow: hidden;\n  font-size: 13px;\n  font-weight: 600;\n  line-height: 1.3;\n  letter-spacing: -0.01em;\n  text-overflow: ellipsis;\n  white-space: nowrap;\n  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.5);\n  opacity: 0;\n  transform: translateY(8px);\n  transition: opacity 0.3s ease, transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);\n}\n.hb-qe8-strip[data-open=\"true\"] .hb-qe8-cap { opacity: 1; transform: none; transition-delay: 0.2s; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-qe8-strip, .hb-qe8-num, .hb-qe8-cap { transition: none; }\n}\n`;\n\nexport function ImageGalleryExpand({\n  images,\n  captions,\n  alt = \"Photo\",\n  width,\n  height,\n  aspect = \"16 / 9\",\n  index: indexProp,\n  defaultIndex = 0,\n  onChange,\n  expand = 5,\n  gap = 6,\n  autoPlay = true,\n  interval = 2400,\n  accent = \"#2f7bff\",\n  className,\n  style,\n  onKeyDown,\n  onPointerLeave,\n  onBlur,\n  ...rest\n}: ImageGalleryExpandProps) {\n  const list = images && images.length > 0 ? images : null;\n  const count = list ? list.length : SCENE_COUNT;\n  const names = captions ?? (list ? [] : SCENE_NAMES);\n  const [index, setIndex] = useSlideIndex(count, indexProp, defaultIndex, onChange);\n  const [hover, setHover] = React.useState<number | null>(null);\n  const [auto, setAuto] = React.useState(index);\n  const [engaged, setEngaged] = React.useState(false);\n  const ref = React.useRef<HTMLDivElement>(null);\n  const strips = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const cycling = autoPlay && !engaged && count > 1;\n  useAutoAdvance(cycling, interval, () => setAuto((a) => (a + 1) % count), ref, hover !== null, auto);\n  const expanded = hover ?? (cycling ? auto : index);\n  const labelOf = (i: number) => names[i] ?? `${alt} ${i + 1} of ${count}`;\n\n  return (\n    <div\n      role=\"group\"\n      aria-label={`${alt} gallery`}\n      {...rest}\n      ref={ref}\n      className={cx(\"hb-qe8\", className)}\n      style={\n        {\n          ...rootBox(width, height, aspect, style),\n          \"--hb-qe8-a\": accent,\n          \"--hb-qe8-g\": Math.max(1, expand),\n          \"--hb-qe8-gap\": `${gap}px`,\n        } as React.CSSProperties\n      }\n      onPointerLeave={(e) => {\n        setHover(null);\n        onPointerLeave?.(e);\n      }}\n      onBlur={(e) => {\n        if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setHover(null);\n        onBlur?.(e);\n      }}\n      onKeyDown={(e) => {\n        onKeyDown?.(e);\n        if (e.defaultPrevented) return;\n        const current = strips.current.findIndex((el) => el === document.activeElement);\n        if (current < 0) return;\n        let next = -1;\n        if (e.key === \"ArrowRight\") next = mod(current + 1, count);\n        else if (e.key === \"ArrowLeft\") next = mod(current - 1, count);\n        else if (e.key === \"Home\") next = 0;\n        else if (e.key === \"End\") next = count - 1;\n        if (next < 0) return;\n        e.preventDefault();\n        strips.current[next]?.focus();\n      }}\n    >\n      <style href=\"hb-image-gallery-expand\" precedence=\"default\">\n        {css}\n      </style>\n      {Array.from({ length: count }, (_, i) => (\n        <button\n          key={i}\n          ref={(el) => {\n            strips.current[i] = el;\n          }}\n          type=\"button\"\n          className=\"hb-qe8-strip\"\n          data-open={i === expanded ? \"true\" : \"false\"}\n          data-selected={i === index ? \"true\" : \"false\"}\n          aria-pressed={i === index}\n          aria-label={labelOf(i)}\n          tabIndex={i === index ? 0 : -1}\n          style={{ backgroundImage: cssUrl(list, i) }}\n          onPointerEnter={() => setHover(i)}\n          onFocus={(e) => {\n            if (e.currentTarget.matches(\":focus-visible\")) setHover(i);\n          }}\n          onClick={() => {\n            setEngaged(true);\n            setAuto(i);\n            setIndex(i);\n          }}\n        >\n          <span className=\"hb-qe8-shade\" aria-hidden=\"true\" />\n          <span className=\"hb-qe8-num\" aria-hidden=\"true\">\n            {String(i + 1).padStart(2, \"0\")}\n          </span>\n          <span className=\"hb-qe8-cap\" aria-hidden=\"true\">\n            {labelOf(i)}\n          </span>\n        </button>\n      ))}\n    </div>\n  );\n}\n"
    }
  ]
}