remotion 4.0.443 → 4.0.445

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.
@@ -5,6 +5,8 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const react_dom_1 = require("react-dom");
7
7
  const CanUseRemotionHooks_js_1 = require("./CanUseRemotionHooks.js");
8
+ const composition_render_error_context_js_1 = require("./composition-render-error-context.js");
9
+ const CompositionErrorBoundary_js_1 = require("./CompositionErrorBoundary.js");
8
10
  const CompositionManagerContext_js_1 = require("./CompositionManagerContext.js");
9
11
  const Folder_js_1 = require("./Folder.js");
10
12
  const input_props_serialization_js_1 = require("./input-props-serialization.js");
@@ -97,6 +99,13 @@ const InnerComposition = ({ width, height, fps, durationInFrames, id, defaultPro
97
99
  unregisterComposition,
98
100
  ]);
99
101
  const resolved = (0, ResolveCompositionConfig_js_1.useResolvedVideoConfig)(id);
102
+ const { setError, clearError } = (0, react_1.useContext)(composition_render_error_context_js_1.CompositionRenderErrorContext);
103
+ const onError = (0, react_1.useCallback)((error) => {
104
+ setError(error);
105
+ }, [setError]);
106
+ const onClear = (0, react_1.useCallback)(() => {
107
+ clearError();
108
+ }, [clearError]);
100
109
  if (environment.isStudio &&
101
110
  video &&
102
111
  video.component === lazy &&
@@ -107,7 +116,7 @@ const InnerComposition = ({ width, height, fps, durationInFrames, id, defaultPro
107
116
  resolved.type !== 'success-and-refreshing')) {
108
117
  return null;
109
118
  }
110
- return (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsx)(CanUseRemotionHooks_js_1.CanUseRemotionHooksProvider, { children: (0, jsx_runtime_1.jsx)(react_1.Suspense, { fallback: (0, jsx_runtime_1.jsx)(loading_indicator_js_1.Loading, {}), children: (0, jsx_runtime_1.jsx)(Comp, { ...((_c = resolved.result.props) !== null && _c !== void 0 ? _c : {}) }) }) }), (0, portal_node_js_1.portalNode)());
119
+ return (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsx)(CanUseRemotionHooks_js_1.CanUseRemotionHooksProvider, { children: (0, jsx_runtime_1.jsx)(CompositionErrorBoundary_js_1.CompositionErrorBoundary, { onError: onError, onClear: onClear, children: (0, jsx_runtime_1.jsx)(react_1.Suspense, { fallback: (0, jsx_runtime_1.jsx)(loading_indicator_js_1.Loading, {}), children: (0, jsx_runtime_1.jsx)(Comp, { ...((_c = resolved.result.props) !== null && _c !== void 0 ? _c : {}) }) }) }) }), (0, portal_node_js_1.portalNode)());
111
120
  }
112
121
  if (environment.isRendering &&
113
122
  video &&
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ type Props = {
3
+ readonly children: React.ReactNode;
4
+ readonly onError: (error: Error) => void;
5
+ readonly onClear: () => void;
6
+ };
7
+ type State = {
8
+ hasError: boolean;
9
+ };
10
+ export declare class CompositionErrorBoundary extends React.Component<Props, State> {
11
+ state: State;
12
+ static getDerivedStateFromError(): Partial<State>;
13
+ componentDidCatch(error: Error): void;
14
+ componentDidUpdate(_prevProps: Props): void;
15
+ render(): React.ReactNode;
16
+ }
17
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CompositionErrorBoundary = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ class CompositionErrorBoundary extends react_1.default.Component {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.state = { hasError: false };
12
+ }
13
+ static getDerivedStateFromError() {
14
+ return { hasError: true };
15
+ }
16
+ componentDidCatch(error) {
17
+ this.props.onError(error);
18
+ }
19
+ componentDidUpdate(_prevProps) {
20
+ if (!this.state.hasError) {
21
+ this.props.onClear();
22
+ }
23
+ }
24
+ render() {
25
+ if (this.state.hasError) {
26
+ return null;
27
+ }
28
+ return this.props.children;
29
+ }
30
+ }
31
+ exports.CompositionErrorBoundary = CompositionErrorBoundary;
@@ -0,0 +1,5 @@
1
+ export type CompositionRenderErrorContextType = {
2
+ setError: (error: Error) => void;
3
+ clearError: () => void;
4
+ };
5
+ export declare const CompositionRenderErrorContext: import("react").Context<CompositionRenderErrorContextType>;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CompositionRenderErrorContext = void 0;
4
+ const react_1 = require("react");
5
+ exports.CompositionRenderErrorContext = (0, react_1.createContext)({
6
+ setError: () => { },
7
+ clearError: () => { },
8
+ });
@@ -0,0 +1,7 @@
1
+ export declare const getTimelineDuration: ({ compositionDurationInFrames, playbackRate, trimBefore, trimAfter, parentSequenceDurationInFrames, }: {
2
+ compositionDurationInFrames: number;
3
+ playbackRate: number;
4
+ trimBefore: number | undefined;
5
+ trimAfter: number | undefined;
6
+ parentSequenceDurationInFrames: number | null;
7
+ }) => number;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTimelineDuration = void 0;
4
+ const calculate_media_duration_js_1 = require("./calculate-media-duration.js");
5
+ const getTimelineDuration = ({ compositionDurationInFrames, playbackRate, trimBefore, trimAfter, parentSequenceDurationInFrames, }) => {
6
+ const mediaDuration = (0, calculate_media_duration_js_1.calculateMediaDuration)({
7
+ mediaDurationInFrames: compositionDurationInFrames * playbackRate + (trimBefore !== null && trimBefore !== void 0 ? trimBefore : 0),
8
+ playbackRate,
9
+ trimBefore,
10
+ trimAfter,
11
+ });
12
+ if (parentSequenceDurationInFrames !== null) {
13
+ return Math.floor(Math.min(parentSequenceDurationInFrames * playbackRate, mediaDuration));
14
+ }
15
+ return mediaDuration;
16
+ };
17
+ exports.getTimelineDuration = getTimelineDuration;
@@ -132,6 +132,7 @@ export * from './use-video-config.js';
132
132
  export * from './version.js';
133
133
  export * from './video-config.js';
134
134
  export { Html5Video, OffthreadVideo, OffthreadVideoProps, RemotionMainVideoProps, RemotionOffthreadVideoProps, RemotionVideoProps, Video, } from './video/index.js';
135
+ export { MediaPlaybackError } from './video/MediaPlaybackError.js';
135
136
  export type { OnVideoFrame } from './video/props.js';
136
137
  export type { VolumeProp } from './volume-prop.js';
137
138
  export { watchStaticFile } from './watch-static-file.js';
package/dist/cjs/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.Config = exports.Experimental = exports.watchStaticFile = exports.Video = exports.OffthreadVideo = exports.Html5Video = exports.useRemotionEnvironment = exports.useDelayRender = exports.useCurrentScale = exports.useCurrentFrame = exports.useBufferState = exports.staticFile = exports.Series = exports.Sequence = exports.registerRoot = exports.prefetch = exports.random = exports.interpolate = exports.Loop = exports.interpolateColors = exports.Img = exports.getStaticFiles = exports.getRemotionEnvironment = exports.delayRender = exports.continueRender = exports.getInputProps = exports.Composition = exports.cancelRender = exports.Html5Audio = exports.Audio = exports.Artifact = void 0;
17
+ exports.Config = exports.Experimental = exports.watchStaticFile = exports.MediaPlaybackError = exports.Video = exports.OffthreadVideo = exports.Html5Video = exports.useRemotionEnvironment = exports.useDelayRender = exports.useCurrentScale = exports.useCurrentFrame = exports.useBufferState = exports.staticFile = exports.Series = exports.Sequence = exports.registerRoot = exports.prefetch = exports.random = exports.interpolate = exports.Loop = exports.interpolateColors = exports.Img = exports.getStaticFiles = exports.getRemotionEnvironment = exports.delayRender = exports.continueRender = exports.getInputProps = exports.Composition = exports.cancelRender = exports.Html5Audio = exports.Audio = exports.Artifact = void 0;
18
18
  require("./_check-rsc.js");
19
19
  require("./asset-types.js");
20
20
  const Clipper_js_1 = require("./Clipper.js");
@@ -88,6 +88,8 @@ var index_js_4 = require("./video/index.js");
88
88
  Object.defineProperty(exports, "Html5Video", { enumerable: true, get: function () { return index_js_4.Html5Video; } });
89
89
  Object.defineProperty(exports, "OffthreadVideo", { enumerable: true, get: function () { return index_js_4.OffthreadVideo; } });
90
90
  Object.defineProperty(exports, "Video", { enumerable: true, get: function () { return index_js_4.Video; } });
91
+ var MediaPlaybackError_js_1 = require("./video/MediaPlaybackError.js");
92
+ Object.defineProperty(exports, "MediaPlaybackError", { enumerable: true, get: function () { return MediaPlaybackError_js_1.MediaPlaybackError; } });
91
93
  var watch_static_file_js_1 = require("./watch-static-file.js");
92
94
  Object.defineProperty(exports, "watchStaticFile", { enumerable: true, get: function () { return watch_static_file_js_1.watchStaticFile; } });
93
95
  exports.Experimental = {
@@ -440,5 +440,6 @@ export declare const Internals: {
440
440
  defaultValue: unknown;
441
441
  shouldResortToDefaultValueIfUndefined: boolean;
442
442
  }) => unknown;
443
+ readonly CompositionRenderErrorContext: import("react").Context<import("./composition-render-error-context.js").CompositionRenderErrorContextType>;
443
444
  };
444
445
  export type { CompositionManagerContext, ResolvedStackLocation, CompProps, LoggingContextValue, MediaVolumeContextValue, RemotionEnvironment, SequenceFieldSchema, SequenceSchema, SerializedJSONWithCustomFields, SetMediaVolumeContextValue, SetTimelineContextValue, TCompMetadata, TComposition, TimelineContextValue, TRenderAsset, TSequence, WatchRemotionStaticFilesPayload, ScheduleAudioNodeOptions, CanUpdateSequencePropStatus, ScheduleAudioNodeResult, NonceHistory, };
@@ -42,6 +42,7 @@ const use_audio_frame_js_1 = require("./audio/use-audio-frame.js");
42
42
  const buffering_js_1 = require("./buffering.js");
43
43
  const calculate_media_duration_js_1 = require("./calculate-media-duration.js");
44
44
  const CanUseRemotionHooks_js_1 = require("./CanUseRemotionHooks.js");
45
+ const composition_render_error_context_js_1 = require("./composition-render-error-context.js");
45
46
  const CompositionManager_js_1 = require("./CompositionManager.js");
46
47
  const CompositionManagerContext_js_1 = require("./CompositionManagerContext.js");
47
48
  const CompositionManagerProvider_js_1 = require("./CompositionManagerProvider.js");
@@ -208,4 +209,5 @@ exports.Internals = {
208
209
  AbsoluteTimeContext: TimelineContext_js_1.AbsoluteTimeContext,
209
210
  RenderAssetManagerProvider: RenderAssetManager_js_1.RenderAssetManagerProvider,
210
211
  getEffectiveVisualModeValue: get_effective_visual_mode_value_js_1.getEffectiveVisualModeValue,
212
+ CompositionRenderErrorContext: composition_render_error_context_js_1.CompositionRenderErrorContext,
211
213
  };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Visual-mode fields for clip timing. Used by `<Sequence>` and merged into media schemas (e.g. `@remotion/media` `<Video>`).
3
+ */
4
+ export declare const SEQUENCE_TIMING_SCHEMA: {
5
+ readonly from: {
6
+ readonly type: "number";
7
+ readonly min: 0;
8
+ readonly step: 1;
9
+ readonly default: 0;
10
+ readonly description: "From";
11
+ };
12
+ readonly durationInFrames: {
13
+ readonly type: "number";
14
+ readonly min: 0.01;
15
+ readonly step: 0.01;
16
+ readonly default: undefined;
17
+ readonly description: "Duration in frames";
18
+ };
19
+ };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SEQUENCE_TIMING_SCHEMA = void 0;
4
+ /**
5
+ * Visual-mode fields for clip timing. Used by `<Sequence>` and merged into media schemas (e.g. `@remotion/media` `<Video>`).
6
+ */
7
+ exports.SEQUENCE_TIMING_SCHEMA = {
8
+ from: {
9
+ type: 'number',
10
+ min: 0,
11
+ step: 1,
12
+ default: 0,
13
+ description: 'From',
14
+ },
15
+ durationInFrames: {
16
+ type: 'number',
17
+ min: 0.01,
18
+ step: 0.01,
19
+ default: undefined,
20
+ description: 'Duration in frames',
21
+ },
22
+ };
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useMediaInTimeline = exports.useImageInTimeline = exports.useBasicMediaInTimeline = void 0;
4
4
  const react_1 = require("react");
5
5
  const use_audio_frame_js_1 = require("./audio/use-audio-frame.js");
6
- const calculate_media_duration_js_1 = require("./calculate-media-duration.js");
7
6
  const get_asset_file_name_js_1 = require("./get-asset-file-name.js");
7
+ const get_timeline_duration_js_1 = require("./get-timeline-duration.js");
8
8
  const nonce_js_1 = require("./nonce.js");
9
9
  const SequenceContext_js_1 = require("./SequenceContext.js");
10
10
  const SequenceManager_js_1 = require("./SequenceManager.js");
@@ -22,6 +22,7 @@ const warnOnce = (message) => {
22
22
  didWarn[message] = true;
23
23
  };
24
24
  const useBasicMediaInTimeline = ({ volume, mediaVolume, mediaType, src, displayName, trimBefore, trimAfter, playbackRate, }) => {
25
+ var _a;
25
26
  if (!src) {
26
27
  throw new Error('No src passed');
27
28
  }
@@ -29,15 +30,13 @@ const useBasicMediaInTimeline = ({ volume, mediaVolume, mediaType, src, displayN
29
30
  const parentSequence = (0, react_1.useContext)(SequenceContext_js_1.SequenceContext);
30
31
  const videoConfig = (0, use_video_config_js_1.useVideoConfig)();
31
32
  const [initialVolume] = (0, react_1.useState)(() => volume);
32
- const mediaDuration = (0, calculate_media_duration_js_1.calculateMediaDuration)({
33
- mediaDurationInFrames: videoConfig.durationInFrames + (trimBefore !== null && trimBefore !== void 0 ? trimBefore : 0),
33
+ const duration = (0, get_timeline_duration_js_1.getTimelineDuration)({
34
+ compositionDurationInFrames: videoConfig.durationInFrames,
34
35
  playbackRate,
35
36
  trimBefore,
36
37
  trimAfter,
38
+ parentSequenceDurationInFrames: (_a = parentSequence === null || parentSequence === void 0 ? void 0 : parentSequence.durationInFrames) !== null && _a !== void 0 ? _a : null,
37
39
  });
38
- const duration = parentSequence
39
- ? Math.min(parentSequence.durationInFrames, mediaDuration)
40
- : mediaDuration;
41
40
  const volumes = (0, react_1.useMemo)(() => {
42
41
  if (typeof volume === 'number') {
43
42
  return volume;
@@ -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.443";
6
+ export declare const VERSION = "4.0.445";
@@ -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.443';
10
+ exports.VERSION = '4.0.445';
@@ -0,0 +1,7 @@
1
+ export declare class MediaPlaybackError extends Error {
2
+ readonly src: string;
3
+ constructor({ message, src }: {
4
+ message: string;
5
+ src: string;
6
+ });
7
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MediaPlaybackError = void 0;
4
+ class MediaPlaybackError extends Error {
5
+ constructor({ message, src }) {
6
+ super(message);
7
+ this.name = 'MediaPlaybackError';
8
+ this.src = src;
9
+ }
10
+ }
11
+ exports.MediaPlaybackError = MediaPlaybackError;
@@ -55,6 +55,7 @@ const volume_position_state_js_1 = require("../volume-position-state.js");
55
55
  const volume_prop_js_1 = require("../volume-prop.js");
56
56
  const volume_safeguard_js_1 = require("../volume-safeguard.js");
57
57
  const emit_video_frame_js_1 = require("./emit-video-frame.js");
58
+ const MediaPlaybackError_js_1 = require("./MediaPlaybackError.js");
58
59
  const video_fragment_js_1 = require("./video-fragment.js");
59
60
  const VideoForDevelopmentRefForwardingFunction = (props, ref) => {
60
61
  var _a, _b, _c, _d, _e, _f;
@@ -192,20 +193,32 @@ const VideoForDevelopmentRefForwardingFunction = (props, ref) => {
192
193
  console.error('Error occurred in video', current === null || current === void 0 ? void 0 : current.error);
193
194
  // If user is handling the error, we don't cause an unhandled exception
194
195
  if (onError) {
195
- const err = new Error(`Code ${current.error.code}: ${current.error.message}`);
196
+ const err = new MediaPlaybackError_js_1.MediaPlaybackError({
197
+ message: `Code ${current.error.code}: ${current.error.message}`,
198
+ src: src,
199
+ });
196
200
  onError(err);
197
201
  return;
198
202
  }
199
- throw new Error(`The browser threw an error while playing the video ${src}: Code ${current.error.code} - ${(_a = current === null || current === void 0 ? void 0 : current.error) === null || _a === void 0 ? void 0 : _a.message}. See https://remotion.dev/docs/media-playback-error for help. Pass an onError() prop to handle the error.`);
203
+ throw new MediaPlaybackError_js_1.MediaPlaybackError({
204
+ message: `The browser threw an error while playing the video ${src}: Code ${current.error.code} - ${(_a = current === null || current === void 0 ? void 0 : current.error) === null || _a === void 0 ? void 0 : _a.message}. See https://remotion.dev/docs/media-playback-error for help. Pass an onError() prop to handle the error.`,
205
+ src: src,
206
+ });
200
207
  }
201
208
  else {
202
209
  // If user is handling the error, we don't cause an unhandled exception
203
210
  if (onError) {
204
- const err = new Error(`The browser threw an error while playing the video ${src}`);
211
+ const err = new MediaPlaybackError_js_1.MediaPlaybackError({
212
+ message: `The browser threw an error while playing the video ${src}`,
213
+ src: src,
214
+ });
205
215
  onError(err);
206
216
  return;
207
217
  }
208
- throw new Error('The browser threw an error while playing the video');
218
+ throw new MediaPlaybackError_js_1.MediaPlaybackError({
219
+ message: 'The browser threw an error while playing the video',
220
+ src: src,
221
+ });
209
222
  }
210
223
  };
211
224
  current.addEventListener('error', errorHandler, { once: true });
@@ -18,6 +18,7 @@ const use_unsafe_video_config_js_1 = require("../use-unsafe-video-config.js");
18
18
  const volume_prop_js_1 = require("../volume-prop.js");
19
19
  const volume_safeguard_js_1 = require("../volume-safeguard.js");
20
20
  const get_current_time_js_1 = require("./get-current-time.js");
21
+ const MediaPlaybackError_js_1 = require("./MediaPlaybackError.js");
21
22
  const seek_until_right_js_1 = require("./seek-until-right.js");
22
23
  const VideoForRenderingForwardFunction = ({ onError, volume: volumeProp, allowAmplificationDuringRender, playbackRate, onDuration, toneFrequency, name, acceptableTimeShiftInSeconds, delayRenderRetries, delayRenderTimeoutInMilliseconds, loopVolumeCurveBehavior, audioStreamIndex, onVideoFrame, ...props }, ref) => {
23
24
  const absoluteFrame = (0, timeline_position_state_js_1.useTimelinePosition)();
@@ -155,10 +156,16 @@ const VideoForRenderingForwardFunction = ({ onError, volume: volumeProp, allowAm
155
156
  if (onError) {
156
157
  return;
157
158
  }
158
- throw new Error(`The browser threw an error while playing the video ${props.src}: Code ${current.error.code} - ${(_a = current === null || current === void 0 ? void 0 : current.error) === null || _a === void 0 ? void 0 : _a.message}. See https://remotion.dev/docs/media-playback-error for help. Pass an onError() prop to handle the error.`);
159
+ throw new MediaPlaybackError_js_1.MediaPlaybackError({
160
+ message: `The browser threw an error while playing the video ${props.src}: Code ${current.error.code} - ${(_a = current === null || current === void 0 ? void 0 : current.error) === null || _a === void 0 ? void 0 : _a.message}. See https://remotion.dev/docs/media-playback-error for help. Pass an onError() prop to handle the error.`,
161
+ src: props.src,
162
+ });
159
163
  }
160
164
  else {
161
- throw new Error('The browser threw an error');
165
+ throw new MediaPlaybackError_js_1.MediaPlaybackError({
166
+ message: 'The browser threw an error',
167
+ src: props.src,
168
+ });
162
169
  }
163
170
  };
164
171
  current.addEventListener('error', errorHandler, { once: true });