react-book-reader 1.0.0

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.
@@ -0,0 +1,722 @@
1
+ var Zt = Object.defineProperty;
2
+ var te = (o, s, t) => s in o ? Zt(o, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[s] = t;
3
+ var Ft = (o, s, t) => (te(o, typeof s != "symbol" ? s + "" : s, t), t), $t = (o, s, t) => {
4
+ if (!s.has(o))
5
+ throw TypeError("Cannot " + t);
6
+ };
7
+ var e = (o, s, t) => ($t(o, s, "read from private field"), t ? t.call(o) : s.get(o)), l = (o, s, t) => {
8
+ if (s.has(o))
9
+ throw TypeError("Cannot add the same private member more than once");
10
+ s instanceof WeakSet ? s.add(o) : s.set(o, t);
11
+ }, g = (o, s, t, i) => ($t(o, s, "write to private field"), i ? i.call(o, t) : s.set(o, t), t);
12
+ var c = (o, s, t) => ($t(o, s, "access private method"), t);
13
+ const ee = (o) => new Promise((s) => setTimeout(s, o)), ie = (o, s, t) => {
14
+ let i;
15
+ return (...n) => {
16
+ const r = () => {
17
+ i = null, t || o(...n);
18
+ }, h = t && !i;
19
+ i && clearTimeout(i), i = setTimeout(r, s), h && o(...n);
20
+ };
21
+ }, se = (o, s, t) => t * (s - o) + o, ne = (o) => 1 - (1 - o) * (1 - o), re = (o, s, t, i, n) => new Promise((r) => {
22
+ let h;
23
+ const a = (d) => {
24
+ h ?? (h = d);
25
+ const u = Math.min(1, (d - h) / t);
26
+ n(se(o, s, i(u))), u < 1 ? requestAnimationFrame(a) : r();
27
+ };
28
+ requestAnimationFrame(a);
29
+ }), oe = (o) => {
30
+ if (!(o != null && o.collapsed))
31
+ return o;
32
+ const { endOffset: s, endContainer: t } = o;
33
+ if (t.nodeType === 1)
34
+ return t;
35
+ if (s + 1 < t.length)
36
+ o.setEnd(t, s + 1);
37
+ else if (s > 1)
38
+ o.setStart(t, s - 1);
39
+ else
40
+ return t.parentNode;
41
+ return o;
42
+ }, wt = (o, s, t, i = t) => {
43
+ const n = o.createRange();
44
+ return n.setStart(s, t), n.setEnd(s, i), n;
45
+ }, St = (o, s, t, i = 0, n = s.nodeValue.length) => {
46
+ if (n - i === 1)
47
+ return t(wt(o, s, i), wt(o, s, n)) < 0 ? i : n;
48
+ const r = Math.floor(i + (n - i) / 2), h = t(wt(o, s, i, r), wt(o, s, r, n));
49
+ return h < 0 ? St(o, s, t, i, r) : h > 0 ? St(o, s, t, r, n) : r;
50
+ }, {
51
+ SHOW_ELEMENT: he,
52
+ SHOW_TEXT: ae,
53
+ SHOW_CDATA_SECTION: le,
54
+ FILTER_ACCEPT: jt,
55
+ FILTER_REJECT: Dt,
56
+ FILTER_SKIP: Wt
57
+ } = NodeFilter, ce = he | ae | le, qt = (o, s, t, i) => {
58
+ const n = (f) => {
59
+ var C, b;
60
+ const x = (C = f.localName) == null ? void 0 : C.toLowerCase();
61
+ if (x === "script" || x === "style")
62
+ return Dt;
63
+ if (f.nodeType === 1) {
64
+ const { left: _, right: I } = i(f.getBoundingClientRect());
65
+ if (I < s || _ > t)
66
+ return Dt;
67
+ if (_ >= s && I <= t)
68
+ return jt;
69
+ } else {
70
+ if (!((b = f.nodeValue) != null && b.trim()))
71
+ return Wt;
72
+ const _ = o.createRange();
73
+ _.selectNodeContents(f);
74
+ const { left: I, right: vt } = i(_.getBoundingClientRect());
75
+ if (vt >= s && I <= t)
76
+ return jt;
77
+ }
78
+ return Wt;
79
+ }, r = o.createTreeWalker(o.body, ce, { acceptNode: n }), h = [];
80
+ for (let f = r.nextNode(); f; f = r.nextNode())
81
+ h.push(f);
82
+ const a = h[0] ?? o.body, d = h[h.length - 1] ?? a, u = a.nodeType === 1 ? 0 : St(o, a, (f, x) => {
83
+ const C = i(f.getBoundingClientRect()), b = i(x.getBoundingClientRect());
84
+ return C.right < s && b.left > s ? 0 : b.left > s ? -1 : 1;
85
+ }), w = d.nodeType === 1 ? 0 : St(o, d, (f, x) => {
86
+ const C = i(f.getBoundingClientRect()), b = i(x.getBoundingClientRect());
87
+ return C.right < t && b.left > t ? 0 : b.left > t ? -1 : 1;
88
+ }), p = o.createRange();
89
+ return p.setStart(a, u), p.setEnd(d, w), p;
90
+ }, de = (o) => {
91
+ const { defaultView: s } = o, { writingMode: t, direction: i } = s.getComputedStyle(o.body), n = t === "vertical-rl" || t === "vertical-lr", r = o.body.dir === "rtl" || i === "rtl" || o.documentElement.dir === "rtl";
92
+ return { vertical: n, rtl: r };
93
+ }, Mt = (o) => {
94
+ const s = o.defaultView.getComputedStyle(o.body);
95
+ return s.backgroundColor === "rgba(0, 0, 0, 0)" && s.backgroundImage === "none" ? o.defaultView.getComputedStyle(o.documentElement).background : s.background;
96
+ }, Ht = (o, s) => Array.from({ length: o }, () => {
97
+ const t = document.createElement("div"), i = document.createElement("div");
98
+ return t.append(i), i.setAttribute("part", s), t;
99
+ }), it = (o, s) => {
100
+ const { style: t } = o;
101
+ for (const [i, n] of Object.entries(s))
102
+ t.setProperty(i, n, "important");
103
+ };
104
+ var rt, E, y, ot, v, S, ht, Y, $, J;
105
+ class ue {
106
+ constructor({ container: s, onExpand: t }) {
107
+ l(this, rt, new ResizeObserver(() => this.expand()));
108
+ l(this, E, document.createElement("div"));
109
+ l(this, y, document.createElement("iframe"));
110
+ l(this, ot, document.createRange());
111
+ l(this, v, void 0);
112
+ l(this, S, !1);
113
+ l(this, ht, !1);
114
+ l(this, Y, !0);
115
+ l(this, $, void 0);
116
+ l(this, J, {});
117
+ this.container = s, this.onExpand = t, e(this, y).setAttribute("part", "filter"), e(this, E).append(e(this, y)), Object.assign(e(this, E).style, {
118
+ boxSizing: "content-box",
119
+ position: "relative",
120
+ overflow: "hidden",
121
+ flex: "0 0 auto",
122
+ width: "100%",
123
+ height: "100%",
124
+ display: "flex",
125
+ justifyContent: "center",
126
+ alignItems: "center"
127
+ }), Object.assign(e(this, y).style, {
128
+ overflow: "hidden",
129
+ border: "0",
130
+ display: "none",
131
+ width: "100%",
132
+ height: "100%"
133
+ }), e(this, y).setAttribute("sandbox", "allow-same-origin allow-scripts"), e(this, y).setAttribute("scrolling", "no");
134
+ }
135
+ get element() {
136
+ return e(this, E);
137
+ }
138
+ get document() {
139
+ return e(this, y).contentDocument;
140
+ }
141
+ async load(s, t, i) {
142
+ if (typeof s != "string")
143
+ throw new Error(`${s} is not string`);
144
+ return new Promise((n) => {
145
+ e(this, y).addEventListener("load", () => {
146
+ const r = this.document;
147
+ t == null || t(r), e(this, y).style.display = "block";
148
+ const { vertical: h, rtl: a } = de(r), d = Mt(r);
149
+ e(this, y).style.display = "none", g(this, S, h), g(this, ht, a), e(this, ot).selectNodeContents(r.body);
150
+ const u = i == null ? void 0 : i({ vertical: h, rtl: a, background: d });
151
+ e(this, y).style.display = "block", this.render(u), e(this, rt).observe(r.body), r.fonts.ready.then(() => this.expand()), n();
152
+ }, { once: !0 }), e(this, y).src = s;
153
+ });
154
+ }
155
+ render(s) {
156
+ s && (g(this, Y, s.flow !== "scrolled"), g(this, J, s), e(this, Y) ? this.columnize(s) : this.scrolled(s));
157
+ }
158
+ scrolled({ gap: s, columnWidth: t }) {
159
+ const i = e(this, S), n = this.document;
160
+ it(n.documentElement, {
161
+ "box-sizing": "border-box",
162
+ padding: i ? `${s}px 0` : `0 ${s}px`,
163
+ "column-width": "auto",
164
+ height: "auto",
165
+ width: "auto"
166
+ }), it(n.body, {
167
+ [i ? "max-height" : "max-width"]: `${t}px`,
168
+ margin: "auto"
169
+ }), this.setImageSize(), this.expand();
170
+ }
171
+ columnize({ width: s, height: t, gap: i, columnWidth: n }) {
172
+ const r = e(this, S);
173
+ g(this, $, r ? t : s);
174
+ const h = this.document;
175
+ it(h.documentElement, {
176
+ "box-sizing": "border-box",
177
+ "column-width": `${Math.trunc(n)}px`,
178
+ "column-gap": `${i}px`,
179
+ "column-fill": "auto",
180
+ ...r ? { width: `${s}px` } : { height: `${t}px` },
181
+ padding: r ? `${i / 2}px 0` : `0 ${i / 2}px`,
182
+ overflow: "hidden",
183
+ // force wrap long words
184
+ "overflow-wrap": "break-word",
185
+ // reset some potentially problematic props
186
+ position: "static",
187
+ border: "0",
188
+ margin: "0",
189
+ "max-height": "none",
190
+ "max-width": "none",
191
+ "min-height": "none",
192
+ "min-width": "none",
193
+ // fix glyph clipping in WebKit
194
+ "-webkit-line-box-contain": "block glyphs replaced"
195
+ }), it(h.body, {
196
+ "max-height": "none",
197
+ "max-width": "none",
198
+ margin: "0"
199
+ }), this.setImageSize(), this.expand();
200
+ }
201
+ setImageSize() {
202
+ const { width: s, height: t, margin: i } = e(this, J), n = e(this, S), r = this.document;
203
+ for (const h of r.body.querySelectorAll("img, svg, video")) {
204
+ const { maxHeight: a, maxWidth: d } = r.defaultView.getComputedStyle(h);
205
+ it(h, {
206
+ "max-height": n ? a !== "none" && a !== "0px" ? a : "100%" : `${t - i * 2}px`,
207
+ "max-width": n ? `${s - i * 2}px` : d !== "none" && d !== "0px" ? d : "100%",
208
+ "object-fit": "contain",
209
+ "page-break-inside": "avoid",
210
+ "break-inside": "avoid",
211
+ "box-sizing": "border-box"
212
+ });
213
+ }
214
+ }
215
+ expand() {
216
+ const { documentElement: s } = this.document;
217
+ if (e(this, Y)) {
218
+ const t = e(this, S) ? "height" : "width", i = e(this, S) ? "width" : "height", n = e(this, ot).getBoundingClientRect(), r = s.getBoundingClientRect(), a = (e(this, S) ? 0 : e(this, ht) ? r.right - n.right : n.left - r.left) + n[t], u = Math.ceil(a / e(this, $)) * e(this, $);
219
+ e(this, E).style.padding = "0", e(this, y).style[t] = `${u}px`, e(this, E).style[t] = `${u + e(this, $) * 2}px`, e(this, y).style[i] = "100%", e(this, E).style[i] = "100%", s.style[t] = `${e(this, $)}px`, e(this, v) && (e(this, v).element.style.margin = "0", e(this, v).element.style.left = e(this, S) ? "0" : `${e(this, $)}px`, e(this, v).element.style.top = e(this, S) ? `${e(this, $)}px` : "0", e(this, v).element.style[t] = `${u}px`, e(this, v).redraw());
220
+ } else {
221
+ const t = e(this, S) ? "width" : "height", i = e(this, S) ? "height" : "width", r = s.getBoundingClientRect()[t], { margin: h } = e(this, J), a = e(this, S) ? `0 ${h}px` : `${h}px 0`;
222
+ e(this, E).style.padding = a, e(this, y).style[t] = `${r}px`, e(this, E).style[t] = `${r}px`, e(this, y).style[i] = "100%", e(this, E).style[i] = "100%", e(this, v) && (e(this, v).element.style.margin = a, e(this, v).element.style.left = "0", e(this, v).element.style.top = "0", e(this, v).element.style[t] = `${r}px`, e(this, v).redraw());
223
+ }
224
+ this.onExpand();
225
+ }
226
+ set overlayer(s) {
227
+ g(this, v, s), e(this, E).append(s.element);
228
+ }
229
+ get overlayer() {
230
+ return e(this, v);
231
+ }
232
+ destroy() {
233
+ this.document && e(this, rt).unobserve(this.document.body);
234
+ }
235
+ }
236
+ rt = new WeakMap(), E = new WeakMap(), y = new WeakMap(), ot = new WeakMap(), v = new WeakMap(), S = new WeakMap(), ht = new WeakMap(), Y = new WeakMap(), $ = new WeakMap(), J = new WeakMap();
237
+ var B, at, j, z, L, D, m, T, k, A, M, P, K, W, lt, ct, dt, U, V, q, Z, Et, Xt, ut, At, gt, Pt, mt, Rt, pt, It, H, st, zt, Gt, N, X, O, G, Ct, Yt, Tt, Jt, Q, nt, ft, Bt, yt, Lt, tt, bt, _t, Kt, kt, Ut, R, F, xt, Vt;
238
+ class Qt extends HTMLElement {
239
+ constructor() {
240
+ super();
241
+ l(this, Et);
242
+ l(this, ut);
243
+ l(this, gt);
244
+ l(this, mt);
245
+ l(this, pt);
246
+ // allows one to process rects as if they were LTR and horizontal
247
+ l(this, H);
248
+ l(this, zt);
249
+ l(this, N);
250
+ l(this, O);
251
+ l(this, Ct);
252
+ l(this, Tt);
253
+ l(this, Q);
254
+ l(this, ft);
255
+ l(this, yt);
256
+ l(this, tt);
257
+ l(this, _t);
258
+ l(this, kt);
259
+ l(this, R);
260
+ l(this, xt);
261
+ l(this, B, this.attachShadow({ mode: "closed" }));
262
+ l(this, at, new ResizeObserver(() => this.render()));
263
+ l(this, j, void 0);
264
+ l(this, z, void 0);
265
+ l(this, L, void 0);
266
+ l(this, D, void 0);
267
+ l(this, m, void 0);
268
+ l(this, T, !1);
269
+ l(this, k, !1);
270
+ l(this, A, 0);
271
+ l(this, M, -1);
272
+ l(this, P, 0);
273
+ // anchor view to a fraction (0-1), Range, or Element
274
+ l(this, K, !1);
275
+ l(this, W, !1);
276
+ // while true, prevent any further navigation
277
+ l(this, lt, void 0);
278
+ l(this, ct, /* @__PURE__ */ new WeakMap());
279
+ l(this, dt, matchMedia("(prefers-color-scheme: dark)"));
280
+ l(this, U, void 0);
281
+ l(this, V, void 0);
282
+ l(this, q, void 0);
283
+ l(this, Z, void 0);
284
+ e(this, B).innerHTML = `<style>
285
+ :host {
286
+ --_gap: 7%;
287
+ --_margin: 48px;
288
+ --_max-inline-size: 720px;
289
+ --_max-block-size: 1440px;
290
+ --_max-column-count: 2;
291
+ --_vertical: 0;
292
+ --_half-gap: calc(var(--_gap) / 2);
293
+ --_max-width: calc(
294
+ var(--_vertical) * var(--_max-block-size)
295
+ + (1 - var(--_vertical)) * var(--_max-inline-size) * var(--_max-column-count)
296
+ );
297
+ --_max-height: calc(
298
+ var(--_vertical) * var(--_max-inline-size) * var(--_max-column-count)
299
+ + (1 - var(--_vertical)) * var(--_max-block-size)
300
+ );
301
+ display: grid;
302
+ grid-template-columns:
303
+ minmax(var(--_half-gap), 1fr)
304
+ minmax(0, var(--_max-width))
305
+ minmax(var(--_half-gap), 1fr);
306
+ grid-template-rows:
307
+ minmax(var(--_margin), 1fr)
308
+ minmax(0, var(--_max-height))
309
+ minmax(var(--_margin), 1fr);
310
+ box-sizing: border-box;
311
+ position: relative;
312
+ overflow: hidden;
313
+ width: 100%;
314
+ height: 100%;
315
+ }
316
+ #background {
317
+ grid-column-start: 1;
318
+ grid-column-end: 4;
319
+ grid-row-start: 1;
320
+ grid-row-end: 4;
321
+ }
322
+ #container {
323
+ grid-column-start: 2;
324
+ grid-row-start: 2;
325
+ overflow: hidden;
326
+ }
327
+ :host([flow="scrolled"]) #container {
328
+ grid-column-start: 1;
329
+ grid-column-end: 4;
330
+ grid-row-start: 1;
331
+ grid-row-end: 4;
332
+ overflow: auto;
333
+ }
334
+ #header {
335
+ grid-column-start: 2;
336
+ grid-row-start: 1;
337
+ }
338
+ #footer {
339
+ grid-column-start: 2;
340
+ grid-row-start: 3;
341
+ align-self: end;
342
+ }
343
+ #header, #footer {
344
+ display: grid;
345
+ height: var(--_margin);
346
+ }
347
+ :is(#header, #footer) > * {
348
+ display: flex;
349
+ align-items: center;
350
+ min-width: 0;
351
+ }
352
+ :is(#header, #footer) > * > * {
353
+ width: 100%;
354
+ overflow: hidden;
355
+ white-space: nowrap;
356
+ text-overflow: ellipsis;
357
+ text-align: center;
358
+ font-size: .75em;
359
+ opacity: .6;
360
+ }
361
+ </style>
362
+ <div id="background" part="filter"></div>
363
+ <div id="header"></div>
364
+ <div id="container"></div>
365
+ <div id="footer"></div>
366
+ `, g(this, j, e(this, B).getElementById("background")), g(this, z, e(this, B).getElementById("container")), g(this, L, e(this, B).getElementById("header")), g(this, D, e(this, B).getElementById("footer")), e(this, at).observe(e(this, z)), e(this, z).addEventListener("scroll", ie(() => {
367
+ this.scrolled && (e(this, K) ? g(this, K, !1) : c(this, Q, nt).call(this, "scroll"));
368
+ }, 250));
369
+ const t = { passive: !1 };
370
+ this.addEventListener("touchstart", c(this, gt, Pt).bind(this), t), this.addEventListener("touchmove", c(this, mt, Rt).bind(this), t), this.addEventListener("touchend", c(this, pt, It).bind(this)), this.addEventListener("load", ({ detail: { doc: i } }) => {
371
+ i.addEventListener("touchstart", c(this, gt, Pt).bind(this), t), i.addEventListener("touchmove", c(this, mt, Rt).bind(this), t), i.addEventListener("touchend", c(this, pt, It).bind(this));
372
+ }), g(this, U, () => {
373
+ e(this, m) && (e(this, j).style.background = Mt(e(this, m).document));
374
+ }), e(this, dt).addEventListener("change", e(this, U));
375
+ }
376
+ attributeChangedCallback(t, i, n) {
377
+ switch (t) {
378
+ case "flow":
379
+ this.render();
380
+ break;
381
+ case "gap":
382
+ case "margin":
383
+ case "max-block-size":
384
+ case "max-column-count":
385
+ this.style.setProperty("--_" + t, n);
386
+ break;
387
+ case "max-inline-size":
388
+ this.style.setProperty("--_" + t, n), this.render();
389
+ break;
390
+ }
391
+ }
392
+ open(t) {
393
+ this.bookDir = t.dir, this.sections = t.sections;
394
+ }
395
+ render() {
396
+ e(this, m) && (e(this, m).render(c(this, ut, At).call(this, {
397
+ vertical: e(this, T),
398
+ rtl: e(this, k)
399
+ })), this.scrollToAnchor(e(this, P)));
400
+ }
401
+ get scrolled() {
402
+ return this.getAttribute("flow") === "scrolled";
403
+ }
404
+ get scrollProp() {
405
+ const { scrolled: t } = this;
406
+ return e(this, T) ? t ? "scrollLeft" : "scrollTop" : t ? "scrollTop" : "scrollLeft";
407
+ }
408
+ get sideProp() {
409
+ const { scrolled: t } = this;
410
+ return e(this, T) ? t ? "width" : "height" : t ? "height" : "width";
411
+ }
412
+ get size() {
413
+ return e(this, z).getBoundingClientRect()[this.sideProp];
414
+ }
415
+ get viewSize() {
416
+ return e(this, m).element.getBoundingClientRect()[this.sideProp];
417
+ }
418
+ get start() {
419
+ return Math.abs(e(this, z)[this.scrollProp]);
420
+ }
421
+ get end() {
422
+ return this.start + this.size;
423
+ }
424
+ get page() {
425
+ return Math.floor((this.start + this.end) / 2 / this.size);
426
+ }
427
+ get pages() {
428
+ return Math.round(this.viewSize / this.size);
429
+ }
430
+ scrollBy(t, i) {
431
+ const n = e(this, T) ? i : t, r = e(this, z), { scrollProp: h } = this, [a, d, u] = e(this, V), w = e(this, k), p = w ? a - u : a - d, f = w ? a + d : a + u;
432
+ r[h] = Math.max(p, Math.min(
433
+ f,
434
+ r[h] + n
435
+ ));
436
+ }
437
+ snap(t, i) {
438
+ const n = e(this, T) ? i : t, [r, h, a] = e(this, V), { start: d, end: u, pages: w, size: p } = this, f = Math.abs(r) - h, x = Math.abs(r) + a, C = n * (e(this, k) ? -p : p), b = Math.floor(
439
+ Math.max(f, Math.min(x, (d + u) / 2 + (isNaN(C) ? 0 : C))) / p
440
+ );
441
+ c(this, O, G).call(this, b, "snap").then(() => {
442
+ const _ = b <= 0 ? -1 : b >= w - 1 ? 1 : null;
443
+ if (_)
444
+ return c(this, tt, bt).call(this, {
445
+ index: c(this, R, F).call(this, _),
446
+ anchor: _ < 0 ? () => 1 : () => 0
447
+ });
448
+ });
449
+ }
450
+ async scrollToAnchor(t, i) {
451
+ var d, u;
452
+ g(this, P, t);
453
+ const n = (u = (d = oe(t)) == null ? void 0 : d.getClientRects) == null ? void 0 : u.call(d);
454
+ if (n) {
455
+ const w = Array.from(n).find((p) => p.width > 0 && p.height > 0) || n[0];
456
+ if (!w)
457
+ return;
458
+ await c(this, zt, Gt).call(this, w, "anchor"), i && c(this, Ct, Yt).call(this);
459
+ return;
460
+ }
461
+ if (this.scrolled) {
462
+ await c(this, N, X).call(this, t * this.viewSize, "anchor");
463
+ return;
464
+ }
465
+ const { pages: r } = this;
466
+ if (!r)
467
+ return;
468
+ const h = r - 2, a = Math.round(t * (h - 1));
469
+ await c(this, O, G).call(this, a + 1, "anchor");
470
+ }
471
+ async goTo(t) {
472
+ if (e(this, W))
473
+ return;
474
+ const i = await t;
475
+ if (c(this, yt, Lt).call(this, i.index))
476
+ return c(this, tt, bt).call(this, i);
477
+ }
478
+ get atStart() {
479
+ return c(this, R, F).call(this, -1) == null && this.page <= 1;
480
+ }
481
+ get atEnd() {
482
+ return c(this, R, F).call(this, 1) == null && this.page >= this.pages - 2;
483
+ }
484
+ prev(t) {
485
+ return c(this, xt, Vt).call(this, -1, t);
486
+ }
487
+ next(t) {
488
+ return c(this, xt, Vt).call(this, 1, t);
489
+ }
490
+ prevSection() {
491
+ return this.goTo({ index: c(this, R, F).call(this, -1) });
492
+ }
493
+ nextSection() {
494
+ return this.goTo({ index: c(this, R, F).call(this, 1) });
495
+ }
496
+ firstSection() {
497
+ const t = this.sections.findIndex((i) => i.linear !== "no");
498
+ return this.goTo({ index: t });
499
+ }
500
+ lastSection() {
501
+ const t = this.sections.findLastIndex((i) => i.linear !== "no");
502
+ return this.goTo({ index: t });
503
+ }
504
+ getContents() {
505
+ return e(this, m) ? [{
506
+ index: e(this, M),
507
+ overlayer: e(this, m).overlayer,
508
+ doc: e(this, m).document
509
+ }] : [];
510
+ }
511
+ setStyles(t) {
512
+ var h, a, d, u, w;
513
+ g(this, lt, t);
514
+ const i = e(this, ct).get((h = e(this, m)) == null ? void 0 : h.document);
515
+ if (!i)
516
+ return;
517
+ const [n, r] = i;
518
+ if (Array.isArray(t)) {
519
+ const [p, f] = t;
520
+ n.textContent = p, r.textContent = f;
521
+ } else
522
+ r.textContent = t;
523
+ e(this, j).style.background = Mt(e(this, m).document), (w = (u = (d = (a = e(this, m)) == null ? void 0 : a.document) == null ? void 0 : d.fonts) == null ? void 0 : u.ready) == null || w.then(() => e(this, m).expand());
524
+ }
525
+ destroy() {
526
+ var t, i;
527
+ e(this, at).unobserve(this), e(this, m).destroy(), g(this, m, null), (i = (t = this.sections[e(this, M)]) == null ? void 0 : t.unload) == null || i.call(t), e(this, dt).removeEventListener("change", e(this, U));
528
+ }
529
+ }
530
+ B = new WeakMap(), at = new WeakMap(), j = new WeakMap(), z = new WeakMap(), L = new WeakMap(), D = new WeakMap(), m = new WeakMap(), T = new WeakMap(), k = new WeakMap(), A = new WeakMap(), M = new WeakMap(), P = new WeakMap(), K = new WeakMap(), W = new WeakMap(), lt = new WeakMap(), ct = new WeakMap(), dt = new WeakMap(), U = new WeakMap(), V = new WeakMap(), q = new WeakMap(), Z = new WeakMap(), Et = new WeakSet(), Xt = function() {
531
+ return e(this, m) && (e(this, m).destroy(), e(this, z).removeChild(e(this, m).element)), g(this, m, new ue({
532
+ container: this,
533
+ onExpand: () => this.scrollToAnchor(e(this, P))
534
+ })), e(this, z).append(e(this, m).element), e(this, m);
535
+ }, ut = new WeakSet(), At = function({ vertical: t, rtl: i, background: n }) {
536
+ g(this, T, t), g(this, k, i), this.style.setProperty("--_vertical", t ? 1 : 0), e(this, j).style.background = n;
537
+ const { width: r, height: h } = e(this, z).getBoundingClientRect(), a = t ? h : r, d = getComputedStyle(this), u = parseFloat(d.getPropertyValue("--_max-inline-size")), w = parseInt(d.getPropertyValue("--_max-column-count")), p = parseFloat(d.getPropertyValue("--_margin"));
538
+ g(this, A, p);
539
+ const f = parseFloat(d.getPropertyValue("--_gap")) / 100, x = -f / (f - 1) * a, C = this.getAttribute("flow");
540
+ if (C === "scrolled") {
541
+ this.setAttribute("dir", t ? "rtl" : "ltr"), this.style.padding = "0";
542
+ const et = u;
543
+ return this.heads = null, this.feet = null, e(this, L).replaceChildren(), e(this, D).replaceChildren(), { flow: C, margin: p, gap: x, columnWidth: et };
544
+ }
545
+ const b = Math.min(w, Math.ceil(a / u)), _ = a / b - x;
546
+ this.setAttribute("dir", i ? "rtl" : "ltr");
547
+ const I = t ? Math.min(2, Math.ceil(r / u)) : b, vt = {
548
+ gridTemplateColumns: `repeat(${I}, 1fr)`,
549
+ gap: `${x}px`,
550
+ padding: t ? "0" : `0 ${x / 2}px`,
551
+ direction: this.bookDir === "rtl" ? "rtl" : "ltr"
552
+ };
553
+ Object.assign(e(this, L).style, vt), Object.assign(e(this, D).style, vt);
554
+ const Nt = Ht(I, "head"), Ot = Ht(I, "foot");
555
+ return this.heads = Nt.map((et) => et.children[0]), this.feet = Ot.map((et) => et.children[0]), e(this, L).replaceChildren(...Nt), e(this, D).replaceChildren(...Ot), { height: h, width: r, margin: p, gap: x, columnWidth: _ };
556
+ }, gt = new WeakSet(), Pt = function(t) {
557
+ const i = t.changedTouches[0];
558
+ g(this, q, {
559
+ x: i == null ? void 0 : i.screenX,
560
+ y: i == null ? void 0 : i.screenY,
561
+ t: t.timeStamp,
562
+ vx: 0,
563
+ xy: 0
564
+ });
565
+ }, mt = new WeakSet(), Rt = function(t) {
566
+ const i = e(this, q);
567
+ if (i.pinched || (i.pinched = globalThis.visualViewport.scale > 1, this.scrolled || i.pinched))
568
+ return;
569
+ if (t.touches.length > 1) {
570
+ e(this, Z) && t.preventDefault();
571
+ return;
572
+ }
573
+ t.preventDefault();
574
+ const n = t.changedTouches[0], r = n.screenX, h = n.screenY, a = i.x - r, d = i.y - h, u = t.timeStamp - i.t;
575
+ i.x = r, i.y = h, i.t = t.timeStamp, i.vx = a / u, i.vy = d / u, g(this, Z, !0), this.scrollBy(a, d);
576
+ }, pt = new WeakSet(), It = function() {
577
+ g(this, Z, !1), !this.scrolled && requestAnimationFrame(() => {
578
+ globalThis.visualViewport.scale === 1 && this.snap(e(this, q).vx, e(this, q).vy);
579
+ });
580
+ }, H = new WeakSet(), st = function() {
581
+ if (this.scrolled) {
582
+ const i = this.viewSize, n = e(this, A);
583
+ return e(this, T) ? ({ left: r, right: h }) => ({ left: i - h - n, right: i - r - n }) : ({ top: r, bottom: h }) => ({ left: r + n, right: h + n });
584
+ }
585
+ const t = this.pages * this.size;
586
+ return e(this, k) ? ({ left: i, right: n }) => ({ left: t - n, right: t - i }) : e(this, T) ? ({ top: i, bottom: n }) => ({ left: i, right: n }) : (i) => i;
587
+ }, zt = new WeakSet(), Gt = async function(t, i) {
588
+ if (this.scrolled) {
589
+ const r = c(this, H, st).call(this)(t).left - e(this, A);
590
+ return c(this, N, X).call(this, r, i);
591
+ }
592
+ const n = c(this, H, st).call(this)(t).left + e(this, A) / 2;
593
+ return c(this, O, G).call(this, Math.floor(n / this.size) + (e(this, k) ? -1 : 1), i);
594
+ }, N = new WeakSet(), X = async function(t, i, n) {
595
+ const r = e(this, z), { scrollProp: h, size: a } = this;
596
+ if (r[h] === t) {
597
+ g(this, V, [t, this.atStart ? 0 : a, this.atEnd ? 0 : a]), c(this, Q, nt).call(this, i);
598
+ return;
599
+ }
600
+ if (this.scrolled && e(this, T) && (t = -t), (i === "snap" || n) && this.hasAttribute("animated"))
601
+ return re(
602
+ r[h],
603
+ t,
604
+ 300,
605
+ ne,
606
+ (d) => r[h] = d
607
+ ).then(() => {
608
+ g(this, V, [t, this.atStart ? 0 : a, this.atEnd ? 0 : a]), c(this, Q, nt).call(this, i);
609
+ });
610
+ r[h] = t, g(this, V, [t, this.atStart ? 0 : a, this.atEnd ? 0 : a]), c(this, Q, nt).call(this, i);
611
+ }, O = new WeakSet(), G = async function(t, i, n) {
612
+ const r = this.size * (e(this, k) ? -t : t);
613
+ return c(this, N, X).call(this, r, i, n);
614
+ }, Ct = new WeakSet(), Yt = function() {
615
+ const { defaultView: t } = e(this, m).document;
616
+ if (e(this, P).startContainer) {
617
+ const i = t.getSelection();
618
+ i.removeAllRanges(), i.addRange(e(this, P));
619
+ }
620
+ }, Tt = new WeakSet(), Jt = function() {
621
+ if (this.scrolled)
622
+ return qt(
623
+ e(this, m).document,
624
+ this.start + e(this, A),
625
+ this.end - e(this, A),
626
+ c(this, H, st).call(this)
627
+ );
628
+ const t = e(this, k) ? -this.size : this.size;
629
+ return qt(
630
+ e(this, m).document,
631
+ this.start - t,
632
+ this.end - t,
633
+ c(this, H, st).call(this)
634
+ );
635
+ }, Q = new WeakSet(), nt = function(t) {
636
+ const i = c(this, Tt, Jt).call(this);
637
+ t !== "anchor" ? g(this, P, i) : g(this, K, !0);
638
+ const n = e(this, M), r = { reason: t, range: i, index: n };
639
+ if (this.scrolled)
640
+ r.fraction = this.start / this.viewSize;
641
+ else if (this.pages > 0) {
642
+ const { page: h, pages: a } = this;
643
+ e(this, L).style.visibility = h > 1 ? "visible" : "hidden", r.fraction = (h - 1) / (a - 2), r.size = 1 / (a - 2);
644
+ }
645
+ this.dispatchEvent(new CustomEvent("relocate", { detail: r }));
646
+ }, ft = new WeakSet(), Bt = async function(t) {
647
+ const { index: i, src: n, anchor: r, onLoad: h, select: a } = await t;
648
+ if (g(this, M, i), n) {
649
+ const d = c(this, Et, Xt).call(this), u = (p) => {
650
+ if (p.head) {
651
+ const f = p.createElement("style");
652
+ p.head.prepend(f);
653
+ const x = p.createElement("style");
654
+ p.head.append(x), e(this, ct).set(p, [f, x]);
655
+ }
656
+ h == null || h({ doc: p, index: i });
657
+ }, w = c(this, ut, At).bind(this);
658
+ await d.load(n, u, w), this.dispatchEvent(new CustomEvent("create-overlayer", {
659
+ detail: {
660
+ doc: d.document,
661
+ index: i,
662
+ attach: (p) => d.overlayer = p
663
+ }
664
+ })), g(this, m, d);
665
+ }
666
+ await this.scrollToAnchor((typeof r == "function" ? r(e(this, m).document) : r) ?? 0, a);
667
+ }, yt = new WeakSet(), Lt = function(t) {
668
+ return t >= 0 && t <= this.sections.length - 1;
669
+ }, tt = new WeakSet(), bt = async function({ index: t, anchor: i, select: n }) {
670
+ if (t === e(this, M))
671
+ await c(this, ft, Bt).call(this, { index: t, anchor: i, select: n });
672
+ else {
673
+ const r = e(this, M), h = (a) => {
674
+ var d, u;
675
+ (u = (d = this.sections[r]) == null ? void 0 : d.unload) == null || u.call(d), this.setStyles(e(this, lt)), this.dispatchEvent(new CustomEvent("load", { detail: a }));
676
+ };
677
+ await c(this, ft, Bt).call(this, Promise.resolve(this.sections[t].load()).then((a) => ({ index: t, src: a, anchor: i, onLoad: h, select: n })).catch((a) => (console.warn(a), console.warn(new Error(`Failed to load section ${t}`)), {})));
678
+ }
679
+ }, _t = new WeakSet(), Kt = function(t) {
680
+ if (!e(this, m))
681
+ return !0;
682
+ if (this.scrolled)
683
+ return this.start > 0 ? c(this, N, X).call(this, Math.max(0, this.start - (t ?? this.size)), null, !0) : !0;
684
+ if (this.atStart)
685
+ return;
686
+ const i = this.page - 1;
687
+ return c(this, O, G).call(this, i, "page", !0).then(() => i <= 0);
688
+ }, kt = new WeakSet(), Ut = function(t) {
689
+ if (!e(this, m))
690
+ return !0;
691
+ if (this.scrolled)
692
+ return this.viewSize - this.end > 2 ? c(this, N, X).call(this, Math.min(this.viewSize, t ? this.start + t : this.end), null, !0) : !0;
693
+ if (this.atEnd)
694
+ return;
695
+ const i = this.page + 1, n = this.pages;
696
+ return c(this, O, G).call(this, i, "page", !0).then(() => i >= n - 1);
697
+ }, R = new WeakSet(), F = function(t) {
698
+ var i;
699
+ for (let n = e(this, M) + t; c(this, yt, Lt).call(this, n); n += t)
700
+ if (((i = this.sections[n]) == null ? void 0 : i.linear) !== "no")
701
+ return n;
702
+ }, xt = new WeakSet(), Vt = async function(t, i) {
703
+ if (e(this, W))
704
+ return;
705
+ g(this, W, !0);
706
+ const n = t === -1, r = await (n ? c(this, _t, Kt).call(this, i) : c(this, kt, Ut).call(this, i));
707
+ r && await c(this, tt, bt).call(this, {
708
+ index: c(this, R, F).call(this, t),
709
+ anchor: n ? () => 1 : () => 0
710
+ }), (r || !this.hasAttribute("animated")) && await ee(100), g(this, W, !1);
711
+ }, Ft(Qt, "observedAttributes", [
712
+ "flow",
713
+ "gap",
714
+ "margin",
715
+ "max-inline-size",
716
+ "max-block-size",
717
+ "max-column-count"
718
+ ]);
719
+ customElements.define("foliate-paginator", Qt);
720
+ export {
721
+ Qt as Paginator
722
+ };