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.
- package/README.md +13 -7
- package/dist/all-in-one/THIRD-PARTY-NOTICES.txt +870 -0
- package/dist/all-in-one/filens.js +5069 -114897
- package/dist/index.d.ts +2 -0
- package/dist/split/THIRD-PARTY-NOTICES.txt +870 -0
- package/dist/split/chunks/archive-haip2eOP.js +1 -0
- package/dist/split/chunks/browser-video-session-C_14e_mG.js +1 -0
- package/dist/split/chunks/cad-5oTkbaDV.js +7 -0
- package/dist/split/chunks/core-EjELrtsP.js +17 -0
- package/dist/split/chunks/diagram-BRcdlitF.js +1 -0
- package/dist/split/chunks/docx-I39iDYpR.js +1 -0
- package/dist/split/chunks/ebook-BRfadCGl.js +5 -0
- package/dist/split/chunks/index-C4jdVbDq.js +1 -0
- package/dist/split/chunks/index-DkF8PBGR.js +1 -0
- package/dist/split/chunks/iwork-DXq9Adf7.js +4 -0
- package/dist/split/chunks/media-runtime-B6322raw.js +1 -0
- package/dist/split/chunks/mindmap-CyR3TRfx.js +1 -0
- package/dist/split/chunks/model3d-BEt6INTt.js +55 -0
- package/dist/split/chunks/mp4box.all-Bw_Tlr0T-D0URDfA1.js +1 -0
- package/dist/split/chunks/panorama-ChsqnvWC.js +973 -0
- package/dist/split/chunks/pdf-Dzzffz3p.js +12 -0
- package/dist/split/chunks/vendor-C1aIdQ-w.js +4115 -0
- package/dist/split/chunks/xlsx-CITQo0Od.js +3 -0
- package/dist/split/converter-image.wasm +0 -0
- package/dist/split/filens.js +2 -5012
- package/package.json +1 -1
- package/dist/split/chunks/archive-B4jVwD9o.js +0 -921
- package/dist/split/chunks/cad-DMg-lGJX.js +0 -2405
- package/dist/split/chunks/core--zVW212C.js +0 -14627
- package/dist/split/chunks/diagram-CDwCA6LZ.js +0 -654
- package/dist/split/chunks/docx-CuQfFJqr.js +0 -299
- package/dist/split/chunks/ebook-CLlJ8KX3.js +0 -623
- package/dist/split/chunks/iwork-dNVC0X8j.js +0 -772
- package/dist/split/chunks/media-runtime-gcsBQMuo.js +0 -48
- package/dist/split/chunks/mindmap-g0-VoK-K.js +0 -560
- package/dist/split/chunks/model3d-1G1CC52V.js +0 -5093
- package/dist/split/chunks/panorama-D7GVivtM.js +0 -5972
- package/dist/split/chunks/pdf-CecYOWld.js +0 -17898
- package/dist/split/chunks/vendor-DPFNKNkh.js +0 -59575
- package/dist/split/chunks/xlsx-Co26yo-R.js +0 -818
|
@@ -1,623 +0,0 @@
|
|
|
1
|
-
var q = Object.defineProperty;
|
|
2
|
-
var G = (t, e, r) => e in t ? q(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
|
-
var T = (t, e, r) => G(t, typeof e != "symbol" ? e + "" : e, r);
|
|
4
|
-
import { J as N } from "./vendor-DPFNKNkh.js";
|
|
5
|
-
import { c as Z } from "./core--zVW212C.js";
|
|
6
|
-
async function W(t, e) {
|
|
7
|
-
const r = [];
|
|
8
|
-
for (let i = 0; i < t.length; ) {
|
|
9
|
-
if (t.startsWith("/*", i)) {
|
|
10
|
-
i = z(t, i);
|
|
11
|
-
continue;
|
|
12
|
-
}
|
|
13
|
-
if (t[i] === '"' || t[i] === "'") {
|
|
14
|
-
i = L(t, i);
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
let l = i, m = !1;
|
|
18
|
-
if (/^@import(?![\w-])/i.test(t.slice(i, i + 9)) && (m = !0, l = $(t, i + 7), t[l] === '"' || t[l] === "'")) {
|
|
19
|
-
const s = L(t, l);
|
|
20
|
-
t[s - 1] === t[l] && r.push({ start: l, end: s, value: P(t.slice(l + 1, s - 1)), stylesheet: m }), i = s;
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
if ((l === 0 || !/[\w\\-]/.test(t[l - 1])) && /^url\(/i.test(t.slice(l, l + 4))) {
|
|
24
|
-
const s = $(t, l + 4);
|
|
25
|
-
let f = s, u;
|
|
26
|
-
if (t[s] === '"' || t[s] === "'") {
|
|
27
|
-
if (f = L(t, s), t[f - 1] !== t[s]) {
|
|
28
|
-
i = f;
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
u = t.slice(s + 1, f - 1);
|
|
32
|
-
} else {
|
|
33
|
-
for (; f < t.length && t[f] !== ")"; )
|
|
34
|
-
t[f] === "\\" && f++, f++;
|
|
35
|
-
u = t.slice(s, f).trimEnd();
|
|
36
|
-
}
|
|
37
|
-
const h = $(t, f);
|
|
38
|
-
if (t[h] === ")") {
|
|
39
|
-
r.push({ start: s, end: f, value: P(u), stylesheet: m }), i = h + 1;
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
i++;
|
|
44
|
-
}
|
|
45
|
-
const n = [];
|
|
46
|
-
let o = 0;
|
|
47
|
-
for (const i of r) {
|
|
48
|
-
const l = await e(i.value, i.stylesheet);
|
|
49
|
-
l !== void 0 && (n.push(t.slice(o, i.start), X(l)), o = i.end);
|
|
50
|
-
}
|
|
51
|
-
return o ? (n.push(t.slice(o)), n.join("")) : t;
|
|
52
|
-
}
|
|
53
|
-
function z(t, e) {
|
|
54
|
-
const r = t.indexOf("*/", e + 2);
|
|
55
|
-
return r < 0 ? t.length : r + 2;
|
|
56
|
-
}
|
|
57
|
-
function $(t, e) {
|
|
58
|
-
for (; e < t.length; )
|
|
59
|
-
if (/\s/.test(t[e])) e++;
|
|
60
|
-
else if (t.startsWith("/*", e)) e = z(t, e);
|
|
61
|
-
else break;
|
|
62
|
-
return e;
|
|
63
|
-
}
|
|
64
|
-
function L(t, e) {
|
|
65
|
-
const r = t[e++];
|
|
66
|
-
for (; e < t.length; )
|
|
67
|
-
if (t[e] === "\\") e += 2;
|
|
68
|
-
else if (t[e++] === r) return e;
|
|
69
|
-
return t.length;
|
|
70
|
-
}
|
|
71
|
-
function P(t) {
|
|
72
|
-
return t.replace(
|
|
73
|
-
/\\(?:([\da-f]{1,6})(?:\r\n|[\t\n\f\r ])?|(\r\n|[\n\r\f])|(.))/gi,
|
|
74
|
-
(e, r, n, o) => {
|
|
75
|
-
if (r) {
|
|
76
|
-
const i = parseInt(r, 16);
|
|
77
|
-
return String.fromCodePoint(!i || i > 1114111 || i >= 55296 && i <= 57343 ? 65533 : i);
|
|
78
|
-
}
|
|
79
|
-
return n ? "" : o ?? "";
|
|
80
|
-
}
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
function X(t) {
|
|
84
|
-
return `"${t.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/[\n\r\f]/g, (e) => `\\${e.charCodeAt(0).toString(16)} `)}"`;
|
|
85
|
-
}
|
|
86
|
-
function U(t, e) {
|
|
87
|
-
const r = e.split(/[?#]/, 1)[0];
|
|
88
|
-
let n = r;
|
|
89
|
-
try {
|
|
90
|
-
n = decodeURIComponent(r);
|
|
91
|
-
} catch {
|
|
92
|
-
}
|
|
93
|
-
const o = [];
|
|
94
|
-
for (const i of `${n.startsWith("/") ? "" : t + "/"}${n}`.replace(/\\/g, "/").split("/"))
|
|
95
|
-
i === ".." ? o.pop() : i && i !== "." && o.push(i);
|
|
96
|
-
return o.join("/");
|
|
97
|
-
}
|
|
98
|
-
async function _(t, e, r, n, o, i, l) {
|
|
99
|
-
const m = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Set(), h = [];
|
|
100
|
-
for (const c of e) {
|
|
101
|
-
const d = U(r, c.href);
|
|
102
|
-
if (/^(?:application\/xhtml\+xml|text\/html)$/.test(c.mediaType)) {
|
|
103
|
-
u.add(d);
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
const y = t.file(d);
|
|
107
|
-
y && h.push({ path: d, mediaType: c.mediaType, file: y });
|
|
108
|
-
}
|
|
109
|
-
for (let c = 0; c < h.length; c += 8) {
|
|
110
|
-
B(o);
|
|
111
|
-
const d = h.slice(c, c + 8), y = await Promise.all(d.map((k) => k.file.async("arraybuffer")));
|
|
112
|
-
B(o);
|
|
113
|
-
for (const [k, p] of d.entries()) {
|
|
114
|
-
const a = { path: p.path, mediaType: p.mediaType, bytes: y[k] };
|
|
115
|
-
m.set(a.path, a), a.mediaType !== "text/css" && (B(o), s.set(a.path, n(new Blob([a.bytes], { type: a.mediaType }))));
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
async function w(c, d, y) {
|
|
119
|
-
if (B(o), y.has(c)) {
|
|
120
|
-
const g = `Skipped circular EPUB stylesheet import: ${c}.`;
|
|
121
|
-
return l.includes(g) || l.push(g), "data:text/css,";
|
|
122
|
-
}
|
|
123
|
-
if (s.has(c)) return s.get(c);
|
|
124
|
-
if (u.has(c) || /\.(?:xhtml|html?)$/i.test(c)) return;
|
|
125
|
-
const k = `${d ? "stylesheet" : "resource"}:${c}`;
|
|
126
|
-
if (f.has(k)) return f.get(k);
|
|
127
|
-
let p = m.get(c);
|
|
128
|
-
if (!p) {
|
|
129
|
-
const g = t.file(c);
|
|
130
|
-
if (g) {
|
|
131
|
-
const x = await g.async("arraybuffer");
|
|
132
|
-
B(o), p = { path: c, bytes: x, mediaType: j(c) }, m.set(c, p);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
let a = p == null ? void 0 : p.bytes, A = (p == null ? void 0 : p.mediaType) || j(c);
|
|
136
|
-
if (!p && i) {
|
|
137
|
-
const g = await i({
|
|
138
|
-
family: "ebook",
|
|
139
|
-
sourceFormat: "epub",
|
|
140
|
-
source: c,
|
|
141
|
-
relation: d ? "stylesheet" : "resource",
|
|
142
|
-
name: c.split("/").pop() ?? c
|
|
143
|
-
});
|
|
144
|
-
B(o), g && typeof g == "object" && !(g instanceof Blob) && !(g instanceof ArrayBuffer) && !ArrayBuffer.isView(g) ? a = g.source : a = g || void 0;
|
|
145
|
-
}
|
|
146
|
-
let C;
|
|
147
|
-
if (typeof a == "string") C = a;
|
|
148
|
-
else if (a !== void 0)
|
|
149
|
-
if (a instanceof Blob && a.type && (A = a.type), A.split(";", 1)[0] === "text/css" || d) {
|
|
150
|
-
const g = a instanceof Blob ? await a.arrayBuffer() : a instanceof ArrayBuffer ? a : new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
|
|
151
|
-
B(o);
|
|
152
|
-
const x = new Set(y);
|
|
153
|
-
x.add(c);
|
|
154
|
-
const S = await v(V(g, A), J(c), x);
|
|
155
|
-
B(o), C = n(new Blob([S], { type: "text/css;charset=utf-8" }));
|
|
156
|
-
} else if (p || a instanceof Blob) {
|
|
157
|
-
const g = a instanceof Uint8Array ? new Uint8Array(a) : a;
|
|
158
|
-
C = n(a instanceof Blob && a.type ? a : new Blob([g], { type: A }));
|
|
159
|
-
} else {
|
|
160
|
-
const g = a instanceof ArrayBuffer ? new Uint8Array(a) : new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
|
|
161
|
-
let x = "";
|
|
162
|
-
for (const S of g) x += String.fromCharCode(S);
|
|
163
|
-
C = `data:${A};base64,${btoa(x)}`;
|
|
164
|
-
}
|
|
165
|
-
return B(o), f.set(k, C), p && C && s.set(c, C), C;
|
|
166
|
-
}
|
|
167
|
-
async function E(c, d, y = !1, k = /* @__PURE__ */ new Set()) {
|
|
168
|
-
var g, x;
|
|
169
|
-
B(o);
|
|
170
|
-
const p = c.trim();
|
|
171
|
-
if (!p || /^(?:[a-z][a-z0-9+.-]*:|#|\/\/)/i.test(p)) return;
|
|
172
|
-
const a = U(d, p), A = await w(a, y, k);
|
|
173
|
-
if (!A) return;
|
|
174
|
-
const C = ((g = p.match(/[?#].*$/)) == null ? void 0 : g[0]) ?? "";
|
|
175
|
-
return A + (/^(?:blob|data):/i.test(A) ? ((x = C.match(/#.*/)) == null ? void 0 : x[0]) ?? "" : C);
|
|
176
|
-
}
|
|
177
|
-
async function v(c, d, y = /* @__PURE__ */ new Set()) {
|
|
178
|
-
return W(c, (k, p) => E(k, d, p, y));
|
|
179
|
-
}
|
|
180
|
-
return B(o), { resolve: E, rewriteCss: v };
|
|
181
|
-
}
|
|
182
|
-
function J(t) {
|
|
183
|
-
return t.slice(0, Math.max(0, t.lastIndexOf("/")));
|
|
184
|
-
}
|
|
185
|
-
function B(t) {
|
|
186
|
-
if (t != null && t.aborted) throw new DOMException("Ebook preview aborted.", "AbortError");
|
|
187
|
-
}
|
|
188
|
-
function V(t, e) {
|
|
189
|
-
var m, s;
|
|
190
|
-
const r = t instanceof Uint8Array ? t : new Uint8Array(t), n = r[0] === 255 && r[1] === 254 ? "utf-16le" : r[0] === 254 && r[1] === 255 ? "utf-16be" : r[0] === 239 && r[1] === 187 && r[2] === 191 ? "utf-8" : void 0, o = (m = e.match(/;\s*charset\s*=\s*["']?([^;\s"']+)/i)) == null ? void 0 : m[1], i = (s = new TextDecoder("ascii").decode(r.subarray(0, 128)).match(/^@charset "([^"\r\n]+)";/)) == null ? void 0 : s[1], l = n ?? o ?? i ?? "utf-8";
|
|
191
|
-
try {
|
|
192
|
-
return new TextDecoder(l).decode(r);
|
|
193
|
-
} catch {
|
|
194
|
-
return new TextDecoder().decode(r);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
function j(t) {
|
|
198
|
-
var r;
|
|
199
|
-
return {
|
|
200
|
-
css: "text/css",
|
|
201
|
-
otf: "font/otf",
|
|
202
|
-
ttf: "font/ttf",
|
|
203
|
-
woff: "font/woff",
|
|
204
|
-
woff2: "font/woff2",
|
|
205
|
-
avif: "image/avif",
|
|
206
|
-
bmp: "image/bmp",
|
|
207
|
-
gif: "image/gif",
|
|
208
|
-
jpg: "image/jpeg",
|
|
209
|
-
jpeg: "image/jpeg",
|
|
210
|
-
png: "image/png",
|
|
211
|
-
svg: "image/svg+xml",
|
|
212
|
-
webp: "image/webp"
|
|
213
|
-
}[((r = t.split(".").pop()) == null ? void 0 : r.toLowerCase()) ?? ""] ?? "application/octet-stream";
|
|
214
|
-
}
|
|
215
|
-
const K = [
|
|
216
|
-
{
|
|
217
|
-
extensions: ["epub"],
|
|
218
|
-
family: "ebook",
|
|
219
|
-
driverId: "ebook",
|
|
220
|
-
targetFormat: "epub",
|
|
221
|
-
contentTypes: ["application/epub+zip"]
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
extensions: ["cbz"],
|
|
225
|
-
family: "ebook",
|
|
226
|
-
driverId: "ebook",
|
|
227
|
-
targetFormat: "cbz",
|
|
228
|
-
contentTypes: ["application/vnd.comicbook+zip", "application/x-cbz"]
|
|
229
|
-
}
|
|
230
|
-
];
|
|
231
|
-
class Q {
|
|
232
|
-
constructor(e, r = {}) {
|
|
233
|
-
T(this, "listeners", {
|
|
234
|
-
loading: /* @__PURE__ */ new Set(),
|
|
235
|
-
rendered: /* @__PURE__ */ new Set(),
|
|
236
|
-
error: /* @__PURE__ */ new Set(),
|
|
237
|
-
statechange: /* @__PURE__ */ new Set(),
|
|
238
|
-
warnings: /* @__PURE__ */ new Set()
|
|
239
|
-
});
|
|
240
|
-
T(this, "root");
|
|
241
|
-
T(this, "tabs");
|
|
242
|
-
T(this, "stage");
|
|
243
|
-
T(this, "createdUrls", []);
|
|
244
|
-
T(this, "book", null);
|
|
245
|
-
T(this, "frame", null);
|
|
246
|
-
T(this, "loadGeneration", 0);
|
|
247
|
-
T(this, "loadController");
|
|
248
|
-
T(this, "removeAbortListener");
|
|
249
|
-
T(this, "state", {
|
|
250
|
-
loading: !1,
|
|
251
|
-
error: null,
|
|
252
|
-
family: "ebook",
|
|
253
|
-
warnings: [],
|
|
254
|
-
capabilities: {
|
|
255
|
-
chapters: !0,
|
|
256
|
-
search: !0,
|
|
257
|
-
fullscreen: !0,
|
|
258
|
-
download: !0
|
|
259
|
-
},
|
|
260
|
-
location: void 0,
|
|
261
|
-
progress: 0,
|
|
262
|
-
chapterTitle: void 0,
|
|
263
|
-
chapterIndex: 0,
|
|
264
|
-
chapterCount: 0,
|
|
265
|
-
chapters: []
|
|
266
|
-
});
|
|
267
|
-
this.host = e, this.options = r, this.root = document.createElement("div"), this.root.className = "ebookv-preview", this.tabs = document.createElement("div"), this.tabs.className = "ebookv-chapters", this.stage = document.createElement("div"), this.stage.className = "ebookv-stage", this.root.replaceChildren(this.tabs, this.stage), this.host.replaceChildren(this.root);
|
|
268
|
-
}
|
|
269
|
-
async load(e, r) {
|
|
270
|
-
var m, s, f;
|
|
271
|
-
const n = ++this.loadGeneration;
|
|
272
|
-
(m = this.loadController) == null || m.abort(), (s = this.removeAbortListener) == null || s.call(this), this.releaseBook();
|
|
273
|
-
const o = new AbortController();
|
|
274
|
-
this.loadController = o;
|
|
275
|
-
const i = r.signal, l = () => {
|
|
276
|
-
o.abort(), n === this.loadGeneration && (this.releaseBook(), this.state.loading = !1, this.emit("statechange", this.state));
|
|
277
|
-
};
|
|
278
|
-
i == null || i.addEventListener("abort", l, { once: !0 }), this.removeAbortListener = () => i == null ? void 0 : i.removeEventListener("abort", l), this.state = {
|
|
279
|
-
...this.state,
|
|
280
|
-
loading: !0,
|
|
281
|
-
error: null,
|
|
282
|
-
title: r.descriptor.name,
|
|
283
|
-
warnings: [],
|
|
284
|
-
location: void 0,
|
|
285
|
-
progress: 0,
|
|
286
|
-
chapterTitle: void 0,
|
|
287
|
-
chapterIndex: 0,
|
|
288
|
-
chapterCount: 0,
|
|
289
|
-
chapters: []
|
|
290
|
-
}, this.emit("loading", this.state), this.emit("statechange", this.state);
|
|
291
|
-
try {
|
|
292
|
-
i != null && i.aborted && o.abort(), b(o.signal);
|
|
293
|
-
const u = M(((f = r.route) == null ? void 0 : f.sourceFormat) ?? r.descriptor.extension);
|
|
294
|
-
if (u !== "epub" && u !== "cbz")
|
|
295
|
-
throw new Error(`Ebook preview currently supports EPUB and CBZ files, got ${u || "unknown"}.`);
|
|
296
|
-
const h = { ...r, signal: o.signal }, w = (v) => (b(o.signal), this.createObjectUrl(v)), E = u === "cbz" ? await tt(e, h, w) : await Y(e, h, w, this.options.resourceResolver);
|
|
297
|
-
if (n !== this.loadGeneration) return;
|
|
298
|
-
b(o.signal), this.book = E, this.state = {
|
|
299
|
-
...this.state,
|
|
300
|
-
loading: !1,
|
|
301
|
-
error: null,
|
|
302
|
-
title: this.book.title ?? r.descriptor.name,
|
|
303
|
-
warnings: this.book.warnings.slice(),
|
|
304
|
-
chapterCount: this.book.chapters.length,
|
|
305
|
-
chapters: this.book.chapters.map((v) => ({
|
|
306
|
-
id: v.id,
|
|
307
|
-
title: v.title
|
|
308
|
-
}))
|
|
309
|
-
}, this.render(), this.state.warnings.length && this.emit("warnings", this.state.warnings), this.emit("rendered", this.state), this.emit("statechange", this.state);
|
|
310
|
-
} catch (u) {
|
|
311
|
-
if (n !== this.loadGeneration) return;
|
|
312
|
-
this.releaseBook(), this.state.loading = !1, o.signal.aborted && b(o.signal);
|
|
313
|
-
const h = u instanceof Error ? u : new Error(String(u));
|
|
314
|
-
throw this.state.error = h.message, this.emit("error", h), this.emit("statechange", this.state), h;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
destroy() {
|
|
318
|
-
var e, r;
|
|
319
|
-
this.loadGeneration++, (e = this.loadController) == null || e.abort(), (r = this.removeAbortListener) == null || r.call(this), this.releaseBook(), this.state.loading = !1, this.root.replaceChildren(), this.root.parentElement === this.host && this.host.replaceChildren();
|
|
320
|
-
for (const n of Object.values(this.listeners)) n.clear();
|
|
321
|
-
}
|
|
322
|
-
getState() {
|
|
323
|
-
var e;
|
|
324
|
-
return {
|
|
325
|
-
...this.state,
|
|
326
|
-
warnings: this.state.warnings.slice(),
|
|
327
|
-
chapters: ((e = this.state.chapters) == null ? void 0 : e.slice()) ?? []
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
on(e, r) {
|
|
331
|
-
return this.listeners[e].add(r), () => {
|
|
332
|
-
this.listeners[e].delete(r);
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
goToPage(e) {
|
|
336
|
-
this.goToChapter(e);
|
|
337
|
-
}
|
|
338
|
-
next() {
|
|
339
|
-
this.goToChapter(Math.min(this.state.chapterIndex + 1, Math.max(this.state.chapterCount - 1, 0)));
|
|
340
|
-
}
|
|
341
|
-
prev() {
|
|
342
|
-
this.goToChapter(Math.max(this.state.chapterIndex - 1, 0));
|
|
343
|
-
}
|
|
344
|
-
goToChapter(e) {
|
|
345
|
-
var o;
|
|
346
|
-
if (!Number.isInteger(e) || !((o = this.book) != null && o.chapters.length))
|
|
347
|
-
return;
|
|
348
|
-
const r = Math.max(0, Math.min(e, this.book.chapters.length - 1));
|
|
349
|
-
if (r === this.state.chapterIndex && this.frame)
|
|
350
|
-
return;
|
|
351
|
-
const n = this.book.chapters[r];
|
|
352
|
-
this.state.chapterIndex = r, this.state.location = n.href, this.state.chapterTitle = n.title, this.state.progress = this.book.chapters.length <= 1 ? 1 : r / (this.book.chapters.length - 1), this.renderTabs(), this.renderChapter(n), this.emit("statechange", this.state);
|
|
353
|
-
}
|
|
354
|
-
render() {
|
|
355
|
-
this.renderTabs(), this.goToChapter(0);
|
|
356
|
-
}
|
|
357
|
-
renderTabs() {
|
|
358
|
-
this.tabs.replaceChildren();
|
|
359
|
-
for (const [e, r] of this.state.chapters.entries()) {
|
|
360
|
-
const n = document.createElement("button");
|
|
361
|
-
n.type = "button", n.className = "ebookv-chapter-tab", n.classList.toggle("is-active", e === this.state.chapterIndex), n.textContent = r.title, n.addEventListener("click", () => this.goToChapter(e)), this.tabs.appendChild(n);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
renderChapter(e) {
|
|
365
|
-
const r = document.createElement("iframe");
|
|
366
|
-
r.className = "ebookv-frame", r.title = e.title, r.setAttribute("sandbox", "allow-same-origin allow-popups"), r.referrerPolicy = "no-referrer", r.srcdoc = e.html, this.frame = r, this.stage.replaceChildren(r);
|
|
367
|
-
}
|
|
368
|
-
createObjectUrl(e) {
|
|
369
|
-
const r = URL.createObjectURL(e);
|
|
370
|
-
return this.createdUrls.push(r), r;
|
|
371
|
-
}
|
|
372
|
-
releaseBook() {
|
|
373
|
-
this.revokeCreatedUrls(), this.book = null, this.frame = null, this.tabs.replaceChildren(), this.stage.replaceChildren(), this.state.chapterCount = 0, this.state.chapterIndex = 0, this.state.chapters = [], this.state.chapterTitle = void 0, this.state.location = void 0, this.state.progress = 0;
|
|
374
|
-
}
|
|
375
|
-
revokeCreatedUrls() {
|
|
376
|
-
for (; this.createdUrls.length; ) {
|
|
377
|
-
const e = this.createdUrls.pop();
|
|
378
|
-
e && URL.revokeObjectURL(e);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
emit(e, r) {
|
|
382
|
-
for (const n of this.listeners[e])
|
|
383
|
-
n(r);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
function mt() {
|
|
387
|
-
return {
|
|
388
|
-
id: "ebook",
|
|
389
|
-
family: "ebook",
|
|
390
|
-
supports: (t) => ["epub", "cbz"].includes(M(t)),
|
|
391
|
-
createSession: (t, e) => new Q(t, e)
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
function dt(t = Z()) {
|
|
395
|
-
return [
|
|
396
|
-
...K,
|
|
397
|
-
...t.filter((e) => !e.extensions.some((r) => r === "epub" || r === "cbz"))
|
|
398
|
-
];
|
|
399
|
-
}
|
|
400
|
-
async function Y(t, e = {
|
|
401
|
-
descriptor: {
|
|
402
|
-
source: t
|
|
403
|
-
}
|
|
404
|
-
}, r = (o) => URL.createObjectURL(o), n) {
|
|
405
|
-
const o = await R(t, e);
|
|
406
|
-
b(e.signal);
|
|
407
|
-
const i = await N.loadAsync(o);
|
|
408
|
-
b(e.signal);
|
|
409
|
-
const l = [], m = await I(i, "META-INF/container.xml", e.signal);
|
|
410
|
-
if (!m)
|
|
411
|
-
throw new Error("Invalid EPUB: missing META-INF/container.xml.");
|
|
412
|
-
const s = et(m), f = s ? U("", s) : null;
|
|
413
|
-
if (!f)
|
|
414
|
-
throw new Error("Invalid EPUB: missing rootfile path.");
|
|
415
|
-
const u = await I(i, f, e.signal);
|
|
416
|
-
if (!u)
|
|
417
|
-
throw new Error(`Invalid EPUB: missing package document ${f}.`);
|
|
418
|
-
const h = H(f), w = D(u, f), E = rt(w), v = nt(w), c = ot(w, "title"), d = await _(i, E.values(), h, r, e.signal, n, l), y = [];
|
|
419
|
-
for (const k of v) {
|
|
420
|
-
b(e.signal);
|
|
421
|
-
const p = E.get(k);
|
|
422
|
-
if (!p) {
|
|
423
|
-
l.push(`Missing manifest item for spine id ${k}.`);
|
|
424
|
-
continue;
|
|
425
|
-
}
|
|
426
|
-
if (!st(p.mediaType)) {
|
|
427
|
-
l.push(`Skipped non-HTML spine item ${p.href}.`);
|
|
428
|
-
continue;
|
|
429
|
-
}
|
|
430
|
-
const a = U(h, p.href), A = await I(i, a, e.signal);
|
|
431
|
-
if (!A) {
|
|
432
|
-
l.push(`Missing chapter file ${a}.`);
|
|
433
|
-
continue;
|
|
434
|
-
}
|
|
435
|
-
const C = await it(A, p.href, h, d, e.signal);
|
|
436
|
-
y.push({
|
|
437
|
-
id: p.id,
|
|
438
|
-
href: p.href,
|
|
439
|
-
title: C.title ?? p.href,
|
|
440
|
-
html: C.html
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
if (!y.length)
|
|
444
|
-
throw new Error("Invalid EPUB: no readable HTML chapters found.");
|
|
445
|
-
return {
|
|
446
|
-
title: c || void 0,
|
|
447
|
-
chapters: y,
|
|
448
|
-
warnings: l
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
async function tt(t, e = {
|
|
452
|
-
descriptor: {
|
|
453
|
-
source: t
|
|
454
|
-
}
|
|
455
|
-
}, r = (n) => URL.createObjectURL(n)) {
|
|
456
|
-
const n = await R(t, e);
|
|
457
|
-
b(e.signal);
|
|
458
|
-
const o = await N.loadAsync(n);
|
|
459
|
-
b(e.signal);
|
|
460
|
-
const i = new Intl.Collator(void 0, { numeric: !0, sensitivity: "base" }), l = Object.values(o.files).filter((s) => !s.dir && at(s.name)).sort((s, f) => i.compare(s.name, f.name));
|
|
461
|
-
if (!l.length)
|
|
462
|
-
throw new Error("Invalid CBZ: no readable image pages found.");
|
|
463
|
-
const m = [];
|
|
464
|
-
for (let s = 0; s < l.length; s += 8) {
|
|
465
|
-
b(e.signal);
|
|
466
|
-
const f = l.slice(s, s + 8), u = await Promise.all(f.map((h) => h.async("arraybuffer")));
|
|
467
|
-
b(e.signal);
|
|
468
|
-
for (const [h, w] of f.entries()) {
|
|
469
|
-
b(e.signal);
|
|
470
|
-
const E = s + h, v = ct(w.name), c = r(new Blob([u[h]], { type: v })), d = `Page ${E + 1}`;
|
|
471
|
-
m.push({
|
|
472
|
-
id: `page-${E + 1}`,
|
|
473
|
-
title: d,
|
|
474
|
-
href: w.name,
|
|
475
|
-
html: lt(d, c)
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
return {
|
|
480
|
-
title: e.descriptor.name,
|
|
481
|
-
chapters: m,
|
|
482
|
-
warnings: []
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
async function R(t, e) {
|
|
486
|
-
if (b(e.signal), typeof t == "string") {
|
|
487
|
-
const r = await fetch(t, { signal: e.signal });
|
|
488
|
-
if (!r.ok)
|
|
489
|
-
throw new Error(`Failed to load EPUB source: ${r.status} ${r.statusText}`.trim());
|
|
490
|
-
const n = await r.arrayBuffer();
|
|
491
|
-
return b(e.signal), n;
|
|
492
|
-
}
|
|
493
|
-
if (ArrayBuffer.isView(t)) {
|
|
494
|
-
const r = new Uint8Array(t.buffer, t.byteOffset, t.byteLength), n = new Uint8Array(r.byteLength);
|
|
495
|
-
return n.set(r), n.buffer;
|
|
496
|
-
}
|
|
497
|
-
if (t instanceof ArrayBuffer)
|
|
498
|
-
return t;
|
|
499
|
-
if (t instanceof Blob) {
|
|
500
|
-
const r = await t.arrayBuffer();
|
|
501
|
-
return b(e.signal), r;
|
|
502
|
-
}
|
|
503
|
-
return new TextEncoder().encode(String(t)).buffer;
|
|
504
|
-
}
|
|
505
|
-
async function I(t, e, r) {
|
|
506
|
-
b(r);
|
|
507
|
-
const n = t.file(e);
|
|
508
|
-
if (!n)
|
|
509
|
-
return null;
|
|
510
|
-
const o = await n.async("text");
|
|
511
|
-
return b(r), o;
|
|
512
|
-
}
|
|
513
|
-
function et(t) {
|
|
514
|
-
const e = D(t, "container.xml"), r = Array.from(e.getElementsByTagName("*")).find((n) => n.localName === "rootfile");
|
|
515
|
-
return (r == null ? void 0 : r.getAttribute("full-path")) ?? null;
|
|
516
|
-
}
|
|
517
|
-
function rt(t) {
|
|
518
|
-
const e = /* @__PURE__ */ new Map();
|
|
519
|
-
for (const r of Array.from(t.getElementsByTagName("*"))) {
|
|
520
|
-
if (r.localName !== "item")
|
|
521
|
-
continue;
|
|
522
|
-
const n = r.getAttribute("id"), o = r.getAttribute("href"), i = r.getAttribute("media-type") ?? "";
|
|
523
|
-
n && o && e.set(n, {
|
|
524
|
-
id: n,
|
|
525
|
-
href: o,
|
|
526
|
-
mediaType: i
|
|
527
|
-
});
|
|
528
|
-
}
|
|
529
|
-
return e;
|
|
530
|
-
}
|
|
531
|
-
function nt(t) {
|
|
532
|
-
return Array.from(t.getElementsByTagName("*")).filter((e) => e.localName === "itemref").map((e) => e.getAttribute("idref") ?? "").filter(Boolean);
|
|
533
|
-
}
|
|
534
|
-
async function it(t, e, r, n, o) {
|
|
535
|
-
var m, s, f, u;
|
|
536
|
-
b(o);
|
|
537
|
-
const i = new DOMParser().parseFromString(t, "text/html"), l = H(U(r, e));
|
|
538
|
-
if (/\b(?:src|href|poster|style)\b/i.test(t))
|
|
539
|
-
for (const h of Array.from(i.querySelectorAll("[src], [*|href], [poster], [style], style"))) {
|
|
540
|
-
for (const E of ["src", "href", "xlink:href", "poster"]) {
|
|
541
|
-
const v = h.getAttribute(E);
|
|
542
|
-
if (!v) continue;
|
|
543
|
-
const c = h.localName.toLowerCase() === "link" && /(?:^|\s)stylesheet(?:\s|$)/i.test(h.getAttribute("rel") ?? ""), d = await n.resolve(v, l, c);
|
|
544
|
-
d && h.setAttribute(E, d);
|
|
545
|
-
}
|
|
546
|
-
h.localName.toLowerCase() === "style" && (h.textContent = await n.rewriteCss(h.textContent ?? "", l));
|
|
547
|
-
const w = h.getAttribute("style");
|
|
548
|
-
w !== null && h.setAttribute("style", await n.rewriteCss(w, l));
|
|
549
|
-
}
|
|
550
|
-
return b(o), {
|
|
551
|
-
title: ((s = (m = i.querySelector("title")) == null ? void 0 : m.textContent) == null ? void 0 : s.trim()) || ((u = (f = i.querySelector("h1,h2,h3")) == null ? void 0 : f.textContent) == null ? void 0 : u.trim()) || void 0,
|
|
552
|
-
html: `<!doctype html>${i.documentElement.outerHTML}`
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
function b(t) {
|
|
556
|
-
if (t != null && t.aborted) throw new DOMException("Ebook preview aborted.", "AbortError");
|
|
557
|
-
}
|
|
558
|
-
function D(t, e) {
|
|
559
|
-
const r = new DOMParser().parseFromString(t, "application/xml");
|
|
560
|
-
if (r.getElementsByTagName("parsererror")[0])
|
|
561
|
-
throw new Error(`Invalid XML in ${e}.`);
|
|
562
|
-
return r;
|
|
563
|
-
}
|
|
564
|
-
function ot(t, e) {
|
|
565
|
-
var n;
|
|
566
|
-
const r = Array.from(t.getElementsByTagName("*")).find((o) => o.localName === e);
|
|
567
|
-
return ((n = r == null ? void 0 : r.textContent) == null ? void 0 : n.trim()) ?? "";
|
|
568
|
-
}
|
|
569
|
-
function st(t) {
|
|
570
|
-
return t === "application/xhtml+xml" || t === "text/html";
|
|
571
|
-
}
|
|
572
|
-
function at(t) {
|
|
573
|
-
return /\.(?:avif|bmp|gif|jpe?g|png|svg|webp)$/i.test(t);
|
|
574
|
-
}
|
|
575
|
-
function ct(t) {
|
|
576
|
-
const e = M(t.split(".").pop());
|
|
577
|
-
return {
|
|
578
|
-
avif: "image/avif",
|
|
579
|
-
bmp: "image/bmp",
|
|
580
|
-
gif: "image/gif",
|
|
581
|
-
jpg: "image/jpeg",
|
|
582
|
-
jpeg: "image/jpeg",
|
|
583
|
-
png: "image/png",
|
|
584
|
-
svg: "image/svg+xml",
|
|
585
|
-
webp: "image/webp"
|
|
586
|
-
}[e] ?? "application/octet-stream";
|
|
587
|
-
}
|
|
588
|
-
function lt(t, e) {
|
|
589
|
-
return `<!doctype html><html><head><meta charset="utf-8"><title>${F(t)}</title><style>
|
|
590
|
-
html,body{margin:0;min-height:100%;background:#111827;color:#f8fafc;font-family:system-ui,sans-serif;}
|
|
591
|
-
body{display:flex;align-items:center;justify-content:center;}
|
|
592
|
-
img{display:block;max-width:100%;max-height:100vh;width:auto;height:auto;object-fit:contain;}
|
|
593
|
-
</style></head><body><img src="${O(e)}" alt="${O(t)}"></body></html>`;
|
|
594
|
-
}
|
|
595
|
-
function F(t) {
|
|
596
|
-
return t.replace(/[&<>]/g, (e) => ({ "&": "&", "<": "<", ">": ">" })[e] ?? e);
|
|
597
|
-
}
|
|
598
|
-
function O(t) {
|
|
599
|
-
return F(t).replace(/"/g, """);
|
|
600
|
-
}
|
|
601
|
-
function H(t) {
|
|
602
|
-
const e = ft(t), r = e.lastIndexOf("/");
|
|
603
|
-
return r > 0 ? e.slice(0, r) : "";
|
|
604
|
-
}
|
|
605
|
-
function ft(t) {
|
|
606
|
-
const e = [];
|
|
607
|
-
for (const r of t.replace(/\\/g, "/").split("/"))
|
|
608
|
-
if (!(!r || r === ".")) {
|
|
609
|
-
if (r === "..") {
|
|
610
|
-
e.pop();
|
|
611
|
-
continue;
|
|
612
|
-
}
|
|
613
|
-
e.push(r);
|
|
614
|
-
}
|
|
615
|
-
return e.join("/");
|
|
616
|
-
}
|
|
617
|
-
function M(t) {
|
|
618
|
-
return String(t ?? "").trim().replace(/^\./, "").toLowerCase();
|
|
619
|
-
}
|
|
620
|
-
export {
|
|
621
|
-
dt as a,
|
|
622
|
-
mt as c
|
|
623
|
-
};
|