remotion 3.3.81 → 3.3.83

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/dist/cjs/Img.d.ts CHANGED
@@ -3,4 +3,6 @@ import React from 'react';
3
3
  * @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.
4
4
  * @see [Documentation](https://www.remotion.dev/docs/img)
5
5
  */
6
- export declare const Img: React.ForwardRefExoticComponent<Pick<React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "key" | keyof React.ImgHTMLAttributes<HTMLImageElement>> & React.RefAttributes<HTMLImageElement>>;
6
+ export declare const Img: React.ForwardRefExoticComponent<Pick<React.ClassAttributes<HTMLImageElement> & React.ImgHTMLAttributes<HTMLImageElement> & {
7
+ maxRetries?: number | undefined;
8
+ }, "key" | "maxRetries" | keyof React.ImgHTMLAttributes<HTMLImageElement>> & React.RefAttributes<HTMLImageElement>>;
package/dist/cjs/Img.js CHANGED
@@ -4,49 +4,86 @@ exports.Img = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const delay_render_js_1 = require("./delay-render.js");
7
- const get_environment_js_1 = require("./get-environment.js");
8
7
  const prefetch_js_1 = require("./prefetch.js");
9
- const ImgRefForwarding = ({ onError, src, ...props }, ref) => {
8
+ function exponentialBackoff(errorCount) {
9
+ return 1000 * 2 ** (errorCount - 1);
10
+ }
11
+ const ImgRefForwarding = ({ onError, maxRetries = 2, src, ...props }, ref) => {
10
12
  const imageRef = (0, react_1.useRef)(null);
11
- const environment = (0, get_environment_js_1.useRemotionEnvironment)();
13
+ const errors = (0, react_1.useRef)({});
12
14
  (0, react_1.useImperativeHandle)(ref, () => {
13
15
  return imageRef.current;
14
16
  }, []);
15
17
  const actualSrc = (0, prefetch_js_1.usePreload)(src);
16
- const didGetError = (0, react_1.useCallback)((e) => {
17
- var _a;
18
- if (onError) {
19
- onError(e);
20
- }
21
- else {
22
- console.error('Error loading image with src:', (_a = imageRef.current) === null || _a === void 0 ? void 0 : _a.src, e, 'Handle the event using the onError() prop to make this message disappear.');
18
+ const retryIn = (0, react_1.useCallback)((timeout) => {
19
+ if (!imageRef.current) {
20
+ return;
23
21
  }
24
- }, [onError]);
25
- // If image source switches, make new handle
26
- if (environment === 'rendering') {
27
- // eslint-disable-next-line react-hooks/rules-of-hooks
28
- (0, react_1.useLayoutEffect)(() => {
29
- if (process.env.NODE_ENV === 'test') {
22
+ const currentSrc = imageRef.current.src;
23
+ setTimeout(() => {
24
+ var _a;
25
+ if (!imageRef.current) {
26
+ // Component has been unmounted, do not retry
30
27
  return;
31
28
  }
32
- const newHandle = (0, delay_render_js_1.delayRender)('Loading <Img> with src=' + src);
33
- const { current } = imageRef;
34
- const didLoad = () => {
35
- (0, delay_render_js_1.continueRender)(newHandle);
36
- };
37
- if (current === null || current === void 0 ? void 0 : current.complete) {
38
- (0, delay_render_js_1.continueRender)(newHandle);
29
+ const newSrc = (_a = imageRef.current) === null || _a === void 0 ? void 0 : _a.src;
30
+ if (newSrc !== currentSrc) {
31
+ // src has changed, do not retry
32
+ return;
39
33
  }
40
- else {
41
- current === null || current === void 0 ? void 0 : current.addEventListener('load', didLoad, { once: true });
34
+ imageRef.current.removeAttribute('src');
35
+ imageRef.current.setAttribute('src', newSrc);
36
+ }, timeout);
37
+ }, []);
38
+ const didGetError = (0, react_1.useCallback)((e) => {
39
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
40
+ if (!errors.current) {
41
+ return;
42
+ }
43
+ errors.current[(_a = imageRef.current) === null || _a === void 0 ? void 0 : _a.src] =
44
+ ((_c = errors.current[(_b = imageRef.current) === null || _b === void 0 ? void 0 : _b.src]) !== null && _c !== void 0 ? _c : 0) + 1;
45
+ if (onError &&
46
+ ((_e = errors.current[(_d = imageRef.current) === null || _d === void 0 ? void 0 : _d.src]) !== null && _e !== void 0 ? _e : 0) > maxRetries) {
47
+ onError(e);
48
+ return;
49
+ }
50
+ if (((_g = errors.current[(_f = imageRef.current) === null || _f === void 0 ? void 0 : _f.src]) !== null && _g !== void 0 ? _g : 0) <= maxRetries) {
51
+ const backoff = exponentialBackoff((_j = errors.current[(_h = imageRef.current) === null || _h === void 0 ? void 0 : _h.src]) !== null && _j !== void 0 ? _j : 0);
52
+ console.warn(`Could not load image with source ${(_k = imageRef.current) === null || _k === void 0 ? void 0 : _k.src}, retrying again in ${backoff}ms`);
53
+ retryIn(backoff);
54
+ return;
55
+ }
56
+ console.error('Error loading image with src:', (_l = imageRef.current) === null || _l === void 0 ? void 0 : _l.src, e, 'Handle the event using the onError() prop to make this message disappear.');
57
+ }, [maxRetries, onError, retryIn]);
58
+ (0, react_1.useLayoutEffect)(() => {
59
+ if (process.env.NODE_ENV === 'test') {
60
+ return;
61
+ }
62
+ const newHandle = (0, delay_render_js_1.delayRender)('Loading <Img> with src=' + src);
63
+ const { current } = imageRef;
64
+ const onComplete = () => {
65
+ var _a, _b, _c, _d;
66
+ if (((_b = errors.current[(_a = imageRef.current) === null || _a === void 0 ? void 0 : _a.src]) !== null && _b !== void 0 ? _b : 0) > 0) {
67
+ delete errors.current[(_c = imageRef.current) === null || _c === void 0 ? void 0 : _c.src];
68
+ console.info(`Retry successful - ${(_d = imageRef.current) === null || _d === void 0 ? void 0 : _d.src} is now loaded`);
42
69
  }
43
- // If tag gets unmounted, clear pending handles because image is not going to load
44
- return () => {
45
- current === null || current === void 0 ? void 0 : current.removeEventListener('load', didLoad);
46
- (0, delay_render_js_1.continueRender)(newHandle);
47
- };
48
- }, [src]);
49
- }
70
+ (0, delay_render_js_1.continueRender)(newHandle);
71
+ };
72
+ const didLoad = () => {
73
+ onComplete();
74
+ };
75
+ if (current === null || current === void 0 ? void 0 : current.complete) {
76
+ onComplete();
77
+ }
78
+ else {
79
+ current === null || current === void 0 ? void 0 : current.addEventListener('load', didLoad, { once: true });
80
+ }
81
+ // If tag gets unmounted, clear pending handles because image is not going to load
82
+ return () => {
83
+ current === null || current === void 0 ? void 0 : current.removeEventListener('load', didLoad);
84
+ (0, delay_render_js_1.continueRender)(newHandle);
85
+ };
86
+ }, [src]);
50
87
  return ((0, jsx_runtime_1.jsx)("img", { ...props, ref: imageRef, src: actualSrc, onError: didGetError }));
51
88
  };
52
89
  /**
@@ -139,6 +139,11 @@ declare global {
139
139
  * Default: 'swangle' in Lambda, null elsewhere.
140
140
  */
141
141
  readonly setChromiumOpenGlRenderer: (renderer: 'swangle' | 'angle' | 'egl' | 'swiftshader') => void;
142
+ /**
143
+ * Set the user agent for Chrome. Only works during rendering.
144
+ * Default:
145
+ */
146
+ readonly setChromiumUserAgent: (userAgent: string | null) => void;
142
147
  };
143
148
  /**
144
149
  * @deprecated New flat config format: You can now replace `Config.Rendering.` with `Config.`
@@ -42,7 +42,7 @@ const useMediaInTimeline = ({ volume, mediaVolume, mediaRef, src, mediaType, pla
42
42
  if (typeof volume === 'number') {
43
43
  return volume;
44
44
  }
45
- return new Array(Math.max(0, duration + startsAt))
45
+ return new Array(Math.floor(Math.max(0, duration + startsAt)))
46
46
  .fill(true)
47
47
  .map((_, i) => {
48
48
  return (0, volume_prop_js_1.evaluateVolume)({
@@ -1 +1 @@
1
- export declare const VERSION = "3.3.81";
1
+ export declare const VERSION = "3.3.83";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // Automatically generated on publish
5
- exports.VERSION = '3.3.81';
5
+ exports.VERSION = '3.3.83';
@@ -13,19 +13,20 @@ const getMediaTime = ({ fps, frame, src, playbackRate, startFrom, mediaType, })
13
13
  playbackRate,
14
14
  startFrom,
15
15
  });
16
- if (src.endsWith('webm')) {
17
- // For WebM videos, we need to add a little bit of shift to get the right frame.
18
- const msPerFrame = 1000 / fps;
19
- const msShift = msPerFrame / 2;
20
- return (expectedFrame * msPerFrame + msShift) / 1000;
21
- }
22
- if (mediaType === 'video') {
16
+ const isChrome = typeof window !== 'undefined' &&
17
+ window.navigator.userAgent.match(/Chrome\/([0-9]+)/);
18
+ if (isChrome &&
19
+ Number(isChrome[1]) < 112 &&
20
+ mediaType === 'video' &&
21
+ src.endsWith('.mp4')) {
23
22
  // In Chrome, for MP4s, if 30fps, the first frame is still displayed at 0.033333
24
23
  // even though after that it increases by 0.033333333 each.
25
24
  // So frame = 0 in Remotion is like frame = 1 for the browser
26
25
  return (expectedFrame + 1) / fps;
27
26
  }
28
- // For audio, we don't do any shift correction
29
- return expectedFrame / fps;
27
+ // For WebM videos, we need to add a little bit of shift to get the right frame.
28
+ const msPerFrame = 1000 / fps;
29
+ const msShift = msPerFrame / 2;
30
+ return (expectedFrame * msPerFrame + msShift) / 1000;
30
31
  };
31
32
  exports.getMediaTime = getMediaTime;
@@ -0,0 +1,9 @@
1
+ import { z } from 'zod';
2
+ export declare const REMOTION_COLOR_BRAND = "__remotion-color";
3
+ export declare const parseColor: (value: string) => {
4
+ a: number;
5
+ r: number;
6
+ g: number;
7
+ b: number;
8
+ };
9
+ export declare const zColor: () => z.ZodEffects<z.ZodString, string, string>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.zColor = exports.parseColor = exports.REMOTION_COLOR_BRAND = void 0;
4
+ const zod_1 = require("zod");
5
+ const interpolate_colors_js_1 = require("./interpolate-colors.js");
6
+ exports.REMOTION_COLOR_BRAND = '__remotion-color';
7
+ const parseColor = (value) => {
8
+ const colored = (0, interpolate_colors_js_1.processColor)(value).toString(16).padStart(8, '0');
9
+ const opacity = parseInt(colored.slice(0, 2), 16);
10
+ const r = parseInt(colored.slice(2, 4), 16);
11
+ const g = parseInt(colored.slice(4, 6), 16);
12
+ const b = parseInt(colored.slice(6, 8), 16);
13
+ return { a: opacity, r, g, b };
14
+ };
15
+ exports.parseColor = parseColor;
16
+ const zColor = () => zod_1.z
17
+ .string()
18
+ .refine((value) => {
19
+ try {
20
+ (0, exports.parseColor)(value);
21
+ return true;
22
+ }
23
+ catch (err) {
24
+ return false;
25
+ }
26
+ }, { message: 'Invalid color' })
27
+ .describe(exports.REMOTION_COLOR_BRAND);
28
+ exports.zColor = zColor;
@@ -58,7 +58,7 @@ function truthy(value) {
58
58
  }
59
59
 
60
60
  // Automatically generated on publish
61
- const VERSION = '3.3.81';
61
+ const VERSION = '3.3.83';
62
62
 
63
63
  const checkMultipleRemotionVersions = () => {
64
64
  if (typeof globalThis === 'undefined') {
@@ -988,7 +988,7 @@ const useMediaInTimeline = ({ volume, mediaVolume, mediaRef, src, mediaType, pla
988
988
  if (typeof volume === 'number') {
989
989
  return volume;
990
990
  }
991
- return new Array(Math.max(0, duration + startsAt))
991
+ return new Array(Math.floor(Math.max(0, duration + startsAt)))
992
992
  .fill(true)
993
993
  .map((_, i) => {
994
994
  return evaluateVolume({
@@ -1197,20 +1197,21 @@ const getMediaTime = ({ fps, frame, src, playbackRate, startFrom, mediaType, })
1197
1197
  playbackRate,
1198
1198
  startFrom,
1199
1199
  });
1200
- if (src.endsWith('webm')) {
1201
- // For WebM videos, we need to add a little bit of shift to get the right frame.
1202
- const msPerFrame = 1000 / fps;
1203
- const msShift = msPerFrame / 2;
1204
- return (expectedFrame * msPerFrame + msShift) / 1000;
1205
- }
1206
- if (mediaType === 'video') {
1200
+ const isChrome = typeof window !== 'undefined' &&
1201
+ window.navigator.userAgent.match(/Chrome\/([0-9]+)/);
1202
+ if (isChrome &&
1203
+ Number(isChrome[1]) < 112 &&
1204
+ mediaType === 'video' &&
1205
+ src.endsWith('.mp4')) {
1207
1206
  // In Chrome, for MP4s, if 30fps, the first frame is still displayed at 0.033333
1208
1207
  // even though after that it increases by 0.033333333 each.
1209
1208
  // So frame = 0 in Remotion is like frame = 1 for the browser
1210
1209
  return (expectedFrame + 1) / fps;
1211
1210
  }
1212
- // For audio, we don't do any shift correction
1213
- return expectedFrame / fps;
1211
+ // For WebM videos, we need to add a little bit of shift to get the right frame.
1212
+ const msPerFrame = 1000 / fps;
1213
+ const msShift = msPerFrame / 2;
1214
+ return (expectedFrame * msPerFrame + msShift) / 1000;
1214
1215
  };
1215
1216
 
1216
1217
  const alreadyWarned = {};
@@ -2790,47 +2791,85 @@ const IFrameRefForwarding = ({ onLoad, onError, ...props }, ref) => {
2790
2791
  */
2791
2792
  const IFrame = forwardRef(IFrameRefForwarding);
2792
2793
 
2793
- const ImgRefForwarding = ({ onError, src, ...props }, ref) => {
2794
+ function exponentialBackoff(errorCount) {
2795
+ return 1000 * 2 ** (errorCount - 1);
2796
+ }
2797
+ const ImgRefForwarding = ({ onError, maxRetries = 2, src, ...props }, ref) => {
2794
2798
  const imageRef = useRef(null);
2795
- const environment = useRemotionEnvironment();
2799
+ const errors = useRef({});
2796
2800
  useImperativeHandle(ref, () => {
2797
2801
  return imageRef.current;
2798
2802
  }, []);
2799
2803
  const actualSrc = usePreload(src);
2800
- const didGetError = useCallback((e) => {
2801
- var _a;
2802
- if (onError) {
2803
- onError(e);
2804
- }
2805
- else {
2806
- console.error('Error loading image with src:', (_a = imageRef.current) === null || _a === void 0 ? void 0 : _a.src, e, 'Handle the event using the onError() prop to make this message disappear.');
2804
+ const retryIn = useCallback((timeout) => {
2805
+ if (!imageRef.current) {
2806
+ return;
2807
2807
  }
2808
- }, [onError]);
2809
- // If image source switches, make new handle
2810
- if (environment === 'rendering') {
2811
- // eslint-disable-next-line react-hooks/rules-of-hooks
2812
- useLayoutEffect(() => {
2813
- if (process.env.NODE_ENV === 'test') {
2808
+ const currentSrc = imageRef.current.src;
2809
+ setTimeout(() => {
2810
+ var _a;
2811
+ if (!imageRef.current) {
2812
+ // Component has been unmounted, do not retry
2814
2813
  return;
2815
2814
  }
2816
- const newHandle = delayRender('Loading <Img> with src=' + src);
2817
- const { current } = imageRef;
2818
- const didLoad = () => {
2819
- continueRender(newHandle);
2820
- };
2821
- if (current === null || current === void 0 ? void 0 : current.complete) {
2822
- continueRender(newHandle);
2815
+ const newSrc = (_a = imageRef.current) === null || _a === void 0 ? void 0 : _a.src;
2816
+ if (newSrc !== currentSrc) {
2817
+ // src has changed, do not retry
2818
+ return;
2823
2819
  }
2824
- else {
2825
- current === null || current === void 0 ? void 0 : current.addEventListener('load', didLoad, { once: true });
2820
+ imageRef.current.removeAttribute('src');
2821
+ imageRef.current.setAttribute('src', newSrc);
2822
+ }, timeout);
2823
+ }, []);
2824
+ const didGetError = useCallback((e) => {
2825
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
2826
+ if (!errors.current) {
2827
+ return;
2828
+ }
2829
+ errors.current[(_a = imageRef.current) === null || _a === void 0 ? void 0 : _a.src] =
2830
+ ((_c = errors.current[(_b = imageRef.current) === null || _b === void 0 ? void 0 : _b.src]) !== null && _c !== void 0 ? _c : 0) + 1;
2831
+ if (onError &&
2832
+ ((_e = errors.current[(_d = imageRef.current) === null || _d === void 0 ? void 0 : _d.src]) !== null && _e !== void 0 ? _e : 0) > maxRetries) {
2833
+ onError(e);
2834
+ return;
2835
+ }
2836
+ if (((_g = errors.current[(_f = imageRef.current) === null || _f === void 0 ? void 0 : _f.src]) !== null && _g !== void 0 ? _g : 0) <= maxRetries) {
2837
+ const backoff = exponentialBackoff((_j = errors.current[(_h = imageRef.current) === null || _h === void 0 ? void 0 : _h.src]) !== null && _j !== void 0 ? _j : 0);
2838
+ console.warn(`Could not load image with source ${(_k = imageRef.current) === null || _k === void 0 ? void 0 : _k.src}, retrying again in ${backoff}ms`);
2839
+ retryIn(backoff);
2840
+ return;
2841
+ }
2842
+ console.error('Error loading image with src:', (_l = imageRef.current) === null || _l === void 0 ? void 0 : _l.src, e, 'Handle the event using the onError() prop to make this message disappear.');
2843
+ }, [maxRetries, onError, retryIn]);
2844
+ useLayoutEffect(() => {
2845
+ if (process.env.NODE_ENV === 'test') {
2846
+ return;
2847
+ }
2848
+ const newHandle = delayRender('Loading <Img> with src=' + src);
2849
+ const { current } = imageRef;
2850
+ const onComplete = () => {
2851
+ var _a, _b, _c, _d;
2852
+ if (((_b = errors.current[(_a = imageRef.current) === null || _a === void 0 ? void 0 : _a.src]) !== null && _b !== void 0 ? _b : 0) > 0) {
2853
+ delete errors.current[(_c = imageRef.current) === null || _c === void 0 ? void 0 : _c.src];
2854
+ console.info(`Retry successful - ${(_d = imageRef.current) === null || _d === void 0 ? void 0 : _d.src} is now loaded`);
2826
2855
  }
2827
- // If tag gets unmounted, clear pending handles because image is not going to load
2828
- return () => {
2829
- current === null || current === void 0 ? void 0 : current.removeEventListener('load', didLoad);
2830
- continueRender(newHandle);
2831
- };
2832
- }, [src]);
2833
- }
2856
+ continueRender(newHandle);
2857
+ };
2858
+ const didLoad = () => {
2859
+ onComplete();
2860
+ };
2861
+ if (current === null || current === void 0 ? void 0 : current.complete) {
2862
+ onComplete();
2863
+ }
2864
+ else {
2865
+ current === null || current === void 0 ? void 0 : current.addEventListener('load', didLoad, { once: true });
2866
+ }
2867
+ // If tag gets unmounted, clear pending handles because image is not going to load
2868
+ return () => {
2869
+ current === null || current === void 0 ? void 0 : current.removeEventListener('load', didLoad);
2870
+ continueRender(newHandle);
2871
+ };
2872
+ }, [src]);
2834
2873
  return (jsx("img", { ...props, ref: imageRef, src: actualSrc, onError: didGetError }));
2835
2874
  };
2836
2875
  /**
@@ -1,4 +1,4 @@
1
1
  // Automatically generated on publish
2
- const VERSION = '3.3.81';
2
+ const VERSION = '3.3.83';
3
3
 
4
4
  export { VERSION };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remotion",
3
- "version": "3.3.81",
3
+ "version": "3.3.83",
4
4
  "description": "Render videos in React",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",