@remotion/transitions 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.
package/cross-zoom.js ADDED
@@ -0,0 +1,2 @@
1
+ // For backwards compatibility when you use `esm-wallaby`
2
+ module.exports = require('./dist/presentations/cross-zoom.js');
@@ -1,11 +1,12 @@
1
1
  // src/html-in-canvas-presentation.tsx
2
- import { useLayoutEffect, useMemo, useRef, useState, useCallback } from "react";
2
+ import { useCallback, useLayoutEffect, useMemo, useRef, useState } from "react";
3
3
  import {
4
- HtmlInCanvas,
4
+ AbsoluteFill,
5
5
  HTML_IN_CANVAS_UNSUPPORTED_MESSAGE,
6
+ HtmlInCanvas,
7
+ Internals,
6
8
  useDelayRender
7
9
  } from "remotion";
8
- import { AbsoluteFill, Internals } from "remotion";
9
10
  import { jsx } from "react/jsx-runtime";
10
11
  var HtmlInCanvasPresentation = ({
11
12
  children,
@@ -0,0 +1,377 @@
1
+ // src/html-in-canvas-presentation.tsx
2
+ import { useCallback, useLayoutEffect, useMemo, useRef, useState } from "react";
3
+ import {
4
+ AbsoluteFill,
5
+ HTML_IN_CANVAS_UNSUPPORTED_MESSAGE,
6
+ HtmlInCanvas,
7
+ Internals,
8
+ useDelayRender
9
+ } from "remotion";
10
+ import { jsx } from "react/jsx-runtime";
11
+ var HtmlInCanvasPresentation = ({
12
+ children,
13
+ onElementImage,
14
+ onUnmount,
15
+ presentationProgress,
16
+ presentationDirection,
17
+ shader,
18
+ effects,
19
+ passedProps,
20
+ bothEnteringAndExiting
21
+ }) => {
22
+ if (!HtmlInCanvas.isSupported()) {
23
+ throw new Error(HTML_IN_CANVAS_UNSUPPORTED_MESSAGE);
24
+ }
25
+ const canvasRef = useRef(null);
26
+ const canvasSubtreeStyle = useMemo(() => {
27
+ return {
28
+ width: "100%",
29
+ height: "100%",
30
+ position: "absolute",
31
+ top: 0,
32
+ left: 0,
33
+ right: 0,
34
+ bottom: 0
35
+ };
36
+ }, []);
37
+ const [offscreenCanvas] = useState(() => new OffscreenCanvas(1, 1));
38
+ const passedPropsRef = useRef(passedProps);
39
+ passedPropsRef.current = passedProps;
40
+ const memoizedEffects = Internals.useMemoizedEffects({
41
+ effects: effects ?? [],
42
+ overrideId: null
43
+ });
44
+ const effectsRef = useRef(memoizedEffects);
45
+ effectsRef.current = memoizedEffects;
46
+ const [instance] = useState(() => shader(offscreenCanvas));
47
+ useLayoutEffect(() => {
48
+ return () => {
49
+ instance.cleanup();
50
+ };
51
+ }, [offscreenCanvas, instance]);
52
+ const chainState = Internals.useEffectChainState();
53
+ const { delayRender, continueRender } = useDelayRender();
54
+ const draw = useCallback(async (prevImage, nextImage, progress) => {
55
+ if (!canvasRef.current) {
56
+ throw new Error("Canvas not found");
57
+ }
58
+ const handle = delayRender("onPaint");
59
+ if (!prevImage && !nextImage) {
60
+ continueRender(handle);
61
+ instance.clear();
62
+ return;
63
+ }
64
+ const width = prevImage?.width ?? nextImage?.width ?? 0;
65
+ const height = prevImage?.height ?? nextImage?.height ?? 0;
66
+ if (width === 0 || height === 0) {
67
+ continueRender(handle);
68
+ instance.clear();
69
+ return;
70
+ }
71
+ offscreenCanvas.width = width;
72
+ offscreenCanvas.height = height;
73
+ instance.draw({
74
+ prevImage,
75
+ nextImage,
76
+ width,
77
+ height,
78
+ time: progress,
79
+ passedProps: passedPropsRef.current
80
+ });
81
+ await Internals.runEffectChain({
82
+ state: chainState.get(width, height),
83
+ source: offscreenCanvas,
84
+ effects: effectsRef.current ?? [],
85
+ width,
86
+ height,
87
+ output: canvasRef.current
88
+ });
89
+ continueRender(handle);
90
+ }, [chainState, instance, offscreenCanvas, continueRender, delayRender]);
91
+ const passThrough = bothEnteringAndExiting && presentationDirection === "exiting";
92
+ useLayoutEffect(() => {
93
+ if (passThrough) {
94
+ return;
95
+ }
96
+ const canvas = canvasRef.current;
97
+ if (!canvas) {
98
+ throw new Error("Canvas not found");
99
+ }
100
+ canvas.layoutSubtree = true;
101
+ const onPaint = () => {
102
+ const firstChild = canvas.firstChild;
103
+ if (!firstChild) {
104
+ return;
105
+ }
106
+ const elementImage = canvas.captureElementImage(firstChild);
107
+ onElementImage(elementImage, draw);
108
+ };
109
+ canvas.addEventListener("paint", onPaint);
110
+ return () => {
111
+ canvas.removeEventListener("paint", onPaint);
112
+ };
113
+ }, [onElementImage, presentationDirection, draw, passThrough]);
114
+ useLayoutEffect(() => {
115
+ if (passThrough) {
116
+ return;
117
+ }
118
+ const canvas = canvasRef.current;
119
+ if (!canvas) {
120
+ throw new Error("Canvas not found");
121
+ }
122
+ canvas.requestPaint?.();
123
+ }, [presentationProgress, passThrough, memoizedEffects]);
124
+ useLayoutEffect(() => {
125
+ if (passThrough) {
126
+ return;
127
+ }
128
+ return () => {
129
+ onUnmount();
130
+ };
131
+ }, [onUnmount, passThrough]);
132
+ useLayoutEffect(() => {
133
+ if (passThrough) {
134
+ return;
135
+ }
136
+ const canvas = canvasRef.current;
137
+ if (!canvas) {
138
+ return;
139
+ }
140
+ const observer = new ResizeObserver(([entry]) => {
141
+ canvas.width = entry.devicePixelContentBoxSize[0].inlineSize;
142
+ canvas.height = entry.devicePixelContentBoxSize[0].blockSize;
143
+ });
144
+ observer.observe(canvas, { box: "device-pixel-content-box" });
145
+ }, [passThrough]);
146
+ if (passThrough) {
147
+ return children;
148
+ }
149
+ return /* @__PURE__ */ jsx(AbsoluteFill, {
150
+ children: /* @__PURE__ */ jsx("canvas", {
151
+ ref: canvasRef,
152
+ style: canvasSubtreeStyle,
153
+ children
154
+ })
155
+ });
156
+ };
157
+ var makeHtmlInCanvasPresentation = (shader) => {
158
+ const CompWithShader = (props) => {
159
+ const { passedProps, ...otherProps } = props;
160
+ const { effects, ...restPassedProps } = props.passedProps;
161
+ return /* @__PURE__ */ jsx(HtmlInCanvasPresentation, {
162
+ shader,
163
+ passedProps: restPassedProps,
164
+ effects,
165
+ ...otherProps
166
+ });
167
+ };
168
+ return (props) => {
169
+ return {
170
+ component: CompWithShader,
171
+ props
172
+ };
173
+ };
174
+ };
175
+
176
+ // src/presentations/cross-zoom.tsx
177
+ var DEFAULT_STRENGTH = 0.4;
178
+ var VERTEX_SHADER = `#version 300 es
179
+ in vec2 a_pos;
180
+ out vec2 v_uv;
181
+ void main() {
182
+ v_uv = vec2(a_pos.x * 0.5 + 0.5, 0.5 - a_pos.y * 0.5);
183
+ gl_Position = vec4(a_pos, 0.0, 1.0);
184
+ }`;
185
+ var FRAGMENT_SHADER = `#version 300 es
186
+ precision highp float;
187
+
188
+ uniform sampler2D u_prev;
189
+ uniform sampler2D u_next;
190
+ uniform float u_time;
191
+ uniform float u_strength;
192
+
193
+ in vec2 v_uv;
194
+ out vec4 outColor;
195
+
196
+ const float PI = 3.141592653589793;
197
+
198
+ float linearEase(float begin, float change, float duration, float time) {
199
+ return change * time / duration + begin;
200
+ }
201
+
202
+ float exponentialEaseInOut(float begin, float change, float duration, float time) {
203
+ if (time == 0.0) {
204
+ return begin;
205
+ }
206
+
207
+ if (time == duration) {
208
+ return begin + change;
209
+ }
210
+
211
+ float t = time / (duration / 2.0);
212
+ if (t < 1.0) {
213
+ return change / 2.0 * pow(2.0, 10.0 * (t - 1.0)) + begin;
214
+ }
215
+
216
+ return change / 2.0 * (-pow(2.0, -10.0 * (t - 1.0)) + 2.0) + begin;
217
+ }
218
+
219
+ float sinusoidalEaseInOut(float begin, float change, float duration, float time) {
220
+ return -change / 2.0 * (cos(PI * time / duration) - 1.0) + begin;
221
+ }
222
+
223
+ float random(vec2 co) {
224
+ return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);
225
+ }
226
+
227
+ vec4 crossFade(vec2 uv, float dissolve) {
228
+ return mix(texture(u_prev, uv), texture(u_next, uv), dissolve);
229
+ }
230
+
231
+ vec4 transition(vec2 uv, float progress) {
232
+ vec2 center = vec2(linearEase(0.25, 0.5, 1.0, progress), 0.5);
233
+ float dissolve = exponentialEaseInOut(0.0, 1.0, 1.0, progress);
234
+ float strength = sinusoidalEaseInOut(0.0, u_strength, 0.5, progress);
235
+
236
+ vec4 color = vec4(0.0);
237
+ float total = 0.0;
238
+ vec2 toCenter = center - uv;
239
+ float offset = random(uv);
240
+
241
+ for (int i = 0; i <= 40; i++) {
242
+ float percent = (float(i) + offset) / 40.0;
243
+ float weight = 4.0 * (percent - percent * percent);
244
+ color += crossFade(uv + toCenter * percent * strength, dissolve) * weight;
245
+ total += weight;
246
+ }
247
+
248
+ return color / total;
249
+ }
250
+
251
+ void main() {
252
+ float progress = 1.0 - u_time;
253
+ outColor = transition(v_uv, progress);
254
+ }`;
255
+ var compileShader = (gl, source, type) => {
256
+ const shader = gl.createShader(type);
257
+ if (!shader) {
258
+ throw new Error("Failed to create shader");
259
+ }
260
+ gl.shaderSource(shader, source);
261
+ gl.compileShader(shader);
262
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
263
+ const log = gl.getShaderInfoLog(shader);
264
+ gl.deleteShader(shader);
265
+ throw new Error(`Failed to compile shader: ${log}`);
266
+ }
267
+ return shader;
268
+ };
269
+ var createProgram = (gl) => {
270
+ const program = gl.createProgram();
271
+ if (!program) {
272
+ throw new Error("Failed to create WebGL program");
273
+ }
274
+ const vs = compileShader(gl, VERTEX_SHADER, gl.VERTEX_SHADER);
275
+ const fs = compileShader(gl, FRAGMENT_SHADER, gl.FRAGMENT_SHADER);
276
+ gl.attachShader(program, vs);
277
+ gl.attachShader(program, fs);
278
+ gl.linkProgram(program);
279
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
280
+ const log = gl.getProgramInfoLog(program);
281
+ gl.deleteProgram(program);
282
+ throw new Error(`Failed to link program: ${log}`);
283
+ }
284
+ return program;
285
+ };
286
+ var createTexture = (gl) => {
287
+ const tex = gl.createTexture();
288
+ if (!tex) {
289
+ throw new Error("Failed to create texture");
290
+ }
291
+ gl.bindTexture(gl.TEXTURE_2D, tex);
292
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
293
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
294
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
295
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
296
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0, 0]));
297
+ return tex;
298
+ };
299
+ var crossZoomShader = (canvas) => {
300
+ const gl = canvas.getContext("webgl2", { premultipliedAlpha: true });
301
+ if (!gl) {
302
+ throw new Error("Failed to create WebGL2 context");
303
+ }
304
+ const program = createProgram(gl);
305
+ const prevTex = createTexture(gl);
306
+ const nextTex = createTexture(gl);
307
+ const vao = gl.createVertexArray();
308
+ gl.bindVertexArray(vao);
309
+ const buffer = gl.createBuffer();
310
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
311
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);
312
+ const aPos = gl.getAttribLocation(program, "a_pos");
313
+ gl.enableVertexAttribArray(aPos);
314
+ gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);
315
+ const uTime = gl.getUniformLocation(program, "u_time");
316
+ const uPrev = gl.getUniformLocation(program, "u_prev");
317
+ const uNext = gl.getUniformLocation(program, "u_next");
318
+ const uStrength = gl.getUniformLocation(program, "u_strength");
319
+ const cleanup = () => {
320
+ gl.deleteProgram(program);
321
+ gl.deleteTexture(prevTex);
322
+ gl.deleteTexture(nextTex);
323
+ };
324
+ const clear = () => {
325
+ gl.clearColor(0, 0, 0, 0);
326
+ gl.clear(gl.COLOR_BUFFER_BIT);
327
+ };
328
+ const draw = ({
329
+ prevImage,
330
+ nextImage,
331
+ width,
332
+ height,
333
+ time,
334
+ passedProps
335
+ }) => {
336
+ const { strength = DEFAULT_STRENGTH } = passedProps;
337
+ if (!prevImage && !nextImage) {
338
+ return;
339
+ }
340
+ if (prevImage && (prevImage.width === 0 || prevImage.height === 0)) {
341
+ return;
342
+ }
343
+ if (nextImage && (nextImage.width === 0 || nextImage.height === 0)) {
344
+ return;
345
+ }
346
+ const effectiveTime = !prevImage ? 0 : !nextImage ? 1 : time;
347
+ gl.viewport(0, 0, width, height);
348
+ gl.clearColor(0, 0, 0, 0);
349
+ gl.clear(gl.COLOR_BUFFER_BIT);
350
+ gl.useProgram(program);
351
+ gl.activeTexture(gl.TEXTURE0);
352
+ gl.bindTexture(gl.TEXTURE_2D, prevTex);
353
+ if (prevImage) {
354
+ gl.texElementImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, prevImage);
355
+ }
356
+ gl.uniform1i(uPrev, 0);
357
+ gl.activeTexture(gl.TEXTURE1);
358
+ gl.bindTexture(gl.TEXTURE_2D, nextTex);
359
+ if (nextImage) {
360
+ gl.texElementImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, nextImage);
361
+ }
362
+ gl.uniform1i(uNext, 1);
363
+ gl.uniform1f(uTime, effectiveTime);
364
+ gl.uniform1f(uStrength, strength);
365
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
366
+ };
367
+ return {
368
+ clear,
369
+ cleanup,
370
+ draw
371
+ };
372
+ };
373
+ var crossZoom = makeHtmlInCanvasPresentation(crossZoomShader);
374
+ export {
375
+ crossZoomShader,
376
+ crossZoom
377
+ };
@@ -1,11 +1,12 @@
1
1
  // src/html-in-canvas-presentation.tsx
2
- import { useLayoutEffect, useMemo, useRef, useState, useCallback } from "react";
2
+ import { useCallback, useLayoutEffect, useMemo, useRef, useState } from "react";
3
3
  import {
4
- HtmlInCanvas,
4
+ AbsoluteFill,
5
5
  HTML_IN_CANVAS_UNSUPPORTED_MESSAGE,
6
+ HtmlInCanvas,
7
+ Internals,
6
8
  useDelayRender
7
9
  } from "remotion";
8
- import { AbsoluteFill, Internals } from "remotion";
9
10
  import { jsx } from "react/jsx-runtime";
10
11
  var HtmlInCanvasPresentation = ({
11
12
  children,
@@ -1,11 +1,12 @@
1
1
  // src/html-in-canvas-presentation.tsx
2
- import { useLayoutEffect, useMemo, useRef, useState, useCallback } from "react";
2
+ import { useCallback, useLayoutEffect, useMemo, useRef, useState } from "react";
3
3
  import {
4
- HtmlInCanvas,
4
+ AbsoluteFill,
5
5
  HTML_IN_CANVAS_UNSUPPORTED_MESSAGE,
6
+ HtmlInCanvas,
7
+ Internals,
6
8
  useDelayRender
7
9
  } from "remotion";
8
- import { AbsoluteFill, Internals } from "remotion";
9
10
  import { jsx } from "react/jsx-runtime";
10
11
  var HtmlInCanvasPresentation = ({
11
12
  children,
@@ -1,11 +1,12 @@
1
1
  // src/html-in-canvas-presentation.tsx
2
- import { useLayoutEffect, useMemo, useRef, useState, useCallback } from "react";
2
+ import { useCallback, useLayoutEffect, useMemo, useRef, useState } from "react";
3
3
  import {
4
- HtmlInCanvas,
4
+ AbsoluteFill,
5
5
  HTML_IN_CANVAS_UNSUPPORTED_MESSAGE,
6
+ HtmlInCanvas,
7
+ Internals,
6
8
  useDelayRender
7
9
  } from "remotion";
8
- import { AbsoluteFill, Internals } from "remotion";
9
10
  import { jsx } from "react/jsx-runtime";
10
11
  var HtmlInCanvasPresentation = ({
11
12
  children,