@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.
Files changed (39) hide show
  1. package/book-flip.js +2 -0
  2. package/crosswarp.js +2 -0
  3. package/dissolve.js +2 -0
  4. package/dist/TransitionSeries.js +16 -6
  5. package/dist/esm/book-flip.mjs +433 -0
  6. package/dist/esm/crosswarp.mjs +330 -0
  7. package/dist/esm/dissolve.mjs +376 -0
  8. package/dist/esm/dreamy-zoom.mjs +347 -0
  9. package/dist/esm/index.mjs +553 -209
  10. package/dist/esm/linear-blur.mjs +342 -0
  11. package/dist/esm/ripple.mjs +341 -0
  12. package/dist/esm/swap.mjs +393 -0
  13. package/dist/esm/zoom-blur.mjs +4 -4
  14. package/dist/esm/zoom-in-out.mjs +4 -4
  15. package/dist/html-in-canvas-presentation.d.ts +4 -4
  16. package/dist/html-in-canvas-presentation.js +4 -4
  17. package/dist/index.d.ts +9 -3
  18. package/dist/index.js +5 -1
  19. package/dist/presentations/book-flip.d.ts +14 -0
  20. package/dist/presentations/book-flip.js +255 -0
  21. package/dist/presentations/crosswarp.d.ts +11 -0
  22. package/dist/presentations/crosswarp.js +154 -0
  23. package/dist/presentations/dissolve.d.ts +17 -0
  24. package/dist/presentations/dissolve.js +193 -0
  25. package/dist/presentations/dreamy-zoom.d.ts +14 -0
  26. package/dist/presentations/dreamy-zoom.js +169 -0
  27. package/dist/presentations/linear-blur.d.ts +13 -0
  28. package/dist/presentations/linear-blur.js +164 -0
  29. package/dist/presentations/ripple.d.ts +14 -0
  30. package/dist/presentations/ripple.js +164 -0
  31. package/dist/presentations/swap.d.ts +15 -0
  32. package/dist/presentations/swap.js +212 -0
  33. package/dist/presentations/zoom-blur.d.ts +2 -2
  34. package/dist/presentations/zoom-in-out.d.ts +2 -2
  35. package/dreamy-zoom.js +2 -0
  36. package/linear-blur.js +2 -0
  37. package/package.json +71 -8
  38. package/ripple.js +2 -0
  39. package/swap.js +2 -0
package/book-flip.js ADDED
@@ -0,0 +1,2 @@
1
+ // For backwards compatibility when you use `esm-wallaby`
2
+ module.exports = require('./dist/presentations/book-flip.js');
package/crosswarp.js ADDED
@@ -0,0 +1,2 @@
1
+ // For backwards compatibility when you use `esm-wallaby`
2
+ module.exports = require('./dist/presentations/crosswarp.js');
package/dissolve.js ADDED
@@ -0,0 +1,2 @@
1
+ // For backwards compatibility when you use `esm-wallaby`
2
+ module.exports = require('./dist/presentations/dissolve.js');
@@ -240,7 +240,9 @@ const TransitionSeriesChildren = ({ children, }) => {
240
240
  const UppercasePrevPresentation = prevPresentation.component;
241
241
  return (jsx_runtime_1.jsx(remotion_1.Sequence
242
242
  // eslint-disable-next-line react/no-array-index-key
243
- , { from: actualStartFrame, durationInFrames: durationInFramesProp, ...passedProps, name: passedProps.name || '<TS.Sequence>', children: jsx_runtime_1.jsx(UppercaseNextPresentation, { passedProps: (_e = nextPresentation.props) !== null && _e !== void 0 ? _e : {}, presentationDirection: "exiting", presentationProgress: nextProgress, presentationDurationInFrames: next.props.timing.getDurationInFrames({ fps }), onElementImage: () => {
243
+ , { from: actualStartFrame, durationInFrames: durationInFramesProp, ...passedProps, name: passedProps.name || '<TS.Sequence>', _remotionInternalDocumentationLink: passedProps.name
244
+ ? undefined
245
+ : 'https://www.remotion.dev/docs/transitions/transitionseries', children: jsx_runtime_1.jsx(UppercaseNextPresentation, { passedProps: (_e = nextPresentation.props) !== null && _e !== void 0 ? _e : {}, presentationDirection: "exiting", presentationProgress: nextProgress, presentationDurationInFrames: next.props.timing.getDurationInFrames({ fps }), onElementImage: () => {
244
246
  throw new Error('Should not call when exiting');
245
247
  }, onUnmount: () => {
246
248
  throw new Error('Should not call when exiting');
@@ -257,7 +259,9 @@ const TransitionSeriesChildren = ({ children, }) => {
257
259
  const UppercasePrevPresentation = prevPresentation.component;
258
260
  return (jsx_runtime_1.jsx(remotion_1.Sequence
259
261
  // eslint-disable-next-line react/no-array-index-key
260
- , { from: actualStartFrame, durationInFrames: durationInFramesProp, ...passedProps, name: passedProps.name || '<TS.Sequence>', children: jsx_runtime_1.jsx(UppercasePrevPresentation, { passedProps: (_h = prevPresentation.props) !== null && _h !== void 0 ? _h : {}, presentationDirection: "entering", presentationProgress: prevProgress, presentationDurationInFrames: prev.props.timing.getDurationInFrames({ fps }), onElementImage: (elementImage, draw) => onNextElementImage(elementImage, prevProgress, draw, i - 1), onUnmount: () => {
262
+ , { from: actualStartFrame, durationInFrames: durationInFramesProp, ...passedProps, name: passedProps.name || '<TS.Sequence>', _remotionInternalDocumentationLink: passedProps.name
263
+ ? undefined
264
+ : 'https://www.remotion.dev/docs/transitions/transitionseries', children: jsx_runtime_1.jsx(UppercasePrevPresentation, { passedProps: (_h = prevPresentation.props) !== null && _h !== void 0 ? _h : {}, presentationDirection: "entering", presentationProgress: prevProgress, presentationDurationInFrames: prev.props.timing.getDurationInFrames({ fps }), onElementImage: (elementImage, draw) => onNextElementImage(elementImage, prevProgress, draw, i - 1), onUnmount: () => {
261
265
  onNextElementImage(null, null, null, i - 1);
262
266
  }, bothEnteringAndExiting: false, children: jsx_runtime_1.jsx(context_js_1.WrapInEnteringProgressContext, { presentationProgress: prevProgress, children: child }) }) }, i));
263
267
  }
@@ -266,18 +270,22 @@ const TransitionSeriesChildren = ({ children, }) => {
266
270
  const UppercaseNextPresentation = nextPresentation.component;
267
271
  return (jsx_runtime_1.jsx(remotion_1.Sequence
268
272
  // eslint-disable-next-line react/no-array-index-key
269
- , { from: actualStartFrame, durationInFrames: durationInFramesProp, ...passedProps, name: passedProps.name || '<TS.Sequence>', children: jsx_runtime_1.jsx(UppercaseNextPresentation, { passedProps: (_k = nextPresentation.props) !== null && _k !== void 0 ? _k : {}, presentationDirection: "exiting", presentationProgress: nextProgress, presentationDurationInFrames: next.props.timing.getDurationInFrames({ fps }), onElementImage: (elementImage, draw) => onPrevElementImage(elementImage, nextProgress, draw, i + 1), onUnmount: () => {
273
+ , { from: actualStartFrame, durationInFrames: durationInFramesProp, ...passedProps, name: passedProps.name || '<TS.Sequence>', _remotionInternalDocumentationLink: passedProps.name
274
+ ? undefined
275
+ : 'https://www.remotion.dev/docs/transitions/transitionseries', children: jsx_runtime_1.jsx(UppercaseNextPresentation, { passedProps: (_k = nextPresentation.props) !== null && _k !== void 0 ? _k : {}, presentationDirection: "exiting", presentationProgress: nextProgress, presentationDurationInFrames: next.props.timing.getDurationInFrames({ fps }), onElementImage: (elementImage, draw) => onPrevElementImage(elementImage, nextProgress, draw, i + 1), onUnmount: () => {
270
276
  onPrevElementImage(null, null, null, i + 1);
271
277
  }, bothEnteringAndExiting: false, children: jsx_runtime_1.jsx(context_js_1.WrapInExitingProgressContext, { presentationProgress: nextProgress, children: child }) }) }, i));
272
278
  }
273
279
  return (jsx_runtime_1.jsx(remotion_1.Sequence
274
280
  // eslint-disable-next-line react/no-array-index-key
275
- , { from: actualStartFrame, durationInFrames: durationInFramesProp, ...passedProps, name: passedProps.name || '<TS.Sequence>', children: child }, i));
281
+ , { from: actualStartFrame, durationInFrames: durationInFramesProp, ...passedProps, name: passedProps.name || '<TS.Sequence>', _remotionInternalDocumentationLink: passedProps.name
282
+ ? undefined
283
+ : 'https://www.remotion.dev/docs/transitions/transitionseries', children: child }, i));
276
284
  });
277
285
  // Now render overlay sequences
278
286
  const overlayElements = overlayRenders.map((overlayInfo) => {
279
287
  const info = overlayInfo;
280
- return (jsx_runtime_1.jsx(remotion_1.Sequence, { from: Math.round(info.overlayFrom), durationInFrames: info.durationInFrames, name: "<TS.Overlay>", layout: "absolute-fill", ...(info.stack ? { stack: info.stack } : {}), children: info.children }, `overlay-${info.index}`));
288
+ return (jsx_runtime_1.jsx(remotion_1.Sequence, { from: Math.round(info.overlayFrom), durationInFrames: info.durationInFrames, name: "<TS.Overlay>", _remotionInternalDocumentationLink: "https://www.remotion.dev/docs/transitions/transitionseries", layout: "absolute-fill", ...(info.stack ? { stack: info.stack } : {}), children: info.children }, `overlay-${info.index}`));
281
289
  });
282
290
  return [...(mainChildren || []), ...overlayElements];
283
291
  }, [flattedChildren, fps, frame, onPrevElementImage, onNextElementImage]);
@@ -295,7 +303,9 @@ const TransitionSeries = ({ children, name, layout: passedLayout, ...otherProps
295
303
  layout !== 'absolute-fill') {
296
304
  throw new TypeError(`The "layout" prop of <TransitionSeries /> is not supported anymore in v5. TransitionSeries' must be absolutely positioned.`);
297
305
  }
298
- return (jsx_runtime_1.jsx(remotion_1.Sequence, { name: displayName, layout: layout, ...otherProps, children: jsx_runtime_1.jsx(TransitionSeriesChildren, { children: children }) }));
306
+ return (jsx_runtime_1.jsx(remotion_1.Sequence, { name: displayName, layout: layout, _remotionInternalDocumentationLink: name === undefined
307
+ ? 'https://www.remotion.dev/docs/transitions/transitionseries'
308
+ : undefined, ...otherProps, children: jsx_runtime_1.jsx(TransitionSeriesChildren, { children: children }) }));
299
309
  };
300
310
  exports.TransitionSeries = TransitionSeries;
301
311
  TransitionSeries.Sequence = SeriesSequence;
@@ -0,0 +1,433 @@
1
+ // src/html-in-canvas-presentation.tsx
2
+ import { useLayoutEffect, useMemo, useRef, useState, useCallback } from "react";
3
+ import {
4
+ HtmlInCanvas,
5
+ HTML_IN_CANVAS_UNSUPPORTED_MESSAGE,
6
+ useDelayRender
7
+ } from "remotion";
8
+ import { AbsoluteFill, Internals } from "remotion";
9
+ import { jsx } from "react/jsx-runtime";
10
+ var HtmlInCanvasPresentation = ({
11
+ children,
12
+ onElementImage,
13
+ onUnmount,
14
+ presentationProgress,
15
+ presentationDirection,
16
+ shader,
17
+ effects,
18
+ passedProps,
19
+ bothEnteringAndExiting
20
+ }) => {
21
+ if (!HtmlInCanvas.isSupported()) {
22
+ throw new Error(HTML_IN_CANVAS_UNSUPPORTED_MESSAGE);
23
+ }
24
+ const canvasRef = useRef(null);
25
+ const canvasSubtreeStyle = useMemo(() => {
26
+ return {
27
+ width: "100%",
28
+ height: "100%",
29
+ position: "absolute",
30
+ top: 0,
31
+ left: 0,
32
+ right: 0,
33
+ bottom: 0
34
+ };
35
+ }, []);
36
+ const [offscreenCanvas] = useState(() => new OffscreenCanvas(1, 1));
37
+ const passedPropsRef = useRef(passedProps);
38
+ passedPropsRef.current = passedProps;
39
+ const memoizedEffects = Internals.useMemoizedEffects({
40
+ effects: effects ?? [],
41
+ overrideId: null
42
+ });
43
+ const effectsRef = useRef(memoizedEffects);
44
+ effectsRef.current = memoizedEffects;
45
+ const [instance] = useState(() => shader(offscreenCanvas));
46
+ useLayoutEffect(() => {
47
+ return () => {
48
+ instance.cleanup();
49
+ };
50
+ }, [offscreenCanvas, instance]);
51
+ const chainState = Internals.useEffectChainState();
52
+ const { delayRender, continueRender } = useDelayRender();
53
+ const draw = useCallback(async (prevImage, nextImage, progress) => {
54
+ if (!canvasRef.current) {
55
+ throw new Error("Canvas not found");
56
+ }
57
+ const handle = delayRender("onPaint");
58
+ if (!prevImage && !nextImage) {
59
+ continueRender(handle);
60
+ instance.clear();
61
+ return;
62
+ }
63
+ const width = prevImage?.width ?? nextImage?.width ?? 0;
64
+ const height = prevImage?.height ?? nextImage?.height ?? 0;
65
+ if (width === 0 || height === 0) {
66
+ continueRender(handle);
67
+ instance.clear();
68
+ return;
69
+ }
70
+ offscreenCanvas.width = width;
71
+ offscreenCanvas.height = height;
72
+ instance.draw({
73
+ prevImage,
74
+ nextImage,
75
+ width,
76
+ height,
77
+ time: progress,
78
+ passedProps: passedPropsRef.current
79
+ });
80
+ await Internals.runEffectChain({
81
+ state: chainState.get(width, height),
82
+ source: offscreenCanvas,
83
+ effects: effectsRef.current ?? [],
84
+ width,
85
+ height,
86
+ output: canvasRef.current
87
+ });
88
+ continueRender(handle);
89
+ }, [chainState, instance, offscreenCanvas, continueRender, delayRender]);
90
+ const passThrough = bothEnteringAndExiting && presentationDirection === "exiting";
91
+ useLayoutEffect(() => {
92
+ if (passThrough) {
93
+ return;
94
+ }
95
+ const canvas = canvasRef.current;
96
+ if (!canvas) {
97
+ throw new Error("Canvas not found");
98
+ }
99
+ canvas.layoutSubtree = true;
100
+ const onPaint = () => {
101
+ const firstChild = canvas.firstChild;
102
+ if (!firstChild) {
103
+ return;
104
+ }
105
+ const elementImage = canvas.captureElementImage(firstChild);
106
+ onElementImage(elementImage, draw);
107
+ };
108
+ canvas.addEventListener("paint", onPaint);
109
+ return () => {
110
+ canvas.removeEventListener("paint", onPaint);
111
+ };
112
+ }, [onElementImage, presentationDirection, draw, passThrough]);
113
+ useLayoutEffect(() => {
114
+ if (passThrough) {
115
+ return;
116
+ }
117
+ const canvas = canvasRef.current;
118
+ if (!canvas) {
119
+ throw new Error("Canvas not found");
120
+ }
121
+ canvas.requestPaint?.();
122
+ }, [presentationProgress, passThrough, memoizedEffects]);
123
+ useLayoutEffect(() => {
124
+ if (passThrough) {
125
+ return;
126
+ }
127
+ return () => {
128
+ onUnmount();
129
+ };
130
+ }, [onUnmount, passThrough]);
131
+ useLayoutEffect(() => {
132
+ if (passThrough) {
133
+ return;
134
+ }
135
+ const canvas = canvasRef.current;
136
+ if (!canvas) {
137
+ return;
138
+ }
139
+ const observer = new ResizeObserver(([entry]) => {
140
+ canvas.width = entry.devicePixelContentBoxSize[0].inlineSize;
141
+ canvas.height = entry.devicePixelContentBoxSize[0].blockSize;
142
+ });
143
+ observer.observe(canvas, { box: "device-pixel-content-box" });
144
+ }, [passThrough]);
145
+ if (passThrough) {
146
+ return children;
147
+ }
148
+ return /* @__PURE__ */ jsx(AbsoluteFill, {
149
+ children: /* @__PURE__ */ jsx("canvas", {
150
+ ref: canvasRef,
151
+ style: canvasSubtreeStyle,
152
+ children
153
+ })
154
+ });
155
+ };
156
+ var makeHtmlInCanvasPresentation = (shader) => {
157
+ const CompWithShader = (props) => {
158
+ const { passedProps, ...otherProps } = props;
159
+ const { effects, ...restPassedProps } = props.passedProps;
160
+ return /* @__PURE__ */ jsx(HtmlInCanvasPresentation, {
161
+ shader,
162
+ passedProps: restPassedProps,
163
+ effects,
164
+ ...otherProps
165
+ });
166
+ };
167
+ return (props) => {
168
+ return {
169
+ component: CompWithShader,
170
+ props
171
+ };
172
+ };
173
+ };
174
+
175
+ // src/presentations/book-flip.tsx
176
+ var DIRECTION_FROM_LEFT = 0;
177
+ var DIRECTION_FROM_RIGHT = 1;
178
+ var DIRECTION_FROM_TOP = 2;
179
+ var DIRECTION_FROM_BOTTOM = 3;
180
+ var DEFAULT_DIRECTION = "from-right";
181
+ var VERTEX_SHADER = `#version 300 es
182
+ in vec2 a_pos;
183
+ out vec2 v_uv;
184
+ void main() {
185
+ v_uv = vec2(a_pos.x * 0.5 + 0.5, 0.5 - a_pos.y * 0.5);
186
+ gl_Position = vec4(a_pos, 0.0, 1.0);
187
+ }`;
188
+ var FRAGMENT_SHADER = `#version 300 es
189
+ precision highp float;
190
+
191
+ uniform sampler2D u_prev;
192
+ uniform sampler2D u_next;
193
+ uniform float u_time;
194
+ uniform float u_direction;
195
+
196
+ in vec2 v_uv;
197
+ out vec4 outColor;
198
+
199
+ const float EPSILON = 0.0001;
200
+
201
+ float avoidZero(float value) {
202
+ if (abs(value) < EPSILON) {
203
+ return value < 0.0 ? -EPSILON : EPSILON;
204
+ }
205
+
206
+ return value;
207
+ }
208
+
209
+ vec2 skewRight(vec2 p, float progress) {
210
+ float skewX = (p.x - progress) / avoidZero(0.5 - progress) * 0.5;
211
+ float skewY =
212
+ (p.y - 0.5) /
213
+ avoidZero(0.5 + progress * (p.x - 0.5) / 0.5) *
214
+ 0.5 +
215
+ 0.5;
216
+ return vec2(skewX, skewY);
217
+ }
218
+
219
+ vec2 skewLeft(vec2 p, float progress) {
220
+ float skewX = (p.x - 0.5) / avoidZero(progress - 0.5) * 0.5 + 0.5;
221
+ float skewY =
222
+ (p.y - 0.5) /
223
+ avoidZero(0.5 + (1.0 - progress) * (0.5 - p.x) / 0.5) *
224
+ 0.5 +
225
+ 0.5;
226
+ return vec2(skewX, skewY);
227
+ }
228
+
229
+ vec4 addShade(float progress) {
230
+ float shadeVal = max(0.7, abs(progress - 0.5) * 2.0);
231
+ return vec4(vec3(shadeVal), 1.0);
232
+ }
233
+
234
+ vec2 toCanonicalUv(vec2 p) {
235
+ if (u_direction < 0.5) {
236
+ return p;
237
+ }
238
+
239
+ if (u_direction < 1.5) {
240
+ return vec2(1.0 - p.x, p.y);
241
+ }
242
+
243
+ if (u_direction < 2.5) {
244
+ return vec2(p.y, 1.0 - p.x);
245
+ }
246
+
247
+ return vec2(1.0 - p.y, p.x);
248
+ }
249
+
250
+ vec2 fromCanonicalUv(vec2 p) {
251
+ if (u_direction < 0.5) {
252
+ return p;
253
+ }
254
+
255
+ if (u_direction < 1.5) {
256
+ return vec2(1.0 - p.x, p.y);
257
+ }
258
+
259
+ if (u_direction < 2.5) {
260
+ return vec2(1.0 - p.y, p.x);
261
+ }
262
+
263
+ return vec2(p.y, 1.0 - p.x);
264
+ }
265
+
266
+ vec4 samplePrev(vec2 p) {
267
+ return texture(u_prev, fromCanonicalUv(p));
268
+ }
269
+
270
+ vec4 sampleNext(vec2 p) {
271
+ return texture(u_next, fromCanonicalUv(p));
272
+ }
273
+
274
+ vec4 transition(vec2 p, float progress) {
275
+ float pr = step(1.0 - progress, p.x);
276
+
277
+ if (p.x < 0.5) {
278
+ return mix(
279
+ samplePrev(p),
280
+ sampleNext(skewLeft(p, progress)) * addShade(progress),
281
+ pr
282
+ );
283
+ }
284
+
285
+ return mix(
286
+ samplePrev(skewRight(p, progress)) * addShade(progress),
287
+ sampleNext(p),
288
+ pr
289
+ );
290
+ }
291
+
292
+ void main() {
293
+ vec2 p = toCanonicalUv(v_uv);
294
+ float progress = 1.0 - u_time;
295
+ outColor = transition(p, progress);
296
+ }`;
297
+ var compileShader = (gl, source, type) => {
298
+ const shader = gl.createShader(type);
299
+ if (!shader) {
300
+ throw new Error("Failed to create shader");
301
+ }
302
+ gl.shaderSource(shader, source);
303
+ gl.compileShader(shader);
304
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
305
+ const log = gl.getShaderInfoLog(shader);
306
+ gl.deleteShader(shader);
307
+ throw new Error(`Failed to compile shader: ${log}`);
308
+ }
309
+ return shader;
310
+ };
311
+ var createProgram = (gl) => {
312
+ const program = gl.createProgram();
313
+ if (!program) {
314
+ throw new Error("Failed to create WebGL program");
315
+ }
316
+ const vs = compileShader(gl, VERTEX_SHADER, gl.VERTEX_SHADER);
317
+ const fs = compileShader(gl, FRAGMENT_SHADER, gl.FRAGMENT_SHADER);
318
+ gl.attachShader(program, vs);
319
+ gl.attachShader(program, fs);
320
+ gl.linkProgram(program);
321
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
322
+ const log = gl.getProgramInfoLog(program);
323
+ gl.deleteProgram(program);
324
+ throw new Error(`Failed to link program: ${log}`);
325
+ }
326
+ return program;
327
+ };
328
+ var createTexture = (gl) => {
329
+ const tex = gl.createTexture();
330
+ if (!tex) {
331
+ throw new Error("Failed to create texture");
332
+ }
333
+ gl.bindTexture(gl.TEXTURE_2D, tex);
334
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
335
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
336
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
337
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
338
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0, 0]));
339
+ return tex;
340
+ };
341
+ var getDirectionConstant = (direction) => {
342
+ switch (direction) {
343
+ case "from-left":
344
+ return DIRECTION_FROM_LEFT;
345
+ case "from-right":
346
+ return DIRECTION_FROM_RIGHT;
347
+ case "from-top":
348
+ return DIRECTION_FROM_TOP;
349
+ case "from-bottom":
350
+ return DIRECTION_FROM_BOTTOM;
351
+ default:
352
+ return DIRECTION_FROM_RIGHT;
353
+ }
354
+ };
355
+ var bookFlipShader = (canvas) => {
356
+ const gl = canvas.getContext("webgl2", { premultipliedAlpha: true });
357
+ if (!gl) {
358
+ throw new Error("Failed to create WebGL2 context");
359
+ }
360
+ const program = createProgram(gl);
361
+ const prevTex = createTexture(gl);
362
+ const nextTex = createTexture(gl);
363
+ const vao = gl.createVertexArray();
364
+ gl.bindVertexArray(vao);
365
+ const buffer = gl.createBuffer();
366
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
367
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);
368
+ const aPos = gl.getAttribLocation(program, "a_pos");
369
+ gl.enableVertexAttribArray(aPos);
370
+ gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);
371
+ const uTime = gl.getUniformLocation(program, "u_time");
372
+ const uPrev = gl.getUniformLocation(program, "u_prev");
373
+ const uNext = gl.getUniformLocation(program, "u_next");
374
+ const uDirection = gl.getUniformLocation(program, "u_direction");
375
+ const cleanup = () => {
376
+ gl.deleteProgram(program);
377
+ gl.deleteTexture(prevTex);
378
+ gl.deleteTexture(nextTex);
379
+ };
380
+ const clear = () => {
381
+ gl.clearColor(0, 0, 0, 0);
382
+ gl.clear(gl.COLOR_BUFFER_BIT);
383
+ };
384
+ const draw = ({
385
+ prevImage,
386
+ nextImage,
387
+ width,
388
+ height,
389
+ time,
390
+ passedProps
391
+ }) => {
392
+ const { direction = DEFAULT_DIRECTION } = passedProps;
393
+ if (!prevImage && !nextImage) {
394
+ return;
395
+ }
396
+ if (prevImage && (prevImage.width === 0 || prevImage.height === 0)) {
397
+ return;
398
+ }
399
+ if (nextImage && (nextImage.width === 0 || nextImage.height === 0)) {
400
+ return;
401
+ }
402
+ const effectiveTime = !prevImage ? 0 : !nextImage ? 1 : time;
403
+ gl.viewport(0, 0, width, height);
404
+ gl.clearColor(0, 0, 0, 0);
405
+ gl.clear(gl.COLOR_BUFFER_BIT);
406
+ gl.useProgram(program);
407
+ gl.activeTexture(gl.TEXTURE0);
408
+ gl.bindTexture(gl.TEXTURE_2D, prevTex);
409
+ if (prevImage) {
410
+ gl.texElementImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, prevImage);
411
+ }
412
+ gl.uniform1i(uPrev, 0);
413
+ gl.activeTexture(gl.TEXTURE1);
414
+ gl.bindTexture(gl.TEXTURE_2D, nextTex);
415
+ if (nextImage) {
416
+ gl.texElementImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, nextImage);
417
+ }
418
+ gl.uniform1i(uNext, 1);
419
+ gl.uniform1f(uTime, effectiveTime);
420
+ gl.uniform1f(uDirection, getDirectionConstant(direction));
421
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
422
+ };
423
+ return {
424
+ clear,
425
+ cleanup,
426
+ draw
427
+ };
428
+ };
429
+ var bookFlip = makeHtmlInCanvasPresentation(bookFlipShader);
430
+ export {
431
+ bookFlipShader,
432
+ bookFlip
433
+ };