@remotion/gif 4.0.0-webhook.27 → 4.1.0-alpha2

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
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generate = exports.parse = void 0;
4
- const gifuct_js_1 = require("gifuct-js");
4
+ const gifuct_1 = require("./gifuct");
5
+ const decompress_frames_1 = require("./parser/decompress-frames");
5
6
  const validateAndFix = (gif) => {
6
7
  let currentGce = null;
7
8
  for (const frame of gif.frames) {
@@ -19,24 +20,40 @@ const parse = (src, { signal, }) => fetch(src, { signal })
19
20
  throw Error(`Wrong content type: "${resp.headers.get('Content-Type')}"`);
20
21
  return resp.arrayBuffer();
21
22
  })
22
- .then((buffer) => (0, gifuct_js_1.parseGIF)(buffer))
23
+ .then((buffer) => (0, gifuct_1.parseGIF)(buffer))
23
24
  .then((gif) => {
24
25
  validateAndFix(gif);
25
26
  return gif;
26
27
  })
27
28
  .then((gif) => Promise.all([
28
- (0, gifuct_js_1.decompressFrames)(gif, false),
29
+ (0, decompress_frames_1.decompressFrames)(gif),
29
30
  { width: gif.lsd.width, height: gif.lsd.height },
30
31
  ]))
31
32
  .then(([frames, options]) => {
32
33
  const readyFrames = [];
33
34
  const size = options.width * options.height * 4;
35
+ let canvas = new Uint8ClampedArray(size);
34
36
  for (let i = 0; i < frames.length; ++i) {
35
37
  const frame = frames[i];
36
- const typedArray = i === 0 || frames[i - 1].disposalType === 2
37
- ? new Uint8ClampedArray(size)
38
- : readyFrames[i - 1].slice();
39
- readyFrames.push(putPixels(typedArray, frame, options));
38
+ // Read about different disposal types
39
+ // https://giflib.sourceforge.net/whatsinagif/animation_and_transparency.html
40
+ const prevCanvas = frames[i].disposalType === 3 ? canvas.slice() : null;
41
+ readyFrames.push(putPixels(canvas, frame, options));
42
+ // Disposal type 2: The canvas should be restored to the background color
43
+ if (frames[i].disposalType === 2) {
44
+ canvas = new Uint8ClampedArray(size);
45
+ }
46
+ // Disposal type 3: The decoder should restore the canvas to its previous state before the current image was drawn
47
+ else if (frames[i].disposalType === 3) {
48
+ if (!prevCanvas) {
49
+ throw Error('Disposal type 3 without previous frame');
50
+ }
51
+ canvas = prevCanvas;
52
+ }
53
+ // Disposal type 1: Draw the next image on top of it
54
+ else {
55
+ canvas = readyFrames[i].slice();
56
+ }
40
57
  }
41
58
  return {
42
59
  ...options,
@@ -55,11 +72,12 @@ const putPixels = (typedArray, frame, gifSize) => {
55
72
  const colorIndex = frame.pixels[pPos];
56
73
  if (colorIndex !== frame.transparentIndex) {
57
74
  const taPos = offset + y * gifSize.width + x;
58
- const color = frame.colorTable[colorIndex] || [0, 0, 0];
75
+ const color = frame.colorTable[colorIndex];
59
76
  typedArray[taPos * 4] = color[0];
60
77
  typedArray[taPos * 4 + 1] = color[1];
61
78
  typedArray[taPos * 4 + 2] = color[2];
62
- typedArray[taPos * 4 + 3] = 255;
79
+ typedArray[taPos * 4 + 3] =
80
+ colorIndex === frame.transparentIndex ? 0 : 255;
63
81
  }
64
82
  }
65
83
  }
@@ -0,0 +1,2 @@
1
+ import type { ParsedFrameWithoutPatch, ParsedGif } from '../gifuct/types';
2
+ export declare const decompressFrames: (parsedGif: ParsedGif) => ParsedFrameWithoutPatch[];
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decompressFrames = void 0;
4
+ const gifuct_1 = require("../gifuct");
5
+ const decompressFrames = (parsedGif) => {
6
+ return parsedGif.frames
7
+ .filter((f) => {
8
+ return !('application' in f);
9
+ })
10
+ .map((f) => {
11
+ const fr = f.image
12
+ ? (0, gifuct_1.decompressFrame)(f, parsedGif.gct)
13
+ : null;
14
+ return fr;
15
+ })
16
+ .filter(Boolean)
17
+ .map((f) => f);
18
+ };
19
+ exports.decompressFrames = decompressFrames;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @description Returns an object with two entries: waitUntilDone() that returns a Promise which can be awaited and free() which will cancel preloading or free up the memory if the GIF is not being used anymore.
3
+ * @see [Documentation](https://www.remotion.dev/docs/gif/preload-gif)
4
+ */
5
+ export declare const preloadGif: (src: string) => {
6
+ waitUntilDone: () => Promise<void>;
7
+ free: () => void;
8
+ };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.preloadGif = void 0;
4
+ const gif_cache_1 = require("./gif-cache");
5
+ const react_tools_1 = require("./react-tools");
6
+ const resolve_gif_source_1 = require("./resolve-gif-source");
7
+ /**
8
+ * @description Returns an object with two entries: waitUntilDone() that returns a Promise which can be awaited and free() which will cancel preloading or free up the memory if the GIF is not being used anymore.
9
+ * @see [Documentation](https://www.remotion.dev/docs/gif/preload-gif)
10
+ */
11
+ const preloadGif = (src) => {
12
+ const resolvedSrc = (0, resolve_gif_source_1.resolveGifSource)(src);
13
+ if (gif_cache_1.volatileGifCache.has(resolvedSrc)) {
14
+ return {
15
+ waitUntilDone: () => Promise.resolve(),
16
+ free: () => gif_cache_1.volatileGifCache.delete(resolvedSrc),
17
+ };
18
+ }
19
+ if (gif_cache_1.manuallyManagedGifCache.has(resolvedSrc)) {
20
+ return {
21
+ waitUntilDone: () => Promise.resolve(),
22
+ free: () => gif_cache_1.manuallyManagedGifCache.delete(resolvedSrc),
23
+ };
24
+ }
25
+ const { prom, cancel } = (0, react_tools_1.parseWithWorker)(resolvedSrc);
26
+ let deleted = false;
27
+ prom.then((p) => {
28
+ if (!deleted) {
29
+ gif_cache_1.manuallyManagedGifCache.set(resolvedSrc, p);
30
+ }
31
+ });
32
+ return {
33
+ waitUntilDone: () => prom.then(() => undefined),
34
+ free: () => {
35
+ cancel();
36
+ deleted = true;
37
+ gif_cache_1.manuallyManagedGifCache.delete(resolvedSrc);
38
+ },
39
+ };
40
+ };
41
+ exports.preloadGif = preloadGif;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
- export declare type RemotionGifProps = {
2
+ export type GifLoopBehavior = 'loop' | 'pause-after-finish' | 'unmount-after-finish';
3
+ export type RemotionGifProps = {
3
4
  src: string;
4
5
  width?: number;
5
6
  height?: number;
@@ -12,11 +13,13 @@ export declare type RemotionGifProps = {
12
13
  onError?: (error: Error) => void;
13
14
  fit?: GifFillMode;
14
15
  style?: React.CSSProperties;
16
+ loopBehavior?: GifLoopBehavior;
17
+ id?: string;
15
18
  };
16
- export declare type GifState = {
19
+ export type GifState = {
17
20
  delays: number[];
18
21
  frames: ImageData[];
19
22
  width: number;
20
23
  height: number;
21
24
  };
22
- export declare type GifFillMode = 'contain' | 'cover' | 'fill';
25
+ export type GifFillMode = 'contain' | 'cover' | 'fill';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
File without changes
@@ -21,6 +21,7 @@ const parseWithWorker = (src) => {
21
21
  else {
22
22
  const data = message.error ? message : (0, parse_generate_1.generate)(message);
23
23
  resolve(data);
24
+ worker.terminate();
24
25
  }
25
26
  }
26
27
  };
@@ -0,0 +1 @@
1
+ export declare const resolveGifSource: (src: string) => string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveGifSource = void 0;
4
+ const resolveGifSource = (src) => {
5
+ return new URL(src, typeof window === 'undefined' ? undefined : window.location.origin).href;
6
+ };
7
+ exports.resolveGifSource = resolveGifSource;
@@ -1,4 +1,4 @@
1
- export declare type Size = {
1
+ export type Size = {
2
2
  width: number;
3
3
  height: number;
4
4
  };
@@ -20,7 +20,7 @@ const useElementSize = (ref) => {
20
20
  const { contentRect } = entries[0];
21
21
  // The clientRect returns the size with `scale()` being applied.
22
22
  const newSize = entries[0].target.getClientRects();
23
- if (!newSize || !newSize[0]) {
23
+ if (!(newSize === null || newSize === void 0 ? void 0 : newSize[0])) {
24
24
  setSize(null);
25
25
  return;
26
26
  }
@@ -0,0 +1,2 @@
1
+ import type { GifLoopBehavior } from './props';
2
+ export declare function useCurrentGifIndex(delays: number[], loopBehavior: GifLoopBehavior): number;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useCurrentGifIndex = void 0;
4
+ const react_1 = require("react");
5
+ const remotion_1 = require("remotion");
6
+ function useCurrentGifIndex(delays, loopBehavior) {
7
+ const currentFrame = (0, remotion_1.useCurrentFrame)();
8
+ const videoConfig = (0, remotion_1.useVideoConfig)();
9
+ const duration = (0, react_1.useMemo)(() => {
10
+ if (delays.length !== 0) {
11
+ return delays.reduce((sum, delay) => sum + (delay !== null && delay !== void 0 ? delay : 0), 0);
12
+ }
13
+ return 1;
14
+ }, [delays]);
15
+ if (delays.length === 0) {
16
+ return 0;
17
+ }
18
+ const time = (currentFrame / videoConfig.fps) * 1000;
19
+ if (loopBehavior === 'pause-after-finish' && time >= duration) {
20
+ return delays.length - 1;
21
+ }
22
+ if (loopBehavior === 'unmount-after-finish' && time >= duration) {
23
+ return -1;
24
+ }
25
+ let currentTime = time % duration;
26
+ for (let i = 0; i < delays.length; i++) {
27
+ const delay = delays[i];
28
+ if (currentTime < delay) {
29
+ return i;
30
+ }
31
+ currentTime -= delay;
32
+ }
33
+ return 0;
34
+ }
35
+ exports.useCurrentGifIndex = useCurrentGifIndex;
File without changes
File without changes
@@ -0,0 +1 @@
1
+ export declare const src = "\"use strict\";(()=>{var P=(t,r,e={},n=e)=>{if(Array.isArray(r))r.forEach(o=>P(t,o,e,n));else if(typeof r==\"function\")r(t,e,n,P);else{let o=Object.keys(r)[0];Array.isArray(r[o])?(n[o]={},P(t,r[o],e,n[o])):n[o]=r[o](t,e,n,P)}return e},M=(t,r)=>function(e,n,o,c){let s=[],a=e.pos;for(;r(e,n,o);){let i={};if(c(e,t,n,i),e.pos===a)break;a=e.pos,s.push(i)}return s},g=(t,r)=>(e,n,o,c)=>{r(e,n,o)&&c(e,t,n,o)};var W=t=>({data:t,pos:0}),m=()=>t=>t.data[t.pos++],U=(t=0)=>r=>r.data[r.pos+t],f=t=>r=>r.data.subarray(r.pos,r.pos+=t),k=t=>r=>r.data.subarray(r.pos,r.pos+t),v=t=>r=>Array.from(f(t)(r)).map(e=>String.fromCharCode(e)).join(\"\"),b=t=>r=>{let e=f(2)(r);return t?(e[1]<<8)+e[0]:(e[0]<<8)+e[1]},E=(t,r)=>(e,n,o)=>{let c=typeof r==\"function\"?r(e,n,o):r,s=f(t),a=new Array(c);for(let i=0;i<c;i++)a[i]=s(e);return a},$=(t,r,e)=>{let n=0;for(let o=0;o<e;o++)n+=Number(t[r+o]&&2**(e-o-1));return n},I=t=>r=>{let e=m()(r),n=new Array(8);for(let o=0;o<8;o++)n[7-o]=Boolean(e&1<<o);return Object.keys(t).reduce((o,c)=>{let s=t[c];return s.length?o[c]=$(n,s.index,s.length):o[c]=n[s.index],o},{})};var z={blocks:t=>{let e=[],n=t.data.length,o=0;for(let a=m()(t);a!==0&&a;a=m()(t)){if(t.pos+a>=n){let i=n-t.pos;e.push(f(i)(t)),o+=i;break}e.push(f(a)(t)),o+=a}let c=new Uint8Array(o),s=0;for(let a=0;a<e.length;a++)c.set(e[a],s),s+=e[a].length;return c}},q=g({gce:[{codes:f(2)},{byteSize:m()},{extras:I({future:{index:0,length:3},disposal:{index:3,length:3},userInput:{index:6},transparentColorGiven:{index:7}})},{delay:b(!0)},{transparentColorIndex:m()},{terminator:m()}]},t=>{let r=k(2)(t);return r[0]===33&&r[1]===249}),H=g({image:[{code:m()},{descriptor:[{left:b(!0)},{top:b(!0)},{width:b(!0)},{height:b(!0)},{lct:I({exists:{index:0},interlaced:{index:1},sort:{index:2},future:{index:3,length:2},size:{index:5,length:3}})}]},g({lct:E(3,(t,r,e)=>2**(e.descriptor.lct.size+1))},(t,r,e)=>e.descriptor.lct.exists),{data:[{minCodeSize:m()},z]}]},t=>U()(t)===44),J=g({text:[{codes:f(2)},{blockSize:m()},{preData:(t,r,e)=>f(e.text.blockSize)(t)},z]},t=>{let r=k(2)(t);return r[0]===33&&r[1]===1}),Q=g({application:[{codes:f(2)},{blockSize:m()},{id:(t,r,e)=>v(e.blockSize)(t)},z]},t=>{let r=k(2)(t);return r[0]===33&&r[1]===255}),V=g({comment:[{codes:f(2)},z]},t=>{let r=k(2)(t);return r[0]===33&&r[1]===254}),K=[{header:[{signature:v(3)},{version:v(3)}]},{lsd:[{width:b(!0)},{height:b(!0)},{gct:I({exists:{index:0},resolution:{index:1,length:3},sort:{index:4},size:{index:5,length:3}})},{backgroundColorIndex:m()},{pixelAspectRatio:m()}]},g({gct:E(3,(t,r)=>2**(r.lsd.gct.size+1))},(t,r)=>r.lsd.gct.exists),{frames:M([q,Q,V,H,J],t=>{let r=U()(t);return r===33||r===44})}];var X=(t,r)=>{let e=new Array(t.length),n=t.length/r,o=function(i,d){let u=t.slice(d*r,(d+1)*r);e.splice(...[i*r,r].concat(u))},c=[0,4,2,1],s=[8,8,4,2],a=0;for(let i=0;i<4;i++)for(let d=c[i];d<n;d+=s[i])o(d,a),a++;return e};var Z=(t,r,e)=>{let c=e,s,a,i,d,u;var w;let l,p;var C,S,h,_,G;let x=new Array(e),B=new Array(4096),T=new Array(4096),F=new Array(4096+1),R=t,y=1<<R,O=y+1;for(s=y+2,u=-1,i=R+1,a=(1<<i)-1,l=0;l<y;l++)B[l]=0,T[l]=l;var C,w,S,h,G,_;for(C=w=S=h=G=_=0,p=0;p<c;){if(h===0){if(w<i){C+=r[_]<<w,w+=8,_++;continue}if(l=C&a,C>>=i,w-=i,l>s||l===O)break;if(l===y){i=R+1,a=(1<<i)-1,s=y+2,u=-1;continue}if(u===-1){F[h++]=T[l],u=l,S=l;continue}for(d=l,l===s&&(F[h++]=S,l=u);l>y;)F[h++]=T[l],l=B[l];S=T[l]&255,F[h++]=S,s<4096&&(B[s]=u,T[s]=S,s++,!(s&a)&&s<4096&&(i++,a+=s)),u=d}h--,x[G++]=F[h],p++}for(p=G;p<c;p++)x[p]=0;return x};var j=t=>{let r=new Uint8Array(t);return P(W(r),K)},D=(t,r)=>{var s,a;if(!t.image){console.warn(\"gif frame does not have associated image.\");return}let{image:e}=t,n=e.descriptor.width*e.descriptor.height,o=Z(e.data.minCodeSize,e.data.blocks,n);return(s=e.descriptor.lct)!=null&&s.interlaced&&(o=X(o,e.descriptor.width)),{pixels:o,dims:{top:t.image.descriptor.top,left:t.image.descriptor.left,width:t.image.descriptor.width,height:t.image.descriptor.height},colorTable:(a=e.descriptor.lct)!=null&&a.exists?e.lct:r,delay:(t.gce.delay||10)*10,disposalType:t.gce.extras.disposal,transparentIndex:t.gce.extras.transparentColorGiven?t.gce.transparentColorIndex:-1}};var L=t=>t.frames.filter(r=>!(\"application\"in r)).map(r=>r.image?D(r,t.gct):null).filter(Boolean).map(r=>r);var Y=t=>{let r=null;for(let e of t.frames)r=e.gce?e.gce:r,\"image\"in e&&!(\"gce\"in e)&&r!==null&&(e.gce=r)},N=(t,{signal:r})=>fetch(t,{signal:r}).then(e=>{var n;if(!((n=e.headers.get(\"Content-Type\"))!=null&&n.includes(\"image/gif\")))throw Error(`Wrong content type: \"${e.headers.get(\"Content-Type\")}\"`);return e.arrayBuffer()}).then(e=>j(e)).then(e=>(Y(e),e)).then(e=>Promise.all([L(e),{width:e.lsd.width,height:e.lsd.height}])).then(([e,n])=>{let o=[],c=n.width*n.height*4,s=new Uint8ClampedArray(c);for(let a=0;a<e.length;++a){let i=e[a],d=e[a].disposalType===3?s.slice():null;if(o.push(ee(s,i,n)),e[a].disposalType===2)s=new Uint8ClampedArray(c);else if(e[a].disposalType===3){if(!d)throw Error(\"Disposal type 3 without previous frame\");s=d}else s=o[a].slice()}return{...n,loaded:!0,delays:e.map(a=>a.delay),frames:o}}),ee=(t,r,e)=>{let{width:n,height:o,top:c,left:s}=r.dims,a=c*e.width+s;for(let i=0;i<o;i++)for(let d=0;d<n;d++){let u=i*n+d,l=r.pixels[u];if(l!==r.transparentIndex){let p=a+i*e.width+d,x=r.colorTable[l];t[p*4]=x[0],t[p*4+1]=x[1],t[p*4+2]=x[2],t[p*4+3]=l===r.transparentIndex?0:255}}return t};var A=new Map;self.addEventListener(\"message\",t=>{let{type:r,src:e}=t.data||t;switch(r){case\"parse\":{if(!A.has(e)){let n=new AbortController,o={signal:n.signal};A.set(e,n),N(e,o).then(c=>{self.postMessage(Object.assign(c,{src:e}),c.frames.map(s=>s.buffer))}).catch(c=>{self.postMessage({src:e,error:c,loaded:!0})}).finally(()=>{A.delete(e)})}break}case\"cancel\":{A.has(e)&&(A.get(e).abort(),A.delete(e));break}default:break}});})();\n";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.src = void 0;
4
+ // Auto-generated by build.mjs
5
+ exports.src =
6
+ // eslint-disable-next-line no-template-curly-in-string
7
+ '"use strict";(()=>{var P=(t,r,e={},n=e)=>{if(Array.isArray(r))r.forEach(o=>P(t,o,e,n));else if(typeof r=="function")r(t,e,n,P);else{let o=Object.keys(r)[0];Array.isArray(r[o])?(n[o]={},P(t,r[o],e,n[o])):n[o]=r[o](t,e,n,P)}return e},M=(t,r)=>function(e,n,o,c){let s=[],a=e.pos;for(;r(e,n,o);){let i={};if(c(e,t,n,i),e.pos===a)break;a=e.pos,s.push(i)}return s},g=(t,r)=>(e,n,o,c)=>{r(e,n,o)&&c(e,t,n,o)};var W=t=>({data:t,pos:0}),m=()=>t=>t.data[t.pos++],U=(t=0)=>r=>r.data[r.pos+t],f=t=>r=>r.data.subarray(r.pos,r.pos+=t),k=t=>r=>r.data.subarray(r.pos,r.pos+t),v=t=>r=>Array.from(f(t)(r)).map(e=>String.fromCharCode(e)).join(""),b=t=>r=>{let e=f(2)(r);return t?(e[1]<<8)+e[0]:(e[0]<<8)+e[1]},E=(t,r)=>(e,n,o)=>{let c=typeof r=="function"?r(e,n,o):r,s=f(t),a=new Array(c);for(let i=0;i<c;i++)a[i]=s(e);return a},$=(t,r,e)=>{let n=0;for(let o=0;o<e;o++)n+=Number(t[r+o]&&2**(e-o-1));return n},I=t=>r=>{let e=m()(r),n=new Array(8);for(let o=0;o<8;o++)n[7-o]=Boolean(e&1<<o);return Object.keys(t).reduce((o,c)=>{let s=t[c];return s.length?o[c]=$(n,s.index,s.length):o[c]=n[s.index],o},{})};var z={blocks:t=>{let e=[],n=t.data.length,o=0;for(let a=m()(t);a!==0&&a;a=m()(t)){if(t.pos+a>=n){let i=n-t.pos;e.push(f(i)(t)),o+=i;break}e.push(f(a)(t)),o+=a}let c=new Uint8Array(o),s=0;for(let a=0;a<e.length;a++)c.set(e[a],s),s+=e[a].length;return c}},q=g({gce:[{codes:f(2)},{byteSize:m()},{extras:I({future:{index:0,length:3},disposal:{index:3,length:3},userInput:{index:6},transparentColorGiven:{index:7}})},{delay:b(!0)},{transparentColorIndex:m()},{terminator:m()}]},t=>{let r=k(2)(t);return r[0]===33&&r[1]===249}),H=g({image:[{code:m()},{descriptor:[{left:b(!0)},{top:b(!0)},{width:b(!0)},{height:b(!0)},{lct:I({exists:{index:0},interlaced:{index:1},sort:{index:2},future:{index:3,length:2},size:{index:5,length:3}})}]},g({lct:E(3,(t,r,e)=>2**(e.descriptor.lct.size+1))},(t,r,e)=>e.descriptor.lct.exists),{data:[{minCodeSize:m()},z]}]},t=>U()(t)===44),J=g({text:[{codes:f(2)},{blockSize:m()},{preData:(t,r,e)=>f(e.text.blockSize)(t)},z]},t=>{let r=k(2)(t);return r[0]===33&&r[1]===1}),Q=g({application:[{codes:f(2)},{blockSize:m()},{id:(t,r,e)=>v(e.blockSize)(t)},z]},t=>{let r=k(2)(t);return r[0]===33&&r[1]===255}),V=g({comment:[{codes:f(2)},z]},t=>{let r=k(2)(t);return r[0]===33&&r[1]===254}),K=[{header:[{signature:v(3)},{version:v(3)}]},{lsd:[{width:b(!0)},{height:b(!0)},{gct:I({exists:{index:0},resolution:{index:1,length:3},sort:{index:4},size:{index:5,length:3}})},{backgroundColorIndex:m()},{pixelAspectRatio:m()}]},g({gct:E(3,(t,r)=>2**(r.lsd.gct.size+1))},(t,r)=>r.lsd.gct.exists),{frames:M([q,Q,V,H,J],t=>{let r=U()(t);return r===33||r===44})}];var X=(t,r)=>{let e=new Array(t.length),n=t.length/r,o=function(i,d){let u=t.slice(d*r,(d+1)*r);e.splice(...[i*r,r].concat(u))},c=[0,4,2,1],s=[8,8,4,2],a=0;for(let i=0;i<4;i++)for(let d=c[i];d<n;d+=s[i])o(d,a),a++;return e};var Z=(t,r,e)=>{let c=e,s,a,i,d,u;var w;let l,p;var C,S,h,_,G;let x=new Array(e),B=new Array(4096),T=new Array(4096),F=new Array(4096+1),R=t,y=1<<R,O=y+1;for(s=y+2,u=-1,i=R+1,a=(1<<i)-1,l=0;l<y;l++)B[l]=0,T[l]=l;var C,w,S,h,G,_;for(C=w=S=h=G=_=0,p=0;p<c;){if(h===0){if(w<i){C+=r[_]<<w,w+=8,_++;continue}if(l=C&a,C>>=i,w-=i,l>s||l===O)break;if(l===y){i=R+1,a=(1<<i)-1,s=y+2,u=-1;continue}if(u===-1){F[h++]=T[l],u=l,S=l;continue}for(d=l,l===s&&(F[h++]=S,l=u);l>y;)F[h++]=T[l],l=B[l];S=T[l]&255,F[h++]=S,s<4096&&(B[s]=u,T[s]=S,s++,!(s&a)&&s<4096&&(i++,a+=s)),u=d}h--,x[G++]=F[h],p++}for(p=G;p<c;p++)x[p]=0;return x};var j=t=>{let r=new Uint8Array(t);return P(W(r),K)},D=(t,r)=>{var s,a;if(!t.image){console.warn("gif frame does not have associated image.");return}let{image:e}=t,n=e.descriptor.width*e.descriptor.height,o=Z(e.data.minCodeSize,e.data.blocks,n);return(s=e.descriptor.lct)!=null&&s.interlaced&&(o=X(o,e.descriptor.width)),{pixels:o,dims:{top:t.image.descriptor.top,left:t.image.descriptor.left,width:t.image.descriptor.width,height:t.image.descriptor.height},colorTable:(a=e.descriptor.lct)!=null&&a.exists?e.lct:r,delay:(t.gce.delay||10)*10,disposalType:t.gce.extras.disposal,transparentIndex:t.gce.extras.transparentColorGiven?t.gce.transparentColorIndex:-1}};var L=t=>t.frames.filter(r=>!("application"in r)).map(r=>r.image?D(r,t.gct):null).filter(Boolean).map(r=>r);var Y=t=>{let r=null;for(let e of t.frames)r=e.gce?e.gce:r,"image"in e&&!("gce"in e)&&r!==null&&(e.gce=r)},N=(t,{signal:r})=>fetch(t,{signal:r}).then(e=>{var n;if(!((n=e.headers.get("Content-Type"))!=null&&n.includes("image/gif")))throw Error(`Wrong content type: "${e.headers.get("Content-Type")}"`);return e.arrayBuffer()}).then(e=>j(e)).then(e=>(Y(e),e)).then(e=>Promise.all([L(e),{width:e.lsd.width,height:e.lsd.height}])).then(([e,n])=>{let o=[],c=n.width*n.height*4,s=new Uint8ClampedArray(c);for(let a=0;a<e.length;++a){let i=e[a],d=e[a].disposalType===3?s.slice():null;if(o.push(ee(s,i,n)),e[a].disposalType===2)s=new Uint8ClampedArray(c);else if(e[a].disposalType===3){if(!d)throw Error("Disposal type 3 without previous frame");s=d}else s=o[a].slice()}return{...n,loaded:!0,delays:e.map(a=>a.delay),frames:o}}),ee=(t,r,e)=>{let{width:n,height:o,top:c,left:s}=r.dims,a=c*e.width+s;for(let i=0;i<o;i++)for(let d=0;d<n;d++){let u=i*n+d,l=r.pixels[u];if(l!==r.transparentIndex){let p=a+i*e.width+d,x=r.colorTable[l];t[p*4]=x[0],t[p*4+1]=x[1],t[p*4+2]=x[2],t[p*4+3]=l===r.transparentIndex?0:255}}return t};var A=new Map;self.addEventListener("message",t=>{let{type:r,src:e}=t.data||t;switch(r){case"parse":{if(!A.has(e)){let n=new AbortController,o={signal:n.signal};A.set(e,n),N(e,o).then(c=>{self.postMessage(Object.assign(c,{src:e}),c.frames.map(s=>s.buffer))}).catch(c=>{self.postMessage({src:e,error:c,loaded:!0})}).finally(()=>{A.delete(e)})}break}case"cancel":{A.has(e)&&(A.get(e).abort(),A.delete(e));break}default:break}});})();\n';
File without changes
File without changes
@@ -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>>;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import type { RemotionGifProps } from './props';
3
+ export declare const GifForDevelopment: import("react").ForwardRefExoticComponent<RemotionGifProps & import("react").RefAttributes<HTMLCanvasElement>>;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import type { RemotionGifProps } from './props';
3
+ export declare const GifForRendering: import("react").ForwardRefExoticComponent<RemotionGifProps & import("react").RefAttributes<HTMLCanvasElement>>;
@@ -0,0 +1,13 @@
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 {};
@@ -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>;
@@ -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,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,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,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,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 {};
@@ -0,0 +1,4 @@
1
+ export { getGifDurationInSeconds } from './get-gif-duration-in-seconds';
2
+ export { Gif } from './Gif';
3
+ export { preloadGif } from './preload-gif';
4
+ export { GifFillMode, RemotionGifProps } from './props';