@remotion/gif 4.0.534 → 4.0.535
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/Gif.js +31 -16
- package/dist/cjs/GifForRendering.js +12 -15
- package/dist/cjs/canvas.js +1 -1
- package/dist/cjs/use-element-size.js +1 -1
- package/dist/esm/index.mjs +82 -64
- package/package.json +3 -3
package/dist/cjs/Gif.js
CHANGED
|
@@ -86,17 +86,21 @@ const GifWithIntrinsicDuration = (props) => {
|
|
|
86
86
|
onErrorRef.current = props.onError;
|
|
87
87
|
const requestInitRef = (0, react_2.useRef)(requestInit);
|
|
88
88
|
requestInitRef.current = requestInit;
|
|
89
|
-
const [
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
const [duration, setDuration] = (0, react_2.useState)(null);
|
|
90
|
+
const [failedHandle, setFailedHandle] = (0, react_2.useState)(null);
|
|
91
|
+
const { delayRenderTimeoutInMilliseconds } = props;
|
|
92
|
+
(0, react_2.useLayoutEffect)(() => {
|
|
93
|
+
const handle = delayRender(`Finding duration of <Gif src="${src}" />`, {
|
|
94
|
+
timeoutInMilliseconds: delayRenderTimeoutInMilliseconds,
|
|
95
|
+
});
|
|
95
96
|
let cancelled = false;
|
|
96
97
|
(0, get_gif_duration_in_seconds_1.getGifDurationInSeconds)(src, { requestInit: requestInitRef.current })
|
|
97
|
-
.then((
|
|
98
|
+
.then((durationInSeconds) => {
|
|
98
99
|
if (!cancelled) {
|
|
99
|
-
|
|
100
|
+
setDuration({
|
|
101
|
+
durationInFrames: Math.ceil(durationInSeconds * fps) - (trimBefore !== null && trimBefore !== void 0 ? trimBefore : 0),
|
|
102
|
+
handle,
|
|
103
|
+
});
|
|
100
104
|
}
|
|
101
105
|
})
|
|
102
106
|
.catch((error) => {
|
|
@@ -105,7 +109,7 @@ const GifWithIntrinsicDuration = (props) => {
|
|
|
105
109
|
}
|
|
106
110
|
if (onErrorRef.current) {
|
|
107
111
|
onErrorRef.current(error);
|
|
108
|
-
|
|
112
|
+
setFailedHandle(handle);
|
|
109
113
|
}
|
|
110
114
|
else {
|
|
111
115
|
cancelRender(error);
|
|
@@ -115,16 +119,27 @@ const GifWithIntrinsicDuration = (props) => {
|
|
|
115
119
|
cancelled = true;
|
|
116
120
|
continueRender(handle);
|
|
117
121
|
};
|
|
118
|
-
}, [
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
+
}, [
|
|
123
|
+
cancelRender,
|
|
124
|
+
continueRender,
|
|
125
|
+
delayRender,
|
|
126
|
+
delayRenderTimeoutInMilliseconds,
|
|
127
|
+
fps,
|
|
128
|
+
src,
|
|
129
|
+
trimBefore,
|
|
130
|
+
]);
|
|
131
|
+
(0, react_2.useLayoutEffect)(() => {
|
|
132
|
+
if (duration !== null) {
|
|
133
|
+
continueRender(duration.handle);
|
|
134
|
+
}
|
|
135
|
+
if (failedHandle !== null) {
|
|
136
|
+
continueRender(failedHandle);
|
|
122
137
|
}
|
|
123
|
-
}, [continueRender,
|
|
124
|
-
if (
|
|
138
|
+
}, [continueRender, duration, failedHandle]);
|
|
139
|
+
if (duration === null || failedHandle !== null) {
|
|
125
140
|
return null;
|
|
126
141
|
}
|
|
127
|
-
return jsx_runtime_1.jsx(GifInner, { ...props, durationInFrames: durationInFrames });
|
|
142
|
+
return jsx_runtime_1.jsx(GifInner, { ...props, durationInFrames: duration.durationInFrames });
|
|
128
143
|
};
|
|
129
144
|
const GifComponent = (props) => {
|
|
130
145
|
var _a;
|
|
@@ -25,20 +25,13 @@ exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad,
|
|
|
25
25
|
frames: [],
|
|
26
26
|
width: 0,
|
|
27
27
|
height: 0,
|
|
28
|
+
handle: null,
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
|
-
return parsedGif;
|
|
31
|
+
return { ...parsedGif, handle: null };
|
|
31
32
|
});
|
|
32
33
|
const [error, setError] = (0, react_1.useState)(null);
|
|
33
|
-
const [renderHandle] = (0, react_1.useState)(() => delayRender(`Rendering <Gif/> with src="${resolvedSrc}"`, {
|
|
34
|
-
timeoutInMilliseconds: delayRenderTimeoutInMilliseconds,
|
|
35
|
-
}));
|
|
36
34
|
const logLevel = remotion_1.Internals.useLogLevel();
|
|
37
|
-
(0, react_1.useEffect)(() => {
|
|
38
|
-
return () => {
|
|
39
|
-
continueRender(renderHandle);
|
|
40
|
-
};
|
|
41
|
-
}, [renderHandle, continueRender]);
|
|
42
35
|
const index = (0, useCurrentGifIndex_1.useCurrentGifIndex)({
|
|
43
36
|
delays: state.delays,
|
|
44
37
|
loopBehavior,
|
|
@@ -48,7 +41,7 @@ exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad,
|
|
|
48
41
|
const currentOnError = (0, react_1.useRef)(onError);
|
|
49
42
|
currentOnLoad.current = onLoad;
|
|
50
43
|
currentOnError.current = onError;
|
|
51
|
-
(0, react_1.
|
|
44
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
52
45
|
const controller = new AbortController();
|
|
53
46
|
let done = false;
|
|
54
47
|
let aborted = false;
|
|
@@ -64,13 +57,14 @@ exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad,
|
|
|
64
57
|
})
|
|
65
58
|
.then((parsed) => {
|
|
66
59
|
var _a;
|
|
60
|
+
if (aborted) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
67
63
|
remotion_1.Internals.Log.verbose({ logLevel, tag: null }, 'Parsed GIF in', Date.now() - time, 'ms');
|
|
68
64
|
(_a = currentOnLoad.current) === null || _a === void 0 ? void 0 : _a.call(currentOnLoad, parsed);
|
|
69
|
-
update(parsed);
|
|
65
|
+
update({ ...parsed, handle: newHandle });
|
|
70
66
|
gif_cache_1.volatileGifCache.set(cacheKey, parsed);
|
|
71
67
|
done = true;
|
|
72
|
-
continueRender(newHandle);
|
|
73
|
-
continueRender(renderHandle);
|
|
74
68
|
})
|
|
75
69
|
.catch((err) => {
|
|
76
70
|
if (aborted) {
|
|
@@ -91,10 +85,8 @@ exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad,
|
|
|
91
85
|
controller.abort();
|
|
92
86
|
}
|
|
93
87
|
continueRender(newHandle);
|
|
94
|
-
continueRender(renderHandle);
|
|
95
88
|
};
|
|
96
89
|
}, [
|
|
97
|
-
renderHandle,
|
|
98
90
|
logLevel,
|
|
99
91
|
cacheKey,
|
|
100
92
|
resolvedSrc,
|
|
@@ -102,6 +94,11 @@ exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad,
|
|
|
102
94
|
continueRender,
|
|
103
95
|
delayRenderTimeoutInMilliseconds,
|
|
104
96
|
]);
|
|
97
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
98
|
+
if (state.handle !== null) {
|
|
99
|
+
continueRender(state.handle);
|
|
100
|
+
}
|
|
101
|
+
}, [state, continueRender]);
|
|
105
102
|
if (error) {
|
|
106
103
|
remotion_1.Internals.Log.error({ logLevel, tag: null }, error.stack);
|
|
107
104
|
if ((0, is_cors_error_1.isCorsError)(error)) {
|
package/dist/cjs/canvas.js
CHANGED
|
@@ -88,7 +88,7 @@ exports.Canvas = (0, react_1.forwardRef)(({ index, frames, width, height, fit, c
|
|
|
88
88
|
(0, react_1.useImperativeHandle)(ref, () => {
|
|
89
89
|
return canvasRef.current;
|
|
90
90
|
}, []);
|
|
91
|
-
(0, react_1.
|
|
91
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
92
92
|
if (!size) {
|
|
93
93
|
return;
|
|
94
94
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -785,15 +785,15 @@ var makeWorker = () => {
|
|
|
785
785
|
|
|
786
786
|
// src/react-tools.ts
|
|
787
787
|
var parseGif = async ({
|
|
788
|
-
src
|
|
788
|
+
src,
|
|
789
789
|
controller,
|
|
790
790
|
requestInit
|
|
791
791
|
}) => {
|
|
792
|
-
const raw = await parse2(
|
|
792
|
+
const raw = await parse2(src, { signal: controller.signal, requestInit });
|
|
793
793
|
return generate(raw);
|
|
794
794
|
};
|
|
795
795
|
var parseWithWorker = ({
|
|
796
|
-
src
|
|
796
|
+
src,
|
|
797
797
|
cacheKey,
|
|
798
798
|
requestInit
|
|
799
799
|
}) => {
|
|
@@ -815,7 +815,7 @@ var parseWithWorker = ({
|
|
|
815
815
|
};
|
|
816
816
|
worker.addEventListener("message", handler);
|
|
817
817
|
worker.postMessage({
|
|
818
|
-
src
|
|
818
|
+
src,
|
|
819
819
|
cacheKey,
|
|
820
820
|
requestInit: workerRequestInit,
|
|
821
821
|
type: "parse"
|
|
@@ -832,19 +832,19 @@ var parseWithWorker = ({
|
|
|
832
832
|
};
|
|
833
833
|
|
|
834
834
|
// src/resolve-gif-source.ts
|
|
835
|
-
var resolveGifSource = (
|
|
835
|
+
var resolveGifSource = (src) => {
|
|
836
836
|
if (typeof window === "undefined") {
|
|
837
|
-
return
|
|
837
|
+
return src;
|
|
838
838
|
}
|
|
839
|
-
return new URL(
|
|
839
|
+
return new URL(src, document.baseURI).href;
|
|
840
840
|
};
|
|
841
841
|
|
|
842
842
|
// src/get-gif-duration-in-seconds.ts
|
|
843
843
|
var calcDuration = (parsed) => {
|
|
844
844
|
return parsed.delays.reduce((sum, delay) => sum + delay, 0) / 1000;
|
|
845
845
|
};
|
|
846
|
-
var getGifDurationInSeconds = async (
|
|
847
|
-
const resolvedSrc = resolveGifSource(
|
|
846
|
+
var getGifDurationInSeconds = async (src, options) => {
|
|
847
|
+
const resolvedSrc = resolveGifSource(src);
|
|
848
848
|
const cacheKey = getGifCacheKey({
|
|
849
849
|
resolvedSrc,
|
|
850
850
|
requestInit: options?.requestInit
|
|
@@ -872,7 +872,7 @@ var getGifDurationInSeconds = async (src2, options) => {
|
|
|
872
872
|
return calcDuration(parsed);
|
|
873
873
|
};
|
|
874
874
|
// src/Gif.tsx
|
|
875
|
-
import React, {
|
|
875
|
+
import React, { useLayoutEffect as useLayoutEffect4, useRef as useRef4, useState as useState5 } from "react";
|
|
876
876
|
import {
|
|
877
877
|
Freeze,
|
|
878
878
|
Internals as Internals3,
|
|
@@ -884,12 +884,12 @@ import {
|
|
|
884
884
|
} from "remotion";
|
|
885
885
|
|
|
886
886
|
// src/GifForDevelopment.tsx
|
|
887
|
-
import { forwardRef as forwardRef2, useEffect as
|
|
887
|
+
import { forwardRef as forwardRef2, useEffect as useEffect2, useRef as useRef2, useState as useState3 } from "react";
|
|
888
888
|
|
|
889
889
|
// src/canvas.tsx
|
|
890
890
|
import {
|
|
891
891
|
forwardRef,
|
|
892
|
-
|
|
892
|
+
useLayoutEffect as useLayoutEffect2,
|
|
893
893
|
useImperativeHandle,
|
|
894
894
|
useMemo as useMemo2,
|
|
895
895
|
useRef,
|
|
@@ -898,7 +898,13 @@ import {
|
|
|
898
898
|
import { Internals, useDelayRender } from "remotion";
|
|
899
899
|
|
|
900
900
|
// src/use-element-size.ts
|
|
901
|
-
import {
|
|
901
|
+
import {
|
|
902
|
+
useCallback,
|
|
903
|
+
useEffect,
|
|
904
|
+
useLayoutEffect,
|
|
905
|
+
useMemo,
|
|
906
|
+
useState
|
|
907
|
+
} from "react";
|
|
902
908
|
var elementSizeHooks = [];
|
|
903
909
|
var useElementSize = (ref) => {
|
|
904
910
|
const [size, setSize] = useState(null);
|
|
@@ -936,7 +942,7 @@ var useElementSize = (ref) => {
|
|
|
936
942
|
height: rect[0].height
|
|
937
943
|
});
|
|
938
944
|
}, [ref]);
|
|
939
|
-
|
|
945
|
+
useLayoutEffect(() => {
|
|
940
946
|
if (!observer) {
|
|
941
947
|
return;
|
|
942
948
|
}
|
|
@@ -1044,7 +1050,7 @@ var Canvas = forwardRef(({ index, frames, width, height, fit, className, style,
|
|
|
1044
1050
|
useImperativeHandle(ref, () => {
|
|
1045
1051
|
return canvasRef.current;
|
|
1046
1052
|
}, []);
|
|
1047
|
-
|
|
1053
|
+
useLayoutEffect2(() => {
|
|
1048
1054
|
if (!size) {
|
|
1049
1055
|
return;
|
|
1050
1056
|
}
|
|
@@ -1199,7 +1205,7 @@ function useCurrentGifIndex({
|
|
|
1199
1205
|
// src/GifForDevelopment.tsx
|
|
1200
1206
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
1201
1207
|
var GifForDevelopment = forwardRef2(({
|
|
1202
|
-
src
|
|
1208
|
+
src,
|
|
1203
1209
|
width,
|
|
1204
1210
|
height,
|
|
1205
1211
|
onError,
|
|
@@ -1211,7 +1217,7 @@ var GifForDevelopment = forwardRef2(({
|
|
|
1211
1217
|
effects,
|
|
1212
1218
|
...props
|
|
1213
1219
|
}, ref) => {
|
|
1214
|
-
const resolvedSrc = resolveGifSource(
|
|
1220
|
+
const resolvedSrc = resolveGifSource(src);
|
|
1215
1221
|
const requestInitRef = useRef2(requestInit);
|
|
1216
1222
|
requestInitRef.current = requestInit;
|
|
1217
1223
|
const cacheKey = getGifCacheKey({ resolvedSrc, requestInit });
|
|
@@ -1232,7 +1238,7 @@ var GifForDevelopment = forwardRef2(({
|
|
|
1232
1238
|
const currentOnError = useRef2(onError);
|
|
1233
1239
|
currentOnLoad.current = onLoad;
|
|
1234
1240
|
currentOnError.current = onError;
|
|
1235
|
-
|
|
1241
|
+
useEffect2(() => {
|
|
1236
1242
|
const parsedGif = volatileGifCache.get(cacheKey) ?? manuallyManagedGifCache.get(cacheKey);
|
|
1237
1243
|
if (parsedGif !== undefined) {
|
|
1238
1244
|
update(parsedGif);
|
|
@@ -1271,9 +1277,9 @@ var GifForDevelopment = forwardRef2(({
|
|
|
1271
1277
|
if (error) {
|
|
1272
1278
|
console.error(error.stack);
|
|
1273
1279
|
if (isCorsError(error)) {
|
|
1274
|
-
throw new Error(`Failed to render GIF with source ${
|
|
1280
|
+
throw new Error(`Failed to render GIF with source ${src}: "${error.message}". You must enable CORS for this URL. Open the Developer Tools to see exactly why this fetch failed.`);
|
|
1275
1281
|
}
|
|
1276
|
-
throw new Error(`Failed to render GIF with source ${
|
|
1282
|
+
throw new Error(`Failed to render GIF with source ${src}: "${error.message}".`);
|
|
1277
1283
|
}
|
|
1278
1284
|
const index = useCurrentGifIndex({
|
|
1279
1285
|
delays: state.delays,
|
|
@@ -1296,11 +1302,11 @@ var GifForDevelopment = forwardRef2(({
|
|
|
1296
1302
|
});
|
|
1297
1303
|
|
|
1298
1304
|
// src/GifForRendering.tsx
|
|
1299
|
-
import { forwardRef as forwardRef3,
|
|
1305
|
+
import { forwardRef as forwardRef3, useLayoutEffect as useLayoutEffect3, useRef as useRef3, useState as useState4 } from "react";
|
|
1300
1306
|
import { Internals as Internals2, useDelayRender as useDelayRender2 } from "remotion";
|
|
1301
1307
|
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
1302
1308
|
var GifForRendering = forwardRef3(({
|
|
1303
|
-
src
|
|
1309
|
+
src,
|
|
1304
1310
|
width,
|
|
1305
1311
|
height,
|
|
1306
1312
|
onLoad,
|
|
@@ -1313,7 +1319,7 @@ var GifForRendering = forwardRef3(({
|
|
|
1313
1319
|
effects,
|
|
1314
1320
|
...props
|
|
1315
1321
|
}, ref) => {
|
|
1316
|
-
const resolvedSrc = resolveGifSource(
|
|
1322
|
+
const resolvedSrc = resolveGifSource(src);
|
|
1317
1323
|
const requestInitRef = useRef3(requestInit);
|
|
1318
1324
|
requestInitRef.current = requestInit;
|
|
1319
1325
|
const cacheKey = getGifCacheKey({ resolvedSrc, requestInit });
|
|
@@ -1325,21 +1331,14 @@ var GifForRendering = forwardRef3(({
|
|
|
1325
1331
|
delays: [],
|
|
1326
1332
|
frames: [],
|
|
1327
1333
|
width: 0,
|
|
1328
|
-
height: 0
|
|
1334
|
+
height: 0,
|
|
1335
|
+
handle: null
|
|
1329
1336
|
};
|
|
1330
1337
|
}
|
|
1331
|
-
return parsedGif;
|
|
1338
|
+
return { ...parsedGif, handle: null };
|
|
1332
1339
|
});
|
|
1333
1340
|
const [error, setError] = useState4(null);
|
|
1334
|
-
const [renderHandle] = useState4(() => delayRender(`Rendering <Gif/> with src="${resolvedSrc}"`, {
|
|
1335
|
-
timeoutInMilliseconds: delayRenderTimeoutInMilliseconds
|
|
1336
|
-
}));
|
|
1337
1341
|
const logLevel = Internals2.useLogLevel();
|
|
1338
|
-
useEffect4(() => {
|
|
1339
|
-
return () => {
|
|
1340
|
-
continueRender(renderHandle);
|
|
1341
|
-
};
|
|
1342
|
-
}, [renderHandle, continueRender]);
|
|
1343
1342
|
const index = useCurrentGifIndex({
|
|
1344
1343
|
delays: state.delays,
|
|
1345
1344
|
loopBehavior,
|
|
@@ -1349,7 +1348,7 @@ var GifForRendering = forwardRef3(({
|
|
|
1349
1348
|
const currentOnError = useRef3(onError);
|
|
1350
1349
|
currentOnLoad.current = onLoad;
|
|
1351
1350
|
currentOnError.current = onError;
|
|
1352
|
-
|
|
1351
|
+
useLayoutEffect3(() => {
|
|
1353
1352
|
const controller = new AbortController;
|
|
1354
1353
|
let done = false;
|
|
1355
1354
|
let aborted = false;
|
|
@@ -1363,13 +1362,14 @@ var GifForRendering = forwardRef3(({
|
|
|
1363
1362
|
src: resolvedSrc,
|
|
1364
1363
|
requestInit: requestInitRef.current
|
|
1365
1364
|
}).then((parsed) => {
|
|
1365
|
+
if (aborted) {
|
|
1366
|
+
return;
|
|
1367
|
+
}
|
|
1366
1368
|
Internals2.Log.verbose({ logLevel, tag: null }, "Parsed GIF in", Date.now() - time, "ms");
|
|
1367
1369
|
currentOnLoad.current?.(parsed);
|
|
1368
|
-
update(parsed);
|
|
1370
|
+
update({ ...parsed, handle: newHandle });
|
|
1369
1371
|
volatileGifCache.set(cacheKey, parsed);
|
|
1370
1372
|
done = true;
|
|
1371
|
-
continueRender(newHandle);
|
|
1372
|
-
continueRender(renderHandle);
|
|
1373
1373
|
}).catch((err) => {
|
|
1374
1374
|
if (aborted) {
|
|
1375
1375
|
continueRender(newHandle);
|
|
@@ -1388,10 +1388,8 @@ var GifForRendering = forwardRef3(({
|
|
|
1388
1388
|
controller.abort();
|
|
1389
1389
|
}
|
|
1390
1390
|
continueRender(newHandle);
|
|
1391
|
-
continueRender(renderHandle);
|
|
1392
1391
|
};
|
|
1393
1392
|
}, [
|
|
1394
|
-
renderHandle,
|
|
1395
1393
|
logLevel,
|
|
1396
1394
|
cacheKey,
|
|
1397
1395
|
resolvedSrc,
|
|
@@ -1399,12 +1397,17 @@ var GifForRendering = forwardRef3(({
|
|
|
1399
1397
|
continueRender,
|
|
1400
1398
|
delayRenderTimeoutInMilliseconds
|
|
1401
1399
|
]);
|
|
1400
|
+
useLayoutEffect3(() => {
|
|
1401
|
+
if (state.handle !== null) {
|
|
1402
|
+
continueRender(state.handle);
|
|
1403
|
+
}
|
|
1404
|
+
}, [state, continueRender]);
|
|
1402
1405
|
if (error) {
|
|
1403
1406
|
Internals2.Log.error({ logLevel, tag: null }, error.stack);
|
|
1404
1407
|
if (isCorsError(error)) {
|
|
1405
|
-
throw new Error(`Failed to render GIF with source ${
|
|
1408
|
+
throw new Error(`Failed to render GIF with source ${src}: "${error.message}". You must enable CORS for this URL.`);
|
|
1406
1409
|
}
|
|
1407
|
-
throw new Error(`Failed to render GIF with source ${
|
|
1410
|
+
throw new Error(`Failed to render GIF with source ${src}: "${error.message}". Render with --log=verbose to see the full stack.`);
|
|
1408
1411
|
}
|
|
1409
1412
|
if (index === -1) {
|
|
1410
1413
|
return null;
|
|
@@ -1441,7 +1444,7 @@ var gifSchema = {
|
|
|
1441
1444
|
...Interactive.cropSchema
|
|
1442
1445
|
};
|
|
1443
1446
|
var GifInner = ({
|
|
1444
|
-
src
|
|
1447
|
+
src,
|
|
1445
1448
|
width,
|
|
1446
1449
|
height,
|
|
1447
1450
|
onLoad,
|
|
@@ -1506,7 +1509,7 @@ var GifInner = ({
|
|
|
1506
1509
|
videoConfigValues: controls?.videoConfigValues ?? null
|
|
1507
1510
|
});
|
|
1508
1511
|
const gifProps = {
|
|
1509
|
-
src
|
|
1512
|
+
src,
|
|
1510
1513
|
width,
|
|
1511
1514
|
height,
|
|
1512
1515
|
onLoad,
|
|
@@ -1550,21 +1553,25 @@ var GifInner = ({
|
|
|
1550
1553
|
var GifWithIntrinsicDuration = (props) => {
|
|
1551
1554
|
const { fps } = useVideoConfig2();
|
|
1552
1555
|
const { delayRender, continueRender, cancelRender } = useDelayRender3();
|
|
1553
|
-
const { src
|
|
1556
|
+
const { src, requestInit, trimBefore } = props;
|
|
1554
1557
|
const onErrorRef = useRef4(props.onError);
|
|
1555
1558
|
onErrorRef.current = props.onError;
|
|
1556
1559
|
const requestInitRef = useRef4(requestInit);
|
|
1557
1560
|
requestInitRef.current = requestInit;
|
|
1558
|
-
const [
|
|
1559
|
-
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1561
|
+
const [duration, setDuration] = useState5(null);
|
|
1562
|
+
const [failedHandle, setFailedHandle] = useState5(null);
|
|
1563
|
+
const { delayRenderTimeoutInMilliseconds } = props;
|
|
1564
|
+
useLayoutEffect4(() => {
|
|
1565
|
+
const handle = delayRender(`Finding duration of <Gif src="${src}" />`, {
|
|
1566
|
+
timeoutInMilliseconds: delayRenderTimeoutInMilliseconds
|
|
1567
|
+
});
|
|
1564
1568
|
let cancelled = false;
|
|
1565
|
-
getGifDurationInSeconds(
|
|
1569
|
+
getGifDurationInSeconds(src, { requestInit: requestInitRef.current }).then((durationInSeconds) => {
|
|
1566
1570
|
if (!cancelled) {
|
|
1567
|
-
|
|
1571
|
+
setDuration({
|
|
1572
|
+
durationInFrames: Math.ceil(durationInSeconds * fps) - (trimBefore ?? 0),
|
|
1573
|
+
handle
|
|
1574
|
+
});
|
|
1568
1575
|
}
|
|
1569
1576
|
}).catch((error) => {
|
|
1570
1577
|
if (cancelled) {
|
|
@@ -1572,7 +1579,7 @@ var GifWithIntrinsicDuration = (props) => {
|
|
|
1572
1579
|
}
|
|
1573
1580
|
if (onErrorRef.current) {
|
|
1574
1581
|
onErrorRef.current(error);
|
|
1575
|
-
|
|
1582
|
+
setFailedHandle(handle);
|
|
1576
1583
|
} else {
|
|
1577
1584
|
cancelRender(error);
|
|
1578
1585
|
}
|
|
@@ -1581,18 +1588,29 @@ var GifWithIntrinsicDuration = (props) => {
|
|
|
1581
1588
|
cancelled = true;
|
|
1582
1589
|
continueRender(handle);
|
|
1583
1590
|
};
|
|
1584
|
-
}, [
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1591
|
+
}, [
|
|
1592
|
+
cancelRender,
|
|
1593
|
+
continueRender,
|
|
1594
|
+
delayRender,
|
|
1595
|
+
delayRenderTimeoutInMilliseconds,
|
|
1596
|
+
fps,
|
|
1597
|
+
src,
|
|
1598
|
+
trimBefore
|
|
1599
|
+
]);
|
|
1600
|
+
useLayoutEffect4(() => {
|
|
1601
|
+
if (duration !== null) {
|
|
1602
|
+
continueRender(duration.handle);
|
|
1603
|
+
}
|
|
1604
|
+
if (failedHandle !== null) {
|
|
1605
|
+
continueRender(failedHandle);
|
|
1588
1606
|
}
|
|
1589
|
-
}, [continueRender,
|
|
1590
|
-
if (
|
|
1607
|
+
}, [continueRender, duration, failedHandle]);
|
|
1608
|
+
if (duration === null || failedHandle !== null) {
|
|
1591
1609
|
return null;
|
|
1592
1610
|
}
|
|
1593
1611
|
return /* @__PURE__ */ jsx4(GifInner, {
|
|
1594
1612
|
...props,
|
|
1595
|
-
durationInFrames
|
|
1613
|
+
durationInFrames: duration.durationInFrames
|
|
1596
1614
|
});
|
|
1597
1615
|
};
|
|
1598
1616
|
var GifComponent = (props) => {
|
|
@@ -1620,8 +1638,8 @@ var Gif = Interactive.withSchema({
|
|
|
1620
1638
|
});
|
|
1621
1639
|
Gif.displayName = "Gif";
|
|
1622
1640
|
// src/preload-gif.ts
|
|
1623
|
-
var preloadGif = (
|
|
1624
|
-
const resolvedSrc = resolveGifSource(
|
|
1641
|
+
var preloadGif = (src, options) => {
|
|
1642
|
+
const resolvedSrc = resolveGifSource(src);
|
|
1625
1643
|
const cacheKey = getGifCacheKey({
|
|
1626
1644
|
resolvedSrc,
|
|
1627
1645
|
requestInit: options?.requestInit
|
|
@@ -1661,7 +1679,7 @@ var preloadGif = (src2, options) => {
|
|
|
1661
1679
|
};
|
|
1662
1680
|
};
|
|
1663
1681
|
export {
|
|
1664
|
-
|
|
1682
|
+
Gif,
|
|
1665
1683
|
getGifDurationInSeconds,
|
|
1666
|
-
|
|
1684
|
+
preloadGif
|
|
1667
1685
|
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"url": "https://github.com/remotion-dev/remotion/tree/main/packages/gif"
|
|
4
4
|
},
|
|
5
5
|
"name": "@remotion/gif",
|
|
6
|
-
"version": "4.0.
|
|
6
|
+
"version": "4.0.535",
|
|
7
7
|
"description": "Embed GIFs in a Remotion video",
|
|
8
8
|
"bugs": {
|
|
9
9
|
"url": "https://github.com/remotion-dev/remotion/issues"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"remotion": "4.0.
|
|
33
|
+
"remotion": "4.0.535"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@testing-library/react": "16.1.0",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"react": "19.2.3",
|
|
39
39
|
"react-dom": "19.2.3",
|
|
40
40
|
"webpack": "5.105.0",
|
|
41
|
-
"@remotion/eslint-config-internal": "4.0.
|
|
41
|
+
"@remotion/eslint-config-internal": "4.0.535",
|
|
42
42
|
"eslint": "9.19.0",
|
|
43
43
|
"@typescript/native-preview": "7.0.0-dev.20260217.1"
|
|
44
44
|
},
|