@prose-reader/core 1.53.0 → 1.54.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.d.ts CHANGED
@@ -26,6 +26,23 @@ declare type Api = {
26
26
 
27
27
  declare type CfiLocator = ReturnType<typeof createCfiLocator>;
28
28
 
29
+ declare type ChapterInfo = {
30
+ title: string;
31
+ subChapter?: {
32
+ title: string;
33
+ subChapter?: {
34
+ title: string;
35
+ subChapter?: {
36
+ title: string;
37
+ path: string;
38
+ };
39
+ path: string;
40
+ };
41
+ path: string;
42
+ };
43
+ path: string;
44
+ };
45
+
29
46
  declare type Context = ReturnType<typeof createContext>;
30
47
 
31
48
  declare type Context_2 = {
@@ -2290,48 +2307,9 @@ export declare const createReader: (options: {
2290
2307
  }) => void);
2291
2308
  getPaginationInfo: () => PaginationInfo;
2292
2309
  paginationInfo$: Observable<PaginationInfo>;
2293
- }, "paginationInfo$"> & {
2294
- paginationInfo$: Observable<PaginationInfo & {
2295
- beginChapterInfo: {
2296
- title: string;
2297
- subChapter?: {
2298
- title: string;
2299
- subChapter?: {
2300
- title: string;
2301
- subChapter?: {
2302
- title: string;
2303
- path: string;
2304
- } | undefined;
2305
- path: string;
2306
- } | undefined;
2307
- path: string;
2308
- } | undefined;
2309
- path: string;
2310
- } | undefined;
2311
- beginSpineItemReadingDirection: "ltr" | "rtl" | undefined;
2312
- beginAbsolutePageIndex: number | undefined;
2313
- endChapterInfo: {
2314
- title: string;
2315
- subChapter?: {
2316
- title: string;
2317
- subChapter?: {
2318
- title: string;
2319
- subChapter?: {
2320
- title: string;
2321
- path: string;
2322
- } | undefined;
2323
- path: string;
2324
- } | undefined;
2325
- path: string;
2326
- } | undefined;
2327
- path: string;
2328
- } | undefined;
2329
- endSpineItemReadingDirection: "ltr" | "rtl" | undefined;
2330
- endAbsolutePageIndex: number | undefined;
2331
- percentageEstimateOfBook: number | undefined;
2332
- numberOfTotalPages: number | undefined;
2333
- isUsingSpread: boolean;
2334
- }>;
2310
+ }, "paginationInfo$" | "getPaginationInfo"> & {
2311
+ paginationInfo$: Observable<PaginationInfo & ExtraPaginationInfo>;
2312
+ getPaginationInfo: () => PaginationInfo & ExtraPaginationInfo;
2335
2313
  };
2336
2314
  } & {
2337
2315
  theme: {
@@ -3150,48 +3128,9 @@ export declare const createReader: (options: {
3150
3128
  }) => void);
3151
3129
  getPaginationInfo: () => PaginationInfo;
3152
3130
  paginationInfo$: Observable<PaginationInfo>;
3153
- }, "paginationInfo$"> & {
3154
- paginationInfo$: Observable<PaginationInfo & {
3155
- beginChapterInfo: {
3156
- title: string;
3157
- subChapter?: {
3158
- title: string;
3159
- subChapter?: {
3160
- title: string;
3161
- subChapter?: {
3162
- title: string;
3163
- path: string;
3164
- } | undefined;
3165
- path: string;
3166
- } | undefined;
3167
- path: string;
3168
- } | undefined;
3169
- path: string;
3170
- } | undefined;
3171
- beginSpineItemReadingDirection: "ltr" | "rtl" | undefined;
3172
- beginAbsolutePageIndex: number | undefined;
3173
- endChapterInfo: {
3174
- title: string;
3175
- subChapter?: {
3176
- title: string;
3177
- subChapter?: {
3178
- title: string;
3179
- subChapter?: {
3180
- title: string;
3181
- path: string;
3182
- } | undefined;
3183
- path: string;
3184
- } | undefined;
3185
- path: string;
3186
- } | undefined;
3187
- path: string;
3188
- } | undefined;
3189
- endSpineItemReadingDirection: "ltr" | "rtl" | undefined;
3190
- endAbsolutePageIndex: number | undefined;
3191
- percentageEstimateOfBook: number | undefined;
3192
- numberOfTotalPages: number | undefined;
3193
- isUsingSpread: boolean;
3194
- }>;
3131
+ }, "paginationInfo$" | "getPaginationInfo"> & {
3132
+ paginationInfo$: Observable<PaginationInfo & ExtraPaginationInfo>;
3133
+ getPaginationInfo: () => PaginationInfo & ExtraPaginationInfo;
3195
3134
  }, "paginationInfo$" | "getPaginationInfo">;
3196
3135
  };
3197
3136
 
@@ -4033,6 +3972,18 @@ declare type Event_2 = {
4033
3972
  data: ReturnType<typeof createSelection> | null;
4034
3973
  };
4035
3974
 
3975
+ declare type ExtraPaginationInfo = {
3976
+ beginChapterInfo: ChapterInfo | undefined;
3977
+ beginSpineItemReadingDirection: `rtl` | `ltr` | undefined;
3978
+ beginAbsolutePageIndex: number | undefined;
3979
+ endChapterInfo: ChapterInfo | undefined;
3980
+ endSpineItemReadingDirection: `rtl` | `ltr` | undefined;
3981
+ endAbsolutePageIndex: number | undefined;
3982
+ percentageEstimateOfBook: number | undefined;
3983
+ numberOfTotalPages: number | undefined;
3984
+ isUsingSpread: boolean;
3985
+ };
3986
+
4036
3987
  export declare const groupBy: <T, K extends string | number | symbol>(list: T[], getKey: (item: T) => K) => Record<K, T[]>;
4037
3988
 
4038
3989
  declare type Hook = ItemOnLoadHook | {
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { takeUntil, Subject, BehaviorSubject, map, combineLatest, switchMap, merge, EMPTY, fromEvent, withLatestFrom as withLatestFrom$1, NEVER, Observable, of, scheduled, animationFrameScheduler, distinctUntilChanged as distinctUntilChanged$1, filter as filter$1, from, interval, iif, identity, take as take$1, forkJoin } from "rxjs";
2
- import { withLatestFrom, distinctUntilChanged, shareReplay, tap, pairwise, switchMap as switchMap$1, filter, take, map as map$1, takeUntil as takeUntil$1, skip, debounceTime, startWith, share, exhaustMap, mergeMap, catchError, debounce, delay } from "rxjs/operators";
1
+ import { takeUntil, Subject, BehaviorSubject, map, combineLatest, switchMap, merge, EMPTY, fromEvent, withLatestFrom as withLatestFrom$1, NEVER, Observable, of, scheduled, animationFrameScheduler, distinctUntilChanged as distinctUntilChanged$1, startWith, filter as filter$1, debounceTime, combineLatestWith, tap as tap$1, shareReplay as shareReplay$1, from, interval, iif, identity, take as take$1, forkJoin } from "rxjs";
2
+ import { withLatestFrom, distinctUntilChanged, shareReplay, tap, pairwise, switchMap as switchMap$1, filter, take, map as map$1, takeUntil as takeUntil$1, skip, share, exhaustMap, mergeMap, catchError, debounce, debounceTime as debounceTime$1, startWith as startWith$1, delay } from "rxjs/operators";
3
3
  import { parseContentType, detectMimeTypeFromName } from "@prose-reader/shared";
4
4
  const chromeEnhancer = (next) => (options) => {
5
5
  const reader = next(options);
@@ -590,6 +590,63 @@ const navigationEnhancer = (next) => (options) => {
590
590
  }
591
591
  };
592
592
  };
593
+ const buildChaptersInfo = (href, tocItem, manifest) => {
594
+ const spineItemIndex = manifest.spineItems.findIndex((item) => item.href === href);
595
+ return tocItem.reduce((acc, tocItem2) => {
596
+ const indexOfHash = tocItem2.href.indexOf(`#`);
597
+ const tocItemPathWithoutAnchor = indexOfHash > 0 ? tocItem2.href.substr(0, indexOfHash) : tocItem2.href;
598
+ const tocItemHrefWithoutFilename = tocItemPathWithoutAnchor.substring(0, tocItemPathWithoutAnchor.lastIndexOf("/"));
599
+ const hrefWithoutFilename = href.substring(0, href.lastIndexOf("/"));
600
+ const hrefIsChapterHref = href.endsWith(tocItemPathWithoutAnchor);
601
+ const hrefIsWithinChapter = hrefWithoutFilename !== "" && hrefWithoutFilename.endsWith(tocItemHrefWithoutFilename);
602
+ const isPossibleTocItemCandidate = hrefIsChapterHref || hrefIsWithinChapter;
603
+ if (isPossibleTocItemCandidate) {
604
+ const spineItemIndexOfPossibleCandidate = manifest.spineItems.findIndex((item) => item.href === tocItem2.href);
605
+ const spineItemIsBeforeThisTocItem = spineItemIndex < spineItemIndexOfPossibleCandidate;
606
+ if (spineItemIsBeforeThisTocItem)
607
+ return acc;
608
+ const info = {
609
+ title: tocItem2.title,
610
+ path: tocItem2.path
611
+ };
612
+ const subInfo = buildChaptersInfo(href, tocItem2.contents, manifest);
613
+ if (subInfo) {
614
+ return {
615
+ ...info,
616
+ subChapter: subInfo
617
+ };
618
+ }
619
+ return info;
620
+ }
621
+ return acc;
622
+ }, void 0);
623
+ };
624
+ const buildChapterInfoFromSpineItem = (manifest, item) => {
625
+ var _a;
626
+ const { href } = item;
627
+ return buildChaptersInfo(href, ((_a = manifest.nav) == null ? void 0 : _a.toc) ?? [], manifest);
628
+ };
629
+ const getChaptersInfo = (reader) => {
630
+ const manifest = reader.context.getManifest();
631
+ const items = reader.getSpineItems();
632
+ if (!manifest)
633
+ return {};
634
+ return items.reduce(
635
+ (acc, { item }) => {
636
+ return {
637
+ ...acc,
638
+ [item.id]: buildChapterInfoFromSpineItem(manifest, item)
639
+ };
640
+ },
641
+ {}
642
+ );
643
+ };
644
+ const trackChapterInfo = (reader) => {
645
+ return reader.spineItems$.pipe(
646
+ startWith([]),
647
+ map(() => getChaptersInfo(reader))
648
+ );
649
+ };
593
650
  const NAMESPACE$6 = `pagination`;
594
651
  const createPagination = ({ context }) => {
595
652
  const paginationSubject$ = new BehaviorSubject({
@@ -602,16 +659,16 @@ const createPagination = ({ context }) => {
602
659
  endCfi: void 0,
603
660
  endSpineItemIndex: void 0
604
661
  });
605
- const getSpineItemNumberOfPages = (spineItem) => {
662
+ const getSpineItemNumberOfPages2 = (spineItem) => {
606
663
  const writingMode = spineItem.spineItemFrame.getWritingMode();
607
664
  const { width, height } = spineItem.getElementDimensions();
608
665
  if (writingMode === `vertical-rl`) {
609
- return getNumberOfPages(height, context.getPageSize().height);
666
+ return calculateNumberOfPagesForItem(height, context.getPageSize().height);
610
667
  }
611
- return getNumberOfPages(width, context.getPageSize().width);
668
+ return calculateNumberOfPagesForItem(width, context.getPageSize().width);
612
669
  };
613
670
  const getInfoForUpdate = (info) => {
614
- const numberOfPages = getSpineItemNumberOfPages(info.spineItem);
671
+ const numberOfPages = getSpineItemNumberOfPages2(info.spineItem);
615
672
  return {
616
673
  numberOfPages,
617
674
  pageIndex: info.pageIndex,
@@ -661,103 +718,39 @@ const getItemOffsetFromPageIndex = (pageWidth, pageIndex, itemWidth) => {
661
718
  const logicalOffset = itemWidth * (pageIndex * pageWidth) / itemWidth;
662
719
  return Math.max(0, Math.min(lastPageOffset, logicalOffset));
663
720
  };
664
- const getNumberOfPages = (itemWidth, pageWidth) => {
721
+ const calculateNumberOfPagesForItem = (itemWidth, pageWidth) => {
665
722
  if ((pageWidth || 0) === 0 || (itemWidth || 0) === 0)
666
723
  return 1;
667
724
  return Math.floor(Math.max(1, itemWidth / pageWidth));
668
725
  };
669
726
  const getClosestValidOffsetFromApproximateOffsetInPages = (offset, pageWidth, itemWidth) => {
670
- const numberOfPages = getNumberOfPages(itemWidth, pageWidth);
727
+ const numberOfPages = calculateNumberOfPagesForItem(itemWidth, pageWidth);
671
728
  const offsetValues = [...Array(numberOfPages)].map((_, i) => i * pageWidth);
672
729
  if (offset >= numberOfPages * pageWidth)
673
730
  return offsetValues[offsetValues.length - 1] || 0;
674
731
  return offsetValues.find((offsetRange) => offset < offsetRange + pageWidth) || 0;
675
732
  };
676
- const NAMESPACE$5 = `paginationEnhancer`;
677
- Report.namespace(NAMESPACE$5);
678
- const paginationEnhancer = (next) => (options) => {
679
- const reader = next(options);
680
- const chaptersInfo = {};
681
- const getChapterInfo2 = (item) => {
682
- const manifest = reader.context.getManifest();
683
- return item && manifest && buildChapterInfoFromSpineItem(manifest, item);
684
- };
685
- const mapPaginationInfoToExtendedInfo = (paginationInfo) => {
686
- const context = reader.context;
687
- const beginItem = paginationInfo.beginSpineItemIndex !== void 0 ? reader.getSpineItem(paginationInfo.beginSpineItemIndex) : void 0;
688
- const endItem = paginationInfo.endSpineItemIndex !== void 0 ? reader.getSpineItem(paginationInfo.endSpineItemIndex) : void 0;
689
- return {
690
- ...paginationInfo,
691
- beginChapterInfo: beginItem ? chaptersInfo[beginItem.item.id] : void 0,
692
- // chapterIndex: number;
693
- // pages: number;
694
- // pageIndexInBook: number;
695
- // pageIndexInChapter: number;
696
- // pagesOfChapter: number;
697
- // pagePercentageInChapter: number;
698
- // offsetPercentageInChapter: number;
699
- // domIndex: number;
700
- // charOffset: number;
701
- // serializeString?: string;
702
- beginSpineItemReadingDirection: beginItem == null ? void 0 : beginItem.getReadingDirection(),
703
- endChapterInfo: endItem ? chaptersInfo[endItem.item.id] : void 0,
704
- endSpineItemReadingDirection: endItem == null ? void 0 : endItem.getReadingDirection(),
705
- // spineItemReadingDirection: focusedSpineItem?.getReadingDirection(),
706
- /**
707
- * This percentage is based of the weight (kb) of every items and the number of pages.
708
- * It is not accurate but gives a general good idea of the overall progress.
709
- * It is recommended to use this progress only for reflow books. For pre-paginated books
710
- * the number of pages and current index can be used instead since 1 page = 1 chapter.
711
- */
712
- percentageEstimateOfBook: endItem ? reader.progression.getPercentageEstimate(
713
- context,
714
- paginationInfo.endSpineItemIndex ?? 0,
715
- paginationInfo.endNumberOfPagesInSpineItem,
716
- paginationInfo.endPageIndexInSpineItem || 0,
717
- reader.getCurrentViewportPosition(),
718
- endItem
719
- ) : 0,
720
- isUsingSpread: context.isUsingSpreadMode() ?? false
721
- // hasNextChapter: (reader.spine.spineItemIndex || 0) < (manifest.readingOrder.length - 1),
722
- // hasPreviousChapter: (reader.spine.spineItemIndex || 0) < (manifest.readingOrder.length - 1),
723
- // numberOfSpineItems: context.getManifest()?.readingOrder.length,
724
- };
725
- };
726
- const getSpineItemNumberOfPages = (spineItem) => {
727
- const writingMode = spineItem.spineItemFrame.getWritingMode();
728
- const { width, height } = spineItem.getElementDimensions();
729
- const settings = reader.settings.getSettings();
730
- if (settings.pageTurnDirection === `vertical` && settings.pageTurnMode === `scrollable`) {
731
- return 1;
732
- }
733
- if (writingMode === `vertical-rl`) {
734
- return getNumberOfPages(height, reader.context.getPageSize().height);
735
- }
736
- return getNumberOfPages(width, reader.context.getPageSize().width);
737
- };
738
- const getNumberOfPagesPerItems = () => reader.getSpineItems().map((item) => {
739
- return getSpineItemNumberOfPages(item);
740
- }, 0);
741
- reader.spineItems$.pipe(
742
- tap(
743
- (items) => items.forEach(({ item }) => {
744
- chaptersInfo[item.id] = getChapterInfo2(item);
745
- })
746
- ),
747
- takeUntil$1(reader.$.destroy$)
748
- ).subscribe();
749
- const innerPaginationExtendedInfo$ = reader.pagination.paginationInfo$.pipe(
750
- map$1((info) => ({
751
- ...info,
752
- ...mapPaginationInfoToExtendedInfo(info)
753
- })),
754
- distinctUntilChanged(isShallowEqual)
755
- );
733
+ const getSpineItemNumberOfPages = ({ spineItem, reader }) => {
734
+ const writingMode = spineItem.spineItemFrame.getWritingMode();
735
+ const { width, height } = spineItem.getElementDimensions();
736
+ const settings = reader.settings.getSettings();
737
+ if (settings.pageTurnDirection === `vertical` && settings.pageTurnMode === `scrollable`) {
738
+ return 1;
739
+ }
740
+ if (writingMode === `vertical-rl`) {
741
+ return calculateNumberOfPagesForItem(height, reader.context.getPageSize().height);
742
+ }
743
+ return calculateNumberOfPagesForItem(width, reader.context.getPageSize().width);
744
+ };
745
+ const getNumberOfPagesForAllSpineItems = (reader) => reader.getSpineItems().map((item) => {
746
+ return getSpineItemNumberOfPages({ spineItem: item, reader });
747
+ }, 0);
748
+ const trackTotalPages = (reader) => {
756
749
  const totalPages$ = reader.$.layout$.pipe(
757
750
  debounceTime(10, animationFrameScheduler),
758
- withLatestFrom(reader.pagination.paginationInfo$),
759
- map$1(() => {
760
- const numberOfPagesPerItems = getNumberOfPagesPerItems();
751
+ withLatestFrom$1(reader.pagination.paginationInfo$),
752
+ map(() => {
753
+ const numberOfPagesPerItems = getNumberOfPagesForAllSpineItems(reader);
761
754
  return {
762
755
  numberOfPagesPerItems,
763
756
  /**
@@ -766,69 +759,102 @@ const paginationEnhancer = (next) => (options) => {
766
759
  numberOfTotalPages: numberOfPagesPerItems.reduce((acc, numberOfPagesForItem) => acc + numberOfPagesForItem, 0)
767
760
  };
768
761
  }),
769
- distinctUntilChanged(isShallowEqual),
762
+ distinctUntilChanged$1(isShallowEqual),
770
763
  startWith({
771
764
  numberOfPagesPerItems: [],
772
765
  numberOfTotalPages: 0
773
766
  })
774
767
  );
775
- const paginationInfo$ = combineLatest([
776
- innerPaginationExtendedInfo$,
777
- totalPages$
778
- ]).pipe(
779
- map$1(([pageInfo, totalPageInfo]) => ({
768
+ return totalPages$;
769
+ };
770
+ const mapPaginationInfoToExtendedInfo = (reader) => (paginationInfo, chaptersInfo) => {
771
+ const context = reader.context;
772
+ const beginItem = paginationInfo.beginSpineItemIndex !== void 0 ? reader.getSpineItem(paginationInfo.beginSpineItemIndex) : void 0;
773
+ const endItem = paginationInfo.endSpineItemIndex !== void 0 ? reader.getSpineItem(paginationInfo.endSpineItemIndex) : void 0;
774
+ return {
775
+ ...paginationInfo,
776
+ beginChapterInfo: beginItem ? chaptersInfo[beginItem.item.id] : void 0,
777
+ // chapterIndex: number;
778
+ // pages: number;
779
+ // pageIndexInBook: number;
780
+ // pageIndexInChapter: number;
781
+ // pagesOfChapter: number;
782
+ // pagePercentageInChapter: number;
783
+ // offsetPercentageInChapter: number;
784
+ // domIndex: number;
785
+ // charOffset: number;
786
+ // serializeString?: string;
787
+ beginSpineItemReadingDirection: beginItem == null ? void 0 : beginItem.getReadingDirection(),
788
+ endChapterInfo: endItem ? chaptersInfo[endItem.item.id] : void 0,
789
+ endSpineItemReadingDirection: endItem == null ? void 0 : endItem.getReadingDirection(),
790
+ // spineItemReadingDirection: focusedSpineItem?.getReadingDirection(),
791
+ /**
792
+ * This percentage is based of the weight (kb) of every items and the number of pages.
793
+ * It is not accurate but gives a general good idea of the overall progress.
794
+ * It is recommended to use this progress only for reflow books. For pre-paginated books
795
+ * the number of pages and current index can be used instead since 1 page = 1 chapter.
796
+ */
797
+ percentageEstimateOfBook: endItem ? reader.progression.getPercentageEstimate(
798
+ context,
799
+ paginationInfo.endSpineItemIndex ?? 0,
800
+ paginationInfo.endNumberOfPagesInSpineItem,
801
+ paginationInfo.endPageIndexInSpineItem || 0,
802
+ reader.getCurrentViewportPosition(),
803
+ endItem
804
+ ) : 0,
805
+ isUsingSpread: context.isUsingSpreadMode() ?? false
806
+ // hasNextChapter: (reader.spine.spineItemIndex || 0) < (manifest.readingOrder.length - 1),
807
+ // hasPreviousChapter: (reader.spine.spineItemIndex || 0) < (manifest.readingOrder.length - 1),
808
+ // numberOfSpineItems: context.getManifest()?.readingOrder.length,
809
+ };
810
+ };
811
+ const trackPaginationInfo = (reader) => {
812
+ const chaptersInfo$ = trackChapterInfo(reader);
813
+ const totalPages$ = trackTotalPages(reader);
814
+ const currentValue = new BehaviorSubject({
815
+ ...reader.pagination.getPaginationInfo(),
816
+ ...mapPaginationInfoToExtendedInfo(reader)(reader.pagination.getPaginationInfo(), getChaptersInfo(reader)),
817
+ beginAbsolutePageIndex: 0,
818
+ endAbsolutePageIndex: 0,
819
+ numberOfTotalPages: 0
820
+ });
821
+ const extandedBasePagination$ = reader.pagination.paginationInfo$.pipe(
822
+ combineLatestWith(chaptersInfo$),
823
+ map(([info, chaptersInfo]) => ({
824
+ ...info,
825
+ ...mapPaginationInfoToExtendedInfo(reader)(info, chaptersInfo)
826
+ })),
827
+ distinctUntilChanged$1(isShallowEqual)
828
+ );
829
+ const paginationInfo$ = combineLatest([extandedBasePagination$, totalPages$]).pipe(
830
+ map(([pageInfo, totalPageInfo]) => ({
780
831
  ...pageInfo,
781
832
  ...totalPageInfo,
782
833
  beginAbsolutePageIndex: totalPageInfo.numberOfPagesPerItems.slice(0, pageInfo.beginSpineItemIndex).reduce((acc, numberOfPagesForItem) => acc + numberOfPagesForItem, pageInfo.beginPageIndexInSpineItem ?? 0),
783
834
  endAbsolutePageIndex: totalPageInfo.numberOfPagesPerItems.slice(0, pageInfo.endSpineItemIndex).reduce((acc, numberOfPagesForItem) => acc + numberOfPagesForItem, pageInfo.endPageIndexInSpineItem ?? 0)
784
835
  })),
785
- shareReplay(1),
786
- takeUntil$1(reader.$.destroy$)
836
+ tap$1((value) => {
837
+ currentValue.next(value);
838
+ }),
839
+ shareReplay$1(1)
787
840
  );
841
+ return { paginationInfo$, getPaginationInfo: () => currentValue.value };
842
+ };
843
+ const NAMESPACE$5 = `paginationEnhancer`;
844
+ Report.namespace(NAMESPACE$5);
845
+ const paginationEnhancer = (next) => (options) => {
846
+ const reader = next(options);
847
+ const { paginationInfo$, getPaginationInfo } = trackPaginationInfo(reader);
848
+ paginationInfo$.pipe(takeUntil(reader.$.destroy$)).subscribe();
788
849
  return {
789
850
  ...reader,
790
851
  pagination: {
791
852
  ...reader.pagination,
853
+ getPaginationInfo,
792
854
  paginationInfo$
793
855
  }
794
856
  };
795
857
  };
796
- const buildChapterInfoFromSpineItem = (manifest, item) => {
797
- var _a;
798
- const { href } = item;
799
- return getChapterInfo(href, ((_a = manifest.nav) == null ? void 0 : _a.toc) ?? [], manifest);
800
- };
801
- const getChapterInfo = (href, tocItem, manifest) => {
802
- const spineItemIndex = manifest.spineItems.findIndex((item) => item.href === href);
803
- return tocItem.reduce((acc, tocItem2) => {
804
- const indexOfHash = tocItem2.href.indexOf(`#`);
805
- const tocItemPathWithoutAnchor = indexOfHash > 0 ? tocItem2.href.substr(0, indexOfHash) : tocItem2.href;
806
- const tocItemHrefWithoutFilename = tocItemPathWithoutAnchor.substring(0, tocItemPathWithoutAnchor.lastIndexOf("/"));
807
- const hrefWithoutFilename = href.substring(0, href.lastIndexOf("/"));
808
- const hrefIsChapterHref = href.endsWith(tocItemPathWithoutAnchor);
809
- const hrefIsWithinChapter = hrefWithoutFilename !== "" && hrefWithoutFilename.endsWith(tocItemHrefWithoutFilename);
810
- const isPossibleTocItemCandidate = hrefIsChapterHref || hrefIsWithinChapter;
811
- if (isPossibleTocItemCandidate) {
812
- const spineItemIndexOfPossibleCandidate = manifest.spineItems.findIndex((item) => item.href === tocItem2.href);
813
- const spineItemIsBeforeThisTocItem = spineItemIndex < spineItemIndexOfPossibleCandidate;
814
- if (spineItemIsBeforeThisTocItem)
815
- return acc;
816
- const info = {
817
- title: tocItem2.title,
818
- path: tocItem2.path
819
- };
820
- const subInfo = getChapterInfo(href, tocItem2.contents, manifest);
821
- if (subInfo) {
822
- return {
823
- ...info,
824
- subChapter: subInfo
825
- };
826
- }
827
- return info;
828
- }
829
- return acc;
830
- }, void 0);
831
- };
832
858
  const defaultThemes = [
833
859
  {
834
860
  name: `bright`,
@@ -4313,10 +4339,10 @@ const createLocationResolver$1 = ({ context }) => {
4313
4339
  const safePosition = getSafePosition(position, spineItem);
4314
4340
  const offset = context.isRTL() ? itemWidth - safePosition.x - context.getPageSize().width : safePosition.x;
4315
4341
  if (spineItem.isUsingVerticalWriting()) {
4316
- const numberOfPages = getNumberOfPages(itemHeight, pageHeight);
4342
+ const numberOfPages = calculateNumberOfPagesForItem(itemHeight, pageHeight);
4317
4343
  return getPageFromOffset(position.y, pageHeight, numberOfPages);
4318
4344
  } else {
4319
- const numberOfPages = getNumberOfPages(itemWidth, pageWidth);
4345
+ const numberOfPages = calculateNumberOfPagesForItem(itemWidth, pageWidth);
4320
4346
  const pageIndex = getPageFromOffset(offset, pageWidth, numberOfPages);
4321
4347
  return pageIndex;
4322
4348
  }
@@ -4437,11 +4463,11 @@ const createNavigationResolver$1 = ({ context }) => {
4437
4463
  const getNavigationForLastPage = (spineItem) => {
4438
4464
  if (spineItem.isUsingVerticalWriting()) {
4439
4465
  const pageHeight = context.getPageSize().height;
4440
- const numberOfPages = getNumberOfPages(spineItem.getElementDimensions().height, pageHeight);
4466
+ const numberOfPages = calculateNumberOfPagesForItem(spineItem.getElementDimensions().height, pageHeight);
4441
4467
  return getNavigationForPage(numberOfPages - 1, spineItem);
4442
4468
  } else {
4443
4469
  const pageWidth = context.getPageSize().width;
4444
- const numberOfPages = getNumberOfPages(spineItem.getElementDimensions().width, pageWidth);
4470
+ const numberOfPages = calculateNumberOfPagesForItem(spineItem.getElementDimensions().width, pageWidth);
4445
4471
  return getNavigationForPage(numberOfPages - 1, spineItem);
4446
4472
  }
4447
4473
  };
@@ -4763,7 +4789,7 @@ const createScrollViewportNavigator = ({
4763
4789
  return getScaledDownPosition({ x: ((_a = element$.getValue()) == null ? void 0 : _a.scrollLeft) ?? 0, y: ((_b = element$.getValue()) == null ? void 0 : _b.scrollTop) ?? 0 });
4764
4790
  };
4765
4791
  const navigationOnScroll$ = userScroll$.pipe(
4766
- debounceTime(SCROLL_FINISHED_DEBOUNCE_TIMEOUT, animationFrameScheduler),
4792
+ debounceTime$1(SCROLL_FINISHED_DEBOUNCE_TIMEOUT, animationFrameScheduler),
4767
4793
  withLatestFrom(currentNavigationSubject$),
4768
4794
  switchMap$1(() => {
4769
4795
  var _a, _b;
@@ -4775,7 +4801,7 @@ const createScrollViewportNavigator = ({
4775
4801
  share()
4776
4802
  );
4777
4803
  const userScrollEnd$ = userScroll$.pipe(
4778
- debounceTime(SCROLL_FINISHED_DEBOUNCE_TIMEOUT, animationFrameScheduler),
4804
+ debounceTime$1(SCROLL_FINISHED_DEBOUNCE_TIMEOUT, animationFrameScheduler),
4779
4805
  share(),
4780
4806
  takeUntil$1(context.$.destroy$)
4781
4807
  );
@@ -4785,7 +4811,7 @@ const createScrollViewportNavigator = ({
4785
4811
  distinctUntilChanged()
4786
4812
  ),
4787
4813
  userScrollEnd$.pipe(map$1(() => `end`))
4788
- ).pipe(startWith(`end`));
4814
+ ).pipe(startWith$1(`end`));
4789
4815
  return {
4790
4816
  destroy: () => {
4791
4817
  },
@@ -5344,7 +5370,7 @@ const createViewportNavigator = ({
5344
5370
  share()
5345
5371
  );
5346
5372
  const processManualAdjust$ = merge(manualAdjust$).pipe(
5347
- startWith(void 0),
5373
+ startWith$1(void 0),
5348
5374
  pairwise(),
5349
5375
  tap(([prevEvent, currentEvent]) => {
5350
5376
  if ((prevEvent == null ? void 0 : prevEvent.type) === `manualAdjust` && (currentEvent == null ? void 0 : currentEvent.type) !== `manualAdjust`) {