{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hover-tilt-gallery",
  "type": "registry:component",
  "title": "Tilt Gallery",
  "description": "A strip of artworks hung in 3D space: every card turns to face the pointer like a sunflower, the closest one widens and steps forward, and the whole wall leans with a sliding sheen.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "hover",
    "gallery",
    "3d",
    "tilt",
    "perspective",
    "cards",
    "portfolio"
  ],
  "docs": "https://hyperblur.dev/effects/hover-tilt-gallery",
  "files": [
    {
      "path": "registry/hyperblur/hover-tilt-gallery.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/hover-tilt-gallery.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface HoverTiltGalleryItem {\n  title: string;\n  meta: string;\n  background: string;\n}\n\nexport interface HoverTiltGalleryProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onSelect\"> {\n  items?: HoverTiltGalleryItem[];\n  height?: number;\n  maxTilt?: number;\n  lift?: number;\n  autoPlay?: boolean;\n  accent?: string;\n  onSelect?: (index: number, item: HoverTiltGalleryItem) => void;\n}\n\nconst defaults: HoverTiltGalleryItem[] = [\n  { title: \"Dune Study\", meta: \"Oil · 2024\", background: \"radial-gradient(circle at 70% 26%, #fff1c9 0 9%, transparent 10%), linear-gradient(170deg, transparent 58%, #a8582c 59%), linear-gradient(190deg, transparent 66%, #7a3a1c 67%), linear-gradient(180deg, #f4b67a 0%, #e0805a 100%)\" },\n  { title: \"Harbor Blue\", meta: \"Print · 2023\", background: \"repeating-linear-gradient(0deg, rgba(255,255,255,.12) 0 2px, transparent 2px 10px), linear-gradient(180deg, transparent 55%, #0b2a4a 55%), linear-gradient(180deg, #8ec5ff 0%, #2f7bff 100%)\" },\n  { title: \"Moss Room\", meta: \"Photo · 2025\", background: \"radial-gradient(60% 40% at 50% 80%, #2c5a35 0%, transparent 70%), radial-gradient(circle at 30% 30%, #b9e08f 0 16%, transparent 17%), linear-gradient(180deg, #4d7d48 0%, #12261a 100%)\" },\n  { title: \"Neon Rain\", meta: \"Digital · 2025\", background: \"repeating-linear-gradient(100deg, transparent 0 9px, rgba(255,90,170,.35) 9px 10px), radial-gradient(70% 50% at 50% 100%, #ff4f9a 0%, transparent 70%), linear-gradient(180deg, #120a2a 0%, #36104a 100%)\" },\n  { title: \"Salt Flat\", meta: \"Photo · 2022\", background: \"linear-gradient(180deg, transparent 52%, #e8eef2 52%, #c3ccd4 100%), radial-gradient(circle at 50% 50%, #ffffff 0 7%, transparent 8%), linear-gradient(180deg, #9cb8d6 0%, #dbe6f0 100%)\" },\n];\n\nconst css = `\n.hb-wg7 { --hb-wg7-accent: #2f7bff; --hb-wg7-h: 132px; position: relative; box-sizing: border-box; width: 100%; perspective: 760px; font-family: inherit; color: #ededed; touch-action: pan-y; }\n.hb-wg7 *, .hb-wg7 *::before, .hb-wg7 *::after { box-sizing: border-box; }\n.hb-wg7-strip { display: flex; gap: 8px; height: var(--hb-wg7-h); transform-style: preserve-3d; will-change: transform; }\n.hb-wg7-card { appearance: none; border: 0; margin: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; position: relative; flex: 1 1 0; min-width: 0; height: 100%; border-radius: 12px; overflow: hidden; transform-style: preserve-3d; will-change: transform; outline: none; background: var(--hb-wg7-bg); box-shadow: inset 0 0 0 1px rgba(255,255,255,.08), 0 18px 28px -18px rgba(0,0,0,.95); transition: flex-grow .55s cubic-bezier(.2,.9,.25,1), box-shadow .35s ease, filter .35s ease; -webkit-tap-highlight-color: transparent; }\n.hb-wg7-card[data-hot=\"true\"] { flex-grow: 1.7; box-shadow: inset 0 0 0 1px rgba(255,255,255,.18), 0 26px 40px -18px rgba(0,0,0,.95); }\n.hb-wg7[data-active=\"true\"] .hb-wg7-card:not([data-hot=\"true\"]) { filter: brightness(.72) saturate(.85); }\n.hb-wg7-card:focus-visible { box-shadow: 0 0 0 2px #0a0a0a, 0 0 0 4px var(--hb-wg7-accent); }\n.hb-wg7-sheen { position: absolute; inset: 0; pointer-events: none; background: linear-gradient(105deg, transparent 30%, rgba(255,255,255,.28) 48%, transparent 62%); background-size: 260% 100%; background-position: var(--hb-wg7-sx, 50%) 0; mix-blend-mode: overlay; opacity: .9; }\n.hb-wg7-cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 22px 9px 8px; display: grid; gap: 1px; text-align: left; background: linear-gradient(180deg, transparent, rgba(0,0,0,.62)); transform: translateZ(18px); opacity: 0; translate: 0 6px; transition: opacity .35s ease, translate .45s cubic-bezier(.2,.9,.25,1); }\n.hb-wg7-card[data-hot=\"true\"] .hb-wg7-cap, .hb-wg7-card:focus-visible .hb-wg7-cap { opacity: 1; translate: 0 0; }\n.hb-wg7-t { font-size: 11.5px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n.hb-wg7-m { font-size: 9.5px; color: rgba(237,237,237,.72); white-space: nowrap; }\n.hb-wg7-floor { position: absolute; left: 6%; right: 6%; bottom: -14px; height: 14px; border-radius: 50%; background: radial-gradient(50% 50% at 50% 50%, rgba(0,0,0,.65), transparent); filter: blur(4px); pointer-events: none; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-wg7-strip, .hb-wg7-card { transform: none !important; transition: none; }\n  .hb-wg7-cap { transition: none; }\n}\n`;\n\nexport function HoverTiltGallery({\n  items = defaults,\n  height = 132,\n  maxTilt = 22,\n  lift = 34,\n  autoPlay = true,\n  accent = \"#2f7bff\",\n  onSelect,\n  className = \"\",\n  style,\n  ...rest\n}: HoverTiltGalleryProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const stripRef = React.useRef<HTMLDivElement>(null);\n  const cardRefs = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const n = items.length;\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const strip = stripRef.current;\n    if (!root || !strip) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const cards = cardRefs.current.slice(0, n).filter((c): c is HTMLButtonElement => !!c);\n    const st = cards.map(() => ({ r: 0, z: 0 }));\n    let px = 0;\n    let py = 0;\n    let inside = false;\n    let focusIdx = -1;\n    let cx = root.offsetWidth / 2;\n    let cy = 0;\n    let mix = 0;\n    let t = 0;\n    let raf = 0;\n    let last = performance.now();\n    let visible = true;\n    let hot = -1;\n    let sr = 0;\n    let sx = 0;\n\n    const setHot = (i: number) => {\n      if (i === hot) return;\n      if (hot >= 0 && cards[hot]) cards[hot].dataset.hot = \"false\";\n      hot = i;\n      if (i >= 0 && cards[i]) cards[i].dataset.hot = \"true\";\n      root.dataset.active = i >= 0 ? \"true\" : \"false\";\n    };\n\n    const frame = (now: number) => {\n      const dt = Math.min(0.05, (now - last) / 1000);\n      last = now;\n      t += dt;\n      const w = root.offsetWidth;\n      const h = root.offsetHeight;\n      const live = inside || focusIdx >= 0 || autoPlay;\n      mix += ((live ? 1 : 0) - mix) * (1 - Math.exp(-dt * 5));\n      let tx = w * (0.5 + 0.42 * Math.sin(t * 0.6));\n      let ty = h * 0.5;\n      if (focusIdx >= 0 && cards[focusIdx]) {\n        tx = cards[focusIdx].offsetLeft + cards[focusIdx].offsetWidth / 2;\n      } else if (inside) {\n        tx = px;\n        ty = py;\n      }\n      const k = 1 - Math.exp(-dt * (inside ? 12 : 4));\n      cx += (tx - cx) * k;\n      cy += (ty - cy) * k;\n      const nx = w ? (cx / w) * 2 - 1 : 0;\n      const ny = h ? (cy / h) * 2 - 1 : 0;\n      sr += (nx * 9 * mix - sr) * k;\n      sx += (ny * -5 * mix - sx) * k;\n      strip.style.transform = `rotateY(${sr.toFixed(2)}deg) rotateX(${sx.toFixed(2)}deg)`;\n      let best = -1;\n      let bestD = Infinity;\n      cards.forEach((c, i) => {\n        const center = c.offsetLeft + c.offsetWidth / 2;\n        const d = cx - center;\n        const ad = Math.abs(d);\n        if (ad < bestD) {\n          bestD = ad;\n          best = i;\n        }\n        const gr = Math.max(-1, Math.min(1, d / (w * 0.35))) * maxTilt * mix;\n        const prox = Math.max(0, 1 - ad / (w * 0.4)) * mix;\n        const s = st[i];\n        s.r += (gr - s.r) * k;\n        s.z += (prox * lift - s.z) * k;\n        c.style.transform = `translateZ(${s.z.toFixed(1)}px) rotateY(${s.r.toFixed(2)}deg)`;\n        c.style.setProperty(\"--hb-wg7-sx\", `${(50 - (d / (c.offsetWidth || 1)) * 30).toFixed(1)}%`);\n      });\n      setHot(live && mix > 0.4 ? best : -1);\n      raf = requestAnimationFrame(frame);\n    };\n    const start = () => {\n      if (raf || !visible || reduce) return;\n      last = performance.now();\n      raf = requestAnimationFrame(frame);\n    };\n    const stop = () => {\n      if (raf) cancelAnimationFrame(raf);\n      raf = 0;\n    };\n    const onMove = (e: PointerEvent) => {\n      const r = root.getBoundingClientRect();\n      const s = r.width ? root.offsetWidth / r.width : 1;\n      px = (e.clientX - r.left) * s;\n      py = (e.clientY - r.top) * s;\n      inside = true;\n      if (reduce) {\n        let best = -1;\n        cards.forEach((c, i) => {\n          if (px >= c.offsetLeft && px <= c.offsetLeft + c.offsetWidth) best = i;\n        });\n        setHot(best);\n      }\n    };\n    const onLeave = () => {\n      inside = false;\n      if (reduce) setHot(-1);\n    };\n    const onUp = (e: PointerEvent) => {\n      if (e.pointerType !== \"mouse\") window.setTimeout(onLeave, 1500);\n    };\n    const onFocusIn = (e: FocusEvent) => {\n      focusIdx = cards.indexOf(e.target as HTMLButtonElement);\n      if (reduce) setHot(focusIdx);\n    };\n    const onFocusOut = (e: FocusEvent) => {\n      if (!root.contains(e.relatedTarget as Node | null)) {\n        focusIdx = -1;\n        if (reduce) setHot(-1);\n      }\n    };\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerdown\", onMove);\n    root.addEventListener(\"pointerleave\", onLeave);\n    root.addEventListener(\"pointerup\", onUp);\n    root.addEventListener(\"focusin\", onFocusIn);\n    root.addEventListener(\"focusout\", onFocusOut);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible) start();\n      else stop();\n    });\n    io.observe(root);\n    start();\n    return () => {\n      stop();\n      io.disconnect();\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerdown\", onMove);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      root.removeEventListener(\"pointerup\", onUp);\n      root.removeEventListener(\"focusin\", onFocusIn);\n      root.removeEventListener(\"focusout\", onFocusOut);\n    };\n  }, [n, maxTilt, lift, autoPlay]);\n\n  const onKey = (e: React.KeyboardEvent<HTMLButtonElement>, i: number) => {\n    let next = -1;\n    if (e.key === \"ArrowRight\") next = (i + 1) % n;\n    if (e.key === \"ArrowLeft\") next = (i - 1 + n) % n;\n    if (next >= 0) {\n      e.preventDefault();\n      cardRefs.current[next]?.focus();\n    }\n  };\n\n  const vars = { \"--hb-wg7-accent\": accent, \"--hb-wg7-h\": `${height}px` } as React.CSSProperties;\n\n  return (\n    <div ref={rootRef} className={`hb-wg7 ${className}`} style={{ ...vars, ...style }} data-active=\"false\" {...rest}>\n      <style href=\"hb-hover-tilt-gallery\" precedence=\"default\">{css}</style>\n      <div ref={stripRef} className=\"hb-wg7-strip\" role=\"group\" aria-label=\"Gallery\">\n        {items.map((item, i) => (\n          <button\n            key={`${item.title}-${i}`}\n            ref={(el) => {\n              cardRefs.current[i] = el;\n            }}\n            type=\"button\"\n            className=\"hb-wg7-card\"\n            data-hot=\"false\"\n            aria-label={`${item.title}, ${item.meta}`}\n            onKeyDown={(e) => onKey(e, i)}\n            onClick={() => onSelect?.(i, item)}\n            style={{ \"--hb-wg7-bg\": item.background } as React.CSSProperties}\n          >\n            <span className=\"hb-wg7-sheen\" aria-hidden=\"true\" />\n            <span className=\"hb-wg7-cap\" aria-hidden=\"true\">\n              <span className=\"hb-wg7-t\">{item.title}</span>\n              <span className=\"hb-wg7-m\">{item.meta}</span>\n            </span>\n          </button>\n        ))}\n      </div>\n      <span className=\"hb-wg7-floor\" aria-hidden=\"true\" />\n    </div>\n  );\n}\n"
    }
  ]
}