@remotion/player 3.3.55 → 3.3.56

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.
Files changed (48) hide show
  1. package/dist/esm/calculate-scale.d.ts +1 -1
  2. package/dist/esm/index.d.ts +2 -1
  3. package/dist/esm/test/test-utils.d.ts +2 -2
  4. package/dist/esm/utils/delay.d.ts +1 -1
  5. package/dist/esm/utils/use-cancellable-promises.d.ts +1 -1
  6. package/dist/{tsconfig-cjs.tsbuildinfo → tsconfig-esm.tsbuildinfo} +1 -1
  7. package/dist/tsconfig.tsbuildinfo +1 -1
  8. package/package.json +4 -4
  9. package/dist/esm/MediaVolumeSlider.js +0 -114
  10. package/dist/esm/Player.js +0 -140
  11. package/dist/esm/PlayerControls.js +0 -146
  12. package/dist/esm/PlayerSeekBar.js +0 -142
  13. package/dist/esm/PlayerUI.js +0 -283
  14. package/dist/esm/SharedPlayerContext.js +0 -68
  15. package/dist/esm/Thumbnail.js +0 -39
  16. package/dist/esm/ThumbnailUI.js +0 -82
  17. package/dist/esm/calculate-next-frame.js +0 -24
  18. package/dist/esm/calculate-scale.js +0 -77
  19. package/dist/esm/emitter-context.js +0 -3
  20. package/dist/esm/error-boundary.js +0 -32
  21. package/dist/esm/event-emitter.js +0 -82
  22. package/dist/esm/format-time.js +0 -5
  23. package/dist/esm/icons.js +0 -42
  24. package/dist/esm/index.js +0 -20
  25. package/dist/esm/player-css-classname.js +0 -1
  26. package/dist/esm/player-methods.js +0 -1
  27. package/dist/esm/test/index.test.js +0 -7
  28. package/dist/esm/test/test-utils.js +0 -14
  29. package/dist/esm/test/validate-in-out-frames.test.js +0 -54
  30. package/dist/esm/test/validate-prop.test.js +0 -129
  31. package/dist/esm/use-hover-state.js +0 -23
  32. package/dist/esm/use-playback.js +0 -88
  33. package/dist/esm/use-player.js +0 -128
  34. package/dist/esm/use-thumbnail.js +0 -14
  35. package/dist/esm/use-video-controls-resize.js +0 -35
  36. package/dist/esm/utils/calculate-player-size.js +0 -24
  37. package/dist/esm/utils/cancellable-promise.js +0 -22
  38. package/dist/esm/utils/delay.js +0 -2
  39. package/dist/esm/utils/is-node.js +0 -1
  40. package/dist/esm/utils/preview-size.js +0 -1
  41. package/dist/esm/utils/props-if-has-props.js +0 -1
  42. package/dist/esm/utils/use-cancellable-promises.js +0 -18
  43. package/dist/esm/utils/use-click-prevention-on-double-click.js +0 -42
  44. package/dist/esm/utils/use-element-size.js +0 -93
  45. package/dist/esm/utils/validate-in-out-frame.js +0 -49
  46. package/dist/esm/utils/validate-initial-frame.js +0 -23
  47. package/dist/esm/utils/validate-playbackrate.js +0 -14
  48. package/dist/esm/volume-persistance.js +0 -14
@@ -1,114 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useCallback, useId, useMemo, useRef, useState } from 'react';
3
- import { Internals, random } from 'remotion';
4
- import { ICON_SIZE, VolumeOffIcon, VolumeOnIcon } from './icons.js';
5
- import { useHoverState } from './use-hover-state.js';
6
- const BAR_HEIGHT = 5;
7
- const KNOB_SIZE = 12;
8
- export const VOLUME_SLIDER_WIDTH = 100;
9
- export const MediaVolumeSlider = ({ displayVerticalVolumeSlider }) => {
10
- const [mediaMuted, setMediaMuted] = Internals.useMediaMutedState();
11
- const [mediaVolume, setMediaVolume] = Internals.useMediaVolumeState();
12
- const [focused, setFocused] = useState(false);
13
- const parentDivRef = useRef(null);
14
- const inputRef = useRef(null);
15
- const hover = useHoverState(parentDivRef);
16
- // eslint-disable-next-line react-hooks/rules-of-hooks
17
- const randomId = typeof useId === 'undefined' ? 'volume-slider' : useId();
18
- const [randomClass] = useState(() => `__remotion-volume-slider-${random(randomId)}`.replace('.', ''));
19
- const isMutedOrZero = mediaMuted || mediaVolume === 0;
20
- const onVolumeChange = (e) => {
21
- setMediaVolume(parseFloat(e.target.value));
22
- };
23
- const onBlur = () => {
24
- setTimeout(() => {
25
- // We need a small delay to check which element was focused next,
26
- // and if it wasn't the volume slider, we hide it
27
- if (document.activeElement !== inputRef.current) {
28
- setFocused(false);
29
- }
30
- }, 10);
31
- };
32
- const onClick = useCallback(() => {
33
- if (mediaVolume === 0) {
34
- setMediaVolume(1);
35
- setMediaMuted(false);
36
- return;
37
- }
38
- setMediaMuted((mute) => !mute);
39
- }, [mediaVolume, setMediaMuted, setMediaVolume]);
40
- const parentDivStyle = useMemo(() => {
41
- return {
42
- display: 'inline-flex',
43
- background: 'none',
44
- border: 'none',
45
- padding: '6px',
46
- justifyContent: 'center',
47
- alignItems: 'center',
48
- touchAction: 'none',
49
- ...(displayVerticalVolumeSlider && { position: 'relative' }),
50
- };
51
- }, [displayVerticalVolumeSlider]);
52
- const volumeContainer = useMemo(() => {
53
- return {
54
- display: 'inline',
55
- width: ICON_SIZE,
56
- height: ICON_SIZE,
57
- cursor: 'pointer',
58
- appearance: 'none',
59
- background: 'none',
60
- border: 'none',
61
- padding: 0,
62
- };
63
- }, []);
64
- const inputStyle = useMemo(() => {
65
- const commonStyle = {
66
- WebkitAppearance: 'none',
67
- backgroundColor: 'rgba(255, 255, 255, 0.5)',
68
- borderRadius: BAR_HEIGHT / 2,
69
- cursor: 'pointer',
70
- height: BAR_HEIGHT,
71
- width: VOLUME_SLIDER_WIDTH,
72
- backgroundImage: `linear-gradient(
73
- to right,
74
- white ${mediaVolume * 100}%, rgba(255, 255, 255, 0) ${mediaVolume * 100}%
75
- )`,
76
- };
77
- if (displayVerticalVolumeSlider) {
78
- return {
79
- ...commonStyle,
80
- transform: `rotate(-90deg)`,
81
- position: 'absolute',
82
- bottom: ICON_SIZE + VOLUME_SLIDER_WIDTH / 2 + 5,
83
- };
84
- }
85
- return {
86
- ...commonStyle,
87
- marginLeft: 5,
88
- };
89
- }, [displayVerticalVolumeSlider, mediaVolume]);
90
- const sliderStyle = `
91
- .${randomClass}::-webkit-slider-thumb {
92
- -webkit-appearance: none;
93
- background-color: white;
94
- border-radius: ${KNOB_SIZE / 2}px;
95
- box-shadow: 0 0 2px black;
96
- height: ${KNOB_SIZE}px;
97
- width: ${KNOB_SIZE}px;
98
- }
99
-
100
- .${randomClass}::-moz-range-thumb {
101
- -webkit-appearance: none;
102
- background-color: white;
103
- border-radius: ${KNOB_SIZE / 2}px;
104
- box-shadow: 0 0 2px black;
105
- height: ${KNOB_SIZE}px;
106
- width: ${KNOB_SIZE}px;
107
- }
108
- `;
109
- return (_jsxs("div", { ref: parentDivRef, style: parentDivStyle, children: [_jsx("style", {
110
- // eslint-disable-next-line react/no-danger
111
- dangerouslySetInnerHTML: {
112
- __html: sliderStyle,
113
- } }), _jsx("button", { "aria-label": isMutedOrZero ? 'Unmute sound' : 'Mute sound', title: isMutedOrZero ? 'Unmute sound' : 'Mute sound', onClick: onClick, onBlur: onBlur, onFocus: () => setFocused(true), style: volumeContainer, type: "button", children: isMutedOrZero ? _jsx(VolumeOffIcon, {}) : _jsx(VolumeOnIcon, {}) }), (focused || hover) && !mediaMuted ? (_jsx("input", { ref: inputRef, "aria-label": "Change volume", className: randomClass, max: 1, min: 0, onBlur: () => setFocused(false), onChange: onVolumeChange, step: 0.01, type: "range", value: mediaVolume, style: inputStyle })) : null] }));
114
- };
@@ -1,140 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { forwardRef, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, } from 'react';
3
- import { Composition, Internals } from 'remotion';
4
- import { PlayerEventEmitterContext } from './emitter-context.js';
5
- import { PlayerEmitter } from './event-emitter.js';
6
- import { PLAYER_CSS_CLASSNAME } from './player-css-classname.js';
7
- import PlayerUI from './PlayerUI.js';
8
- import { SharedPlayerContexts } from './SharedPlayerContext.js';
9
- import { validateInOutFrames } from './utils/validate-in-out-frame.js';
10
- import { validateInitialFrame } from './utils/validate-initial-frame.js';
11
- import { validatePlaybackRate } from './utils/validate-playbackrate.js';
12
- export const componentOrNullIfLazy = (props) => {
13
- if ('component' in props) {
14
- return props.component;
15
- }
16
- return null;
17
- };
18
- const PlayerFn = ({ durationInFrames, compositionHeight, compositionWidth, fps, inputProps, style, controls = false, loop = false, autoPlay = false, showVolumeControls = true, allowFullscreen = true, clickToPlay, doubleClickToFullscreen = false, spaceKeyToPlayOrPause = true, moveToBeginningWhenEnded = true, numberOfSharedAudioTags = 5, errorFallback = () => '⚠️', playbackRate = 1, renderLoading, className, showPosterWhenUnplayed, showPosterWhenEnded, showPosterWhenPaused, initialFrame, renderPoster, inFrame, outFrame, initiallyShowControls, renderFullscreenButton, renderPlayPauseButton, alwaysShowControls = false, ...componentProps }, ref) => {
19
- if (typeof window !== 'undefined') {
20
- // eslint-disable-next-line react-hooks/rules-of-hooks
21
- useLayoutEffect(() => {
22
- window.remotion_isPlayer = true;
23
- }, []);
24
- }
25
- // @ts-expect-error
26
- if (componentProps.defaultProps !== undefined) {
27
- throw new Error('The <Player /> component does not accept `defaultProps`, but some were passed. Use `inputProps` instead.');
28
- }
29
- const componentForValidation = componentOrNullIfLazy(componentProps);
30
- // @ts-expect-error
31
- if ((componentForValidation === null || componentForValidation === void 0 ? void 0 : componentForValidation.type) === Composition) {
32
- throw new TypeError(`'component' should not be an instance of <Composition/>. Pass the React component directly, and set the duration, fps and dimensions as separate props. See https://www.remotion.dev/docs/player/examples for an example.`);
33
- }
34
- if (componentForValidation === Composition) {
35
- throw new TypeError(`'component' must not be the 'Composition' component. Pass your own React component directly, and set the duration, fps and dimensions as separate props. See https://www.remotion.dev/docs/player/examples for an example.`);
36
- }
37
- const component = Internals.useLazyComponent(componentProps);
38
- validateInitialFrame({ initialFrame, durationInFrames });
39
- const [frame, setFrame] = useState(() => initialFrame !== null && initialFrame !== void 0 ? initialFrame : 0);
40
- const [playing, setPlaying] = useState(false);
41
- const [rootId] = useState('player-comp');
42
- const [emitter] = useState(() => new PlayerEmitter());
43
- const rootRef = useRef(null);
44
- const audioAndVideoTags = useRef([]);
45
- const imperativePlaying = useRef(false);
46
- if (typeof compositionHeight !== 'number') {
47
- throw new TypeError(`'compositionHeight' must be a number but got '${typeof compositionHeight}' instead`);
48
- }
49
- if (typeof compositionWidth !== 'number') {
50
- throw new TypeError(`'compositionWidth' must be a number but got '${typeof compositionWidth}' instead`);
51
- }
52
- Internals.validateDimension(compositionHeight, 'compositionHeight', 'of the <Player /> component');
53
- Internals.validateDimension(compositionWidth, 'compositionWidth', 'of the <Player /> component');
54
- Internals.validateDurationInFrames(durationInFrames, 'of the <Player/> component');
55
- Internals.validateFps(fps, 'as a prop of the <Player/> component', false);
56
- validateInOutFrames({
57
- durationInFrames,
58
- inFrame,
59
- outFrame,
60
- });
61
- if (typeof controls !== 'boolean' && typeof controls !== 'undefined') {
62
- throw new TypeError(`'controls' must be a boolean or undefined but got '${typeof controls}' instead`);
63
- }
64
- if (typeof autoPlay !== 'boolean' && typeof autoPlay !== 'undefined') {
65
- throw new TypeError(`'autoPlay' must be a boolean or undefined but got '${typeof autoPlay}' instead`);
66
- }
67
- if (typeof loop !== 'boolean' && typeof loop !== 'undefined') {
68
- throw new TypeError(`'loop' must be a boolean or undefined but got '${typeof loop}' instead`);
69
- }
70
- if (typeof doubleClickToFullscreen !== 'boolean' &&
71
- typeof doubleClickToFullscreen !== 'undefined') {
72
- throw new TypeError(`'doubleClickToFullscreen' must be a boolean or undefined but got '${typeof doubleClickToFullscreen}' instead`);
73
- }
74
- if (typeof showVolumeControls !== 'boolean' &&
75
- typeof showVolumeControls !== 'undefined') {
76
- throw new TypeError(`'showVolumeControls' must be a boolean or undefined but got '${typeof showVolumeControls}' instead`);
77
- }
78
- if (typeof allowFullscreen !== 'boolean' &&
79
- typeof allowFullscreen !== 'undefined') {
80
- throw new TypeError(`'allowFullscreen' must be a boolean or undefined but got '${typeof allowFullscreen}' instead`);
81
- }
82
- if (typeof clickToPlay !== 'boolean' && typeof clickToPlay !== 'undefined') {
83
- throw new TypeError(`'clickToPlay' must be a boolean or undefined but got '${typeof clickToPlay}' instead`);
84
- }
85
- if (typeof spaceKeyToPlayOrPause !== 'boolean' &&
86
- typeof spaceKeyToPlayOrPause !== 'undefined') {
87
- throw new TypeError(`'spaceKeyToPlayOrPause' must be a boolean or undefined but got '${typeof spaceKeyToPlayOrPause}' instead`);
88
- }
89
- if (typeof numberOfSharedAudioTags !== 'number' ||
90
- numberOfSharedAudioTags % 1 !== 0 ||
91
- !Number.isFinite(numberOfSharedAudioTags) ||
92
- Number.isNaN(numberOfSharedAudioTags) ||
93
- numberOfSharedAudioTags < 0) {
94
- throw new TypeError(`'numberOfSharedAudioTags' must be an integer but got '${numberOfSharedAudioTags}' instead`);
95
- }
96
- validatePlaybackRate(playbackRate);
97
- useEffect(() => {
98
- emitter.dispatchRatechange(playbackRate);
99
- }, [emitter, playbackRate]);
100
- useImperativeHandle(ref, () => rootRef.current, []);
101
- const timelineContextValue = useMemo(() => {
102
- return {
103
- frame,
104
- playing,
105
- rootId,
106
- shouldRegisterSequences: false,
107
- playbackRate,
108
- imperativePlaying,
109
- setPlaybackRate: () => {
110
- throw new Error('playback rate');
111
- },
112
- audioAndVideoTags,
113
- };
114
- }, [frame, playbackRate, playing, rootId]);
115
- const setTimelineContextValue = useMemo(() => {
116
- return {
117
- setFrame,
118
- setPlaying,
119
- };
120
- }, [setFrame]);
121
- const passedInputProps = useMemo(() => {
122
- return inputProps !== null && inputProps !== void 0 ? inputProps : {};
123
- }, [inputProps]);
124
- if (typeof window !== 'undefined') {
125
- // eslint-disable-next-line react-hooks/rules-of-hooks
126
- useLayoutEffect(() => {
127
- // Inject CSS only on client, and also only after the Player has hydrated
128
- Internals.CSSUtils.injectCSS(Internals.CSSUtils.makeDefaultCSS(`.${PLAYER_CSS_CLASSNAME}`, '#fff'));
129
- }, []);
130
- }
131
- return (_jsx(Internals.IsPlayerContextProvider, { children: _jsx(SharedPlayerContexts, { timelineContext: timelineContextValue, component: component, compositionHeight: compositionHeight, compositionWidth: compositionWidth, durationInFrames: durationInFrames, fps: fps, inputProps: inputProps, numberOfSharedAudioTags: numberOfSharedAudioTags, children: _jsx(Internals.Timeline.SetTimelineContext.Provider, { value: setTimelineContextValue, children: _jsx(PlayerEventEmitterContext.Provider, { value: emitter, children: _jsx(PlayerUI, { ref: rootRef, renderLoading: renderLoading, autoPlay: Boolean(autoPlay), loop: Boolean(loop), controls: Boolean(controls), errorFallback: errorFallback, style: style, inputProps: passedInputProps, allowFullscreen: Boolean(allowFullscreen), moveToBeginningWhenEnded: Boolean(moveToBeginningWhenEnded), clickToPlay: typeof clickToPlay === 'boolean'
132
- ? clickToPlay
133
- : Boolean(controls), showVolumeControls: Boolean(showVolumeControls), doubleClickToFullscreen: Boolean(doubleClickToFullscreen), spaceKeyToPlayOrPause: Boolean(spaceKeyToPlayOrPause), playbackRate: playbackRate, className: className !== null && className !== void 0 ? className : undefined, showPosterWhenUnplayed: Boolean(showPosterWhenUnplayed), showPosterWhenEnded: Boolean(showPosterWhenEnded), showPosterWhenPaused: Boolean(showPosterWhenPaused), renderPoster: renderPoster, inFrame: inFrame !== null && inFrame !== void 0 ? inFrame : null, outFrame: outFrame !== null && outFrame !== void 0 ? outFrame : null, initiallyShowControls: initiallyShowControls !== null && initiallyShowControls !== void 0 ? initiallyShowControls : true, renderFullscreen: renderFullscreenButton !== null && renderFullscreenButton !== void 0 ? renderFullscreenButton : null, renderPlayPauseButton: renderPlayPauseButton !== null && renderPlayPauseButton !== void 0 ? renderPlayPauseButton : null, alwaysShowControls: alwaysShowControls }) }) }) }) }));
134
- };
135
- const forward = forwardRef;
136
- /**
137
- * @description A component which can be rendered in a regular React App (for example: Create React App, Next.js) to display a Remotion video.
138
- * @see [Documentation](https://www.remotion.dev/docs/player/player)
139
- */
140
- export const Player = forward(PlayerFn);
@@ -1,146 +0,0 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useEffect, useMemo, useRef, useState } from 'react';
3
- import { Internals } from 'remotion';
4
- import { formatTime } from './format-time.js';
5
- import { FullscreenIcon, PauseIcon, PlayIcon } from './icons.js';
6
- import { MediaVolumeSlider } from './MediaVolumeSlider.js';
7
- import { PlayerSeekBar } from './PlayerSeekBar.js';
8
- import { useVideoControlsResize, X_PADDING } from './use-video-controls-resize.js';
9
- const gradientSteps = [
10
- 0, 0.013, 0.049, 0.104, 0.175, 0.259, 0.352, 0.45, 0.55, 0.648, 0.741, 0.825,
11
- 0.896, 0.951, 0.987,
12
- ];
13
- const gradientOpacities = [
14
- 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,
15
- 91.9,
16
- ];
17
- const globalGradientOpacity = 1 / 0.7;
18
- const containerStyle = {
19
- boxSizing: 'border-box',
20
- position: 'absolute',
21
- bottom: 0,
22
- width: '100%',
23
- paddingTop: 40,
24
- paddingBottom: 10,
25
- backgroundImage: `linear-gradient(to bottom,${gradientSteps
26
- .map((g, i) => {
27
- return `hsla(0, 0%, 0%, ${g}) ${gradientOpacities[i] * globalGradientOpacity}%`;
28
- })
29
- .join(', ')}, hsl(0, 0%, 0%) 100%)`,
30
- backgroundSize: 'auto 145px',
31
- display: 'flex',
32
- paddingRight: X_PADDING,
33
- paddingLeft: X_PADDING,
34
- flexDirection: 'column',
35
- transition: 'opacity 0.3s',
36
- };
37
- const buttonStyle = {
38
- appearance: 'none',
39
- backgroundColor: 'transparent',
40
- border: 'none',
41
- cursor: 'pointer',
42
- padding: 0,
43
- display: 'inline',
44
- marginBottom: 0,
45
- marginTop: 0,
46
- height: 25,
47
- };
48
- const controlsRow = {
49
- display: 'flex',
50
- flexDirection: 'row',
51
- width: '100%',
52
- alignItems: 'center',
53
- justifyContent: 'center',
54
- userSelect: 'none',
55
- };
56
- const leftPartStyle = {
57
- display: 'flex',
58
- flexDirection: 'row',
59
- userSelect: 'none',
60
- alignItems: 'center',
61
- };
62
- const xSpacer = {
63
- width: 10,
64
- };
65
- const ySpacer = {
66
- height: 8,
67
- };
68
- const flex1 = {
69
- flex: 1,
70
- };
71
- const fullscreen = {};
72
- const PlayPauseButton = ({ playing }) => playing ? _jsx(PauseIcon, {}) : _jsx(PlayIcon, {});
73
- export const Controls = ({ durationInFrames, hovered, isFullscreen, fps, player, showVolumeControls, onFullscreenButtonClick, allowFullscreen, onExitFullscreenButtonClick, spaceKeyToPlayOrPause, onSeekEnd, onSeekStart, inFrame, outFrame, initiallyShowControls, playerWidth, renderPlayPauseButton, renderFullscreenButton, alwaysShowControls, }) => {
74
- const playButtonRef = useRef(null);
75
- const frame = Internals.Timeline.useTimelinePosition();
76
- const [supportsFullscreen, setSupportsFullscreen] = useState(false);
77
- const { maxTimeLabelWidth, displayVerticalVolumeSlider } = useVideoControlsResize({ allowFullscreen, playerWidth });
78
- const [shouldShowInitially, setInitiallyShowControls] = useState(() => {
79
- if (typeof initiallyShowControls === 'boolean') {
80
- return initiallyShowControls;
81
- }
82
- if (typeof initiallyShowControls === 'number') {
83
- if (initiallyShowControls % 1 !== 0) {
84
- throw new Error('initiallyShowControls must be an integer or a boolean');
85
- }
86
- if (Number.isNaN(initiallyShowControls)) {
87
- throw new Error('initiallyShowControls must not be NaN');
88
- }
89
- if (!Number.isFinite(initiallyShowControls)) {
90
- throw new Error('initiallyShowControls must be finite');
91
- }
92
- if (initiallyShowControls <= 0) {
93
- throw new Error('initiallyShowControls must be a positive integer');
94
- }
95
- return initiallyShowControls;
96
- }
97
- throw new TypeError('initiallyShowControls must be a number or a boolean');
98
- });
99
- const containerCss = useMemo(() => {
100
- // Hide if playing and mouse outside
101
- const shouldShow = hovered || !player.playing || shouldShowInitially || alwaysShowControls;
102
- return {
103
- ...containerStyle,
104
- opacity: Number(shouldShow),
105
- };
106
- }, [hovered, shouldShowInitially, player.playing, alwaysShowControls]);
107
- useEffect(() => {
108
- if (playButtonRef.current && spaceKeyToPlayOrPause) {
109
- // This switches focus to play button when player.playing flag changes
110
- playButtonRef.current.focus({
111
- preventScroll: true,
112
- });
113
- }
114
- }, [player.playing, spaceKeyToPlayOrPause]);
115
- useEffect(() => {
116
- var _a;
117
- // Must be handled client-side to avoid SSR hydration mismatch
118
- setSupportsFullscreen((_a = (typeof document !== 'undefined' &&
119
- (document.fullscreenEnabled || document.webkitFullscreenEnabled))) !== null && _a !== void 0 ? _a : false);
120
- }, []);
121
- useEffect(() => {
122
- if (shouldShowInitially === false) {
123
- return;
124
- }
125
- const time = shouldShowInitially === true ? 2000 : shouldShowInitially;
126
- const timeout = setTimeout(() => {
127
- setInitiallyShowControls(false);
128
- }, time);
129
- return () => {
130
- clearInterval(timeout);
131
- };
132
- }, [shouldShowInitially]);
133
- const timeLabel = useMemo(() => {
134
- return {
135
- color: 'white',
136
- fontFamily: 'sans-serif',
137
- fontSize: 14,
138
- maxWidth: maxTimeLabelWidth === null ? undefined : maxTimeLabelWidth,
139
- overflow: 'hidden',
140
- textOverflow: 'ellipsis',
141
- };
142
- }, [maxTimeLabelWidth]);
143
- return (_jsxs("div", { style: containerCss, children: [_jsxs("div", { style: controlsRow, children: [_jsxs("div", { style: leftPartStyle, children: [_jsx("button", { ref: playButtonRef, type: "button", style: buttonStyle, 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 ? (_jsx(PlayPauseButton, { playing: player.playing })) : (renderPlayPauseButton({ playing: player.playing })) }), showVolumeControls ? (_jsxs(_Fragment, { children: [_jsx("div", { style: xSpacer }), _jsx(MediaVolumeSlider, { displayVerticalVolumeSlider: displayVerticalVolumeSlider })] })) : null, _jsx("div", { style: xSpacer }), _jsxs("div", { style: timeLabel, children: [formatTime(frame / fps), " / ", formatTime(durationInFrames / fps)] }), _jsx("div", { style: xSpacer })] }), _jsx("div", { style: flex1 }), _jsx("div", { style: fullscreen, children: supportsFullscreen && allowFullscreen ? (_jsx("button", { type: "button", "aria-label": isFullscreen ? 'Exit fullscreen' : 'Enter Fullscreen', title: isFullscreen ? 'Exit fullscreen' : 'Enter Fullscreen', style: buttonStyle, onClick: isFullscreen
144
- ? onExitFullscreenButtonClick
145
- : onFullscreenButtonClick, children: renderFullscreenButton === null ? (_jsx(FullscreenIcon, { isFullscreen: isFullscreen })) : (renderFullscreenButton({ isFullscreen })) })) : null })] }), _jsx("div", { style: ySpacer }), _jsx(PlayerSeekBar, { onSeekEnd: onSeekEnd, onSeekStart: onSeekStart, durationInFrames: durationInFrames, inFrame: inFrame, outFrame: outFrame })] }));
146
- };
@@ -1,142 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
- import { Internals, interpolate } from 'remotion';
4
- import { useHoverState } from './use-hover-state.js';
5
- import { usePlayer } from './use-player.js';
6
- import { useElementSize } from './utils/use-element-size.js';
7
- const getFrameFromX = (clientX, durationInFrames, width) => {
8
- var _a;
9
- const pos = clientX;
10
- const frame = Math.round(interpolate(pos, [0, width], [0, (_a = durationInFrames - 1) !== null && _a !== void 0 ? _a : 0], {
11
- extrapolateLeft: 'clamp',
12
- extrapolateRight: 'clamp',
13
- }));
14
- return frame;
15
- };
16
- const BAR_HEIGHT = 5;
17
- const KNOB_SIZE = 12;
18
- const VERTICAL_PADDING = 4;
19
- const containerStyle = {
20
- userSelect: 'none',
21
- paddingTop: VERTICAL_PADDING,
22
- paddingBottom: VERTICAL_PADDING,
23
- boxSizing: 'border-box',
24
- cursor: 'pointer',
25
- position: 'relative',
26
- touchAction: 'none',
27
- };
28
- const barBackground = {
29
- height: BAR_HEIGHT,
30
- backgroundColor: 'rgba(255, 255, 255, 0.25)',
31
- width: '100%',
32
- borderRadius: BAR_HEIGHT / 2,
33
- };
34
- const findBodyInWhichDivIsLocated = (div) => {
35
- let current = div;
36
- while (current.parentElement) {
37
- current = current.parentElement;
38
- }
39
- return current;
40
- };
41
- export const PlayerSeekBar = ({ durationInFrames, onSeekEnd, onSeekStart, inFrame, outFrame }) => {
42
- const containerRef = useRef(null);
43
- const barHovered = useHoverState(containerRef);
44
- const size = useElementSize(containerRef, {
45
- triggerOnWindowResize: true,
46
- shouldApplyCssTransforms: true,
47
- });
48
- const { seek, play, pause, playing } = usePlayer();
49
- const frame = Internals.Timeline.useTimelinePosition();
50
- const [dragging, setDragging] = useState({
51
- dragging: false,
52
- });
53
- const onPointerDown = useCallback((e) => {
54
- if (!size) {
55
- throw new Error('Player has no size');
56
- }
57
- const _frame = getFrameFromX(e.clientX - size.left, durationInFrames, size.width);
58
- pause();
59
- seek(_frame);
60
- setDragging({
61
- dragging: true,
62
- wasPlaying: playing,
63
- });
64
- onSeekStart();
65
- }, [size, durationInFrames, pause, seek, playing, onSeekStart]);
66
- const onPointerMove = useCallback((e) => {
67
- var _a;
68
- if (!size) {
69
- throw new Error('Player has no size');
70
- }
71
- if (!dragging.dragging) {
72
- return;
73
- }
74
- const _frame = getFrameFromX(e.clientX - ((_a = size === null || size === void 0 ? void 0 : size.left) !== null && _a !== void 0 ? _a : 0), durationInFrames, size.width);
75
- seek(_frame);
76
- }, [dragging.dragging, durationInFrames, seek, size]);
77
- const onPointerUp = useCallback(() => {
78
- setDragging({
79
- dragging: false,
80
- });
81
- if (!dragging.dragging) {
82
- return;
83
- }
84
- if (dragging.wasPlaying) {
85
- play();
86
- }
87
- else {
88
- pause();
89
- }
90
- onSeekEnd();
91
- }, [dragging, onSeekEnd, pause, play]);
92
- useEffect(() => {
93
- if (!dragging.dragging) {
94
- return;
95
- }
96
- const body = findBodyInWhichDivIsLocated(containerRef.current);
97
- body.addEventListener('pointermove', onPointerMove);
98
- body.addEventListener('pointerup', onPointerUp);
99
- return () => {
100
- body.removeEventListener('pointermove', onPointerMove);
101
- body.removeEventListener('pointerup', onPointerUp);
102
- };
103
- }, [dragging.dragging, onPointerMove, onPointerUp]);
104
- const knobStyle = useMemo(() => {
105
- var _a;
106
- return {
107
- height: KNOB_SIZE,
108
- width: KNOB_SIZE,
109
- borderRadius: KNOB_SIZE / 2,
110
- position: 'absolute',
111
- top: VERTICAL_PADDING - KNOB_SIZE / 2 + 5 / 2,
112
- backgroundColor: 'white',
113
- left: Math.max(0, (frame / Math.max(1, durationInFrames - 1)) * ((_a = size === null || size === void 0 ? void 0 : size.width) !== null && _a !== void 0 ? _a : 0) -
114
- KNOB_SIZE / 2),
115
- boxShadow: '0 0 2px black',
116
- opacity: Number(barHovered),
117
- };
118
- }, [barHovered, durationInFrames, frame, size]);
119
- const fillStyle = useMemo(() => {
120
- return {
121
- height: BAR_HEIGHT,
122
- backgroundColor: 'rgba(255, 255, 255, 1)',
123
- width: ((frame - (inFrame !== null && inFrame !== void 0 ? inFrame : 0)) / (durationInFrames - 1)) * 100 + '%',
124
- marginLeft: ((inFrame !== null && inFrame !== void 0 ? inFrame : 0) / (durationInFrames - 1)) * 100 + '%',
125
- borderRadius: BAR_HEIGHT / 2,
126
- };
127
- }, [durationInFrames, frame, inFrame]);
128
- const active = useMemo(() => {
129
- return {
130
- height: BAR_HEIGHT,
131
- backgroundColor: 'rgba(255, 255, 255, 0.25)',
132
- width: (((outFrame !== null && outFrame !== void 0 ? outFrame : durationInFrames - 1) - (inFrame !== null && inFrame !== void 0 ? inFrame : 0)) /
133
- (durationInFrames - 1)) *
134
- 100 +
135
- '%',
136
- marginLeft: ((inFrame !== null && inFrame !== void 0 ? inFrame : 0) / (durationInFrames - 1)) * 100 + '%',
137
- borderRadius: BAR_HEIGHT / 2,
138
- position: 'absolute',
139
- };
140
- }, [durationInFrames, inFrame, outFrame]);
141
- return (_jsxs("div", { ref: containerRef, onPointerDown: onPointerDown, style: containerStyle, children: [_jsxs("div", { style: barBackground, children: [_jsx("div", { style: active }), _jsx("div", { style: fillStyle })] }), _jsx("div", { style: knobStyle })] }));
142
- };