@remotion/motion-blur 4.0.544 → 4.0.546
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/dist/cjs/CameraMotionBlur.js +13 -8
- package/dist/cjs/HtmlInCanvasMotionBlur.d.ts +3 -2
- package/dist/cjs/HtmlInCanvasMotionBlur.js +85 -36
- package/dist/cjs/Trail.js +6 -2
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +6 -1
- package/dist/cjs/motion-blur-compositor.d.ts +15 -0
- package/dist/cjs/motion-blur-compositor.js +353 -0
- package/dist/cjs/motion-blur-context.d.ts +9 -0
- package/dist/cjs/motion-blur-context.js +60 -0
- package/dist/esm/index.mjs +546 -60
- package/package.json +5 -4
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMotionBlurCompositor = exports.getMotionBlurGpuDevice = void 0;
|
|
4
|
+
const remotion_1 = require("remotion");
|
|
5
|
+
const webGpuShader = /* wgsl */ `
|
|
6
|
+
@group(0) @binding(0) var source: texture_2d<f32>;
|
|
7
|
+
@group(0) @binding(1) var<uniform> weight: f32;
|
|
8
|
+
|
|
9
|
+
@vertex fn vertex(@builtin(vertex_index) index: u32) -> @builtin(position) vec4f {
|
|
10
|
+
let positions = array<vec2f, 3>(vec2f(-1, -1), vec2f(3, -1), vec2f(-1, 3));
|
|
11
|
+
return vec4f(positions[index], 0, 1);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@fragment fn accumulate(@builtin(position) position: vec4f) -> @location(0) vec4f {
|
|
15
|
+
return textureLoad(source, vec2i(position.xy), 0) * weight;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@fragment fn resolve(@builtin(position) position: vec4f) -> @location(0) vec4f {
|
|
19
|
+
return textureLoad(source, vec2i(position.xy), 0);
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
const webGlVertexShader = /* glsl */ `#version 300 es
|
|
23
|
+
void main() {
|
|
24
|
+
vec2 positions[3] = vec2[3](vec2(-1, -1), vec2(3, -1), vec2(-1, 3));
|
|
25
|
+
gl_Position = vec4(positions[gl_VertexID], 0, 1);
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
const webGlFragmentShader = /* glsl */ `#version 300 es
|
|
29
|
+
precision highp float;
|
|
30
|
+
uniform sampler2D source;
|
|
31
|
+
uniform float weight;
|
|
32
|
+
out vec4 color;
|
|
33
|
+
void main() {
|
|
34
|
+
color = texelFetch(source, ivec2(gl_FragCoord.xy), 0) * weight;
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
let sharedWebGl = null;
|
|
38
|
+
const deviceLossListeners = new WeakMap();
|
|
39
|
+
const lostDevices = new WeakSet();
|
|
40
|
+
const webGpuPipelines = new WeakMap();
|
|
41
|
+
const getMotionBlurGpuDevice = async () => {
|
|
42
|
+
const device = (await remotion_1.Internals.getGpuDevice());
|
|
43
|
+
if (!device || lostDevices.has(device))
|
|
44
|
+
return null;
|
|
45
|
+
if (!deviceLossListeners.has(device)) {
|
|
46
|
+
const listeners = new Set();
|
|
47
|
+
deviceLossListeners.set(device, listeners);
|
|
48
|
+
device.lost.then(() => {
|
|
49
|
+
lostDevices.add(device);
|
|
50
|
+
for (const callback of listeners)
|
|
51
|
+
callback();
|
|
52
|
+
listeners.clear();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return device;
|
|
56
|
+
};
|
|
57
|
+
exports.getMotionBlurGpuDevice = getMotionBlurGpuDevice;
|
|
58
|
+
const createWebGlCompositor = (width, height, requestPaint) => {
|
|
59
|
+
if (sharedWebGl === null || sharedWebGl.gl.isContextLost()) {
|
|
60
|
+
const canvas = document.createElement('canvas');
|
|
61
|
+
const gl = canvas.getContext('webgl2', {
|
|
62
|
+
alpha: true,
|
|
63
|
+
premultipliedAlpha: true,
|
|
64
|
+
preserveDrawingBuffer: true,
|
|
65
|
+
antialias: false,
|
|
66
|
+
depth: false,
|
|
67
|
+
stencil: false,
|
|
68
|
+
});
|
|
69
|
+
if (!gl) {
|
|
70
|
+
throw remotion_1.Internals.createWebGL2ContextError('motion blur accumulation');
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
if (!gl.getExtension('EXT_color_buffer_float')) {
|
|
74
|
+
throw new Error('Motion blur requires WebGL floating-point render targets');
|
|
75
|
+
}
|
|
76
|
+
const program = gl.createProgram();
|
|
77
|
+
if (!program) {
|
|
78
|
+
throw new Error('Failed to create the motion blur WebGL program');
|
|
79
|
+
}
|
|
80
|
+
for (const [type, code] of [
|
|
81
|
+
[gl.VERTEX_SHADER, webGlVertexShader],
|
|
82
|
+
[gl.FRAGMENT_SHADER, webGlFragmentShader],
|
|
83
|
+
]) {
|
|
84
|
+
const shader = gl.createShader(type);
|
|
85
|
+
if (!shader) {
|
|
86
|
+
throw new Error('Failed to create a motion blur WebGL shader');
|
|
87
|
+
}
|
|
88
|
+
gl.shaderSource(shader, code);
|
|
89
|
+
gl.compileShader(shader);
|
|
90
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
91
|
+
const message = gl.getShaderInfoLog(shader);
|
|
92
|
+
gl.deleteShader(shader);
|
|
93
|
+
throw new Error(`Failed to compile motion blur shader: ${message}`);
|
|
94
|
+
}
|
|
95
|
+
gl.attachShader(program, shader);
|
|
96
|
+
gl.deleteShader(shader);
|
|
97
|
+
}
|
|
98
|
+
gl.linkProgram(program);
|
|
99
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
100
|
+
throw new Error(`Failed to link motion blur shaders: ${gl.getProgramInfoLog(program)}`);
|
|
101
|
+
}
|
|
102
|
+
const sourceTexture = gl.createTexture();
|
|
103
|
+
const accumulationTexture = gl.createTexture();
|
|
104
|
+
const framebuffer = gl.createFramebuffer();
|
|
105
|
+
const weight = gl.getUniformLocation(program, 'weight');
|
|
106
|
+
if (!sourceTexture || !accumulationTexture || !framebuffer || !weight) {
|
|
107
|
+
throw new Error('Failed to allocate motion blur WebGL resources');
|
|
108
|
+
}
|
|
109
|
+
for (const texture of [sourceTexture, accumulationTexture]) {
|
|
110
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
111
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
112
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
113
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
114
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
115
|
+
}
|
|
116
|
+
gl.useProgram(program);
|
|
117
|
+
gl.uniform1i(gl.getUniformLocation(program, 'source'), 0);
|
|
118
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
|
119
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
|
120
|
+
gl.disable(gl.DITHER);
|
|
121
|
+
sharedWebGl = {
|
|
122
|
+
canvas,
|
|
123
|
+
gl,
|
|
124
|
+
program,
|
|
125
|
+
sourceTexture,
|
|
126
|
+
accumulationTexture,
|
|
127
|
+
framebuffer,
|
|
128
|
+
weight,
|
|
129
|
+
requestPaint: new Set(),
|
|
130
|
+
users: 0,
|
|
131
|
+
width: 0,
|
|
132
|
+
height: 0,
|
|
133
|
+
};
|
|
134
|
+
const createdState = sharedWebGl;
|
|
135
|
+
canvas.addEventListener('webglcontextlost', (event) => {
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
for (const repaint of createdState.requestPaint)
|
|
138
|
+
repaint();
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
// Losing a context inside an HTML-in-canvas paint can crash Chromium.
|
|
143
|
+
// https://issues.chromium.org/issues/575053149
|
|
144
|
+
setTimeout(() => { var _a; return (_a = gl.getExtension('WEBGL_lose_context')) === null || _a === void 0 ? void 0 : _a.loseContext(); }, 0);
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const state = sharedWebGl;
|
|
149
|
+
state.users++;
|
|
150
|
+
state.requestPaint.add(requestPaint);
|
|
151
|
+
let disposed = false;
|
|
152
|
+
return {
|
|
153
|
+
backend: 'webgl2',
|
|
154
|
+
isLost: () => state.gl.isContextLost(),
|
|
155
|
+
addSample: (source, index, weight) => {
|
|
156
|
+
const { gl, canvas, sourceTexture, accumulationTexture, framebuffer } = state;
|
|
157
|
+
if (index === 0) {
|
|
158
|
+
if (state.width !== width || state.height !== height) {
|
|
159
|
+
canvas.width = width;
|
|
160
|
+
canvas.height = height;
|
|
161
|
+
gl.bindTexture(gl.TEXTURE_2D, sourceTexture);
|
|
162
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
|
163
|
+
gl.bindTexture(gl.TEXTURE_2D, accumulationTexture);
|
|
164
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA16F, width, height, 0, gl.RGBA, gl.HALF_FLOAT, null);
|
|
165
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
166
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, accumulationTexture, 0);
|
|
167
|
+
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) !==
|
|
168
|
+
gl.FRAMEBUFFER_COMPLETE) {
|
|
169
|
+
throw new Error('Motion blur WebGL framebuffer is incomplete');
|
|
170
|
+
}
|
|
171
|
+
state.width = width;
|
|
172
|
+
state.height = height;
|
|
173
|
+
}
|
|
174
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
175
|
+
gl.viewport(0, 0, width, height);
|
|
176
|
+
gl.clearColor(0, 0, 0, 0);
|
|
177
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
178
|
+
gl.enable(gl.BLEND);
|
|
179
|
+
gl.blendFunc(gl.ONE, gl.ONE);
|
|
180
|
+
gl.uniform1f(state.weight, weight);
|
|
181
|
+
}
|
|
182
|
+
gl.bindTexture(gl.TEXTURE_2D, sourceTexture);
|
|
183
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, source);
|
|
184
|
+
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
185
|
+
},
|
|
186
|
+
finish: () => {
|
|
187
|
+
const { gl } = state;
|
|
188
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
189
|
+
gl.disable(gl.BLEND);
|
|
190
|
+
gl.uniform1f(state.weight, 1);
|
|
191
|
+
gl.bindTexture(gl.TEXTURE_2D, state.accumulationTexture);
|
|
192
|
+
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
193
|
+
return state.canvas;
|
|
194
|
+
},
|
|
195
|
+
dispose: () => {
|
|
196
|
+
if (disposed)
|
|
197
|
+
return;
|
|
198
|
+
disposed = true;
|
|
199
|
+
state.requestPaint.delete(requestPaint);
|
|
200
|
+
state.users--;
|
|
201
|
+
if (state.users !== 0)
|
|
202
|
+
return;
|
|
203
|
+
const { gl, canvas } = state;
|
|
204
|
+
if (sharedWebGl === state)
|
|
205
|
+
sharedWebGl = null;
|
|
206
|
+
canvas.width = 0;
|
|
207
|
+
canvas.height = 0;
|
|
208
|
+
setTimeout(() => { var _a; return (_a = gl.getExtension('WEBGL_lose_context')) === null || _a === void 0 ? void 0 : _a.loseContext(); }, 0);
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
const createMotionBlurCompositor = ({ width, height, device, requestPaint, }) => {
|
|
213
|
+
if (!device ||
|
|
214
|
+
lostDevices.has(device) ||
|
|
215
|
+
width > device.limits.maxTextureDimension2D ||
|
|
216
|
+
height > device.limits.maxTextureDimension2D) {
|
|
217
|
+
return createWebGlCompositor(width, height, requestPaint);
|
|
218
|
+
}
|
|
219
|
+
const canvas = document.createElement('canvas');
|
|
220
|
+
canvas.width = width;
|
|
221
|
+
canvas.height = height;
|
|
222
|
+
const context = canvas.getContext('webgpu');
|
|
223
|
+
if (!context)
|
|
224
|
+
return createWebGlCompositor(width, height, requestPaint);
|
|
225
|
+
const sourceTexture = device.createTexture({
|
|
226
|
+
size: [width, height],
|
|
227
|
+
format: 'rgba8unorm',
|
|
228
|
+
usage: GPUTextureUsage.TEXTURE_BINDING |
|
|
229
|
+
GPUTextureUsage.COPY_DST |
|
|
230
|
+
GPUTextureUsage.RENDER_ATTACHMENT,
|
|
231
|
+
});
|
|
232
|
+
const accumulationTexture = device.createTexture({
|
|
233
|
+
size: [width, height],
|
|
234
|
+
format: 'rgba16float',
|
|
235
|
+
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT,
|
|
236
|
+
});
|
|
237
|
+
const weight = device.createBuffer({
|
|
238
|
+
size: 16,
|
|
239
|
+
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
|
|
240
|
+
});
|
|
241
|
+
const format = navigator.gpu.getPreferredCanvasFormat();
|
|
242
|
+
context.configure({
|
|
243
|
+
device,
|
|
244
|
+
format,
|
|
245
|
+
alphaMode: 'premultiplied',
|
|
246
|
+
});
|
|
247
|
+
let pipelines = webGpuPipelines.get(device);
|
|
248
|
+
if (!pipelines) {
|
|
249
|
+
const module = device.createShaderModule({ code: webGpuShader });
|
|
250
|
+
const accumulation = device.createRenderPipeline({
|
|
251
|
+
layout: 'auto',
|
|
252
|
+
vertex: { module, entryPoint: 'vertex' },
|
|
253
|
+
fragment: {
|
|
254
|
+
module,
|
|
255
|
+
entryPoint: 'accumulate',
|
|
256
|
+
targets: [
|
|
257
|
+
{
|
|
258
|
+
format: 'rgba16float',
|
|
259
|
+
blend: {
|
|
260
|
+
color: { srcFactor: 'one', dstFactor: 'one', operation: 'add' },
|
|
261
|
+
alpha: { srcFactor: 'one', dstFactor: 'one', operation: 'add' },
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
],
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
const output = device.createRenderPipeline({
|
|
268
|
+
layout: 'auto',
|
|
269
|
+
vertex: { module, entryPoint: 'vertex' },
|
|
270
|
+
fragment: { module, entryPoint: 'resolve', targets: [{ format }] },
|
|
271
|
+
});
|
|
272
|
+
pipelines = { accumulation, output };
|
|
273
|
+
webGpuPipelines.set(device, pipelines);
|
|
274
|
+
}
|
|
275
|
+
const { accumulation: accumulationPipeline, output: outputPipeline } = pipelines;
|
|
276
|
+
const sourceGroup = device.createBindGroup({
|
|
277
|
+
layout: accumulationPipeline.getBindGroupLayout(0),
|
|
278
|
+
entries: [
|
|
279
|
+
{ binding: 0, resource: sourceTexture.createView() },
|
|
280
|
+
{ binding: 1, resource: { buffer: weight } },
|
|
281
|
+
],
|
|
282
|
+
});
|
|
283
|
+
const outputGroup = device.createBindGroup({
|
|
284
|
+
layout: outputPipeline.getBindGroupLayout(0),
|
|
285
|
+
entries: [{ binding: 0, resource: accumulationTexture.createView() }],
|
|
286
|
+
});
|
|
287
|
+
let lost = false;
|
|
288
|
+
let disposed = false;
|
|
289
|
+
const listeners = deviceLossListeners.get(device);
|
|
290
|
+
const onDeviceLost = () => {
|
|
291
|
+
lost = true;
|
|
292
|
+
requestPaint();
|
|
293
|
+
};
|
|
294
|
+
listeners.add(onDeviceLost);
|
|
295
|
+
return {
|
|
296
|
+
backend: 'webgpu',
|
|
297
|
+
isLost: () => lost,
|
|
298
|
+
addSample: (source, index, sampleWeight) => {
|
|
299
|
+
if (index === 0) {
|
|
300
|
+
device.queue.writeBuffer(weight, 0, new Float32Array([sampleWeight]));
|
|
301
|
+
}
|
|
302
|
+
device.queue.copyExternalImageToTexture({ source }, { texture: sourceTexture, premultipliedAlpha: true }, [width, height]);
|
|
303
|
+
const encoder = device.createCommandEncoder();
|
|
304
|
+
const pass = encoder.beginRenderPass({
|
|
305
|
+
colorAttachments: [
|
|
306
|
+
{
|
|
307
|
+
view: accumulationTexture.createView(),
|
|
308
|
+
clearValue: { r: 0, g: 0, b: 0, a: 0 },
|
|
309
|
+
loadOp: index === 0 ? 'clear' : 'load',
|
|
310
|
+
storeOp: 'store',
|
|
311
|
+
},
|
|
312
|
+
],
|
|
313
|
+
});
|
|
314
|
+
pass.setPipeline(accumulationPipeline);
|
|
315
|
+
pass.setBindGroup(0, sourceGroup);
|
|
316
|
+
pass.draw(3);
|
|
317
|
+
pass.end();
|
|
318
|
+
device.queue.submit([encoder.finish()]);
|
|
319
|
+
},
|
|
320
|
+
finish: () => {
|
|
321
|
+
const encoder = device.createCommandEncoder();
|
|
322
|
+
const pass = encoder.beginRenderPass({
|
|
323
|
+
colorAttachments: [
|
|
324
|
+
{
|
|
325
|
+
view: context.getCurrentTexture().createView(),
|
|
326
|
+
clearValue: { r: 0, g: 0, b: 0, a: 0 },
|
|
327
|
+
loadOp: 'clear',
|
|
328
|
+
storeOp: 'store',
|
|
329
|
+
},
|
|
330
|
+
],
|
|
331
|
+
});
|
|
332
|
+
pass.setPipeline(outputPipeline);
|
|
333
|
+
pass.setBindGroup(0, outputGroup);
|
|
334
|
+
pass.draw(3);
|
|
335
|
+
pass.end();
|
|
336
|
+
device.queue.submit([encoder.finish()]);
|
|
337
|
+
return canvas;
|
|
338
|
+
},
|
|
339
|
+
dispose: () => {
|
|
340
|
+
if (disposed)
|
|
341
|
+
return;
|
|
342
|
+
disposed = true;
|
|
343
|
+
listeners.delete(onDeviceLost);
|
|
344
|
+
sourceTexture.destroy();
|
|
345
|
+
accumulationTexture.destroy();
|
|
346
|
+
weight.destroy();
|
|
347
|
+
context.unconfigure();
|
|
348
|
+
canvas.width = 0;
|
|
349
|
+
canvas.height = 0;
|
|
350
|
+
},
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
exports.createMotionBlurCompositor = createMotionBlurCompositor;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Internals } from 'remotion';
|
|
3
|
+
export type MotionBlurRegistry = NonNullable<React.ContextType<typeof Internals.MotionBlurContext>>['registry'];
|
|
4
|
+
export declare const useMotionBlurRegistry: (componentName: string) => MotionBlurRegistry | null;
|
|
5
|
+
export declare const MotionBlurSampleProvider: React.FC<{
|
|
6
|
+
readonly children: React.ReactNode;
|
|
7
|
+
readonly sampleIndex: number;
|
|
8
|
+
readonly registry: MotionBlurRegistry;
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MotionBlurSampleProvider = exports.useMotionBlurRegistry = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const remotion_1 = require("remotion");
|
|
7
|
+
const useMotionBlurRegistry = (componentName) => {
|
|
8
|
+
const parent = (0, react_1.useContext)(remotion_1.Internals.MotionBlurContext);
|
|
9
|
+
const [registry] = (0, react_1.useState)(() => ({
|
|
10
|
+
canvases: new Map(),
|
|
11
|
+
nestedScopes: new Map(),
|
|
12
|
+
}));
|
|
13
|
+
const [nested, setNested] = (0, react_1.useState)(null);
|
|
14
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
15
|
+
var _a;
|
|
16
|
+
if (parent === null)
|
|
17
|
+
return;
|
|
18
|
+
const scopes = (_a = parent.registry.nestedScopes.get(componentName)) !== null && _a !== void 0 ? _a : [];
|
|
19
|
+
parent.registry.nestedScopes.set(componentName, scopes);
|
|
20
|
+
let scope = scopes.find((candidate) => !candidate.registrations.has(parent.sampleIndex));
|
|
21
|
+
if (!scope) {
|
|
22
|
+
scope = {
|
|
23
|
+
registrations: new Set(),
|
|
24
|
+
registry: { canvases: new Map(), nestedScopes: new Map() },
|
|
25
|
+
};
|
|
26
|
+
scopes.push(scope);
|
|
27
|
+
}
|
|
28
|
+
scope.registrations.add(parent.sampleIndex);
|
|
29
|
+
setNested({ parent, registry: scope.registry });
|
|
30
|
+
const current = scope;
|
|
31
|
+
return () => {
|
|
32
|
+
current.registrations.delete(parent.sampleIndex);
|
|
33
|
+
if (current.registrations.size === 0) {
|
|
34
|
+
scopes.splice(scopes.indexOf(current), 1);
|
|
35
|
+
if (scopes.length === 0) {
|
|
36
|
+
parent.registry.nestedScopes.delete(componentName);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}, [componentName, parent]);
|
|
41
|
+
return parent === null
|
|
42
|
+
? registry
|
|
43
|
+
: (nested === null || nested === void 0 ? void 0 : nested.parent) === parent
|
|
44
|
+
? nested.registry
|
|
45
|
+
: null;
|
|
46
|
+
};
|
|
47
|
+
exports.useMotionBlurRegistry = useMotionBlurRegistry;
|
|
48
|
+
const MotionBlurSampleProvider = ({ children, sampleIndex, registry }) => {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
const parent = (0, react_1.useContext)(remotion_1.Internals.MotionBlurContext);
|
|
51
|
+
const parentIndex = (_a = parent === null || parent === void 0 ? void 0 : parent.sampleIndex) !== null && _a !== void 0 ? _a : '';
|
|
52
|
+
const parentIsPrimary = (_b = parent === null || parent === void 0 ? void 0 : parent.isPrimarySample) !== null && _b !== void 0 ? _b : true;
|
|
53
|
+
const value = (0, react_1.useMemo)(() => ({
|
|
54
|
+
sampleIndex: `${parentIndex}/${sampleIndex}`,
|
|
55
|
+
isPrimarySample: parentIsPrimary && sampleIndex === 0,
|
|
56
|
+
registry,
|
|
57
|
+
}), [parentIndex, parentIsPrimary, sampleIndex, registry]);
|
|
58
|
+
return ((0, jsx_runtime_1.jsx)(remotion_1.Internals.DisableSequenceRegistrationProvider, { disabled: !value.isPrimarySample, children: (0, jsx_runtime_1.jsx)(remotion_1.Internals.MotionBlurContext.Provider, { value: value, children: children }) }));
|
|
59
|
+
};
|
|
60
|
+
exports.MotionBlurSampleProvider = MotionBlurSampleProvider;
|