@remotion/player 3.2.14 → 3.2.16

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/dist/Player.d.ts CHANGED
@@ -36,9 +36,11 @@ export declare type PlayerProps<T> = {
36
36
  showPosterWhenPaused?: boolean;
37
37
  showPosterWhenEnded?: boolean;
38
38
  showPosterWhenUnplayed?: boolean;
39
+ inFrame?: number | null;
40
+ outFrame?: number | null;
39
41
  } & PropsIfHasProps<T> & CompProps<T>;
40
42
  export declare const componentOrNullIfLazy: <T>(props: CompProps<T>) => ComponentType<T> | null;
41
- export declare const PlayerFn: <T>({ durationInFrames, compositionHeight, compositionWidth, fps, inputProps, style, controls, loop, autoPlay, showVolumeControls, allowFullscreen, clickToPlay, doubleClickToFullscreen, spaceKeyToPlayOrPause, moveToBeginningWhenEnded, numberOfSharedAudioTags, errorFallback, playbackRate, renderLoading, className, showPosterWhenUnplayed, showPosterWhenEnded, showPosterWhenPaused, initialFrame, renderPoster, ...componentProps }: PlayerProps<T>, ref: MutableRefObject<PlayerRef>) => JSX.Element;
43
+ export declare const PlayerFn: <T>({ durationInFrames, compositionHeight, compositionWidth, fps, inputProps, style, controls, loop, autoPlay, showVolumeControls, allowFullscreen, clickToPlay, doubleClickToFullscreen, spaceKeyToPlayOrPause, moveToBeginningWhenEnded, numberOfSharedAudioTags, errorFallback, playbackRate, renderLoading, className, showPosterWhenUnplayed, showPosterWhenEnded, showPosterWhenPaused, initialFrame, renderPoster, inFrame, outFrame, ...componentProps }: PlayerProps<T>, ref: MutableRefObject<PlayerRef>) => JSX.Element;
42
44
  declare module 'react' {
43
45
  function forwardRef<T, P = {}>(render: (props: P, ref: React.MutableRefObject<T>) => React.ReactElement | null): (props: P & React.RefAttributes<T>) => React.ReactElement | null;
44
46
  }
package/dist/Player.js CHANGED
@@ -11,6 +11,7 @@ const emitter_context_1 = require("./emitter-context");
11
11
  const event_emitter_1 = require("./event-emitter");
12
12
  const player_css_classname_1 = require("./player-css-classname");
13
13
  const PlayerUI_1 = __importDefault(require("./PlayerUI"));
14
+ const validate_in_out_frame_1 = require("./utils/validate-in-out-frame");
14
15
  const validate_initial_frame_1 = require("./utils/validate-initial-frame");
15
16
  const validate_playbackrate_1 = require("./utils/validate-playbackrate");
16
17
  const volume_persistance_1 = require("./volume-persistance");
@@ -21,7 +22,7 @@ const componentOrNullIfLazy = (props) => {
21
22
  return null;
22
23
  };
23
24
  exports.componentOrNullIfLazy = componentOrNullIfLazy;
24
- 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, ...componentProps }, ref) => {
25
+ 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, ...componentProps }, ref) => {
25
26
  if (typeof window !== 'undefined') {
26
27
  // eslint-disable-next-line react-hooks/rules-of-hooks
27
28
  (0, react_1.useLayoutEffect)(() => {
@@ -61,6 +62,11 @@ const PlayerFn = ({ durationInFrames, compositionHeight, compositionWidth, fps,
61
62
  remotion_1.Internals.validateDimension(compositionWidth, 'compositionWidth', 'of the <Player /> component');
62
63
  remotion_1.Internals.validateDurationInFrames(durationInFrames, 'of the <Player/> component');
63
64
  remotion_1.Internals.validateFps(fps, 'as a prop of the <Player/> component', false);
65
+ (0, validate_in_out_frame_1.validateInOutFrames)({
66
+ durationInFrames,
67
+ inFrame,
68
+ outFrame,
69
+ });
64
70
  if (typeof controls !== 'boolean' && typeof controls !== 'undefined') {
65
71
  throw new TypeError(`'controls' must be a boolean or undefined but got '${typeof controls}' instead`);
66
72
  }
@@ -191,7 +197,7 @@ const PlayerFn = ({ durationInFrames, compositionHeight, compositionWidth, fps,
191
197
  }
192
198
  return ((0, jsx_runtime_1.jsx)(remotion_1.Internals.CanUseRemotionHooksProvider, { children: (0, jsx_runtime_1.jsx)(remotion_1.Internals.Timeline.TimelineContext.Provider, { value: timelineContextValue, children: (0, jsx_runtime_1.jsx)(remotion_1.Internals.Timeline.SetTimelineContext.Provider, { value: setTimelineContextValue, children: (0, jsx_runtime_1.jsx)(remotion_1.Internals.CompositionManager.Provider, { value: compositionManagerContext, 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, children: (0, jsx_runtime_1.jsx)(emitter_context_1.PlayerEventEmitterContext.Provider, { value: emitter, children: (0, jsx_runtime_1.jsx)(PlayerUI_1.default, { 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'
193
199
  ? clickToPlay
194
- : Boolean(controls), showVolumeControls: Boolean(showVolumeControls), setMediaVolume: setMediaVolumeAndPersist, mediaVolume: mediaVolume, mediaMuted: mediaMuted, doubleClickToFullscreen: Boolean(doubleClickToFullscreen), setMediaMuted: setMediaMuted, spaceKeyToPlayOrPause: Boolean(spaceKeyToPlayOrPause), playbackRate: playbackRate, className: className !== null && className !== void 0 ? className : undefined, showPosterWhenUnplayed: Boolean(showPosterWhenUnplayed), showPosterWhenEnded: Boolean(showPosterWhenEnded), showPosterWhenPaused: Boolean(showPosterWhenPaused), renderPoster: renderPoster }) }) }) }) }) }) }) }) }));
200
+ : Boolean(controls), showVolumeControls: Boolean(showVolumeControls), setMediaVolume: setMediaVolumeAndPersist, mediaVolume: mediaVolume, mediaMuted: mediaMuted, doubleClickToFullscreen: Boolean(doubleClickToFullscreen), setMediaMuted: setMediaMuted, 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 }) }) }) }) }) }) }) }) }));
195
201
  };
196
202
  exports.PlayerFn = PlayerFn;
197
203
  exports.Player = (0, react_1.forwardRef)(exports.PlayerFn);
@@ -24,4 +24,6 @@ export declare const Controls: React.FC<{
24
24
  spaceKeyToPlayOrPause: boolean;
25
25
  onSeekEnd: () => void;
26
26
  onSeekStart: () => void;
27
+ inFrame: number | null;
28
+ outFrame: number | null;
27
29
  }>;
@@ -62,7 +62,7 @@ const timeLabel = {
62
62
  fontFamily: 'sans-serif',
63
63
  fontSize: 14,
64
64
  };
65
- const Controls = ({ durationInFrames, hovered, isFullscreen, fps, player, showVolumeControls, onFullscreenButtonClick, allowFullscreen, onExitFullscreenButtonClick, spaceKeyToPlayOrPause, onSeekEnd, onSeekStart, }) => {
65
+ const Controls = ({ durationInFrames, hovered, isFullscreen, fps, player, showVolumeControls, onFullscreenButtonClick, allowFullscreen, onExitFullscreenButtonClick, spaceKeyToPlayOrPause, onSeekEnd, onSeekStart, inFrame, outFrame, }) => {
66
66
  const playButtonRef = (0, react_1.useRef)(null);
67
67
  const frame = remotion_1.Internals.Timeline.useTimelinePosition();
68
68
  const [supportsFullscreen, setSupportsFullscreen] = (0, react_1.useState)(false);
@@ -90,6 +90,6 @@ const Controls = ({ durationInFrames, hovered, isFullscreen, fps, player, showVo
90
90
  }, []);
91
91
  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: player.playing ? (0, jsx_runtime_1.jsx)(icons_1.PauseIcon, {}) : (0, jsx_runtime_1.jsx)(icons_1.PlayIcon, {}) }), 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, {})] })) : 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
92
92
  ? onExitFullscreenButtonClick
93
- : onFullscreenButtonClick, children: (0, jsx_runtime_1.jsx)(icons_1.FullscreenIcon, { minimized: !isFullscreen }) })) : null })] }), (0, jsx_runtime_1.jsx)("div", { style: ySpacer }), (0, jsx_runtime_1.jsx)(PlayerSeekBar_1.PlayerSeekBar, { onSeekEnd: onSeekEnd, onSeekStart: onSeekStart, durationInFrames: durationInFrames })] }));
93
+ : onFullscreenButtonClick, children: (0, jsx_runtime_1.jsx)(icons_1.FullscreenIcon, { minimized: !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 })] }));
94
94
  };
95
95
  exports.Controls = Controls;
@@ -3,4 +3,6 @@ export declare const PlayerSeekBar: React.FC<{
3
3
  durationInFrames: number;
4
4
  onSeekStart: () => void;
5
5
  onSeekEnd: () => void;
6
+ inFrame: number | null;
7
+ outFrame: number | null;
6
8
  }>;
@@ -30,7 +30,7 @@ const containerStyle = {
30
30
  };
31
31
  const barBackground = {
32
32
  height: BAR_HEIGHT,
33
- backgroundColor: 'rgba(255, 255, 255, 0.5)',
33
+ backgroundColor: 'rgba(255, 255, 255, 0.25)',
34
34
  width: '100%',
35
35
  borderRadius: BAR_HEIGHT / 2,
36
36
  };
@@ -41,7 +41,7 @@ const findBodyInWhichDivIsLocated = (div) => {
41
41
  }
42
42
  return current;
43
43
  };
44
- const PlayerSeekBar = ({ durationInFrames, onSeekEnd, onSeekStart }) => {
44
+ const PlayerSeekBar = ({ durationInFrames, onSeekEnd, onSeekStart, inFrame, outFrame }) => {
45
45
  const containerRef = (0, react_1.useRef)(null);
46
46
  const barHovered = (0, use_hover_state_1.useHoverState)(containerRef);
47
47
  const size = (0, use_element_size_1.useElementSize)(containerRef, {
@@ -123,10 +123,24 @@ const PlayerSeekBar = ({ durationInFrames, onSeekEnd, onSeekStart }) => {
123
123
  return {
124
124
  height: BAR_HEIGHT,
125
125
  backgroundColor: 'rgba(255, 255, 255, 1)',
126
- width: (frame / (durationInFrames - 1)) * 100 + '%',
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 + '%',
127
128
  borderRadius: BAR_HEIGHT / 2,
128
129
  };
129
- }, [durationInFrames, frame]);
130
- return ((0, jsx_runtime_1.jsxs)("div", { ref: containerRef, onPointerDown: onPointerDown, style: containerStyle, children: [(0, jsx_runtime_1.jsx)("div", { style: barBackground, children: (0, jsx_runtime_1.jsx)("div", { style: fillStyle }) }), (0, jsx_runtime_1.jsx)("div", { style: knobStyle })] }));
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 })] }));
131
145
  };
132
146
  exports.PlayerSeekBar = PlayerSeekBar;
@@ -32,5 +32,7 @@ declare const _default: (props: {
32
32
  showPosterWhenPaused: boolean;
33
33
  showPosterWhenEnded: boolean;
34
34
  showPosterWhenUnplayed: boolean;
35
+ inFrame: number | null;
36
+ outFrame: number | null;
35
37
  } & React.RefAttributes<PlayerRef | null>) => React.ReactElement<any, string | React.JSXElementConstructor<any>> | null;
36
38
  export default _default;
package/dist/PlayerUI.js CHANGED
@@ -42,7 +42,7 @@ if (reactVersion === '0') {
42
42
  throw new Error(`Version ${reactVersion} of "react" is not supported by Remotion`);
43
43
  }
44
44
  const doesReactVersionSupportSuspense = parseInt(reactVersion, 10) >= 18;
45
- const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps, clickToPlay, showVolumeControls, mediaVolume, mediaMuted, doubleClickToFullscreen, setMediaMuted, setMediaVolume, spaceKeyToPlayOrPause, errorFallback, playbackRate, renderLoading, renderPoster, className, moveToBeginningWhenEnded, showPosterWhenUnplayed, showPosterWhenEnded, showPosterWhenPaused, }, ref) => {
45
+ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps, clickToPlay, showVolumeControls, mediaVolume, mediaMuted, doubleClickToFullscreen, setMediaMuted, setMediaVolume, spaceKeyToPlayOrPause, errorFallback, playbackRate, renderLoading, renderPoster, className, moveToBeginningWhenEnded, showPosterWhenUnplayed, showPosterWhenEnded, showPosterWhenPaused, inFrame, outFrame, }, ref) => {
46
46
  var _a, _b, _c;
47
47
  const config = remotion_1.Internals.useUnsafeVideoConfig();
48
48
  const video = remotion_1.Internals.useVideo();
@@ -60,8 +60,8 @@ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps
60
60
  loop,
61
61
  playbackRate,
62
62
  moveToBeginningWhenEnded,
63
- inFrame: null,
64
- outFrame: null,
63
+ inFrame,
64
+ outFrame,
65
65
  });
66
66
  const player = (0, use_player_1.usePlayer)();
67
67
  (0, react_1.useEffect)(() => {
@@ -233,7 +233,7 @@ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps
233
233
  if (!config || !canvasSize) {
234
234
  return null;
235
235
  }
236
- return (0, calculate_scale_1.calculateScale)({
236
+ return (0, calculate_scale_1.calculateCanvasTransformation)({
237
237
  canvasSize,
238
238
  compositionHeight: config.height,
239
239
  compositionWidth: config.width,
@@ -260,7 +260,7 @@ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps
260
260
  if (!config || !canvasSize) {
261
261
  return {};
262
262
  }
263
- const { scale, xCorrection, yCorrection } = (0, calculate_scale_1.calculateScale)({
263
+ const { scale, xCorrection, yCorrection } = (0, calculate_scale_1.calculateCanvasTransformation)({
264
264
  canvasSize,
265
265
  compositionHeight: config.height,
266
266
  compositionWidth: config.width,
@@ -332,7 +332,7 @@ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps
332
332
  showPosterWhenEnded && player.isLastFrame && !player.isPlaying(),
333
333
  showPosterWhenUnplayed && !player.hasPlayed && !player.isPlaying(),
334
334
  ].some(Boolean);
335
- 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, { ...((_b = video === null || video === void 0 ? void 0 : video.defaultProps) !== null && _b !== void 0 ? _b : {}), ...((_c = inputProps) !== null && _c !== void 0 ? _c : {}) }) })) : 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 })) : null] }));
335
+ 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, { ...((_b = video === null || video === void 0 ? void 0 : video.defaultProps) !== null && _b !== void 0 ? _b : {}), ...((_c = inputProps) !== null && _c !== void 0 ? _c : {}) }) })) : 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 })) : null] }));
336
336
  if (is_node_1.IS_NODE && !doesReactVersionSupportSuspense) {
337
337
  return ((0, jsx_runtime_1.jsx)("div", { ref: container, style: outerStyle, className: className, children: content }));
338
338
  }
@@ -1,7 +1,13 @@
1
1
  import type { PreviewSize } from './utils/preview-size';
2
2
  import type { Size } from './utils/use-element-size';
3
- export declare const calculateScale: ({ previewSize, compositionWidth, compositionHeight, canvasSize, }: {
4
- previewSize: PreviewSize;
3
+ export declare const calculateScale: ({ canvasSize, compositionHeight, compositionWidth, previewSize, }: {
4
+ previewSize: PreviewSize['size'];
5
+ compositionWidth: number;
6
+ compositionHeight: number;
7
+ canvasSize: Size;
8
+ }) => number;
9
+ export declare const calculateCanvasTransformation: ({ previewSize, compositionWidth, compositionHeight, canvasSize, }: {
10
+ previewSize: PreviewSize['size'];
5
11
  compositionWidth: number;
6
12
  compositionHeight: number;
7
13
  canvasSize: Size;
@@ -1,11 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateScale = void 0;
4
- const calculateScale = ({ previewSize, compositionWidth, compositionHeight, canvasSize, }) => {
3
+ exports.calculateCanvasTransformation = exports.calculateScale = void 0;
4
+ const calculateScale = ({ canvasSize, compositionHeight, compositionWidth, previewSize, }) => {
5
5
  const heightRatio = canvasSize.height / compositionHeight;
6
6
  const widthRatio = canvasSize.width / compositionWidth;
7
7
  const ratio = Math.min(heightRatio, widthRatio);
8
- const scale = previewSize === 'auto' ? ratio : Number(previewSize);
8
+ return previewSize === 'auto' ? ratio : Number(previewSize);
9
+ };
10
+ exports.calculateScale = calculateScale;
11
+ const calculateCanvasTransformation = ({ previewSize, compositionWidth, compositionHeight, canvasSize, }) => {
12
+ const scale = (0, exports.calculateScale)({
13
+ canvasSize,
14
+ compositionHeight,
15
+ compositionWidth,
16
+ previewSize,
17
+ });
9
18
  const correction = 0 - (1 - scale) / 2;
10
19
  const xCorrection = correction * compositionWidth;
11
20
  const yCorrection = correction * compositionHeight;
@@ -21,4 +30,4 @@ const calculateScale = ({ previewSize, compositionWidth, compositionHeight, canv
21
30
  scale,
22
31
  };
23
32
  };
24
- exports.calculateScale = calculateScale;
33
+ exports.calculateCanvasTransformation = calculateCanvasTransformation;
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import { PlayerEmitter } from './event-emitter';
3
3
  export { ErrorFallback, Player, PlayerProps } from './Player';
4
4
  export { PlayerMethods, PlayerRef } from './player-methods';
5
5
  export type { RenderLoading, RenderPoster } from './PlayerUI';
6
- export { PreviewSize } from './utils/preview-size';
6
+ export { PreviewSize, Translation } from './utils/preview-size';
7
7
  export { Size } from './utils/use-element-size';
8
8
  export type { CallbackListener, EventTypes };
9
9
  export declare const PlayerInternals: {
@@ -35,8 +35,8 @@ export declare const PlayerInternals: {
35
35
  triggerOnWindowResize: boolean;
36
36
  shouldApplyCssTransforms: boolean;
37
37
  }) => import("./utils/use-element-size").Size | null;
38
- calculateScale: ({ previewSize, compositionWidth, compositionHeight, canvasSize, }: {
39
- previewSize: import("./utils/preview-size").PreviewSize;
38
+ calculateCanvasTransformation: ({ previewSize, compositionWidth, compositionHeight, canvasSize, }: {
39
+ previewSize: number | "auto";
40
40
  compositionWidth: number;
41
41
  compositionHeight: number;
42
42
  canvasSize: import("./utils/use-element-size").Size;
@@ -49,4 +49,10 @@ export declare const PlayerInternals: {
49
49
  };
50
50
  useHoverState: (ref: import("react").RefObject<HTMLDivElement>) => boolean;
51
51
  updateAllElementsSizes: () => void;
52
+ calculateScale: ({ canvasSize, compositionHeight, compositionWidth, previewSize, }: {
53
+ previewSize: number | "auto";
54
+ compositionWidth: number;
55
+ compositionHeight: number;
56
+ canvasSize: import("./utils/use-element-size").Size;
57
+ }) => number;
52
58
  };
package/dist/index.js CHANGED
@@ -16,7 +16,8 @@ exports.PlayerInternals = {
16
16
  usePlayer: use_player_1.usePlayer,
17
17
  usePlayback: use_playback_1.usePlayback,
18
18
  useElementSize: use_element_size_1.useElementSize,
19
- calculateScale: calculate_scale_1.calculateScale,
19
+ calculateCanvasTransformation: calculate_scale_1.calculateCanvasTransformation,
20
20
  useHoverState: use_hover_state_1.useHoverState,
21
21
  updateAllElementsSizes: use_element_size_1.updateAllElementsSizes,
22
+ calculateScale: calculate_scale_1.calculateScale,
22
23
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const validate_in_out_frame_1 = require("../utils/validate-in-out-frame");
4
+ test('Validate in out frames', () => {
5
+ expect(() => (0, validate_in_out_frame_1.validateInOutFrames)({
6
+ durationInFrames: 200,
7
+ inFrame: 201,
8
+ outFrame: undefined,
9
+ })).toThrow(/inFrame must be less than \(durationInFrames - 1\)/);
10
+ expect(() => (0, validate_in_out_frame_1.validateInOutFrames)({
11
+ durationInFrames: 200,
12
+ inFrame: 199,
13
+ outFrame: 201,
14
+ })).toThrow(/outFrame must be less than \(durationInFrames - 1\)/);
15
+ expect(() => (0, validate_in_out_frame_1.validateInOutFrames)({
16
+ durationInFrames: 200,
17
+ inFrame: -10,
18
+ outFrame: null,
19
+ })).toThrow(/inFrame must be greater than 0, but is -10/);
20
+ expect(() => (0, validate_in_out_frame_1.validateInOutFrames)({
21
+ durationInFrames: 200,
22
+ inFrame: null,
23
+ outFrame: -10,
24
+ })).toThrow(/outFrame must be greater than 0, but is -10/);
25
+ expect(() => (0, validate_in_out_frame_1.validateInOutFrames)({
26
+ durationInFrames: 200,
27
+ inFrame: 1.5,
28
+ outFrame: null,
29
+ })).toThrow(/"inFrame" must be an integer, but is 1.5/);
30
+ expect(() => (0, validate_in_out_frame_1.validateInOutFrames)({
31
+ durationInFrames: 200,
32
+ inFrame: 20,
33
+ outFrame: 20,
34
+ })).toThrow(/outFrame must be greater than inFrame, but is 20/);
35
+ expect(() => (0, validate_in_out_frame_1.validateInOutFrames)({
36
+ durationInFrames: 200,
37
+ inFrame: 21,
38
+ outFrame: 20,
39
+ })).toThrow(/outFrame must be greater than inFrame, but is 20 <= 21/);
40
+ expect(() => (0, validate_in_out_frame_1.validateInOutFrames)({
41
+ durationInFrames: 200,
42
+ inFrame: null,
43
+ outFrame: 20,
44
+ })).not.toThrow();
45
+ expect(() => (0, validate_in_out_frame_1.validateInOutFrames)({
46
+ durationInFrames: 200,
47
+ inFrame: null,
48
+ outFrame: null,
49
+ })).not.toThrow();
50
+ expect(() => (0, validate_in_out_frame_1.validateInOutFrames)({
51
+ durationInFrames: 200,
52
+ inFrame: 10,
53
+ outFrame: 20,
54
+ })).not.toThrow();
55
+ });
@@ -1 +1,8 @@
1
- export declare type PreviewSize = 'auto' | number;
1
+ export declare type Translation = {
2
+ x: number;
3
+ y: number;
4
+ };
5
+ export declare type PreviewSize = {
6
+ size: number | 'auto';
7
+ translation: Translation;
8
+ };
@@ -0,0 +1,6 @@
1
+ export declare const validateSingleFrameFrame: (frame: unknown, variableName: string) => number | null;
2
+ export declare const validateInOutFrames: ({ inFrame, durationInFrames, outFrame, }: {
3
+ inFrame: unknown;
4
+ outFrame: unknown;
5
+ durationInFrames: number;
6
+ }) => void;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateInOutFrames = exports.validateSingleFrameFrame = void 0;
4
+ const validateSingleFrameFrame = (frame, variableName) => {
5
+ if (typeof frame === 'undefined' || frame === null) {
6
+ return frame !== null && frame !== void 0 ? frame : null;
7
+ }
8
+ if (typeof frame !== 'number') {
9
+ throw new TypeError(`"${variableName}" must be a number, but is ${JSON.stringify(frame)}`);
10
+ }
11
+ if (Number.isNaN(frame)) {
12
+ throw new TypeError(`"${variableName}" must not be NaN, but is ${JSON.stringify(frame)}`);
13
+ }
14
+ if (!Number.isFinite(frame)) {
15
+ throw new TypeError(`"${variableName}" must be finite, but is ${JSON.stringify(frame)}`);
16
+ }
17
+ if (frame % 1 !== 0) {
18
+ throw new TypeError(`"${variableName}" must be an integer, but is ${JSON.stringify(frame)}`);
19
+ }
20
+ return frame;
21
+ };
22
+ exports.validateSingleFrameFrame = validateSingleFrameFrame;
23
+ const validateInOutFrames = ({ inFrame, durationInFrames, outFrame, }) => {
24
+ const validatedInFrame = (0, exports.validateSingleFrameFrame)(inFrame, 'inFrame');
25
+ const validateOutFrame = (0, exports.validateSingleFrameFrame)(outFrame, 'outFrame');
26
+ if (validatedInFrame === null && validateOutFrame === null) {
27
+ return;
28
+ }
29
+ // Must not be over the duration
30
+ if (validatedInFrame !== null && validatedInFrame > durationInFrames - 1) {
31
+ throw new Error('inFrame must be less than (durationInFrames - 1), but is ' +
32
+ validatedInFrame);
33
+ }
34
+ if (validateOutFrame !== null && validateOutFrame > durationInFrames - 1) {
35
+ throw new Error('outFrame must be less than (durationInFrames - 1), but is ' +
36
+ validatedInFrame);
37
+ }
38
+ // Must not be under 0
39
+ if (validatedInFrame !== null && validatedInFrame < 0) {
40
+ throw new Error('inFrame must be greater than 0, but is ' + validatedInFrame);
41
+ }
42
+ if (validateOutFrame !== null && validateOutFrame < 0) {
43
+ throw new Error('outFrame must be greater than 0, but is ' + validateOutFrame);
44
+ }
45
+ if (validateOutFrame !== null &&
46
+ validatedInFrame !== null &&
47
+ validateOutFrame <= validatedInFrame) {
48
+ throw new Error('outFrame must be greater than inFrame, but is ' +
49
+ validateOutFrame +
50
+ ' <= ' +
51
+ validatedInFrame);
52
+ }
53
+ };
54
+ exports.validateInOutFrames = validateInOutFrames;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/player",
3
- "version": "3.2.14",
3
+ "version": "3.2.16",
4
4
  "description": "Remotion Player",
5
5
  "main": "dist/index.js",
6
6
  "sideEffects": false,
@@ -28,7 +28,7 @@
28
28
  ],
29
29
  "license": "SEE LICENSE IN LICENSE.md",
30
30
  "dependencies": {
31
- "remotion": "3.2.14"
31
+ "remotion": "3.2.16"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "react": ">=16.8.0",
@@ -63,5 +63,5 @@
63
63
  "publishConfig": {
64
64
  "access": "public"
65
65
  },
66
- "gitHead": "544ef952c9df79b015496d68202776787f15cd93"
66
+ "gitHead": "3c64e274a2c74e1b791d4a24b3af2ae456c0fd9e"
67
67
  }