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": [],
"dimensions": {
"width": 700,
"height": 110
},
"displayName": "Word Stream",
"initialProps": null,
"slug": "word-stream",
"sourceCode": "import { Easing, Interactive, Sequence, interpolate, useCurrentFrame, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { forwardRef, useImperativeHandle, useRef, type ComponentProps } from \"react\";\n\ninterface WordStreamProps {\n text: string;\n fontSize?: number;\n color?: string;\n fontWeight?: number;\n wordGap?: number;\n hold?: number;\n drift?: number;\n speed?: number;\n className?: string;\n}\n\ninterface PhraseSchedule {\n words: string[];\n start: number;\n exitStart: number;\n last: boolean;\n}\n\nconst REVEAL_FRAMES = 3;\nconst ENTRY_FRAMES = 8;\nconst RUN_OUT_FRAMES = 5;\nconst SWAP_OVERLAP = 0;\n\nfunction wordStreamLength(text: string, wordGap = 6, hold = 18): number {\n const schedule = schedulePhrases(text, wordGap, hold);\n const finalPhrase = schedule[schedule.length - 1];\n if (!finalPhrase) return 0;\n return (\n finalPhrase.start + (finalPhrase.words.length - 1) * wordGap + REVEAL_FRAMES\n );\n}\n\nfunction schedulePhrases(\n text: string,\n wordGap: number,\n hold: number,\n): PhraseSchedule[] {\n const phrases = text\n .split(\"|\")\n .map((phrase) => phrase.trim())\n .filter(Boolean);\n let cursor = 0;\n return phrases.map((phrase, i) => {\n const words = phrase.split(/\\s+/);\n const start = cursor;\n const complete = start + (words.length - 1) * wordGap + REVEAL_FRAMES;\n const exitStart = complete + hold;\n cursor = exitStart + SWAP_OVERLAP;\n return { words, start, exitStart, last: i === phrases.length - 1 };\n });\n}\n\nconst revealEasing = Easing.bezier(0.2, 0.8, 0.2, 1);\nconst entryEasing = Easing.bezier(0.2, 0.8, 0.3, 1);\nconst runOutEasing = Easing.bezier(0.7, 0, 0.9, 0.4);\n\nfunction WordStreamBase({\n text,\n fontSize = 72,\n color = \"#171717\",\n fontWeight = 400,\n wordGap = 6,\n hold = 18,\n drift = 2,\n speed = 1,\n className,\n}: WordStreamProps) {\n const frame = useCurrentFrame() * speed;\n\n const schedule = schedulePhrases(text, wordGap, hold);\n\n return (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n background: \"transparent\",\n }}\n >\n {schedule.map((phrase, i) => {\n if (frame < phrase.start) return null;\n if (!phrase.last && frame >= phrase.exitStart) return null;\n\n const scale = fontSize / 72;\n const crawl = scale * drift;\n const life = phrase.exitStart - phrase.start;\n\n const entryX = interpolate(\n frame,\n [phrase.start, phrase.start + ENTRY_FRAMES],\n [scale * 30, 0],\n {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n easing: entryEasing,\n },\n );\n const crawlX =\n crawl *\n (life / 2 - (Math.min(frame, phrase.exitStart) - phrase.start));\n const runOutX = phrase.last\n ? 0\n : interpolate(\n frame,\n [phrase.exitStart - RUN_OUT_FRAMES, phrase.exitStart],\n [0, -scale * 80],\n {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n easing: runOutEasing,\n },\n );\n const x = entryX + crawlX + runOutX;\n\n return (\n <div\n key={i}\n style={{\n position: \"absolute\",\n inset: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n whiteSpace: \"nowrap\",\n translate: `${x}px 0`,\n }}\n >\n <span\n className={className}\n style={{\n fontSize,\n fontWeight,\n color,\n letterSpacing: \"-0.02em\",\n fontFamily:\n \"var(--font-geist-sans, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif)\",\n }}\n >\n {phrase.words.map((word, j) => {\n const revealAt = phrase.start + j * wordGap;\n\n const opacity = interpolate(\n frame,\n [revealAt, revealAt + REVEAL_FRAMES],\n [0, 1],\n {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n easing: revealEasing,\n },\n );\n\n return (\n <span\n key={j}\n style={{\n display: \"inline-block\",\n whiteSpace: \"pre\",\n marginRight:\n j < phrase.words.length - 1 ? \"0.28em\" : undefined,\n opacity,\n }}\n >\n {word}\n </span>\n );\n })}\n </span>\n </div>\n );\n })}\n </div>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n text: {\n type: \"text-content\",\n default: \"introducing | one-tap checkout | for your store\",\n description: \"Phrases (| separated)\",\n },\n fontSize: {\n type: \"number\",\n min: 12,\n max: 160,\n step: 1,\n default: 72,\n description: \"Font size\",\n hiddenFromList: false,\n },\n wordGap: {\n type: \"number\",\n min: 2,\n max: 30,\n step: 1,\n default: 6,\n description: \"Frames / word\",\n hiddenFromList: false,\n },\n hold: {\n type: \"number\",\n min: 6,\n max: 90,\n step: 3,\n default: 18,\n description: \"Phrase hold\",\n hiddenFromList: false,\n },\n drift: {\n type: \"number\",\n min: 0,\n max: 6,\n step: 0.5,\n default: 2,\n description: \"Drift px / frame\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#171717\",\n description: \"Color\",\n },\n fontWeight: {\n type: \"enum\",\n default: \"400\",\n variants: {\n \"400\": {},\n \"500\": {},\n \"600\": {},\n \"700\": {},\n },\n description: \"Font weight\",\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 width: {\n type: \"number\",\n default: 700,\n min: 10,\n step: 10,\n description: \"Width\",\n },\n height: {\n type: \"number\",\n default: 110,\n min: 10,\n step: 10,\n description: \"Height\",\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"text\",\"fontSize\",\"wordGap\",\"hold\",\"drift\",\"color\",\"fontWeight\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n text: \"introducing | one-tap checkout | for your store\",\n fontSize: 72,\n wordGap: 6,\n hold: 18,\n drift: 2,\n color: \"#171717\",\n fontWeight: \"400\",\n speed: 1,\n};\n\ntype WordStreamElementProps = InteractiveBaseProps &\n InteractiveTransformProps & { readonly width?: number; readonly height?: number } &\n ComponentProps<typeof WordStreamBase>;\n\nconst WordStreamInner = forwardRef<\n HTMLDivElement,\n WordStreamElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, width = 700, height = 110, ...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 ?? \"<WordStream>\"}\n outlineRef={outlineRef}\n >\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n }}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width,\n height,\n ...style,\n }}\n >\n <WordStreamBase\n {...(componentProps as unknown as ComponentProps<typeof WordStreamBase>)}\n />\n </div>\n </div>\n </Sequence>\n );\n});\n\nexport const WordStream = Interactive.withSchema({\n Component: WordStreamInner,\n componentName: \"<WordStream>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n",
"durationInFrames": 63,
"installationMode": "component-owned-sequence"
},
"durationInFrames": 63
}