Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
{
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
"name": "pitch-over",
"title": "Pitch Over",
"description": "A large number counts to 7,200 with a ruler of ticks and a marker sliding beneath it.",
"dependencies": ["remotion", "@remotion/google-fonts"],
"files": [
{
"path": "registry/remocn/pitch-over/index.tsx",
"content": "\"use client\";\n\nimport { loadFont as loadSpaceGrotesk } from \"@remotion/google-fonts/SpaceGrotesk\";\nimport { loadFont as loadSpaceMono } from \"@remotion/google-fonts/SpaceMono\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n AbsoluteFill,\n continueRender,\n delayRender,\n Easing,\n interpolate,\n useCurrentFrame,\n useVideoConfig,\n} from \"remotion\";\n\nconst grotesk = loadSpaceGrotesk(\"normal\", {\n weights: [\"400\"],\n subsets: [\"latin\"],\n});\nconst mono = loadSpaceMono(\"normal\", {\n weights: [\"400\"],\n subsets: [\"latin\"],\n});\n\nexport interface PitchOverProps {\n value?: number;\n from?: number;\n decimals?: number;\n prefix?: string;\n suffix?: string;\n label?: string;\n accent?: string;\n background?: string;\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n dark: { bg: \"#000000\", ink: \"#FFFFFF\", dim: \"rgba(255,255,255,0.28)\" },\n light: { bg: \"#FFFFFF\", ink: \"#000000\", dim: \"rgba(0,0,0,0.26)\" },\n} as const;\n\nconst TRACK = -0.03;\nconst PROBE_PX = 200;\n\nconst ENTER_END = 10;\nconst COUNT_END = 46;\nconst PITCH_AT = 42;\nconst PITCH_LEN = 34;\nconst LABEL_AT = 70;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_COUNT = Easing.bezier(0.25, 0.6, 0.25, 1);\nconst EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);\nconst EASE_TURN = Easing.bezier(0.6, 0, 0.28, 1.06);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\ninterface Metrics {\n digit: number;\n comma: number;\n dot: number;\n prefix: number;\n suffix: number;\n cap: number;\n base: number;\n label: number;\n}\n\nfunction format(v: number, decimals: number) {\n return v.toLocaleString(\"en-US\", {\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n });\n}\n\nfunction measure(prefix: string, suffix: string, label: string): Metrics {\n const probe = document.createElement(\"span\");\n Object.assign(probe.style, {\n position: \"absolute\",\n left: \"-99999px\",\n top: \"0\",\n visibility: \"hidden\",\n whiteSpace: \"pre\",\n fontFamily: `\"${grotesk.fontFamily}\"`,\n fontWeight: \"400\",\n fontSize: `${PROBE_PX}px`,\n lineHeight: \"1\",\n fontVariantNumeric: \"tabular-nums\",\n letterSpacing: `${TRACK}em`,\n });\n document.body.appendChild(probe);\n const w = (s: string) => {\n if (!s) return 0;\n probe.textContent = s;\n return probe.getBoundingClientRect().width / PROBE_PX;\n };\n const digit = w(\"0000000000\") / 10;\n const comma = w(\",\");\n const dot = w(\".\");\n const pre = w(prefix);\n const suf = w(suffix);\n probe.remove();\n\n let cap = 0.7;\n let base = 0.8;\n let labelW = 0;\n const ctx = document.createElement(\"canvas\").getContext(\"2d\");\n if (ctx) {\n ctx.font = `400 ${PROBE_PX}px \"${grotesk.fontFamily}\"`;\n const m = ctx.measureText(\"0\");\n const asc = m.fontBoundingBoxAscent / PROBE_PX;\n const desc = m.fontBoundingBoxDescent / PROBE_PX;\n cap = m.actualBoundingBoxAscent / PROBE_PX;\n base = (1 - (asc + desc)) / 2 + asc;\n ctx.font = `400 ${PROBE_PX}px \"${mono.fontFamily}\"`;\n labelW = label ? ctx.measureText(label).width / PROBE_PX : 0;\n }\n return {\n digit,\n comma,\n dot,\n prefix: pre,\n suffix: suf,\n cap,\n base,\n label: labelW,\n };\n}\n\nfunction useMetrics(prefix: string, suffix: string, label: string) {\n const key = [prefix, suffix, label].join(\"\\u0001\");\n const [state, setState] = useState<{ key: string; m: Metrics } | null>(null);\n const [handle] = useState(() => delayRender(\"pitch-over: measuring\"));\n const released = useRef(false);\n useEffect(() => {\n let live = true;\n const [p, s, l] = key.split(\"\\u0001\");\n Promise.all([\n grotesk.waitUntilDone(),\n mono.waitUntilDone(),\n document.fonts.load(`400 100px \"${grotesk.fontFamily}\"`),\n document.fonts.load(`400 100px \"${mono.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n if (!live) return;\n setState({ key, m: measure(p, s, l) });\n if (!released.current) {\n released.current = true;\n continueRender(handle);\n }\n });\n return () => {\n live = false;\n };\n }, [key, handle]);\n return state && state.key === key ? state.m : null;\n}\n\nexport function PitchOver({\n value = 7200,\n from = 0,\n decimals = 0,\n prefix = \"\",\n suffix = \"\",\n label = \"Frames rendered, T+04:00\",\n accent,\n background,\n speed = 1,\n theme = \"dark\",\n}: PitchOverProps) {\n const t = useCurrentFrame() * speed;\n const { width: W, height: H } = useVideoConfig();\n const c = THEMES[theme];\n const mark = accent ?? c.ink;\n const m = useMetrics(prefix, suffix, label);\n const finalText = useMemo(\n () => `${prefix}${format(value, decimals)}${suffix}`,\n [prefix, value, decimals, suffix],\n );\n\n const transparent = background === \"transparent\";\n const stage = transparent ? \"transparent\" : (background ?? c.bg);\n\n if (!m) {\n return (\n <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n );\n }\n\n const widthOf = (text: string) => {\n let w = m.prefix + m.suffix;\n const body = text.slice(prefix.length, text.length - suffix.length);\n for (const ch of body) {\n if (ch === \",\") w += m.comma;\n else if (ch === \".\") w += m.dot;\n else w += m.digit;\n }\n return w;\n };\n\n const portrait = H > W * 1.1;\n const minDim = Math.min(W, H);\n const marginX = W * (portrait ? 0.08 : 0.07);\n const marginY = H * (portrait ? 0.08 : 0.11);\n const finalEm = widthOf(finalText);\n\n const F = Math.min(\n (W * (portrait ? 0.84 : 0.62)) / finalEm,\n (H * (portrait ? 0.16 : 0.36)) / m.cap,\n );\n const rulerLen = Math.max(finalEm * F, W * (portrait ? 0.84 : 0.5));\n const capH = m.cap * F;\n const gap = F * 0.14;\n const tickMajor = Math.max(10, F * 0.07);\n const tickMinor = tickMajor * 0.45;\n const labelFs = Math.max(minDim * 0.026, Math.min(minDim * 0.036, F * 0.1));\n const labelTop = gap + tickMajor + labelFs * 0.9;\n const below = labelTop + labelFs * 1.3;\n const stroke = Math.max(1, minDim * 0.0018);\n\n const kV = Math.min(\n portrait ? 1.5 : 1,\n (H - marginY * 2) / rulerLen,\n (W * (portrait ? 0.62 : 0.4)) / (capH + below),\n );\n\n const enter = interpolate(t, [0, ENTER_END], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n const g = interpolate(t, [0, COUNT_END], [0, 1], {\n ...CLAMP,\n easing: EASE_COUNT,\n });\n const count = from + (value - from) * g;\n const text = `${prefix}${format(\n Math.round(count * 10 ** decimals) / 10 ** decimals,\n decimals,\n )}${suffix}`;\n\n const move = interpolate(t, [PITCH_AT, PITCH_AT + PITCH_LEN], [0, 1], {\n ...CLAMP,\n easing: EASE_IO,\n });\n const turn = interpolate(t, [PITCH_AT, PITCH_AT + PITCH_LEN], [0, 1], {\n ...CLAMP,\n easing: EASE_TURN,\n });\n const angle = -90 * (1 - turn);\n const k = kV + (1 - kV) * move;\n\n const vx = marginX + capH * kV;\n const vy = H - marginY;\n const hx = marginX;\n const hy = H - marginY - below;\n const px = vx + (hx - vx) * move;\n const py = vy + (hy - vy) * move + (1 - enter) * H * 0.05;\n\n const majors = 10;\n const minors = 50;\n const reach = g * rulerLen;\n const ticks: { x: number; major: boolean }[] = [];\n for (let i = 0; i <= minors; i++) {\n ticks.push({\n x: (i / minors) * rulerLen,\n major: i % (minors / majors) === 0,\n });\n }\n const labelP = interpolate(t, [LABEL_AT, LABEL_AT + 16], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n const notch = tickMajor * 0.9;\n\n return (\n <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n <div\n style={{\n position: \"absolute\",\n left: px,\n top: py,\n width: 0,\n height: 0,\n transformOrigin: \"0 0\",\n transform: `rotate(${angle.toFixed(3)}deg) scale(${k.toFixed(4)})`,\n opacity: enter,\n }}\n >\n <div\n style={{\n position: \"absolute\",\n left: 0,\n top: -m.base * F,\n height: F,\n lineHeight: `${F}px`,\n whiteSpace: \"pre\",\n fontFamily: grotesk.fontFamily,\n fontWeight: 400,\n fontSize: F,\n fontVariantNumeric: \"tabular-nums\",\n letterSpacing: `${TRACK}em`,\n color: c.ink,\n }}\n >\n {text}\n </div>\n <svg\n width={rulerLen + notch * 2}\n height={below}\n viewBox={`${-notch} 0 ${rulerLen + notch * 2} ${below}`}\n style={{\n position: \"absolute\",\n left: -notch,\n top: 0,\n overflow: \"visible\",\n }}\n aria-hidden\n >\n <line\n x1={0}\n x2={rulerLen}\n y1={gap}\n y2={gap}\n stroke={c.dim}\n strokeWidth={stroke}\n />\n <line\n x1={0}\n x2={reach}\n y1={gap}\n y2={gap}\n stroke={c.ink}\n strokeWidth={stroke}\n />\n {ticks.map((tk) => (\n <line\n key={tk.x}\n x1={tk.x}\n x2={tk.x}\n y1={gap}\n y2={gap + (tk.major ? tickMajor : tickMinor)}\n stroke={tk.x <= reach + 0.5 ? c.ink : c.dim}\n strokeWidth={stroke}\n />\n ))}\n <path\n d={`M${reach.toFixed(2)} ${gap.toFixed(2)} l${(-notch / 2).toFixed(2)} ${(-notch * 0.8).toFixed(2)} h${notch.toFixed(2)} Z`}\n fill={mark}\n />\n </svg>\n {label ? (\n <div\n style={{\n position: \"absolute\",\n left: 0,\n top: labelTop,\n whiteSpace: \"pre\",\n fontFamily: mono.fontFamily,\n fontWeight: 400,\n fontSize: labelFs,\n lineHeight: 1,\n color: c.ink,\n opacity: labelP,\n }}\n >\n {label}\n </div>\n ) : null}\n </div>\n </AbsoluteFill>\n );\n}\n",
"type": "registry:component",
"target": "components/remocn/pitch-over.tsx"
}
],
"type": "registry:component"
}