ipx 4.0.0-beta.1 → 4.0.0
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/README.md +222 -209
- package/dist/THIRD-PARTY-LICENSES.md.gz +0 -0
- package/dist/_chunks/libs/@fastify/accept-negotiator.mjs +22 -23
- package/dist/_chunks/libs/css-select.mjs +1077 -937
- package/dist/_chunks/libs/css-tree.mjs +107 -191
- package/dist/_chunks/libs/csso.mjs +50 -82
- package/dist/_chunks/libs/h3.mjs +107 -106
- package/dist/_chunks/libs/image-meta.d.mts +2 -2
- package/dist/_chunks/libs/image-meta.mjs +464 -305
- package/dist/_chunks/libs/sax.mjs +61 -60
- package/dist/_chunks/libs/svgo.mjs +933 -1008
- package/dist/_chunks/node-fs.mjs +125 -49
- package/dist/_chunks/rolldown-runtime.mjs +2 -11
- package/dist/cli.mjs +4 -3
- package/dist/index.d.mts +64 -11
- package/package.json +30 -29
- package/dist/THIRD-PARTY-LICENSES.md +0 -593
|
@@ -1,58 +1,79 @@
|
|
|
1
1
|
const e = new TextDecoder(), t = (t, n = 0, r = t.length) => e.decode(t.slice(n, r)), n = (e, t = 0, n = e.length) => e.slice(t, n).reduce((e, t) => e + (`0` + t.toString(16)).slice(-2), ``), r = (e, t = 0) => {
|
|
2
|
-
let n = e[t] + e[t + 1] *
|
|
3
|
-
return n
|
|
4
|
-
}, i = (e, t = 0) => e[t] *
|
|
2
|
+
let n = e[t] + e[t + 1] * 256;
|
|
3
|
+
return n >= 2 ** 15 ? n - 2 ** 16 : n;
|
|
4
|
+
}, i = (e, t = 0) => e[t] * 256 + e[t + 1], a = (e, t = 0) => e[t] + e[t + 1] * 256, o = (e, t = 0) => e[t] + e[t + 1] * 256 + e[t + 2] * 2 ** 16, s = (e, t = 0) => {
|
|
5
|
+
let n = l(e, t);
|
|
6
|
+
return n >= 2 ** 31 ? n - 2 ** 32 : n;
|
|
7
|
+
}, c = (e, t = 0) => e[t] * 2 ** 24 + e[t + 1] * 2 ** 16 + e[t + 2] * 256 + e[t + 3], l = (e, t = 0) => e[t] + e[t + 1] * 256 + e[t + 2] * 2 ** 16 + e[t + 3] * 2 ** 24, ee = {
|
|
5
8
|
readUInt16BE: i,
|
|
6
9
|
readUInt16LE: a,
|
|
7
10
|
readUInt32BE: c,
|
|
8
11
|
readUInt32LE: l
|
|
9
12
|
};
|
|
10
|
-
function
|
|
13
|
+
function u(e, t, n, r) {
|
|
11
14
|
n ||= 0;
|
|
12
15
|
let i = r ? `BE` : `LE`, a = `readUInt` + t + i;
|
|
13
|
-
return
|
|
16
|
+
return ee[a](e, n);
|
|
14
17
|
}
|
|
15
|
-
const
|
|
18
|
+
const te = new TextEncoder(), d = (e) => c(te.encode(e));
|
|
19
|
+
function f(e, t, n = 0, r = e.length) {
|
|
20
|
+
let i = d(t), a = n;
|
|
21
|
+
for (; a + 8 <= r;) {
|
|
22
|
+
let t = c(e, a);
|
|
23
|
+
if (t < 8 || a + t > r) return;
|
|
24
|
+
if (c(e, a + 4) === i) return {
|
|
25
|
+
offset: a,
|
|
26
|
+
size: t
|
|
27
|
+
};
|
|
28
|
+
a += t;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const ne = {
|
|
16
32
|
validate: (e) => t(e, 0, 2) === `BM`,
|
|
17
|
-
calculate: (e) => ({
|
|
33
|
+
calculate: (e) => l(e, 14) === 12 ? {
|
|
34
|
+
height: a(e, 20),
|
|
35
|
+
width: a(e, 18)
|
|
36
|
+
} : {
|
|
18
37
|
height: Math.abs(s(e, 22)),
|
|
19
|
-
width:
|
|
20
|
-
}
|
|
38
|
+
width: s(e, 18)
|
|
39
|
+
}
|
|
21
40
|
};
|
|
22
|
-
function
|
|
41
|
+
function p(e, t) {
|
|
23
42
|
let n = e[t];
|
|
24
43
|
return n === 0 ? 256 : n;
|
|
25
44
|
}
|
|
26
|
-
function
|
|
45
|
+
function m(e, t) {
|
|
27
46
|
let n = 6 + t * 16;
|
|
28
47
|
return {
|
|
29
|
-
height:
|
|
30
|
-
width:
|
|
48
|
+
height: p(e, n + 1),
|
|
49
|
+
width: p(e, n)
|
|
31
50
|
};
|
|
32
51
|
}
|
|
33
|
-
const
|
|
52
|
+
const h = {
|
|
34
53
|
validate(e) {
|
|
35
54
|
let t = a(e, 0), n = a(e, 4);
|
|
36
55
|
return t !== 0 || n === 0 ? !1 : a(e, 2) === 1;
|
|
37
56
|
},
|
|
38
57
|
calculate(e) {
|
|
39
|
-
let t = a(e, 4)
|
|
58
|
+
let t = a(e, 4);
|
|
59
|
+
if (6 + t * 16 > e.length) throw TypeError(`Invalid ICO`);
|
|
60
|
+
let n = m(e, 0);
|
|
40
61
|
if (t === 1) return n;
|
|
41
62
|
let r = [n];
|
|
42
|
-
for (let n = 1; n < t; n += 1) r.push(
|
|
63
|
+
for (let n = 1; n < t; n += 1) r.push(m(e, n));
|
|
43
64
|
return {
|
|
44
65
|
height: n.height,
|
|
45
66
|
images: r,
|
|
46
67
|
width: n.width
|
|
47
68
|
};
|
|
48
69
|
}
|
|
49
|
-
},
|
|
70
|
+
}, re = {
|
|
50
71
|
validate(e) {
|
|
51
72
|
let t = a(e, 0), n = a(e, 4);
|
|
52
73
|
return t !== 0 || n === 0 ? !1 : a(e, 2) === 2;
|
|
53
74
|
},
|
|
54
|
-
calculate: (e) =>
|
|
55
|
-
},
|
|
75
|
+
calculate: (e) => h.calculate(e)
|
|
76
|
+
}, ie = {
|
|
56
77
|
validate: (e) => l(e, 0) === 542327876,
|
|
57
78
|
calculate: (e) => ({
|
|
58
79
|
height: l(e, 12),
|
|
@@ -64,65 +85,60 @@ const m = {
|
|
|
64
85
|
height: a(e, 8),
|
|
65
86
|
width: a(e, 6)
|
|
66
87
|
})
|
|
67
|
-
}, v =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (!n) throw TypeError(`heic: iprp box not found`);
|
|
86
|
-
let r = y(e, `ipco`, n.offset + 8, n.offset + n.size);
|
|
87
|
-
if (!r) throw TypeError(`heic: ipco box not found`);
|
|
88
|
-
let i = b(e, `ispe`, r.offset + 8, r.offset + r.size).map((t) => ({
|
|
89
|
-
width: c(e, t.offset + 12),
|
|
90
|
-
height: c(e, t.offset + 16)
|
|
91
|
-
}));
|
|
92
|
-
if (i.length === 0) throw TypeError(`heic: ispe box not found`);
|
|
93
|
-
let a = i[0];
|
|
94
|
-
for (let e = 1; e < i.length; e++) {
|
|
95
|
-
let t = i[e];
|
|
96
|
-
t.width * t.height > a.width * a.height && (a = t);
|
|
88
|
+
}, v = d(`ftyp`), y = d(`ispe`), ae = d(`clap`);
|
|
89
|
+
function b(e, t) {
|
|
90
|
+
return !e || t.width * t.height > e.width * e.height ? t : e;
|
|
91
|
+
}
|
|
92
|
+
function oe(e) {
|
|
93
|
+
let t = f(e, `meta`), n = t && f(e, `iprp`, t.offset + 12, t.offset + t.size), r = n && f(e, `ipco`, n.offset + 8, n.offset + n.size);
|
|
94
|
+
if (!r) throw TypeError(`Invalid HEIF, no ipco box found`);
|
|
95
|
+
let i, a, o = r.offset + r.size, s = r.offset + 8;
|
|
96
|
+
for (; s + 8 <= o;) {
|
|
97
|
+
let t = c(e, s);
|
|
98
|
+
if (t < 8 || s + t > o) throw TypeError(`Invalid HEIF, corrupt ipco box`);
|
|
99
|
+
let n = c(e, s + 4);
|
|
100
|
+
if (n === y) {
|
|
101
|
+
if (t < 20) throw TypeError(`Invalid HEIF, corrupt ispe box`);
|
|
102
|
+
a && (i = b(i, a)), a = {
|
|
103
|
+
width: c(e, s + 12),
|
|
104
|
+
height: c(e, s + 16)
|
|
105
|
+
};
|
|
97
106
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
for (; a < i;) {
|
|
104
|
-
let r = c(e, a);
|
|
105
|
-
if (t(e, a + 4, a + 8) === n) return {
|
|
106
|
-
offset: a,
|
|
107
|
-
size: r
|
|
108
|
-
};
|
|
109
|
-
if (r <= 0 || a + r > i) break;
|
|
110
|
-
a += r;
|
|
107
|
+
if (n === ae && t >= 24 && a) {
|
|
108
|
+
let t = c(e, s + 12), n = c(e, s + 20);
|
|
109
|
+
t > 0 && n > 0 && (a.width = Math.round(c(e, s + 8) / t), a.height = Math.round(c(e, s + 16) / n));
|
|
110
|
+
}
|
|
111
|
+
s += t;
|
|
111
112
|
}
|
|
113
|
+
if (!a) throw TypeError(`Invalid HEIF, no ispe box found`);
|
|
114
|
+
return b(i, a);
|
|
112
115
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
const x = new Set([`avif`, `avis`].map((e) => d(e)));
|
|
117
|
+
function S(e) {
|
|
118
|
+
let n = c(e, 0);
|
|
119
|
+
if (c(e, 4) !== v || n < 12 || n > e.length) return;
|
|
120
|
+
if (x.has(c(e, 8))) return `avif`;
|
|
121
|
+
let r = t(e, 8, 12);
|
|
122
|
+
if ([
|
|
123
|
+
`mif1`,
|
|
124
|
+
`msf1`,
|
|
125
|
+
`miaf`
|
|
126
|
+
].includes(r)) {
|
|
127
|
+
for (let t = 16; t + 4 <= n; t += 4) if (x.has(c(e, t))) return `avif`;
|
|
122
128
|
}
|
|
123
|
-
return
|
|
129
|
+
return [
|
|
130
|
+
`heic`,
|
|
131
|
+
`heix`,
|
|
132
|
+
`hevc`,
|
|
133
|
+
`hevx`,
|
|
134
|
+
`mif1`,
|
|
135
|
+
`msf1`
|
|
136
|
+
].includes(r) ? `heic` : void 0;
|
|
124
137
|
}
|
|
125
|
-
const
|
|
138
|
+
const C = {
|
|
139
|
+
validate: (e) => S(e) === `heic`,
|
|
140
|
+
calculate: (e) => oe(e)
|
|
141
|
+
}, w = {
|
|
126
142
|
ICON: 32,
|
|
127
143
|
"ICN#": 32,
|
|
128
144
|
"icm#": 16,
|
|
@@ -134,18 +150,24 @@ const x = {
|
|
|
134
150
|
is32: 16,
|
|
135
151
|
s8mk: 16,
|
|
136
152
|
icp4: 16,
|
|
153
|
+
ic04: 16,
|
|
154
|
+
icsb: 18,
|
|
155
|
+
sb24: 24,
|
|
137
156
|
icl4: 32,
|
|
138
157
|
icl8: 32,
|
|
139
158
|
il32: 32,
|
|
140
159
|
l8mk: 32,
|
|
141
160
|
icp5: 32,
|
|
161
|
+
ic05: 32,
|
|
142
162
|
ic11: 32,
|
|
163
|
+
icsB: 36,
|
|
143
164
|
ich4: 48,
|
|
144
165
|
ich8: 48,
|
|
145
166
|
ih32: 48,
|
|
146
167
|
h8mk: 48,
|
|
168
|
+
SB24: 48,
|
|
147
169
|
icp6: 64,
|
|
148
|
-
ic12:
|
|
170
|
+
ic12: 64,
|
|
149
171
|
it32: 128,
|
|
150
172
|
t8mk: 128,
|
|
151
173
|
ic07: 128,
|
|
@@ -154,131 +176,219 @@ const x = {
|
|
|
154
176
|
ic09: 512,
|
|
155
177
|
ic14: 512,
|
|
156
178
|
ic10: 1024
|
|
157
|
-
};
|
|
158
|
-
function
|
|
159
|
-
let
|
|
160
|
-
|
|
179
|
+
}, se = new Map(Object.keys(w).map((e) => [d(e), e]));
|
|
180
|
+
function ce(e, t) {
|
|
181
|
+
let n = t + 4;
|
|
182
|
+
if (n + 4 > e.length) throw TypeError(`Invalid ICNS`);
|
|
183
|
+
let r = c(e, n);
|
|
184
|
+
if (r < 8) throw TypeError(`Invalid ICNS`);
|
|
185
|
+
return [se.get(c(e, t)), r];
|
|
161
186
|
}
|
|
162
|
-
function
|
|
163
|
-
let t =
|
|
187
|
+
function le(e) {
|
|
188
|
+
let t = w[e];
|
|
164
189
|
return {
|
|
165
190
|
width: t,
|
|
166
191
|
height: t,
|
|
167
192
|
type: e
|
|
168
193
|
};
|
|
169
194
|
}
|
|
170
|
-
const
|
|
195
|
+
const ue = {
|
|
171
196
|
validate: (e) => t(e, 0, 4) === `icns`,
|
|
172
197
|
calculate(e) {
|
|
173
|
-
let t = e.length, n = c(e, 4), r = 8, i =
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
198
|
+
let t = e.length, n = c(e, 4), r = 8, i = [], a = /* @__PURE__ */ new Set();
|
|
199
|
+
for (; r < n && r < t;) {
|
|
200
|
+
let [t, n] = ce(e, r);
|
|
201
|
+
r += n, t !== void 0 && !a.has(t) && (a.add(t), i.push(le(t)));
|
|
202
|
+
}
|
|
203
|
+
if (i.length === 0) throw TypeError(`Invalid ICNS, no icons found`);
|
|
204
|
+
return i.length === 1 ? i[0] : {
|
|
205
|
+
height: i[0].height,
|
|
206
|
+
images: i,
|
|
207
|
+
width: i[0].width
|
|
179
208
|
};
|
|
180
|
-
for (; r < n && r < t;) i = S(e, r), a = C(i[0]), r += i[1], o.images.push(a);
|
|
181
|
-
return o;
|
|
182
209
|
}
|
|
183
|
-
},
|
|
184
|
-
validate: (e) =>
|
|
210
|
+
}, de = {
|
|
211
|
+
validate: (e) => c(e, 0) === 4283432785,
|
|
185
212
|
calculate: (e) => ({
|
|
186
|
-
height: c(e, 12),
|
|
187
|
-
width: c(e, 8)
|
|
213
|
+
height: c(e, 12) - c(e, 20),
|
|
214
|
+
width: c(e, 8) - c(e, 16)
|
|
188
215
|
})
|
|
189
|
-
},
|
|
190
|
-
ftyp: `66747970`,
|
|
191
|
-
jp2h: `6a703268`,
|
|
192
|
-
jp__: `6a502020`,
|
|
193
|
-
rreq: `72726571`
|
|
194
|
-
}, ie = (e) => {
|
|
195
|
-
let t = e[0], n = 1 + 2 * t, r = i(e, n) * (2 + t);
|
|
196
|
-
n = n + 2 + r;
|
|
197
|
-
let a = i(e, n) * (16 + t);
|
|
198
|
-
return n + 2 + a;
|
|
199
|
-
}, T = (e) => ({
|
|
200
|
-
height: c(e, 4),
|
|
201
|
-
width: c(e, 8)
|
|
202
|
-
}), E = {
|
|
216
|
+
}, fe = {
|
|
203
217
|
validate(e) {
|
|
204
|
-
|
|
205
|
-
if (t !== w.jp__ || r < 1) return !1;
|
|
206
|
-
let i = r + 4, a = c(e, r), o = e.slice(i, i + a);
|
|
207
|
-
return n(o, 0, 4) === w.ftyp;
|
|
218
|
+
return t(e, 4, 8) === `jP ` && f(e, `ftyp`) !== void 0;
|
|
208
219
|
},
|
|
209
220
|
calculate(e) {
|
|
210
|
-
let
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
221
|
+
let t = f(e, `jp2h`), n = t && f(e, `ihdr`, t.offset + 8, t.offset + t.size);
|
|
222
|
+
if (!n || n.size < 16) throw TypeError(`Invalid JPEG 2000, no ihdr box found`);
|
|
223
|
+
return {
|
|
224
|
+
height: c(e, n.offset + 8),
|
|
225
|
+
width: c(e, n.offset + 12)
|
|
226
|
+
};
|
|
216
227
|
}
|
|
217
|
-
};
|
|
218
|
-
function
|
|
219
|
-
return
|
|
228
|
+
}, pe = d(`Exif`);
|
|
229
|
+
function me(e) {
|
|
230
|
+
return c(e, 2) === pe;
|
|
220
231
|
}
|
|
221
|
-
function
|
|
232
|
+
function he(e, t) {
|
|
222
233
|
return {
|
|
223
234
|
height: i(e, t),
|
|
224
235
|
width: i(e, t + 2)
|
|
225
236
|
};
|
|
226
237
|
}
|
|
227
|
-
function
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
238
|
+
function ge(e, t) {
|
|
239
|
+
if (u(e, 16, 8, t) !== 42) return;
|
|
240
|
+
let n = u(e, 32, 10, t), r = 6 + n;
|
|
241
|
+
if (!(n >= 8 && r + 2 <= e.length)) return;
|
|
242
|
+
let i = u(e, 16, r, t);
|
|
243
|
+
for (let n = 0; n < i; n++) {
|
|
244
|
+
let i = r + 2 + n * 12, a = i + 12;
|
|
245
|
+
if (i > e.length) return;
|
|
246
|
+
let o = e.slice(i, a);
|
|
247
|
+
if (u(o, 16, 0, t) === 274) return u(o, 16, 2, t) !== 3 || u(o, 32, 4, t) !== 1 ? void 0 : u(o, 16, 8, t);
|
|
234
248
|
}
|
|
235
249
|
}
|
|
236
|
-
function
|
|
237
|
-
let
|
|
238
|
-
if (a ||
|
|
250
|
+
function _e(e, t) {
|
|
251
|
+
let n = e.slice(2, t), r = i(n, 6), a = r === 19789;
|
|
252
|
+
if (a || r === 18761) return ge(n, a);
|
|
239
253
|
}
|
|
240
|
-
function
|
|
254
|
+
function ve(e, t) {
|
|
241
255
|
if (t > e.length) throw TypeError(`Corrupt JPG, exceeded buffer limits`);
|
|
242
|
-
if (e[t] !== 255) throw TypeError(`Invalid JPG, marker table corrupted`);
|
|
243
256
|
}
|
|
244
|
-
|
|
257
|
+
function T(e, t) {
|
|
258
|
+
let n = e.indexOf(255, t);
|
|
259
|
+
for (; n !== -1;) {
|
|
260
|
+
for (; e[n + 1] === 255;) n++;
|
|
261
|
+
if (e[n + 1] !== 0) return n;
|
|
262
|
+
n = e.indexOf(255, n + 2);
|
|
263
|
+
}
|
|
264
|
+
throw TypeError(`Invalid JPG, marker table corrupted`);
|
|
265
|
+
}
|
|
266
|
+
const E = {
|
|
245
267
|
validate: (e) => n(e, 0, 2) === `ffd8`,
|
|
246
268
|
calculate(e) {
|
|
247
|
-
e = e.
|
|
269
|
+
e = e.subarray(2);
|
|
248
270
|
let t, n;
|
|
249
271
|
for (; e.length > 0;) {
|
|
250
|
-
let r =
|
|
251
|
-
if (
|
|
252
|
-
let n =
|
|
272
|
+
let r = T(e, 0);
|
|
273
|
+
if (n = e[r + 1], n >= 192 && n <= 195 || n >= 201 && n <= 203) {
|
|
274
|
+
let n = he(e, r + 5);
|
|
253
275
|
return t ? {
|
|
254
276
|
height: n.height,
|
|
255
277
|
orientation: t,
|
|
256
278
|
width: n.width
|
|
257
279
|
} : n;
|
|
258
280
|
}
|
|
259
|
-
|
|
281
|
+
if (n === 218) break;
|
|
282
|
+
e = e.subarray(r + 2);
|
|
283
|
+
let a = i(e, 0);
|
|
284
|
+
ve(e, a), me(e) && (t = _e(e, a)), e = e.subarray(a);
|
|
260
285
|
}
|
|
261
286
|
throw TypeError(`Invalid JPG, no size found`);
|
|
262
287
|
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
288
|
+
};
|
|
289
|
+
function D(e) {
|
|
290
|
+
let t = 16;
|
|
291
|
+
return (n) => {
|
|
292
|
+
let r = 0;
|
|
293
|
+
for (let i = 0; i < n; i++, t++) {
|
|
294
|
+
let n = e[t >> 3];
|
|
295
|
+
if (n === void 0) throw TypeError(`Invalid JXL, truncated codestream`);
|
|
296
|
+
r += (n >> (t & 7) & 1) * 2 ** i;
|
|
297
|
+
}
|
|
298
|
+
return r;
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
const O = [
|
|
302
|
+
[1, 1],
|
|
303
|
+
[12, 10],
|
|
304
|
+
[4, 3],
|
|
305
|
+
[3, 2],
|
|
306
|
+
[16, 9],
|
|
307
|
+
[5, 4],
|
|
308
|
+
[2, 1]
|
|
309
|
+
];
|
|
310
|
+
function k(e) {
|
|
311
|
+
let t = D(e), n = (e) => e ? 8 * (1 + t(5)) : 1 + t([
|
|
312
|
+
9,
|
|
313
|
+
13,
|
|
314
|
+
18,
|
|
315
|
+
30
|
|
316
|
+
][t(2)]), r = t(1) === 1, i = n(r), a = t(3);
|
|
317
|
+
if (a === 0) return {
|
|
318
|
+
height: i,
|
|
319
|
+
width: n(r)
|
|
320
|
+
};
|
|
321
|
+
let [o, s] = O[a - 1];
|
|
322
|
+
return {
|
|
323
|
+
height: i,
|
|
324
|
+
width: Math.floor(i * o / s)
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
const A = d(`jxlc`), j = d(`jxlp`);
|
|
328
|
+
function M(e) {
|
|
329
|
+
let t = [], n = 0, r = 0;
|
|
330
|
+
for (; r + 8 <= e.length && n < 32;) {
|
|
331
|
+
let i = c(e, r), a = c(e, r + 4), o = 8;
|
|
332
|
+
if (i === 1) {
|
|
333
|
+
if (r + 16 > e.length) break;
|
|
334
|
+
i = c(e, r + 8) * 2 ** 32 + c(e, r + 12), o = 16;
|
|
335
|
+
} else i === 0 && (i = e.length - r);
|
|
336
|
+
if (a === A || a === j) {
|
|
337
|
+
let s = r + o + (a === j ? 4 : 0);
|
|
338
|
+
if (i < s - r) throw TypeError(`Invalid JXL, corrupt ${a === j ? `jxlp` : `jxlc`} box`);
|
|
339
|
+
let c = Math.min(r + i, e.length, s + 32 - n);
|
|
340
|
+
if (c > s && (t.push(e.subarray(s, c)), n += c - s), a === A) break;
|
|
341
|
+
}
|
|
342
|
+
if (i < o) throw TypeError(`Invalid JXL, corrupt box`);
|
|
343
|
+
r += i;
|
|
344
|
+
}
|
|
345
|
+
let i = new Uint8Array(n), a = 0;
|
|
346
|
+
for (let e of t) i.set(e, a), a += e.length;
|
|
347
|
+
return i;
|
|
348
|
+
}
|
|
349
|
+
const N = (e) => n(e, 0, 2) === `ff0a`, P = {
|
|
350
|
+
validate: (e) => {
|
|
351
|
+
if (N(e)) return !0;
|
|
352
|
+
if (t(e, 4, 8) !== `JXL `) return !1;
|
|
353
|
+
let n = f(e, `ftyp`);
|
|
354
|
+
return n !== void 0 && t(e, n.offset + 8, n.offset + 12) === `jxl `;
|
|
355
|
+
},
|
|
356
|
+
calculate: (e) => {
|
|
357
|
+
let t = N(e) ? e : M(e);
|
|
358
|
+
if (!N(t)) throw TypeError(`Invalid JXL, no codestream found`);
|
|
359
|
+
return k(t);
|
|
360
|
+
}
|
|
361
|
+
}, F = 16909060, ye = {
|
|
362
|
+
validate: (e) => {
|
|
363
|
+
let n = t(e, 1, 7);
|
|
364
|
+
return n === `KTX 11` || n === `KTX 20`;
|
|
365
|
+
},
|
|
366
|
+
calculate: (e) => {
|
|
367
|
+
if (e[5] === 50) return {
|
|
368
|
+
height: l(e, 24),
|
|
369
|
+
width: l(e, 20)
|
|
370
|
+
};
|
|
371
|
+
let t = l(e, 12);
|
|
372
|
+
if (t !== 67305985 && t !== F) throw TypeError(`Invalid KTX, unknown endianness`);
|
|
373
|
+
let n = t === F;
|
|
374
|
+
return {
|
|
375
|
+
height: u(e, 32, 40, n),
|
|
376
|
+
width: u(e, 32, 36, n)
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
}, I = `CgBI`, be = {
|
|
270
380
|
validate(e) {
|
|
271
381
|
if (t(e, 1, 8) === `PNG\r
|
|
272
382
|
|
|
273
383
|
`) {
|
|
274
384
|
let n = t(e, 12, 16);
|
|
275
|
-
if (n ===
|
|
385
|
+
if (n === I && (n = t(e, 28, 32)), n !== `IHDR`) throw TypeError(`Invalid PNG`);
|
|
276
386
|
return !0;
|
|
277
387
|
}
|
|
278
388
|
return !1;
|
|
279
389
|
},
|
|
280
390
|
calculate(e) {
|
|
281
|
-
return t(e, 12, 16) ===
|
|
391
|
+
return t(e, 12, 16) === I ? {
|
|
282
392
|
height: c(e, 36),
|
|
283
393
|
width: c(e, 32)
|
|
284
394
|
} : {
|
|
@@ -286,7 +396,7 @@ const M = {
|
|
|
286
396
|
width: c(e, 16)
|
|
287
397
|
};
|
|
288
398
|
}
|
|
289
|
-
},
|
|
399
|
+
}, L = {
|
|
290
400
|
P1: `pbm/ascii`,
|
|
291
401
|
P2: `pgm/ascii`,
|
|
292
402
|
P3: `ppm/ascii`,
|
|
@@ -294,115 +404,161 @@ const M = {
|
|
|
294
404
|
P5: `pgm`,
|
|
295
405
|
P6: `ppm`,
|
|
296
406
|
P7: `pam`,
|
|
297
|
-
PF: `pfm
|
|
298
|
-
|
|
407
|
+
PF: `pfm`,
|
|
408
|
+
Pf: `pfm`
|
|
409
|
+
}, R = (e) => e === 10 || e === 13, xe = (e) => e === 32 || e >= 9 && e <= 13, z = (e = ``) => /^\d+$/.test(e) ? Number(e) : NaN, Se = /^\s*(width|height|endhdr)(?!\S)\s*(\S*)/i, B = {
|
|
299
410
|
default: (e) => {
|
|
300
|
-
let t =
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
t = n.split(` `);
|
|
305
|
-
break;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
if (t.length === 2) return {
|
|
309
|
-
height: Number.parseInt(t[1], 10),
|
|
310
|
-
width: Number.parseInt(t[0], 10)
|
|
411
|
+
let [t, n] = V(e, `tokens`);
|
|
412
|
+
return {
|
|
413
|
+
height: z(n),
|
|
414
|
+
width: z(t)
|
|
311
415
|
};
|
|
312
|
-
throw TypeError(`Invalid PNM`);
|
|
313
416
|
},
|
|
314
417
|
pam: (e) => {
|
|
315
418
|
let t = {};
|
|
316
|
-
for (
|
|
317
|
-
let n = e.
|
|
318
|
-
if (
|
|
319
|
-
let [r, i] = n.split(` `);
|
|
320
|
-
if (r && i && (t[r.toLowerCase()] = Number.parseInt(i, 10)), t.height && t.width) break;
|
|
419
|
+
for (let n of V(e, `lines`)) {
|
|
420
|
+
let [, e = ``, r] = Se.exec(n) || [], i = e.toLowerCase();
|
|
421
|
+
if ((i === `width` || i === `height`) && (t[i] = z(r)), i === `endhdr` || `width` in t && `height` in t) break;
|
|
321
422
|
}
|
|
322
|
-
|
|
423
|
+
return {
|
|
323
424
|
height: t.height,
|
|
324
425
|
width: t.width
|
|
325
426
|
};
|
|
326
|
-
throw TypeError(`Invalid PAM`);
|
|
327
427
|
}
|
|
328
|
-
}
|
|
329
|
-
|
|
428
|
+
};
|
|
429
|
+
function* V(e, n) {
|
|
430
|
+
let r = n === `lines` ? R : xe, i = n === `lines` ? /[^\n\r]+/g : /[^\t-\r ]+/g, a = 2;
|
|
431
|
+
for (; a < e.length;) {
|
|
432
|
+
let n = a, o = a, s = !1;
|
|
433
|
+
for (; n < e.length && (n - a < 1024 || o === a);) {
|
|
434
|
+
let t = e[n++];
|
|
435
|
+
s = t === 35 || s && !R(t), !s && r(t) && (o = n);
|
|
436
|
+
}
|
|
437
|
+
n === e.length && (o = n), yield* t(e, a, o).replace(/#[^\n\r]*/g, `
|
|
438
|
+
`).match(i) || [], a = o;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
const Ce = {
|
|
442
|
+
validate: (e) => t(e, 0, 2) in L,
|
|
330
443
|
calculate(e) {
|
|
331
|
-
let n = t(e, 0, 2), r =
|
|
332
|
-
return (
|
|
444
|
+
let n = t(e, 0, 2), r = L[n];
|
|
445
|
+
return (B[r] || B.default)(e);
|
|
333
446
|
}
|
|
334
|
-
},
|
|
447
|
+
}, we = {
|
|
335
448
|
validate: (e) => t(e, 0, 4) === `8BPS`,
|
|
336
449
|
calculate: (e) => ({
|
|
337
450
|
height: c(e, 14),
|
|
338
451
|
width: c(e, 18)
|
|
339
452
|
})
|
|
340
|
-
},
|
|
453
|
+
}, Te = /<svg\s([^"'>]|"[^"]*"|'[^']*')*>/, Ee = /<!--[\s\S]*?(?:-->|$)/g, H = {
|
|
341
454
|
height: /\sheight=(["'])([^%]+?)\1/,
|
|
342
|
-
|
|
343
|
-
viewbox: /\sviewbox=(["'])(.+?)\1/i,
|
|
455
|
+
viewbox: /\sviewbox=(["'])([\s\S]+?)\1/i,
|
|
344
456
|
width: /\swidth=(["'])([^%]+?)\1/
|
|
345
|
-
},
|
|
457
|
+
}, U = [
|
|
458
|
+
60,
|
|
459
|
+
115,
|
|
460
|
+
118,
|
|
461
|
+
103
|
|
462
|
+
], De = /^(?:\u00C2\u00A0|\u00E1\u009A\u0080|\u00E2\u0080[\u0080-\u008A\u00A8\u00A9\u00AF]|\u00E2\u0081\u009F|\u00E3\u0080\u0080|\u00EF\u00BB\u00BF)/;
|
|
463
|
+
function Oe(e, t) {
|
|
464
|
+
let n = e[t];
|
|
465
|
+
if (n < 128) return n === 32 || n >= 9 && n <= 13;
|
|
466
|
+
let r = String.fromCharCode(n, e[t + 1], e[t + 2]);
|
|
467
|
+
return De.test(r);
|
|
468
|
+
}
|
|
469
|
+
const W = (e, t) => e[t] === 60 && t + 3 < e.length && e[t + 1] === 33 && e[t + 2] === 45 && e[t + 3] === 45;
|
|
470
|
+
function G(e, t) {
|
|
471
|
+
for (let n = t + 4; n + 2 < e.length; n++) if (e[n] === 45 && e[n + 1] === 45 && e[n + 2] === 62) return n + 3;
|
|
472
|
+
return e.length;
|
|
473
|
+
}
|
|
474
|
+
function ke(e) {
|
|
475
|
+
let n = e.length, r = 0, i = 0, a = 0;
|
|
476
|
+
for (; i < n;) {
|
|
477
|
+
let t = e[i];
|
|
478
|
+
if (t === 60 && W(e, i)) i = G(e, i);
|
|
479
|
+
else {
|
|
480
|
+
if (a === U.length && Oe(e, i)) break;
|
|
481
|
+
t === 60 ? (r = i, a = 1) : a < U.length && t === U[a] ? a++ : a = 0, i++;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
let o = 0;
|
|
485
|
+
for (i++; i < n; i++) {
|
|
486
|
+
let t = e[i];
|
|
487
|
+
if (t === 60 && W(e, i)) i = G(e, i) - 1;
|
|
488
|
+
else if (o) t === o && (o = 0);
|
|
489
|
+
else if (t === 34 || t === 39) o = t;
|
|
490
|
+
else if (t === 62) break;
|
|
491
|
+
}
|
|
492
|
+
if (!(i >= n)) try {
|
|
493
|
+
return t(e, r, i + 1).replace(Ee, ``);
|
|
494
|
+
} catch {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
const K = 2.54, q = {
|
|
346
499
|
in: 96,
|
|
347
|
-
cm: 96 /
|
|
500
|
+
cm: 96 / K,
|
|
348
501
|
em: 16,
|
|
349
502
|
ex: 8,
|
|
350
|
-
m: 96 /
|
|
351
|
-
mm: 96 /
|
|
352
|
-
pc:
|
|
503
|
+
m: 96 / K * 100,
|
|
504
|
+
mm: 96 / K / 10,
|
|
505
|
+
pc: 16,
|
|
353
506
|
pt: 96 / 72,
|
|
354
507
|
px: 1
|
|
355
|
-
},
|
|
356
|
-
function
|
|
357
|
-
let t =
|
|
358
|
-
if (t) return
|
|
508
|
+
}, Ae = RegExp(`^([0-9.]+(?:e\\d+)?)(${Object.keys(q).join(`|`)})?$`);
|
|
509
|
+
function J(e) {
|
|
510
|
+
let t = Ae.exec(e);
|
|
511
|
+
if (t) return Number(t[1]) * (q[t[2]] || 1);
|
|
359
512
|
}
|
|
360
|
-
function
|
|
361
|
-
let t = e.split(
|
|
513
|
+
function je(e) {
|
|
514
|
+
let t = e.trim().split(/[\s,]+/, 4);
|
|
362
515
|
return {
|
|
363
|
-
height:
|
|
364
|
-
width:
|
|
516
|
+
height: J(t[3]),
|
|
517
|
+
width: J(t[2])
|
|
365
518
|
};
|
|
366
519
|
}
|
|
367
|
-
function
|
|
368
|
-
let t = e.match(
|
|
520
|
+
function Me(e) {
|
|
521
|
+
let t = e.match(H.width), n = e.match(H.height), r = e.match(H.viewbox);
|
|
369
522
|
return {
|
|
370
|
-
height: n &&
|
|
371
|
-
viewbox: r &&
|
|
372
|
-
width: t &&
|
|
523
|
+
height: n && Math.round(J(n[2])),
|
|
524
|
+
viewbox: r && je(r[2]),
|
|
525
|
+
width: t && Math.round(J(t[2]))
|
|
373
526
|
};
|
|
374
527
|
}
|
|
375
|
-
function
|
|
528
|
+
function Ne(e) {
|
|
376
529
|
return {
|
|
377
530
|
height: e.height,
|
|
378
531
|
width: e.width
|
|
379
532
|
};
|
|
380
533
|
}
|
|
381
|
-
function Y(e
|
|
382
|
-
|
|
534
|
+
function Y(e) {
|
|
535
|
+
return Math.max(1, Math.round(e));
|
|
536
|
+
}
|
|
537
|
+
function Pe(e, t) {
|
|
538
|
+
let n = t.width, r = t.height;
|
|
383
539
|
return e.width ? {
|
|
384
|
-
height:
|
|
540
|
+
height: Y(e.width * r / n),
|
|
385
541
|
width: e.width
|
|
386
542
|
} : e.height ? {
|
|
387
543
|
height: e.height,
|
|
388
|
-
width:
|
|
544
|
+
width: Y(e.height * n / r)
|
|
389
545
|
} : {
|
|
390
|
-
height:
|
|
391
|
-
width:
|
|
546
|
+
height: Y(r),
|
|
547
|
+
width: Y(n)
|
|
392
548
|
};
|
|
393
549
|
}
|
|
394
|
-
const
|
|
395
|
-
validate: (e) =>
|
|
550
|
+
const Fe = {
|
|
551
|
+
validate: (e) => Te.test(t(e, 0, 1e3)),
|
|
396
552
|
calculate(e) {
|
|
397
|
-
let
|
|
398
|
-
if (
|
|
399
|
-
let e =
|
|
400
|
-
if (e.width && e.height) return
|
|
401
|
-
if (e.viewbox) return
|
|
553
|
+
let t = ke(e);
|
|
554
|
+
if (t) {
|
|
555
|
+
let e = Me(t);
|
|
556
|
+
if (e.width && e.height) return Ne(e);
|
|
557
|
+
if (e.viewbox?.width && e.viewbox.height) return Pe(e, e.viewbox);
|
|
402
558
|
}
|
|
403
559
|
throw TypeError(`Invalid SVG`);
|
|
404
560
|
}
|
|
405
|
-
},
|
|
561
|
+
}, Ie = {
|
|
406
562
|
validate(e) {
|
|
407
563
|
return a(e, 0) === 0 && a(e, 4) === 0;
|
|
408
564
|
},
|
|
@@ -413,120 +569,118 @@ const ae = {
|
|
|
413
569
|
};
|
|
414
570
|
}
|
|
415
571
|
};
|
|
416
|
-
function
|
|
417
|
-
let
|
|
418
|
-
return
|
|
419
|
-
}
|
|
420
|
-
function ce(e, t) {
|
|
421
|
-
let n = d(e, 16, 8, t);
|
|
422
|
-
return (d(e, 16, 10, t) << 16) + n;
|
|
572
|
+
function X(e, t, n) {
|
|
573
|
+
let r = u(e, 32, t + (n ? 0 : 4), n), i = u(e, 32, t + (n ? 4 : 0), n);
|
|
574
|
+
return r * 2 ** 32 + i;
|
|
423
575
|
}
|
|
424
|
-
function
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
576
|
+
function Z(e, t, n, r, i) {
|
|
577
|
+
switch (t) {
|
|
578
|
+
case 3: return u(e, 16, n, r);
|
|
579
|
+
case 4: return u(e, 32, n, r);
|
|
580
|
+
case 16: {
|
|
581
|
+
if (!i) return;
|
|
582
|
+
let t = X(e, n, r);
|
|
583
|
+
if (!Number.isSafeInteger(t)) throw TypeError(`Invalid Tiff. Value too large`);
|
|
584
|
+
return t;
|
|
585
|
+
}
|
|
433
586
|
}
|
|
434
|
-
return n;
|
|
435
|
-
}
|
|
436
|
-
function de(e) {
|
|
437
|
-
let n = t(e, 0, 2);
|
|
438
|
-
if (n === `II`) return `LE`;
|
|
439
|
-
if (n === `MM`) return `BE`;
|
|
440
587
|
}
|
|
441
|
-
const
|
|
442
|
-
|
|
588
|
+
const Le = /* @__PURE__ */ new Set([
|
|
589
|
+
`49492a00`,
|
|
590
|
+
`4d4d002a`,
|
|
591
|
+
`49492b00`,
|
|
592
|
+
`4d4d002b`
|
|
593
|
+
]), Re = {
|
|
594
|
+
validate: (e) => Le.has(n(e, 0, 4)),
|
|
443
595
|
calculate(e) {
|
|
444
|
-
let
|
|
445
|
-
if (
|
|
596
|
+
let n = t(e, 0, 2) === `MM`, r = u(e, 16, 2, n) === 43, i, a, o;
|
|
597
|
+
if (r) {
|
|
598
|
+
let t = u(e, 16, 4, n), r = u(e, 16, 6, n);
|
|
599
|
+
if (t !== 8 || r !== 0) throw TypeError(`Invalid BigTIFF header`);
|
|
600
|
+
let s = X(e, 8, n);
|
|
601
|
+
if (!(s + 8 <= e.length)) throw TypeError(`Invalid Tiff. IFD offset out of bounds`);
|
|
602
|
+
i = X(e, s, n), a = s + 8, o = 20;
|
|
603
|
+
} else {
|
|
604
|
+
let t = u(e, 32, 4, n);
|
|
605
|
+
if (!(t + 2 <= e.length)) throw TypeError(`Invalid Tiff. IFD offset out of bounds`);
|
|
606
|
+
i = u(e, 16, t, n), a = t + 2, o = 12;
|
|
607
|
+
}
|
|
608
|
+
let s = {};
|
|
609
|
+
for (let t = 0; t < Math.min(i, 4096); t++) {
|
|
610
|
+
let i = a + t * o;
|
|
611
|
+
if (i + o > e.length) break;
|
|
612
|
+
let c = u(e, 16, i, n), l = u(e, 16, i + 2, n);
|
|
613
|
+
if ((r ? X(e, i + 4, n) : u(e, 32, i + 4, n)) === 1 && (s[c] = Z(e, l, i + (r ? 12 : 8), n, r)), s[256] && s[257]) break;
|
|
614
|
+
}
|
|
615
|
+
let c = s[256], l = s[257];
|
|
616
|
+
if (!c || !l) throw TypeError(`Invalid Tiff. Missing tags`);
|
|
446
617
|
return {
|
|
447
|
-
height:
|
|
448
|
-
width:
|
|
618
|
+
height: l,
|
|
619
|
+
width: c
|
|
449
620
|
};
|
|
450
621
|
}
|
|
451
622
|
};
|
|
452
|
-
function
|
|
623
|
+
function ze(e) {
|
|
453
624
|
return {
|
|
454
625
|
height: 1 + o(e, 7),
|
|
455
626
|
width: 1 + o(e, 4)
|
|
456
627
|
};
|
|
457
628
|
}
|
|
458
|
-
function
|
|
629
|
+
function Be(e) {
|
|
459
630
|
return {
|
|
460
631
|
height: 1 + ((e[4] & 15) << 10 | e[3] << 2 | (e[2] & 192) >> 6),
|
|
461
632
|
width: 1 + ((e[2] & 63) << 8 | e[1])
|
|
462
633
|
};
|
|
463
634
|
}
|
|
464
|
-
function
|
|
635
|
+
function Ve(e) {
|
|
465
636
|
return {
|
|
466
637
|
height: r(e, 8) & 16383,
|
|
467
638
|
width: r(e, 6) & 16383
|
|
468
639
|
};
|
|
469
640
|
}
|
|
470
|
-
const
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
641
|
+
const Q = {
|
|
642
|
+
bmp: ne,
|
|
643
|
+
cur: re,
|
|
644
|
+
dds: ie,
|
|
645
|
+
gif: _,
|
|
646
|
+
heic: C,
|
|
647
|
+
icns: ue,
|
|
648
|
+
ico: h,
|
|
649
|
+
j2c: de,
|
|
650
|
+
jp2: fe,
|
|
651
|
+
jpg: E,
|
|
652
|
+
jxl: P,
|
|
653
|
+
ktx: ye,
|
|
654
|
+
png: be,
|
|
655
|
+
pnm: Ce,
|
|
656
|
+
psd: we,
|
|
657
|
+
svg: Fe,
|
|
658
|
+
tga: Ie,
|
|
659
|
+
tiff: Re,
|
|
660
|
+
webp: {
|
|
661
|
+
validate(e) {
|
|
662
|
+
let n = t(e, 0, 4) === `RIFF`, r = t(e, 8, 12) === `WEBP`, i = t(e, 12, 15) === `VP8`;
|
|
663
|
+
return n && r && i;
|
|
664
|
+
},
|
|
665
|
+
calculate(e) {
|
|
666
|
+
if (e.length < 30) throw TypeError(`Invalid WebP, truncated input`);
|
|
667
|
+
let r = t(e, 12, 16);
|
|
668
|
+
if (e = e.slice(20, 30), r === `VP8X`) {
|
|
669
|
+
let t = e[0], n = !(t & 192), r = !(t & 1);
|
|
670
|
+
if (n && r) return ze(e);
|
|
671
|
+
throw TypeError(`Invalid WebP`);
|
|
672
|
+
}
|
|
673
|
+
if (r === `VP8 ` && e[0] !== 47) return Ve(e);
|
|
674
|
+
let i = n(e, 3, 6);
|
|
675
|
+
if (r === `VP8L` && i !== `9d012a`) return Be(e);
|
|
480
676
|
throw TypeError(`Invalid WebP`);
|
|
481
677
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
}
|
|
487
|
-
}, _e = {
|
|
488
|
-
validate: (e) => t(e, 8, 12) === `avif`,
|
|
489
|
-
calculate: (e) => {
|
|
490
|
-
let t = Z(e, `meta`), n = Z(e, `iprp`, t.offset + 12, t.offset + t.size), r = Z(e, `ipco`, n.offset + 8, n.offset + n.size), i = Z(e, `ispe`, r.offset + 8, r.offset + r.size);
|
|
491
|
-
return {
|
|
492
|
-
width: c(e, i.offset + 12),
|
|
493
|
-
height: c(e, i.offset + 16)
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
};
|
|
497
|
-
function Z(e, n, r = 0, i = e.length) {
|
|
498
|
-
for (let a = r; a < i;) {
|
|
499
|
-
let r = c(e, a);
|
|
500
|
-
if (t(e, a + 4, a + 8) === n) return {
|
|
501
|
-
offset: a,
|
|
502
|
-
size: r
|
|
503
|
-
};
|
|
504
|
-
if (r <= 0 || a + r > i) break;
|
|
505
|
-
a += r;
|
|
678
|
+
},
|
|
679
|
+
avif: {
|
|
680
|
+
validate: (e) => S(e) === `avif`,
|
|
681
|
+
calculate: (e) => C.calculate(e)
|
|
506
682
|
}
|
|
507
|
-
|
|
508
|
-
}
|
|
509
|
-
const Q = {
|
|
510
|
-
bmp: ee,
|
|
511
|
-
cur: te,
|
|
512
|
-
dds: h,
|
|
513
|
-
gif: _,
|
|
514
|
-
heic: v,
|
|
515
|
-
icns: ne,
|
|
516
|
-
ico: m,
|
|
517
|
-
j2c: re,
|
|
518
|
-
jp2: E,
|
|
519
|
-
jpg: M,
|
|
520
|
-
ktx: N,
|
|
521
|
-
png: F,
|
|
522
|
-
pnm: R,
|
|
523
|
-
psd: z,
|
|
524
|
-
svg: ae,
|
|
525
|
-
tga: oe,
|
|
526
|
-
tiff: pe,
|
|
527
|
-
webp: X,
|
|
528
|
-
avif: _e
|
|
529
|
-
}, ve = Object.keys(Q), $ = {
|
|
683
|
+
}, He = Object.keys(Q), $ = {
|
|
530
684
|
56: `psd`,
|
|
531
685
|
66: `bmp`,
|
|
532
686
|
68: `dds`,
|
|
@@ -538,21 +692,26 @@ const Q = {
|
|
|
538
692
|
137: `png`,
|
|
539
693
|
255: `jpg`
|
|
540
694
|
};
|
|
541
|
-
function
|
|
695
|
+
function Ue(e) {
|
|
542
696
|
let t = e[0];
|
|
543
697
|
if (t in $) {
|
|
544
698
|
let n = $[t];
|
|
545
699
|
if (n && Q[n].validate(e)) return n;
|
|
546
700
|
}
|
|
547
|
-
return
|
|
701
|
+
return He.find((t) => Q[t].validate(e));
|
|
548
702
|
}
|
|
549
|
-
function
|
|
703
|
+
function We(e) {
|
|
550
704
|
if (!(e instanceof Uint8Array)) throw TypeError(`Input should be a Uint8Array`);
|
|
551
|
-
let t =
|
|
705
|
+
let t = Ue(e);
|
|
552
706
|
if (t !== void 0 && t in Q) {
|
|
553
707
|
let n = Q[t].calculate(e);
|
|
554
|
-
if (n !== void 0)
|
|
708
|
+
if (n !== void 0) {
|
|
709
|
+
if (n.images && n.images.length > 1) for (let e of n.images) e.width * e.height > n.width * n.height && (n.width = e.width, n.height = e.height);
|
|
710
|
+
if (!Number.isSafeInteger(n.width) || !Number.isSafeInteger(n.height)) throw TypeError(`Invalid ${t}, truncated or corrupt input`);
|
|
711
|
+
if (n.width <= 0 || n.height < 0) throw TypeError(`Invalid ${t}, zero or negative size`);
|
|
712
|
+
return n.type = t, n;
|
|
713
|
+
}
|
|
555
714
|
}
|
|
556
715
|
throw TypeError(`Unsupported file type: ${t}`);
|
|
557
716
|
}
|
|
558
|
-
export {
|
|
717
|
+
export { We as imageMeta };
|