ipx 4.0.0-alpha.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.
@@ -1,3 +1,558 @@
1
- const decoder=new TextDecoder,toUTF8String=(J,Y=0,X=J.length)=>decoder.decode(J.slice(Y,X)),toHexString=(y,J=0,Y=y.length)=>y.slice(J,Y).reduce((y,J)=>y+(`0`+J.toString(16)).slice(-2),``),readInt16LE=(y,J=0)=>{let Y=y[J]+y[J+1]*2**8;return Y|(Y&2**15)*131070},readUInt16BE=(y,J=0)=>y[J]*2**8+y[J+1],readUInt16LE=(y,J=0)=>y[J]+y[J+1]*2**8,readUInt24LE=(y,J=0)=>y[J]+y[J+1]*2**8+y[J+2]*2**16,readInt32LE=(y,J=0)=>y[J]+y[J+1]*2**8+y[J+2]*2**16+(y[J+3]<<24),readUInt32BE=(y,J=0)=>y[J]*2**24+y[J+1]*2**16+y[J+2]*2**8+y[J+3],readUInt32LE=(y,J=0)=>y[J]+y[J+1]*2**8+y[J+2]*2**16+y[J+3]*2**24,methods={readUInt16BE,readUInt16LE,readUInt32BE,readUInt32LE};function readUInt(y,J,Y,X){Y||=0;let Z=X?`BE`:`LE`;return methods[`readUInt`+J+Z](y,Y)}const BMP={validate:y=>toUTF8String(y,0,2)===`BM`,calculate:y=>({height:Math.abs(readInt32LE(y,22)),width:readUInt32LE(y,18)})};function getSizeFromOffset(y,J){let Y=y[J];return Y===0?256:Y}function getImageSize$1(y,J){let Y=6+J*16;return{height:getSizeFromOffset(y,Y+1),width:getSizeFromOffset(y,Y)}}const ICO={validate(y){let J=readUInt16LE(y,0),Y=readUInt16LE(y,4);return J!==0||Y===0?!1:readUInt16LE(y,2)===1},calculate(y){let J=readUInt16LE(y,4),Y=getImageSize$1(y,0);if(J===1)return Y;let X=[Y];for(let Y=1;Y<J;Y+=1)X.push(getImageSize$1(y,Y));return{height:Y.height,images:X,width:Y.width}}},CUR={validate(y){let J=readUInt16LE(y,0),Y=readUInt16LE(y,4);return J!==0||Y===0?!1:readUInt16LE(y,2)===2},calculate:y=>ICO.calculate(y)},DDS={validate:y=>readUInt32LE(y,0)===542327876,calculate:y=>({height:readUInt32LE(y,12),width:readUInt32LE(y,16)})},gifRegexp=/^GIF8[79]a/,GIF={validate:y=>gifRegexp.test(toUTF8String(y,0,6)),calculate:y=>({height:readUInt16LE(y,8),width:readUInt16LE(y,6)})},HEIC={validate:y=>{let Y=findBox$1(y,`ftyp`);if(!Y)return!1;let X=toUTF8String(y,Y.offset+8,Y.offset+12);return[`heic`,`heix`,`hevc`,`hevx`,`mif1`,`msf1`].includes(X)},calculate:y=>{let J=findBox$1(y,`meta`);if(!J)throw TypeError(`heic: meta box not found`);let Y=findBox$1(y,`iprp`,J.offset+12,J.offset+J.size);if(!Y)throw TypeError(`heic: iprp box not found`);let X=findBox$1(y,`ipco`,Y.offset+8,Y.offset+Y.size);if(!X)throw TypeError(`heic: ipco box not found`);let Z=findAllBoxes(y,`ispe`,X.offset+8,X.offset+X.size).map(J=>({width:readUInt32BE(y,J.offset+12),height:readUInt32BE(y,J.offset+16)}));if(Z.length===0)throw TypeError(`heic: ispe box not found`);let Q=Z[0];for(let y=1;y<Z.length;y++){let J=Z[y];J.width*J.height>Q.width*Q.height&&(Q=J)}return Q}};function findBox$1(y,Y,X=0,Z=y.length){let Q=X;for(;Q<Z;){let X=readUInt32BE(y,Q);if(toUTF8String(y,Q+4,Q+8)===Y)return{offset:Q,size:X};if(X<=0||Q+X>Z)break;Q+=X}}function findAllBoxes(y,Y,X=0,Z=y.length){let Q=X,$=[];for(;Q<Z;){let X=readUInt32BE(y,Q);if(toUTF8String(y,Q+4,Q+8)===Y&&$.push({offset:Q,size:X}),X<=0||Q+X>Z)break;Q+=X}return $}const ICON_TYPE_SIZE={ICON:32,"ICN#":32,"icm#":16,icm4:16,icm8:16,"ics#":16,ics4:16,ics8:16,is32:16,s8mk:16,icp4:16,icl4:32,icl8:32,il32:32,l8mk:32,icp5:32,ic11:32,ich4:48,ich8:48,ih32:48,h8mk:48,icp6:64,ic12:32,it32:128,t8mk:128,ic07:128,ic08:256,ic13:256,ic09:512,ic14:512,ic10:1024};function readImageHeader(y,Y){let X=Y+4;return[toUTF8String(y,Y,X),readUInt32BE(y,X)]}function getImageSize(y){let J=ICON_TYPE_SIZE[y];return{width:J,height:J,type:y}}const ICNS={validate:y=>toUTF8String(y,0,4)===`icns`,calculate(y){let J=y.length,Y=readUInt32BE(y,4),X=8,Z=readImageHeader(y,X),Q=getImageSize(Z[0]);if(X+=Z[1],X===Y)return Q;let $={height:Q.height,images:[Q],width:Q.width};for(;X<Y&&X<J;)Z=readImageHeader(y,X),Q=getImageSize(Z[0]),X+=Z[1],$.images.push(Q);return $}},J2C={validate:y=>toHexString(y,0,4)===`ff4fff51`,calculate:y=>({height:readUInt32BE(y,12),width:readUInt32BE(y,8)})},BoxTypes={ftyp:`66747970`,jp2h:`6a703268`,jp__:`6a502020`,rreq:`72726571`},calculateRREQLength=y=>{let J=y[0],Y=1+2*J,X=readUInt16BE(y,Y)*(2+J);Y=Y+2+X;let Q=readUInt16BE(y,Y)*(16+J);return Y+2+Q},parseIHDR=y=>({height:readUInt32BE(y,4),width:readUInt32BE(y,8)}),JP2={validate(y){let J=toHexString(y,4,8),X=readUInt32BE(y,0);if(J!==BoxTypes.jp__||X<1)return!1;let Z=X+4,Q=readUInt32BE(y,X);return toHexString(y.slice(Z,Z+Q),0,4)===BoxTypes.ftyp},calculate(y){let X=readUInt32BE(y,0),Q=readUInt16BE(y,X+2),$=X+4+Q;switch(toHexString(y,$,$+4)){case BoxTypes.rreq:return $=$+4+4+calculateRREQLength(y.slice($+4)),parseIHDR(y.slice($+8,$+24));case BoxTypes.jp2h:return parseIHDR(y.slice($+8,$+24));default:throw TypeError(`Unsupported header found: `+toUTF8String(y,$,$+4))}}};function isEXIF(y){return toHexString(y,2,6)===`45786966`}function extractSize(y,J){return{height:readUInt16BE(y,J),width:readUInt16BE(y,J+2)}}function extractOrientation(y,J){let Y=readUInt(y,16,14,J);for(let X=0;X<Y;X++){let Y=16+X*12,Z=Y+12;if(Y>y.length)return;let Q=y.slice(Y,Z);if(readUInt(Q,16,0,J)===274)return readUInt(Q,16,2,J)!==3||readUInt(Q,32,4,J)!==1?void 0:readUInt(Q,16,8,J)}}function validateExifBlock(y,J){let X=y.slice(2,J),Z=toHexString(X,6,8),Q=Z===`4d4d`;if(Q||Z===`4949`)return extractOrientation(X,Q)}function validateInput(y,J){if(J>y.length)throw TypeError(`Corrupt JPG, exceeded buffer limits`);if(y[J]!==255)throw TypeError(`Invalid JPG, marker table corrupted`)}const JPG={validate:y=>toHexString(y,0,2)===`ffd8`,calculate(y){y=y.slice(4);let J,Y;for(;y.length>0;){let X=readUInt16BE(y,0);if(isEXIF(y)&&(J=validateExifBlock(y,X)),validateInput(y,X),Y=y[X+1],Y===192||Y===193||Y===194){let Y=extractSize(y,X+5);return J?{height:Y.height,orientation:J,width:Y.width}:Y}y=y.slice(X+2)}throw TypeError(`Invalid JPG, no size found`)}},KTX={validate:y=>toUTF8String(y,1,7)===`KTX 11`,calculate:y=>({height:readUInt32LE(y,40),width:readUInt32LE(y,36)})},pngFriedChunkName=`CgBI`,PNG={validate(y){if(toUTF8String(y,1,8)===`PNG\r
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
2
272
  
3
- `){let Y=toUTF8String(y,12,16);if(Y===pngFriedChunkName&&(Y=toUTF8String(y,28,32)),Y!==`IHDR`)throw TypeError(`Invalid PNG`);return!0}return!1},calculate(y){return toUTF8String(y,12,16)===pngFriedChunkName?{height:readUInt32BE(y,36),width:readUInt32BE(y,32)}:{height:readUInt32BE(y,20),width:readUInt32BE(y,16)}}},PNMTypes={P1:`pbm/ascii`,P2:`pgm/ascii`,P3:`ppm/ascii`,P4:`pbm`,P5:`pgm`,P6:`ppm`,P7:`pam`,PF:`pfm`},handlers={default:y=>{let J=[];for(;y.length>0;){let Y=y.shift();if(Y[0]!==`#`){J=Y.split(` `);break}}if(J.length===2)return{height:Number.parseInt(J[1],10),width:Number.parseInt(J[0],10)};throw TypeError(`Invalid PNM`)},pam:y=>{let J={};for(;y.length>0;){let Y=y.shift();if(Y.length>16||(Y.codePointAt(0)||0)>128)continue;let[X,Z]=Y.split(` `);if(X&&Z&&(J[X.toLowerCase()]=Number.parseInt(Z,10)),J.height&&J.width)break}if(J.height&&J.width)return{height:J.height,width:J.width};throw TypeError(`Invalid PAM`)}},PNM={validate:y=>toUTF8String(y,0,2)in PNMTypes,calculate(y){let Y=PNMTypes[toUTF8String(y,0,2)],X=toUTF8String(y,3).split(/[\n\r]+/);return(handlers[Y]||handlers.default)(X)}},PSD={validate:y=>toUTF8String(y,0,4)===`8BPS`,calculate:y=>({height:readUInt32BE(y,14),width:readUInt32BE(y,18)})},svgReg=/<svg\s([^"'>]|"[^"]*"|'[^']*')*>/,extractorRegExps={height:/\sheight=(["'])([^%]+?)\1/,root:svgReg,viewbox:/\sviewbox=(["'])(.+?)\1/i,width:/\swidth=(["'])([^%]+?)\1/},INCH_CM=2.54,units={in:96,cm:96/INCH_CM,em:16,ex:8,m:96/INCH_CM*100,mm:96/INCH_CM/10,pc:96/72/12,pt:96/72,px:1},unitsReg=RegExp(`^([0-9.]+(?:e\\d+)?)(${Object.keys(units).join(`|`)})?$`);function parseLength(y){let J=unitsReg.exec(y);if(J)return Math.round(Number(J[1])*(units[J[2]]||1))}function parseViewbox(y){let J=y.split(` `);return{height:parseLength(J[3]),width:parseLength(J[2])}}function parseAttributes(y){let J=y.match(extractorRegExps.width),Y=y.match(extractorRegExps.height),X=y.match(extractorRegExps.viewbox);return{height:Y&&parseLength(Y[2]),viewbox:X&&parseViewbox(X[2]),width:J&&parseLength(J[2])}}function calculateByDimensions(y){return{height:y.height,width:y.width}}function calculateByViewbox(y,J){let Y=J.width/J.height;return y.width?{height:Math.floor(y.width/Y),width:y.width}:y.height?{height:y.height,width:Math.floor(y.height*Y)}:{height:J.height,width:J.width}}const SVG={validate:y=>svgReg.test(toUTF8String(y,0,1e3)),calculate(y){let Y=toUTF8String(y).match(extractorRegExps.root);if(Y){let y=parseAttributes(Y[0]);if(y.width&&y.height)return calculateByDimensions(y);if(y.viewbox)return calculateByViewbox(y,y.viewbox)}throw TypeError(`Invalid SVG`)}},TGA={validate(y){return readUInt16LE(y,0)===0&&readUInt16LE(y,4)===0},calculate(y){return{height:readUInt16LE(y,14),width:readUInt16LE(y,12)}}};function readIFD(y,J){let Y=readUInt(y,32,4,J),X=1024,Z=y.length;return Y+X>Z&&(X=Z-Y-10),y.slice(Y+2,Y+2+X)}function readValue(y,J){let Y=readUInt(y,16,8,J);return(readUInt(y,16,10,J)<<16)+Y}function nextTag(y){if(y.length>24)return y.slice(12)}function extractTags(y,J){let Y={},X=y;for(;X&&X.length>0;){let y=readUInt(X,16,0,J),Z=readUInt(X,16,2,J),Q=readUInt(X,32,4,J);if(y===0)break;Q===1&&(Z===3||Z===4)&&(Y[y]=readValue(X,J)),X=nextTag(X)}return Y}function determineEndianness(y){let Y=toUTF8String(y,0,2);if(Y===`II`)return`LE`;if(Y===`MM`)return`BE`}const signatures=new Set([`49492a00`,`4d4d002a`]),TIFF={validate:y=>signatures.has(toHexString(y,0,4)),calculate(y){let J=determineEndianness(y)===`BE`,Y=extractTags(readIFD(y,J),J),X=Y[256],Z=Y[257];if(!X||!Z)throw TypeError(`Invalid Tiff. Missing tags`);return{height:Z,width:X}}};function calculateExtended(y){return{height:1+readUInt24LE(y,7),width:1+readUInt24LE(y,4)}}function calculateLossless(y){return{height:1+((y[4]&15)<<10|y[3]<<2|(y[2]&192)>>6),width:1+((y[2]&63)<<8|y[1])}}function calculateLossy(y){return{height:readInt16LE(y,8)&16383,width:readInt16LE(y,6)&16383}}const WEBP={validate(y){let Y=toUTF8String(y,0,4)===`RIFF`,X=toUTF8String(y,8,12)===`WEBP`,Z=toUTF8String(y,12,15)===`VP8`;return Y&&X&&Z},calculate(y){let X=toUTF8String(y,12,16);if(y=y.slice(20,30),X===`VP8X`){let J=y[0],Y=(J&192)==0,X=(J&1)==0;if(Y&&X)return calculateExtended(y);throw TypeError(`Invalid WebP`)}if(X===`VP8 `&&y[0]!==47)return calculateLossy(y);let Z=toHexString(y,3,6);if(X===`VP8L`&&Z!==`9d012a`)return calculateLossless(y);throw TypeError(`Invalid WebP`)}},AVIF={validate:y=>toUTF8String(y,8,12)===`avif`,calculate:y=>{let J=findBox(y,`meta`),Y=findBox(y,`iprp`,J.offset+12,J.offset+J.size),X=findBox(y,`ipco`,Y.offset+8,Y.offset+Y.size),Z=findBox(y,`ispe`,X.offset+8,X.offset+X.size);return{width:readUInt32BE(y,Z.offset+12),height:readUInt32BE(y,Z.offset+16)}}};function findBox(y,Y,X=0,Z=y.length){for(let Q=X;Q<Z;){let X=readUInt32BE(y,Q);if(toUTF8String(y,Q+4,Q+8)===Y)return{offset:Q,size:X};if(X<=0||Q+X>Z)break;Q+=X}throw Error(`${Y} box not found`)}const typeHandlers={bmp:BMP,cur:CUR,dds:DDS,gif:GIF,heic:HEIC,icns:ICNS,ico:ICO,j2c:J2C,jp2:JP2,jpg:JPG,ktx:KTX,png:PNG,pnm:PNM,psd:PSD,svg:SVG,tga:TGA,tiff:TIFF,webp:WEBP,avif:AVIF},keys=Object.keys(typeHandlers),firstBytes={56:`psd`,66:`bmp`,68:`dds`,71:`gif`,73:`tiff`,77:`tiff`,82:`webp`,105:`icns`,137:`png`,255:`jpg`};function detector(y){let J=y[0];if(J in firstBytes){let Y=firstBytes[J];if(Y&&typeHandlers[Y].validate(y))return Y}return keys.find(J=>typeHandlers[J].validate(y))}function imageMeta(y){if(!(y instanceof Uint8Array))throw TypeError(`Input should be a Uint8Array`);let J=detector(y);if(J!==void 0&&J in typeHandlers){let Y=typeHandlers[J].calculate(y);if(Y!==void 0)return Y.type=J,Y}throw TypeError(`Unsupported file type: ${J}`)}export{imageMeta as t};
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 };