{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stats-before-after",
  "type": "registry:component",
  "title": "Stats Before After",
  "description": "A light case study block that plays numbers from before to after, with a draggable timeline, Before and After buttons, delta pills whose arrows flip, comparison bars and a customer quote.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "stats",
    "stats",
    "before after",
    "comparison",
    "case study",
    "counter",
    "light"
  ],
  "docs": "https://hyperblur.dev/effects/stats-before-after",
  "files": [
    {
      "path": "registry/hyperblur/stats-before-after.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/stats-before-after.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface StatsBeforeAfterItem {\n  label: string;\n  before: number;\n  after: number;\n  decimals?: number;\n  prefix?: string;\n  suffix?: string;\n  better: \"higher\" | \"lower\";\n}\n\nexport interface StatsBeforeAfterProps extends Omit<React.HTMLAttributes<HTMLElement>, \"title\" | \"onChange\"> {\n  eyebrow?: string;\n  title?: string;\n  subtitle?: string;\n  items?: StatsBeforeAfterItem[];\n  beforeLabel?: string;\n  afterLabel?: string;\n  quote?: { text: string; name: string; role: string } | null;\n  autoPlay?: boolean;\n  onChange?: (progress: number) => void;\n  accent?: string;\n}\n\nconst defaultItems: StatsBeforeAfterItem[] = [\n  { label: \"Deploys per week\", before: 3, after: 41, better: \"higher\" },\n  { label: \"Lead time for a change\", before: 9.5, after: 1.2, decimals: 1, suffix: \" days\", better: \"lower\" },\n  { label: \"Time to recover from incidents\", before: 372, after: 38, suffix: \" min\", better: \"lower\" },\n  { label: \"Cloud spend per month\", before: 48200, after: 29700, prefix: \"$\", better: \"lower\" },\n];\n\nconst css = `\n.hb-yic {\n  --hb-yic-accent: #4f46e5;\n  container-type: inline-size;\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  overflow: hidden;\n  background: #fbfaf7;\n  color: #131316;\n  font-family: inherit;\n  -webkit-font-smoothing: antialiased;\n}\n.hb-yic *, .hb-yic *::before, .hb-yic *::after { box-sizing: border-box; }\n.hb-yic::before {\n  content: \"\"; position: absolute; inset: 0; pointer-events: none;\n  background: linear-gradient(90deg, rgba(19, 19, 22, .04) 1px, transparent 1px) 0 0 / calc(100% / 12) 100%;\n  mask-image: linear-gradient(180deg, #000, transparent 60%);\n}\n.hb-yic-inner { position: relative; max-width: 1120px; margin: 0 auto; padding: 72px 20px 80px; }\n.hb-yic-head { display: grid; gap: 24px; align-items: end; }\n.hb-yic-eyebrow { display: inline-flex; align-items: center; gap: 8px; margin: 0 0 14px; padding: 5px 10px; border-radius: 8px; font-size: 12px; font-weight: 600; color: var(--hb-yic-accent); background: color-mix(in srgb, var(--hb-yic-accent) 8%, #fff); border: 1px solid color-mix(in srgb, var(--hb-yic-accent) 18%, transparent); }\n.hb-yic-title { margin: 0; font-size: clamp(30px, 5cqi, 52px); line-height: 1.03; letter-spacing: -.045em; font-weight: 650; max-width: 17ch; }\n.hb-yic-sub { margin: 14px 0 0; max-width: 480px; font-size: 16px; line-height: 1.6; color: #64646c; }\n.hb-yic-ctrl { display: grid; gap: 10px; min-width: 0; }\n.hb-yic-seg { display: inline-flex; padding: 4px; border-radius: 12px; background: #fff; border: 1px solid rgba(19, 19, 22, .1); box-shadow: 0 1px 2px rgba(19, 19, 22, .04); justify-self: start; }\n.hb-yic-seg button { height: 34px; padding: 0 16px; border: 0; border-radius: 9px; background: transparent; color: #64646c; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; transition: background .2s, color .2s; }\n.hb-yic-seg button[aria-pressed=\"true\"] { background: #131316; color: #fff; }\n.hb-yic-seg button:focus-visible, .hb-yic-range:focus-visible { outline: 2px solid var(--hb-yic-accent); outline-offset: 2px; }\n.hb-yic-scrub { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; font-size: 12px; font-weight: 600; color: #8a8a92; }\n.hb-yic-range { -webkit-appearance: none; appearance: none; width: 100%; min-width: 120px; height: 24px; margin: 0; background: transparent; cursor: ew-resize; }\n.hb-yic-range::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(90deg, var(--hb-yic-accent) calc(var(--hb-yic-t) * 100%), #e4e3de 0); }\n.hb-yic-range::-moz-range-track { height: 4px; border-radius: 4px; background: linear-gradient(90deg, var(--hb-yic-accent) calc(var(--hb-yic-t) * 100%), #e4e3de 0); }\n.hb-yic-range::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 6px; background: #fff; border: 2px solid var(--hb-yic-accent); box-shadow: 0 2px 6px rgba(19, 19, 22, .2); }\n.hb-yic-range::-moz-range-thumb { width: 14px; height: 14px; border-radius: 6px; background: #fff; border: 2px solid var(--hb-yic-accent); box-shadow: 0 2px 6px rgba(19, 19, 22, .2); }\n.hb-yic-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 40px; }\n.hb-yic-card {\n  position: relative; padding: 22px; border-radius: 18px; background: #fff; border: 1px solid rgba(19, 19, 22, .08);\n  box-shadow: 0 1px 0 #fff inset, 0 18px 40px -30px rgba(19, 19, 22, .35); display: flex; flex-direction: column; min-width: 0;\n  animation: hb-yic-rise .6s cubic-bezier(.2, .8, .2, 1) both; animation-delay: calc(var(--hb-yic-i) * 80ms);\n}\n.hb-yic-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }\n.hb-yic-label { margin: 0; font-size: 14px; color: #44444c; line-height: 1.35; }\n.hb-yic-delta {\n  display: inline-flex; align-items: center; gap: 4px; flex: none; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums;\n  transition: background .3s, color .3s;\n}\n.hb-yic-delta[data-good=\"true\"] { color: #0b7a4b; background: #dcf5e8; }\n.hb-yic-delta[data-good=\"false\"] { color: #b4321f; background: #fde4df; }\n.hb-yic-delta[data-zero=\"true\"] { color: #8a8a92; background: #f0efea; }\n.hb-yic-delta svg { width: 12px; height: 12px; transition: transform .4s cubic-bezier(.3, 1.4, .5, 1); }\n.hb-yic-delta[data-dir=\"down\"] svg { transform: rotate(180deg); }\n.hb-yic-num { margin: 22px 0 0; font-size: clamp(34px, 4cqi, 46px); line-height: 1; letter-spacing: -.045em; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }\n.hb-yic-num small { font-size: .42em; letter-spacing: -.01em; color: #8a8a92; font-weight: 600; }\n.hb-yic-was { margin: 8px 0 0; font-size: 13px; color: #8a8a92; font-variant-numeric: tabular-nums; }\n.hb-yic-was s { text-decoration-color: rgba(19, 19, 22, .35); }\n.hb-yic-cmp { display: grid; gap: 6px; margin-top: 18px; }\n.hb-yic-cmp div { display: grid; grid-template-columns: 44px minmax(0, 1fr); align-items: center; gap: 8px; font-size: 11px; color: #8a8a92; font-weight: 600; }\n.hb-yic-cmp i { display: block; height: 8px; border-radius: 4px; background: #f0efea; overflow: hidden; }\n.hb-yic-cmp b { display: block; height: 100%; border-radius: 4px; background: #c9c8c2; }\n.hb-yic-cmp div + div b { background: var(--hb-yic-accent); }\n.hb-yic-quote { display: grid; gap: 16px; margin-top: 16px; padding: 24px; border-radius: 18px; background: #131316; color: #f3f3f5; }\n.hb-yic-quote p { margin: 0; font-size: clamp(17px, 2.2cqi, 21px); line-height: 1.45; letter-spacing: -.015em; }\n.hb-yic-who { display: flex; align-items: center; gap: 12px; font-size: 14px; }\n.hb-yic-who i { width: 36px; height: 36px; border-radius: 50%; flex: none; background: linear-gradient(135deg, var(--hb-yic-accent), #f472b6); display: grid; place-items: center; font-style: normal; font-weight: 700; font-size: 13px; }\n.hb-yic-who span { color: #9a9aa2; display: block; font-size: 13px; }\n.hb-yic-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }\n@keyframes hb-yic-rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }\n@container (min-width: 600px) {\n  .hb-yic-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }\n}\n@container (min-width: 920px) {\n  .hb-yic-inner { padding: 104px 32px 112px; }\n  .hb-yic-head { grid-template-columns: minmax(0, 1fr) minmax(0, 380px); }\n  .hb-yic-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }\n  .hb-yic-quote { grid-template-columns: minmax(0, 1fr) auto; align-items: center; padding: 28px 32px; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-yic-card { animation: none; }\n  .hb-yic-delta, .hb-yic-delta svg, .hb-yic-seg button { transition: none; }\n}\n`;\n\nfunction format(v: number, decimals: number) {\n  const fixed = v.toFixed(decimals);\n  const [whole, frac] = fixed.split(\".\");\n  const grouped = whole.replace(/\\B(?=(\\d{3})+(?!\\d))/g, \",\");\n  return frac ? `${grouped}.${frac}` : grouped;\n}\n\nexport function StatsBeforeAfter({\n  eyebrow = \"Case study · Northwind Freight\",\n  title = \"Twelve months after moving to Relay.\",\n  subtitle = \"Northwind's platform team of nine replaced four internal tools. Drag the timeline to compare the numbers they reported.\",\n  items = defaultItems,\n  beforeLabel = \"Q3 2025\",\n  afterLabel = \"Q3 2026\",\n  quote = { text: \"We ship on Fridays now. Nobody on the team remembers when that stopped being scary.\", name: \"Dana Whitlock\", role: \"VP Engineering, Northwind\" },\n  autoPlay = true,\n  onChange,\n  accent = \"#4f46e5\",\n  className = \"\",\n  style,\n  ...rest\n}: StatsBeforeAfterProps) {\n  const [t, setT] = React.useState(autoPlay ? 0 : 1);\n  const raf = React.useRef(0);\n  const tRef = React.useRef(t);\n  const id = React.useId();\n\n  const animateTo = React.useCallback((target: number, delay = 0) => {\n    cancelAnimationFrame(raf.current);\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) {\n      raf.current = requestAnimationFrame(() => {\n        tRef.current = target;\n        setT(target);\n      });\n      return;\n    }\n    const from = tRef.current;\n    let start = 0;\n    const step = (now: number) => {\n      if (!start) start = now + delay;\n      const k = Math.max(0, Math.min(1, (now - start) / 1400));\n      const e = k < 0.5 ? 4 * k * k * k : 1 - Math.pow(-2 * k + 2, 3) / 2;\n      const v = from + (target - from) * e;\n      tRef.current = v;\n      setT(v);\n      if (k < 1) raf.current = requestAnimationFrame(step);\n    };\n    raf.current = requestAnimationFrame(step);\n  }, []);\n\n  React.useEffect(() => {\n    if (autoPlay) animateTo(1, 500);\n    const r = raf;\n    return () => cancelAnimationFrame(r.current);\n  }, [autoPlay, animateTo]);\n\n  const snap = (target: number) => {\n    animateTo(target);\n    onChange?.(target);\n  };\n\n  const scrub = (v: number) => {\n    cancelAnimationFrame(raf.current);\n    tRef.current = v;\n    setT(v);\n    onChange?.(v);\n  };\n\n  const vars = { \"--hb-yic-accent\": accent, \"--hb-yic-t\": t.toFixed(4), ...style } as React.CSSProperties;\n\n  return (\n    <section className={`hb-yic ${className}`} style={vars} {...rest}>\n      <style href=\"hb-stats-before-after\" precedence=\"default\">{css}</style>\n      <div className=\"hb-yic-inner\">\n        <div className=\"hb-yic-head\">\n          <div>\n            {eyebrow ? <p className=\"hb-yic-eyebrow\">{eyebrow}</p> : null}\n            <h2 className=\"hb-yic-title\">{title}</h2>\n            {subtitle ? <p className=\"hb-yic-sub\">{subtitle}</p> : null}\n          </div>\n          <div className=\"hb-yic-ctrl\">\n            <div className=\"hb-yic-seg\" role=\"group\" aria-label=\"Compare\">\n              <button type=\"button\" aria-pressed={t < 0.5} onClick={() => snap(0)}>\n                {`Before · ${beforeLabel}`}\n              </button>\n              <button type=\"button\" aria-pressed={t >= 0.5} onClick={() => snap(1)}>\n                {`After · ${afterLabel}`}\n              </button>\n            </div>\n            <div className=\"hb-yic-scrub\">\n              <span aria-hidden=\"true\">{beforeLabel}</span>\n              <input\n                id={`${id}-t`}\n                className=\"hb-yic-range\"\n                type=\"range\"\n                min={0}\n                max={1000}\n                value={Math.round(t * 1000)}\n                aria-label=\"Timeline from before to after\"\n                aria-valuetext={`${Math.round(t * 100)}% of the way to ${afterLabel}`}\n                onChange={(e) => scrub(Number(e.target.value) / 1000)}\n              />\n              <span aria-hidden=\"true\">{afterLabel}</span>\n            </div>\n          </div>\n        </div>\n\n        <div className=\"hb-yic-grid\">\n          {items.map((it, i) => {\n            const decimals = it.decimals ?? 0;\n            const now = it.before + (it.after - it.before) * t;\n            const change = it.before === 0 ? 0 : (now - it.before) / it.before;\n            const dir = change >= 0 ? \"up\" : \"down\";\n            const good = it.better === \"higher\" ? change >= 0 : change <= 0;\n            const zero = Math.abs(change) < 0.005;\n            const peak = Math.max(it.before, it.after) || 1;\n            const pct = Math.abs(change * 100);\n            return (\n              <article key={it.label} className=\"hb-yic-card\" style={{ \"--hb-yic-i\": i } as React.CSSProperties}>\n                <div className=\"hb-yic-top\">\n                  <p className=\"hb-yic-label\">{it.label}</p>\n                  <span className=\"hb-yic-delta\" data-good={good} data-zero={zero} data-dir={dir}>\n                    <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"3\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                      <path d=\"M12 19V5M5 12l7-7 7 7\" />\n                    </svg>\n                    {`${pct >= 100 ? pct.toFixed(0) : pct.toFixed(1)}%`}\n                  </span>\n                </div>\n                <p className=\"hb-yic-num\">\n                  <span className=\"hb-yic-sr\">{`${it.label}: ${it.prefix ?? \"\"}${format(it.before, decimals)}${it.suffix ?? \"\"} before, ${it.prefix ?? \"\"}${format(it.after, decimals)}${it.suffix ?? \"\"} after`}</span>\n                  <span aria-hidden=\"true\">\n                    {it.prefix}\n                    {format(now, decimals)}\n                    {it.suffix ? <small>{it.suffix}</small> : null}\n                  </span>\n                </p>\n                <p className=\"hb-yic-was\" aria-hidden=\"true\">\n                  {\"Was \"}\n                  <s>{`${it.prefix ?? \"\"}${format(it.before, decimals)}${it.suffix ?? \"\"}`}</s>\n                </p>\n                <div className=\"hb-yic-cmp\" aria-hidden=\"true\">\n                  <div>\n                    <span>Before</span>\n                    <i>\n                      <b style={{ width: `${((it.before / peak) * 100).toFixed(1)}%` }} />\n                    </i>\n                  </div>\n                  <div>\n                    <span>Now</span>\n                    <i>\n                      <b style={{ width: `${((now / peak) * 100).toFixed(1)}%` }} />\n                    </i>\n                  </div>\n                </div>\n              </article>\n            );\n          })}\n        </div>\n\n        {quote ? (\n          <figure className=\"hb-yic-quote\" style={{ margin: \"16px 0 0\" }}>\n            <blockquote style={{ margin: 0 }}>\n              <p>{`\"${quote.text}\"`}</p>\n            </blockquote>\n            <figcaption className=\"hb-yic-who\">\n              <i aria-hidden=\"true\">\n                {quote.name\n                  .split(\" \")\n                  .map((w) => w[0])\n                  .join(\"\")\n                  .slice(0, 2)}\n              </i>\n              <div>\n                {quote.name}\n                <span>{quote.role}</span>\n              </div>\n            </figcaption>\n          </figure>\n        ) : null}\n      </div>\n    </section>\n  );\n}\n"
    }
  ]
}