{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"speedrun-timer","type":"registry:component","title":"Speedrun Timer","description":"A speedrun split table fills row by row and ends on a gold 'WORLD RECORD' time.","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/speedrun-timer.tsx","type":"registry:component","target":"components/kuchi/speedrun-timer.tsx","content":"/*! Portions Copyright (c) 2026 Remocn. MIT License. See THIRD_PARTY_LICENSES. */\n\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/Geist\";\nimport { loadFont as loadMono } from \"@remotion/google-fonts/GeistMono\";\nimport { loadFont as loadManrope } from \"@remotion/google-fonts/Manrope\";\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: geist } = loadFont(\"normal\", {\n  weights: [\"300\", \"400\"],\n  subsets: [\"latin\"],\n});\nconst { fontFamily: mono } = loadMono(\"normal\", {\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 SpeedrunSplit {\n  name: string;\n  /** Cumulative run time at this split, in seconds. */\n  time: number;\n  /** Cumulative personal-best time at this split, in seconds. */\n  pb: number;\n}\n\nexport interface SpeedrunTimerProps {\n  /** Category line in the header, after the logo. */\n  category?: string;\n  /** The splits, in order. The last one is the finish and goes gold. */\n  splits?: SpeedrunSplit[];\n  /** The banner that lands when the run finishes. */\n  banner?: string;\n  /** Colour of the current-split marker. */\n  accent?: string;\n  /** Text color of the splits and timer; 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 splits, timer and banner. Load it yourself; Geist by default. */\n  fontFamily?: string;\n  /** Label above the personal-best time. */\n  pbLabel?: string;\n  /** Corner radius of the splits panel, in px at 1280×720. */\n  radius?: number;\n  /** Replaces the acme mark in the header. */\n  logo?: React.ReactNode;\n  /** Size of the timer and splits, 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 DEFAULT_SPLITS: SpeedrunSplit[] = [\n  { name: \"Script\", time: 521, pb: 563 },\n  { name: \"Edit\", time: 1635, pb: 1703 },\n  { name: \"Captions\", time: 2162, pb: 2143 },\n  { name: \"Render\", time: 2910, pb: 3041 },\n  { name: \"Ship\", time: 3552, pb: 3737 },\n];\n\nconst BEATS = {\n  rowIn: 0,\n  rowGap: 3,\n  run: 12,\n  splits: [30, 50, 66, 84, 102],\n  banner: 106,\n  rise: 102,\n} as const;\n\nconst LIGHT = Easing.bezier(0.22, 1, 0.36, 1);\nconst ENTER = Easing.bezier(0.32, 0.72, 0, 1);\nconst HEAVY = { mass: 1, damping: 26, stiffness: 120 };\nconst CARD = { mass: 0.8, damping: 18, stiffness: 160 };\nconst CHIP = { mass: 0.5, damping: 12, stiffness: 200 };\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nconst THEMES = {\n  dark: {\n    stage: \"#070302\",\n    ink: \"#F6F1EA\",\n    dim: \"#F6F1EA80\",\n    faint: \"#F6F1EA52\",\n    rule: \"#FFFFFF12\",\n    band: \"#FFFFFF0F\",\n    panel: \"rgba(14, 9, 7, 0.62)\",\n    panelShadow:\n      \"inset 0 1px 0 rgba(255,255,255,0.07), 0 0 0 1px rgba(255,255,255,0.08), 0 2px 6px rgba(0,0,0,0.3), 0 24px 60px -18px rgba(0,0,0,0.65)\",\n    ahead: \"#7DDBA3\",\n    behind: \"#FF8A7A\",\n    gold: \"#FFCF7A\",\n    flash: \"#FFB36B\",\n    flashBlend: \"screen\",\n    flashAlpha: 0.55,\n    preset: \"kiln\" as GshPresetId,\n    params: {\n      colors: [\"#4A0802\", \"#C92E0C\", \"#F2802E\", \"#FFB25E\"],\n    } as Partial<GradientParams>,\n    veilFrom: 0.72,\n    veilTo: 0.42,\n  },\n  light: {\n    stage: \"#F3EEE7\",\n    ink: \"#1A120C\",\n    dim: \"#1A120C8C\",\n    faint: \"#1A120C5C\",\n    rule: \"#0000000F\",\n    band: \"#0000000A\",\n    panel: \"rgba(255, 252, 248, 0.72)\",\n    panelShadow:\n      \"0 0 0 1px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.05), 0 20px 50px -20px rgba(60,30,10,0.25)\",\n    ahead: \"#16884A\",\n    behind: \"#C93A2B\",\n    gold: \"#A86A00\",\n    flash: \"#FFC07A\",\n    flashBlend: \"multiply\",\n    flashAlpha: 0.45,\n    preset: \"paper-crease\" as GshPresetId,\n    params: {\n      colors: [\"#FF9A4A\", \"#FFC89A\", \"#F7E4D2\", \"#6A2A10\"],\n      background: \"#F3EEE7\",\n    } as Partial<GradientParams>,\n    veilFrom: 0.6,\n    veilTo: 0.15,\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 > 9) return { x: 0, y: 0 };\n  const k = (1 - d / 9) ** 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 clockParts(sec: number) {\n  const s = Math.max(0, Math.floor(sec));\n  const h = Math.floor(s / 3600);\n  const m = Math.floor((s % 3600) / 60);\n  const r = s % 60;\n  return {\n    head: `${h}:${String(m).padStart(2, \"0\")}`,\n    tail: `:${String(r).padStart(2, \"0\")}`,\n  };\n}\n\nfunction clock(sec: number) {\n  const p = clockParts(sec);\n  return p.head + p.tail;\n}\n\nfunction delta(sec: number) {\n  const a = Math.abs(Math.round(sec));\n  const sign = sec < 0 ? \"−\" : \"+\";\n  return `${sign}${Math.floor(a / 60)}:${String(a % 60).padStart(2, \"0\")}`;\n}\n\nfunction Tabular({ text }: { text: string }) {\n  return (\n    <>\n      {text.split(\"\").map((ch, i) => (\n        <span\n          key={i}\n          style={{\n            display: \"inline-block\",\n            width: ch === \":\" ? \"0.3em\" : \"0.6em\",\n            textAlign: \"center\",\n          }}\n        >\n          {ch}\n        </span>\n      ))}\n    </>\n  );\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 SpeedrunTimer({\n  category = \"Launch video · Any%\",\n  splits = DEFAULT_SPLITS,\n  banner = \"World record\",\n  accent = \"#3B5BFD\",\n  ink,\n  background,\n  fontFamily = geist,\n  pbLabel = \"Personal best\",\n  radius: panelRadius = 18,\n  logo,\n  scale = 1,\n  delay = 0,\n  theme = \"dark\",\n  ground,\n  groundParams,\n  speed = 1,\n}: SpeedrunTimerProps) {\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 tall = H > W;\n  const u = Math.min(W / 1280, H / 720);\n\n  const n = splits.length;\n  const last = BEATS.splits[BEATS.splits.length - 1];\n  const frames = splits.map((_, i) => BEATS.splits[i] ?? last + 18 * (i - 4));\n  const finishAt = frames[n - 1];\n  const done = t >= finishAt;\n\n  const runTime = interpolate(\n    t,\n    [BEATS.run, ...frames],\n    [0, ...splits.map((s) => s.time)],\n    CLAMP,\n  );\n\n  let bump = 0;\n  frames.forEach((f, i) => {\n    bump = Math.max(bump, (i === n - 1 ? 1.3 : 0.3) * kick(t - f));\n  });\n  const hit = shake(t - finishAt, 9 * u, 1.3);\n  const camScale = 1 + 0.025 * bump;\n  const flash = done ? Math.max(0, 1 - (t - finishAt) / 4) ** 2 : 0;\n\n  let tint = 0;\n  let tintColor: string = fg;\n  frames.forEach((f, i) => {\n    const d = t - f;\n    if (d >= 0 && d < 10 && i < n - 1) {\n      tint = (1 - d / 10) ** 2;\n      tintColor = splits[i].time <= splits[i].pb ? c.ahead : c.behind;\n    }\n  });\n  const timerColor = done ? c.gold : fg;\n\n  const wr = spring({ frame: t - BEATS.banner, fps, config: CARD });\n  const blinkOff =\n    (t >= BEATS.banner + 6 && t < BEATS.banner + 8) ||\n    (t >= BEATS.banner + 11 && t < BEATS.banner + 13);\n  const wrOpacity =\n    t < BEATS.banner ? 0 : blinkOff ? 0 : ramp(t, BEATS.banner, 2);\n\n  const rise = LIGHT(ramp(t, BEATS.rise, 28));\n  const veil = c.veilFrom + (c.veilTo - c.veilFrom) * rise;\n  const groundShift = ((tall ? 0.1 : 0.08) + (1 - rise) * 0.12) * H;\n\n  const L = tall\n    ? {\n        pad: 0.07 * W,\n        headerTop: 0.07 * H,\n        panelTop: 0.135 * H,\n        panelW: 0.86 * W,\n        rowH: 0.052 * H,\n        rowFs: 0.024 * H,\n        deltaFs: 0.019 * H,\n        labelFs: 0.016 * H,\n        logoFs: 0.022 * H,\n        timerFs: 0.215 * W,\n        timerTop: 0.555 * H,\n        bannerFs: 0.072 * W,\n        bannerTop: 0.49 * H,\n        timeColW: 0.22 * W,\n        deltaColW: 0.17 * W,\n      }\n    : {\n        pad: 0.0625 * W,\n        headerTop: 0.07 * H,\n        panelTop: 0.15 * H,\n        panelW: 0.56 * W,\n        rowH: 0.074 * H,\n        rowFs: 0.036 * H,\n        deltaFs: 0.029 * H,\n        labelFs: 0.024 * H,\n        logoFs: 0.036 * H,\n        timerFs: 0.3 * H,\n        timerTop: 0.7 * H,\n        bannerFs: 0.07 * H,\n        bannerTop: 0.58 * H,\n        timeColW: 0.12 * W,\n        deltaColW: 0.1 * W,\n      };\n  const inset = 8 * u;\n  const radius = panelRadius * u;\n\n  let bandIndex = 0;\n  frames.forEach((f, i) => {\n    if (i < n - 1) bandIndex += spring({ frame: t - f, fps, config: CARD });\n  });\n  const bandOpacity =\n    ramp(t, BEATS.run - 4, 6) * (1 - LIGHT(ramp(t, finishAt, 6)));\n\n  const monoLabel: React.CSSProperties = {\n    fontFamily: mono,\n    fontWeight: 400,\n    fontSize: L.labelFs,\n    letterSpacing: \"0.04em\",\n    textTransform: \"uppercase\",\n    color: c.dim,\n    lineHeight: 1,\n  };\n\n  const panelIn = spring({ frame: t - BEATS.rowIn, fps, config: HEAVY });\n  const pbParts = clockParts(splits[n - 1]?.pb ?? 0);\n  const pbPop = spring({ frame: t - finishAt - 2, fps, config: CHIP });\n  const timerText = clock(runTime);\n\n  return (\n    <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n      {background === undefined ? (\n        <>\n          <AbsoluteFill\n            style={{\n              top: -0.3 * H,\n              height: 1.55 * H,\n              transform: `translateY(${groundShift - 0.25 * H}px) scale(1.06)`,\n            }}\n          >\n            <GshGround\n              preset={ground ?? c.preset}\n              params={groundParams ?? c.params}\n              timeOffset={5}\n              timeScale={0.4}\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(${hit.x}px, ${hit.y}px) scale(${camScale})`,\n            transformOrigin: \"60% 70%\",\n          }}\n        >\n          <div\n            style={{\n              position: \"absolute\",\n              left: L.pad,\n              right: L.pad,\n              top: L.headerTop,\n              display: \"flex\",\n              alignItems: \"center\",\n              justifyContent: \"space-between\",\n              opacity: ENTER(ramp(t, 0, 10)),\n            }}\n          >\n            <div style={{ display: \"flex\", alignItems: \"center\", gap: 16 * u }}>\n              {logo ?? <KuchiLogo fontSize={L.logoFs} color={fg} />}\n              <span style={monoLabel}>{category}</span>\n            </div>\n          </div>\n\n          {tall ? null : (\n            <div\n              style={{\n                position: \"absolute\",\n                right: L.pad,\n                top: L.panelTop + inset + 0.012 * H,\n                display: \"flex\",\n                flexDirection: \"column\",\n                alignItems: \"flex-end\",\n                gap: 0.022 * H,\n                opacity: ENTER(ramp(t, 4, 12)),\n                transform: `translateY(${(1 - panelIn) * 0.04 * H}px)`,\n              }}\n            >\n              <span style={monoLabel}>{pbLabel}</span>\n              <span\n                style={{\n                  fontFamily,\n                  fontWeight: 300,\n                  fontSize: 0.1 * H,\n                  lineHeight: 0.8,\n                  letterSpacing: \"-0.03em\",\n                  fontVariantNumeric: \"tabular-nums\",\n                  color: done ? c.faint : fg,\n                  textDecoration: done ? \"line-through\" : undefined,\n                  textDecorationThickness: 2 * u,\n                }}\n              >\n                {pbParts.head}\n                {pbParts.tail}\n              </span>\n              <span\n                style={{\n                  fontFamily: mono,\n                  fontWeight: 400,\n                  fontSize: 0.036 * H,\n                  lineHeight: 1,\n                  fontVariantNumeric: \"tabular-nums\",\n                  color: c.gold,\n                  opacity: done ? ramp(t, finishAt + 2, 3) : 0,\n                  transform: `scale(${1.3 - 0.3 * pbPop})`,\n                  transformOrigin: \"100% 50%\",\n                }}\n              >\n                {delta((splits[n - 1]?.time ?? 0) - (splits[n - 1]?.pb ?? 0))}\n              </span>\n            </div>\n          )}\n\n          <div\n            style={{\n              position: \"absolute\",\n              left: L.pad,\n              top: L.panelTop,\n              width: L.panelW,\n              padding: inset,\n              borderRadius: radius,\n              background: c.panel,\n              boxShadow: c.panelShadow,\n              backdropFilter: \"blur(18px)\",\n              WebkitBackdropFilter: \"blur(18px)\",\n              opacity: ramp(t, 0, 4),\n              transform: `translateY(${(1 - panelIn) * 0.05 * H}px)`,\n            }}\n          >\n            <div style={{ position: \"relative\", height: n * L.rowH }}>\n              <div\n                style={{\n                  position: \"absolute\",\n                  left: 0,\n                  right: 0,\n                  top: bandIndex * L.rowH,\n                  height: L.rowH,\n                  borderRadius: radius - inset,\n                  background: c.band,\n                  opacity: bandOpacity,\n                }}\n              >\n                <div\n                  style={{\n                    position: \"absolute\",\n                    left: 9 * u,\n                    top: \"28%\",\n                    bottom: \"28%\",\n                    width: 4 * u,\n                    borderRadius: 2 * u,\n                    background: accent,\n                  }}\n                />\n              </div>\n              {splits.map((s, i) => {\n                const at = frames[i];\n                const isLast = i === n - 1;\n                const completed = t >= at;\n                const inK = spring({\n                  frame: t - BEATS.rowIn - 2 - i * BEATS.rowGap,\n                  fps,\n                  config: CARD,\n                });\n                const pop = spring({ frame: t - at, fps, config: CHIP });\n                const ahead = s.time <= s.pb;\n                const deltaColor = isLast ? c.gold : ahead ? c.ahead : c.behind;\n                const rowFlash = completed\n                  ? Math.max(0, 1 - (t - at) / 12) ** 2\n                  : 0;\n                const rowInk = isLast && completed ? c.gold : fg;\n                const parts = clockParts(completed ? s.time : s.pb);\n                return (\n                  <div\n                    key={s.name}\n                    style={{\n                      position: \"absolute\",\n                      left: 0,\n                      right: 0,\n                      top: i * L.rowH,\n                      height: L.rowH,\n                      display: \"flex\",\n                      alignItems: \"center\",\n                      padding: `0 ${22 * u}px 0 ${26 * u}px`,\n                      borderTop: i === 0 ? undefined : `1px solid ${c.rule}`,\n                      opacity: ramp(t, BEATS.rowIn + 2 + i * BEATS.rowGap, 4),\n                      transform: `translateY(${(1 - inK) * 0.4 * L.rowH}px)`,\n                    }}\n                  >\n                    <div\n                      style={{\n                        position: \"absolute\",\n                        inset: 0,\n                        borderRadius: radius - inset,\n                        background: deltaColor,\n                        opacity: 0.16 * rowFlash,\n                      }}\n                    />\n                    <div\n                      style={{\n                        flex: 1,\n                        fontFamily,\n                        fontWeight: 400,\n                        fontSize: L.rowFs,\n                        letterSpacing: \"-0.01em\",\n                        color: rowInk,\n                        lineHeight: 1,\n                      }}\n                    >\n                      {s.name}\n                    </div>\n                    <div\n                      style={{\n                        width: L.deltaColW,\n                        textAlign: \"right\",\n                        fontFamily: mono,\n                        fontWeight: 400,\n                        fontSize: L.deltaFs,\n                        fontVariantNumeric: \"tabular-nums\",\n                        color: deltaColor,\n                        lineHeight: 1,\n                        opacity: completed ? ramp(t, at, 2) : 0,\n                        transform: `scale(${1.3 - 0.3 * pop})`,\n                        transformOrigin: \"100% 50%\",\n                      }}\n                    >\n                      {delta(s.time - s.pb)}\n                    </div>\n                    <div\n                      style={{\n                        width: L.timeColW,\n                        textAlign: \"right\",\n                        fontFamily,\n                        fontWeight: 400,\n                        fontSize: L.rowFs,\n                        fontVariantNumeric: \"tabular-nums\",\n                        color: completed ? rowInk : c.faint,\n                        lineHeight: 1,\n                      }}\n                    >\n                      {parts.head}\n                      <span style={{ opacity: completed ? 0.55 : 1 }}>\n                        {parts.tail}\n                      </span>\n                    </div>\n                  </div>\n                );\n              })}\n            </div>\n          </div>\n\n          <div\n            style={{\n              position: \"absolute\",\n              right: L.pad,\n              top: L.bannerTop,\n              fontFamily,\n              fontWeight: 300,\n              fontSize: L.bannerFs,\n              lineHeight: 1,\n              letterSpacing: \"0.01em\",\n              textTransform: \"uppercase\",\n              whiteSpace: \"nowrap\",\n              color: c.gold,\n              opacity: wrOpacity,\n              transform: `scale(${1.35 - 0.35 * wr})`,\n              transformOrigin: \"100% 100%\",\n              filter:\n                wr < 0.97\n                  ? `blur(${Math.max(0, 1 - wr) * 10 * u}px)`\n                  : undefined,\n            }}\n          >\n            {banner}\n          </div>\n\n          <div\n            style={{\n              position: \"absolute\",\n              right: L.pad - 0.02 * L.timerFs,\n              top: L.timerTop,\n              fontFamily,\n              fontWeight: 300,\n              fontSize: L.timerFs,\n              lineHeight: 0.8,\n              letterSpacing: \"-0.03em\",\n              color: t < BEATS.run ? c.dim : timerColor,\n              whiteSpace: \"nowrap\",\n            }}\n          >\n            <Tabular text={timerText} />\n            {tint > 0.01 ? (\n              <div\n                style={{\n                  position: \"absolute\",\n                  inset: 0,\n                  color: tintColor,\n                  opacity: tint,\n                }}\n              >\n                <Tabular text={timerText} />\n              </div>\n            ) : null}\n          </div>\n        </div>\n      </ScaleLayer>\n\n      {flash > 0.01 ? (\n        <AbsoluteFill\n          style={{\n            background: c.flash,\n            mixBlendMode: c.flashBlend,\n            opacity: c.flashAlpha * flash,\n          }}\n        />\n      ) : null}\n    </AbsoluteFill>\n  );\n}\n"}]}