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": "Moves Up",
"initialProps": null,
"slug": "moves-up",
"sourceCode": "import { loadFont } from \"@remotion/google-fonts/GolosText\";\nimport React, { forwardRef, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState, type ComponentProps } from \"react\";\nimport { AbsoluteFill, Easing, Interactive, Sequence, continueRender, delayRender, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\nconst golos = loadFont(\"normal\", {\n weights: [\"400\", \"500\"],\n subsets: [\"latin\"],\n});\n\ninterface MovesUpProps {\n items?: string[];\n labels?: [string, string, string];\n shipped?: string;\n accent?: string;\n background?: string;\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n dark: { bg: \"#1D2B53\", ink: \"#FFFFFF\", accent: \"#FFB38A\" },\n light: { bg: \"#FFF4EC\", ink: \"#1D2B53\", accent: \"#D9623B\" },\n} as const;\n\nconst DEFAULT_ITEMS = [\n \"Auto captions\",\n \"Voiceover\",\n \"Vertical cuts\",\n \"Your type, your colours\",\n \"Whatever you ask for\",\n];\n\nconst ROW_SCALE = [1, 0.56, 0.38];\nconst ROW_INK = [1, 0.74, 0.5];\nconst LH = 1.06;\nconst BASE_EM = 0.86;\n\nconst INTRO = 30;\nconst HOLD = 22;\nconst STEP = 66;\nconst TAG_IN = 10;\nconst EXIT_AT = 11;\nconst EXIT_DUR = 10;\nconst PROMO_AT = 14;\nconst PROMO_DUR = 20;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_STEP = Easing.bezier(0.4, 0, 0.15, 1);\nconst EASE_IN = Easing.bezier(0.5, 0, 0.75, 0);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction MovesUpBase({\n items = DEFAULT_ITEMS,\n labels = [\"Now\", \"Next\", \"Later\"],\n shipped = \"shipped\",\n accent,\n background,\n speed = 1,\n theme = \"dark\",\n}: MovesUpProps) {\n const frame = useCurrentFrame();\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 queue = items.length > 0 ? items : DEFAULT_ITEMS;\n const steps = Math.max(0, queue.length - 3);\n const stepAt = (s: number) => INTRO + HOLD + (s - 1) * STEP;\n const naturalEnd = steps > 0 ? stepAt(steps) + PROMO_AT + PROMO_DUR : INTRO;\n const pace = Math.max(1, (naturalEnd + 30) / Math.max(1, durationInFrames));\n const t = frame * speed * pace;\n\n const portrait = H > W * 1.1;\n const margin = W * (portrait ? 0.08 : 0.07);\n const labelW = portrait ? 0 : W * 0.2;\n const itemX = margin + labelW;\n const itemW = W - margin - itemX;\n const baseSize = Math.min(H * 0.15, W * (portrait ? 0.13 : 0.085));\n const minRow = queue.map((_, k) => Math.max(0, Math.min(2, k - steps)));\n\n const refs = useRef<(HTMLDivElement | null)[]>([]);\n const probes = useRef<(HTMLSpanElement | null)[]>([]);\n const [natural, setNatural] = useState<number[] | null>(null);\n const [handle] = useState(() => delayRender(\"moves-up: measuring\"));\n const released = useRef(false);\n const [fontsOk, setFontsOk] = useState(false);\n const [heights, setHeights] = useState<number[] | null>(null);\n\n useEffect(() => {\n let live = true;\n Promise.all([\n golos.waitUntilDone(),\n document.fonts.load(`500 100px \"${golos.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n if (live) setFontsOk(true);\n });\n return () => {\n live = false;\n };\n }, []);\n\n useLayoutEffect(() => {\n if (!fontsOk) return;\n const nat = queue.map(\n (_, i) => (probes.current[i]?.offsetWidth ?? 0) / 100,\n );\n setNatural((prev) =>\n prev && prev.length === nat.length && prev.every((v, i) => v === nat[i])\n ? prev\n : nat,\n );\n const next = queue.map((_, i) => refs.current[i]?.offsetHeight ?? 0);\n setHeights((prev) =>\n prev && prev.length === next.length && prev.every((v, i) => v === next[i])\n ? prev\n : next,\n );\n });\n\n useEffect(() => {\n if (heights && natural && !released.current) {\n released.current = true;\n continueRender(handle);\n }\n }, [heights, natural, handle]);\n\n let fit = baseSize;\n if (natural) {\n for (let k = 0; k < queue.length; k++) {\n const w = natural[k] * ROW_SCALE[minRow[k]];\n if (w > 0) fit = Math.min(fit, (itemW * 0.98) / w);\n }\n }\n const size = Math.max(baseSize * 0.62, fit);\n const labelSize = Math.max(size * 0.24, H * 0.022);\n const labelLift = portrait ? labelSize * 1.5 : 0;\n const rowGap = size * 0.42 + labelLift;\n\n const lineH = size * LH;\n const slots = [0, 1, 2].map((r) => {\n let mx = lineH * ROW_SCALE[r];\n if (heights) {\n for (let k = r; k <= r + steps && k < queue.length; k++) {\n mx = Math.max(mx, heights[k] * ROW_SCALE[r]);\n }\n }\n return mx;\n });\n const total = slots[0] + slots[1] + slots[2] + rowGap * 2 + labelLift;\n const group = Math.min(1, (H * 0.84) / total);\n const top0 = (H - total) / 2 + labelLift;\n const slotTop = [top0, top0 + slots[0] + rowGap];\n slotTop.push(slotTop[1] + slots[1] + rowGap);\n\n const promoted = (() => {\n let sum = 0;\n for (let s = 1; s <= steps; s++) {\n const at = stepAt(s);\n sum += interpolate(\n t,\n [at + PROMO_AT, at + PROMO_AT + PROMO_DUR],\n [0, 1],\n {\n ...CLAMP,\n easing: EASE_STEP,\n },\n );\n }\n return sum;\n })();\n\n const lerpRow = (arr: number[], rf: number) => {\n const r = Math.max(0, Math.min(2, rf));\n const i = Math.min(1, Math.floor(r));\n const f = r - i;\n return arr[i] + (arr[i + 1] - arr[i]) * f;\n };\n\n const rise = (start: number, dur = 14) =>\n interpolate(t, [start, start + dur], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n\n const font: React.CSSProperties = {\n fontFamily: golos.fontFamily,\n fontWeight: 500,\n letterSpacing: \"-0.03em\",\n lineHeight: LH,\n };\n\n return (\n <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n <div\n style={{\n position: \"absolute\",\n left: 0,\n top: 0,\n visibility: \"hidden\",\n whiteSpace: \"nowrap\",\n }}\n >\n {queue.map((item, k) => (\n <span\n key={`probe-${k}-${item}`}\n ref={(el) => {\n probes.current[k] = el;\n }}\n style={{ ...font, fontSize: 100, display: \"inline-block\" }}\n >\n {item}\n {k < steps ? (\n <span style={{ fontSize: \"0.3em\", marginLeft: \"0.6em\" }}>\n {shipped}\n </span>\n ) : null}\n </span>\n ))}\n </div>\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n opacity: heights && natural ? 1 : 0,\n transformOrigin: \"50% 50%\",\n transform: `scale(${group.toFixed(4)})`,\n }}\n >\n {labels.map((label, r) => {\n const p = rise(r * 4);\n const sc = ROW_SCALE[r];\n return (\n <div\n key={`label-${r}`}\n style={{\n ...font,\n position: \"absolute\",\n left: margin,\n top: portrait\n ? slotTop[r] - labelLift\n : slotTop[r] + BASE_EM * size * sc - BASE_EM * labelSize,\n fontSize: labelSize,\n letterSpacing: \"-0.01em\",\n color: r === 0 ? hi : c.ink,\n opacity: p * (r === 0 ? 1 : 0.62),\n transform: `translateY(${((1 - p) * 0.4).toFixed(3)}em)`,\n whiteSpace: \"nowrap\",\n }}\n >\n {label}\n </div>\n );\n })}\n {queue.map((item, k) => {\n const rf = k - promoted;\n const introP = k < 3 ? rise(6 + k * 5, 18) : 1;\n const shipStep = k + 1;\n const shipAt = shipStep <= steps ? stepAt(shipStep) : Infinity;\n const tagP = Number.isFinite(shipAt)\n ? interpolate(t, [shipAt, shipAt + TAG_IN], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n })\n : 0;\n const exitP = Number.isFinite(shipAt)\n ? interpolate(\n t,\n [shipAt + EXIT_AT, shipAt + EXIT_AT + EXIT_DUR],\n [0, 1],\n { ...CLAMP, easing: EASE_IN },\n )\n : 0;\n\n let y: number;\n let sc: number;\n let ink: number;\n let alpha: number;\n if (rf >= 2) {\n const e = Math.min(1, rf - 2);\n y = slotTop[2] + e * slots[2] * 0.9;\n sc = ROW_SCALE[2];\n ink = ROW_INK[2];\n alpha = k < 3 ? introP : interpolate(e, [0, 0.4], [1, 0], CLAMP);\n } else if (rf >= 0) {\n y = lerpRow(slotTop, rf);\n sc = lerpRow(ROW_SCALE, rf);\n ink = lerpRow(ROW_INK, rf);\n alpha = introP;\n } else {\n y = slotTop[0];\n sc = 1;\n ink = 1;\n alpha = 1;\n }\n y -= exitP * slots[0] * 0.45;\n alpha *= 1 - exitP;\n const introY = (1 - introP) * size * sc * 0.35;\n\n return (\n <div\n key={`${k}-${item}`}\n ref={(el) => {\n refs.current[k] = el;\n }}\n style={{\n ...font,\n position: \"absolute\",\n left: itemX,\n top: y + introY,\n width: itemW / ROW_SCALE[minRow[k]],\n fontSize: size,\n color: c.ink,\n transformOrigin: \"0 0\",\n transform: `scale(${sc.toFixed(4)})`,\n opacity: Math.max(0, alpha) * ink,\n textWrap: \"balance\",\n }}\n >\n {item}\n {k < steps ? (\n <span\n style={{\n display: \"inline-block\",\n fontSize: \"0.3em\",\n letterSpacing: \"-0.01em\",\n marginLeft: \"0.6em\",\n color: hi,\n opacity: tagP / Math.max(0.01, ink),\n transform: `translateX(${((1 - tagP) * -0.6).toFixed(3)}em)`,\n }}\n >\n {shipped}\n </span>\n ) : null}\n </div>\n );\n })}\n </div>\n </AbsoluteFill>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n theme: {\n type: \"enum\",\n default: \"dark\",\n variants: {\n dark: {},\n light: {},\n },\n description: \"Theme\",\n },\n shipped: {\n type: \"text-content\",\n default: \"shipped\",\n description: \"Shipped\",\n },\n speed: {\n type: \"number\",\n default: 1,\n min: 0.25,\n max: 4,\n step: 0.25,\n description: \"Speed\",\n hiddenFromList: false,\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"theme\",\"shipped\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n theme: \"dark\",\n shipped: \"shipped\",\n speed: 1,\n};\n\ntype MovesUpElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof MovesUpBase>;\n\nconst MovesUpInner = forwardRef<\n HTMLDivElement,\n MovesUpElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<MovesUp>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <MovesUpBase\n {...(componentProps as unknown as ComponentProps<typeof MovesUpBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const MovesUp = Interactive.withSchema({\n Component: MovesUpInner,\n componentName: \"<MovesUp>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n",
"durationInFrames": 152,
"installationMode": "component-owned-sequence"
},
"durationInFrames": 152
}