Skip to content

🎥 Make videos programmatically with React

move a component

Jonny Burger734d4630b458
diff --git a/packages/core/src/resolve-video-config.ts b/packages/core/src/resolve-video-config.ts
new file mode 100644
index 0000000000..7c1b88843a
--- /dev/null
+++ b/packages/core/src/resolve-video-config.ts
@@ -0,0 +1,48 @@
+import type {AnyComposition} from './CompositionManager.js';
+import type {VideoConfig} from './video-config.js';
+
+export const resolveVideoConfig = async (
+ comp: AnyComposition
+): Promise<VideoConfig> => {
+ const calculated = comp.calculateMetadata
+ ? await comp.calculateMetadata(comp.defaultProps)
+ : null;
+
+ const width = calculated?.width ?? comp.width ?? null;
+ if (!width) {
+ throw new TypeError(
+ 'Composition width was neither specified via the `width` prop nor the `calculateMetadata` function.'
+ );
+ }
+
+ const height = calculated?.height ?? comp.height ?? null;
+ if (!height) {
+ throw new TypeError(
+ 'Composition height was neither specified via the `height` prop nor the `calculateMetadata` function.'
+ );
+ }
+
+ const fps = calculated?.fps ?? comp.fps ?? null;
+ if (!fps) {
+ throw new TypeError(
+ 'Composition fps was neither specified via the `fps` prop nor the `calculateMetadata` function.'
+ );
+ }
+
+ const durationInFrames =
+ calculated?.durationInFrames ?? comp.durationInFrames ?? null;
+ if (!durationInFrames) {
+ throw new TypeError(
+ 'Composition durationInFrames was neither specified via the `durationInFrames` prop nor the `calculateMetadata` function.'
+ );
+ }
+
+ return {
+ width,
+ height,
+ fps,
+ durationInFrames,
+ id: comp.id,
+ defaultProps: comp.defaultProps,
+ };
+};
diff --git a/packages/core/src/use-unsafe-video-config.ts b/packages/core/src/use-unsafe-video-config.ts
index b35aa104cc..6bd44bc12c 100644
--- a/packages/core/src/use-unsafe-video-config.ts
+++ b/packages/core/src/use-unsafe-video-config.ts
@@ -1,5 +1,4 @@
import {useContext, useMemo} from 'react';
-import type {AnyComposition} from './CompositionManager.js';
import {SequenceContext} from './SequenceContext.js';
import {useVideo} from './use-video.js';
import type {VideoConfig} from './video-config.js';
@@ -26,49 +25,3 @@ export const useUnsafeVideoConfig = (): VideoConfig | null => {
};
}, [ctxDuration, video]);
};
-
-export const resolveVideoConfig = async (
- comp: AnyComposition
-): Promise<VideoConfig> => {
- const calculated = comp.calculateMetadata
- ? await comp.calculateMetadata(comp.defaultProps)
- : null;
-
- const width = calculated?.width ?? comp.width ?? null;
- if (!width) {
- throw new TypeError(
- 'Composition width was neither specified via the `width` prop nor the `calculateMetadata` function.'
- );
- }
-
- const height = calculated?.height ?? comp.height ?? null;
- if (!height) {
- throw new TypeError(
- 'Composition height was neither specified via the `height` prop nor the `calculateMetadata` function.'
- );
- }
-
- const fps = calculated?.fps ?? comp.fps ?? null;
- if (!fps) {
- throw new TypeError(
- 'Composition fps was neither specified via the `fps` prop nor the `calculateMetadata` function.'
- );
- }
-
- const durationInFrames =
- calculated?.durationInFrames ?? comp.durationInFrames ?? null;
- if (!durationInFrames) {
- throw new TypeError(
- 'Composition durationInFrames was neither specified via the `durationInFrames` prop nor the `calculateMetadata` function.'
- );
- }
-
- return {
- width,
- height,
- fps,
- durationInFrames,
- id: comp.id,
- defaultProps: comp.defaultProps,
- };
-};