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": "Slide Doors",
"initialProps": null,
"slug": "slide-doors",
"sourceCode": "import { loadFont as loadJakarta } from \"@remotion/google-fonts/PlusJakartaSans\";\nimport React, { forwardRef, useEffect, useImperativeHandle, useMemo, 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 jakarta = loadJakarta(\"normal\", {\n weights: [\"400\"],\n subsets: [\"latin\"],\n});\n\ninterface SlideDoorsProps {\n lines?: string[];\n highlight?: string;\n hold?: number;\n accent?: string;\n background?: string;\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n dark: {\n bg: \"#0B1F33\",\n ink: \"#E8EEF2\",\n teal: \"#00BFA5\",\n track: \"rgba(232,238,242,0.16)\",\n },\n light: {\n bg: \"#E8EEF2\",\n ink: \"#0B1F33\",\n teal: \"#00A08A\",\n track: \"rgba(11,31,51,0.14)\",\n },\n} as const;\n\nconst SCALE_MIN = 0.58;\nconst WGHT = 400;\nconst TRACK = -0.03;\nconst WORD = 0.14;\n\nconst ENTER = 20;\nconst CRACK = 8;\nconst PUSH = 16;\nconst CLEAR = 14;\nconst OPEN = CRACK + PUSH + CLEAR;\nconst PAD = 0.22;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_PUSH = Easing.bezier(0.45, 0, 0.35, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\ninterface LineMetrics {\n words: string[];\n split: number;\n left: number;\n right: number;\n full: number;\n}\n\nfunction measure(lines: string[]): LineMetrics[] {\n const probe = document.createElement(\"span\");\n Object.assign(probe.style, {\n position: \"absolute\",\n left: \"-99999px\",\n top: \"0\",\n visibility: \"hidden\",\n whiteSpace: \"pre\",\n fontFamily: `\"${jakarta.fontFamily}\"`,\n fontWeight: String(WGHT),\n fontSize: \"100px\",\n lineHeight: \"1\",\n letterSpacing: `${TRACK}em`,\n wordSpacing: `${WORD}em`,\n });\n document.body.appendChild(probe);\n const w = (s: string) => {\n probe.textContent = s;\n return s ? probe.getBoundingClientRect().width / 100 - TRACK : 0;\n };\n const out = lines.map((line) => {\n const words = line.split(\" \").filter(Boolean);\n const full = w(words.join(\" \"));\n let split = -1;\n let best = Number.POSITIVE_INFINITY;\n for (let k = 0; k < words.length - 1; k++) {\n const lw = w(words.slice(0, k + 1).join(\" \"));\n const d = Math.abs(lw - full / 2);\n if (d < best) {\n best = d;\n split = k;\n }\n }\n const left = split >= 0 ? w(words.slice(0, split + 1).join(\" \")) : full;\n const right = split >= 0 ? w(words.slice(split + 1).join(\" \")) : 0;\n return { words, split, left, right, full };\n });\n probe.remove();\n return out;\n}\n\nfunction useLines(lines: string[]) {\n const key = lines.join(\"\\u0001\");\n const [state, setState] = useState<{ key: string; m: LineMetrics[] } | null>(\n null,\n );\n const [handle] = useState(() => delayRender(\"slide-doors: measuring\"));\n const released = useRef(false);\n useEffect(() => {\n let live = true;\n Promise.all([\n jakarta.waitUntilDone(),\n document.fonts.load(`${WGHT} 100px \"${jakarta.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n if (!live) return;\n setState({ key, m: measure(key.split(\"\\u0001\")) });\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 : null;\n}\n\nconst stripPunct = (s: string) => s.replace(/[.,!?;:’'\"]+$/u, \"\");\n\nfunction SlideDoorsBase({\n lines = [\"Scenes that move.\", \"Code you own.\", \"Arriving in your repo.\"],\n highlight = \"repo.\",\n hold = 28,\n accent,\n background,\n speed = 1,\n theme = \"dark\",\n}: SlideDoorsProps) {\n const t = useCurrentFrame() * speed;\n const { width: W, height: H } = useVideoConfig();\n const c = THEMES[theme];\n const hi = accent ?? c.teal;\n const list = useMemo(\n () => (lines.length > 0 ? lines : [\"Arriving in your repo.\"]),\n [lines],\n );\n const state = useLines(list);\n\n const transparent = background === \"transparent\";\n const stage = transparent ? \"transparent\" : (background ?? c.bg);\n\n if (!state) {\n return (\n <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n );\n }\n const { m } = state;\n\n const portrait = H > W * 1.1;\n const minDim = Math.min(W, H);\n const widest = Math.max(...m.map((l) => l.full), 0.1);\n const F = Math.min(\n (W * (portrait ? 0.86 : 0.8)) / widest,\n H * (portrait ? 0.075 : 0.14),\n );\n const cx = W / 2;\n const lineH = F * 1.25;\n const trackY = H * (portrait ? 0.7 : 0.74);\n const top = trackY - lineH - F * 0.12;\n const pad = PAD * F;\n const far = W * 0.62;\n const stroke = Math.max(1.5, minDim * 0.0026);\n\n const STEP = CRACK + PUSH + Math.max(8, hold);\n const openAt = (k: number) => ENTER + Math.max(8, hold) + k * STEP;\n let cur = 0;\n for (let k = 0; k < list.length - 1; k++) if (t >= openAt(k)) cur = k + 1;\n const opening = cur > 0 && t < openAt(cur - 1) + OPEN;\n const out = opening ? cur - 1 : -1;\n\n const textStyle: React.CSSProperties = {\n position: \"absolute\",\n top: 0,\n height: lineH,\n lineHeight: `${lineH}px`,\n whiteSpace: \"pre\",\n fontFamily: jakarta.fontFamily,\n fontWeight: WGHT,\n fontSize: F,\n letterSpacing: `${TRACK}em`,\n wordSpacing: `${WORD}em`,\n color: c.ink,\n };\n\n const renderWords = (k: number, words: string[]) =>\n words.map((w, i) => {\n const hl =\n k === list.length - 1 &&\n highlight &&\n stripPunct(w).toLowerCase() === stripPunct(highlight).toLowerCase();\n return (\n <span key={`${k}-${i}-${w}`} style={hl ? { color: hi } : undefined}>\n {w}\n {i < words.length - 1 ? \" \" : \"\"}\n </span>\n );\n });\n\n const doors = (k: number, dl: number, dr: number) => {\n const l = m[k];\n const x0 = cx - (l.full * F) / 2;\n const leftWords = l.split >= 0 ? l.words.slice(0, l.split + 1) : l.words;\n const rightWords = l.split >= 0 ? l.words.slice(l.split + 1) : [];\n return (\n <>\n <div\n key={`L${k}`}\n style={{\n ...textStyle,\n left: x0,\n transform: `translateX(${(-dl).toFixed(2)}px)`,\n }}\n >\n {renderWords(k, leftWords)}\n </div>\n {rightWords.length > 0 ? (\n <div\n key={`R${k}`}\n style={{\n ...textStyle,\n left: x0 + (l.full - l.right) * F,\n transform: `translateX(${dr.toFixed(2)}px)`,\n }}\n >\n {renderWords(k, rightWords)}\n </div>\n ) : null}\n </>\n );\n };\n\n let content: React.ReactNode;\n let gapL = cx;\n let gapR = cx;\n if (t < ENTER || (cur === 0 && !opening)) {\n const p = interpolate(t, [0, ENTER], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n content = doors(0, (1 - p) * far, (1 - p) * far);\n } else if (opening) {\n const tau = t - openAt(out);\n const lo = m[out];\n const ln = m[cur];\n const x0 = cx - (lo.full * F) / 2;\n const edgeL = x0 + lo.left * F;\n const edgeR = lo.split >= 0 ? x0 + (lo.full - lo.right) * F : edgeL;\n const g0 = edgeR - edgeL;\n const gCrack = ln.full * SCALE_MIN * F + 2 * pad;\n const gRest = ln.full * F + 2 * pad;\n const push = interpolate(tau, [CRACK, CRACK + PUSH], [0, 1], {\n ...CLAMP,\n easing: EASE_PUSH,\n });\n const s = SCALE_MIN + (1 - SCALE_MIN) * push;\n const nw = ln.full * s * F;\n let gapW: number;\n if (tau < CRACK) {\n const k = interpolate(tau, [0, CRACK], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n gapW = g0 + (Math.max(gCrack, g0) - g0) * k;\n } else {\n const after = Math.max(0, tau - CRACK - PUSH);\n gapW = Math.max(nw + 2 * pad, g0) + 2 * (F * 0.04 * after * after);\n }\n const centre0 = (edgeL + edgeR) / 2;\n const drift = interpolate(\n gapW,\n [g0, Math.max(g0 + 1, gRest)],\n [0, 1],\n CLAMP,\n );\n const centre = centre0 + (cx - centre0) * drift;\n const dl = edgeL - (centre - gapW / 2);\n const dr = centre + gapW / 2 - edgeR;\n const fits = interpolate(\n gapW - ln.full * SCALE_MIN * F - pad,\n [0, pad],\n [0, 1],\n CLAMP,\n );\n gapL = centre - gapW / 2;\n gapR = centre + gapW / 2;\n content = (\n <>\n {doors(out, dl, dr)}\n <div\n key={`N${cur}`}\n style={{\n ...textStyle,\n left: centre - (ln.full * F) / 2,\n transformOrigin: `${((ln.full * F) / 2).toFixed(2)}px ${(lineH * 0.7).toFixed(2)}px`,\n transform: `scale(${s.toFixed(4)})`,\n opacity: fits,\n }}\n >\n {renderWords(cur, ln.words)}\n </div>\n </>\n );\n } else {\n const l = m[cur];\n content = (\n <div\n key={`N${cur}`}\n style={{ ...textStyle, left: cx - (l.full * F) / 2 }}\n >\n {renderWords(cur, l.words)}\n </div>\n );\n }\n\n const trackIn = interpolate(t, [0, ENTER], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n const halfW = (W / 2) * trackIn;\n\n return (\n <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n <div\n style={{\n position: \"absolute\",\n left: cx - halfW,\n width: halfW * 2,\n top: trackY,\n height: stroke,\n background: c.track,\n }}\n />\n {opening ? (\n <div\n style={{\n position: \"absolute\",\n left: Math.max(0, gapL),\n width: Math.max(0, Math.min(W, gapR) - Math.max(0, gapL)),\n top: trackY - stroke * 0.5,\n height: stroke * 2,\n background: hi,\n }}\n />\n ) : null}\n <div\n style={{\n position: \"absolute\",\n left: 0,\n top,\n width: W,\n height: lineH,\n }}\n >\n {content}\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 highlight: {\n type: \"text-content\",\n default: \"repo.\",\n description: \"Highlight\",\n },\n hold: {\n type: \"number\",\n default: 28,\n min: 0,\n max: 84,\n step: 1,\n description: \"Hold\",\n hiddenFromList: false,\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\",\"highlight\",\"hold\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n theme: \"dark\",\n highlight: \"repo.\",\n hold: 28,\n speed: 1,\n};\n\ntype SlideDoorsElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof SlideDoorsBase>;\n\nconst SlideDoorsInner = forwardRef<\n HTMLDivElement,\n SlideDoorsElementProps & { 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 ?? \"<SlideDoors>\"}\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 <SlideDoorsBase\n {...(componentProps as unknown as ComponentProps<typeof SlideDoorsBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const SlideDoors = Interactive.withSchema({\n Component: SlideDoorsInner,\n componentName: \"<SlideDoors>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n",
"durationInFrames": 138,
"installationMode": "component-owned-sequence"
},
"durationInFrames": 138
}