@remotion/player 4.0.0-lambda.3 → 4.0.0-newpathfunctions.13

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 (311) hide show
  1. package/LICENSE.md +8 -8
  2. package/README.md +1 -1
  3. package/dist/MediaVolumeSlider.d.ts +4 -1
  4. package/dist/MediaVolumeSlider.js +80 -55
  5. package/dist/Player.d.ts +20 -15
  6. package/dist/Player.js +24 -70
  7. package/dist/PlayerControls.d.ts +29 -2
  8. package/dist/PlayerControls.js +66 -15
  9. package/dist/PlayerSeekBar.d.ts +4 -0
  10. package/dist/PlayerSeekBar.js +35 -11
  11. package/dist/PlayerUI.d.ts +18 -9
  12. package/dist/PlayerUI.js +118 -76
  13. package/dist/SharedPlayerContext.d.ts +14 -0
  14. package/dist/SharedPlayerContext.js +72 -0
  15. package/dist/Thumbnail.d.ts +20 -0
  16. package/dist/Thumbnail.js +42 -0
  17. package/dist/ThumbnailUI.d.ts +11 -0
  18. package/dist/ThumbnailUI.js +107 -0
  19. package/dist/calculate-next-frame.d.ts +0 -0
  20. package/dist/calculate-next-frame.js +0 -0
  21. package/dist/calculate-scale.d.ts +30 -5
  22. package/dist/calculate-scale.js +65 -4
  23. package/dist/cjs/MediaVolumeSlider.d.ts +5 -0
  24. package/dist/cjs/MediaVolumeSlider.js +118 -0
  25. package/dist/cjs/Player.d.ts +43 -0
  26. package/dist/cjs/Player.js +143 -0
  27. package/dist/cjs/PlayerControls.d.ts +41 -0
  28. package/dist/cjs/PlayerControls.js +152 -0
  29. package/dist/cjs/PlayerSeekBar.d.ts +8 -0
  30. package/dist/cjs/PlayerSeekBar.js +146 -0
  31. package/dist/cjs/PlayerUI.d.ts +38 -0
  32. package/dist/cjs/PlayerUI.js +308 -0
  33. package/dist/cjs/SharedPlayerContext.d.ts +14 -0
  34. package/dist/cjs/SharedPlayerContext.js +72 -0
  35. package/dist/cjs/Thumbnail.d.ts +20 -0
  36. package/dist/cjs/Thumbnail.js +42 -0
  37. package/dist/cjs/ThumbnailUI.d.ts +11 -0
  38. package/dist/cjs/ThumbnailUI.js +107 -0
  39. package/dist/cjs/calculate-next-frame.d.ts +14 -0
  40. package/dist/cjs/calculate-next-frame.js +28 -0
  41. package/dist/cjs/calculate-scale.d.ts +39 -0
  42. package/dist/cjs/calculate-scale.js +85 -0
  43. package/dist/cjs/emitter-context.d.ts +4 -0
  44. package/dist/cjs/emitter-context.js +9 -0
  45. package/dist/cjs/error-boundary.d.ts +19 -0
  46. package/dist/cjs/error-boundary.js +39 -0
  47. package/dist/cjs/event-emitter.d.ts +66 -0
  48. package/dist/cjs/event-emitter.js +87 -0
  49. package/dist/cjs/format-time.d.ts +1 -0
  50. package/dist/cjs/format-time.js +9 -0
  51. package/dist/cjs/icons.d.ts +10 -0
  52. package/dist/cjs/icons.js +50 -0
  53. package/dist/cjs/index.d.ts +60 -0
  54. package/dist/cjs/index.js +25 -0
  55. package/dist/cjs/player-css-classname.d.ts +1 -0
  56. package/dist/cjs/player-css-classname.js +4 -0
  57. package/dist/cjs/player-methods.d.ts +24 -0
  58. package/dist/cjs/player-methods.js +2 -0
  59. package/dist/cjs/test/index.test.d.ts +1 -0
  60. package/dist/cjs/test/index.test.js +9 -0
  61. package/dist/cjs/test/test-utils.d.ts +6 -0
  62. package/dist/cjs/test/test-utils.js +32 -0
  63. package/dist/cjs/test/validate-in-out-frames.test.d.ts +1 -0
  64. package/dist/cjs/test/validate-in-out-frames.test.js +56 -0
  65. package/dist/cjs/test/validate-prop.test.d.ts +1 -0
  66. package/dist/cjs/test/validate-prop.test.js +131 -0
  67. package/dist/cjs/use-hover-state.d.ts +1 -0
  68. package/dist/cjs/use-hover-state.js +27 -0
  69. package/dist/cjs/use-playback.d.ts +7 -0
  70. package/dist/cjs/use-playback.js +92 -0
  71. package/dist/cjs/use-player.d.ts +19 -0
  72. package/dist/cjs/use-player.js +132 -0
  73. package/dist/cjs/use-thumbnail.d.ts +6 -0
  74. package/dist/cjs/use-thumbnail.js +18 -0
  75. package/dist/cjs/use-video-controls-resize.d.ts +7 -0
  76. package/dist/cjs/use-video-controls-resize.js +36 -0
  77. package/dist/cjs/utils/calculate-player-size.d.ts +9 -0
  78. package/dist/cjs/utils/calculate-player-size.js +29 -0
  79. package/dist/cjs/utils/cancellable-promise.d.ts +5 -0
  80. package/dist/cjs/utils/cancellable-promise.js +26 -0
  81. package/dist/cjs/utils/delay.d.ts +1 -0
  82. package/dist/cjs/utils/delay.js +6 -0
  83. package/dist/cjs/utils/is-node.d.ts +1 -0
  84. package/dist/cjs/utils/is-node.js +4 -0
  85. package/dist/cjs/utils/preview-size.d.ts +8 -0
  86. package/dist/cjs/utils/preview-size.js +2 -0
  87. package/dist/cjs/utils/props-if-has-props.d.ts +5 -0
  88. package/dist/cjs/utils/props-if-has-props.js +2 -0
  89. package/dist/cjs/utils/use-cancellable-promises.d.ts +7 -0
  90. package/dist/cjs/utils/use-cancellable-promises.js +21 -0
  91. package/dist/cjs/utils/use-click-prevention-on-double-click.d.ts +3 -0
  92. package/dist/cjs/utils/use-click-prevention-on-double-click.js +45 -0
  93. package/dist/cjs/utils/use-element-size.d.ts +16 -0
  94. package/dist/cjs/utils/use-element-size.js +98 -0
  95. package/dist/cjs/utils/validate-in-out-frame.d.ts +6 -0
  96. package/dist/cjs/utils/validate-in-out-frame.js +54 -0
  97. package/dist/cjs/utils/validate-initial-frame.d.ts +4 -0
  98. package/dist/cjs/utils/validate-initial-frame.js +27 -0
  99. package/dist/cjs/utils/validate-playbackrate.d.ts +1 -0
  100. package/dist/cjs/utils/validate-playbackrate.js +18 -0
  101. package/dist/cjs/volume-persistance.d.ts +2 -0
  102. package/dist/cjs/volume-persistance.js +19 -0
  103. package/dist/emitter-context.d.ts +2 -1
  104. package/dist/emitter-context.js +2 -1
  105. package/dist/error-boundary.d.ts +0 -0
  106. package/dist/error-boundary.js +0 -0
  107. package/dist/esm/MediaVolumeSlider.d.ts +5 -0
  108. package/dist/esm/MediaVolumeSlider.js +114 -0
  109. package/dist/esm/Player.d.ts +43 -0
  110. package/dist/esm/Player.js +136 -0
  111. package/dist/esm/PlayerControls.d.ts +41 -0
  112. package/dist/esm/PlayerControls.js +148 -0
  113. package/dist/esm/PlayerSeekBar.d.ts +8 -0
  114. package/dist/esm/PlayerSeekBar.js +142 -0
  115. package/dist/esm/PlayerUI.d.ts +38 -0
  116. package/dist/esm/PlayerUI.js +283 -0
  117. package/dist/esm/SharedPlayerContext.d.ts +14 -0
  118. package/dist/esm/SharedPlayerContext.js +68 -0
  119. package/dist/esm/Thumbnail.d.ts +20 -0
  120. package/dist/esm/Thumbnail.js +35 -0
  121. package/dist/esm/ThumbnailUI.d.ts +11 -0
  122. package/dist/esm/ThumbnailUI.js +82 -0
  123. package/dist/esm/calculate-next-frame.d.ts +14 -0
  124. package/dist/esm/calculate-next-frame.js +24 -0
  125. package/dist/esm/calculate-scale.d.ts +39 -0
  126. package/dist/esm/calculate-scale.js +77 -0
  127. package/dist/esm/emitter-context.d.ts +4 -0
  128. package/dist/esm/emitter-context.js +3 -0
  129. package/dist/esm/error-boundary.d.ts +19 -0
  130. package/dist/esm/error-boundary.js +32 -0
  131. package/dist/esm/event-emitter.d.ts +66 -0
  132. package/dist/esm/event-emitter.js +82 -0
  133. package/dist/esm/format-time.d.ts +1 -0
  134. package/dist/esm/format-time.js +5 -0
  135. package/dist/esm/icons.d.ts +10 -0
  136. package/dist/esm/icons.js +42 -0
  137. package/dist/esm/index.d.ts +60 -0
  138. package/dist/esm/index.js +20 -0
  139. package/dist/esm/player-css-classname.d.ts +1 -0
  140. package/dist/esm/player-css-classname.js +1 -0
  141. package/dist/esm/player-methods.d.ts +24 -0
  142. package/dist/esm/player-methods.js +1 -0
  143. package/dist/esm/test/index.test.d.ts +1 -0
  144. package/dist/esm/test/index.test.js +7 -0
  145. package/dist/esm/test/test-utils.d.ts +6 -0
  146. package/dist/esm/test/test-utils.js +14 -0
  147. package/dist/esm/test/validate-in-out-frames.test.d.ts +1 -0
  148. package/dist/esm/test/validate-in-out-frames.test.js +54 -0
  149. package/dist/esm/test/validate-prop.test.d.ts +1 -0
  150. package/dist/esm/test/validate-prop.test.js +129 -0
  151. package/dist/esm/use-hover-state.d.ts +1 -0
  152. package/dist/esm/use-hover-state.js +23 -0
  153. package/dist/esm/use-playback.d.ts +7 -0
  154. package/dist/esm/use-playback.js +88 -0
  155. package/dist/esm/use-player.d.ts +19 -0
  156. package/dist/esm/use-player.js +128 -0
  157. package/dist/esm/use-thumbnail.d.ts +6 -0
  158. package/dist/esm/use-thumbnail.js +14 -0
  159. package/dist/esm/use-video-controls-resize.d.ts +7 -0
  160. package/dist/esm/use-video-controls-resize.js +32 -0
  161. package/dist/esm/utils/calculate-player-size.d.ts +9 -0
  162. package/dist/esm/utils/calculate-player-size.js +25 -0
  163. package/dist/esm/utils/cancellable-promise.d.ts +5 -0
  164. package/dist/esm/utils/cancellable-promise.js +22 -0
  165. package/dist/esm/utils/delay.d.ts +1 -0
  166. package/dist/esm/utils/delay.js +2 -0
  167. package/dist/esm/utils/is-node.d.ts +1 -0
  168. package/dist/esm/utils/is-node.js +1 -0
  169. package/dist/esm/utils/preview-size.d.ts +8 -0
  170. package/dist/esm/utils/preview-size.js +1 -0
  171. package/dist/esm/utils/props-if-has-props.d.ts +5 -0
  172. package/dist/esm/utils/props-if-has-props.js +1 -0
  173. package/dist/esm/utils/use-cancellable-promises.d.ts +7 -0
  174. package/dist/esm/utils/use-cancellable-promises.js +18 -0
  175. package/dist/esm/utils/use-click-prevention-on-double-click.d.ts +3 -0
  176. package/dist/esm/utils/use-click-prevention-on-double-click.js +42 -0
  177. package/dist/esm/utils/use-element-size.d.ts +16 -0
  178. package/dist/esm/utils/use-element-size.js +93 -0
  179. package/dist/esm/utils/validate-in-out-frame.d.ts +6 -0
  180. package/dist/esm/utils/validate-in-out-frame.js +49 -0
  181. package/dist/esm/utils/validate-initial-frame.d.ts +4 -0
  182. package/dist/esm/utils/validate-initial-frame.js +23 -0
  183. package/dist/esm/utils/validate-playbackrate.d.ts +1 -0
  184. package/dist/esm/utils/validate-playbackrate.js +14 -0
  185. package/dist/esm/volume-persistance.d.ts +2 -0
  186. package/dist/esm/volume-persistance.js +14 -0
  187. package/dist/event-emitter.d.ts +33 -9
  188. package/dist/event-emitter.js +33 -1
  189. package/dist/format-time.d.ts +0 -0
  190. package/dist/format-time.js +0 -0
  191. package/dist/icons.d.ts +2 -1
  192. package/dist/icons.js +7 -7
  193. package/dist/index.d.ts +25 -9
  194. package/dist/index.js +5 -2
  195. package/dist/player-css-classname.d.ts +0 -1
  196. package/dist/player-css-classname.js +1 -2
  197. package/dist/player-methods.d.ts +8 -4
  198. package/dist/player-methods.js +0 -0
  199. package/dist/test/index.test.d.ts +0 -0
  200. package/dist/test/index.test.js +3 -2
  201. package/dist/test/test-utils.d.ts +2 -2
  202. package/dist/test/test-utils.js +0 -0
  203. package/dist/test/validate-in-out-frames.test.d.ts +1 -0
  204. package/dist/test/validate-in-out-frames.test.js +56 -0
  205. package/dist/test/validate-prop.test.d.ts +0 -0
  206. package/dist/test/validate-prop.test.js +24 -23
  207. package/dist/tsconfig-cjs.tsbuildinfo +1 -0
  208. package/dist/tsconfig.tsbuildinfo +1 -0
  209. package/dist/use-hover-state.d.ts +0 -0
  210. package/dist/use-hover-state.js +0 -0
  211. package/dist/use-playback.d.ts +4 -1
  212. package/dist/use-playback.js +7 -3
  213. package/dist/use-player.d.ts +8 -3
  214. package/dist/use-player.js +23 -4
  215. package/dist/use-thumbnail.d.ts +6 -0
  216. package/dist/use-thumbnail.js +18 -0
  217. package/dist/use-video-controls-resize.d.ts +7 -0
  218. package/dist/use-video-controls-resize.js +36 -0
  219. package/dist/utils/calculate-player-size.d.ts +2 -2
  220. package/dist/utils/calculate-player-size.js +0 -0
  221. package/dist/utils/cancellable-promise.d.ts +0 -0
  222. package/dist/utils/cancellable-promise.js +0 -0
  223. package/dist/utils/delay.d.ts +0 -0
  224. package/dist/utils/delay.js +0 -0
  225. package/dist/utils/is-node.d.ts +0 -0
  226. package/dist/utils/is-node.js +0 -0
  227. package/dist/utils/preview-size.d.ts +8 -1
  228. package/dist/utils/preview-size.js +0 -0
  229. package/dist/utils/props-if-has-props.d.ts +5 -0
  230. package/dist/utils/props-if-has-props.js +2 -0
  231. package/dist/utils/use-cancellable-promises.d.ts +1 -1
  232. package/dist/utils/use-cancellable-promises.js +0 -0
  233. package/dist/utils/use-click-prevention-on-double-click.d.ts +1 -1
  234. package/dist/utils/use-click-prevention-on-double-click.js +0 -0
  235. package/dist/utils/use-element-size.d.ts +4 -0
  236. package/dist/utils/use-element-size.js +8 -0
  237. package/dist/utils/validate-in-out-frame.d.ts +6 -0
  238. package/dist/utils/validate-in-out-frame.js +54 -0
  239. package/dist/utils/validate-initial-frame.d.ts +4 -0
  240. package/dist/utils/validate-initial-frame.js +27 -0
  241. package/dist/utils/validate-playbackrate.d.ts +0 -0
  242. package/dist/utils/validate-playbackrate.js +0 -0
  243. package/dist/volume-persistance.d.ts +0 -0
  244. package/dist/volume-persistance.js +0 -0
  245. package/package.json +26 -17
  246. package/dist/MediaVolumeSlider.d.ts.map +0 -1
  247. package/dist/MediaVolumeSlider.js.map +0 -1
  248. package/dist/Player.d.ts.map +0 -1
  249. package/dist/Player.js.map +0 -1
  250. package/dist/PlayerControls.d.ts.map +0 -1
  251. package/dist/PlayerControls.js.map +0 -1
  252. package/dist/PlayerSeekBar.d.ts.map +0 -1
  253. package/dist/PlayerSeekBar.js.map +0 -1
  254. package/dist/PlayerUI.d.ts.map +0 -1
  255. package/dist/PlayerUI.js.map +0 -1
  256. package/dist/calculate-next-frame.d.ts.map +0 -1
  257. package/dist/calculate-next-frame.js.map +0 -1
  258. package/dist/calculate-scale.d.ts.map +0 -1
  259. package/dist/calculate-scale.js.map +0 -1
  260. package/dist/emitter-context.d.ts.map +0 -1
  261. package/dist/emitter-context.js.map +0 -1
  262. package/dist/error-boundary.d.ts.map +0 -1
  263. package/dist/error-boundary.js.map +0 -1
  264. package/dist/event-emitter.d.ts.map +0 -1
  265. package/dist/event-emitter.js.map +0 -1
  266. package/dist/format-time.d.ts.map +0 -1
  267. package/dist/format-time.js.map +0 -1
  268. package/dist/icons.d.ts.map +0 -1
  269. package/dist/icons.js.map +0 -1
  270. package/dist/index.d.ts.map +0 -1
  271. package/dist/index.js.map +0 -1
  272. package/dist/player-css-classname.d.ts.map +0 -1
  273. package/dist/player-css-classname.js.map +0 -1
  274. package/dist/player-methods.d.ts.map +0 -1
  275. package/dist/player-methods.js.map +0 -1
  276. package/dist/test/index.test.d.ts.map +0 -1
  277. package/dist/test/index.test.js.map +0 -1
  278. package/dist/test/test-utils.d.ts.map +0 -1
  279. package/dist/test/test-utils.js.map +0 -1
  280. package/dist/test/validate-prop.test.d.ts.map +0 -1
  281. package/dist/test/validate-prop.test.js.map +0 -1
  282. package/dist/use-hover-state.d.ts.map +0 -1
  283. package/dist/use-hover-state.js.map +0 -1
  284. package/dist/use-playback.d.ts.map +0 -1
  285. package/dist/use-playback.js.map +0 -1
  286. package/dist/use-player.d.ts.map +0 -1
  287. package/dist/use-player.js.map +0 -1
  288. package/dist/utils/browser-supports-fullscreen.d.ts +0 -11
  289. package/dist/utils/browser-supports-fullscreen.d.ts.map +0 -1
  290. package/dist/utils/browser-supports-fullscreen.js +0 -5
  291. package/dist/utils/browser-supports-fullscreen.js.map +0 -1
  292. package/dist/utils/calculate-player-size.d.ts.map +0 -1
  293. package/dist/utils/calculate-player-size.js.map +0 -1
  294. package/dist/utils/cancellable-promise.d.ts.map +0 -1
  295. package/dist/utils/cancellable-promise.js.map +0 -1
  296. package/dist/utils/delay.d.ts.map +0 -1
  297. package/dist/utils/delay.js.map +0 -1
  298. package/dist/utils/is-node.d.ts.map +0 -1
  299. package/dist/utils/is-node.js.map +0 -1
  300. package/dist/utils/preview-size.d.ts.map +0 -1
  301. package/dist/utils/preview-size.js.map +0 -1
  302. package/dist/utils/use-cancellable-promises.d.ts.map +0 -1
  303. package/dist/utils/use-cancellable-promises.js.map +0 -1
  304. package/dist/utils/use-click-prevention-on-double-click.d.ts.map +0 -1
  305. package/dist/utils/use-click-prevention-on-double-click.js.map +0 -1
  306. package/dist/utils/use-element-size.d.ts.map +0 -1
  307. package/dist/utils/use-element-size.js.map +0 -1
  308. package/dist/utils/validate-playbackrate.d.ts.map +0 -1
  309. package/dist/utils/validate-playbackrate.js.map +0 -1
  310. package/dist/volume-persistance.d.ts.map +0 -1
  311. package/dist/volume-persistance.js.map +0 -1
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { render } from '@testing-library/react';
3
+ const HelloWorld = () => {
4
+ return _jsx("div", { children: "Hello World" });
5
+ };
6
+ const AllTheProviders = ({ children }) => {
7
+ // overwriting console.error console does not gets poluted with all the errors
8
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
9
+ window.console.error = () => { };
10
+ return _jsx("div", { children: children });
11
+ };
12
+ const customRender = (ui, options) => render(ui, { wrapper: AllTheProviders, ...options });
13
+ export * from '@testing-library/react';
14
+ export { customRender as render, HelloWorld };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,54 @@
1
+ import { expect, test } from 'vitest';
2
+ import { validateInOutFrames } from '../utils/validate-in-out-frame';
3
+ test('Validate in out frames', () => {
4
+ expect(() => validateInOutFrames({
5
+ durationInFrames: 200,
6
+ inFrame: 201,
7
+ outFrame: undefined,
8
+ })).toThrow(/inFrame must be less than \(durationInFrames - 1\)/);
9
+ expect(() => validateInOutFrames({
10
+ durationInFrames: 200,
11
+ inFrame: 199,
12
+ outFrame: 201,
13
+ })).toThrow(/outFrame must be less than \(durationInFrames - 1\)/);
14
+ expect(() => validateInOutFrames({
15
+ durationInFrames: 200,
16
+ inFrame: -10,
17
+ outFrame: null,
18
+ })).toThrow(/inFrame must be greater than 0, but is -10/);
19
+ expect(() => validateInOutFrames({
20
+ durationInFrames: 200,
21
+ inFrame: null,
22
+ outFrame: -10,
23
+ })).toThrow(/outFrame must be greater than 0, but is -10/);
24
+ expect(() => validateInOutFrames({
25
+ durationInFrames: 200,
26
+ inFrame: 1.5,
27
+ outFrame: null,
28
+ })).toThrow(/"inFrame" must be an integer, but is 1.5/);
29
+ expect(() => validateInOutFrames({
30
+ durationInFrames: 200,
31
+ inFrame: 20,
32
+ outFrame: 20,
33
+ })).toThrow(/outFrame must be greater than inFrame, but is 20/);
34
+ expect(() => validateInOutFrames({
35
+ durationInFrames: 200,
36
+ inFrame: 21,
37
+ outFrame: 20,
38
+ })).toThrow(/outFrame must be greater than inFrame, but is 20 <= 21/);
39
+ expect(() => validateInOutFrames({
40
+ durationInFrames: 200,
41
+ inFrame: null,
42
+ outFrame: 20,
43
+ })).not.toThrow();
44
+ expect(() => validateInOutFrames({
45
+ durationInFrames: 200,
46
+ inFrame: null,
47
+ outFrame: null,
48
+ })).not.toThrow();
49
+ expect(() => validateInOutFrames({
50
+ durationInFrames: 200,
51
+ inFrame: 10,
52
+ outFrame: 20,
53
+ })).not.toThrow();
54
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,129 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Composition } from 'remotion';
3
+ import { expect, test } from 'vitest';
4
+ import { Player } from '../index';
5
+ import { HelloWorld, render } from './test-utils';
6
+ test('no compositionWidth should give errors', () => {
7
+ try {
8
+ render(_jsx(Player
9
+ // @ts-expect-error
10
+ , {
11
+ // @ts-expect-error
12
+ compositionWidth: null, errorFallback: () => 'something went wrong', compositionHeight: 400, fps: 30, durationInFrames: 500, component: HelloWorld, controls: true, showVolumeControls: true }));
13
+ }
14
+ catch (e) {
15
+ expect(e.message).toMatch(/'compositionWidth' must be a number but got 'object' instead/);
16
+ }
17
+ });
18
+ test('no compositionHeight should give errors', () => {
19
+ try {
20
+ render(_jsx(Player, { compositionWidth: 400, errorFallback: () => 'something went wrong',
21
+ // @ts-expect-error
22
+ compositionHeight: undefined, fps: 30, durationInFrames: 500, component: HelloWorld, controls: true, showVolumeControls: true }));
23
+ }
24
+ catch (e) {
25
+ expect(e.message).toMatch(/'compositionHeight' must be a number but got 'undefined' instead/);
26
+ }
27
+ });
28
+ test('No fps should give errors', () => {
29
+ try {
30
+ render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, errorFallback: () => 'something went wrong',
31
+ // @ts-expect-error
32
+ fps: null, durationInFrames: 500, component: HelloWorld, controls: true, showVolumeControls: true }));
33
+ }
34
+ catch (e) {
35
+ expect(e.message).toMatch(/"fps" must be a number, but you passed a value of type object/);
36
+ }
37
+ try {
38
+ render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, errorFallback: () => 'something went wrong',
39
+ // @ts-expect-error
40
+ fps: undefined, durationInFrames: 500, component: HelloWorld, controls: true, showVolumeControls: true }));
41
+ }
42
+ catch (e) {
43
+ expect(e.message).toMatch(/"fps" must be a number, but you passed a value of type undefined/);
44
+ }
45
+ });
46
+ test('No durationInFrames should give errors', () => {
47
+ try {
48
+ render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, errorFallback: () => 'something went wrong', fps: 30,
49
+ // @ts-expect-error
50
+ durationInFrames: undefined, component: HelloWorld, controls: true, showVolumeControls: true }));
51
+ }
52
+ catch (e) {
53
+ expect(e.message).toMatch(/durationInFrames` must be a number, but is undefined/);
54
+ }
55
+ });
56
+ test('Invalid playbackRate should give error', () => {
57
+ try {
58
+ render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: HelloWorld, controls: true, showVolumeControls: true, playbackRate: -5 }));
59
+ }
60
+ catch (e) {
61
+ expect(e.message).toMatch(/The lowest possible playback rate is -4. You passed: -5/);
62
+ }
63
+ });
64
+ test('playbackRate of 0 should not be possible', () => {
65
+ try {
66
+ render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: HelloWorld, controls: true, showVolumeControls: true, playbackRate: 0 }));
67
+ }
68
+ catch (e) {
69
+ expect(e.message).toMatch(/A playback rate of 0 is not supported./);
70
+ }
71
+ });
72
+ test('playbackRate of wrong type should not be possible', () => {
73
+ try {
74
+ render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: HelloWorld, controls: true, showVolumeControls: true,
75
+ // @ts-expect-error
76
+ playbackRate: 'hi' }));
77
+ }
78
+ catch (e) {
79
+ expect(e.message).toMatch(/A playback rate of 0 is not supported./);
80
+ }
81
+ });
82
+ test('playbackRate of undefined should be okay', () => {
83
+ render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: HelloWorld, controls: true, showVolumeControls: true }));
84
+ expect(true).toBe(true);
85
+ });
86
+ test('passing in <Composition /> instance should not be possible', () => {
87
+ expect(() => {
88
+ render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: Composition, controls: true, showVolumeControls: true, inputProps: {
89
+ id: 'HelloWorld',
90
+ width: 500,
91
+ height: 400,
92
+ fps: 30,
93
+ durationInFrames: 500,
94
+ component: HelloWorld,
95
+ } }));
96
+ }).toThrow(/'component' must not be the 'Composition' component\. Pass your own React/);
97
+ });
98
+ test('passing in <Composition /> instance should not be possible', () => {
99
+ expect(() => {
100
+ render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500,
101
+ // @ts-expect-error
102
+ component: _jsx(Composition, { durationInFrames: 30, fps: 30, height: 10, width: 10, id: "hello", component: HelloWorld }), controls: true, showVolumeControls: true, inputProps: {
103
+ id: 'HelloWorld',
104
+ width: 500,
105
+ height: 400,
106
+ fps: 30,
107
+ durationInFrames: 500,
108
+ component: HelloWorld,
109
+ } }));
110
+ }).toThrow(/'component' should not be an instance of <Composition\/>\. Pass the React component dir/);
111
+ });
112
+ test.each([
113
+ ['controls'],
114
+ ['loop'],
115
+ ['autoPlay'],
116
+ ['showVolumeControls'],
117
+ ['allowFullscreen'],
118
+ ['clickToPlay'],
119
+ ['doubleClickToFullscreen'],
120
+ ])('No durationInFrames should give errors %s', (a) => {
121
+ const props = {};
122
+ props[a] = 'hey';
123
+ try {
124
+ render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, errorFallback: () => 'something went wrong', fps: 30, durationInFrames: 100, component: HelloWorld, ...props }));
125
+ }
126
+ catch (e) {
127
+ expect(e.message).toMatch(`'${a}' must be a boolean or undefined but got 'string' instead`);
128
+ }
129
+ });
@@ -0,0 +1 @@
1
+ export declare const useHoverState: (ref: React.RefObject<HTMLDivElement>) => boolean;
@@ -0,0 +1,23 @@
1
+ import { useEffect, useState } from 'react';
2
+ export const useHoverState = (ref) => {
3
+ const [hovered, stetHovered] = useState(false);
4
+ useEffect(() => {
5
+ const { current } = ref;
6
+ if (!current) {
7
+ return;
8
+ }
9
+ const onHover = () => {
10
+ stetHovered(true);
11
+ };
12
+ const onLeave = () => {
13
+ stetHovered(false);
14
+ };
15
+ current.addEventListener('mouseenter', onHover);
16
+ current.addEventListener('mouseleave', onLeave);
17
+ return () => {
18
+ current.removeEventListener('mouseenter', onHover);
19
+ current.removeEventListener('mouseenter', onLeave);
20
+ };
21
+ }, [ref]);
22
+ return hovered;
23
+ };
@@ -0,0 +1,7 @@
1
+ export declare const usePlayback: ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, outFrame, }: {
2
+ loop: boolean;
3
+ playbackRate: number;
4
+ moveToBeginningWhenEnded: boolean;
5
+ inFrame: number | null;
6
+ outFrame: number | null;
7
+ }) => void;
@@ -0,0 +1,88 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { Internals } from 'remotion';
3
+ import { calculateNextFrame } from './calculate-next-frame';
4
+ import { usePlayer } from './use-player';
5
+ export const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, outFrame, }) => {
6
+ const frame = Internals.Timeline.useTimelinePosition();
7
+ const config = Internals.useUnsafeVideoConfig();
8
+ const { playing, pause, emitter } = usePlayer();
9
+ const setFrame = Internals.Timeline.useTimelineSetFrame();
10
+ const frameRef = useRef(frame);
11
+ frameRef.current = frame;
12
+ const lastTimeUpdateEvent = useRef(null);
13
+ useEffect(() => {
14
+ if (!config) {
15
+ return;
16
+ }
17
+ if (!playing) {
18
+ return;
19
+ }
20
+ let hasBeenStopped = false;
21
+ let reqAnimFrameCall = null;
22
+ const startedTime = performance.now();
23
+ let framesAdvanced = 0;
24
+ const stop = () => {
25
+ hasBeenStopped = true;
26
+ if (reqAnimFrameCall !== null) {
27
+ cancelAnimationFrame(reqAnimFrameCall);
28
+ }
29
+ };
30
+ const callback = () => {
31
+ const time = performance.now() - startedTime;
32
+ const actualLastFrame = outFrame !== null && outFrame !== void 0 ? outFrame : config.durationInFrames - 1;
33
+ const actualFirstFrame = inFrame !== null && inFrame !== void 0 ? inFrame : 0;
34
+ const { nextFrame, framesToAdvance, hasEnded } = calculateNextFrame({
35
+ time,
36
+ currentFrame: frameRef.current,
37
+ playbackSpeed: playbackRate,
38
+ fps: config.fps,
39
+ actualFirstFrame,
40
+ actualLastFrame,
41
+ framesAdvanced,
42
+ shouldLoop: loop,
43
+ });
44
+ framesAdvanced += framesToAdvance;
45
+ if (nextFrame !== frameRef.current &&
46
+ (!hasEnded || moveToBeginningWhenEnded)) {
47
+ setFrame(nextFrame);
48
+ }
49
+ if (hasEnded) {
50
+ stop();
51
+ pause();
52
+ emitter.dispatchEnded();
53
+ return;
54
+ }
55
+ if (!hasBeenStopped) {
56
+ reqAnimFrameCall = requestAnimationFrame(callback);
57
+ }
58
+ };
59
+ reqAnimFrameCall = requestAnimationFrame(callback);
60
+ return () => {
61
+ stop();
62
+ };
63
+ }, [
64
+ config,
65
+ loop,
66
+ pause,
67
+ playing,
68
+ setFrame,
69
+ emitter,
70
+ playbackRate,
71
+ inFrame,
72
+ outFrame,
73
+ moveToBeginningWhenEnded,
74
+ ]);
75
+ useEffect(() => {
76
+ const interval = setInterval(() => {
77
+ if (lastTimeUpdateEvent.current === frameRef.current) {
78
+ return;
79
+ }
80
+ emitter.dispatchTimeUpdate({ frame: frameRef.current });
81
+ lastTimeUpdateEvent.current = frameRef.current;
82
+ }, 250);
83
+ return () => clearInterval(interval);
84
+ }, [emitter]);
85
+ useEffect(() => {
86
+ emitter.dispatchFrameUpdate({ frame });
87
+ }, [emitter, frame]);
88
+ };
@@ -0,0 +1,19 @@
1
+ import type { SyntheticEvent } from 'react';
2
+ import type { PlayerEmitter } from './event-emitter';
3
+ declare type UsePlayerMethods = {
4
+ frameBack: (frames: number) => void;
5
+ frameForward: (frames: number) => void;
6
+ isLastFrame: boolean;
7
+ isFirstFrame: boolean;
8
+ emitter: PlayerEmitter;
9
+ playing: boolean;
10
+ play: (e?: SyntheticEvent) => void;
11
+ pause: () => void;
12
+ pauseAndReturnToPlayStart: () => void;
13
+ seek: (newFrame: number) => void;
14
+ getCurrentFrame: () => number;
15
+ isPlaying: () => boolean;
16
+ hasPlayed: boolean;
17
+ };
18
+ export declare const usePlayer: () => UsePlayerMethods;
19
+ export {};
@@ -0,0 +1,128 @@
1
+ import { useCallback, useContext, useMemo, useRef, useState } from 'react';
2
+ import { Internals } from 'remotion';
3
+ import { PlayerEventEmitterContext } from './emitter-context';
4
+ export const usePlayer = () => {
5
+ var _a;
6
+ const [playing, setPlaying, imperativePlaying] = Internals.Timeline.usePlayingState();
7
+ const [hasPlayed, setHasPlayed] = useState(false);
8
+ const frame = Internals.Timeline.useTimelinePosition();
9
+ const playStart = useRef(frame);
10
+ const setFrame = Internals.Timeline.useTimelineSetFrame();
11
+ const setTimelinePosition = Internals.Timeline.useTimelineSetFrame();
12
+ const audioContext = useContext(Internals.SharedAudioContext);
13
+ const { audioAndVideoTags } = useContext(Internals.Timeline.TimelineContext);
14
+ const frameRef = useRef();
15
+ frameRef.current = frame;
16
+ const video = Internals.useVideo();
17
+ const config = Internals.useUnsafeVideoConfig();
18
+ const emitter = useContext(PlayerEventEmitterContext);
19
+ const lastFrame = ((_a = config === null || config === void 0 ? void 0 : config.durationInFrames) !== null && _a !== void 0 ? _a : 1) - 1;
20
+ const isLastFrame = frame === lastFrame;
21
+ const isFirstFrame = frame === 0;
22
+ if (!emitter) {
23
+ throw new TypeError('Expected Player event emitter context');
24
+ }
25
+ const seek = useCallback((newFrame) => {
26
+ setTimelinePosition(newFrame);
27
+ emitter.dispatchSeek(newFrame);
28
+ }, [emitter, setTimelinePosition]);
29
+ const play = useCallback((e) => {
30
+ if (imperativePlaying.current) {
31
+ return;
32
+ }
33
+ setHasPlayed(true);
34
+ if (isLastFrame) {
35
+ seek(0);
36
+ }
37
+ /**
38
+ * Play silent audio tags to warm them up for autoplay
39
+ */
40
+ if (audioContext && audioContext.numberOfAudioTags > 0 && e) {
41
+ audioContext.playAllAudios();
42
+ }
43
+ /**
44
+ * Play audios and videos directly here so they can benefit from
45
+ * being triggered by a click
46
+ */
47
+ audioAndVideoTags.current.forEach((a) => a.play());
48
+ imperativePlaying.current = true;
49
+ setPlaying(true);
50
+ playStart.current = frameRef.current;
51
+ emitter.dispatchPlay();
52
+ }, [
53
+ imperativePlaying,
54
+ isLastFrame,
55
+ audioContext,
56
+ setPlaying,
57
+ emitter,
58
+ seek,
59
+ audioAndVideoTags,
60
+ ]);
61
+ const pause = useCallback(() => {
62
+ if (imperativePlaying.current) {
63
+ imperativePlaying.current = false;
64
+ setPlaying(false);
65
+ emitter.dispatchPause();
66
+ }
67
+ }, [emitter, imperativePlaying, setPlaying]);
68
+ const pauseAndReturnToPlayStart = useCallback(() => {
69
+ if (imperativePlaying.current) {
70
+ imperativePlaying.current = false;
71
+ setTimelinePosition(playStart.current);
72
+ setPlaying(false);
73
+ emitter.dispatchPause();
74
+ }
75
+ }, [emitter, imperativePlaying, setPlaying, setTimelinePosition]);
76
+ const hasVideo = Boolean(video);
77
+ const frameBack = useCallback((frames) => {
78
+ if (!hasVideo) {
79
+ return null;
80
+ }
81
+ if (imperativePlaying.current) {
82
+ return;
83
+ }
84
+ setFrame((f) => {
85
+ return Math.max(0, f - frames);
86
+ });
87
+ }, [hasVideo, imperativePlaying, setFrame]);
88
+ const frameForward = useCallback((frames) => {
89
+ if (!hasVideo) {
90
+ return null;
91
+ }
92
+ if (imperativePlaying.current) {
93
+ return;
94
+ }
95
+ setFrame((f) => Math.min(lastFrame, f + frames));
96
+ }, [hasVideo, imperativePlaying, lastFrame, setFrame]);
97
+ const returnValue = useMemo(() => {
98
+ return {
99
+ frameBack,
100
+ frameForward,
101
+ isLastFrame,
102
+ emitter,
103
+ playing,
104
+ play,
105
+ pause,
106
+ seek,
107
+ isFirstFrame,
108
+ getCurrentFrame: () => frameRef.current,
109
+ isPlaying: () => imperativePlaying.current,
110
+ pauseAndReturnToPlayStart,
111
+ hasPlayed,
112
+ };
113
+ }, [
114
+ frameBack,
115
+ frameForward,
116
+ isLastFrame,
117
+ emitter,
118
+ playing,
119
+ play,
120
+ pause,
121
+ seek,
122
+ isFirstFrame,
123
+ pauseAndReturnToPlayStart,
124
+ imperativePlaying,
125
+ hasPlayed,
126
+ ]);
127
+ return returnValue;
128
+ };
@@ -0,0 +1,6 @@
1
+ import type { ThumbnailEmitter } from './event-emitter';
2
+ declare type UseThumbnailMethods = {
3
+ emitter: ThumbnailEmitter;
4
+ };
5
+ export declare const useThumbnail: () => UseThumbnailMethods;
6
+ export {};
@@ -0,0 +1,14 @@
1
+ import { useContext, useMemo } from 'react';
2
+ import { ThumbnailEmitterContext } from './emitter-context';
3
+ export const useThumbnail = () => {
4
+ const emitter = useContext(ThumbnailEmitterContext);
5
+ if (!emitter) {
6
+ throw new TypeError('Expected Player event emitter context');
7
+ }
8
+ const returnValue = useMemo(() => {
9
+ return {
10
+ emitter,
11
+ };
12
+ }, [emitter]);
13
+ return returnValue;
14
+ };
@@ -0,0 +1,7 @@
1
+ export declare const useVideoControlsResize: ({ allowFullscreen: allowFullScreen, playerWidth, }: {
2
+ allowFullscreen: boolean;
3
+ playerWidth: number;
4
+ }) => {
5
+ maxTimeLabelWidth: number;
6
+ displayVerticalVolumeSlider: boolean;
7
+ };
@@ -0,0 +1,32 @@
1
+ import { useMemo } from 'react';
2
+ import { fullscreenIconSize, ICON_SIZE } from './icons';
3
+ import { VOLUME_SLIDER_WIDTH } from './MediaVolumeSlider';
4
+ import { X_PADDING, X_SPACER } from './PlayerControls';
5
+ export const useVideoControlsResize = ({ allowFullscreen: allowFullScreen, playerWidth, }) => {
6
+ const resizeInfo = useMemo(() => {
7
+ const playPauseIconSize = ICON_SIZE;
8
+ const volumeIconSize = ICON_SIZE;
9
+ const _fullscreenIconSize = allowFullScreen ? fullscreenIconSize : 0;
10
+ const elementsSize = volumeIconSize +
11
+ playPauseIconSize +
12
+ _fullscreenIconSize +
13
+ X_PADDING * 2 +
14
+ X_SPACER * 2;
15
+ const maxTimeLabelWidth = playerWidth - elementsSize;
16
+ const maxTimeLabelWidthWithoutNegativeValue = Math.max(maxTimeLabelWidth, 0);
17
+ const availableTimeLabelWidthIfVolumeOpen = maxTimeLabelWidthWithoutNegativeValue - VOLUME_SLIDER_WIDTH;
18
+ // If max label width is lower than the volume width
19
+ // then it means we need to take it's width as the max label width
20
+ // otherwise we took the available width when volume open
21
+ const computedLabelWidth = availableTimeLabelWidthIfVolumeOpen < VOLUME_SLIDER_WIDTH
22
+ ? maxTimeLabelWidthWithoutNegativeValue
23
+ : availableTimeLabelWidthIfVolumeOpen;
24
+ const minWidthForHorizontalDisplay = computedLabelWidth + elementsSize + VOLUME_SLIDER_WIDTH;
25
+ const displayVerticalVolumeSlider = playerWidth < minWidthForHorizontalDisplay;
26
+ return {
27
+ maxTimeLabelWidth: maxTimeLabelWidthWithoutNegativeValue,
28
+ displayVerticalVolumeSlider,
29
+ };
30
+ }, [allowFullScreen, playerWidth]);
31
+ return resizeInfo;
32
+ };
@@ -0,0 +1,9 @@
1
+ import type { StandardLonghandProperties } from 'csstype';
2
+ import type { Size } from './use-element-size';
3
+ export declare const calculatePlayerSize: ({ currentSize, width, height, compositionWidth, compositionHeight, }: {
4
+ currentSize: Size | null;
5
+ width: StandardLonghandProperties['width'] | undefined;
6
+ height: StandardLonghandProperties['height'] | undefined;
7
+ compositionWidth: number;
8
+ compositionHeight: number;
9
+ }) => React.CSSProperties;
@@ -0,0 +1,25 @@
1
+ export const calculatePlayerSize = ({ currentSize, width, height, compositionWidth, compositionHeight, }) => {
2
+ const aspectRatio = compositionWidth / compositionHeight;
3
+ if (!currentSize) {
4
+ return {
5
+ width: compositionWidth,
6
+ height: compositionHeight,
7
+ };
8
+ }
9
+ // If has width specified, but no height, specify a default height that satisfies the aspect ratio.
10
+ if (width !== undefined && height === undefined) {
11
+ return {
12
+ height: currentSize.width / aspectRatio,
13
+ };
14
+ }
15
+ // Opposite: If has height specified, evaluate the height and specify a default width.
16
+ if (height !== undefined && width === undefined) {
17
+ return {
18
+ width: currentSize.height * aspectRatio,
19
+ };
20
+ }
21
+ return {
22
+ width: compositionWidth,
23
+ height: compositionHeight,
24
+ };
25
+ };
@@ -0,0 +1,5 @@
1
+ export declare type CancellablePromise = {
2
+ promise: Promise<unknown>;
3
+ cancel: () => void;
4
+ };
5
+ export declare const cancellablePromise: (promise: Promise<unknown>) => CancellablePromise;
@@ -0,0 +1,22 @@
1
+ export const cancellablePromise = (promise) => {
2
+ let isCanceled = false;
3
+ const wrappedPromise = new Promise((resolve, reject) => {
4
+ promise
5
+ .then((value) => {
6
+ if (isCanceled) {
7
+ reject({ isCanceled, value });
8
+ return;
9
+ }
10
+ resolve(value);
11
+ })
12
+ .catch((error) => {
13
+ reject({ isCanceled, error });
14
+ });
15
+ });
16
+ return {
17
+ promise: wrappedPromise,
18
+ cancel: () => {
19
+ isCanceled = true;
20
+ },
21
+ };
22
+ };
@@ -0,0 +1 @@
1
+ export declare const delay: (n: number) => Promise<unknown>;
@@ -0,0 +1,2 @@
1
+ /* eslint-disable no-promise-executor-return */
2
+ export const delay = (n) => new Promise((resolve) => setTimeout(resolve, n));
@@ -0,0 +1 @@
1
+ export declare const IS_NODE: boolean;
@@ -0,0 +1 @@
1
+ export const IS_NODE = typeof document === 'undefined';
@@ -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
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ export declare type PropsIfHasProps<Props> = {} extends Props ? {
2
+ inputProps?: Props;
3
+ } : {
4
+ inputProps: Props;
5
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { CancellablePromise } from './cancellable-promise';
2
+ declare const useCancellablePromises: () => {
3
+ appendPendingPromise: (promise: CancellablePromise) => void;
4
+ removePendingPromise: (promise: CancellablePromise) => void;
5
+ clearPendingPromises: () => void[];
6
+ };
7
+ export { useCancellablePromises };