@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.
- package/LICENSE.md +8 -8
- package/README.md +1 -1
- package/dist/MediaVolumeSlider.d.ts +4 -1
- package/dist/MediaVolumeSlider.js +80 -55
- package/dist/Player.d.ts +20 -15
- package/dist/Player.js +24 -70
- package/dist/PlayerControls.d.ts +29 -2
- package/dist/PlayerControls.js +66 -15
- package/dist/PlayerSeekBar.d.ts +4 -0
- package/dist/PlayerSeekBar.js +35 -11
- package/dist/PlayerUI.d.ts +18 -9
- package/dist/PlayerUI.js +118 -76
- package/dist/SharedPlayerContext.d.ts +14 -0
- package/dist/SharedPlayerContext.js +72 -0
- package/dist/Thumbnail.d.ts +20 -0
- package/dist/Thumbnail.js +42 -0
- package/dist/ThumbnailUI.d.ts +11 -0
- package/dist/ThumbnailUI.js +107 -0
- package/dist/calculate-next-frame.d.ts +0 -0
- package/dist/calculate-next-frame.js +0 -0
- package/dist/calculate-scale.d.ts +30 -5
- package/dist/calculate-scale.js +65 -4
- package/dist/cjs/MediaVolumeSlider.d.ts +5 -0
- package/dist/cjs/MediaVolumeSlider.js +118 -0
- package/dist/cjs/Player.d.ts +43 -0
- package/dist/cjs/Player.js +143 -0
- package/dist/cjs/PlayerControls.d.ts +41 -0
- package/dist/cjs/PlayerControls.js +152 -0
- package/dist/cjs/PlayerSeekBar.d.ts +8 -0
- package/dist/cjs/PlayerSeekBar.js +146 -0
- package/dist/cjs/PlayerUI.d.ts +38 -0
- package/dist/cjs/PlayerUI.js +308 -0
- package/dist/cjs/SharedPlayerContext.d.ts +14 -0
- package/dist/cjs/SharedPlayerContext.js +72 -0
- package/dist/cjs/Thumbnail.d.ts +20 -0
- package/dist/cjs/Thumbnail.js +42 -0
- package/dist/cjs/ThumbnailUI.d.ts +11 -0
- package/dist/cjs/ThumbnailUI.js +107 -0
- package/dist/cjs/calculate-next-frame.d.ts +14 -0
- package/dist/cjs/calculate-next-frame.js +28 -0
- package/dist/cjs/calculate-scale.d.ts +39 -0
- package/dist/cjs/calculate-scale.js +85 -0
- package/dist/cjs/emitter-context.d.ts +4 -0
- package/dist/cjs/emitter-context.js +9 -0
- package/dist/cjs/error-boundary.d.ts +19 -0
- package/dist/cjs/error-boundary.js +39 -0
- package/dist/cjs/event-emitter.d.ts +66 -0
- package/dist/cjs/event-emitter.js +87 -0
- package/dist/cjs/format-time.d.ts +1 -0
- package/dist/cjs/format-time.js +9 -0
- package/dist/cjs/icons.d.ts +10 -0
- package/dist/cjs/icons.js +50 -0
- package/dist/cjs/index.d.ts +60 -0
- package/dist/cjs/index.js +25 -0
- package/dist/cjs/player-css-classname.d.ts +1 -0
- package/dist/cjs/player-css-classname.js +4 -0
- package/dist/cjs/player-methods.d.ts +24 -0
- package/dist/cjs/player-methods.js +2 -0
- package/dist/cjs/test/index.test.d.ts +1 -0
- package/dist/cjs/test/index.test.js +9 -0
- package/dist/cjs/test/test-utils.d.ts +6 -0
- package/dist/cjs/test/test-utils.js +32 -0
- package/dist/cjs/test/validate-in-out-frames.test.d.ts +1 -0
- package/dist/cjs/test/validate-in-out-frames.test.js +56 -0
- package/dist/cjs/test/validate-prop.test.d.ts +1 -0
- package/dist/cjs/test/validate-prop.test.js +131 -0
- package/dist/cjs/use-hover-state.d.ts +1 -0
- package/dist/cjs/use-hover-state.js +27 -0
- package/dist/cjs/use-playback.d.ts +7 -0
- package/dist/cjs/use-playback.js +92 -0
- package/dist/cjs/use-player.d.ts +19 -0
- package/dist/cjs/use-player.js +132 -0
- package/dist/cjs/use-thumbnail.d.ts +6 -0
- package/dist/cjs/use-thumbnail.js +18 -0
- package/dist/cjs/use-video-controls-resize.d.ts +7 -0
- package/dist/cjs/use-video-controls-resize.js +36 -0
- package/dist/cjs/utils/calculate-player-size.d.ts +9 -0
- package/dist/cjs/utils/calculate-player-size.js +29 -0
- package/dist/cjs/utils/cancellable-promise.d.ts +5 -0
- package/dist/cjs/utils/cancellable-promise.js +26 -0
- package/dist/cjs/utils/delay.d.ts +1 -0
- package/dist/cjs/utils/delay.js +6 -0
- package/dist/cjs/utils/is-node.d.ts +1 -0
- package/dist/cjs/utils/is-node.js +4 -0
- package/dist/cjs/utils/preview-size.d.ts +8 -0
- package/dist/cjs/utils/preview-size.js +2 -0
- package/dist/cjs/utils/props-if-has-props.d.ts +5 -0
- package/dist/cjs/utils/props-if-has-props.js +2 -0
- package/dist/cjs/utils/use-cancellable-promises.d.ts +7 -0
- package/dist/cjs/utils/use-cancellable-promises.js +21 -0
- package/dist/cjs/utils/use-click-prevention-on-double-click.d.ts +3 -0
- package/dist/cjs/utils/use-click-prevention-on-double-click.js +45 -0
- package/dist/cjs/utils/use-element-size.d.ts +16 -0
- package/dist/cjs/utils/use-element-size.js +98 -0
- package/dist/cjs/utils/validate-in-out-frame.d.ts +6 -0
- package/dist/cjs/utils/validate-in-out-frame.js +54 -0
- package/dist/cjs/utils/validate-initial-frame.d.ts +4 -0
- package/dist/cjs/utils/validate-initial-frame.js +27 -0
- package/dist/cjs/utils/validate-playbackrate.d.ts +1 -0
- package/dist/cjs/utils/validate-playbackrate.js +18 -0
- package/dist/cjs/volume-persistance.d.ts +2 -0
- package/dist/cjs/volume-persistance.js +19 -0
- package/dist/emitter-context.d.ts +2 -1
- package/dist/emitter-context.js +2 -1
- package/dist/error-boundary.d.ts +0 -0
- package/dist/error-boundary.js +0 -0
- package/dist/esm/MediaVolumeSlider.d.ts +5 -0
- package/dist/esm/MediaVolumeSlider.js +114 -0
- package/dist/esm/Player.d.ts +43 -0
- package/dist/esm/Player.js +136 -0
- package/dist/esm/PlayerControls.d.ts +41 -0
- package/dist/esm/PlayerControls.js +148 -0
- package/dist/esm/PlayerSeekBar.d.ts +8 -0
- package/dist/esm/PlayerSeekBar.js +142 -0
- package/dist/esm/PlayerUI.d.ts +38 -0
- package/dist/esm/PlayerUI.js +283 -0
- package/dist/esm/SharedPlayerContext.d.ts +14 -0
- package/dist/esm/SharedPlayerContext.js +68 -0
- package/dist/esm/Thumbnail.d.ts +20 -0
- package/dist/esm/Thumbnail.js +35 -0
- package/dist/esm/ThumbnailUI.d.ts +11 -0
- package/dist/esm/ThumbnailUI.js +82 -0
- package/dist/esm/calculate-next-frame.d.ts +14 -0
- package/dist/esm/calculate-next-frame.js +24 -0
- package/dist/esm/calculate-scale.d.ts +39 -0
- package/dist/esm/calculate-scale.js +77 -0
- package/dist/esm/emitter-context.d.ts +4 -0
- package/dist/esm/emitter-context.js +3 -0
- package/dist/esm/error-boundary.d.ts +19 -0
- package/dist/esm/error-boundary.js +32 -0
- package/dist/esm/event-emitter.d.ts +66 -0
- package/dist/esm/event-emitter.js +82 -0
- package/dist/esm/format-time.d.ts +1 -0
- package/dist/esm/format-time.js +5 -0
- package/dist/esm/icons.d.ts +10 -0
- package/dist/esm/icons.js +42 -0
- package/dist/esm/index.d.ts +60 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/player-css-classname.d.ts +1 -0
- package/dist/esm/player-css-classname.js +1 -0
- package/dist/esm/player-methods.d.ts +24 -0
- package/dist/esm/player-methods.js +1 -0
- package/dist/esm/test/index.test.d.ts +1 -0
- package/dist/esm/test/index.test.js +7 -0
- package/dist/esm/test/test-utils.d.ts +6 -0
- package/dist/esm/test/test-utils.js +14 -0
- package/dist/esm/test/validate-in-out-frames.test.d.ts +1 -0
- package/dist/esm/test/validate-in-out-frames.test.js +54 -0
- package/dist/esm/test/validate-prop.test.d.ts +1 -0
- package/dist/esm/test/validate-prop.test.js +129 -0
- package/dist/esm/use-hover-state.d.ts +1 -0
- package/dist/esm/use-hover-state.js +23 -0
- package/dist/esm/use-playback.d.ts +7 -0
- package/dist/esm/use-playback.js +88 -0
- package/dist/esm/use-player.d.ts +19 -0
- package/dist/esm/use-player.js +128 -0
- package/dist/esm/use-thumbnail.d.ts +6 -0
- package/dist/esm/use-thumbnail.js +14 -0
- package/dist/esm/use-video-controls-resize.d.ts +7 -0
- package/dist/esm/use-video-controls-resize.js +32 -0
- package/dist/esm/utils/calculate-player-size.d.ts +9 -0
- package/dist/esm/utils/calculate-player-size.js +25 -0
- package/dist/esm/utils/cancellable-promise.d.ts +5 -0
- package/dist/esm/utils/cancellable-promise.js +22 -0
- package/dist/esm/utils/delay.d.ts +1 -0
- package/dist/esm/utils/delay.js +2 -0
- package/dist/esm/utils/is-node.d.ts +1 -0
- package/dist/esm/utils/is-node.js +1 -0
- package/dist/esm/utils/preview-size.d.ts +8 -0
- package/dist/esm/utils/preview-size.js +1 -0
- package/dist/esm/utils/props-if-has-props.d.ts +5 -0
- package/dist/esm/utils/props-if-has-props.js +1 -0
- package/dist/esm/utils/use-cancellable-promises.d.ts +7 -0
- package/dist/esm/utils/use-cancellable-promises.js +18 -0
- package/dist/esm/utils/use-click-prevention-on-double-click.d.ts +3 -0
- package/dist/esm/utils/use-click-prevention-on-double-click.js +42 -0
- package/dist/esm/utils/use-element-size.d.ts +16 -0
- package/dist/esm/utils/use-element-size.js +93 -0
- package/dist/esm/utils/validate-in-out-frame.d.ts +6 -0
- package/dist/esm/utils/validate-in-out-frame.js +49 -0
- package/dist/esm/utils/validate-initial-frame.d.ts +4 -0
- package/dist/esm/utils/validate-initial-frame.js +23 -0
- package/dist/esm/utils/validate-playbackrate.d.ts +1 -0
- package/dist/esm/utils/validate-playbackrate.js +14 -0
- package/dist/esm/volume-persistance.d.ts +2 -0
- package/dist/esm/volume-persistance.js +14 -0
- package/dist/event-emitter.d.ts +33 -9
- package/dist/event-emitter.js +33 -1
- package/dist/format-time.d.ts +0 -0
- package/dist/format-time.js +0 -0
- package/dist/icons.d.ts +2 -1
- package/dist/icons.js +7 -7
- package/dist/index.d.ts +25 -9
- package/dist/index.js +5 -2
- package/dist/player-css-classname.d.ts +0 -1
- package/dist/player-css-classname.js +1 -2
- package/dist/player-methods.d.ts +8 -4
- package/dist/player-methods.js +0 -0
- package/dist/test/index.test.d.ts +0 -0
- package/dist/test/index.test.js +3 -2
- package/dist/test/test-utils.d.ts +2 -2
- package/dist/test/test-utils.js +0 -0
- package/dist/test/validate-in-out-frames.test.d.ts +1 -0
- package/dist/test/validate-in-out-frames.test.js +56 -0
- package/dist/test/validate-prop.test.d.ts +0 -0
- package/dist/test/validate-prop.test.js +24 -23
- package/dist/tsconfig-cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/use-hover-state.d.ts +0 -0
- package/dist/use-hover-state.js +0 -0
- package/dist/use-playback.d.ts +4 -1
- package/dist/use-playback.js +7 -3
- package/dist/use-player.d.ts +8 -3
- package/dist/use-player.js +23 -4
- package/dist/use-thumbnail.d.ts +6 -0
- package/dist/use-thumbnail.js +18 -0
- package/dist/use-video-controls-resize.d.ts +7 -0
- package/dist/use-video-controls-resize.js +36 -0
- package/dist/utils/calculate-player-size.d.ts +2 -2
- package/dist/utils/calculate-player-size.js +0 -0
- package/dist/utils/cancellable-promise.d.ts +0 -0
- package/dist/utils/cancellable-promise.js +0 -0
- package/dist/utils/delay.d.ts +0 -0
- package/dist/utils/delay.js +0 -0
- package/dist/utils/is-node.d.ts +0 -0
- package/dist/utils/is-node.js +0 -0
- package/dist/utils/preview-size.d.ts +8 -1
- package/dist/utils/preview-size.js +0 -0
- package/dist/utils/props-if-has-props.d.ts +5 -0
- package/dist/utils/props-if-has-props.js +2 -0
- package/dist/utils/use-cancellable-promises.d.ts +1 -1
- package/dist/utils/use-cancellable-promises.js +0 -0
- package/dist/utils/use-click-prevention-on-double-click.d.ts +1 -1
- package/dist/utils/use-click-prevention-on-double-click.js +0 -0
- package/dist/utils/use-element-size.d.ts +4 -0
- package/dist/utils/use-element-size.js +8 -0
- package/dist/utils/validate-in-out-frame.d.ts +6 -0
- package/dist/utils/validate-in-out-frame.js +54 -0
- package/dist/utils/validate-initial-frame.d.ts +4 -0
- package/dist/utils/validate-initial-frame.js +27 -0
- package/dist/utils/validate-playbackrate.d.ts +0 -0
- package/dist/utils/validate-playbackrate.js +0 -0
- package/dist/volume-persistance.d.ts +0 -0
- package/dist/volume-persistance.js +0 -0
- package/package.json +26 -17
- package/dist/MediaVolumeSlider.d.ts.map +0 -1
- package/dist/MediaVolumeSlider.js.map +0 -1
- package/dist/Player.d.ts.map +0 -1
- package/dist/Player.js.map +0 -1
- package/dist/PlayerControls.d.ts.map +0 -1
- package/dist/PlayerControls.js.map +0 -1
- package/dist/PlayerSeekBar.d.ts.map +0 -1
- package/dist/PlayerSeekBar.js.map +0 -1
- package/dist/PlayerUI.d.ts.map +0 -1
- package/dist/PlayerUI.js.map +0 -1
- package/dist/calculate-next-frame.d.ts.map +0 -1
- package/dist/calculate-next-frame.js.map +0 -1
- package/dist/calculate-scale.d.ts.map +0 -1
- package/dist/calculate-scale.js.map +0 -1
- package/dist/emitter-context.d.ts.map +0 -1
- package/dist/emitter-context.js.map +0 -1
- package/dist/error-boundary.d.ts.map +0 -1
- package/dist/error-boundary.js.map +0 -1
- package/dist/event-emitter.d.ts.map +0 -1
- package/dist/event-emitter.js.map +0 -1
- package/dist/format-time.d.ts.map +0 -1
- package/dist/format-time.js.map +0 -1
- package/dist/icons.d.ts.map +0 -1
- package/dist/icons.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/player-css-classname.d.ts.map +0 -1
- package/dist/player-css-classname.js.map +0 -1
- package/dist/player-methods.d.ts.map +0 -1
- package/dist/player-methods.js.map +0 -1
- package/dist/test/index.test.d.ts.map +0 -1
- package/dist/test/index.test.js.map +0 -1
- package/dist/test/test-utils.d.ts.map +0 -1
- package/dist/test/test-utils.js.map +0 -1
- package/dist/test/validate-prop.test.d.ts.map +0 -1
- package/dist/test/validate-prop.test.js.map +0 -1
- package/dist/use-hover-state.d.ts.map +0 -1
- package/dist/use-hover-state.js.map +0 -1
- package/dist/use-playback.d.ts.map +0 -1
- package/dist/use-playback.js.map +0 -1
- package/dist/use-player.d.ts.map +0 -1
- package/dist/use-player.js.map +0 -1
- package/dist/utils/browser-supports-fullscreen.d.ts +0 -11
- package/dist/utils/browser-supports-fullscreen.d.ts.map +0 -1
- package/dist/utils/browser-supports-fullscreen.js +0 -5
- package/dist/utils/browser-supports-fullscreen.js.map +0 -1
- package/dist/utils/calculate-player-size.d.ts.map +0 -1
- package/dist/utils/calculate-player-size.js.map +0 -1
- package/dist/utils/cancellable-promise.d.ts.map +0 -1
- package/dist/utils/cancellable-promise.js.map +0 -1
- package/dist/utils/delay.d.ts.map +0 -1
- package/dist/utils/delay.js.map +0 -1
- package/dist/utils/is-node.d.ts.map +0 -1
- package/dist/utils/is-node.js.map +0 -1
- package/dist/utils/preview-size.d.ts.map +0 -1
- package/dist/utils/preview-size.js.map +0 -1
- package/dist/utils/use-cancellable-promises.d.ts.map +0 -1
- package/dist/utils/use-cancellable-promises.js.map +0 -1
- package/dist/utils/use-click-prevention-on-double-click.d.ts.map +0 -1
- package/dist/utils/use-click-prevention-on-double-click.js.map +0 -1
- package/dist/utils/use-element-size.d.ts.map +0 -1
- package/dist/utils/use-element-size.js.map +0 -1
- package/dist/utils/validate-playbackrate.d.ts.map +0 -1
- package/dist/utils/validate-playbackrate.js.map +0 -1
- package/dist/volume-persistance.d.ts.map +0 -1
- 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,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,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,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,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 @@
|
|
|
1
|
+
export declare const IS_NODE: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const IS_NODE = typeof document === 'undefined';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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 };
|