@remotion/player 4.0.0-webhook.27 → 4.1.0-alpha1
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.
- package/LICENSE.md +8 -8
- package/README.md +1 -1
- package/dist/{MediaVolumeSlider.d.ts → cjs/MediaVolumeSlider.d.ts} +0 -0
- package/dist/{MediaVolumeSlider.js → cjs/MediaVolumeSlider.js} +41 -17
- package/dist/cjs/PlaybackrateControl.d.ts +8 -0
- package/dist/cjs/PlaybackrateControl.js +163 -0
- package/dist/cjs/Player.d.ts +52 -0
- package/dist/{Player.js → cjs/Player.js} +41 -87
- package/dist/{PlayerControls.d.ts → cjs/PlayerControls.d.ts} +14 -5
- package/dist/cjs/PlayerControls.js +161 -0
- package/dist/{PlayerSeekBar.d.ts → cjs/PlayerSeekBar.d.ts} +0 -0
- package/dist/{PlayerSeekBar.js → cjs/PlayerSeekBar.js} +6 -6
- package/dist/{PlayerUI.d.ts → cjs/PlayerUI.d.ts} +13 -12
- package/dist/{PlayerUI.js → cjs/PlayerUI.js} +54 -72
- package/dist/cjs/SharedPlayerContext.d.ts +15 -0
- package/dist/cjs/SharedPlayerContext.js +75 -0
- package/dist/cjs/Thumbnail.d.ts +24 -0
- package/dist/cjs/Thumbnail.js +46 -0
- package/dist/cjs/ThumbnailUI.d.ts +11 -0
- package/dist/cjs/ThumbnailUI.js +107 -0
- package/dist/{calculate-next-frame.d.ts → cjs/calculate-next-frame.d.ts} +0 -0
- package/dist/{calculate-next-frame.js → cjs/calculate-next-frame.js} +0 -0
- package/dist/cjs/calculate-scale.d.ts +39 -0
- package/dist/cjs/calculate-scale.js +85 -0
- package/dist/cjs/emitter-context.d.ts +4 -0
- package/dist/{emitter-context.js → cjs/emitter-context.js} +2 -1
- package/dist/{error-boundary.d.ts → cjs/error-boundary.d.ts} +0 -0
- package/dist/{error-boundary.js → cjs/error-boundary.js} +0 -0
- package/dist/cjs/event-emitter.d.ts +81 -0
- package/dist/{event-emitter.js → cjs/event-emitter.js} +43 -3
- package/dist/{format-time.d.ts → cjs/format-time.d.ts} +0 -0
- package/dist/{format-time.js → cjs/format-time.js} +0 -0
- package/dist/{icons.d.ts → cjs/icons.d.ts} +1 -1
- package/dist/{icons.js → cjs/icons.js} +4 -4
- package/dist/{index.d.ts → cjs/index.d.ts} +13 -11
- package/dist/cjs/index.js +25 -0
- package/dist/cjs/is-backgrounded.d.ts +2 -0
- package/dist/cjs/is-backgrounded.js +24 -0
- package/dist/{player-css-classname.d.ts → cjs/player-css-classname.d.ts} +0 -0
- package/dist/{player-css-classname.js → cjs/player-css-classname.js} +0 -0
- package/dist/{player-methods.d.ts → cjs/player-methods.d.ts} +9 -6
- package/dist/{player-methods.js → cjs/player-methods.js} +0 -0
- package/dist/{test → cjs/test}/index.test.d.ts +0 -0
- package/dist/cjs/test/index.test.js +9 -0
- package/dist/{test → cjs/test}/test-utils.d.ts +0 -0
- package/dist/{test → cjs/test}/test-utils.js +0 -0
- package/dist/{test → cjs/test}/validate-in-out-frames.test.d.ts +0 -0
- package/dist/{test → cjs/test}/validate-in-out-frames.test.js +13 -12
- package/dist/{test → cjs/test}/validate-prop.test.d.ts +0 -0
- package/dist/cjs/test/validate-prop.test.js +131 -0
- package/dist/{use-hover-state.d.ts → cjs/use-hover-state.d.ts} +0 -0
- package/dist/{use-hover-state.js → cjs/use-hover-state.js} +0 -0
- package/dist/{use-playback.d.ts → cjs/use-playback.d.ts} +0 -0
- package/dist/{use-playback.js → cjs/use-playback.js} +46 -9
- package/dist/{use-player.d.ts → cjs/use-player.d.ts} +2 -2
- package/dist/{use-player.js → cjs/use-player.js} +2 -2
- package/dist/cjs/use-thumbnail.d.ts +6 -0
- package/dist/cjs/use-thumbnail.js +18 -0
- package/dist/{use-video-controls-resize.d.ts → cjs/use-video-controls-resize.d.ts} +8 -4
- package/dist/{use-video-controls-resize.js → cjs/use-video-controls-resize.js} +16 -13
- package/dist/{utils → cjs/utils}/calculate-player-size.d.ts +1 -1
- package/dist/{utils → cjs/utils}/calculate-player-size.js +9 -10
- package/dist/{utils → cjs/utils}/cancellable-promise.d.ts +1 -1
- package/dist/{utils → cjs/utils}/cancellable-promise.js +0 -0
- package/dist/{utils → cjs/utils}/delay.d.ts +0 -0
- package/dist/{utils → cjs/utils}/delay.js +0 -0
- package/dist/{utils → cjs/utils}/is-node.d.ts +0 -0
- package/dist/{utils → cjs/utils}/is-node.js +0 -0
- package/dist/{utils → cjs/utils}/preview-size.d.ts +2 -2
- package/dist/{utils → cjs/utils}/preview-size.js +0 -0
- package/dist/cjs/utils/props-if-has-props.d.ts +10 -0
- package/dist/cjs/utils/props-if-has-props.js +2 -0
- package/dist/{utils → cjs/utils}/use-cancellable-promises.d.ts +1 -1
- package/dist/{utils → cjs/utils}/use-cancellable-promises.js +0 -0
- package/dist/{utils → cjs/utils}/use-click-prevention-on-double-click.d.ts +0 -0
- package/dist/{utils → cjs/utils}/use-click-prevention-on-double-click.js +5 -5
- package/dist/cjs/utils/use-component-visible.d.ts +6 -0
- package/dist/cjs/utils/use-component-visible.js +21 -0
- package/dist/{utils → cjs/utils}/use-element-size.d.ts +2 -1
- package/dist/{utils → cjs/utils}/use-element-size.js +29 -12
- package/dist/{utils → cjs/utils}/validate-in-out-frame.d.ts +1 -1
- package/dist/{utils → cjs/utils}/validate-in-out-frame.js +13 -13
- package/dist/{utils → cjs/utils}/validate-initial-frame.d.ts +0 -0
- package/dist/{utils → cjs/utils}/validate-initial-frame.js +0 -0
- package/dist/{utils → cjs/utils}/validate-playbackrate.d.ts +0 -0
- package/dist/{utils → cjs/utils}/validate-playbackrate.js +0 -0
- package/dist/{volume-persistance.d.ts → cjs/volume-persistance.d.ts} +0 -0
- package/dist/{volume-persistance.js → cjs/volume-persistance.js} +0 -0
- package/dist/esm/MediaVolumeSlider.d.ts +5 -0
- package/dist/esm/PlaybackrateControl.d.ts +8 -0
- package/dist/esm/Player.d.ts +52 -0
- package/dist/esm/PlayerControls.d.ts +42 -0
- package/dist/esm/PlayerSeekBar.d.ts +8 -0
- package/dist/esm/PlayerUI.d.ts +40 -0
- package/dist/esm/SharedPlayerContext.d.ts +15 -0
- package/dist/esm/Thumbnail.d.ts +24 -0
- package/dist/esm/ThumbnailUI.d.ts +11 -0
- package/dist/esm/calculate-next-frame.d.ts +14 -0
- package/dist/esm/calculate-scale.d.ts +39 -0
- package/dist/esm/emitter-context.d.ts +4 -0
- package/dist/esm/error-boundary.d.ts +19 -0
- package/dist/esm/event-emitter.d.ts +81 -0
- package/dist/esm/format-time.d.ts +1 -0
- package/dist/esm/icons.d.ts +10 -0
- package/dist/esm/index.d.ts +61 -0
- package/dist/esm/index.mjs +2132 -0
- package/dist/esm/is-backgrounded.d.ts +2 -0
- package/dist/esm/player-css-classname.d.ts +1 -0
- package/dist/esm/player-methods.d.ts +24 -0
- package/dist/esm/test/index.test.d.ts +1 -0
- package/dist/esm/test/test-utils.d.ts +6 -0
- package/dist/esm/test/validate-in-out-frames.test.d.ts +1 -0
- package/dist/esm/test/validate-prop.test.d.ts +1 -0
- package/dist/esm/use-hover-state.d.ts +1 -0
- package/dist/esm/use-playback.d.ts +7 -0
- package/dist/esm/use-player.d.ts +19 -0
- package/dist/esm/use-thumbnail.d.ts +6 -0
- package/dist/esm/use-video-controls-resize.d.ts +11 -0
- package/dist/esm/utils/calculate-player-size.d.ts +9 -0
- package/dist/esm/utils/cancellable-promise.d.ts +5 -0
- package/dist/esm/utils/delay.d.ts +1 -0
- package/dist/esm/utils/is-node.d.ts +1 -0
- package/dist/esm/utils/preview-size.d.ts +8 -0
- package/dist/esm/utils/props-if-has-props.d.ts +10 -0
- package/dist/esm/utils/use-cancellable-promises.d.ts +7 -0
- package/dist/esm/utils/use-click-prevention-on-double-click.d.ts +3 -0
- package/dist/esm/utils/use-component-visible.d.ts +6 -0
- package/dist/esm/utils/use-element-size.d.ts +16 -0
- package/dist/esm/utils/validate-in-out-frame.d.ts +6 -0
- package/dist/esm/utils/validate-initial-frame.d.ts +4 -0
- package/dist/esm/utils/validate-playbackrate.d.ts +1 -0
- package/dist/esm/volume-persistance.d.ts +2 -0
- package/dist/tsconfig-esm.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +80 -66
- package/dist/Player.d.ts +0 -49
- package/dist/PlayerControls.js +0 -137
- package/dist/calculate-scale.d.ts +0 -20
- package/dist/calculate-scale.js +0 -33
- package/dist/emitter-context.d.ts +0 -3
- package/dist/event-emitter.d.ts +0 -52
- package/dist/index.js +0 -23
- package/dist/test/index.test.js +0 -8
- package/dist/test/validate-prop.test.js +0 -130
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Controls = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const remotion_1 = require("remotion");
|
|
7
|
+
const format_time_js_1 = require("./format-time.js");
|
|
8
|
+
const icons_js_1 = require("./icons.js");
|
|
9
|
+
const MediaVolumeSlider_js_1 = require("./MediaVolumeSlider.js");
|
|
10
|
+
const PlaybackrateControl_js_1 = require("./PlaybackrateControl.js");
|
|
11
|
+
const PlayerSeekBar_js_1 = require("./PlayerSeekBar.js");
|
|
12
|
+
const use_video_controls_resize_js_1 = require("./use-video-controls-resize.js");
|
|
13
|
+
const gradientSteps = [
|
|
14
|
+
0, 0.013, 0.049, 0.104, 0.175, 0.259, 0.352, 0.45, 0.55, 0.648, 0.741, 0.825,
|
|
15
|
+
0.896, 0.951, 0.987,
|
|
16
|
+
];
|
|
17
|
+
const gradientOpacities = [
|
|
18
|
+
0, 8.1, 15.5, 22.5, 29, 35.3, 41.2, 47.1, 52.9, 58.8, 64.7, 71, 77.5, 84.5,
|
|
19
|
+
91.9,
|
|
20
|
+
];
|
|
21
|
+
const globalGradientOpacity = 1 / 0.7;
|
|
22
|
+
const containerStyle = {
|
|
23
|
+
boxSizing: 'border-box',
|
|
24
|
+
position: 'absolute',
|
|
25
|
+
bottom: 0,
|
|
26
|
+
width: '100%',
|
|
27
|
+
paddingTop: 40,
|
|
28
|
+
paddingBottom: 10,
|
|
29
|
+
backgroundImage: `linear-gradient(to bottom,${gradientSteps
|
|
30
|
+
.map((g, i) => {
|
|
31
|
+
return `hsla(0, 0%, 0%, ${g}) ${gradientOpacities[i] * globalGradientOpacity}%`;
|
|
32
|
+
})
|
|
33
|
+
.join(', ')}, hsl(0, 0%, 0%) 100%)`,
|
|
34
|
+
backgroundSize: 'auto 145px',
|
|
35
|
+
display: 'flex',
|
|
36
|
+
paddingRight: use_video_controls_resize_js_1.X_PADDING,
|
|
37
|
+
paddingLeft: use_video_controls_resize_js_1.X_PADDING,
|
|
38
|
+
flexDirection: 'column',
|
|
39
|
+
transition: 'opacity 0.3s',
|
|
40
|
+
};
|
|
41
|
+
const controlsRow = {
|
|
42
|
+
display: 'flex',
|
|
43
|
+
flexDirection: 'row',
|
|
44
|
+
width: '100%',
|
|
45
|
+
alignItems: 'center',
|
|
46
|
+
justifyContent: 'center',
|
|
47
|
+
userSelect: 'none',
|
|
48
|
+
};
|
|
49
|
+
const leftPartStyle = {
|
|
50
|
+
display: 'flex',
|
|
51
|
+
flexDirection: 'row',
|
|
52
|
+
userSelect: 'none',
|
|
53
|
+
alignItems: 'center',
|
|
54
|
+
};
|
|
55
|
+
const xSpacer = {
|
|
56
|
+
width: 12,
|
|
57
|
+
};
|
|
58
|
+
const ySpacer = {
|
|
59
|
+
height: 8,
|
|
60
|
+
};
|
|
61
|
+
const flex1 = {
|
|
62
|
+
flex: 1,
|
|
63
|
+
};
|
|
64
|
+
const fullscreen = {};
|
|
65
|
+
const PlayPauseButton = ({ playing }) => playing ? (0, jsx_runtime_1.jsx)(icons_js_1.PauseIcon, {}) : (0, jsx_runtime_1.jsx)(icons_js_1.PlayIcon, {});
|
|
66
|
+
const Controls = ({ durationInFrames, hovered, isFullscreen, fps, player, showVolumeControls, onFullscreenButtonClick, allowFullscreen, onExitFullscreenButtonClick, spaceKeyToPlayOrPause, onSeekEnd, onSeekStart, inFrame, outFrame, initiallyShowControls, canvasSize, renderPlayPauseButton, renderFullscreenButton, alwaysShowControls, showPlaybackRateControl, }) => {
|
|
67
|
+
var _a;
|
|
68
|
+
const playButtonRef = (0, react_1.useRef)(null);
|
|
69
|
+
const frame = remotion_1.Internals.Timeline.useTimelinePosition();
|
|
70
|
+
const [supportsFullscreen, setSupportsFullscreen] = (0, react_1.useState)(false);
|
|
71
|
+
const { maxTimeLabelWidth, displayVerticalVolumeSlider } = (0, use_video_controls_resize_js_1.useVideoControlsResize)({
|
|
72
|
+
allowFullscreen,
|
|
73
|
+
playerWidth: (_a = canvasSize === null || canvasSize === void 0 ? void 0 : canvasSize.width) !== null && _a !== void 0 ? _a : 0,
|
|
74
|
+
});
|
|
75
|
+
const [shouldShowInitially, setInitiallyShowControls] = (0, react_1.useState)(() => {
|
|
76
|
+
if (typeof initiallyShowControls === 'boolean') {
|
|
77
|
+
return initiallyShowControls;
|
|
78
|
+
}
|
|
79
|
+
if (typeof initiallyShowControls === 'number') {
|
|
80
|
+
if (initiallyShowControls % 1 !== 0) {
|
|
81
|
+
throw new Error('initiallyShowControls must be an integer or a boolean');
|
|
82
|
+
}
|
|
83
|
+
if (Number.isNaN(initiallyShowControls)) {
|
|
84
|
+
throw new Error('initiallyShowControls must not be NaN');
|
|
85
|
+
}
|
|
86
|
+
if (!Number.isFinite(initiallyShowControls)) {
|
|
87
|
+
throw new Error('initiallyShowControls must be finite');
|
|
88
|
+
}
|
|
89
|
+
if (initiallyShowControls <= 0) {
|
|
90
|
+
throw new Error('initiallyShowControls must be a positive integer');
|
|
91
|
+
}
|
|
92
|
+
return initiallyShowControls;
|
|
93
|
+
}
|
|
94
|
+
throw new TypeError('initiallyShowControls must be a number or a boolean');
|
|
95
|
+
});
|
|
96
|
+
const containerCss = (0, react_1.useMemo)(() => {
|
|
97
|
+
// Hide if playing and mouse outside
|
|
98
|
+
const shouldShow = hovered || !player.playing || shouldShowInitially || alwaysShowControls;
|
|
99
|
+
return {
|
|
100
|
+
...containerStyle,
|
|
101
|
+
opacity: Number(shouldShow),
|
|
102
|
+
};
|
|
103
|
+
}, [hovered, shouldShowInitially, player.playing, alwaysShowControls]);
|
|
104
|
+
(0, react_1.useEffect)(() => {
|
|
105
|
+
if (playButtonRef.current && spaceKeyToPlayOrPause) {
|
|
106
|
+
// This switches focus to play button when player.playing flag changes
|
|
107
|
+
playButtonRef.current.focus({
|
|
108
|
+
preventScroll: true,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}, [player.playing, spaceKeyToPlayOrPause]);
|
|
112
|
+
(0, react_1.useEffect)(() => {
|
|
113
|
+
var _a;
|
|
114
|
+
// Must be handled client-side to avoid SSR hydration mismatch
|
|
115
|
+
setSupportsFullscreen((_a = (typeof document !== 'undefined' &&
|
|
116
|
+
(document.fullscreenEnabled || document.webkitFullscreenEnabled))) !== null && _a !== void 0 ? _a : false);
|
|
117
|
+
}, []);
|
|
118
|
+
(0, react_1.useEffect)(() => {
|
|
119
|
+
if (shouldShowInitially === false) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const time = shouldShowInitially === true ? 2000 : shouldShowInitially;
|
|
123
|
+
const timeout = setTimeout(() => {
|
|
124
|
+
setInitiallyShowControls(false);
|
|
125
|
+
}, time);
|
|
126
|
+
return () => {
|
|
127
|
+
clearInterval(timeout);
|
|
128
|
+
};
|
|
129
|
+
}, [shouldShowInitially]);
|
|
130
|
+
const timeLabel = (0, react_1.useMemo)(() => {
|
|
131
|
+
return {
|
|
132
|
+
color: 'white',
|
|
133
|
+
fontFamily: 'sans-serif',
|
|
134
|
+
fontSize: 14,
|
|
135
|
+
maxWidth: maxTimeLabelWidth === null ? undefined : maxTimeLabelWidth,
|
|
136
|
+
overflow: 'hidden',
|
|
137
|
+
textOverflow: 'ellipsis',
|
|
138
|
+
};
|
|
139
|
+
}, [maxTimeLabelWidth]);
|
|
140
|
+
const playbackRates = (0, react_1.useMemo)(() => {
|
|
141
|
+
if (showPlaybackRateControl === true) {
|
|
142
|
+
return [0.5, 0.8, 1, 1.2, 1.5, 1.8, 2, 2.5, 3];
|
|
143
|
+
}
|
|
144
|
+
if (Array.isArray(showPlaybackRateControl)) {
|
|
145
|
+
for (const rate of showPlaybackRateControl) {
|
|
146
|
+
if (typeof rate !== 'number') {
|
|
147
|
+
throw new Error('Every item in showPlaybackRateControl must be a number');
|
|
148
|
+
}
|
|
149
|
+
if (rate <= 0) {
|
|
150
|
+
throw new Error('Every item in showPlaybackRateControl must be positive');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return showPlaybackRateControl;
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}, [showPlaybackRateControl]);
|
|
157
|
+
return ((0, jsx_runtime_1.jsxs)("div", { style: containerCss, children: [(0, jsx_runtime_1.jsxs)("div", { style: controlsRow, children: [(0, jsx_runtime_1.jsxs)("div", { style: leftPartStyle, children: [(0, jsx_runtime_1.jsx)("button", { ref: playButtonRef, type: "button", style: PlaybackrateControl_js_1.playerButtonStyle, onClick: player.playing ? player.pause : player.play, "aria-label": player.playing ? 'Pause video' : 'Play video', title: player.playing ? 'Pause video' : 'Play video', children: renderPlayPauseButton === null ? ((0, jsx_runtime_1.jsx)(PlayPauseButton, { playing: player.playing })) : (renderPlayPauseButton({ playing: player.playing })) }), showVolumeControls ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { style: xSpacer }), (0, jsx_runtime_1.jsx)(MediaVolumeSlider_js_1.MediaVolumeSlider, { displayVerticalVolumeSlider: displayVerticalVolumeSlider })] })) : null, (0, jsx_runtime_1.jsx)("div", { style: xSpacer }), (0, jsx_runtime_1.jsxs)("div", { style: timeLabel, children: [(0, format_time_js_1.formatTime)(frame / fps), " / ", (0, format_time_js_1.formatTime)(durationInFrames / fps)] }), (0, jsx_runtime_1.jsx)("div", { style: xSpacer })] }), (0, jsx_runtime_1.jsx)("div", { style: flex1 }), playbackRates && canvasSize && ((0, jsx_runtime_1.jsx)(PlaybackrateControl_js_1.PlaybackrateControl, { canvasSize: canvasSize, playbackRates: playbackRates })), playbackRates && supportsFullscreen && allowFullscreen ? ((0, jsx_runtime_1.jsx)("div", { style: xSpacer })) : null, (0, jsx_runtime_1.jsx)("div", { style: fullscreen, children: supportsFullscreen && allowFullscreen ? ((0, jsx_runtime_1.jsx)("button", { type: "button", "aria-label": isFullscreen ? 'Exit fullscreen' : 'Enter Fullscreen', title: isFullscreen ? 'Exit fullscreen' : 'Enter Fullscreen', style: PlaybackrateControl_js_1.playerButtonStyle, onClick: isFullscreen
|
|
158
|
+
? onExitFullscreenButtonClick
|
|
159
|
+
: onFullscreenButtonClick, children: renderFullscreenButton === null ? ((0, jsx_runtime_1.jsx)(icons_js_1.FullscreenIcon, { isFullscreen: isFullscreen })) : (renderFullscreenButton({ isFullscreen })) })) : null })] }), (0, jsx_runtime_1.jsx)("div", { style: ySpacer }), (0, jsx_runtime_1.jsx)(PlayerSeekBar_js_1.PlayerSeekBar, { onSeekEnd: onSeekEnd, onSeekStart: onSeekStart, durationInFrames: durationInFrames, inFrame: inFrame, outFrame: outFrame })] }));
|
|
160
|
+
};
|
|
161
|
+
exports.Controls = Controls;
|
|
File without changes
|
|
@@ -4,9 +4,9 @@ exports.PlayerSeekBar = void 0;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const remotion_1 = require("remotion");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
7
|
+
const use_hover_state_js_1 = require("./use-hover-state.js");
|
|
8
|
+
const use_player_js_1 = require("./use-player.js");
|
|
9
|
+
const use_element_size_js_1 = require("./utils/use-element-size.js");
|
|
10
10
|
const getFrameFromX = (clientX, durationInFrames, width) => {
|
|
11
11
|
var _a;
|
|
12
12
|
const pos = clientX;
|
|
@@ -43,12 +43,12 @@ const findBodyInWhichDivIsLocated = (div) => {
|
|
|
43
43
|
};
|
|
44
44
|
const PlayerSeekBar = ({ durationInFrames, onSeekEnd, onSeekStart, inFrame, outFrame }) => {
|
|
45
45
|
const containerRef = (0, react_1.useRef)(null);
|
|
46
|
-
const barHovered = (0,
|
|
47
|
-
const size = (0,
|
|
46
|
+
const barHovered = (0, use_hover_state_js_1.useHoverState)(containerRef);
|
|
47
|
+
const size = (0, use_element_size_js_1.useElementSize)(containerRef, {
|
|
48
48
|
triggerOnWindowResize: true,
|
|
49
49
|
shouldApplyCssTransforms: true,
|
|
50
50
|
});
|
|
51
|
-
const { seek, play, pause, playing } = (0,
|
|
51
|
+
const { seek, play, pause, playing } = (0, use_player_js_1.usePlayer)();
|
|
52
52
|
const frame = remotion_1.Internals.Timeline.useTimelinePosition();
|
|
53
53
|
const [dragging, setDragging] = (0, react_1.useState)({
|
|
54
54
|
dragging: false,
|
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { PlayerRef } from './player-methods';
|
|
3
|
-
|
|
2
|
+
import type { PlayerRef } from './player-methods.js';
|
|
3
|
+
import type { RenderFullscreenButton, RenderPlayPauseButton } from './PlayerControls.js';
|
|
4
|
+
export type ErrorFallback = (info: {
|
|
4
5
|
error: Error;
|
|
5
6
|
}) => React.ReactNode;
|
|
6
|
-
export
|
|
7
|
+
export type RenderLoading = (canvas: {
|
|
7
8
|
height: number;
|
|
8
9
|
width: number;
|
|
9
|
-
}) => React.
|
|
10
|
-
export
|
|
11
|
-
declare const _default:
|
|
10
|
+
}) => React.ReactNode;
|
|
11
|
+
export type RenderPoster = RenderLoading;
|
|
12
|
+
declare const _default: React.ForwardRefExoticComponent<{
|
|
12
13
|
controls: boolean;
|
|
13
14
|
loop: boolean;
|
|
14
15
|
autoPlay: boolean;
|
|
15
16
|
allowFullscreen: boolean;
|
|
16
|
-
inputProps: unknown
|
|
17
|
+
inputProps: Record<string, unknown>;
|
|
17
18
|
showVolumeControls: boolean;
|
|
18
|
-
mediaMuted: boolean;
|
|
19
19
|
style?: React.CSSProperties | undefined;
|
|
20
20
|
clickToPlay: boolean;
|
|
21
21
|
doubleClickToFullscreen: boolean;
|
|
22
22
|
spaceKeyToPlayOrPause: boolean;
|
|
23
|
-
setMediaVolume: (v: number) => void;
|
|
24
|
-
setMediaMuted: (v: boolean) => void;
|
|
25
|
-
mediaVolume: number;
|
|
26
23
|
errorFallback: ErrorFallback;
|
|
27
24
|
playbackRate: number;
|
|
28
25
|
renderLoading: RenderLoading | undefined;
|
|
@@ -35,5 +32,9 @@ declare const _default: (props: {
|
|
|
35
32
|
inFrame: number | null;
|
|
36
33
|
outFrame: number | null;
|
|
37
34
|
initiallyShowControls: number | boolean;
|
|
38
|
-
|
|
35
|
+
renderPlayPauseButton: RenderPlayPauseButton | null;
|
|
36
|
+
renderFullscreen: RenderFullscreenButton | null;
|
|
37
|
+
alwaysShowControls: boolean;
|
|
38
|
+
showPlaybackRateControl: boolean | number[];
|
|
39
|
+
} & React.RefAttributes<PlayerRef>>;
|
|
39
40
|
export default _default;
|
|
@@ -26,29 +26,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
27
27
|
const react_1 = __importStar(require("react"));
|
|
28
28
|
const remotion_1 = require("remotion");
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const use_element_size_1 = require("./utils/use-element-size");
|
|
29
|
+
const calculate_scale_js_1 = require("./calculate-scale.js");
|
|
30
|
+
const error_boundary_js_1 = require("./error-boundary.js");
|
|
31
|
+
const player_css_classname_js_1 = require("./player-css-classname.js");
|
|
32
|
+
const PlayerControls_js_1 = require("./PlayerControls.js");
|
|
33
|
+
const use_hover_state_js_1 = require("./use-hover-state.js");
|
|
34
|
+
const use_playback_js_1 = require("./use-playback.js");
|
|
35
|
+
const use_player_js_1 = require("./use-player.js");
|
|
36
|
+
const is_node_js_1 = require("./utils/is-node.js");
|
|
37
|
+
const use_click_prevention_on_double_click_js_1 = require("./utils/use-click-prevention-on-double-click.js");
|
|
38
|
+
const use_element_size_js_1 = require("./utils/use-element-size.js");
|
|
40
39
|
const reactVersion = react_1.default.version.split('.')[0];
|
|
41
40
|
if (reactVersion === '0') {
|
|
42
41
|
throw new Error(`Version ${reactVersion} of "react" is not supported by Remotion`);
|
|
43
42
|
}
|
|
44
43
|
const doesReactVersionSupportSuspense = parseInt(reactVersion, 10) >= 18;
|
|
45
|
-
const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps, clickToPlay, showVolumeControls,
|
|
46
|
-
var _a, _b, _c
|
|
44
|
+
const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps, clickToPlay, showVolumeControls, doubleClickToFullscreen, spaceKeyToPlayOrPause, errorFallback, playbackRate, renderLoading, renderPoster, className, moveToBeginningWhenEnded, showPosterWhenUnplayed, showPosterWhenEnded, showPosterWhenPaused, inFrame, outFrame, initiallyShowControls, renderFullscreen: renderFullscreenButton, renderPlayPauseButton, alwaysShowControls, showPlaybackRateControl, }, ref) => {
|
|
45
|
+
var _a, _b, _c;
|
|
47
46
|
const config = remotion_1.Internals.useUnsafeVideoConfig();
|
|
48
47
|
const video = remotion_1.Internals.useVideo();
|
|
49
48
|
const container = (0, react_1.useRef)(null);
|
|
50
|
-
const hovered = (0,
|
|
51
|
-
const canvasSize = (0,
|
|
49
|
+
const hovered = (0, use_hover_state_js_1.useHoverState)(container);
|
|
50
|
+
const canvasSize = (0, use_element_size_js_1.useElementSize)(container, {
|
|
52
51
|
triggerOnWindowResize: false,
|
|
53
52
|
shouldApplyCssTransforms: false,
|
|
54
53
|
});
|
|
@@ -56,14 +55,14 @@ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps
|
|
|
56
55
|
const [shouldAutoplay, setShouldAutoPlay] = (0, react_1.useState)(autoPlay);
|
|
57
56
|
const [isFullscreen, setIsFullscreen] = (0, react_1.useState)(() => false);
|
|
58
57
|
const [seeking, setSeeking] = (0, react_1.useState)(false);
|
|
59
|
-
(0,
|
|
58
|
+
(0, use_playback_js_1.usePlayback)({
|
|
60
59
|
loop,
|
|
61
60
|
playbackRate,
|
|
62
61
|
moveToBeginningWhenEnded,
|
|
63
62
|
inFrame,
|
|
64
63
|
outFrame,
|
|
65
64
|
});
|
|
66
|
-
const player = (0,
|
|
65
|
+
const player = (0, use_player_js_1.usePlayer)();
|
|
67
66
|
(0, react_1.useEffect)(() => {
|
|
68
67
|
if (hasPausedToResume && !player.playing) {
|
|
69
68
|
setHasPausedToResume(false);
|
|
@@ -129,12 +128,12 @@ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps
|
|
|
129
128
|
var _a;
|
|
130
129
|
const element = (_a = document.webkitFullscreenElement) !== null && _a !== void 0 ? _a : document.fullscreenElement;
|
|
131
130
|
if (element && element === container.current) {
|
|
132
|
-
player.emitter.
|
|
131
|
+
player.emitter.dispatchFullscreenChange({
|
|
133
132
|
isFullscreen: true,
|
|
134
133
|
});
|
|
135
134
|
}
|
|
136
135
|
else {
|
|
137
|
-
player.emitter.
|
|
136
|
+
player.emitter.dispatchFullscreenChange({
|
|
138
137
|
isFullscreen: false,
|
|
139
138
|
});
|
|
140
139
|
}
|
|
@@ -151,7 +150,7 @@ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps
|
|
|
151
150
|
if (!config || !canvasSize) {
|
|
152
151
|
return null;
|
|
153
152
|
}
|
|
154
|
-
return (0,
|
|
153
|
+
return (0, calculate_scale_js_1.calculateCanvasTransformation)({
|
|
155
154
|
canvasSize,
|
|
156
155
|
compositionHeight: config.height,
|
|
157
156
|
compositionWidth: config.width,
|
|
@@ -159,6 +158,25 @@ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps
|
|
|
159
158
|
});
|
|
160
159
|
}, [canvasSize, config]);
|
|
161
160
|
const scale = (_b = layout === null || layout === void 0 ? void 0 : layout.scale) !== null && _b !== void 0 ? _b : 1;
|
|
161
|
+
const initialScaleIgnored = (0, react_1.useRef)(false);
|
|
162
|
+
(0, react_1.useEffect)(() => {
|
|
163
|
+
if (!initialScaleIgnored.current) {
|
|
164
|
+
initialScaleIgnored.current = true;
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
player.emitter.dispatchScaleChange(scale);
|
|
168
|
+
}, [player.emitter, scale]);
|
|
169
|
+
const { setMediaVolume, setMediaMuted } = (0, react_1.useContext)(remotion_1.Internals.SetMediaVolumeContext);
|
|
170
|
+
const { mediaMuted, mediaVolume } = (0, react_1.useContext)(remotion_1.Internals.MediaVolumeContext);
|
|
171
|
+
(0, react_1.useEffect)(() => {
|
|
172
|
+
player.emitter.dispatchVolumeChange(mediaVolume);
|
|
173
|
+
}, [player.emitter, mediaVolume]);
|
|
174
|
+
const isMuted = mediaMuted || mediaVolume === 0;
|
|
175
|
+
(0, react_1.useEffect)(() => {
|
|
176
|
+
player.emitter.dispatchMuteChange({
|
|
177
|
+
isMuted,
|
|
178
|
+
});
|
|
179
|
+
}, [player.emitter, isMuted]);
|
|
162
180
|
(0, react_1.useImperativeHandle)(ref, () => {
|
|
163
181
|
const methods = {
|
|
164
182
|
play: player.play,
|
|
@@ -201,7 +219,7 @@ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps
|
|
|
201
219
|
}
|
|
202
220
|
setMediaVolume(vol);
|
|
203
221
|
},
|
|
204
|
-
isMuted: () =>
|
|
222
|
+
isMuted: () => isMuted,
|
|
205
223
|
mute: () => {
|
|
206
224
|
setMediaMuted(true);
|
|
207
225
|
},
|
|
@@ -217,6 +235,7 @@ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps
|
|
|
217
235
|
isFullscreen,
|
|
218
236
|
loop,
|
|
219
237
|
mediaMuted,
|
|
238
|
+
isMuted,
|
|
220
239
|
mediaVolume,
|
|
221
240
|
player,
|
|
222
241
|
requestFullscreen,
|
|
@@ -227,52 +246,13 @@ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps
|
|
|
227
246
|
]);
|
|
228
247
|
const VideoComponent = video ? video.component : null;
|
|
229
248
|
const outerStyle = (0, react_1.useMemo)(() => {
|
|
230
|
-
|
|
231
|
-
return {};
|
|
232
|
-
}
|
|
233
|
-
return {
|
|
234
|
-
position: 'relative',
|
|
235
|
-
overflow: 'hidden',
|
|
236
|
-
...(0, calculate_player_size_1.calculatePlayerSize)({
|
|
237
|
-
compositionHeight: config.height,
|
|
238
|
-
compositionWidth: config.width,
|
|
239
|
-
currentSize: canvasSize,
|
|
240
|
-
height: style === null || style === void 0 ? void 0 : style.height,
|
|
241
|
-
width: style === null || style === void 0 ? void 0 : style.width,
|
|
242
|
-
}),
|
|
243
|
-
...style,
|
|
244
|
-
};
|
|
249
|
+
return (0, calculate_scale_js_1.calculateOuterStyle)({ canvasSize, config, style });
|
|
245
250
|
}, [canvasSize, config, style]);
|
|
246
251
|
const outer = (0, react_1.useMemo)(() => {
|
|
247
|
-
|
|
248
|
-
return {};
|
|
249
|
-
}
|
|
250
|
-
const { centerX, centerY } = layout;
|
|
251
|
-
return {
|
|
252
|
-
width: config.width * scale,
|
|
253
|
-
height: config.height * scale,
|
|
254
|
-
display: 'flex',
|
|
255
|
-
flexDirection: 'column',
|
|
256
|
-
position: 'absolute',
|
|
257
|
-
left: centerX,
|
|
258
|
-
top: centerY,
|
|
259
|
-
overflow: 'hidden',
|
|
260
|
-
};
|
|
252
|
+
return (0, calculate_scale_js_1.calculateOuter)({ config, layout, scale });
|
|
261
253
|
}, [config, layout, scale]);
|
|
262
254
|
const containerStyle = (0, react_1.useMemo)(() => {
|
|
263
|
-
|
|
264
|
-
return {};
|
|
265
|
-
}
|
|
266
|
-
return {
|
|
267
|
-
position: 'absolute',
|
|
268
|
-
width: config.width,
|
|
269
|
-
height: config.height,
|
|
270
|
-
display: 'flex',
|
|
271
|
-
transform: `scale(${scale})`,
|
|
272
|
-
marginLeft: layout.xCorrection,
|
|
273
|
-
marginTop: layout.yCorrection,
|
|
274
|
-
overflow: 'hidden',
|
|
275
|
-
};
|
|
255
|
+
return (0, calculate_scale_js_1.calculateContainerStyle)({ canvasSize, config, layout, scale });
|
|
276
256
|
}, [canvasSize, config, layout, scale]);
|
|
277
257
|
const onError = (0, react_1.useCallback)((error) => {
|
|
278
258
|
player.pause();
|
|
@@ -304,13 +284,21 @@ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps
|
|
|
304
284
|
requestFullscreen();
|
|
305
285
|
}
|
|
306
286
|
}, [exitFullscreen, isFullscreen, requestFullscreen]);
|
|
307
|
-
const [handleClick, handleDoubleClick] = (0,
|
|
287
|
+
const [handleClick, handleDoubleClick] = (0, use_click_prevention_on_double_click_js_1.useClickPreventionOnDoubleClick)(onSingleClick, onDoubleClick, doubleClickToFullscreen);
|
|
308
288
|
(0, react_1.useEffect)(() => {
|
|
309
289
|
if (shouldAutoplay) {
|
|
310
290
|
player.play();
|
|
311
291
|
setShouldAutoPlay(false);
|
|
312
292
|
}
|
|
313
293
|
}, [shouldAutoplay, player]);
|
|
294
|
+
const loadingMarkup = (0, react_1.useMemo)(() => {
|
|
295
|
+
return renderLoading
|
|
296
|
+
? renderLoading({
|
|
297
|
+
height: outerStyle.height,
|
|
298
|
+
width: outerStyle.width,
|
|
299
|
+
})
|
|
300
|
+
: null;
|
|
301
|
+
}, [outerStyle.height, outerStyle.width, renderLoading]);
|
|
314
302
|
if (!config) {
|
|
315
303
|
return null;
|
|
316
304
|
}
|
|
@@ -329,16 +317,10 @@ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps
|
|
|
329
317
|
showPosterWhenEnded && player.isLastFrame && !player.isPlaying(),
|
|
330
318
|
showPosterWhenUnplayed && !player.hasPlayed && !player.isPlaying(),
|
|
331
319
|
].some(Boolean);
|
|
332
|
-
const content = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { style: outer, onClick: clickToPlay ? handleClick : undefined, onDoubleClick: doubleClickToFullscreen ? handleDoubleClick : undefined, children: (0, jsx_runtime_1.jsx)("div", { style: containerStyle, className:
|
|
333
|
-
if (
|
|
320
|
+
const content = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { style: outer, onClick: clickToPlay ? handleClick : undefined, onDoubleClick: doubleClickToFullscreen ? handleDoubleClick : undefined, children: (0, jsx_runtime_1.jsx)("div", { style: containerStyle, className: player_css_classname_js_1.PLAYER_CSS_CLASSNAME, children: VideoComponent ? ((0, jsx_runtime_1.jsx)(error_boundary_js_1.ErrorBoundary, { onError: onError, errorFallback: errorFallback, children: (0, jsx_runtime_1.jsx)(VideoComponent, { ...((_c = video === null || video === void 0 ? void 0 : video.defaultProps) !== null && _c !== void 0 ? _c : {}), ...(inputProps !== null && inputProps !== void 0 ? inputProps : {}) }) })) : null }) }), shouldShowPoster ? ((0, jsx_runtime_1.jsx)("div", { style: outer, onClick: clickToPlay ? handleClick : undefined, onDoubleClick: doubleClickToFullscreen ? handleDoubleClick : undefined, children: poster })) : null, controls ? ((0, jsx_runtime_1.jsx)(PlayerControls_js_1.Controls, { fps: config.fps, durationInFrames: config.durationInFrames, hovered: hovered, player: player, onFullscreenButtonClick: onFullscreenButtonClick, isFullscreen: isFullscreen, allowFullscreen: allowFullscreen, showVolumeControls: showVolumeControls, onExitFullscreenButtonClick: onExitFullscreenButtonClick, spaceKeyToPlayOrPause: spaceKeyToPlayOrPause, onSeekEnd: onSeekEnd, onSeekStart: onSeekStart, inFrame: inFrame, outFrame: outFrame, initiallyShowControls: initiallyShowControls, canvasSize: canvasSize, renderFullscreenButton: renderFullscreenButton, renderPlayPauseButton: renderPlayPauseButton, alwaysShowControls: alwaysShowControls, showPlaybackRateControl: showPlaybackRateControl })) : null] }));
|
|
321
|
+
if (is_node_js_1.IS_NODE && !doesReactVersionSupportSuspense) {
|
|
334
322
|
return ((0, jsx_runtime_1.jsx)("div", { ref: container, style: outerStyle, className: className, children: content }));
|
|
335
323
|
}
|
|
336
|
-
const loadingMarkup = renderLoading
|
|
337
|
-
? renderLoading({
|
|
338
|
-
height: outerStyle.height,
|
|
339
|
-
width: outerStyle.width,
|
|
340
|
-
})
|
|
341
|
-
: null;
|
|
342
324
|
return ((0, jsx_runtime_1.jsx)("div", { ref: container, style: outerStyle, className: className, children: (0, jsx_runtime_1.jsx)(react_1.Suspense, { fallback: loadingMarkup, children: content }) }));
|
|
343
325
|
};
|
|
344
326
|
exports.default = (0, react_1.forwardRef)(PlayerUI);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ComponentType, LazyExoticComponent } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { TimelineContextValue } from 'remotion';
|
|
4
|
+
export declare const SharedPlayerContexts: React.FC<{
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
timelineContext: TimelineContextValue;
|
|
7
|
+
inputProps?: Record<string, unknown>;
|
|
8
|
+
fps: number;
|
|
9
|
+
compositionWidth: number;
|
|
10
|
+
compositionHeight: number;
|
|
11
|
+
durationInFrames: number;
|
|
12
|
+
component: LazyExoticComponent<ComponentType<unknown>>;
|
|
13
|
+
numberOfSharedAudioTags: number;
|
|
14
|
+
initiallyMuted: boolean;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SharedPlayerContexts = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const remotion_1 = require("remotion");
|
|
7
|
+
const volume_persistance_js_1 = require("./volume-persistance.js");
|
|
8
|
+
const SharedPlayerContexts = ({ children, timelineContext, inputProps, fps, compositionHeight, compositionWidth, durationInFrames, component, numberOfSharedAudioTags, initiallyMuted, }) => {
|
|
9
|
+
const compositionManagerContext = (0, react_1.useMemo)(() => {
|
|
10
|
+
return {
|
|
11
|
+
compositions: [
|
|
12
|
+
{
|
|
13
|
+
component: component,
|
|
14
|
+
durationInFrames,
|
|
15
|
+
height: compositionHeight,
|
|
16
|
+
width: compositionWidth,
|
|
17
|
+
fps,
|
|
18
|
+
id: 'player-comp',
|
|
19
|
+
props: inputProps,
|
|
20
|
+
nonce: 777,
|
|
21
|
+
scale: 1,
|
|
22
|
+
folderName: null,
|
|
23
|
+
defaultProps: undefined,
|
|
24
|
+
parentFolderName: null,
|
|
25
|
+
schema: null,
|
|
26
|
+
calculateMetadata: null,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
folders: [],
|
|
30
|
+
registerFolder: () => undefined,
|
|
31
|
+
unregisterFolder: () => undefined,
|
|
32
|
+
currentComposition: 'player-comp',
|
|
33
|
+
registerComposition: () => undefined,
|
|
34
|
+
registerSequence: () => undefined,
|
|
35
|
+
sequences: [],
|
|
36
|
+
setCurrentComposition: () => undefined,
|
|
37
|
+
unregisterComposition: () => undefined,
|
|
38
|
+
unregisterSequence: () => undefined,
|
|
39
|
+
registerAsset: () => undefined,
|
|
40
|
+
unregisterAsset: () => undefined,
|
|
41
|
+
currentCompositionMetadata: null,
|
|
42
|
+
setCurrentCompositionMetadata: () => undefined,
|
|
43
|
+
assets: [],
|
|
44
|
+
setClipRegion: () => undefined,
|
|
45
|
+
resolved: null,
|
|
46
|
+
};
|
|
47
|
+
}, [
|
|
48
|
+
component,
|
|
49
|
+
durationInFrames,
|
|
50
|
+
compositionHeight,
|
|
51
|
+
compositionWidth,
|
|
52
|
+
fps,
|
|
53
|
+
inputProps,
|
|
54
|
+
]);
|
|
55
|
+
const [mediaMuted, setMediaMuted] = (0, react_1.useState)(() => initiallyMuted);
|
|
56
|
+
const [mediaVolume, setMediaVolume] = (0, react_1.useState)(() => (0, volume_persistance_js_1.getPreferredVolume)());
|
|
57
|
+
const mediaVolumeContextValue = (0, react_1.useMemo)(() => {
|
|
58
|
+
return {
|
|
59
|
+
mediaMuted,
|
|
60
|
+
mediaVolume,
|
|
61
|
+
};
|
|
62
|
+
}, [mediaMuted, mediaVolume]);
|
|
63
|
+
const setMediaVolumeAndPersist = (0, react_1.useCallback)((vol) => {
|
|
64
|
+
setMediaVolume(vol);
|
|
65
|
+
(0, volume_persistance_js_1.persistVolume)(vol);
|
|
66
|
+
}, []);
|
|
67
|
+
const setMediaVolumeContextValue = (0, react_1.useMemo)(() => {
|
|
68
|
+
return {
|
|
69
|
+
setMediaMuted,
|
|
70
|
+
setMediaVolume: setMediaVolumeAndPersist,
|
|
71
|
+
};
|
|
72
|
+
}, [setMediaVolumeAndPersist]);
|
|
73
|
+
return ((0, jsx_runtime_1.jsx)(remotion_1.Internals.CanUseRemotionHooksProvider, { children: (0, jsx_runtime_1.jsx)(remotion_1.Internals.Timeline.TimelineContext.Provider, { value: timelineContext, children: (0, jsx_runtime_1.jsx)(remotion_1.Internals.CompositionManager.Provider, { value: compositionManagerContext, children: (0, jsx_runtime_1.jsx)(remotion_1.Internals.ResolveCompositionConfig, { children: (0, jsx_runtime_1.jsx)(remotion_1.Internals.PrefetchProvider, { children: (0, jsx_runtime_1.jsx)(remotion_1.Internals.DurationsContextProvider, { children: (0, jsx_runtime_1.jsx)(remotion_1.Internals.MediaVolumeContext.Provider, { value: mediaVolumeContextValue, children: (0, jsx_runtime_1.jsx)(remotion_1.Internals.SetMediaVolumeContext.Provider, { value: setMediaVolumeContextValue, children: (0, jsx_runtime_1.jsx)(remotion_1.Internals.SharedAudioContextProvider, { numberOfAudioTags: numberOfSharedAudioTags, component: component, children: children }) }) }) }) }) }) }) }) }));
|
|
74
|
+
};
|
|
75
|
+
exports.SharedPlayerContexts = SharedPlayerContexts;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CSSProperties, MutableRefObject } from 'react';
|
|
2
|
+
import type { CompProps } from 'remotion';
|
|
3
|
+
import type { AnyZodObject } from 'zod';
|
|
4
|
+
import type { ThumbnailMethods } from './player-methods.js';
|
|
5
|
+
import type { ErrorFallback, RenderLoading } from './PlayerUI.js';
|
|
6
|
+
import type { PropsIfHasProps } from './utils/props-if-has-props.js';
|
|
7
|
+
type ThumbnailProps<Schema extends AnyZodObject, Props> = PropsIfHasProps<Schema, Props> & CompProps<Schema> & {
|
|
8
|
+
frameToDisplay: number;
|
|
9
|
+
style?: CSSProperties;
|
|
10
|
+
durationInFrames: number;
|
|
11
|
+
compositionWidth: number;
|
|
12
|
+
compositionHeight: number;
|
|
13
|
+
fps: number;
|
|
14
|
+
errorFallback?: ErrorFallback;
|
|
15
|
+
renderLoading?: RenderLoading;
|
|
16
|
+
className?: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const ThumbnailFn: <Schema extends AnyZodObject, Props>({ frameToDisplay, style, inputProps, compositionHeight, compositionWidth, durationInFrames, fps, className, errorFallback, renderLoading, ...componentProps }: ThumbnailProps<Schema, Props>, ref: MutableRefObject<ThumbnailMethods>) => JSX.Element;
|
|
19
|
+
/**
|
|
20
|
+
* @description A component which can be rendered in a regular React App (for example: Create React App, Next.js) to display a single frame of a video.
|
|
21
|
+
* @see [Documentation](https://www.remotion.dev/docs/player/thumbnail)
|
|
22
|
+
*/
|
|
23
|
+
export declare const Thumbnail: <Schema extends AnyZodObject, Props>(props: ThumbnailProps<Schema, Props> & import("react").RefAttributes<ThumbnailMethods>) => React.ReactElement | null;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
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.Thumbnail = exports.ThumbnailFn = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const remotion_1 = require("remotion");
|
|
10
|
+
const emitter_context_js_1 = require("./emitter-context.js");
|
|
11
|
+
const event_emitter_js_1 = require("./event-emitter.js");
|
|
12
|
+
const SharedPlayerContext_js_1 = require("./SharedPlayerContext.js");
|
|
13
|
+
const ThumbnailUI_js_1 = __importDefault(require("./ThumbnailUI.js"));
|
|
14
|
+
const ThumbnailFn = ({ frameToDisplay, style, inputProps, compositionHeight, compositionWidth, durationInFrames, fps, className, errorFallback = () => '⚠️', renderLoading, ...componentProps }, ref) => {
|
|
15
|
+
const [thumbnailId] = (0, react_1.useState)(() => String((0, remotion_1.random)(null)));
|
|
16
|
+
const rootRef = (0, react_1.useRef)(null);
|
|
17
|
+
const timelineState = (0, react_1.useMemo)(() => {
|
|
18
|
+
return {
|
|
19
|
+
playing: false,
|
|
20
|
+
frame: frameToDisplay,
|
|
21
|
+
rootId: thumbnailId,
|
|
22
|
+
imperativePlaying: {
|
|
23
|
+
current: false,
|
|
24
|
+
},
|
|
25
|
+
playbackRate: 1,
|
|
26
|
+
setPlaybackRate: () => {
|
|
27
|
+
throw new Error('thumbnail');
|
|
28
|
+
},
|
|
29
|
+
audioAndVideoTags: { current: [] },
|
|
30
|
+
};
|
|
31
|
+
}, [frameToDisplay, thumbnailId]);
|
|
32
|
+
(0, react_1.useImperativeHandle)(ref, () => rootRef.current, []);
|
|
33
|
+
const Component = remotion_1.Internals.useLazyComponent(componentProps);
|
|
34
|
+
const [emitter] = (0, react_1.useState)(() => new event_emitter_js_1.ThumbnailEmitter());
|
|
35
|
+
const passedInputProps = (0, react_1.useMemo)(() => {
|
|
36
|
+
return inputProps !== null && inputProps !== void 0 ? inputProps : {};
|
|
37
|
+
}, [inputProps]);
|
|
38
|
+
return ((0, jsx_runtime_1.jsx)(remotion_1.Internals.IsPlayerContextProvider, { children: (0, jsx_runtime_1.jsx)(SharedPlayerContext_js_1.SharedPlayerContexts, { timelineContext: timelineState, component: Component, compositionHeight: compositionHeight, compositionWidth: compositionWidth, durationInFrames: durationInFrames, fps: fps, inputProps: passedInputProps, numberOfSharedAudioTags: 0, initiallyMuted: true, children: (0, jsx_runtime_1.jsx)(emitter_context_js_1.ThumbnailEmitterContext.Provider, { value: emitter, children: (0, jsx_runtime_1.jsx)(ThumbnailUI_js_1.default, { className: className, errorFallback: errorFallback, inputProps: passedInputProps, renderLoading: renderLoading, style: style }) }) }) }));
|
|
39
|
+
};
|
|
40
|
+
exports.ThumbnailFn = ThumbnailFn;
|
|
41
|
+
const forward = react_1.forwardRef;
|
|
42
|
+
/**
|
|
43
|
+
* @description A component which can be rendered in a regular React App (for example: Create React App, Next.js) to display a single frame of a video.
|
|
44
|
+
* @see [Documentation](https://www.remotion.dev/docs/player/thumbnail)
|
|
45
|
+
*/
|
|
46
|
+
exports.Thumbnail = forward(exports.ThumbnailFn);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ThumbnailMethods } from './player-methods.js';
|
|
3
|
+
import type { ErrorFallback, RenderLoading } from './PlayerUI.js';
|
|
4
|
+
declare const _default: React.ForwardRefExoticComponent<{
|
|
5
|
+
inputProps: Record<string, unknown>;
|
|
6
|
+
style?: React.CSSProperties | undefined;
|
|
7
|
+
errorFallback: ErrorFallback;
|
|
8
|
+
renderLoading: RenderLoading | undefined;
|
|
9
|
+
className: string | undefined;
|
|
10
|
+
} & React.RefAttributes<ThumbnailMethods>>;
|
|
11
|
+
export default _default;
|