filens-preview 0.2.0 → 0.3.1

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.
Files changed (47) hide show
  1. package/README.md +69 -16
  2. package/dist/all-in-one/THIRD-PARTY-NOTICES.txt +1902 -63
  3. package/dist/all-in-one/archive/7zz.wasm +0 -0
  4. package/dist/all-in-one/assets/archive-worker-Cy3bEdVg.js +2 -0
  5. package/dist/all-in-one/filens.js +5063 -108925
  6. package/dist/all-in-one/index.html +12 -3
  7. package/dist/index.d.ts +7 -0
  8. package/dist/split/THIRD-PARTY-NOTICES.txt +1902 -63
  9. package/dist/split/archive/7zz.wasm +0 -0
  10. package/dist/split/assets/archive-worker-Cy3bEdVg.js +2 -0
  11. package/dist/split/assets/{iwork-worker-DiTOJG8f.js → iwork-worker-B9KPoDW3.js} +17 -17
  12. package/dist/split/chunks/archive-DMapcEqq.js +1 -0
  13. package/dist/split/chunks/browser-video-session-CGI8FpX_.js +1 -0
  14. package/dist/split/chunks/cad-BvXJNqHR.js +7 -0
  15. package/dist/split/chunks/core-BLayEJn5.js +17 -0
  16. package/dist/split/chunks/diagram-DlpgioZ9.js +1 -0
  17. package/dist/split/chunks/docx-Sii3GNtE.js +1 -0
  18. package/dist/split/chunks/ebook-CLCQfska.js +5 -0
  19. package/dist/split/chunks/index-BPK_cNTp.js +1 -0
  20. package/dist/split/chunks/index-DI_GyFX1.js +1 -0
  21. package/dist/split/chunks/iwork-Datv3D5d.js +4 -0
  22. package/dist/split/chunks/media-runtime-tb-Q4Sah.js +1 -0
  23. package/dist/split/chunks/mindmap-B_GYpiFO.js +1 -0
  24. package/dist/split/chunks/model3d-BsIQNF2D.js +55 -0
  25. package/dist/split/chunks/mp4box.all-Bw_Tlr0T-D0URDfA1.js +1 -0
  26. package/dist/split/chunks/panorama-CIdiLIwD.js +973 -0
  27. package/dist/split/chunks/pdf-Dzzffz3p.js +12 -0
  28. package/dist/split/chunks/vendor-CBCxJuSg.js +4115 -0
  29. package/dist/split/chunks/xlsx-D2NFYc3n.js +3 -0
  30. package/dist/split/converter-image.wasm +0 -0
  31. package/dist/split/filens.js +2 -4781
  32. package/dist/split/index.html +12 -3
  33. package/package.json +2 -2
  34. package/dist/split/chunks/archive-_cUUL2-3.js +0 -731
  35. package/dist/split/chunks/cad-Cyh8aipO.js +0 -2405
  36. package/dist/split/chunks/core-gp02JQ3r.js +0 -14182
  37. package/dist/split/chunks/diagram-rxvArV-1.js +0 -654
  38. package/dist/split/chunks/docx-ecvZsSWm.js +0 -299
  39. package/dist/split/chunks/ebook-5FyKWZ8s.js +0 -623
  40. package/dist/split/chunks/iwork-DlaehzuR.js +0 -772
  41. package/dist/split/chunks/media-runtime-DwW7eq4g.js +0 -48
  42. package/dist/split/chunks/mindmap-D9lNNDoa.js +0 -560
  43. package/dist/split/chunks/model3d-BtFT01ZH.js +0 -5093
  44. package/dist/split/chunks/panorama-Ci6DK6sa.js +0 -5960
  45. package/dist/split/chunks/pdf-CecYOWld.js +0 -17898
  46. package/dist/split/chunks/vendor-DvWhw-zP.js +0 -54471
  47. package/dist/split/chunks/xlsx-VJTu9XNS.js +0 -818
@@ -1,731 +0,0 @@
1
- var V = Object.defineProperty;
2
- var Z = (r, e, t) => e in r ? V(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var f = (r, e, t) => Z(r, typeof e != "symbol" ? e + "" : e, t);
4
- import { g as K } from "./vendor-DvWhw-zP.js";
5
- import { c as G, o as _ } from "./core-gp02JQ3r.js";
6
- const B = [
7
- {
8
- extensions: ["zip", "jar", "war", "ear", "apk"],
9
- family: "archive",
10
- driverId: "archive",
11
- targetFormat: "zip",
12
- contentTypes: ["application/zip", "application/x-zip-compressed", "application/java-archive", "application/vnd.android.package-archive"]
13
- },
14
- {
15
- extensions: ["tar"],
16
- family: "archive",
17
- driverId: "archive",
18
- targetFormat: "tar",
19
- contentTypes: ["application/x-tar"]
20
- },
21
- {
22
- extensions: ["tgz", "gz"],
23
- family: "archive",
24
- driverId: "archive",
25
- targetFormat: "gz",
26
- contentTypes: ["application/gzip", "application/x-gzip"]
27
- }
28
- ];
29
- class q {
30
- constructor(e, t = {}) {
31
- f(this, "listeners", {
32
- loading: /* @__PURE__ */ new Set(),
33
- rendered: /* @__PURE__ */ new Set(),
34
- error: /* @__PURE__ */ new Set(),
35
- statechange: /* @__PURE__ */ new Set(),
36
- warnings: /* @__PURE__ */ new Set()
37
- });
38
- f(this, "root");
39
- f(this, "options");
40
- f(this, "archiveStack", []);
41
- f(this, "activeEntry", null);
42
- f(this, "entryPreviewHost", null);
43
- f(this, "entryPreviewer", null);
44
- f(this, "entryPreviewUnsubscribes", []);
45
- f(this, "entryObjectUrl", null);
46
- f(this, "loadController", null);
47
- f(this, "entryController", null);
48
- f(this, "renderVersion", 0);
49
- f(this, "state", {
50
- loading: !1,
51
- error: null,
52
- family: "archive",
53
- warnings: [],
54
- capabilities: {
55
- archiveBrowse: !0,
56
- search: !0,
57
- download: !0
58
- },
59
- route: "/",
60
- entries: []
61
- });
62
- this.host = e, this.options = t, this.root = document.createElement("div"), this.root.className = "archivev-preview", this.host.replaceChildren(this.root);
63
- }
64
- async load(e, t) {
65
- var a, o, c, h;
66
- this.stopLoad();
67
- const n = new AbortController(), i = n.signal;
68
- this.loadController = n;
69
- const s = () => n.abort();
70
- (a = t.signal) == null || a.addEventListener("abort", s, { once: !0 }), i.addEventListener("abort", () => {
71
- var d;
72
- (d = t.signal) == null || d.removeEventListener("abort", s), this.loadController === n && (this.stopLoad(), this.state = { ...this.state, loading: !1, error: null, warnings: [], route: "/", entries: [] }, this.emit("statechange", this.state));
73
- }, { once: !0 }), this.state = {
74
- ...this.state,
75
- loading: !0,
76
- error: null,
77
- title: t.descriptor.name,
78
- warnings: [],
79
- route: "/",
80
- entries: []
81
- }, this.archiveStack = [], this.emit("loading", this.state), this.emit("statechange", this.state);
82
- try {
83
- (o = t.signal) != null && o.aborted && n.abort(), p(i);
84
- const d = new Uint8Array(await ie(e, { ...t, signal: i }));
85
- p(i);
86
- const l = t.descriptor.name ?? "archive", u = O(l, ((c = t.route) == null ? void 0 : c.sourceFormat) ?? t.descriptor.extension), v = await T(d, u, l, i);
87
- p(i), this.archiveStack = [v], this.state = {
88
- ...this.state,
89
- loading: !1,
90
- error: null
91
- }, this.setRoute("/"), this.emit("rendered", this.state), this.emit("statechange", this.state);
92
- } catch (d) {
93
- if (i.aborted) {
94
- (h = t.signal) != null && h.aborted && p(i);
95
- return;
96
- }
97
- this.stopLoad();
98
- const l = d instanceof Error ? d : new Error(String(d));
99
- throw this.state.loading = !1, this.state.error = l.message, this.emit("error", l), this.emit("statechange", this.state), l;
100
- }
101
- }
102
- destroy() {
103
- this.stopLoad(), this.state = { ...this.state, loading: !1, error: null, warnings: [], route: "/", entries: [] }, this.root.parentElement === this.host && this.host.replaceChildren();
104
- for (const e of Object.values(this.listeners)) e.clear();
105
- }
106
- stopLoad() {
107
- const e = this.loadController;
108
- this.loadController = null, e == null || e.abort(), this.closeEntryPreview(!1), this.archiveStack = [], this.renderVersion++, this.root.replaceChildren();
109
- }
110
- getState() {
111
- return {
112
- ...this.state,
113
- warnings: this.state.warnings.slice(),
114
- entries: this.state.entries.slice()
115
- };
116
- }
117
- on(e, t) {
118
- return this.listeners[e].add(t), () => {
119
- this.listeners[e].delete(t);
120
- };
121
- }
122
- render() {
123
- const e = ++this.renderVersion, t = () => e === this.renderVersion && !!(this.loadController && !this.loadController.signal.aborted), n = document.createElement("div");
124
- n.className = "archivev-summary", n.appendChild(this.createBreadcrumbs(t));
125
- const i = document.createElement("span");
126
- i.className = "archivev-item-count", i.textContent = `${this.state.entries.length} item${this.state.entries.length === 1 ? "" : "s"}`, n.appendChild(i);
127
- const s = document.createElement("div");
128
- s.className = "archivev-toolbar";
129
- const a = document.createElement("button");
130
- a.type = "button", a.className = "archivev-button", a.textContent = "Up", a.disabled = !Y(this.state.route), a.addEventListener("click", () => {
131
- t() && this.navigateUp();
132
- });
133
- const o = document.createElement("button");
134
- o.type = "button", o.className = "archivev-button", o.textContent = "Root", o.disabled = this.state.route === "/", o.addEventListener("click", () => {
135
- t() && this.setRoute("/");
136
- });
137
- const c = document.createElement("button");
138
- if (c.type = "button", c.className = "archivev-button", c.textContent = this.entryController ? "Back to archive" : "Back", c.disabled = !this.entryController && this.archiveStack.length <= 1, c.addEventListener("click", () => {
139
- t() && (this.entryController ? this.closeEntryPreview() : this.popArchive());
140
- }), s.append(c, a, o), this.activeEntry && this.entryPreviewHost) {
141
- this.root.replaceChildren(n, s, this.entryPreviewHost);
142
- return;
143
- }
144
- const h = document.createElement("table");
145
- h.className = "archivev-table", h.appendChild(se());
146
- const d = document.createElement("tbody");
147
- for (const l of this.state.entries) {
148
- const u = document.createElement("tr");
149
- u.className = "archivev-row", u.tabIndex = 0, u.dataset.type = l.type;
150
- const v = document.createElement("td");
151
- v.className = "archivev-name", v.textContent = l.name, v.dataset.type = l.type, u.appendChild(v);
152
- const w = document.createElement("td");
153
- w.className = "archivev-type", w.textContent = l.type, u.appendChild(w);
154
- const E = document.createElement("td");
155
- E.className = "archivev-size", E.textContent = l.type === "directory" ? "" : ae(l.size ?? 0), u.appendChild(E);
156
- const y = document.createElement("td");
157
- y.className = "archivev-modified", y.textContent = l.modified ? new Date(l.modified).toLocaleString() : "", u.appendChild(y), u.addEventListener("click", () => {
158
- t() && this.activateEntry(l);
159
- }), u.addEventListener("keydown", (b) => {
160
- t() && (b.key === "Enter" || b.key === " ") && (b.preventDefault(), this.activateEntry(l));
161
- }), d.appendChild(u);
162
- }
163
- h.appendChild(d), this.root.replaceChildren(n, s, h);
164
- }
165
- createBreadcrumbs(e) {
166
- const t = document.createElement("nav");
167
- t.className = "archivev-breadcrumbs", t.setAttribute("aria-label", "Archive path");
168
- const n = x(this.state.route), i = this.entryController !== null;
169
- this.archiveStack.forEach((o, c) => {
170
- c > 0 && t.appendChild(k());
171
- const h = document.createElement("button");
172
- h.type = "button", h.className = "archivev-breadcrumb", h.textContent = o.label;
173
- const d = c === this.archiveStack.length - 1;
174
- h.disabled = d && n === "/" && !i, h.addEventListener("click", () => {
175
- e() && (d ? this.setRoute("/") : this.popToArchive(c));
176
- }), t.appendChild(h);
177
- });
178
- const s = n === "/" ? [] : n.slice(1, -1).split("/").filter(Boolean);
179
- let a = "/";
180
- for (const o of s) {
181
- a = I(a, `${o}/`), t.appendChild(k());
182
- const c = document.createElement("button");
183
- c.type = "button", c.className = "archivev-breadcrumb", c.textContent = o, c.disabled = a === n && !i;
184
- const h = a;
185
- c.addEventListener("click", () => {
186
- e() && this.setRoute(h);
187
- }), t.appendChild(c);
188
- }
189
- if (this.activeEntry) {
190
- t.appendChild(k());
191
- const o = document.createElement("span");
192
- o.className = "archivev-breadcrumb-current", o.textContent = this.activeEntry.name.split("/").pop() ?? this.activeEntry.name, t.appendChild(o);
193
- }
194
- return t;
195
- }
196
- activateEntry(e) {
197
- if (e.type === "directory") {
198
- this.setRoute(I(this.state.route, e.name));
199
- return;
200
- }
201
- if (ne(e.name)) {
202
- this.openNestedArchive(e.name);
203
- return;
204
- }
205
- this.openEntryPreview(e.name);
206
- }
207
- async openEntryPreview(e) {
208
- var o;
209
- const t = this.findCurrentEntry(e), n = this.archiveStack[this.archiveStack.length - 1];
210
- if (!t || !n)
211
- return;
212
- const i = this.startEntryOperation();
213
- if (!i) return;
214
- const s = i.signal, a = () => this.entryController === i && !s.aborted;
215
- this.state = { ...this.state, loading: !0, error: null }, this.emit("loading", this.state), this.emit("statechange", this.state), this.render();
216
- try {
217
- const c = await g(t.read(), s);
218
- p(s), this.activeEntry = {
219
- name: e,
220
- source: c,
221
- contentType: ce(e, void 0)
222
- }, this.entryPreviewHost = document.createElement("div"), this.entryPreviewHost.className = "archivev-entry-preview", this.render();
223
- const h = this.options.previewerFactory;
224
- if (h) {
225
- const d = h(this.entryPreviewHost, {
226
- ...this.options,
227
- resourceResolver: this.createEntryResourceResolver(n, t.name, s)
228
- });
229
- this.entryPreviewer = d, this.entryPreviewUnsubscribes = [
230
- d.on("error", (l) => {
231
- a() && this.setEntryPreviewError(l);
232
- }),
233
- d.on("warnings", (l) => {
234
- a() && (this.state = { ...this.state, warnings: l }, this.emit("warnings", l), this.emit("statechange", this.state));
235
- })
236
- ], await g(d.preview(c, {
237
- name: e,
238
- extension: M(e),
239
- contentType: this.activeEntry.contentType
240
- }), s), p(s);
241
- } else
242
- this.renderFallbackEntryPreview(this.entryPreviewHost, c, e, this.activeEntry.contentType);
243
- this.state = {
244
- ...this.state,
245
- loading: !1,
246
- error: ((o = this.entryPreviewer) == null ? void 0 : o.getState().error) ?? null
247
- }, this.emit("statechange", this.state);
248
- } catch (c) {
249
- if (!a()) return;
250
- const h = c instanceof Error ? c : new Error(String(c));
251
- this.state = { ...this.state, loading: !1, error: h.message }, this.emit("error", h), this.emit("statechange", this.state);
252
- }
253
- }
254
- setEntryPreviewError(e) {
255
- this.state = { ...this.state, loading: !1, error: e.message }, this.emit("error", e), this.emit("statechange", this.state);
256
- }
257
- closeEntryPreview(e = !0) {
258
- var n, i, s;
259
- const t = this.entryController;
260
- this.entryController = null, t == null || t.abort(), this.entryPreviewUnsubscribes.splice(0).forEach((a) => a()), (n = this.entryPreviewer) == null || n.destroy(), this.entryPreviewer = null;
261
- for (const a of ((i = this.entryPreviewHost) == null ? void 0 : i.querySelectorAll("audio, video")) ?? []) {
262
- const o = a;
263
- o.pause(), o.removeAttribute("src"), o.load();
264
- }
265
- (s = this.entryPreviewHost) == null || s.replaceChildren(), this.entryPreviewHost = null, this.activeEntry = null, this.entryObjectUrl && (URL.revokeObjectURL(this.entryObjectUrl), this.entryObjectUrl = null), e && this.loadController && !this.loadController.signal.aborted && (this.state = { ...this.state, loading: !1, error: null, warnings: [] }, this.render(), this.emit("statechange", this.state));
266
- }
267
- startEntryOperation() {
268
- var i;
269
- this.closeEntryPreview(!1);
270
- const e = (i = this.loadController) == null ? void 0 : i.signal;
271
- if (!e || e.aborted) return null;
272
- const t = new AbortController(), n = () => t.abort();
273
- return this.entryController = t, e.addEventListener("abort", n, { once: !0 }), t.signal.addEventListener("abort", () => e.removeEventListener("abort", n), { once: !0 }), t;
274
- }
275
- popToArchive(e) {
276
- e < 0 || e >= this.archiveStack.length - 1 || (this.closeEntryPreview(!1), this.archiveStack.splice(e + 1), this.setRoute("/"));
277
- }
278
- navigateUp() {
279
- const e = ee(this.state.route);
280
- e !== this.state.route && this.setRoute(e);
281
- }
282
- setRoute(e) {
283
- this.entryController && this.closeEntryPreview(!1);
284
- const t = this.archiveStack[this.archiveStack.length - 1];
285
- if (!t)
286
- return;
287
- const n = x(e);
288
- t.listings ?? (t.listings = /* @__PURE__ */ new Map());
289
- let i = t.listings.get(n);
290
- if (!i) {
291
- const s = n === "/" ? t.entries : (t.directories ?? (t.directories = te(t.entries))).get(n.slice(1)) ?? [];
292
- i = re(s, n), t.listings.set(n, i);
293
- }
294
- this.state = {
295
- ...this.state,
296
- loading: !1,
297
- error: null,
298
- warnings: [],
299
- route: n,
300
- entries: i.map((s) => ({ ...s }))
301
- }, this.render(), this.emit("statechange", this.state);
302
- }
303
- findCurrentEntry(e) {
304
- const t = this.archiveStack[this.archiveStack.length - 1];
305
- if (!t)
306
- return;
307
- const n = this.state.route === "/" ? "" : this.state.route.slice(1);
308
- return t.entries.find((i) => i.type === "file" && i.name === `${n}${e}`);
309
- }
310
- createEntryResourceResolver(e, t, n) {
311
- const i = this.options.resourceResolver, s = t.slice(0, t.lastIndexOf("/") + 1), a = e.resources ?? (e.resources = new Map(e.entries.filter((o) => o.type === "file").map((o) => [z(o.name), o])));
312
- return async (o) => {
313
- p(n);
314
- const c = o.source ?? o.name;
315
- if (c && !/^[a-z][a-z\d+.-]*:/i.test(c)) {
316
- const d = (/^[\\/]/.test(c) ? void 0 : a.get(z(s + c))) ?? a.get(z(c));
317
- if (d) {
318
- const l = await g(d.read(), n);
319
- return p(n), {
320
- source: l,
321
- warnings: []
322
- };
323
- }
324
- }
325
- return i ? g(Promise.resolve(i(o)), n) : void 0;
326
- };
327
- }
328
- renderFallbackEntryPreview(e, t, n, i) {
329
- const s = M(n), a = i ?? "";
330
- if (a.startsWith("image/")) {
331
- this.entryObjectUrl = URL.createObjectURL(new Blob([L(t)], { type: a }));
332
- const c = document.createElement("img");
333
- c.className = "archivev-entry-image", c.alt = n, c.src = this.entryObjectUrl, e.replaceChildren(c);
334
- return;
335
- }
336
- if (a === "application/pdf" || s === "pdf") {
337
- this.entryObjectUrl = URL.createObjectURL(new Blob([L(t)], { type: "application/pdf" }));
338
- const c = document.createElement("iframe");
339
- c.className = "archivev-entry-frame", c.title = n, c.src = this.entryObjectUrl, e.replaceChildren(c);
340
- return;
341
- }
342
- if (a.startsWith("audio/") || a.startsWith("video/")) {
343
- this.entryObjectUrl = URL.createObjectURL(new Blob([L(t)], { type: a }));
344
- const c = document.createElement(a.startsWith("audio/") ? "audio" : "video");
345
- c.className = "archivev-entry-media", c.controls = !0, c.src = this.entryObjectUrl, e.replaceChildren(c);
346
- return;
347
- }
348
- const o = document.createElement("pre");
349
- o.className = "archivev-entry-text", o.textContent = new TextDecoder().decode(t), e.replaceChildren(o);
350
- }
351
- async openNestedArchive(e) {
352
- const t = this.archiveStack[this.archiveStack.length - 1];
353
- if (!t)
354
- return;
355
- const n = this.state.route === "/" ? "" : this.state.route.replace(/^\//, ""), i = t.entries.find((o) => o.type === "file" && o.name === `${n}${e}`);
356
- if (!i)
357
- return;
358
- const s = this.startEntryOperation();
359
- if (!s) return;
360
- const a = s.signal;
361
- this.state = {
362
- ...this.state,
363
- loading: !0,
364
- error: null
365
- }, this.emit("loading", this.state), this.emit("statechange", this.state), this.render();
366
- try {
367
- const o = e.split("/").pop() ?? e, c = await g(i.read(), a);
368
- p(a);
369
- const h = await T(c, O(o), o, a);
370
- p(a), this.closeEntryPreview(!1), this.archiveStack.push(h), this.state = {
371
- ...this.state,
372
- loading: !1,
373
- error: null
374
- }, this.setRoute("/"), this.emit("rendered", this.state);
375
- } catch (o) {
376
- if (a.aborted) return;
377
- const c = o instanceof Error ? o : new Error(String(o));
378
- this.state.loading = !1, this.state.error = c.message, this.emit("error", c), this.emit("statechange", this.state);
379
- }
380
- }
381
- popArchive() {
382
- this.archiveStack.length <= 1 || (this.archiveStack.pop(), this.setRoute("/"));
383
- }
384
- emit(e, t) {
385
- for (const n of this.listeners[e])
386
- n(t);
387
- }
388
- }
389
- function pe() {
390
- return {
391
- id: "archive",
392
- family: "archive",
393
- supports: (r) => D($(r)),
394
- createSession: (r, e) => new q(r, e)
395
- };
396
- }
397
- function me(r = G()) {
398
- const e = new Set(B.flatMap((t) => t.extensions));
399
- return [
400
- ...B,
401
- ...r.filter((t) => !t.extensions.some((n) => e.has(n)))
402
- ];
403
- }
404
- async function T(r, e, t, n) {
405
- if (p(n), W(e)) {
406
- const i = await g(_(r), n);
407
- return p(n), {
408
- label: t,
409
- entries: [...i.values()].map((s) => ({
410
- name: s.name,
411
- type: s.directory ? "directory" : "file",
412
- size: s.directory ? void 0 : s.size,
413
- modified: s.modified,
414
- read: () => s.bytes()
415
- })).sort(U)
416
- };
417
- }
418
- if (e === "tar")
419
- return { label: t, entries: F(r) };
420
- if (e === "gz" || e === "tgz") {
421
- const i = await g(Q(r), n);
422
- if (p(n), e === "tgz" || X(i))
423
- return { label: t, entries: F(i) };
424
- const s = t.replace(/\.gz$/i, "") || "file";
425
- return {
426
- label: t,
427
- entries: [{ name: s, type: "file", size: i.byteLength, read: async () => i.slice() }]
428
- };
429
- }
430
- throw new Error(`Archive preview does not support ${e || "unknown"} files.`);
431
- }
432
- function F(r) {
433
- const e = [], t = /* @__PURE__ */ new Map();
434
- let n = /* @__PURE__ */ new Map(), i;
435
- for (let s = 0; s + 512 <= r.byteLength; ) {
436
- const a = r.subarray(s, s + 512);
437
- if (a.every((m) => m === 0)) break;
438
- if (!H(a)) throw new Error("Invalid TAR header checksum.");
439
- const o = String.fromCharCode(a[156] ?? 0), c = ["x", "g", "L", "K"].includes(o), h = (m) => n.get(m) ?? t.get(m), d = c ? void 0 : h("size"), l = d ? R(d, !0) : P(a, 124, 12);
440
- if (!Number.isSafeInteger(l) || l < 0) throw new Error("Invalid TAR entry size.");
441
- const u = s + 512, v = u + Math.ceil(l / 512) * 512;
442
- if (!Number.isSafeInteger(v) || v > r.byteLength) throw new Error("Truncated TAR entry.");
443
- if (c) {
444
- const m = r.subarray(u, u + l);
445
- if (o === "L") {
446
- const C = m.indexOf(0);
447
- i = new TextDecoder().decode(C < 0 ? m : m.subarray(0, C));
448
- } else if (o !== "K") {
449
- const C = J(m);
450
- for (const [A, S] of C)
451
- o === "g" ? S ? t.set(A, S) : t.delete(A) : n.set(A, S);
452
- }
453
- s = v;
454
- continue;
455
- }
456
- const w = N(a, 345, 155), E = N(a, 0, 100), y = z(h("path") || i || (w ? `${w}/${E}` : E)), b = h("mtime"), j = b ? R(b, !1) : P(a, 136, 12);
457
- if (n = /* @__PURE__ */ new Map(), i = void 0, y && (o === "\0" || o === "0" || o === "5")) {
458
- const m = o === "5", C = m ? `${y.replace(/\/+$/, "")}/` : y;
459
- e.push({
460
- name: C,
461
- type: m ? "directory" : "file",
462
- size: m ? void 0 : l,
463
- modified: b || j > 0 ? j * 1e3 : void 0,
464
- read: async () => m ? new Uint8Array() : r.slice(u, u + l)
465
- });
466
- }
467
- s = v;
468
- }
469
- return e.sort(U);
470
- }
471
- function J(r) {
472
- const e = /* @__PURE__ */ new Map(), t = new TextDecoder();
473
- for (let n = 0; n < r.length; ) {
474
- const i = r.indexOf(32, n);
475
- if (i < 0) throw new Error("Invalid TAR extended header length.");
476
- const s = R(t.decode(r.subarray(n, i)), !0), a = n + s;
477
- if (a <= i + 1 || a > r.length || r[a - 1] !== 10) throw new Error("Truncated TAR extended header.");
478
- const o = t.decode(r.subarray(i + 1, a - 1)), c = o.indexOf("=");
479
- if (c <= 0) throw new Error("Invalid TAR extended header field.");
480
- e.set(o.slice(0, c), o.slice(c + 1)), n = a;
481
- }
482
- return e;
483
- }
484
- function R(r, e) {
485
- const t = Number(r);
486
- if (!(e ? /^\d+$/ : /^-?\d+(?:\.\d+)?$/).test(r) || !Number.isFinite(t) || e && !Number.isSafeInteger(t))
487
- throw new Error("Invalid TAR extended header number.");
488
- return t;
489
- }
490
- async function Q(r) {
491
- return K(r);
492
- }
493
- function X(r) {
494
- return r.byteLength >= 512 && !r.subarray(0, 512).every((e) => e === 0) && H(r.subarray(0, 512));
495
- }
496
- function H(r) {
497
- const e = P(r, 148, 8);
498
- let t = 0;
499
- for (let n = 0; n < 512; n += 1)
500
- t += n >= 148 && n < 156 ? 32 : r[n] ?? 0;
501
- return e === t;
502
- }
503
- function N(r, e, t) {
504
- const n = r.subarray(e, e + t), i = n.indexOf(0);
505
- return new TextDecoder().decode(i >= 0 ? n.subarray(0, i) : n).trim();
506
- }
507
- function P(r, e, t) {
508
- const n = N(r, e, t).replace(/^0+/, "").trim();
509
- return n ? Number.parseInt(n, 8) : 0;
510
- }
511
- function x(r) {
512
- const e = String(r || "/").trim().replace(/\\/g, "/");
513
- if (!e || e === "/")
514
- return "/";
515
- const t = e.replace(/^\/+/, "").replace(/\/+$/, "");
516
- return t ? `/${t}/` : "/";
517
- }
518
- function Y(r) {
519
- return x(r) !== "/";
520
- }
521
- function ee(r) {
522
- const e = x(r);
523
- if (e === "/")
524
- return "/";
525
- const n = e.replace(/^\/|\/$/g, "").split("/").filter(Boolean);
526
- return n.pop(), n.length ? `/${n.join("/")}/` : "/";
527
- }
528
- function I(r, e) {
529
- const t = x(r), n = t === "/" ? "" : t.replace(/^\/|\/$/g, ""), i = String(e).replace(/\\/g, "/").replace(/\/+$/g, "").replace(/^\/+/, ""), s = [n, i].filter(Boolean).join("/");
530
- return s ? `/${s}/` : "/";
531
- }
532
- function te(r) {
533
- const e = /* @__PURE__ */ new Map();
534
- for (const t of r) {
535
- let n = "";
536
- for (let i = t.name.indexOf("/"); i >= 0; i = t.name.indexOf("/", i + 1)) {
537
- const s = t.name.slice(0, i + 1), a = e.has(s);
538
- a || e.set(s, []), n && (!a || i === t.name.length - 1) && e.get(n).push(t), n = s;
539
- }
540
- n && !t.name.endsWith("/") && e.get(n).push(t);
541
- }
542
- return e;
543
- }
544
- function re(r, e) {
545
- const t = x(e), n = t === "/" ? "" : t.slice(1), i = new Map(r.map((a) => [a.name, a])), s = /* @__PURE__ */ new Map();
546
- for (const a of r) {
547
- if (n && !a.name.startsWith(n))
548
- continue;
549
- const o = n ? a.name.slice(n.length) : a.name;
550
- if (!o)
551
- continue;
552
- const c = o.split("/", 1)[0] ?? o;
553
- if (!c)
554
- continue;
555
- const h = o.length > c.length, d = h ? `${c}/` : c;
556
- if (!s.has(d)) {
557
- if (h) {
558
- const l = i.get(`${n}${d}`);
559
- s.set(d, {
560
- name: d,
561
- type: "directory",
562
- modified: l == null ? void 0 : l.modified
563
- });
564
- continue;
565
- }
566
- s.set(d, {
567
- name: d,
568
- type: "file",
569
- size: a.size,
570
- modified: a.modified
571
- });
572
- }
573
- }
574
- return [...s.values()].sort(U);
575
- }
576
- function O(r, e) {
577
- const t = String(r).trim().toLowerCase().split(/[?#]/, 1)[0] ?? "";
578
- return t.endsWith(".tar.gz") || t.endsWith(".tgz") ? "tgz" : $(e || t.split(".").pop());
579
- }
580
- function ne(r) {
581
- return D(O(r));
582
- }
583
- function D(r) {
584
- return W(r) || r === "tar" || r === "tgz" || r === "gz";
585
- }
586
- function W(r) {
587
- return ["zip", "jar", "war", "ear", "apk"].includes(r);
588
- }
589
- async function ie(r, e) {
590
- const t = e.signal;
591
- if (p(t), typeof r == "string") {
592
- const n = (s) => {
593
- var a;
594
- (a = s.body) == null || a.cancel().catch(() => {
595
- });
596
- }, i = await g(fetch(r, { signal: t }), t, n);
597
- try {
598
- if (p(t), !i.ok)
599
- throw new Error(`Failed to load archive source: ${i.status} ${i.statusText}`.trim());
600
- return await g(i.arrayBuffer(), t);
601
- } catch (s) {
602
- throw n(i), s;
603
- }
604
- }
605
- if (ArrayBuffer.isView(r)) {
606
- const n = new Uint8Array(r.buffer, r.byteOffset, r.byteLength), i = new Uint8Array(n.byteLength);
607
- return i.set(n), i.buffer;
608
- }
609
- return r instanceof ArrayBuffer ? r.slice(0) : r instanceof Blob ? g(r.arrayBuffer(), t) : new TextEncoder().encode(String(r)).buffer;
610
- }
611
- function p(r) {
612
- if (r != null && r.aborted) throw new DOMException("Archive preview aborted.", "AbortError");
613
- }
614
- function g(r, e, t) {
615
- return e ? new Promise((n, i) => {
616
- let s = !1;
617
- const a = () => {
618
- s || (s = !0, e.removeEventListener("abort", a), i(new DOMException("Archive preview aborted.", "AbortError")));
619
- };
620
- e.addEventListener("abort", a, { once: !0 }), e.aborted && a(), r.then((o) => {
621
- if (s) {
622
- t == null || t(o);
623
- return;
624
- }
625
- s = !0, e.removeEventListener("abort", a), n(o);
626
- }, (o) => {
627
- s || (s = !0, e.removeEventListener("abort", a), i(o));
628
- }).catch(() => {
629
- });
630
- }) : r;
631
- }
632
- function se() {
633
- const r = document.createElement("thead"), e = document.createElement("tr");
634
- for (const t of ["Name", "Type", "Size", "Modified"]) {
635
- const n = document.createElement("th");
636
- n.textContent = t, e.appendChild(n);
637
- }
638
- return r.appendChild(e), r;
639
- }
640
- function k() {
641
- const r = document.createElement("span");
642
- return r.className = "archivev-breadcrumb-separator", r.textContent = "›", r.setAttribute("aria-hidden", "true"), r;
643
- }
644
- function M(r) {
645
- const t = (r.toLowerCase().split(/[?#]/, 1)[0] ?? "").split(/[\\/]/).pop() ?? "", n = t.lastIndexOf(".");
646
- return n >= 0 ? t.slice(n + 1) : "";
647
- }
648
- function U(r, e) {
649
- return r.type !== e.type ? r.type === "directory" ? -1 : 1 : r.name.localeCompare(e.name);
650
- }
651
- function ae(r) {
652
- if (r < 1024)
653
- return `${r} B`;
654
- const e = ["KB", "MB", "GB", "TB"];
655
- let t = r / 1024, n = 0;
656
- for (; t >= 1024 && n < e.length - 1; )
657
- t /= 1024, n += 1;
658
- return `${t.toFixed(t >= 10 ? 0 : 1)} ${e[n]}`;
659
- }
660
- function $(r) {
661
- return String(r ?? "").trim().replace(/^\./, "").toLowerCase();
662
- }
663
- function z(r) {
664
- const e = String(r ?? "");
665
- if (!/[\\%?#:]|(?:^|\/)\.\.?(?:\/|$)|\/\/|^\/|\/$|^\s|\s$/.test(e)) return e;
666
- const t = e.trim().replace(/\\/g, "/").replace(/^[a-z]+:\/\/[^/]+\//i, "").replace(/^[a-z]:\//i, "").replace(/^\/+/, "").split(/[?#]/)[0] ?? "", n = [];
667
- for (const i of t.split("/"))
668
- if (!(!i || i === ".")) {
669
- if (i === "..") {
670
- n.pop();
671
- continue;
672
- }
673
- n.push(oe(i));
674
- }
675
- return n.join("/");
676
- }
677
- function L(r) {
678
- const e = new Uint8Array(r.byteLength);
679
- return e.set(r), e.buffer;
680
- }
681
- function oe(r) {
682
- try {
683
- return decodeURIComponent(r);
684
- } catch {
685
- return r;
686
- }
687
- }
688
- function ce(r, e, t = !1) {
689
- var s;
690
- const n = t ? r : z(r), i = $((s = n.split("?")[0]) == null ? void 0 : s.split(".").pop());
691
- return (e == null ? void 0 : e[n]) ?? (e == null ? void 0 : e[i]) ?? le(i);
692
- }
693
- function le(r) {
694
- return {
695
- aac: "audio/aac",
696
- avif: "image/avif",
697
- bin: "application/octet-stream",
698
- bmp: "image/bmp",
699
- css: "text/css",
700
- gif: "image/gif",
701
- flac: "audio/flac",
702
- gltf: "model/gltf+json",
703
- html: "text/html",
704
- jpeg: "image/jpeg",
705
- jpg: "image/jpeg",
706
- json: "application/json",
707
- ktx2: "image/ktx2",
708
- m4a: "audio/mp4",
709
- m4v: "video/mp4",
710
- mov: "video/quicktime",
711
- mp3: "audio/mpeg",
712
- mp4: "video/mp4",
713
- obj: "model/obj",
714
- oga: "audio/ogg",
715
- ogg: "audio/ogg",
716
- ogv: "video/ogg",
717
- opus: "audio/ogg",
718
- pdf: "application/pdf",
719
- png: "image/png",
720
- svg: "image/svg+xml",
721
- txt: "text/plain",
722
- wav: "audio/wav",
723
- webm: "video/webm",
724
- webp: "image/webp",
725
- xhtml: "application/xhtml+xml"
726
- }[r];
727
- }
728
- export {
729
- pe as a,
730
- me as c
731
- };