🎥 Make videos programmatically with React
Rename `createDescriptor` + `defineEffect` to just `createEffect`
Jonny Burger6357b91d81ab
diff --git a/packages/core/src/effects/create-effect.ts b/packages/core/src/effects/create-effect.tsnew file mode 100644index 0000000000..516d9cbcb3--- /dev/null+++ b/packages/core/src/effects/create-effect.ts@@ -0,0 +1,29 @@+import type {EffectDefinition, EffectDescriptor} from './effect-types.js';++type EffectFactory<P> = {} extends P+ ? (params?: P) => EffectDescriptor<unknown>+ : (params: P) => EffectDescriptor<unknown>;++// Defines an effect and returns a factory that produces per-frame descriptors.+// The returned function is the public API effect authors expose to users:+//+// export const blur = createEffect<BlurParams, BlurState>({ ... });+// // usage: blur({ radius: 4 })+//+// The descriptor erases `P` and `S` to `unknown` so descriptors of different+// effects can be freely composed inside `EffectsProp` arrays. Without that+// erasure the descriptor would be contravariant in `P` (via `apply`'s+// argument) and concrete descriptors could not flow into `unknown` slots.+export const createEffect = <P, S>(+ definition: EffectDefinition<P, S>,+): EffectFactory<P> => {+ const widened = definition as unknown as EffectDefinition<unknown, unknown>;+ const factory = (params: P = {} as P): EffectDescriptor<unknown> => ({+ definition: widened,+ params,+ stack: new Error().stack!,+ effectKey: widened.calculateKey(params),+ memoized: false,+ });+ return factory as EffectFactory<P>;+};diff --git a/packages/core/src/effects/define-effect.ts b/packages/core/src/effects/define-effect.tsdeleted file mode 100644index a7f35f2988..0000000000--- a/packages/core/src/effects/define-effect.ts+++ /dev/null@@ -1,34 +0,0 @@-import type {EffectDefinition, EffectDescriptor} from './effect-types.js';--// Identity helper for declaring an effect definition with proper type-// inference. Wrapping the literal in `defineEffect(...)` lets TypeScript infer-// `<P, S>` from the `setup` and `apply` signatures while still enforcing the-// shape of the definition.-export const defineEffect = <P, S>(- definition: EffectDefinition<P, S>,-): EffectDefinition<P, S> => definition;--// Factory helper for constructing per-frame descriptors from a definition.-// Effect authors typically expose a small wrapper (e.g.-// `export const blur = (params) => createDescriptor(blurDef, params)`) so users-// don't reach into the internal definition object.-//-// `params` is type-checked against `P` at the call site, but the returned-// descriptor erases both `P` and `S` to `unknown` so it can be freely-// composed in `EffectsProp` arrays alongside descriptors of other effects.-// Without this erasure the descriptor would be contravariant in `P` (via-// `apply`'s argument), which would prevent assigning a concrete-// `EffectDescriptor<MyParams>` into an `EffectDescriptor<unknown>` slot.-export const createDescriptor = <P, S>(- definition: EffectDefinition<P, S>,- params: P,-): EffectDescriptor<unknown> => {- const widened = definition as unknown as EffectDefinition<unknown, unknown>;- return {- definition: widened,- params,- stack: new Error().stack!,- effectKey: widened.calculateKey(params),- memoized: false,- };-};diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.tsindex dc0b17e8b0..90f7905091 100644--- a/packages/core/src/internals.ts+++ b/packages/core/src/internals.ts@@ -45,7 +45,7 @@ import {EditorPropsProvider,timeValueRef,} from './EditorProps.js';-import {createDescriptor, defineEffect} from './effects/define-effect.js';+import {createEffect} from './effects/create-effect.js';import {flattenEffects} from './effects/effect-internals.js';import {runEffectChain} from './effects/run-effect-chain.js';import {useEffectChainState} from './effects/use-effect-chain-state.js';@@ -327,8 +327,7 @@ export const Internals = {useEffectChainState,runEffectChain,useMemoizedEffects,- defineEffect,- createDescriptor,+ createEffect,computeEffectiveSchemaValuesDotNotation,OverrideIdsToNodePathsGettersContext,OverrideIdsToNodePathsSettersContext,diff --git a/packages/effects/src/blur/blur-horizontal.ts b/packages/effects/src/blur/blur-horizontal.tsindex 3d518fc6c5..d3735c49d2 100644--- a/packages/effects/src/blur/blur-horizontal.ts+++ b/packages/effects/src/blur/blur-horizontal.ts@@ -1,7 +1,6 @@-import type {EffectDescriptor} from 'remotion';import {Internals} from 'remotion';-const {createDescriptor, defineEffect} = Internals;+const {createEffect} = Internals;import {applyBlur,cleanupBlur,@@ -14,7 +13,9 @@ export type BlurHorizontalParams = {readonly radius: number;};-const blurHorizontalDef = defineEffect<BlurHorizontalParams, BlurState>({+// Single horizontal pass of the separable Gaussian blur. Most callers should+// use [`blur`](./index.ts) which composes both horizontal and vertical passes.+export const blurHorizontal = createEffect<BlurHorizontalParams, BlurState>({type: 'remotion/blur-horizontal',label: 'Blur (horizontal)',backend: 'webgl2',@@ -26,9 +27,3 @@ const blurHorizontalDef = defineEffect<BlurHorizontalParams, BlurState>({cleanup: (state) => cleanupBlur(state),schema: null,});--// Single horizontal pass of the separable Gaussian blur. Most callers should-// use [`blur`](./index.ts) which composes both horizontal and vertical passes.-export const blurHorizontal = (- params: BlurHorizontalParams,-): EffectDescriptor<unknown> => createDescriptor(blurHorizontalDef, params);diff --git a/packages/effects/src/blur/blur-vertical.ts b/packages/effects/src/blur/blur-vertical.tsindex 12fb2b5ce1..2e06a929f5 100644--- a/packages/effects/src/blur/blur-vertical.ts+++ b/packages/effects/src/blur/blur-vertical.ts@@ -1,7 +1,6 @@-import type {EffectDescriptor} from 'remotion';import {Internals} from 'remotion';-const {createDescriptor, defineEffect} = Internals;+const {createEffect} = Internals;import {applyBlur,cleanupBlur,@@ -14,7 +13,9 @@ export type BlurVerticalParams = {readonly radius: number;};-const blurVerticalDef = defineEffect<BlurVerticalParams, BlurState>({+// Single vertical pass of the separable Gaussian blur. Most callers should+// use [`blur`](./index.ts) which composes both horizontal and vertical passes.+export const blurVertical = createEffect<BlurVerticalParams, BlurState>({type: 'remotion/blur-vertical',label: 'Blur (vertical)',backend: 'webgl2',@@ -26,9 +27,3 @@ const blurVerticalDef = defineEffect<BlurVerticalParams, BlurState>({cleanup: (state) => cleanupBlur(state),schema: null,});--// Single vertical pass of the separable Gaussian blur. Most callers should-// use [`blur`](./index.ts) which composes both horizontal and vertical passes.-export const blurVertical = (- params: BlurVerticalParams,-): EffectDescriptor<unknown> => createDescriptor(blurVerticalDef, params);diff --git a/packages/effects/src/halftone.ts b/packages/effects/src/halftone.tsindex 36cd160fae..8348da18bf 100644--- a/packages/effects/src/halftone.ts+++ b/packages/effects/src/halftone.ts@@ -1,7 +1,7 @@-import type {EffectDescriptor, SequenceSchema} from 'remotion';+import type {SequenceSchema} from 'remotion';import {Internals} from 'remotion';-const {createDescriptor, defineEffect} = Internals;+const {createEffect} = Internals;const SHADE_OUTSIDE_DOT_SCALE = 0.5;@@ -263,7 +263,13 @@ const parseColorRgba = (return [data[0] / 255, data[1] / 255, data[2] / 255, data[3] / 255];};-const halftoneDef = defineEffect<HalftoneParams, HalftoneState>({+// Halftone effect (WebGL2). Converts luminance into a grid of dots, squares,+// or lines. Each fragment determines its nearest grid cell and whether it falls+// inside a dot, so edge dots are never culled. `dotSpacing` sets the grid pitch+// (defaults to `dotSize`). `sampling` controls texture interpolation when+// reading luminance at grid centres. `shadeOutside` fills transparent areas+// with a screen tone instead of luminance-driven ink on opaque pixels alone.+export const halftone = createEffect<HalftoneParams, HalftoneState>({type: 'remotion/halftone',label: 'Halftone',backend: 'webgl2',@@ -417,13 +423,3 @@ const halftoneDef = defineEffect<HalftoneParams, HalftoneState>({},schema: halftoneSchema,});--// Halftone effect (WebGL2). Converts luminance into a grid of dots, squares,-// or lines. Each fragment determines its nearest grid cell and whether it falls-// inside a dot, so edge dots are never culled. `dotSpacing` sets the grid pitch-// (defaults to `dotSize`). `sampling` controls texture interpolation when-// reading luminance at grid centres. `shadeOutside` fills transparent areas-// with a screen tone instead of luminance-driven ink on opaque pixels alone.-export const halftone = (- params: HalftoneParams = {},-): EffectDescriptor<unknown> => createDescriptor(halftoneDef, params);diff --git a/packages/effects/src/tint.ts b/packages/effects/src/tint.tsindex 2b0cce14d9..e7a4eec1d0 100644--- a/packages/effects/src/tint.ts+++ b/packages/effects/src/tint.ts@@ -1,7 +1,7 @@-import type {EffectDescriptor, SequenceSchema} from 'remotion';+import type {SequenceSchema} from 'remotion';import {Internals} from 'remotion';-const {createDescriptor, defineEffect} = Internals;+const {createEffect} = Internals;const DEFAULT_AMOUNT = 0.5 as const;@@ -31,7 +31,10 @@ const resolve = (p: TintParams): TintResolved => ({amount: p.amount ?? DEFAULT_AMOUNT,});-const tintDef = defineEffect<TintParams, null>({+// Tints the source with a flat color. `amount` controls the blend strength+// (0 = no tint, 1 = full color over opaque pixels). Operates on the 2D+// backend; tinting respects the source's alpha mask.+export const tint = createEffect<TintParams, null>({type: 'remotion/tint',label: 'Tint',backend: '2d',@@ -69,9 +72,3 @@ const tintDef = defineEffect<TintParams, null>({cleanup: () => undefined,schema: tintSchema,});--// Tints the source with a flat color. `amount` controls the blend strength-// (0 = no tint, 1 = full color over opaque pixels). Operates on the 2D-// backend; tinting respects the source's alpha mask.-export const tint = (params: TintParams): EffectDescriptor<unknown> =>- createDescriptor(tintDef, params);diff --git a/packages/effects/src/wave.ts b/packages/effects/src/wave.tsindex 2fac51fbc0..a32e3c7cbc 100644--- a/packages/effects/src/wave.ts+++ b/packages/effects/src/wave.ts@@ -1,7 +1,6 @@-import type {EffectDescriptor} from 'remotion';import {Internals} from 'remotion';-const {createDescriptor, defineEffect} = Internals;+const {createEffect} = Internals;export type WaveParams = {readonly amplitude?: number;@@ -27,7 +26,9 @@ const resolve = (p: WaveParams): WaveResolved => ({background: p.background ?? 'transparent',});-const waveDef = defineEffect<WaveParams, null>({+// Vertical-displacement wave effect: shifts vertical slices of the source+// up/down with a sine wave that animates over time. Operates on the 2D backend.+export const wave = createEffect<WaveParams, null>({type: 'remotion/wave',label: 'Wave',backend: '2d',@@ -72,8 +73,3 @@ const waveDef = defineEffect<WaveParams, null>({cleanup: () => undefined,schema: null,});--// Vertical-displacement wave effect: shifts vertical slices of the source-// up/down with a sine wave that animates over time. Operates on the 2D backend.-export const wave = (params: WaveParams = {}): EffectDescriptor<unknown> =>- createDescriptor(waveDef, params);