Skip to content

🎥 Make videos programmatically with React

hmm maybe

Jonny Burger536a495eb7fb
diff --git a/packages/cli/.eslintrc b/packages/cli/.eslintrc
index feceda97f2..8e9d1e4c1d 100644
--- a/packages/cli/.eslintrc
+++ b/packages/cli/.eslintrc
@@ -16,6 +16,11 @@
"name": "zod",
"message": "Can only import zod as a type",
"allowTypeImports": true
+ },
+ {
+ "name": "@remotion/z-color",
+ "message": "Can only import @remotion/z-color as a type",
+ "allowTypeImports": true
}
]
}
diff --git a/packages/cli/src/color-math.ts b/packages/cli/src/color-math.ts
index 27154e5551..939fc78f93 100644
--- a/packages/cli/src/color-math.ts
+++ b/packages/cli/src/color-math.ts
@@ -1,7 +1,11 @@
-import {ZColorInternals} from '@remotion/z-color';
+import type {ZodColorType} from './editor/components/get-zod-if-possible';
-export const colorWithNewOpacity = (color: string, opacity: number) => {
- const {r, g, b} = ZColorInternals.parseColor(color);
+export const colorWithNewOpacity = (
+ color: string,
+ opacity: number,
+ zColor: ZodColorType
+) => {
+ const {r, g, b} = zColor.ZColorInternals.parseColor(color);
if (opacity >= 255) {
return `#${r.toString(16)}${g.toString(16)}${b.toString(16)}`;
}
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodColorEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodColorEditor.tsx
index 53416c9f1a..31a719767c 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodColorEditor.tsx
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodColorEditor.tsx
@@ -1,8 +1,10 @@
-import {ZColorInternals} from '@remotion/z-color';
import React, {useCallback, useMemo, useState} from 'react';
import type {z} from 'zod';
import {colorWithNewOpacity} from '../../../../color-math';
-import {useZodIfPossible} from '../../get-zod-if-possible';
+import {
+ useZodColorIfPossible,
+ useZodIfPossible,
+} from '../../get-zod-if-possible';
import {Row, Spacing} from '../../layout';
import {InputDragger} from '../../NewComposition/InputDragger';
import {RemotionInput} from '../../NewComposition/RemInput';
@@ -47,6 +49,11 @@ export const ZodColorEditor: React.FC<{
throw new Error('expected zod');
}
+ const zodColor = useZodColorIfPossible();
+ if (!zodColor) {
+ throw new Error('expected zod color');
+ }
+
const [localValue, setLocalValue] = useState<LocalState>(() => {
return {
value,
@@ -70,12 +77,16 @@ export const ZodColorEditor: React.FC<{
);
const {a, b, g, r} = localValue.zodValidation.success
- ? ZColorInternals.parseColor(localValue.value)
+ ? zodColor.ZColorInternals.parseColor(localValue.value)
: {a: 1, b: 0, g: 0, r: 0};
const onChange: React.ChangeEventHandler<HTMLInputElement> = useCallback(
(e) => {
- const newColor = colorWithNewOpacity(e.target.value, Math.round(a));
+ const newColor = colorWithNewOpacity(
+ e.target.value,
+ Math.round(a),
+ zodColor
+ );
const safeParse = schema.safeParse(newColor);
const newLocalState: LocalState = {
value: newColor,
@@ -86,7 +97,7 @@ export const ZodColorEditor: React.FC<{
setValue(newColor);
}
},
- [a, schema, setValue]
+ [a, schema, setValue, zodColor]
);
const onTextChange: React.ChangeEventHandler<HTMLInputElement> = useCallback(
@@ -131,7 +142,8 @@ export const ZodColorEditor: React.FC<{
(newValue: string) => {
const newColor = colorWithNewOpacity(
localValue.value,
- Math.round((Number(newValue) / 100) * 255)
+ Math.round((Number(newValue) / 100) * 255),
+ zodColor
);
const safeParse = schema.safeParse(newColor);
const newLocalState: LocalState = {
@@ -143,14 +155,15 @@ export const ZodColorEditor: React.FC<{
setValue(newColor);
}
},
- [localValue.value, schema, setValue]
+ [localValue.value, schema, setValue, zodColor]
);
const onOpacityValueChange = useCallback(
(newValue: number) => {
const newColor = colorWithNewOpacity(
localValue.value,
- Math.round((Number(newValue) / 100) * 255)
+ Math.round((Number(newValue) / 100) * 255),
+ zodColor
);
const safeParse = schema.safeParse(newColor);
@@ -163,7 +176,7 @@ export const ZodColorEditor: React.FC<{
setValue(newColor);
}
},
- [localValue.value, schema, setValue]
+ [localValue.value, schema, setValue, zodColor]
);
return (
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx
index 854177f917..4d60a3e95a 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodSwitch.tsx
@@ -1,13 +1,14 @@
-import {ZColorInternals} from '@remotion/z-color';
import React from 'react';
import type {z} from 'zod';
-import {useZodIfPossible} from '../../get-zod-if-possible';
+import {
+ useZodColorIfPossible,
+ useZodIfPossible,
+} from '../../get-zod-if-possible';
import type {JSONPath} from './zod-types';
import {ZodArrayEditor} from './ZodArrayEditor';
import {ZodBooleanEditor} from './ZodBooleanEditor';
import {ZodColorEditor} from './ZodColorEditor';
import {ZodDateEditor} from './ZodDateEditor';
-import {ZodEffectEditor} from './ZodEffectEditor';
import {ZodEnumEditor} from './ZodEnumEditor';
import {ZonNonEditableValue} from './ZodNonEditableValue';
import {ZodNullableEditor} from './ZodNullableEditor';
@@ -47,6 +48,8 @@ export const ZodSwitch: React.FC<{
throw new Error('expected zod');
}
+ const zodColor = useZodColorIfPossible();
+
// TODO: (Maybe?) enable saving of inserted input props by cmd+s /ctrl + s (also for JSON view)
if (typeName === z.ZodFirstPartyTypeKind.ZodObject) {
@@ -222,7 +225,10 @@ export const ZodSwitch: React.FC<{
}
if (typeName === z.ZodFirstPartyTypeKind.ZodEffects) {
- if (schema._def.description === ZColorInternals.REMOTION_COLOR_BRAND) {
+ if (
+ zodColor &&
+ schema._def.description === zodColor.ZColorInternals.REMOTION_COLOR_BRAND
+ ) {
return (
<ZodColorEditor
value={value as string}
@@ -237,20 +243,6 @@ export const ZodSwitch: React.FC<{
/>
);
}
-
- return (
- <ZodEffectEditor
- value={value}
- setValue={setValue}
- jsonPath={jsonPath}
- schema={schema}
- compact={compact}
- defaultValue={defaultValue}
- onSave={onSave}
- showSaveButton={showSaveButton}
- onRemove={onRemove}
- />
- );
}
if (typeName === z.ZodFirstPartyTypeKind.ZodUnion) {
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/create-zod-values.ts b/packages/cli/src/editor/components/RenderModal/SchemaEditor/create-zod-values.ts
index d54554b7f9..81652bb6d4 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/create-zod-values.ts
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/create-zod-values.ts
@@ -1,10 +1,10 @@
-import {ZColorInternals} from '@remotion/z-color';
import type {z} from 'zod';
-import type {ZodType} from '../../get-zod-if-possible';
+import type {ZodColorType, ZodType} from '../../get-zod-if-possible';
export const createZodValues = (
schema: Zod.ZodTypeAny,
- zodRuntime: ZodType
+ zodRuntime: ZodType,
+ zColorRuntime: ZodColorType | null
): unknown => {
if (!schema) {
throw new Error('Invalid zod schema');
@@ -44,26 +44,28 @@ export const createZodValues = (
const shape = (def as z.ZodObjectDef).shape();
const keys = Object.keys(shape);
const returnValue = keys.reduce((existing, key) => {
- existing[key] = createZodValues(shape[key], zodRuntime);
+ existing[key] = createZodValues(shape[key], zodRuntime, zColorRuntime);
return existing;
}, {} as Record<string, unknown>);
return returnValue;
}
case zodRuntime.ZodFirstPartyTypeKind.ZodArray: {
- return [createZodValues((def as z.ZodArrayDef).type, zodRuntime)];
+ return [
+ createZodValues((def as z.ZodArrayDef).type, zodRuntime, zColorRuntime),
+ ];
}
case zodRuntime.ZodFirstPartyTypeKind.ZodUnion: {
const firstOptions = (def as z.ZodUnionDef).options[0];
return firstOptions
- ? createZodValues(firstOptions, zodRuntime)
+ ? createZodValues(firstOptions, zodRuntime, zColorRuntime)
: undefined;
}
case zodRuntime.ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {
const options = (def as z.ZodDiscriminatedUnionDef<string>).options[0];
- return createZodValues(options, zodRuntime);
+ return createZodValues(options, zodRuntime, zColorRuntime);
}
case zodRuntime.ZodFirstPartyTypeKind.ZodLiteral: {
@@ -71,23 +73,31 @@ export const createZodValues = (
}
case zodRuntime.ZodFirstPartyTypeKind.ZodEffects: {
- if (schema._def.description === ZColorInternals.REMOTION_COLOR_BRAND) {
+ if (
+ zColorRuntime &&
+ schema._def.description ===
+ zColorRuntime.ZColorInternals.REMOTION_COLOR_BRAND
+ ) {
return '#ffffff';
}
- return createZodValues((def as z.ZodEffectsDef).schema, zodRuntime);
+ return createZodValues(
+ (def as z.ZodEffectsDef).schema,
+ zodRuntime,
+ zColorRuntime
+ );
}
case zodRuntime.ZodFirstPartyTypeKind.ZodIntersection: {
const {left, right} = def as z.ZodIntersectionDef;
- const leftValue = createZodValues(left, zodRuntime);
+ const leftValue = createZodValues(left, zodRuntime, zColorRuntime);
if (typeof leftValue !== 'object') {
throw new Error(
'Cannot create value for type z.intersection: Left side is not an object'
);
}
- const rightValue = createZodValues(right, zodRuntime);
+ const rightValue = createZodValues(right, zodRuntime, zColorRuntime);
if (typeof rightValue !== 'object') {
throw new Error(
@@ -100,7 +110,7 @@ export const createZodValues = (
case zodRuntime.ZodFirstPartyTypeKind.ZodTuple: {
const items = (def as z.ZodTupleDef).items.map((item) =>
- createZodValues(item, zodRuntime)
+ createZodValues(item, zodRuntime, zColorRuntime)
);
return items;
}
@@ -108,27 +118,36 @@ export const createZodValues = (
case zodRuntime.ZodFirstPartyTypeKind.ZodRecord: {
const values = createZodValues(
(def as z.ZodRecordDef).valueType,
- zodRuntime
+ zodRuntime,
+ zColorRuntime
);
return {key: values};
}
case zodRuntime.ZodFirstPartyTypeKind.ZodMap: {
const defType = def as z.ZodMapDef;
- const values = createZodValues(defType.valueType, zodRuntime);
- const key = createZodValues(defType.keyType, zodRuntime);
+ const values = createZodValues(
+ defType.valueType,
+ zodRuntime,
+ zColorRuntime
+ );
+ const key = createZodValues(defType.keyType, zodRuntime, zColorRuntime);
return new Map([[key, values]]);
}
case zodRuntime.ZodFirstPartyTypeKind.ZodLazy: {
const defType = def as z.ZodLazyDef;
const type = defType.getter();
- return createZodValues(type, zodRuntime);
+ return createZodValues(type, zodRuntime, zColorRuntime);
}
case zodRuntime.ZodFirstPartyTypeKind.ZodSet: {
const defType = def as z.ZodSetDef;
- const values = createZodValues(defType.valueType, zodRuntime);
+ const values = createZodValues(
+ defType.valueType,
+ zodRuntime,
+ zColorRuntime
+ );
return new Set([values]);
}
@@ -147,13 +166,21 @@ export const createZodValues = (
case zodRuntime.ZodFirstPartyTypeKind.ZodOptional: {
const defType = def as z.ZodOptionalDef;
- const value = createZodValues(defType.innerType, zodRuntime);
+ const value = createZodValues(
+ defType.innerType,
+ zodRuntime,
+ zColorRuntime
+ );
return value;
}
case zodRuntime.ZodFirstPartyTypeKind.ZodNullable: {
const defType = def as z.ZodNullableDef;
- const value = createZodValues(defType.innerType, zodRuntime);
+ const value = createZodValues(
+ defType.innerType,
+ zodRuntime,
+ zColorRuntime
+ );
return value;
}
@@ -164,27 +191,31 @@ export const createZodValues = (
case zodRuntime.ZodFirstPartyTypeKind.ZodCatch: {
const defType = def as z.ZodCatchDef;
- const value = createZodValues(defType.innerType, zodRuntime);
+ const value = createZodValues(
+ defType.innerType,
+ zodRuntime,
+ zColorRuntime
+ );
return value;
}
case zodRuntime.ZodFirstPartyTypeKind.ZodPromise: {
const defType = def as z.ZodPromiseDef;
- const value = createZodValues(defType.type, zodRuntime);
+ const value = createZodValues(defType.type, zodRuntime, zColorRuntime);
return Promise.resolve(value);
}
case zodRuntime.ZodFirstPartyTypeKind.ZodBranded: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const defType = def as z.ZodBrandedDef<any>;
- const value = createZodValues(defType.type, zodRuntime);
+ const value = createZodValues(defType.type, zodRuntime, zColorRuntime);
return value;
}
case zodRuntime.ZodFirstPartyTypeKind.ZodPipeline: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const defType = def as z.ZodPipelineDef<any, any>;
- const value = createZodValues(defType.out, zodRuntime);
+ const value = createZodValues(defType.out, zodRuntime, zColorRuntime);
return value;
}
diff --git a/packages/cli/src/editor/components/get-zod-if-possible.tsx b/packages/cli/src/editor/components/get-zod-if-possible.tsx
index 2d866855cf..0b328eee1a 100644
--- a/packages/cli/src/editor/components/get-zod-if-possible.tsx
+++ b/packages/cli/src/editor/components/get-zod-if-possible.tsx
@@ -11,7 +11,7 @@ export type ZodType = Awaited<typeof import('zod')>['z'];
export type ZodColorType = Awaited<
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
typeof import('@remotion/z-color')
->['zColor'];
+>;
export const getZodIfPossible = async (): Promise<ZodType | null> => {
try {
@@ -22,10 +22,10 @@ export const getZodIfPossible = async (): Promise<ZodType | null> => {
}
};
-const getZColorIfPossible = async (): Promise<ZodColorType | null> => {
+export const getZColorIfPossible = async (): Promise<ZodColorType | null> => {
try {
- const {zColor} = await import('@remotion/z-color');
- return zColor;
+ const mod = await import('@remotion/z-color');
+ return mod;
} catch (err) {
return null;
}
diff --git a/packages/cli/src/test/color-math.test.ts b/packages/cli/src/test/color-math.test.ts
index 5bef6ebca9..ceb9217363 100644
--- a/packages/cli/src/test/color-math.test.ts
+++ b/packages/cli/src/test/color-math.test.ts
@@ -1,8 +1,18 @@
-import {ZColorInternals} from '@remotion/z-color';
import {expect, test} from 'vitest';
+import {getZColorIfPossible} from '../editor/components/get-zod-if-possible';
-test('Color math', () => {
- expect(ZColorInternals.parseColor('rgba(255, 255, 255, 0.5)')).toEqual({
+const getZColor = async () => {
+ const z = await getZColorIfPossible();
+ if (!z) {
+ throw new Error('z-color not found');
+ }
+
+ return z;
+};
+
+test('Color math', async () => {
+ const mod = await getZColor();
+ expect(mod.ZColorInternals.parseColor('rgba(255, 255, 255, 0.5)')).toEqual({
a: 128,
r: 255,
b: 255,
diff --git a/packages/cli/src/test/create-zod-values.test.ts b/packages/cli/src/test/create-zod-values.test.ts
index e6fc943caf..5d871854ab 100644
--- a/packages/cli/src/test/create-zod-values.test.ts
+++ b/packages/cli/src/test/create-zod-values.test.ts
@@ -1,6 +1,8 @@
-import {zColor} from '@remotion/z-color';
import {expect, test} from 'vitest';
-import {getZodIfPossible} from '../editor/components/get-zod-if-possible';
+import {
+ getZColorIfPossible,
+ getZodIfPossible,
+} from '../editor/components/get-zod-if-possible';
import {createZodValues} from '../editor/components/RenderModal/SchemaEditor/create-zod-values';
const getZ = async () => {
@@ -12,57 +14,76 @@ const getZ = async () => {
return z;
};
+const getZColor = async () => {
+ const z = await getZColorIfPossible();
+ if (!z) {
+ throw new Error('z-color not found');
+ }
+
+ return z;
+};
+
test('Should be able to create a string', async () => {
const z = await getZ();
+ const zColor = await getZColor();
- const hi = createZodValues(z.string(), z);
+ const hi = createZodValues(z.string(), z, zColor);
expect(hi).toBe('');
});
test('Should be able to create a number', async () => {
const z = await getZ();
+ const zColor = await getZColor();
- const hi = createZodValues(z.number(), z);
+ const hi = createZodValues(z.number(), z, zColor);
expect(hi).toBe(0);
});
test('Should be able to create an object', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const hi = createZodValues(
z.object({
a: z.string(),
b: z.number(),
}),
- z
+ z,
+ zColor
);
expect(hi).toEqual({a: '', b: 0});
});
test('Should be able to create an array', async () => {
const z = await getZ();
+ const zColor = await getZColor();
- expect(createZodValues(z.array(z.string()), z)).toEqual(['']);
- expect(createZodValues(z.array(z.number()), z)).toEqual([0]);
+ expect(createZodValues(z.array(z.string()), z, zColor)).toEqual(['']);
+ expect(createZodValues(z.array(z.number()), z, zColor)).toEqual([0]);
});
test('Should be able to create a union', async () => {
const z = await getZ();
+ const zColor = await getZColor();
- expect(createZodValues(z.union([z.string(), z.number()]), z)).toBe('');
- expect(createZodValues(z.union([z.number(), z.string()]), z)).toBe(0);
+ expect(createZodValues(z.union([z.string(), z.number()]), z, zColor)).toBe(
+ ''
+ );
+ expect(createZodValues(z.union([z.number(), z.string()]), z, zColor)).toBe(0);
// @ts-expect-error union
- expect(createZodValues(z.union([]), z)).toBe(undefined);
+ expect(createZodValues(z.union([]), z, zColor)).toBe(undefined);
});
test('Zod literal', async () => {
const z = await getZ();
+ const zColor = await getZColor();
- expect(createZodValues(z.literal('hi'), z)).toBe('hi');
+ expect(createZodValues(z.literal('hi'), z, zColor)).toBe('hi');
});
test('Should be able to create a discriminated union', async () => {
const z = await getZ();
+ const zColor = await getZColor();
expect(
createZodValues(
@@ -70,7 +91,8 @@ test('Should be able to create a discriminated union', async () => {
z.object({status: z.literal('success'), data: z.string()}),
z.object({status: z.literal('failed'), error: z.instanceof(Error)}),
]),
- z
+ z,
+ zColor
)
).toEqual({status: 'success', data: ''});
@@ -80,26 +102,29 @@ test('Should be able to create a discriminated union', async () => {
z.object({status: z.literal('failed'), error: z.number()}),
z.object({status: z.literal('success'), data: z.string()}),
]),
- z
+ z,
+ zColor
)
).toEqual({status: 'failed', error: 0});
- // @ts-expect-error invalid zod type
- expect(() => createZodValues(z.discriminatedUnion('status', []), z)).toThrow(
- /Invalid zod schema/
- );
+ expect(() =>
+ // @ts-expect-error invalid zod type
+ createZodValues(z.discriminatedUnion('status', []), z, zColor)
+ ).toThrow(/Invalid zod schema/);
});
test('Zod instanceof', async () => {
const z = await getZ();
+ const zColor = await getZColor();
- expect(() => createZodValues(z.instanceof(Error), z)).toThrow(
+ expect(() => createZodValues(z.instanceof(Error), z, zColor)).toThrow(
/Cannot create a value for type z.any()/
);
});
test('Zod intersection', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const Person = z.object({
name: z.string(),
@@ -110,7 +135,7 @@ test('Zod intersection', async () => {
});
const EmployedPerson = z.intersection(Person, Employee);
- expect(createZodValues(EmployedPerson, z)).toEqual({
+ expect(createZodValues(EmployedPerson, z, zColor)).toEqual({
name: '',
role: '',
});
@@ -118,159 +143,180 @@ test('Zod intersection', async () => {
test('Zod tuples', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const Tuple = z.tuple([z.string(), z.number()]);
- expect(createZodValues(Tuple, z)).toEqual(['', 0]);
+ expect(createZodValues(Tuple, z, zColor)).toEqual(['', 0]);
});
test('Zod record', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const Record = z.record(z.string());
- expect(createZodValues(Record, z)).toEqual({key: ''});
+ expect(createZodValues(Record, z, zColor)).toEqual({key: ''});
});
test('Zod map', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const map = z.map(z.string(), z.number());
- expect(createZodValues(map, z)).toEqual(new Map([['', 0]]));
+ expect(createZodValues(map, z, zColor)).toEqual(new Map([['', 0]]));
});
test('Zod lazy', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const Lazy = z.lazy(() => z.string());
- expect(createZodValues(Lazy, z)).toBe('');
+ expect(createZodValues(Lazy, z, zColor)).toBe('');
});
test('Zod set', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const set = z.set(z.string());
- expect(createZodValues(set, z)).toEqual(new Set(['']));
+ expect(createZodValues(set, z, zColor)).toEqual(new Set(['']));
const set2 = z.set(z.number());
- expect(createZodValues(set2, z)).toEqual(new Set([0]));
+ expect(createZodValues(set2, z, zColor)).toEqual(new Set([0]));
});
test('Zod function', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const fn = z.function();
- expect(() => createZodValues(fn, z)).toThrow(
+ expect(() => createZodValues(fn, z, zColor)).toThrow(
/Cannot create a value for type function/
);
});
test('Zod undefined', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const undef = z.void();
- expect(createZodValues(undef, z)).toBe(undefined);
+ expect(createZodValues(undef, z, zColor)).toBe(undefined);
});
test('Zod null', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const undef = z.null();
- expect(createZodValues(undef, z)).toBe(null);
+ expect(createZodValues(undef, z, zColor)).toBe(null);
});
test('Zod enum', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const Enum = z.enum(['a', 'b']);
- expect(createZodValues(Enum, z)).toBe('a');
+ expect(createZodValues(Enum, z, zColor)).toBe('a');
});
test('Zod nativeEnum', async () => {
const z = await getZ();
+ const zColor = await getZColor();
enum Fruits {
Apple,
Banana,
}
const Enum = z.nativeEnum(Fruits);
- expect(createZodValues(Enum, z)).toBe(Fruits.Apple);
+ expect(createZodValues(Enum, z, zColor)).toBe(Fruits.Apple);
});
test('Zod optional', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const Optional = z.string().optional();
- expect(createZodValues(Optional, z)).toBe('');
+ expect(createZodValues(Optional, z, zColor)).toBe('');
});
test('Zod nullable', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const Nullable = z.string().nullable();
- expect(createZodValues(Nullable, z)).toBe('');
+ expect(createZodValues(Nullable, z, zColor)).toBe('');
});
test('Zod undefined', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const undef = z.string().default('tuna');
- expect(createZodValues(undef, z)).toBe('tuna');
+ expect(createZodValues(undef, z, zColor)).toBe('tuna');
});
test('Zod catch', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const undef = z.string().catch('tuna');
- expect(createZodValues(undef, z)).toBe('');
+ expect(createZodValues(undef, z, zColor)).toBe('');
});
test('Zod promise', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const undef = z.string().promise();
- (createZodValues(undef, z) as Promise<unknown>).then((v) => {
+ (createZodValues(undef, z, zColor) as Promise<unknown>).then((v) => {
expect(v).toBe('');
});
});
test('Zod transform', async () => {
const z = await getZ();
+ const zColor = await getZColor();
// Intentional: We don't parse the Zod values, so we should not transform them
const undef = z.literal('abc').transform((v) => v.toUpperCase());
- expect(createZodValues(undef, z)).toBe('abc');
+ expect(createZodValues(undef, z, zColor)).toBe('abc');
});
test('Zod branded', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const Cat = z.object({name: z.string()}).brand<'Cat'>();
- expect(createZodValues(Cat, z)).toEqual({name: ''});
+ expect(createZodValues(Cat, z, zColor)).toEqual({name: ''});
});
test('Zod lazy', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const datelike = z.union([z.number(), z.string(), z.date()]);
const datelikeToDate = datelike.pipe(z.coerce.date());
- expect(createZodValues(datelikeToDate, z)).toBeInstanceOf(Date);
+ expect(createZodValues(datelikeToDate, z, zColor)).toBeInstanceOf(Date);
});
test('Zod coerce', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const datelike = z.union([z.number(), z.string(), z.date()]);
const datelikeToDate = datelike.pipe(z.coerce.date());
- expect(createZodValues(datelikeToDate, z)).toBeInstanceOf(Date);
+ expect(createZodValues(datelikeToDate, z, zColor)).toBeInstanceOf(Date);
});
test('Zod strict', async () => {
const z = await getZ();
+ const zColor = await getZColor();
const strict = z.strictObject({a: z.string()}).strict();
- expect(createZodValues(strict, z)).toEqual({a: ''});
+ expect(createZodValues(strict, z, zColor)).toEqual({a: ''});
});
test('Should create a color', async () => {
const z = await getZ();
+ const zColor = await getZColor();
- expect(createZodValues(zColor(), z)).toBe('#ffffff');
+ expect(createZodValues(zColor.zColor(), z, zColor)).toBe('#ffffff');
});
diff --git a/packages/example-without-zod/package.json b/packages/example-without-zod/package.json
index eaaba3af04..b808afb156 100644
--- a/packages/example-without-zod/package.json
+++ b/packages/example-without-zod/package.json
@@ -13,6 +13,7 @@
},
"dependencies": {
"remotion": "workspace:*",
+ "@remotion/cli": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "^4.7.0"
diff --git a/packages/example-without-zod/remotion.config.ts b/packages/example-without-zod/remotion.config.ts
new file mode 100644
index 0000000000..76212ca732
--- /dev/null
+++ b/packages/example-without-zod/remotion.config.ts
@@ -0,0 +1,15 @@
+import { Config } from "@remotion/cli/config";
+
+Config.overrideWebpackConfig((config) => {
+ return {
+ ...config,
+ resolve: {
+ ...config.resolve,
+ alias: {
+ ...config.resolve?.alias,
+ zod: "undefined.js",
+ "@remotion/z-color": "undefined.js",
+ },
+ },
+ };
+});
diff --git a/packages/example-without-zod/src/MyComposition.tsx b/packages/example-without-zod/src/MyComposition.tsx
new file mode 100644
index 0000000000..90c3114108
--- /dev/null
+++ b/packages/example-without-zod/src/MyComposition.tsx
@@ -0,0 +1,3 @@
+export const MyComposition = () => {
+ return null;
+};
diff --git a/packages/example-without-zod/src/Root.tsx b/packages/example-without-zod/src/Root.tsx
new file mode 100644
index 0000000000..c54089872f
--- /dev/null
+++ b/packages/example-without-zod/src/Root.tsx
@@ -0,0 +1,18 @@
+import React from "react";
+import { Composition } from "remotion";
+import { MyComposition } from "./MyComposition";
+
+export const Root: React.FC = () => {
+ return (
+ <>
+ <Composition
+ id="MyComposition"
+ component={MyComposition}
+ fps={30}
+ height={1080}
+ width={1080}
+ durationInFrames={60}
+ />
+ </>
+ );
+};
diff --git a/packages/example-without-zod/src/index.ts b/packages/example-without-zod/src/index.ts
new file mode 100644
index 0000000000..e78af8ba34
--- /dev/null
+++ b/packages/example-without-zod/src/index.ts
@@ -0,0 +1,4 @@
+import { registerRoot } from "remotion";
+import { Root } from "./Root";
+
+registerRoot(Root);
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index fc86cd4008..e7379042af 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -596,6 +596,7 @@ importers:
packages/example-without-zod:
specifiers:
+ '@remotion/cli': workspace:*
'@types/react': ^18.0.38
'@types/react-dom': ^18.0.11
react: ^18.2.0
@@ -603,6 +604,7 @@ importers:
remotion: workspace:*
typescript: ^4.7.0
dependencies:
+ '@remotion/cli': link:../cli
react: 18.2.0
react-dom: [email protected]
remotion: link:../core