@remotion/player 4.0.0-alpha.4 → 4.0.0-alpha4

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 (208) hide show
  1. package/LICENSE.md +8 -8
  2. package/README.md +1 -1
  3. package/dist/cjs/MediaVolumeSlider.d.ts +5 -0
  4. package/dist/cjs/MediaVolumeSlider.js +143 -0
  5. package/dist/{Player.d.ts → cjs/Player.d.ts} +21 -13
  6. package/dist/{Player.js → cjs/Player.js} +42 -78
  7. package/dist/{PlayerControls.d.ts → cjs/PlayerControls.d.ts} +17 -2
  8. package/dist/cjs/PlayerControls.js +153 -0
  9. package/dist/{PlayerSeekBar.d.ts → cjs/PlayerSeekBar.d.ts} +4 -0
  10. package/dist/{PlayerSeekBar.js → cjs/PlayerSeekBar.js} +41 -17
  11. package/dist/cjs/PlayerUI.d.ts +39 -0
  12. package/dist/{PlayerUI.js → cjs/PlayerUI.js} +105 -87
  13. package/dist/cjs/SharedPlayerContext.d.ts +15 -0
  14. package/dist/cjs/SharedPlayerContext.js +72 -0
  15. package/dist/cjs/Thumbnail.d.ts +24 -0
  16. package/dist/cjs/Thumbnail.js +46 -0
  17. package/dist/cjs/ThumbnailUI.d.ts +11 -0
  18. package/dist/cjs/ThumbnailUI.js +107 -0
  19. package/dist/{calculate-next-frame.d.ts → cjs/calculate-next-frame.d.ts} +0 -0
  20. package/dist/{calculate-next-frame.js → cjs/calculate-next-frame.js} +0 -0
  21. package/dist/cjs/calculate-scale.d.ts +39 -0
  22. package/dist/cjs/calculate-scale.js +85 -0
  23. package/dist/cjs/emitter-context.d.ts +4 -0
  24. package/dist/{emitter-context.js → cjs/emitter-context.js} +2 -1
  25. package/dist/{error-boundary.d.ts → cjs/error-boundary.d.ts} +0 -0
  26. package/dist/{error-boundary.js → cjs/error-boundary.js} +0 -0
  27. package/dist/cjs/event-emitter.d.ts +76 -0
  28. package/dist/{event-emitter.js → cjs/event-emitter.js} +46 -2
  29. package/dist/{format-time.d.ts → cjs/format-time.d.ts} +0 -0
  30. package/dist/{format-time.js → cjs/format-time.js} +0 -0
  31. package/dist/{icons.d.ts → cjs/icons.d.ts} +2 -1
  32. package/dist/{icons.js → cjs/icons.js} +7 -7
  33. package/dist/{index.d.ts → cjs/index.d.ts} +22 -12
  34. package/dist/cjs/index.js +25 -0
  35. package/dist/cjs/is-backgrounded.d.ts +2 -0
  36. package/dist/cjs/is-backgrounded.js +24 -0
  37. package/dist/{player-css-classname.d.ts → cjs/player-css-classname.d.ts} +0 -1
  38. package/dist/cjs/player-css-classname.js +4 -0
  39. package/dist/{player-methods.d.ts → cjs/player-methods.d.ts} +8 -4
  40. package/dist/{player-methods.js → cjs/player-methods.js} +0 -0
  41. package/dist/{test → cjs/test}/index.test.d.ts +0 -0
  42. package/dist/cjs/test/index.test.js +9 -0
  43. package/dist/{test → cjs/test}/test-utils.d.ts +0 -0
  44. package/dist/{test → cjs/test}/test-utils.js +0 -0
  45. package/dist/{test/validate-prop.test.d.ts → cjs/test/validate-in-out-frames.test.d.ts} +0 -0
  46. package/dist/cjs/test/validate-in-out-frames.test.js +56 -0
  47. package/dist/cjs/test/validate-prop.test.d.ts +1 -0
  48. package/dist/cjs/test/validate-prop.test.js +131 -0
  49. package/dist/{use-hover-state.d.ts → cjs/use-hover-state.d.ts} +0 -0
  50. package/dist/{use-hover-state.js → cjs/use-hover-state.js} +0 -0
  51. package/dist/{use-playback.d.ts → cjs/use-playback.d.ts} +0 -0
  52. package/dist/{use-playback.js → cjs/use-playback.js} +49 -9
  53. package/dist/{use-player.d.ts → cjs/use-player.d.ts} +3 -1
  54. package/dist/{use-player.js → cjs/use-player.js} +15 -8
  55. package/dist/cjs/use-thumbnail.d.ts +6 -0
  56. package/dist/cjs/use-thumbnail.js +18 -0
  57. package/dist/cjs/use-video-controls-resize.d.ts +11 -0
  58. package/dist/cjs/use-video-controls-resize.js +39 -0
  59. package/dist/{utils → cjs/utils}/calculate-player-size.d.ts +1 -1
  60. package/dist/{utils → cjs/utils}/calculate-player-size.js +9 -10
  61. package/dist/{utils → cjs/utils}/cancellable-promise.d.ts +0 -0
  62. package/dist/{utils → cjs/utils}/cancellable-promise.js +0 -0
  63. package/dist/{utils → cjs/utils}/delay.d.ts +0 -0
  64. package/dist/{utils → cjs/utils}/delay.js +0 -0
  65. package/dist/{utils → cjs/utils}/is-node.d.ts +0 -0
  66. package/dist/{utils → cjs/utils}/is-node.js +0 -0
  67. package/dist/cjs/utils/preview-size.d.ts +8 -0
  68. package/dist/{utils → cjs/utils}/preview-size.js +0 -0
  69. package/dist/cjs/utils/props-if-has-props.d.ts +5 -0
  70. package/dist/cjs/utils/props-if-has-props.js +2 -0
  71. package/dist/{utils → cjs/utils}/use-cancellable-promises.d.ts +1 -1
  72. package/dist/{utils → cjs/utils}/use-cancellable-promises.js +0 -0
  73. package/dist/{utils → cjs/utils}/use-click-prevention-on-double-click.d.ts +0 -0
  74. package/dist/{utils → cjs/utils}/use-click-prevention-on-double-click.js +5 -5
  75. package/dist/{utils → cjs/utils}/use-element-size.d.ts +1 -0
  76. package/dist/{utils → cjs/utils}/use-element-size.js +24 -12
  77. package/dist/cjs/utils/validate-in-out-frame.d.ts +6 -0
  78. package/dist/cjs/utils/validate-in-out-frame.js +54 -0
  79. package/dist/cjs/utils/validate-initial-frame.d.ts +4 -0
  80. package/dist/cjs/utils/validate-initial-frame.js +27 -0
  81. package/dist/{utils → cjs/utils}/validate-playbackrate.d.ts +0 -0
  82. package/dist/{utils → cjs/utils}/validate-playbackrate.js +0 -0
  83. package/dist/{volume-persistance.d.ts → cjs/volume-persistance.d.ts} +0 -0
  84. package/dist/{volume-persistance.js → cjs/volume-persistance.js} +0 -0
  85. package/dist/esm/MediaVolumeSlider.d.ts +5 -0
  86. package/dist/esm/Player.d.ts +49 -0
  87. package/dist/esm/PlayerControls.d.ts +40 -0
  88. package/dist/esm/PlayerSeekBar.d.ts +8 -0
  89. package/dist/esm/PlayerUI.d.ts +39 -0
  90. package/dist/esm/SharedPlayerContext.d.ts +15 -0
  91. package/dist/esm/Thumbnail.d.ts +24 -0
  92. package/dist/esm/ThumbnailUI.d.ts +11 -0
  93. package/dist/esm/calculate-next-frame.d.ts +14 -0
  94. package/dist/esm/calculate-scale.d.ts +39 -0
  95. package/dist/esm/emitter-context.d.ts +4 -0
  96. package/dist/esm/error-boundary.d.ts +19 -0
  97. package/dist/esm/event-emitter.d.ts +76 -0
  98. package/dist/esm/format-time.d.ts +1 -0
  99. package/dist/esm/icons.d.ts +10 -0
  100. package/dist/esm/index.d.ts +61 -0
  101. package/dist/esm/index.mjs +1928 -0
  102. package/dist/esm/is-backgrounded.d.ts +2 -0
  103. package/dist/esm/player-css-classname.d.ts +1 -0
  104. package/dist/esm/player-methods.d.ts +24 -0
  105. package/dist/esm/test/index.test.d.ts +1 -0
  106. package/dist/esm/test/test-utils.d.ts +6 -0
  107. package/dist/esm/test/validate-in-out-frames.test.d.ts +1 -0
  108. package/dist/esm/test/validate-prop.test.d.ts +1 -0
  109. package/dist/esm/use-hover-state.d.ts +1 -0
  110. package/dist/esm/use-playback.d.ts +7 -0
  111. package/dist/esm/use-player.d.ts +19 -0
  112. package/dist/esm/use-thumbnail.d.ts +6 -0
  113. package/dist/esm/use-video-controls-resize.d.ts +11 -0
  114. package/dist/esm/utils/calculate-player-size.d.ts +9 -0
  115. package/dist/esm/utils/cancellable-promise.d.ts +5 -0
  116. package/dist/esm/utils/delay.d.ts +1 -0
  117. package/dist/esm/utils/is-node.d.ts +1 -0
  118. package/dist/esm/utils/preview-size.d.ts +8 -0
  119. package/dist/esm/utils/props-if-has-props.d.ts +5 -0
  120. package/dist/esm/utils/use-cancellable-promises.d.ts +7 -0
  121. package/dist/esm/utils/use-click-prevention-on-double-click.d.ts +3 -0
  122. package/dist/esm/utils/use-element-size.d.ts +16 -0
  123. package/dist/esm/utils/validate-in-out-frame.d.ts +6 -0
  124. package/dist/esm/utils/validate-initial-frame.d.ts +4 -0
  125. package/dist/esm/utils/validate-playbackrate.d.ts +1 -0
  126. package/dist/esm/volume-persistance.d.ts +2 -0
  127. package/dist/tsconfig-esm.tsbuildinfo +1 -0
  128. package/dist/tsconfig.tsbuildinfo +1 -0
  129. package/package.json +77 -66
  130. package/dist/MediaVolumeSlider.d.ts +0 -2
  131. package/dist/MediaVolumeSlider.d.ts.map +0 -1
  132. package/dist/MediaVolumeSlider.js +0 -93
  133. package/dist/MediaVolumeSlider.js.map +0 -1
  134. package/dist/Player.d.ts.map +0 -1
  135. package/dist/Player.js.map +0 -1
  136. package/dist/PlayerControls.d.ts.map +0 -1
  137. package/dist/PlayerControls.js +0 -95
  138. package/dist/PlayerControls.js.map +0 -1
  139. package/dist/PlayerSeekBar.d.ts.map +0 -1
  140. package/dist/PlayerSeekBar.js.map +0 -1
  141. package/dist/PlayerUI.d.ts +0 -31
  142. package/dist/PlayerUI.d.ts.map +0 -1
  143. package/dist/PlayerUI.js.map +0 -1
  144. package/dist/calculate-next-frame.d.ts.map +0 -1
  145. package/dist/calculate-next-frame.js.map +0 -1
  146. package/dist/calculate-scale.d.ts +0 -14
  147. package/dist/calculate-scale.d.ts.map +0 -1
  148. package/dist/calculate-scale.js +0 -24
  149. package/dist/calculate-scale.js.map +0 -1
  150. package/dist/emitter-context.d.ts +0 -3
  151. package/dist/emitter-context.d.ts.map +0 -1
  152. package/dist/emitter-context.js.map +0 -1
  153. package/dist/error-boundary.d.ts.map +0 -1
  154. package/dist/error-boundary.js.map +0 -1
  155. package/dist/event-emitter.d.ts +0 -42
  156. package/dist/event-emitter.d.ts.map +0 -1
  157. package/dist/event-emitter.js.map +0 -1
  158. package/dist/format-time.d.ts.map +0 -1
  159. package/dist/format-time.js.map +0 -1
  160. package/dist/icons.d.ts.map +0 -1
  161. package/dist/icons.js.map +0 -1
  162. package/dist/index.d.ts.map +0 -1
  163. package/dist/index.js +0 -22
  164. package/dist/index.js.map +0 -1
  165. package/dist/player-css-classname.d.ts.map +0 -1
  166. package/dist/player-css-classname.js +0 -5
  167. package/dist/player-css-classname.js.map +0 -1
  168. package/dist/player-methods.d.ts.map +0 -1
  169. package/dist/player-methods.js.map +0 -1
  170. package/dist/test/index.test.d.ts.map +0 -1
  171. package/dist/test/index.test.js +0 -8
  172. package/dist/test/index.test.js.map +0 -1
  173. package/dist/test/test-utils.d.ts.map +0 -1
  174. package/dist/test/test-utils.js.map +0 -1
  175. package/dist/test/validate-prop.test.d.ts.map +0 -1
  176. package/dist/test/validate-prop.test.js +0 -130
  177. package/dist/test/validate-prop.test.js.map +0 -1
  178. package/dist/use-hover-state.d.ts.map +0 -1
  179. package/dist/use-hover-state.js.map +0 -1
  180. package/dist/use-playback.d.ts.map +0 -1
  181. package/dist/use-playback.js.map +0 -1
  182. package/dist/use-player.d.ts.map +0 -1
  183. package/dist/use-player.js.map +0 -1
  184. package/dist/utils/browser-supports-fullscreen.d.ts +0 -12
  185. package/dist/utils/browser-supports-fullscreen.d.ts.map +0 -1
  186. package/dist/utils/browser-supports-fullscreen.js +0 -6
  187. package/dist/utils/browser-supports-fullscreen.js.map +0 -1
  188. package/dist/utils/calculate-player-size.d.ts.map +0 -1
  189. package/dist/utils/calculate-player-size.js.map +0 -1
  190. package/dist/utils/cancellable-promise.d.ts.map +0 -1
  191. package/dist/utils/cancellable-promise.js.map +0 -1
  192. package/dist/utils/delay.d.ts.map +0 -1
  193. package/dist/utils/delay.js.map +0 -1
  194. package/dist/utils/is-node.d.ts.map +0 -1
  195. package/dist/utils/is-node.js.map +0 -1
  196. package/dist/utils/preview-size.d.ts +0 -1
  197. package/dist/utils/preview-size.d.ts.map +0 -1
  198. package/dist/utils/preview-size.js.map +0 -1
  199. package/dist/utils/use-cancellable-promises.d.ts.map +0 -1
  200. package/dist/utils/use-cancellable-promises.js.map +0 -1
  201. package/dist/utils/use-click-prevention-on-double-click.d.ts.map +0 -1
  202. package/dist/utils/use-click-prevention-on-double-click.js.map +0 -1
  203. package/dist/utils/use-element-size.d.ts.map +0 -1
  204. package/dist/utils/use-element-size.js.map +0 -1
  205. package/dist/utils/validate-playbackrate.d.ts.map +0 -1
  206. package/dist/utils/validate-playbackrate.js.map +0 -1
  207. package/dist/volume-persistance.d.ts.map +0 -1
  208. package/dist/volume-persistance.js.map +0 -1
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const validate_in_out_frame_js_1 = require("../utils/validate-in-out-frame.js");
5
+ (0, vitest_1.test)('Validate in out frames', () => {
6
+ (0, vitest_1.expect)(() => (0, validate_in_out_frame_js_1.validateInOutFrames)({
7
+ durationInFrames: 200,
8
+ inFrame: 201,
9
+ outFrame: undefined,
10
+ })).toThrow(/inFrame must be less than \(durationInFrames - 1\)/);
11
+ (0, vitest_1.expect)(() => (0, validate_in_out_frame_js_1.validateInOutFrames)({
12
+ durationInFrames: 200,
13
+ inFrame: 199,
14
+ outFrame: 201,
15
+ })).toThrow(/outFrame must be less than \(durationInFrames - 1\)/);
16
+ (0, vitest_1.expect)(() => (0, validate_in_out_frame_js_1.validateInOutFrames)({
17
+ durationInFrames: 200,
18
+ inFrame: -10,
19
+ outFrame: null,
20
+ })).toThrow(/inFrame must be greater than 0, but is -10/);
21
+ (0, vitest_1.expect)(() => (0, validate_in_out_frame_js_1.validateInOutFrames)({
22
+ durationInFrames: 200,
23
+ inFrame: null,
24
+ outFrame: -10,
25
+ })).toThrow(/outFrame must be greater than 0, but is -10/);
26
+ (0, vitest_1.expect)(() => (0, validate_in_out_frame_js_1.validateInOutFrames)({
27
+ durationInFrames: 200,
28
+ inFrame: 1.5,
29
+ outFrame: null,
30
+ })).toThrow(/"inFrame" must be an integer, but is 1.5/);
31
+ (0, vitest_1.expect)(() => (0, validate_in_out_frame_js_1.validateInOutFrames)({
32
+ durationInFrames: 200,
33
+ inFrame: 20,
34
+ outFrame: 20,
35
+ })).toThrow(/outFrame must be greater than inFrame, but is 20/);
36
+ (0, vitest_1.expect)(() => (0, validate_in_out_frame_js_1.validateInOutFrames)({
37
+ durationInFrames: 200,
38
+ inFrame: 21,
39
+ outFrame: 20,
40
+ })).toThrow(/outFrame must be greater than inFrame, but is 20 <= 21/);
41
+ (0, vitest_1.expect)(() => (0, validate_in_out_frame_js_1.validateInOutFrames)({
42
+ durationInFrames: 200,
43
+ inFrame: null,
44
+ outFrame: 20,
45
+ })).not.toThrow();
46
+ (0, vitest_1.expect)(() => (0, validate_in_out_frame_js_1.validateInOutFrames)({
47
+ durationInFrames: 200,
48
+ inFrame: null,
49
+ outFrame: null,
50
+ })).not.toThrow();
51
+ (0, vitest_1.expect)(() => (0, validate_in_out_frame_js_1.validateInOutFrames)({
52
+ durationInFrames: 200,
53
+ inFrame: 10,
54
+ outFrame: 20,
55
+ })).not.toThrow();
56
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const jsx_runtime_1 = require("react/jsx-runtime");
4
+ const remotion_1 = require("remotion");
5
+ const vitest_1 = require("vitest");
6
+ const index_js_1 = require("../index.js");
7
+ const test_utils_js_1 = require("./test-utils.js");
8
+ (0, vitest_1.test)('no compositionWidth should give errors', () => {
9
+ try {
10
+ (0, test_utils_js_1.render)((0, jsx_runtime_1.jsx)(index_js_1.Player
11
+ // @ts-expect-error
12
+ , {
13
+ // @ts-expect-error
14
+ compositionWidth: null, errorFallback: () => 'something went wrong', compositionHeight: 400, fps: 30, durationInFrames: 500, component: test_utils_js_1.HelloWorld, controls: true, showVolumeControls: true }));
15
+ }
16
+ catch (e) {
17
+ (0, vitest_1.expect)(e.message).toMatch(/'compositionWidth' must be a number but got 'object' instead/);
18
+ }
19
+ });
20
+ (0, vitest_1.test)('no compositionHeight should give errors', () => {
21
+ try {
22
+ (0, test_utils_js_1.render)((0, jsx_runtime_1.jsx)(index_js_1.Player, { compositionWidth: 400, errorFallback: () => 'something went wrong',
23
+ // @ts-expect-error
24
+ compositionHeight: undefined, fps: 30, durationInFrames: 500, component: test_utils_js_1.HelloWorld, controls: true, showVolumeControls: true }));
25
+ }
26
+ catch (e) {
27
+ (0, vitest_1.expect)(e.message).toMatch(/'compositionHeight' must be a number but got 'undefined' instead/);
28
+ }
29
+ });
30
+ (0, vitest_1.test)('No fps should give errors', () => {
31
+ try {
32
+ (0, test_utils_js_1.render)((0, jsx_runtime_1.jsx)(index_js_1.Player, { compositionWidth: 500, compositionHeight: 400, errorFallback: () => 'something went wrong',
33
+ // @ts-expect-error
34
+ fps: null, durationInFrames: 500, component: test_utils_js_1.HelloWorld, controls: true, showVolumeControls: true }));
35
+ }
36
+ catch (e) {
37
+ (0, vitest_1.expect)(e.message).toMatch(/"fps" must be a number, but you passed a value of type object/);
38
+ }
39
+ try {
40
+ (0, test_utils_js_1.render)((0, jsx_runtime_1.jsx)(index_js_1.Player, { compositionWidth: 500, compositionHeight: 400, errorFallback: () => 'something went wrong',
41
+ // @ts-expect-error
42
+ fps: undefined, durationInFrames: 500, component: test_utils_js_1.HelloWorld, controls: true, showVolumeControls: true }));
43
+ }
44
+ catch (e) {
45
+ (0, vitest_1.expect)(e.message).toMatch(/"fps" must be a number, but you passed a value of type undefined/);
46
+ }
47
+ });
48
+ (0, vitest_1.test)('No durationInFrames should give errors', () => {
49
+ try {
50
+ (0, test_utils_js_1.render)((0, jsx_runtime_1.jsx)(index_js_1.Player, { compositionWidth: 500, compositionHeight: 400, errorFallback: () => 'something went wrong', fps: 30,
51
+ // @ts-expect-error
52
+ durationInFrames: undefined, component: test_utils_js_1.HelloWorld, controls: true, showVolumeControls: true }));
53
+ }
54
+ catch (e) {
55
+ (0, vitest_1.expect)(e.message).toMatch(/durationInFrames` must be a number, but is undefined/);
56
+ }
57
+ });
58
+ (0, vitest_1.test)('Invalid playbackRate should give error', () => {
59
+ try {
60
+ (0, test_utils_js_1.render)((0, jsx_runtime_1.jsx)(index_js_1.Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: test_utils_js_1.HelloWorld, controls: true, showVolumeControls: true, playbackRate: -5 }));
61
+ }
62
+ catch (e) {
63
+ (0, vitest_1.expect)(e.message).toMatch(/The lowest possible playback rate is -4. You passed: -5/);
64
+ }
65
+ });
66
+ (0, vitest_1.test)('playbackRate of 0 should not be possible', () => {
67
+ try {
68
+ (0, test_utils_js_1.render)((0, jsx_runtime_1.jsx)(index_js_1.Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: test_utils_js_1.HelloWorld, controls: true, showVolumeControls: true, playbackRate: 0 }));
69
+ }
70
+ catch (e) {
71
+ (0, vitest_1.expect)(e.message).toMatch(/A playback rate of 0 is not supported./);
72
+ }
73
+ });
74
+ (0, vitest_1.test)('playbackRate of wrong type should not be possible', () => {
75
+ try {
76
+ (0, test_utils_js_1.render)((0, jsx_runtime_1.jsx)(index_js_1.Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: test_utils_js_1.HelloWorld, controls: true, showVolumeControls: true,
77
+ // @ts-expect-error
78
+ playbackRate: 'hi' }));
79
+ }
80
+ catch (e) {
81
+ (0, vitest_1.expect)(e.message).toMatch(/A playback rate of 0 is not supported./);
82
+ }
83
+ });
84
+ (0, vitest_1.test)('playbackRate of undefined should be okay', () => {
85
+ (0, test_utils_js_1.render)((0, jsx_runtime_1.jsx)(index_js_1.Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: test_utils_js_1.HelloWorld, controls: true, showVolumeControls: true }));
86
+ (0, vitest_1.expect)(true).toBe(true);
87
+ });
88
+ (0, vitest_1.test)('passing in <Composition /> instance should not be possible', () => {
89
+ (0, vitest_1.expect)(() => {
90
+ (0, test_utils_js_1.render)((0, jsx_runtime_1.jsx)(index_js_1.Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: remotion_1.Composition, controls: true, showVolumeControls: true, inputProps: {
91
+ id: 'HelloWorld',
92
+ width: 500,
93
+ height: 400,
94
+ fps: 30,
95
+ durationInFrames: 500,
96
+ component: test_utils_js_1.HelloWorld,
97
+ } }));
98
+ }).toThrow(/'component' must not be the 'Composition' component\. Pass your own React/);
99
+ });
100
+ (0, vitest_1.test)('passing in <Composition /> instance should not be possible', () => {
101
+ (0, vitest_1.expect)(() => {
102
+ (0, test_utils_js_1.render)((0, jsx_runtime_1.jsx)(index_js_1.Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500,
103
+ // @ts-expect-error
104
+ component: (0, jsx_runtime_1.jsx)(remotion_1.Composition, { durationInFrames: 30, fps: 30, height: 10, width: 10, id: "hello", component: test_utils_js_1.HelloWorld }), controls: true, showVolumeControls: true, inputProps: {
105
+ id: 'HelloWorld',
106
+ width: 500,
107
+ height: 400,
108
+ fps: 30,
109
+ durationInFrames: 500,
110
+ component: test_utils_js_1.HelloWorld,
111
+ } }));
112
+ }).toThrow(/'component' should not be an instance of <Composition\/>\. Pass the React component dir/);
113
+ });
114
+ vitest_1.test.each([
115
+ ['controls'],
116
+ ['loop'],
117
+ ['autoPlay'],
118
+ ['showVolumeControls'],
119
+ ['allowFullscreen'],
120
+ ['clickToPlay'],
121
+ ['doubleClickToFullscreen'],
122
+ ])('No durationInFrames should give errors %s', (a) => {
123
+ const props = {};
124
+ props[a] = 'hey';
125
+ try {
126
+ (0, test_utils_js_1.render)((0, jsx_runtime_1.jsx)(index_js_1.Player, { compositionWidth: 500, compositionHeight: 400, errorFallback: () => 'something went wrong', fps: 30, durationInFrames: 100, component: test_utils_js_1.HelloWorld, ...props }));
127
+ }
128
+ catch (e) {
129
+ (0, vitest_1.expect)(e.message).toMatch(`'${a}' must be a boolean or undefined but got 'string' instead`);
130
+ }
131
+ });
@@ -3,13 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.usePlayback = void 0;
4
4
  const react_1 = require("react");
5
5
  const remotion_1 = require("remotion");
6
- const calculate_next_frame_1 = require("./calculate-next-frame");
7
- const use_player_1 = require("./use-player");
6
+ const calculate_next_frame_js_1 = require("./calculate-next-frame.js");
7
+ const is_backgrounded_js_1 = require("./is-backgrounded.js");
8
+ const use_player_js_1 = require("./use-player.js");
8
9
  const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, outFrame, }) => {
9
10
  const frame = remotion_1.Internals.Timeline.useTimelinePosition();
10
11
  const config = remotion_1.Internals.useUnsafeVideoConfig();
11
- const { playing, pause, emitter } = (0, use_player_1.usePlayer)();
12
+ const { playing, pause, emitter } = (0, use_player_js_1.usePlayer)();
12
13
  const setFrame = remotion_1.Internals.Timeline.useTimelineSetFrame();
14
+ // requestAnimationFrame() does not work if the tab is not active.
15
+ // This means that audio will keep playing even if it has ended.
16
+ // In that case, we use setTimeout() instead.
17
+ const isBackgroundedRef = (0, is_backgrounded_js_1.useIsBackgrounded)();
13
18
  const frameRef = (0, react_1.useRef)(frame);
14
19
  frameRef.current = frame;
15
20
  const lastTimeUpdateEvent = (0, react_1.useRef)(null);
@@ -24,17 +29,25 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
24
29
  let reqAnimFrameCall = null;
25
30
  const startedTime = performance.now();
26
31
  let framesAdvanced = 0;
27
- const stop = () => {
28
- hasBeenStopped = true;
32
+ const cancelQueuedFrame = () => {
29
33
  if (reqAnimFrameCall !== null) {
30
- cancelAnimationFrame(reqAnimFrameCall);
34
+ if (reqAnimFrameCall.type === 'raf') {
35
+ cancelAnimationFrame(reqAnimFrameCall.id);
36
+ }
37
+ else {
38
+ clearTimeout(reqAnimFrameCall.id);
39
+ }
31
40
  }
32
41
  };
42
+ const stop = () => {
43
+ hasBeenStopped = true;
44
+ cancelQueuedFrame();
45
+ };
33
46
  const callback = () => {
34
47
  const time = performance.now() - startedTime;
35
48
  const actualLastFrame = outFrame !== null && outFrame !== void 0 ? outFrame : config.durationInFrames - 1;
36
49
  const actualFirstFrame = inFrame !== null && inFrame !== void 0 ? inFrame : 0;
37
- const { nextFrame, framesToAdvance, hasEnded } = (0, calculate_next_frame_1.calculateNextFrame)({
50
+ const { nextFrame, framesToAdvance, hasEnded } = (0, calculate_next_frame_js_1.calculateNextFrame)({
38
51
  time,
39
52
  currentFrame: frameRef.current,
40
53
  playbackSpeed: playbackRate,
@@ -56,11 +69,34 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
56
69
  return;
57
70
  }
58
71
  if (!hasBeenStopped) {
59
- reqAnimFrameCall = requestAnimationFrame(callback);
72
+ queueNextFrame();
73
+ }
74
+ };
75
+ const queueNextFrame = () => {
76
+ if (isBackgroundedRef.current) {
77
+ reqAnimFrameCall = {
78
+ type: 'timeout',
79
+ // Note: Most likely, this will not be 1000 / fps, but the browser will throttle it to ~1/sec.
80
+ id: setTimeout(callback, 1000 / config.fps),
81
+ };
82
+ }
83
+ else {
84
+ reqAnimFrameCall = { type: 'raf', id: requestAnimationFrame(callback) };
85
+ }
86
+ };
87
+ queueNextFrame();
88
+ const onVisibilityChange = () => {
89
+ if (document.visibilityState === 'visible') {
90
+ return;
60
91
  }
92
+ // If tab goes into the background, cancel requestAnimationFrame() and update immediately.
93
+ // , so the transition to setTimeout() can be fulfilled.
94
+ cancelQueuedFrame();
95
+ callback();
61
96
  };
62
- reqAnimFrameCall = requestAnimationFrame(callback);
97
+ window.addEventListener('visibilitychange', onVisibilityChange);
63
98
  return () => {
99
+ window.removeEventListener('visibilitychange', onVisibilityChange);
64
100
  stop();
65
101
  };
66
102
  }, [
@@ -74,6 +110,7 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
74
110
  inFrame,
75
111
  outFrame,
76
112
  moveToBeginningWhenEnded,
113
+ isBackgroundedRef,
77
114
  ]);
78
115
  (0, react_1.useEffect)(() => {
79
116
  const interval = setInterval(() => {
@@ -85,5 +122,8 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
85
122
  }, 250);
86
123
  return () => clearInterval(interval);
87
124
  }, [emitter]);
125
+ (0, react_1.useEffect)(() => {
126
+ emitter.dispatchFrameUpdate({ frame });
127
+ }, [emitter, frame]);
88
128
  };
89
129
  exports.usePlayback = usePlayback;
@@ -1,9 +1,10 @@
1
1
  import type { SyntheticEvent } from 'react';
2
- import type { PlayerEmitter } from './event-emitter';
2
+ import type { PlayerEmitter } from './event-emitter.js';
3
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
10
  play: (e?: SyntheticEvent) => void;
@@ -12,6 +13,7 @@ declare type UsePlayerMethods = {
12
13
  seek: (newFrame: number) => void;
13
14
  getCurrentFrame: () => number;
14
15
  isPlaying: () => boolean;
16
+ hasPlayed: boolean;
15
17
  };
16
18
  export declare const usePlayer: () => UsePlayerMethods;
17
19
  export {};
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.usePlayer = void 0;
4
4
  const react_1 = require("react");
5
5
  const remotion_1 = require("remotion");
6
- const emitter_context_1 = require("./emitter-context");
6
+ const emitter_context_js_1 = require("./emitter-context.js");
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();
11
- const playStart = (0, react_1.useRef)(0);
12
+ const playStart = (0, react_1.useRef)(frame);
12
13
  const setFrame = remotion_1.Internals.Timeline.useTimelineSetFrame();
13
14
  const setTimelinePosition = remotion_1.Internals.Timeline.useTimelineSetFrame();
14
15
  const audioContext = (0, react_1.useContext)(remotion_1.Internals.SharedAudioContext);
@@ -17,9 +18,10 @@ const usePlayer = () => {
17
18
  frameRef.current = frame;
18
19
  const video = remotion_1.Internals.useVideo();
19
20
  const config = remotion_1.Internals.useUnsafeVideoConfig();
20
- const emitter = (0, react_1.useContext)(emitter_context_1.PlayerEventEmitterContext);
21
+ const emitter = (0, react_1.useContext)(emitter_context_js_1.PlayerEventEmitterContext);
21
22
  const lastFrame = ((_a = config === null || config === void 0 ? void 0 : config.durationInFrames) !== null && _a !== void 0 ? _a : 1) - 1;
22
23
  const isLastFrame = frame === lastFrame;
24
+ const isFirstFrame = frame === 0;
23
25
  if (!emitter) {
24
26
  throw new TypeError('Expected Player event emitter context');
25
27
  }
@@ -31,6 +33,7 @@ const usePlayer = () => {
31
33
  if (imperativePlaying.current) {
32
34
  return;
33
35
  }
36
+ setHasPlayed(true);
34
37
  if (isLastFrame) {
35
38
  seek(0);
36
39
  }
@@ -104,21 +107,25 @@ const usePlayer = () => {
104
107
  play,
105
108
  pause,
106
109
  seek,
110
+ isFirstFrame,
107
111
  getCurrentFrame: () => frameRef.current,
108
112
  isPlaying: () => imperativePlaying.current,
109
113
  pauseAndReturnToPlayStart,
114
+ hasPlayed,
110
115
  };
111
116
  }, [
112
- emitter,
113
117
  frameBack,
114
118
  frameForward,
115
- imperativePlaying,
116
119
  isLastFrame,
117
- pause,
118
- play,
120
+ emitter,
119
121
  playing,
120
- pauseAndReturnToPlayStart,
122
+ play,
123
+ pause,
121
124
  seek,
125
+ isFirstFrame,
126
+ pauseAndReturnToPlayStart,
127
+ imperativePlaying,
128
+ hasPlayed,
122
129
  ]);
123
130
  return returnValue;
124
131
  };
@@ -0,0 +1,6 @@
1
+ import type { ThumbnailEmitter } from './event-emitter.js';
2
+ declare type UseThumbnailMethods = {
3
+ emitter: ThumbnailEmitter;
4
+ };
5
+ export declare const useThumbnail: () => UseThumbnailMethods;
6
+ export {};
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useThumbnail = void 0;
4
+ const react_1 = require("react");
5
+ const emitter_context_js_1 = require("./emitter-context.js");
6
+ const useThumbnail = () => {
7
+ const emitter = (0, react_1.useContext)(emitter_context_js_1.ThumbnailEmitterContext);
8
+ if (!emitter) {
9
+ throw new TypeError('Expected Player event emitter context');
10
+ }
11
+ const returnValue = (0, react_1.useMemo)(() => {
12
+ return {
13
+ emitter,
14
+ };
15
+ }, [emitter]);
16
+ return returnValue;
17
+ };
18
+ exports.useThumbnail = useThumbnail;
@@ -0,0 +1,11 @@
1
+ declare type Info = {
2
+ maxTimeLabelWidth: number | null;
3
+ displayVerticalVolumeSlider: boolean;
4
+ };
5
+ export declare const X_SPACER = 10;
6
+ export declare const X_PADDING = 12;
7
+ export declare const useVideoControlsResize: ({ allowFullscreen: allowFullScreen, playerWidth, }: {
8
+ allowFullscreen: boolean;
9
+ playerWidth: number;
10
+ }) => Info;
11
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useVideoControlsResize = exports.X_PADDING = exports.X_SPACER = void 0;
4
+ const react_1 = require("react");
5
+ const icons_js_1 = require("./icons.js");
6
+ const MediaVolumeSlider_js_1 = require("./MediaVolumeSlider.js");
7
+ exports.X_SPACER = 10;
8
+ exports.X_PADDING = 12;
9
+ const useVideoControlsResize = ({ allowFullscreen: allowFullScreen, playerWidth, }) => {
10
+ const resizeInfo = (0, react_1.useMemo)(() => {
11
+ const playPauseIconSize = icons_js_1.ICON_SIZE;
12
+ const volumeIconSize = icons_js_1.ICON_SIZE;
13
+ const _fullscreenIconSize = allowFullScreen ? icons_js_1.fullscreenIconSize : 0;
14
+ const elementsSize = volumeIconSize +
15
+ playPauseIconSize +
16
+ _fullscreenIconSize +
17
+ exports.X_PADDING * 2 +
18
+ exports.X_SPACER * 2;
19
+ const maxTimeLabelWidth = playerWidth - elementsSize;
20
+ const maxTimeLabelWidthWithoutNegativeValue = Math.max(maxTimeLabelWidth, 0);
21
+ const availableTimeLabelWidthIfVolumeOpen = maxTimeLabelWidthWithoutNegativeValue - MediaVolumeSlider_js_1.VOLUME_SLIDER_WIDTH;
22
+ // If max label width is lower than the volume width
23
+ // then it means we need to take it's width as the max label width
24
+ // otherwise we took the available width when volume open
25
+ const computedLabelWidth = availableTimeLabelWidthIfVolumeOpen < MediaVolumeSlider_js_1.VOLUME_SLIDER_WIDTH
26
+ ? maxTimeLabelWidthWithoutNegativeValue
27
+ : availableTimeLabelWidthIfVolumeOpen;
28
+ const minWidthForHorizontalDisplay = computedLabelWidth + elementsSize + MediaVolumeSlider_js_1.VOLUME_SLIDER_WIDTH;
29
+ const displayVerticalVolumeSlider = playerWidth < minWidthForHorizontalDisplay;
30
+ return {
31
+ maxTimeLabelWidth: maxTimeLabelWidthWithoutNegativeValue === 0
32
+ ? null
33
+ : maxTimeLabelWidthWithoutNegativeValue,
34
+ displayVerticalVolumeSlider,
35
+ };
36
+ }, [allowFullScreen, playerWidth]);
37
+ return resizeInfo;
38
+ };
39
+ exports.useVideoControlsResize = useVideoControlsResize;
@@ -1,5 +1,5 @@
1
1
  import type { StandardLonghandProperties } from 'csstype';
2
- import type { Size } from './use-element-size';
2
+ import type { Size } from './use-element-size.js';
3
3
  export declare const calculatePlayerSize: ({ currentSize, width, height, compositionWidth, compositionHeight, }: {
4
4
  currentSize: Size | null;
5
5
  width: StandardLonghandProperties['width'] | undefined;
@@ -2,23 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculatePlayerSize = void 0;
4
4
  const calculatePlayerSize = ({ currentSize, width, height, compositionWidth, compositionHeight, }) => {
5
- const aspectRatio = compositionWidth / compositionHeight;
6
- if (!currentSize) {
7
- return {
8
- width: compositionWidth,
9
- height: compositionHeight,
10
- };
11
- }
12
- // If has width specified, but no height, specify a default height that satisfies the aspect ratio.
13
5
  if (width !== undefined && height === undefined) {
14
6
  return {
15
- height: currentSize.width / aspectRatio,
7
+ aspectRatio: [compositionWidth, compositionHeight].join('/'),
16
8
  };
17
9
  }
18
10
  // Opposite: If has height specified, evaluate the height and specify a default width.
19
11
  if (height !== undefined && width === undefined) {
20
12
  return {
21
- width: currentSize.height * aspectRatio,
13
+ // Aspect ratio CSS prop will work
14
+ aspectRatio: [compositionWidth, compositionHeight].join('/'),
15
+ };
16
+ }
17
+ if (!currentSize) {
18
+ return {
19
+ width: compositionWidth,
20
+ height: compositionHeight,
22
21
  };
23
22
  }
24
23
  return {
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,8 @@
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
+ };
File without changes
@@ -0,0 +1,5 @@
1
+ export declare type PropsIfHasProps<Props> = {} extends Props ? {
2
+ inputProps?: Props;
3
+ } : {
4
+ inputProps: Props;
5
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,4 @@
1
- import type { CancellablePromise } from './cancellable-promise';
1
+ import type { CancellablePromise } from './cancellable-promise.js';
2
2
  declare const useCancellablePromises: () => {
3
3
  appendPendingPromise: (promise: CancellablePromise) => void;
4
4
  removePendingPromise: (promise: CancellablePromise) => void;
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useClickPreventionOnDoubleClick = void 0;
4
4
  const react_1 = require("react");
5
- const cancellable_promise_1 = require("./cancellable-promise");
6
- const delay_1 = require("./delay");
7
- const use_cancellable_promises_1 = require("./use-cancellable-promises");
5
+ const cancellable_promise_js_1 = require("./cancellable-promise.js");
6
+ const delay_js_1 = require("./delay.js");
7
+ const use_cancellable_promises_js_1 = require("./use-cancellable-promises.js");
8
8
  const useClickPreventionOnDoubleClick = (onClick, onDoubleClick, doubleClickToFullscreen) => {
9
- const api = (0, use_cancellable_promises_1.useCancellablePromises)();
9
+ const api = (0, use_cancellable_promises_js_1.useCancellablePromises)();
10
10
  const handleClick = (0, react_1.useCallback)(async (e) => {
11
11
  api.clearPendingPromises();
12
- const waitForClick = (0, cancellable_promise_1.cancellablePromise)((0, delay_1.delay)(200));
12
+ const waitForClick = (0, cancellable_promise_js_1.cancellablePromise)((0, delay_js_1.delay)(200));
13
13
  api.appendPendingPromise(waitForClick);
14
14
  try {
15
15
  await waitForClick.promise;
@@ -7,6 +7,7 @@ export declare type Size = {
7
7
  width: number;
8
8
  height: number;
9
9
  };
10
+ refresh: () => void;
10
11
  };
11
12
  export declare const updateAllElementsSizes: () => void;
12
13
  export declare const useElementSize: (ref: React.RefObject<HTMLElement>, options: {
@@ -20,11 +20,11 @@ const useElementSize = (ref, options) => {
20
20
  const { contentRect } = entries[0];
21
21
  // The clientRect returns the size with `scale()` being applied.
22
22
  const newSize = entries[0].target.getClientRects();
23
- if (!newSize || !newSize[0]) {
23
+ if (!(newSize === null || newSize === void 0 ? void 0 : newSize[0])) {
24
24
  setSize(null);
25
25
  return;
26
26
  }
27
- const probableCssParentScale = newSize[0].width / contentRect.width;
27
+ const probableCssParentScale = contentRect.width === 0 ? 1 : newSize[0].width / contentRect.width;
28
28
  const width = options.shouldApplyCssTransforms
29
29
  ? newSize[0].width
30
30
  : newSize[0].width * (1 / probableCssParentScale);
@@ -52,15 +52,27 @@ const useElementSize = (ref, options) => {
52
52
  setSize(null);
53
53
  return;
54
54
  }
55
- setSize({
56
- width: rect[0].width,
57
- height: rect[0].height,
58
- left: rect[0].x,
59
- top: rect[0].y,
60
- windowSize: {
61
- height: window.innerHeight,
62
- width: window.innerWidth,
63
- },
55
+ setSize((prevState) => {
56
+ const isSame = prevState &&
57
+ prevState.width === rect[0].width &&
58
+ prevState.height === rect[0].height &&
59
+ prevState.left === rect[0].x &&
60
+ prevState.top === rect[0].y &&
61
+ prevState.windowSize.height === window.innerHeight &&
62
+ prevState.windowSize.width === window.innerWidth;
63
+ if (isSame) {
64
+ return prevState;
65
+ }
66
+ return {
67
+ width: rect[0].width,
68
+ height: rect[0].height,
69
+ left: rect[0].x,
70
+ top: rect[0].y,
71
+ windowSize: {
72
+ height: window.innerHeight,
73
+ width: window.innerWidth,
74
+ },
75
+ };
64
76
  });
65
77
  }, [ref]);
66
78
  (0, react_1.useEffect)(() => {
@@ -93,6 +105,6 @@ const useElementSize = (ref, options) => {
93
105
  elementSizeHooks = elementSizeHooks.filter((e) => e !== updateSize);
94
106
  };
95
107
  }, [updateSize]);
96
- return size;
108
+ return size ? { ...size, refresh: updateSize } : null;
97
109
  };
98
110
  exports.useElementSize = useElementSize;