{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"milestone-roll","type":"registry:component","title":"Milestone Roll","description":"A counter races through milestones to a 1,000,000 poster over a gradient ground.","dependencies":["remotion","@remotion/google-fonts"],"docs":"Needs a Remotion project. If a frame renders black, the component is drawing on a transparent layer: put a background behind it, e.g. <AbsoluteFill style={{ background: \"#faf9f6\" }}><Component /></AbsoluteFill>.","registryDependencies":["https://kuchi.kalarislabs.com/r/gradient-ground.json"],"files":[{"path":"components/kuchi/milestone-roll.tsx","type":"registry:component","target":"components/kuchi/milestone-roll.tsx","content":"/*! Portions Copyright (c) 2026 Remocn. MIT License. See THIRD_PARTY_LICENSES. */\n\"use client\";\n\nimport { loadFont as loadMono } from \"@remotion/google-fonts/GeistMono\";\nimport { loadFont as loadSerif } from \"@remotion/google-fonts/InstrumentSerif\";\nimport { loadFont as loadManrope } from \"@remotion/google-fonts/Manrope\";\nimport { loadFont } from \"@remotion/google-fonts/SpaceGrotesk\";\nimport type React from \"react\";\nimport {\n  AbsoluteFill,\n  Easing,\n  interpolate,\n  spring,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\nimport type { GradientParams } from \"@/lib/kuchi/gsh/gradient-engine\";\nimport { GshGround } from \"@/lib/kuchi/gsh/gsh-ground\";\nimport type { GshPresetId } from \"@/lib/kuchi/gsh/presets\";\n\nconst { fontFamily: grotesk } = loadFont(\"normal\", {\n  weights: [\"300\", \"400\"],\n  subsets: [\"latin\"],\n});\nconst { fontFamily: mono } = loadMono(\"normal\", {\n  weights: [\"400\"],\n  subsets: [\"latin\"],\n});\nconst { fontFamily: serifItalic } = loadSerif(\"italic\", {\n  weights: [\"400\"],\n  subsets: [\"latin\"],\n});\nconst manrope = loadManrope(\"normal\", {\n  weights: [\"600\"],\n  subsets: [\"latin\"],\n});\n\n\nfunction KuchiLogo({ fontSize, color }: { fontSize: number; color: string }) {\n  return (\n    <div\n      style={{\n        display: \"flex\",\n        alignItems: \"baseline\",\n        color,\n        fontFamily: manrope.fontFamily,\n        fontWeight: 600,\n        fontSize,\n        letterSpacing: \"-0.025em\",\n        lineHeight: 1,\n      }}\n    >\n      <span>Acme</span>\n    </div>\n  );\n}\n\nexport interface MilestoneRollProps {\n  /** Milestones the counter races through, ascending. The last one is the poster. */\n  milestones?: number[];\n  /** What is being counted, set in the serif italic on the poster and in the top label. */\n  unit?: string;\n  /** Kept for the shared draft API; the colour comes from the halo ground. */\n  accent?: string;\n  /** Text color of the numbers, labels and progress bar; overrides the theme ink. */\n  ink?: string;\n  /** Solid fill in place of the gradient ground; \"transparent\" drops it. */\n  background?: string;\n  /** Typeface for the numbers. Load it yourself; Space Grotesk by default. */\n  fontFamily?: string;\n  /** Frames the counter races to each milestone. */\n  run?: number;\n  /** Frames each milestone holds before the next race. */\n  hold?: number;\n  /** Replaces the acme mark. */\n  logo?: React.ReactNode;\n  /** Size of the counter and chrome, around the frame's center. */\n  scale?: number;\n  /** Frames to hold the first frame before anything moves. */\n  delay?: number;\n  theme?: \"dark\" | \"light\";\n  /** gradients.sh preset id for the ground. */\n  ground?: GshPresetId;\n  /** Overrides for the ground shader. */\n  groundParams?: Partial<GradientParams>;\n  speed?: number;\n}\n\nconst RUN = 15;\nconst HOLD = 14;\nconst OUT = 6;\nconst FIRST = -2;\n\nconst RACE = Easing.bezier(0.55, 0, 1, 0.45);\nconst MOVE = Easing.bezier(0.83, 0, 0.17, 1);\nconst ENTER = Easing.bezier(0.32, 0.72, 0, 1);\nconst CAMERA = Easing.bezier(0.87, 0, 0.13, 1);\nconst HEAVY = { mass: 1, damping: 26, stiffness: 120 };\nconst CARD = { mass: 0.8, damping: 18, stiffness: 160 };\nconst MORPH = { damping: 200 };\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nconst THEMES = {\n  dark: {\n    stage: \"#030306\",\n    ink: \"#F7F3EE\",\n    flash: \"#FFF6E8\",\n    flashAlpha: 0.7,\n    preset: \"iris\" as GshPresetId,\n    params: { background: \"#030306\" } as Partial<GradientParams>,\n    veil: [0.5, 0.38, 0.24, 0.12],\n    final: 0.08,\n    ring: [0.8, 1.05, 1.35, 1.7],\n    finalRing: 2.5,\n  },\n  light: {\n    stage: \"#F4F0EA\",\n    ink: \"#16121A\",\n    flash: \"#FFFFFF\",\n    flashAlpha: 0.8,\n    preset: \"iris\" as GshPresetId,\n    params: {\n      background: \"#F4F0EA\",\n      colors: [\"#FFFFFF\", \"#FFB25A\", \"#EF4F86\", \"#4058FF\"],\n    } as Partial<GradientParams>,\n    veil: [0.5, 0.4, 0.28, 0.16],\n    final: 0.1,\n    ring: [0.8, 1.05, 1.35, 1.7],\n    finalRing: 2.5,\n  },\n} as const;\n\nfunction ramp(t: number, from: number, len: number) {\n  return interpolate(t, [from, from + len], [0, 1], CLAMP);\n}\n\nfunction kick(d: number) {\n  if (d < 0) return 0;\n  if (d < 2) return d / 2;\n  const k = Math.max(0, 1 - (d - 2) / 8);\n  return k * k;\n}\n\nfunction shake(d: number, amp: number, seed: number) {\n  if (d < 0 || d > 7) return { x: 0, y: 0 };\n  const k = (1 - d / 7) ** 2;\n  return {\n    x: amp * k * Math.sin(d * 2.7 + seed),\n    y: amp * 0.7 * k * Math.cos(d * 3.3 + seed * 1.7),\n  };\n}\n\nfunction abbreviate(n: number) {\n  if (n >= 1e6) return `${+(n / 1e6).toFixed(1)}M`;\n  if (n >= 1e3) return `${+(n / 1e3).toFixed(1)}K`;\n  return `${n}`;\n}\n\nfunction withCommas(n: number) {\n  return Math.round(n)\n    .toString()\n    .replace(/\\B(?=(\\d{3})+(?!\\d))/g, \",\");\n}\n\n/** The foreground at `scale`, around the frame's center; nothing extra at 1. */\nfunction ScaleLayer({\n  scale,\n  children,\n}: {\n  scale: number;\n  children: React.ReactNode;\n}) {\n  if (scale === 1) return children;\n  return (\n    <AbsoluteFill style={{ transform: `scale(${scale})` }}>\n      {children}\n    </AbsoluteFill>\n  );\n}\n\nexport function MilestoneRoll({\n  milestones = [1000, 10000, 100000, 1000000],\n  unit = \"renders\",\n  ink,\n  background,\n  fontFamily = grotesk,\n  run = RUN,\n  hold = HOLD,\n  logo,\n  scale = 1,\n  delay = 0,\n  theme = \"dark\",\n  ground,\n  groundParams,\n  speed = 1,\n}: MilestoneRollProps) {\n  const t = Math.max(0, useCurrentFrame() - delay) * speed;\n  const { width: W, height: H, fps } = useVideoConfig();\n  const c = THEMES[theme];\n  const fg = ink ?? c.ink;\n  const stage =\n    background === undefined\n      ? c.stage\n      : background === \"transparent\"\n        ? \"transparent\"\n        : background;\n  const seg = run + hold + OUT;\n  const tall = H > W;\n  const base = tall ? W * 0.62 : H;\n  const u = Math.min(W / 1280, H / 720);\n\n  const n = milestones.length;\n  const hitAt = (i: number) => FIRST + i * seg + run;\n  const finalAt = hitAt(n - 1);\n\n  let hit = -1;\n  for (let i = 0; i < n; i++) if (t >= hitAt(i)) hit = i;\n  const isFinal = hit === n - 1;\n\n  const step = (arr: readonly number[], i: number) =>\n    arr[Math.max(0, Math.min(arr.length - 1, i))];\n  let ring: number = c.ring[0];\n  let veil: number = c.veil[0];\n  for (let i = 0; i < n; i++) {\n    const k = spring({ frame: t - hitAt(i), fps, config: HEAVY });\n    const toRing = i === n - 1 ? c.finalRing : step(c.ring, i + 1);\n    const toVeil = i === n - 1 ? c.final : step(c.veil, i + 1);\n    ring += (toRing - step(c.ring, i)) * k;\n    veil += (toVeil - step(c.veil, i)) * Math.min(1, k);\n  }\n  const breathe = interpolate(t, [0, 180], [0, 1], CLAMP);\n  const flash = hit >= 0 ? Math.max(0, 1 - (t - hitAt(hit)) / 4) ** 2 : 0;\n\n  const runIdx = hit + 1;\n  const runStart = FIRST + runIdx * seg;\n  const from = runIdx === 0 ? 0 : milestones[runIdx - 1];\n  const to = milestones[Math.min(runIdx, n - 1)];\n  const race = RACE(ramp(t, runStart, run));\n  const value = from + (to - from) * race;\n\n  const h = hit >= 0 && !isFinal ? hitAt(hit) : -1e9;\n  const pPunch = spring({ frame: Math.min(t - h, 60), fps, config: CARD });\n  const push = MOVE(ramp(t, h + hold, OUT));\n  const pushDist = 0.8 * H;\n  const inHit = hit >= 0 && !isFinal && t < h + hold + OUT;\n\n  let bump = 0;\n  let sx = 0;\n  let sy = 0;\n  for (let i = 0; i < n; i++) {\n    const d = t - hitAt(i) - 3;\n    bump = Math.max(bump, (i === n - 1 ? 1.3 : 0.9) * kick(d));\n    const s = shake(d, (i === n - 1 ? 9 : 6) * u, i * 1.9);\n    sx += s.x;\n    sy += s.y;\n  }\n  const camScale = 1 + 0.03 * bump;\n\n  const runFs = 0.28 * base;\n  const hugeFs = 0.56 * base;\n  const finalText = withCommas(milestones[n - 1]);\n  const digits = finalText.replace(/,/g, \"\").length;\n  const commas = finalText.length - digits;\n  const finalFs = Math.min(\n    0.3 * base,\n    (0.84 * W) / (digits * 0.6 + commas * 0.26),\n  );\n\n  const numberStyle = {\n    fontFamily,\n    fontWeight: 300,\n    fontVariantNumeric: \"tabular-nums\",\n    lineHeight: 1,\n    whiteSpace: \"nowrap\",\n  } as const;\n\n  const pFinal = spring({ frame: t - finalAt, fps, config: CARD });\n  const pUnit = spring({ frame: t - finalAt - 6, fps, config: MORPH });\n  const pLogo = spring({ frame: t - finalAt - 12, fps, config: MORPH });\n  const creep = interpolate(t, [finalAt + 4, finalAt + 70], [1, 1.035], {\n    ...CLAMP,\n    easing: CAMERA,\n  });\n\n  const chromeOut = isFinal ? 1 - ENTER(ramp(t, finalAt, 6)) : 1;\n  const runFill = isFinal ? 1 : inHit ? 1 : race;\n  const margin = (tall ? 0.07 : 0.05) * W;\n  const labelFs = (tall ? 0.017 : 0.025) * H;\n\n  return (\n    <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n      {background === undefined ? (\n        <>\n          <AbsoluteFill\n            style={{\n              transform: `scale(${ring * (1 + 0.04 * breathe)}) rotate(${-8 * breathe}deg)`,\n            }}\n          >\n            <GshGround\n              preset={ground ?? c.preset}\n              params={groundParams ?? c.params}\n              timeOffset={2}\n              timeScale={0.5}\n              style={{ width: \"100%\", height: \"100%\" }}\n            />\n          </AbsoluteFill>\n          <AbsoluteFill style={{ background: c.stage, opacity: veil }} />\n        </>\n      ) : null}\n\n      <ScaleLayer scale={scale}>\n        <div\n          style={{\n            position: \"absolute\",\n            inset: 0,\n            transform: `translate(${sx}px, ${sy}px) scale(${camScale})`,\n            transformOrigin: \"50% 50%\",\n            color: fg,\n          }}\n        >\n          <div\n            style={{\n              position: \"absolute\",\n              left: margin,\n              right: margin,\n              top: (tall ? 0.06 : 0.07) * H,\n              display: \"flex\",\n              justifyContent: \"space-between\",\n              alignItems: \"center\",\n              fontFamily: mono,\n              fontWeight: 400,\n              fontSize: labelFs,\n              letterSpacing: \"0.06em\",\n              textTransform: \"uppercase\",\n              opacity: chromeOut * ENTER(ramp(t, 0, 10)),\n            }}\n          >\n            <div\n              style={{\n                display: \"flex\",\n                alignItems: \"center\",\n                gap: 0.5 * labelFs,\n              }}\n            >\n              <div\n                style={{\n                  width: 0.4 * labelFs,\n                  height: 0.4 * labelFs,\n                  borderRadius: labelFs,\n                  background: fg,\n                }}\n              />\n              {unit}\n            </div>\n            <div style={{ display: \"flex\", gap: 1.4 * labelFs }}>\n              {milestones.map((m, i) => (\n                <div\n                  key={m}\n                  style={{\n                    opacity: i <= hit ? 1 : 0.4,\n                    fontVariantNumeric: \"tabular-nums\",\n                  }}\n                >\n                  {abbreviate(m)}\n                </div>\n              ))}\n            </div>\n          </div>\n\n          <div\n            style={{\n              position: \"absolute\",\n              left: margin,\n              right: margin,\n              bottom: (tall ? 0.06 : 0.08) * H,\n              height: Math.max(2, 2 * u),\n              opacity: chromeOut * ENTER(ramp(t, 0, 10)),\n            }}\n          >\n            <div\n              style={{\n                position: \"absolute\",\n                inset: 0,\n                background: fg,\n                opacity: 0.2,\n              }}\n            />\n            <div\n              style={{\n                position: \"absolute\",\n                left: 0,\n                top: 0,\n                bottom: 0,\n                width: \"100%\",\n                transform: `scaleX(${runFill})`,\n                transformOrigin: \"0% 50%\",\n                background: fg,\n              }}\n            />\n          </div>\n\n          {!isFinal && (!inHit || t >= h + hold) ? (\n            <div\n              style={{\n                position: \"absolute\",\n                inset: 0,\n                display: \"flex\",\n                alignItems: \"center\",\n                justifyContent: \"center\",\n                transform: `translateY(${inHit ? (1 - push) * pushDist : 0}px)`,\n              }}\n            >\n              <div\n                style={{\n                  ...numberStyle,\n                  fontSize: runFs,\n                  letterSpacing: \"-0.04em\",\n                }}\n              >\n                {withCommas(inHit ? milestones[hit] : value)}\n              </div>\n            </div>\n          ) : null}\n\n          {inHit ? (\n            <div\n              style={{\n                position: \"absolute\",\n                inset: 0,\n                display: \"flex\",\n                alignItems: \"center\",\n                justifyContent: \"center\",\n                transform: `translateY(${-push * pushDist}px) scale(${1.3 - 0.3 * pPunch})`,\n                filter:\n                  pPunch < 0.9\n                    ? `blur(${Math.max(0, 1 - pPunch) ** 2 * 14 * u}px)`\n                    : undefined,\n              }}\n            >\n              <div\n                style={{\n                  ...numberStyle,\n                  fontSize: hugeFs,\n                  letterSpacing: \"-0.055em\",\n                  paddingRight: 0.02 * hugeFs,\n                }}\n              >\n                {abbreviate(milestones[hit])}\n              </div>\n            </div>\n          ) : null}\n\n          {isFinal ? (\n            <div\n              style={{\n                position: \"absolute\",\n                inset: 0,\n                display: \"flex\",\n                flexDirection: \"column\",\n                alignItems: \"center\",\n                justifyContent: \"center\",\n                transform: `scale(${creep})`,\n              }}\n            >\n              <div\n                style={{\n                  ...numberStyle,\n                  fontSize: finalFs,\n                  letterSpacing: \"-0.05em\",\n                  transform: `scale(${1.25 - 0.25 * pFinal})`,\n                  filter:\n                    pFinal < 0.9\n                      ? `blur(${Math.max(0, 1 - pFinal) ** 2 * 14 * u}px)`\n                      : undefined,\n                  opacity: ramp(t, finalAt - 1, 2),\n                }}\n              >\n                {finalText}\n              </div>\n              <div\n                style={{\n                  fontFamily: serifItalic,\n                  fontStyle: \"italic\",\n                  fontWeight: 400,\n                  fontSize: 0.16 * base,\n                  lineHeight: 1,\n                  letterSpacing: \"-0.02em\",\n                  marginTop: 0.005 * base,\n                  opacity: ramp(t, finalAt + 6, 4),\n                  transform: `translateY(${(1 - pUnit) * 0.06 * base}px)`,\n                }}\n              >\n                {unit}\n              </div>\n            </div>\n          ) : null}\n          {isFinal ? (\n            <div\n              style={{\n                position: \"absolute\",\n                left: 0,\n                right: 0,\n                bottom: (tall ? 0.07 : 0.075) * H,\n                display: \"flex\",\n                justifyContent: \"center\",\n                opacity: ramp(t, finalAt + 12, 5),\n                transform: `translateY(${(1 - pLogo) * 0.04 * H}px)`,\n              }}\n            >\n              {logo ?? (\n                <KuchiLogo fontSize={(tall ? 0.024 : 0.05) * H} color={fg} />\n              )}\n            </div>\n          ) : null}\n        </div>\n      </ScaleLayer>\n\n      {flash > 0.01 ? (\n        <AbsoluteFill\n          style={{ background: c.flash, opacity: flash * c.flashAlpha }}\n        />\n      ) : null}\n    </AbsoluteFill>\n  );\n}\n"}]}