@prose-reader/core 1.195.0 → 1.197.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.
@@ -3308,8 +3308,8 @@
3308
3308
  };
3309
3309
  const getScrollPercentageWithinItem = (reader, currentPosition, currentItem) => {
3310
3310
  const context = reader.context;
3311
- const { height, width } = currentItem.layoutPosition;
3312
- const { top, left } = reader.spine.spineLayout.getAbsolutePositionOf(currentItem);
3311
+ const { height, width } = currentItem.layout.layoutInfo;
3312
+ const { top, left } = reader.spine.spineLayout.getSpineItemRelativeLayoutInfo(currentItem);
3313
3313
  if (reader.settings.values.computedPageTurnDirection === `vertical`) {
3314
3314
  return Math.max(
3315
3315
  0,
@@ -3371,29 +3371,22 @@
3371
3371
  })
3372
3372
  );
3373
3373
  };
3374
- const getNumberOfPagesForAllSpineItems = (reader) => reader.spineItemsManager.items.map((item) => {
3375
- const { height, width } = item.layoutPosition;
3376
- return reader.spine.spineItemLocator.getSpineItemNumberOfPages({
3377
- isUsingVerticalWriting: !!item.isUsingVerticalWriting(),
3378
- itemHeight: height,
3379
- itemWidth: width
3380
- });
3381
- }, 0);
3382
3374
  const trackTotalPages = (reader) => {
3383
3375
  const totalPages$ = reader.layout$.pipe(
3384
3376
  rxjs.debounceTime(10, rxjs.animationFrameScheduler),
3385
3377
  rxjs.withLatestFrom(reader.pagination.state$),
3386
3378
  rxjs.map(() => {
3387
- const numberOfPagesPerItems = getNumberOfPagesForAllSpineItems(reader);
3388
3379
  return {
3389
- numberOfPagesPerItems,
3380
+ numberOfPagesPerItems: reader.spineItemsManager.items.reduce(
3381
+ (acc, item) => {
3382
+ return [...acc, item.numberOfPages];
3383
+ },
3384
+ []
3385
+ ),
3390
3386
  /**
3391
3387
  * This may be not accurate for reflowable due to dynamic load / unload.
3392
3388
  */
3393
- numberOfTotalPages: numberOfPagesPerItems.reduce(
3394
- (acc, numberOfPagesForItem) => acc + numberOfPagesForItem,
3395
- 0
3396
- )
3389
+ numberOfTotalPages: reader.spine.spineLayout.numberOfPages
3397
3390
  };
3398
3391
  }),
3399
3392
  rxjs.distinctUntilChanged(shared.isShallowEqual),
@@ -5572,7 +5565,7 @@
5572
5565
  const range = node ? getRangeFromNode(node, offset) : void 0;
5573
5566
  offsetOfNodeInSpineItem = (range == null ? void 0 : range.getBoundingClientRect().x) || offsetOfNodeInSpineItem;
5574
5567
  }
5575
- const spineItemWidth = ((_a = spineItem.layoutPosition) == null ? void 0 : _a.width) || 0;
5568
+ const spineItemWidth = ((_a = spineItem.layout.layoutInfo) == null ? void 0 : _a.width) || 0;
5576
5569
  const pageWidth = context.getPageSize().width;
5577
5570
  if (offsetOfNodeInSpineItem !== void 0) {
5578
5571
  const val = getClosestValidOffsetFromApproximateOffsetInPages(
@@ -5592,7 +5585,7 @@
5592
5585
  frame.contentWindow.document.body !== null) {
5593
5586
  const { x: left, y: top } = getSpineItemPositionFromPageIndex({
5594
5587
  pageIndex,
5595
- itemLayout: spineItem.layoutPosition,
5588
+ itemLayout: spineItem.layout.layoutInfo,
5596
5589
  context,
5597
5590
  isUsingVerticalWriting: !!spineItem.isUsingVerticalWriting()
5598
5591
  });
@@ -5611,7 +5604,7 @@
5611
5604
  return void 0;
5612
5605
  };
5613
5606
  const getSpineItemClosestPositionFromUnsafePosition = (unsafePosition, spineItem) => {
5614
- const { width, height } = spineItem.layoutPosition;
5607
+ const { width, height } = spineItem.layout.layoutInfo;
5615
5608
  const adjustedPosition = {
5616
5609
  x: getClosestValidOffsetFromApproximateOffsetInPages(
5617
5610
  unsafePosition.x,
@@ -5628,7 +5621,7 @@
5628
5621
  };
5629
5622
  const getSpineItemPageIndexFromNode = (node, offset, spineItem) => {
5630
5623
  const position = getSpineItemPositionFromNode(node, offset, spineItem);
5631
- const { height, width } = spineItem.layoutPosition;
5624
+ const { height, width } = spineItem.layout.layoutInfo;
5632
5625
  return position ? getSpineItemPageIndexFromPosition({
5633
5626
  isUsingVerticalWriting: !!spineItem.isUsingVerticalWriting(),
5634
5627
  position,
@@ -5666,14 +5659,9 @@
5666
5659
  context,
5667
5660
  isUsingVerticalWriting: !!item.isUsingVerticalWriting(),
5668
5661
  settings,
5669
- itemLayout: item.layoutPosition
5662
+ itemLayout: item.layout.layoutInfo
5670
5663
  });
5671
- },
5672
- getSpineItemNumberOfPages: (params) => getSpineItemNumberOfPages({
5673
- context,
5674
- settings,
5675
- ...params
5676
- })
5664
+ }
5677
5665
  };
5678
5666
  };
5679
5667
  const createNavigationResolver$1 = ({
@@ -5682,16 +5670,11 @@
5682
5670
  }) => {
5683
5671
  const spineItemLocator = createSpineItemLocator({ context, settings });
5684
5672
  const getNavigationForLastPage = (spineItem) => {
5685
- const { height, width } = spineItem.layoutPosition;
5686
- const numberOfPages = spineItemLocator.getSpineItemNumberOfPages({
5687
- isUsingVerticalWriting: !!spineItem.isUsingVerticalWriting(),
5688
- itemHeight: height,
5689
- itemWidth: width
5690
- });
5673
+ const numberOfPages = spineItem.numberOfPages;
5691
5674
  return spineItemLocator.getSpineItemPositionFromPageIndex({
5692
5675
  pageIndex: numberOfPages - 1,
5693
5676
  isUsingVerticalWriting: !!spineItem.isUsingVerticalWriting(),
5694
- itemLayout: spineItem.layoutPosition
5677
+ itemLayout: spineItem.layout.layoutInfo
5695
5678
  });
5696
5679
  };
5697
5680
  const getNavigationFromNode = (spineItem, node, offset) => {
@@ -5735,7 +5718,7 @@
5735
5718
  const lastSpineItem = spineItemsManager.get(
5736
5719
  spineItemsManager.items.length - 1
5737
5720
  );
5738
- const distanceOfLastSpineItem = spineLayout.getAbsolutePositionOf(
5721
+ const distanceOfLastSpineItem = spineLayout.getSpineItemRelativeLayoutInfo(
5739
5722
  lastSpineItem || 0
5740
5723
  );
5741
5724
  const maximumYOffset = distanceOfLastSpineItem.bottom - pageSizeHeight;
@@ -5758,7 +5741,7 @@
5758
5741
  context
5759
5742
  }) => {
5760
5743
  var _a;
5761
- const itemWidth = ((_a = spineItem.layoutPosition) == null ? void 0 : _a.width) || 0;
5744
+ const itemWidth = ((_a = spineItem.layout.layoutInfo) == null ? void 0 : _a.width) || 0;
5762
5745
  const pageWidth = context.getPageSize().width;
5763
5746
  const anchorElementBoundingRect = spineItem.getBoundingRectOfElementFromSelector(anchor);
5764
5747
  const offsetOfAnchor = (anchorElementBoundingRect == null ? void 0 : anchorElementBoundingRect.x) || 0;
@@ -5917,7 +5900,7 @@
5917
5900
  const spineItemNavigation = spineLocator.spineItemLocator.getSpineItemPositionFromPageIndex({
5918
5901
  pageIndex,
5919
5902
  isUsingVerticalWriting: !!spineItem.isUsingVerticalWriting(),
5920
- itemLayout: spineItem.layoutPosition
5903
+ itemLayout: spineItem.layout.layoutInfo
5921
5904
  });
5922
5905
  const readingOffset = spineLocator.getSpinePositionFromSpineItemPosition({
5923
5906
  spineItemPosition: spineItemNavigation,
@@ -6628,9 +6611,7 @@
6628
6611
  const withSpineItemLayoutInfo = ({ spine }) => (stream) => {
6629
6612
  return stream.pipe(
6630
6613
  rxjs.switchMap(({ navigation, ...rest }) => {
6631
- const spineItemDimensions = spine.spineLayout.getAbsolutePositionOf(
6632
- navigation.spineItem
6633
- );
6614
+ const spineItemDimensions = spine.spineLayout.getSpineItemRelativeLayoutInfo(navigation.spineItem);
6634
6615
  const spineItem = spine.spineItemsManager.get(navigation.spineItem);
6635
6616
  return ((spineItem == null ? void 0 : spineItem.isReady$) ?? rxjs.of(false)).pipe(
6636
6617
  rxjs.first(),
@@ -6684,7 +6665,7 @@
6684
6665
  const positionInSpineItem = spineLocator.spineItemLocator.getSpineItemPositionFromPageIndex({
6685
6666
  pageIndex: beginPageIndexForDirection,
6686
6667
  isUsingVerticalWriting: !!spineItem.isUsingVerticalWriting(),
6687
- itemLayout: spineItem.layoutPosition
6668
+ itemLayout: spineItem.layout.layoutInfo
6688
6669
  });
6689
6670
  return positionInSpineItem;
6690
6671
  }
@@ -6745,7 +6726,7 @@
6745
6726
  rxjs.first(),
6746
6727
  rxjs.map((isReady) => {
6747
6728
  var _a, _b;
6748
- const spineItemAbsolutePosition = spineLayout.getAbsolutePositionOf(spineItem);
6729
+ const spineItemAbsolutePosition = spineLayout.getSpineItemRelativeLayoutInfo(spineItem);
6749
6730
  const isPositionWithinSpineItem = spineLocator.isPositionWithinSpineItem(
6750
6731
  navigation.position,
6751
6732
  spineItem
@@ -6816,7 +6797,7 @@
6816
6797
  const { spineItem } = navigation;
6817
6798
  const foundSpineItem = spineItemsManager.get(spineItem);
6818
6799
  if (!foundSpineItem) return { x: 0, y: 0 };
6819
- const { height, top } = spineLayout.getAbsolutePositionOf(foundSpineItem);
6800
+ const { height, top } = spineLayout.getSpineItemRelativeLayoutInfo(foundSpineItem);
6820
6801
  const isPositionWithinSpineItem = spineLocator.isPositionWithinSpineItem(
6821
6802
  navigation.position,
6822
6803
  foundSpineItem
@@ -7383,18 +7364,8 @@
7383
7364
  const shouldUpdateEndCfi = previousPagination.endSpineItemIndex !== endSpineItemIndex || endLastCfi === void 0 || isRootCfi(endLastCfi);
7384
7365
  const beginCfi = shouldUpdateBeginCfi ? getRootCfi(beginSpineItem) : beginLastCfi;
7385
7366
  const endCfi = shouldUpdateEndCfi ? getRootCfi(endSpineItem) : endLastCfi;
7386
- const beginSpineItemDimensions = beginSpineItem.layoutPosition;
7387
- const beginNumberOfPagesInSpineItem = this.spineItemLocator.getSpineItemNumberOfPages({
7388
- itemHeight: beginSpineItemDimensions.height,
7389
- itemWidth: beginSpineItemDimensions.width,
7390
- isUsingVerticalWriting: !!beginSpineItem.isUsingVerticalWriting()
7391
- });
7392
- const endSpineItemDimensions = endSpineItem.layoutPosition;
7393
- const endNumberOfPagesInSpineItem = this.spineItemLocator.getSpineItemNumberOfPages({
7394
- itemHeight: endSpineItemDimensions.height,
7395
- itemWidth: endSpineItemDimensions.width,
7396
- isUsingVerticalWriting: !!endSpineItem.isUsingVerticalWriting()
7397
- });
7367
+ const beginNumberOfPagesInSpineItem = beginSpineItem.numberOfPages;
7368
+ const endNumberOfPagesInSpineItem = endSpineItem.numberOfPages;
7398
7369
  this.pagination.update({
7399
7370
  beginCfi,
7400
7371
  beginNumberOfPagesInSpineItem,
@@ -7567,10 +7538,7 @@
7567
7538
  const getAbsolutePageIndexFromPageIndex = ({
7568
7539
  pageIndex,
7569
7540
  spineItemOrId,
7570
- spineLayout,
7571
- spineItemsManager,
7572
- context,
7573
- settings
7541
+ spineItemsManager
7574
7542
  }) => {
7575
7543
  const items = spineItemsManager.items;
7576
7544
  const spineItem = spineItemsManager.get(spineItemOrId);
@@ -7578,14 +7546,7 @@
7578
7546
  const { currentAbsolutePage } = items.reduce(
7579
7547
  (acc, item) => {
7580
7548
  if (acc.found) return acc;
7581
- const itemLayout = spineLayout.getAbsolutePositionOf(item);
7582
- const numberOfPages = getSpineItemNumberOfPages({
7583
- isUsingVerticalWriting: !!item.isUsingVerticalWriting(),
7584
- itemHeight: itemLayout.height,
7585
- itemWidth: itemLayout.width,
7586
- context,
7587
- settings
7588
- });
7549
+ const numberOfPages = item.numberOfPages;
7589
7550
  if (spineItem === item) {
7590
7551
  if (pageIndex <= numberOfPages - 1) {
7591
7552
  return {
@@ -7679,23 +7640,13 @@
7679
7640
  };
7680
7641
  const getSpineInfoFromAbsolutePageIndex = ({
7681
7642
  absolutePageIndex,
7682
- spineLayout,
7683
- spineItemsManager,
7684
- context,
7685
- settings
7643
+ spineItemsManager
7686
7644
  }) => {
7687
7645
  const items = spineItemsManager.items;
7688
7646
  const { found, currentAbsolutePage } = items.reduce(
7689
7647
  (acc, item) => {
7690
7648
  if (acc.found) return acc;
7691
- const itemLayout = spineLayout.getAbsolutePositionOf(item);
7692
- const numberOfPages = getSpineItemNumberOfPages({
7693
- isUsingVerticalWriting: !!item.isUsingVerticalWriting(),
7694
- itemHeight: itemLayout.height,
7695
- itemWidth: itemLayout.width,
7696
- context,
7697
- settings
7698
- });
7649
+ const numberOfPages = item.numberOfPages;
7699
7650
  const possiblePageIndex = absolutePageIndex - acc.currentAbsolutePage;
7700
7651
  const currentAbsolutePage2 = acc.currentAbsolutePage + numberOfPages;
7701
7652
  if (possiblePageIndex <= numberOfPages - 1) {
@@ -7729,7 +7680,7 @@
7729
7680
  settings
7730
7681
  }) => {
7731
7682
  const spineItem = spineItemsManager.items.find((item) => {
7732
- const { left, right, bottom, top } = spineLayout.getAbsolutePositionOf(item);
7683
+ const { left, right, bottom, top } = spineLayout.getSpineItemRelativeLayoutInfo(item);
7733
7684
  const isWithinXAxis = position.x >= left && position.x < right;
7734
7685
  if (settings.values.computedPageTurnDirection === `horizontal`) {
7735
7686
  return isWithinXAxis;
@@ -7767,7 +7718,7 @@
7767
7718
  }) || spineItemsManager.get(0);
7768
7719
  const spineItemsVisible = spineItemsManager.items.reduce(
7769
7720
  (acc, spineItem) => {
7770
- const itemPosition = spineLayout.getAbsolutePositionOf(spineItem);
7721
+ const itemPosition = spineLayout.getSpineItemRelativeLayoutInfo(spineItem);
7771
7722
  const { visible } = getItemVisibilityForPosition({
7772
7723
  itemPosition,
7773
7724
  threshold,
@@ -7803,7 +7754,7 @@
7803
7754
  `getSpineItemPositionFromSpinePosition`,
7804
7755
  10,
7805
7756
  (position, spineItem) => {
7806
- const { left, top } = spineLayout.getAbsolutePositionOf(spineItem);
7757
+ const { left, top } = spineLayout.getSpineItemRelativeLayoutInfo(spineItem);
7807
7758
  return {
7808
7759
  /**
7809
7760
  * when using spread the item could be on the right and therefore will be negative
@@ -7821,7 +7772,7 @@
7821
7772
  const getSpinePositionFromSpineItem = (spineItem) => {
7822
7773
  return getSpinePositionFromSpineItemPosition({
7823
7774
  spineItemPosition: { x: 0, y: 0 },
7824
- itemLayout: spineLayout.getAbsolutePositionOf(spineItem)
7775
+ itemLayout: spineLayout.getSpineItemRelativeLayoutInfo(spineItem)
7825
7776
  });
7826
7777
  };
7827
7778
  const getSpineItemFromIframe = (iframe) => {
@@ -7851,21 +7802,16 @@
7851
7802
  spineItem,
7852
7803
  restrictToScreen
7853
7804
  }) => {
7854
- const { height, width } = spineItem.layoutPosition;
7855
- const numberOfPages = spineItemLocator.getSpineItemNumberOfPages({
7856
- isUsingVerticalWriting: !!spineItem.isUsingVerticalWriting(),
7857
- itemHeight: height,
7858
- itemWidth: width
7859
- });
7805
+ const numberOfPages = spineItem.numberOfPages;
7860
7806
  const pages = Array.from(Array(numberOfPages)).map((_, index) => {
7861
7807
  const spineItemPosition = spineItemLocator.getSpineItemPositionFromPageIndex({
7862
7808
  pageIndex: index,
7863
7809
  isUsingVerticalWriting: !!spineItem.isUsingVerticalWriting(),
7864
- itemLayout: spineItem.layoutPosition
7810
+ itemLayout: spineItem.layout.layoutInfo
7865
7811
  });
7866
7812
  const spinePosition = getSpinePositionFromSpineItemPosition({
7867
7813
  spineItemPosition,
7868
- itemLayout: spineLayout.getAbsolutePositionOf(spineItem)
7814
+ itemLayout: spineLayout.getSpineItemRelativeLayoutInfo(spineItem)
7869
7815
  });
7870
7816
  return {
7871
7817
  index,
@@ -7905,11 +7851,11 @@
7905
7851
  };
7906
7852
  };
7907
7853
  const isPositionWithinSpineItem = (position, spineItem) => {
7908
- const { bottom, left, right, top } = spineLayout.getAbsolutePositionOf(spineItem);
7854
+ const { bottom, left, right, top } = spineLayout.getSpineItemRelativeLayoutInfo(spineItem);
7909
7855
  return position.x >= left && position.x <= right && position.y <= bottom && position.y >= top;
7910
7856
  };
7911
7857
  const getSafeSpineItemPositionFromUnsafeSpineItemPosition = (unsafePosition, spineItem) => {
7912
- const { height, width } = spineLayout.getAbsolutePositionOf(spineItem);
7858
+ const { height, width } = spineLayout.getSpineItemRelativeLayoutInfo(spineItem);
7913
7859
  return {
7914
7860
  x: Math.min(Math.max(0, unsafePosition.x), width),
7915
7861
  y: Math.min(Math.max(0, unsafePosition.y), height)
@@ -7920,7 +7866,7 @@
7920
7866
  spineItem,
7921
7867
  spineItemPosition
7922
7868
  }) => {
7923
- const itemLayout = spineLayout.getAbsolutePositionOf(spineItem);
7869
+ const itemLayout = spineLayout.getSpineItemRelativeLayoutInfo(spineItem);
7924
7870
  return getSpinePositionFromSpineItemPosition({
7925
7871
  itemLayout,
7926
7872
  spineItemPosition
@@ -7928,17 +7874,11 @@
7928
7874
  },
7929
7875
  getAbsolutePageIndexFromPageIndex: (params) => getAbsolutePageIndexFromPageIndex({
7930
7876
  ...params,
7931
- context,
7932
- settings,
7933
- spineItemsManager,
7934
- spineLayout
7877
+ spineItemsManager
7935
7878
  }),
7936
7879
  getSpineInfoFromAbsolutePageIndex: (params) => getSpineInfoFromAbsolutePageIndex({
7937
7880
  ...params,
7938
- context,
7939
- settings,
7940
- spineItemsManager,
7941
- spineLayout
7881
+ spineItemsManager
7942
7882
  }),
7943
7883
  getSpinePositionFromSpineItem,
7944
7884
  getSpineItemPositionFromSpinePosition,
@@ -8115,7 +8055,7 @@
8115
8055
  minimumWidth = context.getPageSize().width * 2;
8116
8056
  }
8117
8057
  }
8118
- const itemLayout$ = item.layout({
8058
+ const itemLayout$ = item.layout.layout({
8119
8059
  minimumWidth,
8120
8060
  blankPagePosition,
8121
8061
  spreadPosition: context.state.isUsingSpreadMode ? isScreenStartItem ? context.isRTL() ? `right` : `left` : context.isRTL() ? `left` : `right` : `none`
@@ -8126,29 +8066,52 @@
8126
8066
  const currentValidEdgeYForVerticalPositioning = isScreenStartItem ? verticalOffset : verticalOffset - context.state.visibleAreaRect.height;
8127
8067
  const currentValidEdgeXForVerticalPositioning = isScreenStartItem ? 0 : horizontalOffset;
8128
8068
  if (context.isRTL()) {
8129
- item.adjustPositionOfElement({
8069
+ item.layout.adjustPositionOfElement({
8130
8070
  top: currentValidEdgeYForVerticalPositioning,
8131
8071
  left: currentValidEdgeXForVerticalPositioning
8132
8072
  });
8133
8073
  } else {
8134
- item.adjustPositionOfElement({
8074
+ item.layout.adjustPositionOfElement({
8135
8075
  top: currentValidEdgeYForVerticalPositioning,
8136
8076
  left: currentValidEdgeXForVerticalPositioning
8137
8077
  });
8138
8078
  }
8139
8079
  const newEdgeX = width + currentValidEdgeXForVerticalPositioning;
8140
8080
  const newEdgeY = height + currentValidEdgeYForVerticalPositioning;
8081
+ const layoutPosition2 = {
8082
+ left: currentValidEdgeXForVerticalPositioning,
8083
+ right: newEdgeX,
8084
+ top: currentValidEdgeYForVerticalPositioning,
8085
+ bottom: newEdgeY,
8086
+ height,
8087
+ width,
8088
+ x: currentValidEdgeXForVerticalPositioning,
8089
+ y: currentValidEdgeYForVerticalPositioning
8090
+ };
8141
8091
  return {
8142
8092
  horizontalOffset: newEdgeX,
8143
- verticalOffset: newEdgeY
8093
+ verticalOffset: newEdgeY,
8094
+ layoutPosition: layoutPosition2
8144
8095
  };
8145
8096
  }
8146
- item.adjustPositionOfElement(
8097
+ item.layout.adjustPositionOfElement(
8147
8098
  context.isRTL() ? { right: horizontalOffset, top: 0 } : { left: horizontalOffset, top: 0 }
8148
8099
  );
8100
+ const left = context.isRTL() ? context.state.visibleAreaRect.width - horizontalOffset - width : horizontalOffset;
8101
+ const layoutPosition = {
8102
+ right: context.isRTL() ? context.state.visibleAreaRect.width - horizontalOffset : horizontalOffset + width,
8103
+ left,
8104
+ x: left,
8105
+ top: verticalOffset,
8106
+ bottom: height,
8107
+ height,
8108
+ width,
8109
+ y: verticalOffset
8110
+ };
8149
8111
  return {
8150
8112
  horizontalOffset: horizontalOffset + width,
8151
- verticalOffset: 0
8113
+ verticalOffset: 0,
8114
+ layoutPosition
8152
8115
  };
8153
8116
  })
8154
8117
  );
@@ -8161,7 +8124,11 @@
8161
8124
  this.context = context;
8162
8125
  this.settings = settings;
8163
8126
  this.layoutSubject = new rxjs.Subject();
8127
+ this.spineItemsRelativeLayouts = [];
8164
8128
  spineItemsManager.items$.pipe(
8129
+ rxjs.tap(() => {
8130
+ this.spineItemsRelativeLayouts = [];
8131
+ }),
8165
8132
  rxjs.switchMap((items) => {
8166
8133
  const needsLayouts$ = items.map(
8167
8134
  (spineItem) => spineItem.needsLayout$.pipe(
@@ -8202,28 +8169,41 @@
8202
8169
  layoutInProgress.next(true);
8203
8170
  const manifest = this.context.manifest;
8204
8171
  const isGloballyPrePaginated = isFullyPrePaginated(manifest) ?? false;
8205
- return rxjs.from(this.spineItemsManager.items).pipe(
8172
+ const items$ = rxjs.from(this.spineItemsManager.items);
8173
+ return items$.pipe(
8206
8174
  rxjs.reduce(
8207
- (acc$, item, index) => acc$.pipe(
8175
+ (acc$, item, itemIndex) => acc$.pipe(
8208
8176
  rxjs.concatMap(
8209
- ({ horizontalOffset, verticalOffset }) => layoutItem({
8177
+ ({ horizontalOffset, verticalOffset, pages }) => layoutItem({
8210
8178
  context: this.context,
8211
8179
  horizontalOffset,
8212
- index,
8180
+ index: itemIndex,
8213
8181
  isGloballyPrePaginated,
8214
8182
  item,
8215
8183
  settings: this.settings,
8216
8184
  spineItemsManager: this.spineItemsManager,
8217
8185
  verticalOffset
8218
- })
8186
+ }).pipe(
8187
+ rxjs.map(
8188
+ ({
8189
+ horizontalOffset: newHorizontalOffset,
8190
+ verticalOffset: newVerticalOffset,
8191
+ layoutPosition
8192
+ }) => {
8193
+ this.spineItemsRelativeLayouts[itemIndex] = layoutPosition;
8194
+ return {
8195
+ horizontalOffset: newHorizontalOffset,
8196
+ verticalOffset: newVerticalOffset,
8197
+ pages: [...pages, layoutPosition]
8198
+ };
8199
+ }
8200
+ )
8201
+ )
8219
8202
  )
8220
8203
  ),
8221
- rxjs.of({ horizontalOffset: 0, verticalOffset: 0 })
8204
+ rxjs.of({ horizontalOffset: 0, verticalOffset: 0, pages: [] })
8222
8205
  ),
8223
8206
  rxjs.concatMap((layout$) => layout$),
8224
- rxjs.tap(() => {
8225
- Report.log(NAMESPACE, `layout`);
8226
- }),
8227
8207
  rxjs.finalize(() => {
8228
8208
  layoutInProgress.next(false);
8229
8209
  })
@@ -8231,18 +8211,11 @@
8231
8211
  }),
8232
8212
  rxjs.map(() => {
8233
8213
  const items = spineItemsManager.items;
8234
- const spineItemsPagesAbsolutePositions = items.map((item) => {
8235
- const itemLayout = this.getAbsolutePositionOf(item);
8236
- const numberOfPages = getSpineItemNumberOfPages({
8237
- isUsingVerticalWriting: !!item.isUsingVerticalWriting(),
8238
- itemHeight: itemLayout.height,
8239
- itemWidth: itemLayout.width,
8240
- context,
8241
- settings
8242
- });
8243
- const pages2 = new Array(numberOfPages).fill(void 0);
8244
- return pages2.map(
8245
- (_, pageIndex) => convertSpinePositionToLayoutPosition({
8214
+ const pages = items.reduce((acc, item, itemIndex) => {
8215
+ const itemLayout = this.getSpineItemRelativeLayoutInfo(item);
8216
+ const pages2 = new Array(item.numberOfPages).fill(void 0);
8217
+ const pagesAbsolutePositions = pages2.map((_, pageIndex) => {
8218
+ return convertSpinePositionToLayoutPosition({
8246
8219
  pageSize: this.context.getPageSize(),
8247
8220
  position: getSpinePositionFromSpineItemPosition({
8248
8221
  itemLayout,
@@ -8253,33 +8226,25 @@
8253
8226
  context
8254
8227
  })
8255
8228
  })
8256
- })
8257
- );
8258
- });
8259
- const pages = spineItemsPagesAbsolutePositions.reduce(
8260
- (acc, itemPages, itemIndex) => {
8261
- const itemPagesInfo = itemPages.map(
8262
- (absolutePosition, pageIndex) => ({
8263
- itemIndex,
8264
- absolutePageIndex: itemIndex + pageIndex,
8265
- absolutePosition
8266
- })
8267
- );
8268
- return [...acc, ...itemPagesInfo];
8269
- },
8270
- []
8271
- );
8229
+ });
8230
+ });
8231
+ const itemPagesInfo = pagesAbsolutePositions.map((absolutePosition, pageIndex) => ({
8232
+ itemIndex,
8233
+ absolutePageIndex: itemIndex + pageIndex,
8234
+ absolutePosition
8235
+ }));
8236
+ return [...acc, ...itemPagesInfo];
8237
+ }, []);
8272
8238
  return {
8273
- spineItemsAbsolutePositions: items.map(
8274
- (item) => this.getAbsolutePositionOf(item)
8275
- ),
8276
- spineItemsPagesAbsolutePositions,
8277
8239
  pages
8278
8240
  };
8279
8241
  }),
8280
8242
  rxjs.share()
8281
8243
  );
8282
8244
  this.info$ = this.layout$.pipe(
8245
+ rxjs.tap((layout) => {
8246
+ Report.log(NAMESPACE, `layout:info`, layout);
8247
+ }),
8283
8248
  rxjs.shareReplay({ refCount: true, bufferSize: 1 })
8284
8249
  );
8285
8250
  rxjs.merge(this.layout$, this.info$).pipe(rxjs.takeUntil(this.destroy$)).subscribe();
@@ -8287,9 +8252,9 @@
8287
8252
  layout() {
8288
8253
  this.layoutSubject.next(void 0);
8289
8254
  }
8290
- getAbsolutePositionOf(spineItemOrIndex) {
8291
- var _a;
8292
- return ((_a = this.spineItemsManager.get(spineItemOrIndex)) == null ? void 0 : _a.layoutPosition) || {
8255
+ getSpineItemRelativeLayoutInfo(spineItemOrIndex) {
8256
+ const itemIndex = this.spineItemsManager.getSpineItemIndex(spineItemOrIndex) ?? 0;
8257
+ return this.spineItemsRelativeLayouts[itemIndex] || {
8293
8258
  left: 0,
8294
8259
  right: 0,
8295
8260
  top: 0,
@@ -8300,6 +8265,11 @@
8300
8265
  y: 0
8301
8266
  };
8302
8267
  }
8268
+ get numberOfPages() {
8269
+ return this.spineItemsManager.items.reduce((acc, item) => {
8270
+ return acc + item.numberOfPages;
8271
+ }, 0);
8272
+ }
8303
8273
  destroy() {
8304
8274
  super.destroy();
8305
8275
  this.layoutSubject.complete();
@@ -8423,34 +8393,14 @@
8423
8393
  const adjustedValue = multiplier * pageSize;
8424
8394
  return Math.max(adjustedValue, pageSize);
8425
8395
  }
8426
- /**
8427
- * Returns the absolute layout position relative to the parent element which
8428
- * is supposedly and expectedly the spine element.
8429
- *
8430
- * @important
8431
- *
8432
- * This method is stable and does not consider scalings or transforms on the parents.
8433
- *
8434
- * It does assume and requires that:
8435
- * - the navigator element and the spine element are direct parents.
8436
- * - the spine items are correctly positioned in the DOM and with correct styles values.
8437
- */
8438
- get layoutPosition() {
8439
- const left = Math.round(this.containerElement.offsetLeft * 10) / 10;
8440
- const top = Math.round(this.containerElement.offsetTop * 10) / 10;
8441
- const width = Math.round(this.containerElement.offsetWidth * 10) / 10;
8442
- const height = Math.round(this.containerElement.offsetHeight * 10) / 10;
8443
- const normalizedValues = {
8444
- left,
8445
- top,
8446
- right: left + width,
8447
- bottom: top + height,
8448
- x: left,
8449
- y: top,
8396
+ get layoutInfo() {
8397
+ const style = this.containerElement.style;
8398
+ const width = style.width ? parseFloat(style.width) : 0;
8399
+ const height = style.height ? parseFloat(style.height) : 0;
8400
+ return {
8450
8401
  width,
8451
8402
  height
8452
8403
  };
8453
- return normalizedValues;
8454
8404
  }
8455
8405
  }
8456
8406
  class DefaultRenderer extends DocumentRenderer {
@@ -8525,21 +8475,23 @@
8525
8475
  resourcesHandler: this.resourcesHandler
8526
8476
  };
8527
8477
  this.renderer = rendererFactory ? rendererFactory(rendererParams) : new DefaultRenderer(rendererParams);
8528
- this.spineItemLayout = new SpineItemLayout(
8478
+ this.layout = new SpineItemLayout(
8529
8479
  item,
8530
8480
  this.containerElement,
8531
8481
  context,
8532
8482
  hookManager,
8533
8483
  this.renderer
8534
8484
  );
8535
- this.isReady$ = this.spineItemLayout.layoutProcess$.pipe(
8485
+ this.isReady$ = this.layout.layoutProcess$.pipe(
8536
8486
  operators.withLatestFrom(this.renderer.isLoaded$),
8537
8487
  operators.map(([event, loaded]) => !!(event.type === `end` && loaded)),
8538
8488
  operators.startWith(false),
8539
8489
  operators.distinctUntilChanged(),
8490
+ operators.tap((isReady) => {
8491
+ this.containerElement.dataset["isReady"] = isReady.toString();
8492
+ }),
8540
8493
  operators.shareReplay({ refCount: true, bufferSize: 1 })
8541
8494
  );
8542
- this.layout$ = this.spineItemLayout.layout$;
8543
8495
  this.needsLayout$ = rxjs.merge(this.unloaded$, this.loaded$);
8544
8496
  rxjs.merge(
8545
8497
  /**
@@ -8549,10 +8501,8 @@
8549
8501
  * to layout changes may rely on the isReady value.
8550
8502
  */
8551
8503
  this.isReady$,
8552
- this.spineItemLayout.layout$
8504
+ this.layout.layout$
8553
8505
  ).pipe(operators.takeUntil(this.destroy$)).subscribe();
8554
- this.layout = this.spineItemLayout.layout;
8555
- this.adjustPositionOfElement = this.spineItemLayout.adjustPositionOfElement;
8556
8506
  }
8557
8507
  get element() {
8558
8508
  return this.containerElement;
@@ -8568,9 +8518,6 @@
8568
8518
  get readingDirection() {
8569
8519
  return this.renderer.readingDirection;
8570
8520
  }
8571
- get layoutPosition() {
8572
- return this.spineItemLayout.layoutPosition;
8573
- }
8574
8521
  get loaded$() {
8575
8522
  return this.renderer.state$.pipe(
8576
8523
  operators.distinctUntilChanged(),
@@ -8592,6 +8539,15 @@
8592
8539
  get renditionLayout() {
8593
8540
  return this.renderer.renditionLayout;
8594
8541
  }
8542
+ get numberOfPages() {
8543
+ return getSpineItemNumberOfPages({
8544
+ isUsingVerticalWriting: !!this.isUsingVerticalWriting(),
8545
+ itemHeight: this.layout.layoutInfo.height,
8546
+ itemWidth: this.layout.layoutInfo.width,
8547
+ context: this.context,
8548
+ settings: this.settings
8549
+ });
8550
+ }
8595
8551
  }
8596
8552
  const createContainerElement = (containerElement, item, hookManager) => {
8597
8553
  const element = containerElement.ownerDocument.createElement(`div`);
@@ -8601,6 +8557,7 @@
8601
8557
  position: absolute;
8602
8558
  overflow: hidden;
8603
8559
  `;
8560
+ element.dataset["isReady"] = `false`;
8604
8561
  hookManager.execute("item.onBeforeContainerCreated", void 0, { element });
8605
8562
  return element;
8606
8563
  };