remotion 4.0.244 → 4.0.246

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 (78) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/cjs/AbsoluteFill.d.ts +0 -4
  3. package/dist/cjs/AbsoluteFill.js +3 -3
  4. package/dist/cjs/Composition.d.ts +0 -4
  5. package/dist/cjs/Composition.js +2 -2
  6. package/dist/cjs/Folder.d.ts +0 -4
  7. package/dist/cjs/Folder.js +2 -2
  8. package/dist/cjs/IFrame.d.ts +0 -4
  9. package/dist/cjs/IFrame.js +2 -2
  10. package/dist/cjs/Img.d.ts +0 -4
  11. package/dist/cjs/Img.js +2 -2
  12. package/dist/cjs/Sequence.d.ts +0 -4
  13. package/dist/cjs/Sequence.js +1 -1
  14. package/dist/cjs/Still.d.ts +0 -4
  15. package/dist/cjs/Still.js +1 -1
  16. package/dist/cjs/animated-image/AnimatedImage.d.ts +2 -0
  17. package/dist/cjs/animated-image/AnimatedImage.js +99 -0
  18. package/dist/cjs/animated-image/canvas.d.ts +16 -0
  19. package/dist/cjs/animated-image/canvas.js +122 -0
  20. package/dist/cjs/animated-image/decode-image.d.ts +16 -0
  21. package/dist/cjs/animated-image/decode-image.js +144 -0
  22. package/dist/cjs/animated-image/index.d.ts +1 -0
  23. package/dist/cjs/animated-image/index.js +5 -0
  24. package/dist/cjs/animated-image/props.d.ts +13 -0
  25. package/dist/cjs/animated-image/props.js +2 -0
  26. package/dist/cjs/animated-image/resolve-image-source.d.ts +1 -0
  27. package/dist/cjs/animated-image/resolve-image-source.js +8 -0
  28. package/dist/cjs/audio/Audio.d.ts +0 -4
  29. package/dist/cjs/audio/Audio.js +2 -2
  30. package/dist/cjs/cancel-render.d.ts +0 -4
  31. package/dist/cjs/cancel-render.js +3 -3
  32. package/dist/cjs/delay-render.d.ts +0 -11
  33. package/dist/cjs/delay-render.js +6 -9
  34. package/dist/cjs/freeze.d.ts +0 -4
  35. package/dist/cjs/freeze.js +3 -3
  36. package/dist/cjs/get-remotion-environment.d.ts +0 -4
  37. package/dist/cjs/get-remotion-environment.js +2 -2
  38. package/dist/cjs/get-static-files.d.ts +0 -4
  39. package/dist/cjs/get-static-files.js +3 -3
  40. package/dist/cjs/index.d.ts +1 -0
  41. package/dist/cjs/index.js +1 -0
  42. package/dist/cjs/interpolate-colors.d.ts +0 -4
  43. package/dist/cjs/interpolate-colors.js +7 -5
  44. package/dist/cjs/interpolate.d.ts +0 -11
  45. package/dist/cjs/interpolate.js +3 -10
  46. package/dist/cjs/loop/index.d.ts +0 -4
  47. package/dist/cjs/loop/index.js +2 -2
  48. package/dist/cjs/prefetch.d.ts +0 -4
  49. package/dist/cjs/prefetch.js +2 -2
  50. package/dist/cjs/random.d.ts +0 -4
  51. package/dist/cjs/random.js +2 -2
  52. package/dist/cjs/register-root.d.ts +0 -4
  53. package/dist/cjs/register-root.js +2 -2
  54. package/dist/cjs/spring/index.d.ts +0 -17
  55. package/dist/cjs/spring/index.js +1 -14
  56. package/dist/cjs/spring/measure-spring.d.ts +0 -4
  57. package/dist/cjs/spring/measure-spring.js +3 -3
  58. package/dist/cjs/static-file.d.ts +0 -4
  59. package/dist/cjs/static-file.js +1 -1
  60. package/dist/cjs/use-current-frame.d.ts +0 -4
  61. package/dist/cjs/use-current-frame.js +3 -3
  62. package/dist/cjs/use-current-scale.d.ts +0 -4
  63. package/dist/cjs/use-current-scale.js +3 -3
  64. package/dist/cjs/use-video-config.d.ts +0 -5
  65. package/dist/cjs/use-video-config.js +2 -3
  66. package/dist/cjs/version.d.ts +1 -1
  67. package/dist/cjs/version.js +1 -1
  68. package/dist/cjs/video/OffthreadVideo.d.ts +0 -4
  69. package/dist/cjs/video/OffthreadVideo.js +1 -1
  70. package/dist/cjs/video/Video.d.ts +0 -4
  71. package/dist/cjs/video/Video.js +2 -2
  72. package/dist/cjs/watch-static-file.d.ts +0 -7
  73. package/dist/cjs/watch-static-file.js +2 -5
  74. package/dist/esm/index.mjs +783 -433
  75. package/dist/esm/version.mjs +1 -1
  76. package/package.json +3 -2
  77. package/dist/cjs/use-media-tag-volume.d.ts +0 -2
  78. package/dist/cjs/use-media-tag-volume.js +0 -31
package/LICENSE.md CHANGED
@@ -11,7 +11,7 @@ Depending on the type of your legal entity, you are granted permission to use Re
11
11
 
12
12
  ## Free license
13
13
 
14
- Copyright © 2024 [Remotion](https://www.remotion.dev)
14
+ Copyright © 2025 [Remotion](https://www.remotion.dev)
15
15
 
16
16
  ### Eligibility
17
17
 
@@ -1,6 +1,2 @@
1
1
  import React from 'react';
2
- /**
3
- * @description An absolutely positioned <div> element with 100% width, height, and a column flex style
4
- * @see [Documentation](https://www.remotion.dev/docs/absolute-fill)
5
- */
6
2
  export declare const AbsoluteFill: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
@@ -21,8 +21,8 @@ const AbsoluteFillRefForwarding = (props, ref) => {
21
21
  }, [style]);
22
22
  return (0, jsx_runtime_1.jsx)("div", { ref: ref, style: actualStyle, ...other });
23
23
  };
24
- /**
25
- * @description An absolutely positioned <div> element with 100% width, height, and a column flex style
26
- * @see [Documentation](https://www.remotion.dev/docs/absolute-fill)
24
+ /*
25
+ * @description A helper component which renders an absolutely positioned <div> element with full width, height, and flex display suited for content layering.
26
+ * @see [Documentation](https://remotion.dev/docs/absolute-fill)
27
27
  */
28
28
  exports.AbsoluteFill = (0, react_1.forwardRef)(AbsoluteFillRefForwarding);
@@ -51,9 +51,5 @@ export type CompositionProps<Schema extends AnyZodObject, Props extends Record<s
51
51
  readonly id: string;
52
52
  readonly schema?: Schema;
53
53
  } & CompositionCalculateMetadataOrExplicit<Schema, Props> & CompProps<Props> & PropsIfHasProps<Schema, Props>;
54
- /**
55
- * @description This component is used to register a video to make it renderable and make it show in the sidebar, in dev mode.
56
- * @see [Documentation](https://www.remotion.dev/docs/composition)
57
- */
58
54
  export declare const Composition: <Schema extends AnyZodObject, Props extends Record<string, unknown>>({ width, height, fps, durationInFrames, id, defaultProps, schema, ...compProps }: CompositionProps<Schema, Props>) => React.ReactPortal | null;
59
55
  export {};
@@ -26,9 +26,9 @@ const Fallback = () => {
26
26
  }, []);
27
27
  return null;
28
28
  };
29
- /**
29
+ /*
30
30
  * @description This component is used to register a video to make it renderable and make it show in the sidebar, in dev mode.
31
- * @see [Documentation](https://www.remotion.dev/docs/composition)
31
+ * @see [Documentation](https://remotion.dev/docs/composition)
32
32
  */
33
33
  const Composition = ({ width, height, fps, durationInFrames, id, defaultProps, schema, ...compProps }) => {
34
34
  var _a, _b;
@@ -8,10 +8,6 @@ type FolderContextType = {
8
8
  parentName: string | null;
9
9
  };
10
10
  export declare const FolderContext: import("react").Context<FolderContextType>;
11
- /**
12
- * @description By wrapping a <Composition /> inside a <Folder />, you can visually categorize it in your sidebar, should you have many compositions.
13
- * @see [Documentation](https://www.remotion.dev/docs/folder)
14
- */
15
11
  export declare const Folder: FC<{
16
12
  readonly name: string;
17
13
  readonly children: React.ReactNode;
@@ -10,9 +10,9 @@ exports.FolderContext = (0, react_1.createContext)({
10
10
  folderName: null,
11
11
  parentName: null,
12
12
  });
13
- /**
13
+ /*
14
14
  * @description By wrapping a <Composition /> inside a <Folder />, you can visually categorize it in your sidebar, should you have many compositions.
15
- * @see [Documentation](https://www.remotion.dev/docs/folder)
15
+ * @see [Documentation](https://remotion.dev/docs/folder)
16
16
  */
17
17
  const Folder = ({ name, children }) => {
18
18
  const parent = (0, react_1.useContext)(exports.FolderContext);
@@ -1,8 +1,4 @@
1
1
  import React from 'react';
2
- /**
3
- * @description The <IFrame /> can be used like a regular <iframe> HTML tag.
4
- * @see [Documentation](https://www.remotion.dev/docs/iframe)
5
- */
6
2
  export declare const IFrame: React.ForwardRefExoticComponent<Omit<React.ClassAttributes<HTMLIFrameElement> & React.IframeHTMLAttributes<HTMLIFrameElement> & {
7
3
  readonly delayRenderRetries?: number;
8
4
  readonly delayRenderTimeoutInMilliseconds?: number;
@@ -25,8 +25,8 @@ const IFrameRefForwarding = ({ onLoad, onError, delayRenderRetries, delayRenderT
25
25
  }, [handle, onError]);
26
26
  return (0, jsx_runtime_1.jsx)("iframe", { ...props, ref: ref, onError: didGetError, onLoad: didLoad });
27
27
  };
28
- /**
28
+ /*
29
29
  * @description The <IFrame /> can be used like a regular <iframe> HTML tag.
30
- * @see [Documentation](https://www.remotion.dev/docs/iframe)
30
+ * @see [Documentation](https://remotion.dev/docs/iframe)
31
31
  */
32
32
  exports.IFrame = (0, react_1.forwardRef)(IFrameRefForwarding);
package/dist/cjs/Img.d.ts CHANGED
@@ -7,8 +7,4 @@ export type ImgProps = Omit<React.DetailedHTMLProps<React.ImgHTMLAttributes<HTML
7
7
  readonly onImageFrame?: (imgelement: HTMLImageElement) => void;
8
8
  readonly src: string;
9
9
  };
10
- /**
11
- * @description Works just like a regular HTML img tag. When you use the <Img> tag, Remotion will ensure that the image is loaded before rendering the frame.
12
- * @see [Documentation](https://www.remotion.dev/docs/img)
13
- */
14
10
  export declare const Img: React.ForwardRefExoticComponent<Omit<ImgProps, "ref"> & React.RefAttributes<HTMLImageElement>>;
package/dist/cjs/Img.js CHANGED
@@ -149,8 +149,8 @@ const ImgRefForwarding = ({ onError, maxRetries = 2, src, pauseWhenLoading, dela
149
149
  // src gets set once we've loaded and decoded the image.
150
150
  return (0, jsx_runtime_1.jsx)("img", { ...props, ref: imageRef, onError: didGetError });
151
151
  };
152
- /**
152
+ /*
153
153
  * @description Works just like a regular HTML img tag. When you use the <Img> tag, Remotion will ensure that the image is loaded before rendering the frame.
154
- * @see [Documentation](https://www.remotion.dev/docs/img)
154
+ * @see [Documentation](https://remotion.dev/docs/img)
155
155
  */
156
156
  exports.Img = (0, react_1.forwardRef)(ImgRefForwarding);
@@ -36,8 +36,4 @@ export type SequencePropsWithoutDuration = {
36
36
  export type SequenceProps = {
37
37
  readonly durationInFrames?: number;
38
38
  } & SequencePropsWithoutDuration;
39
- /**
40
- * @description A component that time-shifts its children and wraps them in an absolutely positioned <div>.
41
- * @see [Documentation](https://www.remotion.dev/docs/sequence)
42
- */
43
39
  export declare const Sequence: React.ForwardRefExoticComponent<SequenceProps & React.RefAttributes<HTMLDivElement>>;
@@ -173,7 +173,7 @@ const SequenceRefForwardingFunction = (props, ref) => {
173
173
  }
174
174
  return (0, jsx_runtime_1.jsx)(RegularSequence, { ...props, ref: ref });
175
175
  };
176
- /**
176
+ /*
177
177
  * @description A component that time-shifts its children and wraps them in an absolutely positioned <div>.
178
178
  * @see [Documentation](https://www.remotion.dev/docs/sequence)
179
179
  */
@@ -1,8 +1,4 @@
1
1
  import React from 'react';
2
2
  import type { AnyZodObject } from 'zod';
3
3
  import type { StillProps } from './Composition.js';
4
- /**
5
- * @description A `<Still />` is a `<Composition />` that is only 1 frame long.
6
- * @see [Documentation](https://www.remotion.dev/docs/still)
7
- */
8
4
  export declare const Still: <Schema extends AnyZodObject, Props extends Record<string, unknown>>(props: StillProps<Schema, Props>) => React.DetailedReactHTMLElement<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
package/dist/cjs/Still.js CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Still = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const Composition_js_1 = require("./Composition.js");
9
- /**
9
+ /*
10
10
  * @description A `<Still />` is a `<Composition />` that is only 1 frame long.
11
11
  * @see [Documentation](https://www.remotion.dev/docs/still)
12
12
  */
@@ -0,0 +1,2 @@
1
+ import type { RemotionAnimatedImageProps } from './props';
2
+ export declare const AnimatedImage: import("react").ForwardRefExoticComponent<RemotionAnimatedImageProps & import("react").RefAttributes<HTMLCanvasElement>>;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AnimatedImage = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const cancel_render_js_1 = require("../cancel-render.js");
7
+ const delay_render_js_1 = require("../delay-render.js");
8
+ const use_current_frame_js_1 = require("../use-current-frame.js");
9
+ const use_video_config_js_1 = require("../use-video-config.js");
10
+ const canvas_1 = require("./canvas");
11
+ const decode_image_js_1 = require("./decode-image.js");
12
+ const resolve_image_source_1 = require("./resolve-image-source");
13
+ exports.AnimatedImage = (0, react_1.forwardRef)(({ src, width, height, onError, loopBehavior = 'loop', playbackRate = 1, fit = 'fill', ...props }, canvasRef) => {
14
+ const mountState = (0, react_1.useRef)({ isMounted: true });
15
+ (0, react_1.useEffect)(() => {
16
+ const { current } = mountState;
17
+ current.isMounted = true;
18
+ return () => {
19
+ current.isMounted = false;
20
+ };
21
+ }, []);
22
+ const resolvedSrc = (0, resolve_image_source_1.resolveAnimatedImageSource)(src);
23
+ const [imageDecoder, setImageDecoder] = (0, react_1.useState)(null);
24
+ const [decodeHandle] = (0, react_1.useState)(() => (0, delay_render_js_1.delayRender)(`Rendering <AnimatedImage/> with src="${resolvedSrc}"`));
25
+ const frame = (0, use_current_frame_js_1.useCurrentFrame)();
26
+ const { fps } = (0, use_video_config_js_1.useVideoConfig)();
27
+ const currentTime = frame / playbackRate / fps;
28
+ const currentTimeRef = (0, react_1.useRef)(currentTime);
29
+ currentTimeRef.current = currentTime;
30
+ const ref = (0, react_1.useRef)(null);
31
+ (0, react_1.useImperativeHandle)(canvasRef, () => {
32
+ var _a;
33
+ const c = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.getCanvas();
34
+ if (!c) {
35
+ throw new Error('Canvas ref is not set');
36
+ }
37
+ return c;
38
+ }, []);
39
+ const [initialLoopBehavior] = (0, react_1.useState)(() => loopBehavior);
40
+ (0, react_1.useEffect)(() => {
41
+ const controller = new AbortController();
42
+ (0, decode_image_js_1.decodeImage)({
43
+ resolvedSrc,
44
+ signal: controller.signal,
45
+ currentTime: currentTimeRef.current,
46
+ initialLoopBehavior,
47
+ })
48
+ .then((d) => {
49
+ setImageDecoder(d);
50
+ (0, delay_render_js_1.continueRender)(decodeHandle);
51
+ })
52
+ .catch((err) => {
53
+ if (err.name === 'AbortError') {
54
+ (0, delay_render_js_1.continueRender)(decodeHandle);
55
+ return;
56
+ }
57
+ if (onError) {
58
+ onError === null || onError === void 0 ? void 0 : onError(err);
59
+ (0, delay_render_js_1.continueRender)(decodeHandle);
60
+ }
61
+ else {
62
+ (0, cancel_render_js_1.cancelRender)(err);
63
+ }
64
+ });
65
+ return () => {
66
+ controller.abort();
67
+ };
68
+ }, [resolvedSrc, decodeHandle, onError, initialLoopBehavior]);
69
+ (0, react_1.useLayoutEffect)(() => {
70
+ if (!imageDecoder) {
71
+ return;
72
+ }
73
+ const delay = (0, delay_render_js_1.delayRender)(`Rendering frame at ${currentTime} of <AnimatedImage src="${src}"/>`);
74
+ imageDecoder
75
+ .getFrame(currentTime, loopBehavior)
76
+ .then((videoFrame) => {
77
+ var _a, _b;
78
+ if (mountState.current.isMounted) {
79
+ if (videoFrame === null) {
80
+ (_a = ref.current) === null || _a === void 0 ? void 0 : _a.clear();
81
+ }
82
+ else {
83
+ (_b = ref.current) === null || _b === void 0 ? void 0 : _b.draw(videoFrame.frame);
84
+ }
85
+ }
86
+ (0, delay_render_js_1.continueRender)(delay);
87
+ })
88
+ .catch((err) => {
89
+ if (onError) {
90
+ onError(err);
91
+ (0, delay_render_js_1.continueRender)(delay);
92
+ }
93
+ else {
94
+ (0, cancel_render_js_1.cancelRender)(err);
95
+ }
96
+ });
97
+ }, [currentTime, imageDecoder, loopBehavior, onError, src]);
98
+ return ((0, jsx_runtime_1.jsx)(canvas_1.Canvas, { ref: ref, width: width, height: height, fit: fit, ...props }));
99
+ });
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import type { AnimatedImageFillMode } from './props';
3
+ type Props = {
4
+ readonly width?: number;
5
+ readonly height?: number;
6
+ readonly fit: AnimatedImageFillMode;
7
+ readonly className?: string;
8
+ readonly style?: React.CSSProperties;
9
+ };
10
+ export type AnimatedImageCanvasRef = {
11
+ readonly draw: (imageData: VideoFrame) => void;
12
+ readonly getCanvas: () => HTMLCanvasElement | null;
13
+ clear: () => void;
14
+ };
15
+ export declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<AnimatedImageCanvasRef>>;
16
+ export {};
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Canvas = void 0;
27
+ const jsx_runtime_1 = require("react/jsx-runtime");
28
+ const react_1 = __importStar(require("react"));
29
+ const calcArgs = (fit, frameSize, canvasSize) => {
30
+ switch (fit) {
31
+ case 'fill': {
32
+ return [
33
+ 0,
34
+ 0,
35
+ frameSize.width,
36
+ frameSize.height,
37
+ 0,
38
+ 0,
39
+ canvasSize.width,
40
+ canvasSize.height,
41
+ ];
42
+ }
43
+ case 'contain': {
44
+ const ratio = Math.min(canvasSize.width / frameSize.width, canvasSize.height / frameSize.height);
45
+ const centerX = (canvasSize.width - frameSize.width * ratio) / 2;
46
+ const centerY = (canvasSize.height - frameSize.height * ratio) / 2;
47
+ return [
48
+ 0,
49
+ 0,
50
+ frameSize.width,
51
+ frameSize.height,
52
+ centerX,
53
+ centerY,
54
+ frameSize.width * ratio,
55
+ frameSize.height * ratio,
56
+ ];
57
+ }
58
+ case 'cover': {
59
+ const ratio = Math.max(canvasSize.width / frameSize.width, canvasSize.height / frameSize.height);
60
+ const centerX = (canvasSize.width - frameSize.width * ratio) / 2;
61
+ const centerY = (canvasSize.height - frameSize.height * ratio) / 2;
62
+ return [
63
+ 0,
64
+ 0,
65
+ frameSize.width,
66
+ frameSize.height,
67
+ centerX,
68
+ centerY,
69
+ frameSize.width * ratio,
70
+ frameSize.height * ratio,
71
+ ];
72
+ }
73
+ default:
74
+ throw new Error('Unknown fit: ' + fit);
75
+ }
76
+ };
77
+ const CanvasRefForwardingFunction = ({ width, height, fit, className, style }, ref) => {
78
+ const canvasRef = (0, react_1.useRef)(null);
79
+ const draw = (0, react_1.useCallback)((imageData) => {
80
+ var _a;
81
+ const canvas = canvasRef.current;
82
+ const canvasWidth = width !== null && width !== void 0 ? width : imageData.displayWidth;
83
+ const canvasHeight = height !== null && height !== void 0 ? height : imageData.displayHeight;
84
+ if (!canvas) {
85
+ throw new Error('Canvas ref is not set');
86
+ }
87
+ const ctx = (_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.getContext('2d');
88
+ if (!ctx) {
89
+ throw new Error('Could not get 2d context');
90
+ }
91
+ canvas.width = canvasWidth;
92
+ canvas.height = canvasHeight;
93
+ ctx.drawImage(imageData, ...calcArgs(fit, {
94
+ height: imageData.displayHeight,
95
+ width: imageData.displayWidth,
96
+ }, {
97
+ width: canvasWidth,
98
+ height: canvasHeight,
99
+ }));
100
+ }, [fit, height, width]);
101
+ (0, react_1.useImperativeHandle)(ref, () => {
102
+ return {
103
+ draw,
104
+ getCanvas: () => {
105
+ if (!canvasRef.current) {
106
+ throw new Error('Canvas ref is not set');
107
+ }
108
+ return canvasRef.current;
109
+ },
110
+ clear: () => {
111
+ var _a;
112
+ const ctx = (_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.getContext('2d');
113
+ if (!ctx) {
114
+ throw new Error('Could not get 2d context');
115
+ }
116
+ ctx.clearRect(0, 0, canvasRef.current.width, canvasRef.current.height);
117
+ },
118
+ };
119
+ }, [draw]);
120
+ return (0, jsx_runtime_1.jsx)("canvas", { ref: canvasRef, className: className, style: style });
121
+ };
122
+ exports.Canvas = react_1.default.forwardRef(CanvasRefForwardingFunction);
@@ -0,0 +1,16 @@
1
+ import type { RemotionAnimatedImageLoopBehavior } from './props';
2
+ export type AnimatedImageCacheItem = {
3
+ timeInSeconds: number;
4
+ frameIndex: number;
5
+ frame: VideoFrame | null;
6
+ };
7
+ export type RemotionImageDecoder = {
8
+ getFrame: (i: number, loopBehavior: RemotionAnimatedImageLoopBehavior) => Promise<AnimatedImageCacheItem | null>;
9
+ frameCount: number;
10
+ };
11
+ export declare const decodeImage: ({ resolvedSrc, signal, currentTime, initialLoopBehavior, }: {
12
+ resolvedSrc: string;
13
+ signal: AbortSignal;
14
+ currentTime: number;
15
+ initialLoopBehavior: RemotionAnimatedImageLoopBehavior;
16
+ }) => Promise<RemotionImageDecoder>;
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeImage = void 0;
4
+ const CACHE_SIZE = 5;
5
+ const getActualTime = ({ loopBehavior, durationFound, timeInSec, }) => {
6
+ return loopBehavior === 'loop'
7
+ ? durationFound
8
+ ? timeInSec % durationFound
9
+ : timeInSec
10
+ : Math.min(timeInSec, durationFound || Infinity);
11
+ };
12
+ const decodeImage = async ({ resolvedSrc, signal, currentTime, initialLoopBehavior, }) => {
13
+ if (typeof ImageDecoder === 'undefined') {
14
+ throw new Error('Your browser does not support the WebCodecs ImageDecoder API.');
15
+ }
16
+ const res = await fetch(resolvedSrc, { signal });
17
+ const { body } = res;
18
+ if (!body) {
19
+ throw new Error('Got no body');
20
+ }
21
+ const decoder = new ImageDecoder({
22
+ data: body,
23
+ type: res.headers.get('Content-Type') || 'image/gif',
24
+ });
25
+ await decoder.completed;
26
+ const { selectedTrack } = decoder.tracks;
27
+ if (!selectedTrack) {
28
+ throw new Error('No selected track');
29
+ }
30
+ const cache = [];
31
+ let durationFound = null;
32
+ const getFrameByIndex = async (frameIndex) => {
33
+ const foundInCache = cache.find((c) => c.frameIndex === frameIndex);
34
+ if (foundInCache && foundInCache.frame) {
35
+ return foundInCache;
36
+ }
37
+ const frame = await decoder.decode({
38
+ frameIndex,
39
+ completeFramesOnly: true,
40
+ });
41
+ if (foundInCache) {
42
+ foundInCache.frame = frame.image;
43
+ }
44
+ else {
45
+ cache.push({
46
+ frame: frame.image,
47
+ frameIndex,
48
+ timeInSeconds: frame.image.timestamp / 1000000,
49
+ });
50
+ }
51
+ return {
52
+ frame: frame.image,
53
+ frameIndex,
54
+ timeInSeconds: frame.image.timestamp / 1000000,
55
+ };
56
+ };
57
+ const clearCache = (closeToTimeInSec) => {
58
+ const itemsInCache = cache.filter((c) => c.frame);
59
+ const sortByClosestToCurrentTime = itemsInCache.sort((a, b) => {
60
+ const aDiff = Math.abs(a.timeInSeconds - closeToTimeInSec);
61
+ const bDiff = Math.abs(b.timeInSeconds - closeToTimeInSec);
62
+ return aDiff - bDiff;
63
+ });
64
+ for (let i = 0; i < sortByClosestToCurrentTime.length; i++) {
65
+ if (i < CACHE_SIZE) {
66
+ continue;
67
+ }
68
+ const item = sortByClosestToCurrentTime[i];
69
+ item.frame = null;
70
+ }
71
+ };
72
+ const ensureFrameBeforeAndAfter = async ({ timeInSec, loopBehavior, }) => {
73
+ const actualTimeInSec = getActualTime({
74
+ durationFound,
75
+ loopBehavior,
76
+ timeInSec,
77
+ });
78
+ const framesBefore = cache.filter((c) => c.timeInSeconds <= actualTimeInSec);
79
+ const biggestIndex = framesBefore
80
+ .map((c) => c.frameIndex)
81
+ .reduce((a, b) => Math.max(a, b), 0);
82
+ let i = biggestIndex;
83
+ while (true) {
84
+ const f = await getFrameByIndex(i);
85
+ i++;
86
+ if (!f.frame) {
87
+ throw new Error('No frame found');
88
+ }
89
+ if (!f.frame.duration) {
90
+ throw new Error('Frame has no duration');
91
+ }
92
+ if (i === selectedTrack.frameCount && durationFound === null) {
93
+ const duration = (f.frame.timestamp + f.frame.duration) / 1000000;
94
+ durationFound = duration;
95
+ }
96
+ if (f.timeInSeconds > actualTimeInSec || i === selectedTrack.frameCount) {
97
+ break;
98
+ }
99
+ }
100
+ // If close to end, also cache first frame for smooth wrap around
101
+ if (selectedTrack.frameCount - biggestIndex < 3 &&
102
+ loopBehavior === 'loop') {
103
+ await getFrameByIndex(0);
104
+ }
105
+ clearCache(actualTimeInSec);
106
+ };
107
+ // Twice because might be over total duration
108
+ await ensureFrameBeforeAndAfter({
109
+ timeInSec: currentTime,
110
+ loopBehavior: initialLoopBehavior,
111
+ });
112
+ await ensureFrameBeforeAndAfter({
113
+ timeInSec: currentTime,
114
+ loopBehavior: initialLoopBehavior,
115
+ });
116
+ const getFrame = async (timeInSec, loopBehavior) => {
117
+ if (durationFound !== null &&
118
+ timeInSec > durationFound &&
119
+ loopBehavior === 'clear-after-finish') {
120
+ return null;
121
+ }
122
+ const actualTimeInSec = getActualTime({
123
+ loopBehavior,
124
+ durationFound,
125
+ timeInSec,
126
+ });
127
+ await ensureFrameBeforeAndAfter({ timeInSec: actualTimeInSec, loopBehavior });
128
+ const itemsInCache = cache.filter((c) => c.frame);
129
+ const closest = itemsInCache.reduce((a, b) => {
130
+ const aDiff = Math.abs(a.timeInSeconds - actualTimeInSec);
131
+ const bDiff = Math.abs(b.timeInSeconds - actualTimeInSec);
132
+ return aDiff < bDiff ? a : b;
133
+ });
134
+ if (!closest.frame) {
135
+ throw new Error('No frame found');
136
+ }
137
+ return closest;
138
+ };
139
+ return {
140
+ getFrame,
141
+ frameCount: selectedTrack.frameCount,
142
+ };
143
+ };
144
+ exports.decodeImage = decodeImage;
@@ -0,0 +1 @@
1
+ export { AnimatedImage } from './AnimatedImage';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AnimatedImage = void 0;
4
+ var AnimatedImage_1 = require("./AnimatedImage");
5
+ Object.defineProperty(exports, "AnimatedImage", { enumerable: true, get: function () { return AnimatedImage_1.AnimatedImage; } });
@@ -0,0 +1,13 @@
1
+ export type RemotionAnimatedImageLoopBehavior = 'loop' | 'pause-after-finish' | 'clear-after-finish';
2
+ export type RemotionAnimatedImageProps = {
3
+ src: string;
4
+ width?: number;
5
+ height?: number;
6
+ onError?: (error: Error) => void;
7
+ fit?: AnimatedImageFillMode;
8
+ playbackRate?: number;
9
+ style?: React.CSSProperties;
10
+ loopBehavior?: RemotionAnimatedImageLoopBehavior;
11
+ id?: string;
12
+ };
13
+ export type AnimatedImageFillMode = 'contain' | 'cover' | 'fill';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export declare const resolveAnimatedImageSource: (src: string) => string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveAnimatedImageSource = void 0;
4
+ const resolveAnimatedImageSource = (src) => {
5
+ return new URL(src, typeof window === 'undefined' ? undefined : window.origin)
6
+ .href;
7
+ };
8
+ exports.resolveAnimatedImageSource = resolveAnimatedImageSource;
@@ -1,9 +1,5 @@
1
1
  import React from 'react';
2
2
  import type { RemotionMainAudioProps } from './props.js';
3
- /**
4
- * @description With this component, you can add audio to your video. All audio formats which are supported by Chromium are supported by the component.
5
- * @see [Documentation](https://www.remotion.dev/docs/audio)
6
- */
7
3
  export declare const Audio: React.ForwardRefExoticComponent<Omit<Omit<React.DetailedHTMLProps<React.AudioHTMLAttributes<HTMLAudioElement>, HTMLAudioElement>, "nonce" | "onEnded" | "onResize" | "onResizeCapture" | "autoPlay" | "controls"> & {
8
4
  name?: string;
9
5
  volume?: import("../volume-prop.js").VolumeProp;
@@ -75,9 +75,9 @@ const AudioRefForwardingFunction = (props, ref) => {
75
75
  // Proposal: Make this default to true in v5
76
76
  pauseWhenBuffering: pauseWhenBuffering !== null && pauseWhenBuffering !== void 0 ? pauseWhenBuffering : false, _remotionInternalNeedsDurationCalculation: Boolean(loop), showInTimeline: showInTimeline !== null && showInTimeline !== void 0 ? showInTimeline : true }));
77
77
  };
78
- /**
78
+ /*
79
79
  * @description With this component, you can add audio to your video. All audio formats which are supported by Chromium are supported by the component.
80
- * @see [Documentation](https://www.remotion.dev/docs/audio)
80
+ * @see [Documentation](https://remotion.dev/docs/audio)
81
81
  */
82
82
  exports.Audio = (0, react_1.forwardRef)(AudioRefForwardingFunction);
83
83
  (0, enable_sequence_stack_traces_js_1.addSequenceStackTraces)(exports.Audio);
@@ -1,5 +1 @@
1
- /**
2
- * @description When you invoke this function, Remotion will stop rendering all the frames without any retries
3
- * @see [Documentation](https://www.remotion.dev/docs/cancel-render)
4
- */
5
1
  export declare function cancelRender(err: unknown): never;