Skip to content

🎥 Make videos programmatically with React

simplify

Jonny Burgerb04b5ea74e0c
diff --git a/packages/studio-server/src/codemods/recast-mods.ts b/packages/studio-server/src/codemods/recast-mods.ts
index 8587b41a43..94082cf7ec 100644
--- a/packages/studio-server/src/codemods/recast-mods.ts
+++ b/packages/studio-server/src/codemods/recast-mods.ts
@@ -224,7 +224,7 @@ const getCompositionIdFromJSXElement = (
return null;
}
- if (name.name !== 'Composition') {
+ if (name.name !== 'Composition' && name.name !== 'Still') {
return null;
}
diff --git a/packages/studio/src/components/NewComposition/DuplicateComposition.tsx b/packages/studio/src/components/NewComposition/DuplicateComposition.tsx
index 9b8e6e0203..ae7cd4e886 100644
--- a/packages/studio/src/components/NewComposition/DuplicateComposition.tsx
+++ b/packages/studio/src/components/NewComposition/DuplicateComposition.tsx
@@ -15,16 +15,13 @@ import {
validateCompositionDimension,
validateCompositionName,
} from '../../helpers/validate-new-comp-data';
-import {
- loadAspectRatioOption,
- persistAspectRatioOption,
-} from '../../state/aspect-ratio-locked';
import {ModalsContext} from '../../state/modals';
import {Button} from '../Button';
import {Flex, Row, Spacing} from '../layout';
import {ModalContainer} from '../ModalContainer';
import {NewCompHeader} from '../ModalHeader';
import {showNotification} from '../Notifications/NotificationCenter';
+import {label, optionRow, rightRow} from '../RenderModal/layout';
import {
ResolveCompositionBeforeModal,
ResolvedCompositionContext,
@@ -33,8 +30,6 @@ import {applyCodemod, getProjectInfo} from '../RenderQueue/actions';
import type {ComboboxValue} from './ComboBox';
import {Combobox} from './ComboBox';
import {InputDragger} from './InputDragger';
-import {inputArea, leftLabel} from './new-comp-layout';
-import {NewCompAspectRatio} from './NewCompAspectRatio';
import {NewCompDuration} from './NewCompDuration';
import {RemotionInput} from './RemInput';
import {ValidationMessage} from './ValidationMessage';
@@ -44,10 +39,11 @@ const content: React.CSSProperties = {
paddingRight: 12,
flex: 1,
fontSize: 13,
+ minWidth: 500,
};
const comboBoxStyle: React.CSSProperties = {
- width: inputArea.width,
+ width: 190,
};
const buttonStyle: React.CSSProperties = {
@@ -65,10 +61,15 @@ const DuplicateCompositionLoaded: React.FC<{
throw new Error('Resolved composition context');
}
- const {resolved} = context;
+ const {resolved, unresolved} = context;
const initialCompType: CompType =
resolved.result.durationInFrames === 1 ? 'still' : 'composition';
+
+ const hadDimensionsDefined = unresolved.width && unresolved.height;
+ const hadFpsDefined = unresolved.fps !== undefined;
+ const hadDurationDefined = unresolved.durationInFrames !== undefined;
+
const [selectedFrameRate, setFrameRate] = useState<string>(
String(resolved.result.fps),
);
@@ -120,92 +121,56 @@ const DuplicateCompositionLoaded: React.FC<{
};
}, []);
- const [lockedAspectRatio, setLockedAspectRatio] = useState(
- loadAspectRatioOption() ? Number(size.width) / Number(size.height) : null,
- );
const [durationInFrames, setDurationInFrames] = useState('150');
- const setAspectRatioLocked = useCallback(
- (option: boolean) => {
- persistAspectRatioOption(option);
- setLockedAspectRatio(
- option ? Number(size.width) / Number(size.height) : null,
- );
- },
- [size.height, size.width],
- );
-
const onTypeChanged = useCallback((newType: CompType) => {
setType(newType);
}, []);
- const onWidthChanged = useCallback(
- (newValue: string) => {
- setSize((s) => {
- const {height} = s;
- const newWidth = Number(newValue);
- return {
- height:
- lockedAspectRatio === null
- ? height
- : String(Math.ceil(newWidth / lockedAspectRatio / 2) * 2),
- width: String(newWidth),
- };
- });
- },
- [lockedAspectRatio],
- );
+ const onWidthChanged = useCallback((newValue: string) => {
+ setSize((s) => {
+ const {height} = s;
+ const newWidth = Number(newValue);
+ return {
+ height,
+ width: String(newWidth),
+ };
+ });
+ }, []);
- const onWidthDirectlyChanged = useCallback(
- (newWidth: number) => {
- setSize((s) => {
- const {height} = s;
-
- return {
- height:
- lockedAspectRatio === null
- ? height
- : String(Math.ceil(newWidth / lockedAspectRatio / 2) * 2),
- width: String(newWidth),
- };
- });
- },
- [lockedAspectRatio],
- );
+ const onWidthDirectlyChanged = useCallback((newWidth: number) => {
+ setSize((s) => {
+ const {height} = s;
- const onHeightDirectlyChanged = useCallback(
- (newHeight: number) => {
- setSize((s) => {
- const {width} = s;
-
- return {
- width:
- lockedAspectRatio === null
- ? width
- : String(Math.ceil((newHeight / 2) * lockedAspectRatio) * 2),
- height: String(newHeight),
- };
- });
- },
- [lockedAspectRatio],
- );
+ return {
+ height,
+ width: String(newWidth),
+ };
+ });
+ }, []);
+
+ const onHeightDirectlyChanged = useCallback((newHeight: number) => {
+ setSize((s) => {
+ const {width} = s;
+
+ return {
+ width,
+ height: String(newHeight),
+ };
+ });
+ }, []);
+
+ const onHeightChanged = useCallback((newValue: string) => {
+ setSize((s) => {
+ const {width} = s;
+ const newHeight = Number(newValue);
+ return {
+ width,
+ height: String(newHeight),
+ };
+ });
+ }, []);
- const onHeightChanged = useCallback(
- (newValue: string) => {
- setSize((s) => {
- const {width} = s;
- const newHeight = Number(newValue);
- return {
- width:
- lockedAspectRatio === null
- ? width
- : String(Math.ceil((newHeight / 2) * lockedAspectRatio) * 2),
- height: String(newHeight),
- };
- });
- },
- [lockedAspectRatio],
- );
const onNameChange: ChangeEventHandler<HTMLInputElement> = useCallback(
(e) => {
setName(e.target.value);
@@ -275,10 +240,12 @@ const DuplicateCompositionLoaded: React.FC<{
codemod: {
type: 'duplicate-composition',
idToDuplicate: resolved.result.id,
- newDurationInFrames: Number(durationInFrames),
- newFps: Number(selectedFrameRate),
- newHeight: Number(size.height),
- newWidth: Number(size.width),
+ newDurationInFrames: hadDurationDefined
+ ? Number(durationInFrames)
+ : null,
+ newFps: hadFpsDefined ? Number(selectedFrameRate) : null,
+ newHeight: hadDimensionsDefined ? Number(size.height) : null,
+ newWidth: hadDimensionsDefined ? Number(size.width) : null,
newId,
},
})
@@ -293,12 +260,14 @@ const DuplicateCompositionLoaded: React.FC<{
});
}, [
durationInFrames,
+ hadDimensionsDefined,
+ hadDurationDefined,
+ hadFpsDefined,
newId,
resolved.result.id,
selectedFrameRate,
setSelectedModal,
- size.height,
- size.width,
+ size,
]);
useEffect(() => {
@@ -327,22 +296,21 @@ const DuplicateCompositionLoaded: React.FC<{
<NewCompHeader title={'Duplicate ' + resolved.result.id} />
<form>
<div style={content}>
- <label>
- <Row align="center">
- <div style={leftLabel}>Type</div>
- <div style={inputArea}>
- <Combobox
- title="Type of composition"
- style={comboBoxStyle}
- values={typeValues}
- selectedId={type}
- />
- </div>
- </Row>
- <Spacing y={1} />
- <Row align="center">
- <div style={leftLabel}>ID</div>
- <div style={inputArea}>
+ <div style={optionRow}>
+ <div style={label}>Type</div>
+ <div style={rightRow}>
+ <Combobox
+ title="Type of composition"
+ style={comboBoxStyle}
+ values={typeValues}
+ selectedId={type}
+ />
+ </div>
+ </div>
+ <div style={optionRow}>
+ <div style={label}>ID</div>
+ <div style={rightRow}>
+ <div>
<RemotionInput
value={newId}
onChange={onNameChange}
@@ -351,7 +319,7 @@ const DuplicateCompositionLoaded: React.FC<{
name="compositionId"
placeholder="Composition ID"
status="ok"
- rightAlign={false}
+ rightAlign
/>
{compNameErrMessage ? (
<>
@@ -364,126 +332,98 @@ const DuplicateCompositionLoaded: React.FC<{
</>
) : null}
</div>
- </Row>
- </label>
- <Spacing y={1} />
- <Row align="center">
- <div>
- <div>
- <label>
- <Row align="center">
- <div style={leftLabel}>Width</div>
- <div style={inputArea}>
- <InputDragger
- type="number"
- value={size.width}
- placeholder="Width"
- onTextChange={onWidthChanged}
- name="width"
- step={2}
- min={2}
- required
- status="ok"
- formatter={(w) => `${w}px`}
- max={100000000}
- onValueChange={onWidthDirectlyChanged}
- rightAlign={false}
+ </div>
+ </div>
+
+ {hadDimensionsDefined ? (
+ <>
+ <div style={optionRow}>
+ <div style={label}>Width</div>
+ <div style={rightRow}>
+ <InputDragger
+ type="number"
+ value={size.width}
+ placeholder="Width"
+ onTextChange={onWidthChanged}
+ name="width"
+ step={2}
+ min={2}
+ required
+ status="ok"
+ formatter={(w) => `${w}px`}
+ max={100000000}
+ onValueChange={onWidthDirectlyChanged}
+ rightAlign={false}
+ />
+ {compWidthErrMessage ? (
+ <>
+ <Spacing y={1} block />
+ <ValidationMessage
+ align="flex-start"
+ message={compWidthErrMessage}
+ type="error"
/>
- {compWidthErrMessage ? (
- <>
- <Spacing y={1} block />
- <ValidationMessage
- align="flex-start"
- message={compWidthErrMessage}
- type="error"
- />
- </>
- ) : null}
- </div>
- </Row>
- </label>
+ </>
+ ) : null}
+ </div>
</div>
- <div />
- <Spacing y={1} />
- <div />
- <label>
- <Row align="center">
- <div style={leftLabel}>Height</div>
- <div style={inputArea}>
- <InputDragger
- type="number"
- value={size.height}
- onTextChange={onHeightChanged}
- placeholder="Height"
- name="height"
- step={2}
- required
- formatter={(h) => `${h}px`}
- min={2}
- status="ok"
- max={100000000}
- onValueChange={onHeightDirectlyChanged}
- rightAlign={false}
- />
- {compHeightErrMessage ? (
- <>
- <Spacing y={1} block />
- <ValidationMessage
- align="flex-start"
- message={compHeightErrMessage}
- type="error"
- />
- </>
- ) : null}
- </div>
- </Row>
- </label>
- </div>
- <div>
- <NewCompAspectRatio
- width={Number(size.width)}
- height={Number(size.height)}
- aspectRatioLocked={lockedAspectRatio}
- setAspectRatioLocked={setAspectRatioLocked}
- />
- </div>
- </Row>
- <div />
- <Spacing y={1} />
- {type === 'composition' ? (
+ <div style={optionRow}>
+ <div style={label}>Height</div>
+ <div style={rightRow}>
+ <InputDragger
+ type="number"
+ value={size.height}
+ onTextChange={onHeightChanged}
+ placeholder="Height"
+ name="height"
+ step={2}
+ required
+ formatter={(h) => `${h}px`}
+ min={2}
+ status="ok"
+ max={100000000}
+ onValueChange={onHeightDirectlyChanged}
+ rightAlign={false}
+ />
+ {compHeightErrMessage ? (
+ <>
+ <Spacing y={1} block />
+ <ValidationMessage
+ align="flex-start"
+ message={compHeightErrMessage}
+ type="error"
+ />
+ </>
+ ) : null}
+ </div>
+ </div>
+ </>
+ ) : null}
+ {type === 'composition' && hadDurationDefined ? (
<NewCompDuration
durationInFrames={durationInFrames}
- fps={selectedFrameRate}
setDurationInFrames={setDurationInFrames}
/>
) : null}
- <div />
- <br />
- <div />
- {type === 'composition' ? (
- <div>
- <div />
- <label>
- <Row align="center">
- <div style={leftLabel}>Framerate</div>
- <div style={inputArea}>
- <InputDragger
- type="number"
- value={selectedFrameRate}
- onTextChange={onTextFpsChange}
- placeholder="Frame rate (fps)"
- name="fps"
- min={1}
- required
- status="ok"
- max={240}
- step={0.01}
- onValueChange={onFpsChange}
- rightAlign={false}
- />
- </div>
- </Row>
- </label>
+ {type === 'composition' && hadFpsDefined ? (
+ <div style={optionRow}>
+ <div style={label}>Framerate</div>
+ <div style={rightRow}>
+ <InputDragger
+ type="number"
+ value={selectedFrameRate}
+ onTextChange={onTextFpsChange}
+ placeholder="Frame rate (fps)"
+ name="fps"
+ min={1}
+ required
+ status="ok"
+ max={240}
+ step={0.01}
+ onValueChange={onFpsChange}
+ rightAlign={false}
+ />
+ </div>
</div>
) : null}
</div>
diff --git a/packages/studio/src/components/NewComposition/NewCompAspectRatio.tsx b/packages/studio/src/components/NewComposition/NewCompAspectRatio.tsx
deleted file mode 100644
index 974a09567e..0000000000
--- a/packages/studio/src/components/NewComposition/NewCompAspectRatio.tsx
+++ /dev/null
@@ -1,46 +0,0 @@
-import React from 'react';
-import {rightLabel} from './new-comp-layout';
-import {aspectRatio} from './render-aspect-ratio';
-import {ToggleAspectRatio} from './ToggleAspectRatio';
-
-const GUIDE_HEIGHT = 55;
-const GUIDE_WIDTH = 10;
-
-const container: React.CSSProperties = {
- display: 'flex',
- flexDirection: 'row',
- marginLeft: 10,
- alignItems: 'center',
-};
-
-export const NewCompAspectRatio: React.FC<{
- width: number;
- height: number;
- aspectRatioLocked: number | null;
- setAspectRatioLocked: (newOption: boolean) => void;
-}> = ({width, height, aspectRatioLocked, setAspectRatioLocked}) => {
- const pixels = Number(width) * Number(height);
- return (
- <div>
- <div style={container}>
- <svg width={GUIDE_WIDTH} height={GUIDE_HEIGHT}>
- <path
- d={`M 0 0 L ${GUIDE_WIDTH} 0 L ${GUIDE_WIDTH} ${GUIDE_HEIGHT} L 0 ${GUIDE_HEIGHT}`}
- fill="transparent"
- strokeWidth="2"
- stroke="rgba(255, 255, 255, 0.2)"
- />
- </svg>
- <ToggleAspectRatio
- aspectRatioLocked={Boolean(aspectRatioLocked)}
- setAspectRatioLocked={setAspectRatioLocked}
- />
- {pixels > 0 ? (
- <div style={rightLabel}>
- Aspect ratio {aspectRatio(Number(width), Number(height))}
- </div>
- ) : null}
- </div>
- </div>
- );
-};
diff --git a/packages/studio/src/components/NewComposition/NewCompDuration.tsx b/packages/studio/src/components/NewComposition/NewCompDuration.tsx
index 0b18b0c848..522675ec88 100644
--- a/packages/studio/src/components/NewComposition/NewCompDuration.tsx
+++ b/packages/studio/src/components/NewComposition/NewCompDuration.tsx
@@ -1,15 +1,14 @@
import React, {useCallback} from 'react';
import {validateCompositionDuration} from '../../helpers/validate-new-comp-data';
-import {Row, Spacing} from '../layout';
+import {Spacing} from '../layout';
+import {label, optionRow, rightRow} from '../RenderModal/layout';
import {InputDragger} from './InputDragger';
-import {inputArea, leftLabel, rightLabel} from './new-comp-layout';
import {ValidationMessage} from './ValidationMessage';
export const NewCompDuration: React.FC<{
durationInFrames: string;
- fps: string;
setDurationInFrames: React.Dispatch<React.SetStateAction<string>>;
-}> = ({durationInFrames, setDurationInFrames, fps}) => {
+}> = ({durationInFrames, setDurationInFrames}) => {
const onDurationInFramesChanged = useCallback(
(newValue: string) => {
setDurationInFrames(String(Number(newValue)));
@@ -27,42 +26,35 @@ export const NewCompDuration: React.FC<{
const compDurationErrMessage = validateCompositionDuration(durationInFrames);
return (
- <div>
- <label>
- <Row align="center">
- <div style={leftLabel}> Duration in frames</div>
- <div style={inputArea}>
- <InputDragger
- type="number"
- value={durationInFrames}
- onTextChange={onDurationInFramesChanged}
- placeholder="Duration (frames)"
- name="durationInFrames"
- min={1}
- step={1}
- required
- status="ok"
- // Hitting Promise.all() limit in Chrome
- max={300_000}
- onValueChange={onDurationChangedDirectly}
- rightAlign={false}
+ <div style={optionRow}>
+ <div style={label}>Duration in frames</div>
+ <div style={rightRow}>
+ <InputDragger
+ type="number"
+ value={durationInFrames}
+ onTextChange={onDurationInFramesChanged}
+ placeholder="Duration (frames)"
+ name="durationInFrames"
+ min={1}
+ step={1}
+ required
+ status="ok"
+ // Hitting Promise.all() limit in Chrome
+ max={300_000}
+ onValueChange={onDurationChangedDirectly}
+ rightAlign={false}
+ />
+ {compDurationErrMessage ? (
+ <>
+ <Spacing y={1} block />
+ <ValidationMessage
+ align="flex-start"
+ message={compDurationErrMessage}
+ type="error"
/>
- {compDurationErrMessage ? (
- <>
- <Spacing y={1} block />
- <ValidationMessage
- align="flex-start"
- message={compDurationErrMessage}
- type="error"
- />
- </>
- ) : null}
- </div>
- <span style={rightLabel}>
- {(Number(durationInFrames) / Number(fps)).toFixed(2)}sec
- </span>
- </Row>
- </label>
+ </>
+ ) : null}
+ </div>
</div>
);
};
diff --git a/packages/studio/src/components/NewComposition/ToggleAspectRatio.tsx b/packages/studio/src/components/NewComposition/ToggleAspectRatio.tsx
deleted file mode 100644
index d7fe56eaf0..0000000000
--- a/packages/studio/src/components/NewComposition/ToggleAspectRatio.tsx
+++ /dev/null
@@ -1,37 +0,0 @@
-import type {MouseEventHandler} from 'react';
-import React, {useCallback} from 'react';
-import {BACKGROUND} from '../../helpers/colors';
-import {LockIcon, UnlockIcon} from '../../icons/lock';
-
-const buttonStyle: React.CSSProperties = {
- backgroundColor: BACKGROUND,
- border: 'none',
- position: 'absolute',
- paddingLeft: 2,
- paddingRight: 2,
- marginLeft: 3,
-};
-
-const iconStyle: React.CSSProperties = {
- width: 10,
- color: 'white',
-};
-
-export const ToggleAspectRatio: React.FC<{
- aspectRatioLocked: boolean;
- setAspectRatioLocked: (option: boolean) => void;
-}> = ({aspectRatioLocked, setAspectRatioLocked}) => {
- const onClick: MouseEventHandler = useCallback(() => {
- setAspectRatioLocked(!aspectRatioLocked);
- }, [aspectRatioLocked, setAspectRatioLocked]);
-
- return (
- <button type="button" onClick={onClick} style={buttonStyle}>
- {aspectRatioLocked ? (
- <LockIcon style={iconStyle} />
- ) : (
- <UnlockIcon style={iconStyle} />
- )}
- </button>
- );
-};
diff --git a/packages/studio/src/components/NewComposition/new-comp-layout.ts b/packages/studio/src/components/NewComposition/new-comp-layout.ts
deleted file mode 100644
index 7d6d10e2ea..0000000000
--- a/packages/studio/src/components/NewComposition/new-comp-layout.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import type React from 'react';
-import {LIGHT_COLOR, LIGHT_TEXT} from '../../helpers/colors';
-
-export const leftLabel: React.CSSProperties = {
- width: 160,
- display: 'inline-block',
- textAlign: 'right',
- paddingRight: 30,
- fontSize: 14,
- color: LIGHT_COLOR,
-};
-
-export const inputArea: React.CSSProperties = {
- width: 190,
-};
-
-export const rightLabel: React.CSSProperties = {
- fontSize: 13,
- color: LIGHT_TEXT,
- marginLeft: 10,
-};
diff --git a/packages/studio/src/components/RenderModal/RenderModalOutputName.tsx b/packages/studio/src/components/RenderModal/RenderModalOutputName.tsx
index 0cc92445bc..f493175cf4 100644
--- a/packages/studio/src/components/RenderModal/RenderModalOutputName.tsx
+++ b/packages/studio/src/components/RenderModal/RenderModalOutputName.tsx
@@ -26,7 +26,6 @@ export const RenderModalOutputName = ({
<Column>
<div style={label}>{labelText}</div>
</Column>
-
<div style={rightRow}>
<div>
<RemotionInput
diff --git a/packages/studio/src/icons/lock.tsx b/packages/studio/src/icons/lock.tsx
deleted file mode 100644
index fedab09146..0000000000
--- a/packages/studio/src/icons/lock.tsx
+++ /dev/null
@@ -1,24 +0,0 @@
-import type {SVGProps} from 'react';
-import React from 'react';
-
-export const LockIcon: React.FC<SVGProps<SVGSVGElement>> = (props) => {
- return (
- <svg viewBox="0 0 448 512" {...props}>
- <path
- fill="currentColor"
- d="M400 224h-24v-72C376 68.2 307.8 0 224 0S72 68.2 72 152v72H48c-26.5 0-48 21.5-48 48v192c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V272c0-26.5-21.5-48-48-48zm-104 0H152v-72c0-39.7 32.3-72 72-72s72 32.3 72 72v72z"
- />
- </svg>
- );
-};
-
-export const UnlockIcon: React.FC<SVGProps<SVGSVGElement>> = (props) => {
- return (
- <svg viewBox="0 0 448 512" {...props}>
- <path
- fill="currentColor"
- d="M400 256H152V152.9c0-39.6 31.7-72.5 71.3-72.9 40-.4 72.7 32.1 72.7 72v16c0 13.3 10.7 24 24 24h32c13.3 0 24-10.7 24-24v-16C376 68 307.5-.3 223.5 0 139.5.3 72 69.5 72 153.5V256H48c-26.5 0-48 21.5-48 48v160c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V304c0-26.5-21.5-48-48-48z"
- />
- </svg>
- );
-};
diff --git a/packages/studio/src/state/aspect-ratio-locked.ts b/packages/studio/src/state/aspect-ratio-locked.ts
deleted file mode 100644
index 8c9eb43401..0000000000
--- a/packages/studio/src/state/aspect-ratio-locked.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-const aspectRatioLocalStorageKey = 'aspectRatio';
-
-export const persistAspectRatioOption = (option: boolean) => {
- localStorage.setItem(aspectRatioLocalStorageKey, String(option));
-};
-
-export const loadAspectRatioOption = () => {
- const item = localStorage.getItem(aspectRatioLocalStorageKey);
- if (item === null) {
- return true;
- }
-
- return item !== 'false';
-};