@remotion/effects 4.0.464 → 4.0.466

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.
Files changed (40) hide show
  1. package/README.md +13 -2
  2. package/dist/barrel-distortion/barrel-distortion-runtime.d.ts +21 -0
  3. package/dist/barrel-distortion/barrel-distortion-shaders.d.ts +2 -0
  4. package/dist/barrel-distortion/index.d.ts +7 -0
  5. package/dist/barrel-distortion.d.ts +1 -0
  6. package/dist/blur/blur-runtime.d.ts +4 -1
  7. package/dist/blur/index.d.ts +4 -0
  8. package/dist/blur.d.ts +1 -0
  9. package/dist/brightness.d.ts +7 -0
  10. package/dist/color-utils.d.ts +37 -0
  11. package/dist/effect-internals.d.ts +8 -0
  12. package/dist/esm/barrel-distortion.mjs +329 -0
  13. package/dist/esm/blur.mjs +107 -44
  14. package/dist/esm/brightness.mjs +138 -0
  15. package/dist/esm/grayscale.mjs +128 -0
  16. package/dist/esm/halftone.mjs +150 -20
  17. package/dist/esm/hue.mjs +126 -0
  18. package/dist/esm/index.mjs +0 -1
  19. package/dist/esm/invert.mjs +128 -0
  20. package/dist/esm/mirror.mjs +358 -0
  21. package/dist/esm/saturation.mjs +128 -0
  22. package/dist/esm/scale.mjs +103 -0
  23. package/dist/esm/tint.mjs +72 -14
  24. package/dist/esm/wave.mjs +289 -55
  25. package/dist/grayscale.d.ts +7 -0
  26. package/dist/halftone.d.ts +19 -7
  27. package/dist/hue.d.ts +7 -0
  28. package/dist/invert.d.ts +7 -0
  29. package/dist/mirror/index.d.ts +13 -0
  30. package/dist/mirror/mirror-runtime.d.ts +26 -0
  31. package/dist/mirror/mirror-shaders.d.ts +2 -0
  32. package/dist/mirror.d.ts +1 -0
  33. package/dist/saturation.d.ts +7 -0
  34. package/dist/scale/index.d.ts +11 -0
  35. package/dist/scale.d.ts +1 -0
  36. package/dist/wave/index.d.ts +12 -0
  37. package/dist/wave/wave-runtime.d.ts +29 -0
  38. package/dist/wave/wave-shaders.d.ts +2 -0
  39. package/dist/wave.d.ts +1 -46
  40. package/package.json +77 -12
@@ -0,0 +1,128 @@
1
+ // src/invert.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/invert.ts
86
+ var { createEffect } = Internals;
87
+ var invertSchema = {
88
+ amount: colorAmountSchema
89
+ };
90
+ var resolve = (p) => ({
91
+ amount: p.amount ?? DEFAULT_AMOUNT
92
+ });
93
+ var validateInvertParams = (params) => {
94
+ assertEffectParamsObject(params, "Invert");
95
+ assertOptionalFiniteNumber(params.amount, "amount");
96
+ const { amount } = resolve(params);
97
+ validateUnitInterval(amount, "amount");
98
+ };
99
+ var invert = createEffect({
100
+ type: "remotion/invert",
101
+ label: "Invert",
102
+ documentationLink: "https://www.remotion.dev/docs/effects/invert",
103
+ backend: "2d",
104
+ calculateKey: (params) => {
105
+ const r = resolve(params);
106
+ return `invert-${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 invert 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.filter = `invert(${r.amount * 100}%)`;
117
+ ctx.drawImage(source, 0, 0, width, height);
118
+ ctx.filter = "none";
119
+ },
120
+ cleanup: () => {
121
+ return;
122
+ },
123
+ schema: invertSchema,
124
+ validateParams: validateInvertParams
125
+ });
126
+ export {
127
+ invert
128
+ };
@@ -0,0 +1,358 @@
1
+ // src/mirror/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/mirror/mirror-runtime.ts
86
+ import { Internals } from "remotion";
87
+
88
+ // src/mirror/mirror-shaders.ts
89
+ var MIRROR_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 MIRROR_FS = `#version 300 es
99
+ precision highp float;
100
+ in vec2 vUv;
101
+ out vec4 fragColor;
102
+
103
+ uniform sampler2D uSource;
104
+ uniform float uPosition;
105
+ uniform int uDirection;
106
+ uniform bool uInvert;
107
+
108
+ void main() {
109
+ vec2 srcUv = vUv;
110
+ float coord = uDirection == 0 ? vUv.x : vUv.y;
111
+ bool shouldMirror = uInvert ? coord < uPosition : coord > uPosition;
112
+
113
+ if (shouldMirror) {
114
+ float mirrored = 2.0 * uPosition - coord;
115
+ if (uDirection == 0) {
116
+ srcUv.x = mirrored;
117
+ } else {
118
+ srcUv.y = mirrored;
119
+ }
120
+ }
121
+
122
+ fragColor = texture(uSource, clamp(srcUv, vec2(0.0), vec2(1.0)));
123
+ }
124
+ `;
125
+
126
+ // src/mirror/mirror-runtime.ts
127
+ var { createWebGL2ContextError } = Internals;
128
+ var compileShader = (gl, type, source) => {
129
+ const shader = gl.createShader(type);
130
+ if (!shader) {
131
+ throw new Error("Failed to create WebGL shader");
132
+ }
133
+ gl.shaderSource(shader, source);
134
+ gl.compileShader(shader);
135
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
136
+ const log = gl.getShaderInfoLog(shader);
137
+ gl.deleteShader(shader);
138
+ throw new Error(`Shader compile failed: ${log ?? "(no log)"}`);
139
+ }
140
+ return shader;
141
+ };
142
+ var linkProgram = (gl, vs, fs) => {
143
+ const program = gl.createProgram();
144
+ if (!program) {
145
+ throw new Error("Failed to create WebGL program");
146
+ }
147
+ gl.attachShader(program, vs);
148
+ gl.attachShader(program, fs);
149
+ gl.linkProgram(program);
150
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
151
+ const log = gl.getProgramInfoLog(program);
152
+ gl.deleteProgram(program);
153
+ throw new Error(`Program link failed: ${log ?? "(no log)"}`);
154
+ }
155
+ return program;
156
+ };
157
+ var createProgram = (gl, vertexSource, fragmentSource) => {
158
+ const vs = compileShader(gl, gl.VERTEX_SHADER, vertexSource);
159
+ const fs = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
160
+ const program = linkProgram(gl, vs, fs);
161
+ gl.deleteShader(vs);
162
+ gl.deleteShader(fs);
163
+ return program;
164
+ };
165
+ var createRgbaTexture = (gl) => {
166
+ const texture = gl.createTexture();
167
+ if (!texture) {
168
+ throw new Error("Failed to create WebGL texture");
169
+ }
170
+ gl.bindTexture(gl.TEXTURE_2D, texture);
171
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
172
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
173
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
174
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
175
+ gl.bindTexture(gl.TEXTURE_2D, null);
176
+ return texture;
177
+ };
178
+ var setupMirror = (target) => {
179
+ const gl = target.getContext("webgl2", {
180
+ premultipliedAlpha: true,
181
+ alpha: true,
182
+ preserveDrawingBuffer: true
183
+ });
184
+ if (!gl) {
185
+ throw createWebGL2ContextError("mirror effect");
186
+ }
187
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
188
+ const program = createProgram(gl, MIRROR_VS, MIRROR_FS);
189
+ const vao = gl.createVertexArray();
190
+ if (!vao) {
191
+ throw new Error("Failed to create WebGL vertex array");
192
+ }
193
+ gl.bindVertexArray(vao);
194
+ const data = new Float32Array([
195
+ -1,
196
+ -1,
197
+ 0,
198
+ 0,
199
+ 1,
200
+ -1,
201
+ 1,
202
+ 0,
203
+ -1,
204
+ 1,
205
+ 0,
206
+ 1,
207
+ 1,
208
+ 1,
209
+ 1,
210
+ 1
211
+ ]);
212
+ const vbo = gl.createBuffer();
213
+ if (!vbo) {
214
+ throw new Error("Failed to create WebGL buffer");
215
+ }
216
+ gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
217
+ gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
218
+ gl.enableVertexAttribArray(0);
219
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 16, 0);
220
+ gl.enableVertexAttribArray(1);
221
+ gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 16, 8);
222
+ gl.bindVertexArray(null);
223
+ const textureSource = createRgbaTexture(gl);
224
+ return {
225
+ gl,
226
+ program,
227
+ vao,
228
+ vbo,
229
+ textureSource,
230
+ uniforms: {
231
+ uSource: gl.getUniformLocation(program, "uSource"),
232
+ uPosition: gl.getUniformLocation(program, "uPosition"),
233
+ uDirection: gl.getUniformLocation(program, "uDirection"),
234
+ uInvert: gl.getUniformLocation(program, "uInvert")
235
+ }
236
+ };
237
+ };
238
+ var cleanupMirror = (state) => {
239
+ const { gl, program, vao, vbo, textureSource } = state;
240
+ gl.deleteTexture(textureSource);
241
+ gl.deleteBuffer(vbo);
242
+ gl.deleteProgram(program);
243
+ gl.deleteVertexArray(vao);
244
+ };
245
+ var drawFullscreenQuad = (state) => {
246
+ const { gl, vao } = state;
247
+ gl.bindVertexArray(vao);
248
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
249
+ gl.bindVertexArray(null);
250
+ };
251
+ var applyMirror = ({
252
+ state,
253
+ source,
254
+ width,
255
+ height,
256
+ position,
257
+ direction,
258
+ invert,
259
+ flipSourceY
260
+ }) => {
261
+ const { gl, program, textureSource, uniforms } = state;
262
+ gl.viewport(0, 0, width, height);
263
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);
264
+ gl.bindTexture(gl.TEXTURE_2D, textureSource);
265
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
266
+ gl.bindTexture(gl.TEXTURE_2D, null);
267
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
268
+ gl.clearColor(0, 0, 0, 0);
269
+ gl.clear(gl.COLOR_BUFFER_BIT);
270
+ gl.useProgram(program);
271
+ if (uniforms.uSource)
272
+ gl.uniform1i(uniforms.uSource, 0);
273
+ if (uniforms.uPosition)
274
+ gl.uniform1f(uniforms.uPosition, position);
275
+ if (uniforms.uDirection)
276
+ gl.uniform1i(uniforms.uDirection, direction === "horizontal" ? 0 : 1);
277
+ if (uniforms.uInvert)
278
+ gl.uniform1i(uniforms.uInvert, invert ? 1 : 0);
279
+ gl.activeTexture(gl.TEXTURE0);
280
+ gl.bindTexture(gl.TEXTURE_2D, textureSource);
281
+ drawFullscreenQuad(state);
282
+ gl.bindTexture(gl.TEXTURE_2D, null);
283
+ gl.useProgram(null);
284
+ };
285
+
286
+ // src/mirror/index.ts
287
+ var { createEffect } = Internals2;
288
+ var mirrorSchema = {
289
+ direction: {
290
+ type: "enum",
291
+ variants: {
292
+ horizontal: {},
293
+ vertical: {}
294
+ },
295
+ default: "horizontal",
296
+ description: "Direction"
297
+ },
298
+ position: {
299
+ type: "number",
300
+ min: 0,
301
+ max: 1,
302
+ step: 0.01,
303
+ default: 0.5,
304
+ description: "Position"
305
+ },
306
+ invert: {
307
+ type: "boolean",
308
+ default: false,
309
+ description: "Invert"
310
+ }
311
+ };
312
+ var resolve = (p) => ({
313
+ direction: p.direction ?? "horizontal",
314
+ position: p.position ?? 0.5,
315
+ invert: p.invert ?? false
316
+ });
317
+ var validateMirrorParams = (params) => {
318
+ assertEffectParamsObject(params, "Mirror");
319
+ assertOptionalFiniteNumber(params.position, "position");
320
+ if (params.direction !== undefined && params.direction !== "horizontal" && params.direction !== "vertical") {
321
+ throw new TypeError(`"direction" must be "horizontal" or "vertical", but got ${JSON.stringify(params.direction)}`);
322
+ }
323
+ if (params.invert !== undefined && typeof params.invert !== "boolean") {
324
+ throw new TypeError(`"invert" must be a boolean, but got ${JSON.stringify(params.invert)}`);
325
+ }
326
+ const { position } = resolve(params);
327
+ validateUnitInterval(position, "position");
328
+ };
329
+ var mirror = createEffect({
330
+ type: "remotion/mirror",
331
+ label: "Mirror",
332
+ documentationLink: "https://www.remotion.dev/docs/effects/mirror",
333
+ backend: "webgl2",
334
+ calculateKey: (params) => {
335
+ const r = resolve(params);
336
+ return `mirror-${r.direction}-${r.position}-${r.invert ? 1 : 0}`;
337
+ },
338
+ setup: (target) => setupMirror(target),
339
+ apply: ({ source, width, height, params, state, flipSourceY }) => {
340
+ const r = resolve(params);
341
+ applyMirror({
342
+ state,
343
+ source,
344
+ width,
345
+ height,
346
+ position: r.position,
347
+ direction: r.direction,
348
+ invert: r.invert,
349
+ flipSourceY
350
+ });
351
+ },
352
+ cleanup: (state) => cleanupMirror(state),
353
+ schema: mirrorSchema,
354
+ validateParams: validateMirrorParams
355
+ });
356
+ export {
357
+ mirror
358
+ };
@@ -0,0 +1,128 @@
1
+ // src/saturation.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/saturation.ts
86
+ var { createEffect } = Internals;
87
+ var saturationSchema = {
88
+ amount: colorMultiplierSchema
89
+ };
90
+ var resolve = (p) => ({
91
+ amount: p.amount ?? DEFAULT_AMOUNT
92
+ });
93
+ var validateSaturationParams = (params) => {
94
+ assertEffectParamsObject(params, "Saturation");
95
+ assertOptionalFiniteNumber(params.amount, "amount");
96
+ const { amount } = resolve(params);
97
+ validateNonNegative(amount, "amount");
98
+ };
99
+ var saturation = createEffect({
100
+ type: "remotion/saturation",
101
+ label: "Saturation",
102
+ documentationLink: "https://www.remotion.dev/docs/effects/saturation",
103
+ backend: "2d",
104
+ calculateKey: (params) => {
105
+ const r = resolve(params);
106
+ return `saturation-${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 saturation 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.filter = `saturate(${r.amount * 100}%)`;
117
+ ctx.drawImage(source, 0, 0, width, height);
118
+ ctx.filter = "none";
119
+ },
120
+ cleanup: () => {
121
+ return;
122
+ },
123
+ schema: saturationSchema,
124
+ validateParams: validateSaturationParams
125
+ });
126
+ export {
127
+ saturation
128
+ };
@@ -0,0 +1,103 @@
1
+ // src/scale/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/scale/index.ts
22
+ var { createEffect } = Internals;
23
+ var scaleSchema = {
24
+ scale: {
25
+ type: "number",
26
+ min: 0.1,
27
+ max: 10,
28
+ step: 0.1,
29
+ default: 1,
30
+ description: "Factor"
31
+ },
32
+ horizontal: {
33
+ type: "boolean",
34
+ default: true,
35
+ description: "Horizontal"
36
+ },
37
+ vertical: {
38
+ type: "boolean",
39
+ default: true,
40
+ description: "Vertical"
41
+ }
42
+ };
43
+ var resolve = (p) => ({
44
+ scale: p.scale,
45
+ horizontal: p.horizontal ?? true,
46
+ vertical: p.vertical ?? true
47
+ });
48
+ var validateScaleParams = (params) => {
49
+ assertEffectParamsObject(params, "Scale");
50
+ assertRequiredFiniteNumber(params.scale, "scale");
51
+ if (typeof params.horizontal !== "undefined" && typeof params.horizontal !== "boolean") {
52
+ throw new TypeError(`"horizontal" must be a boolean, but got ${JSON.stringify(params.horizontal)}`);
53
+ }
54
+ if (typeof params.vertical !== "undefined" && typeof params.vertical !== "boolean") {
55
+ throw new TypeError(`"vertical" must be a boolean, but got ${JSON.stringify(params.vertical)}`);
56
+ }
57
+ const resolved = resolve(params);
58
+ if (resolved.scale <= 0) {
59
+ throw new TypeError(`"scale" must be greater than 0, but got ${JSON.stringify(resolved.scale)}`);
60
+ }
61
+ };
62
+ var scale = createEffect({
63
+ type: "remotion/scale",
64
+ label: "Scale",
65
+ documentationLink: "https://www.remotion.dev/docs/effects/scale",
66
+ backend: "2d",
67
+ calculateKey: (params) => {
68
+ const r = resolve(params);
69
+ return `scale-${r.scale}-${r.horizontal}-${r.vertical}`;
70
+ },
71
+ setup: () => null,
72
+ apply: ({ source, target, width, height, params }) => {
73
+ const ctx = target.getContext("2d");
74
+ if (!ctx) {
75
+ throw new Error("Failed to acquire 2D context for scale effect. The canvas may have been assigned a different context type.");
76
+ }
77
+ const r = resolve(params);
78
+ const scaleX = r.horizontal ? r.scale : 1;
79
+ const scaleY = r.vertical ? r.scale : 1;
80
+ if (scaleX === 1 && scaleY === 1) {
81
+ ctx.clearRect(0, 0, width, height);
82
+ ctx.drawImage(source, 0, 0, width, height);
83
+ return;
84
+ }
85
+ ctx.clearRect(0, 0, width, height);
86
+ ctx.save();
87
+ const centerX = width / 2;
88
+ const centerY = height / 2;
89
+ ctx.translate(centerX, centerY);
90
+ ctx.scale(scaleX, scaleY);
91
+ ctx.translate(-centerX, -centerY);
92
+ ctx.drawImage(source, 0, 0, width, height);
93
+ ctx.restore();
94
+ },
95
+ cleanup: () => {
96
+ return;
97
+ },
98
+ schema: scaleSchema,
99
+ validateParams: validateScaleParams
100
+ });
101
+ export {
102
+ scale
103
+ };