Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
{
"type": "remotion-element",
"version": 1,
"element": {
"assets": [],
"dependencies": [
{
"name": "@remotion/google-fonts",
"version": null
}
],
"dimensions": null,
"displayName": "Chore Fold",
"initialProps": null,
"slug": "chore-fold",
"sourceCode": "import { loadFont } from \"@remotion/google-fonts/Geologica\";\nimport React, { useEffect, useRef, useState } from \"react\";\nimport { AbsoluteFill, Easing, continueRender, delayRender, interpolate, useCurrentFrame, useVideoConfig } from \"remotion\";\n\nconst geologica = loadFont(\"normal\", {\n weights: [\"400\", \"500\"],\n subsets: [\"latin\"],\n});\n\nexport interface ChoreFoldProps {\n steps?: string[];\n label?: string;\n name?: string;\n result?: string;\n payoff?: string;\n accent?: string;\n background?: string;\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n dark: { bg: \"#0E3B43\", ink: \"#FFFFFF\", accent: \"#4FE3D0\" },\n light: { bg: \"#E8F6F5\", ink: \"#0B3138\", accent: \"#0F8C7E\" },\n} as const;\n\nconst DEFAULT_STEPS = [\n \"Export the audio.\",\n \"Send it off for a transcript.\",\n \"Fix every timestamp by hand.\",\n \"Style each line to match.\",\n \"Render the whole film again.\",\n];\n\nconst FONT_PX = 200;\nconst STEP_W = 400;\nconst HERO_W = 500;\nconst STEP_TRACK = -0.02;\nconst HERO_TRACK = -0.035;\nconst PITCH = 1.34;\nconst HERO_LH = 1.08;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_MOVE = Easing.bezier(0.65, 0, 0.35, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nconst LINE_AT = 6;\nconst LINE_GAP = 8;\nconst WORD_STAGGER = 2;\nconst WORD_IN = 13;\nconst ROUND = [17, 13, 11, 10, 9];\nconst ROUND_GAP = 3;\nconst SWAP_LEAD = 5;\nconst SWAP_OUT = 10;\nconst SWAP_IN = 18;\nconst PAYOFF_AFTER = 16;\nconst HOLD = 40;\n\ntype Metrics = Record<string, number>;\nconst key = (w: number, s: string) => `${w}\\u0002${s}`;\n\nfunction measureAll(texts: string[]): Metrics {\n const canvas = document.createElement(\"canvas\");\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) throw new Error(\"chore-fold: no 2d context\");\n const out: Metrics = {};\n for (const weight of [STEP_W, HERO_W]) {\n ctx.font = `${weight} ${FONT_PX}px \"${geologica.fontFamily}\"`;\n for (const s of texts) {\n out[key(weight, s)] = ctx.measureText(s).width / FONT_PX;\n }\n }\n return out;\n}\n\nfunction useMetrics(texts: string[]) {\n const id = texts.join(\"\\u0001\");\n const [state, setState] = useState<{ id: string; m: Metrics } | null>(null);\n const [handle] = useState(() => delayRender(\"chore-fold: measuring\"));\n const released = useRef(false);\n useEffect(() => {\n let live = true;\n Promise.all([\n geologica.waitUntilDone(),\n document.fonts.load(`${STEP_W} 100px \"${geologica.fontFamily}\"`),\n document.fonts.load(`${HERO_W} 100px \"${geologica.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n if (!live) return;\n setState({ id, m: measureAll(id.split(\"\\u0001\")) });\n if (!released.current) {\n released.current = true;\n continueRender(handle);\n }\n });\n return () => {\n live = false;\n };\n }, [id, handle]);\n return state && state.id === id ? state.m : null;\n}\n\nconst splitWords = (s: string) => s.split(/\\s+/).filter(Boolean);\n\nfunction balanced(\n words: string[],\n width: (w: string) => number,\n space: number,\n limit: number,\n) {\n const greedy = (lim: number) => {\n const lines: string[][] = [];\n let cur: string[] = [];\n let acc = 0;\n for (const w of words) {\n const ww = width(w);\n if (cur.length > 0 && acc + space + ww > lim) {\n lines.push(cur);\n cur = [w];\n acc = ww;\n } else {\n acc = cur.length > 0 ? acc + space + ww : ww;\n cur.push(w);\n }\n }\n if (cur.length > 0) lines.push(cur);\n return lines;\n };\n const count = greedy(limit).length;\n let lo = 0;\n let hi = limit;\n for (let i = 0; i < 18; i++) {\n const mid = (lo + hi) / 2;\n if (greedy(mid).length <= count) hi = mid;\n else lo = mid;\n }\n return greedy(hi);\n}\n\nexport function ChoreFold({\n steps = DEFAULT_STEPS,\n label = \"By hand\",\n name = \"Captions\",\n result = \"does all of that.\",\n payoff = \"You just talk.\",\n accent,\n background,\n speed = 1,\n theme = \"dark\",\n}: ChoreFoldProps) {\n const t = useCurrentFrame() * speed;\n const { width: W, height: H, durationInFrames } = useVideoConfig();\n const c = THEMES[theme];\n const hi = accent ?? c.accent;\n const stage =\n background === \"transparent\" ? \"transparent\" : (background ?? c.bg);\n\n const list = steps.length > 0 ? steps : DEFAULT_STEPS;\n const heroWords = [\n ...splitWords(name).map((w) => ({ w, lit: true })),\n ...splitWords(result).map((w) => ({ w, lit: false })),\n ];\n const m = useMetrics([\n \" \",\n ...list,\n ...list.flatMap(splitWords),\n ...heroWords.map((h) => h.w),\n payoff,\n ...splitWords(payoff),\n label,\n ]);\n\n if (!m) {\n return (\n <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n );\n }\n\n const n = list.length;\n const portrait = H > W * 1.1;\n const measureW = W * (portrait ? 0.84 : 0.8);\n\n const sW = (s: string) =>\n m[key(STEP_W, s)] + STEP_TRACK * Array.from(s).length;\n const hW = (s: string) =>\n m[key(HERO_W, s)] + HERO_TRACK * Array.from(s).length;\n\n const widest = Math.max(...list.map(sW));\n const capF = H * (portrait ? 0.05 : 0.1);\n const fitH = (H * (portrait ? 0.56 : 0.8)) / (n * PITCH);\n const F = Math.min(capF, measureW / widest, fitH);\n const pitch = F * PITCH;\n\n const heroCap = F * (portrait ? 2 : 1.45);\n let heroF = heroCap;\n let heroLines: { w: string; lit: boolean }[][] = [heroWords];\n for (let i = 0; i < 40; i++) {\n const words = heroWords.map((h) => h.w);\n const lines = balanced(words, hW, hW(\" \"), measureW / heroF);\n if (lines.length <= (portrait ? 3 : 2) || i === 39) {\n let idx = 0;\n heroLines = lines.map((line) => line.map(() => heroWords[idx++]));\n break;\n }\n heroF *= 0.95;\n }\n\n const ease = (from: number, dur: number, curve = EASE_OUT) =>\n interpolate(t, [from, from + dur], [0, 1], { ...CLAMP, easing: curve });\n\n const D = (n - 1) / 2;\n const rounds = Math.max(1, Math.ceil(D));\n const roundDur = (r: number) => ROUND[Math.min(r, ROUND.length - 1)];\n let foldLen = 0;\n for (let r = 0; r < rounds; r++) foldLen += roundDur(r) + ROUND_GAP;\n\n const linesDone = LINE_AT + (n - 1) * LINE_GAP + 16;\n const tail = foldLen + SWAP_LEAD + SWAP_IN + PAYOFF_AFTER + 14 + HOLD;\n const span = durationInFrames * speed;\n const read = Math.min(70, Math.max(18, span - linesDone - tail));\n const foldAt = linesDone + read;\n\n let p = 0;\n let cursor = foldAt;\n for (let r = 0; r < rounds; r++) {\n const step = Math.min(1, D - r);\n p += step * ease(cursor, roundDur(r), EASE_MOVE);\n cursor += roundDur(r) + ROUND_GAP;\n }\n const foldEnd = cursor;\n const swapAt = foldEnd + SWAP_LEAD - ROUND_GAP;\n const heroAt = swapAt + 4;\n const payoffAt = heroAt + PAYOFF_AFTER;\n\n const cy = H * (portrait ? 0.47 : 0.48);\n const ys = list.map((_, i) => {\n const sign = i - D < 0 ? -1 : 1;\n const d = Math.abs(i - D);\n return cy + sign * Math.min(d, Math.max(0, D - p)) * pitch;\n });\n\n const nodes: React.ReactNode[] = [];\n\n if (label) {\n const lin = ease(2, 12);\n const lout = ease(foldAt, 10);\n const labelF = Math.max(12, F * 0.46);\n const top = cy - D * pitch - pitch / 2 - labelF * 1.6;\n const pull = p * pitch * 0.5;\n nodes.push(\n <div\n key=\"label\"\n style={{\n position: \"absolute\",\n left: 0,\n width: W,\n top: top + pull,\n textAlign: \"center\",\n fontFamily: geologica.fontFamily,\n fontWeight: STEP_W,\n fontSize: labelF,\n lineHeight: 1,\n color: hi,\n opacity: lin * (1 - lout),\n transform: `translateY(${((1 - lin) * labelF * 0.6).toFixed(2)}px)`,\n whiteSpace: \"pre\",\n }}\n >\n {label}\n </div>,\n );\n }\n\n const swapOut = ease(swapAt, SWAP_OUT, EASE_MOVE);\n const centre = Math.ceil(D);\n\n list.forEach((line, i) => {\n const enter = LINE_AT + i * LINE_GAP;\n if (t < enter - 1) return;\n const y = ys[i];\n let clipTop = 0;\n let clipBottom = 0;\n if (i - D < 0 && i + 1 < n) {\n clipBottom = Math.max(0, y + pitch / 2 - (ys[i + 1] - pitch / 2));\n } else if (i - 1 - D >= 0) {\n clipTop = Math.max(0, ys[i - 1] + pitch / 2 - (y - pitch / 2));\n }\n const hidden = (clipTop + clipBottom) / pitch;\n if (hidden >= 0.98) return;\n const tuck = 1 - interpolate(hidden, [0.04, 0.5], [0, 1], CLAMP);\n const lastStanding = i === centre;\n const out = lastStanding ? swapOut : 0;\n if (out >= 1) return;\n const words = splitWords(line);\n nodes.push(\n <div\n key={`step-${i}-${line}`}\n style={{\n position: \"absolute\",\n left: 0,\n top: y - pitch / 2,\n width: W,\n height: pitch,\n clipPath: `inset(${clipTop.toFixed(2)}px 0px ${clipBottom.toFixed(2)}px 0px)`,\n overflow: \"hidden\",\n }}\n >\n <div\n style={{\n width: \"100%\",\n textAlign: \"center\",\n fontFamily: geologica.fontFamily,\n fontWeight: STEP_W,\n fontSize: F,\n letterSpacing: `${STEP_TRACK}em`,\n lineHeight: `${pitch}px`,\n color: c.ink,\n whiteSpace: \"pre\",\n opacity: (1 - out) * tuck,\n transform: `translateY(${(-out * pitch * 0.7).toFixed(2)}px)`,\n }}\n >\n {words.map((w, wi) => {\n const e = ease(enter + wi * WORD_STAGGER, WORD_IN);\n return (\n <span\n key={`${w}-${wi}`}\n style={{\n display: \"inline-block\",\n opacity: e,\n transform: `translateY(${((1 - e) * pitch * 0.7).toFixed(2)}px)`,\n }}\n >\n {wi > 0 ? ` ${w}` : w}\n </span>\n );\n })}\n </div>\n </div>,\n );\n });\n\n if (t >= heroAt - 1) {\n const lh = heroF * HERO_LH;\n const blockH = heroLines.length * lh;\n const top = cy - blockH / 2;\n let wordIndex = 0;\n nodes.push(\n <div\n key=\"hero\"\n style={{\n position: \"absolute\",\n left: 0,\n width: W,\n top: top - heroF * 0.1,\n height: blockH + heroF * 0.3,\n overflow: \"hidden\",\n textAlign: \"center\",\n fontFamily: geologica.fontFamily,\n fontWeight: HERO_W,\n fontSize: heroF,\n letterSpacing: `${HERO_TRACK}em`,\n lineHeight: `${lh}px`,\n paddingTop: heroF * 0.1,\n whiteSpace: \"pre\",\n zIndex: 20,\n }}\n >\n {heroLines.map((line) => (\n <div key={line.map((h) => h.w).join(\" \")}>\n {line.map((h, wi) => {\n const e = ease(heroAt + wordIndex++ * WORD_STAGGER, SWAP_IN);\n return (\n <span\n key={`${h.w}-${wi}`}\n style={{\n display: \"inline-block\",\n color: h.lit ? hi : c.ink,\n transform: `translateY(${((1 - e) * blockH * 1.1).toFixed(2)}px)`,\n }}\n >\n {wi > 0 ? ` ${h.w}` : h.w}\n </span>\n );\n })}\n </div>\n ))}\n </div>,\n );\n\n if (payoff) {\n const pf = Math.max(12, Math.min(heroF * 0.5, F * 0.95));\n const pin = ease(payoffAt, 16);\n nodes.push(\n <div\n key=\"payoff\"\n style={{\n position: \"absolute\",\n left: 0,\n width: W,\n top: top + blockH + pf * 0.9,\n textAlign: \"center\",\n fontFamily: geologica.fontFamily,\n fontWeight: STEP_W,\n fontSize: pf,\n letterSpacing: `${STEP_TRACK}em`,\n lineHeight: 1.2,\n color: c.ink,\n opacity: pin * 0.72,\n transform: `translateY(${((1 - pin) * pf * 0.6).toFixed(2)}px)`,\n whiteSpace: \"pre\",\n }}\n >\n {payoff}\n </div>,\n );\n }\n }\n\n return (\n <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n {nodes}\n </AbsoluteFill>\n );\n}",
"durationInFrames": 146,
"installationMode": "wrapped"
},
"durationInFrames": 146
}