filens-preview 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +13 -7
  2. package/dist/all-in-one/THIRD-PARTY-NOTICES.txt +870 -0
  3. package/dist/all-in-one/filens.js +5069 -114897
  4. package/dist/index.d.ts +2 -0
  5. package/dist/split/THIRD-PARTY-NOTICES.txt +870 -0
  6. package/dist/split/chunks/archive-haip2eOP.js +1 -0
  7. package/dist/split/chunks/browser-video-session-C_14e_mG.js +1 -0
  8. package/dist/split/chunks/cad-5oTkbaDV.js +7 -0
  9. package/dist/split/chunks/core-EjELrtsP.js +17 -0
  10. package/dist/split/chunks/diagram-BRcdlitF.js +1 -0
  11. package/dist/split/chunks/docx-I39iDYpR.js +1 -0
  12. package/dist/split/chunks/ebook-BRfadCGl.js +5 -0
  13. package/dist/split/chunks/index-C4jdVbDq.js +1 -0
  14. package/dist/split/chunks/index-DkF8PBGR.js +1 -0
  15. package/dist/split/chunks/iwork-DXq9Adf7.js +4 -0
  16. package/dist/split/chunks/media-runtime-B6322raw.js +1 -0
  17. package/dist/split/chunks/mindmap-CyR3TRfx.js +1 -0
  18. package/dist/split/chunks/model3d-BEt6INTt.js +55 -0
  19. package/dist/split/chunks/mp4box.all-Bw_Tlr0T-D0URDfA1.js +1 -0
  20. package/dist/split/chunks/panorama-ChsqnvWC.js +973 -0
  21. package/dist/split/chunks/pdf-Dzzffz3p.js +12 -0
  22. package/dist/split/chunks/vendor-C1aIdQ-w.js +4115 -0
  23. package/dist/split/chunks/xlsx-CITQo0Od.js +3 -0
  24. package/dist/split/converter-image.wasm +0 -0
  25. package/dist/split/filens.js +2 -5012
  26. package/package.json +1 -1
  27. package/dist/split/chunks/archive-B4jVwD9o.js +0 -921
  28. package/dist/split/chunks/cad-DMg-lGJX.js +0 -2405
  29. package/dist/split/chunks/core--zVW212C.js +0 -14627
  30. package/dist/split/chunks/diagram-CDwCA6LZ.js +0 -654
  31. package/dist/split/chunks/docx-CuQfFJqr.js +0 -299
  32. package/dist/split/chunks/ebook-CLlJ8KX3.js +0 -623
  33. package/dist/split/chunks/iwork-dNVC0X8j.js +0 -772
  34. package/dist/split/chunks/media-runtime-gcsBQMuo.js +0 -48
  35. package/dist/split/chunks/mindmap-g0-VoK-K.js +0 -560
  36. package/dist/split/chunks/model3d-1G1CC52V.js +0 -5093
  37. package/dist/split/chunks/panorama-D7GVivtM.js +0 -5972
  38. package/dist/split/chunks/pdf-CecYOWld.js +0 -17898
  39. package/dist/split/chunks/vendor-DPFNKNkh.js +0 -59575
  40. package/dist/split/chunks/xlsx-Co26yo-R.js +0 -818
@@ -1,772 +0,0 @@
1
- var ge = Object.defineProperty;
2
- var me = (e, t, n) => t in e ? ge(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var S = (e, t, n) => me(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { M as se, r as we, c as pe, b as be, a as J, d as ve, e as K, f as Z, g as ke } from "./core--zVW212C.js";
5
- import { R as j, c as Se, a as ye } from "./xlsx-Co26yo-R.js";
6
- async function Ee(e, t = {}) {
7
- if (q(t.signal), typeof e == "string") {
8
- const n = await fetch(e, {
9
- signal: t.signal
10
- });
11
- if (!n.ok)
12
- throw new Error(`Failed to fetch iWork source: ${n.status} ${n.statusText}`);
13
- const s = new Uint8Array(await n.arrayBuffer());
14
- return q(t.signal), s;
15
- }
16
- if (ArrayBuffer.isView(e))
17
- return new Uint8Array(e.buffer, e.byteOffset, e.byteLength).slice();
18
- if (xe(e))
19
- return new Uint8Array(e).slice();
20
- if (Ce(e)) {
21
- q(t.signal);
22
- const n = new Uint8Array(await e.arrayBuffer());
23
- return q(t.signal), n;
24
- }
25
- throw new Error("Unsupported iWork source type.");
26
- }
27
- function q(e) {
28
- if (e != null && e.aborted)
29
- throw Me();
30
- }
31
- function Me() {
32
- try {
33
- return new DOMException("The operation was aborted.", "AbortError");
34
- } catch {
35
- const e = new Error("The operation was aborted.");
36
- return e.name = "AbortError", e;
37
- }
38
- }
39
- function xe(e) {
40
- return e instanceof ArrayBuffer || Object.prototype.toString.call(e) === "[object ArrayBuffer]" || Object.prototype.toString.call(e) === "[object SharedArrayBuffer]";
41
- }
42
- function Ce(e) {
43
- return typeof e == "object" && e !== null && typeof e.arrayBuffer == "function" && typeof e.size == "number";
44
- }
45
- class Le {
46
- constructor() {
47
- S(this, "worker", null);
48
- S(this, "destroyed", !1);
49
- S(this, "requestId", 0);
50
- S(this, "pending", /* @__PURE__ */ new Map());
51
- S(this, "handleMessage", (t) => {
52
- const n = this.pending.get(t.data.id);
53
- if (!n)
54
- return;
55
- if (this.pending.delete(t.data.id), t.data.error) {
56
- n.reject(new Error(t.data.error));
57
- return;
58
- }
59
- const s = t.data.document ?? t.data.sheet;
60
- if (!s) {
61
- n.reject(new Error("iWork parser worker returned an empty result."));
62
- return;
63
- }
64
- n.resolve(s);
65
- });
66
- S(this, "handleError", (t) => {
67
- const n = new Error(t.message || "iWork parser worker failed.");
68
- this.stopWorker(n);
69
- });
70
- if (typeof Worker > "u")
71
- throw new Error("Web Worker is required for iWork preview parsing.");
72
- this.getWorker();
73
- }
74
- getWorker() {
75
- if (this.destroyed) throw new Error("iWork parser worker has been destroyed.");
76
- return this.worker ? this.worker : (this.worker = new Worker(new URL(
77
- /* @vite-ignore */
78
- "" + new URL("../assets/iwork-worker-B9KPoDW3.js", import.meta.url).href,
79
- import.meta.url
80
- ), {
81
- type: "module"
82
- }), this.worker.addEventListener("message", this.handleMessage), this.worker.addEventListener("error", this.handleError), this.worker);
83
- }
84
- parse(t, n, s) {
85
- this.pending.size && this.cancel();
86
- const i = ++this.requestId, a = t.buffer instanceof ArrayBuffer && t.byteOffset === 0 && t.byteLength === t.buffer.byteLength ? t.buffer : t.slice().buffer;
87
- return new Promise((u, g) => {
88
- this.pending.set(i, { resolve: u, reject: g }), this.postRequest(
89
- i,
90
- {
91
- kind: "document",
92
- id: i,
93
- bytes: a,
94
- hint: n,
95
- sourceName: s
96
- },
97
- [a]
98
- );
99
- });
100
- }
101
- parseSheet(t) {
102
- const n = ++this.requestId;
103
- return new Promise((s, i) => {
104
- this.pending.set(n, { resolve: s, reject: i }), this.postRequest(n, { kind: "sheet", id: n, index: t });
105
- });
106
- }
107
- cancel() {
108
- if (this.pending.size)
109
- this.stopWorker(new DOMException("iWork parsing cancelled.", "AbortError"));
110
- else if (this.worker)
111
- try {
112
- this.worker.postMessage({ kind: "clear" });
113
- } catch {
114
- this.stopWorker(new DOMException("iWork parsing cancelled.", "AbortError"));
115
- }
116
- }
117
- destroy() {
118
- this.destroyed = !0, this.stopWorker(new DOMException("iWork parser worker terminated.", "AbortError"));
119
- }
120
- postRequest(t, n, s = []) {
121
- try {
122
- this.getWorker().postMessage(n, s);
123
- } catch (i) {
124
- const a = this.pending.get(t);
125
- this.pending.delete(t), a == null || a.reject(i instanceof Error ? i : new Error(String(i)));
126
- }
127
- }
128
- stopWorker(t) {
129
- const n = this.worker;
130
- this.worker = null, n == null || n.removeEventListener("message", this.handleMessage), n == null || n.removeEventListener("error", this.handleError), n == null || n.terminate();
131
- for (const s of this.pending.values())
132
- s.reject(t);
133
- this.pending.clear();
134
- }
135
- }
136
- const ie = {
137
- colors: {},
138
- fonts: {}
139
- };
140
- function Te(e) {
141
- return new se(Pe(e));
142
- }
143
- function U(e) {
144
- return e.kind === "key" ? e.slides : e.kind === "pages" ? e.pages.map((t) => t.canvas) : e.sheets.map((t) => t.canvas);
145
- }
146
- function Q(e, t, n, s) {
147
- const i = Fe(t, n.slide), a = s ?? new se(i), u = e.createElement("div");
148
- u.className = t.kind === "numbers" ? "iworkv-page-shell iworkv-sheet-shell" : "iworkv-page-shell";
149
- const g = we(n.slide, i, {
150
- mediaRegistry: a
151
- });
152
- return u.appendChild(g), u;
153
- }
154
- function Fe(e, t) {
155
- return e.kind === "key" ? {
156
- ...e.presentation,
157
- slides: [t]
158
- } : {
159
- size: {
160
- width: t.width,
161
- height: t.height
162
- },
163
- theme: ie,
164
- slides: [t],
165
- media: e.media,
166
- warnings: e.warnings.slice()
167
- };
168
- }
169
- function Pe(e) {
170
- return e.kind === "key" ? e.presentation : {
171
- size: {
172
- width: 1,
173
- height: 1
174
- },
175
- theme: ie,
176
- slides: U(e).map((t) => t.slide),
177
- media: e.media,
178
- warnings: e.warnings.slice()
179
- };
180
- }
181
- function Ae(e, t = {}) {
182
- var G;
183
- const n = /* @__PURE__ */ new Map(), s = new Le(), i = t.fit === void 0;
184
- let a = null, u = null, g = null, R = 0, v = !1;
185
- const r = {
186
- loading: !1,
187
- error: null,
188
- kind: null,
189
- currentPage: 0,
190
- pageCount: 0,
191
- currentSheet: 0,
192
- sheetCount: 0,
193
- scale: t.initialScale ?? 1,
194
- fit: t.fit ?? "contain",
195
- warnings: [],
196
- document: null
197
- };
198
- e.classList.add("iworkv-root"), e.innerHTML = '<div class="iworkv-stage"></div>';
199
- const k = e.querySelector(".iworkv-stage");
200
- let C = null, F = [];
201
- const B = /* @__PURE__ */ new Map(), L = /* @__PURE__ */ new Set(), D = /* @__PURE__ */ new Map();
202
- let N, P = 0;
203
- const y = (o, h) => {
204
- var l;
205
- (l = n.get(o)) == null || l.forEach((c) => c(h));
206
- }, A = () => {
207
- e.classList.toggle("is-loading", r.loading), e.classList.toggle("is-error", !!r.error), e.dataset.status = r.error ?? (r.loading ? "Loading document..." : "");
208
- }, E = () => ({
209
- ...r,
210
- warnings: r.warnings.slice()
211
- }), O = () => {
212
- const o = u;
213
- u = null, o == null || o.abort(), s.cancel(), g == null || g.abort(), g = null, C == null || C.disconnect(), C = null, P && typeof cancelAnimationFrame < "u" && cancelAnimationFrame(P), P = 0, k.replaceChildren(), k.classList.remove("iworkv-numbers-stage"), F = [], B.clear(), L.clear(), D.clear(), a == null || a.destroy(), a = null, Object.assign(r, {
214
- document: null,
215
- kind: null,
216
- loading: !1,
217
- error: null,
218
- warnings: [],
219
- currentPage: 0,
220
- pageCount: 0,
221
- currentSheet: 0,
222
- sheetCount: 0
223
- }), e.scrollTop = 0, e.scrollLeft = 0;
224
- }, I = () => {
225
- var h;
226
- if (g == null || g.abort(), g = new AbortController(), k.innerHTML = "", k.classList.toggle("iworkv-numbers-stage", ((h = r.document) == null ? void 0 : h.kind) === "numbers"), F = [], B.clear(), L.clear(), !r.document)
227
- return;
228
- const o = U(r.document);
229
- if (o.length) {
230
- if (r.document.kind === "numbers") {
231
- oe();
232
- return;
233
- }
234
- if (r.document.kind === "key" || r.document.kind === "pages") {
235
- const l = document.createElement("div");
236
- l.className = "iworkv-pages";
237
- const c = k.getBoundingClientRect();
238
- o.forEach((d, m) => {
239
- const w = document.createElement("div");
240
- w.className = "iworkv-page-shell", z(w, d.width, d.height, _(d.width, d.height, c)), w.dataset.pageIndex = String(m), l.appendChild(w), F.push(w);
241
- }), k.appendChild(l), L.add(r.currentPage), V();
242
- return;
243
- }
244
- }
245
- }, oe = () => {
246
- var p;
247
- if (((p = r.document) == null ? void 0 : p.kind) !== "numbers")
248
- return;
249
- const o = document.createElement("div");
250
- o.className = "xlsxv-preview";
251
- const h = document.createElement("div");
252
- h.className = "xlsxv-sheet-tabs", r.document.sheets.forEach((f, M) => {
253
- const b = document.createElement("button");
254
- b.type = "button", b.className = "xlsxv-sheet-tab", b.classList.toggle("is-active", M === r.currentSheet), b.textContent = f.name, b.addEventListener("click", () => Y(M), { signal: g.signal }), h.appendChild(b);
255
- });
256
- const l = document.createElement("div");
257
- l.className = "xlsxv-grid";
258
- const c = document.createElement("div");
259
- c.className = "iworkv-numbers-tables";
260
- const d = r.document.sheets[r.currentSheet], m = ((d == null ? void 0 : d.tables) ?? []).map(({ item: f }, M) => {
261
- const b = Ie(f, M), x = document.createElement("section");
262
- if (x.className = "iworkv-numbers-table", x.style.containIntrinsicBlockSize = `auto ${(Math.min(Math.max(b.rowCount, 1), j) + 1) * 26}px`, ((d == null ? void 0 : d.tables.length) ?? 0) > 1) {
263
- const $ = document.createElement("h3");
264
- $.className = "iworkv-numbers-table-title", $.textContent = `Table ${M + 1}`, x.appendChild($);
265
- }
266
- const T = Se(b, Math.min(Math.max(b.rowCount, 1), (N == null ? void 0 : N[M]) ?? j));
267
- return ee(T, f, a), x.appendChild(T), c.appendChild(x), { sheet: b, item: f, table: T, body: T.tBodies[0] };
268
- }), w = (d == null ? void 0 : d.canvas.slide.items.filter((f) => f.kind !== "table")) ?? [];
269
- if (d && w.length) {
270
- const f = document.createElement("section"), M = document.createElement("h3");
271
- M.className = "iworkv-numbers-table-title", M.textContent = "Sheet objects";
272
- const b = {
273
- ...d.canvas,
274
- slide: {
275
- ...d.canvas.slide,
276
- items: w
277
- }
278
- }, x = Q(document, r.document, b, a ?? void 0), T = Math.max(k.getBoundingClientRect().width - 32, 1);
279
- z(x, b.width, b.height, T / Math.max(b.width, 1)), f.className = "iworkv-numbers-objects", f.append(M, x), c.appendChild(f);
280
- }
281
- l.appendChild(c), l.addEventListener("scroll", () => {
282
- if (!(l.scrollHeight - l.scrollTop - l.clientHeight > l.clientHeight * 2))
283
- for (const { sheet: f, item: M, table: b, body: x } of m) {
284
- const T = x.rows.length;
285
- T < f.rowCount && (ye(x, f, T + 1, Math.min(T + j, f.rowCount)), ee(b, M, a));
286
- }
287
- }, { passive: !0, signal: g.signal }), o.replaceChildren(h, l), k.appendChild(o);
288
- }, V = () => {
289
- if (!r.document || r.document.kind === "numbers")
290
- return;
291
- const o = U(r.document), l = t.virtual ?? r.document.kind === "pages" ? L : new Set(F.map((c, d) => d));
292
- for (const [c, d] of B)
293
- l.has(c) || (d.remove(), B.delete(c));
294
- for (const c of l) {
295
- if (B.has(c))
296
- continue;
297
- const d = F[c], m = o[c];
298
- if (!d || !m)
299
- continue;
300
- const w = Q(document, r.document, m, a ?? void 0).firstElementChild;
301
- w && (d.appendChild(w), z(d, m.width, m.height, r.scale), B.set(c, w));
302
- }
303
- }, H = () => {
304
- if (P = 0, !r.document || r.document.kind === "numbers" || !F.length)
305
- return;
306
- const o = De(e), h = (o.top + o.bottom) / 2, l = Math.max(o.height, 1);
307
- let c = r.currentPage, d = Number.POSITIVE_INFINITY;
308
- L.clear(), F.forEach((m, w) => {
309
- const p = m.getBoundingClientRect();
310
- p.bottom >= o.top - l && p.top <= o.bottom + l && L.add(w);
311
- const f = Math.abs((p.top + p.bottom) / 2 - h);
312
- f < d && (d = f, c = w);
313
- }), L.size || L.add(c), V(), c !== r.currentPage && (r.currentPage = c, y("pagechange", E()));
314
- }, W = () => {
315
- if (P || typeof requestAnimationFrame > "u") {
316
- P || H();
317
- return;
318
- }
319
- P = requestAnimationFrame(H);
320
- };
321
- e.addEventListener("scroll", W, { passive: !0 }), e.ownerDocument.addEventListener("scroll", W, { capture: !0, passive: !0 }), (G = e.ownerDocument.defaultView) == null || G.addEventListener("scroll", W, { passive: !0 });
322
- const ae = (o) => {
323
- if (!r.document || r.document.kind === "numbers")
324
- return;
325
- const h = k.querySelector(`.iworkv-page-shell[data-page-index="${o}"]`);
326
- h && h.scrollIntoView({
327
- block: "nearest",
328
- inline: "nearest"
329
- });
330
- }, _ = (o, h, l) => {
331
- if (r.fit === "none")
332
- return r.scale;
333
- const c = l ?? k.getBoundingClientRect(), d = Math.max(c.width - 32, 1), m = Math.max(c.height - 32, 1);
334
- return r.fit === "width" ? (r.scale = d / Math.max(o, 1), r.scale) : r.fit === "height" ? (r.scale = m / Math.max(h, 1), r.scale) : (r.scale = Math.min(d / Math.max(o, 1), m / Math.max(h, 1)), r.scale);
335
- }, le = () => {
336
- C == null || C.disconnect(), C = null, !(typeof ResizeObserver > "u") && (C = new ResizeObserver(() => {
337
- var h;
338
- if (!r.document || r.fit === "none")
339
- return;
340
- if (r.document.kind === "numbers") {
341
- const l = (h = r.document.sheets[r.currentSheet]) == null ? void 0 : h.canvas, c = k.querySelector(".iworkv-numbers-objects .iworkv-page-shell");
342
- if (l && c) {
343
- const d = Math.max(k.getBoundingClientRect().width - 32, 1);
344
- z(c, l.width, l.height, d / Math.max(l.width, 1));
345
- }
346
- return;
347
- }
348
- const o = k.getBoundingClientRect();
349
- U(r.document).forEach((l, c) => {
350
- const d = F[c];
351
- d && z(d, l.width, l.height, _(l.width, l.height, o));
352
- }), y("scalechange", E());
353
- }), C.observe(k));
354
- }, ce = (o) => {
355
- var c, d;
356
- const h = ((c = r.document) == null ? void 0 : c.kind) === "numbers" ? r.document : null;
357
- if (!h || ((d = h.sheets[o]) == null ? void 0 : d.loaded) !== !1 || (r.currentSheet === o && (e.classList.add("is-loading"), e.dataset.status = "Loading sheet..."), D.has(o)))
358
- return;
359
- const l = s.parseSheet(o).then((m) => {
360
- r.document === h && (h.sheets[o] = m, r.currentSheet === o && (I(), A()), y("sheetchange", E()));
361
- }).catch((m) => {
362
- if (r.document !== h)
363
- return;
364
- const w = m instanceof Error ? m : new Error(String(m));
365
- r.currentSheet === o && (r.error = w.message, A(), y("error", w));
366
- }).finally(() => {
367
- D.get(o) === l && D.delete(o);
368
- });
369
- D.set(o, l);
370
- }, de = async (o, h = {}) => {
371
- var m, w;
372
- if (v) throw new Error("iWork viewer has been destroyed.");
373
- const l = ++R;
374
- O();
375
- const c = new AbortController();
376
- u = c;
377
- const d = () => {
378
- u === c && (O(), A(), y("loadingchange", E()));
379
- };
380
- if ((m = h.signal) == null || m.addEventListener("abort", d, { once: !0 }), c.signal.addEventListener("abort", () => {
381
- var p;
382
- return (p = h.signal) == null ? void 0 : p.removeEventListener("abort", d);
383
- }, { once: !0 }), (w = h.signal) != null && w.aborted)
384
- throw d(), new DOMException("The operation was aborted.", "AbortError");
385
- r.loading = !0, r.error = null, A(), y("loadingchange", E());
386
- try {
387
- const p = await X(Ee(o, { signal: c.signal }), c.signal);
388
- if (c.signal.aborted) throw new DOMException("The operation was aborted.", "AbortError");
389
- const f = await X(s.parse(p, t.type, Re(o)), c.signal);
390
- if (c.signal.aborted) throw new DOMException("The operation was aborted.", "AbortError");
391
- if (r.document = f, r.kind = f.kind, r.warnings = f.warnings.slice(), i && (f.kind === "key" || f.kind === "pages") && r.fit === "contain" && (r.fit = "width"), r.currentPage = 0, r.currentSheet = 0, D.clear(), r.pageCount = f.kind === "numbers" ? 0 : f.kind === "key" ? f.slides.length : f.pages.length, r.sheetCount = f.kind === "numbers" ? f.sheets.length : 0, a == null || a.destroy(), a = Te(f), r.loading = !1, I(), le(), A(), y("loadingchange", E()), u !== c) return;
392
- y("warnings", r.warnings), u === c && y("rendered", E());
393
- } catch (p) {
394
- if (v || R !== l) return;
395
- if (c.signal.aborted) throw new DOMException("The operation was aborted.", "AbortError");
396
- const f = p instanceof Error ? p : new Error(String(p));
397
- O(), r.error = f.message, A(), y("loadingchange", E()), !v && R === l && y("error", f);
398
- }
399
- }, ue = (o) => {
400
- v || r.kind === "numbers" || (r.fit = "none", r.scale = Math.max(t.minScale ?? 0.25, Math.min(o, t.maxScale ?? 4)), I(), y("scalechange", E()));
401
- }, he = (o = "contain") => {
402
- v || r.kind === "numbers" || (r.fit = o, I(), y("scalechange", E()));
403
- }, fe = (o, h) => {
404
- if (v) return () => {
405
- };
406
- const l = n.get(o) ?? /* @__PURE__ */ new Set();
407
- return l.add(h), n.set(o, l), () => {
408
- l.delete(h);
409
- };
410
- }, Y = (o) => {
411
- v || r.kind !== "numbers" || (r.currentSheet = Math.max(0, Math.min(o, Math.max(r.sheetCount - 1, 0))), r.error = null, I(), A(), ce(r.currentSheet), y("sheetchange", E()));
412
- };
413
- return {
414
- preview: de,
415
- refreshFonts() {
416
- if (v || r.loading || !r.document) return;
417
- const o = e.scrollTop, h = e.scrollLeft, l = k.querySelector(".xlsxv-grid"), c = (l == null ? void 0 : l.scrollTop) ?? 0, d = (l == null ? void 0 : l.scrollLeft) ?? 0;
418
- N = [...k.querySelectorAll("table")].map((w) => {
419
- var p;
420
- return ((p = w.tBodies[0]) == null ? void 0 : p.rows.length) ?? j;
421
- });
422
- try {
423
- I();
424
- } finally {
425
- N = void 0;
426
- }
427
- e.scrollTop = o, e.scrollLeft = h;
428
- const m = k.querySelector(".xlsxv-grid");
429
- m && (m.scrollTop = c, m.scrollLeft = d), y("rendered", E());
430
- },
431
- destroy() {
432
- var o;
433
- v || (v = !0, ++R, n.clear(), O(), e.removeEventListener("scroll", W), e.ownerDocument.removeEventListener("scroll", W, !0), (o = e.ownerDocument.defaultView) == null || o.removeEventListener("scroll", W), s.destroy(), e.classList.remove("iworkv-root", "is-loading", "is-error"), e.removeAttribute("data-status"), e.innerHTML = "");
434
- },
435
- setScale: ue,
436
- fit: he,
437
- goToPage(o) {
438
- v || (r.currentPage = Math.max(0, Math.min(o, Math.max(r.pageCount - 1, 0))), r.document && r.document.kind !== "numbers" ? (L.clear(), L.add(r.currentPage), V(), ae(r.currentPage)) : I(), y("pagechange", E()));
439
- },
440
- goToSheet: Y,
441
- next() {
442
- r.kind === "numbers" ? this.goToSheet(Math.min(r.currentSheet + 1, Math.max(r.sheetCount - 1, 0))) : this.goToPage(Math.min(r.currentPage + 1, Math.max(r.pageCount - 1, 0)));
443
- },
444
- prev() {
445
- r.kind === "numbers" ? this.goToSheet(Math.max(0, r.currentSheet - 1)) : this.goToPage(Math.max(0, r.currentPage - 1));
446
- },
447
- getState: E,
448
- on: fe
449
- };
450
- }
451
- function X(e, t) {
452
- return new Promise((n, s) => {
453
- const i = () => s(new DOMException("The operation was aborted.", "AbortError"));
454
- t.addEventListener("abort", i, { once: !0 }), e.then(n, s).finally(() => t.removeEventListener("abort", i)), t.aborted && i();
455
- });
456
- }
457
- function Ie(e, t) {
458
- const n = /* @__PURE__ */ new Map();
459
- for (const s of e.cells) {
460
- if (s.isMergedContinuation)
461
- continue;
462
- const i = s.row + 1, a = n.get(i) ?? { index: i, cells: [] };
463
- a.cells.push({
464
- ref: `${i}:${s.column + 1}`,
465
- row: i,
466
- column: s.column + 1,
467
- value: s.textFrame.paragraphs.map((u) => u.runs.map((g) => g.text).join("")).join(`
468
- `)
469
- }), n.set(i, a);
470
- }
471
- return {
472
- id: e.id,
473
- name: `Table ${t + 1}`,
474
- rows: [...n.values()].sort((s, i) => s.index - i.index),
475
- columnCount: Math.max(e.columns.length, 1),
476
- rowCount: Math.max(e.rows.length, 1)
477
- };
478
- }
479
- function ee(e, t, n) {
480
- var s, i;
481
- if (n)
482
- for (const a of t.cells) {
483
- if (a.isMergedContinuation || a.fill.type !== "picture" || !a.fill.mediaId)
484
- continue;
485
- const u = (i = (s = e.tBodies[0]) == null ? void 0 : s.rows[a.row]) == null ? void 0 : i.cells[a.column + 1];
486
- if (!u || u.querySelector(".iworkv-cell-image"))
487
- continue;
488
- const g = document.createElement("img");
489
- g.className = "iworkv-cell-image", g.src = n.getUrl(a.fill.mediaId), g.alt = "", g.loading = "lazy", u.prepend(g);
490
- }
491
- }
492
- function Re(e) {
493
- if (typeof e == "string")
494
- return Be(e);
495
- if (typeof File < "u" && e instanceof File)
496
- return e.name;
497
- }
498
- function Be(e) {
499
- var i;
500
- const s = (((i = e.split("?")[0]) == null ? void 0 : i.split("#")[0]) ?? "").split(/[\\/]/).filter(Boolean).at(-1);
501
- if (s)
502
- try {
503
- return decodeURIComponent(s);
504
- } catch {
505
- return s;
506
- }
507
- }
508
- function De(e) {
509
- const t = e.ownerDocument.defaultView, n = e.getBoundingClientRect();
510
- let s = t ? 0 : n.top, i = t ? t.innerHeight : n.bottom;
511
- for (let a = e; a; a = a.parentElement) {
512
- const u = (t == null ? void 0 : t.getComputedStyle(a).overflowY) ?? "visible";
513
- if (!/^(auto|scroll|hidden|clip)$/.test(u))
514
- continue;
515
- const g = a.getBoundingClientRect();
516
- s = Math.max(s, g.top), i = Math.min(i, g.bottom);
517
- }
518
- if (i <= s) {
519
- const a = t ? 0 : n.top, u = t ? t.innerHeight : n.bottom;
520
- return {
521
- top: a,
522
- bottom: u,
523
- height: Math.max(u - a, 1)
524
- };
525
- }
526
- return { top: s, bottom: i, height: i - s };
527
- }
528
- function z(e, t, n, s) {
529
- e.style.width = `${t * s}px`, e.style.height = `${n * s}px`, e.style.position = "relative";
530
- const i = e.firstElementChild;
531
- i && (i.style.transform = `scale(${s})`, i.style.transformOrigin = "top left");
532
- }
533
- const te = [
534
- {
535
- extensions: ["key"],
536
- family: "paged",
537
- driverId: "iwork",
538
- targetFormat: "key"
539
- },
540
- {
541
- extensions: ["pages"],
542
- family: "paged",
543
- driverId: "iwork",
544
- targetFormat: "pages"
545
- },
546
- {
547
- extensions: ["numbers"],
548
- family: "workbook",
549
- driverId: "iwork",
550
- targetFormat: "numbers"
551
- }
552
- ];
553
- class We {
554
- constructor(t, n = {}) {
555
- S(this, "viewer");
556
- S(this, "listeners", {
557
- loading: /* @__PURE__ */ new Set(),
558
- rendered: /* @__PURE__ */ new Set(),
559
- error: /* @__PURE__ */ new Set(),
560
- statechange: /* @__PURE__ */ new Set(),
561
- warnings: /* @__PURE__ */ new Set()
562
- });
563
- S(this, "unsubscribes");
564
- S(this, "lastState");
565
- S(this, "destroyed", !1);
566
- S(this, "fontDocument", null);
567
- S(this, "fontScenes", []);
568
- S(this, "fontAnalysis", J([]));
569
- S(this, "fontUpdate", null);
570
- S(this, "fontLoading");
571
- this.host = t, this.viewer = Ae(t, {
572
- fit: re(n.fit),
573
- initialScale: n.initialScale,
574
- minScale: n.minScale,
575
- maxScale: n.maxScale,
576
- virtual: n.virtual
577
- }), this.lastState = ne(this.viewer.getState()), this.unsubscribes = [
578
- this.viewer.on("loadingchange", (s) => {
579
- this.updateState(s), s.loading && this.emit("loading", this.lastState), this.emit("statechange", this.lastState);
580
- }),
581
- this.viewer.on("rendered", (s) => {
582
- this.updateState(s), this.emit("rendered", this.lastState), this.emit("statechange", this.lastState);
583
- }),
584
- this.viewer.on("error", (s) => {
585
- this.updateState(this.viewer.getState()), this.emit("error", s), this.emit("statechange", this.lastState);
586
- }),
587
- this.viewer.on("warnings", () => {
588
- this.updateState(this.viewer.getState()), this.emit("warnings", this.lastState.warnings);
589
- }),
590
- this.viewer.on("pagechange", (s) => {
591
- this.updateState(s), this.emit("statechange", this.lastState);
592
- }),
593
- this.viewer.on("sheetchange", (s) => {
594
- const i = this.lastState.warnings;
595
- this.updateState(s), i.join(`
596
- `) !== this.lastState.warnings.join(`
597
- `) && this.emit("warnings", this.lastState.warnings), this.emit("statechange", this.lastState);
598
- }),
599
- this.viewer.on("scalechange", (s) => {
600
- this.updateState(s), this.emit("statechange", this.lastState);
601
- })
602
- ], this.fontLoading = be(this, t.ownerDocument, n);
603
- }
604
- async load(t, n) {
605
- var s;
606
- this.fontLoading.reset(n.signal, ((s = n.route) == null ? void 0 : s.targetFormat) ?? n.descriptor.extension ?? "key"), this.fontUpdate = null, await this.viewer.preview(t, { signal: n.signal });
607
- }
608
- destroy() {
609
- if (!this.destroyed) {
610
- this.destroyed = !0, this.fontLoading.destroy();
611
- for (const t of this.unsubscribes)
612
- t();
613
- this.viewer.destroy(), this.updateState(this.viewer.getState());
614
- for (const t of Object.values(this.listeners)) t.clear();
615
- }
616
- }
617
- getState() {
618
- var t;
619
- return {
620
- ...this.lastState,
621
- fonts: (t = this.lastState.fonts) == null ? void 0 : t.map((n) => ({ ...n, classification: n.classification ? { ...n.classification } : void 0 })),
622
- warnings: [...this.lastState.warnings]
623
- };
624
- }
625
- fontSlides() {
626
- const t = this.fontScenes.filter((s) => "items" in s), n = this.fontScenes.filter((s) => !("items" in s));
627
- return [...t, { items: n }];
628
- }
629
- getFontReferences() {
630
- return ve(this.fontSlides());
631
- }
632
- refreshFonts(t) {
633
- var s, i;
634
- if (this.destroyed || !this.fontDocument) return;
635
- const n = new Map(t.references.map((a) => {
636
- var u;
637
- return [JSON.stringify([a.fontFamily, (u = a.traits) == null ? void 0 : u.weight, a.fontStyle]), a];
638
- }));
639
- t = { ...t, references: this.getFontReferences().map((a) => {
640
- var u;
641
- return n.get(JSON.stringify([a.fontFamily, (u = a.traits) == null ? void 0 : u.weight, a.fontStyle])) ?? a;
642
- }) }, this.fontUpdate = t, K(this.fontSlides(), t.references), this.fontAnalysis = Z(t, this.host.ownerDocument), this.updateState(this.viewer.getState()), (t.loaded.length || t.relayout) && ((i = (s = this.viewer).refreshFonts) == null || i.call(s)), this.emit("warnings", this.lastState.warnings), this.emit("statechange", this.lastState);
643
- }
644
- on(t, n) {
645
- return this.destroyed ? () => {
646
- } : (this.listeners[t].add(n), () => {
647
- this.listeners[t].delete(n);
648
- });
649
- }
650
- setScale(t) {
651
- this.viewer.setScale(t);
652
- }
653
- fit(t) {
654
- this.viewer.fit(re(t));
655
- }
656
- goToPage(t) {
657
- if (this.viewer.getState().kind === "numbers") {
658
- this.viewer.goToSheet(t);
659
- return;
660
- }
661
- this.viewer.goToPage(t);
662
- }
663
- next() {
664
- this.viewer.next();
665
- }
666
- prev() {
667
- this.viewer.prev();
668
- }
669
- async fullscreen() {
670
- const t = document.fullscreenElement;
671
- if (t === this.host && document.exitFullscreen) {
672
- await document.exitFullscreen();
673
- return;
674
- }
675
- !t && this.host.requestFullscreen && await this.host.requestFullscreen();
676
- }
677
- updateState(t) {
678
- const n = t.document, s = n ? n.kind === "key" ? n.presentation.slides : n.kind === "pages" ? n.pages.map((u) => u.canvas.slide) : n.sheets.map((u) => u.canvas.slide) : [], i = (n == null ? void 0 : n.kind) === "numbers" ? n.sheets.flatMap((u) => u.tables.map((g) => g.item)) : [], a = [...s, ...i];
679
- if (n !== this.fontDocument || a.length !== this.fontScenes.length || a.some((u, g) => u !== this.fontScenes[g])) {
680
- this.fontDocument = n, this.fontScenes = a;
681
- const u = i.length ? [{ items: i }] : [], g = ke([...s, ...u]);
682
- if (this.fontUpdate) {
683
- const R = new Map(this.fontUpdate.references.map((v) => [v.fontFamily, v]));
684
- this.fontAnalysis = Z({ ...this.fontUpdate, references: g.map((v) => R.get(v.fontFamily) ?? v) }, this.host.ownerDocument), K([...s, ...u], this.fontUpdate.references);
685
- } else this.fontAnalysis = J(g, this.host.ownerDocument);
686
- }
687
- this.lastState = {
688
- ...ne(t),
689
- fonts: this.fontAnalysis.fonts.map((u) => ({ ...u, classification: u.classification ? { ...u.classification } : void 0 })),
690
- warnings: [.../* @__PURE__ */ new Set([...t.warnings, ...this.fontAnalysis.warnings])]
691
- };
692
- }
693
- emit(t, n) {
694
- for (const s of this.listeners[t])
695
- s(n);
696
- }
697
- }
698
- function Ve() {
699
- return {
700
- id: "iwork",
701
- family: "paged",
702
- supports: (e) => Oe(e) != null,
703
- createSession: (e, t) => new We(e, t)
704
- };
705
- }
706
- function $e(e = pe()) {
707
- const t = new Set(te.flatMap((n) => n.extensions));
708
- return [
709
- ...te,
710
- ...e.filter((n) => !n.extensions.some((s) => t.has(s)))
711
- ];
712
- }
713
- function ne(e) {
714
- var t, n, s;
715
- return e.kind === "numbers" ? {
716
- loading: e.loading,
717
- error: e.error,
718
- title: ((t = e.document) == null ? void 0 : t.kind) === "numbers" ? (n = e.document.sheets[e.currentSheet]) == null ? void 0 : n.name : void 0,
719
- family: "workbook",
720
- warnings: e.warnings,
721
- capabilities: {
722
- workbook: !0,
723
- sheets: !0,
724
- fullscreen: !0,
725
- download: !0
726
- },
727
- activeSheetIndex: e.currentSheet,
728
- sheets: ((s = e.document) == null ? void 0 : s.kind) === "numbers" ? e.document.sheets.map((i) => ({
729
- id: i.id,
730
- name: i.name
731
- })) : [],
732
- scale: e.scale
733
- } : {
734
- loading: e.loading,
735
- error: e.error,
736
- title: Ne(e),
737
- family: "paged",
738
- warnings: e.warnings,
739
- capabilities: {
740
- paged: !0,
741
- thumbnails: !0,
742
- zoom: !0,
743
- fit: !0,
744
- fullscreen: !0,
745
- download: !0
746
- },
747
- pageIndex: e.currentPage,
748
- pageCount: e.pageCount,
749
- scale: e.scale,
750
- fit: ze(e.fit)
751
- };
752
- }
753
- function Ne(e) {
754
- var n, s, i;
755
- const t = e.document;
756
- if (t)
757
- return t.kind === "key" ? (n = t.slides[e.currentPage]) == null ? void 0 : n.title : t.kind === "pages" ? ((s = t.pages[e.currentPage]) == null ? void 0 : s.canvas.title) ?? t.title : (i = t.sheets[e.currentSheet]) == null ? void 0 : i.name;
758
- }
759
- function re(e) {
760
- return e === "contain" || e === "width" || e === "none" ? e : e === "height" ? "height" : "contain";
761
- }
762
- function ze(e) {
763
- return e === "contain" || e === "width" || e === "height" || e === "none" ? e : "contain";
764
- }
765
- function Oe(e) {
766
- const t = String(e ?? "").trim().replace(/^\./, "").toLowerCase();
767
- return t === "key" || t === "pages" || t === "numbers" ? t : null;
768
- }
769
- export {
770
- $e as a,
771
- Ve as c
772
- };