Skip to content

🎥 Make videos programmatically with React

cool, now you can use interpolate

Jonny Burger45b561e032ac
diff --git a/packages/convert/app/components/timing-editor/Canvas.tsx b/packages/convert/app/components/timing-editor/Canvas.tsx
index 4fed2d1d1d..81b8b2b00a 100644
--- a/packages/convert/app/components/timing-editor/Canvas.tsx
+++ b/packages/convert/app/components/timing-editor/Canvas.tsx
@@ -1,15 +1,15 @@
import React, {useEffect, useMemo, useRef} from 'react';
import {draw, stopDrawing} from './draw';
-import type {DraggedConfig} from './types';
+import type {TimingConfig} from './types';
import {AnimationDuration} from './AnimationDuration';
export const Canvas: React.FC<{
readonly width: number;
readonly height: number;
- readonly draggedConfig: DraggedConfig | null;
+ readonly draggedConfig: TimingConfig | null;
readonly draggedDuration: number | null;
readonly duration: number;
- readonly config: DraggedConfig;
+ readonly config: TimingConfig;
readonly fps: number;
}> = ({height, width, draggedConfig, draggedDuration, config, duration, fps}) => {
const canvasRef = useRef<HTMLCanvasElement>(null);
diff --git a/packages/convert/app/components/timing-editor/CanvasWrapper.tsx b/packages/convert/app/components/timing-editor/CanvasWrapper.tsx
index 3dde5112d5..5b37c654ba 100644
--- a/packages/convert/app/components/timing-editor/CanvasWrapper.tsx
+++ b/packages/convert/app/components/timing-editor/CanvasWrapper.tsx
@@ -1,13 +1,13 @@
import {PlayerInternals} from '@remotion/player';
import {useRef} from 'react';
import {Canvas} from './Canvas';
-import type {DraggedConfig} from './types';
+import type {TimingConfig} from './types';
export const CanvasWrapper: React.FC<{
- readonly draggedConfig: DraggedConfig | null;
+ readonly draggedConfig: TimingConfig | null;
readonly draggedDuration: number | null;
readonly duration: number;
- readonly config: DraggedConfig;
+ readonly config: TimingConfig;
readonly fps: number;
}> = ({config, draggedConfig, draggedDuration, duration, fps}) => {
const outer = useRef<HTMLDivElement>(null);
diff --git a/packages/convert/app/components/timing-editor/Sidebar.tsx b/packages/convert/app/components/timing-editor/Sidebar.tsx
index cfb2c44759..141b92ec42 100644
--- a/packages/convert/app/components/timing-editor/Sidebar.tsx
+++ b/packages/convert/app/components/timing-editor/Sidebar.tsx
@@ -1,44 +1,39 @@
import React from 'react';
import {Slider} from '~/components/ui/slider';
-import {SliderLabel} from './SliderLabel';
+import {Tabs, TabsList, TabsTrigger} from '~/components/ui/tabs';
import {CheckboxWithLabel} from './CheckboxWithLabel';
-import {Spacing} from './Spacing';
+import {EASING_OPTIONS} from './defaults';
import {PADDING_LEFT} from './draw-trajectory';
+import {SliderLabel} from './SliderLabel';
+import {Spacing} from './Spacing';
+import type {EasingType, TimingConfig} from './types';
export const Sidebar: React.FC<{
- readonly mass: number;
- readonly damping: number;
- readonly stiffness: number;
- readonly fixedDurationInFrames: number | null;
+ readonly config: TimingConfig;
readonly calculatedDurationInFrames: number;
- readonly delay: number;
+ readonly onModeChange: (mode: 'spring' | 'interpolate') => void;
readonly onMassChange: (e: [number]) => void;
readonly onDampingChange: (e: [number]) => void;
readonly onStiffnessChange: (e: [number]) => void;
readonly onDurationInFramesChange: (e: number | null) => void;
readonly onDelayChange: (e: number) => void;
- readonly overshootClamping: boolean;
readonly onRelease: () => void;
readonly onOvershootClampingChange: (checked: boolean) => void;
- readonly reverse: boolean;
readonly onReverseChange: (checked: boolean) => void;
+ readonly onEasingChange: (easing: EasingType) => void;
}> = ({
- mass,
- onDampingChange,
+ config,
+ calculatedDurationInFrames,
+ onModeChange,
onMassChange,
+ onDampingChange,
onStiffnessChange,
onDurationInFramesChange,
- fixedDurationInFrames,
- overshootClamping,
onRelease,
- damping,
- stiffness,
- calculatedDurationInFrames,
onOvershootClampingChange,
onReverseChange,
- reverse,
- delay,
onDelayChange,
+ onEasingChange,
}) => {
return (
<div
@@ -51,77 +46,169 @@ export const Sidebar: React.FC<{
}}
>
<Spacing y={3} />
- <Slider
- value={[mass]}
- min={0.3}
- step={0.1}
- max={10}
- onValueChange={onMassChange}
- onPointerUp={onRelease}
- />
- <SliderLabel label="mass" value={mass} toggleable={null} />
- <br />
- <Slider
- min={1}
- max={200}
- value={[damping]}
- onValueChange={onDampingChange}
- onPointerUp={onRelease}
- />
- <SliderLabel label="damping" value={damping} toggleable={null} />
- <br />
- <Slider
- min={1}
- max={200}
- value={[stiffness]}
- onValueChange={onStiffnessChange}
- onPointerUp={onRelease}
- />
- <SliderLabel toggleable={null} label="stiffness" value={stiffness} />
- <br />
- <Slider
- min={0}
- max={400}
- value={[delay]}
- onValueChange={(val) => {
- onDelayChange(val[0]);
- }}
- onPointerUp={onRelease}
- />
- <SliderLabel label="delay" toggleable={null} value={delay} />
- <br />
- <Slider
- min={1}
- max={200}
- value={[fixedDurationInFrames ?? calculatedDurationInFrames]}
- style={{opacity: fixedDurationInFrames === null ? 0.5 : 1}}
- onValueChange={(val) => {
- onDurationInFramesChange(val[0]);
- }}
- onPointerUp={onRelease}
- />
- <SliderLabel
- label="durationInFrames"
- toggleable={(enabled) => {
- if (enabled) {
- onDurationInFramesChange(calculatedDurationInFrames);
- } else {
- onDurationInFramesChange(null);
- }
- }}
- value={fixedDurationInFrames ?? null}
- />
- <br />
- <CheckboxWithLabel
- checked={overshootClamping}
- id="overshootClamping"
- onCheckedChange={onOvershootClampingChange}
- />
- <CheckboxWithLabel
- checked={reverse}
- id="reverse"
- onCheckedChange={onReverseChange}
- />
+ <Tabs
+ value={config.type}
+ onValueChange={(value) =>
+ onModeChange(value as 'spring' | 'interpolate')
+ }
+ >
+ <TabsList style={{width: '100%'}}>
+ <TabsTrigger value="spring" style={{flex: 1}}>
+ Spring
+ </TabsTrigger>
+ <TabsTrigger value="interpolate" style={{flex: 1}}>
+ Interpolate
+ </TabsTrigger>
+ </TabsList>
+ </Tabs>
+ <Spacing y={3} />
+
+ {config.type === 'spring' ? (
+ <>
+ <Slider
+ value={[config.springConfig.mass]}
+ min={0.3}
+ step={0.1}
+ max={10}
+ onValueChange={onMassChange}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel
+ label="mass"
+ value={config.springConfig.mass}
+ toggleable={null}
+ />
+ <br />
+ <Slider
+ min={1}
+ max={200}
+ value={[config.springConfig.damping]}
+ onValueChange={onDampingChange}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel
+ label="damping"
+ value={config.springConfig.damping}
+ toggleable={null}
+ />
+ <br />
+ <Slider
+ min={1}
+ max={200}
+ value={[config.springConfig.stiffness]}
+ onValueChange={onStiffnessChange}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel
+ toggleable={null}
+ label="stiffness"
+ value={config.springConfig.stiffness}
+ />
+ <br />
+ <Slider
+ min={0}
+ max={400}
+ value={[config.delay]}
+ onValueChange={(val) => {
+ onDelayChange(val[0]);
+ }}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel label="delay" toggleable={null} value={config.delay} />
+ <br />
+ <Slider
+ min={1}
+ max={200}
+ value={[config.durationInFrames ?? calculatedDurationInFrames]}
+ style={{opacity: config.durationInFrames === null ? 0.5 : 1}}
+ onValueChange={(val) => {
+ onDurationInFramesChange(val[0]);
+ }}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel
+ label="durationInFrames"
+ toggleable={(enabled) => {
+ if (enabled) {
+ onDurationInFramesChange(calculatedDurationInFrames);
+ } else {
+ onDurationInFramesChange(null);
+ }
+ }}
+ value={config.durationInFrames ?? null}
+ />
+ <br />
+ <CheckboxWithLabel
+ checked={config.springConfig.overshootClamping}
+ id="overshootClamping"
+ onCheckedChange={onOvershootClampingChange}
+ />
+ <CheckboxWithLabel
+ checked={config.reverse}
+ id="reverse"
+ onCheckedChange={onReverseChange}
+ />
+ </>
+ ) : (
+ <>
+ <label
+ htmlFor="easing-select"
+ style={{
+ fontSize: 12,
+ color: 'var(--muted-foreground)',
+ marginBottom: 4,
+ }}
+ >
+ Easing
+ </label>
+ <select
+ id="easing-select"
+ value={config.easing}
+ onChange={(e) => onEasingChange(e.target.value as EasingType)}
+ 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>
+ <Slider
+ min={1}
+ max={200}
+ value={[config.durationInFrames]}
+ onValueChange={(val) => {
+ onDurationInFramesChange(val[0]);
+ }}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel
+ label="durationInFrames"
+ toggleable={null}
+ value={config.durationInFrames}
+ />
+ <br />
+ <Slider
+ min={0}
+ max={400}
+ value={[config.delay]}
+ onValueChange={(val) => {
+ onDelayChange(val[0]);
+ }}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel label="delay" toggleable={null} value={config.delay} />
+ </>
+ )}
<Spacing y={2} />
</div>
);
diff --git a/packages/convert/app/components/timing-editor/TimingEditor.tsx b/packages/convert/app/components/timing-editor/TimingEditor.tsx
index b86e56dba1..e9b59815c0 100644
--- a/packages/convert/app/components/timing-editor/TimingEditor.tsx
+++ b/packages/convert/app/components/timing-editor/TimingEditor.tsx
@@ -1,61 +1,73 @@
import {useCallback, useState} from 'react';
-import type {SpringConfig} from 'remotion';
import {measureSpring} from 'remotion';
import {AnimationPreview} from './AnimationPreview';
import {CanvasWrapper} from './CanvasWrapper';
-import {DEFAULT_DAMPING, DEFAULT_MASS, DEFAULT_STIFFNESS} from './defaults';
+import {
+ DEFAULT_INTERPOLATE_CONFIG,
+ DEFAULT_SPRING_CONFIG,
+} from './defaults';
import {Header} from './Header';
import {Sidebar} from './Sidebar';
-import type {DraggedConfig} from './types';
+import type {EasingType, TimingConfig} from './types';
const fps = 60;
export function TimingEditor() {
- const [config, setConfig] = useState<
- SpringConfig & {
- reverse: boolean;
- durationInFrames: number | null;
- delay: number;
+ const [config, setConfig] = useState<TimingConfig>(DEFAULT_SPRING_CONFIG);
+ const [draggedConfig, setDraggedConfig] = useState<TimingConfig | null>(null);
+
+ const onModeChange = useCallback((mode: 'spring' | 'interpolate') => {
+ if (mode === 'spring') {
+ setConfig(DEFAULT_SPRING_CONFIG);
+ } else {
+ setConfig(DEFAULT_INTERPOLATE_CONFIG);
}
- >({
- damping: DEFAULT_DAMPING,
- mass: DEFAULT_MASS,
- stiffness: DEFAULT_STIFFNESS,
- overshootClamping: false,
- reverse: false,
- durationInFrames: null,
- delay: 0,
- });
-
- const [draggedConfig, setDraggedConfig] = useState<DraggedConfig | null>(
- null,
- );
+
+ setDraggedConfig(null);
+ }, []);
const onMassChange = useCallback(
(e: [number]) => {
- setDraggedConfig({...config, mass: e[0]});
+ if (config.type !== 'spring') return;
+ setDraggedConfig({
+ ...config,
+ springConfig: {...config.springConfig, mass: e[0]},
+ });
},
[config],
);
const onDampingChange = useCallback(
(e: number[]) => {
- setDraggedConfig({...config, damping: e[0]});
+ if (config.type !== 'spring') return;
+ setDraggedConfig({
+ ...config,
+ springConfig: {...config.springConfig, damping: e[0]},
+ });
},
[config],
);
const onStiffnessChange = useCallback(
(e: number[]) => {
- setDraggedConfig({...config, stiffness: e[0]});
+ if (config.type !== 'spring') return;
+ setDraggedConfig({
+ ...config,
+ springConfig: {...config.springConfig, stiffness: e[0]},
+ });
},
[config],
);
const onDurationInFramesChange = useCallback(
(e: number | null) => {
- setDraggedConfig({...config, durationInFrames: e});
- setConfig({...config, durationInFrames: e});
+ if (config.type === 'spring') {
+ setDraggedConfig({...config, durationInFrames: e});
+ setConfig({...config, durationInFrames: e});
+ } else if (e !== null) {
+ setDraggedConfig({...config, durationInFrames: e});
+ setConfig({...config, durationInFrames: e});
+ }
},
[config],
);
@@ -70,57 +82,68 @@ export function TimingEditor() {
const onOvershootClampingChange = useCallback(
(checked: boolean) => {
- setDraggedConfig({
- ...config,
- overshootClamping: checked,
- });
- setConfig({
+ if (config.type !== 'spring') return;
+ const newConfig = {
...config,
- overshootClamping: checked,
- });
+ springConfig: {...config.springConfig, overshootClamping: checked},
+ };
+ setDraggedConfig(newConfig);
+ setConfig(newConfig);
},
[config],
);
const onReverseChange = useCallback(
(checked: boolean) => {
- setDraggedConfig({
- ...config,
- reverse: checked,
- });
- setConfig({
- ...config,
- reverse: checked,
- });
+ if (config.type !== 'spring') return;
+ const newConfig = {...config, reverse: checked};
+ setDraggedConfig(newConfig);
+ setConfig(newConfig);
+ },
+ [config],
+ );
+
+ const onEasingChange = useCallback(
+ (easing: EasingType) => {
+ if (config.type !== 'interpolate') return;
+ const newConfig = {...config, easing};
+ setDraggedConfig(null);
+ setConfig(newConfig);
},
[config],
);
const onRelease = useCallback(() => {
if (draggedConfig) {
- setConfig(draggedConfig as DraggedConfig);
+ setConfig(draggedConfig);
}
setDraggedConfig(null);
}, [draggedConfig]);
+ const currentConfig = draggedConfig ?? config;
+
const duration =
- config.delay +
- (config.durationInFrames
- ? config.durationInFrames
- : measureSpring({
+ currentConfig.delay +
+ (currentConfig.type === 'spring'
+ ? currentConfig.durationInFrames ??
+ measureSpring({
fps,
threshold: 0.001,
- config,
- }));
+ config: currentConfig.springConfig,
+ })
+ : currentConfig.durationInFrames);
+
const draggedDuration = draggedConfig
- ? draggedConfig.durationInFrames
- ? draggedConfig.durationInFrames + draggedConfig.delay
- : measureSpring({
- fps,
- threshold: 0.001,
- config: draggedConfig,
- }) + draggedConfig.delay
+ ? draggedConfig.delay +
+ (draggedConfig.type === 'spring'
+ ? draggedConfig.durationInFrames ??
+ measureSpring({
+ fps,
+ threshold: 0.001,
+ config: draggedConfig.springConfig,
+ })
+ : draggedConfig.durationInFrames)
: null;
return (
@@ -148,16 +171,9 @@ export function TimingEditor() {
}}
>
<Sidebar
- mass={draggedConfig?.mass ?? config.mass}
- damping={draggedConfig?.damping ?? config.damping}
- stiffness={draggedConfig?.stiffness ?? config.stiffness}
- overshootClamping={config.overshootClamping}
- reverse={config.reverse}
- fixedDurationInFrames={
- draggedConfig?.durationInFrames ?? config.durationInFrames
- }
+ config={currentConfig}
calculatedDurationInFrames={duration}
- delay={draggedConfig?.delay ?? config.delay}
+ onModeChange={onModeChange}
onMassChange={onMassChange}
onDampingChange={onDampingChange}
onStiffnessChange={onStiffnessChange}
@@ -166,6 +182,7 @@ export function TimingEditor() {
onReverseChange={onReverseChange}
onDurationInFramesChange={onDurationInFramesChange}
onDelayChange={onDelayChange}
+ onEasingChange={onEasingChange}
/>
<div id="spring-canvas">
<CanvasWrapper
diff --git a/packages/convert/app/components/timing-editor/defaults.ts b/packages/convert/app/components/timing-editor/defaults.ts
index fcd7aa9460..11553ff11a 100644
--- a/packages/convert/app/components/timing-editor/defaults.ts
+++ b/packages/convert/app/components/timing-editor/defaults.ts
@@ -1,3 +1,51 @@
+import type {EasingType, InterpolateTimingConfig, SpringTimingConfig} from './types';
+
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_SPRING_CONFIG: SpringTimingConfig = {
+ type: 'spring',
+ springConfig: {
+ damping: DEFAULT_DAMPING,
+ mass: DEFAULT_MASS,
+ stiffness: DEFAULT_STIFFNESS,
+ overshootClamping: false,
+ },
+ reverse: false,
+ durationInFrames: null,
+ delay: 0,
+};
+
+export const DEFAULT_INTERPOLATE_CONFIG: InterpolateTimingConfig = {
+ type: 'interpolate',
+ easing: DEFAULT_EASING,
+ durationInFrames: DEFAULT_INTERPOLATE_DURATION,
+ delay: 0,
+};
+
+export const EASING_OPTIONS: {value: EasingType; label: string}[] = [
+ {value: 'linear', label: 'Linear'},
+ {value: 'ease', label: 'Ease'},
+ {value: 'ease-in-quad', label: 'Ease In (Quad)'},
+ {value: 'ease-out-quad', label: 'Ease Out (Quad)'},
+ {value: 'ease-in-out-quad', label: 'Ease In-Out (Quad)'},
+ {value: 'ease-in-cubic', label: 'Ease In (Cubic)'},
+ {value: 'ease-out-cubic', label: 'Ease Out (Cubic)'},
+ {value: 'ease-in-out-cubic', label: 'Ease In-Out (Cubic)'},
+ {value: 'ease-in-sin', label: 'Ease In (Sin)'},
+ {value: 'ease-out-sin', label: 'Ease Out (Sin)'},
+ {value: 'ease-in-out-sin', label: 'Ease In-Out (Sin)'},
+ {value: 'ease-in-exp', label: 'Ease In (Exp)'},
+ {value: 'ease-out-exp', label: 'Ease Out (Exp)'},
+ {value: 'ease-in-out-exp', label: 'Ease In-Out (Exp)'},
+ {value: 'ease-in-circle', label: 'Ease In (Circle)'},
+ {value: 'ease-out-circle', label: 'Ease Out (Circle)'},
+ {value: 'ease-in-out-circle', label: 'Ease In-Out (Circle)'},
+ {value: 'ease-in-bounce', label: 'Ease In (Bounce)'},
+ {value: 'ease-out-bounce', label: 'Ease Out (Bounce)'},
+ {value: 'ease-in-out-bounce', label: 'Ease In-Out (Bounce)'},
+];
diff --git a/packages/convert/app/components/timing-editor/draw-trajectory.ts b/packages/convert/app/components/timing-editor/draw-trajectory.ts
index 401d03d147..e42e02fff3 100644
--- a/packages/convert/app/components/timing-editor/draw-trajectory.ts
+++ b/packages/convert/app/components/timing-editor/draw-trajectory.ts
@@ -67,6 +67,7 @@ export const drawTrajectory = ({
setTimeout(resolve, intervalBetweenDraw - timeSinceLastDraw);
});
}
+
if (stopped) {
break;
}
@@ -100,6 +101,7 @@ export const drawTrajectory = ({
if (scaleEl) {
scaleEl.style.transform = `scale(${springTrajectory[i]})`;
}
+
if (translateEl) {
translateEl.style.transform = `translateY(${interpolate(
springTrajectory[i],
@@ -107,6 +109,7 @@ export const drawTrajectory = ({
[100, 0],
)}px)`;
}
+
if (rotateEl) {
rotateEl.style.transform = `rotate(${interpolate(
springTrajectory[i],
diff --git a/packages/convert/app/components/timing-editor/draw.ts b/packages/convert/app/components/timing-editor/draw.ts
index f4da3ff27c..a516381b73 100644
--- a/packages/convert/app/components/timing-editor/draw.ts
+++ b/packages/convert/app/components/timing-editor/draw.ts
@@ -8,7 +8,7 @@ import {
PADDING_TOP,
drawTrajectory,
} from './draw-trajectory';
-import type {DraggedConfig} from './types';
+import type {TimingConfig} from './types';
export let stopDrawing = () => {};
@@ -26,8 +26,8 @@ export const draw = ({
ref: HTMLCanvasElement;
duration: number;
fps: number;
- config: DraggedConfig;
- draggedConfig: DraggedConfig | null;
+ config: TimingConfig;
+ draggedConfig: TimingConfig | null;
draggedDuration: number | null;
width: number;
height: number;
diff --git a/packages/convert/app/components/timing-editor/get-trajectory.ts b/packages/convert/app/components/timing-editor/get-trajectory.ts
index 4e088aa497..85e84bbd41 100644
--- a/packages/convert/app/components/timing-editor/get-trajectory.ts
+++ b/packages/convert/app/components/timing-editor/get-trajectory.ts
@@ -1,19 +1,91 @@
-import {spring} from 'remotion';
-import type {DraggedConfig} from './types';
+import {Easing, interpolate, spring} from 'remotion';
+import type {EasingType, TimingConfig} from './types';
+
+const getEasingFunction = (easing: EasingType): ((t: number) => number) => {
+ switch (easing) {
+ case 'linear':
+ return Easing.linear;
+ case 'ease':
+ return Easing.ease;
+ case 'ease-in-quad':
+ return Easing.in(Easing.quad);
+ case 'ease-out-quad':
+ return Easing.out(Easing.quad);
+ case 'ease-in-out-quad':
+ return Easing.inOut(Easing.quad);
+ case 'ease-in-cubic':
+ return Easing.in(Easing.cubic);
+ case 'ease-out-cubic':
+ return Easing.out(Easing.cubic);
+ case 'ease-in-out-cubic':
+ return Easing.inOut(Easing.cubic);
+ case 'ease-in-sin':
+ return Easing.in(Easing.sin);
+ case 'ease-out-sin':
+ return Easing.out(Easing.sin);
+ case 'ease-in-out-sin':
+ return Easing.inOut(Easing.sin);
+ case 'ease-in-exp':
+ return Easing.in(Easing.exp);
+ case 'ease-out-exp':
+ return Easing.out(Easing.exp);
+ case 'ease-in-out-exp':
+ return Easing.inOut(Easing.exp);
+ case 'ease-in-circle':
+ return Easing.in(Easing.circle);
+ case 'ease-out-circle':
+ return Easing.out(Easing.circle);
+ case 'ease-in-out-circle':
+ return Easing.inOut(Easing.circle);
+ case 'ease-in-bounce':
+ return Easing.in(Easing.bounce);
+ case 'ease-out-bounce':
+ return Easing.out(Easing.bounce);
+ case 'ease-in-out-bounce':
+ return Easing.inOut(Easing.bounce);
+ default:
+ return Easing.linear;
+ }
+};
export const getTrajectory = (
durationInFrames: number,
fps: number,
- {reverse, ...config}: DraggedConfig,
-) => {
+ config: TimingConfig,
+): number[] => {
+ if (config.type === 'spring') {
+ const {springConfig, reverse, delay} = config;
+ return new Array(durationInFrames).fill(true).map((_, i) => {
+ return spring({
+ fps,
+ frame: i,
+ config: springConfig,
+ reverse,
+ durationInFrames: config.durationInFrames ?? undefined,
+ delay: delay ?? undefined,
+ });
+ });
+ }
+
+ // Interpolate mode
+ const {easing, delay: interpolateDelay} = config;
+ const easingFn = getEasingFunction(easing);
+ const animationDuration = config.durationInFrames;
+
return new Array(durationInFrames).fill(true).map((_, i) => {
- return spring({
- fps,
- frame: i,
- config,
- reverse,
- durationInFrames: config.durationInFrames ?? undefined,
- delay: config.delay ?? undefined,
+ if (i < interpolateDelay) {
+ return 0;
+ }
+
+ const frameInAnimation = i - interpolateDelay;
+ if (frameInAnimation >= animationDuration) {
+ return 1;
+ }
+
+ return interpolate(frameInAnimation, [0, animationDuration], [0, 1], {
+ easing: easingFn,
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
});
});
};
diff --git a/packages/convert/app/components/timing-editor/types.ts b/packages/convert/app/components/timing-editor/types.ts
index 49a55636d8..d4097adc38 100644
--- a/packages/convert/app/components/timing-editor/types.ts
+++ b/packages/convert/app/components/timing-editor/types.ts
@@ -1,7 +1,40 @@
import type {SpringConfig} from 'remotion';
-export type DraggedConfig = SpringConfig & {
+export type EasingType =
+ | 'linear'
+ | 'ease'
+ | 'ease-in-quad'
+ | 'ease-out-quad'
+ | 'ease-in-out-quad'
+ | 'ease-in-cubic'
+ | 'ease-out-cubic'
+ | 'ease-in-out-cubic'
+ | 'ease-in-sin'
+ | 'ease-out-sin'
+ | 'ease-in-out-sin'
+ | 'ease-in-exp'
+ | 'ease-out-exp'
+ | 'ease-in-out-exp'
+ | 'ease-in-circle'
+ | 'ease-out-circle'
+ | 'ease-in-out-circle'
+ | 'ease-in-bounce'
+ | 'ease-out-bounce'
+ | 'ease-in-out-bounce';
+
+export type SpringTimingConfig = {
+ type: 'spring';
+ springConfig: SpringConfig;
reverse: boolean;
durationInFrames: number | null;
delay: number;
};
+
+export type InterpolateTimingConfig = {
+ type: 'interpolate';
+ easing: EasingType;
+ durationInFrames: number;
+ delay: number;
+};
+
+export type TimingConfig = SpringTimingConfig | InterpolateTimingConfig;