@d0paminedriven/fs 6.5.0 → 7.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.
@@ -113,12 +113,12 @@ declare class Fs extends MimeService {
113
113
  fileToBufferAsync: <const T extends string>(path: T) => Promise<Buffer<ArrayBufferLike>>;
114
114
  dirContainsDir<const From extends string, const To extends string>(readDir: From, targetDir: To, options?: ReadDirOptions): boolean;
115
115
  assetToBuffer<const T extends string>(path: T): Promise<{
116
- readonly b64encodedData: `data:application/octet-stream;base64, ${string}` | `data:audio/aac;base64, ${string}` | `data:application/x-abiword;base64, ${string}` | `data:image/aces;base64, ${string}` | `data:image/apng;base64, ${string}` | `data:application/x-freearc;base64, ${string}` | `data:image/avci;base64, ${string}` | `data:image/avif;base64, ${string}` | `data:video/x-msvideo;base64, ${string}` | `data:application/vnd.amazon.ebook;base64, ${string}` | `data:multipart/voice-message;base64, ${string}` | `data:image/bmp;base64, ${string}` | `data:application/x-bzip;base64, ${string}` | `data:application/x-bzip2;base64, ${string}` | `data:application/x-cdf;base64, ${string}` | `data:application/node;base64, ${string}` | `data:text/javascript;base64, ${string}` | `data:application/x-csh;base64, ${string}` | `data:text/css;base64, ${string}` | `data:text/csv;base64, ${string}` | `data:application/msword;base64, ${string}` | `data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64, ${string}` | `data:image/dpx;base64, ${string}` | `data:image/emf;base64, ${string}` | `data:application/vnd.ms-fontobject;base64, ${string}` | `data:application/epub+zip;base64, ${string}` | `data:image/gif;base64, ${string}` | `data:model/gltf-binary;base64, ${string}` | `data:model/gltf+json;base64, ${string}` | `data:application/gzip;base64, ${string}` | `data:application/x-gzip;base64, ${string}` | `data:haptics/hjif;base64, ${string}` | `data:haptics/hmpg;base64, ${string}` | `data:text/html;base64, ${string}` | `data:image/vnd.microsoft.icon;base64, ${string}` | `data:text/calendar;base64, ${string}` | `data:haptics/ivs;base64, ${string}` | `data:application/java-archive;base64, ${string}` | `data:image/jpeg;base64, ${string}` | `data:application/json;base64, ${string}` | `data:application/ld+json;base64, ${string}` | `data:image/ktx;base64, ${string}` | `data:image/ktx2;base64, ${string}` | `data:application/vnd.apple.mpegurl;base64, ${string}` | `data:audio/mp4;base64, ${string}` | `data:video/mp4;base64, ${string}` | `data:text/markdown;base64, ${string}` | `data:application/x-mdx;base64, ${string}` | `data:audio/midi;base64, ${string}` | `data:audio/x-midi;base64, ${string}` | `data:audio/mpeg;base64, ${string}` | `data:video/mpeg;base64, ${string}` | `data:application/vnd.apple.installer+xml;base64, ${string}` | `data:application/x-ndjson;base64, ${string}` | `data:model/obj;base64, ${string}` | `data:text/plain;base64, ${string}` | `data:application/vnd.oasis.opendocument.presentation;base64, ${string}` | `data:application/vnd.oasis.opendocument.spreadsheet;base64, ${string}` | `data:application/vnd.oasis.opendocument.text;base64, ${string}` | `data:audio/ogg;base64, ${string}` | `data:video/ogg;base64, ${string}` | `data:application/ogg;base64, ${string}` | `data:font/otf;base64, ${string}` | `data:image/png;base64, ${string}` | `data:application/pdf;base64, ${string}` | `data:application/x-httpd-php;base64, ${string}` | `data:application/vnd.apple.pkpass;base64, ${string}` | `data:application/vnd.ms-powerpoint;base64, ${string}` | `data:application/vnd.openxmlformats-officedocument.presentationml.presentation;base64, ${string}` | `data:text/x-python;base64, ${string}` | `data:application/x-python-code;base64, ${string}` | `data:application/vnd.rar;base64, ${string}` | `data:text/rust;base64, ${string}` | `data:application/rtf;base64, ${string}` | `data:application/x-sh;base64, ${string}` | `data:application/sql;base64, ${string}` | `data:text/event-stream;base64, ${string}` | `data:image/svg+xml;base64, ${string}` | `data:application/x-tar;base64, ${string}` | `data:image/tiff;base64, ${string}` | `data:application/toml;base64, ${string}` | `data:text/typescript;base64, ${string}` | `data:video/mp2t;base64, ${string}` | `data:video/vnd.dlna.mpeg-tts;base64, ${string}` | `data:application/font-sfnt;base64, ${string}` | `data:font/ttf;base64, ${string}` | `data:model/vnd.usdz+zip;base64, ${string}` | `data:application/vnd.visio;base64, ${string}` | `data:text/vtt;base64, ${string}` | `data:application/wasm;base64, ${string}` | `data:audio/wav;base64, ${string}` | `data:video/webm;base64, ${string}` | `data:image/webp;base64, ${string}` | `data:font/woff;base64, ${string}` | `data:font/woff2;base64, ${string}` | `data:application/xhtml+xml;base64, ${string}` | `data:application/vnd.ms-excel;base64, ${string}` | `data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64, ${string}` | `data:application/xml;base64, ${string}` | `data:application/vnd.mozilla.xul+xml;base64, ${string}` | `data:application/yaml;base64, ${string}` | `data:application/zip;base64, ${string}` | `data:application/x-zip-compressed;base64, ${string}` | `data:video/3gpp;base64, ${string}` | `data:video/3gpp2;base64, ${string}` | `data:application/x-7z-compressed;base64, ${string}`;
117
- readonly extension: "aac" | "abw" | "aces" | "apng" | "arc" | "avci" | "avif" | "avi" | "azw" | "bin" | "bmp" | "bz" | "bz2" | "cda" | "cjs" | "csh" | "css" | "csv" | "doc" | "docx" | "dpx" | "emf" | "eot" | "epub" | "gif" | "glb" | "gltf" | "gz" | "hjif" | "hmpg" | "htm" | "html" | "ico" | "ics" | "ivs" | "ivt" | "jar" | "jpeg" | "jpg" | "js" | "json" | "jsonld" | "ktx" | "ktx2" | "m3u8" | "m4a" | "m4v" | "md" | "mdx" | "mid" | "midi" | "mjs" | "mp3" | "mp4" | "mpeg" | "mpkg" | "ndjson" | "node" | "obj" | "odp" | "ods" | "odt" | "oga" | "ogg" | "ogv" | "ogx" | "opus" | "otf" | "png" | "pdf" | "php" | "pkpass" | "ppt" | "pptx" | "py" | "pyc" | "rar" | "rs" | "rtf" | "sh" | "sql" | "sse" | "svg" | "tar" | "tif" | "tiff" | "toml" | "ts" | "ttf" | "txt" | "usdz" | "vsd" | "vtt" | "wasm" | "wav" | "weba" | "webp" | "woff" | "woff2" | "xhtml" | "xls" | "xlsx" | "xml" | "xul" | "yaml" | "yml" | "zip" | "3gp" | "3g2" | "7z";
116
+ readonly b64encodedData: `data:audio/aac;base64, ${string}` | `data:application/x-abiword;base64, ${string}` | `data:image/aces;base64, ${string}` | `data:image/apng;base64, ${string}` | `data:application/x-freearc;base64, ${string}` | `data:image/avci;base64, ${string}` | `data:image/avif;base64, ${string}` | `data:video/x-msvideo;base64, ${string}` | `data:application/vnd.amazon.ebook;base64, ${string}` | `data:application/octet-stream;base64, ${string}` | `data:multipart/voice-message;base64, ${string}` | `data:image/bmp;base64, ${string}` | `data:application/x-bzip;base64, ${string}` | `data:application/x-bzip2;base64, ${string}` | `data:application/x-cdf;base64, ${string}` | `data:application/node;base64, ${string}` | `data:text/javascript;base64, ${string}` | `data:application/x-csh;base64, ${string}` | `data:text/css;base64, ${string}` | `data:text/csv;base64, ${string}` | `data:application/msword;base64, ${string}` | `data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64, ${string}` | `data:image/dpx;base64, ${string}` | `data:image/emf;base64, ${string}` | `data:application/vnd.ms-fontobject;base64, ${string}` | `data:application/epub+zip;base64, ${string}` | `data:image/gif;base64, ${string}` | `data:model/gltf-binary;base64, ${string}` | `data:model/gltf+json;base64, ${string}` | `data:application/gzip;base64, ${string}` | `data:application/x-gzip;base64, ${string}` | `data:haptics/hjif;base64, ${string}` | `data:haptics/hmpg;base64, ${string}` | `data:text/html;base64, ${string}` | `data:image/vnd.microsoft.icon;base64, ${string}` | `data:text/calendar;base64, ${string}` | `data:haptics/ivs;base64, ${string}` | `data:application/java-archive;base64, ${string}` | `data:image/jpeg;base64, ${string}` | `data:application/json;base64, ${string}` | `data:application/ld+json;base64, ${string}` | `data:image/ktx;base64, ${string}` | `data:image/ktx2;base64, ${string}` | `data:application/vnd.apple.mpegurl;base64, ${string}` | `data:audio/mp4;base64, ${string}` | `data:video/mp4;base64, ${string}` | `data:text/markdown;base64, ${string}` | `data:application/x-mdx;base64, ${string}` | `data:audio/midi;base64, ${string}` | `data:audio/x-midi;base64, ${string}` | `data:audio/mpeg;base64, ${string}` | `data:video/mpeg;base64, ${string}` | `data:application/vnd.apple.installer+xml;base64, ${string}` | `data:application/x-ndjson;base64, ${string}` | `data:model/obj;base64, ${string}` | `data:text/plain;base64, ${string}` | `data:application/vnd.oasis.opendocument.presentation;base64, ${string}` | `data:application/vnd.oasis.opendocument.spreadsheet;base64, ${string}` | `data:application/vnd.oasis.opendocument.text;base64, ${string}` | `data:audio/ogg;base64, ${string}` | `data:video/ogg;base64, ${string}` | `data:application/ogg;base64, ${string}` | `data:font/otf;base64, ${string}` | `data:image/png;base64, ${string}` | `data:application/pdf;base64, ${string}` | `data:application/x-httpd-php;base64, ${string}` | `data:application/vnd.apple.pkpass;base64, ${string}` | `data:application/vnd.ms-powerpoint;base64, ${string}` | `data:application/vnd.openxmlformats-officedocument.presentationml.presentation;base64, ${string}` | `data:text/x-python;base64, ${string}` | `data:application/x-python-code;base64, ${string}` | `data:application/vnd.rar;base64, ${string}` | `data:text/rust;base64, ${string}` | `data:application/rtf;base64, ${string}` | `data:application/x-sh;base64, ${string}` | `data:application/sql;base64, ${string}` | `data:text/event-stream;base64, ${string}` | `data:image/svg+xml;base64, ${string}` | `data:application/x-tar;base64, ${string}` | `data:image/tiff;base64, ${string}` | `data:application/toml;base64, ${string}` | `data:text/typescript;base64, ${string}` | `data:video/mp2t;base64, ${string}` | `data:video/vnd.dlna.mpeg-tts;base64, ${string}` | `data:application/font-sfnt;base64, ${string}` | `data:font/ttf;base64, ${string}` | `data:model/vnd.usdz+zip;base64, ${string}` | `data:application/vnd.visio;base64, ${string}` | `data:text/vtt;base64, ${string}` | `data:application/wasm;base64, ${string}` | `data:audio/wav;base64, ${string}` | `data:video/webm;base64, ${string}` | `data:image/webp;base64, ${string}` | `data:font/woff;base64, ${string}` | `data:font/woff2;base64, ${string}` | `data:application/xhtml+xml;base64, ${string}` | `data:application/vnd.ms-excel;base64, ${string}` | `data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64, ${string}` | `data:application/xml;base64, ${string}` | `data:application/vnd.mozilla.xul+xml;base64, ${string}` | `data:application/yaml;base64, ${string}` | `data:application/zip;base64, ${string}` | `data:application/x-zip-compressed;base64, ${string}` | `data:video/3gpp;base64, ${string}` | `data:video/3gpp2;base64, ${string}` | `data:application/x-7z-compressed;base64, ${string}`;
117
+ readonly extension: "png" | "jpeg" | "gif" | "bmp" | "webp" | "avif" | "epub" | "ttf" | "gz" | "jar" | "json" | "jsonld" | "doc" | "node" | "js" | "bin" | "obj" | "ogx" | "pdf" | "rtf" | "sql" | "toml" | "azw" | "mpkg" | "m3u8" | "pkpass" | "xul" | "xls" | "eot" | "ppt" | "odp" | "ods" | "odt" | "pptx" | "xlsx" | "docx" | "rar" | "vsd" | "wasm" | "7z" | "abw" | "bz" | "bz2" | "cda" | "csh" | "arc" | "php" | "mdx" | "ndjson" | "pyc" | "sh" | "tar" | "zip" | "xhtml" | "xml" | "yml" | "yaml" | "aac" | "mid" | "m4a" | "mp3" | "opus" | "ogg" | "oga" | "wav" | "midi" | "otf" | "woff" | "woff2" | "hjif" | "hmpg" | "ivs" | "ivt" | "aces" | "apng" | "avci" | "dpx" | "emf" | "jpg" | "ktx" | "ktx2" | "svg" | "tiff" | "tif" | "ico" | "glb" | "gltf" | "usdz" | "ics" | "css" | "csv" | "sse" | "ts" | "rs" | "py" | "txt" | "html" | "htm" | "cjs" | "mjs" | "md" | "vtt" | "3gp" | "3g2" | "mp4" | "m4v" | "mpeg" | "ogv" | "weba" | "avi";
118
118
  }>;
119
119
  assetToBufferView<const T extends string>(path: T): Promise<{
120
120
  readonly b64encodedData: string;
121
- readonly extension: "aac" | "abw" | "aces" | "apng" | "arc" | "avci" | "avif" | "avi" | "azw" | "bin" | "bmp" | "bz" | "bz2" | "cda" | "cjs" | "csh" | "css" | "csv" | "doc" | "docx" | "dpx" | "emf" | "eot" | "epub" | "gif" | "glb" | "gltf" | "gz" | "hjif" | "hmpg" | "htm" | "html" | "ico" | "ics" | "ivs" | "ivt" | "jar" | "jpeg" | "jpg" | "js" | "json" | "jsonld" | "ktx" | "ktx2" | "m3u8" | "m4a" | "m4v" | "md" | "mdx" | "mid" | "midi" | "mjs" | "mp3" | "mp4" | "mpeg" | "mpkg" | "ndjson" | "node" | "obj" | "odp" | "ods" | "odt" | "oga" | "ogg" | "ogv" | "ogx" | "opus" | "otf" | "png" | "pdf" | "php" | "pkpass" | "ppt" | "pptx" | "py" | "pyc" | "rar" | "rs" | "rtf" | "sh" | "sql" | "sse" | "svg" | "tar" | "tif" | "tiff" | "toml" | "ts" | "ttf" | "txt" | "usdz" | "vsd" | "vtt" | "wasm" | "wav" | "weba" | "webp" | "woff" | "woff2" | "xhtml" | "xls" | "xlsx" | "xml" | "xul" | "yaml" | "yml" | "zip" | "3gp" | "3g2" | "7z" | undefined;
121
+ readonly extension: "png" | "jpeg" | "gif" | "bmp" | "webp" | "avif" | "epub" | "ttf" | "gz" | "jar" | "json" | "jsonld" | "doc" | "node" | "js" | "bin" | "obj" | "ogx" | "pdf" | "rtf" | "sql" | "toml" | "azw" | "mpkg" | "m3u8" | "pkpass" | "xul" | "xls" | "eot" | "ppt" | "odp" | "ods" | "odt" | "pptx" | "xlsx" | "docx" | "rar" | "vsd" | "wasm" | "7z" | "abw" | "bz" | "bz2" | "cda" | "csh" | "arc" | "php" | "mdx" | "ndjson" | "pyc" | "sh" | "tar" | "zip" | "xhtml" | "xml" | "yml" | "yaml" | "aac" | "mid" | "m4a" | "mp3" | "opus" | "ogg" | "oga" | "wav" | "midi" | "otf" | "woff" | "woff2" | "hjif" | "hmpg" | "ivs" | "ivt" | "aces" | "apng" | "avci" | "dpx" | "emf" | "jpg" | "ktx" | "ktx2" | "svg" | "tiff" | "tif" | "ico" | "glb" | "gltf" | "usdz" | "ics" | "css" | "csv" | "sse" | "ts" | "rs" | "py" | "txt" | "html" | "htm" | "cjs" | "mjs" | "md" | "vtt" | "3gp" | "3g2" | "mp4" | "m4v" | "mpeg" | "ogv" | "weba" | "avi" | undefined;
122
122
  }>;
123
123
  formatHelper<const T extends string>(f: T): string;
124
124
  cleanDataUrl<const C extends string>(props: C): string;
@@ -135,6 +135,10 @@ declare class Fs extends MimeService {
135
135
  * ✅ 'public/assets/image-1.png'
136
136
  */
137
137
  fetchRemoteWriteLocal<const I extends string, const O extends string>(inputUrl: I, outputPath: O, useDetectedExtension?: boolean): Promise<void>;
138
+ parseExif(buffer: Buffer, app1Pos: number, _app1Size: number): {
139
+ orientation: number | null;
140
+ dateTimeOriginal: string | null;
141
+ };
138
142
  /**
139
143
  *
140
144
  * @param inputUrl remote url to fetch data from
@@ -153,30 +157,78 @@ declare class Fs extends MimeService {
153
157
  */
154
158
  fetchRemoteWriteLocalLargeFiles<const I extends string, const O extends string>(inputUrl: I, outputPathI: O, useDetectedExtension?: boolean): Promise<void>;
155
159
  private findBox;
156
- getImageSize(filePath: string): Promise<{
160
+ getImageSpecs(filePath: string): Promise<{
157
161
  width: number;
158
162
  height: number;
159
- type: "png";
163
+ format: "png";
164
+ frames: number;
165
+ animated: boolean;
166
+ hasAlpha: boolean;
167
+ orientation: null;
168
+ aspectRatio: number;
169
+ colorSpace: "unknown" | "rgb" | "rgba" | "grayscale" | "grayscale-alpha" | "indexed";
170
+ iccProfile: string | null;
171
+ exifDateTimeOriginal: string | null;
160
172
  } | {
161
173
  width: number;
162
174
  height: number;
163
- type: "jpeg";
175
+ format: "jpeg";
176
+ frames: number;
177
+ animated: false;
178
+ hasAlpha: false;
179
+ orientation: number | null;
180
+ aspectRatio: number;
181
+ colorSpace: "unknown" | "grayscale" | "ycbcr" | "ycck";
182
+ iccProfile: string | null;
183
+ exifDateTimeOriginal: string | null;
164
184
  } | {
165
185
  width: number;
166
186
  height: number;
167
- type: "gif";
187
+ format: "gif";
188
+ frames: number;
189
+ animated: boolean;
190
+ hasAlpha: null;
191
+ orientation: null;
192
+ aspectRatio: number;
193
+ colorSpace: "indexed";
194
+ iccProfile: null;
195
+ exifDateTimeOriginal: null;
168
196
  } | {
169
197
  width: number;
170
198
  height: number;
171
- type: "bmp";
199
+ format: "bmp";
200
+ frames: number;
201
+ animated: false;
202
+ hasAlpha: null;
203
+ orientation: number;
204
+ aspectRatio: number;
205
+ colorSpace: "rgb" | "indexed";
206
+ iccProfile: null;
207
+ exifDateTimeOriginal: null;
172
208
  } | {
173
209
  width: number;
174
210
  height: number;
175
- type: "webp";
211
+ format: "webp";
212
+ frames: number;
213
+ animated: boolean;
214
+ hasAlpha: boolean;
215
+ orientation: null;
216
+ aspectRatio: number;
217
+ colorSpace: "unknown" | "rgb" | "rgba";
218
+ iccProfile: string | null;
219
+ exifDateTimeOriginal: null;
176
220
  } | {
177
221
  width: number;
178
222
  height: number;
179
- type: "avif";
223
+ format: "avif";
224
+ frames: number;
225
+ animated: boolean;
226
+ hasAlpha: true | null;
227
+ orientation: null;
228
+ aspectRatio: number;
229
+ colorSpace: "unknown" | "rgb" | "rgba" | "grayscale-alpha" | "ycbcr" | "ycck";
230
+ iccProfile: string | null;
231
+ exifDateTimeOriginal: null;
180
232
  }>;
181
233
  /**
182
234
  *
package/dist/fs/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  Fs
3
- } from "../chunk-Y3TLKN7F.js";
4
- import "../chunk-O4BKLMFV.js";
5
- import "../chunk-MXEE2WS7.js";
3
+ } from "../chunk-CTA73JRX.js";
4
+ import "../chunk-CN45SMBB.js";
5
+ import "../chunk-G27YIWW7.js";
6
6
  import "../chunk-QBG7TFHM.js";
7
7
  import "../chunk-IUGBPDQJ.js";
8
8
  import "../chunk-7QVYU63E.js";
package/dist/index.cjs CHANGED
@@ -467,6 +467,21 @@ var MimeService = class extends UrlService {
467
467
  );
468
468
  }
469
469
  }
470
+ mimeToExt(mime) {
471
+ const extensions = this.toExtObj[mime];
472
+ if (extensions.length === 1) return extensions[0];
473
+ if (extensions.length === 2) {
474
+ return extensions[0];
475
+ }
476
+ if (extensions.length === 3) {
477
+ if (mime === "audio/ogg") return "ogg";
478
+ return extensions[0];
479
+ }
480
+ if (extensions.length === 5) {
481
+ return "sse";
482
+ }
483
+ return extensions[0];
484
+ }
470
485
  assetType(url) {
471
486
  const parsed = this.parseUrl(url);
472
487
  if (!parsed) return void 0;
@@ -506,7 +521,7 @@ var unitsObj = {
506
521
  };
507
522
 
508
523
  // src/fs/index.ts
509
- dotenv.config();
524
+ dotenv.config({ quiet: true });
510
525
  var Fs = class extends MimeService {
511
526
  constructor(cwd) {
512
527
  super();
@@ -826,7 +841,6 @@ var Fs = class extends MimeService {
826
841
  if (!response.ok) {
827
842
  throw new Error(`Failed to fetch asset: ${response.statusText}`);
828
843
  }
829
- console.log(Object.fromEntries(Array.from(response.headers.entries())));
830
844
  const reader = response.body?.getReader();
831
845
  if (reader) {
832
846
  const chunks = Array.of();
@@ -893,6 +907,38 @@ var Fs = class extends MimeService {
893
907
  return console.error(err);
894
908
  }
895
909
  }
910
+ parseExif(buffer, app1Pos, _app1Size) {
911
+ const exifHeader = buffer.toString("ascii", app1Pos + 2, app1Pos + 8);
912
+ if (exifHeader !== "Exif\0\0")
913
+ return { orientation: null, dateTimeOriginal: null };
914
+ let tiffPos = app1Pos + 8;
915
+ const byteOrder = buffer.toString("ascii", tiffPos, tiffPos + 2);
916
+ const littleEndian = byteOrder === "II";
917
+ const readUInt16 = littleEndian ? buffer.readUInt16LE.bind(buffer) : buffer.readUInt16BE.bind(buffer);
918
+ const readUInt32 = littleEndian ? buffer.readUInt32LE.bind(buffer) : buffer.readUInt32BE.bind(buffer);
919
+ if (readUInt16(tiffPos + 2) !== 42)
920
+ return { orientation: null, dateTimeOriginal: null };
921
+ let ifdOffset = readUInt32(tiffPos + 4);
922
+ tiffPos += ifdOffset;
923
+ const numEntries = readUInt16(tiffPos);
924
+ tiffPos += 2;
925
+ let orientation = null;
926
+ let dateTimeOriginal = null;
927
+ for (let i = 0; i < numEntries; i++) {
928
+ const tag = readUInt16(tiffPos);
929
+ const type = readUInt16(tiffPos + 2);
930
+ const count = readUInt32(tiffPos + 4);
931
+ const valueOffset = tiffPos + 8;
932
+ if (tag === 274 && type === 3 && count === 1) {
933
+ orientation = readUInt16(valueOffset);
934
+ } else if (tag === 36867 && type === 2 && count === 20) {
935
+ const offset = readUInt32(valueOffset);
936
+ dateTimeOriginal = buffer.toString("ascii", app1Pos + 2 + offset, app1Pos + 2 + offset + 19).trim();
937
+ }
938
+ tiffPos += 12;
939
+ }
940
+ return { orientation, dateTimeOriginal };
941
+ }
896
942
  /**
897
943
  *
898
944
  * @param inputUrl remote url to fetch data from
@@ -973,20 +1019,82 @@ var Fs = class extends MimeService {
973
1019
  }
974
1020
  return null;
975
1021
  }
976
- async getImageSize(filePath) {
1022
+ async getImageSpecs(filePath) {
977
1023
  const buffer = await this.fileToBufferAsync(filePath);
978
1024
  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) {
979
1025
  if (buffer.readUint32BE(8) !== 13 || buffer?.[12] !== 73 || buffer?.[13] !== 72 || buffer?.[14] !== 68 || buffer?.[15] !== 82) {
980
1026
  throw new Error("IHDR Chunk of png not found or incorrect.");
981
1027
  }
1028
+ const colorType = buffer[25];
1029
+ let colorSpace;
1030
+ let hasAlpha = false;
1031
+ switch (colorType) {
1032
+ case 0:
1033
+ colorSpace = "grayscale";
1034
+ break;
1035
+ case 2:
1036
+ colorSpace = "rgb";
1037
+ break;
1038
+ case 3:
1039
+ colorSpace = "indexed";
1040
+ break;
1041
+ case 4:
1042
+ colorSpace = "grayscale-alpha";
1043
+ hasAlpha = true;
1044
+ break;
1045
+ case 6:
1046
+ colorSpace = "rgba";
1047
+ hasAlpha = true;
1048
+ break;
1049
+ default:
1050
+ colorSpace = "unknown";
1051
+ }
1052
+ const width = buffer.readUInt32BE(16);
1053
+ const height = buffer.readUInt32BE(20);
1054
+ let frames = 1;
1055
+ let animated = false;
1056
+ let iccProfile = null;
1057
+ let exifDateTimeOriginal = null;
1058
+ let orientation = null;
1059
+ let pos = 33;
1060
+ while (pos < buffer.length - 12) {
1061
+ const chunkLen = buffer.readUInt32BE(pos);
1062
+ const chunkType = buffer.toString("ascii", pos + 4, pos + 8);
1063
+ const chunkData = pos + 8;
1064
+ if (chunkType === "acTL") {
1065
+ animated = true;
1066
+ frames = buffer.readUInt32BE(chunkData);
1067
+ } else if (chunkType === "iCCP") {
1068
+ const nameEnd = buffer.indexOf(0, chunkData);
1069
+ const profileName = buffer.toString("ascii", chunkData, nameEnd);
1070
+ iccProfile = profileName || "embedded";
1071
+ } else if (chunkType === "tIME") {
1072
+ const month = buffer?.[chunkData + 2], day = buffer?.[chunkData + 3], hour = buffer?.[chunkData + 4], minute = buffer?.[chunkData + 5], second = buffer?.[chunkData + 6];
1073
+ if (typeof month !== "undefined" && typeof day !== "undefined" && typeof hour !== "undefined" && typeof minute !== "undefined" && typeof second !== "undefined") {
1074
+ const year = buffer.readUInt16BE(chunkData);
1075
+ 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")}`;
1076
+ }
1077
+ } else if (chunkType === "IDAT") {
1078
+ break;
1079
+ }
1080
+ pos += 12 + chunkLen;
1081
+ }
982
1082
  return {
983
- width: buffer.readUInt32BE(16),
984
- height: buffer.readUInt32BE(20),
985
- type: "png"
1083
+ width,
1084
+ height,
1085
+ format: "png",
1086
+ frames,
1087
+ animated,
1088
+ hasAlpha,
1089
+ orientation,
1090
+ aspectRatio: width / height,
1091
+ colorSpace,
1092
+ iccProfile,
1093
+ exifDateTimeOriginal
986
1094
  };
987
1095
  }
988
1096
  if (buffer.length >= 10 && buffer[0] === 255 && buffer[1] === 216) {
989
- let pos = 2;
1097
+ let pos = 2, colorSpace = "unknown", hasAlpha = false, width = 0, height = 0, iccProfile = null, orientation = null, exifDateTimeOriginal = null;
990
1098
  while (pos < buffer.length - 10) {
991
1099
  if (buffer[pos] !== 255) {
992
1100
  throw new Error("Invalid JPEG file");
@@ -998,34 +1106,148 @@ var Fs = class extends MimeService {
998
1106
  throw new Error("no marker for jpeg");
999
1107
  }
1000
1108
  if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
1001
- return {
1002
- width: buffer.readUInt16BE(pos + 7),
1003
- height: buffer.readUInt16BE(pos + 5),
1004
- type: "jpeg"
1005
- };
1109
+ const numComponents = buffer[pos + 4];
1110
+ switch (numComponents) {
1111
+ case 1:
1112
+ colorSpace = "grayscale";
1113
+ break;
1114
+ case 3:
1115
+ colorSpace = "ycbcr";
1116
+ break;
1117
+ // Most common for RGB JPEGs (stored as YCbCr)
1118
+ case 4:
1119
+ colorSpace = "ycck";
1120
+ break;
1121
+ // YCCK for CMYK with alpha-like, but no true alpha
1122
+ default:
1123
+ colorSpace = "unknown";
1124
+ }
1125
+ width = buffer.readUInt16BE(pos + 7);
1126
+ height = buffer.readUInt16BE(pos + 5);
1127
+ } else if (marker === 225) {
1128
+ const { orientation: ori, dateTimeOriginal } = this.parseExif(
1129
+ buffer,
1130
+ pos,
1131
+ segmentSize
1132
+ );
1133
+ orientation = ori;
1134
+ exifDateTimeOriginal = dateTimeOriginal;
1135
+ } else if (marker === 226) {
1136
+ const iccHeader = buffer.toString("ascii", pos + 4, pos + 18);
1137
+ if (iccHeader.startsWith("ICC_PROFILE")) {
1138
+ iccProfile = "embedded";
1139
+ }
1006
1140
  }
1007
1141
  pos += segmentSize + 2;
1008
1142
  }
1009
- throw new Error("No dimensions found in JPEG file");
1143
+ if (width === 0) throw new Error("No dimensions found in JPEG file");
1144
+ return {
1145
+ width,
1146
+ height,
1147
+ format: "jpeg",
1148
+ frames: 1,
1149
+ animated: false,
1150
+ // JPEG not animated
1151
+ hasAlpha,
1152
+ orientation,
1153
+ aspectRatio: width / height,
1154
+ colorSpace,
1155
+ iccProfile,
1156
+ exifDateTimeOriginal
1157
+ };
1010
1158
  }
1011
1159
  const gifHeader = buffer.toString("ascii", 0, 6);
1012
1160
  if (buffer.length >= 10 && (gifHeader === "GIF87a" || gifHeader === "GIF89a")) {
1161
+ const width = buffer.readUInt16LE(6), height = buffer.readUInt16LE(8);
1162
+ let frames = 0;
1163
+ let pos = 13;
1164
+ let bufTen = buffer?.[10];
1165
+ if (typeof bufTen === "undefined") {
1166
+ pos = 13;
1167
+ frames = 0;
1168
+ } else if (bufTen & 128) pos += 3 << (bufTen & 7) + 1;
1169
+ while (pos < buffer.length) {
1170
+ if (buffer[pos] === 33) {
1171
+ pos += 2;
1172
+ let subSize = buffer?.[pos];
1173
+ while (subSize && subSize > 0) {
1174
+ pos += subSize + 1;
1175
+ subSize = buffer?.[pos];
1176
+ }
1177
+ pos++;
1178
+ } else if (buffer?.[pos] && buffer?.[pos] === 44) {
1179
+ frames++;
1180
+ pos += 10;
1181
+ let b = buffer?.[pos - 1];
1182
+ if (typeof b !== "undefined" && b & 128)
1183
+ pos += 3 << (b & 7) + 1;
1184
+ pos++;
1185
+ let dataSize = buffer?.[pos];
1186
+ while (dataSize && dataSize > 0) {
1187
+ pos += dataSize + 1;
1188
+ dataSize = buffer[pos];
1189
+ }
1190
+ pos++;
1191
+ } else if (buffer[pos] === 59) {
1192
+ break;
1193
+ } else {
1194
+ pos++;
1195
+ }
1196
+ }
1013
1197
  return {
1014
- width: buffer.readUInt16LE(6),
1015
- height: buffer.readUInt16LE(8),
1016
- type: "gif"
1198
+ width,
1199
+ height,
1200
+ format: "gif",
1201
+ frames,
1202
+ animated: frames > 1,
1203
+ hasAlpha: null,
1204
+ // GIF transparency is per-pixel binary, not full alpha; set null or true if transparent color exists, but complex
1205
+ orientation: null,
1206
+ // No orientation in GIF
1207
+ aspectRatio: width / height,
1208
+ colorSpace: "indexed",
1209
+ iccProfile: null,
1210
+ // No ICC in GIF
1211
+ exifDateTimeOriginal: null
1212
+ // No EXIF in GIF
1017
1213
  };
1018
1214
  }
1019
- if (buffer.length >= 26 && buffer[0] === 66 && buffer[1] === 77) {
1215
+ if (buffer.length >= 26 && buffer?.[0] === 66 && buffer?.[1] === 77) {
1216
+ const width = buffer.readInt32LE(18);
1217
+ const height = Math.abs(buffer.readInt32LE(22));
1218
+ const bitDepth = buffer.readUInt16LE(28);
1219
+ let colorSpace = bitDepth <= 8 ? "indexed" : "rgb";
1020
1220
  return {
1021
- width: buffer.readInt32LE(18),
1022
- height: Math.abs(buffer.readInt32LE(22)),
1023
- type: "bmp"
1221
+ width,
1222
+ height,
1223
+ format: "bmp",
1224
+ frames: 1,
1225
+ animated: false,
1226
+ hasAlpha: null,
1227
+ // Some BMP have alpha in 32bpp, check if bitDepth===32 && compression===3 (bitfields with alpha)
1228
+ orientation: buffer.readInt32LE(22) < 0 ? 1 : 6,
1229
+ // Negative height means top-down (orientation 1), positive bottom-up (like 6, but simplified)
1230
+ aspectRatio: width / height,
1231
+ colorSpace,
1232
+ iccProfile: null,
1233
+ // Rare in BMP
1234
+ exifDateTimeOriginal: null
1024
1235
  };
1025
1236
  }
1026
1237
  if (buffer.length >= 30 && buffer.toString("ascii", 0, 4) === "RIFF" && buffer.toString("ascii", 8, 12) === "WEBP") {
1027
1238
  const chunkType = buffer.toString("ascii", 12, 16);
1239
+ let colorSpace = "unknown";
1240
+ let hasAlpha = false;
1241
+ let width = 0;
1242
+ let height = 0;
1243
+ let frames = 1;
1244
+ let animated = false;
1245
+ let iccProfile = null;
1028
1246
  if (chunkType === "VP8X") {
1247
+ const flags = buffer?.[20];
1248
+ colorSpace = flags ? flags & 2 ? "rgba" : "rgb" : "unknown";
1249
+ hasAlpha = flags ? !!(flags & 2) : false;
1250
+ animated = flags ? !!(flags & 1) : false;
1029
1251
  let widthSubtractOne = 0;
1030
1252
  let heightSubtractOne = 0;
1031
1253
  if (buffer?.[24] && buffer?.[25] && buffer?.[26]) {
@@ -1034,48 +1256,70 @@ var Fs = class extends MimeService {
1034
1256
  if (buffer?.[27] && buffer?.[28] && buffer?.[29]) {
1035
1257
  heightSubtractOne = buffer[27] | buffer[28] << 8 | buffer[29] << 16;
1036
1258
  }
1037
- return {
1038
- width: widthSubtractOne + 1,
1039
- height: heightSubtractOne + 1,
1040
- type: "webp"
1041
- };
1259
+ width = widthSubtractOne + 1;
1260
+ height = heightSubtractOne + 1;
1261
+ if (animated) {
1262
+ let pos = 30;
1263
+ frames = 0;
1264
+ while (pos < buffer.length - 8) {
1265
+ const subChunkType = buffer.toString("ascii", pos, pos + 4);
1266
+ const subChunkSize = buffer.readUInt32LE(pos + 4);
1267
+ if (subChunkType === "ICCP") {
1268
+ iccProfile = "embedded";
1269
+ } else if (subChunkType === "ANMF") {
1270
+ frames++;
1271
+ }
1272
+ pos += 8 + subChunkSize + subChunkSize % 2;
1273
+ }
1274
+ }
1042
1275
  } else if (chunkType === "VP8 ") {
1276
+ colorSpace = "rgb";
1277
+ hasAlpha = false;
1043
1278
  const dataStart = 20;
1044
- if (buffer[dataStart + 3] !== 157 || buffer[dataStart + 4] !== 1 || buffer[dataStart + 5] !== 42) {
1279
+ if (buffer?.[dataStart + 3] !== 157 || buffer?.[dataStart + 4] !== 1 || buffer?.[dataStart + 5] !== 42) {
1045
1280
  throw new Error("Invalid VP8 keyframe");
1046
1281
  }
1047
- const width = buffer.readUInt16LE(dataStart + 6) & 16383;
1048
- const height = buffer.readUInt16LE(dataStart + 8) & 16383;
1049
- return {
1050
- width,
1051
- height,
1052
- type: "webp"
1053
- };
1282
+ width = buffer.readUInt16LE(dataStart + 6) & 16383;
1283
+ height = buffer.readUInt16LE(dataStart + 8) & 16383;
1054
1284
  } else if (chunkType === "VP8L") {
1055
1285
  const dataStart = 20;
1056
- if (buffer[dataStart] !== 47) {
1286
+ if (buffer?.[dataStart] !== 47) {
1057
1287
  throw new Error("Invalid VP8L signature");
1058
1288
  }
1059
1289
  const bits = buffer.readUInt32LE(dataStart + 1);
1060
1290
  if (bits >>> 29 !== 0) {
1061
1291
  throw new Error("Invalid VP8L version");
1062
1292
  }
1063
- const width = 1 + (bits & 16383);
1064
- const height = 1 + (bits >> 14 & 16383);
1065
- return {
1066
- width,
1067
- height,
1068
- type: "webp"
1069
- };
1293
+ colorSpace = bits & 1 << 8 ? "rgba" : "rgb";
1294
+ hasAlpha = !!(bits & 1 << 8);
1295
+ width = 1 + (bits & 16383);
1296
+ height = 1 + (bits >> 14 & 16383);
1297
+ } else {
1298
+ throw new Error("Unsupported WebP chunk");
1070
1299
  }
1071
- throw new Error("Unsupported WebP chunk");
1300
+ return {
1301
+ width,
1302
+ height,
1303
+ format: "webp",
1304
+ frames,
1305
+ animated,
1306
+ hasAlpha,
1307
+ orientation: null,
1308
+ // No standard orientation in WebP
1309
+ aspectRatio: width / height,
1310
+ colorSpace,
1311
+ iccProfile,
1312
+ exifDateTimeOriginal: null
1313
+ // Can have EXIF chunk, but rare; add if needed
1314
+ };
1072
1315
  }
1073
1316
  if (buffer.length >= 32 && buffer.toString("ascii", 4, 8) === "ftyp") {
1074
1317
  const ftyp = this.findBox(buffer, "ftyp");
1075
1318
  if (!ftyp) throw new Error("Invalid AVIF: No ftyp");
1076
1319
  const brands = buffer.toString("ascii", ftyp.pos, ftyp.pos + ftyp.size);
1077
- if (!brands.includes("avif") && !brands.includes("avis"))
1078
- throw new Error("Not an AVIF file");
1320
+ const isAvif = brands.includes("avif");
1321
+ const isAvis = brands.includes("avis");
1322
+ if (!isAvif && !isAvis) throw new Error("Not an AVIF file");
1079
1323
  const meta = this.findBox(buffer, "meta");
1080
1324
  if (!meta) throw new Error("Invalid AVIF: No meta");
1081
1325
  const metaSubStart = meta.pos + 4;
@@ -1089,10 +1333,54 @@ var Fs = class extends MimeService {
1089
1333
  if (buffer[ispe.pos] !== 0) throw new Error("Invalid ispe version");
1090
1334
  const width = buffer.readUInt32BE(ispe.pos + 4);
1091
1335
  const height = buffer.readUInt32BE(ispe.pos + 8);
1336
+ let colorSpace = "rgb";
1337
+ let hasAlpha = false;
1338
+ let iccProfile = null;
1339
+ const colr = this.findBox(buffer, "colr", ipco.pos, ipco.pos + ipco.size);
1340
+ if (colr) {
1341
+ const colrType = buffer.toString("ascii", colr.pos, colr.pos + 4);
1342
+ if (colrType === "nclx") {
1343
+ const matrix = buffer.readUInt16BE(colr.pos + 6);
1344
+ colorSpace = matrix === 2 ? "rgb" : "ycbcr";
1345
+ } else if (colrType === "rICC" || colrType === "prof") {
1346
+ colorSpace = "unknown";
1347
+ iccProfile = "embedded";
1348
+ }
1349
+ }
1350
+ const auxC = this.findBox(buffer, "auxC", ipco.pos, ipco.pos + ipco.size);
1351
+ if (auxC && buffer.toString("ascii", auxC.pos, auxC.pos + auxC.size).includes("alpha")) {
1352
+ hasAlpha = true;
1353
+ if (colorSpace === "rgb" || colorSpace === "ycbcr") {
1354
+ colorSpace = colorSpace === "rgb" ? "rgba" : "ycck";
1355
+ } else if (colorSpace === "unknown") {
1356
+ colorSpace = "grayscale-alpha";
1357
+ }
1358
+ }
1359
+ let frames = 1;
1360
+ let animated = isAvis;
1361
+ if (animated) {
1362
+ const iloc = this.findBox(buffer, "iloc", metaSubStart, metaSubEnd);
1363
+ if (iloc) {
1364
+ const version = buffer?.[iloc.pos];
1365
+ const itemCountPos = iloc.pos + (version ? version < 2 ? 4 : 6 : 4);
1366
+ frames = buffer.readUInt16BE(itemCountPos);
1367
+ }
1368
+ }
1092
1369
  return {
1093
1370
  width,
1094
1371
  height,
1095
- type: "avif"
1372
+ format: "avif",
1373
+ frames,
1374
+ animated,
1375
+ hasAlpha: hasAlpha ? true : null,
1376
+ // null if unknown
1377
+ orientation: null,
1378
+ // Can have 'irot' or 'imir' transforms, but rare
1379
+ aspectRatio: width / height,
1380
+ colorSpace,
1381
+ iccProfile,
1382
+ exifDateTimeOriginal: null
1383
+ // Can have 'XMP' box, but parse XMP for date if needed
1096
1384
  };
1097
1385
  }
1098
1386
  throw new Error("Unsupported image format or invalid file");
package/dist/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  Fs
3
- } from "./chunk-Y3TLKN7F.js";
3
+ } from "./chunk-CTA73JRX.js";
4
4
  import {
5
5
  MimeService,
6
6
  extMimeMap,
7
7
  mimeToExt
8
- } from "./chunk-O4BKLMFV.js";
8
+ } from "./chunk-CN45SMBB.js";
9
9
  import {
10
10
  unitsObj
11
- } from "./chunk-MXEE2WS7.js";
11
+ } from "./chunk-G27YIWW7.js";
12
12
  import {
13
13
  UrlService
14
14
  } from "./chunk-QBG7TFHM.js";