@remotion/transitions 4.0.465 → 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/book-flip.js +2 -0
- package/cross-zoom.js +2 -0
- package/crosswarp.js +2 -0
- package/dist/TransitionSeries.js +16 -6
- package/dist/esm/book-flip.mjs +434 -0
- package/dist/esm/cross-zoom.mjs +377 -0
- package/dist/esm/crosswarp.mjs +331 -0
- package/dist/esm/dissolve.mjs +4 -3
- package/dist/esm/dreamy-zoom.mjs +348 -0
- package/dist/esm/film-burn.mjs +443 -0
- package/dist/esm/index.mjs +1020 -209
- package/dist/esm/linear-blur.mjs +343 -0
- package/dist/esm/ripple.mjs +342 -0
- package/dist/esm/swap.mjs +394 -0
- package/dist/esm/zoom-blur.mjs +4 -3
- package/dist/esm/zoom-in-out.mjs +4 -3
- package/dist/html-in-canvas-presentation.js +4 -5
- package/dist/index.d.ts +13 -3
- package/dist/index.js +9 -1
- package/dist/presentations/book-flip.d.ts +14 -0
- package/dist/presentations/book-flip.js +255 -0
- package/dist/presentations/cross-zoom.d.ts +13 -0
- package/dist/presentations/cross-zoom.js +199 -0
- package/dist/presentations/crosswarp.d.ts +11 -0
- package/dist/presentations/crosswarp.js +154 -0
- package/dist/presentations/dreamy-zoom.d.ts +14 -0
- package/dist/presentations/dreamy-zoom.js +169 -0
- package/dist/presentations/film-burn.d.ts +13 -0
- package/dist/presentations/film-burn.js +265 -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/types.d.ts +1 -1
- package/dreamy-zoom.js +2 -0
- package/film-burn.js +2 -0
- package/linear-blur.js +2 -0
- package/package.json +80 -8
- package/ripple.js +2 -0
- package/swap.js +2 -0
|
@@ -0,0 +1,348 @@
|
|
|
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/dreamy-zoom.tsx
|
|
177
|
+
var DEFAULT_ROTATION = 6;
|
|
178
|
+
var DEFAULT_SCALE = 1.2;
|
|
179
|
+
var VERTEX_SHADER = `#version 300 es
|
|
180
|
+
in vec2 a_pos;
|
|
181
|
+
out vec2 v_uv;
|
|
182
|
+
void main() {
|
|
183
|
+
v_uv = vec2(a_pos.x * 0.5 + 0.5, 0.5 - a_pos.y * 0.5);
|
|
184
|
+
gl_Position = vec4(a_pos, 0.0, 1.0);
|
|
185
|
+
}`;
|
|
186
|
+
var FRAGMENT_SHADER = `#version 300 es
|
|
187
|
+
precision highp float;
|
|
188
|
+
|
|
189
|
+
uniform sampler2D u_prev;
|
|
190
|
+
uniform sampler2D u_next;
|
|
191
|
+
uniform float u_time;
|
|
192
|
+
uniform float u_rotation;
|
|
193
|
+
uniform float u_scale;
|
|
194
|
+
uniform float u_ratio;
|
|
195
|
+
|
|
196
|
+
in vec2 v_uv;
|
|
197
|
+
out vec4 outColor;
|
|
198
|
+
|
|
199
|
+
const float DEG2RAD = 0.03926990816987241548078304229099;
|
|
200
|
+
|
|
201
|
+
vec4 transition(vec2 uv, float progress) {
|
|
202
|
+
float phase = progress < 0.5 ? progress * 2.0 : (progress - 0.5) * 2.0;
|
|
203
|
+
float angleOffset = progress < 0.5 ? mix(0.0, u_rotation * DEG2RAD, phase) : mix(-u_rotation * DEG2RAD, 0.0, phase);
|
|
204
|
+
float newScale = progress < 0.5 ? mix(1.0, u_scale, phase) : mix(u_scale, 1.0, phase);
|
|
205
|
+
|
|
206
|
+
vec2 center = vec2(0.0, 0.0);
|
|
207
|
+
vec2 p = (uv.xy - vec2(0.5, 0.5)) / newScale * vec2(u_ratio, 1.0);
|
|
208
|
+
float angle = atan(p.y, p.x) + angleOffset;
|
|
209
|
+
float dist = distance(center, p);
|
|
210
|
+
|
|
211
|
+
p.x = cos(angle) * dist / u_ratio + 0.5;
|
|
212
|
+
p.y = sin(angle) * dist + 0.5;
|
|
213
|
+
|
|
214
|
+
vec4 c = progress < 0.5 ? texture(u_prev, p) : texture(u_next, p);
|
|
215
|
+
return c + (progress < 0.5 ? mix(0.0, 1.0, phase) : mix(1.0, 0.0, phase));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
void main() {
|
|
219
|
+
float progress = 1.0 - u_time;
|
|
220
|
+
outColor = transition(v_uv, progress);
|
|
221
|
+
}`;
|
|
222
|
+
var compileShader = (gl, source, type) => {
|
|
223
|
+
const shader = gl.createShader(type);
|
|
224
|
+
if (!shader) {
|
|
225
|
+
throw new Error("Failed to create shader");
|
|
226
|
+
}
|
|
227
|
+
gl.shaderSource(shader, source);
|
|
228
|
+
gl.compileShader(shader);
|
|
229
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
230
|
+
const log = gl.getShaderInfoLog(shader);
|
|
231
|
+
gl.deleteShader(shader);
|
|
232
|
+
throw new Error(`Failed to compile shader: ${log}`);
|
|
233
|
+
}
|
|
234
|
+
return shader;
|
|
235
|
+
};
|
|
236
|
+
var createProgram = (gl) => {
|
|
237
|
+
const program = gl.createProgram();
|
|
238
|
+
if (!program) {
|
|
239
|
+
throw new Error("Failed to create WebGL program");
|
|
240
|
+
}
|
|
241
|
+
const vs = compileShader(gl, VERTEX_SHADER, gl.VERTEX_SHADER);
|
|
242
|
+
const fs = compileShader(gl, FRAGMENT_SHADER, gl.FRAGMENT_SHADER);
|
|
243
|
+
gl.attachShader(program, vs);
|
|
244
|
+
gl.attachShader(program, fs);
|
|
245
|
+
gl.linkProgram(program);
|
|
246
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
247
|
+
const log = gl.getProgramInfoLog(program);
|
|
248
|
+
gl.deleteProgram(program);
|
|
249
|
+
throw new Error(`Failed to link program: ${log}`);
|
|
250
|
+
}
|
|
251
|
+
return program;
|
|
252
|
+
};
|
|
253
|
+
var createTexture = (gl) => {
|
|
254
|
+
const tex = gl.createTexture();
|
|
255
|
+
if (!tex) {
|
|
256
|
+
throw new Error("Failed to create texture");
|
|
257
|
+
}
|
|
258
|
+
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
259
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
260
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
261
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
262
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
263
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0, 0]));
|
|
264
|
+
return tex;
|
|
265
|
+
};
|
|
266
|
+
var dreamyZoomShader = (canvas) => {
|
|
267
|
+
const gl = canvas.getContext("webgl2", { premultipliedAlpha: true });
|
|
268
|
+
if (!gl) {
|
|
269
|
+
throw new Error("Failed to create WebGL2 context");
|
|
270
|
+
}
|
|
271
|
+
const program = createProgram(gl);
|
|
272
|
+
const prevTex = createTexture(gl);
|
|
273
|
+
const nextTex = createTexture(gl);
|
|
274
|
+
const vao = gl.createVertexArray();
|
|
275
|
+
gl.bindVertexArray(vao);
|
|
276
|
+
const buffer = gl.createBuffer();
|
|
277
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
278
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);
|
|
279
|
+
const aPos = gl.getAttribLocation(program, "a_pos");
|
|
280
|
+
gl.enableVertexAttribArray(aPos);
|
|
281
|
+
gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);
|
|
282
|
+
const uTime = gl.getUniformLocation(program, "u_time");
|
|
283
|
+
const uPrev = gl.getUniformLocation(program, "u_prev");
|
|
284
|
+
const uNext = gl.getUniformLocation(program, "u_next");
|
|
285
|
+
const uRotation = gl.getUniformLocation(program, "u_rotation");
|
|
286
|
+
const uScale = gl.getUniformLocation(program, "u_scale");
|
|
287
|
+
const uRatio = gl.getUniformLocation(program, "u_ratio");
|
|
288
|
+
const cleanup = () => {
|
|
289
|
+
gl.deleteProgram(program);
|
|
290
|
+
gl.deleteTexture(prevTex);
|
|
291
|
+
gl.deleteTexture(nextTex);
|
|
292
|
+
};
|
|
293
|
+
const clear = () => {
|
|
294
|
+
gl.clearColor(0, 0, 0, 0);
|
|
295
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
296
|
+
};
|
|
297
|
+
const draw = ({
|
|
298
|
+
prevImage,
|
|
299
|
+
nextImage,
|
|
300
|
+
width,
|
|
301
|
+
height,
|
|
302
|
+
time,
|
|
303
|
+
passedProps
|
|
304
|
+
}) => {
|
|
305
|
+
const { rotation = DEFAULT_ROTATION, scale = DEFAULT_SCALE } = passedProps;
|
|
306
|
+
if (!prevImage && !nextImage) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (prevImage && (prevImage.width === 0 || prevImage.height === 0)) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (nextImage && (nextImage.width === 0 || nextImage.height === 0)) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
const effectiveTime = !prevImage ? 0 : !nextImage ? 1 : time;
|
|
316
|
+
gl.viewport(0, 0, width, height);
|
|
317
|
+
gl.clearColor(0, 0, 0, 0);
|
|
318
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
319
|
+
gl.useProgram(program);
|
|
320
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
321
|
+
gl.bindTexture(gl.TEXTURE_2D, prevTex);
|
|
322
|
+
if (prevImage) {
|
|
323
|
+
gl.texElementImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, prevImage);
|
|
324
|
+
}
|
|
325
|
+
gl.uniform1i(uPrev, 0);
|
|
326
|
+
gl.activeTexture(gl.TEXTURE1);
|
|
327
|
+
gl.bindTexture(gl.TEXTURE_2D, nextTex);
|
|
328
|
+
if (nextImage) {
|
|
329
|
+
gl.texElementImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, nextImage);
|
|
330
|
+
}
|
|
331
|
+
gl.uniform1i(uNext, 1);
|
|
332
|
+
gl.uniform1f(uTime, effectiveTime);
|
|
333
|
+
gl.uniform1f(uRotation, rotation);
|
|
334
|
+
gl.uniform1f(uScale, scale);
|
|
335
|
+
gl.uniform1f(uRatio, width / height);
|
|
336
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
337
|
+
};
|
|
338
|
+
return {
|
|
339
|
+
clear,
|
|
340
|
+
cleanup,
|
|
341
|
+
draw
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
var dreamyZoom = makeHtmlInCanvasPresentation(dreamyZoomShader);
|
|
345
|
+
export {
|
|
346
|
+
dreamyZoomShader,
|
|
347
|
+
dreamyZoom
|
|
348
|
+
};
|