1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.continueRender = exports.delayRender = exports.DELAY_RENDER_CALLSTACK_TOKEN = void 0;
|
4 | const get_environment_1 = require("./get-environment");
|
5 | const timeout_1 = require("./timeout");
|
6 | const truthy_1 = require("./truthy");
|
7 | if (typeof window !== 'undefined') {
|
8 | window.ready = false;
|
9 | }
|
10 | let handles = [];
|
11 | const timeouts = {};
|
12 | exports.DELAY_RENDER_CALLSTACK_TOKEN = 'The delayRender was called:';
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | const delayRender = (label) => {
|
20 | var _a, _b;
|
21 | if (typeof label !== 'string' && typeof label !== 'undefined') {
|
22 | throw new Error('The label parameter of delayRender() must be a string or undefined, got: ' +
|
23 | JSON.stringify(label));
|
24 | }
|
25 | const handle = Math.random();
|
26 | handles.push(handle);
|
27 | const called = (_b = (_a = Error().stack) === null || _a === void 0 ? void 0 : _a.replace(/^Error/g, '')) !== null && _b !== void 0 ? _b : '';
|
28 | if ((0, get_environment_1.getRemotionEnvironment)() === 'rendering') {
|
29 | const timeoutToUse = typeof window === 'undefined'
|
30 | ? timeout_1.DEFAULT_PUPPETEER_TIMEOUT
|
31 | : window.remotion_puppeteerTimeout - 2000;
|
32 | timeouts[handle] = setTimeout(() => {
|
33 | const message = [
|
34 | `A delayRender()`,
|
35 | label ? `"${label}"` : null,
|
36 | `was called but not cleared after ${timeoutToUse}ms. See https://remotion.dev/docs/timeout for help.`,
|
37 | exports.DELAY_RENDER_CALLSTACK_TOKEN,
|
38 | called,
|
39 | ]
|
40 | .filter(truthy_1.truthy)
|
41 | .join(' ');
|
42 | throw new Error(message);
|
43 | }, timeoutToUse);
|
44 | }
|
45 | if (typeof window !== 'undefined') {
|
46 | window.ready = false;
|
47 | }
|
48 | return handle;
|
49 | };
|
50 | exports.delayRender = delayRender;
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | const continueRender = (handle) => {
|
57 | if (typeof handle === 'undefined') {
|
58 | throw new TypeError('The continueRender() method must be called with a parameter that is the return value of delayRender(). No value was passed.');
|
59 | }
|
60 | if (typeof handle !== 'number') {
|
61 | throw new TypeError('The parameter passed into continueRender() must be the return value of delayRender() which is a number. Got: ' +
|
62 | JSON.stringify(handle));
|
63 | }
|
64 | handles = handles.filter((h) => {
|
65 | if (h === handle) {
|
66 | if ((0, get_environment_1.getRemotionEnvironment)() === 'rendering') {
|
67 | clearTimeout(timeouts[handle]);
|
68 | }
|
69 | return false;
|
70 | }
|
71 | return true;
|
72 | });
|
73 | if (handles.length === 0 && typeof window !== 'undefined') {
|
74 | window.ready = true;
|
75 | }
|
76 | };
|
77 | exports.continueRender = continueRender;
|