@prose-reader/core 1.276.0 → 1.277.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { Report as Sn, isShallowEqual as V, shallowMergeIfDefined as Ce, getPare
3
3
  import { isShallowEqual as Ps } from "@prose-reader/shared";
4
4
  import { switchMap as Y, first as wn, map as ie, distinctUntilChanged as we, startWith as Pn, shareReplay as Qe, tap as j, pairwise as xn, take as $n, takeUntil as K, filter as he, debounceTime as Tn, skip as At, mergeMap as Fn, catchError as ut, share as Cn } from "rxjs/operators";
5
5
  import { generate as Xe, parse as Dt, isIndirectionOnly as Ln, isParsedCfiRange as Mn, resolve as En } from "@prose-reader/cfi";
6
- const Nn = "@prose-reader/core", N = Sn.namespace(Nn, void 0, {
6
+ const Nn = "@prose-reader/core", E = Sn.namespace(Nn, void 0, {
7
7
  color: "#98cde7"
8
8
  }), An = [
9
9
  "pointercancel",
@@ -79,7 +79,7 @@ const Vn = (n, e) => {
79
79
  try {
80
80
  e <= (t?.endOffset || 0) && t?.setStart(n, e || 0);
81
81
  } catch (i) {
82
- N.error(i);
82
+ E.error(i);
83
83
  }
84
84
  return t;
85
85
  }
@@ -147,7 +147,7 @@ const Vn = (n, e) => {
147
147
  try {
148
148
  return Array.from(i.cssRules || []);
149
149
  } catch (s) {
150
- return N.warn(`Error getting rules for sheet: ${i.href}`, s), [];
150
+ return E.warn(`Error getting rules for sheet: ${i.href}`, s), [];
151
151
  }
152
152
  })();
153
153
  for (const s of r)
@@ -727,7 +727,7 @@ const Ee = class Ee extends Q {
727
727
  w(() => (this.hookManager.destroy("item.onDocumentLoad", this.item.id), Be(() => this.onUnload()).pipe(
728
728
  Se(null),
729
729
  U(),
730
- $e((s) => (N.error("Error unloading document", s), v(null)))
730
+ $e((s) => (E.error("Error unloading document", s), v(null)))
731
731
  ))),
732
732
  S(() => {
733
733
  this.next({ state: "idle", error: void 0 });
@@ -783,7 +783,7 @@ const Ee = class Ee extends Q {
783
783
  ye(() => {
784
784
  e.complete();
785
785
  }),
786
- $e((t) => (N.error(t), v(void 0)))
786
+ $e((t) => (E.error(t), v(void 0)))
787
787
  );
788
788
  }
789
789
  layout(e) {
@@ -1003,10 +1003,10 @@ const zt = (n, e) => {
1003
1003
  }
1004
1004
  }),
1005
1005
  S(() => o),
1006
- $e((a) => (N.error(
1006
+ $e((a) => (E.error(
1007
1007
  `Error while trying to fetch or load resource for item ${n.id}`,
1008
1008
  r
1009
- ), N.error(a), v(o)))
1009
+ ), E.error(a), v(o)))
1010
1010
  ))
1011
1011
  ))
1012
1012
  );
@@ -1434,7 +1434,7 @@ class st {
1434
1434
  this.left = e.left, this.right = e.right, this.top = e.top, this.bottom = e.bottom, this.width = e.width, this.height = e.height, this.x = e.x, this.y = e.y;
1435
1435
  }
1436
1436
  }
1437
- class E {
1437
+ class N {
1438
1438
  constructor(e) {
1439
1439
  this.__symbol = /* @__PURE__ */ Symbol("SpineItemPosition"), this.x = e.x, this.y = e.y;
1440
1440
  }
@@ -1892,18 +1892,18 @@ const Wi = (n) => (e) => {
1892
1892
  (s) => s.href === o
1893
1893
  ) && e.goToUrl(i);
1894
1894
  })
1895
- ), ee = N.namespace("navigation"), _i = ({
1895
+ ), ee = E.namespace("navigation"), _i = ({
1896
1896
  position: n,
1897
1897
  spineItem: e,
1898
1898
  pageHeight: t,
1899
1899
  pageWidth: i,
1900
1900
  spineItemLocator: o
1901
1901
  }) => {
1902
- let r = new E({
1902
+ let r = new N({
1903
1903
  x: n.x - i,
1904
1904
  y: n.y
1905
1905
  });
1906
- return e.isUsingVerticalWriting() && (r = new E({
1906
+ return e.isUsingVerticalWriting() && (r = new N({
1907
1907
  x: n.x,
1908
1908
  y: n.y + t
1909
1909
  })), o.getSpineItemClosestPositionFromUnsafePosition(
@@ -1997,11 +1997,11 @@ const Wi = (n) => (e) => {
1997
1997
  pageWidth: i,
1998
1998
  spineItemLocator: o
1999
1999
  }) => {
2000
- let r = new E({
2000
+ let r = new N({
2001
2001
  x: n.x + i,
2002
2002
  y: n.y
2003
2003
  });
2004
- return e.isUsingVerticalWriting() && (r = new E({
2004
+ return e.isUsingVerticalWriting() && (r = new N({
2005
2005
  x: n.x,
2006
2006
  y: n.y - t
2007
2007
  })), o.getSpineItemClosestPositionFromUnsafePosition(
@@ -2528,7 +2528,7 @@ const Ki = (n) => n.pagination.state$.pipe(
2528
2528
  spineItem: o
2529
2529
  };
2530
2530
  } catch (a) {
2531
- return N.warn(`Error resolving cfi: ${n}.`), N.warn(a), {
2531
+ return E.warn(`Error resolving cfi: ${n}.`), E.warn(a), {
2532
2532
  ...i,
2533
2533
  spineItem: o,
2534
2534
  itemIndex: t,
@@ -2651,7 +2651,7 @@ class ro {
2651
2651
  ) : this.locate(e, t ?? {});
2652
2652
  }
2653
2653
  }
2654
- const so = N.namespace("spine"), ao = ({
2654
+ const so = E.namespace("spine"), ao = ({
2655
2655
  position: n,
2656
2656
  pageSize: e
2657
2657
  }) => new Fi({
@@ -3137,8 +3137,7 @@ const be = (n) => {
3137
3137
  ...l
3138
3138
  })),
3139
3139
  R(V),
3140
- mn(5),
3141
- x((u) => console.warn("paginationInfo", u))
3140
+ mn(5)
3142
3141
  );
3143
3142
  }, Do = (n) => (e) => {
3144
3143
  const t = n(e), i = new q({
@@ -3156,7 +3155,7 @@ const be = (n) => {
3156
3155
  endChapterInfo: void 0,
3157
3156
  endSpineItemReadingDirection: void 0,
3158
3157
  percentageEstimateOfBook: 0
3159
- }), o = new ro(t), r = Ao(t).subscribe(i);
3158
+ }), o = new ro(t), r = Ao(t).pipe(x((s) => E.log("Pagination", s))).subscribe(i);
3160
3159
  return {
3161
3160
  ...t,
3162
3161
  locateResource: o.locateResource.bind(o),
@@ -3260,7 +3259,7 @@ const be = (n) => {
3260
3259
  fn([ze("prose-reader"), k(d.blob())])
3261
3260
  ).pipe(
3262
3261
  Y(([l, p]) => k(l.put(`${e}_${u.id}`, p))),
3263
- ut((l) => (N.error(l), H))
3262
+ ut((l) => (E.error(l), H))
3264
3263
  ) : H;
3265
3264
  }),
3266
3265
  K(n.destroy$)
@@ -3271,7 +3270,7 @@ const be = (n) => {
3271
3270
  })
3272
3271
  );
3273
3272
  return P(s).pipe(
3274
- Y(() => (N.debug("Cleanup up old cache..."), k(ze("prose-reader")).pipe(
3273
+ Y(() => (E.debug("Cleanup up old cache..."), k(ze("prose-reader")).pipe(
3275
3274
  Y(
3276
3275
  (c) => k(c.keys()).pipe(
3277
3276
  ie(
@@ -3283,7 +3282,7 @@ const be = (n) => {
3283
3282
  })
3284
3283
  )
3285
3284
  ),
3286
- ut((c) => (N.error(c), H))
3285
+ ut((c) => (E.error(c), H))
3287
3286
  ))),
3288
3287
  K(n.destroy$)
3289
3288
  ).subscribe(), {
@@ -3318,7 +3317,7 @@ const be = (n) => {
3318
3317
  t.setStart(n.node, o), t.setEnd(n.node, r);
3319
3318
  }
3320
3319
  } catch (o) {
3321
- N.warn("Failed to create range from selection", o, {
3320
+ E.warn("Failed to create range from selection", o, {
3322
3321
  anchor: n,
3323
3322
  focus: e
3324
3323
  });
@@ -3337,7 +3336,7 @@ const be = (n) => {
3337
3336
  { node: o, offset: r }
3338
3337
  );
3339
3338
  } catch (s) {
3340
- N.warn("Failed to create range from selection", s, {
3339
+ E.warn("Failed to create range from selection", s, {
3341
3340
  selection: n,
3342
3341
  spineItem: e
3343
3342
  });
@@ -4025,7 +4024,7 @@ const rr = "[data-prose-reader-scroll-navigator]{height:100%;width:100%;position
4025
4024
  }) : new L({
4026
4025
  x: -n.x,
4027
4026
  y: -n.y
4028
- }), cr = "navigation/ViewportNavigator", Pt = N.namespace(cr);
4027
+ }), cr = "navigation/ViewportNavigator", Pt = E.namespace(cr);
4029
4028
  class ur extends G {
4030
4029
  constructor(e, t, i, o, r) {
4031
4030
  super(), this.settings = e, this.hookManager = t, this.context = i, this.spine = o, this.viewport = r, this.navigateSubject = new O(), this.element$ = new q(
@@ -4505,7 +4504,7 @@ const Sr = ({
4505
4504
  return g;
4506
4505
  }
4507
4506
  if (c && l && e.directionFromLastNavigation === "backward") {
4508
- const g = new E({
4507
+ const g = new N({
4509
4508
  x: (e.positionInSpineItem?.x ?? 0) + d,
4510
4509
  y: (e.positionInSpineItem?.y ?? 0) + u
4511
4510
  });
@@ -4542,7 +4541,7 @@ const Sr = ({
4542
4541
  const { height: c, top: d } = r.getSpineItemSpineLayoutInfo(a), u = e.isPositionWithinSpineItem(
4543
4542
  n.position,
4544
4543
  a
4545
- ), l = n.positionInSpineItem ?? new E({
4544
+ ), l = n.positionInSpineItem ?? new N({
4546
4545
  y: 0,
4547
4546
  x: 0
4548
4547
  });
@@ -4553,7 +4552,7 @@ const Sr = ({
4553
4552
  return o.getNavigationForSpineIndexOrId(a);
4554
4553
  if (d !== n.spineItemTop) {
4555
4554
  const p = e.getSafeSpineItemPositionFromUnsafeSpineItemPosition(
4556
- n.positionInSpineItem ?? new E({
4555
+ n.positionInSpineItem ?? new N({
4557
4556
  x: 0,
4558
4557
  y: 0
4559
4558
  }),
@@ -4565,7 +4564,7 @@ const Sr = ({
4565
4564
  });
4566
4565
  }
4567
4566
  if (d === n.spineItemTop && c !== n.spineItemHeight) {
4568
- const p = (n.spineItemHeight ?? l.y) - l.y, g = new E({
4567
+ const p = (n.spineItemHeight ?? l.y) - l.y, g = new N({
4569
4568
  y: n.directionFromLastNavigation === "backward" ? c - p : l.y,
4570
4569
  x: n.position.x
4571
4570
  });
@@ -4581,7 +4580,7 @@ const Sr = ({
4581
4580
  }
4582
4581
  if (!u) {
4583
4582
  if (!(n.position.y < d)) {
4584
- const m = new E({
4583
+ const m = new N({
4585
4584
  y: c - p,
4586
4585
  x: n.position.x
4587
4586
  });
@@ -4643,7 +4642,7 @@ const Sr = ({
4643
4642
  }
4644
4643
  }))
4645
4644
  ))
4646
- ), vr = "navigation/InternalNavigator", wr = N.namespace(vr);
4645
+ ), vr = "navigation/InternalNavigator", wr = E.namespace(vr);
4647
4646
  class Pr extends G {
4648
4647
  constructor(e, t, i, o, r, s, a, c) {
4649
4648
  super(), this.settings = e, this.context = t, this.userNavigation$ = i, this.controlledNavigationController = o, this.scrollNavigationController = r, this.navigationResolver = s, this.spine = a, this.isRestorationLocked$ = c, this.navigationSubject = new q({
@@ -4890,7 +4889,7 @@ const Me = (n, e, t) => {
4890
4889
  itemWidth: n,
4891
4890
  itemHeight: e,
4892
4891
  spineItemPosition: t
4893
- }) => new E({
4892
+ }) => new N({
4894
4893
  x: Math.min(n, Math.max(0, t.x)),
4895
4894
  y: Math.min(e, Math.max(0, t.y))
4896
4895
  }), Qt = ({
@@ -4942,7 +4941,7 @@ const Me = (n, e, t) => {
4942
4941
  n,
4943
4942
  e.height
4944
4943
  );
4945
- return new E({
4944
+ return new N({
4946
4945
  x: 0,
4947
4946
  y: s
4948
4947
  });
@@ -4952,10 +4951,10 @@ const Me = (n, e, t) => {
4952
4951
  n,
4953
4952
  e.width
4954
4953
  );
4955
- return t.isRTL() ? new E({
4954
+ return t.isRTL() ? new N({
4956
4955
  x: e.width - r - o.pageSize.width,
4957
4956
  y: 0
4958
- }) : new E({
4957
+ }) : new N({
4959
4958
  x: r,
4960
4959
  y: 0
4961
4960
  });
@@ -4974,7 +4973,7 @@ const Me = (n, e, t) => {
4974
4973
  p,
4975
4974
  l
4976
4975
  );
4977
- return new E({ x: g, y: 0 });
4976
+ return new N({ x: g, y: 0 });
4978
4977
  }
4979
4978
  };
4980
4979
  return {
@@ -5013,7 +5012,7 @@ const Me = (n, e, t) => {
5013
5012
  },
5014
5013
  getSpineItemClosestPositionFromUnsafePosition: (a, c) => {
5015
5014
  const { width: d, height: u } = c.layoutInfo;
5016
- return new E({
5015
+ return new N({
5017
5016
  x: He(
5018
5017
  a.x,
5019
5018
  t.pageSize.width,
@@ -5079,7 +5078,7 @@ const Me = (n, e, t) => {
5079
5078
  c,
5080
5079
  d,
5081
5080
  a
5082
- ) || new E({ x: 0, y: 0 })
5081
+ ) || new N({ x: 0, y: 0 })
5083
5082
  };
5084
5083
  };
5085
5084
  function tn({
@@ -5199,10 +5198,20 @@ const Lt = ({
5199
5198
  visibleAreaRectWidth: r.absoluteViewport.width
5200
5199
  });
5201
5200
  }, Cr = (n, e) => {
5202
- if (e && e instanceof HTMLIFrameElement)
5203
- return n.startsWith("#") ? e.contentDocument?.getElementById(
5204
- n.replace("#", "")
5205
- ) : e.contentDocument?.querySelector(n);
5201
+ if (e && e instanceof HTMLIFrameElement) {
5202
+ const t = e.contentDocument, i = n.trim();
5203
+ if (!t || i.length === 0)
5204
+ return;
5205
+ if (i.startsWith("#")) {
5206
+ const o = i.slice(1);
5207
+ return o.length === 0 ? void 0 : t.getElementById(o);
5208
+ }
5209
+ try {
5210
+ return t.querySelector(i);
5211
+ } catch {
5212
+ return;
5213
+ }
5214
+ }
5206
5215
  }, Lr = ({
5207
5216
  anchor: n,
5208
5217
  spineItem: e,
@@ -5225,7 +5234,7 @@ const Lt = ({
5225
5234
  spine: i
5226
5235
  });
5227
5236
  return t.getSpinePositionFromSpineItemPosition({
5228
- spineItemPosition: new E({ x: o, y: 0 }),
5237
+ spineItemPosition: new N({ x: o, y: 0 }),
5229
5238
  spineItem: e
5230
5239
  });
5231
5240
  }, Er = ({
@@ -5347,10 +5356,10 @@ const Lt = ({
5347
5356
  spineItemsManager: e
5348
5357
  });
5349
5358
  if (!h) {
5350
- N.warn(Dr, `unable to detect item id from cfi ${g}`);
5359
+ E.warn(Dr, `unable to detect item id from cfi ${g}`);
5351
5360
  return;
5352
5361
  }
5353
- const y = m ? s.getNavigationFromNode(h, m, f) : new E({ x: 0, y: 0 }), I = t.getSpinePositionFromSpineItemPosition({
5362
+ const y = m ? s.getNavigationFromNode(h, m, f) : new N({ x: 0, y: 0 }), I = t.getSpinePositionFromSpineItemPosition({
5354
5363
  spineItemPosition: y,
5355
5364
  spineItem: h
5356
5365
  });
@@ -5489,7 +5498,7 @@ const Lt = ({
5489
5498
  locker: c,
5490
5499
  navigationState$: g,
5491
5500
  navigate: (f) => {
5492
- s.next(f);
5501
+ E.info("User navigation", f), s.next(f);
5493
5502
  },
5494
5503
  /**
5495
5504
  * Prevent further navigation until the lock is released.
@@ -5671,7 +5680,7 @@ class zr extends Ur {
5671
5680
  manifest: t
5672
5681
  })
5673
5682
  };
5674
- return t?.renditionFlow === "scrolled-continuous" && (o.computedPageTurnMode = "scrollable"), o.computedPageTurnMode === "scrollable" && (o.computedPageTurnDirection = "vertical"), i && o.computedPageTurnAnimation === "slide" && (N.warn(
5683
+ return t?.renditionFlow === "scrolled-continuous" && (o.computedPageTurnMode = "scrollable"), o.computedPageTurnMode === "scrollable" && (o.computedPageTurnDirection = "vertical"), i && o.computedPageTurnAnimation === "slide" && (E.warn(
5675
5684
  `pageTurnAnimation ${o.computedPageTurnAnimation} incompatible with current book, switching back to default`
5676
5685
  ), o.computedPageTurnAnimation = "none"), o.computedPageTurnMode === "scrollable" ? (o.computedPageTurnAnimationDuration = 0, o.computedPageTurnAnimation = "none") : o.computedPageTurnAnimationDuration = e.pageTurnAnimationDuration !== void 0 ? e.pageTurnAnimationDuration : 300, o;
5677
5686
  }
@@ -6188,7 +6197,7 @@ const qr = ({
6188
6197
  }) => {
6189
6198
  const s = (h, m) => {
6190
6199
  const { left: f, top: y } = o.getSpineItemSpineLayoutInfo(m);
6191
- return new E({
6200
+ return new N({
6192
6201
  /**
6193
6202
  * when using spread the item could be on the right and therefore will be negative
6194
6203
  * @example
@@ -6200,7 +6209,7 @@ const qr = ({
6200
6209
  y: Math.max(h.y - y, 0)
6201
6210
  });
6202
6211
  }, a = (h) => _e({
6203
- spineItemPosition: new E({ x: 0, y: 0 }),
6212
+ spineItemPosition: new N({ x: 0, y: 0 }),
6204
6213
  itemLayout: o.getSpineItemSpineLayoutInfo(h)
6205
6214
  }), c = (h) => n.items.find((m) => m.renderer.getDocumentFrame() === h), d = (h, m, f) => {
6206
6215
  if (typeof f == "number") {
@@ -6340,7 +6349,7 @@ const qr = ({
6340
6349
  spineItemLocator: t,
6341
6350
  getSafeSpineItemPositionFromUnsafeSpineItemPosition: (h, m) => {
6342
6351
  const { height: f, width: y } = o.getSpineItemSpineLayoutInfo(m);
6343
- return new E({
6352
+ return new N({
6344
6353
  x: Math.min(Math.max(0, h.x), y),
6345
6354
  y: Math.min(Math.max(0, h.y), f)
6346
6355
  });
@@ -6748,10 +6757,10 @@ const Mt = `${Wt}-core`, os = (n) => {
6748
6757
  }, f = ($) => {
6749
6758
  const { containerElement: C, manifest: _ } = $;
6750
6759
  if (r.manifest) {
6751
- N.warn("loading a new book is not supported yet");
6760
+ E.warn("loading a new book is not supported yet");
6752
6761
  return;
6753
6762
  }
6754
- N.log("load", { options: $ });
6763
+ E.log("load", { options: $ });
6755
6764
  const B = rs(C, e);
6756
6765
  r.update({
6757
6766
  manifest: _,
@@ -6885,7 +6894,7 @@ export {
6885
6894
  nn as SpineItem,
6886
6895
  Ti as SpineItemPageLayout,
6887
6896
  Fi as SpineItemPageSpineLayout,
6888
- E as SpineItemPosition,
6897
+ N as SpineItemPosition,
6889
6898
  Ue as SpineItemSpineLayout,
6890
6899
  ns as SpineItemsManager,
6891
6900
  Qr as SpineItemsObserver,