@remotion/gif 4.0.0-lambda.1 → 4.0.0-newpathfunctions.13
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/LICENSE.md +8 -8
- package/dist/Gif.d.ts +1 -1
- package/dist/Gif.js +2 -1
- package/dist/GifForDevelopment.d.ts +1 -1
- package/dist/GifForDevelopment.js +59 -20
- package/dist/GifForRendering.d.ts +1 -1
- package/dist/GifForRendering.js +66 -21
- package/dist/canvas.d.ts +13 -0
- package/dist/canvas.js +96 -0
- package/dist/get-gif-duration-in-seconds.d.ts +1 -0
- package/dist/get-gif-duration-in-seconds.js +30 -0
- package/dist/gif-cache.d.ts +4 -0
- package/dist/gif-cache.js +6 -0
- package/dist/gifuct/deinterlace.d.ts +4 -0
- package/dist/gifuct/deinterlace.js +26 -0
- package/dist/gifuct/index.d.ts +4 -0
- package/dist/gifuct/index.js +60 -0
- package/dist/gifuct/lzw.d.ts +5 -0
- package/dist/gifuct/lzw.js +119 -0
- package/dist/gifuct/types.d.ts +96 -0
- package/dist/gifuct/types.js +2 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +7 -16
- package/dist/is-cors-error.d.ts +1 -0
- package/dist/is-cors-error.js +13 -0
- package/dist/parse-generate.d.ts +18 -0
- package/dist/parse-generate.js +96 -0
- package/dist/parser/decompress-frames.d.ts +2 -0
- package/dist/parser/decompress-frames.js +19 -0
- package/dist/preload-gif.d.ts +4 -0
- package/dist/preload-gif.js +37 -0
- package/dist/props.d.ts +4 -2
- package/dist/props.js +0 -0
- package/dist/react-tools.d.ts +9 -0
- package/dist/react-tools.js +39 -0
- package/dist/resolve-gif-source.d.ts +1 -0
- package/dist/resolve-gif-source.js +7 -0
- package/dist/use-element-size.d.ts +6 -0
- package/dist/use-element-size.js +73 -0
- package/dist/useCurrentGifIndex.d.ts +2 -2
- package/dist/useCurrentGifIndex.js +21 -14
- package/dist/worker/index.d.ts +1 -0
- package/dist/worker/index.js +12 -0
- package/dist/worker/source.d.ts +1 -0
- package/dist/worker/source.js +7 -0
- package/dist/worker/worker.d.ts +1 -0
- package/dist/worker/worker.js +39 -0
- package/package.json +11 -12
- package/dist/Gif.d.ts.map +0 -1
- package/dist/Gif.js.map +0 -1
- package/dist/GifForDevelopment.d.ts.map +0 -1
- package/dist/GifForDevelopment.js.map +0 -1
- package/dist/GifForRendering.d.ts.map +0 -1
- package/dist/GifForRendering.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/props.d.ts.map +0 -1
- package/dist/props.js.map +0 -1
- package/dist/useCurrentGifIndex.d.ts.map +0 -1
- package/dist/useCurrentGifIndex.js.map +0 -1
package/LICENSE.md
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
# Remotion License
|
|
2
2
|
|
|
3
|
-
Depending on the type of your legal entity, you are granted permission to use Remotion for your project. Individuals and small companies are allowed to use Remotion create videos for free (even commercial), while a company license is required for for-profit
|
|
3
|
+
Depending on the type of your legal entity, you are granted permission to use Remotion for your project. Individuals and small companies are allowed to use Remotion to create videos for free (even commercial), while a company license is required for for-profit organizations of a certain size. This two-tier system was designed to ensure funding for this project while still allowing the source code to be available and the program to be free for most. Read below for the exact terms of use.
|
|
4
4
|
|
|
5
5
|
- [Free license](#free-license)
|
|
6
6
|
- [Company license](#company-license)
|
|
7
7
|
|
|
8
8
|
## Free license
|
|
9
9
|
|
|
10
|
-
Copyright ©
|
|
10
|
+
Copyright © 2023 [Remotion](https://www.remotion.dev/)
|
|
11
11
|
|
|
12
12
|
### Eligibility
|
|
13
13
|
|
|
14
14
|
You are eligible to use Remotion for free if you are:
|
|
15
15
|
|
|
16
16
|
- an individual
|
|
17
|
-
- a for-profit
|
|
18
|
-
- a non-profit or not-for-profit
|
|
17
|
+
- a for-profit organization with up to 3 employees
|
|
18
|
+
- a non-profit or not-for-profit organization
|
|
19
19
|
- evaluating whether Remotion is a good fit, and are not yet using it in a commercial way
|
|
20
20
|
|
|
21
21
|
### Allowed use cases
|
|
22
22
|
|
|
23
|
-
Permission is hereby granted, free of charge, to any person eligible for the "Free license", to use the software non-commercially or commercially for the purpose of creating videos and images and to modify
|
|
23
|
+
Permission is hereby granted, free of charge, to any person eligible for the "Free license", to use the software non-commercially or commercially for the purpose of creating videos and images and to modify the software to their own liking, for the purpose of fulfilling their custom use case or to contribute bug fixes or improvements back to Remotion.
|
|
24
24
|
|
|
25
25
|
### Disallowed use cases
|
|
26
26
|
|
|
27
|
-
It is not allowed to copy or modify Remotion code for the purpose of selling, renting, licensing, relicensing, sublicensing your own derivate of Remotion.
|
|
27
|
+
It is not allowed to copy or modify Remotion code for the purpose of selling, renting, licensing, relicensing, or sublicensing your own derivate of Remotion.
|
|
28
28
|
|
|
29
29
|
### Warranty notice
|
|
30
30
|
|
|
31
|
-
The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and
|
|
31
|
+
The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall the author or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.
|
|
32
32
|
|
|
33
33
|
### Support
|
|
34
34
|
|
|
@@ -36,6 +36,6 @@ Support is provided on a best-we-can-do basis via GitHub Issues and Discord.
|
|
|
36
36
|
|
|
37
37
|
## Company license
|
|
38
38
|
|
|
39
|
-
You are required to obtain a company license to use Remotion if you are not within the group of entities eligible for a free license. This license will enable you to use Remotion for the allowed use cases specified in the free license, and give you access to prioritized support.
|
|
39
|
+
You are required to obtain a company license to use Remotion if you are not within the group of entities eligible for a free license. This license will enable you to use Remotion for the allowed use cases specified in the free license, and give you access to prioritized support (read the [Support Policy](/docs/support)).
|
|
40
40
|
|
|
41
41
|
Visit [companies.remotion.dev](https://companies.remotion.dev) for pricing and to buy a license.
|
package/dist/Gif.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RemotionGifProps } from './props';
|
|
1
|
+
import type { RemotionGifProps } from './props';
|
|
2
2
|
export declare const Gif: (props: RemotionGifProps) => JSX.Element;
|
package/dist/Gif.js
CHANGED
|
@@ -6,7 +6,8 @@ const remotion_1 = require("remotion");
|
|
|
6
6
|
const GifForDevelopment_1 = require("./GifForDevelopment");
|
|
7
7
|
const GifForRendering_1 = require("./GifForRendering");
|
|
8
8
|
const Gif = (props) => {
|
|
9
|
-
|
|
9
|
+
const env = remotion_1.Internals.useRemotionEnvironment();
|
|
10
|
+
if (env === 'rendering') {
|
|
10
11
|
return (0, jsx_runtime_1.jsx)(GifForRendering_1.GifForRendering, { ...props });
|
|
11
12
|
}
|
|
12
13
|
return (0, jsx_runtime_1.jsx)(GifForDevelopment_1.GifForDevelopment, { ...props });
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { RemotionGifProps } from './props';
|
|
2
|
+
import type { RemotionGifProps } from './props';
|
|
3
3
|
export declare const GifForDevelopment: import("react").ForwardRefExoticComponent<RemotionGifProps & import("react").RefAttributes<HTMLCanvasElement>>;
|
|
@@ -2,15 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GifForDevelopment = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const tools_1 = require("@react-gifs/tools");
|
|
6
|
-
const lru_map_1 = require("lru_map");
|
|
7
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");
|
|
8
12
|
const useCurrentGifIndex_1 = require("./useCurrentGifIndex");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const resolvedSrc = new URL(src, window.location.origin).href;
|
|
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);
|
|
12
15
|
const [state, update] = (0, react_1.useState)(() => {
|
|
13
|
-
|
|
16
|
+
var _a;
|
|
17
|
+
const parsedGif = (_a = gif_cache_1.volatileGifCache.get(resolvedSrc)) !== null && _a !== void 0 ? _a : gif_cache_1.manuallyManagedGifCache.get(resolvedSrc);
|
|
14
18
|
if (parsedGif === undefined) {
|
|
15
19
|
return {
|
|
16
20
|
delays: [],
|
|
@@ -21,22 +25,57 @@ exports.GifForDevelopment = (0, react_1.forwardRef)(({ src, width, height, onErr
|
|
|
21
25
|
}
|
|
22
26
|
return parsedGif;
|
|
23
27
|
});
|
|
24
|
-
|
|
25
|
-
(0,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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);
|
|
29
56
|
}
|
|
30
57
|
else {
|
|
31
|
-
|
|
58
|
+
setError(err);
|
|
32
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.`);
|
|
33
73
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
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 }));
|
|
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 }));
|
|
42
81
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { RemotionGifProps } from './props';
|
|
2
|
+
import type { RemotionGifProps } from './props';
|
|
3
3
|
export declare const GifForRendering: import("react").ForwardRefExoticComponent<RemotionGifProps & import("react").RefAttributes<HTMLCanvasElement>>;
|
package/dist/GifForRendering.js
CHANGED
|
@@ -2,34 +2,79 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GifForRendering = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const tools_1 = require("@react-gifs/tools");
|
|
6
5
|
const react_1 = require("react");
|
|
7
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");
|
|
8
12
|
const useCurrentGifIndex_1 = require("./useCurrentGifIndex");
|
|
9
|
-
exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad, onError, fit = 'fill', ...props }, ref) => {
|
|
10
|
-
const resolvedSrc =
|
|
11
|
-
const [state, update] = (0, react_1.useState)({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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;
|
|
16
26
|
});
|
|
27
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
17
28
|
const [id] = (0, react_1.useState)(() => (0, remotion_1.delayRender)(`Rendering <Gif/> with src="${resolvedSrc}"`));
|
|
18
|
-
const index = (0, useCurrentGifIndex_1.useCurrentGifIndex)(state.delays);
|
|
19
|
-
(0,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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);
|
|
23
56
|
}
|
|
24
57
|
else {
|
|
25
|
-
|
|
58
|
+
setError(err);
|
|
26
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.`);
|
|
27
73
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
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 }));
|
|
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 }));
|
|
35
80
|
});
|
package/dist/canvas.d.ts
ADDED
|
@@ -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 {};
|
package/dist/canvas.js
ADDED
|
@@ -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 @@
|
|
|
1
|
+
export declare const getGifDurationInSeconds: (src: string) => Promise<number>;
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
const getGifDurationInSeconds = async (src) => {
|
|
11
|
+
var _a;
|
|
12
|
+
const resolvedSrc = new URL(src, window.location.origin).href;
|
|
13
|
+
const inCache = (_a = gif_cache_1.volatileGifCache.get(resolvedSrc)) !== null && _a !== void 0 ? _a : gif_cache_1.manuallyManagedGifCache.get(resolvedSrc);
|
|
14
|
+
if (inCache) {
|
|
15
|
+
return calcDuration(inCache);
|
|
16
|
+
}
|
|
17
|
+
if (remotion_1.Internals.getRemotionEnvironment() === 'rendering') {
|
|
18
|
+
const renderingParsed = (0, react_tools_1.parseWithWorker)(resolvedSrc);
|
|
19
|
+
const resolved = await renderingParsed.prom;
|
|
20
|
+
gif_cache_1.volatileGifCache.set(resolvedSrc, resolved);
|
|
21
|
+
return calcDuration(resolved);
|
|
22
|
+
}
|
|
23
|
+
const parsed = await (0, react_tools_1.parseGif)({
|
|
24
|
+
src: resolvedSrc,
|
|
25
|
+
controller: new AbortController(),
|
|
26
|
+
});
|
|
27
|
+
gif_cache_1.volatileGifCache.set(resolvedSrc, parsed);
|
|
28
|
+
return calcDuration(parsed);
|
|
29
|
+
};
|
|
30
|
+
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 lru_map_1 = require("lru_map");
|
|
5
|
+
exports.volatileGifCache = new lru_map_1.LRUMap(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) => any;
|
|
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,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.decompressFrames = exports.decompressFrame = exports.parseGIF = void 0;
|
|
7
|
+
// @ts-expect-error
|
|
8
|
+
const js_binary_schema_parser_1 = require("js-binary-schema-parser");
|
|
9
|
+
// @ts-expect-error
|
|
10
|
+
const uint8_1 = require("js-binary-schema-parser/lib/parsers/uint8");
|
|
11
|
+
// @ts-expect-error
|
|
12
|
+
const gif_1 = __importDefault(require("js-binary-schema-parser/lib/schemas/gif"));
|
|
13
|
+
const deinterlace_1 = require("./deinterlace");
|
|
14
|
+
const lzw_1 = require("./lzw");
|
|
15
|
+
const parseGIF = (arrayBuffer) => {
|
|
16
|
+
const byteData = new Uint8Array(arrayBuffer);
|
|
17
|
+
return (0, js_binary_schema_parser_1.parse)((0, uint8_1.buildStream)(byteData), gif_1.default);
|
|
18
|
+
};
|
|
19
|
+
exports.parseGIF = parseGIF;
|
|
20
|
+
const decompressFrame = (frame, gct) => {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
if (!frame.image) {
|
|
23
|
+
console.warn('gif frame does not have associated image.');
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const { image } = frame;
|
|
27
|
+
// get the number of pixels
|
|
28
|
+
const totalPixels = image.descriptor.width * image.descriptor.height;
|
|
29
|
+
// do lzw decompression
|
|
30
|
+
let pixels = (0, lzw_1.lzw)(image.data.minCodeSize, image.data.blocks, totalPixels);
|
|
31
|
+
// deal with interlacing if necessary
|
|
32
|
+
if ((_a = image.descriptor.lct) === null || _a === void 0 ? void 0 : _a.interlaced) {
|
|
33
|
+
pixels = (0, deinterlace_1.deinterlace)(pixels, image.descriptor.width);
|
|
34
|
+
}
|
|
35
|
+
const resultImage = {
|
|
36
|
+
pixels,
|
|
37
|
+
dims: {
|
|
38
|
+
top: frame.image.descriptor.top,
|
|
39
|
+
left: frame.image.descriptor.left,
|
|
40
|
+
width: frame.image.descriptor.width,
|
|
41
|
+
height: frame.image.descriptor.height,
|
|
42
|
+
},
|
|
43
|
+
colorTable: ((_b = image.descriptor.lct) === null || _b === void 0 ? void 0 : _b.exists)
|
|
44
|
+
? image.lct
|
|
45
|
+
: gct,
|
|
46
|
+
delay: (frame.gce.delay || 10) * 10,
|
|
47
|
+
disposalType: frame.gce.extras.disposal,
|
|
48
|
+
transparentIndex: frame.gce.extras.transparentColorGiven
|
|
49
|
+
? frame.gce.transparentColorIndex
|
|
50
|
+
: -1,
|
|
51
|
+
};
|
|
52
|
+
return resultImage;
|
|
53
|
+
};
|
|
54
|
+
exports.decompressFrame = decompressFrame;
|
|
55
|
+
const decompressFrames = (parsedGif) => {
|
|
56
|
+
return parsedGif.frames
|
|
57
|
+
.filter((f) => !('application' in f))
|
|
58
|
+
.map((f) => (0, exports.decompressFrame)(f, parsedGif.gct));
|
|
59
|
+
};
|
|
60
|
+
exports.decompressFrames = decompressFrames;
|