@remotion/gif 4.0.0-webhook.26 → 4.1.0-alpha1

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 (94) hide show
  1. package/LICENSE.md +8 -8
  2. package/dist/cjs/Gif.d.ts +7 -0
  3. package/dist/{Gif.js → cjs/Gif.js} +11 -6
  4. package/dist/{GifForDevelopment.d.ts → cjs/GifForDevelopment.d.ts} +0 -0
  5. package/dist/{GifForDevelopment.js → cjs/GifForDevelopment.js} +10 -5
  6. package/dist/{GifForRendering.d.ts → cjs/GifForRendering.d.ts} +0 -0
  7. package/dist/{GifForRendering.js → cjs/GifForRendering.js} +14 -5
  8. package/dist/{canvas.d.ts → cjs/canvas.d.ts} +1 -1
  9. package/dist/{canvas.js → cjs/canvas.js} +3 -0
  10. package/dist/cjs/get-gif-duration-in-seconds.d.ts +5 -0
  11. package/dist/{get-gif-duration-in-seconds.js → cjs/get-gif-duration-in-seconds.js} +8 -3
  12. package/dist/cjs/gif-cache.d.ts +4 -0
  13. package/dist/cjs/gif-cache.js +6 -0
  14. package/dist/cjs/gifuct/deinterlace.d.ts +4 -0
  15. package/dist/cjs/gifuct/deinterlace.js +26 -0
  16. package/dist/cjs/gifuct/index.d.ts +4 -0
  17. package/dist/cjs/gifuct/index.js +54 -0
  18. package/dist/cjs/gifuct/lzw.d.ts +5 -0
  19. package/dist/cjs/gifuct/lzw.js +119 -0
  20. package/dist/cjs/gifuct/types.d.ts +96 -0
  21. package/dist/{props.js → cjs/gifuct/types.js} +0 -0
  22. package/dist/{index.d.ts → cjs/index.d.ts} +1 -0
  23. package/dist/{index.js → cjs/index.js} +3 -1
  24. package/dist/{is-cors-error.d.ts → cjs/is-cors-error.d.ts} +0 -0
  25. package/dist/{is-cors-error.js → cjs/is-cors-error.js} +0 -0
  26. package/dist/cjs/js-binary-schema-parser/gif.d.ts +51 -0
  27. package/dist/cjs/js-binary-schema-parser/gif.js +158 -0
  28. package/dist/cjs/js-binary-schema-parser/parser.d.ts +9 -0
  29. package/dist/cjs/js-binary-schema-parser/parser.js +54 -0
  30. package/dist/cjs/js-binary-schema-parser/uint8-parser.d.ts +17 -0
  31. package/dist/cjs/js-binary-schema-parser/uint8-parser.js +79 -0
  32. package/dist/cjs/lru/index.d.ts +101 -0
  33. package/dist/cjs/lru/index.js +258 -0
  34. package/dist/{parse-generate.d.ts → cjs/parse-generate.d.ts} +1 -1
  35. package/dist/{parse-generate.js → cjs/parse-generate.js} +27 -9
  36. package/dist/cjs/parser/decompress-frames.d.ts +2 -0
  37. package/dist/cjs/parser/decompress-frames.js +19 -0
  38. package/dist/cjs/preload-gif.d.ts +8 -0
  39. package/dist/cjs/preload-gif.js +41 -0
  40. package/dist/{props.d.ts → cjs/props.d.ts} +6 -3
  41. package/dist/cjs/props.js +2 -0
  42. package/dist/{react-tools.d.ts → cjs/react-tools.d.ts} +0 -0
  43. package/dist/{react-tools.js → cjs/react-tools.js} +1 -0
  44. package/dist/cjs/resolve-gif-source.d.ts +1 -0
  45. package/dist/cjs/resolve-gif-source.js +7 -0
  46. package/dist/{use-element-size.d.ts → cjs/use-element-size.d.ts} +1 -1
  47. package/dist/{use-element-size.js → cjs/use-element-size.js} +1 -1
  48. package/dist/cjs/useCurrentGifIndex.d.ts +2 -0
  49. package/dist/cjs/useCurrentGifIndex.js +35 -0
  50. package/dist/{worker → cjs/worker}/index.d.ts +0 -0
  51. package/dist/{worker → cjs/worker}/index.js +0 -0
  52. package/dist/cjs/worker/source.d.ts +1 -0
  53. package/dist/cjs/worker/source.js +7 -0
  54. package/dist/{worker → cjs/worker}/worker.d.ts +0 -0
  55. package/dist/{worker → cjs/worker}/worker.js +0 -0
  56. package/dist/esm/Gif.d.ts +7 -0
  57. package/dist/esm/GifForDevelopment.d.ts +3 -0
  58. package/dist/esm/GifForRendering.d.ts +3 -0
  59. package/dist/esm/canvas.d.ts +13 -0
  60. package/dist/esm/get-gif-duration-in-seconds.d.ts +5 -0
  61. package/dist/esm/gif-cache.d.ts +4 -0
  62. package/dist/esm/gifuct/deinterlace.d.ts +4 -0
  63. package/dist/esm/gifuct/index.d.ts +4 -0
  64. package/dist/esm/gifuct/lzw.d.ts +5 -0
  65. package/dist/esm/gifuct/types.d.ts +96 -0
  66. package/dist/esm/index.d.ts +4 -0
  67. package/dist/esm/index.mjs +1281 -0
  68. package/dist/esm/is-cors-error.d.ts +1 -0
  69. package/dist/esm/js-binary-schema-parser/gif.d.ts +51 -0
  70. package/dist/esm/js-binary-schema-parser/parser.d.ts +9 -0
  71. package/dist/esm/js-binary-schema-parser/uint8-parser.d.ts +17 -0
  72. package/dist/esm/lru/index.d.ts +101 -0
  73. package/dist/esm/parse-generate.d.ts +18 -0
  74. package/dist/esm/parser/decompress-frames.d.ts +2 -0
  75. package/dist/esm/preload-gif.d.ts +8 -0
  76. package/dist/esm/props.d.ts +25 -0
  77. package/dist/esm/react-tools.d.ts +9 -0
  78. package/dist/esm/resolve-gif-source.d.ts +1 -0
  79. package/dist/esm/use-element-size.d.ts +6 -0
  80. package/dist/esm/useCurrentGifIndex.d.ts +2 -0
  81. package/dist/esm/worker/index.d.ts +1 -0
  82. package/dist/esm/worker/source.d.ts +1 -0
  83. package/dist/esm/worker/worker.d.ts +1 -0
  84. package/dist/tsconfig-esm.tsbuildinfo +1 -0
  85. package/dist/tsconfig.tsbuildinfo +1 -0
  86. package/package.json +67 -57
  87. package/dist/Gif.d.ts +0 -3
  88. package/dist/get-gif-duration-in-seconds.d.ts +0 -1
  89. package/dist/gif-cache.d.ts +0 -3
  90. package/dist/gif-cache.js +0 -5
  91. package/dist/useCurrentGifIndex.d.ts +0 -1
  92. package/dist/useCurrentGifIndex.js +0 -28
  93. package/dist/worker/source.d.ts +0 -1
  94. package/dist/worker/source.js +0 -5
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 organisations 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.
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 © 2022 [Jonny Burger](https://jonny.io)
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 organisation with up to 3 employees
18
- - a non-profit or not-for-profit organisation
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 and 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.
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 noninfringement. 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.
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.
@@ -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: import("react").ForwardRefExoticComponent<RemotionGifProps & import("react").RefAttributes<HTMLCanvasElement>>;
@@ -2,13 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Gif = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
5
6
  const remotion_1 = require("remotion");
6
7
  const GifForDevelopment_1 = require("./GifForDevelopment");
7
8
  const GifForRendering_1 = require("./GifForRendering");
8
- const Gif = (props) => {
9
- if (remotion_1.Internals.getRemotionEnvironment() === 'rendering') {
10
- return (0, jsx_runtime_1.jsx)(GifForRendering_1.GifForRendering, { ...props });
9
+ /**
10
+ * @description Displays a GIF that synchronizes with Remotions useCurrentFrame().
11
+ * @see [Documentation](https://www.remotion.dev/docs/gif/gif)
12
+ */
13
+ exports.Gif = (0, react_1.forwardRef)((props, ref) => {
14
+ const env = remotion_1.Internals.useRemotionEnvironment();
15
+ if (env === 'rendering') {
16
+ return (0, jsx_runtime_1.jsx)(GifForRendering_1.GifForRendering, { ...props, ref: ref });
11
17
  }
12
- return (0, jsx_runtime_1.jsx)(GifForDevelopment_1.GifForDevelopment, { ...props });
13
- };
14
- exports.Gif = Gif;
18
+ return (0, jsx_runtime_1.jsx)(GifForDevelopment_1.GifForDevelopment, { ...props, ref: ref });
19
+ });
@@ -8,11 +8,13 @@ const canvas_1 = require("./canvas");
8
8
  const gif_cache_1 = require("./gif-cache");
9
9
  const is_cors_error_1 = require("./is-cors-error");
10
10
  const react_tools_1 = require("./react-tools");
11
+ const resolve_gif_source_1 = require("./resolve-gif-source");
11
12
  const useCurrentGifIndex_1 = require("./useCurrentGifIndex");
12
- exports.GifForDevelopment = (0, react_1.forwardRef)(({ src, width, height, onError, onLoad, fit = 'fill', ...props }, ref) => {
13
- 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);
14
15
  const [state, update] = (0, react_1.useState)(() => {
15
- const parsedGif = gif_cache_1.gifCache.get(resolvedSrc);
16
+ var _a;
17
+ const parsedGif = (_a = gif_cache_1.volatileGifCache.get(resolvedSrc)) !== null && _a !== void 0 ? _a : gif_cache_1.manuallyManagedGifCache.get(resolvedSrc);
16
18
  if (parsedGif === undefined) {
17
19
  return {
18
20
  delays: [],
@@ -39,7 +41,7 @@ exports.GifForDevelopment = (0, react_1.forwardRef)(({ src, width, height, onErr
39
41
  var _a;
40
42
  (_a = currentOnLoad.current) === null || _a === void 0 ? void 0 : _a.call(currentOnLoad, parsed);
41
43
  update(parsed);
42
- gif_cache_1.gifCache.set(resolvedSrc, parsed);
44
+ gif_cache_1.volatileGifCache.set(resolvedSrc, parsed);
43
45
  done = true;
44
46
  (0, remotion_1.continueRender)(newHandle);
45
47
  (0, remotion_1.continueRender)(id);
@@ -71,6 +73,9 @@ exports.GifForDevelopment = (0, react_1.forwardRef)(({ src, width, height, onErr
71
73
  }
72
74
  throw new Error(`Failed to render GIF with source ${src}: "${error.message}".`);
73
75
  }
74
- const index = (0, useCurrentGifIndex_1.useCurrentGifIndex)(state.delays);
76
+ const index = (0, useCurrentGifIndex_1.useCurrentGifIndex)(state.delays, loopBehavior);
77
+ if (index === -1) {
78
+ return null;
79
+ }
75
80
  return ((0, jsx_runtime_1.jsx)(canvas_1.Canvas, { fit: fit, index: index, frames: state.frames, width: width, height: height, ...props, ref: ref }));
76
81
  });
@@ -8,11 +8,12 @@ const canvas_1 = require("./canvas");
8
8
  const gif_cache_1 = require("./gif-cache");
9
9
  const is_cors_error_1 = require("./is-cors-error");
10
10
  const react_tools_1 = require("./react-tools");
11
+ const resolve_gif_source_1 = require("./resolve-gif-source");
11
12
  const useCurrentGifIndex_1 = require("./useCurrentGifIndex");
12
- exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad, onError, fit = 'fill', ...props }, ref) => {
13
- const resolvedSrc = new URL(src, window.location.origin).href;
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);
14
15
  const [state, update] = (0, react_1.useState)(() => {
15
- const parsedGif = gif_cache_1.gifCache.get(resolvedSrc);
16
+ const parsedGif = gif_cache_1.volatileGifCache.get(resolvedSrc);
16
17
  if (parsedGif === undefined) {
17
18
  return {
18
19
  delays: [],
@@ -25,7 +26,12 @@ exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad,
25
26
  });
26
27
  const [error, setError] = (0, react_1.useState)(null);
27
28
  const [id] = (0, react_1.useState)(() => (0, remotion_1.delayRender)(`Rendering <Gif/> with src="${resolvedSrc}"`));
28
- const index = (0, useCurrentGifIndex_1.useCurrentGifIndex)(state.delays);
29
+ (0, react_1.useEffect)(() => {
30
+ return () => {
31
+ (0, remotion_1.continueRender)(id);
32
+ };
33
+ }, [id]);
34
+ const index = (0, useCurrentGifIndex_1.useCurrentGifIndex)(state.delays, loopBehavior);
29
35
  const currentOnLoad = (0, react_1.useRef)(onLoad);
30
36
  const currentOnError = (0, react_1.useRef)(onError);
31
37
  currentOnLoad.current = onLoad;
@@ -40,7 +46,7 @@ exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad,
40
46
  var _a;
41
47
  (_a = currentOnLoad.current) === null || _a === void 0 ? void 0 : _a.call(currentOnLoad, parsed);
42
48
  update(parsed);
43
- gif_cache_1.gifCache.set(resolvedSrc, parsed);
49
+ gif_cache_1.volatileGifCache.set(resolvedSrc, parsed);
44
50
  done = true;
45
51
  (0, remotion_1.continueRender)(newHandle);
46
52
  (0, remotion_1.continueRender)(id);
@@ -72,5 +78,8 @@ exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad,
72
78
  }
73
79
  throw new Error(`Failed to render GIF with source ${src}: "${error.message}". Render with --log=verbose to see the full stack.`);
74
80
  }
81
+ if (index === -1) {
82
+ return null;
83
+ }
75
84
  return ((0, jsx_runtime_1.jsx)(canvas_1.Canvas, { fit: fit, index: index, frames: state.frames, width: width, height: height, ...props, ref: ref }));
76
85
  });
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import type { GifFillMode } from './props';
3
- declare type Props = {
3
+ type Props = {
4
4
  index: number;
5
5
  frames: ImageData[];
6
6
  width?: number;
@@ -53,6 +53,9 @@ const calcArgs = (fit, frameSize, canvasSize) => {
53
53
  }
54
54
  };
55
55
  const makeCanvas = () => {
56
+ if (typeof document === 'undefined') {
57
+ return null;
58
+ }
56
59
  const canvas = document.createElement('canvas');
57
60
  const ctx = canvas.getContext('2d');
58
61
  canvas.width = 0;
@@ -0,0 +1,5 @@
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>;
@@ -7,23 +7,28 @@ const react_tools_1 = require("./react-tools");
7
7
  const calcDuration = (parsed) => {
8
8
  return (parsed.delays.reduce((sum, delay) => sum + delay, 0) / 1000);
9
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
+ */
10
14
  const getGifDurationInSeconds = async (src) => {
15
+ var _a;
11
16
  const resolvedSrc = new URL(src, window.location.origin).href;
12
- const inCache = gif_cache_1.gifCache.get(resolvedSrc);
17
+ const inCache = (_a = gif_cache_1.volatileGifCache.get(resolvedSrc)) !== null && _a !== void 0 ? _a : gif_cache_1.manuallyManagedGifCache.get(resolvedSrc);
13
18
  if (inCache) {
14
19
  return calcDuration(inCache);
15
20
  }
16
21
  if (remotion_1.Internals.getRemotionEnvironment() === 'rendering') {
17
22
  const renderingParsed = (0, react_tools_1.parseWithWorker)(resolvedSrc);
18
23
  const resolved = await renderingParsed.prom;
19
- gif_cache_1.gifCache.set(resolvedSrc, resolved);
24
+ gif_cache_1.volatileGifCache.set(resolvedSrc, resolved);
20
25
  return calcDuration(resolved);
21
26
  }
22
27
  const parsed = await (0, react_tools_1.parseGif)({
23
28
  src: resolvedSrc,
24
29
  controller: new AbortController(),
25
30
  });
26
- gif_cache_1.gifCache.set(resolvedSrc, parsed);
31
+ gif_cache_1.volatileGifCache.set(resolvedSrc, parsed);
27
32
  return calcDuration(parsed);
28
33
  };
29
34
  exports.getGifDurationInSeconds = getGifDurationInSeconds;
@@ -0,0 +1,4 @@
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>;
@@ -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,4 @@
1
+ /**
2
+ * Deinterlace function from https://github.com/shachaf/jsgif
3
+ */
4
+ export declare const deinterlace: (pixels: number[], width: number) => any[];
@@ -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,5 @@
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[];
@@ -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;
@@ -0,0 +1,96 @@
1
+ type Dimensions = {
2
+ top: number;
3
+ left: number;
4
+ width: number;
5
+ height: number;
6
+ };
7
+ export type Application = {
8
+ application: {
9
+ blockSize: number;
10
+ blocks: number[];
11
+ codes: number[];
12
+ id: string;
13
+ };
14
+ };
15
+ type Lct = {
16
+ exists: boolean;
17
+ future: number;
18
+ interlaced: boolean;
19
+ size: number;
20
+ sort: boolean;
21
+ };
22
+ export type Frame = {
23
+ gce: {
24
+ byteSize: number;
25
+ codes: number[];
26
+ delay: number;
27
+ terminator: number;
28
+ transparentColorIndex: number;
29
+ extras: {
30
+ userInput: boolean;
31
+ transparentColorGiven: boolean;
32
+ future: number;
33
+ disposal: number;
34
+ };
35
+ };
36
+ image: {
37
+ code: number;
38
+ data: {
39
+ minCodeSize: number;
40
+ blocks: number[];
41
+ };
42
+ descriptor: {
43
+ top: number;
44
+ left: number;
45
+ width: number;
46
+ height: number;
47
+ lct: Lct;
48
+ };
49
+ lct: [number, number, number][] | undefined;
50
+ };
51
+ };
52
+ export type ParsedFrame = {
53
+ dims: {
54
+ width: number;
55
+ height: number;
56
+ top: number;
57
+ left: number;
58
+ };
59
+ colorTable: [number, number, number][];
60
+ delay: number;
61
+ disposalType: number;
62
+ patch: Uint8ClampedArray;
63
+ pixels: number[];
64
+ transparentIndex: number;
65
+ };
66
+ export type ParsedFrameWithoutPatch = Omit<ParsedFrame, 'patch'>;
67
+ export type ParsedGif = {
68
+ frames: (Application | Frame)[];
69
+ gct: [number, number, number][];
70
+ header: {
71
+ signature: string;
72
+ version: string;
73
+ };
74
+ lsd: {
75
+ backgroundColorIndex: number;
76
+ gct: {
77
+ exists: boolean;
78
+ resolution: number;
79
+ size: number;
80
+ sort: boolean;
81
+ };
82
+ height: number;
83
+ width: number;
84
+ pixelAspectRatio: number;
85
+ };
86
+ };
87
+ export type Image = {
88
+ pixels: number[];
89
+ dims: Dimensions;
90
+ delay?: number;
91
+ transparentIndex?: number;
92
+ colorTable?: [number, number, number][] | Lct;
93
+ disposalType?: unknown;
94
+ patch?: Uint8ClampedArray;
95
+ };
96
+ export {};
File without changes
@@ -1,3 +1,4 @@
1
1
  export { getGifDurationInSeconds } from './get-gif-duration-in-seconds';
2
2
  export { Gif } from './Gif';
3
+ export { preloadGif } from './preload-gif';
3
4
  export { GifFillMode, RemotionGifProps } from './props';
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Gif = exports.getGifDurationInSeconds = void 0;
3
+ exports.preloadGif = exports.Gif = exports.getGifDurationInSeconds = void 0;
4
4
  var get_gif_duration_in_seconds_1 = require("./get-gif-duration-in-seconds");
5
5
  Object.defineProperty(exports, "getGifDurationInSeconds", { enumerable: true, get: function () { return get_gif_duration_in_seconds_1.getGifDurationInSeconds; } });
6
6
  var Gif_1 = require("./Gif");
7
7
  Object.defineProperty(exports, "Gif", { enumerable: true, get: function () { return Gif_1.Gif; } });
8
+ var preload_gif_1 = require("./preload-gif");
9
+ Object.defineProperty(exports, "preloadGif", { enumerable: true, get: function () { return preload_gif_1.preloadGif; } });
File without changes
@@ -0,0 +1,51 @@
1
+ import type { ParsedGif } from '../gifuct/types';
2
+ import type { Stream } from './uint8-parser';
3
+ export declare const GIF: (((stream: Stream, result: ParsedGif, parent: ParsedGif, parseFn: (st: Stream, schema: unknown, result: ParsedGif, parent: ParsedGif) => void) => void) | {
4
+ header: ({
5
+ signature: (stream: Stream) => string;
6
+ version?: undefined;
7
+ } | {
8
+ version: (stream: Stream) => string;
9
+ signature?: undefined;
10
+ })[];
11
+ lsd?: undefined;
12
+ frames?: undefined;
13
+ } | {
14
+ lsd: ({
15
+ width: (stream: Stream) => number;
16
+ height?: undefined;
17
+ gct?: undefined;
18
+ backgroundColorIndex?: undefined;
19
+ pixelAspectRatio?: undefined;
20
+ } | {
21
+ height: (stream: Stream) => number;
22
+ width?: undefined;
23
+ gct?: undefined;
24
+ backgroundColorIndex?: undefined;
25
+ pixelAspectRatio?: undefined;
26
+ } | {
27
+ gct: (stream: Stream) => Record<string, number | boolean>;
28
+ width?: undefined;
29
+ height?: undefined;
30
+ backgroundColorIndex?: undefined;
31
+ pixelAspectRatio?: undefined;
32
+ } | {
33
+ backgroundColorIndex: (stream: Stream) => number;
34
+ width?: undefined;
35
+ height?: undefined;
36
+ gct?: undefined;
37
+ pixelAspectRatio?: undefined;
38
+ } | {
39
+ pixelAspectRatio: (stream: Stream) => number;
40
+ width?: undefined;
41
+ height?: undefined;
42
+ gct?: undefined;
43
+ backgroundColorIndex?: undefined;
44
+ })[];
45
+ header?: undefined;
46
+ frames?: undefined;
47
+ } | {
48
+ frames: (stream: Stream, result: unknown, parent: unknown, _parse: (st: Stream, schema: unknown, result: unknown, parent: unknown) => void) => unknown[];
49
+ header?: undefined;
50
+ lsd?: undefined;
51
+ })[];