@remotion/gif 3.3.61 → 3.3.63
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.d.ts +7 -0
- package/dist/cjs/Gif.js +19 -0
- package/dist/cjs/GifForDevelopment.d.ts +3 -0
- package/dist/cjs/GifForDevelopment.js +81 -0
- package/dist/cjs/GifForRendering.d.ts +3 -0
- package/dist/cjs/GifForRendering.js +80 -0
- package/dist/cjs/canvas.d.ts +13 -0
- package/dist/cjs/canvas.js +96 -0
- package/dist/cjs/get-gif-duration-in-seconds.d.ts +5 -0
- package/dist/cjs/get-gif-duration-in-seconds.js +34 -0
- package/dist/cjs/gif-cache.d.ts +4 -0
- package/dist/cjs/gif-cache.js +6 -0
- package/dist/cjs/gifuct/deinterlace.d.ts +4 -0
- package/dist/cjs/gifuct/deinterlace.js +26 -0
- package/dist/cjs/gifuct/index.d.ts +4 -0
- package/dist/cjs/gifuct/index.js +54 -0
- package/dist/cjs/gifuct/lzw.d.ts +5 -0
- package/dist/cjs/gifuct/lzw.js +119 -0
- package/dist/cjs/gifuct/types.d.ts +96 -0
- package/dist/cjs/gifuct/types.js +2 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +9 -0
- package/dist/cjs/is-cors-error.d.ts +1 -0
- package/dist/cjs/is-cors-error.js +13 -0
- package/dist/cjs/js-binary-schema-parser/gif.d.ts +51 -0
- package/dist/cjs/js-binary-schema-parser/gif.js +158 -0
- package/dist/cjs/js-binary-schema-parser/parser.d.ts +9 -0
- package/dist/cjs/js-binary-schema-parser/parser.js +54 -0
- package/dist/cjs/js-binary-schema-parser/uint8-parser.d.ts +17 -0
- package/dist/cjs/js-binary-schema-parser/uint8-parser.js +79 -0
- package/dist/cjs/lru/index.d.ts +101 -0
- package/dist/cjs/lru/index.js +258 -0
- package/dist/cjs/parse-generate.d.ts +18 -0
- package/dist/cjs/parse-generate.js +96 -0
- package/dist/cjs/parser/decompress-frames.d.ts +2 -0
- package/dist/cjs/parser/decompress-frames.js +19 -0
- package/dist/cjs/preload-gif.d.ts +8 -0
- package/dist/cjs/preload-gif.js +41 -0
- package/dist/cjs/props.d.ts +24 -0
- package/dist/cjs/props.js +2 -0
- package/dist/cjs/react-tools.d.ts +9 -0
- package/dist/cjs/react-tools.js +40 -0
- package/dist/cjs/resolve-gif-source.d.ts +1 -0
- package/dist/cjs/resolve-gif-source.js +7 -0
- package/dist/cjs/use-element-size.d.ts +6 -0
- package/dist/cjs/use-element-size.js +73 -0
- package/dist/cjs/useCurrentGifIndex.d.ts +2 -0
- package/dist/cjs/useCurrentGifIndex.js +35 -0
- package/dist/cjs/worker/index.d.ts +1 -0
- package/dist/cjs/worker/index.js +12 -0
- package/dist/cjs/worker/source.d.ts +1 -0
- package/dist/cjs/worker/source.js +7 -0
- package/dist/cjs/worker/worker.d.ts +1 -0
- package/dist/cjs/worker/worker.js +39 -0
- package/dist/esm/Gif.d.ts +7 -0
- package/dist/esm/GifForDevelopment.d.ts +3 -0
- package/dist/esm/GifForRendering.d.ts +3 -0
- package/dist/esm/canvas.d.ts +13 -0
- package/dist/esm/get-gif-duration-in-seconds.d.ts +5 -0
- package/dist/esm/gif-cache.d.ts +4 -0
- package/dist/esm/gifuct/deinterlace.d.ts +4 -0
- package/dist/esm/gifuct/index.d.ts +4 -0
- package/dist/esm/gifuct/lzw.d.ts +5 -0
- package/dist/esm/gifuct/types.d.ts +96 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.mjs +1276 -0
- package/dist/esm/is-cors-error.d.ts +1 -0
- package/dist/esm/js-binary-schema-parser/gif.d.ts +51 -0
- package/dist/esm/js-binary-schema-parser/parser.d.ts +9 -0
- package/dist/esm/js-binary-schema-parser/uint8-parser.d.ts +17 -0
- package/dist/esm/lru/index.d.ts +101 -0
- package/dist/esm/parse-generate.d.ts +18 -0
- package/dist/esm/parser/decompress-frames.d.ts +2 -0
- package/dist/esm/preload-gif.d.ts +8 -0
- package/dist/esm/props.d.ts +24 -0
- package/dist/esm/react-tools.d.ts +9 -0
- package/dist/esm/resolve-gif-source.d.ts +1 -0
- package/dist/esm/use-element-size.d.ts +6 -0
- package/dist/esm/useCurrentGifIndex.d.ts +2 -0
- package/dist/esm/worker/index.d.ts +1 -0
- package/dist/esm/worker/source.d.ts +1 -0
- package/dist/esm/worker/worker.d.ts +1 -0
- package/dist/react-tools.js +0 -1
- package/dist/tsconfig-esm.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +19 -8
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { RemotionGifProps } from './props';
|
|
3
|
+
/**
|
|
4
|
+
* @description Displays a GIF that synchronizes with Remotions useCurrentFrame().
|
|
5
|
+
* @see [Documentation](https://www.remotion.dev/docs/gif/gif)
|
|
6
|
+
*/
|
|
7
|
+
export declare const Gif: (props: RemotionGifProps) => JSX.Element;
|
package/dist/cjs/Gif.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Gif = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const remotion_1 = require("remotion");
|
|
6
|
+
const GifForDevelopment_1 = require("./GifForDevelopment");
|
|
7
|
+
const GifForRendering_1 = require("./GifForRendering");
|
|
8
|
+
/**
|
|
9
|
+
* @description Displays a GIF that synchronizes with Remotions useCurrentFrame().
|
|
10
|
+
* @see [Documentation](https://www.remotion.dev/docs/gif/gif)
|
|
11
|
+
*/
|
|
12
|
+
const Gif = (props) => {
|
|
13
|
+
const env = remotion_1.Internals.useRemotionEnvironment();
|
|
14
|
+
if (env === 'rendering') {
|
|
15
|
+
return (0, jsx_runtime_1.jsx)(GifForRendering_1.GifForRendering, { ...props });
|
|
16
|
+
}
|
|
17
|
+
return (0, jsx_runtime_1.jsx)(GifForDevelopment_1.GifForDevelopment, { ...props });
|
|
18
|
+
};
|
|
19
|
+
exports.Gif = Gif;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GifForDevelopment = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const remotion_1 = require("remotion");
|
|
7
|
+
const canvas_1 = require("./canvas");
|
|
8
|
+
const gif_cache_1 = require("./gif-cache");
|
|
9
|
+
const is_cors_error_1 = require("./is-cors-error");
|
|
10
|
+
const react_tools_1 = require("./react-tools");
|
|
11
|
+
const resolve_gif_source_1 = require("./resolve-gif-source");
|
|
12
|
+
const useCurrentGifIndex_1 = require("./useCurrentGifIndex");
|
|
13
|
+
exports.GifForDevelopment = (0, react_1.forwardRef)(({ src, width, height, onError, loopBehavior = 'loop', onLoad, fit = 'fill', ...props }, ref) => {
|
|
14
|
+
const resolvedSrc = (0, resolve_gif_source_1.resolveGifSource)(src);
|
|
15
|
+
const [state, update] = (0, react_1.useState)(() => {
|
|
16
|
+
var _a;
|
|
17
|
+
const parsedGif = (_a = gif_cache_1.volatileGifCache.get(resolvedSrc)) !== null && _a !== void 0 ? _a : gif_cache_1.manuallyManagedGifCache.get(resolvedSrc);
|
|
18
|
+
if (parsedGif === undefined) {
|
|
19
|
+
return {
|
|
20
|
+
delays: [],
|
|
21
|
+
frames: [],
|
|
22
|
+
width: 0,
|
|
23
|
+
height: 0,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return parsedGif;
|
|
27
|
+
});
|
|
28
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
29
|
+
const [id] = (0, react_1.useState)(() => (0, remotion_1.delayRender)(`Rendering <Gif/> with src="${resolvedSrc}"`));
|
|
30
|
+
const currentOnLoad = (0, react_1.useRef)(onLoad);
|
|
31
|
+
const currentOnError = (0, react_1.useRef)(onError);
|
|
32
|
+
currentOnLoad.current = onLoad;
|
|
33
|
+
currentOnError.current = onError;
|
|
34
|
+
(0, react_1.useEffect)(() => {
|
|
35
|
+
let done = false;
|
|
36
|
+
let aborted = false;
|
|
37
|
+
const { prom, cancel } = (0, react_tools_1.parseWithWorker)(resolvedSrc);
|
|
38
|
+
const newHandle = (0, remotion_1.delayRender)('Loading <Gif /> with src=' + resolvedSrc);
|
|
39
|
+
prom
|
|
40
|
+
.then((parsed) => {
|
|
41
|
+
var _a;
|
|
42
|
+
(_a = currentOnLoad.current) === null || _a === void 0 ? void 0 : _a.call(currentOnLoad, parsed);
|
|
43
|
+
update(parsed);
|
|
44
|
+
gif_cache_1.volatileGifCache.set(resolvedSrc, parsed);
|
|
45
|
+
done = true;
|
|
46
|
+
(0, remotion_1.continueRender)(newHandle);
|
|
47
|
+
(0, remotion_1.continueRender)(id);
|
|
48
|
+
})
|
|
49
|
+
.catch((err) => {
|
|
50
|
+
if (aborted) {
|
|
51
|
+
(0, remotion_1.continueRender)(newHandle);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (currentOnError.current) {
|
|
55
|
+
currentOnError.current(err);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
setError(err);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return () => {
|
|
62
|
+
if (!done) {
|
|
63
|
+
aborted = true;
|
|
64
|
+
cancel();
|
|
65
|
+
}
|
|
66
|
+
(0, remotion_1.continueRender)(newHandle);
|
|
67
|
+
};
|
|
68
|
+
}, [id, resolvedSrc]);
|
|
69
|
+
if (error) {
|
|
70
|
+
console.error(error.stack);
|
|
71
|
+
if ((0, is_cors_error_1.isCorsError)(error)) {
|
|
72
|
+
throw new Error(`Failed to render GIF with source ${src}: "${error.message}". You must enable CORS for this URL.`);
|
|
73
|
+
}
|
|
74
|
+
throw new Error(`Failed to render GIF with source ${src}: "${error.message}".`);
|
|
75
|
+
}
|
|
76
|
+
const index = (0, useCurrentGifIndex_1.useCurrentGifIndex)(state.delays, loopBehavior);
|
|
77
|
+
if (index === -1) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
return ((0, jsx_runtime_1.jsx)(canvas_1.Canvas, { fit: fit, index: index, frames: state.frames, width: width, height: height, ...props, ref: ref }));
|
|
81
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GifForRendering = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const remotion_1 = require("remotion");
|
|
7
|
+
const canvas_1 = require("./canvas");
|
|
8
|
+
const gif_cache_1 = require("./gif-cache");
|
|
9
|
+
const is_cors_error_1 = require("./is-cors-error");
|
|
10
|
+
const react_tools_1 = require("./react-tools");
|
|
11
|
+
const resolve_gif_source_1 = require("./resolve-gif-source");
|
|
12
|
+
const useCurrentGifIndex_1 = require("./useCurrentGifIndex");
|
|
13
|
+
exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad, onError, loopBehavior = 'loop', fit = 'fill', ...props }, ref) => {
|
|
14
|
+
const resolvedSrc = (0, resolve_gif_source_1.resolveGifSource)(src);
|
|
15
|
+
const [state, update] = (0, react_1.useState)(() => {
|
|
16
|
+
const parsedGif = gif_cache_1.volatileGifCache.get(resolvedSrc);
|
|
17
|
+
if (parsedGif === undefined) {
|
|
18
|
+
return {
|
|
19
|
+
delays: [],
|
|
20
|
+
frames: [],
|
|
21
|
+
width: 0,
|
|
22
|
+
height: 0,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return parsedGif;
|
|
26
|
+
});
|
|
27
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
28
|
+
const [id] = (0, react_1.useState)(() => (0, remotion_1.delayRender)(`Rendering <Gif/> with src="${resolvedSrc}"`));
|
|
29
|
+
const index = (0, useCurrentGifIndex_1.useCurrentGifIndex)(state.delays, loopBehavior);
|
|
30
|
+
const currentOnLoad = (0, react_1.useRef)(onLoad);
|
|
31
|
+
const currentOnError = (0, react_1.useRef)(onError);
|
|
32
|
+
currentOnLoad.current = onLoad;
|
|
33
|
+
currentOnError.current = onError;
|
|
34
|
+
(0, react_1.useEffect)(() => {
|
|
35
|
+
const controller = new AbortController();
|
|
36
|
+
let done = false;
|
|
37
|
+
let aborted = false;
|
|
38
|
+
const newHandle = (0, remotion_1.delayRender)('Loading <Gif /> with src=' + resolvedSrc);
|
|
39
|
+
(0, react_tools_1.parseGif)({ controller, src: resolvedSrc })
|
|
40
|
+
.then((parsed) => {
|
|
41
|
+
var _a;
|
|
42
|
+
(_a = currentOnLoad.current) === null || _a === void 0 ? void 0 : _a.call(currentOnLoad, parsed);
|
|
43
|
+
update(parsed);
|
|
44
|
+
gif_cache_1.volatileGifCache.set(resolvedSrc, parsed);
|
|
45
|
+
done = true;
|
|
46
|
+
(0, remotion_1.continueRender)(newHandle);
|
|
47
|
+
(0, remotion_1.continueRender)(id);
|
|
48
|
+
})
|
|
49
|
+
.catch((err) => {
|
|
50
|
+
if (aborted) {
|
|
51
|
+
(0, remotion_1.continueRender)(newHandle);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (currentOnError.current) {
|
|
55
|
+
currentOnError.current(err);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
setError(err);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return () => {
|
|
62
|
+
if (!done) {
|
|
63
|
+
aborted = true;
|
|
64
|
+
controller.abort();
|
|
65
|
+
}
|
|
66
|
+
(0, remotion_1.continueRender)(newHandle);
|
|
67
|
+
};
|
|
68
|
+
}, [id, resolvedSrc]);
|
|
69
|
+
if (error) {
|
|
70
|
+
console.error(error.stack);
|
|
71
|
+
if ((0, is_cors_error_1.isCorsError)(error)) {
|
|
72
|
+
throw new Error(`Failed to render GIF with source ${src}: "${error.message}". You must enable CORS for this URL.`);
|
|
73
|
+
}
|
|
74
|
+
throw new Error(`Failed to render GIF with source ${src}: "${error.message}". Render with --log=verbose to see the full stack.`);
|
|
75
|
+
}
|
|
76
|
+
if (index === -1) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
return ((0, jsx_runtime_1.jsx)(canvas_1.Canvas, { fit: fit, index: index, frames: state.frames, width: width, height: height, ...props, ref: ref }));
|
|
80
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { GifFillMode } from './props';
|
|
3
|
+
declare type Props = {
|
|
4
|
+
index: number;
|
|
5
|
+
frames: ImageData[];
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
fit: GifFillMode;
|
|
9
|
+
className?: string;
|
|
10
|
+
style?: React.CSSProperties;
|
|
11
|
+
};
|
|
12
|
+
export declare const Canvas: import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<unknown>>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Canvas = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const use_element_size_1 = require("./use-element-size");
|
|
7
|
+
const calcArgs = (fit, frameSize, canvasSize) => {
|
|
8
|
+
switch (fit) {
|
|
9
|
+
case 'fill': {
|
|
10
|
+
return [
|
|
11
|
+
0,
|
|
12
|
+
0,
|
|
13
|
+
frameSize.width,
|
|
14
|
+
frameSize.height,
|
|
15
|
+
0,
|
|
16
|
+
0,
|
|
17
|
+
canvasSize.width,
|
|
18
|
+
canvasSize.height,
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
case 'contain': {
|
|
22
|
+
const ratio = Math.min(canvasSize.width / frameSize.width, canvasSize.height / frameSize.height);
|
|
23
|
+
const centerX = (canvasSize.width - frameSize.width * ratio) / 2;
|
|
24
|
+
const centerY = (canvasSize.height - frameSize.height * ratio) / 2;
|
|
25
|
+
return [
|
|
26
|
+
0,
|
|
27
|
+
0,
|
|
28
|
+
frameSize.width,
|
|
29
|
+
frameSize.height,
|
|
30
|
+
centerX,
|
|
31
|
+
centerY,
|
|
32
|
+
frameSize.width * ratio,
|
|
33
|
+
frameSize.height * ratio,
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
case 'cover': {
|
|
37
|
+
const ratio = Math.max(canvasSize.width / frameSize.width, canvasSize.height / frameSize.height);
|
|
38
|
+
const centerX = (canvasSize.width - frameSize.width * ratio) / 2;
|
|
39
|
+
const centerY = (canvasSize.height - frameSize.height * ratio) / 2;
|
|
40
|
+
return [
|
|
41
|
+
0,
|
|
42
|
+
0,
|
|
43
|
+
frameSize.width,
|
|
44
|
+
frameSize.height,
|
|
45
|
+
centerX,
|
|
46
|
+
centerY,
|
|
47
|
+
frameSize.width * ratio,
|
|
48
|
+
frameSize.height * ratio,
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
default:
|
|
52
|
+
throw new Error('Unknown fit: ' + fit);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const makeCanvas = () => {
|
|
56
|
+
if (typeof document === 'undefined') {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const canvas = document.createElement('canvas');
|
|
60
|
+
const ctx = canvas.getContext('2d');
|
|
61
|
+
canvas.width = 0;
|
|
62
|
+
canvas.height = 0;
|
|
63
|
+
return ctx;
|
|
64
|
+
};
|
|
65
|
+
exports.Canvas = (0, react_1.forwardRef)(({ index, frames, width, height, fit, className, style }, ref) => {
|
|
66
|
+
const canvasRef = (0, react_1.useRef)(null);
|
|
67
|
+
const [tempCtx] = (0, react_1.useState)(() => {
|
|
68
|
+
return makeCanvas();
|
|
69
|
+
});
|
|
70
|
+
const size = (0, use_element_size_1.useElementSize)(canvasRef);
|
|
71
|
+
(0, react_1.useImperativeHandle)(ref, () => {
|
|
72
|
+
return canvasRef.current;
|
|
73
|
+
}, []);
|
|
74
|
+
(0, react_1.useEffect)(() => {
|
|
75
|
+
var _a;
|
|
76
|
+
if (!size) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const imageData = frames[index];
|
|
80
|
+
const ctx = (_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.getContext('2d');
|
|
81
|
+
if (imageData && tempCtx && ctx) {
|
|
82
|
+
if (tempCtx.canvas.width < imageData.width ||
|
|
83
|
+
tempCtx.canvas.height < imageData.height) {
|
|
84
|
+
tempCtx.canvas.width = imageData.width;
|
|
85
|
+
tempCtx.canvas.height = imageData.height;
|
|
86
|
+
}
|
|
87
|
+
if (size.width > 0 && size.height > 0) {
|
|
88
|
+
ctx.clearRect(0, 0, size.width, size.height);
|
|
89
|
+
tempCtx.clearRect(0, 0, tempCtx.canvas.width, tempCtx.canvas.height);
|
|
90
|
+
}
|
|
91
|
+
tempCtx.putImageData(imageData, 0, 0);
|
|
92
|
+
ctx.drawImage(tempCtx.canvas, ...calcArgs(fit, imageData, { width: size.width, height: size.height }));
|
|
93
|
+
}
|
|
94
|
+
}, [index, frames, fit, tempCtx, size]);
|
|
95
|
+
return ((0, jsx_runtime_1.jsx)("canvas", { ref: canvasRef, className: className, style: style, width: width !== null && width !== void 0 ? width : size === null || size === void 0 ? void 0 : size.width, height: height !== null && height !== void 0 ? height : size === null || size === void 0 ? void 0 : size.height }));
|
|
96
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGifDurationInSeconds = void 0;
|
|
4
|
+
const remotion_1 = require("remotion");
|
|
5
|
+
const gif_cache_1 = require("./gif-cache");
|
|
6
|
+
const react_tools_1 = require("./react-tools");
|
|
7
|
+
const calcDuration = (parsed) => {
|
|
8
|
+
return (parsed.delays.reduce((sum, delay) => sum + delay, 0) / 1000);
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @description Gets the duration in seconds of a GIF
|
|
12
|
+
* @see [Documentation](https://www.remotion.dev/docs/gif/get-gif-duration-in-seconds)
|
|
13
|
+
*/
|
|
14
|
+
const getGifDurationInSeconds = async (src) => {
|
|
15
|
+
var _a;
|
|
16
|
+
const resolvedSrc = new URL(src, window.location.origin).href;
|
|
17
|
+
const inCache = (_a = gif_cache_1.volatileGifCache.get(resolvedSrc)) !== null && _a !== void 0 ? _a : gif_cache_1.manuallyManagedGifCache.get(resolvedSrc);
|
|
18
|
+
if (inCache) {
|
|
19
|
+
return calcDuration(inCache);
|
|
20
|
+
}
|
|
21
|
+
if (remotion_1.Internals.getRemotionEnvironment() === 'rendering') {
|
|
22
|
+
const renderingParsed = (0, react_tools_1.parseWithWorker)(resolvedSrc);
|
|
23
|
+
const resolved = await renderingParsed.prom;
|
|
24
|
+
gif_cache_1.volatileGifCache.set(resolvedSrc, resolved);
|
|
25
|
+
return calcDuration(resolved);
|
|
26
|
+
}
|
|
27
|
+
const parsed = await (0, react_tools_1.parseGif)({
|
|
28
|
+
src: resolvedSrc,
|
|
29
|
+
controller: new AbortController(),
|
|
30
|
+
});
|
|
31
|
+
gif_cache_1.volatileGifCache.set(resolvedSrc, parsed);
|
|
32
|
+
return calcDuration(parsed);
|
|
33
|
+
};
|
|
34
|
+
exports.getGifDurationInSeconds = getGifDurationInSeconds;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.manuallyManagedGifCache = exports.volatileGifCache = void 0;
|
|
4
|
+
const index_1 = require("./lru/index");
|
|
5
|
+
exports.volatileGifCache = new index_1.QuickLRU({ maxSize: 30 });
|
|
6
|
+
exports.manuallyManagedGifCache = new Map();
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Deinterlace function from https://github.com/shachaf/jsgif
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.deinterlace = void 0;
|
|
7
|
+
const deinterlace = (pixels, width) => {
|
|
8
|
+
const newPixels = new Array(pixels.length);
|
|
9
|
+
const rows = pixels.length / width;
|
|
10
|
+
const cpRow = function (toRow, _fromRow) {
|
|
11
|
+
const fromPixels = pixels.slice(_fromRow * width, (_fromRow + 1) * width);
|
|
12
|
+
newPixels.splice(...[toRow * width, width].concat(fromPixels));
|
|
13
|
+
};
|
|
14
|
+
// See appendix E.
|
|
15
|
+
const offsets = [0, 4, 2, 1];
|
|
16
|
+
const steps = [8, 8, 4, 2];
|
|
17
|
+
let fromRow = 0;
|
|
18
|
+
for (let pass = 0; pass < 4; pass++) {
|
|
19
|
+
for (let toRow = offsets[pass]; toRow < rows; toRow += steps[pass]) {
|
|
20
|
+
cpRow(toRow, fromRow);
|
|
21
|
+
fromRow++;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return newPixels;
|
|
25
|
+
};
|
|
26
|
+
exports.deinterlace = deinterlace;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Frame, ParsedFrameWithoutPatch, ParsedGif } from './types';
|
|
2
|
+
export declare const parseGIF: (arrayBuffer: ArrayBuffer) => ParsedGif;
|
|
3
|
+
export declare const decompressFrame: (frame: Frame, gct: [number, number, number][]) => ParsedFrameWithoutPatch | undefined;
|
|
4
|
+
export declare const decompressFrames: (parsedGif: ParsedGif) => (ParsedFrameWithoutPatch | undefined)[];
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decompressFrames = exports.decompressFrame = exports.parseGIF = void 0;
|
|
4
|
+
const gif_1 = require("../js-binary-schema-parser/gif");
|
|
5
|
+
const parser_1 = require("../js-binary-schema-parser/parser");
|
|
6
|
+
const uint8_parser_1 = require("../js-binary-schema-parser/uint8-parser");
|
|
7
|
+
const deinterlace_1 = require("./deinterlace");
|
|
8
|
+
const lzw_1 = require("./lzw");
|
|
9
|
+
const parseGIF = (arrayBuffer) => {
|
|
10
|
+
const byteData = new Uint8Array(arrayBuffer);
|
|
11
|
+
return (0, parser_1.parse)((0, uint8_parser_1.buildStream)(byteData), gif_1.GIF);
|
|
12
|
+
};
|
|
13
|
+
exports.parseGIF = parseGIF;
|
|
14
|
+
const decompressFrame = (frame, gct) => {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
if (!frame.image) {
|
|
17
|
+
console.warn('gif frame does not have associated image.');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const { image } = frame;
|
|
21
|
+
// get the number of pixels
|
|
22
|
+
const totalPixels = image.descriptor.width * image.descriptor.height;
|
|
23
|
+
// do lzw decompression
|
|
24
|
+
let pixels = (0, lzw_1.lzw)(image.data.minCodeSize, image.data.blocks, totalPixels);
|
|
25
|
+
// deal with interlacing if necessary
|
|
26
|
+
if ((_a = image.descriptor.lct) === null || _a === void 0 ? void 0 : _a.interlaced) {
|
|
27
|
+
pixels = (0, deinterlace_1.deinterlace)(pixels, image.descriptor.width);
|
|
28
|
+
}
|
|
29
|
+
const resultImage = {
|
|
30
|
+
pixels,
|
|
31
|
+
dims: {
|
|
32
|
+
top: frame.image.descriptor.top,
|
|
33
|
+
left: frame.image.descriptor.left,
|
|
34
|
+
width: frame.image.descriptor.width,
|
|
35
|
+
height: frame.image.descriptor.height,
|
|
36
|
+
},
|
|
37
|
+
colorTable: ((_b = image.descriptor.lct) === null || _b === void 0 ? void 0 : _b.exists)
|
|
38
|
+
? image.lct
|
|
39
|
+
: gct,
|
|
40
|
+
delay: (frame.gce.delay || 10) * 10,
|
|
41
|
+
disposalType: frame.gce.extras.disposal,
|
|
42
|
+
transparentIndex: frame.gce.extras.transparentColorGiven
|
|
43
|
+
? frame.gce.transparentColorIndex
|
|
44
|
+
: -1,
|
|
45
|
+
};
|
|
46
|
+
return resultImage;
|
|
47
|
+
};
|
|
48
|
+
exports.decompressFrame = decompressFrame;
|
|
49
|
+
const decompressFrames = (parsedGif) => {
|
|
50
|
+
return parsedGif.frames
|
|
51
|
+
.filter((f) => !('application' in f))
|
|
52
|
+
.map((f) => (0, exports.decompressFrame)(f, parsedGif.gct));
|
|
53
|
+
};
|
|
54
|
+
exports.decompressFrames = decompressFrames;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-multi-assign */
|
|
3
|
+
/* eslint-disable no-redeclare */
|
|
4
|
+
/* eslint-disable no-bitwise */
|
|
5
|
+
/* eslint-disable no-var */
|
|
6
|
+
/**
|
|
7
|
+
* javascript port of java LZW decompression
|
|
8
|
+
* Original java author url: https://gist.github.com/devunwired/4479231
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.lzw = void 0;
|
|
12
|
+
const lzw = (minCodeSize, data, pixelCount) => {
|
|
13
|
+
const MAX_STACK_SIZE = 4096;
|
|
14
|
+
const nullCode = -1;
|
|
15
|
+
const npix = pixelCount;
|
|
16
|
+
let available;
|
|
17
|
+
let code_mask;
|
|
18
|
+
let code_size;
|
|
19
|
+
let in_code;
|
|
20
|
+
let old_code;
|
|
21
|
+
var bits;
|
|
22
|
+
let code;
|
|
23
|
+
let i;
|
|
24
|
+
var datum;
|
|
25
|
+
var first;
|
|
26
|
+
var top;
|
|
27
|
+
var bi;
|
|
28
|
+
var pi;
|
|
29
|
+
const dstPixels = new Array(pixelCount);
|
|
30
|
+
const prefix = new Array(MAX_STACK_SIZE);
|
|
31
|
+
const suffix = new Array(MAX_STACK_SIZE);
|
|
32
|
+
const pixelStack = new Array(MAX_STACK_SIZE + 1);
|
|
33
|
+
// Initialize GIF data stream decoder.
|
|
34
|
+
const data_size = minCodeSize;
|
|
35
|
+
const clear = 1 << data_size;
|
|
36
|
+
const end_of_information = clear + 1;
|
|
37
|
+
available = clear + 2;
|
|
38
|
+
old_code = nullCode;
|
|
39
|
+
code_size = data_size + 1;
|
|
40
|
+
code_mask = (1 << code_size) - 1;
|
|
41
|
+
for (code = 0; code < clear; code++) {
|
|
42
|
+
prefix[code] = 0;
|
|
43
|
+
suffix[code] = code;
|
|
44
|
+
}
|
|
45
|
+
// Decode GIF pixel stream.
|
|
46
|
+
var datum;
|
|
47
|
+
var bits;
|
|
48
|
+
var first;
|
|
49
|
+
var top;
|
|
50
|
+
var pi;
|
|
51
|
+
var bi;
|
|
52
|
+
datum = bits = first = top = pi = bi = 0;
|
|
53
|
+
for (i = 0; i < npix;) {
|
|
54
|
+
if (top === 0) {
|
|
55
|
+
if (bits < code_size) {
|
|
56
|
+
// get the next byte
|
|
57
|
+
datum += data[bi] << bits;
|
|
58
|
+
bits += 8;
|
|
59
|
+
bi++;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
// Get the next code.
|
|
63
|
+
code = datum & code_mask;
|
|
64
|
+
datum >>= code_size;
|
|
65
|
+
bits -= code_size;
|
|
66
|
+
// Interpret the code
|
|
67
|
+
if (code > available || code === end_of_information) {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
if (code === clear) {
|
|
71
|
+
// Reset decoder.
|
|
72
|
+
code_size = data_size + 1;
|
|
73
|
+
code_mask = (1 << code_size) - 1;
|
|
74
|
+
available = clear + 2;
|
|
75
|
+
old_code = nullCode;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (old_code === nullCode) {
|
|
79
|
+
pixelStack[top++] = suffix[code];
|
|
80
|
+
old_code = code;
|
|
81
|
+
first = code;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
in_code = code;
|
|
85
|
+
if (code === available) {
|
|
86
|
+
pixelStack[top++] = first;
|
|
87
|
+
code = old_code;
|
|
88
|
+
}
|
|
89
|
+
while (code > clear) {
|
|
90
|
+
pixelStack[top++] = suffix[code];
|
|
91
|
+
code = prefix[code];
|
|
92
|
+
}
|
|
93
|
+
first = suffix[code] & 0xff;
|
|
94
|
+
pixelStack[top++] = first;
|
|
95
|
+
// add a new string to the table, but only if space is available
|
|
96
|
+
// if not, just continue with current table until a clear code is found
|
|
97
|
+
// (deferred clear code implementation as per GIF spec)
|
|
98
|
+
if (available < MAX_STACK_SIZE) {
|
|
99
|
+
prefix[available] = old_code;
|
|
100
|
+
suffix[available] = first;
|
|
101
|
+
available++;
|
|
102
|
+
if ((available & code_mask) === 0 && available < MAX_STACK_SIZE) {
|
|
103
|
+
code_size++;
|
|
104
|
+
code_mask += available;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
old_code = in_code;
|
|
108
|
+
}
|
|
109
|
+
// Pop a pixel off the pixel stack.
|
|
110
|
+
top--;
|
|
111
|
+
dstPixels[pi++] = pixelStack[top];
|
|
112
|
+
i++;
|
|
113
|
+
}
|
|
114
|
+
for (i = pi; i < npix; i++) {
|
|
115
|
+
dstPixels[i] = 0; // clear missing pixels
|
|
116
|
+
}
|
|
117
|
+
return dstPixels;
|
|
118
|
+
};
|
|
119
|
+
exports.lzw = lzw;
|