37 lines
1.7 KiB
TypeScript
37 lines
1.7 KiB
TypeScript
import type { ComponentType } from 'react';
|
|
import type { CalculateMetadataFunction } from 'remotion';
|
|
import type { AnyZodObject, z } from 'zod';
|
|
export type InferProps<Schema extends AnyZodObject, Props extends Record<string, unknown>> = AnyZodObject extends Schema ? {} extends Props ? Record<string, unknown> : Props : {} extends Props ? z.input<Schema> : z.input<Schema> & Props;
|
|
export type DefaultPropsIfHasProps<Schema extends AnyZodObject, Props> = AnyZodObject extends Schema ? {} extends Props ? {
|
|
defaultProps?: z.input<Schema> & Props;
|
|
} : {
|
|
defaultProps: Props;
|
|
} : {} extends Props ? {
|
|
defaultProps: z.input<Schema>;
|
|
} : {
|
|
defaultProps: z.input<Schema> & Props;
|
|
};
|
|
type LooseComponentType<T> = ComponentType<T> | ((props: T) => React.ReactNode);
|
|
type OptionalDimensions<Schema extends AnyZodObject, Props extends Record<string, unknown>> = {
|
|
component: LooseComponentType<Props>;
|
|
id: string;
|
|
width?: number;
|
|
height?: number;
|
|
calculateMetadata: CalculateMetadataFunction<InferProps<Schema, Props>>;
|
|
};
|
|
type MandatoryDimensions<Schema extends AnyZodObject, Props extends Record<string, unknown>> = {
|
|
component: LooseComponentType<Props>;
|
|
id: string;
|
|
width: number;
|
|
height: number;
|
|
calculateMetadata?: CalculateMetadataFunction<InferProps<Schema, Props>> | null;
|
|
};
|
|
export type CompositionCalculateMetadataOrExplicit<Schema extends AnyZodObject, Props extends Record<string, unknown>> = ((OptionalDimensions<Schema, Props> & {
|
|
fps?: number;
|
|
durationInFrames?: number;
|
|
}) | (MandatoryDimensions<Schema, Props> & {
|
|
fps: number;
|
|
durationInFrames: number;
|
|
})) & DefaultPropsIfHasProps<Schema, Props>;
|
|
export {};
|