Skip to content

🎥 Make videos programmatically with React

v3

Jonny Burger44ee64d7fc74
diff --git a/bun.lock b/bun.lock
index ec3f0c6462..4424cc23c8 100644
--- a/bun.lock
+++ b/bun.lock
@@ -1163,6 +1163,8 @@
"name": "@remotion/react18-tests",
"version": "4.0.423",
"dependencies": {
+ "@remotion/zod-types": "workspace:*",
+ "@remotion/zod-types-v3": "workspace:*",
"remotion": "workspace:*",
"zod": "3.22.3",
},
@@ -2349,6 +2351,23 @@
"zod": "catalog:",
},
},
+ "packages/zod-types-v3": {
+ "name": "@remotion/zod-types-v3",
+ "version": "4.0.423",
+ "dependencies": {
+ "@remotion/zod-types": "workspace:*",
+ "remotion": "workspace:*",
+ },
+ "devDependencies": {
+ "@remotion/eslint-config-internal": "workspace:*",
+ "@typescript/native-preview": "catalog:",
+ "eslint": "catalog:",
+ "zod": "3.22.3",
+ },
+ "peerDependencies": {
+ "zod": ">=3.0.0 <4.0.0",
+ },
+ },
},
"overrides": {
"@rspack/core": "1.7.6",
@@ -3752,6 +3771,8 @@
"@remotion/zod-types": ["@remotion/zod-types@workspace:packages/zod-types"],
+ "@remotion/zod-types-v3": ["@remotion/zod-types-v3@workspace:packages/zod-types-v3"],
+
"@rive-app/canvas-advanced": ["@rive-app/[email protected]", "", {}, "sha512-zwqLIc5wRF+zFKgDSTJn21+r4N4KWqAe6iVrjDGFzfxxeKDoESrwK7GQ9qVyS6UH2W4SsDRzO6q6jrlw33+yIg=="],
"@rollup/pluginutils": ["@rollup/[email protected]", "", { "dependencies": { "@types/estree": "1.0.7", "estree-walker": "2.0.2", "picomatch": "4.0.2" } }, "sha512-qWJ2ZTbmumwiLFomfzTyt5Kng4hwPi9rwCYN4SHb6eaRU1KNO4ccxINHr/VhH4GgPlt1XfSTLX2LBTme8ne4Zw=="],
@@ -8906,6 +8927,8 @@
"@remotion/tailwind-v4/tailwindcss": ["[email protected]", "", {}, "sha512-QNbdmeS979Efzim2g/bEvfuh+fTcIdp1y7gA+sb6OYSW74rt7Cr7M78AKdf6HqWT3d5AiTb7SwTT3sLQxr4/qw=="],
+ "@remotion/zod-types-v3/zod": ["[email protected]", "", {}, "sha512-EjIevzuJRiRPbVH4mGc8nApb/lVLKVpmUhAaR5R5doKGfAnGJ6Gr3CViAVjP+4FWSxCsybeWQdcgCtbX+7oZug=="],
+
"@rollup/pluginutils/estree-walker": ["[email protected]", "", {}, "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w=="],
"@shopify/react-native-skia/react": ["[email protected]", "", {}, "sha512-V8AVnmPIICiWpGfm6GLzCR/W5FXLchHop40W4nXBmdlEceh16rCN8O8LNWm5bh5XUX91fh7KpA+W0TgMKmgTpQ=="],
diff --git a/packages/cli/src/list-of-remotion-packages.ts b/packages/cli/src/list-of-remotion-packages.ts
index 2402bce383..2320889e1c 100644
--- a/packages/cli/src/list-of-remotion-packages.ts
+++ b/packages/cli/src/list-of-remotion-packages.ts
@@ -72,6 +72,7 @@ export const listOfRemotionPackages = [
'@remotion/transitions',
'@remotion/media-parser',
'@remotion/zod-types',
+ '@remotion/zod-types-v3',
'@remotion/webcodecs',
'@remotion/convert',
'@remotion/captions',
diff --git a/packages/create-video/src/list-of-remotion-packages.ts b/packages/create-video/src/list-of-remotion-packages.ts
index 2402bce383..2320889e1c 100644
--- a/packages/create-video/src/list-of-remotion-packages.ts
+++ b/packages/create-video/src/list-of-remotion-packages.ts
@@ -72,6 +72,7 @@ export const listOfRemotionPackages = [
'@remotion/transitions',
'@remotion/media-parser',
'@remotion/zod-types',
+ '@remotion/zod-types-v3',
'@remotion/webcodecs',
'@remotion/convert',
'@remotion/captions',
diff --git a/packages/example/src/VisualControls/index.tsx b/packages/example/src/VisualControls/index.tsx
index 0ea71d943a..3f17a64130 100644
--- a/packages/example/src/VisualControls/index.tsx
+++ b/packages/example/src/VisualControls/index.tsx
@@ -6,7 +6,7 @@ import {AbsoluteFill} from 'remotion';
export const VisualControls = () => {
const matrix = visualControl(
'my-matrix',
- [9.63, 0.83, 1.3, 0, 0, 2.79, 0, 0, 1.26, 0.35, 1, 0, 0, 0, 0, 1] as const,
+ [11.77,1.49,1.3,0,0,2.79,0,0,1.26,0.35,1,0,0,0,0,1] as const,
zMatrix(),
);
diff --git a/packages/react18-tests/package.json b/packages/react18-tests/package.json
index 5f811e64c5..34fe1fe128 100644
--- a/packages/react18-tests/package.json
+++ b/packages/react18-tests/package.json
@@ -17,7 +17,9 @@
"license": "UNLICENSED",
"dependencies": {
"remotion": "workspace:*",
- "zod": "3.22.3"
+ "zod": "3.22.3",
+ "@remotion/zod-types": "workspace:*",
+ "@remotion/zod-types-v3": "workspace:*"
},
"devDependencies": {
"@remotion/eslint-config-internal": "workspace:*",
diff --git a/packages/react18-tests/src/test/Root.tsx b/packages/react18-tests/src/test/Root.tsx
index 3cc28e0964..127b4ef749 100644
--- a/packages/react18-tests/src/test/Root.tsx
+++ b/packages/react18-tests/src/test/Root.tsx
@@ -42,7 +42,7 @@ export const Root: React.FC = () => {
defaultProps={{
title: 'Hello from Zod v3!',
count: 10,
- enabled: true,
+ enabled: [1, 0, 0, 1],
tags: ['react18', 'zod-v3'],
level: 'beginner' as const,
}}
diff --git a/packages/react18-tests/src/test/ZodV3SchemaTest.tsx b/packages/react18-tests/src/test/ZodV3SchemaTest.tsx
index f652ac4b2d..18a627cb92 100644
--- a/packages/react18-tests/src/test/ZodV3SchemaTest.tsx
+++ b/packages/react18-tests/src/test/ZodV3SchemaTest.tsx
@@ -2,13 +2,14 @@
* Test composition using zod v3 schema (via zod/v3 import).
* Verifies that the studio schema editor works with zod v3 schemas.
*/
+import {zMatrix} from '@remotion/zod-types-v3';
import React from 'react';
import {z} from 'zod';
export const zodV3Schema = z.object({
title: z.string(),
count: z.number().min(0).max(100),
- enabled: z.boolean(),
+ enabled: zMatrix(),
tags: z.array(z.string()),
level: z.enum(['beginner', 'intermediate', 'advanced']),
});
diff --git a/packages/studio-shared/src/package-info.ts b/packages/studio-shared/src/package-info.ts
index 3725ef5e34..7ce2637fc4 100644
--- a/packages/studio-shared/src/package-info.ts
+++ b/packages/studio-shared/src/package-info.ts
@@ -71,6 +71,7 @@ export const packages = [
'transitions',
'media-parser',
'zod-types',
+ 'zod-types-v3',
'webcodecs',
'convert',
'captions',
@@ -127,6 +128,7 @@ export const descriptions: {[key in Pkgs]: string | null} = {
preload: 'Preloads assets for use in Remotion',
shapes: 'Generate SVG shapes',
'zod-types': 'Zod types for Remotion',
+ 'zod-types-v3': 'Zod v3 types for Remotion',
gif: 'Embed GIFs in a Remotion video',
'eslint-plugin': 'Rules for writing Remotion code',
'eslint-config': 'Default configuration for Remotion templates (ESLint <= 8)',
@@ -266,6 +268,7 @@ export const installableMap: {[key in Pkgs]: boolean} = {
transitions: true,
'media-parser': true,
'zod-types': true,
+ 'zod-types-v3': true,
webcodecs: true,
convert: false,
captions: true,
@@ -303,6 +306,7 @@ export const apiDocs: {[key in Pkgs]: string | null} = {
preload: 'https://www.remotion.dev/docs/preload',
shapes: 'https://www.remotion.dev/docs/shapes',
'zod-types': 'https://www.remotion.dev/docs/zod-types',
+ 'zod-types-v3': 'https://www.remotion.dev/docs/zod-types',
gif: 'https://www.remotion.dev/docs/gif',
'eslint-plugin':
'https://www.remotion.dev/docs/brownfield#install-the-eslint-plugin',
diff --git a/packages/studio/src/components/RenderModal/SchemaEditor/ZodSwitch.tsx b/packages/studio/src/components/RenderModal/SchemaEditor/ZodSwitch.tsx
index 2055f27675..b4f2ff03a8 100644
--- a/packages/studio/src/components/RenderModal/SchemaEditor/ZodSwitch.tsx
+++ b/packages/studio/src/components/RenderModal/SchemaEditor/ZodSwitch.tsx
@@ -80,6 +80,28 @@ export const ZodSwitch: React.FC<{
}
if (typeName === 'string') {
+ // In v4, .refine() doesn't wrap in ZodEffects, so check brand here too
+ if (
+ zodTypes &&
+ description === zodTypes.ZodZypesInternals.REMOTION_COLOR_BRAND
+ ) {
+ return (
+ <ZodColorEditor
+ value={value as string}
+ setValue={setValue as UpdaterFunction<string>}
+ jsonPath={jsonPath}
+ schema={schema}
+ onSave={onSave as UpdaterFunction<string>}
+ defaultValue={defaultValue as string}
+ showSaveButton={showSaveButton}
+ onRemove={onRemove}
+ saving={saving}
+ saveDisabledByParent={saveDisabledByParent}
+ mayPad={mayPad}
+ />
+ );
+ }
+
if ((value as string).startsWith(window.remotion_staticBase)) {
return (
<ZodStaticFileEditor
@@ -251,6 +273,28 @@ export const ZodSwitch: React.FC<{
}
if (typeName === 'array') {
+ // In v4, .refine() doesn't wrap in ZodEffects, so check brand here too
+ if (
+ zodTypes &&
+ description === zodTypes.ZodZypesInternals.REMOTION_MATRIX_BRAND
+ ) {
+ return (
+ <ZodMatrixEditor
+ setValue={setValue as UpdaterFunction<unknown[]>}
+ value={value as unknown[]}
+ jsonPath={jsonPath}
+ schema={schema}
+ defaultValue={defaultValue as unknown[]}
+ onSave={onSave as UpdaterFunction<unknown[]>}
+ showSaveButton={showSaveButton}
+ onRemove={onRemove}
+ saving={saving}
+ saveDisabledByParent={saveDisabledByParent}
+ mayPad={mayPad}
+ />
+ );
+ }
+
return (
<ZodArrayEditor
setValue={setValue as UpdaterFunction<unknown[]>}
diff --git a/packages/studio/src/visual-controls/VisualControls.tsx b/packages/studio/src/visual-controls/VisualControls.tsx
index 519bdfd707..6eb2f5ed85 100644
--- a/packages/studio/src/visual-controls/VisualControls.tsx
+++ b/packages/studio/src/visual-controls/VisualControls.tsx
@@ -9,14 +9,14 @@ import React, {
useState,
} from 'react';
import {useRemotionEnvironment} from 'remotion';
-// eslint-disable-next-line @typescript-eslint/no-explicit-any
import {getZodSchemaFromPrimitive} from '../api/get-zod-schema-from-primitive';
import {useZodIfPossible} from '../components/get-zod-if-possible';
+import type {AnyZodSchema} from '../components/RenderModal/SchemaEditor/zod-schema-type';
import {getVisualControlEditedValue} from './get-current-edited-value';
export type VisualControlValueWithoutUnsaved = {
valueInCode: unknown;
- schema: any;
+ schema: AnyZodSchema;
stack: string;
};
@@ -38,7 +38,7 @@ export const VisualControlsTabActivatedContext =
export type SetVisualControlsContextType = {
updateHandles: () => void;
updateValue: (key: string, value: unknown) => void;
- visualControl: <T>(key: string, value: T, schema?: any) => T;
+ visualControl: <T>(key: string, value: T, schema?: AnyZodSchema) => T;
};
export const VisualControlsContext = createContext<VisualControlsContextType>({
@@ -47,7 +47,7 @@ export const VisualControlsContext = createContext<VisualControlsContextType>({
export type VisualControlRef = {
// May not call it visualControl, because we rely on stacktrace names
- globalVisualControl: <T>(key: string, value: T, schema?: any) => T;
+ globalVisualControl: <T>(key: string, value: T, schema?: AnyZodSchema) => T;
};
export const visualControlRef = createRef<VisualControlRef>();
@@ -115,8 +115,8 @@ export const VisualControlsProvider: React.FC<{
const env = useRemotionEnvironment();
const visualControl = useCallback(
- // eslint-disable-next-line prefer-arrow-callback, @typescript-eslint/no-explicit-any
- function <T>(key: string, value: T, schema?: any): T {
+ // eslint-disable-next-line prefer-arrow-callback
+ function <T>(key: string, value: T, schema?: AnyZodSchema): T {
// eslint-disable-next-line no-constant-condition
if (handles && false) {
/** Intentional: State is managed imperatively */
diff --git a/packages/zod-types-v3/.npmignore b/packages/zod-types-v3/.npmignore
new file mode 100644
index 0000000000..71352c3fd9
--- /dev/null
+++ b/packages/zod-types-v3/.npmignore
@@ -0,0 +1,10 @@
+dist/test/**
+src
+eslint.config.mjs
+tsconfig.tsbuildinfo
+*.tgz
+.turbo
+tsconfig.json
+.prettierrc.js
+bundle.ts
+dist/cjs/test
\ No newline at end of file
diff --git a/packages/zod-types-v3/README.md b/packages/zod-types-v3/README.md
new file mode 100644
index 0000000000..d57ee50d91
--- /dev/null
+++ b/packages/zod-types-v3/README.md
@@ -0,0 +1,15 @@
+# @remotion/zod-types-v3
+
+Zod v3 types for Remotion. Use this package if you are still using Zod v3 and need to compose Remotion schemas into a `z.object()`.
+
+If you are using Zod v4, use `@remotion/zod-types` instead.
+
+## Installation
+
+```bash
+npm install @remotion/zod-types-v3
+```
+
+## Documentation
+
+https://www.remotion.dev/docs/zod-types
diff --git a/packages/zod-types-v3/bundle.ts b/packages/zod-types-v3/bundle.ts
new file mode 100644
index 0000000000..1a9324d4af
--- /dev/null
+++ b/packages/zod-types-v3/bundle.ts
@@ -0,0 +1,32 @@
+import {build} from 'bun';
+import path from 'path';
+
+if (process.env.NODE_ENV !== 'production') {
+ throw new Error('This script must be run using NODE_ENV=production');
+}
+
+console.time('Generated.');
+const output = await build({
+ entrypoints: ['src/index.ts'],
+ naming: '[name].mjs',
+ external: [
+ 'remotion',
+ 'remotion/no-react',
+ '@remotion/zod-types',
+ 'zod',
+ ],
+});
+
+if (!output.success) {
+ console.log(output.logs.join('\n'));
+ process.exit(1);
+}
+
+for (const file of output.outputs) {
+ const str = await file.text();
+ const out = path.join('dist', 'esm', file.path);
+
+ await Bun.write(out, str);
+}
+
+console.timeEnd('Generated.');
diff --git a/packages/zod-types-v3/eslint.config.mjs b/packages/zod-types-v3/eslint.config.mjs
new file mode 100644
index 0000000000..04fd4fac11
--- /dev/null
+++ b/packages/zod-types-v3/eslint.config.mjs
@@ -0,0 +1,7 @@
+import {remotionFlatConfig} from '@remotion/eslint-config-internal';
+
+const config = remotionFlatConfig({react: false});
+
+export default {
+ ...config,
+};
diff --git a/packages/zod-types-v3/package.json b/packages/zod-types-v3/package.json
new file mode 100644
index 0000000000..4c9a63b32a
--- /dev/null
+++ b/packages/zod-types-v3/package.json
@@ -0,0 +1,55 @@
+{
+ "name": "@remotion/zod-types-v3",
+ "version": "4.0.423",
+ "description": "Zod v3 types for Remotion",
+ "main": "dist/index.js",
+ "types": "dist/index.d.ts",
+ "module": "dist/esm/index.mjs",
+ "repository": {
+ "url": "https://github.com/remotion-dev/remotion/tree/main/packages/zod-types-v3"
+ },
+ "sideEffects": false,
+ "type": "module",
+ "scripts": {
+ "formatting": "prettier --experimental-cli src --check",
+ "lint": "eslint src",
+ "watch": "tsgo -w",
+ "make": "tsgo && bun --env-file=../.env.bundle bundle.ts"
+ },
+ "author": "Jonny Burger <[email protected]>",
+ "contributors": [],
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/remotion-dev/remotion/issues"
+ },
+ "dependencies": {
+ "remotion": "workspace:*",
+ "@remotion/zod-types": "workspace:*"
+ },
+ "peerDependencies": {
+ "zod": ">=3.0.0 <4.0.0"
+ },
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "module": "./dist/esm/index.mjs",
+ "import": "./dist/esm/index.mjs"
+ },
+ "./package.json": "./package.json"
+ },
+ "devDependencies": {
+ "zod": "3.22.3",
+ "@remotion/eslint-config-internal": "workspace:*",
+ "eslint": "catalog:",
+ "@typescript/native-preview": "catalog:"
+ },
+ "keywords": [
+ "remotion",
+ "zod",
+ "zod-v3"
+ ],
+ "publishConfig": {
+ "access": "public"
+ },
+ "homepage": "https://www.remotion.dev/docs/zod-types"
+}
diff --git a/packages/zod-types-v3/src/index.ts b/packages/zod-types-v3/src/index.ts
new file mode 100644
index 0000000000..1857a7d320
--- /dev/null
+++ b/packages/zod-types-v3/src/index.ts
@@ -0,0 +1,3 @@
+export {zColor} from './z-color.js';
+export {zMatrix} from './z-matrix.js';
+export {zTextarea} from './z-textarea.js';
diff --git a/packages/zod-types-v3/src/z-color.ts b/packages/zod-types-v3/src/z-color.ts
new file mode 100644
index 0000000000..f982c95b1a
--- /dev/null
+++ b/packages/zod-types-v3/src/z-color.ts
@@ -0,0 +1,20 @@
+import {ZodZypesInternals} from '@remotion/zod-types';
+import {z} from 'zod';
+
+const {parseColor, REMOTION_COLOR_BRAND} = ZodZypesInternals;
+
+export const zColor = () =>
+ z
+ .string()
+ .refine(
+ (value) => {
+ try {
+ parseColor(value);
+ return true;
+ } catch {
+ return false;
+ }
+ },
+ {message: 'Invalid color'},
+ )
+ .describe(REMOTION_COLOR_BRAND);
diff --git a/packages/zod-types-v3/src/z-matrix.ts b/packages/zod-types-v3/src/z-matrix.ts
new file mode 100644
index 0000000000..ce3befda31
--- /dev/null
+++ b/packages/zod-types-v3/src/z-matrix.ts
@@ -0,0 +1,17 @@
+import {ZodZypesInternals} from '@remotion/zod-types';
+import {z} from 'zod';
+
+const {REMOTION_MATRIX_BRAND} = ZodZypesInternals;
+
+export const zMatrix = () =>
+ z
+ .array(z.number().step(0.01))
+ .refine(
+ (value) => {
+ const count = value.length;
+ const root = Math.sqrt(count);
+ return Number.isInteger(root) && root > 0;
+ },
+ {message: 'Invalid matrix, must be a square matrix'},
+ )
+ .describe(REMOTION_MATRIX_BRAND);
diff --git a/packages/zod-types-v3/src/z-textarea.ts b/packages/zod-types-v3/src/z-textarea.ts
new file mode 100644
index 0000000000..d51b08ce7b
--- /dev/null
+++ b/packages/zod-types-v3/src/z-textarea.ts
@@ -0,0 +1,6 @@
+import {ZodZypesInternals} from '@remotion/zod-types';
+import {z} from 'zod';
+
+const {REMOTION_TEXTAREA_BRAND} = ZodZypesInternals;
+
+export const zTextarea = () => z.string().describe(REMOTION_TEXTAREA_BRAND);
diff --git a/packages/zod-types-v3/tsconfig.json b/packages/zod-types-v3/tsconfig.json
new file mode 100644
index 0000000000..e5c5f5163c
--- /dev/null
+++ b/packages/zod-types-v3/tsconfig.json
@@ -0,0 +1,14 @@
+{
+ "extends": "../tsconfig.settings.json",
+ "compilerOptions": {
+ "rootDir": "src",
+ "outDir": "dist",
+ "skipLibCheck": true,
+ "target": "ES2022",
+ "module": "es2020",
+ "moduleResolution": "bundler",
+ "declaration": true,
+ "emitDeclarationOnly": true
+ },
+ "include": ["src"]
+}
diff --git a/tsconfig.json b/tsconfig.json
index 5869c92a93..564700d35f 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -243,6 +243,9 @@
{
"path": "./packages/zod-types"
},
+ {
+ "path": "./packages/zod-types-v3"
+ },
{
"path": "./packages/media"
},