{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hero-scroll-timeline",
  "type": "registry:component",
  "title": "Hero Scroll Timeline",
  "description": "A winding line draws itself down the right side as you scroll, lighting milestone nodes and their cards one by one. On the left a year and a running total count up in step.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "hero",
    "hero",
    "scroll",
    "timeline",
    "milestones",
    "counter",
    "story"
  ],
  "docs": "https://hyperblur.dev/effects/hero-scroll-timeline",
  "files": [
    {
      "path": "registry/hyperblur/hero-scroll-timeline.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/hero-scroll-timeline.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface HeroScrollTimelineLink {\n  label: string;\n  href: string;\n}\n\nexport interface HeroScrollTimelineMilestone {\n  year: number;\n  title: string;\n  text: string;\n  count: number;\n}\n\nexport interface HeroScrollTimelineProps extends Omit<React.HTMLAttributes<HTMLElement>, \"title\"> {\n  eyebrow?: string;\n  title?: string;\n  subtitle?: string;\n  countLabel?: string;\n  milestones?: HeroScrollTimelineMilestone[];\n  cta?: HeroScrollTimelineLink | null;\n  accent?: string;\n  progress?: number;\n  autoPlay?: boolean;\n  duration?: number;\n  length?: number;\n  height?: string;\n  headingAs?: \"h1\" | \"h2\";\n}\n\nconst defaultMilestones: HeroScrollTimelineMilestone[] = [\n  { year: 2019, title: \"First install\", text: \"Twelve panels on a garage in Fresno.\", count: 1 },\n  { year: 2020, title: \"Home batteries\", text: \"Every system ships with storage.\", count: 140 },\n  { year: 2022, title: \"1,000 homes\", text: \"Crews in four California counties.\", count: 1000 },\n  { year: 2023, title: \"Community solar\", text: \"Renters can finally join in.\", count: 6500 },\n  { year: 2025, title: \"Virtual power plant\", text: \"Homes sell power back at peak.\", count: 18000 },\n  { year: 2027, title: \"40,000 rooftops\", text: \"And 312 MW of clean capacity.\", count: 40000 },\n];\n\nconst W = 100;\nconst H = 140;\nconst SAMPLES = 160;\n\nconst curve = (() => {\n  const pts: { x: number; y: number; d: number }[] = [];\n  let total = 0;\n  for (let i = 0; i <= SAMPLES; i++) {\n    const t = i / SAMPLES;\n    const x = 50 + Math.sin(t * Math.PI * 2.5 - 0.4) * 30;\n    const y = 8 + t * (H - 16);\n    if (i > 0) {\n      const prev = pts[i - 1];\n      total += Math.hypot(x - prev.x, y - prev.y);\n    }\n    pts.push({ x, y, d: total });\n  }\n  const path = pts.map((pt, i) => `${i ? \"L\" : \"M\"}${pt.x.toFixed(2)} ${pt.y.toFixed(2)}`).join(\"\");\n  return { pts, total, path };\n})();\n\nfunction pointAt(f: number) {\n  const target = f * curve.total;\n  const pts = curve.pts;\n  for (let i = 1; i < pts.length; i++) {\n    if (pts[i].d >= target) {\n      const a = pts[i - 1];\n      const b = pts[i];\n      const k = b.d === a.d ? 0 : (target - a.d) / (b.d - a.d);\n      return { x: a.x + (b.x - a.x) * k, y: a.y + (b.y - a.y) * k };\n    }\n  }\n  return pts[pts.length - 1];\n}\n\nconst css = `\n.hb-va10 {\n  --hb-va10-accent: #fbbf24;\n  position: relative;\n  width: 100%;\n  height: var(--hb-va10-h);\n  color: #ededed;\n  font-family: inherit;\n  background: #0a0908;\n}\n.hb-va10[data-pinned=\"true\"] { height: calc(var(--hb-va10-h) * var(--hb-va10-len)); }\n.hb-va10 *, .hb-va10 *::before, .hb-va10 *::after { box-sizing: border-box; }\n.hb-va10-stage {\n  position: sticky;\n  top: 0;\n  display: grid;\n  grid-template-columns: minmax(0, 1fr) auto;\n  align-items: center;\n  gap: 3cqw;\n  height: var(--hb-va10-h);\n  padding: 0 6cqw;\n  overflow: hidden;\n  container-type: size;\n  background:\n    radial-gradient(40% 50% at 100% 0%, color-mix(in srgb, var(--hb-va10-accent) 16%, transparent), transparent 70%),\n    #0a0908;\n}\n.hb-va10-eyebrow {\n  display: inline-flex;\n  align-items: center;\n  gap: 0.6em;\n  font-size: clamp(11px, 1.2cqw, 13px);\n  font-weight: 500;\n  color: var(--hb-va10-accent);\n}\n.hb-va10-sun {\n  width: 1em;\n  height: 1em;\n  border-radius: 50%;\n  background: var(--hb-va10-accent);\n  box-shadow: 0 0 0 0.25em color-mix(in srgb, var(--hb-va10-accent) 25%, transparent), 0 0 16px var(--hb-va10-accent);\n}\n.hb-va10-title {\n  max-width: 12ch;\n  margin: 0.5em 0 0;\n  font-family: var(--font-grotesk, var(--font-sans, system-ui));\n  font-size: clamp(1.8rem, 5.2cqw, 4.8rem);\n  font-weight: 600;\n  line-height: 0.98;\n  letter-spacing: -0.045em;\n}\n.hb-va10-sub {\n  max-width: 38ch;\n  margin: 0.9em 0 0;\n  font-size: clamp(12px, 1.4cqw, 16px);\n  line-height: 1.55;\n  color: #a1a1a1;\n}\n.hb-va10-counters {\n  display: flex;\n  gap: 3cqw;\n  margin-top: 2em;\n  padding-top: 1.2em;\n  border-top: 1px solid #262626;\n}\n.hb-va10-counter small {\n  display: block;\n  margin-bottom: 0.35em;\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: clamp(9px, 1cqw, 11px);\n  letter-spacing: 0.16em;\n  text-transform: uppercase;\n  color: #6f6f6f;\n}\n.hb-va10-counter b {\n  display: block;\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: clamp(1.4rem, 3.6cqw, 3.2rem);\n  font-weight: 500;\n  letter-spacing: -0.04em;\n  font-variant-numeric: tabular-nums;\n}\n.hb-va10-counter:last-child b { color: var(--hb-va10-accent); }\n.hb-va10-cta {\n  display: inline-flex;\n  align-items: center;\n  gap: 0.5em;\n  margin-top: 1.6em;\n  padding: 0.7em 1.3em;\n  border-radius: 999px;\n  background: var(--hb-va10-accent);\n  color: #1f1400;\n  font-size: clamp(12px, 1.35cqw, 15px);\n  font-weight: 600;\n  text-decoration: none;\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 12px 30px -12px var(--hb-va10-accent);\n  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1), filter 0.3s ease;\n}\n.hb-va10-cta:hover { transform: translateY(-1px); filter: brightness(1.05); }\n.hb-va10-cta:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }\n.hb-va10-map {\n  position: relative;\n  height: 90cqh;\n  aspect-ratio: 100 / 140;\n}\n.hb-va10-map svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }\n.hb-va10-node {\n  position: absolute;\n  width: 1.6cqh;\n  height: 1.6cqh;\n  min-width: 10px;\n  min-height: 10px;\n  border-radius: 50%;\n  transform: translate(-50%, -50%) scale(0.7);\n  background: #0a0908;\n  border: 2px solid #3a3a3a;\n  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), border-color 0.4s ease, background 0.4s ease, box-shadow 0.4s ease;\n}\n.hb-va10-node[data-on=\"true\"] {\n  transform: translate(-50%, -50%) scale(1);\n  border-color: var(--hb-va10-accent);\n  background: var(--hb-va10-accent);\n  box-shadow: 0 0 0 0.5cqh color-mix(in srgb, var(--hb-va10-accent) 22%, transparent), 0 0 18px var(--hb-va10-accent);\n}\n.hb-va10-card {\n  position: absolute;\n  width: max-content;\n  max-width: 17cqw;\n  padding: 0.55em 0.75em;\n  border-radius: 0.6em;\n  border: 1px solid #262626;\n  background: linear-gradient(180deg, #161514, #111010);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 10px 24px -12px rgba(0, 0, 0, 0.8);\n  font-size: clamp(9px, 1.1cqw, 13px);\n  line-height: 1.35;\n  opacity: 0.18;\n  transform: translate(var(--hb-va10-tx), -50%) translateX(var(--hb-va10-dx));\n  transition: opacity 0.45s cubic-bezier(0.22, 1, 0.36, 1), transform 0.55s cubic-bezier(0.22, 1, 0.36, 1);\n}\n.hb-va10-card[data-side=\"r\"] { --hb-va10-tx: 1.6cqh; --hb-va10-dx: 10px; }\n.hb-va10-card[data-side=\"l\"] { --hb-va10-tx: calc(-100% - 1.6cqh); --hb-va10-dx: -10px; }\n.hb-va10-card[data-on=\"true\"] { opacity: 1; --hb-va10-dx: 0px; }\n.hb-va10-card small {\n  display: block;\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: 0.85em;\n  color: var(--hb-va10-accent);\n}\n.hb-va10-card b { display: block; margin-top: 0.1em; font-weight: 600; }\n.hb-va10-card span { display: block; color: #8f8f8f; }\n@media (max-width: 640px) {\n  .hb-va10-stage { grid-template-columns: 1fr; align-content: center; }\n  .hb-va10-map { display: none; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-va10-node, .hb-va10-card, .hb-va10-cta { transition: none; }\n}\n`;\n\nfunction findScroller(el: HTMLElement): HTMLElement | null {\n  let node = el.parentElement;\n  while (node && node !== document.body && node !== document.documentElement) {\n    const oy = getComputedStyle(node).overflowY;\n    if ((oy === \"auto\" || oy === \"scroll\" || oy === \"overlay\") && node.scrollHeight > node.clientHeight + 1) return node;\n    node = node.parentElement;\n  }\n  return null;\n}\n\nfunction ease(x: number) {\n  return x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;\n}\n\nfunction clamp01(x: number) {\n  return Math.min(1, Math.max(0, x));\n}\n\nfunction loopAt(ms: number, duration: number) {\n  const d = Math.max(1, duration) * 1000;\n  const back = d * 0.7;\n  const hold = 1400;\n  const t = ms % (d + hold + back + 700);\n  if (t < d) return ease(t / d);\n  if (t < d + hold) return 1;\n  if (t < d + hold + back) return 1 - ease((t - d - hold) / back);\n  return 0;\n}\n\nfunction useScrollProgress(\n  ref: React.RefObject<HTMLElement | null>,\n  apply: (p: number) => void,\n  progress: number | undefined,\n  autoPlay: boolean,\n  duration: number,\n) {\n  const applyRef = React.useRef(apply);\n  React.useLayoutEffect(() => {\n    applyRef.current = apply;\n  });\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const run = (p: number) => applyRef.current(clamp01(p));\n    if (typeof progress === \"number\") {\n      run(progress);\n      return;\n    }\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) {\n      run(1);\n      return;\n    }\n    let raf = 0;\n    if (autoPlay) {\n      let visible = true;\n      let last = 0;\n      let t = 0;\n      const io = new IntersectionObserver((entries) => {\n        visible = entries[0]?.isIntersecting ?? true;\n      });\n      io.observe(el);\n      const loop = (now: number) => {\n        const dt = last ? Math.min(64, now - last) : 0;\n        last = now;\n        if (visible) {\n          t += dt;\n          run(loopAt(t, duration));\n        }\n        raf = requestAnimationFrame(loop);\n      };\n      raf = requestAnimationFrame(loop);\n      return () => {\n        cancelAnimationFrame(raf);\n        io.disconnect();\n      };\n    }\n    const sc = findScroller(el);\n    const measure = () => {\n      raf = 0;\n      const r = el.getBoundingClientRect();\n      const top = sc ? r.top - sc.getBoundingClientRect().top : r.top;\n      const vh = sc ? sc.clientHeight : window.innerHeight;\n      const span = r.height - vh;\n      run(span > 1 ? -top / span : (vh - top) / (vh + r.height));\n    };\n    const onScroll = () => {\n      if (!raf) raf = requestAnimationFrame(measure);\n    };\n    measure();\n    const target: HTMLElement | Window = sc ?? window;\n    target.addEventListener(\"scroll\", onScroll, { passive: true });\n    window.addEventListener(\"resize\", onScroll);\n    return () => {\n      cancelAnimationFrame(raf);\n      target.removeEventListener(\"scroll\", onScroll);\n      window.removeEventListener(\"resize\", onScroll);\n    };\n  }, [ref, progress, autoPlay, duration]);\n}\n\nexport function HeroScrollTimeline({\n  eyebrow = \"Helio Energy · since 2019\",\n  title = \"From one rooftop to forty thousand\",\n  subtitle = \"Solar and storage for homes, installed by our own crews and monitored for the life of the system.\",\n  countLabel = \"Homes powered\",\n  milestones = defaultMilestones,\n  cta = { label: \"Get a free roof estimate\", href: \"#\" },\n  accent = \"#fbbf24\",\n  progress,\n  autoPlay = false,\n  duration = 6,\n  length = 4,\n  height = \"100vh\",\n  headingAs = \"h1\",\n  className,\n  style,\n  ...rest\n}: HeroScrollTimelineProps) {\n  const ref = React.useRef<HTMLElement>(null);\n  const pathRef = React.useRef<SVGPathElement>(null);\n  const yearRef = React.useRef<HTMLElement>(null);\n  const countRef = React.useRef<HTMLElement>(null);\n  const nodes = React.useRef<(HTMLSpanElement | null)[]>([]);\n  const cards = React.useRef<(HTMLDivElement | null)[]>([]);\n  const Heading = headingAs;\n  const pinned = progress === undefined && !autoPlay;\n  const m = milestones.length;\n  const marks = React.useMemo(\n    () => milestones.map((_, k) => ({ f: m > 1 ? 0.04 + (k / (m - 1)) * 0.92 : 0.5, ...pointAt(m > 1 ? 0.04 + (k / (m - 1)) * 0.92 : 0.5) })),\n    [milestones, m],\n  );\n  const first = milestones[0];\n\n  useScrollProgress(\n    ref,\n    (p) => {\n      const d = clamp01(p / 0.92);\n      if (pathRef.current) pathRef.current.style.strokeDashoffset = (1 - d).toFixed(4);\n      let reached = -1;\n      marks.forEach((mk, k) => {\n        const on = d >= mk.f - 0.005;\n        if (on) reached = k;\n        const v = on ? \"true\" : \"false\";\n        const nd = nodes.current[k];\n        const cd = cards.current[k];\n        if (nd && nd.dataset.on !== v) nd.dataset.on = v;\n        if (cd && cd.dataset.on !== v) cd.dataset.on = v;\n      });\n      if (!m) return;\n      let year = milestones[0].year;\n      let count = milestones[0].count;\n      if (reached >= 0 && reached < m - 1) {\n        const a = marks[reached];\n        const b = marks[reached + 1];\n        const k = clamp01((d - a.f) / (b.f - a.f));\n        year = Math.floor(milestones[reached].year + (milestones[reached + 1].year - milestones[reached].year) * k);\n        count = Math.round(milestones[reached].count + (milestones[reached + 1].count - milestones[reached].count) * ease(k));\n      } else if (reached === m - 1) {\n        year = milestones[m - 1].year;\n        count = milestones[m - 1].count;\n      }\n      if (yearRef.current) yearRef.current.textContent = String(year);\n      if (countRef.current) countRef.current.textContent = count.toLocaleString(\"en-US\");\n    },\n    progress,\n    autoPlay,\n    duration,\n  );\n\n  return (\n    <section\n      ref={ref}\n      className={[\"hb-va10\", className].filter(Boolean).join(\" \")}\n      data-pinned={pinned ? \"true\" : \"false\"}\n      style={{ \"--hb-va10-accent\": accent, \"--hb-va10-h\": height, \"--hb-va10-len\": length, ...style } as React.CSSProperties}\n      {...rest}\n    >\n      <style href=\"hb-hero-scroll-timeline\" precedence=\"default\">{css}</style>\n      <div className=\"hb-va10-stage\">\n        <div>\n          <span className=\"hb-va10-eyebrow\">\n            <span className=\"hb-va10-sun\" aria-hidden=\"true\" />\n            {eyebrow}\n          </span>\n          <Heading className=\"hb-va10-title\">{title}</Heading>\n          {subtitle ? <p className=\"hb-va10-sub\">{subtitle}</p> : null}\n          <div className=\"hb-va10-counters\" aria-hidden=\"true\">\n            <div className=\"hb-va10-counter\">\n              <small>Year</small>\n              <b ref={yearRef}>{first ? first.year : \"\"}</b>\n            </div>\n            <div className=\"hb-va10-counter\">\n              <small>{countLabel}</small>\n              <b ref={countRef}>{first ? first.count.toLocaleString(\"en-US\") : \"\"}</b>\n            </div>\n          </div>\n          {cta ? (\n            <a className=\"hb-va10-cta\" href={cta.href}>\n              {cta.label}\n            </a>\n          ) : null}\n        </div>\n        <div className=\"hb-va10-map\">\n          <svg viewBox={`0 0 ${W} ${H}`} aria-hidden=\"true\">\n            <path d={curve.path} fill=\"none\" stroke=\"#262626\" strokeWidth=\"0.8\" strokeDasharray=\"1.2 1.6\" />\n            <path\n              ref={pathRef}\n              d={curve.path}\n              fill=\"none\"\n              stroke={accent}\n              strokeWidth=\"1.1\"\n              strokeLinecap=\"round\"\n              pathLength={1}\n              strokeDasharray=\"1 1\"\n              strokeDashoffset=\"1\"\n              style={{ filter: `drop-shadow(0 0 3px ${accent})` }}\n            />\n          </svg>\n          <ol style={{ margin: 0, padding: 0, listStyle: \"none\" }}>\n            {milestones.map((ms, k) => {\n              const mk = marks[k];\n              const left = `${((mk.x / W) * 100).toFixed(2)}%`;\n              const top = `${((mk.y / H) * 100).toFixed(2)}%`;\n              return (\n                <li key={ms.year + ms.title}>\n                  <span\n                    className=\"hb-va10-node\"\n                    style={{ left, top }}\n                    ref={(node) => {\n                      nodes.current[k] = node;\n                    }}\n                  />\n                  <div\n                    className=\"hb-va10-card\"\n                    data-side={mk.x < 50 ? \"r\" : \"l\"}\n                    style={{ left, top }}\n                    ref={(node) => {\n                      cards.current[k] = node;\n                    }}\n                  >\n                    <small>{ms.year}</small>\n                    <b>{ms.title}</b>\n                    <span>{ms.text}</span>\n                  </div>\n                </li>\n              );\n            })}\n          </ol>\n        </div>\n      </div>\n    </section>\n  );\n}\n"
    }
  ]
}