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": "slim-count",
"title": "Slim Count",
"description": "A slim outlined zero counts down beside a condensed line, 'Keyframes left to set by hand'.",
"dependencies": ["remotion", "@remotion/google-fonts"],
"files": [
{
"path": "registry/remocn/slim-count/index.tsx",
"content": "\"use client\";\n\nimport { loadFont as loadAnton } from \"@remotion/google-fonts/Anton\";\nimport { useEffect, useRef, useState } from \"react\";\nimport {\n AbsoluteFill,\n continueRender,\n delayRender,\n Easing,\n interpolate,\n useCurrentFrame,\n useVideoConfig,\n} from \"remotion\";\n\nconst anton = loadAnton(\"normal\", { weights: [\"400\"], subsets: [\"latin\"] });\n\nexport interface SlimCountProps {\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: {\n bg: \"#1B2A6B\",\n ink: \"#F3E9D2\",\n },\n light: {\n bg: \"#F3E9D2\",\n ink: \"#1B2A6B\",\n },\n} as const;\n\nconst RISE_LEN = 16;\nconst LABEL_AT = 6;\nconst COUNT_AT = 24;\nconst COUNT_END = 84;\nconst WAVE_POINTS = 48;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_COUNT = Easing.bezier(0.42, 0, 0.12, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\ninterface Metrics {\n baseline: number;\n cap: 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(): Metrics {\n let baseline = 0.8;\n let cap = 0.72;\n const canvas = document.createElement(\"canvas\");\n canvas.width = 400;\n canvas.height = 400;\n const ctx = canvas.getContext(\"2d\");\n if (ctx) {\n ctx.font = `400 200px \"${anton.fontFamily}\"`;\n const fm = ctx.measureText(\"0123456789\");\n const asc = fm.fontBoundingBoxAscent / 200;\n const desc = fm.fontBoundingBoxDescent / 200;\n baseline = (1 - (asc + desc)) / 2 + asc;\n cap = fm.actualBoundingBoxAscent / 200;\n }\n return { baseline, cap };\n}\n\nfunction useMetrics() {\n const [m, setM] = useState<Metrics | null>(null);\n const [handle] = useState(() => delayRender(\"slim-count: measuring\"));\n const released = useRef(false);\n useEffect(() => {\n let live = true;\n Promise.all([\n anton.waitUntilDone(),\n document.fonts.load(`400 100px \"${anton.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n if (!live) return;\n setM(measure());\n if (!released.current) {\n released.current = true;\n continueRender(handle);\n }\n });\n return () => {\n live = false;\n };\n }, [handle]);\n return m;\n}\n\nfunction digitCount(v: number, decimals: number) {\n return Array.from(format(v, decimals)).length;\n}\n\nexport function SlimCount({\n value = 0,\n from = 100,\n decimals = 0,\n prefix = \"\",\n suffix = \"\",\n label = \"Keyframes left to set by hand\",\n accent,\n background,\n speed = 1,\n theme = \"dark\",\n}: SlimCountProps) {\n const t = useCurrentFrame() * speed;\n const { width: W, height: H } = useVideoConfig();\n const c = THEMES[theme];\n const fill = accent ?? c.ink;\n const m = useMetrics();\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 progress = (f: number) =>\n interpolate(f, [COUNT_AT, COUNT_END], [0, 1], {\n ...CLAMP,\n easing: EASE_COUNT,\n });\n const k = progress(t);\n const v = from + (value - from) * k;\n const q = 10 ** decimals;\n const text = `${prefix}${format(Math.round(v * q) / q, decimals)}${suffix}`;\n\n const portrait = H > W * 1.1;\n const M = Math.min(W, H) * (portrait ? 0.08 : 0.075);\n const chars =\n Math.max(digitCount(from, decimals), digitCount(value, decimals)) +\n Array.from(prefix + suffix).length;\n const F = Math.min(\n (H * (portrait ? 0.4 : 0.74)) / m.cap,\n (W * (portrait ? 0.84 : 0.58)) / Math.max(0.5, chars * 0.47),\n );\n const capPx = m.cap * F;\n const baseY = portrait ? H - M * 2.2 : H / 2 + capPx / 2 + H * 0.04;\n const boxTop = baseY - m.baseline * F;\n const baseLocal = m.baseline * F;\n\n const level = 1 - k;\n const surge = Math.abs(progress(t + 1) - progress(t - 1)) * 20;\n const amp = capPx * (0.006 + Math.min(0.03, surge * 0.02));\n const phase = (t / 30) * Math.PI * 2 * 0.7;\n const levelY =\n baseLocal -\n (capPx + capPx * 0.06) * level +\n (level >= 0.999 ? -amp * 3 : 0);\n const pts: string[] = [];\n for (let i = 0; i <= WAVE_POINTS; i++) {\n const u = i / WAVE_POINTS;\n const y = levelY + amp * Math.sin(u * Math.PI * 2 * 2.2 + phase);\n pts.push(`${(u * 100).toFixed(2)}% ${y.toFixed(2)}px`);\n }\n const clip =\n level <= 0.0005\n ? \"inset(100% 0 0 0)\"\n : `polygon(${pts.join(\", \")}, 100% 100%, 0% 100%)`;\n\n const rise = interpolate(t, [0, RISE_LEN], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n const strokeW = Math.max(2, F * 0.011);\n const labelSize = portrait ? W * 0.1 : H * 0.094;\n const words = label ? label.split(\" \") : [];\n\n const numberStyle = {\n position: \"absolute\" as const,\n right: 0,\n top: 0,\n height: F,\n lineHeight: `${F}px`,\n whiteSpace: \"pre\" as const,\n fontFamily: anton.fontFamily,\n fontWeight: 400,\n fontSize: F,\n letterSpacing: \"0.005em\",\n fontVariantNumeric: \"tabular-nums\",\n };\n\n return (\n <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n <div\n style={{\n position: \"absolute\",\n left: 0,\n width: W,\n top: baseY - capPx - F * 0.1,\n height: capPx + F * 0.16,\n overflow: \"hidden\",\n }}\n >\n <div\n style={{\n position: \"absolute\",\n right: M,\n left: 0,\n top: boxTop - (baseY - capPx - F * 0.1),\n height: F,\n transform: `translateY(${((1 - rise) * capPx * 1.15).toFixed(2)}px)`,\n }}\n >\n <div\n style={{\n ...numberStyle,\n color: fill,\n clipPath: clip,\n }}\n >\n {text}\n </div>\n <div\n style={{\n ...numberStyle,\n color: \"transparent\",\n WebkitTextStroke: `${strokeW.toFixed(2)}px ${c.ink}`,\n }}\n >\n {text}\n </div>\n </div>\n </div>\n {label ? (\n <div\n style={{\n position: \"absolute\",\n left: M,\n top: M,\n width: portrait ? W - M * 2 : W * 0.34,\n fontFamily: anton.fontFamily,\n fontWeight: 400,\n fontSize: labelSize,\n lineHeight: 1.02,\n letterSpacing: \"0.005em\",\n color: c.ink,\n }}\n >\n {words.map((w, i) => {\n const p = interpolate(\n t,\n [LABEL_AT + i * 3, LABEL_AT + i * 3 + 16],\n [0, 1],\n { ...CLAMP, easing: EASE_OUT },\n );\n return (\n <span key={`${w}-${i}`}>\n <span\n style={{\n display: \"inline-block\",\n opacity: p,\n transform: `translateY(${((1 - p) * labelSize * 0.5).toFixed(2)}px)`,\n }}\n >\n {w}\n </span>\n {i < words.length - 1 ? \" \" : \"\"}\n </span>\n );\n })}\n </div>\n ) : null}\n </AbsoluteFill>\n );\n}\n",
"type": "registry:component",
"target": "components/remocn/slim-count.tsx"
}
],
"type": "registry:component"
}