@remotion/effects 4.0.466 → 4.0.468

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.
@@ -17,6 +17,12 @@ var assertRequiredColor = (value, name) => {
17
17
  throw new TypeError(`"${name}" must be a non-empty string, but got ${JSON.stringify(value)}`);
18
18
  }
19
19
  };
20
+ var assertOptionalColor = (value, name) => {
21
+ if (value === undefined) {
22
+ return;
23
+ }
24
+ assertRequiredColor(value, name);
25
+ };
20
26
 
21
27
  // src/color-utils.ts
22
28
  var DEFAULT_AMOUNT = 1;
@@ -81,11 +87,19 @@ var validateSignedUnitInterval = (value, name) => {
81
87
  var clampColorChannel = (value) => {
82
88
  return Math.max(0, Math.min(255, value));
83
89
  };
90
+ var parseColorRgba = (ctx, color) => {
91
+ ctx.clearRect(0, 0, 1, 1);
92
+ ctx.fillStyle = color;
93
+ ctx.fillRect(0, 0, 1, 1);
94
+ const { data } = ctx.getImageData(0, 0, 1, 1);
95
+ return [data[0], data[1], data[2], data[3]];
96
+ };
84
97
 
85
98
  // src/halftone.ts
86
99
  var { createEffect, createWebGL2ContextError } = Internals;
87
100
  var HALFTONE_SHAPES = ["circle", "square", "line"];
88
101
  var HALFTONE_SAMPLING = ["bilinear", "nearest"];
102
+ var HALFTONE_COLOR_MODES = ["solid", "source"];
89
103
  var halftoneSchema = {
90
104
  dotSize: {
91
105
  type: "number",
@@ -138,10 +152,20 @@ var halftoneSchema = {
138
152
  default: false,
139
153
  description: "Invert"
140
154
  },
141
- color: {
142
- type: "color",
143
- default: "black",
144
- description: "Color"
155
+ colorMode: {
156
+ type: "enum",
157
+ default: "solid",
158
+ description: "Color mode",
159
+ variants: {
160
+ solid: {
161
+ dotColor: {
162
+ type: "color",
163
+ default: "red",
164
+ description: "Dot color"
165
+ }
166
+ },
167
+ source: {}
168
+ }
145
169
  }
146
170
  };
147
171
  var formatEnum = (variants) => {
@@ -166,14 +190,6 @@ var assertOptionalBoolean = (value, name) => {
166
190
  throw new TypeError(`"${name}" must be a boolean, but got ${JSON.stringify(value)}`);
167
191
  }
168
192
  };
169
- var assertOptionalColor = (value, name) => {
170
- if (value === undefined) {
171
- return;
172
- }
173
- if (typeof value !== "string" || value.length === 0) {
174
- throw new TypeError(`"${name}" must be a non-empty string, but got ${JSON.stringify(value)}`);
175
- }
176
- };
177
193
  var resolve = (p) => ({
178
194
  shape: p.shape ?? "circle",
179
195
  dotSize: p.dotSize ?? 20,
@@ -182,7 +198,8 @@ var resolve = (p) => ({
182
198
  offsetX: p.offsetX ?? 0,
183
199
  offsetY: p.offsetY ?? 0,
184
200
  sampling: p.sampling ?? "bilinear",
185
- color: p.color ?? "black",
201
+ colorMode: p.colorMode ?? "solid",
202
+ dotColor: "dotColor" in p ? p.dotColor ?? "red" : "red",
186
203
  invert: p.invert ?? false
187
204
  });
188
205
  var validateHalftoneParams = (params) => {
@@ -194,7 +211,14 @@ var validateHalftoneParams = (params) => {
194
211
  assertOptionalFiniteNumber(params.offsetY, "offsetY");
195
212
  assertOptionalEnum(params.shape, "shape", HALFTONE_SHAPES);
196
213
  assertOptionalEnum(params.sampling, "sampling", HALFTONE_SAMPLING);
197
- assertOptionalColor(params.color, "color");
214
+ assertOptionalEnum(params.colorMode, "colorMode", HALFTONE_COLOR_MODES);
215
+ if ("color" in params && params.color !== undefined) {
216
+ throw new TypeError('"color" has been renamed to "dotColor"');
217
+ }
218
+ if (params.colorMode === "source" && "dotColor" in params) {
219
+ throw new TypeError('"dotColor" can only be set when "colorMode" is "solid"');
220
+ }
221
+ assertOptionalColor("dotColor" in params ? params.dotColor : undefined, "dotColor");
198
222
  assertOptionalBoolean(params.invert, "invert");
199
223
  if (params.dotSize !== undefined && params.dotSize < 1) {
200
224
  throw new TypeError(`"dotSize" must be >= 1, but got ${JSON.stringify(params.dotSize)}`);
@@ -227,6 +251,7 @@ uniform vec2 uOffset;
227
251
  uniform vec4 uColor;
228
252
  uniform int uShape;
229
253
  uniform bool uShadeOutside;
254
+ uniform bool uUseSourceColor;
230
255
 
231
256
  void main() {
232
257
  vec2 fragPos = vUv * uResolution;
@@ -285,7 +310,7 @@ void main() {
285
310
  * (1.0 - smoothstep(lineHalf - 0.5, lineHalf + 0.5, abs(diff.y)));
286
311
  }
287
312
 
288
- fragColor = uColor * coverage;
313
+ fragColor = (uUseSourceColor ? texColor : uColor) * coverage;
289
314
  }
290
315
  `;
291
316
  var SHAPE_INDEX = {
@@ -322,21 +347,14 @@ var linkProgram = (gl, vs, fs) => {
322
347
  }
323
348
  return program;
324
349
  };
325
- var parseColorRgba = (ctx, color) => {
326
- ctx.clearRect(0, 0, 1, 1);
327
- ctx.fillStyle = color;
328
- ctx.fillRect(0, 0, 1, 1);
329
- const { data } = ctx.getImageData(0, 0, 1, 1);
330
- return [data[0] / 255, data[1] / 255, data[2] / 255, data[3] / 255];
331
- };
332
350
  var halftone = createEffect({
333
351
  type: "remotion/halftone",
334
- label: "Halftone",
352
+ label: "halftone()",
335
353
  documentationLink: "https://www.remotion.dev/docs/effects/halftone",
336
354
  backend: "webgl2",
337
355
  calculateKey: (params) => {
338
356
  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}`;
357
+ 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
358
  },
341
359
  setup: (target) => {
342
360
  const gl = target.getContext("webgl2", {
@@ -419,19 +437,21 @@ var halftone = createEffect({
419
437
  uColor: gl.getUniformLocation(program, "uColor"),
420
438
  uShape: gl.getUniformLocation(program, "uShape"),
421
439
  uShadeOutside: gl.getUniformLocation(program, "uShadeOutside"),
440
+ uUseSourceColor: gl.getUniformLocation(program, "uUseSourceColor"),
422
441
  colorCtx,
423
442
  cachedColorStr: "",
424
- cachedColorRgba: [0, 0, 0, 1]
443
+ cachedColorRgba: [0, 0, 0, 255]
425
444
  };
426
445
  },
427
446
  apply: ({ source, width, height, params, state, flipSourceY }) => {
428
447
  const r = resolve(params);
429
448
  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);
449
+ if (state.cachedColorStr !== r.dotColor) {
450
+ state.cachedColorStr = r.dotColor;
451
+ state.cachedColorRgba = parseColorRgba(state.colorCtx, r.dotColor);
433
452
  }
434
453
  const [cr, cg, cb, ca] = state.cachedColorRgba;
454
+ const caNormalized = ca / 255;
435
455
  const filter = r.sampling === "nearest" ? gl.NEAREST : gl.LINEAR;
436
456
  gl.viewport(0, 0, width, height);
437
457
  gl.clearColor(0, 0, 0, 0);
@@ -457,11 +477,13 @@ var halftone = createEffect({
457
477
  if (state.uOffset)
458
478
  gl.uniform2f(state.uOffset, r.offsetX, r.offsetY);
459
479
  if (state.uColor)
460
- gl.uniform4f(state.uColor, cr * ca, cg * ca, cb * ca, ca);
480
+ gl.uniform4f(state.uColor, cr / 255 * caNormalized, cg / 255 * caNormalized, cb / 255 * caNormalized, caNormalized);
461
481
  if (state.uShape)
462
482
  gl.uniform1i(state.uShape, SHAPE_INDEX[r.shape]);
463
483
  if (state.uShadeOutside)
464
484
  gl.uniform1i(state.uShadeOutside, r.invert ? 1 : 0);
485
+ if (state.uUseSourceColor)
486
+ gl.uniform1i(state.uUseSourceColor, r.colorMode === "source" ? 1 : 0);
465
487
  gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
466
488
  gl.bindVertexArray(null);
467
489
  gl.bindTexture(gl.TEXTURE_2D, null);
package/dist/esm/hue.mjs CHANGED
@@ -17,6 +17,12 @@ var assertRequiredColor = (value, name) => {
17
17
  throw new TypeError(`"${name}" must be a non-empty string, but got ${JSON.stringify(value)}`);
18
18
  }
19
19
  };
20
+ var assertOptionalColor = (value, name) => {
21
+ if (value === undefined) {
22
+ return;
23
+ }
24
+ assertRequiredColor(value, name);
25
+ };
20
26
 
21
27
  // src/color-utils.ts
22
28
  var DEFAULT_AMOUNT = 1;
@@ -81,6 +87,13 @@ var validateSignedUnitInterval = (value, name) => {
81
87
  var clampColorChannel = (value) => {
82
88
  return Math.max(0, Math.min(255, value));
83
89
  };
90
+ var parseColorRgba = (ctx, color) => {
91
+ ctx.clearRect(0, 0, 1, 1);
92
+ ctx.fillStyle = color;
93
+ ctx.fillRect(0, 0, 1, 1);
94
+ const { data } = ctx.getImageData(0, 0, 1, 1);
95
+ return [data[0], data[1], data[2], data[3]];
96
+ };
84
97
 
85
98
  // src/hue.ts
86
99
  var { createEffect } = Internals;
@@ -96,7 +109,7 @@ var validateHueParams = (params) => {
96
109
  };
97
110
  var hue = createEffect({
98
111
  type: "remotion/hue",
99
- label: "Hue",
112
+ label: "hue()",
100
113
  documentationLink: "https://www.remotion.dev/docs/effects/hue",
101
114
  backend: "2d",
102
115
  calculateKey: (params) => {
@@ -17,6 +17,12 @@ var assertRequiredColor = (value, name) => {
17
17
  throw new TypeError(`"${name}" must be a non-empty string, but got ${JSON.stringify(value)}`);
18
18
  }
19
19
  };
20
+ var assertOptionalColor = (value, name) => {
21
+ if (value === undefined) {
22
+ return;
23
+ }
24
+ assertRequiredColor(value, name);
25
+ };
20
26
 
21
27
  // src/color-utils.ts
22
28
  var DEFAULT_AMOUNT = 1;
@@ -81,6 +87,13 @@ var validateSignedUnitInterval = (value, name) => {
81
87
  var clampColorChannel = (value) => {
82
88
  return Math.max(0, Math.min(255, value));
83
89
  };
90
+ var parseColorRgba = (ctx, color) => {
91
+ ctx.clearRect(0, 0, 1, 1);
92
+ ctx.fillStyle = color;
93
+ ctx.fillRect(0, 0, 1, 1);
94
+ const { data } = ctx.getImageData(0, 0, 1, 1);
95
+ return [data[0], data[1], data[2], data[3]];
96
+ };
84
97
 
85
98
  // src/invert.ts
86
99
  var { createEffect } = Internals;
@@ -98,7 +111,7 @@ var validateInvertParams = (params) => {
98
111
  };
99
112
  var invert = createEffect({
100
113
  type: "remotion/invert",
101
- label: "Invert",
114
+ label: "invert()",
102
115
  documentationLink: "https://www.remotion.dev/docs/effects/invert",
103
116
  backend: "2d",
104
117
  calculateKey: (params) => {
@@ -17,6 +17,12 @@ var assertRequiredColor = (value, name) => {
17
17
  throw new TypeError(`"${name}" must be a non-empty string, but got ${JSON.stringify(value)}`);
18
18
  }
19
19
  };
20
+ var assertOptionalColor = (value, name) => {
21
+ if (value === undefined) {
22
+ return;
23
+ }
24
+ assertRequiredColor(value, name);
25
+ };
20
26
 
21
27
  // src/color-utils.ts
22
28
  var DEFAULT_AMOUNT = 1;
@@ -81,6 +87,13 @@ var validateSignedUnitInterval = (value, name) => {
81
87
  var clampColorChannel = (value) => {
82
88
  return Math.max(0, Math.min(255, value));
83
89
  };
90
+ var parseColorRgba = (ctx, color) => {
91
+ ctx.clearRect(0, 0, 1, 1);
92
+ ctx.fillStyle = color;
93
+ ctx.fillRect(0, 0, 1, 1);
94
+ const { data } = ctx.getImageData(0, 0, 1, 1);
95
+ return [data[0], data[1], data[2], data[3]];
96
+ };
84
97
 
85
98
  // src/mirror/mirror-runtime.ts
86
99
  import { Internals } from "remotion";
@@ -328,7 +341,7 @@ var validateMirrorParams = (params) => {
328
341
  };
329
342
  var mirror = createEffect({
330
343
  type: "remotion/mirror",
331
- label: "Mirror",
344
+ label: "mirror()",
332
345
  documentationLink: "https://www.remotion.dev/docs/effects/mirror",
333
346
  backend: "webgl2",
334
347
  calculateKey: (params) => {
@@ -17,6 +17,12 @@ var assertRequiredColor = (value, name) => {
17
17
  throw new TypeError(`"${name}" must be a non-empty string, but got ${JSON.stringify(value)}`);
18
18
  }
19
19
  };
20
+ var assertOptionalColor = (value, name) => {
21
+ if (value === undefined) {
22
+ return;
23
+ }
24
+ assertRequiredColor(value, name);
25
+ };
20
26
 
21
27
  // src/color-utils.ts
22
28
  var DEFAULT_AMOUNT = 1;
@@ -81,6 +87,13 @@ var validateSignedUnitInterval = (value, name) => {
81
87
  var clampColorChannel = (value) => {
82
88
  return Math.max(0, Math.min(255, value));
83
89
  };
90
+ var parseColorRgba = (ctx, color) => {
91
+ ctx.clearRect(0, 0, 1, 1);
92
+ ctx.fillStyle = color;
93
+ ctx.fillRect(0, 0, 1, 1);
94
+ const { data } = ctx.getImageData(0, 0, 1, 1);
95
+ return [data[0], data[1], data[2], data[3]];
96
+ };
84
97
 
85
98
  // src/saturation.ts
86
99
  var { createEffect } = Internals;
@@ -98,7 +111,7 @@ var validateSaturationParams = (params) => {
98
111
  };
99
112
  var saturation = createEffect({
100
113
  type: "remotion/saturation",
101
- label: "Saturation",
114
+ label: "saturation()",
102
115
  documentationLink: "https://www.remotion.dev/docs/effects/saturation",
103
116
  backend: "2d",
104
117
  calculateKey: (params) => {
@@ -17,6 +17,12 @@ var assertRequiredColor = (value, name) => {
17
17
  throw new TypeError(`"${name}" must be a non-empty string, but got ${JSON.stringify(value)}`);
18
18
  }
19
19
  };
20
+ var assertOptionalColor = (value, name) => {
21
+ if (value === undefined) {
22
+ return;
23
+ }
24
+ assertRequiredColor(value, name);
25
+ };
20
26
 
21
27
  // src/scale/index.ts
22
28
  var { createEffect } = Internals;
@@ -61,7 +67,7 @@ var validateScaleParams = (params) => {
61
67
  };
62
68
  var scale = createEffect({
63
69
  type: "remotion/scale",
64
- label: "Scale",
70
+ label: "scale()",
65
71
  documentationLink: "https://www.remotion.dev/docs/effects/scale",
66
72
  backend: "2d",
67
73
  calculateKey: (params) => {