@readium/navigator-html-injectables 1.2.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- const Mt = Math.pow(2, 32), Ae = () => Math.round(Math.random() * Mt).toString(36), Nt = () => `${Math.round(performance.now())}-${Ae()}-${Ae()}`, X = 1;
2
- class Rt {
1
+ const Mt = Math.pow(2, 32), Ae = () => Math.round(Math.random() * Mt).toString(36), Rt = () => `${Math.round(performance.now())}-${Ae()}-${Ae()}`, _ = 1;
2
+ class Nt {
3
3
  constructor(e) {
4
4
  this.destination = null, this.registrar = /* @__PURE__ */ new Map(), this.origin = "", this.channelId = "", this.receiver = this.receive.bind(this), this.preLog = [], this.wnd = e, e.addEventListener("message", this.receiver);
5
5
  }
@@ -12,8 +12,8 @@ class Rt {
12
12
  if (!(!("_readium" in t) || !t._readium || t._readium <= 0)) {
13
13
  if (t.key === "_ping") {
14
14
  if (!this.destination) {
15
- if (this.destination = e.source, this.origin = e.origin, this.channelId = t._channel, t._readium !== X) {
16
- t._readium > X ? this.send("error", `received comms version ${t._readium} higher than ${X}`) : this.send("error", `received comms version ${t._readium} lower than ${X}`), this.destination = null, this.origin = "", this.channelId = "";
15
+ if (this.destination = e.source, this.origin = e.origin, this.channelId = t._channel, t._readium !== _) {
16
+ t._readium > _ ? this.send("error", `received comms version ${t._readium} higher than ${_}`) : this.send("error", `received comms version ${t._readium} lower than ${_}`), this.destination = null, this.origin = "", this.channelId = "";
17
17
  return;
18
18
  }
19
19
  this.send("_pong", void 0), this.preLog.forEach((r) => this.send("log", r)), this.preLog = [];
@@ -76,9 +76,9 @@ class Rt {
76
76
  if (!this.destination)
77
77
  throw Error("Attempted to send comms message before destination has been initialized");
78
78
  const n = {
79
- _readium: X,
79
+ _readium: _,
80
80
  _channel: this.channelId,
81
- id: r ?? Nt(),
81
+ id: r ?? Rt(),
82
82
  // scrict,
83
83
  key: e,
84
84
  data: t
@@ -95,341 +95,7 @@ class Rt {
95
95
  }
96
96
  }
97
97
  }
98
- class ce {
99
- }
100
- var F = [], Lt = function() {
101
- return F.some(function(i) {
102
- return i.activeTargets.length > 0;
103
- });
104
- }, zt = function() {
105
- return F.some(function(i) {
106
- return i.skippedTargets.length > 0;
107
- });
108
- }, Me = "ResizeObserver loop completed with undelivered notifications.", It = function() {
109
- var i;
110
- typeof ErrorEvent == "function" ? i = new ErrorEvent("error", {
111
- message: Me
112
- }) : (i = document.createEvent("Event"), i.initEvent("error", !1, !1), i.message = Me), window.dispatchEvent(i);
113
- }, G;
114
- (function(i) {
115
- i.BORDER_BOX = "border-box", i.CONTENT_BOX = "content-box", i.DEVICE_PIXEL_CONTENT_BOX = "device-pixel-content-box";
116
- })(G || (G = {}));
117
- var k = function(i) {
118
- return Object.freeze(i);
119
- }, Bt = function() {
120
- function i(e, t) {
121
- this.inlineSize = e, this.blockSize = t, k(this);
122
- }
123
- return i;
124
- }(), Qe = function() {
125
- function i(e, t, r, s) {
126
- return this.x = e, this.y = t, this.width = r, this.height = s, this.top = this.y, this.left = this.x, this.bottom = this.top + this.height, this.right = this.left + this.width, k(this);
127
- }
128
- return i.prototype.toJSON = function() {
129
- var e = this, t = e.x, r = e.y, s = e.top, n = e.right, o = e.bottom, a = e.left, h = e.width, c = e.height;
130
- return { x: t, y: r, top: s, right: n, bottom: o, left: a, width: h, height: c };
131
- }, i.fromRect = function(e) {
132
- return new i(e.x, e.y, e.width, e.height);
133
- }, i;
134
- }(), Ee = function(i) {
135
- return i instanceof SVGElement && "getBBox" in i;
136
- }, et = function(i) {
137
- if (Ee(i)) {
138
- var e = i.getBBox(), t = e.width, r = e.height;
139
- return !t && !r;
140
- }
141
- var s = i, n = s.offsetWidth, o = s.offsetHeight;
142
- return !(n || o || i.getClientRects().length);
143
- }, Ne = function(i) {
144
- var e;
145
- if (i instanceof Element)
146
- return !0;
147
- var t = (e = i == null ? void 0 : i.ownerDocument) === null || e === void 0 ? void 0 : e.defaultView;
148
- return !!(t && i instanceof t.Element);
149
- }, Dt = function(i) {
150
- switch (i.tagName) {
151
- case "INPUT":
152
- if (i.type !== "image")
153
- break;
154
- case "VIDEO":
155
- case "AUDIO":
156
- case "EMBED":
157
- case "OBJECT":
158
- case "CANVAS":
159
- case "IFRAME":
160
- case "IMG":
161
- return !0;
162
- }
163
- return !1;
164
- }, _ = typeof window < "u" ? window : {}, Q = /* @__PURE__ */ new WeakMap(), Re = /auto|scroll/, Wt = /^tb|vertical/, Ft = /msie|trident/i.test(_.navigator && _.navigator.userAgent), N = function(i) {
165
- return parseFloat(i || "0");
166
- }, $ = function(i, e, t) {
167
- return i === void 0 && (i = 0), e === void 0 && (e = 0), t === void 0 && (t = !1), new Bt((t ? e : i) || 0, (t ? i : e) || 0);
168
- }, Le = k({
169
- devicePixelContentBoxSize: $(),
170
- borderBoxSize: $(),
171
- contentBoxSize: $(),
172
- contentRect: new Qe(0, 0, 0, 0)
173
- }), tt = function(i, e) {
174
- if (e === void 0 && (e = !1), Q.has(i) && !e)
175
- return Q.get(i);
176
- if (et(i))
177
- return Q.set(i, Le), Le;
178
- var t = getComputedStyle(i), r = Ee(i) && i.ownerSVGElement && i.getBBox(), s = !Ft && t.boxSizing === "border-box", n = Wt.test(t.writingMode || ""), o = !r && Re.test(t.overflowY || ""), a = !r && Re.test(t.overflowX || ""), h = r ? 0 : N(t.paddingTop), c = r ? 0 : N(t.paddingRight), d = r ? 0 : N(t.paddingBottom), p = r ? 0 : N(t.paddingLeft), u = r ? 0 : N(t.borderTopWidth), f = r ? 0 : N(t.borderRightWidth), v = r ? 0 : N(t.borderBottomWidth), g = r ? 0 : N(t.borderLeftWidth), y = p + c, x = h + d, S = g + f, m = u + v, E = a ? i.offsetHeight - m - i.clientHeight : 0, O = o ? i.offsetWidth - S - i.clientWidth : 0, Y = s ? y + S : 0, Z = s ? x + m : 0, B = r ? r.width : N(t.width) - Y - O, D = r ? r.height : N(t.height) - Z - E, K = B + y + O + S, J = D + x + E + m, U = k({
179
- devicePixelContentBoxSize: $(Math.round(B * devicePixelRatio), Math.round(D * devicePixelRatio), n),
180
- borderBoxSize: $(K, J, n),
181
- contentBoxSize: $(B, D, n),
182
- contentRect: new Qe(p, h, B, D)
183
- });
184
- return Q.set(i, U), U;
185
- }, it = function(i, e, t) {
186
- var r = tt(i, t), s = r.borderBoxSize, n = r.contentBoxSize, o = r.devicePixelContentBoxSize;
187
- switch (e) {
188
- case G.DEVICE_PIXEL_CONTENT_BOX:
189
- return o;
190
- case G.BORDER_BOX:
191
- return s;
192
- default:
193
- return n;
194
- }
195
- }, kt = function() {
196
- function i(e) {
197
- var t = tt(e);
198
- this.target = e, this.contentRect = t.contentRect, this.borderBoxSize = k([t.borderBoxSize]), this.contentBoxSize = k([t.contentBoxSize]), this.devicePixelContentBoxSize = k([t.devicePixelContentBoxSize]);
199
- }
200
- return i;
201
- }(), rt = function(i) {
202
- if (et(i))
203
- return 1 / 0;
204
- for (var e = 0, t = i.parentNode; t; )
205
- e += 1, t = t.parentNode;
206
- return e;
207
- }, Ut = function() {
208
- var i = 1 / 0, e = [];
209
- F.forEach(function(o) {
210
- if (o.activeTargets.length !== 0) {
211
- var a = [];
212
- o.activeTargets.forEach(function(c) {
213
- var d = new kt(c.target), p = rt(c.target);
214
- a.push(d), c.lastReportedSize = it(c.target, c.observedBox), p < i && (i = p);
215
- }), e.push(function() {
216
- o.callback.call(o.observer, a, o.observer);
217
- }), o.activeTargets.splice(0, o.activeTargets.length);
218
- }
219
- });
220
- for (var t = 0, r = e; t < r.length; t++) {
221
- var s = r[t];
222
- s();
223
- }
224
- return i;
225
- }, ze = function(i) {
226
- F.forEach(function(t) {
227
- t.activeTargets.splice(0, t.activeTargets.length), t.skippedTargets.splice(0, t.skippedTargets.length), t.observationTargets.forEach(function(s) {
228
- s.isActive() && (rt(s.target) > i ? t.activeTargets.push(s) : t.skippedTargets.push(s));
229
- });
230
- });
231
- }, $t = function() {
232
- var i = 0;
233
- for (ze(i); Lt(); )
234
- i = Ut(), ze(i);
235
- return zt() && It(), i > 0;
236
- }, de, st = [], Ht = function() {
237
- return st.splice(0).forEach(function(i) {
238
- return i();
239
- });
240
- }, qt = function(i) {
241
- if (!de) {
242
- var e = 0, t = document.createTextNode(""), r = { characterData: !0 };
243
- new MutationObserver(function() {
244
- return Ht();
245
- }).observe(t, r), de = function() {
246
- t.textContent = "".concat(e ? e-- : e++);
247
- };
248
- }
249
- st.push(i), de();
250
- }, Xt = function(i) {
251
- qt(function() {
252
- requestAnimationFrame(i);
253
- });
254
- }, re = 0, Vt = function() {
255
- return !!re;
256
- }, _t = 250, jt = { attributes: !0, characterData: !0, childList: !0, subtree: !0 }, Ie = [
257
- "resize",
258
- "load",
259
- "transitionend",
260
- "animationend",
261
- "animationstart",
262
- "animationiteration",
263
- "keyup",
264
- "keydown",
265
- "mouseup",
266
- "mousedown",
267
- "mouseover",
268
- "mouseout",
269
- "blur",
270
- "focus"
271
- ], Be = function(i) {
272
- return i === void 0 && (i = 0), Date.now() + i;
273
- }, ue = !1, Gt = function() {
274
- function i() {
275
- var e = this;
276
- this.stopped = !0, this.listener = function() {
277
- return e.schedule();
278
- };
279
- }
280
- return i.prototype.run = function(e) {
281
- var t = this;
282
- if (e === void 0 && (e = _t), !ue) {
283
- ue = !0;
284
- var r = Be(e);
285
- Xt(function() {
286
- var s = !1;
287
- try {
288
- s = $t();
289
- } finally {
290
- if (ue = !1, e = r - Be(), !Vt())
291
- return;
292
- s ? t.run(1e3) : e > 0 ? t.run(e) : t.start();
293
- }
294
- });
295
- }
296
- }, i.prototype.schedule = function() {
297
- this.stop(), this.run();
298
- }, i.prototype.observe = function() {
299
- var e = this, t = function() {
300
- return e.observer && e.observer.observe(document.body, jt);
301
- };
302
- document.body ? t() : _.addEventListener("DOMContentLoaded", t);
303
- }, i.prototype.start = function() {
304
- var e = this;
305
- this.stopped && (this.stopped = !1, this.observer = new MutationObserver(this.listener), this.observe(), Ie.forEach(function(t) {
306
- return _.addEventListener(t, e.listener, !0);
307
- }));
308
- }, i.prototype.stop = function() {
309
- var e = this;
310
- this.stopped || (this.observer && this.observer.disconnect(), Ie.forEach(function(t) {
311
- return _.removeEventListener(t, e.listener, !0);
312
- }), this.stopped = !0);
313
- }, i;
314
- }(), fe = new Gt(), De = function(i) {
315
- !re && i > 0 && fe.start(), re += i, !re && fe.stop();
316
- }, Yt = function(i) {
317
- return !Ee(i) && !Dt(i) && getComputedStyle(i).display === "inline";
318
- }, Zt = function() {
319
- function i(e, t) {
320
- this.target = e, this.observedBox = t || G.CONTENT_BOX, this.lastReportedSize = {
321
- inlineSize: 0,
322
- blockSize: 0
323
- };
324
- }
325
- return i.prototype.isActive = function() {
326
- var e = it(this.target, this.observedBox, !0);
327
- return Yt(this.target) && (this.lastReportedSize = e), this.lastReportedSize.inlineSize !== e.inlineSize || this.lastReportedSize.blockSize !== e.blockSize;
328
- }, i;
329
- }(), Kt = function() {
330
- function i(e, t) {
331
- this.activeTargets = [], this.skippedTargets = [], this.observationTargets = [], this.observer = e, this.callback = t;
332
- }
333
- return i;
334
- }(), ee = /* @__PURE__ */ new WeakMap(), We = function(i, e) {
335
- for (var t = 0; t < i.length; t += 1)
336
- if (i[t].target === e)
337
- return t;
338
- return -1;
339
- }, te = function() {
340
- function i() {
341
- }
342
- return i.connect = function(e, t) {
343
- var r = new Kt(e, t);
344
- ee.set(e, r);
345
- }, i.observe = function(e, t, r) {
346
- var s = ee.get(e), n = s.observationTargets.length === 0;
347
- We(s.observationTargets, t) < 0 && (n && F.push(s), s.observationTargets.push(new Zt(t, r && r.box)), De(1), fe.schedule());
348
- }, i.unobserve = function(e, t) {
349
- var r = ee.get(e), s = We(r.observationTargets, t), n = r.observationTargets.length === 1;
350
- s >= 0 && (n && F.splice(F.indexOf(r), 1), r.observationTargets.splice(s, 1), De(-1));
351
- }, i.disconnect = function(e) {
352
- var t = this, r = ee.get(e);
353
- r.observationTargets.slice().forEach(function(s) {
354
- return t.unobserve(e, s.target);
355
- }), r.activeTargets.splice(0, r.activeTargets.length);
356
- }, i;
357
- }(), nt = function() {
358
- function i(e) {
359
- if (arguments.length === 0)
360
- throw new TypeError("Failed to construct 'ResizeObserver': 1 argument required, but only 0 present.");
361
- if (typeof e != "function")
362
- throw new TypeError("Failed to construct 'ResizeObserver': The callback provided as parameter 1 is not a function.");
363
- te.connect(this, e);
364
- }
365
- return i.prototype.observe = function(e, t) {
366
- if (arguments.length === 0)
367
- throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': 1 argument required, but only 0 present.");
368
- if (!Ne(e))
369
- throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element");
370
- te.observe(this, e, t);
371
- }, i.prototype.unobserve = function(e) {
372
- if (arguments.length === 0)
373
- throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': 1 argument required, but only 0 present.");
374
- if (!Ne(e))
375
- throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': parameter 1 is not of type 'Element");
376
- te.unobserve(this, e);
377
- }, i.prototype.disconnect = function() {
378
- te.disconnect(this);
379
- }, i.toString = function() {
380
- return "function ResizeObserver () { [polyfill code] }";
381
- }, i;
382
- }();
383
- const Fe = "readium-snapper-style", ot = class me extends ce {
384
- constructor() {
385
- super(...arguments), this.protected = !1;
386
- }
387
- buildStyles() {
388
- return `
389
- html, body {
390
- touch-action: manipulation;
391
- user-select: ${this.protected ? "none" : "auto"};
392
- }`;
393
- }
394
- mount(e, t) {
395
- const r = e.document.createElement("style");
396
- return r.dataset.readium = "true", r.id = Fe, r.textContent = this.buildStyles(), e.document.head.appendChild(r), t.register("protect", me.moduleName, (s, n) => {
397
- this.protected = !0, r.textContent = this.buildStyles(), n(!0);
398
- }), t.register("unprotect", me.moduleName, (s, n) => {
399
- this.protected = !1, r.textContent = this.buildStyles(), n(!0);
400
- }), t.log("Snapper Mounted"), !0;
401
- }
402
- unmount(e, t) {
403
- var r;
404
- return (r = e.document.getElementById(Fe)) == null || r.remove(), t.log("Snapper Unmounted"), !0;
405
- }
406
- };
407
- ot.moduleName = "snapper";
408
- let at = ot;
409
- function W(i) {
410
- return i.document.body.dir.toLowerCase() === "rtl";
411
- }
412
- function lt(i) {
413
- return parseInt(
414
- i.getComputedStyle(
415
- i.document.documentElement
416
- ).getPropertyValue("column-count")
417
- );
418
- }
419
- function Jt(i) {
420
- const e = "readium-virtual-page";
421
- let t = i.document.getElementById(e);
422
- if (lt(i) !== 2)
423
- t && t.remove();
424
- else {
425
- const s = i.document.scrollingElement.scrollWidth / i.innerWidth;
426
- Math.round(s * 2) / 2 % 1 > 0.1 && (t ? t.remove() : (t = i.document.createElement("div"), t.setAttribute("id", e), t.dataset.readium = "true", t.style.breakBefore = "column", t.innerHTML = "&#8203;", i.document.body.appendChild(t)));
427
- }
428
- }
429
- function Qt(i) {
430
- return i < 0.5 ? 2 * i * i : -1 + (4 - 2 * i) * i;
431
- }
432
- class xe {
98
+ class Ee {
433
99
  /**
434
100
  * Creates a [Encryption].
435
101
  */
@@ -441,7 +107,7 @@ class xe {
441
107
  */
442
108
  static deserialize(e) {
443
109
  if (e && e.algorithm)
444
- return new xe({
110
+ return new Ee({
445
111
  algorithm: e.algorithm,
446
112
  compression: e.compression,
447
113
  originalLength: e.originalLength,
@@ -486,7 +152,7 @@ class b {
486
152
  }
487
153
  Object.defineProperty(b.prototype, "encryption", {
488
154
  get: function() {
489
- return xe.deserialize(this.otherProperties.encrypted);
155
+ return Ee.deserialize(this.otherProperties.encrypted);
490
156
  }
491
157
  });
492
158
  b.prototype.getContains = function() {
@@ -506,22 +172,22 @@ class l {
506
172
  } else
507
173
  throw new Error("Invalid media type");
508
174
  const o = {};
509
- for (let u = 1; u < s.length; u++) {
510
- const f = s[u].split("=");
175
+ for (let d = 1; d < s.length; d++) {
176
+ const f = s[d].split("=");
511
177
  if (f.length === 2) {
512
178
  const v = f[0].toLocaleLowerCase(), g = v === "charset" ? f[1].toUpperCase() : f[1];
513
179
  o[v] = g;
514
180
  }
515
181
  }
516
182
  const a = {}, h = Object.keys(o);
517
- h.sort((u, f) => u.localeCompare(f)), h.forEach((u) => a[u] = o[u]);
183
+ h.sort((d, f) => d.localeCompare(f)), h.forEach((d) => a[d] = o[d]);
518
184
  let c = "";
519
- for (const u in a) {
520
- const f = a[u];
521
- c += `;${u}=${f}`;
185
+ for (const d in a) {
186
+ const f = a[d];
187
+ c += `;${d}=${f}`;
522
188
  }
523
- const d = `${t}/${r}${c}`, p = a.encoding;
524
- this.string = d, this.type = t, this.subtype = r, this.parameters = a, this.encoding = p, this.name = e.name, this.fileExtension = e.fileExtension;
189
+ const u = `${t}/${r}${c}`, p = a.encoding;
190
+ this.string = u, this.type = t, this.subtype = r, this.parameters = a, this.encoding = p, this.name = e.name, this.fileExtension = e.fileExtension;
525
191
  }
526
192
  static parse(e) {
527
193
  return new l(e);
@@ -843,6 +509,27 @@ class l {
843
509
  fileExtension: "json"
844
510
  });
845
511
  }
512
+ static get READIUM_CONTENT_DOCUMENT() {
513
+ return l.parse({
514
+ mediaType: "application/vnd.readium.content+json",
515
+ name: "Readium Content Document",
516
+ fileExtension: "json"
517
+ });
518
+ }
519
+ static get READIUM_GUIDED_NAVIGATION_DOCUMENT() {
520
+ return l.parse({
521
+ mediaType: "application/guided-navigation+json",
522
+ name: "Readium Guided Navigation Document",
523
+ fileExtension: "json"
524
+ });
525
+ }
526
+ static get READIUM_POSITION_LIST() {
527
+ return l.parse({
528
+ mediaType: "application/vnd.readium.position-list+json",
529
+ name: "Readium Position List",
530
+ fileExtension: "json"
531
+ });
532
+ }
846
533
  static get READIUM_WEBPUB() {
847
534
  return l.parse({
848
535
  mediaType: "application/webpub+zip",
@@ -929,7 +616,7 @@ class l {
929
616
  });
930
617
  }
931
618
  }
932
- class ke {
619
+ class Me {
933
620
  constructor(e) {
934
621
  this.uri = e, this.parameters = this.getParameters(e);
935
622
  }
@@ -957,22 +644,22 @@ class ke {
957
644
  return this.uri.replace(/\{(\??)([^}]+)\}/g, (...s) => s[1] ? r(s[2]) : t(s[2]));
958
645
  }
959
646
  }
960
- function ei(i) {
647
+ function Lt(i) {
961
648
  return i && i instanceof Array ? i : void 0;
962
649
  }
963
- function ht(i) {
964
- return i && typeof i == "string" ? [i] : ei(i);
650
+ function Qe(i) {
651
+ return i && typeof i == "string" ? [i] : Lt(i);
965
652
  }
966
- function Ue(i) {
653
+ function Re(i) {
967
654
  return typeof i == "string" ? new Date(i) : void 0;
968
655
  }
969
- function se(i) {
656
+ function re(i) {
970
657
  return isNaN(i) ? void 0 : i;
971
658
  }
972
- function P(i) {
973
- return se(i) !== void 0 && Math.sign(i) >= 0 ? i : void 0;
659
+ function O(i) {
660
+ return re(i) !== void 0 && Math.sign(i) >= 0 ? i : void 0;
974
661
  }
975
- function ti(i) {
662
+ function zt(i) {
976
663
  const e = new Array();
977
664
  return i.forEach((t) => e.push(t)), e;
978
665
  }
@@ -989,7 +676,7 @@ class w {
989
676
  static deserialize(e) {
990
677
  if (!e)
991
678
  return;
992
- const t = se(e.progression), r = se(e.totalProgression), s = se(e.position), n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set([
679
+ const t = re(e.progression), r = re(e.totalProgression), s = re(e.position), n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set([
993
680
  "fragment",
994
681
  "fragments",
995
682
  "progression",
@@ -999,7 +686,7 @@ class w {
999
686
  return Object.entries(e).forEach(([a, h]) => {
1000
687
  o.has(a) || n.set(a, h);
1001
688
  }), new w({
1002
- fragments: ht(e.fragments || e.fragment),
689
+ fragments: Qe(e.fragments || e.fragment),
1003
690
  progression: t !== void 0 && t >= 0 && t <= 1 ? t : void 0,
1004
691
  totalProgression: r !== void 0 && r >= 0 && r <= 1 ? r : void 0,
1005
692
  position: s !== void 0 && s > 0 ? s : void 0,
@@ -1099,11 +786,11 @@ class H {
1099
786
  title: e.title,
1100
787
  rels: e.rel ? e.rel instanceof Array ? new Set(e.rel) : /* @__PURE__ */ new Set([e.rel]) : void 0,
1101
788
  properties: b.deserialize(e.properties),
1102
- height: P(e.height),
1103
- width: P(e.width),
1104
- duration: P(e.duration),
1105
- bitrate: P(e.bitrate),
1106
- languages: ht(e.language),
789
+ height: O(e.height),
790
+ width: O(e.width),
791
+ duration: O(e.duration),
792
+ bitrate: O(e.bitrate),
793
+ languages: Qe(e.language),
1107
794
  alternates: ne.deserialize(e.alternate),
1108
795
  children: ne.deserialize(e.children)
1109
796
  });
@@ -1113,7 +800,7 @@ class H {
1113
800
  */
1114
801
  serialize() {
1115
802
  const e = { href: this.href };
1116
- return this.templated !== void 0 && (e.templated = this.templated), this.type !== void 0 && (e.type = this.type), this.title !== void 0 && (e.title = this.title), this.rels && (e.rel = ti(this.rels)), this.properties && (e.properties = this.properties.serialize()), this.height !== void 0 && (e.height = this.height), this.width !== void 0 && (e.width = this.width), this.duration !== void 0 && (e.duration = this.duration), this.bitrate !== void 0 && (e.bitrate = this.bitrate), this.languages && (e.language = this.languages), this.alternates && (e.alternate = this.alternates.serialize()), this.children && (e.children = this.children.serialize()), e;
803
+ return this.templated !== void 0 && (e.templated = this.templated), this.type !== void 0 && (e.type = this.type), this.title !== void 0 && (e.title = this.title), this.rels && (e.rel = zt(this.rels)), this.properties && (e.properties = this.properties.serialize()), this.height !== void 0 && (e.height = this.height), this.width !== void 0 && (e.width = this.width), this.duration !== void 0 && (e.duration = this.duration), this.bitrate !== void 0 && (e.bitrate = this.bitrate), this.languages && (e.language = this.languages), this.alternates && (e.alternate = this.alternates.serialize()), this.children && (e.children = this.children.serialize()), e;
1117
804
  }
1118
805
  /** MediaType of the linked resource. */
1119
806
  get mediaType() {
@@ -1131,14 +818,14 @@ class H {
1131
818
  }
1132
819
  /** List of URI template parameter keys, if the `Link` is templated. */
1133
820
  get templateParameters() {
1134
- return this.templated ? new ke(this.href).parameters : /* @__PURE__ */ new Set();
821
+ return this.templated ? new Me(this.href).parameters : /* @__PURE__ */ new Set();
1135
822
  }
1136
823
  /** Expands the `Link`'s HREF by replacing URI template variables by the given parameters.
1137
824
  * See RFC 6570 on URI template: https://tools.ietf.org/html/rfc6570
1138
825
  */
1139
826
  expandTemplate(e) {
1140
827
  return new H({
1141
- href: new ke(this.href).expand(e),
828
+ href: new Me(this.href).expand(e),
1142
829
  templated: !1
1143
830
  });
1144
831
  }
@@ -1272,11 +959,11 @@ class oe {
1272
959
  static deserialize(e) {
1273
960
  if (!(e && e.cssSelector))
1274
961
  return;
1275
- let t = P(e.textNodeIndex);
962
+ let t = O(e.textNodeIndex);
1276
963
  if (t === void 0)
1277
964
  return;
1278
- let r = P(e.charOffset);
1279
- return r === void 0 && (r = P(e.offset)), new oe({
965
+ let r = O(e.charOffset);
966
+ return r === void 0 && (r = O(e.offset)), new oe({
1280
967
  cssSelector: e.cssSelector,
1281
968
  textNodeIndex: t,
1282
969
  charOffset: r
@@ -1293,7 +980,7 @@ class oe {
1293
980
  return this.charOffset !== void 0 && (e.charOffset = this.charOffset), e;
1294
981
  }
1295
982
  }
1296
- class we {
983
+ class xe {
1297
984
  /**
1298
985
  * Creates a [DomRange].
1299
986
  */
@@ -1308,7 +995,7 @@ class we {
1308
995
  return;
1309
996
  let t = oe.deserialize(e.start);
1310
997
  if (t)
1311
- return new we({
998
+ return new xe({
1312
999
  start: t,
1313
1000
  end: oe.deserialize(e.end)
1314
1001
  });
@@ -1331,7 +1018,7 @@ w.prototype.getPartialCfi = function() {
1331
1018
  };
1332
1019
  w.prototype.getDomRange = function() {
1333
1020
  var i;
1334
- return we.deserialize((i = this.otherLocations) == null ? void 0 : i.get("domRange"));
1021
+ return xe.deserialize((i = this.otherLocations) == null ? void 0 : i.get("domRange"));
1335
1022
  };
1336
1023
  w.prototype.fragmentParameters = function() {
1337
1024
  return new Map(
@@ -1369,7 +1056,7 @@ w.prototype.space = function() {
1369
1056
  if (e.length === 4 && !e.some(isNaN))
1370
1057
  return e;
1371
1058
  };
1372
- class Te {
1059
+ class we {
1373
1060
  /** Creates a [Price]. */
1374
1061
  constructor(e) {
1375
1062
  this.currency = e.currency, this.value = e.value;
@@ -1383,9 +1070,9 @@ class Te {
1383
1070
  let t = e.currency;
1384
1071
  if (!(t && typeof t == "string" && t.length > 0))
1385
1072
  return;
1386
- let r = P(e.value);
1073
+ let r = O(e.value);
1387
1074
  if (r !== void 0)
1388
- return new Te({ currency: t, value: r });
1075
+ return new we({ currency: t, value: r });
1389
1076
  }
1390
1077
  /**
1391
1078
  * Serializes a [Price] to its RWPM JSON representation.
@@ -1421,7 +1108,7 @@ class j {
1421
1108
  return this.children && (e.children = this.children.map((t) => t.serialize())), e;
1422
1109
  }
1423
1110
  }
1424
- class Se {
1111
+ class Te {
1425
1112
  /** Creates a [Price]. */
1426
1113
  constructor(e) {
1427
1114
  this.total = e.total, this.position = e.position;
@@ -1431,9 +1118,9 @@ class Se {
1431
1118
  */
1432
1119
  static deserialize(e) {
1433
1120
  if (e)
1434
- return new Se({
1435
- total: P(e.total),
1436
- position: P(e.position)
1121
+ return new Te({
1122
+ total: O(e.total),
1123
+ position: O(e.position)
1437
1124
  });
1438
1125
  }
1439
1126
  /**
@@ -1444,7 +1131,7 @@ class Se {
1444
1131
  return this.total !== void 0 && (e.total = this.total), this.position !== void 0 && (e.position = this.position), e;
1445
1132
  }
1446
1133
  }
1447
- class Ce {
1134
+ class Se {
1448
1135
  /** Creates a [Copies]. */
1449
1136
  constructor(e) {
1450
1137
  this.total = e.total, this.available = e.available;
@@ -1454,9 +1141,9 @@ class Ce {
1454
1141
  */
1455
1142
  static deserialize(e) {
1456
1143
  if (e)
1457
- return new Ce({
1458
- total: P(e.total),
1459
- available: P(e.available)
1144
+ return new Se({
1145
+ total: O(e.total),
1146
+ available: O(e.available)
1460
1147
  });
1461
1148
  }
1462
1149
  /**
@@ -1467,7 +1154,7 @@ class Ce {
1467
1154
  return this.total !== void 0 && (e.total = this.total), this.available !== void 0 && (e.available = this.available), e;
1468
1155
  }
1469
1156
  }
1470
- class Pe {
1157
+ class Ce {
1471
1158
  /** Creates a [Availability]. */
1472
1159
  constructor(e) {
1473
1160
  this.state = e.state, this.since = e.since, this.until = e.until;
@@ -1477,10 +1164,10 @@ class Pe {
1477
1164
  */
1478
1165
  static deserialize(e) {
1479
1166
  if (e && e.state)
1480
- return new Pe({
1167
+ return new Ce({
1481
1168
  state: e.state,
1482
- since: Ue(e.since),
1483
- until: Ue(e.until)
1169
+ since: Re(e.since),
1170
+ until: Re(e.until)
1484
1171
  });
1485
1172
  }
1486
1173
  /**
@@ -1492,10 +1179,10 @@ class Pe {
1492
1179
  }
1493
1180
  }
1494
1181
  b.prototype.getNumberOfItems = function() {
1495
- return P(this.otherProperties.numberOfItems);
1182
+ return O(this.otherProperties.numberOfItems);
1496
1183
  };
1497
1184
  b.prototype.getPrice = function() {
1498
- return Te.deserialize(this.otherProperties.price);
1185
+ return we.deserialize(this.otherProperties.price);
1499
1186
  };
1500
1187
  b.prototype.getIndirectAcquisitions = function() {
1501
1188
  const i = this.otherProperties.indirectAcquisition;
@@ -1503,13 +1190,13 @@ b.prototype.getIndirectAcquisitions = function() {
1503
1190
  return i.map((e) => j.deserialize(e)).filter((e) => e !== void 0);
1504
1191
  };
1505
1192
  b.prototype.getHolds = function() {
1506
- return Se.deserialize(this.otherProperties.holds);
1193
+ return Te.deserialize(this.otherProperties.holds);
1507
1194
  };
1508
1195
  b.prototype.getCopies = function() {
1509
- return Ce.deserialize(this.otherProperties.copies);
1196
+ return Se.deserialize(this.otherProperties.copies);
1510
1197
  };
1511
1198
  b.prototype.getAvailability = function() {
1512
- return Pe.deserialize(this.otherProperties.availability);
1199
+ return Ce.deserialize(this.otherProperties.availability);
1513
1200
  };
1514
1201
  b.prototype.getAuthenticate = function() {
1515
1202
  return H.deserialize(this.otherProperties.authenticate);
@@ -1532,31 +1219,33 @@ b.prototype.getPage = function() {
1532
1219
  b.prototype.getSpread = function() {
1533
1220
  return this.otherProperties.spread || void 0;
1534
1221
  };
1535
- function $e(i) {
1222
+ class ce {
1223
+ }
1224
+ function Ne(i) {
1536
1225
  return i.split("").reverse().join("");
1537
1226
  }
1538
- function ii(i, e, t) {
1539
- const r = $e(e);
1227
+ function It(i, e, t) {
1228
+ const r = Ne(e);
1540
1229
  return t.map((s) => {
1541
- const n = Math.max(0, s.end - e.length - s.errors), o = $e(i.slice(n, s.end));
1230
+ const n = Math.max(0, s.end - e.length - s.errors), o = Ne(i.slice(n, s.end));
1542
1231
  return {
1543
- start: ct(o, r, s.errors).reduce((h, c) => s.end - c.end < h ? s.end - c.end : h, s.end),
1232
+ start: et(o, r, s.errors).reduce((h, c) => s.end - c.end < h ? s.end - c.end : h, s.end),
1544
1233
  end: s.end,
1545
1234
  errors: s.errors
1546
1235
  };
1547
1236
  });
1548
1237
  }
1549
- function pe(i) {
1238
+ function ue(i) {
1550
1239
  return (i | -i) >> 31 & 1;
1551
1240
  }
1552
- function He(i, e, t, r) {
1241
+ function Le(i, e, t, r) {
1553
1242
  let s = i.P[t], n = i.M[t];
1554
1243
  const o = r >>> 31, a = e[t] | o, h = a | n, c = (a & s) + s ^ s | a;
1555
- let d = n | ~(c | s), p = s & c;
1556
- const u = pe(d & i.lastRowMask[t]) - pe(p & i.lastRowMask[t]);
1557
- return d <<= 1, p <<= 1, p |= o, d |= pe(r) - o, s = p | ~(h | d), n = d & h, i.P[t] = s, i.M[t] = n, u;
1244
+ let u = n | ~(c | s), p = s & c;
1245
+ const d = ue(u & i.lastRowMask[t]) - ue(p & i.lastRowMask[t]);
1246
+ return u <<= 1, p <<= 1, p |= o, u |= ue(r) - o, s = p | ~(h | u), n = u & h, i.P[t] = s, i.M[t] = n, d;
1558
1247
  }
1559
- function ct(i, e, t) {
1248
+ function et(i, e, t) {
1560
1249
  if (e.length === 0)
1561
1250
  return [];
1562
1251
  t = Math.min(t, e.length);
@@ -1567,10 +1256,10 @@ function ct(i, e, t) {
1567
1256
  };
1568
1257
  o.lastRowMask.fill(1 << 31), o.lastRowMask[n] = 1 << (e.length - 1) % s;
1569
1258
  const a = new Uint32Array(n + 1), h = /* @__PURE__ */ new Map(), c = [];
1570
- for (let u = 0; u < 256; u++)
1259
+ for (let d = 0; d < 256; d++)
1571
1260
  c.push(a);
1572
- for (let u = 0; u < e.length; u += 1) {
1573
- const f = e.charCodeAt(u);
1261
+ for (let d = 0; d < e.length; d += 1) {
1262
+ const f = e.charCodeAt(d);
1574
1263
  if (h.has(f))
1575
1264
  continue;
1576
1265
  const v = new Uint32Array(n + 1);
@@ -1585,45 +1274,45 @@ function ct(i, e, t) {
1585
1274
  }
1586
1275
  }
1587
1276
  }
1588
- let d = Math.max(0, Math.ceil(t / s) - 1);
1277
+ let u = Math.max(0, Math.ceil(t / s) - 1);
1589
1278
  const p = new Uint32Array(n + 1);
1590
- for (let u = 0; u <= d; u += 1)
1591
- p[u] = (u + 1) * s;
1279
+ for (let d = 0; d <= u; d += 1)
1280
+ p[d] = (d + 1) * s;
1592
1281
  p[n] = e.length;
1593
- for (let u = 0; u <= d; u += 1)
1594
- o.P[u] = -1, o.M[u] = 0;
1595
- for (let u = 0; u < i.length; u += 1) {
1596
- const f = i.charCodeAt(u);
1282
+ for (let d = 0; d <= u; d += 1)
1283
+ o.P[d] = -1, o.M[d] = 0;
1284
+ for (let d = 0; d < i.length; d += 1) {
1285
+ const f = i.charCodeAt(d);
1597
1286
  let v;
1598
1287
  f < c.length ? v = c[f] : (v = h.get(f), typeof v > "u" && (v = a));
1599
1288
  let g = 0;
1600
- for (let y = 0; y <= d; y += 1)
1601
- g = He(o, v, y, g), p[y] += g;
1602
- if (p[d] - g <= t && d < n && (v[d + 1] & 1 || g < 0)) {
1603
- d += 1, o.P[d] = -1, o.M[d] = 0;
1289
+ for (let y = 0; y <= u; y += 1)
1290
+ g = Le(o, v, y, g), p[y] += g;
1291
+ if (p[u] - g <= t && u < n && (v[u + 1] & 1 || g < 0)) {
1292
+ u += 1, o.P[u] = -1, o.M[u] = 0;
1604
1293
  let y;
1605
- if (d === n) {
1294
+ if (u === n) {
1606
1295
  const x = e.length % s;
1607
1296
  y = x === 0 ? s : x;
1608
1297
  } else
1609
1298
  y = s;
1610
- p[d] = p[d - 1] + y - g + He(o, v, d, g);
1299
+ p[u] = p[u - 1] + y - g + Le(o, v, u, g);
1611
1300
  } else
1612
- for (; d > 0 && p[d] >= t + s; )
1613
- d -= 1;
1614
- d === n && p[d] <= t && (p[d] < t && r.splice(0, r.length), r.push({
1301
+ for (; u > 0 && p[u] >= t + s; )
1302
+ u -= 1;
1303
+ u === n && p[u] <= t && (p[u] < t && r.splice(0, r.length), r.push({
1615
1304
  start: -1,
1616
- end: u + 1,
1617
- errors: p[d]
1618
- }), t = p[d]);
1305
+ end: d + 1,
1306
+ errors: p[u]
1307
+ }), t = p[u]);
1619
1308
  }
1620
1309
  return r;
1621
1310
  }
1622
- function ri(i, e, t) {
1623
- const r = ct(i, e, t);
1624
- return ii(i, e, r);
1311
+ function Dt(i, e, t) {
1312
+ const r = et(i, e, t);
1313
+ return It(i, e, r);
1625
1314
  }
1626
- function dt(i, e, t) {
1315
+ function tt(i, e, t) {
1627
1316
  let r = 0;
1628
1317
  const s = [];
1629
1318
  for (; r !== -1; )
@@ -1632,31 +1321,31 @@ function dt(i, e, t) {
1632
1321
  end: r + e.length,
1633
1322
  errors: 0
1634
1323
  }), r += 1);
1635
- return s.length > 0 ? s : ri(i, e, t);
1324
+ return s.length > 0 ? s : Dt(i, e, t);
1636
1325
  }
1637
- function qe(i, e) {
1638
- return e.length === 0 || i.length === 0 ? 0 : 1 - dt(i, e, e.length)[0].errors / e.length;
1326
+ function ze(i, e) {
1327
+ return e.length === 0 || i.length === 0 ? 0 : 1 - tt(i, e, e.length)[0].errors / e.length;
1639
1328
  }
1640
- function si(i, e, t = {}) {
1329
+ function Bt(i, e, t = {}) {
1641
1330
  if (e.length === 0)
1642
1331
  return null;
1643
- const r = Math.min(256, e.length / 2), s = dt(i, e, r);
1332
+ const r = Math.min(256, e.length / 2), s = tt(i, e, r);
1644
1333
  if (s.length === 0)
1645
1334
  return null;
1646
1335
  const n = (a) => {
1647
- const u = 1 - a.errors / e.length, f = t.prefix ? qe(
1336
+ const d = 1 - a.errors / e.length, f = t.prefix ? ze(
1648
1337
  i.slice(
1649
1338
  Math.max(0, a.start - t.prefix.length),
1650
1339
  a.start
1651
1340
  ),
1652
1341
  t.prefix
1653
- ) : 1, v = t.suffix ? qe(
1342
+ ) : 1, v = t.suffix ? ze(
1654
1343
  i.slice(a.end, a.end + t.suffix.length),
1655
1344
  t.suffix
1656
1345
  ) : 1;
1657
1346
  let g = 1;
1658
1347
  typeof t.hint == "number" && (g = 1 - Math.abs(a.start - t.hint) / i.length);
1659
- const y = 50 * u + 20 * f + 20 * v + 2 * g, x = 50 + 20 + 20 + 2;
1348
+ const y = 50 * d + 20 * f + 20 * v + 2 * g, x = 50 + 20 + 20 + 2;
1660
1349
  return y / x;
1661
1350
  }, o = s.map((a) => ({
1662
1351
  start: a.start,
@@ -1665,7 +1354,7 @@ function si(i, e, t = {}) {
1665
1354
  }));
1666
1355
  return o.sort((a, h) => h.score - a.score), o[0];
1667
1356
  }
1668
- function ge(i, e, t) {
1357
+ function fe(i, e, t) {
1669
1358
  const r = t === 1 ? e : e - 1;
1670
1359
  if (i.charAt(r).trim() !== "")
1671
1360
  return e;
@@ -1675,7 +1364,7 @@ function ge(i, e, t) {
1675
1364
  const o = s.length - n.length;
1676
1365
  return t === 2 ? e - o : e + o;
1677
1366
  }
1678
- function Xe(i, e) {
1367
+ function Ie(i, e) {
1679
1368
  const t = i.commonAncestorContainer.ownerDocument.createNodeIterator(
1680
1369
  i.commonAncestorContainer,
1681
1370
  NodeFilter.SHOW_TEXT
@@ -1688,7 +1377,7 @@ function Xe(i, e) {
1688
1377
  const a = () => {
1689
1378
  if (n = e === 1 ? t.nextNode() : t.previousNode(), n) {
1690
1379
  const h = n.textContent, c = e === 1 ? 0 : h.length;
1691
- o = ge(h, c, e);
1380
+ o = fe(h, c, e);
1692
1381
  }
1693
1382
  };
1694
1383
  for (; n && o === -1 && n !== s; )
@@ -1697,7 +1386,7 @@ function Xe(i, e) {
1697
1386
  return { node: n, offset: o };
1698
1387
  throw new RangeError("No text nodes with non-whitespace text found in range");
1699
1388
  }
1700
- function ni(i) {
1389
+ function Wt(i) {
1701
1390
  if (!i.toString().trim().length)
1702
1391
  throw new RangeError("Range contains no non-whitespace text");
1703
1392
  if (i.startContainer.nodeType !== Node.TEXT_NODE)
@@ -1707,13 +1396,13 @@ function ni(i) {
1707
1396
  const e = i.cloneRange();
1708
1397
  let t = !1, r = !1;
1709
1398
  const s = {
1710
- start: ge(
1399
+ start: fe(
1711
1400
  i.startContainer.textContent,
1712
1401
  i.startOffset,
1713
1402
  1
1714
1403
  /* Forwards */
1715
1404
  ),
1716
- end: ge(
1405
+ end: fe(
1717
1406
  i.endContainer.textContent,
1718
1407
  i.endOffset,
1719
1408
  2
@@ -1723,7 +1412,7 @@ function ni(i) {
1723
1412
  if (s.start >= 0 && (e.setStart(i.startContainer, s.start), t = !0), s.end > 0 && (e.setEnd(i.endContainer, s.end), r = !0), t && r)
1724
1413
  return e;
1725
1414
  if (!t) {
1726
- const { node: n, offset: o } = Xe(
1415
+ const { node: n, offset: o } = Ie(
1727
1416
  e,
1728
1417
  1
1729
1418
  /* Forwards */
@@ -1731,7 +1420,7 @@ function ni(i) {
1731
1420
  n && o >= 0 && e.setStart(n, o);
1732
1421
  }
1733
1422
  if (!r) {
1734
- const { node: n, offset: o } = Xe(
1423
+ const { node: n, offset: o } = Ie(
1735
1424
  e,
1736
1425
  2
1737
1426
  /* Backwards */
@@ -1740,7 +1429,7 @@ function ni(i) {
1740
1429
  }
1741
1430
  return e;
1742
1431
  }
1743
- function ut(i) {
1432
+ function it(i) {
1744
1433
  var e;
1745
1434
  switch (i.nodeType) {
1746
1435
  case Node.ELEMENT_NODE:
@@ -1750,13 +1439,13 @@ function ut(i) {
1750
1439
  return 0;
1751
1440
  }
1752
1441
  }
1753
- function Ve(i) {
1442
+ function De(i) {
1754
1443
  let e = i.previousSibling, t = 0;
1755
1444
  for (; e; )
1756
- t += ut(e), e = e.previousSibling;
1445
+ t += it(e), e = e.previousSibling;
1757
1446
  return t;
1758
1447
  }
1759
- function pt(i, ...e) {
1448
+ function rt(i, ...e) {
1760
1449
  let t = e.shift();
1761
1450
  const r = i.ownerDocument.createNodeIterator(
1762
1451
  i,
@@ -1771,7 +1460,7 @@ function pt(i, ...e) {
1771
1460
  throw new RangeError("Offset exceeds text length");
1772
1461
  return s;
1773
1462
  }
1774
- class R {
1463
+ class N {
1775
1464
  constructor(e, t) {
1776
1465
  if (t < 0)
1777
1466
  throw new Error("Offset is invalid");
@@ -1788,8 +1477,8 @@ class R {
1788
1477
  throw new Error("Parent is not an ancestor of current element");
1789
1478
  let t = this.element, r = this.offset;
1790
1479
  for (; t !== e; )
1791
- r += Ve(t), t = t.parentElement;
1792
- return new R(t, r);
1480
+ r += De(t), t = t.parentElement;
1481
+ return new N(t, r);
1793
1482
  }
1794
1483
  /**
1795
1484
  * Resolve the position to a specific text node and offset within that node.
@@ -1810,7 +1499,7 @@ class R {
1810
1499
  */
1811
1500
  resolve(e = {}) {
1812
1501
  try {
1813
- return pt(this.element, this.offset)[0];
1502
+ return rt(this.element, this.offset)[0];
1814
1503
  } catch (t) {
1815
1504
  if (this.offset === 0 && e.direction !== void 0) {
1816
1505
  const r = document.createTreeWalker(
@@ -1833,9 +1522,9 @@ class R {
1833
1522
  static fromCharOffset(e, t) {
1834
1523
  switch (e.nodeType) {
1835
1524
  case Node.TEXT_NODE:
1836
- return R.fromPoint(e, t);
1525
+ return N.fromPoint(e, t);
1837
1526
  case Node.ELEMENT_NODE:
1838
- return new R(e, t);
1527
+ return new N(e, t);
1839
1528
  default:
1840
1529
  throw new Error("Node is not an element or text node");
1841
1530
  }
@@ -1853,16 +1542,16 @@ class R {
1853
1542
  throw new Error("Text node offset is out of range");
1854
1543
  if (!e.parentElement)
1855
1544
  throw new Error("Text node has no parent");
1856
- const r = Ve(e) + t;
1857
- return new R(e.parentElement, r);
1545
+ const r = De(e) + t;
1546
+ return new N(e.parentElement, r);
1858
1547
  }
1859
1548
  case Node.ELEMENT_NODE: {
1860
1549
  if (t < 0 || t > e.childNodes.length)
1861
1550
  throw new Error("Child node offset is out of range");
1862
1551
  let r = 0;
1863
1552
  for (let s = 0; s < t; s++)
1864
- r += ut(e.childNodes[s]);
1865
- return new R(e, r);
1553
+ r += it(e.childNodes[s]);
1554
+ return new N(e, r);
1866
1555
  }
1867
1556
  default:
1868
1557
  throw new Error("Point is not in an element or text node");
@@ -1895,7 +1584,7 @@ class z {
1895
1584
  */
1896
1585
  toRange() {
1897
1586
  let e, t;
1898
- this.start.element === this.end.element && this.start.offset <= this.end.offset ? [e, t] = pt(
1587
+ this.start.element === this.end.element && this.start.offset <= this.end.offset ? [e, t] = rt(
1899
1588
  this.start.element,
1900
1589
  this.start.offset,
1901
1590
  this.end.offset
@@ -1913,10 +1602,10 @@ class z {
1913
1602
  * Create a TextRange from a (DOM) Range
1914
1603
  */
1915
1604
  static fromRange(e) {
1916
- const t = R.fromPoint(
1605
+ const t = N.fromPoint(
1917
1606
  e.startContainer,
1918
1607
  e.startOffset
1919
- ), r = R.fromPoint(e.endContainer, e.endOffset);
1608
+ ), r = N.fromPoint(e.endContainer, e.endOffset);
1920
1609
  return new z(t, r);
1921
1610
  }
1922
1611
  /**
@@ -1925,8 +1614,8 @@ class z {
1925
1614
  */
1926
1615
  static fromOffsets(e, t, r) {
1927
1616
  return new z(
1928
- new R(e, t),
1929
- new R(e, r)
1617
+ new N(e, t),
1618
+ new N(e, r)
1930
1619
  );
1931
1620
  }
1932
1621
  /**
@@ -1934,7 +1623,7 @@ class z {
1934
1623
  * whitespace
1935
1624
  */
1936
1625
  static trimmedRange(e) {
1937
- return ni(z.fromRange(e).toRange());
1626
+ return Wt(z.fromRange(e).toRange());
1938
1627
  }
1939
1628
  }
1940
1629
  class ae {
@@ -1998,7 +1687,7 @@ class le {
1998
1687
  return this.toPositionAnchor(e).toRange();
1999
1688
  }
2000
1689
  toPositionAnchor(e = {}) {
2001
- const t = this.root.textContent, r = si(t, this.exact, {
1690
+ const t = this.root.textContent, r = Bt(t, this.exact, {
2002
1691
  ...this.context,
2003
1692
  hint: e.hint
2004
1693
  });
@@ -2007,1087 +1696,1458 @@ class le {
2007
1696
  return new ae(this.root, r.start, r.end);
2008
1697
  }
2009
1698
  }
1699
+ function Ft(i) {
1700
+ const e = i.tagName.toUpperCase();
1701
+ return e === "IMG" || e === "VIDEO" || e === "AUDIO" || e === "IFRAME" || e === "OBJECT" || e === "EMBED" || e === "CANVAS";
1702
+ }
2010
1703
  function Oe(i, e) {
2011
1704
  try {
2012
- let r = e.locations, s = e.text;
2013
- if (s && s.highlight) {
2014
- let n;
2015
- r && r.getCssSelector() && (n = i.querySelector(r.getCssSelector())), n || (n = i.body);
2016
- let o = new le(n, s.highlight, {
2017
- prefix: s.before,
2018
- suffix: s.after
1705
+ const t = e.locations, r = e.text;
1706
+ if (r && r.highlight) {
1707
+ let s;
1708
+ t && t.getCssSelector() && (s = i.querySelector(t.getCssSelector())), s || (s = i.body);
1709
+ const n = new le(s, r.highlight, {
1710
+ prefix: r.before,
1711
+ suffix: r.after
2019
1712
  });
2020
1713
  try {
2021
- return o.toRange();
1714
+ return n.toRange();
2022
1715
  } catch {
2023
- return console.warn("Quote not found:", o), null;
1716
+ return console.warn("Quote not found:", n), null;
2024
1717
  }
2025
1718
  }
2026
- if (r) {
2027
- var t = null;
2028
- if (!t && r.getCssSelector() && (t = i.querySelector(r.getCssSelector())), !t && r.fragments) {
2029
- for (const n of r.fragments)
2030
- if (t = i.getElementById(n), t)
1719
+ if (t) {
1720
+ let s = null;
1721
+ if (!s && t.getCssSelector() && (s = i.querySelector(t.getCssSelector())), !s && t.fragments) {
1722
+ for (const n of t.fragments)
1723
+ if (s = i.getElementById(n), s)
2031
1724
  break;
2032
1725
  }
2033
- if (t) {
2034
- let n = i.createRange();
2035
- return t.childNodes.length === 0 ? (n.selectNodeContents(t), n) : (n.setStartBefore(t), n.setEndAfter(t), n);
1726
+ if (s) {
1727
+ const n = i.createRange();
1728
+ return s.childNodes.length === 0 || Ft(s) ? (n.selectNode(s), n) : (n.setStartBefore(s), n.setEndAfter(s), n);
2036
1729
  }
2037
1730
  }
2038
- } catch (r) {
2039
- console.error(r);
1731
+ } catch (t) {
1732
+ console.error(t);
2040
1733
  }
2041
1734
  return null;
2042
1735
  }
2043
- function T(i) {
2044
- const e = i.getSelection();
2045
- e && e.removeAllRanges();
1736
+ function kt(i, e) {
1737
+ let t = i.getClientRects();
1738
+ t.length || i.commonAncestorContainer.nodeType === Node.ELEMENT_NODE && (t = i.commonAncestorContainer.getClientRects());
1739
+ const r = 1, s = [];
1740
+ for (const c of t)
1741
+ s.push({
1742
+ bottom: c.bottom,
1743
+ height: c.height,
1744
+ left: c.left,
1745
+ right: c.right,
1746
+ top: c.top,
1747
+ width: c.width
1748
+ });
1749
+ const n = st(
1750
+ s,
1751
+ r,
1752
+ e
1753
+ ), o = Ht(n, r), a = nt(o), h = 2 * 2;
1754
+ for (let c = a.length - 1; c >= 0; c--) {
1755
+ const u = a[c];
1756
+ if (!(u.width * u.height > h))
1757
+ if (a.length > 1)
1758
+ a.splice(c, 1);
1759
+ else
1760
+ break;
1761
+ }
1762
+ return a;
2046
1763
  }
2047
- const oi = [
2048
- "a",
2049
- "audio",
2050
- "button",
2051
- "canvas",
2052
- "details",
2053
- "input",
2054
- "label",
2055
- "option",
2056
- "select",
2057
- "submit",
2058
- "textarea",
2059
- "video"
2060
- ];
2061
- function ft(i) {
2062
- var e;
2063
- return oi.indexOf(i.nodeName.toLowerCase()) !== -1 || i.hasAttribute("contenteditable") && ((e = i.getAttribute("contenteditable")) == null ? void 0 : e.toLowerCase()) !== "false" ? i : i.parentElement ? ft(i.parentElement) : null;
1764
+ function st(i, e, t) {
1765
+ for (let r = 0; r < i.length; r++)
1766
+ for (let s = r + 1; s < i.length; s++) {
1767
+ const n = i[r], o = i[s];
1768
+ if (n === o)
1769
+ continue;
1770
+ const a = A(n.top, o.top, e) && A(n.bottom, o.bottom, e), h = A(n.left, o.left, e) && A(n.right, o.right, e);
1771
+ if ((h && !t || a && !h) && ot(n, o, e)) {
1772
+ const d = i.filter((v) => v !== n && v !== o), f = Ut(n, o);
1773
+ return d.push(f), st(
1774
+ d,
1775
+ e,
1776
+ t
1777
+ );
1778
+ }
1779
+ }
1780
+ return i;
2064
1781
  }
2065
- function mt(i, e) {
2066
- const t = gt(i, i.document.body, e);
2067
- return new I({
2068
- href: "#",
2069
- type: "application/xhtml+xml",
2070
- locations: new w({
2071
- otherLocations: /* @__PURE__ */ new Map([
2072
- ["cssSelector", i._readium_cssSelectorGenerator.getCssSelector(t)]
2073
- ])
2074
- }),
2075
- text: new q({
2076
- highlight: t.textContent || void 0
2077
- })
2078
- });
1782
+ function Ut(i, e) {
1783
+ const t = Math.min(i.left, e.left), r = Math.max(i.right, e.right), s = Math.min(i.top, e.top), n = Math.max(i.bottom, e.bottom);
1784
+ return {
1785
+ bottom: n,
1786
+ height: n - s,
1787
+ left: t,
1788
+ right: r,
1789
+ top: s,
1790
+ width: r - t
1791
+ };
2079
1792
  }
2080
- function gt(i, e, t) {
2081
- for (var r = 0; r < e.children.length; r++) {
2082
- const s = e.children[r];
2083
- if (!li(s) && ai(i, s, t))
2084
- return gt(i, s, t);
1793
+ function Ht(i, e) {
1794
+ const t = new Set(i);
1795
+ for (const r of i) {
1796
+ if (!(r.width > 1 && r.height > 1)) {
1797
+ t.delete(r);
1798
+ continue;
1799
+ }
1800
+ for (const n of i)
1801
+ if (r !== n && t.has(n) && $t(n, r, e)) {
1802
+ t.delete(r);
1803
+ break;
1804
+ }
2085
1805
  }
2086
- return e;
1806
+ return Array.from(t);
2087
1807
  }
2088
- function ai(i, e, t) {
2089
- if (e === document.body || e === document.documentElement)
2090
- return !0;
2091
- if (!document || !document.documentElement || !document.body)
2092
- return !1;
2093
- const r = e.getBoundingClientRect();
2094
- return t ? r.bottom > 0 && r.top < i.innerHeight : r.right > 0 && r.left < i.innerWidth;
1808
+ function $t(i, e, t) {
1809
+ return Q(i, e.left, e.top, t) && Q(i, e.right, e.top, t) && Q(i, e.left, e.bottom, t) && Q(i, e.right, e.bottom, t);
2095
1810
  }
2096
- function li(i) {
2097
- const e = getComputedStyle(i);
2098
- return !!(e && (e.getPropertyValue("display") != "block" || e.getPropertyValue("opacity") === "0"));
1811
+ function Q(i, e, t, r) {
1812
+ return (i.left < e || A(i.left, e, r)) && (i.right > e || A(i.right, e, r)) && (i.top < t || A(i.top, t, r)) && (i.bottom > t || A(i.bottom, t, r));
2099
1813
  }
2100
- const _e = "readium-column-snapper-style", hi = 200, vt = class C extends at {
2101
- constructor() {
2102
- super(...arguments), this.shakeTimeout = 0, this.snappingCancelled = !1, this.alreadyScrollLeft = 0, this.overscroll = 0, this.cachedScrollWidth = 0, this.touchState = 0, this.startingX = void 0, this.endingX = void 0, this.onTouchStarter = this.onTouchStart.bind(this), this.onTouchEnder = this.onTouchEnd.bind(this), this.onWidthChanger = this.onWidthChange.bind(this), this.onTouchMover = this.onTouchMove.bind(this);
2103
- }
2104
- doc() {
2105
- return this.wnd.document.scrollingElement;
2106
- }
2107
- scrollOffset() {
2108
- return this.doc().scrollLeft > 0 ? this.doc().scrollLeft : this.alreadyScrollLeft;
2109
- }
2110
- snapOffset(e) {
2111
- const t = e + (W(this.wnd) ? -1 : 1);
2112
- return t - t % this.wnd.innerWidth;
1814
+ function nt(i) {
1815
+ for (let e = 0; e < i.length; e++)
1816
+ for (let t = e + 1; t < i.length; t++) {
1817
+ const r = i[e], s = i[t];
1818
+ if (r !== s && ot(r, s, -1)) {
1819
+ let n = [], o;
1820
+ const a = Be(r, s);
1821
+ if (a.length === 1)
1822
+ n = a, o = r;
1823
+ else {
1824
+ const c = Be(s, r);
1825
+ a.length < c.length ? (n = a, o = r) : (n = c, o = s);
1826
+ }
1827
+ const h = i.filter((c) => c !== o);
1828
+ return Array.prototype.push.apply(h, n), nt(h);
1829
+ }
1830
+ }
1831
+ return i;
1832
+ }
1833
+ function Be(i, e) {
1834
+ const t = qt(e, i);
1835
+ if (t.height === 0 || t.width === 0)
1836
+ return [i];
1837
+ const r = [];
1838
+ {
1839
+ const s = {
1840
+ bottom: i.bottom,
1841
+ height: 0,
1842
+ left: i.left,
1843
+ right: t.left,
1844
+ top: i.top,
1845
+ width: 0
1846
+ };
1847
+ s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && r.push(s);
2113
1848
  }
2114
- reportProgress() {
2115
- this.comms.send("progress", this.wnd.scrollX / this.cachedScrollWidth);
1849
+ {
1850
+ const s = {
1851
+ bottom: t.top,
1852
+ height: 0,
1853
+ left: t.left,
1854
+ right: t.right,
1855
+ top: i.top,
1856
+ width: 0
1857
+ };
1858
+ s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && r.push(s);
2116
1859
  }
2117
- shake() {
2118
- if (this.overscroll !== 0 || this.shakeTimeout !== 0)
2119
- return;
2120
- const e = this.doc();
2121
- e.classList.add(W(this.wnd) ? "readium-bounce-l" : "readium-bounce-r");
2122
- const t = this.scrollOffset();
2123
- this.shakeTimeout = this.wnd.setTimeout(() => {
2124
- e.classList.remove("readium-bounce-l"), e.classList.remove("readium-bounce-r"), this.shakeTimeout = 0, this.doc().scrollLeft = t;
2125
- }, 150);
1860
+ {
1861
+ const s = {
1862
+ bottom: i.bottom,
1863
+ height: 0,
1864
+ left: t.left,
1865
+ right: t.right,
1866
+ top: t.bottom,
1867
+ width: 0
1868
+ };
1869
+ s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && r.push(s);
2126
1870
  }
2127
- // We have to cache this because during overscroll (transform, or left) the width is incorrect due to browser
2128
- takeOverSnap() {
2129
- var t;
2130
- this.snappingCancelled = !0, this.clearTouches();
2131
- const e = this.doc();
2132
- this.overscroll = ((t = e.style.transform) == null ? void 0 : t.length) > 12 ? parseFloat(e.style.transform.slice(12).split("px")[0]) : 0;
1871
+ {
1872
+ const s = {
1873
+ bottom: i.bottom,
1874
+ height: 0,
1875
+ left: t.right,
1876
+ right: i.right,
1877
+ top: i.top,
1878
+ width: 0
1879
+ };
1880
+ s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && r.push(s);
2133
1881
  }
2134
- // Snaps the current offset to the page width.
2135
- snapCurrentOffset(e = !1, t = !1) {
2136
- const r = this.wnd.scrollX > 0 ? this.wnd.scrollX : this.alreadyScrollLeft, s = this.doc(), n = this.dragOffset(), o = lt(this.wnd), a = Math.min(Math.max(0, r), this.cachedScrollWidth), h = W(this.wnd) ? -1 : 1, c = (
2137
- // The hurdle to overcome in order to change pages
2138
- h * (this.wnd.innerWidth / 3) * (h * n > 0 ? 2 : 1)
2139
- ), d = this.snapOffset(a + c);
2140
- if (e && d !== this.scrollOffset()) {
2141
- this.snappingCancelled = !1;
2142
- const p = (g, y, x, S) => x > S ? y : g + (y - g) * Qt(x / S), u = (
2143
- /*Math.abs(startX - (this.useTransform ? currentOffset : 0)) < 10 ? 1 : */
2144
- hi * o
2145
- );
2146
- let f;
2147
- const v = (g) => {
2148
- if (this.snappingCancelled)
2149
- return;
2150
- f || (f = g);
2151
- const y = g - f, x = p(this.overscroll, 0, y, u), S = p(r, d, y, u);
2152
- s.scrollLeft = S, this.overscroll !== 0 && (s.style.transform = `translate3d(${-x}px, 0px, 0px)`), y < u ? this.wnd.requestAnimationFrame(v) : (this.clearTouches(), s.style.removeProperty("transform"), s.scrollLeft = d, t || this.reportProgress());
2153
- };
2154
- this.wnd.requestAnimationFrame(v);
2155
- } else
2156
- s.style.removeProperty("transform"), this.wnd.requestAnimationFrame(() => {
2157
- s.scrollLeft = d, this.clearTouches(), t || this.reportProgress();
2158
- });
1882
+ return r;
1883
+ }
1884
+ function qt(i, e) {
1885
+ const t = Math.max(i.left, e.left), r = Math.min(i.right, e.right), s = Math.max(i.top, e.top), n = Math.min(i.bottom, e.bottom);
1886
+ return {
1887
+ bottom: n,
1888
+ height: Math.max(0, n - s),
1889
+ left: t,
1890
+ right: r,
1891
+ top: s,
1892
+ width: Math.max(0, r - t)
1893
+ };
1894
+ }
1895
+ function ot(i, e, t) {
1896
+ return (i.left < e.right || t >= 0 && A(i.left, e.right, t)) && (e.left < i.right || t >= 0 && A(e.left, i.right, t)) && (i.top < e.bottom || t >= 0 && A(i.top, e.bottom, t)) && (e.top < i.bottom || t >= 0 && A(e.top, i.bottom, t));
1897
+ }
1898
+ function A(i, e, t) {
1899
+ return Math.abs(i - e) <= t;
1900
+ }
1901
+ var F = [], _t = function() {
1902
+ return F.some(function(i) {
1903
+ return i.activeTargets.length > 0;
1904
+ });
1905
+ }, Vt = function() {
1906
+ return F.some(function(i) {
1907
+ return i.skippedTargets.length > 0;
1908
+ });
1909
+ }, We = "ResizeObserver loop completed with undelivered notifications.", jt = function() {
1910
+ var i;
1911
+ typeof ErrorEvent == "function" ? i = new ErrorEvent("error", {
1912
+ message: We
1913
+ }) : (i = document.createEvent("Event"), i.initEvent("error", !1, !1), i.message = We), window.dispatchEvent(i);
1914
+ }, G;
1915
+ (function(i) {
1916
+ i.BORDER_BOX = "border-box", i.CONTENT_BOX = "content-box", i.DEVICE_PIXEL_CONTENT_BOX = "device-pixel-content-box";
1917
+ })(G || (G = {}));
1918
+ var k = function(i) {
1919
+ return Object.freeze(i);
1920
+ }, Xt = function() {
1921
+ function i(e, t) {
1922
+ this.inlineSize = e, this.blockSize = t, k(this);
2159
1923
  }
2160
- dragOffset() {
2161
- return (this.startingX ?? 0) - (this.endingX ?? 0);
1924
+ return i;
1925
+ }(), at = function() {
1926
+ function i(e, t, r, s) {
1927
+ return this.x = e, this.y = t, this.width = r, this.height = s, this.top = this.y, this.left = this.x, this.bottom = this.top + this.height, this.right = this.left + this.width, k(this);
2162
1928
  }
2163
- clearTouches() {
2164
- this.startingX = void 0, this.endingX = void 0, this.overscroll = 0;
1929
+ return i.prototype.toJSON = function() {
1930
+ var e = this, t = e.x, r = e.y, s = e.top, n = e.right, o = e.bottom, a = e.left, h = e.width, c = e.height;
1931
+ return { x: t, y: r, top: s, right: n, bottom: o, left: a, width: h, height: c };
1932
+ }, i.fromRect = function(e) {
1933
+ return new i(e.x, e.y, e.width, e.height);
1934
+ }, i;
1935
+ }(), Pe = function(i) {
1936
+ return i instanceof SVGElement && "getBBox" in i;
1937
+ }, lt = function(i) {
1938
+ if (Pe(i)) {
1939
+ var e = i.getBBox(), t = e.width, r = e.height;
1940
+ return !t && !r;
2165
1941
  }
2166
- onTouchStart(e) {
2167
- switch (e.stopPropagation(), this.takeOverSnap(), e.touches.length) {
2168
- case 1:
1942
+ var s = i, n = s.offsetWidth, o = s.offsetHeight;
1943
+ return !(n || o || i.getClientRects().length);
1944
+ }, Fe = function(i) {
1945
+ var e;
1946
+ if (i instanceof Element)
1947
+ return !0;
1948
+ var t = (e = i == null ? void 0 : i.ownerDocument) === null || e === void 0 ? void 0 : e.defaultView;
1949
+ return !!(t && i instanceof t.Element);
1950
+ }, Gt = function(i) {
1951
+ switch (i.tagName) {
1952
+ case "INPUT":
1953
+ if (i.type !== "image")
2169
1954
  break;
2170
- case 2:
2171
- this.onTouchEnd(e);
2172
- return;
2173
- default: {
2174
- this.onTouchEnd(e), this.comms.send("tap_more", e.touches.length);
2175
- return;
1955
+ case "VIDEO":
1956
+ case "AUDIO":
1957
+ case "EMBED":
1958
+ case "OBJECT":
1959
+ case "CANVAS":
1960
+ case "IFRAME":
1961
+ case "IMG":
1962
+ return !0;
1963
+ }
1964
+ return !1;
1965
+ }, X = typeof window < "u" ? window : {}, ee = /* @__PURE__ */ new WeakMap(), ke = /auto|scroll/, Yt = /^tb|vertical/, Zt = /msie|trident/i.test(X.navigator && X.navigator.userAgent), R = function(i) {
1966
+ return parseFloat(i || "0");
1967
+ }, $ = function(i, e, t) {
1968
+ return i === void 0 && (i = 0), e === void 0 && (e = 0), t === void 0 && (t = !1), new Xt((t ? e : i) || 0, (t ? i : e) || 0);
1969
+ }, Ue = k({
1970
+ devicePixelContentBoxSize: $(),
1971
+ borderBoxSize: $(),
1972
+ contentBoxSize: $(),
1973
+ contentRect: new at(0, 0, 0, 0)
1974
+ }), ht = function(i, e) {
1975
+ if (e === void 0 && (e = !1), ee.has(i) && !e)
1976
+ return ee.get(i);
1977
+ if (lt(i))
1978
+ return ee.set(i, Ue), Ue;
1979
+ var t = getComputedStyle(i), r = Pe(i) && i.ownerSVGElement && i.getBBox(), s = !Zt && t.boxSizing === "border-box", n = Yt.test(t.writingMode || ""), o = !r && ke.test(t.overflowY || ""), a = !r && ke.test(t.overflowX || ""), h = r ? 0 : R(t.paddingTop), c = r ? 0 : R(t.paddingRight), u = r ? 0 : R(t.paddingBottom), p = r ? 0 : R(t.paddingLeft), d = r ? 0 : R(t.borderTopWidth), f = r ? 0 : R(t.borderRightWidth), v = r ? 0 : R(t.borderBottomWidth), g = r ? 0 : R(t.borderLeftWidth), y = p + c, x = h + u, S = g + f, m = d + v, E = a ? i.offsetHeight - m - i.clientHeight : 0, P = o ? i.offsetWidth - S - i.clientWidth : 0, Y = s ? y + S : 0, Z = s ? x + m : 0, D = r ? r.width : R(t.width) - Y - P, B = r ? r.height : R(t.height) - Z - E, J = D + y + P + S, K = B + x + E + m, U = k({
1980
+ devicePixelContentBoxSize: $(Math.round(D * devicePixelRatio), Math.round(B * devicePixelRatio), n),
1981
+ borderBoxSize: $(J, K, n),
1982
+ contentBoxSize: $(D, B, n),
1983
+ contentRect: new at(p, h, D, B)
1984
+ });
1985
+ return ee.set(i, U), U;
1986
+ }, ct = function(i, e, t) {
1987
+ var r = ht(i, t), s = r.borderBoxSize, n = r.contentBoxSize, o = r.devicePixelContentBoxSize;
1988
+ switch (e) {
1989
+ case G.DEVICE_PIXEL_CONTENT_BOX:
1990
+ return o;
1991
+ case G.BORDER_BOX:
1992
+ return s;
1993
+ default:
1994
+ return n;
1995
+ }
1996
+ }, Jt = function() {
1997
+ function i(e) {
1998
+ var t = ht(e);
1999
+ this.target = e, this.contentRect = t.contentRect, this.borderBoxSize = k([t.borderBoxSize]), this.contentBoxSize = k([t.contentBoxSize]), this.devicePixelContentBoxSize = k([t.devicePixelContentBoxSize]);
2000
+ }
2001
+ return i;
2002
+ }(), ut = function(i) {
2003
+ if (lt(i))
2004
+ return 1 / 0;
2005
+ for (var e = 0, t = i.parentNode; t; )
2006
+ e += 1, t = t.parentNode;
2007
+ return e;
2008
+ }, Kt = function() {
2009
+ var i = 1 / 0, e = [];
2010
+ F.forEach(function(o) {
2011
+ if (o.activeTargets.length !== 0) {
2012
+ var a = [];
2013
+ o.activeTargets.forEach(function(c) {
2014
+ var u = new Jt(c.target), p = ut(c.target);
2015
+ a.push(u), c.lastReportedSize = ct(c.target, c.observedBox), p < i && (i = p);
2016
+ }), e.push(function() {
2017
+ o.callback.call(o.observer, a, o.observer);
2018
+ }), o.activeTargets.splice(0, o.activeTargets.length);
2019
+ }
2020
+ });
2021
+ for (var t = 0, r = e; t < r.length; t++) {
2022
+ var s = r[t];
2023
+ s();
2024
+ }
2025
+ return i;
2026
+ }, He = function(i) {
2027
+ F.forEach(function(t) {
2028
+ t.activeTargets.splice(0, t.activeTargets.length), t.skippedTargets.splice(0, t.skippedTargets.length), t.observationTargets.forEach(function(s) {
2029
+ s.isActive() && (ut(s.target) > i ? t.activeTargets.push(s) : t.skippedTargets.push(s));
2030
+ });
2031
+ });
2032
+ }, Qt = function() {
2033
+ var i = 0;
2034
+ for (He(i); _t(); )
2035
+ i = Kt(), He(i);
2036
+ return Vt() && jt(), i > 0;
2037
+ }, de, dt = [], ei = function() {
2038
+ return dt.splice(0).forEach(function(i) {
2039
+ return i();
2040
+ });
2041
+ }, ti = function(i) {
2042
+ if (!de) {
2043
+ var e = 0, t = document.createTextNode(""), r = { characterData: !0 };
2044
+ new MutationObserver(function() {
2045
+ return ei();
2046
+ }).observe(t, r), de = function() {
2047
+ t.textContent = "".concat(e ? e-- : e++);
2048
+ };
2049
+ }
2050
+ dt.push(i), de();
2051
+ }, ii = function(i) {
2052
+ ti(function() {
2053
+ requestAnimationFrame(i);
2054
+ });
2055
+ }, se = 0, ri = function() {
2056
+ return !!se;
2057
+ }, si = 250, ni = { attributes: !0, characterData: !0, childList: !0, subtree: !0 }, $e = [
2058
+ "resize",
2059
+ "load",
2060
+ "transitionend",
2061
+ "animationend",
2062
+ "animationstart",
2063
+ "animationiteration",
2064
+ "keyup",
2065
+ "keydown",
2066
+ "mouseup",
2067
+ "mousedown",
2068
+ "mouseover",
2069
+ "mouseout",
2070
+ "blur",
2071
+ "focus"
2072
+ ], qe = function(i) {
2073
+ return i === void 0 && (i = 0), Date.now() + i;
2074
+ }, pe = !1, oi = function() {
2075
+ function i() {
2076
+ var e = this;
2077
+ this.stopped = !0, this.listener = function() {
2078
+ return e.schedule();
2079
+ };
2080
+ }
2081
+ return i.prototype.run = function(e) {
2082
+ var t = this;
2083
+ if (e === void 0 && (e = si), !pe) {
2084
+ pe = !0;
2085
+ var r = qe(e);
2086
+ ii(function() {
2087
+ var s = !1;
2088
+ try {
2089
+ s = Qt();
2090
+ } finally {
2091
+ if (pe = !1, e = r - qe(), !ri())
2092
+ return;
2093
+ s ? t.run(1e3) : e > 0 ? t.run(e) : t.start();
2094
+ }
2095
+ });
2096
+ }
2097
+ }, i.prototype.schedule = function() {
2098
+ this.stop(), this.run();
2099
+ }, i.prototype.observe = function() {
2100
+ var e = this, t = function() {
2101
+ return e.observer && e.observer.observe(document.body, ni);
2102
+ };
2103
+ document.body ? t() : X.addEventListener("DOMContentLoaded", t);
2104
+ }, i.prototype.start = function() {
2105
+ var e = this;
2106
+ this.stopped && (this.stopped = !1, this.observer = new MutationObserver(this.listener), this.observe(), $e.forEach(function(t) {
2107
+ return X.addEventListener(t, e.listener, !0);
2108
+ }));
2109
+ }, i.prototype.stop = function() {
2110
+ var e = this;
2111
+ this.stopped || (this.observer && this.observer.disconnect(), $e.forEach(function(t) {
2112
+ return X.removeEventListener(t, e.listener, !0);
2113
+ }), this.stopped = !0);
2114
+ }, i;
2115
+ }(), me = new oi(), _e = function(i) {
2116
+ !se && i > 0 && me.start(), se += i, !se && me.stop();
2117
+ }, ai = function(i) {
2118
+ return !Pe(i) && !Gt(i) && getComputedStyle(i).display === "inline";
2119
+ }, li = function() {
2120
+ function i(e, t) {
2121
+ this.target = e, this.observedBox = t || G.CONTENT_BOX, this.lastReportedSize = {
2122
+ inlineSize: 0,
2123
+ blockSize: 0
2124
+ };
2125
+ }
2126
+ return i.prototype.isActive = function() {
2127
+ var e = ct(this.target, this.observedBox, !0);
2128
+ return ai(this.target) && (this.lastReportedSize = e), this.lastReportedSize.inlineSize !== e.inlineSize || this.lastReportedSize.blockSize !== e.blockSize;
2129
+ }, i;
2130
+ }(), hi = function() {
2131
+ function i(e, t) {
2132
+ this.activeTargets = [], this.skippedTargets = [], this.observationTargets = [], this.observer = e, this.callback = t;
2133
+ }
2134
+ return i;
2135
+ }(), te = /* @__PURE__ */ new WeakMap(), Ve = function(i, e) {
2136
+ for (var t = 0; t < i.length; t += 1)
2137
+ if (i[t].target === e)
2138
+ return t;
2139
+ return -1;
2140
+ }, ie = function() {
2141
+ function i() {
2142
+ }
2143
+ return i.connect = function(e, t) {
2144
+ var r = new hi(e, t);
2145
+ te.set(e, r);
2146
+ }, i.observe = function(e, t, r) {
2147
+ var s = te.get(e), n = s.observationTargets.length === 0;
2148
+ Ve(s.observationTargets, t) < 0 && (n && F.push(s), s.observationTargets.push(new li(t, r && r.box)), _e(1), me.schedule());
2149
+ }, i.unobserve = function(e, t) {
2150
+ var r = te.get(e), s = Ve(r.observationTargets, t), n = r.observationTargets.length === 1;
2151
+ s >= 0 && (n && F.splice(F.indexOf(r), 1), r.observationTargets.splice(s, 1), _e(-1));
2152
+ }, i.disconnect = function(e) {
2153
+ var t = this, r = te.get(e);
2154
+ r.observationTargets.slice().forEach(function(s) {
2155
+ return t.unobserve(e, s.target);
2156
+ }), r.activeTargets.splice(0, r.activeTargets.length);
2157
+ }, i;
2158
+ }(), pt = function() {
2159
+ function i(e) {
2160
+ if (arguments.length === 0)
2161
+ throw new TypeError("Failed to construct 'ResizeObserver': 1 argument required, but only 0 present.");
2162
+ if (typeof e != "function")
2163
+ throw new TypeError("Failed to construct 'ResizeObserver': The callback provided as parameter 1 is not a function.");
2164
+ ie.connect(this, e);
2165
+ }
2166
+ return i.prototype.observe = function(e, t) {
2167
+ if (arguments.length === 0)
2168
+ throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': 1 argument required, but only 0 present.");
2169
+ if (!Fe(e))
2170
+ throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element");
2171
+ ie.observe(this, e, t);
2172
+ }, i.prototype.unobserve = function(e) {
2173
+ if (arguments.length === 0)
2174
+ throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': 1 argument required, but only 0 present.");
2175
+ if (!Fe(e))
2176
+ throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': parameter 1 is not of type 'Element");
2177
+ ie.unobserve(this, e);
2178
+ }, i.prototype.disconnect = function() {
2179
+ ie.disconnect(this);
2180
+ }, i.toString = function() {
2181
+ return "function ResizeObserver () { [polyfill code] }";
2182
+ }, i;
2183
+ }();
2184
+ function ci(i, e) {
2185
+ return i.document.documentElement.style.getPropertyValue(e);
2186
+ }
2187
+ function ge(i, e, t) {
2188
+ i.document.documentElement.style.setProperty(e, t);
2189
+ }
2190
+ function ft(i, e) {
2191
+ i.document.documentElement.style.removeProperty(e);
2192
+ }
2193
+ const ui = window.ResizeObserver || pt;
2194
+ var di = /* @__PURE__ */ ((i) => (i.Wrap = "wrap", i.Viewport = "viewport", i.Bounds = "bounds", i.Page = "page", i))(di || {}), pi = /* @__PURE__ */ ((i) => (i.Boxes = "boxes", i.Bounds = "bounds", i))(pi || {});
2195
+ const fi = "Highlight" in window, je = ["IMG", "IMAGE", "AUDIO", "VIDEO", "SVG"];
2196
+ class mi {
2197
+ /**
2198
+ * Creates a DecorationGroup object
2199
+ * @param id Unique HTML ID-adhering name of the group
2200
+ * @param name Human-readable name of the group
2201
+ */
2202
+ constructor(e, t, r, s) {
2203
+ this.wnd = e, this.comms = t, this.id = r, this.name = s, this.items = [], this.lastItemId = 0, this.container = void 0, this.activateable = !1, this.experimentalHighlights = !1, this.currentRender = 0, fi && (this.experimentalHighlights = !0, this.notTextFlag = /* @__PURE__ */ new Map());
2204
+ }
2205
+ get activeable() {
2206
+ return this.activateable;
2207
+ }
2208
+ set activeable(e) {
2209
+ this.activateable = e;
2210
+ }
2211
+ /**
2212
+ * Adds a new decoration to the group.
2213
+ * @param decoration Decoration to add
2214
+ */
2215
+ add(e) {
2216
+ var o, a, h, c;
2217
+ const t = `${this.id}-${this.lastItemId++}`, r = Oe(this.wnd.document, e.locator);
2218
+ if (!r) {
2219
+ this.comms.log("Can't locate DOM range for decoration", e);
2220
+ return;
2221
+ }
2222
+ const s = r.commonAncestorContainer;
2223
+ s.nodeType !== Node.TEXT_NODE && this.experimentalHighlights && (je.includes(s.nodeName.toUpperCase()) && ((o = this.notTextFlag) == null || o.set(t, !0)), s.querySelector(je.join(", ").toLowerCase()) && ((a = this.notTextFlag) == null || a.set(t, !0)), (((h = s.textContent) == null ? void 0 : h.trim()) || "").length === 0 && ((c = this.notTextFlag) == null || c.set(t, !0)));
2224
+ const n = {
2225
+ decoration: e,
2226
+ id: t,
2227
+ range: r
2228
+ };
2229
+ this.items.push(n), this.layout(n), this.renderLayout([n]);
2230
+ }
2231
+ /**
2232
+ * Removes the decoration with given ID from the group.
2233
+ * @param identifier ID of item to remove
2234
+ */
2235
+ remove(e) {
2236
+ var s, n;
2237
+ const t = this.items.findIndex((o) => o.decoration.id === e);
2238
+ if (t < 0)
2239
+ return;
2240
+ const r = this.items[t];
2241
+ if (this.items.splice(t, 1), r.clickableElements = void 0, r.container && (r.container.remove(), r.container = void 0), this.experimentalHighlights && !((s = this.notTextFlag) != null && s.has(r.id))) {
2242
+ const o = this.wnd.CSS.highlights.get(this.id);
2243
+ o == null || o.delete(r.range);
2244
+ }
2245
+ (n = this.notTextFlag) == null || n.delete(r.id);
2246
+ }
2247
+ /**
2248
+ * Notifies that the given decoration was modified and needs to be updated.
2249
+ * @param decoration Decoration to update
2250
+ */
2251
+ update(e) {
2252
+ this.remove(e.id), this.add(e);
2253
+ }
2254
+ /**
2255
+ * Removes all decorations from this group.
2256
+ */
2257
+ clear() {
2258
+ var e;
2259
+ this.clearContainer(), this.items.length = 0, (e = this.notTextFlag) == null || e.clear();
2260
+ }
2261
+ /**
2262
+ * Recreates the decoration elements.
2263
+ * To be called after reflowing the resource, for example.
2264
+ */
2265
+ requestLayout() {
2266
+ this.wnd.cancelAnimationFrame(this.currentRender), this.clearContainer(), this.items.forEach((e) => this.layout(e)), this.renderLayout(this.items);
2267
+ }
2268
+ experimentalLayout(e) {
2269
+ var s, n;
2270
+ const [t, r] = this.requireContainer(!0);
2271
+ r.add(e.range), t.innerHTML = `
2272
+ ::highlight(${this.id}) {
2273
+ color: black;
2274
+ background-color: ${((n = (s = e.decoration) == null ? void 0 : s.style) == null ? void 0 : n.tint) ?? "yellow"};
2275
+ }`;
2276
+ }
2277
+ /**
2278
+ * Layouts a single DecorationItem.
2279
+ * @param item
2280
+ */
2281
+ layout(e) {
2282
+ var v, g, y, x, S;
2283
+ if (this.experimentalHighlights && !((v = this.notTextFlag) != null && v.has(e.id)))
2284
+ return this.experimentalLayout(e);
2285
+ const t = this.wnd.document.createElement("div");
2286
+ t.setAttribute("id", e.id), t.style.setProperty("pointer-events", "none");
2287
+ const r = this.wnd.innerWidth, s = parseInt(
2288
+ getComputedStyle(this.wnd.document.documentElement).getPropertyValue(
2289
+ "column-count"
2290
+ )
2291
+ ), n = r / (s || 1), o = this.wnd.document.scrollingElement, a = o.scrollLeft, h = o.scrollTop, c = (m, E, P) => {
2292
+ var Y, Z, D, B, J, K;
2293
+ if (m.style.position = "absolute", ((Z = (Y = e.decoration) == null ? void 0 : Y.style) == null ? void 0 : Z.width) === "viewport") {
2294
+ m.style.width = `${r}px`, m.style.height = `${E.height}px`;
2295
+ let U = Math.floor(E.left / r) * r;
2296
+ m.style.left = `${U + a}px`, m.style.top = `${E.top + h}px`;
2297
+ } else if (((B = (D = e.decoration) == null ? void 0 : D.style) == null ? void 0 : B.width) === "bounds")
2298
+ m.style.width = `${P.width}px`, m.style.height = `${E.height}px`, m.style.left = `${P.left + a}px`, m.style.top = `${E.top + h}px`;
2299
+ else if (((K = (J = e.decoration) == null ? void 0 : J.style) == null ? void 0 : K.width) === "page") {
2300
+ m.style.width = `${n}px`, m.style.height = `${E.height}px`;
2301
+ let U = Math.floor(E.left / n) * n;
2302
+ m.style.left = `${U + a}px`, m.style.top = `${E.top + h}px`;
2303
+ } else
2304
+ m.style.width = `${E.width}px`, m.style.height = `${E.height}px`, m.style.left = `${E.left + a}px`, m.style.top = `${E.top + h}px`;
2305
+ }, u = e.range.getBoundingClientRect();
2306
+ let p = this.wnd.document.createElement("template");
2307
+ const d = ci(this.wnd, "--USER__appearance") === "readium-night-on";
2308
+ p.innerHTML = `
2309
+ <div
2310
+ class="r2-highlight-0"
2311
+ style="${[
2312
+ `background-color: ${((y = (g = e.decoration) == null ? void 0 : g.style) == null ? void 0 : y.tint) ?? "yellow"} !important`,
2313
+ //"opacity: 0.3 !important",
2314
+ `mix-blend-mode: ${d ? "exclusion" : "multiply"} !important`,
2315
+ "opacity: 1 !important",
2316
+ "box-sizing: border-box !important"
2317
+ ].join("; ")}"
2318
+ >
2319
+ </div>
2320
+ `.trim();
2321
+ const f = p.content.firstElementChild;
2322
+ if (((S = (x = e.decoration) == null ? void 0 : x.style) == null ? void 0 : S.layout) === "bounds") {
2323
+ const m = f.cloneNode(!0);
2324
+ m.style.setProperty("pointer-events", "none"), c(m, u, u), t.append(m);
2325
+ } else {
2326
+ let m = kt(
2327
+ e.range,
2328
+ !0
2329
+ // doNotMergeHorizontallyAlignedRects
2330
+ );
2331
+ m = m.sort((E, P) => E.top < P.top ? -1 : E.top > P.top ? 1 : 0);
2332
+ for (let E of m) {
2333
+ const P = f.cloneNode(!0);
2334
+ P.style.setProperty("pointer-events", "none"), c(P, E, u), t.append(P);
2176
2335
  }
2177
2336
  }
2178
- this.startingX = e.touches[0].clientX, this.alreadyScrollLeft = this.doc().scrollLeft, this.touchState = 1;
2179
- }
2180
- onTouchEnd(e) {
2181
- if (this.touchState === 2) {
2182
- const t = this.dragOffset(), r = this.scrollOffset();
2183
- this.cachedScrollWidth <= this.wnd.innerWidth ? (this.reportProgress(), t > 5 && this.comms.send("no_more", void 0), t < -5 && this.comms.send("no_less", void 0)) : r < 5 && t < 5 ? (this.alreadyScrollLeft = 0, this.comms.send("no_less", void 0)) : this.cachedScrollWidth - r - this.wnd.innerWidth < 5 && t > 5 && (this.alreadyScrollLeft = this.cachedScrollWidth, this.comms.send("no_more", void 0)), this.snapCurrentOffset(!0), this.comms.send("swipe", t);
2184
- }
2185
- this.touchState = 0;
2186
- }
2187
- onWidthChange() {
2188
- this.cachedScrollWidth = this.doc().scrollWidth, this.comms.ready && this.snapCurrentOffset();
2189
- }
2190
- onTouchMove(e) {
2191
- if (this.touchState === 0)
2192
- return;
2193
- this.touchState === 1 && (this.touchState = 2, T(this.wnd)), this.endingX = e.touches[0].clientX;
2194
- const t = this.dragOffset(), r = this.alreadyScrollLeft + t;
2195
- r < 0 ? (this.overscroll = r, this.doc().style.transform = `translate3d(${-this.overscroll}px, 0px, 0px)`) : r + this.wnd.innerWidth > this.cachedScrollWidth ? (this.overscroll = r, this.doc().style.transform = `translate3d(${-r}px, 0px, 0px)`) : (this.overscroll = 0, this.doc().style.removeProperty("transform"), this.doc().scrollLeft = this.alreadyScrollLeft + t);
2337
+ e.container = t, e.clickableElements = Array.from(
2338
+ t.querySelectorAll("[data-activable='1']")
2339
+ ), e.clickableElements.length || (e.clickableElements = Array.from(t.children));
2196
2340
  }
2197
- mount(e, t) {
2198
- if (this.wnd = e, this.comms = t, !super.mount(e, t))
2199
- return !1;
2200
- const r = e.document.createElement("style");
2201
- r.dataset.readium = "true", r.id = _e, r.textContent = `
2202
- @keyframes readium-bounce-l-animation {
2203
- 0%, 100% {transform: translate3d(0, 0, 0);}
2204
- 50% {transform: translate3d(-50px, 0, 0);}
2205
- }
2206
-
2207
- @keyframes readium-bounce-r-animation {
2208
- 0%, 100% {transform: translate3d(0, 0, 0);}
2209
- 50% {transform: translate3d(50px, 0, 0);}
2210
- }
2211
-
2212
- .readium-bounce-l {
2213
- animation: readium-bounce-l-animation 150ms ease-out 1;
2214
- }
2215
-
2216
- .readium-bounce-r {
2217
- animation: readium-bounce-r-animation 150ms ease-out 1;
2218
- }
2219
-
2220
- html {
2221
- overflow: hidden;
2222
- }
2223
-
2224
- body {
2225
- -ms-overflow-style: none; /* for Internet Explorer, Edge */
2226
- }
2227
-
2228
- * {
2229
- scrollbar-width: none; /* for Firefox */
2230
- }
2231
-
2232
- body::-webkit-scrollbar {
2233
- display: none; /* for Chrome, Safari, and Opera */
2234
- }
2235
- `, e.document.head.appendChild(r);
2236
- const s = e.ResizeObserver || nt;
2237
- this.resizeObserver = new s(() => e.requestAnimationFrame(() => {
2238
- e && Jt(e);
2239
- })), this.resizeObserver.observe(e.document.body), this.mutationObserver = new MutationObserver(() => {
2240
- this.wnd.requestAnimationFrame(() => this.cachedScrollWidth = this.doc().scrollWidth);
2241
- }), e.frameElement && this.mutationObserver.observe(e.frameElement, { attributes: !0, attributeFilter: ["style"] }), this.mutationObserver.observe(e.document, { attributes: !0, attributeFilter: ["style"] });
2242
- const n = (o) => {
2243
- const a = this.doc().scrollLeft;
2244
- return this.doc().scrollLeft = this.snapOffset(o), a !== this.doc().scrollLeft;
2245
- };
2246
- return e.addEventListener("orientationchange", this.onWidthChanger), e.addEventListener("resize", this.onWidthChanger), e.requestAnimationFrame(() => this.cachedScrollWidth = this.doc().scrollWidth), t.register("go_progression", C.moduleName, (o, a) => {
2247
- const h = o;
2248
- if (h < 0 || h > 1) {
2249
- t.send("error", {
2250
- message: "go_progression must be given a position from 0.0 to 1.0"
2251
- }), a(!1);
2252
- return;
2253
- }
2254
- this.wnd.requestAnimationFrame(() => {
2255
- this.cachedScrollWidth = this.doc().scrollWidth;
2256
- const c = this.cachedScrollWidth, d = W(e) ? -1 : 1, p = c * h * d;
2257
- this.doc().scrollLeft = this.snapOffset(p), this.reportProgress(), T(this.wnd), a(!0);
2258
- });
2259
- }), t.register("go_id", C.moduleName, (o, a) => {
2260
- const h = e.document.getElementById(o);
2261
- if (!h) {
2262
- a(!1);
2263
- return;
2264
- }
2265
- this.wnd.requestAnimationFrame(() => {
2266
- this.doc().scrollLeft = this.snapOffset(h.getBoundingClientRect().left + e.scrollX), this.reportProgress(), T(this.wnd), a(!0);
2267
- });
2268
- }), t.register("go_text", C.moduleName, (o, a) => {
2269
- let h;
2270
- Array.isArray(o) && (o.length > 1 && (h = o[1]), o = o[0]);
2271
- const c = q.deserialize(o), d = Oe(this.wnd.document, new I({
2272
- href: e.location.href,
2273
- type: "text/html",
2274
- text: c,
2275
- locations: h ? new w({
2276
- otherLocations: /* @__PURE__ */ new Map([
2277
- ["cssSelector", h]
2278
- ])
2279
- }) : void 0
2280
- }));
2281
- if (!d) {
2282
- a(!1);
2341
+ renderLayout(e) {
2342
+ this.wnd.cancelAnimationFrame(this.currentRender), this.currentRender = this.wnd.requestAnimationFrame(() => {
2343
+ if (e = e.filter((r) => {
2344
+ var s;
2345
+ return !this.experimentalHighlights || !!((s = this.notTextFlag) != null && s.has(r.id));
2346
+ }), !e || e.length === 0)
2283
2347
  return;
2284
- }
2285
- this.wnd.requestAnimationFrame(() => {
2286
- this.doc().scrollLeft = this.snapOffset(d.getBoundingClientRect().left + e.scrollX), this.reportProgress(), T(this.wnd), a(!0);
2287
- });
2288
- }), t.register("go_end", C.moduleName, (o, a) => {
2289
- const h = W(e) ? -1 : 1;
2290
- this.wnd.requestAnimationFrame(() => {
2291
- this.cachedScrollWidth = this.doc().scrollWidth;
2292
- const c = this.cachedScrollWidth * h;
2293
- if (this.doc().scrollLeft === c)
2294
- return a(!1);
2295
- this.doc().scrollLeft = this.snapOffset(c), this.reportProgress(), T(this.wnd), a(!0);
2296
- });
2297
- }), t.register("go_start", C.moduleName, (o, a) => {
2298
- this.wnd.requestAnimationFrame(() => {
2299
- if (this.doc().scrollLeft === 0)
2300
- return a(!1);
2301
- this.doc().scrollLeft = 0, this.reportProgress(), T(this.wnd), a(!0);
2302
- });
2303
- }), t.register("go_prev", C.moduleName, (o, a) => {
2304
- this.wnd.requestAnimationFrame(() => {
2305
- const h = e.scrollX - e.innerWidth, c = W(e) ? -(this.cachedScrollWidth - e.innerWidth) : 0, d = n(Math.max(h, c));
2306
- d && (this.reportProgress(), T(this.wnd)), a(d);
2307
- });
2308
- }), t.register("go_next", C.moduleName, (o, a) => {
2309
- this.wnd.requestAnimationFrame(() => {
2310
- const h = e.scrollX + e.innerWidth, c = W(e) ? 0 : this.cachedScrollWidth - e.innerWidth, d = n(Math.min(h, c));
2311
- d && (this.reportProgress(), T(this.wnd)), a(d);
2312
- });
2313
- }), t.register("unfocus", C.moduleName, (o, a) => {
2314
- this.snappingCancelled = !0, T(this.wnd), a(!0);
2315
- }), t.register("shake", C.moduleName, (o, a) => {
2316
- this.shake(), a(!0);
2317
- }), t.register("focus", C.moduleName, (o, a) => {
2318
- this.wnd.requestAnimationFrame(() => {
2319
- this.cachedScrollWidth = this.doc().scrollWidth, this.snapCurrentOffset(!1, !0), this.reportProgress(), a(!0);
2320
- });
2321
- }), t.register("first_visible_locator", C.moduleName, (o, a) => {
2322
- const h = mt(e, !1);
2323
- this.comms.send("first_visible_locator", h.serialize()), a(!0);
2324
- }), e.addEventListener("touchstart", this.onTouchStarter, { passive: !0 }), e.addEventListener("touchend", this.onTouchEnder, { passive: !0 }), e.addEventListener("touchmove", this.onTouchMover, { passive: !0 }), e.document.addEventListener("touchstart", () => {
2325
- }), t.log("ColumnSnapper Mounted"), !0;
2348
+ this.requireContainer().append(...e.map((r) => r.container).filter((r) => !!r));
2349
+ });
2326
2350
  }
2327
- unmount(e, t) {
2328
- var r;
2329
- return this.snappingCancelled = !0, t.unregisterAll(C.moduleName), this.resizeObserver.disconnect(), this.mutationObserver.disconnect(), e.removeEventListener("touchstart", this.onTouchStarter), e.removeEventListener("touchend", this.onTouchEnder), e.removeEventListener("touchmove", this.onTouchMover), e.removeEventListener("orientationchange", this.onWidthChanger), e.removeEventListener("resize", this.onWidthChanger), (r = e.document.getElementById(_e)) == null || r.remove(), t.log("ColumnSnapper Unmounted"), super.unmount(e, t);
2351
+ /**
2352
+ * Returns the group container element, after making sure it exists.
2353
+ * @returns Group's container
2354
+ */
2355
+ requireContainer(e = !1) {
2356
+ if (e) {
2357
+ let t;
2358
+ this.wnd.document.getElementById(`${this.id}-style`) ? t = this.wnd.document.getElementById(`${this.id}-style`) : (t = this.wnd.document.createElement("style"), t.dataset.readium = "true", t.id = `${this.id}-style`, this.wnd.document.head.appendChild(t));
2359
+ let r;
2360
+ return this.wnd.CSS.highlights.has(this.id) ? r = this.wnd.CSS.highlights.get(this.id) : (r = new this.wnd.Highlight(), this.wnd.CSS.highlights.set(this.id, r)), [t, r];
2361
+ }
2362
+ return this.container || (this.container = this.wnd.document.createElement("div"), this.container.setAttribute("id", this.id), this.container.dataset.group = this.name, this.container.dataset.readium = "true", this.container.style.setProperty("pointer-events", "none"), this.container.style.display = "contents", this.wnd.document.body.append(this.container)), this.container;
2330
2363
  }
2331
- };
2332
- vt.moduleName = "column_snapper";
2333
- let ci = vt;
2334
- const he = {
2335
- top: "js-iframe-reader-top-anchor",
2336
- bottom: "js-iframe-reader-bottom-anchor"
2337
- };
2338
- class di extends HTMLElement {
2339
- connectedCallback() {
2340
- this.setAttribute("aria-hidden", "true"), this.style.setProperty("display", "block", "important"), this.style.setProperty("padding", "0", "important"), this.style.setProperty("margin", "0", "important"), this.style.setProperty("visibility", "hidden", "important");
2364
+ /**
2365
+ * Removes the group container.
2366
+ */
2367
+ clearContainer() {
2368
+ this.experimentalHighlights && this.wnd.CSS.highlights.delete(this.id), this.container && (this.container.remove(), this.container = void 0);
2341
2369
  }
2342
2370
  }
2343
- function ui(i) {
2344
- const e = i.getElementsByTagName("body")[0], t = document.createElement("anchor-observer"), r = document.createElement("anchor-observer");
2345
- t.dataset.readium = "true", r.dataset.readium = "true", t == null || t.setAttribute("id", he.top), t == null || t.style.setProperty("height", "115px", "important"), r == null || r.setAttribute("id", he.bottom), r == null || r.style.setProperty("height", "80px", "important"), e == null || e.insertBefore(t, e.firstChild), e == null || e.appendChild(r);
2346
- }
2347
- function pi(i) {
2348
- var s, n;
2349
- const e = i.getElementsByTagName("body")[0], t = e == null ? void 0 : e.querySelector(`#${he.top}`), r = e == null ? void 0 : e.querySelector(`#${he.bottom}`);
2350
- t && ((s = t.parentElement) == null || s.removeChild(t)), r && ((n = r.parentElement) == null || n.removeChild(r));
2351
- }
2352
- const je = "readium-scroll-snapper-style", yt = class M extends at {
2371
+ const mt = class ve extends ce {
2353
2372
  constructor() {
2354
- super(...arguments), this.createAnchorElements = () => {
2355
- ui(this.doc());
2356
- }, this.removeAnchorElements = () => {
2357
- pi(this.doc());
2358
- }, this.createCustomElement = () => {
2359
- customElements.get("anchor-observer") || customElements.define("anchor-observer", di);
2360
- };
2373
+ super(...arguments), this.resizeFrame = 0, this.lastGroupId = 0, this.groups = /* @__PURE__ */ new Map(), this.handleResizer = this.handleResize.bind(this);
2361
2374
  }
2362
- doc() {
2363
- return this.wnd.document.scrollingElement;
2375
+ cleanup() {
2376
+ this.groups.forEach((e) => e.clear()), this.groups.clear();
2364
2377
  }
2365
- reportProgress(e) {
2366
- this.comms.send("progress", e);
2378
+ handleResize() {
2379
+ this.wnd.clearTimeout(this.resizeFrame), this.resizeFrame = this.wnd.setTimeout(() => {
2380
+ this.groups.forEach((e) => {
2381
+ e.experimentalHighlights || e.requestLayout();
2382
+ });
2383
+ }, 50);
2367
2384
  }
2368
2385
  mount(e, t) {
2369
- this.wnd = e, this.comms = t;
2370
- const r = e.document.createElement("style");
2371
- return r.dataset.readium = "true", r.id = je, r.textContent = `
2372
- * {
2373
- scrollbar-width: none; /* for Firefox */
2374
- }
2375
-
2376
- body::-webkit-scrollbar {
2377
- display: none; /* for Chrome, Safari, and Opera */
2378
- }
2379
- `, e.document.head.appendChild(r), t.register("go_progression", M.moduleName, (s, n) => {
2380
- const o = s;
2381
- if (o < 0 || o > 1) {
2382
- t.send("error", {
2383
- message: "go_progression must be given a position from 0.0 to 1.0"
2384
- }), n(!1);
2385
- return;
2386
- }
2387
- this.wnd.requestAnimationFrame(() => {
2388
- this.doc().scrollTop = this.doc().offsetHeight * o, this.reportProgress(o), T(this.wnd), n(!0);
2389
- });
2390
- }), t.register("go_id", M.moduleName, (s, n) => {
2391
- const o = e.document.getElementById(s);
2392
- if (!o) {
2393
- n(!1);
2394
- return;
2395
- }
2396
- this.wnd.requestAnimationFrame(() => {
2397
- this.doc().scrollTop = o.getBoundingClientRect().top + e.scrollY - e.innerHeight / 2, this.reportProgress(this.doc().scrollTop / this.doc().offsetHeight), T(this.wnd), n(!0);
2398
- });
2399
- }), t.register("go_text", M.moduleName, (s, n) => {
2400
- let o;
2401
- Array.isArray(s) && (s.length > 1 && (o = s[1]), s = s[0]);
2402
- const a = q.deserialize(s), h = Oe(this.wnd.document, new I({
2403
- href: e.location.href,
2404
- type: "text/html",
2405
- text: a,
2406
- locations: o ? new w({
2407
- otherLocations: /* @__PURE__ */ new Map([
2408
- ["cssSelector", o]
2409
- ])
2410
- }) : void 0
2411
- }));
2412
- if (!h) {
2413
- n(!1);
2414
- return;
2386
+ return this.wnd = e, t.register("decorate", ve.moduleName, (r, s) => {
2387
+ const n = r;
2388
+ n.decoration && n.decoration.locator && (n.decoration.locator = I.deserialize(n.decoration.locator)), this.groups.has(n.group) || this.groups.set(n.group, new mi(
2389
+ e,
2390
+ t,
2391
+ `readium-decoration-${this.lastGroupId++}`,
2392
+ n.group
2393
+ ));
2394
+ const o = this.groups.get(n.group);
2395
+ switch (n.action) {
2396
+ case "add":
2397
+ o == null || o.add(n.decoration);
2398
+ break;
2399
+ case "remove":
2400
+ o == null || o.remove(n.decoration.id);
2401
+ break;
2402
+ case "clear":
2403
+ o == null || o.clear();
2404
+ break;
2405
+ case "update":
2406
+ o == null || o.update(n.decoration);
2407
+ break;
2415
2408
  }
2416
- this.wnd.requestAnimationFrame(() => {
2417
- this.doc().scrollTop = h.getBoundingClientRect().top + e.scrollY - e.innerHeight / 2, this.reportProgress(this.doc().scrollTop / this.doc().offsetHeight), T(this.wnd), n(!0);
2418
- });
2419
- }), t.register("go_start", M.moduleName, (s, n) => {
2420
- if (this.doc().scrollTop === 0)
2421
- return n(!1);
2422
- this.doc().scrollTop = 0, this.reportProgress(0), n(!0);
2423
- }), t.register("go_end", M.moduleName, (s, n) => {
2424
- if (this.doc().scrollTop === 0)
2425
- return n(!1);
2426
- this.doc().scrollTop = 0, this.reportProgress(0), n(!0);
2427
- }), t.register("unfocus", M.moduleName, (s, n) => {
2428
- T(this.wnd), n(!0);
2429
- }), t.register([
2430
- "go_next",
2431
- "go_prev"
2432
- ], M.moduleName, (s, n) => n(!1)), t.register("focus", M.moduleName, (s, n) => {
2433
- this.reportProgress(this.doc().scrollTop / this.doc().offsetHeight), n(!0);
2434
- }), t.register("first_visible_locator", M.moduleName, (s, n) => {
2435
- const o = mt(e, !0);
2436
- this.comms.send("first_visible_locator", o.serialize()), n(!0);
2437
- }), t.log("ScrollSnapper Mounted"), this.createCustomElement(), this.createAnchorElements(), !0;
2409
+ s(!0);
2410
+ }), this.resizeObserver = new ui(() => e.requestAnimationFrame(() => this.handleResize())), this.resizeObserver.observe(e.document.body), e.addEventListener("orientationchange", this.handleResizer), e.addEventListener("resize", this.handleResizer), t.log("Decorator Mounted"), !0;
2438
2411
  }
2439
2412
  unmount(e, t) {
2440
- var r;
2441
- return t.unregisterAll(M.moduleName), this.removeAnchorElements(), (r = e.document.getElementById(je)) == null || r.remove(), t.log("ScrollSnapper Unmounted"), !0;
2413
+ return e.removeEventListener("orientationchange", this.handleResizer), e.removeEventListener("resize", this.handleResizer), t.unregisterAll(ve.moduleName), this.resizeObserver.disconnect(), this.cleanup(), t.log("Decorator Unmounted"), !0;
2442
2414
  }
2443
2415
  };
2444
- yt.moduleName = "scroll_snapper";
2445
- let fi = yt;
2446
- class bt extends ce {
2416
+ mt.moduleName = "decorator";
2417
+ let gi = mt;
2418
+ const Xe = "readium-snapper-style", gt = class ye extends ce {
2447
2419
  constructor() {
2448
- super(...arguments), this.pointerMoved = !1, this.onPointerUp = this.onPointUp.bind(this), this.onPointerMove = this.onPointMove.bind(this), this.onPointerDown = this.onPointDown.bind(this), this.onContextMenu = this.onContext.bind(this), this.onClicker = this.onClick.bind(this);
2449
- }
2450
- onPointUp(e) {
2451
- var s, n, o, a, h;
2452
- const t = this.wnd.getSelection();
2453
- if (t && ((s = t.toString()) == null ? void 0 : s.length) > 0) {
2454
- const c = (n = t.getRangeAt(0)) == null ? void 0 : n.getClientRects();
2455
- if (!c || c.length === 0)
2456
- return;
2457
- const d = c[0], p = {
2458
- text: t.toString(),
2459
- x: d.x,
2460
- y: d.y,
2461
- width: d.width,
2462
- height: d.height,
2463
- targetFrameSrc: (a = (o = this.wnd) == null ? void 0 : o.location) == null ? void 0 : a.href
2464
- };
2465
- this.comms.send("text_selected", p);
2466
- }
2467
- if (this.pointerMoved) {
2468
- this.pointerMoved = !1;
2469
- return;
2470
- }
2471
- if (!(t != null && t.isCollapsed) || !e.isPrimary)
2472
- return;
2473
- const r = this.wnd.devicePixelRatio;
2474
- e.preventDefault(), this.comms.send(e.pointerType === "touch" ? "tap" : "click", {
2475
- defaultPrevented: e.defaultPrevented,
2476
- x: e.clientX * r,
2477
- y: e.clientY * r,
2478
- targetFrameSrc: this.wnd.location.href,
2479
- targetElement: e.target.outerHTML,
2480
- interactiveElement: (h = ft(e.target)) == null ? void 0 : h.outerHTML,
2481
- cssSelector: this.wnd._readium_cssSelectorGenerator.getCssSelector(e.target)
2482
- }), this.pointerMoved = !1;
2483
- }
2484
- onPointMove(e) {
2485
- if (e.movementY !== void 0 && e.movementX !== void 0) {
2486
- (Math.abs(e.movementX) > 1 || Math.abs(e.movementY) > 1) && (this.pointerMoved = !0);
2487
- return;
2488
- }
2489
- this.pointerMoved = !0;
2490
- }
2491
- onPointDown() {
2492
- this.pointerMoved = !1;
2493
- }
2494
- onContext(e) {
2495
- this.onPointUp(e), this.pointerMoved = !1;
2420
+ super(...arguments), this.protected = !1;
2496
2421
  }
2497
- onClick(e) {
2498
- if (e.preventDefault(), !e.isTrusted) {
2499
- const t = new PointerEvent("pointerup", {
2500
- isPrimary: !0,
2501
- pointerType: "mouse",
2502
- // Not really a better choice than this
2503
- clientX: e.clientX,
2504
- clientY: e.clientY
2505
- });
2506
- Object.defineProperty(t, "target", { writable: !1, value: e.target }), Object.defineProperty(t, "defaultPrevented", { writable: !1, value: e.defaultPrevented }), this.onPointUp(t);
2507
- }
2422
+ buildStyles() {
2423
+ return `
2424
+ html, body {
2425
+ touch-action: manipulation;
2426
+ user-select: ${this.protected ? "none" : "auto"};
2427
+ }`;
2508
2428
  }
2509
2429
  mount(e, t) {
2510
- return this.wnd = e, this.comms = t, e.document.addEventListener("pointerdown", this.onPointerDown), e.document.addEventListener("pointerup", this.onPointerUp), e.document.addEventListener("contextmenu", this.onContextMenu), e.document.addEventListener("pointermove", this.onPointerMove), e.document.addEventListener("click", this.onClicker), t.log("Peripherals Mounted"), !0;
2430
+ const r = e.document.createElement("style");
2431
+ return r.dataset.readium = "true", r.id = Xe, r.textContent = this.buildStyles(), e.document.head.appendChild(r), t.register("protect", ye.moduleName, (s, n) => {
2432
+ this.protected = !0, r.textContent = this.buildStyles(), n(!0);
2433
+ }), t.register("unprotect", ye.moduleName, (s, n) => {
2434
+ this.protected = !1, r.textContent = this.buildStyles(), n(!0);
2435
+ }), t.log("Snapper Mounted"), !0;
2511
2436
  }
2512
2437
  unmount(e, t) {
2513
- return e.document.removeEventListener("pointerdown", this.onPointerDown), e.document.removeEventListener("pointerup", this.onPointerUp), e.document.removeEventListener("contextmenu", this.onContextMenu), e.document.removeEventListener("pointermove", this.onPointerMove), e.document.removeEventListener("click", this.onClicker), t.log("Peripherals Unmounted"), !0;
2438
+ var r;
2439
+ return (r = e.document.getElementById(Xe)) == null || r.remove(), t.log("Snapper Unmounted"), !0;
2440
+ }
2441
+ };
2442
+ gt.moduleName = "snapper";
2443
+ let vt = gt;
2444
+ function W(i) {
2445
+ return i.document.body.dir.toLowerCase() === "rtl";
2446
+ }
2447
+ function yt(i) {
2448
+ return parseInt(
2449
+ i.getComputedStyle(
2450
+ i.document.documentElement
2451
+ ).getPropertyValue("column-count")
2452
+ );
2453
+ }
2454
+ function vi(i) {
2455
+ const e = "readium-virtual-page";
2456
+ let t = i.document.getElementById(e);
2457
+ if (yt(i) !== 2)
2458
+ t && t.remove();
2459
+ else {
2460
+ const s = i.document.scrollingElement.scrollWidth / i.innerWidth;
2461
+ Math.round(s * 2) / 2 % 1 > 0.1 && (t ? t.remove() : (t = i.document.createElement("div"), t.setAttribute("id", e), t.dataset.readium = "true", t.style.breakBefore = "column", t.innerHTML = "&#8203;", i.document.body.appendChild(t)));
2462
+ }
2463
+ }
2464
+ function yi(i) {
2465
+ return i < 0.5 ? 2 * i * i : -1 + (4 - 2 * i) * i;
2466
+ }
2467
+ function T(i) {
2468
+ const e = i.getSelection();
2469
+ e && e.removeAllRanges();
2470
+ }
2471
+ const bi = [
2472
+ "a",
2473
+ "audio",
2474
+ "button",
2475
+ "canvas",
2476
+ "details",
2477
+ "input",
2478
+ "label",
2479
+ "option",
2480
+ "select",
2481
+ "submit",
2482
+ "textarea",
2483
+ "video"
2484
+ ];
2485
+ function bt(i) {
2486
+ var e;
2487
+ return bi.indexOf(i.nodeName.toLowerCase()) !== -1 || i.hasAttribute("contenteditable") && ((e = i.getAttribute("contenteditable")) == null ? void 0 : e.toLowerCase()) !== "false" ? i : i.parentElement ? bt(i.parentElement) : null;
2488
+ }
2489
+ function Et(i, e) {
2490
+ const t = xt(i, i.document.body, e);
2491
+ return new I({
2492
+ href: "#",
2493
+ type: "application/xhtml+xml",
2494
+ locations: new w({
2495
+ otherLocations: /* @__PURE__ */ new Map([
2496
+ ["cssSelector", i._readium_cssSelectorGenerator.getCssSelector(t)]
2497
+ ])
2498
+ }),
2499
+ text: new q({
2500
+ highlight: t.textContent || void 0
2501
+ })
2502
+ });
2503
+ }
2504
+ function xt(i, e, t) {
2505
+ for (var r = 0; r < e.children.length; r++) {
2506
+ const s = e.children[r];
2507
+ if (!xi(s) && Ei(i, s, t))
2508
+ return xt(i, s, t);
2514
2509
  }
2510
+ return e;
2511
+ }
2512
+ function Ei(i, e, t) {
2513
+ if (e === document.body || e === document.documentElement)
2514
+ return !0;
2515
+ if (!document || !document.documentElement || !document.body)
2516
+ return !1;
2517
+ const r = e.getBoundingClientRect();
2518
+ return t ? r.bottom > 0 && r.top < i.innerHeight : r.right > 0 && r.left < i.innerWidth;
2519
+ }
2520
+ function xi(i) {
2521
+ const e = getComputedStyle(i);
2522
+ return !!(e && (e.getPropertyValue("display") != "block" || e.getPropertyValue("opacity") === "0"));
2515
2523
  }
2516
- bt.moduleName = "peripherals";
2517
- const Et = class ve extends ce {
2524
+ const Ge = "readium-column-snapper-style", wi = 200, wt = class C extends vt {
2518
2525
  constructor() {
2519
- super(...arguments), this.mediaPlayingCount = 0, this.allAnimations = /* @__PURE__ */ new Set();
2526
+ super(...arguments), this.shakeTimeout = 0, this.snappingCancelled = !1, this.alreadyScrollLeft = 0, this.overscroll = 0, this.cachedScrollWidth = 0, this.touchState = 0, this.startingX = void 0, this.endingX = void 0, this.onTouchStarter = this.onTouchStart.bind(this), this.onTouchEnder = this.onTouchEnd.bind(this), this.onWidthChanger = this.onWidthChange.bind(this), this.onTouchMover = this.onTouchMove.bind(this);
2520
2527
  }
2521
- wndOnErr(e) {
2522
- var t;
2523
- (t = this.comms) == null || t.send("error", {
2524
- message: e.message,
2525
- filename: e.filename,
2526
- lineno: e.lineno,
2527
- colno: e.colno
2528
- });
2528
+ doc() {
2529
+ return this.wnd.document.scrollingElement;
2529
2530
  }
2530
- unblock(e) {
2531
- var t;
2532
- for (e._readium_blockEvents = !1; ((t = e._readium_blockedEvents) == null ? void 0 : t.length) > 0; ) {
2533
- const r = e._readium_blockedEvents.shift();
2534
- switch (r[0]) {
2535
- case 0:
2536
- Reflect.apply(r[1], r[2], r[3]);
2537
- break;
2538
- case 1:
2539
- const s = r[1], n = r[2];
2540
- e.removeEventListener(s.type, e._readium_eventBlocker, !0);
2541
- const o = new Event(s.type, {
2542
- bubbles: s.bubbles,
2543
- cancelable: s.cancelable
2544
- });
2545
- n ? n.dispatchEvent(o) : e.dispatchEvent(o);
2546
- break;
2547
- }
2548
- }
2531
+ scrollOffset() {
2532
+ return this.doc().scrollLeft > 0 ? this.doc().scrollLeft : this.alreadyScrollLeft;
2549
2533
  }
2550
- onMediaPlayEvent() {
2551
- var e;
2552
- this.mediaPlayingCount++, (e = this.comms) == null || e.send("media_play", this.mediaPlayingCount);
2534
+ snapOffset(e) {
2535
+ const t = e + (W(this.wnd) ? -1 : 1);
2536
+ return t - t % this.wnd.innerWidth;
2553
2537
  }
2554
- onMediaPauseEvent() {
2555
- var e;
2556
- this.mediaPlayingCount > 0 && this.mediaPlayingCount--, (e = this.comms) == null || e.send("media_pause", this.mediaPlayingCount);
2538
+ reportProgress() {
2539
+ this.comms.send("progress", { progress: this.wnd.scrollX / this.cachedScrollWidth, reference: this.wnd.innerWidth / this.doc().scrollWidth });
2557
2540
  }
2558
- pauseAllMedia(e) {
2559
- const t = e.document.querySelectorAll("audio,video");
2560
- for (let r = 0; r < t.length; r++)
2561
- t[r].pause();
2541
+ shake() {
2542
+ if (this.overscroll !== 0 || this.shakeTimeout !== 0)
2543
+ return;
2544
+ const e = this.doc();
2545
+ e.classList.add(W(this.wnd) ? "readium-bounce-l" : "readium-bounce-r");
2546
+ const t = this.scrollOffset();
2547
+ this.shakeTimeout = this.wnd.setTimeout(() => {
2548
+ e.classList.remove("readium-bounce-l"), e.classList.remove("readium-bounce-r"), this.shakeTimeout = 0, this.doc().scrollLeft = t;
2549
+ }, 150);
2562
2550
  }
2563
- mount(e, t) {
2564
- this.comms = t, e.addEventListener(
2565
- "error",
2566
- this.wndOnErr,
2567
- !1
2568
- ), "getAnimations" in e.document && e.document.getAnimations().forEach((s) => {
2569
- s.cancel(), this.allAnimations.add(s);
2570
- }), t.register("activate", ve.moduleName, (s, n) => {
2571
- this.allAnimations.forEach((o) => {
2572
- o.cancel(), o.play();
2573
- }), n(!0);
2574
- }), t.register("unfocus", ve.moduleName, (s, n) => {
2575
- this.pauseAllMedia(e), this.allAnimations.forEach((o) => o.pause()), n(!0);
2576
- });
2577
- const r = e.document.querySelectorAll("audio,video");
2578
- for (let s = 0; s < r.length; s++) {
2579
- const n = r[s];
2580
- n.addEventListener("play", this.onMediaPlayEvent, {
2581
- passive: !0
2582
- }), n.addEventListener("pause", this.onMediaPauseEvent, {
2583
- passive: !0
2551
+ // We have to cache this because during overscroll (transform, or left) the width is incorrect due to browser
2552
+ takeOverSnap() {
2553
+ var t;
2554
+ this.snappingCancelled = !0, this.clearTouches();
2555
+ const e = this.doc();
2556
+ this.overscroll = ((t = e.style.transform) == null ? void 0 : t.length) > 12 ? parseFloat(e.style.transform.slice(12).split("px")[0]) : 0;
2557
+ }
2558
+ // Snaps the current offset to the page width.
2559
+ snapCurrentOffset(e = !1, t = !1) {
2560
+ const r = this.wnd.scrollX > 0 ? this.wnd.scrollX : this.alreadyScrollLeft, s = this.doc(), n = this.dragOffset(), o = yt(this.wnd), a = Math.min(Math.max(0, r), this.cachedScrollWidth), h = W(this.wnd) ? -1 : 1, c = (
2561
+ // The hurdle to overcome in order to change pages
2562
+ h * (this.wnd.innerWidth / 3) * (h * n > 0 ? 2 : 1)
2563
+ ), u = this.snapOffset(a + c);
2564
+ if (e && u !== this.scrollOffset()) {
2565
+ this.snappingCancelled = !1;
2566
+ const p = (g, y, x, S) => x > S ? y : g + (y - g) * yi(x / S), d = (
2567
+ /*Math.abs(startX - (this.useTransform ? currentOffset : 0)) < 10 ? 1 : */
2568
+ wi * o
2569
+ );
2570
+ let f;
2571
+ const v = (g) => {
2572
+ if (this.snappingCancelled)
2573
+ return;
2574
+ f || (f = g);
2575
+ const y = g - f, x = p(this.overscroll, 0, y, d), S = p(r, u, y, d);
2576
+ s.scrollLeft = S, this.overscroll !== 0 && (s.style.transform = `translate3d(${-x}px, 0px, 0px)`), y < d ? this.wnd.requestAnimationFrame(v) : (this.clearTouches(), s.style.removeProperty("transform"), s.scrollLeft = u, t || this.reportProgress());
2577
+ };
2578
+ this.wnd.requestAnimationFrame(v);
2579
+ } else
2580
+ s.style.removeProperty("transform"), this.wnd.requestAnimationFrame(() => {
2581
+ s.scrollLeft = u, this.clearTouches(), t || this.reportProgress();
2584
2582
  });
2585
- }
2586
- return t.log("Setup Mounted"), !0;
2587
2583
  }
2588
- unmount(e, t) {
2589
- return e.removeEventListener("error", this.wndOnErr), e.removeEventListener("play", this.onMediaPlayEvent), e.removeEventListener("pause", this.onMediaPauseEvent), this.allAnimations.forEach((r) => r.cancel()), this.allAnimations.clear(), t.log("Setup Unmounted"), !0;
2584
+ dragOffset() {
2585
+ return (this.startingX ?? 0) - (this.endingX ?? 0);
2590
2586
  }
2591
- };
2592
- Et.moduleName = "setup";
2593
- let xt = Et;
2594
- function mi(i, e) {
2595
- return i.document.documentElement.style.getPropertyValue(e);
2596
- }
2597
- function ye(i, e, t) {
2598
- i.document.documentElement.style.setProperty(e, t);
2599
- }
2600
- function wt(i, e) {
2601
- i.document.documentElement.style.removeProperty(e);
2602
- }
2603
- const Ge = "readium-viewport", Tt = class V extends xt {
2604
- onViewportWidthChanged(e) {
2605
- const t = e.target;
2606
- ye(t, "--RS__viewportWidth", `${t.innerWidth}px`);
2587
+ clearTouches() {
2588
+ this.startingX = void 0, this.endingX = void 0, this.overscroll = 0;
2607
2589
  }
2608
- mount(e, t) {
2609
- if (!super.mount(e, t))
2610
- return !1;
2611
- const r = e.document.createElement("meta");
2612
- return r.dataset.readium = "true", r.setAttribute("name", "viewport"), r.setAttribute("id", Ge), r.setAttribute(
2613
- "content",
2614
- "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"
2615
- ), e.document.head.appendChild(r), e.addEventListener("orientationchange", this.onViewportWidthChanged), e.addEventListener("resize", this.onViewportWidthChanged), this.onViewportWidthChanged({
2616
- target: e
2617
- }), t.register("set_property", V.moduleName, (s, n) => {
2618
- const o = s;
2619
- ye(e, o[0], o[1]), n(!0);
2620
- }), t.register("remove_property", V.moduleName, (s, n) => {
2621
- wt(e, s), n(!0);
2622
- }), t.register("activate", V.moduleName, (s, n) => {
2623
- this.unblock(e), n(!0);
2624
- }), t.log("ReflowableSetup Mounted"), !0;
2590
+ onTouchStart(e) {
2591
+ switch (e.stopPropagation(), this.takeOverSnap(), e.touches.length) {
2592
+ case 1:
2593
+ break;
2594
+ case 2:
2595
+ this.onTouchEnd(e);
2596
+ return;
2597
+ default: {
2598
+ this.onTouchEnd(e), this.comms.send("tap_more", e.touches.length);
2599
+ return;
2600
+ }
2601
+ }
2602
+ this.startingX = e.touches[0].clientX, this.alreadyScrollLeft = this.doc().scrollLeft, this.touchState = 1;
2625
2603
  }
2626
- unmount(e, t) {
2627
- var r;
2628
- return t.unregisterAll(V.moduleName), (r = e.document.head.querySelector(`#${Ge}`)) == null || r.remove(), e.removeEventListener("orientationchange", this.onViewportWidthChanged), t.log("ReflowableSetup Unmounted"), super.unmount(e, t);
2604
+ onTouchEnd(e) {
2605
+ if (this.touchState === 2) {
2606
+ const t = this.dragOffset(), r = this.scrollOffset();
2607
+ this.cachedScrollWidth <= this.wnd.innerWidth ? (this.reportProgress(), t > 5 && this.comms.send("no_more", void 0), t < -5 && this.comms.send("no_less", void 0)) : r < 5 && t < 5 ? (this.alreadyScrollLeft = 0, this.comms.send("no_less", void 0)) : this.cachedScrollWidth - r - this.wnd.innerWidth < 5 && t > 5 && (this.alreadyScrollLeft = this.cachedScrollWidth, this.comms.send("no_more", void 0)), this.snapCurrentOffset(!0), this.comms.send("swipe", t);
2608
+ }
2609
+ this.touchState = 0;
2610
+ }
2611
+ onWidthChange() {
2612
+ this.cachedScrollWidth = this.doc().scrollWidth, this.comms.ready && this.snapCurrentOffset();
2613
+ }
2614
+ onTouchMove(e) {
2615
+ if (this.touchState === 0)
2616
+ return;
2617
+ this.touchState === 1 && (this.touchState = 2, T(this.wnd)), this.endingX = e.touches[0].clientX;
2618
+ const t = this.dragOffset(), r = this.alreadyScrollLeft + t;
2619
+ r < 0 ? (this.overscroll = r, this.doc().style.transform = `translate3d(${-this.overscroll}px, 0px, 0px)`) : r + this.wnd.innerWidth > this.cachedScrollWidth ? (this.overscroll = r, this.doc().style.transform = `translate3d(${-r}px, 0px, 0px)`) : (this.overscroll = 0, this.doc().style.removeProperty("transform"), this.doc().scrollLeft = this.alreadyScrollLeft + t);
2629
2620
  }
2630
- };
2631
- Tt.moduleName = "reflowable_setup";
2632
- let gi = Tt;
2633
- const Ye = "readium-fixed-style", St = class L extends xt {
2634
2621
  mount(e, t) {
2635
- if (!super.mount(e, t))
2622
+ if (this.wnd = e, this.comms = t, !super.mount(e, t))
2636
2623
  return !1;
2624
+ e.navigator.epubReadingSystem.layoutStyle = "paginated";
2637
2625
  const r = e.document.createElement("style");
2638
- return r.id = Ye, r.dataset.readium = "true", r.textContent = `
2639
- html, body {
2640
- text-size-adjust: none;
2641
- -ms-text-size-adjust: none;
2642
- -webkit-text-size-adjust: none;
2643
- -moz-text-size-adjust: none;
2626
+ r.dataset.readium = "true", r.id = Ge, r.textContent = `
2627
+ @keyframes readium-bounce-l-animation {
2628
+ 0%, 100% {transform: translate3d(0, 0, 0);}
2629
+ 50% {transform: translate3d(-50px, 0, 0);}
2630
+ }
2644
2631
 
2645
- /* Fight Safari pinches */
2646
- touch-action: none !important;
2647
- min-height: 100%;
2632
+ @keyframes readium-bounce-r-animation {
2633
+ 0%, 100% {transform: translate3d(0, 0, 0);}
2634
+ 50% {transform: translate3d(50px, 0, 0);}
2635
+ }
2648
2636
 
2649
- /*cursor: var() TODO*/
2650
- }`, e.document.head.appendChild(r), t.register("set_property", L.moduleName, (s, n) => {
2651
- const o = s;
2652
- ye(e, o[0], o[1]), n(!0);
2653
- }), t.register("remove_property", L.moduleName, (s, n) => {
2654
- wt(e, s), n(!0);
2655
- }), t.register("first_visible_locator", L.moduleName, (s, n) => n(!1)), t.register("unfocus", L.moduleName, (s, n) => {
2656
- T(e), n(!0);
2657
- }), t.register([
2658
- "focus",
2659
- "go_next",
2660
- "go_prev",
2661
- "go_id",
2662
- "go_end",
2663
- "go_start",
2664
- "go_text",
2665
- "go_progression"
2666
- ], L.moduleName, (s, n) => n(!0)), t.register("activate", L.moduleName, (s, n) => {
2667
- this.unblock(e), n(!0);
2668
- }), t.log("FixedSetup Mounted"), !0;
2669
- }
2670
- unmount(e, t) {
2671
- var r;
2672
- return t.unregisterAll(L.moduleName), (r = e.document.getElementById(Ye)) == null || r.remove(), t.log("FixedSetup Unmounted"), super.unmount(e, t);
2673
- }
2674
- };
2675
- St.moduleName = "fixed_setup";
2676
- let vi = St;
2677
- function yi(i, e) {
2678
- let t = i.getClientRects();
2679
- t.length || i.commonAncestorContainer.nodeType === Node.ELEMENT_NODE && (t = i.commonAncestorContainer.getClientRects());
2680
- const r = 1, s = [];
2681
- for (const c of t)
2682
- s.push({
2683
- bottom: c.bottom,
2684
- height: c.height,
2685
- left: c.left,
2686
- right: c.right,
2687
- top: c.top,
2688
- width: c.width
2689
- });
2690
- const n = Ct(
2691
- s,
2692
- r,
2693
- e
2694
- ), o = Ei(n, r), a = Pt(o), h = 2 * 2;
2695
- for (let c = a.length - 1; c >= 0; c--) {
2696
- const d = a[c];
2697
- if (!(d.width * d.height > h))
2698
- if (a.length > 1)
2699
- a.splice(c, 1);
2700
- else
2701
- break;
2702
- }
2703
- return a;
2704
- }
2705
- function Ct(i, e, t) {
2706
- for (let r = 0; r < i.length; r++)
2707
- for (let s = r + 1; s < i.length; s++) {
2708
- const n = i[r], o = i[s];
2709
- if (n === o)
2710
- continue;
2711
- const a = A(n.top, o.top, e) && A(n.bottom, o.bottom, e), h = A(n.left, o.left, e) && A(n.right, o.right, e);
2712
- if ((h && !t || a && !h) && Ot(n, o, e)) {
2713
- const u = i.filter((v) => v !== n && v !== o), f = bi(n, o);
2714
- return u.push(f), Ct(
2715
- u,
2716
- e,
2717
- t
2718
- );
2637
+ .readium-bounce-l {
2638
+ animation: readium-bounce-l-animation 150ms ease-out 1;
2639
+ }
2640
+
2641
+ .readium-bounce-r {
2642
+ animation: readium-bounce-r-animation 150ms ease-out 1;
2643
+ }
2644
+
2645
+ html {
2646
+ overflow: hidden;
2647
+ }
2648
+
2649
+ body {
2650
+ -ms-overflow-style: none; /* for Internet Explorer, Edge */
2651
+ }
2652
+
2653
+ * {
2654
+ scrollbar-width: none; /* for Firefox */
2655
+ }
2656
+
2657
+ body::-webkit-scrollbar {
2658
+ display: none; /* for Chrome, Safari, and Opera */
2659
+ }
2660
+ `, e.document.head.appendChild(r);
2661
+ const s = e.ResizeObserver || pt;
2662
+ this.resizeObserver = new s(() => e.requestAnimationFrame(() => {
2663
+ e && vi(e);
2664
+ })), this.resizeObserver.observe(e.document.body), this.mutationObserver = new MutationObserver(() => {
2665
+ this.wnd.requestAnimationFrame(() => this.cachedScrollWidth = this.doc().scrollWidth);
2666
+ }), e.frameElement && this.mutationObserver.observe(e.frameElement, { attributes: !0, attributeFilter: ["style"] }), this.mutationObserver.observe(e.document, { attributes: !0, attributeFilter: ["style"] });
2667
+ const n = (o) => {
2668
+ const a = this.doc().scrollLeft;
2669
+ return this.doc().scrollLeft = this.snapOffset(o), a !== this.doc().scrollLeft;
2670
+ };
2671
+ return e.addEventListener("orientationchange", this.onWidthChanger), e.addEventListener("resize", this.onWidthChanger), e.requestAnimationFrame(() => this.cachedScrollWidth = this.doc().scrollWidth), t.register("go_progression", C.moduleName, (o, a) => {
2672
+ const h = o;
2673
+ if (h < 0 || h > 1) {
2674
+ t.send("error", {
2675
+ message: "go_progression must be given a position from 0.0 to 1.0"
2676
+ }), a(!1);
2677
+ return;
2719
2678
  }
2720
- }
2721
- return i;
2722
- }
2723
- function bi(i, e) {
2724
- const t = Math.min(i.left, e.left), r = Math.max(i.right, e.right), s = Math.min(i.top, e.top), n = Math.max(i.bottom, e.bottom);
2725
- return {
2726
- bottom: n,
2727
- height: n - s,
2728
- left: t,
2729
- right: r,
2730
- top: s,
2731
- width: r - t
2732
- };
2733
- }
2734
- function Ei(i, e) {
2735
- const t = new Set(i);
2736
- for (const r of i) {
2737
- if (!(r.width > 1 && r.height > 1)) {
2738
- t.delete(r);
2739
- continue;
2740
- }
2741
- for (const n of i)
2742
- if (r !== n && t.has(n) && xi(n, r, e)) {
2743
- t.delete(r);
2744
- break;
2679
+ this.wnd.requestAnimationFrame(() => {
2680
+ this.cachedScrollWidth = this.doc().scrollWidth;
2681
+ const c = this.cachedScrollWidth, u = W(e) ? -1 : 1, p = c * h * u;
2682
+ this.doc().scrollLeft = this.snapOffset(p), this.reportProgress(), T(this.wnd), a(!0);
2683
+ });
2684
+ }), t.register("go_id", C.moduleName, (o, a) => {
2685
+ const h = e.document.getElementById(o);
2686
+ if (!h) {
2687
+ a(!1);
2688
+ return;
2689
+ }
2690
+ this.wnd.requestAnimationFrame(() => {
2691
+ this.doc().scrollLeft = this.snapOffset(h.getBoundingClientRect().left + e.scrollX), this.reportProgress(), T(this.wnd), a(!0);
2692
+ });
2693
+ }), t.register("go_text", C.moduleName, (o, a) => {
2694
+ let h;
2695
+ Array.isArray(o) && (o.length > 1 && (h = o[1]), o = o[0]);
2696
+ const c = q.deserialize(o), u = Oe(this.wnd.document, new I({
2697
+ href: e.location.href,
2698
+ type: "text/html",
2699
+ text: c,
2700
+ locations: h ? new w({
2701
+ otherLocations: /* @__PURE__ */ new Map([
2702
+ ["cssSelector", h]
2703
+ ])
2704
+ }) : void 0
2705
+ }));
2706
+ if (!u) {
2707
+ a(!1);
2708
+ return;
2745
2709
  }
2710
+ this.wnd.requestAnimationFrame(() => {
2711
+ this.doc().scrollLeft = this.snapOffset(u.getBoundingClientRect().left + e.scrollX), this.reportProgress(), T(this.wnd), a(!0);
2712
+ });
2713
+ }), t.register("go_end", C.moduleName, (o, a) => {
2714
+ const h = W(e) ? -1 : 1;
2715
+ this.wnd.requestAnimationFrame(() => {
2716
+ this.cachedScrollWidth = this.doc().scrollWidth;
2717
+ const c = this.cachedScrollWidth * h;
2718
+ if (this.doc().scrollLeft === c)
2719
+ return a(!1);
2720
+ this.doc().scrollLeft = this.snapOffset(c), this.reportProgress(), T(this.wnd), a(!0);
2721
+ });
2722
+ }), t.register("go_start", C.moduleName, (o, a) => {
2723
+ this.wnd.requestAnimationFrame(() => {
2724
+ if (this.doc().scrollLeft === 0)
2725
+ return a(!1);
2726
+ this.doc().scrollLeft = 0, this.reportProgress(), T(this.wnd), a(!0);
2727
+ });
2728
+ }), t.register("go_prev", C.moduleName, (o, a) => {
2729
+ this.wnd.requestAnimationFrame(() => {
2730
+ const h = e.scrollX - e.innerWidth, c = W(e) ? -(this.cachedScrollWidth - e.innerWidth) : 0, u = n(Math.max(h, c));
2731
+ u && (this.reportProgress(), T(this.wnd)), a(u);
2732
+ });
2733
+ }), t.register("go_next", C.moduleName, (o, a) => {
2734
+ this.wnd.requestAnimationFrame(() => {
2735
+ const h = e.scrollX + e.innerWidth, c = W(e) ? 0 : this.cachedScrollWidth - e.innerWidth, u = n(Math.min(h, c));
2736
+ u && (this.reportProgress(), T(this.wnd)), a(u);
2737
+ });
2738
+ }), t.register("unfocus", C.moduleName, (o, a) => {
2739
+ this.snappingCancelled = !0, T(this.wnd), a(!0);
2740
+ }), t.register("shake", C.moduleName, (o, a) => {
2741
+ this.shake(), a(!0);
2742
+ }), t.register("focus", C.moduleName, (o, a) => {
2743
+ this.wnd.requestAnimationFrame(() => {
2744
+ this.cachedScrollWidth = this.doc().scrollWidth, this.snapCurrentOffset(!1, !0), this.reportProgress(), a(!0);
2745
+ });
2746
+ }), t.register("first_visible_locator", C.moduleName, (o, a) => {
2747
+ const h = Et(e, !1);
2748
+ this.comms.send("first_visible_locator", h.serialize()), a(!0);
2749
+ }), e.addEventListener("touchstart", this.onTouchStarter, { passive: !0 }), e.addEventListener("touchend", this.onTouchEnder, { passive: !0 }), e.addEventListener("touchmove", this.onTouchMover, { passive: !0 }), e.document.addEventListener("touchstart", () => {
2750
+ }), t.log("ColumnSnapper Mounted"), !0;
2751
+ }
2752
+ unmount(e, t) {
2753
+ var r;
2754
+ return this.snappingCancelled = !0, t.unregisterAll(C.moduleName), this.resizeObserver.disconnect(), this.mutationObserver.disconnect(), e.removeEventListener("touchstart", this.onTouchStarter), e.removeEventListener("touchend", this.onTouchEnder), e.removeEventListener("touchmove", this.onTouchMover), e.removeEventListener("orientationchange", this.onWidthChanger), e.removeEventListener("resize", this.onWidthChanger), (r = e.document.getElementById(Ge)) == null || r.remove(), t.log("ColumnSnapper Unmounted"), super.unmount(e, t);
2755
+ }
2756
+ };
2757
+ wt.moduleName = "column_snapper";
2758
+ let Ti = wt;
2759
+ const he = {
2760
+ top: "js-iframe-reader-top-anchor",
2761
+ bottom: "js-iframe-reader-bottom-anchor"
2762
+ };
2763
+ class Si extends HTMLElement {
2764
+ connectedCallback() {
2765
+ this.setAttribute("aria-hidden", "true"), this.style.setProperty("display", "block", "important"), this.style.setProperty("padding", "0", "important"), this.style.setProperty("margin", "0", "important"), this.style.setProperty("visibility", "hidden", "important");
2746
2766
  }
2747
- return Array.from(t);
2748
- }
2749
- function xi(i, e, t) {
2750
- return ie(i, e.left, e.top, t) && ie(i, e.right, e.top, t) && ie(i, e.left, e.bottom, t) && ie(i, e.right, e.bottom, t);
2751
2767
  }
2752
- function ie(i, e, t, r) {
2753
- return (i.left < e || A(i.left, e, r)) && (i.right > e || A(i.right, e, r)) && (i.top < t || A(i.top, t, r)) && (i.bottom > t || A(i.bottom, t, r));
2768
+ function Ci(i) {
2769
+ const e = i.getElementsByTagName("body")[0], t = document.createElement("anchor-observer"), r = document.createElement("anchor-observer");
2770
+ t.dataset.readium = "true", r.dataset.readium = "true", t == null || t.setAttribute("id", he.top), t == null || t.style.setProperty("height", "115px", "important"), r == null || r.setAttribute("id", he.bottom), r == null || r.style.setProperty("height", "80px", "important"), e == null || e.insertBefore(t, e.firstChild), e == null || e.appendChild(r);
2754
2771
  }
2755
- function Pt(i) {
2756
- for (let e = 0; e < i.length; e++)
2757
- for (let t = e + 1; t < i.length; t++) {
2758
- const r = i[e], s = i[t];
2759
- if (r !== s && Ot(r, s, -1)) {
2760
- let n = [], o;
2761
- const a = Ze(r, s);
2762
- if (a.length === 1)
2763
- n = a, o = r;
2764
- else {
2765
- const c = Ze(s, r);
2766
- a.length < c.length ? (n = a, o = r) : (n = c, o = s);
2767
- }
2768
- const h = i.filter((c) => c !== o);
2769
- return Array.prototype.push.apply(h, n), Pt(h);
2770
- }
2771
- }
2772
- return i;
2772
+ function Oi(i) {
2773
+ var s, n;
2774
+ const e = i.getElementsByTagName("body")[0], t = e == null ? void 0 : e.querySelector(`#${he.top}`), r = e == null ? void 0 : e.querySelector(`#${he.bottom}`);
2775
+ t && ((s = t.parentElement) == null || s.removeChild(t)), r && ((n = r.parentElement) == null || n.removeChild(r));
2773
2776
  }
2774
- function Ze(i, e) {
2775
- const t = wi(e, i);
2776
- if (t.height === 0 || t.width === 0)
2777
- return [i];
2778
- const r = [];
2779
- {
2780
- const s = {
2781
- bottom: i.bottom,
2782
- height: 0,
2783
- left: i.left,
2784
- right: t.left,
2785
- top: i.top,
2786
- width: 0
2787
- };
2788
- s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && r.push(s);
2789
- }
2790
- {
2791
- const s = {
2792
- bottom: t.top,
2793
- height: 0,
2794
- left: t.left,
2795
- right: t.right,
2796
- top: i.top,
2797
- width: 0
2777
+ const Ye = "readium-scroll-snapper-style", Tt = class M extends vt {
2778
+ constructor() {
2779
+ super(...arguments), this.createAnchorElements = () => {
2780
+ Ci(this.doc());
2781
+ }, this.removeAnchorElements = () => {
2782
+ Oi(this.doc());
2783
+ }, this.createCustomElement = () => {
2784
+ customElements.get("anchor-observer") || customElements.define("anchor-observer", Si);
2798
2785
  };
2799
- s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && r.push(s);
2800
2786
  }
2801
- {
2802
- const s = {
2803
- bottom: i.bottom,
2804
- height: 0,
2805
- left: t.left,
2806
- right: t.right,
2807
- top: t.bottom,
2808
- width: 0
2809
- };
2810
- s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && r.push(s);
2787
+ doc() {
2788
+ return this.wnd.document.scrollingElement;
2811
2789
  }
2812
- {
2813
- const s = {
2814
- bottom: i.bottom,
2815
- height: 0,
2816
- left: t.right,
2817
- right: i.right,
2818
- top: i.top,
2819
- width: 0
2820
- };
2821
- s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && r.push(s);
2790
+ reportProgress(e) {
2791
+ this.comms.send("progress", e);
2822
2792
  }
2823
- return r;
2824
- }
2825
- function wi(i, e) {
2826
- const t = Math.max(i.left, e.left), r = Math.min(i.right, e.right), s = Math.max(i.top, e.top), n = Math.min(i.bottom, e.bottom);
2827
- return {
2828
- bottom: n,
2829
- height: Math.max(0, n - s),
2830
- left: t,
2831
- right: r,
2832
- top: s,
2833
- width: Math.max(0, r - t)
2834
- };
2835
- }
2836
- function Ot(i, e, t) {
2837
- return (i.left < e.right || t >= 0 && A(i.left, e.right, t)) && (e.left < i.right || t >= 0 && A(e.left, i.right, t)) && (i.top < e.bottom || t >= 0 && A(i.top, e.bottom, t)) && (e.top < i.bottom || t >= 0 && A(e.top, i.bottom, t));
2838
- }
2839
- function A(i, e, t) {
2840
- return Math.abs(i - e) <= t;
2841
- }
2842
- const Ti = window.ResizeObserver || nt, Si = "Highlight" in window, Ke = ["IMG", "IMAGE", "AUDIO", "VIDEO", "SVG"];
2843
- class Ci {
2844
- /**
2845
- * Creates a DecorationGroup object
2846
- * @param id Unique HTML ID-adhering name of the group
2847
- * @param name Human-readable name of the group
2848
- */
2849
- constructor(e, t, r, s) {
2850
- this.wnd = e, this.comms = t, this.id = r, this.name = s, this.items = [], this.lastItemId = 0, this.container = void 0, this.activateable = !1, this.experimentalHighlights = !1, this.currentRender = 0, Si && (this.experimentalHighlights = !0, this.notTextFlag = /* @__PURE__ */ new Map());
2793
+ mount(e, t) {
2794
+ this.wnd = e, this.comms = t, e.navigator.epubReadingSystem.layoutStyle = "scrolling";
2795
+ const r = e.document.createElement("style");
2796
+ return r.dataset.readium = "true", r.id = Ye, r.textContent = `
2797
+ * {
2798
+ scrollbar-width: none; /* for Firefox */
2799
+ }
2800
+
2801
+ body::-webkit-scrollbar {
2802
+ display: none; /* for Chrome, Safari, and Opera */
2803
+ }
2804
+ `, e.document.head.appendChild(r), t.register("go_progression", M.moduleName, (s, n) => {
2805
+ const o = s;
2806
+ if (o < 0 || o > 1) {
2807
+ t.send("error", {
2808
+ message: "go_progression must be given a position from 0.0 to 1.0"
2809
+ }), n(!1);
2810
+ return;
2811
+ }
2812
+ this.wnd.requestAnimationFrame(() => {
2813
+ this.doc().scrollTop = this.doc().offsetHeight * o, this.reportProgress({ progress: o, reference: this.wnd.innerHeight / this.doc().scrollHeight }), T(this.wnd), n(!0);
2814
+ });
2815
+ }), t.register("go_id", M.moduleName, (s, n) => {
2816
+ const o = e.document.getElementById(s);
2817
+ if (!o) {
2818
+ n(!1);
2819
+ return;
2820
+ }
2821
+ this.wnd.requestAnimationFrame(() => {
2822
+ this.doc().scrollTop = o.getBoundingClientRect().top + e.scrollY - e.innerHeight / 2;
2823
+ const a = this.doc().scrollTop / this.doc().offsetHeight;
2824
+ this.reportProgress({ progress: a, reference: this.wnd.innerHeight / this.doc().scrollHeight }), T(this.wnd), n(!0);
2825
+ });
2826
+ }), t.register("go_text", M.moduleName, (s, n) => {
2827
+ let o;
2828
+ Array.isArray(s) && (s.length > 1 && (o = s[1]), s = s[0]);
2829
+ const a = q.deserialize(s), h = Oe(this.wnd.document, new I({
2830
+ href: e.location.href,
2831
+ type: "text/html",
2832
+ text: a,
2833
+ locations: o ? new w({
2834
+ otherLocations: /* @__PURE__ */ new Map([
2835
+ ["cssSelector", o]
2836
+ ])
2837
+ }) : void 0
2838
+ }));
2839
+ if (!h) {
2840
+ n(!1);
2841
+ return;
2842
+ }
2843
+ this.wnd.requestAnimationFrame(() => {
2844
+ this.doc().scrollTop = h.getBoundingClientRect().top + e.scrollY - e.innerHeight / 2;
2845
+ const c = this.doc().scrollTop / this.doc().offsetHeight;
2846
+ this.reportProgress({ progress: c, reference: this.wnd.innerHeight / this.doc().scrollHeight }), T(this.wnd), n(!0);
2847
+ });
2848
+ }), t.register("go_start", M.moduleName, (s, n) => {
2849
+ if (this.doc().scrollTop === 0)
2850
+ return n(!1);
2851
+ this.doc().scrollTop = 0, this.reportProgress({ progress: 0, reference: this.wnd.innerHeight / this.doc().scrollHeight }), n(!0);
2852
+ }), t.register("go_end", M.moduleName, (s, n) => {
2853
+ if (this.doc().scrollTop === 0)
2854
+ return n(!1);
2855
+ this.doc().scrollTop = 0, this.reportProgress({ progress: 0, reference: this.wnd.innerHeight / this.doc().scrollHeight }), n(!0);
2856
+ }), t.register("unfocus", M.moduleName, (s, n) => {
2857
+ T(this.wnd), n(!0);
2858
+ }), t.register([
2859
+ "go_next",
2860
+ "go_prev"
2861
+ ], M.moduleName, (s, n) => n(!1)), t.register("focus", M.moduleName, (s, n) => {
2862
+ const o = this.doc().scrollTop / this.doc().offsetHeight;
2863
+ this.reportProgress({ progress: o, reference: this.wnd.innerHeight / this.doc().scrollHeight }), n(!0);
2864
+ }), t.register("first_visible_locator", M.moduleName, (s, n) => {
2865
+ const o = Et(e, !0);
2866
+ this.comms.send("first_visible_locator", o.serialize()), n(!0);
2867
+ }), t.log("ScrollSnapper Mounted"), this.createCustomElement(), this.createAnchorElements(), !0;
2851
2868
  }
2852
- get activeable() {
2853
- return this.activateable;
2869
+ unmount(e, t) {
2870
+ var r;
2871
+ return t.unregisterAll(M.moduleName), this.removeAnchorElements(), (r = e.document.getElementById(Ye)) == null || r.remove(), t.log("ScrollSnapper Unmounted"), !0;
2854
2872
  }
2855
- set activeable(e) {
2856
- this.activateable = e;
2873
+ };
2874
+ Tt.moduleName = "scroll_snapper";
2875
+ let Pi = Tt;
2876
+ class St extends ce {
2877
+ constructor() {
2878
+ super(...arguments), this.pointerMoved = !1, this.onPointerUp = this.onPointUp.bind(this), this.onPointerMove = this.onPointMove.bind(this), this.onPointerDown = this.onPointDown.bind(this), this.onContextMenu = this.onContext.bind(this), this.onClicker = this.onClick.bind(this);
2857
2879
  }
2858
- /**
2859
- * Adds a new decoration to the group.
2860
- * @param decoration Decoration to add
2861
- */
2862
- add(e) {
2863
- var o, a, h, c;
2864
- const t = `${this.id}-${this.lastItemId++}`, r = Oe(this.wnd.document, e.locator);
2865
- if (!r) {
2866
- this.comms.log("Can't locate DOM range for decoration", e);
2880
+ onPointUp(e) {
2881
+ var s, n, o, a, h;
2882
+ const t = this.wnd.getSelection();
2883
+ if (t && ((s = t.toString()) == null ? void 0 : s.length) > 0) {
2884
+ const c = (n = t.getRangeAt(0)) == null ? void 0 : n.getClientRects();
2885
+ if (!c || c.length === 0)
2886
+ return;
2887
+ const u = c[0], p = {
2888
+ text: t.toString(),
2889
+ x: u.x,
2890
+ y: u.y,
2891
+ width: u.width,
2892
+ height: u.height,
2893
+ targetFrameSrc: (a = (o = this.wnd) == null ? void 0 : o.location) == null ? void 0 : a.href
2894
+ };
2895
+ this.comms.send("text_selected", p);
2896
+ }
2897
+ if (this.pointerMoved) {
2898
+ this.pointerMoved = !1;
2867
2899
  return;
2868
2900
  }
2869
- const s = r.commonAncestorContainer;
2870
- s.nodeType !== Node.TEXT_NODE && this.experimentalHighlights && (Ke.includes(s.nodeName.toUpperCase()) && ((o = this.notTextFlag) == null || o.set(t, !0)), s.querySelector(Ke.join(", ").toLowerCase()) && ((a = this.notTextFlag) == null || a.set(t, !0)), (((h = s.textContent) == null ? void 0 : h.trim()) || "").length === 0 && ((c = this.notTextFlag) == null || c.set(t, !0)));
2871
- const n = {
2872
- decoration: e,
2873
- id: t,
2874
- range: r
2875
- };
2876
- this.items.push(n), this.layout(n), this.renderLayout([n]);
2901
+ if (!(t != null && t.isCollapsed) || !e.isPrimary)
2902
+ return;
2903
+ const r = this.wnd.devicePixelRatio;
2904
+ e.preventDefault(), this.comms.send(e.pointerType === "touch" ? "tap" : "click", {
2905
+ defaultPrevented: e.defaultPrevented,
2906
+ x: e.clientX * r,
2907
+ y: e.clientY * r,
2908
+ targetFrameSrc: this.wnd.location.href,
2909
+ targetElement: e.target.outerHTML,
2910
+ interactiveElement: (h = bt(e.target)) == null ? void 0 : h.outerHTML,
2911
+ cssSelector: this.wnd._readium_cssSelectorGenerator.getCssSelector(e.target)
2912
+ }), this.pointerMoved = !1;
2877
2913
  }
2878
- /**
2879
- * Removes the decoration with given ID from the group.
2880
- * @param identifier ID of item to remove
2881
- */
2882
- remove(e) {
2883
- var s, n;
2884
- const t = this.items.findIndex((o) => o.decoration.id === e);
2885
- if (t < 0)
2914
+ onPointMove(e) {
2915
+ if (e.movementY !== void 0 && e.movementX !== void 0) {
2916
+ (Math.abs(e.movementX) > 1 || Math.abs(e.movementY) > 1) && (this.pointerMoved = !0);
2886
2917
  return;
2887
- const r = this.items[t];
2888
- if (this.items.splice(t, 1), r.clickableElements = void 0, r.container && (r.container.remove(), r.container = void 0), this.experimentalHighlights && !((s = this.notTextFlag) != null && s.has(r.id))) {
2889
- const o = this.wnd.CSS.highlights.get(this.id);
2890
- o == null || o.delete(r.range);
2891
2918
  }
2892
- (n = this.notTextFlag) == null || n.delete(r.id);
2919
+ this.pointerMoved = !0;
2920
+ }
2921
+ onPointDown() {
2922
+ this.pointerMoved = !1;
2923
+ }
2924
+ onContext(e) {
2925
+ this.onPointUp(e), this.pointerMoved = !1;
2926
+ }
2927
+ onClick(e) {
2928
+ if (e.preventDefault(), !e.isTrusted) {
2929
+ const t = new PointerEvent("pointerup", {
2930
+ isPrimary: !0,
2931
+ pointerType: "mouse",
2932
+ // Not really a better choice than this
2933
+ clientX: e.clientX,
2934
+ clientY: e.clientY
2935
+ });
2936
+ Object.defineProperty(t, "target", { writable: !1, value: e.target }), Object.defineProperty(t, "defaultPrevented", { writable: !1, value: e.defaultPrevented }), this.onPointUp(t);
2937
+ }
2893
2938
  }
2894
- /**
2895
- * Notifies that the given decoration was modified and needs to be updated.
2896
- * @param decoration Decoration to update
2897
- */
2898
- update(e) {
2899
- this.remove(e.id), this.add(e);
2939
+ mount(e, t) {
2940
+ return this.wnd = e, this.comms = t, e.document.addEventListener("pointerdown", this.onPointerDown), e.document.addEventListener("pointerup", this.onPointerUp), e.document.addEventListener("contextmenu", this.onContextMenu), e.document.addEventListener("pointermove", this.onPointerMove), e.document.addEventListener("click", this.onClicker), t.log("Peripherals Mounted"), !0;
2900
2941
  }
2901
- /**
2902
- * Removes all decorations from this group.
2903
- */
2904
- clear() {
2905
- var e;
2906
- this.clearContainer(), this.items.length = 0, (e = this.notTextFlag) == null || e.clear();
2942
+ unmount(e, t) {
2943
+ return e.document.removeEventListener("pointerdown", this.onPointerDown), e.document.removeEventListener("pointerup", this.onPointerUp), e.document.removeEventListener("contextmenu", this.onContextMenu), e.document.removeEventListener("pointermove", this.onPointerMove), e.document.removeEventListener("click", this.onClicker), t.log("Peripherals Unmounted"), !0;
2907
2944
  }
2908
- /**
2909
- * Recreates the decoration elements.
2910
- * To be called after reflowing the resource, for example.
2911
- */
2912
- requestLayout() {
2913
- this.wnd.cancelAnimationFrame(this.currentRender), this.clearContainer(), this.items.forEach((e) => this.layout(e)), this.renderLayout(this.items);
2945
+ }
2946
+ St.moduleName = "peripherals";
2947
+ const Ct = class be extends ce {
2948
+ constructor() {
2949
+ super(...arguments), this.mediaPlayingCount = 0, this.allAnimations = /* @__PURE__ */ new Set();
2914
2950
  }
2915
- experimentalLayout(e) {
2916
- var s, n;
2917
- const [t, r] = this.requireContainer(!0);
2918
- r.add(e.range), t.innerHTML = `
2919
- ::highlight(${this.id}) {
2920
- color: black;
2921
- background-color: ${((n = (s = e.decoration) == null ? void 0 : s.style) == null ? void 0 : n.tint) ?? "yellow"};
2922
- }`;
2951
+ wndOnErr(e) {
2952
+ var t;
2953
+ (t = this.comms) == null || t.send("error", {
2954
+ message: e.message,
2955
+ filename: e.filename,
2956
+ lineno: e.lineno,
2957
+ colno: e.colno
2958
+ });
2923
2959
  }
2924
- /**
2925
- * Layouts a single DecorationItem.
2926
- * @param item
2927
- */
2928
- layout(e) {
2929
- var v, g, y, x, S;
2930
- if (this.experimentalHighlights && !((v = this.notTextFlag) != null && v.has(e.id)))
2931
- return this.experimentalLayout(e);
2932
- const t = this.wnd.document.createElement("div");
2933
- t.setAttribute("id", e.id), t.style.setProperty("pointer-events", "none");
2934
- const r = this.wnd.innerWidth, s = parseInt(
2935
- getComputedStyle(this.wnd.document.documentElement).getPropertyValue(
2936
- "column-count"
2937
- )
2938
- ), n = r / (s || 1), o = this.wnd.document.scrollingElement, a = o.scrollLeft, h = o.scrollTop, c = (m, E, O) => {
2939
- var Y, Z, B, D, K, J;
2940
- if (m.style.position = "absolute", ((Z = (Y = e.decoration) == null ? void 0 : Y.style) == null ? void 0 : Z.width) === "viewport") {
2941
- m.style.width = `${r}px`, m.style.height = `${E.height}px`;
2942
- let U = Math.floor(E.left / r) * r;
2943
- m.style.left = `${U + a}px`, m.style.top = `${E.top + h}px`;
2944
- } else if (((D = (B = e.decoration) == null ? void 0 : B.style) == null ? void 0 : D.width) === "bounds")
2945
- m.style.width = `${O.width}px`, m.style.height = `${E.height}px`, m.style.left = `${O.left + a}px`, m.style.top = `${E.top + h}px`;
2946
- else if (((J = (K = e.decoration) == null ? void 0 : K.style) == null ? void 0 : J.width) === "page") {
2947
- m.style.width = `${n}px`, m.style.height = `${E.height}px`;
2948
- let U = Math.floor(E.left / n) * n;
2949
- m.style.left = `${U + a}px`, m.style.top = `${E.top + h}px`;
2950
- } else
2951
- m.style.width = `${E.width}px`, m.style.height = `${E.height}px`, m.style.left = `${E.left + a}px`, m.style.top = `${E.top + h}px`;
2952
- }, d = e.range.getBoundingClientRect();
2953
- let p = this.wnd.document.createElement("template");
2954
- const u = mi(this.wnd, "--USER__appearance") === "readium-night-on";
2955
- p.innerHTML = `
2956
- <div
2957
- class="r2-highlight-0"
2958
- style="${[
2959
- `background-color: ${((y = (g = e.decoration) == null ? void 0 : g.style) == null ? void 0 : y.tint) ?? "yellow"} !important`,
2960
- //"opacity: 0.3 !important",
2961
- `mix-blend-mode: ${u ? "exclusion" : "multiply"} !important`,
2962
- "opacity: 1 !important",
2963
- "box-sizing: border-box !important"
2964
- ].join("; ")}"
2965
- >
2966
- </div>
2967
- `.trim();
2968
- const f = p.content.firstElementChild;
2969
- if (((S = (x = e.decoration) == null ? void 0 : x.style) == null ? void 0 : S.layout) === "bounds") {
2970
- const m = f.cloneNode(!0);
2971
- m.style.setProperty("pointer-events", "none"), c(m, d, d), t.append(m);
2972
- } else {
2973
- let m = yi(
2974
- e.range,
2975
- !0
2976
- // doNotMergeHorizontallyAlignedRects
2977
- );
2978
- m = m.sort((E, O) => E.top < O.top ? -1 : E.top > O.top ? 1 : 0);
2979
- for (let E of m) {
2980
- const O = f.cloneNode(!0);
2981
- O.style.setProperty("pointer-events", "none"), c(O, E, d), t.append(O);
2960
+ unblock(e) {
2961
+ var t;
2962
+ for (e._readium_blockEvents = !1; ((t = e._readium_blockedEvents) == null ? void 0 : t.length) > 0; ) {
2963
+ const r = e._readium_blockedEvents.shift();
2964
+ switch (r[0]) {
2965
+ case 0:
2966
+ Reflect.apply(r[1], r[2], r[3]);
2967
+ break;
2968
+ case 1:
2969
+ const s = r[1], n = r[2];
2970
+ e.removeEventListener(s.type, e._readium_eventBlocker, !0);
2971
+ const o = new Event(s.type, {
2972
+ bubbles: s.bubbles,
2973
+ cancelable: s.cancelable
2974
+ });
2975
+ n ? n.dispatchEvent(o) : e.dispatchEvent(o);
2976
+ break;
2982
2977
  }
2983
2978
  }
2984
- e.container = t, e.clickableElements = Array.from(
2985
- t.querySelectorAll("[data-activable='1']")
2986
- ), e.clickableElements.length || (e.clickableElements = Array.from(t.children));
2987
2979
  }
2988
- renderLayout(e) {
2989
- this.wnd.cancelAnimationFrame(this.currentRender), this.currentRender = this.wnd.requestAnimationFrame(() => {
2990
- if (e = e.filter((r) => {
2991
- var s;
2992
- return !this.experimentalHighlights || !!((s = this.notTextFlag) != null && s.has(r.id));
2993
- }), !e || e.length === 0)
2994
- return;
2995
- this.requireContainer().append(...e.map((r) => r.container).filter((r) => !!r));
2996
- });
2980
+ onMediaPlayEvent() {
2981
+ var e;
2982
+ this.mediaPlayingCount++, (e = this.comms) == null || e.send("media_play", this.mediaPlayingCount);
2997
2983
  }
2998
- /**
2999
- * Returns the group container element, after making sure it exists.
3000
- * @returns Group's container
3001
- */
3002
- requireContainer(e = !1) {
3003
- if (e) {
3004
- let t;
3005
- this.wnd.document.getElementById(`${this.id}-style`) ? t = this.wnd.document.getElementById(`${this.id}-style`) : (t = this.wnd.document.createElement("style"), t.dataset.readium = "true", t.id = `${this.id}-style`, this.wnd.document.head.appendChild(t));
3006
- let r;
3007
- return this.wnd.CSS.highlights.has(this.id) ? r = this.wnd.CSS.highlights.get(this.id) : (r = new this.wnd.Highlight(), this.wnd.CSS.highlights.set(this.id, r)), [t, r];
2984
+ onMediaPauseEvent() {
2985
+ var e;
2986
+ this.mediaPlayingCount > 0 && this.mediaPlayingCount--, (e = this.comms) == null || e.send("media_pause", this.mediaPlayingCount);
2987
+ }
2988
+ pauseAllMedia(e) {
2989
+ const t = e.document.querySelectorAll("audio,video");
2990
+ for (let r = 0; r < t.length; r++)
2991
+ t[r].pause();
2992
+ }
2993
+ mount(e, t) {
2994
+ this.comms = t, e.addEventListener(
2995
+ "error",
2996
+ this.wndOnErr,
2997
+ !1
2998
+ ), Reflect.defineProperty(e.navigator, "epubReadingSystem", {
2999
+ value: {
3000
+ name: "readium-ts-toolkit",
3001
+ version: "1.3.2",
3002
+ hasFeature: (s, n = "") => {
3003
+ switch (s) {
3004
+ case "dom-manipulation":
3005
+ return !0;
3006
+ case "layout-changes":
3007
+ return !0;
3008
+ case "touch-events":
3009
+ return !0;
3010
+ case "mouse-events":
3011
+ return !0;
3012
+ case "keyboard-events":
3013
+ return !0;
3014
+ case "spine-scripting":
3015
+ return !0;
3016
+ case "embedded-web-content":
3017
+ return !0;
3018
+ default:
3019
+ return !1;
3020
+ }
3021
+ }
3022
+ },
3023
+ writable: !1
3024
+ }), "getAnimations" in e.document && e.document.getAnimations().forEach((s) => {
3025
+ s.cancel(), this.allAnimations.add(s);
3026
+ }), t.register("activate", be.moduleName, (s, n) => {
3027
+ this.allAnimations.forEach((o) => {
3028
+ o.cancel(), o.play();
3029
+ }), n(!0);
3030
+ }), t.register("unfocus", be.moduleName, (s, n) => {
3031
+ this.pauseAllMedia(e), this.allAnimations.forEach((o) => o.pause()), n(!0);
3032
+ });
3033
+ const r = e.document.querySelectorAll("audio,video");
3034
+ for (let s = 0; s < r.length; s++) {
3035
+ const n = r[s];
3036
+ n.addEventListener("play", this.onMediaPlayEvent, {
3037
+ passive: !0
3038
+ }), n.addEventListener("pause", this.onMediaPauseEvent, {
3039
+ passive: !0
3040
+ });
3008
3041
  }
3009
- return this.container || (this.container = this.wnd.document.createElement("div"), this.container.setAttribute("id", this.id), this.container.dataset.group = this.name, this.container.dataset.readium = "true", this.container.style.setProperty("pointer-events", "none"), this.container.style.display = "contents", this.wnd.document.body.append(this.container)), this.container;
3042
+ return t.log("Setup Mounted"), !0;
3010
3043
  }
3011
- /**
3012
- * Removes the group container.
3013
- */
3014
- clearContainer() {
3015
- this.experimentalHighlights && this.wnd.CSS.highlights.delete(this.id), this.container && (this.container.remove(), this.container = void 0);
3044
+ unmount(e, t) {
3045
+ return e.removeEventListener("error", this.wndOnErr), e.removeEventListener("play", this.onMediaPlayEvent), e.removeEventListener("pause", this.onMediaPauseEvent), this.allAnimations.forEach((r) => r.cancel()), this.allAnimations.clear(), t.log("Setup Unmounted"), !0;
3016
3046
  }
3017
- }
3018
- const At = class be extends ce {
3019
- constructor() {
3020
- super(...arguments), this.resizeFrame = 0, this.lastGroupId = 0, this.groups = /* @__PURE__ */ new Map(), this.handleResizer = this.handleResize.bind(this);
3047
+ };
3048
+ Ct.moduleName = "setup";
3049
+ let Ot = Ct;
3050
+ const Ze = "readium-viewport", Pt = class V extends Ot {
3051
+ onViewportWidthChanged(e) {
3052
+ const t = e.target;
3053
+ ge(t, "--RS__viewportWidth", `${t.innerWidth}px`);
3021
3054
  }
3022
- cleanup() {
3023
- this.groups.forEach((e) => e.clear()), this.groups.clear();
3055
+ mount(e, t) {
3056
+ if (!super.mount(e, t))
3057
+ return !1;
3058
+ const r = e.document.createElement("meta");
3059
+ return r.dataset.readium = "true", r.setAttribute("name", "viewport"), r.setAttribute("id", Ze), r.setAttribute(
3060
+ "content",
3061
+ "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"
3062
+ ), e.document.head.appendChild(r), e.addEventListener("orientationchange", this.onViewportWidthChanged), e.addEventListener("resize", this.onViewportWidthChanged), this.onViewportWidthChanged({
3063
+ target: e
3064
+ }), t.register("set_property", V.moduleName, (s, n) => {
3065
+ const o = s;
3066
+ ge(e, o[0], o[1]), n(!0);
3067
+ }), t.register("remove_property", V.moduleName, (s, n) => {
3068
+ ft(e, s), n(!0);
3069
+ }), t.register("activate", V.moduleName, (s, n) => {
3070
+ this.unblock(e), n(!0);
3071
+ }), t.log("ReflowableSetup Mounted"), !0;
3024
3072
  }
3025
- handleResize() {
3026
- this.wnd.clearTimeout(this.resizeFrame), this.resizeFrame = this.wnd.setTimeout(() => {
3027
- this.groups.forEach((e) => {
3028
- e.experimentalHighlights || e.requestLayout();
3029
- });
3030
- }, 50);
3073
+ unmount(e, t) {
3074
+ var r;
3075
+ return t.unregisterAll(V.moduleName), (r = e.document.head.querySelector(`#${Ze}`)) == null || r.remove(), e.removeEventListener("orientationchange", this.onViewportWidthChanged), t.log("ReflowableSetup Unmounted"), super.unmount(e, t);
3031
3076
  }
3077
+ };
3078
+ Pt.moduleName = "reflowable_setup";
3079
+ let Ai = Pt;
3080
+ const Je = "readium-fixed-style", At = class L extends Ot {
3032
3081
  mount(e, t) {
3033
- return this.wnd = e, t.register("decorate", be.moduleName, (r, s) => {
3034
- const n = r;
3035
- n.decoration && n.decoration.locator && (n.decoration.locator = I.deserialize(n.decoration.locator)), this.groups.has(n.group) || this.groups.set(n.group, new Ci(
3036
- e,
3037
- t,
3038
- `readium-decoration-${this.lastGroupId++}`,
3039
- n.group
3040
- ));
3041
- const o = this.groups.get(n.group);
3042
- switch (n.action) {
3043
- case "add":
3044
- o == null || o.add(n.decoration);
3045
- break;
3046
- case "remove":
3047
- o == null || o.remove(n.decoration.id);
3048
- break;
3049
- case "clear":
3050
- o == null || o.clear();
3051
- break;
3052
- case "update":
3053
- o == null || o.update(n.decoration);
3054
- break;
3055
- }
3056
- s(!0);
3057
- }), this.resizeObserver = new Ti(() => e.requestAnimationFrame(() => this.handleResize())), this.resizeObserver.observe(e.document.body), e.addEventListener("orientationchange", this.handleResizer), e.addEventListener("resize", this.handleResizer), t.log("Decorator Mounted"), !0;
3082
+ if (!super.mount(e, t))
3083
+ return !1;
3084
+ e.navigator.epubReadingSystem.layoutStyle = "paginated";
3085
+ const r = e.document.createElement("style");
3086
+ return r.id = Je, r.dataset.readium = "true", r.textContent = `
3087
+ html, body {
3088
+ text-size-adjust: none;
3089
+ -ms-text-size-adjust: none;
3090
+ -webkit-text-size-adjust: none;
3091
+ -moz-text-size-adjust: none;
3092
+
3093
+ /* Fight Safari pinches */
3094
+ touch-action: none !important;
3095
+ min-height: 100%;
3096
+
3097
+ /*cursor: var() TODO*/
3098
+ }`, e.document.head.appendChild(r), t.register("set_property", L.moduleName, (s, n) => {
3099
+ const o = s;
3100
+ ge(e, o[0], o[1]), n(!0);
3101
+ }), t.register("remove_property", L.moduleName, (s, n) => {
3102
+ ft(e, s), n(!0);
3103
+ }), t.register("first_visible_locator", L.moduleName, (s, n) => n(!1)), t.register("unfocus", L.moduleName, (s, n) => {
3104
+ T(e), n(!0);
3105
+ }), t.register([
3106
+ "focus",
3107
+ "go_next",
3108
+ "go_prev",
3109
+ "go_id",
3110
+ "go_end",
3111
+ "go_start",
3112
+ "go_text",
3113
+ "go_progression"
3114
+ ], L.moduleName, (s, n) => n(!0)), t.register("activate", L.moduleName, (s, n) => {
3115
+ this.unblock(e), n(!0);
3116
+ }), t.log("FixedSetup Mounted"), !0;
3058
3117
  }
3059
3118
  unmount(e, t) {
3060
- return e.removeEventListener("orientationchange", this.handleResizer), e.removeEventListener("resize", this.handleResizer), t.unregisterAll(be.moduleName), this.resizeObserver.disconnect(), this.cleanup(), t.log("Decorator Unmounted"), !0;
3119
+ var r;
3120
+ return t.unregisterAll(L.moduleName), (r = e.document.getElementById(Je)) == null || r.remove(), t.log("FixedSetup Unmounted"), super.unmount(e, t);
3061
3121
  }
3062
3122
  };
3063
- At.moduleName = "decorator";
3064
- let Pi = At;
3065
- const Oi = [
3123
+ At.moduleName = "fixed_setup";
3124
+ let Mi = At;
3125
+ const Ri = [
3066
3126
  "fixed_setup",
3067
3127
  "decorator",
3068
3128
  "peripherals"
3069
- ], Ai = [
3129
+ ], Ni = [
3070
3130
  "reflowable_setup",
3071
3131
  "decorator",
3072
3132
  "peripherals",
3073
3133
  "column_snapper",
3074
3134
  "scroll_snapper"
3075
- ], Je = new Map([
3135
+ ], Ke = new Map([
3076
3136
  // All modules go here
3077
- vi,
3137
+ Mi,
3138
+ Ai,
3139
+ St,
3078
3140
  gi,
3079
- bt,
3080
- Pi,
3081
- ci,
3082
- fi
3141
+ Ti,
3142
+ Pi
3083
3143
  ].map((i) => [i.moduleName, i]));
3084
- class Mi {
3144
+ class Li {
3085
3145
  /**
3086
3146
  * @param wnd Window instance to operate on
3087
3147
  * @param initialModules List of initial modules to load
3088
3148
  */
3089
3149
  constructor(e = window, t = []) {
3090
- this.loadedModules = [], this.wnd = e, this.comms = new Rt(e);
3150
+ this.loadedModules = [], this.wnd = e, this.comms = new Nt(e);
3091
3151
  const r = [...new Set(t)];
3092
3152
  if (r.length) {
3093
3153
  if (typeof e > "u")
@@ -3100,7 +3160,7 @@ class Mi {
3100
3160
  }
3101
3161
  }
3102
3162
  loadModule(e) {
3103
- const t = Je.get(e);
3163
+ const t = Ke.get(e);
3104
3164
  return t === void 0 ? (this.comms.log(`Module "${name}" does not exist in the library`), t) : new t();
3105
3165
  }
3106
3166
  /**
@@ -3118,7 +3178,7 @@ class Mi {
3118
3178
  * @returns Success
3119
3179
  */
3120
3180
  removeModule(e) {
3121
- const t = Je.get(e);
3181
+ const t = Ke.get(e);
3122
3182
  if (t === void 0)
3123
3183
  return this.comms.log(`Module "${e}" does not exist in the library`), !1;
3124
3184
  const r = this.loadedModules.findIndex((s) => s instanceof t);
@@ -3132,13 +3192,16 @@ class Mi {
3132
3192
  }
3133
3193
  }
3134
3194
  export {
3135
- X as COMMS_VERSION,
3136
- Rt as Comms,
3137
- Oi as FXLModules,
3138
- Mi as Loader,
3195
+ _ as COMMS_VERSION,
3196
+ Nt as Comms,
3197
+ gi as Decorator,
3198
+ Ri as FXLModules,
3199
+ pi as Layout,
3200
+ Li as Loader,
3139
3201
  ce as Module,
3140
- Je as ModuleLibrary,
3141
- bt as Peripherals,
3142
- Ai as ReflowableModules,
3143
- Nt as mid
3202
+ Ke as ModuleLibrary,
3203
+ St as Peripherals,
3204
+ Ni as ReflowableModules,
3205
+ di as Width,
3206
+ Rt as mid
3144
3207
  };