@likecoin/epub-ts 0.5.0 → 0.6.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.
package/dist/epub.node.js CHANGED
@@ -1,5 +1,5 @@
1
- import { DOMParser as Ut, parseHTML as jt } from "linkedom";
2
- import Ft from "jszip";
1
+ import { DOMParser as jt, parseHTML as Ft } from "linkedom";
2
+ import Ht from "jszip";
3
3
  function A(a) {
4
4
  const t = typeof a == "function" ? a.prototype : a;
5
5
  return t.on = function(e, i) {
@@ -15,25 +15,25 @@ function A(a) {
15
15
  s[n](...i);
16
16
  }, a;
17
17
  }
18
- const _t = (a) => (Promise.resolve().then(() => a(performance.now())), 0), Vt = typeof window < "u" ? window.requestAnimationFrame.bind(window) : _t, Ht = 1, Tt = typeof URL < "u" ? URL : typeof window < "u" ? window.URL : void 0;
19
- function kt() {
18
+ const Tt = (a) => (Promise.resolve().then(() => a(performance.now())), 0), Vt = typeof window < "u" ? window.requestAnimationFrame.bind(window) : Tt, Xt = 1, kt = typeof URL < "u" ? URL : typeof window < "u" ? window.URL : void 0;
19
+ function Nt() {
20
20
  let a = (/* @__PURE__ */ new Date()).getTime();
21
21
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(e) {
22
22
  const i = (a + Math.random() * 16) % 16 | 0;
23
23
  return a = Math.floor(a / 16), (e === "x" ? i : i & 7 | 8).toString(16);
24
24
  });
25
25
  }
26
- function Xt(a) {
26
+ function Yt(a) {
27
27
  return !!(a && a.nodeType === 1);
28
28
  }
29
29
  function E(a) {
30
30
  return !isNaN(parseFloat(a)) && isFinite(a);
31
31
  }
32
- function Yt(a) {
32
+ function Gt(a) {
33
33
  const t = parseFloat(a);
34
34
  return E(a) === !1 ? !1 : typeof a == "string" && a.indexOf(".") > -1 ? !0 : Math.floor(t) !== t;
35
35
  }
36
- function Gt(a, ...t) {
36
+ function $t(a, ...t) {
37
37
  for (let e = 0; e < t.length; e++) {
38
38
  const i = t[e];
39
39
  for (const s in i)
@@ -41,7 +41,7 @@ function Gt(a, ...t) {
41
41
  }
42
42
  return a;
43
43
  }
44
- function _(a, ...t) {
44
+ function C(a, ...t) {
45
45
  return t.forEach(function(e) {
46
46
  e && Object.getOwnPropertyNames(e).forEach(function(i) {
47
47
  Object.defineProperty(a, i, Object.getOwnPropertyDescriptor(e, i));
@@ -111,20 +111,20 @@ function mt() {
111
111
  height: t
112
112
  };
113
113
  }
114
- function $t(a, t) {
114
+ function Kt(a, t) {
115
115
  const i = a.parentNode.childNodes;
116
116
  let s, n = -1;
117
117
  for (let r = 0; r < i.length && (s = i[r], s.nodeType === t && n++, s !== a); r++)
118
118
  ;
119
119
  return n;
120
120
  }
121
- function Kt(a) {
122
- return $t(a, Ht);
121
+ function Zt(a) {
122
+ return Kt(a, Xt);
123
123
  }
124
124
  function Lt(a) {
125
125
  return ["xml", "opf", "ncx"].indexOf(a) > -1;
126
126
  }
127
- function Nt(a, t) {
127
+ function Rt(a, t) {
128
128
  return t === "json" ? JSON.parse(a) : t && Lt(t) ? W(a, "text/xml") : t === "xhtml" ? W(a, "application/xhtml+xml") : t === "html" || t === "htm" ? W(a, "text/html") : a;
129
129
  }
130
130
  class q extends Error {
@@ -132,15 +132,15 @@ class q extends Error {
132
132
  super(t), this.name = "EpubError", this.status = e;
133
133
  }
134
134
  }
135
- function Zt(a, t) {
135
+ function Qt(a, t) {
136
136
  return new Blob([a], { type: t });
137
137
  }
138
138
  function at(a, t) {
139
- const e = Zt(a, t);
140
- return Tt.createObjectURL(e);
139
+ const e = Qt(a, t);
140
+ return kt.createObjectURL(e);
141
141
  }
142
- function Rt(a) {
143
- return Tt.revokeObjectURL(a);
142
+ function At(a) {
143
+ return kt.revokeObjectURL(a);
144
144
  }
145
145
  function vt(a, t) {
146
146
  if (typeof a != "string")
@@ -148,7 +148,7 @@ function vt(a, t) {
148
148
  const e = btoa(a);
149
149
  return "data:" + t + ";base64," + e;
150
150
  }
151
- function Qt(a) {
151
+ function Jt(a) {
152
152
  return Object.prototype.toString.call(a).slice(8, -1);
153
153
  }
154
154
  function W(a, t) {
@@ -169,15 +169,15 @@ function j(a, t, e) {
169
169
  return t += "]", a.querySelector(t) ?? void 0;
170
170
  }
171
171
  function lt(a, t) {
172
- Jt(a, t, NodeFilter.SHOW_TEXT);
172
+ te(a, t, NodeFilter.SHOW_TEXT);
173
173
  }
174
- function Jt(a, t, e) {
174
+ function te(a, t, e) {
175
175
  const i = document.createTreeWalker(a, e, null);
176
176
  let s;
177
177
  for (; s = i.nextNode(); )
178
178
  t(s);
179
179
  }
180
- function te(a) {
180
+ function ee(a) {
181
181
  return new Promise(function(t, e) {
182
182
  const i = new FileReader();
183
183
  i.readAsDataURL(a), i.onloadend = function() {
@@ -227,7 +227,7 @@ function F(a, t, e) {
227
227
  return n;
228
228
  }
229
229
  }
230
- class ee {
230
+ class ie {
231
231
  constructor() {
232
232
  this.collapsed = !1, this.commonAncestorContainer = void 0, this.endContainer = void 0, this.endOffset = void 0, this.startContainer = void 0, this.startOffset = void 0;
233
233
  }
@@ -267,7 +267,7 @@ function U(a) {
267
267
  if (typeof a != "string")
268
268
  throw new TypeError("Path must be a string. Received " + a);
269
269
  }
270
- function ie(a, t) {
270
+ function se(a, t) {
271
271
  let e = "", i = -1, s = 0, n;
272
272
  for (let r = 0; r <= a.length; ++r) {
273
273
  if (r < a.length)
@@ -308,9 +308,9 @@ function dt(...a) {
308
308
  const s = i >= 0 ? a[i] : "/";
309
309
  U(s), s.length !== 0 && (t = s + "/" + t, e = s.charCodeAt(0) === 47);
310
310
  }
311
- return t = ie(t, !e), e ? t.length > 0 ? "/" + t : "/" : t.length > 0 ? t : ".";
311
+ return t = se(t, !e), e ? t.length > 0 ? "/" + t : "/" : t.length > 0 ? t : ".";
312
312
  }
313
- function se(a, t) {
313
+ function ne(a, t) {
314
314
  if (U(a), U(t), a === t || (a = dt(a), t = dt(t), a === t))
315
315
  return "";
316
316
  let e = 1;
@@ -332,17 +332,17 @@ function se(a, t) {
332
332
  } else s > h && (a.charCodeAt(e + c) === 47 ? l = c : c === 0 && (l = 0));
333
333
  break;
334
334
  }
335
- const f = a.charCodeAt(e + c), p = t.charCodeAt(n + c);
336
- if (f !== p)
335
+ const u = a.charCodeAt(e + c), p = t.charCodeAt(n + c);
336
+ if (u !== p)
337
337
  break;
338
- f === 47 && (l = c);
338
+ u === 47 && (l = c);
339
339
  }
340
340
  let d = "";
341
341
  for (c = e + l + 1; c <= i; ++c)
342
342
  (c === i || a.charCodeAt(c) === 47) && (d.length === 0 ? d += ".." : d += "/..");
343
343
  return d.length > 0 ? d + t.slice(n + l) : (n += l, t.charCodeAt(n) === 47 && ++n, t.slice(n));
344
344
  }
345
- function ne(a) {
345
+ function re(a) {
346
346
  if (U(a), a.length === 0)
347
347
  return ".";
348
348
  let t = a.charCodeAt(0);
@@ -358,10 +358,10 @@ function ne(a) {
358
358
  s = !1;
359
359
  return i === -1 ? e ? "/" : "." : e && i === 1 ? "//" : a.slice(0, i);
360
360
  }
361
- function re(a) {
361
+ function oe(a) {
362
362
  return U(a), a.length > 0 && a.charCodeAt(0) === 47;
363
363
  }
364
- function oe(a) {
364
+ function he(a) {
365
365
  U(a);
366
366
  const t = { root: "", dir: "", base: "", ext: "", name: "" };
367
367
  if (a.length === 0)
@@ -383,7 +383,7 @@ function oe(a) {
383
383
  }
384
384
  return n === -1 || o === -1 || c === 0 || c === 1 && n === o - 1 && n === r + 1 ? o !== -1 && (r === 0 && i ? t.base = t.name = a.slice(1, o) : t.base = t.name = a.slice(r, o)) : (r === 0 && i ? (t.name = a.slice(1, n), t.base = a.slice(1, o)) : (t.name = a.slice(r, n), t.base = a.slice(r, o)), t.ext = a.slice(n, o)), r > 0 ? t.dir = a.slice(0, r - 1) : i && (t.dir = "/"), t;
385
385
  }
386
- const z = { resolve: dt, relative: se, dirname: ne, isAbsolute: re, parse: oe };
386
+ const D = { resolve: dt, relative: ne, dirname: re, isAbsolute: oe, parse: he };
387
387
  class P {
388
388
  constructor(t) {
389
389
  t.indexOf("://") > -1 && (t = new URL(t).pathname);
@@ -396,14 +396,14 @@ class P {
396
396
  * @returns {object}
397
397
  */
398
398
  parse(t) {
399
- return z.parse(t);
399
+ return D.parse(t);
400
400
  }
401
401
  /**
402
402
  * @param {string} what
403
403
  * @returns {boolean}
404
404
  */
405
405
  isAbsolute(t) {
406
- return z.isAbsolute(t || this.path);
406
+ return D.isAbsolute(t || this.path);
407
407
  }
408
408
  /**
409
409
  * Check if path ends with a directory
@@ -421,7 +421,7 @@ class P {
421
421
  * @returns {string} resolved
422
422
  */
423
423
  resolve(t) {
424
- return z.resolve(this.directory, t);
424
+ return D.resolve(this.directory, t);
425
425
  }
426
426
  /**
427
427
  * Resolve a path relative to the directory of the Path
@@ -431,7 +431,7 @@ class P {
431
431
  * @returns {string} relative
432
432
  */
433
433
  relative(t) {
434
- return t && t.indexOf("://") > -1 ? t : z.relative(this.directory, t);
434
+ return t && t.indexOf("://") > -1 ? t : D.relative(this.directory, t);
435
435
  }
436
436
  /**
437
437
  * Return the path string
@@ -441,7 +441,7 @@ class P {
441
441
  return this.path;
442
442
  }
443
443
  }
444
- class N {
444
+ class L {
445
445
  constructor(t, e) {
446
446
  const i = t.indexOf("://") > -1;
447
447
  let s = t, n;
@@ -467,7 +467,7 @@ class N {
467
467
  resolve(t) {
468
468
  if (t.indexOf("://") > -1)
469
469
  return t;
470
- const i = z.resolve(this.directory, t);
470
+ const i = D.resolve(this.directory, t);
471
471
  return this.origin + i;
472
472
  }
473
473
  /**
@@ -476,7 +476,7 @@ class N {
476
476
  * @returns {string} path
477
477
  */
478
478
  relative(t) {
479
- return z.relative(t, this.directory);
479
+ return D.relative(t, this.directory);
480
480
  }
481
481
  /**
482
482
  * @returns {string}
@@ -485,19 +485,19 @@ class N {
485
485
  return this.href;
486
486
  }
487
487
  }
488
- const M = 1, k = 3, he = 9;
489
- class m {
488
+ const M = 1, k = 3, ae = 9;
489
+ class y {
490
490
  constructor(t, e, i) {
491
- if (this.str = "", this.base = {}, this.spinePos = 0, this.range = !1, this.path = {}, this.start = null, this.end = null, !(this instanceof m))
492
- return new m(t, e, i);
491
+ if (this.str = "", this.base = {}, this.spinePos = 0, this.range = !1, this.path = {}, this.start = null, this.end = null, !(this instanceof y))
492
+ return new y(t, e, i);
493
493
  typeof e == "string" ? this.base = this.parseComponent(e) : typeof e == "object" && e.steps && (this.base = e);
494
494
  const s = this.checkType(t);
495
495
  if (s === "string")
496
- return this.str = t, _(this, this.parse(t));
496
+ return this.str = t, C(this, this.parse(t));
497
497
  if (s === "range")
498
- return _(this, this.fromRange(t, this.base, i));
498
+ return C(this, this.fromRange(t, this.base, i));
499
499
  if (s === "node")
500
- return _(this, this.fromNode(t, this.base, i));
500
+ return C(this, this.fromNode(t, this.base, i));
501
501
  if (s === "EpubCFI" && t.path)
502
502
  return t;
503
503
  if (t)
@@ -509,7 +509,7 @@ class m {
509
509
  * @private
510
510
  */
511
511
  checkType(t) {
512
- return this.isCfiString(t) ? "string" : t && typeof t == "object" && (Qt(t) === "Range" || typeof t.startContainer < "u") ? "range" : t && typeof t == "object" && typeof t.nodeType < "u" ? "node" : t && typeof t == "object" && t instanceof m ? "EpubCFI" : !1;
512
+ return this.isCfiString(t) ? "string" : t && typeof t == "object" && (Jt(t) === "Range" || typeof t.startContainer < "u") ? "range" : t && typeof t == "object" && typeof t.nodeType < "u" ? "node" : t && typeof t == "object" && t instanceof y ? "EpubCFI" : !1;
513
513
  }
514
514
  /**
515
515
  * Parse a cfi string to a CFI object representation
@@ -611,7 +611,7 @@ class m {
611
611
  */
612
612
  compare(t, e) {
613
613
  let i, s, n, r;
614
- if (typeof t == "string" && (t = new m(t)), typeof e == "string" && (e = new m(e)), t.spinePos > e.spinePos)
614
+ if (typeof t == "string" && (t = new y(t)), typeof e == "string" && (e = new y(e)), t.spinePos > e.spinePos)
615
615
  return 1;
616
616
  if (t.spinePos < e.spinePos)
617
617
  return -1;
@@ -659,7 +659,7 @@ class m {
659
659
  }
660
660
  };
661
661
  let n = t, r;
662
- for (; n && n.parentNode && n.parentNode.nodeType !== he; )
662
+ for (; n && n.parentNode && n.parentNode.nodeType !== ae; )
663
663
  i ? r = this.filteredStep(n, i) : r = this.step(n), r && s.steps.unshift(r), n = n.parentNode;
664
664
  return e != null && e >= 0 && (s.terminal.offset = e, s.steps.length > 0 && s.steps[s.steps.length - 1].type !== "text" && s.steps.push({
665
665
  type: "text",
@@ -839,13 +839,13 @@ class m {
839
839
  let s, n, r, o, h;
840
840
  const l = this;
841
841
  let c, d;
842
- const f = e ? i.querySelector("." + e) != null : !1;
842
+ const u = e ? i.querySelector("." + e) != null : !1;
843
843
  let p;
844
- if (typeof i.createRange < "u" ? s = i.createRange() : s = new ee(), l.range ? (n = l.start, c = l.path.steps.concat(n.steps), o = this.findNode(c, i, f ? e : void 0), r = l.end, d = l.path.steps.concat(r.steps), h = this.findNode(d, i, f ? e : void 0)) : (n = l.path, c = l.path.steps, o = this.findNode(l.path.steps, i, f ? e : void 0)), o)
844
+ if (typeof i.createRange < "u" ? s = i.createRange() : s = new ie(), l.range ? (n = l.start, c = l.path.steps.concat(n.steps), o = this.findNode(c, i, u ? e : void 0), r = l.end, d = l.path.steps.concat(r.steps), h = this.findNode(d, i, u ? e : void 0)) : (n = l.path, c = l.path.steps, o = this.findNode(l.path.steps, i, u ? e : void 0)), o)
845
845
  try {
846
846
  n.terminal.offset != null ? s.setStart(o, n.terminal.offset) : s.setStart(o, 0);
847
847
  } catch {
848
- p = this.fixMiss(c, n.terminal.offset, i, f ? e : void 0), s.setStart(p.container, p.offset);
848
+ p = this.fixMiss(c, n.terminal.offset, i, u ? e : void 0), s.setStart(p.container, p.offset);
849
849
  }
850
850
  else
851
851
  return console.log("No startContainer found for", this.toString()), null;
@@ -853,7 +853,7 @@ class m {
853
853
  try {
854
854
  r.terminal.offset != null ? s.setEnd(h, r.terminal.offset) : s.setEnd(h, 0);
855
855
  } catch {
856
- p = this.fixMiss(d, l.end.terminal.offset, i, f ? e : void 0), s.setEnd(p.container, p.offset);
856
+ p = this.fixMiss(d, l.end.terminal.offset, i, u ? e : void 0), s.setEnd(p.container, p.offset);
857
857
  }
858
858
  return s;
859
859
  }
@@ -932,7 +932,7 @@ class R {
932
932
  return this.hooks = [];
933
933
  }
934
934
  }
935
- function At(a, t) {
935
+ function It(a, t) {
936
936
  let e, i = t.url;
937
937
  const s = i.indexOf("://") > -1;
938
938
  if (!a)
@@ -940,7 +940,7 @@ function At(a, t) {
940
940
  const n = w(a, "head");
941
941
  e = w(n, "base"), e || (e = a.createElement("base"), n.insertBefore(e, n.firstChild)), !s && typeof window < "u" && window.location && (i = window.location.origin + i), e.setAttribute("href", i);
942
942
  }
943
- function ae(a, t) {
943
+ function le(a, t) {
944
944
  let e;
945
945
  const i = t.canonical;
946
946
  if (!a)
@@ -948,7 +948,7 @@ function ae(a, t) {
948
948
  const s = w(a, "head");
949
949
  e = w(s, "link[rel='canonical']"), e ? e.setAttribute("href", i) : (e = a.createElement("link"), e.setAttribute("rel", "canonical"), e.setAttribute("href", i), s.appendChild(e));
950
950
  }
951
- function le(a, t) {
951
+ function ce(a, t) {
952
952
  let e;
953
953
  const i = t.idref;
954
954
  if (!a)
@@ -956,7 +956,7 @@ function le(a, t) {
956
956
  const s = w(a, "head");
957
957
  e = w(s, "link[property='dc.identifier']"), e ? e.setAttribute("content", i) : (e = a.createElement("meta"), e.setAttribute("name", "dc.identifier"), e.setAttribute("content", i), s.appendChild(e));
958
958
  }
959
- function ce(a, t) {
959
+ function de(a, t) {
960
960
  const e = a.querySelectorAll("a[href]");
961
961
  if (!e.length)
962
962
  return;
@@ -974,7 +974,7 @@ function ce(a, t) {
974
974
  else {
975
975
  let c;
976
976
  try {
977
- c = new N(o, s);
977
+ c = new L(o, s);
978
978
  } catch {
979
979
  }
980
980
  r.onclick = function() {
@@ -985,7 +985,7 @@ function ce(a, t) {
985
985
  for (let r = 0; r < e.length; r++)
986
986
  n(e[r]);
987
987
  }
988
- function bt(a, t, e) {
988
+ function xt(a, t, e) {
989
989
  const i = /* @__PURE__ */ new Map(), s = [], n = /[-[\]{}()*+?.,\\^$|#\s]/g;
990
990
  for (let o = 0; o < t.length; o++) {
991
991
  const h = t[o], l = e[o];
@@ -995,8 +995,8 @@ function bt(a, t, e) {
995
995
  try {
996
996
  const d = decodeURIComponent(h);
997
997
  if (d !== h) {
998
- const f = d.replace(n, "\\$&");
999
- i.set(d, l), s.push(f);
998
+ const u = d.replace(n, "\\$&");
999
+ i.set(d, l), s.push(u);
1000
1000
  }
1001
1001
  } catch {
1002
1002
  }
@@ -1006,7 +1006,7 @@ function bt(a, t, e) {
1006
1006
  const r = new RegExp(s.join("|"), "g");
1007
1007
  return a.replace(r, (o) => i.get(o) ?? o);
1008
1008
  }
1009
- async function V(a, t, e, i) {
1009
+ async function H(a, t, e, i) {
1010
1010
  t || (t = new P(a).extension);
1011
1011
  const s = {};
1012
1012
  if (e && (s.credentials = "include"), i || t === "json") {
@@ -1034,7 +1034,7 @@ async function V(a, t, e, i) {
1034
1034
  const r = await n.text();
1035
1035
  return Lt(t) ? W(r, "text/xml") : t === "xhtml" ? W(r, "application/xhtml+xml") : t === "html" || t === "htm" ? W(r, "text/html") : r;
1036
1036
  }
1037
- class de {
1037
+ class ue {
1038
1038
  constructor(t, e) {
1039
1039
  this.idref = t.idref, this.linear = t.linear === "yes", this.properties = t.properties, this.index = t.index, this.href = t.href, this.url = t.url, this.canonical = t.canonical, this.next = t.next, this.prev = t.prev, this.cfiBase = t.cfiBase, e ? this.hooks = e : (this.hooks = {}, this.hooks.serialize = new R(this), this.hooks.content = new R(this)), this.document = void 0, this.contents = void 0, this.output = void 0;
1040
1040
  }
@@ -1044,7 +1044,7 @@ class de {
1044
1044
  * @return {document} a promise with the xml document
1045
1045
  */
1046
1046
  async load(t) {
1047
- const e = t || this.request || V;
1047
+ const e = t || this.request || H;
1048
1048
  if (this.contents)
1049
1049
  return this.contents;
1050
1050
  const i = await e(this.url);
@@ -1055,7 +1055,7 @@ class de {
1055
1055
  * @private
1056
1056
  */
1057
1057
  base() {
1058
- return At(this.document, this);
1058
+ return It(this.document, this);
1059
1059
  }
1060
1060
  /**
1061
1061
  * Render the contents of a section
@@ -1074,12 +1074,12 @@ class de {
1074
1074
  find(t) {
1075
1075
  const e = this, i = [], s = t.toLowerCase(), n = function(r) {
1076
1076
  const o = r.textContent.toLowerCase();
1077
- let h, l, c, d = -1, f;
1077
+ let h, l, c, d = -1, u;
1078
1078
  const p = 150;
1079
1079
  for (; c !== -1; )
1080
- c = o.indexOf(s, d + 1), c !== -1 && (h = e.document.createRange(), h.setStart(r, c), h.setEnd(r, c + s.length), l = e.cfiFromRange(h), r.textContent.length < p ? f = r.textContent : (f = r.textContent.substring(c - p / 2, c + p / 2), f = "..." + f + "..."), i.push({
1080
+ c = o.indexOf(s, d + 1), c !== -1 && (h = e.document.createRange(), h.setStart(r, c), h.setEnd(r, c + s.length), l = e.cfiFromRange(h), r.textContent.length < p ? u = r.textContent : (u = r.textContent.substring(c - p / 2, c + p / 2), u = "..." + u + "..."), i.push({
1081
1081
  cfi: l,
1082
- excerpt: f
1082
+ excerpt: u
1083
1083
  })), d = c;
1084
1084
  };
1085
1085
  return lt(e.document, function(r) {
@@ -1094,21 +1094,21 @@ class de {
1094
1094
  */
1095
1095
  search(t, e = 5) {
1096
1096
  const i = [], n = this, r = t.toLowerCase(), o = function(d) {
1097
- const g = d.reduce((v, y) => v + (y.textContent ?? ""), "").toLowerCase().indexOf(r);
1097
+ const g = d.reduce((m, v) => m + (v.textContent ?? ""), "").toLowerCase().indexOf(r);
1098
1098
  if (g !== -1) {
1099
- const y = g + r.length;
1100
- let b = 0, T = 0;
1099
+ const v = g + r.length;
1100
+ let x = 0, T = 0;
1101
1101
  if (g < d[0].length) {
1102
- for (; b < d.length - 1 && (T += d[b].length, !(y <= T)); )
1103
- b += 1;
1104
- const x = d[0], C = d[b], I = n.document.createRange();
1105
- I.setStart(x, g);
1106
- const Y = d.slice(0, b).reduce((Z, Q) => Z + (Q.textContent ?? "").length, 0);
1107
- I.setEnd(C, Y > y ? y : y - Y);
1108
- const D = n.cfiFromRange(I);
1109
- let O = d.slice(0, b + 1).reduce((Z, Q) => Z + (Q.textContent ?? ""), "");
1102
+ for (; x < d.length - 1 && (T += d[x].length, !(v <= T)); )
1103
+ x += 1;
1104
+ const b = d[0], _ = d[x], I = n.document.createRange();
1105
+ I.setStart(b, g);
1106
+ const Y = d.slice(0, x).reduce((Z, Q) => Z + (Q.textContent ?? "").length, 0);
1107
+ I.setEnd(_, Y > v ? v : v - Y);
1108
+ const z = n.cfiFromRange(I);
1109
+ let O = d.slice(0, x + 1).reduce((Z, Q) => Z + (Q.textContent ?? ""), "");
1110
1110
  O.length > 150 && (O = O.substring(g - 150 / 2, g + 150 / 2), O = "..." + O + "..."), i.push({
1111
- cfi: D,
1111
+ cfi: z,
1112
1112
  excerpt: O
1113
1113
  });
1114
1114
  }
@@ -1143,7 +1143,7 @@ class de {
1143
1143
  * @return {string} cfi an EpubCFI string
1144
1144
  */
1145
1145
  cfiFromRange(t) {
1146
- return new m(t, this.cfiBase).toString();
1146
+ return new y(t, this.cfiBase).toString();
1147
1147
  }
1148
1148
  /**
1149
1149
  * Get a CFI from an Element in the Section
@@ -1151,7 +1151,7 @@ class de {
1151
1151
  * @return {string} cfi an EpubCFI string
1152
1152
  */
1153
1153
  cfiFromElement(t) {
1154
- return new m(t, this.cfiBase).toString();
1154
+ return new y(t, this.cfiBase).toString();
1155
1155
  }
1156
1156
  /**
1157
1157
  * Unload the section document
@@ -1163,9 +1163,9 @@ class de {
1163
1163
  this.unload(), this.hooks.serialize.clear(), this.hooks.content.clear(), this.hooks = void 0, this.idref = void 0, this.linear = void 0, this.properties = void 0, this.index = void 0, this.href = void 0, this.url = void 0, this.next = void 0, this.prev = void 0, this.cfiBase = void 0;
1164
1164
  }
1165
1165
  }
1166
- class ue {
1166
+ class fe {
1167
1167
  constructor() {
1168
- this.spineItems = [], this.spineByHref = {}, this.spineById = {}, this.hooks = {}, this.hooks.serialize = new R(), this.hooks.content = new R(), this.hooks.content.register(At), this.hooks.content.register(ae), this.hooks.content.register(le), this.epubcfi = new m(), this.loaded = !1, this.items = [], this.manifest = {}, this.spineNodeIndex = 0, this.baseUrl = "", this.length = 0;
1168
+ this.spineItems = [], this.spineByHref = {}, this.spineById = {}, this.hooks = {}, this.hooks.serialize = new R(), this.hooks.content = new R(), this.hooks.content.register(It), this.hooks.content.register(le), this.hooks.content.register(ce), this.epubcfi = new y(), this.loaded = !1, this.items = [], this.manifest = {}, this.spineNodeIndex = 0, this.baseUrl = "", this.length = 0;
1169
1169
  }
1170
1170
  /**
1171
1171
  * Unpack items from a opf into spine items
@@ -1195,7 +1195,7 @@ class ue {
1195
1195
  }) : (s.prev = function() {
1196
1196
  }, s.next = function() {
1197
1197
  });
1198
- const o = new de(s, this.hooks);
1198
+ const o = new ue(s, this.hooks);
1199
1199
  this.append(o);
1200
1200
  }), this.loaded = !0;
1201
1201
  }
@@ -1217,7 +1217,7 @@ class ue {
1217
1217
  break;
1218
1218
  e += 1;
1219
1219
  }
1220
- else this.epubcfi.isCfiString(t) ? e = new m(t).spinePos : typeof t == "number" || isNaN(Number(t)) === !1 ? e = Number(t) : typeof t == "string" && t.indexOf("#") === 0 ? e = this.spineById[t.substring(1)] ?? -1 : typeof t == "string" && (t = t.split("#")[0], e = this.spineByHref[t] ?? this.spineByHref[encodeURI(t)] ?? -1);
1220
+ else this.epubcfi.isCfiString(t) ? e = new y(t).spinePos : typeof t == "number" || isNaN(Number(t)) === !1 ? e = Number(t) : typeof t == "string" && t.indexOf("#") === 0 ? e = this.spineById[t.substring(1)] ?? -1 : typeof t == "string" && (t = t.split("#")[0], e = this.spineByHref[t] ?? this.spineByHref[encodeURI(t)] ?? -1);
1221
1221
  return this.spineItems[e] ?? null;
1222
1222
  }
1223
1223
  /**
@@ -1375,7 +1375,7 @@ class pt {
1375
1375
  this._q = [], this.running = !1, this.paused = !0;
1376
1376
  }
1377
1377
  }
1378
- const It = "0.3", G = ["keydown", "keyup", "keypress", "mouseup", "mousedown", "mousemove", "click", "dblclick", "touchend", "touchstart", "touchmove"], u = {
1378
+ const Pt = "0.3", G = ["keydown", "keyup", "keypress", "mouseup", "mousedown", "mousemove", "click", "dblclick", "touchend", "touchstart", "touchmove"], f = {
1379
1379
  BOOK: {
1380
1380
  OPEN_FAILED: "openFailed"
1381
1381
  },
@@ -1432,9 +1432,9 @@ const It = "0.3", G = ["keydown", "keyup", "keypress", "mouseup", "mousedown", "
1432
1432
  DETACH: "detach"
1433
1433
  }
1434
1434
  };
1435
- class Pt {
1435
+ class Ot {
1436
1436
  constructor(t, e, i) {
1437
- this.spine = t, this.request = e, this.pause = i || 0, this.q = new pt(this), this.q.tick = _t, this.epubcfi = new m(), this._locations = [], this._locationsWords = [], this.total = 0, this.break = 150, this._current = 0, this._wordCounter = 0, this._currentCfi = "", this.processingTimeout = void 0;
1437
+ this.spine = t, this.request = e, this.pause = i || 0, this.q = new pt(this), this.q.tick = Tt, this.epubcfi = new y(), this._locations = [], this._locationsWords = [], this.total = 0, this.break = 150, this._current = 0, this._wordCounter = 0, this._currentCfi = "", this.processingTimeout = void 0;
1438
1438
  }
1439
1439
  /**
1440
1440
  * Load all of sections in the book to generate locations
@@ -1466,24 +1466,24 @@ class Pt {
1466
1466
  const r = t.ownerDocument, o = w(r, "body");
1467
1467
  let h = 0, l;
1468
1468
  const c = i || this.break;
1469
- if (lt(o, (f) => {
1470
- const p = f.length;
1471
- let g, v = 0;
1472
- if ((f.textContent ?? "").trim().length === 0)
1473
- return l = f, !1;
1474
- for (h === 0 && (n = this.createRange(), n.startContainer = f, n.startOffset = 0), g = c - h, g > p && (h += p, v = p); v < p; )
1475
- if (g = c - h, h === 0 && (v += 1, n = this.createRange(), n.startContainer = f, n.startOffset = v), v + g >= p)
1476
- h += p - v, v = p;
1469
+ if (lt(o, (u) => {
1470
+ const p = u.length;
1471
+ let g, m = 0;
1472
+ if ((u.textContent ?? "").trim().length === 0)
1473
+ return l = u, !1;
1474
+ for (h === 0 && (n = this.createRange(), n.startContainer = u, n.startOffset = 0), g = c - h, g > p && (h += p, m = p); m < p; )
1475
+ if (g = c - h, h === 0 && (m += 1, n = this.createRange(), n.startContainer = u, n.startOffset = m), m + g >= p)
1476
+ h += p - m, m = p;
1477
1477
  else {
1478
- v += g, n.endContainer = f, n.endOffset = v;
1479
- const y = new m(n, e).toString();
1480
- s.push(y), h = 0;
1478
+ m += g, n.endContainer = u, n.endOffset = m;
1479
+ const v = new y(n, e).toString();
1480
+ s.push(v), h = 0;
1481
1481
  }
1482
- return l = f, !1;
1482
+ return l = u, !1;
1483
1483
  }), n && n.startContainer && l) {
1484
1484
  n.endContainer = l, n.endOffset = l.length;
1485
- const f = new m(n, e).toString();
1486
- s.push(f), h = 0;
1485
+ const u = new y(n, e).toString();
1486
+ s.push(u), h = 0;
1487
1487
  }
1488
1488
  return s;
1489
1489
  }
@@ -1495,7 +1495,7 @@ class Pt {
1495
1495
  * @return {object} locations
1496
1496
  */
1497
1497
  generateFromWords(t, e, i) {
1498
- const s = t ? new m(t) : void 0;
1498
+ const s = t ? new y(t) : void 0;
1499
1499
  return this.q.pause(), this._locationsWords = [], this._wordCounter = 0, this.spine.each((n) => {
1500
1500
  n.linear && (s ? n.index >= s.spinePos && this.q.enqueue((r, o, h, l) => this.processWords(r, o, h, l), n, e, s, i) : this.q.enqueue((r, o, h, l) => this.processWords(r, o, h, l), n, e, s, i));
1501
1501
  }), this.q.run().then(() => (this._currentCfi && (this.currentLocation = this._currentCfi), this._locationsWords));
@@ -1525,16 +1525,16 @@ class Pt {
1525
1525
  if ((p.textContent ?? "").length < 10 && (p.textContent ?? "").trim().length === 0)
1526
1526
  return !1;
1527
1527
  const g = this.countWords(p.textContent ?? "");
1528
- let v, y = 0;
1528
+ let m, v = 0;
1529
1529
  if (g === 0)
1530
1530
  return !1;
1531
- for (v = l - this._wordCounter, v > g && (this._wordCounter += g, y = g); y < g; )
1532
- if (v = l - this._wordCounter, y + v >= g)
1533
- this._wordCounter += g - y, y = g;
1531
+ for (m = l - this._wordCounter, m > g && (this._wordCounter += g, v = g); v < g; )
1532
+ if (m = l - this._wordCounter, v + m >= g)
1533
+ this._wordCounter += g - v, v = g;
1534
1534
  else {
1535
- y += v;
1536
- const b = new m(p, n);
1537
- r.push({ cfi: b.toString(), wordCount: this._wordCounter }), this._wordCounter = 0;
1535
+ v += m;
1536
+ const x = new y(p, n);
1537
+ r.push({ cfi: x.toString(), wordCount: this._wordCounter }), this._wordCounter = 0;
1538
1538
  }
1539
1539
  return !1;
1540
1540
  }), r;
@@ -1545,7 +1545,7 @@ class Pt {
1545
1545
  * @return {number}
1546
1546
  */
1547
1547
  locationFromCfi(t) {
1548
- if (m.prototype.isCfiString(t) && (t = new m(t)), this._locations.length === 0)
1548
+ if (y.prototype.isCfiString(t) && (t = new y(t)), this._locations.length === 0)
1549
1549
  return -1;
1550
1550
  const e = $(t, this._locations, this.epubcfi.compare);
1551
1551
  return e > this.total ? this.total : e;
@@ -1585,7 +1585,7 @@ class Pt {
1585
1585
  */
1586
1586
  cfiFromPercentage(t) {
1587
1587
  if (t > 1 && console.warn("Normalize cfiFromPercentage value to between 0 - 1"), t >= 1) {
1588
- const i = new m(this._locations[this.total]);
1588
+ const i = new y(this._locations[this.total]);
1589
1589
  return i.collapse(), i.toString();
1590
1590
  }
1591
1591
  const e = Math.ceil(this.total * t);
@@ -1616,7 +1616,7 @@ class Pt {
1616
1616
  this._current = t;
1617
1617
  else
1618
1618
  return;
1619
- this._locations.length !== 0 && (typeof t == "string" ? (e = this.locationFromCfi(t), this._current = e) : e = t, this.emit(u.LOCATIONS.CHANGED, {
1619
+ this._locations.length !== 0 && (typeof t == "string" ? (e = this.locationFromCfi(t), this._current = e) : e = t, this.emit(f.LOCATIONS.CHANGED, {
1620
1620
  percentage: this.percentageFromLocation(e)
1621
1621
  }));
1622
1622
  }
@@ -1642,8 +1642,8 @@ class Pt {
1642
1642
  this.spine = void 0, this.request = void 0, this.pause = void 0, this.q?.stop(), this.q = void 0, this.epubcfi = void 0, this._locations = void 0, this.total = void 0, this.break = void 0, this._current = void 0, this.currentLocation = void 0, this._currentCfi = void 0, clearTimeout(this.processingTimeout);
1643
1643
  }
1644
1644
  }
1645
- A(Pt.prototype);
1646
- class fe {
1645
+ A(Ot.prototype);
1646
+ class pe {
1647
1647
  constructor(t) {
1648
1648
  this.packagePath = "", this.directory = "", this.encoding = "", t && this.parse(t);
1649
1649
  }
@@ -1657,13 +1657,13 @@ class fe {
1657
1657
  const e = w(t, "rootfile");
1658
1658
  if (!e)
1659
1659
  throw new Error("No RootFile Found");
1660
- this.packagePath = e.getAttribute("full-path") ?? "", this.directory = z.dirname(this.packagePath), this.encoding = t.xmlEncoding;
1660
+ this.packagePath = e.getAttribute("full-path") ?? "", this.directory = D.dirname(this.packagePath), this.encoding = t.xmlEncoding;
1661
1661
  }
1662
1662
  destroy() {
1663
1663
  this.packagePath = void 0, this.directory = void 0, this.encoding = void 0;
1664
1664
  }
1665
1665
  }
1666
- class xt {
1666
+ class bt {
1667
1667
  constructor(t) {
1668
1668
  this.manifest = {}, this.navPath = "", this.ncxPath = "", this.coverPath = "", this.spineNodeIndex = 0, this.spine = [], this.metadata = {}, t && this.parse(t);
1669
1669
  }
@@ -1684,7 +1684,7 @@ class xt {
1684
1684
  const s = w(t, "spine");
1685
1685
  if (!s)
1686
1686
  throw new Error("No Spine Found");
1687
- return this.manifest = this.parseManifest(i), this.navPath = this.findNavPath(i), this.ncxPath = this.findNcxPath(i, s), this.coverPath = this.findCoverPath(t), this.spineNodeIndex = Kt(s), this.spine = this.parseSpine(s, this.manifest), this.uniqueIdentifier = this.findUniqueIdentifier(t), this.metadata = this.parseMetadata(e), this.metadata.direction = s.getAttribute("page-progression-direction") ?? "", {
1687
+ return this.manifest = this.parseManifest(i), this.navPath = this.findNavPath(i), this.ncxPath = this.findNcxPath(i, s), this.coverPath = this.findCoverPath(t), this.spineNodeIndex = Zt(s), this.spine = this.parseSpine(s, this.manifest), this.uniqueIdentifier = this.findUniqueIdentifier(t), this.metadata = this.parseMetadata(e), this.metadata.direction = s.getAttribute("page-progression-direction") ?? "", {
1688
1688
  metadata: this.metadata,
1689
1689
  spine: this.spine,
1690
1690
  manifest: this.manifest,
@@ -2186,7 +2186,7 @@ const et = {
2186
2186
  "x-ms-vob": "vob",
2187
2187
  "x-smv": "smv"
2188
2188
  }
2189
- }, pe = (function() {
2189
+ }, ge = (function() {
2190
2190
  let a, t, e, i;
2191
2191
  const s = {};
2192
2192
  for (a in et)
@@ -2201,12 +2201,12 @@ const et = {
2201
2201
  s[e[i]] = a + "/" + t;
2202
2202
  }
2203
2203
  return s;
2204
- })(), ge = "text/plain";
2205
- function me(a) {
2206
- return a && pe[a.split(".").pop().toLowerCase()] || ge;
2204
+ })(), me = "text/plain";
2205
+ function ve(a) {
2206
+ return a && ge[a.split(".").pop().toLowerCase()] || me;
2207
2207
  }
2208
- const H = { lookup: me };
2209
- class ve {
2208
+ const V = { lookup: ve };
2209
+ class ye {
2210
2210
  constructor(t, e) {
2211
2211
  this.settings = {
2212
2212
  replacements: e && e.replacements || "base64",
@@ -2252,8 +2252,8 @@ class ve {
2252
2252
  * @return {Promise<string>} Promise resolves with url string
2253
2253
  */
2254
2254
  createUrl(t) {
2255
- const e = new N(t), i = H.lookup(e.filename);
2256
- return this.settings.archive ? this.settings.archive.createUrl(t, { base64: this.settings.replacements === "base64" }) : this.settings.replacements === "base64" ? this.settings.request(t, "blob").then((s) => te(s)).then((s) => vt(s, i)) : this.settings.request(t, "blob").then((s) => at(s, i));
2255
+ const e = new L(t), i = V.lookup(e.filename);
2256
+ return this.settings.archive ? this.settings.archive.createUrl(t, { base64: this.settings.replacements === "base64" }) : this.settings.replacements === "base64" ? this.settings.request(t, "blob").then((s) => ee(s)).then((s) => vt(s, i)) : this.settings.request(t, "blob").then((s) => at(s, i));
2257
2257
  }
2258
2258
  /**
2259
2259
  * Create blob urls for all the assets
@@ -2297,7 +2297,7 @@ class ve {
2297
2297
  */
2298
2298
  createCssFile(t) {
2299
2299
  let e;
2300
- if (z.isAbsolute(t))
2300
+ if (D.isAbsolute(t))
2301
2301
  return new Promise(function(r) {
2302
2302
  r();
2303
2303
  });
@@ -2309,7 +2309,7 @@ class ve {
2309
2309
  return new P(i).relative(o);
2310
2310
  });
2311
2311
  return s ? s.then((r) => {
2312
- const o = bt(r, n, this.replacementUrls);
2312
+ const o = xt(r, n, this.replacementUrls);
2313
2313
  return this.settings.replacements === "base64" ? e = vt(o, "text/css") : e = at(o, "text/css"), e;
2314
2314
  }, (r) => new Promise(function(o) {
2315
2315
  o();
@@ -2350,17 +2350,17 @@ class ve {
2350
2350
  */
2351
2351
  substitute(t, e) {
2352
2352
  let i;
2353
- return e ? i = this.relativeTo(e) : i = this.urls, bt(t, i, this.replacementUrls);
2353
+ return e ? i = this.relativeTo(e) : i = this.urls, xt(t, i, this.replacementUrls);
2354
2354
  }
2355
2355
  destroy() {
2356
2356
  this.replacementUrls && this.replacementUrls.forEach((t) => {
2357
- t && Rt(t);
2357
+ t && At(t);
2358
2358
  }), this.settings = void 0, this.manifest = void 0, this.resources = void 0, this.replacementUrls = void 0, this.html = void 0, this.assets = void 0, this.css = void 0, this.urls = void 0, this.cssUrls = void 0;
2359
2359
  }
2360
2360
  }
2361
2361
  class it {
2362
2362
  constructor(t) {
2363
- this.pages = [], this.locations = [], this.epubcfi = new m(), this.firstPage = 0, this.lastPage = 0, this.totalPages = 0, this.toc = void 0, this.ncx = void 0, t && (this.pageList = this.parse(t)), this.pageList && this.pageList.length && this.process(this.pageList);
2363
+ this.pages = [], this.locations = [], this.epubcfi = new y(), this.firstPage = 0, this.lastPage = 0, this.totalPages = 0, this.toc = void 0, this.ncx = void 0, t && (this.pageList = this.parse(t)), this.pageList && this.pageList.length && this.process(this.pageList);
2364
2364
  }
2365
2365
  /**
2366
2366
  * Parse PageList Xml
@@ -2490,7 +2490,7 @@ class it {
2490
2490
  this.pages = void 0, this.locations = void 0, this.epubcfi = void 0, this.pageList = void 0, this.toc = void 0, this.ncx = void 0;
2491
2491
  }
2492
2492
  }
2493
- class Ot {
2493
+ class Dt {
2494
2494
  constructor(t) {
2495
2495
  this.settings = t, this.name = t.layout || "reflowable", this._spread = t.spread !== "none", this._minSpreadWidth = t.minSpreadWidth || 800, this._evenSpreads = t.evenSpreads || !1, t.flow === "scrolled" || t.flow === "scrolled-continuous" || t.flow === "scrolled-doc" ? this._flow = "scrolled" : this._flow = "paginated", this.width = 0, this.height = 0, this.spreadWidth = 0, this.delta = 0, this.columnWidth = 0, this.gap = 0, this.divisor = 1, this.props = {
2496
2496
  name: this.name,
@@ -2534,13 +2534,13 @@ class Ot {
2534
2534
  const o = e, h = Math.floor(r / 12);
2535
2535
  let l, c;
2536
2536
  this._spread && r >= this._minSpreadWidth ? s = 2 : s = 1, this.name === "reflowable" && this._flow === "paginated" && !(i !== void 0 && i >= 0) && (n = h % 2 === 0 ? h : h - 1), this.name === "pre-paginated" && (n = 0), s > 1 ? (l = r / s - n, c = l + n) : (l = r, c = r), this.name === "pre-paginated" && s > 1 && (r = l);
2537
- const d = l * s + n, f = r;
2538
- this.width = r, this.height = o, this.spreadWidth = d, this.pageWidth = c, this.delta = f, this.columnWidth = l, this.gap = n, this.divisor = s, this.update({
2537
+ const d = l * s + n, u = r;
2538
+ this.width = r, this.height = o, this.spreadWidth = d, this.pageWidth = c, this.delta = u, this.columnWidth = l, this.gap = n, this.divisor = s, this.update({
2539
2539
  width: r,
2540
2540
  height: o,
2541
2541
  spreadWidth: d,
2542
2542
  pageWidth: c,
2543
- delta: f,
2543
+ delta: u,
2544
2544
  columnWidth: l,
2545
2545
  gap: n,
2546
2546
  divisor: s
@@ -2578,13 +2578,13 @@ class Ot {
2578
2578
  if (Object.keys(e).forEach((s) => {
2579
2579
  i[s] === e[s] && delete e[s];
2580
2580
  }), Object.keys(e).length > 0) {
2581
- const s = _(this.props, t);
2582
- this.emit(u.LAYOUT.UPDATED, s, t);
2581
+ const s = C(this.props, t);
2582
+ this.emit(f.LAYOUT.UPDATED, s, t);
2583
2583
  }
2584
2584
  }
2585
2585
  }
2586
- A(Ot.prototype);
2587
- class ye {
2586
+ A(Dt.prototype);
2587
+ class we {
2588
2588
  constructor(t) {
2589
2589
  this.rendition = t, this._themes = {
2590
2590
  default: {
@@ -2651,7 +2651,7 @@ class ye {
2651
2651
  * @param {string} input
2652
2652
  */
2653
2653
  registerUrl(t, e) {
2654
- const i = new N(e);
2654
+ const i = new L(e);
2655
2655
  this._themes[t] = { url: i.toString() }, (this._injected[t] || t === "default") && this.update(t);
2656
2656
  }
2657
2657
  /**
@@ -2749,7 +2749,7 @@ class ye {
2749
2749
  this.rendition = void 0, this._themes = void 0, this._overrides = void 0, this._current = void 0, this._injected = void 0;
2750
2750
  }
2751
2751
  }
2752
- class we {
2752
+ class xe {
2753
2753
  constructor(t) {
2754
2754
  this.rendition = t, this.highlights = [], this.underlines = [], this.marks = [], this._annotations = {}, this._annotationsBySectionIndex = {}, this.rendition.hooks.render.register((e) => this.inject(e)), this.rendition.hooks.unloaded.register((e) => this.clear(e));
2755
2755
  }
@@ -2764,7 +2764,7 @@ class we {
2764
2764
  * @returns {Annotation} annotation
2765
2765
  */
2766
2766
  add(t, e, i, s, n, r) {
2767
- const o = encodeURI(e + t), l = new m(e).spinePos, c = new zt({
2767
+ const o = encodeURI(e + t), l = new y(e).spinePos, c = new zt({
2768
2768
  type: t,
2769
2769
  cfiRange: e,
2770
2770
  data: i,
@@ -2773,8 +2773,8 @@ class we {
2773
2773
  className: n,
2774
2774
  styles: r
2775
2775
  });
2776
- return this._annotations[o] = c, l in this._annotationsBySectionIndex ? this._annotationsBySectionIndex[l].push(o) : this._annotationsBySectionIndex[l] = [o], this.rendition.views().forEach((f) => {
2777
- c.sectionIndex === f.index && c.attach(f);
2776
+ return this._annotations[o] = c, l in this._annotationsBySectionIndex ? this._annotationsBySectionIndex[l].push(o) : this._annotationsBySectionIndex[l] = [o], this.rendition.views().forEach((u) => {
2777
+ c.sectionIndex === u.index && c.attach(u);
2778
2778
  }), c;
2779
2779
  }
2780
2780
  /**
@@ -2872,13 +2872,11 @@ class we {
2872
2872
  }
2873
2873
  /**
2874
2874
  * [Not Implemented] Show annotations
2875
- * @TODO: needs implementation in View
2876
2875
  */
2877
2876
  show() {
2878
2877
  }
2879
2878
  /**
2880
2879
  * [Not Implemented] Hide annotations
2881
- * @TODO: needs implementation in View
2882
2880
  */
2883
2881
  hide() {
2884
2882
  }
@@ -2909,7 +2907,7 @@ class zt {
2909
2907
  attach(t) {
2910
2908
  const { cfiRange: e, data: i, type: s, mark: n, cb: r, className: o, styles: h } = this;
2911
2909
  let l;
2912
- return s === "highlight" ? l = t.highlight(e, i, r, o, h) : s === "underline" ? l = t.underline(e, i, r, o, h) : s === "mark" && (l = t.mark(e, i, r)), this.mark = l, this.emit(u.ANNOTATION.ATTACH, l), l;
2910
+ return s === "highlight" ? l = t.highlight(e, i, r, o, h) : s === "underline" ? l = t.underline(e, i, r, o, h) : s === "mark" && (l = t.mark(e, i, r)), this.mark = l, this.emit(f.ANNOTATION.ATTACH, l), l;
2913
2911
  }
2914
2912
  /**
2915
2913
  * Remove from a view
@@ -2917,19 +2915,18 @@ class zt {
2917
2915
  */
2918
2916
  detach(t) {
2919
2917
  const { cfiRange: e, type: i } = this;
2920
- t && (i === "highlight" ? t.unhighlight(e) : i === "underline" ? t.ununderline(e) : i === "mark" && t.unmark(e)), this.mark = void 0, this.emit(u.ANNOTATION.DETACH);
2918
+ t && (i === "highlight" ? t.unhighlight(e) : i === "underline" ? t.ununderline(e) : i === "mark" && t.unmark(e)), this.mark = void 0, this.emit(f.ANNOTATION.DETACH);
2921
2919
  }
2922
2920
  /**
2923
2921
  * [Not Implemented] Get text of an annotation
2924
- * @TODO: needs implementation in contents
2925
2922
  */
2926
2923
  text() {
2927
2924
  }
2928
2925
  }
2929
2926
  A(zt.prototype);
2930
2927
  class ut {
2931
- constructor(t, e, i, s = !1) {
2932
- this.layout = t, this.horizontal = i === "horizontal", this.direction = e || "ltr", this._dev = s;
2928
+ constructor(t, e, i, s = !1, n) {
2929
+ this.layout = t, this.horizontal = i === "horizontal", this.direction = e || "ltr", this._dev = s, this._measurer = n || null;
2933
2930
  }
2934
2931
  /**
2935
2932
  * Find CFI pairs for entire section at once
@@ -2954,7 +2951,7 @@ class ut {
2954
2951
  end: this.findEnd(n, i, s)
2955
2952
  });
2956
2953
  if (this._dev === !0) {
2957
- const o = t.document, h = new m(r.start).toRange(o), l = new m(r.end).toRange(o), c = o.defaultView.getSelection(), d = o.createRange();
2954
+ const o = t.document, h = new y(r.start).toRange(o), l = new y(r.end).toRange(o), c = o.defaultView.getSelection(), d = o.createRange();
2958
2955
  c.removeAllRanges(), d.setStart(h.startContainer, h.startOffset), d.setEnd(l.endContainer, l.endOffset), c.addRange(d);
2959
2956
  }
2960
2957
  return r;
@@ -2997,33 +2994,33 @@ class ut {
2997
2994
  */
2998
2995
  findStart(t, e, i) {
2999
2996
  const s = [t];
3000
- let n, r, o = t;
2997
+ let n, r, o = t, h;
3001
2998
  for (; s.length; )
3002
- if (n = s.shift(), r = this.walk(n, (h) => {
3003
- let l, c, d, f;
3004
- const p = gt(h);
3005
- if (this.horizontal && this.direction === "ltr") {
3006
- if (l = this.horizontal ? p.left : p.top, c = this.horizontal ? p.right : p.bottom, l >= e && l <= i)
3007
- return h;
3008
- if (c > e)
3009
- return h;
3010
- o = h, s.push(h);
2999
+ if (n = s.shift(), r = this.walk(n, (l) => {
3000
+ let c, d, u, p;
3001
+ const g = gt(l);
3002
+ if (h = g, this.horizontal && this.direction === "ltr") {
3003
+ if (c = g.left, d = g.right, c >= e && c <= i)
3004
+ return l;
3005
+ if (d > e)
3006
+ return l;
3007
+ o = l, s.push(l);
3011
3008
  } else if (this.horizontal && this.direction === "rtl") {
3012
- if (l = p.left, c = p.right, c <= i && c >= e)
3013
- return h;
3014
- if (l < i)
3015
- return h;
3016
- o = h, s.push(h);
3009
+ if (c = g.left, d = g.right, d <= i && d >= e)
3010
+ return l;
3011
+ if (c < i)
3012
+ return l;
3013
+ o = l, s.push(l);
3017
3014
  } else {
3018
- if (d = p.top, f = p.bottom, d >= e && d <= i)
3019
- return h;
3020
- if (f > e)
3021
- return h;
3022
- o = h, s.push(h);
3015
+ if (u = g.top, p = g.bottom, u >= e && u <= i)
3016
+ return l;
3017
+ if (p > e)
3018
+ return l;
3019
+ o = l, s.push(l);
3023
3020
  }
3024
3021
  }), r)
3025
- return this.findTextStartRange(r, e, i);
3026
- return this.findTextStartRange(o, e, i);
3022
+ return this.findTextStartRange(r, e, i, h);
3023
+ return this.findTextStartRange(o, e, i, h);
3027
3024
  }
3028
3025
  /**
3029
3026
  * Find End Range
@@ -3035,87 +3032,142 @@ class ut {
3035
3032
  */
3036
3033
  findEnd(t, e, i) {
3037
3034
  const s = [t];
3038
- let n, r = t, o;
3035
+ let n, r = t, o, h, l;
3039
3036
  for (; s.length; )
3040
- if (n = s.shift(), o = this.walk(n, (h) => {
3041
- let l, c, d, f;
3042
- const p = gt(h);
3043
- if (this.horizontal && this.direction === "ltr") {
3044
- if (l = Math.round(p.left), c = Math.round(p.right), l > i && r)
3037
+ if (n = s.shift(), o = this.walk(n, (c) => {
3038
+ let d, u, p, g;
3039
+ const m = gt(c);
3040
+ if (h = m, this.horizontal && this.direction === "ltr") {
3041
+ if (d = Math.round(m.left), u = Math.round(m.right), d > i && r)
3045
3042
  return r;
3046
- if (c > i)
3047
- return h;
3048
- r = h, s.push(h);
3043
+ if (u > i)
3044
+ return c;
3045
+ r = c, l = m, s.push(c);
3049
3046
  } else if (this.horizontal && this.direction === "rtl") {
3050
- if (l = Math.round(this.horizontal ? p.left : p.top), c = Math.round(this.horizontal ? p.right : p.bottom), c < e && r)
3047
+ if (d = Math.round(m.left), u = Math.round(m.right), u < e && r)
3051
3048
  return r;
3052
- if (l < e)
3053
- return h;
3054
- r = h, s.push(h);
3049
+ if (d < e)
3050
+ return c;
3051
+ r = c, l = m, s.push(c);
3055
3052
  } else {
3056
- if (d = Math.round(p.top), f = Math.round(p.bottom), d > i && r)
3053
+ if (p = Math.round(m.top), g = Math.round(m.bottom), p > i && r)
3057
3054
  return r;
3058
- if (f > i)
3059
- return h;
3060
- r = h, s.push(h);
3055
+ if (g > i)
3056
+ return c;
3057
+ r = c, l = m, s.push(c);
3061
3058
  }
3062
- }), o)
3063
- return this.findTextEndRange(o, e, i);
3064
- return this.findTextEndRange(r, e, i);
3059
+ }), o) {
3060
+ const c = o === r ? l : h;
3061
+ return this.findTextEndRange(o, e, i, c);
3062
+ }
3063
+ return this.findTextEndRange(r, e, i, l);
3064
+ }
3065
+ /**
3066
+ * Try to prepare a text node's root for canvas-based measurement.
3067
+ * Returns the PreparedNode for this text node, or null if not available.
3068
+ * @private
3069
+ */
3070
+ _canvasPrepare(t) {
3071
+ if (!this._measurer || t.nodeType !== Node.TEXT_NODE) return null;
3072
+ const e = t, i = e.parentElement;
3073
+ if (!i) return null;
3074
+ const s = i.ownerDocument?.defaultView;
3075
+ if (!s) return null;
3076
+ const n = this._measurer.getPreparedNode(e);
3077
+ if (n) {
3078
+ const o = s.getComputedStyle(i).font;
3079
+ if (!o || o === n.font) return n;
3080
+ const h = i.ownerDocument.body;
3081
+ h && this._measurer.invalidate(h);
3082
+ }
3083
+ if (this._measurer.hasExoticCSS(e, s)) return null;
3084
+ const r = i.ownerDocument.body;
3085
+ return r ? (this._measurer.prepare(r, s), this._measurer.getPreparedNode(e)) : null;
3086
+ }
3087
+ /**
3088
+ * Canvas fast path: use binary search on pre-measured cumulative widths
3089
+ * to find a Range at the target position, then verify with one getBoundingClientRect.
3090
+ * Returns the Range if verification passes, or null to fall through to DOM loop.
3091
+ * @private
3092
+ */
3093
+ _canvasFindRange(t, e, i, s) {
3094
+ const n = this._canvasPrepare(t);
3095
+ if (!n || n.segments.length === 0) return null;
3096
+ const r = t, o = this.horizontal ? this.direction === "rtl" ? e.right : e.left : e.top, h = this.horizontal && this.direction === "rtl" ? o - i : i - o;
3097
+ if (h < 0) return null;
3098
+ const l = this._measurer.findSegmentIndex(n.segments, h), c = n.segments, d = r.ownerDocument, u = r.data.length;
3099
+ for (let p = l; p < c.length && p <= l + 1; p++) {
3100
+ const g = c[p], m = c[p + 1], v = d.createRange();
3101
+ if (v.setStart(r, Math.min(g.charOffset, u)), v.setEnd(r, Math.min(m ? m.charOffset : u, u)), s(v.getBoundingClientRect())) return v;
3102
+ }
3103
+ return null;
3065
3104
  }
3066
3105
  /**
3067
3106
  * Find Text Start Range
3068
3107
  * @private
3069
- * @param {Node} root root node
3108
+ * @param {Node} node text node
3070
3109
  * @param {number} start position to start at
3071
3110
  * @param {number} end position to end at
3111
+ * @param {DOMRect} [nodePos] pre-computed node bounds from findStart (avoids redundant reflow)
3072
3112
  * @return {Range}
3073
3113
  */
3074
- findTextStartRange(t, e, i) {
3075
- const s = this.splitTextNodeIntoRanges(t);
3076
- let n, r, o, h, l;
3077
- for (let c = 0; c < s.length; c++)
3078
- if (n = s[c], r = n.getBoundingClientRect(), this.horizontal && this.direction === "ltr") {
3079
- if (o = r.left, o >= e)
3080
- return n;
3114
+ findTextStartRange(t, e, i, s) {
3115
+ if (s) {
3116
+ const d = this.horizontal && this.direction === "rtl" ? i : e, u = this._canvasFindRange(t, s, d, (p) => {
3117
+ const g = this.horizontal ? this.direction === "rtl" ? p.right : p.left : p.top;
3118
+ return this.horizontal && this.direction === "ltr" ? g >= e : this.horizontal && this.direction === "rtl" ? g <= i : g >= e;
3119
+ });
3120
+ if (u) return u;
3121
+ }
3122
+ const n = this.splitTextNodeIntoRanges(t);
3123
+ let r, o, h, l, c;
3124
+ for (let d = 0; d < n.length; d++)
3125
+ if (r = n[d], o = r.getBoundingClientRect(), this.horizontal && this.direction === "ltr") {
3126
+ if (h = o.left, h >= e)
3127
+ return r;
3081
3128
  } else if (this.horizontal && this.direction === "rtl") {
3082
- if (l = r.right, l <= i)
3083
- return n;
3084
- } else if (h = r.top, h >= e)
3085
- return n;
3086
- return s[0];
3129
+ if (c = o.right, c <= i)
3130
+ return r;
3131
+ } else if (l = o.top, l >= e)
3132
+ return r;
3133
+ return n[0];
3087
3134
  }
3088
3135
  /**
3089
3136
  * Find Text End Range
3090
3137
  * @private
3091
- * @param {Node} root root node
3138
+ * @param {Node} node text node
3092
3139
  * @param {number} start position to start at
3093
3140
  * @param {number} end position to end at
3141
+ * @param {DOMRect} [nodePos] pre-computed node bounds from findEnd (avoids redundant reflow)
3094
3142
  * @return {Range}
3095
3143
  */
3096
- findTextEndRange(t, e, i) {
3097
- const s = this.splitTextNodeIntoRanges(t);
3098
- let n, r, o, h, l, c, d;
3099
- for (let f = 0; f < s.length; f++) {
3100
- if (r = s[f], o = r.getBoundingClientRect(), this.horizontal && this.direction === "ltr") {
3101
- if (h = o.left, l = o.right, h > i && n)
3102
- return n;
3103
- if (l > i)
3144
+ findTextEndRange(t, e, i, s) {
3145
+ if (s) {
3146
+ const p = this.horizontal && this.direction === "rtl" ? e : i, g = this._canvasFindRange(t, s, p, (m) => this.horizontal && this.direction === "ltr" ? m.left <= i && m.right >= i : this.horizontal && this.direction === "rtl" ? m.right >= e && m.left <= e : m.top <= i && m.bottom >= i);
3147
+ if (g) return g;
3148
+ }
3149
+ const n = this.splitTextNodeIntoRanges(t);
3150
+ let r, o, h, l, c, d, u;
3151
+ for (let p = 0; p < n.length; p++) {
3152
+ if (o = n[p], h = o.getBoundingClientRect(), this.horizontal && this.direction === "ltr") {
3153
+ if (l = h.left, c = h.right, l > i && r)
3104
3154
  return r;
3155
+ if (c > i)
3156
+ return o;
3105
3157
  } else if (this.horizontal && this.direction === "rtl") {
3106
- if (h = o.left, l = o.right, l < e && n)
3107
- return n;
3108
- if (h < e)
3158
+ if (l = h.left, c = h.right, c < e && r)
3109
3159
  return r;
3160
+ if (l < e)
3161
+ return o;
3110
3162
  } else {
3111
- if (c = o.top, d = o.bottom, c > i && n)
3112
- return n;
3113
- if (d > i)
3163
+ if (d = h.top, u = h.bottom, d > i && r)
3114
3164
  return r;
3165
+ if (u > i)
3166
+ return o;
3115
3167
  }
3116
- n = r;
3168
+ r = o;
3117
3169
  }
3118
- return s[s.length - 1];
3170
+ return n[n.length - 1];
3119
3171
  }
3120
3172
  /**
3121
3173
  * Split up a text node into ranges for each word
@@ -3145,7 +3197,7 @@ class ut {
3145
3197
  rangePairToCfiPair(t, e) {
3146
3198
  const i = e.start, s = e.end;
3147
3199
  i.collapse(!0), s.collapse(!1);
3148
- const n = new m(i, t).toString(), r = new m(s, t).toString();
3200
+ const n = new y(i, t).toString(), r = new y(s, t).toString();
3149
3201
  return {
3150
3202
  start: n,
3151
3203
  end: r
@@ -3167,13 +3219,13 @@ class ut {
3167
3219
  return t && (this.horizontal = t === "horizontal"), this.horizontal;
3168
3220
  }
3169
3221
  }
3170
- const be = typeof navigator < "u", Et = be && !/Chrome/.test(navigator.userAgent) && /AppleWebKit/.test(navigator.userAgent), xe = 1;
3171
- class Dt {
3222
+ const be = typeof navigator < "u", Et = be && !/Chrome/.test(navigator.userAgent) && /AppleWebKit/.test(navigator.userAgent), Ee = 1;
3223
+ class Bt {
3172
3224
  constructor(t, e, i, s) {
3173
- this.epubcfi = new m(), this.document = t, this.documentElement = this.document.documentElement, this.content = e || this.document.body, this.window = this.document.defaultView, this._size = {
3225
+ this.epubcfi = new y(), this.document = t, this.documentElement = this.document.documentElement, this.content = e || this.document.body, this.window = this.document.defaultView, this._size = {
3174
3226
  width: 0,
3175
3227
  height: 0
3176
- }, this.sectionIndex = s || 0, this.cfiBase = i || "", this._mediaQueryHandlers = [], this.epubReadingSystem("epub.js", It), this.called = 0, this.active = !0, this.listeners();
3228
+ }, this.sectionIndex = s || 0, this.cfiBase = i || "", this._mediaQueryHandlers = [], this.epubReadingSystem("epub.js", Pt), this.called = 0, this.active = !0, this.listeners();
3177
3229
  }
3178
3230
  /**
3179
3231
  * Get DOM events that are listened for and passed along
@@ -3314,17 +3366,17 @@ class Dt {
3314
3366
  }, s = [];
3315
3367
  let n = {};
3316
3368
  if (e && e.hasAttribute("content")) {
3317
- const r = e.getAttribute("content") ?? "", o = r.match(/width\s*=\s*([^,]*)/), h = r.match(/height\s*=\s*([^,]*)/), l = r.match(/initial-scale\s*=\s*([^,]*)/), c = r.match(/minimum-scale\s*=\s*([^,]*)/), d = r.match(/maximum-scale\s*=\s*([^,]*)/), f = r.match(/user-scalable\s*=\s*([^,]*)/);
3318
- o && o.length && typeof o[1] < "u" && (i.width = o[1]), h && h.length && typeof h[1] < "u" && (i.height = h[1]), l && l.length && typeof l[1] < "u" && (i.scale = l[1]), c && c.length && typeof c[1] < "u" && (i.minimum = c[1]), d && d.length && typeof d[1] < "u" && (i.maximum = d[1]), f && f.length && typeof f[1] < "u" && (i.scalable = f[1]);
3369
+ const r = e.getAttribute("content") ?? "", o = r.match(/width\s*=\s*([^,]*)/), h = r.match(/height\s*=\s*([^,]*)/), l = r.match(/initial-scale\s*=\s*([^,]*)/), c = r.match(/minimum-scale\s*=\s*([^,]*)/), d = r.match(/maximum-scale\s*=\s*([^,]*)/), u = r.match(/user-scalable\s*=\s*([^,]*)/);
3370
+ o && o.length && typeof o[1] < "u" && (i.width = o[1]), h && h.length && typeof h[1] < "u" && (i.height = h[1]), l && l.length && typeof l[1] < "u" && (i.scale = l[1]), c && c.length && typeof c[1] < "u" && (i.minimum = c[1]), d && d.length && typeof d[1] < "u" && (i.maximum = d[1]), u && u.length && typeof u[1] < "u" && (i.scalable = u[1]);
3319
3371
  }
3320
- return n = Gt(t ?? {}, i), t && (n.width && s.push("width=" + n.width), n.height && s.push("height=" + n.height), n.scale && s.push("initial-scale=" + n.scale), n.scalable === "no" ? (s.push("minimum-scale=" + n.scale), s.push("maximum-scale=" + n.scale), s.push("user-scalable=" + n.scalable)) : (n.scalable && s.push("user-scalable=" + n.scalable), n.minimum && s.push("minimum-scale=" + n.minimum), n.maximum && s.push("minimum-scale=" + n.maximum)), e || (e = this.document.createElement("meta"), e.setAttribute("name", "viewport"), this.document.querySelector("head").appendChild(e)), e.setAttribute("content", s.join(", ")), this.window.scrollTo(0, 0)), n;
3372
+ return n = $t(t ?? {}, i), t && (n.width && s.push("width=" + n.width), n.height && s.push("height=" + n.height), n.scale && s.push("initial-scale=" + n.scale), n.scalable === "no" ? (s.push("minimum-scale=" + n.scale), s.push("maximum-scale=" + n.scale), s.push("user-scalable=" + n.scalable)) : (n.scalable && s.push("user-scalable=" + n.scalable), n.minimum && s.push("minimum-scale=" + n.minimum), n.maximum && s.push("minimum-scale=" + n.maximum)), e || (e = this.document.createElement("meta"), e.setAttribute("name", "viewport"), this.document.querySelector("head").appendChild(e)), e.setAttribute("content", s.join(", ")), this.window.scrollTo(0, 0)), n;
3321
3373
  }
3322
3374
  /**
3323
3375
  * Event emitter for when the contents has expanded
3324
3376
  * @private
3325
3377
  */
3326
3378
  expand() {
3327
- this.emit(u.CONTENTS.EXPAND);
3379
+ this.emit(f.CONTENTS.EXPAND);
3328
3380
  }
3329
3381
  /**
3330
3382
  * Add DOM listeners
@@ -3356,7 +3408,7 @@ class Dt {
3356
3408
  (t !== this._size.width || e !== this._size.height) && (this._size = {
3357
3409
  width: t,
3358
3410
  height: e
3359
- }, this.onResize && this.onResize(this._size), this.emit(u.CONTENTS.RESIZE, this._size));
3411
+ }, this.onResize && this.onResize(this._size), this.emit(f.CONTENTS.RESIZE, this._size));
3360
3412
  }
3361
3413
  /**
3362
3414
  * Use css transitions to detect resize
@@ -3447,7 +3499,7 @@ class Dt {
3447
3499
  const s = { left: 0, top: 0 };
3448
3500
  if (!this.document) return s;
3449
3501
  if (this.epubcfi.isCfiString(t)) {
3450
- const n = new m(t).toRange(this.document, e);
3502
+ const n = new y(t).toRange(this.document, e);
3451
3503
  if (n) {
3452
3504
  try {
3453
3505
  if (!n.endContainer || n.startContainer === n.endContainer && n.startOffset === n.endOffset) {
@@ -3462,7 +3514,7 @@ class Dt {
3462
3514
  else if (Et) {
3463
3515
  const r = n.startContainer, o = new Range();
3464
3516
  try {
3465
- r.nodeType === xe ? i = r.getBoundingClientRect() : n.startOffset + 2 < r.length ? (o.setStart(r, n.startOffset), o.setEnd(r, n.startOffset + 2), i = o.getBoundingClientRect()) : n.startOffset - 2 > 0 ? (o.setStart(r, n.startOffset - 2), o.setEnd(r, n.startOffset), i = o.getBoundingClientRect()) : i = r.parentNode.getBoundingClientRect();
3517
+ r.nodeType === Ee ? i = r.getBoundingClientRect() : n.startOffset + 2 < r.length ? (o.setStart(r, n.startOffset), o.setEnd(r, n.startOffset + 2), i = o.getBoundingClientRect()) : n.startOffset - 2 > 0 ? (o.setStart(r, n.startOffset - 2), o.setEnd(r, n.startOffset), i = o.getBoundingClientRect()) : i = r.parentNode.getBoundingClientRect();
3466
3518
  } catch (h) {
3467
3519
  console.error(h, h instanceof Error ? h.stack : void 0);
3468
3520
  }
@@ -3645,7 +3697,7 @@ class Dt {
3645
3697
  */
3646
3698
  triggerSelectedEvent(t) {
3647
3699
  let e, i;
3648
- t && t.rangeCount > 0 && (e = t.getRangeAt(0), e.collapsed || (i = new m(e, this.cfiBase).toString(), this.emit(u.CONTENTS.SELECTED, i), this.emit(u.CONTENTS.SELECTED_RANGE, e)));
3700
+ t && t.rangeCount > 0 && (e = t.getRangeAt(0), e.collapsed || (i = new y(e, this.cfiBase).toString(), this.emit(f.CONTENTS.SELECTED, i), this.emit(f.CONTENTS.SELECTED_RANGE, e)));
3649
3701
  }
3650
3702
  /**
3651
3703
  * Get a Dom Range from EpubCFI
@@ -3654,7 +3706,7 @@ class Dt {
3654
3706
  * @returns {Range} range
3655
3707
  */
3656
3708
  range(t, e) {
3657
- return new m(t).toRange(this.document, e);
3709
+ return new y(t).toRange(this.document, e);
3658
3710
  }
3659
3711
  /**
3660
3712
  * Get an EpubCFI from a Dom Range
@@ -3663,7 +3715,7 @@ class Dt {
3663
3715
  * @returns {EpubCFI} cfi
3664
3716
  */
3665
3717
  cfiFromRange(t, e) {
3666
- return new m(t, this.cfiBase, e).toString();
3718
+ return new y(t, this.cfiBase, e).toString();
3667
3719
  }
3668
3720
  /**
3669
3721
  * Get an EpubCFI from a Dom node
@@ -3672,7 +3724,7 @@ class Dt {
3672
3724
  * @returns {EpubCFI} cfi
3673
3725
  */
3674
3726
  cfiFromNode(t, e) {
3675
- return new m(t, this.cfiBase, e).toString();
3727
+ return new y(t, this.cfiBase, e).toString();
3676
3728
  }
3677
3729
  /**
3678
3730
  * Size the contents to a given width and height
@@ -3698,7 +3750,7 @@ class Dt {
3698
3750
  columns(t, e, i, s, n) {
3699
3751
  const r = "-webkit-column-axis", o = "column-gap", h = "column-width", l = "column-fill", d = this.writingMode().indexOf("vertical") === 0 ? "vertical" : "horizontal";
3700
3752
  this.layoutStyle("paginated"), n === "rtl" && d === "horizontal" && this.direction(n), this.width(t), this.height(e), this.viewport({ width: t, height: e, scale: 1, scalable: "no" });
3701
- const f = [
3753
+ const u = [
3702
3754
  // Fixes Safari column cut offs, but causes RTL issues.
3703
3755
  // Required on iOS: block-level body in CSS columns triggers a
3704
3756
  // WKWebView content-size expansion feedback loop where scrollWidth
@@ -3708,25 +3760,25 @@ class Dt {
3708
3760
  ["overflow-y", "hidden"],
3709
3761
  ["margin", "0", !0]
3710
3762
  ];
3711
- d === "vertical" ? f.push(
3763
+ d === "vertical" ? u.push(
3712
3764
  ["padding-top", s / 2 + "px", !0],
3713
3765
  ["padding-bottom", s / 2 + "px", !0],
3714
3766
  ["padding-left", "20px"],
3715
3767
  ["padding-right", "20px"],
3716
3768
  [r, "vertical"]
3717
- ) : f.push(
3769
+ ) : u.push(
3718
3770
  ["padding-top", "20px"],
3719
3771
  ["padding-bottom", "20px"],
3720
3772
  ["padding-left", s / 2 + "px", !0],
3721
3773
  ["padding-right", s / 2 + "px", !0],
3722
3774
  [r, "horizontal"]
3723
- ), f.push(
3775
+ ), u.push(
3724
3776
  ["box-sizing", "border-box"],
3725
3777
  ["max-width", "inherit"],
3726
3778
  [l, "auto"],
3727
3779
  [o, s + "px"],
3728
3780
  [h, i + "px"]
3729
- ), this.cssBatch(f);
3781
+ ), this.cssBatch(u);
3730
3782
  }
3731
3783
  /**
3732
3784
  * Scale contents from center
@@ -3773,8 +3825,8 @@ class Dt {
3773
3825
  * @private
3774
3826
  */
3775
3827
  linksHandler() {
3776
- ce(this.content, (t) => {
3777
- this.emit(u.CONTENTS.LINK_CLICKED, t);
3828
+ de(this.content, (t) => {
3829
+ this.emit(f.CONTENTS.LINK_CLICKED, t);
3778
3830
  });
3779
3831
  }
3780
3832
  /**
@@ -3827,11 +3879,11 @@ class Dt {
3827
3879
  this.removeListeners(), this.__listeners = {};
3828
3880
  }
3829
3881
  }
3830
- A(Dt.prototype);
3882
+ A(Bt.prototype);
3831
3883
  function X(a) {
3832
3884
  return document.createElementNS("http://www.w3.org/2000/svg", a);
3833
3885
  }
3834
- function Ee(a, t) {
3886
+ function _e(a, t) {
3835
3887
  function e(s) {
3836
3888
  for (let n = t.length - 1; n >= 0; n--) {
3837
3889
  const r = t[n];
@@ -3882,8 +3934,8 @@ function Se(a) {
3882
3934
  function Ce(a, t, e, i) {
3883
3935
  const s = t.getBoundingClientRect();
3884
3936
  function n(h, l, c) {
3885
- const d = h.top - s.top, f = h.left - s.left, p = d + h.height, g = f + h.width;
3886
- return d <= c && f <= l && p > c && g > l;
3937
+ const d = h.top - s.top, u = h.left - s.left, p = d + h.height, g = u + h.width;
3938
+ return d <= c && u <= l && p > c && g > l;
3887
3939
  }
3888
3940
  const r = a.getBoundingClientRect();
3889
3941
  if (!n(r, e, i))
@@ -3894,7 +3946,7 @@ function Ce(a, t, e, i) {
3894
3946
  return !0;
3895
3947
  return !1;
3896
3948
  }
3897
- function _e(a, t) {
3949
+ function Te(a, t) {
3898
3950
  const e = t.getBoundingClientRect(), i = a.getBoundingClientRect();
3899
3951
  return {
3900
3952
  top: i.top - e.top,
@@ -3903,15 +3955,15 @@ function _e(a, t) {
3903
3955
  width: a.scrollWidth
3904
3956
  };
3905
3957
  }
3906
- function Te(a, t) {
3958
+ function ke(a, t) {
3907
3959
  a.style.setProperty("top", `${t.top}px`, "important"), a.style.setProperty("left", `${t.left}px`, "important"), a.style.setProperty("height", `${t.height}px`, "important"), a.style.setProperty("width", `${t.width}px`, "important");
3908
3960
  }
3909
- function ke(a, t) {
3961
+ function Ne(a, t) {
3910
3962
  return t.right <= a.right && t.left >= a.left && t.top >= a.top && t.bottom <= a.bottom;
3911
3963
  }
3912
- class St {
3964
+ class _t {
3913
3965
  constructor(t, e = document.body) {
3914
- this.target = t, this.element = X("svg"), this.marks = [], this.element.style.position = "absolute", this.element.setAttribute("pointer-events", "none"), Ee(this.target, this.marks), this.container = e, this.container.appendChild(this.element), this.render();
3966
+ this.target = t, this.element = X("svg"), this.marks = [], this.element.style.position = "absolute", this.element.setAttribute("pointer-events", "none"), _e(this.target, this.marks), this.container = e, this.container.appendChild(this.element), this.render();
3915
3967
  }
3916
3968
  addMark(t) {
3917
3969
  const e = X("g");
@@ -3925,7 +3977,7 @@ class St {
3925
3977
  this.element.removeChild(i), this.marks.splice(e, 1);
3926
3978
  }
3927
3979
  render() {
3928
- Te(this.element, _e(this.target, this.container));
3980
+ ke(this.element, Te(this.target, this.container));
3929
3981
  for (const t of this.marks)
3930
3982
  t.render();
3931
3983
  }
@@ -3962,14 +4014,14 @@ class Le {
3962
4014
  for (let i = 0; i < t.length; i++) {
3963
4015
  if (t[i] === e)
3964
4016
  return !0;
3965
- if (ke(t[i], e))
4017
+ if (Ne(t[i], e))
3966
4018
  return !1;
3967
4019
  }
3968
4020
  return !0;
3969
4021
  });
3970
4022
  }
3971
4023
  }
3972
- class Bt extends Le {
4024
+ class Mt extends Le {
3973
4025
  constructor(t, e, i, s) {
3974
4026
  super(), this.range = t, this.className = e, this.data = i || {}, this.attributes = s || {};
3975
4027
  }
@@ -3992,7 +4044,7 @@ class Bt extends Le {
3992
4044
  this.element.appendChild(t);
3993
4045
  }
3994
4046
  }
3995
- class Ne extends Bt {
4047
+ class Re extends Mt {
3996
4048
  constructor(t, e, i, s) {
3997
4049
  super(t, e, i, s);
3998
4050
  }
@@ -4002,16 +4054,16 @@ class Ne extends Bt {
4002
4054
  const t = this.element.ownerDocument.createDocumentFragment(), e = this.filteredRanges(), i = this.element.getBoundingClientRect(), s = this.container.getBoundingClientRect();
4003
4055
  for (let n = 0, r = e.length; n < r; n++) {
4004
4056
  const o = e[n], h = X("rect");
4005
- h.setAttribute("x", String(o.left - i.left + s.left)), h.setAttribute("y", String(o.top - i.top + s.top)), h.setAttribute("height", String(o.height)), h.setAttribute("width", String(o.width)), h.setAttribute("fill", "none");
4057
+ h.setAttribute("x", String(o.left - i.left + s.left)), h.setAttribute("y", String(o.top - i.top + s.top)), h.setAttribute("height", String(o.height)), h.setAttribute("width", String(o.width)), h.setAttribute("fill", this.attributes.fill || "none");
4006
4058
  const l = X("line");
4007
- l.setAttribute("x1", String(o.left - i.left + s.left)), l.setAttribute("x2", String(o.left - i.left + s.left + o.width)), l.setAttribute("y1", String(o.top - i.top + s.top + o.height - 1)), l.setAttribute("y2", String(o.top - i.top + s.top + o.height - 1)), l.setAttribute("stroke-width", "1"), l.setAttribute("stroke", "black"), l.setAttribute("stroke-linecap", "square"), t.appendChild(h), t.appendChild(l);
4059
+ l.setAttribute("x1", String(o.left - i.left + s.left)), l.setAttribute("x2", String(o.left - i.left + s.left + o.width)), l.setAttribute("y1", String(o.top - i.top + s.top + o.height - 1)), l.setAttribute("y2", String(o.top - i.top + s.top + o.height - 1)), l.setAttribute("stroke-width", this.attributes["stroke-width"] || "1"), l.setAttribute("stroke", this.attributes.stroke || "black"), l.setAttribute("stroke-linecap", this.attributes["stroke-linecap"] || "square"), t.appendChild(h), t.appendChild(l);
4008
4060
  }
4009
4061
  this.element.appendChild(t);
4010
4062
  }
4011
4063
  }
4012
- class Mt {
4064
+ class Wt {
4013
4065
  constructor(t, e) {
4014
- this.settings = _({
4066
+ this._contentDirty = !0, this._needsReframe = !1, this._expanding = !1, this.settings = C({
4015
4067
  ignoreClass: "",
4016
4068
  axis: void 0,
4017
4069
  //options.layout && options.layout.props.flow === "scrolled" ? "vertical" : "horizontal",
@@ -4024,7 +4076,7 @@ class Mt {
4024
4076
  forceRight: !1,
4025
4077
  allowScriptedContent: !1,
4026
4078
  allowPopups: !1
4027
- }, e || {}), this.id = "epubjs-view-" + kt(), this.section = t, this.index = t.index, this.element = this.container(this.settings.axis), this.added = !1, this.displayed = !1, this.rendered = !1, this.fixedWidth = 0, this.fixedHeight = 0, this.epubcfi = new m(), this.layout = this.settings.layout, this.pane = void 0, this.highlights = {}, this.underlines = {}, this.marks = {};
4079
+ }, e || {}), this.id = "epubjs-view-" + Nt(), this.section = t, this.index = t.index, this.element = this.container(this.settings.axis), this.added = !1, this.displayed = !1, this.rendered = !1, this.fixedWidth = 0, this.fixedHeight = 0, this.epubcfi = new y(), this.layout = this.settings.layout, this.pane = void 0, this.highlights = {}, this.underlines = {}, this.marks = {};
4028
4080
  }
4029
4081
  container(t) {
4030
4082
  const e = document.createElement("div");
@@ -4037,17 +4089,17 @@ class Mt {
4037
4089
  return this.create(), this.size(), this.sectionRender || (this.sectionRender = this.section.render(t)), this.sectionRender.then((i) => this.load(i)).then(() => {
4038
4090
  const i = this.contents.writingMode();
4039
4091
  let s;
4040
- return this.settings.flow === "scrolled" ? s = i.indexOf("vertical") === 0 ? "horizontal" : "vertical" : s = i.indexOf("vertical") === 0 ? "vertical" : "horizontal", i.indexOf("vertical") === 0 && this.settings.flow === "paginated" && (this.layout.delta = this.layout.height), this.setAxis(s), this.emit(u.VIEWS.AXIS, s), this.setWritingMode(i), this.emit(u.VIEWS.WRITING_MODE, i), this.layout.format(this.contents, this.section, this.axis), this.addListeners(), new Promise((n, r) => {
4092
+ return this.settings.flow === "scrolled" ? s = i.indexOf("vertical") === 0 ? "horizontal" : "vertical" : s = i.indexOf("vertical") === 0 ? "vertical" : "horizontal", i.indexOf("vertical") === 0 && this.settings.flow === "paginated" && (this.layout.delta = this.layout.height), this.setAxis(s), this.emit(f.VIEWS.AXIS, s), this.setWritingMode(i), this.emit(f.VIEWS.WRITING_MODE, i), this.layout.format(this.contents, this.section, this.axis), this.addListeners(), new Promise((n, r) => {
4041
4093
  this.expand(), this.settings.forceRight && (this.element.style.marginLeft = this.width() + "px"), n();
4042
4094
  });
4043
- }, (i) => (this.emit(u.VIEWS.LOAD_ERROR, i), new Promise((s, n) => {
4095
+ }, (i) => (this.emit(f.VIEWS.LOAD_ERROR, i), new Promise((s, n) => {
4044
4096
  n(i);
4045
4097
  }))).then(() => {
4046
- this.emit(u.VIEWS.RENDERED, this.section);
4098
+ this.emit(f.VIEWS.RENDERED, this.section);
4047
4099
  });
4048
4100
  }
4049
4101
  reset() {
4050
- this.iframe && (this.iframe.style.width = "0", this.iframe.style.height = "0", this._width = 0, this._height = 0, this._textWidth = void 0, this._contentWidth = void 0, this._textHeight = void 0, this._contentHeight = void 0), this._needsReframe = !0;
4102
+ this.iframe && (this.iframe.style.width = "0", this.iframe.style.height = "0", this._width = 0, this._height = 0, this._textWidth = void 0, this._contentWidth = void 0, this._textHeight = void 0, this._contentHeight = void 0), this._contentDirty = !0, this._needsReframe = !0;
4051
4103
  }
4052
4104
  // Determine locks base on settings
4053
4105
  size(t, e) {
@@ -4063,7 +4115,7 @@ class Mt {
4063
4115
  // Resize a single axis based on content dimensions
4064
4116
  expand(t) {
4065
4117
  let e = this.lockedWidth, i = this.lockedHeight, s;
4066
- !this.iframe || this._expanding || (this._expanding = !0, this.layout.name === "pre-paginated" ? (e = this.layout.columnWidth, i = this.layout.height) : this.settings.axis === "horizontal" ? (e = this.contents.textWidth(), e % this.layout.pageWidth > 0 && (e = Math.ceil(e / this.layout.pageWidth) * this.layout.pageWidth), this.settings.forceEvenPages && (s = e / this.layout.pageWidth, this.layout.divisor > 1 && this.layout.name === "reflowable" && s % 2 > 0 && (e += this.layout.pageWidth))) : this.settings.axis === "vertical" && (i = this.contents.textHeight(), this.settings.flow === "paginated" && i % this.layout.height > 0 && (i = Math.ceil(i / this.layout.height) * this.layout.height)), (this._needsReframe || e !== this._width || i !== this._height) && this.reframe(e, i), this._expanding = !1);
4118
+ !this.iframe || this._expanding || (this._expanding = !0, this.layout.name === "pre-paginated" ? (e = this.layout.columnWidth, i = this.layout.height) : this.settings.axis === "horizontal" ? (!this._contentDirty && this._textWidth !== void 0 ? e = this._textWidth : (e = this.contents.textWidth(), this._textWidth = e, this._contentDirty = !1), e % this.layout.pageWidth > 0 && (e = Math.ceil(e / this.layout.pageWidth) * this.layout.pageWidth), this.settings.forceEvenPages && (s = e / this.layout.pageWidth, this.layout.divisor > 1 && this.layout.name === "reflowable" && s % 2 > 0 && (e += this.layout.pageWidth))) : this.settings.axis === "vertical" && (!this._contentDirty && this._textHeight !== void 0 ? i = this._textHeight : (i = this.contents.textHeight(), this._textHeight = i, this._contentDirty = !1), this.settings.flow === "paginated" && i % this.layout.height > 0 && (i = Math.ceil(i / this.layout.height) * this.layout.height)), (this._needsReframe || e !== this._width || i !== this._height) && this.reframe(e, i), this._expanding = !1);
4067
4119
  }
4068
4120
  reframe(t, e) {
4069
4121
  E(t) && (this.element.style.width = t + "px", this.iframe.style.width = t + "px", this._width = t), E(e) && (this.element.style.height = e + "px", this.iframe.style.height = e + "px", this._height = e);
@@ -4077,7 +4129,7 @@ class Mt {
4077
4129
  let r;
4078
4130
  for (const o in this.marks)
4079
4131
  this.marks.hasOwnProperty(o) && (r = this.marks[o], this.placeMark(r.element, r.range));
4080
- }), this.onResize(this, n), this.emit(u.VIEWS.RESIZED, n), this.prevBounds = n, this.elementBounds = J(this.element);
4132
+ }), this.onResize(this, n), this.emit(f.VIEWS.RESIZED, n), this.prevBounds = n, this.elementBounds = J(this.element);
4081
4133
  }
4082
4134
  load(t) {
4083
4135
  const e = new S(), i = e.promise;
@@ -4097,16 +4149,16 @@ class Mt {
4097
4149
  return i;
4098
4150
  }
4099
4151
  onLoad(t, e) {
4100
- this.window = this.iframe.contentWindow, this.document = this.iframe.contentDocument, this.contents = new Dt(this.document, this.document.body, this.section.cfiBase, this.section.index), this.rendering = !1;
4152
+ this.window = this.iframe.contentWindow, this.document = this.iframe.contentDocument, this.contents = new Bt(this.document, this.document.body, this.section.cfiBase, this.section.index), this.rendering = !1;
4101
4153
  let i = this.document.querySelector("link[rel='canonical']");
4102
- i ? i.setAttribute("href", this.section.canonical) : (i = this.document.createElement("link"), i.setAttribute("rel", "canonical"), i.setAttribute("href", this.section.canonical), this.document.querySelector("head").appendChild(i)), this.contents.on(u.CONTENTS.EXPAND, () => {
4103
- this.displayed && this.iframe && (this.expand(), this.contents && this.layout.format(this.contents));
4104
- }), this.contents.on(u.CONTENTS.RESIZE, (s) => {
4105
- this.displayed && this.iframe && (this.expand(), this.contents && this.layout.format(this.contents));
4154
+ i ? i.setAttribute("href", this.section.canonical) : (i = this.document.createElement("link"), i.setAttribute("rel", "canonical"), i.setAttribute("href", this.section.canonical), this.document.querySelector("head").appendChild(i)), this.contents.on(f.CONTENTS.EXPAND, () => {
4155
+ this.displayed && this.iframe && (this._contentDirty = !0, this.expand(), this.contents && this.layout.format(this.contents));
4156
+ }), this.contents.on(f.CONTENTS.RESIZE, (s) => {
4157
+ this.displayed && this.iframe && (this._textWidth = s.width, this._textHeight = s.height, this._contentDirty = !1, this.expand(), this.contents && this.layout.format(this.contents));
4106
4158
  }), e.resolve(this.contents);
4107
4159
  }
4108
4160
  setLayout(t) {
4109
- this.layout = t, this.contents && (this.layout.format(this.contents), this.expand());
4161
+ this.layout = t, this.contents && (this.layout.format(this.contents), this._contentDirty = !0, this.expand());
4110
4162
  }
4111
4163
  setAxis(t) {
4112
4164
  this.settings.axis = t, t === "horizontal" ? this.element.style.flex = "none" : this.element.style.flex = "initial", this.size();
@@ -4117,21 +4169,21 @@ class Mt {
4117
4169
  addListeners() {
4118
4170
  }
4119
4171
  removeListeners() {
4120
- this.contents && (this.contents.off(u.CONTENTS.EXPAND), this.contents.off(u.CONTENTS.RESIZE));
4172
+ this.contents && (this.contents.off(f.CONTENTS.EXPAND), this.contents.off(f.CONTENTS.RESIZE));
4121
4173
  }
4122
4174
  display(t) {
4123
4175
  const e = new S();
4124
4176
  return this.displayed ? e.resolve(this) : this.render(t).then(() => {
4125
- this.emit(u.VIEWS.DISPLAYED, this), this.onDisplayed(this), this.displayed = !0, e.resolve(this);
4177
+ this.emit(f.VIEWS.DISPLAYED, this), this.onDisplayed(this), this.displayed = !0, e.resolve(this);
4126
4178
  }, (i) => {
4127
4179
  e.reject(i);
4128
4180
  }), e.promise;
4129
4181
  }
4130
4182
  show() {
4131
- this.element.style.visibility = "visible", this.iframe && (this.iframe.style.visibility = "visible", this.iframe.style.transform = "translateZ(0)", this.iframe.offsetWidth, this.iframe.style.transform = ""), this.emit(u.VIEWS.SHOWN, this);
4183
+ this.element.style.visibility = "visible", this.iframe && (this.iframe.style.visibility = "visible", this.iframe.style.transform = "translateZ(0)", this.iframe.offsetWidth, this.iframe.style.transform = ""), this.emit(f.VIEWS.SHOWN, this);
4132
4184
  }
4133
4185
  hide() {
4134
- this.element.style.visibility = "hidden", this.iframe.style.visibility = "hidden", this.stopExpanding = !0, this.emit(u.VIEWS.HIDDEN, this);
4186
+ this.element.style.visibility = "hidden", this.iframe.style.visibility = "hidden", this.stopExpanding = !0, this.emit(f.VIEWS.HIDDEN, this);
4135
4187
  }
4136
4188
  offset() {
4137
4189
  return {
@@ -4167,10 +4219,10 @@ class Mt {
4167
4219
  if (!this.contents)
4168
4220
  return;
4169
4221
  const r = Object.assign({ fill: "yellow", "fill-opacity": "0.3", "mix-blend-mode": "multiply" }, n), o = this.contents.range(t), h = (d) => {
4170
- this.emit(u.VIEWS.MARK_CLICKED, t, e);
4222
+ this.emit(f.VIEWS.MARK_CLICKED, t, e);
4171
4223
  };
4172
- e.epubcfi = t, this.pane || (this.pane = new St(this.iframe, this.element));
4173
- const l = new Bt(o, s, e, r);
4224
+ e.epubcfi = t, this.pane || (this.pane = new _t(this.iframe, this.element));
4225
+ const l = new Mt(o, s, e, r);
4174
4226
  let c;
4175
4227
  try {
4176
4228
  c = this.pane.addMark(l);
@@ -4184,10 +4236,10 @@ class Mt {
4184
4236
  if (!this.contents)
4185
4237
  return;
4186
4238
  const r = Object.assign({ stroke: "black", "stroke-opacity": "0.3", "mix-blend-mode": "multiply" }, n), o = this.contents.range(t), h = (d) => {
4187
- this.emit(u.VIEWS.MARK_CLICKED, t, e);
4239
+ this.emit(f.VIEWS.MARK_CLICKED, t, e);
4188
4240
  };
4189
- e.epubcfi = t, this.pane || (this.pane = new St(this.iframe, this.element));
4190
- const l = new Ne(o, s, e, r);
4241
+ e.epubcfi = t, this.pane || (this.pane = new _t(this.iframe, this.element));
4242
+ const l = new Re(o, s, e, r);
4191
4243
  let c;
4192
4244
  try {
4193
4245
  c = this.pane.addMark(l);
@@ -4206,7 +4258,7 @@ class Mt {
4206
4258
  if (!s)
4207
4259
  return;
4208
4260
  const n = s.commonAncestorContainer, r = n.nodeType === 1 ? n : n.parentNode, o = (l) => {
4209
- this.emit(u.VIEWS.MARK_CLICKED, t, e);
4261
+ this.emit(f.VIEWS.MARK_CLICKED, t, e);
4210
4262
  };
4211
4263
  s.collapsed && n.nodeType === 1 ? (s = new Range(), s.selectNodeContents(n)) : s.collapsed && (s = new Range(), s.selectNodeContents(r));
4212
4264
  const h = this.document.createElement("a");
@@ -4258,16 +4310,16 @@ class Mt {
4258
4310
  this.ununderline(t);
4259
4311
  for (const t in this.marks)
4260
4312
  this.unmark(t);
4261
- this.blobUrl && Rt(this.blobUrl), this.displayed && (this.displayed = !1, this.removeListeners(), this.contents.destroy(), this.stopExpanding = !0, this.iframe && (this.iframe.onload = null), this.element.removeChild(this.iframe), this.pane && (this.pane.element.remove(), this.pane = void 0), this.iframe = void 0, this.contents = void 0, this.section.unload(), this._textWidth = void 0, this._textHeight = void 0, this._width = void 0, this._height = void 0), this.__listeners = {};
4313
+ this.blobUrl && At(this.blobUrl), this.displayed && (this.displayed = !1, this.removeListeners(), this.contents.destroy(), this.stopExpanding = !0, this.iframe && (this.iframe.onload = null), this.element.removeChild(this.iframe), this.pane && (this.pane.element.remove(), this.pane = void 0), this.iframe = void 0, this.contents = void 0, this.section.unload(), this._textWidth = void 0, this._textHeight = void 0, this._width = void 0, this._height = void 0), this.__listeners = {};
4262
4314
  }
4263
4315
  }
4264
- A(Mt.prototype);
4265
- function Re() {
4316
+ A(Wt.prototype);
4317
+ function Ae() {
4266
4318
  let a = "reverse";
4267
- const t = Ae();
4319
+ const t = Ie();
4268
4320
  return document.body.appendChild(t), t.scrollLeft > 0 ? a = "default" : typeof Element < "u" && typeof Element.prototype.scrollIntoView == "function" ? (t.children[0].children[1].scrollIntoView(), t.scrollLeft < 0 && (a = "negative")) : (t.scrollLeft = 1, t.scrollLeft === 0 && (a = "negative")), document.body.removeChild(t), a;
4269
4321
  }
4270
- function Ae() {
4322
+ function Ie() {
4271
4323
  const a = document.createElement("div");
4272
4324
  a.dir = "rtl", a.style.position = "fixed", a.style.width = "1px", a.style.height = "1px", a.style.top = "0px", a.style.left = "0px", a.style.overflow = "hidden";
4273
4325
  const t = document.createElement("div");
@@ -4277,7 +4329,7 @@ function Ae() {
4277
4329
  const i = document.createElement("span");
4278
4330
  return i.style.width = "1px", i.style.display = "inline-block", t.appendChild(e), t.appendChild(i), a.appendChild(t), a;
4279
4331
  }
4280
- function Ie(a, t) {
4332
+ function Pe(a, t) {
4281
4333
  let e = null, i = 0;
4282
4334
  return function(...s) {
4283
4335
  const n = Date.now(), r = t - (n - i);
@@ -4286,9 +4338,9 @@ function Ie(a, t) {
4286
4338
  }, r));
4287
4339
  };
4288
4340
  }
4289
- class Pe {
4341
+ class Oe {
4290
4342
  constructor(t) {
4291
- this.settings = t || {}, this.id = "epubjs-container-" + kt(), this.container = this.create(this.settings), this.settings.hidden && (this.wrapper = this.wrap(this.container));
4343
+ this.settings = t || {}, this.id = "epubjs-container-" + Nt(), this.container = this.create(this.settings), this.settings.hidden && (this.wrapper = this.wrap(this.container));
4292
4344
  }
4293
4345
  /*
4294
4346
  * Creates an element to render to.
@@ -4297,7 +4349,7 @@ class Pe {
4297
4349
  create(t) {
4298
4350
  let e = t.height, i = t.width;
4299
4351
  const s = t.overflow || !1, n = t.axis || "vertical", r = t.direction;
4300
- _(this.settings, t), t.height && E(t.height) && (e = t.height + "px"), t.width && E(t.width) && (i = t.width + "px");
4352
+ C(this.settings, t), t.height && E(t.height) && (e = t.height + "px"), t.width && E(t.width) && (i = t.width + "px");
4301
4353
  const o = document.createElement("div");
4302
4354
  return o.id = this.id, o.classList.add("epub-container"), o.style.wordSpacing = "0", o.style.lineHeight = "0", o.style.verticalAlign = "top", o.style.position = "relative", o.style.overflowAnchor = "none", n === "horizontal" && (o.style.display = "flex", o.style.flexDirection = "row", o.style.flexWrap = "nowrap"), i && (o.style.width = i), e && (o.style.height = e), s && (s === "scroll" && n === "vertical" ? (o.style.overflowY = s, o.style.overflowX = "hidden") : s === "scroll" && n === "horizontal" ? (o.style.overflowY = "hidden", o.style.overflowX = s) : o.style.overflow = s), r && (o.dir = r, o.style.direction = r), r && this.settings.fullsize && (document.body.style.direction = r), o;
4303
4355
  }
@@ -4307,7 +4359,7 @@ class Pe {
4307
4359
  }
4308
4360
  getElement(t) {
4309
4361
  let e = null;
4310
- if (Xt(t) ? e = t : typeof t == "string" && (e = document.getElementById(t)), !e)
4362
+ if (Yt(t) ? e = t : typeof t == "string" && (e = document.getElementById(t)), !e)
4311
4363
  throw new Error("Not an Element");
4312
4364
  return e;
4313
4365
  }
@@ -4321,7 +4373,7 @@ class Pe {
4321
4373
  return this.container;
4322
4374
  }
4323
4375
  onResize(t) {
4324
- (!E(this.settings.width) || !E(this.settings.height)) && (this.resizeFunc = Ie(t, 50), window.addEventListener("resize", this.resizeFunc, !1));
4376
+ (!E(this.settings.width) || !E(this.settings.height)) && (this.resizeFunc = Pe(t, 50), window.addEventListener("resize", this.resizeFunc, !1));
4325
4377
  }
4326
4378
  onOrientationChange(t) {
4327
4379
  this.orientationChangeFunc = t, window.addEventListener("orientationchange", this.orientationChangeFunc, !1);
@@ -4384,7 +4436,7 @@ class Pe {
4384
4436
  this.element && (this.settings.hidden ? this.wrapper : this.container, this.element.contains(this.container) && this.element.removeChild(this.container), window.removeEventListener("resize", this.resizeFunc), window.removeEventListener("orientationchange", this.orientationChangeFunc));
4385
4437
  }
4386
4438
  }
4387
- class Oe {
4439
+ class De {
4388
4440
  constructor(t) {
4389
4441
  this.container = t, this._views = [], this.length = 0, this.hidden = !1;
4390
4442
  }
@@ -4465,9 +4517,170 @@ class Oe {
4465
4517
  this.hidden = !0;
4466
4518
  }
4467
4519
  }
4520
+ const ze = /[\u2E80-\u9FFF\uF900-\uFAFF\uFE30-\uFE4F\u{20000}-\u{2FA1F}]/u;
4521
+ function St(a) {
4522
+ const t = a.letterSpacing;
4523
+ if (t && t !== "normal" && t !== "0px") return !0;
4524
+ const e = a.wordSpacing;
4525
+ if (e && e !== "normal" && e !== "0px") return !0;
4526
+ const i = a.textIndent;
4527
+ return !!(i && i !== "0px");
4528
+ }
4529
+ const Be = 32;
4530
+ class Me {
4531
+ constructor() {
4532
+ this._canvas = null, this._ctx = null, this._widthCache = /* @__PURE__ */ new Map(), this._preparedCache = /* @__PURE__ */ new WeakMap(), this._nodeIndex = /* @__PURE__ */ new WeakMap(), this._segmenter = null;
4533
+ }
4534
+ getCanvas() {
4535
+ return this._ctx ? this._ctx : typeof OffscreenCanvas < "u" && (this._canvas = new OffscreenCanvas(1, 1), this._ctx = this._canvas.getContext("2d"), this._ctx) ? this._ctx : (this._canvas = document.createElement("canvas"), this._ctx = this._canvas.getContext("2d"), this._ctx);
4536
+ }
4537
+ getSegmenter() {
4538
+ return this._segmenter ? this._segmenter : typeof Intl < "u" && "Segmenter" in Intl ? (this._segmenter = new Intl.Segmenter(void 0, { granularity: "word" }), this._segmenter) : null;
4539
+ }
4540
+ /**
4541
+ * Measure a text string with a given CSS font, returning its width in pixels.
4542
+ * Results are cached per font+text pair.
4543
+ */
4544
+ measureText(t, e) {
4545
+ let i = this._widthCache.get(e);
4546
+ if (i) {
4547
+ const r = i.get(t);
4548
+ if (r !== void 0) return r;
4549
+ } else {
4550
+ if (this._widthCache.size >= Be) {
4551
+ const r = this._widthCache.keys().next().value;
4552
+ r !== void 0 && this._widthCache.delete(r);
4553
+ }
4554
+ i = /* @__PURE__ */ new Map(), this._widthCache.set(e, i);
4555
+ }
4556
+ const s = this.getCanvas();
4557
+ if (!s) return 0;
4558
+ s.font = e;
4559
+ const n = s.measureText(t).width;
4560
+ return i.set(t, n), n;
4561
+ }
4562
+ /**
4563
+ * Segment text into word-level pieces suitable for measurement.
4564
+ * Uses Intl.Segmenter when available, falls back to space-splitting
4565
+ * (with per-character splitting for CJK).
4566
+ */
4567
+ segmentText(t) {
4568
+ const e = this.getSegmenter();
4569
+ if (e) {
4570
+ const o = [];
4571
+ for (const h of e.segment(t))
4572
+ o.push({ text: h.segment, index: h.index });
4573
+ return o;
4574
+ }
4575
+ const i = [];
4576
+ let s = "", n = 0, r = 0;
4577
+ for (const o of t)
4578
+ o === " " ? (s && i.push({ text: s, index: n }), i.push({ text: " ", index: r }), s = "", n = r + o.length) : ze.test(o) ? (s && (i.push({ text: s, index: n }), s = ""), i.push({ text: o, index: r }), n = r + o.length) : (s || (n = r), s += o), r += o.length;
4579
+ return s && i.push({ text: s, index: n }), i;
4580
+ }
4581
+ /**
4582
+ * Prepare phase: measure all text nodes under a root element.
4583
+ * Returns PreparedNode[] with cumulative widths for binary search.
4584
+ *
4585
+ * Text nodes whose parent has exotic CSS (letter-spacing, word-spacing,
4586
+ * text-indent) are skipped — the caller should fall back to DOM Range
4587
+ * measurement for those.
4588
+ *
4589
+ * @param root The container element (usually document.body)
4590
+ * @param win The window object for getComputedStyle
4591
+ * @returns PreparedNode[] with entries for measurable text nodes (may be empty)
4592
+ */
4593
+ prepare(t, e) {
4594
+ const i = this._preparedCache.get(t);
4595
+ if (i) return i;
4596
+ const s = [], n = /* @__PURE__ */ new Map(), r = t.ownerDocument.createTreeWalker(t, NodeFilter.SHOW_TEXT, {
4597
+ acceptNode(h) {
4598
+ return h.data.trim().length > 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT;
4599
+ }
4600
+ });
4601
+ let o;
4602
+ for (; o = r.nextNode(); ) {
4603
+ const h = o.parentElement;
4604
+ if (!h) continue;
4605
+ let l = n.get(h);
4606
+ if (l || (l = e.getComputedStyle(h), n.set(h, l)), St(l)) continue;
4607
+ const c = l.font;
4608
+ if (!c) continue;
4609
+ const d = o.data, u = this.segmentText(d), p = [];
4610
+ let g = 0;
4611
+ for (const v of u) {
4612
+ const x = this.measureText(v.text, c);
4613
+ p.push({
4614
+ node: o,
4615
+ charOffset: v.index,
4616
+ text: v.text,
4617
+ width: x,
4618
+ cumWidth: g + x
4619
+ }), g += x;
4620
+ }
4621
+ const m = {
4622
+ node: o,
4623
+ segments: p,
4624
+ totalWidth: g,
4625
+ font: c
4626
+ };
4627
+ s.push(m), this._nodeIndex.set(o, m);
4628
+ }
4629
+ return this._preparedCache.set(t, s), s;
4630
+ }
4631
+ /**
4632
+ * Layout phase: find the segment index at a given pixel position
4633
+ * using binary search on cumulative widths.
4634
+ *
4635
+ * @param segments The TextSegment[] from a PreparedNode
4636
+ * @param position Target position in pixels (relative to text node start)
4637
+ * @returns Index into the segments array
4638
+ */
4639
+ findSegmentIndex(t, e) {
4640
+ if (t.length === 0) return 0;
4641
+ let i = 0, s = t.length - 1;
4642
+ for (; i < s; ) {
4643
+ const n = i + s >>> 1;
4644
+ t[n].cumWidth < e ? i = n + 1 : s = n;
4645
+ }
4646
+ return i;
4647
+ }
4648
+ /**
4649
+ * Look up a previously prepared text node in O(1).
4650
+ * Returns null if the node was not prepared (exotic CSS, not yet prepared, etc.).
4651
+ */
4652
+ getPreparedNode(t) {
4653
+ return this._nodeIndex.get(t) || null;
4654
+ }
4655
+ /**
4656
+ * Check if a text node's parent has exotic CSS that prevents canvas measurement.
4657
+ */
4658
+ hasExoticCSS(t, e) {
4659
+ const i = t.parentElement;
4660
+ return i ? St(e.getComputedStyle(i)) : !0;
4661
+ }
4662
+ /**
4663
+ * Invalidate cached preparation for a root element,
4664
+ * including all per-node index entries under it.
4665
+ */
4666
+ invalidate(t) {
4667
+ const e = this._preparedCache.get(t);
4668
+ if (e) {
4669
+ for (const i of e)
4670
+ this._nodeIndex.delete(i.node);
4671
+ this._preparedCache.delete(t);
4672
+ }
4673
+ }
4674
+ /**
4675
+ * Destroy the measurer, releasing the canvas and all caches.
4676
+ */
4677
+ destroy() {
4678
+ this._widthCache.clear(), this._preparedCache = /* @__PURE__ */ new WeakMap(), this._nodeIndex = /* @__PURE__ */ new WeakMap(), this._ctx = null, this._canvas = null, this._segmenter = null;
4679
+ }
4680
+ }
4468
4681
  class K {
4469
4682
  constructor(t) {
4470
- this.name = "default", this.optsSettings = t.settings, this.View = t.view, this.request = t.request, this.renditionQueue = t.queue, this.q = new pt(this), this.settings = _({}, {
4683
+ this.name = "default", this.optsSettings = t.settings, this.View = t.view, this.request = t.request, this.renditionQueue = t.queue, this.q = new pt(this), this.settings = C({}, {
4471
4684
  infinite: !0,
4472
4685
  hidden: !1,
4473
4686
  width: void 0,
@@ -4479,7 +4692,7 @@ class K {
4479
4692
  fullsize: void 0,
4480
4693
  allowScriptedContent: !1,
4481
4694
  allowPopups: !1
4482
- }), _(this.settings, t.settings || {}), this.viewSettings = {
4695
+ }), C(this.settings, t.settings || {}), this.viewSettings = {
4483
4696
  ignoreClass: this.settings.ignoreClass,
4484
4697
  axis: this.settings.axis,
4485
4698
  flow: this.settings.flow,
@@ -4491,11 +4704,11 @@ class K {
4491
4704
  forceEvenPages: !0,
4492
4705
  allowScriptedContent: this.settings.allowScriptedContent,
4493
4706
  allowPopups: this.settings.allowPopups
4494
- }, this.rendered = !1;
4707
+ }, this._measurer = new Me(), this.rendered = !1;
4495
4708
  }
4496
4709
  render(t, e) {
4497
4710
  const i = t.tagName;
4498
- typeof this.settings.fullsize > "u" && i && (i.toLowerCase() === "body" || i.toLowerCase() === "html") && (this.settings.fullsize = !0), this.settings.fullsize && (this.settings.overflow = "visible", this.overflow = this.settings.overflow), this.settings.size = e, this.settings.rtlScrollType = Re(), this.stage = new Pe({
4711
+ typeof this.settings.fullsize > "u" && i && (i.toLowerCase() === "body" || i.toLowerCase() === "html") && (this.settings.fullsize = !0), this.settings.fullsize && (this.settings.overflow = "visible", this.overflow = this.settings.overflow), this.settings.size = e, this.settings.rtlScrollType = Ae(), this.stage = new Oe({
4499
4712
  width: e.width,
4500
4713
  height: e.height,
4501
4714
  overflow: this.overflow,
@@ -4503,7 +4716,7 @@ class K {
4503
4716
  axis: this.settings.axis,
4504
4717
  fullsize: this.settings.fullsize,
4505
4718
  direction: this.settings.direction
4506
- }), this.stage.attachTo(t), this.container = this.stage.getContainer(), this.views = new Oe(this.container), this._bounds = this.bounds(), this._stageSize = this.stage.size(), this.viewSettings.width = this._stageSize.width, this.viewSettings.height = this._stageSize.height, this.stage.onResize(() => this.onResized()), this.stage.onOrientationChange((s) => this.onOrientationChange(s)), this.addEventListeners(), this.layout && this.updateLayout(), this.rendered = !0;
4719
+ }), this.stage.attachTo(t), this.container = this.stage.getContainer(), this.views = new De(this.container), this._bounds = this.bounds(), this._stageSize = this.stage.size(), this.viewSettings.width = this._stageSize.width, this.viewSettings.height = this._stageSize.height, this.stage.onResize(() => this.onResized()), this.stage.onOrientationChange((s) => this.onOrientationChange(s)), this.addEventListeners(), this.layout && this.updateLayout(), this.rendered = !0;
4507
4720
  }
4508
4721
  addEventListeners() {
4509
4722
  let t;
@@ -4516,24 +4729,24 @@ class K {
4516
4729
  this.settings.fullsize ? t = window : t = this.container, t.removeEventListener("scroll", this._onScroll), this._onScroll = void 0, window.removeEventListener("unload", this._onUnload), this._onUnload = void 0;
4517
4730
  }
4518
4731
  destroy() {
4519
- clearTimeout(this.resizeTimeout), clearTimeout(this.afterScrolled), this.clear(), this.removeEventListeners(), this.stage.destroy(), this.rendered = !1, this.__listeners = {};
4732
+ clearTimeout(this.resizeTimeout), clearTimeout(this.afterScrolled), this.clear(), this.removeEventListeners(), this.stage.destroy(), this._measurer && this._measurer.destroy(), this.rendered = !1, this.__listeners = {};
4520
4733
  }
4521
4734
  onOrientationChange(t) {
4522
4735
  const { orientation: e } = window;
4523
- this.optsSettings?.resizeOnOrientationChange && this.resize(), this.emit(u.MANAGERS.ORIENTATION_CHANGE, e);
4736
+ this.optsSettings?.resizeOnOrientationChange && this.resize(), this.emit(f.MANAGERS.ORIENTATION_CHANGE, e);
4524
4737
  }
4525
4738
  onResized(t) {
4526
4739
  this.resize();
4527
4740
  }
4528
4741
  resize(t, e, i) {
4529
4742
  const s = this.stage.size(t, e);
4530
- this._stageSize && this._stageSize.width === s.width && this._stageSize.height === s.height || (this._stageSize = s, this._bounds = this.bounds(), this.clear(), this.viewSettings.width = this._stageSize.width, this.viewSettings.height = this._stageSize.height, this.updateLayout(), this.emit(u.MANAGERS.RESIZED, {
4743
+ this._stageSize && this._stageSize.width === s.width && this._stageSize.height === s.height || (this._stageSize = s, this._bounds = this.bounds(), this.clear(), this.viewSettings.width = this._stageSize.width, this.viewSettings.height = this._stageSize.height, this.updateLayout(), this.emit(f.MANAGERS.RESIZED, {
4531
4744
  width: this._stageSize.width,
4532
4745
  height: this._stageSize.height
4533
4746
  }, i));
4534
4747
  }
4535
4748
  createView(t, e) {
4536
- return new this.View(t, _(this.viewSettings, { forceRight: e }));
4749
+ return new this.View(t, C(this.viewSettings, { forceRight: e }));
4537
4750
  }
4538
4751
  handleNextPrePaginated(t, e, i) {
4539
4752
  let s;
@@ -4576,10 +4789,10 @@ class K {
4576
4789
  }), s;
4577
4790
  }
4578
4791
  afterDisplayed(t) {
4579
- this.emit(u.MANAGERS.ADDED, t);
4792
+ this.emit(f.MANAGERS.ADDED, t);
4580
4793
  }
4581
4794
  afterResized(t) {
4582
- this.emit(u.MANAGERS.RESIZE, t.section);
4795
+ this.emit(f.MANAGERS.RESIZE, t.section);
4583
4796
  }
4584
4797
  moveTo(t, e) {
4585
4798
  let i = 0, s = 0;
@@ -4587,27 +4800,27 @@ class K {
4587
4800
  }
4588
4801
  add(t, e) {
4589
4802
  const i = this.createView(t, e);
4590
- return this.views.append(i), i.onDisplayed = (s) => this.afterDisplayed(s), i.onResize = (s) => this.afterResized(s), i.on(u.VIEWS.AXIS, (s) => {
4803
+ return this.views.append(i), i.onDisplayed = (s) => this.afterDisplayed(s), i.onResize = (s) => this.afterResized(s), i.on(f.VIEWS.AXIS, (s) => {
4591
4804
  this.updateAxis(s);
4592
- }), i.on(u.VIEWS.WRITING_MODE, (s) => {
4805
+ }), i.on(f.VIEWS.WRITING_MODE, (s) => {
4593
4806
  this.updateWritingMode(s);
4594
4807
  }), i.display(this.request);
4595
4808
  }
4596
4809
  append(t, e) {
4597
4810
  const i = this.createView(t, e);
4598
- return this.views.append(i), i.onDisplayed = (s) => this.afterDisplayed(s), i.onResize = (s) => this.afterResized(s), i.on(u.VIEWS.AXIS, (s) => {
4811
+ return this.views.append(i), i.onDisplayed = (s) => this.afterDisplayed(s), i.onResize = (s) => this.afterResized(s), i.on(f.VIEWS.AXIS, (s) => {
4599
4812
  this.updateAxis(s);
4600
- }), i.on(u.VIEWS.WRITING_MODE, (s) => {
4813
+ }), i.on(f.VIEWS.WRITING_MODE, (s) => {
4601
4814
  this.updateWritingMode(s);
4602
4815
  }), i.display(this.request);
4603
4816
  }
4604
4817
  prepend(t, e) {
4605
4818
  const i = this.createView(t, e);
4606
- return i.on(u.VIEWS.RESIZED, (s) => {
4819
+ return i.on(f.VIEWS.RESIZED, (s) => {
4607
4820
  this.counter(s);
4608
- }), this.views.prepend(i), i.onDisplayed = (s) => this.afterDisplayed(s), i.onResize = (s) => this.afterResized(s), i.on(u.VIEWS.AXIS, (s) => {
4821
+ }), this.views.prepend(i), i.onDisplayed = (s) => this.afterDisplayed(s), i.onResize = (s) => this.afterResized(s), i.on(f.VIEWS.AXIS, (s) => {
4609
4822
  this.updateAxis(s);
4610
- }), i.on(u.VIEWS.WRITING_MODE, (s) => {
4823
+ }), i.on(f.VIEWS.WRITING_MODE, (s) => {
4611
4824
  this.updateWritingMode(s);
4612
4825
  }), i.display(this.request);
4613
4826
  }
@@ -4720,7 +4933,9 @@ class K {
4720
4933
  return t.length ? t[t.length - 1] : null;
4721
4934
  }
4722
4935
  clear() {
4723
- this.views && (this.views.hide(), this.scrollTo(0, 0, !0), this.views.clear());
4936
+ this.views && (this._measurer && this.views.forEach((t) => {
4937
+ t?.document?.body && this._measurer.invalidate(t.document.body);
4938
+ }), this.views.hide(), this.scrollTo(0, 0, !0), this.views.clear());
4724
4939
  }
4725
4940
  currentLocation() {
4726
4941
  return this.updateLayout(), this.isPaginated && this.settings.axis === "horizontal" ? this.location = this.paginatedLocation() : this.location = this.scrolledLocation(), this.location;
@@ -4731,24 +4946,24 @@ class K {
4731
4946
  let r = 0;
4732
4947
  const o = 0;
4733
4948
  return this.settings.fullsize && (r = n ? window.scrollY : window.scrollX), t.map((l) => {
4734
- const c = l.section.index, d = l.section.href, f = l.position(), p = l.width(), g = l.height();
4735
- let v, y, b, T;
4736
- n ? (v = r + e.top - f.top + o, y = v + i - o, T = this.layout.count(g, i).pages, b = i) : (v = r + e.left - f.left + o, y = v + s - o, T = this.layout.count(p, s).pages, b = s);
4737
- let x = Math.ceil(v / b), C = [], I = Math.ceil(y / b);
4949
+ const c = l.section.index, d = l.section.href, u = l.position(), p = l.width(), g = l.height();
4950
+ let m, v, x, T;
4951
+ n ? (m = r + e.top - u.top + o, v = m + i - o, T = this.layout.count(g, i).pages, x = i) : (m = r + e.left - u.left + o, v = m + s - o, T = this.layout.count(p, s).pages, x = s);
4952
+ let b = Math.ceil(m / x), _ = [], I = Math.ceil(v / x);
4738
4953
  if (this.settings.direction === "rtl" && !n) {
4739
- const D = x;
4740
- x = T - I, I = T - D;
4954
+ const z = b;
4955
+ b = T - I, I = T - z;
4741
4956
  }
4742
- C = [];
4743
- for (let D = x; D <= I; D++) {
4744
- const O = D + 1;
4745
- C.push(O);
4957
+ _ = [];
4958
+ for (let z = b; z <= I; z++) {
4959
+ const O = z + 1;
4960
+ _.push(O);
4746
4961
  }
4747
- const Y = this.mapping.page(l.contents, l.section.cfiBase, v, y);
4962
+ const Y = this.mapping.page(l.contents, l.section.cfiBase, m, v);
4748
4963
  return {
4749
4964
  index: c,
4750
4965
  href: d,
4751
- pages: C,
4966
+ pages: _,
4752
4967
  totalPages: T,
4753
4968
  mapping: Y
4754
4969
  };
@@ -4761,26 +4976,26 @@ class K {
4761
4976
  const o = r.section.index, h = r.section.href;
4762
4977
  let l;
4763
4978
  const c = r.position(), d = r.width();
4764
- let f, p, g;
4765
- this.settings.direction === "rtl" ? (l = e.right - i, g = Math.min(Math.abs(l - c.left), this.layout.width) - s, p = c.width - (c.right - l) - s, f = p - g) : (l = e.left + i, g = Math.min(c.right - l, this.layout.width) - s, f = l - c.left + s, p = f + g), s += g;
4766
- const v = this.mapping.page(r.contents, r.section.cfiBase, f, p), y = this.layout.count(d).pages;
4767
- let b = Math.floor(f / this.layout.pageWidth);
4979
+ let u, p, g;
4980
+ this.settings.direction === "rtl" ? (l = e.right - i, g = Math.min(Math.abs(l - c.left), this.layout.width) - s, p = c.width - (c.right - l) - s, u = p - g) : (l = e.left + i, g = Math.min(c.right - l, this.layout.width) - s, u = l - c.left + s, p = u + g), s += g;
4981
+ const m = this.mapping.page(r.contents, r.section.cfiBase, u, p), v = this.layout.count(d).pages;
4982
+ let x = Math.floor(u / this.layout.pageWidth);
4768
4983
  const T = [];
4769
- let x = Math.floor(p / this.layout.pageWidth);
4770
- if (b < 0 && (b = 0, x = x + 1), this.settings.direction === "rtl") {
4771
- const C = b;
4772
- b = y - x, x = y - C;
4984
+ let b = Math.floor(p / this.layout.pageWidth);
4985
+ if (x < 0 && (x = 0, b = b + 1), this.settings.direction === "rtl") {
4986
+ const _ = x;
4987
+ x = v - b, b = v - _;
4773
4988
  }
4774
- for (let C = b + 1; C <= x; C++) {
4775
- const I = C;
4989
+ for (let _ = x + 1; _ <= b; _++) {
4990
+ const I = _;
4776
4991
  T.push(I);
4777
4992
  }
4778
4993
  return {
4779
4994
  index: o,
4780
4995
  href: h,
4781
4996
  pages: T,
4782
- totalPages: y,
4783
- mapping: v
4997
+ totalPages: v,
4998
+ mapping: m
4784
4999
  };
4785
5000
  });
4786
5001
  }
@@ -4804,11 +5019,11 @@ class K {
4804
5019
  }
4805
5020
  onScroll() {
4806
5021
  let t, e;
4807
- this.settings.fullsize ? (t = window.scrollY, e = window.scrollX) : (t = this.container.scrollTop, e = this.container.scrollLeft), this.scrollTop = t, this.scrollLeft = e, this.ignore ? this.ignore = !1 : (this.emit(u.MANAGERS.SCROLL, {
5022
+ this.settings.fullsize ? (t = window.scrollY, e = window.scrollX) : (t = this.container.scrollTop, e = this.container.scrollLeft), this.scrollTop = t, this.scrollLeft = e, this.ignore ? this.ignore = !1 : (this.emit(f.MANAGERS.SCROLL, {
4808
5023
  top: t,
4809
5024
  left: e
4810
5025
  }), clearTimeout(this.afterScrolled), this.afterScrolled = setTimeout(() => {
4811
- this.emit(u.MANAGERS.SCROLLED, {
5026
+ this.emit(f.MANAGERS.SCROLLED, {
4812
5027
  top: this.scrollTop,
4813
5028
  left: this.scrollLeft
4814
5029
  });
@@ -4828,7 +5043,7 @@ class K {
4828
5043
  ), this.settings.offset = this.layout.delta / this.layout.divisor) : this.layout.calculate(this._stageSize.width, this._stageSize.height), this.viewSettings.width = this.layout.width, this.viewSettings.height = this.layout.height, this.setLayout(this.layout));
4829
5044
  }
4830
5045
  setLayout(t) {
4831
- this.viewSettings.layout = t, this.mapping = new ut(t.props, this.settings.direction, this.settings.axis), this.views && this.views.forEach((e) => {
5046
+ this.viewSettings.layout = t, this.mapping = new ut(t.props, this.settings.direction, this.settings.axis, !1, this._measurer), this.views && this.views.forEach((e) => {
4832
5047
  e && e.setLayout(t);
4833
5048
  });
4834
5049
  }
@@ -4836,7 +5051,7 @@ class K {
4836
5051
  this.writingMode = t;
4837
5052
  }
4838
5053
  updateAxis(t, e) {
4839
- !e && t === this.settings.axis || (this.settings.axis = t, this.stage && this.stage.axis(t), this.viewSettings.axis = t, this.mapping && (this.mapping = new ut(this.layout.props, this.settings.direction, this.settings.axis)), this.layout && (t === "vertical" ? this.layout.spread("none") : this.layout.spread(this.layout.settings.spread)));
5054
+ !e && t === this.settings.axis || (this.settings.axis = t, this.stage && this.stage.axis(t), this.viewSettings.axis = t, this.mapping && (this.mapping = new ut(this.layout.props, this.settings.direction, this.settings.axis, !1, this._measurer)), this.layout && (t === "vertical" ? this.layout.spread("none") : this.layout.spread(this.layout.settings.spread)));
4840
5055
  }
4841
5056
  updateFlow(t, e = "auto") {
4842
5057
  const i = t === "paginated" || t === "auto";
@@ -4857,18 +5072,18 @@ class K {
4857
5072
  }
4858
5073
  }
4859
5074
  A(K.prototype);
4860
- const ze = {
5075
+ const We = {
4861
5076
  easeInCubic: function(a) {
4862
5077
  return Math.pow(a, 3);
4863
5078
  }
4864
5079
  };
4865
5080
  class ft {
4866
5081
  constructor(t, e) {
4867
- this.settings = _({
5082
+ this.settings = C({
4868
5083
  duration: 80,
4869
5084
  minVelocity: 0.2,
4870
5085
  minDistance: 10,
4871
- easing: ze.easeInCubic
5086
+ easing: We.easeInCubic
4872
5087
  }, e || {}), this._supportsTouch = this.supportsTouch(), this._supportsTouch && this.setup(t);
4873
5088
  }
4874
5089
  setup(t) {
@@ -4884,10 +5099,10 @@ class ft {
4884
5099
  this.element.style.overflow = "";
4885
5100
  }
4886
5101
  addListeners() {
4887
- this._onResize = this.onResize.bind(this), window.addEventListener("resize", this._onResize), this._onScroll = this.onScroll.bind(this), this.scroller.addEventListener("scroll", this._onScroll), this._onTouchStart = this.onTouchStart.bind(this), this.scroller.addEventListener("touchstart", this._onTouchStart, { passive: !0 }), this.on("touchstart", this._onTouchStart), this._onTouchMove = this.onTouchMove.bind(this), this.scroller.addEventListener("touchmove", this._onTouchMove, { passive: !0 }), this.on("touchmove", this._onTouchMove), this._onTouchEnd = this.onTouchEnd.bind(this), this.scroller.addEventListener("touchend", this._onTouchEnd, { passive: !0 }), this.on("touchend", this._onTouchEnd), this._afterDisplayed = this.afterDisplayed.bind(this), this.manager.on(u.MANAGERS.ADDED, this._afterDisplayed);
5102
+ this._onResize = this.onResize.bind(this), window.addEventListener("resize", this._onResize), this._onScroll = this.onScroll.bind(this), this.scroller.addEventListener("scroll", this._onScroll), this._onTouchStart = this.onTouchStart.bind(this), this.scroller.addEventListener("touchstart", this._onTouchStart, { passive: !0 }), this.on("touchstart", this._onTouchStart), this._onTouchMove = this.onTouchMove.bind(this), this.scroller.addEventListener("touchmove", this._onTouchMove, { passive: !0 }), this.on("touchmove", this._onTouchMove), this._onTouchEnd = this.onTouchEnd.bind(this), this.scroller.addEventListener("touchend", this._onTouchEnd, { passive: !0 }), this.on("touchend", this._onTouchEnd), this._afterDisplayed = this.afterDisplayed.bind(this), this.manager.on(f.MANAGERS.ADDED, this._afterDisplayed);
4888
5103
  }
4889
5104
  removeListeners() {
4890
- window.removeEventListener("resize", this._onResize), this._onResize = void 0, this.scroller.removeEventListener("scroll", this._onScroll), this._onScroll = void 0, this.scroller.removeEventListener("touchstart", this._onTouchStart, { passive: !0 }), this.off("touchstart", this._onTouchStart), this._onTouchStart = void 0, this.scroller.removeEventListener("touchmove", this._onTouchMove, { passive: !0 }), this.off("touchmove", this._onTouchMove), this._onTouchMove = void 0, this.scroller.removeEventListener("touchend", this._onTouchEnd, { passive: !0 }), this.off("touchend", this._onTouchEnd), this._onTouchEnd = void 0, this.manager.off(u.MANAGERS.ADDED, this._afterDisplayed), this._afterDisplayed = void 0;
5105
+ window.removeEventListener("resize", this._onResize), this._onResize = void 0, this.scroller.removeEventListener("scroll", this._onScroll), this._onScroll = void 0, this.scroller.removeEventListener("touchstart", this._onTouchStart, { passive: !0 }), this.off("touchstart", this._onTouchStart), this._onTouchStart = void 0, this.scroller.removeEventListener("touchmove", this._onTouchMove, { passive: !0 }), this.off("touchmove", this._onTouchMove), this._onTouchMove = void 0, this.scroller.removeEventListener("touchend", this._onTouchEnd, { passive: !0 }), this.off("touchend", this._onTouchEnd), this._onTouchEnd = void 0, this.manager.off(f.MANAGERS.ADDED, this._afterDisplayed), this._afterDisplayed = void 0;
4891
5106
  }
4892
5107
  afterDisplayed(t) {
4893
5108
  const e = t.contents;
@@ -4957,7 +5172,7 @@ class ft {
4957
5172
  }
4958
5173
  }
4959
5174
  A(ft.prototype);
4960
- function De(a, t) {
5175
+ function qe(a, t) {
4961
5176
  let e;
4962
5177
  return function(...i) {
4963
5178
  clearTimeout(e), e = setTimeout(() => {
@@ -4965,9 +5180,9 @@ function De(a, t) {
4965
5180
  }, t);
4966
5181
  };
4967
5182
  }
4968
- class Be extends K {
5183
+ class Ue extends K {
4969
5184
  constructor(t) {
4970
- super(t), this.name = "continuous", this.settings = _({}, {
5185
+ super(t), this.name = "continuous", this.settings = C({}, {
4971
5186
  infinite: !0,
4972
5187
  overflow: void 0,
4973
5188
  axis: void 0,
@@ -4981,7 +5196,7 @@ class Be extends K {
4981
5196
  afterScrolledTimeout: 10,
4982
5197
  allowScriptedContent: !1,
4983
5198
  allowPopups: !1
4984
- }), _(this.settings, t.settings || {});
5199
+ }), C(this.settings, t.settings || {});
4985
5200
  const e = t.settings?.gap;
4986
5201
  e !== void 0 && e === 0 && (this.settings.gap = e), this.viewSettings = {
4987
5202
  ignoreClass: this.settings.ignoreClass,
@@ -5008,7 +5223,7 @@ class Be extends K {
5008
5223
  this.isPaginated ? (e = Math.floor(t.left / this.layout.delta) * this.layout.delta, e + (this.settings.offsetDelta ?? 0)) : (i = t.top, t.top + (this.settings.offsetDelta ?? 0)), (e > 0 || i > 0) && this.scrollBy(e, i, !0);
5009
5224
  }
5010
5225
  afterResized(t) {
5011
- this.emit(u.MANAGERS.RESIZE, t.section);
5226
+ this.emit(f.MANAGERS.RESIZE, t.section);
5012
5227
  }
5013
5228
  // Remove Previous Listeners if present
5014
5229
  removeShownListeners(t) {
@@ -5017,35 +5232,33 @@ class Be extends K {
5017
5232
  }
5018
5233
  add(t) {
5019
5234
  const e = this.createView(t);
5020
- return this.views.append(e), e.on(u.VIEWS.RESIZED, (i) => {
5235
+ return this.views.append(e), e.on(f.VIEWS.RESIZED, (i) => {
5021
5236
  e.expanded = !0;
5022
- }), e.on(u.VIEWS.AXIS, (i) => {
5237
+ }), e.on(f.VIEWS.AXIS, (i) => {
5023
5238
  this.updateAxis(i);
5024
- }), e.on(u.VIEWS.WRITING_MODE, (i) => {
5239
+ }), e.on(f.VIEWS.WRITING_MODE, (i) => {
5025
5240
  this.updateWritingMode(i);
5026
5241
  }), e.onDisplayed = (i) => this.afterDisplayed(i), e.onResize = (i) => this.afterResized(i), e.display(this.request);
5027
5242
  }
5028
- // @ts-expect-error - Returns IframeView synchronously unlike base class Promise<IframeView>
5029
5243
  append(t) {
5030
5244
  const e = this.createView(t);
5031
- return e.on(u.VIEWS.RESIZED, (i) => {
5245
+ return e.on(f.VIEWS.RESIZED, (i) => {
5032
5246
  e.expanded = !0;
5033
- }), e.on(u.VIEWS.AXIS, (i) => {
5247
+ }), e.on(f.VIEWS.AXIS, (i) => {
5034
5248
  this.updateAxis(i);
5035
- }), e.on(u.VIEWS.WRITING_MODE, (i) => {
5249
+ }), e.on(f.VIEWS.WRITING_MODE, (i) => {
5036
5250
  this.updateWritingMode(i);
5037
- }), this.views.append(e), e.onDisplayed = (i) => this.afterDisplayed(i), e;
5251
+ }), this.views.append(e), e.onDisplayed = (i) => this.afterDisplayed(i), Promise.resolve(e);
5038
5252
  }
5039
- // @ts-expect-error - Returns IframeView synchronously unlike base class Promise<IframeView>
5040
5253
  prepend(t) {
5041
5254
  const e = this.createView(t);
5042
- return e.on(u.VIEWS.RESIZED, (i) => {
5255
+ return e.on(f.VIEWS.RESIZED, (i) => {
5043
5256
  this.counter(i), e.expanded = !0;
5044
- }), e.on(u.VIEWS.AXIS, (i) => {
5257
+ }), e.on(f.VIEWS.AXIS, (i) => {
5045
5258
  this.updateAxis(i);
5046
- }), e.on(u.VIEWS.WRITING_MODE, (i) => {
5259
+ }), e.on(f.VIEWS.WRITING_MODE, (i) => {
5047
5260
  this.updateWritingMode(i);
5048
- }), this.views.prepend(e), e.onDisplayed = (i) => this.afterDisplayed(i), e;
5261
+ }), this.views.prepend(e), e.onDisplayed = (i) => this.afterDisplayed(i), Promise.resolve(e);
5049
5262
  }
5050
5263
  counter(t) {
5051
5264
  this.settings.axis === "vertical" ? this.scrollBy(0, t.heightDelta, !0) : this.scrollBy(t.widthDelta, 0, !0);
@@ -5059,9 +5272,9 @@ class Be extends K {
5059
5272
  if (o.displayed)
5060
5273
  o.show();
5061
5274
  else {
5062
- const d = o.display(this.request).then(function(f) {
5063
- f.show();
5064
- }, (f) => {
5275
+ const d = o.display(this.request).then(function(u) {
5276
+ u.show();
5277
+ }, (u) => {
5065
5278
  o.hide();
5066
5279
  });
5067
5280
  l.push(d);
@@ -5080,18 +5293,18 @@ class Be extends K {
5080
5293
  t && n && (r = t), e && !n && (r = e);
5081
5294
  const o = this._bounds;
5082
5295
  let h = n ? this.scrollLeft : this.scrollTop;
5083
- const l = n ? Math.floor(o.width) : o.height, c = n ? this.container.scrollWidth : this.container.scrollHeight, d = this.writingMode && this.writingMode.indexOf("vertical") === 0 ? "vertical" : "horizontal", f = this.settings.rtlScrollType, p = this.settings.direction === "rtl";
5084
- this.settings.fullsize ? (n && p && f === "negative" || !n && p && f === "default") && (h = h * -1) : (p && f === "default" && d === "horizontal" && (h = c - l - h), p && f === "negative" && d === "horizontal" && (h = h * -1));
5296
+ const l = n ? Math.floor(o.width) : o.height, c = n ? this.container.scrollWidth : this.container.scrollHeight, d = this.writingMode && this.writingMode.indexOf("vertical") === 0 ? "vertical" : "horizontal", u = this.settings.rtlScrollType, p = this.settings.direction === "rtl";
5297
+ this.settings.fullsize ? (n && p && u === "negative" || !n && p && u === "default") && (h = h * -1) : (p && u === "default" && d === "horizontal" && (h = c - l - h), p && u === "negative" && d === "horizontal" && (h = h * -1));
5085
5298
  const g = () => {
5086
- const x = this.views.first(), C = x && x.section.prev?.();
5087
- C && s.push(this.prepend(C));
5088
- }, v = () => {
5089
- const x = this.views.last(), C = x && x.section.next?.();
5090
- C && s.push(this.append(C));
5091
- }, y = h + l + r, b = h - r;
5092
- y >= c && v(), b < 0 && g();
5093
- const T = s.map((x) => x.display(this.request));
5094
- return s.length ? Promise.all(T).then(() => this.check()).then(() => this.update(r), (x) => x) : (this.q.enqueue(() => {
5299
+ const b = this.views.first(), _ = b && b.section.prev?.();
5300
+ _ && s.push(this.prepend(_));
5301
+ }, m = () => {
5302
+ const b = this.views.last(), _ = b && b.section.next?.();
5303
+ _ && s.push(this.append(_));
5304
+ }, v = h + l + r, x = h - r;
5305
+ v >= c && m(), x < 0 && g();
5306
+ const T = s.map((b) => b.then((_) => _.display(this.request)));
5307
+ return s.length ? Promise.all(T).then(() => this.check()).then(() => this.update(r), (b) => b) : (this.q.enqueue(() => {
5095
5308
  this.update();
5096
5309
  }), i.resolve(!1), i.promise);
5097
5310
  }
@@ -5120,7 +5333,7 @@ class Be extends K {
5120
5333
  addScrollListeners() {
5121
5334
  let t;
5122
5335
  const e = this.settings.direction === "rtl" && this.settings.rtlScrollType === "default" ? -1 : 1;
5123
- this.scrollDeltaVert = 0, this.scrollDeltaHorz = 0, this.settings.fullsize ? (t = window, this.scrollTop = window.scrollY * e, this.scrollLeft = window.scrollX * e) : (t = this.container, this.scrollTop = this.container.scrollTop, this.scrollLeft = this.container.scrollLeft), this._onScroll = this.onScroll.bind(this), t.addEventListener("scroll", this._onScroll), this._scrolled = De(() => this.scrolled(), 30), this.didScroll = !1;
5336
+ this.scrollDeltaVert = 0, this.scrollDeltaHorz = 0, this.settings.fullsize ? (t = window, this.scrollTop = window.scrollY * e, this.scrollLeft = window.scrollX * e) : (t = this.container, this.scrollTop = this.container.scrollTop, this.scrollLeft = this.container.scrollLeft), this._onScroll = this.onScroll.bind(this), t.addEventListener("scroll", this._onScroll), this._scrolled = qe(() => this.scrolled(), 30), this.didScroll = !1;
5124
5337
  }
5125
5338
  removeEventListeners() {
5126
5339
  let t;
@@ -5134,11 +5347,11 @@ class Be extends K {
5134
5347
  }, 150), clearTimeout(this.afterScrolled), this.didScroll = !1;
5135
5348
  }
5136
5349
  scrolled() {
5137
- this.q.enqueue(() => this.check()), this.emit(u.MANAGERS.SCROLL, {
5350
+ this.q.enqueue(() => this.check()), this.emit(f.MANAGERS.SCROLL, {
5138
5351
  top: this.scrollTop,
5139
5352
  left: this.scrollLeft
5140
5353
  }), clearTimeout(this.afterScrolled), this.afterScrolled = setTimeout(() => {
5141
- this.snapper && this.snapper.supportsTouch() && this.snapper.needsSnap() || this.emit(u.MANAGERS.SCROLLED, {
5354
+ this.snapper && this.snapper.supportsTouch() && this.snapper.needsSnap() || this.emit(f.MANAGERS.SCROLLED, {
5142
5355
  top: this.scrollTop,
5143
5356
  left: this.scrollLeft
5144
5357
  });
@@ -5159,9 +5372,9 @@ class Be extends K {
5159
5372
  clearTimeout(this.scrollTimeout), clearTimeout(this.trimTimeout), super.destroy(), this.snapper && this.snapper.destroy();
5160
5373
  }
5161
5374
  }
5162
- class Wt {
5375
+ class qt {
5163
5376
  constructor(t, e) {
5164
- this.settings = _({}, {
5377
+ this.settings = C({}, {
5165
5378
  width: null,
5166
5379
  height: null,
5167
5380
  ignoreClass: "",
@@ -5178,7 +5391,7 @@ class Wt {
5178
5391
  defaultDirection: "ltr",
5179
5392
  allowScriptedContent: !1,
5180
5393
  allowPopups: !1
5181
- }), _(this.settings, e), typeof this.settings.manager == "object" && (this.manager = this.settings.manager), this.book = t, this.hooks = {}, this.hooks.display = new R(this), this.hooks.serialize = new R(this), this.hooks.content = new R(this), this.hooks.unloaded = new R(this), this.hooks.layout = new R(this), this.hooks.render = new R(this), this.hooks.show = new R(this), this.hooks.content.register((i) => this.handleLinks(i)), this.hooks.content.register((i) => this.passEvents(i)), this.hooks.content.register((i) => this.adjustImages(i)), this.book.spine.hooks.content.register((i, s) => this.injectIdentifier(i, s)), this.settings.stylesheet && this.book.spine.hooks.content.register((i, s) => this.injectStylesheet(i, s)), this.settings.script && this.book.spine.hooks.content.register((i, s) => this.injectScript(i, s)), this.themes = new ye(this), this.annotations = new we(this), this.epubcfi = new m(), this.q = new pt(this), this.location = void 0, this.q.enqueue(this.book.opened), this.starting = new S(), this.started = this.starting.promise, this.q.enqueue(this.start);
5394
+ }), C(this.settings, e), typeof this.settings.manager == "object" && (this.manager = this.settings.manager), this.book = t, this.hooks = {}, this.hooks.display = new R(this), this.hooks.serialize = new R(this), this.hooks.content = new R(this), this.hooks.unloaded = new R(this), this.hooks.layout = new R(this), this.hooks.render = new R(this), this.hooks.show = new R(this), this.hooks.content.register((i) => this.handleLinks(i)), this.hooks.content.register((i) => this.passEvents(i)), this.hooks.content.register((i) => this.adjustImages(i)), this.book.spine.hooks.content.register((i, s) => this.injectIdentifier(i, s)), this.settings.stylesheet && this.book.spine.hooks.content.register((i, s) => this.injectStylesheet(i, s)), this.settings.script && this.book.spine.hooks.content.register((i, s) => this.injectScript(i, s)), this.themes = new we(this), this.annotations = new xe(this), this.epubcfi = new y(), this.q = new pt(this), this.location = void 0, this.q.enqueue(this.book.opened), this.starting = new S(), this.started = this.starting.promise, this.q.enqueue(this.start);
5182
5395
  }
5183
5396
  /**
5184
5397
  * Set the manager function
@@ -5194,7 +5407,7 @@ class Wt {
5194
5407
  */
5195
5408
  requireManager(t) {
5196
5409
  let e;
5197
- return typeof t == "string" && t === "default" ? e = K : typeof t == "string" && t === "continuous" ? e = Be : e = t, e;
5410
+ return typeof t == "string" && t === "default" ? e = K : typeof t == "string" && t === "continuous" ? e = Ue : e = t, e;
5198
5411
  }
5199
5412
  /**
5200
5413
  * Require the view from passed string, or as a class function
@@ -5203,7 +5416,7 @@ class Wt {
5203
5416
  */
5204
5417
  requireView(t) {
5205
5418
  let e;
5206
- return typeof t == "string" && t === "iframe" ? e = Mt : e = t, e;
5419
+ return typeof t == "string" && t === "iframe" ? e = Wt : e = t, e;
5207
5420
  }
5208
5421
  /**
5209
5422
  * Start the rendering
@@ -5223,7 +5436,7 @@ class Wt {
5223
5436
  queue: this.q,
5224
5437
  request: this.book.load.bind(this.book),
5225
5438
  settings: this.settings
5226
- })), this.direction(this.book.package.metadata.direction || this.settings.defaultDirection), this.settings.globalLayoutProperties = this.determineLayoutProperties(this.book.package.metadata), this.flow(this.settings.globalLayoutProperties.flow), this.layout(this.settings.globalLayoutProperties), this.manager.on(u.MANAGERS.ADDED, (t) => this.afterDisplayed(t)), this.manager.on(u.MANAGERS.REMOVED, (t) => this.afterRemoved(t)), this.manager.on(u.MANAGERS.RESIZED, (t, e) => this.onResized(t, e)), this.manager.on(u.MANAGERS.ORIENTATION_CHANGE, (t) => this.onOrientationChange(t)), this.manager.on(u.MANAGERS.SCROLLED, () => this.reportLocation()), this.emit(u.RENDITION.STARTED), this.starting.resolve();
5439
+ })), this.direction(this.book.package.metadata.direction || this.settings.defaultDirection), this.settings.globalLayoutProperties = this.determineLayoutProperties(this.book.package.metadata), this.flow(this.settings.globalLayoutProperties.flow), this.layout(this.settings.globalLayoutProperties), this.manager.on(f.MANAGERS.ADDED, (t) => this.afterDisplayed(t)), this.manager.on(f.MANAGERS.REMOVED, (t) => this.afterRemoved(t)), this.manager.on(f.MANAGERS.RESIZED, (t, e) => this.onResized(t, e)), this.manager.on(f.MANAGERS.ORIENTATION_CHANGE, (t) => this.onOrientationChange(t)), this.manager.on(f.MANAGERS.SCROLLED, () => this.reportLocation()), this.emit(f.RENDITION.STARTED), this.starting.resolve();
5227
5440
  }
5228
5441
  /**
5229
5442
  * Call to attach the container to an element in the dom
@@ -5236,7 +5449,7 @@ class Wt {
5236
5449
  this.manager.render(t, {
5237
5450
  width: this.settings.width,
5238
5451
  height: this.settings.height
5239
- }), this.emit(u.RENDITION.ATTACHED);
5452
+ }), this.emit(f.RENDITION.ATTACHED);
5240
5453
  });
5241
5454
  }
5242
5455
  /**
@@ -5261,12 +5474,12 @@ class Wt {
5261
5474
  return;
5262
5475
  this.epubcfi.isCfiString(t);
5263
5476
  const e = new S(), i = e.promise;
5264
- this.displaying = e, this.book.locations.length() && Yt(t) && (t = this.book.locations.cfiFromPercentage(parseFloat(t)));
5477
+ this.displaying = e, this.book.locations.length() && Gt(t) && (t = this.book.locations.cfiFromPercentage(parseFloat(t)));
5265
5478
  const s = this.book.spine.get(t);
5266
5479
  return s ? (this.manager.display(s, t).then(() => {
5267
- e.resolve(s), this.displaying = void 0, this.emit(u.RENDITION.DISPLAYED, s), this.reportLocation();
5480
+ e.resolve(s), this.displaying = void 0, this.emit(f.RENDITION.DISPLAYED, s), this.reportLocation();
5268
5481
  }, (n) => {
5269
- this.emit(u.RENDITION.DISPLAY_ERROR, n);
5482
+ this.emit(f.RENDITION.DISPLAY_ERROR, n);
5270
5483
  }), i) : (e.reject(new Error("No Section Found")), i);
5271
5484
  }
5272
5485
  /*
@@ -5319,12 +5532,12 @@ class Wt {
5319
5532
  * @param {*} view
5320
5533
  */
5321
5534
  afterDisplayed(t) {
5322
- t.on(u.VIEWS.MARK_CLICKED, (e, i) => {
5535
+ t.on(f.VIEWS.MARK_CLICKED, (e, i) => {
5323
5536
  t.contents && this.triggerMarkEvent(e, i, t.contents);
5324
5537
  }), this.hooks.render.trigger(t, this).then(() => {
5325
5538
  t.contents ? this.hooks.content.trigger(t.contents, this).then(() => {
5326
- this.emit(u.RENDITION.RENDERED, t.section, t);
5327
- }) : this.emit(u.RENDITION.RENDERED, t.section, t);
5539
+ this.emit(f.RENDITION.RENDERED, t.section, t);
5540
+ }) : this.emit(f.RENDITION.RENDERED, t.section, t);
5328
5541
  });
5329
5542
  }
5330
5543
  /**
@@ -5334,7 +5547,7 @@ class Wt {
5334
5547
  */
5335
5548
  afterRemoved(t) {
5336
5549
  this.hooks.unloaded.trigger(t, this).then(() => {
5337
- this.emit(u.RENDITION.REMOVED, t.section, t);
5550
+ this.emit(f.RENDITION.REMOVED, t.section, t);
5338
5551
  });
5339
5552
  }
5340
5553
  /**
@@ -5342,7 +5555,7 @@ class Wt {
5342
5555
  * @private
5343
5556
  */
5344
5557
  onResized(t, e) {
5345
- this.emit(u.RENDITION.RESIZED, {
5558
+ this.emit(f.RENDITION.RESIZED, {
5346
5559
  width: t.width,
5347
5560
  height: t.height
5348
5561
  }, e), this.location && this.location.start && this.display(e || this.location.start.cfi);
@@ -5352,7 +5565,7 @@ class Wt {
5352
5565
  * @private
5353
5566
  */
5354
5567
  onOrientationChange(t) {
5355
- this.emit(u.RENDITION.ORIENTATION_CHANGE, t);
5568
+ this.emit(f.RENDITION.ORIENTATION_CHANGE, t);
5356
5569
  }
5357
5570
  /**
5358
5571
  * Move the Rendition to a specific offset
@@ -5424,13 +5637,13 @@ class Wt {
5424
5637
  * @param {object} settings
5425
5638
  */
5426
5639
  layout(t) {
5427
- return t && (this._layout = new Ot(t), this._layout.spread(t.spread, this.settings.minSpreadWidth), this._layout.on(u.LAYOUT.UPDATED, (e, i) => {
5428
- this.emit(u.RENDITION.LAYOUT, e, i);
5640
+ return t && (this._layout = new Dt(t), this._layout.spread(t.spread, this.settings.minSpreadWidth), this._layout.on(f.LAYOUT.UPDATED, (e, i) => {
5641
+ this.emit(f.RENDITION.LAYOUT, e, i);
5429
5642
  })), this.manager && this._layout && this.manager.applyLayout(this._layout), this._layout;
5430
5643
  }
5431
5644
  /**
5432
5645
  * Adjust if the rendition uses spreads
5433
- * @param {string} spread none | auto (TODO: implement landscape, portrait, both)
5646
+ * @param {string} spread none | auto
5434
5647
  * @param {int} [min] min width to use spreads at
5435
5648
  */
5436
5649
  spread(t, e) {
@@ -5454,25 +5667,25 @@ class Wt {
5454
5667
  if (t && "then" in t && typeof t.then == "function")
5455
5668
  t.then((e) => {
5456
5669
  const i = this.located(e);
5457
- !i || !i.start || !i.end || (this.location = i, this.emit(u.RENDITION.LOCATION_CHANGED, {
5670
+ !i || !i.start || !i.end || (this.location = i, this.emit(f.RENDITION.LOCATION_CHANGED, {
5458
5671
  index: this.location.start.index,
5459
5672
  href: this.location.start.href,
5460
5673
  start: this.location.start.cfi,
5461
5674
  end: this.location.end.cfi,
5462
5675
  percentage: this.location.start.percentage
5463
- }), this.emit(u.RENDITION.RELOCATED, this.location));
5676
+ }), this.emit(f.RENDITION.RELOCATED, this.location));
5464
5677
  });
5465
5678
  else if (t) {
5466
5679
  const e = this.located(t);
5467
5680
  if (!e || !e.start || !e.end)
5468
5681
  return;
5469
- this.location = e, this.emit(u.RENDITION.LOCATION_CHANGED, {
5682
+ this.location = e, this.emit(f.RENDITION.LOCATION_CHANGED, {
5470
5683
  index: this.location.start.index,
5471
5684
  href: this.location.start.href,
5472
5685
  start: this.location.start.cfi,
5473
5686
  end: this.location.end.cfi,
5474
5687
  percentage: this.location.start.percentage
5475
- }), this.emit(u.RENDITION.RELOCATED, this.location);
5688
+ }), this.emit(f.RENDITION.RELOCATED, this.location);
5476
5689
  }
5477
5690
  });
5478
5691
  });
@@ -5525,7 +5738,7 @@ class Wt {
5525
5738
  * Remove and Clean Up the Rendition
5526
5739
  */
5527
5740
  destroy() {
5528
- this.q.clear(), this.manager && (this.manager.off(u.MANAGERS.ADDED), this.manager.off(u.MANAGERS.REMOVED), this.manager.off(u.MANAGERS.RESIZED), this.manager.off(u.MANAGERS.ORIENTATION_CHANGE), this.manager.off(u.MANAGERS.SCROLLED), this.manager.destroy(), this.manager = void 0), this.book = void 0, this.hooks.display.clear(), this.hooks.serialize.clear(), this.hooks.content.clear(), this.hooks.unloaded.clear(), this.hooks.layout.clear(), this.hooks.render.clear(), this.hooks.show.clear(), this.themes.destroy(), this._layout && this._layout.off(u.LAYOUT.UPDATED), this._layout = void 0, this.location = void 0;
5741
+ this.q.clear(), this.manager && (this.manager.off(f.MANAGERS.ADDED), this.manager.off(f.MANAGERS.REMOVED), this.manager.off(f.MANAGERS.RESIZED), this.manager.off(f.MANAGERS.ORIENTATION_CHANGE), this.manager.off(f.MANAGERS.SCROLLED), this.manager.destroy(), this.manager = void 0), this.book = void 0, this.hooks.display.clear(), this.hooks.serialize.clear(), this.hooks.content.clear(), this.hooks.unloaded.clear(), this.hooks.layout.clear(), this.hooks.render.clear(), this.hooks.show.clear(), this.themes.destroy(), this._layout && this._layout.off(f.LAYOUT.UPDATED), this._layout = void 0, this.location = void 0;
5529
5742
  }
5530
5743
  /**
5531
5744
  * Pass the events from a view's Contents
@@ -5535,7 +5748,7 @@ class Wt {
5535
5748
  passEvents(t) {
5536
5749
  G.forEach((e) => {
5537
5750
  t.on(e, (i) => this.triggerViewEvent(i, t));
5538
- }), t.on(u.CONTENTS.SELECTED, (e) => this.triggerSelectedEvent(e, t));
5751
+ }), t.on(f.CONTENTS.SELECTED, (e) => this.triggerSelectedEvent(e, t));
5539
5752
  }
5540
5753
  /**
5541
5754
  * Emit events passed by a view
@@ -5551,7 +5764,7 @@ class Wt {
5551
5764
  * @param {string} cfirange
5552
5765
  */
5553
5766
  triggerSelectedEvent(t, e) {
5554
- this.emit(u.RENDITION.SELECTED, t, e);
5767
+ this.emit(f.RENDITION.SELECTED, t, e);
5555
5768
  }
5556
5769
  /**
5557
5770
  * Emit a markClicked event with the cfiRange and data from a mark
@@ -5559,7 +5772,7 @@ class Wt {
5559
5772
  * @param {EpubCFI} cfirange
5560
5773
  */
5561
5774
  triggerMarkEvent(t, e, i) {
5562
- this.emit(u.RENDITION.MARK_CLICKED, t, e, i);
5775
+ this.emit(f.RENDITION.MARK_CLICKED, t, e, i);
5563
5776
  }
5564
5777
  /**
5565
5778
  * Get a Range from a Visible CFI
@@ -5568,7 +5781,7 @@ class Wt {
5568
5781
  * @return {range}
5569
5782
  */
5570
5783
  getRange(t, e) {
5571
- const i = new m(t), s = this.manager.visible().filter(function(n) {
5784
+ const i = new y(t), s = this.manager.visible().filter(function(n) {
5572
5785
  return i.spinePos === n.index;
5573
5786
  });
5574
5787
  if (s.length)
@@ -5624,7 +5837,7 @@ class Wt {
5624
5837
  * @private
5625
5838
  */
5626
5839
  handleLinks(t) {
5627
- t && t.on(u.CONTENTS.LINK_CLICKED, (e) => {
5840
+ t && t.on(f.CONTENTS.LINK_CLICKED, (e) => {
5628
5841
  const i = this.book.path.relative(e);
5629
5842
  this.display(i);
5630
5843
  });
@@ -5663,9 +5876,9 @@ class Wt {
5663
5876
  s.setAttribute("name", "dc.relation.ispartof"), i && s.setAttribute("content", i), t.getElementsByTagName("head")[0].appendChild(s);
5664
5877
  }
5665
5878
  }
5666
- A(Wt.prototype);
5879
+ A(qt.prototype);
5667
5880
  const st = typeof window < "u" ? window.URL : URL;
5668
- class Me {
5881
+ class je {
5669
5882
  constructor() {
5670
5883
  this.zip = void 0, this.urlCache = {}, this.checkRequirements();
5671
5884
  }
@@ -5676,7 +5889,7 @@ class Me {
5676
5889
  */
5677
5890
  checkRequirements() {
5678
5891
  try {
5679
- this.zip = new Ft();
5892
+ this.zip = new Ht();
5680
5893
  } catch {
5681
5894
  throw new Error("JSZip lib not loaded");
5682
5895
  }
@@ -5697,7 +5910,7 @@ class Me {
5697
5910
  * @return {Promise} zipfile
5698
5911
  */
5699
5912
  openUrl(t, e) {
5700
- return V(t, "binary").then((i) => this.zip.loadAsync(i, { base64: e }));
5913
+ return H(t, "binary").then((i) => this.zip.loadAsync(i, { base64: e }));
5701
5914
  }
5702
5915
  /**
5703
5916
  * Request a url from the archive
@@ -5722,7 +5935,7 @@ class Me {
5722
5935
  * @return {any} the parsed result
5723
5936
  */
5724
5937
  handleResponse(t, e) {
5725
- return Nt(t, e);
5938
+ return Rt(t, e);
5726
5939
  }
5727
5940
  /**
5728
5941
  * Get a Blob from Archive by Url
@@ -5733,7 +5946,7 @@ class Me {
5733
5946
  getBlob(t, e) {
5734
5947
  const i = decodeURIComponent(t.substr(1)), s = this.zip.file(i);
5735
5948
  if (s)
5736
- return e = e || H.lookup(s.name), s.async("uint8array").then(function(n) {
5949
+ return e = e || V.lookup(s.name), s.async("uint8array").then(function(n) {
5737
5950
  return new Blob([n], { type: e });
5738
5951
  });
5739
5952
  }
@@ -5759,7 +5972,7 @@ class Me {
5759
5972
  getBase64(t, e) {
5760
5973
  const i = decodeURIComponent(t.substr(1)), s = this.zip.file(i);
5761
5974
  if (s)
5762
- return e = e || H.lookup(s.name), s.async("base64").then(function(n) {
5975
+ return e = e || V.lookup(s.name), s.async("base64").then(function(n) {
5763
5976
  return "data:" + e + ";base64," + n;
5764
5977
  });
5765
5978
  }
@@ -5803,7 +6016,7 @@ class Me {
5803
6016
  this.zip = void 0, this.urlCache = {};
5804
6017
  }
5805
6018
  }
5806
- function We(a) {
6019
+ function Fe(a) {
5807
6020
  return new Promise((t, e) => {
5808
6021
  const i = indexedDB.open(a, 1);
5809
6022
  i.onupgradeneeded = () => {
@@ -5811,8 +6024,8 @@ function We(a) {
5811
6024
  }, i.onsuccess = () => t(i.result), i.onerror = () => e(i.error);
5812
6025
  });
5813
6026
  }
5814
- function qe(a) {
5815
- const t = We(a);
6027
+ function He(a) {
6028
+ const t = Fe(a);
5816
6029
  return {
5817
6030
  getItem(e) {
5818
6031
  return t.then((i) => new Promise((s, n) => {
@@ -5829,9 +6042,9 @@ function qe(a) {
5829
6042
  };
5830
6043
  }
5831
6044
  const nt = typeof window < "u" ? window.URL : void 0;
5832
- class qt {
6045
+ class Ut {
5833
6046
  constructor(t, e, i) {
5834
- this.urlCache = {}, this.name = t, this.requester = e || V, this.resolver = i, this.online = !0, this.checkRequirements(), this.addListeners();
6047
+ this.urlCache = {}, this.name = t, this.requester = e || H, this.resolver = i, this.online = !0, this.checkRequirements(), this.addListeners();
5835
6048
  }
5836
6049
  /**
5837
6050
  * Checks that IndexedDB is available and creates the storage instance
@@ -5841,7 +6054,7 @@ class qt {
5841
6054
  try {
5842
6055
  if (typeof indexedDB > "u")
5843
6056
  throw new Error("IndexedDB not available");
5844
- this.storage = qe(this.name);
6057
+ this.storage = He(this.name);
5845
6058
  } catch {
5846
6059
  throw new Error("IndexedDB not available");
5847
6060
  }
@@ -5925,7 +6138,7 @@ class qt {
5925
6138
  * @return {string | Document | Blob | object} the parsed result
5926
6139
  */
5927
6140
  handleResponse(t, e) {
5928
- return Nt(t, e);
6141
+ return Rt(t, e);
5929
6142
  }
5930
6143
  /**
5931
6144
  * Get a Blob from Storage by Url
@@ -5937,7 +6150,7 @@ class qt {
5937
6150
  const i = encodeURIComponent(t);
5938
6151
  return this.storage.getItem(i).then(function(s) {
5939
6152
  if (s)
5940
- return e = e || H.lookup(t), new Blob([s], { type: e });
6153
+ return e = e || V.lookup(t), new Blob([s], { type: e });
5941
6154
  });
5942
6155
  }
5943
6156
  /**
@@ -5960,7 +6173,7 @@ class qt {
5960
6173
  */
5961
6174
  async getBase64(t, e) {
5962
6175
  const i = encodeURIComponent(t);
5963
- e = e || H.lookup(t);
6176
+ e = e || V.lookup(t);
5964
6177
  const s = await this.storage.getItem(i);
5965
6178
  if (!s) return;
5966
6179
  const n = new Blob([s], { type: e });
@@ -6009,7 +6222,7 @@ class qt {
6009
6222
  this.urlCache = {}, this.removeListeners();
6010
6223
  }
6011
6224
  }
6012
- A(qt.prototype);
6225
+ A(Ut.prototype);
6013
6226
  class rt {
6014
6227
  constructor(t) {
6015
6228
  this.interactive = "", this.fixedLayout = "", this.openToSpread = "", this.orientationLock = "", t && this.parse(t);
@@ -6045,7 +6258,7 @@ class rt {
6045
6258
  this.interactive = void 0, this.fixedLayout = void 0, this.openToSpread = void 0, this.orientationLock = void 0;
6046
6259
  }
6047
6260
  }
6048
- const Ct = "META-INF/container.xml", Ue = "META-INF/com.apple.ibooks.display-options.xml", L = {
6261
+ const Ct = "META-INF/container.xml", Ve = "META-INF/com.apple.ibooks.display-options.xml", N = {
6049
6262
  BINARY: "binary",
6050
6263
  BASE64: "base64",
6051
6264
  EPUB: "epub",
@@ -6053,9 +6266,9 @@ const Ct = "META-INF/container.xml", Ue = "META-INF/com.apple.ibooks.display-opt
6053
6266
  MANIFEST: "json",
6054
6267
  DIRECTORY: "directory"
6055
6268
  };
6056
- class je {
6269
+ class Xe {
6057
6270
  constructor(t, e) {
6058
- typeof e > "u" && typeof t != "string" && !(t instanceof Blob) && !(t instanceof ArrayBuffer) && (e = t, t = void 0), this.settings = _({}, {
6271
+ typeof e > "u" && typeof t != "string" && !(t instanceof Blob) && !(t instanceof ArrayBuffer) && (e = t, t = void 0), this.settings = C({}, {
6059
6272
  requestMethod: void 0,
6060
6273
  requestCredentials: void 0,
6061
6274
  requestHeaders: void 0,
@@ -6064,7 +6277,7 @@ class je {
6064
6277
  canonical: void 0,
6065
6278
  openAs: void 0,
6066
6279
  store: void 0
6067
- }), _(this.settings, e), this.opening = new S(), this.opened = this.opening.promise, this.isOpen = !1, this.loading = {
6280
+ }), C(this.settings, e), this.opening = new S(), this.opened = this.opening.promise, this.isOpen = !1, this.loading = {
6068
6281
  manifest: new S(),
6069
6282
  spine: new S(),
6070
6283
  metadata: new S(),
@@ -6090,9 +6303,9 @@ class je {
6090
6303
  this.loaded.navigation,
6091
6304
  this.loaded.resources,
6092
6305
  this.loaded.displayOptions
6093
- ]), this.isRendered = !1, this.request = this.settings.requestMethod || V, this.spine = new ue(), this.locations = new Pt(this.spine, (i) => this.load(i)), this.navigation = void 0, this.pageList = void 0, this.url = void 0, this.path = void 0, this.archived = !1, this.archive = void 0, this.storage = void 0, this.resources = void 0, this.rendition = void 0, this.container = void 0, this.packaging = void 0, this.displayOptions = void 0, this.settings.store && this.store(this.settings.store), t && this.open(t, this.settings.openAs).catch((i) => {
6306
+ ]), this.isRendered = !1, this.request = this.settings.requestMethod || H, this.spine = new fe(), this.locations = new Ot(this.spine, (i) => this.load(i)), this.navigation = void 0, this.pageList = void 0, this.url = void 0, this.path = void 0, this.archived = !1, this.archive = void 0, this.storage = void 0, this.resources = void 0, this.rendition = void 0, this.container = void 0, this.packaging = void 0, this.displayOptions = void 0, this.settings.store && this.store(this.settings.store), t && this.open(t, this.settings.openAs).catch((i) => {
6094
6307
  const s = new Error("Cannot load book at " + t);
6095
- this.emit(u.BOOK.OPEN_FAILED, s);
6308
+ this.emit(f.BOOK.OPEN_FAILED, s);
6096
6309
  });
6097
6310
  }
6098
6311
  /**
@@ -6105,7 +6318,7 @@ class je {
6105
6318
  open(t, e) {
6106
6319
  let i;
6107
6320
  const s = e || this.determineType(t);
6108
- return s === L.BINARY ? (this.archived = !0, this.url = new N("/", ""), i = this.openEpub(t)) : s === L.BASE64 ? (this.archived = !0, this.url = new N("/", ""), i = this.openEpub(t, s)) : s === L.EPUB ? (this.archived = !0, this.url = new N("/", ""), i = this.request(t, "binary", this.settings.requestCredentials, this.settings.requestHeaders).then((n) => this.openEpub(n))) : s === L.OPF ? (this.url = new N(t), i = this.openPackaging(this.url.Path.toString())) : s === L.MANIFEST ? (this.url = new N(t), i = this.openManifest(this.url.Path.toString())) : (this.url = new N(t), i = this.openContainer(Ct).then((n) => this.openPackaging(n))), i;
6321
+ return s === N.BINARY ? (this.archived = !0, this.url = new L("/", ""), i = this.openEpub(t)) : s === N.BASE64 ? (this.archived = !0, this.url = new L("/", ""), i = this.openEpub(t, s)) : s === N.EPUB ? (this.archived = !0, this.url = new L("/", ""), i = this.request(t, "binary", this.settings.requestCredentials, this.settings.requestHeaders).then((n) => this.openEpub(n))) : s === N.OPF ? (this.url = new L(t), i = this.openPackaging(this.url.Path.toString())) : s === N.MANIFEST ? (this.url = new L(t), i = this.openManifest(this.url.Path.toString())) : (this.url = new L(t), i = this.openContainer(Ct).then((n) => this.openPackaging(n))), i;
6109
6322
  }
6110
6323
  /**
6111
6324
  * Open an archived epub
@@ -6124,7 +6337,7 @@ class je {
6124
6337
  * @return {string} packagePath
6125
6338
  */
6126
6339
  openContainer(t) {
6127
- return this.load(t).then((e) => (this.container = new fe(e), this.resolve(this.container.packagePath)));
6340
+ return this.load(t).then((e) => (this.container = new pe(e), this.resolve(this.container.packagePath)));
6128
6341
  }
6129
6342
  /**
6130
6343
  * Open the Open Packaging Format Xml
@@ -6133,7 +6346,7 @@ class je {
6133
6346
  * @return {Promise}
6134
6347
  */
6135
6348
  openPackaging(t) {
6136
- return this.path = new P(t), this.load(t).then((e) => (this.packaging = new xt(e), this.unpack(this.packaging)));
6349
+ return this.path = new P(t), this.load(t).then((e) => (this.packaging = new bt(e), this.unpack(this.packaging)));
6137
6350
  }
6138
6351
  /**
6139
6352
  * Open the manifest JSON
@@ -6142,7 +6355,7 @@ class je {
6142
6355
  * @return {Promise}
6143
6356
  */
6144
6357
  openManifest(t) {
6145
- return this.path = new P(t), this.load(t).then((e) => (this.packaging = new xt(), this.packaging.load(e), this.unpack(this.packaging)));
6358
+ return this.path = new P(t), this.load(t).then((e) => (this.packaging = new bt(), this.packaging.load(e), this.unpack(this.packaging)));
6146
6359
  }
6147
6360
  /**
6148
6361
  * Load a resource from the Book
@@ -6183,17 +6396,17 @@ class je {
6183
6396
  determineType(t) {
6184
6397
  let e;
6185
6398
  if (this.settings.encoding === "base64")
6186
- return L.BASE64;
6399
+ return N.BASE64;
6187
6400
  if (typeof t != "string")
6188
- return L.BINARY;
6189
- if (e = new N(t).path().extension, e && (e = e.replace(/\?.*$/, "")), !e)
6190
- return L.DIRECTORY;
6401
+ return N.BINARY;
6402
+ if (e = new L(t).path().extension, e && (e = e.replace(/\?.*$/, "")), !e)
6403
+ return N.DIRECTORY;
6191
6404
  if (e === "epub")
6192
- return L.EPUB;
6405
+ return N.EPUB;
6193
6406
  if (e === "opf")
6194
- return L.OPF;
6407
+ return N.OPF;
6195
6408
  if (e === "json")
6196
- return L.MANIFEST;
6409
+ return N.MANIFEST;
6197
6410
  }
6198
6411
  /**
6199
6412
  * unpack the contents of the Books packaging
@@ -6201,11 +6414,11 @@ class je {
6201
6414
  * @param {Packaging} packaging object
6202
6415
  */
6203
6416
  unpack(t) {
6204
- this.package = t, this.packaging.metadata.layout === "" ? this.load(this.url.resolve(Ue)).then((i) => {
6417
+ this.package = t, this.packaging.metadata.layout === "" ? this.load(this.url.resolve(Ve)).then((i) => {
6205
6418
  this.displayOptions = new rt(i), this.loading.displayOptions.resolve(this.displayOptions);
6206
6419
  }).catch((i) => {
6207
6420
  this.displayOptions = new rt(), this.loading.displayOptions.resolve(this.displayOptions);
6208
- }) : (this.displayOptions = new rt(), this.loading.displayOptions.resolve(this.displayOptions)), this.spine.unpack(this.packaging, (i, s) => this.resolve(i, s), (i) => this.canonical(i)), this.resources = new ve(this.packaging.manifest, {
6421
+ }) : (this.displayOptions = new rt(), this.loading.displayOptions.resolve(this.displayOptions)), this.spine.unpack(this.packaging, (i, s) => this.resolve(i, s), (i) => this.canonical(i)), this.resources = new ye(this.packaging.manifest, {
6209
6422
  archive: this.archive,
6210
6423
  resolver: (i, s) => this.resolve(i, s),
6211
6424
  request: (i, s) => this.request(i, s),
@@ -6247,7 +6460,7 @@ class je {
6247
6460
  * @return {Rendition}
6248
6461
  */
6249
6462
  renderTo(t, e) {
6250
- return this.rendition = new Wt(this, e), this.rendition.attachTo(t), this.rendition;
6463
+ return this.rendition = new qt(this, e), this.rendition.attachTo(t), this.rendition;
6251
6464
  }
6252
6465
  /**
6253
6466
  * Set if request should use withCredentials
@@ -6271,7 +6484,7 @@ class je {
6271
6484
  * @return {Archive}
6272
6485
  */
6273
6486
  unarchive(t, e) {
6274
- return this.archive = new Me(), this.archive.open(t, e === "base64");
6487
+ return this.archive = new je(), this.archive.open(t, e === "base64");
6275
6488
  }
6276
6489
  /**
6277
6490
  * Store the epubs contents
@@ -6281,14 +6494,14 @@ class je {
6281
6494
  * @return {Store}
6282
6495
  */
6283
6496
  store(t) {
6284
- const e = this.settings.replacements && this.settings.replacements !== "none" ? this.settings.replacements : void 0, i = this.url, s = this.settings.requestMethod || ((n, r) => V(n, r));
6285
- return this.storage = new qt(t, s, (n, r) => this.resolve(n, r)), this.request = (n, r) => this.storage.request(n, r), this.opened.then(() => {
6497
+ const e = this.settings.replacements && this.settings.replacements !== "none" ? this.settings.replacements : void 0, i = this.url, s = this.settings.requestMethod || ((n, r) => H(n, r));
6498
+ return this.storage = new Ut(t, s, (n, r) => this.resolve(n, r)), this.request = (n, r) => this.storage.request(n, r), this.opened.then(() => {
6286
6499
  this.archived && (this.storage.requester = (r, o) => this.archive.request(r, o));
6287
6500
  const n = (r, o) => {
6288
6501
  o.output = this.resources.substitute(r, o.url);
6289
6502
  };
6290
6503
  this.resources.settings.replacements = e || "blobUrl", this.resources.replacements().then(() => this.resources.replaceCss()), this.storage.on("offline", () => {
6291
- this.url = new N("/", ""), this.spine.hooks.serialize.register(n);
6504
+ this.url = new L("/", ""), this.spine.hooks.serialize.register(n);
6292
6505
  }), this.storage.on("online", () => {
6293
6506
  this.url = i, this.spine.hooks.serialize.deregister(n);
6294
6507
  });
@@ -6319,7 +6532,7 @@ class je {
6319
6532
  * @return {Promise}
6320
6533
  */
6321
6534
  getRange(t) {
6322
- const e = new m(t), i = this.spine.get(e.spinePos), s = (n) => this.load(n);
6535
+ const e = new y(t), i = this.spine.get(e.spinePos), s = (n) => this.load(n);
6323
6536
  return i ? i.load(s).then(function(n) {
6324
6537
  return e.toRange(i.document);
6325
6538
  }) : new Promise((n, r) => {
@@ -6333,7 +6546,7 @@ class je {
6333
6546
  */
6334
6547
  key(t) {
6335
6548
  const e = t || this.packaging.metadata.identifier || this.url.filename;
6336
- return `epubjs:${It}:${e}`;
6549
+ return `epubjs:${Pt}:${e}`;
6337
6550
  }
6338
6551
  /**
6339
6552
  * Destroy the Book and all associated objects
@@ -6342,30 +6555,30 @@ class je {
6342
6555
  this.opened = void 0, this.loading = void 0, this.loaded = void 0, this.ready = void 0, this.replacementsReady = void 0, this.isOpen = !1, this.isRendered = !1, this.spine && this.spine.destroy(), this.locations && this.locations.destroy(), this.pageList && this.pageList.destroy(), this.archive && this.archive.destroy(), this.resources && this.resources.destroy(), this.container && this.container.destroy(), this.packaging && this.packaging.destroy(), this.rendition && this.rendition.destroy(), this.displayOptions && this.displayOptions.destroy(), this.storage && (this.storage.destroy(), this.storage = void 0), this.spine = void 0, this.locations = void 0, this.pageList = void 0, this.archive = void 0, this.resources = void 0, this.container = void 0, this.packaging = void 0, this.rendition = void 0, this.navigation = void 0, this.url = void 0, this.path = void 0, this.archived = !1;
6343
6556
  }
6344
6557
  }
6345
- A(je.prototype);
6346
- typeof globalThis.DOMParser > "u" && (globalThis.DOMParser = Ut);
6558
+ A(Xe.prototype);
6559
+ typeof globalThis.DOMParser > "u" && (globalThis.DOMParser = jt);
6347
6560
  typeof globalThis.XMLSerializer > "u" && (globalThis.XMLSerializer = class {
6348
6561
  serializeToString(t) {
6349
6562
  return t.toString();
6350
6563
  }
6351
6564
  });
6352
6565
  if (typeof globalThis.document > "u") {
6353
- const { document: a } = jt("<!DOCTYPE html><html><head></head><body></body></html>");
6566
+ const { document: a } = Ft("<!DOCTYPE html><html><head></head><body></body></html>");
6354
6567
  globalThis.document = a;
6355
6568
  }
6356
6569
  export {
6357
- Me as Archive,
6358
- je as Book,
6359
- fe as Container,
6570
+ je as Archive,
6571
+ Xe as Book,
6572
+ pe as Container,
6360
6573
  rt as DisplayOptions,
6361
- m as EpubCFI,
6362
- Ot as Layout,
6363
- Pt as Locations,
6574
+ y as EpubCFI,
6575
+ Dt as Layout,
6576
+ Ot as Locations,
6364
6577
  tt as Navigation,
6365
- xt as Packaging,
6578
+ bt as Packaging,
6366
6579
  it as PageList,
6367
- ve as Resources,
6368
- de as Section,
6369
- ue as Spine
6580
+ ye as Resources,
6581
+ ue as Section,
6582
+ fe as Spine
6370
6583
  };
6371
6584
  //# sourceMappingURL=epub.node.js.map