@prose-reader/core 1.21.0 → 1.22.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.d.ts +6 -1
- package/dist/createReaderWithEnhancer.d.ts +233 -805
- package/dist/enhancers/accessibility.d.ts +231 -805
- package/dist/enhancers/chrome.d.ts +231 -805
- package/dist/enhancers/cssFix.d.ts +6639 -0
- package/dist/enhancers/fonts.d.ts +233 -807
- package/dist/enhancers/hotkeys.d.ts +231 -805
- package/dist/enhancers/layoutEnhancer/layoutEnhancer.d.ts +231 -805
- package/dist/enhancers/links.d.ts +231 -805
- package/dist/enhancers/loadingEnhancer.d.ts +231 -805
- package/dist/enhancers/media.d.ts +231 -805
- package/dist/enhancers/navigation.d.ts +231 -805
- package/dist/enhancers/pagination.d.ts +233 -805
- package/dist/enhancers/progression.d.ts +231 -805
- package/dist/enhancers/resources/index.d.ts +231 -805
- package/dist/enhancers/theme.d.ts +231 -805
- package/dist/enhancers/types/enhancer.d.ts +231 -805
- package/dist/enhancers/utils.d.ts +231 -805
- package/dist/enhancers/webkit.d.ts +231 -805
- package/dist/enhancers/zoom/index.d.ts +231 -805
- package/dist/prose.js +300 -278
- package/dist/prose.js.map +1 -1
- package/dist/prose.umd.cjs +299 -277
- package/dist/prose.umd.cjs.map +1 -1
- package/dist/reader.d.ts +231 -805
- package/dist/spine/locationResolver.d.ts +7 -17
- package/dist/spine/navigationResolver.d.ts +5 -8
- package/dist/spine/types.d.ts +10 -0
- package/dist/spineItem/locationResolver.d.ts +3 -7
- package/dist/spineItem/navigationResolver.d.ts +7 -17
- package/dist/spineItem/types.d.ts +19 -0
- package/dist/spineItemManager.d.ts +6 -519
- package/dist/types/Hook.d.ts +6 -6
- package/dist/types/Spine.d.ts +1 -5
- package/package.json +3 -3
package/dist/prose.umd.cjs
CHANGED
|
@@ -2117,9 +2117,62 @@
|
|
|
2117
2117
|
}));
|
|
2118
2118
|
});
|
|
2119
2119
|
}
|
|
2120
|
+
const hasOwn = Object.prototype.hasOwnProperty;
|
|
2121
|
+
const is = (x, y) => {
|
|
2122
|
+
if (x === y) {
|
|
2123
|
+
return x !== 0 || y !== 0 || 1 / x === 1 / y;
|
|
2124
|
+
} else {
|
|
2125
|
+
return false;
|
|
2126
|
+
}
|
|
2127
|
+
};
|
|
2128
|
+
const isShallowEqual = (objectA, objectB, options) => {
|
|
2129
|
+
if (objectA === objectB) {
|
|
2130
|
+
return true;
|
|
2131
|
+
}
|
|
2132
|
+
if (typeof objectA !== `object` || objectA === null) {
|
|
2133
|
+
return false;
|
|
2134
|
+
}
|
|
2135
|
+
if (typeof objectB !== `object` || objectB === null) {
|
|
2136
|
+
return false;
|
|
2137
|
+
}
|
|
2138
|
+
const keysA = Object.keys(objectA);
|
|
2139
|
+
const keysB = Object.keys(objectB);
|
|
2140
|
+
if (keysA.length !== keysB.length) {
|
|
2141
|
+
return false;
|
|
2142
|
+
}
|
|
2143
|
+
const isEqual = options && typeof options.customEqual === `function` ? options.customEqual : is;
|
|
2144
|
+
for (let i = 0; i < keysA.length; i++) {
|
|
2145
|
+
const key = keysA[i] || ``;
|
|
2146
|
+
if (!hasOwn.call(objectB, key) || !isEqual(objectA[key], objectB[key])) {
|
|
2147
|
+
return false;
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
return true;
|
|
2151
|
+
};
|
|
2152
|
+
const groupBy = (list, getKey) => list.reduce((previous, currentItem) => {
|
|
2153
|
+
const group = getKey(currentItem);
|
|
2154
|
+
if (!previous[group])
|
|
2155
|
+
previous[group] = [];
|
|
2156
|
+
previous[group].push(currentItem);
|
|
2157
|
+
return previous;
|
|
2158
|
+
}, {});
|
|
2159
|
+
const getBase64FromBlob = (data) => {
|
|
2160
|
+
const reader = new FileReader();
|
|
2161
|
+
return new Promise((resolve) => {
|
|
2162
|
+
reader.addEventListener(
|
|
2163
|
+
`load`,
|
|
2164
|
+
function() {
|
|
2165
|
+
resolve(reader.result);
|
|
2166
|
+
},
|
|
2167
|
+
false
|
|
2168
|
+
);
|
|
2169
|
+
reader.readAsDataURL(data);
|
|
2170
|
+
});
|
|
2171
|
+
};
|
|
2120
2172
|
const fontsEnhancer = (next) => (options) => {
|
|
2121
2173
|
const { fontScale = 1, lineHeight = `publisher`, fontWeight = `publisher`, fontJustification = `publisher` } = options;
|
|
2122
|
-
const
|
|
2174
|
+
const changes$ = new rxjs.Subject();
|
|
2175
|
+
const settings$ = new rxjs.BehaviorSubject({
|
|
2123
2176
|
fontScale,
|
|
2124
2177
|
lineHeight,
|
|
2125
2178
|
fontWeight,
|
|
@@ -2137,10 +2190,10 @@
|
|
|
2137
2190
|
*/
|
|
2138
2191
|
``}
|
|
2139
2192
|
body {
|
|
2140
|
-
${
|
|
2141
|
-
${
|
|
2142
|
-
${
|
|
2143
|
-
${
|
|
2193
|
+
${settings$.value.fontScale !== 1 ? `font-size: ${settings$.value.fontScale}em !important;` : ``}
|
|
2194
|
+
${settings$.value.lineHeight !== `publisher` ? `line-height: ${settings$.value.lineHeight} !important;` : ``}
|
|
2195
|
+
${settings$.value.fontWeight !== `publisher` ? `font-weight: ${settings$.value.fontWeight} !important;` : ``}
|
|
2196
|
+
${settings$.value.fontJustification !== `publisher` ? `text-align: ${settings$.value.fontJustification} !important;` : ``}
|
|
2144
2197
|
}
|
|
2145
2198
|
`;
|
|
2146
2199
|
const applyChangeToSpineItem = (requireLayout) => {
|
|
@@ -2168,8 +2221,20 @@
|
|
|
2168
2221
|
return false;
|
|
2169
2222
|
})
|
|
2170
2223
|
);
|
|
2171
|
-
|
|
2172
|
-
|
|
2224
|
+
const newSettings$ = changes$.pipe(
|
|
2225
|
+
withLatestFrom(settings$),
|
|
2226
|
+
rxjs.map(([changes, settings]) => ({
|
|
2227
|
+
fontJustification: changes.fontJustification ?? settings.fontJustification,
|
|
2228
|
+
fontWeight: changes.fontWeight ?? settings.fontWeight,
|
|
2229
|
+
lineHeight: changes.lineHeight ?? settings.lineHeight,
|
|
2230
|
+
fontScale: Math.max(0.01, changes.fontScale ?? settings.fontScale)
|
|
2231
|
+
})),
|
|
2232
|
+
distinctUntilChanged(isShallowEqual),
|
|
2233
|
+
shareReplay(1)
|
|
2234
|
+
);
|
|
2235
|
+
newSettings$.subscribe(settings$);
|
|
2236
|
+
settings$.pipe(shouldRequireLayout, tap(applyChangeToSpineItem), rxjs.takeUntil(reader.$.destroy$)).subscribe();
|
|
2237
|
+
const settingsMerge$ = rxjs.combineLatest([reader.settings$, settings$]).pipe(
|
|
2173
2238
|
rxjs.map(([innerSettings, settings]) => ({
|
|
2174
2239
|
...innerSettings,
|
|
2175
2240
|
...settings
|
|
@@ -2177,56 +2242,56 @@
|
|
|
2177
2242
|
);
|
|
2178
2243
|
return {
|
|
2179
2244
|
...reader,
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2245
|
+
destroy: () => {
|
|
2246
|
+
changes$.complete();
|
|
2247
|
+
settings$.complete();
|
|
2248
|
+
},
|
|
2183
2249
|
setSettings: (settings) => {
|
|
2184
|
-
const {
|
|
2185
|
-
|
|
2186
|
-
fontScale: fontScale2 = settingsSubject$.value.fontScale,
|
|
2187
|
-
fontWeight: fontWeight2 = settingsSubject$.value.fontWeight,
|
|
2188
|
-
lineHeight: lineHeight2 = settingsSubject$.value.lineHeight,
|
|
2189
|
-
...passthroughSettings
|
|
2190
|
-
} = settings;
|
|
2191
|
-
if (hasOneKey(settings, [`fontJustification`, `fontScale`, `fontWeight`, `lineHeight`])) {
|
|
2192
|
-
settingsSubject$.next({ fontJustification: fontJustification2, fontScale: fontScale2, fontWeight: fontWeight2, lineHeight: lineHeight2 });
|
|
2193
|
-
}
|
|
2250
|
+
const { fontJustification: fontJustification2, fontScale: fontScale2, fontWeight: fontWeight2, lineHeight: lineHeight2, ...passthroughSettings } = settings;
|
|
2251
|
+
changes$.next({ fontJustification: fontJustification2, fontScale: fontScale2, fontWeight: fontWeight2, lineHeight: lineHeight2 });
|
|
2194
2252
|
reader.setSettings(passthroughSettings);
|
|
2195
2253
|
},
|
|
2196
|
-
|
|
2197
|
-
* Combine reader settings with enhancer settings
|
|
2198
|
-
*/
|
|
2199
|
-
settings$
|
|
2254
|
+
settings$: settingsMerge$
|
|
2200
2255
|
};
|
|
2201
2256
|
};
|
|
2202
|
-
const hasOneKey = (obj, keys) => keys.some((key) => key in obj);
|
|
2203
2257
|
const hotkeysEnhancer = (next) => (options) => {
|
|
2204
2258
|
const reader = next(options);
|
|
2205
|
-
const
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2259
|
+
const navigateOnKey = (document2) => rxjs.fromEvent(document2, "keyup").pipe(
|
|
2260
|
+
rxjs.withLatestFrom(reader.settings$),
|
|
2261
|
+
rxjs.map(([e, { pageTurnDirection }]) => {
|
|
2262
|
+
if (pageTurnDirection === "horizontal") {
|
|
2263
|
+
if (e.key === `ArrowRight`) {
|
|
2264
|
+
reader.turnRight();
|
|
2265
|
+
}
|
|
2266
|
+
if (e.key === `ArrowLeft`) {
|
|
2267
|
+
reader.turnLeft();
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
if (pageTurnDirection === "vertical") {
|
|
2271
|
+
if (e.key === `ArrowDown`) {
|
|
2272
|
+
reader.turnRight();
|
|
2273
|
+
}
|
|
2274
|
+
if (e.key === `ArrowUp`) {
|
|
2275
|
+
reader.turnLeft();
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
return e;
|
|
2279
|
+
})
|
|
2280
|
+
);
|
|
2281
|
+
navigateOnKey(document).pipe(rxjs.takeUntil(reader.$.destroy$)).subscribe();
|
|
2282
|
+
reader.spineItems$.pipe(
|
|
2283
|
+
rxjs.switchMap(
|
|
2284
|
+
(spineItems) => rxjs.merge(
|
|
2285
|
+
...spineItems.map(
|
|
2286
|
+
(item) => item.$.loaded$.pipe(
|
|
2287
|
+
rxjs.switchMap((iframe) => (iframe == null ? void 0 : iframe.contentDocument) ? navigateOnKey(iframe.contentDocument) : rxjs.EMPTY)
|
|
2288
|
+
)
|
|
2289
|
+
)
|
|
2290
|
+
)
|
|
2291
|
+
),
|
|
2292
|
+
rxjs.takeUntil(reader.$.destroy$)
|
|
2293
|
+
).subscribe();
|
|
2294
|
+
return reader;
|
|
2230
2295
|
};
|
|
2231
2296
|
const SHOULD_NOT_LAYOUT$2 = false;
|
|
2232
2297
|
const createMovingSafePan$ = (reader) => {
|
|
@@ -2282,58 +2347,6 @@
|
|
|
2282
2347
|
}, {});
|
|
2283
2348
|
});
|
|
2284
2349
|
};
|
|
2285
|
-
const hasOwn = Object.prototype.hasOwnProperty;
|
|
2286
|
-
const is = (x, y) => {
|
|
2287
|
-
if (x === y) {
|
|
2288
|
-
return x !== 0 || y !== 0 || 1 / x === 1 / y;
|
|
2289
|
-
} else {
|
|
2290
|
-
return false;
|
|
2291
|
-
}
|
|
2292
|
-
};
|
|
2293
|
-
const isShallowEqual = (objectA, objectB, options) => {
|
|
2294
|
-
if (objectA === objectB) {
|
|
2295
|
-
return true;
|
|
2296
|
-
}
|
|
2297
|
-
if (typeof objectA !== `object` || objectA === null) {
|
|
2298
|
-
return false;
|
|
2299
|
-
}
|
|
2300
|
-
if (typeof objectB !== `object` || objectB === null) {
|
|
2301
|
-
return false;
|
|
2302
|
-
}
|
|
2303
|
-
const keysA = Object.keys(objectA);
|
|
2304
|
-
const keysB = Object.keys(objectB);
|
|
2305
|
-
if (keysA.length !== keysB.length) {
|
|
2306
|
-
return false;
|
|
2307
|
-
}
|
|
2308
|
-
const isEqual = options && typeof options.customEqual === `function` ? options.customEqual : is;
|
|
2309
|
-
for (let i = 0; i < keysA.length; i++) {
|
|
2310
|
-
const key = keysA[i] || ``;
|
|
2311
|
-
if (!hasOwn.call(objectB, key) || !isEqual(objectA[key], objectB[key])) {
|
|
2312
|
-
return false;
|
|
2313
|
-
}
|
|
2314
|
-
}
|
|
2315
|
-
return true;
|
|
2316
|
-
};
|
|
2317
|
-
const groupBy = (list, getKey) => list.reduce((previous, currentItem) => {
|
|
2318
|
-
const group = getKey(currentItem);
|
|
2319
|
-
if (!previous[group])
|
|
2320
|
-
previous[group] = [];
|
|
2321
|
-
previous[group].push(currentItem);
|
|
2322
|
-
return previous;
|
|
2323
|
-
}, {});
|
|
2324
|
-
const getBase64FromBlob = (data) => {
|
|
2325
|
-
const reader = new FileReader();
|
|
2326
|
-
return new Promise((resolve) => {
|
|
2327
|
-
reader.addEventListener(
|
|
2328
|
-
`load`,
|
|
2329
|
-
function() {
|
|
2330
|
-
resolve(reader.result);
|
|
2331
|
-
},
|
|
2332
|
-
false
|
|
2333
|
-
);
|
|
2334
|
-
reader.readAsDataURL(data);
|
|
2335
|
-
});
|
|
2336
|
-
};
|
|
2337
2350
|
const fixReflowable = (reader) => {
|
|
2338
2351
|
reader.registerHook(`item.onAfterLayout`, ({ item, blankPagePosition, minimumWidth }) => {
|
|
2339
2352
|
var _a;
|
|
@@ -2689,7 +2702,7 @@
|
|
|
2689
2702
|
return offsetValues.find((offsetRange) => offset < offsetRange + pageWidth) || 0;
|
|
2690
2703
|
};
|
|
2691
2704
|
const NAMESPACE$5 = `paginationEnhancer`;
|
|
2692
|
-
|
|
2705
|
+
Report.namespace(NAMESPACE$5);
|
|
2693
2706
|
const paginationEnhancer = (next) => (options) => {
|
|
2694
2707
|
const reader = next(options);
|
|
2695
2708
|
const chaptersInfo = {};
|
|
@@ -2699,8 +2712,12 @@
|
|
|
2699
2712
|
};
|
|
2700
2713
|
const mapPaginationInfoToExtendedInfo = (paginationInfo) => {
|
|
2701
2714
|
const context = reader.context;
|
|
2715
|
+
const manifest = context.getManifest();
|
|
2716
|
+
const numberOfSpineItems = (manifest == null ? void 0 : manifest.spineItems.length) ?? 0;
|
|
2702
2717
|
const beginItem = paginationInfo.beginSpineItemIndex !== void 0 ? reader.getSpineItem(paginationInfo.beginSpineItemIndex) : void 0;
|
|
2703
2718
|
const endItem = paginationInfo.endSpineItemIndex !== void 0 ? reader.getSpineItem(paginationInfo.endSpineItemIndex) : void 0;
|
|
2719
|
+
const isAtAbsoluteBeginning = paginationInfo.beginSpineItemIndex === 0 && paginationInfo.beginPageIndex === 0;
|
|
2720
|
+
const isAtAbsoluteEnd = paginationInfo.endPageIndex === paginationInfo.endNumberOfPages - 1 && paginationInfo.endSpineItemIndex === Math.max(numberOfSpineItems - 1, 0);
|
|
2704
2721
|
return {
|
|
2705
2722
|
beginPageIndexInChapter: paginationInfo.beginPageIndex,
|
|
2706
2723
|
beginNumberOfPagesInChapter: paginationInfo.beginNumberOfPages,
|
|
@@ -2716,19 +2733,14 @@
|
|
|
2716
2733
|
// charOffset: number;
|
|
2717
2734
|
// serializeString?: string;
|
|
2718
2735
|
beginSpineItemIndex: paginationInfo.beginSpineItemIndex,
|
|
2719
|
-
// spineItemPath: beginItem?.item.path,
|
|
2720
|
-
// spineItemId: beginItem?.item.id,
|
|
2721
2736
|
beginCfi: paginationInfo.beginCfi,
|
|
2722
2737
|
beginSpineItemReadingDirection: beginItem == null ? void 0 : beginItem.getReadingDirection(),
|
|
2723
2738
|
endChapterInfo: endItem ? chaptersInfo[endItem.item.id] : void 0,
|
|
2724
2739
|
endPageIndexInChapter: paginationInfo.endPageIndex,
|
|
2725
2740
|
endNumberOfPagesInChapter: paginationInfo.endNumberOfPages,
|
|
2726
2741
|
endSpineItemIndex: paginationInfo.endSpineItemIndex,
|
|
2727
|
-
// spineItemPath: endItem?.item.path,
|
|
2728
|
-
// spineItemId: endItem?.item.id,
|
|
2729
2742
|
endSpineItemReadingDirection: endItem == null ? void 0 : endItem.getReadingDirection(),
|
|
2730
2743
|
endCfi: paginationInfo.endCfi,
|
|
2731
|
-
// end: ReadingLocation;
|
|
2732
2744
|
// spineItemReadingDirection: focusedSpineItem?.getReadingDirection(),
|
|
2733
2745
|
/**
|
|
2734
2746
|
* This percentage is based of the weight (kb) of every items and the number of pages.
|
|
@@ -2744,12 +2756,12 @@
|
|
|
2744
2756
|
reader.getCurrentViewportPosition(),
|
|
2745
2757
|
endItem
|
|
2746
2758
|
) : 0,
|
|
2747
|
-
isUsingSpread: context.shouldDisplaySpread()
|
|
2748
|
-
// chaptersOfBook: number;
|
|
2749
|
-
// chapter: string;
|
|
2759
|
+
isUsingSpread: context.shouldDisplaySpread(),
|
|
2750
2760
|
// hasNextChapter: (reader.spine.spineItemIndex || 0) < (manifest.readingOrder.length - 1),
|
|
2751
2761
|
// hasPreviousChapter: (reader.spine.spineItemIndex || 0) < (manifest.readingOrder.length - 1),
|
|
2752
2762
|
// numberOfSpineItems: context.getManifest()?.readingOrder.length,
|
|
2763
|
+
canGoLeft: (manifest == null ? void 0 : manifest.readingDirection) === "ltr" && !isAtAbsoluteBeginning || (manifest == null ? void 0 : manifest.readingDirection) === "rtl" && !isAtAbsoluteEnd,
|
|
2764
|
+
canGoRight: (manifest == null ? void 0 : manifest.readingDirection) === "ltr" && !isAtAbsoluteEnd || (manifest == null ? void 0 : manifest.readingDirection) === "rtl" && !isAtAbsoluteBeginning
|
|
2753
2765
|
};
|
|
2754
2766
|
};
|
|
2755
2767
|
const getSpineItemNumberOfPages = (spineItem) => {
|
|
@@ -2767,7 +2779,7 @@
|
|
|
2767
2779
|
const getNumberOfPagesPerItems = () => reader.getSpineItems().map((item) => {
|
|
2768
2780
|
return getSpineItemNumberOfPages(item);
|
|
2769
2781
|
}, 0);
|
|
2770
|
-
reader
|
|
2782
|
+
reader.spineItems$.pipe(
|
|
2771
2783
|
tap(
|
|
2772
2784
|
(items) => items.forEach(({ item }) => {
|
|
2773
2785
|
chaptersInfo[item.id] = getChapterInfo2(item);
|
|
@@ -2808,9 +2820,6 @@
|
|
|
2808
2820
|
beginAbsolutePageIndex: totalPageInfo.numberOfPagesPerItems.slice(0, pageInfo.beginSpineItemIndex).reduce((acc, numberOfPagesForItem) => acc + numberOfPagesForItem, pageInfo.beginPageIndexInChapter ?? 0),
|
|
2809
2821
|
endAbsolutePageIndex: totalPageInfo.numberOfPagesPerItems.slice(0, pageInfo.endSpineItemIndex).reduce((acc, numberOfPagesForItem) => acc + numberOfPagesForItem, pageInfo.endPageIndexInChapter ?? 0)
|
|
2810
2822
|
})),
|
|
2811
|
-
tap((data) => {
|
|
2812
|
-
report$1.log(`pagination`, data);
|
|
2813
|
-
}),
|
|
2814
2823
|
shareReplay(1),
|
|
2815
2824
|
takeUntil(reader.$.destroy$)
|
|
2816
2825
|
);
|
|
@@ -2912,7 +2921,7 @@
|
|
|
2912
2921
|
removeStyle(`prose-reader-theme`);
|
|
2913
2922
|
addStyle(`prose-reader-theme`, getStyle());
|
|
2914
2923
|
});
|
|
2915
|
-
reader
|
|
2924
|
+
reader.spineItems$.pipe(
|
|
2916
2925
|
tap((items) => items.map(({ element }) => applyChangeToSpineItemElement({ container: element }))),
|
|
2917
2926
|
takeUntil(reader.$.destroy$)
|
|
2918
2927
|
).subscribe();
|
|
@@ -3320,7 +3329,7 @@
|
|
|
3320
3329
|
getVisibleAreaRect: () => visibleAreaRect,
|
|
3321
3330
|
shouldDisplaySpread,
|
|
3322
3331
|
setHasVerticalWriting,
|
|
3323
|
-
setVisibleAreaRect: (
|
|
3332
|
+
setVisibleAreaRect: ({ height, width, x, y }) => {
|
|
3324
3333
|
visibleAreaRect.width = width;
|
|
3325
3334
|
visibleAreaRect.height = height - marginTop - marginBottom;
|
|
3326
3335
|
visibleAreaRect.x = x;
|
|
@@ -3633,13 +3642,17 @@
|
|
|
3633
3642
|
getComputedStyleAfterLoad
|
|
3634
3643
|
} = createLoader({ context, hooks$, item, parent, fetchResource, viewportState$ });
|
|
3635
3644
|
let isLoadedSync = false;
|
|
3636
|
-
|
|
3645
|
+
let isReadySync = false;
|
|
3637
3646
|
isLoaded$.subscribe({
|
|
3638
3647
|
next: (value) => {
|
|
3639
3648
|
isLoadedSync = value;
|
|
3640
3649
|
}
|
|
3641
3650
|
});
|
|
3642
|
-
isReady$.subscribe(
|
|
3651
|
+
isReady$.subscribe({
|
|
3652
|
+
next: (value) => {
|
|
3653
|
+
isReadySync = value;
|
|
3654
|
+
}
|
|
3655
|
+
});
|
|
3643
3656
|
const getManipulableFrame = () => {
|
|
3644
3657
|
const frame = frameElement$.value;
|
|
3645
3658
|
if (isLoadedSync && frame) {
|
|
@@ -3691,8 +3704,14 @@
|
|
|
3691
3704
|
destroySubject$.complete();
|
|
3692
3705
|
};
|
|
3693
3706
|
return {
|
|
3707
|
+
/**
|
|
3708
|
+
* @deprecated
|
|
3709
|
+
*/
|
|
3694
3710
|
getIsLoaded: () => isLoadedSync,
|
|
3695
|
-
|
|
3711
|
+
/**
|
|
3712
|
+
* @deprecated
|
|
3713
|
+
*/
|
|
3714
|
+
getIsReady: () => isReadySync,
|
|
3696
3715
|
getViewportDimensions,
|
|
3697
3716
|
getFrameElement: () => frameElement$.getValue(),
|
|
3698
3717
|
getHtmlFromResource,
|
|
@@ -3736,7 +3755,7 @@
|
|
|
3736
3755
|
unloaded$,
|
|
3737
3756
|
loaded$,
|
|
3738
3757
|
ready$,
|
|
3739
|
-
isReady
|
|
3758
|
+
isReady$,
|
|
3740
3759
|
/**
|
|
3741
3760
|
* This is used as upstream layout change. This event is being listened to by upper app
|
|
3742
3761
|
* in order to layout again and adjust every element based on the new content.
|
|
@@ -4219,6 +4238,14 @@
|
|
|
4219
4238
|
var _a2;
|
|
4220
4239
|
return (_a2 = spineItemFrame.getWritingMode()) == null ? void 0 : _a2.startsWith(`vertical`);
|
|
4221
4240
|
},
|
|
4241
|
+
/**
|
|
4242
|
+
* @important
|
|
4243
|
+
* Do not use this value for layout and navigation. It will be in possible conflict
|
|
4244
|
+
* with the global reading direction. A book should not mix them anyway. A page can have
|
|
4245
|
+
* a different reading direction for style reason but it should be in theory pre-paginated.
|
|
4246
|
+
* For example an english page in a japanese manga. That's expected and will
|
|
4247
|
+
* be confined to a single page.
|
|
4248
|
+
*/
|
|
4222
4249
|
getReadingDirection: () => {
|
|
4223
4250
|
return spineItemFrame.getReadingDirection() || context.getReadingDirection();
|
|
4224
4251
|
},
|
|
@@ -5748,7 +5775,7 @@
|
|
|
5748
5775
|
currentNavigationPosition$,
|
|
5749
5776
|
viewportState$
|
|
5750
5777
|
}) => {
|
|
5751
|
-
const
|
|
5778
|
+
const spineItems$ = new rxjs.Subject();
|
|
5752
5779
|
const itemsBeforeDestroySubject$ = new rxjs.Subject();
|
|
5753
5780
|
const subject = new rxjs.Subject();
|
|
5754
5781
|
const containerElement = createContainerElement(ownerDocument, hooks$);
|
|
@@ -5763,7 +5790,7 @@
|
|
|
5763
5790
|
var _a;
|
|
5764
5791
|
itemsBeforeDestroySubject$.next();
|
|
5765
5792
|
spineItemManager.destroyItems();
|
|
5766
|
-
(_a = context.getManifest()) == null ? void 0 : _a.spineItems.map(
|
|
5793
|
+
(_a = context.getManifest()) == null ? void 0 : _a.spineItems.map((resource) => {
|
|
5767
5794
|
const spineItem = createSpineItem({
|
|
5768
5795
|
item: resource,
|
|
5769
5796
|
containerElement,
|
|
@@ -5774,7 +5801,7 @@
|
|
|
5774
5801
|
});
|
|
5775
5802
|
spineItemManager.add(spineItem);
|
|
5776
5803
|
});
|
|
5777
|
-
|
|
5804
|
+
spineItems$.next(spineItemManager.getAll());
|
|
5778
5805
|
};
|
|
5779
5806
|
const manipulateSpineItems = (cb) => {
|
|
5780
5807
|
let shouldLayout = false;
|
|
@@ -6020,7 +6047,7 @@
|
|
|
6020
6047
|
manipulateSpineItems,
|
|
6021
6048
|
manipulateSpineItem,
|
|
6022
6049
|
destroy: () => {
|
|
6023
|
-
|
|
6050
|
+
spineItems$.complete();
|
|
6024
6051
|
itemsBeforeDestroySubject$.next();
|
|
6025
6052
|
itemsBeforeDestroySubject$.complete();
|
|
6026
6053
|
subject.complete();
|
|
@@ -6040,7 +6067,7 @@
|
|
|
6040
6067
|
$: {
|
|
6041
6068
|
$: subject.asObservable(),
|
|
6042
6069
|
layout$: spineItemManager.$.layout$,
|
|
6043
|
-
|
|
6070
|
+
spineItems$: spineItems$.asObservable(),
|
|
6044
6071
|
itemsBeforeDestroy$: itemsBeforeDestroySubject$.asObservable()
|
|
6045
6072
|
}
|
|
6046
6073
|
};
|
|
@@ -6081,10 +6108,10 @@
|
|
|
6081
6108
|
const isGloballyPrePaginated = (manifest == null ? void 0 : manifest.renditionLayout) === `pre-paginated`;
|
|
6082
6109
|
manifest ? getCoverItem(manifest) : void 0;
|
|
6083
6110
|
orderedSpineItemsSubject$.value.reduce(
|
|
6084
|
-
(
|
|
6111
|
+
({ horizontalOffset, verticalOffset }, item, index) => {
|
|
6085
6112
|
let minimumWidth = context.getPageSize().width;
|
|
6086
6113
|
let blankPagePosition = `none`;
|
|
6087
|
-
const itemStartOnNewScreen =
|
|
6114
|
+
const itemStartOnNewScreen = horizontalOffset % context.getVisibleAreaRect().width === 0;
|
|
6088
6115
|
const isLastItem = index === orderedSpineItemsSubject$.value.length - 1;
|
|
6089
6116
|
if (context.shouldDisplaySpread()) {
|
|
6090
6117
|
if (!isGloballyPrePaginated && item.item.renditionLayout === `reflowable` && !isLastItem) {
|
|
@@ -6115,8 +6142,8 @@
|
|
|
6115
6142
|
spreadPosition: context.shouldDisplaySpread() ? itemStartOnNewScreen ? context.isRTL() ? `right` : `left` : context.isRTL() ? `left` : `right` : `none`
|
|
6116
6143
|
});
|
|
6117
6144
|
if (context.getSettings().computedPageTurnDirection === `vertical`) {
|
|
6118
|
-
const currentValidEdgeYForVerticalPositioning = itemStartOnNewScreen ?
|
|
6119
|
-
const currentValidEdgeXForVerticalPositioning = itemStartOnNewScreen ? 0 :
|
|
6145
|
+
const currentValidEdgeYForVerticalPositioning = itemStartOnNewScreen ? verticalOffset : verticalOffset - context.getVisibleAreaRect().height;
|
|
6146
|
+
const currentValidEdgeXForVerticalPositioning = itemStartOnNewScreen ? 0 : horizontalOffset;
|
|
6120
6147
|
if (context.isRTL()) {
|
|
6121
6148
|
item.adjustPositionOfElement({
|
|
6122
6149
|
top: currentValidEdgeYForVerticalPositioning,
|
|
@@ -6128,41 +6155,41 @@
|
|
|
6128
6155
|
left: currentValidEdgeXForVerticalPositioning
|
|
6129
6156
|
});
|
|
6130
6157
|
}
|
|
6131
|
-
const
|
|
6158
|
+
const newEdgeX = width + currentValidEdgeXForVerticalPositioning;
|
|
6132
6159
|
const newEdgeY = height + currentValidEdgeYForVerticalPositioning;
|
|
6133
6160
|
newItemLayoutInformation.push({
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6161
|
+
left: currentValidEdgeXForVerticalPositioning,
|
|
6162
|
+
right: newEdgeX,
|
|
6163
|
+
top: currentValidEdgeYForVerticalPositioning,
|
|
6164
|
+
bottom: newEdgeY,
|
|
6138
6165
|
height,
|
|
6139
6166
|
width
|
|
6140
6167
|
});
|
|
6141
6168
|
return {
|
|
6142
|
-
|
|
6143
|
-
|
|
6169
|
+
horizontalOffset: newEdgeX,
|
|
6170
|
+
verticalOffset: newEdgeY
|
|
6144
6171
|
};
|
|
6145
6172
|
}
|
|
6146
|
-
|
|
6147
|
-
item.adjustPositionOfElement({ right: edgeOffset.edgeX, top: 0 });
|
|
6148
|
-
} else {
|
|
6149
|
-
item.adjustPositionOfElement({ left: edgeOffset.edgeX, top: 0 });
|
|
6150
|
-
}
|
|
6151
|
-
const newEdgeX = width + edgeOffset.edgeX;
|
|
6173
|
+
item.adjustPositionOfElement(context.isRTL() ? { right: horizontalOffset, top: 0 } : { left: horizontalOffset, top: 0 });
|
|
6152
6174
|
newItemLayoutInformation.push({
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6156
|
-
|
|
6175
|
+
...context.isRTL() ? {
|
|
6176
|
+
left: context.getVisibleAreaRect().width - horizontalOffset - width,
|
|
6177
|
+
right: context.getVisibleAreaRect().width - horizontalOffset
|
|
6178
|
+
} : {
|
|
6179
|
+
left: horizontalOffset,
|
|
6180
|
+
right: horizontalOffset + width
|
|
6181
|
+
},
|
|
6182
|
+
top: verticalOffset,
|
|
6183
|
+
bottom: height,
|
|
6157
6184
|
height,
|
|
6158
6185
|
width
|
|
6159
6186
|
});
|
|
6160
6187
|
return {
|
|
6161
|
-
|
|
6162
|
-
|
|
6188
|
+
horizontalOffset: horizontalOffset + width,
|
|
6189
|
+
verticalOffset: 0
|
|
6163
6190
|
};
|
|
6164
6191
|
},
|
|
6165
|
-
{
|
|
6192
|
+
{ horizontalOffset: 0, verticalOffset: 0 }
|
|
6166
6193
|
);
|
|
6167
6194
|
const hasLayoutChanges = itemLayoutInformation.some((old, index) => !isShallowEqual(old, newItemLayoutInformation[index]));
|
|
6168
6195
|
itemLayoutInformation = newItemLayoutInformation;
|
|
@@ -6204,34 +6231,18 @@
|
|
|
6204
6231
|
}
|
|
6205
6232
|
return orderedSpineItemsSubject$.value.find(({ item }) => item.id === indexOrId);
|
|
6206
6233
|
};
|
|
6207
|
-
const getAbsolutePositionOf =
|
|
6208
|
-
`
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
topEnd: 0,
|
|
6220
|
-
width: 0,
|
|
6221
|
-
height: 0
|
|
6222
|
-
};
|
|
6223
|
-
}
|
|
6224
|
-
return itemLayoutInformation[indexOfItem] || {
|
|
6225
|
-
leftStart: 0,
|
|
6226
|
-
leftEnd: 0,
|
|
6227
|
-
topStart: 0,
|
|
6228
|
-
topEnd: 0,
|
|
6229
|
-
width: 0,
|
|
6230
|
-
height: 0
|
|
6231
|
-
};
|
|
6232
|
-
},
|
|
6233
|
-
{ disable: true }
|
|
6234
|
-
);
|
|
6234
|
+
const getAbsolutePositionOf = (spineItemOrIndex) => {
|
|
6235
|
+
const indexOfItem = typeof spineItemOrIndex === `number` ? spineItemOrIndex : orderedSpineItemsSubject$.value.indexOf(spineItemOrIndex);
|
|
6236
|
+
const layoutInformation = itemLayoutInformation[indexOfItem];
|
|
6237
|
+
return layoutInformation || {
|
|
6238
|
+
left: 0,
|
|
6239
|
+
right: 0,
|
|
6240
|
+
top: 0,
|
|
6241
|
+
bottom: 0,
|
|
6242
|
+
width: 0,
|
|
6243
|
+
height: 0
|
|
6244
|
+
};
|
|
6245
|
+
};
|
|
6235
6246
|
const getFocusedSpineItem = () => focusedSpineItemIndex !== void 0 ? orderedSpineItemsSubject$.value[focusedSpineItemIndex] : void 0;
|
|
6236
6247
|
const comparePositionOf = (toCompare, withItem) => {
|
|
6237
6248
|
const isAfter = orderedSpineItemsSubject$.value.indexOf(toCompare) > orderedSpineItemsSubject$.value.indexOf(withItem);
|
|
@@ -6269,26 +6280,6 @@
|
|
|
6269
6280
|
const item = getFocusedSpineItem();
|
|
6270
6281
|
return item && getSpineItemIndex(item);
|
|
6271
6282
|
};
|
|
6272
|
-
const getSpineItemAtPosition = Report.measurePerformance(
|
|
6273
|
-
`getSpineItemAtPosition`,
|
|
6274
|
-
10,
|
|
6275
|
-
(position) => {
|
|
6276
|
-
const detectedItem = orderedSpineItemsSubject$.value.find((item) => {
|
|
6277
|
-
const { leftStart, leftEnd, topEnd, topStart } = getAbsolutePositionOf(item);
|
|
6278
|
-
const isWithinXAxis = position.x >= leftStart && position.x < leftEnd;
|
|
6279
|
-
if (context.getSettings().computedPageTurnDirection === `horizontal`) {
|
|
6280
|
-
return isWithinXAxis;
|
|
6281
|
-
} else {
|
|
6282
|
-
return isWithinXAxis && position.y >= topStart && position.y < topEnd;
|
|
6283
|
-
}
|
|
6284
|
-
});
|
|
6285
|
-
if (position.x === 0 && !detectedItem) {
|
|
6286
|
-
return orderedSpineItemsSubject$.value[0];
|
|
6287
|
-
}
|
|
6288
|
-
return detectedItem;
|
|
6289
|
-
},
|
|
6290
|
-
{ disable: true }
|
|
6291
|
-
);
|
|
6292
6283
|
const destroyItems = () => {
|
|
6293
6284
|
orderedSpineItemsSubject$.value.forEach((item) => item.destroy());
|
|
6294
6285
|
};
|
|
@@ -6308,7 +6299,6 @@
|
|
|
6308
6299
|
loadContents,
|
|
6309
6300
|
comparePositionOf,
|
|
6310
6301
|
getAbsolutePositionOf,
|
|
6311
|
-
getSpineItemAtPosition,
|
|
6312
6302
|
getFocusedSpineItem,
|
|
6313
6303
|
getFocusedSpineItemIndex,
|
|
6314
6304
|
getSpineItemIndex,
|
|
@@ -6326,9 +6316,12 @@
|
|
|
6326
6316
|
};
|
|
6327
6317
|
};
|
|
6328
6318
|
const createLocationResolver$1 = ({ context }) => {
|
|
6319
|
+
const getSafePosition = (unsafeSpineItemPosition, spineItem) => ({
|
|
6320
|
+
x: Math.min(spineItem.getElementDimensions().width, Math.max(0, unsafeSpineItemPosition.x)),
|
|
6321
|
+
y: Math.min(spineItem.getElementDimensions().height, Math.max(0, unsafeSpineItemPosition.y))
|
|
6322
|
+
});
|
|
6329
6323
|
const getSpineItemPositionFromPageIndex = (pageIndex, spineItem) => {
|
|
6330
6324
|
const { width: itemWidth, height: itemHeight } = spineItem.getElementDimensions();
|
|
6331
|
-
const itemReadingDirection = spineItem.getReadingDirection();
|
|
6332
6325
|
if (spineItem.isUsingVerticalWriting()) {
|
|
6333
6326
|
const ltrRelativeOffset2 = getItemOffsetFromPageIndex(context.getPageSize().height, pageIndex, itemHeight);
|
|
6334
6327
|
return {
|
|
@@ -6337,7 +6330,7 @@
|
|
|
6337
6330
|
};
|
|
6338
6331
|
}
|
|
6339
6332
|
const ltrRelativeOffset = getItemOffsetFromPageIndex(context.getPageSize().width, pageIndex, itemWidth);
|
|
6340
|
-
if (
|
|
6333
|
+
if (context.isRTL()) {
|
|
6341
6334
|
return {
|
|
6342
6335
|
x: itemWidth - ltrRelativeOffset - context.getPageSize().width,
|
|
6343
6336
|
y: 0
|
|
@@ -6350,19 +6343,16 @@
|
|
|
6350
6343
|
};
|
|
6351
6344
|
const getSpineItemPageIndexFromPosition = (position, spineItem) => {
|
|
6352
6345
|
const { width: itemWidth, height: itemHeight } = spineItem.getElementDimensions();
|
|
6353
|
-
const itemReadingDirection = spineItem.getReadingDirection();
|
|
6354
6346
|
const pageWidth = context.getPageSize().width;
|
|
6355
6347
|
const pageHeight = context.getPageSize().height;
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
offsetNormalizedForLtr = itemWidth - offsetNormalizedForLtr - context.getPageSize().width;
|
|
6359
|
-
}
|
|
6348
|
+
const safePosition = getSafePosition(position, spineItem);
|
|
6349
|
+
const offset = context.isRTL() ? itemWidth - safePosition.x - context.getPageSize().width : safePosition.x;
|
|
6360
6350
|
if (spineItem.isUsingVerticalWriting()) {
|
|
6361
6351
|
const numberOfPages = getNumberOfPages(itemHeight, pageHeight);
|
|
6362
6352
|
return getPageFromOffset(position.y, pageHeight, numberOfPages);
|
|
6363
6353
|
} else {
|
|
6364
6354
|
const numberOfPages = getNumberOfPages(itemWidth, pageWidth);
|
|
6365
|
-
const pageIndex = getPageFromOffset(
|
|
6355
|
+
const pageIndex = getPageFromOffset(offset, pageWidth, numberOfPages);
|
|
6366
6356
|
return pageIndex;
|
|
6367
6357
|
}
|
|
6368
6358
|
};
|
|
@@ -6442,6 +6432,13 @@
|
|
|
6442
6432
|
getFirstNodeOrRangeAtPage
|
|
6443
6433
|
};
|
|
6444
6434
|
};
|
|
6435
|
+
class SpineItemNavigationPosition {
|
|
6436
|
+
constructor(position) {
|
|
6437
|
+
this.__symbol = `SpineItemNavigationPosition`;
|
|
6438
|
+
this.x = position.x;
|
|
6439
|
+
this.y = position.y;
|
|
6440
|
+
}
|
|
6441
|
+
}
|
|
6445
6442
|
const createNavigationResolver$1 = ({ context }) => {
|
|
6446
6443
|
const spineItemLocator = createLocationResolver$1({ context });
|
|
6447
6444
|
const getNavigationForLeftPage = (position, spineItem) => {
|
|
@@ -6455,7 +6452,8 @@
|
|
|
6455
6452
|
y: position.y + context.getPageSize().height
|
|
6456
6453
|
};
|
|
6457
6454
|
}
|
|
6458
|
-
|
|
6455
|
+
const navigationPosition = spineItemLocator.getSpineItemClosestPositionFromUnsafePosition(nextPotentialPosition, spineItem);
|
|
6456
|
+
return new SpineItemNavigationPosition(navigationPosition);
|
|
6459
6457
|
};
|
|
6460
6458
|
const getNavigationForRightPage = (position, spineItem) => {
|
|
6461
6459
|
let nextPotentialPosition = {
|
|
@@ -6468,7 +6466,8 @@
|
|
|
6468
6466
|
y: position.y - context.getPageSize().height
|
|
6469
6467
|
};
|
|
6470
6468
|
}
|
|
6471
|
-
|
|
6469
|
+
const navigationPosition = spineItemLocator.getSpineItemClosestPositionFromUnsafePosition(nextPotentialPosition, spineItem);
|
|
6470
|
+
return new SpineItemNavigationPosition(navigationPosition);
|
|
6472
6471
|
};
|
|
6473
6472
|
const getNavigationForLastPage = (spineItem) => {
|
|
6474
6473
|
if (spineItem.isUsingVerticalWriting()) {
|
|
@@ -6482,16 +6481,16 @@
|
|
|
6482
6481
|
}
|
|
6483
6482
|
};
|
|
6484
6483
|
const getNavigationForPage = (pageIndex, spineItem) => {
|
|
6485
|
-
const
|
|
6486
|
-
return
|
|
6484
|
+
const { x, y } = spineItemLocator.getSpineItemPositionFromPageIndex(pageIndex, spineItem);
|
|
6485
|
+
return new SpineItemNavigationPosition({ x, y });
|
|
6487
6486
|
};
|
|
6488
6487
|
const getNavigationFromNode = (spineItem, node, offset) => {
|
|
6489
6488
|
const position = spineItemLocator.getSpineItemPositionFromNode(node, offset, spineItem);
|
|
6490
|
-
return position || { x: 0, y: 0 };
|
|
6489
|
+
return new SpineItemNavigationPosition(position || { x: 0, y: 0 });
|
|
6491
6490
|
};
|
|
6492
6491
|
const getNavigationForPosition = (spineItem, position) => {
|
|
6493
6492
|
const potentiallyCorrectedPosition = spineItemLocator.getSpineItemClosestPositionFromUnsafePosition(position, spineItem);
|
|
6494
|
-
return potentiallyCorrectedPosition;
|
|
6493
|
+
return new SpineItemNavigationPosition(potentiallyCorrectedPosition);
|
|
6495
6494
|
};
|
|
6496
6495
|
return {
|
|
6497
6496
|
getNavigationForLeftPage,
|
|
@@ -6518,11 +6517,18 @@
|
|
|
6518
6517
|
(position) => {
|
|
6519
6518
|
const lastSpineItem = spineItemManager.get(spineItemManager.getLength() - 1);
|
|
6520
6519
|
const distanceOfLastSpineItem = spineItemManager.getAbsolutePositionOf(lastSpineItem || 0);
|
|
6521
|
-
const
|
|
6522
|
-
const
|
|
6520
|
+
const maximumYOffset = distanceOfLastSpineItem.bottom - context.getPageSize().height;
|
|
6521
|
+
const y = Math.min(Math.max(0, position.y), maximumYOffset);
|
|
6522
|
+
if (context.isRTL()) {
|
|
6523
|
+
return {
|
|
6524
|
+
x: Math.max(Math.min(0, position.x), distanceOfLastSpineItem.left),
|
|
6525
|
+
y
|
|
6526
|
+
};
|
|
6527
|
+
}
|
|
6528
|
+
const maximumXOffset = distanceOfLastSpineItem.right - context.getPageSize().width;
|
|
6523
6529
|
return {
|
|
6524
6530
|
x: Math.min(Math.max(0, position.x), maximumXOffset),
|
|
6525
|
-
y
|
|
6531
|
+
y
|
|
6526
6532
|
};
|
|
6527
6533
|
},
|
|
6528
6534
|
{ disable: true }
|
|
@@ -6538,7 +6544,7 @@
|
|
|
6538
6544
|
if (!spineItem) {
|
|
6539
6545
|
Report.warn(NAMESPACE$3, `unable to detect item id from cfi ${cfi}`);
|
|
6540
6546
|
} else {
|
|
6541
|
-
const spineItemNavigation = node ? spineItemNavigator.getNavigationFromNode(spineItem, node, offset) : { x: 0, y: 0 };
|
|
6547
|
+
const spineItemNavigation = node ? spineItemNavigator.getNavigationFromNode(spineItem, node, offset) : new SpineItemNavigationPosition({ x: 0, y: 0 });
|
|
6542
6548
|
const readingPosition = locator.getSpinePositionFromSpineItemPosition(spineItemNavigation, spineItem);
|
|
6543
6549
|
return { ...getAdjustedPositionForSpread(readingPosition), spineItem };
|
|
6544
6550
|
}
|
|
@@ -6575,10 +6581,10 @@
|
|
|
6575
6581
|
}
|
|
6576
6582
|
const spineItemPosition = locator.getSpineItemPositionFromSpinePosition(position, spineItem);
|
|
6577
6583
|
const spineItemNavigationForRightPage = spineItemNavigator.getNavigationForRightPage(spineItemPosition, spineItem);
|
|
6578
|
-
const isNewNavigationInCurrentItem =
|
|
6584
|
+
const isNewNavigationInCurrentItem = arePositionsDifferent(spineItemNavigationForRightPage, spineItemPosition);
|
|
6579
6585
|
if (!isNewNavigationInCurrentItem) {
|
|
6580
6586
|
return wrapPositionWithSafeEdge(
|
|
6581
|
-
|
|
6587
|
+
pageTurnDirection === `horizontal` ? { x: position.x + context.getPageSize().width, y: 0 } : { y: position.y + context.getPageSize().height, x: 0 }
|
|
6582
6588
|
);
|
|
6583
6589
|
} else {
|
|
6584
6590
|
const readingOrderPosition = locator.getSpinePositionFromSpineItemPosition(spineItemNavigationForRightPage, spineItem);
|
|
@@ -6594,10 +6600,10 @@
|
|
|
6594
6600
|
}
|
|
6595
6601
|
const spineItemPosition = locator.getSpineItemPositionFromSpinePosition(position, spineItem);
|
|
6596
6602
|
const spineItemNavigation = spineItemNavigator.getNavigationForLeftPage(spineItemPosition, spineItem);
|
|
6597
|
-
const isNewNavigationInCurrentItem =
|
|
6603
|
+
const isNewNavigationInCurrentItem = arePositionsDifferent(spineItemNavigation, spineItemPosition);
|
|
6598
6604
|
if (!isNewNavigationInCurrentItem) {
|
|
6599
6605
|
return wrapPositionWithSafeEdge(
|
|
6600
|
-
|
|
6606
|
+
pageTurnDirection === `horizontal` ? { x: position.x - context.getPageSize().width, y: 0 } : { y: position.y - context.getPageSize().height, x: 0 }
|
|
6601
6607
|
);
|
|
6602
6608
|
} else {
|
|
6603
6609
|
const readingOrderPosition = locator.getSpinePositionFromSpineItemPosition(spineItemNavigation, spineItem);
|
|
@@ -6606,7 +6612,7 @@
|
|
|
6606
6612
|
};
|
|
6607
6613
|
const getNavigationForRightPage = (position) => {
|
|
6608
6614
|
const spineItemOnPosition = locator.getSpineItemFromPosition(position) || spineItemManager.getFocusedSpineItem();
|
|
6609
|
-
|
|
6615
|
+
const navigation = getNavigationForRightSinglePage(position);
|
|
6610
6616
|
if ((spineItemOnPosition == null ? void 0 : spineItemOnPosition.isUsingVerticalWriting()) && position.x === navigation.x) {
|
|
6611
6617
|
return getAdjustedPositionForSpread(navigation);
|
|
6612
6618
|
}
|
|
@@ -6627,13 +6633,14 @@
|
|
|
6627
6633
|
if (context.getSettings().computedPageTurnDirection === `vertical` && position.y !== navigation.y) {
|
|
6628
6634
|
return getAdjustedPositionForSpread(navigation);
|
|
6629
6635
|
}
|
|
6630
|
-
|
|
6636
|
+
const doubleNavigation = getNavigationForRightSinglePage(navigation);
|
|
6637
|
+
return getAdjustedPositionForSpread(doubleNavigation);
|
|
6631
6638
|
}
|
|
6632
6639
|
return getAdjustedPositionForSpread(navigation);
|
|
6633
6640
|
};
|
|
6634
6641
|
const getNavigationForLeftPage = (position) => {
|
|
6635
6642
|
const spineItemOnPosition = locator.getSpineItemFromPosition(position) || spineItemManager.getFocusedSpineItem();
|
|
6636
|
-
|
|
6643
|
+
const navigation = getNavigationForLeftSinglePage(position);
|
|
6637
6644
|
if ((spineItemOnPosition == null ? void 0 : spineItemOnPosition.isUsingVerticalWriting()) && position.x === navigation.x) {
|
|
6638
6645
|
return getAdjustedPositionForSpread(navigation);
|
|
6639
6646
|
}
|
|
@@ -6648,17 +6655,17 @@
|
|
|
6648
6655
|
if (context.getSettings().computedPageTurnDirection === `vertical` && position.y !== navigation.y) {
|
|
6649
6656
|
return getAdjustedPositionForSpread(navigation);
|
|
6650
6657
|
}
|
|
6651
|
-
|
|
6658
|
+
const doubleNavigation = getNavigationForLeftSinglePage(navigation);
|
|
6659
|
+
return getAdjustedPositionForSpread(doubleNavigation);
|
|
6652
6660
|
}
|
|
6653
6661
|
return getAdjustedPositionForSpread(navigation);
|
|
6654
6662
|
};
|
|
6655
6663
|
const getNavigationForUrl = (url) => {
|
|
6656
|
-
var _a
|
|
6664
|
+
var _a;
|
|
6657
6665
|
try {
|
|
6658
6666
|
const validUrl = url instanceof URL ? url : new URL(url);
|
|
6659
6667
|
const urlWithoutAnchor = `${validUrl.origin}${validUrl.pathname}`;
|
|
6660
6668
|
const existingSpineItem = (_a = context.getManifest()) == null ? void 0 : _a.spineItems.find((item) => item.href === urlWithoutAnchor);
|
|
6661
|
-
console.log({ validUrl, urlWithoutAnchor, existingSpineItem }, (_b = context.getManifest()) == null ? void 0 : _b.spineItems);
|
|
6662
6669
|
if (existingSpineItem) {
|
|
6663
6670
|
const spineItem = spineItemManager.get(existingSpineItem.id);
|
|
6664
6671
|
if (spineItem) {
|
|
@@ -6913,7 +6920,11 @@
|
|
|
6913
6920
|
if (allowSpineItemChange) {
|
|
6914
6921
|
const positionOfNewSpineItemComparedToCurrentOne = spineItemManager.comparePositionOf(newSpineItem, currentSpineItem);
|
|
6915
6922
|
if (positionOfNewSpineItemComparedToCurrentOne === `before`) {
|
|
6916
|
-
return rxjs.of({
|
|
6923
|
+
return rxjs.of({
|
|
6924
|
+
...navigation,
|
|
6925
|
+
lastUserExpectedNavigation: { type: `navigate-from-next-item` },
|
|
6926
|
+
animate: true
|
|
6927
|
+
});
|
|
6917
6928
|
} else {
|
|
6918
6929
|
return rxjs.of({
|
|
6919
6930
|
...navigation,
|
|
@@ -7030,7 +7041,7 @@
|
|
|
7030
7041
|
const correctedX = delta.x - ((movingLastDelta == null ? void 0 : movingLastDelta.x) || 0);
|
|
7031
7042
|
const correctedY = delta.y - ((movingLastDelta == null ? void 0 : movingLastDelta.y) || 0);
|
|
7032
7043
|
navigation = navigator2.wrapPositionWithSafeEdge({
|
|
7033
|
-
x: pageTurnDirection === `horizontal` ?
|
|
7044
|
+
x: pageTurnDirection === `horizontal` ? movingLastPosition.x - correctedX : 0,
|
|
7034
7045
|
y: pageTurnDirection === `horizontal` ? 0 : movingLastPosition.y - correctedY
|
|
7035
7046
|
});
|
|
7036
7047
|
movingLastDelta = delta;
|
|
@@ -7092,7 +7103,10 @@
|
|
|
7092
7103
|
const triggerPercentage = movingForward ? 1 - navigationSnapThreshold : navigationSnapThreshold;
|
|
7093
7104
|
const triggerXPosition = pageTurnDirection === `horizontal` ? to.x + context.getVisibleAreaRect().width * triggerPercentage : 0;
|
|
7094
7105
|
const triggerYPosition = pageTurnDirection === `horizontal` ? 0 : to.y + context.getVisibleAreaRect().height * triggerPercentage;
|
|
7095
|
-
const midScreenPositionSafePosition = navigator2.wrapPositionWithSafeEdge({
|
|
7106
|
+
const midScreenPositionSafePosition = navigator2.wrapPositionWithSafeEdge({
|
|
7107
|
+
x: triggerXPosition,
|
|
7108
|
+
y: triggerYPosition
|
|
7109
|
+
});
|
|
7096
7110
|
const finalNavigation = navigator2.getNavigationForPosition(midScreenPositionSafePosition);
|
|
7097
7111
|
const lastUserExpectedNavigation = getLastUserExpectedNavigation(finalNavigation);
|
|
7098
7112
|
return rxjs.of({ ...finalNavigation, lastUserExpectedNavigation });
|
|
@@ -7131,7 +7145,11 @@
|
|
|
7131
7145
|
element.appendChild(spine.element);
|
|
7132
7146
|
const layoutSubject$ = new rxjs.Subject();
|
|
7133
7147
|
let currentViewportPositionMemoUnused;
|
|
7134
|
-
const currentNavigationPositionSubject$ = new rxjs.BehaviorSubject({
|
|
7148
|
+
const currentNavigationPositionSubject$ = new rxjs.BehaviorSubject({
|
|
7149
|
+
x: -1,
|
|
7150
|
+
y: 0,
|
|
7151
|
+
spineItem: void 0
|
|
7152
|
+
});
|
|
7135
7153
|
const navigator2 = createNavigationResolver({
|
|
7136
7154
|
context,
|
|
7137
7155
|
spineItemManager,
|
|
@@ -7141,8 +7159,6 @@
|
|
|
7141
7159
|
const adjustNavigationSubject$ = new rxjs.Subject();
|
|
7142
7160
|
parentElement.appendChild(element);
|
|
7143
7161
|
const getCurrentViewportPosition = Report.measurePerformance(`${NAMESPACE} getCurrentViewportPosition`, 1, () => {
|
|
7144
|
-
if (currentViewportPositionMemoUnused && (currentViewportPositionMemoUnused == null ? void 0 : currentViewportPositionMemoUnused.x) !== ~~(Math.abs(element.getBoundingClientRect().x) * 10) / 10)
|
|
7145
|
-
;
|
|
7146
7162
|
if (context.getSettings().computedPageTurnMode === `scrollable`) {
|
|
7147
7163
|
return scrollViewportNavigator.getCurrentViewportPosition();
|
|
7148
7164
|
}
|
|
@@ -7151,7 +7167,8 @@
|
|
|
7151
7167
|
// we want to round to first decimal because it's possible to have half pixel
|
|
7152
7168
|
// however browser engine can also gives back x.yyyy based on their precision
|
|
7153
7169
|
// @see https://stackoverflow.com/questions/13847053/difference-between-and-math-floor for ~~
|
|
7154
|
-
x: ~~(
|
|
7170
|
+
x: ~~(x * -1 * 10) / 10,
|
|
7171
|
+
// x: ~~(x * 10) / 10,
|
|
7155
7172
|
y: ~~(Math.abs(y) * 10) / 10
|
|
7156
7173
|
};
|
|
7157
7174
|
currentViewportPositionMemoUnused = newValue;
|
|
@@ -7198,11 +7215,7 @@
|
|
|
7198
7215
|
return navigator22.adjustReadingOffset({ x, y }) || isAdjusted2;
|
|
7199
7216
|
}, false);
|
|
7200
7217
|
if (!isAdjusted) {
|
|
7201
|
-
|
|
7202
|
-
element.style.transform = `translate3d(${x}px, -${y}px, 0)`;
|
|
7203
|
-
} else {
|
|
7204
|
-
element.style.transform = `translate3d(-${x}px, -${y}px, 0)`;
|
|
7205
|
-
}
|
|
7218
|
+
element.style.transform = `translate3d(${-x}px, -${y}px, 0)`;
|
|
7206
7219
|
}
|
|
7207
7220
|
hooks.forEach((hook) => {
|
|
7208
7221
|
if (hook.name === `onViewportOffsetAdjust`) {
|
|
@@ -7527,14 +7540,7 @@
|
|
|
7527
7540
|
`getSpineItemPositionFromSpinePosition`,
|
|
7528
7541
|
10,
|
|
7529
7542
|
(position, spineItem) => {
|
|
7530
|
-
const {
|
|
7531
|
-
if (context.isRTL()) {
|
|
7532
|
-
return {
|
|
7533
|
-
x: leftEnd - position.x - context.getPageSize().width,
|
|
7534
|
-
// y: (topEnd - position.y) - context.getPageSize().height,
|
|
7535
|
-
y: Math.max(0, position.y - topStart)
|
|
7536
|
-
};
|
|
7537
|
-
}
|
|
7543
|
+
const { left, top } = spineItemManager.getAbsolutePositionOf(spineItem);
|
|
7538
7544
|
return {
|
|
7539
7545
|
/**
|
|
7540
7546
|
* when using spread the item could be on the right and therefore will be negative
|
|
@@ -7543,31 +7549,35 @@
|
|
|
7543
7549
|
* 400 - 600 = -200.
|
|
7544
7550
|
* However we can assume we are at 0, because we in fact can see the beginning of the item
|
|
7545
7551
|
*/
|
|
7546
|
-
x:
|
|
7547
|
-
y:
|
|
7552
|
+
x: position.x - left,
|
|
7553
|
+
y: position.y - top
|
|
7548
7554
|
};
|
|
7549
7555
|
},
|
|
7550
7556
|
{ disable: true }
|
|
7551
7557
|
);
|
|
7552
7558
|
const getSpinePositionFromSpineItemPosition = (spineItemPosition, spineItem) => {
|
|
7553
|
-
const {
|
|
7554
|
-
if (context.isRTL()) {
|
|
7555
|
-
return {
|
|
7556
|
-
x: leftEnd - spineItemPosition.x - context.getPageSize().width,
|
|
7557
|
-
// y: (topEnd - spineItemPosition.y) - context.getPageSize().height,
|
|
7558
|
-
y: topStart + spineItemPosition.y
|
|
7559
|
-
};
|
|
7560
|
-
}
|
|
7559
|
+
const { left, top } = spineItemManager.getAbsolutePositionOf(spineItem);
|
|
7561
7560
|
return {
|
|
7562
|
-
x:
|
|
7563
|
-
y:
|
|
7561
|
+
x: left + spineItemPosition.x,
|
|
7562
|
+
y: top + spineItemPosition.y
|
|
7564
7563
|
};
|
|
7565
7564
|
};
|
|
7566
7565
|
const getSpineItemFromPosition = Report.measurePerformance(
|
|
7567
7566
|
`getSpineItemFromOffset`,
|
|
7568
7567
|
10,
|
|
7569
7568
|
(position) => {
|
|
7570
|
-
const spineItem = spineItemManager.
|
|
7569
|
+
const spineItem = spineItemManager.getAll().find((item) => {
|
|
7570
|
+
const { left, right, bottom, top } = spineItemManager.getAbsolutePositionOf(item);
|
|
7571
|
+
const isWithinXAxis = position.x >= left && position.x < right;
|
|
7572
|
+
if (context.getSettings().computedPageTurnDirection === `horizontal`) {
|
|
7573
|
+
return isWithinXAxis;
|
|
7574
|
+
} else {
|
|
7575
|
+
return isWithinXAxis && position.y >= top && position.y < bottom;
|
|
7576
|
+
}
|
|
7577
|
+
});
|
|
7578
|
+
if (position.x === 0 && !spineItem) {
|
|
7579
|
+
return spineItemManager.getAll()[0];
|
|
7580
|
+
}
|
|
7571
7581
|
return spineItem;
|
|
7572
7582
|
},
|
|
7573
7583
|
{ disable: true }
|
|
@@ -7581,23 +7591,30 @@
|
|
|
7581
7591
|
return position;
|
|
7582
7592
|
};
|
|
7583
7593
|
const getSpineItemsFromReadingOrderPosition = (position) => {
|
|
7584
|
-
const
|
|
7585
|
-
const
|
|
7586
|
-
if (
|
|
7594
|
+
const itemAtPosition = getSpineItemFromPosition(position) || spineItemManager.getFocusedSpineItem();
|
|
7595
|
+
const itemAtPositionIndex = spineItemManager.getSpineItemIndex(itemAtPosition);
|
|
7596
|
+
if (itemAtPositionIndex === void 0)
|
|
7587
7597
|
return void 0;
|
|
7588
7598
|
let endPosition = position;
|
|
7589
7599
|
if (context.shouldDisplaySpread()) {
|
|
7590
7600
|
endPosition = { x: position.x + context.getPageSize().width, y: position.y };
|
|
7591
7601
|
}
|
|
7592
|
-
const endItemIndex = spineItemManager.getSpineItemIndex(getSpineItemFromPosition(endPosition) || spineItemManager.getFocusedSpineItem()) ??
|
|
7593
|
-
const
|
|
7602
|
+
const endItemIndex = spineItemManager.getSpineItemIndex(getSpineItemFromPosition(endPosition) || spineItemManager.getFocusedSpineItem()) ?? itemAtPositionIndex;
|
|
7603
|
+
const items = [
|
|
7604
|
+
{ item: itemAtPositionIndex, position },
|
|
7605
|
+
{ item: endItemIndex, position: endPosition }
|
|
7606
|
+
];
|
|
7607
|
+
const [begin, end] = items.sort((a, b) => {
|
|
7608
|
+
if (a.item === b.item) {
|
|
7609
|
+
return context.isRTL() ? b.position.x - a.position.x : a.position.x - b.position.x;
|
|
7610
|
+
}
|
|
7611
|
+
return a.item - b.item;
|
|
7612
|
+
});
|
|
7594
7613
|
return {
|
|
7595
|
-
begin:
|
|
7596
|
-
beginPosition: position,
|
|
7597
|
-
end:
|
|
7598
|
-
endPosition
|
|
7599
|
-
left,
|
|
7600
|
-
right
|
|
7614
|
+
begin: begin.item,
|
|
7615
|
+
beginPosition: begin.position,
|
|
7616
|
+
end: end.item,
|
|
7617
|
+
endPosition: end.position
|
|
7601
7618
|
};
|
|
7602
7619
|
};
|
|
7603
7620
|
const getSpineItemFromIframe = (iframe) => {
|
|
@@ -7779,7 +7796,12 @@
|
|
|
7779
7796
|
element.style.height = `${dimensions.height - marginTop - marginBottom}px`;
|
|
7780
7797
|
element.style.width = `${containerElementEvenWidth - 2 * margin}px`;
|
|
7781
7798
|
const elementRect = element.getBoundingClientRect();
|
|
7782
|
-
context.setVisibleAreaRect(
|
|
7799
|
+
context.setVisibleAreaRect({
|
|
7800
|
+
x: elementRect.x,
|
|
7801
|
+
y: elementRect.y,
|
|
7802
|
+
width: containerElementEvenWidth,
|
|
7803
|
+
height: dimensions.height
|
|
7804
|
+
});
|
|
7783
7805
|
viewportNavigator.layout();
|
|
7784
7806
|
};
|
|
7785
7807
|
const load = (manifest, loadOptions = {}) => {
|
|
@@ -7900,6 +7922,7 @@
|
|
|
7900
7922
|
* BehaviorSubject
|
|
7901
7923
|
*/
|
|
7902
7924
|
pagination$: pagination.$.info$,
|
|
7925
|
+
spineItems$: spine.$.spineItems$,
|
|
7903
7926
|
$: {
|
|
7904
7927
|
state$: stateSubject$.asObservable(),
|
|
7905
7928
|
/**
|
|
@@ -7915,7 +7938,6 @@
|
|
|
7915
7938
|
selection$: selectionSubject$.asObservable(),
|
|
7916
7939
|
viewportState$: viewportNavigator.$.state$,
|
|
7917
7940
|
layout$: spine.$.layout$,
|
|
7918
|
-
itemsCreated$: spine.$.itemsCreated$,
|
|
7919
7941
|
itemsBeforeDestroy$: spine.$.itemsBeforeDestroy$,
|
|
7920
7942
|
itemIsReady$: spineItemManager.$.itemIsReady$,
|
|
7921
7943
|
destroy$
|
|
@@ -8273,11 +8295,11 @@
|
|
|
8273
8295
|
};
|
|
8274
8296
|
const getScrollPercentageWithinItem = (context, currentPosition, currentItem) => {
|
|
8275
8297
|
const { height, width } = currentItem.getElementDimensions();
|
|
8276
|
-
const {
|
|
8298
|
+
const { top, left } = reader.getAbsolutePositionOf(currentItem);
|
|
8277
8299
|
if (context.getSettings().computedPageTurnDirection === `vertical`) {
|
|
8278
|
-
return Math.max(0, Math.min(1, (currentPosition.y -
|
|
8300
|
+
return Math.max(0, Math.min(1, (currentPosition.y - top + context.getVisibleAreaRect().height) / height));
|
|
8279
8301
|
} else {
|
|
8280
|
-
return Math.max(0, Math.min(1, (currentPosition.x -
|
|
8302
|
+
return Math.max(0, Math.min(1, (currentPosition.x - left + context.getVisibleAreaRect().width) / width));
|
|
8281
8303
|
}
|
|
8282
8304
|
};
|
|
8283
8305
|
return {
|
|
@@ -8405,7 +8427,7 @@
|
|
|
8405
8427
|
return {};
|
|
8406
8428
|
})
|
|
8407
8429
|
);
|
|
8408
|
-
const items$ = reader
|
|
8430
|
+
const items$ = reader.spineItems$.pipe(
|
|
8409
8431
|
switchMap((items) => createEntries$(items)),
|
|
8410
8432
|
shareReplay(1),
|
|
8411
8433
|
takeUntil(reader.context.$.destroy$)
|