1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.RemotionRoot = void 0;
|
4 | const jsx_runtime_1 = require("react/jsx-runtime");
|
5 | const react_1 = require("react");
|
6 | const shared_audio_tags_1 = require("./audio/shared-audio-tags");
|
7 | const CompositionManager_1 = require("./CompositionManager");
|
8 | const delay_render_1 = require("./delay-render");
|
9 | const nonce_1 = require("./nonce");
|
10 | const random_1 = require("./random");
|
11 | const timeline_position_state_1 = require("./timeline-position-state");
|
12 | const RemotionRoot = ({ children }) => {
|
13 | var _a;
|
14 | const [remotionRootId] = (0, react_1.useState)(() => String((0, random_1.random)(null)));
|
15 | const [frame, setFrame] = (0, react_1.useState)((_a = window.remotion_initialFrame) !== null && _a !== void 0 ? _a : 0);
|
16 | const [playing, setPlaying] = (0, react_1.useState)(false);
|
17 | const imperativePlaying = (0, react_1.useRef)(false);
|
18 | const [fastRefreshes, setFastRefreshes] = (0, react_1.useState)(0);
|
19 | const [playbackRate, setPlaybackRate] = (0, react_1.useState)(1);
|
20 | const audioAndVideoTags = (0, react_1.useRef)([]);
|
21 | (0, react_1.useLayoutEffect)(() => {
|
22 | if (typeof window !== 'undefined') {
|
23 | window.remotion_setFrame = (f) => {
|
24 | const id = (0, delay_render_1.delayRender)(`Setting the current frame to ${f}`);
|
25 | setFrame(f);
|
26 | requestAnimationFrame(() => (0, delay_render_1.continueRender)(id));
|
27 | };
|
28 | window.remotion_isPlayer = false;
|
29 | }
|
30 | }, []);
|
31 | const timelineContextValue = (0, react_1.useMemo)(() => {
|
32 | return {
|
33 | frame,
|
34 | playing,
|
35 | imperativePlaying,
|
36 | rootId: remotionRootId,
|
37 | playbackRate,
|
38 | setPlaybackRate,
|
39 | audioAndVideoTags,
|
40 | };
|
41 | }, [frame, playbackRate, playing, remotionRootId]);
|
42 | const setTimelineContextValue = (0, react_1.useMemo)(() => {
|
43 | return {
|
44 | setFrame,
|
45 | setPlaying,
|
46 | };
|
47 | }, []);
|
48 | const nonceContext = (0, react_1.useMemo)(() => {
|
49 | let counter = 0;
|
50 | return {
|
51 | getNonce: () => counter++,
|
52 | fastRefreshes,
|
53 | };
|
54 | }, [fastRefreshes]);
|
55 | (0, react_1.useEffect)(() => {
|
56 | if (module.hot) {
|
57 | module.hot.addStatusHandler((status) => {
|
58 | if (status === 'idle') {
|
59 | setFastRefreshes((i) => i + 1);
|
60 | }
|
61 | });
|
62 | }
|
63 | }, []);
|
64 | return ((0, jsx_runtime_1.jsx)(nonce_1.NonceContext.Provider, { value: nonceContext, children: (0, jsx_runtime_1.jsx)(timeline_position_state_1.TimelineContext.Provider, { value: timelineContextValue, children: (0, jsx_runtime_1.jsx)(timeline_position_state_1.SetTimelineContext.Provider, { value: setTimelineContextValue, children: (0, jsx_runtime_1.jsx)(CompositionManager_1.CompositionManagerProvider, { children: (0, jsx_runtime_1.jsx)(shared_audio_tags_1.SharedAudioContextProvider
|
65 |
|
66 | , {
|
67 |
|
68 | numberOfAudioTags: 0, children: children }, void 0) }, void 0) }, void 0) }, void 0) }, void 0));
|
69 | };
|
70 | exports.RemotionRoot = RemotionRoot;
|