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": "Crew of One",
"initialProps": null,
"slug": "crew-of-one",
"sourceCode": "import { loadFont } from \"@remotion/google-fonts/Gabarito\";\nimport React, { useEffect, useRef, useState } from \"react\";\nimport { AbsoluteFill, Easing, continueRender, delayRender, interpolate, useCurrentFrame, useVideoConfig } from \"remotion\";\n\nconst gabarito = loadFont(\"normal\", {\n weights: [\"400\", \"500\"],\n subsets: [\"latin\"],\n});\n\nexport interface CrewOfOneProps {\n roles?: string[];\n name?: string;\n accent?: string;\n background?: string;\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n dark: { bg: \"#3B1E6E\", ink: \"#FFFFFF\", accent: \"#FF7A6B\" },\n light: { bg: \"#EDE7FB\", ink: \"#3B1E6E\", accent: \"#D9483A\" },\n} as const;\n\nconst ROLE_W = 400;\nconst NAME_W = 500;\nconst TRACK = -0.02;\nconst NAME_TRACK = -0.03;\nconst FONT_PX = 200;\nconst NAME_SCALE = 2.3;\nconst LINE = 1.32;\nconst STACK_LINE = 1.06;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\ninterface Metrics {\n roles: number;\n name: number;\n asc: number;\n desc: number;\n}\n\nfunction measure(roles: string[], name: string): Metrics {\n const canvas = document.createElement(\"canvas\");\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) throw new Error(\"crew-of-one: no 2d context\");\n ctx.font = `${ROLE_W} ${FONT_PX}px \"${gabarito.fontFamily}\"`;\n let widest = 0.1;\n for (const r of roles) {\n widest = Math.max(\n widest,\n ctx.measureText(r).width / FONT_PX + TRACK * Array.from(r).length,\n );\n }\n const fm = ctx.measureText(\"Hxg\");\n ctx.font = `${NAME_W} ${FONT_PX}px \"${gabarito.fontFamily}\"`;\n const nameW =\n ctx.measureText(name).width / FONT_PX +\n NAME_TRACK * Array.from(name).length;\n return {\n roles: widest,\n name: nameW,\n asc: fm.fontBoundingBoxAscent / FONT_PX,\n desc: fm.fontBoundingBoxDescent / FONT_PX,\n };\n}\n\nfunction useMetrics(roles: string[], name: string) {\n const key = [name, ...roles].join(\"\\u0001\");\n const [state, setState] = useState<{ key: string; m: Metrics } | null>(null);\n const [handle] = useState(() => delayRender(\"crew-of-one: measuring\"));\n const released = useRef(false);\n useEffect(() => {\n let live = true;\n Promise.all([\n gabarito.waitUntilDone(),\n document.fonts.load(`${ROLE_W} 100px \"${gabarito.fontFamily}\"`),\n document.fonts.load(`${NAME_W} 100px \"${gabarito.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n if (!live) return;\n const [n, ...rs] = key.split(\"\\u0001\");\n setState({ key, m: measure(rs, n) });\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 CrewOfOne({\n roles = [\n \"Written by\",\n \"Directed by\",\n \"Edited by\",\n \"Motion by\",\n \"Captions by\",\n \"Shipped by\",\n ],\n name = \"you\",\n accent,\n background,\n speed = 1,\n theme = \"dark\",\n}: CrewOfOneProps) {\n const frame = useCurrentFrame();\n const { width: W, height: H, durationInFrames } = useVideoConfig();\n const t = frame * speed;\n const D = Math.max(90, durationInFrames);\n const c = THEMES[theme];\n const hi = accent ?? c.accent;\n const stage =\n background === \"transparent\" ? \"transparent\" : (background ?? c.bg);\n const list = roles.length > 0 ? roles : [\"Made by\"];\n const m = useMetrics(list, name);\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 margin = W * (portrait ? 0.07 : 0.06);\n const gap = W * (portrait ? 0.035 : 0.025);\n const gutter = W * (portrait ? 0.56 : 0.54);\n const leftRoom = gutter - gap / 2 - margin;\n const rightRoom = W - margin - (gutter + gap / 2);\n const stackFit = (H * 0.86) / (n * STACK_LINE);\n const F = Math.min(\n H * (portrait ? 0.055 : 0.13),\n leftRoom / m.roles,\n rightRoom / (m.name * NAME_SCALE),\n stackFit,\n );\n const NF = F * NAME_SCALE;\n const mid = H / 2;\n const baseline = mid + F * 0.36;\n const top = (base: number, size: number) =>\n base - ((1 - m.asc - m.desc) / 2 + m.asc) * size;\n\n const introEnd = 18;\n const rollStart = 30;\n const rollEnd = Math.max(rollStart + (n - 1) * 10, D * 0.6);\n const step = n > 1 ? (rollEnd - rollStart) / (n - 1) : 1;\n const move = Math.min(13, step * 0.55);\n let p = 0;\n for (let k = 1; k < n; k++) {\n const s = rollStart + (k - 1) * step + (step - move);\n p += interpolate(t, [s, s + move], [0, 1], { ...CLAMP, easing: EASE_IO });\n }\n const cStart = rollEnd + 12;\n const cLen = 24;\n const gather = interpolate(t, [cStart, cStart + cLen], [0, 1], {\n ...CLAMP,\n easing: EASE_IO,\n });\n const intro = interpolate(t, [0, introEnd], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n const nameIn = interpolate(t, [8, 26], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n\n const LS = F * LINE;\n const LS2 = F * STACK_LINE;\n const stackTop = -((n - 1) / 2) * LS2;\n\n const roleStyle: React.CSSProperties = {\n position: \"absolute\",\n right: W - (gutter - gap / 2),\n height: F,\n lineHeight: `${F}px`,\n whiteSpace: \"pre\",\n fontFamily: gabarito.fontFamily,\n fontWeight: ROLE_W,\n fontSize: F,\n letterSpacing: `${TRACK}em`,\n color: c.ink,\n textAlign: \"right\",\n };\n\n const nodes: React.ReactNode[] = list.map((r, i) => {\n const d = i - p;\n const rollY = d * LS + (1 - intro) * LS * 0.9;\n const stackY = stackTop + i * LS2;\n const y = rollY + (stackY - rollY) * gather;\n const ad = Math.abs(d);\n const rollA =\n interpolate(ad, [0, 0.55, 1, 2.6], [1, 0.42, 0.3, 0], CLAMP) * intro;\n const a = rollA + (1 - rollA) * gather;\n return (\n <div\n key={`r${i}`}\n style={{\n ...roleStyle,\n top: top(baseline + y, F),\n opacity: a,\n }}\n >\n {r}\n </div>\n );\n });\n\n const nameTop = top(baseline, NF);\n return (\n <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n {nodes}\n <div\n style={{\n position: \"absolute\",\n left: gutter + gap / 2,\n top: nameTop - NF * 0.15,\n height: NF * 1.35,\n overflow: \"hidden\",\n }}\n >\n <div\n style={{\n position: \"relative\",\n top: NF * 0.15,\n height: NF,\n lineHeight: `${NF}px`,\n whiteSpace: \"pre\",\n fontFamily: gabarito.fontFamily,\n fontWeight: NAME_W,\n fontSize: NF,\n letterSpacing: `${NAME_TRACK}em`,\n color: hi,\n transform: `translateY(${((1 - nameIn) * NF * 1.3).toFixed(2)}px)`,\n }}\n >\n {name}\n </div>\n </div>\n </AbsoluteFill>\n );\n}",
"durationInFrames": 138,
"installationMode": "wrapped"
},
"durationInFrames": 138
}