@prose-reader/core 1.57.0 → 1.59.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/cfi.d.ts +74 -0
- package/dist/constants.d.ts +6 -0
- package/dist/context/Context.d.ts +63 -0
- package/dist/context/isUsingSpreadMode.d.ts +10 -0
- package/dist/createReaderWithEnhancer.d.ts +268 -0
- package/dist/enhancers/accessibility.d.ts +3 -0
- package/dist/enhancers/chrome.d.ts +3 -0
- package/dist/enhancers/events/createIframeEventBridgeElement.d.ts +1 -0
- package/dist/enhancers/events/events.d.ts +8 -0
- package/dist/enhancers/events/normalizeEventForViewport.d.ts +7 -0
- package/dist/enhancers/firefox.d.ts +3 -0
- package/dist/enhancers/fonts.d.ts +19 -0
- package/dist/enhancers/hotkeys.d.ts +3 -0
- package/dist/enhancers/layoutEnhancer/createMovingSafePan$.d.ts +4 -0
- package/dist/enhancers/layoutEnhancer/fixReflowable.d.ts +3 -0
- package/dist/enhancers/layoutEnhancer/layoutEnhancer.d.ts +10 -0
- package/dist/enhancers/layoutEnhancer/types.d.ts +8 -0
- package/dist/enhancers/links.d.ts +14 -0
- package/dist/enhancers/loadingEnhancer.d.ts +24 -0
- package/dist/enhancers/media.d.ts +3 -0
- package/dist/enhancers/navigation/navigation.d.ts +9 -0
- package/dist/enhancers/navigation/navigator.d.ts +8 -0
- package/dist/enhancers/navigation/state.d.ts +12 -0
- package/dist/enhancers/pagination/chapters.d.ts +24 -0
- package/dist/enhancers/pagination/constants.d.ts +1 -0
- package/dist/enhancers/pagination/enhancer.d.ts +14 -0
- package/dist/enhancers/pagination/pagination.d.ts +10 -0
- package/dist/enhancers/pagination/spine.d.ts +13 -0
- package/dist/enhancers/pagination/types.d.ts +19 -0
- package/dist/enhancers/pagination.test.d.ts +1 -0
- package/dist/enhancers/progression.d.ts +16 -0
- package/dist/enhancers/publicApi.d.ts +5 -0
- package/dist/enhancers/resources/index.d.ts +3 -0
- package/dist/enhancers/resources/indexedDB.d.ts +6 -0
- package/dist/enhancers/resources/resourcesManager.d.ts +7 -0
- package/dist/enhancers/theme.d.ts +32 -0
- package/dist/enhancers/types/enhancer.d.ts +9 -0
- package/dist/enhancers/utils.d.ts +7 -0
- package/dist/enhancers/webkit.d.ts +3 -0
- package/dist/enhancers/zoom/elementZoomer.d.ts +19 -0
- package/dist/enhancers/zoom/index.d.ts +4 -0
- package/dist/enhancers/zoom/types.d.ts +23 -0
- package/dist/enhancers/zoom/viewportZoomer.d.ts +19 -0
- package/dist/frames.d.ts +5 -0
- package/dist/hooks/HookManager.d.ts +10 -0
- package/dist/hooks/types.d.ts +64 -0
- package/dist/index.d.ts +9 -4262
- package/dist/index.js +225 -255
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +225 -255
- package/dist/index.umd.cjs.map +1 -1
- package/dist/manifest/areAllItemsPrePaginated.d.ts +3 -0
- package/dist/manifest/isFullyPrePaginated.d.ts +3 -0
- package/dist/pagination/pagination.d.ts +88 -0
- package/dist/pagination/types.d.ts +10 -0
- package/dist/reader.d.ts +8 -0
- package/dist/report.d.ts +26 -0
- package/dist/selection.d.ts +7 -0
- package/dist/settings/SettingsManager.d.ts +14 -0
- package/dist/settings/defaultSettings.d.ts +3 -0
- package/dist/settings/getComputedSettings.d.ts +4 -0
- package/dist/settings/types.d.ts +19 -0
- package/dist/spine/cfiLocator.d.ts +340 -0
- package/dist/spine/createSpine.d.ts +31 -0
- package/dist/spine/locationResolver.d.ts +636 -0
- package/dist/spine/navigationResolver.d.ts +48 -0
- package/dist/spine/types.d.ts +10 -0
- package/dist/spineItem/commonSpineItem.d.ts +165 -0
- package/dist/spineItem/createSpineItem.d.ts +167 -0
- package/dist/spineItem/frameItem/createFrame$.d.ts +1 -0
- package/dist/spineItem/frameItem/createFrameManipulator.d.ts +5 -0
- package/dist/spineItem/frameItem/createHtmlPageFromResource.d.ts +3 -0
- package/dist/spineItem/frameItem/frameItem.d.ts +49 -0
- package/dist/spineItem/frameItem/loader.d.ts +30 -0
- package/dist/spineItem/locationResolver.d.ts +24 -0
- package/dist/spineItem/navigationResolver.d.ts +16 -0
- package/dist/spineItem/prePaginatedSpineItem.d.ts +166 -0
- package/dist/spineItem/reflowableSpineItem.d.ts +165 -0
- package/dist/spineItem/styles/getStyleForViewportDocument.d.ts +1 -0
- package/dist/spineItem/trackers.d.ts +34 -0
- package/dist/spineItem/types.d.ts +19 -0
- package/dist/spineItemManager.d.ts +505 -0
- package/dist/types/Spine.d.ts +40 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/reader.d.ts +44 -0
- package/dist/utils/compose.d.ts +8 -0
- package/dist/utils/dom.d.ts +19 -0
- package/dist/utils/isDefined.d.ts +1 -0
- package/dist/utils/layout.d.ts +7 -0
- package/dist/utils/layout.test.d.ts +1 -0
- package/dist/utils/manifest.d.ts +3 -0
- package/dist/utils/objects.d.ts +6 -0
- package/dist/utils/objects.test.d.ts +1 -0
- package/dist/utils/rxjs.d.ts +5 -0
- package/dist/viewportNavigator/manualViewportNavigator.d.ts +96 -0
- package/dist/viewportNavigator/panViewportNavigator.d.ts +55 -0
- package/dist/viewportNavigator/scrollViewportNavigator.d.ts +38 -0
- package/dist/viewportNavigator/types.d.ts +34 -0
- package/dist/viewportNavigator/viewportNavigator.d.ts +82 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -4,8 +4,7 @@ import { parseContentType, detectMimeTypeFromName } from "@prose-reader/shared";
|
|
|
4
4
|
const chromeEnhancer = (next) => (options) => {
|
|
5
5
|
const reader = next(options);
|
|
6
6
|
reader.context.state$.pipe(takeUntil(reader.$.destroy$)).subscribe(({ containerElement }) => {
|
|
7
|
-
if (!containerElement)
|
|
8
|
-
return;
|
|
7
|
+
if (!containerElement) return;
|
|
9
8
|
const onScroll = () => {
|
|
10
9
|
if (reader.settings.settings.computedPageTurnMode === `controlled`) {
|
|
11
10
|
containerElement.scrollTo(0, 0);
|
|
@@ -54,8 +53,7 @@ const isShallowEqual = (objectA, objectB, options) => {
|
|
|
54
53
|
const groupBy = (list, getKey) => list.reduce(
|
|
55
54
|
(previous, currentItem) => {
|
|
56
55
|
const group = getKey(currentItem);
|
|
57
|
-
if (!previous[group])
|
|
58
|
-
previous[group] = [];
|
|
56
|
+
if (!previous[group]) previous[group] = [];
|
|
59
57
|
previous[group].push(currentItem);
|
|
60
58
|
return previous;
|
|
61
59
|
},
|
|
@@ -75,7 +73,12 @@ const getBase64FromBlob = (data) => {
|
|
|
75
73
|
});
|
|
76
74
|
};
|
|
77
75
|
const fontsEnhancer = (next) => (options) => {
|
|
78
|
-
const {
|
|
76
|
+
const {
|
|
77
|
+
fontScale = 1,
|
|
78
|
+
lineHeight = `publisher`,
|
|
79
|
+
fontWeight = `publisher`,
|
|
80
|
+
fontJustification = `publisher`
|
|
81
|
+
} = options;
|
|
79
82
|
const changes$ = new Subject();
|
|
80
83
|
const settings$ = new BehaviorSubject({
|
|
81
84
|
fontScale,
|
|
@@ -123,10 +126,8 @@ const fontsEnhancer = (next) => (options) => {
|
|
|
123
126
|
const shouldRequireLayout = (source) => source.pipe(
|
|
124
127
|
pairwise(),
|
|
125
128
|
map(([old, latest]) => {
|
|
126
|
-
if (latest.fontScale !== old.fontScale)
|
|
127
|
-
|
|
128
|
-
if (latest.lineHeight !== old.lineHeight)
|
|
129
|
-
return true;
|
|
129
|
+
if (latest.fontScale !== old.fontScale) return true;
|
|
130
|
+
if (latest.lineHeight !== old.lineHeight) return true;
|
|
130
131
|
return false;
|
|
131
132
|
})
|
|
132
133
|
);
|
|
@@ -211,8 +212,7 @@ const createMovingSafePan$ = (reader) => {
|
|
|
211
212
|
let iframeOverlayForAnimationsElement;
|
|
212
213
|
const updateOverlayElement$ = reader.context.state$.pipe(
|
|
213
214
|
switchMap$1(({ containerElement }) => {
|
|
214
|
-
if (!containerElement)
|
|
215
|
-
return NEVER;
|
|
215
|
+
if (!containerElement) return NEVER;
|
|
216
216
|
return new Observable(() => {
|
|
217
217
|
iframeOverlayForAnimationsElement = containerElement.ownerDocument.createElement(`div`);
|
|
218
218
|
iframeOverlayForAnimationsElement.style.cssText = `
|
|
@@ -276,8 +276,7 @@ const fixReflowable = (reader) => {
|
|
|
276
276
|
reader.hookManager.register(`item.onAfterLayout`, ({ item, blankPagePosition, minimumWidth }) => {
|
|
277
277
|
var _a;
|
|
278
278
|
const spineItem = reader.spineItemManager.get(item.id);
|
|
279
|
-
if (!((spineItem == null ? void 0 : spineItem.item.renditionLayout) === `reflowable`))
|
|
280
|
-
return;
|
|
279
|
+
if (!((spineItem == null ? void 0 : spineItem.item.renditionLayout) === `reflowable`)) return;
|
|
281
280
|
const { viewportDimensions } = (spineItem == null ? void 0 : spineItem.getViewPortInformation()) ?? {};
|
|
282
281
|
const { width: pageWidth } = reader.context.getPageSize();
|
|
283
282
|
const frameElement = (_a = spineItem == null ? void 0 : spineItem.spineItemFrame.getManipulableFrame()) == null ? void 0 : _a.frame;
|
|
@@ -426,20 +425,16 @@ const createReport = (namespace) => ({
|
|
|
426
425
|
log: (...data) => {
|
|
427
426
|
var _a;
|
|
428
427
|
if ((_a = getWindow()) == null ? void 0 : _a.__PROSE_READER_DEBUG) {
|
|
429
|
-
if (namespace)
|
|
430
|
-
|
|
431
|
-
else
|
|
432
|
-
console.log(wrap(ROOT_NAMESPACE), ...data);
|
|
428
|
+
if (namespace) console.log(wrap(ROOT_NAMESPACE), wrap(namespace), ...data);
|
|
429
|
+
else console.log(wrap(ROOT_NAMESPACE), ...data);
|
|
433
430
|
}
|
|
434
431
|
},
|
|
435
432
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
436
433
|
warn: (...data) => {
|
|
437
434
|
var _a;
|
|
438
435
|
if ((_a = getWindow()) == null ? void 0 : _a.__PROSE_READER_DEBUG) {
|
|
439
|
-
if (namespace)
|
|
440
|
-
|
|
441
|
-
else
|
|
442
|
-
console.warn(wrap(ROOT_NAMESPACE), ...data);
|
|
436
|
+
if (namespace) console.warn(wrap(ROOT_NAMESPACE), wrap(namespace), ...data);
|
|
437
|
+
else console.warn(wrap(ROOT_NAMESPACE), ...data);
|
|
443
438
|
}
|
|
444
439
|
},
|
|
445
440
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -462,8 +457,7 @@ const createReport = (namespace) => ({
|
|
|
462
457
|
logMetric: (performanceEntry, targetDuration = 0) => {
|
|
463
458
|
var _a;
|
|
464
459
|
if ((_a = getWindow()) == null ? void 0 : _a.__PROSE_READER_DEBUG) {
|
|
465
|
-
if (performanceEntry.duration <= targetDuration)
|
|
466
|
-
;
|
|
460
|
+
if (performanceEntry.duration <= targetDuration) ;
|
|
467
461
|
else {
|
|
468
462
|
console.warn(
|
|
469
463
|
`[prose-reader] [metric] `,
|
|
@@ -475,8 +469,7 @@ const createReport = (namespace) => ({
|
|
|
475
469
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
476
470
|
measurePerformance: (name, targetDuration = 10, functionToMeasure, { disable } = {}) => {
|
|
477
471
|
var _a;
|
|
478
|
-
if (disable || !((_a = getWindow()) == null ? void 0 : _a.__PROSE_READER_DEBUG))
|
|
479
|
-
return functionToMeasure;
|
|
472
|
+
if (disable || !((_a = getWindow()) == null ? void 0 : _a.__PROSE_READER_DEBUG)) return functionToMeasure;
|
|
480
473
|
return (...args) => {
|
|
481
474
|
const t0 = performance.now();
|
|
482
475
|
const response = functionToMeasure(...args);
|
|
@@ -502,8 +495,7 @@ const linksEnhancer = (next) => (options) => {
|
|
|
502
495
|
const subject = new Subject();
|
|
503
496
|
const handleNavigationForClick = (element) => {
|
|
504
497
|
var _a;
|
|
505
|
-
if (!element.href)
|
|
506
|
-
return false;
|
|
498
|
+
if (!element.href) return false;
|
|
507
499
|
const hrefUrl = new URL(element.href);
|
|
508
500
|
const hrefWithoutAnchor = `${hrefUrl.origin}${hrefUrl.pathname}`;
|
|
509
501
|
const hasExistingSpineItem = (_a = reader.context.manifest) == null ? void 0 : _a.spineItems.some((item) => item.href === hrefWithoutAnchor);
|
|
@@ -539,7 +531,9 @@ const createNavigator = (reader) => {
|
|
|
539
531
|
const goToNextSpineItem = () => {
|
|
540
532
|
var _a;
|
|
541
533
|
const focusedSpineItemIndex = reader.spineItemManager.getFocusedSpineItemIndex() || 0;
|
|
542
|
-
const { end = focusedSpineItemIndex } = reader.spine.locator.getSpineItemsFromReadingOrderPosition(
|
|
534
|
+
const { end = focusedSpineItemIndex } = reader.spine.locator.getSpineItemsFromReadingOrderPosition(
|
|
535
|
+
reader.viewportNavigator.getCurrentNavigationPosition()
|
|
536
|
+
) || {};
|
|
543
537
|
const numberOfSpineItems = ((_a = reader.context.manifest) == null ? void 0 : _a.spineItems.length) ?? 0;
|
|
544
538
|
const nextItem = end + 1;
|
|
545
539
|
if (nextItem < numberOfSpineItems) {
|
|
@@ -548,7 +542,9 @@ const createNavigator = (reader) => {
|
|
|
548
542
|
};
|
|
549
543
|
const goToPreviousSpineItem = () => {
|
|
550
544
|
const focusedSpineItemIndex = reader.spineItemManager.getFocusedSpineItemIndex() || 0;
|
|
551
|
-
const { begin = focusedSpineItemIndex } = reader.spine.locator.getSpineItemsFromReadingOrderPosition(
|
|
545
|
+
const { begin = focusedSpineItemIndex } = reader.spine.locator.getSpineItemsFromReadingOrderPosition(
|
|
546
|
+
reader.viewportNavigator.getCurrentNavigationPosition()
|
|
547
|
+
) || {};
|
|
552
548
|
const nextItem = begin - 1;
|
|
553
549
|
if (nextItem >= 0) {
|
|
554
550
|
reader.viewportNavigator.goToSpineItem(nextItem);
|
|
@@ -558,16 +554,14 @@ const createNavigator = (reader) => {
|
|
|
558
554
|
goToNextSpineItem,
|
|
559
555
|
goToPreviousSpineItem,
|
|
560
556
|
goToLeftSpineItem: () => {
|
|
561
|
-
if (reader.settings.settings.computedPageTurnDirection === "vertical")
|
|
562
|
-
return;
|
|
557
|
+
if (reader.settings.settings.computedPageTurnDirection === "vertical") return;
|
|
563
558
|
if (reader.context.isRTL()) {
|
|
564
559
|
return goToNextSpineItem();
|
|
565
560
|
}
|
|
566
561
|
return goToPreviousSpineItem();
|
|
567
562
|
},
|
|
568
563
|
goToRightSpineItem: () => {
|
|
569
|
-
if (reader.settings.settings.computedPageTurnDirection === "vertical")
|
|
570
|
-
return;
|
|
564
|
+
if (reader.settings.settings.computedPageTurnDirection === "vertical") return;
|
|
571
565
|
if (reader.context.isRTL()) {
|
|
572
566
|
return goToPreviousSpineItem();
|
|
573
567
|
}
|
|
@@ -617,8 +611,7 @@ const buildChaptersInfo = (href, tocItem, manifest) => {
|
|
|
617
611
|
if (isPossibleTocItemCandidate) {
|
|
618
612
|
const spineItemIndexOfPossibleCandidate = manifest.spineItems.findIndex((item) => item.href === tocItem2.href);
|
|
619
613
|
const spineItemIsBeforeThisTocItem = spineItemIndex < spineItemIndexOfPossibleCandidate;
|
|
620
|
-
if (spineItemIsBeforeThisTocItem)
|
|
621
|
-
return acc;
|
|
614
|
+
if (spineItemIsBeforeThisTocItem) return acc;
|
|
622
615
|
const info = {
|
|
623
616
|
title: tocItem2.title,
|
|
624
617
|
path: tocItem2.path
|
|
@@ -643,8 +636,7 @@ const buildChapterInfoFromSpineItem = (manifest, item) => {
|
|
|
643
636
|
const getChaptersInfo = (reader) => {
|
|
644
637
|
const manifest = reader.context.manifest;
|
|
645
638
|
const items = reader.spineItemManager.getAll();
|
|
646
|
-
if (!manifest)
|
|
647
|
-
return {};
|
|
639
|
+
if (!manifest) return {};
|
|
648
640
|
return items.reduce(
|
|
649
641
|
(acc, { item }) => {
|
|
650
642
|
return {
|
|
@@ -733,15 +725,13 @@ const getItemOffsetFromPageIndex = (pageWidth, pageIndex, itemWidth) => {
|
|
|
733
725
|
return Math.max(0, Math.min(lastPageOffset, logicalOffset));
|
|
734
726
|
};
|
|
735
727
|
const calculateNumberOfPagesForItem = (itemWidth, pageWidth) => {
|
|
736
|
-
if ((pageWidth || 0) === 0 || (itemWidth || 0) === 0)
|
|
737
|
-
return 1;
|
|
728
|
+
if ((pageWidth || 0) === 0 || (itemWidth || 0) === 0) return 1;
|
|
738
729
|
return Math.floor(Math.max(1, itemWidth / pageWidth));
|
|
739
730
|
};
|
|
740
731
|
const getClosestValidOffsetFromApproximateOffsetInPages = (offset, pageWidth, itemWidth) => {
|
|
741
732
|
const numberOfPages = calculateNumberOfPagesForItem(itemWidth, pageWidth);
|
|
742
733
|
const offsetValues = [...Array(numberOfPages)].map((_, i) => i * pageWidth);
|
|
743
|
-
if (offset >= numberOfPages * pageWidth)
|
|
744
|
-
return offsetValues[offsetValues.length - 1] || 0;
|
|
734
|
+
if (offset >= numberOfPages * pageWidth) return offsetValues[offsetValues.length - 1] || 0;
|
|
745
735
|
return offsetValues.find((offsetRange) => offset < offsetRange + pageWidth) || 0;
|
|
746
736
|
};
|
|
747
737
|
const getSpineItemNumberOfPages = ({ spineItem, reader }) => {
|
|
@@ -840,7 +830,10 @@ const trackPaginationInfo = (reader) => {
|
|
|
840
830
|
})),
|
|
841
831
|
distinctUntilChanged$1(isShallowEqual)
|
|
842
832
|
);
|
|
843
|
-
const paginationInfo$ = combineLatest([
|
|
833
|
+
const paginationInfo$ = combineLatest([
|
|
834
|
+
extandedBasePagination$,
|
|
835
|
+
totalPages$
|
|
836
|
+
]).pipe(
|
|
844
837
|
map(([pageInfo, totalPageInfo]) => ({
|
|
845
838
|
...pageInfo,
|
|
846
839
|
...totalPageInfo,
|
|
@@ -1093,8 +1086,7 @@ const createViewportZoomer = (reader) => {
|
|
|
1093
1086
|
const scale = (userScale) => {
|
|
1094
1087
|
const spineElement = reader.spine.getElement();
|
|
1095
1088
|
const viewportElement = reader.viewportNavigator.getElement();
|
|
1096
|
-
if (!spineElement || !viewportElement)
|
|
1097
|
-
return;
|
|
1089
|
+
if (!spineElement || !viewportElement) return;
|
|
1098
1090
|
const roundedScale = Math.ceil((userScale < 1 ? baseScale - (1 - userScale) : baseScale + (userScale - 1)) * 100) / 100;
|
|
1099
1091
|
const newScale = Math.max(roundedScale, 1);
|
|
1100
1092
|
const currentScale = spineElement.getBoundingClientRect().width / spineElement.offsetWidth;
|
|
@@ -1216,10 +1208,8 @@ const isUsingSpreadMode = ({
|
|
|
1216
1208
|
}) => {
|
|
1217
1209
|
const { height, width } = visibleAreaRect;
|
|
1218
1210
|
const isLandscape = width > height;
|
|
1219
|
-
if (forceSinglePageMode)
|
|
1220
|
-
|
|
1221
|
-
if ((manifest == null ? void 0 : manifest.renditionFlow) === `scrolled-continuous`)
|
|
1222
|
-
return false;
|
|
1211
|
+
if (forceSinglePageMode) return false;
|
|
1212
|
+
if ((manifest == null ? void 0 : manifest.renditionFlow) === `scrolled-continuous`) return false;
|
|
1223
1213
|
if (!isLandscape && (manifest == null ? void 0 : manifest.renditionSpread) === `portrait`) {
|
|
1224
1214
|
return true;
|
|
1225
1215
|
}
|
|
@@ -1381,8 +1371,7 @@ const getIntrinsicDimensionsFromBase64Img = (data) => new Promise((resolve, reje
|
|
|
1381
1371
|
image.onerror = reject;
|
|
1382
1372
|
});
|
|
1383
1373
|
const createHtmlPageFromResource = async (resourceResponse, item) => {
|
|
1384
|
-
if (typeof resourceResponse === `string`)
|
|
1385
|
-
return resourceResponse;
|
|
1374
|
+
if (typeof resourceResponse === `string`) return resourceResponse;
|
|
1386
1375
|
const contentType = parseContentType(resourceResponse.headers.get(`Content-Type`) || ``) || detectMimeTypeFromName(item.href);
|
|
1387
1376
|
if ([`image/jpg`, `image/jpeg`, `image/png`, `image/webp`].some((mime) => mime === contentType)) {
|
|
1388
1377
|
const data = await getBase64FromBlob(await resourceResponse.blob());
|
|
@@ -1496,8 +1485,7 @@ const createLoader = ({
|
|
|
1496
1485
|
}
|
|
1497
1486
|
}),
|
|
1498
1487
|
mergeMap((frame) => {
|
|
1499
|
-
if (!frame)
|
|
1500
|
-
return EMPTY;
|
|
1488
|
+
if (!frame) return EMPTY;
|
|
1501
1489
|
return fromEvent(frame, `load`).pipe(
|
|
1502
1490
|
take(1),
|
|
1503
1491
|
mergeMap(() => {
|
|
@@ -1514,10 +1502,11 @@ const createLoader = ({
|
|
|
1514
1502
|
if (settings.settings.computedPageTurnMode !== `scrollable`) {
|
|
1515
1503
|
frame.setAttribute(`tab-index`, `0`);
|
|
1516
1504
|
}
|
|
1517
|
-
|
|
1505
|
+
const hookResults = hookManager.execute(`item.onLoad`, item.id, {
|
|
1518
1506
|
itemId: item.id,
|
|
1519
1507
|
frame
|
|
1520
|
-
}).
|
|
1508
|
+
}).filter((result) => result instanceof Observable);
|
|
1509
|
+
return combineLatest([of(null), ...hookResults]).pipe(map$1(() => frame));
|
|
1521
1510
|
})
|
|
1522
1511
|
);
|
|
1523
1512
|
}),
|
|
@@ -1690,8 +1679,7 @@ const createFrameItem = ({
|
|
|
1690
1679
|
return `rtl`;
|
|
1691
1680
|
}
|
|
1692
1681
|
const direction = (_a = getComputedStyleAfterLoad()) == null ? void 0 : _a.direction;
|
|
1693
|
-
if ([`ltr`, `rtl`].includes(direction || ``))
|
|
1694
|
-
return direction;
|
|
1682
|
+
if ([`ltr`, `rtl`].includes(direction || ``)) return direction;
|
|
1695
1683
|
return void 0;
|
|
1696
1684
|
},
|
|
1697
1685
|
isUsingVerticalWriting,
|
|
@@ -1778,8 +1766,7 @@ const createSelectionTracker = () => {
|
|
|
1778
1766
|
getSelection: () => {
|
|
1779
1767
|
var _a;
|
|
1780
1768
|
const selection = (_a = frame == null ? void 0 : frame.contentWindow) == null ? void 0 : _a.getSelection();
|
|
1781
|
-
if (!(selection == null ? void 0 : selection.anchorNode) || selection.type === `None` || selection.type === `Caret`)
|
|
1782
|
-
return void 0;
|
|
1769
|
+
if (!(selection == null ? void 0 : selection.anchorNode) || selection.type === `None` || selection.type === `Caret`) return void 0;
|
|
1783
1770
|
return selection;
|
|
1784
1771
|
},
|
|
1785
1772
|
$: subject.asObservable()
|
|
@@ -2360,7 +2347,10 @@ const buildStyleForViewportFrame = () => {
|
|
|
2360
2347
|
}
|
|
2361
2348
|
`;
|
|
2362
2349
|
};
|
|
2363
|
-
const buildStyleForReflowableImageOnly = ({
|
|
2350
|
+
const buildStyleForReflowableImageOnly = ({
|
|
2351
|
+
isScrollable,
|
|
2352
|
+
enableTouch
|
|
2353
|
+
}) => {
|
|
2364
2354
|
return `
|
|
2365
2355
|
${/*
|
|
2366
2356
|
* @see https://hammerjs.github.io/touch-action/
|
|
@@ -2544,8 +2534,7 @@ function matchAll(str, regExp, add) {
|
|
|
2544
2534
|
let m;
|
|
2545
2535
|
do {
|
|
2546
2536
|
m = str.match(regExp);
|
|
2547
|
-
if (!m)
|
|
2548
|
-
break;
|
|
2537
|
+
if (!m) break;
|
|
2549
2538
|
matches.push(m.index + add);
|
|
2550
2539
|
offset += m.index + m.length;
|
|
2551
2540
|
str = str.slice(m.index + m.length);
|
|
@@ -2608,24 +2597,17 @@ function calcSiblingCount(nodes, n, offset) {
|
|
|
2608
2597
|
function compareTemporal(a, b) {
|
|
2609
2598
|
const isA = typeof a === `number`;
|
|
2610
2599
|
const isB = typeof b === `number`;
|
|
2611
|
-
if (!isA && !isB)
|
|
2612
|
-
|
|
2613
|
-
if (
|
|
2614
|
-
return -1;
|
|
2615
|
-
if (isA && !isB)
|
|
2616
|
-
return 1;
|
|
2600
|
+
if (!isA && !isB) return 0;
|
|
2601
|
+
if (!isA && isB) return -1;
|
|
2602
|
+
if (isA && !isB) return 1;
|
|
2617
2603
|
return (a || 0) - (b || 0);
|
|
2618
2604
|
}
|
|
2619
2605
|
function compareSpatial(a, b) {
|
|
2620
|
-
if (!a && !b)
|
|
2621
|
-
|
|
2622
|
-
if (
|
|
2623
|
-
return -1;
|
|
2624
|
-
if (a && !b)
|
|
2625
|
-
return 1;
|
|
2606
|
+
if (!a && !b) return 0;
|
|
2607
|
+
if (!a && b) return -1;
|
|
2608
|
+
if (a && !b) return 1;
|
|
2626
2609
|
const diff = (a.y || 0) - (b.y || 0);
|
|
2627
|
-
if (diff)
|
|
2628
|
-
return diff;
|
|
2610
|
+
if (diff) return diff;
|
|
2629
2611
|
return (a.x || 0) - (b.x || 0);
|
|
2630
2612
|
}
|
|
2631
2613
|
class CFI {
|
|
@@ -2647,20 +2629,16 @@ class CFI {
|
|
|
2647
2629
|
const isCFI = /^epubcfi\((.*)\)$/;
|
|
2648
2630
|
str = str.trim();
|
|
2649
2631
|
const m = str.match(isCFI);
|
|
2650
|
-
if (!m)
|
|
2651
|
-
|
|
2652
|
-
if (m.length < 2)
|
|
2653
|
-
return;
|
|
2632
|
+
if (!m) throw new Error(`Not a valid CFI`);
|
|
2633
|
+
if (m.length < 2) return;
|
|
2654
2634
|
str = m[1] || ``;
|
|
2655
2635
|
let parsed, offset, newDoc;
|
|
2656
2636
|
let subParts = [];
|
|
2657
2637
|
let sawComma = 0;
|
|
2658
2638
|
while (str.length) {
|
|
2659
2639
|
({ parsed, offset, newDoc } = this.parse(str));
|
|
2660
|
-
if (!parsed || offset === null)
|
|
2661
|
-
|
|
2662
|
-
if (sawComma && newDoc)
|
|
2663
|
-
throw new Error(`CFI is a range that spans multiple documents. This is not allowed`);
|
|
2640
|
+
if (!parsed || offset === null) throw new Error(`Parsing failed`);
|
|
2641
|
+
if (sawComma && newDoc) throw new Error(`CFI is a range that spans multiple documents. This is not allowed`);
|
|
2664
2642
|
subParts.push(parsed);
|
|
2665
2643
|
if (newDoc || str.length - offset <= 0) {
|
|
2666
2644
|
if (sawComma === 2) {
|
|
@@ -2704,8 +2682,7 @@ class CFI {
|
|
|
2704
2682
|
if (!parts) {
|
|
2705
2683
|
if (this.from) {
|
|
2706
2684
|
this.removeIllegalOpts(this.from);
|
|
2707
|
-
if (!this.to)
|
|
2708
|
-
return;
|
|
2685
|
+
if (!this.to) return;
|
|
2709
2686
|
parts = this.to;
|
|
2710
2687
|
} else {
|
|
2711
2688
|
parts = this.parts;
|
|
@@ -2728,8 +2705,7 @@ class CFI {
|
|
|
2728
2705
|
let o;
|
|
2729
2706
|
while (node.parentNode) {
|
|
2730
2707
|
o = calcSiblingCount(node.parentNode.childNodes, node, offset);
|
|
2731
|
-
if (!cfi && o.offset)
|
|
2732
|
-
cfi = `:` + o.offset;
|
|
2708
|
+
if (!cfi && o.offset) cfi = `:` + o.offset;
|
|
2733
2709
|
cfi = `/` + o.count + (node.id ? `[` + cfiEscape(node.id) + `]` : ``) + cfi;
|
|
2734
2710
|
node = node.parentNode;
|
|
2735
2711
|
}
|
|
@@ -2746,8 +2722,7 @@ class CFI {
|
|
|
2746
2722
|
} else {
|
|
2747
2723
|
cfi = this.generatePart(node, offset, extra);
|
|
2748
2724
|
}
|
|
2749
|
-
if (extra)
|
|
2750
|
-
cfi += extra;
|
|
2725
|
+
if (extra) cfi += extra;
|
|
2751
2726
|
return `epubcfi(` + cfi + `)`;
|
|
2752
2727
|
}
|
|
2753
2728
|
static toParsed(cfi) {
|
|
@@ -2764,13 +2739,10 @@ class CFI {
|
|
|
2764
2739
|
for (i = 0; i < max; i++) {
|
|
2765
2740
|
cA = a[i];
|
|
2766
2741
|
cB = b[i];
|
|
2767
|
-
if (!cA)
|
|
2768
|
-
|
|
2769
|
-
if (!cB)
|
|
2770
|
-
return 1;
|
|
2742
|
+
if (!cA) return -1;
|
|
2743
|
+
if (!cB) return 1;
|
|
2771
2744
|
diff = this.compareParts(cA, cB);
|
|
2772
|
-
if (diff)
|
|
2773
|
-
return diff;
|
|
2745
|
+
if (diff) return diff;
|
|
2774
2746
|
}
|
|
2775
2747
|
return 0;
|
|
2776
2748
|
}
|
|
@@ -2787,14 +2759,11 @@ class CFI {
|
|
|
2787
2759
|
if (a.isRange || b.isRange) {
|
|
2788
2760
|
if (a.isRange && b.isRange) {
|
|
2789
2761
|
const diff = this.comparePath(oA.from, oB.from);
|
|
2790
|
-
if (diff)
|
|
2791
|
-
return diff;
|
|
2762
|
+
if (diff) return diff;
|
|
2792
2763
|
return this.comparePath(oA.to, oB.to);
|
|
2793
2764
|
}
|
|
2794
|
-
if (a.isRange)
|
|
2795
|
-
|
|
2796
|
-
if (b.isRange)
|
|
2797
|
-
oB = oB.from;
|
|
2765
|
+
if (a.isRange) oA = oA.from;
|
|
2766
|
+
if (b.isRange) oB = oB.from;
|
|
2798
2767
|
return this.comparePath(oA, oB);
|
|
2799
2768
|
} else {
|
|
2800
2769
|
return this.comparePath(oA, oB);
|
|
@@ -2807,29 +2776,22 @@ class CFI {
|
|
|
2807
2776
|
for (i = 0; i < max; i++) {
|
|
2808
2777
|
cA = a[i];
|
|
2809
2778
|
cB = b[i];
|
|
2810
|
-
if (!cA)
|
|
2811
|
-
|
|
2812
|
-
if (!cB)
|
|
2813
|
-
return 1;
|
|
2779
|
+
if (!cA) return -1;
|
|
2780
|
+
if (!cB) return 1;
|
|
2814
2781
|
diff = cA.nodeIndex - cB.nodeIndex;
|
|
2815
|
-
if (diff)
|
|
2816
|
-
return diff;
|
|
2782
|
+
if (diff) return diff;
|
|
2817
2783
|
if (cA.nodeIndex === 0) {
|
|
2818
2784
|
return 0;
|
|
2819
2785
|
}
|
|
2820
|
-
if (i < max - 1)
|
|
2821
|
-
continue;
|
|
2786
|
+
if (i < max - 1) continue;
|
|
2822
2787
|
if (cA.nodeIndex % 2 === 0) {
|
|
2823
2788
|
diff = compareTemporal(cA.temporal, cB.temporal);
|
|
2824
|
-
if (diff)
|
|
2825
|
-
return diff;
|
|
2789
|
+
if (diff) return diff;
|
|
2826
2790
|
diff = compareSpatial(cA.spatial, cB.spatial);
|
|
2827
|
-
if (diff)
|
|
2828
|
-
return diff;
|
|
2791
|
+
if (diff) return diff;
|
|
2829
2792
|
}
|
|
2830
2793
|
diff = (cA.offset || 0) - (cB.offset || 0);
|
|
2831
|
-
if (diff)
|
|
2832
|
-
return diff;
|
|
2794
|
+
if (diff) return diff;
|
|
2833
2795
|
}
|
|
2834
2796
|
return 0;
|
|
2835
2797
|
}
|
|
@@ -2847,8 +2809,7 @@ class CFI {
|
|
|
2847
2809
|
return this.decodeEntities(dom, str).length;
|
|
2848
2810
|
}
|
|
2849
2811
|
getFrom() {
|
|
2850
|
-
if (!this.isRange)
|
|
2851
|
-
throw new Error(`Trying to get beginning of non-range CFI`);
|
|
2812
|
+
if (!this.isRange) throw new Error(`Trying to get beginning of non-range CFI`);
|
|
2852
2813
|
if (!this.from) {
|
|
2853
2814
|
return this.deepClone(this.parts);
|
|
2854
2815
|
}
|
|
@@ -2857,8 +2818,7 @@ class CFI {
|
|
|
2857
2818
|
return parts;
|
|
2858
2819
|
}
|
|
2859
2820
|
getTo() {
|
|
2860
|
-
if (!this.isRange)
|
|
2861
|
-
throw new Error(`Trying to get end of non-range CFI`);
|
|
2821
|
+
if (!this.isRange) throw new Error(`Trying to get end of non-range CFI`);
|
|
2862
2822
|
const parts = this.deepClone(this.parts);
|
|
2863
2823
|
parts[parts.length - 1] = parts[parts.length - 1].concat(this.to);
|
|
2864
2824
|
return parts;
|
|
@@ -2874,8 +2834,7 @@ class CFI {
|
|
|
2874
2834
|
return this.deepClone(this.parts);
|
|
2875
2835
|
}
|
|
2876
2836
|
parseSideBias(o, loc) {
|
|
2877
|
-
if (!loc)
|
|
2878
|
-
return;
|
|
2837
|
+
if (!loc) return;
|
|
2879
2838
|
const m = loc.trim().match(/^(.*);s=([ba])$/);
|
|
2880
2839
|
if (!m || m.length < 3) {
|
|
2881
2840
|
if (typeof o.textLocationAssertion === `object`) {
|
|
@@ -2899,11 +2858,9 @@ class CFI {
|
|
|
2899
2858
|
}
|
|
2900
2859
|
}
|
|
2901
2860
|
parseSpatialRange(range) {
|
|
2902
|
-
if (!range)
|
|
2903
|
-
return void 0;
|
|
2861
|
+
if (!range) return void 0;
|
|
2904
2862
|
const m = range.trim().match(/^([\d\.]+):([\d\.]+)$/);
|
|
2905
|
-
if (!m || m.length < 3)
|
|
2906
|
-
return void 0;
|
|
2863
|
+
if (!m || m.length < 3) return void 0;
|
|
2907
2864
|
const o = {
|
|
2908
2865
|
x: parseInt(m[1]),
|
|
2909
2866
|
y: parseInt(m[2])
|
|
@@ -2993,8 +2950,7 @@ class CFI {
|
|
|
2993
2950
|
} else {
|
|
2994
2951
|
prevState = state;
|
|
2995
2952
|
state = null;
|
|
2996
|
-
if (f && seenColon)
|
|
2997
|
-
o.spatial = this.parseSpatialRange(f);
|
|
2953
|
+
if (f && seenColon) o.spatial = this.parseSpatialRange(f);
|
|
2998
2954
|
f = null;
|
|
2999
2955
|
}
|
|
3000
2956
|
}
|
|
@@ -3104,8 +3060,7 @@ class CFI {
|
|
|
3104
3060
|
}
|
|
3105
3061
|
escape = false;
|
|
3106
3062
|
}
|
|
3107
|
-
if (!o.nodeIndex && o.nodeIndex !== 0)
|
|
3108
|
-
throw new Error(`Missing child node index in CFI`);
|
|
3063
|
+
if (!o.nodeIndex && o.nodeIndex !== 0) throw new Error(`Missing child node index in CFI`);
|
|
3109
3064
|
return { parsed: o, offset: i, newDoc: state === `!` };
|
|
3110
3065
|
}
|
|
3111
3066
|
// The CFI counts child nodes differently from the DOM
|
|
@@ -3113,8 +3068,7 @@ class CFI {
|
|
|
3113
3068
|
// according to the CFI standard way of counting
|
|
3114
3069
|
getChildNodeByCFIIndex(dom, parentNode, index, offset) {
|
|
3115
3070
|
const children = parentNode.childNodes;
|
|
3116
|
-
if (!children.length)
|
|
3117
|
-
return { node: parentNode, offset: 0 };
|
|
3071
|
+
if (!children.length) return { node: parentNode, offset: 0 };
|
|
3118
3072
|
if (index <= 0) {
|
|
3119
3073
|
return { node: children[0], relativeToNode: `before`, offset: 0 };
|
|
3120
3074
|
}
|
|
@@ -3182,8 +3136,7 @@ class CFI {
|
|
|
3182
3136
|
}
|
|
3183
3137
|
}
|
|
3184
3138
|
isTextNode(node) {
|
|
3185
|
-
if (!node)
|
|
3186
|
-
return false;
|
|
3139
|
+
if (!node) return false;
|
|
3187
3140
|
if (node.nodeType === TEXT_NODE || node.nodeType === CDATA_SECTION_NODE) {
|
|
3188
3141
|
return true;
|
|
3189
3142
|
}
|
|
@@ -3215,15 +3168,13 @@ class CFI {
|
|
|
3215
3168
|
str = this.decodeEntities(dom, curNode.textContent);
|
|
3216
3169
|
nodeLengths[i] = str.length;
|
|
3217
3170
|
txt += str;
|
|
3218
|
-
if (!curNode.nextSibling)
|
|
3219
|
-
break;
|
|
3171
|
+
if (!curNode.nextSibling) break;
|
|
3220
3172
|
curNode = curNode.nextSibling;
|
|
3221
3173
|
i++;
|
|
3222
3174
|
}
|
|
3223
3175
|
const matchOffset = assertion.pre ? assertion.pre.length : 0;
|
|
3224
3176
|
const m = matchAll(txt, new RegExp(matchStr), matchOffset);
|
|
3225
|
-
if (!m.length)
|
|
3226
|
-
return { node, offset };
|
|
3177
|
+
if (!m.length) return { node, offset };
|
|
3227
3178
|
let newOffset = closest(m, offset);
|
|
3228
3179
|
if (curNode === node && newOffset === offset) {
|
|
3229
3180
|
return { node, offset };
|
|
@@ -3232,11 +3183,9 @@ class CFI {
|
|
|
3232
3183
|
curNode = startNode;
|
|
3233
3184
|
while (newOffset >= nodeLengths[i]) {
|
|
3234
3185
|
newOffset -= nodeLengths[i];
|
|
3235
|
-
if (newOffset < 0)
|
|
3236
|
-
return { node, offset };
|
|
3186
|
+
if (newOffset < 0) return { node, offset };
|
|
3237
3187
|
const nodeOffsets = [];
|
|
3238
|
-
if (!curNode.nextSibling || i + 1 >= nodeOffsets.length)
|
|
3239
|
-
return { node, offset };
|
|
3188
|
+
if (!curNode.nextSibling || i + 1 >= nodeOffsets.length) return { node, offset };
|
|
3240
3189
|
i++;
|
|
3241
3190
|
curNode = curNode.nextSibling;
|
|
3242
3191
|
}
|
|
@@ -3244,8 +3193,7 @@ class CFI {
|
|
|
3244
3193
|
}
|
|
3245
3194
|
resolveNode(index, subparts, dom, opts) {
|
|
3246
3195
|
opts = Object.assign({}, opts || {});
|
|
3247
|
-
if (!dom)
|
|
3248
|
-
throw new Error(`Missing DOM argument`);
|
|
3196
|
+
if (!dom) throw new Error(`Missing DOM argument`);
|
|
3249
3197
|
let startNode;
|
|
3250
3198
|
if (index === 0) {
|
|
3251
3199
|
startNode = dom.querySelector(`package`);
|
|
@@ -3259,8 +3207,7 @@ class CFI {
|
|
|
3259
3207
|
}
|
|
3260
3208
|
}
|
|
3261
3209
|
startNode = dom;
|
|
3262
|
-
if (!startNode)
|
|
3263
|
-
throw new Error(`Document incompatible with CFIs`);
|
|
3210
|
+
if (!startNode) throw new Error(`Document incompatible with CFIs`);
|
|
3264
3211
|
let node = startNode;
|
|
3265
3212
|
let startFrom = 0;
|
|
3266
3213
|
let i;
|
|
@@ -3302,40 +3249,33 @@ class CFI {
|
|
|
3302
3249
|
throw new Error(`index is out of bounds`);
|
|
3303
3250
|
}
|
|
3304
3251
|
const subparts = this.parts[index];
|
|
3305
|
-
if (!subparts)
|
|
3306
|
-
throw new Error(`Missing CFI part for index: ` + index);
|
|
3252
|
+
if (!subparts) throw new Error(`Missing CFI part for index: ` + index);
|
|
3307
3253
|
const o = this.resolveNode(index, subparts, dom, opts);
|
|
3308
3254
|
let node = o.node;
|
|
3309
3255
|
const tagName = node.tagName.toLowerCase();
|
|
3310
3256
|
if (tagName === `itemref` && // @ts-ignore
|
|
3311
3257
|
node.parentNode.tagName.toLowerCase() === `spine`) {
|
|
3312
3258
|
const idref = node.getAttribute(`idref`);
|
|
3313
|
-
if (!idref)
|
|
3314
|
-
throw new Error(`Referenced node had not 'idref' attribute`);
|
|
3259
|
+
if (!idref) throw new Error(`Referenced node had not 'idref' attribute`);
|
|
3315
3260
|
node = dom.getElementById(idref);
|
|
3316
|
-
if (!node)
|
|
3317
|
-
throw new Error(`Specified node is missing from manifest`);
|
|
3261
|
+
if (!node) throw new Error(`Specified node is missing from manifest`);
|
|
3318
3262
|
const href = node.getAttribute(`href`);
|
|
3319
|
-
if (!href)
|
|
3320
|
-
throw new Error(`Manifest item is missing href attribute`);
|
|
3263
|
+
if (!href) throw new Error(`Manifest item is missing href attribute`);
|
|
3321
3264
|
return href;
|
|
3322
3265
|
}
|
|
3323
3266
|
if (tagName === `iframe` || tagName === `embed`) {
|
|
3324
3267
|
const src = node.getAttribute(`src`);
|
|
3325
|
-
if (!src)
|
|
3326
|
-
throw new Error(tagName + ` element is missing 'src' attribute`);
|
|
3268
|
+
if (!src) throw new Error(tagName + ` element is missing 'src' attribute`);
|
|
3327
3269
|
return src;
|
|
3328
3270
|
}
|
|
3329
3271
|
if (tagName === `object`) {
|
|
3330
3272
|
const data = node.getAttribute(`data`);
|
|
3331
|
-
if (!data)
|
|
3332
|
-
throw new Error(tagName + ` element is missing 'data' attribute`);
|
|
3273
|
+
if (!data) throw new Error(tagName + ` element is missing 'data' attribute`);
|
|
3333
3274
|
return data;
|
|
3334
3275
|
}
|
|
3335
3276
|
if (tagName === `image` || tagName === `use`) {
|
|
3336
3277
|
const href = node.getAttribute(`xlink:href`);
|
|
3337
|
-
if (!href)
|
|
3338
|
-
throw new Error(tagName + ` element is missing 'xlink:href' attribute`);
|
|
3278
|
+
if (!href) throw new Error(tagName + ` element is missing 'xlink:href' attribute`);
|
|
3339
3279
|
return href;
|
|
3340
3280
|
}
|
|
3341
3281
|
throw new Error(`No URI found`);
|
|
@@ -3346,13 +3286,11 @@ class CFI {
|
|
|
3346
3286
|
resolveLocation(dom, parts) {
|
|
3347
3287
|
const index = parts.length - 1;
|
|
3348
3288
|
const subparts = parts[index];
|
|
3349
|
-
if (!subparts)
|
|
3350
|
-
throw new Error(`Missing CFI part for index: ` + index);
|
|
3289
|
+
if (!subparts) throw new Error(`Missing CFI part for index: ` + index);
|
|
3351
3290
|
const o = this.resolveNode(index, subparts, dom);
|
|
3352
3291
|
const lastPart = this.deepClone(subparts[subparts.length - 1]);
|
|
3353
3292
|
delete lastPart.nodeIndex;
|
|
3354
|
-
if (!lastPart.offset)
|
|
3355
|
-
delete o.offset;
|
|
3293
|
+
if (!lastPart.offset) delete o.offset;
|
|
3356
3294
|
return { ...lastPart, ...o };
|
|
3357
3295
|
}
|
|
3358
3296
|
// Takes the Document or XMLDocument for the final
|
|
@@ -3416,12 +3354,20 @@ const createSelection = (selection, item) => {
|
|
|
3416
3354
|
toString: () => text,
|
|
3417
3355
|
getAnchorCfi: () => {
|
|
3418
3356
|
if (selection.anchorNode) {
|
|
3419
|
-
return CFI.generate(
|
|
3357
|
+
return CFI.generate(
|
|
3358
|
+
selection.anchorNode,
|
|
3359
|
+
selection.anchorOffset,
|
|
3360
|
+
`|[prose~anchor~${encodeURIComponent(item.id)}]`
|
|
3361
|
+
);
|
|
3420
3362
|
}
|
|
3421
3363
|
},
|
|
3422
3364
|
getFocusCfi: () => {
|
|
3423
3365
|
if (selection.focusNode) {
|
|
3424
|
-
return CFI.generate(
|
|
3366
|
+
return CFI.generate(
|
|
3367
|
+
selection.focusNode,
|
|
3368
|
+
selection.focusOffset,
|
|
3369
|
+
`|[prose~anchor~${encodeURIComponent(item.id)}]`
|
|
3370
|
+
);
|
|
3425
3371
|
}
|
|
3426
3372
|
}
|
|
3427
3373
|
};
|
|
@@ -3595,7 +3541,10 @@ const createSpine = ({
|
|
|
3595
3541
|
beginSpineItem
|
|
3596
3542
|
);
|
|
3597
3543
|
const beginPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(beginPosition, beginSpineItem);
|
|
3598
|
-
const endPosition = spineLocator.getSpineItemPositionFromSpinePosition(
|
|
3544
|
+
const endPosition = spineLocator.getSpineItemPositionFromSpinePosition(
|
|
3545
|
+
spineItemsFromPosition.endPosition,
|
|
3546
|
+
endSpineItem
|
|
3547
|
+
);
|
|
3599
3548
|
const endPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(endPosition, endSpineItem);
|
|
3600
3549
|
const endItemIndex = spineItemManager.getSpineItemIndex(endSpineItem) ?? 0;
|
|
3601
3550
|
pagination.updateBeginAndEnd(
|
|
@@ -3678,8 +3627,7 @@ const createSpine = ({
|
|
|
3678
3627
|
map$1(([, currentNavigationPosition]) => {
|
|
3679
3628
|
const focusedSpineItemIndex = spineItemManager.getFocusedSpineItemIndex();
|
|
3680
3629
|
report.log(`update contents`, { focusedSpineItemIndex });
|
|
3681
|
-
if (focusedSpineItemIndex === void 0)
|
|
3682
|
-
return;
|
|
3630
|
+
if (focusedSpineItemIndex === void 0) return;
|
|
3683
3631
|
const { begin = focusedSpineItemIndex, end = focusedSpineItemIndex } = spineLocator.getSpineItemsFromReadingOrderPosition(currentNavigationPosition) || {};
|
|
3684
3632
|
if (begin !== focusedSpineItemIndex && end !== focusedSpineItemIndex) {
|
|
3685
3633
|
Report.warn(`Current viewport is not in sync with focus item, load from focus item rather than viewport`);
|
|
@@ -3815,7 +3763,9 @@ const createSpineItemManager = ({ context, settings }) => {
|
|
|
3815
3763
|
verticalOffset: newEdgeY
|
|
3816
3764
|
};
|
|
3817
3765
|
}
|
|
3818
|
-
item.adjustPositionOfElement(
|
|
3766
|
+
item.adjustPositionOfElement(
|
|
3767
|
+
context.isRTL() ? { right: horizontalOffset, top: 0 } : { left: horizontalOffset, top: 0 }
|
|
3768
|
+
);
|
|
3819
3769
|
newItemLayoutInformation.push({
|
|
3820
3770
|
...context.isRTL() ? {
|
|
3821
3771
|
left: context.state.visibleAreaRect.width - horizontalOffset - width,
|
|
@@ -3836,18 +3786,18 @@ const createSpineItemManager = ({ context, settings }) => {
|
|
|
3836
3786
|
},
|
|
3837
3787
|
{ horizontalOffset: 0, verticalOffset: 0 }
|
|
3838
3788
|
);
|
|
3839
|
-
const hasLayoutChanges = itemLayoutInformation.some(
|
|
3789
|
+
const hasLayoutChanges = itemLayoutInformation.some(
|
|
3790
|
+
(old, index) => !isShallowEqual(old, newItemLayoutInformation[index])
|
|
3791
|
+
);
|
|
3840
3792
|
itemLayoutInformation = newItemLayoutInformation;
|
|
3841
3793
|
Report.log(NAMESPACE$4, `layout`, { hasLayoutChanges, itemLayoutInformation });
|
|
3842
3794
|
layout$.next(hasLayoutChanges);
|
|
3843
3795
|
};
|
|
3844
3796
|
const focus = (indexOrSpineItem) => {
|
|
3845
3797
|
const spineItemToFocus = typeof indexOrSpineItem === `number` ? get(indexOrSpineItem) : indexOrSpineItem;
|
|
3846
|
-
if (!spineItemToFocus)
|
|
3847
|
-
return;
|
|
3798
|
+
if (!spineItemToFocus) return;
|
|
3848
3799
|
const newActiveSpineItemIndex = orderedSpineItemsSubject$.value.indexOf(spineItemToFocus);
|
|
3849
|
-
if (newActiveSpineItemIndex === focusedSpineItemIndex)
|
|
3850
|
-
return;
|
|
3800
|
+
if (newActiveSpineItemIndex === focusedSpineItemIndex) return;
|
|
3851
3801
|
focusedSpineItemIndex = newActiveSpineItemIndex;
|
|
3852
3802
|
focus$.next({ data: spineItemToFocus });
|
|
3853
3803
|
};
|
|
@@ -3897,8 +3847,7 @@ const createSpineItemManager = ({ context, settings }) => {
|
|
|
3897
3847
|
return `before`;
|
|
3898
3848
|
};
|
|
3899
3849
|
const getSpineItemIndex = (spineItem) => {
|
|
3900
|
-
if (!spineItem)
|
|
3901
|
-
return void 0;
|
|
3850
|
+
if (!spineItem) return void 0;
|
|
3902
3851
|
const index = orderedSpineItemsSubject$.value.indexOf(spineItem);
|
|
3903
3852
|
return index < 0 ? void 0 : index;
|
|
3904
3853
|
};
|
|
@@ -3959,13 +3908,27 @@ const createSpineItemManager = ({ context, settings }) => {
|
|
|
3959
3908
|
layout$: layout$.asObservable(),
|
|
3960
3909
|
itemIsReady$: orderedSpineItemsSubject$.asObservable().pipe(
|
|
3961
3910
|
switchMap$1((items) => {
|
|
3962
|
-
const itemsIsReady$ = items.map(
|
|
3911
|
+
const itemsIsReady$ = items.map(
|
|
3912
|
+
(item) => item.$.isReady$.pipe(map$1((isReady) => ({ item: item.item, isReady })))
|
|
3913
|
+
);
|
|
3963
3914
|
return merge(...itemsIsReady$);
|
|
3964
3915
|
})
|
|
3965
3916
|
)
|
|
3966
3917
|
}
|
|
3967
3918
|
};
|
|
3968
3919
|
};
|
|
3920
|
+
const pointerEvents$1 = [
|
|
3921
|
+
`pointercancel`,
|
|
3922
|
+
`pointerdown`,
|
|
3923
|
+
`pointerenter`,
|
|
3924
|
+
`pointerleave`,
|
|
3925
|
+
`pointermove`,
|
|
3926
|
+
`pointerout`,
|
|
3927
|
+
`pointerover`,
|
|
3928
|
+
`pointerup`
|
|
3929
|
+
// `touchstart` as const,
|
|
3930
|
+
// `touchend` as const,
|
|
3931
|
+
];
|
|
3969
3932
|
const isHtmlElement = (element) => {
|
|
3970
3933
|
return typeof element === `object` && !!element && `nodeType` in element && (element == null ? void 0 : element.nodeType) === Node.ELEMENT_NODE && `innerText` in element;
|
|
3971
3934
|
};
|
|
@@ -3992,7 +3955,11 @@ const getFirstVisibleNodeForViewport = Report.measurePerformance(
|
|
|
3992
3955
|
const visibleRect = getFirstVisibleDOMRect(rects, viewport);
|
|
3993
3956
|
if (visibleRect) {
|
|
3994
3957
|
lastValidRange = range.cloneRange();
|
|
3995
|
-
const rangeOrCaret = createRangeOrCaretFromPoint(
|
|
3958
|
+
const rangeOrCaret = createRangeOrCaretFromPoint(
|
|
3959
|
+
ownerDocument,
|
|
3960
|
+
Math.ceil(visibleRect.left),
|
|
3961
|
+
Math.ceil(visibleRect.top)
|
|
3962
|
+
);
|
|
3996
3963
|
if (rangeOrCaret && `startContainer` in rangeOrCaret && rangeOrCaret.startContainer === lastValidRange.startContainer) {
|
|
3997
3964
|
lastValidOffset = rangeOrCaret.startOffset;
|
|
3998
3965
|
}
|
|
@@ -4028,14 +3995,10 @@ const getFirstVisibleElementForViewport = (element, viewport) => {
|
|
|
4028
3995
|
return lastValidElement;
|
|
4029
3996
|
};
|
|
4030
3997
|
function getElementOrNodePositionFromViewPort(domRect, { left, right }) {
|
|
4031
|
-
if (domRect.left <= left && domRect.right <= left)
|
|
4032
|
-
|
|
4033
|
-
if (domRect.left <=
|
|
4034
|
-
|
|
4035
|
-
if (domRect.left <= right && domRect.right > right)
|
|
4036
|
-
return `partially-after`;
|
|
4037
|
-
if (domRect.left > right)
|
|
4038
|
-
return `after`;
|
|
3998
|
+
if (domRect.left <= left && domRect.right <= left) return `before`;
|
|
3999
|
+
if (domRect.left <= left && domRect.right > left && domRect.right <= right) return `partially-before`;
|
|
4000
|
+
if (domRect.left <= right && domRect.right > right) return `partially-after`;
|
|
4001
|
+
if (domRect.left > right) return `after`;
|
|
4039
4002
|
return `within`;
|
|
4040
4003
|
}
|
|
4041
4004
|
function getFirstVisibleDOMRect(domRect, viewport) {
|
|
@@ -4067,22 +4030,24 @@ const isPointerEvent = (event) => {
|
|
|
4067
4030
|
var _a, _b, _c, _d, _e;
|
|
4068
4031
|
if ((event == null ? void 0 : event.target) && ((_b = (_a = event == null ? void 0 : event.target) == null ? void 0 : _a.ownerDocument) == null ? void 0 : _b.defaultView)) {
|
|
4069
4032
|
const eventView = (_d = (_c = event == null ? void 0 : event.target) == null ? void 0 : _c.ownerDocument) == null ? void 0 : _d.defaultView;
|
|
4070
|
-
if (eventView.PointerEvent) {
|
|
4071
|
-
return
|
|
4033
|
+
if (eventView.PointerEvent && event instanceof eventView.PointerEvent) {
|
|
4034
|
+
return true;
|
|
4072
4035
|
}
|
|
4073
4036
|
}
|
|
4074
4037
|
if ((event == null ? void 0 : event.view) && ((_e = event == null ? void 0 : event.view) == null ? void 0 : _e.window)) {
|
|
4075
4038
|
const eventView = event == null ? void 0 : event.view;
|
|
4076
|
-
if (eventView.PointerEvent) {
|
|
4077
|
-
return
|
|
4039
|
+
if (eventView.PointerEvent && event instanceof eventView.PointerEvent) {
|
|
4040
|
+
return true;
|
|
4078
4041
|
}
|
|
4079
4042
|
}
|
|
4043
|
+
if (pointerEvents$1.includes(event.type)) {
|
|
4044
|
+
return true;
|
|
4045
|
+
}
|
|
4080
4046
|
return false;
|
|
4081
4047
|
};
|
|
4082
4048
|
const isMouseEvent = (event) => {
|
|
4083
4049
|
var _a, _b, _c, _d, _e;
|
|
4084
|
-
if (isPointerEvent(event))
|
|
4085
|
-
return false;
|
|
4050
|
+
if (isPointerEvent(event)) return false;
|
|
4086
4051
|
if ((event == null ? void 0 : event.target) && ((_b = (_a = event == null ? void 0 : event.target) == null ? void 0 : _a.ownerDocument) == null ? void 0 : _b.defaultView)) {
|
|
4087
4052
|
const eventView = (_d = (_c = event == null ? void 0 : event.target) == null ? void 0 : _c.ownerDocument) == null ? void 0 : _d.defaultView;
|
|
4088
4053
|
if (eventView.MouseEvent) {
|
|
@@ -4211,10 +4176,8 @@ const createLocationResolver$1 = ({ context }) => {
|
|
|
4211
4176
|
};
|
|
4212
4177
|
const getPageFromOffset = (offset, pageWidth, numberOfPages) => {
|
|
4213
4178
|
const offsetValues = [...Array(numberOfPages)].map((_, i) => i * pageWidth);
|
|
4214
|
-
if (offset <= 0)
|
|
4215
|
-
|
|
4216
|
-
if (offset >= numberOfPages * pageWidth)
|
|
4217
|
-
return numberOfPages - 1;
|
|
4179
|
+
if (offset <= 0) return 0;
|
|
4180
|
+
if (offset >= numberOfPages * pageWidth) return numberOfPages - 1;
|
|
4218
4181
|
return Math.max(
|
|
4219
4182
|
0,
|
|
4220
4183
|
offsetValues.findIndex((offsetRange) => offset < offsetRange + pageWidth)
|
|
@@ -4250,7 +4213,10 @@ const createNavigationResolver$1 = ({ context }) => {
|
|
|
4250
4213
|
y: position.y + context.getPageSize().height
|
|
4251
4214
|
};
|
|
4252
4215
|
}
|
|
4253
|
-
const navigationPosition = spineItemLocator.getSpineItemClosestPositionFromUnsafePosition(
|
|
4216
|
+
const navigationPosition = spineItemLocator.getSpineItemClosestPositionFromUnsafePosition(
|
|
4217
|
+
nextPotentialPosition,
|
|
4218
|
+
spineItem
|
|
4219
|
+
);
|
|
4254
4220
|
return new SpineItemNavigationPosition(navigationPosition);
|
|
4255
4221
|
};
|
|
4256
4222
|
const getNavigationForRightPage = (position, spineItem) => {
|
|
@@ -4264,7 +4230,10 @@ const createNavigationResolver$1 = ({ context }) => {
|
|
|
4264
4230
|
y: position.y - context.getPageSize().height
|
|
4265
4231
|
};
|
|
4266
4232
|
}
|
|
4267
|
-
const navigationPosition = spineItemLocator.getSpineItemClosestPositionFromUnsafePosition(
|
|
4233
|
+
const navigationPosition = spineItemLocator.getSpineItemClosestPositionFromUnsafePosition(
|
|
4234
|
+
nextPotentialPosition,
|
|
4235
|
+
spineItem
|
|
4236
|
+
);
|
|
4268
4237
|
return new SpineItemNavigationPosition(navigationPosition);
|
|
4269
4238
|
};
|
|
4270
4239
|
const getNavigationForLastPage = (spineItem) => {
|
|
@@ -4287,7 +4256,10 @@ const createNavigationResolver$1 = ({ context }) => {
|
|
|
4287
4256
|
return new SpineItemNavigationPosition(position || { x: 0, y: 0 });
|
|
4288
4257
|
};
|
|
4289
4258
|
const getNavigationForPosition = (spineItem, position) => {
|
|
4290
|
-
const potentiallyCorrectedPosition = spineItemLocator.getSpineItemClosestPositionFromUnsafePosition(
|
|
4259
|
+
const potentiallyCorrectedPosition = spineItemLocator.getSpineItemClosestPositionFromUnsafePosition(
|
|
4260
|
+
position,
|
|
4261
|
+
spineItem
|
|
4262
|
+
);
|
|
4291
4263
|
return new SpineItemNavigationPosition(potentiallyCorrectedPosition);
|
|
4292
4264
|
};
|
|
4293
4265
|
return {
|
|
@@ -4386,7 +4358,10 @@ const createNavigationResolver = ({
|
|
|
4386
4358
|
pageTurnDirection === `horizontal` ? { x: position.x + context.getPageSize().width, y: 0 } : { y: position.y + context.getPageSize().height, x: 0 }
|
|
4387
4359
|
);
|
|
4388
4360
|
} else {
|
|
4389
|
-
const readingOrderPosition = locator.getSpinePositionFromSpineItemPosition(
|
|
4361
|
+
const readingOrderPosition = locator.getSpinePositionFromSpineItemPosition(
|
|
4362
|
+
spineItemNavigationForRightPage,
|
|
4363
|
+
spineItem
|
|
4364
|
+
);
|
|
4390
4365
|
return readingOrderPosition;
|
|
4391
4366
|
}
|
|
4392
4367
|
};
|
|
@@ -4566,8 +4541,7 @@ const createScrollViewportNavigator = ({
|
|
|
4566
4541
|
const getScaledDownPosition = ({ x, y }) => {
|
|
4567
4542
|
var _a, _b;
|
|
4568
4543
|
const spineElement = spine.getElement();
|
|
4569
|
-
if (!spineElement)
|
|
4570
|
-
throw new Error("Invalid spine element");
|
|
4544
|
+
if (!spineElement) throw new Error("Invalid spine element");
|
|
4571
4545
|
const spineScaleX = spineElement.getBoundingClientRect().width / spineElement.offsetWidth;
|
|
4572
4546
|
const scaledDownPosition = {
|
|
4573
4547
|
x: getNewScaledOffset({
|
|
@@ -4722,13 +4696,15 @@ const createManualViewportNavigator = ({
|
|
|
4722
4696
|
10,
|
|
4723
4697
|
(navigation, { allowSpineItemChange = true } = {}) => {
|
|
4724
4698
|
const currentSpineItem = spineItemManager.getFocusedSpineItem();
|
|
4725
|
-
if (!currentSpineItem)
|
|
4726
|
-
return EMPTY;
|
|
4699
|
+
if (!currentSpineItem) return EMPTY;
|
|
4727
4700
|
const newSpineItem = locator.getSpineItemFromPosition(navigation) || currentSpineItem;
|
|
4728
4701
|
const spineItemHasChanged = newSpineItem !== currentSpineItem;
|
|
4729
4702
|
if (spineItemHasChanged) {
|
|
4730
4703
|
if (allowSpineItemChange) {
|
|
4731
|
-
const positionOfNewSpineItemComparedToCurrentOne = spineItemManager.comparePositionOf(
|
|
4704
|
+
const positionOfNewSpineItemComparedToCurrentOne = spineItemManager.comparePositionOf(
|
|
4705
|
+
newSpineItem,
|
|
4706
|
+
currentSpineItem
|
|
4707
|
+
);
|
|
4732
4708
|
if (positionOfNewSpineItemComparedToCurrentOne === `before`) {
|
|
4733
4709
|
return of({
|
|
4734
4710
|
...navigation,
|
|
@@ -4882,8 +4858,7 @@ const createPanViewportNavigator = ({
|
|
|
4882
4858
|
10,
|
|
4883
4859
|
(navigation, { allowSpineItemChange = true } = {}) => {
|
|
4884
4860
|
const currentSpineItem = spineItemManager.getFocusedSpineItem();
|
|
4885
|
-
if (!currentSpineItem)
|
|
4886
|
-
return void 0;
|
|
4861
|
+
if (!currentSpineItem) return void 0;
|
|
4887
4862
|
const newSpineItem = locator.getSpineItemFromPosition(navigation) || currentSpineItem;
|
|
4888
4863
|
const spineItemHasChanged = newSpineItem !== currentSpineItem;
|
|
4889
4864
|
if (spineItemHasChanged) {
|
|
@@ -5024,8 +4999,7 @@ const createViewportNavigator = ({
|
|
|
5024
4999
|
2,
|
|
5025
5000
|
({ x, y }) => {
|
|
5026
5001
|
const element = element$.getValue();
|
|
5027
|
-
if (!element)
|
|
5028
|
-
throw new Error("Invalid element");
|
|
5002
|
+
if (!element) throw new Error("Invalid element");
|
|
5029
5003
|
currentViewportPositionMemoUnused = void 0;
|
|
5030
5004
|
const isAdjusted = viewportNavigators.reduce((isAdjusted2, navigator22) => {
|
|
5031
5005
|
return navigator22.adjustReadingOffset({ x, y }) || isAdjusted2;
|
|
@@ -5182,9 +5156,8 @@ const createViewportNavigator = ({
|
|
|
5182
5156
|
}
|
|
5183
5157
|
}),
|
|
5184
5158
|
switchMap$1(([, currentEvent]) => {
|
|
5185
|
-
if ((currentEvent == null ? void 0 : currentEvent.type) !== `manualAdjust`)
|
|
5186
|
-
|
|
5187
|
-
const animationDuration = currentEvent.animation === `snap` ? settings.settings.computedSnapAnimationDuration : settings.settings.computedPageTurnAnimationDuration;
|
|
5159
|
+
if ((currentEvent == null ? void 0 : currentEvent.type) !== `manualAdjust`) return EMPTY;
|
|
5160
|
+
const animationDuration = currentEvent.animation === `snap` ? settings.settings.snapAnimationDuration : settings.settings.computedPageTurnAnimationDuration;
|
|
5188
5161
|
const pageTurnAnimation = currentEvent.animation === `snap` ? `slide` : settings.settings.computedPageTurnAnimation;
|
|
5189
5162
|
return of(currentEvent).pipe(
|
|
5190
5163
|
/**
|
|
@@ -5291,8 +5264,7 @@ const createViewportNavigator = ({
|
|
|
5291
5264
|
() => waitForViewportFree$.pipe(
|
|
5292
5265
|
switchMap$1(() => {
|
|
5293
5266
|
const focusedSpineItem = spineItemManager.getFocusedSpineItem();
|
|
5294
|
-
if (!focusedSpineItem)
|
|
5295
|
-
return EMPTY;
|
|
5267
|
+
if (!focusedSpineItem) return EMPTY;
|
|
5296
5268
|
return adjustNavigation(focusedSpineItem);
|
|
5297
5269
|
}),
|
|
5298
5270
|
takeUntil$1(navigation$)
|
|
@@ -5410,13 +5382,14 @@ const createLocationResolver = ({
|
|
|
5410
5382
|
const getSpineItemsFromReadingOrderPosition = (position) => {
|
|
5411
5383
|
const itemAtPosition = getSpineItemFromPosition(position) || spineItemManager.getFocusedSpineItem();
|
|
5412
5384
|
const itemAtPositionIndex = spineItemManager.getSpineItemIndex(itemAtPosition);
|
|
5413
|
-
if (itemAtPositionIndex === void 0)
|
|
5414
|
-
return void 0;
|
|
5385
|
+
if (itemAtPositionIndex === void 0) return void 0;
|
|
5415
5386
|
let endPosition = position;
|
|
5416
5387
|
if (context.state.isUsingSpreadMode) {
|
|
5417
5388
|
endPosition = { x: position.x + context.getPageSize().width, y: position.y };
|
|
5418
5389
|
}
|
|
5419
|
-
const endItemIndex = spineItemManager.getSpineItemIndex(
|
|
5390
|
+
const endItemIndex = spineItemManager.getSpineItemIndex(
|
|
5391
|
+
getSpineItemFromPosition(endPosition) || spineItemManager.getFocusedSpineItem()
|
|
5392
|
+
) ?? itemAtPositionIndex;
|
|
5420
5393
|
const items = [
|
|
5421
5394
|
{ item: itemAtPositionIndex, position },
|
|
5422
5395
|
{ item: endItemIndex, position: endPosition }
|
|
@@ -5496,12 +5469,10 @@ const createCfiLocator = ({
|
|
|
5496
5469
|
};
|
|
5497
5470
|
const resolveCfi = (cfiString) => {
|
|
5498
5471
|
var _a, _b, _c;
|
|
5499
|
-
if (!cfiString)
|
|
5500
|
-
return void 0;
|
|
5472
|
+
if (!cfiString) return void 0;
|
|
5501
5473
|
const spineItem = getSpineItemFromCfi(cfiString);
|
|
5502
5474
|
const spineItemIndex = spineItemManager.getSpineItemIndex(spineItem) || 0;
|
|
5503
|
-
if (!spineItem)
|
|
5504
|
-
return void 0;
|
|
5475
|
+
if (!spineItem) return void 0;
|
|
5505
5476
|
const { cleanedCfi, offset } = extractProseMetadataFromCfi(cfiString);
|
|
5506
5477
|
const cfi = new CFI(cleanedCfi, {});
|
|
5507
5478
|
const doc = (_c = (_b = (_a = spineItem.spineItemFrame.getManipulableFrame()) == null ? void 0 : _a.frame) == null ? void 0 : _b.contentWindow) == null ? void 0 : _c.document;
|
|
@@ -5541,8 +5512,7 @@ const getComputedSettings = (settings, context) => {
|
|
|
5541
5512
|
computedPageTurnDirection: settings.pageTurnDirection,
|
|
5542
5513
|
computedPageTurnAnimation: settings.pageTurnAnimation,
|
|
5543
5514
|
computedPageTurnMode: `controlled`,
|
|
5544
|
-
computedPageTurnAnimationDuration: 0
|
|
5545
|
-
computedSnapAnimationDuration: 0
|
|
5515
|
+
computedPageTurnAnimationDuration: 0
|
|
5546
5516
|
};
|
|
5547
5517
|
if ((manifest == null ? void 0 : manifest.renditionFlow) === `scrolled-continuous`) {
|
|
5548
5518
|
computedSettings.computedPageTurnMode = `scrollable`;
|
|
@@ -5579,7 +5549,7 @@ const defaultSettings = {
|
|
|
5579
5549
|
// computedPageTurnAnimationDuration: 0,
|
|
5580
5550
|
pageTurnMode: `controlled`,
|
|
5581
5551
|
// computedPageTurnMode: `controlled`,
|
|
5582
|
-
|
|
5552
|
+
snapAnimationDuration: 300,
|
|
5583
5553
|
navigationSnapThreshold: 0.3,
|
|
5584
5554
|
numberOfAdjacentSpineItemToPreLoad: 0
|
|
5585
5555
|
};
|
|
@@ -5613,8 +5583,7 @@ class SettingsManager {
|
|
|
5613
5583
|
this._settingsSubject$.next(newMergedSettings);
|
|
5614
5584
|
}
|
|
5615
5585
|
setSettings(settings) {
|
|
5616
|
-
if (Object.keys(settings).length === 0)
|
|
5617
|
-
return;
|
|
5586
|
+
if (Object.keys(settings).length === 0) return;
|
|
5618
5587
|
const newMergedSettings = { ...this._settingsSubject$.value, ...settings };
|
|
5619
5588
|
this._updateSettings(newMergedSettings);
|
|
5620
5589
|
}
|
|
@@ -5635,7 +5604,7 @@ class HookManager {
|
|
|
5635
5604
|
* - call destroy function for every execution of this specific hook
|
|
5636
5605
|
* - remove the hook for further calls
|
|
5637
5606
|
*/
|
|
5638
|
-
|
|
5607
|
+
deregister(hookToDeregister) {
|
|
5639
5608
|
this._hooks = this._hooks.filter((hook) => hook !== hookToDeregister);
|
|
5640
5609
|
return this.destroy(hookToDeregister.name, void 0, hookToDeregister);
|
|
5641
5610
|
}
|
|
@@ -5647,21 +5616,16 @@ class HookManager {
|
|
|
5647
5616
|
register(name, fn) {
|
|
5648
5617
|
const hook = {
|
|
5649
5618
|
name,
|
|
5650
|
-
runFn:
|
|
5651
|
-
const returnValue = fn(params);
|
|
5652
|
-
if (!returnValue)
|
|
5653
|
-
return of(void 0);
|
|
5654
|
-
return returnValue;
|
|
5655
|
-
}
|
|
5619
|
+
runFn: fn
|
|
5656
5620
|
};
|
|
5657
5621
|
this._hooks.push(hook);
|
|
5658
5622
|
return () => {
|
|
5659
|
-
this.
|
|
5623
|
+
this.deregister(hook);
|
|
5660
5624
|
};
|
|
5661
5625
|
}
|
|
5662
5626
|
execute(name, id, params) {
|
|
5663
5627
|
const hooks = this._hooks.filter((hook) => name === hook.name);
|
|
5664
|
-
const
|
|
5628
|
+
const fnResults = hooks.map((hook) => {
|
|
5665
5629
|
let userDestroyFn = () => of(void 0);
|
|
5666
5630
|
const destroySubject = new Subject();
|
|
5667
5631
|
const destroy = (fn) => {
|
|
@@ -5673,16 +5637,16 @@ class HookManager {
|
|
|
5673
5637
|
const result = userDestroyFn();
|
|
5674
5638
|
return result ?? of(void 0);
|
|
5675
5639
|
};
|
|
5676
|
-
const
|
|
5640
|
+
const fnResult = hook.runFn({ ...params, destroy$: destroySubject.asObservable(), destroy });
|
|
5677
5641
|
this._hookExecutions.push({
|
|
5678
5642
|
name,
|
|
5679
5643
|
id,
|
|
5680
5644
|
destroyFn,
|
|
5681
5645
|
ref: hook
|
|
5682
5646
|
});
|
|
5683
|
-
return
|
|
5647
|
+
return fnResult;
|
|
5684
5648
|
});
|
|
5685
|
-
return
|
|
5649
|
+
return fnResults;
|
|
5686
5650
|
}
|
|
5687
5651
|
destroy(name, id, ref) {
|
|
5688
5652
|
const instances = this._hookExecutions.filter(
|
|
@@ -5764,8 +5728,7 @@ const createReader = (inputSettings) => {
|
|
|
5764
5728
|
var _a;
|
|
5765
5729
|
const containerElement = (_a = elementSubject$.getValue()) == null ? void 0 : _a.parentElement;
|
|
5766
5730
|
const element = elementSubject$.getValue();
|
|
5767
|
-
if (!element || !containerElement)
|
|
5768
|
-
throw new Error("Invalid element");
|
|
5731
|
+
if (!element || !containerElement) throw new Error("Invalid element");
|
|
5769
5732
|
const dimensions = {
|
|
5770
5733
|
width: containerElement == null ? void 0 : containerElement.offsetWidth,
|
|
5771
5734
|
height: containerElement == null ? void 0 : containerElement.offsetHeight
|
|
@@ -5838,7 +5801,12 @@ const createReader = (inputSettings) => {
|
|
|
5838
5801
|
}),
|
|
5839
5802
|
distinctUntilChanged(isShallowEqual),
|
|
5840
5803
|
map$1(
|
|
5841
|
-
({
|
|
5804
|
+
({
|
|
5805
|
+
hasVerticalWriting,
|
|
5806
|
+
renditionFlow,
|
|
5807
|
+
renditionLayout,
|
|
5808
|
+
computedPageTurnMode
|
|
5809
|
+
}) => {
|
|
5842
5810
|
return {
|
|
5843
5811
|
...stateSubject$.value,
|
|
5844
5812
|
supportedPageTurnMode: renditionFlow === `scrolled-continuous` ? [`scrollable`] : !context.state.areAllItemsPrePaginated ? [`controlled`] : [`controlled`, `scrollable`],
|
|
@@ -6032,8 +6000,7 @@ const createResourcesManager = (context) => {
|
|
|
6032
6000
|
};
|
|
6033
6001
|
const get = async (itemIndexOrId, fetchResource) => {
|
|
6034
6002
|
const item = retrieveItem(itemIndexOrId);
|
|
6035
|
-
if (!item)
|
|
6036
|
-
return new Response(`Item not found`, { status: 404 });
|
|
6003
|
+
if (!item) return new Response(`Item not found`, { status: 404 });
|
|
6037
6004
|
const db = await openDatabase(`prose-reader`);
|
|
6038
6005
|
const cacheData = await db.get(`${uniqueID}_${item.id}`);
|
|
6039
6006
|
if (cacheData) {
|
|
@@ -6049,8 +6016,7 @@ const createResourcesManager = (context) => {
|
|
|
6049
6016
|
cache$.asObservable().pipe(
|
|
6050
6017
|
mergeMap(({ id, data }) => {
|
|
6051
6018
|
const item = retrieveItem(id);
|
|
6052
|
-
if (!item)
|
|
6053
|
-
return EMPTY;
|
|
6019
|
+
if (!item) return EMPTY;
|
|
6054
6020
|
return from(forkJoin([openDatabase(`prose-reader`), from(data.blob())])).pipe(
|
|
6055
6021
|
switchMap$1(([db, blob]) => {
|
|
6056
6022
|
return from(db.put(`${uniqueID}_${item.id}`, blob));
|
|
@@ -6204,7 +6170,11 @@ const progressionEnhancer = (next) => (options) => {
|
|
|
6204
6170
|
} else {
|
|
6205
6171
|
progressWithinThisItem = 0;
|
|
6206
6172
|
}
|
|
6207
|
-
totalProgress = getTotalProgressFromPercentages(
|
|
6173
|
+
totalProgress = getTotalProgressFromPercentages(
|
|
6174
|
+
estimateBeforeThisItem,
|
|
6175
|
+
currentItemWeight,
|
|
6176
|
+
progressWithinThisItem
|
|
6177
|
+
);
|
|
6208
6178
|
}
|
|
6209
6179
|
if (currentSpineIndex === readingOrderLength - 1 && pageIndex === numberOfPages - 1 && totalProgress > 0.99) {
|
|
6210
6180
|
return 1;
|
|
@@ -6245,8 +6215,7 @@ const accessibilityEnhancer = (next) => (options) => {
|
|
|
6245
6215
|
reader.hookManager.register(`item.onLoad`, ({ itemId, frame, destroy }) => {
|
|
6246
6216
|
var _a;
|
|
6247
6217
|
const item = reader.spineItemManager.get(itemId);
|
|
6248
|
-
if (!item)
|
|
6249
|
-
return;
|
|
6218
|
+
if (!item) return;
|
|
6250
6219
|
item.manipulateSpineItem(({ addStyle }) => {
|
|
6251
6220
|
addStyle(
|
|
6252
6221
|
`prose-reader-accessibility`,
|
|
@@ -6379,7 +6348,10 @@ const createLoadingElementContainer = (containerElement, context) => {
|
|
|
6379
6348
|
`;
|
|
6380
6349
|
return loadingElement;
|
|
6381
6350
|
};
|
|
6382
|
-
const defaultLoadingElementCreate = ({
|
|
6351
|
+
const defaultLoadingElementCreate = ({
|
|
6352
|
+
container,
|
|
6353
|
+
item
|
|
6354
|
+
}) => {
|
|
6383
6355
|
const logoElement = container.ownerDocument.createElement(`div`);
|
|
6384
6356
|
logoElement.innerText = `prose`;
|
|
6385
6357
|
logoElement.style.cssText = `
|
|
@@ -6414,11 +6386,9 @@ const createNormalizeEventForViewport = ({
|
|
|
6414
6386
|
const eventIsComingFromBridge = event.target === iframeEventBridgeElement$.getValue();
|
|
6415
6387
|
const iframeOriginalEvent = getOriginalFrameEventFromDocumentEvent(event);
|
|
6416
6388
|
const originalFrame = (_a = iframeOriginalEvent == null ? void 0 : iframeOriginalEvent.view) == null ? void 0 : _a.frameElement;
|
|
6417
|
-
if (!eventIsComingFromBridge || !iframeOriginalEvent || !originalFrame)
|
|
6418
|
-
return event;
|
|
6389
|
+
if (!eventIsComingFromBridge || !iframeOriginalEvent || !originalFrame) return event;
|
|
6419
6390
|
const spineItem = locator.getSpineItemFromIframe(originalFrame);
|
|
6420
|
-
if (!spineItem)
|
|
6421
|
-
return event;
|
|
6391
|
+
if (!spineItem) return event;
|
|
6422
6392
|
if (isPointerEvent(event)) {
|
|
6423
6393
|
const { clientX, clientY } = spineItem.translateFramePositionIntoPage(event);
|
|
6424
6394
|
const newEvent = new PointerEvent(event.type, {
|
|
@@ -6504,8 +6474,7 @@ const eventsEnhancer = (next) => (options) => {
|
|
|
6504
6474
|
const reader = next(options);
|
|
6505
6475
|
reader.hookManager.register(`item.onLoad`, ({ destroy, frame, itemId }) => {
|
|
6506
6476
|
const item = reader.spineItemManager.get(itemId);
|
|
6507
|
-
if (!item)
|
|
6508
|
-
return;
|
|
6477
|
+
if (!item) return;
|
|
6509
6478
|
const unregister = passthroughEvents.map((event) => {
|
|
6510
6479
|
var _a;
|
|
6511
6480
|
const listener = (e) => {
|
|
@@ -6596,6 +6565,7 @@ const createReaderWithEnhancers = (
|
|
|
6596
6565
|
)
|
|
6597
6566
|
);
|
|
6598
6567
|
export {
|
|
6568
|
+
HookManager,
|
|
6599
6569
|
Report,
|
|
6600
6570
|
createReaderWithEnhancers as createReader,
|
|
6601
6571
|
groupBy,
|