Skip to content

Commit

Permalink
Merge pull request #26 from SimenB/patch-1
Browse files Browse the repository at this point in the history
fix: lazy load `GifUtil` rather than `nextTick`
  • Loading branch information
jtlapp committed Mar 12, 2022
2 parents da9b9ca + 31cbf51 commit bb8c979
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/gifcodec.js
Expand Up @@ -2,10 +2,17 @@

const Omggif = require('omggif');
const { Gif, GifError } = require('./gif');
let GifUtil; // allow circular dependency with GifUtil
process.nextTick(() => {
GifUtil = require('./gifutil');
});

// allow circular dependency with GifUtil
function GifUtil() {
const data = require('./gifutil');

GifUtil = function () {
return data;
};

return data;
}

const { GifFrame } = require('./gifframe');

Expand Down Expand Up @@ -95,7 +102,7 @@ class GifCodec
if (frames === null || frames.length === 0) {
throw new GifError("there are no frames");
}
const dims = GifUtil.getMaxDimensions(frames);
const dims = GifUtil().getMaxDimensions(frames);

spec = Object.assign({}, spec); // don't munge caller's spec
spec.width = dims.maxWidth;
Expand Down Expand Up @@ -170,10 +177,10 @@ class GifCodec
_encodeGif(frames, spec) {
let colorInfo;
if (spec.colorScope === Gif.LocalColorsOnly) {
colorInfo = GifUtil.getColorInfo(frames, 0);
colorInfo = GifUtil().getColorInfo(frames, 0);
}
else {
colorInfo = GifUtil.getColorInfo(frames, 256);
colorInfo = GifUtil().getColorInfo(frames, 256);
if (!colorInfo.colors) { // if global palette impossible
if (spec.colorScope === Gif.GlobalColorsOnly) {
throw new GifError(
Expand Down

0 comments on commit bb8c979

Please sign in to comment.