@readium/shared 1.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.
Files changed (150) hide show
  1. package/LICENSE +28 -0
  2. package/README.MD +27 -0
  3. package/dist/index.js +2536 -0
  4. package/dist/index.umd.cjs +2 -0
  5. package/package.json +73 -0
  6. package/src/fetcher/Fetcher.ts +37 -0
  7. package/src/fetcher/HttpFetcher.ts +122 -0
  8. package/src/fetcher/Resource.ts +37 -0
  9. package/src/fetcher/index.ts +2 -0
  10. package/src/index.ts +4 -0
  11. package/src/opds/Acquisition.ts +54 -0
  12. package/src/opds/Availability.ts +61 -0
  13. package/src/opds/Copies.ts +43 -0
  14. package/src/opds/Holds.ts +43 -0
  15. package/src/opds/Price.ts +51 -0
  16. package/src/opds/index.ts +5 -0
  17. package/src/publication/BelongsTo.ts +51 -0
  18. package/src/publication/Contributor.ts +129 -0
  19. package/src/publication/GuidedNavigation.ts +176 -0
  20. package/src/publication/Link.ts +332 -0
  21. package/src/publication/LocalizedString.ts +74 -0
  22. package/src/publication/Locator.ts +225 -0
  23. package/src/publication/LocatorCollection.ts +133 -0
  24. package/src/publication/Manifest.ts +256 -0
  25. package/src/publication/Metadata.ts +329 -0
  26. package/src/publication/Properties.ts +44 -0
  27. package/src/publication/Publication.ts +148 -0
  28. package/src/publication/PublicationCollection.ts +144 -0
  29. package/src/publication/ReadingProgression.ts +28 -0
  30. package/src/publication/Subject.ts +115 -0
  31. package/src/publication/encryption/Encryption.ts +68 -0
  32. package/src/publication/encryption/Properties.ts +20 -0
  33. package/src/publication/encryption/index.ts +2 -0
  34. package/src/publication/epub/EPUBLayout.ts +10 -0
  35. package/src/publication/epub/Presentation.ts +16 -0
  36. package/src/publication/epub/Properties.ts +28 -0
  37. package/src/publication/epub/Publication.ts +51 -0
  38. package/src/publication/epub/index.ts +4 -0
  39. package/src/publication/html/DomRange.ts +63 -0
  40. package/src/publication/html/DomRangePoint.ts +64 -0
  41. package/src/publication/html/Locations.ts +129 -0
  42. package/src/publication/html/index.ts +3 -0
  43. package/src/publication/index.ts +19 -0
  44. package/src/publication/opds/Properties.ts +84 -0
  45. package/src/publication/opds/Publication.ts +14 -0
  46. package/src/publication/opds/index.ts +2 -0
  47. package/src/publication/presentation/Metadata.ts +19 -0
  48. package/src/publication/presentation/Presentation.ts +155 -0
  49. package/src/publication/presentation/Properties.ts +70 -0
  50. package/src/publication/presentation/index.ts +3 -0
  51. package/src/publication/services/content/Content.ts +36 -0
  52. package/src/publication/services/content/ContentTokenizer.ts +62 -0
  53. package/src/publication/services/content/Iterator.ts +46 -0
  54. package/src/publication/services/content/element/attributes.ts +44 -0
  55. package/src/publication/services/content/element/element.ts +118 -0
  56. package/src/publication/services/content/element/index.ts +3 -0
  57. package/src/publication/services/content/element/text_role.ts +60 -0
  58. package/src/publication/services/content/index.ts +5 -0
  59. package/src/publication/services/content/iterators/HTMLResourceContentIterator.ts +571 -0
  60. package/src/publication/services/content/iterators/PDFTextContentIterator.ts +184 -0
  61. package/src/publication/services/content/iterators/PublicationContentIterator.ts +144 -0
  62. package/src/publication/services/content/iterators/helpers.ts +146 -0
  63. package/src/publication/services/content/iterators/index.ts +3 -0
  64. package/src/publication/services/index.ts +1 -0
  65. package/src/util/JSONParse.ts +31 -0
  66. package/src/util/Language.ts +5 -0
  67. package/src/util/URITemplate.ts +83 -0
  68. package/src/util/index.ts +5 -0
  69. package/src/util/mediatype/MediaType.ts +563 -0
  70. package/src/util/mediatype/index.ts +1 -0
  71. package/src/util/tokenizer/TextTokenizer.ts +126 -0
  72. package/src/util/tokenizer/Tokenizer.ts +8 -0
  73. package/src/util/tokenizer/index.ts +2 -0
  74. package/src/util/tokenizer/tokenize-english/README.md +7 -0
  75. package/src/util/tokenizer/tokenize-english/abbreviations.js +52 -0
  76. package/src/util/tokenizer/tokenize-english/index.d.ts +3 -0
  77. package/src/util/tokenizer/tokenize-english/index.js +243 -0
  78. package/src/util/tokenizer/tokenize-english/utils.js +16 -0
  79. package/src/util/tokenizer/tokenize-text/README.MD +6 -0
  80. package/src/util/tokenizer/tokenize-text/index.d.ts +52 -0
  81. package/src/util/tokenizer/tokenize-text/index.js +256 -0
  82. package/src/util/tokenizer/tokenize-text/tokens.js +100 -0
  83. package/types/src/fetcher/Fetcher.d.ts +27 -0
  84. package/types/src/fetcher/HttpFetcher.d.ts +28 -0
  85. package/types/src/fetcher/Resource.d.ts +15 -0
  86. package/types/src/fetcher/index.d.ts +2 -0
  87. package/types/src/index.d.ts +4 -0
  88. package/types/src/opds/Acquisition.d.ts +26 -0
  89. package/types/src/opds/Availability.d.ts +32 -0
  90. package/types/src/opds/Copies.d.ts +22 -0
  91. package/types/src/opds/Holds.d.ts +22 -0
  92. package/types/src/opds/Price.d.ts +29 -0
  93. package/types/src/opds/index.d.ts +5 -0
  94. package/types/src/publication/BelongsTo.d.ts +23 -0
  95. package/types/src/publication/Contributor.d.ts +60 -0
  96. package/types/src/publication/GuidedNavigation.d.ts +70 -0
  97. package/types/src/publication/Link.d.ts +128 -0
  98. package/types/src/publication/LocalizedString.d.ts +48 -0
  99. package/types/src/publication/Locator.d.ts +101 -0
  100. package/types/src/publication/LocatorCollection.d.ts +54 -0
  101. package/types/src/publication/Manifest.d.ts +59 -0
  102. package/types/src/publication/Metadata.d.ts +101 -0
  103. package/types/src/publication/Properties.d.ts +28 -0
  104. package/types/src/publication/Publication.d.ts +53 -0
  105. package/types/src/publication/PublicationCollection.d.ts +34 -0
  106. package/types/src/publication/ReadingProgression.d.ts +9 -0
  107. package/types/src/publication/Subject.d.ts +56 -0
  108. package/types/src/publication/encryption/Encryption.d.ts +33 -0
  109. package/types/src/publication/encryption/Properties.d.ts +10 -0
  110. package/types/src/publication/encryption/index.d.ts +2 -0
  111. package/types/src/publication/epub/EPUBLayout.d.ts +5 -0
  112. package/types/src/publication/epub/Presentation.d.ts +7 -0
  113. package/types/src/publication/epub/Properties.d.ts +14 -0
  114. package/types/src/publication/epub/Publication.d.ts +19 -0
  115. package/types/src/publication/epub/index.d.ts +4 -0
  116. package/types/src/publication/html/DomRange.d.ts +40 -0
  117. package/types/src/publication/html/DomRangePoint.d.ts +36 -0
  118. package/types/src/publication/html/Locations.d.ts +45 -0
  119. package/types/src/publication/html/index.d.ts +3 -0
  120. package/types/src/publication/index.d.ts +19 -0
  121. package/types/src/publication/opds/Properties.d.ts +38 -0
  122. package/types/src/publication/opds/Publication.d.ts +6 -0
  123. package/types/src/publication/opds/index.d.ts +2 -0
  124. package/types/src/publication/presentation/Metadata.d.ts +6 -0
  125. package/types/src/publication/presentation/Presentation.d.ts +95 -0
  126. package/types/src/publication/presentation/Properties.d.ts +32 -0
  127. package/types/src/publication/presentation/index.d.ts +3 -0
  128. package/types/src/publication/services/content/Content.d.ts +20 -0
  129. package/types/src/publication/services/content/ContentTokenizer.d.ts +19 -0
  130. package/types/src/publication/services/content/Iterator.d.ts +38 -0
  131. package/types/src/publication/services/content/element/attributes.d.ts +31 -0
  132. package/types/src/publication/services/content/element/element.d.ts +107 -0
  133. package/types/src/publication/services/content/element/index.d.ts +3 -0
  134. package/types/src/publication/services/content/element/text_role.d.ts +53 -0
  135. package/types/src/publication/services/content/index.d.ts +5 -0
  136. package/types/src/publication/services/content/iterators/HTMLResourceContentIterator.d.ts +30 -0
  137. package/types/src/publication/services/content/iterators/PDFTextContentIterator.d.ts +60 -0
  138. package/types/src/publication/services/content/iterators/PublicationContentIterator.d.ts +59 -0
  139. package/types/src/publication/services/content/iterators/helpers.d.ts +10 -0
  140. package/types/src/publication/services/content/iterators/index.d.ts +3 -0
  141. package/types/src/publication/services/index.d.ts +1 -0
  142. package/types/src/util/JSONParse.d.ts +11 -0
  143. package/types/src/util/Language.d.ts +1 -0
  144. package/types/src/util/URITemplate.d.ts +24 -0
  145. package/types/src/util/index.d.ts +5 -0
  146. package/types/src/util/mediatype/MediaType.d.ts +148 -0
  147. package/types/src/util/mediatype/index.d.ts +1 -0
  148. package/types/src/util/tokenizer/TextTokenizer.d.ts +39 -0
  149. package/types/src/util/tokenizer/Tokenizer.d.ts +6 -0
  150. package/types/src/util/tokenizer/index.d.ts +2 -0
package/dist/index.js ADDED
@@ -0,0 +1,2536 @@
1
+ class kt {
2
+ close() {
3
+ }
4
+ links() {
5
+ return [];
6
+ }
7
+ get(t) {
8
+ throw Error("This is an empty fetcher");
9
+ }
10
+ }
11
+ class ne {
12
+ constructor(t, e) {
13
+ this.client = t || window.fetch.bind(window), this.baseUrl = e;
14
+ }
15
+ links() {
16
+ return [];
17
+ }
18
+ get(t) {
19
+ const e = t.toURL(this.baseUrl);
20
+ if (e === void 0)
21
+ throw Error(`Invalid HREF: ${t.href}`);
22
+ return new St(this.client, t, e);
23
+ }
24
+ close() {
25
+ }
26
+ }
27
+ class St {
28
+ constructor(t, e, i) {
29
+ this.client = t || window.fetch.bind(window), this._link = e, this.url = i;
30
+ }
31
+ /** Cached HEAD response to get the expected content length and other metadata. */
32
+ async headResponse() {
33
+ if (this._headResponse)
34
+ return this._headResponse;
35
+ const t = await this.client(this.url, {
36
+ method: "HEAD"
37
+ });
38
+ if (!t.ok)
39
+ throw new Error(
40
+ `http HEAD request for ${this.url} failed with HTTP status code ${t.status}`
41
+ );
42
+ return this._headResponse = t, t;
43
+ }
44
+ close() {
45
+ }
46
+ async link() {
47
+ return this._link;
48
+ }
49
+ async read(t) {
50
+ if (t)
51
+ throw new Error("http read range not implemented!");
52
+ const e = await this.client(this.url);
53
+ if (!e.ok)
54
+ throw new Error(
55
+ `http GET request for ${this.url} failed with HTTP status code ${e.status}`
56
+ );
57
+ return new Uint8Array(await e.arrayBuffer());
58
+ }
59
+ async length() {
60
+ const e = (await this.headResponse()).headers.get("content-length");
61
+ if (e === null || e === "")
62
+ throw new Error("length for resource unavailable");
63
+ return parseInt(e);
64
+ }
65
+ async readAsJSON() {
66
+ const t = await this.client(this.url);
67
+ if (!t.ok)
68
+ throw new Error(
69
+ `http GET request for ${this.url} failed with HTTP status code ${t.status}`
70
+ );
71
+ return await t.json();
72
+ }
73
+ async readAsString() {
74
+ const t = await this.client(this.url);
75
+ if (!t.ok)
76
+ throw new Error(
77
+ `http GET request for ${this.url} failed with HTTP status code ${t.status}`
78
+ );
79
+ return await t.text();
80
+ }
81
+ async readAsXML() {
82
+ const t = await this.client(this.url);
83
+ if (!t.ok)
84
+ throw new Error(
85
+ `http GET request for ${this.url} failed with HTTP status code ${t.status}`
86
+ );
87
+ return new DOMParser().parseFromString(
88
+ await t.text(),
89
+ "application/xml"
90
+ );
91
+ }
92
+ }
93
+ class M {
94
+ /**
95
+ * Creates a [Encryption].
96
+ */
97
+ constructor(t) {
98
+ this.algorithm = t.algorithm, this.compression = t.compression, this.originalLength = t.originalLength, this.profile = t.profile, this.scheme = t.scheme;
99
+ }
100
+ /**
101
+ * Parses a [Encryption] from its RWPM JSON representation.
102
+ */
103
+ static deserialize(t) {
104
+ if (t && t.algorithm)
105
+ return new M({
106
+ algorithm: t.algorithm,
107
+ compression: t.compression,
108
+ originalLength: t.originalLength,
109
+ profile: t.profile,
110
+ scheme: t.scheme
111
+ });
112
+ }
113
+ /**
114
+ * Serializes a [Encryption] to its RWPM JSON representation.
115
+ */
116
+ serialize() {
117
+ const t = { algorithm: this.algorithm };
118
+ 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;
119
+ }
120
+ }
121
+ class g {
122
+ constructor(t) {
123
+ this.otherProperties = t;
124
+ }
125
+ /**
126
+ * Creates a [Properties] from its RWPM JSON representation.
127
+ */
128
+ static deserialize(t) {
129
+ if (t)
130
+ return new g(t);
131
+ }
132
+ /**
133
+ * Serializes a [Properties] to its RWPM JSON representation.
134
+ */
135
+ serialize() {
136
+ return this.otherProperties;
137
+ }
138
+ /**
139
+ * Makes a copy of this [Properties] after merging in the given additional other [properties].
140
+ */
141
+ add(t) {
142
+ const e = Object.assign({}, this.otherProperties);
143
+ for (const i in t)
144
+ e[i] = t[i];
145
+ return new g(e);
146
+ }
147
+ }
148
+ Object.defineProperty(g.prototype, "encryption", {
149
+ get: function() {
150
+ return M.deserialize(this.otherProperties.encrypted);
151
+ }
152
+ });
153
+ var ot = /* @__PURE__ */ ((r) => (r.fixed = "fixed", r.reflowable = "reflowable", r))(ot || {}), Tt = /* @__PURE__ */ ((r) => (r.auto = "auto", r.landscape = "landscape", r.portrait = "portrait", r))(Tt || {}), Nt = /* @__PURE__ */ ((r) => (r.auto = "auto", r.clipped = "clipped", r.paginated = "paginated", r.scrolled = "scrolled", r))(Nt || {}), W = /* @__PURE__ */ ((r) => (r.left = "left", r.right = "right", r.center = "center", r))(W || {}), Lt = /* @__PURE__ */ ((r) => (r.auto = "auto", r.both = "both", r.none = "none", r.landscape = "landscape", r))(Lt || {}), Ct = /* @__PURE__ */ ((r) => (r.contain = "contain", r.cover = "cover", r.width = "width", r.height = "height", r))(Ct || {});
154
+ class J {
155
+ /** Creates a [Presentation]. */
156
+ constructor(t) {
157
+ this.clipped = t.clipped, this.fit = t.fit, this.orientation = t.orientation, this.spread = t.spread, this.layout = t.layout, this.continuous = t.continuous, this.overflow = t.overflow;
158
+ }
159
+ /**
160
+ * Parses a [Presentation] from its RWPM JSON representation.
161
+ *
162
+ */
163
+ static deserialize(t) {
164
+ if (t)
165
+ return new J({
166
+ clipped: t.clipped,
167
+ continuous: t.continuous,
168
+ fit: t.fit,
169
+ orientation: t.orientation,
170
+ overflow: t.overflow,
171
+ spread: t.spread,
172
+ layout: t.layout
173
+ });
174
+ }
175
+ /**
176
+ * Serializes a [Presentation] to its RWPM JSON representation.
177
+ */
178
+ serialize() {
179
+ const t = {};
180
+ return this.clipped !== void 0 && (t.clipped = this.clipped), this.continuous !== void 0 && (t.continuous = this.continuous), this.fit !== void 0 && (t.fit = this.fit), this.orientation !== void 0 && (t.orientation = this.orientation), this.overflow !== void 0 && (t.overflow = this.overflow), this.spread !== void 0 && (t.spread = this.spread), this.layout !== void 0 && (t.layout = this.layout), t;
181
+ }
182
+ }
183
+ J.prototype.layoutOf = function(r) {
184
+ var t;
185
+ return ((t = r.properties) == null ? void 0 : t.getLayout()) || this.layout || ot.reflowable;
186
+ };
187
+ g.prototype.getContains = function() {
188
+ return new Set(this.otherProperties.contains || []);
189
+ };
190
+ g.prototype.getLayout = function() {
191
+ return this.otherProperties.layout;
192
+ };
193
+ class n {
194
+ /** Creates a MediaType object. */
195
+ constructor(t) {
196
+ let e, i, s = t.mediaType.replace(/\s/g, "").split(";");
197
+ const a = s[0].split("/");
198
+ if (a.length === 2) {
199
+ if (e = a[0].toLowerCase().trim(), i = a[1].toLowerCase().trim(), e.length === 0 || i.length === 0)
200
+ throw new Error("Invalid media type");
201
+ } else
202
+ throw new Error("Invalid media type");
203
+ const o = {};
204
+ for (let c = 1; c < s.length; c++) {
205
+ const d = s[c].split("=");
206
+ if (d.length === 2) {
207
+ const v = d[0].toLocaleLowerCase(), N = v === "charset" ? d[1].toUpperCase() : d[1];
208
+ o[v] = N;
209
+ }
210
+ }
211
+ const l = {}, h = Object.keys(o);
212
+ h.sort((c, d) => c.localeCompare(d)), h.forEach((c) => l[c] = o[c]);
213
+ let p = "";
214
+ for (const c in l) {
215
+ const d = l[c];
216
+ p += `;${c}=${d}`;
217
+ }
218
+ const f = `${e}/${i}${p}`, u = l.encoding;
219
+ this.string = f, this.type = e, this.subtype = i, this.parameters = l, this.encoding = u, this.name = t.name, this.fileExtension = t.fileExtension;
220
+ }
221
+ static parse(t) {
222
+ return new n(t);
223
+ }
224
+ /** Structured syntax suffix, e.g. `+zip` in `application/epub+zip`.
225
+ * Gives a hint on the underlying structure of this media type.
226
+ * See. https://tools.ietf.org/html/rfc6838#section-4.2.8
227
+ */
228
+ get structuredSyntaxSuffix() {
229
+ const t = this.subtype.split("+");
230
+ return t.length > 1 ? `+${t[t.length - 1]}` : void 0;
231
+ }
232
+ /** Parameter values might or might not be case-sensitive, depending on the semantics of
233
+ * the parameter name.
234
+ * https://tools.ietf.org/html/rfc2616#section-3.7
235
+ *
236
+ * The character set names may be up to 40 characters taken from the printable characters
237
+ * of US-ASCII. However, no distinction is made between use of upper and lower case
238
+ * letters.
239
+ * https://www.iana.org/assignments/character-sets/character-sets.xhtml
240
+ */
241
+ get charset() {
242
+ return this.parameters.charset;
243
+ }
244
+ /** Returns whether the given `other` media type is included in this media type.
245
+ * For example, `text/html` contains `text/html;charset=utf-8`.
246
+ * - `other` must match the parameters in the `parameters` property, but extra parameters
247
+ * are ignored.
248
+ * - Order of parameters is ignored.
249
+ * - Wildcards are supported, meaning that `image/*` contains `image/png`
250
+ */
251
+ contains(t) {
252
+ const e = typeof t == "string" ? n.parse({ mediaType: t }) : t;
253
+ if (!((this.type === "*" || this.type === e.type) && (this.subtype === "*" || this.subtype === e.subtype)))
254
+ return !1;
255
+ const i = new Set(
256
+ Object.entries(this.parameters).map(([a, o]) => `${a}=${o}`)
257
+ ), s = new Set(
258
+ Object.entries(e.parameters).map(([a, o]) => `${a}=${o}`)
259
+ );
260
+ for (const a of Array.from(i.values()))
261
+ if (!s.has(a))
262
+ return !1;
263
+ return !0;
264
+ }
265
+ /** Returns whether this media type and `other` are the same, ignoring parameters that
266
+ * are not in both media types.
267
+ * For example, `text/html` matches `text/html;charset=utf-8`, but `text/html;charset=ascii`
268
+ * doesn't. This is basically like `contains`, but working in both direction.
269
+ */
270
+ matches(t) {
271
+ const e = typeof t == "string" ? n.parse({ mediaType: t }) : t;
272
+ return this.contains(e) || e.contains(this);
273
+ }
274
+ /**
275
+ * Returns whether this media type matches any of the [others] media types.
276
+ */
277
+ matchesAny(...t) {
278
+ for (const e of t)
279
+ if (this.matches(e))
280
+ return !0;
281
+ return !1;
282
+ }
283
+ /** Checks the MediaType equals another one (comparing their string) */
284
+ equals(t) {
285
+ return this.string === t.string;
286
+ }
287
+ /** Returns whether this media type is structured as a ZIP archive. */
288
+ get isZIP() {
289
+ return this.matchesAny(
290
+ n.ZIP,
291
+ n.LCP_PROTECTED_AUDIOBOOK,
292
+ n.LCP_PROTECTED_PDF
293
+ ) || this.structuredSyntaxSuffix === "+zip";
294
+ }
295
+ /** Returns whether this media type is structured as a JSON file. */
296
+ get isJSON() {
297
+ return this.matchesAny(n.JSON) || this.structuredSyntaxSuffix === "+json";
298
+ }
299
+ /** Returns whether this media type is of an OPDS feed. */
300
+ get isOPDS() {
301
+ return this.matchesAny(
302
+ n.OPDS1,
303
+ n.OPDS1_ENTRY,
304
+ n.OPDS2,
305
+ n.OPDS2_PUBLICATION,
306
+ n.OPDS_AUTHENTICATION
307
+ ) || this.structuredSyntaxSuffix === "+json";
308
+ }
309
+ /** Returns whether this media type is of an HTML document. */
310
+ get isHTML() {
311
+ return this.matchesAny(n.HTML, n.XHTML);
312
+ }
313
+ /** Returns whether this media type is of a bitmap image, so excluding vectorial formats. */
314
+ get isBitmap() {
315
+ return this.matchesAny(
316
+ n.BMP,
317
+ n.GIF,
318
+ n.JPEG,
319
+ n.PNG,
320
+ n.TIFF,
321
+ n.WEBP
322
+ );
323
+ }
324
+ /** Returns whether this media type is of an audio clip. */
325
+ get isAudio() {
326
+ return this.type === "audio";
327
+ }
328
+ /** Returns whether this media type is of a video clip. */
329
+ get isVideo() {
330
+ return this.type === "video";
331
+ }
332
+ /** Returns whether this media type is of a Readium Web Publication Manifest. */
333
+ get isRWPM() {
334
+ return this.matchesAny(
335
+ n.READIUM_AUDIOBOOK_MANIFEST,
336
+ n.DIVINA_MANIFEST,
337
+ n.READIUM_WEBPUB_MANIFEST
338
+ );
339
+ }
340
+ /** Returns whether this media type is of a publication file. */
341
+ get isPublication() {
342
+ return this.matchesAny(
343
+ n.READIUM_AUDIOBOOK,
344
+ n.READIUM_AUDIOBOOK_MANIFEST,
345
+ n.CBZ,
346
+ n.DIVINA,
347
+ n.DIVINA_MANIFEST,
348
+ n.EPUB,
349
+ n.LCP_PROTECTED_AUDIOBOOK,
350
+ n.LCP_PROTECTED_PDF,
351
+ n.LPF,
352
+ n.PDF,
353
+ n.W3C_WPUB_MANIFEST,
354
+ n.READIUM_WEBPUB,
355
+ n.READIUM_WEBPUB_MANIFEST,
356
+ n.ZAB
357
+ );
358
+ }
359
+ // Known Media Types
360
+ static get AAC() {
361
+ return n.parse({ mediaType: "audio/aac", fileExtension: "aac" });
362
+ }
363
+ static get ACSM() {
364
+ return n.parse({
365
+ mediaType: "application/vnd.adobe.adept+xml",
366
+ name: "Adobe Content Server Message",
367
+ fileExtension: "acsm"
368
+ });
369
+ }
370
+ static get AIFF() {
371
+ return n.parse({ mediaType: "audio/aiff", fileExtension: "aiff" });
372
+ }
373
+ static get AVI() {
374
+ return n.parse({
375
+ mediaType: "video/x-msvideo",
376
+ fileExtension: "avi"
377
+ });
378
+ }
379
+ static get BINARY() {
380
+ return n.parse({ mediaType: "application/octet-stream" });
381
+ }
382
+ static get BMP() {
383
+ return n.parse({ mediaType: "image/bmp", fileExtension: "bmp" });
384
+ }
385
+ static get CBZ() {
386
+ return n.parse({
387
+ mediaType: "application/vnd.comicbook+zip",
388
+ name: "Comic Book Archive",
389
+ fileExtension: "cbz"
390
+ });
391
+ }
392
+ static get CSS() {
393
+ return n.parse({ mediaType: "text/css", fileExtension: "css" });
394
+ }
395
+ static get DIVINA() {
396
+ return n.parse({
397
+ mediaType: "application/divina+zip",
398
+ name: "Digital Visual Narratives",
399
+ fileExtension: "divina"
400
+ });
401
+ }
402
+ static get DIVINA_MANIFEST() {
403
+ return n.parse({
404
+ mediaType: "application/divina+json",
405
+ name: "Digital Visual Narratives",
406
+ fileExtension: "json"
407
+ });
408
+ }
409
+ static get EPUB() {
410
+ return n.parse({
411
+ mediaType: "application/epub+zip",
412
+ name: "EPUB",
413
+ fileExtension: "epub"
414
+ });
415
+ }
416
+ static get GIF() {
417
+ return n.parse({ mediaType: "image/gif", fileExtension: "gif" });
418
+ }
419
+ static get GZ() {
420
+ return n.parse({
421
+ mediaType: "application/gzip",
422
+ fileExtension: "gz"
423
+ });
424
+ }
425
+ static get HTML() {
426
+ return n.parse({ mediaType: "text/html", fileExtension: "html" });
427
+ }
428
+ static get JAVASCRIPT() {
429
+ return n.parse({
430
+ mediaType: "text/javascript",
431
+ fileExtension: "js"
432
+ });
433
+ }
434
+ static get JPEG() {
435
+ return n.parse({ mediaType: "image/jpeg", fileExtension: "jpeg" });
436
+ }
437
+ static get JSON() {
438
+ return n.parse({ mediaType: "application/json" });
439
+ }
440
+ static get LCP_LICENSE_DOCUMENT() {
441
+ return n.parse({
442
+ mediaType: "application/vnd.readium.lcp.license.v1.0+json",
443
+ name: "LCP License",
444
+ fileExtension: "lcpl"
445
+ });
446
+ }
447
+ static get LCP_PROTECTED_AUDIOBOOK() {
448
+ return n.parse({
449
+ mediaType: "application/audiobook+lcp",
450
+ name: "LCP Protected Audiobook",
451
+ fileExtension: "lcpa"
452
+ });
453
+ }
454
+ static get LCP_PROTECTED_PDF() {
455
+ return n.parse({
456
+ mediaType: "application/pdf+lcp",
457
+ name: "LCP Protected PDF",
458
+ fileExtension: "lcpdf"
459
+ });
460
+ }
461
+ static get LCP_STATUS_DOCUMENT() {
462
+ return n.parse({
463
+ mediaType: "application/vnd.readium.license.status.v1.0+json"
464
+ });
465
+ }
466
+ static get LPF() {
467
+ return n.parse({
468
+ mediaType: "application/lpf+zip",
469
+ fileExtension: "lpf"
470
+ });
471
+ }
472
+ static get MP3() {
473
+ return n.parse({ mediaType: "audio/mpeg", fileExtension: "mp3" });
474
+ }
475
+ static get MPEG() {
476
+ return n.parse({ mediaType: "video/mpeg", fileExtension: "mpeg" });
477
+ }
478
+ static get NCX() {
479
+ return n.parse({
480
+ mediaType: "application/x-dtbncx+xml",
481
+ fileExtension: "ncx"
482
+ });
483
+ }
484
+ static get OGG() {
485
+ return n.parse({ mediaType: "audio/ogg", fileExtension: "oga" });
486
+ }
487
+ static get OGV() {
488
+ return n.parse({ mediaType: "video/ogg", fileExtension: "ogv" });
489
+ }
490
+ static get OPDS1() {
491
+ return n.parse({
492
+ mediaType: "application/atom+xml;profile=opds-catalog"
493
+ });
494
+ }
495
+ static get OPDS1_ENTRY() {
496
+ return n.parse({
497
+ mediaType: "application/atom+xml;type=entry;profile=opds-catalog"
498
+ });
499
+ }
500
+ static get OPDS2() {
501
+ return n.parse({ mediaType: "application/opds+json" });
502
+ }
503
+ static get OPDS2_PUBLICATION() {
504
+ return n.parse({ mediaType: "application/opds-publication+json" });
505
+ }
506
+ static get OPDS_AUTHENTICATION() {
507
+ return n.parse({
508
+ mediaType: "application/opds-authentication+json"
509
+ });
510
+ }
511
+ static get OPUS() {
512
+ return n.parse({ mediaType: "audio/opus", fileExtension: "opus" });
513
+ }
514
+ static get OTF() {
515
+ return n.parse({ mediaType: "font/otf", fileExtension: "otf" });
516
+ }
517
+ static get PDF() {
518
+ return n.parse({
519
+ mediaType: "application/pdf",
520
+ name: "PDF",
521
+ fileExtension: "pdf"
522
+ });
523
+ }
524
+ static get PNG() {
525
+ return n.parse({ mediaType: "image/png", fileExtension: "png" });
526
+ }
527
+ static get READIUM_AUDIOBOOK() {
528
+ return n.parse({
529
+ mediaType: "application/audiobook+zip",
530
+ name: "Readium Audiobook",
531
+ fileExtension: "audiobook"
532
+ });
533
+ }
534
+ static get READIUM_AUDIOBOOK_MANIFEST() {
535
+ return n.parse({
536
+ mediaType: "application/audiobook+json",
537
+ name: "Readium Audiobook",
538
+ fileExtension: "json"
539
+ });
540
+ }
541
+ static get READIUM_CONTENT_DOCUMENT() {
542
+ return n.parse({
543
+ mediaType: "application/vnd.readium.content+json",
544
+ name: "Readium Content Document",
545
+ fileExtension: "json"
546
+ });
547
+ }
548
+ static get READIUM_GUIDED_NAVIGATION_DOCUMENT() {
549
+ return n.parse({
550
+ mediaType: "application/guided-navigation+json",
551
+ name: "Readium Guided Navigation Document",
552
+ fileExtension: "json"
553
+ });
554
+ }
555
+ static get READIUM_POSITION_LIST() {
556
+ return n.parse({
557
+ mediaType: "application/vnd.readium.position-list+json",
558
+ name: "Readium Position List",
559
+ fileExtension: "json"
560
+ });
561
+ }
562
+ static get READIUM_WEBPUB() {
563
+ return n.parse({
564
+ mediaType: "application/webpub+zip",
565
+ name: "Readium Web Publication",
566
+ fileExtension: "webpub"
567
+ });
568
+ }
569
+ static get READIUM_WEBPUB_MANIFEST() {
570
+ return n.parse({
571
+ mediaType: "application/webpub+json",
572
+ name: "Readium Web Publication",
573
+ fileExtension: "json"
574
+ });
575
+ }
576
+ static get SMIL() {
577
+ return n.parse({
578
+ mediaType: "application/smil+xml",
579
+ fileExtension: "smil"
580
+ });
581
+ }
582
+ static get SVG() {
583
+ return n.parse({
584
+ mediaType: "image/svg+xml",
585
+ fileExtension: "svg"
586
+ });
587
+ }
588
+ static get TEXT() {
589
+ return n.parse({ mediaType: "text/plain", fileExtension: "txt" });
590
+ }
591
+ static get TIFF() {
592
+ return n.parse({ mediaType: "image/tiff", fileExtension: "tiff" });
593
+ }
594
+ static get TTF() {
595
+ return n.parse({ mediaType: "font/ttf", fileExtension: "ttf" });
596
+ }
597
+ static get W3C_WPUB_MANIFEST() {
598
+ return n.parse({
599
+ mediaType: "application/x.readium.w3c.wpub+json",
600
+ name: "Web Publication",
601
+ fileExtension: "json"
602
+ });
603
+ }
604
+ static get WAV() {
605
+ return n.parse({ mediaType: "audio/wav", fileExtension: "wav" });
606
+ }
607
+ static get WEBM_AUDIO() {
608
+ return n.parse({ mediaType: "audio/webm", fileExtension: "webm" });
609
+ }
610
+ static get WEBM_VIDEO() {
611
+ return n.parse({ mediaType: "video/webm", fileExtension: "webm" });
612
+ }
613
+ static get WEBP() {
614
+ return n.parse({ mediaType: "image/webp", fileExtension: "webp" });
615
+ }
616
+ static get WOFF() {
617
+ return n.parse({ mediaType: "font/woff", fileExtension: "woff" });
618
+ }
619
+ static get WOFF2() {
620
+ return n.parse({ mediaType: "font/woff2", fileExtension: "woff2" });
621
+ }
622
+ static get XHTML() {
623
+ return n.parse({
624
+ mediaType: "application/xhtml+xml",
625
+ fileExtension: "xhtml"
626
+ });
627
+ }
628
+ static get XML() {
629
+ return n.parse({
630
+ mediaType: "application/xml",
631
+ fileExtension: "xml"
632
+ });
633
+ }
634
+ static get ZAB() {
635
+ return n.parse({
636
+ mediaType: "application/x.readium.zab+zip",
637
+ name: "Zipped Audio Book",
638
+ fileExtension: "zab"
639
+ });
640
+ }
641
+ static get ZIP() {
642
+ return n.parse({
643
+ mediaType: "application/zip",
644
+ fileExtension: "zip"
645
+ });
646
+ }
647
+ }
648
+ class B {
649
+ constructor(t) {
650
+ this.uri = t, this.parameters = this.getParameters(t);
651
+ }
652
+ /**
653
+ * List of URI template parameter keys, if the [Link] is templated.
654
+ */
655
+ getParameters(t) {
656
+ const e = /\{\??([^}]+)\}/g, i = t.match(e);
657
+ return i ? new Set(
658
+ i.join(",").replace(e, "$1").split(",").map((s) => s.trim())
659
+ ) : /* @__PURE__ */ new Set();
660
+ }
661
+ /** Expands the URI by replacing the template variables by the given parameters.
662
+ * Any extra parameter is appended as query parameters.
663
+ * See RFC 6570 on URI template: https://tools.ietf.org/html/rfc6570
664
+ */
665
+ expand(t) {
666
+ const e = (s) => s.split(",").map((a) => {
667
+ const o = t[a];
668
+ return o ? encodeURIComponent(o) : "";
669
+ }).join(","), i = (s) => "?" + s.split(",").map((a) => {
670
+ const o = a.split("=")[0], l = t[o];
671
+ return l ? `${o}=${encodeURIComponent(l)}` : "";
672
+ }).join("&");
673
+ return this.uri.replace(/\{(\??)([^}]+)\}/g, (...s) => s[1] ? i(s[2]) : e(s[2]));
674
+ }
675
+ }
676
+ function Dt(r) {
677
+ return r && r instanceof Array ? r : void 0;
678
+ }
679
+ function T(r) {
680
+ return r && typeof r == "string" ? [r] : Dt(r);
681
+ }
682
+ function F(r) {
683
+ return typeof r == "string" ? new Date(r) : void 0;
684
+ }
685
+ function S(r) {
686
+ return isNaN(r) ? void 0 : r;
687
+ }
688
+ function y(r) {
689
+ return S(r) !== void 0 && Math.sign(r) >= 0 ? r : void 0;
690
+ }
691
+ function X(r) {
692
+ const t = new Array();
693
+ return r.forEach((e) => t.push(e)), t;
694
+ }
695
+ class E {
696
+ /**
697
+ * Creates a [Locations].
698
+ */
699
+ constructor(t) {
700
+ this.fragments = t.fragments ? t.fragments : new Array(), this.progression = t.progression, this.totalProgression = t.totalProgression, this.position = t.position, this.otherLocations = t.otherLocations;
701
+ }
702
+ /**
703
+ * Parses a [Locations] from its RWPM JSON representation.
704
+ */
705
+ static deserialize(t) {
706
+ if (!t)
707
+ return;
708
+ const e = S(t.progression), i = S(t.totalProgression), s = S(t.position), a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set([
709
+ "fragment",
710
+ "fragments",
711
+ "progression",
712
+ "totalProgression",
713
+ "position"
714
+ ]);
715
+ return Object.entries(t).forEach(([l, h]) => {
716
+ o.has(l) || a.set(l, h);
717
+ }), new E({
718
+ fragments: T(t.fragments || t.fragment),
719
+ progression: e !== void 0 && e >= 0 && e <= 1 ? e : void 0,
720
+ totalProgression: i !== void 0 && i >= 0 && i <= 1 ? i : void 0,
721
+ position: s !== void 0 && s > 0 ? s : void 0,
722
+ otherLocations: a.size === 0 ? void 0 : a
723
+ });
724
+ }
725
+ /**
726
+ * Serializes a [Locations] to its RWPM JSON representation.
727
+ */
728
+ serialize() {
729
+ const t = {};
730
+ 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;
731
+ }
732
+ }
733
+ class Y {
734
+ /**
735
+ * Creates a [Text].
736
+ */
737
+ constructor(t) {
738
+ this.after = t.after, this.before = t.before, this.highlight = t.highlight;
739
+ }
740
+ /**
741
+ * Parses a [Locations] from its RWPM JSON representation.
742
+ */
743
+ static deserialize(t) {
744
+ if (t)
745
+ return new Y({
746
+ after: t.after,
747
+ before: t.before,
748
+ highlight: t.highlight
749
+ });
750
+ }
751
+ /**
752
+ * Serializes a [Locations] to its RWPM JSON representation.
753
+ */
754
+ serialize() {
755
+ const t = {};
756
+ 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;
757
+ }
758
+ }
759
+ class P {
760
+ /**
761
+ * Creates a [Locator].
762
+ */
763
+ constructor(t) {
764
+ this.href = t.href, this.type = t.type, this.title = t.title, this.locations = t.locations ? t.locations : new E({}), this.text = t.text;
765
+ }
766
+ /**
767
+ * Parses a [Link] from its RWPM JSON representation.
768
+ */
769
+ static deserialize(t) {
770
+ if (t && t.href && t.type)
771
+ return new P({
772
+ href: t.href,
773
+ type: t.type,
774
+ title: t.title,
775
+ locations: E.deserialize(t.locations),
776
+ text: Y.deserialize(t.text)
777
+ });
778
+ }
779
+ /**
780
+ * Serializes a [Link] to its RWPM JSON representation.
781
+ */
782
+ serialize() {
783
+ const t = { href: this.href, type: this.type };
784
+ return this.title !== void 0 && (t.title = this.title), this.locations && (t.locations = this.locations.serialize()), this.text && (t.text = this.text.serialize()), t;
785
+ }
786
+ /**
787
+ * Shortcut to get a copy of the [Locator] with different [Locations] sub-properties.
788
+ */
789
+ copyWithLocations(t) {
790
+ return new P({
791
+ href: this.href,
792
+ type: this.type,
793
+ title: this.title,
794
+ text: this.text,
795
+ locations: new E({ ...this.locations, ...t })
796
+ });
797
+ }
798
+ }
799
+ class w {
800
+ /**
801
+ * Creates a [Link].
802
+ */
803
+ constructor(t) {
804
+ 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.duration = t.duration, this.bitrate = t.bitrate, this.languages = t.languages, this.alternates = t.alternates, this.children = t.children;
805
+ }
806
+ /**
807
+ * Parses a [Link] from its RWPM JSON representation.
808
+ */
809
+ static deserialize(t) {
810
+ if (t && t.href && typeof t.href == "string")
811
+ return new w({
812
+ href: t.href,
813
+ templated: t.templated,
814
+ type: t.type,
815
+ title: t.title,
816
+ rels: t.rel ? t.rel instanceof Array ? new Set(t.rel) : /* @__PURE__ */ new Set([t.rel]) : void 0,
817
+ properties: g.deserialize(t.properties),
818
+ height: y(t.height),
819
+ width: y(t.width),
820
+ duration: y(t.duration),
821
+ bitrate: y(t.bitrate),
822
+ languages: T(t.language),
823
+ alternates: b.deserialize(t.alternate),
824
+ children: b.deserialize(t.children)
825
+ });
826
+ }
827
+ /**
828
+ * Serializes a [Link] to its RWPM JSON representation.
829
+ */
830
+ serialize() {
831
+ const t = { href: this.href };
832
+ 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 = X(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.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;
833
+ }
834
+ /** MediaType of the linked resource. */
835
+ get mediaType() {
836
+ return this.type !== void 0 ? n.parse({ mediaType: this.type }) : n.BINARY;
837
+ }
838
+ /** Computes an absolute URL to the link, relative to the given `baseURL`.
839
+ * If the link's `href` is already absolute, the `baseURL` is ignored.
840
+ */
841
+ toURL(t) {
842
+ const e = this.href.replace(/^(\/)/, "");
843
+ if (e.length === 0)
844
+ return;
845
+ let i = t || "/";
846
+ return i.startsWith("/") && (i = "file://" + i), new URL(e, i).href.replace(/^(file:\/\/)/, "");
847
+ }
848
+ /** List of URI template parameter keys, if the `Link` is templated. */
849
+ get templateParameters() {
850
+ return this.templated ? new B(this.href).parameters : /* @__PURE__ */ new Set();
851
+ }
852
+ /** Expands the `Link`'s HREF by replacing URI template variables by the given parameters.
853
+ * See RFC 6570 on URI template: https://tools.ietf.org/html/rfc6570
854
+ */
855
+ expandTemplate(t) {
856
+ return new w({
857
+ href: new B(this.href).expand(t),
858
+ templated: !1
859
+ });
860
+ }
861
+ /**
862
+ * Makes a copy of this [Link] after merging in the given additional other [properties].
863
+ */
864
+ addProperties(t) {
865
+ var i;
866
+ const e = w.deserialize(this.serialize());
867
+ return e.properties = e.properties ? (i = e.properties) == null ? void 0 : i.add(t) : new g(t), e;
868
+ }
869
+ /**
870
+ * Creates a [Locator] from a reading order [Link].
871
+ */
872
+ get locator() {
873
+ let t = this.href.split("#");
874
+ return new P({
875
+ href: t.length > 0 && t[0] !== void 0 ? t[0] : this.href,
876
+ type: this.type ?? "",
877
+ title: this.title,
878
+ locations: new E({
879
+ fragments: t.length > 1 && t[1] !== void 0 ? [t[1]] : []
880
+ })
881
+ });
882
+ }
883
+ }
884
+ class b {
885
+ /**
886
+ * Creates a [Links].
887
+ */
888
+ constructor(t) {
889
+ this.items = t;
890
+ }
891
+ /**
892
+ * Creates a list of [Link] from its RWPM JSON representation.
893
+ */
894
+ static deserialize(t) {
895
+ if (t && t instanceof Array)
896
+ return new b(
897
+ t.map((e) => w.deserialize(e)).filter((e) => e !== void 0)
898
+ );
899
+ }
900
+ /**
901
+ * Serializes an array of [Link] to its RWPM JSON representation.
902
+ */
903
+ serialize() {
904
+ return this.items.map((t) => t.serialize());
905
+ }
906
+ /** Finds the first link with the given relation. */
907
+ findWithRel(t) {
908
+ const e = (i) => i.rels && i.rels.has(t);
909
+ return this.items.find(e);
910
+ }
911
+ /** Finds all the links with the given relation. */
912
+ filterByRel(t) {
913
+ const e = (i) => i.rels && i.rels.has(t);
914
+ return this.items.filter(e);
915
+ }
916
+ /** Finds the first link matching the given HREF. */
917
+ findWithHref(t) {
918
+ const e = (i) => i.href === t;
919
+ return this.items.find(e);
920
+ }
921
+ /** Finds the index of the first link matching the given HREF. */
922
+ findIndexWithHref(t) {
923
+ const e = (i) => i.href === t;
924
+ return this.items.findIndex(e);
925
+ }
926
+ /** Finds the first link matching the given media type. */
927
+ findWithMediaType(t) {
928
+ const e = (i) => i.mediaType.matches(t);
929
+ return this.items.find(e);
930
+ }
931
+ /** Finds all the links matching the given media type. */
932
+ filterByMediaType(t) {
933
+ const e = (i) => i.mediaType.matches(t);
934
+ return this.items.filter(e);
935
+ }
936
+ /** Finds all the links matching any of the given media types. */
937
+ filterByMediaTypes(t) {
938
+ const e = (i) => {
939
+ for (const s of t)
940
+ if (i.mediaType.matches(s))
941
+ return !0;
942
+ return !1;
943
+ };
944
+ return this.items.filter(e);
945
+ }
946
+ /** Returns whether all the resources in the collection are audio clips. */
947
+ everyIsAudio() {
948
+ const t = (e) => e.mediaType.isAudio;
949
+ return this.items.length > 0 && this.items.every(t);
950
+ }
951
+ /** Returns whether all the resources in the collection are bitmaps. */
952
+ everyIsBitmap() {
953
+ const t = (e) => e.mediaType.isBitmap;
954
+ return this.items.length > 0 && this.items.every(t);
955
+ }
956
+ /** Returns whether all the resources in the collection are HTML documents. */
957
+ everyIsHTML() {
958
+ const t = (e) => e.mediaType.isHTML;
959
+ return this.items.length > 0 && this.items.every(t);
960
+ }
961
+ /** Returns whether all the resources in the collection are video clips. */
962
+ everyIsVideo() {
963
+ const t = (e) => e.mediaType.isVideo;
964
+ return this.items.length > 0 && this.items.every(t);
965
+ }
966
+ /** Returns whether all the resources in the collection are matching any of the given media types. */
967
+ everyMatchesMediaType(t) {
968
+ return Array.isArray(t) ? this.items.length > 0 && this.items.every((e) => {
969
+ for (const i of t)
970
+ return e.mediaType.matches(i);
971
+ return !1;
972
+ }) : this.items.length > 0 && this.items.every((e) => e.mediaType.matches(t));
973
+ }
974
+ filterLinksHasType() {
975
+ return this.items.filter((t) => t.type);
976
+ }
977
+ }
978
+ class Q {
979
+ constructor(t) {
980
+ this.links = t.links, this.guided = t.guided;
981
+ }
982
+ static deserialize(t) {
983
+ if (t)
984
+ return new Q({
985
+ links: b.deserialize(t.links),
986
+ guided: L.deserializeArray(t.guided)
987
+ });
988
+ }
989
+ serialize() {
990
+ const t = {};
991
+ return this.links !== void 0 && (t.links = this.links.serialize()), this.guided !== void 0 && (t.guided = this.guided.map((e) => e.serialize())), t;
992
+ }
993
+ }
994
+ class L {
995
+ /**
996
+ * Creates a [GuidedNavigation] object.
997
+ */
998
+ constructor(t) {
999
+ this.audioref = t.audioref, this.children = t.children, this.imgref = t.imgref, this.role = t.role, this.text = t.text, this.textref = t.textref;
1000
+ }
1001
+ /**
1002
+ * Parses a [GuidedNavigationObject] from its RWPM JSON representation.
1003
+ *
1004
+ * A GuidedNavigationObject can be parsed from a single string, or a full-fledged object.
1005
+ */
1006
+ static deserialize(t) {
1007
+ if (t)
1008
+ return new L({
1009
+ audioref: t.audioref,
1010
+ children: L.deserializeArray(t.children),
1011
+ imgref: t.imgref,
1012
+ role: t.role ? new Set(T(t.role)) : void 0,
1013
+ text: t.text,
1014
+ textref: t.textref
1015
+ });
1016
+ }
1017
+ /**
1018
+ * Parses a [GuidedNavigationObject] array from its RWPM JSON representation.
1019
+ */
1020
+ static deserializeArray(t) {
1021
+ if (t instanceof Array)
1022
+ return t.map((e) => L.deserialize(e)).filter((e) => e !== void 0);
1023
+ }
1024
+ /**
1025
+ * Serializes a [GuidedNavigationObject] to its RWPM JSON representation.
1026
+ */
1027
+ serialize() {
1028
+ const t = {};
1029
+ return this.audioref !== void 0 && (t.audioref = this.audioref), this.children !== void 0 && (t.children = this.children.map((e) => e.serialize())), this.imgref !== void 0 && (t.imgref = this.imgref), this.role !== void 0 && (t.role = X(this.role)), this.text !== void 0 && (t.text = this.text), this.textref !== void 0 && (t.textref = this.textref), t;
1030
+ }
1031
+ get audioFile() {
1032
+ var t;
1033
+ return (t = this.audioref) == null ? void 0 : t.split("#")[0];
1034
+ }
1035
+ get audioTime() {
1036
+ var t;
1037
+ if ((t = this.audioref) != null && t.includes("#"))
1038
+ return this.audioref.split("#", 2)[1];
1039
+ }
1040
+ get textFile() {
1041
+ var t;
1042
+ return (t = this.textref) == null ? void 0 : t.split("#")[0];
1043
+ }
1044
+ get fragmentId() {
1045
+ var t;
1046
+ if ((t = this.textref) != null && t.includes("#"))
1047
+ return this.textref.split("#", 2)[1];
1048
+ }
1049
+ get clip() {
1050
+ const t = this.audioFile;
1051
+ if (!t)
1052
+ return;
1053
+ const e = this.audioTime, i = {
1054
+ audioResource: t,
1055
+ fragmentId: this.fragmentId
1056
+ };
1057
+ if (!e)
1058
+ return i;
1059
+ const s = this.parseTimer(e);
1060
+ return i.start = s[0], i.end = s[1], i;
1061
+ }
1062
+ parseTimer(t) {
1063
+ if (!t || !t.startsWith("t="))
1064
+ return [void 0, void 0];
1065
+ const e = t.substring(2).split(",").map((i) => parseFloat(i));
1066
+ return e.length === 1 ? [isNaN(e[0]) ? void 0 : e[0], void 0] : e.length > 2 ? [void 0, void 0] : [isNaN(e[0]) ? void 0 : e[0], isNaN(e[1]) ? void 0 : e[1]];
1067
+ }
1068
+ }
1069
+ function Rt(r, t) {
1070
+ return t.length > 1 ? t.indexOf(r.slice(-1)) > -1 : r.slice(-1) === t;
1071
+ }
1072
+ function Ut(r, t) {
1073
+ return r.slice(r.length - t.length) === t;
1074
+ }
1075
+ const Z = {
1076
+ endsWith: Ut,
1077
+ endsWithChar: Rt
1078
+ }, Wt = [
1079
+ "ie",
1080
+ "eg",
1081
+ "ext",
1082
+ // + number?
1083
+ "Fig",
1084
+ "fig",
1085
+ "Figs",
1086
+ "figs",
1087
+ "et al",
1088
+ "Co",
1089
+ "Corp",
1090
+ "Ave",
1091
+ "Inc",
1092
+ "Ex",
1093
+ "Viz",
1094
+ "vs",
1095
+ "Vs",
1096
+ "repr",
1097
+ "Rep",
1098
+ "Dem",
1099
+ "trans",
1100
+ "Vol",
1101
+ "pp",
1102
+ "rev",
1103
+ "est",
1104
+ "Ref",
1105
+ "Refs",
1106
+ "Eq",
1107
+ "Eqs",
1108
+ "Ch",
1109
+ "Sec",
1110
+ "Secs",
1111
+ "mi",
1112
+ "Dept",
1113
+ "Univ",
1114
+ "Nos",
1115
+ "No",
1116
+ "Mol",
1117
+ "Cell",
1118
+ "Miss",
1119
+ "Mrs",
1120
+ "Mr",
1121
+ "Ms",
1122
+ "Prof",
1123
+ "Dr",
1124
+ "Sgt",
1125
+ "Col",
1126
+ "Gen",
1127
+ "Rep",
1128
+ "Sen",
1129
+ "Gov",
1130
+ "Lt",
1131
+ "Maj",
1132
+ "Capt",
1133
+ "St",
1134
+ "Sr",
1135
+ "Jr",
1136
+ "jr",
1137
+ "Rev",
1138
+ "PhD",
1139
+ "MD",
1140
+ "BA",
1141
+ "MA",
1142
+ "MM",
1143
+ "BSc",
1144
+ "MSc",
1145
+ "Jan",
1146
+ "Feb",
1147
+ "Mar",
1148
+ "Apr",
1149
+ "Jun",
1150
+ "Jul",
1151
+ "Aug",
1152
+ "Sep",
1153
+ "Sept",
1154
+ "Oct",
1155
+ "Nov",
1156
+ "Dec",
1157
+ "Sun",
1158
+ "Mon",
1159
+ "Tu",
1160
+ "Tue",
1161
+ "Tues",
1162
+ "Wed",
1163
+ "Th",
1164
+ "Thu",
1165
+ "Thur",
1166
+ "Thurs",
1167
+ "Fri",
1168
+ "Sat"
1169
+ ];
1170
+ function lt(r) {
1171
+ return /^[A-Z][a-z].*/.test(r) || K(r);
1172
+ }
1173
+ function Bt(r) {
1174
+ return lt(r) || /``|"|'/.test(r.substring(0, 2));
1175
+ }
1176
+ function Ft(r) {
1177
+ return ~Wt.indexOf(r.replace(/\W+/g, ""));
1178
+ }
1179
+ function Gt(r, t) {
1180
+ if (r === "a.m." || r === "p.m.") {
1181
+ var e = t.replace(/\W+/g, "").slice(-3).toLowerCase();
1182
+ if (e === "day")
1183
+ return !0;
1184
+ }
1185
+ return !1;
1186
+ }
1187
+ function nt(r) {
1188
+ var t = r.replace(/[\(\)\[\]\{\}]/g, "").match(/(.\.)*/);
1189
+ return t && t[0].length > 0;
1190
+ }
1191
+ function at(r) {
1192
+ return r.length <= 3 ? !0 : lt(r);
1193
+ }
1194
+ function K(r, t) {
1195
+ return t && (r = r.slice(t - 1, t + 2)), !isNaN(Number(r));
1196
+ }
1197
+ function Ht(r) {
1198
+ return r.match(/^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$/);
1199
+ }
1200
+ function $t(r) {
1201
+ return r.match(/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/);
1202
+ }
1203
+ function Vt(r) {
1204
+ var t = 0;
1205
+ if ((t = r.indexOf(".")) > -1 || (t = r.indexOf("!")) > -1 || (t = r.indexOf("?")) > -1) {
1206
+ var e = r.charAt(t + 1);
1207
+ if (e.match(/[a-zA-Z].*/))
1208
+ return [r.slice(0, t), r.charAt(t), r.slice(t + 1)];
1209
+ }
1210
+ return !1;
1211
+ }
1212
+ function Jt(r) {
1213
+ return r === "." || r === "!" || r === "?";
1214
+ }
1215
+ function Zt(r, t) {
1216
+ t = Object.assign(t || {}, {
1217
+ newlineBoundary: t && t.newlineBoundary || !0
1218
+ });
1219
+ var e = /\s/;
1220
+ return r.serie(
1221
+ // Split into words
1222
+ r.re(e, { split: !0 }),
1223
+ // Merge words as sentences
1224
+ r.splitAndMerge(function(i, s, a, o, l, h) {
1225
+ var p, f = [i, null], u = i, c = h.slice(l + 1).find(function(v) {
1226
+ return !e.test(v.value);
1227
+ });
1228
+ if (i === `
1229
+ ` && t.newlineBoundary || Jt(i) || Z.endsWithChar(i, "?!"))
1230
+ return f;
1231
+ if (Z.endsWithChar(i, ".")) {
1232
+ if (c) {
1233
+ if (i.length === 2 && isNaN(i.charAt(0)) && i.match(/[a-zA-Z]/) || Ft(i))
1234
+ return u;
1235
+ if (Bt(c.value)) {
1236
+ if (Gt(i, c.value) || K(c.value) && at(i))
1237
+ return u;
1238
+ } else if (Z.endsWith(i, "..") || nt(i) || at(i))
1239
+ return u;
1240
+ }
1241
+ return f;
1242
+ }
1243
+ let d;
1244
+ return (d = i.indexOf(".")) > -1 && (K(i, d) || nt(i) || $t(i) || Ht(i)) ? u : (p = Vt(i)) ? [
1245
+ p[0] + p[1],
1246
+ null,
1247
+ p[2]
1248
+ ] : u;
1249
+ }),
1250
+ // Filter empty sentences
1251
+ r.filter(function(i) {
1252
+ return i.trim() != "";
1253
+ })
1254
+ );
1255
+ }
1256
+ const Kt = (r, ...t) => (...e) => r(...t, ...e);
1257
+ function qt(r) {
1258
+ return {
1259
+ sentences: Kt(Zt, r)
1260
+ };
1261
+ }
1262
+ function Mt(r, t) {
1263
+ return t ? r.reduce(function(e, i) {
1264
+ var s = [
1265
+ i.index,
1266
+ i.offset,
1267
+ i.value
1268
+ ].join("-");
1269
+ return [e, s].join(":");
1270
+ }, t) : null;
1271
+ }
1272
+ function Xt(r) {
1273
+ const { index: t, offset: e, value: i, ...s } = r;
1274
+ return s;
1275
+ }
1276
+ function Yt(r, t) {
1277
+ var e = 0;
1278
+ return Array.isArray(t) || (t = [t]), t.map(function(i) {
1279
+ return i === null ? null : (typeof i == "string" && (i = {
1280
+ value: i,
1281
+ index: e,
1282
+ offset: i.length
1283
+ }), typeof i == "object" && (i.index = i.index || 0, e = e + i.index + i.offset, i.index = r.index + i.index, i.offset = i.offset || i.value.length), i);
1284
+ });
1285
+ }
1286
+ function Qt(r, t) {
1287
+ var a;
1288
+ if (r.length == 0)
1289
+ return null;
1290
+ var e = "", i = 0, s = (a = r[0]) == null ? void 0 : a.index;
1291
+ return r.forEach(function(o, l) {
1292
+ var h = r[l - 1];
1293
+ r[l + 1];
1294
+ var p = h ? o.index + 1 - (h.index + h.offset) : 0;
1295
+ e = e + new Array(p).join(t) + o.value;
1296
+ var f = o.index - s + o.offset;
1297
+ f > i && (i = f);
1298
+ }), {
1299
+ // Index equal is the one from the first token
1300
+ index: s,
1301
+ value: e,
1302
+ offset: Math.max(i, e.length)
1303
+ };
1304
+ }
1305
+ const C = {
1306
+ tokensId: Mt,
1307
+ normalize: Yt,
1308
+ properties: Xt,
1309
+ merge: Qt
1310
+ };
1311
+ var _t = ' \r\n  !"#$%&()*+,-.\\/:;<=>?@[\\]^_`{|}~', jt = new RegExp(
1312
+ "([^" + _t + "]+)"
1313
+ );
1314
+ function z(r) {
1315
+ if (!(this instanceof z))
1316
+ return new z(r);
1317
+ this.opts = Object.assign({
1318
+ cacheGet: function(t) {
1319
+ return null;
1320
+ },
1321
+ cacheSet: function(t, e) {
1322
+ }
1323
+ }, r);
1324
+ }
1325
+ z.prototype.split = function(t, e = {}) {
1326
+ var i = this;
1327
+ return e = Object.assign({ preserveProperties: !0, cache: () => null }, e), function(s, a) {
1328
+ if (arguments.length === 6)
1329
+ return t.apply(null, arguments);
1330
+ var o, l, h;
1331
+ if (s === void 0)
1332
+ return [];
1333
+ if (typeof s == "string" ? s = [{
1334
+ value: s,
1335
+ index: 0,
1336
+ offset: s.length
1337
+ }] : Array.isArray(s) || (s = [s]), l = C.tokensId(s, e.cache()), l && (h = i.opts.cacheGet(l), h))
1338
+ return h;
1339
+ var p = s.map(function(f, u) {
1340
+ var c = s[u + 1], d = t(
1341
+ f.value,
1342
+ Object.assign({}, f),
1343
+ o ? Object.assign({}, o) : null,
1344
+ c ? Object.assign({}, c) : null,
1345
+ u,
1346
+ s
1347
+ ) || [];
1348
+ if (d = C.normalize(f, d), e.preserveProperties) {
1349
+ var v = C.properties(f);
1350
+ d = d.map(function(N) {
1351
+ return Object.assign({}, N, v);
1352
+ });
1353
+ }
1354
+ return o = f, d;
1355
+ }).filter(Boolean).flat();
1356
+ return l && i.opts.cacheSet(l, p), p;
1357
+ };
1358
+ };
1359
+ z.prototype.re = function(t, e = {}) {
1360
+ return e = Object.assign({ split: !1 }, e), this.split(function(i, s) {
1361
+ for (var a = i, o = [], l, h = 0; l = t.exec(i); ) {
1362
+ var p = l.index, f = h + p, u = l[0] || "", c = u.length;
1363
+ if (e.split && h < f) {
1364
+ var d = a.slice(h, f);
1365
+ o.push({
1366
+ value: d,
1367
+ index: h,
1368
+ offset: d.length
1369
+ });
1370
+ }
1371
+ o.push({
1372
+ value: u,
1373
+ index: f,
1374
+ offset: c,
1375
+ match: l
1376
+ }), i = i.slice(p + c), h = f + c;
1377
+ }
1378
+ return e.split && i && o.push({
1379
+ value: i,
1380
+ index: h,
1381
+ offset: i.length
1382
+ }), o;
1383
+ }, {
1384
+ cache: function() {
1385
+ return t.toString();
1386
+ }
1387
+ });
1388
+ };
1389
+ z.prototype.splitAndMerge = function(t, e = {}) {
1390
+ var i = this;
1391
+ return e = Object.assign({ mergeWith: "" }, e), function(s) {
1392
+ var a = [], o = [];
1393
+ function l() {
1394
+ if (o.length != 0) {
1395
+ var h = C.merge(o, e.mergeWith);
1396
+ a.push(h), o = [];
1397
+ }
1398
+ }
1399
+ return i.split(function(h, p) {
1400
+ var f = t.apply(null, arguments);
1401
+ f = C.normalize(p, f), f.forEach(function(u) {
1402
+ u === null ? l() : o.push(u);
1403
+ });
1404
+ })(s), l(), a;
1405
+ };
1406
+ };
1407
+ z.prototype.filter = function(t) {
1408
+ return this.split(function(e, i) {
1409
+ if (t.apply(null, arguments))
1410
+ return {
1411
+ value: i.value,
1412
+ index: 0,
1413
+ offset: i.offset
1414
+ };
1415
+ });
1416
+ };
1417
+ z.prototype.extend = function(t) {
1418
+ return this.split(function(e, i) {
1419
+ var s = typeof t == "function" ? t.apply(null, arguments) : t;
1420
+ return Object.assign({
1421
+ value: i.value,
1422
+ index: 0,
1423
+ offset: i.offset
1424
+ }, s);
1425
+ });
1426
+ };
1427
+ z.prototype.ifthen = function(r, t) {
1428
+ return this.split(function(e, i) {
1429
+ if (r.apply(null, arguments))
1430
+ return t.apply(null, arguments);
1431
+ const { index: s, ...a } = i;
1432
+ return a;
1433
+ });
1434
+ };
1435
+ z.prototype.test = function(t) {
1436
+ return this.filter(function(e, i) {
1437
+ return t.test(e);
1438
+ }, {
1439
+ cache: t.toString()
1440
+ });
1441
+ };
1442
+ z.prototype.flow = function(...t) {
1443
+ const e = t.reduce((i, s) => (...a) => s(i(...a)));
1444
+ return this.split(e);
1445
+ };
1446
+ z.prototype.serie = function(...t) {
1447
+ return t.reduce((e, i) => (...s) => i(e(...s)));
1448
+ };
1449
+ z.prototype.merge = function() {
1450
+ return this.splitAndMerge((r) => [r]);
1451
+ };
1452
+ z.prototype.sections = function() {
1453
+ return this.re(/([^\n\.,;!?]+)/i, { split: !1 });
1454
+ };
1455
+ z.prototype.words = function() {
1456
+ return this.re(jt);
1457
+ };
1458
+ z.prototype.characters = function() {
1459
+ return this.re(/[^\s]/);
1460
+ };
1461
+ var te = /* @__PURE__ */ ((r) => (r.Word = "word", r.Sentence = "sentence", r.Paragraph = "paragraph", r))(te || {});
1462
+ const ae = (r, t) => "Segmenter" in Intl ? new ee(r, t) : new ie(r, t);
1463
+ class ee {
1464
+ constructor(t, e) {
1465
+ if (this.unit = e, t = t ?? (navigator == null ? void 0 : navigator.language), !("Segmenter" in Intl))
1466
+ throw new Error("Intl.Segmenter is not supported in this environment");
1467
+ if (e === "paragraph")
1468
+ throw new Error("IntlTextTokenizer does not handle TextUnit.Paragraph");
1469
+ this.segmenter = new Intl.Segmenter(t, {
1470
+ granularity: e
1471
+ });
1472
+ }
1473
+ tokenize(t) {
1474
+ const e = this.segmenter.segment(t), i = [];
1475
+ for (let s of e) {
1476
+ if (this.unit === "word" && s.isWordLike === !1)
1477
+ continue;
1478
+ const a = ht(s.segment);
1479
+ a !== null && i.push([s.index, s.index + a.length]);
1480
+ }
1481
+ return i;
1482
+ }
1483
+ }
1484
+ class ie {
1485
+ constructor(t, e) {
1486
+ if (this.unit = e, t = t ?? (navigator == null ? void 0 : navigator.language), this.isEnglish = t.toLowerCase().split("-")[0] === "en", e === "paragraph")
1487
+ throw new Error("NaiveTextTokenizer does not handle TextUnit.Paragraph");
1488
+ this.tokenizer = new z();
1489
+ }
1490
+ tokenize(t) {
1491
+ let e = [];
1492
+ switch (this.unit) {
1493
+ case "word":
1494
+ e = this.tokenizer.words()(t);
1495
+ break;
1496
+ case "sentence":
1497
+ this.isEnglish ? e = qt(this.tokenizer).sentences()(t) : e = this.tokenizer.sections()(t);
1498
+ break;
1499
+ default:
1500
+ e = [];
1501
+ }
1502
+ if (!e)
1503
+ return [];
1504
+ const i = [];
1505
+ return e.forEach((s) => {
1506
+ if (s.value.length === 0)
1507
+ return;
1508
+ const a = ht(s.value);
1509
+ a !== null && i.push([s.index, s.index + a.length]);
1510
+ }), i;
1511
+ }
1512
+ }
1513
+ const re = new RegExp("[\\p{L}\\p{N}]+", "u"), ht = (r) => {
1514
+ const t = r.trimEnd();
1515
+ return t.length === 0 || t.match(re) === null ? null : t;
1516
+ };
1517
+ class I {
1518
+ constructor(t) {
1519
+ this.fetcher = new kt(), t.fetcher && (this.fetcher = t.fetcher), this.manifest = t.manifest, this.context = t.manifest.context, this.metadata = t.manifest.metadata, this.links = t.manifest.links, this.readingOrder = t.manifest.readingOrder, this.resources = t.manifest.resources, this.tableOfContents = t.manifest.tableOfContents, this.subcollections = t.manifest.subcollections;
1520
+ }
1521
+ /** The URL where this publication is served, computed from the `Link` with `self` relation.
1522
+ * e.g. https://provider.com/pub1293/manifest.json gives https://provider.com/pub1293/
1523
+ */
1524
+ get baseURL() {
1525
+ return this.manifest.baseURL;
1526
+ }
1527
+ /** Finds the first Link having the given `href` in the publication's links. */
1528
+ linkWithHref(t) {
1529
+ return this.manifest.linkWithHref(t);
1530
+ }
1531
+ /**
1532
+ * Returns the [links] of the first child [PublicationCollection] with the given role, or an
1533
+ * empty list.
1534
+ */
1535
+ linksWithRole(t) {
1536
+ var i;
1537
+ const e = (i = this.subcollections) == null ? void 0 : i.get(t);
1538
+ return e && e.length > 0 ? e[0].links : void 0;
1539
+ }
1540
+ /** Finds all the links with the given relation in the publication's links. */
1541
+ linksWithRel(t) {
1542
+ return this.manifest.linksWithRel(t);
1543
+ }
1544
+ /**
1545
+ * Finds the first [Link] having the given [rel] in the publications's links.
1546
+ */
1547
+ linkWithRel(t) {
1548
+ return this.manifest.linkWithRel(t);
1549
+ }
1550
+ async positionsFromManifest() {
1551
+ const t = this.manifest.links.findWithMediaType(
1552
+ "application/vnd.readium.position-list+json"
1553
+ );
1554
+ if (t === void 0)
1555
+ return [];
1556
+ const e = await this.get(
1557
+ t
1558
+ ).readAsJSON();
1559
+ return e.total ? e.positions.map((i) => P.deserialize(i)).filter((i) => i !== void 0) : [];
1560
+ }
1561
+ async guideForLink(t) {
1562
+ const e = (o) => {
1563
+ var l;
1564
+ return (l = o.alternates) == null ? void 0 : l.findWithMediaType(
1565
+ "application/guided-navigation+json"
1566
+ );
1567
+ };
1568
+ let i = e(t);
1569
+ if (!i) {
1570
+ const o = this.linkWithHref(t.href);
1571
+ o !== void 0 && (i = e(o));
1572
+ }
1573
+ if (i || (i = this.manifest.links.findWithMediaType(
1574
+ "application/guided-navigation+json"
1575
+ )), !i)
1576
+ return;
1577
+ let s = i.href;
1578
+ if (i.templated) {
1579
+ const o = new B(s), l = {};
1580
+ o.parameters.has("ref") && (l.ref = t.href), s = new B(s).expand(l);
1581
+ }
1582
+ const a = await this.get(new w({
1583
+ href: s
1584
+ })).readAsJSON();
1585
+ return Q.deserialize(a);
1586
+ }
1587
+ /**
1588
+ * Returns the resource targeted by the given non-templated [link].
1589
+ */
1590
+ get(t) {
1591
+ return this.fetcher.get(t);
1592
+ }
1593
+ }
1594
+ I.prototype.getPageList = function() {
1595
+ return this.linksWithRole("pageList");
1596
+ };
1597
+ I.prototype.getLandmarks = function() {
1598
+ return this.linksWithRole("landmarks");
1599
+ };
1600
+ I.prototype.getListOfAudioClips = function() {
1601
+ return this.linksWithRole("loa");
1602
+ };
1603
+ I.prototype.getListOfIllustrations = function() {
1604
+ return this.linksWithRole("loi");
1605
+ };
1606
+ I.prototype.getListOfTables = function() {
1607
+ return this.linksWithRole("lot");
1608
+ };
1609
+ I.prototype.getListOfVideoClips = function() {
1610
+ return this.linksWithRole("lov");
1611
+ };
1612
+ class G {
1613
+ /**
1614
+ * Creates a [DomRange].
1615
+ */
1616
+ constructor(t) {
1617
+ this.cssSelector = t.cssSelector, this.textNodeIndex = t.textNodeIndex, this.charOffset = t.charOffset;
1618
+ }
1619
+ /**
1620
+ * Parses a [DomRangePoint] from its RWPM JSON representation.
1621
+ */
1622
+ static deserialize(t) {
1623
+ if (!(t && t.cssSelector))
1624
+ return;
1625
+ let e = y(t.textNodeIndex);
1626
+ if (e === void 0)
1627
+ return;
1628
+ let i = y(t.charOffset);
1629
+ return i === void 0 && (i = y(t.offset)), new G({
1630
+ cssSelector: t.cssSelector,
1631
+ textNodeIndex: e,
1632
+ charOffset: i
1633
+ });
1634
+ }
1635
+ /**
1636
+ * Serializes a [DomRangePoint] to its RWPM JSON representation.
1637
+ */
1638
+ serialize() {
1639
+ const t = {
1640
+ cssSelector: this.cssSelector,
1641
+ textNodeIndex: this.textNodeIndex
1642
+ };
1643
+ return this.charOffset !== void 0 && (t.charOffset = this.charOffset), t;
1644
+ }
1645
+ }
1646
+ class _ {
1647
+ /**
1648
+ * Creates a [DomRange].
1649
+ */
1650
+ constructor(t) {
1651
+ this.start = t.start, this.end = t.end;
1652
+ }
1653
+ /**
1654
+ * Parses a [DomRange] from its RWPM JSON representation.
1655
+ */
1656
+ static deserialize(t) {
1657
+ if (!t)
1658
+ return;
1659
+ let e = G.deserialize(t.start);
1660
+ if (e)
1661
+ return new _({
1662
+ start: e,
1663
+ end: G.deserialize(t.end)
1664
+ });
1665
+ }
1666
+ /**
1667
+ * Serializes a [DomRange] to its RWPM JSON representation.
1668
+ */
1669
+ serialize() {
1670
+ const t = { start: this.start.serialize() };
1671
+ return this.end && (t.end = this.end.serialize()), t;
1672
+ }
1673
+ }
1674
+ E.prototype.getCssSelector = function() {
1675
+ var r;
1676
+ return (r = this.otherLocations) == null ? void 0 : r.get("cssSelector");
1677
+ };
1678
+ E.prototype.getPartialCfi = function() {
1679
+ var r;
1680
+ return (r = this.otherLocations) == null ? void 0 : r.get("partialCfi");
1681
+ };
1682
+ E.prototype.getDomRange = function() {
1683
+ var r;
1684
+ return _.deserialize((r = this.otherLocations) == null ? void 0 : r.get("domRange"));
1685
+ };
1686
+ E.prototype.fragmentParameters = function() {
1687
+ return new Map(
1688
+ 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) => [
1689
+ r[0].trim().toLowerCase(),
1690
+ r[1].trim()
1691
+ ])
1692
+ );
1693
+ };
1694
+ E.prototype.htmlId = function() {
1695
+ if (!this.fragments.length)
1696
+ return;
1697
+ let r = this.fragments.find((t) => t.length && !t.includes("="));
1698
+ if (!r) {
1699
+ const t = this.fragmentParameters();
1700
+ t.has("id") ? r = t.get("id") : t.has("name") && (r = t.get("name"));
1701
+ }
1702
+ return r != null && r.startsWith("#") ? r.slice(1) : r;
1703
+ };
1704
+ E.prototype.page = function() {
1705
+ const r = parseInt(this.fragmentParameters().get("page"));
1706
+ if (!isNaN(r) && r >= 0)
1707
+ return r;
1708
+ };
1709
+ E.prototype.time = function() {
1710
+ const r = parseInt(this.fragmentParameters().get("t"));
1711
+ if (!isNaN(r))
1712
+ return r;
1713
+ };
1714
+ E.prototype.space = function() {
1715
+ const r = this.fragmentParameters();
1716
+ if (!r.has("xywh"))
1717
+ return;
1718
+ const t = r.get("xywh").split(",").map((e) => parseInt(e));
1719
+ if (t.length === 4 && !t.some(isNaN))
1720
+ return t;
1721
+ };
1722
+ class j {
1723
+ /** Creates a [Price]. */
1724
+ constructor(t) {
1725
+ this.currency = t.currency, this.value = t.value;
1726
+ }
1727
+ /**
1728
+ * Parses a [Price] from its RWPM JSON representation.
1729
+ */
1730
+ static deserialize(t) {
1731
+ if (!t)
1732
+ return;
1733
+ let e = t.currency;
1734
+ if (!(e && typeof e == "string" && e.length > 0))
1735
+ return;
1736
+ let i = y(t.value);
1737
+ if (i !== void 0)
1738
+ return new j({ currency: e, value: i });
1739
+ }
1740
+ /**
1741
+ * Serializes a [Price] to its RWPM JSON representation.
1742
+ */
1743
+ serialize() {
1744
+ return { currency: this.currency, value: this.value };
1745
+ }
1746
+ }
1747
+ class D {
1748
+ /** Creates a [Acquisition]. */
1749
+ constructor(t) {
1750
+ this.type = t.type, this.children = t.children;
1751
+ }
1752
+ /**
1753
+ * Parses a [Acquisition] from its RWPM JSON representation.
1754
+ */
1755
+ static deserialize(t) {
1756
+ if (t && t.type)
1757
+ return new D({
1758
+ type: t.type,
1759
+ children: D.deserializeArray(t.children)
1760
+ });
1761
+ }
1762
+ static deserializeArray(t) {
1763
+ if (t instanceof Array)
1764
+ return t.map((e) => D.deserialize(e)).filter((e) => e !== void 0);
1765
+ }
1766
+ /**
1767
+ * Serializes a [Acquisition] to its RWPM JSON representation.
1768
+ */
1769
+ serialize() {
1770
+ const t = { type: this.type };
1771
+ return this.children && (t.children = this.children.map((e) => e.serialize())), t;
1772
+ }
1773
+ }
1774
+ class tt {
1775
+ /** Creates a [Price]. */
1776
+ constructor(t) {
1777
+ this.total = t.total, this.position = t.position;
1778
+ }
1779
+ /**
1780
+ * Parses a [Holds] from its RWPM JSON representation.
1781
+ */
1782
+ static deserialize(t) {
1783
+ if (t)
1784
+ return new tt({
1785
+ total: y(t.total),
1786
+ position: y(t.position)
1787
+ });
1788
+ }
1789
+ /**
1790
+ * Serializes a [Holds] to its RWPM JSON representation.
1791
+ */
1792
+ serialize() {
1793
+ const t = {};
1794
+ return this.total !== void 0 && (t.total = this.total), this.position !== void 0 && (t.position = this.position), t;
1795
+ }
1796
+ }
1797
+ class et {
1798
+ /** Creates a [Copies]. */
1799
+ constructor(t) {
1800
+ this.total = t.total, this.available = t.available;
1801
+ }
1802
+ /**
1803
+ * Parses a [Copies] from its RWPM JSON representation.
1804
+ */
1805
+ static deserialize(t) {
1806
+ if (t)
1807
+ return new et({
1808
+ total: y(t.total),
1809
+ available: y(t.available)
1810
+ });
1811
+ }
1812
+ /**
1813
+ * Serializes a [Copies] to its RWPM JSON representation.
1814
+ */
1815
+ serialize() {
1816
+ const t = {};
1817
+ return this.total !== void 0 && (t.total = this.total), this.available !== void 0 && (t.available = this.available), t;
1818
+ }
1819
+ }
1820
+ var se = /* @__PURE__ */ ((r) => (r.available = "available", r.reserved = "reserved", r.ready = "ready", r))(se || {});
1821
+ class it {
1822
+ /** Creates a [Availability]. */
1823
+ constructor(t) {
1824
+ this.state = t.state, this.since = t.since, this.until = t.until;
1825
+ }
1826
+ /**
1827
+ * Parses a [Availability] from its RWPM JSON representation.
1828
+ */
1829
+ static deserialize(t) {
1830
+ if (t && t.state)
1831
+ return new it({
1832
+ state: t.state,
1833
+ since: F(t.since),
1834
+ until: F(t.until)
1835
+ });
1836
+ }
1837
+ /**
1838
+ * Serializes a [Availability] to its RWPM JSON representation.
1839
+ */
1840
+ serialize() {
1841
+ const t = { state: this.state };
1842
+ return this.since !== void 0 && (t.since = this.since.toISOString()), this.until !== void 0 && (t.until = this.until.toISOString()), t;
1843
+ }
1844
+ }
1845
+ g.prototype.getNumberOfItems = function() {
1846
+ return y(this.otherProperties.numberOfItems);
1847
+ };
1848
+ g.prototype.getPrice = function() {
1849
+ return j.deserialize(this.otherProperties.price);
1850
+ };
1851
+ g.prototype.getIndirectAcquisitions = function() {
1852
+ const r = this.otherProperties.indirectAcquisition;
1853
+ if (r && r instanceof Array)
1854
+ return r.map((t) => D.deserialize(t)).filter((t) => t !== void 0);
1855
+ };
1856
+ g.prototype.getHolds = function() {
1857
+ return tt.deserialize(this.otherProperties.holds);
1858
+ };
1859
+ g.prototype.getCopies = function() {
1860
+ return et.deserialize(this.otherProperties.copies);
1861
+ };
1862
+ g.prototype.getAvailability = function() {
1863
+ return it.deserialize(this.otherProperties.availability);
1864
+ };
1865
+ g.prototype.getAuthenticate = function() {
1866
+ return w.deserialize(this.otherProperties.authenticate);
1867
+ };
1868
+ I.prototype.getImages = function() {
1869
+ return this.linksWithRole("images");
1870
+ };
1871
+ const rt = class k {
1872
+ /**
1873
+ * translations can be a string or a collection of language/translation pairs,
1874
+ * for a single string the language is assumed to be undefined
1875
+ */
1876
+ constructor(t) {
1877
+ this.translations = typeof t == "string" ? { [k.UNDEFINED_LANGUAGE]: t } : t;
1878
+ }
1879
+ /**
1880
+ * Parses a [LocalizedString] from its RWPM JSON representation.
1881
+ *
1882
+ * "anyOf": [
1883
+ * {
1884
+ * "type": "string"
1885
+ * },
1886
+ * {
1887
+ * "description": "The language in a language map must be a valid BCP 47 tag.",
1888
+ * "type": "object",
1889
+ * "patternProperties": {
1890
+ * "^((?<grandfathered>(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((?<language>([A-Za-z]{2,3}(-(?<extlang>[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-(?<script>[A-Za-z]{4}))?(-(?<region>[A-Za-z]{2}|[0-9]{3}))?(-(?<variant>[A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*(-(?<extension>[0-9A-WY-Za-wy-z](-[A-Za-z0-9]{2,8})+))*(-(?<privateUse>x(-[A-Za-z0-9]{1,8})+))?)|(?<privateUse2>x(-[A-Za-z0-9]{1,8})+))$": {
1891
+ * "type": "string"
1892
+ * }
1893
+ * },
1894
+ * "additionalProperties": false,
1895
+ * "minProperties": 1
1896
+ * }
1897
+ * ]
1898
+ */
1899
+ static deserialize(t) {
1900
+ if (t && (typeof t == "string" || t.constructor === Object))
1901
+ return new k(t);
1902
+ }
1903
+ serialize() {
1904
+ return this.translations;
1905
+ }
1906
+ /**
1907
+ * Returns the first translation for the given [language] BCP–47 tag.
1908
+ * If not found, then fallback:
1909
+ * 1. on the undefined language
1910
+ * 2. on the English language
1911
+ * 3. the first translation found
1912
+ * 4. returns empty string
1913
+ */
1914
+ getTranslation(t) {
1915
+ return this.translations[t || k.UNDEFINED_LANGUAGE] || this.translations[k.UNDEFINED_LANGUAGE] || this.translations[k.LANGUAGE_EN] || (Object.values(this.translations).length === 0 ? "" : Object.values(this.translations)[0]);
1916
+ }
1917
+ };
1918
+ rt.UNDEFINED_LANGUAGE = "undefined";
1919
+ rt.LANGUAGE_EN = "en";
1920
+ let O = rt;
1921
+ class H {
1922
+ /**
1923
+ * Creates a [Contributor] object.
1924
+ */
1925
+ constructor(t) {
1926
+ this.name = t.name, this.sortAs = t.sortAs, this.identifier = t.identifier, this.roles = t.roles, this.links = t.links, this.position = t.position;
1927
+ }
1928
+ /**
1929
+ * Parses a [Contributor] from its RWPM JSON representation.
1930
+ *
1931
+ * A contributor can be parsed from a single string, or a full-fledged object.
1932
+ */
1933
+ static deserialize(t) {
1934
+ if (t)
1935
+ return typeof t == "string" ? new H({
1936
+ name: O.deserialize(t)
1937
+ }) : t.name ? new H({
1938
+ name: O.deserialize(t.name),
1939
+ sortAs: t.sortAs,
1940
+ identifier: t.identifier,
1941
+ roles: t.role ? new Set(T(t.role)) : void 0,
1942
+ links: b.deserialize(t.links),
1943
+ position: S(t.position)
1944
+ }) : void 0;
1945
+ }
1946
+ /**
1947
+ * Serializes a [Contributor] to its RWPM JSON representation.
1948
+ */
1949
+ serialize() {
1950
+ const t = { name: this.name.serialize() };
1951
+ return this.sortAs !== void 0 && (t.sortAs = this.sortAs), this.identifier !== void 0 && (t.identifier = this.identifier), this.roles && (t.role = X(this.roles)), this.links && (t.links = this.links.serialize()), this.position !== void 0 && (t.position = this.position), t;
1952
+ }
1953
+ }
1954
+ class m {
1955
+ /**
1956
+ * Creates a [Contributors] object.
1957
+ */
1958
+ constructor(t) {
1959
+ this.items = t;
1960
+ }
1961
+ /**
1962
+ * Parses a [Contributors] from its RWPM JSON representation.
1963
+ *
1964
+ */
1965
+ static deserialize(t) {
1966
+ if (!t)
1967
+ return;
1968
+ const e = t instanceof Array ? t : [t];
1969
+ return new m(
1970
+ e.map((i) => H.deserialize(i)).filter((i) => i !== void 0)
1971
+ );
1972
+ }
1973
+ /**
1974
+ * Serializes a [Contributors] to its RWPM JSON representation.
1975
+ */
1976
+ serialize() {
1977
+ return this.items.map((t) => t.serialize());
1978
+ }
1979
+ }
1980
+ class R {
1981
+ /** Creates an Array of [Subject]. */
1982
+ constructor(t) {
1983
+ this.items = t && t.items ? t.items : /* @__PURE__ */ new Map();
1984
+ }
1985
+ /**
1986
+ * Parses a [BelongsTo] from its RWPM JSON representation.
1987
+ */
1988
+ static deserialize(t) {
1989
+ if (!(t && t instanceof Object))
1990
+ return;
1991
+ const e = /* @__PURE__ */ new Map();
1992
+ return Object.entries(t).forEach(([i, s]) => {
1993
+ const a = m.deserialize(s);
1994
+ a && a.items.length > 0 && e.set(i, a);
1995
+ }), new R({ items: e });
1996
+ }
1997
+ /**
1998
+ * Serializes a [BelongsTo] to its RWPM JSON representation.
1999
+ */
2000
+ serialize() {
2001
+ const t = {};
2002
+ return this.items.forEach(
2003
+ (e, i) => t[i] = e.serialize()
2004
+ ), t;
2005
+ }
2006
+ }
2007
+ var x = /* @__PURE__ */ ((r) => (r.auto = "auto", r.btt = "btt", r.ltr = "ltr", r.rtl = "rtl", r.ttb = "ttb", r))(x || {});
2008
+ function oe(r) {
2009
+ switch (r) {
2010
+ case "auto":
2011
+ case "ttb":
2012
+ case "ltr":
2013
+ return W.left;
2014
+ case "rtl":
2015
+ case "btt":
2016
+ return W.right;
2017
+ default:
2018
+ return W.left;
2019
+ }
2020
+ }
2021
+ class $ {
2022
+ /** Creates a [Subject]. */
2023
+ constructor(t) {
2024
+ this.name = t.name, this.sortAs = t.sortAs, this.code = t.code, this.scheme = t.scheme, this.links = t.links;
2025
+ }
2026
+ /**
2027
+ * Parses a [Subject] from its RWPM JSON representation.
2028
+ *
2029
+ * A [Subject] can be parsed from a single string, or a full-fledged object.
2030
+ */
2031
+ static deserialize(t) {
2032
+ if (t)
2033
+ return typeof t == "string" ? new $({
2034
+ name: O.deserialize(t)
2035
+ }) : t.name ? new $({
2036
+ name: O.deserialize(t.name),
2037
+ sortAs: t.sortAs,
2038
+ code: t.code,
2039
+ scheme: t.scheme,
2040
+ links: b.deserialize(t.links)
2041
+ }) : void 0;
2042
+ }
2043
+ /**
2044
+ * Serializes a [Subject] to its RWPM JSON representation.
2045
+ */
2046
+ serialize() {
2047
+ const t = { name: this.name.serialize() };
2048
+ return this.sortAs !== void 0 && (t.sortAs = this.sortAs), this.code !== void 0 && (t.code = this.code), this.scheme !== void 0 && (t.scheme = this.scheme), this.links && (t.links = this.links.serialize()), t;
2049
+ }
2050
+ }
2051
+ class st {
2052
+ /** Creates an Array of [Subject]. */
2053
+ constructor(t) {
2054
+ this.items = t;
2055
+ }
2056
+ /**
2057
+ * Parses a [Subjects] from its RWPM JSON representation.
2058
+ */
2059
+ static deserialize(t) {
2060
+ if (!t)
2061
+ return;
2062
+ const e = t instanceof Array ? t : [t];
2063
+ return new st(
2064
+ e.map((i) => $.deserialize(i)).filter((i) => i !== void 0)
2065
+ );
2066
+ }
2067
+ /**
2068
+ * Serializes a [Subjects] to its RWPM JSON representation.
2069
+ */
2070
+ serialize() {
2071
+ return this.items.map((t) => t.serialize());
2072
+ }
2073
+ }
2074
+ const ct = class q {
2075
+ /** Creates [Metadata] object */
2076
+ constructor(t) {
2077
+ this.title = t.title, this.typeUri = t.typeUri, this.identifier = t.identifier, this.subtitle = t.subtitle, this.sortAs = t.sortAs, this.artists = t.artists, this.authors = t.authors, this.colorists = t.colorists, this.contributors = t.contributors, this.editors = t.editors, this.illustrators = t.illustrators, this.inkers = t.inkers, this.letterers = t.letterers, this.narrators = t.narrators, this.pencilers = t.pencilers, this.translators = t.translators, this.languages = t.languages, this.description = t.description, this.publishers = t.publishers, this.imprints = t.imprints, this.published = t.published, this.modified = t.modified, this.subjects = t.subjects, this.belongsTo = t.belongsTo, this.belongsToCollections = t.belongsToCollections, this.belongsToSeries = t.belongsToSeries, this.belongsToCollections && this.belongsToCollections.items.length > 0 && (this.belongsTo || (this.belongsTo = new R()), this.belongsTo.items.set("collection", this.belongsToCollections)), this.belongsToSeries && this.belongsToSeries.items.length > 0 && (this.belongsTo || (this.belongsTo = new R()), this.belongsTo.items.set("series", this.belongsToSeries)), this.readingProgression = t.readingProgression, this.duration = t.duration, this.numberOfPages = t.numberOfPages, this.otherMetadata = t.otherMetadata;
2078
+ }
2079
+ /**
2080
+ * Parses a [Metadata] from its RWPM JSON representation.
2081
+ *
2082
+ * If the metadata can't be parsed, a warning will be logged with [warnings].
2083
+ */
2084
+ static deserialize(t) {
2085
+ if (!(t && t.title))
2086
+ return;
2087
+ const e = O.deserialize(t.title), i = t["@type"], s = t.identifier, a = O.deserialize(t.subtitle), o = O.deserialize(t.sortAs), l = m.deserialize(t.artist), h = m.deserialize(t.author), p = m.deserialize(t.colorist), f = m.deserialize(t.contributor), u = m.deserialize(t.editor), c = m.deserialize(t.illustrator), d = m.deserialize(t.inker), v = m.deserialize(t.letterer), N = m.deserialize(t.narrator), dt = m.deserialize(t.penciler), gt = m.deserialize(t.translator), mt = T(t.language), zt = t.description, yt = m.deserialize(t.publisher), bt = m.deserialize(t.imprint), Et = F(t.published), vt = F(t.modified), xt = st.deserialize(t.subject), At = R.deserialize(t.belongsTo), wt = t.readingProgression, Ot = y(t.duration), Pt = y(t.numberOfPages);
2088
+ let U = Object.assign({}, t);
2089
+ return q.mappedProperties.forEach((It) => delete U[It]), Object.keys(U).length === 0 && (U = void 0), new q({
2090
+ title: e,
2091
+ typeUri: i,
2092
+ identifier: s,
2093
+ subtitle: a,
2094
+ sortAs: o,
2095
+ artists: l,
2096
+ authors: h,
2097
+ colorists: p,
2098
+ contributors: f,
2099
+ editors: u,
2100
+ illustrators: c,
2101
+ inkers: d,
2102
+ letterers: v,
2103
+ narrators: N,
2104
+ pencilers: dt,
2105
+ translators: gt,
2106
+ languages: mt,
2107
+ description: zt,
2108
+ publishers: yt,
2109
+ imprints: bt,
2110
+ published: Et,
2111
+ modified: vt,
2112
+ subjects: xt,
2113
+ belongsTo: At,
2114
+ readingProgression: wt,
2115
+ duration: Ot,
2116
+ numberOfPages: Pt,
2117
+ otherMetadata: U
2118
+ });
2119
+ }
2120
+ /**
2121
+ * Serializes a [Metadata] to its RWPM JSON representation.
2122
+ */
2123
+ serialize() {
2124
+ const t = { title: this.title.serialize() };
2125
+ if (this.typeUri !== void 0 && (t["@type"] = this.typeUri), this.identifier !== void 0 && (t.identifier = this.identifier), this.subtitle && (t.subtitle = this.subtitle.serialize()), this.sortAs && (t.sortAs = this.sortAs.serialize()), this.editors && (t.editor = this.editors.serialize()), this.artists && (t.artist = this.artists.serialize()), this.authors && (t.author = this.authors.serialize()), this.colorists && (t.colorist = this.colorists.serialize()), this.contributors && (t.contributor = this.contributors.serialize()), this.illustrators && (t.illustrator = this.illustrators.serialize()), this.letterers && (t.letterer = this.letterers.serialize()), this.narrators && (t.narrator = this.narrators.serialize()), this.pencilers && (t.penciler = this.pencilers.serialize()), this.translators && (t.translator = this.translators.serialize()), this.inkers && (t.inker = this.inkers.serialize()), this.languages && (t.language = this.languages), this.description !== void 0 && (t.description = this.description), this.publishers && (t.publisher = this.publishers.serialize()), this.imprints && (t.imprint = this.imprints.serialize()), this.published !== void 0 && (t.published = this.published.toISOString()), this.modified !== void 0 && (t.modified = this.modified.toISOString()), this.subjects && (t.subject = this.subjects.serialize()), this.belongsTo && (t.belongsTo = this.belongsTo.serialize()), this.readingProgression && (t.readingProgression = this.readingProgression), this.duration !== void 0 && (t.duration = this.duration), this.numberOfPages !== void 0 && (t.numberOfPages = this.numberOfPages), this.otherMetadata) {
2126
+ const e = this.otherMetadata;
2127
+ Object.keys(e).forEach((i) => t[i] = e[i]);
2128
+ }
2129
+ return t;
2130
+ }
2131
+ /**
2132
+ * Computes a [ReadingProgression] when the value of [readingProgression] is set to
2133
+ * auto, using the publication language.
2134
+ *
2135
+ * See this issue for more details: https://github.com/readium/architecture/issues/113
2136
+ */
2137
+ get effectiveReadingProgression() {
2138
+ var i;
2139
+ if (this.readingProgression && this.readingProgression !== x.auto)
2140
+ return this.readingProgression;
2141
+ if (((i = this.languages) == null ? void 0 : i.length) !== 1)
2142
+ return x.ltr;
2143
+ const t = this.languages[0].toLowerCase();
2144
+ if (t === "zh-hant" || t === "zh-tw")
2145
+ return x.rtl;
2146
+ switch (t.split("-")[0]) {
2147
+ case "ar":
2148
+ return x.rtl;
2149
+ case "fa":
2150
+ return x.rtl;
2151
+ case "he":
2152
+ return x.rtl;
2153
+ default:
2154
+ return x.ltr;
2155
+ }
2156
+ }
2157
+ };
2158
+ ct.mappedProperties = [
2159
+ "title",
2160
+ "@type",
2161
+ "identifier",
2162
+ "subtitle",
2163
+ "sortAs",
2164
+ "artist",
2165
+ "author",
2166
+ "colorist",
2167
+ "contributor",
2168
+ "editor",
2169
+ "illustrator",
2170
+ "inker",
2171
+ "letterer",
2172
+ "narrator",
2173
+ "penciler",
2174
+ "translator",
2175
+ "language",
2176
+ "description",
2177
+ "publisher",
2178
+ "imprint",
2179
+ "published",
2180
+ "modified",
2181
+ "subject",
2182
+ "belongsTo",
2183
+ "readingProgression",
2184
+ "duration",
2185
+ "numberOfPages"
2186
+ ];
2187
+ let ft = ct;
2188
+ ft.prototype.getPresentation = function() {
2189
+ var t, e;
2190
+ const r = ((t = this.otherMetadata) == null ? void 0 : t.presentation) || ((e = this.otherMetadata) == null ? void 0 : e.rendition);
2191
+ if (r)
2192
+ return J.deserialize(r);
2193
+ };
2194
+ g.prototype.getClipped = function() {
2195
+ return this.otherProperties.clipped;
2196
+ };
2197
+ g.prototype.getFit = function() {
2198
+ return this.otherProperties.fit;
2199
+ };
2200
+ g.prototype.getOrientation = function() {
2201
+ return this.otherProperties.orientation;
2202
+ };
2203
+ g.prototype.getOverflow = function() {
2204
+ return this.otherProperties.overflow;
2205
+ };
2206
+ g.prototype.getPage = function() {
2207
+ return this.otherProperties.page || void 0;
2208
+ };
2209
+ g.prototype.getSpread = function() {
2210
+ return this.otherProperties.spread || void 0;
2211
+ };
2212
+ class V {
2213
+ /**
2214
+ * Creates a [LocatorMetadata].
2215
+ */
2216
+ constructor(t) {
2217
+ this.title = t.title, this.numberOfItems = t.numberOfItems, this.otherMetadata = t.otherMetadata;
2218
+ }
2219
+ /**
2220
+ * Parses a [LocatorMetadata] from its RWPM JSON representation.
2221
+ */
2222
+ static deserialize(t) {
2223
+ if (!t)
2224
+ return;
2225
+ const e = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(["title", "numberOfItems"]);
2226
+ return Object.entries(t).forEach(([s, a]) => {
2227
+ i.has(s) || e.set(s, a);
2228
+ }), new V({
2229
+ title: O.deserialize(t.title),
2230
+ numberOfItems: S(t.numberOfItems),
2231
+ otherMetadata: e.size === 0 ? void 0 : e
2232
+ });
2233
+ }
2234
+ /**
2235
+ * Serializes a [LocatorMetadata] to its RWPM JSON representation.
2236
+ */
2237
+ serialize() {
2238
+ const t = {};
2239
+ return this.title && (t.title = this.title.serialize()), this.numberOfItems !== void 0 && (t.numberOfItems = this.numberOfItems), this.otherMetadata && this.otherMetadata.forEach((e, i) => t[i] = e), t;
2240
+ }
2241
+ }
2242
+ class ut {
2243
+ /**
2244
+ * Creates a [LocatorCollection].
2245
+ */
2246
+ constructor(t) {
2247
+ this.metadata = t.metadata ?? new V({}), this.links = t.links ?? new b([]), this.locators = t.locators ?? [];
2248
+ }
2249
+ /**
2250
+ * Parses a [LocatorCollection] from its RWPM JSON representation.
2251
+ */
2252
+ static deserialize(t) {
2253
+ if (!t)
2254
+ return;
2255
+ let e, i = t.locators;
2256
+ return i && i instanceof Array && (e = i.map((s) => P.deserialize(s)).filter((s) => s !== void 0)), new ut({
2257
+ metadata: V.deserialize(t.metadata),
2258
+ links: b.deserialize(t.links),
2259
+ locators: e
2260
+ });
2261
+ }
2262
+ /**
2263
+ * Serializes a [LocatorCollection] to its RWPM JSON representation.
2264
+ */
2265
+ serialize() {
2266
+ const t = {};
2267
+ if (this.metadata) {
2268
+ let e = this.metadata.serialize();
2269
+ e && Object.keys(e).length > 0 && (t.metadata = e);
2270
+ }
2271
+ return this.links && this.links.items.length > 0 && (t.links = this.links.serialize()), this.locators && (t.locators = this.locators.map((e) => e.serialize())), t;
2272
+ }
2273
+ }
2274
+ class A {
2275
+ /**
2276
+ * Creates a [PublicationCollection].
2277
+ */
2278
+ constructor(t) {
2279
+ this.metadata = t.metadata, this.links = t.links, this.subcollections = t.subcollections;
2280
+ }
2281
+ /**
2282
+ * Parses a [PublicationCollection] from its RWPM JSON representation.
2283
+ */
2284
+ static deserialize(t) {
2285
+ if (!t)
2286
+ return;
2287
+ let e, i, s;
2288
+ if (t instanceof Array)
2289
+ e = b.deserialize(t);
2290
+ else if (t instanceof Object)
2291
+ e = b.deserialize(t.links), i = /* @__PURE__ */ new Map(), t.metadata && Object.entries(t.metadata).forEach(([a, o]) => {
2292
+ i == null || i.set(a, o);
2293
+ }), s = A.deserializeCollections(t);
2294
+ else
2295
+ return;
2296
+ if (!(!e || e.items.length === 0))
2297
+ return new A({
2298
+ metadata: i != null && i.size ? i : void 0,
2299
+ links: e,
2300
+ subcollections: s != null && s.size ? s : void 0
2301
+ });
2302
+ }
2303
+ /**
2304
+ * Parses a map of [PublicationCollection] indexed by their roles from its RWPM JSON representation.
2305
+ *
2306
+ */
2307
+ static deserializeCollections(t) {
2308
+ if (!t)
2309
+ return;
2310
+ const e = /* @__PURE__ */ new Map();
2311
+ return Object.entries(t).forEach(([i, s]) => {
2312
+ if (i !== "links" && i !== "metadata") {
2313
+ const a = A.deserialize(s);
2314
+ if (a) {
2315
+ const o = new Array();
2316
+ o.push(a), e.set(i, o);
2317
+ } else if (s instanceof Array) {
2318
+ const o = s.map(
2319
+ (l) => A.deserialize(l)
2320
+ ).filter((l) => l !== void 0);
2321
+ e.set(i, o);
2322
+ }
2323
+ }
2324
+ }), e.size ? e : void 0;
2325
+ }
2326
+ /**
2327
+ * Serializes a [PublicationCollection] to its RWPM JSON representation.
2328
+ */
2329
+ serialize() {
2330
+ const t = {};
2331
+ return this.metadata && (t.metadata = {}, this.metadata.forEach(
2332
+ (e, i) => t.metadata[i] = e
2333
+ )), this.links.items.length && (t.links = this.links.serialize()), A.serializeCollection(t, this.subcollections), t;
2334
+ }
2335
+ static serializeCollection(t, e) {
2336
+ e && e.size > 0 && e.forEach(
2337
+ (i, s) => {
2338
+ i.length === 1 ? t[s] = i[0].serialize() : t[s] = i.map((a) => a.serialize());
2339
+ }
2340
+ );
2341
+ }
2342
+ }
2343
+ class pt {
2344
+ constructor(t) {
2345
+ this.context = t.context, this.metadata = t.metadata, this.links = t.links, this.readingOrder = t.readingOrder, this.resources = t.resources, this.tableOfContents = t.tableOfContents, this.subcollections = t.subcollections;
2346
+ }
2347
+ /**
2348
+ * Parses a [Publication] from its RWPM JSON representation.
2349
+ *
2350
+ * https://readium.org/webpub-manifest/
2351
+ * https://readium.org/webpub-manifest/schema/publication.schema.json
2352
+ */
2353
+ static deserialize(t) {
2354
+ if (!t)
2355
+ return;
2356
+ const e = ft.deserialize(t.metadata);
2357
+ if (!e)
2358
+ return;
2359
+ const i = b.deserialize(t.links);
2360
+ if (!i)
2361
+ return;
2362
+ const s = b.deserialize(
2363
+ t.readingOrder ? t.readingOrder : t.spine
2364
+ );
2365
+ if (s)
2366
+ return new pt({
2367
+ context: T(t["@context"]),
2368
+ metadata: e,
2369
+ links: i,
2370
+ readingOrder: s,
2371
+ resources: b.deserialize(t.resources),
2372
+ tableOfContents: b.deserialize(t.toc),
2373
+ subcollections: A.deserializeCollections({
2374
+ sub: t.sub
2375
+ })
2376
+ });
2377
+ }
2378
+ /**
2379
+ * Serializes a [Publication] to its RWPM JSON representation.
2380
+ */
2381
+ serialize() {
2382
+ const t = {};
2383
+ return this.context !== void 0 && (t["@context"] = this.context), t.metadata = this.metadata.serialize(), t.links = this.links.serialize(), t.readingOrder = this.readingOrder.serialize(), this.resources && (t.resources = this.resources.serialize()), this.tableOfContents && (t.toc = this.tableOfContents.serialize()), A.serializeCollection(t, this.subcollections), t;
2384
+ }
2385
+ /** Finds the first link with the given relation in the manifest's links. */
2386
+ linkWithRel(t) {
2387
+ const e = new Array();
2388
+ e.push(this.readingOrder), this.resources && e.push(this.resources), e.push(this.links);
2389
+ let i;
2390
+ for (const s of e)
2391
+ if (i = s.findWithRel(t), i !== void 0)
2392
+ return i;
2393
+ return i;
2394
+ }
2395
+ /** Finds all the links with the given relation in the manifest's links. */
2396
+ linksWithRel(t) {
2397
+ const e = [];
2398
+ return e.push(this.readingOrder.filterByRel(t)), this.resources && e.push(this.resources.filterByRel(t)), e.push(this.links.filterByRel(t)), e.reduce((i, s) => i.concat(s), []);
2399
+ }
2400
+ /**
2401
+ * Creates a new [Locator] object from a [Link] to a resource of this manifest.
2402
+ * Returns null if the resource is not found in this manifest.
2403
+ */
2404
+ locatorFromLink(t) {
2405
+ const e = t.href.split("#"), i = e.length == 2 ? e[0] : t.href, s = this.linkWithHref(i);
2406
+ if (!s)
2407
+ return;
2408
+ const a = s.type;
2409
+ if (!a)
2410
+ return;
2411
+ const o = e.length == 2 ? e[1] : void 0;
2412
+ return new P({
2413
+ href: i,
2414
+ type: a,
2415
+ title: s.title ?? t.title,
2416
+ locations: new E({
2417
+ fragments: o ? [o] : void 0,
2418
+ progression: o ? void 0 : 0
2419
+ })
2420
+ });
2421
+ }
2422
+ /** Finds the first Link having the given `href` in the publication's links. */
2423
+ linkWithHref(t) {
2424
+ const e = (l) => {
2425
+ let h;
2426
+ for (const f of l)
2427
+ if (h = f.findWithHref(t), h !== void 0)
2428
+ return h;
2429
+ const p = new Array();
2430
+ return l.forEach((f) => {
2431
+ const u = [];
2432
+ for (const c of f.items)
2433
+ c.alternates && u.push(c.alternates), c.children && u.push(c.children);
2434
+ p.push(...u);
2435
+ }), p.length > 0 && (h = e(p)), h;
2436
+ }, i = [];
2437
+ i.push(this.readingOrder), this.resources && i.push(this.resources), i.push(this.links);
2438
+ const s = e(i);
2439
+ if (s !== void 0)
2440
+ return s;
2441
+ const a = t.split(/[#]/);
2442
+ if (a.length < 2)
2443
+ return;
2444
+ const o = a[0];
2445
+ return this.linkWithHref(o);
2446
+ }
2447
+ /** The URL where this publication is served, computed from the `Link` with `self` relation.
2448
+ * e.g. https://provider.com/pub1293/manifest.json gives https://provider.com/pub1293/
2449
+ */
2450
+ get baseURL() {
2451
+ const t = this.links.items.find(
2452
+ (e) => e.rels && e.rels.has("self")
2453
+ );
2454
+ if (t) {
2455
+ let e = t.href;
2456
+ if (e) {
2457
+ const i = e.lastIndexOf("/"), s = i === -1 ? void 0 : e.substring(i + 1);
2458
+ e = e.replace(new RegExp("/?$query$"), ""), e = e.replace(new RegExp("//$"), ""), s && (e = e.replace(new RegExp(s + "$"), ""));
2459
+ }
2460
+ return e;
2461
+ }
2462
+ }
2463
+ /**
2464
+ * Sets the URL where this [Publication]'s RWPM manifest is served.
2465
+ */
2466
+ setSelfLink(t) {
2467
+ this.links.items = this.links.items.filter(
2468
+ (e) => {
2469
+ var i;
2470
+ return e.rels === void 0 || !((i = e.rels) != null && i.has("self"));
2471
+ }
2472
+ ), this.links.items.push(
2473
+ new w({
2474
+ href: t,
2475
+ type: n.READIUM_WEBPUB_MANIFEST.string,
2476
+ rels: /* @__PURE__ */ new Set(["self"])
2477
+ })
2478
+ );
2479
+ }
2480
+ }
2481
+ export {
2482
+ D as Acquisition,
2483
+ it as Availability,
2484
+ se as AvailabilityStatus,
2485
+ R as BelongsTo,
2486
+ H as Contributor,
2487
+ m as Contributors,
2488
+ et as Copies,
2489
+ ae as DefaultTextContentTokenizer,
2490
+ _ as DomRange,
2491
+ G as DomRangePoint,
2492
+ ot as EPUBLayout,
2493
+ kt as EmptyFetcher,
2494
+ M as Encryption,
2495
+ Ct as Fit,
2496
+ Q as GuidedNavigationDocument,
2497
+ L as GuidedNavigationObject,
2498
+ tt as Holds,
2499
+ ne as HttpFetcher,
2500
+ St as HttpResource,
2501
+ ee as IntlTextTokenizer,
2502
+ w as Link,
2503
+ b as Links,
2504
+ O as LocalizedString,
2505
+ P as Locator,
2506
+ ut as LocatorCollection,
2507
+ V as LocatorCollectionMetadata,
2508
+ E as LocatorLocations,
2509
+ Y as LocatorText,
2510
+ pt as Manifest,
2511
+ n as MediaType,
2512
+ ft as Metadata,
2513
+ ie as NaiveTextTokenizer,
2514
+ Tt as Orientation,
2515
+ Nt as Overflow,
2516
+ W as Page,
2517
+ J as Presentation,
2518
+ j as Price,
2519
+ g as Properties,
2520
+ I as Publication,
2521
+ A as PublicationCollection,
2522
+ x as ReadingProgression,
2523
+ Lt as Spread,
2524
+ $ as Subject,
2525
+ st as Subjects,
2526
+ te as TextUnit,
2527
+ B as URITemplate,
2528
+ Dt as arrayfromJSON,
2529
+ T as arrayfromJSONorString,
2530
+ F as datefromJSON,
2531
+ oe as leadingPage,
2532
+ S as numberfromJSON,
2533
+ y as positiveNumberfromJSON,
2534
+ X as setToArray,
2535
+ ht as speakableToken
2536
+ };