🎥 Make videos programmatically with React
update remotion preview
Jonny Burgerd3503e0bf6b6
diff --git a/packages/convert/app/components/timing-editor/AnimationPreview.tsx b/packages/convert/app/components/timing-editor/AnimationPreview.tsxindex a72b0bd13e..f8a341f903 100644--- a/packages/convert/app/components/timing-editor/AnimationPreview.tsx+++ b/packages/convert/app/components/timing-editor/AnimationPreview.tsx@@ -1,37 +1,52 @@+import {+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue,+} from '@remotion/design';import React from 'react';+import {ReplayButton} from './ReplayButton';++export type AnimationType = 'Scale' | 'Translate' | 'Opacity';export const AnimationPreview: React.FC<{readonly id: string;- readonly animation: string;-}> = ({id, animation}) => {+ readonly animation: AnimationType;+ readonly onAnimationChange: (animation: AnimationType) => void;+ readonly onReplay: () => void;+}> = ({id, animation, onAnimationChange, onReplay}) => {return (- <div style={{textAlign: 'center', paddingBottom: 20}}>- <div- style={{- height: 65,- width: 80,- display: 'flex',- justifyContent: 'center',- alignItems: 'center',- }}- >+ <div className="text-center pb-5 w-full h-full flex flex-col">+ <div className="flex justify-center items-center flex-1"><divid={id}+ className="font-brand font-black text-[10vw] md:text-[5vw]"style={{- height: 50,- width: 50,- backgroundColor: 'black',borderRadius: 10,}}- />+ >+ Hello World+ </div></div>- <div- style={{- fontSize: 13,- color: 'rgb(101 101 106)',- }}- >- {animation}+ <div className="flex flex-row gap-2 justify-center items-center">+ <Select+ value={animation}+ onValueChange={(v) => {+ onAnimationChange(v as AnimationType);+ onReplay();+ }}+ >+ <SelectTrigger className="w-[120px] rounded-full">+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ <SelectItem value="Scale">Scale</SelectItem>+ <SelectItem value="Translate">Translate</SelectItem>+ <SelectItem value="Opacity">Opacity</SelectItem>+ </SelectContent>+ </Select>+ <ReplayButton onReplay={onReplay} /></div></div>);diff --git a/packages/convert/app/components/timing-editor/InterpolateEditor.tsx b/packages/convert/app/components/timing-editor/InterpolateEditor.tsxindex 73932b95dd..8f09dfcafb 100644--- a/packages/convert/app/components/timing-editor/InterpolateEditor.tsx+++ b/packages/convert/app/components/timing-editor/InterpolateEditor.tsx@@ -1,51 +1,257 @@import React from 'react';import {Slider} from '~/components/ui/slider';-import {EASING_OPTIONS} from './defaults';import {SliderLabel} from './SliderLabel';import type {EasingType, InterpolateTimingConfig} from './types';+type Direction = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out';+type Curve = 'quad' | 'cubic' | 'sin' | 'exp' | 'circle' | 'bounce';++const LinearIcon: React.FC = () => (+ <svg width={24} height={24} viewBox="0 0 24 24" fill="none">+ <path+ d="M4 20 L20 4"+ stroke="currentColor"+ strokeWidth={2}+ strokeLinecap="round"+ />+ </svg>+);++const EaseInIcon: React.FC = () => (+ <svg width={24} height={24} viewBox="0 0 24 24" fill="none">+ <path+ d="M4 20 Q20 20 20 4"+ stroke="currentColor"+ strokeWidth={2}+ strokeLinecap="round"+ fill="none"+ />+ </svg>+);++const EaseOutIcon: React.FC = () => (+ <svg width={24} height={24} viewBox="0 0 24 24" fill="none">+ <path+ d="M4 20 Q4 4 20 4"+ stroke="currentColor"+ strokeWidth={2}+ strokeLinecap="round"+ fill="none"+ />+ </svg>+);++const EaseInOutIcon: React.FC = () => (+ <svg width={24} height={24} viewBox="0 0 24 24" fill="none">+ <path+ d="M4 20 C14 20 10 4 20 4"+ stroke="currentColor"+ strokeWidth={2}+ strokeLinecap="round"+ fill="none"+ />+ </svg>+);++const DIRECTION_ICONS: Record<Direction, React.FC> = {+ linear: LinearIcon,+ 'ease-in': EaseInIcon,+ 'ease-out': EaseOutIcon,+ 'ease-in-out': EaseInOutIcon,+};++const DIRECTIONS: {value: Direction; label: string}[] = [+ {value: 'linear', label: 'Linear'},+ {value: 'ease-in', label: 'In'},+ {value: 'ease-out', label: 'Out'},+ {value: 'ease-in-out', label: 'In-Out'},+];++// Curve icons show ease-in style (concave, belly facing bottom-right)+const QuadIcon: React.FC = () => (+ <svg width={24} height={24} viewBox="0 0 24 24" fill="none">+ <path+ d="M4 20 Q14 20 20 4"+ stroke="currentColor"+ strokeWidth={2}+ strokeLinecap="round"+ fill="none"+ />+ </svg>+);++const CubicIcon: React.FC = () => (+ <svg width={24} height={24} viewBox="0 0 24 24" fill="none">+ <path+ d="M4 20 Q20 20 20 4"+ stroke="currentColor"+ strokeWidth={2}+ strokeLinecap="round"+ fill="none"+ />+ </svg>+);++const SinIcon: React.FC = () => (+ <svg width={24} height={24} viewBox="0 0 24 24" fill="none">+ <path+ d="M4 20 C16 20 20 16 20 4"+ stroke="currentColor"+ strokeWidth={2}+ strokeLinecap="round"+ fill="none"+ />+ </svg>+);++const ExpIcon: React.FC = () => (+ <svg width={24} height={24} viewBox="0 0 24 24" fill="none">+ <path+ d="M4 20 L12 20 Q20 20 20 4"+ stroke="currentColor"+ strokeWidth={2}+ strokeLinecap="round"+ fill="none"+ />+ </svg>+);++const CircleIcon: React.FC = () => (+ <svg width={24} height={24} viewBox="0 0 24 24" fill="none">+ <path+ d="M4 20 A16 16 0 0 0 20 4"+ stroke="currentColor"+ strokeWidth={2}+ strokeLinecap="round"+ fill="none"+ />+ </svg>+);++const BounceIcon: React.FC = () => (+ <svg width={24} height={24} viewBox="0 0 24 24" fill="none">+ <path+ d="M4 20 Q4 4 7 4 Q9 4 9 10 Q9 4 12 4 Q14 4 14 8 Q14 4 17 4 L20 4"+ stroke="currentColor"+ strokeWidth={2}+ strokeLinecap="round"+ fill="none"+ />+ </svg>+);++const CURVE_ICONS: Record<Curve, React.FC> = {+ quad: QuadIcon,+ cubic: CubicIcon,+ sin: SinIcon,+ exp: ExpIcon,+ circle: CircleIcon,+ bounce: BounceIcon,+};++const CURVES: {value: Curve; label: string}[] = [+ {value: 'quad', label: 'Quad'},+ {value: 'cubic', label: 'Cubic'},+ {value: 'sin', label: 'Sin'},+ {value: 'exp', label: 'Exp'},+ {value: 'circle', label: 'Circle'},+ {value: 'bounce', label: 'Bounce'},+];++const parseEasing = (+ easing: EasingType,+): {direction: Direction; curve: Curve} => {+ if (easing === 'linear' || easing === 'ease') {+ return {direction: 'linear', curve: 'cubic'};+ }++ const parts = easing.split('-');+ // e.g., "ease-in-cubic" -> ["ease", "in", "cubic"]+ // e.g., "ease-in-out-cubic" -> ["ease", "in", "out", "cubic"]+ const curve = parts[parts.length - 1] as Curve;+ const direction = parts.slice(0, -1).join('-') as Direction;++ return {direction, curve};+};++const combineEasing = (direction: Direction, curve: Curve): EasingType => {+ if (direction === 'linear') {+ return 'linear';+ }++ return `${direction}-${curve}` as EasingType;+};+export const InterpolateEditor: React.FC<{readonly config: InterpolateTimingConfig;readonly onDragChange: (config: InterpolateTimingConfig) => void;readonly onChange: (config: InterpolateTimingConfig) => void;readonly onRelease: () => void;}> = ({config, onDragChange, onRelease, onChange}) => {+ const {direction, curve} = parseEasing(config.easing);++ const handleDirectionChange = (newDirection: Direction) => {+ const newEasing = combineEasing(newDirection, curve);+ onChange({...config, easing: newEasing});+ onRelease();+ };++ const handleCurveChange = (newCurve: Curve) => {+ const newEasing = combineEasing(direction, newCurve);+ onChange({...config, easing: newEasing});+ onRelease();+ };+return (<>- <label- htmlFor="easing-select"- style={{- fontSize: 12,- color: 'var(--muted-foreground)',- marginBottom: 4,- }}- >- Easing- </label>- <select- id="easing-select"- value={config.easing}- onChange={(e) => {- onChange({...config, easing: e.target.value as EasingType});- onRelease();- }}- style={{- padding: '8px 12px',- borderRadius: 6,- border: '1px solid #333',- backgroundColor: 'var(--background)',- color: 'var(--foreground)',- fontSize: 14,- marginBottom: 16,- cursor: 'pointer',- }}- >- {EASING_OPTIONS.map((opt) => (- <option key={opt.value} value={opt.value}>- {opt.label}- </option>- ))}- </select>+ <label className="text-xs text-muted-foreground mb-1">Convexity</label>+ <div className="flex flex-row gap-1 mb-4">+ {DIRECTIONS.map((d) => {+ const Icon = DIRECTION_ICONS[d.value];+ return (+ <div key={d.value} className="flex-1">+ <button+ type="button"+ className={`w-full font-brand text-xs h-15 flex flex-col items-center justify-center gap-0.5 rounded-md border border-transparent cursor-pointer ${+ direction === d.value+ ? ''+ : 'text-gray-300 hover:text-gray-500'+ }`}+ onClick={() => handleDirectionChange(d.value)}+ >+ <Icon />+ {d.label}+ </button>+ </div>+ );+ })}+ </div>+ {direction !== 'linear' && (+ <>+ <label className="text-xs text-muted-foreground mb-1">Curve</label>+ <div className="flex flex-row gap-1 mb-4">+ {CURVES.map((c) => {+ const Icon = CURVE_ICONS[c.value];+ return (+ <div key={c.value} className="flex-1">+ <button+ type="button"+ className={`w-full font-brand text-xs h-15 flex flex-col items-center justify-center gap-0.5 rounded-md border border-transparent cursor-pointer ${+ curve === c.value+ ? ''+ : 'text-gray-300 hover:text-gray-500'+ }`}+ onClick={() => handleCurveChange(c.value)}+ >+ <Icon />+ {c.label}+ </button>+ </div>+ );+ })}+ </div>+ </>+ )}<Slidermin={0.02}max={3.33}diff --git a/packages/convert/app/components/timing-editor/TimingEditor.tsx b/packages/convert/app/components/timing-editor/TimingEditor.tsxindex 881ef0f74c..c9be83f47b 100644--- a/packages/convert/app/components/timing-editor/TimingEditor.tsx+++ b/packages/convert/app/components/timing-editor/TimingEditor.tsx@@ -1,6 +1,6 @@import {useCallback, useState} from 'react';import {measureSpring} from 'remotion';-import {AnimationPreview} from './AnimationPreview';+import {AnimationPreview, type AnimationType} from './AnimationPreview';import {CanvasWrapper} from './CanvasWrapper';import {DEFAULT_INTERPOLATE_CONFIG,@@ -8,7 +8,6 @@ import {DEFAULT_SPRING_CONFIG,} from './defaults';import {HARDCODED_FPS} from './generate-code';-import {ReplayButton} from './ReplayButton';import {Sidebar} from './Sidebar';import type {MixingMode, TimingComponent, TimingConfig} from './types';@@ -24,6 +23,8 @@ export function TimingEditor() {config: TimingConfig;} | null>(null);const [replayKey, setReplayKey] = useState(0);+ const [selectedAnimation, setSelectedAnimation] =+ useState<AnimationType>('Scale');const onReplay = useCallback(() => {setReplayKey((k) => k + 1);@@ -147,7 +148,7 @@ export function TimingEditor() {: null;return (- <div className="flex justify-center items-center h-full w-full absolute flex-col">+ <div className="flex justify-center items-center min-h-screen flex-col bg-[#F9FAFC]"><div className="flex overflow-hidden w-full flex-1 flex-col md:flex-row"><Sidebarcomponents={components}@@ -162,13 +163,13 @@ export function TimingEditor() {onMixingModeChange={onMixingModeChange}/><div className="flex flex-col w-full h-auto flex-1">- <div className="absolute right-4 top-4">- <ReplayButton onReplay={onReplay} />- </div><div className="hidden md:flex flex-row justify-center items-center flex-1">- <AnimationPreview animation="Scale" id="spring-scale" />- <AnimationPreview animation="Translate" id="spring-translate" />- <AnimationPreview animation="Rotate" id="spring-rotate" />+ <AnimationPreview+ animation={selectedAnimation}+ id={`spring-${selectedAnimation.toLowerCase()}`}+ onAnimationChange={setSelectedAnimation}+ onReplay={onReplay}+ /></div><div className="h-[300px]"><CanvasWrapperdiff --git a/packages/convert/app/components/timing-editor/defaults.ts b/packages/convert/app/components/timing-editor/defaults.tsindex 2b133cb7bf..c295158828 100644--- a/packages/convert/app/components/timing-editor/defaults.ts+++ b/packages/convert/app/components/timing-editor/defaults.ts@@ -9,8 +9,8 @@ export const DEFAULT_DAMPING = 10;export const DEFAULT_MASS = 1;export const DEFAULT_STIFFNESS = 100;-export const DEFAULT_INTERPOLATE_DURATION = 30;-export const DEFAULT_EASING: EasingType = 'ease-out-cubic';+export const DEFAULT_INTERPOLATE_DURATION = 60;+export const DEFAULT_EASING: EasingType = 'ease-in-out-cubic';export const DEFAULT_SINE_DURATION = 60;export const DEFAULT_SINE_AMPLITUDE = 1;diff --git a/packages/convert/app/components/timing-editor/draw-trajectory.ts b/packages/convert/app/components/timing-editor/draw-trajectory.tsindex 340cddfea3..1879efb544 100644--- a/packages/convert/app/components/timing-editor/draw-trajectory.ts+++ b/packages/convert/app/components/timing-editor/draw-trajectory.ts@@ -25,7 +25,8 @@ const getY = ({springTrajectory: number[];}) => {const range = max - min;- const normalizedValue = range === 0 ? 0.5 : (springTrajectory[i] - min) / range;+ const normalizedValue =+ range === 0 ? 0.5 : (springTrajectory[i] - min) / range;return ((canvasHeight - PADDING_TOP - PADDING_BOTTOM) * (1 - normalizedValue) +PADDING_TOP@@ -96,7 +97,7 @@ export const drawTrajectory = ({if (animate) {const scaleEl = document.getElementById('spring-scale');const translateEl = document.getElementById('spring-translate');- const rotateEl = document.getElementById('spring-rotate');+ const opacityEl = document.getElementById('spring-opacity');if (scaleEl) {scaleEl.style.transform = `scale(${springTrajectory[i]})`;@@ -106,16 +107,12 @@ export const drawTrajectory = ({translateEl.style.transform = `translateY(${interpolate(springTrajectory[i],[0, 1],- [100, 0],+ [300, 0],)}px)`;}- if (rotateEl) {- rotateEl.style.transform = `rotate(${interpolate(- springTrajectory[i],- [0, 1],- [Math.PI * 2, 0],- )}rad)`;+ if (opacityEl) {+ opacityEl.style.opacity = springTrajectory[i].toString();}}}