@remotion/gif 4.0.0-prefetch.11 → 4.0.0-prefetch.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md 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 © 2022 [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
 
package/dist/Gif.d.ts CHANGED
File without changes
package/dist/Gif.js CHANGED
File without changes
File without changes
@@ -2,15 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GifForDevelopment = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
- const tools_1 = require("@react-gifs/tools");
6
- const lru_map_1 = require("lru_map");
7
5
  const react_1 = require("react");
6
+ const remotion_1 = require("remotion");
7
+ const canvas_1 = require("./canvas");
8
+ const gif_cache_1 = require("./gif-cache");
9
+ const is_cors_error_1 = require("./is-cors-error");
10
+ const react_tools_1 = require("./react-tools");
8
11
  const useCurrentGifIndex_1 = require("./useCurrentGifIndex");
9
- const cache = new lru_map_1.LRUMap(30);
10
12
  exports.GifForDevelopment = (0, react_1.forwardRef)(({ src, width, height, onError, onLoad, fit = 'fill', ...props }, ref) => {
11
13
  const resolvedSrc = new URL(src, window.location.origin).href;
12
14
  const [state, update] = (0, react_1.useState)(() => {
13
- const parsedGif = cache.get(resolvedSrc);
15
+ const parsedGif = gif_cache_1.gifCache.get(resolvedSrc);
14
16
  if (parsedGif === undefined) {
15
17
  return {
16
18
  delays: [],
@@ -21,22 +23,54 @@ exports.GifForDevelopment = (0, react_1.forwardRef)(({ src, width, height, onErr
21
23
  }
22
24
  return parsedGif;
23
25
  });
24
- // skip loading if frames exist
25
- (0, tools_1.useWorkerParser)(Boolean(state.frames.length) || resolvedSrc, (info) => {
26
- if ('error' in info) {
27
- if (onError) {
28
- onError(info.error);
26
+ const [error, setError] = (0, react_1.useState)(null);
27
+ const [id] = (0, react_1.useState)(() => (0, remotion_1.delayRender)(`Rendering <Gif/> with src="${resolvedSrc}"`));
28
+ const currentOnLoad = (0, react_1.useRef)(onLoad);
29
+ const currentOnError = (0, react_1.useRef)(onError);
30
+ currentOnLoad.current = onLoad;
31
+ currentOnError.current = onError;
32
+ (0, react_1.useEffect)(() => {
33
+ let done = false;
34
+ let aborted = false;
35
+ const { prom, cancel } = (0, react_tools_1.parseWithWorker)(resolvedSrc);
36
+ const newHandle = (0, remotion_1.delayRender)('Loading <Gif /> with src=' + resolvedSrc);
37
+ prom
38
+ .then((parsed) => {
39
+ var _a;
40
+ (_a = currentOnLoad.current) === null || _a === void 0 ? void 0 : _a.call(currentOnLoad, parsed);
41
+ update(parsed);
42
+ gif_cache_1.gifCache.set(resolvedSrc, parsed);
43
+ done = true;
44
+ (0, remotion_1.continueRender)(newHandle);
45
+ (0, remotion_1.continueRender)(id);
46
+ })
47
+ .catch((err) => {
48
+ if (aborted) {
49
+ (0, remotion_1.continueRender)(newHandle);
50
+ return;
51
+ }
52
+ if (currentOnError.current) {
53
+ currentOnError.current(err);
29
54
  }
30
55
  else {
31
- console.error('Error loading GIF:', info.error, 'Handle the event using the onError() prop to make this message disappear.');
56
+ setError(err);
32
57
  }
58
+ });
59
+ return () => {
60
+ if (!done) {
61
+ aborted = true;
62
+ cancel();
63
+ }
64
+ (0, remotion_1.continueRender)(newHandle);
65
+ };
66
+ }, [id, resolvedSrc]);
67
+ if (error) {
68
+ console.error(error.stack);
69
+ if ((0, is_cors_error_1.isCorsError)(error)) {
70
+ throw new Error(`Failed to render GIF with source ${src}: "${error.message}". You must enable CORS for this URL.`);
33
71
  }
34
- else {
35
- onLoad === null || onLoad === void 0 ? void 0 : onLoad(info);
36
- cache.set(resolvedSrc, info);
37
- update(info);
38
- }
39
- });
72
+ throw new Error(`Failed to render GIF with source ${src}: "${error.message}".`);
73
+ }
40
74
  const index = (0, useCurrentGifIndex_1.useCurrentGifIndex)(state.delays);
41
- return ((0, jsx_runtime_1.jsx)(tools_1.Canvas, { fit: fit, index: index, frames: state.frames, width: width !== null && width !== void 0 ? width : state.width, height: height !== null && height !== void 0 ? height : state.height, ...props, ref: ref }));
75
+ return ((0, jsx_runtime_1.jsx)(canvas_1.Canvas, { fit: fit, index: index, frames: state.frames, width: width, height: height, ...props, ref: ref }));
42
76
  });
File without changes
@@ -2,37 +2,69 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GifForRendering = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
- const tools_1 = require("@react-gifs/tools");
6
5
  const react_1 = require("react");
7
6
  const remotion_1 = require("remotion");
7
+ const canvas_1 = require("./canvas");
8
+ const gif_cache_1 = require("./gif-cache");
8
9
  const is_cors_error_1 = require("./is-cors-error");
10
+ const react_tools_1 = require("./react-tools");
9
11
  const useCurrentGifIndex_1 = require("./useCurrentGifIndex");
10
12
  exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad, onError, fit = 'fill', ...props }, ref) => {
11
13
  const resolvedSrc = new URL(src, window.location.origin).href;
12
- const [state, update] = (0, react_1.useState)({
13
- delays: [],
14
- frames: [],
15
- width: 0,
16
- height: 0,
14
+ const [state, update] = (0, react_1.useState)(() => {
15
+ const parsedGif = gif_cache_1.gifCache.get(resolvedSrc);
16
+ if (parsedGif === undefined) {
17
+ return {
18
+ delays: [],
19
+ frames: [],
20
+ width: 0,
21
+ height: 0,
22
+ };
23
+ }
24
+ return parsedGif;
17
25
  });
18
26
  const [error, setError] = (0, react_1.useState)(null);
19
27
  const [id] = (0, react_1.useState)(() => (0, remotion_1.delayRender)(`Rendering <Gif/> with src="${resolvedSrc}"`));
20
28
  const index = (0, useCurrentGifIndex_1.useCurrentGifIndex)(state.delays);
21
- (0, tools_1.useParser)(resolvedSrc, (info) => {
22
- if ('error' in info) {
23
- if (onError) {
24
- onError(info.error);
29
+ const currentOnLoad = (0, react_1.useRef)(onLoad);
30
+ const currentOnError = (0, react_1.useRef)(onError);
31
+ currentOnLoad.current = onLoad;
32
+ currentOnError.current = onError;
33
+ (0, react_1.useEffect)(() => {
34
+ const controller = new AbortController();
35
+ let done = false;
36
+ let aborted = false;
37
+ const newHandle = (0, remotion_1.delayRender)('Loading <Gif /> with src=' + resolvedSrc);
38
+ (0, react_tools_1.parseGif)({ controller, src: resolvedSrc })
39
+ .then((parsed) => {
40
+ var _a;
41
+ (_a = currentOnLoad.current) === null || _a === void 0 ? void 0 : _a.call(currentOnLoad, parsed);
42
+ update(parsed);
43
+ gif_cache_1.gifCache.set(resolvedSrc, parsed);
44
+ done = true;
45
+ (0, remotion_1.continueRender)(newHandle);
46
+ (0, remotion_1.continueRender)(id);
47
+ })
48
+ .catch((err) => {
49
+ if (aborted) {
50
+ (0, remotion_1.continueRender)(newHandle);
51
+ return;
52
+ }
53
+ if (currentOnError.current) {
54
+ currentOnError.current(err);
25
55
  }
26
56
  else {
27
- setError(info.error);
57
+ setError(err);
28
58
  }
29
- }
30
- else {
31
- onLoad === null || onLoad === void 0 ? void 0 : onLoad(info);
32
- update(info);
33
- }
34
- (0, remotion_1.continueRender)(id);
35
- });
59
+ });
60
+ return () => {
61
+ if (!done) {
62
+ aborted = true;
63
+ controller.abort();
64
+ }
65
+ (0, remotion_1.continueRender)(newHandle);
66
+ };
67
+ }, [id, resolvedSrc]);
36
68
  if (error) {
37
69
  console.error(error.stack);
38
70
  if ((0, is_cors_error_1.isCorsError)(error)) {
@@ -40,5 +72,5 @@ exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad,
40
72
  }
41
73
  throw new Error(`Failed to render GIF with source ${src}: "${error.message}". Render with --log=verbose to see the full stack.`);
42
74
  }
43
- return ((0, jsx_runtime_1.jsx)(tools_1.Canvas, { fit: fit, index: index, frames: state.frames, width: width !== null && width !== void 0 ? width : state.width, height: height !== null && height !== void 0 ? height : state.height, ...props, ref: ref }));
75
+ return ((0, jsx_runtime_1.jsx)(canvas_1.Canvas, { fit: fit, index: index, frames: state.frames, width: width, height: height, ...props, ref: ref }));
44
76
  });
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ import type { GifFillMode } from './props';
3
+ declare type Props = {
4
+ index: number;
5
+ frames: ImageData[];
6
+ width?: number;
7
+ height?: number;
8
+ fit: GifFillMode;
9
+ className?: string;
10
+ style?: React.CSSProperties;
11
+ };
12
+ export declare const Canvas: import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<unknown>>;
13
+ export {};
package/dist/canvas.js ADDED
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Canvas = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const use_element_size_1 = require("./use-element-size");
7
+ const calcArgs = (fit, frameSize, canvasSize) => {
8
+ switch (fit) {
9
+ case 'fill': {
10
+ return [
11
+ 0,
12
+ 0,
13
+ frameSize.width,
14
+ frameSize.height,
15
+ 0,
16
+ 0,
17
+ canvasSize.width,
18
+ canvasSize.height,
19
+ ];
20
+ }
21
+ case 'contain': {
22
+ const ratio = Math.min(canvasSize.width / frameSize.width, canvasSize.height / frameSize.height);
23
+ const centerX = (canvasSize.width - frameSize.width * ratio) / 2;
24
+ const centerY = (canvasSize.height - frameSize.height * ratio) / 2;
25
+ return [
26
+ 0,
27
+ 0,
28
+ frameSize.width,
29
+ frameSize.height,
30
+ centerX,
31
+ centerY,
32
+ frameSize.width * ratio,
33
+ frameSize.height * ratio,
34
+ ];
35
+ }
36
+ case 'cover': {
37
+ const ratio = Math.max(canvasSize.width / frameSize.width, canvasSize.height / frameSize.height);
38
+ const centerX = (canvasSize.width - frameSize.width * ratio) / 2;
39
+ const centerY = (canvasSize.height - frameSize.height * ratio) / 2;
40
+ return [
41
+ 0,
42
+ 0,
43
+ frameSize.width,
44
+ frameSize.height,
45
+ centerX,
46
+ centerY,
47
+ frameSize.width * ratio,
48
+ frameSize.height * ratio,
49
+ ];
50
+ }
51
+ default:
52
+ throw new Error('Unknown fit: ' + fit);
53
+ }
54
+ };
55
+ const makeCanvas = () => {
56
+ const canvas = document.createElement('canvas');
57
+ const ctx = canvas.getContext('2d');
58
+ canvas.width = 0;
59
+ canvas.height = 0;
60
+ return ctx;
61
+ };
62
+ exports.Canvas = (0, react_1.forwardRef)(({ index, frames, width, height, fit, className, style }, ref) => {
63
+ const canvasRef = (0, react_1.useRef)(null);
64
+ const [tempCtx] = (0, react_1.useState)(() => {
65
+ return makeCanvas();
66
+ });
67
+ const size = (0, use_element_size_1.useElementSize)(canvasRef);
68
+ (0, react_1.useImperativeHandle)(ref, () => {
69
+ return canvasRef.current;
70
+ }, []);
71
+ (0, react_1.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 ((0, jsx_runtime_1.jsx)("canvas", { ref: canvasRef, className: className, style: style, width: width !== null && width !== void 0 ? width : size === null || size === void 0 ? void 0 : size.width, height: height !== null && height !== void 0 ? height : size === null || size === void 0 ? void 0 : size.height }));
93
+ });
@@ -0,0 +1 @@
1
+ export declare const getGifDurationInSeconds: (src: string) => Promise<number>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGifDurationInSeconds = void 0;
4
+ const remotion_1 = require("remotion");
5
+ const gif_cache_1 = require("./gif-cache");
6
+ const react_tools_1 = require("./react-tools");
7
+ const calcDuration = (parsed) => {
8
+ return (parsed.delays.reduce((sum, delay) => sum + delay, 0) / 1000);
9
+ };
10
+ const getGifDurationInSeconds = async (src) => {
11
+ const resolvedSrc = new URL(src, window.location.origin).href;
12
+ const inCache = gif_cache_1.gifCache.get(resolvedSrc);
13
+ if (inCache) {
14
+ return calcDuration(inCache);
15
+ }
16
+ if (remotion_1.Internals.getRemotionEnvironment() === 'rendering') {
17
+ const renderingParsed = (0, react_tools_1.parseWithWorker)(resolvedSrc);
18
+ const resolved = await renderingParsed.prom;
19
+ gif_cache_1.gifCache.set(resolvedSrc, resolved);
20
+ return calcDuration(resolved);
21
+ }
22
+ const parsed = await (0, react_tools_1.parseGif)({
23
+ src: resolvedSrc,
24
+ controller: new AbortController(),
25
+ });
26
+ gif_cache_1.gifCache.set(resolvedSrc, parsed);
27
+ return calcDuration(parsed);
28
+ };
29
+ exports.getGifDurationInSeconds = getGifDurationInSeconds;
@@ -0,0 +1,3 @@
1
+ import { LRUMap } from 'lru_map';
2
+ import type { GifState } from './props';
3
+ export declare const gifCache: LRUMap<string, GifState>;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gifCache = void 0;
4
+ const lru_map_1 = require("lru_map");
5
+ exports.gifCache = new lru_map_1.LRUMap(30);
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export * from './Gif';
2
- export * from './props';
1
+ export { getGifDurationInSeconds } from './get-gif-duration-in-seconds';
2
+ export { Gif } from './Gif';
3
+ export { GifFillMode, RemotionGifProps } from './props';
package/dist/index.js CHANGED
@@ -1,18 +1,7 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Gif"), exports);
18
- __exportStar(require("./props"), exports);
3
+ exports.Gif = exports.getGifDurationInSeconds = void 0;
4
+ var get_gif_duration_in_seconds_1 = require("./get-gif-duration-in-seconds");
5
+ Object.defineProperty(exports, "getGifDurationInSeconds", { enumerable: true, get: function () { return get_gif_duration_in_seconds_1.getGifDurationInSeconds; } });
6
+ var Gif_1 = require("./Gif");
7
+ Object.defineProperty(exports, "Gif", { enumerable: true, get: function () { return Gif_1.Gif; } });
File without changes
File without changes
@@ -0,0 +1,18 @@
1
+ import type { GifState } from './props';
2
+ export declare const parse: (src: string, { signal, }: {
3
+ signal: AbortController['signal'];
4
+ }) => Promise<{
5
+ loaded: boolean;
6
+ delays: number[];
7
+ frames: Uint8ClampedArray[];
8
+ width: number;
9
+ height: number;
10
+ }>;
11
+ declare type ParserCallbackArgs = {
12
+ width: number;
13
+ height: number;
14
+ delays: number[];
15
+ frames: Uint8ClampedArray[];
16
+ };
17
+ export declare const generate: (info: ParserCallbackArgs) => GifState;
18
+ export {};
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generate = exports.parse = void 0;
4
+ const gifuct_js_1 = require("gifuct-js");
5
+ const validateAndFix = (gif) => {
6
+ let currentGce = null;
7
+ for (const frame of gif.frames) {
8
+ currentGce = frame.gce ? frame.gce : currentGce;
9
+ // fix loosing graphic control extension for same frames
10
+ if ('image' in frame && !('gce' in frame) && currentGce !== null) {
11
+ frame.gce = currentGce;
12
+ }
13
+ }
14
+ };
15
+ const parse = (src, { signal, }) => fetch(src, { signal })
16
+ .then((resp) => {
17
+ var _a;
18
+ if (!((_a = resp.headers.get('Content-Type')) === null || _a === void 0 ? void 0 : _a.includes('image/gif')))
19
+ throw Error(`Wrong content type: "${resp.headers.get('Content-Type')}"`);
20
+ return resp.arrayBuffer();
21
+ })
22
+ .then((buffer) => (0, gifuct_js_1.parseGIF)(buffer))
23
+ .then((gif) => {
24
+ validateAndFix(gif);
25
+ return gif;
26
+ })
27
+ .then((gif) => Promise.all([
28
+ (0, gifuct_js_1.decompressFrames)(gif, false),
29
+ { width: gif.lsd.width, height: gif.lsd.height },
30
+ ]))
31
+ .then(([frames, options]) => {
32
+ const readyFrames = [];
33
+ const size = options.width * options.height * 4;
34
+ for (let i = 0; i < frames.length; ++i) {
35
+ 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));
40
+ }
41
+ return {
42
+ ...options,
43
+ loaded: true,
44
+ delays: frames.map((frame) => frame.delay),
45
+ frames: readyFrames,
46
+ };
47
+ });
48
+ exports.parse = parse;
49
+ const putPixels = (typedArray, frame, gifSize) => {
50
+ const { width, height, top: dy, left: dx } = frame.dims;
51
+ const offset = dy * gifSize.width + dx;
52
+ for (let y = 0; y < height; y++) {
53
+ for (let x = 0; x < width; x++) {
54
+ const pPos = y * width + x;
55
+ const colorIndex = frame.pixels[pPos];
56
+ if (colorIndex !== frame.transparentIndex) {
57
+ const taPos = offset + y * gifSize.width + x;
58
+ const color = frame.colorTable[colorIndex] || [0, 0, 0];
59
+ typedArray[taPos * 4] = color[0];
60
+ typedArray[taPos * 4 + 1] = color[1];
61
+ typedArray[taPos * 4 + 2] = color[2];
62
+ typedArray[taPos * 4 + 3] = 255;
63
+ }
64
+ }
65
+ }
66
+ return typedArray;
67
+ };
68
+ const generate = (info) => {
69
+ return {
70
+ ...info,
71
+ frames: info.frames.map((buffer) => {
72
+ const image = new ImageData(info.width, info.height);
73
+ image.data.set(new Uint8ClampedArray(buffer));
74
+ return image;
75
+ }),
76
+ };
77
+ };
78
+ exports.generate = generate;
package/dist/props.d.ts CHANGED
@@ -4,14 +4,13 @@ export declare type RemotionGifProps = {
4
4
  width?: number;
5
5
  height?: number;
6
6
  onLoad?: (info: {
7
- loaded: true;
8
7
  width: number;
9
8
  height: number;
10
9
  delays: number[];
11
10
  frames: ImageData[];
12
11
  }) => void;
13
12
  onError?: (error: Error) => void;
14
- fit?: 'contain' | 'fill' | 'cover';
13
+ fit?: GifFillMode;
15
14
  style?: React.CSSProperties;
16
15
  };
17
16
  export declare type GifState = {
@@ -20,3 +19,4 @@ export declare type GifState = {
20
19
  width: number;
21
20
  height: number;
22
21
  };
22
+ export declare type GifFillMode = 'contain' | 'cover' | 'fill';
package/dist/props.js CHANGED
File without changes
@@ -0,0 +1,9 @@
1
+ import type { GifState } from './props';
2
+ export declare const parseGif: ({ src, controller, }: {
3
+ src: string;
4
+ controller: AbortController;
5
+ }) => Promise<GifState>;
6
+ export declare const parseWithWorker: (src: string) => {
7
+ prom: Promise<GifState>;
8
+ cancel: () => void;
9
+ };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseWithWorker = exports.parseGif = void 0;
4
+ const parse_generate_1 = require("./parse-generate");
5
+ const worker_1 = require("./worker");
6
+ const parseGif = async ({ src, controller, }) => {
7
+ const raw = await (0, parse_generate_1.parse)(src, { signal: controller.signal });
8
+ return (0, parse_generate_1.generate)(raw);
9
+ };
10
+ exports.parseGif = parseGif;
11
+ const parseWithWorker = (src) => {
12
+ const worker = (0, worker_1.makeWorker)();
13
+ let handler = null;
14
+ const prom = new Promise((resolve, reject) => {
15
+ handler = (e) => {
16
+ const message = e.data || e;
17
+ if (message.src === src) {
18
+ if (message.error) {
19
+ reject(new Error(message.error));
20
+ }
21
+ else {
22
+ const data = message.error ? message : (0, parse_generate_1.generate)(message);
23
+ resolve(data);
24
+ }
25
+ }
26
+ };
27
+ worker.addEventListener('message', handler);
28
+ worker.postMessage({ src, type: 'parse' });
29
+ });
30
+ return {
31
+ prom,
32
+ cancel: () => {
33
+ worker.postMessage({ src, type: 'cancel' });
34
+ worker.removeEventListener('message', handler);
35
+ worker.terminate();
36
+ },
37
+ };
38
+ };
39
+ exports.parseWithWorker = parseWithWorker;
@@ -0,0 +1,6 @@
1
+ export declare type Size = {
2
+ width: number;
3
+ height: number;
4
+ };
5
+ export declare const updateAllElementsSizes: () => void;
6
+ export declare const useElementSize: (ref: React.RefObject<HTMLElement>) => Size | null;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useElementSize = exports.updateAllElementsSizes = void 0;
4
+ const react_1 = require("react");
5
+ let elementSizeHooks = [];
6
+ const updateAllElementsSizes = () => {
7
+ for (const listener of elementSizeHooks) {
8
+ listener();
9
+ }
10
+ };
11
+ exports.updateAllElementsSizes = updateAllElementsSizes;
12
+ const useElementSize = (ref) => {
13
+ const [size, setSize] = (0, react_1.useState)(null);
14
+ const observer = (0, react_1.useMemo)(() => {
15
+ if (typeof ResizeObserver === 'undefined') {
16
+ return null;
17
+ }
18
+ return new ResizeObserver((entries) => {
19
+ // The contentRect returns the width without any `scale()`'s being applied. The height is wrong
20
+ const { contentRect } = entries[0];
21
+ // The clientRect returns the size with `scale()` being applied.
22
+ const newSize = entries[0].target.getClientRects();
23
+ if (!newSize || !newSize[0]) {
24
+ setSize(null);
25
+ return;
26
+ }
27
+ const probableCssParentScale = newSize[0].width / contentRect.width;
28
+ const width = newSize[0].width * (1 / probableCssParentScale);
29
+ const height = newSize[0].height * (1 / probableCssParentScale);
30
+ setSize({
31
+ width,
32
+ height,
33
+ });
34
+ });
35
+ }, []);
36
+ const updateSize = (0, react_1.useCallback)(() => {
37
+ if (!ref.current) {
38
+ return;
39
+ }
40
+ const rect = ref.current.getClientRects();
41
+ if (!rect[0]) {
42
+ setSize(null);
43
+ return;
44
+ }
45
+ setSize({
46
+ width: rect[0].width,
47
+ height: rect[0].height,
48
+ });
49
+ }, [ref]);
50
+ (0, react_1.useEffect)(() => {
51
+ if (!observer) {
52
+ return;
53
+ }
54
+ updateSize();
55
+ const { current } = ref;
56
+ if (ref.current) {
57
+ observer.observe(ref.current);
58
+ }
59
+ return () => {
60
+ if (current) {
61
+ observer.unobserve(current);
62
+ }
63
+ };
64
+ }, [observer, ref, updateSize]);
65
+ (0, react_1.useEffect)(() => {
66
+ elementSizeHooks.push(updateSize);
67
+ return () => {
68
+ elementSizeHooks = elementSizeHooks.filter((e) => e !== updateSize);
69
+ };
70
+ }, [updateSize]);
71
+ return size;
72
+ };
73
+ exports.useElementSize = useElementSize;
@@ -1,2 +1 @@
1
- declare function useCurrentGifIndex(delays: number[]): number;
2
- export { useCurrentGifIndex };
1
+ export declare function useCurrentGifIndex(delays: number[]): number;
File without changes
@@ -0,0 +1 @@
1
+ export declare const makeWorker: () => Worker;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeWorker = void 0;
4
+ const source_1 = require("./source");
5
+ const makeWorker = () => {
6
+ const blob = new Blob([source_1.src], { type: 'application/javascript' });
7
+ const url = URL.createObjectURL(blob);
8
+ const worker = new Worker(url);
9
+ URL.revokeObjectURL(url);
10
+ return worker;
11
+ };
12
+ exports.makeWorker = makeWorker;
@@ -0,0 +1 @@
1
+ export declare const src = "function e(e){const r={exports:{}};return e(r,r.exports),r.exports}const r=e(((e,r)=> {Object.defineProperty(r,\"__esModule\",{value:!0}),r.loop=r.conditional=r.parse=void 0;r.parse=function e(r,t){const n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}; const a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:n;if(Array.isArray(t))t.forEach(((t)=> {return e(r,t,n,a)}));else if(typeof t===\"function\")t(r,n,a,e);else{const i=Object.keys(t)[0];Array.isArray(t[i])?(a[i]={},e(r,t[i],n,a[i])):a[i]=t[i](r,n,a,e)}return n};r.conditional=function(e,r){return function(t,n,a,i){r(t,n,a)&&i(t,e,n,a)}};r.loop=function(e,r){return function(t,n,a,i){for(var o=[];r(t,n,a);){const s={};i(t,e,n,s),o.push(s)}return o}}})); const t=e(((e,r)=> {Object.defineProperty(r,\"__esModule\",{value:!0}),r.readBits=r.readArray=r.readUnsigned=r.readString=r.peekBytes=r.readBytes=r.peekByte=r.readByte=r.buildStream=void 0;r.buildStream=function(e){return{data:e,pos:0}};const t=function(){return function(e){return e.data[e.pos++]}};r.readByte=t;r.peekByte=function(){const e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return function(r){return r.data[r.pos+e]}};const n=function(e){return function(r){return r.data.subarray(r.pos,r.pos+=e)}};r.readBytes=n;r.peekBytes=function(e){return function(r){return r.data.subarray(r.pos,r.pos+e)}};r.readString=function(e){return function(r){return Array.from(n(e)(r)).map(((e)=> {return String.fromCharCode(e)})).join(\"\")}};r.readUnsigned=function(e){return function(r){const t=n(2)(r);return e?(t[1]<<8)+t[0]:(t[0]<<8)+t[1]}};r.readArray=function(e,r){return function(t,a,i){for(var o=typeof r===\"function\"?r(t,a,i):r,s=n(e),d=new Array(o),c=0;c<o;c++)d[c]=s(t);return d}};r.readBits=function(e){return function(r){for(var t=function(e){return e.data[e.pos++]}(r),n=new Array(8),a=0;a<8;a++)n[7-a]=Boolean(t&1<<a);return Object.keys(e).reduce(((r,t)=> {const a=e[t];return a.length?r[t]=function(e,r,t){for(var n=0,a=0;a<t;a++)n+=e[r+a]&&2**(t-a-1);return n}(n,a.index,a.length):r[t]=n[a.index],r}),{})}}})); const n=e(((e,n)=> {Object.defineProperty(n,\"__esModule\",{value:!0}),n.default=void 0;const a={blocks(e){for(var r=[],n=e.data.length,a=0,i=(0,t.readByte)()(e);i!==0;i=(0,t.readByte)()(e)){if(e.pos+i>=n){const o=n-e.pos;r.push((0,t.readBytes)(o)(e)),a+=o;break}r.push((0,t.readBytes)(i)(e)),a+=i}for(var s=new Uint8Array(a),d=0,c=0;c<r.length;c++)s.set(r[c],d),d+=r[c].length;return s}}; const i=(0,r.conditional)({gce:[{codes:(0,t.readBytes)(2)},{byteSize:(0,t.readByte)()},{extras:(0,t.readBits)({future:{index:0,length:3},disposal:{index:3,length:3},userInput:{index:6},transparentColorGiven:{index:7}})},{delay:(0,t.readUnsigned)(!0)},{transparentColorIndex:(0,t.readByte)()},{terminator:(0,t.readByte)()}]},((e)=> {const r=(0,t.peekBytes)(2)(e);return r[0]===33&&r[1]===249})); const o=(0,r.conditional)({image:[{code:(0,t.readByte)()},{descriptor:[{left:(0,t.readUnsigned)(!0)},{top:(0,t.readUnsigned)(!0)},{width:(0,t.readUnsigned)(!0)},{height:(0,t.readUnsigned)(!0)},{lct:(0,t.readBits)({exists:{index:0},interlaced:{index:1},sort:{index:2},future:{index:3,length:2},size:{index:5,length:3}})}]},(0,r.conditional)({lct:(0,t.readArray)(3,((e,r,t)=> {return 2**(t.descriptor.lct.size+1)}))},((e,r,t)=> {return t.descriptor.lct.exists})),{data:[{minCodeSize:(0,t.readByte)()},a]}]},((e)=> {return (0,t.peekByte)()(e)===44})); const s=(0,r.conditional)({text:[{codes:(0,t.readBytes)(2)},{blockSize:(0,t.readByte)()},{preData(e,r,n){return(0,t.readBytes)(n.text.blockSize)(e)}},a]},((e)=> {const r=(0,t.peekBytes)(2)(e);return r[0]===33&&r[1]===1})); const d=(0,r.conditional)({application:[{codes:(0,t.readBytes)(2)},{blockSize:(0,t.readByte)()},{id(e,r,n){return(0,t.readString)(n.blockSize)(e)}},a]},((e)=> {const r=(0,t.peekBytes)(2)(e);return r[0]===33&&r[1]===255})); const c=(0,r.conditional)({comment:[{codes:(0,t.readBytes)(2)},a]},((e)=> {const r=(0,t.peekBytes)(2)(e);return r[0]===33&&r[1]===254})); const u=[{header:[{signature:(0,t.readString)(3)},{version:(0,t.readString)(3)}]},{lsd:[{width:(0,t.readUnsigned)(!0)},{height:(0,t.readUnsigned)(!0)},{gct:(0,t.readBits)({exists:{index:0},resolution:{index:1,length:3},sort:{index:4},size:{index:5,length:3}})},{backgroundColorIndex:(0,t.readByte)()},{pixelAspectRatio:(0,t.readByte)()}]},(0,r.conditional)({gct:(0,t.readArray)(3,((e,r)=> {return 2**(r.lsd.gct.size+1)}))},((e,r)=> {return r.lsd.gct.exists})),{frames:(0,r.loop)([i,d,c,o,s],((e)=> {const r=(0,t.peekByte)()(e);return r===33||r===44}))}];n.default=u})); const a=e(((e,r)=> {Object.defineProperty(r,\"__esModule\",{value:!0}),r.deinterlace=void 0;r.deinterlace=function(e,r){for(var t=new Array(e.length),n=e.length/r,a=function(n,a){const i=e.slice(a*r,(a+1)*r);t.splice.apply(t,[n*r,r].concat(i))},i=[0,4,2,1],o=[8,8,4,2],s=0,d=0;d<4;d++)for(let c=i[d];c<n;c+=o[d])a(c,s),s++;return t}})); const i=e(((e,r)=> {Object.defineProperty(r,\"__esModule\",{value:!0}),r.lzw=void 0;r.lzw=function(e,r,t){let n; let a; let i; let o; let s; let d; let c; let u; let l; let f; let p; let g; let y; let h; let v; let m; const x=4096; const B=t; const w=new Array(t); const b=new Array(x); const k=new Array(x); const A=new Array(4097);for(s=(a=1<<(f=e))+1,n=a+2,c=-1,i=(1<<(o=f+1))-1,u=0;u<a;u++)b[u]=0,k[u]=u;for(p=g=y=h=v=m=0,l=0;l<B;){if(h===0){if(g<o){p+=r[m]<<g,g+=8,m++;continue}if(u=p&i,p>>=o,g-=o,u>n||u==s)break;if(u==a){i=(1<<(o=f+1))-1,n=a+2,c=-1;continue}if(c==-1){A[h++]=k[u],c=u,y=u;continue}for(d=u,u==n&&(A[h++]=y,u=c);u>a;)A[h++]=k[u],u=b[u];y=255&k[u],A[h++]=y,n<x&&(b[n]=c,k[n]=y,(++n&i)==0&&n<x&&(o++,i+=n)),c=d}h--,w[v++]=A[h],l++}for(l=v;l<B;l++)w[l]=0;return w}})); const o=e(((e,o)=> {Object.defineProperty(o,\"__esModule\",{value:!0}),o.decompressFrames=o.decompressFrame=o.parseGIF=void 0;let s; const d=(s=n)&&s.__esModule?s:{default:s};o.parseGIF=function(e){const n=new Uint8Array(e);return(0,r.parse)((0,t.buildStream)(n),d.default)};const c=function(e,r,t){if(e.image){const n=e.image; const o=n.descriptor.width*n.descriptor.height; let s=(0,i.lzw)(n.data.minCodeSize,n.data.blocks,o);n.descriptor.lct.interlaced&&(s=(0,a.deinterlace)(s,n.descriptor.width));const d={pixels:s,dims:{top:e.image.descriptor.top,left:e.image.descriptor.left,width:e.image.descriptor.width,height:e.image.descriptor.height}};return n.descriptor.lct&&n.descriptor.lct.exists?d.colorTable=n.lct:d.colorTable=r,e.gce&&(d.delay=10*(e.gce.delay||10),d.disposalType=e.gce.extras.disposal,e.gce.extras.transparentColorGiven&&(d.transparentIndex=e.gce.transparentColorIndex)),t&&(d.patch=function(e){for(var r=e.pixels.length,t=new Uint8ClampedArray(4*r),n=0;n<r;n++){const a=4*n; const i=e.pixels[n]; const o=e.colorTable[i]||[0,0,0];t[a]=o[0],t[a+1]=o[1],t[a+2]=o[2],t[a+3]=i!==e.transparentIndex?255:0}return t}(d)),d}console.warn(\"gif frame does not have associated image.\")};o.decompressFrame=c;o.decompressFrames=function(e,r){return e.frames.filter(((e)=> {return e.image})).map(((t)=> {return c(t,e.gct,r)}))}}));const s=(e,r,t)=>{const{width:n,height:a,top:i,left:o}=r.dims; const s=i*t.width+o;for(let i=0;i<a;i++)for(let a=0;a<n;a++){const o=i*n+a; const d=r.pixels[o];if(d!==r.transparentIndex){const n=s+i*t.width+a; const o=r.colorTable[d]||[0,0,0];e[4*n]=o[0],e[4*n+1]=o[1],e[4*n+2]=o[2],e[4*n+3]=255}}return e}; const d=new Map;self.addEventListener(\"message\",(e=>{const{type:r,src:t}=e.data||e;switch(r){case\"parse\":if(!d.has(t)){const e=new AbortController; const r={signal:e.signal};d.set(t,e),((e,{signal:r})=>fetch(e,{signal:r}).then((e=>{if(!e.headers.get(\"Content-Type\").includes(\"image/gif\"))throw Error(`Wrong content type: \"${e.headers.get(\"Content-Type\")}\"`);return e.arrayBuffer()})).then((e=>o.parseGIF(e))).then((e=>((e=>{let r=null;for(const t of e.frames)r=t.gce?t.gce:r,\"image\"in t&&!(\"gce\"in t)&&(t.gce=r)})(e),e))).then((e=>Promise.all([o.decompressFrames(e,!1),{width:e.lsd.width,height:e.lsd.height}]))).then((([e,r])=>{const t=[]; const n=r.width*r.height*4;for(let a=0;a<e.length;++a){const i=e[a]; const o=a===0||e[a-1].disposalType===2?new Uint8ClampedArray(n):t[a-1].slice();t.push(s(o,i,r))}return{...r,loaded:!0,delays:e.map((e=>e.delay)),frames:t}})))(t,r).then((e=>{self.postMessage(Object.assign(e,{src:t}),e.frames.map((e=>e.buffer)))})).catch((e=>{self.postMessage({src:t,error:e,loaded:!0})})).finally((()=>{d.delete(t)}))}break;case\"cancel\":if(d.has(t)){d.get(t).abort(),d.delete(t)}}}));";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.src = void 0;
4
+ // Clone react-tools/gifs and then run npm run build. Make sure to escape the `` characters
5
+ exports.src = `function e(e){const r={exports:{}};return e(r,r.exports),r.exports}const r=e(((e,r)=> {Object.defineProperty(r,"__esModule",{value:!0}),r.loop=r.conditional=r.parse=void 0;r.parse=function e(r,t){const n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}; const a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:n;if(Array.isArray(t))t.forEach(((t)=> {return e(r,t,n,a)}));else if(typeof t==="function")t(r,n,a,e);else{const i=Object.keys(t)[0];Array.isArray(t[i])?(a[i]={},e(r,t[i],n,a[i])):a[i]=t[i](r,n,a,e)}return n};r.conditional=function(e,r){return function(t,n,a,i){r(t,n,a)&&i(t,e,n,a)}};r.loop=function(e,r){return function(t,n,a,i){for(var o=[];r(t,n,a);){const s={};i(t,e,n,s),o.push(s)}return o}}})); const t=e(((e,r)=> {Object.defineProperty(r,"__esModule",{value:!0}),r.readBits=r.readArray=r.readUnsigned=r.readString=r.peekBytes=r.readBytes=r.peekByte=r.readByte=r.buildStream=void 0;r.buildStream=function(e){return{data:e,pos:0}};const t=function(){return function(e){return e.data[e.pos++]}};r.readByte=t;r.peekByte=function(){const e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return function(r){return r.data[r.pos+e]}};const n=function(e){return function(r){return r.data.subarray(r.pos,r.pos+=e)}};r.readBytes=n;r.peekBytes=function(e){return function(r){return r.data.subarray(r.pos,r.pos+e)}};r.readString=function(e){return function(r){return Array.from(n(e)(r)).map(((e)=> {return String.fromCharCode(e)})).join("")}};r.readUnsigned=function(e){return function(r){const t=n(2)(r);return e?(t[1]<<8)+t[0]:(t[0]<<8)+t[1]}};r.readArray=function(e,r){return function(t,a,i){for(var o=typeof r==="function"?r(t,a,i):r,s=n(e),d=new Array(o),c=0;c<o;c++)d[c]=s(t);return d}};r.readBits=function(e){return function(r){for(var t=function(e){return e.data[e.pos++]}(r),n=new Array(8),a=0;a<8;a++)n[7-a]=Boolean(t&1<<a);return Object.keys(e).reduce(((r,t)=> {const a=e[t];return a.length?r[t]=function(e,r,t){for(var n=0,a=0;a<t;a++)n+=e[r+a]&&2**(t-a-1);return n}(n,a.index,a.length):r[t]=n[a.index],r}),{})}}})); const n=e(((e,n)=> {Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;const a={blocks(e){for(var r=[],n=e.data.length,a=0,i=(0,t.readByte)()(e);i!==0;i=(0,t.readByte)()(e)){if(e.pos+i>=n){const o=n-e.pos;r.push((0,t.readBytes)(o)(e)),a+=o;break}r.push((0,t.readBytes)(i)(e)),a+=i}for(var s=new Uint8Array(a),d=0,c=0;c<r.length;c++)s.set(r[c],d),d+=r[c].length;return s}}; const i=(0,r.conditional)({gce:[{codes:(0,t.readBytes)(2)},{byteSize:(0,t.readByte)()},{extras:(0,t.readBits)({future:{index:0,length:3},disposal:{index:3,length:3},userInput:{index:6},transparentColorGiven:{index:7}})},{delay:(0,t.readUnsigned)(!0)},{transparentColorIndex:(0,t.readByte)()},{terminator:(0,t.readByte)()}]},((e)=> {const r=(0,t.peekBytes)(2)(e);return r[0]===33&&r[1]===249})); const o=(0,r.conditional)({image:[{code:(0,t.readByte)()},{descriptor:[{left:(0,t.readUnsigned)(!0)},{top:(0,t.readUnsigned)(!0)},{width:(0,t.readUnsigned)(!0)},{height:(0,t.readUnsigned)(!0)},{lct:(0,t.readBits)({exists:{index:0},interlaced:{index:1},sort:{index:2},future:{index:3,length:2},size:{index:5,length:3}})}]},(0,r.conditional)({lct:(0,t.readArray)(3,((e,r,t)=> {return 2**(t.descriptor.lct.size+1)}))},((e,r,t)=> {return t.descriptor.lct.exists})),{data:[{minCodeSize:(0,t.readByte)()},a]}]},((e)=> {return (0,t.peekByte)()(e)===44})); const s=(0,r.conditional)({text:[{codes:(0,t.readBytes)(2)},{blockSize:(0,t.readByte)()},{preData(e,r,n){return(0,t.readBytes)(n.text.blockSize)(e)}},a]},((e)=> {const r=(0,t.peekBytes)(2)(e);return r[0]===33&&r[1]===1})); const d=(0,r.conditional)({application:[{codes:(0,t.readBytes)(2)},{blockSize:(0,t.readByte)()},{id(e,r,n){return(0,t.readString)(n.blockSize)(e)}},a]},((e)=> {const r=(0,t.peekBytes)(2)(e);return r[0]===33&&r[1]===255})); const c=(0,r.conditional)({comment:[{codes:(0,t.readBytes)(2)},a]},((e)=> {const r=(0,t.peekBytes)(2)(e);return r[0]===33&&r[1]===254})); const u=[{header:[{signature:(0,t.readString)(3)},{version:(0,t.readString)(3)}]},{lsd:[{width:(0,t.readUnsigned)(!0)},{height:(0,t.readUnsigned)(!0)},{gct:(0,t.readBits)({exists:{index:0},resolution:{index:1,length:3},sort:{index:4},size:{index:5,length:3}})},{backgroundColorIndex:(0,t.readByte)()},{pixelAspectRatio:(0,t.readByte)()}]},(0,r.conditional)({gct:(0,t.readArray)(3,((e,r)=> {return 2**(r.lsd.gct.size+1)}))},((e,r)=> {return r.lsd.gct.exists})),{frames:(0,r.loop)([i,d,c,o,s],((e)=> {const r=(0,t.peekByte)()(e);return r===33||r===44}))}];n.default=u})); const a=e(((e,r)=> {Object.defineProperty(r,"__esModule",{value:!0}),r.deinterlace=void 0;r.deinterlace=function(e,r){for(var t=new Array(e.length),n=e.length/r,a=function(n,a){const i=e.slice(a*r,(a+1)*r);t.splice.apply(t,[n*r,r].concat(i))},i=[0,4,2,1],o=[8,8,4,2],s=0,d=0;d<4;d++)for(let c=i[d];c<n;c+=o[d])a(c,s),s++;return t}})); const i=e(((e,r)=> {Object.defineProperty(r,"__esModule",{value:!0}),r.lzw=void 0;r.lzw=function(e,r,t){let n; let a; let i; let o; let s; let d; let c; let u; let l; let f; let p; let g; let y; let h; let v; let m; const x=4096; const B=t; const w=new Array(t); const b=new Array(x); const k=new Array(x); const A=new Array(4097);for(s=(a=1<<(f=e))+1,n=a+2,c=-1,i=(1<<(o=f+1))-1,u=0;u<a;u++)b[u]=0,k[u]=u;for(p=g=y=h=v=m=0,l=0;l<B;){if(h===0){if(g<o){p+=r[m]<<g,g+=8,m++;continue}if(u=p&i,p>>=o,g-=o,u>n||u==s)break;if(u==a){i=(1<<(o=f+1))-1,n=a+2,c=-1;continue}if(c==-1){A[h++]=k[u],c=u,y=u;continue}for(d=u,u==n&&(A[h++]=y,u=c);u>a;)A[h++]=k[u],u=b[u];y=255&k[u],A[h++]=y,n<x&&(b[n]=c,k[n]=y,(++n&i)==0&&n<x&&(o++,i+=n)),c=d}h--,w[v++]=A[h],l++}for(l=v;l<B;l++)w[l]=0;return w}})); const o=e(((e,o)=> {Object.defineProperty(o,"__esModule",{value:!0}),o.decompressFrames=o.decompressFrame=o.parseGIF=void 0;let s; const d=(s=n)&&s.__esModule?s:{default:s};o.parseGIF=function(e){const n=new Uint8Array(e);return(0,r.parse)((0,t.buildStream)(n),d.default)};const c=function(e,r,t){if(e.image){const n=e.image; const o=n.descriptor.width*n.descriptor.height; let s=(0,i.lzw)(n.data.minCodeSize,n.data.blocks,o);n.descriptor.lct.interlaced&&(s=(0,a.deinterlace)(s,n.descriptor.width));const d={pixels:s,dims:{top:e.image.descriptor.top,left:e.image.descriptor.left,width:e.image.descriptor.width,height:e.image.descriptor.height}};return n.descriptor.lct&&n.descriptor.lct.exists?d.colorTable=n.lct:d.colorTable=r,e.gce&&(d.delay=10*(e.gce.delay||10),d.disposalType=e.gce.extras.disposal,e.gce.extras.transparentColorGiven&&(d.transparentIndex=e.gce.transparentColorIndex)),t&&(d.patch=function(e){for(var r=e.pixels.length,t=new Uint8ClampedArray(4*r),n=0;n<r;n++){const a=4*n; const i=e.pixels[n]; const o=e.colorTable[i]||[0,0,0];t[a]=o[0],t[a+1]=o[1],t[a+2]=o[2],t[a+3]=i!==e.transparentIndex?255:0}return t}(d)),d}console.warn("gif frame does not have associated image.")};o.decompressFrame=c;o.decompressFrames=function(e,r){return e.frames.filter(((e)=> {return e.image})).map(((t)=> {return c(t,e.gct,r)}))}}));const s=(e,r,t)=>{const{width:n,height:a,top:i,left:o}=r.dims; const s=i*t.width+o;for(let i=0;i<a;i++)for(let a=0;a<n;a++){const o=i*n+a; const d=r.pixels[o];if(d!==r.transparentIndex){const n=s+i*t.width+a; const o=r.colorTable[d]||[0,0,0];e[4*n]=o[0],e[4*n+1]=o[1],e[4*n+2]=o[2],e[4*n+3]=255}}return e}; const d=new Map;self.addEventListener("message",(e=>{const{type:r,src:t}=e.data||e;switch(r){case"parse":if(!d.has(t)){const e=new AbortController; const r={signal:e.signal};d.set(t,e),((e,{signal:r})=>fetch(e,{signal:r}).then((e=>{if(!e.headers.get("Content-Type").includes("image/gif"))throw Error(\`Wrong content type: "$\{e.headers.get("Content-Type")}"\`);return e.arrayBuffer()})).then((e=>o.parseGIF(e))).then((e=>((e=>{let r=null;for(const t of e.frames)r=t.gce?t.gce:r,"image"in t&&!("gce"in t)&&(t.gce=r)})(e),e))).then((e=>Promise.all([o.decompressFrames(e,!1),{width:e.lsd.width,height:e.lsd.height}]))).then((([e,r])=>{const t=[]; const n=r.width*r.height*4;for(let a=0;a<e.length;++a){const i=e[a]; const o=a===0||e[a-1].disposalType===2?new Uint8ClampedArray(n):t[a-1].slice();t.push(s(o,i,r))}return{...r,loaded:!0,delays:e.map((e=>e.delay)),frames:t}})))(t,r).then((e=>{self.postMessage(Object.assign(e,{src:t}),e.frames.map((e=>e.buffer)))})).catch((e=>{self.postMessage({src:t,error:e,loaded:!0})})).finally((()=>{d.delete(t)}))}break;case"cancel":if(d.has(t)){d.get(t).abort(),d.delete(t)}}}));`;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const parse_generate_1 = require("../parse-generate");
4
+ const abortMap = new Map();
5
+ self.addEventListener('message', (e) => {
6
+ const { type, src } = e.data || e;
7
+ switch (type) {
8
+ case 'parse': {
9
+ if (!abortMap.has(src)) {
10
+ const controller = new AbortController();
11
+ const signal = { signal: controller.signal };
12
+ abortMap.set(src, controller);
13
+ (0, parse_generate_1.parse)(src, signal)
14
+ .then((result) => {
15
+ self.postMessage(Object.assign(result, { src }),
16
+ // @ts-expect-error
17
+ result.frames.map((frame) => frame.buffer));
18
+ })
19
+ .catch((error) => {
20
+ self.postMessage({ src, error, loaded: true });
21
+ })
22
+ .finally(() => {
23
+ abortMap.delete(src);
24
+ });
25
+ }
26
+ break;
27
+ }
28
+ case 'cancel': {
29
+ if (abortMap.has(src)) {
30
+ const controller = abortMap.get(src);
31
+ controller.abort();
32
+ abortMap.delete(src);
33
+ }
34
+ break;
35
+ }
36
+ default:
37
+ break;
38
+ }
39
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/gif",
3
- "version": "4.0.0-prefetch.11+edeed0968",
3
+ "version": "4.0.0-prefetch.12+c7eb5bd76",
4
4
  "description": "Gif component for remotion",
5
5
  "sideEffects": false,
6
6
  "repository": {
@@ -21,23 +21,22 @@
21
21
  "watch": "tsc -w"
22
22
  },
23
23
  "dependencies": {
24
- "@react-gifs/tools": "0.1.2",
24
+ "gifuct-js": "2.1.2",
25
25
  "lru_map": "0.4.1",
26
- "remotion": "4.0.0-prefetch.11+edeed0968"
26
+ "remotion": "4.0.0-prefetch.12+c7eb5bd76"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@jonny/eslint-config": "3.0.266",
30
30
  "@types/node": "^16.7.5",
31
31
  "@types/react": "18.0.1",
32
32
  "@types/react-dom": "18.0.0",
33
- "eslint": "8.13.0",
34
- "jest": "^27.2.4",
33
+ "eslint": "8.25.0",
35
34
  "prettier": "2.6.2",
36
35
  "prettier-plugin-organize-imports": "^2.3.4",
37
36
  "react": "18.0.0",
38
37
  "react-dom": "18.0.0",
39
38
  "typescript": "^4.7.0",
40
- "webpack": "5.72.0"
39
+ "webpack": "5.74.0"
41
40
  },
42
41
  "peerDependencies": {
43
42
  "react": ">=16.8.0",
@@ -54,5 +53,5 @@
54
53
  "publishConfig": {
55
54
  "access": "public"
56
55
  },
57
- "gitHead": "edeed0968f80a7678bd7c3bdf90fa8b9466f9059"
56
+ "gitHead": "c7eb5bd76f2f89677f007a54e1bc5d3e3403094f"
58
57
  }