{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stats-scrub-band",
  "type": "registry:component",
  "title": "Stats Scrub Band",
  "description": "A band of four metrics with sparklines that share one crosshair. Hovering or pressing the arrow keys scrubs every metric to the same day at once, and a range switch redraws all lines for 7, 30 or 90 days.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "stats",
    "stats",
    "sparkline",
    "scrub",
    "crosshair",
    "range",
    "section"
  ],
  "docs": "https://hyperblur.dev/effects/stats-scrub-band",
  "files": [
    {
      "path": "registry/hyperblur/stats-scrub-band.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/stats-scrub-band.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ScrubMetric {\n  label: string;\n  base: number;\n  trend: number;\n  volatility?: number;\n  prefix?: string;\n  suffix?: string;\n  decimals?: number;\n  lowerIsBetter?: boolean;\n}\n\nexport interface StatsScrubBandProps extends Omit<React.HTMLAttributes<HTMLElement>, \"title\"> {\n  eyebrow?: string;\n  title?: string;\n  metrics?: ScrubMetric[];\n  ranges?: number[];\n  defaultRange?: number;\n  endDate?: string;\n  accent?: string;\n  onRangeChange?: (days: number) => void;\n}\n\nconst css = `\n.hb-wb7 {\n  --hb-wb7-accent: #2f7bff;\n  box-sizing: border-box;\n  position: relative;\n  width: 100%;\n  container-type: inline-size;\n  background: #0a0a0a;\n  color: #ededed;\n  font-family: inherit;\n  -webkit-font-smoothing: antialiased;\n}\n.hb-wb7 *, .hb-wb7 *::before, .hb-wb7 *::after { box-sizing: border-box; }\n.hb-wb7-wrap { max-width: 1180px; margin: 0 auto; padding: 88px 24px 96px; }\n.hb-wb7-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }\n.hb-wb7-eyebrow { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; color: #8f8f8f; font-size: 13px; }\n.hb-wb7-live { position: relative; width: 8px; height: 8px; border-radius: 50%; background: #22c55e; }\n.hb-wb7-live::after { content: \"\"; position: absolute; inset: -4px; border-radius: 50%; border: 1px solid #22c55e; animation: hb-wb7-ping 2s cubic-bezier(.2, .8, .2, 1) infinite; }\n.hb-wb7-title { margin: 0; max-width: 560px; font-size: clamp(26px, 3.6cqw, 40px); font-weight: 600; line-height: 1.06; letter-spacing: -.035em; text-wrap: balance; }\n.hb-wb7-seg { position: relative; display: inline-flex; padding: 3px; border: 1px solid rgba(255, 255, 255, .08); border-radius: 999px; background: #121212; }\n.hb-wb7-seg button {\n  position: relative;\n  z-index: 1;\n  min-width: 52px;\n  padding: 7px 12px;\n  border: 0;\n  border-radius: 999px;\n  background: transparent;\n  color: #8f8f8f;\n  font: inherit;\n  font-size: 12.5px;\n  font-weight: 500;\n  font-variant-numeric: tabular-nums;\n  cursor: pointer;\n  transition: color .25s ease;\n}\n.hb-wb7-seg button[aria-pressed=\"true\"] { color: #0a0a0a; }\n.hb-wb7-seg button:focus-visible { outline: 2px solid var(--hb-wb7-accent); outline-offset: 2px; }\n.hb-wb7-thumb { position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc((100% - 6px) / var(--hb-wb7-n)); border-radius: 999px; background: #ededed; transform: translateX(calc(var(--hb-wb7-r) * 100%)); transition: transform .45s cubic-bezier(.2, .8, .2, 1); }\n.hb-wb7-band {\n  position: relative;\n  display: grid;\n  grid-template-columns: repeat(var(--hb-wb7-cols, 4), minmax(0, 1fr));\n  border: 1px solid rgba(255, 255, 255, .08);\n  border-radius: 20px;\n  background: linear-gradient(180deg, #121212, #0d0d0d);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05), 0 40px 80px -40px rgba(0, 0, 0, .9);\n  overflow: hidden;\n  cursor: crosshair;\n  touch-action: pan-y;\n}\n.hb-wb7-band:focus-visible { outline: 2px solid var(--hb-wb7-accent); outline-offset: 3px; }\n.hb-wb7-date {\n  position: absolute;\n  top: 14px;\n  right: 16px;\n  padding: 3px 9px;\n  border: 1px solid rgba(255, 255, 255, .1);\n  border-radius: 999px;\n  background: #1a1a1a;\n  color: #a1a1a1;\n  font-size: 11.5px;\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-variant-numeric: tabular-nums;\n  z-index: 2;\n}\n.hb-wb7-date b { color: #ededed; font-weight: 500; }\n.hb-wb7-cell { position: relative; min-width: 0; padding: 22px 22px 0; border-left: 1px solid rgba(255, 255, 255, .07); }\n.hb-wb7-cell:first-child { border-left: 0; }\n.hb-wb7-label { margin: 0; color: #8f8f8f; font-size: 13px; font-weight: 500; }\n.hb-wb7-row { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; margin-top: 10px; }\n.hb-wb7-val { font-size: clamp(26px, 3cqw, 34px); font-weight: 600; line-height: 1; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }\n.hb-wb7-delta { display: inline-flex; align-items: center; gap: 3px; padding: 2px 7px; border-radius: 999px; font-size: 11.5px; font-weight: 600; font-variant-numeric: tabular-nums; }\n.hb-wb7-delta[data-good=\"true\"] { color: #4ade80; background: rgba(74, 222, 128, .1); }\n.hb-wb7-delta[data-good=\"false\"] { color: #f87171; background: rgba(248, 113, 113, .1); }\n.hb-wb7-spark { display: block; width: calc(100% + 44px); height: 92px; margin: 18px -22px 0; overflow: visible; }\n.hb-wb7-area { opacity: 0; animation: hb-wb7-fade .9s .35s ease both; }\n.hb-wb7-line { fill: none; stroke: var(--hb-wb7-accent); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; stroke-dasharray: 1; stroke-dashoffset: 1; animation: hb-wb7-draw 1.2s cubic-bezier(.65, 0, .35, 1) forwards; animation-delay: calc(var(--hb-wb7-i) * 90ms); }\n.hb-wb7-end { position: absolute; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; background: var(--hb-wb7-accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--hb-wb7-accent) 25%, transparent); pointer-events: none; animation: hb-wb7-fade .4s 1.2s both; }\n.hb-wb7-dotwrap { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: #0a0a0a; border: 2px solid var(--hb-wb7-accent); pointer-events: none; }\n.hb-wb7-xline { position: absolute; top: 0; bottom: 0; width: 1px; background: linear-gradient(180deg, transparent, rgba(255, 255, 255, .28) 30%, rgba(255, 255, 255, .28)); pointer-events: none; }\n.hb-wb7-foot { display: flex; justify-content: space-between; gap: 16px; margin-top: 14px; color: #6f6f6f; font-size: 12px; }\n.hb-wb7-foot kbd { padding: 1px 5px; border: 1px solid rgba(255, 255, 255, .12); border-radius: 4px; background: #151515; color: #a1a1a1; font-family: var(--font-mono, ui-monospace, monospace); font-size: 11px; }\n.hb-wb7-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }\n@keyframes hb-wb7-draw { to { stroke-dashoffset: 0; } }\n@keyframes hb-wb7-fade { from { opacity: 0; } to { opacity: 1; } }\n@keyframes hb-wb7-ping { from { transform: scale(.6); opacity: 1; } to { transform: scale(1.8); opacity: 0; } }\n@container (max-width: 860px) {\n  .hb-wb7-band { --hb-wb7-cols: 2; }\n  .hb-wb7-cell:nth-child(odd of .hb-wb7-cell) { border-left: 0; }\n  .hb-wb7-cell:nth-child(n+3 of .hb-wb7-cell) { border-top: 1px solid rgba(255, 255, 255, .07); }\n  .hb-wb7-top { flex-direction: column; align-items: flex-start; }\n}\n@container (max-width: 460px) {\n  .hb-wb7-wrap { padding: 64px 16px 72px; }\n  .hb-wb7-band { --hb-wb7-cols: 1; }\n  .hb-wb7-cell { border-left: 0; }\n  .hb-wb7-cell:nth-child(n+2 of .hb-wb7-cell) { border-top: 1px solid rgba(255, 255, 255, .07); }\n  .hb-wb7-spark { height: 70px; }\n  .hb-wb7-foot span:last-child { display: none; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-wb7-live::after { animation: none; }\n  .hb-wb7-line { animation: none; stroke-dashoffset: 0; }\n  .hb-wb7-area, .hb-wb7-end { animation: none; opacity: 1; }\n  .hb-wb7-thumb, .hb-wb7-seg button { transition: none; }\n}\n`;\n\nconst defaultMetrics: ScrubMetric[] = [\n  { label: \"Monthly recurring revenue\", base: 182400, trend: 0.22, volatility: 0.025, prefix: \"$\" },\n  { label: \"Active workspaces\", base: 8120, trend: 0.16, volatility: 0.03 },\n  { label: \"Net revenue retention\", base: 112.4, trend: 0.035, volatility: 0.006, suffix: \"%\", decimals: 1 },\n  { label: \"Median time to value\", base: 3.9, trend: -0.28, volatility: 0.04, suffix: \" days\", decimals: 1, lowerIsBetter: true },\n];\n\nconst months = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"];\n\nfunction daysIn(y: number, m: number) {\n  if (m === 1) return y % 4 === 0 && (y % 100 !== 0 || y % 400 === 0) ? 29 : 28;\n  return [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][m];\n}\n\nfunction shift(iso: string, back: number) {\n  const [ys, ms, ds] = iso.split(\"-\");\n  let y = Number(ys) || 2026;\n  let m = (Number(ms) || 1) - 1;\n  let d = Number(ds) || 1;\n  let k = back;\n  while (k > 0) {\n    if (d > k) {\n      d -= k;\n      k = 0;\n    } else {\n      k -= d;\n      m -= 1;\n      if (m < 0) {\n        m = 11;\n        y -= 1;\n      }\n      d = daysIn(y, m);\n    }\n  }\n  return `${months[m]} ${d}`;\n}\n\nfunction rnd(seed: number) {\n  let x = (seed + 0x9e3779b9) >>> 0;\n  x = Math.imul(x ^ (x >>> 16), 0x85ebca6b) >>> 0;\n  x = Math.imul(x ^ (x >>> 13), 0xc2b2ae35) >>> 0;\n  return ((x ^ (x >>> 16)) >>> 0) / 4294967296;\n}\n\nfunction series(m: ScrubMetric, mi: number, days: number) {\n  const vol = m.volatility ?? 0.03;\n  const out: number[] = [];\n  let walk = 0;\n  for (let i = 0; i < days; i += 1) {\n    const x = days === 1 ? 1 : i / (days - 1);\n    walk = walk * 0.6 + (rnd(mi * 1000 + days * 7 + i) - 0.5) * 2 * vol;\n    const span = m.trend * (days / 90);\n    out.push(m.base * (1 - span + span * x + walk));\n  }\n  out[days - 1] = m.base;\n  return out;\n}\n\nfunction fmt(m: ScrubMetric, v: number) {\n  const dec = m.decimals ?? 0;\n  const s = v.toLocaleString(\"en-US\", { minimumFractionDigits: dec, maximumFractionDigits: dec });\n  return `${m.prefix ?? \"\"}${s}${m.suffix ?? \"\"}`;\n}\n\nexport function StatsScrubBand({\n  eyebrow = \"Updated every 15 minutes\",\n  title = \"Growth you can scrub through, day by day\",\n  metrics = defaultMetrics,\n  ranges = [7, 30, 90],\n  defaultRange = 1,\n  endDate = \"2026-11-07\",\n  accent = \"#2f7bff\",\n  onRangeChange,\n  className = \"\",\n  style,\n  ...rest\n}: StatsScrubBandProps) {\n  const uid = React.useId();\n  const [r, setR] = React.useState(Math.max(0, Math.min(defaultRange, ranges.length - 1)));\n  const [hover, setHover] = React.useState<number | null>(null);\n  const days = Math.max(2, ranges[r] ?? 30);\n  const data = React.useMemo(() => metrics.map((m, i) => series(m, i, days)), [metrics, days]);\n  const at = hover === null ? days - 1 : hover;\n\n  const W = 200;\n  const H = 60;\n  const xs = (i: number) => (i / (days - 1)) * W;\n\n  const pick = (e: React.PointerEvent<HTMLDivElement>) => {\n    const cell = (e.target as HTMLElement).closest(\"[data-cell]\") as HTMLElement | null;\n    if (!cell) return;\n    const b = cell.getBoundingClientRect();\n    const f = Math.max(0, Math.min(1, (e.clientX - b.left) / Math.max(b.width, 1)));\n    setHover(Math.round(f * (days - 1)));\n  };\n\n  const onKey = (e: React.KeyboardEvent) => {\n    if (e.key === \"ArrowLeft\") {\n      e.preventDefault();\n      setHover(Math.max(0, at - 1));\n    } else if (e.key === \"ArrowRight\") {\n      e.preventDefault();\n      setHover(Math.min(days - 1, at + 1));\n    } else if (e.key === \"Escape\" || e.key === \"End\") {\n      setHover(null);\n    } else if (e.key === \"Home\") {\n      setHover(0);\n    }\n  };\n\n  const choose = (i: number) => {\n    setR(i);\n    setHover(null);\n    onRangeChange?.(ranges[i]);\n  };\n\n  const vars = { \"--hb-wb7-accent\": accent, \"--hb-wb7-n\": ranges.length, \"--hb-wb7-r\": r, ...style } as React.CSSProperties;\n  const dateLabel = shift(endDate, days - 1 - at);\n\n  return (\n    <section className={`hb-wb7 ${className}`} style={vars} aria-labelledby={`${uid}-t`} {...rest}>\n      <style href=\"hb-stats-scrub-band\" precedence=\"default\">{css}</style>\n      <div className=\"hb-wb7-wrap\">\n        <div className=\"hb-wb7-top\">\n          <div>\n            <p className=\"hb-wb7-eyebrow\"><span className=\"hb-wb7-live\" aria-hidden=\"true\" />{eyebrow}</p>\n            <h2 id={`${uid}-t`} className=\"hb-wb7-title\">{title}</h2>\n          </div>\n          <div className=\"hb-wb7-seg\" role=\"group\" aria-label=\"Time range\">\n            <span className=\"hb-wb7-thumb\" aria-hidden=\"true\" />\n            {ranges.map((d, i) => (\n              <button key={d} type=\"button\" aria-pressed={i === r} onClick={() => choose(i)}>{`${d}D`}</button>\n            ))}\n          </div>\n        </div>\n        <div\n          className=\"hb-wb7-band\"\n          tabIndex={0}\n          role=\"group\"\n          aria-label={`Metrics for ${dateLabel}. Use the arrow keys to move through days.`}\n          onPointerMove={pick}\n          onPointerDown={pick}\n          onPointerLeave={() => setHover(null)}\n          onKeyDown={onKey}\n          onBlur={() => setHover(null)}\n        >\n          <span className=\"hb-wb7-date\" aria-live=\"polite\">\n            {hover === null ? <><b>Today</b>{` ${dateLabel}`}</> : <b>{dateLabel}</b>}\n          </span>\n          {metrics.map((m, mi) => {\n            const s = data[mi];\n            const min = Math.min(...s);\n            const max = Math.max(...s);\n            const ys = (v: number) => H - 6 - ((v - min) / Math.max(max - min, 1e-9)) * (H - 16);\n            const line = s.map((v, i) => `${i ? \"L\" : \"M\"}${xs(i).toFixed(2)} ${ys(v).toFixed(2)}`).join(\" \");\n            const area = `${line} L${W} ${H} L0 ${H} Z`;\n            const v = s[at];\n            const first = s[0];\n            const pct = ((v - first) / Math.max(Math.abs(first), 1e-9)) * 100;\n            const good = m.lowerIsBetter ? pct <= 0 : pct >= 0;\n            const gid = `${uid.replace(/[^a-zA-Z0-9]/g, \"\")}-g${mi}`;\n            const px = (at / (days - 1)) * 100;\n            const py = (ys(v) / H) * 100;\n            return (\n              <div key={`${m.label}-${mi}`} className=\"hb-wb7-cell\" data-cell=\"\">\n                <p className=\"hb-wb7-label\">{m.label}</p>\n                <div className=\"hb-wb7-row\">\n                  <span className=\"hb-wb7-val\">{fmt(m, v)}</span>\n                  <span className=\"hb-wb7-delta\" data-good={good}>\n                    {`${pct >= 0 ? \"+\" : \"\"}${pct.toFixed(1)}%`}\n                  </span>\n                </div>\n                <div style={{ position: \"relative\" }}>\n                  <svg key={days} className=\"hb-wb7-spark\" viewBox={`0 0 ${W} ${H}`} preserveAspectRatio=\"none\" aria-hidden=\"true\" style={{ \"--hb-wb7-i\": mi } as React.CSSProperties}>\n                    <defs>\n                      <linearGradient id={gid} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n                        <stop offset=\"0\" stopColor={accent} stopOpacity=\".28\" />\n                        <stop offset=\"1\" stopColor={accent} stopOpacity=\"0\" />\n                      </linearGradient>\n                    </defs>\n                    <path className=\"hb-wb7-area\" d={area} fill={`url(#${gid})`} />\n                    <path className=\"hb-wb7-line\" d={line} pathLength={1} />\n                  </svg>\n                  <div style={{ position: \"absolute\", inset: \"18px -22px 0\" }} aria-hidden=\"true\">\n                    {hover !== null ? (\n                      <>\n                        <span className=\"hb-wb7-xline\" style={{ left: `${px.toFixed(2)}%` }} />\n                        <span className=\"hb-wb7-dotwrap\" style={{ left: `${px.toFixed(2)}%`, top: `${py.toFixed(2)}%` }} />\n                      </>\n                    ) : (\n                      <span key={days} className=\"hb-wb7-end\" style={{ left: \"100%\", top: `${py.toFixed(2)}%` }} />\n                    )}\n                  </div>\n                </div>\n              </div>\n            );\n          })}\n        </div>\n        <div className=\"hb-wb7-foot\">\n          <span>{`Change measured from ${shift(endDate, days - 1)}`}</span>\n          <span>Hover or use <kbd>Left</kbd> <kbd>Right</kbd> to scrub every metric at once</span>\n        </div>\n      </div>\n    </section>\n  );\n}\n"
    }
  ]
}