@remotion/gif 3.1.4 → 3.1.7

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.
@@ -5,6 +5,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const tools_1 = require("@react-gifs/tools");
6
6
  const react_1 = require("react");
7
7
  const remotion_1 = require("remotion");
8
+ const is_cors_error_1 = require("./is-cors-error");
8
9
  const useCurrentGifIndex_1 = require("./useCurrentGifIndex");
9
10
  exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad, onError, fit = 'fill', ...props }, ref) => {
10
11
  const resolvedSrc = new URL(src, window.location.origin).href;
@@ -14,6 +15,7 @@ exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad,
14
15
  width: 0,
15
16
  height: 0,
16
17
  });
18
+ const [error, setError] = (0, react_1.useState)(null);
17
19
  const [id] = (0, react_1.useState)(() => (0, remotion_1.delayRender)(`Rendering <Gif/> with src="${resolvedSrc}"`));
18
20
  const index = (0, useCurrentGifIndex_1.useCurrentGifIndex)(state.delays);
19
21
  (0, tools_1.useParser)(resolvedSrc, (info) => {
@@ -22,7 +24,7 @@ exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad,
22
24
  onError(info.error);
23
25
  }
24
26
  else {
25
- console.error('Error loading GIF:', info.error, 'Handle the event using the onError() prop to make this message disappear.');
27
+ setError(info.error);
26
28
  }
27
29
  }
28
30
  else {
@@ -31,5 +33,12 @@ exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad,
31
33
  }
32
34
  (0, remotion_1.continueRender)(id);
33
35
  });
36
+ if (error) {
37
+ console.error(error.stack);
38
+ if ((0, is_cors_error_1.isCorsError)(error)) {
39
+ throw new Error(`Failed to render GIF with source ${src}: "${error.message}". You must enable CORS for this URL.`);
40
+ }
41
+ throw new Error(`Failed to render GIF with source ${src}: "${error.message}". Render with --log=verbose to see the full stack.`);
42
+ }
34
43
  return ((0, jsx_runtime_1.jsx)(tools_1.Canvas, { fit: fit, index: index, frames: state.frames, width: width !== null && width !== void 0 ? width : state.width, height: height !== null && height !== void 0 ? height : state.height, ...props, ref: ref }));
35
44
  });
@@ -0,0 +1 @@
1
+ export declare const isCorsError: (error: Error) => boolean;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCorsError = void 0;
4
+ const isCorsError = (error) => {
5
+ return (
6
+ // Chrome
7
+ error.message.includes('Failed to fetch') ||
8
+ // Safari
9
+ error.message.includes('Load failed') ||
10
+ // Firefox
11
+ error.message.includes('NetworkError when attempting to fetch resource'));
12
+ };
13
+ exports.isCorsError = isCorsError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/gif",
3
- "version": "3.1.4",
3
+ "version": "3.1.7",
4
4
  "description": "Gif component for remotion",
5
5
  "sideEffects": false,
6
6
  "repository": {
@@ -23,7 +23,7 @@
23
23
  "dependencies": {
24
24
  "@react-gifs/tools": "0.1.2",
25
25
  "lru_map": "0.4.1",
26
- "remotion": "3.1.4"
26
+ "remotion": "3.1.7"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@jonny/eslint-config": "3.0.266",
@@ -54,5 +54,5 @@
54
54
  "publishConfig": {
55
55
  "access": "public"
56
56
  },
57
- "gitHead": "cb662e72c635e5e70c5541d85e276ce2f4075099"
57
+ "gitHead": "599379fef6043a7125d1979766f915580ec1cf77"
58
58
  }