remotion 4.0.108 → 4.0.109

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.
@@ -0,0 +1 @@
1
+ export declare const getTimelineClipName: (children: React.ReactNode) => string;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTimelineClipName = void 0;
4
+ const react_1 = require("react");
5
+ const HIDDEN_NAMES = ['__WEBPACK_DEFAULT_EXPORT__'];
6
+ const getTimelineClipName = (children) => {
7
+ var _a;
8
+ const tree = (_a = react_1.Children.map(children, (ch) => {
9
+ if (!(0, react_1.isValidElement)(ch)) {
10
+ return null;
11
+ }
12
+ // Must be name, not ID
13
+ const name = typeof ch.type !== 'string' && ch.type.name;
14
+ if (name && !HIDDEN_NAMES.includes(name)) {
15
+ return name;
16
+ }
17
+ if (ch.props.children) {
18
+ const chName = (0, exports.getTimelineClipName)(ch.props.children);
19
+ return chName;
20
+ }
21
+ return null;
22
+ })) === null || _a === void 0 ? void 0 : _a.filter(Boolean);
23
+ return (tree === null || tree === void 0 ? void 0 : tree.length) ? tree[0] : '';
24
+ };
25
+ exports.getTimelineClipName = getTimelineClipName;
@@ -1 +1 @@
1
- export declare const VERSION = "4.0.108";
1
+ export declare const VERSION = "4.0.109";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // Automatically generated on publish
5
- exports.VERSION = '4.0.108';
5
+ exports.VERSION = '4.0.109';
@@ -105,7 +105,7 @@ function truthy(value) {
105
105
  }
106
106
 
107
107
  // Automatically generated on publish
108
- const VERSION = '4.0.108';
108
+ const VERSION = '4.0.109';
109
109
 
110
110
  const checkMultipleRemotionVersions = () => {
111
111
  if (typeof globalThis === 'undefined') {
@@ -1,4 +1,4 @@
1
1
  // Automatically generated on publish
2
- const VERSION = '4.0.108';
2
+ const VERSION = '4.0.109';
3
3
 
4
4
  export { VERSION };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remotion",
3
- "version": "4.0.108",
3
+ "version": "4.0.109",
4
4
  "description": "Render videos in React",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",
@@ -1,11 +0,0 @@
1
- import React from 'react';
2
- import type { RemotionAudioProps } from './props.js';
3
- type AudioForPreviewProps = RemotionAudioProps & {
4
- shouldPreMountAudioTags: boolean;
5
- onDuration: (src: string, durationInSeconds: number) => void;
6
- pauseWhenBuffering: boolean;
7
- _remotionInternalNativeLoopPassed: boolean;
8
- _remotionInternalStack: string | null;
9
- };
10
- export declare const AudioForPreview: React.ForwardRefExoticComponent<Omit<AudioForPreviewProps, "ref"> & React.RefAttributes<HTMLAudioElement>>;
11
- export {};
@@ -1,119 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AudioForPreview = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const react_1 = require("react");
6
- const prefetch_js_1 = require("../prefetch.js");
7
- const random_js_1 = require("../random.js");
8
- const SequenceContext_js_1 = require("../SequenceContext.js");
9
- const SequenceManager_js_1 = require("../SequenceManager.js");
10
- const use_media_buffering_js_1 = require("../use-media-buffering.js");
11
- const use_media_in_timeline_js_1 = require("../use-media-in-timeline.js");
12
- const use_media_playback_js_1 = require("../use-media-playback.js");
13
- const use_media_tag_volume_js_1 = require("../use-media-tag-volume.js");
14
- const use_sync_volume_with_media_tag_js_1 = require("../use-sync-volume-with-media-tag.js");
15
- const volume_position_state_js_1 = require("../volume-position-state.js");
16
- const shared_audio_tags_js_1 = require("./shared-audio-tags.js");
17
- const use_audio_frame_js_1 = require("./use-audio-frame.js");
18
- const AudioForDevelopmentForwardRefFunction = (props, ref) => {
19
- var _a;
20
- const [initialShouldPreMountAudioElements] = (0, react_1.useState)(props.shouldPreMountAudioTags);
21
- if (props.shouldPreMountAudioTags !== initialShouldPreMountAudioElements) {
22
- throw new Error('Cannot change the behavior for pre-mounting audio tags dynamically.');
23
- }
24
- const [mediaVolume] = (0, volume_position_state_js_1.useMediaVolumeState)();
25
- const [mediaMuted] = (0, volume_position_state_js_1.useMediaMutedState)();
26
- const volumePropFrame = (0, use_audio_frame_js_1.useFrameForVolumeProp)();
27
- const { volume, muted, playbackRate, shouldPreMountAudioTags, src, onDuration, acceptableTimeShiftInSeconds, _remotionInternalNeedsDurationCalculation, _remotionInternalNativeLoopPassed, _remotionInternalStack, allowAmplificationDuringRender, name, pauseWhenBuffering, ...nativeProps } = props;
28
- const { hidden } = (0, react_1.useContext)(SequenceManager_js_1.SequenceVisibilityToggleContext);
29
- if (!src) {
30
- throw new TypeError("No 'src' was passed to <Audio>.");
31
- }
32
- const preloadedSrc = (0, prefetch_js_1.usePreload)(src);
33
- const sequenceContext = (0, react_1.useContext)(SequenceContext_js_1.SequenceContext);
34
- const [timelineId] = (0, react_1.useState)(() => String(Math.random()));
35
- const isSequenceHidden = (_a = hidden[timelineId]) !== null && _a !== void 0 ? _a : false;
36
- const propsToPass = (0, react_1.useMemo)(() => {
37
- return {
38
- muted: muted || mediaMuted || isSequenceHidden,
39
- src: preloadedSrc,
40
- loop: _remotionInternalNativeLoopPassed,
41
- ...nativeProps,
42
- };
43
- }, [
44
- _remotionInternalNativeLoopPassed,
45
- isSequenceHidden,
46
- mediaMuted,
47
- muted,
48
- nativeProps,
49
- preloadedSrc,
50
- ]);
51
- // Generate a string that's as unique as possible for this asset
52
- // but at the same time deterministic. We use it to combat strict mode issues.
53
- const id = (0, react_1.useMemo)(() => `audio-${(0, random_js_1.random)(src !== null && src !== void 0 ? src : '')}-${sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom}-${sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.cumulatedFrom}-${sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.durationInFrames}-muted:${props.muted}-loop:${props.loop}`, [
54
- src,
55
- sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom,
56
- sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.cumulatedFrom,
57
- sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.durationInFrames,
58
- props.muted,
59
- props.loop,
60
- ]);
61
- const audioRef = (0, shared_audio_tags_js_1.useSharedAudio)(propsToPass, id).el;
62
- const actualVolume = (0, use_media_tag_volume_js_1.useMediaTagVolume)(audioRef);
63
- (0, use_sync_volume_with_media_tag_js_1.useSyncVolumeWithMediaTag)({
64
- volumePropFrame,
65
- actualVolume,
66
- volume,
67
- mediaVolume,
68
- mediaRef: audioRef,
69
- });
70
- (0, use_media_in_timeline_js_1.useMediaInTimeline)({
71
- volume,
72
- mediaVolume,
73
- mediaRef: audioRef,
74
- src,
75
- mediaType: 'audio',
76
- playbackRate: playbackRate !== null && playbackRate !== void 0 ? playbackRate : 1,
77
- displayName: name !== null && name !== void 0 ? name : null,
78
- id: timelineId,
79
- stack: props._remotionInternalStack,
80
- });
81
- (0, use_media_playback_js_1.useMediaPlayback)({
82
- mediaRef: audioRef,
83
- src,
84
- mediaType: 'audio',
85
- playbackRate: playbackRate !== null && playbackRate !== void 0 ? playbackRate : 1,
86
- onlyWarnForMediaSeekingError: false,
87
- acceptableTimeshift: acceptableTimeShiftInSeconds !== null && acceptableTimeShiftInSeconds !== void 0 ? acceptableTimeShiftInSeconds : use_media_playback_js_1.DEFAULT_ACCEPTABLE_TIMESHIFT,
88
- });
89
- (0, use_media_buffering_js_1.useMediaBuffering)(audioRef, pauseWhenBuffering);
90
- (0, react_1.useImperativeHandle)(ref, () => {
91
- return audioRef.current;
92
- }, [audioRef]);
93
- const currentOnDurationCallback = (0, react_1.useRef)();
94
- currentOnDurationCallback.current = onDuration;
95
- (0, react_1.useEffect)(() => {
96
- var _a;
97
- const { current } = audioRef;
98
- if (!current) {
99
- return;
100
- }
101
- if (current.duration) {
102
- (_a = currentOnDurationCallback.current) === null || _a === void 0 ? void 0 : _a.call(currentOnDurationCallback, current.src, current.duration);
103
- return;
104
- }
105
- const onLoadedMetadata = () => {
106
- var _a;
107
- (_a = currentOnDurationCallback.current) === null || _a === void 0 ? void 0 : _a.call(currentOnDurationCallback, current.src, current.duration);
108
- };
109
- current.addEventListener('loadedmetadata', onLoadedMetadata);
110
- return () => {
111
- current.removeEventListener('loadedmetadata', onLoadedMetadata);
112
- };
113
- }, [audioRef, src]);
114
- if (initialShouldPreMountAudioElements) {
115
- return null;
116
- }
117
- return (0, jsx_runtime_1.jsx)("audio", { ref: audioRef, preload: "metadata", ...propsToPass });
118
- };
119
- exports.AudioForPreview = (0, react_1.forwardRef)(AudioForDevelopmentForwardRefFunction);
@@ -1,26 +0,0 @@
1
- import React from 'react';
2
- type Block = {
3
- id: string;
4
- };
5
- type OnBufferingCallback = () => void;
6
- type OnResumeCallback = () => void;
7
- type ListenForBuffering = (callback: OnBufferingCallback) => {
8
- remove: () => void;
9
- };
10
- type ListenForResume = (callback: OnResumeCallback) => {
11
- remove: () => void;
12
- };
13
- type AddBlock = (block: Block) => {
14
- unblock: () => void;
15
- };
16
- type BufferManager = {
17
- addBlock: AddBlock;
18
- listenForBuffering: ListenForBuffering;
19
- listenForResume: ListenForResume;
20
- buffering: React.MutableRefObject<boolean>;
21
- };
22
- export declare const BufferingContextReact: React.Context<BufferManager | null>;
23
- export declare const BufferingProvider: React.FC<{
24
- children: React.ReactNode;
25
- }>;
26
- export {};
@@ -1,75 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.BufferingProvider = exports.BufferingContextReact = void 0;
27
- const jsx_runtime_1 = require("react/jsx-runtime");
28
- const react_1 = __importStar(require("react"));
29
- const useBufferManager = () => {
30
- const [blocks, setBlocks] = (0, react_1.useState)([]);
31
- const [onBufferingCallbacks, setOnBufferingCallbacks] = (0, react_1.useState)([]);
32
- const [onResumeCallbacks, setOnResumeCallbacks] = (0, react_1.useState)([]);
33
- const buffering = (0, react_1.useRef)(false);
34
- const addBlock = (0, react_1.useCallback)((block) => {
35
- setBlocks((b) => [...b, block]);
36
- return {
37
- unblock: () => {
38
- setBlocks((b) => b.filter((bx) => bx !== block));
39
- },
40
- };
41
- }, []);
42
- const listenForBuffering = (0, react_1.useCallback)((callback) => {
43
- setOnBufferingCallbacks((c) => [...c, callback]);
44
- return {
45
- remove: () => {
46
- setOnBufferingCallbacks((c) => c.filter((cb) => cb !== callback));
47
- },
48
- };
49
- }, []);
50
- const listenForResume = (0, react_1.useCallback)((callback) => {
51
- setOnResumeCallbacks((c) => [...c, callback]);
52
- return {
53
- remove: () => {
54
- setOnResumeCallbacks((c) => c.filter((cb) => cb !== callback));
55
- },
56
- };
57
- }, []);
58
- (0, react_1.useEffect)(() => {
59
- if (blocks.length > 0) {
60
- onBufferingCallbacks.forEach((c) => c());
61
- }
62
- else {
63
- onResumeCallbacks.forEach((c) => c());
64
- }
65
- }, [blocks, onBufferingCallbacks, onResumeCallbacks]);
66
- return (0, react_1.useMemo)(() => {
67
- return { addBlock, listenForBuffering, listenForResume, buffering };
68
- }, [addBlock, buffering, listenForBuffering, listenForResume]);
69
- };
70
- exports.BufferingContextReact = react_1.default.createContext(null);
71
- const BufferingProvider = ({ children }) => {
72
- const bufferManager = useBufferManager();
73
- return ((0, jsx_runtime_1.jsx)(exports.BufferingContextReact.Provider, { value: bufferManager, children: children }));
74
- };
75
- exports.BufferingProvider = BufferingProvider;
@@ -1,5 +0,0 @@
1
- export declare const useBufferState: () => {
2
- delayPlayback: () => {
3
- unblock: () => void;
4
- };
5
- };
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useBufferState = void 0;
4
- const react_1 = require("react");
5
- const buffering_1 = require("./buffering");
6
- const CanUseRemotionHooks_1 = require("./CanUseRemotionHooks");
7
- const useBufferState = () => {
8
- const canUseRemotionHooks = (0, react_1.useContext)(CanUseRemotionHooks_1.CanUseRemotionHooks);
9
- if (!canUseRemotionHooks) {
10
- if (typeof window !== 'undefined' && window.remotion_isPlayer) {
11
- throw new Error(`useCurrentFrame can only be called inside a component that was passed to <Player>. See: https://www.remotion.dev/docs/player/examples`);
12
- }
13
- 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`);
14
- }
15
- const buffer = (0, react_1.useContext)(buffering_1.BufferingContextReact);
16
- if (!buffer) {
17
- throw new Error('BufferingContextReact was unexpectedly not found. Most likely your Remotion versions are mismatching.');
18
- }
19
- return (0, react_1.useMemo)(() => ({
20
- delayPlayback: () => {
21
- const { unblock } = buffer.addBlock({
22
- id: String(Math.random()),
23
- });
24
- return { unblock };
25
- },
26
- }), [buffer]);
27
- };
28
- exports.useBufferState = useBufferState;
@@ -1,5 +0,0 @@
1
- export declare const useBufferState: () => {
2
- delayPlayback: () => {
3
- unblock: () => void;
4
- };
5
- };
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useBufferState = void 0;
4
- const react_1 = require("react");
5
- const buffering_1 = require("./buffering");
6
- const CanUseRemotionHooks_1 = require("./CanUseRemotionHooks");
7
- const useBufferState = () => {
8
- const canUseRemotionHooks = (0, react_1.useContext)(CanUseRemotionHooks_1.CanUseRemotionHooks);
9
- if (!canUseRemotionHooks) {
10
- if (typeof window !== 'undefined' && window.remotion_isPlayer) {
11
- throw new Error(`useCurrentFrame can only be called inside a component that was passed to <Player>. See: https://www.remotion.dev/docs/player/examples`);
12
- }
13
- 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`);
14
- }
15
- const buffer = (0, react_1.useContext)(buffering_1.BufferingContextReact);
16
- if (!buffer) {
17
- throw new Error('BufferingContextReact was unexpectedly not found. Most likely your Remotion versions are mismatching.');
18
- }
19
- return (0, react_1.useMemo)(() => ({
20
- delayPlayback: () => {
21
- const { unblock } = buffer.addBlock({
22
- id: String(Math.random()),
23
- });
24
- return { unblock };
25
- },
26
- }), [buffer]);
27
- };
28
- exports.useBufferState = useBufferState;
@@ -1,2 +0,0 @@
1
- import type React from 'react';
2
- export declare const useMediaBuffering: (element: React.RefObject<HTMLVideoElement | HTMLAudioElement>, shouldBuffer: boolean) => void;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useMediaBuffering = void 0;
4
- const react_1 = require("react");
5
- const use_buffer_state_1 = require("./use-buffer-state");
6
- const useMediaBuffering = (element, shouldBuffer) => {
7
- const buffer = (0, use_buffer_state_1.useBufferState)();
8
- (0, react_1.useEffect)(() => {
9
- let cleanup = () => undefined;
10
- const { current } = element;
11
- if (!current) {
12
- return;
13
- }
14
- if (!shouldBuffer) {
15
- return;
16
- }
17
- const onWaiting = () => {
18
- const { unblock } = buffer.delayPlayback();
19
- const onCanPlay = () => {
20
- unblock();
21
- };
22
- current.addEventListener('canplay', onCanPlay, {
23
- once: true,
24
- });
25
- cleanup = () => {
26
- current.removeEventListener('canplay', onCanPlay);
27
- return undefined;
28
- };
29
- };
30
- if (current.readyState < current.HAVE_FUTURE_DATA) {
31
- onWaiting();
32
- }
33
- else {
34
- current.addEventListener('waiting', onWaiting);
35
- }
36
- return () => {
37
- cleanup();
38
- };
39
- }, [buffer, element, shouldBuffer]);
40
- };
41
- exports.useMediaBuffering = useMediaBuffering;
@@ -1,11 +0,0 @@
1
- import React from 'react';
2
- import type { RemotionVideoProps } from './props.js';
3
- type VideoForPreviewProps = RemotionVideoProps & {
4
- onlyWarnForMediaSeekingError: boolean;
5
- onDuration: (src: string, durationInSeconds: number) => void;
6
- pauseWhenBuffering: boolean;
7
- _remotionInternalNativeLoopPassed: boolean;
8
- _remotionInternalStack: string | null;
9
- };
10
- export declare const VideoForPreview: React.ForwardRefExoticComponent<Omit<VideoForPreviewProps, "ref"> & React.RefAttributes<HTMLVideoElement>>;
11
- export {};
@@ -1,150 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VideoForPreview = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const react_1 = require("react");
6
- const use_audio_frame_js_1 = require("../audio/use-audio-frame.js");
7
- const prefetch_js_1 = require("../prefetch.js");
8
- const SequenceContext_js_1 = require("../SequenceContext.js");
9
- const SequenceManager_js_1 = require("../SequenceManager.js");
10
- const use_media_buffering_js_1 = require("../use-media-buffering.js");
11
- const use_media_in_timeline_js_1 = require("../use-media-in-timeline.js");
12
- const use_media_playback_js_1 = require("../use-media-playback.js");
13
- const use_media_tag_volume_js_1 = require("../use-media-tag-volume.js");
14
- const use_sync_volume_with_media_tag_js_1 = require("../use-sync-volume-with-media-tag.js");
15
- const use_video_config_js_1 = require("../use-video-config.js");
16
- const volume_position_state_js_1 = require("../volume-position-state.js");
17
- const video_fragment_js_1 = require("./video-fragment.js");
18
- const VideoForDevelopmentRefForwardingFunction = (props, ref) => {
19
- var _a, _b, _c;
20
- const videoRef = (0, react_1.useRef)(null);
21
- const volumePropFrame = (0, use_audio_frame_js_1.useFrameForVolumeProp)();
22
- const { fps, durationInFrames } = (0, use_video_config_js_1.useVideoConfig)();
23
- const parentSequence = (0, react_1.useContext)(SequenceContext_js_1.SequenceContext);
24
- const { hidden } = (0, react_1.useContext)(SequenceManager_js_1.SequenceVisibilityToggleContext);
25
- const [timelineId] = (0, react_1.useState)(() => String(Math.random()));
26
- const isSequenceHidden = (_a = hidden[timelineId]) !== null && _a !== void 0 ? _a : false;
27
- const { volume, muted, playbackRate, onlyWarnForMediaSeekingError, src, onDuration,
28
- // @ts-expect-error
29
- acceptableTimeShift, acceptableTimeShiftInSeconds, toneFrequency, name, _remotionInternalNativeLoopPassed, _remotionInternalStack, style, pauseWhenBuffering, ...nativeProps } = props;
30
- if (typeof acceptableTimeShift !== 'undefined') {
31
- throw new Error('acceptableTimeShift has been removed. Use acceptableTimeShiftInSeconds instead.');
32
- }
33
- const actualVolume = (0, use_media_tag_volume_js_1.useMediaTagVolume)(videoRef);
34
- const [mediaVolume] = (0, volume_position_state_js_1.useMediaVolumeState)();
35
- const [mediaMuted] = (0, volume_position_state_js_1.useMediaMutedState)();
36
- (0, use_media_in_timeline_js_1.useMediaInTimeline)({
37
- mediaRef: videoRef,
38
- volume,
39
- mediaVolume,
40
- mediaType: 'video',
41
- src,
42
- playbackRate: (_b = props.playbackRate) !== null && _b !== void 0 ? _b : 1,
43
- displayName: name !== null && name !== void 0 ? name : null,
44
- id: timelineId,
45
- stack: props._remotionInternalStack,
46
- });
47
- (0, use_sync_volume_with_media_tag_js_1.useSyncVolumeWithMediaTag)({
48
- volumePropFrame,
49
- actualVolume,
50
- volume,
51
- mediaVolume,
52
- mediaRef: videoRef,
53
- });
54
- (0, use_media_playback_js_1.useMediaPlayback)({
55
- mediaRef: videoRef,
56
- src,
57
- mediaType: 'video',
58
- playbackRate: (_c = props.playbackRate) !== null && _c !== void 0 ? _c : 1,
59
- onlyWarnForMediaSeekingError,
60
- acceptableTimeshift: acceptableTimeShiftInSeconds !== null && acceptableTimeShiftInSeconds !== void 0 ? acceptableTimeShiftInSeconds : use_media_playback_js_1.DEFAULT_ACCEPTABLE_TIMESHIFT,
61
- });
62
- (0, use_media_buffering_js_1.useMediaBuffering)(videoRef, pauseWhenBuffering);
63
- const actualFrom = parentSequence
64
- ? parentSequence.relativeFrom + parentSequence.cumulatedFrom
65
- : 0;
66
- const duration = parentSequence
67
- ? Math.min(parentSequence.durationInFrames, durationInFrames)
68
- : durationInFrames;
69
- const actualSrc = (0, video_fragment_js_1.useAppendVideoFragment)({
70
- actualSrc: (0, prefetch_js_1.usePreload)(src),
71
- actualFrom,
72
- duration,
73
- fps,
74
- });
75
- (0, react_1.useImperativeHandle)(ref, () => {
76
- return videoRef.current;
77
- }, []);
78
- (0, react_1.useEffect)(() => {
79
- const { current } = videoRef;
80
- if (!current) {
81
- return;
82
- }
83
- const errorHandler = () => {
84
- var _a;
85
- if (current === null || current === void 0 ? void 0 : current.error) {
86
- // eslint-disable-next-line no-console
87
- console.error('Error occurred in video', current === null || current === void 0 ? void 0 : current.error);
88
- // If user is handling the error, we don't cause an unhandled exception
89
- if (props.onError) {
90
- return;
91
- }
92
- 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.`);
93
- }
94
- else {
95
- throw new Error('The browser threw an error');
96
- }
97
- };
98
- current.addEventListener('error', errorHandler, { once: true });
99
- return () => {
100
- current.removeEventListener('error', errorHandler);
101
- };
102
- }, [props.onError, src]);
103
- const currentOnDurationCallback = (0, react_1.useRef)();
104
- currentOnDurationCallback.current = onDuration;
105
- (0, react_1.useEffect)(() => {
106
- var _a;
107
- const { current } = videoRef;
108
- if (!current) {
109
- return;
110
- }
111
- if (current.duration) {
112
- (_a = currentOnDurationCallback.current) === null || _a === void 0 ? void 0 : _a.call(currentOnDurationCallback, src, current.duration);
113
- return;
114
- }
115
- const onLoadedMetadata = () => {
116
- var _a;
117
- (_a = currentOnDurationCallback.current) === null || _a === void 0 ? void 0 : _a.call(currentOnDurationCallback, src, current.duration);
118
- };
119
- current.addEventListener('loadedmetadata', onLoadedMetadata);
120
- return () => {
121
- current.removeEventListener('loadedmetadata', onLoadedMetadata);
122
- };
123
- }, [src]);
124
- (0, react_1.useEffect)(() => {
125
- const { current } = videoRef;
126
- if (!current) {
127
- return;
128
- }
129
- // Without this, on iOS Safari, the video cannot be seeked.
130
- // if a seek is triggered before `loadedmetadata` is fired,
131
- // the video will not seek, even if `loadedmetadata` is fired afterwards.
132
- // Also, this needs to happen in a useEffect, because otherwise
133
- // the SSR props will be applied.
134
- if ((0, video_fragment_js_1.isIosSafari)()) {
135
- current.preload = 'metadata';
136
- }
137
- else {
138
- current.preload = 'auto';
139
- }
140
- }, []);
141
- const actualStyle = (0, react_1.useMemo)(() => {
142
- var _a;
143
- return {
144
- ...style,
145
- opacity: isSequenceHidden ? 0 : (_a = style === null || style === void 0 ? void 0 : style.opacity) !== null && _a !== void 0 ? _a : 1,
146
- };
147
- }, [isSequenceHidden, style]);
148
- return ((0, jsx_runtime_1.jsx)("video", { ref: videoRef, muted: muted || mediaMuted, playsInline: true, src: actualSrc, loop: _remotionInternalNativeLoopPassed, style: actualStyle, ...nativeProps }));
149
- };
150
- exports.VideoForPreview = (0, react_1.forwardRef)(VideoForDevelopmentRefForwardingFunction);