{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "motion-stat-sequence",
  "type": "registry:component",
  "title": "Motion Stat Sequence",
  "description": "A pinned report section where three numbers take turns: each one counts up while its rule draws and a delta chip pops in, then dims as the next takes over. A rail on the left tracks the whole sequence.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "motion",
    "scroll",
    "stats",
    "counter",
    "numbers",
    "pinned",
    "report"
  ],
  "docs": "https://hyperblur.dev/effects/motion-stat-sequence",
  "files": [
    {
      "path": "registry/hyperblur/motion-stat-sequence.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/motion-stat-sequence.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface MotionStatSequenceStat {\n  value: number;\n  label: string;\n  prefix?: string;\n  suffix?: string;\n  decimals?: number;\n  delta?: string;\n}\n\nexport interface MotionStatSequenceProps extends Omit<React.HTMLAttributes<HTMLElement>, \"title\"> {\n  eyebrow?: string;\n  title?: string;\n  stats?: MotionStatSequenceStat[];\n  accent?: string;\n  progress?: number;\n  autoPlay?: boolean;\n  duration?: number;\n  length?: number;\n  height?: string;\n}\n\nconst defaultStats: MotionStatSequenceStat[] = [\n  { value: 2.4, decimals: 1, suffix: \"B\", label: \"Requests served last quarter\", delta: \"+38% QoQ\" },\n  { value: 99.995, decimals: 3, suffix: \"%\", label: \"Edge uptime across 41 regions\", delta: \"4 min downtime\" },\n  { value: 186, prefix: \"\", suffix: \"ms\", label: \"Median cold start, worldwide\", delta: \"-62ms since May\" },\n];\n\nconst css = `\n.hb-wh1 {\n  --hb-wh1-a: #2f7bff;\n  position: relative;\n  width: 100%;\n  height: var(--hb-wh1-h);\n  color: #ededed;\n  font-family: inherit;\n  background: #0a0a0a;\n}\n.hb-wh1[data-pinned=\"true\"] { height: calc(var(--hb-wh1-h) * var(--hb-wh1-len)); }\n.hb-wh1 *, .hb-wh1 *::before, .hb-wh1 *::after { box-sizing: border-box; }\n.hb-wh1-stage {\n  position: sticky;\n  top: 0;\n  height: var(--hb-wh1-h);\n  overflow: hidden;\n  container-type: size;\n  display: grid;\n  grid-template-columns: 1fr;\n  align-content: center;\n  gap: 4cqh;\n  padding: 7cqh max(16px, 6cqw);\n  background:\n    radial-gradient(60% 80% at 100% 0%, color-mix(in srgb, var(--hb-wh1-a) 10%, transparent), transparent 70%),\n    linear-gradient(180deg, #0c0c0c, #0a0a0a);\n}\n.hb-wh1-title, .hb-wh1-meter { display: none; }\n.hb-wh1-eyebrow {\n  display: flex;\n  align-items: center;\n  gap: 0.6em;\n  margin: 0;\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: clamp(8px, 2.2cqh, 12px);\n  letter-spacing: 0.16em;\n  text-transform: uppercase;\n  color: #8f8f8f;\n}\n.hb-wh1-eyebrow::before {\n  content: \"\";\n  width: 0.55em;\n  height: 0.55em;\n  border-radius: 50%;\n  background: var(--hb-wh1-a);\n  box-shadow: 0 0 0 3px color-mix(in srgb, var(--hb-wh1-a) 22%, transparent);\n}\n.hb-wh1-title {\n  margin: 0.7em 0 0;\n  max-width: 13ch;\n  font-family: var(--font-grotesk, var(--font-sans, system-ui));\n  font-size: clamp(22px, 6.4cqh, 60px);\n  font-weight: 600;\n  line-height: 1.02;\n  letter-spacing: -0.035em;\n  color: #f5f5f5;\n}\n.hb-wh1-meter {\n  display: flex;\n  align-items: center;\n  gap: 0.8em;\n  margin-top: 2.2em;\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: clamp(9px, 1.8cqh, 12px);\n  color: #6f6f6f;\n  font-variant-numeric: tabular-nums;\n}\n.hb-wh1-meter i {\n  position: relative;\n  flex: 0 0 9em;\n  height: 2px;\n  border-radius: 2px;\n  background: #222;\n  overflow: hidden;\n}\n.hb-wh1-meter i::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  background: var(--hb-wh1-a);\n  transform-origin: left;\n  transform: scaleX(var(--hb-wh1-p, 0));\n}\n.hb-wh1-list {\n  position: relative;\n  margin: 0;\n  padding: 0 0 0 clamp(14px, 4cqw, 34px);\n  list-style: none;\n  display: grid;\n  gap: clamp(4px, 2.4cqh, 26px);\n}\n.hb-wh1-list::before {\n  content: \"\";\n  position: absolute;\n  left: 0;\n  top: 0.4em;\n  bottom: 0.4em;\n  width: 1px;\n  background: #242424;\n}\n.hb-wh1-list::after {\n  content: \"\";\n  position: absolute;\n  left: -0.5px;\n  top: 0.4em;\n  bottom: 0.4em;\n  width: 2px;\n  background: linear-gradient(180deg, var(--hb-wh1-a), color-mix(in srgb, var(--hb-wh1-a) 50%, #fff));\n  transform-origin: top;\n  transform: scaleY(var(--hb-wh1-p, 0));\n  box-shadow: 0 0 10px var(--hb-wh1-a);\n}\n.hb-wh1-row {\n  position: relative;\n  display: grid;\n  grid-template-columns: auto 1fr;\n  align-items: baseline;\n  column-gap: clamp(8px, 2.4cqw, 22px);\n  opacity: calc(0.22 + var(--hb-wh1-on) * 0.78);\n  transform: translateX(calc((1 - var(--hb-wh1-on)) * 10px));\n  transition: opacity 0.5s cubic-bezier(0.22, 1, 0.36, 1), transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);\n}\n.hb-wh1-row[data-state=\"done\"] { opacity: 0.62; }\n.hb-wh1-dot {\n  position: absolute;\n  left: calc(clamp(14px, 4cqw, 34px) * -1 - 4px);\n  top: 50%;\n  width: 9px;\n  height: 9px;\n  border-radius: 50%;\n  border: 1px solid #3a3a3a;\n  background: #0a0a0a;\n  transform: translateY(-50%) scale(calc(0.7 + var(--hb-wh1-on) * 0.3));\n  transition: border-color 0.4s ease, background 0.4s ease;\n}\n.hb-wh1-row[data-state=\"active\"] .hb-wh1-dot,\n.hb-wh1-row[data-state=\"done\"] .hb-wh1-dot {\n  border-color: var(--hb-wh1-a);\n  background: var(--hb-wh1-a);\n  box-shadow: 0 0 0 4px color-mix(in srgb, var(--hb-wh1-a) 20%, transparent);\n}\n.hb-wh1-num {\n  grid-row: span 2;\n  min-width: 4.6ch;\n  font-family: var(--font-grotesk, var(--font-sans, system-ui));\n  font-size: clamp(24px, 13cqh, 92px);\n  font-weight: 600;\n  line-height: 1;\n  letter-spacing: -0.04em;\n  font-variant-numeric: tabular-nums;\n  color: #f6f6f6;\n}\n.hb-wh1-unit { color: color-mix(in srgb, var(--hb-wh1-a) 55%, #fff); font-size: 0.62em; letter-spacing: -0.02em; margin-left: 0.04em; }\n.hb-wh1-label {\n  align-self: end;\n  font-size: clamp(9px, 2.5cqh, 16px);\n  line-height: 1.3;\n  color: #a1a1a1;\n}\n.hb-wh1-foot {\n  display: flex;\n  align-items: center;\n  gap: 0.6em;\n  align-self: start;\n  margin-top: 0.35em;\n}\n.hb-wh1-bar {\n  position: relative;\n  width: clamp(36px, 14cqw, 140px);\n  height: 2px;\n  border-radius: 2px;\n  background: #1f1f1f;\n  overflow: hidden;\n}\n.hb-wh1-bar::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  background: var(--hb-wh1-a);\n  transform-origin: left;\n  transform: scaleX(var(--hb-wh1-t));\n}\n.hb-wh1-delta {\n  padding: 0.18em 0.55em;\n  border-radius: 999px;\n  border: 1px solid color-mix(in srgb, var(--hb-wh1-a) 40%, transparent);\n  background: color-mix(in srgb, var(--hb-wh1-a) 12%, transparent);\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: clamp(7px, 1.8cqh, 11px);\n  white-space: nowrap;\n  color: color-mix(in srgb, var(--hb-wh1-a) 45%, #fff);\n  opacity: 0;\n  transform: translateY(4px) scale(0.92);\n  transition: opacity 0.35s ease, transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);\n}\n.hb-wh1-row[data-state=\"done\"] .hb-wh1-delta,\n.hb-wh1-row[data-full=\"true\"] .hb-wh1-delta { opacity: 1; transform: none; }\n.hb-wh1-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n}\n@container (min-width: 620px) {\n  .hb-wh1-stage { grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); align-items: center; column-gap: 6cqw; }\n  .hb-wh1-title { display: block; }\n  .hb-wh1-meter { display: flex; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-wh1-row, .hb-wh1-dot, .hb-wh1-delta { transition: none; }\n}\n`;\n\nfunction clamp01(x: number) {\n  return Math.min(1, Math.max(0, x));\n}\n\nfunction ease(x: number) {\n  return 1 - Math.pow(1 - x, 3);\n}\n\nfunction inOut(x: number) {\n  return x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;\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 loopAt(ms: number, duration: number) {\n  const d = Math.max(1, duration) * 1000;\n  const back = d * 0.45;\n  const hold = 1600;\n  const t = ms % (d + hold + back + 600);\n  if (t < d) return t / d;\n  if (t < d + hold) return 1;\n  if (t < d + hold + back) return 1 - inOut((t - d - hold) / back);\n  return 0;\n}\n\nfunction useProgress(\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\nfunction format(v: number, decimals: number) {\n  return v.toLocaleString(\"en-US\", { minimumFractionDigits: decimals, maximumFractionDigits: decimals });\n}\n\nexport function MotionStatSequence({\n  eyebrow = \"Platform report · Q3\",\n  title = \"A quarter on the network, in three numbers\",\n  stats = defaultStats,\n  accent = \"#2f7bff\",\n  progress,\n  autoPlay = false,\n  duration = 6,\n  length = 3,\n  height = \"100vh\",\n  className,\n  style,\n  ...rest\n}: MotionStatSequenceProps) {\n  const ref = React.useRef<HTMLElement>(null);\n  const [p, setP] = React.useState(typeof progress === \"number\" ? clamp01(progress) : 0);\n  const pinned = progress === undefined && !autoPlay;\n  const n = Math.max(1, stats.length);\n\n  useProgress(\n    ref,\n    (v) => {\n      const q = Math.round(v * 2000) / 2000;\n      ref.current?.style.setProperty(\"--hb-wh1-p\", q.toFixed(4));\n      setP((old) => (old === q ? old : q));\n    },\n    progress,\n    autoPlay,\n    duration,\n  );\n\n  const s = clamp01(p / 0.92) * n;\n\n  return (\n    <section\n      ref={ref}\n      className={[\"hb-wh1\", className].filter(Boolean).join(\" \")}\n      data-pinned={pinned ? \"true\" : \"false\"}\n      style={\n        {\n          \"--hb-wh1-a\": accent,\n          \"--hb-wh1-h\": height,\n          \"--hb-wh1-len\": length,\n          ...style,\n        } as React.CSSProperties\n      }\n      {...rest}\n    >\n      <style href=\"hb-motion-stat-sequence\" precedence=\"default\">{css}</style>\n      <div className=\"hb-wh1-stage\">\n        <div className=\"hb-wh1-intro\">\n          <p className=\"hb-wh1-eyebrow\">{eyebrow}</p>\n          <h2 className=\"hb-wh1-title\">{title}</h2>\n          <div className=\"hb-wh1-meter\" aria-hidden=\"true\">\n            <span>{String(Math.min(n, Math.floor(s) + 1)).padStart(2, \"0\")}</span>\n            <i />\n            <span>{String(n).padStart(2, \"0\")}</span>\n          </div>\n        </div>\n        <ol className=\"hb-wh1-list\">\n          {stats.map((stat, i) => {\n            const local = clamp01(s - i);\n            const t = ease(clamp01(local / 0.8));\n            const state = local >= 1 ? \"done\" : local > 0 ? \"active\" : \"idle\";\n            const on = state === \"idle\" ? 0 : 1;\n            const decimals = stat.decimals ?? 0;\n            return (\n              <li\n                key={stat.label}\n                className=\"hb-wh1-row\"\n                data-state={state}\n                data-full={t >= 0.999 ? \"true\" : \"false\"}\n                style={{ \"--hb-wh1-on\": on, \"--hb-wh1-t\": t.toFixed(4) } as React.CSSProperties}\n              >\n                <span className=\"hb-wh1-dot\" aria-hidden=\"true\" />\n                <span className=\"hb-wh1-num\" aria-hidden=\"true\">\n                  {stat.prefix ? <span className=\"hb-wh1-unit\">{stat.prefix}</span> : null}\n                  {format(stat.value * t, decimals)}\n                  {stat.suffix ? <span className=\"hb-wh1-unit\">{stat.suffix}</span> : null}\n                </span>\n                <span className=\"hb-wh1-sr\">\n                  {stat.prefix}\n                  {format(stat.value, decimals)}\n                  {stat.suffix}\n                </span>\n                <span className=\"hb-wh1-label\">{stat.label}</span>\n                <span className=\"hb-wh1-foot\" aria-hidden=\"true\">\n                  <span className=\"hb-wh1-bar\" />\n                  {stat.delta ? <span className=\"hb-wh1-delta\">{stat.delta}</span> : null}\n                </span>\n              </li>\n            );\n          })}\n        </ol>\n      </div>\n    </section>\n  );\n}\n"
    }
  ]
}