remotion 4.0.145 → 4.0.147

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.
@@ -69,7 +69,7 @@ export type TRenderAsset = {
69
69
  audioStartFrame: number;
70
70
  };
71
71
  export declare const compositionsRef: React.RefObject<{
72
- getCompositions: () => TCompMetadataWithCalcFunction<AnyZodObject, Record<string, unknown>>[];
72
+ getCompositions: () => AnyComposition[];
73
73
  }>;
74
74
  export declare const CompositionManagerProvider: React.FC<{
75
75
  readonly children: React.ReactNode;
@@ -9,7 +9,10 @@ export type EditorPropsContextType = {
9
9
  }) => void;
10
10
  };
11
11
  export declare const EditorPropsContext: React.Context<EditorPropsContextType>;
12
+ export declare const editorPropsProviderRef: React.RefObject<{
13
+ getProps: () => Props;
14
+ }>;
12
15
  export declare const EditorPropsProvider: React.FC<{
13
- children: React.ReactNode;
16
+ readonly children: React.ReactNode;
14
17
  }>;
15
18
  export {};
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.EditorPropsProvider = exports.EditorPropsContext = void 0;
26
+ exports.EditorPropsProvider = exports.editorPropsProviderRef = exports.EditorPropsContext = void 0;
27
27
  const jsx_runtime_1 = require("react/jsx-runtime");
28
28
  const react_1 = __importStar(require("react"));
29
29
  exports.EditorPropsContext = (0, react_1.createContext)({
@@ -32,6 +32,7 @@ exports.EditorPropsContext = (0, react_1.createContext)({
32
32
  throw new Error('Not implemented');
33
33
  },
34
34
  });
35
+ exports.editorPropsProviderRef = react_1.default.createRef();
35
36
  const EditorPropsProvider = ({ children }) => {
36
37
  const [props, setProps] = react_1.default.useState({});
37
38
  const updateProps = (0, react_1.useCallback)(({ defaultProps, id, newProps, }) => {
@@ -45,6 +46,11 @@ const EditorPropsProvider = ({ children }) => {
45
46
  };
46
47
  });
47
48
  }, []);
49
+ (0, react_1.useImperativeHandle)(exports.editorPropsProviderRef, () => {
50
+ return {
51
+ getProps: () => props,
52
+ };
53
+ }, [props]);
48
54
  const ctx = (0, react_1.useMemo)(() => {
49
55
  return { props, updateProps };
50
56
  }, [props, updateProps]);
@@ -27,11 +27,27 @@ const RemotionRoot = ({ children, numberOfAudioTags }) => {
27
27
  window.remotion_setFrame = (f, composition, attempt) => {
28
28
  window.remotion_attempt = attempt;
29
29
  const id = (0, delay_render_js_1.delayRender)(`Setting the current frame to ${f}`);
30
- setFrame((s) => ({
31
- ...s,
32
- [composition]: f,
33
- }));
34
- requestAnimationFrame(() => (0, delay_render_js_1.continueRender)(id));
30
+ let asyncUpdate = true;
31
+ setFrame((s) => {
32
+ var _a;
33
+ const currentFrame = (_a = s[composition]) !== null && _a !== void 0 ? _a : window.remotion_initialFrame;
34
+ // Avoid cloning the object
35
+ if (currentFrame === f) {
36
+ asyncUpdate = false;
37
+ return s;
38
+ }
39
+ return {
40
+ ...s,
41
+ [composition]: f,
42
+ };
43
+ });
44
+ // After setting the state, need to wait until it is applied in the next cycle
45
+ if (asyncUpdate) {
46
+ requestAnimationFrame(() => (0, delay_render_js_1.continueRender)(id));
47
+ }
48
+ else {
49
+ (0, delay_render_js_1.continueRender)(id);
50
+ }
35
51
  };
36
52
  window.remotion_isPlayer = false;
37
53
  }, []);
@@ -64,7 +64,7 @@ const AudioForRenderingRefForwardingFunction = (props, ref) => {
64
64
  playbackRate: (_a = props.playbackRate) !== null && _a !== void 0 ? _a : 1,
65
65
  allowAmplificationDuringRender: allowAmplificationDuringRender !== null && allowAmplificationDuringRender !== void 0 ? allowAmplificationDuringRender : false,
66
66
  toneFrequency: toneFrequency !== null && toneFrequency !== void 0 ? toneFrequency : null,
67
- audioStartFrame: -((_b = sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom) !== null && _b !== void 0 ? _b : 0),
67
+ audioStartFrame: Math.max(0, -((_b = sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom) !== null && _b !== void 0 ? _b : 0)),
68
68
  });
69
69
  return () => unregisterRenderAsset(id);
70
70
  }, [
@@ -64,7 +64,7 @@ export declare const Internals: {
64
64
  readonly isCompositionIdValid: (id: string) => RegExpMatchArray | null;
65
65
  readonly getPreviewDomElement: () => HTMLElement | null;
66
66
  readonly compositionsRef: import("react").RefObject<{
67
- getCompositions: () => import("./CompositionManager.js").TCompMetadataWithCalcFunction<import("zod").AnyZodObject, Record<string, unknown>>[];
67
+ getCompositions: () => import("./CompositionManager.js").AnyComposition[];
68
68
  }>;
69
69
  readonly portalNode: () => HTMLElement;
70
70
  readonly waitForRoot: (fn: (comp: import("react").FC<{}>) => void) => () => void;
@@ -83,7 +83,7 @@ export declare const Internals: {
83
83
  }>;
84
84
  readonly useIsPlayer: () => boolean;
85
85
  readonly EditorPropsProvider: import("react").FC<{
86
- children: import("react").ReactNode;
86
+ readonly children: import("react").ReactNode;
87
87
  }>;
88
88
  readonly EditorPropsContext: import("react").Context<import("./EditorProps.js").EditorPropsContextType>;
89
89
  readonly usePreload: (src: string) => string;
@@ -155,5 +155,10 @@ export declare const Internals: {
155
155
  height: number;
156
156
  };
157
157
  }) => number;
158
+ readonly editorPropsProviderRef: import("react").RefObject<{
159
+ getProps: () => {
160
+ [x: string]: Record<string, unknown>;
161
+ };
162
+ }>;
158
163
  };
159
164
  export type { CompositionManagerContext, CompProps, MediaVolumeContextValue, RemotionEnvironment, SerializedJSONWithCustomFields, SetMediaVolumeContextValue, SetTimelineContextValue, TRenderAsset as TAsset, TCompMetadata, TComposition, TimelinePosition as Timeline, TimelineContextValue, TSequence, WatchRemotionStaticFilesPayload, };
@@ -124,4 +124,5 @@ exports.Internals = {
124
124
  CurrentScaleContext: use_current_scale_js_1.CurrentScaleContext,
125
125
  PreviewSizeContext: use_current_scale_js_1.PreviewSizeContext,
126
126
  calculateScale: use_current_scale_js_1.calculateScale,
127
+ editorPropsProviderRef: EditorProps_js_1.editorPropsProviderRef,
127
128
  };
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.usePlayingState = exports.useTimelineSetFrame = exports.useTimelinePosition = exports.getFrameForComposition = exports.getInitialFrameState = exports.persistCurrentFrame = exports.SetTimelineContext = exports.TimelineContext = void 0;
4
4
  const react_1 = require("react");
5
+ const get_remotion_environment_js_1 = require("./get-remotion-environment.js");
5
6
  const use_video_js_1 = require("./use-video.js");
6
7
  exports.TimelineContext = (0, react_1.createContext)({
7
8
  frame: {},
@@ -39,12 +40,16 @@ const getInitialFrameState = () => {
39
40
  };
40
41
  exports.getInitialFrameState = getInitialFrameState;
41
42
  const getFrameForComposition = (composition) => {
42
- var _a, _b, _c;
43
+ var _a, _b;
43
44
  const item = (_a = localStorage.getItem(makeKey())) !== null && _a !== void 0 ? _a : '{}';
44
45
  const obj = JSON.parse(item);
45
- return obj[composition]
46
- ? Number(obj[composition])
47
- : (_c = (typeof window === 'undefined' ? 0 : (_b = window.remotion_initialFrame) !== null && _b !== void 0 ? _b : 0)) !== null && _c !== void 0 ? _c : 0;
46
+ if (obj[composition] !== undefined) {
47
+ return Number(obj[composition]);
48
+ }
49
+ if (typeof window === 'undefined') {
50
+ return 0;
51
+ }
52
+ return (_b = window.remotion_initialFrame) !== null && _b !== void 0 ? _b : 0;
48
53
  };
49
54
  exports.getFrameForComposition = getFrameForComposition;
50
55
  const useTimelinePosition = () => {
@@ -56,7 +61,7 @@ const useTimelinePosition = () => {
56
61
  ? 0
57
62
  : (_a = window.remotion_initialFrame) !== null && _a !== void 0 ? _a : 0;
58
63
  }
59
- const unclamped = (_b = state.frame[videoConfig.id]) !== null && _b !== void 0 ? _b : (typeof window !== 'undefined' && window.remotion_isPlayer
64
+ const unclamped = (_b = state.frame[videoConfig.id]) !== null && _b !== void 0 ? _b : ((0, get_remotion_environment_js_1.getRemotionEnvironment)().isPlayer
60
65
  ? 0
61
66
  : (0, exports.getFrameForComposition)(videoConfig.id));
62
67
  return Math.min(videoConfig.durationInFrames - 1, unclamped);
@@ -4,6 +4,7 @@ exports.useCurrentFrame = void 0;
4
4
  const react_1 = require("react");
5
5
  const CanUseRemotionHooks_js_1 = require("./CanUseRemotionHooks.js");
6
6
  const SequenceContext_js_1 = require("./SequenceContext.js");
7
+ const get_remotion_environment_js_1 = require("./get-remotion-environment.js");
7
8
  const timeline_position_state_js_1 = require("./timeline-position-state.js");
8
9
  /**
9
10
  * @description Get the current frame of the video. Frames are 0-indexed, meaning the first frame is 0, the last frame is the duration of the composition in frames minus one.
@@ -12,7 +13,7 @@ const timeline_position_state_js_1 = require("./timeline-position-state.js");
12
13
  const useCurrentFrame = () => {
13
14
  const canUseRemotionHooks = (0, react_1.useContext)(CanUseRemotionHooks_js_1.CanUseRemotionHooks);
14
15
  if (!canUseRemotionHooks) {
15
- if (typeof window !== 'undefined' && window.remotion_isPlayer) {
16
+ if ((0, get_remotion_environment_js_1.getRemotionEnvironment)().isPlayer) {
16
17
  throw new Error(`useCurrentFrame can only be called inside a component that was passed to <Player>. See: https://www.remotion.dev/docs/player/examples`);
17
18
  }
18
19
  throw new Error(`useCurrentFrame() can only be called inside a component that was registered as a composition. See https://www.remotion.dev/docs/the-fundamentals#defining-compositions`);
@@ -3,4 +3,4 @@
3
3
  * @see [Documentation](https://remotion.dev/docs/version)
4
4
  * @returns {string} The current version of the remotion package
5
5
  */
6
- export declare const VERSION = "4.0.145";
6
+ export declare const VERSION = "4.0.147";
@@ -7,4 +7,4 @@ exports.VERSION = void 0;
7
7
  * @see [Documentation](https://remotion.dev/docs/version)
8
8
  * @returns {string} The current version of the remotion package
9
9
  */
10
- exports.VERSION = '4.0.145';
10
+ exports.VERSION = '4.0.147';
@@ -70,7 +70,7 @@ const OffthreadVideoForRendering = ({ onError, volume: volumeProp, playbackRate,
70
70
  playbackRate: playbackRate !== null && playbackRate !== void 0 ? playbackRate : 1,
71
71
  allowAmplificationDuringRender: allowAmplificationDuringRender !== null && allowAmplificationDuringRender !== void 0 ? allowAmplificationDuringRender : false,
72
72
  toneFrequency: toneFrequency !== null && toneFrequency !== void 0 ? toneFrequency : null,
73
- audioStartFrame: -((_a = sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom) !== null && _a !== void 0 ? _a : 0),
73
+ audioStartFrame: Math.max(0, -((_a = sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom) !== null && _a !== void 0 ? _a : 0)),
74
74
  });
75
75
  return () => unregisterRenderAsset(id);
76
76
  }, [
@@ -71,7 +71,7 @@ const VideoForRenderingForwardFunction = ({ onError, volume: volumeProp, allowAm
71
71
  playbackRate: playbackRate !== null && playbackRate !== void 0 ? playbackRate : 1,
72
72
  allowAmplificationDuringRender: allowAmplificationDuringRender !== null && allowAmplificationDuringRender !== void 0 ? allowAmplificationDuringRender : false,
73
73
  toneFrequency: toneFrequency !== null && toneFrequency !== void 0 ? toneFrequency : null,
74
- audioStartFrame: -((_a = sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom) !== null && _a !== void 0 ? _a : 0),
74
+ audioStartFrame: Math.max(0, -((_a = sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom) !== null && _a !== void 0 ? _a : 0)),
75
75
  });
76
76
  return () => unregisterRenderAsset(id);
77
77
  }, [
@@ -1,4 +1,4 @@
1
- import React, { createContext, useState, useMemo, useLayoutEffect, useContext, useEffect, forwardRef, useCallback, useRef, createRef, useImperativeHandle, useReducer, Suspense, Children } from 'react';
1
+ import React, { createContext, useState, useMemo, useLayoutEffect, useContext, useEffect, forwardRef, useCallback, useRef, useImperativeHandle, createRef, useReducer, Suspense, Children } from 'react';
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import { createPortal } from 'react-dom';
4
4
 
@@ -110,7 +110,7 @@ function truthy(value) {
110
110
  * @see [Documentation](https://remotion.dev/docs/version)
111
111
  * @returns {string} The current version of the remotion package
112
112
  */
113
- const VERSION = '4.0.145';
113
+ const VERSION = '4.0.147';
114
114
 
115
115
  const checkMultipleRemotionVersions = () => {
116
116
  if (typeof globalThis === 'undefined') {
@@ -265,6 +265,7 @@ const EditorPropsContext = createContext({
265
265
  throw new Error('Not implemented');
266
266
  },
267
267
  });
268
+ const editorPropsProviderRef = React.createRef();
268
269
  const EditorPropsProvider = ({ children }) => {
269
270
  const [props, setProps] = React.useState({});
270
271
  const updateProps = useCallback(({ defaultProps, id, newProps, }) => {
@@ -278,6 +279,11 @@ const EditorPropsProvider = ({ children }) => {
278
279
  };
279
280
  });
280
281
  }, []);
282
+ useImperativeHandle(editorPropsProviderRef, () => {
283
+ return {
284
+ getProps: () => props,
285
+ };
286
+ }, [props]);
281
287
  const ctx = useMemo(() => {
282
288
  return { props, updateProps };
283
289
  }, [props, updateProps]);
@@ -857,12 +863,16 @@ const getInitialFrameState = () => {
857
863
  return obj;
858
864
  };
859
865
  const getFrameForComposition = (composition) => {
860
- var _a, _b, _c;
866
+ var _a, _b;
861
867
  const item = (_a = localStorage.getItem(makeKey())) !== null && _a !== void 0 ? _a : '{}';
862
868
  const obj = JSON.parse(item);
863
- return obj[composition]
864
- ? Number(obj[composition])
865
- : (_c = (typeof window === 'undefined' ? 0 : (_b = window.remotion_initialFrame) !== null && _b !== void 0 ? _b : 0)) !== null && _c !== void 0 ? _c : 0;
869
+ if (obj[composition] !== undefined) {
870
+ return Number(obj[composition]);
871
+ }
872
+ if (typeof window === 'undefined') {
873
+ return 0;
874
+ }
875
+ return (_b = window.remotion_initialFrame) !== null && _b !== void 0 ? _b : 0;
866
876
  };
867
877
  const useTimelinePosition = () => {
868
878
  var _a, _b;
@@ -873,7 +883,7 @@ const useTimelinePosition = () => {
873
883
  ? 0
874
884
  : (_a = window.remotion_initialFrame) !== null && _a !== void 0 ? _a : 0;
875
885
  }
876
- const unclamped = (_b = state.frame[videoConfig.id]) !== null && _b !== void 0 ? _b : (typeof window !== 'undefined' && window.remotion_isPlayer
886
+ const unclamped = (_b = state.frame[videoConfig.id]) !== null && _b !== void 0 ? _b : (getRemotionEnvironment().isPlayer
877
887
  ? 0
878
888
  : getFrameForComposition(videoConfig.id));
879
889
  return Math.min(videoConfig.durationInFrames - 1, unclamped);
@@ -963,7 +973,7 @@ const useVideoConfig = () => {
963
973
  const useCurrentFrame = () => {
964
974
  const canUseRemotionHooks = useContext(CanUseRemotionHooks);
965
975
  if (!canUseRemotionHooks) {
966
- if (typeof window !== 'undefined' && window.remotion_isPlayer) {
976
+ if (getRemotionEnvironment().isPlayer) {
967
977
  throw new Error(`useCurrentFrame can only be called inside a component that was passed to <Player>. See: https://www.remotion.dev/docs/player/examples`);
968
978
  }
969
979
  throw new Error(`useCurrentFrame() can only be called inside a component that was registered as a composition. See https://www.remotion.dev/docs/the-fundamentals#defining-compositions`);
@@ -2836,7 +2846,7 @@ const AudioForRenderingRefForwardingFunction = (props, ref) => {
2836
2846
  playbackRate: (_a = props.playbackRate) !== null && _a !== void 0 ? _a : 1,
2837
2847
  allowAmplificationDuringRender: allowAmplificationDuringRender !== null && allowAmplificationDuringRender !== void 0 ? allowAmplificationDuringRender : false,
2838
2848
  toneFrequency: toneFrequency !== null && toneFrequency !== void 0 ? toneFrequency : null,
2839
- audioStartFrame: -((_b = sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom) !== null && _b !== void 0 ? _b : 0),
2849
+ audioStartFrame: Math.max(0, -((_b = sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom) !== null && _b !== void 0 ? _b : 0)),
2840
2850
  });
2841
2851
  return () => unregisterRenderAsset(id);
2842
2852
  }, [
@@ -3757,11 +3767,27 @@ const RemotionRoot = ({ children, numberOfAudioTags }) => {
3757
3767
  window.remotion_setFrame = (f, composition, attempt) => {
3758
3768
  window.remotion_attempt = attempt;
3759
3769
  const id = delayRender(`Setting the current frame to ${f}`);
3760
- setFrame((s) => ({
3761
- ...s,
3762
- [composition]: f,
3763
- }));
3764
- requestAnimationFrame(() => continueRender(id));
3770
+ let asyncUpdate = true;
3771
+ setFrame((s) => {
3772
+ var _a;
3773
+ const currentFrame = (_a = s[composition]) !== null && _a !== void 0 ? _a : window.remotion_initialFrame;
3774
+ // Avoid cloning the object
3775
+ if (currentFrame === f) {
3776
+ asyncUpdate = false;
3777
+ return s;
3778
+ }
3779
+ return {
3780
+ ...s,
3781
+ [composition]: f,
3782
+ };
3783
+ });
3784
+ // After setting the state, need to wait until it is applied in the next cycle
3785
+ if (asyncUpdate) {
3786
+ requestAnimationFrame(() => continueRender(id));
3787
+ }
3788
+ else {
3789
+ continueRender(id);
3790
+ }
3765
3791
  };
3766
3792
  window.remotion_isPlayer = false;
3767
3793
  }, []);
@@ -4039,6 +4065,7 @@ const Internals = {
4039
4065
  CurrentScaleContext,
4040
4066
  PreviewSizeContext,
4041
4067
  calculateScale,
4068
+ editorPropsProviderRef,
4042
4069
  };
4043
4070
 
4044
4071
  /**
@@ -4874,7 +4901,7 @@ const OffthreadVideoForRendering = ({ onError, volume: volumeProp, playbackRate,
4874
4901
  playbackRate: playbackRate !== null && playbackRate !== void 0 ? playbackRate : 1,
4875
4902
  allowAmplificationDuringRender: allowAmplificationDuringRender !== null && allowAmplificationDuringRender !== void 0 ? allowAmplificationDuringRender : false,
4876
4903
  toneFrequency: toneFrequency !== null && toneFrequency !== void 0 ? toneFrequency : null,
4877
- audioStartFrame: -((_a = sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom) !== null && _a !== void 0 ? _a : 0),
4904
+ audioStartFrame: Math.max(0, -((_a = sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom) !== null && _a !== void 0 ? _a : 0)),
4878
4905
  });
4879
4906
  return () => unregisterRenderAsset(id);
4880
4907
  }, [
@@ -5233,7 +5260,7 @@ const VideoForRenderingForwardFunction = ({ onError, volume: volumeProp, allowAm
5233
5260
  playbackRate: playbackRate !== null && playbackRate !== void 0 ? playbackRate : 1,
5234
5261
  allowAmplificationDuringRender: allowAmplificationDuringRender !== null && allowAmplificationDuringRender !== void 0 ? allowAmplificationDuringRender : false,
5235
5262
  toneFrequency: toneFrequency !== null && toneFrequency !== void 0 ? toneFrequency : null,
5236
- audioStartFrame: -((_a = sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom) !== null && _a !== void 0 ? _a : 0),
5263
+ audioStartFrame: Math.max(0, -((_a = sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom) !== null && _a !== void 0 ? _a : 0)),
5237
5264
  });
5238
5265
  return () => unregisterRenderAsset(id);
5239
5266
  }, [
@@ -4,6 +4,6 @@
4
4
  * @see [Documentation](https://remotion.dev/docs/version)
5
5
  * @returns {string} The current version of the remotion package
6
6
  */
7
- const VERSION = '4.0.145';
7
+ const VERSION = '4.0.147';
8
8
 
9
9
  export { VERSION };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remotion",
3
- "version": "4.0.145",
3
+ "version": "4.0.147",
4
4
  "description": "Render videos in React",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",