@prose-reader/core 1.198.0 → 1.200.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/context/Context.d.ts +3 -0
- package/dist/createReaderWithEnhancer.d.ts +12 -19
- package/dist/enhancers/layoutEnhancer/layoutInfo.d.ts +2 -2
- package/dist/enhancers/navigation/navigators/manualNavigator.d.ts +2 -2
- package/dist/enhancers/navigation/navigators/panNavigator.d.ts +3 -3
- package/dist/enhancers/navigation/resolvers/getNavigationForLeftOrTopPage.d.ts +3 -3
- package/dist/enhancers/navigation/resolvers/getNavigationForLeftSinglePage.d.ts +3 -3
- package/dist/enhancers/navigation/resolvers/getNavigationForRightOrBottomPage.d.ts +3 -3
- package/dist/enhancers/navigation/resolvers/getNavigationForRightSinglePage.d.ts +3 -3
- package/dist/index.js +212 -90
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +212 -90
- package/dist/index.umd.cjs.map +1 -1
- package/dist/navigation/InternalNavigator.d.ts +7 -5
- package/dist/navigation/Navigator.d.ts +12 -16
- package/dist/navigation/UserNavigator.d.ts +5 -4
- package/dist/navigation/consolidation/consolidateWithPagination.d.ts +1 -1
- package/dist/navigation/consolidation/withFallbackPosition.d.ts +1 -1
- package/dist/navigation/consolidation/withSpineItem.d.ts +2 -2
- package/dist/navigation/resolvers/NavigationResolver.d.ts +12 -16
- package/dist/navigation/resolvers/getAdjustedPositionForSpread.d.ts +3 -3
- package/dist/navigation/resolvers/getAdjustedPositionWithSafeEdge.d.ts +3 -6
- package/dist/navigation/resolvers/getNavigationForPosition.d.ts +3 -3
- package/dist/navigation/resolvers/getNavigationForSpineItemPage.d.ts +2 -2
- package/dist/navigation/resolvers/getNavigationForUrl.d.ts +2 -2
- package/dist/navigation/resolvers/getNavigationFromSpineItemPosition.d.ts +1 -1
- package/dist/navigation/restoration/restoreNavigationForControlledPageTurnMode.d.ts +3 -4
- package/dist/navigation/restoration/restorePosition.d.ts +2 -2
- package/dist/navigation/viewport/ViewportNavigator.d.ts +4 -12
- package/dist/navigation/viewport/getScaledDownPosition.d.ts +4 -6
- package/dist/navigation/viewport/positions.d.ts +9 -0
- package/dist/reader.d.ts +12 -19
- package/dist/spine/loader/SpineItemsLoader.d.ts +2 -2
- package/dist/spine/locator/SpineLocator.d.ts +7 -6
- package/dist/spine/locator/getItemVisibilityForPosition.d.ts +3 -6
- package/dist/spine/locator/getSpineItemFromPosition.d.ts +2 -2
- package/dist/spine/locator/getVisibleSpineItemsFromPosition.d.ts +4 -3
- package/dist/spine/types.d.ts +13 -3
- package/dist/viewport/translateSpinePositionToRelativeViewport.d.ts +4 -0
- package/dist/viewport/types.d.ts +29 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2156,22 +2156,32 @@ class SpineElementLayout {
|
|
|
2156
2156
|
class SpineItemSpineLayout extends SpineElementLayout {
|
|
2157
2157
|
constructor() {
|
|
2158
2158
|
super(...arguments);
|
|
2159
|
-
this.__symbol =
|
|
2159
|
+
this.__symbol = `SpineItemSpineLayout`;
|
|
2160
2160
|
}
|
|
2161
2161
|
}
|
|
2162
2162
|
class SpineItemPageSpineLayout extends SpineElementLayout {
|
|
2163
2163
|
constructor() {
|
|
2164
2164
|
super(...arguments);
|
|
2165
|
-
this.__symbol =
|
|
2165
|
+
this.__symbol = `SpineItemPageSpineLayout`;
|
|
2166
2166
|
}
|
|
2167
2167
|
}
|
|
2168
2168
|
class SpinePosition {
|
|
2169
2169
|
constructor(position) {
|
|
2170
|
-
this.__symbol =
|
|
2170
|
+
this.__symbol = `SpinePosition`;
|
|
2171
2171
|
this.x = position.x;
|
|
2172
2172
|
this.y = position.y;
|
|
2173
2173
|
}
|
|
2174
2174
|
}
|
|
2175
|
+
class UnsafeSpinePosition {
|
|
2176
|
+
constructor(position) {
|
|
2177
|
+
this.__symbol = `UnsafeSpinePosition`;
|
|
2178
|
+
this.x = position.x;
|
|
2179
|
+
this.y = position.y;
|
|
2180
|
+
}
|
|
2181
|
+
static from(position) {
|
|
2182
|
+
return new UnsafeSpinePosition(position);
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2175
2185
|
const spinePositionToSpineItemSpineLayout = ({
|
|
2176
2186
|
position,
|
|
2177
2187
|
pageSize
|
|
@@ -2747,7 +2757,13 @@ const getNavigationForLeftSinglePage = ({
|
|
|
2747
2757
|
);
|
|
2748
2758
|
if (!isNewNavigationInCurrentItem) {
|
|
2749
2759
|
return navigationResolver.getAdjustedPositionWithSafeEdge(
|
|
2750
|
-
pageTurnDirection === `horizontal` ?
|
|
2760
|
+
pageTurnDirection === `horizontal` ? new SpinePosition({
|
|
2761
|
+
x: position.x - context.getPageSize().width,
|
|
2762
|
+
y: 0
|
|
2763
|
+
}) : new SpinePosition({
|
|
2764
|
+
y: position.y - context.getPageSize().height,
|
|
2765
|
+
x: 0
|
|
2766
|
+
})
|
|
2751
2767
|
);
|
|
2752
2768
|
}
|
|
2753
2769
|
const readingOrderPosition = spineLocator.getSpinePositionFromSpineItemPosition({
|
|
@@ -2856,7 +2872,13 @@ const getNavigationForRightSinglePage = ({
|
|
|
2856
2872
|
);
|
|
2857
2873
|
if (!isNewNavigationInCurrentItem) {
|
|
2858
2874
|
return navigationResolver.getAdjustedPositionWithSafeEdge(
|
|
2859
|
-
pageTurnDirection === `horizontal` ?
|
|
2875
|
+
pageTurnDirection === `horizontal` ? new SpinePosition({
|
|
2876
|
+
x: position.x + context.getPageSize().width,
|
|
2877
|
+
y: 0
|
|
2878
|
+
}) : new SpinePosition({
|
|
2879
|
+
y: position.y + context.getPageSize().height,
|
|
2880
|
+
x: 0
|
|
2881
|
+
})
|
|
2860
2882
|
);
|
|
2861
2883
|
}
|
|
2862
2884
|
const readingOrderPosition = spineLocator.getSpinePositionFromSpineItemPosition({
|
|
@@ -2918,7 +2940,7 @@ class ManualNavigator {
|
|
|
2918
2940
|
constructor(reader) {
|
|
2919
2941
|
this.reader = reader;
|
|
2920
2942
|
this.movingLastDelta = { x: 0, y: 0 };
|
|
2921
|
-
this.movingLastPosition = { x: 0, y: 0 };
|
|
2943
|
+
this.movingLastPosition = new SpinePosition({ x: 0, y: 0 });
|
|
2922
2944
|
this.unlock = void 0;
|
|
2923
2945
|
}
|
|
2924
2946
|
turnRight() {
|
|
@@ -3114,8 +3136,8 @@ class PanNavigator {
|
|
|
3114
3136
|
constructor(reader) {
|
|
3115
3137
|
this.reader = reader;
|
|
3116
3138
|
this.lastDelta = { x: 0, y: 0 };
|
|
3117
|
-
this.lastPosition = { x: 0, y: 0 };
|
|
3118
|
-
this.lastStartPosition = { x: 0, y: 0 };
|
|
3139
|
+
this.lastPosition = new SpinePosition({ x: 0, y: 0 });
|
|
3140
|
+
this.lastStartPosition = new SpinePosition({ x: 0, y: 0 });
|
|
3119
3141
|
this.unlock = void 0;
|
|
3120
3142
|
}
|
|
3121
3143
|
moveTo(delta, { final, start } = {}) {
|
|
@@ -3134,16 +3156,19 @@ class PanNavigator {
|
|
|
3134
3156
|
}
|
|
3135
3157
|
let navigation = this.reader.navigation.getNavigation().position;
|
|
3136
3158
|
if (delta) {
|
|
3159
|
+
const viewportScale = this.reader.context.absoluteViewport.width / this.reader.context.relativeViewport.width;
|
|
3137
3160
|
const correctedX = Math.floor(delta.x) - (((_b = this.lastDelta) == null ? void 0 : _b.x) || 0);
|
|
3138
3161
|
const correctedY = Math.floor(delta.y) - (((_c = this.lastDelta) == null ? void 0 : _c.y) || 0);
|
|
3139
|
-
|
|
3140
|
-
x:
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3162
|
+
const x = Math.floor(
|
|
3163
|
+
pageTurnDirection === `horizontal` ? this.lastPosition.x - correctedX / viewportScale : 0
|
|
3164
|
+
);
|
|
3165
|
+
const y = Math.floor(
|
|
3166
|
+
pageTurnDirection === `horizontal` ? 0 : this.lastPosition.y - correctedY / viewportScale
|
|
3167
|
+
);
|
|
3168
|
+
navigation = new SpinePosition({
|
|
3169
|
+
x,
|
|
3170
|
+
y
|
|
3171
|
+
});
|
|
3147
3172
|
this.lastDelta = delta;
|
|
3148
3173
|
} else {
|
|
3149
3174
|
navigation = this.lastPosition;
|
|
@@ -5320,6 +5345,39 @@ const resolveCfi = ({
|
|
|
5320
5345
|
};
|
|
5321
5346
|
};
|
|
5322
5347
|
const isFullyPrePaginated = (manifest) => (manifest == null ? void 0 : manifest.renditionLayout) === "pre-paginated" || (manifest == null ? void 0 : manifest.spineItems.every((item) => item.renditionLayout === "pre-paginated"));
|
|
5348
|
+
class ViewportSlicePosition extends DOMRect {
|
|
5349
|
+
constructor() {
|
|
5350
|
+
super(...arguments);
|
|
5351
|
+
this.__symbol = Symbol(`ViewportPosition`);
|
|
5352
|
+
}
|
|
5353
|
+
static from(positionOrRect, viewport) {
|
|
5354
|
+
if (viewport) {
|
|
5355
|
+
const position = positionOrRect;
|
|
5356
|
+
return new ViewportSlicePosition(
|
|
5357
|
+
position.x,
|
|
5358
|
+
position.y,
|
|
5359
|
+
viewport.width,
|
|
5360
|
+
viewport.height
|
|
5361
|
+
);
|
|
5362
|
+
}
|
|
5363
|
+
const rect = positionOrRect;
|
|
5364
|
+
return new ViewportSlicePosition(rect.x, rect.y, rect.width, rect.height);
|
|
5365
|
+
}
|
|
5366
|
+
}
|
|
5367
|
+
class AbsoluteViewport {
|
|
5368
|
+
constructor({ width, height }) {
|
|
5369
|
+
this.__symbol = Symbol(`AbsoluteViewport`);
|
|
5370
|
+
this.width = width;
|
|
5371
|
+
this.height = height;
|
|
5372
|
+
}
|
|
5373
|
+
}
|
|
5374
|
+
class RelativeViewport {
|
|
5375
|
+
constructor({ width, height }) {
|
|
5376
|
+
this.__symbol = Symbol(`RelativeViewport`);
|
|
5377
|
+
this.width = width;
|
|
5378
|
+
this.height = height;
|
|
5379
|
+
}
|
|
5380
|
+
}
|
|
5323
5381
|
class BridgeEvent {
|
|
5324
5382
|
constructor() {
|
|
5325
5383
|
this.navigationSubject = new ReplaySubject(1);
|
|
@@ -5449,6 +5507,28 @@ class Context {
|
|
|
5449
5507
|
height: visibleAreaRect.height
|
|
5450
5508
|
};
|
|
5451
5509
|
}
|
|
5510
|
+
get absoluteViewport() {
|
|
5511
|
+
const absoluteViewport = this._stateSubject.getValue().visibleAreaRect;
|
|
5512
|
+
return new AbsoluteViewport({
|
|
5513
|
+
width: absoluteViewport.width,
|
|
5514
|
+
height: absoluteViewport.height
|
|
5515
|
+
});
|
|
5516
|
+
}
|
|
5517
|
+
/**
|
|
5518
|
+
* @important
|
|
5519
|
+
*
|
|
5520
|
+
* Contains long floating values.
|
|
5521
|
+
*/
|
|
5522
|
+
get relativeViewport() {
|
|
5523
|
+
var _a, _b;
|
|
5524
|
+
const absoluteViewport = this.absoluteViewport;
|
|
5525
|
+
const viewportRect = (_b = (_a = this._stateSubject.getValue().containerElement) == null ? void 0 : _a.children[0]) == null ? void 0 : _b.getBoundingClientRect();
|
|
5526
|
+
const relativeScale = ((viewportRect == null ? void 0 : viewportRect.width) ?? absoluteViewport.width) / absoluteViewport.width;
|
|
5527
|
+
return new RelativeViewport({
|
|
5528
|
+
width: absoluteViewport.width / relativeScale,
|
|
5529
|
+
height: absoluteViewport.height / relativeScale
|
|
5530
|
+
});
|
|
5531
|
+
}
|
|
5452
5532
|
}
|
|
5453
5533
|
class HookManager {
|
|
5454
5534
|
constructor() {
|
|
@@ -5528,7 +5608,7 @@ class HookManager {
|
|
|
5528
5608
|
}
|
|
5529
5609
|
const getItemOffsetFromPageIndex = (pageWidth, pageIndex, itemWidth) => {
|
|
5530
5610
|
const lastPageOffset = itemWidth - pageWidth;
|
|
5531
|
-
const logicalOffset = itemWidth * (pageIndex * pageWidth) / itemWidth;
|
|
5611
|
+
const logicalOffset = itemWidth * (pageIndex * pageWidth) / (itemWidth || 1);
|
|
5532
5612
|
return Math.max(0, Math.min(lastPageOffset, logicalOffset));
|
|
5533
5613
|
};
|
|
5534
5614
|
const calculateNumberOfPagesForItem = (itemWidth, pageWidth) => {
|
|
@@ -5802,7 +5882,7 @@ const getAdjustedPositionForSpread = ({
|
|
|
5802
5882
|
}) => {
|
|
5803
5883
|
const isOffsetNotAtEdge = x % visibleAreaRectWidth !== 0;
|
|
5804
5884
|
const correctedX = isOffsetNotAtEdge ? x - pageSizeWidth : x;
|
|
5805
|
-
return { x: correctedX, y };
|
|
5885
|
+
return new SpinePosition({ x: correctedX, y });
|
|
5806
5886
|
};
|
|
5807
5887
|
const getAdjustedPositionWithSafeEdge = ({
|
|
5808
5888
|
position,
|
|
@@ -5821,16 +5901,16 @@ const getAdjustedPositionWithSafeEdge = ({
|
|
|
5821
5901
|
const maximumYOffset = distanceOfLastSpineItem.bottom - pageSizeHeight;
|
|
5822
5902
|
const y = Math.min(Math.max(0, position.y), maximumYOffset);
|
|
5823
5903
|
if (isRTL) {
|
|
5824
|
-
return {
|
|
5904
|
+
return new SpinePosition({
|
|
5825
5905
|
x: Math.max(Math.min(0, position.x), distanceOfLastSpineItem.left),
|
|
5826
5906
|
y
|
|
5827
|
-
};
|
|
5907
|
+
});
|
|
5828
5908
|
}
|
|
5829
5909
|
const maximumXOffset = distanceOfLastSpineItem.right - visibleAreaRectWidth;
|
|
5830
|
-
return {
|
|
5910
|
+
return new SpinePosition({
|
|
5831
5911
|
x: Math.min(Math.max(0, position.x), maximumXOffset),
|
|
5832
5912
|
y
|
|
5833
|
-
};
|
|
5913
|
+
});
|
|
5834
5914
|
};
|
|
5835
5915
|
const getNavigationForPosition = ({
|
|
5836
5916
|
viewportPosition,
|
|
@@ -5858,7 +5938,7 @@ const getNavigationForPosition = ({
|
|
|
5858
5938
|
visibleAreaRectWidth: context.state.visibleAreaRect.width
|
|
5859
5939
|
});
|
|
5860
5940
|
}
|
|
5861
|
-
return { x: 0, y: 0 };
|
|
5941
|
+
return new SpinePosition({ x: 0, y: 0 });
|
|
5862
5942
|
};
|
|
5863
5943
|
const getNavigationForSpineItemPage = ({
|
|
5864
5944
|
pageIndex,
|
|
@@ -5872,7 +5952,7 @@ const getNavigationForSpineItemPage = ({
|
|
|
5872
5952
|
if (!spineItem) {
|
|
5873
5953
|
const xPositionForPageIndex = pageIndex * context.getPageSize().width;
|
|
5874
5954
|
return getNavigationForPosition({
|
|
5875
|
-
viewportPosition: { x: xPositionForPageIndex, y: 0 },
|
|
5955
|
+
viewportPosition: new SpinePosition({ x: xPositionForPageIndex, y: 0 }),
|
|
5876
5956
|
context,
|
|
5877
5957
|
spineItemNavigationResolver,
|
|
5878
5958
|
spineLocator
|
|
@@ -6018,7 +6098,6 @@ const createNavigationResolver = ({
|
|
|
6018
6098
|
}) => {
|
|
6019
6099
|
const spineItemNavigator = createNavigationResolver$1({ context, settings });
|
|
6020
6100
|
const arePositionsDifferent = (a, b) => a.x !== b.x || a.y !== b.y;
|
|
6021
|
-
const areNavigationDifferent = (a, b) => arePositionsDifferent(a, b) || !!a.spineItem && !!b.spineItem && a.spineItem !== b.spineItem;
|
|
6022
6101
|
const getNavigationForCfi = (cfi) => {
|
|
6023
6102
|
const spineItem = spineItemsManager.getSpineItemFromCfi(cfi);
|
|
6024
6103
|
const { node, offset = 0 } = resolveCfi({
|
|
@@ -6062,7 +6141,7 @@ const createNavigationResolver = ({
|
|
|
6062
6141
|
visibleAreaRectWidth: context.state.visibleAreaRect.width
|
|
6063
6142
|
});
|
|
6064
6143
|
}
|
|
6065
|
-
return { x: 0, y: 0 };
|
|
6144
|
+
return new SpinePosition({ x: 0, y: 0 });
|
|
6066
6145
|
};
|
|
6067
6146
|
const getMostPredominantNavigationForPosition = (viewportPosition) => {
|
|
6068
6147
|
const pageTurnDirection = settings.values.computedPageTurnDirection;
|
|
@@ -6070,10 +6149,10 @@ const createNavigationResolver = ({
|
|
|
6070
6149
|
const triggerXPosition = pageTurnDirection === `horizontal` ? viewportPosition.x + context.state.visibleAreaRect.width * triggerPercentage : 0;
|
|
6071
6150
|
const triggerYPosition = pageTurnDirection === `horizontal` ? 0 : viewportPosition.y + context.state.visibleAreaRect.height * triggerPercentage;
|
|
6072
6151
|
const midScreenPositionSafePosition = getAdjustedPositionWithSafeEdge({
|
|
6073
|
-
position: {
|
|
6152
|
+
position: new SpinePosition({
|
|
6074
6153
|
x: triggerXPosition,
|
|
6075
6154
|
y: triggerYPosition
|
|
6076
|
-
},
|
|
6155
|
+
}),
|
|
6077
6156
|
isRTL: context.isRTL(),
|
|
6078
6157
|
pageSizeHeight: context.getPageSize().height,
|
|
6079
6158
|
visibleAreaRectWidth: context.state.visibleAreaRect.width,
|
|
@@ -6135,7 +6214,6 @@ const createNavigationResolver = ({
|
|
|
6135
6214
|
spineLayout
|
|
6136
6215
|
}),
|
|
6137
6216
|
isNavigationGoingForwardFrom,
|
|
6138
|
-
areNavigationDifferent,
|
|
6139
6217
|
arePositionsDifferent,
|
|
6140
6218
|
getAdjustedPositionForSpread: (position) => getAdjustedPositionForSpread({
|
|
6141
6219
|
position,
|
|
@@ -6152,7 +6230,7 @@ const getScaledDownPosition = ({
|
|
|
6152
6230
|
}) => {
|
|
6153
6231
|
if (!spineElement) throw new Error("Invalid spine element");
|
|
6154
6232
|
const spineScaleX = spineElement.getBoundingClientRect().width / spineElement.offsetWidth;
|
|
6155
|
-
const scaledDownPosition = {
|
|
6233
|
+
const scaledDownPosition = new SpinePosition({
|
|
6156
6234
|
x: getNewScaledOffset({
|
|
6157
6235
|
newScale: 1,
|
|
6158
6236
|
oldScale: spineScaleX,
|
|
@@ -6167,9 +6245,27 @@ const getScaledDownPosition = ({
|
|
|
6167
6245
|
pageSize: spineElement.scrollHeight,
|
|
6168
6246
|
scrollOffset: y
|
|
6169
6247
|
})
|
|
6170
|
-
};
|
|
6248
|
+
});
|
|
6171
6249
|
return scaledDownPosition;
|
|
6172
6250
|
};
|
|
6251
|
+
const spinePositionToTranslation = (position) => {
|
|
6252
|
+
return {
|
|
6253
|
+
x: -position.x,
|
|
6254
|
+
y: -position.y
|
|
6255
|
+
};
|
|
6256
|
+
};
|
|
6257
|
+
const translationToSpinePosition = (translation) => {
|
|
6258
|
+
if (translation instanceof DOMMatrix) {
|
|
6259
|
+
return new SpinePosition({
|
|
6260
|
+
x: -translation.e,
|
|
6261
|
+
y: -translation.f
|
|
6262
|
+
});
|
|
6263
|
+
}
|
|
6264
|
+
return new SpinePosition({
|
|
6265
|
+
x: -translation.x,
|
|
6266
|
+
y: -translation.y
|
|
6267
|
+
});
|
|
6268
|
+
};
|
|
6173
6269
|
const NAMESPACE$3 = `navigation/ViewportNavigator`;
|
|
6174
6270
|
const report$3 = Report.namespace(NAMESPACE$3);
|
|
6175
6271
|
class ViewportNavigator extends DestroyableClass {
|
|
@@ -6314,11 +6410,15 @@ class ViewportNavigator extends DestroyableClass {
|
|
|
6314
6410
|
* @see https://stackoverflow.com/questions/22111256/translate3d-vs-translate-performance
|
|
6315
6411
|
* for remark about flicker / fonts smoothing
|
|
6316
6412
|
*/
|
|
6317
|
-
setViewportPosition(
|
|
6413
|
+
setViewportPosition(position) {
|
|
6318
6414
|
const element = this.viewportElement$.getValue();
|
|
6319
6415
|
if (this.settings.values.computedPageTurnMode === `scrollable`) {
|
|
6320
6416
|
this.scrollingSubject.next(true);
|
|
6321
|
-
element.scrollTo({
|
|
6417
|
+
element.scrollTo({
|
|
6418
|
+
left: position.x,
|
|
6419
|
+
top: position.y,
|
|
6420
|
+
behavior: "instant"
|
|
6421
|
+
});
|
|
6322
6422
|
timer(1).pipe(
|
|
6323
6423
|
tap$1(() => {
|
|
6324
6424
|
this.scrollingSubject.next(false);
|
|
@@ -6326,36 +6426,37 @@ class ViewportNavigator extends DestroyableClass {
|
|
|
6326
6426
|
takeUntil(merge(this.scrollingSubject.pipe(skip$1(1)), this.destroy$))
|
|
6327
6427
|
).subscribe();
|
|
6328
6428
|
} else {
|
|
6329
|
-
|
|
6429
|
+
const translation = spinePositionToTranslation(position);
|
|
6430
|
+
element.style.transform = `translate(${translation.x}px, ${translation.y}px)`;
|
|
6330
6431
|
}
|
|
6331
6432
|
this.hookManager.execute("onViewportOffsetAdjust", void 0, {});
|
|
6332
6433
|
}
|
|
6333
6434
|
navigate(navigation) {
|
|
6334
6435
|
this.navigateSubject.next(navigation);
|
|
6335
6436
|
}
|
|
6437
|
+
/**
|
|
6438
|
+
* @important The reason we use computed transform and not bounding client is to avoid
|
|
6439
|
+
* transofmration inconsistency between the viewport and the spine.
|
|
6440
|
+
*/
|
|
6336
6441
|
get viewportPosition() {
|
|
6337
6442
|
const element = this.viewportElement$.getValue();
|
|
6338
6443
|
if (this.settings.values.computedPageTurnMode === `scrollable`) {
|
|
6339
6444
|
return getScaledDownPosition({
|
|
6340
6445
|
element,
|
|
6341
|
-
position: {
|
|
6446
|
+
position: new SpinePosition({
|
|
6342
6447
|
x: (element == null ? void 0 : element.scrollLeft) ?? 0,
|
|
6343
6448
|
y: (element == null ? void 0 : element.scrollTop) ?? 0
|
|
6344
|
-
},
|
|
6449
|
+
}),
|
|
6345
6450
|
spineElement: this.spine.element
|
|
6346
6451
|
});
|
|
6347
6452
|
}
|
|
6348
|
-
const
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
// @see https://stackoverflow.com/questions/13847053/difference-between-and-math-floor for ~~
|
|
6356
|
-
x: ~~(x * -1 * 10) / 10,
|
|
6357
|
-
y: ~~(Math.abs(y) * 10) / 10
|
|
6358
|
-
};
|
|
6453
|
+
const computedStyle = window.getComputedStyle(element);
|
|
6454
|
+
const transform = computedStyle.transform || computedStyle.webkitTransform;
|
|
6455
|
+
if (!transform || transform === "none") {
|
|
6456
|
+
return new SpinePosition({ x: 0, y: 0 });
|
|
6457
|
+
}
|
|
6458
|
+
const matrix = new DOMMatrix(transform);
|
|
6459
|
+
return translationToSpinePosition(matrix);
|
|
6359
6460
|
}
|
|
6360
6461
|
}
|
|
6361
6462
|
class Locker {
|
|
@@ -6419,10 +6520,10 @@ class UserNavigator extends DestroyableClass {
|
|
|
6419
6520
|
const targetElement = event.target;
|
|
6420
6521
|
const scaledDownPosition = getScaledDownPosition({
|
|
6421
6522
|
element: targetElement,
|
|
6422
|
-
position: {
|
|
6523
|
+
position: new SpinePosition({
|
|
6423
6524
|
x: targetElement.scrollLeft ?? 0,
|
|
6424
6525
|
y: targetElement.scrollTop ?? 0
|
|
6425
|
-
},
|
|
6526
|
+
}),
|
|
6426
6527
|
spineElement: this.spine.element
|
|
6427
6528
|
});
|
|
6428
6529
|
this.navigate({
|
|
@@ -6616,7 +6717,7 @@ const withFallbackPosition = ({
|
|
|
6616
6717
|
return {
|
|
6617
6718
|
navigation: {
|
|
6618
6719
|
...navigation,
|
|
6619
|
-
position: { x: 0, y: 0 }
|
|
6720
|
+
position: new SpinePosition({ x: 0, y: 0 })
|
|
6620
6721
|
},
|
|
6621
6722
|
...rest
|
|
6622
6723
|
};
|
|
@@ -6815,7 +6916,7 @@ const restoreNavigationForControlledPageTurnMode = ({
|
|
|
6815
6916
|
}) => {
|
|
6816
6917
|
const spineItem = spineItemsManager.get(navigation.spineItem);
|
|
6817
6918
|
if (!spineItem) {
|
|
6818
|
-
return of({ x: 0, y: 0 });
|
|
6919
|
+
return of(new SpinePosition({ x: 0, y: 0 }));
|
|
6819
6920
|
}
|
|
6820
6921
|
return spineItem.isReady$.pipe(
|
|
6821
6922
|
first$1(),
|
|
@@ -7631,6 +7732,14 @@ class ReaderSettingsManager extends SettingsManager3 {
|
|
|
7631
7732
|
};
|
|
7632
7733
|
}
|
|
7633
7734
|
}
|
|
7735
|
+
const translateSpinePositionToRelativeViewport = (absolutePosition, absoluteViewport, relativeViewport) => {
|
|
7736
|
+
const offsetX = (relativeViewport.width - absoluteViewport.width) / 2;
|
|
7737
|
+
const offsetY = (relativeViewport.height - absoluteViewport.height) / 2;
|
|
7738
|
+
return new UnsafeSpinePosition({
|
|
7739
|
+
x: absolutePosition.x - offsetX,
|
|
7740
|
+
y: absolutePosition.y - offsetY
|
|
7741
|
+
});
|
|
7742
|
+
};
|
|
7634
7743
|
const getAbsolutePageIndexFromPageIndex = ({
|
|
7635
7744
|
pageIndex,
|
|
7636
7745
|
spineItemOrId,
|
|
@@ -7676,10 +7785,10 @@ const isItemVisibleOnScreenByThresholdForPosition = ({
|
|
|
7676
7785
|
visibleWidthOfItem,
|
|
7677
7786
|
visibleHeightOfItem,
|
|
7678
7787
|
threshold,
|
|
7679
|
-
|
|
7788
|
+
viewportPosition
|
|
7680
7789
|
}) => {
|
|
7681
|
-
const widthRatioOfSpaceTakenInScreen = visibleWidthOfItem /
|
|
7682
|
-
const heightRatioOfSpaceTakenInScreen = visibleHeightOfItem /
|
|
7790
|
+
const widthRatioOfSpaceTakenInScreen = visibleWidthOfItem / viewportPosition.width;
|
|
7791
|
+
const heightRatioOfSpaceTakenInScreen = visibleHeightOfItem / viewportPosition.height;
|
|
7683
7792
|
const isItemVisibleEnoughOnScreen = heightRatioOfSpaceTakenInScreen >= threshold && widthRatioOfSpaceTakenInScreen >= threshold;
|
|
7684
7793
|
return isItemVisibleEnoughOnScreen;
|
|
7685
7794
|
};
|
|
@@ -7694,14 +7803,13 @@ const getItemVisibilityForPosition = ({
|
|
|
7694
7803
|
},
|
|
7695
7804
|
threshold,
|
|
7696
7805
|
viewportPosition,
|
|
7697
|
-
restrictToScreen
|
|
7698
|
-
context
|
|
7806
|
+
restrictToScreen
|
|
7699
7807
|
}) => {
|
|
7700
7808
|
const viewportLeft = viewportPosition.x;
|
|
7701
|
-
const viewportRight = viewportPosition.x + (
|
|
7809
|
+
const viewportRight = viewportPosition.x + (viewportPosition.width - 1);
|
|
7702
7810
|
const viewportTop = viewportPosition.y;
|
|
7703
7811
|
const viewportBottom = Math.max(
|
|
7704
|
-
viewportPosition.y + (
|
|
7812
|
+
viewportPosition.y + (viewportPosition.height - 1),
|
|
7705
7813
|
0
|
|
7706
7814
|
);
|
|
7707
7815
|
const visibleWidthOfItem = Math.max(
|
|
@@ -7718,7 +7826,7 @@ const getItemVisibilityForPosition = ({
|
|
|
7718
7826
|
threshold,
|
|
7719
7827
|
visibleHeightOfItem,
|
|
7720
7828
|
visibleWidthOfItem,
|
|
7721
|
-
|
|
7829
|
+
viewportPosition
|
|
7722
7830
|
});
|
|
7723
7831
|
if (restrictToScreen) {
|
|
7724
7832
|
return { visible: isItemVisibleEnoughOnScreen };
|
|
@@ -7804,7 +7912,8 @@ const getVisibleSpineItemsFromPosition = ({
|
|
|
7804
7912
|
spineItemsManager,
|
|
7805
7913
|
context,
|
|
7806
7914
|
settings,
|
|
7807
|
-
spineLayout
|
|
7915
|
+
spineLayout,
|
|
7916
|
+
useAbsoluteViewport = true
|
|
7808
7917
|
}) => {
|
|
7809
7918
|
const fallbackSpineItem = getSpineItemFromPosition({
|
|
7810
7919
|
position,
|
|
@@ -7815,12 +7924,21 @@ const getVisibleSpineItemsFromPosition = ({
|
|
|
7815
7924
|
const spineItemsVisible = spineItemsManager.items.reduce(
|
|
7816
7925
|
(acc, spineItem) => {
|
|
7817
7926
|
const itemPosition = spineLayout.getSpineItemSpineLayoutInfo(spineItem);
|
|
7927
|
+
const viewport = useAbsoluteViewport ? context.absoluteViewport : context.relativeViewport;
|
|
7928
|
+
const relativeSpinePosition = translateSpinePositionToRelativeViewport(
|
|
7929
|
+
position,
|
|
7930
|
+
context.absoluteViewport,
|
|
7931
|
+
viewport
|
|
7932
|
+
);
|
|
7933
|
+
const viewportPosition = ViewportSlicePosition.from(
|
|
7934
|
+
relativeSpinePosition,
|
|
7935
|
+
viewport
|
|
7936
|
+
);
|
|
7818
7937
|
const { visible } = getItemVisibilityForPosition({
|
|
7819
7938
|
itemPosition,
|
|
7820
7939
|
threshold,
|
|
7821
|
-
viewportPosition
|
|
7822
|
-
restrictToScreen
|
|
7823
|
-
context
|
|
7940
|
+
viewportPosition,
|
|
7941
|
+
restrictToScreen
|
|
7824
7942
|
});
|
|
7825
7943
|
if (visible) {
|
|
7826
7944
|
return [...acc, spineItem];
|
|
@@ -7846,25 +7964,20 @@ const createSpineLocator = ({
|
|
|
7846
7964
|
settings,
|
|
7847
7965
|
spineLayout
|
|
7848
7966
|
}) => {
|
|
7849
|
-
const getSpineItemPositionFromSpinePosition =
|
|
7850
|
-
|
|
7851
|
-
|
|
7852
|
-
|
|
7853
|
-
|
|
7854
|
-
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
|
|
7858
|
-
|
|
7859
|
-
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
|
|
7863
|
-
y: Math.max(position.y - top, 0)
|
|
7864
|
-
});
|
|
7865
|
-
},
|
|
7866
|
-
{ disable: true }
|
|
7867
|
-
);
|
|
7967
|
+
const getSpineItemPositionFromSpinePosition = (position, spineItem) => {
|
|
7968
|
+
const { left, top } = spineLayout.getSpineItemSpineLayoutInfo(spineItem);
|
|
7969
|
+
return new SpineItemPosition({
|
|
7970
|
+
/**
|
|
7971
|
+
* when using spread the item could be on the right and therefore will be negative
|
|
7972
|
+
* @example
|
|
7973
|
+
* 400 (position = viewport), page of 200
|
|
7974
|
+
* 400 - 600 = -200.
|
|
7975
|
+
* However we can assume we are at 0, because we in fact can see the beginning of the item
|
|
7976
|
+
*/
|
|
7977
|
+
x: Math.max(position.x - left, 0),
|
|
7978
|
+
y: Math.max(position.y - top, 0)
|
|
7979
|
+
});
|
|
7980
|
+
};
|
|
7868
7981
|
const getSpinePositionFromSpineItem = (spineItem) => {
|
|
7869
7982
|
return getSpinePositionFromSpineItemPosition({
|
|
7870
7983
|
spineItemPosition: new SpineItemPosition({ x: 0, y: 0 }),
|
|
@@ -7896,7 +8009,8 @@ const createSpineLocator = ({
|
|
|
7896
8009
|
position,
|
|
7897
8010
|
threshold,
|
|
7898
8011
|
spineItem,
|
|
7899
|
-
restrictToScreen
|
|
8012
|
+
restrictToScreen,
|
|
8013
|
+
useAbsoluteViewport = true
|
|
7900
8014
|
}) => {
|
|
7901
8015
|
const numberOfPages = spineItem.numberOfPages;
|
|
7902
8016
|
const pages = Array.from(Array(numberOfPages)).map((_, index) => {
|
|
@@ -7922,9 +8036,18 @@ const createSpineLocator = ({
|
|
|
7922
8036
|
});
|
|
7923
8037
|
const pagesVisible = pages.reduce(
|
|
7924
8038
|
(acc, { absolutePosition, index }) => {
|
|
8039
|
+
const viewport = useAbsoluteViewport ? context.absoluteViewport : context.relativeViewport;
|
|
8040
|
+
const relativeSpinePosition = translateSpinePositionToRelativeViewport(
|
|
8041
|
+
position,
|
|
8042
|
+
context.absoluteViewport,
|
|
8043
|
+
viewport
|
|
8044
|
+
);
|
|
8045
|
+
const viewportPosition = ViewportSlicePosition.from(
|
|
8046
|
+
relativeSpinePosition,
|
|
8047
|
+
viewport
|
|
8048
|
+
);
|
|
7925
8049
|
const { visible } = getItemVisibilityForPosition({
|
|
7926
|
-
|
|
7927
|
-
viewportPosition: position,
|
|
8050
|
+
viewportPosition,
|
|
7928
8051
|
restrictToScreen,
|
|
7929
8052
|
threshold,
|
|
7930
8053
|
itemPosition: absolutePosition
|
|
@@ -8029,7 +8152,8 @@ class SpineItemsLoader extends DestroyableClass {
|
|
|
8029
8152
|
const { numberOfAdjacentSpineItemToPreLoad } = settings.values;
|
|
8030
8153
|
const { beginIndex = 0, endIndex = 0 } = spineLocator.getVisibleSpineItemsFromPosition({
|
|
8031
8154
|
position: navigation.position,
|
|
8032
|
-
threshold: 0
|
|
8155
|
+
threshold: 0,
|
|
8156
|
+
useAbsoluteViewport: false
|
|
8033
8157
|
}) || {};
|
|
8034
8158
|
const beginMaximumIndex = beginIndex - numberOfAdjacentSpineItemToPreLoad;
|
|
8035
8159
|
const endMaximumIndex = endIndex + numberOfAdjacentSpineItemToPreLoad;
|
|
@@ -8792,17 +8916,15 @@ const createReader = (inputSettings) => {
|
|
|
8792
8916
|
const margin = 0;
|
|
8793
8917
|
const marginTop = 0;
|
|
8794
8918
|
const marginBottom = 0;
|
|
8795
|
-
const containerElementWidth = dimensions.width;
|
|
8796
|
-
const containerElementEvenWidth = containerElementWidth;
|
|
8797
8919
|
element.style.setProperty(`overflow`, `hidden`);
|
|
8798
8920
|
element.style.height = `${dimensions.height - marginTop - marginBottom}px`;
|
|
8799
|
-
element.style.width = `${
|
|
8921
|
+
element.style.width = `${dimensions.width - 2 * margin}px`;
|
|
8800
8922
|
const elementRect = element.getBoundingClientRect();
|
|
8801
8923
|
context.update({
|
|
8802
8924
|
visibleAreaRect: {
|
|
8803
8925
|
x: elementRect.x,
|
|
8804
8926
|
y: elementRect.y,
|
|
8805
|
-
width:
|
|
8927
|
+
width: dimensions.width,
|
|
8806
8928
|
height: dimensions.height
|
|
8807
8929
|
}
|
|
8808
8930
|
});
|