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": "res-climb",
"title": "Res Climb",
"description": "A glowing number climbs in resolution-like steps to 200+ with a small caption.",
"dependencies": ["remotion", "@remotion/google-fonts"],
"files": [
{
"path": "registry/remocn/res-climb/index.tsx",
"content": "\"use client\";\n\nimport { loadFont as loadGeistMono } from \"@remotion/google-fonts/GeistMono\";\nimport { loadFont as loadOnest } from \"@remotion/google-fonts/Onest\";\nimport type React from \"react\";\nimport { useEffect, useId, 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 onest = loadOnest(\"normal\", {\n weights: [\"400\", \"500\"],\n subsets: [\"latin\"],\n});\nconst mono = loadGeistMono(\"normal\", {\n weights: [\"400\"],\n subsets: [\"latin\"],\n});\n\nexport interface ResClimbProps {\n value?: string;\n label?: string;\n eyebrow?: string;\n steps?: number[];\n accent?: string;\n background?: string;\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n dark: {\n bg: \"#050608\",\n ink: \"#F2F1EE\",\n muted: \"#8C8B92\",\n ramp: [\"#f4f7ff\", \"#8fb4ff\", \"ACCENT\", \"#3b2fa8\"],\n haze: 0.32,\n grain: 0.05,\n },\n light: {\n bg: \"#F5F4F0\",\n ink: \"#121214\",\n muted: \"#6E6C67\",\n ramp: [\"#1a1660\", \"ACCENT\", \"#5d7cff\", \"#8fb4ff\"],\n haze: 0.16,\n grain: 0.035,\n },\n} as const;\n\nconst TRACK = -0.04;\nconst SAMPLE = 400;\nconst BUILD = 12;\nconst FIRST_SNAP = 28;\nconst SNAP_GAPS = [10, 8, 6, 5];\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\ninterface Level {\n cols: number;\n rows: number;\n cell: number;\n lit: number[];\n}\n\ninterface Metrics {\n inkW: number;\n inkH: number;\n ox: number;\n oy: number;\n cap: number;\n levels: Level[];\n label: number;\n eyebrow: number;\n}\n\nfunction measure(\n value: string,\n steps: number[],\n label: string,\n eyebrow: string,\n): Metrics {\n const canvas = document.createElement(\"canvas\");\n const ctx = canvas.getContext(\"2d\", { willReadFrequently: true });\n if (!ctx) throw new Error(\"res-climb: no 2d context\");\n ctx.font = `500 ${SAMPLE}px \"${onest.fontFamily}\"`;\n ctx.letterSpacing = `${TRACK * SAMPLE}px`;\n const tm = ctx.measureText(value);\n const L = tm.actualBoundingBoxLeft;\n const R = tm.actualBoundingBoxRight;\n const A = tm.actualBoundingBoxAscent;\n const D = tm.actualBoundingBoxDescent;\n ctx.letterSpacing = \"0px\";\n const cap = ctx.measureText(\"H\").actualBoundingBoxAscent;\n const inkW = Math.max(1, Math.ceil(L + R));\n const inkH = Math.max(1, Math.ceil(A + D));\n\n canvas.width = inkW;\n canvas.height = inkH;\n ctx.font = `500 ${SAMPLE}px \"${onest.fontFamily}\"`;\n ctx.letterSpacing = `${TRACK * SAMPLE}px`;\n ctx.textBaseline = \"alphabetic\";\n ctx.fillStyle = \"#000\";\n ctx.clearRect(0, 0, inkW, inkH);\n ctx.fillText(value, L, A);\n const data = ctx.getImageData(0, 0, inkW, inkH).data;\n\n const levels = steps.map((rowsPerCap) => {\n const cell = cap / rowsPerCap;\n const cols = Math.ceil(inkW / cell);\n const rows = Math.ceil(inkH / cell);\n const lit: number[] = [];\n for (let r = 0; r < rows; r++) {\n const y0 = Math.floor(r * cell);\n const y1 = Math.min(inkH, Math.floor((r + 1) * cell));\n for (let c = 0; c < cols; c++) {\n const x0 = Math.floor(c * cell);\n const x1 = Math.min(inkW, Math.floor((c + 1) * cell));\n let sum = 0;\n let cnt = 0;\n const stride = cell > 12 ? 2 : 1;\n for (let y = y0; y < y1; y += stride)\n for (let x = x0; x < x1; x += stride) {\n sum += data[(y * inkW + x) * 4 + 3];\n cnt++;\n }\n if (cnt && sum / cnt / 255 >= 0.45) lit.push(c, r);\n }\n }\n return { cols, rows, cell: cell / SAMPLE, lit };\n });\n\n ctx.letterSpacing = \"0px\";\n ctx.font = `400 ${SAMPLE}px \"${onest.fontFamily}\"`;\n const lw = label ? ctx.measureText(label).width / SAMPLE : 0;\n ctx.font = `400 ${SAMPLE}px \"${mono.fontFamily}\"`;\n const ew = eyebrow ? ctx.measureText(eyebrow).width / SAMPLE : 0;\n\n return {\n inkW: inkW / SAMPLE,\n inkH: inkH / SAMPLE,\n ox: L / SAMPLE,\n oy: A / SAMPLE,\n cap: cap / SAMPLE,\n levels,\n label: lw,\n eyebrow: ew,\n };\n}\n\nfunction useMetrics(\n value: string,\n steps: number[],\n label: string,\n eyebrow: string,\n) {\n const [metrics, setMetrics] = useState<Metrics | null>(null);\n const [handle] = useState(() => delayRender(\"res-climb: measuring\"));\n const released = useRef(false);\n useEffect(() => {\n let live = true;\n Promise.all([\n onest.waitUntilDone(),\n mono.waitUntilDone(),\n document.fonts.load(`500 100px \"${onest.fontFamily}\"`),\n document.fonts.load(`400 100px \"${onest.fontFamily}\"`),\n document.fonts.load(`400 100px \"${mono.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n if (!live) return;\n setMetrics(measure(value, steps, label, eyebrow));\n if (!released.current) {\n released.current = true;\n continueRender(handle);\n }\n });\n return () => {\n live = false;\n };\n }, [value, steps, label, eyebrow, handle]);\n return metrics;\n}\n\nfunction hexRgb(hex: string): [number, number, number] {\n const h = hex.replace(\"#\", \"\");\n const full =\n h.length === 3\n ? h\n .split(\"\")\n .map((ch) => ch + ch)\n .join(\"\")\n : h.slice(0, 6);\n const n = Number.parseInt(full, 16);\n return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n}\n\nfunction rampAt(ramp: [number, number, number][], u: number) {\n const x = Math.max(0, Math.min(1, u)) * (ramp.length - 1);\n const i = Math.min(ramp.length - 2, Math.floor(x));\n const f = x - i;\n const a = ramp[i];\n const b = ramp[i + 1];\n return `rgb(${Math.round(a[0] + (b[0] - a[0]) * f)},${Math.round(a[1] + (b[1] - a[1]) * f)},${Math.round(a[2] + (b[2] - a[2]) * f)})`;\n}\n\nconst DEFAULT_STEPS = [7, 14, 28];\n\nexport function ResClimb({\n value = \"200+\",\n label = \"components, ready to drop in\",\n eyebrow = \"remocn registry\",\n steps = DEFAULT_STEPS,\n accent = \"#3B5BFD\",\n background,\n speed = 1,\n theme = \"dark\",\n}: ResClimbProps) {\n const t = useCurrentFrame() * speed;\n const { width: W, height: H } = useVideoConfig();\n const c = THEMES[theme];\n const stage = background ?? c.bg;\n const uid = useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n const stepList = useMemo(\n () => (steps.length ? steps.slice(0, 4) : DEFAULT_STEPS),\n [steps],\n );\n const m = useMetrics(value, stepList, label, eyebrow);\n const ramp = useMemo(\n () =>\n c.ramp.map((col) => hexRgb(col === \"ACCENT\" ? accent : col)) as [\n number,\n number,\n number,\n ][],\n [c.ramp, accent],\n );\n\n if (!m) {\n return (\n <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n );\n }\n\n const F = Math.min((H * 0.4) / m.cap, (W * (H > W ? 0.88 : 0.8)) / m.inkW);\n const inkW = m.inkW * F;\n const inkH = m.inkH * F;\n const labelGap = label ? Math.max(H * 0.05, F * 0.08) : 0;\n const labelSize = Math.min(\n H * 0.046,\n Math.max(H * 0.032, F * 0.06),\n (W * 0.86) / Math.max(0.1, m.label),\n );\n const eyebrowSize = Math.min(H * 0.026, (W * 0.8) / Math.max(0.1, m.eyebrow));\n const eyebrowGap = eyebrow ? Math.max(H * 0.045, F * 0.07) : 0;\n const blockH =\n (eyebrow ? eyebrowSize + eyebrowGap : 0) +\n inkH +\n (label ? labelGap + labelSize * 1.2 : 0);\n const top = (H - blockH) / 2 + (eyebrow ? eyebrowSize + eyebrowGap : 0);\n const left = (W - inkW) / 2;\n\n const snaps: number[] = [];\n for (let i = 0; i < m.levels.length; i++)\n snaps.push(i === 0 ? FIRST_SNAP : snaps[i - 1] + SNAP_GAPS[i - 1]);\n const crispAt = snaps[snaps.length - 1];\n const labelAt = crispAt + 3;\n let level = 0;\n for (let i = 0; i < m.levels.length - 1; i++)\n if (t >= snaps[i]) level = i + 1;\n const crisp = t >= crispAt;\n\n const push = interpolate(t, [0, crispAt + 30], [0.93, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n\n const drift = Math.sin(t / 24) * 0.04;\n const gx0 = left + inkW * (0.0 + drift);\n const gy0 = top;\n const gx1 = left + inkW * (1.0 + drift);\n const gy1 = top + inkH;\n const gdx = gx1 - gx0;\n const gdy = gy1 - gy0;\n const glen = gdx * gdx + gdy * gdy;\n const uAt = (x: number, y: number) =>\n ((x - gx0) * gdx + (y - gy0) * gdy) / glen;\n\n const lv = m.levels[level];\n const cellPx = lv.cell * F;\n const cells: React.ReactNode[] = [];\n if (!crisp) {\n for (let k = 0; k < lv.lit.length; k += 2) {\n const col = lv.lit[k];\n const row = lv.lit[k + 1];\n if (level === 0) {\n const at = (col / Math.max(1, lv.cols - 1)) * BUILD - BUILD * 0.33;\n if (t < at) continue;\n }\n const x = left + col * cellPx;\n const y = top + row * cellPx;\n cells.push(\n <rect\n key={k}\n x={x - 0.35}\n y={y - 0.35}\n width={cellPx + 0.7}\n height={cellPx + 0.7}\n fill={rampAt(ramp, uAt(x + cellPx / 2, y + cellPx / 2))}\n />,\n );\n }\n }\n\n const labelP = interpolate(t, [labelAt, labelAt + 20], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n const eyebrowP = interpolate(t, [-6, 12], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n const haze = interpolate(t, [crispAt - 4, crispAt + 24], [0.35, 1], CLAMP);\n\n const cx = W / 2;\n const cy = top + inkH / 2;\n const scale = `translate(${cx}px, ${cy}px) scale(${push}) translate(${-cx}px, ${-cy}px)`;\n\n return (\n <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n {background !== \"transparent\" ? (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n opacity: c.haze * haze,\n background: `radial-gradient(55% 48% at 50% ${((cy / H) * 100).toFixed(2)}%, ${rampAt(ramp, 0.62)} 0%, transparent 70%)`,\n }}\n />\n ) : null}\n <div style={{ position: \"absolute\", inset: 0, transform: scale }}>\n <svg\n width={W}\n height={H}\n viewBox={`0 0 ${W} ${H}`}\n style={{ position: \"absolute\", inset: 0 }}\n aria-hidden\n >\n <defs>\n <linearGradient\n id={`${uid}beam`}\n gradientUnits=\"userSpaceOnUse\"\n x1={gx0}\n y1={gy0}\n x2={gx1}\n y2={gy1}\n >\n {ramp.map((col, i) => (\n <stop\n key={`${col.join(\",\")}-${i}`}\n offset={i / (ramp.length - 1)}\n stopColor={`rgb(${col.join(\",\")})`}\n />\n ))}\n </linearGradient>\n </defs>\n {crisp ? (\n <text\n x={left + m.ox * F}\n y={top + m.oy * F}\n fill={`url(#${uid}beam)`}\n style={{\n fontFamily: onest.fontFamily,\n fontWeight: 500,\n fontSize: F,\n letterSpacing: `${TRACK}em`,\n }}\n >\n {value}\n </text>\n ) : (\n <g shapeRendering=\"crispEdges\">{cells}</g>\n )}\n </svg>\n {eyebrow ? (\n <div\n style={{\n position: \"absolute\",\n left: 0,\n width: W,\n top: top - eyebrowGap - eyebrowSize,\n textAlign: \"center\",\n fontFamily: mono.fontFamily,\n fontWeight: 400,\n fontSize: eyebrowSize,\n lineHeight: 1,\n letterSpacing: \"0.02em\",\n color: c.muted,\n opacity: eyebrowP,\n }}\n >\n {eyebrow}\n </div>\n ) : null}\n {label ? (\n <div\n style={{\n position: \"absolute\",\n left: 0,\n width: W,\n top: top + inkH + labelGap,\n textAlign: \"center\",\n fontFamily: onest.fontFamily,\n fontWeight: 400,\n fontSize: labelSize,\n lineHeight: 1.2,\n letterSpacing: \"-0.01em\",\n color: c.ink,\n opacity: labelP,\n transform: `translateY(${((1 - labelP) * labelSize * 0.6).toFixed(2)}px)`,\n }}\n >\n {label}\n </div>\n ) : null}\n </div>\n <Grain opacity={c.grain} />\n </AbsoluteFill>\n );\n}\n\nfunction Grain({ opacity }: { opacity: number }) {\n const id = `rc${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n return (\n <svg\n width=\"100%\"\n height=\"100%\"\n style={{\n position: \"absolute\",\n inset: 0,\n opacity,\n mixBlendMode: \"overlay\",\n pointerEvents: \"none\",\n }}\n aria-hidden\n >\n <filter id={id}>\n <feTurbulence\n type=\"fractalNoise\"\n baseFrequency=\"0.9\"\n numOctaves={2}\n seed={5}\n />\n <feColorMatrix type=\"saturate\" values=\"0\" />\n </filter>\n <rect width=\"100%\" height=\"100%\" filter={`url(#${id})`} />\n </svg>\n );\n}\n",
"type": "registry:component",
"target": "components/remocn/res-climb.tsx"
}
],
"type": "registry:component"
}