react-book-reader 1.1.7 → 1.1.9

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.
@@ -1,258 +0,0 @@
1
- const q = (d) => d ? d.replace(/[\t\n\f\r ]+/g, " ").replace(/^[\t\n\f\r ]+/, "").replace(/[\t\n\f\r ]+$/, "") : "", u = (d) => q(d?.textContent), S = {
2
- XLINK: "http://www.w3.org/1999/xlink",
3
- EPUB: "http://www.idpf.org/2007/ops"
4
- }, T = {
5
- XML: "application/xml",
6
- XHTML: "application/xhtml+xml"
7
- }, l = {
8
- strong: ["strong", "self"],
9
- emphasis: ["em", "self"],
10
- style: ["span", "self"],
11
- a: "anchor",
12
- strikethrough: ["s", "self"],
13
- sub: ["sub", "self"],
14
- sup: ["sup", "self"],
15
- code: ["code", "self"],
16
- image: "image"
17
- }, k = {
18
- tr: ["tr", {
19
- th: ["th", l, ["colspan", "rowspan", "align", "valign"]],
20
- td: ["td", l, ["colspan", "rowspan", "align", "valign"]]
21
- }, ["align"]]
22
- }, B = {
23
- epigraph: ["blockquote"],
24
- subtitle: ["h2", l],
25
- "text-author": ["p", l],
26
- date: ["p", l],
27
- stanza: "stanza"
28
- }, L = {
29
- title: ["header", {
30
- p: ["h1", l],
31
- "empty-line": ["br"]
32
- }],
33
- epigraph: ["blockquote", "self"],
34
- image: "image",
35
- annotation: ["aside"],
36
- section: ["section", "self"],
37
- p: ["p", l],
38
- poem: ["blockquote", B],
39
- subtitle: ["h2", l],
40
- cite: ["blockquote", "self"],
41
- "empty-line": ["br"],
42
- table: ["table", k],
43
- "text-author": ["p", l]
44
- };
45
- B.epigraph.push(L);
46
- const E = {
47
- image: "image",
48
- title: ["section", {
49
- p: ["h1", l],
50
- "empty-line": ["br"]
51
- }],
52
- epigraph: ["section", L],
53
- section: ["section", L]
54
- };
55
- class D {
56
- constructor(t) {
57
- this.fb2 = t, this.doc = document.implementation.createDocument(S.XHTML, "html"), this.bins = new Map(Array.from(
58
- this.fb2.getElementsByTagName("binary"),
59
- (n) => [n.id, n]
60
- ));
61
- }
62
- getImageSrc(t) {
63
- const n = t.getAttributeNS(S.XLINK, "href");
64
- if (!n) return "data:,";
65
- const [, a] = n.split("#");
66
- if (!a) return n;
67
- const s = this.bins.get(a);
68
- return s ? `data:${s.getAttribute("content-type")};base64,${s.textContent}` : n;
69
- }
70
- image(t) {
71
- const n = this.doc.createElement("img");
72
- return n.alt = t.getAttribute("alt"), n.title = t.getAttribute("title"), n.setAttribute("src", this.getImageSrc(t)), n;
73
- }
74
- anchor(t) {
75
- const n = this.convert(t, { a: ["a", l] });
76
- return n.setAttribute("href", t.getAttributeNS(S.XLINK, "href")), t.getAttribute("type") === "note" && n.setAttributeNS(S.EPUB, "epub:type", "noteref"), n;
77
- }
78
- stanza(t) {
79
- const n = this.convert(t, {
80
- stanza: ["p", {
81
- title: ["header", {
82
- p: ["strong", l],
83
- "empty-line": ["br"]
84
- }],
85
- subtitle: ["p", l]
86
- }]
87
- });
88
- for (const a of t.children) a.nodeName === "v" && (n.append(this.doc.createTextNode(a.textContent)), n.append(this.doc.createElement("br")));
89
- return n;
90
- }
91
- convert(t, n) {
92
- if (t.nodeType === 3) return this.doc.createTextNode(t.textContent);
93
- if (t.nodeType === 4) return this.doc.createCDATASection(t.textContent);
94
- if (t.nodeType === 8) return this.doc.createComment(t.textContent);
95
- const a = n?.[t.nodeName];
96
- if (!a) return null;
97
- if (typeof a == "string") return this[a](t);
98
- const [s, p, m] = a, f = this.doc.createElement(s);
99
- if (t.id && (f.id = t.id), f.classList.add(t.nodeName), Array.isArray(m)) for (const g of m) {
100
- const A = t.getAttribute(g);
101
- A && f.setAttribute(g, A);
102
- }
103
- const w = p === "self" ? n : p;
104
- let y = t.firstChild;
105
- for (; y; ) {
106
- const g = this.convert(y, w);
107
- g && f.append(g), y = y.nextSibling;
108
- }
109
- return f;
110
- }
111
- }
112
- const $ = async (d) => {
113
- const t = await d.arrayBuffer(), n = new TextDecoder("utf-8").decode(t), a = new DOMParser(), s = a.parseFromString(n, T.XML), p = s.xmlEncoding || n.match(/^<\?xml\s+version\s*=\s*["']1.\d+"\s+encoding\s*=\s*["']([A-Za-z0-9._-]*)["']/)?.[1];
114
- if (p && p.toLowerCase() !== "utf-8") {
115
- const m = new TextDecoder(p).decode(t);
116
- return a.parseFromString(m, T.XML);
117
- }
118
- return s;
119
- }, O = URL.createObjectURL(new Blob([`
120
- @namespace epub "http://www.idpf.org/2007/ops";
121
- body > img, section > img {
122
- display: block;
123
- margin: auto;
124
- }
125
- .title h1 {
126
- text-align: center;
127
- }
128
- body > section > .title, body.notesBodyType > .title {
129
- margin: 3em 0;
130
- }
131
- body.notesBodyType > section .title h1 {
132
- text-align: start;
133
- }
134
- body.notesBodyType > section .title {
135
- margin: 1em 0;
136
- }
137
- p {
138
- text-indent: 1em;
139
- margin: 0;
140
- }
141
- :not(p) + p, p:first-child {
142
- text-indent: 0;
143
- }
144
- .poem p {
145
- text-indent: 0;
146
- margin: 1em 0;
147
- }
148
- .text-author, .date {
149
- text-align: end;
150
- }
151
- .text-author:before {
152
- content: "—";
153
- }
154
- table {
155
- border-collapse: collapse;
156
- }
157
- td, th {
158
- padding: .25em;
159
- }
160
- a[epub|type~="noteref"] {
161
- font-size: .75em;
162
- vertical-align: super;
163
- }
164
- body:not(.notesBodyType) > .title, body:not(.notesBodyType) > .epigraph {
165
- margin: 3em 0;
166
- }
167
- `], { type: "text/css" })), X = (d) => `<?xml version="1.0" encoding="utf-8"?>
168
- <html xmlns="http://www.w3.org/1999/xhtml">
169
- <head><link href="${O}" rel="stylesheet" type="text/css"/></head>
170
- <body>${d}</body>
171
- </html>`, C = "data-foliate-id", z = async (d) => {
172
- const t = {}, n = await $(d), a = new D(n), s = (e) => n.querySelector(e), p = (e) => [...n.querySelectorAll(e)], m = (e) => {
173
- const o = u(e.querySelector("nickname"));
174
- if (o) return o;
175
- const r = u(e.querySelector("first-name")), i = u(e.querySelector("middle-name")), c = u(e.querySelector("last-name")), h = [r, i, c].filter((b) => b).join(" "), x = c ? [c, [r, i].filter((b) => b).join(" ")].join(", ") : null;
176
- return { name: h, sortAs: x };
177
- }, f = (e) => e?.getAttribute("value") ?? u(e), w = s("title-info annotation");
178
- if (t.metadata = {
179
- title: u(s("title-info book-title")),
180
- identifier: u(s("document-info id")),
181
- language: u(s("title-info lang")),
182
- author: p("title-info author").map(m),
183
- translator: p("title-info translator").map(m),
184
- contributor: p("document-info author").map(m).concat(p("document-info program-used").map(u)).map((e) => Object.assign(
185
- typeof e == "string" ? { name: e } : e,
186
- { role: "bkp" }
187
- )),
188
- publisher: u(s("publish-info publisher")),
189
- published: f(s("title-info date")),
190
- modified: f(s("document-info date")),
191
- description: w ? a.convert(
192
- w,
193
- { annotation: ["div", L] }
194
- ).innerHTML : null,
195
- subject: p("title-info genre").map(u)
196
- }, s("coverpage image")) {
197
- const e = a.getImageSrc(s("coverpage image"));
198
- t.getCover = () => fetch(e).then((o) => o.blob());
199
- } else t.getCover = () => null;
200
- const y = Array.from(n.querySelectorAll("body"), (e) => {
201
- const o = a.convert(e, { body: ["body", E] });
202
- return [Array.from(o.children, (r) => {
203
- const i = [r, ...r.querySelectorAll("[id]")].map((c) => c.id);
204
- return { el: r, ids: i };
205
- }), o];
206
- }), g = [], A = y[0][0].map(({ el: e, ids: o }) => {
207
- const r = Array.from(
208
- e.querySelectorAll(":scope > section > .title"),
209
- (i, c) => (i.setAttribute(C, c), { title: u(i), index: c })
210
- );
211
- return { ids: o, titles: r, el: e };
212
- }).concat(y.slice(1).map(([e, o]) => {
213
- const r = e.map((i) => i.ids).flat();
214
- return o.classList.add("notesBodyType"), { ids: r, el: o, linear: "no" };
215
- })).map(({ ids: e, titles: o, el: r, linear: i }) => {
216
- const c = X(r.outerHTML), h = new Blob([c], { type: T.XHTML }), x = URL.createObjectURL(h);
217
- g.push(x);
218
- const b = q(
219
- r.querySelector(".title, .subtitle, p")?.textContent ?? (r.classList.contains("title") ? r.textContent : "")
220
- );
221
- return {
222
- ids: e,
223
- title: b,
224
- titles: o,
225
- load: () => x,
226
- createDocument: () => new DOMParser().parseFromString(c, T.XHTML),
227
- // doo't count image data as it'd skew the size too much
228
- size: h.size - Array.from(
229
- r.querySelectorAll("[src]"),
230
- (v) => v.getAttribute("src")?.length ?? 0
231
- ).reduce((v, N) => v + N, 0),
232
- linear: i
233
- };
234
- }), M = /* @__PURE__ */ new Map();
235
- return t.sections = A.map((e, o) => {
236
- const { ids: r, load: i, createDocument: c, size: h, linear: x } = e;
237
- for (const b of r) b && M.set(b, o);
238
- return { id: o, load: i, createDocument: c, size: h, linear: x };
239
- }), t.toc = A.map(({ title: e, titles: o }, r) => {
240
- const i = r.toString();
241
- return {
242
- label: e,
243
- href: i,
244
- subitems: o?.length ? o.map(({ title: c, index: h }) => ({
245
- label: c,
246
- href: `${i}#${h}`
247
- })) : null
248
- };
249
- }).filter((e) => e), t.resolveHref = (e) => {
250
- const [o, r] = e.split("#");
251
- return o ? { index: Number(o), anchor: (i) => i.querySelector(`[${C}="${r}"]`) } : { index: M.get(r), anchor: (i) => i.getElementById(r) };
252
- }, t.splitTOCHref = (e) => e?.split("#")?.map((o) => Number(o)) ?? [], t.getTOCFragment = (e, o) => e.querySelector(`[${C}="${o}"]`), t.destroy = () => {
253
- for (const e of g) URL.revokeObjectURL(e);
254
- }, t;
255
- };
256
- export {
257
- z as makeFB2
258
- };
@@ -1,139 +0,0 @@
1
- var t = Uint8Array, M = Uint16Array, sr = Int32Array, nr = new t([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0, 0]), ar = new t([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 0, 0]), hr = new t([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), er = function(n, r) {
2
- for (var a = new M(31), i = 0; i < 31; ++i) a[i] = r += 1 << n[i - 1];
3
- var o = new sr(a[30]);
4
- for (i = 1; i < 30; ++i) for (var b = a[i]; b < a[i + 1]; ++b) o[b] = b - a[i] << 5 | i;
5
- return { b: a, r: o };
6
- }, ir = er(nr, 2), or = ir.b, yr = ir.r;
7
- or[28] = 258, yr[258] = 28;
8
- for (var gr = er(ar, 0).b, vr = new M(32768), v = 0; v < 32768; ++v) {
9
- var m = (43690 & v) >> 1 | (21845 & v) << 1;
10
- m = (61680 & (m = (52428 & m) >> 2 | (13107 & m) << 2)) >> 4 | (3855 & m) << 4, vr[v] = ((65280 & m) >> 8 | (255 & m) << 8) >> 1;
11
- }
12
- var S = function(n, r, a) {
13
- for (var i = n.length, o = 0, b = new M(r); o < i; ++o) n[o] && ++b[n[o] - 1];
14
- var g, w = new M(r);
15
- for (o = 1; o < r; ++o) w[o] = w[o - 1] + b[o - 1] << 1;
16
- {
17
- g = new M(1 << r);
18
- var x = 15 - r;
19
- for (o = 0; o < i; ++o) if (n[o]) for (var E = o << 4 | n[o], h = r - n[o], e = w[n[o] - 1]++ << h, f = e | (1 << h) - 1; e <= f; ++e) g[vr[e] >> x] = E;
20
- }
21
- return g;
22
- }, K = new t(288);
23
- for (v = 0; v < 144; ++v) K[v] = 8;
24
- for (v = 144; v < 256; ++v) K[v] = 9;
25
- for (v = 256; v < 280; ++v) K[v] = 7;
26
- for (v = 280; v < 288; ++v) K[v] = 8;
27
- var fr = new t(32);
28
- for (v = 0; v < 32; ++v) fr[v] = 5;
29
- var wr = S(K, 9), pr = S(fr, 5), G = function(n) {
30
- for (var r = n[0], a = 1; a < n.length; ++a) n[a] > r && (r = n[a]);
31
- return r;
32
- }, u = function(n, r, a) {
33
- var i = r / 8 | 0;
34
- return (n[i] | n[i + 1] << 8) >> (7 & r) & a;
35
- }, Z = function(n, r) {
36
- var a = r / 8 | 0;
37
- return (n[a] | n[a + 1] << 8 | n[a + 2] << 16) >> (7 & r);
38
- }, kr = ["unexpected EOF", "invalid block type", "invalid length/literal", "invalid distance", "stream finished", "no stream handler", , "no callback", "invalid UTF-8 data", "extra field too long", "date not in range 1980-2099", "filename too long", "stream finishing", "invalid zip data"], c = function(n, r, a) {
39
- var i = new Error(r || kr[n]);
40
- if (i.code = n, Error.captureStackTrace && Error.captureStackTrace(i, c), !a) throw i;
41
- return i;
42
- }, mr = function(n, r, a, i) {
43
- var o = n.length, b = i ? i.length : 0;
44
- if (!o || r.f && !r.l) return a || new t(0);
45
- var g = !a, w = g || r.i != 2, x = r.i;
46
- g && (a = new t(3 * o));
47
- var E = function(z) {
48
- var Y = a.length;
49
- if (z > Y) {
50
- var k = new t(Math.max(2 * Y, z));
51
- k.set(a), a = k;
52
- }
53
- }, h = r.f || 0, e = r.p || 0, f = r.b || 0, p = r.l, L = r.d, T = r.m, A = r.n, q = 8 * o;
54
- do {
55
- if (!p) {
56
- h = u(n, e, 1);
57
- var B = u(n, e + 1, 3);
58
- if (e += 3, !B) {
59
- var I = n[(s = 4 + ((e + 7) / 8 | 0)) - 4] | n[s - 3] << 8, J = s + I;
60
- if (J > o) {
61
- x && c(0);
62
- break;
63
- }
64
- w && E(f + I), a.set(n.subarray(s, J), f), r.b = f += I, r.p = e = 8 * J, r.f = h;
65
- continue;
66
- }
67
- if (B == 1) p = wr, L = pr, T = 9, A = 5;
68
- else if (B == 2) {
69
- var O = u(n, e, 31) + 257, R = u(n, e + 10, 15) + 4, C = O + u(n, e + 5, 31) + 1;
70
- e += 14;
71
- for (var U = new t(C), P = new t(19), l = 0; l < R; ++l) P[hr[l]] = u(n, e + 3 * l, 7);
72
- e += 3 * R;
73
- var Q = G(P), tr = (1 << Q) - 1, lr = S(P, Q);
74
- for (l = 0; l < C; ) {
75
- var s, $ = lr[u(n, e, tr)];
76
- if (e += 15 & $, (s = $ >> 4) < 16) U[l++] = s;
77
- else {
78
- var D = 0, X = 0;
79
- for (s == 16 ? (X = 3 + u(n, e, 3), e += 2, D = U[l - 1]) : s == 17 ? (X = 3 + u(n, e, 7), e += 3) : s == 18 && (X = 11 + u(n, e, 127), e += 7); X--; ) U[l++] = D;
80
- }
81
- }
82
- var W = U.subarray(0, O), y = U.subarray(O);
83
- T = G(W), A = G(y), p = S(W, T), L = S(y, A);
84
- } else c(1);
85
- if (e > q) {
86
- x && c(0);
87
- break;
88
- }
89
- }
90
- w && E(f + 131072);
91
- for (var ur = (1 << T) - 1, cr = (1 << A) - 1, V = e; ; V = e) {
92
- var d = (D = p[Z(n, e) & ur]) >> 4;
93
- if ((e += 15 & D) > q) {
94
- x && c(0);
95
- break;
96
- }
97
- if (D || c(2), d < 256) a[f++] = d;
98
- else {
99
- if (d == 256) {
100
- V = e, p = null;
101
- break;
102
- }
103
- var N = d - 254;
104
- if (d > 264) {
105
- var F = nr[l = d - 257];
106
- N = u(n, e, (1 << F) - 1) + or[l], e += F;
107
- }
108
- var _ = L[Z(n, e) & cr], j = _ >> 4;
109
- if (_ || c(3), e += 15 & _, y = gr[j], j > 3 && (F = ar[j], y += Z(n, e) & (1 << F) - 1, e += F), e > q) {
110
- x && c(0);
111
- break;
112
- }
113
- w && E(f + 131072);
114
- var H = f + N;
115
- if (f < y) {
116
- var rr = b - y, br = Math.min(y, H);
117
- for (rr + f < 0 && c(3); f < br; ++f) a[f] = i[rr + f];
118
- }
119
- for (; f < H; ++f) a[f] = a[f - y];
120
- }
121
- }
122
- r.l = p, r.p = V, r.b = f, r.f = h, p && (h = 1, r.m = T, r.d = L, r.n = A);
123
- } while (!h);
124
- return f != a.length && g ? (function(z, Y, k) {
125
- return (k == null || k > z.length) && (k = z.length), new t(z.subarray(Y, k));
126
- })(a, 0, f) : a.subarray(0, f);
127
- }, xr = new t(0);
128
- function zr(n, r) {
129
- return mr(n.subarray((a = n, i = r && r.dictionary, ((15 & a[0]) != 8 || a[0] >> 4 > 7 || (a[0] << 8 | a[1]) % 31) && c(6, "invalid zlib data"), (a[1] >> 5 & 1) == +!i && c(6, "invalid zlib data: " + (32 & a[1] ? "need" : "unexpected") + " dictionary"), 2 + (a[1] >> 3 & 4)), -4), { i: 2 }, r && r.out, r && r.dictionary);
130
- var a, i;
131
- }
132
- var dr = typeof TextDecoder < "u" && new TextDecoder();
133
- try {
134
- dr.decode(xr, { stream: !0 });
135
- } catch {
136
- }
137
- export {
138
- zr as unzlibSync
139
- };
@@ -1,195 +0,0 @@
1
- const y = (d) => d?.split(/[,;\s]/)?.filter((t) => t)?.map((t) => t.split("=").map((i) => i.trim())), S = (d, t) => {
2
- if (d.documentElement.localName === "svg") {
3
- const [, , n, h] = d.documentElement.getAttribute("viewBox")?.split(/\s/) ?? [];
4
- return { width: n, height: h };
5
- }
6
- const i = y(d.querySelector('meta[name="viewport"]')?.getAttribute("content"));
7
- if (i) return Object.fromEntries(i);
8
- if (typeof t == "string") return y(t);
9
- if (t?.width && t.height) return t;
10
- const e = d.querySelector("img");
11
- return e ? { width: e.naturalWidth, height: e.naturalHeight } : (console.warn(new Error("Missing viewport properties")), { width: 1e3, height: 2e3 });
12
- };
13
- class k extends HTMLElement {
14
- static observedAttributes = ["zoom"];
15
- #a = this.attachShadow({ mode: "closed" });
16
- #f = new ResizeObserver(() => this.#e());
17
- #i;
18
- #h = -1;
19
- defaultViewport;
20
- spread;
21
- #l = !1;
22
- #s;
23
- #r;
24
- #t;
25
- #n;
26
- #o;
27
- constructor() {
28
- super();
29
- const t = new CSSStyleSheet();
30
- this.#a.adoptedStyleSheets = [t], t.replaceSync(`:host {
31
- width: 100%;
32
- height: 100%;
33
- display: flex;
34
- justify-content: center;
35
- align-items: center;
36
- overflow: auto;
37
- }`), this.#f.observe(this);
38
- }
39
- attributeChangedCallback(t, i, e) {
40
- t === "zoom" && (this.#o = e !== "fit-width" && e !== "fit-page" ? parseFloat(e) : e, this.#e());
41
- }
42
- async #c({ index: t, src: i }) {
43
- const e = typeof i == "string", n = e ? i : i?.src, h = e ? null : i?.onZoom, r = document.createElement("div");
44
- r.setAttribute("dir", "ltr");
45
- const o = document.createElement("iframe");
46
- return r.append(o), Object.assign(o.style, {
47
- border: "0",
48
- display: "none",
49
- overflow: "hidden"
50
- }), o.setAttribute("sandbox", "allow-same-origin allow-scripts"), o.setAttribute("scrolling", "no"), o.setAttribute("part", "filter"), this.#a.append(r), n ? new Promise((s) => {
51
- o.addEventListener("load", () => {
52
- const c = o.contentDocument;
53
- this.dispatchEvent(new CustomEvent("load", { detail: { doc: c, index: t } }));
54
- const { width: a, height: l } = S(c, this.defaultViewport);
55
- s({
56
- element: r,
57
- iframe: o,
58
- width: parseFloat(a),
59
- height: parseFloat(l),
60
- onZoom: h
61
- });
62
- }, { once: !0 }), o.src = n;
63
- }) : { blank: !0, element: r, iframe: o };
64
- }
65
- #e(t = this.#n) {
66
- if (!t) return;
67
- const i = this.#s ?? {}, e = this.#t ?? this.#r ?? {}, n = t === "left" ? i : e, { width: h, height: r } = this.getBoundingClientRect(), o = this.spread !== "both" && this.spread !== "portrait" && r > h;
68
- this.#l = o;
69
- const s = i.width ?? e.width ?? 0, c = i.height ?? e.height ?? 0, a = typeof this.#o == "number" && !isNaN(this.#o) ? this.#o : (this.#o === "fit-width" ? o || this.#t ? h / (n.width ?? s) : h / ((i.width ?? s) + (e.width ?? s)) : o || this.#t ? Math.min(
70
- h / (n.width ?? s),
71
- r / (n.height ?? c)
72
- ) : Math.min(
73
- h / ((i.width ?? s) + (e.width ?? s)),
74
- r / Math.max(
75
- i.height ?? c,
76
- e.height ?? c
77
- )
78
- )) || 1, l = (g) => {
79
- let { element: p, iframe: u, width: m, height: w, blank: x, onZoom: f } = g;
80
- if (!u) return;
81
- f && f({ doc: g.iframe.contentDocument, scale: a });
82
- const b = f ? a : 1;
83
- Object.assign(u.style, {
84
- width: `${m * b}px`,
85
- height: `${w * b}px`,
86
- transform: f ? "none" : `scale(${a})`,
87
- transformOrigin: "top left",
88
- display: x ? "none" : "block"
89
- }), Object.assign(p.style, {
90
- width: `${(m ?? s) * a}px`,
91
- height: `${(w ?? c) * a}px`,
92
- overflow: "hidden",
93
- display: "block",
94
- flexShrink: "0",
95
- marginBlock: "auto"
96
- }), o && g !== n && (p.style.display = "none");
97
- };
98
- this.#t ? l(this.#t) : (l(i), l(e));
99
- }
100
- async #g({ left: t, right: i, center: e, side: n }) {
101
- this.#a.replaceChildren(), this.#s = null, this.#r = null, this.#t = null, e ? (this.#t = await this.#c(e), this.#n = "center", this.#e()) : (this.#s = await this.#c(t), this.#r = await this.#c(i), this.#n = this.#s.blank ? "right" : this.#r.blank ? "left" : n, this.#e());
102
- }
103
- #p() {
104
- if (!(this.#t || this.#s?.blank) && this.#l && this.#s?.element?.style?.display === "none")
105
- return this.#n = "left", this.#e(), this.#d("page"), !0;
106
- }
107
- #u() {
108
- if (!(this.#t || this.#r?.blank) && this.#l && this.#r?.element?.style?.display === "none")
109
- return this.#n = "right", this.#e(), this.#d("page"), !0;
110
- }
111
- open(t) {
112
- this.book = t;
113
- const { rendition: i } = t;
114
- this.spread = i?.spread, this.defaultViewport = i?.viewport;
115
- const e = t.dir === "rtl", n = !e;
116
- this.rtl = e, i?.spread === "none" ? this.#i = t.sections.map((h) => ({ center: h })) : this.#i = t.sections.reduce((h, r, o) => {
117
- const s = h[h.length - 1], { pageSpread: c } = r, a = () => {
118
- const l = {};
119
- return h.push(l), l;
120
- };
121
- if (c === "center") {
122
- const l = s.left || s.right ? a() : s;
123
- l.center = r;
124
- } else if (c === "left") {
125
- const l = s.center || s.left || n && o ? a() : s;
126
- l.left = r;
127
- } else if (c === "right") {
128
- const l = s.center || s.right || e && o ? a() : s;
129
- l.right = r;
130
- } else n ? s.center || s.right ? a().left = r : s.left || !o ? s.right = r : s.left = r : s.center || s.left ? a().right = r : s.right || !o ? s.left = r : s.right = r;
131
- return h;
132
- }, [{}]);
133
- }
134
- get index() {
135
- const t = this.#i[this.#h], i = t?.center ?? (this.#n === "left" ? t.left ?? t.right : t.right ?? t.left);
136
- return this.book.sections.indexOf(i);
137
- }
138
- #d(t) {
139
- this.dispatchEvent(new CustomEvent("relocate", { detail: { reason: t, range: null, index: this.index, fraction: 0, size: 1 } }));
140
- }
141
- getSpreadOf(t) {
142
- const i = this.#i;
143
- for (let e = 0; e < i.length; e++) {
144
- const { left: n, right: h, center: r } = i[e];
145
- if (n === t) return { index: e, side: "left" };
146
- if (h === t) return { index: e, side: "right" };
147
- if (r === t) return { index: e, side: "center" };
148
- }
149
- }
150
- async goToSpread(t, i, e) {
151
- if (t < 0 || t > this.#i.length - 1) return;
152
- if (t === this.#h) {
153
- this.#e(i);
154
- return;
155
- }
156
- this.#h = t;
157
- const n = this.#i[t];
158
- if (n.center) {
159
- const h = this.book.sections.indexOf(n.center), r = await n.center?.load?.();
160
- await this.#g({ center: { index: h, src: r } });
161
- } else {
162
- const h = this.book.sections.indexOf(n.left), r = this.book.sections.indexOf(n.right), o = await n.left?.load?.(), s = await n.right?.load?.(), c = { index: h, src: o }, a = { index: r, src: s };
163
- await this.#g({ left: c, right: a, side: i });
164
- }
165
- this.#d(e);
166
- }
167
- async select(t) {
168
- await this.goTo(t);
169
- }
170
- async goTo(t) {
171
- const { book: i } = this, e = await t, n = i.sections[e.index];
172
- if (!n) return;
173
- const { index: h, side: r } = this.getSpreadOf(n);
174
- await this.goToSpread(h, r);
175
- }
176
- async next() {
177
- if (!(this.rtl ? this.#p() : this.#u())) return this.goToSpread(this.#h + 1, this.rtl ? "right" : "left", "page");
178
- }
179
- async prev() {
180
- if (!(this.rtl ? this.#u() : this.#p())) return this.goToSpread(this.#h - 1, this.rtl ? "left" : "right", "page");
181
- }
182
- getContents() {
183
- return Array.from(this.#a.querySelectorAll("iframe"), (t) => ({
184
- doc: t.contentDocument
185
- // TODO: index, overlayer
186
- }));
187
- }
188
- destroy() {
189
- this.#f.unobserve(this);
190
- }
191
- }
192
- customElements.define("foliate-fxl", k);
193
- export {
194
- k as FixedLayout
195
- };