imagescript 4.0.0-rc.1 → 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.
@@ -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;
@@ -5,6 +5,14 @@ export function checkOptions(value, usage) {
5
5
  if (value !== undefined && !isOptions(value))
6
6
  throw new TypeError(`${usage.split('(')[0]}() takes an options object, like ${usage}, not ${value === null ? 'null' : typeof value}`);
7
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
+ }
8
16
  export function finite(value, name) {
9
17
  const number = Number(value);
10
18
  if (!Number.isFinite(number))
@@ -27,6 +35,14 @@ export function fitLoops(count, format) {
27
35
  throw new RangeError(`refuse loop counts that don't fit the format: ${format} loop counts go up to ${max}, not ${count}`);
28
36
  return count;
29
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
+ }
30
46
  export function quality(value, name = 'quality') {
31
47
  const q = finite(value, name);
32
48
  if (q < 0 || q > 100)
@@ -38,5 +54,14 @@ export function effort(value, max) {
38
54
  throw new RangeError(`effort must be an integer 0-${max}, not ${value}`);
39
55
  return value;
40
56
  }
41
- export const compressionLevel = (value) => Math.min(9, Math.max(0, ~~finite(value, 'compression level')));
42
- export const color = (value, name = 'color') => finite(value, name);
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;
67
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imagescript",
3
- "version": "4.0.0-rc.1",
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 src/version.ts jsr.json"
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": "(AGPL-3.0-or-later OR MIT)",
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": "9.39.5",
96
+ "@eslint/js": "10.0.1",
99
97
  "c8": "12.0.0",
100
- "eslint": "9.39.5",
98
+ "eslint": "10.14.0",
101
99
  "eslint-plugin-sonarjs": "4.2.2",
102
- "typedoc": "0.27.9",
103
- "typescript": "5.7.3",
104
- "typescript-eslint": "8.72.0"
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
  }