react-book-reader 1.1.7 → 1.1.8
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/lib/overlayer.js +175 -0
- package/lib/react-book-reader.es.js +6588 -918
- package/package.json +65 -64
- package/lib/comic-book-D8f_Cc7Q.js +0 -25
- package/lib/epub-vizLT02-.js +0 -681
- package/lib/fb2-DCqZtzQ5.js +0 -258
- package/lib/fflate-CExlDunL.js +0 -139
- package/lib/fixed-layout-CMyaX9h8.js +0 -195
- package/lib/mobi-CikMBloG.js +0 -960
- package/lib/paginator-CpnI4Urk.js +0 -748
- package/lib/pdf-D5_pBBCO.js +0 -109
- package/lib/search-aqQXTfxz.js +0 -72
- package/lib/tts-UQB-k9b_.js +0 -212
- package/lib/view-Ht0IwIBs.js +0 -774
- package/lib/zip-Bw0cufIw.js +0 -1509
package/lib/view-Ht0IwIBs.js
DELETED
|
@@ -1,774 +0,0 @@
|
|
|
1
|
-
const K = (n, t) => n.map((e, s, i) => t(e, s, i) ? s : null).filter((e) => e != null), B = (n, t) => [-1, ...t, n.length].reduce(({ xs: e, a: s }, i) => ({ xs: e?.concat([n.slice(s + 1, i)]) ?? [], a: i }), {}).xs, G = (n, t) => n.slice(0, -1).concat([n[n.length - 1].concat(t[0])]).concat(t.slice(1)), C = /\d/, x = /^epubcfi\((.*)\)$/, N = (n) => n.replace(/[\^[\](),;=]/g, "^$&"), $ = (n) => x.test(n) ? n : `epubcfi(${n})`, q = (n) => n.match(x)?.[1] ?? n, X = (n) => (...t) => `epubcfi(${n(...t.map((e) => e.match(x)?.[1] ?? e))})`, Q = X((...n) => n.join("!")), Y = (n) => {
|
|
2
|
-
const t = [];
|
|
3
|
-
let e, s, i = "";
|
|
4
|
-
const o = (a) => (t.push(a), e = null, i = ""), r = (a) => (i += a, s = !1);
|
|
5
|
-
for (const a of Array.from(n.trim()).concat("")) {
|
|
6
|
-
if (a === "^" && !s) {
|
|
7
|
-
s = !0;
|
|
8
|
-
continue;
|
|
9
|
-
}
|
|
10
|
-
if (e === "!") o(["!"]);
|
|
11
|
-
else if (e === ",") o([","]);
|
|
12
|
-
else if (e === "/" || e === ":")
|
|
13
|
-
if (C.test(a)) {
|
|
14
|
-
r(a);
|
|
15
|
-
continue;
|
|
16
|
-
} else o([e, parseInt(i)]);
|
|
17
|
-
else if (e === "~")
|
|
18
|
-
if (C.test(a) || a === ".") {
|
|
19
|
-
r(a);
|
|
20
|
-
continue;
|
|
21
|
-
} else o(["~", parseFloat(i)]);
|
|
22
|
-
else if (e === "@") {
|
|
23
|
-
if (a === ":") {
|
|
24
|
-
o(["@", parseFloat(i)]), e = "@";
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
if (C.test(a) || a === ".") {
|
|
28
|
-
r(a);
|
|
29
|
-
continue;
|
|
30
|
-
} else o(["@", parseFloat(i)]);
|
|
31
|
-
} else if (e === "[") {
|
|
32
|
-
a === ";" && !s ? (o(["[", i]), e = ";") : a === "," && !s ? (o(["[", i]), e = "[") : a === "]" && !s ? o(["[", i]) : r(a);
|
|
33
|
-
continue;
|
|
34
|
-
} else if (e?.startsWith(";")) {
|
|
35
|
-
a === "=" && !s ? (e = `;${i}`, i = "") : a === ";" && !s ? (o([e, i]), e = ";") : a === "]" && !s ? o([e, i]) : r(a);
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
(a === "/" || a === ":" || a === "~" || a === "@" || a === "[" || a === "!" || a === ",") && (e = a);
|
|
39
|
-
}
|
|
40
|
-
return t;
|
|
41
|
-
}, M = (n, t) => K(n, ([e]) => e === t), tt = (n) => {
|
|
42
|
-
const t = [];
|
|
43
|
-
let e;
|
|
44
|
-
for (const [s, i] of n) {
|
|
45
|
-
if (s === "/") t.push({ index: i });
|
|
46
|
-
else {
|
|
47
|
-
const o = t[t.length - 1];
|
|
48
|
-
if (s === ":") o.offset = i;
|
|
49
|
-
else if (s === "~") o.temporal = i;
|
|
50
|
-
else if (s === "@") o.spatial = (o.spatial ?? []).concat(i);
|
|
51
|
-
else if (s === ";s") o.side = i;
|
|
52
|
-
else if (s === "[")
|
|
53
|
-
if (e === "/" && i) o.id = i;
|
|
54
|
-
else {
|
|
55
|
-
o.text = (o.text ?? []).concat(i);
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
e = s;
|
|
60
|
-
}
|
|
61
|
-
return t;
|
|
62
|
-
}, k = (n) => B(n, M(n, "!")).map(tt), b = (n) => {
|
|
63
|
-
const t = Y(q(n)), e = M(t, ",");
|
|
64
|
-
if (!e.length) return k(t);
|
|
65
|
-
const [s, i, o] = B(t, e).map(k);
|
|
66
|
-
return { parent: s, start: i, end: o };
|
|
67
|
-
}, et = ({ index: n, id: t, offset: e, temporal: s, spatial: i, text: o, side: r }) => {
|
|
68
|
-
const a = r ? `;s=${r}` : "";
|
|
69
|
-
return `/${n}` + (t ? `[${N(t)}${a}]` : "") + (e != null && n % 2 ? `:${e}` : "") + (s ? `~${s}` : "") + (i ? `@${i.join(":")}` : "") + (o || !t && r ? "[" + (o?.map(N)?.join(",") ?? "") + a + "]" : "");
|
|
70
|
-
}, W = (n) => n.parent ? [n.parent, n.start, n.end].map(W).join(",") : n.map((t) => t.map(et).join("")).join("!"), E = (n) => $(W(n)), m = (n, t) => typeof n == "string" ? E(m(b(n), t)) : n.parent ? G(n.parent, n[t ? "end" : "start"]) : n, st = (n, t) => {
|
|
71
|
-
typeof n == "string" && (n = b(n)), typeof t == "string" && (t = b(t)), n = m(n), t = m(t, !0);
|
|
72
|
-
const e = n[n.length - 1], s = t[t.length - 1], i = [], o = [], r = [];
|
|
73
|
-
let a = !0;
|
|
74
|
-
const h = Math.max(e.length, s.length);
|
|
75
|
-
for (let l = 0; l < h; l++) {
|
|
76
|
-
const d = e[l], f = s[l];
|
|
77
|
-
a &&= d?.index === f?.index && !d?.offset && !f?.offset, a ? i.push(d) : (d && o.push(d), f && r.push(f));
|
|
78
|
-
}
|
|
79
|
-
const c = n.slice(0, -1).concat([i]);
|
|
80
|
-
return E({ parent: c, start: [o], end: [r] });
|
|
81
|
-
}, F = ({ nodeType: n }) => n === 3 || n === 4, v = ({ nodeType: n }) => n === 1, D = (n, t) => {
|
|
82
|
-
const e = Array.from(n.childNodes).filter((s) => F(s) || v(s));
|
|
83
|
-
return t ? e.map((s) => {
|
|
84
|
-
const i = t(s);
|
|
85
|
-
return i === NodeFilter.FILTER_REJECT ? null : i === NodeFilter.FILTER_SKIP ? D(s, t) : s;
|
|
86
|
-
}).flat().filter((s) => s) : e;
|
|
87
|
-
}, I = (n, t) => {
|
|
88
|
-
const e = D(n, t).reduce((s, i) => {
|
|
89
|
-
let o = s[s.length - 1];
|
|
90
|
-
return o ? F(i) ? Array.isArray(o) ? o.push(i) : F(o) ? s[s.length - 1] = [o, i] : s.push(i) : v(o) ? s.push(null, i) : s.push(i) : s.push(i), s;
|
|
91
|
-
}, []);
|
|
92
|
-
return v(e[0]) && e.unshift("first"), v(e[e.length - 1]) && e.push("last"), e.unshift("before"), e.push("after"), e;
|
|
93
|
-
}, S = (n, t, e) => {
|
|
94
|
-
const { id: s } = t[t.length - 1];
|
|
95
|
-
if (s) {
|
|
96
|
-
const r = n.ownerDocument.getElementById(s);
|
|
97
|
-
if (r) return { node: r, offset: 0 };
|
|
98
|
-
}
|
|
99
|
-
for (const { index: r } of t) {
|
|
100
|
-
const a = n ? I(n, e)[r] : null;
|
|
101
|
-
if (a === "first") return { node: n.firstChild ?? n };
|
|
102
|
-
if (a === "last") return { node: n.lastChild ?? n };
|
|
103
|
-
if (a === "before") return { node: n, before: !0 };
|
|
104
|
-
if (a === "after") return { node: n, after: !0 };
|
|
105
|
-
n = a;
|
|
106
|
-
}
|
|
107
|
-
const { offset: i } = t[t.length - 1];
|
|
108
|
-
if (!Array.isArray(n)) return { node: n, offset: i };
|
|
109
|
-
let o = 0;
|
|
110
|
-
for (const r of n) {
|
|
111
|
-
const { length: a } = r.nodeValue;
|
|
112
|
-
if (o + a >= i) return { node: r, offset: i - o };
|
|
113
|
-
o += a;
|
|
114
|
-
}
|
|
115
|
-
}, A = (n, t, e) => {
|
|
116
|
-
const { parentNode: s, id: i } = n, o = I(s, e), r = o.findIndex((c) => Array.isArray(c) ? c.some((l) => l === n) : c === n), a = o[r];
|
|
117
|
-
if (Array.isArray(a)) {
|
|
118
|
-
let c = 0;
|
|
119
|
-
for (const l of a)
|
|
120
|
-
if (l === n) {
|
|
121
|
-
c += t;
|
|
122
|
-
break;
|
|
123
|
-
} else c += l.nodeValue.length;
|
|
124
|
-
t = c;
|
|
125
|
-
}
|
|
126
|
-
const h = { id: i, index: r, offset: t };
|
|
127
|
-
return (s !== n.ownerDocument.documentElement ? A(s, null, e).concat(h) : [h]).filter((c) => c.index !== -1);
|
|
128
|
-
}, nt = (n, t) => {
|
|
129
|
-
const { startContainer: e, startOffset: s, endContainer: i, endOffset: o } = n, r = A(e, s, t);
|
|
130
|
-
if (n.collapsed) return E([r]);
|
|
131
|
-
const a = A(i, o, t);
|
|
132
|
-
return st([r], [a]);
|
|
133
|
-
}, it = (n, t, e) => {
|
|
134
|
-
const s = m(t), i = m(t, !0), o = n.documentElement, r = S(o, s[0], e), a = S(o, i[0], e), h = n.createRange();
|
|
135
|
-
return r.before ? h.setStartBefore(r.node) : r.after ? h.setStartAfter(r.node) : h.setStart(r.node, r.offset), a.before ? h.setEndBefore(a.node) : a.after ? h.setEndAfter(a.node) : h.setEnd(a.node, a.offset), h;
|
|
136
|
-
}, At = (n) => {
|
|
137
|
-
const t = [], { parentNode: e } = n[0], s = A(e);
|
|
138
|
-
for (const [i, o] of I(e).entries()) {
|
|
139
|
-
const r = n[t.length];
|
|
140
|
-
o === r && t.push(E([s.concat({ id: r.id, index: i })]));
|
|
141
|
-
}
|
|
142
|
-
return t;
|
|
143
|
-
}, xt = (n, t) => S(n.documentElement, m(t)).node, z = {
|
|
144
|
-
fromIndex: (n) => $(`/6/${(n + 1) * 2}`),
|
|
145
|
-
toIndex: (n) => n?.at(-1).index / 2 - 1
|
|
146
|
-
}, ot = (n) => {
|
|
147
|
-
let t = 0;
|
|
148
|
-
const e = (s) => {
|
|
149
|
-
if (s.id = t++, s.subitems) for (const i of s.subitems) e(i);
|
|
150
|
-
};
|
|
151
|
-
for (const s of n) e(s);
|
|
152
|
-
return n;
|
|
153
|
-
}, j = (n) => n.map((t) => t.subitems?.length ? [t, j(t.subitems)].flat() : t).flat();
|
|
154
|
-
class L {
|
|
155
|
-
async init({ toc: t, ids: e, splitHref: s, getFragment: i }) {
|
|
156
|
-
ot(t);
|
|
157
|
-
const o = j(t), r = /* @__PURE__ */ new Map();
|
|
158
|
-
for (const [h, c] of o.entries()) {
|
|
159
|
-
const [l, d] = await s(c?.href) ?? [], f = { fragment: d, item: c };
|
|
160
|
-
r.has(l) ? r.get(l).items.push(f) : r.set(l, { prev: o[h - 1], items: [f] });
|
|
161
|
-
}
|
|
162
|
-
const a = /* @__PURE__ */ new Map();
|
|
163
|
-
for (const [h, c] of e.entries())
|
|
164
|
-
r.has(c) ? a.set(c, r.get(c)) : a.set(c, a.get(e[h - 1]));
|
|
165
|
-
this.ids = e, this.map = a, this.getFragment = i;
|
|
166
|
-
}
|
|
167
|
-
getProgress(t, e) {
|
|
168
|
-
if (!this.ids) return;
|
|
169
|
-
const s = this.ids[t], i = this.map.get(s);
|
|
170
|
-
if (!i) return null;
|
|
171
|
-
const { prev: o, items: r } = i;
|
|
172
|
-
if (!r) return o;
|
|
173
|
-
if (!e || r.length === 1 && !r[0].fragment) return r[0].item;
|
|
174
|
-
const a = e.startContainer.getRootNode();
|
|
175
|
-
for (const [h, { fragment: c }] of r.entries()) {
|
|
176
|
-
const l = this.getFragment(a, c);
|
|
177
|
-
if (l && e.comparePoint(l, 0) > 0)
|
|
178
|
-
return r[h - 1]?.item ?? o;
|
|
179
|
-
}
|
|
180
|
-
return r[r.length - 1].item;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
class rt {
|
|
184
|
-
constructor(t, e, s) {
|
|
185
|
-
this.sizes = t.map((i) => i.linear != "no" && i.size > 0 ? i.size : 0), this.sizePerLoc = e, this.sizePerTimeUnit = s, this.sizeTotal = this.sizes.reduce((i, o) => i + o, 0), this.sectionFractions = this.#e();
|
|
186
|
-
}
|
|
187
|
-
#e() {
|
|
188
|
-
const { sizeTotal: t } = this, e = [0];
|
|
189
|
-
let s = 0;
|
|
190
|
-
for (const i of this.sizes) e.push((s += i) / t);
|
|
191
|
-
return e;
|
|
192
|
-
}
|
|
193
|
-
// get progress given index of and fractions within a section
|
|
194
|
-
getProgress(t, e, s = 0) {
|
|
195
|
-
const { sizes: i, sizePerLoc: o, sizePerTimeUnit: r, sizeTotal: a } = this, h = i[t] ?? 0, l = i.slice(0, t).reduce((p, w) => p + w, 0) + e * h, d = l + s * h, f = a - l, u = (1 - e) * h;
|
|
196
|
-
return {
|
|
197
|
-
fraction: d / a,
|
|
198
|
-
section: {
|
|
199
|
-
current: t,
|
|
200
|
-
total: i.length
|
|
201
|
-
},
|
|
202
|
-
location: {
|
|
203
|
-
current: Math.floor(l / o),
|
|
204
|
-
next: Math.floor(d / o),
|
|
205
|
-
total: Math.ceil(a / o)
|
|
206
|
-
},
|
|
207
|
-
time: {
|
|
208
|
-
section: u / r,
|
|
209
|
-
total: f / r
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
// the inverse of `getProgress`
|
|
214
|
-
// get index of and fraction in section based on total fraction
|
|
215
|
-
getSection(t) {
|
|
216
|
-
if (t <= 0) return [0, 0];
|
|
217
|
-
if (t >= 1) return [this.sizes.length - 1, 1];
|
|
218
|
-
t = t + Number.EPSILON;
|
|
219
|
-
const { sizeTotal: e } = this;
|
|
220
|
-
let s = this.sectionFractions.findIndex((o) => o > t) - 1;
|
|
221
|
-
if (s < 0) return [0, 0];
|
|
222
|
-
for (; !this.sizes[s]; ) s++;
|
|
223
|
-
const i = (t - this.sectionFractions[s]) / (this.sizes[s] / e);
|
|
224
|
-
return [s, i];
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
const g = (n) => document.createElementNS("http://www.w3.org/2000/svg", n);
|
|
228
|
-
class R {
|
|
229
|
-
#e = g("svg");
|
|
230
|
-
#t = /* @__PURE__ */ new Map();
|
|
231
|
-
constructor() {
|
|
232
|
-
Object.assign(this.#e.style, {
|
|
233
|
-
position: "absolute",
|
|
234
|
-
top: "0",
|
|
235
|
-
left: "0",
|
|
236
|
-
width: "100%",
|
|
237
|
-
height: "100%",
|
|
238
|
-
pointerEvents: "none"
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
get element() {
|
|
242
|
-
return this.#e;
|
|
243
|
-
}
|
|
244
|
-
add(t, e, s, i) {
|
|
245
|
-
this.#t.has(t) && this.remove(t), typeof e == "function" && (e = e(this.#e.getRootNode()));
|
|
246
|
-
const o = e.getClientRects(), r = s(o, i);
|
|
247
|
-
this.#e.append(r), this.#t.set(t, { range: e, draw: s, options: i, element: r, rects: o });
|
|
248
|
-
}
|
|
249
|
-
remove(t) {
|
|
250
|
-
this.#t.has(t) && (this.#e.removeChild(this.#t.get(t).element), this.#t.delete(t));
|
|
251
|
-
}
|
|
252
|
-
redraw() {
|
|
253
|
-
for (const t of this.#t.values()) {
|
|
254
|
-
const { range: e, draw: s, options: i, element: o } = t;
|
|
255
|
-
this.#e.removeChild(o);
|
|
256
|
-
const r = e.getClientRects(), a = s(r, i);
|
|
257
|
-
this.#e.append(a), t.element = a, t.rects = r;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
hitTest({ x: t, y: e }) {
|
|
261
|
-
const s = Array.from(this.#t.entries());
|
|
262
|
-
for (let i = s.length - 1; i >= 0; i--) {
|
|
263
|
-
const [o, r] = s[i];
|
|
264
|
-
for (const { left: a, top: h, right: c, bottom: l } of r.rects)
|
|
265
|
-
if (h <= e && a <= t && l > e && c > t)
|
|
266
|
-
return [o, r.range];
|
|
267
|
-
}
|
|
268
|
-
return [];
|
|
269
|
-
}
|
|
270
|
-
static underline(t, e = {}) {
|
|
271
|
-
const { color: s = "red", width: i = 2, writingMode: o } = e, r = g("g");
|
|
272
|
-
if (r.setAttribute("fill", s), o === "vertical-rl" || o === "vertical-lr")
|
|
273
|
-
for (const { right: a, top: h, height: c } of t) {
|
|
274
|
-
const l = g("rect");
|
|
275
|
-
l.setAttribute("x", a - i), l.setAttribute("y", h), l.setAttribute("height", c), l.setAttribute("width", i), r.append(l);
|
|
276
|
-
}
|
|
277
|
-
else for (const { left: a, bottom: h, width: c } of t) {
|
|
278
|
-
const l = g("rect");
|
|
279
|
-
l.setAttribute("x", a), l.setAttribute("y", h - i), l.setAttribute("height", i), l.setAttribute("width", c), r.append(l);
|
|
280
|
-
}
|
|
281
|
-
return r;
|
|
282
|
-
}
|
|
283
|
-
static strikethrough(t, e = {}) {
|
|
284
|
-
const { color: s = "red", width: i = 2, writingMode: o } = e, r = g("g");
|
|
285
|
-
if (r.setAttribute("fill", s), o === "vertical-rl" || o === "vertical-lr")
|
|
286
|
-
for (const { right: a, left: h, top: c, height: l } of t) {
|
|
287
|
-
const d = g("rect");
|
|
288
|
-
d.setAttribute("x", (a + h) / 2), d.setAttribute("y", c), d.setAttribute("height", l), d.setAttribute("width", i), r.append(d);
|
|
289
|
-
}
|
|
290
|
-
else for (const { left: a, top: h, bottom: c, width: l } of t) {
|
|
291
|
-
const d = g("rect");
|
|
292
|
-
d.setAttribute("x", a), d.setAttribute("y", (h + c) / 2), d.setAttribute("height", i), d.setAttribute("width", l), r.append(d);
|
|
293
|
-
}
|
|
294
|
-
return r;
|
|
295
|
-
}
|
|
296
|
-
static squiggly(t, e = {}) {
|
|
297
|
-
const { color: s = "red", width: i = 2, writingMode: o } = e, r = g("g");
|
|
298
|
-
r.setAttribute("fill", "none"), r.setAttribute("stroke", s), r.setAttribute("stroke-width", i);
|
|
299
|
-
const a = i * 1.5;
|
|
300
|
-
if (o === "vertical-rl" || o === "vertical-lr")
|
|
301
|
-
for (const { right: h, top: c, height: l } of t) {
|
|
302
|
-
const d = g("path"), f = Math.round(l / a / 1.5), u = l / f, p = Array.from(
|
|
303
|
-
{ length: f },
|
|
304
|
-
(w, T) => `l${T % 2 ? -a : a} ${u}`
|
|
305
|
-
).join("");
|
|
306
|
-
d.setAttribute("d", `M${h} ${c}${p}`), r.append(d);
|
|
307
|
-
}
|
|
308
|
-
else for (const { left: h, bottom: c, width: l } of t) {
|
|
309
|
-
const d = g("path"), f = Math.round(l / a / 1.5), u = l / f, p = Array.from(
|
|
310
|
-
{ length: f },
|
|
311
|
-
(w, T) => `l${u} ${T % 2 ? a : -a}`
|
|
312
|
-
).join("");
|
|
313
|
-
d.setAttribute("d", `M${h} ${c}${p}`), r.append(d);
|
|
314
|
-
}
|
|
315
|
-
return r;
|
|
316
|
-
}
|
|
317
|
-
static highlight(t, e = {}) {
|
|
318
|
-
const { color: s = "red" } = e, i = g("g");
|
|
319
|
-
i.setAttribute("fill", s), i.style.opacity = "var(--overlayer-highlight-opacity, .3)", i.style.mixBlendMode = "var(--overlayer-highlight-blend-mode, normal)";
|
|
320
|
-
for (const { left: o, top: r, height: a, width: h } of t) {
|
|
321
|
-
const c = g("rect");
|
|
322
|
-
c.setAttribute("x", o), c.setAttribute("y", r), c.setAttribute("height", a), c.setAttribute("width", h), i.append(c);
|
|
323
|
-
}
|
|
324
|
-
return i;
|
|
325
|
-
}
|
|
326
|
-
static outline(t, e = {}) {
|
|
327
|
-
const { color: s = "red", width: i = 3, radius: o = 3 } = e, r = g("g");
|
|
328
|
-
r.setAttribute("fill", "none"), r.setAttribute("stroke", s), r.setAttribute("stroke-width", i);
|
|
329
|
-
for (const { left: a, top: h, height: c, width: l } of t) {
|
|
330
|
-
const d = g("rect");
|
|
331
|
-
d.setAttribute("x", a), d.setAttribute("y", h), d.setAttribute("height", c), d.setAttribute("width", l), d.setAttribute("rx", o), r.append(d);
|
|
332
|
-
}
|
|
333
|
-
return r;
|
|
334
|
-
}
|
|
335
|
-
// make an exact copy of an image in the overlay
|
|
336
|
-
// one can then apply filters to the entire element, without affecting them;
|
|
337
|
-
// it's a bit silly and probably better to just invert images twice
|
|
338
|
-
// (though the color will be off in that case if you do heu-rotate)
|
|
339
|
-
static copyImage([t], e = {}) {
|
|
340
|
-
const { src: s } = e, i = g("image"), { left: o, top: r, height: a, width: h } = t;
|
|
341
|
-
return i.setAttribute("href", s), i.setAttribute("x", o), i.setAttribute("y", r), i.setAttribute("height", a), i.setAttribute("width", h), i;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
const at = (n, t) => {
|
|
345
|
-
const e = [];
|
|
346
|
-
for (let s = t.currentNode; s; s = t.nextNode()) {
|
|
347
|
-
const i = n.comparePoint(s, 0);
|
|
348
|
-
if (i === 0) e.push(s);
|
|
349
|
-
else if (i > 0) break;
|
|
350
|
-
}
|
|
351
|
-
return e;
|
|
352
|
-
}, ct = (n, t) => {
|
|
353
|
-
const e = [];
|
|
354
|
-
for (let s = t.nextNode(); s; s = t.nextNode())
|
|
355
|
-
e.push(s);
|
|
356
|
-
return e;
|
|
357
|
-
}, lt = NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_CDATA_SECTION, ht = (n) => {
|
|
358
|
-
if (n.nodeType === 1) {
|
|
359
|
-
const t = n.tagName.toLowerCase();
|
|
360
|
-
return t === "script" || t === "style" ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_SKIP;
|
|
361
|
-
}
|
|
362
|
-
return NodeFilter.FILTER_ACCEPT;
|
|
363
|
-
}, O = function* (n, t, e) {
|
|
364
|
-
const s = n.commonAncestorContainer ?? n.body ?? n, i = document.createTreeWalker(s, lt, { acceptNode: e || ht }), r = (n.commonAncestorContainer ? at : ct)(n, i), a = r.map((c) => c.nodeValue), h = (c, l, d, f) => {
|
|
365
|
-
const u = document.createRange();
|
|
366
|
-
return u.setStart(r[c], l), u.setEnd(r[d], f), u;
|
|
367
|
-
};
|
|
368
|
-
for (const c of t(a, h)) yield c;
|
|
369
|
-
}, y = "foliate-search:", dt = async (n) => {
|
|
370
|
-
const t = new Uint8Array(await n.slice(0, 4).arrayBuffer());
|
|
371
|
-
return t[0] === 80 && t[1] === 75 && t[2] === 3 && t[3] === 4;
|
|
372
|
-
}, ut = async (n) => {
|
|
373
|
-
const t = new Uint8Array(await n.slice(0, 5).arrayBuffer());
|
|
374
|
-
return t[0] === 37 && t[1] === 80 && t[2] === 68 && t[3] === 70 && t[4] === 45;
|
|
375
|
-
}, ft = ({ name: n, type: t }) => t === "application/vnd.comicbook+zip" || n.endsWith(".cbz"), gt = ({ name: n, type: t }) => t === "application/x-fictionbook+xml" || n.endsWith(".fb2"), pt = ({ name: n, type: t }) => t === "application/x-zip-compressed-fb2" || n.endsWith(".fb2.zip") || n.endsWith(".fbz"), mt = async (n) => {
|
|
376
|
-
const { configure: t, ZipReader: e, BlobReader: s, TextWriter: i, BlobWriter: o } = await import("./zip-Bw0cufIw.js");
|
|
377
|
-
t({ useWebWorkers: !1 });
|
|
378
|
-
const a = await new e(new s(n)).getEntries(), h = new Map(a.map((u) => [u.filename, u])), c = (u) => (p, ...w) => h.has(p) ? u(h.get(p), ...w) : null, l = c((u) => u.getData(new i())), d = c((u, p) => u.getData(new o(p)));
|
|
379
|
-
return { entries: a, loadText: l, loadBlob: d, getSize: (u) => h.get(u)?.uncompressedSize ?? 0 };
|
|
380
|
-
}, _ = async (n) => n.isFile ? n : (await Promise.all(Array.from(
|
|
381
|
-
await new Promise((t, e) => n.createReader().readEntries((s) => t(s), (s) => e(s))),
|
|
382
|
-
_
|
|
383
|
-
))).flat(), wt = async (n) => {
|
|
384
|
-
const t = await _(n), e = await Promise.all(
|
|
385
|
-
t.map((l) => new Promise((d, f) => l.file(
|
|
386
|
-
(u) => d([u, l.fullPath]),
|
|
387
|
-
(u) => f(u)
|
|
388
|
-
)))
|
|
389
|
-
), s = new Map(e.map(([l, d]) => [d.replace(n.fullPath + "/", ""), l])), i = new TextDecoder(), o = (l) => l ? i.decode(l) : null, r = (l) => s.get(l)?.arrayBuffer() ?? null;
|
|
390
|
-
return { loadText: async (l) => o(await r(l)), loadBlob: (l) => s.get(l), getSize: (l) => s.get(l)?.size ?? 0 };
|
|
391
|
-
};
|
|
392
|
-
class H extends Error {
|
|
393
|
-
}
|
|
394
|
-
class U extends Error {
|
|
395
|
-
}
|
|
396
|
-
class V extends Error {
|
|
397
|
-
}
|
|
398
|
-
const yt = async (n) => {
|
|
399
|
-
const t = await fetch(n);
|
|
400
|
-
if (!t.ok) throw new H(
|
|
401
|
-
`${t.status} ${t.statusText}`,
|
|
402
|
-
{ cause: t }
|
|
403
|
-
);
|
|
404
|
-
return new File([await t.blob()], new URL(t.url).pathname);
|
|
405
|
-
}, Z = async (n) => {
|
|
406
|
-
typeof n == "string" && (n = await yt(n));
|
|
407
|
-
let t;
|
|
408
|
-
if (n.isDirectory) {
|
|
409
|
-
const e = await wt(n), { EPUB: s } = await import("./epub-vizLT02-.js");
|
|
410
|
-
t = await new s(e).init();
|
|
411
|
-
} else if (n.size) if (await dt(n)) {
|
|
412
|
-
const e = await mt(n);
|
|
413
|
-
if (ft(n)) {
|
|
414
|
-
const { makeComicBook: s } = await import("./comic-book-D8f_Cc7Q.js");
|
|
415
|
-
t = s(e, n);
|
|
416
|
-
} else if (pt(n)) {
|
|
417
|
-
const { makeFB2: s } = await import("./fb2-DCqZtzQ5.js"), { entries: i } = e, o = i.find((a) => a.filename.endsWith(".fb2")), r = await e.loadBlob((o ?? i[0]).filename);
|
|
418
|
-
t = await s(r);
|
|
419
|
-
} else {
|
|
420
|
-
const { EPUB: s } = await import("./epub-vizLT02-.js");
|
|
421
|
-
t = await new s(e).init();
|
|
422
|
-
}
|
|
423
|
-
} else if (await ut(n)) {
|
|
424
|
-
const { makePDF: e } = await import("./pdf-D5_pBBCO.js");
|
|
425
|
-
t = await e(n);
|
|
426
|
-
} else {
|
|
427
|
-
const { isMOBI: e, MOBI: s } = await import("./mobi-CikMBloG.js");
|
|
428
|
-
if (await e(n)) {
|
|
429
|
-
const i = await import("./fflate-CExlDunL.js");
|
|
430
|
-
t = await new s({ unzlib: i.unzlibSync }).open(n);
|
|
431
|
-
} else if (gt(n)) {
|
|
432
|
-
const { makeFB2: i } = await import("./fb2-DCqZtzQ5.js");
|
|
433
|
-
t = await i(n);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
else throw new U("File not found");
|
|
437
|
-
if (!t) throw new V("File type not supported");
|
|
438
|
-
return t;
|
|
439
|
-
};
|
|
440
|
-
class P {
|
|
441
|
-
#e;
|
|
442
|
-
#t;
|
|
443
|
-
#n;
|
|
444
|
-
#s;
|
|
445
|
-
constructor(t, e, s = {}) {
|
|
446
|
-
this.#t = t, this.#n = e, this.#s = s, this.#s.hidden && this.hide(), this.#t.addEventListener("mousemove", ({ screenX: i, screenY: o }) => {
|
|
447
|
-
i === this.#s.x && o === this.#s.y || (this.#s.x = i, this.#s.y = o, this.show(), this.#e && clearTimeout(this.#e), e() && (this.#e = setTimeout(this.hide.bind(this), 1e3)));
|
|
448
|
-
}, !1);
|
|
449
|
-
}
|
|
450
|
-
cloneFor(t) {
|
|
451
|
-
return new P(t, this.#n, this.#s);
|
|
452
|
-
}
|
|
453
|
-
hide() {
|
|
454
|
-
this.#t.style.cursor = "none", this.#s.hidden = !0;
|
|
455
|
-
}
|
|
456
|
-
show() {
|
|
457
|
-
this.#t.style.removeProperty("cursor"), this.#s.hidden = !1;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
class vt extends EventTarget {
|
|
461
|
-
#e = [];
|
|
462
|
-
#t = -1;
|
|
463
|
-
pushState(t) {
|
|
464
|
-
const e = this.#e[this.#t];
|
|
465
|
-
e === t || e?.fraction && e.fraction === t.fraction || (this.#e[++this.#t] = t, this.#e.length = this.#t + 1, this.dispatchEvent(new Event("index-change")));
|
|
466
|
-
}
|
|
467
|
-
replaceState(t) {
|
|
468
|
-
const e = this.#t;
|
|
469
|
-
this.#e[e] = t;
|
|
470
|
-
}
|
|
471
|
-
back() {
|
|
472
|
-
const t = this.#t;
|
|
473
|
-
if (t <= 0) return;
|
|
474
|
-
const e = { state: this.#e[t - 1] };
|
|
475
|
-
this.#t = t - 1, this.dispatchEvent(new CustomEvent("popstate", { detail: e })), this.dispatchEvent(new Event("index-change"));
|
|
476
|
-
}
|
|
477
|
-
forward() {
|
|
478
|
-
const t = this.#t;
|
|
479
|
-
if (t >= this.#e.length - 1) return;
|
|
480
|
-
const e = { state: this.#e[t + 1] };
|
|
481
|
-
this.#t = t + 1, this.dispatchEvent(new CustomEvent("popstate", { detail: e })), this.dispatchEvent(new Event("index-change"));
|
|
482
|
-
}
|
|
483
|
-
get canGoBack() {
|
|
484
|
-
return this.#t > 0;
|
|
485
|
-
}
|
|
486
|
-
get canGoForward() {
|
|
487
|
-
return this.#t < this.#e.length - 1;
|
|
488
|
-
}
|
|
489
|
-
clear() {
|
|
490
|
-
this.#e = [], this.#t = -1;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
const bt = (n) => {
|
|
494
|
-
if (!n) return {};
|
|
495
|
-
try {
|
|
496
|
-
const t = Intl.getCanonicalLocales(n)[0], e = new Intl.Locale(t), s = ["zh", "ja", "kr"].includes(e.language), i = (e.getTextInfo?.() ?? e.textInfo)?.direction;
|
|
497
|
-
return { canonical: t, locale: e, isCJK: s, direction: i };
|
|
498
|
-
} catch (t) {
|
|
499
|
-
return console.warn(t), {};
|
|
500
|
-
}
|
|
501
|
-
};
|
|
502
|
-
class J extends HTMLElement {
|
|
503
|
-
#e = this.attachShadow({ mode: "closed" });
|
|
504
|
-
#t;
|
|
505
|
-
#n;
|
|
506
|
-
#s;
|
|
507
|
-
#o = /* @__PURE__ */ new Map();
|
|
508
|
-
#a = new P(this, () => this.hasAttribute("autohide-cursor"));
|
|
509
|
-
isFixedLayout = !1;
|
|
510
|
-
lastLocation;
|
|
511
|
-
history = new vt();
|
|
512
|
-
constructor() {
|
|
513
|
-
super(), this.history.addEventListener("popstate", ({ detail: t }) => {
|
|
514
|
-
const e = this.resolveNavigation(t.state);
|
|
515
|
-
this.renderer.goTo(e);
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
async open(t) {
|
|
519
|
-
if ((typeof t == "string" || typeof t.arrayBuffer == "function" || t.isDirectory) && (t = await Z(t)), this.book = t, this.language = bt(t.metadata?.language), t.splitTOCHref && t.getTOCFragment) {
|
|
520
|
-
const e = t.sections.map((o) => o.id);
|
|
521
|
-
this.#t = new rt(t.sections, 1500, 1600);
|
|
522
|
-
const s = t.splitTOCHref.bind(t), i = t.getTOCFragment.bind(t);
|
|
523
|
-
this.#n = new L(), await this.#n.init({
|
|
524
|
-
toc: t.toc ?? [],
|
|
525
|
-
ids: e,
|
|
526
|
-
splitHref: s,
|
|
527
|
-
getFragment: i
|
|
528
|
-
}), this.#s = new L(), await this.#s.init({
|
|
529
|
-
toc: t.pageList ?? [],
|
|
530
|
-
ids: e,
|
|
531
|
-
splitHref: s,
|
|
532
|
-
getFragment: i
|
|
533
|
-
});
|
|
534
|
-
}
|
|
535
|
-
if (this.isFixedLayout = this.book.rendition?.layout === "pre-paginated", this.isFixedLayout ? (await import("./fixed-layout-CMyaX9h8.js"), this.renderer = document.createElement("foliate-fxl")) : (await import("./paginator-CpnI4Urk.js"), this.renderer = document.createElement("foliate-paginator")), this.renderer.setAttribute("exportparts", "head,foot,filter"), this.renderer.addEventListener("load", (e) => this.#l(e.detail)), this.renderer.addEventListener("relocate", (e) => this.#c(e.detail)), this.renderer.addEventListener("create-overlayer", (e) => e.detail.attach(this.#d(e.detail))), this.renderer.open(t), this.#e.append(this.renderer), t.sections.some((e) => e.mediaOverlay)) {
|
|
536
|
-
const e = t.media.activeClass, s = t.media.playbackActiveClass;
|
|
537
|
-
this.mediaOverlay = t.getMediaOverlay();
|
|
538
|
-
let i;
|
|
539
|
-
this.mediaOverlay.addEventListener("highlight", (o) => {
|
|
540
|
-
const r = this.resolveNavigation(o.detail.text);
|
|
541
|
-
this.renderer.goTo(r).then(() => {
|
|
542
|
-
const { doc: a } = this.renderer.getContents().find((c) => c.index = r.index), h = r.anchor(a);
|
|
543
|
-
h.classList.add(e), s && h.ownerDocument.documentElement.classList.add(s), i = new WeakRef(h);
|
|
544
|
-
});
|
|
545
|
-
}), this.mediaOverlay.addEventListener("unhighlight", () => {
|
|
546
|
-
const o = i?.deref();
|
|
547
|
-
o && (o.classList.remove(e), s && o.ownerDocument.documentElement.classList.remove(s));
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
close() {
|
|
552
|
-
this.renderer?.destroy(), this.renderer?.remove(), this.#t = null, this.#n = null, this.#s = null, this.#o = /* @__PURE__ */ new Map(), this.lastLocation = null, this.history.clear(), this.tts = null, this.mediaOverlay = null;
|
|
553
|
-
}
|
|
554
|
-
goToTextStart() {
|
|
555
|
-
return this.goTo(this.book.landmarks?.find((t) => t.type.includes("bodymatter") || t.type.includes("text"))?.href ?? this.book.sections.findIndex((t) => t.linear !== "no"));
|
|
556
|
-
}
|
|
557
|
-
async init({ lastLocation: t, showTextStart: e }) {
|
|
558
|
-
const s = t ? this.resolveNavigation(t) : null;
|
|
559
|
-
s ? (await this.renderer.goTo(s), this.history.pushState(t)) : e ? await this.goToTextStart() : (this.history.pushState(0), await this.next());
|
|
560
|
-
}
|
|
561
|
-
#i(t, e, s) {
|
|
562
|
-
return this.dispatchEvent(new CustomEvent(t, { detail: e, cancelable: s }));
|
|
563
|
-
}
|
|
564
|
-
#c({ reason: t, range: e, index: s, fraction: i, size: o }) {
|
|
565
|
-
const r = this.#t?.getProgress(s, i, o) ?? {}, a = this.#n?.getProgress(s, e), h = this.#s?.getProgress(s, e), c = this.getCFI(s, e);
|
|
566
|
-
this.lastLocation = { ...r, tocItem: a, pageItem: h, cfi: c, range: e }, (t === "snap" || t === "page" || t === "scroll") && this.history.replaceState(c), this.#i("relocate", this.lastLocation);
|
|
567
|
-
}
|
|
568
|
-
#l({ doc: t, index: e }) {
|
|
569
|
-
t.documentElement.lang ||= this.language.canonical ?? "", this.language.isCJK || (t.documentElement.dir ||= this.language.direction ?? ""), this.#h(t, e), this.#a.cloneFor(t.documentElement), this.#i("load", { doc: t, index: e });
|
|
570
|
-
}
|
|
571
|
-
#h(t, e) {
|
|
572
|
-
const { book: s } = this, i = s.sections[e];
|
|
573
|
-
t.addEventListener("click", (o) => {
|
|
574
|
-
const r = o.target.closest("a[href]");
|
|
575
|
-
if (!r) return;
|
|
576
|
-
o.preventDefault();
|
|
577
|
-
const a = r.getAttribute("href"), h = i?.resolveHref?.(a) ?? a;
|
|
578
|
-
s?.isExternal?.(h) ? Promise.resolve(this.#i("external-link", { a: r, href: h }, !0)).then((c) => c ? globalThis.open(h, "_blank") : null).catch((c) => console.error(c)) : Promise.resolve(this.#i("link", { a: r, href: h }, !0)).then((c) => c ? this.goTo(h) : null).catch((c) => console.error(c));
|
|
579
|
-
});
|
|
580
|
-
}
|
|
581
|
-
async addAnnotation(t, e) {
|
|
582
|
-
const { value: s } = t;
|
|
583
|
-
if (s.startsWith(y)) {
|
|
584
|
-
const h = s.replace(y, ""), { index: c, anchor: l } = await this.resolveNavigation(h), d = this.#r(c);
|
|
585
|
-
if (d) {
|
|
586
|
-
const { overlayer: f, doc: u } = d;
|
|
587
|
-
if (e) {
|
|
588
|
-
f.remove(s);
|
|
589
|
-
return;
|
|
590
|
-
}
|
|
591
|
-
const p = u ? l(u) : l;
|
|
592
|
-
f.add(s, p, R.outline);
|
|
593
|
-
}
|
|
594
|
-
return;
|
|
595
|
-
}
|
|
596
|
-
const { index: i, anchor: o } = await this.resolveNavigation(s), r = this.#r(i);
|
|
597
|
-
if (r) {
|
|
598
|
-
const { overlayer: h, doc: c } = r;
|
|
599
|
-
if (h.remove(s), !e) {
|
|
600
|
-
const l = c ? o(c) : o, d = (f, u) => h.add(s, l, f, u);
|
|
601
|
-
this.#i("draw-annotation", { draw: d, annotation: t, doc: c, range: l });
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
const a = this.#n.getProgress(i)?.label ?? "";
|
|
605
|
-
return { index: i, label: a };
|
|
606
|
-
}
|
|
607
|
-
deleteAnnotation(t) {
|
|
608
|
-
return this.addAnnotation(t, !0);
|
|
609
|
-
}
|
|
610
|
-
#r(t) {
|
|
611
|
-
return this.renderer.getContents().find((e) => e.index === t && e.overlayer);
|
|
612
|
-
}
|
|
613
|
-
#d({ doc: t, index: e }) {
|
|
614
|
-
const s = new R();
|
|
615
|
-
t.addEventListener("click", (o) => {
|
|
616
|
-
const [r, a] = s.hitTest(o);
|
|
617
|
-
r && !r.startsWith(y) && this.#i("show-annotation", { value: r, index: e, range: a });
|
|
618
|
-
}, !1);
|
|
619
|
-
const i = this.#o.get(e);
|
|
620
|
-
if (i) for (const o of i) this.addAnnotation(o);
|
|
621
|
-
return this.#i("create-overlay", { index: e }), s;
|
|
622
|
-
}
|
|
623
|
-
async showAnnotation(t) {
|
|
624
|
-
const { value: e } = t, s = await this.goTo(e);
|
|
625
|
-
if (s) {
|
|
626
|
-
const { index: i, anchor: o } = s, { doc: r } = this.#r(i), a = o(r);
|
|
627
|
-
this.#i("show-annotation", { value: e, index: i, range: a });
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
getCFI(t, e) {
|
|
631
|
-
const s = this.book.sections[t].cfi ?? z.fromIndex(t);
|
|
632
|
-
return e ? Q(s, nt(e)) : s;
|
|
633
|
-
}
|
|
634
|
-
resolveCFI(t) {
|
|
635
|
-
if (this.book.resolveCFI)
|
|
636
|
-
return this.book.resolveCFI(t);
|
|
637
|
-
{
|
|
638
|
-
const e = b(t);
|
|
639
|
-
return { index: z.toIndex((e.parent ?? e).shift()), anchor: (o) => it(o, e) };
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
resolveNavigation(t) {
|
|
643
|
-
try {
|
|
644
|
-
if (typeof t == "number") return { index: t };
|
|
645
|
-
if (typeof t.fraction == "number") {
|
|
646
|
-
const [e, s] = this.#t.getSection(t.fraction);
|
|
647
|
-
return { index: e, anchor: s };
|
|
648
|
-
}
|
|
649
|
-
return x.test(t) ? this.resolveCFI(t) : this.book.resolveHref(t);
|
|
650
|
-
} catch (e) {
|
|
651
|
-
console.error(e), console.error(`Could not resolve target ${t}`);
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
async goTo(t) {
|
|
655
|
-
const e = this.resolveNavigation(t);
|
|
656
|
-
try {
|
|
657
|
-
return await this.renderer.goTo(e), this.history.pushState(t), e;
|
|
658
|
-
} catch (s) {
|
|
659
|
-
console.error(s), console.error(`Could not go to ${t}`);
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
async goToFraction(t) {
|
|
663
|
-
const [e, s] = this.#t.getSection(t);
|
|
664
|
-
await this.renderer.goTo({ index: e, anchor: s }), this.history.pushState({ fraction: t });
|
|
665
|
-
}
|
|
666
|
-
async select(t) {
|
|
667
|
-
try {
|
|
668
|
-
const e = await this.resolveNavigation(t);
|
|
669
|
-
await this.renderer.goTo({ ...e, select: !0 }), this.history.pushState(t);
|
|
670
|
-
} catch (e) {
|
|
671
|
-
console.error(e), console.error(`Could not go to ${t}`);
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
deselect() {
|
|
675
|
-
for (const { doc: t } of this.renderer.getContents())
|
|
676
|
-
t.defaultView.getSelection().removeAllRanges();
|
|
677
|
-
}
|
|
678
|
-
getSectionFractions() {
|
|
679
|
-
return (this.#t?.sectionFractions ?? []).map((t) => t + Number.EPSILON);
|
|
680
|
-
}
|
|
681
|
-
getProgressOf(t, e) {
|
|
682
|
-
const s = this.#n?.getProgress(t, e), i = this.#s?.getProgress(t, e);
|
|
683
|
-
return { tocItem: s, pageItem: i };
|
|
684
|
-
}
|
|
685
|
-
async getTOCItemOf(t) {
|
|
686
|
-
try {
|
|
687
|
-
const { index: e, anchor: s } = await this.resolveNavigation(t), i = await this.book.sections[e].createDocument(), o = s(i), r = o instanceof Range, a = r ? o : i.createRange();
|
|
688
|
-
return r || a.selectNodeContents(o), this.#n.getProgress(e, a);
|
|
689
|
-
} catch (e) {
|
|
690
|
-
console.error(e), console.error(`Could not get ${t}`);
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
async prev(t) {
|
|
694
|
-
await this.renderer.prev(t);
|
|
695
|
-
}
|
|
696
|
-
async next(t) {
|
|
697
|
-
await this.renderer.next(t);
|
|
698
|
-
}
|
|
699
|
-
goLeft() {
|
|
700
|
-
return this.book.dir === "rtl" ? this.next() : this.prev();
|
|
701
|
-
}
|
|
702
|
-
goRight() {
|
|
703
|
-
return this.book.dir === "rtl" ? this.prev() : this.next();
|
|
704
|
-
}
|
|
705
|
-
async *#u(t, e, s) {
|
|
706
|
-
const i = await this.book.sections[s].createDocument();
|
|
707
|
-
for (const { range: o, excerpt: r } of t(i, e))
|
|
708
|
-
yield { cfi: this.getCFI(s, o), excerpt: r };
|
|
709
|
-
}
|
|
710
|
-
async *#f(t, e) {
|
|
711
|
-
const { sections: s } = this.book;
|
|
712
|
-
for (const [i, { createDocument: o }] of s.entries()) {
|
|
713
|
-
if (!o) continue;
|
|
714
|
-
const r = await o(), a = Array.from(t(r, e), ({ range: c, excerpt: l }) => ({ cfi: this.getCFI(i, c), excerpt: l }));
|
|
715
|
-
yield { progress: (i + 1) / s.length }, a.length && (yield { index: i, subitems: a });
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
async *search(t) {
|
|
719
|
-
this.clearSearch();
|
|
720
|
-
const { searchMatcher: e } = await import("./search-aqQXTfxz.js"), { query: s, index: i } = t, o = e(
|
|
721
|
-
O,
|
|
722
|
-
{ defaultLocale: this.language, ...t }
|
|
723
|
-
), r = i != null ? this.#u(o, s, i) : this.#f(o, s), a = [];
|
|
724
|
-
this.#o.set(i, a);
|
|
725
|
-
for await (const h of r)
|
|
726
|
-
if (h.subitems) {
|
|
727
|
-
const c = h.subitems.map(({ cfi: l }) => ({ value: y + l }));
|
|
728
|
-
this.#o.set(h.index, c);
|
|
729
|
-
for (const l of c) this.addAnnotation(l);
|
|
730
|
-
yield {
|
|
731
|
-
label: this.#n.getProgress(h.index)?.label ?? "",
|
|
732
|
-
subitems: h.subitems
|
|
733
|
-
};
|
|
734
|
-
} else {
|
|
735
|
-
if (h.cfi) {
|
|
736
|
-
const c = { value: y + h.cfi };
|
|
737
|
-
a.push(c), this.addAnnotation(c);
|
|
738
|
-
}
|
|
739
|
-
yield h;
|
|
740
|
-
}
|
|
741
|
-
yield "done";
|
|
742
|
-
}
|
|
743
|
-
clearSearch() {
|
|
744
|
-
for (const t of this.#o.values())
|
|
745
|
-
for (const e of t) this.deleteAnnotation(e);
|
|
746
|
-
this.#o.clear();
|
|
747
|
-
}
|
|
748
|
-
async initTTS(t = "word", e) {
|
|
749
|
-
const s = this.renderer.getContents()[0].doc;
|
|
750
|
-
if (this.tts && this.tts.doc === s) return;
|
|
751
|
-
const { TTS: i } = await import("./tts-UQB-k9b_.js");
|
|
752
|
-
this.tts = new i(s, O, e || ((o) => this.renderer.scrollToAnchor(o, !0)), t);
|
|
753
|
-
}
|
|
754
|
-
startMediaOverlay() {
|
|
755
|
-
const { index: t } = this.renderer.getContents()[0];
|
|
756
|
-
return this.mediaOverlay.start(t);
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
customElements.define("foliate-view", J);
|
|
760
|
-
const Et = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
761
|
-
__proto__: null,
|
|
762
|
-
NotFoundError: U,
|
|
763
|
-
ResponseError: H,
|
|
764
|
-
UnsupportedTypeError: V,
|
|
765
|
-
View: J,
|
|
766
|
-
makeBook: Z
|
|
767
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
768
|
-
export {
|
|
769
|
-
it as a,
|
|
770
|
-
At as f,
|
|
771
|
-
b as p,
|
|
772
|
-
xt as t,
|
|
773
|
-
Et as v
|
|
774
|
-
};
|