π₯ Make videos programmatically with React
Rework component wrapping/imports and add page for code examples
ASchwadc0a7a6c7f8aa
diff --git a/packages/template-code-generation/src/app/api/generate/route.ts b/packages/template-code-generation/src/app/api/generate/route.tsindex 6f3d32c113..70f60c31f7 100644--- a/packages/template-code-generation/src/app/api/generate/route.ts+++ b/packages/template-code-generation/src/app/api/generate/route.ts@@ -10,11 +10,11 @@ LAYOUT RULES:- Never constrain diagrams to a small centered box - maximize the visual spaceCOLOR RULES:-- Keep colors minimal (2-4 colors max) and define them as constants at the top+- Keep colors minimal (2-4 colors max) and define them as constants INSIDE the component body- Example: const COLOR_TEXT = "#000000"; const COLOR_HIGHLIGHT = "#A7C7E7";TEXT CONTENT RULES (CRITICAL):-- ALL text strings that appear in the animation MUST be defined as constants at the top+- ALL text strings that appear in the animation MUST be defined as constants INSIDE the component body- Never hardcode text directly in JSX - always use variables- This allows users to easily edit all text content- Use descriptive constant names in UPPER_SNAKE_CASE@@ -24,7 +24,7 @@ TEXT CONTENT RULES (CRITICAL):const STEP_1_TEXT = "Grind Coffee";ANIMATION TIMING RULES:-- Define animation speed/timing parameters as constants that users can adjust+- Define animation speed/timing parameters as constants INSIDE the component body- Use descriptive names for delays, durations, and speed multipliers- This allows users to fine-tune animation pacing without editing code- Example:@@ -32,6 +32,18 @@ ANIMATION TIMING RULES:const FADE_DURATION = 20; // Duration in framesconst ELEMENT_DELAY = 5; // Delay between elements in frames+CONSTANTS PLACEMENT (CRITICAL):+- NEVER define constants outside the component function+- ALL constants (colors, text, timing, layout) MUST be defined INSIDE the component body+- Place constants AFTER the hooks (useCurrentFrame, useVideoConfig) but BEFORE any calculations+- Correct order inside component:+ 1) Multi-line comment description+ 2) Hooks (useCurrentFrame, useVideoConfig, useState, etc.)+ 3) Constants (COLORS, TEXT, TIMING, LAYOUT)+ 4) Calculations and derived values+ 5) return JSX+- NEVER put constants before hooks - this is a common mistake+ADDITIONAL CONSTANTS TO DEFINE:- Typography: FONT_SIZE, FONT_WEIGHT, LETTER_SPACING- Layout: ROW_GAP, PADDING, BORDER_RADIUS, MAX_WIDTH_PERCENT@@ -67,254 +79,266 @@ EXAMPLE 1: Typewriter with highlight (advanced)Prompt: "Text with typewriter effect, pause mid-sentence, then highlight a word"-/*- * Typewriter with blinking cursor, dramatic pause, spring-based highlight, and layer crossfade.- */-const frame = useCurrentFrame();-const {fps} = useVideoConfig();--const COLOR_TEXT = "#000000";-const COLOR_HIGHLIGHT = "#A7C7E7";--const FULL_TEXT = "From prompt to motion graphics. This is Veloce.";-const HIGHLIGHT_WORD = "Veloce";-const CARET_SYMBOL = "β";-const SPLIT_AFTER = " This is Veloce."; // Phrase to delay before typing--const FONT_SIZE = 72;-const FONT_WEIGHT = 700;-const CHAR_FRAMES = 2;-const CURSOR_BLINK_FRAMES = 16;-const HIGHLIGHT_DELAY = 6;-const HIGHLIGHT_WIPE_DURATION = 18;-const CROSSFADE_DURATION = 8;-const WAIT_AFTER_PRE_SECONDS = 1; // Dramatic pause mid-sentence--const WAIT_AFTER_PRE_FRAMES = Math.round(fps * WAIT_AFTER_PRE_SECONDS);-const f = frame;--// Split point for pause-const splitIndex = FULL_TEXT.indexOf(SPLIT_AFTER);-const preLen = splitIndex >= 0 ? splitIndex : FULL_TEXT.length;-const postLen = FULL_TEXT.length - preLen;--// Typewriter with pause-let typedChars = 0;-if (f < preLen * CHAR_FRAMES) {- typedChars = Math.floor(f / CHAR_FRAMES);-} else if (f < preLen * CHAR_FRAMES + WAIT_AFTER_PRE_FRAMES) {- typedChars = preLen;-} else {- const postPhase = f - preLen * CHAR_FRAMES - WAIT_AFTER_PRE_FRAMES;- typedChars = Math.min(FULL_TEXT.length, preLen + Math.floor(postPhase / CHAR_FRAMES));-}-const typedText = FULL_TEXT.slice(0, typedChars);-const typingDone = typedChars >= FULL_TEXT.length;--// Caret blink (smooth)-const caretOpacity = !typingDone- ? interpolate(f % CURSOR_BLINK_FRAMES, [0, CURSOR_BLINK_FRAMES / 2, CURSOR_BLINK_FRAMES], [1, 0, 1], {extrapolateLeft: "clamp", extrapolateRight: "clamp"})- : 0;--// Highlight segmentation-const highlightIndex = FULL_TEXT.indexOf(HIGHLIGHT_WORD);-const hasHighlight = highlightIndex >= 0;-const preText = hasHighlight ? FULL_TEXT.slice(0, highlightIndex) : FULL_TEXT;-const postText = hasHighlight ? FULL_TEXT.slice(highlightIndex + HIGHLIGHT_WORD.length) : "";--// Timing-const typeEnd = preLen * CHAR_FRAMES + WAIT_AFTER_PRE_FRAMES + postLen * CHAR_FRAMES;-const highlightStart = typeEnd + HIGHLIGHT_DELAY;--const typedOpacity = interpolate(f, [highlightStart - CROSSFADE_DURATION, highlightStart + CROSSFADE_DURATION], [1, 0], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});-const finalOpacity = interpolate(f, [highlightStart, highlightStart + CROSSFADE_DURATION], [0, 1], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});--// Container entrance with spring-const entrance = spring({fps, frame: f, config: {damping: 200, stiffness: 120}, durationInFrames: 20});-const containerScale = interpolate(entrance, [0, 1], [0.98, 1], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});--// Highlight with spring (smoother than interpolate)-const highlightProgress = spring({fps, frame: f - highlightStart, config: {damping: 200, stiffness: 180}, durationInFrames: HIGHLIGHT_WIPE_DURATION});-const highlightScaleX = Math.max(0, Math.min(1, highlightProgress));--return (- <AbsoluteFill style={{display: "flex", alignItems: "center", justifyContent: "center"}}>- <div style={{position: "relative"}}>- {/* Typing layer */}- <div style={{color: COLOR_TEXT, fontSize: FONT_SIZE, fontWeight: FONT_WEIGHT, lineHeight: 1.15, whiteSpace: "pre-wrap", opacity: typedOpacity}}>- <span>{typedText}</span>- <span style={{opacity: caretOpacity}}>{CARET_SYMBOL}</span>- </div>- {/* Final layer with highlight */}- <div style={{position: "absolute", inset: 0, color: COLOR_TEXT, fontSize: FONT_SIZE, fontWeight: FONT_WEIGHT, lineHeight: 1.15, whiteSpace: "pre-wrap", opacity: finalOpacity}}>- {hasHighlight ? (- <>- <span>{preText}</span>- <span style={{position: "relative", display: "inline-block"}}>- <span style={{- position: "absolute", left: 0, right: 0, top: "50%", height: "1.05em",- transform: \`translateY(-50%) scaleX(\${highlightScaleX})\`,- transformOrigin: "left center", backgroundColor: COLOR_HIGHLIGHT, borderRadius: "0.18em", zIndex: 0- }} />- <span style={{position: "relative", zIndex: 1}}>{HIGHLIGHT_WORD}</span>- </span>- <span>{postText}</span>- </>- ) : (- <span>{FULL_TEXT}</span>- )}+import { useCurrentFrame, useVideoConfig, AbsoluteFill, interpolate, spring } from "remotion";++export const MyAnimation = () => {+ /*+ * Typewriter with blinking cursor, dramatic pause, spring-based highlight, and layer crossfade.+ */+ const frame = useCurrentFrame();+ const {fps} = useVideoConfig();++ const COLOR_TEXT = "#000000";+ const COLOR_HIGHLIGHT = "#A7C7E7";++ const FULL_TEXT = "From prompt to motion graphics. This is Veloce.";+ const HIGHLIGHT_WORD = "Veloce";+ const CARET_SYMBOL = "β";+ const SPLIT_AFTER = " This is Veloce."; // Phrase to delay before typing++ const FONT_SIZE = 72;+ const FONT_WEIGHT = 700;+ const CHAR_FRAMES = 2;+ const CURSOR_BLINK_FRAMES = 16;+ const HIGHLIGHT_DELAY = 6;+ const HIGHLIGHT_WIPE_DURATION = 18;+ const CROSSFADE_DURATION = 8;+ const WAIT_AFTER_PRE_SECONDS = 1; // Dramatic pause mid-sentence++ const WAIT_AFTER_PRE_FRAMES = Math.round(fps * WAIT_AFTER_PRE_SECONDS);+ const f = frame;++ // Split point for pause+ const splitIndex = FULL_TEXT.indexOf(SPLIT_AFTER);+ const preLen = splitIndex >= 0 ? splitIndex : FULL_TEXT.length;+ const postLen = FULL_TEXT.length - preLen;++ // Typewriter with pause+ let typedChars = 0;+ if (f < preLen * CHAR_FRAMES) {+ typedChars = Math.floor(f / CHAR_FRAMES);+ } else if (f < preLen * CHAR_FRAMES + WAIT_AFTER_PRE_FRAMES) {+ typedChars = preLen;+ } else {+ const postPhase = f - preLen * CHAR_FRAMES - WAIT_AFTER_PRE_FRAMES;+ typedChars = Math.min(FULL_TEXT.length, preLen + Math.floor(postPhase / CHAR_FRAMES));+ }+ const typedText = FULL_TEXT.slice(0, typedChars);+ const typingDone = typedChars >= FULL_TEXT.length;++ // Caret blink (smooth)+ const caretOpacity = !typingDone+ ? interpolate(f % CURSOR_BLINK_FRAMES, [0, CURSOR_BLINK_FRAMES / 2, CURSOR_BLINK_FRAMES], [1, 0, 1], {extrapolateLeft: "clamp", extrapolateRight: "clamp"})+ : 0;++ // Highlight segmentation+ const highlightIndex = FULL_TEXT.indexOf(HIGHLIGHT_WORD);+ const hasHighlight = highlightIndex >= 0;+ const preText = hasHighlight ? FULL_TEXT.slice(0, highlightIndex) : FULL_TEXT;+ const postText = hasHighlight ? FULL_TEXT.slice(highlightIndex + HIGHLIGHT_WORD.length) : "";++ // Timing+ const typeEnd = preLen * CHAR_FRAMES + WAIT_AFTER_PRE_FRAMES + postLen * CHAR_FRAMES;+ const highlightStart = typeEnd + HIGHLIGHT_DELAY;++ const typedOpacity = interpolate(f, [highlightStart - CROSSFADE_DURATION, highlightStart + CROSSFADE_DURATION], [1, 0], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});+ const finalOpacity = interpolate(f, [highlightStart, highlightStart + CROSSFADE_DURATION], [0, 1], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});++ // Container entrance with spring+ const entrance = spring({fps, frame: f, config: {damping: 200, stiffness: 120}, durationInFrames: 20});+ const containerScale = interpolate(entrance, [0, 1], [0.98, 1], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});++ // Highlight with spring (smoother than interpolate)+ const highlightProgress = spring({fps, frame: f - highlightStart, config: {damping: 200, stiffness: 180}, durationInFrames: HIGHLIGHT_WIPE_DURATION});+ const highlightScaleX = Math.max(0, Math.min(1, highlightProgress));++ return (+ <AbsoluteFill style={{display: "flex", alignItems: "center", justifyContent: "center"}}>+ <div style={{position: "relative"}}>+ {/* Typing layer */}+ <div style={{color: COLOR_TEXT, fontSize: FONT_SIZE, fontWeight: FONT_WEIGHT, lineHeight: 1.15, whiteSpace: "pre-wrap", opacity: typedOpacity}}>+ <span>{typedText}</span>+ <span style={{opacity: caretOpacity}}>{CARET_SYMBOL}</span>+ </div>+ {/* Final layer with highlight */}+ <div style={{position: "absolute", inset: 0, color: COLOR_TEXT, fontSize: FONT_SIZE, fontWeight: FONT_WEIGHT, lineHeight: 1.15, whiteSpace: "pre-wrap", opacity: finalOpacity}}>+ {hasHighlight ? (+ <>+ <span>{preText}</span>+ <span style={{position: "relative", display: "inline-block"}}>+ <span style={{+ position: "absolute", left: 0, right: 0, top: "50%", height: "1.05em",+ transform: \`translateY(-50%) scaleX(\${highlightScaleX})\`,+ transformOrigin: "left center", backgroundColor: COLOR_HIGHLIGHT, borderRadius: "0.18em", zIndex: 0+ }} />+ <span style={{position: "relative", zIndex: 1}}>{HIGHLIGHT_WORD}</span>+ </span>+ <span>{postText}</span>+ </>+ ) : (+ <span>{FULL_TEXT}</span>+ )}+ </div></div>- </div>- </AbsoluteFill>-);+ </AbsoluteFill>+ );+};---EXAMPLE 2: Chat bubblesPrompt: "WhatsApp-style chat with messages appearing one by one"-/*- * Chat conversation with bubbles sliding in with spring animation.- */-const frame = useCurrentFrame();-const {fps, width, height} = useVideoConfig();--const COLOR_BACKGROUND = "#0b141a";-const COLOR_SENT = "#1f8a70";-const COLOR_RECEIVED = "#202c33";-const COLOR_TEXT = "#e9edef";--const MSG_1 = "Hey, how are you?";-const MSG_2 = "Great, thanks!";-const MSG_3 = "Want to grab coffee?";--const FONT_SIZE = 44;-const FADE_DURATION = 18;-const STAGGER_DELAY = 38;-const SLIDE_DISTANCE = 40;-const BOUNCE_DAMPING = 12;-const BOUNCE_STIFFNESS = 170;-const BUBBLE_RADIUS = 18;-const BUBBLE_PADDING_X = 24;-const BUBBLE_PADDING_Y = 18;-const ROW_GAP = 22;-const MAX_WIDTH_PERCENT = 72;--// Derived timing-const MSG1_START = 0;-const MSG2_START = MSG1_START + FADE_DURATION + STAGGER_DELAY;-const MSG3_START = MSG2_START + FADE_DURATION + STAGGER_DELAY;--// Helper component for repeated bubbles-const MessageRow = ({text, align, start}) => {- const local = frame - start;- const opacity = interpolate(local, [0, FADE_DURATION], [0, 1], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});- const bounce = spring({frame: Math.max(0, local), fps, damping: BOUNCE_DAMPING, stiffness: BOUNCE_STIFFNESS});- const scale = interpolate(bounce, [0, 1], [0.98, 1], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});- const xFrom = align === "right" ? SLIDE_DISTANCE : -SLIDE_DISTANCE;- const tx = interpolate(opacity, [0, 1], [xFrom, 0], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});- const bubbleBg = align === "right" ? COLOR_SENT : COLOR_RECEIVED;+import { useCurrentFrame, useVideoConfig, AbsoluteFill, interpolate, spring } from "remotion";++export const MyAnimation = () => {+ /*+ * Chat conversation with bubbles sliding in with spring animation.+ */+ const frame = useCurrentFrame();+ const {fps, width, height} = useVideoConfig();++ const COLOR_BACKGROUND = "#0b141a";+ const COLOR_SENT = "#1f8a70";+ const COLOR_RECEIVED = "#202c33";+ const COLOR_TEXT = "#e9edef";++ const MSG_1 = "Hey, how are you?";+ const MSG_2 = "Great, thanks!";+ const MSG_3 = "Want to grab coffee?";++ const FONT_SIZE = 44;+ const FADE_DURATION = 18;+ const STAGGER_DELAY = 38;+ const SLIDE_DISTANCE = 40;+ const BOUNCE_DAMPING = 12;+ const BOUNCE_STIFFNESS = 170;+ const BUBBLE_RADIUS = 18;+ const BUBBLE_PADDING_X = 24;+ const BUBBLE_PADDING_Y = 18;+ const ROW_GAP = 22;+ const MAX_WIDTH_PERCENT = 72;++ // Derived timing+ const MSG1_START = 0;+ const MSG2_START = MSG1_START + FADE_DURATION + STAGGER_DELAY;+ const MSG3_START = MSG2_START + FADE_DURATION + STAGGER_DELAY;++ // Helper component for repeated bubbles+ const MessageRow = ({text, align, start}: {text: string, align: string, start: number}) => {+ const local = frame - start;+ const opacity = interpolate(local, [0, FADE_DURATION], [0, 1], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});+ const bounce = spring({frame: Math.max(0, local), fps, config: {damping: BOUNCE_DAMPING, stiffness: BOUNCE_STIFFNESS}});+ const scale = interpolate(bounce, [0, 1], [0.98, 1], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});+ const xFrom = align === "right" ? SLIDE_DISTANCE : -SLIDE_DISTANCE;+ const tx = interpolate(opacity, [0, 1], [xFrom, 0], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});+ const bubbleBg = align === "right" ? COLOR_SENT : COLOR_RECEIVED;++ return (+ <div style={{width: "100%", display: "flex", justifyContent: align === "right" ? "flex-end" : "flex-start", marginTop: ROW_GAP}}>+ <div style={{+ maxWidth: \`\${MAX_WIDTH_PERCENT}%\`,+ backgroundColor: bubbleBg,+ color: COLOR_TEXT,+ padding: \`\${BUBBLE_PADDING_Y}px \${BUBBLE_PADDING_X}px\`,+ borderRadius: BUBBLE_RADIUS,+ fontSize: FONT_SIZE,+ opacity,+ transform: \`translateX(\${tx}px) scale(\${scale})\`,+ transformOrigin: align === "right" ? "100% 100%" : "0% 100%"+ }}>+ {text}+ </div>+ </div>+ );+ };return (- <div style={{width: "100%", display: "flex", justifyContent: align === "right" ? "flex-end" : "flex-start", marginTop: ROW_GAP}}>- <div style={{- maxWidth: \`\${MAX_WIDTH_PERCENT}%\`,- backgroundColor: bubbleBg,- color: COLOR_TEXT,- padding: \`\${BUBBLE_PADDING_Y}px \${BUBBLE_PADDING_X}px\`,- borderRadius: BUBBLE_RADIUS,- fontSize: FONT_SIZE,- opacity,- transform: \`translateX(\${tx}px) scale(\${scale})\`,- transformOrigin: align === "right" ? "100% 100%" : "0% 100%"- }}>- {text}- </div>- </div>+ <AbsoluteFill style={{+ backgroundColor: COLOR_BACKGROUND,+ display: "flex",+ flexDirection: "column",+ justifyContent: "flex-end",+ padding: Math.max(36, Math.round(width * 0.04))+ }}>+ <div style={{flex: 1}} />+ <MessageRow text={MSG_1} align="left" start={MSG1_START} />+ <MessageRow text={MSG_2} align="right" start={MSG2_START} />+ <MessageRow text={MSG_3} align="left" start={MSG3_START} />+ <div style={{height: Math.max(20, Math.round(height * 0.02))}} />+ </AbsoluteFill>);};-return (- <AbsoluteFill style={{- backgroundColor: COLOR_BACKGROUND,- display: "flex",- flexDirection: "column",- justifyContent: "flex-end",- padding: Math.max(36, Math.round(width * 0.04))- }}>- <div style={{flex: 1}} />- <MessageRow text={MSG_1} align="left" start={MSG1_START} />- <MessageRow text={MSG_2} align="right" start={MSG2_START} />- <MessageRow text={MSG_3} align="left" start={MSG3_START} />- <div style={{height: Math.max(20, Math.round(height * 0.02))}} />- </AbsoluteFill>-);----EXAMPLE 3: Rotating word carouselPrompt: "Text that dissolves between different words"-/*- * Prefix text with rotating words that crossfade with blur.- */-const frame = useCurrentFrame();--const COLOR_TEXT = "#7b92c1";-const PREFIX = "Created for";-const WORDS = ["Creators", "Marketers", "Developers", "Everyone"];--const PREFIX_FONT_SIZE = 80;-const WORD_FONT_SIZE = 80;-const PREFIX_WEIGHT = 300;-const WORD_WEIGHT = 700;-const WORD_GAP = 20;-const HOLD_DURATION = 32;-const FLIP_DURATION = 18;-const BLUR_AMOUNT = 6;--const perStep = HOLD_DURATION + FLIP_DURATION;-const totalSteps = WORDS.length;-const currentStep = Math.floor(frame / perStep) % totalSteps;-const nextStep = (currentStep + 1) % totalSteps;-const phase = frame % perStep;-const isFlipping = phase >= HOLD_DURATION;-const flipProgress = isFlipping ? (phase - HOLD_DURATION) / FLIP_DURATION : 0;--const outOpacity = interpolate(flipProgress, [0, 1], [1, 0], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});-const inOpacity = interpolate(flipProgress, [0, 1], [0, 1], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});-const outBlur = interpolate(flipProgress, [0, 1], [0, BLUR_AMOUNT], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});-const inBlur = interpolate(flipProgress, [0, 1], [BLUR_AMOUNT, 0], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});--// Find longest word for stable width-const longestWord = WORDS.reduce((a, b) => a.length >= b.length ? a : b, WORDS[0]);--return (- <AbsoluteFill style={{display: "flex", alignItems: "center", justifyContent: "center"}}>- <div style={{display: "flex", alignItems: "baseline", gap: WORD_GAP, color: COLOR_TEXT}}>- <div style={{fontSize: PREFIX_FONT_SIZE, fontWeight: PREFIX_WEIGHT}}>{PREFIX}</div>- <div style={{position: "relative", fontSize: WORD_FONT_SIZE, fontWeight: WORD_WEIGHT}}>- {/* Invisible width keeper */}- <div style={{visibility: "hidden"}}>{longestWord}</div>- {/* Current word (fades out during flip) */}- {!isFlipping && (- <div style={{position: "absolute", left: 0, top: 0}}>{WORDS[currentStep]}</div>- )}- {/* Crossfade during flip */}- {isFlipping && (- <>- <div style={{position: "absolute", left: 0, top: 0, opacity: outOpacity, filter: \`blur(\${outBlur}px)\`}}>- {WORDS[currentStep]}- </div>- <div style={{position: "absolute", left: 0, top: 0, opacity: inOpacity, filter: \`blur(\${inBlur}px)\`}}>- {WORDS[nextStep]}- </div>- </>- )}+import { useCurrentFrame, AbsoluteFill, interpolate } from "remotion";++export const MyAnimation = () => {+ /*+ * Prefix text with rotating words that crossfade with blur.+ */+ const frame = useCurrentFrame();++ const COLOR_TEXT = "#7b92c1";+ const PREFIX = "Created for";+ const WORDS = ["Creators", "Marketers", "Developers", "Everyone"];++ const PREFIX_FONT_SIZE = 80;+ const WORD_FONT_SIZE = 80;+ const PREFIX_WEIGHT = 300;+ const WORD_WEIGHT = 700;+ const WORD_GAP = 20;+ const HOLD_DURATION = 32;+ const FLIP_DURATION = 18;+ const BLUR_AMOUNT = 6;++ const perStep = HOLD_DURATION + FLIP_DURATION;+ const totalSteps = WORDS.length;+ const currentStep = Math.floor(frame / perStep) % totalSteps;+ const nextStep = (currentStep + 1) % totalSteps;+ const phase = frame % perStep;+ const isFlipping = phase >= HOLD_DURATION;+ const flipProgress = isFlipping ? (phase - HOLD_DURATION) / FLIP_DURATION : 0;++ const outOpacity = interpolate(flipProgress, [0, 1], [1, 0], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});+ const inOpacity = interpolate(flipProgress, [0, 1], [0, 1], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});+ const outBlur = interpolate(flipProgress, [0, 1], [0, BLUR_AMOUNT], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});+ const inBlur = interpolate(flipProgress, [0, 1], [BLUR_AMOUNT, 0], {extrapolateLeft: "clamp", extrapolateRight: "clamp"});++ // Find longest word for stable width+ const longestWord = WORDS.reduce((a, b) => a.length >= b.length ? a : b, WORDS[0]);++ return (+ <AbsoluteFill style={{display: "flex", alignItems: "center", justifyContent: "center"}}>+ <div style={{display: "flex", alignItems: "baseline", gap: WORD_GAP, color: COLOR_TEXT}}>+ <div style={{fontSize: PREFIX_FONT_SIZE, fontWeight: PREFIX_WEIGHT}}>{PREFIX}</div>+ <div style={{position: "relative", fontSize: WORD_FONT_SIZE, fontWeight: WORD_WEIGHT}}>+ {/* Invisible width keeper */}+ <div style={{visibility: "hidden"}}>{longestWord}</div>+ {/* Current word (fades out during flip) */}+ {!isFlipping && (+ <div style={{position: "absolute", left: 0, top: 0}}>{WORDS[currentStep]}</div>+ )}+ {/* Crossfade during flip */}+ {isFlipping && (+ <>+ <div style={{position: "absolute", left: 0, top: 0, opacity: outOpacity, filter: \`blur(\${outBlur}px)\`}}>+ {WORDS[currentStep]}+ </div>+ <div style={{position: "absolute", left: 0, top: 0, opacity: inOpacity, filter: \`blur(\${inBlur}px)\`}}>+ {WORDS[nextStep]}+ </div>+ </>+ )}+ </div></div>- </div>- </AbsoluteFill>-);+ </AbsoluteFill>+ );+};---@@ -322,199 +346,217 @@ EXAMPLE 4: Animated bar chart / histogramPrompt: "An animated histogram with the gold price. Focus on simplicity and elegance. Small headline, all bars are well laid out"-/*- * Elegant animated bar chart showing gold prices with Y-axis, staggered spring animations, and full-width layout.- */-const frame = useCurrentFrame();-const { fps, height: videoHeight } = useVideoConfig();--const TITLE = "Gold Price 2024";-const UNIT = "USD per troy ounce";-const COLOR_BAR = "#D4AF37";-const COLOR_TEXT = "#ffffff";-const COLOR_MUTED = "#888888";-const COLOR_BG = "#0a0a0a";-const COLOR_AXIS = "#333333";--const PADDING = 50;-const HEADER_HEIGHT = 70;-const LABEL_HEIGHT = 32;-const BAR_GAP = 8;-const BAR_RADIUS = 4;-const TITLE_FONT_SIZE = 24;-const LABEL_FONT_SIZE = 11;-const VALUE_FONT_SIZE = 11;-const AXIS_FONT_SIZE = 12;-const STAGGER_DELAY = 5;-const HEADER_START_FRAME = 0;-const BARS_START_FRAME = 10;-const SPRING_DAMPING = 18;-const SPRING_STIFFNESS = 80;--const data = [- { month: "Jan", price: 2039 },- { month: "Feb", price: 2024 },- { month: "Mar", price: 2160 },- { month: "Apr", price: 2330 },- { month: "May", price: 2327 },- { month: "Jun", price: 2339 },- { month: "Jul", price: 2426 },- { month: "Aug", price: 2503 },- { month: "Sep", price: 2634 },- { month: "Oct", price: 2735 },- { month: "Nov", price: 2672 },- { month: "Dec", price: 2650 },-];--const minPrice = 1900;-const maxPrice = 2800;-const priceRange = maxPrice - minPrice;-const chartHeight = videoHeight - (PADDING * 2) - HEADER_HEIGHT - LABEL_HEIGHT;-const yAxisSteps = [1900, 2100, 2300, 2500, 2700];--const headerOpacity = spring({- frame: frame - HEADER_START_FRAME,- fps,- config: { damping: 20, stiffness: 100 },-});--return (- <AbsoluteFill- style={{- backgroundColor: COLOR_BG,- padding: PADDING,- display: "flex",- flexDirection: "column",- fontFamily: "Inter, sans-serif",- }}- >- {/* Header */}- <div style={{ height: HEADER_HEIGHT, opacity: headerOpacity, marginBottom: 10 }}>- <div style={{ color: COLOR_TEXT, fontSize: TITLE_FONT_SIZE, fontWeight: 600 }}>{TITLE}</div>- <div style={{ color: COLOR_MUTED, fontSize: 14, marginTop: 4 }}>{UNIT}</div>- </div>-- {/* Chart container */}- <div style={{ display: "flex", alignItems: "flex-end", width: "100%", flex: 1 }}>- {/* Y-Axis */}- <div- style={{- display: "flex",- flexDirection: "column",- justifyContent: "space-between",- height: chartHeight,- paddingRight: 12,- marginBottom: LABEL_HEIGHT,- }}- >- {yAxisSteps.slice().reverse().map((step) => (- <div- key={step}- style={{- color: COLOR_MUTED,- fontSize: AXIS_FONT_SIZE,- textAlign: "right",- minWidth: 40,- }}- >- {step.toLocaleString()}- </div>- ))}+import { useCurrentFrame, useVideoConfig, AbsoluteFill, spring } from "remotion";++export const MyAnimation = () => {+ /*+ * Elegant animated bar chart showing gold prices with Y-axis, staggered spring animations, and full-width layout.+ */+ const frame = useCurrentFrame();+ const { fps, height: videoHeight } = useVideoConfig();++ const TITLE = "Gold Price 2024";+ const UNIT = "USD per troy ounce";+ const COLOR_BAR = "#D4AF37";+ const COLOR_TEXT = "#ffffff";+ const COLOR_MUTED = "#888888";+ const COLOR_BG = "#0a0a0a";+ const COLOR_AXIS = "#333333";++ const PADDING = 50;+ const HEADER_HEIGHT = 70;+ const LABEL_HEIGHT = 32;+ const BAR_GAP = 8;+ const BAR_RADIUS = 4;+ const TITLE_FONT_SIZE = 24;+ const LABEL_FONT_SIZE = 11;+ const VALUE_FONT_SIZE = 11;+ const AXIS_FONT_SIZE = 12;+ const STAGGER_DELAY = 5;+ const HEADER_START_FRAME = 0;+ const BARS_START_FRAME = 10;+ const SPRING_DAMPING = 18;+ const SPRING_STIFFNESS = 80;++ const data = [+ { month: "Jan", price: 2039 },+ { month: "Feb", price: 2024 },+ { month: "Mar", price: 2160 },+ { month: "Apr", price: 2330 },+ { month: "May", price: 2327 },+ { month: "Jun", price: 2339 },+ { month: "Jul", price: 2426 },+ { month: "Aug", price: 2503 },+ { month: "Sep", price: 2634 },+ { month: "Oct", price: 2735 },+ { month: "Nov", price: 2672 },+ { month: "Dec", price: 2650 },+ ];++ const minPrice = 1900;+ const maxPrice = 2800;+ const priceRange = maxPrice - minPrice;+ const chartHeight = videoHeight - (PADDING * 2) - HEADER_HEIGHT - LABEL_HEIGHT;+ const yAxisSteps = [1900, 2100, 2300, 2500, 2700];++ const headerOpacity = spring({+ frame: frame - HEADER_START_FRAME,+ fps,+ config: { damping: 20, stiffness: 100 },+ });++ return (+ <AbsoluteFill+ style={{+ backgroundColor: COLOR_BG,+ padding: PADDING,+ display: "flex",+ flexDirection: "column",+ fontFamily: "Inter, sans-serif",+ }}+ >+ {/* Header */}+ <div style={{ height: HEADER_HEIGHT, opacity: headerOpacity, marginBottom: 10 }}>+ <div style={{ color: COLOR_TEXT, fontSize: TITLE_FONT_SIZE, fontWeight: 600 }}>{TITLE}</div>+ <div style={{ color: COLOR_MUTED, fontSize: 14, marginTop: 4 }}>{UNIT}</div></div>- {/* Chart area */}- <div- style={{- display: "flex",- alignItems: "flex-end",- gap: BAR_GAP,- height: chartHeight,- flex: 1,- borderLeft: \`1px solid \${COLOR_AXIS}\`,- borderBottom: \`1px solid \${COLOR_AXIS}\`,- paddingLeft: 8,- }}- >- {data.map((item, i) => {- const delay = i * STAGGER_DELAY;- const progress = spring({- frame: frame - delay - BARS_START_FRAME,- fps,- config: { damping: SPRING_DAMPING, stiffness: SPRING_STIFFNESS },- });-- const normalizedHeight = ((item.price - minPrice) / priceRange) * chartHeight;- const height = normalizedHeight * progress;-- return (+ {/* Chart container */}+ <div style={{ display: "flex", alignItems: "flex-end", width: "100%", flex: 1 }}>+ {/* Y-Axis */}+ <div+ style={{+ display: "flex",+ flexDirection: "column",+ justifyContent: "space-between",+ height: chartHeight,+ paddingRight: 12,+ marginBottom: LABEL_HEIGHT,+ }}+ >+ {yAxisSteps.slice().reverse().map((step) => (<div- key={i}+ key={step}style={{- textAlign: "center",- flex: 1,- height: "100%",- display: "flex",- flexDirection: "column",- justifyContent: "flex-end",+ color: COLOR_MUTED,+ fontSize: AXIS_FONT_SIZE,+ textAlign: "right",+ minWidth: 40,}}>+ {step.toLocaleString()}+ </div>+ ))}+ </div>++ {/* Chart area */}+ <div+ style={{+ display: "flex",+ alignItems: "flex-end",+ gap: BAR_GAP,+ height: chartHeight,+ flex: 1,+ borderLeft: \`1px solid \${COLOR_AXIS}\`,+ borderBottom: \`1px solid \${COLOR_AXIS}\`,+ paddingLeft: 8,+ }}+ >+ {data.map((item, i) => {+ const delay = i * STAGGER_DELAY;+ const progress = spring({+ frame: frame - delay - BARS_START_FRAME,+ fps,+ config: { damping: SPRING_DAMPING, stiffness: SPRING_STIFFNESS },+ });++ const normalizedHeight = ((item.price - minPrice) / priceRange) * chartHeight;+ const height = normalizedHeight * progress;++ return (<div+ key={i}style={{- width: "100%",- height,- backgroundColor: COLOR_BAR,- borderRadius: \`\${BAR_RADIUS}px \${BAR_RADIUS}px 0 0\`,+ textAlign: "center",+ flex: 1,+ height: "100%",display: "flex",- justifyContent: "center",- alignItems: "flex-start",- paddingTop: 6,- minHeight: height > 0 ? 4 : 0,- }}- >- {height > 30 && (- <span- style={{- color: COLOR_BG,- fontSize: VALUE_FONT_SIZE,- fontWeight: 600,- opacity: progress,- }}- >- {item.price.toLocaleString()}- </span>- )}- </div>- <div- style={{- color: COLOR_MUTED,- fontSize: LABEL_FONT_SIZE,- marginTop: 8,- height: LABEL_HEIGHT - 8,+ flexDirection: "column",+ justifyContent: "flex-end",}}>- {item.month}+ <div+ style={{+ width: "100%",+ height,+ backgroundColor: COLOR_BAR,+ borderRadius: \`\${BAR_RADIUS}px \${BAR_RADIUS}px 0 0\`,+ display: "flex",+ justifyContent: "center",+ alignItems: "flex-start",+ paddingTop: 6,+ minHeight: height > 0 ? 4 : 0,+ }}+ >+ {height > 30 && (+ <span+ style={{+ color: COLOR_BG,+ fontSize: VALUE_FONT_SIZE,+ fontWeight: 600,+ opacity: progress,+ }}+ >+ {item.price.toLocaleString()}+ </span>+ )}+ </div>+ <div+ style={{+ color: COLOR_MUTED,+ fontSize: LABEL_FONT_SIZE,+ marginTop: 8,+ height: LABEL_HEIGHT - 8,+ }}+ >+ {item.month}+ </div></div>- </div>- );- })}+ );+ })}+ </div></div>- </div>- </AbsoluteFill>-);+ </AbsoluteFill>+ );+};----END OF EXAMPLESIMPORTANT RULES:-- Start the code with a multi-line comment (/* */) containing a 2-3 sentence description of what you're building-- NEVER include imports or exports - they are provided automatically-- Available APIs: React, AbsoluteFill, interpolate, useCurrentFrame, useVideoConfig, spring, Sequence+- Start with proper ES6 imports, then export the component as: export const MyAnimation = () => {...}+- Start the component body with a multi-line comment (/* */) containing a 2-3 sentence description of what you're building+- ALWAYS include the necessary imports at the top of the file++AVAILABLE IMPORTS (use exactly these import statements):+- import { useCurrentFrame, useVideoConfig, AbsoluteFill, interpolate, spring, Sequence } from "remotion";+- import { Circle, Rect, Triangle, Star, Ellipse, Pie } from "@remotion/shapes";+- import { Lottie } from "@remotion/lottie";+- import { ThreeCanvas } from "@remotion/three";++REACT HOOKS:+- Import React hooks using named imports: import { useState, useEffect } from "react";+- Example: const [data, setData] = useState(null);++EXPORT FORMAT:+- Always export as: export const MyAnimation = () => { ... };+- Do not use default exports+- Use creative animations with smooth transitions- Component should use frame-based animations with interpolate()- Make it visually impressive and modern- Use inline styles for all styling- ALWAYS use fontFamily: 'Inter, sans-serif' for ALL text elements to ensure consistent rendering-- Do not define the component name - start directly with the comment, then the code- Do not generate typescript types or interfaces- ALWAYS make sure to show all contents on the screen WITHOUT going off-screen or being cut off- ALWAYS set backgroundColor on AbsoluteFill from frame 0 - never fade in backgroundsdiff --git a/packages/template-code-generation/src/app/code-examples/page.tsx b/packages/template-code-generation/src/app/code-examples/page.tsxindex 7f9d9b83bf..81a6850fe8 100644--- a/packages/template-code-generation/src/app/code-examples/page.tsx+++ b/packages/template-code-generation/src/app/code-examples/page.tsx@@ -1,6 +1,13 @@"use client";-import { useState, useCallback, useMemo, Suspense, useEffect, useRef } from "react";+import {+ useState,+ useCallback,+ useMemo,+ Suspense,+ useEffect,+ useRef,+} from "react";import Link from "next/link";import { useSearchParams, useRouter } from "next/navigation";import { ArrowLeft, PanelLeftClose, PanelLeft } from "lucide-react";@@ -45,7 +52,9 @@ function DemoPageContent() {if (example) {setCode(example.code);compileCode(example.code);- router.replace(`/code-examples?example=${exampleId}`, { scroll: false });+ router.replace(`/code-examples?example=${exampleId}`, {+ scroll: false,+ });}},[setCode, compileCode, router],@@ -59,10 +68,10 @@ function DemoPageContent() {[setCode, compileCode],);- const categories = [...new Set(examples.map((e) => e.category))];+ const categories = Array.from(new Set(examples.map((e) => e.category)));return (- <div className="h-screen w-screen bg-[#0a0a0a] flex flex-col">+ <div className="h-screen w-screen bg-[#0a0a0a] flex flex-col [&_::-webkit-scrollbar]:w-1.5 [&_::-webkit-scrollbar-track]:bg-transparent [&_::-webkit-scrollbar-thumb]:bg-[#333] [&_::-webkit-scrollbar-thumb]:rounded-full hover:[&_::-webkit-scrollbar-thumb]:bg-[#444]">{/* Header with logo */}<header className="flex items-center gap-6 py-8 px-12 shrink-0"><div className="flex flex-col gap-2">@@ -83,7 +92,7 @@ function DemoPageContent() {<div className="flex-1 flex overflow-hidden px-12">{/* Sidebar */}<div- className={`border-r border-[#222] flex flex-col shrink-0 transition-all duration-300 overflow-hidden ${+ className={`flex flex-col shrink-0 transition-all duration-300 overflow-hidden ${sidebarOpen ? "w-64 mr-8" : "w-0 border-r-0"}`}>@@ -101,7 +110,11 @@ function DemoPageContent() {.map((example) => (<buttonkey={example.id}- ref={selectedExample.id === example.id ? selectedButtonRef : null}+ ref={+ selectedExample.id === example.id+ ? selectedButtonRef+ : null+ }onClick={() => handleExampleSelect(example.id)}className={`w-full text-left p-3 rounded-lg border transition-all ${selectedExample.id === example.id@@ -109,7 +122,9 @@ function DemoPageContent() {: "border-[#222] bg-[#111] text-gray-400 hover:border-[#333] hover:bg-[#1a1a1a]"}`}>- <div className="font-medium text-sm">{example.name}</div>+ <div className="font-medium text-sm">+ {example.name}+ </div><div className="text-xs text-[#666] mt-1 line-clamp-2">{example.description}</div>@@ -139,7 +154,9 @@ function DemoPageContent() {<h2 className="text-lg font-semibold text-white">{selectedExample.name}</h2>- <p className="text-sm text-[#666]">{selectedExample.description}</p>+ <p className="text-sm text-[#666]">+ {selectedExample.description}+ </p></div></div>diff --git a/packages/template-code-generation/src/components/CodeEditor/CodeEditor.tsx b/packages/template-code-generation/src/components/CodeEditor/CodeEditor.tsxindex e797afc87b..bdffb70cb2 100644--- a/packages/template-code-generation/src/components/CodeEditor/CodeEditor.tsx+++ b/packages/template-code-generation/src/components/CodeEditor/CodeEditor.tsx@@ -11,7 +11,6 @@ import {import { EditorHeader } from "./EditorHeader";import { StreamingOverlay } from "./StreamingOverlay";-import { ReadOnlyToast } from "./ReadOnlyToast";import { EDITOR_STYLES } from "./styles";// Monaco must be loaded client-side only@@ -33,18 +32,6 @@ interface CodeEditorProps {streamPhase?: StreamPhase;}-const WRAPPER_PREFIX = `import * as Remotion from 'remotion';--export const MyAnimation = () => {-`;--const WRAPPER_SUFFIX = `-};`;--// Calculate line counts for wrapper boundaries-const PREFIX_LINE_COUNT = WRAPPER_PREFIX.split("\n").length - 1;-const SUFFIX_LINE_COUNT = WRAPPER_SUFFIX.split("\n").length - 1;-export const CodeEditor: React.FC<CodeEditorProps> = ({code,onChange,@@ -54,19 +41,14 @@ export const CodeEditor: React.FC<CodeEditorProps> = ({const monacoRef = useRef<Monaco | null>(null);const editorRef = useRef<editor.IStandaloneCodeEditor | null>(null);const isStreamingRef = useRef(isStreaming);- const decorationsRef = useRef<editor.IEditorDecorationsCollection | null>(- null,- );- const [showReadOnlyToast, setShowReadOnlyToast] = React.useState(false);- const toastTimeoutRef = useRef<NodeJS.Timeout | null>(null);// Keep ref in sync with prop and clear markers during streaminguseEffect(() => {isStreamingRef.current = isStreaming;}, [isStreaming]);- // Derive language from streaming state- const editorLanguage = isStreaming ? "plaintext" : "javascript";+ // Use typescript for semantic checking, plaintext during streaming+ const editorLanguage = isStreaming ? "plaintext" : "typescript";// Continuously clear markers while streaminguseEffect(() => {@@ -86,44 +68,6 @@ export const CodeEditor: React.FC<CodeEditorProps> = ({return () => clearInterval(interval);}, [isStreaming, code]);- // Apply read-only decorations to prefix and suffix lines- const applyReadOnlyDecorations = (totalLines: number) => {- if (!editorRef.current || !monacoRef.current) return;-- const decorations: editor.IModelDeltaDecoration[] = [];-- // Prefix lines (lines 1 to PREFIX_LINE_COUNT)- for (let i = 1; i <= PREFIX_LINE_COUNT; i++) {- decorations.push({- range: new monacoRef.current.Range(i, 1, i, 1),- options: {- isWholeLine: true,- className: "readonly-line",- },- });- }-- // Suffix lines (last SUFFIX_LINE_COUNT lines)- const suffixStart = totalLines - SUFFIX_LINE_COUNT + 1;- for (let i = suffixStart; i <= totalLines; i++) {- decorations.push({- range: new monacoRef.current.Range(i, 1, i, 1),- options: {- isWholeLine: true,- className: "readonly-line",- },- });- }-- // Use the modern createDecorationsCollection API- if (decorationsRef.current) {- decorationsRef.current.set(decorations);- } else {- decorationsRef.current =- editorRef.current.createDecorationsCollection(decorations);- }- };-const handleEditorMount = (editorInstance: editor.IStandaloneCodeEditor,monaco: Monaco,@@ -134,84 +78,168 @@ export const CodeEditor: React.FC<CodeEditorProps> = ({// eslint-disable-next-line @typescript-eslint/no-explicit-anyconst ts = (monaco.languages as any).typescript;- // Apply initial decorations- const totalLines = (WRAPPER_PREFIX + code + WRAPPER_SUFFIX).split(- "\n",- ).length;- applyReadOnlyDecorations(totalLines);-- // Configure TypeScript compiler options+ // Configure TypeScript compiler options for JSX supportts?.typescriptDefaults?.setCompilerOptions({target: ts.ScriptTarget?.ESNext,module: ts.ModuleKind?.ESNext,- jsx: ts.JsxEmit?.React,- jsxFactory: "React.createElement",+ jsx: ts.JsxEmit?.Preserve,allowNonTsExtensions: true,strict: false,noEmit: true,esModuleInterop: true,+ moduleResolution: ts.ModuleResolutionKind?.NodeJs,+ skipLibCheck: true,+ });++ // Enable semantic validation for import checking+ ts?.typescriptDefaults?.setDiagnosticsOptions({+ noSemanticValidation: false,+ noSyntaxValidation: false,});// Add React types so TS understands JSXts?.typescriptDefaults?.addExtraLib(`declare namespace React {- type ReactNode = string | number | boolean | null | undefined | React.ReactElement | React.ReactNode[];+ type ReactNode = string | number | boolean | null | undefined | ReactElement | ReactNode[];interface ReactElement<P = any> { type: any; props: P; key: string | null; }type FC<P = {}> = (props: P) => ReactElement | null;- type CSSProperties = Record<string, string | number>;- interface HTMLAttributes<T> extends AriaAttributes, DOMAttributes<T> {+ type CSSProperties = { [key: string]: string | number | undefined };+ interface HTMLAttributes<T> {className?: string;style?: CSSProperties;+ children?: ReactNode;+ [key: string]: any;+ }+ interface SVGAttributes<T> {+ className?: string;+ style?: CSSProperties;+ children?: ReactNode;[key: string]: any;}- interface AriaAttributes { [key: string]: any; }- interface DOMAttributes<T> { children?: ReactNode; [key: string]: any; }function createElement(type: any, props?: any, ...children: any[]): ReactElement;+ function useState<T>(initial: T | (() => T)): [T, (value: T | ((prev: T) => T)) => void];+ function useEffect(effect: () => void | (() => void), deps?: any[]): void;+ function useCallback<T extends (...args: any[]) => any>(callback: T, deps: any[]): T;+ function useMemo<T>(factory: () => T, deps: any[]): T;+ function useRef<T>(initial: T): { current: T };}declare const React: typeof React;+ declare namespace JSX {+ interface Element extends React.ReactElement<any, any> {}+ interface IntrinsicElements {+ div: React.HTMLAttributes<HTMLDivElement>;+ span: React.HTMLAttributes<HTMLSpanElement>;+ p: React.HTMLAttributes<HTMLParagraphElement>;+ h1: React.HTMLAttributes<HTMLHeadingElement>;+ h2: React.HTMLAttributes<HTMLHeadingElement>;+ h3: React.HTMLAttributes<HTMLHeadingElement>;+ img: React.HTMLAttributes<HTMLImageElement> & { src?: string; alt?: string };+ svg: React.SVGAttributes<SVGSVGElement>;+ path: React.SVGAttributes<SVGPathElement> & { d?: string };+ circle: React.SVGAttributes<SVGCircleElement> & { cx?: number; cy?: number; r?: number };+ rect: React.SVGAttributes<SVGRectElement> & { x?: number; y?: number; width?: number; height?: number };+ polygon: React.SVGAttributes<SVGPolygonElement> & { points?: string };+ line: React.SVGAttributes<SVGLineElement> & { x1?: number; y1?: number; x2?: number; y2?: number };+ text: React.SVGAttributes<SVGTextElement> & { x?: number; y?: number };+ g: React.SVGAttributes<SVGGElement>;+ defs: React.SVGAttributes<SVGDefsElement>;+ filter: React.SVGAttributes<SVGFilterElement> & { id?: string };+ feGaussianBlur: React.SVGAttributes<SVGFEGaussianBlurElement> & { stdDeviation?: number | string; result?: string };+ feMerge: React.SVGAttributes<SVGFEMergeElement>;+ feMergeNode: React.SVGAttributes<SVGFEMergeNodeElement> & { in?: string };+ mesh: any;+ group: any;+ ambientLight: any;+ pointLight: any;+ sphereGeometry: any;+ meshStandardMaterial: any;+ planeGeometry: any;+ [elemName: string]: any;+ }+ }`,"react.d.ts",);- // Add type declaration for remotion module+ // Add module declaration for 'react' to allow imports+ ts?.typescriptDefaults?.addExtraLib(+ `declare module 'react' {+ export const useState: typeof React.useState;+ export const useEffect: typeof React.useEffect;+ export const useCallback: typeof React.useCallback;+ export const useMemo: typeof React.useMemo;+ export const useRef: typeof React.useRef;+ export default React;+ }`,+ "react-module.d.ts",+ );++ // Add type declarations for all whitelisted librariests?.typescriptDefaults?.addExtraLib(`declare module 'remotion' {export const AbsoluteFill: React.FC<React.HTMLAttributes<HTMLDivElement>>;export function useCurrentFrame(): number;export function useVideoConfig(): { fps: number; durationInFrames: number; width: number; height: number };export function interpolate(input: number, inputRange: number[], outputRange: number[], options?: any): number;- export function spring(options: { frame: number; fps: number; config?: any }): number;+ export function spring(options: { frame: number; fps: number; config?: any; durationInFrames?: number }): number;export const Sequence: React.FC<{ from?: number; durationInFrames?: number; children: React.ReactNode }>;}`,"remotion.d.ts",);- // Block editing in protected lines by intercepting model changes- const model = editorInstance.getModel();- if (model) {- let lastValidContent = model.getValue();+ ts?.typescriptDefaults?.addExtraLib(+ `declare module '@remotion/shapes' {+ interface ShapeProps {+ fill?: string;+ stroke?: string;+ strokeWidth?: number;+ style?: React.CSSProperties;+ }+ export const Rect: React.FC<ShapeProps & { width: number; height: number; cornerRadius?: number }>;+ export const Circle: React.FC<ShapeProps & { radius: number }>;+ export const Triangle: React.FC<ShapeProps & { length: number; direction?: 'up' | 'down' | 'left' | 'right' }>;+ export const Star: React.FC<ShapeProps & { innerRadius: number; outerRadius: number; points?: number }>;+ export const Polygon: React.FC<ShapeProps & { radius: number; points: number }>;+ export const Ellipse: React.FC<ShapeProps & { rx: number; ry: number }>;+ }`,+ "remotion-shapes.d.ts",+ );- model.onDidChangeContent(() => {- const currentContent = model.getValue();- const hasValidPrefix = currentContent.startsWith(WRAPPER_PREFIX);- const hasValidSuffix = currentContent.endsWith(WRAPPER_SUFFIX);+ ts?.typescriptDefaults?.addExtraLib(+ `declare module '@remotion/lottie' {+ export const Lottie: React.FC<{ animationData?: any; src?: string; playbackRate?: number; style?: React.CSSProperties }>;+ }`,+ "remotion-lottie.d.ts",+ );- if (!hasValidPrefix || !hasValidSuffix) {- model.setValue(lastValidContent);+ ts?.typescriptDefaults?.addExtraLib(+ `declare module '@remotion/three' {+ export const ThreeCanvas: React.FC<{+ children?: any;+ style?: React.CSSProperties;+ width?: number;+ height?: number;+ camera?: { position?: number[]; fov?: number; near?: number; far?: number; [key: string]: any };+ orthographic?: boolean;+ [key: string]: any;+ }>;+ }`,+ "remotion-three.d.ts",+ );- if (toastTimeoutRef.current) {- clearTimeout(toastTimeoutRef.current);- }- setShowReadOnlyToast(true);- toastTimeoutRef.current = setTimeout(() => {- setShowReadOnlyToast(false);- }, 2000);- } else {- lastValidContent = currentContent;- }- });- }+ ts?.typescriptDefaults?.addExtraLib(+ `declare module 'three' {+ export class Vector3 { constructor(x?: number, y?: number, z?: number); x: number; y: number; z: number; }+ export class Color { constructor(color?: string | number); }+ export class MeshStandardMaterial { constructor(params?: any); }+ export class BoxGeometry { constructor(width?: number, height?: number, depth?: number); }+ export class SphereGeometry { constructor(radius?: number, widthSegments?: number, heightSegments?: number); }+ export class Mesh { constructor(geometry?: any, material?: any); position: Vector3; rotation: Vector3; }+ export const DoubleSide: number;+ }`,+ "three.d.ts",+ );// Override marker setting to suppress during streamingconst originalSetModelMarkers = monaco.editor.setModelMarkers;@@ -236,65 +264,28 @@ export const CodeEditor: React.FC<CodeEditorProps> = ({});};- // Wrap the body code with prefix/suffix for display- const displayCode = WRAPPER_PREFIX + code + WRAPPER_SUFFIX;-- // Extract body from full code when user edits, restore wrapper if modified+ // Simple pass-through: code is displayed and edited as-isconst handleChange = (value: string | undefined) => {- if (!value) {- onChange("");- return;- }-- const hasValidPrefix = value.startsWith(WRAPPER_PREFIX);- const hasValidSuffix = value.endsWith(WRAPPER_SUFFIX);-- // If wrapper was modified, restore it- if (!hasValidPrefix || !hasValidSuffix) {- let body = value;- if (hasValidPrefix) {- body = body.slice(WRAPPER_PREFIX.length);- }- if (hasValidSuffix) {- body = body.slice(0, -WRAPPER_SUFFIX.length);- }-- const restoredCode = WRAPPER_PREFIX + body + WRAPPER_SUFFIX;- editorRef.current?.setValue(restoredCode);-- const totalLines = restoredCode.split("\n").length;- applyReadOnlyDecorations(totalLines);-- onChange(body);- return;- }-- // Normal case: wrapper intact, extract body- const body = value.slice(WRAPPER_PREFIX.length, -WRAPPER_SUFFIX.length);-- const totalLines = value.split("\n").length;- applyReadOnlyDecorations(totalLines);-- onChange(body);+ onChange(value || "");};return (<div className="flex-2 h-full flex flex-col"><h2 className="text-sm font-medium text-[#888] mb-3">Remotion Code</h2><div className="flex-1 flex flex-col bg-[#1e1e1e] rounded-lg overflow-hidden">- <EditorHeader filename="MyAnimation.tsx" code={displayCode} />+ <EditorHeader filename="MyAnimation.tsx" code={code} /><style>{EDITOR_STYLES}</style><div className="flex-1 overflow-hidden relative"><StreamingOverlayvisible={isStreaming}message={streamPhase === "reasoning" ? "Thinking..." : "Generating code..."}/>- <ReadOnlyToast visible={showReadOnlyToast} /><MonacoEditorheight="100%"language={editorLanguage}theme="vs-dark"- value={displayCode}+ path="MyAnimation.tsx"+ value={code}onChange={handleChange}onMount={handleEditorMount}options={{diff --git a/packages/template-code-generation/src/hooks/useCodeCompiler.ts b/packages/template-code-generation/src/hooks/useCodeCompiler.tsindex c61887ceb4..78a6af6361 100644--- a/packages/template-code-generation/src/hooks/useCodeCompiler.ts+++ b/packages/template-code-generation/src/hooks/useCodeCompiler.ts@@ -1,6 +1,6 @@"use client";-import { useCallback } from "react";+import { useCallback, useState, useEffect, useMemo, useRef } from "react";import * as Babel from "@babel/standalone";import React from "react";import {@@ -21,6 +21,27 @@ export interface CompilationResult {error: string | null;}+// Extract component body from full ES6 code with imports+function extractComponentBody(code: string): string {+ // Strip import lines+ const lines = code.split("\n");+ const nonImportLines = lines.filter(+ (line) => !line.trim().startsWith("import ")+ );+ const codeWithoutImports = nonImportLines.join("\n");++ // Extract body from "export const MyAnimation = () => { ... };"+ const match = codeWithoutImports.match(+ /export\s+const\s+\w+\s*=\s*\(\s*\)\s*=>\s*\{([\s\S]*)\};?\s*$/+ );+ if (match) {+ return match[1].trim();+ }++ // Fallback: return code as-is (backward compatible with body-only input)+ return code;+}+export function useCodeCompiler() {const compile = useCallback((code: string): CompilationResult => {if (!code.trim()) {@@ -28,9 +49,11 @@ export function useCodeCompiler() {}try {+ // Extract component body (handles both full ES6 code and body-only)+ const componentBody = extractComponentBody(code);+// Wrap the component body in a function BEFORE transpilation- // Expected input: just the component body (hooks, variables, and return statement)- const wrappedSource = `const DynamicAnimation = () => {\n${code}\n};`;+ const wrappedSource = `const DynamicAnimation = () => {\n${componentBody}\n};`;// Transpile JSX/TypeScript to JavaScript using Babelconst transpiled = Babel.transform(wrappedSource, {@@ -68,6 +91,26 @@ export function useCodeCompiler() {"useVideoConfig","spring","Sequence",+ "useState",+ "useEffect",+ "useMemo",+ "useRef",+ "Rect",+ "Circle",+ "Triangle",+ "Star",+ "Polygon",+ "Ellipse",+ "Heart",+ "Pie",+ "makeRect",+ "makeCircle",+ "makeTriangle",+ "makeStar",+ "makePolygon",+ "makeEllipse",+ "makeHeart",+ "makePie",wrappedCode,);@@ -84,6 +127,26 @@ export function useCodeCompiler() {useVideoConfig,spring,Sequence,+ useState,+ useEffect,+ useMemo,+ useRef,+ RemotionShapes.Rect,+ RemotionShapes.Circle,+ RemotionShapes.Triangle,+ RemotionShapes.Star,+ RemotionShapes.Polygon,+ RemotionShapes.Ellipse,+ RemotionShapes.Heart,+ RemotionShapes.Pie,+ RemotionShapes.makeRect,+ RemotionShapes.makeCircle,+ RemotionShapes.makeTriangle,+ RemotionShapes.makeStar,+ RemotionShapes.makePolygon,+ RemotionShapes.makeEllipse,+ RemotionShapes.makeHeart,+ RemotionShapes.makePie,);if (typeof Component !== "function") {diff --git a/packages/template-code-generation/src/templates/animated-shapes.ts b/packages/template-code-generation/src/templates/animated-shapes.tsnew file mode 100644index 0000000000..cf53f9b6f7--- /dev/null+++ b/packages/template-code-generation/src/templates/animated-shapes.ts@@ -0,0 +1,93 @@+import { RemotionExample } from "./index";++export const animatedShapesCode = `import { AbsoluteFill, useCurrentFrame, useVideoConfig, spring, interpolate } from "remotion";+import { Circle, Triangle, Rect, Star } from "@remotion/shapes";++export const MyAnimation = () => {+ const frame = useCurrentFrame();+ const { fps, width, height } = useVideoConfig();++ const shapes = [+ { type: "circle", color: "#6366f1", delay: 0 },+ { type: "triangle", color: "#10b981", delay: 15 },+ { type: "rect", color: "#f59e0b", delay: 30 },+ { type: "star", color: "#ec4899", delay: 45 },+ ];++ return (+ <AbsoluteFill+ style={{+ backgroundColor: "#0f0f0f",+ justifyContent: "center",+ alignItems: "center",+ }}+ >+ <div+ style={{+ display: "flex",+ gap: 80,+ alignItems: "center",+ }}+ >+ {shapes.map((shape, i) => {+ const entrance = spring({+ frame: frame - shape.delay,+ fps,+ config: { damping: 12, stiffness: 200 },+ });++ const rotation = interpolate(+ frame,+ [0, 180],+ [0, 360],+ { extrapolateRight: "clamp" }+ );++ const bounce = Math.sin((frame - shape.delay) * 0.1) * 10;++ const scale = entrance;+ const opacity = entrance;++ const shapeProps = {+ fill: shape.color,+ stroke: "#fff",+ strokeWidth: 2,+ };++ return (+ <div+ key={i}+ style={{+ opacity,+ transform: \`scale(\${scale}) translateY(\${bounce}px) rotate(\${shape.type === "star" ? rotation : 0}deg)\`,+ }}+ >+ {shape.type === "circle" && (+ <Circle radius={60} {...shapeProps} />+ )}+ {shape.type === "triangle" && (+ <Triangle length={120} direction="up" {...shapeProps} />+ )}+ {shape.type === "rect" && (+ <Rect width={100} height={100} cornerRadius={12} {...shapeProps} />+ )}+ {shape.type === "star" && (+ <Star points={5} innerRadius={40} outerRadius={70} {...shapeProps} />+ )}+ </div>+ );+ })}+ </div>+ </AbsoluteFill>+ );+};`;++export const animatedShapesExample: RemotionExample = {+ id: "animated-shapes",+ name: "Animated Shapes",+ description: "Bouncing and rotating SVG shapes with spring animations",+ category: "Other",+ durationInFrames: 180,+ fps: 30,+ code: animatedShapesCode,+};diff --git a/packages/template-code-generation/src/templates/chat-messages.ts b/packages/template-code-generation/src/templates/chat-messages.tsnew file mode 100644index 0000000000..fee14679d3--- /dev/null+++ b/packages/template-code-generation/src/templates/chat-messages.ts@@ -0,0 +1,83 @@+import { RemotionExample } from "./index";++export const chatMessagesCode = `import { AbsoluteFill, useCurrentFrame, useVideoConfig, spring } from "remotion";++export const MyAnimation = () => {+ const frame = useCurrentFrame();+ const { fps } = useVideoConfig();++ const messages = [+ { text: "Hey! How are you?", isMe: false, delay: 0 },+ { text: "I'm good! Working on Remotion", isMe: true, delay: 45 },+ { text: "That's awesome! Show me!", isMe: false, delay: 90 },+ { text: "Check this out!", isMe: true, delay: 135 },+ ];++ const visibleMessages = messages.filter((msg) => frame >= msg.delay);+ const messageHeight = 100;++ return (+ <AbsoluteFill+ style={{+ backgroundColor: "#0a0a0a",+ padding: 60,+ justifyContent: "flex-end",+ paddingBottom: 80,+ }}+ >+ <div style={{ width: "100%", position: "relative" }}>+ {messages.map((msg, i) => {+ const progress = spring({+ frame: frame - msg.delay,+ fps,+ config: { damping: 12, stiffness: 200 },+ });++ if (frame < msg.delay) return null;++ const messagesAfter = messages.filter((m, idx) => idx > i && frame >= m.delay).length;+ const yOffset = messagesAfter * messageHeight;++ const xOffset = msg.isMe ? (1 - progress) * 100 : (1 - progress) * -100;++ return (+ <div+ key={i}+ style={{+ display: "flex",+ justifyContent: msg.isMe ? "flex-end" : "flex-start",+ marginBottom: 24,+ opacity: progress,+ transform: \`translateX(\${xOffset}px) translateY(\${-yOffset}px) scale(\${0.8 + progress * 0.2})\`,+ }}+ >+ <div+ style={{+ backgroundColor: msg.isMe ? "#25D366" : "#2a2a2a",+ color: "#fff",+ padding: "20px 28px",+ borderRadius: 24,+ fontSize: 42,+ fontFamily: "system-ui, sans-serif",+ maxWidth: "70%",+ }}+ >+ {msg.text}+ </div>+ </div>+ );+ })}+ </div>+ </AbsoluteFill>+ );+};`;++export const chatMessagesExample: RemotionExample = {+ id: "chat-messages",+ name: "Chat Messages",+ description: "WhatsApp-style bouncy message bubbles",+ category: "Text",+ durationInFrames: 180,+ fps: 30,+ code: chatMessagesCode,+};diff --git a/packages/template-code-generation/src/templates/counter-animation.ts b/packages/template-code-generation/src/templates/counter-animation.tsnew file mode 100644index 0000000000..77b217ff41--- /dev/null+++ b/packages/template-code-generation/src/templates/counter-animation.ts@@ -0,0 +1,93 @@+import { RemotionExample } from "./index";++export const counterAnimationCode = `import { AbsoluteFill, useCurrentFrame, useVideoConfig, interpolate } from "remotion";++export const MyAnimation = () => {+ const frame = useCurrentFrame();+ const { fps, durationInFrames } = useVideoConfig();++ const metrics = [+ { label: "Users", target: 10000, color: "#4f46e5" },+ { label: "Revenue", target: 50000, prefix: "$", color: "#10b981" },+ { label: "Growth", target: 127, suffix: "%", color: "#f59e0b" },+ ];++ const progress = interpolate(+ frame,+ [0, durationInFrames * 0.7],+ [0, 1],+ { extrapolateRight: "clamp" }+ );++ return (+ <AbsoluteFill+ style={{+ backgroundColor: "#0f0f0f",+ justifyContent: "center",+ alignItems: "center",+ }}+ >+ <div+ style={{+ display: "flex",+ gap: 60,+ }}+ >+ {metrics.map((metric, i) => {+ const staggeredProgress = interpolate(+ progress,+ [i * 0.15, i * 0.15 + 0.7],+ [0, 1],+ { extrapolateLeft: "clamp", extrapolateRight: "clamp" }+ );++ const value = Math.round(metric.target * staggeredProgress);++ return (+ <div+ key={i}+ style={{+ textAlign: "center",+ opacity: interpolate(staggeredProgress, [0, 0.2], [0, 1]),+ transform: \`translateY(\${(1 - staggeredProgress) * 20}px)\`,+ minWidth: 200,+ }}+ >+ <div+ style={{+ fontSize: 72,+ fontWeight: "bold",+ color: metric.color,+ fontFamily: "system-ui, sans-serif",+ fontVariantNumeric: "tabular-nums",+ }}+ >+ {metric.prefix || ""}{value.toLocaleString()}{metric.suffix || ""}+ </div>+ <div+ style={{+ fontSize: 24,+ color: "#888",+ marginTop: 8,+ fontFamily: "system-ui, sans-serif",+ }}+ >+ {metric.label}+ </div>+ </div>+ );+ })}+ </div>+ </AbsoluteFill>+ );+};`;++export const counterAnimationExample: RemotionExample = {+ id: "counter-animation",+ name: "Counter Animation",+ description: "Animated number counters with metrics",+ category: "Charts",+ durationInFrames: 150,+ fps: 30,+ code: counterAnimationCode,+};diff --git a/packages/template-code-generation/src/templates/falling-spheres.ts b/packages/template-code-generation/src/templates/falling-spheres.tsnew file mode 100644index 0000000000..0abe54873e--- /dev/null+++ b/packages/template-code-generation/src/templates/falling-spheres.ts@@ -0,0 +1,116 @@+import { RemotionExample } from "./index";++export const fallingSpheresCode = `import { AbsoluteFill, useCurrentFrame, useVideoConfig } from "remotion";+import { ThreeCanvas } from "@remotion/three";++export const MyAnimation = () => {+ const frame = useCurrentFrame();+ const { width, height, fps } = useVideoConfig();++ const spheres = [+ { x: -1.5, z: -0.5, delay: 0, radius: 0.4, restitution: 0.75 },+ { x: 0, z: 0, delay: 20, radius: 0.5, restitution: 0.75 },+ { x: 1.5, z: 0.5, delay: 40, radius: 0.35, restitution: 0.75 },+ { x: -0.8, z: 1, delay: 60, radius: 0.45, restitution: 0.75 },+ { x: 0.8, z: -1, delay: 80, radius: 0.38, restitution: 0.75 },+ ];++ const gravity = 12;+ const groundY = -2;++ // Realistic bounce physics simulation+ const simulateBounce = (f: number, delay: number, radius: number, restitution: number) => {+ const elapsed = Math.max(0, f - delay);+ const t = elapsed / fps;+ const startY = 6;+ const surfaceY = groundY + radius;++ // Calculate time to first impact+ const firstImpactTime = Math.sqrt(2 * (startY - surfaceY) / gravity);++ if (t <= firstImpactTime) {+ const y = startY - 0.5 * gravity * t * t;+ return { y, squash: 1 };+ }++ // After first impact, simulate bounces+ let currentVelocity = gravity * firstImpactTime;+ let bounceStartTime = firstImpactTime;++ for (let bounce = 0; bounce < 20; bounce++) {+ currentVelocity *= restitution;++ if (currentVelocity < 0.5) {+ return { y: surfaceY, squash: 1 };+ }++ const bounceDuration = 2 * currentVelocity / gravity;+ const timeInBounce = t - bounceStartTime;++ if (timeInBounce <= bounceDuration) {+ const y = surfaceY + currentVelocity * timeInBounce - 0.5 * gravity * timeInBounce * timeInBounce;+ const impactProximity = Math.abs(y - surfaceY);+ const squash = impactProximity < 0.08 ? 0.65 + (impactProximity / 0.08) * 0.35 : 1;+ return { y: Math.max(surfaceY, y), squash };+ }++ bounceStartTime += bounceDuration;+ }++ return { y: surfaceY, squash: 1 };+ };++ return (+ <AbsoluteFill style={{ backgroundColor: "#000000" }}>+ <ThreeCanvas+ width={width}+ height={height}+ camera={{ position: [0, 3, 8], fov: 40 }}+ >+ <ambientLight intensity={0.05} />++ <mesh rotation={[-Math.PI / 2, 0, 0]} position={[0, groundY, 0]}>+ <planeGeometry args={[20, 20]} />+ <meshStandardMaterial color="#0a0a0a" metalness={0.9} roughness={0.3} />+ </mesh>++ {spheres.map((sphere, i) => {+ const { y, squash } = simulateBounce(frame, sphere.delay, sphere.radius, sphere.restitution);+ const stretch = 1 / squash;++ return (+ <group key={i} position={[sphere.x, y, sphere.z]}>+ <pointLight+ color="#ffd700"+ intensity={0.8}+ distance={4}+ decay={2}+ />+ {/* Golden sphere */}+ <mesh scale={[1, squash, stretch]}>+ <sphereGeometry args={[sphere.radius, 32, 32]} />+ <meshStandardMaterial+ color="#ffd700"+ emissive="#cc7a00"+ emissiveIntensity={0.15}+ metalness={0.4}+ roughness={0.6}+ />+ </mesh>+ </group>+ );+ })}+ </ThreeCanvas>+ </AbsoluteFill>+ );+};`;++export const fallingSpheresExample: RemotionExample = {+ id: "falling-spheres",+ name: "Golden Bouncing Spheres",+ description: "Glowing golden spheres with physics and orbiting camera",+ category: "3D",+ durationInFrames: 450,+ fps: 60,+ code: fallingSpheresCode,+};diff --git a/packages/template-code-generation/src/templates/histogram.ts b/packages/template-code-generation/src/templates/histogram.tsnew file mode 100644index 0000000000..0f855cef1a--- /dev/null+++ b/packages/template-code-generation/src/templates/histogram.ts@@ -0,0 +1,103 @@+import { RemotionExample } from "./index";++export const histogramCode = `import { AbsoluteFill, useCurrentFrame, useVideoConfig, spring } from "remotion";+import { Rect } from "@remotion/shapes";++export const MyAnimation = () => {+ const frame = useCurrentFrame();+ const { fps } = useVideoConfig();++ const data = [+ { label: "Mon", value: 65, color: "#6366f1" },+ { label: "Tue", value: 85, color: "#8b5cf6" },+ { label: "Wed", value: 45, color: "#a855f7" },+ { label: "Thu", value: 95, color: "#d946ef" },+ { label: "Fri", value: 75, color: "#ec4899" },+ ];++ const maxValue = Math.max(...data.map(d => d.value));+ const barWidth = 80;++ return (+ <AbsoluteFill+ style={{+ backgroundColor: "#0a0a0a",+ justifyContent: "center",+ alignItems: "flex-end",+ padding: 60,+ paddingBottom: 100,+ }}+ >+ <div+ style={{+ display: "flex",+ alignItems: "flex-end",+ gap: 24,+ height: 400,+ width: "100%",+ justifyContent: "center",+ }}+ >+ {data.map((item, i) => {+ const delay = i * 10;+ const progress = spring({+ frame: frame - delay,+ fps,+ config: { damping: 15, stiffness: 100 },+ });++ const height = Math.max(1, (item.value / maxValue) * 300 * progress);++ return (+ <div key={i} style={{ textAlign: "center", position: "relative" }}>+ <div style={{ position: "relative", height, width: barWidth }}>+ <Rect+ width={barWidth}+ height={height}+ fill={item.color}+ cornerRadius={12}+ style={{ filter: \`drop-shadow(0 0 8px \${item.color}50)\` }}+ />+ <span+ style={{+ position: "absolute",+ top: 10,+ left: "50%",+ transform: "translateX(-50%)",+ color: "#fff",+ fontSize: 18,+ fontWeight: "bold",+ opacity: progress,+ fontFamily: "system-ui, sans-serif",+ }}+ >+ {Math.round(item.value * progress)}+ </span>+ </div>+ <div+ style={{+ color: "#888",+ fontSize: 16,+ marginTop: 12,+ fontFamily: "system-ui, sans-serif",+ }}+ >+ {item.label}+ </div>+ </div>+ );+ })}+ </div>+ </AbsoluteFill>+ );+};`;++export const histogramExample: RemotionExample = {+ id: "histogram",+ name: "Histogram",+ description: "Animated bar chart using @remotion/shapes",+ category: "Charts",+ durationInFrames: 120,+ fps: 30,+ code: histogramCode,+};diff --git a/packages/template-code-generation/src/templates/index.ts b/packages/template-code-generation/src/templates/index.tsindex e0cd6b5f9a..b6b8d7941a 100644--- a/packages/template-code-generation/src/templates/index.ts+++ b/packages/template-code-generation/src/templates/index.ts@@ -1,3 +1,13 @@+import { textRotationExample } from "./text-rotation";+import { chatMessagesExample } from "./chat-messages";+import { counterAnimationExample } from "./counter-animation";+import { histogramExample } from "./histogram";+import { progressBarExample } from "./progress-bar";+import { animatedShapesExample } from "./animated-shapes";+import { morphingHexagonsExample } from "./morphing-hexagons";+import { lottieAnimationExample } from "./lottie-animation";+import { fallingSpheresExample } from "./falling-spheres";+export interface RemotionExample {id: string;name: string;@@ -5,861 +15,19 @@ export interface RemotionExample {code: string;durationInFrames: number;fps: number;- category: "Text" | "Charts" | "Shapes" | "Animation" | "3D" | "Other";+ category: "Text" | "Charts" | "Animation" | "3D" | "Other";}export const examples: RemotionExample[] = [- {- id: "text-rotation",- name: "Text Rotation",- description: "Rotating words with dissolve and blur effects",- category: "Text",- durationInFrames: 240,- fps: 30,- code: `- const frame = Remotion.useCurrentFrame();- const { fps } = Remotion.useVideoConfig();-- const words = ["One sec please :)", "Getting started", "with your", "Code Generation"];- const wordDuration = 60; // frames per word- const currentWordIndex = Math.floor(frame / wordDuration) % words.length;- const frameInWord = frame % wordDuration;-- // Fade in/out animation- const opacity = Remotion.interpolate(- frameInWord,- [0, 15, 45, 60],- [0, 1, 1, 0],- { extrapolateRight: "clamp" }- );-- // Scale animation- const scale = Remotion.interpolate(- frameInWord,- [0, 15, 45, 60],- [0.8, 1, 1, 1.2],- { extrapolateRight: "clamp" }- );-- // Blur animation- const blur = Remotion.interpolate(- frameInWord,- [0, 15, 45, 60],- [10, 0, 0, 10],- { extrapolateRight: "clamp" }- );-- return (- <Remotion.AbsoluteFill- style={{- backgroundColor: "#1a1a2e",- justifyContent: "center",- alignItems: "center",- }}- >- <h1- style={{- fontSize: 120,- fontWeight: "bold",- color: "#eee",- opacity,- transform: \`scale(\${scale})\`,- filter: \`blur(\${blur}px)\`,- fontFamily: "system-ui, sans-serif",- }}- >- {words[currentWordIndex]}- </h1>- </Remotion.AbsoluteFill>- );`,- },- {- id: "chat-messages",- name: "Chat Messages",- description: "WhatsApp-style bouncy message bubbles",- category: "Text",- durationInFrames: 180,- fps: 30,- code: `- const frame = Remotion.useCurrentFrame();- const { fps } = Remotion.useVideoConfig();-- const messages = [- { text: "Hey! How are you?", isMe: false, delay: 0 },- { text: "I'm good! Working on Remotion", isMe: true, delay: 45 },- { text: "That's awesome! Show me!", isMe: false, delay: 90 },- { text: "Check this out!", isMe: true, delay: 135 },- ];-- const visibleMessages = messages.filter((msg) => frame >= msg.delay);- const messageHeight = 100;-- return (- <Remotion.AbsoluteFill- style={{- backgroundColor: "#0a0a0a",- padding: 60,- justifyContent: "flex-end",- paddingBottom: 80,- }}- >- <div style={{ width: "100%", position: "relative" }}>- {messages.map((msg, i) => {- const progress = Remotion.spring({- frame: frame - msg.delay,- fps,- config: { damping: 12, stiffness: 200 },- });-- if (frame < msg.delay) return null;-- const messagesAfter = messages.filter((m, idx) => idx > i && frame >= m.delay).length;- const yOffset = messagesAfter * messageHeight;-- const xOffset = msg.isMe ? (1 - progress) * 100 : (1 - progress) * -100;-- return (- <div- key={i}- style={{- display: "flex",- justifyContent: msg.isMe ? "flex-end" : "flex-start",- marginBottom: 24,- opacity: progress,- transform: \`translateX(\${xOffset}px) translateY(\${-yOffset}px) scale(\${0.8 + progress * 0.2})\`,- }}- >- <div- style={{- backgroundColor: msg.isMe ? "#25D366" : "#2a2a2a",- color: "#fff",- padding: "20px 28px",- borderRadius: 24,- fontSize: 42,- fontFamily: "system-ui, sans-serif",- maxWidth: "70%",- }}- >- {msg.text}- </div>- </div>- );- })}- </div>- </Remotion.AbsoluteFill>- );`,- },- {- id: "counter-animation",- name: "Counter Animation",- description: "Animated number counters with metrics",- category: "Charts",- durationInFrames: 150,- fps: 30,- code: `- const frame = Remotion.useCurrentFrame();- const { fps, durationInFrames } = Remotion.useVideoConfig();-- const metrics = [- { label: "Users", target: 10000, color: "#4f46e5" },- { label: "Revenue", target: 50000, prefix: "$", color: "#10b981" },- { label: "Growth", target: 127, suffix: "%", color: "#f59e0b" },- ];-- const progress = Remotion.interpolate(- frame,- [0, durationInFrames * 0.7],- [0, 1],- { extrapolateRight: "clamp" }- );-- return (- <Remotion.AbsoluteFill- style={{- backgroundColor: "#0f0f0f",- justifyContent: "center",- alignItems: "center",- }}- >- <div- style={{- display: "flex",- gap: 60,- }}- >- {metrics.map((metric, i) => {- const staggeredProgress = Remotion.interpolate(- progress,- [i * 0.15, i * 0.15 + 0.7],- [0, 1],- { extrapolateLeft: "clamp", extrapolateRight: "clamp" }- );-- const value = Math.round(metric.target * staggeredProgress);-- return (- <div- key={i}- style={{- textAlign: "center",- opacity: Remotion.interpolate(staggeredProgress, [0, 0.2], [0, 1]),- transform: \`translateY(\${(1 - staggeredProgress) * 20}px)\`,- minWidth: 200,- }}- >- <div- style={{- fontSize: 72,- fontWeight: "bold",- color: metric.color,- fontFamily: "system-ui, sans-serif",- fontVariantNumeric: "tabular-nums",- }}- >- {metric.prefix || ""}{value.toLocaleString()}{metric.suffix || ""}- </div>- <div- style={{- fontSize: 24,- color: "#888",- marginTop: 8,- fontFamily: "system-ui, sans-serif",- }}- >- {metric.label}- </div>- </div>- );- })}- </div>- </Remotion.AbsoluteFill>- );`,- },- {- id: "histogram",- name: "Histogram",- description: "Animated bar chart using @remotion/shapes",- category: "Charts",- durationInFrames: 120,- fps: 30,- code: `- const frame = Remotion.useCurrentFrame();- const { fps } = Remotion.useVideoConfig();-- const data = [- { label: "Mon", value: 65, color: "#6366f1" },- { label: "Tue", value: 85, color: "#8b5cf6" },- { label: "Wed", value: 45, color: "#a855f7" },- { label: "Thu", value: 95, color: "#d946ef" },- { label: "Fri", value: 75, color: "#ec4899" },- ];-- const maxValue = Math.max(...data.map(d => d.value));- const barWidth = 80;-- return (- <Remotion.AbsoluteFill- style={{- backgroundColor: "#0a0a0a",- justifyContent: "center",- alignItems: "flex-end",- padding: 60,- paddingBottom: 100,- }}- >- <div- style={{- display: "flex",- alignItems: "flex-end",- gap: 24,- height: 400,- width: "100%",- justifyContent: "center",- }}- >- {data.map((item, i) => {- const delay = i * 10;- const progress = Remotion.spring({- frame: frame - delay,- fps,- config: { damping: 15, stiffness: 100 },- });-- const height = Math.max(1, (item.value / maxValue) * 300 * progress);-- return (- <div key={i} style={{ textAlign: "center", position: "relative" }}>- <div style={{ position: "relative", height, width: barWidth }}>- <RemotionShapes.Rect- width={barWidth}- height={height}- fill={item.color}- cornerRadius={12}- style={{ filter: \`drop-shadow(0 0 8px \${item.color}50)\` }}- />- <span- style={{- position: "absolute",- top: 10,- left: "50%",- transform: "translateX(-50%)",- color: "#fff",- fontSize: 18,- fontWeight: "bold",- opacity: progress,- fontFamily: "system-ui, sans-serif",- }}- >- {Math.round(item.value * progress)}- </span>- </div>- <div- style={{- color: "#888",- fontSize: 16,- marginTop: 12,- fontFamily: "system-ui, sans-serif",- }}- >- {item.label}- </div>- </div>- );- })}- </div>- </Remotion.AbsoluteFill>- );`,- },- {- id: "progress-bar",- name: "Progress Bar",- description: "Animated progress bar from 0 to 100%",- category: "Other",- durationInFrames: 180,- fps: 30,- code: `- const frame = Remotion.useCurrentFrame();- const { durationInFrames } = Remotion.useVideoConfig();-- const progress = Remotion.interpolate(- frame,- [0, durationInFrames * 0.8],- [0, 100],- { extrapolateRight: "clamp" }- );-- const opacity = Remotion.interpolate(- frame,- [0, 20],- [0, 1],- { extrapolateRight: "clamp" }- );-- return (- <Remotion.AbsoluteFill- style={{- backgroundColor: "#1a1a1a",- justifyContent: "center",- alignItems: "center",- opacity,- }}- >- <div style={{ width: 600 }}>- <div- style={{- display: "flex",- justifyContent: "space-between",- marginBottom: 16,- }}- >- <span- style={{- color: "#fff",- fontSize: 24,- fontFamily: "system-ui, sans-serif",- }}- >- Loading...- </span>- <span- style={{- color: "#10b981",- fontSize: 24,- fontWeight: "bold",- fontFamily: "system-ui, sans-serif",- }}- >- {Math.round(progress)}%- </span>- </div>- <div- style={{- width: "100%",- height: 24,- backgroundColor: "#333",- borderRadius: 12,- overflow: "hidden",- }}- >- <div- style={{- width: \`\${progress}%\`,- height: "100%",- background: "linear-gradient(90deg, #10b981, #34d399)",- borderRadius: 12,- transition: "width 0.1s ease-out",- }}- />- </div>- </div>- </Remotion.AbsoluteFill>- );`,- },- {- id: "animated-shapes",- name: "Animated Shapes",- description: "Bouncing and rotating SVG shapes with spring animations",- category: "Shapes",- durationInFrames: 180,- fps: 30,- code: `- const frame = Remotion.useCurrentFrame();- const { fps, width, height } = Remotion.useVideoConfig();-- const shapes = [- { type: "circle", color: "#6366f1", delay: 0 },- { type: "triangle", color: "#10b981", delay: 15 },- { type: "rect", color: "#f59e0b", delay: 30 },- { type: "star", color: "#ec4899", delay: 45 },- ];-- return (- <Remotion.AbsoluteFill- style={{- backgroundColor: "#0f0f0f",- justifyContent: "center",- alignItems: "center",- }}- >- <div- style={{- display: "flex",- gap: 80,- alignItems: "center",- }}- >- {shapes.map((shape, i) => {- const entrance = Remotion.spring({- frame: frame - shape.delay,- fps,- config: { damping: 12, stiffness: 200 },- });-- const rotation = Remotion.interpolate(- frame,- [0, 180],- [0, 360],- { extrapolateRight: "clamp" }- );-- const bounce = Math.sin((frame - shape.delay) * 0.1) * 10;-- const scale = entrance;- const opacity = entrance;-- const shapeProps = {- fill: shape.color,- stroke: "#fff",- strokeWidth: 2,- };-- return (- <div- key={i}- style={{- opacity,- transform: \`scale(\${scale}) translateY(\${bounce}px) rotate(\${shape.type === "star" ? rotation : 0}deg)\`,- }}- >- {shape.type === "circle" && (- <RemotionShapes.Circle radius={60} {...shapeProps} />- )}- {shape.type === "triangle" && (- <RemotionShapes.Triangle length={120} direction="up" {...shapeProps} />- )}- {shape.type === "rect" && (- <RemotionShapes.Rect width={100} height={100} cornerRadius={12} {...shapeProps} />- )}- {shape.type === "star" && (- <RemotionShapes.Star points={5} innerRadius={40} outerRadius={70} {...shapeProps} />- )}- </div>- );- })}- </div>- </Remotion.AbsoluteFill>- );`,- },- {- id: "morphing-hexagons",- name: "Morphing Hexagons",- description:- "Mesmerizing hexagon grid with pulsing and color-shifting effects",- category: "Shapes",- durationInFrames: 240,- fps: 30,- code: `- const frame = Remotion.useCurrentFrame();- const { fps, width, height } = Remotion.useVideoConfig();-- const hexSize = 50;- const cols = 7;- const rows = 5;-- const hexagons = [];- for (let row = 0; row < rows; row++) {- for (let col = 0; col < cols; col++) {- const offsetX = row % 2 === 0 ? 0 : hexSize * 0.866;- hexagons.push({- x: col * hexSize * 1.732 + offsetX,- y: row * hexSize * 1.5,- delay: (row + col) * 3,- });- }- }-- const gridWidth = (cols - 1) * hexSize * 1.732 + hexSize;- const gridHeight = (rows - 1) * hexSize * 1.5 + hexSize * 2;-- return (- <Remotion.AbsoluteFill- style={{- backgroundColor: "#0a0a0f",- justifyContent: "center",- alignItems: "center",- }}- >- <svg- width={gridWidth + 100}- height={gridHeight + 100}- viewBox={\`-50 -50 \${gridWidth + 100} \${gridHeight + 100}\`}- >- <defs>- <filter id="glow">- <feGaussianBlur stdDeviation="3" result="coloredBlur" />- <feMerge>- <feMergeNode in="coloredBlur" />- <feMergeNode in="SourceGraphic" />- </feMerge>- </filter>- </defs>- {hexagons.map((hex, i) => {- const wave = Math.sin((frame - hex.delay) * 0.08);- const pulse = Remotion.interpolate(wave, [-1, 1], [0.6, 1]);-- const hue = Remotion.interpolate(- (frame + hex.delay * 2) % 240,- [0, 120, 240],- [280, 200, 280]- );-- const opacity = Remotion.interpolate(wave, [-1, 1], [0.3, 0.9]);-- const scale = Remotion.interpolate(wave, [-1, 1], [0.7, 1]);-- const entrance = Remotion.spring({- frame: frame - hex.delay,- fps,- config: { damping: 15, stiffness: 120 },- });-- const points = [];- for (let j = 0; j < 6; j++) {- const angle = (Math.PI / 3) * j - Math.PI / 6;- const px = hex.x + hexSize * scale * entrance * Math.cos(angle);- const py = hex.y + hexSize * scale * entrance * Math.sin(angle);- points.push(\`\${px},\${py}\`);- }-- return (- <polygon- key={i}- points={points.join(" ")}- fill="none"- stroke={\`hsl(\${hue}, 80%, 60%)\`}- strokeWidth={2 * pulse}- opacity={opacity * entrance}- filter="url(#glow)"- />- );- })}- </svg>- </Remotion.AbsoluteFill>- );`,- },- {- id: "spiral-dots",- name: "Spiral Dots",- description: "Hypnotic spiral of dots with rainbow colors and rotation",- category: "Shapes",- durationInFrames: 300,- fps: 30,- code: `- const frame = Remotion.useCurrentFrame();- const { fps } = Remotion.useVideoConfig();-- const numDots = 120;- const maxRadius = 280;-- const globalRotation = Remotion.interpolate(frame, [0, 300], [0, Math.PI * 4]);-- const entrance = Remotion.spring({- frame,- fps,- config: { damping: 20, stiffness: 80 },- });-- return (- <Remotion.AbsoluteFill- style={{- backgroundColor: "#050510",- justifyContent: "center",- alignItems: "center",- }}- >- <svg width={600} height={600} viewBox="-300 -300 600 600">- <defs>- <filter id="dotGlow">- <feGaussianBlur stdDeviation="2" result="blur" />- <feMerge>- <feMergeNode in="blur" />- <feMergeNode in="SourceGraphic" />- </feMerge>- </filter>- </defs>- {Array.from({ length: numDots }).map((_, i) => {- const t = i / numDots;- const spiralAngle = t * Math.PI * 8 + globalRotation;- const radius = t * maxRadius * entrance;-- const x = Math.cos(spiralAngle) * radius;- const y = Math.sin(spiralAngle) * radius;-- const hue = (t * 360 + frame * 2) % 360;-- const pulse = Math.sin(frame * 0.1 + i * 0.2) * 0.5 + 1;- const dotSize = (3 + t * 8) * pulse;-- const opacity = Remotion.interpolate(t, [0, 0.1, 1], [0, 1, 0.8]) * entrance;-- return (- <circle- key={i}- cx={x}- cy={y}- r={dotSize}- fill={\`hsl(\${hue}, 90%, 60%)\`}- opacity={opacity}- filter="url(#dotGlow)"- />- );- })}- </svg>- </Remotion.AbsoluteFill>- );`,- },- {- id: "lottie-animation",- name: "Lottie Fish Loader",- description: "Glowing fish loader animation from LottieFiles",- category: "Animation",- durationInFrames: 180,- fps: 60,- code: `- const frame = Remotion.useCurrentFrame();- const { fps, durationInFrames } = Remotion.useVideoConfig();- const [animationData, setAnimationData] = React.useState(null);-- React.useEffect(() => {- fetch("https://assets-v2.lottiefiles.com/a/73ecc94a-4ccb-4018-a710-835b9eaffeaf/OwGeQT8PCr.json")- .then((res) => res.json())- .then((data) => setAnimationData(data))- .catch((err) => console.error("Failed to load Lottie:", err));- }, []);-- const entrance = Remotion.spring({- frame,- fps,- config: { damping: 15, stiffness: 100 },- });-- const scale = Remotion.interpolate(entrance, [0, 1], [0.5, 1]);- const opacity = Remotion.interpolate(entrance, [0, 1], [0, 1]);-- if (!animationData) {- return (- <Remotion.AbsoluteFill- style={{- backgroundColor: "#000000",- justifyContent: "center",- alignItems: "center",- }}- >- <div style={{ color: "#94a3b8", fontSize: 24, fontFamily: "system-ui" }}>- Loading animation...- </div>- </Remotion.AbsoluteFill>- );- }-- return (- <Remotion.AbsoluteFill- style={{- backgroundColor: "#000000",- justifyContent: "center",- alignItems: "center",- }}- >- <div- style={{- transform: \`scale(\${scale})\`,- opacity,- }}- >- <Lottie- animationData={animationData}- style={{ width: 400, height: 400 }}- />- </div>- <div- style={{- position: "absolute",- bottom: 60,- color: "#e2e8f0",- fontSize: 24,- fontFamily: "system-ui",- opacity,- textAlign: "center",- }}- >- <div style={{ fontWeight: "bold", marginBottom: 4 }}>Glowing Fish Loader</div>- <div style={{ fontSize: 16, color: "#94a3b8" }}>by Mau Ali on LottieFiles</div>- </div>- </Remotion.AbsoluteFill>- );`,- },- {- id: "falling-spheres",- name: "Golden Bouncing Spheres",- description: "Glowing golden spheres with physics and orbiting camera",- category: "3D",- durationInFrames: 450,- fps: 60,- code: `- const frame = Remotion.useCurrentFrame();- const { width, height, fps, durationInFrames } = Remotion.useVideoConfig();-- const spheres = [- { x: -1.5, z: -0.5, delay: 0, radius: 0.4, restitution: 0.75 },- { x: 0, z: 0, delay: 20, radius: 0.5, restitution: 0.75 },- { x: 1.5, z: 0.5, delay: 40, radius: 0.35, restitution: 0.75 },- { x: -0.8, z: 1, delay: 60, radius: 0.45, restitution: 0.75 },- { x: 0.8, z: -1, delay: 80, radius: 0.38, restitution: 0.75 },- ];-- const gravity = 12;- const groundY = -2;-- // Realistic bounce physics simulation- const simulateBounce = (f, delay, radius, restitution) => {- const elapsed = Math.max(0, f - delay);- const t = elapsed / fps;- const startY = 6;- const surfaceY = groundY + radius;-- // Calculate time to first impact- const firstImpactTime = Math.sqrt(2 * (startY - surfaceY) / gravity);-- if (t <= firstImpactTime) {- const y = startY - 0.5 * gravity * t * t;- return { y, squash: 1 };- }-- // After first impact, simulate bounces- let currentVelocity = gravity * firstImpactTime;- let bounceStartTime = firstImpactTime;-- for (let bounce = 0; bounce < 20; bounce++) {- currentVelocity *= restitution;-- if (currentVelocity < 0.5) {- return { y: surfaceY, squash: 1 };- }-- const bounceDuration = 2 * currentVelocity / gravity;- const timeInBounce = t - bounceStartTime;-- if (timeInBounce <= bounceDuration) {- const y = surfaceY + currentVelocity * timeInBounce - 0.5 * gravity * timeInBounce * timeInBounce;- const impactProximity = Math.abs(y - surfaceY);- const squash = impactProximity < 0.08 ? 0.65 + (impactProximity / 0.08) * 0.35 : 1;- return { y: Math.max(surfaceY, y), squash };- }-- bounceStartTime += bounceDuration;- }-- return { y: surfaceY, squash: 1 };- };-- return (- <Remotion.AbsoluteFill style={{ backgroundColor: "#000000" }}>- <ThreeCanvas- width={width}- height={height}- camera={{ position: [0, 3, 8], fov: 40 }}- >- {/* Minimal ambient for dark scene */}- <ambientLight intensity={0.05} />-- {/* Ground plane - dark reflective surface */}- <mesh rotation={[-Math.PI / 2, 0, 0]} position={[0, groundY, 0]}>- <planeGeometry args={[20, 20]} />- <meshStandardMaterial color="#0a0a0a" metalness={0.9} roughness={0.3} />- </mesh>-- {/* Bouncing golden spheres with point lights */}- {spheres.map((sphere, i) => {- const { y, squash } = simulateBounce(frame, sphere.delay, sphere.radius, sphere.restitution);- const stretch = 1 / squash;-- return (- <group key={i} position={[sphere.x, y, sphere.z]}>- {/* Point light emanating from sphere */}- <pointLight- color="#ffd700"- intensity={0.8}- distance={4}- decay={2}- />- {/* Golden sphere */}- <mesh scale={[1, squash, stretch]}>- <sphereGeometry args={[sphere.radius, 32, 32]} />- <meshStandardMaterial- color="#ffd700"- emissive="#cc7a00"- emissiveIntensity={0.15}- metalness={0.4}- roughness={0.6}- />- </mesh>- </group>- );- })}- </ThreeCanvas>- </Remotion.AbsoluteFill>- );`,- },+ textRotationExample,+ chatMessagesExample,+ counterAnimationExample,+ histogramExample,+ progressBarExample,+ animatedShapesExample,+ morphingHexagonsExample,+ lottieAnimationExample,+ fallingSpheresExample,];export function getExampleById(id: string): RemotionExample | undefined {diff --git a/packages/template-code-generation/src/templates/lottie-animation.ts b/packages/template-code-generation/src/templates/lottie-animation.tsnew file mode 100644index 0000000000..f33aa912b1--- /dev/null+++ b/packages/template-code-generation/src/templates/lottie-animation.ts@@ -0,0 +1,89 @@+import { RemotionExample } from "./index";++export const lottieAnimationCode = `import { AbsoluteFill, useCurrentFrame, useVideoConfig, spring, interpolate } from "remotion";+import { Lottie } from "@remotion/lottie";+import { useState, useEffect } from "react";++export const MyAnimation = () => {+ const frame = useCurrentFrame();+ const { fps } = useVideoConfig();+ const [animationData, setAnimationData] = useState(null);++ useEffect(() => {+ fetch("https://assets-v2.lottiefiles.com/a/73ecc94a-4ccb-4018-a710-835b9eaffeaf/OwGeQT8PCr.json")+ .then((res) => res.json())+ .then((data) => setAnimationData(data))+ .catch((err) => console.error("Failed to load Lottie:", err));+ }, []);++ const entrance = spring({+ frame,+ fps,+ config: { damping: 15, stiffness: 100 },+ });++ const scale = interpolate(entrance, [0, 1], [0.5, 1]);+ const opacity = interpolate(entrance, [0, 1], [0, 1]);++ if (!animationData) {+ return (+ <AbsoluteFill+ style={{+ backgroundColor: "#000000",+ justifyContent: "center",+ alignItems: "center",+ }}+ >+ <div style={{ color: "#94a3b8", fontSize: 24, fontFamily: "system-ui" }}>+ Loading animation...+ </div>+ </AbsoluteFill>+ );+ }++ return (+ <AbsoluteFill+ style={{+ backgroundColor: "#000000",+ justifyContent: "center",+ alignItems: "center",+ }}+ >+ <div+ style={{+ transform: \`scale(\${scale})\`,+ opacity,+ }}+ >+ <Lottie+ animationData={animationData}+ style={{ width: 400, height: 400 }}+ />+ </div>+ <div+ style={{+ position: "absolute",+ bottom: 60,+ color: "#e2e8f0",+ fontSize: 24,+ fontFamily: "system-ui",+ opacity,+ textAlign: "center",+ }}+ >+ <div style={{ fontWeight: "bold", marginBottom: 4 }}>Glowing Fish Loader</div>+ <div style={{ fontSize: 16, color: "#94a3b8" }}>by Mau Ali on LottieFiles</div>+ </div>+ </AbsoluteFill>+ );+};`;++export const lottieAnimationExample: RemotionExample = {+ id: "lottie-animation",+ name: "Lottie Fish Loader",+ description: "Glowing fish loader animation from LottieFiles",+ category: "Animation",+ durationInFrames: 180,+ fps: 60,+ code: lottieAnimationCode,+};diff --git a/packages/template-code-generation/src/templates/morphing-hexagons.ts b/packages/template-code-generation/src/templates/morphing-hexagons.tsnew file mode 100644index 0000000000..3cc27e3604--- /dev/null+++ b/packages/template-code-generation/src/templates/morphing-hexagons.ts@@ -0,0 +1,104 @@+import { RemotionExample } from "./index";++export const morphingHexagonsCode = `import { AbsoluteFill, useCurrentFrame, useVideoConfig, interpolate, spring } from "remotion";++export const MyAnimation = () => {+ const frame = useCurrentFrame();+ const { fps, width, height } = useVideoConfig();++ const hexSize = 50;+ const cols = 7;+ const rows = 5;++ const hexagons: Array<{ x: number; y: number; delay: number }> = [];+ for (let row = 0; row < rows; row++) {+ for (let col = 0; col < cols; col++) {+ const offsetX = row % 2 === 0 ? 0 : hexSize * 0.866;+ hexagons.push({+ x: col * hexSize * 1.732 + offsetX,+ y: row * hexSize * 1.5,+ delay: (row + col) * 3,+ });+ }+ }++ const gridWidth = (cols - 1) * hexSize * 1.732 + hexSize;+ const gridHeight = (rows - 1) * hexSize * 1.5 + hexSize * 2;++ return (+ <AbsoluteFill+ style={{+ backgroundColor: "#0a0a0f",+ justifyContent: "center",+ alignItems: "center",+ }}+ >+ <svg+ width={gridWidth + 100}+ height={gridHeight + 100}+ viewBox={\`-50 -50 \${gridWidth + 100} \${gridHeight + 100}\`}+ >+ <defs>+ <filter id="glow">+ <feGaussianBlur stdDeviation="3" result="coloredBlur" />+ <feMerge>+ <feMergeNode in="coloredBlur" />+ <feMergeNode in="SourceGraphic" />+ </feMerge>+ </filter>+ </defs>+ {hexagons.map((hex, i) => {+ const wave = Math.sin((frame - hex.delay) * 0.08);+ const pulse = interpolate(wave, [-1, 1], [0.6, 1]);++ const hue = interpolate(+ (frame + hex.delay * 2) % 240,+ [0, 120, 240],+ [280, 200, 280]+ );++ const opacity = interpolate(wave, [-1, 1], [0.3, 0.9]);++ const scale = interpolate(wave, [-1, 1], [0.7, 1]);++ const entrance = spring({+ frame: frame - hex.delay,+ fps,+ config: { damping: 15, stiffness: 120 },+ });++ const points: string[] = [];+ for (let j = 0; j < 6; j++) {+ const angle = (Math.PI / 3) * j - Math.PI / 6;+ const px = hex.x + hexSize * scale * entrance * Math.cos(angle);+ const py = hex.y + hexSize * scale * entrance * Math.sin(angle);+ points.push(\`\${px},\${py}\`);+ }++ return (+ <polygon+ key={i}+ points={points.join(" ")}+ fill="none"+ stroke={\`hsl(\${hue}, 80%, 60%)\`}+ strokeWidth={2 * pulse}+ opacity={opacity * entrance}+ filter="url(#glow)"+ />+ );+ })}+ </svg>+ </AbsoluteFill>+ );+};`;++export const morphingHexagonsExample: RemotionExample = {+ id: "morphing-hexagons",+ name: "Morphing Hexagons",+ description:+ "Mesmerizing hexagon grid with pulsing and color-shifting effects",+ category: "Other",+ durationInFrames: 240,+ fps: 30,+ code: morphingHexagonsCode,+};diff --git a/packages/template-code-generation/src/templates/progress-bar.ts b/packages/template-code-generation/src/templates/progress-bar.tsnew file mode 100644index 0000000000..e9f5900770--- /dev/null+++ b/packages/template-code-generation/src/templates/progress-bar.ts@@ -0,0 +1,92 @@+import { RemotionExample } from "./index";++export const progressBarCode = `import { AbsoluteFill, useCurrentFrame, useVideoConfig, interpolate } from "remotion";++export const MyAnimation = () => {+ const frame = useCurrentFrame();+ const { durationInFrames } = useVideoConfig();++ const progress = interpolate(+ frame,+ [0, durationInFrames * 0.8],+ [0, 100],+ { extrapolateRight: "clamp" }+ );++ const opacity = interpolate(+ frame,+ [0, 20],+ [0, 1],+ { extrapolateRight: "clamp" }+ );++ return (+ <AbsoluteFill+ style={{+ backgroundColor: "#1a1a1a",+ justifyContent: "center",+ alignItems: "center",+ opacity,+ }}+ >+ <div style={{ width: 600 }}>+ <div+ style={{+ display: "flex",+ justifyContent: "space-between",+ marginBottom: 16,+ }}+ >+ <span+ style={{+ color: "#fff",+ fontSize: 24,+ fontFamily: "system-ui, sans-serif",+ }}+ >+ Loading...+ </span>+ <span+ style={{+ color: "#10b981",+ fontSize: 24,+ fontWeight: "bold",+ fontFamily: "system-ui, sans-serif",+ }}+ >+ {Math.round(progress)}%+ </span>+ </div>+ <div+ style={{+ width: "100%",+ height: 24,+ backgroundColor: "#333",+ borderRadius: 12,+ overflow: "hidden",+ }}+ >+ <div+ style={{+ width: \`\${progress}%\`,+ height: "100%",+ background: "linear-gradient(90deg, #10b981, #34d399)",+ borderRadius: 12,+ transition: "width 0.1s ease-out",+ }}+ />+ </div>+ </div>+ </AbsoluteFill>+ );+};`;++export const progressBarExample: RemotionExample = {+ id: "progress-bar",+ name: "Progress Bar",+ description: "Animated progress bar from 0 to 100%",+ category: "Other",+ durationInFrames: 180,+ fps: 30,+ code: progressBarCode,+};diff --git a/packages/template-code-generation/src/templates/text-rotation.ts b/packages/template-code-generation/src/templates/text-rotation.tsnew file mode 100644index 0000000000..c3f5e2f5f6--- /dev/null+++ b/packages/template-code-generation/src/templates/text-rotation.ts@@ -0,0 +1,84 @@+import { RemotionExample } from "./index";++export const textRotationCode = `import { useCurrentFrame, useVideoConfig, AbsoluteFill, interpolate } from "remotion";++export const MyAnimation = () => {+ const frame = useCurrentFrame();+ const { fps } = useVideoConfig();++ // Text content - easily customizable+ const WORDS = ["One sec please :)", "Getting started", "with your", "Code Generation"];++ // Animation timing+ const WORD_DURATION = 60; // frames per word+ const FADE_IN_DURATION = 15;+ const FADE_OUT_START = 45;++ // Visual styling+ const FONT_SIZE = 120;+ const FONT_WEIGHT = "bold";+ const COLOR_TEXT = "#eee";+ const COLOR_BACKGROUND = "#1a1a2e";+ const BLUR_AMOUNT = 10;++ const currentWordIndex = Math.floor(frame / WORD_DURATION) % WORDS.length;+ const frameInWord = frame % WORD_DURATION;++ // Fade in/out animation+ const opacity = interpolate(+ frameInWord,+ [0, FADE_IN_DURATION, FADE_OUT_START, WORD_DURATION],+ [0, 1, 1, 0],+ { extrapolateRight: "clamp" }+ );++ // Scale animation+ const scale = interpolate(+ frameInWord,+ [0, FADE_IN_DURATION, FADE_OUT_START, WORD_DURATION],+ [0.8, 1, 1, 1.2],+ { extrapolateRight: "clamp" }+ );++ // Blur animation+ const blur = interpolate(+ frameInWord,+ [0, FADE_IN_DURATION, FADE_OUT_START, WORD_DURATION],+ [BLUR_AMOUNT, 0, 0, BLUR_AMOUNT],+ { extrapolateRight: "clamp" }+ );++ return (+ <AbsoluteFill+ style={{+ backgroundColor: COLOR_BACKGROUND,+ justifyContent: "center",+ alignItems: "center",+ }}+ >+ <h1+ style={{+ fontSize: FONT_SIZE,+ fontWeight: FONT_WEIGHT,+ color: COLOR_TEXT,+ opacity,+ transform: \`scale(\${scale})\`,+ filter: \`blur(\${blur}px)\`,+ fontFamily: "system-ui, sans-serif",+ }}+ >+ {WORDS[currentWordIndex]}+ </h1>+ </AbsoluteFill>+ );+};`;++export const textRotationExample: RemotionExample = {+ id: "text-rotation",+ name: "Text Rotation",+ description: "Rotating words with dissolve and blur effects",+ category: "Text",+ durationInFrames: 240,+ fps: 30,+ code: textRotationCode,+};