@prose-reader/core 1.57.0 → 1.59.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 (100) hide show
  1. package/dist/cfi.d.ts +74 -0
  2. package/dist/constants.d.ts +6 -0
  3. package/dist/context/Context.d.ts +63 -0
  4. package/dist/context/isUsingSpreadMode.d.ts +10 -0
  5. package/dist/createReaderWithEnhancer.d.ts +268 -0
  6. package/dist/enhancers/accessibility.d.ts +3 -0
  7. package/dist/enhancers/chrome.d.ts +3 -0
  8. package/dist/enhancers/events/createIframeEventBridgeElement.d.ts +1 -0
  9. package/dist/enhancers/events/events.d.ts +8 -0
  10. package/dist/enhancers/events/normalizeEventForViewport.d.ts +7 -0
  11. package/dist/enhancers/firefox.d.ts +3 -0
  12. package/dist/enhancers/fonts.d.ts +19 -0
  13. package/dist/enhancers/hotkeys.d.ts +3 -0
  14. package/dist/enhancers/layoutEnhancer/createMovingSafePan$.d.ts +4 -0
  15. package/dist/enhancers/layoutEnhancer/fixReflowable.d.ts +3 -0
  16. package/dist/enhancers/layoutEnhancer/layoutEnhancer.d.ts +10 -0
  17. package/dist/enhancers/layoutEnhancer/types.d.ts +8 -0
  18. package/dist/enhancers/links.d.ts +14 -0
  19. package/dist/enhancers/loadingEnhancer.d.ts +24 -0
  20. package/dist/enhancers/media.d.ts +3 -0
  21. package/dist/enhancers/navigation/navigation.d.ts +9 -0
  22. package/dist/enhancers/navigation/navigator.d.ts +8 -0
  23. package/dist/enhancers/navigation/state.d.ts +12 -0
  24. package/dist/enhancers/pagination/chapters.d.ts +24 -0
  25. package/dist/enhancers/pagination/constants.d.ts +1 -0
  26. package/dist/enhancers/pagination/enhancer.d.ts +14 -0
  27. package/dist/enhancers/pagination/pagination.d.ts +10 -0
  28. package/dist/enhancers/pagination/spine.d.ts +13 -0
  29. package/dist/enhancers/pagination/types.d.ts +19 -0
  30. package/dist/enhancers/pagination.test.d.ts +1 -0
  31. package/dist/enhancers/progression.d.ts +16 -0
  32. package/dist/enhancers/publicApi.d.ts +5 -0
  33. package/dist/enhancers/resources/index.d.ts +3 -0
  34. package/dist/enhancers/resources/indexedDB.d.ts +6 -0
  35. package/dist/enhancers/resources/resourcesManager.d.ts +7 -0
  36. package/dist/enhancers/theme.d.ts +32 -0
  37. package/dist/enhancers/types/enhancer.d.ts +9 -0
  38. package/dist/enhancers/utils.d.ts +7 -0
  39. package/dist/enhancers/webkit.d.ts +3 -0
  40. package/dist/enhancers/zoom/elementZoomer.d.ts +19 -0
  41. package/dist/enhancers/zoom/index.d.ts +4 -0
  42. package/dist/enhancers/zoom/types.d.ts +23 -0
  43. package/dist/enhancers/zoom/viewportZoomer.d.ts +19 -0
  44. package/dist/frames.d.ts +5 -0
  45. package/dist/hooks/HookManager.d.ts +10 -0
  46. package/dist/hooks/types.d.ts +64 -0
  47. package/dist/index.d.ts +9 -4262
  48. package/dist/index.js +225 -255
  49. package/dist/index.js.map +1 -1
  50. package/dist/index.umd.cjs +225 -255
  51. package/dist/index.umd.cjs.map +1 -1
  52. package/dist/manifest/areAllItemsPrePaginated.d.ts +3 -0
  53. package/dist/manifest/isFullyPrePaginated.d.ts +3 -0
  54. package/dist/pagination/pagination.d.ts +88 -0
  55. package/dist/pagination/types.d.ts +10 -0
  56. package/dist/reader.d.ts +8 -0
  57. package/dist/report.d.ts +26 -0
  58. package/dist/selection.d.ts +7 -0
  59. package/dist/settings/SettingsManager.d.ts +14 -0
  60. package/dist/settings/defaultSettings.d.ts +3 -0
  61. package/dist/settings/getComputedSettings.d.ts +4 -0
  62. package/dist/settings/types.d.ts +19 -0
  63. package/dist/spine/cfiLocator.d.ts +340 -0
  64. package/dist/spine/createSpine.d.ts +31 -0
  65. package/dist/spine/locationResolver.d.ts +636 -0
  66. package/dist/spine/navigationResolver.d.ts +48 -0
  67. package/dist/spine/types.d.ts +10 -0
  68. package/dist/spineItem/commonSpineItem.d.ts +165 -0
  69. package/dist/spineItem/createSpineItem.d.ts +167 -0
  70. package/dist/spineItem/frameItem/createFrame$.d.ts +1 -0
  71. package/dist/spineItem/frameItem/createFrameManipulator.d.ts +5 -0
  72. package/dist/spineItem/frameItem/createHtmlPageFromResource.d.ts +3 -0
  73. package/dist/spineItem/frameItem/frameItem.d.ts +49 -0
  74. package/dist/spineItem/frameItem/loader.d.ts +30 -0
  75. package/dist/spineItem/locationResolver.d.ts +24 -0
  76. package/dist/spineItem/navigationResolver.d.ts +16 -0
  77. package/dist/spineItem/prePaginatedSpineItem.d.ts +166 -0
  78. package/dist/spineItem/reflowableSpineItem.d.ts +165 -0
  79. package/dist/spineItem/styles/getStyleForViewportDocument.d.ts +1 -0
  80. package/dist/spineItem/trackers.d.ts +34 -0
  81. package/dist/spineItem/types.d.ts +19 -0
  82. package/dist/spineItemManager.d.ts +505 -0
  83. package/dist/types/Spine.d.ts +40 -0
  84. package/dist/types/index.d.ts +12 -0
  85. package/dist/types/reader.d.ts +44 -0
  86. package/dist/utils/compose.d.ts +8 -0
  87. package/dist/utils/dom.d.ts +19 -0
  88. package/dist/utils/isDefined.d.ts +1 -0
  89. package/dist/utils/layout.d.ts +7 -0
  90. package/dist/utils/layout.test.d.ts +1 -0
  91. package/dist/utils/manifest.d.ts +3 -0
  92. package/dist/utils/objects.d.ts +6 -0
  93. package/dist/utils/objects.test.d.ts +1 -0
  94. package/dist/utils/rxjs.d.ts +5 -0
  95. package/dist/viewportNavigator/manualViewportNavigator.d.ts +96 -0
  96. package/dist/viewportNavigator/panViewportNavigator.d.ts +55 -0
  97. package/dist/viewportNavigator/scrollViewportNavigator.d.ts +38 -0
  98. package/dist/viewportNavigator/types.d.ts +34 -0
  99. package/dist/viewportNavigator/viewportNavigator.d.ts +82 -0
  100. package/package.json +3 -3
@@ -5,8 +5,7 @@
5
5
  const chromeEnhancer = (next) => (options) => {
6
6
  const reader = next(options);
7
7
  reader.context.state$.pipe(rxjs.takeUntil(reader.$.destroy$)).subscribe(({ containerElement }) => {
8
- if (!containerElement)
9
- return;
8
+ if (!containerElement) return;
10
9
  const onScroll = () => {
11
10
  if (reader.settings.settings.computedPageTurnMode === `controlled`) {
12
11
  containerElement.scrollTo(0, 0);
@@ -55,8 +54,7 @@
55
54
  const groupBy = (list, getKey) => list.reduce(
56
55
  (previous, currentItem) => {
57
56
  const group = getKey(currentItem);
58
- if (!previous[group])
59
- previous[group] = [];
57
+ if (!previous[group]) previous[group] = [];
60
58
  previous[group].push(currentItem);
61
59
  return previous;
62
60
  },
@@ -76,7 +74,12 @@
76
74
  });
77
75
  };
78
76
  const fontsEnhancer = (next) => (options) => {
79
- const { fontScale = 1, lineHeight = `publisher`, fontWeight = `publisher`, fontJustification = `publisher` } = options;
77
+ const {
78
+ fontScale = 1,
79
+ lineHeight = `publisher`,
80
+ fontWeight = `publisher`,
81
+ fontJustification = `publisher`
82
+ } = options;
80
83
  const changes$ = new rxjs.Subject();
81
84
  const settings$ = new rxjs.BehaviorSubject({
82
85
  fontScale,
@@ -124,10 +127,8 @@
124
127
  const shouldRequireLayout = (source) => source.pipe(
125
128
  operators.pairwise(),
126
129
  rxjs.map(([old, latest]) => {
127
- if (latest.fontScale !== old.fontScale)
128
- return true;
129
- if (latest.lineHeight !== old.lineHeight)
130
- return true;
130
+ if (latest.fontScale !== old.fontScale) return true;
131
+ if (latest.lineHeight !== old.lineHeight) return true;
131
132
  return false;
132
133
  })
133
134
  );
@@ -212,8 +213,7 @@
212
213
  let iframeOverlayForAnimationsElement;
213
214
  const updateOverlayElement$ = reader.context.state$.pipe(
214
215
  operators.switchMap(({ containerElement }) => {
215
- if (!containerElement)
216
- return rxjs.NEVER;
216
+ if (!containerElement) return rxjs.NEVER;
217
217
  return new rxjs.Observable(() => {
218
218
  iframeOverlayForAnimationsElement = containerElement.ownerDocument.createElement(`div`);
219
219
  iframeOverlayForAnimationsElement.style.cssText = `
@@ -277,8 +277,7 @@
277
277
  reader.hookManager.register(`item.onAfterLayout`, ({ item, blankPagePosition, minimumWidth }) => {
278
278
  var _a;
279
279
  const spineItem = reader.spineItemManager.get(item.id);
280
- if (!((spineItem == null ? void 0 : spineItem.item.renditionLayout) === `reflowable`))
281
- return;
280
+ if (!((spineItem == null ? void 0 : spineItem.item.renditionLayout) === `reflowable`)) return;
282
281
  const { viewportDimensions } = (spineItem == null ? void 0 : spineItem.getViewPortInformation()) ?? {};
283
282
  const { width: pageWidth } = reader.context.getPageSize();
284
283
  const frameElement = (_a = spineItem == null ? void 0 : spineItem.spineItemFrame.getManipulableFrame()) == null ? void 0 : _a.frame;
@@ -427,20 +426,16 @@
427
426
  log: (...data) => {
428
427
  var _a;
429
428
  if ((_a = getWindow()) == null ? void 0 : _a.__PROSE_READER_DEBUG) {
430
- if (namespace)
431
- console.log(wrap(ROOT_NAMESPACE), wrap(namespace), ...data);
432
- else
433
- console.log(wrap(ROOT_NAMESPACE), ...data);
429
+ if (namespace) console.log(wrap(ROOT_NAMESPACE), wrap(namespace), ...data);
430
+ else console.log(wrap(ROOT_NAMESPACE), ...data);
434
431
  }
435
432
  },
436
433
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
437
434
  warn: (...data) => {
438
435
  var _a;
439
436
  if ((_a = getWindow()) == null ? void 0 : _a.__PROSE_READER_DEBUG) {
440
- if (namespace)
441
- console.warn(wrap(ROOT_NAMESPACE), wrap(namespace), ...data);
442
- else
443
- console.warn(wrap(ROOT_NAMESPACE), ...data);
437
+ if (namespace) console.warn(wrap(ROOT_NAMESPACE), wrap(namespace), ...data);
438
+ else console.warn(wrap(ROOT_NAMESPACE), ...data);
444
439
  }
445
440
  },
446
441
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -463,8 +458,7 @@
463
458
  logMetric: (performanceEntry, targetDuration = 0) => {
464
459
  var _a;
465
460
  if ((_a = getWindow()) == null ? void 0 : _a.__PROSE_READER_DEBUG) {
466
- if (performanceEntry.duration <= targetDuration)
467
- ;
461
+ if (performanceEntry.duration <= targetDuration) ;
468
462
  else {
469
463
  console.warn(
470
464
  `[prose-reader] [metric] `,
@@ -476,8 +470,7 @@
476
470
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
477
471
  measurePerformance: (name, targetDuration = 10, functionToMeasure, { disable } = {}) => {
478
472
  var _a;
479
- if (disable || !((_a = getWindow()) == null ? void 0 : _a.__PROSE_READER_DEBUG))
480
- return functionToMeasure;
473
+ if (disable || !((_a = getWindow()) == null ? void 0 : _a.__PROSE_READER_DEBUG)) return functionToMeasure;
481
474
  return (...args) => {
482
475
  const t0 = performance.now();
483
476
  const response = functionToMeasure(...args);
@@ -503,8 +496,7 @@
503
496
  const subject = new rxjs.Subject();
504
497
  const handleNavigationForClick = (element) => {
505
498
  var _a;
506
- if (!element.href)
507
- return false;
499
+ if (!element.href) return false;
508
500
  const hrefUrl = new URL(element.href);
509
501
  const hrefWithoutAnchor = `${hrefUrl.origin}${hrefUrl.pathname}`;
510
502
  const hasExistingSpineItem = (_a = reader.context.manifest) == null ? void 0 : _a.spineItems.some((item) => item.href === hrefWithoutAnchor);
@@ -540,7 +532,9 @@
540
532
  const goToNextSpineItem = () => {
541
533
  var _a;
542
534
  const focusedSpineItemIndex = reader.spineItemManager.getFocusedSpineItemIndex() || 0;
543
- const { end = focusedSpineItemIndex } = reader.spine.locator.getSpineItemsFromReadingOrderPosition(reader.viewportNavigator.getCurrentNavigationPosition()) || {};
535
+ const { end = focusedSpineItemIndex } = reader.spine.locator.getSpineItemsFromReadingOrderPosition(
536
+ reader.viewportNavigator.getCurrentNavigationPosition()
537
+ ) || {};
544
538
  const numberOfSpineItems = ((_a = reader.context.manifest) == null ? void 0 : _a.spineItems.length) ?? 0;
545
539
  const nextItem = end + 1;
546
540
  if (nextItem < numberOfSpineItems) {
@@ -549,7 +543,9 @@
549
543
  };
550
544
  const goToPreviousSpineItem = () => {
551
545
  const focusedSpineItemIndex = reader.spineItemManager.getFocusedSpineItemIndex() || 0;
552
- const { begin = focusedSpineItemIndex } = reader.spine.locator.getSpineItemsFromReadingOrderPosition(reader.viewportNavigator.getCurrentNavigationPosition()) || {};
546
+ const { begin = focusedSpineItemIndex } = reader.spine.locator.getSpineItemsFromReadingOrderPosition(
547
+ reader.viewportNavigator.getCurrentNavigationPosition()
548
+ ) || {};
553
549
  const nextItem = begin - 1;
554
550
  if (nextItem >= 0) {
555
551
  reader.viewportNavigator.goToSpineItem(nextItem);
@@ -559,16 +555,14 @@
559
555
  goToNextSpineItem,
560
556
  goToPreviousSpineItem,
561
557
  goToLeftSpineItem: () => {
562
- if (reader.settings.settings.computedPageTurnDirection === "vertical")
563
- return;
558
+ if (reader.settings.settings.computedPageTurnDirection === "vertical") return;
564
559
  if (reader.context.isRTL()) {
565
560
  return goToNextSpineItem();
566
561
  }
567
562
  return goToPreviousSpineItem();
568
563
  },
569
564
  goToRightSpineItem: () => {
570
- if (reader.settings.settings.computedPageTurnDirection === "vertical")
571
- return;
565
+ if (reader.settings.settings.computedPageTurnDirection === "vertical") return;
572
566
  if (reader.context.isRTL()) {
573
567
  return goToPreviousSpineItem();
574
568
  }
@@ -618,8 +612,7 @@
618
612
  if (isPossibleTocItemCandidate) {
619
613
  const spineItemIndexOfPossibleCandidate = manifest.spineItems.findIndex((item) => item.href === tocItem2.href);
620
614
  const spineItemIsBeforeThisTocItem = spineItemIndex < spineItemIndexOfPossibleCandidate;
621
- if (spineItemIsBeforeThisTocItem)
622
- return acc;
615
+ if (spineItemIsBeforeThisTocItem) return acc;
623
616
  const info = {
624
617
  title: tocItem2.title,
625
618
  path: tocItem2.path
@@ -644,8 +637,7 @@
644
637
  const getChaptersInfo = (reader) => {
645
638
  const manifest = reader.context.manifest;
646
639
  const items = reader.spineItemManager.getAll();
647
- if (!manifest)
648
- return {};
640
+ if (!manifest) return {};
649
641
  return items.reduce(
650
642
  (acc, { item }) => {
651
643
  return {
@@ -734,15 +726,13 @@
734
726
  return Math.max(0, Math.min(lastPageOffset, logicalOffset));
735
727
  };
736
728
  const calculateNumberOfPagesForItem = (itemWidth, pageWidth) => {
737
- if ((pageWidth || 0) === 0 || (itemWidth || 0) === 0)
738
- return 1;
729
+ if ((pageWidth || 0) === 0 || (itemWidth || 0) === 0) return 1;
739
730
  return Math.floor(Math.max(1, itemWidth / pageWidth));
740
731
  };
741
732
  const getClosestValidOffsetFromApproximateOffsetInPages = (offset, pageWidth, itemWidth) => {
742
733
  const numberOfPages = calculateNumberOfPagesForItem(itemWidth, pageWidth);
743
734
  const offsetValues = [...Array(numberOfPages)].map((_, i) => i * pageWidth);
744
- if (offset >= numberOfPages * pageWidth)
745
- return offsetValues[offsetValues.length - 1] || 0;
735
+ if (offset >= numberOfPages * pageWidth) return offsetValues[offsetValues.length - 1] || 0;
746
736
  return offsetValues.find((offsetRange) => offset < offsetRange + pageWidth) || 0;
747
737
  };
748
738
  const getSpineItemNumberOfPages = ({ spineItem, reader }) => {
@@ -841,7 +831,10 @@
841
831
  })),
842
832
  rxjs.distinctUntilChanged(isShallowEqual)
843
833
  );
844
- const paginationInfo$ = rxjs.combineLatest([extandedBasePagination$, totalPages$]).pipe(
834
+ const paginationInfo$ = rxjs.combineLatest([
835
+ extandedBasePagination$,
836
+ totalPages$
837
+ ]).pipe(
845
838
  rxjs.map(([pageInfo, totalPageInfo]) => ({
846
839
  ...pageInfo,
847
840
  ...totalPageInfo,
@@ -1094,8 +1087,7 @@
1094
1087
  const scale = (userScale) => {
1095
1088
  const spineElement = reader.spine.getElement();
1096
1089
  const viewportElement = reader.viewportNavigator.getElement();
1097
- if (!spineElement || !viewportElement)
1098
- return;
1090
+ if (!spineElement || !viewportElement) return;
1099
1091
  const roundedScale = Math.ceil((userScale < 1 ? baseScale - (1 - userScale) : baseScale + (userScale - 1)) * 100) / 100;
1100
1092
  const newScale = Math.max(roundedScale, 1);
1101
1093
  const currentScale = spineElement.getBoundingClientRect().width / spineElement.offsetWidth;
@@ -1217,10 +1209,8 @@
1217
1209
  }) => {
1218
1210
  const { height, width } = visibleAreaRect;
1219
1211
  const isLandscape = width > height;
1220
- if (forceSinglePageMode)
1221
- return false;
1222
- if ((manifest == null ? void 0 : manifest.renditionFlow) === `scrolled-continuous`)
1223
- return false;
1212
+ if (forceSinglePageMode) return false;
1213
+ if ((manifest == null ? void 0 : manifest.renditionFlow) === `scrolled-continuous`) return false;
1224
1214
  if (!isLandscape && (manifest == null ? void 0 : manifest.renditionSpread) === `portrait`) {
1225
1215
  return true;
1226
1216
  }
@@ -1382,8 +1372,7 @@
1382
1372
  image.onerror = reject;
1383
1373
  });
1384
1374
  const createHtmlPageFromResource = async (resourceResponse, item) => {
1385
- if (typeof resourceResponse === `string`)
1386
- return resourceResponse;
1375
+ if (typeof resourceResponse === `string`) return resourceResponse;
1387
1376
  const contentType = shared.parseContentType(resourceResponse.headers.get(`Content-Type`) || ``) || shared.detectMimeTypeFromName(item.href);
1388
1377
  if ([`image/jpg`, `image/jpeg`, `image/png`, `image/webp`].some((mime) => mime === contentType)) {
1389
1378
  const data = await getBase64FromBlob(await resourceResponse.blob());
@@ -1497,8 +1486,7 @@
1497
1486
  }
1498
1487
  }),
1499
1488
  operators.mergeMap((frame) => {
1500
- if (!frame)
1501
- return rxjs.EMPTY;
1489
+ if (!frame) return rxjs.EMPTY;
1502
1490
  return rxjs.fromEvent(frame, `load`).pipe(
1503
1491
  operators.take(1),
1504
1492
  operators.mergeMap(() => {
@@ -1515,10 +1503,11 @@
1515
1503
  if (settings.settings.computedPageTurnMode !== `scrollable`) {
1516
1504
  frame.setAttribute(`tab-index`, `0`);
1517
1505
  }
1518
- return hookManager.execute(`item.onLoad`, item.id, {
1506
+ const hookResults = hookManager.execute(`item.onLoad`, item.id, {
1519
1507
  itemId: item.id,
1520
1508
  frame
1521
- }).pipe(operators.map(() => frame));
1509
+ }).filter((result) => result instanceof rxjs.Observable);
1510
+ return rxjs.combineLatest([rxjs.of(null), ...hookResults]).pipe(operators.map(() => frame));
1522
1511
  })
1523
1512
  );
1524
1513
  }),
@@ -1691,8 +1680,7 @@
1691
1680
  return `rtl`;
1692
1681
  }
1693
1682
  const direction = (_a = getComputedStyleAfterLoad()) == null ? void 0 : _a.direction;
1694
- if ([`ltr`, `rtl`].includes(direction || ``))
1695
- return direction;
1683
+ if ([`ltr`, `rtl`].includes(direction || ``)) return direction;
1696
1684
  return void 0;
1697
1685
  },
1698
1686
  isUsingVerticalWriting,
@@ -1779,8 +1767,7 @@
1779
1767
  getSelection: () => {
1780
1768
  var _a;
1781
1769
  const selection = (_a = frame == null ? void 0 : frame.contentWindow) == null ? void 0 : _a.getSelection();
1782
- if (!(selection == null ? void 0 : selection.anchorNode) || selection.type === `None` || selection.type === `Caret`)
1783
- return void 0;
1770
+ if (!(selection == null ? void 0 : selection.anchorNode) || selection.type === `None` || selection.type === `Caret`) return void 0;
1784
1771
  return selection;
1785
1772
  },
1786
1773
  $: subject.asObservable()
@@ -2361,7 +2348,10 @@
2361
2348
  }
2362
2349
  `;
2363
2350
  };
2364
- const buildStyleForReflowableImageOnly = ({ isScrollable, enableTouch }) => {
2351
+ const buildStyleForReflowableImageOnly = ({
2352
+ isScrollable,
2353
+ enableTouch
2354
+ }) => {
2365
2355
  return `
2366
2356
  ${/*
2367
2357
  * @see https://hammerjs.github.io/touch-action/
@@ -2545,8 +2535,7 @@
2545
2535
  let m;
2546
2536
  do {
2547
2537
  m = str.match(regExp);
2548
- if (!m)
2549
- break;
2538
+ if (!m) break;
2550
2539
  matches.push(m.index + add);
2551
2540
  offset += m.index + m.length;
2552
2541
  str = str.slice(m.index + m.length);
@@ -2609,24 +2598,17 @@
2609
2598
  function compareTemporal(a, b) {
2610
2599
  const isA = typeof a === `number`;
2611
2600
  const isB = typeof b === `number`;
2612
- if (!isA && !isB)
2613
- return 0;
2614
- if (!isA && isB)
2615
- return -1;
2616
- if (isA && !isB)
2617
- return 1;
2601
+ if (!isA && !isB) return 0;
2602
+ if (!isA && isB) return -1;
2603
+ if (isA && !isB) return 1;
2618
2604
  return (a || 0) - (b || 0);
2619
2605
  }
2620
2606
  function compareSpatial(a, b) {
2621
- if (!a && !b)
2622
- return 0;
2623
- if (!a && b)
2624
- return -1;
2625
- if (a && !b)
2626
- return 1;
2607
+ if (!a && !b) return 0;
2608
+ if (!a && b) return -1;
2609
+ if (a && !b) return 1;
2627
2610
  const diff = (a.y || 0) - (b.y || 0);
2628
- if (diff)
2629
- return diff;
2611
+ if (diff) return diff;
2630
2612
  return (a.x || 0) - (b.x || 0);
2631
2613
  }
2632
2614
  class CFI {
@@ -2648,20 +2630,16 @@
2648
2630
  const isCFI = /^epubcfi\((.*)\)$/;
2649
2631
  str = str.trim();
2650
2632
  const m = str.match(isCFI);
2651
- if (!m)
2652
- throw new Error(`Not a valid CFI`);
2653
- if (m.length < 2)
2654
- return;
2633
+ if (!m) throw new Error(`Not a valid CFI`);
2634
+ if (m.length < 2) return;
2655
2635
  str = m[1] || ``;
2656
2636
  let parsed, offset, newDoc;
2657
2637
  let subParts = [];
2658
2638
  let sawComma = 0;
2659
2639
  while (str.length) {
2660
2640
  ({ parsed, offset, newDoc } = this.parse(str));
2661
- if (!parsed || offset === null)
2662
- throw new Error(`Parsing failed`);
2663
- if (sawComma && newDoc)
2664
- throw new Error(`CFI is a range that spans multiple documents. This is not allowed`);
2641
+ if (!parsed || offset === null) throw new Error(`Parsing failed`);
2642
+ if (sawComma && newDoc) throw new Error(`CFI is a range that spans multiple documents. This is not allowed`);
2665
2643
  subParts.push(parsed);
2666
2644
  if (newDoc || str.length - offset <= 0) {
2667
2645
  if (sawComma === 2) {
@@ -2705,8 +2683,7 @@
2705
2683
  if (!parts) {
2706
2684
  if (this.from) {
2707
2685
  this.removeIllegalOpts(this.from);
2708
- if (!this.to)
2709
- return;
2686
+ if (!this.to) return;
2710
2687
  parts = this.to;
2711
2688
  } else {
2712
2689
  parts = this.parts;
@@ -2729,8 +2706,7 @@
2729
2706
  let o;
2730
2707
  while (node.parentNode) {
2731
2708
  o = calcSiblingCount(node.parentNode.childNodes, node, offset);
2732
- if (!cfi && o.offset)
2733
- cfi = `:` + o.offset;
2709
+ if (!cfi && o.offset) cfi = `:` + o.offset;
2734
2710
  cfi = `/` + o.count + (node.id ? `[` + cfiEscape(node.id) + `]` : ``) + cfi;
2735
2711
  node = node.parentNode;
2736
2712
  }
@@ -2747,8 +2723,7 @@
2747
2723
  } else {
2748
2724
  cfi = this.generatePart(node, offset, extra);
2749
2725
  }
2750
- if (extra)
2751
- cfi += extra;
2726
+ if (extra) cfi += extra;
2752
2727
  return `epubcfi(` + cfi + `)`;
2753
2728
  }
2754
2729
  static toParsed(cfi) {
@@ -2765,13 +2740,10 @@
2765
2740
  for (i = 0; i < max; i++) {
2766
2741
  cA = a[i];
2767
2742
  cB = b[i];
2768
- if (!cA)
2769
- return -1;
2770
- if (!cB)
2771
- return 1;
2743
+ if (!cA) return -1;
2744
+ if (!cB) return 1;
2772
2745
  diff = this.compareParts(cA, cB);
2773
- if (diff)
2774
- return diff;
2746
+ if (diff) return diff;
2775
2747
  }
2776
2748
  return 0;
2777
2749
  }
@@ -2788,14 +2760,11 @@
2788
2760
  if (a.isRange || b.isRange) {
2789
2761
  if (a.isRange && b.isRange) {
2790
2762
  const diff = this.comparePath(oA.from, oB.from);
2791
- if (diff)
2792
- return diff;
2763
+ if (diff) return diff;
2793
2764
  return this.comparePath(oA.to, oB.to);
2794
2765
  }
2795
- if (a.isRange)
2796
- oA = oA.from;
2797
- if (b.isRange)
2798
- oB = oB.from;
2766
+ if (a.isRange) oA = oA.from;
2767
+ if (b.isRange) oB = oB.from;
2799
2768
  return this.comparePath(oA, oB);
2800
2769
  } else {
2801
2770
  return this.comparePath(oA, oB);
@@ -2808,29 +2777,22 @@
2808
2777
  for (i = 0; i < max; i++) {
2809
2778
  cA = a[i];
2810
2779
  cB = b[i];
2811
- if (!cA)
2812
- return -1;
2813
- if (!cB)
2814
- return 1;
2780
+ if (!cA) return -1;
2781
+ if (!cB) return 1;
2815
2782
  diff = cA.nodeIndex - cB.nodeIndex;
2816
- if (diff)
2817
- return diff;
2783
+ if (diff) return diff;
2818
2784
  if (cA.nodeIndex === 0) {
2819
2785
  return 0;
2820
2786
  }
2821
- if (i < max - 1)
2822
- continue;
2787
+ if (i < max - 1) continue;
2823
2788
  if (cA.nodeIndex % 2 === 0) {
2824
2789
  diff = compareTemporal(cA.temporal, cB.temporal);
2825
- if (diff)
2826
- return diff;
2790
+ if (diff) return diff;
2827
2791
  diff = compareSpatial(cA.spatial, cB.spatial);
2828
- if (diff)
2829
- return diff;
2792
+ if (diff) return diff;
2830
2793
  }
2831
2794
  diff = (cA.offset || 0) - (cB.offset || 0);
2832
- if (diff)
2833
- return diff;
2795
+ if (diff) return diff;
2834
2796
  }
2835
2797
  return 0;
2836
2798
  }
@@ -2848,8 +2810,7 @@
2848
2810
  return this.decodeEntities(dom, str).length;
2849
2811
  }
2850
2812
  getFrom() {
2851
- if (!this.isRange)
2852
- throw new Error(`Trying to get beginning of non-range CFI`);
2813
+ if (!this.isRange) throw new Error(`Trying to get beginning of non-range CFI`);
2853
2814
  if (!this.from) {
2854
2815
  return this.deepClone(this.parts);
2855
2816
  }
@@ -2858,8 +2819,7 @@
2858
2819
  return parts;
2859
2820
  }
2860
2821
  getTo() {
2861
- if (!this.isRange)
2862
- throw new Error(`Trying to get end of non-range CFI`);
2822
+ if (!this.isRange) throw new Error(`Trying to get end of non-range CFI`);
2863
2823
  const parts = this.deepClone(this.parts);
2864
2824
  parts[parts.length - 1] = parts[parts.length - 1].concat(this.to);
2865
2825
  return parts;
@@ -2875,8 +2835,7 @@
2875
2835
  return this.deepClone(this.parts);
2876
2836
  }
2877
2837
  parseSideBias(o, loc) {
2878
- if (!loc)
2879
- return;
2838
+ if (!loc) return;
2880
2839
  const m = loc.trim().match(/^(.*);s=([ba])$/);
2881
2840
  if (!m || m.length < 3) {
2882
2841
  if (typeof o.textLocationAssertion === `object`) {
@@ -2900,11 +2859,9 @@
2900
2859
  }
2901
2860
  }
2902
2861
  parseSpatialRange(range) {
2903
- if (!range)
2904
- return void 0;
2862
+ if (!range) return void 0;
2905
2863
  const m = range.trim().match(/^([\d\.]+):([\d\.]+)$/);
2906
- if (!m || m.length < 3)
2907
- return void 0;
2864
+ if (!m || m.length < 3) return void 0;
2908
2865
  const o = {
2909
2866
  x: parseInt(m[1]),
2910
2867
  y: parseInt(m[2])
@@ -2994,8 +2951,7 @@
2994
2951
  } else {
2995
2952
  prevState = state;
2996
2953
  state = null;
2997
- if (f && seenColon)
2998
- o.spatial = this.parseSpatialRange(f);
2954
+ if (f && seenColon) o.spatial = this.parseSpatialRange(f);
2999
2955
  f = null;
3000
2956
  }
3001
2957
  }
@@ -3105,8 +3061,7 @@
3105
3061
  }
3106
3062
  escape = false;
3107
3063
  }
3108
- if (!o.nodeIndex && o.nodeIndex !== 0)
3109
- throw new Error(`Missing child node index in CFI`);
3064
+ if (!o.nodeIndex && o.nodeIndex !== 0) throw new Error(`Missing child node index in CFI`);
3110
3065
  return { parsed: o, offset: i, newDoc: state === `!` };
3111
3066
  }
3112
3067
  // The CFI counts child nodes differently from the DOM
@@ -3114,8 +3069,7 @@
3114
3069
  // according to the CFI standard way of counting
3115
3070
  getChildNodeByCFIIndex(dom, parentNode, index, offset) {
3116
3071
  const children = parentNode.childNodes;
3117
- if (!children.length)
3118
- return { node: parentNode, offset: 0 };
3072
+ if (!children.length) return { node: parentNode, offset: 0 };
3119
3073
  if (index <= 0) {
3120
3074
  return { node: children[0], relativeToNode: `before`, offset: 0 };
3121
3075
  }
@@ -3183,8 +3137,7 @@
3183
3137
  }
3184
3138
  }
3185
3139
  isTextNode(node) {
3186
- if (!node)
3187
- return false;
3140
+ if (!node) return false;
3188
3141
  if (node.nodeType === TEXT_NODE || node.nodeType === CDATA_SECTION_NODE) {
3189
3142
  return true;
3190
3143
  }
@@ -3216,15 +3169,13 @@
3216
3169
  str = this.decodeEntities(dom, curNode.textContent);
3217
3170
  nodeLengths[i] = str.length;
3218
3171
  txt += str;
3219
- if (!curNode.nextSibling)
3220
- break;
3172
+ if (!curNode.nextSibling) break;
3221
3173
  curNode = curNode.nextSibling;
3222
3174
  i++;
3223
3175
  }
3224
3176
  const matchOffset = assertion.pre ? assertion.pre.length : 0;
3225
3177
  const m = matchAll(txt, new RegExp(matchStr), matchOffset);
3226
- if (!m.length)
3227
- return { node, offset };
3178
+ if (!m.length) return { node, offset };
3228
3179
  let newOffset = closest(m, offset);
3229
3180
  if (curNode === node && newOffset === offset) {
3230
3181
  return { node, offset };
@@ -3233,11 +3184,9 @@
3233
3184
  curNode = startNode;
3234
3185
  while (newOffset >= nodeLengths[i]) {
3235
3186
  newOffset -= nodeLengths[i];
3236
- if (newOffset < 0)
3237
- return { node, offset };
3187
+ if (newOffset < 0) return { node, offset };
3238
3188
  const nodeOffsets = [];
3239
- if (!curNode.nextSibling || i + 1 >= nodeOffsets.length)
3240
- return { node, offset };
3189
+ if (!curNode.nextSibling || i + 1 >= nodeOffsets.length) return { node, offset };
3241
3190
  i++;
3242
3191
  curNode = curNode.nextSibling;
3243
3192
  }
@@ -3245,8 +3194,7 @@
3245
3194
  }
3246
3195
  resolveNode(index, subparts, dom, opts) {
3247
3196
  opts = Object.assign({}, opts || {});
3248
- if (!dom)
3249
- throw new Error(`Missing DOM argument`);
3197
+ if (!dom) throw new Error(`Missing DOM argument`);
3250
3198
  let startNode;
3251
3199
  if (index === 0) {
3252
3200
  startNode = dom.querySelector(`package`);
@@ -3260,8 +3208,7 @@
3260
3208
  }
3261
3209
  }
3262
3210
  startNode = dom;
3263
- if (!startNode)
3264
- throw new Error(`Document incompatible with CFIs`);
3211
+ if (!startNode) throw new Error(`Document incompatible with CFIs`);
3265
3212
  let node = startNode;
3266
3213
  let startFrom = 0;
3267
3214
  let i;
@@ -3303,40 +3250,33 @@
3303
3250
  throw new Error(`index is out of bounds`);
3304
3251
  }
3305
3252
  const subparts = this.parts[index];
3306
- if (!subparts)
3307
- throw new Error(`Missing CFI part for index: ` + index);
3253
+ if (!subparts) throw new Error(`Missing CFI part for index: ` + index);
3308
3254
  const o = this.resolveNode(index, subparts, dom, opts);
3309
3255
  let node = o.node;
3310
3256
  const tagName = node.tagName.toLowerCase();
3311
3257
  if (tagName === `itemref` && // @ts-ignore
3312
3258
  node.parentNode.tagName.toLowerCase() === `spine`) {
3313
3259
  const idref = node.getAttribute(`idref`);
3314
- if (!idref)
3315
- throw new Error(`Referenced node had not 'idref' attribute`);
3260
+ if (!idref) throw new Error(`Referenced node had not 'idref' attribute`);
3316
3261
  node = dom.getElementById(idref);
3317
- if (!node)
3318
- throw new Error(`Specified node is missing from manifest`);
3262
+ if (!node) throw new Error(`Specified node is missing from manifest`);
3319
3263
  const href = node.getAttribute(`href`);
3320
- if (!href)
3321
- throw new Error(`Manifest item is missing href attribute`);
3264
+ if (!href) throw new Error(`Manifest item is missing href attribute`);
3322
3265
  return href;
3323
3266
  }
3324
3267
  if (tagName === `iframe` || tagName === `embed`) {
3325
3268
  const src = node.getAttribute(`src`);
3326
- if (!src)
3327
- throw new Error(tagName + ` element is missing 'src' attribute`);
3269
+ if (!src) throw new Error(tagName + ` element is missing 'src' attribute`);
3328
3270
  return src;
3329
3271
  }
3330
3272
  if (tagName === `object`) {
3331
3273
  const data = node.getAttribute(`data`);
3332
- if (!data)
3333
- throw new Error(tagName + ` element is missing 'data' attribute`);
3274
+ if (!data) throw new Error(tagName + ` element is missing 'data' attribute`);
3334
3275
  return data;
3335
3276
  }
3336
3277
  if (tagName === `image` || tagName === `use`) {
3337
3278
  const href = node.getAttribute(`xlink:href`);
3338
- if (!href)
3339
- throw new Error(tagName + ` element is missing 'xlink:href' attribute`);
3279
+ if (!href) throw new Error(tagName + ` element is missing 'xlink:href' attribute`);
3340
3280
  return href;
3341
3281
  }
3342
3282
  throw new Error(`No URI found`);
@@ -3347,13 +3287,11 @@
3347
3287
  resolveLocation(dom, parts) {
3348
3288
  const index = parts.length - 1;
3349
3289
  const subparts = parts[index];
3350
- if (!subparts)
3351
- throw new Error(`Missing CFI part for index: ` + index);
3290
+ if (!subparts) throw new Error(`Missing CFI part for index: ` + index);
3352
3291
  const o = this.resolveNode(index, subparts, dom);
3353
3292
  const lastPart = this.deepClone(subparts[subparts.length - 1]);
3354
3293
  delete lastPart.nodeIndex;
3355
- if (!lastPart.offset)
3356
- delete o.offset;
3294
+ if (!lastPart.offset) delete o.offset;
3357
3295
  return { ...lastPart, ...o };
3358
3296
  }
3359
3297
  // Takes the Document or XMLDocument for the final
@@ -3417,12 +3355,20 @@
3417
3355
  toString: () => text,
3418
3356
  getAnchorCfi: () => {
3419
3357
  if (selection.anchorNode) {
3420
- return CFI.generate(selection.anchorNode, selection.anchorOffset, `|[prose~anchor~${encodeURIComponent(item.id)}]`);
3358
+ return CFI.generate(
3359
+ selection.anchorNode,
3360
+ selection.anchorOffset,
3361
+ `|[prose~anchor~${encodeURIComponent(item.id)}]`
3362
+ );
3421
3363
  }
3422
3364
  },
3423
3365
  getFocusCfi: () => {
3424
3366
  if (selection.focusNode) {
3425
- return CFI.generate(selection.focusNode, selection.focusOffset, `|[prose~anchor~${encodeURIComponent(item.id)}]`);
3367
+ return CFI.generate(
3368
+ selection.focusNode,
3369
+ selection.focusOffset,
3370
+ `|[prose~anchor~${encodeURIComponent(item.id)}]`
3371
+ );
3426
3372
  }
3427
3373
  }
3428
3374
  };
@@ -3596,7 +3542,10 @@
3596
3542
  beginSpineItem
3597
3543
  );
3598
3544
  const beginPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(beginPosition, beginSpineItem);
3599
- const endPosition = spineLocator.getSpineItemPositionFromSpinePosition(spineItemsFromPosition.endPosition, endSpineItem);
3545
+ const endPosition = spineLocator.getSpineItemPositionFromSpinePosition(
3546
+ spineItemsFromPosition.endPosition,
3547
+ endSpineItem
3548
+ );
3600
3549
  const endPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(endPosition, endSpineItem);
3601
3550
  const endItemIndex = spineItemManager.getSpineItemIndex(endSpineItem) ?? 0;
3602
3551
  pagination.updateBeginAndEnd(
@@ -3679,8 +3628,7 @@
3679
3628
  operators.map(([, currentNavigationPosition]) => {
3680
3629
  const focusedSpineItemIndex = spineItemManager.getFocusedSpineItemIndex();
3681
3630
  report.log(`update contents`, { focusedSpineItemIndex });
3682
- if (focusedSpineItemIndex === void 0)
3683
- return;
3631
+ if (focusedSpineItemIndex === void 0) return;
3684
3632
  const { begin = focusedSpineItemIndex, end = focusedSpineItemIndex } = spineLocator.getSpineItemsFromReadingOrderPosition(currentNavigationPosition) || {};
3685
3633
  if (begin !== focusedSpineItemIndex && end !== focusedSpineItemIndex) {
3686
3634
  Report.warn(`Current viewport is not in sync with focus item, load from focus item rather than viewport`);
@@ -3816,7 +3764,9 @@
3816
3764
  verticalOffset: newEdgeY
3817
3765
  };
3818
3766
  }
3819
- item.adjustPositionOfElement(context.isRTL() ? { right: horizontalOffset, top: 0 } : { left: horizontalOffset, top: 0 });
3767
+ item.adjustPositionOfElement(
3768
+ context.isRTL() ? { right: horizontalOffset, top: 0 } : { left: horizontalOffset, top: 0 }
3769
+ );
3820
3770
  newItemLayoutInformation.push({
3821
3771
  ...context.isRTL() ? {
3822
3772
  left: context.state.visibleAreaRect.width - horizontalOffset - width,
@@ -3837,18 +3787,18 @@
3837
3787
  },
3838
3788
  { horizontalOffset: 0, verticalOffset: 0 }
3839
3789
  );
3840
- const hasLayoutChanges = itemLayoutInformation.some((old, index) => !isShallowEqual(old, newItemLayoutInformation[index]));
3790
+ const hasLayoutChanges = itemLayoutInformation.some(
3791
+ (old, index) => !isShallowEqual(old, newItemLayoutInformation[index])
3792
+ );
3841
3793
  itemLayoutInformation = newItemLayoutInformation;
3842
3794
  Report.log(NAMESPACE$4, `layout`, { hasLayoutChanges, itemLayoutInformation });
3843
3795
  layout$.next(hasLayoutChanges);
3844
3796
  };
3845
3797
  const focus = (indexOrSpineItem) => {
3846
3798
  const spineItemToFocus = typeof indexOrSpineItem === `number` ? get(indexOrSpineItem) : indexOrSpineItem;
3847
- if (!spineItemToFocus)
3848
- return;
3799
+ if (!spineItemToFocus) return;
3849
3800
  const newActiveSpineItemIndex = orderedSpineItemsSubject$.value.indexOf(spineItemToFocus);
3850
- if (newActiveSpineItemIndex === focusedSpineItemIndex)
3851
- return;
3801
+ if (newActiveSpineItemIndex === focusedSpineItemIndex) return;
3852
3802
  focusedSpineItemIndex = newActiveSpineItemIndex;
3853
3803
  focus$.next({ data: spineItemToFocus });
3854
3804
  };
@@ -3898,8 +3848,7 @@
3898
3848
  return `before`;
3899
3849
  };
3900
3850
  const getSpineItemIndex = (spineItem) => {
3901
- if (!spineItem)
3902
- return void 0;
3851
+ if (!spineItem) return void 0;
3903
3852
  const index = orderedSpineItemsSubject$.value.indexOf(spineItem);
3904
3853
  return index < 0 ? void 0 : index;
3905
3854
  };
@@ -3960,13 +3909,27 @@
3960
3909
  layout$: layout$.asObservable(),
3961
3910
  itemIsReady$: orderedSpineItemsSubject$.asObservable().pipe(
3962
3911
  operators.switchMap((items) => {
3963
- const itemsIsReady$ = items.map((item) => item.$.isReady$.pipe(operators.map((isReady) => ({ item: item.item, isReady }))));
3912
+ const itemsIsReady$ = items.map(
3913
+ (item) => item.$.isReady$.pipe(operators.map((isReady) => ({ item: item.item, isReady })))
3914
+ );
3964
3915
  return rxjs.merge(...itemsIsReady$);
3965
3916
  })
3966
3917
  )
3967
3918
  }
3968
3919
  };
3969
3920
  };
3921
+ const pointerEvents$1 = [
3922
+ `pointercancel`,
3923
+ `pointerdown`,
3924
+ `pointerenter`,
3925
+ `pointerleave`,
3926
+ `pointermove`,
3927
+ `pointerout`,
3928
+ `pointerover`,
3929
+ `pointerup`
3930
+ // `touchstart` as const,
3931
+ // `touchend` as const,
3932
+ ];
3970
3933
  const isHtmlElement = (element) => {
3971
3934
  return typeof element === `object` && !!element && `nodeType` in element && (element == null ? void 0 : element.nodeType) === Node.ELEMENT_NODE && `innerText` in element;
3972
3935
  };
@@ -3993,7 +3956,11 @@
3993
3956
  const visibleRect = getFirstVisibleDOMRect(rects, viewport);
3994
3957
  if (visibleRect) {
3995
3958
  lastValidRange = range.cloneRange();
3996
- const rangeOrCaret = createRangeOrCaretFromPoint(ownerDocument, Math.ceil(visibleRect.left), Math.ceil(visibleRect.top));
3959
+ const rangeOrCaret = createRangeOrCaretFromPoint(
3960
+ ownerDocument,
3961
+ Math.ceil(visibleRect.left),
3962
+ Math.ceil(visibleRect.top)
3963
+ );
3997
3964
  if (rangeOrCaret && `startContainer` in rangeOrCaret && rangeOrCaret.startContainer === lastValidRange.startContainer) {
3998
3965
  lastValidOffset = rangeOrCaret.startOffset;
3999
3966
  }
@@ -4029,14 +3996,10 @@
4029
3996
  return lastValidElement;
4030
3997
  };
4031
3998
  function getElementOrNodePositionFromViewPort(domRect, { left, right }) {
4032
- if (domRect.left <= left && domRect.right <= left)
4033
- return `before`;
4034
- if (domRect.left <= left && domRect.right > left && domRect.right <= right)
4035
- return `partially-before`;
4036
- if (domRect.left <= right && domRect.right > right)
4037
- return `partially-after`;
4038
- if (domRect.left > right)
4039
- return `after`;
3999
+ if (domRect.left <= left && domRect.right <= left) return `before`;
4000
+ if (domRect.left <= left && domRect.right > left && domRect.right <= right) return `partially-before`;
4001
+ if (domRect.left <= right && domRect.right > right) return `partially-after`;
4002
+ if (domRect.left > right) return `after`;
4040
4003
  return `within`;
4041
4004
  }
4042
4005
  function getFirstVisibleDOMRect(domRect, viewport) {
@@ -4068,22 +4031,24 @@
4068
4031
  var _a, _b, _c, _d, _e;
4069
4032
  if ((event == null ? void 0 : event.target) && ((_b = (_a = event == null ? void 0 : event.target) == null ? void 0 : _a.ownerDocument) == null ? void 0 : _b.defaultView)) {
4070
4033
  const eventView = (_d = (_c = event == null ? void 0 : event.target) == null ? void 0 : _c.ownerDocument) == null ? void 0 : _d.defaultView;
4071
- if (eventView.PointerEvent) {
4072
- return event instanceof eventView.PointerEvent;
4034
+ if (eventView.PointerEvent && event instanceof eventView.PointerEvent) {
4035
+ return true;
4073
4036
  }
4074
4037
  }
4075
4038
  if ((event == null ? void 0 : event.view) && ((_e = event == null ? void 0 : event.view) == null ? void 0 : _e.window)) {
4076
4039
  const eventView = event == null ? void 0 : event.view;
4077
- if (eventView.PointerEvent) {
4078
- return event instanceof eventView.PointerEvent;
4040
+ if (eventView.PointerEvent && event instanceof eventView.PointerEvent) {
4041
+ return true;
4079
4042
  }
4080
4043
  }
4044
+ if (pointerEvents$1.includes(event.type)) {
4045
+ return true;
4046
+ }
4081
4047
  return false;
4082
4048
  };
4083
4049
  const isMouseEvent = (event) => {
4084
4050
  var _a, _b, _c, _d, _e;
4085
- if (isPointerEvent(event))
4086
- return false;
4051
+ if (isPointerEvent(event)) return false;
4087
4052
  if ((event == null ? void 0 : event.target) && ((_b = (_a = event == null ? void 0 : event.target) == null ? void 0 : _a.ownerDocument) == null ? void 0 : _b.defaultView)) {
4088
4053
  const eventView = (_d = (_c = event == null ? void 0 : event.target) == null ? void 0 : _c.ownerDocument) == null ? void 0 : _d.defaultView;
4089
4054
  if (eventView.MouseEvent) {
@@ -4212,10 +4177,8 @@
4212
4177
  };
4213
4178
  const getPageFromOffset = (offset, pageWidth, numberOfPages) => {
4214
4179
  const offsetValues = [...Array(numberOfPages)].map((_, i) => i * pageWidth);
4215
- if (offset <= 0)
4216
- return 0;
4217
- if (offset >= numberOfPages * pageWidth)
4218
- return numberOfPages - 1;
4180
+ if (offset <= 0) return 0;
4181
+ if (offset >= numberOfPages * pageWidth) return numberOfPages - 1;
4219
4182
  return Math.max(
4220
4183
  0,
4221
4184
  offsetValues.findIndex((offsetRange) => offset < offsetRange + pageWidth)
@@ -4251,7 +4214,10 @@
4251
4214
  y: position.y + context.getPageSize().height
4252
4215
  };
4253
4216
  }
4254
- const navigationPosition = spineItemLocator.getSpineItemClosestPositionFromUnsafePosition(nextPotentialPosition, spineItem);
4217
+ const navigationPosition = spineItemLocator.getSpineItemClosestPositionFromUnsafePosition(
4218
+ nextPotentialPosition,
4219
+ spineItem
4220
+ );
4255
4221
  return new SpineItemNavigationPosition(navigationPosition);
4256
4222
  };
4257
4223
  const getNavigationForRightPage = (position, spineItem) => {
@@ -4265,7 +4231,10 @@
4265
4231
  y: position.y - context.getPageSize().height
4266
4232
  };
4267
4233
  }
4268
- const navigationPosition = spineItemLocator.getSpineItemClosestPositionFromUnsafePosition(nextPotentialPosition, spineItem);
4234
+ const navigationPosition = spineItemLocator.getSpineItemClosestPositionFromUnsafePosition(
4235
+ nextPotentialPosition,
4236
+ spineItem
4237
+ );
4269
4238
  return new SpineItemNavigationPosition(navigationPosition);
4270
4239
  };
4271
4240
  const getNavigationForLastPage = (spineItem) => {
@@ -4288,7 +4257,10 @@
4288
4257
  return new SpineItemNavigationPosition(position || { x: 0, y: 0 });
4289
4258
  };
4290
4259
  const getNavigationForPosition = (spineItem, position) => {
4291
- const potentiallyCorrectedPosition = spineItemLocator.getSpineItemClosestPositionFromUnsafePosition(position, spineItem);
4260
+ const potentiallyCorrectedPosition = spineItemLocator.getSpineItemClosestPositionFromUnsafePosition(
4261
+ position,
4262
+ spineItem
4263
+ );
4292
4264
  return new SpineItemNavigationPosition(potentiallyCorrectedPosition);
4293
4265
  };
4294
4266
  return {
@@ -4387,7 +4359,10 @@
4387
4359
  pageTurnDirection === `horizontal` ? { x: position.x + context.getPageSize().width, y: 0 } : { y: position.y + context.getPageSize().height, x: 0 }
4388
4360
  );
4389
4361
  } else {
4390
- const readingOrderPosition = locator.getSpinePositionFromSpineItemPosition(spineItemNavigationForRightPage, spineItem);
4362
+ const readingOrderPosition = locator.getSpinePositionFromSpineItemPosition(
4363
+ spineItemNavigationForRightPage,
4364
+ spineItem
4365
+ );
4391
4366
  return readingOrderPosition;
4392
4367
  }
4393
4368
  };
@@ -4567,8 +4542,7 @@
4567
4542
  const getScaledDownPosition = ({ x, y }) => {
4568
4543
  var _a, _b;
4569
4544
  const spineElement = spine.getElement();
4570
- if (!spineElement)
4571
- throw new Error("Invalid spine element");
4545
+ if (!spineElement) throw new Error("Invalid spine element");
4572
4546
  const spineScaleX = spineElement.getBoundingClientRect().width / spineElement.offsetWidth;
4573
4547
  const scaledDownPosition = {
4574
4548
  x: getNewScaledOffset({
@@ -4723,13 +4697,15 @@
4723
4697
  10,
4724
4698
  (navigation, { allowSpineItemChange = true } = {}) => {
4725
4699
  const currentSpineItem = spineItemManager.getFocusedSpineItem();
4726
- if (!currentSpineItem)
4727
- return rxjs.EMPTY;
4700
+ if (!currentSpineItem) return rxjs.EMPTY;
4728
4701
  const newSpineItem = locator.getSpineItemFromPosition(navigation) || currentSpineItem;
4729
4702
  const spineItemHasChanged = newSpineItem !== currentSpineItem;
4730
4703
  if (spineItemHasChanged) {
4731
4704
  if (allowSpineItemChange) {
4732
- const positionOfNewSpineItemComparedToCurrentOne = spineItemManager.comparePositionOf(newSpineItem, currentSpineItem);
4705
+ const positionOfNewSpineItemComparedToCurrentOne = spineItemManager.comparePositionOf(
4706
+ newSpineItem,
4707
+ currentSpineItem
4708
+ );
4733
4709
  if (positionOfNewSpineItemComparedToCurrentOne === `before`) {
4734
4710
  return rxjs.of({
4735
4711
  ...navigation,
@@ -4883,8 +4859,7 @@
4883
4859
  10,
4884
4860
  (navigation, { allowSpineItemChange = true } = {}) => {
4885
4861
  const currentSpineItem = spineItemManager.getFocusedSpineItem();
4886
- if (!currentSpineItem)
4887
- return void 0;
4862
+ if (!currentSpineItem) return void 0;
4888
4863
  const newSpineItem = locator.getSpineItemFromPosition(navigation) || currentSpineItem;
4889
4864
  const spineItemHasChanged = newSpineItem !== currentSpineItem;
4890
4865
  if (spineItemHasChanged) {
@@ -5025,8 +5000,7 @@
5025
5000
  2,
5026
5001
  ({ x, y }) => {
5027
5002
  const element = element$.getValue();
5028
- if (!element)
5029
- throw new Error("Invalid element");
5003
+ if (!element) throw new Error("Invalid element");
5030
5004
  currentViewportPositionMemoUnused = void 0;
5031
5005
  const isAdjusted = viewportNavigators.reduce((isAdjusted2, navigator22) => {
5032
5006
  return navigator22.adjustReadingOffset({ x, y }) || isAdjusted2;
@@ -5183,9 +5157,8 @@
5183
5157
  }
5184
5158
  }),
5185
5159
  operators.switchMap(([, currentEvent]) => {
5186
- if ((currentEvent == null ? void 0 : currentEvent.type) !== `manualAdjust`)
5187
- return rxjs.EMPTY;
5188
- const animationDuration = currentEvent.animation === `snap` ? settings.settings.computedSnapAnimationDuration : settings.settings.computedPageTurnAnimationDuration;
5160
+ if ((currentEvent == null ? void 0 : currentEvent.type) !== `manualAdjust`) return rxjs.EMPTY;
5161
+ const animationDuration = currentEvent.animation === `snap` ? settings.settings.snapAnimationDuration : settings.settings.computedPageTurnAnimationDuration;
5189
5162
  const pageTurnAnimation = currentEvent.animation === `snap` ? `slide` : settings.settings.computedPageTurnAnimation;
5190
5163
  return rxjs.of(currentEvent).pipe(
5191
5164
  /**
@@ -5292,8 +5265,7 @@
5292
5265
  () => waitForViewportFree$.pipe(
5293
5266
  operators.switchMap(() => {
5294
5267
  const focusedSpineItem = spineItemManager.getFocusedSpineItem();
5295
- if (!focusedSpineItem)
5296
- return rxjs.EMPTY;
5268
+ if (!focusedSpineItem) return rxjs.EMPTY;
5297
5269
  return adjustNavigation(focusedSpineItem);
5298
5270
  }),
5299
5271
  operators.takeUntil(navigation$)
@@ -5411,13 +5383,14 @@
5411
5383
  const getSpineItemsFromReadingOrderPosition = (position) => {
5412
5384
  const itemAtPosition = getSpineItemFromPosition(position) || spineItemManager.getFocusedSpineItem();
5413
5385
  const itemAtPositionIndex = spineItemManager.getSpineItemIndex(itemAtPosition);
5414
- if (itemAtPositionIndex === void 0)
5415
- return void 0;
5386
+ if (itemAtPositionIndex === void 0) return void 0;
5416
5387
  let endPosition = position;
5417
5388
  if (context.state.isUsingSpreadMode) {
5418
5389
  endPosition = { x: position.x + context.getPageSize().width, y: position.y };
5419
5390
  }
5420
- const endItemIndex = spineItemManager.getSpineItemIndex(getSpineItemFromPosition(endPosition) || spineItemManager.getFocusedSpineItem()) ?? itemAtPositionIndex;
5391
+ const endItemIndex = spineItemManager.getSpineItemIndex(
5392
+ getSpineItemFromPosition(endPosition) || spineItemManager.getFocusedSpineItem()
5393
+ ) ?? itemAtPositionIndex;
5421
5394
  const items = [
5422
5395
  { item: itemAtPositionIndex, position },
5423
5396
  { item: endItemIndex, position: endPosition }
@@ -5497,12 +5470,10 @@
5497
5470
  };
5498
5471
  const resolveCfi = (cfiString) => {
5499
5472
  var _a, _b, _c;
5500
- if (!cfiString)
5501
- return void 0;
5473
+ if (!cfiString) return void 0;
5502
5474
  const spineItem = getSpineItemFromCfi(cfiString);
5503
5475
  const spineItemIndex = spineItemManager.getSpineItemIndex(spineItem) || 0;
5504
- if (!spineItem)
5505
- return void 0;
5476
+ if (!spineItem) return void 0;
5506
5477
  const { cleanedCfi, offset } = extractProseMetadataFromCfi(cfiString);
5507
5478
  const cfi = new CFI(cleanedCfi, {});
5508
5479
  const doc = (_c = (_b = (_a = spineItem.spineItemFrame.getManipulableFrame()) == null ? void 0 : _a.frame) == null ? void 0 : _b.contentWindow) == null ? void 0 : _c.document;
@@ -5542,8 +5513,7 @@
5542
5513
  computedPageTurnDirection: settings.pageTurnDirection,
5543
5514
  computedPageTurnAnimation: settings.pageTurnAnimation,
5544
5515
  computedPageTurnMode: `controlled`,
5545
- computedPageTurnAnimationDuration: 0,
5546
- computedSnapAnimationDuration: 0
5516
+ computedPageTurnAnimationDuration: 0
5547
5517
  };
5548
5518
  if ((manifest == null ? void 0 : manifest.renditionFlow) === `scrolled-continuous`) {
5549
5519
  computedSettings.computedPageTurnMode = `scrollable`;
@@ -5580,7 +5550,7 @@
5580
5550
  // computedPageTurnAnimationDuration: 0,
5581
5551
  pageTurnMode: `controlled`,
5582
5552
  // computedPageTurnMode: `controlled`,
5583
- // computedSnapAnimationDuration: 300,
5553
+ snapAnimationDuration: 300,
5584
5554
  navigationSnapThreshold: 0.3,
5585
5555
  numberOfAdjacentSpineItemToPreLoad: 0
5586
5556
  };
@@ -5614,8 +5584,7 @@
5614
5584
  this._settingsSubject$.next(newMergedSettings);
5615
5585
  }
5616
5586
  setSettings(settings) {
5617
- if (Object.keys(settings).length === 0)
5618
- return;
5587
+ if (Object.keys(settings).length === 0) return;
5619
5588
  const newMergedSettings = { ...this._settingsSubject$.value, ...settings };
5620
5589
  this._updateSettings(newMergedSettings);
5621
5590
  }
@@ -5636,7 +5605,7 @@
5636
5605
  * - call destroy function for every execution of this specific hook
5637
5606
  * - remove the hook for further calls
5638
5607
  */
5639
- _deregister(hookToDeregister) {
5608
+ deregister(hookToDeregister) {
5640
5609
  this._hooks = this._hooks.filter((hook) => hook !== hookToDeregister);
5641
5610
  return this.destroy(hookToDeregister.name, void 0, hookToDeregister);
5642
5611
  }
@@ -5648,21 +5617,16 @@
5648
5617
  register(name, fn) {
5649
5618
  const hook = {
5650
5619
  name,
5651
- runFn: (params) => {
5652
- const returnValue = fn(params);
5653
- if (!returnValue)
5654
- return rxjs.of(void 0);
5655
- return returnValue;
5656
- }
5620
+ runFn: fn
5657
5621
  };
5658
5622
  this._hooks.push(hook);
5659
5623
  return () => {
5660
- this._deregister(hook);
5624
+ this.deregister(hook);
5661
5625
  };
5662
5626
  }
5663
5627
  execute(name, id, params) {
5664
5628
  const hooks = this._hooks.filter((hook) => name === hook.name);
5665
- const runFns = hooks.map((hook) => {
5629
+ const fnResults = hooks.map((hook) => {
5666
5630
  let userDestroyFn = () => rxjs.of(void 0);
5667
5631
  const destroySubject = new rxjs.Subject();
5668
5632
  const destroy = (fn) => {
@@ -5674,16 +5638,16 @@
5674
5638
  const result = userDestroyFn();
5675
5639
  return result ?? rxjs.of(void 0);
5676
5640
  };
5677
- const execution = hook.runFn({ ...params, destroy$: destroySubject.asObservable(), destroy });
5641
+ const fnResult = hook.runFn({ ...params, destroy$: destroySubject.asObservable(), destroy });
5678
5642
  this._hookExecutions.push({
5679
5643
  name,
5680
5644
  id,
5681
5645
  destroyFn,
5682
5646
  ref: hook
5683
5647
  });
5684
- return execution;
5648
+ return fnResult;
5685
5649
  });
5686
- return rxjs.combineLatest(runFns);
5650
+ return fnResults;
5687
5651
  }
5688
5652
  destroy(name, id, ref) {
5689
5653
  const instances = this._hookExecutions.filter(
@@ -5765,8 +5729,7 @@
5765
5729
  var _a;
5766
5730
  const containerElement = (_a = elementSubject$.getValue()) == null ? void 0 : _a.parentElement;
5767
5731
  const element = elementSubject$.getValue();
5768
- if (!element || !containerElement)
5769
- throw new Error("Invalid element");
5732
+ if (!element || !containerElement) throw new Error("Invalid element");
5770
5733
  const dimensions = {
5771
5734
  width: containerElement == null ? void 0 : containerElement.offsetWidth,
5772
5735
  height: containerElement == null ? void 0 : containerElement.offsetHeight
@@ -5839,7 +5802,12 @@
5839
5802
  }),
5840
5803
  operators.distinctUntilChanged(isShallowEqual),
5841
5804
  operators.map(
5842
- ({ hasVerticalWriting, renditionFlow, renditionLayout, computedPageTurnMode }) => {
5805
+ ({
5806
+ hasVerticalWriting,
5807
+ renditionFlow,
5808
+ renditionLayout,
5809
+ computedPageTurnMode
5810
+ }) => {
5843
5811
  return {
5844
5812
  ...stateSubject$.value,
5845
5813
  supportedPageTurnMode: renditionFlow === `scrolled-continuous` ? [`scrollable`] : !context.state.areAllItemsPrePaginated ? [`controlled`] : [`controlled`, `scrollable`],
@@ -6033,8 +6001,7 @@
6033
6001
  };
6034
6002
  const get = async (itemIndexOrId, fetchResource) => {
6035
6003
  const item = retrieveItem(itemIndexOrId);
6036
- if (!item)
6037
- return new Response(`Item not found`, { status: 404 });
6004
+ if (!item) return new Response(`Item not found`, { status: 404 });
6038
6005
  const db = await openDatabase(`prose-reader`);
6039
6006
  const cacheData = await db.get(`${uniqueID}_${item.id}`);
6040
6007
  if (cacheData) {
@@ -6050,8 +6017,7 @@
6050
6017
  cache$.asObservable().pipe(
6051
6018
  operators.mergeMap(({ id, data }) => {
6052
6019
  const item = retrieveItem(id);
6053
- if (!item)
6054
- return rxjs.EMPTY;
6020
+ if (!item) return rxjs.EMPTY;
6055
6021
  return rxjs.from(rxjs.forkJoin([openDatabase(`prose-reader`), rxjs.from(data.blob())])).pipe(
6056
6022
  operators.switchMap(([db, blob]) => {
6057
6023
  return rxjs.from(db.put(`${uniqueID}_${item.id}`, blob));
@@ -6205,7 +6171,11 @@
6205
6171
  } else {
6206
6172
  progressWithinThisItem = 0;
6207
6173
  }
6208
- totalProgress = getTotalProgressFromPercentages(estimateBeforeThisItem, currentItemWeight, progressWithinThisItem);
6174
+ totalProgress = getTotalProgressFromPercentages(
6175
+ estimateBeforeThisItem,
6176
+ currentItemWeight,
6177
+ progressWithinThisItem
6178
+ );
6209
6179
  }
6210
6180
  if (currentSpineIndex === readingOrderLength - 1 && pageIndex === numberOfPages - 1 && totalProgress > 0.99) {
6211
6181
  return 1;
@@ -6246,8 +6216,7 @@
6246
6216
  reader.hookManager.register(`item.onLoad`, ({ itemId, frame, destroy }) => {
6247
6217
  var _a;
6248
6218
  const item = reader.spineItemManager.get(itemId);
6249
- if (!item)
6250
- return;
6219
+ if (!item) return;
6251
6220
  item.manipulateSpineItem(({ addStyle }) => {
6252
6221
  addStyle(
6253
6222
  `prose-reader-accessibility`,
@@ -6380,7 +6349,10 @@
6380
6349
  `;
6381
6350
  return loadingElement;
6382
6351
  };
6383
- const defaultLoadingElementCreate = ({ container, item }) => {
6352
+ const defaultLoadingElementCreate = ({
6353
+ container,
6354
+ item
6355
+ }) => {
6384
6356
  const logoElement = container.ownerDocument.createElement(`div`);
6385
6357
  logoElement.innerText = `prose`;
6386
6358
  logoElement.style.cssText = `
@@ -6415,11 +6387,9 @@
6415
6387
  const eventIsComingFromBridge = event.target === iframeEventBridgeElement$.getValue();
6416
6388
  const iframeOriginalEvent = getOriginalFrameEventFromDocumentEvent(event);
6417
6389
  const originalFrame = (_a = iframeOriginalEvent == null ? void 0 : iframeOriginalEvent.view) == null ? void 0 : _a.frameElement;
6418
- if (!eventIsComingFromBridge || !iframeOriginalEvent || !originalFrame)
6419
- return event;
6390
+ if (!eventIsComingFromBridge || !iframeOriginalEvent || !originalFrame) return event;
6420
6391
  const spineItem = locator.getSpineItemFromIframe(originalFrame);
6421
- if (!spineItem)
6422
- return event;
6392
+ if (!spineItem) return event;
6423
6393
  if (isPointerEvent(event)) {
6424
6394
  const { clientX, clientY } = spineItem.translateFramePositionIntoPage(event);
6425
6395
  const newEvent = new PointerEvent(event.type, {
@@ -6505,8 +6475,7 @@
6505
6475
  const reader = next(options);
6506
6476
  reader.hookManager.register(`item.onLoad`, ({ destroy, frame, itemId }) => {
6507
6477
  const item = reader.spineItemManager.get(itemId);
6508
- if (!item)
6509
- return;
6478
+ if (!item) return;
6510
6479
  const unregister = passthroughEvents.map((event) => {
6511
6480
  var _a;
6512
6481
  const listener = (e) => {
@@ -6596,6 +6565,7 @@
6596
6565
  )
6597
6566
  )
6598
6567
  );
6568
+ exports2.HookManager = HookManager;
6599
6569
  exports2.Report = Report;
6600
6570
  exports2.createReader = createReaderWithEnhancers;
6601
6571
  exports2.groupBy = groupBy;