@remotion/gif 3.3.33 → 3.3.35

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.
@@ -9,8 +9,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
11
  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;
12
+ exports.GifForDevelopment = (0, react_1.forwardRef)(({ src, width, height, onError, loopBehavior = 'loop', onLoad, fit = 'fill', ...props }, ref) => {
13
+ const resolvedSrc = new URL(src, typeof window === 'undefined' ? undefined : window.location.origin).href;
14
14
  const [state, update] = (0, react_1.useState)(() => {
15
15
  const parsedGif = gif_cache_1.gifCache.get(resolvedSrc);
16
16
  if (parsedGif === undefined) {
@@ -71,6 +71,9 @@ exports.GifForDevelopment = (0, react_1.forwardRef)(({ src, width, height, onErr
71
71
  }
72
72
  throw new Error(`Failed to render GIF with source ${src}: "${error.message}".`);
73
73
  }
74
- const index = (0, useCurrentGifIndex_1.useCurrentGifIndex)(state.delays);
74
+ const index = (0, useCurrentGifIndex_1.useCurrentGifIndex)(state.delays, loopBehavior);
75
+ if (index === -1) {
76
+ return null;
77
+ }
75
78
  return ((0, jsx_runtime_1.jsx)(canvas_1.Canvas, { fit: fit, index: index, frames: state.frames, width: width, height: height, ...props, ref: ref }));
76
79
  });
@@ -9,7 +9,7 @@ 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
11
  const useCurrentGifIndex_1 = require("./useCurrentGifIndex");
12
- exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad, onError, fit = 'fill', ...props }, ref) => {
12
+ exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad, onError, loopBehavior = 'loop', fit = 'fill', ...props }, ref) => {
13
13
  const resolvedSrc = new URL(src, window.location.origin).href;
14
14
  const [state, update] = (0, react_1.useState)(() => {
15
15
  const parsedGif = gif_cache_1.gifCache.get(resolvedSrc);
@@ -25,7 +25,7 @@ exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad,
25
25
  });
26
26
  const [error, setError] = (0, react_1.useState)(null);
27
27
  const [id] = (0, react_1.useState)(() => (0, remotion_1.delayRender)(`Rendering <Gif/> with src="${resolvedSrc}"`));
28
- const index = (0, useCurrentGifIndex_1.useCurrentGifIndex)(state.delays);
28
+ const index = (0, useCurrentGifIndex_1.useCurrentGifIndex)(state.delays, loopBehavior);
29
29
  const currentOnLoad = (0, react_1.useRef)(onLoad);
30
30
  const currentOnError = (0, react_1.useRef)(onError);
31
31
  currentOnLoad.current = onLoad;
@@ -72,5 +72,8 @@ exports.GifForRendering = (0, react_1.forwardRef)(({ src, width, height, onLoad,
72
72
  }
73
73
  throw new Error(`Failed to render GIF with source ${src}: "${error.message}". Render with --log=verbose to see the full stack.`);
74
74
  }
75
+ if (index === -1) {
76
+ return null;
77
+ }
75
78
  return ((0, jsx_runtime_1.jsx)(canvas_1.Canvas, { fit: fit, index: index, frames: state.frames, width: width, height: height, ...props, ref: ref }));
76
79
  });
package/dist/canvas.js CHANGED
@@ -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;
@@ -1,8 +1,4 @@
1
1
  import type { Frame, ParsedFrameWithoutPatch, ParsedGif } from './types';
2
2
  export declare const parseGIF: (arrayBuffer: ArrayBuffer) => any;
3
- export declare const decompressFrame: (frame: Frame, gct: [
4
- number,
5
- number,
6
- number
7
- ][]) => ParsedFrameWithoutPatch | undefined;
3
+ export declare const decompressFrame: (frame: Frame, gct: [number, number, number][]) => ParsedFrameWithoutPatch | undefined;
8
4
  export declare const decompressFrames: (parsedGif: ParsedGif) => (ParsedFrameWithoutPatch | undefined)[];
package/dist/props.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ export declare type GifLoopBehavior = 'loop' | 'pause-after-finish' | 'unmount-after-finish';
2
3
  export declare type RemotionGifProps = {
3
4
  src: string;
4
5
  width?: number;
@@ -12,6 +13,7 @@ export declare type RemotionGifProps = {
12
13
  onError?: (error: Error) => void;
13
14
  fit?: GifFillMode;
14
15
  style?: React.CSSProperties;
16
+ loopBehavior?: GifLoopBehavior;
15
17
  };
16
18
  export declare type GifState = {
17
19
  delays: number[];
@@ -1 +1,2 @@
1
- export declare function useCurrentGifIndex(delays: number[]): number;
1
+ import type { GifLoopBehavior } from './props';
2
+ export declare function useCurrentGifIndex(delays: number[], loopBehavior: GifLoopBehavior): number;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useCurrentGifIndex = void 0;
4
4
  const react_1 = require("react");
5
5
  const remotion_1 = require("remotion");
6
- function useCurrentGifIndex(delays) {
6
+ function useCurrentGifIndex(delays, loopBehavior) {
7
7
  const currentFrame = (0, remotion_1.useCurrentFrame)();
8
8
  const videoConfig = (0, remotion_1.useVideoConfig)();
9
9
  const duration = (0, react_1.useMemo)(() => {
@@ -12,19 +12,24 @@ function useCurrentGifIndex(delays) {
12
12
  }
13
13
  return 1;
14
14
  }, [delays]);
15
- const index = (0, react_1.useMemo)(() => {
16
- if (delays.length === 0) {
17
- return 0;
18
- }
19
- let currentTime = ((currentFrame / videoConfig.fps) * 1000) % duration;
20
- for (const [i, delay] of delays.entries()) {
21
- if (currentTime < delay) {
22
- return i;
23
- }
24
- currentTime -= delay;
25
- }
15
+ if (delays.length === 0) {
26
16
  return 0;
27
- }, [delays, duration, currentFrame, videoConfig]);
28
- return index;
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;
29
34
  }
30
35
  exports.useCurrentGifIndex = useCurrentGifIndex;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/gif",
3
- "version": "3.3.33",
3
+ "version": "3.3.35",
4
4
  "description": "Gif component for remotion",
5
5
  "sideEffects": false,
6
6
  "repository": {
@@ -23,7 +23,7 @@
23
23
  "dependencies": {
24
24
  "js-binary-schema-parser": "^2.0.3",
25
25
  "lru_map": "0.4.1",
26
- "remotion": "3.3.33"
26
+ "remotion": "3.3.35"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@jonny/eslint-config": "3.0.266",
@@ -53,5 +53,5 @@
53
53
  "publishConfig": {
54
54
  "access": "public"
55
55
  },
56
- "gitHead": "0356b9108673ac98c41990f192b101f7a6574ed0"
56
+ "gitHead": "92344ca937e4c51b8484f79528e3c38d598f7053"
57
57
  }
@@ -1,4 +0,0 @@
1
- import type { CondFunction, ParseFun, Result, Stream } from './types';
2
- export declare const parse: (stream: Stream, schema: any, result?: Result, parent?: Result) => Result;
3
- export declare const conditional: (schema: any, conditionFunc: CondFunction) => (stream: any, result: Result, parent: Result, _parse: ParseFun) => void;
4
- export declare const loop: (schema: any, continueFunc: any) => (stream: any, result: any, parent: any, parse: any) => {}[];
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loop = exports.conditional = exports.parse = void 0;
4
- const parse = (stream, schema, result = {}, parent = result) => {
5
- if (Array.isArray(schema)) {
6
- schema.forEach((partSchema) => (0, exports.parse)(stream, partSchema, result, parent));
7
- }
8
- else if (typeof schema === 'function') {
9
- schema(stream, result, parent, exports.parse);
10
- }
11
- else {
12
- const key = Object.keys(schema)[0];
13
- if (Array.isArray(schema[key])) {
14
- parent[key] = {};
15
- (0, exports.parse)(stream, schema[key], result, parent[key]);
16
- }
17
- else {
18
- parent[key] = schema[key](stream, result, parent, exports.parse);
19
- }
20
- }
21
- return result;
22
- };
23
- exports.parse = parse;
24
- const conditional = (schema, conditionFunc) => (stream, result, parent, _parse) => {
25
- if (conditionFunc(stream, result, parent)) {
26
- _parse(stream, schema, result, parent);
27
- }
28
- };
29
- exports.conditional = conditional;
30
- const loop = (schema, continueFunc) => (stream, result, parent, parse) => {
31
- const arr = [];
32
- let lastStreamPos = stream.pos;
33
- while (continueFunc(stream, result, parent)) {
34
- const newParent = {};
35
- parse(stream, schema, result, newParent);
36
- // cases when whole file is parsed but no termination is there and stream position is not getting updated as well
37
- // it falls into infinite recursion, null check to avoid the same
38
- if (stream.pos === lastStreamPos) {
39
- break;
40
- }
41
- lastStreamPos = stream.pos;
42
- arr.push(newParent);
43
- }
44
- return arr;
45
- };
46
- exports.loop = loop;
@@ -1,7 +0,0 @@
1
- export declare type Schema = SchemaFun | Schema[] | SchemaFun[] | Record<string, Schema>;
2
- export declare type Stream = unknown;
3
- export declare type Result = Record<string, unknown>;
4
- export declare type CondFunction = (a: Stream, b: Result, c: unknown) => boolean;
5
- export declare type ParseFun = (a: Stream, b: Schema, c: Result | undefined, d: Result | undefined) => Result;
6
- declare type SchemaFun = (stream: Stream, res: Result, parent: Result | undefined, parseFn: ParseFun) => void;
7
- export {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });