@remotion/effects 4.0.463 → 4.0.465

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.
package/README.md CHANGED
@@ -1,7 +1,18 @@
1
1
  # @remotion/effects
2
2
 
3
- Experimental presets for Remotion canvas effect hooks
3
+ Effects that can be applied to Remotion-based canvas components
4
+
5
+ [![NPM Downloads](https://img.shields.io/npm/dm/@remotion/effects.svg?style=flat&color=black&label=Downloads)](https://npmcharts.com/compare/@remotion/effects?minimal=true)
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @remotion/effects --save-exact
11
+ ```
12
+
13
+ When installing a Remotion package, make sure to align the version of all `remotion` and `@remotion/*` packages to the same version.
14
+ Remove the `^` character from the version number to use the exact version.
4
15
 
5
16
  ## Usage
6
17
 
7
- This is an internal package and has no documentation.
18
+ See the [documentation](https://www.remotion.dev/docs/effects/api) for more information.
@@ -26,6 +26,9 @@ type ApplyBlurParams = {
26
26
  readonly width: number;
27
27
  readonly height: number;
28
28
  readonly radius: number;
29
+ readonly horizontal: boolean;
30
+ readonly vertical: boolean;
31
+ readonly flipSourceY: boolean;
29
32
  };
30
- export declare const applyBlur: ({ state, source, width, height, radius, }: ApplyBlurParams) => void;
33
+ export declare const applyBlur: ({ state, source, width, height, radius, horizontal, vertical, flipSourceY, }: ApplyBlurParams) => void;
31
34
  export {};
@@ -1,5 +1,9 @@
1
1
  export type BlurParams = {
2
2
  readonly radius: number;
3
+ /** Apply blur along the horizontal axis. Defaults to `true`. */
4
+ readonly horizontal?: boolean;
5
+ /** Apply blur along the vertical axis. Defaults to `true`. */
6
+ readonly vertical?: boolean;
3
7
  };
4
8
  export declare const blur: (params: BlurParams & {
5
9
  readonly disabled?: boolean | undefined;
package/dist/blur.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { blur, type BlurParams } from './blur/index.js';
@@ -0,0 +1,8 @@
1
+ export declare const EffectInternals: {
2
+ readonly halftone: (params?: (import("./halftone.js").HalftoneParams & {
3
+ readonly disabled?: boolean | undefined;
4
+ }) | undefined) => import("remotion").EffectDescriptor<unknown>;
5
+ readonly tint: (params: import("./tint.js").TintParams & {
6
+ readonly disabled?: boolean | undefined;
7
+ }) => import("remotion").EffectDescriptor<unknown>;
8
+ };
package/dist/esm/blur.mjs CHANGED
@@ -1,23 +1,24 @@
1
- var __defProp = Object.defineProperty;
2
- var __returnValue = (v) => v;
3
- function __exportSetter(name, newValue) {
4
- this[name] = __returnValue.bind(null, newValue);
5
- }
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true,
11
- configurable: true,
12
- set: __exportSetter.bind(all, name)
13
- });
1
+ // src/blur/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
+ }
14
19
  };
15
20
 
16
- // src/blur/index.ts
17
- var exports_blur = {};
18
- __export(exports_blur, {
19
- blur: () => blur
20
- });
21
+ // src/blur/blur-runtime.ts
21
22
  import { Internals } from "remotion";
22
23
 
23
24
  // src/blur/blur-shaders.ts
@@ -73,6 +74,7 @@ var BLUR_FS_HORIZONTAL = buildFs("horizontal");
73
74
  var BLUR_FS_VERTICAL = buildFs("vertical");
74
75
 
75
76
  // src/blur/blur-runtime.ts
77
+ var { createWebGL2ContextError } = Internals;
76
78
  var compileShader = (gl, type, source) => {
77
79
  const shader = gl.createShader(type);
78
80
  if (!shader) {
@@ -135,10 +137,9 @@ var setupBlur = (target) => {
135
137
  preserveDrawingBuffer: true
136
138
  });
137
139
  if (!gl) {
138
- throw new Error("Failed to acquire WebGL2 context for blur effect");
140
+ throw createWebGL2ContextError("blur effect");
139
141
  }
140
142
  gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
141
- gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
142
143
  const programHorizontal = createProgram(gl, BLUR_VS, BLUR_FS_HORIZONTAL);
143
144
  const programVertical = createProgram(gl, BLUR_VS, BLUR_FS_VERTICAL);
144
145
  const vao = gl.createVertexArray();
@@ -245,12 +246,31 @@ var drawFullscreenQuad = (state) => {
245
246
  gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
246
247
  gl.bindVertexArray(null);
247
248
  };
249
+ var uploadBlurSource = ({
250
+ gl,
251
+ textureSource,
252
+ source,
253
+ textureIntermediate,
254
+ width,
255
+ height,
256
+ flipSourceY
257
+ }) => {
258
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipSourceY);
259
+ gl.bindTexture(gl.TEXTURE_2D, textureSource);
260
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
261
+ gl.bindTexture(gl.TEXTURE_2D, textureIntermediate);
262
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
263
+ gl.bindTexture(gl.TEXTURE_2D, null);
264
+ };
248
265
  var applyBlur = ({
249
266
  state,
250
267
  source,
251
268
  width,
252
269
  height,
253
- radius
270
+ radius,
271
+ horizontal,
272
+ vertical,
273
+ flipSourceY
254
274
  }) => {
255
275
  const {
256
276
  gl,
@@ -261,32 +281,72 @@ var applyBlur = ({
261
281
  framebuffer
262
282
  } = state;
263
283
  gl.viewport(0, 0, width, height);
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, textureIntermediate);
267
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
268
- gl.bindTexture(gl.TEXTURE_2D, null);
269
- gl.clearColor(0, 0, 0, 0);
270
- gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
271
- gl.clear(gl.COLOR_BUFFER_BIT);
272
- gl.activeTexture(gl.TEXTURE0);
273
- gl.bindTexture(gl.TEXTURE_2D, textureSource);
274
- gl.useProgram(programHorizontal);
275
- setBlurUniforms({
284
+ uploadBlurSource({
276
285
  gl,
277
- uniforms: state.horizontal,
278
- radius,
286
+ textureSource,
287
+ source,
288
+ textureIntermediate,
279
289
  width,
280
- height
290
+ height,
291
+ flipSourceY
281
292
  });
282
- drawFullscreenQuad(state);
293
+ gl.clearColor(0, 0, 0, 0);
294
+ if (!horizontal && !vertical) {
295
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
296
+ gl.clear(gl.COLOR_BUFFER_BIT);
297
+ gl.activeTexture(gl.TEXTURE0);
298
+ gl.bindTexture(gl.TEXTURE_2D, textureSource);
299
+ gl.useProgram(programVertical);
300
+ setBlurUniforms({
301
+ gl,
302
+ uniforms: state.vertical,
303
+ radius: 0,
304
+ width,
305
+ height
306
+ });
307
+ drawFullscreenQuad(state);
308
+ gl.bindTexture(gl.TEXTURE_2D, null);
309
+ gl.useProgram(null);
310
+ return;
311
+ }
312
+ if (horizontal && vertical) {
313
+ gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
314
+ gl.clear(gl.COLOR_BUFFER_BIT);
315
+ gl.activeTexture(gl.TEXTURE0);
316
+ gl.bindTexture(gl.TEXTURE_2D, textureSource);
317
+ gl.useProgram(programHorizontal);
318
+ setBlurUniforms({
319
+ gl,
320
+ uniforms: state.horizontal,
321
+ radius,
322
+ width,
323
+ height
324
+ });
325
+ drawFullscreenQuad(state);
326
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
327
+ gl.clear(gl.COLOR_BUFFER_BIT);
328
+ gl.bindTexture(gl.TEXTURE_2D, textureIntermediate);
329
+ gl.useProgram(programVertical);
330
+ setBlurUniforms({
331
+ gl,
332
+ uniforms: state.vertical,
333
+ radius,
334
+ width,
335
+ height
336
+ });
337
+ drawFullscreenQuad(state);
338
+ gl.bindTexture(gl.TEXTURE_2D, null);
339
+ gl.useProgram(null);
340
+ return;
341
+ }
283
342
  gl.bindFramebuffer(gl.FRAMEBUFFER, null);
284
343
  gl.clear(gl.COLOR_BUFFER_BIT);
285
- gl.bindTexture(gl.TEXTURE_2D, textureIntermediate);
286
- gl.useProgram(programVertical);
344
+ gl.activeTexture(gl.TEXTURE0);
345
+ gl.bindTexture(gl.TEXTURE_2D, textureSource);
346
+ gl.useProgram(horizontal ? programHorizontal : programVertical);
287
347
  setBlurUniforms({
288
348
  gl,
289
- uniforms: state.vertical,
349
+ uniforms: horizontal ? state.horizontal : state.vertical,
290
350
  radius,
291
351
  width,
292
352
  height
@@ -297,38 +357,62 @@ var applyBlur = ({
297
357
  };
298
358
 
299
359
  // src/blur/index.ts
300
- var { createEffect } = Internals;
360
+ var { createEffect } = Internals2;
361
+ var resolveBlurParams = (params) => ({
362
+ radius: params.radius,
363
+ horizontal: params.horizontal ?? true,
364
+ vertical: params.vertical ?? true
365
+ });
301
366
  var blurSchema = {
302
367
  radius: {
303
368
  type: "number",
304
369
  min: 0,
305
370
  max: 100,
306
371
  step: 1,
307
- default: 10,
308
- description: "Blur radius"
372
+ default: undefined,
373
+ description: "Blur"
374
+ },
375
+ horizontal: {
376
+ type: "boolean",
377
+ default: true,
378
+ description: "Horizontal"
379
+ },
380
+ vertical: {
381
+ type: "boolean",
382
+ default: true,
383
+ description: "Vertical"
309
384
  }
310
385
  };
386
+ var validateBlurParams = (params) => {
387
+ assertEffectParamsObject(params, "Blur");
388
+ assertRequiredFiniteNumber(params.radius, "radius");
389
+ };
311
390
  var blur = createEffect({
312
391
  type: "remotion/blur",
313
392
  label: "Blur",
314
393
  backend: "webgl2",
315
- calculateKey: (params) => String(params.radius),
394
+ calculateKey: (params) => {
395
+ const r = resolveBlurParams(params);
396
+ return `${r.radius}-${r.horizontal ? 1 : 0}-${r.vertical ? 1 : 0}`;
397
+ },
316
398
  setup: (target) => setupBlur(target),
317
- apply: ({ source, width, height, params, state }) => {
399
+ apply: ({ source, width, height, params, state, flipSourceY }) => {
400
+ const r = resolveBlurParams(params);
318
401
  applyBlur({
319
402
  state,
320
403
  source,
321
404
  width,
322
405
  height,
323
- radius: params.radius
406
+ radius: r.radius,
407
+ horizontal: r.horizontal,
408
+ vertical: r.vertical,
409
+ flipSourceY
324
410
  });
325
411
  },
326
412
  cleanup: (state) => cleanupBlur(state),
327
- schema: blurSchema
413
+ schema: blurSchema,
414
+ validateParams: validateBlurParams
328
415
  });
329
-
330
- // src/entrypoints/blur.ts
331
- var { blur: blur2 } = exports_blur;
332
416
  export {
333
- blur2 as blur
417
+ blur
334
418
  };
@@ -1,21 +1,17 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __returnValue = (v) => v;
3
- function __exportSetter(name, newValue) {
4
- this[name] = __returnValue.bind(null, newValue);
5
- }
6
2
  var __export = (target, all) => {
7
3
  for (var name in all)
8
4
  __defProp(target, name, {
9
5
  get: all[name],
10
6
  enumerable: true,
11
7
  configurable: true,
12
- set: __exportSetter.bind(all, name)
8
+ set: (newValue) => all[name] = () => newValue
13
9
  });
14
10
  };
15
11
 
16
12
  // src/halftone.ts
17
13
  import { Internals } from "remotion";
18
- var { createEffect } = Internals;
14
+ var { createEffect, createWebGL2ContextError } = Internals;
19
15
  var SHADE_OUTSIDE_DOT_SCALE = 0.5;
20
16
  var halftoneSchema = {
21
17
  dotSize: {
@@ -219,7 +215,7 @@ var halftone = createEffect({
219
215
  preserveDrawingBuffer: true
220
216
  });
221
217
  if (!gl) {
222
- throw new Error("Failed to acquire WebGL2 context for halftone effect");
218
+ throw createWebGL2ContextError("halftone effect");
223
219
  }
224
220
  gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
225
221
  gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
@@ -347,7 +343,8 @@ var halftone = createEffect({
347
343
  gl.deleteVertexArray(vao);
348
344
  gl.deleteTexture(texture);
349
345
  },
350
- schema: halftoneSchema
346
+ schema: halftoneSchema,
347
+ validateParams: () => {}
351
348
  });
352
349
  export {
353
350
  halftoneSchema,