{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "gallery-coverflow-lights",
  "type": "registry:component",
  "title": "Gallery Coverflow Lights",
  "description": "A cover flow where the active image throws soft colored light onto the stage while the neighbors turn away into the dark.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "components",
    "gallery",
    "coverflow",
    "carousel",
    "3d",
    "glow",
    "albums"
  ],
  "docs": "https://hyperblur.dev/effects/gallery-coverflow-lights",
  "files": [
    {
      "path": "registry/hyperblur/gallery-coverflow-lights.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/gallery-coverflow-lights.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface CoverflowLightsImage {\n  src?: string;\n  title: string;\n  caption?: string;\n  color?: string;\n}\n\nexport interface GalleryCoverflowLightsProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n  images?: CoverflowLightsImage[];\n  index?: number;\n  defaultIndex?: number;\n  onChange?: (index: number) => void;\n  autoPlay?: boolean;\n  interval?: number;\n  glow?: number;\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: CoverflowLightsImage[] = scenes.map((s) => ({ title: s.title, caption: s.caption }));\n\nfunction imageUrl(list: CoverflowLightsImage[], 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 sceneColors = [\"#ff7a59\", \"#4f7cff\", \"#2fd3c7\", \"#ff4fa3\", \"#7cc46a\", \"#ff8f7a\"];\n\nfunction lightOf(list: CoverflowLightsImage[], i: number) {\n  return list[i]?.color ?? sceneColors[mod(i, sceneColors.length)];\n}\n\nconst css = `\n.hb-zx3 {\n  position: relative;\n  box-sizing: border-box;\n  display: flex;\n  flex-direction: column;\n  width: 100%;\n  overflow: hidden;\n  border: 1px solid #222222;\n  border-radius: 14px;\n  background: #060606;\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-zx3 *, .hb-zx3 *::before, .hb-zx3 *::after { box-sizing: border-box; }\n.hb-zx3:focus-visible { box-shadow: 0 0 0 2px #0a0a0a, 0 0 0 4px var(--hb-zx3-l); }\n.hb-zx3-stage {\n  position: relative;\n  flex: 1 1 0;\n  min-height: 0;\n  container-type: size;\n  cursor: grab;\n  touch-action: pan-y;\n}\n.hb-zx3-stage[data-drag=\"true\"] { cursor: grabbing; }\n.hb-zx3-glow, .hb-zx3-spill, .hb-zx3-beam {\n  position: absolute;\n  pointer-events: none;\n  background-color: var(--hb-zx3-l);\n  transition: background-color 0.9s ease, opacity 0.9s ease;\n}\n.hb-zx3-glow {\n  left: 50%;\n  top: 46%;\n  width: 70cqw;\n  height: 90cqh;\n  border-radius: 50%;\n  transform: translate(-50%, -50%);\n  filter: blur(40px);\n  opacity: calc(0.42 * var(--hb-zx3-g));\n}\n.hb-zx3-spill {\n  left: 50%;\n  top: 82%;\n  width: 80cqw;\n  height: 24cqh;\n  border-radius: 50%;\n  transform: translate(-50%, -50%);\n  filter: blur(18px);\n  opacity: calc(0.45 * var(--hb-zx3-g));\n}\n.hb-zx3-beam {\n  left: 50%;\n  top: 0;\n  width: 70cqw;\n  height: 60cqh;\n  transform: translateX(-50%);\n  clip-path: polygon(40% 0, 60% 0, 100% 100%, 0 100%);\n  -webkit-mask-image: linear-gradient(180deg, rgba(0,0,0,0.9), transparent);\n  mask-image: linear-gradient(180deg, rgba(0,0,0,0.9), transparent);\n  filter: blur(6px);\n  opacity: calc(0.22 * var(--hb-zx3-g));\n}\n.hb-zx3-world {\n  position: absolute;\n  inset: 0;\n  perspective: 280cqh;\n  perspective-origin: 50% 45%;\n  transform-style: preserve-3d;\n}\n.hb-zx3-card {\n  --hb-zx3-c: min(30cqw, 62cqh);\n  position: absolute;\n  left: 50%;\n  top: 45%;\n  width: var(--hb-zx3-c);\n  aspect-ratio: 1 / 1;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 8px;\n  background-color: #111;\n  background-size: cover;\n  background-position: center;\n  cursor: pointer;\n  transform-style: preserve-3d;\n  transition: transform 0.6s cubic-bezier(0.22, 0.8, 0.24, 1), filter 0.6s ease, box-shadow 0.9s ease, opacity var(--hb-zx3-od, 0.35s) ease var(--hb-zx3-dl, 0s);\n  will-change: transform;\n}\n.hb-zx3-card:focus-visible { outline: 2px solid var(--hb-zx3-l); outline-offset: 3px; }\n.hb-zx3-card[data-on=\"true\"] { box-shadow: 0 0 0 1px rgba(255,255,255,0.14), 0 0 46px -6px var(--hb-zx3-l), 0 18px 34px rgba(0,0,0,0.6); }\n.hb-zx3-refl {\n  position: absolute;\n  left: 0;\n  right: 0;\n  top: calc(100% + 3px);\n  height: 55%;\n  border-radius: 8px;\n  background: inherit;\n  background-size: 100% 182%;\n  background-position: bottom;\n  transform: scaleY(-1);\n  opacity: 0.28;\n  -webkit-mask-image: linear-gradient(0deg, rgba(0,0,0,0.9), transparent 75%);\n  mask-image: linear-gradient(0deg, rgba(0,0,0,0.9), transparent 75%);\n  pointer-events: none;\n}\n.hb-zx3[data-drag=\"true\"] .hb-zx3-card { transition: box-shadow 0.9s ease; }\n.hb-zx3-arrow {\n  position: absolute;\n  top: 45%;\n  z-index: 200;\n  width: 30px;\n  height: 30px;\n  display: grid;\n  place-items: center;\n  margin: 0;\n  padding: 0;\n  border: 1px solid rgba(255,255,255,0.12);\n  border-radius: 999px;\n  background: rgba(14,14,14,0.7);\n  -webkit-backdrop-filter: blur(6px);\n  backdrop-filter: blur(6px);\n  color: #ededed;\n  cursor: pointer;\n  transform: translateY(-50%);\n  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;\n}\n.hb-zx3-arrow:hover { background: rgba(30,30,30,0.85); border-color: rgba(255,255,255,0.22); }\n.hb-zx3-arrow:active { transform: translateY(-50%) scale(0.94); }\n.hb-zx3-arrow:focus-visible { outline: 2px solid var(--hb-zx3-l); outline-offset: 2px; }\n.hb-zx3-prev { left: 8px; }\n.hb-zx3-next { right: 8px; }\n.hb-zx3-bar {\n  position: relative;\n  z-index: 2;\n  flex: none;\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  gap: 12px;\n  padding: 7px 12px 9px;\n}\n.hb-zx3-text { min-width: 0; }\n.hb-zx3-title { margin: 0; font-size: 13px; font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; animation: hb-zx3-in 0.5s ease both; }\n.hb-zx3-cap { margin: 1px 0 0; font-size: 11px; color: #8f8f8f; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; animation: hb-zx3-in 0.5s 0.06s ease both; }\n.hb-zx3-dots { display: flex; gap: 5px; flex: none; }\n.hb-zx3-dot {\n  width: 5px;\n  height: 5px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 999px;\n  background: #3a3a3a;\n  cursor: pointer;\n  transition: width 0.3s ease, background-color 0.3s ease;\n}\n.hb-zx3-dot[data-on=\"true\"] { width: 16px; background: var(--hb-zx3-l); }\n.hb-zx3-dot:focus-visible { outline: 2px solid var(--hb-zx3-l); outline-offset: 2px; }\n@keyframes hb-zx3-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-zx3-card, .hb-zx3-glow, .hb-zx3-spill, .hb-zx3-beam, .hb-zx3-dot, .hb-zx3-arrow { transition: none; }\n  .hb-zx3-title, .hb-zx3-cap { animation: none; }\n}\n`;\n\nfunction place(d: number) {\n  const ad = Math.abs(d);\n  const sg = Math.sign(d);\n  const near = Math.min(ad, 1);\n  const far = Math.max(0, ad - 1);\n  return {\n    x: sg * (near * 0.82 + far * 0.4),\n    z: -(near * 0.75 + far * 0.3),\n    r: -sg * near * 56,\n    b: Math.max(0.12, 1 - near * 0.58 - far * 0.2),\n    o: Math.max(0, Math.min(1, 2.6 - ad)),\n  };\n}\n\nexport function GalleryCoverflowLights({\n  images,\n  index,\n  defaultIndex = 0,\n  onChange,\n  autoPlay = true,\n  interval = 3200,\n  glow = 1,\n  height,\n  className,\n  style,\n  onKeyDown,\n  onPointerEnter,\n  onPointerLeave,\n  onFocus,\n  onBlur,\n  ...rest\n}: GalleryCoverflowLightsProps) {\n  const list = images && images.length > 0 ? images : defaults;\n  const n = list.length;\n  const controlled = index !== undefined;\n  const [inner, setInner] = React.useState(() => mod(defaultIndex, n));\n  const active = mod(controlled ? index : inner, n);\n  const [drag, setDrag] = React.useState(0);\n  const [dragging, setDragging] = React.useState(false);\n  const [paused, setPaused] = React.useState(false);\n  const [unit, setUnit] = React.useState(100);\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const stageRef = React.useRef<HTMLDivElement>(null);\n  const dragRef = React.useRef<null | { id: number; startX: number; moved: boolean }>(null);\n  const reduced = useReducedMotion();\n  const visible = useInView(rootRef);\n  const [tick, setTick] = React.useState(0);\n\n  const go = React.useCallback(\n    (next: number) => {\n      const i = mod(next, n);\n      if (i === active) return;\n      if (!controlled) setInner(i);\n      onChange?.(i);\n    },\n    [active, controlled, n, onChange],\n  );\n\n  const nextRef = React.useRef(() => {});\n  React.useEffect(() => {\n    nextRef.current = () => go(active + 1);\n  });\n\n  React.useEffect(() => {\n    if (!autoPlay || reduced || !visible || paused || dragging || n < 2) return;\n    const id = window.setInterval(() => nextRef.current(), interval);\n    return () => window.clearInterval(id);\n  }, [autoPlay, reduced, visible, paused, dragging, interval, n, tick]);\n\n  React.useEffect(() => {\n    const el = stageRef.current;\n    if (!el || typeof ResizeObserver === \"undefined\") return;\n    const ro = new ResizeObserver(() => {\n      setUnit(Math.max(40, Math.min(el.clientWidth * 0.3, el.clientHeight * 0.62)));\n    });\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n\n  const step = (d: number) => {\n    go(active + d);\n    setTick((t) => t + 1);\n  };\n\n  const handleKey = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    onKeyDown?.(e);\n    if (e.defaultPrevented) return;\n    if (e.key === \"ArrowRight\") step(1);\n    else if (e.key === \"ArrowLeft\") step(-1);\n    else if (e.key === \"Home\") go(0);\n    else if (e.key === \"End\") go(n - 1);\n    else return;\n    e.preventDefault();\n  };\n\n  const down = (e: React.PointerEvent<HTMLDivElement>) => {\n    if (e.button !== 0) return;\n    dragRef.current = { id: e.pointerId, startX: e.clientX, moved: false };\n  };\n\n  const move = (e: React.PointerEvent<HTMLDivElement>) => {\n    const d = dragRef.current;\n    if (!d || d.id !== e.pointerId) return;\n    const dx = e.clientX - d.startX;\n    if (!d.moved && Math.abs(dx) > 5) {\n      d.moved = true;\n      e.currentTarget.setPointerCapture(e.pointerId);\n      setDragging(true);\n    }\n    if (d.moved) setDrag(-dx / (unit * 0.82));\n  };\n\n  const up = (e: React.PointerEvent<HTMLDivElement>) => {\n    const d = dragRef.current;\n    if (!d || d.id !== e.pointerId) return;\n    dragRef.current = null;\n    if (!d.moved) return;\n    const dx = e.clientX - d.startX;\n    let steps = Math.round(-dx / (unit * 0.82));\n    if (steps === 0 && Math.abs(dx) > 28) steps = dx < 0 ? 1 : -1;\n    setDragging(false);\n    setDrag(0);\n    if (steps !== 0) step(steps);\n  };\n\n  const pos = active + drag;\n  const light = lightOf(list, active);\n  const current = list[active];\n\n  return (\n    <div\n      ref={rootRef}\n      role=\"region\"\n      aria-roledescription=\"carousel\"\n      aria-label=\"Cover flow gallery\"\n      tabIndex={0}\n      className={className ? `hb-zx3 ${className}` : \"hb-zx3\"}\n      data-drag={dragging}\n      style={{\n        ...(height !== undefined ? { height } : { aspectRatio: \"16 / 10\" }),\n        [\"--hb-zx3-l\" as string]: light,\n        [\"--hb-zx3-g\" as string]: String(glow),\n        ...style,\n      }}\n      onKeyDown={handleKey}\n      onPointerEnter={(e) => {\n        setPaused(true);\n        onPointerEnter?.(e);\n      }}\n      onPointerLeave={(e) => {\n        setPaused(false);\n        onPointerLeave?.(e);\n      }}\n      onFocus={(e) => {\n        if (e.target.matches(\":focus-visible\")) setPaused(true);\n        onFocus?.(e);\n      }}\n      onBlur={(e) => {\n        if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setPaused(false);\n        onBlur?.(e);\n      }}\n      {...rest}\n    >\n      <style href=\"hb-gallery-coverflow-lights\" precedence=\"default\">\n        {css}\n      </style>\n      <div\n        ref={stageRef}\n        className=\"hb-zx3-stage\"\n        data-drag={dragging}\n        onPointerDown={down}\n        onPointerMove={move}\n        onPointerUp={up}\n        onPointerCancel={up}\n      >\n        <div className=\"hb-zx3-beam\" />\n        <div className=\"hb-zx3-glow\" />\n        <div className=\"hb-zx3-spill\" />\n        <div className=\"hb-zx3-world\">\n          {list.map((item, i) => {\n            let d = mod(i - pos + n / 2, n) - n / 2;\n            if (n === 1) d = 0;\n            const p = place(d);\n            const ad = Math.abs(d);\n            const on = i === active;\n            return (\n              <button\n                key={i}\n                type=\"button\"\n                className=\"hb-zx3-card\"\n                data-on={on}\n                tabIndex={-1}\n                aria-label={on ? item.title : `Show ${item.title}`}\n                aria-hidden={p.o === 0}\n                onClick={() => {\n                  if (!on) step(mod(i - active + n / 2, n) - n / 2 || 0);\n                }}\n                style={{\n                  backgroundImage: imageUrl(list, i),\n                  transform: `translate(-50%, -50%) translate3d(calc(var(--hb-zx3-c) * ${p.x.toFixed(3)}), 0, calc(var(--hb-zx3-c) * ${p.z.toFixed(3)})) rotateY(${p.r.toFixed(2)}deg)`,\n                  filter: `brightness(${p.b.toFixed(3)})`,\n                  opacity: Number(p.o.toFixed(3)),\n                  zIndex: 100 - Math.round(ad * 10),\n                  pointerEvents: p.o < 0.2 ? \"none\" : undefined,\n                  [\"--hb-zx3-od\" as string]: p.o === 0 ? \"0.12s\" : \"0.35s\",\n                  [\"--hb-zx3-dl\" as string]: p.o > 0 && ad >= 1.5 ? \"0.42s\" : \"0s\",\n                }}\n              >\n                <span className=\"hb-zx3-refl\" />\n              </button>\n            );\n          })}\n        </div>\n        {n > 1 ? (\n          <>\n            <button type=\"button\" className=\"hb-zx3-arrow hb-zx3-prev\" aria-label=\"Previous image\" onClick={() => step(-1)} onPointerDown={(e) => e.stopPropagation()}>\n              <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                <path d=\"M15 6l-6 6 6 6\" />\n              </svg>\n            </button>\n            <button type=\"button\" className=\"hb-zx3-arrow hb-zx3-next\" aria-label=\"Next image\" onClick={() => step(1)} onPointerDown={(e) => e.stopPropagation()}>\n              <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                <path d=\"M9 6l6 6-6 6\" />\n              </svg>\n            </button>\n          </>\n        ) : null}\n      </div>\n      <div className=\"hb-zx3-bar\">\n        <div className=\"hb-zx3-text\" key={active}>\n          <p className=\"hb-zx3-title\">{current?.title}</p>\n          {current?.caption ? <p className=\"hb-zx3-cap\">{current.caption}</p> : null}\n        </div>\n        <div className=\"hb-zx3-dots\">\n          {list.map((item, i) => (\n            <button\n              key={i}\n              type=\"button\"\n              className=\"hb-zx3-dot\"\n              data-on={i === active}\n              aria-label={`Go to ${item.title}`}\n              aria-current={i === active}\n              tabIndex={-1}\n              onClick={() => step(mod(i - active + n / 2, n) - n / 2 || 0)}\n            />\n          ))}\n        </div>\n      </div>\n    </div>\n  );\n}\n\nexport default GalleryCoverflowLights;\n"
    }
  ]
}