@prose-reader/core 1.60.0 → 1.61.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/enhancers/fonts/SettingsManager.d.ts +1 -1
- package/dist/enhancers/layoutEnhancer/SettingsManager.d.ts +1 -1
- package/dist/enhancers/pagination/spine.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +995 -361
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +996 -362
- package/dist/index.umd.cjs.map +1 -1
- package/dist/pagination/pagination.d.ts +1 -1
- package/dist/settings/ReaderSettingsManager.d.ts +4 -16
- package/dist/settings/SettingsInterface.d.ts +1 -1
- package/dist/settings/SettingsManager.d.ts +20 -0
- package/dist/settings/SettingsManagerOverload.d.ts +2 -2
- package/dist/spine/cfiLocator.d.ts +3 -3
- package/dist/spine/locationResolver.d.ts +4 -4
- package/dist/spineItem/commonSpineItem.d.ts +1 -1
- package/dist/spineItem/createSpineItem.d.ts +1 -1
- package/dist/spineItem/frameItem/frameItem.d.ts +1 -2
- package/dist/spineItem/frameItem/loader.d.ts +1 -2
- package/dist/spineItem/navigationResolver.d.ts +1 -1
- package/dist/spineItem/prePaginatedSpineItem.d.ts +1 -1
- package/dist/spineItem/reflowableSpineItem.d.ts +1 -1
- package/dist/spineItemManager.d.ts +4 -4
- package/dist/viewportNavigator/manualViewportNavigator.d.ts +2 -2
- package/dist/viewportNavigator/viewportNavigator.d.ts +2 -2
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
var __typeError = (msg) => {
|
|
2
|
-
throw TypeError(msg);
|
|
3
|
-
};
|
|
4
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
-
var _context;
|
|
9
1
|
import { takeUntil, Subject, combineLatest, map as map$1, switchMap, merge, EMPTY, fromEvent, withLatestFrom, NEVER, Observable, of, scheduled, animationFrameScheduler, distinctUntilChanged as distinctUntilChanged$1, startWith as startWith$1, BehaviorSubject, filter as filter$1, debounceTime, combineLatestWith, tap as tap$1, shareReplay as shareReplay$1, from, interval, iif, identity, take as take$1, forkJoin } from "rxjs";
|
|
10
2
|
import { startWith, map, shareReplay, tap, pairwise, switchMap as switchMap$1, filter, take, distinctUntilChanged, takeUntil as takeUntil$1, skip, withLatestFrom as withLatestFrom$1, share, exhaustMap, mergeMap, catchError, debounce, debounceTime as debounceTime$1, delay } from "rxjs/operators";
|
|
11
3
|
import { parseContentType, detectMimeTypeFromName } from "@prose-reader/shared";
|
|
@@ -95,8 +87,15 @@ function shallowMergeIfDefined(obj1, obj2) {
|
|
|
95
87
|
class SettingsManagerOverload {
|
|
96
88
|
constructor(initialSettings, settingsManager) {
|
|
97
89
|
this.settingsManager = settingsManager;
|
|
98
|
-
|
|
99
|
-
|
|
90
|
+
const inputSettings = shallowMergeIfDefined(
|
|
91
|
+
this.getDefaultSettings(),
|
|
92
|
+
initialSettings
|
|
93
|
+
);
|
|
94
|
+
this.outputSettings = this.computeOutputSettings(inputSettings);
|
|
95
|
+
this.inputSettings = shallowMergeIfDefined(
|
|
96
|
+
this.getDefaultSettings(),
|
|
97
|
+
initialSettings
|
|
98
|
+
);
|
|
100
99
|
this.outputSettingsUpdateSubject = new Subject();
|
|
101
100
|
this.settings$ = combineLatest([
|
|
102
101
|
this.settingsManager.settings$,
|
|
@@ -110,18 +109,22 @@ class SettingsManagerOverload {
|
|
|
110
109
|
_prepareUpdate(settings) {
|
|
111
110
|
const parentInputSettings = this.getCleanedParentInputSettings(settings);
|
|
112
111
|
const parentManagerPreparedUpdate = this.settingsManager._prepareUpdate(parentInputSettings);
|
|
113
|
-
|
|
114
|
-
const outputSettings = this.computeOutputSettings();
|
|
112
|
+
const inputSettings = shallowMergeIfDefined(this.inputSettings, settings);
|
|
113
|
+
const outputSettings = this.computeOutputSettings(inputSettings);
|
|
115
114
|
const hasChanged = this.hasSettingsChanged(outputSettings);
|
|
116
|
-
console.log({ outputSettings, hasChanged, parentManagerPreparedUpdate });
|
|
117
115
|
return {
|
|
118
116
|
hasChanged: hasChanged || parentManagerPreparedUpdate.hasChanged,
|
|
119
117
|
commit: () => {
|
|
118
|
+
this.inputSettings = inputSettings;
|
|
120
119
|
this.outputSettings = outputSettings;
|
|
121
120
|
if (!parentManagerPreparedUpdate.hasChanged && hasChanged) {
|
|
122
121
|
this.outputSettingsUpdateSubject.next(outputSettings);
|
|
123
122
|
}
|
|
124
|
-
parentManagerPreparedUpdate.commit();
|
|
123
|
+
const parentOutputSettings = parentManagerPreparedUpdate.commit();
|
|
124
|
+
return {
|
|
125
|
+
...parentOutputSettings,
|
|
126
|
+
...outputSettings
|
|
127
|
+
};
|
|
125
128
|
}
|
|
126
129
|
};
|
|
127
130
|
}
|
|
@@ -139,9 +142,9 @@ class SettingsManagerOverload {
|
|
|
139
142
|
this.outputSettingsUpdateSubject.complete();
|
|
140
143
|
}
|
|
141
144
|
}
|
|
142
|
-
let SettingsManager$
|
|
143
|
-
computeOutputSettings() {
|
|
144
|
-
return
|
|
145
|
+
let SettingsManager$2 = class SettingsManager extends SettingsManagerOverload {
|
|
146
|
+
computeOutputSettings(settings) {
|
|
147
|
+
return settings;
|
|
145
148
|
}
|
|
146
149
|
hasSettingsChanged(newOutputSettings) {
|
|
147
150
|
return !isShallowEqual(this.outputSettings, newOutputSettings);
|
|
@@ -163,7 +166,7 @@ const fontsEnhancer = (next) => (options) => {
|
|
|
163
166
|
const { fontScale, lineHeight, fontWeight, fontJustification } = options;
|
|
164
167
|
const changes$ = new Subject();
|
|
165
168
|
const reader = next(options);
|
|
166
|
-
const settingsManager = new SettingsManager$
|
|
169
|
+
const settingsManager = new SettingsManager$2(
|
|
167
170
|
{
|
|
168
171
|
fontScale,
|
|
169
172
|
lineHeight,
|
|
@@ -216,7 +219,11 @@ const fontsEnhancer = (next) => (options) => {
|
|
|
216
219
|
return false;
|
|
217
220
|
})
|
|
218
221
|
);
|
|
219
|
-
settingsManager.settings$.pipe(
|
|
222
|
+
settingsManager.settings$.pipe(
|
|
223
|
+
shouldRequireLayout,
|
|
224
|
+
tap(applyChangeToSpineItem),
|
|
225
|
+
takeUntil(reader.$.destroy$)
|
|
226
|
+
).subscribe();
|
|
220
227
|
return {
|
|
221
228
|
...reader,
|
|
222
229
|
destroy: () => {
|
|
@@ -257,7 +264,9 @@ const hotkeysEnhancer = (next) => (options) => {
|
|
|
257
264
|
(spineItems) => merge(
|
|
258
265
|
...spineItems.map(
|
|
259
266
|
(item) => item.$.loaded$.pipe(
|
|
260
|
-
switchMap(
|
|
267
|
+
switchMap(
|
|
268
|
+
(iframe) => (iframe == null ? void 0 : iframe.contentDocument) ? navigateOnKey(iframe.contentDocument) : EMPTY
|
|
269
|
+
)
|
|
261
270
|
)
|
|
262
271
|
)
|
|
263
272
|
)
|
|
@@ -291,14 +300,24 @@ const createMovingSafePan$ = (reader) => {
|
|
|
291
300
|
);
|
|
292
301
|
const createResetLock$ = (source) => scheduled(source, animationFrameScheduler).pipe(
|
|
293
302
|
tap(() => {
|
|
294
|
-
iframeOverlayForAnimationsElement == null ? void 0 : iframeOverlayForAnimationsElement.style.setProperty(
|
|
303
|
+
iframeOverlayForAnimationsElement == null ? void 0 : iframeOverlayForAnimationsElement.style.setProperty(
|
|
304
|
+
`visibility`,
|
|
305
|
+
`hidden`
|
|
306
|
+
);
|
|
295
307
|
})
|
|
296
308
|
);
|
|
297
|
-
const viewportFree$ = reader.viewportNavigator.$.state$.pipe(
|
|
298
|
-
|
|
309
|
+
const viewportFree$ = reader.viewportNavigator.$.state$.pipe(
|
|
310
|
+
filter((data) => data === `free`)
|
|
311
|
+
);
|
|
312
|
+
const viewportBusy$ = reader.viewportNavigator.$.state$.pipe(
|
|
313
|
+
filter((data) => data === `busy`)
|
|
314
|
+
);
|
|
299
315
|
const lockAfterViewportBusy$ = viewportBusy$.pipe(
|
|
300
316
|
tap(() => {
|
|
301
|
-
iframeOverlayForAnimationsElement == null ? void 0 : iframeOverlayForAnimationsElement.style.setProperty(
|
|
317
|
+
iframeOverlayForAnimationsElement == null ? void 0 : iframeOverlayForAnimationsElement.style.setProperty(
|
|
318
|
+
`visibility`,
|
|
319
|
+
`visible`
|
|
320
|
+
);
|
|
302
321
|
})
|
|
303
322
|
);
|
|
304
323
|
const resetLockViewportFree$ = createResetLock$(viewportFree$).pipe(take(1));
|
|
@@ -331,34 +350,48 @@ const mapKeysTo = (keys) => {
|
|
|
331
350
|
});
|
|
332
351
|
};
|
|
333
352
|
const fixReflowable = (reader) => {
|
|
334
|
-
reader.hookManager.register(
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
353
|
+
reader.hookManager.register(
|
|
354
|
+
`item.onAfterLayout`,
|
|
355
|
+
({ item, blankPagePosition, minimumWidth }) => {
|
|
356
|
+
var _a;
|
|
357
|
+
const spineItem = reader.spineItemManager.get(item.id);
|
|
358
|
+
if (!((spineItem == null ? void 0 : spineItem.item.renditionLayout) === `reflowable`)) return;
|
|
359
|
+
const { viewportDimensions } = (spineItem == null ? void 0 : spineItem.getViewPortInformation()) ?? {};
|
|
360
|
+
const { width: pageWidth } = reader.context.getPageSize();
|
|
361
|
+
const frameElement = (_a = spineItem == null ? void 0 : spineItem.spineItemFrame.getManipulableFrame()) == null ? void 0 : _a.frame;
|
|
362
|
+
if (viewportDimensions) {
|
|
363
|
+
const spineManagerWantAFullWidthItem = pageWidth < minimumWidth;
|
|
364
|
+
const noBlankPageAsked = blankPagePosition === `none`;
|
|
365
|
+
if (noBlankPageAsked && spineManagerWantAFullWidthItem) {
|
|
366
|
+
frameElement == null ? void 0 : frameElement.style.setProperty(
|
|
367
|
+
`left`,
|
|
368
|
+
reader.context.isRTL() ? `75%` : `25%`
|
|
369
|
+
);
|
|
370
|
+
}
|
|
346
371
|
}
|
|
347
372
|
}
|
|
348
|
-
|
|
373
|
+
);
|
|
349
374
|
};
|
|
350
375
|
function isDefined(arg) {
|
|
351
376
|
return arg !== null && arg !== void 0;
|
|
352
377
|
}
|
|
353
|
-
class SettingsManager2 extends SettingsManagerOverload {
|
|
354
|
-
computeOutputSettings() {
|
|
355
|
-
return
|
|
378
|
+
let SettingsManager$1 = class SettingsManager2 extends SettingsManagerOverload {
|
|
379
|
+
computeOutputSettings(inputSettings) {
|
|
380
|
+
return inputSettings;
|
|
356
381
|
}
|
|
357
382
|
hasSettingsChanged(newOutputSettings) {
|
|
358
383
|
return !isShallowEqual(this.outputSettings, newOutputSettings);
|
|
359
384
|
}
|
|
360
385
|
getCleanedParentInputSettings(settings) {
|
|
361
|
-
const {
|
|
386
|
+
const {
|
|
387
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
388
|
+
layoutAutoResize,
|
|
389
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
390
|
+
pageHorizontalMargin,
|
|
391
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
392
|
+
pageVerticalMargin,
|
|
393
|
+
...rest
|
|
394
|
+
} = settings;
|
|
362
395
|
return rest;
|
|
363
396
|
}
|
|
364
397
|
getDefaultSettings() {
|
|
@@ -368,12 +401,12 @@ class SettingsManager2 extends SettingsManagerOverload {
|
|
|
368
401
|
pageVerticalMargin: 24
|
|
369
402
|
};
|
|
370
403
|
}
|
|
371
|
-
}
|
|
404
|
+
};
|
|
372
405
|
const SHOULD_NOT_LAYOUT = false;
|
|
373
406
|
const layoutEnhancer = (next) => (options) => {
|
|
374
407
|
const { pageHorizontalMargin, pageVerticalMargin, layoutAutoResize } = options;
|
|
375
408
|
const reader = next(options);
|
|
376
|
-
const settingsManager = new
|
|
409
|
+
const settingsManager = new SettingsManager$1(
|
|
377
410
|
{
|
|
378
411
|
pageHorizontalMargin,
|
|
379
412
|
pageVerticalMargin,
|
|
@@ -391,24 +424,26 @@ const layoutEnhancer = (next) => (options) => {
|
|
|
391
424
|
return SHOULD_NOT_LAYOUT;
|
|
392
425
|
});
|
|
393
426
|
});
|
|
394
|
-
reader.hookManager.register(
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
`prose-layout-enhancer-css
|
|
411
|
-
|
|
427
|
+
reader.hookManager.register(
|
|
428
|
+
`item.onLayoutBeforeMeasurement`,
|
|
429
|
+
({ frame, minimumWidth, item, isImageType }) => {
|
|
430
|
+
var _a, _b;
|
|
431
|
+
const { pageHorizontalMargin: pageHorizontalMargin2 = 0, pageVerticalMargin: pageVerticalMargin2 = 0 } = settingsManager.settings;
|
|
432
|
+
const pageSize = reader.context.getPageSize();
|
|
433
|
+
if (item.renditionLayout === `reflowable` && frame.getIsReady() && !isImageType() && !frame.getViewportDimensions()) {
|
|
434
|
+
let columnWidth = pageSize.width - pageHorizontalMargin2 * 2;
|
|
435
|
+
const columnHeight = pageSize.height - pageVerticalMargin2 * 2;
|
|
436
|
+
let width = pageSize.width - pageHorizontalMargin2 * 2;
|
|
437
|
+
let columnGap = pageHorizontalMargin2 * 2;
|
|
438
|
+
if (frame.isUsingVerticalWriting()) {
|
|
439
|
+
width = minimumWidth - pageHorizontalMargin2 * 2;
|
|
440
|
+
columnWidth = columnHeight;
|
|
441
|
+
columnGap = pageVerticalMargin2 * 2;
|
|
442
|
+
}
|
|
443
|
+
(_a = frame.getManipulableFrame()) == null ? void 0 : _a.removeStyle(`prose-layout-enhancer-css`);
|
|
444
|
+
(_b = frame.getManipulableFrame()) == null ? void 0 : _b.addStyle(
|
|
445
|
+
`prose-layout-enhancer-css`,
|
|
446
|
+
`
|
|
412
447
|
body {
|
|
413
448
|
width: ${width}px !important;
|
|
414
449
|
margin: ${pageVerticalMargin2}px ${pageHorizontalMargin2}px !important;
|
|
@@ -427,9 +462,10 @@ const layoutEnhancer = (next) => (options) => {
|
|
|
427
462
|
max-width: ${columnWidth}px;
|
|
428
463
|
}
|
|
429
464
|
`
|
|
430
|
-
|
|
465
|
+
);
|
|
466
|
+
}
|
|
431
467
|
}
|
|
432
|
-
|
|
468
|
+
);
|
|
433
469
|
fixReflowable(reader);
|
|
434
470
|
let observer;
|
|
435
471
|
if (options.layoutAutoResize === `container`) {
|
|
@@ -480,7 +516,10 @@ const time = (name, targetDuration = 0) => {
|
|
|
480
516
|
return () => {
|
|
481
517
|
tick++;
|
|
482
518
|
const t1 = performance.now();
|
|
483
|
-
Report.logMetric(
|
|
519
|
+
Report.logMetric(
|
|
520
|
+
{ name: `${name} - tick ${tick}`, duration: t1 - t0 },
|
|
521
|
+
targetDuration
|
|
522
|
+
);
|
|
484
523
|
};
|
|
485
524
|
};
|
|
486
525
|
const createReport = (namespace) => ({
|
|
@@ -496,7 +535,8 @@ const createReport = (namespace) => ({
|
|
|
496
535
|
warn: (...data) => {
|
|
497
536
|
var _a;
|
|
498
537
|
if ((_a = getWindow()) == null ? void 0 : _a.__PROSE_READER_DEBUG) {
|
|
499
|
-
if (namespace)
|
|
538
|
+
if (namespace)
|
|
539
|
+
console.warn(wrap(ROOT_NAMESPACE), wrap(namespace), ...data);
|
|
500
540
|
else console.warn(wrap(ROOT_NAMESPACE), ...data);
|
|
501
541
|
}
|
|
502
542
|
},
|
|
@@ -561,7 +601,9 @@ const linksEnhancer = (next) => (options) => {
|
|
|
561
601
|
if (!element.href) return false;
|
|
562
602
|
const hrefUrl = new URL(element.href);
|
|
563
603
|
const hrefWithoutAnchor = `${hrefUrl.origin}${hrefUrl.pathname}`;
|
|
564
|
-
const hasExistingSpineItem = (_a = reader.context.manifest) == null ? void 0 : _a.spineItems.some(
|
|
604
|
+
const hasExistingSpineItem = (_a = reader.context.manifest) == null ? void 0 : _a.spineItems.some(
|
|
605
|
+
(item) => item.href === hrefWithoutAnchor
|
|
606
|
+
);
|
|
565
607
|
if (hasExistingSpineItem) {
|
|
566
608
|
reader.viewportNavigator.goToUrl(hrefUrl);
|
|
567
609
|
return true;
|
|
@@ -576,7 +618,11 @@ const linksEnhancer = (next) => (options) => {
|
|
|
576
618
|
Report.warn(`prevented click on`, element, e);
|
|
577
619
|
e.preventDefault();
|
|
578
620
|
const isNavigable = handleNavigationForClick(element);
|
|
579
|
-
subject.next({
|
|
621
|
+
subject.next({
|
|
622
|
+
event: `linkClicked`,
|
|
623
|
+
data: element,
|
|
624
|
+
isNavigable
|
|
625
|
+
});
|
|
580
626
|
}
|
|
581
627
|
})
|
|
582
628
|
);
|
|
@@ -617,14 +663,16 @@ const createNavigator = (reader) => {
|
|
|
617
663
|
goToNextSpineItem,
|
|
618
664
|
goToPreviousSpineItem,
|
|
619
665
|
goToLeftSpineItem: () => {
|
|
620
|
-
if (reader.settings.settings.computedPageTurnDirection === "vertical")
|
|
666
|
+
if (reader.settings.settings.computedPageTurnDirection === "vertical")
|
|
667
|
+
return;
|
|
621
668
|
if (reader.context.isRTL()) {
|
|
622
669
|
return goToNextSpineItem();
|
|
623
670
|
}
|
|
624
671
|
return goToPreviousSpineItem();
|
|
625
672
|
},
|
|
626
673
|
goToRightSpineItem: () => {
|
|
627
|
-
if (reader.settings.settings.computedPageTurnDirection === "vertical")
|
|
674
|
+
if (reader.settings.settings.computedPageTurnDirection === "vertical")
|
|
675
|
+
return;
|
|
628
676
|
if (reader.context.isRTL()) {
|
|
629
677
|
return goToPreviousSpineItem();
|
|
630
678
|
}
|
|
@@ -662,17 +710,24 @@ const navigationEnhancer = (next) => (options) => {
|
|
|
662
710
|
};
|
|
663
711
|
};
|
|
664
712
|
const buildChaptersInfo = (href, tocItem, manifest) => {
|
|
665
|
-
const spineItemIndex = manifest.spineItems.findIndex(
|
|
713
|
+
const spineItemIndex = manifest.spineItems.findIndex(
|
|
714
|
+
(item) => item.href === href
|
|
715
|
+
);
|
|
666
716
|
return tocItem.reduce((acc, tocItem2) => {
|
|
667
717
|
const indexOfHash = tocItem2.href.indexOf(`#`);
|
|
668
718
|
const tocItemPathWithoutAnchor = indexOfHash > 0 ? tocItem2.href.substr(0, indexOfHash) : tocItem2.href;
|
|
669
|
-
const tocItemHrefWithoutFilename = tocItemPathWithoutAnchor.substring(
|
|
719
|
+
const tocItemHrefWithoutFilename = tocItemPathWithoutAnchor.substring(
|
|
720
|
+
0,
|
|
721
|
+
tocItemPathWithoutAnchor.lastIndexOf("/")
|
|
722
|
+
);
|
|
670
723
|
const hrefWithoutFilename = href.substring(0, href.lastIndexOf("/"));
|
|
671
724
|
const hrefIsChapterHref = href.endsWith(tocItemPathWithoutAnchor);
|
|
672
725
|
const hrefIsWithinChapter = hrefWithoutFilename !== "" && hrefWithoutFilename.endsWith(tocItemHrefWithoutFilename);
|
|
673
726
|
const isPossibleTocItemCandidate = hrefIsChapterHref || hrefIsWithinChapter;
|
|
674
727
|
if (isPossibleTocItemCandidate) {
|
|
675
|
-
const spineItemIndexOfPossibleCandidate = manifest.spineItems.findIndex(
|
|
728
|
+
const spineItemIndexOfPossibleCandidate = manifest.spineItems.findIndex(
|
|
729
|
+
(item) => item.href === tocItem2.href
|
|
730
|
+
);
|
|
676
731
|
const spineItemIsBeforeThisTocItem = spineItemIndex < spineItemIndexOfPossibleCandidate;
|
|
677
732
|
if (spineItemIsBeforeThisTocItem) return acc;
|
|
678
733
|
const info = {
|
|
@@ -717,7 +772,9 @@ const trackChapterInfo = (reader) => {
|
|
|
717
772
|
);
|
|
718
773
|
};
|
|
719
774
|
const NAMESPACE$6 = `pagination`;
|
|
720
|
-
const createPagination = ({
|
|
775
|
+
const createPagination = ({
|
|
776
|
+
context
|
|
777
|
+
}) => {
|
|
721
778
|
const paginationSubject$ = new BehaviorSubject({
|
|
722
779
|
beginPageIndexInSpineItem: void 0,
|
|
723
780
|
beginNumberOfPagesInSpineItem: 0,
|
|
@@ -770,7 +827,9 @@ const createPagination = ({ context }) => {
|
|
|
770
827
|
const getPaginationInfo = () => paginationSubject$.value;
|
|
771
828
|
const paginationInfo$ = paginationSubject$.pipe(
|
|
772
829
|
distinctUntilChanged$1(isShallowEqual),
|
|
773
|
-
filter$1(
|
|
830
|
+
filter$1(
|
|
831
|
+
({ beginPageIndexInSpineItem }) => beginPageIndexInSpineItem !== void 0
|
|
832
|
+
)
|
|
774
833
|
);
|
|
775
834
|
const destroy = () => {
|
|
776
835
|
paginationSubject$.complete();
|
|
@@ -794,10 +853,14 @@ const calculateNumberOfPagesForItem = (itemWidth, pageWidth) => {
|
|
|
794
853
|
const getClosestValidOffsetFromApproximateOffsetInPages = (offset, pageWidth, itemWidth) => {
|
|
795
854
|
const numberOfPages = calculateNumberOfPagesForItem(itemWidth, pageWidth);
|
|
796
855
|
const offsetValues = [...Array(numberOfPages)].map((_, i) => i * pageWidth);
|
|
797
|
-
if (offset >= numberOfPages * pageWidth)
|
|
856
|
+
if (offset >= numberOfPages * pageWidth)
|
|
857
|
+
return offsetValues[offsetValues.length - 1] || 0;
|
|
798
858
|
return offsetValues.find((offsetRange) => offset < offsetRange + pageWidth) || 0;
|
|
799
859
|
};
|
|
800
|
-
const getSpineItemNumberOfPages = ({
|
|
860
|
+
const getSpineItemNumberOfPages = ({
|
|
861
|
+
spineItem,
|
|
862
|
+
reader
|
|
863
|
+
}) => {
|
|
801
864
|
const writingMode = spineItem.spineItemFrame.getWritingMode();
|
|
802
865
|
const { width, height } = spineItem.getElementDimensions();
|
|
803
866
|
const settings = reader.settings.settings;
|
|
@@ -805,9 +868,15 @@ const getSpineItemNumberOfPages = ({ spineItem, reader }) => {
|
|
|
805
868
|
return 1;
|
|
806
869
|
}
|
|
807
870
|
if (writingMode === `vertical-rl`) {
|
|
808
|
-
return calculateNumberOfPagesForItem(
|
|
871
|
+
return calculateNumberOfPagesForItem(
|
|
872
|
+
height,
|
|
873
|
+
reader.context.getPageSize().height
|
|
874
|
+
);
|
|
809
875
|
}
|
|
810
|
-
return calculateNumberOfPagesForItem(
|
|
876
|
+
return calculateNumberOfPagesForItem(
|
|
877
|
+
width,
|
|
878
|
+
reader.context.getPageSize().width
|
|
879
|
+
);
|
|
811
880
|
};
|
|
812
881
|
const getNumberOfPagesForAllSpineItems = (reader) => reader.spineItemManager.getAll().map((item) => {
|
|
813
882
|
return getSpineItemNumberOfPages({ spineItem: item, reader });
|
|
@@ -823,7 +892,10 @@ const trackTotalPages = (reader) => {
|
|
|
823
892
|
/**
|
|
824
893
|
* This may be not accurate for reflowable due to dynamic load / unload.
|
|
825
894
|
*/
|
|
826
|
-
numberOfTotalPages: numberOfPagesPerItems.reduce(
|
|
895
|
+
numberOfTotalPages: numberOfPagesPerItems.reduce(
|
|
896
|
+
(acc, numberOfPagesForItem) => acc + numberOfPagesForItem,
|
|
897
|
+
0
|
|
898
|
+
)
|
|
827
899
|
};
|
|
828
900
|
}),
|
|
829
901
|
distinctUntilChanged$1(isShallowEqual),
|
|
@@ -880,7 +952,10 @@ const trackPaginationInfo = (reader) => {
|
|
|
880
952
|
const totalPages$ = trackTotalPages(reader);
|
|
881
953
|
const currentValue = new BehaviorSubject({
|
|
882
954
|
...reader.pagination.getPaginationInfo(),
|
|
883
|
-
...mapPaginationInfoToExtendedInfo(reader)(
|
|
955
|
+
...mapPaginationInfoToExtendedInfo(reader)(
|
|
956
|
+
reader.pagination.getPaginationInfo(),
|
|
957
|
+
getChaptersInfo(reader)
|
|
958
|
+
),
|
|
884
959
|
beginAbsolutePageIndex: 0,
|
|
885
960
|
endAbsolutePageIndex: 0,
|
|
886
961
|
numberOfTotalPages: 0
|
|
@@ -900,8 +975,14 @@ const trackPaginationInfo = (reader) => {
|
|
|
900
975
|
map$1(([pageInfo, totalPageInfo]) => ({
|
|
901
976
|
...pageInfo,
|
|
902
977
|
...totalPageInfo,
|
|
903
|
-
beginAbsolutePageIndex: totalPageInfo.numberOfPagesPerItems.slice(0, pageInfo.beginSpineItemIndex).reduce(
|
|
904
|
-
|
|
978
|
+
beginAbsolutePageIndex: totalPageInfo.numberOfPagesPerItems.slice(0, pageInfo.beginSpineItemIndex).reduce(
|
|
979
|
+
(acc, numberOfPagesForItem) => acc + numberOfPagesForItem,
|
|
980
|
+
pageInfo.beginPageIndexInSpineItem ?? 0
|
|
981
|
+
),
|
|
982
|
+
endAbsolutePageIndex: totalPageInfo.numberOfPagesPerItems.slice(0, pageInfo.endSpineItemIndex).reduce(
|
|
983
|
+
(acc, numberOfPagesForItem) => acc + numberOfPagesForItem,
|
|
984
|
+
pageInfo.endPageIndexInSpineItem ?? 0
|
|
985
|
+
)
|
|
905
986
|
})),
|
|
906
987
|
tap$1((value) => {
|
|
907
988
|
currentValue.next(value);
|
|
@@ -943,9 +1024,13 @@ const defaultThemes = [
|
|
|
943
1024
|
];
|
|
944
1025
|
const themeEnhancer = (next) => (options) => {
|
|
945
1026
|
const reader = next(options);
|
|
946
|
-
const currentThemeSubject$ = new BehaviorSubject(
|
|
1027
|
+
const currentThemeSubject$ = new BehaviorSubject(
|
|
1028
|
+
options.theme ?? `bright`
|
|
1029
|
+
);
|
|
947
1030
|
const getStyle = () => {
|
|
948
|
-
const foundTheme = defaultThemes.find(
|
|
1031
|
+
const foundTheme = defaultThemes.find(
|
|
1032
|
+
(entry) => entry.name === currentThemeSubject$.value
|
|
1033
|
+
);
|
|
949
1034
|
return `
|
|
950
1035
|
body {
|
|
951
1036
|
${foundTheme !== void 0 ? `background-color: ${foundTheme.backgroundColor} !important;` : ``}
|
|
@@ -962,21 +1047,30 @@ const themeEnhancer = (next) => (options) => {
|
|
|
962
1047
|
` : ``}
|
|
963
1048
|
`;
|
|
964
1049
|
};
|
|
965
|
-
const applyChangeToSpineItemElement = ({
|
|
966
|
-
|
|
1050
|
+
const applyChangeToSpineItemElement = ({
|
|
1051
|
+
container
|
|
1052
|
+
}) => {
|
|
1053
|
+
const foundTheme = defaultThemes.find(
|
|
1054
|
+
(entry) => entry.name === currentThemeSubject$.value
|
|
1055
|
+
);
|
|
967
1056
|
if (foundTheme) {
|
|
968
|
-
container.style.setProperty(
|
|
1057
|
+
container.style.setProperty(
|
|
1058
|
+
`background-color`,
|
|
1059
|
+
foundTheme.backgroundColor
|
|
1060
|
+
);
|
|
969
1061
|
}
|
|
970
1062
|
return () => {
|
|
971
1063
|
};
|
|
972
1064
|
};
|
|
973
1065
|
const applyChangeToSpineItem = () => {
|
|
974
|
-
reader.spine.manipulateSpineItems(
|
|
975
|
-
removeStyle
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
1066
|
+
reader.spine.manipulateSpineItems(
|
|
1067
|
+
({ removeStyle, addStyle, container }) => {
|
|
1068
|
+
removeStyle(`prose-reader-theme`);
|
|
1069
|
+
addStyle(`prose-reader-theme`, getStyle());
|
|
1070
|
+
applyChangeToSpineItemElement({ container });
|
|
1071
|
+
return false;
|
|
1072
|
+
}
|
|
1073
|
+
);
|
|
980
1074
|
};
|
|
981
1075
|
reader.hookManager.register(`item.onLoad`, ({ itemId }) => {
|
|
982
1076
|
const item = reader.spineItemManager.get(itemId);
|
|
@@ -987,7 +1081,11 @@ const themeEnhancer = (next) => (options) => {
|
|
|
987
1081
|
});
|
|
988
1082
|
});
|
|
989
1083
|
reader.spine.$.spineItems$.pipe(
|
|
990
|
-
tap(
|
|
1084
|
+
tap(
|
|
1085
|
+
(items) => items.map(
|
|
1086
|
+
({ element }) => applyChangeToSpineItemElement({ container: element })
|
|
1087
|
+
)
|
|
1088
|
+
),
|
|
991
1089
|
takeUntil$1(reader.$.destroy$)
|
|
992
1090
|
).subscribe();
|
|
993
1091
|
currentThemeSubject$.pipe(
|
|
@@ -1054,7 +1152,9 @@ const createElementZoomer = (reader) => {
|
|
|
1054
1152
|
};
|
|
1055
1153
|
const scale = (userScale) => {
|
|
1056
1154
|
const imgElement = imageMagnifierContainer == null ? void 0 : imageMagnifierContainer.querySelector(`img`);
|
|
1057
|
-
const roundedScale = Math.ceil(
|
|
1155
|
+
const roundedScale = Math.ceil(
|
|
1156
|
+
(userScale < 1 ? baseScale - (1 - userScale) : baseScale + (userScale - 1)) * 100
|
|
1157
|
+
) / 100;
|
|
1058
1158
|
const newScale = Math.max(roundedScale, 1);
|
|
1059
1159
|
if (roundedScale < 1) {
|
|
1060
1160
|
imgLastPosition = { x: 0, y: 0 };
|
|
@@ -1150,7 +1250,9 @@ const createViewportZoomer = (reader) => {
|
|
|
1150
1250
|
const spineElement = reader.spine.getElement();
|
|
1151
1251
|
const viewportElement = reader.viewportNavigator.getElement();
|
|
1152
1252
|
if (!spineElement || !viewportElement) return;
|
|
1153
|
-
const roundedScale = Math.ceil(
|
|
1253
|
+
const roundedScale = Math.ceil(
|
|
1254
|
+
(userScale < 1 ? baseScale - (1 - userScale) : baseScale + (userScale - 1)) * 100
|
|
1255
|
+
) / 100;
|
|
1154
1256
|
const newScale = Math.max(roundedScale, 1);
|
|
1155
1257
|
const currentScale = spineElement.getBoundingClientRect().width / spineElement.offsetWidth;
|
|
1156
1258
|
const currentScrollTop = viewportElement.scrollTop;
|
|
@@ -1259,7 +1361,9 @@ const zoomEnhancer = (next) => (options) => {
|
|
|
1259
1361
|
isUsingScrollableZoom: isUsingScrollableViewport,
|
|
1260
1362
|
setCurrentScaleAsBase,
|
|
1261
1363
|
$: {
|
|
1262
|
-
isZooming$: currentZoomerSubject$.pipe(
|
|
1364
|
+
isZooming$: currentZoomerSubject$.pipe(
|
|
1365
|
+
switchMap((zoomer) => (zoomer == null ? void 0 : zoomer.isZooming$) || of(false))
|
|
1366
|
+
)
|
|
1263
1367
|
}
|
|
1264
1368
|
}
|
|
1265
1369
|
};
|
|
@@ -1406,15 +1510,21 @@ const getOriginalFrameEventFromDocumentEvent = (event) => {
|
|
|
1406
1510
|
return event[__UNSAFE_REFERENCE_ORIGINAL_IFRAME_EVENT_KEY];
|
|
1407
1511
|
};
|
|
1408
1512
|
const attachOriginalFrameEventToDocumentEvent = (event, frameEvent) => {
|
|
1409
|
-
Object.defineProperty(event, __UNSAFE_REFERENCE_ORIGINAL_IFRAME_EVENT_KEY, {
|
|
1513
|
+
Object.defineProperty(event, __UNSAFE_REFERENCE_ORIGINAL_IFRAME_EVENT_KEY, {
|
|
1514
|
+
value: frameEvent,
|
|
1515
|
+
enumerable: true
|
|
1516
|
+
});
|
|
1410
1517
|
};
|
|
1411
|
-
const createFrame$ = Report.measurePerformance(
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1518
|
+
const createFrame$ = Report.measurePerformance(
|
|
1519
|
+
`SpineItemFrame createFrame`,
|
|
1520
|
+
Infinity,
|
|
1521
|
+
() => {
|
|
1522
|
+
const frame = document.createElement(`iframe`);
|
|
1523
|
+
frame.frameBorder = `no`;
|
|
1524
|
+
frame.tabIndex = 0;
|
|
1525
|
+
frame.setAttribute(`sandbox`, `allow-same-origin allow-scripts`);
|
|
1526
|
+
frame.scrolling = `no`;
|
|
1527
|
+
frame.style.cssText = `
|
|
1418
1528
|
visibility: hidden;
|
|
1419
1529
|
overflow: hidden;
|
|
1420
1530
|
background-color: transparent;
|
|
@@ -1423,8 +1533,9 @@ const createFrame$ = Report.measurePerformance(`SpineItemFrame createFrame`, Inf
|
|
|
1423
1533
|
transition: opacity 300ms;
|
|
1424
1534
|
opacity: 0;
|
|
1425
1535
|
`;
|
|
1426
|
-
|
|
1427
|
-
}
|
|
1536
|
+
return of(frame);
|
|
1537
|
+
}
|
|
1538
|
+
);
|
|
1428
1539
|
const getIntrinsicDimensionsFromBase64Img = (data) => new Promise((resolve, reject) => {
|
|
1429
1540
|
const image = new Image();
|
|
1430
1541
|
image.src = data;
|
|
@@ -1436,7 +1547,9 @@ const getIntrinsicDimensionsFromBase64Img = (data) => new Promise((resolve, reje
|
|
|
1436
1547
|
const createHtmlPageFromResource = async (resourceResponse, item) => {
|
|
1437
1548
|
if (typeof resourceResponse === `string`) return resourceResponse;
|
|
1438
1549
|
const contentType = parseContentType(resourceResponse.headers.get(`Content-Type`) || ``) || detectMimeTypeFromName(item.href);
|
|
1439
|
-
if ([`image/jpg`, `image/jpeg`, `image/png`, `image/webp`].some(
|
|
1550
|
+
if ([`image/jpg`, `image/jpeg`, `image/png`, `image/webp`].some(
|
|
1551
|
+
(mime) => mime === contentType
|
|
1552
|
+
)) {
|
|
1440
1553
|
const data = await getBase64FromBlob(await resourceResponse.blob());
|
|
1441
1554
|
const { height, width } = await getIntrinsicDimensionsFromBase64Img(data);
|
|
1442
1555
|
return `
|
|
@@ -1479,7 +1592,6 @@ const createHtmlPageFromResource = async (resourceResponse, item) => {
|
|
|
1479
1592
|
const createLoader = ({
|
|
1480
1593
|
item,
|
|
1481
1594
|
parent,
|
|
1482
|
-
fetchResource,
|
|
1483
1595
|
context,
|
|
1484
1596
|
viewportState$,
|
|
1485
1597
|
settings,
|
|
@@ -1524,9 +1636,17 @@ const createLoader = ({
|
|
|
1524
1636
|
mergeMap((frame) => {
|
|
1525
1637
|
parent.appendChild(frame);
|
|
1526
1638
|
frameElementSubject$.next(frame);
|
|
1639
|
+
const { fetchResource } = settings.settings;
|
|
1527
1640
|
if (!fetchResource && item.href.startsWith(window.location.origin) && // we have an encoding and it's a valid html
|
|
1528
|
-
(item.mediaType && [
|
|
1529
|
-
|
|
1641
|
+
(item.mediaType && [
|
|
1642
|
+
`application/xhtml+xml`,
|
|
1643
|
+
`application/xml`,
|
|
1644
|
+
`text/html`,
|
|
1645
|
+
`text/xml`
|
|
1646
|
+
].includes(item.mediaType) || // no encoding ? then try to detect html
|
|
1647
|
+
!item.mediaType && ITEM_EXTENSION_VALID_FOR_FRAME_SRC.some(
|
|
1648
|
+
(extension) => item.href.endsWith(extension)
|
|
1649
|
+
))) {
|
|
1530
1650
|
frame == null ? void 0 : frame.setAttribute(`src`, item.href);
|
|
1531
1651
|
return of(frame);
|
|
1532
1652
|
} else {
|
|
@@ -1540,7 +1660,9 @@ const createLoader = ({
|
|
|
1540
1660
|
}),
|
|
1541
1661
|
map(() => frame),
|
|
1542
1662
|
catchError((e) => {
|
|
1543
|
-
Report.error(
|
|
1663
|
+
Report.error(
|
|
1664
|
+
`Error while trying to fetch or load resource for item ${item.id}`
|
|
1665
|
+
);
|
|
1544
1666
|
console.error(e);
|
|
1545
1667
|
return of(frame);
|
|
1546
1668
|
})
|
|
@@ -1568,8 +1690,12 @@ const createLoader = ({
|
|
|
1568
1690
|
const hookResults = hookManager.execute(`item.onLoad`, item.id, {
|
|
1569
1691
|
itemId: item.id,
|
|
1570
1692
|
frame
|
|
1571
|
-
}).filter(
|
|
1572
|
-
|
|
1693
|
+
}).filter(
|
|
1694
|
+
(result) => result instanceof Observable
|
|
1695
|
+
);
|
|
1696
|
+
return combineLatest([of(null), ...hookResults]).pipe(
|
|
1697
|
+
map(() => frame)
|
|
1698
|
+
);
|
|
1573
1699
|
})
|
|
1574
1700
|
);
|
|
1575
1701
|
}),
|
|
@@ -1582,10 +1708,14 @@ const createLoader = ({
|
|
|
1582
1708
|
takeUntil$1(destroySubject$)
|
|
1583
1709
|
);
|
|
1584
1710
|
const ready$ = load$.pipe(
|
|
1585
|
-
switchMap$1(
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1711
|
+
switchMap$1(
|
|
1712
|
+
(frame) => {
|
|
1713
|
+
var _a;
|
|
1714
|
+
return from(((_a = frame == null ? void 0 : frame.contentDocument) == null ? void 0 : _a.fonts.ready) || of(void 0)).pipe(
|
|
1715
|
+
takeUntil$1(unloadSubject$)
|
|
1716
|
+
);
|
|
1717
|
+
}
|
|
1718
|
+
),
|
|
1589
1719
|
share(),
|
|
1590
1720
|
makeItHot,
|
|
1591
1721
|
takeUntil$1(destroySubject$)
|
|
@@ -1626,7 +1756,6 @@ const createFrameManipulator = (frameElement) => ({
|
|
|
1626
1756
|
const createFrameItem = ({
|
|
1627
1757
|
item,
|
|
1628
1758
|
parent,
|
|
1629
|
-
fetchResource,
|
|
1630
1759
|
context,
|
|
1631
1760
|
viewportState$,
|
|
1632
1761
|
settings,
|
|
@@ -1634,12 +1763,27 @@ const createFrameItem = ({
|
|
|
1634
1763
|
}) => {
|
|
1635
1764
|
const destroySubject$ = new Subject();
|
|
1636
1765
|
const {
|
|
1637
|
-
$: {
|
|
1766
|
+
$: {
|
|
1767
|
+
unload$,
|
|
1768
|
+
loaded$,
|
|
1769
|
+
isLoaded$,
|
|
1770
|
+
isReady$,
|
|
1771
|
+
unloaded$,
|
|
1772
|
+
frameElement$,
|
|
1773
|
+
ready$
|
|
1774
|
+
},
|
|
1638
1775
|
load,
|
|
1639
1776
|
unload,
|
|
1640
1777
|
destroy: loaderDestroy,
|
|
1641
1778
|
getComputedStyleAfterLoad
|
|
1642
|
-
} = createLoader({
|
|
1779
|
+
} = createLoader({
|
|
1780
|
+
context,
|
|
1781
|
+
hookManager,
|
|
1782
|
+
item,
|
|
1783
|
+
parent,
|
|
1784
|
+
viewportState$,
|
|
1785
|
+
settings
|
|
1786
|
+
});
|
|
1643
1787
|
let isLoadedSync = false;
|
|
1644
1788
|
let isReadySync = false;
|
|
1645
1789
|
isLoaded$.subscribe({
|
|
@@ -1667,7 +1811,10 @@ const createFrameItem = ({
|
|
|
1667
1811
|
const viewPortMetaInfos = viewPortMeta.getAttribute(`content`);
|
|
1668
1812
|
if (viewPortMetaInfos) {
|
|
1669
1813
|
const width = getAttributeValueFromString(viewPortMetaInfos, `width`);
|
|
1670
|
-
const height = getAttributeValueFromString(
|
|
1814
|
+
const height = getAttributeValueFromString(
|
|
1815
|
+
viewPortMetaInfos,
|
|
1816
|
+
`height`
|
|
1817
|
+
);
|
|
1671
1818
|
if (width > 0 && height > 0) {
|
|
1672
1819
|
return {
|
|
1673
1820
|
width,
|
|
@@ -1742,7 +1889,8 @@ const createFrameItem = ({
|
|
|
1742
1889
|
return `rtl`;
|
|
1743
1890
|
}
|
|
1744
1891
|
const direction = (_a = getComputedStyleAfterLoad()) == null ? void 0 : _a.direction;
|
|
1745
|
-
if ([`ltr`, `rtl`].includes(direction || ``))
|
|
1892
|
+
if ([`ltr`, `rtl`].includes(direction || ``))
|
|
1893
|
+
return direction;
|
|
1746
1894
|
return void 0;
|
|
1747
1895
|
},
|
|
1748
1896
|
isUsingVerticalWriting,
|
|
@@ -1814,7 +1962,10 @@ const createSelectionTracker = () => {
|
|
|
1814
1962
|
});
|
|
1815
1963
|
(_a = frameToTrack.contentDocument) == null ? void 0 : _a.addEventListener(`selectionchange`, () => {
|
|
1816
1964
|
var _a2;
|
|
1817
|
-
subject.next({
|
|
1965
|
+
subject.next({
|
|
1966
|
+
event: `selectionchange`,
|
|
1967
|
+
data: ((_a2 = frame == null ? void 0 : frame.contentWindow) == null ? void 0 : _a2.getSelection()) || null
|
|
1968
|
+
});
|
|
1818
1969
|
});
|
|
1819
1970
|
(_b = frameToTrack.contentWindow) == null ? void 0 : _b.addEventListener(`selectstart`, () => {
|
|
1820
1971
|
isSelecting = true;
|
|
@@ -1829,7 +1980,8 @@ const createSelectionTracker = () => {
|
|
|
1829
1980
|
getSelection: () => {
|
|
1830
1981
|
var _a;
|
|
1831
1982
|
const selection = (_a = frame == null ? void 0 : frame.contentWindow) == null ? void 0 : _a.getSelection();
|
|
1832
|
-
if (!(selection == null ? void 0 : selection.anchorNode) || selection.type === `None` || selection.type === `Caret`)
|
|
1983
|
+
if (!(selection == null ? void 0 : selection.anchorNode) || selection.type === `None` || selection.type === `Caret`)
|
|
1984
|
+
return void 0;
|
|
1833
1985
|
return selection;
|
|
1834
1986
|
},
|
|
1835
1987
|
$: subject.asObservable()
|
|
@@ -1844,7 +1996,11 @@ const createCommonSpineItem = ({
|
|
|
1844
1996
|
hookManager
|
|
1845
1997
|
}) => {
|
|
1846
1998
|
const destroySubject$ = new Subject();
|
|
1847
|
-
const containerElement = createContainerElement$1(
|
|
1999
|
+
const containerElement = createContainerElement$1(
|
|
2000
|
+
parentElement,
|
|
2001
|
+
item,
|
|
2002
|
+
hookManager
|
|
2003
|
+
);
|
|
1848
2004
|
const overlayElement = createOverlayElement(parentElement, item);
|
|
1849
2005
|
const fingerTracker = createFingerTracker();
|
|
1850
2006
|
const selectionTracker = createSelectionTracker();
|
|
@@ -1883,7 +2039,11 @@ const createCommonSpineItem = ({
|
|
|
1883
2039
|
(_a = spineItemFrame.getManipulableFrame()) == null ? void 0 : _a.removeStyle(`prose-reader-css`);
|
|
1884
2040
|
(_b = spineItemFrame.getManipulableFrame()) == null ? void 0 : _b.addStyle(`prose-reader-css`, cssText);
|
|
1885
2041
|
};
|
|
1886
|
-
const adjustPositionOfElement = ({
|
|
2042
|
+
const adjustPositionOfElement = ({
|
|
2043
|
+
right,
|
|
2044
|
+
left,
|
|
2045
|
+
top
|
|
2046
|
+
}) => {
|
|
1887
2047
|
if (right !== void 0) {
|
|
1888
2048
|
containerElement.style.right = `${right}px`;
|
|
1889
2049
|
} else {
|
|
@@ -1907,7 +2067,10 @@ const createCommonSpineItem = ({
|
|
|
1907
2067
|
const frameElement = (_a = spineItemFrame.getManipulableFrame()) == null ? void 0 : _a.frame;
|
|
1908
2068
|
if (containerElement && (frameElement == null ? void 0 : frameElement.contentDocument) && (frameElement == null ? void 0 : frameElement.contentWindow) && viewportDimensions) {
|
|
1909
2069
|
const computedWidthScale = pageWidth / viewportDimensions.width;
|
|
1910
|
-
const computedScale = Math.min(
|
|
2070
|
+
const computedScale = Math.min(
|
|
2071
|
+
computedWidthScale,
|
|
2072
|
+
pageHeight / viewportDimensions.height
|
|
2073
|
+
);
|
|
1911
2074
|
return { computedScale, computedWidthScale, viewportDimensions };
|
|
1912
2075
|
}
|
|
1913
2076
|
};
|
|
@@ -1960,7 +2123,11 @@ const createCommonSpineItem = ({
|
|
|
1960
2123
|
}) => {
|
|
1961
2124
|
containerElement.style.width = `${width}px`;
|
|
1962
2125
|
containerElement.style.height = `${height}px`;
|
|
1963
|
-
hookManager.execute(`item.onAfterLayout`, void 0, {
|
|
2126
|
+
hookManager.execute(`item.onAfterLayout`, void 0, {
|
|
2127
|
+
blankPagePosition,
|
|
2128
|
+
item,
|
|
2129
|
+
minimumWidth
|
|
2130
|
+
});
|
|
1964
2131
|
setLayoutDirty();
|
|
1965
2132
|
};
|
|
1966
2133
|
const translateFramePositionIntoPage = (position) => {
|
|
@@ -2174,8 +2341,14 @@ const createPrePaginatedSpineItem = ({
|
|
|
2174
2341
|
}
|
|
2175
2342
|
const transformTranslateX = spreadPosition !== `none` ? `0` : `-50%`;
|
|
2176
2343
|
const transformOriginX = spreadPosition === `right` && blankPagePosition !== `before` ? `left` : spreadPosition === `left` || blankPagePosition === `before` && context.isRTL() ? `right` : `center`;
|
|
2177
|
-
frameElement == null ? void 0 : frameElement.style.setProperty(
|
|
2178
|
-
|
|
2344
|
+
frameElement == null ? void 0 : frameElement.style.setProperty(
|
|
2345
|
+
`transform`,
|
|
2346
|
+
`translate(${transformTranslateX}, -50%) scale(${computedScale})`
|
|
2347
|
+
);
|
|
2348
|
+
frameElement == null ? void 0 : frameElement.style.setProperty(
|
|
2349
|
+
`transform-origin`,
|
|
2350
|
+
`${transformOriginX} center`
|
|
2351
|
+
);
|
|
2179
2352
|
commonSpineItem.executeOnLayoutBeforeMeasurementHook({ minimumWidth });
|
|
2180
2353
|
} else {
|
|
2181
2354
|
commonSpineItem.injectStyle(cssLink);
|
|
@@ -2195,11 +2368,21 @@ const createPrePaginatedSpineItem = ({
|
|
|
2195
2368
|
}
|
|
2196
2369
|
}
|
|
2197
2370
|
commonSpineItem.executeOnLayoutBeforeMeasurementHook({ minimumWidth });
|
|
2198
|
-
commonSpineItem.layout({
|
|
2371
|
+
commonSpineItem.layout({
|
|
2372
|
+
width: minimumWidth,
|
|
2373
|
+
height: contentHeight,
|
|
2374
|
+
blankPagePosition,
|
|
2375
|
+
minimumWidth
|
|
2376
|
+
});
|
|
2199
2377
|
return { width: minimumWidth, height: contentHeight };
|
|
2200
2378
|
} else {
|
|
2201
2379
|
commonSpineItem.executeOnLayoutBeforeMeasurementHook({ minimumWidth });
|
|
2202
|
-
commonSpineItem.layout({
|
|
2380
|
+
commonSpineItem.layout({
|
|
2381
|
+
width: minimumWidth,
|
|
2382
|
+
height: pageHeight,
|
|
2383
|
+
blankPagePosition,
|
|
2384
|
+
minimumWidth
|
|
2385
|
+
});
|
|
2203
2386
|
}
|
|
2204
2387
|
return { width: minimumWidth, height: pageHeight };
|
|
2205
2388
|
};
|
|
@@ -2328,19 +2511,27 @@ const createReflowableSpineItem = ({
|
|
|
2328
2511
|
`left`,
|
|
2329
2512
|
blankPagePosition === `before` ? context.isRTL() ? `25%` : `75%` : blankPagePosition === `after` ? context.isRTL() ? `75%` : `25%` : `50%`
|
|
2330
2513
|
);
|
|
2331
|
-
frameElement == null ? void 0 : frameElement.style.setProperty(
|
|
2514
|
+
frameElement == null ? void 0 : frameElement.style.setProperty(
|
|
2515
|
+
`transform`,
|
|
2516
|
+
`translate(-50%, -50%) scale(${computedScale})`
|
|
2517
|
+
);
|
|
2332
2518
|
frameElement == null ? void 0 : frameElement.style.setProperty(`transform-origin`, `center center`);
|
|
2333
2519
|
} else {
|
|
2334
2520
|
const frameStyle = commonSpineItem.isImageType() ? buildStyleForReflowableImageOnly({
|
|
2335
2521
|
isScrollable: ((_g = context.manifest) == null ? void 0 : _g.renditionFlow) === `scrolled-continuous`,
|
|
2336
2522
|
enableTouch: settings.settings.computedPageTurnMode !== `scrollable`
|
|
2337
2523
|
}) : buildStyleWithMultiColumn(
|
|
2338
|
-
commonSpineItem.getDimensionsForReflowableContent(
|
|
2524
|
+
commonSpineItem.getDimensionsForReflowableContent(
|
|
2525
|
+
spineItemFrame.isUsingVerticalWriting(),
|
|
2526
|
+
minimumWidth
|
|
2527
|
+
)
|
|
2339
2528
|
);
|
|
2340
2529
|
commonSpineItem.injectStyle(frameStyle);
|
|
2341
2530
|
commonSpineItem.executeOnLayoutBeforeMeasurementHook({ minimumWidth });
|
|
2342
2531
|
if (spineItemFrame.isUsingVerticalWriting()) {
|
|
2343
|
-
const pages = Math.ceil(
|
|
2532
|
+
const pages = Math.ceil(
|
|
2533
|
+
frameElement.contentDocument.documentElement.scrollHeight / pageHeight
|
|
2534
|
+
);
|
|
2344
2535
|
contentHeight = pages * pageHeight;
|
|
2345
2536
|
spineItemFrame.staticLayout({
|
|
2346
2537
|
width: minimumWidth,
|
|
@@ -2354,7 +2545,9 @@ const createReflowableSpineItem = ({
|
|
|
2354
2545
|
height: contentHeight
|
|
2355
2546
|
});
|
|
2356
2547
|
} else {
|
|
2357
|
-
const pages = Math.ceil(
|
|
2548
|
+
const pages = Math.ceil(
|
|
2549
|
+
frameElement.contentDocument.documentElement.scrollWidth / pageWidth
|
|
2550
|
+
);
|
|
2358
2551
|
if (isGloballyPrePaginated) {
|
|
2359
2552
|
contentWidth = pageWidth;
|
|
2360
2553
|
} else {
|
|
@@ -2375,13 +2568,23 @@ const createReflowableSpineItem = ({
|
|
|
2375
2568
|
} else {
|
|
2376
2569
|
frameElement == null ? void 0 : frameElement.style.setProperty(`margin-left`, `0px`);
|
|
2377
2570
|
}
|
|
2378
|
-
commonSpineItem.layout({
|
|
2571
|
+
commonSpineItem.layout({
|
|
2572
|
+
width: contentWidth,
|
|
2573
|
+
height: contentHeight,
|
|
2574
|
+
blankPagePosition,
|
|
2575
|
+
minimumWidth
|
|
2576
|
+
});
|
|
2379
2577
|
return { width: contentWidth, height: contentHeight };
|
|
2380
2578
|
} else {
|
|
2381
2579
|
commonSpineItem.executeOnLayoutBeforeMeasurementHook({ minimumWidth });
|
|
2382
2580
|
}
|
|
2383
2581
|
const height = latestContentHeightWhenLoaded || pageHeight;
|
|
2384
|
-
commonSpineItem.layout({
|
|
2582
|
+
commonSpineItem.layout({
|
|
2583
|
+
width: minimumWidth,
|
|
2584
|
+
height,
|
|
2585
|
+
blankPagePosition,
|
|
2586
|
+
minimumWidth
|
|
2587
|
+
});
|
|
2385
2588
|
return { width: minimumWidth, height };
|
|
2386
2589
|
};
|
|
2387
2590
|
return {
|
|
@@ -2701,7 +2904,10 @@ class CFI {
|
|
|
2701
2904
|
while (str.length) {
|
|
2702
2905
|
({ parsed, offset, newDoc } = this.parse(str));
|
|
2703
2906
|
if (!parsed || offset === null) throw new Error(`Parsing failed`);
|
|
2704
|
-
if (sawComma && newDoc)
|
|
2907
|
+
if (sawComma && newDoc)
|
|
2908
|
+
throw new Error(
|
|
2909
|
+
`CFI is a range that spans multiple documents. This is not allowed`
|
|
2910
|
+
);
|
|
2705
2911
|
subParts.push(parsed);
|
|
2706
2912
|
if (newDoc || str.length - offset <= 0) {
|
|
2707
2913
|
if (sawComma === 2) {
|
|
@@ -2769,7 +2975,8 @@ class CFI {
|
|
|
2769
2975
|
while (node.parentNode) {
|
|
2770
2976
|
o = calcSiblingCount(node.parentNode.childNodes, node, offset);
|
|
2771
2977
|
if (!cfi && o.offset) cfi = `:` + o.offset;
|
|
2772
|
-
cfi =
|
|
2978
|
+
cfi = // @ts-ignore
|
|
2979
|
+
`/` + o.count + (node.id ? `[` + cfiEscape(node.id) + `]` : ``) + cfi;
|
|
2773
2980
|
node = node.parentNode;
|
|
2774
2981
|
}
|
|
2775
2982
|
return cfi;
|
|
@@ -2872,7 +3079,8 @@ class CFI {
|
|
|
2872
3079
|
return this.decodeEntities(dom, str).length;
|
|
2873
3080
|
}
|
|
2874
3081
|
getFrom() {
|
|
2875
|
-
if (!this.isRange)
|
|
3082
|
+
if (!this.isRange)
|
|
3083
|
+
throw new Error(`Trying to get beginning of non-range CFI`);
|
|
2876
3084
|
if (!this.from) {
|
|
2877
3085
|
return this.deepClone(this.parts);
|
|
2878
3086
|
}
|
|
@@ -3057,10 +3265,13 @@ class CFI {
|
|
|
3057
3265
|
}
|
|
3058
3266
|
if (cur === `:` || cur === `~` || cur === `@`) {
|
|
3059
3267
|
if (this.opts.stricter) {
|
|
3060
|
-
if (cur === `:` &&
|
|
3268
|
+
if (cur === `:` && // @ts-ignore
|
|
3269
|
+
(typeof o.temporal !== `undefined` || // @ts-ignore
|
|
3270
|
+
typeof o.spatial !== `undefined`)) {
|
|
3061
3271
|
break;
|
|
3062
3272
|
}
|
|
3063
|
-
if ((cur === `~` || cur === `@`) &&
|
|
3273
|
+
if ((cur === `~` || cur === `@`) && // @ts-ignore
|
|
3274
|
+
typeof o.offset !== `undefined`) {
|
|
3064
3275
|
break;
|
|
3065
3276
|
}
|
|
3066
3277
|
}
|
|
@@ -3123,7 +3334,8 @@ class CFI {
|
|
|
3123
3334
|
}
|
|
3124
3335
|
escape = false;
|
|
3125
3336
|
}
|
|
3126
|
-
if (!o.nodeIndex && o.nodeIndex !== 0)
|
|
3337
|
+
if (!o.nodeIndex && o.nodeIndex !== 0)
|
|
3338
|
+
throw new Error(`Missing child node index in CFI`);
|
|
3127
3339
|
return { parsed: o, offset: i, newDoc: state === `!` };
|
|
3128
3340
|
}
|
|
3129
3341
|
// The CFI counts child nodes differently from the DOM
|
|
@@ -3161,7 +3373,11 @@ class CFI {
|
|
|
3161
3373
|
if (!lastChild) {
|
|
3162
3374
|
return { node: parentNode, offset: 0 };
|
|
3163
3375
|
}
|
|
3164
|
-
return {
|
|
3376
|
+
return {
|
|
3377
|
+
node: lastChild,
|
|
3378
|
+
// @ts-ignore
|
|
3379
|
+
offset: this.trueLength(dom, lastChild.textContent)
|
|
3380
|
+
};
|
|
3165
3381
|
}
|
|
3166
3382
|
}
|
|
3167
3383
|
lastChild = child;
|
|
@@ -3248,7 +3464,8 @@ class CFI {
|
|
|
3248
3464
|
newOffset -= nodeLengths[i];
|
|
3249
3465
|
if (newOffset < 0) return { node, offset };
|
|
3250
3466
|
const nodeOffsets = [];
|
|
3251
|
-
if (!curNode.nextSibling || i + 1 >= nodeOffsets.length)
|
|
3467
|
+
if (!curNode.nextSibling || i + 1 >= nodeOffsets.length)
|
|
3468
|
+
return { node, offset };
|
|
3252
3469
|
i++;
|
|
3253
3470
|
curNode = curNode.nextSibling;
|
|
3254
3471
|
}
|
|
@@ -3277,7 +3494,12 @@ class CFI {
|
|
|
3277
3494
|
let subpart;
|
|
3278
3495
|
for (i = subparts.length - 1; i >= 0; i--) {
|
|
3279
3496
|
subpart = subparts[i];
|
|
3280
|
-
if (
|
|
3497
|
+
if (
|
|
3498
|
+
// @ts-ignore
|
|
3499
|
+
!opts.ignoreIDs && // @ts-ignore
|
|
3500
|
+
subpart.nodeID && // @ts-ignore
|
|
3501
|
+
(node = dom.getElementById(subpart.nodeID))
|
|
3502
|
+
) {
|
|
3281
3503
|
startFrom = i + 1;
|
|
3282
3504
|
break;
|
|
3283
3505
|
}
|
|
@@ -3289,9 +3511,22 @@ class CFI {
|
|
|
3289
3511
|
for (i = startFrom; i < subparts.length; i++) {
|
|
3290
3512
|
subpart = subparts[i];
|
|
3291
3513
|
if (subpart) {
|
|
3292
|
-
o = this.getChildNodeByCFIIndex(
|
|
3514
|
+
o = this.getChildNodeByCFIIndex(
|
|
3515
|
+
dom,
|
|
3516
|
+
// @ts-ignore
|
|
3517
|
+
o.node,
|
|
3518
|
+
subpart.nodeIndex,
|
|
3519
|
+
subpart.offset
|
|
3520
|
+
);
|
|
3293
3521
|
if (subpart.textLocationAssertion) {
|
|
3294
|
-
o = this.correctOffset(
|
|
3522
|
+
o = this.correctOffset(
|
|
3523
|
+
dom,
|
|
3524
|
+
// @ts-ignore
|
|
3525
|
+
o.node,
|
|
3526
|
+
subpart.offset,
|
|
3527
|
+
// @ts-ignore
|
|
3528
|
+
subpart.textLocationAssertion
|
|
3529
|
+
);
|
|
3295
3530
|
}
|
|
3296
3531
|
}
|
|
3297
3532
|
}
|
|
@@ -3333,12 +3568,14 @@ class CFI {
|
|
|
3333
3568
|
}
|
|
3334
3569
|
if (tagName === `object`) {
|
|
3335
3570
|
const data = node.getAttribute(`data`);
|
|
3336
|
-
if (!data)
|
|
3571
|
+
if (!data)
|
|
3572
|
+
throw new Error(tagName + ` element is missing 'data' attribute`);
|
|
3337
3573
|
return data;
|
|
3338
3574
|
}
|
|
3339
3575
|
if (tagName === `image` || tagName === `use`) {
|
|
3340
3576
|
const href = node.getAttribute(`xlink:href`);
|
|
3341
|
-
if (!href)
|
|
3577
|
+
if (!href)
|
|
3578
|
+
throw new Error(tagName + ` element is missing 'xlink:href' attribute`);
|
|
3342
3579
|
return href;
|
|
3343
3580
|
}
|
|
3344
3581
|
throw new Error(`No URI found`);
|
|
@@ -3510,17 +3747,26 @@ const createSpine = ({
|
|
|
3510
3747
|
spineItemsFromPosition.beginPosition,
|
|
3511
3748
|
beginSpineItem
|
|
3512
3749
|
);
|
|
3513
|
-
const beginPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3750
|
+
const beginPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3751
|
+
beginPosition,
|
|
3752
|
+
beginSpineItem
|
|
3753
|
+
);
|
|
3514
3754
|
const endPosition = spineLocator.getSpineItemPositionFromSpinePosition(
|
|
3515
3755
|
spineItemsFromPosition.endPosition,
|
|
3516
3756
|
endSpineItem
|
|
3517
3757
|
);
|
|
3518
|
-
const endPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3758
|
+
const endPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3759
|
+
endPosition,
|
|
3760
|
+
endSpineItem
|
|
3761
|
+
);
|
|
3519
3762
|
pagination.updateBeginAndEnd(
|
|
3520
3763
|
{
|
|
3521
3764
|
spineItem: beginSpineItem,
|
|
3522
3765
|
spineItemIndex: spineItemManager.getSpineItemIndex(beginSpineItem) ?? 0,
|
|
3523
|
-
pageIndex: spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3766
|
+
pageIndex: spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3767
|
+
beginPosition,
|
|
3768
|
+
beginSpineItem
|
|
3769
|
+
),
|
|
3524
3770
|
cfi: shouldUpdateBeginCfi ? cfiLocator.getCfi(beginPageIndex, beginSpineItem) : beginLastCfi,
|
|
3525
3771
|
options: {
|
|
3526
3772
|
isAtEndOfChapter: false
|
|
@@ -3529,7 +3775,10 @@ const createSpine = ({
|
|
|
3529
3775
|
{
|
|
3530
3776
|
spineItem: endSpineItem,
|
|
3531
3777
|
spineItemIndex: spineItemManager.getSpineItemIndex(endSpineItem) ?? 0,
|
|
3532
|
-
pageIndex: spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3778
|
+
pageIndex: spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3779
|
+
endPosition,
|
|
3780
|
+
endSpineItem
|
|
3781
|
+
),
|
|
3533
3782
|
cfi: shouldUpdateEndCfi ? cfiLocator.getCfi(endPageIndex, endSpineItem) : endLastCfi,
|
|
3534
3783
|
options: {
|
|
3535
3784
|
isAtEndOfChapter: false
|
|
@@ -3566,7 +3815,11 @@ const createSpine = ({
|
|
|
3566
3815
|
() => fingerTracker$.pipe(
|
|
3567
3816
|
filter(({ event: event2 }) => event2 === `fingermove`),
|
|
3568
3817
|
debounce(() => interval(1e3)),
|
|
3569
|
-
takeUntil$1(
|
|
3818
|
+
takeUntil$1(
|
|
3819
|
+
fingerTracker$.pipe(
|
|
3820
|
+
filter(({ event: event2 }) => event2 === `fingerout`)
|
|
3821
|
+
)
|
|
3822
|
+
),
|
|
3570
3823
|
tap(({ data }) => {
|
|
3571
3824
|
})
|
|
3572
3825
|
)
|
|
@@ -3603,12 +3856,18 @@ const createSpine = ({
|
|
|
3603
3856
|
spineItemsFromPosition.beginPosition,
|
|
3604
3857
|
beginSpineItem
|
|
3605
3858
|
);
|
|
3606
|
-
const beginPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3859
|
+
const beginPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3860
|
+
beginPosition,
|
|
3861
|
+
beginSpineItem
|
|
3862
|
+
);
|
|
3607
3863
|
const endPosition = spineLocator.getSpineItemPositionFromSpinePosition(
|
|
3608
3864
|
spineItemsFromPosition.endPosition,
|
|
3609
3865
|
endSpineItem
|
|
3610
3866
|
);
|
|
3611
|
-
const endPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3867
|
+
const endPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3868
|
+
endPosition,
|
|
3869
|
+
endSpineItem
|
|
3870
|
+
);
|
|
3612
3871
|
const endItemIndex = spineItemManager.getSpineItemIndex(endSpineItem) ?? 0;
|
|
3613
3872
|
pagination.updateBeginAndEnd(
|
|
3614
3873
|
{
|
|
@@ -3667,7 +3926,9 @@ const createSpine = ({
|
|
|
3667
3926
|
);
|
|
3668
3927
|
itemUpdateOnNavigation$.pipe(
|
|
3669
3928
|
switchMap$1((data) => {
|
|
3670
|
-
return adjustPagination(data.position).pipe(
|
|
3929
|
+
return adjustPagination(data.position).pipe(
|
|
3930
|
+
takeUntil$1(spineItemManager.$.layout$)
|
|
3931
|
+
);
|
|
3671
3932
|
}),
|
|
3672
3933
|
takeUntil$1(context.destroy$)
|
|
3673
3934
|
).subscribe();
|
|
@@ -3691,10 +3952,20 @@ const createSpine = ({
|
|
|
3691
3952
|
const focusedSpineItemIndex = spineItemManager.getFocusedSpineItemIndex();
|
|
3692
3953
|
report.log(`update contents`, { focusedSpineItemIndex });
|
|
3693
3954
|
if (focusedSpineItemIndex === void 0) return;
|
|
3694
|
-
const {
|
|
3955
|
+
const {
|
|
3956
|
+
begin = focusedSpineItemIndex,
|
|
3957
|
+
end = focusedSpineItemIndex
|
|
3958
|
+
} = spineLocator.getSpineItemsFromReadingOrderPosition(
|
|
3959
|
+
currentNavigationPosition
|
|
3960
|
+
) || {};
|
|
3695
3961
|
if (begin !== focusedSpineItemIndex && end !== focusedSpineItemIndex) {
|
|
3696
|
-
Report.warn(
|
|
3697
|
-
|
|
3962
|
+
Report.warn(
|
|
3963
|
+
`Current viewport is not in sync with focus item, load from focus item rather than viewport`
|
|
3964
|
+
);
|
|
3965
|
+
spineItemManager.loadContents([
|
|
3966
|
+
focusedSpineItemIndex,
|
|
3967
|
+
focusedSpineItemIndex
|
|
3968
|
+
]);
|
|
3698
3969
|
} else {
|
|
3699
3970
|
spineItemManager.loadContents([begin, end]);
|
|
3700
3971
|
}
|
|
@@ -3753,7 +4024,10 @@ const createContainerElement = (doc) => {
|
|
|
3753
4024
|
return element;
|
|
3754
4025
|
};
|
|
3755
4026
|
const NAMESPACE$4 = `spineItemManager`;
|
|
3756
|
-
const createSpineItemManager = ({
|
|
4027
|
+
const createSpineItemManager = ({
|
|
4028
|
+
context,
|
|
4029
|
+
settings
|
|
4030
|
+
}) => {
|
|
3757
4031
|
const focus$ = new Subject();
|
|
3758
4032
|
const layout$ = new Subject();
|
|
3759
4033
|
let itemLayoutInformation = [];
|
|
@@ -3864,30 +4138,36 @@ const createSpineItemManager = ({ context, settings }) => {
|
|
|
3864
4138
|
focusedSpineItemIndex = newActiveSpineItemIndex;
|
|
3865
4139
|
focus$.next({ data: spineItemToFocus });
|
|
3866
4140
|
};
|
|
3867
|
-
const loadContents = Report.measurePerformance(
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
const
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
4141
|
+
const loadContents = Report.measurePerformance(
|
|
4142
|
+
`loadContents`,
|
|
4143
|
+
10,
|
|
4144
|
+
(rangeOfIndex) => {
|
|
4145
|
+
var _a;
|
|
4146
|
+
const [leftIndex, rightIndex] = rangeOfIndex;
|
|
4147
|
+
const numberOfAdjacentSpineItemToPreLoad = settings.settings.numberOfAdjacentSpineItemToPreLoad;
|
|
4148
|
+
const isPrePaginated = ((_a = context.manifest) == null ? void 0 : _a.renditionLayout) === `pre-paginated`;
|
|
4149
|
+
const isUsingFreeScroll = settings.settings.computedPageTurnMode === `scrollable`;
|
|
4150
|
+
orderedSpineItemsSubject$.value.forEach((orderedSpineItem, index) => {
|
|
4151
|
+
const isBeforeFocusedWithPreload = (
|
|
4152
|
+
// we never want to preload anything before on free scroll on flow because it could offset the cursor
|
|
4153
|
+
index < leftIndex && !isPrePaginated && isUsingFreeScroll ? true : index < leftIndex - numberOfAdjacentSpineItemToPreLoad
|
|
4154
|
+
);
|
|
4155
|
+
const isAfterTailWithPreload = index > rightIndex + numberOfAdjacentSpineItemToPreLoad;
|
|
4156
|
+
if (!isBeforeFocusedWithPreload && !isAfterTailWithPreload) {
|
|
4157
|
+
orderedSpineItem.loadContent();
|
|
4158
|
+
} else {
|
|
4159
|
+
orderedSpineItem.unloadContent();
|
|
4160
|
+
}
|
|
4161
|
+
});
|
|
4162
|
+
}
|
|
4163
|
+
);
|
|
3886
4164
|
const get = (indexOrId) => {
|
|
3887
4165
|
if (typeof indexOrId === `number`) {
|
|
3888
4166
|
return orderedSpineItemsSubject$.value[indexOrId];
|
|
3889
4167
|
}
|
|
3890
|
-
return orderedSpineItemsSubject$.value.find(
|
|
4168
|
+
return orderedSpineItemsSubject$.value.find(
|
|
4169
|
+
({ item }) => item.id === indexOrId
|
|
4170
|
+
);
|
|
3891
4171
|
};
|
|
3892
4172
|
const getAbsolutePositionOf = (spineItemOrIndex) => {
|
|
3893
4173
|
const indexOfItem = typeof spineItemOrIndex === `number` ? spineItemOrIndex : orderedSpineItemsSubject$.value.indexOf(spineItemOrIndex);
|
|
@@ -3972,7 +4252,9 @@ const createSpineItemManager = ({ context, settings }) => {
|
|
|
3972
4252
|
itemIsReady$: orderedSpineItemsSubject$.asObservable().pipe(
|
|
3973
4253
|
switchMap$1((items) => {
|
|
3974
4254
|
const itemsIsReady$ = items.map(
|
|
3975
|
-
(item) => item.$.isReady$.pipe(
|
|
4255
|
+
(item) => item.$.isReady$.pipe(
|
|
4256
|
+
map((isReady) => ({ item: item.item, isReady }))
|
|
4257
|
+
)
|
|
3976
4258
|
);
|
|
3977
4259
|
return merge(...itemsIsReady$);
|
|
3978
4260
|
})
|
|
@@ -4043,7 +4325,10 @@ const getFirstVisibleNodeForViewport = Report.measurePerformance(
|
|
|
4043
4325
|
);
|
|
4044
4326
|
const getFirstVisibleElementForViewport = (element, viewport) => {
|
|
4045
4327
|
let lastValidElement;
|
|
4046
|
-
const positionFromViewport = getElementOrNodePositionFromViewPort(
|
|
4328
|
+
const positionFromViewport = getElementOrNodePositionFromViewPort(
|
|
4329
|
+
element.getBoundingClientRect(),
|
|
4330
|
+
viewport
|
|
4331
|
+
);
|
|
4047
4332
|
if (positionFromViewport !== `before` && positionFromViewport !== `after`) {
|
|
4048
4333
|
lastValidElement = element;
|
|
4049
4334
|
}
|
|
@@ -4059,7 +4344,8 @@ const getFirstVisibleElementForViewport = (element, viewport) => {
|
|
|
4059
4344
|
};
|
|
4060
4345
|
function getElementOrNodePositionFromViewPort(domRect, { left, right }) {
|
|
4061
4346
|
if (domRect.left <= left && domRect.right <= left) return `before`;
|
|
4062
|
-
if (domRect.left <= left && domRect.right > left && domRect.right <= right)
|
|
4347
|
+
if (domRect.left <= left && domRect.right > left && domRect.right <= right)
|
|
4348
|
+
return `partially-before`;
|
|
4063
4349
|
if (domRect.left <= right && domRect.right > right) return `partially-after`;
|
|
4064
4350
|
if (domRect.left > right) return `after`;
|
|
4065
4351
|
return `within`;
|
|
@@ -4143,19 +4429,33 @@ const isTouchEvent = (event) => {
|
|
|
4143
4429
|
};
|
|
4144
4430
|
const createLocationResolver$1 = ({ context }) => {
|
|
4145
4431
|
const getSafePosition = (unsafeSpineItemPosition, spineItem) => ({
|
|
4146
|
-
x: Math.min(
|
|
4147
|
-
|
|
4432
|
+
x: Math.min(
|
|
4433
|
+
spineItem.getElementDimensions().width,
|
|
4434
|
+
Math.max(0, unsafeSpineItemPosition.x)
|
|
4435
|
+
),
|
|
4436
|
+
y: Math.min(
|
|
4437
|
+
spineItem.getElementDimensions().height,
|
|
4438
|
+
Math.max(0, unsafeSpineItemPosition.y)
|
|
4439
|
+
)
|
|
4148
4440
|
});
|
|
4149
4441
|
const getSpineItemPositionFromPageIndex = (pageIndex, spineItem) => {
|
|
4150
4442
|
const { width: itemWidth, height: itemHeight } = spineItem.getElementDimensions();
|
|
4151
4443
|
if (spineItem.isUsingVerticalWriting()) {
|
|
4152
|
-
const ltrRelativeOffset2 = getItemOffsetFromPageIndex(
|
|
4444
|
+
const ltrRelativeOffset2 = getItemOffsetFromPageIndex(
|
|
4445
|
+
context.getPageSize().height,
|
|
4446
|
+
pageIndex,
|
|
4447
|
+
itemHeight
|
|
4448
|
+
);
|
|
4153
4449
|
return {
|
|
4154
4450
|
x: 0,
|
|
4155
4451
|
y: ltrRelativeOffset2
|
|
4156
4452
|
};
|
|
4157
4453
|
}
|
|
4158
|
-
const ltrRelativeOffset = getItemOffsetFromPageIndex(
|
|
4454
|
+
const ltrRelativeOffset = getItemOffsetFromPageIndex(
|
|
4455
|
+
context.getPageSize().width,
|
|
4456
|
+
pageIndex,
|
|
4457
|
+
itemWidth
|
|
4458
|
+
);
|
|
4159
4459
|
if (context.isRTL()) {
|
|
4160
4460
|
return {
|
|
4161
4461
|
x: itemWidth - ltrRelativeOffset - context.getPageSize().width,
|
|
@@ -4174,7 +4474,10 @@ const createLocationResolver$1 = ({ context }) => {
|
|
|
4174
4474
|
const safePosition = getSafePosition(position, spineItem);
|
|
4175
4475
|
const offset = context.isRTL() ? itemWidth - safePosition.x - context.getPageSize().width : safePosition.x;
|
|
4176
4476
|
if (spineItem.isUsingVerticalWriting()) {
|
|
4177
|
-
const numberOfPages = calculateNumberOfPagesForItem(
|
|
4477
|
+
const numberOfPages = calculateNumberOfPagesForItem(
|
|
4478
|
+
itemHeight,
|
|
4479
|
+
pageHeight
|
|
4480
|
+
);
|
|
4178
4481
|
return getPageFromOffset(position.y, pageHeight, numberOfPages);
|
|
4179
4482
|
} else {
|
|
4180
4483
|
const numberOfPages = calculateNumberOfPagesForItem(itemWidth, pageWidth);
|
|
@@ -4188,7 +4491,11 @@ const createLocationResolver$1 = ({ context }) => {
|
|
|
4188
4491
|
const pageWidth = context.getPageSize().width;
|
|
4189
4492
|
const anchorElementBoundingRect = spineItem.getBoundingRectOfElementFromSelector(anchor);
|
|
4190
4493
|
const offsetOfAnchor = (anchorElementBoundingRect == null ? void 0 : anchorElementBoundingRect.x) || 0;
|
|
4191
|
-
return getClosestValidOffsetFromApproximateOffsetInPages(
|
|
4494
|
+
return getClosestValidOffsetFromApproximateOffsetInPages(
|
|
4495
|
+
offsetOfAnchor,
|
|
4496
|
+
pageWidth,
|
|
4497
|
+
itemWidth
|
|
4498
|
+
);
|
|
4192
4499
|
};
|
|
4193
4500
|
const getSpineItemPositionFromNode = (node, offset, spineItem) => {
|
|
4194
4501
|
var _a;
|
|
@@ -4202,7 +4509,11 @@ const createLocationResolver$1 = ({ context }) => {
|
|
|
4202
4509
|
const spineItemWidth = ((_a = spineItem.getElementDimensions()) == null ? void 0 : _a.width) || 0;
|
|
4203
4510
|
const pageWidth = context.getPageSize().width;
|
|
4204
4511
|
if (offsetOfNodeInSpineItem) {
|
|
4205
|
-
const val = getClosestValidOffsetFromApproximateOffsetInPages(
|
|
4512
|
+
const val = getClosestValidOffsetFromApproximateOffsetInPages(
|
|
4513
|
+
offsetOfNodeInSpineItem,
|
|
4514
|
+
pageWidth,
|
|
4515
|
+
spineItemWidth
|
|
4516
|
+
);
|
|
4206
4517
|
return { x: val, y: 0 };
|
|
4207
4518
|
}
|
|
4208
4519
|
return void 0;
|
|
@@ -4213,14 +4524,20 @@ const createLocationResolver$1 = ({ context }) => {
|
|
|
4213
4524
|
const frame = (_b = (_a = spineItem.spineItemFrame) == null ? void 0 : _a.getManipulableFrame()) == null ? void 0 : _b.frame;
|
|
4214
4525
|
if (((_c = frame == null ? void 0 : frame.contentWindow) == null ? void 0 : _c.document) && // very important because it is being used by next functions
|
|
4215
4526
|
frame.contentWindow.document.body !== null) {
|
|
4216
|
-
const { x: left, y: top } = getSpineItemPositionFromPageIndex(
|
|
4527
|
+
const { x: left, y: top } = getSpineItemPositionFromPageIndex(
|
|
4528
|
+
pageIndex,
|
|
4529
|
+
spineItem
|
|
4530
|
+
);
|
|
4217
4531
|
const viewport = {
|
|
4218
4532
|
left,
|
|
4219
4533
|
right: left + pageSize.width,
|
|
4220
4534
|
top,
|
|
4221
4535
|
bottom: top + pageSize.height
|
|
4222
4536
|
};
|
|
4223
|
-
const res = getFirstVisibleNodeForViewport(
|
|
4537
|
+
const res = getFirstVisibleNodeForViewport(
|
|
4538
|
+
frame.contentWindow.document,
|
|
4539
|
+
viewport
|
|
4540
|
+
);
|
|
4224
4541
|
return res;
|
|
4225
4542
|
}
|
|
4226
4543
|
return void 0;
|
|
@@ -4228,8 +4545,16 @@ const createLocationResolver$1 = ({ context }) => {
|
|
|
4228
4545
|
const getSpineItemClosestPositionFromUnsafePosition = (unsafePosition, spineItem) => {
|
|
4229
4546
|
const { width, height } = spineItem.getElementDimensions();
|
|
4230
4547
|
const adjustedPosition = {
|
|
4231
|
-
x: getClosestValidOffsetFromApproximateOffsetInPages(
|
|
4232
|
-
|
|
4548
|
+
x: getClosestValidOffsetFromApproximateOffsetInPages(
|
|
4549
|
+
unsafePosition.x,
|
|
4550
|
+
context.getPageSize().width,
|
|
4551
|
+
width
|
|
4552
|
+
),
|
|
4553
|
+
y: getClosestValidOffsetFromApproximateOffsetInPages(
|
|
4554
|
+
unsafePosition.y,
|
|
4555
|
+
context.getPageSize().height,
|
|
4556
|
+
height
|
|
4557
|
+
)
|
|
4233
4558
|
};
|
|
4234
4559
|
return adjustedPosition;
|
|
4235
4560
|
};
|
|
@@ -4263,7 +4588,9 @@ class SpineItemNavigationPosition {
|
|
|
4263
4588
|
this.y = position.y;
|
|
4264
4589
|
}
|
|
4265
4590
|
}
|
|
4266
|
-
const createNavigationResolver$1 = ({
|
|
4591
|
+
const createNavigationResolver$1 = ({
|
|
4592
|
+
context
|
|
4593
|
+
}) => {
|
|
4267
4594
|
const spineItemLocator = createLocationResolver$1({ context });
|
|
4268
4595
|
const getNavigationForLeftPage = (position, spineItem) => {
|
|
4269
4596
|
let nextPotentialPosition = {
|
|
@@ -4302,20 +4629,33 @@ const createNavigationResolver$1 = ({ context }) => {
|
|
|
4302
4629
|
const getNavigationForLastPage = (spineItem) => {
|
|
4303
4630
|
if (spineItem.isUsingVerticalWriting()) {
|
|
4304
4631
|
const pageHeight = context.getPageSize().height;
|
|
4305
|
-
const numberOfPages = calculateNumberOfPagesForItem(
|
|
4632
|
+
const numberOfPages = calculateNumberOfPagesForItem(
|
|
4633
|
+
spineItem.getElementDimensions().height,
|
|
4634
|
+
pageHeight
|
|
4635
|
+
);
|
|
4306
4636
|
return getNavigationForPage(numberOfPages - 1, spineItem);
|
|
4307
4637
|
} else {
|
|
4308
4638
|
const pageWidth = context.getPageSize().width;
|
|
4309
|
-
const numberOfPages = calculateNumberOfPagesForItem(
|
|
4639
|
+
const numberOfPages = calculateNumberOfPagesForItem(
|
|
4640
|
+
spineItem.getElementDimensions().width,
|
|
4641
|
+
pageWidth
|
|
4642
|
+
);
|
|
4310
4643
|
return getNavigationForPage(numberOfPages - 1, spineItem);
|
|
4311
4644
|
}
|
|
4312
4645
|
};
|
|
4313
4646
|
const getNavigationForPage = (pageIndex, spineItem) => {
|
|
4314
|
-
const { x, y } = spineItemLocator.getSpineItemPositionFromPageIndex(
|
|
4647
|
+
const { x, y } = spineItemLocator.getSpineItemPositionFromPageIndex(
|
|
4648
|
+
pageIndex,
|
|
4649
|
+
spineItem
|
|
4650
|
+
);
|
|
4315
4651
|
return new SpineItemNavigationPosition({ x, y });
|
|
4316
4652
|
};
|
|
4317
4653
|
const getNavigationFromNode = (spineItem, node, offset) => {
|
|
4318
|
-
const position = spineItemLocator.getSpineItemPositionFromNode(
|
|
4654
|
+
const position = spineItemLocator.getSpineItemPositionFromNode(
|
|
4655
|
+
node,
|
|
4656
|
+
offset,
|
|
4657
|
+
spineItem
|
|
4658
|
+
);
|
|
4319
4659
|
return new SpineItemNavigationPosition(position || { x: 0, y: 0 });
|
|
4320
4660
|
};
|
|
4321
4661
|
const getNavigationForPosition = (spineItem, position) => {
|
|
@@ -4349,8 +4689,12 @@ const createNavigationResolver = ({
|
|
|
4349
4689
|
`${NAMESPACE$3} wrapPositionWithSafeEdge`,
|
|
4350
4690
|
1,
|
|
4351
4691
|
(position) => {
|
|
4352
|
-
const lastSpineItem = spineItemManager.get(
|
|
4353
|
-
|
|
4692
|
+
const lastSpineItem = spineItemManager.get(
|
|
4693
|
+
spineItemManager.getLength() - 1
|
|
4694
|
+
);
|
|
4695
|
+
const distanceOfLastSpineItem = spineItemManager.getAbsolutePositionOf(
|
|
4696
|
+
lastSpineItem || 0
|
|
4697
|
+
);
|
|
4354
4698
|
const maximumYOffset = distanceOfLastSpineItem.bottom - context.getPageSize().height;
|
|
4355
4699
|
const y = Math.min(Math.max(0, position.y), maximumYOffset);
|
|
4356
4700
|
if (context.isRTL()) {
|
|
@@ -4367,7 +4711,10 @@ const createNavigationResolver = ({
|
|
|
4367
4711
|
},
|
|
4368
4712
|
{ disable: true }
|
|
4369
4713
|
);
|
|
4370
|
-
const getAdjustedPositionForSpread = ({
|
|
4714
|
+
const getAdjustedPositionForSpread = ({
|
|
4715
|
+
x,
|
|
4716
|
+
y
|
|
4717
|
+
}) => {
|
|
4371
4718
|
const isOffsetNotAtEdge = x % context.state.visibleAreaRect.width !== 0;
|
|
4372
4719
|
const correctedX = isOffsetNotAtEdge ? x - context.getPageSize().width : x;
|
|
4373
4720
|
return { x: correctedX, y };
|
|
@@ -4379,7 +4726,10 @@ const createNavigationResolver = ({
|
|
|
4379
4726
|
Report.warn(NAMESPACE$3, `unable to detect item id from cfi ${cfi}`);
|
|
4380
4727
|
} else {
|
|
4381
4728
|
const spineItemNavigation = node ? spineItemNavigator.getNavigationFromNode(spineItem, node, offset) : new SpineItemNavigationPosition({ x: 0, y: 0 });
|
|
4382
|
-
const readingPosition = locator.getSpinePositionFromSpineItemPosition(
|
|
4729
|
+
const readingPosition = locator.getSpinePositionFromSpineItemPosition(
|
|
4730
|
+
spineItemNavigation,
|
|
4731
|
+
spineItem
|
|
4732
|
+
);
|
|
4383
4733
|
return { ...getAdjustedPositionForSpread(readingPosition), spineItem };
|
|
4384
4734
|
}
|
|
4385
4735
|
return { x: 0, y: 0 };
|
|
@@ -4389,13 +4739,22 @@ const createNavigationResolver = ({
|
|
|
4389
4739
|
const xPositionForPageIndex = pageIndex * context.getPageSize().width;
|
|
4390
4740
|
return getNavigationForPosition({ x: xPositionForPageIndex, y: 0 });
|
|
4391
4741
|
}
|
|
4392
|
-
const spineItemNavigation = spineItemNavigator.getNavigationForPage(
|
|
4393
|
-
|
|
4742
|
+
const spineItemNavigation = spineItemNavigator.getNavigationForPage(
|
|
4743
|
+
pageIndex,
|
|
4744
|
+
spineItem
|
|
4745
|
+
);
|
|
4746
|
+
const readingOffset = locator.getSpinePositionFromSpineItemPosition(
|
|
4747
|
+
spineItemNavigation,
|
|
4748
|
+
spineItem
|
|
4749
|
+
);
|
|
4394
4750
|
return getAdjustedPositionForSpread(readingOffset);
|
|
4395
4751
|
};
|
|
4396
4752
|
const getNavigationForLastPage = (spineItem) => {
|
|
4397
4753
|
const spineItemNavigation = spineItemNavigator.getNavigationForLastPage(spineItem);
|
|
4398
|
-
const position = locator.getSpinePositionFromSpineItemPosition(
|
|
4754
|
+
const position = locator.getSpinePositionFromSpineItemPosition(
|
|
4755
|
+
spineItemNavigation,
|
|
4756
|
+
spineItem
|
|
4757
|
+
);
|
|
4399
4758
|
return getAdjustedPositionForSpread(position);
|
|
4400
4759
|
};
|
|
4401
4760
|
const getNavigationForSpineIndexOrId = (indexOrId) => {
|
|
@@ -4413,9 +4772,15 @@ const createNavigationResolver = ({
|
|
|
4413
4772
|
if (!spineItem) {
|
|
4414
4773
|
return defaultNavigation;
|
|
4415
4774
|
}
|
|
4416
|
-
const spineItemPosition = locator.getSpineItemPositionFromSpinePosition(
|
|
4775
|
+
const spineItemPosition = locator.getSpineItemPositionFromSpinePosition(
|
|
4776
|
+
position,
|
|
4777
|
+
spineItem
|
|
4778
|
+
);
|
|
4417
4779
|
const spineItemNavigationForRightPage = spineItemNavigator.getNavigationForRightPage(spineItemPosition, spineItem);
|
|
4418
|
-
const isNewNavigationInCurrentItem = arePositionsDifferent(
|
|
4780
|
+
const isNewNavigationInCurrentItem = arePositionsDifferent(
|
|
4781
|
+
spineItemNavigationForRightPage,
|
|
4782
|
+
spineItemPosition
|
|
4783
|
+
);
|
|
4419
4784
|
if (!isNewNavigationInCurrentItem) {
|
|
4420
4785
|
return wrapPositionWithSafeEdge(
|
|
4421
4786
|
pageTurnDirection === `horizontal` ? { x: position.x + context.getPageSize().width, y: 0 } : { y: position.y + context.getPageSize().height, x: 0 }
|
|
@@ -4435,15 +4800,27 @@ const createNavigationResolver = ({
|
|
|
4435
4800
|
if (!spineItem) {
|
|
4436
4801
|
return defaultNavigation;
|
|
4437
4802
|
}
|
|
4438
|
-
const spineItemPosition = locator.getSpineItemPositionFromSpinePosition(
|
|
4439
|
-
|
|
4440
|
-
|
|
4803
|
+
const spineItemPosition = locator.getSpineItemPositionFromSpinePosition(
|
|
4804
|
+
position,
|
|
4805
|
+
spineItem
|
|
4806
|
+
);
|
|
4807
|
+
const spineItemNavigation = spineItemNavigator.getNavigationForLeftPage(
|
|
4808
|
+
spineItemPosition,
|
|
4809
|
+
spineItem
|
|
4810
|
+
);
|
|
4811
|
+
const isNewNavigationInCurrentItem = arePositionsDifferent(
|
|
4812
|
+
spineItemNavigation,
|
|
4813
|
+
spineItemPosition
|
|
4814
|
+
);
|
|
4441
4815
|
if (!isNewNavigationInCurrentItem) {
|
|
4442
4816
|
return wrapPositionWithSafeEdge(
|
|
4443
4817
|
pageTurnDirection === `horizontal` ? { x: position.x - context.getPageSize().width, y: 0 } : { y: position.y - context.getPageSize().height, x: 0 }
|
|
4444
4818
|
);
|
|
4445
4819
|
} else {
|
|
4446
|
-
const readingOrderPosition = locator.getSpinePositionFromSpineItemPosition(
|
|
4820
|
+
const readingOrderPosition = locator.getSpinePositionFromSpineItemPosition(
|
|
4821
|
+
spineItemNavigation,
|
|
4822
|
+
spineItem
|
|
4823
|
+
);
|
|
4447
4824
|
return readingOrderPosition;
|
|
4448
4825
|
}
|
|
4449
4826
|
};
|
|
@@ -4485,7 +4862,10 @@ const createNavigationResolver = ({
|
|
|
4485
4862
|
if ((spineItemOnPosition == null ? void 0 : spineItemOnPosition.isUsingVerticalWriting()) && position.x !== navigation.x) {
|
|
4486
4863
|
return getAdjustedPositionForSpread(
|
|
4487
4864
|
wrapPositionWithSafeEdge(
|
|
4488
|
-
context.isRTL() ? { ...navigation, x: navigation.x + context.getPageSize().width } : {
|
|
4865
|
+
context.isRTL() ? { ...navigation, x: navigation.x + context.getPageSize().width } : {
|
|
4866
|
+
...navigation,
|
|
4867
|
+
x: navigation.x - context.getPageSize().width
|
|
4868
|
+
}
|
|
4489
4869
|
)
|
|
4490
4870
|
);
|
|
4491
4871
|
}
|
|
@@ -4502,7 +4882,9 @@ const createNavigationResolver = ({
|
|
|
4502
4882
|
try {
|
|
4503
4883
|
const validUrl = url instanceof URL ? url : new URL(url);
|
|
4504
4884
|
const urlWithoutAnchor = `${validUrl.origin}${validUrl.pathname}`;
|
|
4505
|
-
const existingSpineItem = (_a = context.manifest) == null ? void 0 : _a.spineItems.find(
|
|
4885
|
+
const existingSpineItem = (_a = context.manifest) == null ? void 0 : _a.spineItems.find(
|
|
4886
|
+
(item) => item.href === urlWithoutAnchor
|
|
4887
|
+
);
|
|
4506
4888
|
if (existingSpineItem) {
|
|
4507
4889
|
const spineItem = spineItemManager.get(existingSpineItem.id);
|
|
4508
4890
|
if (spineItem) {
|
|
@@ -4517,15 +4899,27 @@ const createNavigationResolver = ({
|
|
|
4517
4899
|
}
|
|
4518
4900
|
};
|
|
4519
4901
|
const getNavigationForAnchor = (anchor, spineItem) => {
|
|
4520
|
-
const position = locator.getSpinePositionFromSpineItemAnchor(
|
|
4902
|
+
const position = locator.getSpinePositionFromSpineItemAnchor(
|
|
4903
|
+
anchor,
|
|
4904
|
+
spineItem
|
|
4905
|
+
);
|
|
4521
4906
|
return getAdjustedPositionForSpread(position);
|
|
4522
4907
|
};
|
|
4523
4908
|
const getNavigationForPosition = (viewportPosition) => {
|
|
4524
4909
|
const spineItem = locator.getSpineItemFromPosition(viewportPosition);
|
|
4525
4910
|
if (spineItem) {
|
|
4526
|
-
const spineItemPosition = locator.getSpineItemPositionFromSpinePosition(
|
|
4527
|
-
|
|
4528
|
-
|
|
4911
|
+
const spineItemPosition = locator.getSpineItemPositionFromSpinePosition(
|
|
4912
|
+
viewportPosition,
|
|
4913
|
+
spineItem
|
|
4914
|
+
);
|
|
4915
|
+
const spineItemValidPosition = spineItemNavigator.getNavigationForPosition(
|
|
4916
|
+
spineItem,
|
|
4917
|
+
spineItemPosition
|
|
4918
|
+
);
|
|
4919
|
+
const viewportNavigation = locator.getSpinePositionFromSpineItemPosition(
|
|
4920
|
+
spineItemValidPosition,
|
|
4921
|
+
spineItem
|
|
4922
|
+
);
|
|
4529
4923
|
return getAdjustedPositionForSpread(viewportNavigation);
|
|
4530
4924
|
}
|
|
4531
4925
|
return { x: 0, y: 0 };
|
|
@@ -4535,7 +4929,10 @@ const createNavigationResolver = ({
|
|
|
4535
4929
|
const triggerPercentage = 0.5;
|
|
4536
4930
|
const triggerXPosition = pageTurnDirection === `horizontal` ? viewportPosition.x + context.state.visibleAreaRect.width * triggerPercentage : 0;
|
|
4537
4931
|
const triggerYPosition = pageTurnDirection === `horizontal` ? 0 : viewportPosition.y + context.state.visibleAreaRect.height * triggerPercentage;
|
|
4538
|
-
const midScreenPositionSafePosition = wrapPositionWithSafeEdge({
|
|
4932
|
+
const midScreenPositionSafePosition = wrapPositionWithSafeEdge({
|
|
4933
|
+
x: triggerXPosition,
|
|
4934
|
+
y: triggerYPosition
|
|
4935
|
+
});
|
|
4539
4936
|
return getNavigationForPosition(midScreenPositionSafePosition);
|
|
4540
4937
|
};
|
|
4541
4938
|
const isNavigationGoingForwardFrom = (to, from2) => {
|
|
@@ -4630,7 +5027,10 @@ const createScrollViewportNavigator = ({
|
|
|
4630
5027
|
};
|
|
4631
5028
|
const getCurrentViewportPosition = () => {
|
|
4632
5029
|
var _a, _b;
|
|
4633
|
-
return getScaledDownPosition({
|
|
5030
|
+
return getScaledDownPosition({
|
|
5031
|
+
x: ((_a = element$.getValue()) == null ? void 0 : _a.scrollLeft) ?? 0,
|
|
5032
|
+
y: ((_b = element$.getValue()) == null ? void 0 : _b.scrollTop) ?? 0
|
|
5033
|
+
});
|
|
4634
5034
|
};
|
|
4635
5035
|
const navigationOnScroll$ = userScroll$.pipe(
|
|
4636
5036
|
debounceTime$1(SCROLL_FINISHED_DEBOUNCE_TIMEOUT, animationFrameScheduler),
|
|
@@ -4638,9 +5038,16 @@ const createScrollViewportNavigator = ({
|
|
|
4638
5038
|
switchMap$1(() => {
|
|
4639
5039
|
var _a, _b;
|
|
4640
5040
|
const navigation = getNavigationForPosition(
|
|
4641
|
-
getScaledDownPosition({
|
|
5041
|
+
getScaledDownPosition({
|
|
5042
|
+
x: ((_a = element$.getValue()) == null ? void 0 : _a.scrollLeft) ?? 0,
|
|
5043
|
+
y: ((_b = element$.getValue()) == null ? void 0 : _b.scrollTop) ?? 0
|
|
5044
|
+
})
|
|
4642
5045
|
);
|
|
4643
|
-
return of({
|
|
5046
|
+
return of({
|
|
5047
|
+
position: navigation,
|
|
5048
|
+
animate: false,
|
|
5049
|
+
lastUserExpectedNavigation: void 0
|
|
5050
|
+
});
|
|
4644
5051
|
}),
|
|
4645
5052
|
share()
|
|
4646
5053
|
);
|
|
@@ -4678,16 +5085,29 @@ const createManualViewportNavigator = ({
|
|
|
4678
5085
|
}) => {
|
|
4679
5086
|
const stateSubject$ = new BehaviorSubject(`end`);
|
|
4680
5087
|
const navigationTriggerSubject$ = new Subject();
|
|
4681
|
-
const turnLeft = ({
|
|
4682
|
-
|
|
4683
|
-
|
|
5088
|
+
const turnLeft = ({
|
|
5089
|
+
allowSpineItemChange = true
|
|
5090
|
+
} = {}) => navigationTriggerSubject$.next({
|
|
5091
|
+
type: `leftPage`,
|
|
5092
|
+
data: { allowSpineItemChange }
|
|
5093
|
+
});
|
|
5094
|
+
const turnRight = ({
|
|
5095
|
+
allowSpineItemChange = true
|
|
5096
|
+
} = {}) => {
|
|
5097
|
+
navigationTriggerSubject$.next({
|
|
5098
|
+
type: `rightPage`,
|
|
5099
|
+
data: { allowSpineItemChange }
|
|
5100
|
+
});
|
|
4684
5101
|
};
|
|
4685
5102
|
const goToPageOfCurrentChapter = (pageIndex) => navigationTriggerSubject$.next({ type: `chapterPage`, data: { pageIndex } });
|
|
4686
5103
|
const goToPage = (pageIndex) => navigationTriggerSubject$.next({ type: `pageIndex`, data: { pageIndex } });
|
|
4687
5104
|
const goToCfi = (cfi, options = { animate: true }) => navigationTriggerSubject$.next({ type: `cfi`, data: { cfi, ...options } });
|
|
4688
5105
|
const goToUrl = (url) => navigationTriggerSubject$.next({ type: `url`, data: url });
|
|
4689
5106
|
const goToSpineItem = (indexOrId, options = { animate: true }) => {
|
|
4690
|
-
navigationTriggerSubject$.next({
|
|
5107
|
+
navigationTriggerSubject$.next({
|
|
5108
|
+
type: `spineItem`,
|
|
5109
|
+
data: { indexOrId, ...options }
|
|
5110
|
+
});
|
|
4691
5111
|
};
|
|
4692
5112
|
const urlNavigation$ = navigationTriggerSubject$.pipe(
|
|
4693
5113
|
filter((e) => e.type === `url`),
|
|
@@ -4698,7 +5118,10 @@ const createManualViewportNavigator = ({
|
|
|
4698
5118
|
return of({
|
|
4699
5119
|
...navigation,
|
|
4700
5120
|
animate: true,
|
|
4701
|
-
lastUserExpectedNavigation: {
|
|
5121
|
+
lastUserExpectedNavigation: {
|
|
5122
|
+
type: `navigate-from-anchor`,
|
|
5123
|
+
data: navigation.url.hash
|
|
5124
|
+
}
|
|
4702
5125
|
});
|
|
4703
5126
|
}
|
|
4704
5127
|
return EMPTY;
|
|
@@ -4708,7 +5131,9 @@ const createManualViewportNavigator = ({
|
|
|
4708
5131
|
filter((e) => e.type === `spineItem`),
|
|
4709
5132
|
switchMap$1(({ data: { animate, indexOrId } }) => {
|
|
4710
5133
|
const navigation = navigator2.getNavigationForSpineIndexOrId(indexOrId);
|
|
4711
|
-
const lastUserExpectedNavigation = {
|
|
5134
|
+
const lastUserExpectedNavigation = {
|
|
5135
|
+
type: `navigate-from-previous-item`
|
|
5136
|
+
};
|
|
4712
5137
|
Report.log(NAMESPACE$2, `goToSpineItem`, { indexOrId, animate, navigation });
|
|
4713
5138
|
return of({ ...navigation, animate, lastUserExpectedNavigation });
|
|
4714
5139
|
})
|
|
@@ -4721,7 +5146,10 @@ const createManualViewportNavigator = ({
|
|
|
4721
5146
|
return {
|
|
4722
5147
|
...navigation,
|
|
4723
5148
|
animate,
|
|
4724
|
-
lastUserExpectedNavigation: {
|
|
5149
|
+
lastUserExpectedNavigation: {
|
|
5150
|
+
type: `navigate-from-cfi`,
|
|
5151
|
+
data: cfi
|
|
5152
|
+
}
|
|
4725
5153
|
};
|
|
4726
5154
|
})
|
|
4727
5155
|
);
|
|
@@ -4731,7 +5159,11 @@ const createManualViewportNavigator = ({
|
|
|
4731
5159
|
const spineItem = spineItemManager.getFocusedSpineItem();
|
|
4732
5160
|
if (spineItem) {
|
|
4733
5161
|
const navigation = navigator2.getNavigationForPage(pageIndex, spineItem);
|
|
4734
|
-
return of({
|
|
5162
|
+
return of({
|
|
5163
|
+
...navigation,
|
|
5164
|
+
lastUserExpectedNavigation: void 0,
|
|
5165
|
+
animate: true
|
|
5166
|
+
});
|
|
4735
5167
|
}
|
|
4736
5168
|
return EMPTY;
|
|
4737
5169
|
})
|
|
@@ -4764,26 +5196,31 @@ const createManualViewportNavigator = ({
|
|
|
4764
5196
|
const spineItemHasChanged = newSpineItem !== currentSpineItem;
|
|
4765
5197
|
if (spineItemHasChanged) {
|
|
4766
5198
|
if (allowSpineItemChange) {
|
|
4767
|
-
const positionOfNewSpineItemComparedToCurrentOne = spineItemManager.comparePositionOf(
|
|
4768
|
-
newSpineItem,
|
|
4769
|
-
currentSpineItem
|
|
4770
|
-
);
|
|
5199
|
+
const positionOfNewSpineItemComparedToCurrentOne = spineItemManager.comparePositionOf(newSpineItem, currentSpineItem);
|
|
4771
5200
|
if (positionOfNewSpineItemComparedToCurrentOne === `before`) {
|
|
4772
5201
|
return of({
|
|
4773
5202
|
...navigation,
|
|
4774
|
-
lastUserExpectedNavigation: {
|
|
5203
|
+
lastUserExpectedNavigation: {
|
|
5204
|
+
type: `navigate-from-next-item`
|
|
5205
|
+
},
|
|
4775
5206
|
animate: true
|
|
4776
5207
|
});
|
|
4777
5208
|
} else {
|
|
4778
5209
|
return of({
|
|
4779
5210
|
...navigation,
|
|
4780
|
-
lastUserExpectedNavigation: {
|
|
5211
|
+
lastUserExpectedNavigation: {
|
|
5212
|
+
type: `navigate-from-previous-item`
|
|
5213
|
+
},
|
|
4781
5214
|
animate: true
|
|
4782
5215
|
});
|
|
4783
5216
|
}
|
|
4784
5217
|
}
|
|
4785
5218
|
} else {
|
|
4786
|
-
return of({
|
|
5219
|
+
return of({
|
|
5220
|
+
...navigation,
|
|
5221
|
+
lastUserExpectedNavigation: void 0,
|
|
5222
|
+
animate: true
|
|
5223
|
+
});
|
|
4787
5224
|
}
|
|
4788
5225
|
return EMPTY;
|
|
4789
5226
|
}
|
|
@@ -4799,7 +5236,11 @@ const createManualViewportNavigator = ({
|
|
|
4799
5236
|
currentNavigation
|
|
4800
5237
|
]) => {
|
|
4801
5238
|
const navigation = navigator2.getNavigationForLeftPage(currentNavigation);
|
|
4802
|
-
Report.log(NAMESPACE$2, `turnLeft`, {
|
|
5239
|
+
Report.log(NAMESPACE$2, `turnLeft`, {
|
|
5240
|
+
currentNavigation,
|
|
5241
|
+
navigation,
|
|
5242
|
+
allowSpineItemChange
|
|
5243
|
+
});
|
|
4803
5244
|
return turnPageTo$(navigation, { allowSpineItemChange });
|
|
4804
5245
|
}
|
|
4805
5246
|
)
|
|
@@ -4815,7 +5256,11 @@ const createManualViewportNavigator = ({
|
|
|
4815
5256
|
currentNavigation
|
|
4816
5257
|
]) => {
|
|
4817
5258
|
const navigation = navigator2.getNavigationForRightPage(currentNavigation);
|
|
4818
|
-
Report.log(NAMESPACE$2, `turnRight`, {
|
|
5259
|
+
Report.log(NAMESPACE$2, `turnRight`, {
|
|
5260
|
+
currentNavigation,
|
|
5261
|
+
navigation,
|
|
5262
|
+
allowSpineItemChange
|
|
5263
|
+
});
|
|
4819
5264
|
return turnPageTo$(navigation, { allowSpineItemChange });
|
|
4820
5265
|
}
|
|
4821
5266
|
)
|
|
@@ -4835,7 +5280,9 @@ const createManualViewportNavigator = ({
|
|
|
4835
5280
|
* navigation would theoretically always move to different items.
|
|
4836
5281
|
*/
|
|
4837
5282
|
withLatestFrom$1(currentNavigationSubject$),
|
|
4838
|
-
filter(
|
|
5283
|
+
filter(
|
|
5284
|
+
([navigation, currentNavigation]) => navigator2.areNavigationDifferent(navigation, currentNavigation)
|
|
5285
|
+
),
|
|
4839
5286
|
map(([navigation]) => navigation)
|
|
4840
5287
|
);
|
|
4841
5288
|
return {
|
|
@@ -4926,7 +5373,10 @@ const createPanViewportNavigator = ({
|
|
|
4926
5373
|
const spineItemHasChanged = newSpineItem !== currentSpineItem;
|
|
4927
5374
|
if (spineItemHasChanged) {
|
|
4928
5375
|
if (allowSpineItemChange) {
|
|
4929
|
-
if (spineItemManager.comparePositionOf(
|
|
5376
|
+
if (spineItemManager.comparePositionOf(
|
|
5377
|
+
newSpineItem,
|
|
5378
|
+
currentSpineItem
|
|
5379
|
+
) === `before`) {
|
|
4930
5380
|
return { type: `navigate-from-next-item` };
|
|
4931
5381
|
} else {
|
|
4932
5382
|
return { type: `navigate-from-previous-item` };
|
|
@@ -4956,7 +5406,9 @@ const createPanViewportNavigator = ({
|
|
|
4956
5406
|
x: triggerXPosition,
|
|
4957
5407
|
y: triggerYPosition
|
|
4958
5408
|
});
|
|
4959
|
-
const finalNavigation = navigator2.getNavigationForPosition(
|
|
5409
|
+
const finalNavigation = navigator2.getNavigationForPosition(
|
|
5410
|
+
midScreenPositionSafePosition
|
|
5411
|
+
);
|
|
4960
5412
|
const lastUserExpectedNavigation = getLastUserExpectedNavigation(finalNavigation);
|
|
4961
5413
|
return of({ ...finalNavigation, lastUserExpectedNavigation });
|
|
4962
5414
|
}
|
|
@@ -5008,23 +5460,30 @@ const createViewportNavigator = ({
|
|
|
5008
5460
|
locator: spineLocator
|
|
5009
5461
|
});
|
|
5010
5462
|
const adjustNavigationSubject$ = new Subject();
|
|
5011
|
-
const getCurrentViewportPosition = Report.measurePerformance(
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5463
|
+
const getCurrentViewportPosition = Report.measurePerformance(
|
|
5464
|
+
`${NAMESPACE} getCurrentViewportPosition`,
|
|
5465
|
+
1,
|
|
5466
|
+
() => {
|
|
5467
|
+
var _a;
|
|
5468
|
+
if (settings.settings.computedPageTurnMode === `scrollable`) {
|
|
5469
|
+
return scrollViewportNavigator.getCurrentViewportPosition();
|
|
5470
|
+
}
|
|
5471
|
+
const { x, y } = ((_a = element$.getValue()) == null ? void 0 : _a.getBoundingClientRect()) ?? {
|
|
5472
|
+
x: 0,
|
|
5473
|
+
y: 0
|
|
5474
|
+
};
|
|
5475
|
+
const newValue = {
|
|
5476
|
+
// we want to round to first decimal because it's possible to have half pixel
|
|
5477
|
+
// however browser engine can also gives back x.yyyy based on their precision
|
|
5478
|
+
// @see https://stackoverflow.com/questions/13847053/difference-between-and-math-floor for ~~
|
|
5479
|
+
x: ~~(x * -1 * 10) / 10,
|
|
5480
|
+
// x: ~~(x * 10) / 10,
|
|
5481
|
+
y: ~~(Math.abs(y) * 10) / 10
|
|
5482
|
+
};
|
|
5483
|
+
currentViewportPositionMemoUnused = newValue;
|
|
5484
|
+
return currentViewportPositionMemoUnused;
|
|
5015
5485
|
}
|
|
5016
|
-
|
|
5017
|
-
const newValue = {
|
|
5018
|
-
// we want to round to first decimal because it's possible to have half pixel
|
|
5019
|
-
// however browser engine can also gives back x.yyyy based on their precision
|
|
5020
|
-
// @see https://stackoverflow.com/questions/13847053/difference-between-and-math-floor for ~~
|
|
5021
|
-
x: ~~(x * -1 * 10) / 10,
|
|
5022
|
-
// x: ~~(x * 10) / 10,
|
|
5023
|
-
y: ~~(Math.abs(y) * 10) / 10
|
|
5024
|
-
};
|
|
5025
|
-
currentViewportPositionMemoUnused = newValue;
|
|
5026
|
-
return currentViewportPositionMemoUnused;
|
|
5027
|
-
});
|
|
5486
|
+
);
|
|
5028
5487
|
const panViewportNavigator = createPanViewportNavigator({
|
|
5029
5488
|
context,
|
|
5030
5489
|
settings,
|
|
@@ -5050,8 +5509,14 @@ const createViewportNavigator = ({
|
|
|
5050
5509
|
spineItemManager,
|
|
5051
5510
|
locator: spineLocator
|
|
5052
5511
|
});
|
|
5053
|
-
const viewportNavigators = [
|
|
5054
|
-
|
|
5512
|
+
const viewportNavigators = [
|
|
5513
|
+
scrollViewportNavigator,
|
|
5514
|
+
panViewportNavigator,
|
|
5515
|
+
manualViewportNavigator
|
|
5516
|
+
];
|
|
5517
|
+
const viewportNavigatorsSharedState$ = merge(
|
|
5518
|
+
...viewportNavigators.map(({ $: { state$: state$2 } }) => state$2)
|
|
5519
|
+
);
|
|
5055
5520
|
let lastUserExpectedNavigation;
|
|
5056
5521
|
const makeItHot = (source$) => {
|
|
5057
5522
|
source$.pipe(takeUntil$1(context.destroy$)).subscribe();
|
|
@@ -5079,28 +5544,51 @@ const createViewportNavigator = ({
|
|
|
5079
5544
|
let adjustedSpinePosition = currentNavigationPositionSubject$.value;
|
|
5080
5545
|
const offsetInSpineItem = 0;
|
|
5081
5546
|
if (settings.settings.computedPageTurnMode === `scrollable`) {
|
|
5082
|
-
adjustedSpinePosition = scrollViewportNavigator.getNavigationForPosition(
|
|
5547
|
+
adjustedSpinePosition = scrollViewportNavigator.getNavigationForPosition(
|
|
5548
|
+
getCurrentViewportPosition()
|
|
5549
|
+
);
|
|
5083
5550
|
} else if ((lastUserExpectedNavigation == null ? void 0 : lastUserExpectedNavigation.type) === `navigate-from-cfi`) {
|
|
5084
|
-
adjustedSpinePosition = navigator2.getNavigationForCfi(
|
|
5085
|
-
|
|
5551
|
+
adjustedSpinePosition = navigator2.getNavigationForCfi(
|
|
5552
|
+
lastUserExpectedNavigation.data
|
|
5553
|
+
);
|
|
5554
|
+
Report.log(
|
|
5555
|
+
NAMESPACE,
|
|
5556
|
+
`adjustNavigation`,
|
|
5557
|
+
`navigate-from-cfi`,
|
|
5558
|
+
`use last cfi`
|
|
5559
|
+
);
|
|
5086
5560
|
} else if ((lastUserExpectedNavigation == null ? void 0 : lastUserExpectedNavigation.type) === `navigate-from-next-item`) {
|
|
5087
5561
|
adjustedSpinePosition = navigator2.getNavigationForLastPage(spineItem);
|
|
5088
5562
|
Report.log(NAMESPACE, `adjustNavigation`, `navigate-from-next-item`, {});
|
|
5089
5563
|
} else if ((lastUserExpectedNavigation == null ? void 0 : lastUserExpectedNavigation.type) === `navigate-from-previous-item`) {
|
|
5090
5564
|
adjustedSpinePosition = navigator2.getNavigationForPage(0, spineItem);
|
|
5091
|
-
Report.log(
|
|
5565
|
+
Report.log(
|
|
5566
|
+
NAMESPACE,
|
|
5567
|
+
`adjustNavigation`,
|
|
5568
|
+
`navigate-from-previous-item`,
|
|
5569
|
+
{}
|
|
5570
|
+
);
|
|
5092
5571
|
} else if ((lastUserExpectedNavigation == null ? void 0 : lastUserExpectedNavigation.type) === `navigate-from-anchor`) {
|
|
5093
5572
|
const anchor = lastUserExpectedNavigation.data;
|
|
5094
|
-
adjustedSpinePosition = navigator2.getNavigationForAnchor(
|
|
5573
|
+
adjustedSpinePosition = navigator2.getNavigationForAnchor(
|
|
5574
|
+
anchor,
|
|
5575
|
+
spineItem
|
|
5576
|
+
);
|
|
5095
5577
|
} else if (lastCfi) {
|
|
5096
5578
|
adjustedSpinePosition = navigator2.getNavigationForCfi(lastCfi);
|
|
5097
5579
|
Report.log(NAMESPACE, `adjustNavigation`, `use last cfi`);
|
|
5098
5580
|
} else {
|
|
5099
5581
|
const currentPageIndex = pagination.getPaginationInfo().beginPageIndexInSpineItem || 0;
|
|
5100
|
-
adjustedSpinePosition = navigator2.getNavigationForPage(
|
|
5582
|
+
adjustedSpinePosition = navigator2.getNavigationForPage(
|
|
5583
|
+
currentPageIndex,
|
|
5584
|
+
spineItem
|
|
5585
|
+
);
|
|
5101
5586
|
Report.log(NAMESPACE, `adjustNavigation`, `use guess strategy`, {});
|
|
5102
5587
|
}
|
|
5103
|
-
const areDifferent = navigator2.arePositionsDifferent(
|
|
5588
|
+
const areDifferent = navigator2.arePositionsDifferent(
|
|
5589
|
+
adjustedSpinePosition,
|
|
5590
|
+
currentNavigationPositionSubject$.value
|
|
5591
|
+
);
|
|
5104
5592
|
Report.log(NAMESPACE, `adjustNavigation`, {
|
|
5105
5593
|
areDifferent,
|
|
5106
5594
|
offsetInSpineItem,
|
|
@@ -5124,7 +5612,11 @@ const createViewportNavigator = ({
|
|
|
5124
5612
|
currentViewportPositionMemoUnused = void 0;
|
|
5125
5613
|
});
|
|
5126
5614
|
const layoutChangeSettings$ = settings.settings$.pipe(
|
|
5127
|
-
mapKeysTo([
|
|
5615
|
+
mapKeysTo([
|
|
5616
|
+
`computedPageTurnDirection`,
|
|
5617
|
+
`computedPageTurnMode`,
|
|
5618
|
+
`numberOfAdjacentSpineItemToPreLoad`
|
|
5619
|
+
]),
|
|
5128
5620
|
distinctUntilChanged(isShallowEqual),
|
|
5129
5621
|
skip(1)
|
|
5130
5622
|
);
|
|
@@ -5236,10 +5728,16 @@ const createViewportNavigator = ({
|
|
|
5236
5728
|
const noAdjustmentNeeded = false;
|
|
5237
5729
|
if (data.shouldAnimate && !noAdjustmentNeeded) {
|
|
5238
5730
|
if (pageTurnAnimation === `fade`) {
|
|
5239
|
-
element$.getValue().style.setProperty(
|
|
5731
|
+
element$.getValue().style.setProperty(
|
|
5732
|
+
`transition`,
|
|
5733
|
+
`opacity ${animationDuration / 2}ms`
|
|
5734
|
+
);
|
|
5240
5735
|
element$.getValue().style.setProperty(`opacity`, `0`);
|
|
5241
5736
|
} else if (currentEvent.animation === `snap` || pageTurnAnimation === `slide`) {
|
|
5242
|
-
element$.getValue().style.setProperty(
|
|
5737
|
+
element$.getValue().style.setProperty(
|
|
5738
|
+
`transition`,
|
|
5739
|
+
`transform ${animationDuration}ms`
|
|
5740
|
+
);
|
|
5243
5741
|
element$.getValue().style.setProperty(`opacity`, `1`);
|
|
5244
5742
|
}
|
|
5245
5743
|
} else {
|
|
@@ -5288,8 +5786,13 @@ const createViewportNavigator = ({
|
|
|
5288
5786
|
merge(manualAdjust$).pipe(map(() => `start`)),
|
|
5289
5787
|
merge(processManualAdjust$).pipe(map(() => `end`))
|
|
5290
5788
|
);
|
|
5291
|
-
const state$ = combineLatest([
|
|
5292
|
-
map((
|
|
5789
|
+
const state$ = combineLatest([
|
|
5790
|
+
...viewportNavigators.map(({ $: { state$: state$2 } }) => state$2),
|
|
5791
|
+
adjustmentState$
|
|
5792
|
+
]).pipe(
|
|
5793
|
+
map(
|
|
5794
|
+
(states) => states.every((state) => state === `end`) ? `free` : `busy`
|
|
5795
|
+
),
|
|
5293
5796
|
distinctUntilChanged(),
|
|
5294
5797
|
shareReplay(1),
|
|
5295
5798
|
/**
|
|
@@ -5379,7 +5882,9 @@ const createElement = (doc, hookManager) => {
|
|
|
5379
5882
|
position: relative;
|
|
5380
5883
|
`;
|
|
5381
5884
|
element.className = `${HTML_PREFIX$1}-viewport-navigator`;
|
|
5382
|
-
hookManager.execute("viewportNavigator.onBeforeContainerCreated", void 0, {
|
|
5885
|
+
hookManager.execute("viewportNavigator.onBeforeContainerCreated", void 0, {
|
|
5886
|
+
element
|
|
5887
|
+
});
|
|
5383
5888
|
return element;
|
|
5384
5889
|
};
|
|
5385
5890
|
const createLocationResolver = ({
|
|
@@ -5438,8 +5943,14 @@ const createLocationResolver = ({
|
|
|
5438
5943
|
return getSpinePositionFromSpineItemPosition({ x: 0, y: 0 }, spineItem);
|
|
5439
5944
|
};
|
|
5440
5945
|
const getSpinePositionFromSpineItemAnchor = (anchor, spineItem) => {
|
|
5441
|
-
const spineItemOffset = spineItemLocator.getSpineItemOffsetFromAnchor(
|
|
5442
|
-
|
|
5946
|
+
const spineItemOffset = spineItemLocator.getSpineItemOffsetFromAnchor(
|
|
5947
|
+
anchor,
|
|
5948
|
+
spineItem
|
|
5949
|
+
);
|
|
5950
|
+
const position = getSpinePositionFromSpineItemPosition(
|
|
5951
|
+
{ x: spineItemOffset, y: 0 },
|
|
5952
|
+
spineItem
|
|
5953
|
+
);
|
|
5443
5954
|
return position;
|
|
5444
5955
|
};
|
|
5445
5956
|
const getSpineItemsFromReadingOrderPosition = (position) => {
|
|
@@ -5448,7 +5959,10 @@ const createLocationResolver = ({
|
|
|
5448
5959
|
if (itemAtPositionIndex === void 0) return void 0;
|
|
5449
5960
|
let endPosition = position;
|
|
5450
5961
|
if (context.state.isUsingSpreadMode) {
|
|
5451
|
-
endPosition = {
|
|
5962
|
+
endPosition = {
|
|
5963
|
+
x: position.x + context.getPageSize().width,
|
|
5964
|
+
y: position.y
|
|
5965
|
+
};
|
|
5452
5966
|
}
|
|
5453
5967
|
const endItemIndex = spineItemManager.getSpineItemIndex(
|
|
5454
5968
|
getSpineItemFromPosition(endPosition) || spineItemManager.getFocusedSpineItem()
|
|
@@ -5476,9 +5990,17 @@ const createLocationResolver = ({
|
|
|
5476
5990
|
const getSpineItemPageIndexFromNode = (node, offset, spineItemOrIndex) => {
|
|
5477
5991
|
if (typeof spineItemOrIndex === `number`) {
|
|
5478
5992
|
const spineItem = spineItemManager.get(spineItemOrIndex);
|
|
5479
|
-
return spineItem ? spineItemLocator.getSpineItemPageIndexFromNode(
|
|
5993
|
+
return spineItem ? spineItemLocator.getSpineItemPageIndexFromNode(
|
|
5994
|
+
node,
|
|
5995
|
+
offset || 0,
|
|
5996
|
+
spineItem
|
|
5997
|
+
) : void 0;
|
|
5480
5998
|
}
|
|
5481
|
-
return spineItemLocator.getSpineItemPageIndexFromNode(
|
|
5999
|
+
return spineItemLocator.getSpineItemPageIndexFromNode(
|
|
6000
|
+
node,
|
|
6001
|
+
offset || 0,
|
|
6002
|
+
spineItemOrIndex
|
|
6003
|
+
);
|
|
5482
6004
|
};
|
|
5483
6005
|
return {
|
|
5484
6006
|
getSpinePositionFromSpineItemPosition,
|
|
@@ -5496,18 +6018,29 @@ const createCfiLocator = ({
|
|
|
5496
6018
|
spineItemLocator
|
|
5497
6019
|
}) => {
|
|
5498
6020
|
const getItemAnchor = (spineItem) => `|[prose~anchor~${encodeURIComponent(spineItem.item.id)}]`;
|
|
5499
|
-
const getCfi = Report.measurePerformance(
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
6021
|
+
const getCfi = Report.measurePerformance(
|
|
6022
|
+
`getCfi`,
|
|
6023
|
+
10,
|
|
6024
|
+
(pageIndex, spineItem) => {
|
|
6025
|
+
var _a, _b, _c;
|
|
6026
|
+
const nodeOrRange = spineItemLocator.getFirstNodeOrRangeAtPage(
|
|
6027
|
+
pageIndex,
|
|
6028
|
+
spineItem
|
|
6029
|
+
);
|
|
6030
|
+
const doc = (_c = (_b = (_a = spineItem.spineItemFrame.getManipulableFrame()) == null ? void 0 : _a.frame) == null ? void 0 : _b.contentWindow) == null ? void 0 : _c.document;
|
|
6031
|
+
const itemAnchor = getItemAnchor(spineItem);
|
|
6032
|
+
const offset = `|[prose~offset~${(nodeOrRange == null ? void 0 : nodeOrRange.offset) || 0}]`;
|
|
6033
|
+
if (nodeOrRange && doc) {
|
|
6034
|
+
const cfiString = CFI.generate(
|
|
6035
|
+
nodeOrRange.node,
|
|
6036
|
+
0,
|
|
6037
|
+
`${itemAnchor}${offset}`
|
|
6038
|
+
);
|
|
6039
|
+
return cfiString;
|
|
6040
|
+
}
|
|
6041
|
+
return getRootCfi(spineItem);
|
|
5508
6042
|
}
|
|
5509
|
-
|
|
5510
|
-
});
|
|
6043
|
+
);
|
|
5511
6044
|
const getRootCfi = (spineItem) => {
|
|
5512
6045
|
const itemAnchor = getItemAnchor(spineItem);
|
|
5513
6046
|
return `epubcfi(/0${itemAnchor}) `;
|
|
@@ -5554,9 +6087,22 @@ const createCfiLocator = ({
|
|
|
5554
6087
|
spineItemIndex
|
|
5555
6088
|
};
|
|
5556
6089
|
};
|
|
5557
|
-
const generateFromRange = ({
|
|
5558
|
-
|
|
5559
|
-
|
|
6090
|
+
const generateFromRange = ({
|
|
6091
|
+
startNode,
|
|
6092
|
+
start,
|
|
6093
|
+
end,
|
|
6094
|
+
endNode
|
|
6095
|
+
}, item) => {
|
|
6096
|
+
const startCFI = CFI.generate(
|
|
6097
|
+
startNode,
|
|
6098
|
+
start,
|
|
6099
|
+
`|[prose~anchor~${encodeURIComponent(item.id)}]`
|
|
6100
|
+
);
|
|
6101
|
+
const endCFI = CFI.generate(
|
|
6102
|
+
endNode,
|
|
6103
|
+
end,
|
|
6104
|
+
`|[prose~anchor~${encodeURIComponent(item.id)}]`
|
|
6105
|
+
);
|
|
5560
6106
|
return { start: startCFI, end: endCFI };
|
|
5561
6107
|
};
|
|
5562
6108
|
return {
|
|
@@ -5568,19 +6114,57 @@ const createCfiLocator = ({
|
|
|
5568
6114
|
generateFromRange
|
|
5569
6115
|
};
|
|
5570
6116
|
};
|
|
5571
|
-
class
|
|
5572
|
-
constructor(initialSettings
|
|
5573
|
-
__privateAdd(this, _context);
|
|
5574
|
-
__privateSet(this, _context, context);
|
|
6117
|
+
class SettingsManager3 {
|
|
6118
|
+
constructor(initialSettings) {
|
|
5575
6119
|
const settingsWithDefaults = {
|
|
5576
6120
|
...this.getDefaultSettings(),
|
|
5577
6121
|
...initialSettings
|
|
5578
6122
|
};
|
|
5579
|
-
|
|
5580
|
-
this.outputSettings = outputSettings;
|
|
6123
|
+
this.inputSettings = settingsWithDefaults;
|
|
5581
6124
|
this.outputSettingsUpdateSubject = new Subject();
|
|
5582
|
-
this.settings$ = this.outputSettingsUpdateSubject.asObservable().pipe(
|
|
5583
|
-
|
|
6125
|
+
this.settings$ = this.outputSettingsUpdateSubject.asObservable().pipe(shareReplay(1));
|
|
6126
|
+
this.settings$.subscribe();
|
|
6127
|
+
}
|
|
6128
|
+
_prepareUpdate(settings) {
|
|
6129
|
+
const newInputSettings = shallowMergeIfDefined(this.inputSettings, settings);
|
|
6130
|
+
const state = this.getOutputSettings(newInputSettings);
|
|
6131
|
+
const hasChanged = !isShallowEqual(this.outputSettings, state);
|
|
6132
|
+
return {
|
|
6133
|
+
hasChanged,
|
|
6134
|
+
state,
|
|
6135
|
+
commit: () => {
|
|
6136
|
+
this.inputSettings = newInputSettings;
|
|
6137
|
+
this.outputSettings = state;
|
|
6138
|
+
if (hasChanged) {
|
|
6139
|
+
this.outputSettingsUpdateSubject.next(state);
|
|
6140
|
+
}
|
|
6141
|
+
return state;
|
|
6142
|
+
}
|
|
6143
|
+
};
|
|
6144
|
+
}
|
|
6145
|
+
update(settings) {
|
|
6146
|
+
const { commit } = this._prepareUpdate(settings);
|
|
6147
|
+
commit();
|
|
6148
|
+
}
|
|
6149
|
+
get settings() {
|
|
6150
|
+
if (!this.outputSettings) {
|
|
6151
|
+
const { commit } = this._prepareUpdate(this.inputSettings);
|
|
6152
|
+
return commit();
|
|
6153
|
+
}
|
|
6154
|
+
return this.outputSettings;
|
|
6155
|
+
}
|
|
6156
|
+
destroy() {
|
|
6157
|
+
this.outputSettingsUpdateSubject.complete();
|
|
6158
|
+
}
|
|
6159
|
+
}
|
|
6160
|
+
class ReaderSettingsManager extends SettingsManager3 {
|
|
6161
|
+
constructor(initialSettings, context) {
|
|
6162
|
+
super(initialSettings);
|
|
6163
|
+
this.context = context;
|
|
6164
|
+
const recomputeSettingsOnContextChange$ = combineLatest([
|
|
6165
|
+
context.hasVerticalWriting$,
|
|
6166
|
+
context.manifest$
|
|
6167
|
+
]).pipe(
|
|
5584
6168
|
tap(() => {
|
|
5585
6169
|
this.update(this.settings);
|
|
5586
6170
|
})
|
|
@@ -5594,8 +6178,8 @@ class ReaderSettingsManager {
|
|
|
5594
6178
|
this.settings$.subscribe();
|
|
5595
6179
|
}
|
|
5596
6180
|
getComputedSettings(settings) {
|
|
5597
|
-
const manifest =
|
|
5598
|
-
const hasVerticalWriting =
|
|
6181
|
+
const manifest = this.context.manifest;
|
|
6182
|
+
const hasVerticalWriting = this.context.state.hasVerticalWriting ?? false;
|
|
5599
6183
|
const computedSettings = {
|
|
5600
6184
|
computedPageTurnDirection: settings.pageTurnDirection,
|
|
5601
6185
|
computedPageTurnAnimation: settings.pageTurnAnimation,
|
|
@@ -5606,7 +6190,9 @@ class ReaderSettingsManager {
|
|
|
5606
6190
|
computedSettings.computedPageTurnMode = `scrollable`;
|
|
5607
6191
|
computedSettings.computedPageTurnDirection = `vertical`;
|
|
5608
6192
|
} else if (manifest && settings.pageTurnMode === `scrollable` && (manifest.renditionLayout !== `pre-paginated` || !areAllItemsPrePaginated(manifest))) {
|
|
5609
|
-
Report.warn(
|
|
6193
|
+
Report.warn(
|
|
6194
|
+
`pageTurnMode ${settings.pageTurnMode} incompatible with current book, switching back to default`
|
|
6195
|
+
);
|
|
5610
6196
|
computedSettings.computedPageTurnAnimation = `none`;
|
|
5611
6197
|
computedSettings.computedPageTurnMode = `controlled`;
|
|
5612
6198
|
} else if (settings.pageTurnMode === `scrollable`) {
|
|
@@ -5627,22 +6213,8 @@ class ReaderSettingsManager {
|
|
|
5627
6213
|
}
|
|
5628
6214
|
return computedSettings;
|
|
5629
6215
|
}
|
|
5630
|
-
_prepareUpdate(settings) {
|
|
5631
|
-
const state = this.getOutputSettings(settings);
|
|
5632
|
-
const hasChanged = !isShallowEqual(this.outputSettings, state);
|
|
5633
|
-
return {
|
|
5634
|
-
hasChanged,
|
|
5635
|
-
state,
|
|
5636
|
-
commit: () => {
|
|
5637
|
-
this.outputSettings = state;
|
|
5638
|
-
if (hasChanged) {
|
|
5639
|
-
this.outputSettingsUpdateSubject.next(state);
|
|
5640
|
-
}
|
|
5641
|
-
}
|
|
5642
|
-
};
|
|
5643
|
-
}
|
|
5644
6216
|
getOutputSettings(inputSettings) {
|
|
5645
|
-
const computedSettings = this.getComputedSettings(
|
|
6217
|
+
const computedSettings = this.getComputedSettings(inputSettings);
|
|
5646
6218
|
return { ...this.outputSettings, ...inputSettings, ...computedSettings };
|
|
5647
6219
|
}
|
|
5648
6220
|
getDefaultSettings() {
|
|
@@ -5661,18 +6233,7 @@ class ReaderSettingsManager {
|
|
|
5661
6233
|
numberOfAdjacentSpineItemToPreLoad: 0
|
|
5662
6234
|
};
|
|
5663
6235
|
}
|
|
5664
|
-
update(settings) {
|
|
5665
|
-
const { commit } = this._prepareUpdate(settings);
|
|
5666
|
-
commit();
|
|
5667
|
-
}
|
|
5668
|
-
get settings() {
|
|
5669
|
-
return this.outputSettings;
|
|
5670
|
-
}
|
|
5671
|
-
destroy() {
|
|
5672
|
-
this.outputSettingsUpdateSubject.complete();
|
|
5673
|
-
}
|
|
5674
6236
|
}
|
|
5675
|
-
_context = new WeakMap();
|
|
5676
6237
|
class HookManager {
|
|
5677
6238
|
constructor() {
|
|
5678
6239
|
this._hooks = [];
|
|
@@ -5703,7 +6264,9 @@ class HookManager {
|
|
|
5703
6264
|
};
|
|
5704
6265
|
}
|
|
5705
6266
|
execute(name, id, params) {
|
|
5706
|
-
const hooks = this._hooks.filter(
|
|
6267
|
+
const hooks = this._hooks.filter(
|
|
6268
|
+
(hook) => name === hook.name
|
|
6269
|
+
);
|
|
5707
6270
|
const fnResults = hooks.map((hook) => {
|
|
5708
6271
|
let userDestroyFn = () => of(void 0);
|
|
5709
6272
|
const destroySubject = new Subject();
|
|
@@ -5716,7 +6279,11 @@ class HookManager {
|
|
|
5716
6279
|
const result = userDestroyFn();
|
|
5717
6280
|
return result ?? of(void 0);
|
|
5718
6281
|
};
|
|
5719
|
-
const fnResult = hook.runFn({
|
|
6282
|
+
const fnResult = hook.runFn({
|
|
6283
|
+
...params,
|
|
6284
|
+
destroy$: destroySubject.asObservable(),
|
|
6285
|
+
destroy
|
|
6286
|
+
});
|
|
5720
6287
|
this._hookExecutions.push({
|
|
5721
6288
|
name,
|
|
5722
6289
|
id,
|
|
@@ -5735,7 +6302,9 @@ class HookManager {
|
|
|
5735
6302
|
name === hookInstance.name && (!id || id && id === hookInstance.id)
|
|
5736
6303
|
)
|
|
5737
6304
|
);
|
|
5738
|
-
this._hookExecutions = this._hookExecutions.filter(
|
|
6305
|
+
this._hookExecutions = this._hookExecutions.filter(
|
|
6306
|
+
(instance) => !instances.includes(instance)
|
|
6307
|
+
);
|
|
5739
6308
|
const destroyFns = instances.map(({ destroyFn }) => destroyFn());
|
|
5740
6309
|
return combineLatest(destroyFns);
|
|
5741
6310
|
}
|
|
@@ -5756,9 +6325,14 @@ const createReader = (inputSettings) => {
|
|
|
5756
6325
|
const hookManager = new HookManager();
|
|
5757
6326
|
const context = new Context();
|
|
5758
6327
|
const settingsManager = new ReaderSettingsManager(inputSettings, context);
|
|
5759
|
-
const spineItemManager = createSpineItemManager({
|
|
6328
|
+
const spineItemManager = createSpineItemManager({
|
|
6329
|
+
context,
|
|
6330
|
+
settings: settingsManager
|
|
6331
|
+
});
|
|
5760
6332
|
const pagination = createPagination({ context, spineItemManager });
|
|
5761
|
-
const elementSubject$ = new BehaviorSubject(
|
|
6333
|
+
const elementSubject$ = new BehaviorSubject(
|
|
6334
|
+
void 0
|
|
6335
|
+
);
|
|
5762
6336
|
const element$ = elementSubject$.pipe(filter(isDefined));
|
|
5763
6337
|
const spineItemLocator = createLocationResolver$1({ context });
|
|
5764
6338
|
const spineLocator = createLocationResolver({
|
|
@@ -5801,8 +6375,12 @@ const createReader = (inputSettings) => {
|
|
|
5801
6375
|
});
|
|
5802
6376
|
viewportNavigator.$.state$.subscribe(viewportStateSubject);
|
|
5803
6377
|
viewportNavigator.$.navigation$.subscribe(navigationSubject);
|
|
5804
|
-
viewportNavigator.$.navigationAdjustedAfterLayout$.subscribe(
|
|
5805
|
-
|
|
6378
|
+
viewportNavigator.$.navigationAdjustedAfterLayout$.subscribe(
|
|
6379
|
+
navigationAdjustedSubject
|
|
6380
|
+
);
|
|
6381
|
+
viewportNavigator.$.currentNavigationPosition$.subscribe(
|
|
6382
|
+
currentNavigationPositionSubject$
|
|
6383
|
+
);
|
|
5806
6384
|
const layout = () => {
|
|
5807
6385
|
var _a;
|
|
5808
6386
|
const containerElement = (_a = elementSubject$.getValue()) == null ? void 0 : _a.parentElement;
|
|
@@ -5844,7 +6422,11 @@ const createReader = (inputSettings) => {
|
|
|
5844
6422
|
elementSubject$.next(element);
|
|
5845
6423
|
loadOptions.containerElement.appendChild(element);
|
|
5846
6424
|
}
|
|
5847
|
-
context.update({
|
|
6425
|
+
context.update({
|
|
6426
|
+
manifest,
|
|
6427
|
+
...loadOptions,
|
|
6428
|
+
forceSinglePageMode: settingsManager.settings.forceSinglePageMode
|
|
6429
|
+
});
|
|
5848
6430
|
layout();
|
|
5849
6431
|
if (!loadOptions.cfi) {
|
|
5850
6432
|
viewportNavigator.goToSpineItem(0, { animate: false });
|
|
@@ -5929,7 +6511,9 @@ const createReader = (inputSettings) => {
|
|
|
5929
6511
|
* have an effect.
|
|
5930
6512
|
* It can typically be used to hide a loading indicator.
|
|
5931
6513
|
*/
|
|
5932
|
-
loadStatus$: context.manifest$.pipe(
|
|
6514
|
+
loadStatus$: context.manifest$.pipe(
|
|
6515
|
+
map((manifest) => manifest ? "ready" : "idle")
|
|
6516
|
+
),
|
|
5933
6517
|
/**
|
|
5934
6518
|
* Dispatched when a change in selection happens
|
|
5935
6519
|
*/
|
|
@@ -6096,7 +6680,9 @@ const createResourcesManager = (context) => {
|
|
|
6096
6680
|
mergeMap(({ id, data }) => {
|
|
6097
6681
|
const item = retrieveItem(id);
|
|
6098
6682
|
if (!item) return EMPTY;
|
|
6099
|
-
return from(
|
|
6683
|
+
return from(
|
|
6684
|
+
forkJoin([openDatabase(`prose-reader`), from(data.blob())])
|
|
6685
|
+
).pipe(
|
|
6100
6686
|
switchMap$1(([db, blob]) => {
|
|
6101
6687
|
return from(db.put(`${uniqueID}_${item.id}`, blob));
|
|
6102
6688
|
}),
|
|
@@ -6119,7 +6705,9 @@ const createResourcesManager = (context) => {
|
|
|
6119
6705
|
return from(openDatabase(`prose-reader`)).pipe(
|
|
6120
6706
|
switchMap$1(
|
|
6121
6707
|
(db) => from(db.keys()).pipe(
|
|
6122
|
-
map(
|
|
6708
|
+
map(
|
|
6709
|
+
(keys) => keys.filter((key) => !key.toString().startsWith(uniqueID))
|
|
6710
|
+
),
|
|
6123
6711
|
switchMap$1((keysToRemove) => {
|
|
6124
6712
|
const promises = keysToRemove.map((key) => db.remove(key));
|
|
6125
6713
|
return from(Promise.all(promises));
|
|
@@ -6166,7 +6754,9 @@ const mediaEnhancer = (next) => (options) => {
|
|
|
6166
6754
|
entries.forEach((entry) => {
|
|
6167
6755
|
var _a;
|
|
6168
6756
|
const frame = entry.target;
|
|
6169
|
-
const audios = Array.from(
|
|
6757
|
+
const audios = Array.from(
|
|
6758
|
+
((_a = frame.contentDocument) == null ? void 0 : _a.body.getElementsByTagName(`audio`)) || []
|
|
6759
|
+
);
|
|
6170
6760
|
if (!entry.isIntersecting) {
|
|
6171
6761
|
audios.forEach((audioElement) => {
|
|
6172
6762
|
audioElement.pause();
|
|
@@ -6245,7 +6835,11 @@ const progressionEnhancer = (next) => (options) => {
|
|
|
6245
6835
|
let totalProgress = estimateBeforeThisItem + progressWithinThisItem;
|
|
6246
6836
|
if (((_f = context.manifest) == null ? void 0 : _f.renditionFlow) === `scrolled-continuous`) {
|
|
6247
6837
|
if (currentItem.isReady()) {
|
|
6248
|
-
progressWithinThisItem = getScrollPercentageWithinItem(
|
|
6838
|
+
progressWithinThisItem = getScrollPercentageWithinItem(
|
|
6839
|
+
context,
|
|
6840
|
+
currentPosition,
|
|
6841
|
+
currentItem
|
|
6842
|
+
);
|
|
6249
6843
|
} else {
|
|
6250
6844
|
progressWithinThisItem = 0;
|
|
6251
6845
|
}
|
|
@@ -6267,9 +6861,21 @@ const progressionEnhancer = (next) => (options) => {
|
|
|
6267
6861
|
const { height, width } = currentItem.getElementDimensions();
|
|
6268
6862
|
const { top, left } = reader.spineItemManager.getAbsolutePositionOf(currentItem);
|
|
6269
6863
|
if (reader.settings.settings.computedPageTurnDirection === `vertical`) {
|
|
6270
|
-
return Math.max(
|
|
6864
|
+
return Math.max(
|
|
6865
|
+
0,
|
|
6866
|
+
Math.min(
|
|
6867
|
+
1,
|
|
6868
|
+
(currentPosition.y - top + context.state.visibleAreaRect.height) / height
|
|
6869
|
+
)
|
|
6870
|
+
);
|
|
6271
6871
|
} else {
|
|
6272
|
-
return Math.max(
|
|
6872
|
+
return Math.max(
|
|
6873
|
+
0,
|
|
6874
|
+
Math.min(
|
|
6875
|
+
1,
|
|
6876
|
+
(currentPosition.x - left + context.state.visibleAreaRect.width) / width
|
|
6877
|
+
)
|
|
6878
|
+
);
|
|
6273
6879
|
}
|
|
6274
6880
|
};
|
|
6275
6881
|
return {
|
|
@@ -6329,19 +6935,25 @@ const IS_SAFARI = navigator.userAgent.indexOf(``) > -1 && navigator.userAgent.in
|
|
|
6329
6935
|
const webkitEnhancer = (createReader2) => (options) => {
|
|
6330
6936
|
const reader = createReader2(options);
|
|
6331
6937
|
if (IS_SAFARI) {
|
|
6332
|
-
reader.hookManager.register(
|
|
6333
|
-
|
|
6938
|
+
reader.hookManager.register(
|
|
6939
|
+
"viewportNavigator.onBeforeContainerCreated",
|
|
6940
|
+
({ element }) => {
|
|
6941
|
+
element.style.cssText = `
|
|
6334
6942
|
${element.style.cssText}
|
|
6335
6943
|
-webkit-transform-style: preserve-3d;
|
|
6336
6944
|
`;
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6945
|
+
}
|
|
6946
|
+
);
|
|
6947
|
+
reader.hookManager.register(
|
|
6948
|
+
"item.onBeforeContainerCreated",
|
|
6949
|
+
({ element }) => {
|
|
6950
|
+
element.style.cssText = `
|
|
6340
6951
|
${element.style.cssText}
|
|
6341
6952
|
-webkit-transform-style: preserve-3d;
|
|
6342
6953
|
-webkit-backface-visibility: hidden;
|
|
6343
6954
|
`;
|
|
6344
|
-
|
|
6955
|
+
}
|
|
6956
|
+
);
|
|
6345
6957
|
}
|
|
6346
6958
|
return reader;
|
|
6347
6959
|
};
|
|
@@ -6372,14 +6984,20 @@ const loadingEnhancer = (next) => (options) => {
|
|
|
6372
6984
|
tap(({ width, theme }) => {
|
|
6373
6985
|
Object.values(entries).forEach((element) => {
|
|
6374
6986
|
element.style.setProperty(`max-width`, `${width}px`);
|
|
6375
|
-
element.style.setProperty(
|
|
6987
|
+
element.style.setProperty(
|
|
6988
|
+
`color`,
|
|
6989
|
+
theme === `sepia` ? `#939393` : `rgb(202, 202, 202)`
|
|
6990
|
+
);
|
|
6376
6991
|
});
|
|
6377
6992
|
})
|
|
6378
6993
|
);
|
|
6379
6994
|
const updateEntriesVisibility$ = (entries) => reader.spineItemManager.$.itemIsReady$.pipe(
|
|
6380
6995
|
tap(({ item, isReady }) => {
|
|
6381
6996
|
var _a;
|
|
6382
|
-
(_a = entries[item.id]) == null ? void 0 : _a.style.setProperty(
|
|
6997
|
+
(_a = entries[item.id]) == null ? void 0 : _a.style.setProperty(
|
|
6998
|
+
`visibility`,
|
|
6999
|
+
isReady ? `hidden` : `visible`
|
|
7000
|
+
);
|
|
6383
7001
|
})
|
|
6384
7002
|
);
|
|
6385
7003
|
const destroyEntries$ = (entries) => reader.spine.$.itemsBeforeDestroy$.pipe(
|
|
@@ -6395,7 +7013,12 @@ const loadingEnhancer = (next) => (options) => {
|
|
|
6395
7013
|
);
|
|
6396
7014
|
items$.pipe(
|
|
6397
7015
|
switchMap$1((entries) => merge(of(entries), destroyEntries$(entries))),
|
|
6398
|
-
switchMap$1(
|
|
7016
|
+
switchMap$1(
|
|
7017
|
+
(entries) => merge(
|
|
7018
|
+
updateEntriesLayout$(entries),
|
|
7019
|
+
updateEntriesVisibility$(entries)
|
|
7020
|
+
)
|
|
7021
|
+
),
|
|
6399
7022
|
takeUntil$1(reader.$.destroy$)
|
|
6400
7023
|
).subscribe();
|
|
6401
7024
|
return {
|
|
@@ -6465,7 +7088,8 @@ const createNormalizeEventForViewport = ({
|
|
|
6465
7088
|
const eventIsComingFromBridge = event.target === iframeEventBridgeElement$.getValue();
|
|
6466
7089
|
const iframeOriginalEvent = getOriginalFrameEventFromDocumentEvent(event);
|
|
6467
7090
|
const originalFrame = (_a = iframeOriginalEvent == null ? void 0 : iframeOriginalEvent.view) == null ? void 0 : _a.frameElement;
|
|
6468
|
-
if (!eventIsComingFromBridge || !iframeOriginalEvent || !originalFrame)
|
|
7091
|
+
if (!eventIsComingFromBridge || !iframeOriginalEvent || !originalFrame)
|
|
7092
|
+
return event;
|
|
6469
7093
|
const spineItem = locator.getSpineItemFromIframe(originalFrame);
|
|
6470
7094
|
if (!spineItem) return event;
|
|
6471
7095
|
if (isPointerEvent(event)) {
|
|
@@ -6476,7 +7100,10 @@ const createNormalizeEventForViewport = ({
|
|
|
6476
7100
|
clientX,
|
|
6477
7101
|
clientY
|
|
6478
7102
|
});
|
|
6479
|
-
Object.defineProperty(newEvent, `target`, {
|
|
7103
|
+
Object.defineProperty(newEvent, `target`, {
|
|
7104
|
+
value: iframeOriginalEvent.target,
|
|
7105
|
+
enumerable: true
|
|
7106
|
+
});
|
|
6480
7107
|
return newEvent;
|
|
6481
7108
|
}
|
|
6482
7109
|
if (isMouseEvent(event)) {
|
|
@@ -6486,7 +7113,10 @@ const createNormalizeEventForViewport = ({
|
|
|
6486
7113
|
clientX,
|
|
6487
7114
|
clientY
|
|
6488
7115
|
});
|
|
6489
|
-
Object.defineProperty(newEvent, `target`, {
|
|
7116
|
+
Object.defineProperty(newEvent, `target`, {
|
|
7117
|
+
value: iframeOriginalEvent.target,
|
|
7118
|
+
enumerable: true
|
|
7119
|
+
});
|
|
6490
7120
|
return newEvent;
|
|
6491
7121
|
}
|
|
6492
7122
|
if (isTouchEvent(event)) {
|
|
@@ -6504,7 +7134,10 @@ const createNormalizeEventForViewport = ({
|
|
|
6504
7134
|
changedTouches: touches,
|
|
6505
7135
|
targetTouches: touches
|
|
6506
7136
|
});
|
|
6507
|
-
Object.defineProperty(newEvent, `target`, {
|
|
7137
|
+
Object.defineProperty(newEvent, `target`, {
|
|
7138
|
+
value: iframeOriginalEvent.target,
|
|
7139
|
+
enumerable: true
|
|
7140
|
+
});
|
|
6508
7141
|
return newEvent;
|
|
6509
7142
|
}
|
|
6510
7143
|
return event;
|
|
@@ -6646,6 +7279,7 @@ const createReaderWithEnhancers = (
|
|
|
6646
7279
|
export {
|
|
6647
7280
|
HookManager,
|
|
6648
7281
|
Report,
|
|
7282
|
+
SettingsManager3 as SettingsManager,
|
|
6649
7283
|
createReaderWithEnhancers as createReader,
|
|
6650
7284
|
groupBy,
|
|
6651
7285
|
isShallowEqual
|