🎥 Make videos programmatically with React
validate format of imageFormat
Jonny Burgerb9fc2ea7281b
diff --git a/packages/core/src/validation/validate-offthreadvideo-image-format.ts b/packages/core/src/validation/validate-offthreadvideo-image-format.tsnew file mode 100644index 0000000000..a4aa3fc8b8--- /dev/null+++ b/packages/core/src/validation/validate-offthreadvideo-image-format.ts@@ -0,0 +1,19 @@+export const validateOffthreadVideoImageFormat = (input: unknown) => {+ if (typeof input === 'undefined') {+ return;+ }++ if (typeof input !== 'string') {+ throw new TypeError(+ `<OffthreadVideo imageFormat=""> must be a string, but got ${JSON.stringify(+ input+ )} instead.`+ );+ }++ if (input !== 'png' && input !== 'jpeg') {+ throw new TypeError(+ `<OffthreadVideo imageFormat=""> must be either "png" or "jpeg", but got ${input}`+ );+ }+};diff --git a/packages/core/src/video/OffthreadVideo.tsx b/packages/core/src/video/OffthreadVideo.tsxindex d723bbb095..fa8314e7ff 100644--- a/packages/core/src/video/OffthreadVideo.tsx+++ b/packages/core/src/video/OffthreadVideo.tsx@@ -3,12 +3,11 @@ import {getRemotionEnvironment} from '../get-environment';import {Sequence} from '../Sequence';import {validateMediaProps} from '../validate-media-props';import {validateStartFromProps} from '../validate-start-from-props';+import {validateOffthreadVideoImageFormat} from '../validation/validate-offthreadvideo-image-format';import {OffthreadVideoForRendering} from './OffthreadVideoForRendering';import {OffthreadVideoProps, RemotionMainVideoProps} from './props';import {VideoForDevelopment} from './VideoForDevelopment';-export type OffthreadVideoImageFormat = 'png' | 'jpeg';-export const OffthreadVideo: React.FC<OffthreadVideoProps & RemotionMainVideoProps> = (props) => {@@ -32,6 +31,7 @@ export const OffthreadVideo: React.FC<}validateMediaProps(props, 'Video');+ validateOffthreadVideoImageFormat(props.imageFormat);if (getRemotionEnvironment() === 'rendering') {return <OffthreadVideoForRendering {...otherProps} />;diff --git a/packages/core/src/video/index.ts b/packages/core/src/video/index.tsindex fcbda2bcf1..fc3d489030 100644--- a/packages/core/src/video/index.ts+++ b/packages/core/src/video/index.ts@@ -1,5 +1,6 @@-export {OffthreadVideo, OffthreadVideoImageFormat} from './OffthreadVideo';+export {OffthreadVideo} from './OffthreadVideo';export {+ OffthreadVideoImageFormat,OffthreadVideoProps as RemotionOffthreadVideoProps,RemotionMainVideoProps,RemotionVideoProps,diff --git a/packages/core/src/video/props.ts b/packages/core/src/video/props.tsindex a5040700aa..dc4b2e6497 100644--- a/packages/core/src/video/props.ts+++ b/packages/core/src/video/props.ts@@ -17,6 +17,8 @@ export type RemotionVideoProps = Omit<playbackRate?: number;};+export type OffthreadVideoImageFormat = 'png' | 'jpeg';+export type OffthreadVideoProps = {src: string;className?: string;@@ -25,4 +27,5 @@ export type OffthreadVideoProps = {playbackRate?: number;muted?: boolean;onError?: React.ReactEventHandler<HTMLVideoElement | HTMLImageElement>;+ imageFormat?: OffthreadVideoImageFormat;};