@remotion/transitions 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.
- package/book-flip.js +2 -0
- package/crosswarp.js +2 -0
- package/dissolve.js +2 -0
- package/dist/TransitionSeries.js +16 -6
- package/dist/esm/book-flip.mjs +433 -0
- package/dist/esm/crosswarp.mjs +330 -0
- package/dist/esm/dissolve.mjs +376 -0
- package/dist/esm/dreamy-zoom.mjs +347 -0
- package/dist/esm/index.mjs +553 -209
- package/dist/esm/linear-blur.mjs +342 -0
- package/dist/esm/ripple.mjs +341 -0
- package/dist/esm/swap.mjs +393 -0
- package/dist/esm/zoom-blur.mjs +4 -4
- package/dist/esm/zoom-in-out.mjs +4 -4
- package/dist/html-in-canvas-presentation.d.ts +4 -4
- package/dist/html-in-canvas-presentation.js +4 -4
- package/dist/index.d.ts +9 -3
- package/dist/index.js +5 -1
- package/dist/presentations/book-flip.d.ts +14 -0
- package/dist/presentations/book-flip.js +255 -0
- package/dist/presentations/crosswarp.d.ts +11 -0
- package/dist/presentations/crosswarp.js +154 -0
- package/dist/presentations/dissolve.d.ts +17 -0
- package/dist/presentations/dissolve.js +193 -0
- package/dist/presentations/dreamy-zoom.d.ts +14 -0
- package/dist/presentations/dreamy-zoom.js +169 -0
- package/dist/presentations/linear-blur.d.ts +13 -0
- package/dist/presentations/linear-blur.js +164 -0
- package/dist/presentations/ripple.d.ts +14 -0
- package/dist/presentations/ripple.js +164 -0
- package/dist/presentations/swap.d.ts +15 -0
- package/dist/presentations/swap.js +212 -0
- package/dist/presentations/zoom-blur.d.ts +2 -2
- package/dist/presentations/zoom-in-out.d.ts +2 -2
- package/dreamy-zoom.js +2 -0
- package/linear-blur.js +2 -0
- package/package.json +71 -8
- package/ripple.js +2 -0
- package/swap.js +2 -0
package/dist/esm/index.mjs
CHANGED
|
@@ -76,6 +76,515 @@ var slide = (props) => {
|
|
|
76
76
|
};
|
|
77
77
|
};
|
|
78
78
|
|
|
79
|
+
// src/html-in-canvas-presentation.tsx
|
|
80
|
+
import { useLayoutEffect, useMemo as useMemo2, useRef, useState, useCallback } from "react";
|
|
81
|
+
import {
|
|
82
|
+
HtmlInCanvas,
|
|
83
|
+
HTML_IN_CANVAS_UNSUPPORTED_MESSAGE,
|
|
84
|
+
useDelayRender
|
|
85
|
+
} from "remotion";
|
|
86
|
+
import { AbsoluteFill as AbsoluteFill2, Internals } from "remotion";
|
|
87
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
88
|
+
var HtmlInCanvasPresentation = ({
|
|
89
|
+
children,
|
|
90
|
+
onElementImage,
|
|
91
|
+
onUnmount,
|
|
92
|
+
presentationProgress,
|
|
93
|
+
presentationDirection,
|
|
94
|
+
shader,
|
|
95
|
+
effects,
|
|
96
|
+
passedProps,
|
|
97
|
+
bothEnteringAndExiting
|
|
98
|
+
}) => {
|
|
99
|
+
if (!HtmlInCanvas.isSupported()) {
|
|
100
|
+
throw new Error(HTML_IN_CANVAS_UNSUPPORTED_MESSAGE);
|
|
101
|
+
}
|
|
102
|
+
const canvasRef = useRef(null);
|
|
103
|
+
const canvasSubtreeStyle = useMemo2(() => {
|
|
104
|
+
return {
|
|
105
|
+
width: "100%",
|
|
106
|
+
height: "100%",
|
|
107
|
+
position: "absolute",
|
|
108
|
+
top: 0,
|
|
109
|
+
left: 0,
|
|
110
|
+
right: 0,
|
|
111
|
+
bottom: 0
|
|
112
|
+
};
|
|
113
|
+
}, []);
|
|
114
|
+
const [offscreenCanvas] = useState(() => new OffscreenCanvas(1, 1));
|
|
115
|
+
const passedPropsRef = useRef(passedProps);
|
|
116
|
+
passedPropsRef.current = passedProps;
|
|
117
|
+
const memoizedEffects = Internals.useMemoizedEffects({
|
|
118
|
+
effects: effects ?? [],
|
|
119
|
+
overrideId: null
|
|
120
|
+
});
|
|
121
|
+
const effectsRef = useRef(memoizedEffects);
|
|
122
|
+
effectsRef.current = memoizedEffects;
|
|
123
|
+
const [instance] = useState(() => shader(offscreenCanvas));
|
|
124
|
+
useLayoutEffect(() => {
|
|
125
|
+
return () => {
|
|
126
|
+
instance.cleanup();
|
|
127
|
+
};
|
|
128
|
+
}, [offscreenCanvas, instance]);
|
|
129
|
+
const chainState = Internals.useEffectChainState();
|
|
130
|
+
const { delayRender, continueRender } = useDelayRender();
|
|
131
|
+
const draw = useCallback(async (prevImage, nextImage, progress) => {
|
|
132
|
+
if (!canvasRef.current) {
|
|
133
|
+
throw new Error("Canvas not found");
|
|
134
|
+
}
|
|
135
|
+
const handle = delayRender("onPaint");
|
|
136
|
+
if (!prevImage && !nextImage) {
|
|
137
|
+
continueRender(handle);
|
|
138
|
+
instance.clear();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const width = prevImage?.width ?? nextImage?.width ?? 0;
|
|
142
|
+
const height = prevImage?.height ?? nextImage?.height ?? 0;
|
|
143
|
+
if (width === 0 || height === 0) {
|
|
144
|
+
continueRender(handle);
|
|
145
|
+
instance.clear();
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
offscreenCanvas.width = width;
|
|
149
|
+
offscreenCanvas.height = height;
|
|
150
|
+
instance.draw({
|
|
151
|
+
prevImage,
|
|
152
|
+
nextImage,
|
|
153
|
+
width,
|
|
154
|
+
height,
|
|
155
|
+
time: progress,
|
|
156
|
+
passedProps: passedPropsRef.current
|
|
157
|
+
});
|
|
158
|
+
await Internals.runEffectChain({
|
|
159
|
+
state: chainState.get(width, height),
|
|
160
|
+
source: offscreenCanvas,
|
|
161
|
+
effects: effectsRef.current ?? [],
|
|
162
|
+
width,
|
|
163
|
+
height,
|
|
164
|
+
output: canvasRef.current
|
|
165
|
+
});
|
|
166
|
+
continueRender(handle);
|
|
167
|
+
}, [chainState, instance, offscreenCanvas, continueRender, delayRender]);
|
|
168
|
+
const passThrough = bothEnteringAndExiting && presentationDirection === "exiting";
|
|
169
|
+
useLayoutEffect(() => {
|
|
170
|
+
if (passThrough) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const canvas = canvasRef.current;
|
|
174
|
+
if (!canvas) {
|
|
175
|
+
throw new Error("Canvas not found");
|
|
176
|
+
}
|
|
177
|
+
canvas.layoutSubtree = true;
|
|
178
|
+
const onPaint = () => {
|
|
179
|
+
const firstChild = canvas.firstChild;
|
|
180
|
+
if (!firstChild) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const elementImage = canvas.captureElementImage(firstChild);
|
|
184
|
+
onElementImage(elementImage, draw);
|
|
185
|
+
};
|
|
186
|
+
canvas.addEventListener("paint", onPaint);
|
|
187
|
+
return () => {
|
|
188
|
+
canvas.removeEventListener("paint", onPaint);
|
|
189
|
+
};
|
|
190
|
+
}, [onElementImage, presentationDirection, draw, passThrough]);
|
|
191
|
+
useLayoutEffect(() => {
|
|
192
|
+
if (passThrough) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const canvas = canvasRef.current;
|
|
196
|
+
if (!canvas) {
|
|
197
|
+
throw new Error("Canvas not found");
|
|
198
|
+
}
|
|
199
|
+
canvas.requestPaint?.();
|
|
200
|
+
}, [presentationProgress, passThrough, memoizedEffects]);
|
|
201
|
+
useLayoutEffect(() => {
|
|
202
|
+
if (passThrough) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
return () => {
|
|
206
|
+
onUnmount();
|
|
207
|
+
};
|
|
208
|
+
}, [onUnmount, passThrough]);
|
|
209
|
+
useLayoutEffect(() => {
|
|
210
|
+
if (passThrough) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const canvas = canvasRef.current;
|
|
214
|
+
if (!canvas) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
218
|
+
canvas.width = entry.devicePixelContentBoxSize[0].inlineSize;
|
|
219
|
+
canvas.height = entry.devicePixelContentBoxSize[0].blockSize;
|
|
220
|
+
});
|
|
221
|
+
observer.observe(canvas, { box: "device-pixel-content-box" });
|
|
222
|
+
}, [passThrough]);
|
|
223
|
+
if (passThrough) {
|
|
224
|
+
return children;
|
|
225
|
+
}
|
|
226
|
+
return /* @__PURE__ */ jsx2(AbsoluteFill2, {
|
|
227
|
+
children: /* @__PURE__ */ jsx2("canvas", {
|
|
228
|
+
ref: canvasRef,
|
|
229
|
+
style: canvasSubtreeStyle,
|
|
230
|
+
children
|
|
231
|
+
})
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
var makeHtmlInCanvasPresentation = (shader) => {
|
|
235
|
+
const CompWithShader = (props) => {
|
|
236
|
+
const { passedProps, ...otherProps } = props;
|
|
237
|
+
const { effects, ...restPassedProps } = props.passedProps;
|
|
238
|
+
return /* @__PURE__ */ jsx2(HtmlInCanvasPresentation, {
|
|
239
|
+
shader,
|
|
240
|
+
passedProps: restPassedProps,
|
|
241
|
+
effects,
|
|
242
|
+
...otherProps
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
return (props) => {
|
|
246
|
+
return {
|
|
247
|
+
component: CompWithShader,
|
|
248
|
+
props
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// src/presentations/linear-blur.tsx
|
|
254
|
+
var VERTEX_SHADER = `#version 300 es
|
|
255
|
+
in vec2 a_pos;
|
|
256
|
+
out vec2 v_uv;
|
|
257
|
+
void main() {
|
|
258
|
+
v_uv = vec2(a_pos.x * 0.5 + 0.5, 0.5 - a_pos.y * 0.5);
|
|
259
|
+
gl_Position = vec4(a_pos, 0.0, 1.0);
|
|
260
|
+
}`;
|
|
261
|
+
var FRAGMENT_SHADER = `#version 300 es
|
|
262
|
+
precision highp float;
|
|
263
|
+
|
|
264
|
+
uniform sampler2D u_prev;
|
|
265
|
+
uniform sampler2D u_next;
|
|
266
|
+
uniform float u_time;
|
|
267
|
+
uniform float u_intensity;
|
|
268
|
+
|
|
269
|
+
in vec2 v_uv;
|
|
270
|
+
out vec4 outColor;
|
|
271
|
+
|
|
272
|
+
const int PASSES = 6;
|
|
273
|
+
|
|
274
|
+
vec4 transition(vec2 uv, float progress) {
|
|
275
|
+
vec4 c1 = vec4(0.0);
|
|
276
|
+
vec4 c2 = vec4(0.0);
|
|
277
|
+
|
|
278
|
+
float disp = u_intensity * (0.5 - distance(0.5, progress));
|
|
279
|
+
for (int xi = 0; xi < PASSES; xi++) {
|
|
280
|
+
float x = float(xi) / float(PASSES) - 0.5;
|
|
281
|
+
for (int yi = 0; yi < PASSES; yi++) {
|
|
282
|
+
float y = float(yi) / float(PASSES) - 0.5;
|
|
283
|
+
vec2 v = vec2(x, y);
|
|
284
|
+
c1 += texture(u_prev, uv + disp * v);
|
|
285
|
+
c2 += texture(u_next, uv + disp * v);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
c1 /= float(PASSES * PASSES);
|
|
290
|
+
c2 /= float(PASSES * PASSES);
|
|
291
|
+
return mix(c1, c2, progress);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
void main() {
|
|
295
|
+
float progress = 1.0 - u_time;
|
|
296
|
+
outColor = transition(v_uv, progress);
|
|
297
|
+
}`;
|
|
298
|
+
var compileShader = (gl, source, type) => {
|
|
299
|
+
const shader = gl.createShader(type);
|
|
300
|
+
if (!shader) {
|
|
301
|
+
throw new Error("Failed to create shader");
|
|
302
|
+
}
|
|
303
|
+
gl.shaderSource(shader, source);
|
|
304
|
+
gl.compileShader(shader);
|
|
305
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
306
|
+
const log = gl.getShaderInfoLog(shader);
|
|
307
|
+
gl.deleteShader(shader);
|
|
308
|
+
throw new Error(`Failed to compile shader: ${log}`);
|
|
309
|
+
}
|
|
310
|
+
return shader;
|
|
311
|
+
};
|
|
312
|
+
var createProgram = (gl) => {
|
|
313
|
+
const program = gl.createProgram();
|
|
314
|
+
if (!program) {
|
|
315
|
+
throw new Error("Failed to create WebGL program");
|
|
316
|
+
}
|
|
317
|
+
const vs = compileShader(gl, VERTEX_SHADER, gl.VERTEX_SHADER);
|
|
318
|
+
const fs = compileShader(gl, FRAGMENT_SHADER, gl.FRAGMENT_SHADER);
|
|
319
|
+
gl.attachShader(program, vs);
|
|
320
|
+
gl.attachShader(program, fs);
|
|
321
|
+
gl.linkProgram(program);
|
|
322
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
323
|
+
const log = gl.getProgramInfoLog(program);
|
|
324
|
+
gl.deleteProgram(program);
|
|
325
|
+
throw new Error(`Failed to link program: ${log}`);
|
|
326
|
+
}
|
|
327
|
+
return program;
|
|
328
|
+
};
|
|
329
|
+
var createTexture = (gl) => {
|
|
330
|
+
const tex = gl.createTexture();
|
|
331
|
+
if (!tex) {
|
|
332
|
+
throw new Error("Failed to create texture");
|
|
333
|
+
}
|
|
334
|
+
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
335
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
336
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
337
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
338
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
339
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0, 0]));
|
|
340
|
+
return tex;
|
|
341
|
+
};
|
|
342
|
+
var linearBlurShader = (canvas) => {
|
|
343
|
+
const gl = canvas.getContext("webgl2", { premultipliedAlpha: true });
|
|
344
|
+
if (!gl) {
|
|
345
|
+
throw new Error("Failed to create WebGL2 context");
|
|
346
|
+
}
|
|
347
|
+
const program = createProgram(gl);
|
|
348
|
+
const prevTex = createTexture(gl);
|
|
349
|
+
const nextTex = createTexture(gl);
|
|
350
|
+
const vao = gl.createVertexArray();
|
|
351
|
+
gl.bindVertexArray(vao);
|
|
352
|
+
const buffer = gl.createBuffer();
|
|
353
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
354
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);
|
|
355
|
+
const aPos = gl.getAttribLocation(program, "a_pos");
|
|
356
|
+
gl.enableVertexAttribArray(aPos);
|
|
357
|
+
gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);
|
|
358
|
+
const uTime = gl.getUniformLocation(program, "u_time");
|
|
359
|
+
const uPrev = gl.getUniformLocation(program, "u_prev");
|
|
360
|
+
const uNext = gl.getUniformLocation(program, "u_next");
|
|
361
|
+
const uIntensity = gl.getUniformLocation(program, "u_intensity");
|
|
362
|
+
const cleanup = () => {
|
|
363
|
+
gl.deleteProgram(program);
|
|
364
|
+
gl.deleteTexture(prevTex);
|
|
365
|
+
gl.deleteTexture(nextTex);
|
|
366
|
+
};
|
|
367
|
+
const clear = () => {
|
|
368
|
+
gl.clearColor(0, 0, 0, 0);
|
|
369
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
370
|
+
};
|
|
371
|
+
const draw = ({
|
|
372
|
+
prevImage,
|
|
373
|
+
nextImage,
|
|
374
|
+
width,
|
|
375
|
+
height,
|
|
376
|
+
time,
|
|
377
|
+
passedProps
|
|
378
|
+
}) => {
|
|
379
|
+
const { intensity = 0.1 } = passedProps;
|
|
380
|
+
if (!prevImage && !nextImage) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
if (prevImage && (prevImage.width === 0 || prevImage.height === 0)) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (nextImage && (nextImage.width === 0 || nextImage.height === 0)) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
const effectiveTime = !prevImage ? 0 : !nextImage ? 1 : time;
|
|
390
|
+
gl.viewport(0, 0, width, height);
|
|
391
|
+
gl.clearColor(0, 0, 0, 0);
|
|
392
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
393
|
+
gl.useProgram(program);
|
|
394
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
395
|
+
gl.bindTexture(gl.TEXTURE_2D, prevTex);
|
|
396
|
+
if (prevImage) {
|
|
397
|
+
gl.texElementImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, prevImage);
|
|
398
|
+
}
|
|
399
|
+
gl.uniform1i(uPrev, 0);
|
|
400
|
+
gl.activeTexture(gl.TEXTURE1);
|
|
401
|
+
gl.bindTexture(gl.TEXTURE_2D, nextTex);
|
|
402
|
+
if (nextImage) {
|
|
403
|
+
gl.texElementImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, nextImage);
|
|
404
|
+
}
|
|
405
|
+
gl.uniform1i(uNext, 1);
|
|
406
|
+
gl.uniform1f(uTime, effectiveTime);
|
|
407
|
+
gl.uniform1f(uIntensity, intensity);
|
|
408
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
409
|
+
};
|
|
410
|
+
return {
|
|
411
|
+
clear,
|
|
412
|
+
cleanup,
|
|
413
|
+
draw
|
|
414
|
+
};
|
|
415
|
+
};
|
|
416
|
+
var linearBlur = makeHtmlInCanvasPresentation(linearBlurShader);
|
|
417
|
+
|
|
418
|
+
// src/presentations/dreamy-zoom.tsx
|
|
419
|
+
var DEFAULT_ROTATION = 6;
|
|
420
|
+
var DEFAULT_SCALE = 1.2;
|
|
421
|
+
var VERTEX_SHADER2 = `#version 300 es
|
|
422
|
+
in vec2 a_pos;
|
|
423
|
+
out vec2 v_uv;
|
|
424
|
+
void main() {
|
|
425
|
+
v_uv = vec2(a_pos.x * 0.5 + 0.5, 0.5 - a_pos.y * 0.5);
|
|
426
|
+
gl_Position = vec4(a_pos, 0.0, 1.0);
|
|
427
|
+
}`;
|
|
428
|
+
var FRAGMENT_SHADER2 = `#version 300 es
|
|
429
|
+
precision highp float;
|
|
430
|
+
|
|
431
|
+
uniform sampler2D u_prev;
|
|
432
|
+
uniform sampler2D u_next;
|
|
433
|
+
uniform float u_time;
|
|
434
|
+
uniform float u_rotation;
|
|
435
|
+
uniform float u_scale;
|
|
436
|
+
uniform float u_ratio;
|
|
437
|
+
|
|
438
|
+
in vec2 v_uv;
|
|
439
|
+
out vec4 outColor;
|
|
440
|
+
|
|
441
|
+
const float DEG2RAD = 0.03926990816987241548078304229099;
|
|
442
|
+
|
|
443
|
+
vec4 transition(vec2 uv, float progress) {
|
|
444
|
+
float phase = progress < 0.5 ? progress * 2.0 : (progress - 0.5) * 2.0;
|
|
445
|
+
float angleOffset = progress < 0.5 ? mix(0.0, u_rotation * DEG2RAD, phase) : mix(-u_rotation * DEG2RAD, 0.0, phase);
|
|
446
|
+
float newScale = progress < 0.5 ? mix(1.0, u_scale, phase) : mix(u_scale, 1.0, phase);
|
|
447
|
+
|
|
448
|
+
vec2 center = vec2(0.0, 0.0);
|
|
449
|
+
vec2 p = (uv.xy - vec2(0.5, 0.5)) / newScale * vec2(u_ratio, 1.0);
|
|
450
|
+
float angle = atan(p.y, p.x) + angleOffset;
|
|
451
|
+
float dist = distance(center, p);
|
|
452
|
+
|
|
453
|
+
p.x = cos(angle) * dist / u_ratio + 0.5;
|
|
454
|
+
p.y = sin(angle) * dist + 0.5;
|
|
455
|
+
|
|
456
|
+
vec4 c = progress < 0.5 ? texture(u_prev, p) : texture(u_next, p);
|
|
457
|
+
return c + (progress < 0.5 ? mix(0.0, 1.0, phase) : mix(1.0, 0.0, phase));
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
void main() {
|
|
461
|
+
float progress = 1.0 - u_time;
|
|
462
|
+
outColor = transition(v_uv, progress);
|
|
463
|
+
}`;
|
|
464
|
+
var compileShader2 = (gl, source, type) => {
|
|
465
|
+
const shader = gl.createShader(type);
|
|
466
|
+
if (!shader) {
|
|
467
|
+
throw new Error("Failed to create shader");
|
|
468
|
+
}
|
|
469
|
+
gl.shaderSource(shader, source);
|
|
470
|
+
gl.compileShader(shader);
|
|
471
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
472
|
+
const log = gl.getShaderInfoLog(shader);
|
|
473
|
+
gl.deleteShader(shader);
|
|
474
|
+
throw new Error(`Failed to compile shader: ${log}`);
|
|
475
|
+
}
|
|
476
|
+
return shader;
|
|
477
|
+
};
|
|
478
|
+
var createProgram2 = (gl) => {
|
|
479
|
+
const program = gl.createProgram();
|
|
480
|
+
if (!program) {
|
|
481
|
+
throw new Error("Failed to create WebGL program");
|
|
482
|
+
}
|
|
483
|
+
const vs = compileShader2(gl, VERTEX_SHADER2, gl.VERTEX_SHADER);
|
|
484
|
+
const fs = compileShader2(gl, FRAGMENT_SHADER2, gl.FRAGMENT_SHADER);
|
|
485
|
+
gl.attachShader(program, vs);
|
|
486
|
+
gl.attachShader(program, fs);
|
|
487
|
+
gl.linkProgram(program);
|
|
488
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
489
|
+
const log = gl.getProgramInfoLog(program);
|
|
490
|
+
gl.deleteProgram(program);
|
|
491
|
+
throw new Error(`Failed to link program: ${log}`);
|
|
492
|
+
}
|
|
493
|
+
return program;
|
|
494
|
+
};
|
|
495
|
+
var createTexture2 = (gl) => {
|
|
496
|
+
const tex = gl.createTexture();
|
|
497
|
+
if (!tex) {
|
|
498
|
+
throw new Error("Failed to create texture");
|
|
499
|
+
}
|
|
500
|
+
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
501
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
502
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
503
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
504
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
505
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0, 0]));
|
|
506
|
+
return tex;
|
|
507
|
+
};
|
|
508
|
+
var dreamyZoomShader = (canvas) => {
|
|
509
|
+
const gl = canvas.getContext("webgl2", { premultipliedAlpha: true });
|
|
510
|
+
if (!gl) {
|
|
511
|
+
throw new Error("Failed to create WebGL2 context");
|
|
512
|
+
}
|
|
513
|
+
const program = createProgram2(gl);
|
|
514
|
+
const prevTex = createTexture2(gl);
|
|
515
|
+
const nextTex = createTexture2(gl);
|
|
516
|
+
const vao = gl.createVertexArray();
|
|
517
|
+
gl.bindVertexArray(vao);
|
|
518
|
+
const buffer = gl.createBuffer();
|
|
519
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
520
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);
|
|
521
|
+
const aPos = gl.getAttribLocation(program, "a_pos");
|
|
522
|
+
gl.enableVertexAttribArray(aPos);
|
|
523
|
+
gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);
|
|
524
|
+
const uTime = gl.getUniformLocation(program, "u_time");
|
|
525
|
+
const uPrev = gl.getUniformLocation(program, "u_prev");
|
|
526
|
+
const uNext = gl.getUniformLocation(program, "u_next");
|
|
527
|
+
const uRotation = gl.getUniformLocation(program, "u_rotation");
|
|
528
|
+
const uScale = gl.getUniformLocation(program, "u_scale");
|
|
529
|
+
const uRatio = gl.getUniformLocation(program, "u_ratio");
|
|
530
|
+
const cleanup = () => {
|
|
531
|
+
gl.deleteProgram(program);
|
|
532
|
+
gl.deleteTexture(prevTex);
|
|
533
|
+
gl.deleteTexture(nextTex);
|
|
534
|
+
};
|
|
535
|
+
const clear = () => {
|
|
536
|
+
gl.clearColor(0, 0, 0, 0);
|
|
537
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
538
|
+
};
|
|
539
|
+
const draw = ({
|
|
540
|
+
prevImage,
|
|
541
|
+
nextImage,
|
|
542
|
+
width,
|
|
543
|
+
height,
|
|
544
|
+
time,
|
|
545
|
+
passedProps
|
|
546
|
+
}) => {
|
|
547
|
+
const { rotation = DEFAULT_ROTATION, scale = DEFAULT_SCALE } = passedProps;
|
|
548
|
+
if (!prevImage && !nextImage) {
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
if (prevImage && (prevImage.width === 0 || prevImage.height === 0)) {
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
if (nextImage && (nextImage.width === 0 || nextImage.height === 0)) {
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
const effectiveTime = !prevImage ? 0 : !nextImage ? 1 : time;
|
|
558
|
+
gl.viewport(0, 0, width, height);
|
|
559
|
+
gl.clearColor(0, 0, 0, 0);
|
|
560
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
561
|
+
gl.useProgram(program);
|
|
562
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
563
|
+
gl.bindTexture(gl.TEXTURE_2D, prevTex);
|
|
564
|
+
if (prevImage) {
|
|
565
|
+
gl.texElementImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, prevImage);
|
|
566
|
+
}
|
|
567
|
+
gl.uniform1i(uPrev, 0);
|
|
568
|
+
gl.activeTexture(gl.TEXTURE1);
|
|
569
|
+
gl.bindTexture(gl.TEXTURE_2D, nextTex);
|
|
570
|
+
if (nextImage) {
|
|
571
|
+
gl.texElementImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, nextImage);
|
|
572
|
+
}
|
|
573
|
+
gl.uniform1i(uNext, 1);
|
|
574
|
+
gl.uniform1f(uTime, effectiveTime);
|
|
575
|
+
gl.uniform1f(uRotation, rotation);
|
|
576
|
+
gl.uniform1f(uScale, scale);
|
|
577
|
+
gl.uniform1f(uRatio, width / height);
|
|
578
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
579
|
+
};
|
|
580
|
+
return {
|
|
581
|
+
clear,
|
|
582
|
+
cleanup,
|
|
583
|
+
draw
|
|
584
|
+
};
|
|
585
|
+
};
|
|
586
|
+
var dreamyZoom = makeHtmlInCanvasPresentation(dreamyZoomShader);
|
|
587
|
+
|
|
79
588
|
// src/timings/linear-timing.ts
|
|
80
589
|
import { interpolate } from "remotion";
|
|
81
590
|
var linearTiming = (options) => {
|
|
@@ -123,33 +632,33 @@ var springTiming = (options = {}) => {
|
|
|
123
632
|
};
|
|
124
633
|
};
|
|
125
634
|
// src/TransitionSeries.tsx
|
|
126
|
-
import { Children, useCallback, useMemo as
|
|
127
|
-
import { Internals, Sequence, useCurrentFrame, useVideoConfig } from "remotion";
|
|
635
|
+
import { Children, useCallback as useCallback2, useMemo as useMemo4, useRef as useRef2 } from "react";
|
|
636
|
+
import { Internals as Internals2, Sequence, useCurrentFrame, useVideoConfig } from "remotion";
|
|
128
637
|
import { NoReactInternals as NoReactInternals2 } from "remotion/no-react";
|
|
129
638
|
|
|
130
639
|
// src/context.tsx
|
|
131
|
-
import React2, { useMemo as
|
|
132
|
-
import { jsx as
|
|
640
|
+
import React2, { useMemo as useMemo3 } from "react";
|
|
641
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
133
642
|
var EnteringContext = React2.createContext(null);
|
|
134
643
|
var ExitingContext = React2.createContext(null);
|
|
135
644
|
var WrapInEnteringProgressContext = ({ presentationProgress, children }) => {
|
|
136
|
-
const value =
|
|
645
|
+
const value = useMemo3(() => {
|
|
137
646
|
return {
|
|
138
647
|
enteringProgress: presentationProgress
|
|
139
648
|
};
|
|
140
649
|
}, [presentationProgress]);
|
|
141
|
-
return /* @__PURE__ */
|
|
650
|
+
return /* @__PURE__ */ jsx3(EnteringContext.Provider, {
|
|
142
651
|
value,
|
|
143
652
|
children
|
|
144
653
|
});
|
|
145
654
|
};
|
|
146
655
|
var WrapInExitingProgressContext = ({ presentationProgress, children }) => {
|
|
147
|
-
const value =
|
|
656
|
+
const value = useMemo3(() => {
|
|
148
657
|
return {
|
|
149
658
|
exitingProgress: presentationProgress
|
|
150
659
|
};
|
|
151
660
|
}, [presentationProgress]);
|
|
152
|
-
return /* @__PURE__ */
|
|
661
|
+
return /* @__PURE__ */ jsx3(ExitingContext.Provider, {
|
|
153
662
|
value,
|
|
154
663
|
children
|
|
155
664
|
});
|
|
@@ -173,7 +682,7 @@ import { NoReactInternals } from "remotion/no-react";
|
|
|
173
682
|
var validateDurationInFrames = NoReactInternals.validateDurationInFrames;
|
|
174
683
|
|
|
175
684
|
// src/TransitionSeries.tsx
|
|
176
|
-
import { jsx as
|
|
685
|
+
import { jsx as jsx4, Fragment } from "react/jsx-runtime";
|
|
177
686
|
var TransitionSeriesTransition = function(_props) {
|
|
178
687
|
return null;
|
|
179
688
|
};
|
|
@@ -181,7 +690,7 @@ var SeriesOverlay = () => {
|
|
|
181
690
|
return null;
|
|
182
691
|
};
|
|
183
692
|
var SeriesSequence = ({ children }) => {
|
|
184
|
-
return /* @__PURE__ */
|
|
693
|
+
return /* @__PURE__ */ jsx4(Fragment, {
|
|
185
694
|
children
|
|
186
695
|
});
|
|
187
696
|
};
|
|
@@ -190,12 +699,12 @@ var TransitionSeriesChildren = ({
|
|
|
190
699
|
}) => {
|
|
191
700
|
const { fps } = useVideoConfig();
|
|
192
701
|
const frame = useCurrentFrame();
|
|
193
|
-
const prevImageRef =
|
|
194
|
-
const nextImageRef =
|
|
195
|
-
const flattedChildren =
|
|
702
|
+
const prevImageRef = useRef2({});
|
|
703
|
+
const nextImageRef = useRef2({});
|
|
704
|
+
const flattedChildren = useMemo4(() => {
|
|
196
705
|
return flattenChildren(children);
|
|
197
706
|
}, [children]);
|
|
198
|
-
const drawIfSynced =
|
|
707
|
+
const drawIfSynced = useCallback2((index) => {
|
|
199
708
|
const prevImage = prevImageRef?.current?.[index];
|
|
200
709
|
const nextImage = nextImageRef?.current?.[index];
|
|
201
710
|
if (!nextImage?.elementImage && prevImage?.elementImage) {
|
|
@@ -213,15 +722,15 @@ var TransitionSeriesChildren = ({
|
|
|
213
722
|
nextImage?.draw?.(null, null, 0);
|
|
214
723
|
}
|
|
215
724
|
}, []);
|
|
216
|
-
const onNextElementImage =
|
|
725
|
+
const onNextElementImage = useCallback2((elementImage, progress, draw, index) => {
|
|
217
726
|
prevImageRef.current[index] = { elementImage, progress, draw };
|
|
218
727
|
drawIfSynced(index);
|
|
219
728
|
}, [drawIfSynced]);
|
|
220
|
-
const onPrevElementImage =
|
|
729
|
+
const onPrevElementImage = useCallback2((elementImage, progress, draw, index) => {
|
|
221
730
|
nextImageRef.current[index] = { elementImage, progress, draw };
|
|
222
731
|
drawIfSynced(index);
|
|
223
732
|
}, [drawIfSynced]);
|
|
224
|
-
const childrenValue =
|
|
733
|
+
const childrenValue = useMemo4(() => {
|
|
225
734
|
let transitionOffsets = 0;
|
|
226
735
|
let startFrame = 0;
|
|
227
736
|
const overlayRenders = [];
|
|
@@ -369,12 +878,13 @@ var TransitionSeriesChildren = ({
|
|
|
369
878
|
const prevPresentation = prev.props.presentation ?? slide();
|
|
370
879
|
const UppercaseNextPresentation = nextPresentation.component;
|
|
371
880
|
const UppercasePrevPresentation = prevPresentation.component;
|
|
372
|
-
return /* @__PURE__ */
|
|
881
|
+
return /* @__PURE__ */ jsx4(Sequence, {
|
|
373
882
|
from: actualStartFrame,
|
|
374
883
|
durationInFrames: durationInFramesProp,
|
|
375
884
|
...passedProps,
|
|
376
885
|
name: passedProps.name || "<TS.Sequence>",
|
|
377
|
-
|
|
886
|
+
_remotionInternalDocumentationLink: passedProps.name ? undefined : "https://www.remotion.dev/docs/transitions/transitionseries",
|
|
887
|
+
children: /* @__PURE__ */ jsx4(UppercaseNextPresentation, {
|
|
378
888
|
passedProps: nextPresentation.props ?? {},
|
|
379
889
|
presentationDirection: "exiting",
|
|
380
890
|
presentationProgress: nextProgress,
|
|
@@ -386,9 +896,9 @@ var TransitionSeriesChildren = ({
|
|
|
386
896
|
throw new Error("Should not call when exiting");
|
|
387
897
|
},
|
|
388
898
|
bothEnteringAndExiting: true,
|
|
389
|
-
children: /* @__PURE__ */
|
|
899
|
+
children: /* @__PURE__ */ jsx4(WrapInExitingProgressContext, {
|
|
390
900
|
presentationProgress: nextProgress,
|
|
391
|
-
children: /* @__PURE__ */
|
|
901
|
+
children: /* @__PURE__ */ jsx4(UppercasePrevPresentation, {
|
|
392
902
|
passedProps: prevPresentation.props ?? {},
|
|
393
903
|
presentationDirection: "entering",
|
|
394
904
|
presentationProgress: prevProgress,
|
|
@@ -402,7 +912,7 @@ var TransitionSeriesChildren = ({
|
|
|
402
912
|
onNextElementImage(null, null, null, i - 1);
|
|
403
913
|
},
|
|
404
914
|
bothEnteringAndExiting: true,
|
|
405
|
-
children: /* @__PURE__ */
|
|
915
|
+
children: /* @__PURE__ */ jsx4(WrapInEnteringProgressContext, {
|
|
406
916
|
presentationProgress: prevProgress,
|
|
407
917
|
children: child
|
|
408
918
|
})
|
|
@@ -414,12 +924,13 @@ var TransitionSeriesChildren = ({
|
|
|
414
924
|
if (prevProgress !== null && prev) {
|
|
415
925
|
const prevPresentation = prev.props.presentation ?? slide();
|
|
416
926
|
const UppercasePrevPresentation = prevPresentation.component;
|
|
417
|
-
return /* @__PURE__ */
|
|
927
|
+
return /* @__PURE__ */ jsx4(Sequence, {
|
|
418
928
|
from: actualStartFrame,
|
|
419
929
|
durationInFrames: durationInFramesProp,
|
|
420
930
|
...passedProps,
|
|
421
931
|
name: passedProps.name || "<TS.Sequence>",
|
|
422
|
-
|
|
932
|
+
_remotionInternalDocumentationLink: passedProps.name ? undefined : "https://www.remotion.dev/docs/transitions/transitionseries",
|
|
933
|
+
children: /* @__PURE__ */ jsx4(UppercasePrevPresentation, {
|
|
423
934
|
passedProps: prevPresentation.props ?? {},
|
|
424
935
|
presentationDirection: "entering",
|
|
425
936
|
presentationProgress: prevProgress,
|
|
@@ -429,7 +940,7 @@ var TransitionSeriesChildren = ({
|
|
|
429
940
|
onNextElementImage(null, null, null, i - 1);
|
|
430
941
|
},
|
|
431
942
|
bothEnteringAndExiting: false,
|
|
432
|
-
children: /* @__PURE__ */
|
|
943
|
+
children: /* @__PURE__ */ jsx4(WrapInEnteringProgressContext, {
|
|
433
944
|
presentationProgress: prevProgress,
|
|
434
945
|
children: child
|
|
435
946
|
})
|
|
@@ -439,12 +950,13 @@ var TransitionSeriesChildren = ({
|
|
|
439
950
|
if (nextProgress !== null && next) {
|
|
440
951
|
const nextPresentation = next.props.presentation ?? slide();
|
|
441
952
|
const UppercaseNextPresentation = nextPresentation.component;
|
|
442
|
-
return /* @__PURE__ */
|
|
953
|
+
return /* @__PURE__ */ jsx4(Sequence, {
|
|
443
954
|
from: actualStartFrame,
|
|
444
955
|
durationInFrames: durationInFramesProp,
|
|
445
956
|
...passedProps,
|
|
446
957
|
name: passedProps.name || "<TS.Sequence>",
|
|
447
|
-
|
|
958
|
+
_remotionInternalDocumentationLink: passedProps.name ? undefined : "https://www.remotion.dev/docs/transitions/transitionseries",
|
|
959
|
+
children: /* @__PURE__ */ jsx4(UppercaseNextPresentation, {
|
|
448
960
|
passedProps: nextPresentation.props ?? {},
|
|
449
961
|
presentationDirection: "exiting",
|
|
450
962
|
presentationProgress: nextProgress,
|
|
@@ -454,27 +966,29 @@ var TransitionSeriesChildren = ({
|
|
|
454
966
|
onPrevElementImage(null, null, null, i + 1);
|
|
455
967
|
},
|
|
456
968
|
bothEnteringAndExiting: false,
|
|
457
|
-
children: /* @__PURE__ */
|
|
969
|
+
children: /* @__PURE__ */ jsx4(WrapInExitingProgressContext, {
|
|
458
970
|
presentationProgress: nextProgress,
|
|
459
971
|
children: child
|
|
460
972
|
})
|
|
461
973
|
})
|
|
462
974
|
}, i);
|
|
463
975
|
}
|
|
464
|
-
return /* @__PURE__ */
|
|
976
|
+
return /* @__PURE__ */ jsx4(Sequence, {
|
|
465
977
|
from: actualStartFrame,
|
|
466
978
|
durationInFrames: durationInFramesProp,
|
|
467
979
|
...passedProps,
|
|
468
980
|
name: passedProps.name || "<TS.Sequence>",
|
|
981
|
+
_remotionInternalDocumentationLink: passedProps.name ? undefined : "https://www.remotion.dev/docs/transitions/transitionseries",
|
|
469
982
|
children: child
|
|
470
983
|
}, i);
|
|
471
984
|
});
|
|
472
985
|
const overlayElements = overlayRenders.map((overlayInfo) => {
|
|
473
986
|
const info = overlayInfo;
|
|
474
|
-
return /* @__PURE__ */
|
|
987
|
+
return /* @__PURE__ */ jsx4(Sequence, {
|
|
475
988
|
from: Math.round(info.overlayFrom),
|
|
476
989
|
durationInFrames: info.durationInFrames,
|
|
477
990
|
name: "<TS.Overlay>",
|
|
991
|
+
_remotionInternalDocumentationLink: "https://www.remotion.dev/docs/transitions/transitionseries",
|
|
478
992
|
layout: "absolute-fill",
|
|
479
993
|
...info.stack ? { stack: info.stack } : {},
|
|
480
994
|
children: info.children
|
|
@@ -482,7 +996,7 @@ var TransitionSeriesChildren = ({
|
|
|
482
996
|
});
|
|
483
997
|
return [...mainChildren || [], ...overlayElements];
|
|
484
998
|
}, [flattedChildren, fps, frame, onPrevElementImage, onNextElementImage]);
|
|
485
|
-
return /* @__PURE__ */
|
|
999
|
+
return /* @__PURE__ */ jsx4(Fragment, {
|
|
486
1000
|
children: childrenValue
|
|
487
1001
|
});
|
|
488
1002
|
};
|
|
@@ -492,11 +1006,12 @@ var TransitionSeries = ({ children, name, layout: passedLayout, ...otherProps })
|
|
|
492
1006
|
if (NoReactInternals2.ENABLE_V5_BREAKING_CHANGES && layout !== "absolute-fill") {
|
|
493
1007
|
throw new TypeError(`The "layout" prop of <TransitionSeries /> is not supported anymore in v5. TransitionSeries' must be absolutely positioned.`);
|
|
494
1008
|
}
|
|
495
|
-
return /* @__PURE__ */
|
|
1009
|
+
return /* @__PURE__ */ jsx4(Sequence, {
|
|
496
1010
|
name: displayName,
|
|
497
1011
|
layout,
|
|
1012
|
+
_remotionInternalDocumentationLink: name === undefined ? "https://www.remotion.dev/docs/transitions/transitionseries" : undefined,
|
|
498
1013
|
...otherProps,
|
|
499
|
-
children: /* @__PURE__ */
|
|
1014
|
+
children: /* @__PURE__ */ jsx4(TransitionSeriesChildren, {
|
|
500
1015
|
children
|
|
501
1016
|
})
|
|
502
1017
|
});
|
|
@@ -504,9 +1019,9 @@ var TransitionSeries = ({ children, name, layout: passedLayout, ...otherProps })
|
|
|
504
1019
|
TransitionSeries.Sequence = SeriesSequence;
|
|
505
1020
|
TransitionSeries.Transition = TransitionSeriesTransition;
|
|
506
1021
|
TransitionSeries.Overlay = SeriesOverlay;
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
1022
|
+
Internals2.addSequenceStackTraces(TransitionSeries);
|
|
1023
|
+
Internals2.addSequenceStackTraces(SeriesSequence);
|
|
1024
|
+
Internals2.addSequenceStackTraces(SeriesOverlay);
|
|
510
1025
|
// src/use-transition-progress.ts
|
|
511
1026
|
import React5 from "react";
|
|
512
1027
|
var useTransitionProgress = () => {
|
|
@@ -525,183 +1040,12 @@ var useTransitionProgress = () => {
|
|
|
525
1040
|
exiting: exiting?.exitingProgress ?? 0
|
|
526
1041
|
};
|
|
527
1042
|
};
|
|
528
|
-
// src/html-in-canvas-presentation.tsx
|
|
529
|
-
import { useLayoutEffect, useMemo as useMemo4, useRef as useRef2, useState, useCallback as useCallback2 } from "react";
|
|
530
|
-
import {
|
|
531
|
-
HtmlInCanvas,
|
|
532
|
-
HTML_IN_CANVAS_UNSUPPORTED_MESSAGE,
|
|
533
|
-
useDelayRender
|
|
534
|
-
} from "remotion";
|
|
535
|
-
import { AbsoluteFill as AbsoluteFill2, Internals as Internals2 } from "remotion";
|
|
536
|
-
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
537
|
-
var HtmlInCanvasPresentation = ({
|
|
538
|
-
children,
|
|
539
|
-
onElementImage,
|
|
540
|
-
onUnmount,
|
|
541
|
-
presentationProgress,
|
|
542
|
-
presentationDirection,
|
|
543
|
-
shader,
|
|
544
|
-
_experimentalEffects,
|
|
545
|
-
passedProps,
|
|
546
|
-
bothEnteringAndExiting
|
|
547
|
-
}) => {
|
|
548
|
-
if (!HtmlInCanvas.isSupported()) {
|
|
549
|
-
throw new Error(HTML_IN_CANVAS_UNSUPPORTED_MESSAGE);
|
|
550
|
-
}
|
|
551
|
-
const canvasRef = useRef2(null);
|
|
552
|
-
const canvasSubtreeStyle = useMemo4(() => {
|
|
553
|
-
return {
|
|
554
|
-
width: "100%",
|
|
555
|
-
height: "100%",
|
|
556
|
-
position: "absolute",
|
|
557
|
-
top: 0,
|
|
558
|
-
left: 0,
|
|
559
|
-
right: 0,
|
|
560
|
-
bottom: 0
|
|
561
|
-
};
|
|
562
|
-
}, []);
|
|
563
|
-
const [offscreenCanvas] = useState(() => new OffscreenCanvas(1, 1));
|
|
564
|
-
const passedPropsRef = useRef2(passedProps);
|
|
565
|
-
passedPropsRef.current = passedProps;
|
|
566
|
-
const memoizedEffects = Internals2.useMemoizedEffects({
|
|
567
|
-
effects: _experimentalEffects ?? [],
|
|
568
|
-
overrideId: null
|
|
569
|
-
});
|
|
570
|
-
const effectsRef = useRef2(memoizedEffects);
|
|
571
|
-
effectsRef.current = memoizedEffects;
|
|
572
|
-
const [instance] = useState(() => shader(offscreenCanvas));
|
|
573
|
-
useLayoutEffect(() => {
|
|
574
|
-
return () => {
|
|
575
|
-
instance.cleanup();
|
|
576
|
-
};
|
|
577
|
-
}, [offscreenCanvas, instance]);
|
|
578
|
-
const chainState = Internals2.useEffectChainState();
|
|
579
|
-
const { delayRender, continueRender } = useDelayRender();
|
|
580
|
-
const draw = useCallback2(async (prevImage, nextImage, progress) => {
|
|
581
|
-
if (!canvasRef.current) {
|
|
582
|
-
throw new Error("Canvas not found");
|
|
583
|
-
}
|
|
584
|
-
const handle = delayRender("onPaint");
|
|
585
|
-
if (!prevImage && !nextImage) {
|
|
586
|
-
continueRender(handle);
|
|
587
|
-
instance.clear();
|
|
588
|
-
return;
|
|
589
|
-
}
|
|
590
|
-
const width = prevImage?.width ?? nextImage?.width ?? 0;
|
|
591
|
-
const height = prevImage?.height ?? nextImage?.height ?? 0;
|
|
592
|
-
if (width === 0 || height === 0) {
|
|
593
|
-
continueRender(handle);
|
|
594
|
-
instance.clear();
|
|
595
|
-
return;
|
|
596
|
-
}
|
|
597
|
-
offscreenCanvas.width = width;
|
|
598
|
-
offscreenCanvas.height = height;
|
|
599
|
-
instance.draw({
|
|
600
|
-
prevImage,
|
|
601
|
-
nextImage,
|
|
602
|
-
width,
|
|
603
|
-
height,
|
|
604
|
-
time: progress,
|
|
605
|
-
passedProps: passedPropsRef.current
|
|
606
|
-
});
|
|
607
|
-
await Internals2.runEffectChain({
|
|
608
|
-
state: chainState.get(width, height),
|
|
609
|
-
source: offscreenCanvas,
|
|
610
|
-
effects: effectsRef.current ?? [],
|
|
611
|
-
width,
|
|
612
|
-
height,
|
|
613
|
-
output: canvasRef.current
|
|
614
|
-
});
|
|
615
|
-
continueRender(handle);
|
|
616
|
-
}, [chainState, instance, offscreenCanvas, continueRender, delayRender]);
|
|
617
|
-
const passThrough = bothEnteringAndExiting && presentationDirection === "exiting";
|
|
618
|
-
useLayoutEffect(() => {
|
|
619
|
-
if (passThrough) {
|
|
620
|
-
return;
|
|
621
|
-
}
|
|
622
|
-
const canvas = canvasRef.current;
|
|
623
|
-
if (!canvas) {
|
|
624
|
-
throw new Error("Canvas not found");
|
|
625
|
-
}
|
|
626
|
-
canvas.layoutSubtree = true;
|
|
627
|
-
const onPaint = () => {
|
|
628
|
-
const firstChild = canvas.firstChild;
|
|
629
|
-
if (!firstChild) {
|
|
630
|
-
return;
|
|
631
|
-
}
|
|
632
|
-
const elementImage = canvas.captureElementImage(firstChild);
|
|
633
|
-
onElementImage(elementImage, draw);
|
|
634
|
-
};
|
|
635
|
-
canvas.addEventListener("paint", onPaint);
|
|
636
|
-
return () => {
|
|
637
|
-
canvas.removeEventListener("paint", onPaint);
|
|
638
|
-
};
|
|
639
|
-
}, [onElementImage, presentationDirection, draw, passThrough]);
|
|
640
|
-
useLayoutEffect(() => {
|
|
641
|
-
if (passThrough) {
|
|
642
|
-
return;
|
|
643
|
-
}
|
|
644
|
-
const canvas = canvasRef.current;
|
|
645
|
-
if (!canvas) {
|
|
646
|
-
throw new Error("Canvas not found");
|
|
647
|
-
}
|
|
648
|
-
canvas.requestPaint?.();
|
|
649
|
-
}, [presentationProgress, passThrough, memoizedEffects]);
|
|
650
|
-
useLayoutEffect(() => {
|
|
651
|
-
if (passThrough) {
|
|
652
|
-
return;
|
|
653
|
-
}
|
|
654
|
-
return () => {
|
|
655
|
-
onUnmount();
|
|
656
|
-
};
|
|
657
|
-
}, [onUnmount, passThrough]);
|
|
658
|
-
useLayoutEffect(() => {
|
|
659
|
-
if (passThrough) {
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
662
|
-
const canvas = canvasRef.current;
|
|
663
|
-
if (!canvas) {
|
|
664
|
-
return;
|
|
665
|
-
}
|
|
666
|
-
const observer = new ResizeObserver(([entry]) => {
|
|
667
|
-
canvas.width = entry.devicePixelContentBoxSize[0].inlineSize;
|
|
668
|
-
canvas.height = entry.devicePixelContentBoxSize[0].blockSize;
|
|
669
|
-
});
|
|
670
|
-
observer.observe(canvas, { box: "device-pixel-content-box" });
|
|
671
|
-
}, [passThrough]);
|
|
672
|
-
if (passThrough) {
|
|
673
|
-
return children;
|
|
674
|
-
}
|
|
675
|
-
return /* @__PURE__ */ jsx4(AbsoluteFill2, {
|
|
676
|
-
children: /* @__PURE__ */ jsx4("canvas", {
|
|
677
|
-
ref: canvasRef,
|
|
678
|
-
style: canvasSubtreeStyle,
|
|
679
|
-
children
|
|
680
|
-
})
|
|
681
|
-
});
|
|
682
|
-
};
|
|
683
|
-
var makeHtmlInCanvasPresentation = (shader) => {
|
|
684
|
-
const CompWithShader = (props) => {
|
|
685
|
-
const { passedProps, ...otherProps } = props;
|
|
686
|
-
const { _experimentalEffects, ...restPassedProps } = props.passedProps;
|
|
687
|
-
return /* @__PURE__ */ jsx4(HtmlInCanvasPresentation, {
|
|
688
|
-
shader,
|
|
689
|
-
passedProps: restPassedProps,
|
|
690
|
-
_experimentalEffects,
|
|
691
|
-
...otherProps
|
|
692
|
-
});
|
|
693
|
-
};
|
|
694
|
-
return (props) => {
|
|
695
|
-
return {
|
|
696
|
-
component: CompWithShader,
|
|
697
|
-
props
|
|
698
|
-
};
|
|
699
|
-
};
|
|
700
|
-
};
|
|
701
1043
|
export {
|
|
702
1044
|
useTransitionProgress,
|
|
703
1045
|
springTiming,
|
|
704
1046
|
makeHtmlInCanvasPresentation,
|
|
705
1047
|
linearTiming,
|
|
1048
|
+
linearBlur,
|
|
1049
|
+
dreamyZoom,
|
|
706
1050
|
TransitionSeries
|
|
707
1051
|
};
|