@remotion/gif 4.0.207 → 4.0.209

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.
Files changed (57) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/esm/index.mjs +5 -7
  3. package/package.json +2 -2
  4. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/Gif.d.ts +0 -7
  5. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/Gif.js +0 -16
  6. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/GifForDevelopment.d.ts +0 -3
  7. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/GifForDevelopment.js +0 -82
  8. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/GifForRendering.d.ts +0 -3
  9. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/GifForRendering.js +0 -86
  10. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/canvas.d.ts +0 -13
  11. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/canvas.js +0 -93
  12. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/get-gif-duration-in-seconds.d.ts +0 -5
  13. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/get-gif-duration-in-seconds.js +0 -30
  14. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/gif-cache.d.ts +0 -4
  15. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/gif-cache.js +0 -3
  16. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/gifuct/deinterlace.d.ts +0 -4
  17. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/gifuct/deinterlace.js +0 -22
  18. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/gifuct/index.d.ts +0 -4
  19. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/gifuct/index.js +0 -50
  20. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/gifuct/lzw.d.ts +0 -5
  21. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/gifuct/lzw.js +0 -115
  22. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/gifuct/types.d.ts +0 -96
  23. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/gifuct/types.js +0 -1
  24. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/index.d.ts +0 -4
  25. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/index.js +0 -3
  26. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/is-cors-error.d.ts +0 -1
  27. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/is-cors-error.js +0 -9
  28. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/js-binary-schema-parser/gif.d.ts +0 -51
  29. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/js-binary-schema-parser/gif.js +0 -155
  30. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/js-binary-schema-parser/parser.d.ts +0 -9
  31. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/js-binary-schema-parser/parser.js +0 -48
  32. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/js-binary-schema-parser/uint8-parser.d.ts +0 -17
  33. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/js-binary-schema-parser/uint8-parser.js +0 -67
  34. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/lru/index.d.ts +0 -101
  35. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/lru/index.js +0 -254
  36. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/parse-generate.d.ts +0 -18
  37. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/parse-generate.js +0 -110
  38. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/parser/decompress-frames.d.ts +0 -2
  39. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/parser/decompress-frames.js +0 -12
  40. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/preload-gif.d.ts +0 -8
  41. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/preload-gif.js +0 -37
  42. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/props.d.ts +0 -26
  43. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/props.js +0 -1
  44. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/react-tools.d.ts +0 -9
  45. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/react-tools.js +0 -35
  46. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/resolve-gif-source.d.ts +0 -1
  47. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/resolve-gif-source.js +0 -4
  48. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/use-element-size.d.ts +0 -6
  49. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/use-element-size.js +0 -68
  50. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/useCurrentGifIndex.d.ts +0 -6
  51. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/useCurrentGifIndex.js +0 -32
  52. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/worker/index.d.ts +0 -1
  53. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/worker/index.js +0 -8
  54. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/worker/source.d.ts +0 -1
  55. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/worker/source.js +0 -4
  56. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/worker/worker.d.ts +0 -1
  57. package/.rollup.cache/Users/jonathanburger/remotion/packages/gif/dist/esm/worker/worker.js +0 -37
@@ -1,4 +1,4 @@
1
1
 
2
- > @remotion/gif@4.0.206 build /Users/jonathanburger/remotion/packages/gif
2
+ > @remotion/gif@4.0.208 build /Users/jonathanburger/remotion/packages/gif
3
3
  > node build.mjs && bun --env-file=../.env.bundle bundle.ts
4
4
 
@@ -168,7 +168,7 @@ var Canvas = forwardRef(({ index, frames, width, height, fit, className, style }
168
168
  ctx.drawImage(tempCtx.canvas, ...calcArgs(fit, imageData, { width: size.width, height: size.height }));
169
169
  }
170
170
  }, [index, frames, fit, tempCtx, size]);
171
- return jsx("canvas", {
171
+ return /* @__PURE__ */ jsx("canvas", {
172
172
  ref: canvasRef,
173
173
  className,
174
174
  style,
@@ -1091,7 +1091,7 @@ var GifForDevelopment = forwardRef2(({
1091
1091
  if (index === -1) {
1092
1092
  return null;
1093
1093
  }
1094
- return jsx2(Canvas, {
1094
+ return /* @__PURE__ */ jsx2(Canvas, {
1095
1095
  fit,
1096
1096
  index,
1097
1097
  frames: state.frames,
@@ -1189,7 +1189,7 @@ var GifForRendering = forwardRef3(({
1189
1189
  if (index === -1) {
1190
1190
  return null;
1191
1191
  }
1192
- return jsx3(Canvas, {
1192
+ return /* @__PURE__ */ jsx3(Canvas, {
1193
1193
  fit,
1194
1194
  index,
1195
1195
  frames: state.frames,
@@ -1207,17 +1207,16 @@ jsx as jsx4
1207
1207
  var Gif = forwardRef4((props, ref) => {
1208
1208
  const env = getRemotionEnvironment();
1209
1209
  if (env.isRendering) {
1210
- return jsx4(GifForRendering, {
1210
+ return /* @__PURE__ */ jsx4(GifForRendering, {
1211
1211
  ...props,
1212
1212
  ref
1213
1213
  });
1214
1214
  }
1215
- return jsx4(GifForDevelopment, {
1215
+ return /* @__PURE__ */ jsx4(GifForDevelopment, {
1216
1216
  ...props,
1217
1217
  ref
1218
1218
  });
1219
1219
  });
1220
-
1221
1220
  // src/get-gif-duration-in-seconds.ts
1222
1221
  import {getRemotionEnvironment as getRemotionEnvironment2} from "remotion";
1223
1222
  var calcDuration = (parsed) => {
@@ -1242,7 +1241,6 @@ var getGifDurationInSeconds = async (src2) => {
1242
1241
  volatileGifCache.set(resolvedSrc, parsed);
1243
1242
  return calcDuration(parsed);
1244
1243
  };
1245
-
1246
1244
  // src/preload-gif.ts
1247
1245
  var preloadGif = (src2) => {
1248
1246
  const resolvedSrc = resolveGifSource(src2);
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.207",
6
+ "version": "4.0.209",
7
7
  "description": "Embed GIFs in a Remotion video",
8
8
  "sideEffects": false,
9
9
  "bugs": {
@@ -24,7 +24,7 @@
24
24
  }
25
25
  },
26
26
  "dependencies": {
27
- "remotion": "4.0.207"
27
+ "remotion": "4.0.209"
28
28
  },
29
29
  "devDependencies": {
30
30
  "esbuild": "0.18.6",
@@ -1,7 +0,0 @@
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: import("react").ForwardRefExoticComponent<RemotionGifProps & import("react").RefAttributes<HTMLCanvasElement>>;
@@ -1,16 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { forwardRef } from 'react';
3
- import { getRemotionEnvironment } from 'remotion';
4
- import { GifForDevelopment } from './GifForDevelopment';
5
- import { GifForRendering } from './GifForRendering';
6
- /**
7
- * @description Displays a GIF that synchronizes with Remotions useCurrentFrame().
8
- * @see [Documentation](https://www.remotion.dev/docs/gif/gif)
9
- */
10
- export const Gif = forwardRef((props, ref) => {
11
- const env = getRemotionEnvironment();
12
- if (env.isRendering) {
13
- return _jsx(GifForRendering, { ...props, ref: ref });
14
- }
15
- return _jsx(GifForDevelopment, { ...props, ref: ref });
16
- });
@@ -1,3 +0,0 @@
1
- /// <reference types="react" />
2
- import type { RemotionGifProps } from './props';
3
- export declare const GifForDevelopment: import("react").ForwardRefExoticComponent<RemotionGifProps & import("react").RefAttributes<HTMLCanvasElement>>;
@@ -1,82 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { forwardRef, useEffect, useRef, useState } from 'react';
3
- import { continueRender, delayRender } from 'remotion';
4
- import { Canvas } from './canvas';
5
- import { manuallyManagedGifCache, volatileGifCache } from './gif-cache';
6
- import { isCorsError } from './is-cors-error';
7
- import { parseWithWorker } from './react-tools';
8
- import { resolveGifSource } from './resolve-gif-source';
9
- import { useCurrentGifIndex } from './useCurrentGifIndex';
10
- export const GifForDevelopment = forwardRef(({ src, width, height, onError, loopBehavior = 'loop', playbackRate = 1, onLoad, fit = 'fill', ...props }, ref) => {
11
- const resolvedSrc = resolveGifSource(src);
12
- const [state, update] = useState(() => {
13
- var _a;
14
- const parsedGif = (_a = volatileGifCache.get(resolvedSrc)) !== null && _a !== void 0 ? _a : manuallyManagedGifCache.get(resolvedSrc);
15
- if (parsedGif === undefined) {
16
- return {
17
- delays: [],
18
- frames: [],
19
- width: 0,
20
- height: 0,
21
- };
22
- }
23
- return parsedGif;
24
- });
25
- const [error, setError] = useState(null);
26
- const [id] = useState(() => delayRender(`Rendering <Gif/> with src="${resolvedSrc}"`));
27
- const currentOnLoad = useRef(onLoad);
28
- const currentOnError = useRef(onError);
29
- currentOnLoad.current = onLoad;
30
- currentOnError.current = onError;
31
- useEffect(() => {
32
- let done = false;
33
- let aborted = false;
34
- const { prom, cancel } = parseWithWorker(resolvedSrc);
35
- const newHandle = delayRender('Loading <Gif /> with src=' + resolvedSrc);
36
- prom
37
- .then((parsed) => {
38
- var _a;
39
- (_a = currentOnLoad.current) === null || _a === void 0 ? void 0 : _a.call(currentOnLoad, parsed);
40
- update(parsed);
41
- volatileGifCache.set(resolvedSrc, parsed);
42
- done = true;
43
- continueRender(newHandle);
44
- continueRender(id);
45
- })
46
- .catch((err) => {
47
- if (aborted) {
48
- continueRender(newHandle);
49
- return;
50
- }
51
- if (currentOnError.current) {
52
- currentOnError.current(err);
53
- }
54
- else {
55
- setError(err);
56
- }
57
- });
58
- return () => {
59
- if (!done) {
60
- aborted = true;
61
- cancel();
62
- }
63
- continueRender(newHandle);
64
- };
65
- }, [id, resolvedSrc]);
66
- if (error) {
67
- console.error(error.stack);
68
- if (isCorsError(error)) {
69
- 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.`);
70
- }
71
- throw new Error(`Failed to render GIF with source ${src}: "${error.message}".`);
72
- }
73
- const index = useCurrentGifIndex({
74
- delays: state.delays,
75
- loopBehavior,
76
- playbackRate,
77
- });
78
- if (index === -1) {
79
- return null;
80
- }
81
- return (_jsx(Canvas, { fit: fit, index: index, frames: state.frames, width: width, height: height, ...props, ref: ref }));
82
- });
@@ -1,3 +0,0 @@
1
- /// <reference types="react" />
2
- import type { RemotionGifProps } from './props';
3
- export declare const GifForRendering: import("react").ForwardRefExoticComponent<RemotionGifProps & import("react").RefAttributes<HTMLCanvasElement>>;
@@ -1,86 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { forwardRef, useEffect, useRef, useState } from 'react';
3
- import { continueRender, delayRender } from 'remotion';
4
- import { Canvas } from './canvas';
5
- import { volatileGifCache } from './gif-cache';
6
- import { isCorsError } from './is-cors-error';
7
- import { parseGif } from './react-tools';
8
- import { resolveGifSource } from './resolve-gif-source';
9
- import { useCurrentGifIndex } from './useCurrentGifIndex';
10
- export const GifForRendering = forwardRef(({ src, width, height, onLoad, onError, loopBehavior = 'loop', playbackRate = 1, fit = 'fill', ...props }, ref) => {
11
- const resolvedSrc = resolveGifSource(src);
12
- const [state, update] = useState(() => {
13
- const parsedGif = volatileGifCache.get(resolvedSrc);
14
- if (parsedGif === undefined) {
15
- return {
16
- delays: [],
17
- frames: [],
18
- width: 0,
19
- height: 0,
20
- };
21
- }
22
- return parsedGif;
23
- });
24
- const [error, setError] = useState(null);
25
- const [id] = useState(() => delayRender(`Rendering <Gif/> with src="${resolvedSrc}"`));
26
- useEffect(() => {
27
- return () => {
28
- continueRender(id);
29
- };
30
- }, [id]);
31
- const index = useCurrentGifIndex({
32
- delays: state.delays,
33
- loopBehavior,
34
- playbackRate,
35
- });
36
- const currentOnLoad = useRef(onLoad);
37
- const currentOnError = useRef(onError);
38
- currentOnLoad.current = onLoad;
39
- currentOnError.current = onError;
40
- useEffect(() => {
41
- const controller = new AbortController();
42
- let done = false;
43
- let aborted = false;
44
- const newHandle = delayRender('Loading <Gif /> with src=' + resolvedSrc);
45
- parseGif({ controller, src: resolvedSrc })
46
- .then((parsed) => {
47
- var _a;
48
- (_a = currentOnLoad.current) === null || _a === void 0 ? void 0 : _a.call(currentOnLoad, parsed);
49
- update(parsed);
50
- volatileGifCache.set(resolvedSrc, parsed);
51
- done = true;
52
- continueRender(newHandle);
53
- continueRender(id);
54
- })
55
- .catch((err) => {
56
- if (aborted) {
57
- continueRender(newHandle);
58
- return;
59
- }
60
- if (currentOnError.current) {
61
- currentOnError.current(err);
62
- }
63
- else {
64
- setError(err);
65
- }
66
- });
67
- return () => {
68
- if (!done) {
69
- aborted = true;
70
- controller.abort();
71
- }
72
- continueRender(newHandle);
73
- };
74
- }, [id, resolvedSrc]);
75
- if (error) {
76
- console.error(error.stack);
77
- if (isCorsError(error)) {
78
- throw new Error(`Failed to render GIF with source ${src}: "${error.message}". You must enable CORS for this URL.`);
79
- }
80
- throw new Error(`Failed to render GIF with source ${src}: "${error.message}". Render with --log=verbose to see the full stack.`);
81
- }
82
- if (index === -1) {
83
- return null;
84
- }
85
- return (_jsx(Canvas, { fit: fit, index: index, frames: state.frames, width: width, height: height, ...props, ref: ref }));
86
- });
@@ -1,13 +0,0 @@
1
- /// <reference types="react" />
2
- import type { GifFillMode } from './props';
3
- 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 {};
@@ -1,93 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { forwardRef, useEffect, useImperativeHandle, useRef, useState, } from 'react';
3
- import { useElementSize } from './use-element-size';
4
- const calcArgs = (fit, frameSize, canvasSize) => {
5
- switch (fit) {
6
- case 'fill': {
7
- return [
8
- 0,
9
- 0,
10
- frameSize.width,
11
- frameSize.height,
12
- 0,
13
- 0,
14
- canvasSize.width,
15
- canvasSize.height,
16
- ];
17
- }
18
- case 'contain': {
19
- const ratio = Math.min(canvasSize.width / frameSize.width, canvasSize.height / frameSize.height);
20
- const centerX = (canvasSize.width - frameSize.width * ratio) / 2;
21
- const centerY = (canvasSize.height - frameSize.height * ratio) / 2;
22
- return [
23
- 0,
24
- 0,
25
- frameSize.width,
26
- frameSize.height,
27
- centerX,
28
- centerY,
29
- frameSize.width * ratio,
30
- frameSize.height * ratio,
31
- ];
32
- }
33
- case 'cover': {
34
- const ratio = Math.max(canvasSize.width / frameSize.width, canvasSize.height / frameSize.height);
35
- const centerX = (canvasSize.width - frameSize.width * ratio) / 2;
36
- const centerY = (canvasSize.height - frameSize.height * ratio) / 2;
37
- return [
38
- 0,
39
- 0,
40
- frameSize.width,
41
- frameSize.height,
42
- centerX,
43
- centerY,
44
- frameSize.width * ratio,
45
- frameSize.height * ratio,
46
- ];
47
- }
48
- default:
49
- throw new Error('Unknown fit: ' + fit);
50
- }
51
- };
52
- const makeCanvas = () => {
53
- if (typeof document === 'undefined') {
54
- return null;
55
- }
56
- const canvas = document.createElement('canvas');
57
- const ctx = canvas.getContext('2d');
58
- canvas.width = 0;
59
- canvas.height = 0;
60
- return ctx;
61
- };
62
- export const Canvas = forwardRef(({ index, frames, width, height, fit, className, style }, ref) => {
63
- const canvasRef = useRef(null);
64
- const [tempCtx] = useState(() => {
65
- return makeCanvas();
66
- });
67
- const size = useElementSize(canvasRef);
68
- useImperativeHandle(ref, () => {
69
- return canvasRef.current;
70
- }, []);
71
- useEffect(() => {
72
- var _a;
73
- if (!size) {
74
- return;
75
- }
76
- const imageData = frames[index];
77
- const ctx = (_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.getContext('2d');
78
- if (imageData && tempCtx && ctx) {
79
- if (tempCtx.canvas.width < imageData.width ||
80
- tempCtx.canvas.height < imageData.height) {
81
- tempCtx.canvas.width = imageData.width;
82
- tempCtx.canvas.height = imageData.height;
83
- }
84
- if (size.width > 0 && size.height > 0) {
85
- ctx.clearRect(0, 0, size.width, size.height);
86
- tempCtx.clearRect(0, 0, tempCtx.canvas.width, tempCtx.canvas.height);
87
- }
88
- tempCtx.putImageData(imageData, 0, 0);
89
- ctx.drawImage(tempCtx.canvas, ...calcArgs(fit, imageData, { width: size.width, height: size.height }));
90
- }
91
- }, [index, frames, fit, tempCtx, size]);
92
- return (_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 }));
93
- });
@@ -1,5 +0,0 @@
1
- /**
2
- * @description Gets the duration in seconds of a GIF
3
- * @see [Documentation](https://www.remotion.dev/docs/gif/get-gif-duration-in-seconds)
4
- */
5
- export declare const getGifDurationInSeconds: (src: string) => Promise<number>;
@@ -1,30 +0,0 @@
1
- import { getRemotionEnvironment } from 'remotion';
2
- import { manuallyManagedGifCache, volatileGifCache } from './gif-cache';
3
- import { parseGif, parseWithWorker } from './react-tools';
4
- const calcDuration = (parsed) => {
5
- return (parsed.delays.reduce((sum, delay) => sum + delay, 0) / 1000);
6
- };
7
- /**
8
- * @description Gets the duration in seconds of a GIF
9
- * @see [Documentation](https://www.remotion.dev/docs/gif/get-gif-duration-in-seconds)
10
- */
11
- export const getGifDurationInSeconds = async (src) => {
12
- var _a;
13
- const resolvedSrc = new URL(src, window.origin).href;
14
- const inCache = (_a = volatileGifCache.get(resolvedSrc)) !== null && _a !== void 0 ? _a : manuallyManagedGifCache.get(resolvedSrc);
15
- if (inCache) {
16
- return calcDuration(inCache);
17
- }
18
- if (getRemotionEnvironment().isRendering) {
19
- const renderingParsed = parseWithWorker(resolvedSrc);
20
- const resolved = await renderingParsed.prom;
21
- volatileGifCache.set(resolvedSrc, resolved);
22
- return calcDuration(resolved);
23
- }
24
- const parsed = await parseGif({
25
- src: resolvedSrc,
26
- controller: new AbortController(),
27
- });
28
- volatileGifCache.set(resolvedSrc, parsed);
29
- return calcDuration(parsed);
30
- };
@@ -1,4 +0,0 @@
1
- import { QuickLRU } from './lru/index';
2
- import type { GifState } from './props';
3
- export declare const volatileGifCache: QuickLRU<string, GifState>;
4
- export declare const manuallyManagedGifCache: Map<string, GifState>;
@@ -1,3 +0,0 @@
1
- import { QuickLRU } from './lru/index';
2
- export const volatileGifCache = new QuickLRU({ maxSize: 30 });
3
- export const manuallyManagedGifCache = new Map();
@@ -1,4 +0,0 @@
1
- /**
2
- * Deinterlace function from https://github.com/shachaf/jsgif
3
- */
4
- export declare const deinterlace: (pixels: number[], width: number) => any[];
@@ -1,22 +0,0 @@
1
- /**
2
- * Deinterlace function from https://github.com/shachaf/jsgif
3
- */
4
- export const deinterlace = (pixels, width) => {
5
- const newPixels = new Array(pixels.length);
6
- const rows = pixels.length / width;
7
- const cpRow = function (toRow, _fromRow) {
8
- const fromPixels = pixels.slice(_fromRow * width, (_fromRow + 1) * width);
9
- newPixels.splice(...[toRow * width, width].concat(fromPixels));
10
- };
11
- // See appendix E.
12
- const offsets = [0, 4, 2, 1];
13
- const steps = [8, 8, 4, 2];
14
- let fromRow = 0;
15
- for (let pass = 0; pass < 4; pass++) {
16
- for (let toRow = offsets[pass]; toRow < rows; toRow += steps[pass]) {
17
- cpRow(toRow, fromRow);
18
- fromRow++;
19
- }
20
- }
21
- return newPixels;
22
- };
@@ -1,4 +0,0 @@
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 | null;
4
- export declare const decompressFrames: (parsedGif: ParsedGif) => (ParsedFrameWithoutPatch | null)[];
@@ -1,50 +0,0 @@
1
- import { GIF } from '../js-binary-schema-parser/gif';
2
- import { parse } from '../js-binary-schema-parser/parser';
3
- import { buildStream } from '../js-binary-schema-parser/uint8-parser';
4
- import { deinterlace } from './deinterlace';
5
- import { lzw } from './lzw';
6
- export const parseGIF = (arrayBuffer) => {
7
- const byteData = new Uint8Array(arrayBuffer);
8
- return parse(buildStream(byteData), GIF);
9
- };
10
- export const decompressFrame = (frame, gct) => {
11
- var _a, _b, _c, _d;
12
- if (!frame.image) {
13
- console.warn('gif frame does not have associated image.');
14
- return null;
15
- }
16
- const { image } = frame;
17
- // get the number of pixels
18
- const totalPixels = image.descriptor.width * image.descriptor.height;
19
- // do lzw decompression
20
- let pixels = lzw(image.data.minCodeSize, image.data.blocks, totalPixels);
21
- // deal with interlacing if necessary
22
- if ((_a = image.descriptor.lct) === null || _a === void 0 ? void 0 : _a.interlaced) {
23
- pixels = deinterlace(pixels, image.descriptor.width);
24
- }
25
- const resultImage = {
26
- pixels,
27
- dims: {
28
- top: frame.image.descriptor.top,
29
- left: frame.image.descriptor.left,
30
- width: frame.image.descriptor.width,
31
- height: frame.image.descriptor.height,
32
- },
33
- colorTable: ((_b = image.descriptor.lct) === null || _b === void 0 ? void 0 : _b.exists)
34
- ? image.lct
35
- : gct,
36
- delay: ((_d = (_c = frame.gce) === null || _c === void 0 ? void 0 : _c.delay) !== null && _d !== void 0 ? _d : 10) * 10,
37
- disposalType: frame.gce ? frame.gce.extras.disposal : 1,
38
- transparentIndex: frame.gce
39
- ? frame.gce.extras.transparentColorGiven
40
- ? frame.gce.transparentColorIndex
41
- : -1
42
- : -1,
43
- };
44
- return resultImage;
45
- };
46
- export const decompressFrames = (parsedGif) => {
47
- return parsedGif.frames
48
- .filter((f) => !('application' in f))
49
- .map((f) => decompressFrame(f, parsedGif.gct));
50
- };
@@ -1,5 +0,0 @@
1
- /**
2
- * javascript port of java LZW decompression
3
- * Original java author url: https://gist.github.com/devunwired/4479231
4
- */
5
- export declare const lzw: (minCodeSize: number, data: number[], pixelCount: number) => any[];
@@ -1,115 +0,0 @@
1
- /* eslint-disable no-multi-assign */
2
- /* eslint-disable no-redeclare */
3
- /* eslint-disable no-bitwise */
4
- /* eslint-disable no-var */
5
- /**
6
- * javascript port of java LZW decompression
7
- * Original java author url: https://gist.github.com/devunwired/4479231
8
- */
9
- export const lzw = (minCodeSize, data, pixelCount) => {
10
- const MAX_STACK_SIZE = 4096;
11
- const nullCode = -1;
12
- const npix = pixelCount;
13
- let available;
14
- let code_mask;
15
- let code_size;
16
- let in_code;
17
- let old_code;
18
- var bits;
19
- let code;
20
- let i;
21
- var datum;
22
- var first;
23
- var top;
24
- var bi;
25
- var pi;
26
- const dstPixels = new Array(pixelCount);
27
- const prefix = new Array(MAX_STACK_SIZE);
28
- const suffix = new Array(MAX_STACK_SIZE);
29
- const pixelStack = new Array(MAX_STACK_SIZE + 1);
30
- // Initialize GIF data stream decoder.
31
- const data_size = minCodeSize;
32
- const clear = 1 << data_size;
33
- const end_of_information = clear + 1;
34
- available = clear + 2;
35
- old_code = nullCode;
36
- code_size = data_size + 1;
37
- code_mask = (1 << code_size) - 1;
38
- for (code = 0; code < clear; code++) {
39
- prefix[code] = 0;
40
- suffix[code] = code;
41
- }
42
- // Decode GIF pixel stream.
43
- var datum;
44
- var bits;
45
- var first;
46
- var top;
47
- var pi;
48
- var bi;
49
- datum = bits = first = top = pi = bi = 0;
50
- for (i = 0; i < npix;) {
51
- if (top === 0) {
52
- if (bits < code_size) {
53
- // get the next byte
54
- datum += data[bi] << bits;
55
- bits += 8;
56
- bi++;
57
- continue;
58
- }
59
- // Get the next code.
60
- code = datum & code_mask;
61
- datum >>= code_size;
62
- bits -= code_size;
63
- // Interpret the code
64
- if (code > available || code === end_of_information) {
65
- break;
66
- }
67
- if (code === clear) {
68
- // Reset decoder.
69
- code_size = data_size + 1;
70
- code_mask = (1 << code_size) - 1;
71
- available = clear + 2;
72
- old_code = nullCode;
73
- continue;
74
- }
75
- if (old_code === nullCode) {
76
- pixelStack[top++] = suffix[code];
77
- old_code = code;
78
- first = code;
79
- continue;
80
- }
81
- in_code = code;
82
- if (code === available) {
83
- pixelStack[top++] = first;
84
- code = old_code;
85
- }
86
- while (code > clear) {
87
- pixelStack[top++] = suffix[code];
88
- code = prefix[code];
89
- }
90
- first = suffix[code] & 0xff;
91
- pixelStack[top++] = first;
92
- // add a new string to the table, but only if space is available
93
- // if not, just continue with current table until a clear code is found
94
- // (deferred clear code implementation as per GIF spec)
95
- if (available < MAX_STACK_SIZE) {
96
- prefix[available] = old_code;
97
- suffix[available] = first;
98
- available++;
99
- if ((available & code_mask) === 0 && available < MAX_STACK_SIZE) {
100
- code_size++;
101
- code_mask += available;
102
- }
103
- }
104
- old_code = in_code;
105
- }
106
- // Pop a pixel off the pixel stack.
107
- top--;
108
- dstPixels[pi++] = pixelStack[top];
109
- i++;
110
- }
111
- for (i = pi; i < npix; i++) {
112
- dstPixels[i] = 0; // clear missing pixels
113
- }
114
- return dstPixels;
115
- };