@prose-reader/core 1.41.0 → 1.42.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/index.d.ts +4366 -8
- package/dist/{prose.js → index.js} +632 -443
- package/dist/index.js.map +1 -0
- package/dist/{prose.umd.cjs → index.umd.cjs} +630 -441
- package/dist/index.umd.cjs.map +1 -0
- package/package.json +7 -7
- package/dist/cfi.d.ts +0 -74
- package/dist/constants.d.ts +0 -6
- package/dist/context.d.ts +0 -44
- package/dist/createReaderWithEnhancer.d.ts +0 -5381
- package/dist/enhancers/accessibility.d.ts +0 -4890
- package/dist/enhancers/chrome.d.ts +0 -4890
- package/dist/enhancers/fonts.d.ts +0 -4904
- package/dist/enhancers/hotkeys.d.ts +0 -4890
- package/dist/enhancers/layoutEnhancer/createMovingSafePan$.d.ts +0 -3
- package/dist/enhancers/layoutEnhancer/fixReflowable.d.ts +0 -2
- package/dist/enhancers/layoutEnhancer/layoutEnhancer.d.ts +0 -4897
- package/dist/enhancers/layoutEnhancer/types.d.ts +0 -8
- package/dist/enhancers/links.d.ts +0 -4900
- package/dist/enhancers/loadingEnhancer.d.ts +0 -4919
- package/dist/enhancers/media.d.ts +0 -4890
- package/dist/enhancers/navigation.d.ts +0 -4893
- package/dist/enhancers/pagination.d.ts +0 -5279
- package/dist/enhancers/progression.d.ts +0 -4903
- package/dist/enhancers/resources/index.d.ts +0 -4890
- package/dist/enhancers/resources/indexedDB.d.ts +0 -6
- package/dist/enhancers/resources/resourcesManager.d.ts +0 -6
- package/dist/enhancers/theme.d.ts +0 -4916
- package/dist/enhancers/types/enhancer.d.ts +0 -4894
- package/dist/enhancers/utils.d.ts +0 -4894
- package/dist/enhancers/webkit.d.ts +0 -4890
- package/dist/enhancers/zoom/elementZoomer.d.ts +0 -18
- package/dist/enhancers/zoom/index.d.ts +0 -4891
- package/dist/enhancers/zoom/types.d.ts +0 -22
- package/dist/enhancers/zoom/viewportZoomer.d.ts +0 -18
- package/dist/frames.d.ts +0 -5
- package/dist/pagination.d.ts +0 -65
- package/dist/prose.js.map +0 -1
- package/dist/prose.umd.cjs.map +0 -1
- package/dist/reader.d.ts +0 -4907
- package/dist/report.d.ts +0 -26
- package/dist/selection.d.ts +0 -6
- package/dist/settings.d.ts +0 -39
- package/dist/spine/cfiLocator.d.ts +0 -371
- package/dist/spine/createSpine.d.ts +0 -29
- package/dist/spine/eventsHelper.d.ts +0 -11
- package/dist/spine/locationResolver.d.ts +0 -697
- package/dist/spine/navigationResolver.d.ts +0 -45
- package/dist/spine/types.d.ts +0 -10
- package/dist/spineItem/commonSpineItem.d.ts +0 -171
- package/dist/spineItem/createSpineItem.d.ts +0 -181
- package/dist/spineItem/frameItem/createFrame$.d.ts +0 -1
- package/dist/spineItem/frameItem/createFrameManipulator.d.ts +0 -5
- package/dist/spineItem/frameItem/createHtmlPageFromResource.d.ts +0 -2
- package/dist/spineItem/frameItem/frameItem.d.ts +0 -46
- package/dist/spineItem/frameItem/loader.d.ts +0 -27
- package/dist/spineItem/locationResolver.d.ts +0 -23
- package/dist/spineItem/navigationResolver.d.ts +0 -13
- package/dist/spineItem/prePaginatedSpineItem.d.ts +0 -180
- package/dist/spineItem/reflowableSpineItem.d.ts +0 -179
- package/dist/spineItem/styles/getStyleForViewportDocument.d.ts +0 -1
- package/dist/spineItem/trackers.d.ts +0 -34
- package/dist/spineItem/types.d.ts +0 -19
- package/dist/spineItemManager.d.ts +0 -550
- package/dist/types/Hook.d.ts +0 -73
- package/dist/types/Spine.d.ts +0 -39
- package/dist/types/index.d.ts +0 -11
- package/dist/utils/dom.d.ts +0 -19
- package/dist/utils/layout.d.ts +0 -7
- package/dist/utils/objects.d.ts +0 -6
- package/dist/utils/rxjs.d.ts +0 -4
- package/dist/viewportNavigator/manualViewportNavigator.d.ts +0 -1440
- package/dist/viewportNavigator/panViewportNavigator.d.ts +0 -215
- package/dist/viewportNavigator/scrollViewportNavigator.d.ts +0 -35
- package/dist/viewportNavigator/types.d.ts +0 -33
- package/dist/viewportNavigator/viewportNavigator.d.ts +0 -71
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { Subject, BehaviorSubject, map,
|
|
2
|
-
import { withLatestFrom, distinctUntilChanged, shareReplay, tap, pairwise, filter, take, map as map$1,
|
|
1
|
+
import { takeUntil, Subject, BehaviorSubject, map, combineLatest, switchMap, merge, EMPTY, fromEvent, withLatestFrom as withLatestFrom$1, NEVER, Observable, of, scheduled, animationFrameScheduler, distinctUntilChanged as distinctUntilChanged$1, filter as filter$1, from, interval, iif, identity, take as take$1, forkJoin } from "rxjs";
|
|
2
|
+
import { withLatestFrom, distinctUntilChanged, shareReplay, tap, pairwise, switchMap as switchMap$1, filter, take, map as map$1, takeUntil as takeUntil$1, skip, debounceTime, startWith, share, exhaustMap, mergeMap, catchError, debounce, delay } from "rxjs/operators";
|
|
3
3
|
import { parseContentType, detectMimeTypeFromName } from "@prose-reader/shared";
|
|
4
|
-
const SHOULD_NOT_LAYOUT$3 = false;
|
|
5
4
|
const chromeEnhancer = (next) => (options) => {
|
|
6
5
|
const reader = next(options);
|
|
7
|
-
reader.
|
|
6
|
+
reader.context$.pipe(takeUntil(reader.$.destroy$)).subscribe(({ containerElement }) => {
|
|
7
|
+
if (!containerElement)
|
|
8
|
+
return;
|
|
8
9
|
const onScroll = () => {
|
|
9
|
-
if (reader.
|
|
10
|
-
|
|
10
|
+
if (reader.settings.getSettings().computedPageTurnMode === `controlled`) {
|
|
11
|
+
containerElement.scrollTo(0, 0);
|
|
11
12
|
}
|
|
12
13
|
};
|
|
13
|
-
|
|
14
|
-
return SHOULD_NOT_LAYOUT$3;
|
|
14
|
+
containerElement.addEventListener(`scroll`, onScroll);
|
|
15
15
|
});
|
|
16
16
|
reader.registerHook(`item.onLoad`, ({ frame }) => {
|
|
17
17
|
var _a;
|
|
@@ -139,30 +139,35 @@ const fontsEnhancer = (next) => (options) => {
|
|
|
139
139
|
);
|
|
140
140
|
newSettings$.subscribe(settings$);
|
|
141
141
|
settings$.pipe(shouldRequireLayout, tap(applyChangeToSpineItem), takeUntil(reader.$.destroy$)).subscribe();
|
|
142
|
-
const settingsMerge$ = combineLatest([reader.settings$, settings$]).pipe(
|
|
142
|
+
const settingsMerge$ = combineLatest([reader.settings.settings$, settings$]).pipe(
|
|
143
143
|
map(([innerSettings, settings]) => ({
|
|
144
144
|
...innerSettings,
|
|
145
145
|
...settings
|
|
146
146
|
}))
|
|
147
147
|
);
|
|
148
|
+
const setSettings = (settings) => {
|
|
149
|
+
const { fontJustification: fontJustification2, fontScale: fontScale2, fontWeight: fontWeight2, lineHeight: lineHeight2, ...passthroughSettings } = settings;
|
|
150
|
+
changes$.next({ fontJustification: fontJustification2, fontScale: fontScale2, fontWeight: fontWeight2, lineHeight: lineHeight2 });
|
|
151
|
+
reader.settings.setSettings(passthroughSettings);
|
|
152
|
+
};
|
|
148
153
|
return {
|
|
149
154
|
...reader,
|
|
150
155
|
destroy: () => {
|
|
151
156
|
changes$.complete();
|
|
152
157
|
settings$.complete();
|
|
158
|
+
reader.destroy();
|
|
153
159
|
},
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
settings$: settingsMerge$
|
|
160
|
+
settings: {
|
|
161
|
+
...reader.settings,
|
|
162
|
+
setSettings,
|
|
163
|
+
settings$: settingsMerge$
|
|
164
|
+
}
|
|
160
165
|
};
|
|
161
166
|
};
|
|
162
167
|
const hotkeysEnhancer = (next) => (options) => {
|
|
163
168
|
const reader = next(options);
|
|
164
169
|
const navigateOnKey = (document2) => fromEvent(document2, "keyup").pipe(
|
|
165
|
-
withLatestFrom$1(reader.settings$),
|
|
170
|
+
withLatestFrom$1(reader.settings.settings$),
|
|
166
171
|
map(([e, { pageTurnDirection }]) => {
|
|
167
172
|
if (pageTurnDirection === "horizontal") {
|
|
168
173
|
if (e.key === `ArrowRight`) {
|
|
@@ -198,22 +203,30 @@ const hotkeysEnhancer = (next) => (options) => {
|
|
|
198
203
|
).subscribe();
|
|
199
204
|
return reader;
|
|
200
205
|
};
|
|
201
|
-
const SHOULD_NOT_LAYOUT$2 = false;
|
|
202
206
|
const createMovingSafePan$ = (reader) => {
|
|
203
207
|
let iframeOverlayForAnimationsElement;
|
|
204
|
-
reader.
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
208
|
+
const updateOverlayElement$ = reader.context$.pipe(
|
|
209
|
+
switchMap$1(({ containerElement }) => {
|
|
210
|
+
if (!containerElement)
|
|
211
|
+
return NEVER;
|
|
212
|
+
return new Observable(() => {
|
|
213
|
+
iframeOverlayForAnimationsElement = containerElement.ownerDocument.createElement(`div`);
|
|
214
|
+
iframeOverlayForAnimationsElement.style.cssText = `
|
|
215
|
+
position: absolute;
|
|
216
|
+
left: 0;
|
|
217
|
+
top: 0;
|
|
218
|
+
width: 100%;
|
|
219
|
+
height: 100%;
|
|
220
|
+
visibility: hidden;
|
|
221
|
+
`;
|
|
222
|
+
containerElement.appendChild(iframeOverlayForAnimationsElement);
|
|
223
|
+
return () => {
|
|
224
|
+
iframeOverlayForAnimationsElement == null ? void 0 : iframeOverlayForAnimationsElement.remove();
|
|
225
|
+
iframeOverlayForAnimationsElement = void 0;
|
|
226
|
+
};
|
|
227
|
+
});
|
|
228
|
+
})
|
|
229
|
+
);
|
|
217
230
|
const createResetLock$ = (source) => scheduled(source, animationFrameScheduler).pipe(
|
|
218
231
|
tap(() => {
|
|
219
232
|
iframeOverlayForAnimationsElement == null ? void 0 : iframeOverlayForAnimationsElement.style.setProperty(`visibility`, `hidden`);
|
|
@@ -227,8 +240,8 @@ const createMovingSafePan$ = (reader) => {
|
|
|
227
240
|
})
|
|
228
241
|
);
|
|
229
242
|
const resetLockViewportFree$ = createResetLock$(viewportFree$).pipe(take(1));
|
|
230
|
-
const pageTurnMode$ = reader.
|
|
231
|
-
map$1(() => reader.
|
|
243
|
+
const pageTurnMode$ = reader.settings.settings$.pipe(
|
|
244
|
+
map$1(() => reader.settings.getSettings().computedPageTurnMode),
|
|
232
245
|
distinctUntilChanged()
|
|
233
246
|
);
|
|
234
247
|
const handleViewportLock$ = pageTurnMode$.pipe(
|
|
@@ -237,7 +250,7 @@ const createMovingSafePan$ = (reader) => {
|
|
|
237
250
|
),
|
|
238
251
|
takeUntil$1(reader.$.destroy$)
|
|
239
252
|
);
|
|
240
|
-
return handleViewportLock
|
|
253
|
+
return merge(updateOverlayElement$, handleViewportLock$);
|
|
241
254
|
};
|
|
242
255
|
const mapKeysTo = (keys) => {
|
|
243
256
|
return map$1((obj) => {
|
|
@@ -273,7 +286,10 @@ const fixReflowable = (reader) => {
|
|
|
273
286
|
}
|
|
274
287
|
});
|
|
275
288
|
};
|
|
276
|
-
|
|
289
|
+
function isDefined(arg) {
|
|
290
|
+
return arg !== null && arg !== void 0;
|
|
291
|
+
}
|
|
292
|
+
const SHOULD_NOT_LAYOUT = false;
|
|
277
293
|
const layoutEnhancer = (next) => (options) => {
|
|
278
294
|
const { pageHorizontalMargin = 24, pageVerticalMargin = 24 } = options;
|
|
279
295
|
const reader = next(options);
|
|
@@ -288,7 +304,7 @@ const layoutEnhancer = (next) => (options) => {
|
|
|
288
304
|
void frame.getBoundingClientRect().left;
|
|
289
305
|
hasRedrawn = true;
|
|
290
306
|
}
|
|
291
|
-
return SHOULD_NOT_LAYOUT
|
|
307
|
+
return SHOULD_NOT_LAYOUT;
|
|
292
308
|
});
|
|
293
309
|
});
|
|
294
310
|
reader.registerHook(`item.onLayoutBeforeMeasurement`, ({ frame, minimumWidth, item, isImageType }) => {
|
|
@@ -333,10 +349,17 @@ const layoutEnhancer = (next) => (options) => {
|
|
|
333
349
|
fixReflowable(reader);
|
|
334
350
|
let observer;
|
|
335
351
|
if (options.layoutAutoResize === `container`) {
|
|
336
|
-
|
|
337
|
-
|
|
352
|
+
reader.context$.pipe(
|
|
353
|
+
map$1((state) => state.containerElement),
|
|
354
|
+
filter(isDefined),
|
|
355
|
+
distinctUntilChanged(),
|
|
356
|
+
takeUntil$1(reader.$.destroy$)
|
|
357
|
+
).subscribe((container) => {
|
|
358
|
+
observer = new ResizeObserver(() => {
|
|
359
|
+
reader == null ? void 0 : reader.layout();
|
|
360
|
+
});
|
|
361
|
+
observer.observe(container);
|
|
338
362
|
});
|
|
339
|
-
observer.observe(options.containerElement);
|
|
340
363
|
}
|
|
341
364
|
const movingSafePan$ = createMovingSafePan$(reader);
|
|
342
365
|
movingSafePan$.subscribe();
|
|
@@ -349,27 +372,32 @@ const layoutEnhancer = (next) => (options) => {
|
|
|
349
372
|
}),
|
|
350
373
|
takeUntil$1(reader.$.destroy$)
|
|
351
374
|
).subscribe();
|
|
375
|
+
const settings$ = combineLatest([reader.settings.settings$, settingsSubject$.asObservable()]).pipe(
|
|
376
|
+
map$1(([innerSettings, settings]) => ({
|
|
377
|
+
...innerSettings,
|
|
378
|
+
...settings
|
|
379
|
+
}))
|
|
380
|
+
);
|
|
381
|
+
const setSettings = ({ pageVerticalMargin: pageVerticalMargin2, pageHorizontalMargin: pageHorizontalMargin2, ...rest }) => {
|
|
382
|
+
if (pageHorizontalMargin2 !== void 0 || pageVerticalMargin2 !== void 0) {
|
|
383
|
+
settingsSubject$.next({
|
|
384
|
+
pageHorizontalMargin: pageHorizontalMargin2 ?? settingsSubject$.value.pageHorizontalMargin,
|
|
385
|
+
pageVerticalMargin: pageVerticalMargin2 ?? settingsSubject$.value.pageVerticalMargin
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
reader.settings.setSettings(rest);
|
|
389
|
+
};
|
|
352
390
|
return {
|
|
353
391
|
...reader,
|
|
354
392
|
destroy: () => {
|
|
355
393
|
reader.destroy();
|
|
356
394
|
observer == null ? void 0 : observer.disconnect();
|
|
357
395
|
},
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
reader.setSettings(rest);
|
|
366
|
-
},
|
|
367
|
-
settings$: combineLatest([reader.settings$, settingsSubject$.asObservable()]).pipe(
|
|
368
|
-
map$1(([innerSettings, settings]) => ({
|
|
369
|
-
...innerSettings,
|
|
370
|
-
...settings
|
|
371
|
-
}))
|
|
372
|
-
)
|
|
396
|
+
settings: {
|
|
397
|
+
...reader.settings,
|
|
398
|
+
setSettings,
|
|
399
|
+
settings$
|
|
400
|
+
}
|
|
373
401
|
};
|
|
374
402
|
};
|
|
375
403
|
const ROOT_NAMESPACE = `@prose-reader/core`;
|
|
@@ -461,13 +489,15 @@ const linksEnhancer = (next) => (options) => {
|
|
|
461
489
|
const handleNavigationForClick = (element) => {
|
|
462
490
|
var _a;
|
|
463
491
|
if (!element.href)
|
|
464
|
-
return;
|
|
492
|
+
return false;
|
|
465
493
|
const hrefUrl = new URL(element.href);
|
|
466
494
|
const hrefWithoutAnchor = `${hrefUrl.origin}${hrefUrl.pathname}`;
|
|
467
495
|
const hasExistingSpineItem = (_a = reader.context.getManifest()) == null ? void 0 : _a.spineItems.some((item) => item.href === hrefWithoutAnchor);
|
|
468
496
|
if (hasExistingSpineItem) {
|
|
469
497
|
reader.goToUrl(hrefUrl);
|
|
498
|
+
return true;
|
|
470
499
|
}
|
|
500
|
+
return false;
|
|
471
501
|
};
|
|
472
502
|
reader.registerHook(`item.onLoad`, ({ frame }) => {
|
|
473
503
|
if (frame.contentDocument) {
|
|
@@ -476,8 +506,8 @@ const linksEnhancer = (next) => (options) => {
|
|
|
476
506
|
if (e.target && `style` in e.target && `ELEMENT_NODE` in e.target) {
|
|
477
507
|
Report.warn(`prevented click on`, element, e);
|
|
478
508
|
e.preventDefault();
|
|
479
|
-
handleNavigationForClick(element);
|
|
480
|
-
subject.next({ event: `linkClicked`, data: element });
|
|
509
|
+
const isNavigable = handleNavigationForClick(element);
|
|
510
|
+
subject.next({ event: `linkClicked`, data: element, isNavigable });
|
|
481
511
|
}
|
|
482
512
|
})
|
|
483
513
|
);
|
|
@@ -491,8 +521,7 @@ const linksEnhancer = (next) => (options) => {
|
|
|
491
521
|
}
|
|
492
522
|
};
|
|
493
523
|
};
|
|
494
|
-
const
|
|
495
|
-
const reader = next(options);
|
|
524
|
+
const createNavigator = (reader) => {
|
|
496
525
|
const goToNextSpineItem = () => {
|
|
497
526
|
var _a;
|
|
498
527
|
const focusedSpineItemIndex = reader.getFocusedSpineItemIndex() || 0;
|
|
@@ -512,14 +541,19 @@ const navigationEnhancer = (next) => (options) => {
|
|
|
512
541
|
}
|
|
513
542
|
};
|
|
514
543
|
return {
|
|
515
|
-
|
|
544
|
+
goToNextSpineItem,
|
|
545
|
+
goToPreviousSpineItem,
|
|
516
546
|
goToLeftSpineItem: () => {
|
|
547
|
+
if (reader.settings.getSettings().computedPageTurnDirection === "vertical")
|
|
548
|
+
return;
|
|
517
549
|
if (reader.context.isRTL()) {
|
|
518
550
|
return goToNextSpineItem();
|
|
519
551
|
}
|
|
520
552
|
return goToPreviousSpineItem();
|
|
521
553
|
},
|
|
522
554
|
goToRightSpineItem: () => {
|
|
555
|
+
if (reader.settings.getSettings().computedPageTurnDirection === "vertical")
|
|
556
|
+
return;
|
|
523
557
|
if (reader.context.isRTL()) {
|
|
524
558
|
return goToPreviousSpineItem();
|
|
525
559
|
}
|
|
@@ -527,15 +561,44 @@ const navigationEnhancer = (next) => (options) => {
|
|
|
527
561
|
}
|
|
528
562
|
};
|
|
529
563
|
};
|
|
564
|
+
const createState = (reader) => {
|
|
565
|
+
return reader.pagination.paginationInfo$.pipe(
|
|
566
|
+
withLatestFrom$1(reader.context.$.manifest$, reader.settings.settings$),
|
|
567
|
+
map(([paginationInfo, manifest, { computedPageTurnDirection }]) => {
|
|
568
|
+
const numberOfSpineItems = (manifest == null ? void 0 : manifest.spineItems.length) ?? 0;
|
|
569
|
+
const isAtAbsoluteBeginning = paginationInfo.beginSpineItemIndex === 0 && paginationInfo.beginPageIndexInSpineItem === 0;
|
|
570
|
+
const isAtAbsoluteEnd = paginationInfo.endPageIndexInSpineItem === paginationInfo.endNumberOfPagesInSpineItem - 1 && paginationInfo.endSpineItemIndex === Math.max(numberOfSpineItems - 1, 0);
|
|
571
|
+
return {
|
|
572
|
+
canGoTopSpineItem: computedPageTurnDirection === "vertical" && !isAtAbsoluteBeginning,
|
|
573
|
+
canGoBottomSpineItem: computedPageTurnDirection === "vertical" && !isAtAbsoluteEnd,
|
|
574
|
+
canGoLeftSpineItem: computedPageTurnDirection !== "vertical" && ((manifest == null ? void 0 : manifest.readingDirection) === "ltr" && !isAtAbsoluteBeginning || (manifest == null ? void 0 : manifest.readingDirection) === "rtl" && !isAtAbsoluteEnd),
|
|
575
|
+
canGoRightSpineItem: computedPageTurnDirection !== "vertical" && ((manifest == null ? void 0 : manifest.readingDirection) === "ltr" && !isAtAbsoluteEnd || (manifest == null ? void 0 : manifest.readingDirection) === "rtl" && !isAtAbsoluteBeginning)
|
|
576
|
+
};
|
|
577
|
+
}),
|
|
578
|
+
distinctUntilChanged$1(isShallowEqual)
|
|
579
|
+
);
|
|
580
|
+
};
|
|
581
|
+
const navigationEnhancer = (next) => (options) => {
|
|
582
|
+
const reader = next(options);
|
|
583
|
+
const state$ = createState(reader);
|
|
584
|
+
const navigator2 = createNavigator(reader);
|
|
585
|
+
return {
|
|
586
|
+
...reader,
|
|
587
|
+
navigation: {
|
|
588
|
+
...navigator2,
|
|
589
|
+
state$
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
};
|
|
530
593
|
const NAMESPACE$6 = `pagination`;
|
|
531
594
|
const createPagination = ({ context }) => {
|
|
532
595
|
const paginationSubject$ = new BehaviorSubject({
|
|
533
|
-
|
|
534
|
-
|
|
596
|
+
beginPageIndexInSpineItem: void 0,
|
|
597
|
+
beginNumberOfPagesInSpineItem: 0,
|
|
535
598
|
beginCfi: void 0,
|
|
536
599
|
beginSpineItemIndex: void 0,
|
|
537
|
-
|
|
538
|
-
|
|
600
|
+
endPageIndexInSpineItem: void 0,
|
|
601
|
+
endNumberOfPagesInSpineItem: 0,
|
|
539
602
|
endCfi: void 0,
|
|
540
603
|
endSpineItemIndex: void 0
|
|
541
604
|
});
|
|
@@ -562,12 +625,12 @@ const createPagination = ({ context }) => {
|
|
|
562
625
|
const beginInfo = getInfoForUpdate(begin);
|
|
563
626
|
const endInfo = getInfoForUpdate(end);
|
|
564
627
|
const newValues = {
|
|
565
|
-
|
|
566
|
-
|
|
628
|
+
beginPageIndexInSpineItem: beginInfo.pageIndex,
|
|
629
|
+
beginNumberOfPagesInSpineItem: beginInfo.numberOfPages,
|
|
567
630
|
beginCfi: beginInfo.cfi,
|
|
568
631
|
beginSpineItemIndex: begin.spineItemIndex,
|
|
569
|
-
|
|
570
|
-
|
|
632
|
+
endPageIndexInSpineItem: endInfo.pageIndex,
|
|
633
|
+
endNumberOfPagesInSpineItem: endInfo.numberOfPages,
|
|
571
634
|
endCfi: endInfo.cfi,
|
|
572
635
|
endSpineItemIndex: end.spineItemIndex
|
|
573
636
|
};
|
|
@@ -578,18 +641,19 @@ const createPagination = ({ context }) => {
|
|
|
578
641
|
},
|
|
579
642
|
{ disable: true }
|
|
580
643
|
);
|
|
581
|
-
const
|
|
582
|
-
const
|
|
644
|
+
const getPaginationInfo = () => paginationSubject$.value;
|
|
645
|
+
const paginationInfo$ = paginationSubject$.pipe(
|
|
646
|
+
distinctUntilChanged$1(isShallowEqual),
|
|
647
|
+
filter$1(({ beginPageIndexInSpineItem }) => beginPageIndexInSpineItem !== void 0)
|
|
648
|
+
);
|
|
583
649
|
const destroy = () => {
|
|
584
650
|
paginationSubject$.complete();
|
|
585
651
|
};
|
|
586
652
|
return {
|
|
587
653
|
destroy,
|
|
588
654
|
updateBeginAndEnd,
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
info$
|
|
592
|
-
}
|
|
655
|
+
getPaginationInfo,
|
|
656
|
+
paginationInfo$
|
|
593
657
|
};
|
|
594
658
|
};
|
|
595
659
|
const getItemOffsetFromPageIndex = (pageWidth, pageIndex, itemWidth) => {
|
|
@@ -620,15 +684,10 @@ const paginationEnhancer = (next) => (options) => {
|
|
|
620
684
|
};
|
|
621
685
|
const mapPaginationInfoToExtendedInfo = (paginationInfo) => {
|
|
622
686
|
const context = reader.context;
|
|
623
|
-
const manifest = context.getManifest();
|
|
624
|
-
const numberOfSpineItems = (manifest == null ? void 0 : manifest.spineItems.length) ?? 0;
|
|
625
687
|
const beginItem = paginationInfo.beginSpineItemIndex !== void 0 ? reader.getSpineItem(paginationInfo.beginSpineItemIndex) : void 0;
|
|
626
688
|
const endItem = paginationInfo.endSpineItemIndex !== void 0 ? reader.getSpineItem(paginationInfo.endSpineItemIndex) : void 0;
|
|
627
|
-
const isAtAbsoluteBeginning = paginationInfo.beginSpineItemIndex === 0 && paginationInfo.beginPageIndex === 0;
|
|
628
|
-
const isAtAbsoluteEnd = paginationInfo.endPageIndex === paginationInfo.endNumberOfPages - 1 && paginationInfo.endSpineItemIndex === Math.max(numberOfSpineItems - 1, 0);
|
|
629
689
|
return {
|
|
630
|
-
|
|
631
|
-
beginNumberOfPagesInChapter: paginationInfo.beginNumberOfPages,
|
|
690
|
+
...paginationInfo,
|
|
632
691
|
beginChapterInfo: beginItem ? chaptersInfo[beginItem.item.id] : void 0,
|
|
633
692
|
// chapterIndex: number;
|
|
634
693
|
// pages: number;
|
|
@@ -640,15 +699,9 @@ const paginationEnhancer = (next) => (options) => {
|
|
|
640
699
|
// domIndex: number;
|
|
641
700
|
// charOffset: number;
|
|
642
701
|
// serializeString?: string;
|
|
643
|
-
beginSpineItemIndex: paginationInfo.beginSpineItemIndex,
|
|
644
|
-
beginCfi: paginationInfo.beginCfi,
|
|
645
702
|
beginSpineItemReadingDirection: beginItem == null ? void 0 : beginItem.getReadingDirection(),
|
|
646
703
|
endChapterInfo: endItem ? chaptersInfo[endItem.item.id] : void 0,
|
|
647
|
-
endPageIndexInChapter: paginationInfo.endPageIndex,
|
|
648
|
-
endNumberOfPagesInChapter: paginationInfo.endNumberOfPages,
|
|
649
|
-
endSpineItemIndex: paginationInfo.endSpineItemIndex,
|
|
650
704
|
endSpineItemReadingDirection: endItem == null ? void 0 : endItem.getReadingDirection(),
|
|
651
|
-
endCfi: paginationInfo.endCfi,
|
|
652
705
|
// spineItemReadingDirection: focusedSpineItem?.getReadingDirection(),
|
|
653
706
|
/**
|
|
654
707
|
* This percentage is based of the weight (kb) of every items and the number of pages.
|
|
@@ -659,23 +712,21 @@ const paginationEnhancer = (next) => (options) => {
|
|
|
659
712
|
percentageEstimateOfBook: endItem ? reader.progression.getPercentageEstimate(
|
|
660
713
|
context,
|
|
661
714
|
paginationInfo.endSpineItemIndex ?? 0,
|
|
662
|
-
paginationInfo.
|
|
663
|
-
paginationInfo.
|
|
715
|
+
paginationInfo.endNumberOfPagesInSpineItem,
|
|
716
|
+
paginationInfo.endPageIndexInSpineItem || 0,
|
|
664
717
|
reader.getCurrentViewportPosition(),
|
|
665
718
|
endItem
|
|
666
719
|
) : 0,
|
|
667
|
-
isUsingSpread: context.
|
|
720
|
+
isUsingSpread: context.isUsingSpreadMode() ?? false
|
|
668
721
|
// hasNextChapter: (reader.spine.spineItemIndex || 0) < (manifest.readingOrder.length - 1),
|
|
669
722
|
// hasPreviousChapter: (reader.spine.spineItemIndex || 0) < (manifest.readingOrder.length - 1),
|
|
670
723
|
// numberOfSpineItems: context.getManifest()?.readingOrder.length,
|
|
671
|
-
canGoLeft: (manifest == null ? void 0 : manifest.readingDirection) === "ltr" && !isAtAbsoluteBeginning || (manifest == null ? void 0 : manifest.readingDirection) === "rtl" && !isAtAbsoluteEnd,
|
|
672
|
-
canGoRight: (manifest == null ? void 0 : manifest.readingDirection) === "ltr" && !isAtAbsoluteEnd || (manifest == null ? void 0 : manifest.readingDirection) === "rtl" && !isAtAbsoluteBeginning
|
|
673
724
|
};
|
|
674
725
|
};
|
|
675
726
|
const getSpineItemNumberOfPages = (spineItem) => {
|
|
676
727
|
const writingMode = spineItem.spineItemFrame.getWritingMode();
|
|
677
728
|
const { width, height } = spineItem.getElementDimensions();
|
|
678
|
-
const settings = reader.
|
|
729
|
+
const settings = reader.settings.getSettings();
|
|
679
730
|
if (settings.pageTurnDirection === `vertical` && settings.pageTurnMode === `scrollable`) {
|
|
680
731
|
return 1;
|
|
681
732
|
}
|
|
@@ -695,7 +746,7 @@ const paginationEnhancer = (next) => (options) => {
|
|
|
695
746
|
),
|
|
696
747
|
takeUntil$1(reader.$.destroy$)
|
|
697
748
|
).subscribe();
|
|
698
|
-
const innerPaginationExtendedInfo$ = reader.pagination$.pipe(
|
|
749
|
+
const innerPaginationExtendedInfo$ = reader.pagination.paginationInfo$.pipe(
|
|
699
750
|
map$1((info) => ({
|
|
700
751
|
...info,
|
|
701
752
|
...mapPaginationInfoToExtendedInfo(info)
|
|
@@ -704,7 +755,7 @@ const paginationEnhancer = (next) => (options) => {
|
|
|
704
755
|
);
|
|
705
756
|
const totalPages$ = reader.$.layout$.pipe(
|
|
706
757
|
debounceTime(10, animationFrameScheduler),
|
|
707
|
-
withLatestFrom(reader.pagination$),
|
|
758
|
+
withLatestFrom(reader.pagination.paginationInfo$),
|
|
708
759
|
map$1(() => {
|
|
709
760
|
const numberOfPagesPerItems = getNumberOfPagesPerItems();
|
|
710
761
|
return {
|
|
@@ -721,19 +772,25 @@ const paginationEnhancer = (next) => (options) => {
|
|
|
721
772
|
numberOfTotalPages: 0
|
|
722
773
|
})
|
|
723
774
|
);
|
|
724
|
-
const
|
|
775
|
+
const paginationInfo$ = combineLatest([
|
|
776
|
+
innerPaginationExtendedInfo$,
|
|
777
|
+
totalPages$
|
|
778
|
+
]).pipe(
|
|
725
779
|
map$1(([pageInfo, totalPageInfo]) => ({
|
|
726
780
|
...pageInfo,
|
|
727
781
|
...totalPageInfo,
|
|
728
|
-
beginAbsolutePageIndex: totalPageInfo.numberOfPagesPerItems.slice(0, pageInfo.beginSpineItemIndex).reduce((acc, numberOfPagesForItem) => acc + numberOfPagesForItem, pageInfo.
|
|
729
|
-
endAbsolutePageIndex: totalPageInfo.numberOfPagesPerItems.slice(0, pageInfo.endSpineItemIndex).reduce((acc, numberOfPagesForItem) => acc + numberOfPagesForItem, pageInfo.
|
|
782
|
+
beginAbsolutePageIndex: totalPageInfo.numberOfPagesPerItems.slice(0, pageInfo.beginSpineItemIndex).reduce((acc, numberOfPagesForItem) => acc + numberOfPagesForItem, pageInfo.beginPageIndexInSpineItem ?? 0),
|
|
783
|
+
endAbsolutePageIndex: totalPageInfo.numberOfPagesPerItems.slice(0, pageInfo.endSpineItemIndex).reduce((acc, numberOfPagesForItem) => acc + numberOfPagesForItem, pageInfo.endPageIndexInSpineItem ?? 0)
|
|
730
784
|
})),
|
|
731
785
|
shareReplay(1),
|
|
732
786
|
takeUntil$1(reader.$.destroy$)
|
|
733
787
|
);
|
|
734
788
|
return {
|
|
735
789
|
...reader,
|
|
736
|
-
pagination
|
|
790
|
+
pagination: {
|
|
791
|
+
...reader.pagination,
|
|
792
|
+
paginationInfo$
|
|
793
|
+
}
|
|
737
794
|
};
|
|
738
795
|
};
|
|
739
796
|
const buildChapterInfoFromSpineItem = (manifest, item) => {
|
|
@@ -854,7 +911,6 @@ const themeEnhancer = (next) => (options) => {
|
|
|
854
911
|
}
|
|
855
912
|
};
|
|
856
913
|
};
|
|
857
|
-
const SHOULD_NOT_LAYOUT = false;
|
|
858
914
|
const createElementZoomer = (reader) => {
|
|
859
915
|
const isZooming$ = new BehaviorSubject(false);
|
|
860
916
|
let imageMagnifierContainer;
|
|
@@ -867,7 +923,8 @@ const createElementZoomer = (reader) => {
|
|
|
867
923
|
imgLastPosition = { x: 0, y: 0 };
|
|
868
924
|
baseScale = 1;
|
|
869
925
|
lastUserScale = 1;
|
|
870
|
-
reader.
|
|
926
|
+
const container = reader.context.getState().containerElement;
|
|
927
|
+
if (container) {
|
|
871
928
|
imageMagnifierContainer = container.ownerDocument.createElement(`div`);
|
|
872
929
|
imageMagnifierContainer.style.cssText = `
|
|
873
930
|
top: 0;
|
|
@@ -878,6 +935,7 @@ const createElementZoomer = (reader) => {
|
|
|
878
935
|
background: black;
|
|
879
936
|
width: 100%;
|
|
880
937
|
height: 100%;
|
|
938
|
+
user-select: none;
|
|
881
939
|
`;
|
|
882
940
|
const clonedImgElement = imgElement.cloneNode();
|
|
883
941
|
clonedImgElement.src = imgElement.src;
|
|
@@ -887,8 +945,7 @@ const createElementZoomer = (reader) => {
|
|
|
887
945
|
clonedImgElement.style.setProperty(`pointer-events`, `none`);
|
|
888
946
|
imageMagnifierContainer.appendChild(clonedImgElement);
|
|
889
947
|
container.appendChild(imageMagnifierContainer);
|
|
890
|
-
|
|
891
|
-
});
|
|
948
|
+
}
|
|
892
949
|
scale(1.2);
|
|
893
950
|
setCurrentScaleAsBase();
|
|
894
951
|
};
|
|
@@ -911,14 +968,14 @@ const createElementZoomer = (reader) => {
|
|
|
911
968
|
const move = (delta, { isFirst, isLast }) => {
|
|
912
969
|
const imgElement = imageMagnifierContainer == null ? void 0 : imageMagnifierContainer.querySelector(`img`);
|
|
913
970
|
if (isFirst) {
|
|
914
|
-
movingLastDelta =
|
|
971
|
+
movingLastDelta = delta;
|
|
915
972
|
}
|
|
916
973
|
if (delta) {
|
|
917
|
-
const
|
|
918
|
-
const
|
|
974
|
+
const newOffsetX = delta.x - ((movingLastDelta == null ? void 0 : movingLastDelta.x) || 0);
|
|
975
|
+
const newOffsetY = delta.y - ((movingLastDelta == null ? void 0 : movingLastDelta.y) || 0);
|
|
919
976
|
imgLastPosition = {
|
|
920
|
-
x: imgLastPosition.x +
|
|
921
|
-
y: imgLastPosition.y +
|
|
977
|
+
x: imgLastPosition.x + newOffsetX,
|
|
978
|
+
y: imgLastPosition.y + newOffsetY
|
|
922
979
|
};
|
|
923
980
|
imgElement == null ? void 0 : imgElement.style.setProperty(
|
|
924
981
|
`transform`,
|
|
@@ -932,11 +989,8 @@ const createElementZoomer = (reader) => {
|
|
|
932
989
|
};
|
|
933
990
|
const exit = () => {
|
|
934
991
|
lastUserScale = 1;
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
imageMagnifierContainer = void 0;
|
|
938
|
-
return SHOULD_NOT_LAYOUT;
|
|
939
|
-
});
|
|
992
|
+
imageMagnifierContainer == null ? void 0 : imageMagnifierContainer.remove();
|
|
993
|
+
imageMagnifierContainer = void 0;
|
|
940
994
|
isZooming$.next(false);
|
|
941
995
|
};
|
|
942
996
|
const _isZooming = () => isZooming$.value;
|
|
@@ -980,7 +1034,10 @@ const createViewportZoomer = (reader) => {
|
|
|
980
1034
|
};
|
|
981
1035
|
const enter = () => {
|
|
982
1036
|
reset();
|
|
983
|
-
reader.spine.
|
|
1037
|
+
const spineElement = reader.spine.getElement();
|
|
1038
|
+
if (spineElement) {
|
|
1039
|
+
spineElement.style.transformOrigin = `0 0`;
|
|
1040
|
+
}
|
|
984
1041
|
isZooming$.next(true);
|
|
985
1042
|
scale(1);
|
|
986
1043
|
setCurrentScaleAsBase();
|
|
@@ -989,23 +1046,27 @@ const createViewportZoomer = (reader) => {
|
|
|
989
1046
|
baseScale = lastUserScale;
|
|
990
1047
|
};
|
|
991
1048
|
const scale = (userScale) => {
|
|
1049
|
+
const spineElement = reader.spine.getElement();
|
|
1050
|
+
const viewportElement = reader.viewportNavigator.getElement();
|
|
1051
|
+
if (!spineElement || !viewportElement)
|
|
1052
|
+
return;
|
|
992
1053
|
const roundedScale = Math.ceil((userScale < 1 ? baseScale - (1 - userScale) : baseScale + (userScale - 1)) * 100) / 100;
|
|
993
1054
|
const newScale = Math.max(roundedScale, 1);
|
|
994
|
-
const currentScale =
|
|
995
|
-
const currentScrollTop =
|
|
996
|
-
|
|
997
|
-
|
|
1055
|
+
const currentScale = spineElement.getBoundingClientRect().width / spineElement.offsetWidth;
|
|
1056
|
+
const currentScrollTop = viewportElement.scrollTop;
|
|
1057
|
+
spineElement.style.transform = `scale(${newScale})`;
|
|
1058
|
+
viewportElement.scrollLeft = getNewScaledOffset({
|
|
998
1059
|
newScale,
|
|
999
1060
|
oldScale: currentScale,
|
|
1000
|
-
pageSize:
|
|
1001
|
-
screenSize:
|
|
1002
|
-
scrollOffset:
|
|
1061
|
+
pageSize: viewportElement.clientWidth,
|
|
1062
|
+
screenSize: spineElement.offsetWidth,
|
|
1063
|
+
scrollOffset: viewportElement.scrollLeft
|
|
1003
1064
|
});
|
|
1004
|
-
|
|
1065
|
+
viewportElement.scrollTop = getNewScaledOffset({
|
|
1005
1066
|
newScale,
|
|
1006
1067
|
oldScale: currentScale,
|
|
1007
|
-
pageSize:
|
|
1008
|
-
screenSize:
|
|
1068
|
+
pageSize: viewportElement.clientHeight,
|
|
1069
|
+
screenSize: spineElement.offsetHeight,
|
|
1009
1070
|
scrollOffset: currentScrollTop
|
|
1010
1071
|
});
|
|
1011
1072
|
lastUserScale = newScale;
|
|
@@ -1037,7 +1098,7 @@ const zoomEnhancer = (next) => (options) => {
|
|
|
1037
1098
|
const elementZoomer = createElementZoomer(reader);
|
|
1038
1099
|
const viewportZoomer = createViewportZoomer(reader);
|
|
1039
1100
|
const currentZoomerSubject$ = new BehaviorSubject(void 0);
|
|
1040
|
-
const isUsingScrollableViewport = () => reader.
|
|
1101
|
+
const isUsingScrollableViewport = () => reader.settings.getSettings().computedPageTurnMode === `scrollable`;
|
|
1041
1102
|
const enter = (imgElement) => {
|
|
1042
1103
|
var _a;
|
|
1043
1104
|
(_a = currentZoomerSubject$ == null ? void 0 : currentZoomerSubject$.value) == null ? void 0 : _a.exit();
|
|
@@ -1103,83 +1164,44 @@ const zoomEnhancer = (next) => (options) => {
|
|
|
1103
1164
|
}
|
|
1104
1165
|
};
|
|
1105
1166
|
};
|
|
1106
|
-
const
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
numberOfAdjacentSpineItemToPreLoad: 0,
|
|
1120
|
-
...initialSettings
|
|
1121
|
-
};
|
|
1122
|
-
updateComputedSettings(void 0, mergedSettings, false);
|
|
1123
|
-
const settingsSubject$ = new BehaviorSubject(mergedSettings);
|
|
1124
|
-
const setSettings = (newSettings, options) => {
|
|
1125
|
-
if (Object.keys(newSettings).length === 0)
|
|
1126
|
-
return;
|
|
1127
|
-
const newMergedSettings = { ...settingsSubject$.value, ...newSettings };
|
|
1128
|
-
updateComputedSettings(options.manifest, newMergedSettings, options.hasVerticalWritingSubject);
|
|
1129
|
-
settingsSubject$.next(newMergedSettings);
|
|
1130
|
-
};
|
|
1131
|
-
const recompute = (options) => {
|
|
1132
|
-
const newMergedSettings = { ...settingsSubject$.value };
|
|
1133
|
-
updateComputedSettings(options.manifest, newMergedSettings, options.hasVerticalWritingSubject);
|
|
1134
|
-
settingsSubject$.next(newMergedSettings);
|
|
1135
|
-
};
|
|
1136
|
-
const destroy = () => {
|
|
1137
|
-
settingsSubject$.complete();
|
|
1138
|
-
};
|
|
1139
|
-
return {
|
|
1140
|
-
getSettings: () => settingsSubject$.value,
|
|
1141
|
-
setSettings,
|
|
1142
|
-
recompute,
|
|
1143
|
-
destroy,
|
|
1144
|
-
$: {
|
|
1145
|
-
settings$: settingsSubject$.asObservable().pipe(distinctUntilChanged(isShallowEqual))
|
|
1146
|
-
}
|
|
1147
|
-
};
|
|
1148
|
-
};
|
|
1149
|
-
const areAllItemsPrePaginated$1 = (manifest) => !(manifest == null ? void 0 : manifest.spineItems.some((item) => item.renditionLayout === `reflowable`));
|
|
1150
|
-
const updateComputedSettings = (newManifest, settings, hasVerticalWriting) => {
|
|
1151
|
-
settings.computedPageTurnDirection = settings.pageTurnDirection;
|
|
1152
|
-
settings.computedPageTurnAnimation = settings.pageTurnAnimation;
|
|
1153
|
-
settings.computedPageTurnMode = `controlled`;
|
|
1154
|
-
if ((newManifest == null ? void 0 : newManifest.renditionFlow) === `scrolled-continuous`) {
|
|
1155
|
-
settings.computedPageTurnMode = `scrollable`;
|
|
1156
|
-
settings.computedPageTurnDirection = `vertical`;
|
|
1157
|
-
} else if (newManifest && settings.pageTurnMode === `scrollable` && (newManifest.renditionLayout !== `pre-paginated` || !areAllItemsPrePaginated$1(newManifest))) {
|
|
1158
|
-
Report.warn(`pageTurnMode ${settings.pageTurnMode} incompatible with current book, switching back to default`);
|
|
1159
|
-
settings.computedPageTurnAnimation = `none`;
|
|
1160
|
-
settings.computedPageTurnMode = `controlled`;
|
|
1161
|
-
} else if (settings.pageTurnMode === `scrollable`) {
|
|
1162
|
-
settings.computedPageTurnMode = `scrollable`;
|
|
1163
|
-
settings.computedPageTurnDirection = `vertical`;
|
|
1164
|
-
}
|
|
1165
|
-
if (hasVerticalWriting && settings.computedPageTurnAnimation === `slide`) {
|
|
1166
|
-
Report.warn(
|
|
1167
|
-
`pageTurnAnimation ${settings.computedPageTurnAnimation} incompatible with current book, switching back to default`
|
|
1168
|
-
);
|
|
1169
|
-
settings.computedPageTurnAnimation = `none`;
|
|
1170
|
-
}
|
|
1171
|
-
if (settings.computedPageTurnMode === `scrollable`) {
|
|
1172
|
-
settings.computedPageTurnAnimationDuration = 0;
|
|
1173
|
-
settings.computedPageTurnAnimation = `none`;
|
|
1174
|
-
} else {
|
|
1175
|
-
settings.computedPageTurnAnimationDuration = settings.pageTurnAnimationDuration !== void 0 ? settings.pageTurnAnimationDuration : 300;
|
|
1167
|
+
const isUsingSpreadMode = ({
|
|
1168
|
+
manifest,
|
|
1169
|
+
visibleAreaRect,
|
|
1170
|
+
forceSinglePageMode
|
|
1171
|
+
}) => {
|
|
1172
|
+
const { height, width } = visibleAreaRect;
|
|
1173
|
+
const isLandscape = width > height;
|
|
1174
|
+
if (forceSinglePageMode)
|
|
1175
|
+
return false;
|
|
1176
|
+
if ((manifest == null ? void 0 : manifest.renditionFlow) === `scrolled-continuous`)
|
|
1177
|
+
return false;
|
|
1178
|
+
if (!isLandscape && (manifest == null ? void 0 : manifest.renditionSpread) === `portrait`) {
|
|
1179
|
+
return true;
|
|
1176
1180
|
}
|
|
1181
|
+
return isLandscape && ((manifest == null ? void 0 : manifest.renditionSpread) === void 0 || (manifest == null ? void 0 : manifest.renditionSpread) === `auto` || (manifest == null ? void 0 : manifest.renditionSpread) === `landscape` || (manifest == null ? void 0 : manifest.renditionSpread) === `both`);
|
|
1177
1182
|
};
|
|
1178
|
-
const
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
const
|
|
1182
|
-
|
|
1183
|
+
const isFullyPrePaginated = (manifest) => (manifest == null ? void 0 : manifest.renditionLayout) === "pre-paginated" || (manifest == null ? void 0 : manifest.spineItems.every((item) => item.renditionLayout === "pre-paginated"));
|
|
1184
|
+
const createContext = (settings) => {
|
|
1185
|
+
const stateSubject = new BehaviorSubject({});
|
|
1186
|
+
const manifest$ = stateSubject.pipe(
|
|
1187
|
+
map$1((state) => state.manifest),
|
|
1188
|
+
filter(isDefined),
|
|
1189
|
+
distinctUntilChanged()
|
|
1190
|
+
);
|
|
1191
|
+
const containerElement$ = stateSubject.pipe(
|
|
1192
|
+
map$1((state) => state.containerElement),
|
|
1193
|
+
filter(isDefined),
|
|
1194
|
+
distinctUntilChanged()
|
|
1195
|
+
);
|
|
1196
|
+
const hasVerticalWriting$ = stateSubject.pipe(
|
|
1197
|
+
map$1((state) => state.hasVerticalWriting),
|
|
1198
|
+
filter(isDefined),
|
|
1199
|
+
distinctUntilChanged()
|
|
1200
|
+
);
|
|
1201
|
+
const isUsingSpreadMode$ = stateSubject.pipe(
|
|
1202
|
+
map$1((state) => state.isUsingSpreadMode),
|
|
1203
|
+
distinctUntilChanged()
|
|
1204
|
+
);
|
|
1183
1205
|
const visibleAreaRect = {
|
|
1184
1206
|
width: 0,
|
|
1185
1207
|
height: 0,
|
|
@@ -1189,82 +1211,113 @@ const createContext = (initialSettings) => {
|
|
|
1189
1211
|
const marginTop = 0;
|
|
1190
1212
|
const marginBottom = 0;
|
|
1191
1213
|
const destroy$ = new Subject();
|
|
1192
|
-
const
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
if (settings.getSettings().forceSinglePageMode)
|
|
1197
|
-
return false;
|
|
1198
|
-
if ((manifest == null ? void 0 : manifest.renditionFlow) === `scrolled-continuous`)
|
|
1199
|
-
return false;
|
|
1200
|
-
if (!isLandscape && (manifest == null ? void 0 : manifest.renditionSpread) === `portrait`) {
|
|
1201
|
-
return true;
|
|
1214
|
+
const setState = (newState) => {
|
|
1215
|
+
const newCompleteState = { ...stateSubject.getValue(), ...newState };
|
|
1216
|
+
if (!isShallowEqual(newCompleteState, stateSubject.getValue())) {
|
|
1217
|
+
stateSubject.next(newCompleteState);
|
|
1202
1218
|
}
|
|
1203
|
-
return isLandscape && ((manifest == null ? void 0 : manifest.renditionSpread) === void 0 || (manifest == null ? void 0 : manifest.renditionSpread) === `auto` || (manifest == null ? void 0 : manifest.renditionSpread) === `landscape` || (manifest == null ? void 0 : manifest.renditionSpread) === `both`);
|
|
1204
1219
|
};
|
|
1205
1220
|
const load = (newManifest, newLoadOptions) => {
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1221
|
+
setState({
|
|
1222
|
+
manifest: newManifest,
|
|
1223
|
+
...newLoadOptions,
|
|
1224
|
+
isFullyPrePaginated: isFullyPrePaginated(newManifest),
|
|
1225
|
+
isUsingSpreadMode: isUsingSpreadMode({
|
|
1226
|
+
manifest: newManifest,
|
|
1227
|
+
visibleAreaRect,
|
|
1228
|
+
forceSinglePageMode: settings.getSettings().forceSinglePageMode
|
|
1229
|
+
})
|
|
1230
|
+
});
|
|
1210
1231
|
};
|
|
1211
1232
|
const isRTL = () => {
|
|
1212
|
-
|
|
1233
|
+
var _a;
|
|
1234
|
+
return ((_a = stateSubject.getValue().manifest) == null ? void 0 : _a.readingDirection) === `rtl`;
|
|
1213
1235
|
};
|
|
1214
|
-
const setHasVerticalWriting = () =>
|
|
1215
|
-
|
|
1216
|
-
|
|
1236
|
+
const setHasVerticalWriting = (value) => setState({
|
|
1237
|
+
hasVerticalWriting: value
|
|
1238
|
+
});
|
|
1239
|
+
const recomputeSettings$ = merge(hasVerticalWriting$, manifest$);
|
|
1240
|
+
recomputeSettings$.pipe(
|
|
1241
|
+
withLatestFrom(hasVerticalWriting$, manifest$),
|
|
1242
|
+
tap(([, hasVerticalWriting, manifest]) => {
|
|
1243
|
+
settings.recompute({ hasVerticalWriting, manifest });
|
|
1244
|
+
}),
|
|
1245
|
+
takeUntil$1(destroy$)
|
|
1246
|
+
).subscribe();
|
|
1247
|
+
settings.$.settings$.pipe(
|
|
1248
|
+
map$1(({ forceSinglePageMode }) => forceSinglePageMode),
|
|
1217
1249
|
distinctUntilChanged(),
|
|
1218
|
-
|
|
1219
|
-
|
|
1250
|
+
withLatestFrom(manifest$),
|
|
1251
|
+
tap(([forceSinglePageMode, manifest]) => {
|
|
1252
|
+
setState({
|
|
1253
|
+
isUsingSpreadMode: isUsingSpreadMode({
|
|
1254
|
+
manifest,
|
|
1255
|
+
visibleAreaRect,
|
|
1256
|
+
forceSinglePageMode
|
|
1257
|
+
})
|
|
1258
|
+
});
|
|
1220
1259
|
}),
|
|
1221
1260
|
takeUntil$1(destroy$)
|
|
1222
1261
|
).subscribe();
|
|
1223
1262
|
const destroy = () => {
|
|
1224
|
-
|
|
1225
|
-
loadSubject$.complete();
|
|
1263
|
+
stateSubject.complete();
|
|
1226
1264
|
destroy$.next();
|
|
1227
1265
|
destroy$.complete();
|
|
1228
|
-
hasVerticalWritingSubject$.complete();
|
|
1229
1266
|
};
|
|
1230
1267
|
return {
|
|
1231
1268
|
load,
|
|
1232
1269
|
isRTL,
|
|
1233
|
-
areAllItemsPrePaginated: () =>
|
|
1270
|
+
areAllItemsPrePaginated: () => {
|
|
1271
|
+
var _a;
|
|
1272
|
+
return areAllItemsPrePaginated$1((_a = stateSubject.getValue()) == null ? void 0 : _a.manifest);
|
|
1273
|
+
},
|
|
1234
1274
|
destroy,
|
|
1235
|
-
getLoadOptions: () => loadOptions,
|
|
1236
1275
|
getCalculatedInnerMargin: () => 0,
|
|
1237
1276
|
getVisibleAreaRect: () => visibleAreaRect,
|
|
1238
|
-
|
|
1277
|
+
isUsingSpreadMode: () => stateSubject.getValue().isUsingSpreadMode,
|
|
1239
1278
|
setHasVerticalWriting,
|
|
1240
1279
|
setVisibleAreaRect: ({ height, width, x, y }) => {
|
|
1241
1280
|
visibleAreaRect.width = width;
|
|
1242
1281
|
visibleAreaRect.height = height - marginTop - marginBottom;
|
|
1243
1282
|
visibleAreaRect.x = x;
|
|
1244
1283
|
visibleAreaRect.y = y;
|
|
1284
|
+
const manifest = stateSubject.getValue().manifest;
|
|
1285
|
+
if (manifest) {
|
|
1286
|
+
setState({
|
|
1287
|
+
isUsingSpreadMode: isUsingSpreadMode({
|
|
1288
|
+
manifest,
|
|
1289
|
+
visibleAreaRect,
|
|
1290
|
+
forceSinglePageMode: settings.getSettings().forceSinglePageMode
|
|
1291
|
+
})
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
},
|
|
1295
|
+
getState: () => stateSubject.getValue(),
|
|
1296
|
+
getManifest: () => {
|
|
1297
|
+
var _a;
|
|
1298
|
+
return (_a = stateSubject.getValue()) == null ? void 0 : _a.manifest;
|
|
1299
|
+
},
|
|
1300
|
+
getReadingDirection: () => {
|
|
1301
|
+
var _a, _b;
|
|
1302
|
+
return (_b = (_a = stateSubject.getValue()) == null ? void 0 : _a.manifest) == null ? void 0 : _b.readingDirection;
|
|
1245
1303
|
},
|
|
1246
|
-
getManifest: () => manifest,
|
|
1247
|
-
getReadingDirection: () => manifest == null ? void 0 : manifest.readingDirection,
|
|
1248
1304
|
getPageSize: () => {
|
|
1249
1305
|
return {
|
|
1250
|
-
width:
|
|
1306
|
+
width: stateSubject.getValue().isUsingSpreadMode ? visibleAreaRect.width / 2 : visibleAreaRect.width,
|
|
1251
1307
|
height: visibleAreaRect.height
|
|
1252
1308
|
};
|
|
1253
1309
|
},
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
manifest
|
|
1258
|
-
}),
|
|
1310
|
+
containerElement$,
|
|
1311
|
+
isUsingSpreadMode$,
|
|
1312
|
+
hasVerticalWriting$,
|
|
1259
1313
|
$: {
|
|
1260
|
-
|
|
1314
|
+
manifest$,
|
|
1261
1315
|
destroy$: destroy$.asObservable(),
|
|
1262
|
-
|
|
1263
|
-
load$: loadSubject$.asObservable()
|
|
1316
|
+
state$: stateSubject.asObservable()
|
|
1264
1317
|
}
|
|
1265
1318
|
};
|
|
1266
1319
|
};
|
|
1267
|
-
const areAllItemsPrePaginated = (manifest) => !(manifest == null ? void 0 : manifest.spineItems.some((item) => item.renditionLayout === `reflowable`));
|
|
1320
|
+
const areAllItemsPrePaginated$1 = (manifest) => !(manifest == null ? void 0 : manifest.spineItems.some((item) => item.renditionLayout === `reflowable`));
|
|
1268
1321
|
const __UNSAFE_REFERENCE_ORIGINAL_IFRAME_EVENT_KEY = `__UNSAFE_REFERENCE_ORIGINAL_IFRAME_EVENT`;
|
|
1269
1322
|
const ITEM_EXTENSION_VALID_FOR_FRAME_SRC = [`.xhtml`, `.html`, `.htm`];
|
|
1270
1323
|
const HTML_PREFIX$1 = `prose-reader`;
|
|
@@ -1381,7 +1434,8 @@ const createLoader = ({
|
|
|
1381
1434
|
fetchResource,
|
|
1382
1435
|
hooks$,
|
|
1383
1436
|
context,
|
|
1384
|
-
viewportState
|
|
1437
|
+
viewportState$,
|
|
1438
|
+
settings
|
|
1385
1439
|
}) => {
|
|
1386
1440
|
const destroySubject$ = new Subject();
|
|
1387
1441
|
const loadSubject$ = new Subject();
|
|
@@ -1470,7 +1524,7 @@ const createLoader = ({
|
|
|
1470
1524
|
if ((frame == null ? void 0 : frame.contentDocument) && body) {
|
|
1471
1525
|
computedStyleAfterLoad = (_b = frame == null ? void 0 : frame.contentWindow) == null ? void 0 : _b.getComputedStyle(body);
|
|
1472
1526
|
}
|
|
1473
|
-
if (
|
|
1527
|
+
if (settings.getSettings().computedPageTurnMode !== `scrollable`) {
|
|
1474
1528
|
frame.setAttribute(`tab-index`, `0`);
|
|
1475
1529
|
}
|
|
1476
1530
|
const manipulableFrame = createFrameManipulator(frame);
|
|
@@ -1539,7 +1593,8 @@ const createFrameItem = ({
|
|
|
1539
1593
|
fetchResource,
|
|
1540
1594
|
context,
|
|
1541
1595
|
hooks$,
|
|
1542
|
-
viewportState
|
|
1596
|
+
viewportState$,
|
|
1597
|
+
settings
|
|
1543
1598
|
}) => {
|
|
1544
1599
|
const destroySubject$ = new Subject();
|
|
1545
1600
|
const {
|
|
@@ -1548,7 +1603,7 @@ const createFrameItem = ({
|
|
|
1548
1603
|
unload,
|
|
1549
1604
|
destroy: loaderDestroy,
|
|
1550
1605
|
getComputedStyleAfterLoad
|
|
1551
|
-
} = createLoader({ context, hooks$, item, parent, fetchResource, viewportState
|
|
1606
|
+
} = createLoader({ context, hooks$, item, parent, fetchResource, viewportState$, settings });
|
|
1552
1607
|
let isLoadedSync = false;
|
|
1553
1608
|
let isReadySync = false;
|
|
1554
1609
|
isLoaded$.subscribe({
|
|
@@ -1636,7 +1691,7 @@ const createFrameItem = ({
|
|
|
1636
1691
|
if (frame) {
|
|
1637
1692
|
frame.style.width = `${size.width}px`;
|
|
1638
1693
|
frame.style.height = `${size.height}px`;
|
|
1639
|
-
if (
|
|
1694
|
+
if (settings.getSettings().computedPageTurnMode !== `scrollable`) {
|
|
1640
1695
|
frame.setAttribute(`tab-index`, `0`);
|
|
1641
1696
|
}
|
|
1642
1697
|
}
|
|
@@ -1901,9 +1956,12 @@ const pointerEvents = [
|
|
|
1901
1956
|
`pointermove`,
|
|
1902
1957
|
`pointerout`,
|
|
1903
1958
|
`pointerover`,
|
|
1904
|
-
`pointerup
|
|
1959
|
+
`pointerup`,
|
|
1960
|
+
`touchstart`,
|
|
1961
|
+
`touchend`
|
|
1905
1962
|
];
|
|
1906
1963
|
const mouseEvents = [
|
|
1964
|
+
`click`,
|
|
1907
1965
|
`mousedown`,
|
|
1908
1966
|
`mouseup`,
|
|
1909
1967
|
`mouseenter`,
|
|
@@ -1917,9 +1975,10 @@ const createCommonSpineItem = ({
|
|
|
1917
1975
|
item,
|
|
1918
1976
|
context,
|
|
1919
1977
|
parentElement,
|
|
1920
|
-
iframeEventBridgeElement
|
|
1978
|
+
iframeEventBridgeElement$,
|
|
1921
1979
|
hooks$,
|
|
1922
|
-
viewportState
|
|
1980
|
+
viewportState$,
|
|
1981
|
+
settings
|
|
1923
1982
|
}) => {
|
|
1924
1983
|
var _a;
|
|
1925
1984
|
const destroySubject$ = new Subject();
|
|
@@ -1927,14 +1986,15 @@ const createCommonSpineItem = ({
|
|
|
1927
1986
|
const overlayElement = createOverlayElement(parentElement, item);
|
|
1928
1987
|
const fingerTracker = createFingerTracker();
|
|
1929
1988
|
const selectionTracker = createSelectionTracker();
|
|
1930
|
-
const frameHooks = createFrameHooks(iframeEventBridgeElement
|
|
1989
|
+
const frameHooks = createFrameHooks(iframeEventBridgeElement$, fingerTracker, selectionTracker);
|
|
1931
1990
|
const spineItemFrame = createFrameItem({
|
|
1932
1991
|
parent: containerElement,
|
|
1933
1992
|
item,
|
|
1934
1993
|
context,
|
|
1935
|
-
fetchResource: (_a = context.
|
|
1994
|
+
fetchResource: (_a = context.getState()) == null ? void 0 : _a.fetchResource,
|
|
1936
1995
|
hooks$: hooks$.asObservable().pipe(map$1((hooks) => [...hooks, ...frameHooks])),
|
|
1937
|
-
viewportState
|
|
1996
|
+
viewportState$,
|
|
1997
|
+
settings
|
|
1938
1998
|
});
|
|
1939
1999
|
containerElement.appendChild(overlayElement);
|
|
1940
2000
|
parentElement.appendChild(containerElement);
|
|
@@ -2059,10 +2119,10 @@ const createCommonSpineItem = ({
|
|
|
2059
2119
|
};
|
|
2060
2120
|
};
|
|
2061
2121
|
const getResource = async () => {
|
|
2062
|
-
const
|
|
2122
|
+
const fetchResource = context.getState().fetchResource;
|
|
2063
2123
|
const lastFetch = (_) => {
|
|
2064
|
-
if (
|
|
2065
|
-
return
|
|
2124
|
+
if (fetchResource) {
|
|
2125
|
+
return fetchResource(item);
|
|
2066
2126
|
}
|
|
2067
2127
|
return fetch(item.href);
|
|
2068
2128
|
};
|
|
@@ -2198,7 +2258,7 @@ const createOverlayElement = (containerElement, item) => {
|
|
|
2198
2258
|
`;
|
|
2199
2259
|
return element;
|
|
2200
2260
|
};
|
|
2201
|
-
const createFrameHooks = (iframeEventBridgeElement
|
|
2261
|
+
const createFrameHooks = (iframeEventBridgeElement$, fingerTracker, selectionTracker) => {
|
|
2202
2262
|
return [
|
|
2203
2263
|
{
|
|
2204
2264
|
name: `item.onLoad`,
|
|
@@ -2206,6 +2266,7 @@ const createFrameHooks = (iframeEventBridgeElement, fingerTracker, selectionTrac
|
|
|
2206
2266
|
const unregister = passthroughEvents.map((event) => {
|
|
2207
2267
|
var _a;
|
|
2208
2268
|
const listener = (e) => {
|
|
2269
|
+
var _a2;
|
|
2209
2270
|
let convertedEvent = e;
|
|
2210
2271
|
if (isPointerEvent(e)) {
|
|
2211
2272
|
convertedEvent = new PointerEvent(e.type, e);
|
|
@@ -2215,7 +2276,7 @@ const createFrameHooks = (iframeEventBridgeElement, fingerTracker, selectionTrac
|
|
|
2215
2276
|
}
|
|
2216
2277
|
if (convertedEvent !== e) {
|
|
2217
2278
|
attachOriginalFrameEventToDocumentEvent(convertedEvent, e);
|
|
2218
|
-
iframeEventBridgeElement.dispatchEvent(convertedEvent);
|
|
2279
|
+
(_a2 = iframeEventBridgeElement$.getValue()) == null ? void 0 : _a2.dispatchEvent(convertedEvent);
|
|
2219
2280
|
}
|
|
2220
2281
|
};
|
|
2221
2282
|
(_a = frame.contentDocument) == null ? void 0 : _a.addEventListener(event, listener);
|
|
@@ -2245,17 +2306,19 @@ const createPrePaginatedSpineItem = ({
|
|
|
2245
2306
|
item,
|
|
2246
2307
|
context,
|
|
2247
2308
|
containerElement,
|
|
2248
|
-
iframeEventBridgeElement
|
|
2309
|
+
iframeEventBridgeElement$,
|
|
2249
2310
|
hooks$,
|
|
2250
|
-
viewportState
|
|
2311
|
+
viewportState$,
|
|
2312
|
+
settings
|
|
2251
2313
|
}) => {
|
|
2252
2314
|
const commonSpineItem = createCommonSpineItem({
|
|
2253
2315
|
context,
|
|
2254
2316
|
item,
|
|
2255
2317
|
parentElement: containerElement,
|
|
2256
|
-
iframeEventBridgeElement
|
|
2318
|
+
iframeEventBridgeElement$,
|
|
2257
2319
|
hooks$,
|
|
2258
|
-
viewportState
|
|
2320
|
+
viewportState$,
|
|
2321
|
+
settings
|
|
2259
2322
|
});
|
|
2260
2323
|
const spineItemFrame = commonSpineItem.spineItemFrame;
|
|
2261
2324
|
const layout = ({
|
|
@@ -2274,7 +2337,7 @@ const createPrePaginatedSpineItem = ({
|
|
|
2274
2337
|
const cssLink = buildDocumentStyle(
|
|
2275
2338
|
{
|
|
2276
2339
|
...commonSpineItem.getDimensionsForPaginatedContent(),
|
|
2277
|
-
enableTouch:
|
|
2340
|
+
enableTouch: settings.getSettings().computedPageTurnMode !== `scrollable`,
|
|
2278
2341
|
spreadPosition
|
|
2279
2342
|
},
|
|
2280
2343
|
viewportDimensions
|
|
@@ -2417,17 +2480,19 @@ const createReflowableSpineItem = ({
|
|
|
2417
2480
|
item,
|
|
2418
2481
|
context,
|
|
2419
2482
|
containerElement,
|
|
2420
|
-
iframeEventBridgeElement
|
|
2483
|
+
iframeEventBridgeElement$,
|
|
2421
2484
|
hooks$,
|
|
2422
|
-
viewportState
|
|
2485
|
+
viewportState$,
|
|
2486
|
+
settings
|
|
2423
2487
|
}) => {
|
|
2424
2488
|
const commonSpineItem = createCommonSpineItem({
|
|
2425
2489
|
context,
|
|
2426
2490
|
item,
|
|
2427
2491
|
parentElement: containerElement,
|
|
2428
|
-
iframeEventBridgeElement
|
|
2492
|
+
iframeEventBridgeElement$,
|
|
2429
2493
|
hooks$,
|
|
2430
|
-
viewportState
|
|
2494
|
+
viewportState$,
|
|
2495
|
+
settings
|
|
2431
2496
|
});
|
|
2432
2497
|
const spineItemFrame = commonSpineItem.spineItemFrame;
|
|
2433
2498
|
let latestContentHeightWhenLoaded;
|
|
@@ -2466,7 +2531,7 @@ const createReflowableSpineItem = ({
|
|
|
2466
2531
|
} else {
|
|
2467
2532
|
const frameStyle = commonSpineItem.isImageType() ? buildStyleForReflowableImageOnly({
|
|
2468
2533
|
isScrollable: ((_g = context.getManifest()) == null ? void 0 : _g.renditionFlow) === `scrolled-continuous`,
|
|
2469
|
-
enableTouch:
|
|
2534
|
+
enableTouch: settings.getSettings().computedPageTurnMode !== `scrollable`
|
|
2470
2535
|
}) : buildStyleWithMultiColumn(
|
|
2471
2536
|
commonSpineItem.getDimensionsForReflowableContent(spineItemFrame.isUsingVerticalWriting(), minimumWidth)
|
|
2472
2537
|
);
|
|
@@ -2691,36 +2756,39 @@ const createSpineItem = ({
|
|
|
2691
2756
|
item,
|
|
2692
2757
|
context,
|
|
2693
2758
|
containerElement,
|
|
2694
|
-
iframeEventBridgeElement
|
|
2759
|
+
iframeEventBridgeElement$,
|
|
2695
2760
|
hooks$,
|
|
2696
|
-
viewportState
|
|
2761
|
+
viewportState$,
|
|
2762
|
+
settings
|
|
2697
2763
|
}) => {
|
|
2698
2764
|
if (item.renditionLayout === `pre-paginated`) {
|
|
2699
2765
|
return createPrePaginatedSpineItem({
|
|
2700
2766
|
item,
|
|
2701
2767
|
context,
|
|
2702
2768
|
containerElement,
|
|
2703
|
-
iframeEventBridgeElement
|
|
2769
|
+
iframeEventBridgeElement$,
|
|
2704
2770
|
hooks$,
|
|
2705
|
-
viewportState
|
|
2771
|
+
viewportState$,
|
|
2772
|
+
settings
|
|
2706
2773
|
});
|
|
2707
2774
|
}
|
|
2708
2775
|
return createReflowableSpineItem({
|
|
2709
2776
|
item,
|
|
2710
2777
|
context,
|
|
2711
2778
|
containerElement,
|
|
2712
|
-
iframeEventBridgeElement
|
|
2779
|
+
iframeEventBridgeElement$,
|
|
2713
2780
|
hooks$,
|
|
2714
|
-
viewportState
|
|
2781
|
+
viewportState$,
|
|
2782
|
+
settings
|
|
2715
2783
|
});
|
|
2716
2784
|
};
|
|
2717
2785
|
const createEventsHelper = ({
|
|
2718
|
-
iframeEventBridgeElement
|
|
2786
|
+
iframeEventBridgeElement$,
|
|
2719
2787
|
locator
|
|
2720
2788
|
}) => {
|
|
2721
2789
|
const normalizeEventForViewport = (event) => {
|
|
2722
2790
|
var _a;
|
|
2723
|
-
const eventIsComingFromBridge = event.target === iframeEventBridgeElement;
|
|
2791
|
+
const eventIsComingFromBridge = event.target === iframeEventBridgeElement$.getValue();
|
|
2724
2792
|
const iframeOriginalEvent = getOriginalFrameEventFromDocumentEvent(event);
|
|
2725
2793
|
const originalFrame = (_a = iframeOriginalEvent == null ? void 0 : iframeOriginalEvent.view) == null ? void 0 : _a.frameElement;
|
|
2726
2794
|
if (!eventIsComingFromBridge || !iframeOriginalEvent || !originalFrame)
|
|
@@ -3668,11 +3736,12 @@ const createSelection = (selection, item) => {
|
|
|
3668
3736
|
};
|
|
3669
3737
|
};
|
|
3670
3738
|
const report = Report.namespace(`spine`);
|
|
3739
|
+
const noopElement$1 = document.createElement("div");
|
|
3671
3740
|
const createSpine = ({
|
|
3672
|
-
|
|
3741
|
+
element$,
|
|
3673
3742
|
context,
|
|
3674
3743
|
pagination,
|
|
3675
|
-
iframeEventBridgeElement
|
|
3744
|
+
iframeEventBridgeElement$,
|
|
3676
3745
|
spineItemManager,
|
|
3677
3746
|
hooks$,
|
|
3678
3747
|
spineItemLocator,
|
|
@@ -3681,31 +3750,32 @@ const createSpine = ({
|
|
|
3681
3750
|
navigation$,
|
|
3682
3751
|
navigationAdjusted$,
|
|
3683
3752
|
currentNavigationPosition$,
|
|
3684
|
-
viewportState
|
|
3753
|
+
viewportState$,
|
|
3754
|
+
settings
|
|
3685
3755
|
}) => {
|
|
3686
3756
|
const spineItems$ = new Subject();
|
|
3687
3757
|
const itemsBeforeDestroySubject$ = new Subject();
|
|
3688
3758
|
const subject = new Subject();
|
|
3689
|
-
const containerElement =
|
|
3759
|
+
const containerElement$ = new BehaviorSubject(noopElement$1);
|
|
3690
3760
|
const eventsHelper = createEventsHelper({
|
|
3691
3761
|
context,
|
|
3692
3762
|
spineItemManager,
|
|
3693
|
-
iframeEventBridgeElement
|
|
3763
|
+
iframeEventBridgeElement$,
|
|
3694
3764
|
locator: spineLocator
|
|
3695
3765
|
});
|
|
3696
3766
|
let selectionSubscription;
|
|
3697
|
-
const reload = () => {
|
|
3698
|
-
var _a;
|
|
3767
|
+
const reload = (manifest) => {
|
|
3699
3768
|
itemsBeforeDestroySubject$.next();
|
|
3700
3769
|
spineItemManager.destroyItems();
|
|
3701
|
-
|
|
3770
|
+
manifest.spineItems.map((resource) => {
|
|
3702
3771
|
const spineItem = createSpineItem({
|
|
3703
3772
|
item: resource,
|
|
3704
|
-
containerElement,
|
|
3705
|
-
iframeEventBridgeElement
|
|
3773
|
+
containerElement: containerElement$.getValue(),
|
|
3774
|
+
iframeEventBridgeElement$,
|
|
3706
3775
|
context,
|
|
3707
3776
|
hooks$,
|
|
3708
|
-
viewportState
|
|
3777
|
+
viewportState$,
|
|
3778
|
+
settings
|
|
3709
3779
|
});
|
|
3710
3780
|
spineItemManager.add(spineItem);
|
|
3711
3781
|
});
|
|
@@ -3724,7 +3794,7 @@ const createSpine = ({
|
|
|
3724
3794
|
var _a;
|
|
3725
3795
|
(_a = spineItemManager.get(id)) == null ? void 0 : _a.manipulateSpineItem(cb);
|
|
3726
3796
|
};
|
|
3727
|
-
context.$.
|
|
3797
|
+
context.$.manifest$.pipe(tap(reload), takeUntil$1(context.$.destroy$)).subscribe();
|
|
3728
3798
|
const waitForViewportFree$ = viewportState$.pipe(
|
|
3729
3799
|
filter((v) => v === `free`),
|
|
3730
3800
|
take(1)
|
|
@@ -3739,10 +3809,10 @@ const createSpine = ({
|
|
|
3739
3809
|
const spineItemsFromPosition = spineLocator.getSpineItemsFromReadingOrderPosition(position);
|
|
3740
3810
|
const beginSpineItem = spineItemsFromPosition ? spineItemManager.get(spineItemsFromPosition.begin) : void 0;
|
|
3741
3811
|
const endSpineItem = spineItemsFromPosition ? spineItemManager.get(spineItemsFromPosition.end) : void 0;
|
|
3742
|
-
const beginLastCfi = pagination.
|
|
3743
|
-
const endLastCfi = pagination.
|
|
3744
|
-
const shouldUpdateBeginCfi = pagination.
|
|
3745
|
-
const shouldUpdateEndCfi = pagination.
|
|
3812
|
+
const beginLastCfi = pagination.getPaginationInfo().beginCfi;
|
|
3813
|
+
const endLastCfi = pagination.getPaginationInfo().endCfi;
|
|
3814
|
+
const shouldUpdateBeginCfi = pagination.getPaginationInfo().beginSpineItemIndex !== (spineItemsFromPosition == null ? void 0 : spineItemsFromPosition.begin) || beginLastCfi === void 0 || (beginLastCfi == null ? void 0 : beginLastCfi.startsWith(`epubcfi(/0`));
|
|
3815
|
+
const shouldUpdateEndCfi = pagination.getPaginationInfo().endSpineItemIndex !== (spineItemsFromPosition == null ? void 0 : spineItemsFromPosition.end) || endLastCfi === void 0 || (endLastCfi == null ? void 0 : endLastCfi.startsWith(`epubcfi(/0`));
|
|
3746
3816
|
if (beginSpineItem && endSpineItem && spineItemsFromPosition) {
|
|
3747
3817
|
const beginPosition = spineLocator.getSpineItemPositionFromSpinePosition(
|
|
3748
3818
|
spineItemsFromPosition.beginPosition,
|
|
@@ -3862,7 +3932,7 @@ const createSpine = ({
|
|
|
3862
3932
|
*
|
|
3863
3933
|
* The cfi is later adjusted with heavy dom lookup once the viewport is free.
|
|
3864
3934
|
*/
|
|
3865
|
-
cfi: (lastExpectedNavigation == null ? void 0 : lastExpectedNavigation.type) === `navigate-from-cfi` && spineItemToFocus === beginSpineItem ? lastExpectedNavigation.data : data.triggeredBy === `adjust` &&
|
|
3935
|
+
cfi: (lastExpectedNavigation == null ? void 0 : lastExpectedNavigation.type) === `navigate-from-cfi` && spineItemToFocus === beginSpineItem ? lastExpectedNavigation.data : data.triggeredBy === `adjust` && settings.getSettings().computedPageTurnMode === `controlled` ? pagination.getPaginationInfo().beginCfi : beginItemIndex !== pagination.getPaginationInfo().beginSpineItemIndex ? cfiLocator.getRootCfi(beginSpineItem) : (
|
|
3866
3936
|
/* @todo check ? */
|
|
3867
3937
|
cfiLocator.getRootCfi(beginSpineItem)
|
|
3868
3938
|
),
|
|
@@ -3874,7 +3944,7 @@ const createSpine = ({
|
|
|
3874
3944
|
spineItem: endSpineItem,
|
|
3875
3945
|
spineItemIndex: endItemIndex,
|
|
3876
3946
|
pageIndex: endPageIndex,
|
|
3877
|
-
cfi: (lastExpectedNavigation == null ? void 0 : lastExpectedNavigation.type) === `navigate-from-cfi` && spineItemToFocus === endSpineItem ? lastExpectedNavigation.data : data.triggeredBy === `adjust` &&
|
|
3947
|
+
cfi: (lastExpectedNavigation == null ? void 0 : lastExpectedNavigation.type) === `navigate-from-cfi` && spineItemToFocus === endSpineItem ? lastExpectedNavigation.data : data.triggeredBy === `adjust` && settings.getSettings().computedPageTurnMode === `controlled` ? pagination.getPaginationInfo().endCfi : endItemIndex !== pagination.getPaginationInfo().endSpineItemIndex ? cfiLocator.getRootCfi(endSpineItem) : (
|
|
3878
3948
|
/* @todo check ? */
|
|
3879
3949
|
cfiLocator.getRootCfi(endSpineItem)
|
|
3880
3950
|
),
|
|
@@ -3940,8 +4010,13 @@ const createSpine = ({
|
|
|
3940
4010
|
}),
|
|
3941
4011
|
takeUntil$1(context.$.destroy$)
|
|
3942
4012
|
).subscribe();
|
|
4013
|
+
const elementSub = element$.pipe().subscribe((element) => {
|
|
4014
|
+
const containerElement = createContainerElement(element.ownerDocument);
|
|
4015
|
+
containerElement$.next(containerElement);
|
|
4016
|
+
});
|
|
3943
4017
|
return {
|
|
3944
|
-
element
|
|
4018
|
+
element$: containerElement$,
|
|
4019
|
+
getElement: () => containerElement$.getValue(),
|
|
3945
4020
|
locator: spineLocator,
|
|
3946
4021
|
spineItemLocator,
|
|
3947
4022
|
cfiLocator,
|
|
@@ -3949,13 +4024,14 @@ const createSpine = ({
|
|
|
3949
4024
|
manipulateSpineItems,
|
|
3950
4025
|
manipulateSpineItem,
|
|
3951
4026
|
destroy: () => {
|
|
4027
|
+
elementSub.unsubscribe();
|
|
3952
4028
|
spineItems$.complete();
|
|
3953
4029
|
itemsBeforeDestroySubject$.next();
|
|
3954
4030
|
itemsBeforeDestroySubject$.complete();
|
|
3955
4031
|
subject.complete();
|
|
3956
4032
|
spineItemManager.destroy();
|
|
3957
4033
|
selectionSubscription == null ? void 0 : selectionSubscription.unsubscribe();
|
|
3958
|
-
containerElement.remove();
|
|
4034
|
+
containerElement$.getValue().remove();
|
|
3959
4035
|
},
|
|
3960
4036
|
adjustPagination,
|
|
3961
4037
|
isSelecting: () => {
|
|
@@ -3974,22 +4050,17 @@ const createSpine = ({
|
|
|
3974
4050
|
}
|
|
3975
4051
|
};
|
|
3976
4052
|
};
|
|
3977
|
-
const createContainerElement = (doc
|
|
4053
|
+
const createContainerElement = (doc) => {
|
|
3978
4054
|
const element = doc.createElement(`div`);
|
|
3979
4055
|
element.style.cssText = `
|
|
3980
4056
|
height: 100%;
|
|
3981
4057
|
position: relative;
|
|
3982
4058
|
`;
|
|
3983
4059
|
element.className = `${HTML_PREFIX$1}-spine`;
|
|
3984
|
-
return
|
|
3985
|
-
if (hook.name === `spine.onBeforeContainerCreated`) {
|
|
3986
|
-
return hook.fn(element2);
|
|
3987
|
-
}
|
|
3988
|
-
return element2;
|
|
3989
|
-
}, element);
|
|
4060
|
+
return element;
|
|
3990
4061
|
};
|
|
3991
4062
|
const NAMESPACE$4 = `spineItemManager`;
|
|
3992
|
-
const createSpineItemManager = ({ context }) => {
|
|
4063
|
+
const createSpineItemManager = ({ context, settings }) => {
|
|
3993
4064
|
const focus$ = new Subject();
|
|
3994
4065
|
const layout$ = new Subject();
|
|
3995
4066
|
let itemLayoutInformation = [];
|
|
@@ -4005,7 +4076,7 @@ const createSpineItemManager = ({ context }) => {
|
|
|
4005
4076
|
let blankPagePosition = `none`;
|
|
4006
4077
|
const itemStartOnNewScreen = horizontalOffset % context.getVisibleAreaRect().width === 0;
|
|
4007
4078
|
const isLastItem = index === orderedSpineItemsSubject$.value.length - 1;
|
|
4008
|
-
if (context.
|
|
4079
|
+
if (context.isUsingSpreadMode()) {
|
|
4009
4080
|
if (!isGloballyPrePaginated && item.item.renditionLayout === `reflowable` && !isLastItem) {
|
|
4010
4081
|
minimumWidth = context.getPageSize().width * 2;
|
|
4011
4082
|
}
|
|
@@ -4031,9 +4102,9 @@ const createSpineItemManager = ({ context }) => {
|
|
|
4031
4102
|
const { width, height } = item.layout({
|
|
4032
4103
|
minimumWidth,
|
|
4033
4104
|
blankPagePosition,
|
|
4034
|
-
spreadPosition: context.
|
|
4105
|
+
spreadPosition: context.isUsingSpreadMode() ? itemStartOnNewScreen ? context.isRTL() ? `right` : `left` : context.isRTL() ? `left` : `right` : `none`
|
|
4035
4106
|
});
|
|
4036
|
-
if (
|
|
4107
|
+
if (settings.getSettings().computedPageTurnDirection === `vertical`) {
|
|
4037
4108
|
const currentValidEdgeYForVerticalPositioning = itemStartOnNewScreen ? verticalOffset : verticalOffset - context.getVisibleAreaRect().height;
|
|
4038
4109
|
const currentValidEdgeXForVerticalPositioning = itemStartOnNewScreen ? 0 : horizontalOffset;
|
|
4039
4110
|
if (context.isRTL()) {
|
|
@@ -4101,9 +4172,9 @@ const createSpineItemManager = ({ context }) => {
|
|
|
4101
4172
|
const loadContents = Report.measurePerformance(`loadContents`, 10, (rangeOfIndex) => {
|
|
4102
4173
|
var _a;
|
|
4103
4174
|
const [leftIndex, rightIndex] = rangeOfIndex;
|
|
4104
|
-
const numberOfAdjacentSpineItemToPreLoad =
|
|
4175
|
+
const numberOfAdjacentSpineItemToPreLoad = settings.getSettings().numberOfAdjacentSpineItemToPreLoad;
|
|
4105
4176
|
const isPrePaginated = ((_a = context.getManifest()) == null ? void 0 : _a.renditionLayout) === `pre-paginated`;
|
|
4106
|
-
const isUsingFreeScroll =
|
|
4177
|
+
const isUsingFreeScroll = settings.getSettings().computedPageTurnMode === `scrollable`;
|
|
4107
4178
|
orderedSpineItemsSubject$.value.forEach((orderedSpineItem, index) => {
|
|
4108
4179
|
const isBeforeFocusedWithPreload = (
|
|
4109
4180
|
// we never want to preload anything before on free scroll on flow because it could offset the cursor
|
|
@@ -4157,7 +4228,9 @@ const createSpineItemManager = ({ context }) => {
|
|
|
4157
4228
|
spineItem.$.loaded$.pipe(
|
|
4158
4229
|
tap(() => {
|
|
4159
4230
|
if (spineItem.isUsingVerticalWriting()) {
|
|
4160
|
-
context.setHasVerticalWriting();
|
|
4231
|
+
context.setHasVerticalWriting(true);
|
|
4232
|
+
} else {
|
|
4233
|
+
context.setHasVerticalWriting(false);
|
|
4161
4234
|
}
|
|
4162
4235
|
}),
|
|
4163
4236
|
takeUntil$1(context.$.destroy$)
|
|
@@ -4398,9 +4471,10 @@ const createNavigationResolver = ({
|
|
|
4398
4471
|
context,
|
|
4399
4472
|
spineItemManager,
|
|
4400
4473
|
cfiLocator,
|
|
4401
|
-
locator
|
|
4474
|
+
locator,
|
|
4475
|
+
settings
|
|
4402
4476
|
}) => {
|
|
4403
|
-
const spineItemNavigator = createNavigationResolver$1({ context });
|
|
4477
|
+
const spineItemNavigator = createNavigationResolver$1({ context, settings });
|
|
4404
4478
|
const arePositionsDifferent = (a, b) => a.x !== b.x || a.y !== b.y;
|
|
4405
4479
|
const areNavigationDifferent = (a, b) => arePositionsDifferent(a, b) || !!a.spineItem && !!b.spineItem && a.spineItem !== b.spineItem;
|
|
4406
4480
|
const wrapPositionWithSafeEdge = Report.measurePerformance(
|
|
@@ -4465,7 +4539,7 @@ const createNavigationResolver = ({
|
|
|
4465
4539
|
return { x: 0, y: 0 };
|
|
4466
4540
|
};
|
|
4467
4541
|
const getNavigationForRightSinglePage = (position) => {
|
|
4468
|
-
const pageTurnDirection =
|
|
4542
|
+
const pageTurnDirection = settings.getSettings().computedPageTurnDirection;
|
|
4469
4543
|
const spineItem = locator.getSpineItemFromPosition(position) || spineItemManager.getFocusedSpineItem();
|
|
4470
4544
|
const defaultNavigation = position;
|
|
4471
4545
|
if (!spineItem) {
|
|
@@ -4484,7 +4558,7 @@ const createNavigationResolver = ({
|
|
|
4484
4558
|
}
|
|
4485
4559
|
};
|
|
4486
4560
|
const getNavigationForLeftSinglePage = (position) => {
|
|
4487
|
-
const pageTurnDirection =
|
|
4561
|
+
const pageTurnDirection = settings.getSettings().computedPageTurnDirection;
|
|
4488
4562
|
const spineItem = locator.getSpineItemFromPosition(position) || spineItemManager.getFocusedSpineItem();
|
|
4489
4563
|
const defaultNavigation = { ...position, spineItem };
|
|
4490
4564
|
if (!spineItem) {
|
|
@@ -4508,7 +4582,7 @@ const createNavigationResolver = ({
|
|
|
4508
4582
|
if ((spineItemOnPosition == null ? void 0 : spineItemOnPosition.isUsingVerticalWriting()) && position.x === navigation.x) {
|
|
4509
4583
|
return getAdjustedPositionForSpread(navigation);
|
|
4510
4584
|
}
|
|
4511
|
-
if (context.
|
|
4585
|
+
if (context.isUsingSpreadMode()) {
|
|
4512
4586
|
if ((spineItemOnPosition == null ? void 0 : spineItemOnPosition.isUsingVerticalWriting()) && position.x !== navigation.x) {
|
|
4513
4587
|
return getAdjustedPositionForSpread(
|
|
4514
4588
|
wrapPositionWithSafeEdge(
|
|
@@ -4522,7 +4596,7 @@ const createNavigationResolver = ({
|
|
|
4522
4596
|
)
|
|
4523
4597
|
);
|
|
4524
4598
|
}
|
|
4525
|
-
if (
|
|
4599
|
+
if (settings.getSettings().computedPageTurnDirection === `vertical` && position.y !== navigation.y) {
|
|
4526
4600
|
return getAdjustedPositionForSpread(navigation);
|
|
4527
4601
|
}
|
|
4528
4602
|
const doubleNavigation = getNavigationForRightSinglePage(navigation);
|
|
@@ -4536,7 +4610,7 @@ const createNavigationResolver = ({
|
|
|
4536
4610
|
if ((spineItemOnPosition == null ? void 0 : spineItemOnPosition.isUsingVerticalWriting()) && position.x === navigation.x) {
|
|
4537
4611
|
return getAdjustedPositionForSpread(navigation);
|
|
4538
4612
|
}
|
|
4539
|
-
if (context.
|
|
4613
|
+
if (context.isUsingSpreadMode()) {
|
|
4540
4614
|
if ((spineItemOnPosition == null ? void 0 : spineItemOnPosition.isUsingVerticalWriting()) && position.x !== navigation.x) {
|
|
4541
4615
|
return getAdjustedPositionForSpread(
|
|
4542
4616
|
wrapPositionWithSafeEdge(
|
|
@@ -4544,7 +4618,7 @@ const createNavigationResolver = ({
|
|
|
4544
4618
|
)
|
|
4545
4619
|
);
|
|
4546
4620
|
}
|
|
4547
|
-
if (
|
|
4621
|
+
if (settings.getSettings().computedPageTurnDirection === `vertical` && position.y !== navigation.y) {
|
|
4548
4622
|
return getAdjustedPositionForSpread(navigation);
|
|
4549
4623
|
}
|
|
4550
4624
|
const doubleNavigation = getNavigationForLeftSinglePage(navigation);
|
|
@@ -4586,7 +4660,7 @@ const createNavigationResolver = ({
|
|
|
4586
4660
|
return { x: 0, y: 0 };
|
|
4587
4661
|
};
|
|
4588
4662
|
const getMostPredominantNavigationForPosition = (viewportPosition) => {
|
|
4589
|
-
const pageTurnDirection =
|
|
4663
|
+
const pageTurnDirection = settings.getSettings().computedPageTurnDirection;
|
|
4590
4664
|
const triggerPercentage = 0.5;
|
|
4591
4665
|
const triggerXPosition = pageTurnDirection === `horizontal` ? viewportPosition.x + context.getVisibleAreaRect().width * triggerPercentage : 0;
|
|
4592
4666
|
const triggerYPosition = pageTurnDirection === `horizontal` ? 0 : viewportPosition.y + context.getVisibleAreaRect().height * triggerPercentage;
|
|
@@ -4594,7 +4668,7 @@ const createNavigationResolver = ({
|
|
|
4594
4668
|
return getNavigationForPosition(midScreenPositionSafePosition);
|
|
4595
4669
|
};
|
|
4596
4670
|
const isNavigationGoingForwardFrom = (to, from2) => {
|
|
4597
|
-
const pageTurnDirection =
|
|
4671
|
+
const pageTurnDirection = settings.getSettings().computedPageTurnDirection;
|
|
4598
4672
|
if (pageTurnDirection === `vertical`) {
|
|
4599
4673
|
return to.y > from2.y;
|
|
4600
4674
|
}
|
|
@@ -4620,9 +4694,10 @@ const createNavigationResolver = ({
|
|
|
4620
4694
|
const SCROLL_FINISHED_DEBOUNCE_TIMEOUT = 200;
|
|
4621
4695
|
const createScrollViewportNavigator = ({
|
|
4622
4696
|
context,
|
|
4623
|
-
element
|
|
4697
|
+
element$,
|
|
4624
4698
|
navigator: navigator2,
|
|
4625
4699
|
currentNavigationSubject$,
|
|
4700
|
+
settings,
|
|
4626
4701
|
spine
|
|
4627
4702
|
}) => {
|
|
4628
4703
|
let lastScrollWasProgrammaticallyTriggered = false;
|
|
@@ -4636,38 +4711,44 @@ const createScrollViewportNavigator = ({
|
|
|
4636
4711
|
})
|
|
4637
4712
|
);
|
|
4638
4713
|
const adjustReadingOffset = ({ x, y }) => {
|
|
4639
|
-
|
|
4714
|
+
var _a;
|
|
4715
|
+
if (settings.getSettings().computedPageTurnMode === `scrollable`) {
|
|
4640
4716
|
lastScrollWasProgrammaticallyTriggered = true;
|
|
4641
|
-
element.scrollTo({ left: x, top: y });
|
|
4717
|
+
(_a = element$.getValue()) == null ? void 0 : _a.scrollTo({ left: x, top: y });
|
|
4642
4718
|
return true;
|
|
4643
4719
|
}
|
|
4644
4720
|
return false;
|
|
4645
4721
|
};
|
|
4646
|
-
const runOnFreePageTurnModeOnly$ = (source) =>
|
|
4647
|
-
map$1(() =>
|
|
4722
|
+
const runOnFreePageTurnModeOnly$ = (source) => settings.$.settings$.pipe(
|
|
4723
|
+
map$1(({ computedPageTurnMode }) => computedPageTurnMode),
|
|
4648
4724
|
distinctUntilChanged(),
|
|
4649
4725
|
switchMap$1((mode) => iif(() => mode === `controlled`, EMPTY, source))
|
|
4650
4726
|
);
|
|
4651
|
-
const userScroll$ = runOnFreePageTurnModeOnly$(
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4727
|
+
const userScroll$ = runOnFreePageTurnModeOnly$(
|
|
4728
|
+
element$.pipe(
|
|
4729
|
+
filter(isDefined),
|
|
4730
|
+
switchMap$1((element) => fromEvent(element, `scroll`))
|
|
4731
|
+
)
|
|
4732
|
+
).pipe(onlyUserScrollFilter, share(), takeUntil$1(context.$.destroy$));
|
|
4656
4733
|
const getScaledDownPosition = ({ x, y }) => {
|
|
4657
|
-
|
|
4734
|
+
var _a, _b;
|
|
4735
|
+
const spineElement = spine.getElement();
|
|
4736
|
+
if (!spineElement)
|
|
4737
|
+
throw new Error("Invalid spine element");
|
|
4738
|
+
const spineScaleX = spineElement.getBoundingClientRect().width / spineElement.offsetWidth;
|
|
4658
4739
|
const scaledDownPosition = {
|
|
4659
4740
|
x: getNewScaledOffset({
|
|
4660
4741
|
newScale: 1,
|
|
4661
4742
|
oldScale: spineScaleX,
|
|
4662
|
-
screenSize: element.clientWidth,
|
|
4663
|
-
pageSize:
|
|
4743
|
+
screenSize: ((_a = element$.getValue()) == null ? void 0 : _a.clientWidth) ?? 0,
|
|
4744
|
+
pageSize: spineElement.scrollWidth,
|
|
4664
4745
|
scrollOffset: x
|
|
4665
4746
|
}),
|
|
4666
4747
|
y: getNewScaledOffset({
|
|
4667
4748
|
newScale: 1,
|
|
4668
4749
|
oldScale: spineScaleX,
|
|
4669
|
-
screenSize: element.clientHeight,
|
|
4670
|
-
pageSize:
|
|
4750
|
+
screenSize: ((_b = element$.getValue()) == null ? void 0 : _b.clientHeight) ?? 0,
|
|
4751
|
+
pageSize: spineElement.scrollHeight,
|
|
4671
4752
|
scrollOffset: y
|
|
4672
4753
|
})
|
|
4673
4754
|
};
|
|
@@ -4678,13 +4759,17 @@ const createScrollViewportNavigator = ({
|
|
|
4678
4759
|
return navigation;
|
|
4679
4760
|
};
|
|
4680
4761
|
const getCurrentViewportPosition = () => {
|
|
4681
|
-
|
|
4762
|
+
var _a, _b;
|
|
4763
|
+
return getScaledDownPosition({ x: ((_a = element$.getValue()) == null ? void 0 : _a.scrollLeft) ?? 0, y: ((_b = element$.getValue()) == null ? void 0 : _b.scrollTop) ?? 0 });
|
|
4682
4764
|
};
|
|
4683
4765
|
const navigationOnScroll$ = userScroll$.pipe(
|
|
4684
4766
|
debounceTime(SCROLL_FINISHED_DEBOUNCE_TIMEOUT, animationFrameScheduler),
|
|
4685
4767
|
withLatestFrom(currentNavigationSubject$),
|
|
4686
4768
|
switchMap$1(() => {
|
|
4687
|
-
|
|
4769
|
+
var _a, _b;
|
|
4770
|
+
const navigation = getNavigationForPosition(
|
|
4771
|
+
getScaledDownPosition({ x: ((_a = element$.getValue()) == null ? void 0 : _a.scrollLeft) ?? 0, y: ((_b = element$.getValue()) == null ? void 0 : _b.scrollTop) ?? 0 })
|
|
4772
|
+
);
|
|
4688
4773
|
return of({ position: navigation, animate: false, lastUserExpectedNavigation: void 0 });
|
|
4689
4774
|
}),
|
|
4690
4775
|
share()
|
|
@@ -4907,7 +4992,8 @@ const createPanViewportNavigator = ({
|
|
|
4907
4992
|
spineItemManager,
|
|
4908
4993
|
locator,
|
|
4909
4994
|
context,
|
|
4910
|
-
currentNavigationSubject
|
|
4995
|
+
currentNavigationSubject$,
|
|
4996
|
+
settings
|
|
4911
4997
|
}) => {
|
|
4912
4998
|
const navigationTriggerSubject$ = new Subject();
|
|
4913
4999
|
const stateSubject$ = new BehaviorSubject(`end`);
|
|
@@ -4918,11 +5004,11 @@ const createPanViewportNavigator = ({
|
|
|
4918
5004
|
`${NAMESPACE$1} moveTo`,
|
|
4919
5005
|
5,
|
|
4920
5006
|
(delta, { final, start } = {}) => {
|
|
4921
|
-
if (
|
|
5007
|
+
if (settings.getSettings().computedPageTurnMode === `scrollable`) {
|
|
4922
5008
|
Report.warn(`pan control is not available on free page turn mode`);
|
|
4923
5009
|
return;
|
|
4924
5010
|
}
|
|
4925
|
-
const pageTurnDirection =
|
|
5011
|
+
const pageTurnDirection = settings.getSettings().computedPageTurnDirection;
|
|
4926
5012
|
if (start) {
|
|
4927
5013
|
stateSubject$.next(`start`);
|
|
4928
5014
|
movingLastDelta = { x: 0, y: 0 };
|
|
@@ -4982,7 +5068,7 @@ const createPanViewportNavigator = ({
|
|
|
4982
5068
|
);
|
|
4983
5069
|
const snapNavigation$ = navigationTriggerSubject$.pipe(
|
|
4984
5070
|
filter((e) => e.type === `snap`),
|
|
4985
|
-
withLatestFrom$1(
|
|
5071
|
+
withLatestFrom$1(settings.$.settings$),
|
|
4986
5072
|
switchMap$1(
|
|
4987
5073
|
([
|
|
4988
5074
|
{
|
|
@@ -4990,7 +5076,7 @@ const createPanViewportNavigator = ({
|
|
|
4990
5076
|
},
|
|
4991
5077
|
{ navigationSnapThreshold }
|
|
4992
5078
|
]) => {
|
|
4993
|
-
const pageTurnDirection =
|
|
5079
|
+
const pageTurnDirection = settings.getSettings().computedPageTurnDirection;
|
|
4994
5080
|
const movingForward = navigator2.isNavigationGoingForwardFrom(to, from2);
|
|
4995
5081
|
const triggerPercentage = movingForward ? 1 - navigationSnapThreshold : navigationSnapThreshold;
|
|
4996
5082
|
const triggerXPosition = pageTurnDirection === `horizontal` ? to.x + context.getVisibleAreaRect().width * triggerPercentage : 0;
|
|
@@ -5023,18 +5109,19 @@ const createPanViewportNavigator = ({
|
|
|
5023
5109
|
};
|
|
5024
5110
|
};
|
|
5025
5111
|
const NAMESPACE = `viewportNavigator`;
|
|
5112
|
+
const noopElement = document.createElement("div");
|
|
5026
5113
|
const createViewportNavigator = ({
|
|
5027
5114
|
spineItemManager,
|
|
5028
5115
|
context,
|
|
5029
5116
|
pagination,
|
|
5030
|
-
parentElement
|
|
5117
|
+
parentElement$,
|
|
5031
5118
|
cfiLocator,
|
|
5032
5119
|
spineLocator,
|
|
5033
5120
|
hooks$,
|
|
5034
|
-
spine
|
|
5121
|
+
spine,
|
|
5122
|
+
settings
|
|
5035
5123
|
}) => {
|
|
5036
|
-
const element =
|
|
5037
|
-
element.appendChild(spine.element);
|
|
5124
|
+
const element$ = new BehaviorSubject(noopElement);
|
|
5038
5125
|
const layoutSubject$ = new Subject();
|
|
5039
5126
|
let currentViewportPositionMemoUnused;
|
|
5040
5127
|
const currentNavigationPositionSubject$ = new BehaviorSubject({
|
|
@@ -5044,17 +5131,18 @@ const createViewportNavigator = ({
|
|
|
5044
5131
|
});
|
|
5045
5132
|
const navigator2 = createNavigationResolver({
|
|
5046
5133
|
context,
|
|
5134
|
+
settings,
|
|
5047
5135
|
spineItemManager,
|
|
5048
5136
|
cfiLocator,
|
|
5049
5137
|
locator: spineLocator
|
|
5050
5138
|
});
|
|
5051
5139
|
const adjustNavigationSubject$ = new Subject();
|
|
5052
|
-
parentElement.appendChild(element);
|
|
5053
5140
|
const getCurrentViewportPosition = Report.measurePerformance(`${NAMESPACE} getCurrentViewportPosition`, 1, () => {
|
|
5054
|
-
|
|
5141
|
+
var _a;
|
|
5142
|
+
if (settings.getSettings().computedPageTurnMode === `scrollable`) {
|
|
5055
5143
|
return scrollViewportNavigator.getCurrentViewportPosition();
|
|
5056
5144
|
}
|
|
5057
|
-
const { x, y } = element.getBoundingClientRect();
|
|
5145
|
+
const { x, y } = ((_a = element$.getValue()) == null ? void 0 : _a.getBoundingClientRect()) ?? { x: 0, y: 0 };
|
|
5058
5146
|
const newValue = {
|
|
5059
5147
|
// we want to round to first decimal because it's possible to have half pixel
|
|
5060
5148
|
// however browser engine can also gives back x.yyyy based on their precision
|
|
@@ -5068,7 +5156,7 @@ const createViewportNavigator = ({
|
|
|
5068
5156
|
});
|
|
5069
5157
|
const panViewportNavigator = createPanViewportNavigator({
|
|
5070
5158
|
context,
|
|
5071
|
-
|
|
5159
|
+
settings,
|
|
5072
5160
|
navigator: navigator2,
|
|
5073
5161
|
spineItemManager,
|
|
5074
5162
|
locator: spineLocator,
|
|
@@ -5077,15 +5165,15 @@ const createViewportNavigator = ({
|
|
|
5077
5165
|
});
|
|
5078
5166
|
const scrollViewportNavigator = createScrollViewportNavigator({
|
|
5079
5167
|
context,
|
|
5080
|
-
element
|
|
5168
|
+
element$,
|
|
5081
5169
|
navigator: navigator2,
|
|
5082
5170
|
currentNavigationSubject$: currentNavigationPositionSubject$,
|
|
5083
5171
|
spine,
|
|
5084
|
-
spineItemManager
|
|
5172
|
+
spineItemManager,
|
|
5173
|
+
settings
|
|
5085
5174
|
});
|
|
5086
5175
|
const manualViewportNavigator = createManualViewportNavigator({
|
|
5087
5176
|
context,
|
|
5088
|
-
element,
|
|
5089
5177
|
navigator: navigator2,
|
|
5090
5178
|
currentNavigationSubject$: currentNavigationPositionSubject$,
|
|
5091
5179
|
spineItemManager,
|
|
@@ -5102,6 +5190,9 @@ const createViewportNavigator = ({
|
|
|
5102
5190
|
`adjustReadingOffset`,
|
|
5103
5191
|
2,
|
|
5104
5192
|
({ x, y }, hooks) => {
|
|
5193
|
+
const element = element$.getValue();
|
|
5194
|
+
if (!element)
|
|
5195
|
+
throw new Error("Invalid element");
|
|
5105
5196
|
currentViewportPositionMemoUnused = void 0;
|
|
5106
5197
|
const isAdjusted = viewportNavigators.reduce((isAdjusted2, navigator22) => {
|
|
5107
5198
|
return navigator22.adjustReadingOffset({ x, y }) || isAdjusted2;
|
|
@@ -5118,10 +5209,10 @@ const createViewportNavigator = ({
|
|
|
5118
5209
|
{ disable: true }
|
|
5119
5210
|
);
|
|
5120
5211
|
const adjustNavigation = (spineItem) => {
|
|
5121
|
-
const lastCfi = pagination.
|
|
5212
|
+
const lastCfi = pagination.getPaginationInfo().beginCfi;
|
|
5122
5213
|
let adjustedSpinePosition = currentNavigationPositionSubject$.value;
|
|
5123
5214
|
const offsetInSpineItem = 0;
|
|
5124
|
-
if (
|
|
5215
|
+
if (settings.getSettings().computedPageTurnMode === `scrollable`) {
|
|
5125
5216
|
adjustedSpinePosition = scrollViewportNavigator.getNavigationForPosition(getCurrentViewportPosition());
|
|
5126
5217
|
} else if ((lastUserExpectedNavigation == null ? void 0 : lastUserExpectedNavigation.type) === `navigate-from-cfi`) {
|
|
5127
5218
|
adjustedSpinePosition = navigator2.getNavigationForCfi(lastUserExpectedNavigation.data);
|
|
@@ -5139,7 +5230,7 @@ const createViewportNavigator = ({
|
|
|
5139
5230
|
adjustedSpinePosition = navigator2.getNavigationForCfi(lastCfi);
|
|
5140
5231
|
Report.log(NAMESPACE, `adjustNavigation`, `use last cfi`);
|
|
5141
5232
|
} else {
|
|
5142
|
-
const currentPageIndex = pagination.
|
|
5233
|
+
const currentPageIndex = pagination.getPaginationInfo().beginPageIndexInSpineItem || 0;
|
|
5143
5234
|
adjustedSpinePosition = navigator2.getNavigationForPage(currentPageIndex, spineItem);
|
|
5144
5235
|
Report.log(NAMESPACE, `adjustNavigation`, `use guess strategy`, {});
|
|
5145
5236
|
}
|
|
@@ -5166,14 +5257,15 @@ const createViewportNavigator = ({
|
|
|
5166
5257
|
layoutSubject$.subscribe(() => {
|
|
5167
5258
|
currentViewportPositionMemoUnused = void 0;
|
|
5168
5259
|
});
|
|
5169
|
-
const layoutChangeSettings$ =
|
|
5260
|
+
const layoutChangeSettings$ = settings.$.settings$.pipe(
|
|
5170
5261
|
mapKeysTo([`computedPageTurnDirection`, `computedPageTurnMode`, `numberOfAdjacentSpineItemToPreLoad`]),
|
|
5171
5262
|
distinctUntilChanged(isShallowEqual),
|
|
5172
5263
|
skip(1)
|
|
5173
5264
|
);
|
|
5174
5265
|
const layout$ = merge(layoutSubject$, layoutChangeSettings$).pipe(
|
|
5175
|
-
|
|
5176
|
-
|
|
5266
|
+
withLatestFrom(element$),
|
|
5267
|
+
tap(([, element]) => {
|
|
5268
|
+
if (settings.getSettings().computedPageTurnMode === `scrollable`) {
|
|
5177
5269
|
element.style.removeProperty(`transform`);
|
|
5178
5270
|
element.style.removeProperty(`transition`);
|
|
5179
5271
|
element.style.overflow = `scroll`;
|
|
@@ -5229,7 +5321,7 @@ const createViewportNavigator = ({
|
|
|
5229
5321
|
);
|
|
5230
5322
|
const navigationWhichRequireManualAdjust$ = navigation$.pipe(
|
|
5231
5323
|
filter(({ triggeredBy }) => {
|
|
5232
|
-
if (triggeredBy === `scroll` ||
|
|
5324
|
+
if (triggeredBy === `scroll` || settings.getSettings().computedPageTurnMode === `scrollable` && triggeredBy === `adjust`) {
|
|
5233
5325
|
return false;
|
|
5234
5326
|
} else {
|
|
5235
5327
|
return true;
|
|
@@ -5241,7 +5333,7 @@ const createViewportNavigator = ({
|
|
|
5241
5333
|
navigationWhichRequireManualAdjust$
|
|
5242
5334
|
).pipe(
|
|
5243
5335
|
map$1(({ animation, position }) => {
|
|
5244
|
-
const shouldAnimate = !(!animation || animation === `turn` &&
|
|
5336
|
+
const shouldAnimate = !(!animation || animation === `turn` && settings.getSettings().computedPageTurnAnimation === `none`);
|
|
5245
5337
|
return {
|
|
5246
5338
|
type: `manualAdjust`,
|
|
5247
5339
|
shouldAnimate,
|
|
@@ -5256,15 +5348,15 @@ const createViewportNavigator = ({
|
|
|
5256
5348
|
pairwise(),
|
|
5257
5349
|
tap(([prevEvent, currentEvent]) => {
|
|
5258
5350
|
if ((prevEvent == null ? void 0 : prevEvent.type) === `manualAdjust` && (currentEvent == null ? void 0 : currentEvent.type) !== `manualAdjust`) {
|
|
5259
|
-
element.style.setProperty(`transition`, `none`);
|
|
5260
|
-
element.style.setProperty(`opacity`, `1`);
|
|
5351
|
+
element$.getValue().style.setProperty(`transition`, `none`);
|
|
5352
|
+
element$.getValue().style.setProperty(`opacity`, `1`);
|
|
5261
5353
|
}
|
|
5262
5354
|
}),
|
|
5263
5355
|
switchMap$1(([, currentEvent]) => {
|
|
5264
5356
|
if ((currentEvent == null ? void 0 : currentEvent.type) !== `manualAdjust`)
|
|
5265
5357
|
return EMPTY;
|
|
5266
|
-
const animationDuration = currentEvent.animation === `snap` ?
|
|
5267
|
-
const pageTurnAnimation = currentEvent.animation === `snap` ? `slide` :
|
|
5358
|
+
const animationDuration = currentEvent.animation === `snap` ? settings.getSettings().computedSnapAnimationDuration : settings.getSettings().computedPageTurnAnimationDuration;
|
|
5359
|
+
const pageTurnAnimation = currentEvent.animation === `snap` ? `slide` : settings.getSettings().computedPageTurnAnimation;
|
|
5268
5360
|
return of(currentEvent).pipe(
|
|
5269
5361
|
/**
|
|
5270
5362
|
* @important
|
|
@@ -5279,15 +5371,15 @@ const createViewportNavigator = ({
|
|
|
5279
5371
|
const noAdjustmentNeeded = false;
|
|
5280
5372
|
if (data.shouldAnimate && !noAdjustmentNeeded) {
|
|
5281
5373
|
if (pageTurnAnimation === `fade`) {
|
|
5282
|
-
element.style.setProperty(`transition`, `opacity ${animationDuration / 2}ms`);
|
|
5283
|
-
element.style.setProperty(`opacity`, `0`);
|
|
5374
|
+
element$.getValue().style.setProperty(`transition`, `opacity ${animationDuration / 2}ms`);
|
|
5375
|
+
element$.getValue().style.setProperty(`opacity`, `0`);
|
|
5284
5376
|
} else if (currentEvent.animation === `snap` || pageTurnAnimation === `slide`) {
|
|
5285
|
-
element.style.setProperty(`transition`, `transform ${animationDuration}ms`);
|
|
5286
|
-
element.style.setProperty(`opacity`, `1`);
|
|
5377
|
+
element$.getValue().style.setProperty(`transition`, `transform ${animationDuration}ms`);
|
|
5378
|
+
element$.getValue().style.setProperty(`opacity`, `1`);
|
|
5287
5379
|
}
|
|
5288
5380
|
} else {
|
|
5289
|
-
element.style.setProperty(`transition`, `none`);
|
|
5290
|
-
element.style.setProperty(`opacity`, `1`);
|
|
5381
|
+
element$.getValue().style.setProperty(`transition`, `none`);
|
|
5382
|
+
element$.getValue().style.setProperty(`opacity`, `1`);
|
|
5291
5383
|
}
|
|
5292
5384
|
}),
|
|
5293
5385
|
/**
|
|
@@ -5308,7 +5400,7 @@ const createViewportNavigator = ({
|
|
|
5308
5400
|
tap(([data, hooks]) => {
|
|
5309
5401
|
if (pageTurnAnimation === `fade`) {
|
|
5310
5402
|
adjustReadingOffset(data.position, hooks);
|
|
5311
|
-
element.style.setProperty(`opacity`, `1`);
|
|
5403
|
+
element$.getValue().style.setProperty(`opacity`, `1`);
|
|
5312
5404
|
}
|
|
5313
5405
|
}),
|
|
5314
5406
|
currentEvent.shouldAnimate ? delay(animationDuration / 2, animationFrameScheduler) : identity,
|
|
@@ -5380,10 +5472,17 @@ const createViewportNavigator = ({
|
|
|
5380
5472
|
),
|
|
5381
5473
|
share()
|
|
5382
5474
|
);
|
|
5475
|
+
const parentElementSub = parentElement$.pipe(filter(isDefined), withLatestFrom(spine.element$)).subscribe(([parentElement, spineElement]) => {
|
|
5476
|
+
const element = createElement(parentElement.ownerDocument, hooks$);
|
|
5477
|
+
element.appendChild(spineElement);
|
|
5478
|
+
parentElement.appendChild(element);
|
|
5479
|
+
element$.next(element);
|
|
5480
|
+
});
|
|
5383
5481
|
const destroy = () => {
|
|
5384
5482
|
layoutSubject$.complete();
|
|
5385
5483
|
adjustNavigationSubject$.complete();
|
|
5386
5484
|
currentNavigationPositionSubject$.complete();
|
|
5485
|
+
parentElementSub.unsubscribe();
|
|
5387
5486
|
viewportNavigators.forEach((navigator22) => navigator22.destroy());
|
|
5388
5487
|
};
|
|
5389
5488
|
return {
|
|
@@ -5400,7 +5499,8 @@ const createViewportNavigator = ({
|
|
|
5400
5499
|
goToPageOfCurrentChapter: manualViewportNavigator.goToPageOfCurrentChapter,
|
|
5401
5500
|
moveTo: panViewportNavigator.moveTo,
|
|
5402
5501
|
getLastUserExpectedNavigation: () => lastUserExpectedNavigation,
|
|
5403
|
-
element
|
|
5502
|
+
element$,
|
|
5503
|
+
getElement: () => element$.getValue(),
|
|
5404
5504
|
$: {
|
|
5405
5505
|
state$,
|
|
5406
5506
|
navigation$,
|
|
@@ -5426,7 +5526,8 @@ const createElement = (doc, hooks$) => {
|
|
|
5426
5526
|
const createLocationResolver = ({
|
|
5427
5527
|
spineItemManager,
|
|
5428
5528
|
context,
|
|
5429
|
-
spineItemLocator
|
|
5529
|
+
spineItemLocator,
|
|
5530
|
+
settings
|
|
5430
5531
|
}) => {
|
|
5431
5532
|
const getSpineItemPositionFromSpinePosition = Report.measurePerformance(
|
|
5432
5533
|
`getSpineItemPositionFromSpinePosition`,
|
|
@@ -5461,7 +5562,7 @@ const createLocationResolver = ({
|
|
|
5461
5562
|
const spineItem = spineItemManager.getAll().find((item) => {
|
|
5462
5563
|
const { left, right, bottom, top } = spineItemManager.getAbsolutePositionOf(item);
|
|
5463
5564
|
const isWithinXAxis = position.x >= left && position.x < right;
|
|
5464
|
-
if (
|
|
5565
|
+
if (settings.getSettings().computedPageTurnDirection === `horizontal`) {
|
|
5465
5566
|
return isWithinXAxis;
|
|
5466
5567
|
} else {
|
|
5467
5568
|
return isWithinXAxis && position.y >= top && position.y < bottom;
|
|
@@ -5488,7 +5589,7 @@ const createLocationResolver = ({
|
|
|
5488
5589
|
if (itemAtPositionIndex === void 0)
|
|
5489
5590
|
return void 0;
|
|
5490
5591
|
let endPosition = position;
|
|
5491
|
-
if (context.
|
|
5592
|
+
if (context.isUsingSpreadMode()) {
|
|
5492
5593
|
endPosition = { x: position.x + context.getPageSize().width, y: position.y };
|
|
5493
5594
|
}
|
|
5494
5595
|
const endItemIndex = spineItemManager.getSpineItemIndex(getSpineItemFromPosition(endPosition) || spineItemManager.getFocusedSpineItem()) ?? itemAtPositionIndex;
|
|
@@ -5609,15 +5710,86 @@ const createCfiLocator = ({
|
|
|
5609
5710
|
generateFromRange
|
|
5610
5711
|
};
|
|
5611
5712
|
};
|
|
5713
|
+
const areAllItemsPrePaginated = (manifest) => !(manifest == null ? void 0 : manifest.spineItems.some((item) => item.renditionLayout === `reflowable`));
|
|
5714
|
+
const createSettings = (initialSettings) => {
|
|
5715
|
+
const mergedSettings = {
|
|
5716
|
+
forceSinglePageMode: false,
|
|
5717
|
+
pageTurnAnimation: `none`,
|
|
5718
|
+
computedPageTurnAnimation: `none`,
|
|
5719
|
+
pageTurnDirection: `horizontal`,
|
|
5720
|
+
computedPageTurnDirection: `horizontal`,
|
|
5721
|
+
pageTurnAnimationDuration: void 0,
|
|
5722
|
+
computedPageTurnAnimationDuration: 0,
|
|
5723
|
+
pageTurnMode: `controlled`,
|
|
5724
|
+
computedPageTurnMode: `controlled`,
|
|
5725
|
+
computedSnapAnimationDuration: 300,
|
|
5726
|
+
navigationSnapThreshold: 0.3,
|
|
5727
|
+
numberOfAdjacentSpineItemToPreLoad: 0,
|
|
5728
|
+
...initialSettings
|
|
5729
|
+
};
|
|
5730
|
+
updateComputedSettings(void 0, mergedSettings, false);
|
|
5731
|
+
const settingsSubject$ = new BehaviorSubject(mergedSettings);
|
|
5732
|
+
const setSettings = (newSettings, options) => {
|
|
5733
|
+
if (Object.keys(newSettings).length === 0)
|
|
5734
|
+
return;
|
|
5735
|
+
const newMergedSettings = { ...settingsSubject$.value, ...newSettings };
|
|
5736
|
+
updateComputedSettings(options.manifest, newMergedSettings, options.hasVerticalWriting ?? false);
|
|
5737
|
+
settingsSubject$.next(newMergedSettings);
|
|
5738
|
+
};
|
|
5739
|
+
const recompute = (options) => {
|
|
5740
|
+
const newMergedSettings = { ...settingsSubject$.value };
|
|
5741
|
+
updateComputedSettings(options.manifest, newMergedSettings, options.hasVerticalWriting ?? false);
|
|
5742
|
+
settingsSubject$.next(newMergedSettings);
|
|
5743
|
+
};
|
|
5744
|
+
const destroy = () => {
|
|
5745
|
+
settingsSubject$.complete();
|
|
5746
|
+
};
|
|
5747
|
+
return {
|
|
5748
|
+
getSettings: () => settingsSubject$.value,
|
|
5749
|
+
setSettings,
|
|
5750
|
+
recompute,
|
|
5751
|
+
destroy,
|
|
5752
|
+
$: {
|
|
5753
|
+
settings$: settingsSubject$.asObservable().pipe(distinctUntilChanged(isShallowEqual))
|
|
5754
|
+
}
|
|
5755
|
+
};
|
|
5756
|
+
};
|
|
5757
|
+
const updateComputedSettings = (newManifest, settings, hasVerticalWriting) => {
|
|
5758
|
+
settings.computedPageTurnDirection = settings.pageTurnDirection;
|
|
5759
|
+
settings.computedPageTurnAnimation = settings.pageTurnAnimation;
|
|
5760
|
+
settings.computedPageTurnMode = `controlled`;
|
|
5761
|
+
if ((newManifest == null ? void 0 : newManifest.renditionFlow) === `scrolled-continuous`) {
|
|
5762
|
+
settings.computedPageTurnMode = `scrollable`;
|
|
5763
|
+
settings.computedPageTurnDirection = `vertical`;
|
|
5764
|
+
} else if (newManifest && settings.pageTurnMode === `scrollable` && (newManifest.renditionLayout !== `pre-paginated` || !areAllItemsPrePaginated(newManifest))) {
|
|
5765
|
+
Report.warn(`pageTurnMode ${settings.pageTurnMode} incompatible with current book, switching back to default`);
|
|
5766
|
+
settings.computedPageTurnAnimation = `none`;
|
|
5767
|
+
settings.computedPageTurnMode = `controlled`;
|
|
5768
|
+
} else if (settings.pageTurnMode === `scrollable`) {
|
|
5769
|
+
settings.computedPageTurnMode = `scrollable`;
|
|
5770
|
+
settings.computedPageTurnDirection = `vertical`;
|
|
5771
|
+
}
|
|
5772
|
+
if (hasVerticalWriting && settings.computedPageTurnAnimation === `slide`) {
|
|
5773
|
+
Report.warn(
|
|
5774
|
+
`pageTurnAnimation ${settings.computedPageTurnAnimation} incompatible with current book, switching back to default`
|
|
5775
|
+
);
|
|
5776
|
+
settings.computedPageTurnAnimation = `none`;
|
|
5777
|
+
}
|
|
5778
|
+
if (settings.computedPageTurnMode === `scrollable`) {
|
|
5779
|
+
settings.computedPageTurnAnimationDuration = 0;
|
|
5780
|
+
settings.computedPageTurnAnimation = `none`;
|
|
5781
|
+
} else {
|
|
5782
|
+
settings.computedPageTurnAnimationDuration = settings.pageTurnAnimationDuration !== void 0 ? settings.pageTurnAnimationDuration : 300;
|
|
5783
|
+
}
|
|
5784
|
+
};
|
|
5612
5785
|
const IFRAME_EVENT_BRIDGE_ELEMENT_ID = `proseReaderIframeEventBridgeElement`;
|
|
5613
|
-
const createReader = ({
|
|
5786
|
+
const createReader = ({ hooks: initialHooks, ...inputSettings }) => {
|
|
5614
5787
|
const stateSubject$ = new BehaviorSubject({
|
|
5615
5788
|
supportedPageTurnAnimation: [`fade`, `none`, `slide`],
|
|
5616
5789
|
supportedPageTurnMode: [`controlled`, `scrollable`],
|
|
5617
5790
|
supportedPageTurnDirection: [`horizontal`, `vertical`],
|
|
5618
5791
|
supportedComputedPageTurnDirection: [`horizontal`, `vertical`]
|
|
5619
5792
|
});
|
|
5620
|
-
const readySubject$ = new Subject();
|
|
5621
5793
|
const destroy$ = new Subject();
|
|
5622
5794
|
const selectionSubject$ = new Subject();
|
|
5623
5795
|
const hooksSubject$ = new BehaviorSubject(initialHooks || []);
|
|
@@ -5625,16 +5797,19 @@ const createReader = ({ containerElement, hooks: initialHooks, ...settings }) =>
|
|
|
5625
5797
|
const navigationAdjustedSubject = new Subject();
|
|
5626
5798
|
const currentNavigationPositionSubject$ = new BehaviorSubject({ x: 0, y: 0 });
|
|
5627
5799
|
const viewportStateSubject = new BehaviorSubject(`free`);
|
|
5800
|
+
const settings = createSettings(inputSettings);
|
|
5628
5801
|
const context = createContext(settings);
|
|
5629
|
-
const spineItemManager = createSpineItemManager({ context });
|
|
5802
|
+
const spineItemManager = createSpineItemManager({ context, settings });
|
|
5630
5803
|
const pagination = createPagination({ context, spineItemManager });
|
|
5631
|
-
const
|
|
5632
|
-
const
|
|
5804
|
+
const elementSubject$ = new BehaviorSubject(void 0);
|
|
5805
|
+
const element$ = elementSubject$.pipe(filter(isDefined));
|
|
5806
|
+
const iframeEventBridgeElement$ = new BehaviorSubject(void 0);
|
|
5633
5807
|
const spineItemLocator = createLocationResolver$1({ context });
|
|
5634
5808
|
const spineLocator = createLocationResolver({
|
|
5635
5809
|
context,
|
|
5636
5810
|
spineItemManager,
|
|
5637
|
-
spineItemLocator
|
|
5811
|
+
spineItemLocator,
|
|
5812
|
+
settings
|
|
5638
5813
|
});
|
|
5639
5814
|
const cfiLocator = createCfiLocator({
|
|
5640
5815
|
spineItemManager,
|
|
@@ -5643,9 +5818,10 @@ const createReader = ({ containerElement, hooks: initialHooks, ...settings }) =>
|
|
|
5643
5818
|
});
|
|
5644
5819
|
const navigation$ = navigationSubject.asObservable();
|
|
5645
5820
|
const spine = createSpine({
|
|
5646
|
-
|
|
5647
|
-
iframeEventBridgeElement
|
|
5821
|
+
element$,
|
|
5822
|
+
iframeEventBridgeElement$,
|
|
5648
5823
|
context,
|
|
5824
|
+
settings,
|
|
5649
5825
|
pagination,
|
|
5650
5826
|
spineItemManager,
|
|
5651
5827
|
hooks$: hooksSubject$,
|
|
@@ -5661,22 +5837,26 @@ const createReader = ({ containerElement, hooks: initialHooks, ...settings }) =>
|
|
|
5661
5837
|
context,
|
|
5662
5838
|
pagination,
|
|
5663
5839
|
spineItemManager,
|
|
5664
|
-
parentElement
|
|
5840
|
+
parentElement$: elementSubject$,
|
|
5665
5841
|
cfiLocator,
|
|
5666
5842
|
spineLocator,
|
|
5667
5843
|
hooks$: hooksSubject$,
|
|
5668
|
-
spine
|
|
5844
|
+
spine,
|
|
5845
|
+
settings
|
|
5669
5846
|
});
|
|
5670
|
-
containerElement.appendChild(element);
|
|
5671
|
-
element.appendChild(iframeEventBridgeElement);
|
|
5672
5847
|
viewportNavigator.$.state$.subscribe(viewportStateSubject);
|
|
5673
5848
|
viewportNavigator.$.navigation$.subscribe(navigationSubject);
|
|
5674
5849
|
viewportNavigator.$.navigationAdjustedAfterLayout$.subscribe(navigationAdjustedSubject);
|
|
5675
5850
|
viewportNavigator.$.currentNavigationPosition$.subscribe(currentNavigationPositionSubject$);
|
|
5676
5851
|
const layout = () => {
|
|
5852
|
+
var _a;
|
|
5853
|
+
const containerElement = (_a = elementSubject$.getValue()) == null ? void 0 : _a.parentElement;
|
|
5854
|
+
const element = elementSubject$.getValue();
|
|
5855
|
+
if (!element || !containerElement)
|
|
5856
|
+
throw new Error("Invalid element");
|
|
5677
5857
|
const dimensions = {
|
|
5678
|
-
width: containerElement.offsetWidth,
|
|
5679
|
-
height: containerElement.offsetHeight
|
|
5858
|
+
width: containerElement == null ? void 0 : containerElement.offsetWidth,
|
|
5859
|
+
height: containerElement == null ? void 0 : containerElement.offsetHeight
|
|
5680
5860
|
};
|
|
5681
5861
|
const margin = 0;
|
|
5682
5862
|
const marginTop = 0;
|
|
@@ -5696,12 +5876,21 @@ const createReader = ({ containerElement, hooks: initialHooks, ...settings }) =>
|
|
|
5696
5876
|
});
|
|
5697
5877
|
viewportNavigator.layout();
|
|
5698
5878
|
};
|
|
5699
|
-
const load = (manifest, loadOptions
|
|
5879
|
+
const load = (manifest, loadOptions) => {
|
|
5880
|
+
var _a;
|
|
5700
5881
|
if (context.getManifest()) {
|
|
5701
5882
|
Report.warn(`loading a new book is not supported yet`);
|
|
5702
5883
|
return;
|
|
5703
5884
|
}
|
|
5704
5885
|
Report.log(`load`, { manifest, loadOptions });
|
|
5886
|
+
const element = createWrapperElement(loadOptions.containerElement);
|
|
5887
|
+
const iframeEventBridgeElement = createIframeEventBridgeElement(loadOptions.containerElement);
|
|
5888
|
+
if (loadOptions.containerElement !== ((_a = elementSubject$.getValue()) == null ? void 0 : _a.parentElement)) {
|
|
5889
|
+
elementSubject$.next(element);
|
|
5890
|
+
iframeEventBridgeElement$.next(iframeEventBridgeElement);
|
|
5891
|
+
loadOptions.containerElement.appendChild(element);
|
|
5892
|
+
element.appendChild(iframeEventBridgeElement);
|
|
5893
|
+
}
|
|
5705
5894
|
context.load(manifest, loadOptions);
|
|
5706
5895
|
layout();
|
|
5707
5896
|
if (!loadOptions.cfi) {
|
|
@@ -5709,14 +5898,10 @@ const createReader = ({ containerElement, hooks: initialHooks, ...settings }) =>
|
|
|
5709
5898
|
} else {
|
|
5710
5899
|
viewportNavigator.goToCfi(loadOptions.cfi, { animate: false });
|
|
5711
5900
|
}
|
|
5712
|
-
readySubject$.next();
|
|
5713
5901
|
};
|
|
5714
5902
|
const registerHook = (name, fn) => {
|
|
5715
5903
|
hooksSubject$.next([...hooksSubject$.getValue(), { name, fn }]);
|
|
5716
5904
|
};
|
|
5717
|
-
const manipulateContainer = (cb) => {
|
|
5718
|
-
cb(element);
|
|
5719
|
-
};
|
|
5720
5905
|
spine.$.$.pipe(
|
|
5721
5906
|
tap((event) => {
|
|
5722
5907
|
if (event.type === `onSelectionChange`) {
|
|
@@ -5731,45 +5916,42 @@ const createReader = ({ containerElement, hooks: initialHooks, ...settings }) =>
|
|
|
5731
5916
|
}),
|
|
5732
5917
|
takeUntil$1(context.$.destroy$)
|
|
5733
5918
|
).subscribe();
|
|
5734
|
-
merge(context.$.
|
|
5735
|
-
|
|
5736
|
-
withLatestFrom(context.$.
|
|
5737
|
-
map$1(([, hasVerticalWriting]) => {
|
|
5738
|
-
const settings2 = context.getSettings();
|
|
5919
|
+
merge(context.$.state$, settings.$.settings$).pipe(
|
|
5920
|
+
map$1(() => void 0),
|
|
5921
|
+
withLatestFrom(context.$.state$),
|
|
5922
|
+
map$1(([, { hasVerticalWriting }]) => {
|
|
5739
5923
|
const manifest = context.getManifest();
|
|
5740
5924
|
return {
|
|
5741
5925
|
hasVerticalWriting,
|
|
5742
5926
|
renditionFlow: manifest == null ? void 0 : manifest.renditionFlow,
|
|
5743
5927
|
renditionLayout: manifest == null ? void 0 : manifest.renditionLayout,
|
|
5744
|
-
computedPageTurnMode:
|
|
5928
|
+
computedPageTurnMode: settings.getSettings().computedPageTurnMode
|
|
5745
5929
|
};
|
|
5746
5930
|
}),
|
|
5747
5931
|
distinctUntilChanged(isShallowEqual),
|
|
5748
5932
|
map$1(
|
|
5749
|
-
({
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
-
supportedPageTurnAnimation: renditionFlow === `scrolled-continuous` || computedPageTurnMode === `scrollable` ? [`none`] : hasVerticalWriting ? [`fade`, `none`] : [`fade`, `none`, `slide`],
|
|
5758
|
-
supportedPageTurnDirection: computedPageTurnMode === `scrollable` ? [`vertical`] : renditionLayout === `reflowable` ? [`horizontal`] : [`horizontal`, `vertical`]
|
|
5759
|
-
})
|
|
5933
|
+
({ hasVerticalWriting, renditionFlow, renditionLayout, computedPageTurnMode }) => {
|
|
5934
|
+
return {
|
|
5935
|
+
...stateSubject$.value,
|
|
5936
|
+
supportedPageTurnMode: renditionFlow === `scrolled-continuous` ? [`scrollable`] : !context.areAllItemsPrePaginated() ? [`controlled`] : [`controlled`, `scrollable`],
|
|
5937
|
+
supportedPageTurnAnimation: renditionFlow === `scrolled-continuous` || computedPageTurnMode === `scrollable` ? [`none`] : hasVerticalWriting ? [`fade`, `none`] : [`fade`, `none`, `slide`],
|
|
5938
|
+
supportedPageTurnDirection: computedPageTurnMode === `scrollable` ? [`vertical`] : renditionLayout === `reflowable` ? [`horizontal`] : [`horizontal`, `vertical`]
|
|
5939
|
+
};
|
|
5940
|
+
}
|
|
5760
5941
|
),
|
|
5761
5942
|
takeUntil$1(destroy$)
|
|
5762
5943
|
).subscribe(stateSubject$);
|
|
5763
5944
|
const destroy = () => {
|
|
5945
|
+
var _a, _b;
|
|
5946
|
+
settings.destroy();
|
|
5764
5947
|
hooksSubject$.next([]);
|
|
5765
5948
|
hooksSubject$.complete();
|
|
5766
5949
|
pagination.destroy();
|
|
5767
5950
|
context.destroy();
|
|
5768
5951
|
viewportNavigator.destroy();
|
|
5769
5952
|
spine.destroy();
|
|
5770
|
-
|
|
5771
|
-
iframeEventBridgeElement.remove();
|
|
5772
|
-
readySubject$.complete();
|
|
5953
|
+
(_a = elementSubject$.getValue()) == null ? void 0 : _a.remove();
|
|
5954
|
+
(_b = iframeEventBridgeElement$.getValue()) == null ? void 0 : _b.remove();
|
|
5773
5955
|
stateSubject$.complete();
|
|
5774
5956
|
selectionSubject$.complete();
|
|
5775
5957
|
destroy$.next();
|
|
@@ -5782,7 +5964,6 @@ const createReader = ({ containerElement, hooks: initialHooks, ...settings }) =>
|
|
|
5782
5964
|
viewportNavigator,
|
|
5783
5965
|
manipulateSpineItems: spine.manipulateSpineItems,
|
|
5784
5966
|
manipulateSpineItem: spine.manipulateSpineItem,
|
|
5785
|
-
manipulateContainer,
|
|
5786
5967
|
moveTo: viewportNavigator.moveTo,
|
|
5787
5968
|
turnLeft: viewportNavigator.turnLeft,
|
|
5788
5969
|
turnRight: viewportNavigator.turnRight,
|
|
@@ -5807,23 +5988,23 @@ const createReader = ({ containerElement, hooks: initialHooks, ...settings }) =>
|
|
|
5807
5988
|
layout,
|
|
5808
5989
|
load,
|
|
5809
5990
|
destroy,
|
|
5810
|
-
setSettings: context.setSettings,
|
|
5811
|
-
settings$: context.$.settings$,
|
|
5812
|
-
/**
|
|
5813
|
-
* @important
|
|
5814
|
-
* BehaviorSubject
|
|
5815
|
-
*/
|
|
5816
|
-
pagination$: pagination.$.info$,
|
|
5817
5991
|
spineItems$: spine.$.spineItems$,
|
|
5992
|
+
context$: context.$.state$,
|
|
5993
|
+
pagination,
|
|
5994
|
+
settings: {
|
|
5995
|
+
settings$: settings.$.settings$,
|
|
5996
|
+
getSettings: settings.getSettings,
|
|
5997
|
+
setSettings: (data) => settings.setSettings(data, context.getState())
|
|
5998
|
+
},
|
|
5818
5999
|
$: {
|
|
5819
6000
|
state$: stateSubject$.asObservable(),
|
|
5820
6001
|
/**
|
|
5821
|
-
* Dispatched when the reader has loaded a book and is
|
|
6002
|
+
* Dispatched when the reader has loaded a book and is rendering a book.
|
|
5822
6003
|
* Using navigation API and getting information about current content will
|
|
5823
6004
|
* have an effect.
|
|
5824
6005
|
* It can typically be used to hide a loading indicator.
|
|
5825
6006
|
*/
|
|
5826
|
-
|
|
6007
|
+
loadStatus$: context.$.manifest$.pipe(map$1((manifest) => manifest ? "ready" : "idle")),
|
|
5827
6008
|
/**
|
|
5828
6009
|
* Dispatched when a change in selection happens
|
|
5829
6010
|
*/
|
|
@@ -6026,7 +6207,7 @@ const createResourcesManager = (context) => {
|
|
|
6026
6207
|
}),
|
|
6027
6208
|
takeUntil$1(context.$.destroy$)
|
|
6028
6209
|
).subscribe();
|
|
6029
|
-
const onLoad$ = context.$.
|
|
6210
|
+
const onLoad$ = context.$.manifest$.pipe(
|
|
6030
6211
|
tap(() => {
|
|
6031
6212
|
uniqueID = Date.now().toString();
|
|
6032
6213
|
})
|
|
@@ -6178,9 +6359,9 @@ const progressionEnhancer = (next) => (options) => {
|
|
|
6178
6359
|
totalProgress = getTotalProgressFromPercentages(estimateBeforeThisItem, currentItemWeight, progressWithinThisItem);
|
|
6179
6360
|
}
|
|
6180
6361
|
if (currentSpineIndex === readingOrderLength - 1 && pageIndex === numberOfPages - 1 && totalProgress > 0.99) {
|
|
6181
|
-
return
|
|
6362
|
+
return 100;
|
|
6182
6363
|
}
|
|
6183
|
-
return totalProgress;
|
|
6364
|
+
return totalProgress * 100;
|
|
6184
6365
|
};
|
|
6185
6366
|
const getTotalProgressFromPercentages = (estimateBeforeThisItem, currentItemWeight, progressWithinThisItem) => {
|
|
6186
6367
|
return estimateBeforeThisItem + currentItemWeight * progressWithinThisItem;
|
|
@@ -6188,7 +6369,7 @@ const progressionEnhancer = (next) => (options) => {
|
|
|
6188
6369
|
const getScrollPercentageWithinItem = (context, currentPosition, currentItem) => {
|
|
6189
6370
|
const { height, width } = currentItem.getElementDimensions();
|
|
6190
6371
|
const { top, left } = reader.getAbsolutePositionOf(currentItem);
|
|
6191
|
-
if (
|
|
6372
|
+
if (reader.settings.getSettings().computedPageTurnDirection === `vertical`) {
|
|
6192
6373
|
return Math.max(0, Math.min(1, (currentPosition.y - top + context.getVisibleAreaRect().height) / height));
|
|
6193
6374
|
} else {
|
|
6194
6375
|
return Math.max(0, Math.min(1, (currentPosition.x - left + context.getVisibleAreaRect().width) / width));
|
|
@@ -6378,26 +6559,34 @@ const defaultLoadingElementCreate = ({ container, item }) => {
|
|
|
6378
6559
|
container.appendChild(detailsElement);
|
|
6379
6560
|
return container;
|
|
6380
6561
|
};
|
|
6562
|
+
const publicApiEnhancer = (next) => {
|
|
6563
|
+
return (options) => {
|
|
6564
|
+
const reader = next(options);
|
|
6565
|
+
return reader;
|
|
6566
|
+
};
|
|
6567
|
+
};
|
|
6381
6568
|
const createReaderWithEnhancers = (
|
|
6382
6569
|
//__
|
|
6383
|
-
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
|
|
6400
|
-
|
|
6570
|
+
publicApiEnhancer(
|
|
6571
|
+
loadingEnhancer(
|
|
6572
|
+
webkitEnhancer(
|
|
6573
|
+
fontsEnhancer(
|
|
6574
|
+
linksEnhancer(
|
|
6575
|
+
accessibilityEnhancer(
|
|
6576
|
+
resourcesEnhancer(
|
|
6577
|
+
utilsEnhancer(
|
|
6578
|
+
layoutEnhancer(
|
|
6579
|
+
zoomEnhancer(
|
|
6580
|
+
mediaEnhancer(
|
|
6581
|
+
chromeEnhancer(
|
|
6582
|
+
navigationEnhancer(
|
|
6583
|
+
themeEnhancer(
|
|
6584
|
+
hotkeysEnhancer(
|
|
6585
|
+
paginationEnhancer(
|
|
6586
|
+
progressionEnhancer(
|
|
6587
|
+
// __
|
|
6588
|
+
createReader
|
|
6589
|
+
)
|
|
6401
6590
|
)
|
|
6402
6591
|
)
|
|
6403
6592
|
)
|
|
@@ -6421,4 +6610,4 @@ export {
|
|
|
6421
6610
|
groupBy,
|
|
6422
6611
|
isShallowEqual
|
|
6423
6612
|
};
|
|
6424
|
-
//# sourceMappingURL=
|
|
6613
|
+
//# sourceMappingURL=index.js.map
|