remotion 3.3.55 → 3.3.56

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 (143) hide show
  1. package/dist/cjs/audio/Audio.d.ts +1 -1
  2. package/dist/cjs/index.d.ts +1 -0
  3. package/dist/cjs/internals.d.ts +1 -1
  4. package/dist/cjs/use-video.d.ts +1 -1
  5. package/dist/cjs/version.d.ts +1 -1
  6. package/dist/cjs/version.js +1 -1
  7. package/dist/esm/index.mjs +1 -1
  8. package/dist/esm/version.mjs +1 -1
  9. package/dist/tsconfig-esm.tsbuildinfo +1 -0
  10. package/package.json +3 -3
  11. package/tsconfig-esm.json +12 -0
  12. package/dist/esm/AbsoluteFill.js +0 -25
  13. package/dist/esm/CanUseRemotionHooks.js +0 -6
  14. package/dist/esm/Clipper.js +0 -20
  15. package/dist/esm/Composition.js +0 -112
  16. package/dist/esm/CompositionManager.js +0 -137
  17. package/dist/esm/Folder.js +0 -33
  18. package/dist/esm/IFrame.js +0 -25
  19. package/dist/esm/Img.js +0 -53
  20. package/dist/esm/NativeLayers.js +0 -25
  21. package/dist/esm/Null.js +0 -21
  22. package/dist/esm/RemotionRoot.js +0 -69
  23. package/dist/esm/Sequence.js +0 -128
  24. package/dist/esm/SequenceContext.js +0 -2
  25. package/dist/esm/Still.js +0 -9
  26. package/dist/esm/absolute-src.js +0 -3
  27. package/dist/esm/asset-types.js +0 -1
  28. package/dist/esm/audio/Audio.js +0 -53
  29. package/dist/esm/audio/AudioForDevelopment.js +0 -91
  30. package/dist/esm/audio/AudioForRendering.js +0 -108
  31. package/dist/esm/audio/index.js +0 -2
  32. package/dist/esm/audio/props.js +0 -1
  33. package/dist/esm/audio/shared-audio-tags.js +0 -194
  34. package/dist/esm/audio/use-audio-frame.js +0 -18
  35. package/dist/esm/bezier.js +0 -110
  36. package/dist/esm/cancel-render.js +0 -43
  37. package/dist/esm/config/input-props.js +0 -27
  38. package/dist/esm/config.js +0 -17
  39. package/dist/esm/default-css.js +0 -44
  40. package/dist/esm/delay-render.js +0 -72
  41. package/dist/esm/easing.js +0 -77
  42. package/dist/esm/freeze.js +0 -34
  43. package/dist/esm/get-asset-file-name.js +0 -10
  44. package/dist/esm/get-environment.js +0 -29
  45. package/dist/esm/get-preview-dom-element.js +0 -3
  46. package/dist/esm/get-static-files.js +0 -31
  47. package/dist/esm/get-timeline-clip-name.js +0 -21
  48. package/dist/esm/index.js +0 -49
  49. package/dist/esm/internals.js +0 -75
  50. package/dist/esm/interpolate-colors.js +0 -401
  51. package/dist/esm/interpolate.js +0 -123
  52. package/dist/esm/is-approximately-the-same.js +0 -4
  53. package/dist/esm/is-player.js +0 -9
  54. package/dist/esm/loading-indicator.js +0 -31
  55. package/dist/esm/loop/index.js +0 -29
  56. package/dist/esm/multiple-versions-warning.js +0 -28
  57. package/dist/esm/nonce.js +0 -13
  58. package/dist/esm/play-and-handle-not-allowed-error.js +0 -40
  59. package/dist/esm/portal-node.js +0 -19
  60. package/dist/esm/prefetch-state.js +0 -22
  61. package/dist/esm/prefetch.js +0 -107
  62. package/dist/esm/random.js +0 -37
  63. package/dist/esm/register-root.js +0 -31
  64. package/dist/esm/series/flatten-children.js +0 -12
  65. package/dist/esm/series/index.js +0 -61
  66. package/dist/esm/setup-env-variables.js +0 -32
  67. package/dist/esm/spring/index.js +0 -50
  68. package/dist/esm/spring/measure-spring.js +0 -64
  69. package/dist/esm/spring/spring-utils.js +0 -99
  70. package/dist/esm/static-file.js +0 -29
  71. package/dist/esm/test/Img.test.js +0 -20
  72. package/dist/esm/test/absolute-src.test.js +0 -16
  73. package/dist/esm/test/audio-for-rendering.test.js +0 -83
  74. package/dist/esm/test/audio.test.js +0 -51
  75. package/dist/esm/test/bezier.test.js +0 -50
  76. package/dist/esm/test/composition-rules.test.js +0 -28
  77. package/dist/esm/test/composition-validation.test.js +0 -97
  78. package/dist/esm/test/easing.test.js +0 -189
  79. package/dist/esm/test/expect-to-throw.js +0 -11
  80. package/dist/esm/test/freeze.test.js +0 -63
  81. package/dist/esm/test/get-asset-file-name.test.js +0 -12
  82. package/dist/esm/test/get-current-time.test.js +0 -72
  83. package/dist/esm/test/input-props.test.js +0 -29
  84. package/dist/esm/test/interpolate.test.js +0 -136
  85. package/dist/esm/test/interpolateColors.test.js +0 -61
  86. package/dist/esm/test/loop-validation.test.js +0 -68
  87. package/dist/esm/test/measure-spring.test.js +0 -43
  88. package/dist/esm/test/media-validation.test.js +0 -45
  89. package/dist/esm/test/nested-sequences.test.js +0 -130
  90. package/dist/esm/test/not-all-props-in-media-tags.test.js +0 -28
  91. package/dist/esm/test/random.test.js +0 -58
  92. package/dist/esm/test/ready-manager.test.js +0 -27
  93. package/dist/esm/test/render-hook.js +0 -20
  94. package/dist/esm/test/sequence-from-initial-offset.test.js +0 -33
  95. package/dist/esm/test/sequence-validation.test.js +0 -45
  96. package/dist/esm/test/series.test.js +0 -113
  97. package/dist/esm/test/spring.test.js +0 -36
  98. package/dist/esm/test/truthy.test.js +0 -22
  99. package/dist/esm/test/use-audio-frame.test.js +0 -53
  100. package/dist/esm/test/use-media-in-timeline.test.js +0 -49
  101. package/dist/esm/test/use-media-tag-volume.test.js +0 -44
  102. package/dist/esm/test/use-sync-volume-with-media-tag.test.js +0 -53
  103. package/dist/esm/test/validate-start-from-props.test.js +0 -37
  104. package/dist/esm/test/video.test.js +0 -55
  105. package/dist/esm/test/volume-prop.test.js +0 -93
  106. package/dist/esm/test/wrap-sequence-context.js +0 -37
  107. package/dist/esm/timeline-position-state.js +0 -35
  108. package/dist/esm/truthy.js +0 -3
  109. package/dist/esm/use-current-frame.js +0 -23
  110. package/dist/esm/use-lazy-component.js +0 -22
  111. package/dist/esm/use-media-in-timeline.js +0 -125
  112. package/dist/esm/use-media-playback.js +0 -73
  113. package/dist/esm/use-media-tag-volume.js +0 -27
  114. package/dist/esm/use-sync-volume-with-media-tag.js +0 -17
  115. package/dist/esm/use-unsafe-video-config.js +0 -23
  116. package/dist/esm/use-video-config.js +0 -26
  117. package/dist/esm/use-video.js +0 -24
  118. package/dist/esm/validate-frame.js +0 -20
  119. package/dist/esm/validate-media-props.js +0 -20
  120. package/dist/esm/validate-start-from-props.js +0 -27
  121. package/dist/esm/validation/validate-composition-id.js +0 -8
  122. package/dist/esm/validation/validate-dimensions.js +0 -17
  123. package/dist/esm/validation/validate-duration-in-frames.js +0 -11
  124. package/dist/esm/validation/validate-folder-name.js +0 -14
  125. package/dist/esm/validation/validate-fps.js +0 -17
  126. package/dist/esm/validation/validate-offthreadvideo-image-format.js +0 -11
  127. package/dist/esm/validation/validation-spring-duration.js +0 -17
  128. package/dist/esm/version.js +0 -2
  129. package/dist/esm/video/OffthreadVideo.js +0 -33
  130. package/dist/esm/video/OffthreadVideoForRendering.js +0 -100
  131. package/dist/esm/video/Video.js +0 -51
  132. package/dist/esm/video/VideoForDevelopment.js +0 -110
  133. package/dist/esm/video/VideoForRendering.js +0 -200
  134. package/dist/esm/video/duration-state.js +0 -29
  135. package/dist/esm/video/get-current-time.js +0 -26
  136. package/dist/esm/video/index.js +0 -2
  137. package/dist/esm/video/props.js +0 -1
  138. package/dist/esm/video/video-fragment.js +0 -55
  139. package/dist/esm/video-config.js +0 -1
  140. package/dist/esm/volume-position-state.js +0 -27
  141. package/dist/esm/volume-prop.js +0 -20
  142. package/dist/esm/warn-about-non-seekable-media.js +0 -30
  143. package/dist/esm/wrap-remotion-context.js +0 -45
@@ -1,53 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { afterAll, beforeAll, describe, expect, test, vitest } from 'vitest';
3
- import * as useAudioFrameModule from '../audio/use-audio-frame.js';
4
- import { useFrameForVolumeProp, useMediaStartsAt, } from '../audio/use-audio-frame.js';
5
- import { SequenceContext } from '../SequenceContext.js';
6
- import * as useFrameModule from '../use-current-frame.js';
7
- import { renderHook } from './render-hook.js';
8
- test.skip('Media starts at 0 if it is outside a sequence', () => {
9
- const wrapper = ({ children }) => (_jsx(SequenceContext.Provider, { value: null, children: children }));
10
- const { result } = renderHook(() => useMediaStartsAt(), { wrapper });
11
- expect(result.current).toEqual(0);
12
- });
13
- test.skip('Media start is shifted back based on sequence', () => {
14
- const mockSequence = {
15
- cumulatedFrom: 0,
16
- relativeFrom: -100,
17
- parentFrom: 0,
18
- durationInFrames: 0,
19
- id: 'mock',
20
- };
21
- const wrapper = ({ children }) => (_jsx(SequenceContext.Provider, { value: mockSequence, children: children }));
22
- const { result } = renderHook(() => useMediaStartsAt(), { wrapper });
23
- expect(result.current).toEqual(-100);
24
- });
25
- describe('useFrameForVolumeProp hook tests', () => {
26
- beforeAll(() => {
27
- vitest
28
- .spyOn(useAudioFrameModule, 'useMediaStartsAt')
29
- .mockImplementation(() => -10);
30
- });
31
- afterAll(() => {
32
- vitest.spyOn(useAudioFrameModule, 'useMediaStartsAt').mockRestore();
33
- });
34
- test.skip('Media not mounted', () => {
35
- vitest.spyOn(useFrameModule, 'useCurrentFrame').mockImplementation(() => 9);
36
- const { result } = renderHook(() => useFrameForVolumeProp());
37
- expect(result.current).toEqual(-1);
38
- });
39
- test.skip('Media mounted', () => {
40
- vitest
41
- .spyOn(useFrameModule, 'useCurrentFrame')
42
- .mockImplementation(() => 10);
43
- const { result } = renderHook(() => useFrameForVolumeProp());
44
- expect(result.current).toEqual(0);
45
- });
46
- test.skip('Media mounted + 1 frame', () => {
47
- vitest
48
- .spyOn(useFrameModule, 'useCurrentFrame')
49
- .mockImplementation(() => 11);
50
- const { result } = renderHook(() => useFrameForVolumeProp());
51
- expect(result.current).toEqual(1);
52
- });
53
- });
@@ -1,49 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { afterAll, beforeAll, expect, test, vitest } from 'vitest';
3
- import { Internals } from '../internals.js';
4
- import { useMediaInTimeline } from '../use-media-in-timeline.js';
5
- import * as useVideoConfigModule from '../use-video-config.js';
6
- import { renderHook } from './render-hook.js';
7
- import { mockCompositionContext } from './wrap-sequence-context.js';
8
- beforeAll(() => {
9
- vitest
10
- .spyOn(useVideoConfigModule, 'useVideoConfig')
11
- .mockImplementation(() => ({
12
- width: 10,
13
- height: 10,
14
- fps: 30,
15
- durationInFrames: 100,
16
- id: 'hithere',
17
- defaultProps: () => ({}),
18
- }));
19
- });
20
- afterAll(() => {
21
- vitest.spyOn(useVideoConfigModule, 'useVideoConfig').mockClear();
22
- });
23
- test('useMediaInTimeline registers and unregisters new sequence', () => {
24
- const registerSequence = vitest.fn();
25
- const unregisterSequence = vitest.fn();
26
- const wrapper = ({ children }) => (_jsx(Internals.CompositionManager.Provider, { value:
27
- // eslint-disable-next-line react/jsx-no-constructed-context-values
28
- {
29
- ...mockCompositionContext,
30
- registerSequence,
31
- unregisterSequence,
32
- }, children: children }));
33
- const audioRef = {
34
- current: { volume: 0.5 },
35
- };
36
- const { unmount } = renderHook(() => useMediaInTimeline({
37
- volume: 1,
38
- src: 'test',
39
- mediaVolume: 1,
40
- mediaType: 'audio',
41
- mediaRef: audioRef,
42
- playbackRate: 1,
43
- }), {
44
- wrapper,
45
- });
46
- expect(registerSequence).toHaveBeenCalled();
47
- unmount();
48
- expect(unregisterSequence).toHaveBeenCalled();
49
- });
@@ -1,44 +0,0 @@
1
- import React from 'react';
2
- import { afterEach, beforeEach, describe, expect, test, vitest } from 'vitest';
3
- import { useMediaTagVolume } from '../use-media-tag-volume.js';
4
- import { renderHook } from './render-hook.js';
5
- describe('Should update state when volume changes', () => {
6
- const setState = vitest.fn();
7
- const useStateSpy = vitest.spyOn(React, 'useState');
8
- beforeEach(() => {
9
- // @ts-expect-error
10
- useStateSpy.mockImplementation((init) => [init, setState]);
11
- });
12
- afterEach(() => {
13
- useStateSpy.mockRestore();
14
- });
15
- test.skip('has the volume been set', () => {
16
- const addEventListener = vitest.fn();
17
- const removeEventListener = vitest.fn();
18
- let audioRef = {
19
- current: { volume: 0.5, addEventListener, removeEventListener },
20
- };
21
- const { rerender } = renderHook(({ mediaRef }) => useMediaTagVolume(mediaRef), {
22
- initialProps: { mediaRef: audioRef },
23
- });
24
- expect(setState).toHaveBeenCalledWith(0.5);
25
- audioRef = {
26
- current: { ...audioRef.current, volume: 0.75 },
27
- };
28
- rerender({ mediaRef: audioRef });
29
- expect(setState).toHaveBeenCalledWith(0.75);
30
- expect(addEventListener).toHaveBeenCalledWith('volumechange', expect.anything());
31
- expect(removeEventListener).toHaveBeenCalledWith('volumechange', expect.anything());
32
- });
33
- });
34
- test('Should listen for volume changes', () => {
35
- const addEventListener = vitest.fn();
36
- const removeEventListener = vitest.fn();
37
- const audioRef = {
38
- current: { volume: 0.5, addEventListener, removeEventListener },
39
- };
40
- renderHook(({ mediaRef }) => useMediaTagVolume(mediaRef), {
41
- initialProps: { mediaRef: audioRef },
42
- });
43
- expect(addEventListener).toHaveBeenCalledTimes(1);
44
- });
@@ -1,53 +0,0 @@
1
- import { expect, test, vitest } from 'vitest';
2
- import { useSyncVolumeWithMediaTag } from '../use-sync-volume-with-media-tag.js';
3
- import { renderHook } from './render-hook.js';
4
- test('has the volume been adapted', () => {
5
- var _a, _b;
6
- const addEventListener = vitest.fn();
7
- const removeEventListener = vitest.fn();
8
- const audioRef = {
9
- current: { volume: 0.5, addEventListener, removeEventListener },
10
- };
11
- const volume = 0.6;
12
- const volumePropFrame = 1;
13
- const actualVolume = 0.4;
14
- const initialProps = {
15
- volumePropFrame,
16
- actualVolume,
17
- volume,
18
- mediaRef: audioRef,
19
- mediaVolume: 1,
20
- };
21
- const { rerender } = renderHook((hookProps) => useSyncVolumeWithMediaTag(hookProps), {
22
- initialProps,
23
- });
24
- expect((_a = audioRef.current) === null || _a === void 0 ? void 0 : _a.volume).toEqual(initialProps.volume);
25
- const newVolume = 0.5;
26
- rerender({
27
- ...initialProps,
28
- volume: newVolume,
29
- });
30
- expect((_b = audioRef.current) === null || _b === void 0 ? void 0 : _b.volume).toEqual(newVolume);
31
- });
32
- test('volume should not be adapted', () => {
33
- var _a;
34
- const addEventListener = vitest.fn();
35
- const removeEventListener = vitest.fn();
36
- const audioRef = {
37
- current: { volume: 0.4, addEventListener, removeEventListener },
38
- };
39
- const volume = 0.4;
40
- const volumePropFrame = 1;
41
- const actualVolume = 0.4;
42
- const initialProps = {
43
- volumePropFrame,
44
- actualVolume,
45
- volume,
46
- mediaRef: audioRef,
47
- mediaVolume: 1,
48
- };
49
- renderHook((hookProps) => useSyncVolumeWithMediaTag(hookProps), {
50
- initialProps,
51
- });
52
- expect((_a = audioRef.current) === null || _a === void 0 ? void 0 : _a.volume).toEqual(initialProps.volume);
53
- });
@@ -1,37 +0,0 @@
1
- import { describe, test } from 'vitest';
2
- import { validateStartFromProps } from '../validate-start-from-props.js';
3
- import { expectToThrow } from './expect-to-throw.js';
4
- describe('ValidateStartFrom props should throw', () => {
5
- describe('Throw with invalid startFrom prop', () => {
6
- test('It should throw if startFrom prop is negative', () => {
7
- expectToThrow(() => validateStartFromProps(-40, 1), /startFrom must be greater than equal to 0 instead got -40./);
8
- });
9
- test('It should throw if startFrom is not a number', () => {
10
- expectToThrow(
11
- // @ts-expect-error
12
- () => validateStartFromProps('10', 20), /type of startFrom prop must be a number, instead got type string./);
13
- });
14
- test('It should throw if startFrom is NaN', () => {
15
- expectToThrow(() => validateStartFromProps(NaN, 20), /startFrom prop can not be NaN or Infinity./);
16
- });
17
- test('It should throw if startFrom is Infinity', () => {
18
- expectToThrow(() => validateStartFromProps(Infinity, 20), /startFrom prop can not be NaN or Infinity./);
19
- });
20
- });
21
- describe('Throw with invalid endAt prop', () => {
22
- test('It should throw if endAt prop is negative', () => {
23
- expectToThrow(() => validateStartFromProps(0, -40), /endAt must be a positive number, instead got -40./);
24
- });
25
- test('It should throw if endAt is less than startFrom', () => {
26
- expectToThrow(() => validateStartFromProps(10, 1), /endAt prop must be greater than startFrom prop./);
27
- });
28
- test('It should throw if endAt is not a number', () => {
29
- expectToThrow(
30
- // @ts-expect-error
31
- () => validateStartFromProps(10, '20'), /type of endAt prop must be a number, instead got type string./);
32
- });
33
- test('It should throw if endAt is NaN', () => {
34
- expectToThrow(() => validateStartFromProps(10, NaN), /endAt prop can not be NaN./);
35
- });
36
- });
37
- });
@@ -1,55 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- /**
3
- * @vitest-environment jsdom
4
- */
5
- import { render } from '@testing-library/react';
6
- import React, { useContext } from 'react';
7
- import { describe, expect, test } from 'vitest';
8
- import { CanUseRemotionHooksProvider } from '../CanUseRemotionHooks.js';
9
- import { Internals } from '../internals.js';
10
- import { Video } from '../video/index.js';
11
- import { expectToThrow } from './expect-to-throw.js';
12
- const Wrapper = ({ children }) => {
13
- const compositions = useContext(Internals.CompositionManager);
14
- return (_jsx(CanUseRemotionHooksProvider, { children: _jsx(Internals.RemotionRoot, { numberOfAudioTags: 0, children: _jsx(Internals.CompositionManager.Provider
15
- // eslint-disable-next-line react/jsx-no-constructed-context-values
16
- , {
17
- // eslint-disable-next-line react/jsx-no-constructed-context-values
18
- value: {
19
- ...compositions,
20
- compositions: [
21
- {
22
- height: 1080,
23
- width: 1080,
24
- fps: 30,
25
- durationInFrames: 30,
26
- id: 'markup',
27
- nonce: 0,
28
- component: React.lazy(() => Promise.resolve({
29
- default: (() => null),
30
- })),
31
- defaultProps: undefined,
32
- folderName: null,
33
- parentFolderName: null,
34
- },
35
- ],
36
- currentComposition: 'markup',
37
- }, children: children }) }) }));
38
- };
39
- describe('Render correctly with props', () => {
40
- test('It should render Video without startFrom / endAt props', () => {
41
- expect(() => render(_jsx(Wrapper, { children: _jsx(Video, { src: "test" }) }))).not.toThrow();
42
- });
43
- test('It should render Video with startFrom props', () => {
44
- expect(() => render(_jsx(Wrapper, { children: _jsx(Video, { src: "test", startFrom: 10 }) }))).not.toThrow();
45
- });
46
- test('It should render Video with endAt props', () => {
47
- expect(() => render(_jsx(Wrapper, { children: _jsx(Video, { src: "test", endAt: 10 }) }))).not.toThrow();
48
- });
49
- test('It should render Video with startFrom and endAt props', () => {
50
- expect(() => render(_jsx(Wrapper, { children: _jsx(Video, { src: "test", startFrom: 10, endAt: 15 }) }))).not.toThrow();
51
- });
52
- test('It should throw if videoConfig/Wrapper is missing', () => {
53
- expectToThrow(() => render(_jsx(CanUseRemotionHooksProvider, { children: _jsx(Video, { startFrom: 10, endAt: 15 }) })), /No video config found/);
54
- });
55
- });
@@ -1,93 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { evaluateVolume } from '../volume-prop.js';
3
- import { expectToThrow } from './expect-to-throw.js';
4
- describe('EvaluateVolume does not throw', () => {
5
- test('Volume is undefined', () => {
6
- const toEvaluate = {
7
- frame: 10,
8
- volume: undefined,
9
- mediaVolume: 1,
10
- allowAmplificationDuringRender: false,
11
- };
12
- expect(evaluateVolume(toEvaluate)).toEqual(1);
13
- });
14
- test('Volume is smaller than one', () => {
15
- const smallVolume = 0.5;
16
- const toEvaluate = {
17
- frame: 10,
18
- volume: smallVolume,
19
- mediaVolume: 1,
20
- allowAmplificationDuringRender: false,
21
- };
22
- expect(evaluateVolume(toEvaluate)).toEqual(smallVolume);
23
- });
24
- test('Volume is bigger than one', () => {
25
- const toEvaluate = {
26
- frame: 10,
27
- volume: 10,
28
- mediaVolume: 1,
29
- allowAmplificationDuringRender: true,
30
- };
31
- expect(evaluateVolume(toEvaluate)).toBe(10);
32
- });
33
- test('evaluated volume from frame that is smaller than one', () => {
34
- const toEvaluate = {
35
- frame: 1,
36
- volume: (frame) => frame * 0.5,
37
- mediaVolume: 1,
38
- allowAmplificationDuringRender: false,
39
- };
40
- expect(evaluateVolume(toEvaluate)).toBe(0.5);
41
- });
42
- test('evaluated volume from frame that is bigger than one', () => {
43
- const toEvaluate = {
44
- frame: 10,
45
- volume: (frame) => frame,
46
- mediaVolume: 1,
47
- allowAmplificationDuringRender: false,
48
- };
49
- expect(evaluateVolume(toEvaluate)).toBe(1);
50
- });
51
- });
52
- describe('evaluateVolume throws exception', () => {
53
- test('It should throw if volume prop is neither number nor undefined', () => {
54
- const toEvaluate = { frame: 10, volume: 'NaN' };
55
- expectToThrow(() => {
56
- // @ts-expect-error
57
- evaluateVolume(toEvaluate);
58
- }, /volume is not a function/);
59
- });
60
- test('It should throw if volume is invalid type', () => {
61
- const invalidVolume = 'anystring';
62
- const toEvaluate = { frame: 1, volume: () => invalidVolume, mediaVolume: 1 };
63
- // changing the test because string multiply by a number in javascript is `NaN`
64
- expectToThrow(() => {
65
- // @ts-expect-error
66
- evaluateVolume(toEvaluate);
67
- }, /You passed in a function to the volume prop but it returned NaN for frame 1./);
68
- });
69
- test('It should throw if volume is NaN', () => {
70
- const invalidVolume = NaN;
71
- const toEvaluate = {
72
- frame: 1,
73
- volume: () => invalidVolume,
74
- mediaVolume: 1,
75
- allowAmplificationDuringRender: false,
76
- };
77
- expectToThrow(() => {
78
- evaluateVolume(toEvaluate);
79
- }, /You passed in a function to the volume prop but it returned NaN for frame 1/);
80
- });
81
- test('It should throw if volume returns non finite number', () => {
82
- const invalidVolume = Infinity;
83
- const toEvaluate = {
84
- frame: 1,
85
- volume: () => invalidVolume,
86
- mediaVolume: 1,
87
- allowAmplificationDuringRender: false,
88
- };
89
- expectToThrow(() => {
90
- evaluateVolume(toEvaluate);
91
- }, /You passed in a function to the volume prop but it returned a non-finite number for frame 1/);
92
- });
93
- });
@@ -1,37 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { CanUseRemotionHooksProvider } from '../CanUseRemotionHooks.js';
3
- import { CompositionManager } from '../CompositionManager.js';
4
- const Comp = () => null;
5
- export const mockCompositionContext = {
6
- assets: [],
7
- compositions: [
8
- {
9
- id: 'my-comp',
10
- durationInFrames: 100,
11
- // @ts-expect-error
12
- component: Comp,
13
- defaultProps: {},
14
- folderName: null,
15
- fps: 30,
16
- height: 1080,
17
- width: 1080,
18
- parentFolderName: null,
19
- nonce: 0,
20
- },
21
- ],
22
- currentComposition: 'my-comp',
23
- folders: [],
24
- registerAsset: () => undefined,
25
- registerComposition: () => undefined,
26
- registerFolder: () => undefined,
27
- registerSequence: () => undefined,
28
- sequences: [],
29
- setCurrentComposition: () => undefined,
30
- unregisterAsset: () => undefined,
31
- unregisterComposition: () => undefined,
32
- unregisterFolder: () => undefined,
33
- unregisterSequence: () => undefined,
34
- };
35
- export const WrapSequenceContext = ({ children }) => {
36
- return (_jsx(CanUseRemotionHooksProvider, { children: _jsx(CompositionManager.Provider, { value: mockCompositionContext, children: children }) }));
37
- };
@@ -1,35 +0,0 @@
1
- import { createContext, useContext, useMemo } from 'react';
2
- export const TimelineContext = createContext({
3
- frame: 0,
4
- playing: false,
5
- playbackRate: 1,
6
- rootId: '',
7
- imperativePlaying: {
8
- current: false,
9
- },
10
- setPlaybackRate: () => {
11
- throw new Error('default');
12
- },
13
- audioAndVideoTags: { current: [] },
14
- });
15
- export const SetTimelineContext = createContext({
16
- setFrame: () => {
17
- throw new Error('default');
18
- },
19
- setPlaying: () => {
20
- throw new Error('default');
21
- },
22
- });
23
- export const useTimelinePosition = () => {
24
- const state = useContext(TimelineContext);
25
- return state.frame;
26
- };
27
- export const useTimelineSetFrame = () => {
28
- const { setFrame } = useContext(SetTimelineContext);
29
- return setFrame;
30
- };
31
- export const usePlayingState = () => {
32
- const { playing, imperativePlaying } = useContext(TimelineContext);
33
- const { setPlaying } = useContext(SetTimelineContext);
34
- return useMemo(() => [playing, setPlaying, imperativePlaying], [imperativePlaying, playing, setPlaying]);
35
- };
@@ -1,3 +0,0 @@
1
- export function truthy(value) {
2
- return Boolean(value);
3
- }
@@ -1,23 +0,0 @@
1
- import { useContext } from 'react';
2
- import { CanUseRemotionHooks } from './CanUseRemotionHooks.js';
3
- import { SequenceContext } from './SequenceContext.js';
4
- import { useTimelinePosition } from './timeline-position-state.js';
5
- /**
6
- * @description Get the current frame of the video. Frames are 0-indexed, meaning the first frame is 0, the last frame is the duration of the composition in frames minus one.
7
- * @see [Documentation](https://remotion.dev/docs/use-current-frame)
8
- */
9
- export const useCurrentFrame = () => {
10
- const canUseRemotionHooks = useContext(CanUseRemotionHooks);
11
- if (!canUseRemotionHooks) {
12
- if (typeof window !== 'undefined' && window.remotion_isPlayer) {
13
- throw new Error(`useCurrentFrame can only be called inside a component that was passed to <Player>. See: https://www.remotion.dev/docs/player/examples`);
14
- }
15
- throw new Error(`useCurrentFrame() can only be called inside a component that was registered as a composition. See https://www.remotion.dev/docs/the-fundamentals#defining-compositions`);
16
- }
17
- const frame = useTimelinePosition();
18
- const context = useContext(SequenceContext);
19
- const contextOffset = context
20
- ? context.cumulatedFrom + context.relativeFrom
21
- : 0;
22
- return frame - contextOffset;
23
- };
@@ -1,22 +0,0 @@
1
- import React, { useMemo } from 'react';
2
- // Expected, it can be any component props
3
- export const useLazyComponent = (compProps) => {
4
- const lazy = useMemo(() => {
5
- if ('lazyComponent' in compProps) {
6
- return React.lazy(compProps.lazyComponent);
7
- }
8
- if ('component' in compProps) {
9
- // In SSR, suspense is not yet supported, we cannot use React.lazy
10
- if (typeof document === 'undefined') {
11
- return compProps.component;
12
- }
13
- return React.lazy(() => Promise.resolve({ default: compProps.component }));
14
- }
15
- throw new Error("You must pass either 'component' or 'lazyComponent'");
16
- // Very important to leave the dependencies as they are, or instead
17
- // the player will remount on every frame.
18
- // @ts-expect-error
19
- // eslint-disable-next-line react-hooks/exhaustive-deps
20
- }, [compProps.component, compProps.lazyComponent]);
21
- return lazy;
22
- };
@@ -1,125 +0,0 @@
1
- import { useContext, useEffect, useMemo, useState } from 'react';
2
- import { useMediaStartsAt } from './audio/use-audio-frame.js';
3
- import { CompositionManager } from './CompositionManager.js';
4
- import { getAssetDisplayName } from './get-asset-file-name.js';
5
- import { useRemotionEnvironment } from './get-environment.js';
6
- import { useNonce } from './nonce.js';
7
- import { playAndHandleNotAllowedError } from './play-and-handle-not-allowed-error.js';
8
- import { SequenceContext } from './SequenceContext.js';
9
- import { TimelineContext, usePlayingState } from './timeline-position-state.js';
10
- import { useVideoConfig } from './use-video-config.js';
11
- import { evaluateVolume } from './volume-prop.js';
12
- const didWarn = {};
13
- const warnOnce = (message) => {
14
- if (didWarn[message]) {
15
- return;
16
- }
17
- console.warn(message);
18
- didWarn[message] = true;
19
- };
20
- export const useMediaInTimeline = ({ volume, mediaVolume, mediaRef, src, mediaType, playbackRate, }) => {
21
- const videoConfig = useVideoConfig();
22
- const { rootId, audioAndVideoTags } = useContext(TimelineContext);
23
- const parentSequence = useContext(SequenceContext);
24
- const actualFrom = parentSequence
25
- ? parentSequence.relativeFrom + parentSequence.cumulatedFrom
26
- : 0;
27
- const [playing] = usePlayingState();
28
- const startsAt = useMediaStartsAt();
29
- const { registerSequence, unregisterSequence } = useContext(CompositionManager);
30
- const [id] = useState(() => String(Math.random()));
31
- const [initialVolume] = useState(() => volume);
32
- const nonce = useNonce();
33
- const duration = parentSequence
34
- ? Math.min(parentSequence.durationInFrames, videoConfig.durationInFrames)
35
- : videoConfig.durationInFrames;
36
- const doesVolumeChange = typeof volume === 'function';
37
- const environment = useRemotionEnvironment();
38
- const volumes = useMemo(() => {
39
- if (typeof volume === 'number') {
40
- return volume;
41
- }
42
- return new Array(Math.max(0, duration + startsAt))
43
- .fill(true)
44
- .map((_, i) => {
45
- return evaluateVolume({
46
- frame: i + startsAt,
47
- volume,
48
- mediaVolume,
49
- allowAmplificationDuringRender: false,
50
- });
51
- })
52
- .join(',');
53
- }, [duration, startsAt, volume, mediaVolume]);
54
- useEffect(() => {
55
- if (typeof volume === 'number' && volume !== initialVolume) {
56
- warnOnce(`Remotion: The ${mediaType} with src ${src} has changed it's volume. Prefer the callback syntax for setting volume to get better timeline display: https://www.remotion.dev/docs/using-audio/#controlling-volume`);
57
- }
58
- }, [initialVolume, mediaType, src, volume]);
59
- useEffect(() => {
60
- var _a;
61
- if (!mediaRef.current) {
62
- return;
63
- }
64
- if (!src) {
65
- throw new Error('No src passed');
66
- }
67
- if (environment !== 'preview' && process.env.NODE_ENV !== 'test') {
68
- return;
69
- }
70
- registerSequence({
71
- type: mediaType,
72
- src,
73
- id,
74
- duration,
75
- from: 0,
76
- parent: (_a = parentSequence === null || parentSequence === void 0 ? void 0 : parentSequence.id) !== null && _a !== void 0 ? _a : null,
77
- displayName: getAssetDisplayName(src),
78
- rootId,
79
- volume: volumes,
80
- showInTimeline: true,
81
- nonce,
82
- startMediaFrom: 0 - startsAt,
83
- doesVolumeChange,
84
- showLoopTimesInTimeline: undefined,
85
- playbackRate,
86
- });
87
- return () => {
88
- unregisterSequence(id);
89
- };
90
- }, [
91
- actualFrom,
92
- duration,
93
- id,
94
- parentSequence,
95
- src,
96
- registerSequence,
97
- rootId,
98
- unregisterSequence,
99
- videoConfig,
100
- volumes,
101
- doesVolumeChange,
102
- nonce,
103
- mediaRef,
104
- mediaType,
105
- startsAt,
106
- playbackRate,
107
- environment,
108
- ]);
109
- useEffect(() => {
110
- const tag = {
111
- id,
112
- play: () => {
113
- if (!playing) {
114
- // Don't play if for example in a <Freeze> state.
115
- return;
116
- }
117
- return playAndHandleNotAllowedError(mediaRef, mediaType);
118
- },
119
- };
120
- audioAndVideoTags.current.push(tag);
121
- return () => {
122
- audioAndVideoTags.current = audioAndVideoTags.current.filter((a) => a.id !== id);
123
- };
124
- }, [audioAndVideoTags, id, mediaRef, mediaType, playing]);
125
- };