@d0paminedriven/fs 7.0.0 → 7.1.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.
@@ -0,0 +1,1071 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/image/index.ts
22
+ var image_exports = {};
23
+ __export(image_exports, {
24
+ ImageService: () => ImageService
25
+ });
26
+ module.exports = __toCommonJS(image_exports);
27
+
28
+ // src/utils/index.ts
29
+ var UtilsService = class {
30
+ static {
31
+ __name(this, "UtilsService");
32
+ }
33
+ chunkArray(arr, maxChunkLength) {
34
+ const chunks = Array.of();
35
+ let currentChunkLength = 0;
36
+ let currentChunk = Array.of();
37
+ for (const [index, val] of arr.entries()) {
38
+ if (val.length + currentChunkLength >= maxChunkLength) {
39
+ if (currentChunk.length) {
40
+ chunks.push(currentChunk);
41
+ }
42
+ currentChunkLength = val.length;
43
+ currentChunk = [val];
44
+ } else {
45
+ currentChunk.push(val);
46
+ currentChunkLength += val.length + 1;
47
+ }
48
+ if (arr.length === index + 1) {
49
+ chunks.push(currentChunk);
50
+ }
51
+ }
52
+ return chunks.length ? chunks : [arr];
53
+ }
54
+ b64ToBlob(b64Data) {
55
+ {
56
+ const sliceSize = 512;
57
+ const typeMatch = /^data:((?:image|application|haptics|video|text|font|model|audio|multipart)\/[A-Za-z0-9+-.]+(?:;[^,]+)*);base64,(.+)$/i.exec(
58
+ b64Data
59
+ );
60
+ if (!typeMatch) {
61
+ throw new Error(`${b64Data} is not a valid data Url`);
62
+ }
63
+ const type = typeMatch[1];
64
+ const base64Data = typeMatch?.[2] ?? "";
65
+ const byteCharacters = Buffer.from(base64Data, "base64").toString(
66
+ "binary"
67
+ );
68
+ const byteArrays = Array.of();
69
+ for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
70
+ const slice = byteCharacters.slice(offset, offset + sliceSize);
71
+ const byteNumbers = new Array(slice.length);
72
+ for (let i = 0; i < slice.length; i++) {
73
+ byteNumbers[i] = slice.charCodeAt(i);
74
+ }
75
+ const byteArray = new Uint8Array(byteNumbers);
76
+ byteArrays.push(byteArray);
77
+ }
78
+ const blob = new Blob(byteArrays, { type });
79
+ return blob;
80
+ }
81
+ }
82
+ arrToArrOfArrs = /* @__PURE__ */ __name(({
83
+ arrToFragment = Array.of(),
84
+ arrOfArrsAggregator = Array.of(),
85
+ interval
86
+ }) => new Promise(
87
+ (resolve, _reject) => resolve(
88
+ ((interval2) => {
89
+ for (let i = 0; i <= arrToFragment.length; i++) {
90
+ if ((i % interval2 === 0 || i === 0) && i <= arrToFragment.length) {
91
+ let segment = arrToFragment.slice(i, i + interval2);
92
+ arrOfArrsAggregator.push(segment);
93
+ }
94
+ }
95
+ })(interval)
96
+ )
97
+ ).then((_) => arrOfArrsAggregator), "arrToArrOfArrs");
98
+ extractTuple(obj, props) {
99
+ return [props, obj[props]];
100
+ }
101
+ sort(obj, order) {
102
+ return Object.fromEntries(
103
+ Object.entries(obj).sort(
104
+ ([a, _aa], [b, _bb]) => order === "DESC" ? b.localeCompare(a) - a.localeCompare(b) : a.localeCompare(b) - b.localeCompare(a)
105
+ )
106
+ );
107
+ }
108
+ excludeTargeted = /* @__PURE__ */ __name((obj, props, sort) => {
109
+ const resolve = Object.fromEntries(
110
+ Object.entries(obj).map(([key, val]) => {
111
+ if (props.includes(key)) {
112
+ return ["omit", "omit"];
113
+ } else return [key, val];
114
+ }).filter(([t, _v]) => /omit/.test(t) === false)
115
+ );
116
+ return typeof sort !== "undefined" ? this.sort(resolve, sort) : resolve;
117
+ }, "excludeTargeted");
118
+ includeTargeted = /* @__PURE__ */ __name((obj, props, sort) => {
119
+ const resolve = Object.fromEntries(
120
+ props.map((val) => this.extractTuple(obj, val))
121
+ );
122
+ return typeof sort !== "undefined" ? this.sort(resolve, sort) : resolve;
123
+ }, "includeTargeted");
124
+ countsSorter = /* @__PURE__ */ __name((counter, keySort = "ASC", valSort = "DESC") => Object.fromEntries(
125
+ Array.from(Object.entries(counter)).sort(
126
+ ([aStr, _aNum], [bStr, _bNum]) => keySort === "DESC" ? bStr.localeCompare(aStr) - aStr.localeCompare(bStr) : aStr.localeCompare(bStr) - bStr.localeCompare(aStr)
127
+ ).sort(([aStr, aNum], [bStr, bNum]) => {
128
+ if (typeof (aNum && bNum) === "number") {
129
+ return valSort === "ASC" ? aNum - bNum : bNum - aNum;
130
+ } else if (typeof (aNum && bNum) === "string") {
131
+ return valSort === "ASC" ? aStr.localeCompare(bStr) - bStr.localeCompare(aStr) : bStr.localeCompare(aStr) - aStr.localeCompare(bStr);
132
+ } else
133
+ throw new Error(
134
+ "only Record<string, string> and Record<string,number> types supported"
135
+ );
136
+ })
137
+ ), "countsSorter");
138
+ range(from, to) {
139
+ const values = Array.of();
140
+ for (let i = from; i < to; i++) {
141
+ values.push(i);
142
+ }
143
+ return values;
144
+ }
145
+ isPrimeNumber = /* @__PURE__ */ __name((n) => {
146
+ for (let i = 2; n > i; i++) {
147
+ if (n % i === 0) {
148
+ return false;
149
+ }
150
+ }
151
+ return n > 1;
152
+ }, "isPrimeNumber");
153
+ acceptor = /* @__PURE__ */ __name((num) => [...Array(num !== 0 ? num : this.range(num = -101, num = 101)).keys()].reverse().filter(this.isPrimeNumber), "acceptor");
154
+ };
155
+
156
+ // src/url/index.ts
157
+ var UrlService = class extends UtilsService {
158
+ static {
159
+ __name(this, "UrlService");
160
+ }
161
+ URL_REGEX = /^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
162
+ parseUrl(url) {
163
+ const parsed = this.URL_REGEX.exec(url);
164
+ if (parsed) {
165
+ return {
166
+ href: parsed[0],
167
+ protocol: parsed[1] ?? "",
168
+ baseUrl: `${parsed[1]}${parsed[3]}`,
169
+ host: parsed[4] ?? "",
170
+ pathname: parsed[5] ?? "",
171
+ search: parsed[6] ?? "",
172
+ hash: parsed[8] ?? ""
173
+ };
174
+ } else return null;
175
+ }
176
+ };
177
+
178
+ // src/mime/index.ts
179
+ var extMimeMap = {
180
+ aac: ["audio/aac"],
181
+ abw: ["application/x-abiword"],
182
+ aces: ["image/aces"],
183
+ apng: ["image/apng"],
184
+ arc: ["application/x-freearc"],
185
+ avci: ["image/avci"],
186
+ avif: ["image/avif"],
187
+ avi: ["video/x-msvideo"],
188
+ azw: ["application/vnd.amazon.ebook"],
189
+ bin: ["application/octet-stream", "multipart/voice-message"],
190
+ bmp: ["image/bmp"],
191
+ bz: ["application/x-bzip"],
192
+ bz2: ["application/x-bzip2"],
193
+ cda: ["application/x-cdf"],
194
+ cjs: ["application/node", "text/javascript"],
195
+ csh: ["application/x-csh"],
196
+ css: ["text/css"],
197
+ csv: ["text/csv"],
198
+ cur: ["image/x-icon"],
199
+ doc: ["application/msword"],
200
+ docx: [
201
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
202
+ ],
203
+ dpx: ["image/dpx"],
204
+ emf: ["image/emf"],
205
+ eot: ["application/vnd.ms-fontobject"],
206
+ epub: ["application/epub+zip"],
207
+ gif: ["image/gif"],
208
+ glb: ["model/gltf-binary"],
209
+ gltf: ["model/gltf+json"],
210
+ gz: ["application/gzip", "application/x-gzip"],
211
+ hjif: ["haptics/hjif"],
212
+ hmpg: ["haptics/hmpg"],
213
+ htm: ["text/html"],
214
+ html: ["text/html"],
215
+ ico: ["image/vnd.microsoft.icon", "image/x-icon"],
216
+ ics: ["text/calendar"],
217
+ ivs: ["haptics/ivs"],
218
+ ivt: ["haptics/ivs"],
219
+ jar: ["application/java-archive"],
220
+ jfif: ["image/jpeg"],
221
+ jif: ["image/jpeg"],
222
+ jpe: ["image/jpeg"],
223
+ jpeg: ["image/jpeg"],
224
+ jpg: ["image/jpeg"],
225
+ js: ["application/node", "text/javascript"],
226
+ json: ["application/json"],
227
+ jsonld: ["application/ld+json"],
228
+ ktx: ["image/ktx"],
229
+ ktx2: ["image/ktx2"],
230
+ m3u8: ["application/vnd.apple.mpegurl"],
231
+ m4a: ["audio/mp4"],
232
+ m4v: ["video/mp4"],
233
+ md: ["text/markdown"],
234
+ mdx: ["application/x-mdx"],
235
+ mid: ["audio/midi"],
236
+ midi: ["audio/x-midi"],
237
+ mjs: ["text/javascript"],
238
+ mp3: ["audio/mpeg"],
239
+ mp4: ["video/mp4"],
240
+ mpd: ["application/dash+xml"],
241
+ mpeg: ["video/mpeg"],
242
+ mpkg: ["application/vnd.apple.installer+xml"],
243
+ mtlx: ["application/xml"],
244
+ ndjson: ["application/x-ndjson"],
245
+ node: ["application/node", "text/javascript"],
246
+ obj: ["model/obj", "application/octet-stream", "text/plain"],
247
+ odp: ["application/vnd.oasis.opendocument.presentation"],
248
+ ods: ["application/vnd.oasis.opendocument.spreadsheet"],
249
+ odt: ["application/vnd.oasis.opendocument.text"],
250
+ oga: ["audio/ogg"],
251
+ ogg: ["audio/ogg"],
252
+ ogv: ["video/ogg"],
253
+ ogx: ["application/ogg"],
254
+ opus: ["audio/ogg"],
255
+ otf: ["font/otf"],
256
+ png: ["image/png"],
257
+ pdf: ["application/pdf"],
258
+ php: ["application/x-httpd-php"],
259
+ pjp: ["image/jpeg"],
260
+ pjpeg: ["image/jpeg"],
261
+ pkpass: ["application/vnd.apple.pkpass"],
262
+ ppt: ["application/vnd.ms-powerpoint"],
263
+ pptx: [
264
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation"
265
+ ],
266
+ py: ["text/x-python"],
267
+ pyc: ["application/x-python-code"],
268
+ rar: ["application/vnd.rar"],
269
+ rs: ["text/rust"],
270
+ rtf: ["application/rtf"],
271
+ sh: ["application/x-sh"],
272
+ sql: ["application/sql"],
273
+ sse: ["text/event-stream"],
274
+ svg: ["image/svg+xml"],
275
+ tar: ["application/x-tar"],
276
+ tif: ["image/tiff"],
277
+ tiff: ["image/tiff"],
278
+ toml: ["application/toml"],
279
+ ts: ["text/typescript", "video/mp2t", "video/vnd.dlna.mpeg-tts"],
280
+ ttf: ["application/font-sfnt", "font/ttf"],
281
+ txt: ["text/plain"],
282
+ usdz: ["model/vnd.usdz+zip"],
283
+ vsd: ["application/vnd.visio"],
284
+ vtt: ["text/vtt"],
285
+ wasm: ["application/wasm"],
286
+ wav: ["audio/wav"],
287
+ weba: ["audio/webm"],
288
+ webm: ["video/webm"],
289
+ webmanifest: ["application/manifest+json"],
290
+ webp: ["image/webp"],
291
+ woff: ["font/woff"],
292
+ woff2: ["font/woff2"],
293
+ xhtml: ["application/xhtml+xml"],
294
+ xls: ["application/vnd.ms-excel"],
295
+ xlsx: ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],
296
+ xml: ["application/xml", "text/xml"],
297
+ xul: ["application/vnd.mozilla.xul+xml"],
298
+ yaml: ["application/yaml"],
299
+ yml: ["application/yaml"],
300
+ zip: ["application/zip", "application/x-zip-compressed"],
301
+ "3gp": ["video/3gpp"],
302
+ "3g2": ["video/3gpp2"],
303
+ "7z": ["application/x-7z-compressed"]
304
+ };
305
+ var mimeToExt = {
306
+ "application/dash+xml": ["mpd"],
307
+ "application/epub+zip": ["epub"],
308
+ "application/font-sfnt": ["ttf"],
309
+ "application/gzip": ["gz"],
310
+ "application/java-archive": ["jar"],
311
+ "application/json": ["json"],
312
+ "application/ld+json": ["jsonld"],
313
+ "application/manifest+json": ["webmanifest"],
314
+ "application/msword": ["doc"],
315
+ "application/node": ["node", "js"],
316
+ "application/octet-stream": ["bin", "obj"],
317
+ "application/ogg": ["ogx"],
318
+ "application/pdf": ["pdf"],
319
+ "application/rtf": ["rtf"],
320
+ "application/sql": ["sql"],
321
+ "application/toml": ["toml"],
322
+ "application/vnd.amazon.ebook": ["azw"],
323
+ "application/vnd.apple.installer+xml": ["mpkg"],
324
+ "application/vnd.apple.mpegurl": ["m3u8"],
325
+ "application/vnd.apple.pkpass": ["pkpass"],
326
+ "application/vnd.mozilla.xul+xml": ["xul"],
327
+ "application/vnd.ms-excel": ["xls"],
328
+ "application/vnd.ms-fontobject": ["eot"],
329
+ "application/vnd.ms-powerpoint": ["ppt"],
330
+ "application/vnd.oasis.opendocument.presentation": ["odp"],
331
+ "application/vnd.oasis.opendocument.spreadsheet": ["ods"],
332
+ "application/vnd.oasis.opendocument.text": ["odt"],
333
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation": [
334
+ "pptx"
335
+ ],
336
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": ["xlsx"],
337
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": [
338
+ "docx"
339
+ ],
340
+ "application/vnd.rar": ["rar"],
341
+ "application/vnd.visio": ["vsd"],
342
+ "application/wasm": ["wasm"],
343
+ "application/x-7z-compressed": ["7z"],
344
+ "application/x-abiword": ["abw"],
345
+ "application/x-bzip": ["bz"],
346
+ "application/x-bzip2": ["bz2"],
347
+ "application/x-cdf": ["cda"],
348
+ "application/x-csh": ["csh"],
349
+ "application/x-freearc": ["arc"],
350
+ "application/x-gzip": ["gz"],
351
+ "application/x-httpd-php": ["php"],
352
+ "application/x-mdx": ["mdx"],
353
+ "application/x-ndjson": ["ndjson"],
354
+ "application/x-python-code": ["pyc"],
355
+ "application/x-sh": ["sh"],
356
+ "application/x-tar": ["tar"],
357
+ "application/x-zip-compressed": ["zip"],
358
+ "application/xhtml+xml": ["xhtml"],
359
+ "application/xml": ["xml", "mtlx"],
360
+ "application/yaml": ["yml", "yaml"],
361
+ "application/zip": ["zip"],
362
+ "audio/aac": ["aac"],
363
+ "audio/midi": ["mid"],
364
+ "audio/mp4": ["m4a"],
365
+ "audio/mpeg": ["mp3"],
366
+ "audio/ogg": ["opus", "ogg", "oga"],
367
+ "audio/wav": ["wav"],
368
+ "audio/webm": ["weba"],
369
+ "audio/x-midi": ["midi"],
370
+ "font/otf": ["otf"],
371
+ "font/ttf": ["ttf"],
372
+ "font/woff": ["woff"],
373
+ "font/woff2": ["woff2"],
374
+ "haptics/hjif": ["hjif"],
375
+ "haptics/hmpg": ["hmpg"],
376
+ "haptics/ivs": ["ivs", "ivt"],
377
+ "image/aces": ["aces"],
378
+ "image/apng": ["apng"],
379
+ "image/avci": ["avci"],
380
+ "image/avif": ["avif"],
381
+ "image/bmp": ["bmp"],
382
+ "image/dpx": ["dpx"],
383
+ "image/emf": ["emf"],
384
+ "image/gif": ["gif"],
385
+ "image/jpeg": ["jpg", "jpeg", "jpe", "jif", "jfif", "pjp", "pjpeg"],
386
+ "image/ktx": ["ktx"],
387
+ "image/ktx2": ["ktx2"],
388
+ "image/png": ["png"],
389
+ "image/svg+xml": ["svg"],
390
+ "image/tiff": ["tiff", "tif"],
391
+ "image/vnd.microsoft.icon": ["ico"],
392
+ "image/webp": ["webp"],
393
+ "image/x-icon": ["cur", "ico"],
394
+ "model/gltf-binary": ["glb"],
395
+ "model/gltf+json": ["gltf"],
396
+ "model/obj": ["obj"],
397
+ "model/vnd.usdz+zip": ["usdz"],
398
+ "multipart/voice-message": ["bin"],
399
+ "text/calendar": ["ics"],
400
+ "text/css": ["css"],
401
+ "text/csv": ["csv"],
402
+ "text/event-stream": ["sse"],
403
+ "text/html": ["html", "htm"],
404
+ "text/javascript": ["js", "mjs", "cjs"],
405
+ "text/markdown": ["md"],
406
+ "text/plain": ["txt"],
407
+ "text/rust": ["rs"],
408
+ "text/typescript": ["ts"],
409
+ "text/vtt": ["vtt"],
410
+ "text/xml": ["xml"],
411
+ "text/x-python": ["py"],
412
+ "video/3gpp": ["3gp"],
413
+ "video/3gpp2": ["3g2"],
414
+ "video/mp2t": ["ts"],
415
+ "video/mp4": ["mp4", "m4v"],
416
+ "video/mpeg": ["mpeg"],
417
+ "video/ogg": ["ogv"],
418
+ "video/vnd.dlna.mpeg-tts": ["ts"],
419
+ "video/webm": ["webm"],
420
+ "video/x-msvideo": ["avi"]
421
+ };
422
+ var MimeService = class extends UrlService {
423
+ static {
424
+ __name(this, "MimeService");
425
+ }
426
+ constructor() {
427
+ super();
428
+ }
429
+ mimeTypeObj = extMimeMap;
430
+ toExtObj = mimeToExt;
431
+ compareMimeToExt(p = "mime") {
432
+ let a = {};
433
+ if (p === "mime") {
434
+ for (const [_key, vals] of Object.entries(extMimeMap)) {
435
+ for (const val of vals) {
436
+ a[val] = (a[val] ?? 0) + 1;
437
+ }
438
+ }
439
+ for (const [key, _val] of Object.entries(mimeToExt)) {
440
+ a[key] = (a[key] ?? 0) + 1;
441
+ }
442
+ return Object.fromEntries(
443
+ Object.entries(a).sort(([_a, aa], [_b, bb]) => bb - aa)
444
+ );
445
+ } else {
446
+ for (const [_key, vals] of Object.entries(mimeToExt)) {
447
+ for (const val of vals) {
448
+ a[val] = (a[val] ?? 0) + 1;
449
+ }
450
+ }
451
+ for (const [key, _val] of Object.entries(extMimeMap)) {
452
+ a[key] = (a[key] ?? 0) + 1;
453
+ }
454
+ return Object.fromEntries(
455
+ Object.entries(a).sort(([_a, aa], [_b, bb]) => bb - aa)
456
+ );
457
+ }
458
+ }
459
+ mimeToExt(mime) {
460
+ const extensions = this.toExtObj[mime];
461
+ if (extensions.length === 1) return extensions[0];
462
+ if (extensions.length === 2) {
463
+ return extensions[0];
464
+ }
465
+ if (extensions.length === 3) {
466
+ if (mime === "audio/ogg") return "ogg";
467
+ return extensions[0];
468
+ }
469
+ if (extensions.length === 7) {
470
+ return extensions[0];
471
+ }
472
+ return extensions[0];
473
+ }
474
+ assetType(url) {
475
+ const parsed = this.parseUrl(url);
476
+ if (!parsed) return void 0;
477
+ const ext = parsed.pathname.split(/([.])/g)?.reverse()?.[0]?.toLowerCase();
478
+ return ext && ext in this.mimeTypeObj ? ext : void 0;
479
+ }
480
+ getMimes(ext) {
481
+ return this.mimeTypeObj[ext];
482
+ }
483
+ getMimeFor(ext, opts) {
484
+ const mimes = this.getMimes(ext);
485
+ if (mimes.length === 1) return mimes[0];
486
+ if (opts?.type) {
487
+ const found = mimes.find((mime) => mime.startsWith(opts.type + "/"));
488
+ return found ?? mimes[0];
489
+ }
490
+ return mimes[0];
491
+ }
492
+ isMimeFor(ext, mime) {
493
+ return this.getMimes(ext).find((s) => s === mime);
494
+ }
495
+ getMimeTypeForPath(path, opts) {
496
+ const ext = this.assetType(path);
497
+ if (!ext) return "application/octet-stream";
498
+ return this.getMimeFor(ext, opts);
499
+ }
500
+ };
501
+
502
+ // src/image/index.ts
503
+ var ImageService = class extends MimeService {
504
+ static {
505
+ __name(this, "ImageService");
506
+ }
507
+ parseExif(buffer, app1Pos, app1Size) {
508
+ const exifHeader = buffer.toString("ascii", app1Pos + 2, app1Pos + 8);
509
+ if (exifHeader !== "Exif\0\0")
510
+ return { orientation: null, dateTimeOriginal: null };
511
+ let tiffPos = app1Pos + 8;
512
+ const app1End = app1Pos + app1Size;
513
+ if (tiffPos + 10 > app1End)
514
+ return { orientation: null, dateTimeOriginal: null };
515
+ const byteOrder = buffer.toString("ascii", tiffPos, tiffPos + 2);
516
+ const littleEndian = byteOrder === "II";
517
+ const readUInt16 = littleEndian ? buffer.readUInt16LE.bind(buffer) : buffer.readUInt16BE.bind(buffer);
518
+ const readUInt32 = littleEndian ? buffer.readUInt32LE.bind(buffer) : buffer.readUInt32BE.bind(buffer);
519
+ if (readUInt16(tiffPos + 2) !== 42)
520
+ return { orientation: null, dateTimeOriginal: null };
521
+ let ifdOffset = readUInt32(tiffPos + 4);
522
+ tiffPos += ifdOffset;
523
+ const numEntries = readUInt16(tiffPos);
524
+ tiffPos += 2;
525
+ let orientation = null;
526
+ let dateTimeOriginal = null;
527
+ for (let i = 0; i < numEntries; i++) {
528
+ const tag = readUInt16(tiffPos), type = readUInt16(tiffPos + 2), count = readUInt32(tiffPos + 4), valueOffset = tiffPos + 8;
529
+ if (tag === 274 && type === 3 && count === 1) {
530
+ orientation = readUInt16(valueOffset);
531
+ } else if (tag === 36867 && type === 2 && count === 20) {
532
+ const offset = readUInt32(valueOffset);
533
+ if (app1Pos + 2 + offset + 19 > app1End) {
534
+ dateTimeOriginal = null;
535
+ } else {
536
+ dateTimeOriginal = buffer.toString("ascii", app1Pos + 2 + offset, app1Pos + 2 + offset + 19).trim();
537
+ }
538
+ }
539
+ tiffPos += 12;
540
+ }
541
+ return { orientation, dateTimeOriginal };
542
+ }
543
+ parseXmpFromAvif(buffer, meta, _ipco) {
544
+ const iinf = this.findBox(
545
+ buffer,
546
+ "iinf",
547
+ meta.pos + 4,
548
+ meta.pos + meta.size
549
+ );
550
+ if (!iinf) return null;
551
+ let pos = iinf.pos;
552
+ const version = buffer[pos++];
553
+ const itemCount = version === 0 ? buffer.readUInt16BE(pos) : buffer.readUInt32BE(pos);
554
+ pos += version === 0 ? 2 : 4;
555
+ let xmpItemId;
556
+ for (let i = 0; i < itemCount; i++) {
557
+ const infeStart = pos;
558
+ const infeSize = buffer.readUInt32BE(pos);
559
+ if (buffer.toString("ascii", pos + 4, pos + 8) !== "infe") break;
560
+ pos += 8;
561
+ const infeVersion = buffer?.[pos++];
562
+ if (!infeVersion) return null;
563
+ const itemId = infeVersion < 2 ? buffer.readUInt16BE(pos) : buffer.readUInt32BE(pos);
564
+ pos += infeVersion < 2 ? 2 : 4;
565
+ pos += 2;
566
+ const itemType = buffer.toString("ascii", pos, pos + 4);
567
+ pos += 4;
568
+ let nameEnd = pos;
569
+ while (buffer[nameEnd] !== 0 && nameEnd < infeStart + infeSize) nameEnd++;
570
+ const _itemName = buffer.toString("ascii", pos, nameEnd);
571
+ pos = nameEnd + 1;
572
+ if (itemType === "mime") {
573
+ let ctEnd = pos;
574
+ while (buffer[ctEnd] !== 0 && ctEnd < infeStart + infeSize) ctEnd++;
575
+ const contentType = buffer.toString("ascii", pos, ctEnd);
576
+ if (contentType === "application/rdf+xml") {
577
+ xmpItemId = itemId;
578
+ break;
579
+ }
580
+ pos = ctEnd + 1;
581
+ }
582
+ pos = infeStart + infeSize;
583
+ }
584
+ if (!xmpItemId) return null;
585
+ const iloc = this.findBox(
586
+ buffer,
587
+ "iloc",
588
+ meta.pos + 4,
589
+ meta.pos + meta.size
590
+ );
591
+ if (!iloc) return null;
592
+ pos = iloc.pos;
593
+ const ilocVersion = buffer[pos++];
594
+ const sizes = buffer?.[pos++];
595
+ if (!sizes) return null;
596
+ const offsetSize = sizes >> 4 & 15;
597
+ const lengthSize = sizes & 15;
598
+ let indexSize = 0;
599
+ if (ilocVersion === 1 || ilocVersion === 2) {
600
+ const indexSizes = buffer?.[pos++];
601
+ if (!indexSizes) return null;
602
+ indexSize = indexSizes >> 4 & 15;
603
+ }
604
+ if (!ilocVersion) return null;
605
+ let buffpos = buffer?.[pos++];
606
+ if (!buffpos) return null;
607
+ const baseOffsetSize = ilocVersion < 2 ? 0 : buffpos >> 4 & 15;
608
+ const itemCountIloc = ilocVersion < 2 ? buffer.readUInt16BE(pos) : buffer.readUInt32BE(pos);
609
+ pos += ilocVersion < 2 ? 2 : 4;
610
+ let xmpOffset = 0;
611
+ let xmpLength = 0;
612
+ for (let i = 0; i < itemCountIloc; i++) {
613
+ const curItemId = ilocVersion < 2 ? buffer.readUInt16BE(pos) : buffer.readUInt32BE(pos);
614
+ pos += ilocVersion < 2 ? 2 : 4;
615
+ if (curItemId !== xmpItemId) {
616
+ if (ilocVersion === 1 || ilocVersion === 2) pos += 2;
617
+ pos += 2;
618
+ pos += baseOffsetSize;
619
+ const extentCount2 = buffer.readUInt16BE(pos);
620
+ pos += 2;
621
+ for (let e = 0; e < extentCount2; e++) {
622
+ if (indexSize > 0) pos += indexSize;
623
+ pos += offsetSize + lengthSize;
624
+ }
625
+ continue;
626
+ }
627
+ if (ilocVersion === 1 || ilocVersion === 2) {
628
+ const constructionMethod = buffer.readUInt16BE(pos);
629
+ pos += 2;
630
+ if (constructionMethod !== 0) return null;
631
+ }
632
+ pos += 2;
633
+ const baseOffset = this.readVarSize(buffer, pos, baseOffsetSize);
634
+ pos += baseOffsetSize;
635
+ const extentCount = buffer.readUInt16BE(pos);
636
+ pos += 2;
637
+ if (extentCount !== 1) return null;
638
+ if (indexSize > 0) pos += indexSize;
639
+ const extentOffset = this.readVarSize(buffer, pos, offsetSize);
640
+ pos += offsetSize;
641
+ const extentLength = this.readVarSize(buffer, pos, lengthSize);
642
+ xmpOffset = baseOffset + extentOffset;
643
+ xmpLength = extentLength;
644
+ break;
645
+ }
646
+ if (xmpOffset === 0 || xmpLength === 0 || xmpOffset + xmpLength > buffer.length)
647
+ return null;
648
+ return buffer.toString("utf8", xmpOffset, xmpOffset + xmpLength);
649
+ }
650
+ readVarSize(buffer, pos, size) {
651
+ if (size === 0) return 0;
652
+ if (size === 1 && buffer?.[pos]) return buffer?.[pos];
653
+ if (size === 2) return buffer.readUInt16BE(pos);
654
+ if (size === 3) {
655
+ let pos1 = buffer?.[pos + 1], pos2 = buffer?.[pos + 2];
656
+ if (buffer?.[pos] && pos1 && pos2) {
657
+ return buffer[pos] << 16 | pos1 << 8 | pos2;
658
+ }
659
+ throw new Error("Invalid var size");
660
+ }
661
+ if (size === 4) return buffer.readUInt32BE(pos);
662
+ if (size === 8) return Number(buffer.readBigUInt64BE(pos));
663
+ throw new Error("Invalid var size");
664
+ }
665
+ findBox(buffer, type, start = 0, end = buffer.length) {
666
+ let pos = start;
667
+ while (pos < end) {
668
+ let boxSize = buffer.readUInt32BE(pos);
669
+ let boxType = buffer.toString("ascii", pos + 4, pos + 8);
670
+ let hdrSize = 8;
671
+ if (boxSize === 1) {
672
+ boxSize = Number(buffer.readBigUInt64BE(pos + 8));
673
+ hdrSize = 16;
674
+ } else if (boxSize === 0) {
675
+ boxSize = end - pos;
676
+ }
677
+ if (boxType === type) {
678
+ return { pos: pos + hdrSize, size: boxSize - hdrSize };
679
+ }
680
+ pos += boxSize;
681
+ }
682
+ return null;
683
+ }
684
+ getImageSpecsWorkup(buffer) {
685
+ if (buffer?.length >= 24 && buffer?.[0] === 137 && buffer?.[1] === 80 && buffer?.[2] === 78 && buffer?.[3] === 71 && buffer?.[4] === 13 && buffer?.[5] === 10 && buffer?.[6] === 26 && buffer?.[7] === 10) {
686
+ if (buffer.readUint32BE(8) !== 13 || buffer?.[12] !== 73 || buffer?.[13] !== 72 || buffer?.[14] !== 68 || buffer?.[15] !== 82) {
687
+ throw new Error("IHDR Chunk of png not found or incorrect.");
688
+ }
689
+ const colorType = buffer[25];
690
+ let colorSpace;
691
+ let hasAlpha = false;
692
+ switch (colorType) {
693
+ case 0:
694
+ colorSpace = "grayscale";
695
+ break;
696
+ case 2:
697
+ colorSpace = "rgb";
698
+ break;
699
+ case 3:
700
+ colorSpace = "indexed";
701
+ break;
702
+ case 4:
703
+ colorSpace = "grayscale-alpha";
704
+ hasAlpha = true;
705
+ break;
706
+ case 6:
707
+ colorSpace = "rgba";
708
+ hasAlpha = true;
709
+ break;
710
+ default:
711
+ colorSpace = "unknown";
712
+ }
713
+ const width = buffer.readUInt32BE(16);
714
+ const height = buffer.readUInt32BE(20);
715
+ let frames = 1;
716
+ let animated = false;
717
+ let iccProfile = null;
718
+ let exifDateTimeOriginal = null;
719
+ let orientation = null;
720
+ let pos = 33;
721
+ while (pos < buffer.length - 12) {
722
+ const chunkLen = buffer.readUInt32BE(pos);
723
+ const chunkType = buffer.toString("ascii", pos + 4, pos + 8);
724
+ const chunkData = pos + 8;
725
+ if (chunkType === "acTL") {
726
+ animated = true;
727
+ frames = buffer.readUInt32BE(chunkData);
728
+ } else if (chunkType === "iCCP") {
729
+ const nameEnd = buffer.indexOf(0, chunkData);
730
+ const profileName = buffer.toString("ascii", chunkData, nameEnd);
731
+ iccProfile = profileName || "embedded";
732
+ } else if (chunkType === "tIME") {
733
+ const month = buffer?.[chunkData + 2], day = buffer?.[chunkData + 3], hour = buffer?.[chunkData + 4], minute = buffer?.[chunkData + 5], second = buffer?.[chunkData + 6];
734
+ if (typeof month !== "undefined" && typeof day !== "undefined" && typeof hour !== "undefined" && typeof minute !== "undefined" && typeof second !== "undefined") {
735
+ const year = buffer.readUInt16BE(chunkData);
736
+ exifDateTimeOriginal = `${year}:${month.toString().padStart(2, "0")}:${day.toString().padStart(2, "0")} ${hour.toString().padStart(2, "0")}:${minute.toString().padStart(2, "0")}:${second.toString().padStart(2, "0")}`;
737
+ }
738
+ } else if (chunkType === "IDAT") {
739
+ break;
740
+ }
741
+ pos += 12 + chunkLen;
742
+ }
743
+ return {
744
+ width,
745
+ height,
746
+ format: "png",
747
+ frames,
748
+ animated,
749
+ hasAlpha,
750
+ orientation,
751
+ aspectRatio: width / height,
752
+ colorSpace,
753
+ iccProfile,
754
+ exifDateTimeOriginal
755
+ };
756
+ }
757
+ if (buffer.length >= 10 && buffer[0] === 255 && buffer[1] === 216) {
758
+ let pos = 2, colorSpace = "unknown", hasAlpha = false, width = 0, height = 0, iccProfile = null, orientation = null, exifDateTimeOriginal = null;
759
+ while (pos < buffer.length - 10) {
760
+ if (buffer[pos] !== 255) {
761
+ throw new Error("Invalid JPEG file");
762
+ }
763
+ const marker = buffer[pos + 1];
764
+ if (marker === 218) break;
765
+ const segmentSize = buffer.readUInt16BE(pos + 2);
766
+ if (!marker) {
767
+ throw new Error("no marker for jpeg");
768
+ }
769
+ if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
770
+ const numComponents = buffer[pos + 4];
771
+ switch (numComponents) {
772
+ case 1:
773
+ colorSpace = "grayscale";
774
+ break;
775
+ case 3:
776
+ colorSpace = "ycbcr";
777
+ break;
778
+ // Most common for RGB JPEGs (stored as YCbCr)
779
+ case 4:
780
+ colorSpace = "ycck";
781
+ break;
782
+ // YCCK for CMYK with alpha-like, but no true alpha
783
+ default:
784
+ colorSpace = "unknown";
785
+ }
786
+ width = buffer.readUInt16BE(pos + 7);
787
+ height = buffer.readUInt16BE(pos + 5);
788
+ } else if (marker === 225) {
789
+ const { orientation: ori, dateTimeOriginal } = this.parseExif(
790
+ buffer,
791
+ pos,
792
+ segmentSize
793
+ );
794
+ orientation = ori;
795
+ exifDateTimeOriginal = dateTimeOriginal;
796
+ } else if (marker === 226) {
797
+ const iccHeader = buffer.toString("ascii", pos + 4, pos + 18);
798
+ if (iccHeader.startsWith("ICC_PROFILE")) {
799
+ iccProfile = "embedded";
800
+ }
801
+ }
802
+ pos += segmentSize + 2;
803
+ }
804
+ if (width === 0) throw new Error("No dimensions found in JPEG file");
805
+ return {
806
+ width,
807
+ height,
808
+ format: "jpeg",
809
+ frames: 1,
810
+ animated: false,
811
+ // JPEG not animated
812
+ hasAlpha,
813
+ orientation,
814
+ aspectRatio: width / height,
815
+ colorSpace,
816
+ iccProfile,
817
+ exifDateTimeOriginal
818
+ };
819
+ }
820
+ const gifHeader = buffer.toString("ascii", 0, 6);
821
+ if (buffer.length >= 10 && (gifHeader === "GIF87a" || gifHeader === "GIF89a")) {
822
+ const width = buffer.readUInt16LE(6), height = buffer.readUInt16LE(8);
823
+ let frames = 0;
824
+ let pos = 13;
825
+ let bufTen = buffer?.[10];
826
+ if (typeof bufTen === "undefined") {
827
+ pos = 13;
828
+ frames = 0;
829
+ } else if (bufTen & 128) pos += 3 << (bufTen & 7) + 1;
830
+ while (pos < buffer.length) {
831
+ if (buffer[pos] === 33) {
832
+ pos += 2;
833
+ let subSize = buffer?.[pos];
834
+ while (subSize && subSize > 0) {
835
+ pos += subSize + 1;
836
+ subSize = buffer?.[pos];
837
+ }
838
+ pos++;
839
+ } else if (buffer?.[pos] && buffer?.[pos] === 44) {
840
+ frames++;
841
+ pos += 10;
842
+ let b = buffer?.[pos - 1];
843
+ if (typeof b !== "undefined" && b & 128)
844
+ pos += 3 << (b & 7) + 1;
845
+ pos++;
846
+ let dataSize = buffer?.[pos];
847
+ while (dataSize && dataSize > 0) {
848
+ pos += dataSize + 1;
849
+ dataSize = buffer[pos];
850
+ }
851
+ pos++;
852
+ } else if (buffer[pos] === 59) {
853
+ break;
854
+ } else {
855
+ pos++;
856
+ }
857
+ }
858
+ return {
859
+ width,
860
+ height,
861
+ format: "gif",
862
+ frames,
863
+ animated: frames > 1,
864
+ hasAlpha: null,
865
+ // GIF transparency is per-pixel binary, not full alpha; set null or true if transparent color exists, but complex
866
+ orientation: null,
867
+ // No orientation in GIF
868
+ aspectRatio: width / height,
869
+ colorSpace: "indexed",
870
+ iccProfile: null,
871
+ // No ICC in GIF
872
+ exifDateTimeOriginal: null
873
+ // No EXIF in GIF
874
+ };
875
+ }
876
+ if (buffer.length >= 26 && buffer?.[0] === 66 && buffer?.[1] === 77) {
877
+ const width = buffer.readInt32LE(18);
878
+ const height = Math.abs(buffer.readInt32LE(22));
879
+ const bitDepth = buffer.readUInt16LE(28);
880
+ let colorSpace = bitDepth <= 8 ? "indexed" : "rgb";
881
+ return {
882
+ width,
883
+ height,
884
+ format: "bmp",
885
+ frames: 1,
886
+ animated: false,
887
+ hasAlpha: null,
888
+ // Some BMP have alpha in 32bpp, check if bitDepth===32 && compression===3 (bitfields with alpha)
889
+ orientation: buffer.readInt32LE(22) < 0 ? 1 : 6,
890
+ // Negative height means top-down (orientation 1), positive bottom-up (like 6, but simplified)
891
+ aspectRatio: width / height,
892
+ colorSpace,
893
+ iccProfile: null,
894
+ // Rare in BMP
895
+ exifDateTimeOriginal: null
896
+ };
897
+ }
898
+ if (buffer.length >= 30 && buffer.toString("ascii", 0, 4) === "RIFF" && buffer.toString("ascii", 8, 12) === "WEBP") {
899
+ const chunkType = buffer.toString("ascii", 12, 16);
900
+ let colorSpace = "unknown";
901
+ let hasAlpha = false;
902
+ let width = 0;
903
+ let height = 0;
904
+ let frames = 1;
905
+ let animated = false;
906
+ let iccProfile = null;
907
+ if (chunkType === "VP8X") {
908
+ const flags = buffer?.[20];
909
+ colorSpace = flags ? flags & 2 ? "rgba" : "rgb" : "unknown";
910
+ hasAlpha = flags ? !!(flags & 2) : false;
911
+ animated = flags ? !!(flags & 1) : false;
912
+ let widthSubtractOne = 0;
913
+ let heightSubtractOne = 0;
914
+ if (buffer?.[24] && buffer?.[25] && buffer?.[26]) {
915
+ widthSubtractOne = buffer[24] | buffer[25] << 8 | buffer[26] << 16;
916
+ }
917
+ if (buffer?.[27] && buffer?.[28] && buffer?.[29]) {
918
+ heightSubtractOne = buffer[27] | buffer[28] << 8 | buffer[29] << 16;
919
+ }
920
+ width = widthSubtractOne + 1;
921
+ height = heightSubtractOne + 1;
922
+ if (animated) {
923
+ let pos = 30;
924
+ frames = 0;
925
+ while (pos < buffer.length - 8) {
926
+ const subChunkType = buffer.toString("ascii", pos, pos + 4);
927
+ const subChunkSize = buffer.readUInt32LE(pos + 4);
928
+ if (subChunkType === "ICCP") {
929
+ iccProfile = "embedded";
930
+ } else if (subChunkType === "ANMF") {
931
+ frames++;
932
+ }
933
+ pos += 8 + subChunkSize + subChunkSize % 2;
934
+ }
935
+ }
936
+ } else if (chunkType === "VP8 ") {
937
+ colorSpace = "rgb";
938
+ hasAlpha = false;
939
+ const dataStart = 20;
940
+ if (buffer?.[dataStart + 3] !== 157 || buffer?.[dataStart + 4] !== 1 || buffer?.[dataStart + 5] !== 42) {
941
+ throw new Error("Invalid VP8 keyframe");
942
+ }
943
+ width = buffer.readUInt16LE(dataStart + 6) & 16383;
944
+ height = buffer.readUInt16LE(dataStart + 8) & 16383;
945
+ } else if (chunkType === "VP8L") {
946
+ const dataStart = 20;
947
+ if (buffer?.[dataStart] !== 47) {
948
+ throw new Error("Invalid VP8L signature");
949
+ }
950
+ const bits = buffer.readUInt32LE(dataStart + 1);
951
+ if (bits >>> 29 !== 0) {
952
+ throw new Error("Invalid VP8L version");
953
+ }
954
+ colorSpace = bits & 1 << 8 ? "rgba" : "rgb";
955
+ hasAlpha = !!(bits & 1 << 8);
956
+ width = 1 + (bits & 16383);
957
+ height = 1 + (bits >> 14 & 16383);
958
+ } else {
959
+ throw new Error("Unsupported WebP chunk");
960
+ }
961
+ return {
962
+ width,
963
+ height,
964
+ format: "webp",
965
+ frames,
966
+ animated,
967
+ hasAlpha,
968
+ orientation: null,
969
+ // No standard orientation in WebP
970
+ aspectRatio: width / height,
971
+ colorSpace,
972
+ iccProfile,
973
+ exifDateTimeOriginal: null
974
+ // Can have EXIF chunk, but rare; add if needed
975
+ };
976
+ }
977
+ if (buffer.length >= 32 && buffer.toString("ascii", 4, 8) === "ftyp") {
978
+ const ftyp = this.findBox(buffer, "ftyp");
979
+ if (!ftyp) throw new Error("Invalid AVIF: No ftyp");
980
+ const brands = buffer.toString("ascii", ftyp.pos, ftyp.pos + ftyp.size);
981
+ const isAvif = brands.includes("avif");
982
+ const isAvis = brands.includes("avis");
983
+ if (!isAvif && !isAvis) throw new Error("Not an AVIF file");
984
+ const meta = this.findBox(buffer, "meta");
985
+ if (!meta) throw new Error("Invalid AVIF: No meta");
986
+ const metaSubStart = meta.pos + 4;
987
+ const metaSubEnd = meta.pos + meta.size;
988
+ const iprp = this.findBox(buffer, "iprp", metaSubStart, metaSubEnd);
989
+ if (!iprp) throw new Error("Invalid AVIF: No iprp");
990
+ const ipco = this.findBox(buffer, "ipco", iprp.pos, iprp.pos + iprp.size);
991
+ if (!ipco) throw new Error("Invalid AVIF: No ipco");
992
+ const ispe = this.findBox(buffer, "ispe", ipco.pos, ipco.pos + ipco.size);
993
+ if (!ispe) throw new Error("Invalid AVIF: No ispe");
994
+ if (buffer[ispe.pos] !== 0) throw new Error("Invalid ispe version");
995
+ const width = buffer.readUInt32BE(ispe.pos + 4);
996
+ const height = buffer.readUInt32BE(ispe.pos + 8);
997
+ let colorSpace = "rgb";
998
+ let hasAlpha = false;
999
+ let iccProfile = null;
1000
+ const colr = this.findBox(buffer, "colr", ipco.pos, ipco.pos + ipco.size);
1001
+ if (colr) {
1002
+ const colrType = buffer.toString("ascii", colr.pos, colr.pos + 4);
1003
+ if (colrType === "nclx") {
1004
+ const matrix = buffer.readUInt16BE(colr.pos + 6);
1005
+ colorSpace = matrix === 2 ? "rgb" : "ycbcr";
1006
+ } else if (colrType === "rICC" || colrType === "prof") {
1007
+ colorSpace = "unknown";
1008
+ iccProfile = "embedded";
1009
+ }
1010
+ }
1011
+ const auxC = this.findBox(buffer, "auxC", ipco.pos, ipco.pos + ipco.size);
1012
+ if (auxC && buffer.toString("ascii", auxC.pos, auxC.pos + auxC.size).includes("alpha")) {
1013
+ hasAlpha = true;
1014
+ if (colorSpace === "rgb") {
1015
+ colorSpace = "rgba";
1016
+ } else if (colorSpace === "ycbcr") {
1017
+ colorSpace = "ycck";
1018
+ } else if (colorSpace === "grayscale" || colorSpace === "unknown") {
1019
+ colorSpace = "grayscale-alpha";
1020
+ }
1021
+ }
1022
+ const xmpXml = this.parseXmpFromAvif(buffer, meta, ipco);
1023
+ let exifDateTimeOriginal = null;
1024
+ if (xmpXml) {
1025
+ let dateStart = xmpXml.indexOf('xmp:CreateDate="');
1026
+ if (dateStart === -1)
1027
+ dateStart = xmpXml.indexOf('photoshop:DateCreated="');
1028
+ if (dateStart !== -1) {
1029
+ dateStart += 16;
1030
+ const dateEnd = xmpXml.indexOf('"', dateStart);
1031
+ if (dateEnd !== -1) {
1032
+ exifDateTimeOriginal = xmpXml.substring(dateStart, dateEnd);
1033
+ }
1034
+ }
1035
+ }
1036
+ let frames = 1;
1037
+ let animated = isAvis;
1038
+ if (animated) {
1039
+ const iloc = this.findBox(buffer, "iloc", metaSubStart, metaSubEnd);
1040
+ if (iloc) {
1041
+ const version = buffer?.[iloc.pos] ?? 0;
1042
+ const itemCountPos = iloc.pos + (version < 2 ? 4 : 6);
1043
+ let itemCount = buffer?.readUInt16BE(itemCountPos) ?? 0;
1044
+ if (version >= 2) itemCount = buffer?.readUInt32BE(itemCountPos) ?? 0;
1045
+ frames = Math.max(1, Math.floor(itemCount / (hasAlpha ? 2 : 1)));
1046
+ }
1047
+ }
1048
+ return {
1049
+ width,
1050
+ height,
1051
+ format: "avif",
1052
+ frames,
1053
+ animated,
1054
+ hasAlpha: hasAlpha ? true : null,
1055
+ orientation: null,
1056
+ // Can have 'irot' or 'imir' transforms, but rare
1057
+ aspectRatio: width / height,
1058
+ colorSpace,
1059
+ iccProfile,
1060
+ exifDateTimeOriginal
1061
+ // Can have 'XMP' box, but parse XMP for date if needed
1062
+ };
1063
+ }
1064
+ throw new Error("Unsupported image format or invalid file");
1065
+ }
1066
+ };
1067
+ // Annotate the CommonJS export names for ESM import in node:
1068
+ 0 && (module.exports = {
1069
+ ImageService
1070
+ });
1071
+ //# sourceMappingURL=index.cjs.map