@remotion/player 3.3.43 → 3.3.44

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 (92) hide show
  1. package/dist/cjs/PlayerControls.js +1 -1
  2. package/dist/cjs/error-boundary.d.ts +1 -1
  3. package/dist/cjs/use-video-controls-resize.d.ts +6 -4
  4. package/dist/cjs/use-video-controls-resize.js +3 -1
  5. package/dist/cjs/utils/calculate-player-size.js +9 -10
  6. package/dist/esm/PlayerControls.js +1 -1
  7. package/dist/esm/use-video-controls-resize.d.ts +6 -4
  8. package/dist/esm/use-video-controls-resize.js +3 -1
  9. package/dist/esm/utils/calculate-player-size.js +9 -10
  10. package/dist/tsconfig-cjs.tsbuildinfo +1 -1
  11. package/dist/tsconfig.tsbuildinfo +1 -1
  12. package/package.json +3 -3
  13. package/dist/MediaVolumeSlider.d.ts +0 -5
  14. package/dist/MediaVolumeSlider.js +0 -118
  15. package/dist/Player.d.ts +0 -43
  16. package/dist/Player.js +0 -141
  17. package/dist/PlayerControls.d.ts +0 -41
  18. package/dist/PlayerControls.js +0 -138
  19. package/dist/PlayerSeekBar.d.ts +0 -8
  20. package/dist/PlayerSeekBar.js +0 -146
  21. package/dist/PlayerUI.d.ts +0 -38
  22. package/dist/PlayerUI.js +0 -308
  23. package/dist/SharedPlayerContext.d.ts +0 -14
  24. package/dist/SharedPlayerContext.js +0 -72
  25. package/dist/Thumbnail.d.ts +0 -20
  26. package/dist/Thumbnail.js +0 -42
  27. package/dist/ThumbnailUI.d.ts +0 -11
  28. package/dist/ThumbnailUI.js +0 -107
  29. package/dist/calculate-next-frame.d.ts +0 -14
  30. package/dist/calculate-next-frame.js +0 -28
  31. package/dist/calculate-scale.d.ts +0 -39
  32. package/dist/calculate-scale.js +0 -85
  33. package/dist/emitter-context.d.ts +0 -4
  34. package/dist/emitter-context.js +0 -9
  35. package/dist/error-boundary.d.ts +0 -19
  36. package/dist/error-boundary.js +0 -39
  37. package/dist/event-emitter.d.ts +0 -66
  38. package/dist/event-emitter.js +0 -87
  39. package/dist/format-time.d.ts +0 -1
  40. package/dist/format-time.js +0 -9
  41. package/dist/icons.d.ts +0 -10
  42. package/dist/icons.js +0 -50
  43. package/dist/index.d.ts +0 -61
  44. package/dist/index.js +0 -25
  45. package/dist/player-css-classname.d.ts +0 -1
  46. package/dist/player-css-classname.js +0 -4
  47. package/dist/player-methods.d.ts +0 -24
  48. package/dist/player-methods.js +0 -2
  49. package/dist/test/index.test.d.ts +0 -1
  50. package/dist/test/index.test.js +0 -9
  51. package/dist/test/test-utils.d.ts +0 -6
  52. package/dist/test/test-utils.js +0 -32
  53. package/dist/test/validate-in-out-frames.test.d.ts +0 -1
  54. package/dist/test/validate-in-out-frames.test.js +0 -56
  55. package/dist/test/validate-prop.test.d.ts +0 -1
  56. package/dist/test/validate-prop.test.js +0 -131
  57. package/dist/use-hover-state.d.ts +0 -1
  58. package/dist/use-hover-state.js +0 -27
  59. package/dist/use-playback.d.ts +0 -7
  60. package/dist/use-playback.js +0 -92
  61. package/dist/use-player.d.ts +0 -19
  62. package/dist/use-player.js +0 -132
  63. package/dist/use-thumbnail.d.ts +0 -6
  64. package/dist/use-thumbnail.js +0 -18
  65. package/dist/use-video-controls-resize.d.ts +0 -7
  66. package/dist/use-video-controls-resize.js +0 -36
  67. package/dist/utils/calculate-player-size.d.ts +0 -9
  68. package/dist/utils/calculate-player-size.js +0 -29
  69. package/dist/utils/cancellable-promise.d.ts +0 -5
  70. package/dist/utils/cancellable-promise.js +0 -26
  71. package/dist/utils/delay.d.ts +0 -1
  72. package/dist/utils/delay.js +0 -6
  73. package/dist/utils/is-node.d.ts +0 -1
  74. package/dist/utils/is-node.js +0 -4
  75. package/dist/utils/preview-size.d.ts +0 -8
  76. package/dist/utils/preview-size.js +0 -2
  77. package/dist/utils/props-if-has-props.d.ts +0 -5
  78. package/dist/utils/props-if-has-props.js +0 -2
  79. package/dist/utils/use-cancellable-promises.d.ts +0 -7
  80. package/dist/utils/use-cancellable-promises.js +0 -21
  81. package/dist/utils/use-click-prevention-on-double-click.d.ts +0 -3
  82. package/dist/utils/use-click-prevention-on-double-click.js +0 -45
  83. package/dist/utils/use-element-size.d.ts +0 -15
  84. package/dist/utils/use-element-size.js +0 -98
  85. package/dist/utils/validate-in-out-frame.d.ts +0 -6
  86. package/dist/utils/validate-in-out-frame.js +0 -54
  87. package/dist/utils/validate-initial-frame.d.ts +0 -4
  88. package/dist/utils/validate-initial-frame.js +0 -27
  89. package/dist/utils/validate-playbackrate.d.ts +0 -1
  90. package/dist/utils/validate-playbackrate.js +0 -18
  91. package/dist/volume-persistance.d.ts +0 -2
  92. package/dist/volume-persistance.js +0 -19
@@ -1,41 +0,0 @@
1
- import type { MouseEventHandler, ReactNode } from 'react';
2
- import React from 'react';
3
- import type { usePlayer } from './use-player';
4
- export declare type RenderPlayPauseButton = (props: {
5
- playing: boolean;
6
- }) => ReactNode;
7
- export declare type RenderFullscreenButton = (props: {
8
- isFullscreen: boolean;
9
- }) => ReactNode;
10
- export declare const X_SPACER = 10;
11
- export declare const X_PADDING = 12;
12
- declare global {
13
- interface Document {
14
- webkitFullscreenEnabled?: boolean;
15
- webkitFullscreenElement?: Element;
16
- webkitExitFullscreen?: Document['exitFullscreen'];
17
- }
18
- interface HTMLDivElement {
19
- webkitRequestFullScreen: HTMLDivElement['requestFullscreen'];
20
- }
21
- }
22
- export declare const Controls: React.FC<{
23
- fps: number;
24
- durationInFrames: number;
25
- hovered: boolean;
26
- showVolumeControls: boolean;
27
- player: ReturnType<typeof usePlayer>;
28
- onFullscreenButtonClick: MouseEventHandler<HTMLButtonElement>;
29
- isFullscreen: boolean;
30
- allowFullscreen: boolean;
31
- onExitFullscreenButtonClick: MouseEventHandler<HTMLButtonElement>;
32
- spaceKeyToPlayOrPause: boolean;
33
- onSeekEnd: () => void;
34
- onSeekStart: () => void;
35
- inFrame: number | null;
36
- outFrame: number | null;
37
- initiallyShowControls: number | boolean;
38
- playerWidth: number;
39
- renderPlayPauseButton: RenderPlayPauseButton | null;
40
- renderFullscreenButton: RenderFullscreenButton | null;
41
- }>;
@@ -1,138 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Controls = exports.X_PADDING = exports.X_SPACER = 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_1 = require("./format-time");
8
- const icons_1 = require("./icons");
9
- const MediaVolumeSlider_1 = require("./MediaVolumeSlider");
10
- const PlayerSeekBar_1 = require("./PlayerSeekBar");
11
- const use_video_controls_resize_1 = require("./use-video-controls-resize");
12
- exports.X_SPACER = 10;
13
- exports.X_PADDING = 12;
14
- const containerStyle = {
15
- boxSizing: 'border-box',
16
- position: 'absolute',
17
- bottom: 0,
18
- width: '100%',
19
- paddingTop: 10,
20
- paddingBottom: 10,
21
- background: 'linear-gradient(transparent, rgba(0, 0, 0, 0.4))',
22
- display: 'flex',
23
- paddingRight: exports.X_PADDING,
24
- paddingLeft: exports.X_PADDING,
25
- flexDirection: 'column',
26
- transition: 'opacity 0.3s',
27
- };
28
- const buttonStyle = {
29
- appearance: 'none',
30
- backgroundColor: 'transparent',
31
- border: 'none',
32
- cursor: 'pointer',
33
- padding: 0,
34
- display: 'inline',
35
- marginBottom: 0,
36
- marginTop: 0,
37
- height: 25,
38
- };
39
- const controlsRow = {
40
- display: 'flex',
41
- flexDirection: 'row',
42
- width: '100%',
43
- alignItems: 'center',
44
- justifyContent: 'center',
45
- userSelect: 'none',
46
- };
47
- const leftPartStyle = {
48
- display: 'flex',
49
- flexDirection: 'row',
50
- userSelect: 'none',
51
- alignItems: 'center',
52
- };
53
- const xSpacer = {
54
- width: 10,
55
- };
56
- const ySpacer = {
57
- height: 8,
58
- };
59
- const flex1 = {
60
- flex: 1,
61
- };
62
- const fullscreen = {};
63
- const PlayPauseButton = ({ playing }) => playing ? (0, jsx_runtime_1.jsx)(icons_1.PauseIcon, {}) : (0, jsx_runtime_1.jsx)(icons_1.PlayIcon, {});
64
- const Controls = ({ durationInFrames, hovered, isFullscreen, fps, player, showVolumeControls, onFullscreenButtonClick, allowFullscreen, onExitFullscreenButtonClick, spaceKeyToPlayOrPause, onSeekEnd, onSeekStart, inFrame, outFrame, initiallyShowControls, playerWidth, renderPlayPauseButton, renderFullscreenButton, }) => {
65
- const playButtonRef = (0, react_1.useRef)(null);
66
- const frame = remotion_1.Internals.Timeline.useTimelinePosition();
67
- const [supportsFullscreen, setSupportsFullscreen] = (0, react_1.useState)(false);
68
- const { maxTimeLabelWidth, displayVerticalVolumeSlider } = (0, use_video_controls_resize_1.useVideoControlsResize)({ allowFullscreen, playerWidth });
69
- const [shouldShowInitially, setInitiallyShowControls] = (0, react_1.useState)(() => {
70
- if (typeof initiallyShowControls === 'boolean') {
71
- return initiallyShowControls;
72
- }
73
- if (typeof initiallyShowControls === 'number') {
74
- if (initiallyShowControls % 1 !== 0) {
75
- throw new Error('initiallyShowControls must be an integer or a boolean');
76
- }
77
- if (Number.isNaN(initiallyShowControls)) {
78
- throw new Error('initiallyShowControls must not be NaN');
79
- }
80
- if (!Number.isFinite(initiallyShowControls)) {
81
- throw new Error('initiallyShowControls must be finite');
82
- }
83
- if (initiallyShowControls <= 0) {
84
- throw new Error('initiallyShowControls must be a positive integer');
85
- }
86
- return initiallyShowControls;
87
- }
88
- throw new TypeError('initiallyShowControls must be a number or a boolean');
89
- });
90
- const containerCss = (0, react_1.useMemo)(() => {
91
- // Hide if playing and mouse outside
92
- const shouldShow = hovered || !player.playing || shouldShowInitially;
93
- return {
94
- ...containerStyle,
95
- opacity: Number(shouldShow),
96
- };
97
- }, [hovered, shouldShowInitially, player.playing]);
98
- (0, react_1.useEffect)(() => {
99
- if (playButtonRef.current && spaceKeyToPlayOrPause) {
100
- // This switches focus to play button when player.playing flag changes
101
- playButtonRef.current.focus({
102
- preventScroll: true,
103
- });
104
- }
105
- }, [player.playing, spaceKeyToPlayOrPause]);
106
- (0, react_1.useEffect)(() => {
107
- var _a;
108
- // Must be handled client-side to avoid SSR hydration mismatch
109
- setSupportsFullscreen((_a = (typeof document !== 'undefined' &&
110
- (document.fullscreenEnabled || document.webkitFullscreenEnabled))) !== null && _a !== void 0 ? _a : false);
111
- }, []);
112
- (0, react_1.useEffect)(() => {
113
- if (shouldShowInitially === false) {
114
- return;
115
- }
116
- const time = shouldShowInitially === true ? 2000 : shouldShowInitially;
117
- const timeout = setTimeout(() => {
118
- setInitiallyShowControls(false);
119
- }, time);
120
- return () => {
121
- clearInterval(timeout);
122
- };
123
- }, [shouldShowInitially]);
124
- const timeLabel = (0, react_1.useMemo)(() => {
125
- return {
126
- color: 'white',
127
- fontFamily: 'sans-serif',
128
- fontSize: 14,
129
- maxWidth: maxTimeLabelWidth,
130
- overflow: 'hidden',
131
- textOverflow: 'ellipsis',
132
- };
133
- }, [maxTimeLabelWidth]);
134
- 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: 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 ? ((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_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_1.formatTime)(frame / fps), " / ", (0, format_time_1.formatTime)(durationInFrames / fps)] }), (0, jsx_runtime_1.jsx)("div", { style: xSpacer })] }), (0, jsx_runtime_1.jsx)("div", { style: flex1 }), (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: buttonStyle, onClick: isFullscreen
135
- ? onExitFullscreenButtonClick
136
- : onFullscreenButtonClick, children: renderFullscreenButton === null ? ((0, jsx_runtime_1.jsx)(icons_1.FullscreenIcon, { isFullscreen: isFullscreen })) : (renderFullscreenButton({ isFullscreen })) })) : null })] }), (0, jsx_runtime_1.jsx)("div", { style: ySpacer }), (0, jsx_runtime_1.jsx)(PlayerSeekBar_1.PlayerSeekBar, { onSeekEnd: onSeekEnd, onSeekStart: onSeekStart, durationInFrames: durationInFrames, inFrame: inFrame, outFrame: outFrame })] }));
137
- };
138
- exports.Controls = Controls;
@@ -1,8 +0,0 @@
1
- /// <reference types="react" />
2
- export declare const PlayerSeekBar: React.FC<{
3
- durationInFrames: number;
4
- onSeekStart: () => void;
5
- onSeekEnd: () => void;
6
- inFrame: number | null;
7
- outFrame: number | null;
8
- }>;
@@ -1,146 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PlayerSeekBar = 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 use_hover_state_1 = require("./use-hover-state");
8
- const use_player_1 = require("./use-player");
9
- const use_element_size_1 = require("./utils/use-element-size");
10
- const getFrameFromX = (clientX, durationInFrames, width) => {
11
- var _a;
12
- const pos = clientX;
13
- const frame = Math.round((0, remotion_1.interpolate)(pos, [0, width], [0, (_a = durationInFrames - 1) !== null && _a !== void 0 ? _a : 0], {
14
- extrapolateLeft: 'clamp',
15
- extrapolateRight: 'clamp',
16
- }));
17
- return frame;
18
- };
19
- const BAR_HEIGHT = 5;
20
- const KNOB_SIZE = 12;
21
- const VERTICAL_PADDING = 4;
22
- const containerStyle = {
23
- userSelect: 'none',
24
- paddingTop: VERTICAL_PADDING,
25
- paddingBottom: VERTICAL_PADDING,
26
- boxSizing: 'border-box',
27
- cursor: 'pointer',
28
- position: 'relative',
29
- touchAction: 'none',
30
- };
31
- const barBackground = {
32
- height: BAR_HEIGHT,
33
- backgroundColor: 'rgba(255, 255, 255, 0.25)',
34
- width: '100%',
35
- borderRadius: BAR_HEIGHT / 2,
36
- };
37
- const findBodyInWhichDivIsLocated = (div) => {
38
- let current = div;
39
- while (current.parentElement) {
40
- current = current.parentElement;
41
- }
42
- return current;
43
- };
44
- const PlayerSeekBar = ({ durationInFrames, onSeekEnd, onSeekStart, inFrame, outFrame }) => {
45
- const containerRef = (0, react_1.useRef)(null);
46
- const barHovered = (0, use_hover_state_1.useHoverState)(containerRef);
47
- const size = (0, use_element_size_1.useElementSize)(containerRef, {
48
- triggerOnWindowResize: true,
49
- shouldApplyCssTransforms: true,
50
- });
51
- const { seek, play, pause, playing } = (0, use_player_1.usePlayer)();
52
- const frame = remotion_1.Internals.Timeline.useTimelinePosition();
53
- const [dragging, setDragging] = (0, react_1.useState)({
54
- dragging: false,
55
- });
56
- const onPointerDown = (0, react_1.useCallback)((e) => {
57
- if (!size) {
58
- throw new Error('Player has no size');
59
- }
60
- const _frame = getFrameFromX(e.clientX - size.left, durationInFrames, size.width);
61
- pause();
62
- seek(_frame);
63
- setDragging({
64
- dragging: true,
65
- wasPlaying: playing,
66
- });
67
- onSeekStart();
68
- }, [size, durationInFrames, pause, seek, playing, onSeekStart]);
69
- const onPointerMove = (0, react_1.useCallback)((e) => {
70
- var _a;
71
- if (!size) {
72
- throw new Error('Player has no size');
73
- }
74
- if (!dragging.dragging) {
75
- return;
76
- }
77
- const _frame = getFrameFromX(e.clientX - ((_a = size === null || size === void 0 ? void 0 : size.left) !== null && _a !== void 0 ? _a : 0), durationInFrames, size.width);
78
- seek(_frame);
79
- }, [dragging.dragging, durationInFrames, seek, size]);
80
- const onPointerUp = (0, react_1.useCallback)(() => {
81
- setDragging({
82
- dragging: false,
83
- });
84
- if (!dragging.dragging) {
85
- return;
86
- }
87
- if (dragging.wasPlaying) {
88
- play();
89
- }
90
- else {
91
- pause();
92
- }
93
- onSeekEnd();
94
- }, [dragging, onSeekEnd, pause, play]);
95
- (0, react_1.useEffect)(() => {
96
- if (!dragging.dragging) {
97
- return;
98
- }
99
- const body = findBodyInWhichDivIsLocated(containerRef.current);
100
- body.addEventListener('pointermove', onPointerMove);
101
- body.addEventListener('pointerup', onPointerUp);
102
- return () => {
103
- body.removeEventListener('pointermove', onPointerMove);
104
- body.removeEventListener('pointerup', onPointerUp);
105
- };
106
- }, [dragging.dragging, onPointerMove, onPointerUp]);
107
- const knobStyle = (0, react_1.useMemo)(() => {
108
- var _a;
109
- return {
110
- height: KNOB_SIZE,
111
- width: KNOB_SIZE,
112
- borderRadius: KNOB_SIZE / 2,
113
- position: 'absolute',
114
- top: VERTICAL_PADDING - KNOB_SIZE / 2 + 5 / 2,
115
- backgroundColor: 'white',
116
- 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) -
117
- KNOB_SIZE / 2),
118
- boxShadow: '0 0 2px black',
119
- opacity: Number(barHovered),
120
- };
121
- }, [barHovered, durationInFrames, frame, size]);
122
- const fillStyle = (0, react_1.useMemo)(() => {
123
- return {
124
- height: BAR_HEIGHT,
125
- backgroundColor: 'rgba(255, 255, 255, 1)',
126
- width: ((frame - (inFrame !== null && inFrame !== void 0 ? inFrame : 0)) / (durationInFrames - 1)) * 100 + '%',
127
- marginLeft: ((inFrame !== null && inFrame !== void 0 ? inFrame : 0) / (durationInFrames - 1)) * 100 + '%',
128
- borderRadius: BAR_HEIGHT / 2,
129
- };
130
- }, [durationInFrames, frame, inFrame]);
131
- const active = (0, react_1.useMemo)(() => {
132
- return {
133
- height: BAR_HEIGHT,
134
- backgroundColor: 'rgba(255, 255, 255, 0.25)',
135
- width: (((outFrame !== null && outFrame !== void 0 ? outFrame : durationInFrames - 1) - (inFrame !== null && inFrame !== void 0 ? inFrame : 0)) /
136
- (durationInFrames - 1)) *
137
- 100 +
138
- '%',
139
- marginLeft: ((inFrame !== null && inFrame !== void 0 ? inFrame : 0) / (durationInFrames - 1)) * 100 + '%',
140
- borderRadius: BAR_HEIGHT / 2,
141
- position: 'absolute',
142
- };
143
- }, [durationInFrames, inFrame, outFrame]);
144
- return ((0, jsx_runtime_1.jsxs)("div", { ref: containerRef, onPointerDown: onPointerDown, style: containerStyle, children: [(0, jsx_runtime_1.jsxs)("div", { style: barBackground, children: [(0, jsx_runtime_1.jsx)("div", { style: active }), (0, jsx_runtime_1.jsx)("div", { style: fillStyle })] }), (0, jsx_runtime_1.jsx)("div", { style: knobStyle })] }));
145
- };
146
- exports.PlayerSeekBar = PlayerSeekBar;
@@ -1,38 +0,0 @@
1
- import React from 'react';
2
- import type { PlayerRef } from './player-methods';
3
- import type { RenderFullscreenButton, RenderPlayPauseButton } from './PlayerControls';
4
- export declare type ErrorFallback = (info: {
5
- error: Error;
6
- }) => React.ReactNode;
7
- export declare type RenderLoading = (canvas: {
8
- height: number;
9
- width: number;
10
- }) => React.ReactNode;
11
- export declare type RenderPoster = RenderLoading;
12
- declare const _default: React.ForwardRefExoticComponent<{
13
- controls: boolean;
14
- loop: boolean;
15
- autoPlay: boolean;
16
- allowFullscreen: boolean;
17
- inputProps: unknown;
18
- showVolumeControls: boolean;
19
- style?: React.CSSProperties | undefined;
20
- clickToPlay: boolean;
21
- doubleClickToFullscreen: boolean;
22
- spaceKeyToPlayOrPause: boolean;
23
- errorFallback: ErrorFallback;
24
- playbackRate: number;
25
- renderLoading: RenderLoading | undefined;
26
- renderPoster: RenderLoading | undefined;
27
- className: string | undefined;
28
- moveToBeginningWhenEnded: boolean;
29
- showPosterWhenPaused: boolean;
30
- showPosterWhenEnded: boolean;
31
- showPosterWhenUnplayed: boolean;
32
- inFrame: number | null;
33
- outFrame: number | null;
34
- initiallyShowControls: number | boolean;
35
- renderPlayPauseButton: RenderPlayPauseButton | null;
36
- renderFullscreen: RenderFullscreenButton | null;
37
- } & React.RefAttributes<PlayerRef>>;
38
- export default _default;
package/dist/PlayerUI.js DELETED
@@ -1,308 +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
- const jsx_runtime_1 = require("react/jsx-runtime");
27
- const react_1 = __importStar(require("react"));
28
- const remotion_1 = require("remotion");
29
- const calculate_scale_1 = require("./calculate-scale");
30
- const error_boundary_1 = require("./error-boundary");
31
- const player_css_classname_1 = require("./player-css-classname");
32
- const PlayerControls_1 = require("./PlayerControls");
33
- const use_hover_state_1 = require("./use-hover-state");
34
- const use_playback_1 = require("./use-playback");
35
- const use_player_1 = require("./use-player");
36
- const is_node_1 = require("./utils/is-node");
37
- const use_click_prevention_on_double_click_1 = require("./utils/use-click-prevention-on-double-click");
38
- const use_element_size_1 = require("./utils/use-element-size");
39
- const reactVersion = react_1.default.version.split('.')[0];
40
- if (reactVersion === '0') {
41
- throw new Error(`Version ${reactVersion} of "react" is not supported by Remotion`);
42
- }
43
- const doesReactVersionSupportSuspense = parseInt(reactVersion, 10) >= 18;
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, }, ref) => {
45
- var _a, _b, _c, _d, _e;
46
- const config = remotion_1.Internals.useUnsafeVideoConfig();
47
- const video = remotion_1.Internals.useVideo();
48
- const container = (0, react_1.useRef)(null);
49
- const hovered = (0, use_hover_state_1.useHoverState)(container);
50
- const canvasSize = (0, use_element_size_1.useElementSize)(container, {
51
- triggerOnWindowResize: false,
52
- shouldApplyCssTransforms: false,
53
- });
54
- const [hasPausedToResume, setHasPausedToResume] = (0, react_1.useState)(false);
55
- const [shouldAutoplay, setShouldAutoPlay] = (0, react_1.useState)(autoPlay);
56
- const [isFullscreen, setIsFullscreen] = (0, react_1.useState)(() => false);
57
- const [seeking, setSeeking] = (0, react_1.useState)(false);
58
- (0, use_playback_1.usePlayback)({
59
- loop,
60
- playbackRate,
61
- moveToBeginningWhenEnded,
62
- inFrame,
63
- outFrame,
64
- });
65
- const player = (0, use_player_1.usePlayer)();
66
- (0, react_1.useEffect)(() => {
67
- if (hasPausedToResume && !player.playing) {
68
- setHasPausedToResume(false);
69
- player.play();
70
- }
71
- }, [hasPausedToResume, player]);
72
- (0, react_1.useEffect)(() => {
73
- const { current } = container;
74
- if (!current) {
75
- return;
76
- }
77
- const onFullscreenChange = () => {
78
- setIsFullscreen(document.fullscreenElement === current ||
79
- document.webkitFullscreenElement === current);
80
- };
81
- document.addEventListener('fullscreenchange', onFullscreenChange);
82
- document.addEventListener('webkitfullscreenchange', onFullscreenChange);
83
- return () => {
84
- document.removeEventListener('fullscreenchange', onFullscreenChange);
85
- document.removeEventListener('webkitfullscreenchange', onFullscreenChange);
86
- };
87
- }, []);
88
- const toggle = (0, react_1.useCallback)((e) => {
89
- if (player.isPlaying()) {
90
- player.pause();
91
- }
92
- else {
93
- player.play(e);
94
- }
95
- }, [player]);
96
- const requestFullscreen = (0, react_1.useCallback)(() => {
97
- if (!allowFullscreen) {
98
- throw new Error('allowFullscreen is false');
99
- }
100
- const supportsFullScreen = document.fullscreenEnabled || document.webkitFullscreenEnabled;
101
- if (!supportsFullScreen) {
102
- throw new Error('Browser doesnt support fullscreen');
103
- }
104
- if (!container.current) {
105
- throw new Error('No player ref found');
106
- }
107
- if (container.current.webkitRequestFullScreen) {
108
- container.current.webkitRequestFullScreen();
109
- }
110
- else {
111
- container.current.requestFullscreen();
112
- }
113
- }, [allowFullscreen]);
114
- const exitFullscreen = (0, react_1.useCallback)(() => {
115
- if (document.webkitExitFullscreen) {
116
- document.webkitExitFullscreen();
117
- }
118
- else {
119
- document.exitFullscreen();
120
- }
121
- }, []);
122
- (0, react_1.useEffect)(() => {
123
- const { current } = container;
124
- if (!current) {
125
- return;
126
- }
127
- const fullscreenChange = () => {
128
- var _a;
129
- const element = (_a = document.webkitFullscreenElement) !== null && _a !== void 0 ? _a : document.fullscreenElement;
130
- if (element && element === container.current) {
131
- player.emitter.dispatchFullscreenChangeUpdate({
132
- isFullscreen: true,
133
- });
134
- }
135
- else {
136
- player.emitter.dispatchFullscreenChangeUpdate({
137
- isFullscreen: false,
138
- });
139
- }
140
- };
141
- current.addEventListener('webkitfullscreenchange', fullscreenChange);
142
- current.addEventListener('fullscreenchange', fullscreenChange);
143
- return () => {
144
- current.removeEventListener('webkitfullscreenchange', fullscreenChange);
145
- current.removeEventListener('fullscreenchange', fullscreenChange);
146
- };
147
- }, [player.emitter]);
148
- const durationInFrames = (_a = config === null || config === void 0 ? void 0 : config.durationInFrames) !== null && _a !== void 0 ? _a : 1;
149
- const layout = (0, react_1.useMemo)(() => {
150
- if (!config || !canvasSize) {
151
- return null;
152
- }
153
- return (0, calculate_scale_1.calculateCanvasTransformation)({
154
- canvasSize,
155
- compositionHeight: config.height,
156
- compositionWidth: config.width,
157
- previewSize: 'auto',
158
- });
159
- }, [canvasSize, config]);
160
- const scale = (_b = layout === null || layout === void 0 ? void 0 : layout.scale) !== null && _b !== void 0 ? _b : 1;
161
- const { setMediaVolume, setMediaMuted } = (0, react_1.useContext)(remotion_1.Internals.SetMediaVolumeContext);
162
- const { mediaMuted, mediaVolume } = (0, react_1.useContext)(remotion_1.Internals.MediaVolumeContext);
163
- (0, react_1.useImperativeHandle)(ref, () => {
164
- const methods = {
165
- play: player.play,
166
- pause: player.pause,
167
- toggle,
168
- getContainerNode: () => container.current,
169
- getCurrentFrame: player.getCurrentFrame,
170
- isPlaying: () => player.playing,
171
- seekTo: (f) => {
172
- const lastFrame = durationInFrames - 1;
173
- const frameToSeekTo = Math.max(0, Math.min(lastFrame, f));
174
- if (player.isPlaying()) {
175
- const pauseToResume = frameToSeekTo !== lastFrame || loop;
176
- setHasPausedToResume(pauseToResume);
177
- player.pause();
178
- }
179
- if (frameToSeekTo === lastFrame && !loop) {
180
- player.emitter.dispatchEnded();
181
- }
182
- player.seek(frameToSeekTo);
183
- },
184
- isFullscreen: () => isFullscreen,
185
- requestFullscreen,
186
- exitFullscreen,
187
- getVolume: () => {
188
- if (mediaMuted) {
189
- return 0;
190
- }
191
- return mediaVolume;
192
- },
193
- setVolume: (vol) => {
194
- if (typeof vol !== 'number') {
195
- throw new TypeError(`setVolume() takes a number, got value of type ${typeof vol}`);
196
- }
197
- if (isNaN(vol)) {
198
- throw new TypeError(`setVolume() got a number that is NaN. Volume must be between 0 and 1.`);
199
- }
200
- if (vol < 0 || vol > 1) {
201
- throw new TypeError(`setVolume() got a number that is out of range. Must be between 0 and 1, got ${typeof vol}`);
202
- }
203
- setMediaVolume(vol);
204
- },
205
- isMuted: () => mediaMuted || mediaVolume === 0,
206
- mute: () => {
207
- setMediaMuted(true);
208
- },
209
- unmute: () => {
210
- setMediaMuted(false);
211
- },
212
- getScale: () => scale,
213
- };
214
- return Object.assign(player.emitter, methods);
215
- }, [
216
- durationInFrames,
217
- exitFullscreen,
218
- isFullscreen,
219
- loop,
220
- mediaMuted,
221
- mediaVolume,
222
- player,
223
- requestFullscreen,
224
- setMediaMuted,
225
- setMediaVolume,
226
- toggle,
227
- scale,
228
- ]);
229
- const VideoComponent = video ? video.component : null;
230
- const outerStyle = (0, react_1.useMemo)(() => {
231
- return (0, calculate_scale_1.calculateOuterStyle)({ canvasSize, config, style });
232
- }, [canvasSize, config, style]);
233
- const outer = (0, react_1.useMemo)(() => {
234
- return (0, calculate_scale_1.calculateOuter)({ config, layout, scale });
235
- }, [config, layout, scale]);
236
- const containerStyle = (0, react_1.useMemo)(() => {
237
- return (0, calculate_scale_1.calculateContainerStyle)({ canvasSize, config, layout, scale });
238
- }, [canvasSize, config, layout, scale]);
239
- const onError = (0, react_1.useCallback)((error) => {
240
- player.pause();
241
- // Pay attention to `this context`
242
- player.emitter.dispatchError(error);
243
- }, [player]);
244
- const onFullscreenButtonClick = (0, react_1.useCallback)((e) => {
245
- e.stopPropagation();
246
- requestFullscreen();
247
- }, [requestFullscreen]);
248
- const onExitFullscreenButtonClick = (0, react_1.useCallback)((e) => {
249
- e.stopPropagation();
250
- exitFullscreen();
251
- }, [exitFullscreen]);
252
- const onSingleClick = (0, react_1.useCallback)((e) => {
253
- toggle(e);
254
- }, [toggle]);
255
- const onSeekStart = (0, react_1.useCallback)(() => {
256
- setSeeking(true);
257
- }, []);
258
- const onSeekEnd = (0, react_1.useCallback)(() => {
259
- setSeeking(false);
260
- }, []);
261
- const onDoubleClick = (0, react_1.useCallback)(() => {
262
- if (isFullscreen) {
263
- exitFullscreen();
264
- }
265
- else {
266
- requestFullscreen();
267
- }
268
- }, [exitFullscreen, isFullscreen, requestFullscreen]);
269
- const [handleClick, handleDoubleClick] = (0, use_click_prevention_on_double_click_1.useClickPreventionOnDoubleClick)(onSingleClick, onDoubleClick, doubleClickToFullscreen);
270
- (0, react_1.useEffect)(() => {
271
- if (shouldAutoplay) {
272
- player.play();
273
- setShouldAutoPlay(false);
274
- }
275
- }, [shouldAutoplay, player]);
276
- const loadingMarkup = (0, react_1.useMemo)(() => {
277
- return renderLoading
278
- ? renderLoading({
279
- height: outerStyle.height,
280
- width: outerStyle.width,
281
- })
282
- : null;
283
- }, [outerStyle.height, outerStyle.width, renderLoading]);
284
- if (!config) {
285
- return null;
286
- }
287
- const poster = renderPoster
288
- ? renderPoster({
289
- height: outerStyle.height,
290
- width: outerStyle.width,
291
- })
292
- : null;
293
- if (poster === undefined) {
294
- throw new TypeError('renderPoster() must return a React element, but undefined was returned');
295
- }
296
- const shouldShowPoster = poster &&
297
- [
298
- showPosterWhenPaused && !player.isPlaying() && !seeking,
299
- showPosterWhenEnded && player.isLastFrame && !player.isPlaying(),
300
- showPosterWhenUnplayed && !player.hasPlayed && !player.isPlaying(),
301
- ].some(Boolean);
302
- 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_1.PLAYER_CSS_CLASSNAME, children: VideoComponent ? ((0, jsx_runtime_1.jsx)(error_boundary_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 : {}), ...((_d = inputProps) !== null && _d !== void 0 ? _d : {}) }) })) : 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_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, playerWidth: (_e = canvasSize === null || canvasSize === void 0 ? void 0 : canvasSize.width) !== null && _e !== void 0 ? _e : 0, renderFullscreenButton: renderFullscreenButton, renderPlayPauseButton: renderPlayPauseButton })) : null] }));
303
- if (is_node_1.IS_NODE && !doesReactVersionSupportSuspense) {
304
- return ((0, jsx_runtime_1.jsx)("div", { ref: container, style: outerStyle, className: className, children: content }));
305
- }
306
- 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 }) }));
307
- };
308
- exports.default = (0, react_1.forwardRef)(PlayerUI);