imagescript 3.20.3 → 4.0.0-rc.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/LICENSE +16 -12
- package/README.md +21 -12
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/animation-encoder.d.ts +1 -34
- package/dist/animation-encoder.js +35 -34
- package/dist/animation.d.ts +108 -122
- package/dist/animation.js +285 -121
- package/dist/codecs/av1/decode.js +1 -1
- package/dist/codecs/av1/encode.js +1 -1
- package/dist/codecs/gif.js +11 -9
- package/dist/codecs/hdr.d.ts +1 -1
- package/dist/codecs/jpeg.js +13 -13
- package/dist/codecs/jxl/headers.js +3 -3
- package/dist/codecs/jxl/patches-enc.js +1 -1
- package/dist/codecs/jxl.js +5 -5
- package/dist/codecs/netpbm.js +7 -7
- package/dist/codecs/png.js +15 -15
- package/dist/codecs/quantize.js +34 -8
- package/dist/codecs/tiff.js +1 -1
- package/dist/codecs/webp.js +3 -3
- package/dist/codecs/zlib.js +1 -1
- package/dist/colors.d.ts +8 -7
- package/dist/colors.js +23 -3
- package/dist/frame.d.ts +94 -100
- package/dist/frame.js +89 -65
- package/dist/gainmap.d.ts +88 -46
- package/dist/gainmap.js +75 -51
- package/dist/image-type.d.ts +6 -1
- package/dist/image-type.js +4 -1
- package/dist/image.d.ts +317 -738
- package/dist/image.js +308 -438
- package/dist/index.d.ts +19 -25
- package/dist/index.js +15 -14
- package/dist/metadata.d.ts +4 -3
- package/dist/metadata.js +9 -7
- package/dist/render/colr.js +1 -1
- package/dist/render/font.js +1 -1
- package/dist/render/layout.js +1 -1
- package/dist/render/segment.js +1 -1
- package/dist/render/shapers/hangul.js +1 -1
- package/dist/render/svg.js +68 -20
- package/dist/render/text.js +7 -9
- package/dist/text-layout.d.ts +5 -35
- package/dist/text-layout.js +11 -12
- package/dist/util/gain.js +12 -12
- package/dist/util/mem.d.ts +1 -1
- package/dist/util/optimize.js +3 -1
- package/dist/util/options.js +46 -7
- package/package.json +15 -10
- package/LICENSE.AGPL-3.0 +0 -619
- package/LICENSE.MIT +0 -19
- package/dist/gif.d.ts +0 -36
- package/dist/gif.js +0 -22
- package/dist/util/rotate.js +0 -43
- package/dist/version.js +0 -1
package/dist/util/gain.js
CHANGED
|
@@ -3,7 +3,7 @@ export const LINEAR = new Float32Array(256).map((_, v) => (v /= 255) <= 0.04045
|
|
|
3
3
|
export const encodeSRGB = (v) => 255 * (v <= 0.0031308 ? 12.92 * Math.max(0, v) : 1.055 * Math.min(1, v) ** (1 / 2.4) - 0.055);
|
|
4
4
|
const LUMA = [0.2126, 0.7152, 0.0722];
|
|
5
5
|
const gainTables = (map) => [0, 1, 2].map(c => {
|
|
6
|
-
const min = map.
|
|
6
|
+
const min = map.__min__[c], max = map.__max__[c], gamma = map.__gamma__[c];
|
|
7
7
|
return new Float32Array(256).map((_, v) => min + (max - min) * (v / 255) ** (1 / gamma));
|
|
8
8
|
});
|
|
9
9
|
export function decodeGains(map) {
|
|
@@ -18,7 +18,7 @@ export function decodeGains(map) {
|
|
|
18
18
|
return gains;
|
|
19
19
|
}
|
|
20
20
|
export function encodeGains(map, gains, width, height, single) {
|
|
21
|
-
const min = map.
|
|
21
|
+
const min = map.__min__.slice(), max = map.__max__.slice();
|
|
22
22
|
for (let g = 0; g < gains.length; g += 3)
|
|
23
23
|
for (let c = 0; c < 3; c++) {
|
|
24
24
|
const v = gains[g + c];
|
|
@@ -31,17 +31,17 @@ export function encodeGains(map, gains, width, height, single) {
|
|
|
31
31
|
const lo = Math.min(...min), hi = Math.max(...max);
|
|
32
32
|
min.fill(lo);
|
|
33
33
|
max.fill(hi);
|
|
34
|
-
const gamma = map.
|
|
35
|
-
map.
|
|
34
|
+
const gamma = map.__gamma__[0];
|
|
35
|
+
map.__gamma__ = [gamma, gamma, gamma];
|
|
36
36
|
}
|
|
37
|
-
map.
|
|
38
|
-
map.
|
|
37
|
+
map.__min__ = min;
|
|
38
|
+
map.__max__ = max;
|
|
39
39
|
const image = map.image.width === width && map.image.height === height ? map.image : new Image(width, height);
|
|
40
40
|
const out = image.bitmap;
|
|
41
41
|
for (let i = 0, g = 0; i < out.length; i += 4, g += 3) {
|
|
42
42
|
for (let c = 0; c < 3; c++) {
|
|
43
43
|
const t = max[c] > min[c] ? (gains[g + c] - min[c]) / (max[c] - min[c]) : 0;
|
|
44
|
-
out[i + c] = 255 * Math.min(1, Math.max(0, t)) ** map.
|
|
44
|
+
out[i + c] = 255 * Math.min(1, Math.max(0, t)) ** map.__gamma__[c];
|
|
45
45
|
}
|
|
46
46
|
out[i + 3] = 255;
|
|
47
47
|
}
|
|
@@ -61,8 +61,8 @@ export function neutralMap(like, likeWidth, width, height) {
|
|
|
61
61
|
bitmap[i + 3] = 255;
|
|
62
62
|
}
|
|
63
63
|
map.image = image;
|
|
64
|
-
map.
|
|
65
|
-
map.
|
|
64
|
+
map.__min__ = map.__min__.map(v => Math.min(v, 0));
|
|
65
|
+
map.__max__ = map.__max__.map(v => Math.max(v, 0));
|
|
66
66
|
return map;
|
|
67
67
|
}
|
|
68
68
|
const sample = (gains, width, height, x, y, out) => {
|
|
@@ -80,7 +80,7 @@ export function redraw(image, map, left, top, right, bottom, light, single = map
|
|
|
80
80
|
const mapWidth = map.width, mapHeight = map.height;
|
|
81
81
|
const sx = mapWidth / width, sy = mapHeight / height;
|
|
82
82
|
const oS = map.offsetSDR, oH = map.offsetHDR;
|
|
83
|
-
const lo = Math.min(0, ...map.
|
|
83
|
+
const lo = Math.min(0, ...map.__min__), hi = Math.max(0, ...map.__max__, extraMax);
|
|
84
84
|
const S = [0, 0, 0], H = [0, 0, 0], sumS = [0, 0, 0], sumH = [0, 0, 0];
|
|
85
85
|
const i0 = Math.max(0, Math.floor(left * sx)), i1 = Math.min(mapWidth, Math.ceil(right * sx));
|
|
86
86
|
const j0 = Math.max(0, Math.floor(top * sy)), j1 = Math.min(mapHeight, Math.ceil(bottom * sy));
|
|
@@ -125,7 +125,7 @@ export function redraw(image, map, left, top, right, bottom, light, single = map
|
|
|
125
125
|
next[g + c] = ratio(sumH[c] / n + oH[c], sumS[c] / n + oS[c], lo, hi);
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
-
const {
|
|
128
|
+
const { __min__: min, __max__: max, gamma } = map;
|
|
129
129
|
let fits = !single || (min[0] === min[1] && min[1] === min[2] && max[0] === max[1] && max[1] === max[2] && gamma[0] === gamma[1] && gamma[1] === gamma[2]);
|
|
130
130
|
for (let g = 0; fits && g < next.length; g += 3)
|
|
131
131
|
for (let c = 0; c < 3; c++)
|
|
@@ -217,7 +217,7 @@ export function recolor(map, before, apply, exact) {
|
|
|
217
217
|
let changedPeak = 1;
|
|
218
218
|
for (let g = 0; g < changed.length; g++)
|
|
219
219
|
changedPeak = Math.max(changedPeak, changed[g]);
|
|
220
|
-
const lo = Math.min(0, ...map.
|
|
220
|
+
const lo = Math.min(0, ...map.__min__), hi = Math.max(Math.log2(Math.max(peak, changedPeak)), ...map.__max__);
|
|
221
221
|
const single = map.channels === 1;
|
|
222
222
|
for (let g = 0; g < gains.length; g += 3) {
|
|
223
223
|
if (single) {
|
package/dist/util/mem.d.ts
CHANGED
package/dist/util/optimize.js
CHANGED
|
@@ -62,8 +62,10 @@ export class Optimizer {
|
|
|
62
62
|
const { replace, even, alpha, palette, tolerance } = this.options;
|
|
63
63
|
let changed = bounds(state, { x: 0, y: 0, width, height });
|
|
64
64
|
if (!changed) {
|
|
65
|
-
if (this.last)
|
|
65
|
+
if (this.last && this.last.duration + duration <= (this.options.maxDuration ?? Infinity))
|
|
66
66
|
this.last.duration += duration;
|
|
67
|
+
else if (this.last)
|
|
68
|
+
this.output(empty(duration));
|
|
67
69
|
else {
|
|
68
70
|
this.output(empty(duration));
|
|
69
71
|
this.opaque = false;
|
package/dist/util/options.js
CHANGED
|
@@ -1,12 +1,48 @@
|
|
|
1
1
|
export function isOptions(value) {
|
|
2
2
|
return typeof value === 'object' && value !== null && !ArrayBuffer.isView(value);
|
|
3
3
|
}
|
|
4
|
+
export function checkOptions(value, usage) {
|
|
5
|
+
if (value !== undefined && !isOptions(value))
|
|
6
|
+
throw new TypeError(`${usage.split('(')[0]}() takes an options object, like ${usage}, not ${value === null ? 'null' : typeof value}`);
|
|
7
|
+
}
|
|
8
|
+
export function oneOf(value, allowed, name) {
|
|
9
|
+
if (typeof value !== 'string' || !allowed.includes(value)) {
|
|
10
|
+
const list = allowed.map(a => `'${a}'`);
|
|
11
|
+
const expected = list.length > 1 ? `${list.slice(0, -1).join(', ')} or ${list[list.length - 1]}` : list[0];
|
|
12
|
+
throw new TypeError(`${name} must be ${expected}, not ${typeof value === 'string' ? `'${value}'` : String(value)}`);
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
4
16
|
export function finite(value, name) {
|
|
5
17
|
const number = Number(value);
|
|
6
18
|
if (!Number.isFinite(number))
|
|
7
19
|
throw new RangeError(`Invalid ${name}: ${value}`);
|
|
8
20
|
return number;
|
|
9
21
|
}
|
|
22
|
+
export function loopCount(value, name = 'loop count') {
|
|
23
|
+
if (typeof value !== 'number')
|
|
24
|
+
throw new TypeError(`${name} must be a number (Infinity or an integer from 0), not ${value === null ? 'null' : typeof value}`);
|
|
25
|
+
if (value !== Infinity && (!Number.isInteger(value) || value < 0))
|
|
26
|
+
throw new RangeError(`${name} must be Infinity or an integer from 0, not ${value}`);
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
export const toPlays = (count) => count === Infinity ? 0 : count + 1;
|
|
30
|
+
export const fromPlays = (plays) => plays === 0 ? Infinity : plays - 1;
|
|
31
|
+
const LOOP_LIMITS = { GIF: 65535, WebP: 65534, APNG: 2 ** 31 - 2 };
|
|
32
|
+
export function fitLoops(count, format) {
|
|
33
|
+
const max = LOOP_LIMITS[format];
|
|
34
|
+
if (count !== Infinity && count > max)
|
|
35
|
+
throw new RangeError(`refuse loop counts that don't fit the format: ${format} loop counts go up to ${max}, not ${count}`);
|
|
36
|
+
return count;
|
|
37
|
+
}
|
|
38
|
+
const DURATION_LIMITS = { GIF: 655350, APNG: 655350, WebP: 0xffffff };
|
|
39
|
+
export const maxDuration = (format) => DURATION_LIMITS[format];
|
|
40
|
+
export function fitDuration(duration, format) {
|
|
41
|
+
const max = DURATION_LIMITS[format];
|
|
42
|
+
if (duration > max)
|
|
43
|
+
throw new RangeError(`refuse frame durations that don't fit the format: ${format} frames last up to ${max} ms, not ${duration}`);
|
|
44
|
+
return duration;
|
|
45
|
+
}
|
|
10
46
|
export function quality(value, name = 'quality') {
|
|
11
47
|
const q = finite(value, name);
|
|
12
48
|
if (q < 0 || q > 100)
|
|
@@ -18,11 +54,14 @@ export function effort(value, max) {
|
|
|
18
54
|
throw new RangeError(`effort must be an integer 0-${max}, not ${value}`);
|
|
19
55
|
return value;
|
|
20
56
|
}
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
57
|
+
export function compressionLevel(value) {
|
|
58
|
+
if (!Number.isInteger(value) || value < 0 || value > 9)
|
|
59
|
+
throw new RangeError(`compression level must be an integer 0-9, not ${value}`);
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
export function color(value, name = 'color') {
|
|
63
|
+
const number = finite(value, name);
|
|
64
|
+
if (!Number.isInteger(number) || number < -0x80000000 || number > 0xffffffff)
|
|
65
|
+
throw new RangeError(`Invalid ${name}: ${value} (a color is an integer like 0xrrggbbaa)`);
|
|
66
|
+
return number >>> 0;
|
|
28
67
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "imagescript",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-rc.2",
|
|
4
4
|
"description": "Pure TypeScript image processing that runs everywhere",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -14,8 +14,6 @@
|
|
|
14
14
|
"files": [
|
|
15
15
|
"dist",
|
|
16
16
|
"LICENSE",
|
|
17
|
-
"LICENSE.MIT",
|
|
18
|
-
"LICENSE.AGPL-3.0",
|
|
19
17
|
"THIRD_PARTY_NOTICES.md",
|
|
20
18
|
"licenses",
|
|
21
19
|
"README.md"
|
|
@@ -29,7 +27,7 @@
|
|
|
29
27
|
"test": "npm run build && node ./tests/run.js",
|
|
30
28
|
"coverage": "node scripts/build.js --source-maps && c8 node ./tests/run.js && node scripts/coverage-report.js",
|
|
31
29
|
"prepack": "npm run build",
|
|
32
|
-
"version": "node scripts/version.js && git add
|
|
30
|
+
"version": "node scripts/version.js && git add jsr.json"
|
|
33
31
|
},
|
|
34
32
|
"repository": {
|
|
35
33
|
"type": "git",
|
|
@@ -86,7 +84,7 @@
|
|
|
86
84
|
"font"
|
|
87
85
|
],
|
|
88
86
|
"author": "Mathis Mensing <mathis@matmen.dev>",
|
|
89
|
-
"license": "
|
|
87
|
+
"license": "MIT",
|
|
90
88
|
"bugs": {
|
|
91
89
|
"url": "https://github.com/imagescript/ImageScript/issues"
|
|
92
90
|
},
|
|
@@ -95,12 +93,19 @@
|
|
|
95
93
|
"node": ">=22.13.0"
|
|
96
94
|
},
|
|
97
95
|
"devDependencies": {
|
|
98
|
-
"@eslint/js": "
|
|
96
|
+
"@eslint/js": "10.0.1",
|
|
99
97
|
"c8": "12.0.0",
|
|
100
|
-
"eslint": "
|
|
98
|
+
"eslint": "10.14.0",
|
|
101
99
|
"eslint-plugin-sonarjs": "4.2.2",
|
|
102
|
-
"typedoc": "0.
|
|
103
|
-
"typescript": "
|
|
104
|
-
"typescript-eslint": "8.72.
|
|
100
|
+
"typedoc": "0.28.20",
|
|
101
|
+
"typescript": "6.0.3",
|
|
102
|
+
"typescript-eslint": "8.72.2"
|
|
103
|
+
},
|
|
104
|
+
"overrides": {
|
|
105
|
+
"minimatch": "11.0.8",
|
|
106
|
+
"glob": "14.0.5",
|
|
107
|
+
"typedoc": {
|
|
108
|
+
"minimatch": "9.0.9"
|
|
109
|
+
}
|
|
105
110
|
}
|
|
106
111
|
}
|