Skip to content

🎥 Make videos programmatically with React

vibing...

Jonny Burgera2a0f91f3b65
diff --git a/packages/convert/app/components/timing-editor/Header.tsx b/packages/convert/app/components/timing-editor/Header.tsx
deleted file mode 100644
index 6a822de190..0000000000
--- a/packages/convert/app/components/timing-editor/Header.tsx
+++ /dev/null
@@ -1,26 +0,0 @@
-import React from 'react';
-
-export const Header: React.FC = () => {
- return (
- <div
- style={{
- display: 'flex',
- flexDirection: 'row',
- fontFamily: 'GTPlanar',
- fontWeight: 'bold',
- width: '100%',
- height: 60,
- borderBottom: '1px solid #242424',
- alignItems: 'center',
- paddingLeft: 20,
- paddingRight: 18,
- }}
- >
- <div style={{fontSize: 20}}>Timing Editor</div>
- <div style={{flex: 1}} />
- <a href="https://remotion.dev" target="_blank" rel="noreferrer">
- <img style={{height: 60}} src="/remotion.png" alt="Remotion" />
- </a>
- </div>
- );
-};
diff --git a/packages/convert/app/components/timing-editor/InterpolateEditor.tsx b/packages/convert/app/components/timing-editor/InterpolateEditor.tsx
new file mode 100644
index 0000000000..8d815ac57e
--- /dev/null
+++ b/packages/convert/app/components/timing-editor/InterpolateEditor.tsx
@@ -0,0 +1,74 @@
+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';
+
+export const InterpolateEditor: React.FC<{
+ readonly config: InterpolateTimingConfig;
+ readonly onChange: (config: InterpolateTimingConfig) => void;
+ readonly onRelease: () => void;
+}> = ({config, onChange, 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});
+ }}
+ 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) => {
+ onChange({...config, durationInFrames: val[0]});
+ }}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel
+ label="durationInFrames"
+ toggleable={null}
+ value={config.durationInFrames}
+ />
+ <br />
+ <Slider
+ min={0}
+ max={400}
+ value={[config.delay]}
+ onValueChange={(val) => {
+ onChange({...config, delay: val[0]});
+ }}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel label="delay" toggleable={null} value={config.delay} />
+ </>
+ );
+};
diff --git a/packages/convert/app/components/timing-editor/Sidebar.tsx b/packages/convert/app/components/timing-editor/Sidebar.tsx
index 2826cc6968..8d215a92fe 100644
--- a/packages/convert/app/components/timing-editor/Sidebar.tsx
+++ b/packages/convert/app/components/timing-editor/Sidebar.tsx
@@ -1,45 +1,18 @@
import React from 'react';
-import {Slider} from '~/components/ui/slider';
import {Tabs, TabsList, TabsTrigger} from '~/components/ui/tabs';
-import {CheckboxWithLabel} from './CheckboxWithLabel';
-import {EASING_OPTIONS} from './defaults';
-import {SliderLabel} from './SliderLabel';
+import {InterpolateEditor} from './InterpolateEditor';
+import {SineEditor} from './SineEditor';
import {Spacing} from './Spacing';
-import type {EasingType, TimingConfig} from './types';
+import {SpringEditor} from './SpringEditor';
+import type {TimingConfig} from './types';
export const Sidebar: React.FC<{
readonly config: TimingConfig;
readonly calculatedDurationInFrames: number;
readonly onModeChange: (mode: 'spring' | 'interpolate' | 'sine') => 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 onChange: (config: TimingConfig) => void;
readonly onRelease: () => void;
- readonly onOvershootClampingChange: (checked: boolean) => void;
- readonly onReverseChange: (checked: boolean) => void;
- readonly onEasingChange: (easing: EasingType) => void;
- readonly onAmplitudeChange: (e: number) => void;
- readonly onFrequencyChange: (e: number) => void;
- readonly onFrameOffsetChange: (e: number) => void;
-}> = ({
- config,
- calculatedDurationInFrames,
- onModeChange,
- onMassChange,
- onDampingChange,
- onStiffnessChange,
- onDurationInFramesChange,
- onRelease,
- onOvershootClampingChange,
- onReverseChange,
- onDelayChange,
- onEasingChange,
- onAmplitudeChange,
- onFrequencyChange,
- onFrameOffsetChange,
-}) => {
+}> = ({config, calculatedDurationInFrames, onModeChange, onChange, onRelease}) => {
return (
<div
id="spring-sidebar"
@@ -50,6 +23,16 @@ export const Sidebar: React.FC<{
borderRight: '1px solid #242424',
}}
>
+ <div
+ style={{
+ fontFamily: 'GTPlanar',
+ fontWeight: 'bold',
+ fontSize: 20,
+ marginBottom: 16,
+ }}
+ >
+ Timing Editor
+ </div>
<Tabs
value={config.type}
onValueChange={(value) =>
@@ -68,212 +51,23 @@ export const Sidebar: React.FC<{
</TabsTrigger>
</TabsList>
</Tabs>
- <Spacing y={3} />
+ <Spacing y={2} />
{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}
- />
- <Slider
- min={1}
- max={200}
- value={[config.springConfig.damping]}
- onValueChange={onDampingChange}
- onPointerUp={onRelease}
- />
- <SliderLabel
- label="damping"
- value={config.springConfig.damping}
- toggleable={null}
- />
- <Slider
- min={1}
- max={200}
- value={[config.springConfig.stiffness]}
- onValueChange={onStiffnessChange}
- onPointerUp={onRelease}
- />
- <SliderLabel
- toggleable={null}
- label="stiffness"
- value={config.springConfig.stiffness}
- />
- <Slider
- min={0}
- max={400}
- value={[config.delay]}
- onValueChange={(val) => {
- onDelayChange(val[0]);
- }}
- onPointerUp={onRelease}
- />
- <SliderLabel label="delay" toggleable={null} value={config.delay} />
- <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}
- />
- <CheckboxWithLabel
- checked={config.springConfig.overshootClamping}
- id="overshootClamping"
- onCheckedChange={onOvershootClampingChange}
- />
- <CheckboxWithLabel
- checked={config.reverse}
- id="reverse"
- onCheckedChange={onReverseChange}
- />
- </>
+ <SpringEditor
+ config={config}
+ calculatedDurationInFrames={calculatedDurationInFrames}
+ onChange={onChange}
+ onRelease={onRelease}
+ />
) : config.type === 'interpolate' ? (
- <>
- <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} />
- </>
+ <InterpolateEditor
+ config={config}
+ onChange={onChange}
+ onRelease={onRelease}
+ />
) : (
- <>
- <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.1}
- max={2}
- step={0.1}
- value={[config.amplitude]}
- onValueChange={(val) => {
- onAmplitudeChange(val[0]);
- }}
- onPointerUp={onRelease}
- />
- <SliderLabel
- label="amplitude"
- toggleable={null}
- value={config.amplitude}
- />
- <br />
- <Slider
- min={0.1}
- max={10}
- step={0.1}
- value={[config.frequency]}
- onValueChange={(val) => {
- onFrequencyChange(val[0]);
- }}
- onPointerUp={onRelease}
- />
- <SliderLabel
- label="frequency"
- toggleable={null}
- value={config.frequency}
- />
- <br />
- <Slider
- min={0}
- max={100}
- value={[config.frameOffset]}
- onValueChange={(val) => {
- onFrameOffsetChange(val[0]);
- }}
- onPointerUp={onRelease}
- />
- <SliderLabel
- label="frameOffset"
- toggleable={null}
- value={config.frameOffset}
- />
- </>
+ <SineEditor config={config} onChange={onChange} onRelease={onRelease} />
)}
<Spacing y={2} />
</div>
diff --git a/packages/convert/app/components/timing-editor/SineEditor.tsx b/packages/convert/app/components/timing-editor/SineEditor.tsx
new file mode 100644
index 0000000000..b2e5bffbad
--- /dev/null
+++ b/packages/convert/app/components/timing-editor/SineEditor.tsx
@@ -0,0 +1,68 @@
+import React from 'react';
+import {Slider} from '~/components/ui/slider';
+import {SliderLabel} from './SliderLabel';
+import type {SineTimingConfig} from './types';
+
+export const SineEditor: React.FC<{
+ readonly config: SineTimingConfig;
+ readonly onChange: (config: SineTimingConfig) => void;
+ readonly onRelease: () => void;
+}> = ({config, onChange, onRelease}) => {
+ return (
+ <>
+ <Slider
+ min={1}
+ max={200}
+ value={[config.durationInFrames]}
+ onValueChange={(val) => {
+ onChange({...config, durationInFrames: val[0]});
+ }}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel
+ label="durationInFrames"
+ toggleable={null}
+ value={config.durationInFrames}
+ />
+ <br />
+ <Slider
+ min={0.1}
+ max={2}
+ step={0.1}
+ value={[config.amplitude]}
+ onValueChange={(val) => {
+ onChange({...config, amplitude: val[0]});
+ }}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel label="amplitude" toggleable={null} value={config.amplitude} />
+ <br />
+ <Slider
+ min={0.1}
+ max={10}
+ step={0.1}
+ value={[config.frequency]}
+ onValueChange={(val) => {
+ onChange({...config, frequency: val[0]});
+ }}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel label="frequency" toggleable={null} value={config.frequency} />
+ <br />
+ <Slider
+ min={0}
+ max={100}
+ value={[config.frameOffset]}
+ onValueChange={(val) => {
+ onChange({...config, frameOffset: val[0]});
+ }}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel
+ label="frameOffset"
+ toggleable={null}
+ value={config.frameOffset}
+ />
+ </>
+ );
+};
diff --git a/packages/convert/app/components/timing-editor/SpringEditor.tsx b/packages/convert/app/components/timing-editor/SpringEditor.tsx
new file mode 100644
index 0000000000..35a65c34c7
--- /dev/null
+++ b/packages/convert/app/components/timing-editor/SpringEditor.tsx
@@ -0,0 +1,117 @@
+import React from 'react';
+import {Slider} from '~/components/ui/slider';
+import {CheckboxWithLabel} from './CheckboxWithLabel';
+import {SliderLabel} from './SliderLabel';
+import type {SpringTimingConfig} from './types';
+
+export const SpringEditor: React.FC<{
+ readonly config: SpringTimingConfig;
+ readonly calculatedDurationInFrames: number;
+ readonly onChange: (config: SpringTimingConfig) => void;
+ readonly onRelease: () => void;
+}> = ({config, calculatedDurationInFrames, onChange, onRelease}) => {
+ return (
+ <>
+ <Slider
+ value={[config.springConfig.mass]}
+ min={0.3}
+ step={0.1}
+ max={10}
+ onValueChange={(val) => {
+ onChange({
+ ...config,
+ springConfig: {...config.springConfig, mass: val[0]},
+ });
+ }}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel
+ label="mass"
+ value={config.springConfig.mass}
+ toggleable={null}
+ />
+ <Slider
+ min={1}
+ max={200}
+ value={[config.springConfig.damping]}
+ onValueChange={(val) => {
+ onChange({
+ ...config,
+ springConfig: {...config.springConfig, damping: val[0]},
+ });
+ }}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel
+ label="damping"
+ value={config.springConfig.damping}
+ toggleable={null}
+ />
+ <Slider
+ min={1}
+ max={200}
+ value={[config.springConfig.stiffness]}
+ onValueChange={(val) => {
+ onChange({
+ ...config,
+ springConfig: {...config.springConfig, stiffness: val[0]},
+ });
+ }}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel
+ toggleable={null}
+ label="stiffness"
+ value={config.springConfig.stiffness}
+ />
+ <Slider
+ min={0}
+ max={400}
+ value={[config.delay]}
+ onValueChange={(val) => {
+ onChange({...config, delay: val[0]});
+ }}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel label="delay" toggleable={null} value={config.delay} />
+ <Slider
+ min={1}
+ max={200}
+ value={[config.durationInFrames ?? calculatedDurationInFrames]}
+ style={{opacity: config.durationInFrames === null ? 0.5 : 1}}
+ onValueChange={(val) => {
+ onChange({...config, durationInFrames: val[0]});
+ }}
+ onPointerUp={onRelease}
+ />
+ <SliderLabel
+ label="durationInFrames"
+ toggleable={(enabled) => {
+ if (enabled) {
+ onChange({...config, durationInFrames: calculatedDurationInFrames});
+ } else {
+ onChange({...config, durationInFrames: null});
+ }
+ }}
+ value={config.durationInFrames ?? null}
+ />
+ <CheckboxWithLabel
+ checked={config.springConfig.overshootClamping}
+ id="overshootClamping"
+ onCheckedChange={(checked) => {
+ onChange({
+ ...config,
+ springConfig: {...config.springConfig, overshootClamping: checked},
+ });
+ }}
+ />
+ <CheckboxWithLabel
+ checked={config.reverse}
+ id="reverse"
+ onCheckedChange={(checked) => {
+ onChange({...config, reverse: checked});
+ }}
+ />
+ </>
+ );
+};
diff --git a/packages/convert/app/components/timing-editor/TimingEditor.tsx b/packages/convert/app/components/timing-editor/TimingEditor.tsx
index 9d0d483ca0..d20d68eb53 100644
--- a/packages/convert/app/components/timing-editor/TimingEditor.tsx
+++ b/packages/convert/app/components/timing-editor/TimingEditor.tsx
@@ -7,9 +7,8 @@ import {
DEFAULT_SINE_CONFIG,
DEFAULT_SPRING_CONFIG,
} from './defaults';
-import {Header} from './Header';
import {Sidebar} from './Sidebar';
-import type {EasingType, TimingConfig} from './types';
+import type {TimingConfig} from './types';
const fps = 60;
@@ -32,120 +31,9 @@ export function TimingEditor() {
[],
);
- const onMassChange = useCallback(
- (e: [number]) => {
- if (config.type !== 'spring') return;
- setDraggedConfig({
- ...config,
- springConfig: {...config.springConfig, mass: e[0]},
- });
- },
- [config],
- );
-
- const onDampingChange = useCallback(
- (e: number[]) => {
- if (config.type !== 'spring') return;
- setDraggedConfig({
- ...config,
- springConfig: {...config.springConfig, damping: e[0]},
- });
- },
- [config],
- );
-
- const onStiffnessChange = useCallback(
- (e: number[]) => {
- if (config.type !== 'spring') return;
- setDraggedConfig({
- ...config,
- springConfig: {...config.springConfig, stiffness: e[0]},
- });
- },
- [config],
- );
-
- const onDurationInFramesChange = useCallback(
- (e: number | null) => {
- if (config.type === 'spring') {
- setDraggedConfig({...config, durationInFrames: e});
- setConfig({...config, durationInFrames: e});
- } else if (e !== null) {
- // Interpolate mode: only set draggedConfig during drag
- setDraggedConfig({...config, durationInFrames: e});
- }
- },
- [config],
- );
-
- const onDelayChange = useCallback(
- (e: number) => {
- if (config.type === 'sine') return;
- setDraggedConfig({...config, delay: e});
- // Only immediately commit for spring mode
- if (config.type === 'spring') {
- setConfig({...config, delay: e});
- }
- },
- [config],
- );
-
- const onOvershootClampingChange = useCallback(
- (checked: boolean) => {
- if (config.type !== 'spring') return;
- const newConfig = {
- ...config,
- springConfig: {...config.springConfig, overshootClamping: checked},
- };
- setDraggedConfig(newConfig);
- setConfig(newConfig);
- },
- [config],
- );
-
- const onReverseChange = useCallback(
- (checked: boolean) => {
- 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 onAmplitudeChange = useCallback(
- (amplitude: number) => {
- if (config.type !== 'sine') return;
- setDraggedConfig({...config, amplitude});
- },
- [config],
- );
-
- const onFrequencyChange = useCallback(
- (frequency: number) => {
- if (config.type !== 'sine') return;
- setDraggedConfig({...config, frequency});
- },
- [config],
- );
-
- const onFrameOffsetChange = useCallback(
- (frameOffset: number) => {
- if (config.type !== 'sine') return;
- setDraggedConfig({...config, frameOffset});
- },
- [config],
- );
+ const onChange = useCallback((newConfig: TimingConfig) => {
+ setDraggedConfig(newConfig);
+ }, []);
const onRelease = useCallback(() => {
if (draggedConfig) {
@@ -193,12 +81,10 @@ export function TimingEditor() {
flexDirection: 'column',
}}
>
- <Header />
<div
id="spring-app"
style={{
display: 'flex',
- borderRadius: 8,
overflow: 'hidden',
width: '100%',
flex: 1,
@@ -208,18 +94,8 @@ export function TimingEditor() {
config={currentConfig}
calculatedDurationInFrames={duration}
onModeChange={onModeChange}
- onMassChange={onMassChange}
- onDampingChange={onDampingChange}
- onStiffnessChange={onStiffnessChange}
+ onChange={onChange}
onRelease={onRelease}
- onOvershootClampingChange={onOvershootClampingChange}
- onReverseChange={onReverseChange}
- onDurationInFramesChange={onDurationInFramesChange}
- onDelayChange={onDelayChange}
- onEasingChange={onEasingChange}
- onAmplitudeChange={onAmplitudeChange}
- onFrequencyChange={onFrequencyChange}
- onFrameOffsetChange={onFrameOffsetChange}
/>
<div id="spring-canvas">
<CanvasWrapper