@remotion/player 4.0.0-oops.3 → 4.0.0-prefetch.10

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 (41) hide show
  1. package/dist/MediaVolumeSlider.js +1 -1
  2. package/dist/Player.d.ts +16 -6
  3. package/dist/Player.js +23 -7
  4. package/dist/PlayerControls.d.ts +17 -2
  5. package/dist/PlayerControls.js +13 -5
  6. package/dist/PlayerSeekBar.d.ts +4 -0
  7. package/dist/PlayerSeekBar.js +35 -11
  8. package/dist/PlayerUI.d.ts +11 -2
  9. package/dist/PlayerUI.js +93 -12
  10. package/dist/calculate-scale.d.ts +10 -4
  11. package/dist/calculate-scale.js +13 -4
  12. package/dist/emitter-context.d.ts +1 -1
  13. package/dist/error-boundary.js +1 -1
  14. package/dist/event-emitter.d.ts +5 -0
  15. package/dist/event-emitter.js +4 -0
  16. package/dist/icons.js +8 -8
  17. package/dist/index.d.ts +20 -7
  18. package/dist/index.js +2 -1
  19. package/dist/player-methods.d.ts +2 -2
  20. package/dist/test/test-utils.d.ts +3 -3
  21. package/dist/test/test-utils.js +7 -3
  22. package/dist/test/validate-in-out-frames.test.d.ts +1 -0
  23. package/dist/test/validate-in-out-frames.test.js +55 -0
  24. package/dist/test/validate-prop.test.js +14 -14
  25. package/dist/use-playback.d.ts +4 -1
  26. package/dist/use-playback.js +4 -3
  27. package/dist/use-player.d.ts +9 -4
  28. package/dist/use-player.js +23 -4
  29. package/dist/utils/calculate-player-size.d.ts +2 -2
  30. package/dist/utils/preview-size.d.ts +8 -1
  31. package/dist/utils/use-cancellable-promises.d.ts +1 -1
  32. package/dist/utils/use-click-prevention-on-double-click.d.ts +1 -1
  33. package/dist/utils/use-element-size.d.ts +4 -0
  34. package/dist/utils/use-element-size.js +8 -0
  35. package/dist/utils/validate-in-out-frame.d.ts +6 -0
  36. package/dist/utils/validate-in-out-frame.js +54 -0
  37. package/dist/utils/validate-initial-frame.d.ts +4 -0
  38. package/dist/utils/validate-initial-frame.js +27 -0
  39. package/package.json +5 -5
  40. package/dist/utils/browser-supports-fullscreen.d.ts +0 -11
  41. package/dist/utils/browser-supports-fullscreen.js +0 -5
package/dist/icons.js CHANGED
@@ -8,11 +8,11 @@ const rotate = {
8
8
  transform: `rotate(90deg)`,
9
9
  };
10
10
  const PlayIcon = () => {
11
- return ((0, jsx_runtime_1.jsx)("svg", { width: exports.ICON_SIZE, height: exports.ICON_SIZE, viewBox: "-100 -100 400 400", style: rotate, children: (0, jsx_runtime_1.jsx)("path", { fill: "#fff", stroke: "#fff", strokeWidth: "100", strokeLinejoin: "round", d: "M 2 172 a 196 100 0 0 0 195 5 A 196 240 0 0 0 100 2.259 A 196 240 0 0 0 2 172 z" }, void 0) }, void 0));
11
+ return ((0, jsx_runtime_1.jsx)("svg", { width: exports.ICON_SIZE, height: exports.ICON_SIZE, viewBox: "-100 -100 400 400", style: rotate, children: (0, jsx_runtime_1.jsx)("path", { fill: "#fff", stroke: "#fff", strokeWidth: "100", strokeLinejoin: "round", d: "M 2 172 a 196 100 0 0 0 195 5 A 196 240 0 0 0 100 2.259 A 196 240 0 0 0 2 172 z" }) }));
12
12
  };
13
13
  exports.PlayIcon = PlayIcon;
14
14
  const PauseIcon = () => {
15
- return ((0, jsx_runtime_1.jsxs)("svg", { viewBox: "0 0 100 100", width: exports.ICON_SIZE, height: exports.ICON_SIZE, children: [(0, jsx_runtime_1.jsx)("rect", { x: "25", y: "20", width: "20", height: "60", fill: "#fff", ry: "5", rx: "5" }, void 0), (0, jsx_runtime_1.jsx)("rect", { x: "55", y: "20", width: "20", height: "60", fill: "#fff", ry: "5", rx: "5" }, void 0)] }, void 0));
15
+ return ((0, jsx_runtime_1.jsxs)("svg", { viewBox: "0 0 100 100", width: exports.ICON_SIZE, height: exports.ICON_SIZE, children: [(0, jsx_runtime_1.jsx)("rect", { x: "25", y: "20", width: "20", height: "60", fill: "#fff", ry: "5", rx: "5" }), (0, jsx_runtime_1.jsx)("rect", { x: "55", y: "20", width: "20", height: "60", fill: "#fff", ry: "5", rx: "5" })] }));
16
16
  };
17
17
  exports.PauseIcon = PauseIcon;
18
18
  const FullscreenIcon = ({ minimized }) => {
@@ -25,26 +25,26 @@ const FullscreenIcon = ({ minimized }) => {
25
25
  M ${out} ${inset}
26
26
  L ${middleInset} ${middleInset}
27
27
  L ${inset} ${out}
28
- `, stroke: "#fff", strokeWidth: strokeWidth, fill: "none" }, void 0), (0, jsx_runtime_1.jsx)("path", { d: `
28
+ `, stroke: "#fff", strokeWidth: strokeWidth, fill: "none" }), (0, jsx_runtime_1.jsx)("path", { d: `
29
29
  M ${viewSize - out} ${inset}
30
30
  L ${viewSize - middleInset} ${middleInset}
31
31
  L ${viewSize - inset} ${out}
32
- `, stroke: "#fff", strokeWidth: strokeWidth, fill: "none" }, void 0), (0, jsx_runtime_1.jsx)("path", { d: `
32
+ `, stroke: "#fff", strokeWidth: strokeWidth, fill: "none" }), (0, jsx_runtime_1.jsx)("path", { d: `
33
33
  M ${out} ${viewSize - inset}
34
34
  L ${middleInset} ${viewSize - middleInset}
35
35
  L ${inset} ${viewSize - out}
36
- `, stroke: "#fff", strokeWidth: strokeWidth, fill: "none" }, void 0), (0, jsx_runtime_1.jsx)("path", { d: `
36
+ `, stroke: "#fff", strokeWidth: strokeWidth, fill: "none" }), (0, jsx_runtime_1.jsx)("path", { d: `
37
37
  M ${viewSize - out} ${viewSize - inset}
38
38
  L ${viewSize - middleInset} ${viewSize - middleInset}
39
39
  L ${viewSize - inset} ${viewSize - out}
40
- `, stroke: "#fff", strokeWidth: strokeWidth, fill: "none" }, void 0)] }, void 0));
40
+ `, stroke: "#fff", strokeWidth: strokeWidth, fill: "none" })] }));
41
41
  };
42
42
  exports.FullscreenIcon = FullscreenIcon;
43
43
  const VolumeOffIcon = () => {
44
- return ((0, jsx_runtime_1.jsx)("svg", { width: exports.ICON_SIZE, height: exports.ICON_SIZE, viewBox: "0 0 24 24", children: (0, jsx_runtime_1.jsx)("path", { d: "M3.63 3.63a.996.996 0 000 1.41L7.29 8.7 7 9H4c-.55 0-1 .45-1 1v4c0 .55.45 1 1 1h3l3.29 3.29c.63.63 1.71.18 1.71-.71v-4.17l4.18 4.18c-.49.37-1.02.68-1.6.91-.36.15-.58.53-.58.92 0 .72.73 1.18 1.39.91.8-.33 1.55-.77 2.22-1.31l1.34 1.34a.996.996 0 101.41-1.41L5.05 3.63c-.39-.39-1.02-.39-1.42 0zM19 12c0 .82-.15 1.61-.41 2.34l1.53 1.53c.56-1.17.88-2.48.88-3.87 0-3.83-2.4-7.11-5.78-8.4-.59-.23-1.22.23-1.22.86v.19c0 .38.25.71.61.85C17.18 6.54 19 9.06 19 12zm-8.71-6.29l-.17.17L12 7.76V6.41c0-.89-1.08-1.33-1.71-.7zM16.5 12A4.5 4.5 0 0014 7.97v1.79l2.48 2.48c.01-.08.02-.16.02-.24z", fill: "#fff" }, void 0) }, void 0));
44
+ return ((0, jsx_runtime_1.jsx)("svg", { width: exports.ICON_SIZE, height: exports.ICON_SIZE, viewBox: "0 0 24 24", children: (0, jsx_runtime_1.jsx)("path", { d: "M3.63 3.63a.996.996 0 000 1.41L7.29 8.7 7 9H4c-.55 0-1 .45-1 1v4c0 .55.45 1 1 1h3l3.29 3.29c.63.63 1.71.18 1.71-.71v-4.17l4.18 4.18c-.49.37-1.02.68-1.6.91-.36.15-.58.53-.58.92 0 .72.73 1.18 1.39.91.8-.33 1.55-.77 2.22-1.31l1.34 1.34a.996.996 0 101.41-1.41L5.05 3.63c-.39-.39-1.02-.39-1.42 0zM19 12c0 .82-.15 1.61-.41 2.34l1.53 1.53c.56-1.17.88-2.48.88-3.87 0-3.83-2.4-7.11-5.78-8.4-.59-.23-1.22.23-1.22.86v.19c0 .38.25.71.61.85C17.18 6.54 19 9.06 19 12zm-8.71-6.29l-.17.17L12 7.76V6.41c0-.89-1.08-1.33-1.71-.7zM16.5 12A4.5 4.5 0 0014 7.97v1.79l2.48 2.48c.01-.08.02-.16.02-.24z", fill: "#fff" }) }));
45
45
  };
46
46
  exports.VolumeOffIcon = VolumeOffIcon;
47
47
  const VolumeOnIcon = () => {
48
- return ((0, jsx_runtime_1.jsx)("svg", { width: exports.ICON_SIZE, height: exports.ICON_SIZE, viewBox: "0 0 24 24", children: (0, jsx_runtime_1.jsx)("path", { d: "M3 10v4c0 .55.45 1 1 1h3l3.29 3.29c.63.63 1.71.18 1.71-.71V6.41c0-.89-1.08-1.34-1.71-.71L7 9H4c-.55 0-1 .45-1 1zm13.5 2A4.5 4.5 0 0014 7.97v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 4.45v.2c0 .38.25.71.6.85C17.18 6.53 19 9.06 19 12s-1.82 5.47-4.4 6.5c-.36.14-.6.47-.6.85v.2c0 .63.63 1.07 1.21.85C18.6 19.11 21 15.84 21 12s-2.4-7.11-5.79-8.4c-.58-.23-1.21.22-1.21.85z", fill: "#fff" }, void 0) }, void 0));
48
+ return ((0, jsx_runtime_1.jsx)("svg", { width: exports.ICON_SIZE, height: exports.ICON_SIZE, viewBox: "0 0 24 24", children: (0, jsx_runtime_1.jsx)("path", { d: "M3 10v4c0 .55.45 1 1 1h3l3.29 3.29c.63.63 1.71.18 1.71-.71V6.41c0-.89-1.08-1.34-1.71-.71L7 9H4c-.55 0-1 .45-1 1zm13.5 2A4.5 4.5 0 0014 7.97v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 4.45v.2c0 .38.25.71.6.85C17.18 6.53 19 9.06 19 12s-1.82 5.47-4.4 6.5c-.36.14-.6.47-.6.85v.2c0 .63.63 1.07 1.21.85C18.6 19.11 21 15.84 21 12s-2.4-7.11-5.79-8.4c-.58-.23-1.21.22-1.21.85z", fill: "#fff" }) }));
49
49
  };
50
50
  exports.VolumeOnIcon = VolumeOnIcon;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  /// <reference types="react" />
2
- import { CallbackListener, EventTypes, PlayerEmitter } from './event-emitter';
3
- export { ErrorFallback, Player } from './Player';
2
+ import type { CallbackListener, EventTypes } from './event-emitter';
3
+ import { PlayerEmitter } from './event-emitter';
4
+ export { ErrorFallback, Player, PlayerProps } from './Player';
4
5
  export { PlayerMethods, PlayerRef } from './player-methods';
5
- export type { RenderLoading } from './PlayerUI';
6
- export { PreviewSize } from './utils/preview-size';
6
+ export type { RenderLoading, RenderPoster } from './PlayerUI';
7
+ export { PreviewSize, Translation } from './utils/preview-size';
7
8
  export { Size } from './utils/use-element-size';
8
9
  export type { CallbackListener, EventTypes };
9
10
  export declare const PlayerInternals: {
@@ -13,24 +14,30 @@ export declare const PlayerInternals: {
13
14
  frameBack: (frames: number) => void;
14
15
  frameForward: (frames: number) => void;
15
16
  isLastFrame: boolean;
17
+ isFirstFrame: boolean;
16
18
  emitter: PlayerEmitter;
17
19
  playing: boolean;
18
20
  play: (e?: import("react").SyntheticEvent<Element, Event> | undefined) => void;
19
21
  pause: () => void;
22
+ pauseAndReturnToPlayStart: () => void;
20
23
  seek: (newFrame: number) => void;
21
24
  getCurrentFrame: () => number;
22
25
  isPlaying: () => boolean;
26
+ hasPlayed: boolean;
23
27
  };
24
- usePlayback: ({ loop, playbackRate, }: {
28
+ usePlayback: ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, outFrame, }: {
25
29
  loop: boolean;
26
30
  playbackRate: number;
31
+ moveToBeginningWhenEnded: boolean;
32
+ inFrame: number | null;
33
+ outFrame: number | null;
27
34
  }) => void;
28
35
  useElementSize: (ref: import("react").RefObject<HTMLElement>, options: {
29
36
  triggerOnWindowResize: boolean;
30
37
  shouldApplyCssTransforms: boolean;
31
38
  }) => import("./utils/use-element-size").Size | null;
32
- calculateScale: ({ previewSize, compositionWidth, compositionHeight, canvasSize, }: {
33
- previewSize: import("./utils/preview-size").PreviewSize;
39
+ calculateCanvasTransformation: ({ previewSize, compositionWidth, compositionHeight, canvasSize, }: {
40
+ previewSize: number | "auto";
34
41
  compositionWidth: number;
35
42
  compositionHeight: number;
36
43
  canvasSize: import("./utils/use-element-size").Size;
@@ -43,4 +50,10 @@ export declare const PlayerInternals: {
43
50
  };
44
51
  useHoverState: (ref: import("react").RefObject<HTMLDivElement>) => boolean;
45
52
  updateAllElementsSizes: () => void;
53
+ calculateScale: ({ canvasSize, compositionHeight, compositionWidth, previewSize, }: {
54
+ previewSize: number | "auto";
55
+ compositionWidth: number;
56
+ compositionHeight: number;
57
+ canvasSize: import("./utils/use-element-size").Size;
58
+ }) => number;
46
59
  };
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
  };
@@ -1,5 +1,5 @@
1
- import { SyntheticEvent } from 'react';
2
- import { PlayerEmitter } from './event-emitter';
1
+ import type { SyntheticEvent } from 'react';
2
+ import type { PlayerEmitter } from './event-emitter';
3
3
  export declare type PlayerMethods = {
4
4
  play: (e?: SyntheticEvent) => void;
5
5
  pause: () => void;
@@ -1,6 +1,6 @@
1
- import { queries, RenderOptions } from '@testing-library/react';
2
- import { FC, ReactElement } from 'react';
1
+ import type { queries, RenderOptions } from '@testing-library/react';
2
+ import type { FC, ReactElement } from 'react';
3
3
  declare const HelloWorld: FC;
4
- declare const customRender: (ui: ReactElement, options?: Omit<RenderOptions<typeof queries, HTMLElement, HTMLElement>, "queries"> | undefined) => import("@testing-library/react").RenderResult<typeof queries, HTMLElement, HTMLElement>;
4
+ declare const customRender: (ui: ReactElement, options?: Omit<RenderOptions, 'queries'>) => import("@testing-library/react").RenderResult<typeof queries, HTMLElement, HTMLElement>;
5
5
  export * from '@testing-library/react';
6
6
  export { customRender as render, HelloWorld };
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -14,14 +18,14 @@ exports.HelloWorld = exports.render = void 0;
14
18
  const jsx_runtime_1 = require("react/jsx-runtime");
15
19
  const react_1 = require("@testing-library/react");
16
20
  const HelloWorld = () => {
17
- return (0, jsx_runtime_1.jsx)("div", { children: "Hello World" }, void 0);
21
+ return (0, jsx_runtime_1.jsx)("div", { children: "Hello World" });
18
22
  };
19
23
  exports.HelloWorld = HelloWorld;
20
24
  const AllTheProviders = ({ children }) => {
21
25
  // overwriting console.error console does not gets poluted with all the errors
22
26
  // eslint-disable-next-line @typescript-eslint/no-empty-function
23
27
  window.console.error = () => { };
24
- return (0, jsx_runtime_1.jsx)("div", { children: children }, void 0);
28
+ return (0, jsx_runtime_1.jsx)("div", { children: children });
25
29
  };
26
30
  const customRender = (ui, options) => (0, react_1.render)(ui, { wrapper: AllTheProviders, ...options });
27
31
  exports.render = customRender;
@@ -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
+ });
@@ -10,7 +10,7 @@ test('no compositionWidth should give errors', () => {
10
10
  // @ts-expect-error
11
11
  , {
12
12
  // @ts-expect-error
13
- compositionWidth: null, errorFallback: () => 'something went wrong', compositionHeight: 400, fps: 30, durationInFrames: 500, component: test_utils_1.HelloWorld, controls: true, showVolumeControls: true }, void 0));
13
+ compositionWidth: null, errorFallback: () => 'something went wrong', compositionHeight: 400, fps: 30, durationInFrames: 500, component: test_utils_1.HelloWorld, controls: true, showVolumeControls: true }));
14
14
  }
15
15
  catch (e) {
16
16
  expect(e.message).toMatch(/'compositionWidth' must be a number but got 'object' instead/);
@@ -20,7 +20,7 @@ test('no compositionHeight should give errors', () => {
20
20
  try {
21
21
  (0, test_utils_1.render)((0, jsx_runtime_1.jsx)(index_1.Player, { compositionWidth: 400, errorFallback: () => 'something went wrong',
22
22
  // @ts-expect-error
23
- compositionHeight: undefined, fps: 30, durationInFrames: 500, component: test_utils_1.HelloWorld, controls: true, showVolumeControls: true }, void 0));
23
+ compositionHeight: undefined, fps: 30, durationInFrames: 500, component: test_utils_1.HelloWorld, controls: true, showVolumeControls: true }));
24
24
  }
25
25
  catch (e) {
26
26
  expect(e.message).toMatch(/'compositionHeight' must be a number but got 'undefined' instead/);
@@ -30,7 +30,7 @@ test('No fps should give errors', () => {
30
30
  try {
31
31
  (0, test_utils_1.render)((0, jsx_runtime_1.jsx)(index_1.Player, { compositionWidth: 500, compositionHeight: 400, errorFallback: () => 'something went wrong',
32
32
  // @ts-expect-error
33
- fps: null, durationInFrames: 500, component: test_utils_1.HelloWorld, controls: true, showVolumeControls: true }, void 0));
33
+ fps: null, durationInFrames: 500, component: test_utils_1.HelloWorld, controls: true, showVolumeControls: true }));
34
34
  }
35
35
  catch (e) {
36
36
  expect(e.message).toMatch(/"fps" must be a number, but you passed a value of type object/);
@@ -38,7 +38,7 @@ test('No fps should give errors', () => {
38
38
  try {
39
39
  (0, test_utils_1.render)((0, jsx_runtime_1.jsx)(index_1.Player, { compositionWidth: 500, compositionHeight: 400, errorFallback: () => 'something went wrong',
40
40
  // @ts-expect-error
41
- fps: undefined, durationInFrames: 500, component: test_utils_1.HelloWorld, controls: true, showVolumeControls: true }, void 0));
41
+ fps: undefined, durationInFrames: 500, component: test_utils_1.HelloWorld, controls: true, showVolumeControls: true }));
42
42
  }
43
43
  catch (e) {
44
44
  expect(e.message).toMatch(/"fps" must be a number, but you passed a value of type undefined/);
@@ -48,15 +48,15 @@ test('No durationInFrames should give errors', () => {
48
48
  try {
49
49
  (0, test_utils_1.render)((0, jsx_runtime_1.jsx)(index_1.Player, { compositionWidth: 500, compositionHeight: 400, errorFallback: () => 'something went wrong', fps: 30,
50
50
  // @ts-expect-error
51
- durationInFrames: undefined, component: test_utils_1.HelloWorld, controls: true, showVolumeControls: true }, void 0));
51
+ durationInFrames: undefined, component: test_utils_1.HelloWorld, controls: true, showVolumeControls: true }));
52
52
  }
53
53
  catch (e) {
54
- expect(e.message).toMatch(/The "durationInFrames" prop of the <Player\/> component must be a number, but you passed a value of type undefined/);
54
+ expect(e.message).toMatch(/durationInFrames` must be a number, but is undefined/);
55
55
  }
56
56
  });
57
57
  test('Invalid playbackRate should give error', () => {
58
58
  try {
59
- (0, test_utils_1.render)((0, jsx_runtime_1.jsx)(index_1.Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: test_utils_1.HelloWorld, controls: true, showVolumeControls: true, playbackRate: -5 }, void 0));
59
+ (0, test_utils_1.render)((0, jsx_runtime_1.jsx)(index_1.Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: test_utils_1.HelloWorld, controls: true, showVolumeControls: true, playbackRate: -5 }));
60
60
  }
61
61
  catch (e) {
62
62
  expect(e.message).toMatch(/The lowest possible playback rate is -4. You passed: -5/);
@@ -64,7 +64,7 @@ test('Invalid playbackRate should give error', () => {
64
64
  });
65
65
  test('playbackRate of 0 should not be possible', () => {
66
66
  try {
67
- (0, test_utils_1.render)((0, jsx_runtime_1.jsx)(index_1.Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: test_utils_1.HelloWorld, controls: true, showVolumeControls: true, playbackRate: 0 }, void 0));
67
+ (0, test_utils_1.render)((0, jsx_runtime_1.jsx)(index_1.Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: test_utils_1.HelloWorld, controls: true, showVolumeControls: true, playbackRate: 0 }));
68
68
  }
69
69
  catch (e) {
70
70
  expect(e.message).toMatch(/A playback rate of 0 is not supported./);
@@ -74,14 +74,14 @@ test('playbackRate of wrong type should not be possible', () => {
74
74
  try {
75
75
  (0, test_utils_1.render)((0, jsx_runtime_1.jsx)(index_1.Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: test_utils_1.HelloWorld, controls: true, showVolumeControls: true,
76
76
  // @ts-expect-error
77
- playbackRate: 'hi' }, void 0));
77
+ playbackRate: 'hi' }));
78
78
  }
79
79
  catch (e) {
80
80
  expect(e.message).toMatch(/A playback rate of 0 is not supported./);
81
81
  }
82
82
  });
83
83
  test('playbackRate of undefined should be okay', () => {
84
- (0, test_utils_1.render)((0, jsx_runtime_1.jsx)(index_1.Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: test_utils_1.HelloWorld, controls: true, showVolumeControls: true }, void 0));
84
+ (0, test_utils_1.render)((0, jsx_runtime_1.jsx)(index_1.Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: test_utils_1.HelloWorld, controls: true, showVolumeControls: true }));
85
85
  expect(true).toBe(true);
86
86
  });
87
87
  test('passing in <Composition /> instance should not be possible', () => {
@@ -93,21 +93,21 @@ test('passing in <Composition /> instance should not be possible', () => {
93
93
  fps: 30,
94
94
  durationInFrames: 500,
95
95
  component: test_utils_1.HelloWorld,
96
- } }, void 0));
96
+ } }));
97
97
  }).toThrow(/'component' must not be the 'Composition' component\. Pass your own React/);
98
98
  });
99
99
  test('passing in <Composition /> instance should not be possible', () => {
100
100
  expect(() => {
101
101
  (0, test_utils_1.render)((0, jsx_runtime_1.jsx)(index_1.Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500,
102
102
  // @ts-expect-error
103
- component: (0, jsx_runtime_1.jsx)(remotion_1.Composition, { durationInFrames: 30, fps: 30, height: 10, width: 10, id: "hello", component: test_utils_1.HelloWorld }, void 0), controls: true, showVolumeControls: true, inputProps: {
103
+ component: (0, jsx_runtime_1.jsx)(remotion_1.Composition, { durationInFrames: 30, fps: 30, height: 10, width: 10, id: "hello", component: test_utils_1.HelloWorld }), controls: true, showVolumeControls: true, inputProps: {
104
104
  id: 'HelloWorld',
105
105
  width: 500,
106
106
  height: 400,
107
107
  fps: 30,
108
108
  durationInFrames: 500,
109
109
  component: test_utils_1.HelloWorld,
110
- } }, void 0));
110
+ } }));
111
111
  }).toThrow(/'component' should not be an instance of <Composition\/>\. Pass the React component dir/);
112
112
  });
113
113
  test.each([
@@ -122,7 +122,7 @@ test.each([
122
122
  const props = {};
123
123
  props[a] = 'hey';
124
124
  try {
125
- (0, test_utils_1.render)((0, jsx_runtime_1.jsx)(index_1.Player, { compositionWidth: 500, compositionHeight: 400, errorFallback: () => 'something went wrong', fps: 30, durationInFrames: 100, component: test_utils_1.HelloWorld, ...props }, void 0));
125
+ (0, test_utils_1.render)((0, jsx_runtime_1.jsx)(index_1.Player, { compositionWidth: 500, compositionHeight: 400, errorFallback: () => 'something went wrong', fps: 30, durationInFrames: 100, component: test_utils_1.HelloWorld, ...props }));
126
126
  }
127
127
  catch (e) {
128
128
  expect(e.message).toMatch(`'${a}' must be a boolean or undefined but got 'string' instead`);
@@ -1,4 +1,7 @@
1
- export declare const usePlayback: ({ loop, playbackRate, }: {
1
+ export declare const usePlayback: ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, outFrame, }: {
2
2
  loop: boolean;
3
3
  playbackRate: number;
4
+ moveToBeginningWhenEnded: boolean;
5
+ inFrame: number | null;
6
+ outFrame: number | null;
4
7
  }) => void;
@@ -5,12 +5,11 @@ const react_1 = require("react");
5
5
  const remotion_1 = require("remotion");
6
6
  const calculate_next_frame_1 = require("./calculate-next-frame");
7
7
  const use_player_1 = require("./use-player");
8
- const usePlayback = ({ loop, playbackRate, }) => {
8
+ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, outFrame, }) => {
9
9
  const frame = remotion_1.Internals.Timeline.useTimelinePosition();
10
10
  const config = remotion_1.Internals.useUnsafeVideoConfig();
11
11
  const { playing, pause, emitter } = (0, use_player_1.usePlayer)();
12
12
  const setFrame = remotion_1.Internals.Timeline.useTimelineSetFrame();
13
- const { inFrame, outFrame } = remotion_1.Internals.Timeline.useTimelineInOutFramePosition();
14
13
  const frameRef = (0, react_1.useRef)(frame);
15
14
  frameRef.current = frame;
16
15
  const lastTimeUpdateEvent = (0, react_1.useRef)(null);
@@ -46,7 +45,8 @@ const usePlayback = ({ loop, playbackRate, }) => {
46
45
  shouldLoop: loop,
47
46
  });
48
47
  framesAdvanced += framesToAdvance;
49
- if (nextFrame !== frameRef.current) {
48
+ if (nextFrame !== frameRef.current &&
49
+ (!hasEnded || moveToBeginningWhenEnded)) {
50
50
  setFrame(nextFrame);
51
51
  }
52
52
  if (hasEnded) {
@@ -73,6 +73,7 @@ const usePlayback = ({ loop, playbackRate, }) => {
73
73
  playbackRate,
74
74
  inFrame,
75
75
  outFrame,
76
+ moveToBeginningWhenEnded,
76
77
  ]);
77
78
  (0, react_1.useEffect)(() => {
78
79
  const interval = setInterval(() => {
@@ -1,14 +1,19 @@
1
- import { SyntheticEvent } from 'react';
2
- import { PlayerEmitter } from './event-emitter';
3
- export declare const usePlayer: () => {
1
+ import type { SyntheticEvent } from 'react';
2
+ import type { PlayerEmitter } from './event-emitter';
3
+ declare type UsePlayerMethods = {
4
4
  frameBack: (frames: number) => void;
5
5
  frameForward: (frames: number) => void;
6
6
  isLastFrame: boolean;
7
+ isFirstFrame: boolean;
7
8
  emitter: PlayerEmitter;
8
9
  playing: boolean;
9
- play: (e?: SyntheticEvent<Element, Event> | undefined) => void;
10
+ play: (e?: SyntheticEvent) => void;
10
11
  pause: () => void;
12
+ pauseAndReturnToPlayStart: () => void;
11
13
  seek: (newFrame: number) => void;
12
14
  getCurrentFrame: () => number;
13
15
  isPlaying: () => boolean;
16
+ hasPlayed: boolean;
14
17
  };
18
+ export declare const usePlayer: () => UsePlayerMethods;
19
+ export {};
@@ -7,7 +7,9 @@ const emitter_context_1 = require("./emitter-context");
7
7
  const usePlayer = () => {
8
8
  var _a;
9
9
  const [playing, setPlaying, imperativePlaying] = remotion_1.Internals.Timeline.usePlayingState();
10
+ const [hasPlayed, setHasPlayed] = (0, react_1.useState)(false);
10
11
  const frame = remotion_1.Internals.Timeline.useTimelinePosition();
12
+ const playStart = (0, react_1.useRef)(frame);
11
13
  const setFrame = remotion_1.Internals.Timeline.useTimelineSetFrame();
12
14
  const setTimelinePosition = remotion_1.Internals.Timeline.useTimelineSetFrame();
13
15
  const audioContext = (0, react_1.useContext)(remotion_1.Internals.SharedAudioContext);
@@ -19,6 +21,7 @@ const usePlayer = () => {
19
21
  const emitter = (0, react_1.useContext)(emitter_context_1.PlayerEventEmitterContext);
20
22
  const lastFrame = ((_a = config === null || config === void 0 ? void 0 : config.durationInFrames) !== null && _a !== void 0 ? _a : 1) - 1;
21
23
  const isLastFrame = frame === lastFrame;
24
+ const isFirstFrame = frame === 0;
22
25
  if (!emitter) {
23
26
  throw new TypeError('Expected Player event emitter context');
24
27
  }
@@ -30,6 +33,7 @@ const usePlayer = () => {
30
33
  if (imperativePlaying.current) {
31
34
  return;
32
35
  }
36
+ setHasPlayed(true);
33
37
  if (isLastFrame) {
34
38
  seek(0);
35
39
  }
@@ -46,6 +50,7 @@ const usePlayer = () => {
46
50
  audioAndVideoTags.current.forEach((a) => a.play());
47
51
  imperativePlaying.current = true;
48
52
  setPlaying(true);
53
+ playStart.current = frameRef.current;
49
54
  emitter.dispatchPlay();
50
55
  }, [
51
56
  imperativePlaying,
@@ -63,6 +68,14 @@ const usePlayer = () => {
63
68
  emitter.dispatchPause();
64
69
  }
65
70
  }, [emitter, imperativePlaying, setPlaying]);
71
+ const pauseAndReturnToPlayStart = (0, react_1.useCallback)(() => {
72
+ if (imperativePlaying.current) {
73
+ imperativePlaying.current = false;
74
+ setTimelinePosition(playStart.current);
75
+ setPlaying(false);
76
+ emitter.dispatchPause();
77
+ }
78
+ }, [emitter, imperativePlaying, setPlaying, setTimelinePosition]);
66
79
  const hasVideo = Boolean(video);
67
80
  const frameBack = (0, react_1.useCallback)((frames) => {
68
81
  if (!hasVideo) {
@@ -94,19 +107,25 @@ const usePlayer = () => {
94
107
  play,
95
108
  pause,
96
109
  seek,
110
+ isFirstFrame,
97
111
  getCurrentFrame: () => frameRef.current,
98
112
  isPlaying: () => imperativePlaying.current,
113
+ pauseAndReturnToPlayStart,
114
+ hasPlayed,
99
115
  };
100
116
  }, [
101
- emitter,
102
117
  frameBack,
103
118
  frameForward,
104
- imperativePlaying,
105
119
  isLastFrame,
106
- pause,
107
- play,
120
+ emitter,
108
121
  playing,
122
+ play,
123
+ pause,
109
124
  seek,
125
+ isFirstFrame,
126
+ pauseAndReturnToPlayStart,
127
+ imperativePlaying,
128
+ hasPlayed,
110
129
  ]);
111
130
  return returnValue;
112
131
  };
@@ -1,5 +1,5 @@
1
- import { StandardLonghandProperties } from 'csstype';
2
- import { Size } from './use-element-size';
1
+ import type { StandardLonghandProperties } from 'csstype';
2
+ import type { Size } from './use-element-size';
3
3
  export declare const calculatePlayerSize: ({ currentSize, width, height, compositionWidth, compositionHeight, }: {
4
4
  currentSize: Size | null;
5
5
  width: StandardLonghandProperties['width'] | undefined;
@@ -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
+ };
@@ -1,4 +1,4 @@
1
- import { CancellablePromise } from './cancellable-promise';
1
+ import type { CancellablePromise } from './cancellable-promise';
2
2
  declare const useCancellablePromises: () => {
3
3
  appendPendingPromise: (promise: CancellablePromise) => void;
4
4
  removePendingPromise: (promise: CancellablePromise) => void;
@@ -1,3 +1,3 @@
1
- import { SyntheticEvent } from 'react';
1
+ import type { SyntheticEvent } from 'react';
2
2
  declare const useClickPreventionOnDoubleClick: (onClick: (e: SyntheticEvent) => void, onDoubleClick: () => void, doubleClickToFullscreen: boolean) => [(e: SyntheticEvent) => void, () => void];
3
3
  export { useClickPreventionOnDoubleClick };
@@ -3,6 +3,10 @@ export declare type Size = {
3
3
  height: number;
4
4
  left: number;
5
5
  top: number;
6
+ windowSize: {
7
+ width: number;
8
+ height: number;
9
+ };
6
10
  };
7
11
  export declare const updateAllElementsSizes: () => void;
8
12
  export declare const useElementSize: (ref: React.RefObject<HTMLElement>, options: {
@@ -36,6 +36,10 @@ const useElementSize = (ref, options) => {
36
36
  height,
37
37
  left: newSize[0].x,
38
38
  top: newSize[0].y,
39
+ windowSize: {
40
+ height: window.innerHeight,
41
+ width: window.innerWidth,
42
+ },
39
43
  });
40
44
  });
41
45
  }, [options.shouldApplyCssTransforms]);
@@ -53,6 +57,10 @@ const useElementSize = (ref, options) => {
53
57
  height: rect[0].height,
54
58
  left: rect[0].x,
55
59
  top: rect[0].y,
60
+ windowSize: {
61
+ height: window.innerHeight,
62
+ width: window.innerWidth,
63
+ },
56
64
  });
57
65
  }, [ref]);
58
66
  (0, react_1.useEffect)(() => {
@@ -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;
@@ -0,0 +1,4 @@
1
+ export declare const validateInitialFrame: ({ initialFrame, durationInFrames, }: {
2
+ initialFrame: unknown;
3
+ durationInFrames: unknown;
4
+ }) => void;