imagescript 3.20.1 → 3.20.2
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/dist/animation-encoder.js +4 -1
- package/dist/animation.js +4 -1
- package/dist/util/options.js +6 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ import { Frame } from "./frame.js";
|
|
|
6
6
|
import { Optimizer, Compositor, coverCanvas, fillUnchanged } from "./util/optimize.js";
|
|
7
7
|
import { compressAsync, decompressAsync } from "./codecs/zlib.js";
|
|
8
8
|
import { resolveMetadata, pngText, exifData, gifComments } from "./metadata.js";
|
|
9
|
-
import { finite, compressionLevel } from "./util/options.js";
|
|
9
|
+
import { finite, compressionLevel, fitLoops } from "./util/options.js";
|
|
10
10
|
const toPlays = (loopCount) => loopCount < 0 || loopCount === Infinity ? 0 : loopCount + 1;
|
|
11
11
|
export class AnimationEncoder {
|
|
12
12
|
format;
|
|
@@ -71,6 +71,7 @@ export class AnimationEncoder {
|
|
|
71
71
|
}
|
|
72
72
|
static __webp__(width, height, { loopCount = -1, metadata = {}, optimize = true, quality, effort = 2, sharpYuv = false, alphaQuality = 100 }) {
|
|
73
73
|
canvas(width, height, loopCount);
|
|
74
|
+
fitLoops(loopCount, 'WebP');
|
|
74
75
|
if (width > 1 << 24 || height > 1 << 24)
|
|
75
76
|
throw new RangeError('WebP: canvas too large');
|
|
76
77
|
const lossy = webp.lossyOptions(quality, effort, sharpYuv, alphaQuality);
|
|
@@ -100,6 +101,7 @@ export class AnimationEncoder {
|
|
|
100
101
|
static __gif__(width, height, { loopCount = -1, metadata = {}, optimize = true, quality: qualityOption = 95 }) {
|
|
101
102
|
const quality = finite(qualityOption, 'quality');
|
|
102
103
|
canvas(width, height, loopCount);
|
|
104
|
+
fitLoops(loopCount, 'GIF');
|
|
103
105
|
const comments = gifComments(resolveMetadata(metadata));
|
|
104
106
|
let first = null, restores = false;
|
|
105
107
|
const rest = [];
|
|
@@ -126,6 +128,7 @@ export class AnimationEncoder {
|
|
|
126
128
|
static __apng__(width, height, { loopCount = -1, metadata = {}, optimize = true, compression: compressionOption = 4 }) {
|
|
127
129
|
const compression = compressionLevel(compressionOption);
|
|
128
130
|
canvas(width, height, loopCount);
|
|
131
|
+
fitLoops(loopCount, 'APNG');
|
|
129
132
|
const text = pngText(resolveMetadata(metadata));
|
|
130
133
|
const stored = [];
|
|
131
134
|
const cost = new png.AlphaCost();
|
package/dist/animation.js
CHANGED
|
@@ -11,7 +11,7 @@ import { Frame, FrameDisposalModes } from "./frame.js";
|
|
|
11
11
|
import { ImageType } from "./image-type.js";
|
|
12
12
|
import { optimize } from "./util/optimize.js";
|
|
13
13
|
import { resolveMetadata, pngText, exifData, gifComments } from "./metadata.js";
|
|
14
|
-
import { isOptions, finite, compressionLevel } from "./util/options.js";
|
|
14
|
+
import { isOptions, finite, compressionLevel, fitLoops } from "./util/options.js";
|
|
15
15
|
import { MAX_PIXELS, decoding } from "./util/limits.js";
|
|
16
16
|
import { AnimationEncoder } from "./animation-encoder.js";
|
|
17
17
|
const toPlays = (loopCount) => loopCount < 0 || loopCount === Infinity ? 0 : loopCount + 1;
|
|
@@ -105,6 +105,7 @@ export class Animation extends Array {
|
|
|
105
105
|
}
|
|
106
106
|
async encodeGIF(qualityOrOptions = 95) {
|
|
107
107
|
const { quality = 95, metadata = {}, optimize = true } = isOptions(qualityOrOptions) ? qualityOrOptions : { quality: qualityOrOptions };
|
|
108
|
+
fitLoops(this.loopCount, 'GIF');
|
|
108
109
|
this.__validate__();
|
|
109
110
|
const frames = optimize
|
|
110
111
|
? this.__optimized__({ replace: false, even: false, alpha: 'frame', palette: 256, cover: true }).map(f => ({ ...f, dispose: f.dispose ? 3 : 1 }))
|
|
@@ -122,6 +123,7 @@ export class Animation extends Array {
|
|
|
122
123
|
}
|
|
123
124
|
async encodeAPNG(compressionOrOptions = 4) {
|
|
124
125
|
const { compression = 4, metadata = {}, optimize = true } = isOptions(compressionOrOptions) ? compressionOrOptions : { compression: compressionOrOptions };
|
|
126
|
+
fitLoops(this.loopCount, 'APNG');
|
|
125
127
|
this.__validate__();
|
|
126
128
|
if (!this.length)
|
|
127
129
|
throw new Error('An animation needs at least one frame');
|
|
@@ -131,6 +133,7 @@ export class Animation extends Array {
|
|
|
131
133
|
return png.encodeAnimation(frames, this.width, this.height, toPlays(this.loopCount), compressionLevel(compression), pngText(resolveMetadata(metadata)));
|
|
132
134
|
}
|
|
133
135
|
async encodeWebP({ metadata = {}, optimize = true, quality, effort = 2, sharpYuv = false, alphaQuality = 100 } = {}) {
|
|
136
|
+
fitLoops(this.loopCount, 'WebP');
|
|
134
137
|
this.__validate__();
|
|
135
138
|
if (!this.length)
|
|
136
139
|
throw new Error('An animation needs at least one frame');
|
package/dist/util/options.js
CHANGED
|
@@ -20,3 +20,9 @@ export function effort(value, max) {
|
|
|
20
20
|
}
|
|
21
21
|
export const compressionLevel = (value) => Math.min(9, Math.max(0, ~~finite(value, 'compression level')));
|
|
22
22
|
export const color = (value, name = 'color') => finite(value, name);
|
|
23
|
+
const LOOP_LIMITS = { GIF: 65535, WebP: 65534, APNG: 2 ** 31 - 2 };
|
|
24
|
+
export function fitLoops(loopCount, format) {
|
|
25
|
+
if (loopCount !== Infinity && loopCount > LOOP_LIMITS[format])
|
|
26
|
+
throw new RangeError(`${format} stores loop counts up to ${LOOP_LIMITS[format]} (or Infinity to loop forever), not ${loopCount}`);
|
|
27
|
+
return loopCount;
|
|
28
|
+
}
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '3.20.
|
|
1
|
+
export const VERSION = '3.20.2';
|