ipx 3.1.1 → 4.0.0-alpha.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/README.md +69 -42
- package/dist/THIRD-PARTY-LICENSES.md +539 -0
- package/dist/_chunks/libs/@fastify/accept-negotiator.mjs +71 -0
- package/dist/_chunks/libs/boolbase.mjs +12 -0
- package/dist/_chunks/libs/css-select.mjs +4139 -0
- package/dist/_chunks/libs/css-tree.mjs +31158 -0
- package/dist/_chunks/libs/csso.mjs +1834 -0
- package/dist/_chunks/libs/etag.mjs +25 -0
- package/dist/_chunks/libs/h3.mjs +267 -0
- package/dist/_chunks/libs/image-meta.d.mts +12 -0
- package/dist/_chunks/libs/image-meta.mjs +558 -0
- package/dist/_chunks/libs/sax.mjs +836 -0
- package/dist/_chunks/libs/svgo.mjs +5918 -0
- package/dist/_chunks/libs/ufo.mjs +41 -0
- package/dist/_chunks/node-fs.mjs +690 -0
- package/dist/_chunks/rolldown-runtime.mjs +42 -0
- package/dist/_chunks/svgo-node.mjs +3 -0
- package/dist/cli.d.mts +1 -2
- package/dist/cli.mjs +67 -59
- package/dist/index.d.mts +214 -321
- package/dist/index.mjs +30 -50
- package/package.json +44 -49
- package/bin/ipx.mjs +0 -2
- package/dist/cli.cjs +0 -63
- package/dist/cli.d.cts +0 -2
- package/dist/cli.d.ts +0 -2
- package/dist/index.cjs +0 -62
- package/dist/index.d.cts +0 -397
- package/dist/index.d.ts +0 -397
- package/dist/shared/ipx.CXJeaylD.mjs +0 -764
- package/dist/shared/ipx.GUc23orS.cjs +0 -778
|
@@ -0,0 +1,558 @@
|
|
|
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] * 2 ** 8;
|
|
3
|
+
return n | (n & 2 ** 15) * 131070;
|
|
4
|
+
}, i = (e, t = 0) => e[t] * 2 ** 8 + e[t + 1], a = (e, t = 0) => e[t] + e[t + 1] * 2 ** 8, o = (e, t = 0) => e[t] + e[t + 1] * 2 ** 8 + e[t + 2] * 2 ** 16, s = (e, t = 0) => e[t] + e[t + 1] * 2 ** 8 + e[t + 2] * 2 ** 16 + (e[t + 3] << 24), c = (e, t = 0) => e[t] * 2 ** 24 + e[t + 1] * 2 ** 16 + e[t + 2] * 2 ** 8 + e[t + 3], l = (e, t = 0) => e[t] + e[t + 1] * 2 ** 8 + e[t + 2] * 2 ** 16 + e[t + 3] * 2 ** 24, u = {
|
|
5
|
+
readUInt16BE: i,
|
|
6
|
+
readUInt16LE: a,
|
|
7
|
+
readUInt32BE: c,
|
|
8
|
+
readUInt32LE: l
|
|
9
|
+
};
|
|
10
|
+
function d(e, t, n, r) {
|
|
11
|
+
n ||= 0;
|
|
12
|
+
let i = r ? `BE` : `LE`;
|
|
13
|
+
return u[`readUInt` + t + i](e, n);
|
|
14
|
+
}
|
|
15
|
+
const ee = {
|
|
16
|
+
validate: (e) => t(e, 0, 2) === `BM`,
|
|
17
|
+
calculate: (e) => ({
|
|
18
|
+
height: Math.abs(s(e, 22)),
|
|
19
|
+
width: l(e, 18)
|
|
20
|
+
})
|
|
21
|
+
};
|
|
22
|
+
function f(e, t) {
|
|
23
|
+
let n = e[t];
|
|
24
|
+
return n === 0 ? 256 : n;
|
|
25
|
+
}
|
|
26
|
+
function p(e, t) {
|
|
27
|
+
let n = 6 + t * 16;
|
|
28
|
+
return {
|
|
29
|
+
height: f(e, n + 1),
|
|
30
|
+
width: f(e, n)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const m = {
|
|
34
|
+
validate(e) {
|
|
35
|
+
let t = a(e, 0), n = a(e, 4);
|
|
36
|
+
return t !== 0 || n === 0 ? !1 : a(e, 2) === 1;
|
|
37
|
+
},
|
|
38
|
+
calculate(e) {
|
|
39
|
+
let t = a(e, 4), n = p(e, 0);
|
|
40
|
+
if (t === 1) return n;
|
|
41
|
+
let r = [n];
|
|
42
|
+
for (let n = 1; n < t; n += 1) r.push(p(e, n));
|
|
43
|
+
return {
|
|
44
|
+
height: n.height,
|
|
45
|
+
images: r,
|
|
46
|
+
width: n.width
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}, te = {
|
|
50
|
+
validate(e) {
|
|
51
|
+
let t = a(e, 0), n = a(e, 4);
|
|
52
|
+
return t !== 0 || n === 0 ? !1 : a(e, 2) === 2;
|
|
53
|
+
},
|
|
54
|
+
calculate: (e) => m.calculate(e)
|
|
55
|
+
}, h = {
|
|
56
|
+
validate: (e) => l(e, 0) === 542327876,
|
|
57
|
+
calculate: (e) => ({
|
|
58
|
+
height: l(e, 12),
|
|
59
|
+
width: l(e, 16)
|
|
60
|
+
})
|
|
61
|
+
}, g = /^GIF8[79]a/, _ = {
|
|
62
|
+
validate: (e) => g.test(t(e, 0, 6)),
|
|
63
|
+
calculate: (e) => ({
|
|
64
|
+
height: a(e, 8),
|
|
65
|
+
width: a(e, 6)
|
|
66
|
+
})
|
|
67
|
+
}, v = {
|
|
68
|
+
validate: (e) => {
|
|
69
|
+
let n = y(e, `ftyp`);
|
|
70
|
+
if (!n) return !1;
|
|
71
|
+
let r = t(e, n.offset + 8, n.offset + 12);
|
|
72
|
+
return [
|
|
73
|
+
`heic`,
|
|
74
|
+
`heix`,
|
|
75
|
+
`hevc`,
|
|
76
|
+
`hevx`,
|
|
77
|
+
`mif1`,
|
|
78
|
+
`msf1`
|
|
79
|
+
].includes(r);
|
|
80
|
+
},
|
|
81
|
+
calculate: (e) => {
|
|
82
|
+
let t = y(e, `meta`);
|
|
83
|
+
if (!t) throw TypeError(`heic: meta box not found`);
|
|
84
|
+
let n = y(e, `iprp`, t.offset + 12, t.offset + t.size);
|
|
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);
|
|
97
|
+
}
|
|
98
|
+
return a;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
function y(e, n, r = 0, i = e.length) {
|
|
102
|
+
let a = r;
|
|
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;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function b(e, n, r = 0, i = e.length) {
|
|
114
|
+
let a = r, o = [];
|
|
115
|
+
for (; a < i;) {
|
|
116
|
+
let r = c(e, a);
|
|
117
|
+
if (t(e, a + 4, a + 8) === n && o.push({
|
|
118
|
+
offset: a,
|
|
119
|
+
size: r
|
|
120
|
+
}), r <= 0 || a + r > i) break;
|
|
121
|
+
a += r;
|
|
122
|
+
}
|
|
123
|
+
return o;
|
|
124
|
+
}
|
|
125
|
+
const x = {
|
|
126
|
+
ICON: 32,
|
|
127
|
+
"ICN#": 32,
|
|
128
|
+
"icm#": 16,
|
|
129
|
+
icm4: 16,
|
|
130
|
+
icm8: 16,
|
|
131
|
+
"ics#": 16,
|
|
132
|
+
ics4: 16,
|
|
133
|
+
ics8: 16,
|
|
134
|
+
is32: 16,
|
|
135
|
+
s8mk: 16,
|
|
136
|
+
icp4: 16,
|
|
137
|
+
icl4: 32,
|
|
138
|
+
icl8: 32,
|
|
139
|
+
il32: 32,
|
|
140
|
+
l8mk: 32,
|
|
141
|
+
icp5: 32,
|
|
142
|
+
ic11: 32,
|
|
143
|
+
ich4: 48,
|
|
144
|
+
ich8: 48,
|
|
145
|
+
ih32: 48,
|
|
146
|
+
h8mk: 48,
|
|
147
|
+
icp6: 64,
|
|
148
|
+
ic12: 32,
|
|
149
|
+
it32: 128,
|
|
150
|
+
t8mk: 128,
|
|
151
|
+
ic07: 128,
|
|
152
|
+
ic08: 256,
|
|
153
|
+
ic13: 256,
|
|
154
|
+
ic09: 512,
|
|
155
|
+
ic14: 512,
|
|
156
|
+
ic10: 1024
|
|
157
|
+
};
|
|
158
|
+
function S(e, n) {
|
|
159
|
+
let r = n + 4;
|
|
160
|
+
return [t(e, n, r), c(e, r)];
|
|
161
|
+
}
|
|
162
|
+
function C(e) {
|
|
163
|
+
let t = x[e];
|
|
164
|
+
return {
|
|
165
|
+
width: t,
|
|
166
|
+
height: t,
|
|
167
|
+
type: e
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const ne = {
|
|
171
|
+
validate: (e) => t(e, 0, 4) === `icns`,
|
|
172
|
+
calculate(e) {
|
|
173
|
+
let t = e.length, n = c(e, 4), r = 8, i = S(e, r), a = C(i[0]);
|
|
174
|
+
if (r += i[1], r === n) return a;
|
|
175
|
+
let o = {
|
|
176
|
+
height: a.height,
|
|
177
|
+
images: [a],
|
|
178
|
+
width: a.width
|
|
179
|
+
};
|
|
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
|
+
}
|
|
183
|
+
}, re = {
|
|
184
|
+
validate: (e) => n(e, 0, 4) === `ff4fff51`,
|
|
185
|
+
calculate: (e) => ({
|
|
186
|
+
height: c(e, 12),
|
|
187
|
+
width: c(e, 8)
|
|
188
|
+
})
|
|
189
|
+
}, w = {
|
|
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 = {
|
|
203
|
+
validate(e) {
|
|
204
|
+
let t = n(e, 4, 8), r = c(e, 0);
|
|
205
|
+
if (t !== w.jp__ || r < 1) return !1;
|
|
206
|
+
let i = r + 4, a = c(e, r);
|
|
207
|
+
return n(e.slice(i, i + a), 0, 4) === w.ftyp;
|
|
208
|
+
},
|
|
209
|
+
calculate(e) {
|
|
210
|
+
let r = c(e, 0), a = i(e, r + 2), o = r + 4 + a;
|
|
211
|
+
switch (n(e, o, o + 4)) {
|
|
212
|
+
case w.rreq: return o = o + 4 + 4 + ie(e.slice(o + 4)), T(e.slice(o + 8, o + 24));
|
|
213
|
+
case w.jp2h: return T(e.slice(o + 8, o + 24));
|
|
214
|
+
default: throw TypeError(`Unsupported header found: ` + t(e, o, o + 4));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
function D(e) {
|
|
219
|
+
return n(e, 2, 6) === `45786966`;
|
|
220
|
+
}
|
|
221
|
+
function O(e, t) {
|
|
222
|
+
return {
|
|
223
|
+
height: i(e, t),
|
|
224
|
+
width: i(e, t + 2)
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
function k(e, t) {
|
|
228
|
+
let n = d(e, 16, 14, t);
|
|
229
|
+
for (let r = 0; r < n; r++) {
|
|
230
|
+
let n = 16 + r * 12, i = n + 12;
|
|
231
|
+
if (n > e.length) return;
|
|
232
|
+
let a = e.slice(n, i);
|
|
233
|
+
if (d(a, 16, 0, t) === 274) return d(a, 16, 2, t) !== 3 || d(a, 32, 4, t) !== 1 ? void 0 : d(a, 16, 8, t);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function A(e, t) {
|
|
237
|
+
let r = e.slice(2, t), i = n(r, 6, 8), a = i === `4d4d`;
|
|
238
|
+
if (a || i === `4949`) return k(r, a);
|
|
239
|
+
}
|
|
240
|
+
function j(e, t) {
|
|
241
|
+
if (t > e.length) throw TypeError(`Corrupt JPG, exceeded buffer limits`);
|
|
242
|
+
if (e[t] !== 255) throw TypeError(`Invalid JPG, marker table corrupted`);
|
|
243
|
+
}
|
|
244
|
+
const M = {
|
|
245
|
+
validate: (e) => n(e, 0, 2) === `ffd8`,
|
|
246
|
+
calculate(e) {
|
|
247
|
+
e = e.slice(4);
|
|
248
|
+
let t, n;
|
|
249
|
+
for (; e.length > 0;) {
|
|
250
|
+
let r = i(e, 0);
|
|
251
|
+
if (D(e) && (t = A(e, r)), j(e, r), n = e[r + 1], n === 192 || n === 193 || n === 194) {
|
|
252
|
+
let n = O(e, r + 5);
|
|
253
|
+
return t ? {
|
|
254
|
+
height: n.height,
|
|
255
|
+
orientation: t,
|
|
256
|
+
width: n.width
|
|
257
|
+
} : n;
|
|
258
|
+
}
|
|
259
|
+
e = e.slice(r + 2);
|
|
260
|
+
}
|
|
261
|
+
throw TypeError(`Invalid JPG, no size found`);
|
|
262
|
+
}
|
|
263
|
+
}, N = {
|
|
264
|
+
validate: (e) => t(e, 1, 7) === `KTX 11`,
|
|
265
|
+
calculate: (e) => ({
|
|
266
|
+
height: l(e, 40),
|
|
267
|
+
width: l(e, 36)
|
|
268
|
+
})
|
|
269
|
+
}, P = `CgBI`, F = {
|
|
270
|
+
validate(e) {
|
|
271
|
+
if (t(e, 1, 8) === `PNG\r
|
|
272
|
+
|
|
273
|
+
`) {
|
|
274
|
+
let n = t(e, 12, 16);
|
|
275
|
+
if (n === P && (n = t(e, 28, 32)), n !== `IHDR`) throw TypeError(`Invalid PNG`);
|
|
276
|
+
return !0;
|
|
277
|
+
}
|
|
278
|
+
return !1;
|
|
279
|
+
},
|
|
280
|
+
calculate(e) {
|
|
281
|
+
return t(e, 12, 16) === P ? {
|
|
282
|
+
height: c(e, 36),
|
|
283
|
+
width: c(e, 32)
|
|
284
|
+
} : {
|
|
285
|
+
height: c(e, 20),
|
|
286
|
+
width: c(e, 16)
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
}, I = {
|
|
290
|
+
P1: `pbm/ascii`,
|
|
291
|
+
P2: `pgm/ascii`,
|
|
292
|
+
P3: `ppm/ascii`,
|
|
293
|
+
P4: `pbm`,
|
|
294
|
+
P5: `pgm`,
|
|
295
|
+
P6: `ppm`,
|
|
296
|
+
P7: `pam`,
|
|
297
|
+
PF: `pfm`
|
|
298
|
+
}, L = {
|
|
299
|
+
default: (e) => {
|
|
300
|
+
let t = [];
|
|
301
|
+
for (; e.length > 0;) {
|
|
302
|
+
let n = e.shift();
|
|
303
|
+
if (n[0] !== `#`) {
|
|
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)
|
|
311
|
+
};
|
|
312
|
+
throw TypeError(`Invalid PNM`);
|
|
313
|
+
},
|
|
314
|
+
pam: (e) => {
|
|
315
|
+
let t = {};
|
|
316
|
+
for (; e.length > 0;) {
|
|
317
|
+
let n = e.shift();
|
|
318
|
+
if (n.length > 16 || (n.codePointAt(0) || 0) > 128) continue;
|
|
319
|
+
let [r, i] = n.split(` `);
|
|
320
|
+
if (r && i && (t[r.toLowerCase()] = Number.parseInt(i, 10)), t.height && t.width) break;
|
|
321
|
+
}
|
|
322
|
+
if (t.height && t.width) return {
|
|
323
|
+
height: t.height,
|
|
324
|
+
width: t.width
|
|
325
|
+
};
|
|
326
|
+
throw TypeError(`Invalid PAM`);
|
|
327
|
+
}
|
|
328
|
+
}, R = {
|
|
329
|
+
validate: (e) => t(e, 0, 2) in I,
|
|
330
|
+
calculate(e) {
|
|
331
|
+
let n = I[t(e, 0, 2)], r = t(e, 3).split(/[\n\r]+/);
|
|
332
|
+
return (L[n] || L.default)(r);
|
|
333
|
+
}
|
|
334
|
+
}, z = {
|
|
335
|
+
validate: (e) => t(e, 0, 4) === `8BPS`,
|
|
336
|
+
calculate: (e) => ({
|
|
337
|
+
height: c(e, 14),
|
|
338
|
+
width: c(e, 18)
|
|
339
|
+
})
|
|
340
|
+
}, B = /<svg\s([^"'>]|"[^"]*"|'[^']*')*>/, V = {
|
|
341
|
+
height: /\sheight=(["'])([^%]+?)\1/,
|
|
342
|
+
root: B,
|
|
343
|
+
viewbox: /\sviewbox=(["'])(.+?)\1/i,
|
|
344
|
+
width: /\swidth=(["'])([^%]+?)\1/
|
|
345
|
+
}, H = 2.54, U = {
|
|
346
|
+
in: 96,
|
|
347
|
+
cm: 96 / H,
|
|
348
|
+
em: 16,
|
|
349
|
+
ex: 8,
|
|
350
|
+
m: 96 / H * 100,
|
|
351
|
+
mm: 96 / H / 10,
|
|
352
|
+
pc: 96 / 72 / 12,
|
|
353
|
+
pt: 96 / 72,
|
|
354
|
+
px: 1
|
|
355
|
+
}, W = RegExp(`^([0-9.]+(?:e\\d+)?)(${Object.keys(U).join(`|`)})?$`);
|
|
356
|
+
function G(e) {
|
|
357
|
+
let t = W.exec(e);
|
|
358
|
+
if (t) return Math.round(Number(t[1]) * (U[t[2]] || 1));
|
|
359
|
+
}
|
|
360
|
+
function K(e) {
|
|
361
|
+
let t = e.split(` `);
|
|
362
|
+
return {
|
|
363
|
+
height: G(t[3]),
|
|
364
|
+
width: G(t[2])
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
function q(e) {
|
|
368
|
+
let t = e.match(V.width), n = e.match(V.height), r = e.match(V.viewbox);
|
|
369
|
+
return {
|
|
370
|
+
height: n && G(n[2]),
|
|
371
|
+
viewbox: r && K(r[2]),
|
|
372
|
+
width: t && G(t[2])
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
function J(e) {
|
|
376
|
+
return {
|
|
377
|
+
height: e.height,
|
|
378
|
+
width: e.width
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
function Y(e, t) {
|
|
382
|
+
let n = t.width / t.height;
|
|
383
|
+
return e.width ? {
|
|
384
|
+
height: Math.floor(e.width / n),
|
|
385
|
+
width: e.width
|
|
386
|
+
} : e.height ? {
|
|
387
|
+
height: e.height,
|
|
388
|
+
width: Math.floor(e.height * n)
|
|
389
|
+
} : {
|
|
390
|
+
height: t.height,
|
|
391
|
+
width: t.width
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
const ae = {
|
|
395
|
+
validate: (e) => B.test(t(e, 0, 1e3)),
|
|
396
|
+
calculate(e) {
|
|
397
|
+
let n = t(e).match(V.root);
|
|
398
|
+
if (n) {
|
|
399
|
+
let e = q(n[0]);
|
|
400
|
+
if (e.width && e.height) return J(e);
|
|
401
|
+
if (e.viewbox) return Y(e, e.viewbox);
|
|
402
|
+
}
|
|
403
|
+
throw TypeError(`Invalid SVG`);
|
|
404
|
+
}
|
|
405
|
+
}, oe = {
|
|
406
|
+
validate(e) {
|
|
407
|
+
return a(e, 0) === 0 && a(e, 4) === 0;
|
|
408
|
+
},
|
|
409
|
+
calculate(e) {
|
|
410
|
+
return {
|
|
411
|
+
height: a(e, 14),
|
|
412
|
+
width: a(e, 12)
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
function se(e, t) {
|
|
417
|
+
let n = d(e, 32, 4, t), r = 1024, i = e.length;
|
|
418
|
+
return n + r > i && (r = i - n - 10), e.slice(n + 2, n + 2 + r);
|
|
419
|
+
}
|
|
420
|
+
function ce(e, t) {
|
|
421
|
+
let n = d(e, 16, 8, t);
|
|
422
|
+
return (d(e, 16, 10, t) << 16) + n;
|
|
423
|
+
}
|
|
424
|
+
function le(e) {
|
|
425
|
+
if (e.length > 24) return e.slice(12);
|
|
426
|
+
}
|
|
427
|
+
function ue(e, t) {
|
|
428
|
+
let n = {}, r = e;
|
|
429
|
+
for (; r && r.length > 0;) {
|
|
430
|
+
let e = d(r, 16, 0, t), i = d(r, 16, 2, t), a = d(r, 32, 4, t);
|
|
431
|
+
if (e === 0) break;
|
|
432
|
+
a === 1 && (i === 3 || i === 4) && (n[e] = ce(r, t)), r = le(r);
|
|
433
|
+
}
|
|
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
|
+
}
|
|
441
|
+
const fe = /* @__PURE__ */ new Set([`49492a00`, `4d4d002a`]), pe = {
|
|
442
|
+
validate: (e) => fe.has(n(e, 0, 4)),
|
|
443
|
+
calculate(e) {
|
|
444
|
+
let t = de(e) === `BE`, n = ue(se(e, t), t), r = n[256], i = n[257];
|
|
445
|
+
if (!r || !i) throw TypeError(`Invalid Tiff. Missing tags`);
|
|
446
|
+
return {
|
|
447
|
+
height: i,
|
|
448
|
+
width: r
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
function me(e) {
|
|
453
|
+
return {
|
|
454
|
+
height: 1 + o(e, 7),
|
|
455
|
+
width: 1 + o(e, 4)
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
function he(e) {
|
|
459
|
+
return {
|
|
460
|
+
height: 1 + ((e[4] & 15) << 10 | e[3] << 2 | (e[2] & 192) >> 6),
|
|
461
|
+
width: 1 + ((e[2] & 63) << 8 | e[1])
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
function ge(e) {
|
|
465
|
+
return {
|
|
466
|
+
height: r(e, 8) & 16383,
|
|
467
|
+
width: r(e, 6) & 16383
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
const X = {
|
|
471
|
+
validate(e) {
|
|
472
|
+
let n = t(e, 0, 4) === `RIFF`, r = t(e, 8, 12) === `WEBP`, i = t(e, 12, 15) === `VP8`;
|
|
473
|
+
return n && r && i;
|
|
474
|
+
},
|
|
475
|
+
calculate(e) {
|
|
476
|
+
let r = t(e, 12, 16);
|
|
477
|
+
if (e = e.slice(20, 30), r === `VP8X`) {
|
|
478
|
+
let t = e[0], n = (t & 192) == 0, r = (t & 1) == 0;
|
|
479
|
+
if (n && r) return me(e);
|
|
480
|
+
throw TypeError(`Invalid WebP`);
|
|
481
|
+
}
|
|
482
|
+
if (r === `VP8 ` && e[0] !== 47) return ge(e);
|
|
483
|
+
let i = n(e, 3, 6);
|
|
484
|
+
if (r === `VP8L` && i !== `9d012a`) return he(e);
|
|
485
|
+
throw TypeError(`Invalid WebP`);
|
|
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;
|
|
506
|
+
}
|
|
507
|
+
throw Error(`${n} box not found`);
|
|
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), $ = {
|
|
530
|
+
56: `psd`,
|
|
531
|
+
66: `bmp`,
|
|
532
|
+
68: `dds`,
|
|
533
|
+
71: `gif`,
|
|
534
|
+
73: `tiff`,
|
|
535
|
+
77: `tiff`,
|
|
536
|
+
82: `webp`,
|
|
537
|
+
105: `icns`,
|
|
538
|
+
137: `png`,
|
|
539
|
+
255: `jpg`
|
|
540
|
+
};
|
|
541
|
+
function ye(e) {
|
|
542
|
+
let t = e[0];
|
|
543
|
+
if (t in $) {
|
|
544
|
+
let n = $[t];
|
|
545
|
+
if (n && Q[n].validate(e)) return n;
|
|
546
|
+
}
|
|
547
|
+
return ve.find((t) => Q[t].validate(e));
|
|
548
|
+
}
|
|
549
|
+
function be(e) {
|
|
550
|
+
if (!(e instanceof Uint8Array)) throw TypeError(`Input should be a Uint8Array`);
|
|
551
|
+
let t = ye(e);
|
|
552
|
+
if (t !== void 0 && t in Q) {
|
|
553
|
+
let n = Q[t].calculate(e);
|
|
554
|
+
if (n !== void 0) return n.type = t, n;
|
|
555
|
+
}
|
|
556
|
+
throw TypeError(`Unsupported file type: ${t}`);
|
|
557
|
+
}
|
|
558
|
+
export { be as imageMeta };
|