{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stats-bar-race",
  "type": "registry:component",
  "title": "Stats Bar Race",
  "description": "A headline and summary figure beside a ranked bar chart. On view the bars race out to their values, larger ones running longer, while the numbers count up in step.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "stats",
    "stats",
    "bar chart",
    "ranking",
    "race",
    "count up",
    "section"
  ],
  "docs": "https://hyperblur.dev/effects/stats-bar-race",
  "files": [
    {
      "path": "registry/hyperblur/stats-bar-race.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/stats-bar-race.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface RaceBar {\n  label: string;\n  detail?: string;\n  value: number;\n}\n\nexport interface StatsBarRaceProps extends Omit<React.HTMLAttributes<HTMLElement>, \"title\"> {\n  eyebrow?: string;\n  title?: string;\n  subtitle?: string;\n  summary?: { value: string; label: string } | null;\n  chartTitle?: string;\n  chartCaption?: string;\n  bars?: RaceBar[];\n  unit?: string;\n  duration?: number;\n  accent?: string;\n}\n\nconst css = `\n.hb-ka7 {\n  --hb-ka7-accent: #ff6b4a;\n  box-sizing: border-box;\n  position: relative;\n  width: 100%;\n  overflow: hidden;\n  container-type: inline-size;\n  background: #0a0a0a;\n  color: #ededed;\n  font-family: inherit;\n  -webkit-font-smoothing: antialiased;\n}\n.hb-ka7 *, .hb-ka7 *::before, .hb-ka7 *::after { box-sizing: border-box; }\n.hb-ka7::before {\n  content: \"\";\n  position: absolute;\n  right: -10%;\n  top: -30%;\n  width: 70%;\n  height: 120%;\n  background: radial-gradient(closest-side, color-mix(in srgb, var(--hb-ka7-accent) 12%, transparent), transparent);\n  pointer-events: none;\n}\n.hb-ka7-wrap {\n  position: relative;\n  display: grid;\n  grid-template-columns: minmax(0, .82fr) minmax(0, 1.4fr);\n  align-items: center;\n  gap: 56px;\n  max-width: 1120px;\n  margin: 0 auto;\n  padding: 96px 24px;\n}\n.hb-ka7-eyebrow {\n  display: inline-flex;\n  align-items: center;\n  gap: 8px;\n  margin: 0 0 18px;\n  color: #a1a1a1;\n  font-size: 13px;\n  font-weight: 500;\n}\n.hb-ka7-eyebrow i {\n  width: 8px;\n  height: 8px;\n  border-radius: 50%;\n  background: var(--hb-ka7-accent);\n  box-shadow: 0 0 0 3px color-mix(in srgb, var(--hb-ka7-accent) 25%, transparent);\n}\n.hb-ka7-title {\n  margin: 0;\n  font-family: var(--font-grotesk, \"Space Grotesk\", ui-sans-serif, system-ui, sans-serif);\n  font-size: clamp(30px, 4.4cqw, 48px);\n  font-weight: 600;\n  line-height: 1.04;\n  letter-spacing: -.035em;\n  text-wrap: balance;\n}\n.hb-ka7-sub { margin: 18px 0 0; color: #8f8f8f; font-size: 16px; line-height: 1.6; }\n.hb-ka7-sum { margin-top: 36px; padding-top: 24px; border-top: 1px solid rgba(255, 255, 255, .08); }\n.hb-ka7-sum b {\n  display: block;\n  font-family: var(--font-grotesk, \"Space Grotesk\", ui-sans-serif, system-ui, sans-serif);\n  font-size: clamp(40px, 5.6cqw, 60px);\n  font-weight: 500;\n  line-height: 1;\n  letter-spacing: -.04em;\n  background: linear-gradient(180deg, #fff, #8f8f8f);\n  -webkit-background-clip: text;\n  background-clip: text;\n  color: transparent;\n}\n.hb-ka7-sum span { display: block; margin-top: 8px; color: #8f8f8f; font-size: 14px; }\n.hb-ka7-card {\n  min-width: 0;\n  padding: 26px 26px 20px;\n  border: 1px solid rgba(255, 255, 255, .08);\n  border-radius: 20px;\n  background: linear-gradient(180deg, #121214, #0d0d0e);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05), 0 40px 80px -40px rgba(0, 0, 0, .9);\n}\n.hb-ka7-ch { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 22px; }\n.hb-ka7-ch h3 { margin: 0; font-size: 15px; font-weight: 600; }\n.hb-ka7-ch span { color: #6f6f6f; font-size: 12px; white-space: nowrap; }\n.hb-ka7-rows { position: relative; display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 0; list-style: none; }\n.hb-ka7-row {\n  display: grid;\n  grid-template-columns: 24px minmax(0, 132px) minmax(0, 1fr) 76px;\n  align-items: center;\n  gap: 12px;\n}\n.hb-ka7-rank { color: #5f5f5f; font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace); font-size: 12px; }\n.hb-ka7-name { min-width: 0; }\n.hb-ka7-name b { display: block; overflow: hidden; font-size: 14px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }\n.hb-ka7-name span { display: block; color: #6f6f6f; font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace); font-size: 11px; }\n.hb-ka7-track {\n  position: relative;\n  height: 30px;\n  border-radius: 8px;\n  background-color: rgba(255, 255, 255, .025);\n  background-image: linear-gradient(90deg, rgba(255, 255, 255, .06) 1px, transparent 1px);\n  background-size: 25% 100%;\n}\n.hb-ka7-bar {\n  position: absolute;\n  top: 0;\n  bottom: 0;\n  left: 0;\n  min-width: 4px;\n  border-radius: 8px;\n  background: linear-gradient(90deg, rgba(255, 255, 255, .08), rgba(255, 255, 255, .26));\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12);\n}\n.hb-ka7-bar::after {\n  content: \"\";\n  position: absolute;\n  top: 5px;\n  right: 5px;\n  bottom: 5px;\n  width: 3px;\n  border-radius: 2px;\n  background: rgba(255, 255, 255, .55);\n}\n.hb-ka7-row[data-lead=\"true\"] .hb-ka7-bar {\n  background: linear-gradient(90deg, color-mix(in srgb, var(--hb-ka7-accent) 25%, transparent), var(--hb-ka7-accent));\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 0 28px -6px var(--hb-ka7-accent);\n}\n.hb-ka7-row[data-lead=\"true\"] .hb-ka7-bar::after { background: #fff; }\n.hb-ka7-val {\n  text-align: right;\n  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);\n  font-size: 14px;\n  font-variant-numeric: tabular-nums;\n}\n.hb-ka7-row[data-lead=\"true\"] .hb-ka7-val { color: color-mix(in srgb, var(--hb-ka7-accent) 55%, #fff); }\n.hb-ka7-axis {\n  display: grid;\n  grid-template-columns: 24px minmax(0, 132px) minmax(0, 1fr) 76px;\n  gap: 12px;\n  margin-top: 12px;\n  color: #5f5f5f;\n  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);\n  font-size: 10.5px;\n}\n.hb-ka7-ticks { display: flex; justify-content: space-between; }\n.hb-ka7-unit { text-align: right; }\n@container (max-width: 860px) {\n  .hb-ka7-wrap { grid-template-columns: minmax(0, 1fr); gap: 40px; }\n}\n@container (max-width: 520px) {\n  .hb-ka7-wrap { padding: 64px 16px 72px; }\n  .hb-ka7-card { padding: 18px 14px 14px; border-radius: 16px; }\n  .hb-ka7-row, .hb-ka7-axis { grid-template-columns: minmax(0, 84px) minmax(0, 1fr) 58px; gap: 10px; }\n  .hb-ka7-rank, .hb-ka7-axis > span:first-child { display: none; }\n  .hb-ka7-name span { display: none; }\n  .hb-ka7-name b, .hb-ka7-val { font-size: 12.5px; }\n  .hb-ka7-track { height: 24px; }\n  .hb-ka7-ch { flex-direction: column; gap: 4px; }\n}\n`;\n\nfunction useProgress<T extends Element>(ref: React.RefObject<T | null>, duration: number) {\n  const [t, setT] = React.useState(0);\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    let raf = 0;\n    const run = () => {\n      if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) {\n        setT(1);\n        return;\n      }\n      const start = performance.now();\n      const tick = (now: number) => {\n        const p = Math.min((now - start) / duration, 1);\n        setT(p);\n        if (p < 1) raf = requestAnimationFrame(tick);\n      };\n      raf = requestAnimationFrame(tick);\n    };\n    if (typeof IntersectionObserver === \"undefined\") {\n      raf = requestAnimationFrame(() => setT(1));\n      return () => cancelAnimationFrame(raf);\n    }\n    const io = new IntersectionObserver(\n      (entries) => {\n        if (entries.some((e) => e.isIntersecting)) {\n          io.disconnect();\n          run();\n        }\n      },\n      { threshold: 0.25 },\n    );\n    io.observe(el);\n    return () => {\n      io.disconnect();\n      cancelAnimationFrame(raf);\n    };\n  }, [ref, duration]);\n  return t;\n}\n\nfunction easeOut(x: number) {\n  return 1 - Math.pow(1 - x, 3);\n}\n\nfunction niceMax(n: number) {\n  if (n <= 0) return 1;\n  const mag = Math.pow(10, Math.floor(Math.log10(n)));\n  const steps = [1, 1.2, 1.5, 2, 2.5, 3, 4, 5, 6, 8, 10];\n  const unit = steps.find((s) => s * mag >= n) ?? 10;\n  return unit * mag;\n}\n\nfunction compact(n: number) {\n  if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(n % 1_000_000 ? 1 : 0)}M`;\n  if (n >= 1000) return `${(n / 1000).toFixed(n % 1000 ? 1 : 0)}k`;\n  return String(Math.round(n));\n}\n\nconst defaultBars: RaceBar[] = [\n  { label: \"Frankfurt\", detail: \"fra1\", value: 48200 },\n  { label: \"Virginia\", detail: \"iad1\", value: 41900 },\n  { label: \"Tokyo\", detail: \"hnd1\", value: 33400 },\n  { label: \"Sao Paulo\", detail: \"gru1\", value: 21700 },\n  { label: \"Sydney\", detail: \"syd1\", value: 17300 },\n  { label: \"Mumbai\", detail: \"bom1\", value: 14800 },\n];\n\nexport function StatsBarRace({\n  eyebrow = \"Live network\",\n  title = \"Six regions. One edge that never sleeps.\",\n  subtitle = \"Traffic is served from the region closest to each visitor, with automatic failover in under two seconds.\",\n  summary = { value: \"177k\", label: \"requests per second at peak, October 2026\" },\n  chartTitle = \"Requests per second by region\",\n  chartCaption = \"30-day peak\",\n  bars = defaultBars,\n  unit = \"req/s\",\n  duration = 2600,\n  accent = \"#ff6b4a\",\n  className = \"\",\n  style,\n  ...rest\n}: StatsBarRaceProps) {\n  const uid = React.useId();\n  const ref = React.useRef<HTMLUListElement>(null);\n  const t = useProgress(ref, Math.max(duration, 200));\n  const sorted = [...bars].sort((a, b) => b.value - a.value);\n  const top = sorted[0]?.value ?? 1;\n  const max = niceMax(top);\n  const ticks = [0, 0.25, 0.5, 0.75, 1].map((f) => compact(max * f));\n  const vars = { \"--hb-ka7-accent\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <section className={`hb-ka7 ${className}`} style={vars} aria-labelledby={`${uid}-t`} {...rest}>\n      <style href=\"hb-stats-bar-race\" precedence=\"default\">{css}</style>\n      <div className=\"hb-ka7-wrap\">\n        <div>\n          {eyebrow && (\n            <p className=\"hb-ka7-eyebrow\">\n              <i aria-hidden=\"true\" />\n              {eyebrow}\n            </p>\n          )}\n          <h2 id={`${uid}-t`} className=\"hb-ka7-title\">{title}</h2>\n          {subtitle && <p className=\"hb-ka7-sub\">{subtitle}</p>}\n          {summary && (\n            <div className=\"hb-ka7-sum\">\n              <b>{summary.value}</b>\n              <span>{summary.label}</span>\n            </div>\n          )}\n        </div>\n        <div className=\"hb-ka7-card\">\n          <div className=\"hb-ka7-ch\">\n            <h3>{chartTitle}</h3>\n            {chartCaption && <span>{chartCaption}</span>}\n          </div>\n          <ul ref={ref} className=\"hb-ka7-rows\">\n            {sorted.map((b, i) => {\n              const share = b.value / top;\n              const span = 0.4 + 0.6 * share;\n              const local = t >= 1 ? 1 : easeOut(Math.min(t / span, 1));\n              const width = (b.value / max) * 100 * local;\n              const shown = Math.round(b.value * local);\n              return (\n                <li key={`${b.label}-${i}`} className=\"hb-ka7-row\" data-lead={i === 0}>\n                  <span className=\"hb-ka7-rank\" aria-hidden=\"true\">{String(i + 1).padStart(2, \"0\")}</span>\n                  <span className=\"hb-ka7-name\">\n                    <b>{b.label}</b>\n                    {b.detail && <span>{b.detail}</span>}\n                  </span>\n                  <span className=\"hb-ka7-track\" aria-hidden=\"true\">\n                    <span className=\"hb-ka7-bar\" style={{ width: `${width.toFixed(2)}%` }} />\n                  </span>\n                  <span className=\"hb-ka7-val\">\n                    <span aria-hidden=\"true\">{shown.toLocaleString(\"en-US\")}</span>\n                    <span style={{ position: \"absolute\", width: 1, height: 1, overflow: \"hidden\", clip: \"rect(0 0 0 0)\" }}>\n                      {`${b.value.toLocaleString(\"en-US\")} ${unit}`}\n                    </span>\n                  </span>\n                </li>\n              );\n            })}\n          </ul>\n          <div className=\"hb-ka7-axis\" aria-hidden=\"true\">\n            <span />\n            <span />\n            <span className=\"hb-ka7-ticks\">\n              {ticks.map((tk, i) => (\n                <span key={i}>{tk}</span>\n              ))}\n            </span>\n            <span className=\"hb-ka7-unit\">{unit}</span>\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n"
    }
  ]
}