{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "gallery-runway",
  "type": "registry:component",
  "title": "Gallery Runway",
  "description": "Framed images walk toward the viewer along a lit runway in 3D, growing and stepping aside as they pass. Hovering a frame stops the flow.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "components",
    "gallery",
    "3d",
    "perspective",
    "runway",
    "images",
    "showcase"
  ],
  "docs": "https://hyperblur.dev/effects/gallery-runway",
  "files": [
    {
      "path": "registry/hyperblur/gallery-runway.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/gallery-runway.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface RunwayImage {\n  src?: string;\n  title: string;\n  caption?: string;\n}\n\nexport interface GalleryRunwayProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\"> {\n  images?: RunwayImage[];\n  value?: number | null;\n  defaultValue?: number | null;\n  onChange?: (index: number) => void;\n  speed?: number;\n  playing?: boolean;\n  accent?: string;\n  height?: number | string;\n}\n\ntype Scene = {\n  title: string;\n  caption: string;\n  sky: [string, string, string];\n  sun: string;\n  hills: [string, string, string];\n};\n\nconst scenes: Scene[] = [\n  { title: \"Dune Sunrise\", caption: \"Erg Chebbi, 6:12 am\", sky: [\"#ffd08a\", \"#ff7a59\", \"#5b2a6e\"], sun: \"#fff1c9\", hills: [\"#c4573f\", \"#7d2e45\", \"#3a1631\"] },\n  { title: \"Harbor Lights\", caption: \"Lisbon waterfront\", sky: [\"#0d1640\", \"#2c3f9c\", \"#7aa7ff\"], sun: \"#e8f0ff\", hills: [\"#2a3a8a\", \"#18205a\", \"#0a0e2c\"] },\n  { title: \"Glacier Lake\", caption: \"Moraine Lake, Alberta\", sky: [\"#d6fbf6\", \"#5fcfcf\", \"#0e5a74\"], sun: \"#ffffff\", hills: [\"#3e8fa0\", \"#1f5f73\", \"#0b2f40\"] },\n  { title: \"Neon Alley\", caption: \"Shinjuku, 1:40 am\", sky: [\"#2a0b3f\", \"#8a1f7a\", \"#ff4fa3\"], sun: \"#ffd1ec\", hills: [\"#5a1460\", \"#33093f\", \"#16041f\"] },\n  { title: \"Pine Ridge\", caption: \"Olympic Peninsula\", sky: [\"#eef4d8\", \"#97c27a\", \"#28563a\"], sun: \"#fffbe6\", hills: [\"#4f8a52\", \"#2c5c3a\", \"#123222\"] },\n  { title: \"Coral Hour\", caption: \"Big Sur coastline\", sky: [\"#ffe6d6\", \"#ff9f8a\", \"#c2457a\"], sun: \"#fff4e8\", hills: [\"#d0627a\", \"#8e2f5c\", \"#46163a\"] },\n];\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<number, string>();\n\nfunction sceneUri(i: number) {\n  const k = mod(i, scenes.length);\n  const hit = sceneCache.get(k);\n  if (hit) return hit;\n  const sc = scenes[k];\n  let s = `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 320 200\" preserveAspectRatio=\"xMidYMid slice\"><defs><linearGradient id=\"s\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"${sc.sky[0]}\"/><stop offset=\"0.55\" stop-color=\"${sc.sky[1]}\"/><stop offset=\"1\" stop-color=\"${sc.sky[2]}\"/></linearGradient></defs><rect width=\"320\" height=\"200\" fill=\"url(#s)\"/>`;\n  const sx = 60 + (hash(k * 13) % 200);\n  const sy = 40 + (hash(k * 17) % 40);\n  s += `<circle cx=\"${sx}\" cy=\"${sy}\" r=\"34\" fill=\"${sc.sun}\" opacity=\"0.18\"/><circle cx=\"${sx}\" cy=\"${sy}\" r=\"18\" fill=\"${sc.sun}\" opacity=\"0.9\"/>`;\n  for (let l = 0; l < 3; l += 1) {\n    const base = 112 + l * 30;\n    const amp = 34 - l * 8;\n    let d = `M0 200 L0 ${base - (hash(k * 41 + l * 7) % amp)}`;\n    for (let j = 1; j <= 8; j += 1) {\n      d += ` L${j * 40} ${base - (hash(k * 41 + l * 7 + j * 3) % amp)}`;\n    }\n    s += `<path d=\"${d} L320 200Z\" fill=\"${sc.hills[l]}\"/>`;\n  }\n  s += \"</svg>\";\n  const uri = `data:image/svg+xml,${encodeURIComponent(s)}`;\n  sceneCache.set(k, uri);\n  return uri;\n}\n\nconst defaults: RunwayImage[] = scenes.map((s) => ({ title: s.title, caption: s.caption }));\n\nfunction imageUrl(list: RunwayImage[], i: number) {\n  const item = list[i];\n  return item?.src ? `url(${JSON.stringify(item.src)})` : `url(\"${sceneUri(i)}\")`;\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\nconst css = `\n.hb-zx5 {\n  --hb-zx5-a: #2f7bff;\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  overflow: hidden;\n  container-type: size;\n  border: 1px solid #222222;\n  border-radius: 14px;\n  background: linear-gradient(180deg, #08090c 0%, #0b0c10 34%, #060606 100%);\n  color: #ededed;\n  font-family: inherit;\n  user-select: none;\n  -webkit-user-select: none;\n  -webkit-tap-highlight-color: transparent;\n  isolation: isolate;\n  outline: none;\n}\n.hb-zx5 *, .hb-zx5 *::before, .hb-zx5 *::after { box-sizing: border-box; }\n.hb-zx5:focus-visible { box-shadow: 0 0 0 2px #0a0a0a, 0 0 0 4px var(--hb-zx5-a); }\n.hb-zx5-horizon {\n  position: absolute;\n  left: 50%;\n  top: 34%;\n  width: 120cqh;\n  height: 26cqh;\n  border-radius: 50%;\n  transform: translate(-50%, -50%);\n  background: var(--hb-zx5-a);\n  opacity: 0.22;\n  filter: blur(26px);\n  pointer-events: none;\n}\n.hb-zx5-stage {\n  position: absolute;\n  inset: 0;\n  perspective: 330cqh;\n  perspective-origin: 50% 34%;\n  transform-style: preserve-3d;\n}\n.hb-zx5-floor {\n  position: absolute;\n  left: 50%;\n  bottom: 22%;\n  width: 150cqh;\n  height: 1100cqh;\n  transform-origin: 50% 100%;\n  transform: translateX(-50%) translateZ(110cqh) rotateX(90deg);\n  background-image:\n    radial-gradient(circle, #ffffff 0 16%, color-mix(in srgb, var(--hb-zx5-a) 70%, transparent) 26%, transparent 46%),\n    radial-gradient(circle, #ffffff 0 16%, color-mix(in srgb, var(--hb-zx5-a) 70%, transparent) 26%, transparent 46%),\n    linear-gradient(90deg, transparent 49.4%, rgba(255,255,255,0.16) 49.4% 50.6%, transparent 50.6%),\n    linear-gradient(90deg, transparent 4%, color-mix(in srgb, var(--hb-zx5-a) 55%, transparent) 4% 4.8%, transparent 4.8% 95.2%, color-mix(in srgb, var(--hb-zx5-a) 55%, transparent) 95.2% 96%, transparent 96%),\n    linear-gradient(180deg, #0c0d12 0%, #141519 100%);\n  background-size: 9cqh 70cqh, 9cqh 70cqh, 100% 40cqh, 100% 100%, 100% 100%;\n  background-repeat: repeat-y, repeat-y, repeat-y, no-repeat, no-repeat;\n  background-position: 1.5% 0, 98.5% 0, 0 0, 0 0, 0 0;\n  -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 45%);\n  mask-image: linear-gradient(180deg, transparent 0%, #000 45%);\n  pointer-events: none;\n}\n.hb-zx5-frame {\n  position: absolute;\n  left: 50%;\n  bottom: 22%;\n  width: 36cqh;\n  aspect-ratio: 4 / 5;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 5px;\n  background-color: #111;\n  background-size: cover;\n  background-position: center;\n  cursor: pointer;\n  transform-origin: 50% 100%;\n  will-change: transform, opacity;\n  box-shadow: 0 0 0 1px rgba(255,255,255,0.12), 0 14px 28px rgba(0,0,0,0.6);\n  transition: box-shadow 0.3s ease;\n}\n.hb-zx5-frame::after {\n  content: \"\";\n  position: absolute;\n  left: 8%;\n  right: 8%;\n  bottom: -7%;\n  height: 10%;\n  border-radius: 50%;\n  background: rgba(0,0,0,0.75);\n  filter: blur(5px);\n  z-index: -1;\n}\n.hb-zx5-frame[data-hot=\"true\"] { box-shadow: 0 0 0 1.5px #ffffff, 0 0 28px -4px var(--hb-zx5-a), 0 14px 28px rgba(0,0,0,0.6); }\n.hb-zx5-frame[data-sel=\"true\"] { box-shadow: 0 0 0 2px var(--hb-zx5-a), 0 0 30px -2px var(--hb-zx5-a), 0 14px 28px rgba(0,0,0,0.6); }\n.hb-zx5-plate {\n  position: absolute;\n  left: 0;\n  right: 0;\n  bottom: 0;\n  padding: 18% 7% 6%;\n  border-radius: 0 0 5px 5px;\n  background: linear-gradient(180deg, transparent, rgba(0,0,0,0.72));\n  font-size: 3.6cqh;\n  font-weight: 600;\n  line-height: 1.15;\n  text-align: left;\n  color: #fff;\n  white-space: nowrap;\n  overflow: hidden;\n  text-overflow: ellipsis;\n  pointer-events: none;\n}\n.hb-zx5-hud {\n  position: absolute;\n  left: 10px;\n  top: 9px;\n  right: 10px;\n  z-index: 2000;\n  display: flex;\n  align-items: flex-start;\n  justify-content: space-between;\n  gap: 8px;\n  pointer-events: none;\n}\n.hb-zx5-now { min-width: 0; }\n.hb-zx5-kick { margin: 0; font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--hb-zx5-a); }\n.hb-zx5-title { margin: 2px 0 0; font-size: 13px; font-weight: 600; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; animation: hb-zx5-in 0.4s ease both; }\n.hb-zx5-cap { margin: 1px 0 0; font-size: 10.5px; color: #8f8f8f; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n.hb-zx5-state {\n  flex: none;\n  display: inline-flex;\n  align-items: center;\n  gap: 5px;\n  height: 20px;\n  padding: 0 8px;\n  border: 1px solid rgba(255,255,255,0.1);\n  border-radius: 999px;\n  background: rgba(10,10,10,0.6);\n  font-size: 10px;\n  color: #a1a1a1;\n  font-variant-numeric: tabular-nums;\n}\n.hb-zx5-dot { width: 6px; height: 6px; border-radius: 999px; background: #3ddc84; box-shadow: 0 0 8px #3ddc84; }\n.hb-zx5-dot[data-paused=\"true\"] { background: #f5b04a; box-shadow: 0 0 8px #f5b04a; }\n@keyframes hb-zx5-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-zx5-frame { transition: none; }\n  .hb-zx5-title { animation: none; }\n}\n`;\n\nfunction smooth(a: number, b: number, v: number) {\n  const t = Math.max(0, Math.min(1, (v - a) / (b - a)));\n  return t * t * (3 - 2 * t);\n}\n\nfunction slotPose(p: number, j: number) {\n  const side = j % 2 === 0 ? -1 : 1;\n  const x = side * (24 + Math.max(0, p - 0.5) * 80);\n  const z = -880 + p * 990;\n  const o = smooth(0, 0.14, p) * (1 - smooth(0.86, 1, p));\n  const b = 0.32 + 0.68 * smooth(0, 0.8, p);\n  return { x, z, o, b };\n}\n\nexport function GalleryRunway({\n  images,\n  value,\n  defaultValue = null,\n  onChange,\n  speed = 0.055,\n  playing = true,\n  accent = \"#2f7bff\",\n  height,\n  className,\n  style,\n  onKeyDown,\n  onFocus,\n  onBlur,\n  ...rest\n}: GalleryRunwayProps) {\n  const list = images && images.length > 0 ? images : defaults;\n  const n = list.length;\n  const slots = n >= 6 ? n : n * Math.ceil(6 / n);\n  const controlled = value !== undefined;\n  const [inner, setInner] = React.useState<number | null>(defaultValue);\n  const raw = controlled ? value : inner;\n  const sel = raw === null || raw === undefined ? null : mod(raw, n);\n  const [hot, setHot] = React.useState<number | null>(null);\n  const [front, setFront] = React.useState(0);\n  const [paused, setPaused] = React.useState(false);\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const floorRef = React.useRef<HTMLDivElement>(null);\n  const frameRefs = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const reduced = useReducedMotion();\n  const visible = useInView(rootRef);\n  const st = React.useRef({ flow: 0.04, rate: 1, nudge: 0, hold: false, manual: false, front: -1, slots });\n\n  React.useEffect(() => {\n    const s = st.current;\n    s.slots = slots;\n    s.hold = hot !== null;\n    s.manual = paused || !playing;\n  });\n\n  React.useEffect(() => {\n    const apply = () => {\n      const s = st.current;\n      let best = -1;\n      let bestP = -1;\n      for (let j = 0; j < s.slots; j += 1) {\n        const el = frameRefs.current[j];\n        const p = mod(s.flow + j / s.slots, 1);\n        const pose = slotPose(p, j);\n        if (p < 0.9 && p > bestP) {\n          bestP = p;\n          best = j;\n        }\n        if (!el) continue;\n        el.style.transform = `translate3d(calc(-50% + ${pose.x.toFixed(2)}cqh), 0, ${pose.z.toFixed(2)}cqh)`;\n        el.style.opacity = pose.o.toFixed(3);\n        el.style.filter = `brightness(${pose.b.toFixed(3)})`;\n        el.style.zIndex = String(Math.round(p * 1000));\n        el.style.pointerEvents = pose.o < 0.3 ? \"none\" : \"auto\";\n      }\n      const floor = floorRef.current;\n      if (floor) {\n        const y = mod(s.flow * 990, 280).toFixed(2);\n        floor.style.backgroundPosition = `1.5% ${y}cqh, 98.5% ${y}cqh, 0 ${y}cqh, 0 0, 0 0`;\n      }\n      if (best !== s.front) {\n        s.front = best;\n        setFront(best);\n      }\n    };\n    apply();\n    if (!visible) return;\n    let raf = 0;\n    let last = performance.now();\n    const loop = (t: number) => {\n      const dt = Math.min(0.05, (t - last) / 1000);\n      last = t;\n      const s = st.current;\n      const want = s.hold || s.manual || reduced ? 0 : 1;\n      s.rate += (want - s.rate) * (1 - Math.exp(-dt * 5));\n      if (Math.abs(want - s.rate) < 0.001) s.rate = want;\n      s.flow += speed * s.rate * dt;\n      if (s.nudge !== 0) {\n        const k = reduced ? s.nudge : s.nudge * (1 - Math.exp(-dt * 7));\n        s.flow += k;\n        s.nudge -= k;\n        if (Math.abs(s.nudge) < 0.0005) {\n          s.flow += s.nudge;\n          s.nudge = 0;\n        }\n      }\n      apply();\n      raf = requestAnimationFrame(loop);\n    };\n    raf = requestAnimationFrame(loop);\n    return () => cancelAnimationFrame(raf);\n  }, [visible, reduced, speed, slots]);\n\n  const select = (i: number) => {\n    if (!controlled) setInner(i);\n    onChange?.(i);\n  };\n\n  const handleKey = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    onKeyDown?.(e);\n    if (e.defaultPrevented) return;\n    const s = st.current;\n    if (e.key === \"ArrowUp\" || e.key === \"ArrowRight\") s.nudge += 1 / s.slots;\n    else if (e.key === \"ArrowDown\" || e.key === \"ArrowLeft\") s.nudge -= 1 / s.slots;\n    else if (e.key === \" \") setPaused((p) => !p);\n    else if (e.key === \"Enter\") {\n      if (front >= 0) select(front % n);\n    } else return;\n    e.preventDefault();\n  };\n\n  const shown = hot ?? (front >= 0 ? front % n : 0);\n  const item = list[shown];\n  const isPaused = paused || !playing || hot !== null || reduced;\n\n  const frames = Array.from({ length: slots }, (_, j) => {\n    const i = j % n;\n    return (\n      <button\n        key={j}\n        ref={(el) => {\n          frameRefs.current[j] = el;\n        }}\n        type=\"button\"\n        tabIndex={-1}\n        className=\"hb-zx5-frame\"\n        data-hot={hot === i}\n        data-sel={sel === i}\n        aria-label={list[i].title}\n        style={{ backgroundImage: imageUrl(list, i), opacity: 0 }}\n        onPointerEnter={() => setHot(i)}\n        onPointerLeave={() => setHot((h) => (h === i ? null : h))}\n        onClick={() => select(i)}\n      >\n        <span className=\"hb-zx5-plate\">{list[i].title}</span>\n      </button>\n    );\n  });\n\n  return (\n    <div\n      ref={rootRef}\n      role=\"region\"\n      aria-roledescription=\"carousel\"\n      aria-label=\"Runway gallery. Arrow keys move the flow, Space pauses, Enter selects the front frame.\"\n      tabIndex={0}\n      className={className ? `hb-zx5 ${className}` : \"hb-zx5\"}\n      style={{\n        ...(height !== undefined ? { height } : { aspectRatio: \"16 / 10\" }),\n        [\"--hb-zx5-a\" as string]: accent,\n        ...style,\n      }}\n      onKeyDown={handleKey}\n      onFocus={onFocus}\n      onBlur={onBlur}\n      {...rest}\n    >\n      <style href=\"hb-gallery-runway\" precedence=\"default\">\n        {css}\n      </style>\n      <div className=\"hb-zx5-horizon\" />\n      <div className=\"hb-zx5-stage\">\n        <div ref={floorRef} className=\"hb-zx5-floor\" />\n        {frames}\n      </div>\n      <div className=\"hb-zx5-hud\">\n        <div className=\"hb-zx5-now\">\n          <p className=\"hb-zx5-kick\">{hot !== null ? \"Paused on\" : sel === shown ? \"Selected\" : \"Now passing\"}</p>\n          <p className=\"hb-zx5-title\" key={shown}>\n            {item?.title}\n          </p>\n          {item?.caption ? <p className=\"hb-zx5-cap\">{item.caption}</p> : null}\n        </div>\n        <span className=\"hb-zx5-state\">\n          <span className=\"hb-zx5-dot\" data-paused={isPaused} />\n          {shown + 1}/{n}\n        </span>\n      </div>\n    </div>\n  );\n}\n\nexport default GalleryRunway;\n"
    }
  ]
}