@autorender/sdk-core 0.1.30 → 0.1.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,8 +1,14 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __commonJS = (cb, mod) => function __require() {
10
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
+ };
6
12
  var __export = (target, all) => {
7
13
  for (var name in all)
8
14
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -15,7 +21,868 @@ var __copyProps = (to, from, except, desc) => {
15
21
  }
16
22
  return to;
17
23
  };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
+ // If the importer is in node compatibility mode or this is not an ESM
26
+ // file that has been converted to a CommonJS file using a Babel-
27
+ // compatible transform (i.e. "__esModule" has not been set), then set
28
+ // "default" to the CommonJS "module.exports" for node compatibility.
29
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
+ mod
31
+ ));
18
32
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
34
+
35
+ // ../../node_modules/ieee754/index.js
36
+ var require_ieee754 = __commonJS({
37
+ "../../node_modules/ieee754/index.js"(exports2) {
38
+ "use strict";
39
+ exports2.read = function(buffer, offset, isLE, mLen, nBytes) {
40
+ var e, m;
41
+ var eLen = nBytes * 8 - mLen - 1;
42
+ var eMax = (1 << eLen) - 1;
43
+ var eBias = eMax >> 1;
44
+ var nBits = -7;
45
+ var i = isLE ? nBytes - 1 : 0;
46
+ var d = isLE ? -1 : 1;
47
+ var s = buffer[offset + i];
48
+ i += d;
49
+ e = s & (1 << -nBits) - 1;
50
+ s >>= -nBits;
51
+ nBits += eLen;
52
+ for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {
53
+ }
54
+ m = e & (1 << -nBits) - 1;
55
+ e >>= -nBits;
56
+ nBits += mLen;
57
+ for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {
58
+ }
59
+ if (e === 0) {
60
+ e = 1 - eBias;
61
+ } else if (e === eMax) {
62
+ return m ? NaN : (s ? -1 : 1) * Infinity;
63
+ } else {
64
+ m = m + Math.pow(2, mLen);
65
+ e = e - eBias;
66
+ }
67
+ return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
68
+ };
69
+ exports2.write = function(buffer, value, offset, isLE, mLen, nBytes) {
70
+ var e, m, c;
71
+ var eLen = nBytes * 8 - mLen - 1;
72
+ var eMax = (1 << eLen) - 1;
73
+ var eBias = eMax >> 1;
74
+ var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
75
+ var i = isLE ? 0 : nBytes - 1;
76
+ var d = isLE ? 1 : -1;
77
+ var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
78
+ value = Math.abs(value);
79
+ if (isNaN(value) || value === Infinity) {
80
+ m = isNaN(value) ? 1 : 0;
81
+ e = eMax;
82
+ } else {
83
+ e = Math.floor(Math.log(value) / Math.LN2);
84
+ if (value * (c = Math.pow(2, -e)) < 1) {
85
+ e--;
86
+ c *= 2;
87
+ }
88
+ if (e + eBias >= 1) {
89
+ value += rt / c;
90
+ } else {
91
+ value += rt * Math.pow(2, 1 - eBias);
92
+ }
93
+ if (value * c >= 2) {
94
+ e++;
95
+ c /= 2;
96
+ }
97
+ if (e + eBias >= eMax) {
98
+ m = 0;
99
+ e = eMax;
100
+ } else if (e + eBias >= 1) {
101
+ m = (value * c - 1) * Math.pow(2, mLen);
102
+ e = e + eBias;
103
+ } else {
104
+ m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
105
+ e = 0;
106
+ }
107
+ }
108
+ for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) {
109
+ }
110
+ e = e << mLen | m;
111
+ eLen += mLen;
112
+ for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {
113
+ }
114
+ buffer[offset + i - d] |= s * 128;
115
+ };
116
+ }
117
+ });
118
+
119
+ // ../../node_modules/ms/index.js
120
+ var require_ms = __commonJS({
121
+ "../../node_modules/ms/index.js"(exports2, module2) {
122
+ "use strict";
123
+ var s = 1e3;
124
+ var m = s * 60;
125
+ var h = m * 60;
126
+ var d = h * 24;
127
+ var w = d * 7;
128
+ var y = d * 365.25;
129
+ module2.exports = function(val, options) {
130
+ options = options || {};
131
+ var type = typeof val;
132
+ if (type === "string" && val.length > 0) {
133
+ return parse(val);
134
+ } else if (type === "number" && isFinite(val)) {
135
+ return options.long ? fmtLong(val) : fmtShort(val);
136
+ }
137
+ throw new Error(
138
+ "val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
139
+ );
140
+ };
141
+ function parse(str) {
142
+ str = String(str);
143
+ if (str.length > 100) {
144
+ return;
145
+ }
146
+ var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
147
+ str
148
+ );
149
+ if (!match) {
150
+ return;
151
+ }
152
+ var n = parseFloat(match[1]);
153
+ var type = (match[2] || "ms").toLowerCase();
154
+ switch (type) {
155
+ case "years":
156
+ case "year":
157
+ case "yrs":
158
+ case "yr":
159
+ case "y":
160
+ return n * y;
161
+ case "weeks":
162
+ case "week":
163
+ case "w":
164
+ return n * w;
165
+ case "days":
166
+ case "day":
167
+ case "d":
168
+ return n * d;
169
+ case "hours":
170
+ case "hour":
171
+ case "hrs":
172
+ case "hr":
173
+ case "h":
174
+ return n * h;
175
+ case "minutes":
176
+ case "minute":
177
+ case "mins":
178
+ case "min":
179
+ case "m":
180
+ return n * m;
181
+ case "seconds":
182
+ case "second":
183
+ case "secs":
184
+ case "sec":
185
+ case "s":
186
+ return n * s;
187
+ case "milliseconds":
188
+ case "millisecond":
189
+ case "msecs":
190
+ case "msec":
191
+ case "ms":
192
+ return n;
193
+ default:
194
+ return void 0;
195
+ }
196
+ }
197
+ function fmtShort(ms) {
198
+ var msAbs = Math.abs(ms);
199
+ if (msAbs >= d) {
200
+ return Math.round(ms / d) + "d";
201
+ }
202
+ if (msAbs >= h) {
203
+ return Math.round(ms / h) + "h";
204
+ }
205
+ if (msAbs >= m) {
206
+ return Math.round(ms / m) + "m";
207
+ }
208
+ if (msAbs >= s) {
209
+ return Math.round(ms / s) + "s";
210
+ }
211
+ return ms + "ms";
212
+ }
213
+ function fmtLong(ms) {
214
+ var msAbs = Math.abs(ms);
215
+ if (msAbs >= d) {
216
+ return plural(ms, msAbs, d, "day");
217
+ }
218
+ if (msAbs >= h) {
219
+ return plural(ms, msAbs, h, "hour");
220
+ }
221
+ if (msAbs >= m) {
222
+ return plural(ms, msAbs, m, "minute");
223
+ }
224
+ if (msAbs >= s) {
225
+ return plural(ms, msAbs, s, "second");
226
+ }
227
+ return ms + " ms";
228
+ }
229
+ function plural(ms, msAbs, n, name) {
230
+ var isPlural = msAbs >= n * 1.5;
231
+ return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
232
+ }
233
+ }
234
+ });
235
+
236
+ // ../../node_modules/debug/src/common.js
237
+ var require_common = __commonJS({
238
+ "../../node_modules/debug/src/common.js"(exports2, module2) {
239
+ "use strict";
240
+ function setup(env) {
241
+ createDebug.debug = createDebug;
242
+ createDebug.default = createDebug;
243
+ createDebug.coerce = coerce;
244
+ createDebug.disable = disable;
245
+ createDebug.enable = enable;
246
+ createDebug.enabled = enabled;
247
+ createDebug.humanize = require_ms();
248
+ createDebug.destroy = destroy;
249
+ Object.keys(env).forEach((key) => {
250
+ createDebug[key] = env[key];
251
+ });
252
+ createDebug.names = [];
253
+ createDebug.skips = [];
254
+ createDebug.formatters = {};
255
+ function selectColor(namespace) {
256
+ let hash = 0;
257
+ for (let i = 0; i < namespace.length; i++) {
258
+ hash = (hash << 5) - hash + namespace.charCodeAt(i);
259
+ hash |= 0;
260
+ }
261
+ return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
262
+ }
263
+ createDebug.selectColor = selectColor;
264
+ function createDebug(namespace) {
265
+ let prevTime;
266
+ let enableOverride = null;
267
+ let namespacesCache;
268
+ let enabledCache;
269
+ function debug2(...args) {
270
+ if (!debug2.enabled) {
271
+ return;
272
+ }
273
+ const self = debug2;
274
+ const curr = Number(/* @__PURE__ */ new Date());
275
+ const ms = curr - (prevTime || curr);
276
+ self.diff = ms;
277
+ self.prev = prevTime;
278
+ self.curr = curr;
279
+ prevTime = curr;
280
+ args[0] = createDebug.coerce(args[0]);
281
+ if (typeof args[0] !== "string") {
282
+ args.unshift("%O");
283
+ }
284
+ let index = 0;
285
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
286
+ if (match === "%%") {
287
+ return "%";
288
+ }
289
+ index++;
290
+ const formatter = createDebug.formatters[format];
291
+ if (typeof formatter === "function") {
292
+ const val = args[index];
293
+ match = formatter.call(self, val);
294
+ args.splice(index, 1);
295
+ index--;
296
+ }
297
+ return match;
298
+ });
299
+ createDebug.formatArgs.call(self, args);
300
+ const logFn = self.log || createDebug.log;
301
+ logFn.apply(self, args);
302
+ }
303
+ debug2.namespace = namespace;
304
+ debug2.useColors = createDebug.useColors();
305
+ debug2.color = createDebug.selectColor(namespace);
306
+ debug2.extend = extend;
307
+ debug2.destroy = createDebug.destroy;
308
+ Object.defineProperty(debug2, "enabled", {
309
+ enumerable: true,
310
+ configurable: false,
311
+ get: () => {
312
+ if (enableOverride !== null) {
313
+ return enableOverride;
314
+ }
315
+ if (namespacesCache !== createDebug.namespaces) {
316
+ namespacesCache = createDebug.namespaces;
317
+ enabledCache = createDebug.enabled(namespace);
318
+ }
319
+ return enabledCache;
320
+ },
321
+ set: (v) => {
322
+ enableOverride = v;
323
+ }
324
+ });
325
+ if (typeof createDebug.init === "function") {
326
+ createDebug.init(debug2);
327
+ }
328
+ return debug2;
329
+ }
330
+ function extend(namespace, delimiter) {
331
+ const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
332
+ newDebug.log = this.log;
333
+ return newDebug;
334
+ }
335
+ function enable(namespaces) {
336
+ createDebug.save(namespaces);
337
+ createDebug.namespaces = namespaces;
338
+ createDebug.names = [];
339
+ createDebug.skips = [];
340
+ const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
341
+ for (const ns of split) {
342
+ if (ns[0] === "-") {
343
+ createDebug.skips.push(ns.slice(1));
344
+ } else {
345
+ createDebug.names.push(ns);
346
+ }
347
+ }
348
+ }
349
+ function matchesTemplate(search, template) {
350
+ let searchIndex = 0;
351
+ let templateIndex = 0;
352
+ let starIndex = -1;
353
+ let matchIndex = 0;
354
+ while (searchIndex < search.length) {
355
+ if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) {
356
+ if (template[templateIndex] === "*") {
357
+ starIndex = templateIndex;
358
+ matchIndex = searchIndex;
359
+ templateIndex++;
360
+ } else {
361
+ searchIndex++;
362
+ templateIndex++;
363
+ }
364
+ } else if (starIndex !== -1) {
365
+ templateIndex = starIndex + 1;
366
+ matchIndex++;
367
+ searchIndex = matchIndex;
368
+ } else {
369
+ return false;
370
+ }
371
+ }
372
+ while (templateIndex < template.length && template[templateIndex] === "*") {
373
+ templateIndex++;
374
+ }
375
+ return templateIndex === template.length;
376
+ }
377
+ function disable() {
378
+ const namespaces = [
379
+ ...createDebug.names,
380
+ ...createDebug.skips.map((namespace) => "-" + namespace)
381
+ ].join(",");
382
+ createDebug.enable("");
383
+ return namespaces;
384
+ }
385
+ function enabled(name) {
386
+ for (const skip of createDebug.skips) {
387
+ if (matchesTemplate(name, skip)) {
388
+ return false;
389
+ }
390
+ }
391
+ for (const ns of createDebug.names) {
392
+ if (matchesTemplate(name, ns)) {
393
+ return true;
394
+ }
395
+ }
396
+ return false;
397
+ }
398
+ function coerce(val) {
399
+ if (val instanceof Error) {
400
+ return val.stack || val.message;
401
+ }
402
+ return val;
403
+ }
404
+ function destroy() {
405
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
406
+ }
407
+ createDebug.enable(createDebug.load());
408
+ return createDebug;
409
+ }
410
+ module2.exports = setup;
411
+ }
412
+ });
413
+
414
+ // ../../node_modules/debug/src/browser.js
415
+ var require_browser = __commonJS({
416
+ "../../node_modules/debug/src/browser.js"(exports2, module2) {
417
+ "use strict";
418
+ exports2.formatArgs = formatArgs;
419
+ exports2.save = save;
420
+ exports2.load = load;
421
+ exports2.useColors = useColors;
422
+ exports2.storage = localstorage();
423
+ exports2.destroy = /* @__PURE__ */ (() => {
424
+ let warned = false;
425
+ return () => {
426
+ if (!warned) {
427
+ warned = true;
428
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
429
+ }
430
+ };
431
+ })();
432
+ exports2.colors = [
433
+ "#0000CC",
434
+ "#0000FF",
435
+ "#0033CC",
436
+ "#0033FF",
437
+ "#0066CC",
438
+ "#0066FF",
439
+ "#0099CC",
440
+ "#0099FF",
441
+ "#00CC00",
442
+ "#00CC33",
443
+ "#00CC66",
444
+ "#00CC99",
445
+ "#00CCCC",
446
+ "#00CCFF",
447
+ "#3300CC",
448
+ "#3300FF",
449
+ "#3333CC",
450
+ "#3333FF",
451
+ "#3366CC",
452
+ "#3366FF",
453
+ "#3399CC",
454
+ "#3399FF",
455
+ "#33CC00",
456
+ "#33CC33",
457
+ "#33CC66",
458
+ "#33CC99",
459
+ "#33CCCC",
460
+ "#33CCFF",
461
+ "#6600CC",
462
+ "#6600FF",
463
+ "#6633CC",
464
+ "#6633FF",
465
+ "#66CC00",
466
+ "#66CC33",
467
+ "#9900CC",
468
+ "#9900FF",
469
+ "#9933CC",
470
+ "#9933FF",
471
+ "#99CC00",
472
+ "#99CC33",
473
+ "#CC0000",
474
+ "#CC0033",
475
+ "#CC0066",
476
+ "#CC0099",
477
+ "#CC00CC",
478
+ "#CC00FF",
479
+ "#CC3300",
480
+ "#CC3333",
481
+ "#CC3366",
482
+ "#CC3399",
483
+ "#CC33CC",
484
+ "#CC33FF",
485
+ "#CC6600",
486
+ "#CC6633",
487
+ "#CC9900",
488
+ "#CC9933",
489
+ "#CCCC00",
490
+ "#CCCC33",
491
+ "#FF0000",
492
+ "#FF0033",
493
+ "#FF0066",
494
+ "#FF0099",
495
+ "#FF00CC",
496
+ "#FF00FF",
497
+ "#FF3300",
498
+ "#FF3333",
499
+ "#FF3366",
500
+ "#FF3399",
501
+ "#FF33CC",
502
+ "#FF33FF",
503
+ "#FF6600",
504
+ "#FF6633",
505
+ "#FF9900",
506
+ "#FF9933",
507
+ "#FFCC00",
508
+ "#FFCC33"
509
+ ];
510
+ function useColors() {
511
+ if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) {
512
+ return true;
513
+ }
514
+ if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
515
+ return false;
516
+ }
517
+ let m;
518
+ return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
519
+ typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
520
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
521
+ typeof navigator !== "undefined" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
522
+ typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
523
+ }
524
+ function formatArgs(args) {
525
+ args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module2.exports.humanize(this.diff);
526
+ if (!this.useColors) {
527
+ return;
528
+ }
529
+ const c = "color: " + this.color;
530
+ args.splice(1, 0, c, "color: inherit");
531
+ let index = 0;
532
+ let lastC = 0;
533
+ args[0].replace(/%[a-zA-Z%]/g, (match) => {
534
+ if (match === "%%") {
535
+ return;
536
+ }
537
+ index++;
538
+ if (match === "%c") {
539
+ lastC = index;
540
+ }
541
+ });
542
+ args.splice(lastC, 0, c);
543
+ }
544
+ exports2.log = console.debug || console.log || (() => {
545
+ });
546
+ function save(namespaces) {
547
+ try {
548
+ if (namespaces) {
549
+ exports2.storage.setItem("debug", namespaces);
550
+ } else {
551
+ exports2.storage.removeItem("debug");
552
+ }
553
+ } catch (error) {
554
+ }
555
+ }
556
+ function load() {
557
+ let r;
558
+ try {
559
+ r = exports2.storage.getItem("debug") || exports2.storage.getItem("DEBUG");
560
+ } catch (error) {
561
+ }
562
+ if (!r && typeof process !== "undefined" && "env" in process) {
563
+ r = process.env.DEBUG;
564
+ }
565
+ return r;
566
+ }
567
+ function localstorage() {
568
+ try {
569
+ return localStorage;
570
+ } catch (error) {
571
+ }
572
+ }
573
+ module2.exports = require_common()(exports2);
574
+ var { formatters } = module2.exports;
575
+ formatters.j = function(v) {
576
+ try {
577
+ return JSON.stringify(v);
578
+ } catch (error) {
579
+ return "[UnexpectedJSONParseError]: " + error.message;
580
+ }
581
+ };
582
+ }
583
+ });
584
+
585
+ // ../../node_modules/has-flag/index.js
586
+ var require_has_flag = __commonJS({
587
+ "../../node_modules/has-flag/index.js"(exports2, module2) {
588
+ "use strict";
589
+ module2.exports = (flag, argv = process.argv) => {
590
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
591
+ const position = argv.indexOf(prefix + flag);
592
+ const terminatorPosition = argv.indexOf("--");
593
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
594
+ };
595
+ }
596
+ });
597
+
598
+ // ../../node_modules/supports-color/index.js
599
+ var require_supports_color = __commonJS({
600
+ "../../node_modules/supports-color/index.js"(exports2, module2) {
601
+ "use strict";
602
+ var os = require("os");
603
+ var tty = require("tty");
604
+ var hasFlag = require_has_flag();
605
+ var { env } = process;
606
+ var forceColor;
607
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
608
+ forceColor = 0;
609
+ } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
610
+ forceColor = 1;
611
+ }
612
+ if ("FORCE_COLOR" in env) {
613
+ if (env.FORCE_COLOR === "true") {
614
+ forceColor = 1;
615
+ } else if (env.FORCE_COLOR === "false") {
616
+ forceColor = 0;
617
+ } else {
618
+ forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
619
+ }
620
+ }
621
+ function translateLevel(level) {
622
+ if (level === 0) {
623
+ return false;
624
+ }
625
+ return {
626
+ level,
627
+ hasBasic: true,
628
+ has256: level >= 2,
629
+ has16m: level >= 3
630
+ };
631
+ }
632
+ function supportsColor(haveStream, streamIsTTY) {
633
+ if (forceColor === 0) {
634
+ return 0;
635
+ }
636
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
637
+ return 3;
638
+ }
639
+ if (hasFlag("color=256")) {
640
+ return 2;
641
+ }
642
+ if (haveStream && !streamIsTTY && forceColor === void 0) {
643
+ return 0;
644
+ }
645
+ const min = forceColor || 0;
646
+ if (env.TERM === "dumb") {
647
+ return min;
648
+ }
649
+ if (process.platform === "win32") {
650
+ const osRelease = os.release().split(".");
651
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
652
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
653
+ }
654
+ return 1;
655
+ }
656
+ if ("CI" in env) {
657
+ if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
658
+ return 1;
659
+ }
660
+ return min;
661
+ }
662
+ if ("TEAMCITY_VERSION" in env) {
663
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
664
+ }
665
+ if (env.COLORTERM === "truecolor") {
666
+ return 3;
667
+ }
668
+ if ("TERM_PROGRAM" in env) {
669
+ const version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
670
+ switch (env.TERM_PROGRAM) {
671
+ case "iTerm.app":
672
+ return version >= 3 ? 3 : 2;
673
+ case "Apple_Terminal":
674
+ return 2;
675
+ }
676
+ }
677
+ if (/-256(color)?$/i.test(env.TERM)) {
678
+ return 2;
679
+ }
680
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
681
+ return 1;
682
+ }
683
+ if ("COLORTERM" in env) {
684
+ return 1;
685
+ }
686
+ return min;
687
+ }
688
+ function getSupportLevel(stream) {
689
+ const level = supportsColor(stream, stream && stream.isTTY);
690
+ return translateLevel(level);
691
+ }
692
+ module2.exports = {
693
+ supportsColor: getSupportLevel,
694
+ stdout: translateLevel(supportsColor(true, tty.isatty(1))),
695
+ stderr: translateLevel(supportsColor(true, tty.isatty(2)))
696
+ };
697
+ }
698
+ });
699
+
700
+ // ../../node_modules/debug/src/node.js
701
+ var require_node = __commonJS({
702
+ "../../node_modules/debug/src/node.js"(exports2, module2) {
703
+ "use strict";
704
+ var tty = require("tty");
705
+ var util = require("util");
706
+ exports2.init = init;
707
+ exports2.log = log;
708
+ exports2.formatArgs = formatArgs;
709
+ exports2.save = save;
710
+ exports2.load = load;
711
+ exports2.useColors = useColors;
712
+ exports2.destroy = util.deprecate(
713
+ () => {
714
+ },
715
+ "Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."
716
+ );
717
+ exports2.colors = [6, 2, 3, 4, 5, 1];
718
+ try {
719
+ const supportsColor = require_supports_color();
720
+ if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
721
+ exports2.colors = [
722
+ 20,
723
+ 21,
724
+ 26,
725
+ 27,
726
+ 32,
727
+ 33,
728
+ 38,
729
+ 39,
730
+ 40,
731
+ 41,
732
+ 42,
733
+ 43,
734
+ 44,
735
+ 45,
736
+ 56,
737
+ 57,
738
+ 62,
739
+ 63,
740
+ 68,
741
+ 69,
742
+ 74,
743
+ 75,
744
+ 76,
745
+ 77,
746
+ 78,
747
+ 79,
748
+ 80,
749
+ 81,
750
+ 92,
751
+ 93,
752
+ 98,
753
+ 99,
754
+ 112,
755
+ 113,
756
+ 128,
757
+ 129,
758
+ 134,
759
+ 135,
760
+ 148,
761
+ 149,
762
+ 160,
763
+ 161,
764
+ 162,
765
+ 163,
766
+ 164,
767
+ 165,
768
+ 166,
769
+ 167,
770
+ 168,
771
+ 169,
772
+ 170,
773
+ 171,
774
+ 172,
775
+ 173,
776
+ 178,
777
+ 179,
778
+ 184,
779
+ 185,
780
+ 196,
781
+ 197,
782
+ 198,
783
+ 199,
784
+ 200,
785
+ 201,
786
+ 202,
787
+ 203,
788
+ 204,
789
+ 205,
790
+ 206,
791
+ 207,
792
+ 208,
793
+ 209,
794
+ 214,
795
+ 215,
796
+ 220,
797
+ 221
798
+ ];
799
+ }
800
+ } catch (error) {
801
+ }
802
+ exports2.inspectOpts = Object.keys(process.env).filter((key) => {
803
+ return /^debug_/i.test(key);
804
+ }).reduce((obj, key) => {
805
+ const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => {
806
+ return k.toUpperCase();
807
+ });
808
+ let val = process.env[key];
809
+ if (/^(yes|on|true|enabled)$/i.test(val)) {
810
+ val = true;
811
+ } else if (/^(no|off|false|disabled)$/i.test(val)) {
812
+ val = false;
813
+ } else if (val === "null") {
814
+ val = null;
815
+ } else {
816
+ val = Number(val);
817
+ }
818
+ obj[prop] = val;
819
+ return obj;
820
+ }, {});
821
+ function useColors() {
822
+ return "colors" in exports2.inspectOpts ? Boolean(exports2.inspectOpts.colors) : tty.isatty(process.stderr.fd);
823
+ }
824
+ function formatArgs(args) {
825
+ const { namespace: name, useColors: useColors2 } = this;
826
+ if (useColors2) {
827
+ const c = this.color;
828
+ const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
829
+ const prefix = ` ${colorCode};1m${name} \x1B[0m`;
830
+ args[0] = prefix + args[0].split("\n").join("\n" + prefix);
831
+ args.push(colorCode + "m+" + module2.exports.humanize(this.diff) + "\x1B[0m");
832
+ } else {
833
+ args[0] = getDate() + name + " " + args[0];
834
+ }
835
+ }
836
+ function getDate() {
837
+ if (exports2.inspectOpts.hideDate) {
838
+ return "";
839
+ }
840
+ return (/* @__PURE__ */ new Date()).toISOString() + " ";
841
+ }
842
+ function log(...args) {
843
+ return process.stderr.write(util.formatWithOptions(exports2.inspectOpts, ...args) + "\n");
844
+ }
845
+ function save(namespaces) {
846
+ if (namespaces) {
847
+ process.env.DEBUG = namespaces;
848
+ } else {
849
+ delete process.env.DEBUG;
850
+ }
851
+ }
852
+ function load() {
853
+ return process.env.DEBUG;
854
+ }
855
+ function init(debug2) {
856
+ debug2.inspectOpts = {};
857
+ const keys = Object.keys(exports2.inspectOpts);
858
+ for (let i = 0; i < keys.length; i++) {
859
+ debug2.inspectOpts[keys[i]] = exports2.inspectOpts[keys[i]];
860
+ }
861
+ }
862
+ module2.exports = require_common()(exports2);
863
+ var { formatters } = module2.exports;
864
+ formatters.o = function(v) {
865
+ this.inspectOpts.colors = this.useColors;
866
+ return util.inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
867
+ };
868
+ formatters.O = function(v) {
869
+ this.inspectOpts.colors = this.useColors;
870
+ return util.inspect(v, this.inspectOpts);
871
+ };
872
+ }
873
+ });
874
+
875
+ // ../../node_modules/debug/src/index.js
876
+ var require_src = __commonJS({
877
+ "../../node_modules/debug/src/index.js"(exports2, module2) {
878
+ "use strict";
879
+ if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
880
+ module2.exports = require_browser();
881
+ } else {
882
+ module2.exports = require_node();
883
+ }
884
+ }
885
+ });
19
886
 
20
887
  // src/index.ts
21
888
  var src_exports = {};
@@ -198,187 +1065,3136 @@ var AutorenderApiClient = class {
198
1065
  reject(new DOMException("Upload aborted", "AbortError"));
199
1066
  });
200
1067
  }
201
- let lastProgress = 0;
202
- xhr.upload.onprogress = (event) => {
203
- if (event.lengthComputable && onProgress) {
204
- const progress = Math.round(event.loaded / event.total * 100);
205
- lastProgress = progress;
206
- onProgress(progress);
207
- } else if (onProgress && event.loaded > 0) {
208
- const estimatedProgress = Math.min(
209
- 95,
210
- Math.round(event.loaded / (event.loaded + 1e6) * 100)
211
- );
212
- if (estimatedProgress > lastProgress) {
213
- lastProgress = estimatedProgress;
214
- onProgress(estimatedProgress);
1068
+ let lastProgress = 0;
1069
+ xhr.upload.onprogress = (event) => {
1070
+ if (event.lengthComputable && onProgress) {
1071
+ const progress = Math.round(event.loaded / event.total * 100);
1072
+ lastProgress = progress;
1073
+ onProgress(progress);
1074
+ } else if (onProgress && event.loaded > 0) {
1075
+ const estimatedProgress = Math.min(
1076
+ 95,
1077
+ Math.round(event.loaded / (event.loaded + 1e6) * 100)
1078
+ );
1079
+ if (estimatedProgress > lastProgress) {
1080
+ lastProgress = estimatedProgress;
1081
+ onProgress(estimatedProgress);
1082
+ }
1083
+ }
1084
+ };
1085
+ xhr.onerror = () => {
1086
+ reject(new Error(`Upload failed: ${xhr.statusText}`));
1087
+ };
1088
+ xhr.onload = () => {
1089
+ try {
1090
+ if (xhr.status < 200 || xhr.status >= 300) {
1091
+ const errorText = xhr.responseText || xhr.statusText;
1092
+ reject(new Error(`Upload failed: ${errorText}`));
1093
+ return;
1094
+ }
1095
+ const newResponse = JSON.parse(xhr.responseText);
1096
+ const response = {
1097
+ success: true,
1098
+ file_no: newResponse.file_no || newResponse.id,
1099
+ name: newResponse.name,
1100
+ url: newResponse.url,
1101
+ file_size: newResponse.size,
1102
+ format: newResponse.format,
1103
+ width: newResponse.width,
1104
+ height: newResponse.height,
1105
+ created_at: newResponse.created_at,
1106
+ path: newResponse.path,
1107
+ workspace_no: newResponse.workspace_id,
1108
+ isDuplicate: newResponse.is_duplicate || false
1109
+ };
1110
+ resolve(response);
1111
+ } catch (error) {
1112
+ reject(new Error("Failed to parse response"));
1113
+ }
1114
+ };
1115
+ const endpoint = `${this.baseUrl}/uploads`;
1116
+ const formData = new FormData();
1117
+ formData.append("file", params.file);
1118
+ formData.append("file_name", params.file.name);
1119
+ if (params.folderPath) {
1120
+ formData.append("folder", params.folderPath);
1121
+ }
1122
+ if (params.settings?.tags?.length) {
1123
+ formData.append("tags", params.settings.tags.join(","));
1124
+ }
1125
+ if (params.settings?.pretransformations) {
1126
+ formData.append("transform", params.settings.pretransformations);
1127
+ }
1128
+ if (params.settings?.custom_id) {
1129
+ formData.append("custom_id", params.settings.custom_id);
1130
+ }
1131
+ xhr.open("POST", endpoint);
1132
+ xhr.setRequestHeader("Authorization", `Bearer ${this.apiKey}`);
1133
+ xhr.setRequestHeader("accept", "application/json");
1134
+ xhr.send(formData);
1135
+ });
1136
+ }
1137
+ };
1138
+
1139
+ // src/utils/helpers.ts
1140
+ function generateId() {
1141
+ if (typeof crypto !== "undefined" && "randomUUID" in crypto) {
1142
+ return crypto.randomUUID();
1143
+ }
1144
+ return "id-" + Math.random().toString(36).slice(2, 11);
1145
+ }
1146
+ function resolveIcon(renderer) {
1147
+ if (typeof renderer === "function") {
1148
+ return resolveIcon(renderer());
1149
+ }
1150
+ if (typeof renderer === "string") {
1151
+ const template = document.createElement("template");
1152
+ template.innerHTML = renderer.trim();
1153
+ return template.content.firstElementChild;
1154
+ }
1155
+ return renderer ? renderer.cloneNode(true) : null;
1156
+ }
1157
+ function toCssVars(theme) {
1158
+ const variables = {};
1159
+ if (theme.accentColor) {
1160
+ variables["--ar-accent"] = theme.accentColor;
1161
+ }
1162
+ if (theme.borderRadius !== void 0) {
1163
+ variables["--ar-radius"] = `${theme.borderRadius}px`;
1164
+ }
1165
+ if (theme.fontFamily) {
1166
+ variables["--ar-font-family"] = theme.fontFamily;
1167
+ }
1168
+ if (theme.dropzoneBackground) {
1169
+ variables["--ar-dropzone-bg"] = theme.dropzoneBackground;
1170
+ }
1171
+ if (theme.dropzoneBorder) {
1172
+ variables["--ar-dropzone-border"] = theme.dropzoneBorder;
1173
+ }
1174
+ return variables;
1175
+ }
1176
+ function applyCssVariables(element, variables) {
1177
+ Object.entries(variables).forEach(([key, value]) => {
1178
+ element.style.setProperty(key, value);
1179
+ });
1180
+ }
1181
+ function getRelativeFolderPath(basePath, relativePath) {
1182
+ if (!relativePath) return void 0;
1183
+ const parts = relativePath.split("/").map((segment) => segment.trim()).filter((segment) => segment && segment !== ".");
1184
+ if (parts.length <= 1) {
1185
+ return void 0;
1186
+ }
1187
+ const folderSegments = parts.slice(0, -1);
1188
+ if (basePath) {
1189
+ const baseSegments = basePath.split("/").map((segment) => segment.trim()).filter((segment) => segment && segment !== ".");
1190
+ let offset = 0;
1191
+ while (offset < baseSegments.length && offset < folderSegments.length && folderSegments[offset] === baseSegments[offset]) {
1192
+ offset += 1;
1193
+ }
1194
+ return offset < folderSegments.length ? folderSegments.slice(offset).join("/") : void 0;
1195
+ }
1196
+ return folderSegments.length ? folderSegments.join("/") : void 0;
1197
+ }
1198
+ function calculateBatchProgress(items) {
1199
+ if (items.length === 0) return 0;
1200
+ const total = items.reduce((acc, item) => acc + item.progress, 0);
1201
+ return Math.round(total / items.length);
1202
+ }
1203
+ var S3_URL_PATTERN = /^s3:\/\/([^/]+)\/(.+)$/i;
1204
+ function sanitizeBaseUrl(baseUrl) {
1205
+ if (!baseUrl) return void 0;
1206
+ const trimmed = baseUrl.trim();
1207
+ if (!trimmed) return void 0;
1208
+ return trimmed.replace(/\/+$/, "");
1209
+ }
1210
+ function extractWorkspaceFromUrl(url) {
1211
+ if (!url) return void 0;
1212
+ const s3Match = S3_URL_PATTERN.exec(url);
1213
+ if (s3Match) {
1214
+ return s3Match[1];
1215
+ }
1216
+ try {
1217
+ const parsed = new URL(url);
1218
+ const firstSegment = parsed.pathname.replace(/^\/+/, "").split("/")[0];
1219
+ return firstSegment || void 0;
1220
+ } catch {
1221
+ return void 0;
1222
+ }
1223
+ }
1224
+ function extractPathFromUrl(url) {
1225
+ if (!url) return void 0;
1226
+ const s3Match = S3_URL_PATTERN.exec(url);
1227
+ if (s3Match) {
1228
+ return s3Match[2];
1229
+ }
1230
+ try {
1231
+ const parsed = new URL(url);
1232
+ const [, ...rest] = parsed.pathname.replace(/^\/+/, "").split("/");
1233
+ return rest.length ? rest.join("/") : void 0;
1234
+ } catch {
1235
+ return void 0;
1236
+ }
1237
+ }
1238
+ function buildAssetDeliveryUrl(baseUrl, workspace, path, fallback) {
1239
+ const sanitizedBase = sanitizeBaseUrl(baseUrl);
1240
+ if (!sanitizedBase || !workspace || !path) {
1241
+ return fallback;
1242
+ }
1243
+ const normalizedPath = path.split("/").filter(Boolean).map((segment) => encodeURIComponent(segment)).join("/");
1244
+ return `${sanitizedBase}/${workspace}/${normalizedPath}`.replace(/([^:]\/)\/+/g, "$1");
1245
+ }
1246
+
1247
+ // ../../node_modules/token-types/lib/index.js
1248
+ var ieee754 = __toESM(require_ieee754(), 1);
1249
+
1250
+ // ../../node_modules/@borewit/text-codec/lib/index.js
1251
+ var WINDOWS_1252_EXTRA = {
1252
+ 128: "\u20AC",
1253
+ 130: "\u201A",
1254
+ 131: "\u0192",
1255
+ 132: "\u201E",
1256
+ 133: "\u2026",
1257
+ 134: "\u2020",
1258
+ 135: "\u2021",
1259
+ 136: "\u02C6",
1260
+ 137: "\u2030",
1261
+ 138: "\u0160",
1262
+ 139: "\u2039",
1263
+ 140: "\u0152",
1264
+ 142: "\u017D",
1265
+ 145: "\u2018",
1266
+ 146: "\u2019",
1267
+ 147: "\u201C",
1268
+ 148: "\u201D",
1269
+ 149: "\u2022",
1270
+ 150: "\u2013",
1271
+ 151: "\u2014",
1272
+ 152: "\u02DC",
1273
+ 153: "\u2122",
1274
+ 154: "\u0161",
1275
+ 155: "\u203A",
1276
+ 156: "\u0153",
1277
+ 158: "\u017E",
1278
+ 159: "\u0178"
1279
+ };
1280
+ var WINDOWS_1252_REVERSE = {};
1281
+ for (const [code, char] of Object.entries(WINDOWS_1252_EXTRA)) {
1282
+ WINDOWS_1252_REVERSE[char] = Number.parseInt(code);
1283
+ }
1284
+ function textDecode(bytes, encoding = "utf-8") {
1285
+ switch (encoding.toLowerCase()) {
1286
+ case "utf-8":
1287
+ case "utf8":
1288
+ if (typeof globalThis.TextDecoder !== "undefined") {
1289
+ return new globalThis.TextDecoder("utf-8").decode(bytes);
1290
+ }
1291
+ return decodeUTF8(bytes);
1292
+ case "utf-16le":
1293
+ return decodeUTF16LE(bytes);
1294
+ case "ascii":
1295
+ return decodeASCII(bytes);
1296
+ case "latin1":
1297
+ case "iso-8859-1":
1298
+ return decodeLatin1(bytes);
1299
+ case "windows-1252":
1300
+ return decodeWindows1252(bytes);
1301
+ default:
1302
+ throw new RangeError(`Encoding '${encoding}' not supported`);
1303
+ }
1304
+ }
1305
+ function decodeUTF8(bytes) {
1306
+ let out = "";
1307
+ let i = 0;
1308
+ while (i < bytes.length) {
1309
+ const b1 = bytes[i++];
1310
+ if (b1 < 128) {
1311
+ out += String.fromCharCode(b1);
1312
+ } else if (b1 < 224) {
1313
+ const b2 = bytes[i++] & 63;
1314
+ out += String.fromCharCode((b1 & 31) << 6 | b2);
1315
+ } else if (b1 < 240) {
1316
+ const b2 = bytes[i++] & 63;
1317
+ const b3 = bytes[i++] & 63;
1318
+ out += String.fromCharCode((b1 & 15) << 12 | b2 << 6 | b3);
1319
+ } else {
1320
+ const b2 = bytes[i++] & 63;
1321
+ const b3 = bytes[i++] & 63;
1322
+ const b4 = bytes[i++] & 63;
1323
+ let cp = (b1 & 7) << 18 | b2 << 12 | b3 << 6 | b4;
1324
+ cp -= 65536;
1325
+ out += String.fromCharCode(55296 + (cp >> 10 & 1023), 56320 + (cp & 1023));
1326
+ }
1327
+ }
1328
+ return out;
1329
+ }
1330
+ function decodeUTF16LE(bytes) {
1331
+ let out = "";
1332
+ for (let i = 0; i < bytes.length; i += 2) {
1333
+ out += String.fromCharCode(bytes[i] | bytes[i + 1] << 8);
1334
+ }
1335
+ return out;
1336
+ }
1337
+ function decodeASCII(bytes) {
1338
+ return String.fromCharCode(...bytes.map((b) => b & 127));
1339
+ }
1340
+ function decodeLatin1(bytes) {
1341
+ return String.fromCharCode(...bytes);
1342
+ }
1343
+ function decodeWindows1252(bytes) {
1344
+ let out = "";
1345
+ for (const b of bytes) {
1346
+ if (b >= 128 && b <= 159 && WINDOWS_1252_EXTRA[b]) {
1347
+ out += WINDOWS_1252_EXTRA[b];
1348
+ } else {
1349
+ out += String.fromCharCode(b);
1350
+ }
1351
+ }
1352
+ return out;
1353
+ }
1354
+
1355
+ // ../../node_modules/token-types/lib/index.js
1356
+ function dv(array) {
1357
+ return new DataView(array.buffer, array.byteOffset);
1358
+ }
1359
+ var UINT8 = {
1360
+ len: 1,
1361
+ get(array, offset) {
1362
+ return dv(array).getUint8(offset);
1363
+ },
1364
+ put(array, offset, value) {
1365
+ dv(array).setUint8(offset, value);
1366
+ return offset + 1;
1367
+ }
1368
+ };
1369
+ var UINT16_LE = {
1370
+ len: 2,
1371
+ get(array, offset) {
1372
+ return dv(array).getUint16(offset, true);
1373
+ },
1374
+ put(array, offset, value) {
1375
+ dv(array).setUint16(offset, value, true);
1376
+ return offset + 2;
1377
+ }
1378
+ };
1379
+ var UINT16_BE = {
1380
+ len: 2,
1381
+ get(array, offset) {
1382
+ return dv(array).getUint16(offset);
1383
+ },
1384
+ put(array, offset, value) {
1385
+ dv(array).setUint16(offset, value);
1386
+ return offset + 2;
1387
+ }
1388
+ };
1389
+ var UINT32_LE = {
1390
+ len: 4,
1391
+ get(array, offset) {
1392
+ return dv(array).getUint32(offset, true);
1393
+ },
1394
+ put(array, offset, value) {
1395
+ dv(array).setUint32(offset, value, true);
1396
+ return offset + 4;
1397
+ }
1398
+ };
1399
+ var UINT32_BE = {
1400
+ len: 4,
1401
+ get(array, offset) {
1402
+ return dv(array).getUint32(offset);
1403
+ },
1404
+ put(array, offset, value) {
1405
+ dv(array).setUint32(offset, value);
1406
+ return offset + 4;
1407
+ }
1408
+ };
1409
+ var INT32_BE = {
1410
+ len: 4,
1411
+ get(array, offset) {
1412
+ return dv(array).getInt32(offset);
1413
+ },
1414
+ put(array, offset, value) {
1415
+ dv(array).setInt32(offset, value);
1416
+ return offset + 4;
1417
+ }
1418
+ };
1419
+ var UINT64_LE = {
1420
+ len: 8,
1421
+ get(array, offset) {
1422
+ return dv(array).getBigUint64(offset, true);
1423
+ },
1424
+ put(array, offset, value) {
1425
+ dv(array).setBigUint64(offset, value, true);
1426
+ return offset + 8;
1427
+ }
1428
+ };
1429
+ var StringType = class {
1430
+ constructor(len, encoding) {
1431
+ this.len = len;
1432
+ this.encoding = encoding;
1433
+ }
1434
+ get(data, offset = 0) {
1435
+ const bytes = data.subarray(offset, offset + this.len);
1436
+ return textDecode(bytes, this.encoding);
1437
+ }
1438
+ };
1439
+
1440
+ // ../../node_modules/strtok3/lib/stream/Errors.js
1441
+ var defaultMessages = "End-Of-Stream";
1442
+ var EndOfStreamError = class extends Error {
1443
+ constructor() {
1444
+ super(defaultMessages);
1445
+ this.name = "EndOfStreamError";
1446
+ }
1447
+ };
1448
+ var AbortError = class extends Error {
1449
+ constructor(message = "The operation was aborted") {
1450
+ super(message);
1451
+ this.name = "AbortError";
1452
+ }
1453
+ };
1454
+
1455
+ // ../../node_modules/strtok3/lib/stream/AbstractStreamReader.js
1456
+ var AbstractStreamReader = class {
1457
+ constructor() {
1458
+ this.endOfStream = false;
1459
+ this.interrupted = false;
1460
+ this.peekQueue = [];
1461
+ }
1462
+ async peek(uint8Array, mayBeLess = false) {
1463
+ const bytesRead = await this.read(uint8Array, mayBeLess);
1464
+ this.peekQueue.push(uint8Array.subarray(0, bytesRead));
1465
+ return bytesRead;
1466
+ }
1467
+ async read(buffer, mayBeLess = false) {
1468
+ if (buffer.length === 0) {
1469
+ return 0;
1470
+ }
1471
+ let bytesRead = this.readFromPeekBuffer(buffer);
1472
+ if (!this.endOfStream) {
1473
+ bytesRead += await this.readRemainderFromStream(buffer.subarray(bytesRead), mayBeLess);
1474
+ }
1475
+ if (bytesRead === 0 && !mayBeLess) {
1476
+ throw new EndOfStreamError();
1477
+ }
1478
+ return bytesRead;
1479
+ }
1480
+ /**
1481
+ * Read chunk from stream
1482
+ * @param buffer - Target Uint8Array (or Buffer) to store data read from stream in
1483
+ * @returns Number of bytes read
1484
+ */
1485
+ readFromPeekBuffer(buffer) {
1486
+ let remaining = buffer.length;
1487
+ let bytesRead = 0;
1488
+ while (this.peekQueue.length > 0 && remaining > 0) {
1489
+ const peekData = this.peekQueue.pop();
1490
+ if (!peekData)
1491
+ throw new Error("peekData should be defined");
1492
+ const lenCopy = Math.min(peekData.length, remaining);
1493
+ buffer.set(peekData.subarray(0, lenCopy), bytesRead);
1494
+ bytesRead += lenCopy;
1495
+ remaining -= lenCopy;
1496
+ if (lenCopy < peekData.length) {
1497
+ this.peekQueue.push(peekData.subarray(lenCopy));
1498
+ }
1499
+ }
1500
+ return bytesRead;
1501
+ }
1502
+ async readRemainderFromStream(buffer, mayBeLess) {
1503
+ let bytesRead = 0;
1504
+ while (bytesRead < buffer.length && !this.endOfStream) {
1505
+ if (this.interrupted) {
1506
+ throw new AbortError();
1507
+ }
1508
+ const chunkLen = await this.readFromStream(buffer.subarray(bytesRead), mayBeLess);
1509
+ if (chunkLen === 0)
1510
+ break;
1511
+ bytesRead += chunkLen;
1512
+ }
1513
+ if (!mayBeLess && bytesRead < buffer.length) {
1514
+ throw new EndOfStreamError();
1515
+ }
1516
+ return bytesRead;
1517
+ }
1518
+ };
1519
+
1520
+ // ../../node_modules/strtok3/lib/stream/WebStreamReader.js
1521
+ var WebStreamReader = class extends AbstractStreamReader {
1522
+ constructor(reader) {
1523
+ super();
1524
+ this.reader = reader;
1525
+ }
1526
+ async abort() {
1527
+ return this.close();
1528
+ }
1529
+ async close() {
1530
+ this.reader.releaseLock();
1531
+ }
1532
+ };
1533
+
1534
+ // ../../node_modules/strtok3/lib/stream/WebStreamByobReader.js
1535
+ var WebStreamByobReader = class extends WebStreamReader {
1536
+ /**
1537
+ * Read from stream
1538
+ * @param buffer - Target Uint8Array (or Buffer) to store data read from stream in
1539
+ * @param mayBeLess - If true, may fill the buffer partially
1540
+ * @protected Bytes read
1541
+ */
1542
+ async readFromStream(buffer, mayBeLess) {
1543
+ if (buffer.length === 0)
1544
+ return 0;
1545
+ const result = await this.reader.read(new Uint8Array(buffer.length), { min: mayBeLess ? void 0 : buffer.length });
1546
+ if (result.done) {
1547
+ this.endOfStream = result.done;
1548
+ }
1549
+ if (result.value) {
1550
+ buffer.set(result.value);
1551
+ return result.value.length;
1552
+ }
1553
+ return 0;
1554
+ }
1555
+ };
1556
+
1557
+ // ../../node_modules/strtok3/lib/stream/WebStreamDefaultReader.js
1558
+ var WebStreamDefaultReader = class extends AbstractStreamReader {
1559
+ constructor(reader) {
1560
+ super();
1561
+ this.reader = reader;
1562
+ this.buffer = null;
1563
+ }
1564
+ /**
1565
+ * Copy chunk to target, and store the remainder in this.buffer
1566
+ */
1567
+ writeChunk(target, chunk) {
1568
+ const written = Math.min(chunk.length, target.length);
1569
+ target.set(chunk.subarray(0, written));
1570
+ if (written < chunk.length) {
1571
+ this.buffer = chunk.subarray(written);
1572
+ } else {
1573
+ this.buffer = null;
1574
+ }
1575
+ return written;
1576
+ }
1577
+ /**
1578
+ * Read from stream
1579
+ * @param buffer - Target Uint8Array (or Buffer) to store data read from stream in
1580
+ * @param mayBeLess - If true, may fill the buffer partially
1581
+ * @protected Bytes read
1582
+ */
1583
+ async readFromStream(buffer, mayBeLess) {
1584
+ if (buffer.length === 0)
1585
+ return 0;
1586
+ let totalBytesRead = 0;
1587
+ if (this.buffer) {
1588
+ totalBytesRead += this.writeChunk(buffer, this.buffer);
1589
+ }
1590
+ while (totalBytesRead < buffer.length && !this.endOfStream) {
1591
+ const result = await this.reader.read();
1592
+ if (result.done) {
1593
+ this.endOfStream = true;
1594
+ break;
1595
+ }
1596
+ if (result.value) {
1597
+ totalBytesRead += this.writeChunk(buffer.subarray(totalBytesRead), result.value);
1598
+ }
1599
+ }
1600
+ if (!mayBeLess && totalBytesRead === 0 && this.endOfStream) {
1601
+ throw new EndOfStreamError();
1602
+ }
1603
+ return totalBytesRead;
1604
+ }
1605
+ abort() {
1606
+ this.interrupted = true;
1607
+ return this.reader.cancel();
1608
+ }
1609
+ async close() {
1610
+ await this.abort();
1611
+ this.reader.releaseLock();
1612
+ }
1613
+ };
1614
+
1615
+ // ../../node_modules/strtok3/lib/stream/WebStreamReaderFactory.js
1616
+ function makeWebStreamReader(stream) {
1617
+ try {
1618
+ const reader = stream.getReader({ mode: "byob" });
1619
+ if (reader instanceof ReadableStreamDefaultReader) {
1620
+ return new WebStreamDefaultReader(reader);
1621
+ }
1622
+ return new WebStreamByobReader(reader);
1623
+ } catch (error) {
1624
+ if (error instanceof TypeError) {
1625
+ return new WebStreamDefaultReader(stream.getReader());
1626
+ }
1627
+ throw error;
1628
+ }
1629
+ }
1630
+
1631
+ // ../../node_modules/strtok3/lib/AbstractTokenizer.js
1632
+ var AbstractTokenizer = class {
1633
+ /**
1634
+ * Constructor
1635
+ * @param options Tokenizer options
1636
+ * @protected
1637
+ */
1638
+ constructor(options) {
1639
+ this.numBuffer = new Uint8Array(8);
1640
+ this.position = 0;
1641
+ this.onClose = options?.onClose;
1642
+ if (options?.abortSignal) {
1643
+ options.abortSignal.addEventListener("abort", () => {
1644
+ this.abort();
1645
+ });
1646
+ }
1647
+ }
1648
+ /**
1649
+ * Read a token from the tokenizer-stream
1650
+ * @param token - The token to read
1651
+ * @param position - If provided, the desired position in the tokenizer-stream
1652
+ * @returns Promise with token data
1653
+ */
1654
+ async readToken(token, position = this.position) {
1655
+ const uint8Array = new Uint8Array(token.len);
1656
+ const len = await this.readBuffer(uint8Array, { position });
1657
+ if (len < token.len)
1658
+ throw new EndOfStreamError();
1659
+ return token.get(uint8Array, 0);
1660
+ }
1661
+ /**
1662
+ * Peek a token from the tokenizer-stream.
1663
+ * @param token - Token to peek from the tokenizer-stream.
1664
+ * @param position - Offset where to begin reading within the file. If position is null, data will be read from the current file position.
1665
+ * @returns Promise with token data
1666
+ */
1667
+ async peekToken(token, position = this.position) {
1668
+ const uint8Array = new Uint8Array(token.len);
1669
+ const len = await this.peekBuffer(uint8Array, { position });
1670
+ if (len < token.len)
1671
+ throw new EndOfStreamError();
1672
+ return token.get(uint8Array, 0);
1673
+ }
1674
+ /**
1675
+ * Read a numeric token from the stream
1676
+ * @param token - Numeric token
1677
+ * @returns Promise with number
1678
+ */
1679
+ async readNumber(token) {
1680
+ const len = await this.readBuffer(this.numBuffer, { length: token.len });
1681
+ if (len < token.len)
1682
+ throw new EndOfStreamError();
1683
+ return token.get(this.numBuffer, 0);
1684
+ }
1685
+ /**
1686
+ * Read a numeric token from the stream
1687
+ * @param token - Numeric token
1688
+ * @returns Promise with number
1689
+ */
1690
+ async peekNumber(token) {
1691
+ const len = await this.peekBuffer(this.numBuffer, { length: token.len });
1692
+ if (len < token.len)
1693
+ throw new EndOfStreamError();
1694
+ return token.get(this.numBuffer, 0);
1695
+ }
1696
+ /**
1697
+ * Ignore number of bytes, advances the pointer in under tokenizer-stream.
1698
+ * @param length - Number of bytes to ignore
1699
+ * @return resolves the number of bytes ignored, equals length if this available, otherwise the number of bytes available
1700
+ */
1701
+ async ignore(length) {
1702
+ if (this.fileInfo.size !== void 0) {
1703
+ const bytesLeft = this.fileInfo.size - this.position;
1704
+ if (length > bytesLeft) {
1705
+ this.position += bytesLeft;
1706
+ return bytesLeft;
1707
+ }
1708
+ }
1709
+ this.position += length;
1710
+ return length;
1711
+ }
1712
+ async close() {
1713
+ await this.abort();
1714
+ await this.onClose?.();
1715
+ }
1716
+ normalizeOptions(uint8Array, options) {
1717
+ if (!this.supportsRandomAccess() && options && options.position !== void 0 && options.position < this.position) {
1718
+ throw new Error("`options.position` must be equal or greater than `tokenizer.position`");
1719
+ }
1720
+ return {
1721
+ ...{
1722
+ mayBeLess: false,
1723
+ offset: 0,
1724
+ length: uint8Array.length,
1725
+ position: this.position
1726
+ },
1727
+ ...options
1728
+ };
1729
+ }
1730
+ abort() {
1731
+ return Promise.resolve();
1732
+ }
1733
+ };
1734
+
1735
+ // ../../node_modules/strtok3/lib/ReadStreamTokenizer.js
1736
+ var maxBufferSize = 256e3;
1737
+ var ReadStreamTokenizer = class extends AbstractTokenizer {
1738
+ /**
1739
+ * Constructor
1740
+ * @param streamReader stream-reader to read from
1741
+ * @param options Tokenizer options
1742
+ */
1743
+ constructor(streamReader, options) {
1744
+ super(options);
1745
+ this.streamReader = streamReader;
1746
+ this.fileInfo = options?.fileInfo ?? {};
1747
+ }
1748
+ /**
1749
+ * Read buffer from tokenizer
1750
+ * @param uint8Array - Target Uint8Array to fill with data read from the tokenizer-stream
1751
+ * @param options - Read behaviour options
1752
+ * @returns Promise with number of bytes read
1753
+ */
1754
+ async readBuffer(uint8Array, options) {
1755
+ const normOptions = this.normalizeOptions(uint8Array, options);
1756
+ const skipBytes = normOptions.position - this.position;
1757
+ if (skipBytes > 0) {
1758
+ await this.ignore(skipBytes);
1759
+ return this.readBuffer(uint8Array, options);
1760
+ }
1761
+ if (skipBytes < 0) {
1762
+ throw new Error("`options.position` must be equal or greater than `tokenizer.position`");
1763
+ }
1764
+ if (normOptions.length === 0) {
1765
+ return 0;
1766
+ }
1767
+ const bytesRead = await this.streamReader.read(uint8Array.subarray(0, normOptions.length), normOptions.mayBeLess);
1768
+ this.position += bytesRead;
1769
+ if ((!options || !options.mayBeLess) && bytesRead < normOptions.length) {
1770
+ throw new EndOfStreamError();
1771
+ }
1772
+ return bytesRead;
1773
+ }
1774
+ /**
1775
+ * Peek (read ahead) buffer from tokenizer
1776
+ * @param uint8Array - Uint8Array (or Buffer) to write data to
1777
+ * @param options - Read behaviour options
1778
+ * @returns Promise with number of bytes peeked
1779
+ */
1780
+ async peekBuffer(uint8Array, options) {
1781
+ const normOptions = this.normalizeOptions(uint8Array, options);
1782
+ let bytesRead = 0;
1783
+ if (normOptions.position) {
1784
+ const skipBytes = normOptions.position - this.position;
1785
+ if (skipBytes > 0) {
1786
+ const skipBuffer = new Uint8Array(normOptions.length + skipBytes);
1787
+ bytesRead = await this.peekBuffer(skipBuffer, { mayBeLess: normOptions.mayBeLess });
1788
+ uint8Array.set(skipBuffer.subarray(skipBytes));
1789
+ return bytesRead - skipBytes;
1790
+ }
1791
+ if (skipBytes < 0) {
1792
+ throw new Error("Cannot peek from a negative offset in a stream");
1793
+ }
1794
+ }
1795
+ if (normOptions.length > 0) {
1796
+ try {
1797
+ bytesRead = await this.streamReader.peek(uint8Array.subarray(0, normOptions.length), normOptions.mayBeLess);
1798
+ } catch (err) {
1799
+ if (options?.mayBeLess && err instanceof EndOfStreamError) {
1800
+ return 0;
1801
+ }
1802
+ throw err;
1803
+ }
1804
+ if (!normOptions.mayBeLess && bytesRead < normOptions.length) {
1805
+ throw new EndOfStreamError();
1806
+ }
1807
+ }
1808
+ return bytesRead;
1809
+ }
1810
+ async ignore(length) {
1811
+ const bufSize = Math.min(maxBufferSize, length);
1812
+ const buf = new Uint8Array(bufSize);
1813
+ let totBytesRead = 0;
1814
+ while (totBytesRead < length) {
1815
+ const remaining = length - totBytesRead;
1816
+ const bytesRead = await this.readBuffer(buf, { length: Math.min(bufSize, remaining) });
1817
+ if (bytesRead < 0) {
1818
+ return bytesRead;
1819
+ }
1820
+ totBytesRead += bytesRead;
1821
+ }
1822
+ return totBytesRead;
1823
+ }
1824
+ abort() {
1825
+ return this.streamReader.abort();
1826
+ }
1827
+ async close() {
1828
+ return this.streamReader.close();
1829
+ }
1830
+ supportsRandomAccess() {
1831
+ return false;
1832
+ }
1833
+ };
1834
+
1835
+ // ../../node_modules/strtok3/lib/BufferTokenizer.js
1836
+ var BufferTokenizer = class extends AbstractTokenizer {
1837
+ /**
1838
+ * Construct BufferTokenizer
1839
+ * @param uint8Array - Uint8Array to tokenize
1840
+ * @param options Tokenizer options
1841
+ */
1842
+ constructor(uint8Array, options) {
1843
+ super(options);
1844
+ this.uint8Array = uint8Array;
1845
+ this.fileInfo = { ...options?.fileInfo ?? {}, ...{ size: uint8Array.length } };
1846
+ }
1847
+ /**
1848
+ * Read buffer from tokenizer
1849
+ * @param uint8Array - Uint8Array to tokenize
1850
+ * @param options - Read behaviour options
1851
+ * @returns {Promise<number>}
1852
+ */
1853
+ async readBuffer(uint8Array, options) {
1854
+ if (options?.position) {
1855
+ this.position = options.position;
1856
+ }
1857
+ const bytesRead = await this.peekBuffer(uint8Array, options);
1858
+ this.position += bytesRead;
1859
+ return bytesRead;
1860
+ }
1861
+ /**
1862
+ * Peek (read ahead) buffer from tokenizer
1863
+ * @param uint8Array
1864
+ * @param options - Read behaviour options
1865
+ * @returns {Promise<number>}
1866
+ */
1867
+ async peekBuffer(uint8Array, options) {
1868
+ const normOptions = this.normalizeOptions(uint8Array, options);
1869
+ const bytes2read = Math.min(this.uint8Array.length - normOptions.position, normOptions.length);
1870
+ if (!normOptions.mayBeLess && bytes2read < normOptions.length) {
1871
+ throw new EndOfStreamError();
1872
+ }
1873
+ uint8Array.set(this.uint8Array.subarray(normOptions.position, normOptions.position + bytes2read));
1874
+ return bytes2read;
1875
+ }
1876
+ close() {
1877
+ return super.close();
1878
+ }
1879
+ supportsRandomAccess() {
1880
+ return true;
1881
+ }
1882
+ setPosition(position) {
1883
+ this.position = position;
1884
+ }
1885
+ };
1886
+
1887
+ // ../../node_modules/strtok3/lib/BlobTokenizer.js
1888
+ var BlobTokenizer = class extends AbstractTokenizer {
1889
+ /**
1890
+ * Construct BufferTokenizer
1891
+ * @param blob - Uint8Array to tokenize
1892
+ * @param options Tokenizer options
1893
+ */
1894
+ constructor(blob, options) {
1895
+ super(options);
1896
+ this.blob = blob;
1897
+ this.fileInfo = { ...options?.fileInfo ?? {}, ...{ size: blob.size, mimeType: blob.type } };
1898
+ }
1899
+ /**
1900
+ * Read buffer from tokenizer
1901
+ * @param uint8Array - Uint8Array to tokenize
1902
+ * @param options - Read behaviour options
1903
+ * @returns {Promise<number>}
1904
+ */
1905
+ async readBuffer(uint8Array, options) {
1906
+ if (options?.position) {
1907
+ this.position = options.position;
1908
+ }
1909
+ const bytesRead = await this.peekBuffer(uint8Array, options);
1910
+ this.position += bytesRead;
1911
+ return bytesRead;
1912
+ }
1913
+ /**
1914
+ * Peek (read ahead) buffer from tokenizer
1915
+ * @param buffer
1916
+ * @param options - Read behaviour options
1917
+ * @returns {Promise<number>}
1918
+ */
1919
+ async peekBuffer(buffer, options) {
1920
+ const normOptions = this.normalizeOptions(buffer, options);
1921
+ const bytes2read = Math.min(this.blob.size - normOptions.position, normOptions.length);
1922
+ if (!normOptions.mayBeLess && bytes2read < normOptions.length) {
1923
+ throw new EndOfStreamError();
1924
+ }
1925
+ const arrayBuffer = await this.blob.slice(normOptions.position, normOptions.position + bytes2read).arrayBuffer();
1926
+ buffer.set(new Uint8Array(arrayBuffer));
1927
+ return bytes2read;
1928
+ }
1929
+ close() {
1930
+ return super.close();
1931
+ }
1932
+ supportsRandomAccess() {
1933
+ return true;
1934
+ }
1935
+ setPosition(position) {
1936
+ this.position = position;
1937
+ }
1938
+ };
1939
+
1940
+ // ../../node_modules/strtok3/lib/core.js
1941
+ function fromWebStream(webStream, options) {
1942
+ const webStreamReader = makeWebStreamReader(webStream);
1943
+ const _options = options ?? {};
1944
+ const chainedClose = _options.onClose;
1945
+ _options.onClose = async () => {
1946
+ await webStreamReader.close();
1947
+ if (chainedClose) {
1948
+ return chainedClose();
1949
+ }
1950
+ };
1951
+ return new ReadStreamTokenizer(webStreamReader, _options);
1952
+ }
1953
+ function fromBuffer(uint8Array, options) {
1954
+ return new BufferTokenizer(uint8Array, options);
1955
+ }
1956
+ function fromBlob(blob, options) {
1957
+ return new BlobTokenizer(blob, options);
1958
+ }
1959
+
1960
+ // ../../node_modules/@tokenizer/inflate/lib/ZipHandler.js
1961
+ var import_debug = __toESM(require_src(), 1);
1962
+
1963
+ // ../../node_modules/@tokenizer/inflate/lib/ZipToken.js
1964
+ var Signature = {
1965
+ LocalFileHeader: 67324752,
1966
+ DataDescriptor: 134695760,
1967
+ CentralFileHeader: 33639248,
1968
+ EndOfCentralDirectory: 101010256
1969
+ };
1970
+ var DataDescriptor = {
1971
+ get(array) {
1972
+ return {
1973
+ signature: UINT32_LE.get(array, 0),
1974
+ compressedSize: UINT32_LE.get(array, 8),
1975
+ uncompressedSize: UINT32_LE.get(array, 12)
1976
+ };
1977
+ },
1978
+ len: 16
1979
+ };
1980
+ var LocalFileHeaderToken = {
1981
+ get(array) {
1982
+ const flags = UINT16_LE.get(array, 6);
1983
+ return {
1984
+ signature: UINT32_LE.get(array, 0),
1985
+ minVersion: UINT16_LE.get(array, 4),
1986
+ dataDescriptor: !!(flags & 8),
1987
+ compressedMethod: UINT16_LE.get(array, 8),
1988
+ compressedSize: UINT32_LE.get(array, 18),
1989
+ uncompressedSize: UINT32_LE.get(array, 22),
1990
+ filenameLength: UINT16_LE.get(array, 26),
1991
+ extraFieldLength: UINT16_LE.get(array, 28),
1992
+ filename: null
1993
+ };
1994
+ },
1995
+ len: 30
1996
+ };
1997
+ var EndOfCentralDirectoryRecordToken = {
1998
+ get(array) {
1999
+ return {
2000
+ signature: UINT32_LE.get(array, 0),
2001
+ nrOfThisDisk: UINT16_LE.get(array, 4),
2002
+ nrOfThisDiskWithTheStart: UINT16_LE.get(array, 6),
2003
+ nrOfEntriesOnThisDisk: UINT16_LE.get(array, 8),
2004
+ nrOfEntriesOfSize: UINT16_LE.get(array, 10),
2005
+ sizeOfCd: UINT32_LE.get(array, 12),
2006
+ offsetOfStartOfCd: UINT32_LE.get(array, 16),
2007
+ zipFileCommentLength: UINT16_LE.get(array, 20)
2008
+ };
2009
+ },
2010
+ len: 22
2011
+ };
2012
+ var FileHeader = {
2013
+ get(array) {
2014
+ const flags = UINT16_LE.get(array, 8);
2015
+ return {
2016
+ signature: UINT32_LE.get(array, 0),
2017
+ minVersion: UINT16_LE.get(array, 6),
2018
+ dataDescriptor: !!(flags & 8),
2019
+ compressedMethod: UINT16_LE.get(array, 10),
2020
+ compressedSize: UINT32_LE.get(array, 20),
2021
+ uncompressedSize: UINT32_LE.get(array, 24),
2022
+ filenameLength: UINT16_LE.get(array, 28),
2023
+ extraFieldLength: UINT16_LE.get(array, 30),
2024
+ fileCommentLength: UINT16_LE.get(array, 32),
2025
+ relativeOffsetOfLocalHeader: UINT32_LE.get(array, 42),
2026
+ filename: null
2027
+ };
2028
+ },
2029
+ len: 46
2030
+ };
2031
+
2032
+ // ../../node_modules/@tokenizer/inflate/lib/ZipHandler.js
2033
+ function signatureToArray(signature) {
2034
+ const signatureBytes = new Uint8Array(UINT32_LE.len);
2035
+ UINT32_LE.put(signatureBytes, 0, signature);
2036
+ return signatureBytes;
2037
+ }
2038
+ var debug = (0, import_debug.default)("tokenizer:inflate");
2039
+ var syncBufferSize = 256 * 1024;
2040
+ var ddSignatureArray = signatureToArray(Signature.DataDescriptor);
2041
+ var eocdSignatureBytes = signatureToArray(Signature.EndOfCentralDirectory);
2042
+ var ZipHandler = class _ZipHandler {
2043
+ constructor(tokenizer) {
2044
+ this.tokenizer = tokenizer;
2045
+ this.syncBuffer = new Uint8Array(syncBufferSize);
2046
+ }
2047
+ async isZip() {
2048
+ return await this.peekSignature() === Signature.LocalFileHeader;
2049
+ }
2050
+ peekSignature() {
2051
+ return this.tokenizer.peekToken(UINT32_LE);
2052
+ }
2053
+ async findEndOfCentralDirectoryLocator() {
2054
+ const randomReadTokenizer = this.tokenizer;
2055
+ const chunkLength = Math.min(16 * 1024, randomReadTokenizer.fileInfo.size);
2056
+ const buffer = this.syncBuffer.subarray(0, chunkLength);
2057
+ await this.tokenizer.readBuffer(buffer, { position: randomReadTokenizer.fileInfo.size - chunkLength });
2058
+ for (let i = buffer.length - 4; i >= 0; i--) {
2059
+ if (buffer[i] === eocdSignatureBytes[0] && buffer[i + 1] === eocdSignatureBytes[1] && buffer[i + 2] === eocdSignatureBytes[2] && buffer[i + 3] === eocdSignatureBytes[3]) {
2060
+ return randomReadTokenizer.fileInfo.size - chunkLength + i;
2061
+ }
2062
+ }
2063
+ return -1;
2064
+ }
2065
+ async readCentralDirectory() {
2066
+ if (!this.tokenizer.supportsRandomAccess()) {
2067
+ debug("Cannot reading central-directory without random-read support");
2068
+ return;
2069
+ }
2070
+ debug("Reading central-directory...");
2071
+ const pos = this.tokenizer.position;
2072
+ const offset = await this.findEndOfCentralDirectoryLocator();
2073
+ if (offset > 0) {
2074
+ debug("Central-directory 32-bit signature found");
2075
+ const eocdHeader = await this.tokenizer.readToken(EndOfCentralDirectoryRecordToken, offset);
2076
+ const files = [];
2077
+ this.tokenizer.setPosition(eocdHeader.offsetOfStartOfCd);
2078
+ for (let n = 0; n < eocdHeader.nrOfEntriesOfSize; ++n) {
2079
+ const entry = await this.tokenizer.readToken(FileHeader);
2080
+ if (entry.signature !== Signature.CentralFileHeader) {
2081
+ throw new Error("Expected Central-File-Header signature");
2082
+ }
2083
+ entry.filename = await this.tokenizer.readToken(new StringType(entry.filenameLength, "utf-8"));
2084
+ await this.tokenizer.ignore(entry.extraFieldLength);
2085
+ await this.tokenizer.ignore(entry.fileCommentLength);
2086
+ files.push(entry);
2087
+ debug(`Add central-directory file-entry: n=${n + 1}/${files.length}: filename=${files[n].filename}`);
2088
+ }
2089
+ this.tokenizer.setPosition(pos);
2090
+ return files;
2091
+ }
2092
+ this.tokenizer.setPosition(pos);
2093
+ }
2094
+ async unzip(fileCb) {
2095
+ const entries = await this.readCentralDirectory();
2096
+ if (entries) {
2097
+ return this.iterateOverCentralDirectory(entries, fileCb);
2098
+ }
2099
+ let stop = false;
2100
+ do {
2101
+ const zipHeader = await this.readLocalFileHeader();
2102
+ if (!zipHeader)
2103
+ break;
2104
+ const next = fileCb(zipHeader);
2105
+ stop = !!next.stop;
2106
+ let fileData;
2107
+ await this.tokenizer.ignore(zipHeader.extraFieldLength);
2108
+ if (zipHeader.dataDescriptor && zipHeader.compressedSize === 0) {
2109
+ const chunks = [];
2110
+ let len = syncBufferSize;
2111
+ debug("Compressed-file-size unknown, scanning for next data-descriptor-signature....");
2112
+ let nextHeaderIndex = -1;
2113
+ while (nextHeaderIndex < 0 && len === syncBufferSize) {
2114
+ len = await this.tokenizer.peekBuffer(this.syncBuffer, { mayBeLess: true });
2115
+ nextHeaderIndex = indexOf(this.syncBuffer.subarray(0, len), ddSignatureArray);
2116
+ const size = nextHeaderIndex >= 0 ? nextHeaderIndex : len;
2117
+ if (next.handler) {
2118
+ const data = new Uint8Array(size);
2119
+ await this.tokenizer.readBuffer(data);
2120
+ chunks.push(data);
2121
+ } else {
2122
+ await this.tokenizer.ignore(size);
2123
+ }
2124
+ }
2125
+ debug(`Found data-descriptor-signature at pos=${this.tokenizer.position}`);
2126
+ if (next.handler) {
2127
+ await this.inflate(zipHeader, mergeArrays(chunks), next.handler);
2128
+ }
2129
+ } else {
2130
+ if (next.handler) {
2131
+ debug(`Reading compressed-file-data: ${zipHeader.compressedSize} bytes`);
2132
+ fileData = new Uint8Array(zipHeader.compressedSize);
2133
+ await this.tokenizer.readBuffer(fileData);
2134
+ await this.inflate(zipHeader, fileData, next.handler);
2135
+ } else {
2136
+ debug(`Ignoring compressed-file-data: ${zipHeader.compressedSize} bytes`);
2137
+ await this.tokenizer.ignore(zipHeader.compressedSize);
2138
+ }
2139
+ }
2140
+ debug(`Reading data-descriptor at pos=${this.tokenizer.position}`);
2141
+ if (zipHeader.dataDescriptor) {
2142
+ const dataDescriptor = await this.tokenizer.readToken(DataDescriptor);
2143
+ if (dataDescriptor.signature !== 134695760) {
2144
+ throw new Error(`Expected data-descriptor-signature at position ${this.tokenizer.position - DataDescriptor.len}`);
2145
+ }
2146
+ }
2147
+ } while (!stop);
2148
+ }
2149
+ async iterateOverCentralDirectory(entries, fileCb) {
2150
+ for (const fileHeader of entries) {
2151
+ const next = fileCb(fileHeader);
2152
+ if (next.handler) {
2153
+ this.tokenizer.setPosition(fileHeader.relativeOffsetOfLocalHeader);
2154
+ const zipHeader = await this.readLocalFileHeader();
2155
+ if (zipHeader) {
2156
+ await this.tokenizer.ignore(zipHeader.extraFieldLength);
2157
+ const fileData = new Uint8Array(fileHeader.compressedSize);
2158
+ await this.tokenizer.readBuffer(fileData);
2159
+ await this.inflate(zipHeader, fileData, next.handler);
2160
+ }
2161
+ }
2162
+ if (next.stop)
2163
+ break;
2164
+ }
2165
+ }
2166
+ async inflate(zipHeader, fileData, cb) {
2167
+ if (zipHeader.compressedMethod === 0) {
2168
+ return cb(fileData);
2169
+ }
2170
+ if (zipHeader.compressedMethod !== 8) {
2171
+ throw new Error(`Unsupported ZIP compression method: ${zipHeader.compressedMethod}`);
2172
+ }
2173
+ debug(`Decompress filename=${zipHeader.filename}, compressed-size=${fileData.length}`);
2174
+ const uncompressedData = await _ZipHandler.decompressDeflateRaw(fileData);
2175
+ return cb(uncompressedData);
2176
+ }
2177
+ static async decompressDeflateRaw(data) {
2178
+ const input = new ReadableStream({
2179
+ start(controller) {
2180
+ controller.enqueue(data);
2181
+ controller.close();
2182
+ }
2183
+ });
2184
+ const ds = new DecompressionStream("deflate-raw");
2185
+ const output = input.pipeThrough(ds);
2186
+ try {
2187
+ const response = new Response(output);
2188
+ const buffer = await response.arrayBuffer();
2189
+ return new Uint8Array(buffer);
2190
+ } catch (err) {
2191
+ const message = err instanceof Error ? `Failed to deflate ZIP entry: ${err.message}` : "Unknown decompression error in ZIP entry";
2192
+ throw new TypeError(message);
2193
+ }
2194
+ }
2195
+ async readLocalFileHeader() {
2196
+ const signature = await this.tokenizer.peekToken(UINT32_LE);
2197
+ if (signature === Signature.LocalFileHeader) {
2198
+ const header = await this.tokenizer.readToken(LocalFileHeaderToken);
2199
+ header.filename = await this.tokenizer.readToken(new StringType(header.filenameLength, "utf-8"));
2200
+ return header;
2201
+ }
2202
+ if (signature === Signature.CentralFileHeader) {
2203
+ return false;
2204
+ }
2205
+ if (signature === 3759263696) {
2206
+ throw new Error("Encrypted ZIP");
2207
+ }
2208
+ throw new Error("Unexpected signature");
2209
+ }
2210
+ };
2211
+ function indexOf(buffer, portion) {
2212
+ const bufferLength = buffer.length;
2213
+ const portionLength = portion.length;
2214
+ if (portionLength > bufferLength)
2215
+ return -1;
2216
+ for (let i = 0; i <= bufferLength - portionLength; i++) {
2217
+ let found = true;
2218
+ for (let j = 0; j < portionLength; j++) {
2219
+ if (buffer[i + j] !== portion[j]) {
2220
+ found = false;
2221
+ break;
2222
+ }
2223
+ }
2224
+ if (found) {
2225
+ return i;
2226
+ }
2227
+ }
2228
+ return -1;
2229
+ }
2230
+ function mergeArrays(chunks) {
2231
+ const totalLength = chunks.reduce((acc, curr) => acc + curr.length, 0);
2232
+ const mergedArray = new Uint8Array(totalLength);
2233
+ let offset = 0;
2234
+ for (const chunk of chunks) {
2235
+ mergedArray.set(chunk, offset);
2236
+ offset += chunk.length;
2237
+ }
2238
+ return mergedArray;
2239
+ }
2240
+
2241
+ // ../../node_modules/@tokenizer/inflate/lib/GzipHandler.js
2242
+ var GzipHandler = class {
2243
+ constructor(tokenizer) {
2244
+ this.tokenizer = tokenizer;
2245
+ }
2246
+ inflate() {
2247
+ const tokenizer = this.tokenizer;
2248
+ return new ReadableStream({
2249
+ async pull(controller) {
2250
+ const buffer = new Uint8Array(1024);
2251
+ const size = await tokenizer.readBuffer(buffer, { mayBeLess: true });
2252
+ if (size === 0) {
2253
+ controller.close();
2254
+ return;
2255
+ }
2256
+ controller.enqueue(buffer.subarray(0, size));
2257
+ }
2258
+ }).pipeThrough(new DecompressionStream("gzip"));
2259
+ }
2260
+ };
2261
+
2262
+ // ../../node_modules/uint8array-extras/index.js
2263
+ var cachedDecoders = {
2264
+ utf8: new globalThis.TextDecoder("utf8")
2265
+ };
2266
+ var cachedEncoder = new globalThis.TextEncoder();
2267
+ var byteToHexLookupTable = Array.from({ length: 256 }, (_, index) => index.toString(16).padStart(2, "0"));
2268
+ function getUintBE(view) {
2269
+ const { byteLength } = view;
2270
+ if (byteLength === 6) {
2271
+ return view.getUint16(0) * 2 ** 32 + view.getUint32(2);
2272
+ }
2273
+ if (byteLength === 5) {
2274
+ return view.getUint8(0) * 2 ** 32 + view.getUint32(1);
2275
+ }
2276
+ if (byteLength === 4) {
2277
+ return view.getUint32(0);
2278
+ }
2279
+ if (byteLength === 3) {
2280
+ return view.getUint8(0) * 2 ** 16 + view.getUint16(1);
2281
+ }
2282
+ if (byteLength === 2) {
2283
+ return view.getUint16(0);
2284
+ }
2285
+ if (byteLength === 1) {
2286
+ return view.getUint8(0);
2287
+ }
2288
+ }
2289
+
2290
+ // ../../node_modules/file-type/util.js
2291
+ function stringToBytes(string, encoding) {
2292
+ if (encoding === "utf-16le") {
2293
+ const bytes = [];
2294
+ for (let index = 0; index < string.length; index++) {
2295
+ const code = string.charCodeAt(index);
2296
+ bytes.push(code & 255, code >> 8 & 255);
2297
+ }
2298
+ return bytes;
2299
+ }
2300
+ if (encoding === "utf-16be") {
2301
+ const bytes = [];
2302
+ for (let index = 0; index < string.length; index++) {
2303
+ const code = string.charCodeAt(index);
2304
+ bytes.push(code >> 8 & 255, code & 255);
2305
+ }
2306
+ return bytes;
2307
+ }
2308
+ return [...string].map((character) => character.charCodeAt(0));
2309
+ }
2310
+ function tarHeaderChecksumMatches(arrayBuffer, offset = 0) {
2311
+ const readSum = Number.parseInt(new StringType(6).get(arrayBuffer, 148).replace(/\0.*$/, "").trim(), 8);
2312
+ if (Number.isNaN(readSum)) {
2313
+ return false;
2314
+ }
2315
+ let sum = 8 * 32;
2316
+ for (let index = offset; index < offset + 148; index++) {
2317
+ sum += arrayBuffer[index];
2318
+ }
2319
+ for (let index = offset + 156; index < offset + 512; index++) {
2320
+ sum += arrayBuffer[index];
2321
+ }
2322
+ return readSum === sum;
2323
+ }
2324
+ var uint32SyncSafeToken = {
2325
+ get: (buffer, offset) => buffer[offset + 3] & 127 | buffer[offset + 2] << 7 | buffer[offset + 1] << 14 | buffer[offset] << 21,
2326
+ len: 4
2327
+ };
2328
+
2329
+ // ../../node_modules/file-type/supported.js
2330
+ var extensions = [
2331
+ "jpg",
2332
+ "png",
2333
+ "apng",
2334
+ "gif",
2335
+ "webp",
2336
+ "flif",
2337
+ "xcf",
2338
+ "cr2",
2339
+ "cr3",
2340
+ "orf",
2341
+ "arw",
2342
+ "dng",
2343
+ "nef",
2344
+ "rw2",
2345
+ "raf",
2346
+ "tif",
2347
+ "bmp",
2348
+ "icns",
2349
+ "jxr",
2350
+ "psd",
2351
+ "indd",
2352
+ "zip",
2353
+ "tar",
2354
+ "rar",
2355
+ "gz",
2356
+ "bz2",
2357
+ "7z",
2358
+ "dmg",
2359
+ "mp4",
2360
+ "mid",
2361
+ "mkv",
2362
+ "webm",
2363
+ "mov",
2364
+ "avi",
2365
+ "mpg",
2366
+ "mp2",
2367
+ "mp3",
2368
+ "m4a",
2369
+ "oga",
2370
+ "ogg",
2371
+ "ogv",
2372
+ "opus",
2373
+ "flac",
2374
+ "wav",
2375
+ "spx",
2376
+ "amr",
2377
+ "pdf",
2378
+ "epub",
2379
+ "elf",
2380
+ "macho",
2381
+ "exe",
2382
+ "swf",
2383
+ "rtf",
2384
+ "wasm",
2385
+ "woff",
2386
+ "woff2",
2387
+ "eot",
2388
+ "ttf",
2389
+ "otf",
2390
+ "ttc",
2391
+ "ico",
2392
+ "flv",
2393
+ "ps",
2394
+ "xz",
2395
+ "sqlite",
2396
+ "nes",
2397
+ "crx",
2398
+ "xpi",
2399
+ "cab",
2400
+ "deb",
2401
+ "ar",
2402
+ "rpm",
2403
+ "Z",
2404
+ "lz",
2405
+ "cfb",
2406
+ "mxf",
2407
+ "mts",
2408
+ "blend",
2409
+ "bpg",
2410
+ "docx",
2411
+ "pptx",
2412
+ "xlsx",
2413
+ "3gp",
2414
+ "3g2",
2415
+ "j2c",
2416
+ "jp2",
2417
+ "jpm",
2418
+ "jpx",
2419
+ "mj2",
2420
+ "aif",
2421
+ "qcp",
2422
+ "odt",
2423
+ "ods",
2424
+ "odp",
2425
+ "xml",
2426
+ "mobi",
2427
+ "heic",
2428
+ "cur",
2429
+ "ktx",
2430
+ "ape",
2431
+ "wv",
2432
+ "dcm",
2433
+ "ics",
2434
+ "glb",
2435
+ "pcap",
2436
+ "dsf",
2437
+ "lnk",
2438
+ "alias",
2439
+ "voc",
2440
+ "ac3",
2441
+ "m4v",
2442
+ "m4p",
2443
+ "m4b",
2444
+ "f4v",
2445
+ "f4p",
2446
+ "f4b",
2447
+ "f4a",
2448
+ "mie",
2449
+ "asf",
2450
+ "ogm",
2451
+ "ogx",
2452
+ "mpc",
2453
+ "arrow",
2454
+ "shp",
2455
+ "aac",
2456
+ "mp1",
2457
+ "it",
2458
+ "s3m",
2459
+ "xm",
2460
+ "skp",
2461
+ "avif",
2462
+ "eps",
2463
+ "lzh",
2464
+ "pgp",
2465
+ "asar",
2466
+ "stl",
2467
+ "chm",
2468
+ "3mf",
2469
+ "zst",
2470
+ "jxl",
2471
+ "vcf",
2472
+ "jls",
2473
+ "pst",
2474
+ "dwg",
2475
+ "parquet",
2476
+ "class",
2477
+ "arj",
2478
+ "cpio",
2479
+ "ace",
2480
+ "avro",
2481
+ "icc",
2482
+ "fbx",
2483
+ "vsdx",
2484
+ "vtt",
2485
+ "apk",
2486
+ "drc",
2487
+ "lz4",
2488
+ "potx",
2489
+ "xltx",
2490
+ "dotx",
2491
+ "xltm",
2492
+ "ott",
2493
+ "ots",
2494
+ "otp",
2495
+ "odg",
2496
+ "otg",
2497
+ "xlsm",
2498
+ "docm",
2499
+ "dotm",
2500
+ "potm",
2501
+ "pptm",
2502
+ "jar",
2503
+ "jmp",
2504
+ "rm",
2505
+ "sav",
2506
+ "ppsm",
2507
+ "ppsx",
2508
+ "tar.gz",
2509
+ "reg",
2510
+ "dat"
2511
+ ];
2512
+ var mimeTypes = [
2513
+ "image/jpeg",
2514
+ "image/png",
2515
+ "image/gif",
2516
+ "image/webp",
2517
+ "image/flif",
2518
+ "image/x-xcf",
2519
+ "image/x-canon-cr2",
2520
+ "image/x-canon-cr3",
2521
+ "image/tiff",
2522
+ "image/bmp",
2523
+ "image/vnd.ms-photo",
2524
+ "image/vnd.adobe.photoshop",
2525
+ "application/x-indesign",
2526
+ "application/epub+zip",
2527
+ "application/x-xpinstall",
2528
+ "application/vnd.ms-powerpoint.slideshow.macroenabled.12",
2529
+ "application/vnd.oasis.opendocument.text",
2530
+ "application/vnd.oasis.opendocument.spreadsheet",
2531
+ "application/vnd.oasis.opendocument.presentation",
2532
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
2533
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation",
2534
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
2535
+ "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
2536
+ "application/zip",
2537
+ "application/x-tar",
2538
+ "application/x-rar-compressed",
2539
+ "application/gzip",
2540
+ "application/x-bzip2",
2541
+ "application/x-7z-compressed",
2542
+ "application/x-apple-diskimage",
2543
+ "application/vnd.apache.arrow.file",
2544
+ "video/mp4",
2545
+ "audio/midi",
2546
+ "video/matroska",
2547
+ "video/webm",
2548
+ "video/quicktime",
2549
+ "video/vnd.avi",
2550
+ "audio/wav",
2551
+ "audio/qcelp",
2552
+ "audio/x-ms-asf",
2553
+ "video/x-ms-asf",
2554
+ "application/vnd.ms-asf",
2555
+ "video/mpeg",
2556
+ "video/3gpp",
2557
+ "audio/mpeg",
2558
+ "audio/mp4",
2559
+ // RFC 4337
2560
+ "video/ogg",
2561
+ "audio/ogg",
2562
+ "audio/ogg; codecs=opus",
2563
+ "application/ogg",
2564
+ "audio/flac",
2565
+ "audio/ape",
2566
+ "audio/wavpack",
2567
+ "audio/amr",
2568
+ "application/pdf",
2569
+ "application/x-elf",
2570
+ "application/x-mach-binary",
2571
+ "application/x-msdownload",
2572
+ "application/x-shockwave-flash",
2573
+ "application/rtf",
2574
+ "application/wasm",
2575
+ "font/woff",
2576
+ "font/woff2",
2577
+ "application/vnd.ms-fontobject",
2578
+ "font/ttf",
2579
+ "font/otf",
2580
+ "font/collection",
2581
+ "image/x-icon",
2582
+ "video/x-flv",
2583
+ "application/postscript",
2584
+ "application/eps",
2585
+ "application/x-xz",
2586
+ "application/x-sqlite3",
2587
+ "application/x-nintendo-nes-rom",
2588
+ "application/x-google-chrome-extension",
2589
+ "application/vnd.ms-cab-compressed",
2590
+ "application/x-deb",
2591
+ "application/x-unix-archive",
2592
+ "application/x-rpm",
2593
+ "application/x-compress",
2594
+ "application/x-lzip",
2595
+ "application/x-cfb",
2596
+ "application/x-mie",
2597
+ "application/mxf",
2598
+ "video/mp2t",
2599
+ "application/x-blender",
2600
+ "image/bpg",
2601
+ "image/j2c",
2602
+ "image/jp2",
2603
+ "image/jpx",
2604
+ "image/jpm",
2605
+ "image/mj2",
2606
+ "audio/aiff",
2607
+ "application/xml",
2608
+ "application/x-mobipocket-ebook",
2609
+ "image/heif",
2610
+ "image/heif-sequence",
2611
+ "image/heic",
2612
+ "image/heic-sequence",
2613
+ "image/icns",
2614
+ "image/ktx",
2615
+ "application/dicom",
2616
+ "audio/x-musepack",
2617
+ "text/calendar",
2618
+ "text/vcard",
2619
+ "text/vtt",
2620
+ "model/gltf-binary",
2621
+ "application/vnd.tcpdump.pcap",
2622
+ "audio/x-dsf",
2623
+ // Non-standard
2624
+ "application/x.ms.shortcut",
2625
+ // Invented by us
2626
+ "application/x.apple.alias",
2627
+ // Invented by us
2628
+ "audio/x-voc",
2629
+ "audio/vnd.dolby.dd-raw",
2630
+ "audio/x-m4a",
2631
+ "image/apng",
2632
+ "image/x-olympus-orf",
2633
+ "image/x-sony-arw",
2634
+ "image/x-adobe-dng",
2635
+ "image/x-nikon-nef",
2636
+ "image/x-panasonic-rw2",
2637
+ "image/x-fujifilm-raf",
2638
+ "video/x-m4v",
2639
+ "video/3gpp2",
2640
+ "application/x-esri-shape",
2641
+ "audio/aac",
2642
+ "audio/x-it",
2643
+ "audio/x-s3m",
2644
+ "audio/x-xm",
2645
+ "video/MP1S",
2646
+ "video/MP2P",
2647
+ "application/vnd.sketchup.skp",
2648
+ "image/avif",
2649
+ "application/x-lzh-compressed",
2650
+ "application/pgp-encrypted",
2651
+ "application/x-asar",
2652
+ "model/stl",
2653
+ "application/vnd.ms-htmlhelp",
2654
+ "model/3mf",
2655
+ "image/jxl",
2656
+ "application/zstd",
2657
+ "image/jls",
2658
+ "application/vnd.ms-outlook",
2659
+ "image/vnd.dwg",
2660
+ "application/vnd.apache.parquet",
2661
+ "application/java-vm",
2662
+ "application/x-arj",
2663
+ "application/x-cpio",
2664
+ "application/x-ace-compressed",
2665
+ "application/avro",
2666
+ "application/vnd.iccprofile",
2667
+ "application/x.autodesk.fbx",
2668
+ // Invented by us
2669
+ "application/vnd.visio",
2670
+ "application/vnd.android.package-archive",
2671
+ "application/vnd.google.draco",
2672
+ // Invented by us
2673
+ "application/x-lz4",
2674
+ // Invented by us
2675
+ "application/vnd.openxmlformats-officedocument.presentationml.template",
2676
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.template",
2677
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
2678
+ "application/vnd.ms-excel.template.macroenabled.12",
2679
+ "application/vnd.oasis.opendocument.text-template",
2680
+ "application/vnd.oasis.opendocument.spreadsheet-template",
2681
+ "application/vnd.oasis.opendocument.presentation-template",
2682
+ "application/vnd.oasis.opendocument.graphics",
2683
+ "application/vnd.oasis.opendocument.graphics-template",
2684
+ "application/vnd.ms-excel.sheet.macroenabled.12",
2685
+ "application/vnd.ms-word.document.macroenabled.12",
2686
+ "application/vnd.ms-word.template.macroenabled.12",
2687
+ "application/vnd.ms-powerpoint.template.macroenabled.12",
2688
+ "application/vnd.ms-powerpoint.presentation.macroenabled.12",
2689
+ "application/java-archive",
2690
+ "application/vnd.rn-realmedia",
2691
+ "application/x-spss-sav",
2692
+ "application/x-ms-regedit",
2693
+ "application/x-ft-windows-registry-hive",
2694
+ "application/x-jmp-data"
2695
+ ];
2696
+
2697
+ // ../../node_modules/file-type/core.js
2698
+ var reasonableDetectionSizeInBytes = 4100;
2699
+ async function fileTypeFromBlob(blob, options) {
2700
+ return new FileTypeParser(options).fromBlob(blob);
2701
+ }
2702
+ function getFileTypeFromMimeType(mimeType) {
2703
+ mimeType = mimeType.toLowerCase();
2704
+ switch (mimeType) {
2705
+ case "application/epub+zip":
2706
+ return {
2707
+ ext: "epub",
2708
+ mime: mimeType
2709
+ };
2710
+ case "application/vnd.oasis.opendocument.text":
2711
+ return {
2712
+ ext: "odt",
2713
+ mime: mimeType
2714
+ };
2715
+ case "application/vnd.oasis.opendocument.text-template":
2716
+ return {
2717
+ ext: "ott",
2718
+ mime: mimeType
2719
+ };
2720
+ case "application/vnd.oasis.opendocument.spreadsheet":
2721
+ return {
2722
+ ext: "ods",
2723
+ mime: mimeType
2724
+ };
2725
+ case "application/vnd.oasis.opendocument.spreadsheet-template":
2726
+ return {
2727
+ ext: "ots",
2728
+ mime: mimeType
2729
+ };
2730
+ case "application/vnd.oasis.opendocument.presentation":
2731
+ return {
2732
+ ext: "odp",
2733
+ mime: mimeType
2734
+ };
2735
+ case "application/vnd.oasis.opendocument.presentation-template":
2736
+ return {
2737
+ ext: "otp",
2738
+ mime: mimeType
2739
+ };
2740
+ case "application/vnd.oasis.opendocument.graphics":
2741
+ return {
2742
+ ext: "odg",
2743
+ mime: mimeType
2744
+ };
2745
+ case "application/vnd.oasis.opendocument.graphics-template":
2746
+ return {
2747
+ ext: "otg",
2748
+ mime: mimeType
2749
+ };
2750
+ case "application/vnd.openxmlformats-officedocument.presentationml.slideshow":
2751
+ return {
2752
+ ext: "ppsx",
2753
+ mime: mimeType
2754
+ };
2755
+ case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
2756
+ return {
2757
+ ext: "xlsx",
2758
+ mime: mimeType
2759
+ };
2760
+ case "application/vnd.ms-excel.sheet.macroenabled":
2761
+ return {
2762
+ ext: "xlsm",
2763
+ mime: "application/vnd.ms-excel.sheet.macroenabled.12"
2764
+ };
2765
+ case "application/vnd.openxmlformats-officedocument.spreadsheetml.template":
2766
+ return {
2767
+ ext: "xltx",
2768
+ mime: mimeType
2769
+ };
2770
+ case "application/vnd.ms-excel.template.macroenabled":
2771
+ return {
2772
+ ext: "xltm",
2773
+ mime: "application/vnd.ms-excel.template.macroenabled.12"
2774
+ };
2775
+ case "application/vnd.ms-powerpoint.slideshow.macroenabled":
2776
+ return {
2777
+ ext: "ppsm",
2778
+ mime: "application/vnd.ms-powerpoint.slideshow.macroenabled.12"
2779
+ };
2780
+ case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
2781
+ return {
2782
+ ext: "docx",
2783
+ mime: mimeType
2784
+ };
2785
+ case "application/vnd.ms-word.document.macroenabled":
2786
+ return {
2787
+ ext: "docm",
2788
+ mime: "application/vnd.ms-word.document.macroenabled.12"
2789
+ };
2790
+ case "application/vnd.openxmlformats-officedocument.wordprocessingml.template":
2791
+ return {
2792
+ ext: "dotx",
2793
+ mime: mimeType
2794
+ };
2795
+ case "application/vnd.ms-word.template.macroenabledtemplate":
2796
+ return {
2797
+ ext: "dotm",
2798
+ mime: "application/vnd.ms-word.template.macroenabled.12"
2799
+ };
2800
+ case "application/vnd.openxmlformats-officedocument.presentationml.template":
2801
+ return {
2802
+ ext: "potx",
2803
+ mime: mimeType
2804
+ };
2805
+ case "application/vnd.ms-powerpoint.template.macroenabled":
2806
+ return {
2807
+ ext: "potm",
2808
+ mime: "application/vnd.ms-powerpoint.template.macroenabled.12"
2809
+ };
2810
+ case "application/vnd.openxmlformats-officedocument.presentationml.presentation":
2811
+ return {
2812
+ ext: "pptx",
2813
+ mime: mimeType
2814
+ };
2815
+ case "application/vnd.ms-powerpoint.presentation.macroenabled":
2816
+ return {
2817
+ ext: "pptm",
2818
+ mime: "application/vnd.ms-powerpoint.presentation.macroenabled.12"
2819
+ };
2820
+ case "application/vnd.ms-visio.drawing":
2821
+ return {
2822
+ ext: "vsdx",
2823
+ mime: "application/vnd.visio"
2824
+ };
2825
+ case "application/vnd.ms-package.3dmanufacturing-3dmodel+xml":
2826
+ return {
2827
+ ext: "3mf",
2828
+ mime: "model/3mf"
2829
+ };
2830
+ default:
2831
+ }
2832
+ }
2833
+ function _check(buffer, headers, options) {
2834
+ options = {
2835
+ offset: 0,
2836
+ ...options
2837
+ };
2838
+ for (const [index, header] of headers.entries()) {
2839
+ if (options.mask) {
2840
+ if (header !== (options.mask[index] & buffer[index + options.offset])) {
2841
+ return false;
2842
+ }
2843
+ } else if (header !== buffer[index + options.offset]) {
2844
+ return false;
2845
+ }
2846
+ }
2847
+ return true;
2848
+ }
2849
+ var FileTypeParser = class {
2850
+ constructor(options) {
2851
+ // Detections with a high degree of certainty in identifying the correct file type
2852
+ __publicField(this, "detectConfident", async (tokenizer) => {
2853
+ this.buffer = new Uint8Array(reasonableDetectionSizeInBytes);
2854
+ if (tokenizer.fileInfo.size === void 0) {
2855
+ tokenizer.fileInfo.size = Number.MAX_SAFE_INTEGER;
2856
+ }
2857
+ this.tokenizer = tokenizer;
2858
+ await tokenizer.peekBuffer(this.buffer, { length: 32, mayBeLess: true });
2859
+ if (this.check([66, 77])) {
2860
+ return {
2861
+ ext: "bmp",
2862
+ mime: "image/bmp"
2863
+ };
2864
+ }
2865
+ if (this.check([11, 119])) {
2866
+ return {
2867
+ ext: "ac3",
2868
+ mime: "audio/vnd.dolby.dd-raw"
2869
+ };
2870
+ }
2871
+ if (this.check([120, 1])) {
2872
+ return {
2873
+ ext: "dmg",
2874
+ mime: "application/x-apple-diskimage"
2875
+ };
2876
+ }
2877
+ if (this.check([77, 90])) {
2878
+ return {
2879
+ ext: "exe",
2880
+ mime: "application/x-msdownload"
2881
+ };
2882
+ }
2883
+ if (this.check([37, 33])) {
2884
+ await tokenizer.peekBuffer(this.buffer, { length: 24, mayBeLess: true });
2885
+ if (this.checkString("PS-Adobe-", { offset: 2 }) && this.checkString(" EPSF-", { offset: 14 })) {
2886
+ return {
2887
+ ext: "eps",
2888
+ mime: "application/eps"
2889
+ };
2890
+ }
2891
+ return {
2892
+ ext: "ps",
2893
+ mime: "application/postscript"
2894
+ };
2895
+ }
2896
+ if (this.check([31, 160]) || this.check([31, 157])) {
2897
+ return {
2898
+ ext: "Z",
2899
+ mime: "application/x-compress"
2900
+ };
2901
+ }
2902
+ if (this.check([199, 113])) {
2903
+ return {
2904
+ ext: "cpio",
2905
+ mime: "application/x-cpio"
2906
+ };
2907
+ }
2908
+ if (this.check([96, 234])) {
2909
+ return {
2910
+ ext: "arj",
2911
+ mime: "application/x-arj"
2912
+ };
2913
+ }
2914
+ if (this.check([239, 187, 191])) {
2915
+ this.tokenizer.ignore(3);
2916
+ return this.detectConfident(tokenizer);
2917
+ }
2918
+ if (this.check([71, 73, 70])) {
2919
+ return {
2920
+ ext: "gif",
2921
+ mime: "image/gif"
2922
+ };
2923
+ }
2924
+ if (this.check([73, 73, 188])) {
2925
+ return {
2926
+ ext: "jxr",
2927
+ mime: "image/vnd.ms-photo"
2928
+ };
2929
+ }
2930
+ if (this.check([31, 139, 8])) {
2931
+ const gzipHandler = new GzipHandler(tokenizer);
2932
+ const stream = gzipHandler.inflate();
2933
+ let shouldCancelStream = true;
2934
+ try {
2935
+ let compressedFileType;
2936
+ try {
2937
+ compressedFileType = await this.fromStream(stream);
2938
+ } catch {
2939
+ shouldCancelStream = false;
2940
+ }
2941
+ if (compressedFileType && compressedFileType.ext === "tar") {
2942
+ return {
2943
+ ext: "tar.gz",
2944
+ mime: "application/gzip"
2945
+ };
2946
+ }
2947
+ } finally {
2948
+ if (shouldCancelStream) {
2949
+ await stream.cancel();
2950
+ }
2951
+ }
2952
+ return {
2953
+ ext: "gz",
2954
+ mime: "application/gzip"
2955
+ };
2956
+ }
2957
+ if (this.check([66, 90, 104])) {
2958
+ return {
2959
+ ext: "bz2",
2960
+ mime: "application/x-bzip2"
2961
+ };
2962
+ }
2963
+ if (this.checkString("ID3")) {
2964
+ await tokenizer.ignore(6);
2965
+ const id3HeaderLength = await tokenizer.readToken(uint32SyncSafeToken);
2966
+ if (tokenizer.position + id3HeaderLength > tokenizer.fileInfo.size) {
2967
+ return {
2968
+ ext: "mp3",
2969
+ mime: "audio/mpeg"
2970
+ };
2971
+ }
2972
+ await tokenizer.ignore(id3HeaderLength);
2973
+ return this.fromTokenizer(tokenizer);
2974
+ }
2975
+ if (this.checkString("MP+")) {
2976
+ return {
2977
+ ext: "mpc",
2978
+ mime: "audio/x-musepack"
2979
+ };
2980
+ }
2981
+ if ((this.buffer[0] === 67 || this.buffer[0] === 70) && this.check([87, 83], { offset: 1 })) {
2982
+ return {
2983
+ ext: "swf",
2984
+ mime: "application/x-shockwave-flash"
2985
+ };
2986
+ }
2987
+ if (this.check([255, 216, 255])) {
2988
+ if (this.check([247], { offset: 3 })) {
2989
+ return {
2990
+ ext: "jls",
2991
+ mime: "image/jls"
2992
+ };
2993
+ }
2994
+ return {
2995
+ ext: "jpg",
2996
+ mime: "image/jpeg"
2997
+ };
2998
+ }
2999
+ if (this.check([79, 98, 106, 1])) {
3000
+ return {
3001
+ ext: "avro",
3002
+ mime: "application/avro"
3003
+ };
3004
+ }
3005
+ if (this.checkString("FLIF")) {
3006
+ return {
3007
+ ext: "flif",
3008
+ mime: "image/flif"
3009
+ };
3010
+ }
3011
+ if (this.checkString("8BPS")) {
3012
+ return {
3013
+ ext: "psd",
3014
+ mime: "image/vnd.adobe.photoshop"
3015
+ };
3016
+ }
3017
+ if (this.checkString("MPCK")) {
3018
+ return {
3019
+ ext: "mpc",
3020
+ mime: "audio/x-musepack"
3021
+ };
3022
+ }
3023
+ if (this.checkString("FORM")) {
3024
+ return {
3025
+ ext: "aif",
3026
+ mime: "audio/aiff"
3027
+ };
3028
+ }
3029
+ if (this.checkString("icns", { offset: 0 })) {
3030
+ return {
3031
+ ext: "icns",
3032
+ mime: "image/icns"
3033
+ };
3034
+ }
3035
+ if (this.check([80, 75, 3, 4])) {
3036
+ let fileType;
3037
+ await new ZipHandler(tokenizer).unzip((zipHeader) => {
3038
+ switch (zipHeader.filename) {
3039
+ case "META-INF/mozilla.rsa":
3040
+ fileType = {
3041
+ ext: "xpi",
3042
+ mime: "application/x-xpinstall"
3043
+ };
3044
+ return {
3045
+ stop: true
3046
+ };
3047
+ case "META-INF/MANIFEST.MF":
3048
+ fileType = {
3049
+ ext: "jar",
3050
+ mime: "application/java-archive"
3051
+ };
3052
+ return {
3053
+ stop: true
3054
+ };
3055
+ case "mimetype":
3056
+ return {
3057
+ async handler(fileData) {
3058
+ const mimeType = new TextDecoder("utf-8").decode(fileData).trim();
3059
+ fileType = getFileTypeFromMimeType(mimeType);
3060
+ },
3061
+ stop: true
3062
+ };
3063
+ case "[Content_Types].xml":
3064
+ return {
3065
+ async handler(fileData) {
3066
+ let xmlContent = new TextDecoder("utf-8").decode(fileData);
3067
+ const endPos = xmlContent.indexOf('.main+xml"');
3068
+ if (endPos === -1) {
3069
+ const mimeType = "application/vnd.ms-package.3dmanufacturing-3dmodel+xml";
3070
+ if (xmlContent.includes(`ContentType="${mimeType}"`)) {
3071
+ fileType = getFileTypeFromMimeType(mimeType);
3072
+ }
3073
+ } else {
3074
+ xmlContent = xmlContent.slice(0, Math.max(0, endPos));
3075
+ const firstPos = xmlContent.lastIndexOf('"');
3076
+ const mimeType = xmlContent.slice(Math.max(0, firstPos + 1));
3077
+ fileType = getFileTypeFromMimeType(mimeType);
3078
+ }
3079
+ },
3080
+ stop: true
3081
+ };
3082
+ default:
3083
+ if (/classes\d*\.dex/.test(zipHeader.filename)) {
3084
+ fileType = {
3085
+ ext: "apk",
3086
+ mime: "application/vnd.android.package-archive"
3087
+ };
3088
+ return { stop: true };
3089
+ }
3090
+ return {};
3091
+ }
3092
+ }).catch((error) => {
3093
+ if (!(error instanceof EndOfStreamError)) {
3094
+ throw error;
3095
+ }
3096
+ });
3097
+ return fileType ?? {
3098
+ ext: "zip",
3099
+ mime: "application/zip"
3100
+ };
3101
+ }
3102
+ if (this.checkString("OggS")) {
3103
+ await tokenizer.ignore(28);
3104
+ const type = new Uint8Array(8);
3105
+ await tokenizer.readBuffer(type);
3106
+ if (_check(type, [79, 112, 117, 115, 72, 101, 97, 100])) {
3107
+ return {
3108
+ ext: "opus",
3109
+ mime: "audio/ogg; codecs=opus"
3110
+ };
3111
+ }
3112
+ if (_check(type, [128, 116, 104, 101, 111, 114, 97])) {
3113
+ return {
3114
+ ext: "ogv",
3115
+ mime: "video/ogg"
3116
+ };
3117
+ }
3118
+ if (_check(type, [1, 118, 105, 100, 101, 111, 0])) {
3119
+ return {
3120
+ ext: "ogm",
3121
+ mime: "video/ogg"
3122
+ };
3123
+ }
3124
+ if (_check(type, [127, 70, 76, 65, 67])) {
3125
+ return {
3126
+ ext: "oga",
3127
+ mime: "audio/ogg"
3128
+ };
3129
+ }
3130
+ if (_check(type, [83, 112, 101, 101, 120, 32, 32])) {
3131
+ return {
3132
+ ext: "spx",
3133
+ mime: "audio/ogg"
3134
+ };
3135
+ }
3136
+ if (_check(type, [1, 118, 111, 114, 98, 105, 115])) {
3137
+ return {
3138
+ ext: "ogg",
3139
+ mime: "audio/ogg"
3140
+ };
3141
+ }
3142
+ return {
3143
+ ext: "ogx",
3144
+ mime: "application/ogg"
3145
+ };
3146
+ }
3147
+ if (this.check([80, 75]) && (this.buffer[2] === 3 || this.buffer[2] === 5 || this.buffer[2] === 7) && (this.buffer[3] === 4 || this.buffer[3] === 6 || this.buffer[3] === 8)) {
3148
+ return {
3149
+ ext: "zip",
3150
+ mime: "application/zip"
3151
+ };
3152
+ }
3153
+ if (this.checkString("MThd")) {
3154
+ return {
3155
+ ext: "mid",
3156
+ mime: "audio/midi"
3157
+ };
3158
+ }
3159
+ if (this.checkString("wOFF") && (this.check([0, 1, 0, 0], { offset: 4 }) || this.checkString("OTTO", { offset: 4 }))) {
3160
+ return {
3161
+ ext: "woff",
3162
+ mime: "font/woff"
3163
+ };
3164
+ }
3165
+ if (this.checkString("wOF2") && (this.check([0, 1, 0, 0], { offset: 4 }) || this.checkString("OTTO", { offset: 4 }))) {
3166
+ return {
3167
+ ext: "woff2",
3168
+ mime: "font/woff2"
3169
+ };
3170
+ }
3171
+ if (this.check([212, 195, 178, 161]) || this.check([161, 178, 195, 212])) {
3172
+ return {
3173
+ ext: "pcap",
3174
+ mime: "application/vnd.tcpdump.pcap"
3175
+ };
3176
+ }
3177
+ if (this.checkString("DSD ")) {
3178
+ return {
3179
+ ext: "dsf",
3180
+ mime: "audio/x-dsf"
3181
+ // Non-standard
3182
+ };
3183
+ }
3184
+ if (this.checkString("LZIP")) {
3185
+ return {
3186
+ ext: "lz",
3187
+ mime: "application/x-lzip"
3188
+ };
3189
+ }
3190
+ if (this.checkString("fLaC")) {
3191
+ return {
3192
+ ext: "flac",
3193
+ mime: "audio/flac"
3194
+ };
3195
+ }
3196
+ if (this.check([66, 80, 71, 251])) {
3197
+ return {
3198
+ ext: "bpg",
3199
+ mime: "image/bpg"
3200
+ };
3201
+ }
3202
+ if (this.checkString("wvpk")) {
3203
+ return {
3204
+ ext: "wv",
3205
+ mime: "audio/wavpack"
3206
+ };
3207
+ }
3208
+ if (this.checkString("%PDF")) {
3209
+ return {
3210
+ ext: "pdf",
3211
+ mime: "application/pdf"
3212
+ };
3213
+ }
3214
+ if (this.check([0, 97, 115, 109])) {
3215
+ return {
3216
+ ext: "wasm",
3217
+ mime: "application/wasm"
3218
+ };
3219
+ }
3220
+ if (this.check([73, 73])) {
3221
+ const fileType = await this.readTiffHeader(false);
3222
+ if (fileType) {
3223
+ return fileType;
3224
+ }
3225
+ }
3226
+ if (this.check([77, 77])) {
3227
+ const fileType = await this.readTiffHeader(true);
3228
+ if (fileType) {
3229
+ return fileType;
3230
+ }
3231
+ }
3232
+ if (this.checkString("MAC ")) {
3233
+ return {
3234
+ ext: "ape",
3235
+ mime: "audio/ape"
3236
+ };
3237
+ }
3238
+ if (this.check([26, 69, 223, 163])) {
3239
+ async function readField() {
3240
+ const msb = await tokenizer.peekNumber(UINT8);
3241
+ let mask = 128;
3242
+ let ic = 0;
3243
+ while ((msb & mask) === 0 && mask !== 0) {
3244
+ ++ic;
3245
+ mask >>= 1;
3246
+ }
3247
+ const id = new Uint8Array(ic + 1);
3248
+ await tokenizer.readBuffer(id);
3249
+ return id;
3250
+ }
3251
+ async function readElement() {
3252
+ const idField = await readField();
3253
+ const lengthField = await readField();
3254
+ lengthField[0] ^= 128 >> lengthField.length - 1;
3255
+ const nrLength = Math.min(6, lengthField.length);
3256
+ const idView = new DataView(idField.buffer);
3257
+ const lengthView = new DataView(lengthField.buffer, lengthField.length - nrLength, nrLength);
3258
+ return {
3259
+ id: getUintBE(idView),
3260
+ len: getUintBE(lengthView)
3261
+ };
3262
+ }
3263
+ async function readChildren(children) {
3264
+ while (children > 0) {
3265
+ const element = await readElement();
3266
+ if (element.id === 17026) {
3267
+ const rawValue = await tokenizer.readToken(new StringType(element.len));
3268
+ return rawValue.replaceAll(/\00.*$/g, "");
3269
+ }
3270
+ await tokenizer.ignore(element.len);
3271
+ --children;
3272
+ }
3273
+ }
3274
+ const re = await readElement();
3275
+ const documentType = await readChildren(re.len);
3276
+ switch (documentType) {
3277
+ case "webm":
3278
+ return {
3279
+ ext: "webm",
3280
+ mime: "video/webm"
3281
+ };
3282
+ case "matroska":
3283
+ return {
3284
+ ext: "mkv",
3285
+ mime: "video/matroska"
3286
+ };
3287
+ default:
3288
+ return;
3289
+ }
3290
+ }
3291
+ if (this.checkString("SQLi")) {
3292
+ return {
3293
+ ext: "sqlite",
3294
+ mime: "application/x-sqlite3"
3295
+ };
3296
+ }
3297
+ if (this.check([78, 69, 83, 26])) {
3298
+ return {
3299
+ ext: "nes",
3300
+ mime: "application/x-nintendo-nes-rom"
3301
+ };
3302
+ }
3303
+ if (this.checkString("Cr24")) {
3304
+ return {
3305
+ ext: "crx",
3306
+ mime: "application/x-google-chrome-extension"
3307
+ };
3308
+ }
3309
+ if (this.checkString("MSCF") || this.checkString("ISc(")) {
3310
+ return {
3311
+ ext: "cab",
3312
+ mime: "application/vnd.ms-cab-compressed"
3313
+ };
3314
+ }
3315
+ if (this.check([237, 171, 238, 219])) {
3316
+ return {
3317
+ ext: "rpm",
3318
+ mime: "application/x-rpm"
3319
+ };
3320
+ }
3321
+ if (this.check([197, 208, 211, 198])) {
3322
+ return {
3323
+ ext: "eps",
3324
+ mime: "application/eps"
3325
+ };
3326
+ }
3327
+ if (this.check([40, 181, 47, 253])) {
3328
+ return {
3329
+ ext: "zst",
3330
+ mime: "application/zstd"
3331
+ };
3332
+ }
3333
+ if (this.check([127, 69, 76, 70])) {
3334
+ return {
3335
+ ext: "elf",
3336
+ mime: "application/x-elf"
3337
+ };
3338
+ }
3339
+ if (this.check([33, 66, 68, 78])) {
3340
+ return {
3341
+ ext: "pst",
3342
+ mime: "application/vnd.ms-outlook"
3343
+ };
3344
+ }
3345
+ if (this.checkString("PAR1") || this.checkString("PARE")) {
3346
+ return {
3347
+ ext: "parquet",
3348
+ mime: "application/vnd.apache.parquet"
3349
+ };
3350
+ }
3351
+ if (this.checkString("ttcf")) {
3352
+ return {
3353
+ ext: "ttc",
3354
+ mime: "font/collection"
3355
+ };
3356
+ }
3357
+ if (this.check([207, 250, 237, 254])) {
3358
+ return {
3359
+ ext: "macho",
3360
+ mime: "application/x-mach-binary"
3361
+ };
3362
+ }
3363
+ if (this.check([4, 34, 77, 24])) {
3364
+ return {
3365
+ ext: "lz4",
3366
+ mime: "application/x-lz4"
3367
+ // Invented by us
3368
+ };
3369
+ }
3370
+ if (this.checkString("regf")) {
3371
+ return {
3372
+ ext: "dat",
3373
+ mime: "application/x-ft-windows-registry-hive"
3374
+ };
3375
+ }
3376
+ if (this.checkString("$FL2") || this.checkString("$FL3")) {
3377
+ return {
3378
+ ext: "sav",
3379
+ mime: "application/x-spss-sav"
3380
+ };
3381
+ }
3382
+ if (this.check([79, 84, 84, 79, 0])) {
3383
+ return {
3384
+ ext: "otf",
3385
+ mime: "font/otf"
3386
+ };
3387
+ }
3388
+ if (this.checkString("#!AMR")) {
3389
+ return {
3390
+ ext: "amr",
3391
+ mime: "audio/amr"
3392
+ };
3393
+ }
3394
+ if (this.checkString("{\\rtf")) {
3395
+ return {
3396
+ ext: "rtf",
3397
+ mime: "application/rtf"
3398
+ };
3399
+ }
3400
+ if (this.check([70, 76, 86, 1])) {
3401
+ return {
3402
+ ext: "flv",
3403
+ mime: "video/x-flv"
3404
+ };
3405
+ }
3406
+ if (this.checkString("IMPM")) {
3407
+ return {
3408
+ ext: "it",
3409
+ mime: "audio/x-it"
3410
+ };
3411
+ }
3412
+ if (this.checkString("-lh0-", { offset: 2 }) || this.checkString("-lh1-", { offset: 2 }) || this.checkString("-lh2-", { offset: 2 }) || this.checkString("-lh3-", { offset: 2 }) || this.checkString("-lh4-", { offset: 2 }) || this.checkString("-lh5-", { offset: 2 }) || this.checkString("-lh6-", { offset: 2 }) || this.checkString("-lh7-", { offset: 2 }) || this.checkString("-lzs-", { offset: 2 }) || this.checkString("-lz4-", { offset: 2 }) || this.checkString("-lz5-", { offset: 2 }) || this.checkString("-lhd-", { offset: 2 })) {
3413
+ return {
3414
+ ext: "lzh",
3415
+ mime: "application/x-lzh-compressed"
3416
+ };
3417
+ }
3418
+ if (this.check([0, 0, 1, 186])) {
3419
+ if (this.check([33], { offset: 4, mask: [241] })) {
3420
+ return {
3421
+ ext: "mpg",
3422
+ // May also be .ps, .mpeg
3423
+ mime: "video/MP1S"
3424
+ };
3425
+ }
3426
+ if (this.check([68], { offset: 4, mask: [196] })) {
3427
+ return {
3428
+ ext: "mpg",
3429
+ // May also be .mpg, .m2p, .vob or .sub
3430
+ mime: "video/MP2P"
3431
+ };
3432
+ }
3433
+ }
3434
+ if (this.checkString("ITSF")) {
3435
+ return {
3436
+ ext: "chm",
3437
+ mime: "application/vnd.ms-htmlhelp"
3438
+ };
3439
+ }
3440
+ if (this.check([202, 254, 186, 190])) {
3441
+ return {
3442
+ ext: "class",
3443
+ mime: "application/java-vm"
3444
+ };
3445
+ }
3446
+ if (this.checkString(".RMF")) {
3447
+ return {
3448
+ ext: "rm",
3449
+ mime: "application/vnd.rn-realmedia"
3450
+ };
3451
+ }
3452
+ if (this.checkString("DRACO")) {
3453
+ return {
3454
+ ext: "drc",
3455
+ mime: "application/vnd.google.draco"
3456
+ // Invented by us
3457
+ };
3458
+ }
3459
+ if (this.check([253, 55, 122, 88, 90, 0])) {
3460
+ return {
3461
+ ext: "xz",
3462
+ mime: "application/x-xz"
3463
+ };
3464
+ }
3465
+ if (this.checkString("<?xml ")) {
3466
+ return {
3467
+ ext: "xml",
3468
+ mime: "application/xml"
3469
+ };
3470
+ }
3471
+ if (this.check([55, 122, 188, 175, 39, 28])) {
3472
+ return {
3473
+ ext: "7z",
3474
+ mime: "application/x-7z-compressed"
3475
+ };
3476
+ }
3477
+ if (this.check([82, 97, 114, 33, 26, 7]) && (this.buffer[6] === 0 || this.buffer[6] === 1)) {
3478
+ return {
3479
+ ext: "rar",
3480
+ mime: "application/x-rar-compressed"
3481
+ };
3482
+ }
3483
+ if (this.checkString("solid ")) {
3484
+ return {
3485
+ ext: "stl",
3486
+ mime: "model/stl"
3487
+ };
3488
+ }
3489
+ if (this.checkString("AC")) {
3490
+ const version = new StringType(4, "latin1").get(this.buffer, 2);
3491
+ if (version.match("^d*") && version >= 1e3 && version <= 1050) {
3492
+ return {
3493
+ ext: "dwg",
3494
+ mime: "image/vnd.dwg"
3495
+ };
3496
+ }
3497
+ }
3498
+ if (this.checkString("070707")) {
3499
+ return {
3500
+ ext: "cpio",
3501
+ mime: "application/x-cpio"
3502
+ };
3503
+ }
3504
+ if (this.checkString("BLENDER")) {
3505
+ return {
3506
+ ext: "blend",
3507
+ mime: "application/x-blender"
3508
+ };
3509
+ }
3510
+ if (this.checkString("!<arch>")) {
3511
+ await tokenizer.ignore(8);
3512
+ const string = await tokenizer.readToken(new StringType(13, "ascii"));
3513
+ if (string === "debian-binary") {
3514
+ return {
3515
+ ext: "deb",
3516
+ mime: "application/x-deb"
3517
+ };
3518
+ }
3519
+ return {
3520
+ ext: "ar",
3521
+ mime: "application/x-unix-archive"
3522
+ };
3523
+ }
3524
+ if (this.checkString("WEBVTT") && // One of LF, CR, tab, space, or end of file must follow "WEBVTT" per the spec (see `fixture/fixture-vtt-*.vtt` for examples). Note that `\0` is technically the null character (there is no such thing as an EOF character). However, checking for `\0` gives us the same result as checking for the end of the stream.
3525
+ ["\n", "\r", " ", " ", "\0"].some((char7) => this.checkString(char7, { offset: 6 }))) {
3526
+ return {
3527
+ ext: "vtt",
3528
+ mime: "text/vtt"
3529
+ };
3530
+ }
3531
+ if (this.check([137, 80, 78, 71, 13, 10, 26, 10])) {
3532
+ await tokenizer.ignore(8);
3533
+ async function readChunkHeader() {
3534
+ return {
3535
+ length: await tokenizer.readToken(INT32_BE),
3536
+ type: await tokenizer.readToken(new StringType(4, "latin1"))
3537
+ };
3538
+ }
3539
+ do {
3540
+ const chunk = await readChunkHeader();
3541
+ if (chunk.length < 0) {
3542
+ return;
3543
+ }
3544
+ switch (chunk.type) {
3545
+ case "IDAT":
3546
+ return {
3547
+ ext: "png",
3548
+ mime: "image/png"
3549
+ };
3550
+ case "acTL":
3551
+ return {
3552
+ ext: "apng",
3553
+ mime: "image/apng"
3554
+ };
3555
+ default:
3556
+ await tokenizer.ignore(chunk.length + 4);
3557
+ }
3558
+ } while (tokenizer.position + 8 < tokenizer.fileInfo.size);
3559
+ return {
3560
+ ext: "png",
3561
+ mime: "image/png"
3562
+ };
3563
+ }
3564
+ if (this.check([65, 82, 82, 79, 87, 49, 0, 0])) {
3565
+ return {
3566
+ ext: "arrow",
3567
+ mime: "application/vnd.apache.arrow.file"
3568
+ };
3569
+ }
3570
+ if (this.check([103, 108, 84, 70, 2, 0, 0, 0])) {
3571
+ return {
3572
+ ext: "glb",
3573
+ mime: "model/gltf-binary"
3574
+ };
3575
+ }
3576
+ if (this.check([102, 114, 101, 101], { offset: 4 }) || this.check([109, 100, 97, 116], { offset: 4 }) || this.check([109, 111, 111, 118], { offset: 4 }) || this.check([119, 105, 100, 101], { offset: 4 })) {
3577
+ return {
3578
+ ext: "mov",
3579
+ mime: "video/quicktime"
3580
+ };
3581
+ }
3582
+ if (this.check([73, 73, 82, 79, 8, 0, 0, 0, 24])) {
3583
+ return {
3584
+ ext: "orf",
3585
+ mime: "image/x-olympus-orf"
3586
+ };
3587
+ }
3588
+ if (this.checkString("gimp xcf ")) {
3589
+ return {
3590
+ ext: "xcf",
3591
+ mime: "image/x-xcf"
3592
+ };
3593
+ }
3594
+ if (this.checkString("ftyp", { offset: 4 }) && (this.buffer[8] & 96) !== 0) {
3595
+ const brandMajor = new StringType(4, "latin1").get(this.buffer, 8).replace("\0", " ").trim();
3596
+ switch (brandMajor) {
3597
+ case "avif":
3598
+ case "avis":
3599
+ return { ext: "avif", mime: "image/avif" };
3600
+ case "mif1":
3601
+ return { ext: "heic", mime: "image/heif" };
3602
+ case "msf1":
3603
+ return { ext: "heic", mime: "image/heif-sequence" };
3604
+ case "heic":
3605
+ case "heix":
3606
+ return { ext: "heic", mime: "image/heic" };
3607
+ case "hevc":
3608
+ case "hevx":
3609
+ return { ext: "heic", mime: "image/heic-sequence" };
3610
+ case "qt":
3611
+ return { ext: "mov", mime: "video/quicktime" };
3612
+ case "M4V":
3613
+ case "M4VH":
3614
+ case "M4VP":
3615
+ return { ext: "m4v", mime: "video/x-m4v" };
3616
+ case "M4P":
3617
+ return { ext: "m4p", mime: "video/mp4" };
3618
+ case "M4B":
3619
+ return { ext: "m4b", mime: "audio/mp4" };
3620
+ case "M4A":
3621
+ return { ext: "m4a", mime: "audio/x-m4a" };
3622
+ case "F4V":
3623
+ return { ext: "f4v", mime: "video/mp4" };
3624
+ case "F4P":
3625
+ return { ext: "f4p", mime: "video/mp4" };
3626
+ case "F4A":
3627
+ return { ext: "f4a", mime: "audio/mp4" };
3628
+ case "F4B":
3629
+ return { ext: "f4b", mime: "audio/mp4" };
3630
+ case "crx":
3631
+ return { ext: "cr3", mime: "image/x-canon-cr3" };
3632
+ default:
3633
+ if (brandMajor.startsWith("3g")) {
3634
+ if (brandMajor.startsWith("3g2")) {
3635
+ return { ext: "3g2", mime: "video/3gpp2" };
3636
+ }
3637
+ return { ext: "3gp", mime: "video/3gpp" };
3638
+ }
3639
+ return { ext: "mp4", mime: "video/mp4" };
3640
+ }
3641
+ }
3642
+ if (this.checkString("REGEDIT4\r\n")) {
3643
+ return {
3644
+ ext: "reg",
3645
+ mime: "application/x-ms-regedit"
3646
+ };
3647
+ }
3648
+ if (this.check([82, 73, 70, 70])) {
3649
+ if (this.checkString("WEBP", { offset: 8 })) {
3650
+ return {
3651
+ ext: "webp",
3652
+ mime: "image/webp"
3653
+ };
3654
+ }
3655
+ if (this.check([65, 86, 73], { offset: 8 })) {
3656
+ return {
3657
+ ext: "avi",
3658
+ mime: "video/vnd.avi"
3659
+ };
3660
+ }
3661
+ if (this.check([87, 65, 86, 69], { offset: 8 })) {
3662
+ return {
3663
+ ext: "wav",
3664
+ mime: "audio/wav"
3665
+ };
3666
+ }
3667
+ if (this.check([81, 76, 67, 77], { offset: 8 })) {
3668
+ return {
3669
+ ext: "qcp",
3670
+ mime: "audio/qcelp"
3671
+ };
3672
+ }
3673
+ }
3674
+ if (this.check([73, 73, 85, 0, 24, 0, 0, 0, 136, 231, 116, 216])) {
3675
+ return {
3676
+ ext: "rw2",
3677
+ mime: "image/x-panasonic-rw2"
3678
+ };
3679
+ }
3680
+ if (this.check([48, 38, 178, 117, 142, 102, 207, 17, 166, 217])) {
3681
+ async function readHeader() {
3682
+ const guid = new Uint8Array(16);
3683
+ await tokenizer.readBuffer(guid);
3684
+ return {
3685
+ id: guid,
3686
+ size: Number(await tokenizer.readToken(UINT64_LE))
3687
+ };
3688
+ }
3689
+ await tokenizer.ignore(30);
3690
+ while (tokenizer.position + 24 < tokenizer.fileInfo.size) {
3691
+ const header = await readHeader();
3692
+ let payload = header.size - 24;
3693
+ if (_check(header.id, [145, 7, 220, 183, 183, 169, 207, 17, 142, 230, 0, 192, 12, 32, 83, 101])) {
3694
+ const typeId = new Uint8Array(16);
3695
+ payload -= await tokenizer.readBuffer(typeId);
3696
+ if (_check(typeId, [64, 158, 105, 248, 77, 91, 207, 17, 168, 253, 0, 128, 95, 92, 68, 43])) {
3697
+ return {
3698
+ ext: "asf",
3699
+ mime: "audio/x-ms-asf"
3700
+ };
3701
+ }
3702
+ if (_check(typeId, [192, 239, 25, 188, 77, 91, 207, 17, 168, 253, 0, 128, 95, 92, 68, 43])) {
3703
+ return {
3704
+ ext: "asf",
3705
+ mime: "video/x-ms-asf"
3706
+ };
3707
+ }
3708
+ break;
215
3709
  }
3710
+ await tokenizer.ignore(payload);
216
3711
  }
217
- };
218
- xhr.onerror = () => {
219
- reject(new Error(`Upload failed: ${xhr.statusText}`));
220
- };
221
- xhr.onload = () => {
222
- try {
223
- if (xhr.status < 200 || xhr.status >= 300) {
224
- const errorText = xhr.responseText || xhr.statusText;
225
- reject(new Error(`Upload failed: ${errorText}`));
3712
+ return {
3713
+ ext: "asf",
3714
+ mime: "application/vnd.ms-asf"
3715
+ };
3716
+ }
3717
+ if (this.check([171, 75, 84, 88, 32, 49, 49, 187, 13, 10, 26, 10])) {
3718
+ return {
3719
+ ext: "ktx",
3720
+ mime: "image/ktx"
3721
+ };
3722
+ }
3723
+ if ((this.check([126, 16, 4]) || this.check([126, 24, 4])) && this.check([48, 77, 73, 69], { offset: 4 })) {
3724
+ return {
3725
+ ext: "mie",
3726
+ mime: "application/x-mie"
3727
+ };
3728
+ }
3729
+ if (this.check([39, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], { offset: 2 })) {
3730
+ return {
3731
+ ext: "shp",
3732
+ mime: "application/x-esri-shape"
3733
+ };
3734
+ }
3735
+ if (this.check([255, 79, 255, 81])) {
3736
+ return {
3737
+ ext: "j2c",
3738
+ mime: "image/j2c"
3739
+ };
3740
+ }
3741
+ if (this.check([0, 0, 0, 12, 106, 80, 32, 32, 13, 10, 135, 10])) {
3742
+ await tokenizer.ignore(20);
3743
+ const type = await tokenizer.readToken(new StringType(4, "ascii"));
3744
+ switch (type) {
3745
+ case "jp2 ":
3746
+ return {
3747
+ ext: "jp2",
3748
+ mime: "image/jp2"
3749
+ };
3750
+ case "jpx ":
3751
+ return {
3752
+ ext: "jpx",
3753
+ mime: "image/jpx"
3754
+ };
3755
+ case "jpm ":
3756
+ return {
3757
+ ext: "jpm",
3758
+ mime: "image/jpm"
3759
+ };
3760
+ case "mjp2":
3761
+ return {
3762
+ ext: "mj2",
3763
+ mime: "image/mj2"
3764
+ };
3765
+ default:
226
3766
  return;
3767
+ }
3768
+ }
3769
+ if (this.check([255, 10]) || this.check([0, 0, 0, 12, 74, 88, 76, 32, 13, 10, 135, 10])) {
3770
+ return {
3771
+ ext: "jxl",
3772
+ mime: "image/jxl"
3773
+ };
3774
+ }
3775
+ if (this.check([254, 255])) {
3776
+ if (this.checkString("<?xml ", { offset: 2, encoding: "utf-16be" })) {
3777
+ return {
3778
+ ext: "xml",
3779
+ mime: "application/xml"
3780
+ };
3781
+ }
3782
+ return void 0;
3783
+ }
3784
+ if (this.check([208, 207, 17, 224, 161, 177, 26, 225])) {
3785
+ return {
3786
+ ext: "cfb",
3787
+ mime: "application/x-cfb"
3788
+ };
3789
+ }
3790
+ await tokenizer.peekBuffer(this.buffer, { length: Math.min(256, tokenizer.fileInfo.size), mayBeLess: true });
3791
+ if (this.check([97, 99, 115, 112], { offset: 36 })) {
3792
+ return {
3793
+ ext: "icc",
3794
+ mime: "application/vnd.iccprofile"
3795
+ };
3796
+ }
3797
+ if (this.checkString("**ACE", { offset: 7 }) && this.checkString("**", { offset: 12 })) {
3798
+ return {
3799
+ ext: "ace",
3800
+ mime: "application/x-ace-compressed"
3801
+ };
3802
+ }
3803
+ if (this.checkString("BEGIN:")) {
3804
+ if (this.checkString("VCARD", { offset: 6 })) {
3805
+ return {
3806
+ ext: "vcf",
3807
+ mime: "text/vcard"
3808
+ };
3809
+ }
3810
+ if (this.checkString("VCALENDAR", { offset: 6 })) {
3811
+ return {
3812
+ ext: "ics",
3813
+ mime: "text/calendar"
3814
+ };
3815
+ }
3816
+ }
3817
+ if (this.checkString("FUJIFILMCCD-RAW")) {
3818
+ return {
3819
+ ext: "raf",
3820
+ mime: "image/x-fujifilm-raf"
3821
+ };
3822
+ }
3823
+ if (this.checkString("Extended Module:")) {
3824
+ return {
3825
+ ext: "xm",
3826
+ mime: "audio/x-xm"
3827
+ };
3828
+ }
3829
+ if (this.checkString("Creative Voice File")) {
3830
+ return {
3831
+ ext: "voc",
3832
+ mime: "audio/x-voc"
3833
+ };
3834
+ }
3835
+ if (this.check([4, 0, 0, 0]) && this.buffer.length >= 16) {
3836
+ const jsonSize = new DataView(this.buffer.buffer).getUint32(12, true);
3837
+ if (jsonSize > 12 && this.buffer.length >= jsonSize + 16) {
3838
+ try {
3839
+ const header = new TextDecoder().decode(this.buffer.subarray(16, jsonSize + 16));
3840
+ const json = JSON.parse(header);
3841
+ if (json.files) {
3842
+ return {
3843
+ ext: "asar",
3844
+ mime: "application/x-asar"
3845
+ };
3846
+ }
3847
+ } catch {
227
3848
  }
228
- const newResponse = JSON.parse(xhr.responseText);
229
- const response = {
230
- success: true,
231
- file_no: newResponse.file_no || newResponse.id,
232
- name: newResponse.name,
233
- url: newResponse.url,
234
- file_size: newResponse.size,
235
- format: newResponse.format,
236
- width: newResponse.width,
237
- height: newResponse.height,
238
- created_at: newResponse.created_at,
239
- path: newResponse.path,
240
- workspace_no: newResponse.workspace_id,
241
- isDuplicate: newResponse.is_duplicate || false
3849
+ }
3850
+ }
3851
+ if (this.check([6, 14, 43, 52, 2, 5, 1, 1, 13, 1, 2, 1, 1, 2])) {
3852
+ return {
3853
+ ext: "mxf",
3854
+ mime: "application/mxf"
3855
+ };
3856
+ }
3857
+ if (this.checkString("SCRM", { offset: 44 })) {
3858
+ return {
3859
+ ext: "s3m",
3860
+ mime: "audio/x-s3m"
3861
+ };
3862
+ }
3863
+ if (this.check([71]) && this.check([71], { offset: 188 })) {
3864
+ return {
3865
+ ext: "mts",
3866
+ mime: "video/mp2t"
3867
+ };
3868
+ }
3869
+ if (this.check([71], { offset: 4 }) && this.check([71], { offset: 196 })) {
3870
+ return {
3871
+ ext: "mts",
3872
+ mime: "video/mp2t"
3873
+ };
3874
+ }
3875
+ if (this.check([66, 79, 79, 75, 77, 79, 66, 73], { offset: 60 })) {
3876
+ return {
3877
+ ext: "mobi",
3878
+ mime: "application/x-mobipocket-ebook"
3879
+ };
3880
+ }
3881
+ if (this.check([68, 73, 67, 77], { offset: 128 })) {
3882
+ return {
3883
+ ext: "dcm",
3884
+ mime: "application/dicom"
3885
+ };
3886
+ }
3887
+ if (this.check([76, 0, 0, 0, 1, 20, 2, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70])) {
3888
+ return {
3889
+ ext: "lnk",
3890
+ mime: "application/x.ms.shortcut"
3891
+ // Invented by us
3892
+ };
3893
+ }
3894
+ if (this.check([98, 111, 111, 107, 0, 0, 0, 0, 109, 97, 114, 107, 0, 0, 0, 0])) {
3895
+ return {
3896
+ ext: "alias",
3897
+ mime: "application/x.apple.alias"
3898
+ // Invented by us
3899
+ };
3900
+ }
3901
+ if (this.checkString("Kaydara FBX Binary \0")) {
3902
+ return {
3903
+ ext: "fbx",
3904
+ mime: "application/x.autodesk.fbx"
3905
+ // Invented by us
3906
+ };
3907
+ }
3908
+ if (this.check([76, 80], { offset: 34 }) && (this.check([0, 0, 1], { offset: 8 }) || this.check([1, 0, 2], { offset: 8 }) || this.check([2, 0, 2], { offset: 8 }))) {
3909
+ return {
3910
+ ext: "eot",
3911
+ mime: "application/vnd.ms-fontobject"
3912
+ };
3913
+ }
3914
+ if (this.check([6, 6, 237, 245, 216, 29, 70, 229, 189, 49, 239, 231, 254, 116, 183, 29])) {
3915
+ return {
3916
+ ext: "indd",
3917
+ mime: "application/x-indesign"
3918
+ };
3919
+ }
3920
+ if (this.check([255, 255, 0, 0, 7, 0, 0, 0, 4, 0, 0, 0, 1, 0, 1, 0]) || this.check([0, 0, 255, 255, 0, 0, 0, 7, 0, 0, 0, 4, 0, 1, 0, 1])) {
3921
+ return {
3922
+ ext: "jmp",
3923
+ mime: "application/x-jmp-data"
3924
+ };
3925
+ }
3926
+ await tokenizer.peekBuffer(this.buffer, { length: Math.min(512, tokenizer.fileInfo.size), mayBeLess: true });
3927
+ if (this.checkString("ustar", { offset: 257 }) && (this.checkString("\0", { offset: 262 }) || this.checkString(" ", { offset: 262 })) || this.check([0, 0, 0, 0, 0, 0], { offset: 257 }) && tarHeaderChecksumMatches(this.buffer)) {
3928
+ return {
3929
+ ext: "tar",
3930
+ mime: "application/x-tar"
3931
+ };
3932
+ }
3933
+ if (this.check([255, 254])) {
3934
+ const encoding = "utf-16le";
3935
+ if (this.checkString("<?xml ", { offset: 2, encoding })) {
3936
+ return {
3937
+ ext: "xml",
3938
+ mime: "application/xml"
242
3939
  };
243
- resolve(response);
244
- } catch (error) {
245
- reject(new Error("Failed to parse response"));
246
3940
  }
247
- };
248
- const endpoint = `${this.baseUrl}/uploads`;
249
- const formData = new FormData();
250
- formData.append("file", params.file);
251
- formData.append("file_name", params.file.name);
252
- if (params.folderPath) {
253
- formData.append("folder", params.folderPath);
3941
+ if (this.check([255, 14], { offset: 2 }) && this.checkString("SketchUp Model", { offset: 4, encoding })) {
3942
+ return {
3943
+ ext: "skp",
3944
+ mime: "application/vnd.sketchup.skp"
3945
+ };
3946
+ }
3947
+ if (this.checkString("Windows Registry Editor Version 5.00\r\n", { offset: 2, encoding })) {
3948
+ return {
3949
+ ext: "reg",
3950
+ mime: "application/x-ms-regedit"
3951
+ };
3952
+ }
3953
+ return void 0;
254
3954
  }
255
- if (params.settings?.tags?.length) {
256
- formData.append("tags", params.settings.tags.join(","));
3955
+ if (this.checkString("-----BEGIN PGP MESSAGE-----")) {
3956
+ return {
3957
+ ext: "pgp",
3958
+ mime: "application/pgp-encrypted"
3959
+ };
257
3960
  }
258
- if (params.settings?.pretransformations) {
259
- formData.append("transform", params.settings.pretransformations);
3961
+ });
3962
+ // Detections with limited supporting data, resulting in a higher likelihood of false positives
3963
+ __publicField(this, "detectImprecise", async (tokenizer) => {
3964
+ this.buffer = new Uint8Array(reasonableDetectionSizeInBytes);
3965
+ await tokenizer.peekBuffer(this.buffer, { length: Math.min(8, tokenizer.fileInfo.size), mayBeLess: true });
3966
+ if (this.check([0, 0, 1, 186]) || this.check([0, 0, 1, 179])) {
3967
+ return {
3968
+ ext: "mpg",
3969
+ mime: "video/mpeg"
3970
+ };
260
3971
  }
261
- if (params.settings?.custom_id) {
262
- formData.append("custom_id", params.settings.custom_id);
3972
+ if (this.check([0, 1, 0, 0, 0])) {
3973
+ return {
3974
+ ext: "ttf",
3975
+ mime: "font/ttf"
3976
+ };
3977
+ }
3978
+ if (this.check([0, 0, 1, 0])) {
3979
+ return {
3980
+ ext: "ico",
3981
+ mime: "image/x-icon"
3982
+ };
3983
+ }
3984
+ if (this.check([0, 0, 2, 0])) {
3985
+ return {
3986
+ ext: "cur",
3987
+ mime: "image/x-icon"
3988
+ };
3989
+ }
3990
+ await tokenizer.peekBuffer(this.buffer, { length: Math.min(2 + this.options.mpegOffsetTolerance, tokenizer.fileInfo.size), mayBeLess: true });
3991
+ if (this.buffer.length >= 2 + this.options.mpegOffsetTolerance) {
3992
+ for (let depth = 0; depth <= this.options.mpegOffsetTolerance; ++depth) {
3993
+ const type = this.scanMpeg(depth);
3994
+ if (type) {
3995
+ return type;
3996
+ }
3997
+ }
263
3998
  }
264
- xhr.open("POST", endpoint);
265
- xhr.setRequestHeader("Authorization", `Bearer ${this.apiKey}`);
266
- xhr.setRequestHeader("accept", "application/json");
267
- xhr.send(formData);
268
3999
  });
4000
+ this.options = {
4001
+ mpegOffsetTolerance: 0,
4002
+ ...options
4003
+ };
4004
+ this.detectors = [
4005
+ ...options?.customDetectors ?? [],
4006
+ { id: "core", detect: this.detectConfident },
4007
+ { id: "core.imprecise", detect: this.detectImprecise }
4008
+ ];
4009
+ this.tokenizerOptions = {
4010
+ abortSignal: options?.signal
4011
+ };
269
4012
  }
270
- };
271
-
272
- // src/utils/helpers.ts
273
- function generateId() {
274
- if (typeof crypto !== "undefined" && "randomUUID" in crypto) {
275
- return crypto.randomUUID();
276
- }
277
- return "id-" + Math.random().toString(36).slice(2, 11);
278
- }
279
- function resolveIcon(renderer) {
280
- if (typeof renderer === "function") {
281
- return resolveIcon(renderer());
282
- }
283
- if (typeof renderer === "string") {
284
- const template = document.createElement("template");
285
- template.innerHTML = renderer.trim();
286
- return template.content.firstElementChild;
4013
+ async fromTokenizer(tokenizer) {
4014
+ const initialPosition = tokenizer.position;
4015
+ for (const detector of this.detectors) {
4016
+ const fileType = await detector.detect(tokenizer);
4017
+ if (fileType) {
4018
+ return fileType;
4019
+ }
4020
+ if (initialPosition !== tokenizer.position) {
4021
+ return void 0;
4022
+ }
4023
+ }
287
4024
  }
288
- return renderer ? renderer.cloneNode(true) : null;
289
- }
290
- function toCssVars(theme) {
291
- const variables = {};
292
- if (theme.accentColor) {
293
- variables["--ar-accent"] = theme.accentColor;
4025
+ async fromBuffer(input) {
4026
+ if (!(input instanceof Uint8Array || input instanceof ArrayBuffer)) {
4027
+ throw new TypeError(`Expected the \`input\` argument to be of type \`Uint8Array\` or \`ArrayBuffer\`, got \`${typeof input}\``);
4028
+ }
4029
+ const buffer = input instanceof Uint8Array ? input : new Uint8Array(input);
4030
+ if (!(buffer?.length > 1)) {
4031
+ return;
4032
+ }
4033
+ return this.fromTokenizer(fromBuffer(buffer, this.tokenizerOptions));
294
4034
  }
295
- if (theme.borderRadius !== void 0) {
296
- variables["--ar-radius"] = `${theme.borderRadius}px`;
4035
+ async fromBlob(blob) {
4036
+ const tokenizer = fromBlob(blob, this.tokenizerOptions);
4037
+ try {
4038
+ return await this.fromTokenizer(tokenizer);
4039
+ } finally {
4040
+ await tokenizer.close();
4041
+ }
297
4042
  }
298
- if (theme.fontFamily) {
299
- variables["--ar-font-family"] = theme.fontFamily;
4043
+ async fromStream(stream) {
4044
+ const tokenizer = fromWebStream(stream, this.tokenizerOptions);
4045
+ try {
4046
+ return await this.fromTokenizer(tokenizer);
4047
+ } finally {
4048
+ await tokenizer.close();
4049
+ }
300
4050
  }
301
- if (theme.dropzoneBackground) {
302
- variables["--ar-dropzone-bg"] = theme.dropzoneBackground;
4051
+ async toDetectionStream(stream, options) {
4052
+ const { sampleSize = reasonableDetectionSizeInBytes } = options;
4053
+ let detectedFileType;
4054
+ let firstChunk;
4055
+ const reader = stream.getReader({ mode: "byob" });
4056
+ try {
4057
+ const { value: chunk, done } = await reader.read(new Uint8Array(sampleSize));
4058
+ firstChunk = chunk;
4059
+ if (!done && chunk) {
4060
+ try {
4061
+ detectedFileType = await this.fromBuffer(chunk.subarray(0, sampleSize));
4062
+ } catch (error) {
4063
+ if (!(error instanceof EndOfStreamError)) {
4064
+ throw error;
4065
+ }
4066
+ detectedFileType = void 0;
4067
+ }
4068
+ }
4069
+ firstChunk = chunk;
4070
+ } finally {
4071
+ reader.releaseLock();
4072
+ }
4073
+ const transformStream = new TransformStream({
4074
+ async start(controller) {
4075
+ controller.enqueue(firstChunk);
4076
+ },
4077
+ transform(chunk, controller) {
4078
+ controller.enqueue(chunk);
4079
+ }
4080
+ });
4081
+ const newStream = stream.pipeThrough(transformStream);
4082
+ newStream.fileType = detectedFileType;
4083
+ return newStream;
303
4084
  }
304
- if (theme.dropzoneBorder) {
305
- variables["--ar-dropzone-border"] = theme.dropzoneBorder;
4085
+ check(header, options) {
4086
+ return _check(this.buffer, header, options);
306
4087
  }
307
- return variables;
308
- }
309
- function applyCssVariables(element, variables) {
310
- Object.entries(variables).forEach(([key, value]) => {
311
- element.style.setProperty(key, value);
312
- });
313
- }
314
- function getRelativeFolderPath(basePath, relativePath) {
315
- if (!relativePath) return void 0;
316
- const parts = relativePath.split("/").map((segment) => segment.trim()).filter((segment) => segment && segment !== ".");
317
- if (parts.length <= 1) {
318
- return void 0;
4088
+ checkString(header, options) {
4089
+ return this.check(stringToBytes(header, options?.encoding), options);
319
4090
  }
320
- const folderSegments = parts.slice(0, -1);
321
- if (basePath) {
322
- const baseSegments = basePath.split("/").map((segment) => segment.trim()).filter((segment) => segment && segment !== ".");
323
- let offset = 0;
324
- while (offset < baseSegments.length && offset < folderSegments.length && folderSegments[offset] === baseSegments[offset]) {
325
- offset += 1;
4091
+ async readTiffTag(bigEndian) {
4092
+ const tagId = await this.tokenizer.readToken(bigEndian ? UINT16_BE : UINT16_LE);
4093
+ this.tokenizer.ignore(10);
4094
+ switch (tagId) {
4095
+ case 50341:
4096
+ return {
4097
+ ext: "arw",
4098
+ mime: "image/x-sony-arw"
4099
+ };
4100
+ case 50706:
4101
+ return {
4102
+ ext: "dng",
4103
+ mime: "image/x-adobe-dng"
4104
+ };
4105
+ default:
326
4106
  }
327
- return offset < folderSegments.length ? folderSegments.slice(offset).join("/") : void 0;
328
- }
329
- return folderSegments.length ? folderSegments.join("/") : void 0;
330
- }
331
- function calculateBatchProgress(items) {
332
- if (items.length === 0) return 0;
333
- const total = items.reduce((acc, item) => acc + item.progress, 0);
334
- return Math.round(total / items.length);
335
- }
336
- var S3_URL_PATTERN = /^s3:\/\/([^/]+)\/(.+)$/i;
337
- function sanitizeBaseUrl(baseUrl) {
338
- if (!baseUrl) return void 0;
339
- const trimmed = baseUrl.trim();
340
- if (!trimmed) return void 0;
341
- return trimmed.replace(/\/+$/, "");
342
- }
343
- function extractWorkspaceFromUrl(url) {
344
- if (!url) return void 0;
345
- const s3Match = S3_URL_PATTERN.exec(url);
346
- if (s3Match) {
347
- return s3Match[1];
348
4107
  }
349
- try {
350
- const parsed = new URL(url);
351
- const firstSegment = parsed.pathname.replace(/^\/+/, "").split("/")[0];
352
- return firstSegment || void 0;
353
- } catch {
354
- return void 0;
355
- }
356
- }
357
- function extractPathFromUrl(url) {
358
- if (!url) return void 0;
359
- const s3Match = S3_URL_PATTERN.exec(url);
360
- if (s3Match) {
361
- return s3Match[2];
4108
+ async readTiffIFD(bigEndian) {
4109
+ const numberOfTags = await this.tokenizer.readToken(bigEndian ? UINT16_BE : UINT16_LE);
4110
+ for (let n = 0; n < numberOfTags; ++n) {
4111
+ const fileType = await this.readTiffTag(bigEndian);
4112
+ if (fileType) {
4113
+ return fileType;
4114
+ }
4115
+ }
362
4116
  }
363
- try {
364
- const parsed = new URL(url);
365
- const [, ...rest] = parsed.pathname.replace(/^\/+/, "").split("/");
366
- return rest.length ? rest.join("/") : void 0;
367
- } catch {
368
- return void 0;
4117
+ async readTiffHeader(bigEndian) {
4118
+ const version = (bigEndian ? UINT16_BE : UINT16_LE).get(this.buffer, 2);
4119
+ const ifdOffset = (bigEndian ? UINT32_BE : UINT32_LE).get(this.buffer, 4);
4120
+ if (version === 42) {
4121
+ if (ifdOffset >= 6) {
4122
+ if (this.checkString("CR", { offset: 8 })) {
4123
+ return {
4124
+ ext: "cr2",
4125
+ mime: "image/x-canon-cr2"
4126
+ };
4127
+ }
4128
+ if (ifdOffset >= 8) {
4129
+ const someId1 = (bigEndian ? UINT16_BE : UINT16_LE).get(this.buffer, 8);
4130
+ const someId2 = (bigEndian ? UINT16_BE : UINT16_LE).get(this.buffer, 10);
4131
+ if (someId1 === 28 && someId2 === 254 || someId1 === 31 && someId2 === 11) {
4132
+ return {
4133
+ ext: "nef",
4134
+ mime: "image/x-nikon-nef"
4135
+ };
4136
+ }
4137
+ }
4138
+ }
4139
+ await this.tokenizer.ignore(ifdOffset);
4140
+ const fileType = await this.readTiffIFD(bigEndian);
4141
+ return fileType ?? {
4142
+ ext: "tif",
4143
+ mime: "image/tiff"
4144
+ };
4145
+ }
4146
+ if (version === 43) {
4147
+ return {
4148
+ ext: "tif",
4149
+ mime: "image/tiff"
4150
+ };
4151
+ }
369
4152
  }
370
- }
371
- function buildAssetDeliveryUrl(baseUrl, workspace, path, fallback) {
372
- const sanitizedBase = sanitizeBaseUrl(baseUrl);
373
- if (!sanitizedBase || !workspace || !path) {
374
- return fallback;
4153
+ /**
4154
+ Scan check MPEG 1 or 2 Layer 3 header, or 'layer 0' for ADTS (MPEG sync-word 0xFFE).
4155
+
4156
+ @param offset - Offset to scan for sync-preamble.
4157
+ @returns {{ext: string, mime: string}}
4158
+ */
4159
+ scanMpeg(offset) {
4160
+ if (this.check([255, 224], { offset, mask: [255, 224] })) {
4161
+ if (this.check([16], { offset: offset + 1, mask: [22] })) {
4162
+ if (this.check([8], { offset: offset + 1, mask: [8] })) {
4163
+ return {
4164
+ ext: "aac",
4165
+ mime: "audio/aac"
4166
+ };
4167
+ }
4168
+ return {
4169
+ ext: "aac",
4170
+ mime: "audio/aac"
4171
+ };
4172
+ }
4173
+ if (this.check([2], { offset: offset + 1, mask: [6] })) {
4174
+ return {
4175
+ ext: "mp3",
4176
+ mime: "audio/mpeg"
4177
+ };
4178
+ }
4179
+ if (this.check([4], { offset: offset + 1, mask: [6] })) {
4180
+ return {
4181
+ ext: "mp2",
4182
+ mime: "audio/mpeg"
4183
+ };
4184
+ }
4185
+ if (this.check([6], { offset: offset + 1, mask: [6] })) {
4186
+ return {
4187
+ ext: "mp1",
4188
+ mime: "audio/mpeg"
4189
+ };
4190
+ }
4191
+ }
375
4192
  }
376
- const normalizedPath = path.split("/").filter(Boolean).map((segment) => encodeURIComponent(segment)).join("/");
377
- return `${sanitizedBase}/${workspace}/${normalizedPath}`.replace(/([^:]\/)\/+/g, "$1");
378
- }
4193
+ };
4194
+ var supportedExtensions = new Set(extensions);
4195
+ var supportedMimeTypes = new Set(mimeTypes);
379
4196
 
380
4197
  // src/core/uploader-controller.ts
381
- var import_file_type = require("file-type");
382
4198
  var DEFAULT_PARALLEL_UPLOADS = 4;
383
4199
  var MAX_FILE_SIZE_BYTES = 100 * 1024 * 1024;
384
4200
  var UploaderController = class extends EventTarget {
@@ -431,7 +4247,7 @@ var UploaderController = class extends EventTarget {
431
4247
  let mimeType = file.type;
432
4248
  if (!mimeType || mimeType === "application/octet-stream" || mimeType === "") {
433
4249
  try {
434
- const detected = await (0, import_file_type.fileTypeFromBlob)(file);
4250
+ const detected = await fileTypeFromBlob(file);
435
4251
  if (detected?.mime) {
436
4252
  mimeType = detected.mime;
437
4253
  Object.defineProperty(file, "type", {
@@ -3895,4 +7711,9 @@ function registerAutorenderUploaderElement() {
3895
7711
  registerAutorenderUploaderElement,
3896
7712
  resetFormatCache
3897
7713
  });
7714
+ /*! Bundled license information:
7715
+
7716
+ ieee754/index.js:
7717
+ (*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *)
7718
+ */
3898
7719
  //# sourceMappingURL=index.cjs.map