@remotion/effects 4.0.466 → 4.0.467

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ export type ChromaticAberrationState = {
2
+ gl: WebGL2RenderingContext;
3
+ program: WebGLProgram;
4
+ vao: WebGLVertexArrayObject;
5
+ vbo: WebGLBuffer;
6
+ textureSource: WebGLTexture;
7
+ uniforms: {
8
+ uSource: WebGLUniformLocation | null;
9
+ uOffset: WebGLUniformLocation | null;
10
+ };
11
+ };
12
+ export declare const setupChromaticAberration: (target: HTMLCanvasElement) => ChromaticAberrationState;
13
+ export declare const cleanupChromaticAberration: (state: ChromaticAberrationState) => void;
14
+ export declare const applyChromaticAberration: ({ state, source, width, height, amount, angle, flipSourceY, }: {
15
+ readonly state: ChromaticAberrationState;
16
+ readonly source: CanvasImageSource;
17
+ readonly width: number;
18
+ readonly height: number;
19
+ readonly amount: number;
20
+ readonly angle: number;
21
+ readonly flipSourceY: boolean;
22
+ }) => void;
@@ -0,0 +1,2 @@
1
+ export declare const CHROMATIC_ABERRATION_VS = "#version 300 es\nlayout(location = 0) in vec2 aPos;\nlayout(location = 1) in vec2 aUv;\nout vec2 vUv;\nvoid main() {\n\tvUv = aUv;\n\tgl_Position = vec4(aPos, 0.0, 1.0);\n}\n";
2
+ export declare const CHROMATIC_ABERRATION_FS = "#version 300 es\nprecision highp float;\nin vec2 vUv;\nout vec4 fragColor;\n\nuniform sampler2D uSource;\nuniform vec2 uOffset;\n\nvoid main() {\n\tvec4 redSample = texture(uSource, vUv - uOffset);\n\tvec4 centerSample = texture(uSource, vUv);\n\tvec4 blueSample = texture(uSource, vUv + uOffset);\n\n\tfragColor = vec4(redSample.r, centerSample.g, blueSample.b, centerSample.a);\n}\n";
@@ -0,0 +1,9 @@
1
+ export type ChromaticAberrationParams = {
2
+ /** RGB channel separation in pixels. Defaults to `8`. */
3
+ readonly amount?: number;
4
+ /** Direction of the split in degrees. Defaults to `0`. */
5
+ readonly angle?: number;
6
+ };
7
+ export declare const chromaticAberration: (params?: (ChromaticAberrationParams & {
8
+ readonly disabled?: boolean | undefined;
9
+ }) | undefined) => import("remotion").EffectDescriptor<unknown>;
@@ -0,0 +1 @@
1
+ export { chromaticAberration, type ChromaticAberrationParams, } from './chromatic-aberration/index.js';
@@ -0,0 +1,7 @@
1
+ export type ContrastParams = {
2
+ /** Contrast multiplier. `1` leaves the image unchanged, `0` produces a flat gray, values above `1` increase contrast. Defaults to `1`. */
3
+ readonly amount?: number;
4
+ };
5
+ export declare const contrast: (params?: (ContrastParams & {
6
+ readonly disabled?: boolean | undefined;
7
+ }) | undefined) => import("remotion").EffectDescriptor<unknown>;
@@ -0,0 +1,330 @@
1
+ // src/chromatic-aberration/index.ts
2
+ import { Internals as Internals2 } from "remotion";
3
+
4
+ // src/validate-effect-param.ts
5
+ var assertEffectParamsObject = (params, effectLabel) => {
6
+ if (params === null || typeof params !== "object") {
7
+ throw new TypeError(`${effectLabel} effect requires a parameters object, but got ${JSON.stringify(params)}`);
8
+ }
9
+ };
10
+ var assertRequiredFiniteNumber = (value, name) => {
11
+ if (typeof value !== "number" || !Number.isFinite(value)) {
12
+ throw new TypeError(`"${name}" must be a finite number, but got ${JSON.stringify(value)}`);
13
+ }
14
+ };
15
+ var assertRequiredColor = (value, name) => {
16
+ if (typeof value !== "string" || value.length === 0) {
17
+ throw new TypeError(`"${name}" must be a non-empty string, but got ${JSON.stringify(value)}`);
18
+ }
19
+ };
20
+
21
+ // src/color-utils.ts
22
+ var DEFAULT_AMOUNT = 1;
23
+ var DEFAULT_BRIGHTNESS_AMOUNT = 0;
24
+ var DEFAULT_HUE_DEGREES = 0;
25
+ var colorAmountSchema = {
26
+ type: "number",
27
+ min: 0,
28
+ max: 1,
29
+ step: 0.01,
30
+ default: DEFAULT_AMOUNT,
31
+ description: "Amount"
32
+ };
33
+ var colorMultiplierSchema = {
34
+ type: "number",
35
+ min: 0,
36
+ step: 0.01,
37
+ default: DEFAULT_AMOUNT,
38
+ description: "Amount"
39
+ };
40
+ var brightnessAmountSchema = {
41
+ type: "number",
42
+ min: -1,
43
+ max: 1,
44
+ step: 0.01,
45
+ default: DEFAULT_BRIGHTNESS_AMOUNT,
46
+ description: "Amount"
47
+ };
48
+ var hueDegreesSchema = {
49
+ type: "number",
50
+ step: 1,
51
+ default: DEFAULT_HUE_DEGREES,
52
+ description: "Degrees"
53
+ };
54
+ var assertOptionalFiniteNumber = (value, name) => {
55
+ if (value === undefined) {
56
+ return;
57
+ }
58
+ assertRequiredFiniteNumber(value, name);
59
+ };
60
+ var validateUnitInterval = (value, name) => {
61
+ if (value < 0) {
62
+ throw new TypeError(`"${name}" must be >= 0, but got ${JSON.stringify(value)}`);
63
+ }
64
+ if (value > 1) {
65
+ throw new TypeError(`"${name}" must be <= 1, but got ${JSON.stringify(value)}`);
66
+ }
67
+ };
68
+ var validateNonNegative = (value, name) => {
69
+ if (value < 0) {
70
+ throw new TypeError(`"${name}" must be >= 0, but got ${JSON.stringify(value)}`);
71
+ }
72
+ };
73
+ var validateSignedUnitInterval = (value, name) => {
74
+ if (value < -1) {
75
+ throw new TypeError(`"${name}" must be >= -1, but got ${JSON.stringify(value)}`);
76
+ }
77
+ if (value > 1) {
78
+ throw new TypeError(`"${name}" must be <= 1, but got ${JSON.stringify(value)}`);
79
+ }
80
+ };
81
+ var clampColorChannel = (value) => {
82
+ return Math.max(0, Math.min(255, value));
83
+ };
84
+
85
+ // src/chromatic-aberration/chromatic-aberration-runtime.ts
86
+ import { Internals } from "remotion";
87
+
88
+ // src/chromatic-aberration/chromatic-aberration-shaders.ts
89
+ var CHROMATIC_ABERRATION_VS = `#version 300 es
90
+ layout(location = 0) in vec2 aPos;
91
+ layout(location = 1) in vec2 aUv;
92
+ out vec2 vUv;
93
+ void main() {
94
+ vUv = aUv;
95
+ gl_Position = vec4(aPos, 0.0, 1.0);
96
+ }
97
+ `;
98
+ var CHROMATIC_ABERRATION_FS = `#version 300 es
99
+ precision highp float;
100
+ in vec2 vUv;
101
+ out vec4 fragColor;
102
+
103
+ uniform sampler2D uSource;
104
+ uniform vec2 uOffset;
105
+
106
+ void main() {
107
+ vec4 redSample = texture(uSource, vUv - uOffset);
108
+ vec4 centerSample = texture(uSource, vUv);
109
+ vec4 blueSample = texture(uSource, vUv + uOffset);
110
+
111
+ fragColor = vec4(redSample.r, centerSample.g, blueSample.b, centerSample.a);
112
+ }
113
+ `;
114
+
115
+ // src/chromatic-aberration/chromatic-aberration-runtime.ts
116
+ var { createWebGL2ContextError } = Internals;
117
+ var compileShader = (gl, type, source) => {
118
+ const shader = gl.createShader(type);
119
+ if (!shader) {
120
+ throw new Error("Failed to create WebGL shader");
121
+ }
122
+ gl.shaderSource(shader, source);
123
+ gl.compileShader(shader);
124
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
125
+ const log = gl.getShaderInfoLog(shader);
126
+ gl.deleteShader(shader);
127
+ throw new Error(`Shader compile failed: ${log ?? "(no log)"}`);
128
+ }
129
+ return shader;
130
+ };
131
+ var linkProgram = (gl, vs, fs) => {
132
+ const program = gl.createProgram();
133
+ if (!program) {
134
+ throw new Error("Failed to create WebGL program");
135
+ }
136
+ gl.attachShader(program, vs);
137
+ gl.attachShader(program, fs);
138
+ gl.linkProgram(program);
139
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
140
+ const log = gl.getProgramInfoLog(program);
141
+ gl.deleteProgram(program);
142
+ throw new Error(`Program link failed: ${log ?? "(no log)"}`);
143
+ }
144
+ return program;
145
+ };
146
+ var createProgram = (gl, vertexSource, fragmentSource) => {
147
+ const vs = compileShader(gl, gl.VERTEX_SHADER, vertexSource);
148
+ const fs = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
149
+ const program = linkProgram(gl, vs, fs);
150
+ gl.deleteShader(vs);
151
+ gl.deleteShader(fs);
152
+ return program;
153
+ };
154
+ var createRgbaTexture = (gl) => {
155
+ const texture = gl.createTexture();
156
+ if (!texture) {
157
+ throw new Error("Failed to create WebGL texture");
158
+ }
159
+ gl.bindTexture(gl.TEXTURE_2D, texture);
160
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
161
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
162
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
163
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
164
+ gl.bindTexture(gl.TEXTURE_2D, null);
165
+ return texture;
166
+ };
167
+ var setupChromaticAberration = (target) => {
168
+ const gl = target.getContext("webgl2", {
169
+ premultipliedAlpha: true,
170
+ alpha: true,
171
+ preserveDrawingBuffer: true
172
+ });
173
+ if (!gl) {
174
+ throw createWebGL2ContextError("chromatic aberration effect");
175
+ }
176
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
177
+ const program = createProgram(gl, CHROMATIC_ABERRATION_VS, CHROMATIC_ABERRATION_FS);
178
+ const vao = gl.createVertexArray();
179
+ if (!vao) {
180
+ throw new Error("Failed to create WebGL vertex array");
181
+ }
182
+ gl.bindVertexArray(vao);
183
+ const data = new Float32Array([
184
+ -1,
185
+ -1,
186
+ 0,
187
+ 0,
188
+ 1,
189
+ -1,
190
+ 1,
191
+ 0,
192
+ -1,
193
+ 1,
194
+ 0,
195
+ 1,
196
+ 1,
197
+ 1,
198
+ 1,
199
+ 1
200
+ ]);
201
+ const vbo = gl.createBuffer();
202
+ if (!vbo) {
203
+ throw new Error("Failed to create WebGL buffer");
204
+ }
205
+ gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
206
+ gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
207
+ gl.enableVertexAttribArray(0);
208
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 16, 0);
209
+ gl.enableVertexAttribArray(1);
210
+ gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 16, 8);
211
+ gl.bindVertexArray(null);
212
+ const textureSource = createRgbaTexture(gl);
213
+ return {
214
+ gl,
215
+ program,
216
+ vao,
217
+ vbo,
218
+ textureSource,
219
+ uniforms: {
220
+ uSource: gl.getUniformLocation(program, "uSource"),
221
+ uOffset: gl.getUniformLocation(program, "uOffset")
222
+ }
223
+ };
224
+ };
225
+ var cleanupChromaticAberration = (state) => {
226
+ const { gl, program, vao, vbo, textureSource } = state;
227
+ gl.deleteTexture(textureSource);
228
+ gl.deleteBuffer(vbo);
229
+ gl.deleteProgram(program);
230
+ gl.deleteVertexArray(vao);
231
+ };
232
+ var drawFullscreenQuad = (state) => {
233
+ const { gl, vao } = state;
234
+ gl.bindVertexArray(vao);
235
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
236
+ gl.bindVertexArray(null);
237
+ };
238
+ var applyChromaticAberration = ({
239
+ state,
240
+ source,
241
+ width,
242
+ height,
243
+ amount,
244
+ angle,
245
+ flipSourceY
246
+ }) => {
247
+ const { gl, program, textureSource, uniforms } = state;
248
+ const radians = angle * Math.PI / 180;
249
+ const x = Math.cos(radians) * amount / width;
250
+ const y = Math.sin(radians) * amount / height;
251
+ gl.viewport(0, 0, width, height);
252
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);
253
+ gl.bindTexture(gl.TEXTURE_2D, textureSource);
254
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
255
+ gl.bindTexture(gl.TEXTURE_2D, null);
256
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
257
+ gl.clearColor(0, 0, 0, 0);
258
+ gl.clear(gl.COLOR_BUFFER_BIT);
259
+ gl.useProgram(program);
260
+ if (uniforms.uSource)
261
+ gl.uniform1i(uniforms.uSource, 0);
262
+ if (uniforms.uOffset)
263
+ gl.uniform2f(uniforms.uOffset, x, y);
264
+ gl.activeTexture(gl.TEXTURE0);
265
+ gl.bindTexture(gl.TEXTURE_2D, textureSource);
266
+ drawFullscreenQuad(state);
267
+ gl.bindTexture(gl.TEXTURE_2D, null);
268
+ gl.useProgram(null);
269
+ };
270
+
271
+ // src/chromatic-aberration/index.ts
272
+ var { createEffect } = Internals2;
273
+ var DEFAULT_CHROMATIC_ABERRATION_AMOUNT = 8;
274
+ var DEFAULT_CHROMATIC_ABERRATION_ANGLE = 0;
275
+ var chromaticAberrationSchema = {
276
+ amount: {
277
+ type: "number",
278
+ min: 0,
279
+ max: 100,
280
+ step: 1,
281
+ default: DEFAULT_CHROMATIC_ABERRATION_AMOUNT,
282
+ description: "Amount"
283
+ },
284
+ angle: {
285
+ type: "number",
286
+ step: 1,
287
+ default: DEFAULT_CHROMATIC_ABERRATION_ANGLE,
288
+ description: "Angle"
289
+ }
290
+ };
291
+ var resolve = (params) => ({
292
+ amount: params.amount ?? DEFAULT_CHROMATIC_ABERRATION_AMOUNT,
293
+ angle: params.angle ?? DEFAULT_CHROMATIC_ABERRATION_ANGLE
294
+ });
295
+ var validateChromaticAberrationParams = (params) => {
296
+ assertEffectParamsObject(params, "Chromatic Aberration");
297
+ assertOptionalFiniteNumber(params.amount, "amount");
298
+ assertOptionalFiniteNumber(params.angle, "angle");
299
+ const resolved = resolve(params);
300
+ validateNonNegative(resolved.amount, "amount");
301
+ };
302
+ var chromaticAberration = createEffect({
303
+ type: "remotion/chromatic-aberration",
304
+ label: "Chromatic Aberration",
305
+ documentationLink: "https://www.remotion.dev/docs/effects/chromatic-aberration",
306
+ backend: "webgl2",
307
+ calculateKey: (params) => {
308
+ const resolved = resolve(params);
309
+ return `chromatic-aberration-${resolved.amount}-${resolved.angle}`;
310
+ },
311
+ setup: (target) => setupChromaticAberration(target),
312
+ apply: ({ source, width, height, params, state, flipSourceY }) => {
313
+ const resolved = resolve(params);
314
+ applyChromaticAberration({
315
+ state,
316
+ source,
317
+ width,
318
+ height,
319
+ amount: resolved.amount,
320
+ angle: resolved.angle,
321
+ flipSourceY
322
+ });
323
+ },
324
+ cleanup: (state) => cleanupChromaticAberration(state),
325
+ schema: chromaticAberrationSchema,
326
+ validateParams: validateChromaticAberrationParams
327
+ });
328
+ export {
329
+ chromaticAberration
330
+ };
@@ -0,0 +1,138 @@
1
+ // src/contrast.ts
2
+ import { Internals } from "remotion";
3
+
4
+ // src/validate-effect-param.ts
5
+ var assertEffectParamsObject = (params, effectLabel) => {
6
+ if (params === null || typeof params !== "object") {
7
+ throw new TypeError(`${effectLabel} effect requires a parameters object, but got ${JSON.stringify(params)}`);
8
+ }
9
+ };
10
+ var assertRequiredFiniteNumber = (value, name) => {
11
+ if (typeof value !== "number" || !Number.isFinite(value)) {
12
+ throw new TypeError(`"${name}" must be a finite number, but got ${JSON.stringify(value)}`);
13
+ }
14
+ };
15
+ var assertRequiredColor = (value, name) => {
16
+ if (typeof value !== "string" || value.length === 0) {
17
+ throw new TypeError(`"${name}" must be a non-empty string, but got ${JSON.stringify(value)}`);
18
+ }
19
+ };
20
+
21
+ // src/color-utils.ts
22
+ var DEFAULT_AMOUNT = 1;
23
+ var DEFAULT_BRIGHTNESS_AMOUNT = 0;
24
+ var DEFAULT_HUE_DEGREES = 0;
25
+ var colorAmountSchema = {
26
+ type: "number",
27
+ min: 0,
28
+ max: 1,
29
+ step: 0.01,
30
+ default: DEFAULT_AMOUNT,
31
+ description: "Amount"
32
+ };
33
+ var colorMultiplierSchema = {
34
+ type: "number",
35
+ min: 0,
36
+ step: 0.01,
37
+ default: DEFAULT_AMOUNT,
38
+ description: "Amount"
39
+ };
40
+ var brightnessAmountSchema = {
41
+ type: "number",
42
+ min: -1,
43
+ max: 1,
44
+ step: 0.01,
45
+ default: DEFAULT_BRIGHTNESS_AMOUNT,
46
+ description: "Amount"
47
+ };
48
+ var hueDegreesSchema = {
49
+ type: "number",
50
+ step: 1,
51
+ default: DEFAULT_HUE_DEGREES,
52
+ description: "Degrees"
53
+ };
54
+ var assertOptionalFiniteNumber = (value, name) => {
55
+ if (value === undefined) {
56
+ return;
57
+ }
58
+ assertRequiredFiniteNumber(value, name);
59
+ };
60
+ var validateUnitInterval = (value, name) => {
61
+ if (value < 0) {
62
+ throw new TypeError(`"${name}" must be >= 0, but got ${JSON.stringify(value)}`);
63
+ }
64
+ if (value > 1) {
65
+ throw new TypeError(`"${name}" must be <= 1, but got ${JSON.stringify(value)}`);
66
+ }
67
+ };
68
+ var validateNonNegative = (value, name) => {
69
+ if (value < 0) {
70
+ throw new TypeError(`"${name}" must be >= 0, but got ${JSON.stringify(value)}`);
71
+ }
72
+ };
73
+ var validateSignedUnitInterval = (value, name) => {
74
+ if (value < -1) {
75
+ throw new TypeError(`"${name}" must be >= -1, but got ${JSON.stringify(value)}`);
76
+ }
77
+ if (value > 1) {
78
+ throw new TypeError(`"${name}" must be <= 1, but got ${JSON.stringify(value)}`);
79
+ }
80
+ };
81
+ var clampColorChannel = (value) => {
82
+ return Math.max(0, Math.min(255, value));
83
+ };
84
+
85
+ // src/contrast.ts
86
+ var { createEffect } = Internals;
87
+ var contrastSchema = {
88
+ amount: colorMultiplierSchema
89
+ };
90
+ var resolve = (p) => ({
91
+ amount: p.amount ?? DEFAULT_AMOUNT
92
+ });
93
+ var validateContrastParams = (params) => {
94
+ assertEffectParamsObject(params, "Contrast");
95
+ assertOptionalFiniteNumber(params.amount, "amount");
96
+ const { amount } = resolve(params);
97
+ validateNonNegative(amount, "amount");
98
+ };
99
+ var contrast = createEffect({
100
+ type: "remotion/contrast",
101
+ label: "Contrast",
102
+ documentationLink: "https://www.remotion.dev/docs/effects/contrast",
103
+ backend: "2d",
104
+ calculateKey: (params) => {
105
+ const r = resolve(params);
106
+ return `contrast-${r.amount}`;
107
+ },
108
+ setup: () => null,
109
+ apply: ({ source, target, width, height, params }) => {
110
+ const ctx = target.getContext("2d");
111
+ if (!ctx) {
112
+ throw new Error("Failed to acquire 2D context for contrast effect. The canvas may have been assigned a different context type.");
113
+ }
114
+ const r = resolve(params);
115
+ ctx.clearRect(0, 0, width, height);
116
+ ctx.drawImage(source, 0, 0, width, height);
117
+ if (r.amount === 1) {
118
+ return;
119
+ }
120
+ const imageData = ctx.getImageData(0, 0, width, height);
121
+ const { data } = imageData;
122
+ const factor = r.amount;
123
+ for (let i = 0;i < data.length; i += 4) {
124
+ data[i] = clampColorChannel((data[i] - 128) * factor + 128);
125
+ data[i + 1] = clampColorChannel((data[i + 1] - 128) * factor + 128);
126
+ data[i + 2] = clampColorChannel((data[i + 2] - 128) * factor + 128);
127
+ }
128
+ ctx.putImageData(imageData, 0, 0);
129
+ },
130
+ cleanup: () => {
131
+ return;
132
+ },
133
+ schema: contrastSchema,
134
+ validateParams: validateContrastParams
135
+ });
136
+ export {
137
+ contrast
138
+ };
@@ -86,6 +86,7 @@ var clampColorChannel = (value) => {
86
86
  var { createEffect, createWebGL2ContextError } = Internals;
87
87
  var HALFTONE_SHAPES = ["circle", "square", "line"];
88
88
  var HALFTONE_SAMPLING = ["bilinear", "nearest"];
89
+ var HALFTONE_COLOR_MODES = ["solid", "source"];
89
90
  var halftoneSchema = {
90
91
  dotSize: {
91
92
  type: "number",
@@ -138,10 +139,20 @@ var halftoneSchema = {
138
139
  default: false,
139
140
  description: "Invert"
140
141
  },
141
- color: {
142
- type: "color",
143
- default: "black",
144
- description: "Color"
142
+ colorMode: {
143
+ type: "enum",
144
+ default: "solid",
145
+ description: "Color mode",
146
+ variants: {
147
+ solid: {
148
+ dotColor: {
149
+ type: "color",
150
+ default: "red",
151
+ description: "Dot color"
152
+ }
153
+ },
154
+ source: {}
155
+ }
145
156
  }
146
157
  };
147
158
  var formatEnum = (variants) => {
@@ -182,7 +193,8 @@ var resolve = (p) => ({
182
193
  offsetX: p.offsetX ?? 0,
183
194
  offsetY: p.offsetY ?? 0,
184
195
  sampling: p.sampling ?? "bilinear",
185
- color: p.color ?? "black",
196
+ colorMode: p.colorMode ?? "solid",
197
+ dotColor: "dotColor" in p ? p.dotColor ?? "red" : "red",
186
198
  invert: p.invert ?? false
187
199
  });
188
200
  var validateHalftoneParams = (params) => {
@@ -194,7 +206,14 @@ var validateHalftoneParams = (params) => {
194
206
  assertOptionalFiniteNumber(params.offsetY, "offsetY");
195
207
  assertOptionalEnum(params.shape, "shape", HALFTONE_SHAPES);
196
208
  assertOptionalEnum(params.sampling, "sampling", HALFTONE_SAMPLING);
197
- assertOptionalColor(params.color, "color");
209
+ assertOptionalEnum(params.colorMode, "colorMode", HALFTONE_COLOR_MODES);
210
+ if ("color" in params && params.color !== undefined) {
211
+ throw new TypeError('"color" has been renamed to "dotColor"');
212
+ }
213
+ if (params.colorMode === "source" && "dotColor" in params) {
214
+ throw new TypeError('"dotColor" can only be set when "colorMode" is "solid"');
215
+ }
216
+ assertOptionalColor("dotColor" in params ? params.dotColor : undefined, "dotColor");
198
217
  assertOptionalBoolean(params.invert, "invert");
199
218
  if (params.dotSize !== undefined && params.dotSize < 1) {
200
219
  throw new TypeError(`"dotSize" must be >= 1, but got ${JSON.stringify(params.dotSize)}`);
@@ -227,6 +246,7 @@ uniform vec2 uOffset;
227
246
  uniform vec4 uColor;
228
247
  uniform int uShape;
229
248
  uniform bool uShadeOutside;
249
+ uniform bool uUseSourceColor;
230
250
 
231
251
  void main() {
232
252
  vec2 fragPos = vUv * uResolution;
@@ -285,7 +305,7 @@ void main() {
285
305
  * (1.0 - smoothstep(lineHalf - 0.5, lineHalf + 0.5, abs(diff.y)));
286
306
  }
287
307
 
288
- fragColor = uColor * coverage;
308
+ fragColor = (uUseSourceColor ? texColor : uColor) * coverage;
289
309
  }
290
310
  `;
291
311
  var SHAPE_INDEX = {
@@ -336,7 +356,7 @@ var halftone = createEffect({
336
356
  backend: "webgl2",
337
357
  calculateKey: (params) => {
338
358
  const r = resolve(params);
339
- return `halftone-${r.shape}-${r.dotSize}-${r.dotSpacing}-${r.rotation}-${r.offsetX}-${r.offsetY}-${r.sampling}-${r.color}-${r.invert ? 1 : 0}`;
359
+ return `halftone-${r.shape}-${r.dotSize}-${r.dotSpacing}-${r.rotation}-${r.offsetX}-${r.offsetY}-${r.sampling}-${r.colorMode}-${r.dotColor}-${r.invert ? 1 : 0}`;
340
360
  },
341
361
  setup: (target) => {
342
362
  const gl = target.getContext("webgl2", {
@@ -419,6 +439,7 @@ var halftone = createEffect({
419
439
  uColor: gl.getUniformLocation(program, "uColor"),
420
440
  uShape: gl.getUniformLocation(program, "uShape"),
421
441
  uShadeOutside: gl.getUniformLocation(program, "uShadeOutside"),
442
+ uUseSourceColor: gl.getUniformLocation(program, "uUseSourceColor"),
422
443
  colorCtx,
423
444
  cachedColorStr: "",
424
445
  cachedColorRgba: [0, 0, 0, 1]
@@ -427,9 +448,9 @@ var halftone = createEffect({
427
448
  apply: ({ source, width, height, params, state, flipSourceY }) => {
428
449
  const r = resolve(params);
429
450
  const { gl, program, vao, texture } = state;
430
- if (state.cachedColorStr !== r.color) {
431
- state.cachedColorStr = r.color;
432
- state.cachedColorRgba = parseColorRgba(state.colorCtx, r.color);
451
+ if (state.cachedColorStr !== r.dotColor) {
452
+ state.cachedColorStr = r.dotColor;
453
+ state.cachedColorRgba = parseColorRgba(state.colorCtx, r.dotColor);
433
454
  }
434
455
  const [cr, cg, cb, ca] = state.cachedColorRgba;
435
456
  const filter = r.sampling === "nearest" ? gl.NEAREST : gl.LINEAR;
@@ -462,6 +483,8 @@ var halftone = createEffect({
462
483
  gl.uniform1i(state.uShape, SHAPE_INDEX[r.shape]);
463
484
  if (state.uShadeOutside)
464
485
  gl.uniform1i(state.uShadeOutside, r.invert ? 1 : 0);
486
+ if (state.uUseSourceColor)
487
+ gl.uniform1i(state.uUseSourceColor, r.colorMode === "source" ? 1 : 0);
465
488
  gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
466
489
  gl.bindVertexArray(null);
467
490
  gl.bindTexture(gl.TEXTURE_2D, null);
@@ -0,0 +1,205 @@
1
+ // src/translate/index.ts
2
+ import { Internals } from "remotion";
3
+
4
+ // src/validate-effect-param.ts
5
+ var assertEffectParamsObject = (params, effectLabel) => {
6
+ if (params === null || typeof params !== "object") {
7
+ throw new TypeError(`${effectLabel} effect requires a parameters object, but got ${JSON.stringify(params)}`);
8
+ }
9
+ };
10
+ var assertRequiredFiniteNumber = (value, name) => {
11
+ if (typeof value !== "number" || !Number.isFinite(value)) {
12
+ throw new TypeError(`"${name}" must be a finite number, but got ${JSON.stringify(value)}`);
13
+ }
14
+ };
15
+ var assertRequiredColor = (value, name) => {
16
+ if (typeof value !== "string" || value.length === 0) {
17
+ throw new TypeError(`"${name}" must be a non-empty string, but got ${JSON.stringify(value)}`);
18
+ }
19
+ };
20
+
21
+ // src/color-utils.ts
22
+ var DEFAULT_AMOUNT = 1;
23
+ var DEFAULT_BRIGHTNESS_AMOUNT = 0;
24
+ var DEFAULT_HUE_DEGREES = 0;
25
+ var colorAmountSchema = {
26
+ type: "number",
27
+ min: 0,
28
+ max: 1,
29
+ step: 0.01,
30
+ default: DEFAULT_AMOUNT,
31
+ description: "Amount"
32
+ };
33
+ var colorMultiplierSchema = {
34
+ type: "number",
35
+ min: 0,
36
+ step: 0.01,
37
+ default: DEFAULT_AMOUNT,
38
+ description: "Amount"
39
+ };
40
+ var brightnessAmountSchema = {
41
+ type: "number",
42
+ min: -1,
43
+ max: 1,
44
+ step: 0.01,
45
+ default: DEFAULT_BRIGHTNESS_AMOUNT,
46
+ description: "Amount"
47
+ };
48
+ var hueDegreesSchema = {
49
+ type: "number",
50
+ step: 1,
51
+ default: DEFAULT_HUE_DEGREES,
52
+ description: "Degrees"
53
+ };
54
+ var assertOptionalFiniteNumber = (value, name) => {
55
+ if (value === undefined) {
56
+ return;
57
+ }
58
+ assertRequiredFiniteNumber(value, name);
59
+ };
60
+ var validateUnitInterval = (value, name) => {
61
+ if (value < 0) {
62
+ throw new TypeError(`"${name}" must be >= 0, but got ${JSON.stringify(value)}`);
63
+ }
64
+ if (value > 1) {
65
+ throw new TypeError(`"${name}" must be <= 1, but got ${JSON.stringify(value)}`);
66
+ }
67
+ };
68
+ var validateNonNegative = (value, name) => {
69
+ if (value < 0) {
70
+ throw new TypeError(`"${name}" must be >= 0, but got ${JSON.stringify(value)}`);
71
+ }
72
+ };
73
+ var validateSignedUnitInterval = (value, name) => {
74
+ if (value < -1) {
75
+ throw new TypeError(`"${name}" must be >= -1, but got ${JSON.stringify(value)}`);
76
+ }
77
+ if (value > 1) {
78
+ throw new TypeError(`"${name}" must be <= 1, but got ${JSON.stringify(value)}`);
79
+ }
80
+ };
81
+ var clampColorChannel = (value) => {
82
+ return Math.max(0, Math.min(255, value));
83
+ };
84
+
85
+ // src/translate/index.ts
86
+ var { createEffect } = Internals;
87
+ var xyTranslateSchema = {
88
+ x: {
89
+ type: "number",
90
+ step: 1,
91
+ default: 0,
92
+ description: "X"
93
+ },
94
+ y: {
95
+ type: "number",
96
+ step: 1,
97
+ default: 0,
98
+ description: "Y"
99
+ }
100
+ };
101
+ var uvTranslateSchema = {
102
+ u: {
103
+ type: "number",
104
+ step: 0.01,
105
+ default: 0,
106
+ description: "U"
107
+ },
108
+ v: {
109
+ type: "number",
110
+ step: 0.01,
111
+ default: 0,
112
+ description: "V"
113
+ }
114
+ };
115
+ var resolveXyTranslate = (params) => ({
116
+ x: params.x ?? 0,
117
+ y: params.y ?? 0
118
+ });
119
+ var resolveUvTranslate = (params) => ({
120
+ u: params.u ?? 0,
121
+ v: params.v ?? 0
122
+ });
123
+ var validateXyTranslateParams = (params) => {
124
+ assertEffectParamsObject(params, "xyTranslate");
125
+ assertOptionalFiniteNumber(params.x, "x");
126
+ assertOptionalFiniteNumber(params.y, "y");
127
+ };
128
+ var validateUvTranslateParams = (params) => {
129
+ assertEffectParamsObject(params, "uvTranslate");
130
+ assertOptionalFiniteNumber(params.u, "u");
131
+ assertOptionalFiniteNumber(params.v, "v");
132
+ };
133
+ var applyTranslate = ({
134
+ source,
135
+ target,
136
+ width,
137
+ height,
138
+ x,
139
+ y
140
+ }) => {
141
+ const ctx = target.getContext("2d");
142
+ if (!ctx) {
143
+ throw new Error("Failed to acquire 2D context for translate effect. The canvas may have been assigned a different context type.");
144
+ }
145
+ ctx.clearRect(0, 0, width, height);
146
+ ctx.drawImage(source, x, y, width, height);
147
+ };
148
+ var xyTranslate = createEffect({
149
+ type: "remotion/xy-translate",
150
+ label: "XY Translate",
151
+ documentationLink: "https://www.remotion.dev/docs/effects/xy-translate",
152
+ backend: "2d",
153
+ calculateKey: (params) => {
154
+ const r = resolveXyTranslate(params);
155
+ return `xy-translate-${r.x}-${r.y}`;
156
+ },
157
+ setup: () => null,
158
+ apply: ({ source, target, width, height, params }) => {
159
+ const r = resolveXyTranslate(params);
160
+ applyTranslate({
161
+ source,
162
+ target,
163
+ width,
164
+ height,
165
+ x: r.x,
166
+ y: r.y
167
+ });
168
+ },
169
+ cleanup: () => {
170
+ return;
171
+ },
172
+ schema: xyTranslateSchema,
173
+ validateParams: validateXyTranslateParams
174
+ });
175
+ var uvTranslate = createEffect({
176
+ type: "remotion/uv-translate",
177
+ label: "UV Translate",
178
+ documentationLink: "https://www.remotion.dev/docs/effects/uv-translate",
179
+ backend: "2d",
180
+ calculateKey: (params) => {
181
+ const r = resolveUvTranslate(params);
182
+ return `uv-translate-${r.u}-${r.v}`;
183
+ },
184
+ setup: () => null,
185
+ apply: ({ source, target, width, height, params }) => {
186
+ const r = resolveUvTranslate(params);
187
+ applyTranslate({
188
+ source,
189
+ target,
190
+ width,
191
+ height,
192
+ x: r.u * width,
193
+ y: r.v * height
194
+ });
195
+ },
196
+ cleanup: () => {
197
+ return;
198
+ },
199
+ schema: uvTranslateSchema,
200
+ validateParams: validateUvTranslateParams
201
+ });
202
+ export {
203
+ xyTranslate,
204
+ uvTranslate
205
+ };
@@ -1,5 +1,6 @@
1
1
  declare const HALFTONE_SHAPES: readonly ["circle", "square", "line"];
2
2
  declare const HALFTONE_SAMPLING: readonly ["bilinear", "nearest"];
3
+ declare const HALFTONE_COLOR_MODES: readonly ["solid", "source"];
3
4
  export declare const halftoneSchema: {
4
5
  readonly dotSize: {
5
6
  readonly type: "number";
@@ -52,15 +53,26 @@ export declare const halftoneSchema: {
52
53
  readonly default: false;
53
54
  readonly description: "Invert";
54
55
  };
55
- readonly color: {
56
- readonly type: "color";
57
- readonly default: "black";
58
- readonly description: "Color";
56
+ readonly colorMode: {
57
+ readonly type: "enum";
58
+ readonly default: "solid";
59
+ readonly description: "Color mode";
60
+ readonly variants: {
61
+ readonly solid: {
62
+ readonly dotColor: {
63
+ readonly type: "color";
64
+ readonly default: "red";
65
+ readonly description: "Dot color";
66
+ };
67
+ };
68
+ readonly source: {};
69
+ };
59
70
  };
60
71
  };
61
72
  export type HalftoneShape = (typeof HALFTONE_SHAPES)[number];
62
73
  export type HalftoneSampling = (typeof HALFTONE_SAMPLING)[number];
63
- export type HalftoneParams = {
74
+ export type HalftoneColorMode = (typeof HALFTONE_COLOR_MODES)[number];
75
+ type HalftoneCommonParams = {
64
76
  readonly shape?: HalftoneShape;
65
77
  readonly dotSize?: number;
66
78
  /**
@@ -72,8 +84,6 @@ export type HalftoneParams = {
72
84
  readonly offsetX?: number;
73
85
  readonly offsetY?: number;
74
86
  readonly sampling?: HalftoneSampling;
75
- /** Dot color. Defaults to black. */
76
- readonly color?: string;
77
87
  /**
78
88
  * When false (default), dark areas produce larger dots.
79
89
  * When true, the pattern is inverted:
@@ -81,6 +91,13 @@ export type HalftoneParams = {
81
91
  */
82
92
  readonly invert?: boolean;
83
93
  };
94
+ export type HalftoneParams = HalftoneCommonParams & ({
95
+ readonly colorMode?: 'solid';
96
+ /** Dot color. Defaults to red. */
97
+ readonly dotColor?: string;
98
+ } | {
99
+ readonly colorMode: 'source';
100
+ });
84
101
  export declare const halftone: (params?: (HalftoneParams & {
85
102
  readonly disabled?: boolean | undefined;
86
103
  }) | undefined) => import("remotion").EffectDescriptor<unknown>;
@@ -0,0 +1,18 @@
1
+ export type XyTranslateParams = {
2
+ /** Horizontal offset in pixels. Defaults to `0`. */
3
+ readonly x?: number;
4
+ /** Vertical offset in pixels. Defaults to `0`. */
5
+ readonly y?: number;
6
+ };
7
+ export type UvTranslateParams = {
8
+ /** Horizontal offset in UV coordinates. `1` equals the full canvas width. Defaults to `0`. */
9
+ readonly u?: number;
10
+ /** Vertical offset in UV coordinates. `1` equals the full canvas height. Defaults to `0`. */
11
+ readonly v?: number;
12
+ };
13
+ export declare const xyTranslate: (params?: (XyTranslateParams & {
14
+ readonly disabled?: boolean | undefined;
15
+ }) | undefined) => import("remotion").EffectDescriptor<unknown>;
16
+ export declare const uvTranslate: (params?: (UvTranslateParams & {
17
+ readonly disabled?: boolean | undefined;
18
+ }) | undefined) => import("remotion").EffectDescriptor<unknown>;
@@ -0,0 +1 @@
1
+ export { uvTranslate, xyTranslate, type UvTranslateParams, type XyTranslateParams, } from './translate/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/effects",
3
- "version": "4.0.466",
3
+ "version": "4.0.467",
4
4
  "description": "Effects that can be applied to Remotion-based canvas components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "url": "https://github.com/remotion-dev/remotion/issues"
25
25
  },
26
26
  "dependencies": {
27
- "remotion": "4.0.466"
27
+ "remotion": "4.0.467"
28
28
  },
29
29
  "exports": {
30
30
  ".": {
@@ -42,11 +42,21 @@
42
42
  "module": "./dist/esm/blur.mjs",
43
43
  "import": "./dist/esm/blur.mjs"
44
44
  },
45
+ "./chromatic-aberration": {
46
+ "types": "./dist/chromatic-aberration.d.ts",
47
+ "module": "./dist/esm/chromatic-aberration.mjs",
48
+ "import": "./dist/esm/chromatic-aberration.mjs"
49
+ },
45
50
  "./brightness": {
46
51
  "types": "./dist/brightness.d.ts",
47
52
  "module": "./dist/esm/brightness.mjs",
48
53
  "import": "./dist/esm/brightness.mjs"
49
54
  },
55
+ "./contrast": {
56
+ "types": "./dist/contrast.d.ts",
57
+ "module": "./dist/esm/contrast.mjs",
58
+ "import": "./dist/esm/contrast.mjs"
59
+ },
50
60
  "./halftone": {
51
61
  "types": "./dist/halftone.d.ts",
52
62
  "module": "./dist/esm/halftone.mjs",
@@ -87,6 +97,11 @@
87
97
  "module": "./dist/esm/tint.mjs",
88
98
  "import": "./dist/esm/tint.mjs"
89
99
  },
100
+ "./translate": {
101
+ "types": "./dist/translate.d.ts",
102
+ "module": "./dist/esm/translate.mjs",
103
+ "import": "./dist/esm/translate.mjs"
104
+ },
90
105
  "./wave": {
91
106
  "types": "./dist/wave.d.ts",
92
107
  "module": "./dist/esm/wave.mjs",
@@ -102,9 +117,15 @@
102
117
  "blur": [
103
118
  "dist/blur.d.ts"
104
119
  ],
120
+ "chromatic-aberration": [
121
+ "dist/chromatic-aberration.d.ts"
122
+ ],
105
123
  "brightness": [
106
124
  "dist/brightness.d.ts"
107
125
  ],
126
+ "contrast": [
127
+ "dist/contrast.d.ts"
128
+ ],
108
129
  "halftone": [
109
130
  "dist/halftone.d.ts"
110
131
  ],
@@ -129,6 +150,9 @@
129
150
  "tint": [
130
151
  "dist/tint.d.ts"
131
152
  ],
153
+ "translate": [
154
+ "dist/translate.d.ts"
155
+ ],
132
156
  "wave": [
133
157
  "dist/wave.d.ts"
134
158
  ]
@@ -136,7 +160,7 @@
136
160
  },
137
161
  "homepage": "https://www.remotion.dev/docs/effects/api",
138
162
  "devDependencies": {
139
- "@remotion/eslint-config-internal": "4.0.466",
163
+ "@remotion/eslint-config-internal": "4.0.467",
140
164
  "eslint": "9.19.0",
141
165
  "@typescript/native-preview": "7.0.0-dev.20260217.1"
142
166
  },