@prose-reader/core 1.14.0 → 1.15.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/prose.js CHANGED
@@ -2760,28 +2760,34 @@ const paginationEnhancer = (next) => (options) => {
2760
2760
  const buildChapterInfoFromSpineItem = (manifest, item) => {
2761
2761
  var _a;
2762
2762
  const { href } = item;
2763
- return getChapterInfo(href, ((_a = manifest.nav) == null ? void 0 : _a.toc) ?? []);
2763
+ return getChapterInfo(href, ((_a = manifest.nav) == null ? void 0 : _a.toc) ?? [], manifest);
2764
2764
  };
2765
- const getChapterInfo = (href, tocItems) => {
2766
- return tocItems.reduce((acc, tocItem) => {
2767
- const indexOfHash = tocItem.href.indexOf(`#`);
2768
- const tocItemPathWithoutAnchor = indexOfHash > 0 ? tocItem.href.substr(0, indexOfHash) : tocItem.href;
2765
+ const getChapterInfo = (href, tocItem, manifest) => {
2766
+ const spineItemIndex = manifest.spineItems.findIndex((item) => item.href === href);
2767
+ return tocItem.reduce((acc, tocItem2) => {
2768
+ const indexOfHash = tocItem2.href.indexOf(`#`);
2769
+ const tocItemPathWithoutAnchor = indexOfHash > 0 ? tocItem2.href.substr(0, indexOfHash) : tocItem2.href;
2769
2770
  const tocItemHrefWithoutFilename = tocItemPathWithoutAnchor.substring(0, tocItemPathWithoutAnchor.lastIndexOf("/"));
2770
2771
  const hrefWithoutFilename = href.substring(0, href.lastIndexOf("/"));
2771
2772
  const hrefIsChapterHref = href.endsWith(tocItemPathWithoutAnchor);
2772
2773
  const hrefIsWithinChapter = hrefWithoutFilename !== "" && hrefWithoutFilename.endsWith(tocItemHrefWithoutFilename);
2773
- if (hrefIsChapterHref || hrefIsWithinChapter) {
2774
+ const isPossibleTocItemCandidate = hrefIsChapterHref || hrefIsWithinChapter;
2775
+ if (isPossibleTocItemCandidate) {
2776
+ const spineItemIndexOfPossibleCandidate = manifest.spineItems.findIndex((item) => item.href === tocItem2.href);
2777
+ const spineItemIsBeforeThisTocItem = spineItemIndex < spineItemIndexOfPossibleCandidate;
2778
+ if (spineItemIsBeforeThisTocItem)
2779
+ return acc;
2774
2780
  return {
2775
- title: tocItem.title,
2776
- path: tocItem.path
2781
+ title: tocItem2.title,
2782
+ path: tocItem2.path
2777
2783
  };
2778
2784
  }
2779
- const subInfo = getChapterInfo(href, tocItem.contents);
2785
+ const subInfo = getChapterInfo(href, tocItem2.contents, manifest);
2780
2786
  if (subInfo) {
2781
2787
  return {
2782
2788
  subChapter: subInfo,
2783
- title: tocItem.title,
2784
- path: tocItem.path
2789
+ title: tocItem2.title,
2790
+ path: tocItem2.path
2785
2791
  };
2786
2792
  }
2787
2793
  return acc;