{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scroll-horizontal-track",
  "type": "registry:component",
  "title": "Scroll Horizontal Track",
  "description": "A pinned section where vertical scrolling slides a strip of cards sideways, with a progress rail and a card counter.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "motion",
    "scroll",
    "horizontal",
    "pinned",
    "cards",
    "carousel",
    "gallery"
  ],
  "docs": "https://hyperblur.dev/effects/scroll-horizontal-track",
  "files": [
    {
      "path": "registry/hyperblur/scroll-horizontal-track.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/scroll-horizontal-track.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ScrollTrackCard {\n  title: string;\n  text: string;\n  tag?: string;\n  from?: string;\n  to?: string;\n}\n\nexport interface ScrollHorizontalTrackProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\"> {\n  cards?: ScrollTrackCard[];\n  title?: string;\n  scroller?: React.RefObject<HTMLElement | null> | HTMLElement | null;\n  height?: number | string;\n  autoplay?: boolean;\n  accent?: string;\n}\n\ntype Scroller = React.RefObject<HTMLElement | null> | HTMLElement | null;\n\ninterface Frame {\n  sc: HTMLElement | null;\n  top: number;\n  vh: number;\n}\n\nconst defaultCards: ScrollTrackCard[] = [\n  { title: \"Lisbon\", text: \"Tram 28 at dawn and pastries on the hill.\", tag: \"Days 1-2\", from: \"#f6c177\", to: \"#c2410c\" },\n  { title: \"Porto\", text: \"Riverside cellars and the blue-tiled station.\", tag: \"Days 3-4\", from: \"#7dd3fc\", to: \"#1d4ed8\" },\n  { title: \"Salamanca\", text: \"Golden stone, quiet courtyards, late dinners.\", tag: \"Day 5\", from: \"#fde68a\", to: \"#b45309\" },\n  { title: \"Madrid\", text: \"Three museums, one long lunch, a night train.\", tag: \"Days 6-7\", from: \"#fda4af\", to: \"#9f1239\" },\n  { title: \"Valencia\", text: \"Orange groves and a beach that stays warm.\", tag: \"Days 8-9\", from: \"#86efac\", to: \"#0f766e\" },\n  { title: \"Barcelona\", text: \"Rooftops, markets and the last sunset.\", tag: \"Day 10\", from: \"#c4b5fd\", to: \"#6d28d9\" },\n];\n\nconst css = `\n.hb-qm6 {\n  --hb-qm6-a: #2f7bff;\n  --hb-qm6-p: 0;\n  --hb-qm6-u: 100vh;\n  --hb-qm6-travel: 0px;\n  position: relative;\n  width: 100%;\n  color: #ededed;\n  font-family: inherit;\n}\n.hb-qm6, .hb-qm6 * { box-sizing: border-box; }\n.hb-qm6-vp {\n  position: relative;\n  overflow-x: hidden;\n  overflow-y: auto;\n  overflow-anchor: none;\n  scrollbar-width: thin;\n  scrollbar-color: #2e2e2e transparent;\n  outline: none;\n}\n.hb-qm6-vp:focus-visible { outline: 2px solid var(--hb-qm6-a); outline-offset: -2px; }\n.hb-qm6-track {\n  position: relative;\n  width: 100%;\n  height: calc(var(--hb-qm6-u) + var(--hb-qm6-travel));\n}\n.hb-qm6-stage {\n  position: sticky;\n  top: 0;\n  display: flex;\n  flex-direction: column;\n  height: var(--hb-qm6-u);\n  overflow: hidden;\n  container-type: inline-size;\n  background: var(--hb-qm6-bg, #0a0a0a);\n}\n.hb-qm6-top {\n  display: flex;\n  flex: none;\n  align-items: baseline;\n  justify-content: space-between;\n  gap: 1em;\n  padding: 1.1em 1.3em 0.7em;\n}\n.hb-qm6-title {\n  margin: 0;\n  font-size: 1.05em;\n  font-weight: 600;\n  letter-spacing: -0.01em;\n  color: #f4f4f4;\n}\n.hb-qm6-hint {\n  display: inline-flex;\n  align-items: center;\n  gap: 0.4em;\n  font-size: 0.7em;\n  letter-spacing: 0.1em;\n  text-transform: uppercase;\n  color: #8f8f8f;\n}\n.hb-qm6-hint svg {\n  width: 1.4em;\n  height: 1.4em;\n  fill: none;\n  stroke: currentColor;\n  stroke-width: 1.8;\n  stroke-linecap: round;\n  stroke-linejoin: round;\n}\n.hb-qm6-view { display: flex; flex: 1; min-height: 0; align-items: stretch; }\n.hb-qm6-strip {\n  display: flex;\n  flex: none;\n  gap: 0.8em;\n  width: max-content;\n  padding: 0 1.3em;\n  transform: translate3d(calc(var(--hb-qm6-p) * var(--hb-qm6-travel) * -1), 0, 0);\n  will-change: transform;\n}\n.hb-qm6-card {\n  display: flex;\n  flex: none;\n  flex-direction: column;\n  width: clamp(9em, 62cqw, 19em);\n  overflow: hidden;\n  border: 1px solid #262626;\n  border-radius: 1em;\n  background: #111111;\n}\n.hb-qm6-art {\n  position: relative;\n  flex: 1;\n  min-height: 3em;\n  background: linear-gradient(145deg, var(--hb-qm6-f), var(--hb-qm6-s));\n}\n.hb-qm6-art::before {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  background: radial-gradient(80% 90% at 15% 0%, rgba(255, 255, 255, 0.32), transparent 65%),\n    linear-gradient(180deg, transparent 50%, rgba(0, 0, 0, 0.35));\n}\n.hb-qm6-tag {\n  position: absolute;\n  left: 0.7em;\n  top: 0.65em;\n  padding: 0.2em 0.6em;\n  border-radius: 999px;\n  background: rgba(10, 10, 10, 0.55);\n  font-size: 0.66em;\n  font-weight: 600;\n  letter-spacing: 0.04em;\n  color: #fff;\n  backdrop-filter: blur(6px);\n  -webkit-backdrop-filter: blur(6px);\n}\n.hb-qm6-body { flex: none; padding: 0.7em 0.9em 0.8em; }\n.hb-qm6-name {\n  margin: 0;\n  font-size: 1em;\n  font-weight: 600;\n  line-height: 1.2;\n  letter-spacing: -0.01em;\n  color: #f4f4f4;\n}\n.hb-qm6-text {\n  margin: 0.25em 0 0;\n  font-size: 0.78em;\n  line-height: 1.4;\n  color: #a1a1a1;\n}\n.hb-qm6-rail {\n  display: flex;\n  flex: none;\n  align-items: center;\n  gap: 0.9em;\n  padding: 0.8em 1.3em 1.1em;\n}\n.hb-qm6-count {\n  flex: none;\n  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;\n  font-size: 0.72em;\n  font-variant-numeric: tabular-nums;\n  letter-spacing: 0.04em;\n  color: #a1a1a1;\n}\n.hb-qm6-line {\n  position: relative;\n  flex: 1;\n  height: 2px;\n  border-radius: 999px;\n  background: rgba(255, 255, 255, 0.09);\n}\n.hb-qm6-line::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  border-radius: inherit;\n  background: var(--hb-qm6-a);\n  transform: scaleX(var(--hb-qm6-p));\n  transform-origin: left center;\n}\n.hb-qm6-tick {\n  position: absolute;\n  top: 50%;\n  width: 6px;\n  height: 6px;\n  margin: -3px 0 0 -3px;\n  border-radius: 999px;\n  background: #2a2a2a;\n  transition: background-color 0.25s ease;\n}\n.hb-qm6-tick[data-on=\"true\"] { background: var(--hb-qm6-a); }\n@media (prefers-reduced-motion: reduce) {\n  .hb-qm6-strip { will-change: auto; }\n  .hb-qm6-tick { transition: none; }\n}\n`;\n\nfunction clamp(n: number) {\n  return Math.min(1, Math.max(0, n));\n}\n\nfunction pick(scroller: Scroller | undefined): HTMLElement | null {\n  if (!scroller) return null;\n  return \"current\" in scroller ? scroller.current : scroller;\n}\n\nfunction useScrollFrame(\n  rootRef: React.RefObject<HTMLElement | null>,\n  viewportRef: React.RefObject<HTMLElement | null>,\n  scroller: Scroller | undefined,\n  own: boolean,\n  unit: string,\n  onFrame: (frame: Frame) => void,\n) {\n  const latest = React.useRef(onFrame);\n\n  React.useEffect(() => {\n    latest.current = onFrame;\n  });\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    if (!root) return;\n    const sc = own ? viewportRef.current : pick(scroller);\n    const host: HTMLElement | Window = sc ?? window;\n    const run = () => {\n      const top = sc ? sc.getBoundingClientRect().top : 0;\n      const vh = sc ? sc.clientHeight : window.innerHeight;\n      if (sc && !own) root.style.setProperty(unit, `${vh}px`);\n      latest.current({ sc, top, vh });\n    };\n    host.addEventListener(\"scroll\", run, { passive: true });\n    window.addEventListener(\"resize\", run);\n    const ro = new ResizeObserver(run);\n    ro.observe(root);\n    if (sc) ro.observe(sc);\n    return () => {\n      host.removeEventListener(\"scroll\", run);\n      window.removeEventListener(\"resize\", run);\n      ro.disconnect();\n    };\n  }, [rootRef, viewportRef, scroller, own, unit]);\n}\n\nfunction useAutoScroll(viewportRef: React.RefObject<HTMLElement | null>, active: boolean) {\n  React.useEffect(() => {\n    const el = viewportRef.current;\n    if (!el || !active) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) {\n      el.scrollTop = (el.scrollHeight - el.clientHeight) * 0.45;\n      return;\n    }\n    let raf = 0;\n    let last = 0;\n    let pos = 0;\n    let dir = 1;\n    let hold = 700;\n    let idle = 0;\n    const touch = () => {\n      idle = performance.now() + 3200;\n    };\n    const tick = (now: number) => {\n      raf = requestAnimationFrame(tick);\n      const dt = Math.min(now - last, 50);\n      last = now;\n      const max = el.scrollHeight - el.clientHeight;\n      if (max <= 0) return;\n      if (now < idle) {\n        pos = el.scrollTop / max;\n        return;\n      }\n      if (hold > 0) {\n        hold -= dt;\n        return;\n      }\n      pos += (dir * dt) / 9000;\n      if (pos >= 1) {\n        pos = 1;\n        dir = -1;\n        hold = 900;\n      } else if (pos <= 0) {\n        pos = 0;\n        dir = 1;\n        hold = 900;\n      }\n      el.scrollTop = pos * max;\n    };\n    const io = new IntersectionObserver(([entry]) => {\n      if (entry.isIntersecting) {\n        if (!raf) {\n          last = performance.now();\n          raf = requestAnimationFrame(tick);\n        }\n      } else {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n    });\n    io.observe(el);\n    const events = [\"wheel\", \"touchstart\", \"pointerdown\", \"keydown\"] as const;\n    for (const name of events) el.addEventListener(name, touch, { passive: true });\n    return () => {\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      for (const name of events) el.removeEventListener(name, touch);\n    };\n  }, [viewportRef, active]);\n}\n\nexport function ScrollHorizontalTrack({\n  cards = defaultCards,\n  title = \"Ten days by rail\",\n  scroller,\n  height,\n  autoplay = false,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: ScrollHorizontalTrackProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const viewportRef = React.useRef<HTMLDivElement>(null);\n  const trackRef = React.useRef<HTMLDivElement>(null);\n  const stageRef = React.useRef<HTMLDivElement>(null);\n  const stripRef = React.useRef<HTMLDivElement>(null);\n  const [index, setIndex] = React.useState(0);\n  const own = height !== undefined;\n  const n = Math.max(1, cards.length);\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const stage = stageRef.current;\n    const strip = stripRef.current;\n    if (!root || !stage || !strip) return;\n    const measure = () => {\n      const travel = Math.max(0, strip.scrollWidth - stage.clientWidth);\n      root.style.setProperty(\"--hb-qm6-travel\", `${travel}px`);\n    };\n    const ro = new ResizeObserver(measure);\n    ro.observe(stage);\n    ro.observe(strip);\n    return () => ro.disconnect();\n  }, [cards.length]);\n\n  useAutoScroll(viewportRef, own && autoplay);\n  useScrollFrame(rootRef, viewportRef, scroller, own, \"--hb-qm6-u\", ({ top, vh }) => {\n    const track = trackRef.current;\n    if (!track) return;\n    const rect = track.getBoundingClientRect();\n    const span = rect.height - vh;\n    const p = span > 0 ? clamp((top - rect.top) / span) : 0;\n    rootRef.current?.style.setProperty(\"--hb-qm6-p\", p.toFixed(4));\n    setIndex(Math.round(p * (n - 1)));\n  });\n\n  const pad = (v: number) => String(v).padStart(2, \"0\");\n\n  const body = (\n    <div ref={trackRef} className=\"hb-qm6-track\">\n      <div ref={stageRef} className=\"hb-qm6-stage\">\n        <div className=\"hb-qm6-top\">\n          <h3 className=\"hb-qm6-title\">{title}</h3>\n          <span className=\"hb-qm6-hint\" aria-hidden=\"true\">\n            Scroll\n            <svg viewBox=\"0 0 24 24\">\n              <path d=\"M4 12h16M14 6l6 6-6 6\" />\n            </svg>\n          </span>\n        </div>\n        <div className=\"hb-qm6-view\">\n          <div ref={stripRef} className=\"hb-qm6-strip\">\n            {cards.map((card, i) => (\n              <article\n                key={i}\n                className=\"hb-qm6-card\"\n                aria-label={`${i + 1} of ${n}: ${card.title}`}\n              >\n                <div\n                  className=\"hb-qm6-art\"\n                  style={\n                    {\n                      \"--hb-qm6-f\": card.from ?? \"#7fb3ff\",\n                      \"--hb-qm6-s\": card.to ?? \"#1d3a8a\",\n                    } as React.CSSProperties\n                  }\n                >\n                  {card.tag ? <span className=\"hb-qm6-tag\">{card.tag}</span> : null}\n                </div>\n                <div className=\"hb-qm6-body\">\n                  <h4 className=\"hb-qm6-name\">{card.title}</h4>\n                  <p className=\"hb-qm6-text\">{card.text}</p>\n                </div>\n              </article>\n            ))}\n          </div>\n        </div>\n        <div className=\"hb-qm6-rail\" aria-hidden=\"true\">\n          <span className=\"hb-qm6-count\">\n            {pad(index + 1)} / {pad(n)}\n          </span>\n          <div className=\"hb-qm6-line\">\n            {cards.map((_, i) => (\n              <span\n                key={i}\n                className=\"hb-qm6-tick\"\n                data-on={i <= index}\n                style={{ left: `${n > 1 ? ((i / (n - 1)) * 100).toFixed(2) : \"0\"}%` }}\n              />\n            ))}\n          </div>\n        </div>\n      </div>\n    </div>\n  );\n\n  return (\n    <div\n      ref={rootRef}\n      className={`hb-qm6 ${className}`.trim()}\n      style={\n        {\n          \"--hb-qm6-a\": accent,\n          ...(own ? { \"--hb-qm6-u\": typeof height === \"number\" ? `${height}px` : height } : null),\n          ...style,\n        } as React.CSSProperties\n      }\n      {...rest}\n    >\n      <style href=\"hb-scroll-horizontal-track\" precedence=\"default\">\n        {css}\n      </style>\n      {own ? (\n        <div\n          ref={viewportRef}\n          className=\"hb-qm6-vp\"\n          style={{ height }}\n          tabIndex={0}\n          role=\"region\"\n          aria-label=\"Scrollable content\"\n        >\n          {body}\n        </div>\n      ) : (\n        body\n      )}\n    </div>\n  );\n}\n"
    }
  ]
}