Skip to content

🎥 Make videos programmatically with React

turn into object

Jonny Burgerdadcd9dc352a
diff --git a/packages/core/src/Composition.tsx b/packages/core/src/Composition.tsx
index 82126eb1f9..ffcda2aab0 100644
--- a/packages/core/src/Composition.tsx
+++ b/packages/core/src/Composition.tsx
@@ -99,11 +99,11 @@ export const Composition = <T,>({
validateCompositionId(id);
validateDimension(width, 'width', 'of the <Composition/> component');
validateDimension(height, 'height', 'of the <Composition/> component');
- validateDurationInFrames(
+ validateDurationInFrames({
durationInFrames,
- 'of the <Composition/> component',
- false
- );
+ component: 'of the <Composition/> component',
+ allowFloats: false,
+ });
validateFps(fps, 'as a prop of the <Composition/> component', false);
registerComposition<T>({
diff --git a/packages/core/src/loop/index.tsx b/packages/core/src/loop/index.tsx
index da982d8ff1..103a03b8fd 100644
--- a/packages/core/src/loop/index.tsx
+++ b/packages/core/src/loop/index.tsx
@@ -25,7 +25,11 @@ export const Loop: React.FC<LoopProps> = ({
...props
}) => {
const {durationInFrames: compDuration} = useVideoConfig();
- validateDurationInFrames(durationInFrames, 'of the <Loop /> component', true);
+ validateDurationInFrames({
+ durationInFrames,
+ component: 'of the <Loop /> component',
+ allowFloats: true,
+ });
if (typeof times !== 'number') {
throw new TypeError(
diff --git a/packages/core/src/series/index.tsx b/packages/core/src/series/index.tsx
index 7746982287..c9d89eb7e4 100644
--- a/packages/core/src/series/index.tsx
+++ b/packages/core/src/series/index.tsx
@@ -81,11 +81,11 @@ const Series: FC<{
i !== flattenedChildren.length - 1 ||
durationInFramesProp !== Infinity
) {
- validateDurationInFrames(
- durationInFramesProp,
- `of a <Series.Sequence /> component`,
- true
- );
+ validateDurationInFrames({
+ durationInFrames: durationInFramesProp,
+ component: `of a <Series.Sequence /> component`,
+ allowFloats: true,
+ });
}
const offset = castedChild.props.offset ?? 0;
diff --git a/packages/core/src/validation/validate-duration-in-frames.ts b/packages/core/src/validation/validate-duration-in-frames.ts
index 00ce812279..4681df4e66 100644
--- a/packages/core/src/validation/validate-duration-in-frames.ts
+++ b/packages/core/src/validation/validate-duration-in-frames.ts
@@ -1,8 +1,12 @@
-export const validateDurationInFrames = (
- durationInFrames: number,
- component: string,
- allowFloats: boolean
-) => {
+export const validateDurationInFrames = ({
+ allowFloats,
+ component,
+ durationInFrames,
+}: {
+ durationInFrames: number;
+ component: string;
+ allowFloats: boolean;
+}) => {
if (typeof durationInFrames !== 'number') {
throw new Error(
`The "durationInFrames" prop ${component} must be a number, but you passed a value of type ${typeof durationInFrames}`
diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.ts
index b6b0ae1d01..8a3eb0e274 100644
--- a/packages/lambda/src/functions/launch.ts
+++ b/packages/lambda/src/functions/launch.ts
@@ -181,11 +181,11 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {
forceHeight: params.forceHeight,
forceWidth: params.forceWidth,
});
- Internals.validateDurationInFrames(
- comp.durationInFrames,
- 'passed to a Lambda render',
- false
- );
+ Internals.validateDurationInFrames({
+ durationInFrames: comp.durationInFrames,
+ component: 'passed to a Lambda render',
+ allowFloats: false,
+ });
Internals.validateFps(comp.fps, 'passed to a Lambda render', false);
Internals.validateDimension(
comp.height,
diff --git a/packages/player/src/Player.tsx b/packages/player/src/Player.tsx
index 888d82061c..2990992856 100644
--- a/packages/player/src/Player.tsx
+++ b/packages/player/src/Player.tsx
@@ -181,11 +181,11 @@ const PlayerFn = <T,>(
'compositionWidth',
'of the <Player /> component'
);
- Internals.validateDurationInFrames(
+ Internals.validateDurationInFrames({
durationInFrames,
- 'of the <Player/> component',
- false
- );
+ component: 'of the <Player/> component',
+ allowFloats: false,
+ });
Internals.validateFps(fps, 'as a prop of the <Player/> component', false);
validateInOutFrames({
diff --git a/packages/renderer/src/render-frames.ts b/packages/renderer/src/render-frames.ts
index 8672f06253..02592ef3af 100644
--- a/packages/renderer/src/render-frames.ts
+++ b/packages/renderer/src/render-frames.ts
@@ -528,11 +528,11 @@ export const renderFrames = (
'in the `config` object of `renderFrames()`',
false
);
- Internals.validateDurationInFrames(
- composition.durationInFrames,
- 'in the `config` object passed to `renderFrames()`',
- false
- );
+ Internals.validateDurationInFrames({
+ durationInFrames: composition.durationInFrames,
+ component: 'in the `config` object passed to `renderFrames()`',
+ allowFloats: false,
+ });
if (options.quality !== undefined && options.imageFormat !== 'jpeg') {
throw new Error(
"You can only pass the `quality` option if `imageFormat` is 'jpeg'."
diff --git a/packages/renderer/src/render-still.ts b/packages/renderer/src/render-still.ts
index 5010091b4c..446215e8a0 100644
--- a/packages/renderer/src/render-still.ts
+++ b/packages/renderer/src/render-still.ts
@@ -103,11 +103,11 @@ const innerRenderStill = async ({
'in the `config` object of `renderStill()`',
false
);
- Internals.validateDurationInFrames(
- composition.durationInFrames,
- 'in the `config` object passed to `renderStill()`',
- false
- );
+ Internals.validateDurationInFrames({
+ durationInFrames: composition.durationInFrames,
+ component: 'in the `config` object passed to `renderStill()`',
+ allowFloats: false,
+ });
validateNonNullImageFormat(imageFormat);
Internals.validateFrame(frame, composition.durationInFrames);
const stillFrame = convertToPositiveFrameIndex({