@readium/navigator-html-injectables 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,70 +1,66 @@
1
- const ae = Math.pow(2, 32), vt = () => Math.round(Math.random() * ae).toString(36), le = () => `${Math.round(performance.now())}-${vt()}-${vt()}`, H = 1;
2
- class he {
3
- constructor(t) {
4
- this.destination = null, this.registrar = /* @__PURE__ */ new Map(), this.origin = "", this.channelId = "", this.receiver = this.receive.bind(this), this.preLog = [], this.wnd = t, t.addEventListener("message", this.receiver);
5
- }
6
- receive(t) {
7
- if (t.source === null)
8
- throw Error("Event source is null");
9
- if (typeof t.data != "object")
10
- return;
11
- const e = t.data;
12
- if (!(!("_readium" in e) || !e._readium || e._readium <= 0)) {
13
- if (e.key === "_ping") {
1
+ const Qe = Math.pow(2, 32), Ee = () => Math.round(Math.random() * Qe).toString(36), et = () => `${Math.round(performance.now())}-${Ee()}-${Ee()}`, U = 1;
2
+ class tt {
3
+ constructor(e) {
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
+ }
6
+ receive(e) {
7
+ if (e.source === null) throw Error("Event source is null");
8
+ if (typeof e.data != "object") return;
9
+ const t = e.data;
10
+ if (!(!("_readium" in t) || !t._readium || t._readium <= 0)) {
11
+ if (t.key === "_ping") {
14
12
  if (!this.destination) {
15
- if (this.destination = t.source, this.origin = t.origin, this.channelId = e._channel, e._readium !== H) {
16
- e._readium > H ? this.send("error", `received comms version ${e._readium} higher than ${H}`) : this.send("error", `received comms version ${e._readium} lower than ${H}`), this.destination = null, this.origin = "", this.channelId = "";
13
+ if (this.destination = e.source, this.origin = e.origin, this.channelId = t._channel, t._readium !== U) {
14
+ t._readium > U ? this.send("error", `received comms version ${t._readium} higher than ${U}`) : this.send("error", `received comms version ${t._readium} lower than ${U}`), this.destination = null, this.origin = "", this.channelId = "";
17
15
  return;
18
16
  }
19
17
  this.send("_pong", void 0), this.preLog.forEach((i) => this.send("log", i)), this.preLog = [];
20
18
  }
21
19
  return;
22
20
  } else if (this.channelId) {
23
- if (e._channel !== this.channelId || t.origin !== this.origin)
24
- return;
21
+ if (t._channel !== this.channelId || e.origin !== this.origin) return;
25
22
  } else
26
23
  return;
27
- this.handle(e);
24
+ this.handle(t);
28
25
  }
29
26
  }
30
- handle(t) {
31
- const e = this.registrar.get(t.key);
32
- if (!e || e.length === 0) {
33
- t.strict && this.send("_unhandled", t);
27
+ handle(e) {
28
+ const t = this.registrar.get(e.key);
29
+ if (!t || t.length === 0) {
30
+ e.strict && this.send("_unhandled", e);
34
31
  return;
35
32
  }
36
- e.forEach((i) => i.cb(t.data, (r) => {
37
- this.send("_ack", r, t.id);
33
+ t.forEach((i) => i.cb(e.data, (s) => {
34
+ this.send("_ack", s, e.id);
38
35
  }));
39
36
  }
40
- register(t, e, i) {
41
- Array.isArray(t) || (t = [t]), t.forEach((r) => {
42
- const n = this.registrar.get(r);
37
+ register(e, t, i) {
38
+ Array.isArray(e) || (e = [e]), e.forEach((s) => {
39
+ const n = this.registrar.get(s);
43
40
  if (n && n.length >= 0) {
44
- if (n.find((l) => l.module === e))
45
- throw new Error(`Trying to register another callback for combination of event ${r} and module ${e}`);
41
+ if (n.find((l) => l.module === t)) throw new Error(`Trying to register another callback for combination of event ${s} and module ${t}`);
46
42
  n.push({
47
43
  cb: i,
48
- module: e
49
- }), this.registrar.set(r, n);
44
+ module: t
45
+ }), this.registrar.set(s, n);
50
46
  } else
51
- this.registrar.set(r, [{
47
+ this.registrar.set(s, [{
52
48
  cb: i,
53
- module: e
49
+ module: t
54
50
  }]);
55
51
  });
56
52
  }
57
- unregister(t, e) {
58
- Array.isArray(t) || (t = [t]), t.forEach((i) => {
59
- const r = this.registrar.get(i);
60
- !r || r.length === 0 || r.splice(r.findIndex((n) => n.module === e), 1);
53
+ unregister(e, t) {
54
+ Array.isArray(e) || (e = [e]), e.forEach((i) => {
55
+ const s = this.registrar.get(i);
56
+ !s || s.length === 0 || s.splice(s.findIndex((n) => n.module === t), 1);
61
57
  });
62
58
  }
63
- unregisterAll(t) {
64
- this.registrar.forEach((e, i) => this.registrar.set(i, e.filter((r) => r.module !== t)));
59
+ unregisterAll(e) {
60
+ this.registrar.forEach((t, i) => this.registrar.set(i, t.filter((s) => s.module !== e)));
65
61
  }
66
- log(...t) {
67
- this.destination ? this.send("log", t) : this.preLog.push(t);
62
+ log(...e) {
63
+ this.destination ? this.send("log", e) : this.preLog.push(e);
68
64
  }
69
65
  get ready() {
70
66
  return !!this.destination;
@@ -72,57 +68,53 @@ class he {
72
68
  destroy() {
73
69
  this.destination = null, this.channelId = "", this.preLog = [], this.registrar.clear(), this.wnd.removeEventListener("message", this.receiver);
74
70
  }
75
- send(t, e, i = void 0, r = []) {
76
- if (!this.destination)
77
- throw Error("Attempted to send comms message before destination has been initialized");
71
+ send(e, t, i = void 0, s = []) {
72
+ if (!this.destination) throw Error("Attempted to send comms message before destination has been initialized");
78
73
  const n = {
79
- _readium: H,
74
+ _readium: U,
80
75
  _channel: this.channelId,
81
- id: i ?? le(),
76
+ id: i ?? et(),
82
77
  // scrict,
83
- key: t,
84
- data: e
78
+ key: e,
79
+ data: t
85
80
  };
86
81
  try {
87
82
  this.destination.postMessage(n, {
88
83
  targetOrigin: this.origin,
89
- transfer: r
84
+ transfer: s
90
85
  });
91
86
  } catch (o) {
92
- if (r.length > 0)
93
- throw o;
94
- this.destination.postMessage(n, this.origin, r);
87
+ if (s.length > 0) throw o;
88
+ this.destination.postMessage(n, this.origin, s);
95
89
  }
96
90
  }
97
91
  }
98
- const L = class B {
99
- constructor(t) {
100
- if (typeof t == "string") {
101
- if (!B.VALID_MODES.has(t.toLowerCase()))
92
+ const N = class W {
93
+ constructor(e) {
94
+ if (typeof e == "string") {
95
+ if (!W.VALID_MODES.has(e.toLowerCase()))
102
96
  return;
103
- this.value = t.toLowerCase();
97
+ this.value = e.toLowerCase();
104
98
  } else {
105
- const e = t.filter(
106
- (i) => B.VALID_MODES.has(i.toLowerCase())
99
+ const t = e.filter(
100
+ (i) => W.VALID_MODES.has(i.toLowerCase())
107
101
  );
108
- if (e.length === 0)
102
+ if (t.length === 0)
109
103
  return;
110
- this.value = Array.from(new Set(e));
104
+ this.value = Array.from(new Set(t));
111
105
  }
112
106
  }
113
107
  /**
114
108
  * Parses a [PrimaryAccessMode] from its RWPM JSON representation.
115
109
  */
116
- static deserialize(t) {
117
- if (!t)
118
- return;
119
- if (typeof t == "string")
120
- return new B(t);
121
- if (!Array.isArray(t))
122
- return;
123
- const e = t.filter((i) => i ? B.VALID_MODES.has(i.toLowerCase()) : !1);
124
- if (e.length !== 0)
125
- return new B(e);
110
+ static deserialize(e) {
111
+ if (!e) return;
112
+ if (typeof e == "string")
113
+ return new W(e);
114
+ if (!Array.isArray(e)) return;
115
+ const t = e.filter((i) => i ? W.VALID_MODES.has(i.toLowerCase()) : !1);
116
+ if (t.length !== 0)
117
+ return new W(t);
126
118
  }
127
119
  /**
128
120
  * Serializes a [PrimaryAccessMode] to its RWPM JSON representation.
@@ -131,42 +123,38 @@ const L = class B {
131
123
  return this.value;
132
124
  }
133
125
  };
134
- L.VALID_MODES = /* @__PURE__ */ new Set(["auditory", "tactile", "textual", "visual"]);
135
- L.AUDITORY = new L("auditory");
136
- L.TACTILE = new L("tactile");
137
- L.TEXTUAL = new L("textual");
138
- L.VISUAL = new L("visual");
139
- class rt {
126
+ N.VALID_MODES = /* @__PURE__ */ new Set(["auditory", "tactile", "textual", "visual"]), N.AUDITORY = new N("auditory"), N.TACTILE = new N("tactile"), N.TEXTUAL = new N("textual"), N.VISUAL = new N("visual");
127
+ class ue {
140
128
  /**
141
129
  * Creates a [Encryption].
142
130
  */
143
- constructor(t) {
144
- this.algorithm = t.algorithm, this.compression = t.compression, this.originalLength = t.originalLength, this.profile = t.profile, this.scheme = t.scheme;
131
+ constructor(e) {
132
+ this.algorithm = e.algorithm, this.compression = e.compression, this.originalLength = e.originalLength, this.profile = e.profile, this.scheme = e.scheme;
145
133
  }
146
134
  /**
147
135
  * Parses a [Encryption] from its RWPM JSON representation.
148
136
  */
149
- static deserialize(t) {
150
- if (t && t.algorithm)
151
- return new rt({
152
- algorithm: t.algorithm,
153
- compression: t.compression,
154
- originalLength: t.originalLength,
155
- profile: t.profile,
156
- scheme: t.scheme
137
+ static deserialize(e) {
138
+ if (e && e.algorithm)
139
+ return new ue({
140
+ algorithm: e.algorithm,
141
+ compression: e.compression,
142
+ originalLength: e.originalLength,
143
+ profile: e.profile,
144
+ scheme: e.scheme
157
145
  });
158
146
  }
159
147
  /**
160
148
  * Serializes a [Encryption] to its RWPM JSON representation.
161
149
  */
162
150
  serialize() {
163
- const t = { algorithm: this.algorithm };
164
- return this.compression !== void 0 && (t.compression = this.compression), this.originalLength !== void 0 && (t.originalLength = this.originalLength), this.profile !== void 0 && (t.profile = this.profile), this.scheme !== void 0 && (t.scheme = this.scheme), t;
151
+ const e = { algorithm: this.algorithm };
152
+ return this.compression !== void 0 && (e.compression = this.compression), this.originalLength !== void 0 && (e.originalLength = this.originalLength), this.profile !== void 0 && (e.profile = this.profile), this.scheme !== void 0 && (e.scheme = this.scheme), e;
165
153
  }
166
154
  }
167
- class w {
168
- constructor(t) {
169
- this.otherProperties = t;
155
+ class C {
156
+ constructor(e) {
157
+ this.otherProperties = e;
170
158
  }
171
159
  get page() {
172
160
  return this.otherProperties.page;
@@ -174,9 +162,9 @@ class w {
174
162
  /**
175
163
  * Creates a [Properties] from its RWPM JSON representation.
176
164
  */
177
- static deserialize(t) {
178
- if (t)
179
- return new w(t);
165
+ static deserialize(e) {
166
+ if (e)
167
+ return new C(e);
180
168
  }
181
169
  /**
182
170
  * Serializes a [Properties] to its RWPM JSON representation.
@@ -187,75 +175,75 @@ class w {
187
175
  /**
188
176
  * Makes a copy of this [Properties] after merging in the given additional other [properties].
189
177
  */
190
- add(t) {
191
- const e = Object.assign({}, this.otherProperties);
192
- for (const i in t)
193
- e[i] = t[i];
194
- return new w(e);
178
+ add(e) {
179
+ const t = Object.assign({}, this.otherProperties);
180
+ for (const i in e)
181
+ t[i] = e[i];
182
+ return new C(t);
195
183
  }
196
184
  }
197
- Object.defineProperty(w.prototype, "encryption", {
185
+ Object.defineProperty(C.prototype, "encryption", {
198
186
  get: function() {
199
- return rt.deserialize(this.otherProperties.encrypted);
187
+ return ue.deserialize(this.otherProperties.encrypted);
200
188
  }
201
189
  });
202
- function ce(s) {
203
- return s && s instanceof Array ? s : void 0;
190
+ function it(r) {
191
+ return r && Array.isArray(r) ? r : void 0;
204
192
  }
205
- function Ut(s) {
206
- return s && typeof s == "string" ? [s] : ce(s);
193
+ function He(r) {
194
+ return r && typeof r == "string" ? [r] : it(r);
207
195
  }
208
- function bt(s) {
209
- return typeof s == "string" ? new Date(s) : void 0;
196
+ function xe(r) {
197
+ return typeof r == "string" ? new Date(r) : void 0;
210
198
  }
211
- function q(s) {
212
- return isNaN(s) ? void 0 : s;
199
+ function X(r) {
200
+ return isNaN(r) ? void 0 : r;
213
201
  }
214
- function T(s) {
215
- return q(s) !== void 0 && Math.sign(s) >= 0 ? s : void 0;
202
+ function S(r) {
203
+ return X(r) !== void 0 && Math.sign(r) >= 0 ? r : void 0;
216
204
  }
217
- function ue(s) {
218
- const t = new Array();
219
- return s.forEach((e) => t.push(e)), t;
205
+ function st(r) {
206
+ const e = new Array();
207
+ return r.forEach((t) => e.push(t)), e;
220
208
  }
221
209
  class a {
222
210
  /** Creates a MediaType object. */
223
- constructor(t) {
224
- let e, i, r = t.mediaType.replace(/\s/g, "").split(";");
225
- const n = r[0].split("/");
211
+ constructor(e) {
212
+ let t, i, s = e.mediaType.replace(/\s/g, "").split(";");
213
+ const n = s[0].split("/");
226
214
  if (n.length === 2) {
227
- if (e = n[0].toLowerCase().trim(), i = n[1].toLowerCase().trim(), e.length === 0 || i.length === 0)
215
+ if (t = n[0].toLowerCase().trim(), i = n[1].toLowerCase().trim(), t.length === 0 || i.length === 0)
228
216
  throw new Error("Invalid media type");
229
217
  } else
230
218
  throw new Error("Invalid media type");
231
219
  const o = {};
232
- for (let d = 1; d < r.length; d++) {
233
- const f = r[d].split("=");
234
- if (f.length === 2) {
235
- const g = f[0].toLocaleLowerCase(), m = g === "charset" ? f[1].toUpperCase() : f[1];
236
- o[g] = m;
220
+ for (let p = 1; p < s.length; p++) {
221
+ const y = s[p].split("=");
222
+ if (y.length === 2) {
223
+ const d = y[0].toLocaleLowerCase(), f = d === "charset" ? y[1].toUpperCase() : y[1];
224
+ o[d] = f;
237
225
  }
238
226
  }
239
- const l = {}, c = Object.keys(o);
240
- c.sort((d, f) => d.localeCompare(f)), c.forEach((d) => l[d] = o[d]);
227
+ const l = {}, u = Object.keys(o);
228
+ u.sort((p, y) => p.localeCompare(y)), u.forEach((p) => l[p] = o[p]);
241
229
  let h = "";
242
- for (const d in l) {
243
- const f = l[d];
244
- h += `;${d}=${f}`;
230
+ for (const p in l) {
231
+ const y = l[p];
232
+ h += `;${p}=${y}`;
245
233
  }
246
- const u = `${e}/${i}${h}`, p = l.encoding;
247
- this.string = u, this.type = e, this.subtype = i, this.parameters = l, this.encoding = p, this.name = t.name, this.fileExtension = t.fileExtension;
234
+ const c = `${t}/${i}${h}`, m = l.encoding;
235
+ this.string = c, this.type = t, this.subtype = i, this.parameters = l, this.encoding = m, this.name = e.name, this.fileExtension = e.fileExtension;
248
236
  }
249
- static parse(t) {
250
- return new a(t);
237
+ static parse(e) {
238
+ return new a(e);
251
239
  }
252
240
  /** Structured syntax suffix, e.g. `+zip` in `application/epub+zip`.
253
241
  * Gives a hint on the underlying structure of this media type.
254
242
  * See. https://tools.ietf.org/html/rfc6838#section-4.2.8
255
243
  */
256
244
  get structuredSyntaxSuffix() {
257
- const t = this.subtype.split("+");
258
- return t.length > 1 ? `+${t[t.length - 1]}` : void 0;
245
+ const e = this.subtype.split("+");
246
+ return e.length > 1 ? `+${e[e.length - 1]}` : void 0;
259
247
  }
260
248
  /** Parameter values might or might not be case-sensitive, depending on the semantics of
261
249
  * the parameter name.
@@ -276,17 +264,17 @@ class a {
276
264
  * - Order of parameters is ignored.
277
265
  * - Wildcards are supported, meaning that `image/*` contains `image/png`
278
266
  */
279
- contains(t) {
280
- const e = typeof t == "string" ? a.parse({ mediaType: t }) : t;
281
- if (!((this.type === "*" || this.type === e.type) && (this.subtype === "*" || this.subtype === e.subtype)))
267
+ contains(e) {
268
+ const t = typeof e == "string" ? a.parse({ mediaType: e }) : e;
269
+ if (!((this.type === "*" || this.type === t.type) && (this.subtype === "*" || this.subtype === t.subtype)))
282
270
  return !1;
283
271
  const i = new Set(
284
272
  Object.entries(this.parameters).map(([n, o]) => `${n}=${o}`)
285
- ), r = new Set(
286
- Object.entries(e.parameters).map(([n, o]) => `${n}=${o}`)
273
+ ), s = new Set(
274
+ Object.entries(t.parameters).map(([n, o]) => `${n}=${o}`)
287
275
  );
288
276
  for (const n of Array.from(i.values()))
289
- if (!r.has(n))
277
+ if (!s.has(n))
290
278
  return !1;
291
279
  return !0;
292
280
  }
@@ -295,22 +283,22 @@ class a {
295
283
  * For example, `text/html` matches `text/html;charset=utf-8`, but `text/html;charset=ascii`
296
284
  * doesn't. This is basically like `contains`, but working in both direction.
297
285
  */
298
- matches(t) {
299
- const e = typeof t == "string" ? a.parse({ mediaType: t }) : t;
300
- return this.contains(e) || e.contains(this);
286
+ matches(e) {
287
+ const t = typeof e == "string" ? a.parse({ mediaType: e }) : e;
288
+ return this.contains(t) || t.contains(this);
301
289
  }
302
290
  /**
303
291
  * Returns whether this media type matches any of the [others] media types.
304
292
  */
305
- matchesAny(...t) {
306
- for (const e of t)
307
- if (this.matches(e))
293
+ matchesAny(...e) {
294
+ for (const t of e)
295
+ if (this.matches(t))
308
296
  return !0;
309
297
  return !1;
310
298
  }
311
299
  /** Checks the MediaType equals another one (comparing their string) */
312
- equals(t) {
313
- return this.string === t.string;
300
+ equals(e) {
301
+ return this.string === e.string;
314
302
  }
315
303
  /** Returns whether this media type is structured as a ZIP archive. */
316
304
  get isZIP() {
@@ -673,61 +661,60 @@ class a {
673
661
  });
674
662
  }
675
663
  }
676
- class Et {
677
- constructor(t) {
678
- this.uri = t, this.parameters = this.getParameters(t);
664
+ class Te {
665
+ constructor(e) {
666
+ this.uri = e, this.parameters = this.getParameters(e);
679
667
  }
680
668
  /**
681
669
  * List of URI template parameter keys, if the [Link] is templated.
682
670
  */
683
- getParameters(t) {
684
- const e = /\{\??([^}]+)\}/g, i = t.match(e);
671
+ getParameters(e) {
672
+ const t = /\{\??([^}]+)\}/g, i = e.match(t);
685
673
  return i ? new Set(
686
- i.join(",").replace(e, "$1").split(",").map((r) => r.trim())
674
+ i.join(",").replace(t, "$1").split(",").map((s) => s.trim())
687
675
  ) : /* @__PURE__ */ new Set();
688
676
  }
689
677
  /** Expands the URI by replacing the template variables by the given parameters.
690
678
  * Any extra parameter is appended as query parameters.
691
679
  * See RFC 6570 on URI template: https://tools.ietf.org/html/rfc6570
692
680
  */
693
- expand(t) {
694
- const e = (r) => r.split(",").map((n) => {
695
- const o = t[n];
681
+ expand(e) {
682
+ const t = (s) => s.split(",").map((n) => {
683
+ const o = e[n];
696
684
  return o ? encodeURIComponent(o) : "";
697
- }).join(","), i = (r) => "?" + r.split(",").map((n) => {
698
- const o = n.split("=")[0], l = t[o];
685
+ }).join(","), i = (s) => "?" + s.split(",").map((n) => {
686
+ const o = n.split("=")[0], l = e[o];
699
687
  return l ? `${o}=${encodeURIComponent(l)}` : "";
700
688
  }).join("&");
701
- return this.uri.replace(/\{(\??)([^}]+)\}/g, (...r) => r[1] ? i(r[2]) : e(r[2]));
689
+ return this.uri.replace(/\{(\??)([^}]+)\}/g, (...s) => s[1] ? i(s[2]) : t(s[2]));
702
690
  }
703
691
  }
704
- class E {
692
+ class b {
705
693
  /**
706
694
  * Creates a [Locations].
707
695
  */
708
- constructor(t) {
709
- this.fragments = t.fragments ? t.fragments : new Array(), this.progression = t.progression, this.totalProgression = t.totalProgression, this.position = t.position, this.otherLocations = t.otherLocations;
696
+ constructor(e) {
697
+ this.fragments = e.fragments ? e.fragments : new Array(), this.progression = e.progression, this.totalProgression = e.totalProgression, this.position = e.position, this.otherLocations = e.otherLocations;
710
698
  }
711
699
  /**
712
700
  * Parses a [Locations] from its RWPM JSON representation.
713
701
  */
714
- static deserialize(t) {
715
- if (!t)
716
- return;
717
- const e = q(t.progression), i = q(t.totalProgression), r = q(t.position), n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set([
702
+ static deserialize(e) {
703
+ if (!e) return;
704
+ const t = X(e.progression), i = X(e.totalProgression), s = X(e.position), n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set([
718
705
  "fragment",
719
706
  "fragments",
720
707
  "progression",
721
708
  "totalProgression",
722
709
  "position"
723
710
  ]);
724
- return Object.entries(t).forEach(([l, c]) => {
725
- o.has(l) || n.set(l, c);
726
- }), new E({
727
- fragments: Ut(t.fragments || t.fragment),
728
- progression: e !== void 0 && e >= 0 && e <= 1 ? e : void 0,
711
+ return Object.entries(e).forEach(([l, u]) => {
712
+ o.has(l) || n.set(l, u);
713
+ }), new b({
714
+ fragments: He(e.fragments || e.fragment),
715
+ progression: t !== void 0 && t >= 0 && t <= 1 ? t : void 0,
729
716
  totalProgression: i !== void 0 && i >= 0 && i <= 1 ? i : void 0,
730
- position: r !== void 0 && r > 0 ? r : void 0,
717
+ position: s !== void 0 && s > 0 ? s : void 0,
731
718
  otherLocations: n.size === 0 ? void 0 : n
732
719
  });
733
720
  }
@@ -735,111 +722,111 @@ class E {
735
722
  * Serializes a [Locations] to its RWPM JSON representation.
736
723
  */
737
724
  serialize() {
738
- const t = {};
739
- return this.fragments && (t.fragments = this.fragments), this.progression !== void 0 && (t.progression = this.progression), this.totalProgression !== void 0 && (t.totalProgression = this.totalProgression), this.position !== void 0 && (t.position = this.position), this.otherLocations && this.otherLocations.forEach((e, i) => t[i] = e), t;
725
+ const e = {};
726
+ return this.fragments && (e.fragments = this.fragments), this.progression !== void 0 && (e.progression = this.progression), this.totalProgression !== void 0 && (e.totalProgression = this.totalProgression), this.position !== void 0 && (e.position = this.position), this.otherLocations && this.otherLocations.forEach((t, i) => e[i] = t), e;
740
727
  }
741
728
  }
742
- class $ {
729
+ class z {
743
730
  /**
744
731
  * Creates a [Text].
745
732
  */
746
- constructor(t) {
747
- this.after = t.after, this.before = t.before, this.highlight = t.highlight;
733
+ constructor(e) {
734
+ this.after = e.after, this.before = e.before, this.highlight = e.highlight;
748
735
  }
749
736
  /**
750
737
  * Parses a [Locations] from its RWPM JSON representation.
751
738
  */
752
- static deserialize(t) {
753
- if (t)
754
- return new $({
755
- after: t.after,
756
- before: t.before,
757
- highlight: t.highlight
739
+ static deserialize(e) {
740
+ if (e)
741
+ return new z({
742
+ after: e.after,
743
+ before: e.before,
744
+ highlight: e.highlight
758
745
  });
759
746
  }
760
747
  /**
761
748
  * Serializes a [Locations] to its RWPM JSON representation.
762
749
  */
763
750
  serialize() {
764
- const t = {};
765
- return this.after !== void 0 && (t.after = this.after), this.before !== void 0 && (t.before = this.before), this.highlight !== void 0 && (t.highlight = this.highlight), t;
751
+ const e = {};
752
+ return this.after !== void 0 && (e.after = this.after), this.before !== void 0 && (e.before = this.before), this.highlight !== void 0 && (e.highlight = this.highlight), e;
766
753
  }
767
754
  }
768
- class W {
755
+ class L {
769
756
  /**
770
757
  * Creates a [Locator].
771
758
  */
772
- constructor(t) {
773
- this.href = t.href, this.type = t.type, this.title = t.title, this.locations = t.locations ? t.locations : new E({}), this.text = t.text;
759
+ constructor(e) {
760
+ this.href = e.href, this.type = e.type, this.title = e.title, this.locations = e.locations ? e.locations : new b({}), this.text = e.text;
774
761
  }
775
762
  /**
776
763
  * Parses a [Link] from its RWPM JSON representation.
777
764
  */
778
- static deserialize(t) {
779
- if (t && t.href && t.type)
780
- return new W({
781
- href: t.href,
782
- type: t.type,
783
- title: t.title,
784
- locations: E.deserialize(t.locations),
785
- text: $.deserialize(t.text)
765
+ static deserialize(e) {
766
+ if (e && e.href && e.type)
767
+ return new L({
768
+ href: e.href,
769
+ type: e.type,
770
+ title: e.title,
771
+ locations: b.deserialize(e.locations),
772
+ text: z.deserialize(e.text)
786
773
  });
787
774
  }
788
775
  /**
789
776
  * Serializes a [Link] to its RWPM JSON representation.
790
777
  */
791
778
  serialize() {
792
- const t = { href: this.href, type: this.type };
793
- return this.title !== void 0 && (t.title = this.title), this.locations && (t.locations = this.locations.serialize()), this.text && (t.text = this.text.serialize()), t;
779
+ const e = { href: this.href, type: this.type };
780
+ return this.title !== void 0 && (e.title = this.title), this.locations && (e.locations = this.locations.serialize()), this.text && (e.text = this.text.serialize()), e;
794
781
  }
795
782
  /**
796
783
  * Shortcut to get a copy of the [Locator] with different [Locations] sub-properties.
797
784
  */
798
- copyWithLocations(t) {
799
- return new W({
785
+ copyWithLocations(e) {
786
+ return new L({
800
787
  href: this.href,
801
788
  type: this.type,
802
789
  title: this.title,
803
790
  text: this.text,
804
- locations: new E({ ...this.locations, ...t })
791
+ locations: new b({ ...this.locations, ...e })
805
792
  });
806
793
  }
807
794
  }
808
- class k {
795
+ class F {
809
796
  /**
810
797
  * Creates a [Link].
811
798
  */
812
- constructor(t) {
813
- this.href = t.href, this.templated = t.templated, this.type = t.type, this.title = t.title, this.rels = t.rels, this.properties = t.properties, this.height = t.height, this.width = t.width, this.size = t.size, this.duration = t.duration, this.bitrate = t.bitrate, this.languages = t.languages, this.alternates = t.alternates, this.children = t.children;
799
+ constructor(e) {
800
+ this.href = e.href, this.templated = e.templated, this.type = e.type, this.title = e.title, this.rels = e.rels, this.properties = e.properties, this.height = e.height, this.width = e.width, this.size = e.size, this.duration = e.duration, this.bitrate = e.bitrate, this.languages = e.languages, this.alternates = e.alternates, this.children = e.children;
814
801
  }
815
802
  /**
816
803
  * Parses a [Link] from its RWPM JSON representation.
817
804
  */
818
- static deserialize(t) {
819
- if (!(!t || typeof t.href != "string"))
820
- return new k({
821
- href: t.href,
822
- templated: t.templated,
823
- type: t.type,
824
- title: t.title,
825
- rels: t.rel ? t.rel instanceof Array ? new Set(t.rel) : /* @__PURE__ */ new Set([t.rel]) : void 0,
826
- properties: w.deserialize(t.properties),
827
- height: T(t.height),
828
- width: T(t.width),
829
- size: T(t.size),
830
- duration: T(t.duration),
831
- bitrate: T(t.bitrate),
832
- languages: Ut(t.language),
833
- alternates: _.deserialize(t.alternate),
834
- children: _.deserialize(t.children)
805
+ static deserialize(e) {
806
+ if (!(!e || typeof e.href != "string"))
807
+ return new F({
808
+ href: e.href,
809
+ templated: e.templated,
810
+ type: e.type,
811
+ title: e.title,
812
+ rels: e.rel ? Array.isArray(e.rel) ? new Set(e.rel) : /* @__PURE__ */ new Set([e.rel]) : void 0,
813
+ properties: C.deserialize(e.properties),
814
+ height: S(e.height),
815
+ width: S(e.width),
816
+ size: S(e.size),
817
+ duration: S(e.duration),
818
+ bitrate: S(e.bitrate),
819
+ languages: He(e.language),
820
+ alternates: _.deserialize(e.alternate),
821
+ children: _.deserialize(e.children)
835
822
  });
836
823
  }
837
824
  /**
838
825
  * Serializes a [Link] to its RWPM JSON representation.
839
826
  */
840
827
  serialize() {
841
- const t = { href: this.href };
842
- return this.templated !== void 0 && (t.templated = this.templated), this.type !== void 0 && (t.type = this.type), this.title !== void 0 && (t.title = this.title), this.rels && (t.rel = ue(this.rels)), this.properties && (t.properties = this.properties.serialize()), this.height !== void 0 && (t.height = this.height), this.width !== void 0 && (t.width = this.width), this.size !== void 0 && (t.size = this.size), this.duration !== void 0 && (t.duration = this.duration), this.bitrate !== void 0 && (t.bitrate = this.bitrate), this.languages && (t.language = this.languages), this.alternates && (t.alternate = this.alternates.serialize()), this.children && (t.children = this.children.serialize()), t;
828
+ const e = { href: this.href };
829
+ 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 = st(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.size !== void 0 && (e.size = this.size), 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;
843
830
  }
844
831
  /** MediaType of the linked resource. */
845
832
  get mediaType() {
@@ -848,45 +835,43 @@ class k {
848
835
  /** Computes an absolute URL to the link, relative to the given `baseURL`.
849
836
  * If the link's `href` is already absolute, the `baseURL` is ignored.
850
837
  */
851
- toURL(t) {
852
- const e = this.href.replace(/^(\/)/, "");
853
- if (e.length === 0)
854
- return;
855
- let i = t || "/";
856
- return i.startsWith("/") && (i = "file://" + i), new URL(e, i).href.replace(/^(file:\/\/)/, "");
838
+ toURL(e) {
839
+ const t = this.href.replace(/^(\/)/, "");
840
+ if (t.length === 0) return;
841
+ let i = e || "/";
842
+ return i.startsWith("/") && (i = "file://" + i), new URL(t, i).href.replace(/^(file:\/\/)/, "");
857
843
  }
858
844
  /** List of URI template parameter keys, if the `Link` is templated. */
859
845
  get templateParameters() {
860
- return this.templated ? new Et(this.href).parameters : /* @__PURE__ */ new Set();
846
+ return this.templated ? new Te(this.href).parameters : /* @__PURE__ */ new Set();
861
847
  }
862
848
  /** Expands the `Link`'s HREF by replacing URI template variables by the given parameters.
863
849
  * See RFC 6570 on URI template: https://tools.ietf.org/html/rfc6570
864
850
  */
865
- expandTemplate(t) {
866
- return new k({
867
- href: new Et(this.href).expand(t),
851
+ expandTemplate(e) {
852
+ return new F({
853
+ href: new Te(this.href).expand(e),
868
854
  templated: !1
869
855
  });
870
856
  }
871
857
  /**
872
858
  * Makes a copy of this [Link] after merging in the given additional other [properties].
873
859
  */
874
- addProperties(t) {
875
- var e;
876
- const i = k.deserialize(this.serialize());
877
- return i.properties = i.properties ? (e = i.properties) == null ? void 0 : e.add(t) : new w(t), i;
860
+ addProperties(e) {
861
+ const t = F.deserialize(this.serialize());
862
+ return t.properties = t.properties ? t.properties?.add(e) : new C(e), t;
878
863
  }
879
864
  /**
880
865
  * Creates a [Locator] from a reading order [Link].
881
866
  */
882
867
  get locator() {
883
- let t = this.href.split("#");
884
- return new W({
885
- href: t.length > 0 && t[0] !== void 0 ? t[0] : this.href,
868
+ let e = this.href.split("#");
869
+ return new L({
870
+ href: e.length > 0 && e[0] !== void 0 ? e[0] : this.href,
886
871
  type: this.type ?? "",
887
872
  title: this.title,
888
- locations: new E({
889
- fragments: t.length > 1 && t[1] !== void 0 ? [t[1]] : []
873
+ locations: new b({
874
+ fragments: e.length > 1 && e[1] !== void 0 ? [e[1]] : []
890
875
  })
891
876
  });
892
877
  }
@@ -895,119 +880,117 @@ class _ {
895
880
  /**
896
881
  * Creates a [Links].
897
882
  */
898
- constructor(t) {
899
- this.items = t;
883
+ constructor(e) {
884
+ this.items = e;
900
885
  }
901
886
  /**
902
887
  * Creates a list of [Link] from its RWPM JSON representation.
903
888
  */
904
- static deserialize(t) {
905
- if (t && t instanceof Array)
889
+ static deserialize(e) {
890
+ if (e && Array.isArray(e))
906
891
  return new _(
907
- t.map((e) => k.deserialize(e)).filter((e) => e !== void 0)
892
+ e.map((t) => F.deserialize(t)).filter((t) => t !== void 0)
908
893
  );
909
894
  }
910
895
  /**
911
896
  * Serializes an array of [Link] to its RWPM JSON representation.
912
897
  */
913
898
  serialize() {
914
- return this.items.map((t) => t.serialize());
899
+ return this.items.map((e) => e.serialize());
915
900
  }
916
901
  /** Finds the first link with the given relation. */
917
- findWithRel(t) {
918
- const e = (i) => i.rels && i.rels.has(t);
919
- return this.items.find(e);
902
+ findWithRel(e) {
903
+ const t = (i) => i.rels && i.rels.has(e);
904
+ return this.items.find(t);
920
905
  }
921
906
  /** Finds all the links with the given relation. */
922
- filterByRel(t) {
923
- const e = (i) => i.rels && i.rels.has(t);
924
- return this.items.filter(e);
907
+ filterByRel(e) {
908
+ const t = (i) => i.rels && i.rels.has(e);
909
+ return this.items.filter(t);
925
910
  }
926
911
  /** Finds the first link matching the given HREF. */
927
- findWithHref(t) {
928
- const e = (i) => i.href === t;
929
- return this.items.find(e);
912
+ findWithHref(e) {
913
+ const t = (i) => i.href === e;
914
+ return this.items.find(t);
930
915
  }
931
916
  /** Finds the index of the first link matching the given HREF. */
932
- findIndexWithHref(t) {
933
- const e = (i) => i.href === t;
934
- return this.items.findIndex(e);
917
+ findIndexWithHref(e) {
918
+ const t = (i) => i.href === e;
919
+ return this.items.findIndex(t);
935
920
  }
936
921
  /** Finds the first link matching the given media type. */
937
- findWithMediaType(t) {
938
- const e = (i) => i.mediaType.matches(t);
939
- return this.items.find(e);
922
+ findWithMediaType(e) {
923
+ const t = (i) => i.mediaType.matches(e);
924
+ return this.items.find(t);
940
925
  }
941
926
  /** Finds all the links matching the given media type. */
942
- filterByMediaType(t) {
943
- const e = (i) => i.mediaType.matches(t);
944
- return this.items.filter(e);
927
+ filterByMediaType(e) {
928
+ const t = (i) => i.mediaType.matches(e);
929
+ return this.items.filter(t);
945
930
  }
946
931
  /** Finds all the links matching any of the given media types. */
947
- filterByMediaTypes(t) {
948
- const e = (i) => {
949
- for (const r of t)
950
- if (i.mediaType.matches(r))
932
+ filterByMediaTypes(e) {
933
+ const t = (i) => {
934
+ for (const s of e)
935
+ if (i.mediaType.matches(s))
951
936
  return !0;
952
937
  return !1;
953
938
  };
954
- return this.items.filter(e);
939
+ return this.items.filter(t);
955
940
  }
956
941
  /** Returns whether all the resources in the collection are audio clips. */
957
942
  everyIsAudio() {
958
- const t = (e) => e.mediaType.isAudio;
959
- return this.items.length > 0 && this.items.every(t);
943
+ const e = (t) => t.mediaType.isAudio;
944
+ return this.items.length > 0 && this.items.every(e);
960
945
  }
961
946
  /** Returns whether all the resources in the collection are bitmaps. */
962
947
  everyIsBitmap() {
963
- const t = (e) => e.mediaType.isBitmap;
964
- return this.items.length > 0 && this.items.every(t);
948
+ const e = (t) => t.mediaType.isBitmap;
949
+ return this.items.length > 0 && this.items.every(e);
965
950
  }
966
951
  /** Returns whether all the resources in the collection are HTML documents. */
967
952
  everyIsHTML() {
968
- const t = (e) => e.mediaType.isHTML;
969
- return this.items.length > 0 && this.items.every(t);
953
+ const e = (t) => t.mediaType.isHTML;
954
+ return this.items.length > 0 && this.items.every(e);
970
955
  }
971
956
  /** Returns whether all the resources in the collection are video clips. */
972
957
  everyIsVideo() {
973
- const t = (e) => e.mediaType.isVideo;
974
- return this.items.length > 0 && this.items.every(t);
958
+ const e = (t) => t.mediaType.isVideo;
959
+ return this.items.length > 0 && this.items.every(e);
975
960
  }
976
961
  /** Returns whether all the resources in the collection are matching any of the given media types. */
977
- everyMatchesMediaType(t) {
978
- return Array.isArray(t) ? this.items.length > 0 && this.items.every((e) => {
979
- for (const i of t)
980
- return e.mediaType.matches(i);
962
+ everyMatchesMediaType(e) {
963
+ return Array.isArray(e) ? this.items.length > 0 && this.items.every((t) => {
964
+ for (const i of e)
965
+ return t.mediaType.matches(i);
981
966
  return !1;
982
- }) : this.items.length > 0 && this.items.every((e) => e.mediaType.matches(t));
967
+ }) : this.items.length > 0 && this.items.every((t) => t.mediaType.matches(e));
983
968
  }
984
969
  filterLinksHasType() {
985
- return this.items.filter((t) => t.type);
970
+ return this.items.filter((e) => e.type);
986
971
  }
987
972
  }
988
- w.prototype.getContains = function() {
973
+ C.prototype.getContains = function() {
989
974
  return new Set(this.otherProperties.contains || []);
990
975
  };
991
- class X {
976
+ class G {
992
977
  /**
993
978
  * Creates a [DomRange].
994
979
  */
995
- constructor(t) {
996
- this.cssSelector = t.cssSelector, this.textNodeIndex = t.textNodeIndex, this.charOffset = t.charOffset;
980
+ constructor(e) {
981
+ this.cssSelector = e.cssSelector, this.textNodeIndex = e.textNodeIndex, this.charOffset = e.charOffset;
997
982
  }
998
983
  /**
999
984
  * Parses a [DomRangePoint] from its RWPM JSON representation.
1000
985
  */
1001
- static deserialize(t) {
1002
- if (!(t && t.cssSelector))
1003
- return;
1004
- let e = T(t.textNodeIndex);
1005
- if (e === void 0)
1006
- return;
1007
- let i = T(t.charOffset);
1008
- return i === void 0 && (i = T(t.offset)), new X({
1009
- cssSelector: t.cssSelector,
1010
- textNodeIndex: e,
986
+ static deserialize(e) {
987
+ if (!(e && e.cssSelector)) return;
988
+ let t = S(e.textNodeIndex);
989
+ if (t === void 0) return;
990
+ let i = S(e.charOffset);
991
+ return i === void 0 && (i = S(e.offset)), new G({
992
+ cssSelector: e.cssSelector,
993
+ textNodeIndex: t,
1011
994
  charOffset: i
1012
995
  });
1013
996
  }
@@ -1015,106 +998,97 @@ class X {
1015
998
  * Serializes a [DomRangePoint] to its RWPM JSON representation.
1016
999
  */
1017
1000
  serialize() {
1018
- const t = {
1001
+ const e = {
1019
1002
  cssSelector: this.cssSelector,
1020
1003
  textNodeIndex: this.textNodeIndex
1021
1004
  };
1022
- return this.charOffset !== void 0 && (t.charOffset = this.charOffset), t;
1005
+ return this.charOffset !== void 0 && (e.charOffset = this.charOffset), e;
1023
1006
  }
1024
1007
  }
1025
- class nt {
1008
+ class de {
1026
1009
  /**
1027
1010
  * Creates a [DomRange].
1028
1011
  */
1029
- constructor(t) {
1030
- this.start = t.start, this.end = t.end;
1012
+ constructor(e) {
1013
+ this.start = e.start, this.end = e.end;
1031
1014
  }
1032
1015
  /**
1033
1016
  * Parses a [DomRange] from its RWPM JSON representation.
1034
1017
  */
1035
- static deserialize(t) {
1036
- if (!t)
1037
- return;
1038
- let e = X.deserialize(t.start);
1039
- if (e)
1040
- return new nt({
1041
- start: e,
1042
- end: X.deserialize(t.end)
1018
+ static deserialize(e) {
1019
+ if (!e) return;
1020
+ let t = G.deserialize(e.start);
1021
+ if (t)
1022
+ return new de({
1023
+ start: t,
1024
+ end: G.deserialize(e.end)
1043
1025
  });
1044
1026
  }
1045
1027
  /**
1046
1028
  * Serializes a [DomRange] to its RWPM JSON representation.
1047
1029
  */
1048
1030
  serialize() {
1049
- const t = { start: this.start.serialize() };
1050
- return this.end && (t.end = this.end.serialize()), t;
1031
+ const e = { start: this.start.serialize() };
1032
+ return this.end && (e.end = this.end.serialize()), e;
1051
1033
  }
1052
1034
  }
1053
- E.prototype.getCssSelector = function() {
1054
- var s;
1055
- return (s = this.otherLocations) == null ? void 0 : s.get("cssSelector");
1035
+ b.prototype.getCssSelector = function() {
1036
+ return this.otherLocations?.get("cssSelector");
1056
1037
  };
1057
- E.prototype.getPartialCfi = function() {
1058
- var s;
1059
- return (s = this.otherLocations) == null ? void 0 : s.get("partialCfi");
1038
+ b.prototype.getPartialCfi = function() {
1039
+ return this.otherLocations?.get("partialCfi");
1060
1040
  };
1061
- E.prototype.getDomRange = function() {
1062
- var s;
1063
- return nt.deserialize((s = this.otherLocations) == null ? void 0 : s.get("domRange"));
1041
+ b.prototype.getDomRange = function() {
1042
+ return de.deserialize(this.otherLocations?.get("domRange"));
1064
1043
  };
1065
- E.prototype.fragmentParameters = function() {
1044
+ b.prototype.fragmentParameters = function() {
1066
1045
  return new Map(
1067
- this.fragments.map((s) => s.startsWith("#") ? s.slice(1) : s).join("&").split("&").filter((s) => !s.startsWith("#")).map((s) => s.split("=")).filter((s) => s.length === 2).map((s) => [
1068
- s[0].trim().toLowerCase(),
1069
- s[1].trim()
1046
+ this.fragments.map((r) => r.startsWith("#") ? r.slice(1) : r).join("&").split("&").filter((r) => !r.startsWith("#")).map((r) => r.split("=")).filter((r) => r.length === 2).map((r) => [
1047
+ r[0].trim().toLowerCase(),
1048
+ r[1].trim()
1070
1049
  ])
1071
1050
  );
1072
1051
  };
1073
- E.prototype.htmlId = function() {
1074
- if (!this.fragments.length)
1075
- return;
1076
- let s = this.fragments.find((t) => t.length && !t.includes("="));
1077
- if (!s) {
1078
- const t = this.fragmentParameters();
1079
- t.has("id") ? s = t.get("id") : t.has("name") && (s = t.get("name"));
1080
- }
1081
- return s != null && s.startsWith("#") ? s.slice(1) : s;
1052
+ b.prototype.htmlId = function() {
1053
+ if (!this.fragments.length) return;
1054
+ let r = this.fragments.find((e) => e.length && !e.includes("="));
1055
+ if (!r) {
1056
+ const e = this.fragmentParameters();
1057
+ e.has("id") ? r = e.get("id") : e.has("name") && (r = e.get("name"));
1058
+ }
1059
+ return r?.startsWith("#") ? r.slice(1) : r;
1082
1060
  };
1083
- E.prototype.page = function() {
1084
- const s = parseInt(this.fragmentParameters().get("page"));
1085
- if (!isNaN(s) && s >= 0)
1086
- return s;
1061
+ b.prototype.page = function() {
1062
+ const r = parseInt(this.fragmentParameters().get("page"));
1063
+ if (!isNaN(r) && r >= 0) return r;
1087
1064
  };
1088
- E.prototype.time = function() {
1089
- const s = parseInt(this.fragmentParameters().get("t"));
1090
- if (!isNaN(s))
1091
- return s;
1065
+ b.prototype.time = function() {
1066
+ const r = parseInt(this.fragmentParameters().get("t"));
1067
+ if (!isNaN(r)) return r;
1092
1068
  };
1093
- E.prototype.space = function() {
1094
- const s = this.fragmentParameters();
1095
- if (!s.has("xywh"))
1096
- return;
1097
- const t = s.get("xywh").split(",").map((e) => parseInt(e));
1098
- if (t.length === 4 && !t.some(isNaN))
1099
- return t;
1069
+ b.prototype.space = function() {
1070
+ const r = this.fragmentParameters();
1071
+ if (!r.has("xywh")) return;
1072
+ const e = r.get("xywh").split(",").map((t) => parseInt(t));
1073
+ if (e.length === 4 && !e.some(isNaN))
1074
+ return e;
1100
1075
  };
1101
- class ot {
1076
+ class pe {
1102
1077
  /** Creates a [Price]. */
1103
- constructor(t) {
1104
- this.currency = t.currency, this.value = t.value;
1078
+ constructor(e) {
1079
+ this.currency = e.currency, this.value = e.value;
1105
1080
  }
1106
1081
  /**
1107
1082
  * Parses a [Price] from its RWPM JSON representation.
1108
1083
  */
1109
- static deserialize(t) {
1110
- if (!t)
1111
- return;
1112
- let e = t.currency;
1113
- if (!(e && typeof e == "string" && e.length > 0))
1084
+ static deserialize(e) {
1085
+ if (!e) return;
1086
+ let t = e.currency;
1087
+ if (!(t && typeof t == "string" && t.length > 0))
1114
1088
  return;
1115
- let i = T(t.value);
1089
+ let i = S(e.value);
1116
1090
  if (i !== void 0)
1117
- return new ot({ currency: e, value: i });
1091
+ return new pe({ currency: t, value: i });
1118
1092
  }
1119
1093
  /**
1120
1094
  * Serializes a [Price] to its RWPM JSON representation.
@@ -1123,417 +1097,402 @@ class ot {
1123
1097
  return { currency: this.currency, value: this.value };
1124
1098
  }
1125
1099
  }
1126
- class V {
1100
+ class B {
1127
1101
  /** Creates a [Acquisition]. */
1128
- constructor(t) {
1129
- this.type = t.type, this.children = t.children;
1102
+ constructor(e) {
1103
+ this.type = e.type, this.children = e.children;
1130
1104
  }
1131
1105
  /**
1132
1106
  * Parses a [Acquisition] from its RWPM JSON representation.
1133
1107
  */
1134
- static deserialize(t) {
1135
- if (t && t.type)
1136
- return new V({
1137
- type: t.type,
1138
- children: V.deserializeArray(t.children)
1108
+ static deserialize(e) {
1109
+ if (e && e.type)
1110
+ return new B({
1111
+ type: e.type,
1112
+ children: B.deserializeArray(e.children)
1139
1113
  });
1140
1114
  }
1141
- static deserializeArray(t) {
1142
- if (t instanceof Array)
1143
- return t.map((e) => V.deserialize(e)).filter((e) => e !== void 0);
1115
+ static deserializeArray(e) {
1116
+ if (Array.isArray(e))
1117
+ return e.map((t) => B.deserialize(t)).filter((t) => t !== void 0);
1144
1118
  }
1145
1119
  /**
1146
1120
  * Serializes a [Acquisition] to its RWPM JSON representation.
1147
1121
  */
1148
1122
  serialize() {
1149
- const t = { type: this.type };
1150
- return this.children && (t.children = this.children.map((e) => e.serialize())), t;
1123
+ const e = { type: this.type };
1124
+ return this.children && (e.children = this.children.map((t) => t.serialize())), e;
1151
1125
  }
1152
1126
  }
1153
- class at {
1127
+ class fe {
1154
1128
  /** Creates a [Price]. */
1155
- constructor(t) {
1156
- this.total = t.total, this.position = t.position;
1129
+ constructor(e) {
1130
+ this.total = e.total, this.position = e.position;
1157
1131
  }
1158
1132
  /**
1159
1133
  * Parses a [Holds] from its RWPM JSON representation.
1160
1134
  */
1161
- static deserialize(t) {
1162
- if (t)
1163
- return new at({
1164
- total: T(t.total),
1165
- position: T(t.position)
1135
+ static deserialize(e) {
1136
+ if (e)
1137
+ return new fe({
1138
+ total: S(e.total),
1139
+ position: S(e.position)
1166
1140
  });
1167
1141
  }
1168
1142
  /**
1169
1143
  * Serializes a [Holds] to its RWPM JSON representation.
1170
1144
  */
1171
1145
  serialize() {
1172
- const t = {};
1173
- return this.total !== void 0 && (t.total = this.total), this.position !== void 0 && (t.position = this.position), t;
1146
+ const e = {};
1147
+ return this.total !== void 0 && (e.total = this.total), this.position !== void 0 && (e.position = this.position), e;
1174
1148
  }
1175
1149
  }
1176
- class lt {
1150
+ class me {
1177
1151
  /** Creates a [Copies]. */
1178
- constructor(t) {
1179
- this.total = t.total, this.available = t.available;
1152
+ constructor(e) {
1153
+ this.total = e.total, this.available = e.available;
1180
1154
  }
1181
1155
  /**
1182
1156
  * Parses a [Copies] from its RWPM JSON representation.
1183
1157
  */
1184
- static deserialize(t) {
1185
- if (t)
1186
- return new lt({
1187
- total: T(t.total),
1188
- available: T(t.available)
1158
+ static deserialize(e) {
1159
+ if (e)
1160
+ return new me({
1161
+ total: S(e.total),
1162
+ available: S(e.available)
1189
1163
  });
1190
1164
  }
1191
1165
  /**
1192
1166
  * Serializes a [Copies] to its RWPM JSON representation.
1193
1167
  */
1194
1168
  serialize() {
1195
- const t = {};
1196
- return this.total !== void 0 && (t.total = this.total), this.available !== void 0 && (t.available = this.available), t;
1169
+ const e = {};
1170
+ return this.total !== void 0 && (e.total = this.total), this.available !== void 0 && (e.available = this.available), e;
1197
1171
  }
1198
1172
  }
1199
- class ht {
1173
+ class ge {
1200
1174
  /** Creates a [Availability]. */
1201
- constructor(t) {
1202
- this.state = t.state, this.since = t.since, this.until = t.until;
1175
+ constructor(e) {
1176
+ this.state = e.state, this.since = e.since, this.until = e.until;
1203
1177
  }
1204
1178
  /**
1205
1179
  * Parses a [Availability] from its RWPM JSON representation.
1206
1180
  */
1207
- static deserialize(t) {
1208
- if (t && t.state)
1209
- return new ht({
1210
- state: t.state,
1211
- since: bt(t.since),
1212
- until: bt(t.until)
1181
+ static deserialize(e) {
1182
+ if (e && e.state)
1183
+ return new ge({
1184
+ state: e.state,
1185
+ since: xe(e.since),
1186
+ until: xe(e.until)
1213
1187
  });
1214
1188
  }
1215
1189
  /**
1216
1190
  * Serializes a [Availability] to its RWPM JSON representation.
1217
1191
  */
1218
1192
  serialize() {
1219
- const t = { state: this.state };
1220
- return this.since !== void 0 && (t.since = this.since.toISOString()), this.until !== void 0 && (t.until = this.until.toISOString()), t;
1193
+ const e = { state: this.state };
1194
+ return this.since !== void 0 && (e.since = this.since.toISOString()), this.until !== void 0 && (e.until = this.until.toISOString()), e;
1221
1195
  }
1222
1196
  }
1223
- w.prototype.getNumberOfItems = function() {
1224
- return T(this.otherProperties.numberOfItems);
1197
+ C.prototype.getNumberOfItems = function() {
1198
+ return S(this.otherProperties.numberOfItems);
1225
1199
  };
1226
- w.prototype.getPrice = function() {
1227
- return ot.deserialize(this.otherProperties.price);
1200
+ C.prototype.getPrice = function() {
1201
+ return pe.deserialize(this.otherProperties.price);
1228
1202
  };
1229
- w.prototype.getIndirectAcquisitions = function() {
1230
- const s = this.otherProperties.indirectAcquisition;
1231
- if (s && s instanceof Array)
1232
- return s.map((t) => V.deserialize(t)).filter((t) => t !== void 0);
1203
+ C.prototype.getIndirectAcquisitions = function() {
1204
+ const r = this.otherProperties.indirectAcquisition;
1205
+ if (r && Array.isArray(r))
1206
+ return r.map((e) => B.deserialize(e)).filter((e) => e !== void 0);
1233
1207
  };
1234
- w.prototype.getHolds = function() {
1235
- return at.deserialize(this.otherProperties.holds);
1208
+ C.prototype.getHolds = function() {
1209
+ return fe.deserialize(this.otherProperties.holds);
1236
1210
  };
1237
- w.prototype.getCopies = function() {
1238
- return lt.deserialize(this.otherProperties.copies);
1211
+ C.prototype.getCopies = function() {
1212
+ return me.deserialize(this.otherProperties.copies);
1239
1213
  };
1240
- w.prototype.getAvailability = function() {
1241
- return ht.deserialize(this.otherProperties.availability);
1214
+ C.prototype.getAvailability = function() {
1215
+ return ge.deserialize(this.otherProperties.availability);
1242
1216
  };
1243
- w.prototype.getAuthenticate = function() {
1244
- return k.deserialize(this.otherProperties.authenticate);
1217
+ C.prototype.getAuthenticate = function() {
1218
+ return F.deserialize(this.otherProperties.authenticate);
1245
1219
  };
1246
- var z;
1247
- (function(s) {
1248
- s.NONE = "none", s.DESCENDANT = "descendant", s.CHILD = "child";
1249
- })(z || (z = {}));
1250
- var M;
1251
- (function(s) {
1252
- s.id = "id", s.class = "class", s.tag = "tag", s.attribute = "attribute", s.nthchild = "nthchild", s.nthoftype = "nthoftype";
1253
- })(M || (M = {}));
1254
- const de = "CssSelectorGenerator";
1255
- function xt(s = "unknown problem", ...t) {
1256
- console.warn(`${de}: ${s}`, ...t);
1257
- }
1258
- M.id, M.class, M.tag, M.attribute, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY;
1259
- function pe(s) {
1260
- return s instanceof RegExp;
1261
- }
1262
- function fe(s) {
1263
- return s.replace(/[|\\{}()[\]^$+?.]/g, "\\$&").replace(/\*/g, ".+");
1264
- }
1265
- function me(s) {
1266
- const t = s.map((e) => {
1267
- if (pe(e))
1268
- return (i) => e.test(i);
1269
- if (typeof e == "function")
1220
+ const rt = "CssSelectorGenerator";
1221
+ function we(r = "unknown problem", ...e) {
1222
+ console.warn(`${rt}: ${r}`, ...e);
1223
+ }
1224
+ function nt(r) {
1225
+ return r instanceof RegExp;
1226
+ }
1227
+ function ot(r) {
1228
+ return r.replace(/[|\\{}()[\]^$+?.]/g, "\\$&").replace(/\*/g, ".+");
1229
+ }
1230
+ function at(r) {
1231
+ const e = r.map((t) => {
1232
+ if (nt(t))
1233
+ return (i) => t.test(i);
1234
+ if (typeof t == "function")
1270
1235
  return (i) => {
1271
- const r = e(i);
1272
- return typeof r != "boolean" ? (xt("pattern matcher function invalid", "Provided pattern matching function does not return boolean. It's result will be ignored.", e), !1) : r;
1236
+ const s = t(i);
1237
+ return typeof s != "boolean" ? (we("pattern matcher function invalid", "Provided pattern matching function does not return boolean. It's result will be ignored.", t), !1) : s;
1273
1238
  };
1274
- if (typeof e == "string") {
1275
- const i = new RegExp("^" + fe(e) + "$");
1276
- return (r) => i.test(r);
1239
+ if (typeof t == "string") {
1240
+ const i = new RegExp("^" + ot(t) + "$");
1241
+ return (s) => i.test(s);
1277
1242
  }
1278
- return xt("pattern matcher invalid", "Pattern matching only accepts strings, regular expressions and/or functions. This item is invalid and will be ignored.", e), () => !1;
1243
+ return we("pattern matcher invalid", "Pattern matching only accepts strings, regular expressions and/or functions. This item is invalid and will be ignored.", t), () => !1;
1279
1244
  });
1280
- return (e) => t.some((i) => i(e));
1245
+ return (t) => e.some((i) => i(t));
1281
1246
  }
1282
- const ge = "", ye = " > ", ve = " ";
1283
- z.NONE + "", z.NONE, z.DESCENDANT + "", z.DESCENDANT, z.CHILD + "", z.CHILD;
1284
- M.nthoftype, M.tag, M.id, M.class, M.attribute, M.nthchild;
1285
- me([
1247
+ at([
1286
1248
  "class",
1287
1249
  "id",
1288
1250
  // Angular attributes
1289
1251
  "ng-*"
1290
1252
  ]);
1291
- class K {
1253
+ class j {
1292
1254
  }
1293
- function St(s) {
1294
- return s.split("").reverse().join("");
1255
+ function Se(r) {
1256
+ return r.split("").reverse().join("");
1295
1257
  }
1296
- function be(s, t, e) {
1297
- const i = St(t);
1298
- return e.map((r) => {
1299
- const n = Math.max(0, r.end - t.length - r.errors), o = St(s.slice(n, r.end));
1258
+ function lt(r, e, t) {
1259
+ const i = Se(e);
1260
+ return t.map((s) => {
1261
+ const n = Math.max(0, s.end - e.length - s.errors), o = Se(r.slice(n, s.end));
1300
1262
  return {
1301
- start: Bt(o, i, r.errors).reduce((c, h) => r.end - h.end < c ? r.end - h.end : c, r.end),
1302
- end: r.end,
1303
- errors: r.errors
1263
+ start: $e(o, i, s.errors).reduce((u, h) => s.end - h.end < u ? s.end - h.end : u, s.end),
1264
+ end: s.end,
1265
+ errors: s.errors
1304
1266
  };
1305
1267
  });
1306
1268
  }
1307
- function Q(s) {
1308
- return (s | -s) >> 31 & 1;
1269
+ function te(r) {
1270
+ return (r | -r) >> 31 & 1;
1309
1271
  }
1310
- function Tt(s, t, e, i) {
1311
- let r = s.P[e], n = s.M[e];
1312
- const o = i >>> 31, l = t[e] | o, c = l | n, h = (l & r) + r ^ r | l;
1313
- let u = n | ~(h | r), p = r & h;
1314
- const d = Q(u & s.lastRowMask[e]) - Q(p & s.lastRowMask[e]);
1315
- return u <<= 1, p <<= 1, p |= o, u |= Q(i) - o, r = p | ~(c | u), n = u & c, s.P[e] = r, s.M[e] = n, d;
1272
+ function Ce(r, e, t, i) {
1273
+ let s = r.P[t], n = r.M[t];
1274
+ const o = i >>> 31, l = e[t] | o, u = l | n, h = (l & s) + s ^ s | l;
1275
+ let c = n | ~(h | s), m = s & h;
1276
+ const p = te(c & r.lastRowMask[t]) - te(m & r.lastRowMask[t]);
1277
+ return c <<= 1, m <<= 1, m |= o, c |= te(i) - o, s = m | ~(u | c), n = c & u, r.P[t] = s, r.M[t] = n, p;
1316
1278
  }
1317
- function Bt(s, t, e) {
1318
- if (t.length === 0)
1279
+ function $e(r, e, t) {
1280
+ if (e.length === 0)
1319
1281
  return [];
1320
- e = Math.min(e, t.length);
1321
- const i = [], r = 32, n = Math.ceil(t.length / r) - 1, o = {
1282
+ t = Math.min(t, e.length);
1283
+ const i = [], s = 32, n = Math.ceil(e.length / s) - 1, o = {
1322
1284
  P: new Uint32Array(n + 1),
1323
1285
  M: new Uint32Array(n + 1),
1324
1286
  lastRowMask: new Uint32Array(n + 1)
1325
1287
  };
1326
- o.lastRowMask.fill(1 << 31), o.lastRowMask[n] = 1 << (t.length - 1) % r;
1327
- const l = new Uint32Array(n + 1), c = /* @__PURE__ */ new Map(), h = [];
1328
- for (let d = 0; d < 256; d++)
1288
+ o.lastRowMask.fill(1 << 31), o.lastRowMask[n] = 1 << (e.length - 1) % s;
1289
+ const l = new Uint32Array(n + 1), u = /* @__PURE__ */ new Map(), h = [];
1290
+ for (let p = 0; p < 256; p++)
1329
1291
  h.push(l);
1330
- for (let d = 0; d < t.length; d += 1) {
1331
- const f = t.charCodeAt(d);
1332
- if (c.has(f))
1292
+ for (let p = 0; p < e.length; p += 1) {
1293
+ const y = e.charCodeAt(p);
1294
+ if (u.has(y))
1333
1295
  continue;
1334
- const g = new Uint32Array(n + 1);
1335
- c.set(f, g), f < h.length && (h[f] = g);
1336
- for (let m = 0; m <= n; m += 1) {
1337
- g[m] = 0;
1338
- for (let v = 0; v < r; v += 1) {
1339
- const x = m * r + v;
1340
- if (x >= t.length)
1296
+ const d = new Uint32Array(n + 1);
1297
+ u.set(y, d), y < h.length && (h[y] = d);
1298
+ for (let f = 0; f <= n; f += 1) {
1299
+ d[f] = 0;
1300
+ for (let g = 0; g < s; g += 1) {
1301
+ const E = f * s + g;
1302
+ if (E >= e.length)
1341
1303
  continue;
1342
- t.charCodeAt(x) === f && (g[m] |= 1 << v);
1304
+ e.charCodeAt(E) === y && (d[f] |= 1 << g);
1343
1305
  }
1344
1306
  }
1345
1307
  }
1346
- let u = Math.max(0, Math.ceil(e / r) - 1);
1347
- const p = new Uint32Array(n + 1);
1348
- for (let d = 0; d <= u; d += 1)
1349
- p[d] = (d + 1) * r;
1350
- p[n] = t.length;
1351
- for (let d = 0; d <= u; d += 1)
1352
- o.P[d] = -1, o.M[d] = 0;
1353
- for (let d = 0; d < s.length; d += 1) {
1354
- const f = s.charCodeAt(d);
1355
- let g;
1356
- f < h.length ? g = h[f] : (g = c.get(f), typeof g > "u" && (g = l));
1357
- let m = 0;
1358
- for (let v = 0; v <= u; v += 1)
1359
- m = Tt(o, g, v, m), p[v] += m;
1360
- if (p[u] - m <= e && u < n && (g[u + 1] & 1 || m < 0)) {
1361
- u += 1, o.P[u] = -1, o.M[u] = 0;
1362
- let v;
1363
- if (u === n) {
1364
- const x = t.length % r;
1365
- v = x === 0 ? r : x;
1308
+ let c = Math.max(0, Math.ceil(t / s) - 1);
1309
+ const m = new Uint32Array(n + 1);
1310
+ for (let p = 0; p <= c; p += 1)
1311
+ m[p] = (p + 1) * s;
1312
+ m[n] = e.length;
1313
+ for (let p = 0; p <= c; p += 1)
1314
+ o.P[p] = -1, o.M[p] = 0;
1315
+ for (let p = 0; p < r.length; p += 1) {
1316
+ const y = r.charCodeAt(p);
1317
+ let d;
1318
+ y < h.length ? d = h[y] : (d = u.get(y), typeof d > "u" && (d = l));
1319
+ let f = 0;
1320
+ for (let g = 0; g <= c; g += 1)
1321
+ f = Ce(o, d, g, f), m[g] += f;
1322
+ if (m[c] - f <= t && c < n && (d[c + 1] & 1 || f < 0)) {
1323
+ c += 1, o.P[c] = -1, o.M[c] = 0;
1324
+ let g;
1325
+ if (c === n) {
1326
+ const E = e.length % s;
1327
+ g = E === 0 ? s : E;
1366
1328
  } else
1367
- v = r;
1368
- p[u] = p[u - 1] + v - m + Tt(o, g, u, m);
1329
+ g = s;
1330
+ m[c] = m[c - 1] + g - f + Ce(o, d, c, f);
1369
1331
  } else
1370
- for (; u > 0 && p[u] >= e + r; )
1371
- u -= 1;
1372
- u === n && p[u] <= e && (p[u] < e && i.splice(0, i.length), i.push({
1332
+ for (; c > 0 && m[c] >= t + s; )
1333
+ c -= 1;
1334
+ c === n && m[c] <= t && (m[c] < t && i.splice(0, i.length), i.push({
1373
1335
  start: -1,
1374
- end: d + 1,
1375
- errors: p[u]
1376
- }), e = p[u]);
1336
+ end: p + 1,
1337
+ errors: m[c]
1338
+ }), t = m[c]);
1377
1339
  }
1378
1340
  return i;
1379
1341
  }
1380
- function Ee(s, t, e) {
1381
- const i = Bt(s, t, e);
1382
- return be(s, t, i);
1342
+ function ht(r, e, t) {
1343
+ const i = $e(r, e, t);
1344
+ return lt(r, e, i);
1383
1345
  }
1384
- function kt(s, t, e) {
1346
+ function ke(r, e, t) {
1385
1347
  let i = 0;
1386
- const r = [];
1348
+ const s = [];
1387
1349
  for (; i !== -1; )
1388
- i = s.indexOf(t, i), i !== -1 && (r.push({
1350
+ i = r.indexOf(e, i), i !== -1 && (s.push({
1389
1351
  start: i,
1390
- end: i + t.length,
1352
+ end: i + e.length,
1391
1353
  errors: 0
1392
1354
  }), i += 1);
1393
- return r.length > 0 ? r : Ee(s, t, e);
1355
+ return s.length > 0 ? s : ht(r, e, t);
1394
1356
  }
1395
- function wt(s, t) {
1396
- return t.length === 0 || s.length === 0 ? 0 : 1 - kt(s, t, t.length)[0].errors / t.length;
1357
+ function Pe(r, e) {
1358
+ return e.length === 0 || r.length === 0 ? 0 : 1 - ke(r, e, e.length)[0].errors / e.length;
1397
1359
  }
1398
- function xe(s, t, e = {}) {
1399
- if (t.length === 0)
1360
+ function ct(r, e, t = {}) {
1361
+ if (e.length === 0)
1400
1362
  return null;
1401
- const i = Math.min(256, t.length / 2), r = kt(s, t, i);
1402
- if (r.length === 0)
1363
+ const i = Math.min(256, e.length / 2), s = ke(r, e, i);
1364
+ if (s.length === 0)
1403
1365
  return null;
1404
1366
  const n = (l) => {
1405
- const d = 1 - l.errors / t.length, f = e.prefix ? wt(
1406
- s.slice(
1407
- Math.max(0, l.start - e.prefix.length),
1367
+ const p = 1 - l.errors / e.length, y = t.prefix ? Pe(
1368
+ r.slice(
1369
+ Math.max(0, l.start - t.prefix.length),
1408
1370
  l.start
1409
1371
  ),
1410
- e.prefix
1411
- ) : 1, g = e.suffix ? wt(
1412
- s.slice(l.end, l.end + e.suffix.length),
1413
- e.suffix
1372
+ t.prefix
1373
+ ) : 1, d = t.suffix ? Pe(
1374
+ r.slice(l.end, l.end + t.suffix.length),
1375
+ t.suffix
1414
1376
  ) : 1;
1415
- let m = 1;
1416
- typeof e.hint == "number" && (m = 1 - Math.abs(l.start - e.hint) / s.length);
1417
- const v = 50 * d + 20 * f + 20 * g + 2 * m, x = 50 + 20 + 20 + 2;
1418
- return v / x;
1419
- }, o = r.map((l) => ({
1377
+ let f = 1;
1378
+ return typeof t.hint == "number" && (f = 1 - Math.abs(l.start - t.hint) / r.length), (50 * p + 20 * y + 20 * d + 2 * f) / 92;
1379
+ }, o = s.map((l) => ({
1420
1380
  start: l.start,
1421
1381
  end: l.end,
1422
1382
  score: n(l)
1423
1383
  }));
1424
- return o.sort((l, c) => c.score - l.score), o[0];
1425
- }
1426
- function tt(s, t, e) {
1427
- const i = e === 1 ? t : t - 1;
1428
- if (s.charAt(i).trim() !== "")
1429
- return t;
1430
- let r, n;
1431
- if (e === 2 ? (r = s.substring(0, t), n = r.trimEnd()) : (r = s.substring(t), n = r.trimStart()), !n.length)
1384
+ return o.sort((l, u) => u.score - l.score), o[0];
1385
+ }
1386
+ function ie(r, e, t) {
1387
+ const i = t === 1 ? e : e - 1;
1388
+ if (r.charAt(i).trim() !== "")
1389
+ return e;
1390
+ let s, n;
1391
+ if (t === 2 ? (s = r.substring(0, e), n = s.trimEnd()) : (s = r.substring(e), n = s.trimStart()), !n.length)
1432
1392
  return -1;
1433
- const o = r.length - n.length;
1434
- return e === 2 ? t - o : t + o;
1393
+ const o = s.length - n.length;
1394
+ return t === 2 ? e - o : e + o;
1435
1395
  }
1436
- function Ct(s, t) {
1437
- const e = s.commonAncestorContainer.ownerDocument.createNodeIterator(
1438
- s.commonAncestorContainer,
1396
+ function Ae(r, e) {
1397
+ const t = r.commonAncestorContainer.ownerDocument.createNodeIterator(
1398
+ r.commonAncestorContainer,
1439
1399
  NodeFilter.SHOW_TEXT
1440
- ), i = t === 1 ? s.startContainer : s.endContainer, r = t === 1 ? s.endContainer : s.startContainer;
1441
- let n = e.nextNode();
1400
+ ), i = e === 1 ? r.startContainer : r.endContainer, s = e === 1 ? r.endContainer : r.startContainer;
1401
+ let n = t.nextNode();
1442
1402
  for (; n && n !== i; )
1443
- n = e.nextNode();
1444
- t === 2 && (n = e.previousNode());
1403
+ n = t.nextNode();
1404
+ e === 2 && (n = t.previousNode());
1445
1405
  let o = -1;
1446
1406
  const l = () => {
1447
- if (n = t === 1 ? e.nextNode() : e.previousNode(), n) {
1448
- const c = n.textContent, h = t === 1 ? 0 : c.length;
1449
- o = tt(c, h, t);
1407
+ if (n = e === 1 ? t.nextNode() : t.previousNode(), n) {
1408
+ const u = n.textContent, h = e === 1 ? 0 : u.length;
1409
+ o = ie(u, h, e);
1450
1410
  }
1451
1411
  };
1452
- for (; n && o === -1 && n !== r; )
1412
+ for (; n && o === -1 && n !== s; )
1453
1413
  l();
1454
1414
  if (n && o >= 0)
1455
1415
  return { node: n, offset: o };
1456
1416
  throw new RangeError("No text nodes with non-whitespace text found in range");
1457
1417
  }
1458
- function Se(s) {
1459
- if (!s.toString().trim().length)
1418
+ function ut(r) {
1419
+ if (!r.toString().trim().length)
1460
1420
  throw new RangeError("Range contains no non-whitespace text");
1461
- if (s.startContainer.nodeType !== Node.TEXT_NODE)
1421
+ if (r.startContainer.nodeType !== Node.TEXT_NODE)
1462
1422
  throw new RangeError("Range startContainer is not a text node");
1463
- if (s.endContainer.nodeType !== Node.TEXT_NODE)
1423
+ if (r.endContainer.nodeType !== Node.TEXT_NODE)
1464
1424
  throw new RangeError("Range endContainer is not a text node");
1465
- const t = s.cloneRange();
1466
- let e = !1, i = !1;
1467
- const r = {
1468
- start: tt(
1469
- s.startContainer.textContent,
1470
- s.startOffset,
1425
+ const e = r.cloneRange();
1426
+ let t = !1, i = !1;
1427
+ const s = {
1428
+ start: ie(
1429
+ r.startContainer.textContent,
1430
+ r.startOffset,
1471
1431
  1
1472
1432
  /* Forwards */
1473
1433
  ),
1474
- end: tt(
1475
- s.endContainer.textContent,
1476
- s.endOffset,
1434
+ end: ie(
1435
+ r.endContainer.textContent,
1436
+ r.endOffset,
1477
1437
  2
1478
1438
  /* Backwards */
1479
1439
  )
1480
1440
  };
1481
- if (r.start >= 0 && (t.setStart(s.startContainer, r.start), e = !0), r.end > 0 && (t.setEnd(s.endContainer, r.end), i = !0), e && i)
1482
- return t;
1483
- if (!e) {
1484
- const { node: n, offset: o } = Ct(
1485
- t,
1441
+ if (s.start >= 0 && (e.setStart(r.startContainer, s.start), t = !0), s.end > 0 && (e.setEnd(r.endContainer, s.end), i = !0), t && i)
1442
+ return e;
1443
+ if (!t) {
1444
+ const { node: n, offset: o } = Ae(
1445
+ e,
1486
1446
  1
1487
1447
  /* Forwards */
1488
1448
  );
1489
- n && o >= 0 && t.setStart(n, o);
1449
+ n && o >= 0 && e.setStart(n, o);
1490
1450
  }
1491
1451
  if (!i) {
1492
- const { node: n, offset: o } = Ct(
1493
- t,
1452
+ const { node: n, offset: o } = Ae(
1453
+ e,
1494
1454
  2
1495
1455
  /* Backwards */
1496
1456
  );
1497
- n && o > 0 && t.setEnd(n, o);
1457
+ n && o > 0 && e.setEnd(n, o);
1498
1458
  }
1499
- return t;
1459
+ return e;
1500
1460
  }
1501
- function $t(s) {
1502
- var t;
1503
- switch (s.nodeType) {
1461
+ function Ve(r) {
1462
+ switch (r.nodeType) {
1504
1463
  case Node.ELEMENT_NODE:
1505
1464
  case Node.TEXT_NODE:
1506
- return ((t = s.textContent) == null ? void 0 : t.length) ?? 0;
1465
+ return r.textContent?.length ?? 0;
1507
1466
  default:
1508
1467
  return 0;
1509
1468
  }
1510
1469
  }
1511
- function Pt(s) {
1512
- let t = s.previousSibling, e = 0;
1513
- for (; t; )
1514
- e += $t(t), t = t.previousSibling;
1515
- return e;
1470
+ function Me(r) {
1471
+ let e = r.previousSibling, t = 0;
1472
+ for (; e; )
1473
+ t += Ve(e), e = e.previousSibling;
1474
+ return t;
1516
1475
  }
1517
- function Ht(s, ...t) {
1518
- let e = t.shift();
1519
- const i = s.ownerDocument.createNodeIterator(
1520
- s,
1476
+ function je(r, ...e) {
1477
+ let t = e.shift();
1478
+ const i = r.ownerDocument.createNodeIterator(
1479
+ r,
1521
1480
  NodeFilter.SHOW_TEXT
1522
- ), r = [];
1481
+ ), s = [];
1523
1482
  let n = i.nextNode(), o, l = 0;
1524
- for (; e !== void 0 && n; )
1525
- o = n, l + o.data.length > e ? (r.push({ node: o, offset: e - l }), e = t.shift()) : (n = i.nextNode(), l += o.data.length);
1526
- for (; e !== void 0 && o && l === e; )
1527
- r.push({ node: o, offset: o.data.length }), e = t.shift();
1528
- if (e !== void 0)
1483
+ for (; t !== void 0 && n; )
1484
+ o = n, l + o.data.length > t ? (s.push({ node: o, offset: t - l }), t = e.shift()) : (n = i.nextNode(), l += o.data.length);
1485
+ for (; t !== void 0 && o && l === t; )
1486
+ s.push({ node: o, offset: o.data.length }), t = e.shift();
1487
+ if (t !== void 0)
1529
1488
  throw new RangeError("Offset exceeds text length");
1530
- return r;
1489
+ return s;
1531
1490
  }
1532
- class A {
1533
- constructor(t, e) {
1534
- if (e < 0)
1491
+ class M {
1492
+ constructor(e, t) {
1493
+ if (t < 0)
1535
1494
  throw new Error("Offset is invalid");
1536
- this.element = t, this.offset = e;
1495
+ this.element = e, this.offset = t;
1537
1496
  }
1538
1497
  /**
1539
1498
  * Return a copy of this position with offset relative to a given ancestor
@@ -1541,13 +1500,13 @@ class A {
1541
1500
  *
1542
1501
  * @param parent - Ancestor of `this.element`
1543
1502
  */
1544
- relativeTo(t) {
1545
- if (!t.contains(this.element))
1503
+ relativeTo(e) {
1504
+ if (!e.contains(this.element))
1546
1505
  throw new Error("Parent is not an ancestor of current element");
1547
- let e = this.element, i = this.offset;
1548
- for (; e !== t; )
1549
- i += Pt(e), e = e.parentElement;
1550
- return new A(e, i);
1506
+ let t = this.element, i = this.offset;
1507
+ for (; t !== e; )
1508
+ i += Me(t), t = t.parentElement;
1509
+ return new M(t, i);
1551
1510
  }
1552
1511
  /**
1553
1512
  * Resolve the position to a specific text node and offset within that node.
@@ -1566,34 +1525,34 @@ class A {
1566
1525
  *
1567
1526
  * @throws {RangeError}
1568
1527
  */
1569
- resolve(t = {}) {
1528
+ resolve(e = {}) {
1570
1529
  try {
1571
- return Ht(this.element, this.offset)[0];
1572
- } catch (e) {
1573
- if (this.offset === 0 && t.direction !== void 0) {
1530
+ return je(this.element, this.offset)[0];
1531
+ } catch (t) {
1532
+ if (this.offset === 0 && e.direction !== void 0) {
1574
1533
  const i = document.createTreeWalker(
1575
1534
  this.element.getRootNode(),
1576
1535
  NodeFilter.SHOW_TEXT
1577
1536
  );
1578
1537
  i.currentNode = this.element;
1579
- const r = t.direction === 1, n = r ? i.nextNode() : i.previousNode();
1538
+ const s = e.direction === 1, n = s ? i.nextNode() : i.previousNode();
1580
1539
  if (!n)
1581
- throw e;
1582
- return { node: n, offset: r ? 0 : n.data.length };
1540
+ throw t;
1541
+ return { node: n, offset: s ? 0 : n.data.length };
1583
1542
  } else
1584
- throw e;
1543
+ throw t;
1585
1544
  }
1586
1545
  }
1587
1546
  /**
1588
1547
  * Construct a `TextPosition` that refers to the `offset`th character within
1589
1548
  * `node`.
1590
1549
  */
1591
- static fromCharOffset(t, e) {
1592
- switch (t.nodeType) {
1550
+ static fromCharOffset(e, t) {
1551
+ switch (e.nodeType) {
1593
1552
  case Node.TEXT_NODE:
1594
- return A.fromPoint(t, e);
1553
+ return M.fromPoint(e, t);
1595
1554
  case Node.ELEMENT_NODE:
1596
- return new A(t, e);
1555
+ return new M(e, t);
1597
1556
  default:
1598
1557
  throw new Error("Node is not an element or text node");
1599
1558
  }
@@ -1604,42 +1563,42 @@ class A {
1604
1563
  * @param node
1605
1564
  * @param offset - Offset within the node
1606
1565
  */
1607
- static fromPoint(t, e) {
1608
- switch (t.nodeType) {
1566
+ static fromPoint(e, t) {
1567
+ switch (e.nodeType) {
1609
1568
  case Node.TEXT_NODE: {
1610
- if (e < 0 || e > t.data.length)
1569
+ if (t < 0 || t > e.data.length)
1611
1570
  throw new Error("Text node offset is out of range");
1612
- if (!t.parentElement)
1571
+ if (!e.parentElement)
1613
1572
  throw new Error("Text node has no parent");
1614
- const i = Pt(t) + e;
1615
- return new A(t.parentElement, i);
1573
+ const i = Me(e) + t;
1574
+ return new M(e.parentElement, i);
1616
1575
  }
1617
1576
  case Node.ELEMENT_NODE: {
1618
- if (e < 0 || e > t.childNodes.length)
1577
+ if (t < 0 || t > e.childNodes.length)
1619
1578
  throw new Error("Child node offset is out of range");
1620
1579
  let i = 0;
1621
- for (let r = 0; r < e; r++)
1622
- i += $t(t.childNodes[r]);
1623
- return new A(t, i);
1580
+ for (let s = 0; s < t; s++)
1581
+ i += Ve(e.childNodes[s]);
1582
+ return new M(e, i);
1624
1583
  }
1625
1584
  default:
1626
1585
  throw new Error("Point is not in an element or text node");
1627
1586
  }
1628
1587
  }
1629
1588
  }
1630
- class D {
1631
- constructor(t, e) {
1632
- this.start = t, this.end = e;
1589
+ class I {
1590
+ constructor(e, t) {
1591
+ this.start = e, this.end = t;
1633
1592
  }
1634
1593
  /**
1635
1594
  * Create a new TextRange whose `start` and `end` are computed relative to
1636
1595
  * `element`. `element` must be an ancestor of both `start.element` and
1637
1596
  * `end.element`.
1638
1597
  */
1639
- relativeTo(t) {
1640
- return new D(
1641
- this.start.relativeTo(t),
1642
- this.end.relativeTo(t)
1598
+ relativeTo(e) {
1599
+ return new I(
1600
+ this.start.relativeTo(e),
1601
+ this.end.relativeTo(e)
1643
1602
  );
1644
1603
  }
1645
1604
  /**
@@ -1652,63 +1611,63 @@ class D {
1652
1611
  * May throw if the `start` or `end` positions cannot be resolved to a range.
1653
1612
  */
1654
1613
  toRange() {
1655
- let t, e;
1656
- this.start.element === this.end.element && this.start.offset <= this.end.offset ? [t, e] = Ht(
1614
+ let e, t;
1615
+ this.start.element === this.end.element && this.start.offset <= this.end.offset ? [e, t] = je(
1657
1616
  this.start.element,
1658
1617
  this.start.offset,
1659
1618
  this.end.offset
1660
- ) : (t = this.start.resolve({
1619
+ ) : (e = this.start.resolve({
1661
1620
  direction: 1
1662
1621
  /* FORWARDS */
1663
- }), e = this.end.resolve({
1622
+ }), t = this.end.resolve({
1664
1623
  direction: 2
1665
1624
  /* BACKWARDS */
1666
1625
  }));
1667
1626
  const i = new Range();
1668
- return i.setStart(t.node, t.offset), i.setEnd(e.node, e.offset), i;
1627
+ return i.setStart(e.node, e.offset), i.setEnd(t.node, t.offset), i;
1669
1628
  }
1670
1629
  /**
1671
1630
  * Create a TextRange from a (DOM) Range
1672
1631
  */
1673
- static fromRange(t) {
1674
- const e = A.fromPoint(
1675
- t.startContainer,
1676
- t.startOffset
1677
- ), i = A.fromPoint(t.endContainer, t.endOffset);
1678
- return new D(e, i);
1632
+ static fromRange(e) {
1633
+ const t = M.fromPoint(
1634
+ e.startContainer,
1635
+ e.startOffset
1636
+ ), i = M.fromPoint(e.endContainer, e.endOffset);
1637
+ return new I(t, i);
1679
1638
  }
1680
1639
  /**
1681
1640
  * Create a TextRange representing the `start`th to `end`th characters in
1682
1641
  * `root`
1683
1642
  */
1684
- static fromOffsets(t, e, i) {
1685
- return new D(
1686
- new A(t, e),
1687
- new A(t, i)
1643
+ static fromOffsets(e, t, i) {
1644
+ return new I(
1645
+ new M(e, t),
1646
+ new M(e, i)
1688
1647
  );
1689
1648
  }
1690
1649
  /**
1691
1650
  * Return a new Range representing `range` trimmed of any leading or trailing
1692
1651
  * whitespace
1693
1652
  */
1694
- static trimmedRange(t) {
1695
- return Se(D.fromRange(t).toRange());
1653
+ static trimmedRange(e) {
1654
+ return ut(I.fromRange(e).toRange());
1696
1655
  }
1697
1656
  }
1698
- class G {
1699
- constructor(t, e, i) {
1700
- this.root = t, this.start = e, this.end = i;
1657
+ class Y {
1658
+ constructor(e, t, i) {
1659
+ this.root = e, this.start = t, this.end = i;
1701
1660
  }
1702
- static fromRange(t, e) {
1703
- const i = D.fromRange(e).relativeTo(t);
1704
- return new G(
1705
- t,
1661
+ static fromRange(e, t) {
1662
+ const i = I.fromRange(t).relativeTo(e);
1663
+ return new Y(
1664
+ e,
1706
1665
  i.start.offset,
1707
1666
  i.end.offset
1708
1667
  );
1709
1668
  }
1710
- static fromSelector(t, e) {
1711
- return new G(t, e.start, e.end);
1669
+ static fromSelector(e, t) {
1670
+ return new Y(e, t.start, t.end);
1712
1671
  }
1713
1672
  toSelector() {
1714
1673
  return {
@@ -1718,31 +1677,31 @@ class G {
1718
1677
  };
1719
1678
  }
1720
1679
  toRange() {
1721
- return D.fromOffsets(this.root, this.start, this.end).toRange();
1680
+ return I.fromOffsets(this.root, this.start, this.end).toRange();
1722
1681
  }
1723
1682
  }
1724
- class Y {
1683
+ class K {
1725
1684
  /**
1726
1685
  * @param root - A root element from which to anchor.
1727
1686
  */
1728
- constructor(t, e, i = {}) {
1729
- this.root = t, this.exact = e, this.context = i;
1687
+ constructor(e, t, i = {}) {
1688
+ this.root = e, this.exact = t, this.context = i;
1730
1689
  }
1731
1690
  /**
1732
1691
  * Create a `TextQuoteAnchor` from a range.
1733
1692
  *
1734
1693
  * Will throw if `range` does not contain any text nodes.
1735
1694
  */
1736
- static fromRange(t, e) {
1737
- const i = t.textContent, r = D.fromRange(e).relativeTo(t), n = r.start.offset, o = r.end.offset, l = 32;
1738
- return new Y(t, i.slice(n, o), {
1695
+ static fromRange(e, t) {
1696
+ const i = e.textContent, s = I.fromRange(t).relativeTo(e), n = s.start.offset, o = s.end.offset, l = 32;
1697
+ return new K(e, i.slice(n, o), {
1739
1698
  prefix: i.slice(Math.max(0, n - l), n),
1740
1699
  suffix: i.slice(o, Math.min(i.length, o + l))
1741
1700
  });
1742
1701
  }
1743
- static fromSelector(t, e) {
1744
- const { prefix: i, suffix: r } = e;
1745
- return new Y(t, e.exact, { prefix: i, suffix: r });
1702
+ static fromSelector(e, t) {
1703
+ const { prefix: i, suffix: s } = t;
1704
+ return new K(e, t.exact, { prefix: i, suffix: s });
1746
1705
  }
1747
1706
  toSelector() {
1748
1707
  return {
@@ -1752,30 +1711,30 @@ class Y {
1752
1711
  suffix: this.context.suffix
1753
1712
  };
1754
1713
  }
1755
- toRange(t = {}) {
1756
- return this.toPositionAnchor(t).toRange();
1714
+ toRange(e = {}) {
1715
+ return this.toPositionAnchor(e).toRange();
1757
1716
  }
1758
- toPositionAnchor(t = {}) {
1759
- const e = this.root.textContent, i = xe(e, this.exact, {
1717
+ toPositionAnchor(e = {}) {
1718
+ const t = this.root.textContent, i = ct(t, this.exact, {
1760
1719
  ...this.context,
1761
- hint: t.hint
1720
+ hint: e.hint
1762
1721
  });
1763
1722
  if (!i)
1764
1723
  throw new Error("Quote not found");
1765
- return new G(this.root, i.start, i.end);
1724
+ return new Y(this.root, i.start, i.end);
1766
1725
  }
1767
1726
  }
1768
- function Te(s) {
1769
- const t = s.tagName.toUpperCase();
1770
- return t === "IMG" || t === "VIDEO" || t === "AUDIO" || t === "IFRAME" || t === "OBJECT" || t === "EMBED" || t === "CANVAS";
1727
+ function dt(r) {
1728
+ const e = r.tagName.toUpperCase();
1729
+ return e === "IMG" || e === "VIDEO" || e === "AUDIO" || e === "IFRAME" || e === "OBJECT" || e === "EMBED" || e === "CANVAS";
1771
1730
  }
1772
- function ct(s, t) {
1731
+ function ee(r, e) {
1773
1732
  try {
1774
- const e = t.locations, i = t.text;
1733
+ const t = e.locations, i = e.text;
1775
1734
  if (i && i.highlight) {
1776
- let r;
1777
- e && e.getCssSelector() && (r = s.querySelector(e.getCssSelector())), r || (r = s.body);
1778
- const n = new Y(r, i.highlight, {
1735
+ let s;
1736
+ t && t.getCssSelector() && (s = r.querySelector(t.getCssSelector())), s || (s = r.body);
1737
+ const n = new K(s, i.highlight, {
1779
1738
  prefix: i.before,
1780
1739
  suffix: i.after
1781
1740
  });
@@ -1785,29 +1744,29 @@ function ct(s, t) {
1785
1744
  return console.warn("Quote not found:", n), null;
1786
1745
  }
1787
1746
  }
1788
- if (e) {
1789
- let r = null;
1790
- if (!r && e.getCssSelector() && (r = s.querySelector(e.getCssSelector())), !r && e.fragments) {
1791
- for (const n of e.fragments)
1792
- if (r = s.getElementById(n), r)
1747
+ if (t) {
1748
+ let s = null;
1749
+ if (!s && t.getCssSelector() && (s = r.querySelector(t.getCssSelector())), !s && t.fragments) {
1750
+ for (const n of t.fragments)
1751
+ if (s = r.getElementById(n), s)
1793
1752
  break;
1794
1753
  }
1795
- if (r) {
1796
- const n = s.createRange();
1797
- return r.childNodes.length === 0 || Te(r) ? (n.selectNode(r), n) : (n.setStartBefore(r), n.setEndAfter(r), n);
1754
+ if (s) {
1755
+ const n = r.createRange();
1756
+ return s.childNodes.length === 0 || dt(s) ? (n.selectNode(s), n) : (n.setStartBefore(s), n.setEndAfter(s), n);
1798
1757
  }
1799
1758
  }
1800
- } catch (e) {
1801
- console.error(e);
1759
+ } catch (t) {
1760
+ console.error(t);
1802
1761
  }
1803
1762
  return null;
1804
1763
  }
1805
- function we(s, t) {
1806
- let e = s.getClientRects();
1807
- e.length || s.commonAncestorContainer.nodeType === Node.ELEMENT_NODE && (e = s.commonAncestorContainer.getClientRects());
1808
- const i = 1, r = [];
1809
- for (const h of e)
1810
- r.push({
1764
+ function pt(r, e) {
1765
+ let t = r.getClientRects();
1766
+ t.length || r.commonAncestorContainer.nodeType === Node.ELEMENT_NODE && (t = r.commonAncestorContainer.getClientRects());
1767
+ const i = 1, s = [];
1768
+ for (const h of t)
1769
+ s.push({
1811
1770
  bottom: h.bottom,
1812
1771
  height: h.height,
1813
1772
  left: h.left,
@@ -1815,14 +1774,13 @@ function we(s, t) {
1815
1774
  top: h.top,
1816
1775
  width: h.width
1817
1776
  });
1818
- const n = Vt(
1819
- r,
1820
- i,
1821
- t
1822
- ), o = Pe(n, i), l = jt(o), c = 2 * 2;
1777
+ const n = qe(
1778
+ s,
1779
+ i
1780
+ ), o = mt(n, i), l = Xe(o), u = 4;
1823
1781
  for (let h = l.length - 1; h >= 0; h--) {
1824
- const u = l[h];
1825
- if (!(u.width * u.height > c))
1782
+ const c = l[h];
1783
+ if (!(c.width * c.height > u))
1826
1784
  if (l.length > 1)
1827
1785
  l.splice(h, 1);
1828
1786
  else
@@ -1830,231 +1788,229 @@ function we(s, t) {
1830
1788
  }
1831
1789
  return l;
1832
1790
  }
1833
- function Vt(s, t, e) {
1834
- for (let i = 0; i < s.length; i++)
1835
- for (let r = i + 1; r < s.length; r++) {
1836
- const n = s[i], o = s[r];
1791
+ function qe(r, e, t) {
1792
+ for (let i = 0; i < r.length; i++)
1793
+ for (let s = i + 1; s < r.length; s++) {
1794
+ const n = r[i], o = r[s];
1837
1795
  if (n === o)
1838
1796
  continue;
1839
- const l = N(n.top, o.top, t) && N(n.bottom, o.bottom, t), c = N(n.left, o.left, t) && N(n.right, o.right, t);
1840
- if ((c && !e || l && !c) && qt(n, o, t)) {
1841
- const d = s.filter((g) => g !== n && g !== o), f = Ce(n, o);
1842
- return d.push(f), Vt(
1843
- d,
1844
- t,
1797
+ const l = P(n.top, o.top, e) && P(n.bottom, o.bottom, e), u = P(n.left, o.left, e) && P(n.right, o.right, e);
1798
+ if (l && !u && _e(n, o, e)) {
1799
+ const m = r.filter((y) => y !== n && y !== o), p = ft(n, o);
1800
+ return m.push(p), qe(
1801
+ m,
1845
1802
  e
1846
1803
  );
1847
1804
  }
1848
1805
  }
1849
- return s;
1806
+ return r;
1850
1807
  }
1851
- function Ce(s, t) {
1852
- const e = Math.min(s.left, t.left), i = Math.max(s.right, t.right), r = Math.min(s.top, t.top), n = Math.max(s.bottom, t.bottom);
1808
+ function ft(r, e) {
1809
+ const t = Math.min(r.left, e.left), i = Math.max(r.right, e.right), s = Math.min(r.top, e.top), n = Math.max(r.bottom, e.bottom);
1853
1810
  return {
1854
1811
  bottom: n,
1855
- height: n - r,
1856
- left: e,
1812
+ height: n - s,
1813
+ left: t,
1857
1814
  right: i,
1858
- top: r,
1859
- width: i - e
1815
+ top: s,
1816
+ width: i - t
1860
1817
  };
1861
1818
  }
1862
- function Pe(s, t) {
1863
- const e = new Set(s);
1864
- for (const i of s) {
1819
+ function mt(r, e) {
1820
+ const t = new Set(r);
1821
+ for (const i of r) {
1865
1822
  if (!(i.width > 1 && i.height > 1)) {
1866
- e.delete(i);
1823
+ t.delete(i);
1867
1824
  continue;
1868
1825
  }
1869
- for (const n of s)
1870
- if (i !== n && e.has(n) && Me(n, i, t)) {
1871
- e.delete(i);
1826
+ for (const n of r)
1827
+ if (i !== n && t.has(n) && gt(n, i, e)) {
1828
+ t.delete(i);
1872
1829
  break;
1873
1830
  }
1874
1831
  }
1875
- return Array.from(e);
1832
+ return Array.from(t);
1876
1833
  }
1877
- function Me(s, t, e) {
1878
- return j(s, t.left, t.top, e) && j(s, t.right, t.top, e) && j(s, t.left, t.bottom, e) && j(s, t.right, t.bottom, e);
1834
+ function gt(r, e, t) {
1835
+ return q(r, e.left, e.top, t) && q(r, e.right, e.top, t) && q(r, e.left, e.bottom, t) && q(r, e.right, e.bottom, t);
1879
1836
  }
1880
- function j(s, t, e, i) {
1881
- return (s.left < t || N(s.left, t, i)) && (s.right > t || N(s.right, t, i)) && (s.top < e || N(s.top, e, i)) && (s.bottom > e || N(s.bottom, e, i));
1837
+ function q(r, e, t, i) {
1838
+ return (r.left < e || P(r.left, e, i)) && (r.right > e || P(r.right, e, i)) && (r.top < t || P(r.top, t, i)) && (r.bottom > t || P(r.bottom, t, i));
1882
1839
  }
1883
- function jt(s) {
1884
- for (let t = 0; t < s.length; t++)
1885
- for (let e = t + 1; e < s.length; e++) {
1886
- const i = s[t], r = s[e];
1887
- if (i !== r && qt(i, r, -1)) {
1840
+ function Xe(r) {
1841
+ for (let e = 0; e < r.length; e++)
1842
+ for (let t = e + 1; t < r.length; t++) {
1843
+ const i = r[e], s = r[t];
1844
+ if (i !== s && _e(i, s, -1)) {
1888
1845
  let n = [], o;
1889
- const l = Mt(i, r);
1846
+ const l = Ne(i, s);
1890
1847
  if (l.length === 1)
1891
1848
  n = l, o = i;
1892
1849
  else {
1893
- const h = Mt(r, i);
1894
- l.length < h.length ? (n = l, o = i) : (n = h, o = r);
1850
+ const h = Ne(s, i);
1851
+ l.length < h.length ? (n = l, o = i) : (n = h, o = s);
1895
1852
  }
1896
- const c = s.filter((h) => h !== o);
1897
- return Array.prototype.push.apply(c, n), jt(c);
1853
+ const u = r.filter((h) => h !== o);
1854
+ return Array.prototype.push.apply(u, n), Xe(u);
1898
1855
  }
1899
1856
  }
1900
- return s;
1857
+ return r;
1901
1858
  }
1902
- function Mt(s, t) {
1903
- const e = Ne(t, s);
1904
- if (e.height === 0 || e.width === 0)
1905
- return [s];
1859
+ function Ne(r, e) {
1860
+ const t = yt(e, r);
1861
+ if (t.height === 0 || t.width === 0)
1862
+ return [r];
1906
1863
  const i = [];
1907
1864
  {
1908
- const r = {
1909
- bottom: s.bottom,
1865
+ const s = {
1866
+ bottom: r.bottom,
1910
1867
  height: 0,
1911
- left: s.left,
1912
- right: e.left,
1913
- top: s.top,
1868
+ left: r.left,
1869
+ right: t.left,
1870
+ top: r.top,
1914
1871
  width: 0
1915
1872
  };
1916
- r.width = r.right - r.left, r.height = r.bottom - r.top, r.height !== 0 && r.width !== 0 && i.push(r);
1873
+ s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && i.push(s);
1917
1874
  }
1918
1875
  {
1919
- const r = {
1920
- bottom: e.top,
1876
+ const s = {
1877
+ bottom: t.top,
1921
1878
  height: 0,
1922
- left: e.left,
1923
- right: e.right,
1924
- top: s.top,
1879
+ left: t.left,
1880
+ right: t.right,
1881
+ top: r.top,
1925
1882
  width: 0
1926
1883
  };
1927
- r.width = r.right - r.left, r.height = r.bottom - r.top, r.height !== 0 && r.width !== 0 && i.push(r);
1884
+ s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && i.push(s);
1928
1885
  }
1929
1886
  {
1930
- const r = {
1931
- bottom: s.bottom,
1887
+ const s = {
1888
+ bottom: r.bottom,
1932
1889
  height: 0,
1933
- left: e.left,
1934
- right: e.right,
1935
- top: e.bottom,
1890
+ left: t.left,
1891
+ right: t.right,
1892
+ top: t.bottom,
1936
1893
  width: 0
1937
1894
  };
1938
- r.width = r.right - r.left, r.height = r.bottom - r.top, r.height !== 0 && r.width !== 0 && i.push(r);
1895
+ s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && i.push(s);
1939
1896
  }
1940
1897
  {
1941
- const r = {
1942
- bottom: s.bottom,
1898
+ const s = {
1899
+ bottom: r.bottom,
1943
1900
  height: 0,
1944
- left: e.right,
1945
- right: s.right,
1946
- top: s.top,
1901
+ left: t.right,
1902
+ right: r.right,
1903
+ top: r.top,
1947
1904
  width: 0
1948
1905
  };
1949
- r.width = r.right - r.left, r.height = r.bottom - r.top, r.height !== 0 && r.width !== 0 && i.push(r);
1906
+ s.width = s.right - s.left, s.height = s.bottom - s.top, s.height !== 0 && s.width !== 0 && i.push(s);
1950
1907
  }
1951
1908
  return i;
1952
1909
  }
1953
- function Ne(s, t) {
1954
- const e = Math.max(s.left, t.left), i = Math.min(s.right, t.right), r = Math.max(s.top, t.top), n = Math.min(s.bottom, t.bottom);
1910
+ function yt(r, e) {
1911
+ const t = Math.max(r.left, e.left), i = Math.min(r.right, e.right), s = Math.max(r.top, e.top), n = Math.min(r.bottom, e.bottom);
1955
1912
  return {
1956
1913
  bottom: n,
1957
- height: Math.max(0, n - r),
1958
- left: e,
1914
+ height: Math.max(0, n - s),
1915
+ left: t,
1959
1916
  right: i,
1960
- top: r,
1961
- width: Math.max(0, i - e)
1917
+ top: s,
1918
+ width: Math.max(0, i - t)
1962
1919
  };
1963
1920
  }
1964
- function qt(s, t, e) {
1965
- return (s.left < t.right || e >= 0 && N(s.left, t.right, e)) && (t.left < s.right || e >= 0 && N(t.left, s.right, e)) && (s.top < t.bottom || e >= 0 && N(s.top, t.bottom, e)) && (t.top < s.bottom || e >= 0 && N(t.top, s.bottom, e));
1921
+ function _e(r, e, t) {
1922
+ return (r.left < e.right || t >= 0 && P(r.left, e.right, t)) && (e.left < r.right || t >= 0 && P(e.left, r.right, t)) && (r.top < e.bottom || t >= 0 && P(r.top, e.bottom, t)) && (e.top < r.bottom || t >= 0 && P(e.top, r.bottom, t));
1966
1923
  }
1967
- function N(s, t, e) {
1968
- return Math.abs(s - t) <= e;
1924
+ function P(r, e, t) {
1925
+ return Math.abs(r - e) <= t;
1969
1926
  }
1970
- function _t(s) {
1971
- const t = {}, e = s.document.documentElement.style;
1972
- for (const i in s.document.documentElement.style)
1973
- Object.hasOwn(e, i) && !Number.isNaN(Number.parseInt(i)) && (t[e[i]] = e.getPropertyValue(e[i]));
1974
- return t;
1927
+ function Ge(r) {
1928
+ const e = {}, t = r.document.documentElement.style;
1929
+ for (const i in r.document.documentElement.style)
1930
+ Object.hasOwn(t, i) && !Number.isNaN(Number.parseInt(i)) && (e[t[i]] = t.getPropertyValue(t[i]));
1931
+ return e;
1975
1932
  }
1976
- function Ae(s, t) {
1977
- const e = _t(s);
1978
- Object.keys(e).forEach((i) => {
1979
- t.hasOwnProperty(i) || ut(s, i);
1980
- }), Object.entries(t).forEach(([i, r]) => {
1981
- e[i] !== r && Z(s, i, r);
1933
+ function vt(r, e) {
1934
+ const t = Ge(r);
1935
+ Object.keys(t).forEach((i) => {
1936
+ e.hasOwnProperty(i) || ye(r, i);
1937
+ }), Object.entries(e).forEach(([i, s]) => {
1938
+ t[i] !== s && Z(r, i, s);
1982
1939
  });
1983
1940
  }
1984
- function Nt(s, t) {
1985
- return s.document.documentElement.style.getPropertyValue(t);
1941
+ function Oe(r, e) {
1942
+ return r.document.documentElement.style.getPropertyValue(e);
1986
1943
  }
1987
- function Z(s, t, e) {
1988
- s.document.documentElement.style.setProperty(t, e);
1944
+ function Z(r, e, t) {
1945
+ r.document.documentElement.style.setProperty(e, t);
1989
1946
  }
1990
- function ut(s, t) {
1991
- s.document.documentElement.style.removeProperty(t);
1947
+ function ye(r, e) {
1948
+ r.document.documentElement.style.removeProperty(e);
1992
1949
  }
1993
- const Oe = (s) => {
1994
- if (s.startsWith("rgb")) {
1995
- const t = s.match(/rgb\((\d+),\s(\d+),\s(\d+)(?:,\s(\d+))?\)/);
1996
- if (t)
1950
+ const bt = (r) => {
1951
+ if (r.startsWith("rgb")) {
1952
+ const e = r.match(/rgb\((\d+),\s(\d+),\s(\d+)(?:,\s(\d+))?\)/);
1953
+ if (e)
1997
1954
  return {
1998
- r: parseInt(t[1], 10),
1999
- g: parseInt(t[2], 10),
2000
- b: parseInt(t[3], 10),
2001
- a: t[4] ? parseInt(t[4], 10) / 255 : 1
1955
+ r: parseInt(e[1], 10),
1956
+ g: parseInt(e[2], 10),
1957
+ b: parseInt(e[3], 10),
1958
+ a: e[4] ? parseInt(e[4], 10) / 255 : 1
2002
1959
  };
2003
- } else if (s.startsWith("#")) {
2004
- const t = s.slice(1);
2005
- if (t.length === 3 || t.length === 4)
1960
+ } else if (r.startsWith("#")) {
1961
+ const e = r.slice(1);
1962
+ if (e.length === 3 || e.length === 4)
2006
1963
  return {
2007
- r: parseInt(t[0] + t[0], 16) / 255,
2008
- g: parseInt(t[1] + t[1], 16) / 255,
2009
- b: parseInt(t[2] + t[2], 16) / 255,
2010
- a: t.length === 4 ? parseInt(t[3] + t[3], 16) / 255 : 1
1964
+ r: parseInt(e[0] + e[0], 16) / 255,
1965
+ g: parseInt(e[1] + e[1], 16) / 255,
1966
+ b: parseInt(e[2] + e[2], 16) / 255,
1967
+ a: e.length === 4 ? parseInt(e[3] + e[3], 16) / 255 : 1
2011
1968
  };
2012
- if (t.length === 6 || t.length === 8)
1969
+ if (e.length === 6 || e.length === 8)
2013
1970
  return {
2014
- r: parseInt(t[0] + t[1], 16) / 255,
2015
- g: parseInt(t[2] + t[3], 16) / 255,
2016
- b: parseInt(t[4] + t[5], 16) / 255,
2017
- a: t.length === 8 ? parseInt(t[6] + t[7], 16) / 255 : 1
1971
+ r: parseInt(e[0] + e[1], 16) / 255,
1972
+ g: parseInt(e[2] + e[3], 16) / 255,
1973
+ b: parseInt(e[4] + e[5], 16) / 255,
1974
+ a: e.length === 8 ? parseInt(e[6] + e[7], 16) / 255 : 1
2018
1975
  };
2019
1976
  }
2020
1977
  return { r: 0, g: 0, b: 0, a: 1 };
2021
- }, Ie = (s) => 0.2126 * s.r * s.a + 0.7152 * s.g * s.a + 0.0722 * s.b * s.a, Le = (s) => {
2022
- const t = Oe(s);
2023
- return Ie(t) < 128;
1978
+ }, Et = (r) => 0.2126 * r.r * r.a + 0.7152 * r.g * r.a + 0.0722 * r.b * r.a, xt = (r) => {
1979
+ const e = bt(r);
1980
+ return Et(e) < 128;
2024
1981
  };
2025
- var Re = /* @__PURE__ */ ((s) => (s.Wrap = "wrap", s.Viewport = "viewport", s.Bounds = "bounds", s.Page = "page", s))(Re || {}), ze = /* @__PURE__ */ ((s) => (s.Boxes = "boxes", s.Bounds = "bounds", s))(ze || {});
2026
- const De = () => "Highlight" in window, At = ["IMG", "IMAGE", "AUDIO", "VIDEO", "SVG"];
2027
- class We {
1982
+ var Tt = /* @__PURE__ */ ((r) => (r.Wrap = "wrap", r.Viewport = "viewport", r.Bounds = "bounds", r.Page = "page", r))(Tt || {}), wt = /* @__PURE__ */ ((r) => (r.Boxes = "boxes", r.Bounds = "bounds", r))(wt || {});
1983
+ const St = () => "Highlight" in window, Le = ["IMG", "IMAGE", "AUDIO", "VIDEO", "SVG"];
1984
+ class Ct {
2028
1985
  /**
2029
1986
  * Creates a DecorationGroup object
2030
1987
  * @param id Unique HTML ID-adhering name of the group
2031
1988
  * @param name Human-readable name of the group
2032
1989
  */
2033
- constructor(t, e, i, r) {
2034
- this.wnd = t, this.comms = e, this.id = i, this.name = r, this.items = [], this.lastItemId = 0, this.container = void 0, this.activateable = !1, this.experimentalHighlights = !1, this.currentRender = 0, De() && (this.experimentalHighlights = !0, this.notTextFlag = /* @__PURE__ */ new Map());
1990
+ constructor(e, t, i, s) {
1991
+ this.wnd = e, this.comms = t, this.id = i, this.name = s, this.items = [], this.lastItemId = 0, this.container = void 0, this.activateable = !1, this.experimentalHighlights = !1, this.currentRender = 0, St() && (this.experimentalHighlights = !0, this.notTextFlag = /* @__PURE__ */ new Map());
2035
1992
  }
2036
1993
  get activeable() {
2037
1994
  return this.activateable;
2038
1995
  }
2039
- set activeable(t) {
2040
- this.activateable = t;
1996
+ set activeable(e) {
1997
+ this.activateable = e;
2041
1998
  }
2042
1999
  /**
2043
2000
  * Adds a new decoration to the group.
2044
2001
  * @param decoration Decoration to add
2045
2002
  */
2046
- add(t) {
2047
- var o, l, c, h;
2048
- const e = `${this.id}-${this.lastItemId++}`, i = ct(this.wnd.document, t.locator);
2003
+ add(e) {
2004
+ const t = `${this.id}-${this.lastItemId++}`, i = ee(this.wnd.document, e.locator);
2049
2005
  if (!i) {
2050
- this.comms.log("Can't locate DOM range for decoration", t);
2006
+ this.comms.log("Can't locate DOM range for decoration", e);
2051
2007
  return;
2052
2008
  }
2053
- const r = i.commonAncestorContainer;
2054
- r.nodeType !== Node.TEXT_NODE && this.experimentalHighlights && (At.includes(r.nodeName.toUpperCase()) && ((o = this.notTextFlag) == null || o.set(e, !0)), r.querySelector(At.join(", ").toLowerCase()) && ((l = this.notTextFlag) == null || l.set(e, !0)), (((c = r.textContent) == null ? void 0 : c.trim()) || "").length === 0 && ((h = this.notTextFlag) == null || h.set(e, !0)));
2009
+ const s = i.commonAncestorContainer;
2010
+ s.nodeType !== Node.TEXT_NODE && this.experimentalHighlights && (Le.includes(s.nodeName.toUpperCase()) && this.notTextFlag?.set(t, !0), s.querySelector(Le.join(", ").toLowerCase()) && this.notTextFlag?.set(t, !0), (s.textContent?.trim() || "").length === 0 && this.notTextFlag?.set(t, !0));
2055
2011
  const n = {
2056
- decoration: t,
2057
- id: e,
2012
+ decoration: e,
2013
+ id: t,
2058
2014
  range: i
2059
2015
  };
2060
2016
  this.items.push(n), this.layout(n), this.renderLayout([n]);
@@ -2063,132 +2019,116 @@ class We {
2063
2019
  * Removes the decoration with given ID from the group.
2064
2020
  * @param identifier ID of item to remove
2065
2021
  */
2066
- remove(t) {
2067
- var r, n;
2068
- const e = this.items.findIndex((o) => o.decoration.id === t);
2069
- if (e < 0)
2070
- return;
2071
- const i = this.items[e];
2072
- if (this.items.splice(e, 1), i.clickableElements = void 0, i.container && (i.container.remove(), i.container = void 0), this.experimentalHighlights && !((r = this.notTextFlag) != null && r.has(i.id))) {
2073
- const o = this.wnd.CSS.highlights.get(this.id);
2074
- o == null || o.delete(i.range);
2075
- }
2076
- (n = this.notTextFlag) == null || n.delete(i.id);
2022
+ remove(e) {
2023
+ const t = this.items.findIndex((s) => s.decoration.id === e);
2024
+ if (t < 0) return;
2025
+ const i = this.items[t];
2026
+ this.items.splice(t, 1), i.clickableElements = void 0, i.container && (i.container.remove(), i.container = void 0), this.experimentalHighlights && !this.notTextFlag?.has(i.id) && this.wnd.CSS.highlights.get(this.id)?.delete(i.range), this.notTextFlag?.delete(i.id);
2077
2027
  }
2078
2028
  /**
2079
2029
  * Notifies that the given decoration was modified and needs to be updated.
2080
2030
  * @param decoration Decoration to update
2081
2031
  */
2082
- update(t) {
2083
- this.remove(t.id), this.add(t);
2032
+ update(e) {
2033
+ this.remove(e.id), this.add(e);
2084
2034
  }
2085
2035
  /**
2086
2036
  * Removes all decorations from this group.
2087
2037
  */
2088
2038
  clear() {
2089
- var t;
2090
- this.clearContainer(), this.items.length = 0, (t = this.notTextFlag) == null || t.clear();
2039
+ this.clearContainer(), this.items.length = 0, this.notTextFlag?.clear();
2091
2040
  }
2092
2041
  /**
2093
2042
  * Recreates the decoration elements.
2094
2043
  * To be called after reflowing the resource, for example.
2095
2044
  */
2096
2045
  requestLayout() {
2097
- this.wnd.cancelAnimationFrame(this.currentRender), this.clearContainer(), this.items.forEach((t) => this.layout(t)), this.renderLayout(this.items);
2046
+ this.wnd.cancelAnimationFrame(this.currentRender), this.clearContainer(), this.items.forEach((e) => this.layout(e)), this.renderLayout(this.items);
2098
2047
  }
2099
- experimentalLayout(t) {
2100
- var r, n;
2101
- const [e, i] = this.requireContainer(!0);
2102
- i.add(t.range), e.innerHTML = `
2048
+ experimentalLayout(e) {
2049
+ const [t, i] = this.requireContainer(!0);
2050
+ i.add(e.range), t.innerHTML = `
2103
2051
  ::highlight(${this.id}) {
2104
2052
  color: black;
2105
- background-color: ${((n = (r = t.decoration) == null ? void 0 : r.style) == null ? void 0 : n.tint) ?? "yellow"};
2053
+ background-color: ${e.decoration?.style?.tint ?? "yellow"};
2106
2054
  }`;
2107
2055
  }
2108
2056
  /**
2109
2057
  * Layouts a single DecorationItem.
2110
2058
  * @param item
2111
2059
  */
2112
- layout(t) {
2113
- var g, m, v, x, O;
2114
- if (this.experimentalHighlights && !((g = this.notTextFlag) != null && g.has(t.id)))
2115
- return this.experimentalLayout(t);
2116
- const e = this.wnd.document.createElement("div");
2117
- e.setAttribute("id", t.id), e.style.setProperty("pointer-events", "none");
2118
- const i = this.wnd.innerWidth, r = parseInt(
2060
+ layout(e) {
2061
+ if (this.experimentalHighlights && !this.notTextFlag?.has(e.id))
2062
+ return this.experimentalLayout(e);
2063
+ const t = this.wnd.document.createElement("div");
2064
+ t.setAttribute("id", e.id), t.style.setProperty("pointer-events", "none");
2065
+ const i = this.wnd.innerWidth, s = parseInt(
2119
2066
  getComputedStyle(this.wnd.document.documentElement).getPropertyValue(
2120
2067
  "column-count"
2121
2068
  )
2122
- ), n = i / (r || 1), o = this.wnd.document.scrollingElement, l = o.scrollLeft, c = o.scrollTop, h = (y, b, I) => {
2123
- var dt, pt, ft, mt, gt, yt;
2124
- if (y.style.position = "absolute", ((pt = (dt = t.decoration) == null ? void 0 : dt.style) == null ? void 0 : pt.width) === "viewport") {
2125
- y.style.width = `${i}px`, y.style.height = `${b.height}px`;
2126
- let J = Math.floor(b.left / i) * i;
2127
- y.style.left = `${J + l}px`, y.style.top = `${b.top + c}px`;
2128
- } else if (((mt = (ft = t.decoration) == null ? void 0 : ft.style) == null ? void 0 : mt.width) === "bounds")
2129
- y.style.width = `${I.width}px`, y.style.height = `${b.height}px`, y.style.left = `${I.left + l}px`, y.style.top = `${b.top + c}px`;
2130
- else if (((yt = (gt = t.decoration) == null ? void 0 : gt.style) == null ? void 0 : yt.width) === "page") {
2131
- y.style.width = `${n}px`, y.style.height = `${b.height}px`;
2132
- let J = Math.floor(b.left / n) * n;
2133
- y.style.left = `${J + l}px`, y.style.top = `${b.top + c}px`;
2069
+ ), n = i / (s || 1), o = this.wnd.document.scrollingElement, l = o.scrollLeft, u = o.scrollTop, h = (d, f, g) => {
2070
+ if (d.style.position = "absolute", e.decoration?.style?.width === "viewport") {
2071
+ d.style.width = `${i}px`, d.style.height = `${f.height}px`;
2072
+ let E = Math.floor(f.left / i) * i;
2073
+ d.style.left = `${E + l}px`, d.style.top = `${f.top + u}px`;
2074
+ } else if (e.decoration?.style?.width === "bounds")
2075
+ d.style.width = `${g.width}px`, d.style.height = `${f.height}px`, d.style.left = `${g.left + l}px`, d.style.top = `${f.top + u}px`;
2076
+ else if (e.decoration?.style?.width === "page") {
2077
+ d.style.width = `${n}px`, d.style.height = `${f.height}px`;
2078
+ let E = Math.floor(f.left / n) * n;
2079
+ d.style.left = `${E + l}px`, d.style.top = `${f.top + u}px`;
2134
2080
  } else
2135
- y.style.width = `${b.width}px`, y.style.height = `${b.height}px`, y.style.left = `${b.left + l}px`, y.style.top = `${b.top + c}px`;
2136
- }, u = t.range.getBoundingClientRect();
2137
- let p = this.wnd.document.createElement("template");
2138
- const d = Nt(this.wnd, "--USER__appearance") === "readium-night-on" || Le(Nt(this.wnd, "--USER__backgroundColor"));
2139
- p.innerHTML = `
2081
+ d.style.width = `${f.width}px`, d.style.height = `${f.height}px`, d.style.left = `${f.left + l}px`, d.style.top = `${f.top + u}px`;
2082
+ }, c = e.range.getBoundingClientRect();
2083
+ let m = this.wnd.document.createElement("template");
2084
+ const p = Oe(this.wnd, "--USER__appearance") === "readium-night-on" || xt(Oe(this.wnd, "--USER__backgroundColor"));
2085
+ m.innerHTML = `
2140
2086
  <div
2141
2087
  class="r2-highlight-0"
2142
2088
  style="${[
2143
- `background-color: ${((v = (m = t.decoration) == null ? void 0 : m.style) == null ? void 0 : v.tint) ?? "yellow"} !important`,
2089
+ `background-color: ${e.decoration?.style?.tint ?? "yellow"} !important`,
2144
2090
  //"opacity: 0.3 !important",
2145
- `mix-blend-mode: ${d ? "exclusion" : "multiply"} !important`,
2091
+ `mix-blend-mode: ${p ? "exclusion" : "multiply"} !important`,
2146
2092
  "opacity: 1 !important",
2147
2093
  "box-sizing: border-box !important"
2148
2094
  ].join("; ")}"
2149
2095
  >
2150
2096
  </div>
2151
2097
  `.trim();
2152
- const f = p.content.firstElementChild;
2153
- if (((O = (x = t.decoration) == null ? void 0 : x.style) == null ? void 0 : O.layout) === "bounds") {
2154
- const y = f.cloneNode(!0);
2155
- y.style.setProperty("pointer-events", "none"), h(y, u, u), e.append(y);
2098
+ const y = m.content.firstElementChild;
2099
+ if (e.decoration?.style?.layout === "bounds") {
2100
+ const d = y.cloneNode(!0);
2101
+ d.style.setProperty("pointer-events", "none"), h(d, c, c), t.append(d);
2156
2102
  } else {
2157
- let y = we(
2158
- t.range,
2159
- !0
2160
- // doNotMergeHorizontallyAlignedRects
2103
+ let d = pt(
2104
+ e.range
2161
2105
  );
2162
- y = y.sort((b, I) => b.top < I.top ? -1 : b.top > I.top ? 1 : 0);
2163
- for (let b of y) {
2164
- const I = f.cloneNode(!0);
2165
- I.style.setProperty("pointer-events", "none"), h(I, b, u), e.append(I);
2106
+ d = d.sort((f, g) => f.top < g.top ? -1 : f.top > g.top ? 1 : 0);
2107
+ for (let f of d) {
2108
+ const g = y.cloneNode(!0);
2109
+ g.style.setProperty("pointer-events", "none"), h(g, f, c), t.append(g);
2166
2110
  }
2167
2111
  }
2168
- t.container = e, t.clickableElements = Array.from(
2169
- e.querySelectorAll("[data-activable='1']")
2170
- ), t.clickableElements.length || (t.clickableElements = Array.from(e.children));
2112
+ e.container = t, e.clickableElements = Array.from(
2113
+ t.querySelectorAll("[data-activable='1']")
2114
+ ), e.clickableElements.length || (e.clickableElements = Array.from(t.children));
2171
2115
  }
2172
- renderLayout(t) {
2116
+ renderLayout(e) {
2173
2117
  this.wnd.cancelAnimationFrame(this.currentRender), this.currentRender = this.wnd.requestAnimationFrame(() => {
2174
- if (t = t.filter((i) => {
2175
- var r;
2176
- return !this.experimentalHighlights || !!((r = this.notTextFlag) != null && r.has(i.id));
2177
- }), !t || t.length === 0)
2178
- return;
2179
- this.requireContainer().append(...t.map((i) => i.container).filter((i) => !!i));
2118
+ if (e = e.filter((i) => !this.experimentalHighlights || !!this.notTextFlag?.has(i.id)), !e || e.length === 0) return;
2119
+ this.requireContainer().append(...e.map((i) => i.container).filter((i) => !!i));
2180
2120
  });
2181
2121
  }
2182
2122
  /**
2183
2123
  * Returns the group container element, after making sure it exists.
2184
2124
  * @returns Group's container
2185
2125
  */
2186
- requireContainer(t = !1) {
2187
- if (t) {
2188
- let e;
2189
- this.wnd.document.getElementById(`${this.id}-style`) ? e = this.wnd.document.getElementById(`${this.id}-style`) : (e = this.wnd.document.createElement("style"), e.dataset.readium = "true", e.id = `${this.id}-style`, this.wnd.document.head.appendChild(e));
2126
+ requireContainer(e = !1) {
2127
+ if (e) {
2128
+ let t;
2129
+ 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));
2190
2130
  let i;
2191
- return this.wnd.CSS.highlights.has(this.id) ? i = this.wnd.CSS.highlights.get(this.id) : (i = new this.wnd.Highlight(), this.wnd.CSS.highlights.set(this.id, i)), [e, i];
2131
+ return this.wnd.CSS.highlights.has(this.id) ? i = this.wnd.CSS.highlights.get(this.id) : (i = new this.wnd.Highlight(), this.wnd.CSS.highlights.set(this.id, i)), [t, i];
2192
2132
  }
2193
2133
  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;
2194
2134
  }
@@ -2199,54 +2139,54 @@ class We {
2199
2139
  this.experimentalHighlights && this.wnd.CSS.highlights.delete(this.id), this.container && (this.container.remove(), this.container = void 0);
2200
2140
  }
2201
2141
  }
2202
- const Xt = class et extends K {
2142
+ const H = class H extends j {
2203
2143
  constructor() {
2204
2144
  super(...arguments), this.resizeFrame = 0, this.lastGroupId = 0, this.groups = /* @__PURE__ */ new Map(), this.handleResizer = this.handleResize.bind(this);
2205
2145
  }
2206
2146
  cleanup() {
2207
- this.groups.forEach((t) => t.clear()), this.groups.clear();
2147
+ this.groups.forEach((e) => e.clear()), this.groups.clear();
2208
2148
  }
2209
2149
  handleResize() {
2210
2150
  this.wnd.clearTimeout(this.resizeFrame), this.resizeFrame = this.wnd.setTimeout(() => {
2211
- this.groups.forEach((t) => {
2212
- t.experimentalHighlights || t.requestLayout();
2151
+ this.groups.forEach((e) => {
2152
+ e.experimentalHighlights || e.requestLayout();
2213
2153
  });
2214
2154
  }, 50);
2215
2155
  }
2216
- mount(t, e) {
2217
- return this.wnd = t, e.register("decorate", et.moduleName, (i, r) => {
2156
+ mount(e, t) {
2157
+ return this.wnd = e, t.register("decorate", H.moduleName, (i, s) => {
2218
2158
  const n = i;
2219
- n.decoration && n.decoration.locator && (n.decoration.locator = W.deserialize(n.decoration.locator)), this.groups.has(n.group) || this.groups.set(n.group, new We(
2220
- t,
2159
+ n.decoration && n.decoration.locator && (n.decoration.locator = L.deserialize(n.decoration.locator)), this.groups.has(n.group) || this.groups.set(n.group, new Ct(
2221
2160
  e,
2161
+ t,
2222
2162
  `readium-decoration-${this.lastGroupId++}`,
2223
2163
  n.group
2224
2164
  ));
2225
2165
  const o = this.groups.get(n.group);
2226
2166
  switch (n.action) {
2227
2167
  case "add":
2228
- o == null || o.add(n.decoration);
2168
+ o?.add(n.decoration);
2229
2169
  break;
2230
2170
  case "remove":
2231
- o == null || o.remove(n.decoration.id);
2171
+ o?.remove(n.decoration.id);
2232
2172
  break;
2233
2173
  case "clear":
2234
- o == null || o.clear();
2174
+ o?.clear();
2235
2175
  break;
2236
2176
  case "update":
2237
- o == null || o.update(n.decoration);
2177
+ o?.update(n.decoration);
2238
2178
  break;
2239
2179
  }
2240
- r(!0);
2241
- }), this.resizeObserver = new ResizeObserver(() => t.requestAnimationFrame(() => this.handleResize())), this.resizeObserver.observe(t.document.body), t.addEventListener("orientationchange", this.handleResizer), t.addEventListener("resize", this.handleResizer), e.log("Decorator Mounted"), !0;
2180
+ s(!0);
2181
+ }), this.resizeObserver = new ResizeObserver(() => 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;
2242
2182
  }
2243
- unmount(t, e) {
2244
- return t.removeEventListener("orientationchange", this.handleResizer), t.removeEventListener("resize", this.handleResizer), e.unregisterAll(et.moduleName), this.resizeObserver.disconnect(), this.cleanup(), e.log("Decorator Unmounted"), !0;
2183
+ unmount(e, t) {
2184
+ return e.removeEventListener("orientationchange", this.handleResizer), e.removeEventListener("resize", this.handleResizer), t.unregisterAll(H.moduleName), this.resizeObserver.disconnect(), this.cleanup(), t.log("Decorator Unmounted"), !0;
2245
2185
  }
2246
2186
  };
2247
- Xt.moduleName = "decorator";
2248
- let Fe = Xt;
2249
- const Ot = "readium-snapper-style", Gt = class it extends K {
2187
+ H.moduleName = "decorator";
2188
+ let se = H;
2189
+ const Ie = "readium-snapper-style", $ = class $ extends j {
2250
2190
  constructor() {
2251
2191
  super(...arguments), this.protected = !1;
2252
2192
  }
@@ -2257,62 +2197,61 @@ const Ot = "readium-snapper-style", Gt = class it extends K {
2257
2197
  user-select: ${this.protected ? "none" : "auto"};
2258
2198
  }`;
2259
2199
  }
2260
- mount(t, e) {
2261
- const i = t.document.createElement("style");
2262
- return i.dataset.readium = "true", i.id = Ot, i.textContent = this.buildStyles(), t.document.head.appendChild(i), e.register("protect", it.moduleName, (r, n) => {
2200
+ mount(e, t) {
2201
+ const i = e.document.createElement("style");
2202
+ return i.dataset.readium = "true", i.id = Ie, i.textContent = this.buildStyles(), e.document.head.appendChild(i), t.register("protect", $.moduleName, (s, n) => {
2263
2203
  this.protected = !0, i.textContent = this.buildStyles(), n(!0);
2264
- }), e.register("unprotect", it.moduleName, (r, n) => {
2204
+ }), t.register("unprotect", $.moduleName, (s, n) => {
2265
2205
  this.protected = !1, i.textContent = this.buildStyles(), n(!0);
2266
- }), e.log("Snapper Mounted"), !0;
2206
+ }), t.log("Snapper Mounted"), !0;
2267
2207
  }
2268
- unmount(t, e) {
2269
- var i;
2270
- return (i = t.document.getElementById(Ot)) == null || i.remove(), e.log("Snapper Unmounted"), !0;
2208
+ unmount(e, t) {
2209
+ return e.document.getElementById(Ie)?.remove(), t.log("Snapper Unmounted"), !0;
2271
2210
  }
2272
2211
  };
2273
- Gt.moduleName = "snapper";
2274
- let Yt = Gt;
2275
- function F(s) {
2276
- return s.document.body.dir.toLowerCase() === "rtl";
2212
+ $.moduleName = "snapper";
2213
+ let V = $;
2214
+ function R(r) {
2215
+ return r.document.body.dir.toLowerCase() === "rtl";
2277
2216
  }
2278
- function Zt(s) {
2217
+ function Ye(r) {
2279
2218
  return parseInt(
2280
- s.getComputedStyle(
2281
- s.document.documentElement
2219
+ r.getComputedStyle(
2220
+ r.document.documentElement
2282
2221
  ).getPropertyValue("column-count")
2283
2222
  );
2284
2223
  }
2285
- function It(s) {
2286
- const t = getComputedStyle(s), e = parseFloat(t.paddingTop || "0"), i = parseFloat(t.paddingBottom || "0");
2287
- return s.clientHeight - e - i;
2224
+ function Re(r) {
2225
+ const e = getComputedStyle(r), t = parseFloat(e.paddingTop || "0"), i = parseFloat(e.paddingBottom || "0");
2226
+ return r.clientHeight - t - i;
2288
2227
  }
2289
- function Lt(s) {
2290
- const t = Zt(s);
2291
- if (!t)
2228
+ function ze(r) {
2229
+ const e = Ye(r);
2230
+ if (!e)
2292
2231
  return !1;
2293
- const e = s.document.querySelectorAll("div[id^='readium-virtual-page']");
2294
- for (const h of e)
2232
+ const t = r.document.querySelectorAll("div[id^='readium-virtual-page']");
2233
+ for (const h of t)
2295
2234
  h.remove();
2296
- const i = e.length, r = s.document.scrollingElement.scrollWidth, n = s.visualViewport.width, l = Math.round(r / n * t) % t, c = t === 1 || l === 0 ? 0 : t - l;
2297
- if (c > 0)
2298
- for (let h = 0; h < c; h++) {
2299
- const u = s.document.createElement("div");
2300
- u.setAttribute("id", `readium-virtual-page-${h}`), u.dataset.readium = "true", CSS.supports("break-before", "column") ? u.style.breakBefore = "column" : (CSS.supports("break-inside", "avoid-column") && (u.style.breakInside = "avoid-column"), u.style.height = It(s.document.documentElement) + "px"), u.innerHTML = "&#8203;", s.document.body.appendChild(u);
2235
+ const i = t.length, s = r.document.scrollingElement.scrollWidth, n = r.visualViewport.width, l = Math.round(s / n * e) % e, u = e === 1 || l === 0 ? 0 : e - l;
2236
+ if (u > 0)
2237
+ for (let h = 0; h < u; h++) {
2238
+ const c = r.document.createElement("div");
2239
+ c.setAttribute("id", `readium-virtual-page-${h}`), c.dataset.readium = "true", CSS.supports("break-before", "column") ? c.style.breakBefore = "column" : (CSS.supports("break-inside", "avoid-column") && (c.style.breakInside = "avoid-column"), c.style.height = Re(r.document.documentElement) + "px"), c.innerHTML = "&#8203;", r.document.body.appendChild(c);
2301
2240
  }
2302
- return i !== c;
2241
+ return i !== u;
2303
2242
  }
2304
- function Ue(s) {
2305
- const t = s.document.createElement("style");
2306
- t.appendChild(s.document.createTextNode("*{}")), s.document.body.appendChild(t), s.document.body.removeChild(t);
2243
+ function Ke(r) {
2244
+ const e = r.document.createElement("style");
2245
+ e.appendChild(r.document.createTextNode("*{}")), r.document.body.appendChild(e), r.document.body.removeChild(e);
2307
2246
  }
2308
- function Be(s) {
2309
- return s < 0.5 ? 2 * s * s : -1 + (4 - 2 * s) * s;
2247
+ function Pt(r) {
2248
+ return r < 0.5 ? 2 * r * r : -1 + (4 - 2 * r) * r;
2310
2249
  }
2311
- function S(s) {
2312
- const t = s.getSelection();
2313
- t && t.removeAllRanges();
2250
+ function v(r) {
2251
+ const e = r.getSelection();
2252
+ e && e.removeAllRanges();
2314
2253
  }
2315
- const ke = [
2254
+ const At = [
2316
2255
  "a",
2317
2256
  "audio",
2318
2257
  "button",
@@ -2326,57 +2265,56 @@ const ke = [
2326
2265
  "textarea",
2327
2266
  "video"
2328
2267
  ];
2329
- function Kt(s) {
2330
- var t;
2331
- return ke.indexOf(s.nodeName.toLowerCase()) !== -1 || s.hasAttribute("contenteditable") && ((t = s.getAttribute("contenteditable")) == null ? void 0 : t.toLowerCase()) !== "false" ? s : s.parentElement ? Kt(s.parentElement) : null;
2268
+ function Ze(r) {
2269
+ return At.indexOf(r.nodeName.toLowerCase()) !== -1 || r.hasAttribute("contenteditable") && r.getAttribute("contenteditable")?.toLowerCase() !== "false" ? r : r.parentElement ? Ze(r.parentElement) : null;
2332
2270
  }
2333
- function Jt(s, t) {
2334
- const e = Qt(s, s.document.body, t), i = s._readium_cssSelectorGenerator.getCssSelector(e, {
2271
+ function ve(r, e) {
2272
+ const t = Je(r, r.document.body, e), i = r._readium_cssSelectorGenerator.getCssSelector(t, {
2335
2273
  selectors: ["tag", "id", "class", "nthchild", "nthoftype", "attribute"]
2336
2274
  });
2337
- return new W({
2275
+ return new L({
2338
2276
  href: "#",
2339
2277
  type: "application/xhtml+xml",
2340
- locations: new E({
2278
+ locations: new b({
2341
2279
  otherLocations: /* @__PURE__ */ new Map([
2342
2280
  ["cssSelector", i]
2343
2281
  ])
2344
2282
  }),
2345
- text: new $({
2346
- highlight: e.textContent || void 0
2283
+ text: new z({
2284
+ highlight: t.textContent || void 0
2347
2285
  })
2348
2286
  });
2349
2287
  }
2350
- function Qt(s, t, e) {
2351
- for (var i = 0; i < t.children.length; i++) {
2352
- const r = t.children[i];
2353
- if (!Ve(r) && $e(s, r, e))
2354
- return He(s, r) ? r : Qt(s, r, e);
2288
+ function Je(r, e, t) {
2289
+ for (var i = 0; i < e.children.length; i++) {
2290
+ const s = e.children[i];
2291
+ if (!Ot(s) && Mt(r, s, t))
2292
+ return Nt(r, s) ? s : Je(r, s, t);
2355
2293
  }
2356
- return t;
2294
+ return e;
2357
2295
  }
2358
- function $e(s, t, e) {
2359
- if (t === document.body || t === document.documentElement)
2296
+ function Mt(r, e, t) {
2297
+ if (e === document.body || e === document.documentElement)
2360
2298
  return !0;
2361
2299
  if (!document || !document.documentElement || !document.body)
2362
2300
  return !1;
2363
- const i = t.getBoundingClientRect();
2364
- return e ? i.bottom > 0 && i.top < s.innerHeight : i.right > 0 && i.left < s.innerWidth;
2365
- }
2366
- function He(s, t) {
2367
- const e = t.getBoundingClientRect();
2368
- return e.top >= 0 && e.left >= 0 && e.bottom <= s.innerHeight && e.right <= s.innerWidth;
2369
- }
2370
- function Ve(s) {
2371
- const t = getComputedStyle(s);
2372
- if (t) {
2373
- const e = t.getPropertyValue("display");
2374
- if (e != "block" && e != "list-item" || t.getPropertyValue("opacity") === "0")
2301
+ const i = e.getBoundingClientRect();
2302
+ return t ? i.bottom > 0 && i.top < r.innerHeight : i.right > 0 && i.left < r.innerWidth;
2303
+ }
2304
+ function Nt(r, e) {
2305
+ const t = e.getBoundingClientRect();
2306
+ return t.top >= 0 && t.left >= 0 && t.bottom <= r.innerHeight && t.right <= r.innerWidth;
2307
+ }
2308
+ function Ot(r) {
2309
+ const e = getComputedStyle(r);
2310
+ if (e) {
2311
+ const t = e.getPropertyValue("display");
2312
+ if (t != "block" && t != "list-item" || e.getPropertyValue("opacity") === "0")
2375
2313
  return !0;
2376
2314
  }
2377
2315
  return !1;
2378
2316
  }
2379
- const Rt = "readium-column-snapper-style", je = 200, te = class C extends Yt {
2317
+ const De = "readium-column-snapper-style", Lt = 200, x = class x extends V {
2380
2318
  constructor() {
2381
2319
  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);
2382
2320
  }
@@ -2386,58 +2324,55 @@ const Rt = "readium-column-snapper-style", je = 200, te = class C extends Yt {
2386
2324
  scrollOffset() {
2387
2325
  return this.doc().scrollLeft > 0 ? this.doc().scrollLeft : this.alreadyScrollLeft;
2388
2326
  }
2389
- snapOffset(t) {
2390
- const e = t + (F(this.wnd) ? -1 : 1);
2391
- return e - e % this.wnd.innerWidth;
2327
+ snapOffset(e) {
2328
+ const t = e + (R(this.wnd) ? -1 : 1);
2329
+ return t - t % this.wnd.innerWidth;
2392
2330
  }
2393
2331
  reportProgress() {
2394
- const t = this.wnd.scrollX, e = this.cachedScrollWidth, i = Math.max(0, Math.min(1, t / e)), r = Math.max(0, Math.min(1, (t + this.wnd.innerWidth) / e));
2332
+ const e = this.wnd.scrollX, t = this.cachedScrollWidth, i = Math.max(0, Math.min(1, e / t)), s = Math.max(0, Math.min(1, (e + this.wnd.innerWidth) / t));
2395
2333
  this.comms.send("progress", {
2396
2334
  start: i,
2397
- end: r
2335
+ end: s
2398
2336
  });
2399
2337
  }
2400
2338
  shake() {
2401
- if (this.overscroll !== 0 || this.shakeTimeout !== 0)
2402
- return;
2403
- const t = this.doc();
2404
- t.classList.add(F(this.wnd) ? "readium-bounce-l" : "readium-bounce-r");
2405
- const e = this.scrollOffset();
2339
+ if (this.overscroll !== 0 || this.shakeTimeout !== 0) return;
2340
+ const e = this.doc();
2341
+ e.classList.add(R(this.wnd) ? "readium-bounce-l" : "readium-bounce-r");
2342
+ const t = this.scrollOffset();
2406
2343
  this.shakeTimeout = this.wnd.setTimeout(() => {
2407
- t.classList.remove("readium-bounce-l"), t.classList.remove("readium-bounce-r"), this.shakeTimeout = 0, this.doc().scrollLeft = e;
2344
+ e.classList.remove("readium-bounce-l"), e.classList.remove("readium-bounce-r"), this.shakeTimeout = 0, this.doc().scrollLeft = t;
2408
2345
  }, 150);
2409
2346
  }
2410
2347
  // We have to cache this because during overscroll (transform, or left) the width is incorrect due to browser
2411
2348
  takeOverSnap() {
2412
- var e;
2413
2349
  this.snappingCancelled = !0, this.clearTouches();
2414
- const t = this.doc();
2415
- this.overscroll = ((e = t.style.transform) == null ? void 0 : e.length) > 12 ? parseFloat(t.style.transform.slice(12).split("px")[0]) : 0;
2350
+ const e = this.doc();
2351
+ this.overscroll = e.style.transform?.length > 12 ? parseFloat(e.style.transform.slice(12).split("px")[0]) : 0;
2416
2352
  }
2417
2353
  // Snaps the current offset to the page width.
2418
- snapCurrentOffset(t = !1, e = !1) {
2419
- const i = this.wnd.scrollX > 0 ? this.wnd.scrollX : this.alreadyScrollLeft, r = this.doc(), n = this.dragOffset(), o = Zt(this.wnd), l = Math.min(Math.max(0, i), this.cachedScrollWidth), c = F(this.wnd) ? -1 : 1, h = (
2354
+ snapCurrentOffset(e = !1, t = !1) {
2355
+ const i = this.wnd.scrollX > 0 ? this.wnd.scrollX : this.alreadyScrollLeft, s = this.doc(), n = this.dragOffset(), o = Ye(this.wnd), l = Math.min(Math.max(0, i), this.cachedScrollWidth), u = R(this.wnd) ? -1 : 1, h = (
2420
2356
  // The hurdle to overcome in order to change pages
2421
- c * (this.wnd.innerWidth / 3) * (c * n > 0 ? 2 : 1)
2422
- ), u = this.snapOffset(l + h);
2423
- if (t && u !== this.scrollOffset()) {
2357
+ u * (this.wnd.innerWidth / 3) * (u * n > 0 ? 2 : 1)
2358
+ ), c = this.snapOffset(l + h);
2359
+ if (e && c !== this.scrollOffset()) {
2424
2360
  this.snappingCancelled = !1;
2425
- const p = (m, v, x, O) => x > O ? v : m + (v - m) * Be(x / O), d = (
2361
+ const m = (f, g, E, D) => E > D ? g : f + (g - f) * Pt(E / D), p = (
2426
2362
  /*Math.abs(startX - (this.useTransform ? currentOffset : 0)) < 10 ? 1 : */
2427
- je * o
2363
+ Lt * o
2428
2364
  );
2429
- let f;
2430
- const g = (m) => {
2431
- if (this.snappingCancelled)
2432
- return;
2433
- f || (f = m);
2434
- const v = m - f, x = p(this.overscroll, 0, v, d), O = p(i, u, v, d);
2435
- r.scrollLeft = O, this.overscroll !== 0 && (r.style.transform = `translate3d(${-x}px, 0px, 0px)`), v < d ? this.wnd.requestAnimationFrame(g) : (this.clearTouches(), r.style.removeProperty("transform"), r.scrollLeft = u, e || this.reportProgress());
2365
+ let y;
2366
+ const d = (f) => {
2367
+ if (this.snappingCancelled) return;
2368
+ y || (y = f);
2369
+ const g = f - y, E = m(this.overscroll, 0, g, p), D = m(i, c, g, p);
2370
+ s.scrollLeft = D, this.overscroll !== 0 && (s.style.transform = `translate3d(${-E}px, 0px, 0px)`), g < p ? this.wnd.requestAnimationFrame(d) : (this.clearTouches(), s.style.removeProperty("transform"), s.scrollLeft = c, t || this.reportProgress());
2436
2371
  };
2437
- this.wnd.requestAnimationFrame(g);
2372
+ this.wnd.requestAnimationFrame(d);
2438
2373
  } else
2439
- r.style.removeProperty("transform"), this.wnd.requestAnimationFrame(() => {
2440
- r.scrollLeft = u, this.clearTouches(), e || this.reportProgress();
2374
+ s.style.removeProperty("transform"), this.wnd.requestAnimationFrame(() => {
2375
+ s.scrollLeft = c, this.clearTouches(), t || this.reportProgress();
2441
2376
  });
2442
2377
  }
2443
2378
  dragOffset() {
@@ -2446,43 +2381,41 @@ const Rt = "readium-column-snapper-style", je = 200, te = class C extends Yt {
2446
2381
  clearTouches() {
2447
2382
  this.startingX = void 0, this.endingX = void 0, this.overscroll = 0;
2448
2383
  }
2449
- onTouchStart(t) {
2450
- switch (t.stopPropagation(), this.takeOverSnap(), t.touches.length) {
2384
+ onTouchStart(e) {
2385
+ switch (e.stopPropagation(), this.takeOverSnap(), e.touches.length) {
2451
2386
  case 1:
2452
2387
  break;
2453
2388
  case 2:
2454
- this.onTouchEnd(t);
2389
+ this.onTouchEnd(e);
2455
2390
  return;
2456
2391
  default: {
2457
- this.onTouchEnd(t), this.comms.send("tap_more", t.touches.length);
2392
+ this.onTouchEnd(e), this.comms.send("tap_more", e.touches.length);
2458
2393
  return;
2459
2394
  }
2460
2395
  }
2461
- this.startingX = t.touches[0].clientX, this.alreadyScrollLeft = this.doc().scrollLeft, this.touchState = 1;
2396
+ this.startingX = e.touches[0].clientX, this.alreadyScrollLeft = this.doc().scrollLeft, this.touchState = 1;
2462
2397
  }
2463
- onTouchEnd(t) {
2398
+ onTouchEnd(e) {
2464
2399
  if (this.touchState === 2) {
2465
- const e = this.dragOffset(), i = this.scrollOffset();
2466
- this.cachedScrollWidth <= this.wnd.innerWidth ? (this.reportProgress(), e > 5 && this.comms.send("no_more", void 0), e < -5 && this.comms.send("no_less", void 0)) : i < 5 && e < 5 ? (this.alreadyScrollLeft = 0, this.comms.send("no_less", void 0)) : this.cachedScrollWidth - i - this.wnd.innerWidth < 5 && e > 5 && (this.alreadyScrollLeft = this.cachedScrollWidth, this.comms.send("no_more", void 0)), this.snapCurrentOffset(!0), this.comms.send("swipe", e);
2400
+ const t = this.dragOffset(), i = this.scrollOffset();
2401
+ 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)) : i < 5 && t < 5 ? (this.alreadyScrollLeft = 0, this.comms.send("no_less", void 0)) : this.cachedScrollWidth - i - 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);
2467
2402
  }
2468
2403
  this.touchState = 0;
2469
2404
  }
2470
2405
  onWidthChange() {
2471
2406
  this.cachedScrollWidth = this.doc().scrollWidth, this.comms.ready && this.snapCurrentOffset();
2472
2407
  }
2473
- onTouchMove(t) {
2474
- if (this.touchState === 0)
2475
- return;
2476
- this.touchState === 1 && (this.touchState = 2, S(this.wnd)), this.endingX = t.touches[0].clientX;
2477
- const e = this.dragOffset(), i = this.alreadyScrollLeft + e;
2478
- i < 0 ? (this.overscroll = i, this.doc().style.transform = `translate3d(${-this.overscroll}px, 0px, 0px)`) : i + this.wnd.innerWidth > this.cachedScrollWidth ? (this.overscroll = i, this.doc().style.transform = `translate3d(${-i}px, 0px, 0px)`) : (this.overscroll = 0, this.doc().style.removeProperty("transform"), this.doc().scrollLeft = this.alreadyScrollLeft + e);
2479
- }
2480
- mount(t, e) {
2481
- if (this.wnd = t, this.comms = e, !super.mount(t, e))
2482
- return !1;
2483
- t.navigator.epubReadingSystem.layoutStyle = "paginated";
2484
- const i = t.document.createElement("style");
2485
- i.dataset.readium = "true", i.id = Rt, i.textContent = `
2408
+ onTouchMove(e) {
2409
+ if (this.touchState === 0) return;
2410
+ this.touchState === 1 && (this.touchState = 2, v(this.wnd)), this.endingX = e.touches[0].clientX;
2411
+ const t = this.dragOffset(), i = this.alreadyScrollLeft + t;
2412
+ i < 0 ? (this.overscroll = i, this.doc().style.transform = `translate3d(${-this.overscroll}px, 0px, 0px)`) : i + this.wnd.innerWidth > this.cachedScrollWidth ? (this.overscroll = i, this.doc().style.transform = `translate3d(${-i}px, 0px, 0px)`) : (this.overscroll = 0, this.doc().style.removeProperty("transform"), this.doc().scrollLeft = this.alreadyScrollLeft + t);
2413
+ }
2414
+ mount(e, t) {
2415
+ if (this.wnd = e, this.comms = t, !super.mount(e, t)) return !1;
2416
+ e.navigator.epubReadingSystem && (e.navigator.epubReadingSystem.layoutStyle = "paginated");
2417
+ const i = e.document.createElement("style");
2418
+ i.dataset.readium = "true", i.id = De, i.textContent = `
2486
2419
  @keyframes readium-bounce-l-animation {
2487
2420
  0%, 100% {transform: translate3d(0, 0, 0);}
2488
2421
  50% {transform: translate3d(-50px, 0, 0);}
@@ -2516,54 +2449,54 @@ const Rt = "readium-column-snapper-style", je = 200, te = class C extends Yt {
2516
2449
  body::-webkit-scrollbar {
2517
2450
  display: none; /* for Chrome, Safari, and Opera */
2518
2451
  }
2519
- `, t.document.head.appendChild(i), this.resizeObserver = new ResizeObserver(() => {
2520
- t.requestAnimationFrame(() => {
2521
- t && Lt(t);
2452
+ `, e.document.head.appendChild(i), this.resizeObserver = new ResizeObserver(() => {
2453
+ e.requestAnimationFrame(() => {
2454
+ e && ze(e);
2522
2455
  }), this.onWidthChange();
2523
- }), this.resizeObserver.observe(t.document.body), this.mutationObserver = new MutationObserver((n) => {
2456
+ }), this.resizeObserver.observe(e.document.body), this.mutationObserver = new MutationObserver((n) => {
2524
2457
  for (const o of n)
2525
2458
  if (o.target === this.wnd.document.documentElement) {
2526
- const l = o.oldValue, c = o.target.getAttribute("style"), h = /transform\s*:\s*([^;]+)/, u = l == null ? void 0 : l.match(h), p = c == null ? void 0 : c.match(h);
2527
- (!u && !p || u && !p || u && p && u[1] !== p[1]) && (t.requestAnimationFrame(() => {
2528
- t && Lt(t);
2459
+ const l = o.oldValue, u = o.target.getAttribute("style"), h = /transform\s*:\s*([^;]+)/, c = l?.match(h), m = u?.match(h);
2460
+ (!c && !m || c && !m || c && m && c[1] !== m[1]) && (e.requestAnimationFrame(() => {
2461
+ e && ze(e);
2529
2462
  }), this.onWidthChange());
2530
2463
  } else
2531
- t.requestAnimationFrame(() => this.cachedScrollWidth = this.doc().scrollWidth);
2532
- }), t.frameElement && this.mutationObserver.observe(t.frameElement, { attributes: !0, attributeFilter: ["style"] }), this.mutationObserver.observe(t.document, { attributes: !0, attributeFilter: ["style"] }), this.mutationObserver.observe(t.document.documentElement, { attributes: !0, attributeFilter: ["style"] });
2533
- const r = (n) => {
2464
+ e.requestAnimationFrame(() => this.cachedScrollWidth = this.doc().scrollWidth);
2465
+ }), e.frameElement && this.mutationObserver.observe(e.frameElement, { attributes: !0, attributeFilter: ["style"] }), this.mutationObserver.observe(e.document, { attributes: !0, attributeFilter: ["style"] }), this.mutationObserver.observe(e.document.documentElement, { attributes: !0, attributeFilter: ["style"] });
2466
+ const s = (n) => {
2534
2467
  const o = this.doc().scrollLeft;
2535
2468
  return this.doc().scrollLeft = this.snapOffset(n), o !== this.doc().scrollLeft;
2536
2469
  };
2537
- return t.addEventListener("orientationchange", this.onWidthChanger), t.addEventListener("resize", this.onWidthChanger), t.requestAnimationFrame(() => this.cachedScrollWidth = this.doc().scrollWidth), e.register("go_progression", C.moduleName, (n, o) => {
2470
+ return e.addEventListener("orientationchange", this.onWidthChanger), e.addEventListener("resize", this.onWidthChanger), e.requestAnimationFrame(() => this.cachedScrollWidth = this.doc().scrollWidth), t.register("go_progression", x.moduleName, (n, o) => {
2538
2471
  const l = n;
2539
2472
  if (l < 0 || l > 1) {
2540
- e.send("error", {
2473
+ t.send("error", {
2541
2474
  message: "go_progression must be given a position from 0.0 to 1.0"
2542
2475
  }), o(!1);
2543
2476
  return;
2544
2477
  }
2545
2478
  this.wnd.requestAnimationFrame(() => {
2546
2479
  this.cachedScrollWidth = this.doc().scrollWidth;
2547
- const c = this.cachedScrollWidth, h = F(t) ? -1 : 1, u = c * l * h;
2548
- this.doc().scrollLeft = this.snapOffset(u), this.reportProgress(), S(this.wnd), o(!0);
2480
+ const u = this.cachedScrollWidth, h = R(e) ? -1 : 1, c = u * l * h;
2481
+ this.doc().scrollLeft = this.snapOffset(c), this.reportProgress(), v(this.wnd), o(!0);
2549
2482
  });
2550
- }), e.register("go_id", C.moduleName, (n, o) => {
2551
- const l = t.document.getElementById(n);
2483
+ }), t.register("go_id", x.moduleName, (n, o) => {
2484
+ const l = e.document.getElementById(n);
2552
2485
  if (!l) {
2553
2486
  o(!1);
2554
2487
  return;
2555
2488
  }
2556
2489
  this.wnd.requestAnimationFrame(() => {
2557
- this.doc().scrollLeft = this.snapOffset(l.getBoundingClientRect().left + t.scrollX), this.reportProgress(), S(this.wnd), o(!0);
2490
+ this.doc().scrollLeft = this.snapOffset(l.getBoundingClientRect().left + e.scrollX), this.reportProgress(), v(this.wnd), o(!0);
2558
2491
  });
2559
- }), e.register("go_text", C.moduleName, (n, o) => {
2492
+ }), t.register("go_text", x.moduleName, (n, o) => {
2560
2493
  let l;
2561
2494
  Array.isArray(n) && (n.length > 1 && (l = n[1]), n = n[0]);
2562
- const c = $.deserialize(n), h = ct(this.wnd.document, new W({
2563
- href: t.location.href,
2495
+ const u = z.deserialize(n), h = ee(this.wnd.document, new L({
2496
+ href: e.location.href,
2564
2497
  type: "text/html",
2565
- text: c,
2566
- locations: l ? new E({
2498
+ text: u,
2499
+ locations: l ? new b({
2567
2500
  otherLocations: /* @__PURE__ */ new Map([
2568
2501
  ["cssSelector", l]
2569
2502
  ])
@@ -2574,57 +2507,54 @@ const Rt = "readium-column-snapper-style", je = 200, te = class C extends Yt {
2574
2507
  return;
2575
2508
  }
2576
2509
  this.wnd.requestAnimationFrame(() => {
2577
- this.doc().scrollLeft = this.snapOffset(h.getBoundingClientRect().left + t.scrollX), this.reportProgress(), S(this.wnd), o(!0);
2510
+ this.doc().scrollLeft = this.snapOffset(h.getBoundingClientRect().left + e.scrollX), this.reportProgress(), v(this.wnd), o(!0);
2578
2511
  });
2579
- }), e.register("go_end", C.moduleName, (n, o) => {
2580
- const l = F(t) ? -1 : 1;
2512
+ }), t.register("go_end", x.moduleName, (n, o) => {
2513
+ const l = R(e) ? -1 : 1;
2581
2514
  this.wnd.requestAnimationFrame(() => {
2582
2515
  this.cachedScrollWidth = this.doc().scrollWidth;
2583
- const c = this.cachedScrollWidth * l;
2584
- if (this.doc().scrollLeft === c)
2585
- return o(!1);
2586
- this.doc().scrollLeft = this.snapOffset(c), this.reportProgress(), S(this.wnd), o(!0);
2516
+ const u = this.cachedScrollWidth * l;
2517
+ if (this.doc().scrollLeft === u) return o(!1);
2518
+ this.doc().scrollLeft = this.snapOffset(u), this.reportProgress(), v(this.wnd), o(!0);
2587
2519
  });
2588
- }), e.register("go_start", C.moduleName, (n, o) => {
2520
+ }), t.register("go_start", x.moduleName, (n, o) => {
2589
2521
  this.wnd.requestAnimationFrame(() => {
2590
- if (this.doc().scrollLeft === 0)
2591
- return o(!1);
2592
- this.doc().scrollLeft = 0, this.reportProgress(), S(this.wnd), o(!0);
2522
+ if (this.doc().scrollLeft === 0) return o(!1);
2523
+ this.doc().scrollLeft = 0, this.reportProgress(), v(this.wnd), o(!0);
2593
2524
  });
2594
- }), e.register("go_prev", C.moduleName, (n, o) => {
2525
+ }), t.register("go_prev", x.moduleName, (n, o) => {
2595
2526
  this.wnd.requestAnimationFrame(() => {
2596
2527
  this.cachedScrollWidth = this.doc().scrollWidth;
2597
- const l = t.scrollX - t.innerWidth, c = F(t) ? -(this.cachedScrollWidth - t.innerWidth) : 0, h = r(Math.max(l, c));
2598
- h && (this.reportProgress(), S(this.wnd)), o(h);
2528
+ const l = e.scrollX - e.innerWidth, u = R(e) ? -(this.cachedScrollWidth - e.innerWidth) : 0, h = s(Math.max(l, u));
2529
+ h && (this.reportProgress(), v(this.wnd)), o(h);
2599
2530
  });
2600
- }), e.register("go_next", C.moduleName, (n, o) => {
2531
+ }), t.register("go_next", x.moduleName, (n, o) => {
2601
2532
  this.wnd.requestAnimationFrame(() => {
2602
2533
  this.cachedScrollWidth = this.doc().scrollWidth;
2603
- const l = t.scrollX + t.innerWidth, c = F(t) ? 0 : this.cachedScrollWidth - t.innerWidth, h = r(Math.min(l, c));
2604
- h && (this.reportProgress(), S(this.wnd)), o(h);
2534
+ const l = e.scrollX + e.innerWidth, u = R(e) ? 0 : this.cachedScrollWidth - e.innerWidth, h = s(Math.min(l, u));
2535
+ h && (this.reportProgress(), v(this.wnd)), o(h);
2605
2536
  });
2606
- }), e.register("unfocus", C.moduleName, (n, o) => {
2607
- this.snappingCancelled = !0, S(this.wnd), o(!0);
2608
- }), e.register("shake", C.moduleName, (n, o) => {
2537
+ }), t.register("unfocus", x.moduleName, (n, o) => {
2538
+ this.snappingCancelled = !0, v(this.wnd), o(!0);
2539
+ }), t.register("shake", x.moduleName, (n, o) => {
2609
2540
  this.shake(), o(!0);
2610
- }), e.register("focus", C.moduleName, (n, o) => {
2541
+ }), t.register("focus", x.moduleName, (n, o) => {
2611
2542
  this.wnd.requestAnimationFrame(() => {
2612
2543
  this.cachedScrollWidth = this.doc().scrollWidth, this.snapCurrentOffset(!1, !0), this.reportProgress(), o(!0);
2613
2544
  });
2614
- }), e.register("first_visible_locator", C.moduleName, (n, o) => {
2615
- const l = Jt(t, !1);
2545
+ }), t.register("first_visible_locator", x.moduleName, (n, o) => {
2546
+ const l = ve(e, !1);
2616
2547
  this.comms.send("first_visible_locator", l.serialize()), o(!0);
2617
- }), t.addEventListener("touchstart", this.onTouchStarter, { passive: !0 }), t.addEventListener("touchend", this.onTouchEnder, { passive: !0 }), t.addEventListener("touchmove", this.onTouchMover, { passive: !0 }), t.document.addEventListener("touchstart", () => {
2618
- }), e.log("ColumnSnapper Mounted"), !0;
2548
+ }), 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", () => {
2549
+ }), t.log("ColumnSnapper Mounted"), !0;
2619
2550
  }
2620
- unmount(t, e) {
2621
- var i;
2622
- return this.snappingCancelled = !0, e.unregisterAll(C.moduleName), this.resizeObserver.disconnect(), this.mutationObserver.disconnect(), t.removeEventListener("touchstart", this.onTouchStarter), t.removeEventListener("touchend", this.onTouchEnder), t.removeEventListener("touchmove", this.onTouchMover), t.removeEventListener("orientationchange", this.onWidthChanger), t.removeEventListener("resize", this.onWidthChanger), (i = t.document.getElementById(Rt)) == null || i.remove(), e.log("ColumnSnapper Unmounted"), super.unmount(t, e);
2551
+ unmount(e, t) {
2552
+ return this.snappingCancelled = !0, t.unregisterAll(x.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), e.document.getElementById(De)?.remove(), t.log("ColumnSnapper Unmounted"), super.unmount(e, t);
2623
2553
  }
2624
2554
  };
2625
- te.moduleName = "column_snapper";
2626
- let qe = te;
2627
- const zt = "readium-scroll-snapper-style", ee = class P extends Yt {
2555
+ x.moduleName = "column_snapper";
2556
+ let re = x;
2557
+ const We = "readium-scroll-snapper-style", T = class T extends V {
2628
2558
  constructor() {
2629
2559
  super(...arguments), this.initialScrollHandled = !1, this.isScrolling = !1, this.lastScrollTop = 0, this.isResizing = !1, this.resizeDebounce = null, this.handleScroll = () => {
2630
2560
  if (this.comms.ready && !this.isResizing) {
@@ -2634,8 +2564,8 @@ const zt = "readium-scroll-snapper-style", ee = class P extends Yt {
2634
2564
  }
2635
2565
  this.isScrolling || (this.isScrolling = !0, this.wnd.requestAnimationFrame(() => {
2636
2566
  this.reportProgress();
2637
- const t = this.doc().scrollTop, e = t - this.lastScrollTop;
2638
- this.lastScrollTop = t, this.comms.send("scroll", e), this.isScrolling = !1;
2567
+ const e = this.doc().scrollTop, t = e - this.lastScrollTop;
2568
+ this.lastScrollTop = e, this.comms.send("scroll", t), this.isScrolling = !1;
2639
2569
  }));
2640
2570
  }
2641
2571
  };
@@ -2644,18 +2574,17 @@ const zt = "readium-scroll-snapper-style", ee = class P extends Yt {
2644
2574
  return this.wnd.document.scrollingElement;
2645
2575
  }
2646
2576
  reportProgress() {
2647
- if (!this.comms.ready)
2648
- return;
2649
- const t = Math.ceil(this.doc().scrollTop), e = this.doc().scrollHeight, i = this.wnd.innerHeight, r = Math.max(0, Math.min(1, t / e)), n = Math.max(0, Math.min(1, (t + i) / e));
2577
+ if (!this.comms.ready) return;
2578
+ const e = Math.ceil(this.doc().scrollTop), t = this.doc().scrollHeight, i = this.wnd.innerHeight, s = Math.max(0, Math.min(1, e / t)), n = Math.max(0, Math.min(1, (e + i) / t));
2650
2579
  this.comms.send("progress", {
2651
- start: r,
2580
+ start: s,
2652
2581
  end: n
2653
2582
  });
2654
2583
  }
2655
- mount(t, e) {
2656
- this.wnd = t, this.comms = e, this.initialScrollHandled = !1, this.lastScrollTop = 0, this.isResizing = !1, this.resizeDebounce && (this.wnd.clearTimeout(this.resizeDebounce), this.resizeDebounce = null), t.navigator.epubReadingSystem.layoutStyle = "scrolling";
2657
- const i = t.document.createElement("style");
2658
- return i.dataset.readium = "true", i.id = zt, i.textContent = `
2584
+ mount(e, t) {
2585
+ this.wnd = e, this.comms = t, this.initialScrollHandled = !1, this.lastScrollTop = 0, this.isResizing = !1, this.resizeDebounce && (this.wnd.clearTimeout(this.resizeDebounce), this.resizeDebounce = null), e.navigator.epubReadingSystem && (e.navigator.epubReadingSystem.layoutStyle = "scrolling");
2586
+ const i = e.document.createElement("style");
2587
+ return i.dataset.readium = "true", i.id = We, i.textContent = `
2659
2588
  * {
2660
2589
  scrollbar-width: none; /* for Firefox */
2661
2590
  }
@@ -2663,122 +2592,217 @@ const zt = "readium-scroll-snapper-style", ee = class P extends Yt {
2663
2592
  body::-webkit-scrollbar {
2664
2593
  display: none; /* for Chrome, Safari, and Opera */
2665
2594
  }
2666
- `, t.document.head.appendChild(i), this.resizeObserver = new ResizeObserver(() => {
2595
+ `, e.document.head.appendChild(i), this.resizeObserver = new ResizeObserver(() => {
2667
2596
  this.resizeDebounce && this.wnd.clearTimeout(this.resizeDebounce), this.isResizing = !0, this.resizeDebounce = this.wnd.setTimeout(() => {
2668
2597
  this.isResizing = !1, this.resizeDebounce = null, this.reportProgress();
2669
2598
  }, 50);
2670
- }), this.resizeObserver.observe(t.document.body), t.addEventListener("scroll", this.handleScroll, { passive: !0 }), e.register("force_webkit_recalc", P.moduleName, () => {
2671
- Ue(this.wnd);
2672
- const r = this.doc().scrollTop;
2673
- r > 1 ? this.doc().scrollTop = r - 1 : this.doc().scrollTop = r + 1, this.doc().scrollTop = r;
2674
- }), e.register("go_progression", P.moduleName, (r, n) => {
2675
- const o = r;
2599
+ }), this.resizeObserver.observe(e.document.body), e.addEventListener("scroll", this.handleScroll, { passive: !0 }), t.register("force_webkit_recalc", T.moduleName, () => {
2600
+ Ke(this.wnd);
2601
+ const s = this.doc().scrollTop;
2602
+ s > 1 ? this.doc().scrollTop = s - 1 : this.doc().scrollTop = s + 1, this.doc().scrollTop = s;
2603
+ }), t.register("go_progression", T.moduleName, (s, n) => {
2604
+ const o = s;
2676
2605
  if (o < 0 || o > 1) {
2677
- e.send("error", {
2606
+ t.send("error", {
2678
2607
  message: "go_progression must be given a position from 0.0 to 1.0"
2679
2608
  }), n(!1);
2680
2609
  return;
2681
2610
  }
2682
2611
  this.wnd.requestAnimationFrame(() => {
2683
- this.doc().scrollTop = this.doc().offsetHeight * o, this.reportProgress(), S(this.wnd), n(!0);
2612
+ this.doc().scrollTop = this.doc().offsetHeight * o, this.reportProgress(), v(this.wnd), n(!0);
2684
2613
  });
2685
- }), e.register("go_id", P.moduleName, (r, n) => {
2686
- const o = t.document.getElementById(r);
2614
+ }), t.register("go_id", T.moduleName, (s, n) => {
2615
+ const o = e.document.getElementById(s);
2687
2616
  if (!o) {
2688
2617
  n(!1);
2689
2618
  return;
2690
2619
  }
2691
2620
  this.wnd.requestAnimationFrame(() => {
2692
- this.doc().scrollTop = o.getBoundingClientRect().top + t.scrollY - t.innerHeight / 2, this.reportProgress(), S(this.wnd), n(!0);
2621
+ this.doc().scrollTop = o.getBoundingClientRect().top + e.scrollY - e.innerHeight / 2, this.reportProgress(), v(this.wnd), n(!0);
2693
2622
  });
2694
- }), e.register("go_text", P.moduleName, (r, n) => {
2623
+ }), t.register("go_text", T.moduleName, (s, n) => {
2695
2624
  let o;
2696
- Array.isArray(r) && (r.length > 1 && (o = r[1]), r = r[0]);
2697
- const l = $.deserialize(r), c = ct(this.wnd.document, new W({
2698
- href: t.location.href,
2625
+ Array.isArray(s) && (s.length > 1 && (o = s[1]), s = s[0]);
2626
+ const l = z.deserialize(s), u = ee(this.wnd.document, new L({
2627
+ href: e.location.href,
2699
2628
  type: "text/html",
2700
2629
  text: l,
2701
- locations: o ? new E({
2630
+ locations: o ? new b({
2702
2631
  otherLocations: /* @__PURE__ */ new Map([
2703
2632
  ["cssSelector", o]
2704
2633
  ])
2705
2634
  }) : void 0
2706
2635
  }));
2707
- if (!c) {
2636
+ if (!u) {
2708
2637
  n(!1);
2709
2638
  return;
2710
2639
  }
2711
2640
  this.wnd.requestAnimationFrame(() => {
2712
- this.doc().scrollTop = c.getBoundingClientRect().top + t.scrollY - t.innerHeight / 2, this.reportProgress(), S(this.wnd), n(!0);
2641
+ this.doc().scrollTop = u.getBoundingClientRect().top + e.scrollY - e.innerHeight / 2, this.reportProgress(), v(this.wnd), n(!0);
2713
2642
  });
2714
- }), e.register("go_start", P.moduleName, (r, n) => {
2715
- if (this.doc().scrollTop === 0)
2716
- return n(!1);
2643
+ }), t.register("go_start", T.moduleName, (s, n) => {
2644
+ if (this.doc().scrollTop === 0) return n(!1);
2717
2645
  this.doc().scrollTop = 0, this.reportProgress(), n(!0);
2718
- }), e.register("go_end", P.moduleName, (r, n) => {
2719
- if (this.doc().scrollTop === this.doc().scrollHeight - this.doc().offsetHeight)
2720
- return n(!1);
2646
+ }), t.register("go_end", T.moduleName, (s, n) => {
2647
+ if (this.doc().scrollTop === this.doc().scrollHeight - this.doc().offsetHeight) return n(!1);
2721
2648
  this.doc().scrollTop = this.doc().scrollHeight - this.doc().offsetHeight, this.reportProgress(), n(!0);
2722
- }), e.register("unfocus", P.moduleName, (r, n) => {
2723
- S(this.wnd), n(!0);
2724
- }), e.register([
2649
+ }), t.register("unfocus", T.moduleName, (s, n) => {
2650
+ v(this.wnd), n(!0);
2651
+ }), t.register([
2725
2652
  "go_next",
2726
2653
  "go_prev"
2727
- ], P.moduleName, (r, n) => n(!1)), e.register("focus", P.moduleName, (r, n) => {
2654
+ ], T.moduleName, (s, n) => n(!1)), t.register("focus", T.moduleName, (s, n) => {
2728
2655
  this.reportProgress(), n(!0);
2729
- }), e.register("first_visible_locator", P.moduleName, (r, n) => {
2730
- const o = Jt(t, !0);
2656
+ }), t.register("first_visible_locator", T.moduleName, (s, n) => {
2657
+ const o = ve(e, !0);
2731
2658
  this.comms.send("first_visible_locator", o.serialize()), n(!0);
2732
- }), e.log("ScrollSnapper Mounted"), !0;
2659
+ }), t.log("ScrollSnapper Mounted"), !0;
2660
+ }
2661
+ unmount(e, t) {
2662
+ return t.unregisterAll(T.moduleName), this.resizeObserver.disconnect(), this.handleScroll && e.removeEventListener("scroll", this.handleScroll), e.document.getElementById(We)?.remove(), t.log("ScrollSnapper Unmounted"), !0;
2663
+ }
2664
+ };
2665
+ T.moduleName = "scroll_snapper";
2666
+ let ne = T;
2667
+ const w = class w extends V {
2668
+ constructor() {
2669
+ super(...arguments), this.initialScrollHandled = !1, this.isScrolling = !1, this.lastScrollTop = 0, this.isResizing = !1, this.resizeDebounce = null, this.handleScroll = () => {
2670
+ if (this.comms.ready && !this.isResizing) {
2671
+ if (!this.initialScrollHandled) {
2672
+ this.lastScrollTop = this.doc().scrollTop, this.initialScrollHandled = !0, this.reportProgress();
2673
+ return;
2674
+ }
2675
+ this.isScrolling || (this.isScrolling = !0, this.wnd.requestAnimationFrame(() => {
2676
+ this.reportProgress();
2677
+ const e = this.doc().scrollTop, t = e - this.lastScrollTop;
2678
+ this.lastScrollTop = e, this.comms.send("scroll", t), this.isScrolling = !1;
2679
+ }));
2680
+ }
2681
+ };
2682
+ }
2683
+ doc() {
2684
+ return this.wnd.document.scrollingElement;
2685
+ }
2686
+ reportProgress() {
2687
+ if (!this.comms.ready) return;
2688
+ const e = Math.ceil(this.doc().scrollTop), t = this.doc().scrollHeight, i = this.wnd.innerHeight, s = Math.max(0, Math.min(1, e / t)), n = Math.max(0, Math.min(1, (e + i) / t));
2689
+ this.comms.send("progress", {
2690
+ start: s,
2691
+ end: n
2692
+ });
2693
+ }
2694
+ mount(e, t) {
2695
+ return this.wnd = e, this.comms = t, this.initialScrollHandled = !1, this.lastScrollTop = 0, this.isResizing = !1, this.resizeDebounce && (this.wnd.clearTimeout(this.resizeDebounce), this.resizeDebounce = null), this.resizeObserver = new ResizeObserver(() => {
2696
+ this.resizeDebounce && this.wnd.clearTimeout(this.resizeDebounce), this.isResizing = !0, this.resizeDebounce = this.wnd.setTimeout(() => {
2697
+ this.isResizing = !1, this.resizeDebounce = null, this.reportProgress();
2698
+ }, 50);
2699
+ }), this.resizeObserver.observe(e.document.body), e.addEventListener("scroll", this.handleScroll, { passive: !0 }), t.register("force_webkit_recalc", w.moduleName, () => {
2700
+ Ke(this.wnd);
2701
+ const i = this.doc().scrollTop;
2702
+ i > 1 ? this.doc().scrollTop = i - 1 : this.doc().scrollTop = i + 1, this.doc().scrollTop = i;
2703
+ }), t.register("go_progression", w.moduleName, (i, s) => {
2704
+ const n = i;
2705
+ if (n < 0 || n > 1) {
2706
+ t.send("error", {
2707
+ message: "go_progression must be given a position from 0.0 to 1.0"
2708
+ }), s(!1);
2709
+ return;
2710
+ }
2711
+ this.wnd.requestAnimationFrame(() => {
2712
+ this.doc().scrollTop = this.doc().offsetHeight * n, this.reportProgress(), v(this.wnd), s(!0);
2713
+ });
2714
+ }), this.comms.register("go_id", w.moduleName, (i, s) => {
2715
+ const n = e.document.getElementById(i);
2716
+ if (!n) {
2717
+ s(!1);
2718
+ return;
2719
+ }
2720
+ this.wnd.requestAnimationFrame(() => {
2721
+ this.doc().scrollTop = n.getBoundingClientRect().top + e.scrollY - e.innerHeight / 2, this.reportProgress(), v(this.wnd), s(!0);
2722
+ });
2723
+ }), t.register("go_text", w.moduleName, (i, s) => {
2724
+ let n;
2725
+ Array.isArray(i) && (i.length > 1 && (n = i[1]), i = i[0]);
2726
+ const o = z.deserialize(i), l = ee(this.wnd.document, new L({
2727
+ href: e.location.href,
2728
+ type: "text/html",
2729
+ text: o,
2730
+ locations: n ? new b({
2731
+ otherLocations: /* @__PURE__ */ new Map([
2732
+ ["cssSelector", n]
2733
+ ])
2734
+ }) : void 0
2735
+ }));
2736
+ if (!l) {
2737
+ s(!1);
2738
+ return;
2739
+ }
2740
+ this.wnd.requestAnimationFrame(() => {
2741
+ this.doc().scrollTop = l.getBoundingClientRect().top + e.scrollY - e.innerHeight / 2, this.reportProgress(), v(this.wnd), s(!0);
2742
+ });
2743
+ }), t.register("go_start", w.moduleName, (i, s) => {
2744
+ if (this.doc().scrollTop === 0) return s(!1);
2745
+ this.doc().scrollTop = 0, this.reportProgress(), s(!0);
2746
+ }), t.register("go_end", w.moduleName, (i, s) => {
2747
+ if (this.doc().scrollTop === this.doc().scrollHeight - this.doc().offsetHeight) return s(!1);
2748
+ this.doc().scrollTop = this.doc().scrollHeight - this.doc().offsetHeight, this.reportProgress(), s(!0);
2749
+ }), t.register("unfocus", w.moduleName, (i, s) => {
2750
+ v(this.wnd), s(!0);
2751
+ }), t.register([
2752
+ "go_next",
2753
+ "go_prev"
2754
+ ], w.moduleName, (i, s) => s(!1)), t.register("focus", w.moduleName, (i, s) => {
2755
+ this.reportProgress(), s(!0);
2756
+ }), t.register("first_visible_locator", w.moduleName, (i, s) => {
2757
+ const n = ve(e, !0);
2758
+ t.send("first_visible_locator", n.serialize()), s(!0);
2759
+ }), t.log("WebPubSnapper Mounted"), !0;
2733
2760
  }
2734
- unmount(t, e) {
2735
- var i;
2736
- return e.unregisterAll(P.moduleName), this.resizeObserver.disconnect(), this.handleScroll && t.removeEventListener("scroll", this.handleScroll), (i = t.document.getElementById(zt)) == null || i.remove(), e.log("ScrollSnapper Unmounted"), !0;
2761
+ unmount(e, t) {
2762
+ return t.unregisterAll(w.moduleName), this.resizeObserver.disconnect(), this.handleScroll && e.removeEventListener("scroll", this.handleScroll), t.log("WebPubSnapper Unmounted"), !0;
2737
2763
  }
2738
2764
  };
2739
- ee.moduleName = "scroll_snapper";
2740
- let _e = ee;
2741
- class ie extends K {
2765
+ w.moduleName = "webpub_snapper";
2766
+ let oe = w;
2767
+ const be = class be extends j {
2742
2768
  constructor() {
2743
2769
  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);
2744
2770
  }
2745
- onPointUp(t) {
2746
- var r, n, o, l, c;
2747
- const e = this.wnd.getSelection();
2748
- if (e && ((r = e.toString()) == null ? void 0 : r.length) > 0) {
2749
- const h = (n = e.getRangeAt(0)) == null ? void 0 : n.getClientRects();
2750
- if (!h || h.length === 0)
2771
+ onPointUp(e) {
2772
+ const t = this.wnd.getSelection();
2773
+ if (t && t.toString()?.length > 0) {
2774
+ const s = t.getRangeAt(0)?.getClientRects();
2775
+ if (!s || s.length === 0)
2751
2776
  return;
2752
- const u = h[0], p = {
2753
- text: e.toString(),
2754
- x: u.x,
2755
- y: u.y,
2756
- width: u.width,
2757
- height: u.height,
2758
- targetFrameSrc: (l = (o = this.wnd) == null ? void 0 : o.location) == null ? void 0 : l.href
2777
+ const n = s[0], o = {
2778
+ text: t.toString(),
2779
+ x: n.x,
2780
+ y: n.y,
2781
+ width: n.width,
2782
+ height: n.height,
2783
+ targetFrameSrc: this.wnd?.location?.href
2759
2784
  };
2760
- this.comms.send("text_selected", p);
2785
+ this.comms.send("text_selected", o);
2761
2786
  }
2762
2787
  if (this.pointerMoved) {
2763
2788
  this.pointerMoved = !1;
2764
2789
  return;
2765
2790
  }
2766
- if (!(e != null && e.isCollapsed) || !t.isPrimary)
2767
- return;
2791
+ if (!t?.isCollapsed || !e.isPrimary) return;
2768
2792
  const i = this.wnd.devicePixelRatio;
2769
- t.preventDefault(), this.comms.send(t.pointerType === "touch" ? "tap" : "click", {
2770
- defaultPrevented: t.defaultPrevented,
2771
- x: t.clientX * i,
2772
- y: t.clientY * i,
2793
+ e.preventDefault(), this.comms.send(e.pointerType === "touch" ? "tap" : "click", {
2794
+ defaultPrevented: e.defaultPrevented,
2795
+ x: e.clientX * i,
2796
+ y: e.clientY * i,
2773
2797
  targetFrameSrc: this.wnd.location.href,
2774
- targetElement: t.target.outerHTML,
2775
- interactiveElement: (c = Kt(t.target)) == null ? void 0 : c.outerHTML,
2776
- cssSelector: this.wnd._readium_cssSelectorGenerator.getCssSelector(t.target)
2798
+ targetElement: e.target.outerHTML,
2799
+ interactiveElement: Ze(e.target)?.outerHTML,
2800
+ cssSelector: this.wnd._readium_cssSelectorGenerator.getCssSelector(e.target)
2777
2801
  }), this.pointerMoved = !1;
2778
2802
  }
2779
- onPointMove(t) {
2780
- if (t.movementY !== void 0 && t.movementX !== void 0) {
2781
- (Math.abs(t.movementX) > 1 || Math.abs(t.movementY) > 1) && (this.pointerMoved = !0);
2803
+ onPointMove(e) {
2804
+ if (e.movementY !== void 0 && e.movementX !== void 0) {
2805
+ (Math.abs(e.movementX) > 1 || Math.abs(e.movementY) > 1) && (this.pointerMoved = !0);
2782
2806
  return;
2783
2807
  }
2784
2808
  this.pointerMoved = !0;
@@ -2786,86 +2810,83 @@ class ie extends K {
2786
2810
  onPointDown() {
2787
2811
  this.pointerMoved = !1;
2788
2812
  }
2789
- onContext(t) {
2790
- this.onPointUp(t), this.pointerMoved = !1;
2813
+ onContext(e) {
2814
+ this.onPointUp(e), this.pointerMoved = !1;
2791
2815
  }
2792
- onClick(t) {
2793
- if (t.preventDefault(), !t.isTrusted) {
2794
- const e = new PointerEvent("pointerup", {
2816
+ onClick(e) {
2817
+ if (e.preventDefault(), !e.isTrusted) {
2818
+ const t = new PointerEvent("pointerup", {
2795
2819
  isPrimary: !0,
2796
2820
  pointerType: "mouse",
2797
2821
  // Not really a better choice than this
2798
- clientX: t.clientX,
2799
- clientY: t.clientY
2822
+ clientX: e.clientX,
2823
+ clientY: e.clientY
2800
2824
  });
2801
- Object.defineProperty(e, "target", { writable: !1, value: t.target }), Object.defineProperty(e, "defaultPrevented", { writable: !1, value: t.defaultPrevented }), this.onPointUp(e);
2825
+ Object.defineProperty(t, "target", { writable: !1, value: e.target }), Object.defineProperty(t, "defaultPrevented", { writable: !1, value: e.defaultPrevented }), this.onPointUp(t);
2802
2826
  }
2803
2827
  }
2804
- mount(t, e) {
2805
- return this.wnd = t, this.comms = e, t.document.addEventListener("pointerdown", this.onPointerDown), t.document.addEventListener("pointerup", this.onPointerUp), t.document.addEventListener("contextmenu", this.onContextMenu), t.document.addEventListener("pointermove", this.onPointerMove), t.document.addEventListener("click", this.onClicker), e.log("Peripherals Mounted"), !0;
2828
+ mount(e, t) {
2829
+ 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;
2806
2830
  }
2807
- unmount(t, e) {
2808
- return t.document.removeEventListener("pointerdown", this.onPointerDown), t.document.removeEventListener("pointerup", this.onPointerUp), t.document.removeEventListener("contextmenu", this.onContextMenu), t.document.removeEventListener("pointermove", this.onPointerMove), t.document.removeEventListener("click", this.onClicker), e.log("Peripherals Unmounted"), !0;
2831
+ unmount(e, t) {
2832
+ 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;
2809
2833
  }
2810
- }
2811
- ie.moduleName = "peripherals";
2812
- const se = class st extends K {
2834
+ };
2835
+ be.moduleName = "peripherals";
2836
+ let ae = be;
2837
+ const k = class k extends j {
2813
2838
  constructor() {
2814
2839
  super(...arguments), this.mediaPlayingCount = 0, this.allAnimations = /* @__PURE__ */ new Set();
2815
2840
  }
2816
- wndOnErr(t) {
2817
- var e;
2818
- (e = this.comms) == null || e.send("error", {
2819
- message: t.message,
2820
- filename: t.filename,
2821
- lineno: t.lineno,
2822
- colno: t.colno
2841
+ wndOnErr(e) {
2842
+ this.comms?.send("error", {
2843
+ message: e.message,
2844
+ filename: e.filename,
2845
+ lineno: e.lineno,
2846
+ colno: e.colno
2823
2847
  });
2824
2848
  }
2825
- unblock(t) {
2826
- var e;
2827
- for (t._readium_blockEvents = !1; ((e = t._readium_blockedEvents) == null ? void 0 : e.length) > 0; ) {
2828
- const i = t._readium_blockedEvents.shift();
2829
- switch (i[0]) {
2849
+ unblock(e) {
2850
+ for (e._readium_blockEvents = !1; e._readium_blockedEvents?.length > 0; ) {
2851
+ const t = e._readium_blockedEvents.shift();
2852
+ switch (t[0]) {
2830
2853
  case 0:
2831
- Reflect.apply(i[1], i[2], i[3]);
2854
+ Reflect.apply(t[1], t[2], t[3]);
2832
2855
  break;
2833
2856
  case 1:
2834
- const r = i[1], n = i[2];
2835
- t.removeEventListener(r.type, t._readium_eventBlocker, !0);
2836
- const o = new Event(r.type, {
2837
- bubbles: r.bubbles,
2838
- cancelable: r.cancelable
2857
+ const i = t[1], s = t[2];
2858
+ e.removeEventListener(i.type, e._readium_eventBlocker, !0);
2859
+ const n = new Event(i.type, {
2860
+ bubbles: i.bubbles,
2861
+ cancelable: i.cancelable
2839
2862
  });
2840
- n ? n.dispatchEvent(o) : t.dispatchEvent(o);
2863
+ s ? s.dispatchEvent(n) : e.dispatchEvent(n);
2841
2864
  break;
2842
2865
  }
2843
2866
  }
2844
2867
  }
2845
2868
  onMediaPlayEvent() {
2846
- var t;
2847
- this.mediaPlayingCount++, (t = this.comms) == null || t.send("media_play", this.mediaPlayingCount);
2869
+ this.mediaPlayingCount++, this.comms?.send("media_play", this.mediaPlayingCount);
2848
2870
  }
2849
2871
  onMediaPauseEvent() {
2850
- var t;
2851
- this.mediaPlayingCount > 0 && this.mediaPlayingCount--, (t = this.comms) == null || t.send("media_pause", this.mediaPlayingCount);
2872
+ this.mediaPlayingCount > 0 && this.mediaPlayingCount--, this.comms?.send("media_pause", this.mediaPlayingCount);
2852
2873
  }
2853
- pauseAllMedia(t) {
2854
- const e = t.document.querySelectorAll("audio,video");
2855
- for (let i = 0; i < e.length; i++)
2856
- e[i].pause();
2874
+ pauseAllMedia(e) {
2875
+ const t = e.document.querySelectorAll("audio,video");
2876
+ for (let i = 0; i < t.length; i++)
2877
+ t[i].pause();
2857
2878
  }
2858
- mount(t, e) {
2859
- this.comms = e, t.addEventListener(
2879
+ mount(e, t) {
2880
+ this.comms = t, e.addEventListener(
2860
2881
  "error",
2861
2882
  this.wndOnErr,
2862
2883
  !1
2863
- ), Reflect.defineProperty(t.navigator, "epubReadingSystem", {
2884
+ ), Reflect.defineProperty(e.navigator, "epubReadingSystem", {
2864
2885
  value: {
2865
2886
  name: "readium-ts-toolkit",
2866
- version: "2.1.0",
2867
- hasFeature: (r, n = "") => {
2868
- switch (r) {
2887
+ version: "2.2.0",
2888
+ hasFeature: (s, n = "") => {
2889
+ switch (s) {
2869
2890
  case "dom-manipulation":
2870
2891
  return !0;
2871
2892
  case "layout-changes":
@@ -2886,73 +2907,70 @@ const se = class st extends K {
2886
2907
  }
2887
2908
  },
2888
2909
  writable: !1
2889
- }), "getAnimations" in t.document && t.document.getAnimations().forEach((r) => {
2890
- r.cancel(), this.allAnimations.add(r);
2891
- }), e.register("activate", st.moduleName, (r, n) => {
2910
+ }), "getAnimations" in e.document && e.document.getAnimations().forEach((s) => {
2911
+ s.cancel(), this.allAnimations.add(s);
2912
+ }), t.register("activate", k.moduleName, (s, n) => {
2892
2913
  this.allAnimations.forEach((o) => {
2893
2914
  o.cancel(), o.play();
2894
2915
  }), n(!0);
2895
- }), e.register("unfocus", st.moduleName, (r, n) => {
2896
- this.pauseAllMedia(t), this.allAnimations.forEach((o) => o.pause()), n(!0);
2916
+ }), t.register("unfocus", k.moduleName, (s, n) => {
2917
+ this.pauseAllMedia(e), this.allAnimations.forEach((o) => o.pause()), n(!0);
2897
2918
  });
2898
- const i = t.document.querySelectorAll("audio,video");
2899
- for (let r = 0; r < i.length; r++) {
2900
- const n = i[r];
2919
+ const i = e.document.querySelectorAll("audio,video");
2920
+ for (let s = 0; s < i.length; s++) {
2921
+ const n = i[s];
2901
2922
  n.addEventListener("play", this.onMediaPlayEvent, {
2902
2923
  passive: !0
2903
2924
  }), n.addEventListener("pause", this.onMediaPauseEvent, {
2904
2925
  passive: !0
2905
2926
  });
2906
2927
  }
2907
- return e.log("Setup Mounted"), !0;
2928
+ return t.log("Setup Mounted"), !0;
2908
2929
  }
2909
- unmount(t, e) {
2910
- return t.removeEventListener("error", this.wndOnErr), t.removeEventListener("play", this.onMediaPlayEvent), t.removeEventListener("pause", this.onMediaPauseEvent), this.allAnimations.forEach((i) => i.cancel()), this.allAnimations.clear(), e.log("Setup Unmounted"), !0;
2930
+ unmount(e, t) {
2931
+ return e.removeEventListener("error", this.wndOnErr), e.removeEventListener("play", this.onMediaPlayEvent), e.removeEventListener("pause", this.onMediaPauseEvent), this.allAnimations.forEach((i) => i.cancel()), this.allAnimations.clear(), t.log("Setup Unmounted"), !0;
2911
2932
  }
2912
2933
  };
2913
- se.moduleName = "setup";
2914
- let re = se;
2915
- const Dt = "readium-viewport", ne = class U extends re {
2916
- onViewportWidthChanged(t) {
2917
- const e = t.target;
2918
- Z(e, "--RS__viewportWidth", `${e.innerWidth}px`);
2919
- }
2920
- mount(t, e) {
2921
- if (!super.mount(t, e))
2922
- return !1;
2923
- const i = t.document.createElement("meta");
2924
- return i.dataset.readium = "true", i.setAttribute("name", "viewport"), i.setAttribute("id", Dt), i.setAttribute(
2934
+ k.moduleName = "setup";
2935
+ let J = k;
2936
+ const Fe = "readium-viewport", O = class O extends J {
2937
+ onViewportWidthChanged(e) {
2938
+ const t = e.target;
2939
+ Z(t, "--RS__viewportWidth", `${t.innerWidth}px`);
2940
+ }
2941
+ mount(e, t) {
2942
+ if (!super.mount(e, t)) return !1;
2943
+ const i = e.document.createElement("meta");
2944
+ return i.dataset.readium = "true", i.setAttribute("name", "viewport"), i.setAttribute("id", Fe), i.setAttribute(
2925
2945
  "content",
2926
2946
  "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"
2927
- ), t.document.head.appendChild(i), t.addEventListener("orientationchange", this.onViewportWidthChanged), t.addEventListener("resize", this.onViewportWidthChanged), this.onViewportWidthChanged({
2928
- target: t
2929
- }), e.register("get_properties", U.moduleName, (r, n) => {
2930
- _t(t), n(!0);
2931
- }), e.register("update_properties", U.moduleName, (r, n) => {
2932
- r["--RS__viewportWidth"] = `${t.innerWidth}px`, Ae(t, r), n(!0);
2933
- }), e.register("set_property", U.moduleName, (r, n) => {
2934
- const o = r;
2935
- Z(t, o[0], o[1]), n(!0);
2936
- }), e.register("remove_property", U.moduleName, (r, n) => {
2937
- ut(t, r), n(!0);
2938
- }), e.register("activate", U.moduleName, (r, n) => {
2939
- this.unblock(t), n(!0);
2940
- }), e.log("ReflowableSetup Mounted"), !0;
2941
- }
2942
- unmount(t, e) {
2943
- var i;
2944
- return e.unregisterAll(U.moduleName), (i = t.document.head.querySelector(`#${Dt}`)) == null || i.remove(), t.removeEventListener("orientationchange", this.onViewportWidthChanged), e.log("ReflowableSetup Unmounted"), super.unmount(t, e);
2947
+ ), e.document.head.appendChild(i), e.addEventListener("orientationchange", this.onViewportWidthChanged), e.addEventListener("resize", this.onViewportWidthChanged), this.onViewportWidthChanged({
2948
+ target: e
2949
+ }), t.register("get_properties", O.moduleName, (s, n) => {
2950
+ Ge(e), n(!0);
2951
+ }), t.register("update_properties", O.moduleName, (s, n) => {
2952
+ s["--RS__viewportWidth"] = `${e.innerWidth}px`, vt(e, s), n(!0);
2953
+ }), t.register("set_property", O.moduleName, (s, n) => {
2954
+ const o = s;
2955
+ Z(e, o[0], o[1]), n(!0);
2956
+ }), t.register("remove_property", O.moduleName, (s, n) => {
2957
+ ye(e, s), n(!0);
2958
+ }), t.register("activate", O.moduleName, (s, n) => {
2959
+ this.unblock(e), n(!0);
2960
+ }), t.log("ReflowableSetup Mounted"), !0;
2961
+ }
2962
+ unmount(e, t) {
2963
+ return t.unregisterAll(O.moduleName), e.document.head.querySelector(`#${Fe}`)?.remove(), e.removeEventListener("orientationchange", this.onViewportWidthChanged), t.log("ReflowableSetup Unmounted"), super.unmount(e, t);
2945
2964
  }
2946
2965
  };
2947
- ne.moduleName = "reflowable_setup";
2948
- let Xe = ne;
2949
- const Wt = "readium-fixed-style", oe = class R extends re {
2950
- mount(t, e) {
2951
- if (!super.mount(t, e))
2952
- return !1;
2953
- t.navigator.epubReadingSystem.layoutStyle = "paginated";
2954
- const i = t.document.createElement("style");
2955
- return i.id = Wt, i.dataset.readium = "true", i.textContent = `
2966
+ O.moduleName = "reflowable_setup";
2967
+ let le = O;
2968
+ const Ue = "readium-fixed-style", A = class A extends J {
2969
+ mount(e, t) {
2970
+ if (!super.mount(e, t)) return !1;
2971
+ e.navigator.epubReadingSystem && (e.navigator.epubReadingSystem.layoutStyle = "paginated");
2972
+ const i = e.document.createElement("style");
2973
+ return i.id = Ue, i.dataset.readium = "true", i.textContent = `
2956
2974
  html, body {
2957
2975
  text-size-adjust: none;
2958
2976
  -ms-text-size-adjust: none;
@@ -2964,14 +2982,14 @@ const Wt = "readium-fixed-style", oe = class R extends re {
2964
2982
  min-height: 100%;
2965
2983
 
2966
2984
  /*cursor: var() TODO*/
2967
- }`, t.document.head.appendChild(i), e.register("set_property", R.moduleName, (r, n) => {
2968
- const o = r;
2969
- Z(t, o[0], o[1]), n(!0);
2970
- }), e.register("remove_property", R.moduleName, (r, n) => {
2971
- ut(t, r), n(!0);
2972
- }), e.register("first_visible_locator", R.moduleName, (r, n) => n(!1)), e.register("unfocus", R.moduleName, (r, n) => {
2973
- S(t), n(!0);
2974
- }), e.register([
2985
+ }`, e.document.head.appendChild(i), t.register("set_property", A.moduleName, (s, n) => {
2986
+ const o = s;
2987
+ Z(e, o[0], o[1]), n(!0);
2988
+ }), t.register("remove_property", A.moduleName, (s, n) => {
2989
+ ye(e, s), n(!0);
2990
+ }), t.register("first_visible_locator", A.moduleName, (s, n) => n(!1)), t.register("unfocus", A.moduleName, (s, n) => {
2991
+ v(e), n(!0);
2992
+ }), t.register([
2975
2993
  "focus",
2976
2994
  "go_next",
2977
2995
  "go_prev",
@@ -2980,97 +2998,128 @@ const Wt = "readium-fixed-style", oe = class R extends re {
2980
2998
  "go_start",
2981
2999
  "go_text",
2982
3000
  "go_progression"
2983
- ], R.moduleName, (r, n) => n(!0)), e.register("activate", R.moduleName, (r, n) => {
2984
- this.unblock(t), n(!0);
2985
- }), e.log("FixedSetup Mounted"), !0;
3001
+ ], A.moduleName, (s, n) => n(!0)), t.register("activate", A.moduleName, (s, n) => {
3002
+ this.unblock(e), n(!0);
3003
+ }), t.log("FixedSetup Mounted"), !0;
3004
+ }
3005
+ unmount(e, t) {
3006
+ return t.unregisterAll(A.moduleName), e.document.getElementById(Ue)?.remove(), t.log("FixedSetup Unmounted"), super.unmount(e, t);
3007
+ }
3008
+ };
3009
+ A.moduleName = "fixed_setup";
3010
+ let he = A;
3011
+ const Q = class Q extends j {
3012
+ wndOnErr(e) {
3013
+ this.comms?.send("error", {
3014
+ message: e.message,
3015
+ filename: e.filename,
3016
+ lineno: e.lineno,
3017
+ colno: e.colno
3018
+ });
3019
+ }
3020
+ mount(e, t) {
3021
+ return this.comms = t, e.addEventListener(
3022
+ "error",
3023
+ this.wndOnErr,
3024
+ !1
3025
+ ), t.register("activate", Q.moduleName, (i, s) => {
3026
+ s(!0);
3027
+ }), t.log("WebPubSetup Mounted"), !0;
2986
3028
  }
2987
- unmount(t, e) {
2988
- var i;
2989
- return e.unregisterAll(R.moduleName), (i = t.document.getElementById(Wt)) == null || i.remove(), e.log("FixedSetup Unmounted"), super.unmount(t, e);
3029
+ unmount(e, t) {
3030
+ return e.removeEventListener("error", this.wndOnErr), t.log("WebPubSetup Unmounted"), !0;
2990
3031
  }
2991
3032
  };
2992
- oe.moduleName = "fixed_setup";
2993
- let Ge = oe;
2994
- const Ye = [
3033
+ Q.moduleName = "webpub_setup";
3034
+ let ce = Q;
3035
+ const Rt = [
2995
3036
  "fixed_setup",
2996
3037
  "decorator",
2997
3038
  "peripherals"
2998
- ], Ze = [
3039
+ ], zt = [
2999
3040
  "reflowable_setup",
3000
3041
  "decorator",
3001
3042
  "peripherals",
3002
3043
  "column_snapper",
3003
3044
  "scroll_snapper"
3004
- ], Ft = new Map([
3045
+ ], Dt = [
3046
+ "webpub_setup",
3047
+ "webpub_snapper",
3048
+ "decorator",
3049
+ "peripherals"
3050
+ ], Be = new Map([
3005
3051
  // All modules go here
3006
- Ge,
3007
- Xe,
3008
- ie,
3009
- Fe,
3010
- qe,
3011
- _e
3012
- ].map((s) => [s.moduleName, s]));
3013
- class Ke {
3052
+ he,
3053
+ le,
3054
+ ce,
3055
+ oe,
3056
+ ae,
3057
+ se,
3058
+ re,
3059
+ ne
3060
+ ].map((r) => [r.moduleName, r]));
3061
+ class Wt {
3014
3062
  /**
3015
3063
  * @param wnd Window instance to operate on
3016
3064
  * @param initialModules List of initial modules to load
3017
3065
  */
3018
- constructor(t = window, e = []) {
3019
- this.loadedModules = [], this.wnd = t, this.comms = new he(t);
3020
- const i = [...new Set(e)];
3066
+ constructor(e = window, t = []) {
3067
+ this.loadedModules = [], this.wnd = e, this.comms = new tt(e);
3068
+ const i = [...new Set(t)];
3021
3069
  if (i.length) {
3022
- if (typeof t > "u")
3070
+ if (typeof e > "u")
3023
3071
  throw Error("Loader is not in a web browser");
3024
- t.parent !== t && this.comms.log("Loader is probably in a frame"), this.loadedModules = i.map((r) => {
3025
- const n = this.loadModule(r);
3072
+ e.parent !== e && this.comms.log("Loader is probably in a frame"), this.loadedModules = i.map((s) => {
3073
+ const n = this.loadModule(s);
3026
3074
  if (n)
3027
3075
  return n.mount(this.wnd, this.comms), n;
3028
- }).filter((r) => r !== void 0);
3076
+ }).filter((s) => s !== void 0);
3029
3077
  }
3030
3078
  }
3031
- loadModule(t) {
3032
- const e = Ft.get(t);
3033
- return e === void 0 ? (this.comms.log(`Module "${name}" does not exist in the library`), e) : new e();
3079
+ loadModule(e) {
3080
+ const t = Be.get(e);
3081
+ return t === void 0 ? (this.comms.log(`Module "${name}" does not exist in the library`), t) : new t();
3034
3082
  }
3035
3083
  /**
3036
3084
  * Add a module by name
3037
3085
  * @param moduleName Module name
3038
3086
  * @returns Success
3039
3087
  */
3040
- addModule(t) {
3041
- const e = this.loadModule(t);
3042
- return !e || !e.mount(this.wnd, this.comms) ? !1 : (this.loadedModules.push(e), !0);
3088
+ addModule(e) {
3089
+ const t = this.loadModule(e);
3090
+ return !t || !t.mount(this.wnd, this.comms) ? !1 : (this.loadedModules.push(t), !0);
3043
3091
  }
3044
3092
  /**
3045
3093
  * Remove a module by name
3046
3094
  * @param moduleName Module name
3047
3095
  * @returns Success
3048
3096
  */
3049
- removeModule(t) {
3050
- const e = Ft.get(t);
3051
- if (e === void 0)
3052
- return this.comms.log(`Module "${t}" does not exist in the library`), !1;
3053
- const i = this.loadedModules.findIndex((r) => r instanceof e);
3097
+ removeModule(e) {
3098
+ const t = Be.get(e);
3099
+ if (t === void 0)
3100
+ return this.comms.log(`Module "${e}" does not exist in the library`), !1;
3101
+ const i = this.loadedModules.findIndex((s) => s instanceof t);
3054
3102
  return i < 0 ? !1 : (this.loadedModules[i].unmount(this.wnd, this.comms), this.loadedModules.splice(i, 1), !0);
3055
3103
  }
3056
3104
  /**
3057
3105
  * Unmount and remove all modules
3058
3106
  */
3059
3107
  destroy() {
3060
- this.comms.destroy(), this.loadedModules.forEach((t) => t.unmount(this.wnd, this.comms)), this.loadedModules = [];
3108
+ this.comms.destroy(), this.loadedModules.forEach((e) => e.unmount(this.wnd, this.comms)), this.loadedModules = [];
3061
3109
  }
3062
3110
  }
3063
3111
  export {
3064
- H as COMMS_VERSION,
3065
- he as Comms,
3066
- Fe as Decorator,
3067
- Ye as FXLModules,
3068
- ze as Layout,
3069
- Ke as Loader,
3070
- K as Module,
3071
- Ft as ModuleLibrary,
3072
- ie as Peripherals,
3073
- Ze as ReflowableModules,
3074
- Re as Width,
3075
- le as mid
3112
+ U as COMMS_VERSION,
3113
+ tt as Comms,
3114
+ se as Decorator,
3115
+ Rt as FXLModules,
3116
+ wt as Layout,
3117
+ Wt as Loader,
3118
+ j as Module,
3119
+ Be as ModuleLibrary,
3120
+ ae as Peripherals,
3121
+ zt as ReflowableModules,
3122
+ Dt as WebPubModules,
3123
+ Tt as Width,
3124
+ et as mid
3076
3125
  };