@readium/shared 2.1.5 → 2.2.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2022, Readium Foundation
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/dist/index.js CHANGED
@@ -84,7 +84,7 @@ class ei {
84
84
  );
85
85
  return new DOMParser().parseFromString(
86
86
  await t.text(),
87
- "application/xml"
87
+ this._link.mediaType.isHTML ? this._link.mediaType.string : "text/xml"
88
88
  );
89
89
  }
90
90
  }
@@ -101,7 +101,7 @@ class ir {
101
101
  return this.readAsString().then((t) => t === void 0 ? t : JSON.parse(t));
102
102
  }
103
103
  readAsXML() {
104
- return this.readAsString().then((t) => t === void 0 ? t : new DOMParser().parseFromString(t, "text/xml"));
104
+ return this.link().then((t) => this.readAsString().then((e) => e === void 0 ? e : new DOMParser().parseFromString(e, t.mediaType.isHTML ? t.mediaType.string : "text/xml")));
105
105
  }
106
106
  }
107
107
  class _ {
@@ -214,15 +214,15 @@ const y = class y {
214
214
  };
215
215
  y.AUDITORY = new y("auditory"), y.CHART_ON_VISUAL = new y("chartOnVisual"), y.CHEM_ON_VISUAL = new y("chemOnVisual"), y.COLOR_DEPENDENT = new y("colorDependent"), y.DIAGRAM_ON_VISUAL = new y("diagramOnVisual"), y.MATH_ON_VISUAL = new y("mathOnVisual"), y.MUSIC_ON_VISUAL = new y("musicOnVisual"), y.TACTILE = new y("tactile"), y.TEXT_ON_VISUAL = new y("textOnVisual"), y.TEXTUAL = new y("textual"), y.VISUAL = new y("visual");
216
216
  let R = y;
217
- const x = class x {
217
+ const N = class N {
218
218
  constructor(t) {
219
219
  if (typeof t == "string") {
220
- if (!x.VALID_MODES.has(t.toLowerCase()))
220
+ if (!N.VALID_MODES.has(t.toLowerCase()))
221
221
  return;
222
222
  this.value = t.toLowerCase();
223
223
  } else {
224
224
  const e = t.filter(
225
- (i) => x.VALID_MODES.has(i.toLowerCase())
225
+ (i) => N.VALID_MODES.has(i.toLowerCase())
226
226
  );
227
227
  if (e.length === 0)
228
228
  return;
@@ -235,11 +235,11 @@ const x = class x {
235
235
  static deserialize(t) {
236
236
  if (!t) return;
237
237
  if (typeof t == "string")
238
- return new x(t);
238
+ return new N(t);
239
239
  if (!Array.isArray(t)) return;
240
- const e = t.filter((i) => i ? x.VALID_MODES.has(i.toLowerCase()) : !1);
240
+ const e = t.filter((i) => i ? N.VALID_MODES.has(i.toLowerCase()) : !1);
241
241
  if (e.length !== 0)
242
- return new x(e);
242
+ return new N(e);
243
243
  }
244
244
  /**
245
245
  * Serializes a [PrimaryAccessMode] to its RWPM JSON representation.
@@ -248,8 +248,8 @@ const x = class x {
248
248
  return this.value;
249
249
  }
250
250
  };
251
- x.VALID_MODES = /* @__PURE__ */ new Set(["auditory", "tactile", "textual", "visual"]), x.AUDITORY = new x("auditory"), x.TACTILE = new x("tactile"), x.TEXTUAL = new x("textual"), x.VISUAL = new x("visual");
252
- let It = x;
251
+ N.VALID_MODES = /* @__PURE__ */ new Set(["auditory", "tactile", "textual", "visual"]), N.AUDITORY = new N("auditory"), N.TACTILE = new N("tactile"), N.TEXTUAL = new N("textual"), N.VISUAL = new N("visual");
252
+ let It = N;
253
253
  const l = class l {
254
254
  constructor(t) {
255
255
  this.value = t;
@@ -1066,7 +1066,7 @@ function ct(s) {
1066
1066
  function K(s) {
1067
1067
  return isNaN(s) ? void 0 : s;
1068
1068
  }
1069
- function L(s) {
1069
+ function O(s) {
1070
1070
  return K(s) !== void 0 && Math.sign(s) >= 0 ? s : void 0;
1071
1071
  }
1072
1072
  function lt(s) {
@@ -1707,14 +1707,14 @@ class U {
1707
1707
  title: t.title,
1708
1708
  rels: t.rel ? Array.isArray(t.rel) ? new Set(t.rel) : /* @__PURE__ */ new Set([t.rel]) : void 0,
1709
1709
  properties: D.deserialize(t.properties),
1710
- height: L(t.height),
1711
- width: L(t.width),
1712
- size: L(t.size),
1713
- duration: L(t.duration),
1714
- bitrate: L(t.bitrate),
1710
+ height: O(t.height),
1711
+ width: O(t.width),
1712
+ size: O(t.size),
1713
+ duration: O(t.duration),
1714
+ bitrate: O(t.bitrate),
1715
1715
  languages: F(t.language),
1716
- alternates: O.deserialize(t.alternate),
1717
- children: O.deserialize(t.children)
1716
+ alternates: x.deserialize(t.alternate),
1717
+ children: x.deserialize(t.children)
1718
1718
  });
1719
1719
  }
1720
1720
  /**
@@ -1772,7 +1772,7 @@ class U {
1772
1772
  });
1773
1773
  }
1774
1774
  }
1775
- class O {
1775
+ class x {
1776
1776
  /**
1777
1777
  * Creates a [Links].
1778
1778
  */
@@ -1784,7 +1784,7 @@ class O {
1784
1784
  */
1785
1785
  static deserialize(t) {
1786
1786
  if (t && Array.isArray(t))
1787
- return new O(
1787
+ return new x(
1788
1788
  t.map((e) => U.deserialize(e)).filter((e) => e !== void 0)
1789
1789
  );
1790
1790
  }
@@ -1937,7 +1937,7 @@ class ut {
1937
1937
  identifier: t.identifier,
1938
1938
  altIdentifiers: t.altIdentifier ? Array.isArray(t.altIdentifier) ? new Set(t.altIdentifier.map((e) => Z.deserialize(e)).filter((e) => e !== void 0)) : new Set([Z.deserialize(t.altIdentifier)].filter((e) => e !== void 0)) : void 0,
1939
1939
  roles: t.role ? new Set(F(t.role)) : void 0,
1940
- links: O.deserialize(t.links),
1940
+ links: x.deserialize(t.links),
1941
1941
  position: K(t.position)
1942
1942
  }) : void 0;
1943
1943
  }
@@ -1949,7 +1949,7 @@ class ut {
1949
1949
  return this.sortAs !== void 0 && (t.sortAs = this.sortAs.serialize()), this.identifier !== void 0 && (t.identifier = this.identifier), this.altIdentifiers && (t.altIdentifier = lt(this.altIdentifiers).map((e) => e.serialize())), this.roles && (t.role = lt(this.roles)), this.links && (t.links = this.links.serialize()), this.position !== void 0 && (t.position = this.position), t;
1950
1950
  }
1951
1951
  }
1952
- class N {
1952
+ class L {
1953
1953
  /**
1954
1954
  * Creates a [Contributors] object.
1955
1955
  */
@@ -1963,7 +1963,7 @@ class N {
1963
1963
  static deserialize(t) {
1964
1964
  if (!t) return;
1965
1965
  const e = Array.isArray(t) ? t : [t];
1966
- return new N(
1966
+ return new L(
1967
1967
  e.map((i) => ut.deserialize(i)).filter((i) => i !== void 0)
1968
1968
  );
1969
1969
  }
@@ -1986,7 +1986,7 @@ class q {
1986
1986
  if (!(t && typeof t == "object")) return;
1987
1987
  const e = /* @__PURE__ */ new Map();
1988
1988
  return Object.entries(t).forEach(([i, r]) => {
1989
- const n = N.deserialize(r);
1989
+ const n = L.deserialize(r);
1990
1990
  n && n.items.length > 0 && e.set(i, n);
1991
1991
  }), new q({ items: e });
1992
1992
  }
@@ -2023,7 +2023,7 @@ class dt {
2023
2023
  sortAs: t.sortAs ? M.deserialize(t.sortAs) : void 0,
2024
2024
  code: t.code,
2025
2025
  scheme: t.scheme,
2026
- links: O.deserialize(t.links)
2026
+ links: x.deserialize(t.links)
2027
2027
  }) : void 0;
2028
2028
  }
2029
2029
  /**
@@ -2092,7 +2092,7 @@ const tt = class tt {
2092
2092
  */
2093
2093
  static deserialize(t) {
2094
2094
  if (!(t && t.title)) return;
2095
- const e = M.deserialize(t.title), i = t["@type"], r = F(t.conformsTo), n = t.identifier, a = Z.deserialize(t.altIdentifier), o = M.deserialize(t.subtitle), h = M.deserialize(t.sortAs), m = N.deserialize(t.artist), p = N.deserialize(t.author), u = N.deserialize(t.colorist), g = N.deserialize(t.contributor), v = N.deserialize(t.editor), C = N.deserialize(t.illustrator), d = N.deserialize(t.inker), I = N.deserialize(t.letterer), B = N.deserialize(t.narrator), Me = N.deserialize(t.penciler), Be = N.deserialize(t.translator), Ge = F(t.language), We = t.description, He = N.deserialize(t.publisher), Fe = N.deserialize(t.imprint), _e = ct(t.published), Ve = ct(t.modified), Ye = Vt.deserialize(t.subject), $e = q.deserialize(t.belongsTo), Xe = _.deserialize(t.accessibility), Ke = t.layout, Ze = t.readingProgression, Je = L(t.duration), qe = L(t.numberOfPages), Qe = Yt.deserialize(t.tdm);
2095
+ const e = M.deserialize(t.title), i = t["@type"], r = F(t.conformsTo), n = t.identifier, a = Z.deserialize(t.altIdentifier), o = M.deserialize(t.subtitle), h = M.deserialize(t.sortAs), m = L.deserialize(t.artist), p = L.deserialize(t.author), u = L.deserialize(t.colorist), g = L.deserialize(t.contributor), v = L.deserialize(t.editor), C = L.deserialize(t.illustrator), d = L.deserialize(t.inker), I = L.deserialize(t.letterer), B = L.deserialize(t.narrator), Me = L.deserialize(t.penciler), Be = L.deserialize(t.translator), Ge = F(t.language), We = t.description, He = L.deserialize(t.publisher), Fe = L.deserialize(t.imprint), _e = ct(t.published), Ve = ct(t.modified), Ye = Vt.deserialize(t.subject), $e = q.deserialize(t.belongsTo), Xe = _.deserialize(t.accessibility), Ke = t.layout, Ze = t.readingProgression, Je = O(t.duration), qe = O(t.numberOfPages), Qe = Yt.deserialize(t.tdm);
2096
2096
  let at = Object.assign({}, t);
2097
2097
  return tt.mappedProperties.forEach((je) => delete at[je]), Object.keys(at).length === 0 && (at = void 0), new tt({
2098
2098
  title: e,
@@ -2242,7 +2242,7 @@ class $t {
2242
2242
  static deserialize(t) {
2243
2243
  if (t)
2244
2244
  return new $t({
2245
- links: O.deserialize(t.links),
2245
+ links: x.deserialize(t.links),
2246
2246
  guided: X.deserializeArray(t.guided)
2247
2247
  });
2248
2248
  }
@@ -2907,10 +2907,10 @@ class mt {
2907
2907
  */
2908
2908
  static deserialize(t) {
2909
2909
  if (!(t && t.cssSelector)) return;
2910
- let e = L(t.textNodeIndex);
2910
+ let e = O(t.textNodeIndex);
2911
2911
  if (e === void 0) return;
2912
- let i = L(t.charOffset);
2913
- return i === void 0 && (i = L(t.offset)), new mt({
2912
+ let i = O(t.charOffset);
2913
+ return i === void 0 && (i = O(t.offset)), new mt({
2914
2914
  cssSelector: t.cssSelector,
2915
2915
  textNodeIndex: e,
2916
2916
  charOffset: i
@@ -2995,6 +2995,10 @@ T.prototype.space = function() {
2995
2995
  if (t.length === 4 && !t.some(isNaN))
2996
2996
  return t;
2997
2997
  };
2998
+ T.prototype.text = function() {
2999
+ const s = this.fragmentParameters();
3000
+ console.log(s);
3001
+ };
2998
3002
  class Kt {
2999
3003
  /** Creates a [Price]. */
3000
3004
  constructor(t) {
@@ -3008,7 +3012,7 @@ class Kt {
3008
3012
  let e = t.currency;
3009
3013
  if (!(e && typeof e == "string" && e.length > 0))
3010
3014
  return;
3011
- let i = L(t.value);
3015
+ let i = O(t.value);
3012
3016
  if (i !== void 0)
3013
3017
  return new Kt({ currency: e, value: i });
3014
3018
  }
@@ -3057,8 +3061,8 @@ class Zt {
3057
3061
  static deserialize(t) {
3058
3062
  if (t)
3059
3063
  return new Zt({
3060
- total: L(t.total),
3061
- position: L(t.position)
3064
+ total: O(t.total),
3065
+ position: O(t.position)
3062
3066
  });
3063
3067
  }
3064
3068
  /**
@@ -3080,8 +3084,8 @@ class Jt {
3080
3084
  static deserialize(t) {
3081
3085
  if (t)
3082
3086
  return new Jt({
3083
- total: L(t.total),
3084
- available: L(t.available)
3087
+ total: O(t.total),
3088
+ available: O(t.available)
3085
3089
  });
3086
3090
  }
3087
3091
  /**
@@ -3118,7 +3122,7 @@ class qt {
3118
3122
  }
3119
3123
  }
3120
3124
  D.prototype.getNumberOfItems = function() {
3121
- return L(this.otherProperties.numberOfItems);
3125
+ return O(this.otherProperties.numberOfItems);
3122
3126
  };
3123
3127
  D.prototype.getPrice = function() {
3124
3128
  return Kt.deserialize(this.otherProperties.price);
@@ -4273,7 +4277,7 @@ class js {
4273
4277
  h.length > 0 && (o = new U({
4274
4278
  href: h[0].href,
4275
4279
  type: h[0].type,
4276
- alternates: h.length > 1 ? new O(h.slice(1)) : void 0
4280
+ alternates: h.length > 1 ? new x(h.slice(1)) : void 0
4277
4281
  }));
4278
4282
  }
4279
4283
  o && (r === "AUDIO" ? this.elementRecipes.push({
@@ -4398,7 +4402,7 @@ class De {
4398
4402
  * Creates a [LocatorCollection].
4399
4403
  */
4400
4404
  constructor(t) {
4401
- this.metadata = t.metadata ?? new At({}), this.links = t.links ?? new O([]), this.locators = t.locators ?? [];
4405
+ this.metadata = t.metadata ?? new At({}), this.links = t.links ?? new x([]), this.locators = t.locators ?? [];
4402
4406
  }
4403
4407
  /**
4404
4408
  * Parses a [LocatorCollection] from its RWPM JSON representation.
@@ -4408,7 +4412,7 @@ class De {
4408
4412
  let e, i = t.locators;
4409
4413
  return i && Array.isArray(i) && (e = i.map((r) => k.deserialize(r)).filter((r) => r !== void 0)), new De({
4410
4414
  metadata: At.deserialize(t.metadata),
4411
- links: O.deserialize(t.links),
4415
+ links: x.deserialize(t.links),
4412
4416
  locators: e
4413
4417
  });
4414
4418
  }
@@ -4438,9 +4442,9 @@ class W {
4438
4442
  if (!t) return;
4439
4443
  let e, i, r;
4440
4444
  if (Array.isArray(t))
4441
- e = O.deserialize(t);
4445
+ e = x.deserialize(t);
4442
4446
  else if (typeof t == "object")
4443
- e = O.deserialize(t.links), i = /* @__PURE__ */ new Map(), t.metadata && Object.entries(t.metadata).forEach(([n, a]) => {
4447
+ e = x.deserialize(t.links), i = /* @__PURE__ */ new Map(), t.metadata && Object.entries(t.metadata).forEach(([n, a]) => {
4444
4448
  i?.set(n, a);
4445
4449
  }), r = W.deserializeCollections(t);
4446
4450
  else
@@ -4493,7 +4497,7 @@ class W {
4493
4497
  }
4494
4498
  class Ue {
4495
4499
  constructor(t) {
4496
- this.context = t.context, this.metadata = t.metadata, this.links = t.links, this.readingOrder = t.readingOrder, this.resources = t.resources, this.toc = t.toc, this.subcollections = t.subcollections;
4500
+ this.context = t.context, this.metadata = t.metadata, this.links = t.links || new x([]), this.readingOrder = t.readingOrder, this.resources = t.resources, this.toc = t.toc, this.subcollections = t.subcollections;
4497
4501
  }
4498
4502
  /**
4499
4503
  * Parses a [Publication] from its RWPM JSON representation.
@@ -4505,19 +4509,17 @@ class Ue {
4505
4509
  if (!t) return;
4506
4510
  const e = ft.deserialize(t.metadata);
4507
4511
  if (!e) return;
4508
- const i = O.deserialize(t.links);
4509
- if (!i) return;
4510
- const r = O.deserialize(
4512
+ const i = x.deserialize(
4511
4513
  t.readingOrder ? t.readingOrder : t.spine
4512
4514
  );
4513
- if (r)
4515
+ if (i)
4514
4516
  return new Ue({
4515
4517
  context: F(t["@context"]),
4516
4518
  metadata: e,
4517
- links: i,
4518
- readingOrder: r,
4519
- resources: O.deserialize(t.resources),
4520
- toc: O.deserialize(t.toc),
4519
+ links: x.deserialize(t.links),
4520
+ readingOrder: i,
4521
+ resources: x.deserialize(t.resources),
4522
+ toc: x.deserialize(t.toc),
4521
4523
  subcollections: W.deserializeCollections({
4522
4524
  sub: t.sub
4523
4525
  })
@@ -4528,12 +4530,12 @@ class Ue {
4528
4530
  */
4529
4531
  serialize() {
4530
4532
  const t = {};
4531
- 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.toc && (t.toc = this.toc.serialize()), W.serializeCollection(t, this.subcollections), t;
4533
+ return this.context !== void 0 && (t["@context"] = this.context), t.metadata = this.metadata.serialize(), this.links?.items.length > 0 && (t.links = this.links.serialize()), t.readingOrder = this.readingOrder.serialize(), this.resources && (t.resources = this.resources.serialize()), this.toc && (t.toc = this.toc.serialize()), W.serializeCollection(t, this.subcollections), t;
4532
4534
  }
4533
4535
  /** Finds the first link with the given relation in the manifest's links. */
4534
4536
  linkWithRel(t) {
4535
4537
  const e = new Array();
4536
- e.push(this.readingOrder), this.resources && e.push(this.resources), e.push(this.links);
4538
+ e.push(this.readingOrder), this.resources && e.push(this.resources), this.links && e.push(this.links);
4537
4539
  let i;
4538
4540
  for (const r of e)
4539
4541
  if (i = r.findWithRel(t), i !== void 0)
@@ -4543,7 +4545,7 @@ class Ue {
4543
4545
  /** Finds all the links with the given relation in the manifest's links. */
4544
4546
  linksWithRel(t) {
4545
4547
  const e = [];
4546
- return e.push(this.readingOrder.filterByRel(t)), this.resources && e.push(this.resources.filterByRel(t)), e.push(this.links.filterByRel(t)), e.reduce((i, r) => i.concat(r), []);
4548
+ return e.push(this.readingOrder.filterByRel(t)), this.resources && e.push(this.resources.filterByRel(t)), this.links && e.push(this.links.filterByRel(t)), e.reduce((i, r) => i.concat(r), []);
4547
4549
  }
4548
4550
  /**
4549
4551
  * Creates a new [Locator] object from a [Link] to a resource of this manifest.
@@ -4580,7 +4582,7 @@ class Ue {
4580
4582
  m.push(...u);
4581
4583
  }), m.length > 0 && (h = e(m)), h;
4582
4584
  }, i = [];
4583
- i.push(this.readingOrder), this.resources && i.push(this.resources), i.push(this.links);
4585
+ i.push(this.readingOrder), this.resources && i.push(this.resources), this.links && i.push(this.links);
4584
4586
  const r = e(i);
4585
4587
  if (r !== void 0)
4586
4588
  return r;
@@ -4642,7 +4644,7 @@ export {
4642
4644
  nr as Content,
4643
4645
  me as ContentElement,
4644
4646
  ut as Contributor,
4645
- N as Contributors,
4647
+ L as Contributors,
4646
4648
  Jt as Copies,
4647
4649
  Ri as DefaultTextContentTokenizer,
4648
4650
  Xt as DomRange,
@@ -4670,7 +4672,7 @@ export {
4670
4672
  $ as Layout,
4671
4673
  Wt as Legal,
4672
4674
  U as Link,
4673
- O as Links,
4675
+ x as Links,
4674
4676
  f as Localization,
4675
4677
  M as LocalizedString,
4676
4678
  k as Locator,
@@ -4720,7 +4722,7 @@ export {
4720
4722
  ct as datefromJSON,
4721
4723
  rr as leadingPage,
4722
4724
  K as numberfromJSON,
4723
- L as positiveNumberfromJSON,
4725
+ O as positiveNumberfromJSON,
4724
4726
  lt as setToArray,
4725
4727
  fe as speakableToken
4726
4728
  };