@prose-reader/core 1.69.0 → 1.71.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.
@@ -705,7 +705,7 @@
705
705
  spineItemPosition
706
706
  );
707
707
  if (!isNewNavigationInCurrentItem) {
708
- return navigationResolver.wrapPositionWithSafeEdge(
708
+ return navigationResolver.getAdjustedPositionWithSafeEdge(
709
709
  pageTurnDirection === `horizontal` ? { x: position.x + context.getPageSize().width, y: 0 } : { y: position.y + context.getPageSize().height, x: 0 }
710
710
  );
711
711
  } else {
@@ -739,7 +739,7 @@
739
739
  if (context.state.isUsingSpreadMode) {
740
740
  if ((spineItem == null ? void 0 : spineItem.isUsingVerticalWriting()) && position.x !== navigation.x) {
741
741
  return navigationResolver.getAdjustedPositionForSpread(
742
- navigationResolver.wrapPositionWithSafeEdge(
742
+ navigationResolver.getAdjustedPositionWithSafeEdge(
743
743
  context.isRTL() ? {
744
744
  ...navigation,
745
745
  x: navigation.x - context.getPageSize().width
@@ -818,7 +818,7 @@
818
818
  spineItemPosition
819
819
  );
820
820
  if (!isNewNavigationInCurrentItem) {
821
- return navigationResolver.wrapPositionWithSafeEdge(
821
+ return navigationResolver.getAdjustedPositionWithSafeEdge(
822
822
  pageTurnDirection === `horizontal` ? { x: position.x - context.getPageSize().width, y: 0 } : { y: position.y - context.getPageSize().height, x: 0 }
823
823
  );
824
824
  } else {
@@ -852,7 +852,7 @@
852
852
  if (context.state.isUsingSpreadMode) {
853
853
  if ((spineItem == null ? void 0 : spineItem.isUsingVerticalWriting()) && position.x !== navigation.x) {
854
854
  return navigationResolver.getAdjustedPositionForSpread(
855
- navigationResolver.wrapPositionWithSafeEdge(
855
+ navigationResolver.getAdjustedPositionWithSafeEdge(
856
856
  context.isRTL() ? { ...navigation, x: navigation.x + context.getPageSize().width } : {
857
857
  ...navigation,
858
858
  x: navigation.x - context.getPageSize().width
@@ -1063,19 +1063,29 @@
1063
1063
  const observeState = (reader) => {
1064
1064
  return reader.pagination.pagination$.pipe(
1065
1065
  rxjs.withLatestFrom(reader.context.manifest$, reader.settings.settings$),
1066
- rxjs.map(([paginationInfo, manifest, { computedPageTurnDirection }]) => {
1067
- const numberOfSpineItems = (manifest == null ? void 0 : manifest.spineItems.length) ?? 0;
1068
- const isAtAbsoluteBeginning = paginationInfo.beginSpineItemIndex === 0;
1069
- const isAtAbsoluteEnd = paginationInfo.endSpineItemIndex === Math.max(numberOfSpineItems - 1, 0);
1070
- const isAtEndSpineItem = paginationInfo.endSpineItemIndex === Math.max(numberOfSpineItems - 1, 0);
1071
- const isAtBeginSpineItem = paginationInfo.beginSpineItemIndex === 0;
1072
- return {
1073
- canGoTopSpineItem: computedPageTurnDirection === "vertical" && !isAtAbsoluteBeginning,
1074
- canGoBottomSpineItem: computedPageTurnDirection === "vertical" && !isAtAbsoluteEnd,
1075
- canGoLeftSpineItem: computedPageTurnDirection !== "vertical" && ((manifest == null ? void 0 : manifest.readingDirection) === "ltr" && !isAtAbsoluteBeginning || (manifest == null ? void 0 : manifest.readingDirection) === "rtl" && !isAtEndSpineItem),
1076
- canGoRightSpineItem: computedPageTurnDirection !== "vertical" && ((manifest == null ? void 0 : manifest.readingDirection) === "ltr" && !isAtAbsoluteEnd || (manifest == null ? void 0 : manifest.readingDirection) === "rtl" && !isAtBeginSpineItem)
1077
- };
1078
- }),
1066
+ rxjs.map(
1067
+ ([
1068
+ paginationInfo,
1069
+ { spineItems, readingDirection },
1070
+ { computedPageTurnDirection }
1071
+ ]) => {
1072
+ const numberOfSpineItems = spineItems.length ?? 0;
1073
+ const isAtAbsoluteBeginning = paginationInfo.beginSpineItemIndex === 0;
1074
+ const isAtAbsoluteEnd = paginationInfo.endSpineItemIndex === Math.max(numberOfSpineItems - 1, 0);
1075
+ const isAtEndSpineItem = paginationInfo.endSpineItemIndex === Math.max(numberOfSpineItems - 1, 0);
1076
+ const isAtBeginSpineItem = paginationInfo.beginSpineItemIndex === 0;
1077
+ const isAtBeginFirstPage = paginationInfo.beginPageIndexInSpineItem === 0;
1078
+ const isAtEndLastPage = paginationInfo.endPageIndexInSpineItem === paginationInfo.endNumberOfPagesInSpineItem - 1;
1079
+ return {
1080
+ canTurnLeft: computedPageTurnDirection === "vertical" ? false : !isAtBeginFirstPage,
1081
+ canTurnRight: computedPageTurnDirection === "vertical" ? false : !isAtEndLastPage,
1082
+ canGoTopSpineItem: computedPageTurnDirection === "vertical" && !isAtAbsoluteBeginning,
1083
+ canGoBottomSpineItem: computedPageTurnDirection === "vertical" && !isAtAbsoluteEnd,
1084
+ canGoLeftSpineItem: computedPageTurnDirection !== "vertical" && (readingDirection === "ltr" && !isAtAbsoluteBeginning || readingDirection === "rtl" && !isAtEndSpineItem),
1085
+ canGoRightSpineItem: computedPageTurnDirection !== "vertical" && (readingDirection === "ltr" && !isAtAbsoluteEnd || readingDirection === "rtl" && !isAtBeginSpineItem)
1086
+ };
1087
+ }
1088
+ ),
1079
1089
  rxjs.distinctUntilChanged(isShallowEqual)
1080
1090
  );
1081
1091
  };
@@ -2250,12 +2260,12 @@
2250
2260
  const correctedX = isOffsetNotAtEdge ? x - pageSizeWidth : x;
2251
2261
  return { x: correctedX, y };
2252
2262
  };
2253
- const wrapPositionWithSafeEdge = ({
2263
+ const getAdjustedPositionWithSafeEdge = ({
2254
2264
  position,
2255
2265
  isRTL,
2256
- pageSizeWidth,
2257
2266
  pageSizeHeight,
2258
- spineItemsManager
2267
+ spineItemsManager,
2268
+ visibleAreaRectWidth
2259
2269
  }) => {
2260
2270
  const lastSpineItem = spineItemsManager.get(spineItemsManager.getLength() - 1);
2261
2271
  const distanceOfLastSpineItem = spineItemsManager.getAbsolutePositionOf(
@@ -2269,7 +2279,7 @@
2269
2279
  y
2270
2280
  };
2271
2281
  }
2272
- const maximumXOffset = distanceOfLastSpineItem.right - pageSizeWidth;
2282
+ const maximumXOffset = distanceOfLastSpineItem.right - visibleAreaRectWidth;
2273
2283
  return {
2274
2284
  x: Math.min(Math.max(0, position.x), maximumXOffset),
2275
2285
  y
@@ -3400,14 +3410,14 @@
3400
3410
  const triggerPercentage = 0.5;
3401
3411
  const triggerXPosition = pageTurnDirection === `horizontal` ? viewportPosition.x + context.state.visibleAreaRect.width * triggerPercentage : 0;
3402
3412
  const triggerYPosition = pageTurnDirection === `horizontal` ? 0 : viewportPosition.y + context.state.visibleAreaRect.height * triggerPercentage;
3403
- const midScreenPositionSafePosition = wrapPositionWithSafeEdge({
3413
+ const midScreenPositionSafePosition = getAdjustedPositionWithSafeEdge({
3404
3414
  position: {
3405
3415
  x: triggerXPosition,
3406
3416
  y: triggerYPosition
3407
3417
  },
3408
3418
  isRTL: context.isRTL(),
3409
3419
  pageSizeHeight: context.getPageSize().height,
3410
- pageSizeWidth: context.getPageSize().width,
3420
+ visibleAreaRectWidth: context.state.visibleAreaRect.width,
3411
3421
  spineItemsManager
3412
3422
  });
3413
3423
  return getNavigationForPosition({
@@ -3456,11 +3466,11 @@
3456
3466
  spineLocator: locator
3457
3467
  }),
3458
3468
  getMostPredominantNavigationForPosition,
3459
- wrapPositionWithSafeEdge: (position) => wrapPositionWithSafeEdge({
3469
+ getAdjustedPositionWithSafeEdge: (position) => getAdjustedPositionWithSafeEdge({
3460
3470
  position,
3461
3471
  isRTL: context.isRTL(),
3462
3472
  pageSizeHeight: context.getPageSize().height,
3463
- pageSizeWidth: context.getPageSize().width,
3473
+ visibleAreaRectWidth: context.state.visibleAreaRect.width,
3464
3474
  spineItemsManager
3465
3475
  }),
3466
3476
  isNavigationGoingForwardFrom,
@@ -4149,7 +4159,7 @@
4149
4159
  return {
4150
4160
  navigation: {
4151
4161
  ...navigation,
4152
- position: navigationResolver.wrapPositionWithSafeEdge(
4162
+ position: navigationResolver.getAdjustedPositionWithSafeEdge(
4153
4163
  navigation.position
4154
4164
  )
4155
4165
  },
@@ -4439,7 +4449,7 @@
4439
4449
  rxjs.map(
4440
4450
  () => ({
4441
4451
  ...navigation,
4442
- animation: "turn"
4452
+ animation: "snap"
4443
4453
  })
4444
4454
  ),
4445
4455
  rxjs.finalize(() => {
@@ -4806,7 +4816,7 @@
4806
4816
  pageTurnMode: `controlled`,
4807
4817
  snapAnimationDuration: 300,
4808
4818
  navigationSnapThreshold: 0.3,
4809
- numberOfAdjacentSpineItemToPreLoad: 0
4819
+ numberOfAdjacentSpineItemToPreLoad: 2
4810
4820
  };
4811
4821
  }
4812
4822
  }
@@ -6915,7 +6925,18 @@
6915
6925
  const layoutHasChanged$ = spineItemsManager.layout$.pipe(
6916
6926
  rxjs.filter((hasChanged) => hasChanged)
6917
6927
  );
6918
- const loadSpineItems$ = rxjs.merge(navigationUpdate$, layoutHasChanged$).pipe(
6928
+ const numberOfAdjacentSpineItemToPreLoad$ = settings.settings$.pipe(
6929
+ rxjs.map(
6930
+ ({ numberOfAdjacentSpineItemToPreLoad }) => numberOfAdjacentSpineItemToPreLoad
6931
+ ),
6932
+ rxjs.skip(1),
6933
+ rxjs.distinctUntilChanged()
6934
+ );
6935
+ const loadSpineItems$ = rxjs.merge(
6936
+ navigationUpdate$,
6937
+ layoutHasChanged$,
6938
+ numberOfAdjacentSpineItemToPreLoad$
6939
+ ).pipe(
6919
6940
  // this can be changed by whatever we want and SHOULD not break navigation.
6920
6941
  // Ideally loading faster is better but loading too close to user navigating can
6921
6942
  // be dangerous.