@prose-reader/core 1.40.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} +656 -477
- package/dist/index.js.map +1 -0
- package/dist/{prose.umd.cjs → index.umd.cjs} +654 -475
- 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/manifest.d.ts +0 -2
- 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
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("rxjs"), require("rxjs/operators"), require("@prose-reader/shared")) : typeof define === "function" && define.amd ? define(["exports", "rxjs", "rxjs/operators", "@prose-reader/shared"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.prose = {}, global.rxjs, global.operators, global.shared));
|
|
3
3
|
})(this, function(exports2, rxjs, operators, shared) {
|
|
4
4
|
"use strict";
|
|
5
|
-
const SHOULD_NOT_LAYOUT$3 = false;
|
|
6
5
|
const chromeEnhancer = (next) => (options) => {
|
|
7
6
|
const reader = next(options);
|
|
8
|
-
reader.
|
|
7
|
+
reader.context$.pipe(rxjs.takeUntil(reader.$.destroy$)).subscribe(({ containerElement }) => {
|
|
8
|
+
if (!containerElement)
|
|
9
|
+
return;
|
|
9
10
|
const onScroll = () => {
|
|
10
|
-
if (reader.
|
|
11
|
-
|
|
11
|
+
if (reader.settings.getSettings().computedPageTurnMode === `controlled`) {
|
|
12
|
+
containerElement.scrollTo(0, 0);
|
|
12
13
|
}
|
|
13
14
|
};
|
|
14
|
-
|
|
15
|
-
return SHOULD_NOT_LAYOUT$3;
|
|
15
|
+
containerElement.addEventListener(`scroll`, onScroll);
|
|
16
16
|
});
|
|
17
17
|
reader.registerHook(`item.onLoad`, ({ frame }) => {
|
|
18
18
|
var _a;
|
|
@@ -52,13 +52,16 @@
|
|
|
52
52
|
}
|
|
53
53
|
return true;
|
|
54
54
|
};
|
|
55
|
-
const groupBy = (list, getKey) => list.reduce(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
previous[group]
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
const groupBy = (list, getKey) => list.reduce(
|
|
56
|
+
(previous, currentItem) => {
|
|
57
|
+
const group = getKey(currentItem);
|
|
58
|
+
if (!previous[group])
|
|
59
|
+
previous[group] = [];
|
|
60
|
+
previous[group].push(currentItem);
|
|
61
|
+
return previous;
|
|
62
|
+
},
|
|
63
|
+
{}
|
|
64
|
+
);
|
|
62
65
|
const getBase64FromBlob = (data) => {
|
|
63
66
|
const reader = new FileReader();
|
|
64
67
|
return new Promise((resolve) => {
|
|
@@ -137,30 +140,35 @@
|
|
|
137
140
|
);
|
|
138
141
|
newSettings$.subscribe(settings$);
|
|
139
142
|
settings$.pipe(shouldRequireLayout, operators.tap(applyChangeToSpineItem), rxjs.takeUntil(reader.$.destroy$)).subscribe();
|
|
140
|
-
const settingsMerge$ = rxjs.combineLatest([reader.settings$, settings$]).pipe(
|
|
143
|
+
const settingsMerge$ = rxjs.combineLatest([reader.settings.settings$, settings$]).pipe(
|
|
141
144
|
rxjs.map(([innerSettings, settings]) => ({
|
|
142
145
|
...innerSettings,
|
|
143
146
|
...settings
|
|
144
147
|
}))
|
|
145
148
|
);
|
|
149
|
+
const setSettings = (settings) => {
|
|
150
|
+
const { fontJustification: fontJustification2, fontScale: fontScale2, fontWeight: fontWeight2, lineHeight: lineHeight2, ...passthroughSettings } = settings;
|
|
151
|
+
changes$.next({ fontJustification: fontJustification2, fontScale: fontScale2, fontWeight: fontWeight2, lineHeight: lineHeight2 });
|
|
152
|
+
reader.settings.setSettings(passthroughSettings);
|
|
153
|
+
};
|
|
146
154
|
return {
|
|
147
155
|
...reader,
|
|
148
156
|
destroy: () => {
|
|
149
157
|
changes$.complete();
|
|
150
158
|
settings$.complete();
|
|
159
|
+
reader.destroy();
|
|
151
160
|
},
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
settings$: settingsMerge$
|
|
161
|
+
settings: {
|
|
162
|
+
...reader.settings,
|
|
163
|
+
setSettings,
|
|
164
|
+
settings$: settingsMerge$
|
|
165
|
+
}
|
|
158
166
|
};
|
|
159
167
|
};
|
|
160
168
|
const hotkeysEnhancer = (next) => (options) => {
|
|
161
169
|
const reader = next(options);
|
|
162
170
|
const navigateOnKey = (document2) => rxjs.fromEvent(document2, "keyup").pipe(
|
|
163
|
-
rxjs.withLatestFrom(reader.settings$),
|
|
171
|
+
rxjs.withLatestFrom(reader.settings.settings$),
|
|
164
172
|
rxjs.map(([e, { pageTurnDirection }]) => {
|
|
165
173
|
if (pageTurnDirection === "horizontal") {
|
|
166
174
|
if (e.key === `ArrowRight`) {
|
|
@@ -196,22 +204,30 @@
|
|
|
196
204
|
).subscribe();
|
|
197
205
|
return reader;
|
|
198
206
|
};
|
|
199
|
-
const SHOULD_NOT_LAYOUT$2 = false;
|
|
200
207
|
const createMovingSafePan$ = (reader) => {
|
|
201
208
|
let iframeOverlayForAnimationsElement;
|
|
202
|
-
reader.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
209
|
+
const updateOverlayElement$ = reader.context$.pipe(
|
|
210
|
+
operators.switchMap(({ containerElement }) => {
|
|
211
|
+
if (!containerElement)
|
|
212
|
+
return rxjs.NEVER;
|
|
213
|
+
return new rxjs.Observable(() => {
|
|
214
|
+
iframeOverlayForAnimationsElement = containerElement.ownerDocument.createElement(`div`);
|
|
215
|
+
iframeOverlayForAnimationsElement.style.cssText = `
|
|
216
|
+
position: absolute;
|
|
217
|
+
left: 0;
|
|
218
|
+
top: 0;
|
|
219
|
+
width: 100%;
|
|
220
|
+
height: 100%;
|
|
221
|
+
visibility: hidden;
|
|
222
|
+
`;
|
|
223
|
+
containerElement.appendChild(iframeOverlayForAnimationsElement);
|
|
224
|
+
return () => {
|
|
225
|
+
iframeOverlayForAnimationsElement == null ? void 0 : iframeOverlayForAnimationsElement.remove();
|
|
226
|
+
iframeOverlayForAnimationsElement = void 0;
|
|
227
|
+
};
|
|
228
|
+
});
|
|
229
|
+
})
|
|
230
|
+
);
|
|
215
231
|
const createResetLock$ = (source) => rxjs.scheduled(source, rxjs.animationFrameScheduler).pipe(
|
|
216
232
|
operators.tap(() => {
|
|
217
233
|
iframeOverlayForAnimationsElement == null ? void 0 : iframeOverlayForAnimationsElement.style.setProperty(`visibility`, `hidden`);
|
|
@@ -225,8 +241,8 @@
|
|
|
225
241
|
})
|
|
226
242
|
);
|
|
227
243
|
const resetLockViewportFree$ = createResetLock$(viewportFree$).pipe(operators.take(1));
|
|
228
|
-
const pageTurnMode$ = reader.
|
|
229
|
-
operators.map(() => reader.
|
|
244
|
+
const pageTurnMode$ = reader.settings.settings$.pipe(
|
|
245
|
+
operators.map(() => reader.settings.getSettings().computedPageTurnMode),
|
|
230
246
|
operators.distinctUntilChanged()
|
|
231
247
|
);
|
|
232
248
|
const handleViewportLock$ = pageTurnMode$.pipe(
|
|
@@ -235,19 +251,22 @@
|
|
|
235
251
|
),
|
|
236
252
|
operators.takeUntil(reader.$.destroy$)
|
|
237
253
|
);
|
|
238
|
-
return handleViewportLock
|
|
254
|
+
return rxjs.merge(updateOverlayElement$, handleViewportLock$);
|
|
239
255
|
};
|
|
240
256
|
const mapKeysTo = (keys) => {
|
|
241
257
|
return operators.map((obj) => {
|
|
242
|
-
return Object.entries(obj).reduce(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
258
|
+
return Object.entries(obj).reduce(
|
|
259
|
+
(acc, [key, entry]) => {
|
|
260
|
+
if (keys.includes(key)) {
|
|
261
|
+
return {
|
|
262
|
+
...acc,
|
|
263
|
+
[key]: entry
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
return acc;
|
|
267
|
+
},
|
|
268
|
+
{}
|
|
269
|
+
);
|
|
251
270
|
});
|
|
252
271
|
};
|
|
253
272
|
const fixReflowable = (reader) => {
|
|
@@ -268,7 +287,10 @@
|
|
|
268
287
|
}
|
|
269
288
|
});
|
|
270
289
|
};
|
|
271
|
-
|
|
290
|
+
function isDefined(arg) {
|
|
291
|
+
return arg !== null && arg !== void 0;
|
|
292
|
+
}
|
|
293
|
+
const SHOULD_NOT_LAYOUT = false;
|
|
272
294
|
const layoutEnhancer = (next) => (options) => {
|
|
273
295
|
const { pageHorizontalMargin = 24, pageVerticalMargin = 24 } = options;
|
|
274
296
|
const reader = next(options);
|
|
@@ -283,7 +305,7 @@
|
|
|
283
305
|
void frame.getBoundingClientRect().left;
|
|
284
306
|
hasRedrawn = true;
|
|
285
307
|
}
|
|
286
|
-
return SHOULD_NOT_LAYOUT
|
|
308
|
+
return SHOULD_NOT_LAYOUT;
|
|
287
309
|
});
|
|
288
310
|
});
|
|
289
311
|
reader.registerHook(`item.onLayoutBeforeMeasurement`, ({ frame, minimumWidth, item, isImageType }) => {
|
|
@@ -328,10 +350,17 @@
|
|
|
328
350
|
fixReflowable(reader);
|
|
329
351
|
let observer;
|
|
330
352
|
if (options.layoutAutoResize === `container`) {
|
|
331
|
-
|
|
332
|
-
|
|
353
|
+
reader.context$.pipe(
|
|
354
|
+
operators.map((state) => state.containerElement),
|
|
355
|
+
operators.filter(isDefined),
|
|
356
|
+
operators.distinctUntilChanged(),
|
|
357
|
+
operators.takeUntil(reader.$.destroy$)
|
|
358
|
+
).subscribe((container) => {
|
|
359
|
+
observer = new ResizeObserver(() => {
|
|
360
|
+
reader == null ? void 0 : reader.layout();
|
|
361
|
+
});
|
|
362
|
+
observer.observe(container);
|
|
333
363
|
});
|
|
334
|
-
observer.observe(options.containerElement);
|
|
335
364
|
}
|
|
336
365
|
const movingSafePan$ = createMovingSafePan$(reader);
|
|
337
366
|
movingSafePan$.subscribe();
|
|
@@ -344,27 +373,32 @@
|
|
|
344
373
|
}),
|
|
345
374
|
operators.takeUntil(reader.$.destroy$)
|
|
346
375
|
).subscribe();
|
|
376
|
+
const settings$ = rxjs.combineLatest([reader.settings.settings$, settingsSubject$.asObservable()]).pipe(
|
|
377
|
+
operators.map(([innerSettings, settings]) => ({
|
|
378
|
+
...innerSettings,
|
|
379
|
+
...settings
|
|
380
|
+
}))
|
|
381
|
+
);
|
|
382
|
+
const setSettings = ({ pageVerticalMargin: pageVerticalMargin2, pageHorizontalMargin: pageHorizontalMargin2, ...rest }) => {
|
|
383
|
+
if (pageHorizontalMargin2 !== void 0 || pageVerticalMargin2 !== void 0) {
|
|
384
|
+
settingsSubject$.next({
|
|
385
|
+
pageHorizontalMargin: pageHorizontalMargin2 ?? settingsSubject$.value.pageHorizontalMargin,
|
|
386
|
+
pageVerticalMargin: pageVerticalMargin2 ?? settingsSubject$.value.pageVerticalMargin
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
reader.settings.setSettings(rest);
|
|
390
|
+
};
|
|
347
391
|
return {
|
|
348
392
|
...reader,
|
|
349
393
|
destroy: () => {
|
|
350
394
|
reader.destroy();
|
|
351
395
|
observer == null ? void 0 : observer.disconnect();
|
|
352
396
|
},
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
reader.setSettings(rest);
|
|
361
|
-
},
|
|
362
|
-
settings$: rxjs.combineLatest([reader.settings$, settingsSubject$.asObservable()]).pipe(
|
|
363
|
-
operators.map(([innerSettings, settings]) => ({
|
|
364
|
-
...innerSettings,
|
|
365
|
-
...settings
|
|
366
|
-
}))
|
|
367
|
-
)
|
|
397
|
+
settings: {
|
|
398
|
+
...reader.settings,
|
|
399
|
+
setSettings,
|
|
400
|
+
settings$
|
|
401
|
+
}
|
|
368
402
|
};
|
|
369
403
|
};
|
|
370
404
|
const ROOT_NAMESPACE = `@prose-reader/core`;
|
|
@@ -456,13 +490,15 @@
|
|
|
456
490
|
const handleNavigationForClick = (element) => {
|
|
457
491
|
var _a;
|
|
458
492
|
if (!element.href)
|
|
459
|
-
return;
|
|
493
|
+
return false;
|
|
460
494
|
const hrefUrl = new URL(element.href);
|
|
461
495
|
const hrefWithoutAnchor = `${hrefUrl.origin}${hrefUrl.pathname}`;
|
|
462
496
|
const hasExistingSpineItem = (_a = reader.context.getManifest()) == null ? void 0 : _a.spineItems.some((item) => item.href === hrefWithoutAnchor);
|
|
463
497
|
if (hasExistingSpineItem) {
|
|
464
498
|
reader.goToUrl(hrefUrl);
|
|
499
|
+
return true;
|
|
465
500
|
}
|
|
501
|
+
return false;
|
|
466
502
|
};
|
|
467
503
|
reader.registerHook(`item.onLoad`, ({ frame }) => {
|
|
468
504
|
if (frame.contentDocument) {
|
|
@@ -471,8 +507,8 @@
|
|
|
471
507
|
if (e.target && `style` in e.target && `ELEMENT_NODE` in e.target) {
|
|
472
508
|
Report.warn(`prevented click on`, element, e);
|
|
473
509
|
e.preventDefault();
|
|
474
|
-
handleNavigationForClick(element);
|
|
475
|
-
subject.next({ event: `linkClicked`, data: element });
|
|
510
|
+
const isNavigable = handleNavigationForClick(element);
|
|
511
|
+
subject.next({ event: `linkClicked`, data: element, isNavigable });
|
|
476
512
|
}
|
|
477
513
|
})
|
|
478
514
|
);
|
|
@@ -486,8 +522,7 @@
|
|
|
486
522
|
}
|
|
487
523
|
};
|
|
488
524
|
};
|
|
489
|
-
const
|
|
490
|
-
const reader = next(options);
|
|
525
|
+
const createNavigator = (reader) => {
|
|
491
526
|
const goToNextSpineItem = () => {
|
|
492
527
|
var _a;
|
|
493
528
|
const focusedSpineItemIndex = reader.getFocusedSpineItemIndex() || 0;
|
|
@@ -507,14 +542,19 @@
|
|
|
507
542
|
}
|
|
508
543
|
};
|
|
509
544
|
return {
|
|
510
|
-
|
|
545
|
+
goToNextSpineItem,
|
|
546
|
+
goToPreviousSpineItem,
|
|
511
547
|
goToLeftSpineItem: () => {
|
|
548
|
+
if (reader.settings.getSettings().computedPageTurnDirection === "vertical")
|
|
549
|
+
return;
|
|
512
550
|
if (reader.context.isRTL()) {
|
|
513
551
|
return goToNextSpineItem();
|
|
514
552
|
}
|
|
515
553
|
return goToPreviousSpineItem();
|
|
516
554
|
},
|
|
517
555
|
goToRightSpineItem: () => {
|
|
556
|
+
if (reader.settings.getSettings().computedPageTurnDirection === "vertical")
|
|
557
|
+
return;
|
|
518
558
|
if (reader.context.isRTL()) {
|
|
519
559
|
return goToPreviousSpineItem();
|
|
520
560
|
}
|
|
@@ -522,15 +562,44 @@
|
|
|
522
562
|
}
|
|
523
563
|
};
|
|
524
564
|
};
|
|
565
|
+
const createState = (reader) => {
|
|
566
|
+
return reader.pagination.paginationInfo$.pipe(
|
|
567
|
+
rxjs.withLatestFrom(reader.context.$.manifest$, reader.settings.settings$),
|
|
568
|
+
rxjs.map(([paginationInfo, manifest, { computedPageTurnDirection }]) => {
|
|
569
|
+
const numberOfSpineItems = (manifest == null ? void 0 : manifest.spineItems.length) ?? 0;
|
|
570
|
+
const isAtAbsoluteBeginning = paginationInfo.beginSpineItemIndex === 0 && paginationInfo.beginPageIndexInSpineItem === 0;
|
|
571
|
+
const isAtAbsoluteEnd = paginationInfo.endPageIndexInSpineItem === paginationInfo.endNumberOfPagesInSpineItem - 1 && paginationInfo.endSpineItemIndex === Math.max(numberOfSpineItems - 1, 0);
|
|
572
|
+
return {
|
|
573
|
+
canGoTopSpineItem: computedPageTurnDirection === "vertical" && !isAtAbsoluteBeginning,
|
|
574
|
+
canGoBottomSpineItem: computedPageTurnDirection === "vertical" && !isAtAbsoluteEnd,
|
|
575
|
+
canGoLeftSpineItem: computedPageTurnDirection !== "vertical" && ((manifest == null ? void 0 : manifest.readingDirection) === "ltr" && !isAtAbsoluteBeginning || (manifest == null ? void 0 : manifest.readingDirection) === "rtl" && !isAtAbsoluteEnd),
|
|
576
|
+
canGoRightSpineItem: computedPageTurnDirection !== "vertical" && ((manifest == null ? void 0 : manifest.readingDirection) === "ltr" && !isAtAbsoluteEnd || (manifest == null ? void 0 : manifest.readingDirection) === "rtl" && !isAtAbsoluteBeginning)
|
|
577
|
+
};
|
|
578
|
+
}),
|
|
579
|
+
rxjs.distinctUntilChanged(isShallowEqual)
|
|
580
|
+
);
|
|
581
|
+
};
|
|
582
|
+
const navigationEnhancer = (next) => (options) => {
|
|
583
|
+
const reader = next(options);
|
|
584
|
+
const state$ = createState(reader);
|
|
585
|
+
const navigator2 = createNavigator(reader);
|
|
586
|
+
return {
|
|
587
|
+
...reader,
|
|
588
|
+
navigation: {
|
|
589
|
+
...navigator2,
|
|
590
|
+
state$
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
};
|
|
525
594
|
const NAMESPACE$6 = `pagination`;
|
|
526
595
|
const createPagination = ({ context }) => {
|
|
527
596
|
const paginationSubject$ = new rxjs.BehaviorSubject({
|
|
528
|
-
|
|
529
|
-
|
|
597
|
+
beginPageIndexInSpineItem: void 0,
|
|
598
|
+
beginNumberOfPagesInSpineItem: 0,
|
|
530
599
|
beginCfi: void 0,
|
|
531
600
|
beginSpineItemIndex: void 0,
|
|
532
|
-
|
|
533
|
-
|
|
601
|
+
endPageIndexInSpineItem: void 0,
|
|
602
|
+
endNumberOfPagesInSpineItem: 0,
|
|
534
603
|
endCfi: void 0,
|
|
535
604
|
endSpineItemIndex: void 0
|
|
536
605
|
});
|
|
@@ -557,12 +626,12 @@
|
|
|
557
626
|
const beginInfo = getInfoForUpdate(begin);
|
|
558
627
|
const endInfo = getInfoForUpdate(end);
|
|
559
628
|
const newValues = {
|
|
560
|
-
|
|
561
|
-
|
|
629
|
+
beginPageIndexInSpineItem: beginInfo.pageIndex,
|
|
630
|
+
beginNumberOfPagesInSpineItem: beginInfo.numberOfPages,
|
|
562
631
|
beginCfi: beginInfo.cfi,
|
|
563
632
|
beginSpineItemIndex: begin.spineItemIndex,
|
|
564
|
-
|
|
565
|
-
|
|
633
|
+
endPageIndexInSpineItem: endInfo.pageIndex,
|
|
634
|
+
endNumberOfPagesInSpineItem: endInfo.numberOfPages,
|
|
566
635
|
endCfi: endInfo.cfi,
|
|
567
636
|
endSpineItemIndex: end.spineItemIndex
|
|
568
637
|
};
|
|
@@ -573,18 +642,19 @@
|
|
|
573
642
|
},
|
|
574
643
|
{ disable: true }
|
|
575
644
|
);
|
|
576
|
-
const
|
|
577
|
-
const
|
|
645
|
+
const getPaginationInfo = () => paginationSubject$.value;
|
|
646
|
+
const paginationInfo$ = paginationSubject$.pipe(
|
|
647
|
+
rxjs.distinctUntilChanged(isShallowEqual),
|
|
648
|
+
rxjs.filter(({ beginPageIndexInSpineItem }) => beginPageIndexInSpineItem !== void 0)
|
|
649
|
+
);
|
|
578
650
|
const destroy = () => {
|
|
579
651
|
paginationSubject$.complete();
|
|
580
652
|
};
|
|
581
653
|
return {
|
|
582
654
|
destroy,
|
|
583
655
|
updateBeginAndEnd,
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
info$
|
|
587
|
-
}
|
|
656
|
+
getPaginationInfo,
|
|
657
|
+
paginationInfo$
|
|
588
658
|
};
|
|
589
659
|
};
|
|
590
660
|
const getItemOffsetFromPageIndex = (pageWidth, pageIndex, itemWidth) => {
|
|
@@ -615,15 +685,10 @@
|
|
|
615
685
|
};
|
|
616
686
|
const mapPaginationInfoToExtendedInfo = (paginationInfo) => {
|
|
617
687
|
const context = reader.context;
|
|
618
|
-
const manifest = context.getManifest();
|
|
619
|
-
const numberOfSpineItems = (manifest == null ? void 0 : manifest.spineItems.length) ?? 0;
|
|
620
688
|
const beginItem = paginationInfo.beginSpineItemIndex !== void 0 ? reader.getSpineItem(paginationInfo.beginSpineItemIndex) : void 0;
|
|
621
689
|
const endItem = paginationInfo.endSpineItemIndex !== void 0 ? reader.getSpineItem(paginationInfo.endSpineItemIndex) : void 0;
|
|
622
|
-
const isAtAbsoluteBeginning = paginationInfo.beginSpineItemIndex === 0 && paginationInfo.beginPageIndex === 0;
|
|
623
|
-
const isAtAbsoluteEnd = paginationInfo.endPageIndex === paginationInfo.endNumberOfPages - 1 && paginationInfo.endSpineItemIndex === Math.max(numberOfSpineItems - 1, 0);
|
|
624
690
|
return {
|
|
625
|
-
|
|
626
|
-
beginNumberOfPagesInChapter: paginationInfo.beginNumberOfPages,
|
|
691
|
+
...paginationInfo,
|
|
627
692
|
beginChapterInfo: beginItem ? chaptersInfo[beginItem.item.id] : void 0,
|
|
628
693
|
// chapterIndex: number;
|
|
629
694
|
// pages: number;
|
|
@@ -635,15 +700,9 @@
|
|
|
635
700
|
// domIndex: number;
|
|
636
701
|
// charOffset: number;
|
|
637
702
|
// serializeString?: string;
|
|
638
|
-
beginSpineItemIndex: paginationInfo.beginSpineItemIndex,
|
|
639
|
-
beginCfi: paginationInfo.beginCfi,
|
|
640
703
|
beginSpineItemReadingDirection: beginItem == null ? void 0 : beginItem.getReadingDirection(),
|
|
641
704
|
endChapterInfo: endItem ? chaptersInfo[endItem.item.id] : void 0,
|
|
642
|
-
endPageIndexInChapter: paginationInfo.endPageIndex,
|
|
643
|
-
endNumberOfPagesInChapter: paginationInfo.endNumberOfPages,
|
|
644
|
-
endSpineItemIndex: paginationInfo.endSpineItemIndex,
|
|
645
705
|
endSpineItemReadingDirection: endItem == null ? void 0 : endItem.getReadingDirection(),
|
|
646
|
-
endCfi: paginationInfo.endCfi,
|
|
647
706
|
// spineItemReadingDirection: focusedSpineItem?.getReadingDirection(),
|
|
648
707
|
/**
|
|
649
708
|
* This percentage is based of the weight (kb) of every items and the number of pages.
|
|
@@ -654,23 +713,21 @@
|
|
|
654
713
|
percentageEstimateOfBook: endItem ? reader.progression.getPercentageEstimate(
|
|
655
714
|
context,
|
|
656
715
|
paginationInfo.endSpineItemIndex ?? 0,
|
|
657
|
-
paginationInfo.
|
|
658
|
-
paginationInfo.
|
|
716
|
+
paginationInfo.endNumberOfPagesInSpineItem,
|
|
717
|
+
paginationInfo.endPageIndexInSpineItem || 0,
|
|
659
718
|
reader.getCurrentViewportPosition(),
|
|
660
719
|
endItem
|
|
661
720
|
) : 0,
|
|
662
|
-
isUsingSpread: context.
|
|
721
|
+
isUsingSpread: context.isUsingSpreadMode() ?? false
|
|
663
722
|
// hasNextChapter: (reader.spine.spineItemIndex || 0) < (manifest.readingOrder.length - 1),
|
|
664
723
|
// hasPreviousChapter: (reader.spine.spineItemIndex || 0) < (manifest.readingOrder.length - 1),
|
|
665
724
|
// numberOfSpineItems: context.getManifest()?.readingOrder.length,
|
|
666
|
-
canGoLeft: (manifest == null ? void 0 : manifest.readingDirection) === "ltr" && !isAtAbsoluteBeginning || (manifest == null ? void 0 : manifest.readingDirection) === "rtl" && !isAtAbsoluteEnd,
|
|
667
|
-
canGoRight: (manifest == null ? void 0 : manifest.readingDirection) === "ltr" && !isAtAbsoluteEnd || (manifest == null ? void 0 : manifest.readingDirection) === "rtl" && !isAtAbsoluteBeginning
|
|
668
725
|
};
|
|
669
726
|
};
|
|
670
727
|
const getSpineItemNumberOfPages = (spineItem) => {
|
|
671
728
|
const writingMode = spineItem.spineItemFrame.getWritingMode();
|
|
672
729
|
const { width, height } = spineItem.getElementDimensions();
|
|
673
|
-
const settings = reader.
|
|
730
|
+
const settings = reader.settings.getSettings();
|
|
674
731
|
if (settings.pageTurnDirection === `vertical` && settings.pageTurnMode === `scrollable`) {
|
|
675
732
|
return 1;
|
|
676
733
|
}
|
|
@@ -690,7 +747,7 @@
|
|
|
690
747
|
),
|
|
691
748
|
operators.takeUntil(reader.$.destroy$)
|
|
692
749
|
).subscribe();
|
|
693
|
-
const innerPaginationExtendedInfo$ = reader.pagination$.pipe(
|
|
750
|
+
const innerPaginationExtendedInfo$ = reader.pagination.paginationInfo$.pipe(
|
|
694
751
|
operators.map((info) => ({
|
|
695
752
|
...info,
|
|
696
753
|
...mapPaginationInfoToExtendedInfo(info)
|
|
@@ -699,7 +756,7 @@
|
|
|
699
756
|
);
|
|
700
757
|
const totalPages$ = reader.$.layout$.pipe(
|
|
701
758
|
operators.debounceTime(10, rxjs.animationFrameScheduler),
|
|
702
|
-
operators.withLatestFrom(reader.pagination$),
|
|
759
|
+
operators.withLatestFrom(reader.pagination.paginationInfo$),
|
|
703
760
|
operators.map(() => {
|
|
704
761
|
const numberOfPagesPerItems = getNumberOfPagesPerItems();
|
|
705
762
|
return {
|
|
@@ -716,19 +773,25 @@
|
|
|
716
773
|
numberOfTotalPages: 0
|
|
717
774
|
})
|
|
718
775
|
);
|
|
719
|
-
const
|
|
776
|
+
const paginationInfo$ = rxjs.combineLatest([
|
|
777
|
+
innerPaginationExtendedInfo$,
|
|
778
|
+
totalPages$
|
|
779
|
+
]).pipe(
|
|
720
780
|
operators.map(([pageInfo, totalPageInfo]) => ({
|
|
721
781
|
...pageInfo,
|
|
722
782
|
...totalPageInfo,
|
|
723
|
-
beginAbsolutePageIndex: totalPageInfo.numberOfPagesPerItems.slice(0, pageInfo.beginSpineItemIndex).reduce((acc, numberOfPagesForItem) => acc + numberOfPagesForItem, pageInfo.
|
|
724
|
-
endAbsolutePageIndex: totalPageInfo.numberOfPagesPerItems.slice(0, pageInfo.endSpineItemIndex).reduce((acc, numberOfPagesForItem) => acc + numberOfPagesForItem, pageInfo.
|
|
783
|
+
beginAbsolutePageIndex: totalPageInfo.numberOfPagesPerItems.slice(0, pageInfo.beginSpineItemIndex).reduce((acc, numberOfPagesForItem) => acc + numberOfPagesForItem, pageInfo.beginPageIndexInSpineItem ?? 0),
|
|
784
|
+
endAbsolutePageIndex: totalPageInfo.numberOfPagesPerItems.slice(0, pageInfo.endSpineItemIndex).reduce((acc, numberOfPagesForItem) => acc + numberOfPagesForItem, pageInfo.endPageIndexInSpineItem ?? 0)
|
|
725
785
|
})),
|
|
726
786
|
operators.shareReplay(1),
|
|
727
787
|
operators.takeUntil(reader.$.destroy$)
|
|
728
788
|
);
|
|
729
789
|
return {
|
|
730
790
|
...reader,
|
|
731
|
-
pagination
|
|
791
|
+
pagination: {
|
|
792
|
+
...reader.pagination,
|
|
793
|
+
paginationInfo$
|
|
794
|
+
}
|
|
732
795
|
};
|
|
733
796
|
};
|
|
734
797
|
const buildChapterInfoFromSpineItem = (manifest, item) => {
|
|
@@ -849,7 +912,6 @@
|
|
|
849
912
|
}
|
|
850
913
|
};
|
|
851
914
|
};
|
|
852
|
-
const SHOULD_NOT_LAYOUT = false;
|
|
853
915
|
const createElementZoomer = (reader) => {
|
|
854
916
|
const isZooming$ = new rxjs.BehaviorSubject(false);
|
|
855
917
|
let imageMagnifierContainer;
|
|
@@ -862,7 +924,8 @@
|
|
|
862
924
|
imgLastPosition = { x: 0, y: 0 };
|
|
863
925
|
baseScale = 1;
|
|
864
926
|
lastUserScale = 1;
|
|
865
|
-
reader.
|
|
927
|
+
const container = reader.context.getState().containerElement;
|
|
928
|
+
if (container) {
|
|
866
929
|
imageMagnifierContainer = container.ownerDocument.createElement(`div`);
|
|
867
930
|
imageMagnifierContainer.style.cssText = `
|
|
868
931
|
top: 0;
|
|
@@ -873,6 +936,7 @@
|
|
|
873
936
|
background: black;
|
|
874
937
|
width: 100%;
|
|
875
938
|
height: 100%;
|
|
939
|
+
user-select: none;
|
|
876
940
|
`;
|
|
877
941
|
const clonedImgElement = imgElement.cloneNode();
|
|
878
942
|
clonedImgElement.src = imgElement.src;
|
|
@@ -882,8 +946,7 @@
|
|
|
882
946
|
clonedImgElement.style.setProperty(`pointer-events`, `none`);
|
|
883
947
|
imageMagnifierContainer.appendChild(clonedImgElement);
|
|
884
948
|
container.appendChild(imageMagnifierContainer);
|
|
885
|
-
|
|
886
|
-
});
|
|
949
|
+
}
|
|
887
950
|
scale(1.2);
|
|
888
951
|
setCurrentScaleAsBase();
|
|
889
952
|
};
|
|
@@ -906,14 +969,14 @@
|
|
|
906
969
|
const move = (delta, { isFirst, isLast }) => {
|
|
907
970
|
const imgElement = imageMagnifierContainer == null ? void 0 : imageMagnifierContainer.querySelector(`img`);
|
|
908
971
|
if (isFirst) {
|
|
909
|
-
movingLastDelta =
|
|
972
|
+
movingLastDelta = delta;
|
|
910
973
|
}
|
|
911
974
|
if (delta) {
|
|
912
|
-
const
|
|
913
|
-
const
|
|
975
|
+
const newOffsetX = delta.x - ((movingLastDelta == null ? void 0 : movingLastDelta.x) || 0);
|
|
976
|
+
const newOffsetY = delta.y - ((movingLastDelta == null ? void 0 : movingLastDelta.y) || 0);
|
|
914
977
|
imgLastPosition = {
|
|
915
|
-
x: imgLastPosition.x +
|
|
916
|
-
y: imgLastPosition.y +
|
|
978
|
+
x: imgLastPosition.x + newOffsetX,
|
|
979
|
+
y: imgLastPosition.y + newOffsetY
|
|
917
980
|
};
|
|
918
981
|
imgElement == null ? void 0 : imgElement.style.setProperty(
|
|
919
982
|
`transform`,
|
|
@@ -927,11 +990,8 @@
|
|
|
927
990
|
};
|
|
928
991
|
const exit = () => {
|
|
929
992
|
lastUserScale = 1;
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
imageMagnifierContainer = void 0;
|
|
933
|
-
return SHOULD_NOT_LAYOUT;
|
|
934
|
-
});
|
|
993
|
+
imageMagnifierContainer == null ? void 0 : imageMagnifierContainer.remove();
|
|
994
|
+
imageMagnifierContainer = void 0;
|
|
935
995
|
isZooming$.next(false);
|
|
936
996
|
};
|
|
937
997
|
const _isZooming = () => isZooming$.value;
|
|
@@ -975,7 +1035,10 @@
|
|
|
975
1035
|
};
|
|
976
1036
|
const enter = () => {
|
|
977
1037
|
reset();
|
|
978
|
-
reader.spine.
|
|
1038
|
+
const spineElement = reader.spine.getElement();
|
|
1039
|
+
if (spineElement) {
|
|
1040
|
+
spineElement.style.transformOrigin = `0 0`;
|
|
1041
|
+
}
|
|
979
1042
|
isZooming$.next(true);
|
|
980
1043
|
scale(1);
|
|
981
1044
|
setCurrentScaleAsBase();
|
|
@@ -984,23 +1047,27 @@
|
|
|
984
1047
|
baseScale = lastUserScale;
|
|
985
1048
|
};
|
|
986
1049
|
const scale = (userScale) => {
|
|
1050
|
+
const spineElement = reader.spine.getElement();
|
|
1051
|
+
const viewportElement = reader.viewportNavigator.getElement();
|
|
1052
|
+
if (!spineElement || !viewportElement)
|
|
1053
|
+
return;
|
|
987
1054
|
const roundedScale = Math.ceil((userScale < 1 ? baseScale - (1 - userScale) : baseScale + (userScale - 1)) * 100) / 100;
|
|
988
1055
|
const newScale = Math.max(roundedScale, 1);
|
|
989
|
-
const currentScale =
|
|
990
|
-
const currentScrollTop =
|
|
991
|
-
|
|
992
|
-
|
|
1056
|
+
const currentScale = spineElement.getBoundingClientRect().width / spineElement.offsetWidth;
|
|
1057
|
+
const currentScrollTop = viewportElement.scrollTop;
|
|
1058
|
+
spineElement.style.transform = `scale(${newScale})`;
|
|
1059
|
+
viewportElement.scrollLeft = getNewScaledOffset({
|
|
993
1060
|
newScale,
|
|
994
1061
|
oldScale: currentScale,
|
|
995
|
-
pageSize:
|
|
996
|
-
screenSize:
|
|
997
|
-
scrollOffset:
|
|
1062
|
+
pageSize: viewportElement.clientWidth,
|
|
1063
|
+
screenSize: spineElement.offsetWidth,
|
|
1064
|
+
scrollOffset: viewportElement.scrollLeft
|
|
998
1065
|
});
|
|
999
|
-
|
|
1066
|
+
viewportElement.scrollTop = getNewScaledOffset({
|
|
1000
1067
|
newScale,
|
|
1001
1068
|
oldScale: currentScale,
|
|
1002
|
-
pageSize:
|
|
1003
|
-
screenSize:
|
|
1069
|
+
pageSize: viewportElement.clientHeight,
|
|
1070
|
+
screenSize: spineElement.offsetHeight,
|
|
1004
1071
|
scrollOffset: currentScrollTop
|
|
1005
1072
|
});
|
|
1006
1073
|
lastUserScale = newScale;
|
|
@@ -1032,7 +1099,7 @@
|
|
|
1032
1099
|
const elementZoomer = createElementZoomer(reader);
|
|
1033
1100
|
const viewportZoomer = createViewportZoomer(reader);
|
|
1034
1101
|
const currentZoomerSubject$ = new rxjs.BehaviorSubject(void 0);
|
|
1035
|
-
const isUsingScrollableViewport = () => reader.
|
|
1102
|
+
const isUsingScrollableViewport = () => reader.settings.getSettings().computedPageTurnMode === `scrollable`;
|
|
1036
1103
|
const enter = (imgElement) => {
|
|
1037
1104
|
var _a;
|
|
1038
1105
|
(_a = currentZoomerSubject$ == null ? void 0 : currentZoomerSubject$.value) == null ? void 0 : _a.exit();
|
|
@@ -1098,83 +1165,44 @@
|
|
|
1098
1165
|
}
|
|
1099
1166
|
};
|
|
1100
1167
|
};
|
|
1101
|
-
const
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
numberOfAdjacentSpineItemToPreLoad: 0,
|
|
1115
|
-
...initialSettings
|
|
1116
|
-
};
|
|
1117
|
-
updateComputedSettings(void 0, mergedSettings, false);
|
|
1118
|
-
const settingsSubject$ = new rxjs.BehaviorSubject(mergedSettings);
|
|
1119
|
-
const setSettings = (newSettings, options) => {
|
|
1120
|
-
if (Object.keys(newSettings).length === 0)
|
|
1121
|
-
return;
|
|
1122
|
-
const newMergedSettings = { ...settingsSubject$.value, ...newSettings };
|
|
1123
|
-
updateComputedSettings(options.manifest, newMergedSettings, options.hasVerticalWritingSubject);
|
|
1124
|
-
settingsSubject$.next(newMergedSettings);
|
|
1125
|
-
};
|
|
1126
|
-
const recompute = (options) => {
|
|
1127
|
-
const newMergedSettings = { ...settingsSubject$.value };
|
|
1128
|
-
updateComputedSettings(options.manifest, newMergedSettings, options.hasVerticalWritingSubject);
|
|
1129
|
-
settingsSubject$.next(newMergedSettings);
|
|
1130
|
-
};
|
|
1131
|
-
const destroy = () => {
|
|
1132
|
-
settingsSubject$.complete();
|
|
1133
|
-
};
|
|
1134
|
-
return {
|
|
1135
|
-
getSettings: () => settingsSubject$.value,
|
|
1136
|
-
setSettings,
|
|
1137
|
-
recompute,
|
|
1138
|
-
destroy,
|
|
1139
|
-
$: {
|
|
1140
|
-
settings$: settingsSubject$.asObservable().pipe(operators.distinctUntilChanged(isShallowEqual))
|
|
1141
|
-
}
|
|
1142
|
-
};
|
|
1143
|
-
};
|
|
1144
|
-
const areAllItemsPrePaginated$1 = (manifest) => !(manifest == null ? void 0 : manifest.spineItems.some((item) => item.renditionLayout === `reflowable`));
|
|
1145
|
-
const updateComputedSettings = (newManifest, settings, hasVerticalWriting) => {
|
|
1146
|
-
settings.computedPageTurnDirection = settings.pageTurnDirection;
|
|
1147
|
-
settings.computedPageTurnAnimation = settings.pageTurnAnimation;
|
|
1148
|
-
settings.computedPageTurnMode = `controlled`;
|
|
1149
|
-
if ((newManifest == null ? void 0 : newManifest.renditionFlow) === `scrolled-continuous`) {
|
|
1150
|
-
settings.computedPageTurnMode = `scrollable`;
|
|
1151
|
-
settings.computedPageTurnDirection = `vertical`;
|
|
1152
|
-
} else if (newManifest && settings.pageTurnMode === `scrollable` && (newManifest.renditionLayout !== `pre-paginated` || !areAllItemsPrePaginated$1(newManifest))) {
|
|
1153
|
-
Report.warn(`pageTurnMode ${settings.pageTurnMode} incompatible with current book, switching back to default`);
|
|
1154
|
-
settings.computedPageTurnAnimation = `none`;
|
|
1155
|
-
settings.computedPageTurnMode = `controlled`;
|
|
1156
|
-
} else if (settings.pageTurnMode === `scrollable`) {
|
|
1157
|
-
settings.computedPageTurnMode = `scrollable`;
|
|
1158
|
-
settings.computedPageTurnDirection = `vertical`;
|
|
1159
|
-
}
|
|
1160
|
-
if (hasVerticalWriting && settings.computedPageTurnAnimation === `slide`) {
|
|
1161
|
-
Report.warn(
|
|
1162
|
-
`pageTurnAnimation ${settings.computedPageTurnAnimation} incompatible with current book, switching back to default`
|
|
1163
|
-
);
|
|
1164
|
-
settings.computedPageTurnAnimation = `none`;
|
|
1165
|
-
}
|
|
1166
|
-
if (settings.computedPageTurnMode === `scrollable`) {
|
|
1167
|
-
settings.computedPageTurnAnimationDuration = 0;
|
|
1168
|
-
settings.computedPageTurnAnimation = `none`;
|
|
1169
|
-
} else {
|
|
1170
|
-
settings.computedPageTurnAnimationDuration = settings.pageTurnAnimationDuration !== void 0 ? settings.pageTurnAnimationDuration : 300;
|
|
1168
|
+
const isUsingSpreadMode = ({
|
|
1169
|
+
manifest,
|
|
1170
|
+
visibleAreaRect,
|
|
1171
|
+
forceSinglePageMode
|
|
1172
|
+
}) => {
|
|
1173
|
+
const { height, width } = visibleAreaRect;
|
|
1174
|
+
const isLandscape = width > height;
|
|
1175
|
+
if (forceSinglePageMode)
|
|
1176
|
+
return false;
|
|
1177
|
+
if ((manifest == null ? void 0 : manifest.renditionFlow) === `scrolled-continuous`)
|
|
1178
|
+
return false;
|
|
1179
|
+
if (!isLandscape && (manifest == null ? void 0 : manifest.renditionSpread) === `portrait`) {
|
|
1180
|
+
return true;
|
|
1171
1181
|
}
|
|
1182
|
+
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`);
|
|
1172
1183
|
};
|
|
1173
|
-
const
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
const
|
|
1177
|
-
|
|
1184
|
+
const isFullyPrePaginated = (manifest) => (manifest == null ? void 0 : manifest.renditionLayout) === "pre-paginated" || (manifest == null ? void 0 : manifest.spineItems.every((item) => item.renditionLayout === "pre-paginated"));
|
|
1185
|
+
const createContext = (settings) => {
|
|
1186
|
+
const stateSubject = new rxjs.BehaviorSubject({});
|
|
1187
|
+
const manifest$ = stateSubject.pipe(
|
|
1188
|
+
operators.map((state) => state.manifest),
|
|
1189
|
+
operators.filter(isDefined),
|
|
1190
|
+
operators.distinctUntilChanged()
|
|
1191
|
+
);
|
|
1192
|
+
const containerElement$ = stateSubject.pipe(
|
|
1193
|
+
operators.map((state) => state.containerElement),
|
|
1194
|
+
operators.filter(isDefined),
|
|
1195
|
+
operators.distinctUntilChanged()
|
|
1196
|
+
);
|
|
1197
|
+
const hasVerticalWriting$ = stateSubject.pipe(
|
|
1198
|
+
operators.map((state) => state.hasVerticalWriting),
|
|
1199
|
+
operators.filter(isDefined),
|
|
1200
|
+
operators.distinctUntilChanged()
|
|
1201
|
+
);
|
|
1202
|
+
const isUsingSpreadMode$ = stateSubject.pipe(
|
|
1203
|
+
operators.map((state) => state.isUsingSpreadMode),
|
|
1204
|
+
operators.distinctUntilChanged()
|
|
1205
|
+
);
|
|
1178
1206
|
const visibleAreaRect = {
|
|
1179
1207
|
width: 0,
|
|
1180
1208
|
height: 0,
|
|
@@ -1184,82 +1212,113 @@
|
|
|
1184
1212
|
const marginTop = 0;
|
|
1185
1213
|
const marginBottom = 0;
|
|
1186
1214
|
const destroy$ = new rxjs.Subject();
|
|
1187
|
-
const
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
if (settings.getSettings().forceSinglePageMode)
|
|
1192
|
-
return false;
|
|
1193
|
-
if ((manifest == null ? void 0 : manifest.renditionFlow) === `scrolled-continuous`)
|
|
1194
|
-
return false;
|
|
1195
|
-
if (!isLandscape && (manifest == null ? void 0 : manifest.renditionSpread) === `portrait`) {
|
|
1196
|
-
return true;
|
|
1215
|
+
const setState = (newState) => {
|
|
1216
|
+
const newCompleteState = { ...stateSubject.getValue(), ...newState };
|
|
1217
|
+
if (!isShallowEqual(newCompleteState, stateSubject.getValue())) {
|
|
1218
|
+
stateSubject.next(newCompleteState);
|
|
1197
1219
|
}
|
|
1198
|
-
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`);
|
|
1199
1220
|
};
|
|
1200
1221
|
const load = (newManifest, newLoadOptions) => {
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1222
|
+
setState({
|
|
1223
|
+
manifest: newManifest,
|
|
1224
|
+
...newLoadOptions,
|
|
1225
|
+
isFullyPrePaginated: isFullyPrePaginated(newManifest),
|
|
1226
|
+
isUsingSpreadMode: isUsingSpreadMode({
|
|
1227
|
+
manifest: newManifest,
|
|
1228
|
+
visibleAreaRect,
|
|
1229
|
+
forceSinglePageMode: settings.getSettings().forceSinglePageMode
|
|
1230
|
+
})
|
|
1231
|
+
});
|
|
1205
1232
|
};
|
|
1206
1233
|
const isRTL = () => {
|
|
1207
|
-
|
|
1234
|
+
var _a;
|
|
1235
|
+
return ((_a = stateSubject.getValue().manifest) == null ? void 0 : _a.readingDirection) === `rtl`;
|
|
1208
1236
|
};
|
|
1209
|
-
const setHasVerticalWriting = () =>
|
|
1210
|
-
|
|
1211
|
-
|
|
1237
|
+
const setHasVerticalWriting = (value) => setState({
|
|
1238
|
+
hasVerticalWriting: value
|
|
1239
|
+
});
|
|
1240
|
+
const recomputeSettings$ = rxjs.merge(hasVerticalWriting$, manifest$);
|
|
1241
|
+
recomputeSettings$.pipe(
|
|
1242
|
+
operators.withLatestFrom(hasVerticalWriting$, manifest$),
|
|
1243
|
+
operators.tap(([, hasVerticalWriting, manifest]) => {
|
|
1244
|
+
settings.recompute({ hasVerticalWriting, manifest });
|
|
1245
|
+
}),
|
|
1246
|
+
operators.takeUntil(destroy$)
|
|
1247
|
+
).subscribe();
|
|
1248
|
+
settings.$.settings$.pipe(
|
|
1249
|
+
operators.map(({ forceSinglePageMode }) => forceSinglePageMode),
|
|
1212
1250
|
operators.distinctUntilChanged(),
|
|
1213
|
-
operators.
|
|
1214
|
-
|
|
1251
|
+
operators.withLatestFrom(manifest$),
|
|
1252
|
+
operators.tap(([forceSinglePageMode, manifest]) => {
|
|
1253
|
+
setState({
|
|
1254
|
+
isUsingSpreadMode: isUsingSpreadMode({
|
|
1255
|
+
manifest,
|
|
1256
|
+
visibleAreaRect,
|
|
1257
|
+
forceSinglePageMode
|
|
1258
|
+
})
|
|
1259
|
+
});
|
|
1215
1260
|
}),
|
|
1216
1261
|
operators.takeUntil(destroy$)
|
|
1217
1262
|
).subscribe();
|
|
1218
1263
|
const destroy = () => {
|
|
1219
|
-
|
|
1220
|
-
loadSubject$.complete();
|
|
1264
|
+
stateSubject.complete();
|
|
1221
1265
|
destroy$.next();
|
|
1222
1266
|
destroy$.complete();
|
|
1223
|
-
hasVerticalWritingSubject$.complete();
|
|
1224
1267
|
};
|
|
1225
1268
|
return {
|
|
1226
1269
|
load,
|
|
1227
1270
|
isRTL,
|
|
1228
|
-
areAllItemsPrePaginated: () =>
|
|
1271
|
+
areAllItemsPrePaginated: () => {
|
|
1272
|
+
var _a;
|
|
1273
|
+
return areAllItemsPrePaginated$1((_a = stateSubject.getValue()) == null ? void 0 : _a.manifest);
|
|
1274
|
+
},
|
|
1229
1275
|
destroy,
|
|
1230
|
-
getLoadOptions: () => loadOptions,
|
|
1231
1276
|
getCalculatedInnerMargin: () => 0,
|
|
1232
1277
|
getVisibleAreaRect: () => visibleAreaRect,
|
|
1233
|
-
|
|
1278
|
+
isUsingSpreadMode: () => stateSubject.getValue().isUsingSpreadMode,
|
|
1234
1279
|
setHasVerticalWriting,
|
|
1235
1280
|
setVisibleAreaRect: ({ height, width, x, y }) => {
|
|
1236
1281
|
visibleAreaRect.width = width;
|
|
1237
1282
|
visibleAreaRect.height = height - marginTop - marginBottom;
|
|
1238
1283
|
visibleAreaRect.x = x;
|
|
1239
1284
|
visibleAreaRect.y = y;
|
|
1285
|
+
const manifest = stateSubject.getValue().manifest;
|
|
1286
|
+
if (manifest) {
|
|
1287
|
+
setState({
|
|
1288
|
+
isUsingSpreadMode: isUsingSpreadMode({
|
|
1289
|
+
manifest,
|
|
1290
|
+
visibleAreaRect,
|
|
1291
|
+
forceSinglePageMode: settings.getSettings().forceSinglePageMode
|
|
1292
|
+
})
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
},
|
|
1296
|
+
getState: () => stateSubject.getValue(),
|
|
1297
|
+
getManifest: () => {
|
|
1298
|
+
var _a;
|
|
1299
|
+
return (_a = stateSubject.getValue()) == null ? void 0 : _a.manifest;
|
|
1300
|
+
},
|
|
1301
|
+
getReadingDirection: () => {
|
|
1302
|
+
var _a, _b;
|
|
1303
|
+
return (_b = (_a = stateSubject.getValue()) == null ? void 0 : _a.manifest) == null ? void 0 : _b.readingDirection;
|
|
1240
1304
|
},
|
|
1241
|
-
getManifest: () => manifest,
|
|
1242
|
-
getReadingDirection: () => manifest == null ? void 0 : manifest.readingDirection,
|
|
1243
1305
|
getPageSize: () => {
|
|
1244
1306
|
return {
|
|
1245
|
-
width:
|
|
1307
|
+
width: stateSubject.getValue().isUsingSpreadMode ? visibleAreaRect.width / 2 : visibleAreaRect.width,
|
|
1246
1308
|
height: visibleAreaRect.height
|
|
1247
1309
|
};
|
|
1248
1310
|
},
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
manifest
|
|
1253
|
-
}),
|
|
1311
|
+
containerElement$,
|
|
1312
|
+
isUsingSpreadMode$,
|
|
1313
|
+
hasVerticalWriting$,
|
|
1254
1314
|
$: {
|
|
1255
|
-
|
|
1315
|
+
manifest$,
|
|
1256
1316
|
destroy$: destroy$.asObservable(),
|
|
1257
|
-
|
|
1258
|
-
load$: loadSubject$.asObservable()
|
|
1317
|
+
state$: stateSubject.asObservable()
|
|
1259
1318
|
}
|
|
1260
1319
|
};
|
|
1261
1320
|
};
|
|
1262
|
-
const areAllItemsPrePaginated = (manifest) => !(manifest == null ? void 0 : manifest.spineItems.some((item) => item.renditionLayout === `reflowable`));
|
|
1321
|
+
const areAllItemsPrePaginated$1 = (manifest) => !(manifest == null ? void 0 : manifest.spineItems.some((item) => item.renditionLayout === `reflowable`));
|
|
1263
1322
|
const __UNSAFE_REFERENCE_ORIGINAL_IFRAME_EVENT_KEY = `__UNSAFE_REFERENCE_ORIGINAL_IFRAME_EVENT`;
|
|
1264
1323
|
const ITEM_EXTENSION_VALID_FOR_FRAME_SRC = [`.xhtml`, `.html`, `.htm`];
|
|
1265
1324
|
const HTML_PREFIX$1 = `prose-reader`;
|
|
@@ -1376,7 +1435,8 @@
|
|
|
1376
1435
|
fetchResource,
|
|
1377
1436
|
hooks$,
|
|
1378
1437
|
context,
|
|
1379
|
-
viewportState
|
|
1438
|
+
viewportState$,
|
|
1439
|
+
settings
|
|
1380
1440
|
}) => {
|
|
1381
1441
|
const destroySubject$ = new rxjs.Subject();
|
|
1382
1442
|
const loadSubject$ = new rxjs.Subject();
|
|
@@ -1465,7 +1525,7 @@
|
|
|
1465
1525
|
if ((frame == null ? void 0 : frame.contentDocument) && body) {
|
|
1466
1526
|
computedStyleAfterLoad = (_b = frame == null ? void 0 : frame.contentWindow) == null ? void 0 : _b.getComputedStyle(body);
|
|
1467
1527
|
}
|
|
1468
|
-
if (
|
|
1528
|
+
if (settings.getSettings().computedPageTurnMode !== `scrollable`) {
|
|
1469
1529
|
frame.setAttribute(`tab-index`, `0`);
|
|
1470
1530
|
}
|
|
1471
1531
|
const manipulableFrame = createFrameManipulator(frame);
|
|
@@ -1534,7 +1594,8 @@
|
|
|
1534
1594
|
fetchResource,
|
|
1535
1595
|
context,
|
|
1536
1596
|
hooks$,
|
|
1537
|
-
viewportState
|
|
1597
|
+
viewportState$,
|
|
1598
|
+
settings
|
|
1538
1599
|
}) => {
|
|
1539
1600
|
const destroySubject$ = new rxjs.Subject();
|
|
1540
1601
|
const {
|
|
@@ -1543,7 +1604,7 @@
|
|
|
1543
1604
|
unload,
|
|
1544
1605
|
destroy: loaderDestroy,
|
|
1545
1606
|
getComputedStyleAfterLoad
|
|
1546
|
-
} = createLoader({ context, hooks$, item, parent, fetchResource, viewportState
|
|
1607
|
+
} = createLoader({ context, hooks$, item, parent, fetchResource, viewportState$, settings });
|
|
1547
1608
|
let isLoadedSync = false;
|
|
1548
1609
|
let isReadySync = false;
|
|
1549
1610
|
isLoaded$.subscribe({
|
|
@@ -1631,7 +1692,7 @@
|
|
|
1631
1692
|
if (frame) {
|
|
1632
1693
|
frame.style.width = `${size.width}px`;
|
|
1633
1694
|
frame.style.height = `${size.height}px`;
|
|
1634
|
-
if (
|
|
1695
|
+
if (settings.getSettings().computedPageTurnMode !== `scrollable`) {
|
|
1635
1696
|
frame.setAttribute(`tab-index`, `0`);
|
|
1636
1697
|
}
|
|
1637
1698
|
}
|
|
@@ -1896,9 +1957,12 @@
|
|
|
1896
1957
|
`pointermove`,
|
|
1897
1958
|
`pointerout`,
|
|
1898
1959
|
`pointerover`,
|
|
1899
|
-
`pointerup
|
|
1960
|
+
`pointerup`,
|
|
1961
|
+
`touchstart`,
|
|
1962
|
+
`touchend`
|
|
1900
1963
|
];
|
|
1901
1964
|
const mouseEvents = [
|
|
1965
|
+
`click`,
|
|
1902
1966
|
`mousedown`,
|
|
1903
1967
|
`mouseup`,
|
|
1904
1968
|
`mouseenter`,
|
|
@@ -1912,9 +1976,10 @@
|
|
|
1912
1976
|
item,
|
|
1913
1977
|
context,
|
|
1914
1978
|
parentElement,
|
|
1915
|
-
iframeEventBridgeElement
|
|
1979
|
+
iframeEventBridgeElement$,
|
|
1916
1980
|
hooks$,
|
|
1917
|
-
viewportState
|
|
1981
|
+
viewportState$,
|
|
1982
|
+
settings
|
|
1918
1983
|
}) => {
|
|
1919
1984
|
var _a;
|
|
1920
1985
|
const destroySubject$ = new rxjs.Subject();
|
|
@@ -1922,14 +1987,15 @@
|
|
|
1922
1987
|
const overlayElement = createOverlayElement(parentElement, item);
|
|
1923
1988
|
const fingerTracker = createFingerTracker();
|
|
1924
1989
|
const selectionTracker = createSelectionTracker();
|
|
1925
|
-
const frameHooks = createFrameHooks(iframeEventBridgeElement
|
|
1990
|
+
const frameHooks = createFrameHooks(iframeEventBridgeElement$, fingerTracker, selectionTracker);
|
|
1926
1991
|
const spineItemFrame = createFrameItem({
|
|
1927
1992
|
parent: containerElement,
|
|
1928
1993
|
item,
|
|
1929
1994
|
context,
|
|
1930
|
-
fetchResource: (_a = context.
|
|
1995
|
+
fetchResource: (_a = context.getState()) == null ? void 0 : _a.fetchResource,
|
|
1931
1996
|
hooks$: hooks$.asObservable().pipe(operators.map((hooks) => [...hooks, ...frameHooks])),
|
|
1932
|
-
viewportState
|
|
1997
|
+
viewportState$,
|
|
1998
|
+
settings
|
|
1933
1999
|
});
|
|
1934
2000
|
containerElement.appendChild(overlayElement);
|
|
1935
2001
|
parentElement.appendChild(containerElement);
|
|
@@ -2054,10 +2120,10 @@
|
|
|
2054
2120
|
};
|
|
2055
2121
|
};
|
|
2056
2122
|
const getResource = async () => {
|
|
2057
|
-
const
|
|
2123
|
+
const fetchResource = context.getState().fetchResource;
|
|
2058
2124
|
const lastFetch = (_) => {
|
|
2059
|
-
if (
|
|
2060
|
-
return
|
|
2125
|
+
if (fetchResource) {
|
|
2126
|
+
return fetchResource(item);
|
|
2061
2127
|
}
|
|
2062
2128
|
return fetch(item.href);
|
|
2063
2129
|
};
|
|
@@ -2193,7 +2259,7 @@
|
|
|
2193
2259
|
`;
|
|
2194
2260
|
return element;
|
|
2195
2261
|
};
|
|
2196
|
-
const createFrameHooks = (iframeEventBridgeElement
|
|
2262
|
+
const createFrameHooks = (iframeEventBridgeElement$, fingerTracker, selectionTracker) => {
|
|
2197
2263
|
return [
|
|
2198
2264
|
{
|
|
2199
2265
|
name: `item.onLoad`,
|
|
@@ -2201,6 +2267,7 @@
|
|
|
2201
2267
|
const unregister = passthroughEvents.map((event) => {
|
|
2202
2268
|
var _a;
|
|
2203
2269
|
const listener = (e) => {
|
|
2270
|
+
var _a2;
|
|
2204
2271
|
let convertedEvent = e;
|
|
2205
2272
|
if (isPointerEvent(e)) {
|
|
2206
2273
|
convertedEvent = new PointerEvent(e.type, e);
|
|
@@ -2210,7 +2277,7 @@
|
|
|
2210
2277
|
}
|
|
2211
2278
|
if (convertedEvent !== e) {
|
|
2212
2279
|
attachOriginalFrameEventToDocumentEvent(convertedEvent, e);
|
|
2213
|
-
iframeEventBridgeElement.dispatchEvent(convertedEvent);
|
|
2280
|
+
(_a2 = iframeEventBridgeElement$.getValue()) == null ? void 0 : _a2.dispatchEvent(convertedEvent);
|
|
2214
2281
|
}
|
|
2215
2282
|
};
|
|
2216
2283
|
(_a = frame.contentDocument) == null ? void 0 : _a.addEventListener(event, listener);
|
|
@@ -2240,17 +2307,19 @@
|
|
|
2240
2307
|
item,
|
|
2241
2308
|
context,
|
|
2242
2309
|
containerElement,
|
|
2243
|
-
iframeEventBridgeElement
|
|
2310
|
+
iframeEventBridgeElement$,
|
|
2244
2311
|
hooks$,
|
|
2245
|
-
viewportState
|
|
2312
|
+
viewportState$,
|
|
2313
|
+
settings
|
|
2246
2314
|
}) => {
|
|
2247
2315
|
const commonSpineItem = createCommonSpineItem({
|
|
2248
2316
|
context,
|
|
2249
2317
|
item,
|
|
2250
2318
|
parentElement: containerElement,
|
|
2251
|
-
iframeEventBridgeElement
|
|
2319
|
+
iframeEventBridgeElement$,
|
|
2252
2320
|
hooks$,
|
|
2253
|
-
viewportState
|
|
2321
|
+
viewportState$,
|
|
2322
|
+
settings
|
|
2254
2323
|
});
|
|
2255
2324
|
const spineItemFrame = commonSpineItem.spineItemFrame;
|
|
2256
2325
|
const layout = ({
|
|
@@ -2269,7 +2338,7 @@
|
|
|
2269
2338
|
const cssLink = buildDocumentStyle(
|
|
2270
2339
|
{
|
|
2271
2340
|
...commonSpineItem.getDimensionsForPaginatedContent(),
|
|
2272
|
-
enableTouch:
|
|
2341
|
+
enableTouch: settings.getSettings().computedPageTurnMode !== `scrollable`,
|
|
2273
2342
|
spreadPosition
|
|
2274
2343
|
},
|
|
2275
2344
|
viewportDimensions
|
|
@@ -2412,17 +2481,19 @@
|
|
|
2412
2481
|
item,
|
|
2413
2482
|
context,
|
|
2414
2483
|
containerElement,
|
|
2415
|
-
iframeEventBridgeElement
|
|
2484
|
+
iframeEventBridgeElement$,
|
|
2416
2485
|
hooks$,
|
|
2417
|
-
viewportState
|
|
2486
|
+
viewportState$,
|
|
2487
|
+
settings
|
|
2418
2488
|
}) => {
|
|
2419
2489
|
const commonSpineItem = createCommonSpineItem({
|
|
2420
2490
|
context,
|
|
2421
2491
|
item,
|
|
2422
2492
|
parentElement: containerElement,
|
|
2423
|
-
iframeEventBridgeElement
|
|
2493
|
+
iframeEventBridgeElement$,
|
|
2424
2494
|
hooks$,
|
|
2425
|
-
viewportState
|
|
2495
|
+
viewportState$,
|
|
2496
|
+
settings
|
|
2426
2497
|
});
|
|
2427
2498
|
const spineItemFrame = commonSpineItem.spineItemFrame;
|
|
2428
2499
|
let latestContentHeightWhenLoaded;
|
|
@@ -2461,7 +2532,7 @@
|
|
|
2461
2532
|
} else {
|
|
2462
2533
|
const frameStyle = commonSpineItem.isImageType() ? buildStyleForReflowableImageOnly({
|
|
2463
2534
|
isScrollable: ((_g = context.getManifest()) == null ? void 0 : _g.renditionFlow) === `scrolled-continuous`,
|
|
2464
|
-
enableTouch:
|
|
2535
|
+
enableTouch: settings.getSettings().computedPageTurnMode !== `scrollable`
|
|
2465
2536
|
}) : buildStyleWithMultiColumn(
|
|
2466
2537
|
commonSpineItem.getDimensionsForReflowableContent(spineItemFrame.isUsingVerticalWriting(), minimumWidth)
|
|
2467
2538
|
);
|
|
@@ -2686,36 +2757,39 @@
|
|
|
2686
2757
|
item,
|
|
2687
2758
|
context,
|
|
2688
2759
|
containerElement,
|
|
2689
|
-
iframeEventBridgeElement
|
|
2760
|
+
iframeEventBridgeElement$,
|
|
2690
2761
|
hooks$,
|
|
2691
|
-
viewportState
|
|
2762
|
+
viewportState$,
|
|
2763
|
+
settings
|
|
2692
2764
|
}) => {
|
|
2693
2765
|
if (item.renditionLayout === `pre-paginated`) {
|
|
2694
2766
|
return createPrePaginatedSpineItem({
|
|
2695
2767
|
item,
|
|
2696
2768
|
context,
|
|
2697
2769
|
containerElement,
|
|
2698
|
-
iframeEventBridgeElement
|
|
2770
|
+
iframeEventBridgeElement$,
|
|
2699
2771
|
hooks$,
|
|
2700
|
-
viewportState
|
|
2772
|
+
viewportState$,
|
|
2773
|
+
settings
|
|
2701
2774
|
});
|
|
2702
2775
|
}
|
|
2703
2776
|
return createReflowableSpineItem({
|
|
2704
2777
|
item,
|
|
2705
2778
|
context,
|
|
2706
2779
|
containerElement,
|
|
2707
|
-
iframeEventBridgeElement
|
|
2780
|
+
iframeEventBridgeElement$,
|
|
2708
2781
|
hooks$,
|
|
2709
|
-
viewportState
|
|
2782
|
+
viewportState$,
|
|
2783
|
+
settings
|
|
2710
2784
|
});
|
|
2711
2785
|
};
|
|
2712
2786
|
const createEventsHelper = ({
|
|
2713
|
-
iframeEventBridgeElement
|
|
2787
|
+
iframeEventBridgeElement$,
|
|
2714
2788
|
locator
|
|
2715
2789
|
}) => {
|
|
2716
2790
|
const normalizeEventForViewport = (event) => {
|
|
2717
2791
|
var _a;
|
|
2718
|
-
const eventIsComingFromBridge = event.target === iframeEventBridgeElement;
|
|
2792
|
+
const eventIsComingFromBridge = event.target === iframeEventBridgeElement$.getValue();
|
|
2719
2793
|
const iframeOriginalEvent = getOriginalFrameEventFromDocumentEvent(event);
|
|
2720
2794
|
const originalFrame = (_a = iframeOriginalEvent == null ? void 0 : iframeOriginalEvent.view) == null ? void 0 : _a.frameElement;
|
|
2721
2795
|
if (!eventIsComingFromBridge || !iframeOriginalEvent || !originalFrame)
|
|
@@ -3663,11 +3737,12 @@
|
|
|
3663
3737
|
};
|
|
3664
3738
|
};
|
|
3665
3739
|
const report = Report.namespace(`spine`);
|
|
3740
|
+
const noopElement$1 = document.createElement("div");
|
|
3666
3741
|
const createSpine = ({
|
|
3667
|
-
|
|
3742
|
+
element$,
|
|
3668
3743
|
context,
|
|
3669
3744
|
pagination,
|
|
3670
|
-
iframeEventBridgeElement
|
|
3745
|
+
iframeEventBridgeElement$,
|
|
3671
3746
|
spineItemManager,
|
|
3672
3747
|
hooks$,
|
|
3673
3748
|
spineItemLocator,
|
|
@@ -3676,31 +3751,32 @@
|
|
|
3676
3751
|
navigation$,
|
|
3677
3752
|
navigationAdjusted$,
|
|
3678
3753
|
currentNavigationPosition$,
|
|
3679
|
-
viewportState
|
|
3754
|
+
viewportState$,
|
|
3755
|
+
settings
|
|
3680
3756
|
}) => {
|
|
3681
3757
|
const spineItems$ = new rxjs.Subject();
|
|
3682
3758
|
const itemsBeforeDestroySubject$ = new rxjs.Subject();
|
|
3683
3759
|
const subject = new rxjs.Subject();
|
|
3684
|
-
const containerElement =
|
|
3760
|
+
const containerElement$ = new rxjs.BehaviorSubject(noopElement$1);
|
|
3685
3761
|
const eventsHelper = createEventsHelper({
|
|
3686
3762
|
context,
|
|
3687
3763
|
spineItemManager,
|
|
3688
|
-
iframeEventBridgeElement
|
|
3764
|
+
iframeEventBridgeElement$,
|
|
3689
3765
|
locator: spineLocator
|
|
3690
3766
|
});
|
|
3691
3767
|
let selectionSubscription;
|
|
3692
|
-
const reload = () => {
|
|
3693
|
-
var _a;
|
|
3768
|
+
const reload = (manifest) => {
|
|
3694
3769
|
itemsBeforeDestroySubject$.next();
|
|
3695
3770
|
spineItemManager.destroyItems();
|
|
3696
|
-
|
|
3771
|
+
manifest.spineItems.map((resource) => {
|
|
3697
3772
|
const spineItem = createSpineItem({
|
|
3698
3773
|
item: resource,
|
|
3699
|
-
containerElement,
|
|
3700
|
-
iframeEventBridgeElement
|
|
3774
|
+
containerElement: containerElement$.getValue(),
|
|
3775
|
+
iframeEventBridgeElement$,
|
|
3701
3776
|
context,
|
|
3702
3777
|
hooks$,
|
|
3703
|
-
viewportState
|
|
3778
|
+
viewportState$,
|
|
3779
|
+
settings
|
|
3704
3780
|
});
|
|
3705
3781
|
spineItemManager.add(spineItem);
|
|
3706
3782
|
});
|
|
@@ -3719,7 +3795,7 @@
|
|
|
3719
3795
|
var _a;
|
|
3720
3796
|
(_a = spineItemManager.get(id)) == null ? void 0 : _a.manipulateSpineItem(cb);
|
|
3721
3797
|
};
|
|
3722
|
-
context.$.
|
|
3798
|
+
context.$.manifest$.pipe(operators.tap(reload), operators.takeUntil(context.$.destroy$)).subscribe();
|
|
3723
3799
|
const waitForViewportFree$ = viewportState$.pipe(
|
|
3724
3800
|
operators.filter((v) => v === `free`),
|
|
3725
3801
|
operators.take(1)
|
|
@@ -3734,10 +3810,10 @@
|
|
|
3734
3810
|
const spineItemsFromPosition = spineLocator.getSpineItemsFromReadingOrderPosition(position);
|
|
3735
3811
|
const beginSpineItem = spineItemsFromPosition ? spineItemManager.get(spineItemsFromPosition.begin) : void 0;
|
|
3736
3812
|
const endSpineItem = spineItemsFromPosition ? spineItemManager.get(spineItemsFromPosition.end) : void 0;
|
|
3737
|
-
const beginLastCfi = pagination.
|
|
3738
|
-
const endLastCfi = pagination.
|
|
3739
|
-
const shouldUpdateBeginCfi = pagination.
|
|
3740
|
-
const shouldUpdateEndCfi = pagination.
|
|
3813
|
+
const beginLastCfi = pagination.getPaginationInfo().beginCfi;
|
|
3814
|
+
const endLastCfi = pagination.getPaginationInfo().endCfi;
|
|
3815
|
+
const shouldUpdateBeginCfi = pagination.getPaginationInfo().beginSpineItemIndex !== (spineItemsFromPosition == null ? void 0 : spineItemsFromPosition.begin) || beginLastCfi === void 0 || (beginLastCfi == null ? void 0 : beginLastCfi.startsWith(`epubcfi(/0`));
|
|
3816
|
+
const shouldUpdateEndCfi = pagination.getPaginationInfo().endSpineItemIndex !== (spineItemsFromPosition == null ? void 0 : spineItemsFromPosition.end) || endLastCfi === void 0 || (endLastCfi == null ? void 0 : endLastCfi.startsWith(`epubcfi(/0`));
|
|
3741
3817
|
if (beginSpineItem && endSpineItem && spineItemsFromPosition) {
|
|
3742
3818
|
const beginPosition = spineLocator.getSpineItemPositionFromSpinePosition(
|
|
3743
3819
|
spineItemsFromPosition.beginPosition,
|
|
@@ -3796,16 +3872,10 @@
|
|
|
3796
3872
|
selectionTracker$.pipe(
|
|
3797
3873
|
operators.filter(({ event: event2 }) => event2 === `selectstart`),
|
|
3798
3874
|
operators.switchMap(
|
|
3799
|
-
(
|
|
3875
|
+
() => fingerTracker$.pipe(
|
|
3800
3876
|
operators.filter(({ event: event2 }) => event2 === `fingermove`),
|
|
3801
3877
|
operators.debounce(() => rxjs.interval(1e3)),
|
|
3802
|
-
operators.takeUntil(
|
|
3803
|
-
fingerTracker$.pipe(
|
|
3804
|
-
operators.filter(({ event: event2 }) => event2 === `fingerout`),
|
|
3805
|
-
operators.tap(() => {
|
|
3806
|
-
})
|
|
3807
|
-
)
|
|
3808
|
-
),
|
|
3878
|
+
operators.takeUntil(fingerTracker$.pipe(operators.filter(({ event: event2 }) => event2 === `fingerout`))),
|
|
3809
3879
|
operators.tap(({ data }) => {
|
|
3810
3880
|
})
|
|
3811
3881
|
)
|
|
@@ -3863,7 +3933,7 @@
|
|
|
3863
3933
|
*
|
|
3864
3934
|
* The cfi is later adjusted with heavy dom lookup once the viewport is free.
|
|
3865
3935
|
*/
|
|
3866
|
-
cfi: (lastExpectedNavigation == null ? void 0 : lastExpectedNavigation.type) === `navigate-from-cfi` && spineItemToFocus === beginSpineItem ? lastExpectedNavigation.data : data.triggeredBy === `adjust` &&
|
|
3936
|
+
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) : (
|
|
3867
3937
|
/* @todo check ? */
|
|
3868
3938
|
cfiLocator.getRootCfi(beginSpineItem)
|
|
3869
3939
|
),
|
|
@@ -3875,7 +3945,7 @@
|
|
|
3875
3945
|
spineItem: endSpineItem,
|
|
3876
3946
|
spineItemIndex: endItemIndex,
|
|
3877
3947
|
pageIndex: endPageIndex,
|
|
3878
|
-
cfi: (lastExpectedNavigation == null ? void 0 : lastExpectedNavigation.type) === `navigate-from-cfi` && spineItemToFocus === endSpineItem ? lastExpectedNavigation.data : data.triggeredBy === `adjust` &&
|
|
3948
|
+
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) : (
|
|
3879
3949
|
/* @todo check ? */
|
|
3880
3950
|
cfiLocator.getRootCfi(endSpineItem)
|
|
3881
3951
|
),
|
|
@@ -3941,8 +4011,13 @@
|
|
|
3941
4011
|
}),
|
|
3942
4012
|
operators.takeUntil(context.$.destroy$)
|
|
3943
4013
|
).subscribe();
|
|
4014
|
+
const elementSub = element$.pipe().subscribe((element) => {
|
|
4015
|
+
const containerElement = createContainerElement(element.ownerDocument);
|
|
4016
|
+
containerElement$.next(containerElement);
|
|
4017
|
+
});
|
|
3944
4018
|
return {
|
|
3945
|
-
element
|
|
4019
|
+
element$: containerElement$,
|
|
4020
|
+
getElement: () => containerElement$.getValue(),
|
|
3946
4021
|
locator: spineLocator,
|
|
3947
4022
|
spineItemLocator,
|
|
3948
4023
|
cfiLocator,
|
|
@@ -3950,13 +4025,14 @@
|
|
|
3950
4025
|
manipulateSpineItems,
|
|
3951
4026
|
manipulateSpineItem,
|
|
3952
4027
|
destroy: () => {
|
|
4028
|
+
elementSub.unsubscribe();
|
|
3953
4029
|
spineItems$.complete();
|
|
3954
4030
|
itemsBeforeDestroySubject$.next();
|
|
3955
4031
|
itemsBeforeDestroySubject$.complete();
|
|
3956
4032
|
subject.complete();
|
|
3957
4033
|
spineItemManager.destroy();
|
|
3958
4034
|
selectionSubscription == null ? void 0 : selectionSubscription.unsubscribe();
|
|
3959
|
-
containerElement.remove();
|
|
4035
|
+
containerElement$.getValue().remove();
|
|
3960
4036
|
},
|
|
3961
4037
|
adjustPagination,
|
|
3962
4038
|
isSelecting: () => {
|
|
@@ -3975,31 +4051,17 @@
|
|
|
3975
4051
|
}
|
|
3976
4052
|
};
|
|
3977
4053
|
};
|
|
3978
|
-
const createContainerElement = (doc
|
|
4054
|
+
const createContainerElement = (doc) => {
|
|
3979
4055
|
const element = doc.createElement(`div`);
|
|
3980
4056
|
element.style.cssText = `
|
|
3981
4057
|
height: 100%;
|
|
3982
4058
|
position: relative;
|
|
3983
4059
|
`;
|
|
3984
4060
|
element.className = `${HTML_PREFIX$1}-spine`;
|
|
3985
|
-
return
|
|
3986
|
-
if (hook.name === `spine.onBeforeContainerCreated`) {
|
|
3987
|
-
return hook.fn(element2);
|
|
3988
|
-
}
|
|
3989
|
-
return element2;
|
|
3990
|
-
}, element);
|
|
3991
|
-
};
|
|
3992
|
-
const getCoverItem = (manifest) => {
|
|
3993
|
-
var _a;
|
|
3994
|
-
const coverItem = (_a = manifest.guide) == null ? void 0 : _a.find((item) => item.type === `cover`);
|
|
3995
|
-
return manifest.spineItems.findIndex((item) => {
|
|
3996
|
-
if (!(coverItem == null ? void 0 : coverItem.href))
|
|
3997
|
-
return false;
|
|
3998
|
-
return item.href.endsWith(coverItem.href);
|
|
3999
|
-
});
|
|
4061
|
+
return element;
|
|
4000
4062
|
};
|
|
4001
4063
|
const NAMESPACE$4 = `spineItemManager`;
|
|
4002
|
-
const createSpineItemManager = ({ context }) => {
|
|
4064
|
+
const createSpineItemManager = ({ context, settings }) => {
|
|
4003
4065
|
const focus$ = new rxjs.Subject();
|
|
4004
4066
|
const layout$ = new rxjs.Subject();
|
|
4005
4067
|
let itemLayoutInformation = [];
|
|
@@ -4009,14 +4071,13 @@
|
|
|
4009
4071
|
const manifest = context.getManifest();
|
|
4010
4072
|
const newItemLayoutInformation = [];
|
|
4011
4073
|
const isGloballyPrePaginated = (manifest == null ? void 0 : manifest.renditionLayout) === `pre-paginated`;
|
|
4012
|
-
manifest ? getCoverItem(manifest) : void 0;
|
|
4013
4074
|
orderedSpineItemsSubject$.value.reduce(
|
|
4014
4075
|
({ horizontalOffset, verticalOffset }, item, index) => {
|
|
4015
4076
|
let minimumWidth = context.getPageSize().width;
|
|
4016
4077
|
let blankPagePosition = `none`;
|
|
4017
4078
|
const itemStartOnNewScreen = horizontalOffset % context.getVisibleAreaRect().width === 0;
|
|
4018
4079
|
const isLastItem = index === orderedSpineItemsSubject$.value.length - 1;
|
|
4019
|
-
if (context.
|
|
4080
|
+
if (context.isUsingSpreadMode()) {
|
|
4020
4081
|
if (!isGloballyPrePaginated && item.item.renditionLayout === `reflowable` && !isLastItem) {
|
|
4021
4082
|
minimumWidth = context.getPageSize().width * 2;
|
|
4022
4083
|
}
|
|
@@ -4042,9 +4103,9 @@
|
|
|
4042
4103
|
const { width, height } = item.layout({
|
|
4043
4104
|
minimumWidth,
|
|
4044
4105
|
blankPagePosition,
|
|
4045
|
-
spreadPosition: context.
|
|
4106
|
+
spreadPosition: context.isUsingSpreadMode() ? itemStartOnNewScreen ? context.isRTL() ? `right` : `left` : context.isRTL() ? `left` : `right` : `none`
|
|
4046
4107
|
});
|
|
4047
|
-
if (
|
|
4108
|
+
if (settings.getSettings().computedPageTurnDirection === `vertical`) {
|
|
4048
4109
|
const currentValidEdgeYForVerticalPositioning = itemStartOnNewScreen ? verticalOffset : verticalOffset - context.getVisibleAreaRect().height;
|
|
4049
4110
|
const currentValidEdgeXForVerticalPositioning = itemStartOnNewScreen ? 0 : horizontalOffset;
|
|
4050
4111
|
if (context.isRTL()) {
|
|
@@ -4112,9 +4173,9 @@
|
|
|
4112
4173
|
const loadContents = Report.measurePerformance(`loadContents`, 10, (rangeOfIndex) => {
|
|
4113
4174
|
var _a;
|
|
4114
4175
|
const [leftIndex, rightIndex] = rangeOfIndex;
|
|
4115
|
-
const numberOfAdjacentSpineItemToPreLoad =
|
|
4176
|
+
const numberOfAdjacentSpineItemToPreLoad = settings.getSettings().numberOfAdjacentSpineItemToPreLoad;
|
|
4116
4177
|
const isPrePaginated = ((_a = context.getManifest()) == null ? void 0 : _a.renditionLayout) === `pre-paginated`;
|
|
4117
|
-
const isUsingFreeScroll =
|
|
4178
|
+
const isUsingFreeScroll = settings.getSettings().computedPageTurnMode === `scrollable`;
|
|
4118
4179
|
orderedSpineItemsSubject$.value.forEach((orderedSpineItem, index) => {
|
|
4119
4180
|
const isBeforeFocusedWithPreload = (
|
|
4120
4181
|
// we never want to preload anything before on free scroll on flow because it could offset the cursor
|
|
@@ -4168,7 +4229,9 @@
|
|
|
4168
4229
|
spineItem.$.loaded$.pipe(
|
|
4169
4230
|
operators.tap(() => {
|
|
4170
4231
|
if (spineItem.isUsingVerticalWriting()) {
|
|
4171
|
-
context.setHasVerticalWriting();
|
|
4232
|
+
context.setHasVerticalWriting(true);
|
|
4233
|
+
} else {
|
|
4234
|
+
context.setHasVerticalWriting(false);
|
|
4172
4235
|
}
|
|
4173
4236
|
}),
|
|
4174
4237
|
operators.takeUntil(context.$.destroy$)
|
|
@@ -4409,9 +4472,10 @@
|
|
|
4409
4472
|
context,
|
|
4410
4473
|
spineItemManager,
|
|
4411
4474
|
cfiLocator,
|
|
4412
|
-
locator
|
|
4475
|
+
locator,
|
|
4476
|
+
settings
|
|
4413
4477
|
}) => {
|
|
4414
|
-
const spineItemNavigator = createNavigationResolver$1({ context });
|
|
4478
|
+
const spineItemNavigator = createNavigationResolver$1({ context, settings });
|
|
4415
4479
|
const arePositionsDifferent = (a, b) => a.x !== b.x || a.y !== b.y;
|
|
4416
4480
|
const areNavigationDifferent = (a, b) => arePositionsDifferent(a, b) || !!a.spineItem && !!b.spineItem && a.spineItem !== b.spineItem;
|
|
4417
4481
|
const wrapPositionWithSafeEdge = Report.measurePerformance(
|
|
@@ -4476,7 +4540,7 @@
|
|
|
4476
4540
|
return { x: 0, y: 0 };
|
|
4477
4541
|
};
|
|
4478
4542
|
const getNavigationForRightSinglePage = (position) => {
|
|
4479
|
-
const pageTurnDirection =
|
|
4543
|
+
const pageTurnDirection = settings.getSettings().computedPageTurnDirection;
|
|
4480
4544
|
const spineItem = locator.getSpineItemFromPosition(position) || spineItemManager.getFocusedSpineItem();
|
|
4481
4545
|
const defaultNavigation = position;
|
|
4482
4546
|
if (!spineItem) {
|
|
@@ -4495,7 +4559,7 @@
|
|
|
4495
4559
|
}
|
|
4496
4560
|
};
|
|
4497
4561
|
const getNavigationForLeftSinglePage = (position) => {
|
|
4498
|
-
const pageTurnDirection =
|
|
4562
|
+
const pageTurnDirection = settings.getSettings().computedPageTurnDirection;
|
|
4499
4563
|
const spineItem = locator.getSpineItemFromPosition(position) || spineItemManager.getFocusedSpineItem();
|
|
4500
4564
|
const defaultNavigation = { ...position, spineItem };
|
|
4501
4565
|
if (!spineItem) {
|
|
@@ -4519,7 +4583,7 @@
|
|
|
4519
4583
|
if ((spineItemOnPosition == null ? void 0 : spineItemOnPosition.isUsingVerticalWriting()) && position.x === navigation.x) {
|
|
4520
4584
|
return getAdjustedPositionForSpread(navigation);
|
|
4521
4585
|
}
|
|
4522
|
-
if (context.
|
|
4586
|
+
if (context.isUsingSpreadMode()) {
|
|
4523
4587
|
if ((spineItemOnPosition == null ? void 0 : spineItemOnPosition.isUsingVerticalWriting()) && position.x !== navigation.x) {
|
|
4524
4588
|
return getAdjustedPositionForSpread(
|
|
4525
4589
|
wrapPositionWithSafeEdge(
|
|
@@ -4533,7 +4597,7 @@
|
|
|
4533
4597
|
)
|
|
4534
4598
|
);
|
|
4535
4599
|
}
|
|
4536
|
-
if (
|
|
4600
|
+
if (settings.getSettings().computedPageTurnDirection === `vertical` && position.y !== navigation.y) {
|
|
4537
4601
|
return getAdjustedPositionForSpread(navigation);
|
|
4538
4602
|
}
|
|
4539
4603
|
const doubleNavigation = getNavigationForRightSinglePage(navigation);
|
|
@@ -4547,7 +4611,7 @@
|
|
|
4547
4611
|
if ((spineItemOnPosition == null ? void 0 : spineItemOnPosition.isUsingVerticalWriting()) && position.x === navigation.x) {
|
|
4548
4612
|
return getAdjustedPositionForSpread(navigation);
|
|
4549
4613
|
}
|
|
4550
|
-
if (context.
|
|
4614
|
+
if (context.isUsingSpreadMode()) {
|
|
4551
4615
|
if ((spineItemOnPosition == null ? void 0 : spineItemOnPosition.isUsingVerticalWriting()) && position.x !== navigation.x) {
|
|
4552
4616
|
return getAdjustedPositionForSpread(
|
|
4553
4617
|
wrapPositionWithSafeEdge(
|
|
@@ -4555,7 +4619,7 @@
|
|
|
4555
4619
|
)
|
|
4556
4620
|
);
|
|
4557
4621
|
}
|
|
4558
|
-
if (
|
|
4622
|
+
if (settings.getSettings().computedPageTurnDirection === `vertical` && position.y !== navigation.y) {
|
|
4559
4623
|
return getAdjustedPositionForSpread(navigation);
|
|
4560
4624
|
}
|
|
4561
4625
|
const doubleNavigation = getNavigationForLeftSinglePage(navigation);
|
|
@@ -4597,7 +4661,7 @@
|
|
|
4597
4661
|
return { x: 0, y: 0 };
|
|
4598
4662
|
};
|
|
4599
4663
|
const getMostPredominantNavigationForPosition = (viewportPosition) => {
|
|
4600
|
-
const pageTurnDirection =
|
|
4664
|
+
const pageTurnDirection = settings.getSettings().computedPageTurnDirection;
|
|
4601
4665
|
const triggerPercentage = 0.5;
|
|
4602
4666
|
const triggerXPosition = pageTurnDirection === `horizontal` ? viewportPosition.x + context.getVisibleAreaRect().width * triggerPercentage : 0;
|
|
4603
4667
|
const triggerYPosition = pageTurnDirection === `horizontal` ? 0 : viewportPosition.y + context.getVisibleAreaRect().height * triggerPercentage;
|
|
@@ -4605,7 +4669,7 @@
|
|
|
4605
4669
|
return getNavigationForPosition(midScreenPositionSafePosition);
|
|
4606
4670
|
};
|
|
4607
4671
|
const isNavigationGoingForwardFrom = (to, from) => {
|
|
4608
|
-
const pageTurnDirection =
|
|
4672
|
+
const pageTurnDirection = settings.getSettings().computedPageTurnDirection;
|
|
4609
4673
|
if (pageTurnDirection === `vertical`) {
|
|
4610
4674
|
return to.y > from.y;
|
|
4611
4675
|
}
|
|
@@ -4631,9 +4695,10 @@
|
|
|
4631
4695
|
const SCROLL_FINISHED_DEBOUNCE_TIMEOUT = 200;
|
|
4632
4696
|
const createScrollViewportNavigator = ({
|
|
4633
4697
|
context,
|
|
4634
|
-
element
|
|
4698
|
+
element$,
|
|
4635
4699
|
navigator: navigator2,
|
|
4636
4700
|
currentNavigationSubject$,
|
|
4701
|
+
settings,
|
|
4637
4702
|
spine
|
|
4638
4703
|
}) => {
|
|
4639
4704
|
let lastScrollWasProgrammaticallyTriggered = false;
|
|
@@ -4647,38 +4712,44 @@
|
|
|
4647
4712
|
})
|
|
4648
4713
|
);
|
|
4649
4714
|
const adjustReadingOffset = ({ x, y }) => {
|
|
4650
|
-
|
|
4715
|
+
var _a;
|
|
4716
|
+
if (settings.getSettings().computedPageTurnMode === `scrollable`) {
|
|
4651
4717
|
lastScrollWasProgrammaticallyTriggered = true;
|
|
4652
|
-
element.scrollTo({ left: x, top: y });
|
|
4718
|
+
(_a = element$.getValue()) == null ? void 0 : _a.scrollTo({ left: x, top: y });
|
|
4653
4719
|
return true;
|
|
4654
4720
|
}
|
|
4655
4721
|
return false;
|
|
4656
4722
|
};
|
|
4657
|
-
const runOnFreePageTurnModeOnly$ = (source) =>
|
|
4658
|
-
operators.map(() =>
|
|
4723
|
+
const runOnFreePageTurnModeOnly$ = (source) => settings.$.settings$.pipe(
|
|
4724
|
+
operators.map(({ computedPageTurnMode }) => computedPageTurnMode),
|
|
4659
4725
|
operators.distinctUntilChanged(),
|
|
4660
4726
|
operators.switchMap((mode) => rxjs.iif(() => mode === `controlled`, rxjs.EMPTY, source))
|
|
4661
4727
|
);
|
|
4662
|
-
const userScroll$ = runOnFreePageTurnModeOnly$(
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4728
|
+
const userScroll$ = runOnFreePageTurnModeOnly$(
|
|
4729
|
+
element$.pipe(
|
|
4730
|
+
operators.filter(isDefined),
|
|
4731
|
+
operators.switchMap((element) => rxjs.fromEvent(element, `scroll`))
|
|
4732
|
+
)
|
|
4733
|
+
).pipe(onlyUserScrollFilter, operators.share(), operators.takeUntil(context.$.destroy$));
|
|
4667
4734
|
const getScaledDownPosition = ({ x, y }) => {
|
|
4668
|
-
|
|
4735
|
+
var _a, _b;
|
|
4736
|
+
const spineElement = spine.getElement();
|
|
4737
|
+
if (!spineElement)
|
|
4738
|
+
throw new Error("Invalid spine element");
|
|
4739
|
+
const spineScaleX = spineElement.getBoundingClientRect().width / spineElement.offsetWidth;
|
|
4669
4740
|
const scaledDownPosition = {
|
|
4670
4741
|
x: getNewScaledOffset({
|
|
4671
4742
|
newScale: 1,
|
|
4672
4743
|
oldScale: spineScaleX,
|
|
4673
|
-
screenSize: element.clientWidth,
|
|
4674
|
-
pageSize:
|
|
4744
|
+
screenSize: ((_a = element$.getValue()) == null ? void 0 : _a.clientWidth) ?? 0,
|
|
4745
|
+
pageSize: spineElement.scrollWidth,
|
|
4675
4746
|
scrollOffset: x
|
|
4676
4747
|
}),
|
|
4677
4748
|
y: getNewScaledOffset({
|
|
4678
4749
|
newScale: 1,
|
|
4679
4750
|
oldScale: spineScaleX,
|
|
4680
|
-
screenSize: element.clientHeight,
|
|
4681
|
-
pageSize:
|
|
4751
|
+
screenSize: ((_b = element$.getValue()) == null ? void 0 : _b.clientHeight) ?? 0,
|
|
4752
|
+
pageSize: spineElement.scrollHeight,
|
|
4682
4753
|
scrollOffset: y
|
|
4683
4754
|
})
|
|
4684
4755
|
};
|
|
@@ -4689,13 +4760,17 @@
|
|
|
4689
4760
|
return navigation;
|
|
4690
4761
|
};
|
|
4691
4762
|
const getCurrentViewportPosition = () => {
|
|
4692
|
-
|
|
4763
|
+
var _a, _b;
|
|
4764
|
+
return getScaledDownPosition({ x: ((_a = element$.getValue()) == null ? void 0 : _a.scrollLeft) ?? 0, y: ((_b = element$.getValue()) == null ? void 0 : _b.scrollTop) ?? 0 });
|
|
4693
4765
|
};
|
|
4694
4766
|
const navigationOnScroll$ = userScroll$.pipe(
|
|
4695
4767
|
operators.debounceTime(SCROLL_FINISHED_DEBOUNCE_TIMEOUT, rxjs.animationFrameScheduler),
|
|
4696
4768
|
operators.withLatestFrom(currentNavigationSubject$),
|
|
4697
4769
|
operators.switchMap(() => {
|
|
4698
|
-
|
|
4770
|
+
var _a, _b;
|
|
4771
|
+
const navigation = getNavigationForPosition(
|
|
4772
|
+
getScaledDownPosition({ x: ((_a = element$.getValue()) == null ? void 0 : _a.scrollLeft) ?? 0, y: ((_b = element$.getValue()) == null ? void 0 : _b.scrollTop) ?? 0 })
|
|
4773
|
+
);
|
|
4699
4774
|
return rxjs.of({ position: navigation, animate: false, lastUserExpectedNavigation: void 0 });
|
|
4700
4775
|
}),
|
|
4701
4776
|
operators.share()
|
|
@@ -4918,7 +4993,8 @@
|
|
|
4918
4993
|
spineItemManager,
|
|
4919
4994
|
locator,
|
|
4920
4995
|
context,
|
|
4921
|
-
currentNavigationSubject
|
|
4996
|
+
currentNavigationSubject$,
|
|
4997
|
+
settings
|
|
4922
4998
|
}) => {
|
|
4923
4999
|
const navigationTriggerSubject$ = new rxjs.Subject();
|
|
4924
5000
|
const stateSubject$ = new rxjs.BehaviorSubject(`end`);
|
|
@@ -4929,11 +5005,11 @@
|
|
|
4929
5005
|
`${NAMESPACE$1} moveTo`,
|
|
4930
5006
|
5,
|
|
4931
5007
|
(delta, { final, start } = {}) => {
|
|
4932
|
-
if (
|
|
5008
|
+
if (settings.getSettings().computedPageTurnMode === `scrollable`) {
|
|
4933
5009
|
Report.warn(`pan control is not available on free page turn mode`);
|
|
4934
5010
|
return;
|
|
4935
5011
|
}
|
|
4936
|
-
const pageTurnDirection =
|
|
5012
|
+
const pageTurnDirection = settings.getSettings().computedPageTurnDirection;
|
|
4937
5013
|
if (start) {
|
|
4938
5014
|
stateSubject$.next(`start`);
|
|
4939
5015
|
movingLastDelta = { x: 0, y: 0 };
|
|
@@ -4993,7 +5069,7 @@
|
|
|
4993
5069
|
);
|
|
4994
5070
|
const snapNavigation$ = navigationTriggerSubject$.pipe(
|
|
4995
5071
|
operators.filter((e) => e.type === `snap`),
|
|
4996
|
-
rxjs.withLatestFrom(
|
|
5072
|
+
rxjs.withLatestFrom(settings.$.settings$),
|
|
4997
5073
|
operators.switchMap(
|
|
4998
5074
|
([
|
|
4999
5075
|
{
|
|
@@ -5001,7 +5077,7 @@
|
|
|
5001
5077
|
},
|
|
5002
5078
|
{ navigationSnapThreshold }
|
|
5003
5079
|
]) => {
|
|
5004
|
-
const pageTurnDirection =
|
|
5080
|
+
const pageTurnDirection = settings.getSettings().computedPageTurnDirection;
|
|
5005
5081
|
const movingForward = navigator2.isNavigationGoingForwardFrom(to, from);
|
|
5006
5082
|
const triggerPercentage = movingForward ? 1 - navigationSnapThreshold : navigationSnapThreshold;
|
|
5007
5083
|
const triggerXPosition = pageTurnDirection === `horizontal` ? to.x + context.getVisibleAreaRect().width * triggerPercentage : 0;
|
|
@@ -5034,18 +5110,19 @@
|
|
|
5034
5110
|
};
|
|
5035
5111
|
};
|
|
5036
5112
|
const NAMESPACE = `viewportNavigator`;
|
|
5113
|
+
const noopElement = document.createElement("div");
|
|
5037
5114
|
const createViewportNavigator = ({
|
|
5038
5115
|
spineItemManager,
|
|
5039
5116
|
context,
|
|
5040
5117
|
pagination,
|
|
5041
|
-
parentElement
|
|
5118
|
+
parentElement$,
|
|
5042
5119
|
cfiLocator,
|
|
5043
5120
|
spineLocator,
|
|
5044
5121
|
hooks$,
|
|
5045
|
-
spine
|
|
5122
|
+
spine,
|
|
5123
|
+
settings
|
|
5046
5124
|
}) => {
|
|
5047
|
-
const element =
|
|
5048
|
-
element.appendChild(spine.element);
|
|
5125
|
+
const element$ = new rxjs.BehaviorSubject(noopElement);
|
|
5049
5126
|
const layoutSubject$ = new rxjs.Subject();
|
|
5050
5127
|
let currentViewportPositionMemoUnused;
|
|
5051
5128
|
const currentNavigationPositionSubject$ = new rxjs.BehaviorSubject({
|
|
@@ -5055,17 +5132,18 @@
|
|
|
5055
5132
|
});
|
|
5056
5133
|
const navigator2 = createNavigationResolver({
|
|
5057
5134
|
context,
|
|
5135
|
+
settings,
|
|
5058
5136
|
spineItemManager,
|
|
5059
5137
|
cfiLocator,
|
|
5060
5138
|
locator: spineLocator
|
|
5061
5139
|
});
|
|
5062
5140
|
const adjustNavigationSubject$ = new rxjs.Subject();
|
|
5063
|
-
parentElement.appendChild(element);
|
|
5064
5141
|
const getCurrentViewportPosition = Report.measurePerformance(`${NAMESPACE} getCurrentViewportPosition`, 1, () => {
|
|
5065
|
-
|
|
5142
|
+
var _a;
|
|
5143
|
+
if (settings.getSettings().computedPageTurnMode === `scrollable`) {
|
|
5066
5144
|
return scrollViewportNavigator.getCurrentViewportPosition();
|
|
5067
5145
|
}
|
|
5068
|
-
const { x, y } = element.getBoundingClientRect();
|
|
5146
|
+
const { x, y } = ((_a = element$.getValue()) == null ? void 0 : _a.getBoundingClientRect()) ?? { x: 0, y: 0 };
|
|
5069
5147
|
const newValue = {
|
|
5070
5148
|
// we want to round to first decimal because it's possible to have half pixel
|
|
5071
5149
|
// however browser engine can also gives back x.yyyy based on their precision
|
|
@@ -5079,7 +5157,7 @@
|
|
|
5079
5157
|
});
|
|
5080
5158
|
const panViewportNavigator = createPanViewportNavigator({
|
|
5081
5159
|
context,
|
|
5082
|
-
|
|
5160
|
+
settings,
|
|
5083
5161
|
navigator: navigator2,
|
|
5084
5162
|
spineItemManager,
|
|
5085
5163
|
locator: spineLocator,
|
|
@@ -5088,15 +5166,15 @@
|
|
|
5088
5166
|
});
|
|
5089
5167
|
const scrollViewportNavigator = createScrollViewportNavigator({
|
|
5090
5168
|
context,
|
|
5091
|
-
element
|
|
5169
|
+
element$,
|
|
5092
5170
|
navigator: navigator2,
|
|
5093
5171
|
currentNavigationSubject$: currentNavigationPositionSubject$,
|
|
5094
5172
|
spine,
|
|
5095
|
-
spineItemManager
|
|
5173
|
+
spineItemManager,
|
|
5174
|
+
settings
|
|
5096
5175
|
});
|
|
5097
5176
|
const manualViewportNavigator = createManualViewportNavigator({
|
|
5098
5177
|
context,
|
|
5099
|
-
element,
|
|
5100
5178
|
navigator: navigator2,
|
|
5101
5179
|
currentNavigationSubject$: currentNavigationPositionSubject$,
|
|
5102
5180
|
spineItemManager,
|
|
@@ -5113,6 +5191,9 @@
|
|
|
5113
5191
|
`adjustReadingOffset`,
|
|
5114
5192
|
2,
|
|
5115
5193
|
({ x, y }, hooks) => {
|
|
5194
|
+
const element = element$.getValue();
|
|
5195
|
+
if (!element)
|
|
5196
|
+
throw new Error("Invalid element");
|
|
5116
5197
|
currentViewportPositionMemoUnused = void 0;
|
|
5117
5198
|
const isAdjusted = viewportNavigators.reduce((isAdjusted2, navigator22) => {
|
|
5118
5199
|
return navigator22.adjustReadingOffset({ x, y }) || isAdjusted2;
|
|
@@ -5129,10 +5210,10 @@
|
|
|
5129
5210
|
{ disable: true }
|
|
5130
5211
|
);
|
|
5131
5212
|
const adjustNavigation = (spineItem) => {
|
|
5132
|
-
const lastCfi = pagination.
|
|
5213
|
+
const lastCfi = pagination.getPaginationInfo().beginCfi;
|
|
5133
5214
|
let adjustedSpinePosition = currentNavigationPositionSubject$.value;
|
|
5134
5215
|
const offsetInSpineItem = 0;
|
|
5135
|
-
if (
|
|
5216
|
+
if (settings.getSettings().computedPageTurnMode === `scrollable`) {
|
|
5136
5217
|
adjustedSpinePosition = scrollViewportNavigator.getNavigationForPosition(getCurrentViewportPosition());
|
|
5137
5218
|
} else if ((lastUserExpectedNavigation == null ? void 0 : lastUserExpectedNavigation.type) === `navigate-from-cfi`) {
|
|
5138
5219
|
adjustedSpinePosition = navigator2.getNavigationForCfi(lastUserExpectedNavigation.data);
|
|
@@ -5150,7 +5231,7 @@
|
|
|
5150
5231
|
adjustedSpinePosition = navigator2.getNavigationForCfi(lastCfi);
|
|
5151
5232
|
Report.log(NAMESPACE, `adjustNavigation`, `use last cfi`);
|
|
5152
5233
|
} else {
|
|
5153
|
-
const currentPageIndex = pagination.
|
|
5234
|
+
const currentPageIndex = pagination.getPaginationInfo().beginPageIndexInSpineItem || 0;
|
|
5154
5235
|
adjustedSpinePosition = navigator2.getNavigationForPage(currentPageIndex, spineItem);
|
|
5155
5236
|
Report.log(NAMESPACE, `adjustNavigation`, `use guess strategy`, {});
|
|
5156
5237
|
}
|
|
@@ -5177,14 +5258,15 @@
|
|
|
5177
5258
|
layoutSubject$.subscribe(() => {
|
|
5178
5259
|
currentViewportPositionMemoUnused = void 0;
|
|
5179
5260
|
});
|
|
5180
|
-
const layoutChangeSettings$ =
|
|
5261
|
+
const layoutChangeSettings$ = settings.$.settings$.pipe(
|
|
5181
5262
|
mapKeysTo([`computedPageTurnDirection`, `computedPageTurnMode`, `numberOfAdjacentSpineItemToPreLoad`]),
|
|
5182
5263
|
operators.distinctUntilChanged(isShallowEqual),
|
|
5183
5264
|
operators.skip(1)
|
|
5184
5265
|
);
|
|
5185
5266
|
const layout$ = rxjs.merge(layoutSubject$, layoutChangeSettings$).pipe(
|
|
5186
|
-
operators.
|
|
5187
|
-
|
|
5267
|
+
operators.withLatestFrom(element$),
|
|
5268
|
+
operators.tap(([, element]) => {
|
|
5269
|
+
if (settings.getSettings().computedPageTurnMode === `scrollable`) {
|
|
5188
5270
|
element.style.removeProperty(`transform`);
|
|
5189
5271
|
element.style.removeProperty(`transition`);
|
|
5190
5272
|
element.style.overflow = `scroll`;
|
|
@@ -5240,7 +5322,7 @@
|
|
|
5240
5322
|
);
|
|
5241
5323
|
const navigationWhichRequireManualAdjust$ = navigation$.pipe(
|
|
5242
5324
|
operators.filter(({ triggeredBy }) => {
|
|
5243
|
-
if (triggeredBy === `scroll` ||
|
|
5325
|
+
if (triggeredBy === `scroll` || settings.getSettings().computedPageTurnMode === `scrollable` && triggeredBy === `adjust`) {
|
|
5244
5326
|
return false;
|
|
5245
5327
|
} else {
|
|
5246
5328
|
return true;
|
|
@@ -5252,7 +5334,7 @@
|
|
|
5252
5334
|
navigationWhichRequireManualAdjust$
|
|
5253
5335
|
).pipe(
|
|
5254
5336
|
operators.map(({ animation, position }) => {
|
|
5255
|
-
const shouldAnimate = !(!animation || animation === `turn` &&
|
|
5337
|
+
const shouldAnimate = !(!animation || animation === `turn` && settings.getSettings().computedPageTurnAnimation === `none`);
|
|
5256
5338
|
return {
|
|
5257
5339
|
type: `manualAdjust`,
|
|
5258
5340
|
shouldAnimate,
|
|
@@ -5267,15 +5349,15 @@
|
|
|
5267
5349
|
operators.pairwise(),
|
|
5268
5350
|
operators.tap(([prevEvent, currentEvent]) => {
|
|
5269
5351
|
if ((prevEvent == null ? void 0 : prevEvent.type) === `manualAdjust` && (currentEvent == null ? void 0 : currentEvent.type) !== `manualAdjust`) {
|
|
5270
|
-
element.style.setProperty(`transition`, `none`);
|
|
5271
|
-
element.style.setProperty(`opacity`, `1`);
|
|
5352
|
+
element$.getValue().style.setProperty(`transition`, `none`);
|
|
5353
|
+
element$.getValue().style.setProperty(`opacity`, `1`);
|
|
5272
5354
|
}
|
|
5273
5355
|
}),
|
|
5274
5356
|
operators.switchMap(([, currentEvent]) => {
|
|
5275
5357
|
if ((currentEvent == null ? void 0 : currentEvent.type) !== `manualAdjust`)
|
|
5276
5358
|
return rxjs.EMPTY;
|
|
5277
|
-
const animationDuration = currentEvent.animation === `snap` ?
|
|
5278
|
-
const pageTurnAnimation = currentEvent.animation === `snap` ? `slide` :
|
|
5359
|
+
const animationDuration = currentEvent.animation === `snap` ? settings.getSettings().computedSnapAnimationDuration : settings.getSettings().computedPageTurnAnimationDuration;
|
|
5360
|
+
const pageTurnAnimation = currentEvent.animation === `snap` ? `slide` : settings.getSettings().computedPageTurnAnimation;
|
|
5279
5361
|
return rxjs.of(currentEvent).pipe(
|
|
5280
5362
|
/**
|
|
5281
5363
|
* @important
|
|
@@ -5290,15 +5372,15 @@
|
|
|
5290
5372
|
const noAdjustmentNeeded = false;
|
|
5291
5373
|
if (data.shouldAnimate && !noAdjustmentNeeded) {
|
|
5292
5374
|
if (pageTurnAnimation === `fade`) {
|
|
5293
|
-
element.style.setProperty(`transition`, `opacity ${animationDuration / 2}ms`);
|
|
5294
|
-
element.style.setProperty(`opacity`, `0`);
|
|
5375
|
+
element$.getValue().style.setProperty(`transition`, `opacity ${animationDuration / 2}ms`);
|
|
5376
|
+
element$.getValue().style.setProperty(`opacity`, `0`);
|
|
5295
5377
|
} else if (currentEvent.animation === `snap` || pageTurnAnimation === `slide`) {
|
|
5296
|
-
element.style.setProperty(`transition`, `transform ${animationDuration}ms`);
|
|
5297
|
-
element.style.setProperty(`opacity`, `1`);
|
|
5378
|
+
element$.getValue().style.setProperty(`transition`, `transform ${animationDuration}ms`);
|
|
5379
|
+
element$.getValue().style.setProperty(`opacity`, `1`);
|
|
5298
5380
|
}
|
|
5299
5381
|
} else {
|
|
5300
|
-
element.style.setProperty(`transition`, `none`);
|
|
5301
|
-
element.style.setProperty(`opacity`, `1`);
|
|
5382
|
+
element$.getValue().style.setProperty(`transition`, `none`);
|
|
5383
|
+
element$.getValue().style.setProperty(`opacity`, `1`);
|
|
5302
5384
|
}
|
|
5303
5385
|
}),
|
|
5304
5386
|
/**
|
|
@@ -5319,7 +5401,7 @@
|
|
|
5319
5401
|
operators.tap(([data, hooks]) => {
|
|
5320
5402
|
if (pageTurnAnimation === `fade`) {
|
|
5321
5403
|
adjustReadingOffset(data.position, hooks);
|
|
5322
|
-
element.style.setProperty(`opacity`, `1`);
|
|
5404
|
+
element$.getValue().style.setProperty(`opacity`, `1`);
|
|
5323
5405
|
}
|
|
5324
5406
|
}),
|
|
5325
5407
|
currentEvent.shouldAnimate ? operators.delay(animationDuration / 2, rxjs.animationFrameScheduler) : rxjs.identity,
|
|
@@ -5391,10 +5473,17 @@
|
|
|
5391
5473
|
),
|
|
5392
5474
|
operators.share()
|
|
5393
5475
|
);
|
|
5476
|
+
const parentElementSub = parentElement$.pipe(operators.filter(isDefined), operators.withLatestFrom(spine.element$)).subscribe(([parentElement, spineElement]) => {
|
|
5477
|
+
const element = createElement(parentElement.ownerDocument, hooks$);
|
|
5478
|
+
element.appendChild(spineElement);
|
|
5479
|
+
parentElement.appendChild(element);
|
|
5480
|
+
element$.next(element);
|
|
5481
|
+
});
|
|
5394
5482
|
const destroy = () => {
|
|
5395
5483
|
layoutSubject$.complete();
|
|
5396
5484
|
adjustNavigationSubject$.complete();
|
|
5397
5485
|
currentNavigationPositionSubject$.complete();
|
|
5486
|
+
parentElementSub.unsubscribe();
|
|
5398
5487
|
viewportNavigators.forEach((navigator22) => navigator22.destroy());
|
|
5399
5488
|
};
|
|
5400
5489
|
return {
|
|
@@ -5411,7 +5500,8 @@
|
|
|
5411
5500
|
goToPageOfCurrentChapter: manualViewportNavigator.goToPageOfCurrentChapter,
|
|
5412
5501
|
moveTo: panViewportNavigator.moveTo,
|
|
5413
5502
|
getLastUserExpectedNavigation: () => lastUserExpectedNavigation,
|
|
5414
|
-
element
|
|
5503
|
+
element$,
|
|
5504
|
+
getElement: () => element$.getValue(),
|
|
5415
5505
|
$: {
|
|
5416
5506
|
state$,
|
|
5417
5507
|
navigation$,
|
|
@@ -5437,7 +5527,8 @@
|
|
|
5437
5527
|
const createLocationResolver = ({
|
|
5438
5528
|
spineItemManager,
|
|
5439
5529
|
context,
|
|
5440
|
-
spineItemLocator
|
|
5530
|
+
spineItemLocator,
|
|
5531
|
+
settings
|
|
5441
5532
|
}) => {
|
|
5442
5533
|
const getSpineItemPositionFromSpinePosition = Report.measurePerformance(
|
|
5443
5534
|
`getSpineItemPositionFromSpinePosition`,
|
|
@@ -5472,7 +5563,7 @@
|
|
|
5472
5563
|
const spineItem = spineItemManager.getAll().find((item) => {
|
|
5473
5564
|
const { left, right, bottom, top } = spineItemManager.getAbsolutePositionOf(item);
|
|
5474
5565
|
const isWithinXAxis = position.x >= left && position.x < right;
|
|
5475
|
-
if (
|
|
5566
|
+
if (settings.getSettings().computedPageTurnDirection === `horizontal`) {
|
|
5476
5567
|
return isWithinXAxis;
|
|
5477
5568
|
} else {
|
|
5478
5569
|
return isWithinXAxis && position.y >= top && position.y < bottom;
|
|
@@ -5499,7 +5590,7 @@
|
|
|
5499
5590
|
if (itemAtPositionIndex === void 0)
|
|
5500
5591
|
return void 0;
|
|
5501
5592
|
let endPosition = position;
|
|
5502
|
-
if (context.
|
|
5593
|
+
if (context.isUsingSpreadMode()) {
|
|
5503
5594
|
endPosition = { x: position.x + context.getPageSize().width, y: position.y };
|
|
5504
5595
|
}
|
|
5505
5596
|
const endItemIndex = spineItemManager.getSpineItemIndex(getSpineItemFromPosition(endPosition) || spineItemManager.getFocusedSpineItem()) ?? itemAtPositionIndex;
|
|
@@ -5620,15 +5711,86 @@
|
|
|
5620
5711
|
generateFromRange
|
|
5621
5712
|
};
|
|
5622
5713
|
};
|
|
5714
|
+
const areAllItemsPrePaginated = (manifest) => !(manifest == null ? void 0 : manifest.spineItems.some((item) => item.renditionLayout === `reflowable`));
|
|
5715
|
+
const createSettings = (initialSettings) => {
|
|
5716
|
+
const mergedSettings = {
|
|
5717
|
+
forceSinglePageMode: false,
|
|
5718
|
+
pageTurnAnimation: `none`,
|
|
5719
|
+
computedPageTurnAnimation: `none`,
|
|
5720
|
+
pageTurnDirection: `horizontal`,
|
|
5721
|
+
computedPageTurnDirection: `horizontal`,
|
|
5722
|
+
pageTurnAnimationDuration: void 0,
|
|
5723
|
+
computedPageTurnAnimationDuration: 0,
|
|
5724
|
+
pageTurnMode: `controlled`,
|
|
5725
|
+
computedPageTurnMode: `controlled`,
|
|
5726
|
+
computedSnapAnimationDuration: 300,
|
|
5727
|
+
navigationSnapThreshold: 0.3,
|
|
5728
|
+
numberOfAdjacentSpineItemToPreLoad: 0,
|
|
5729
|
+
...initialSettings
|
|
5730
|
+
};
|
|
5731
|
+
updateComputedSettings(void 0, mergedSettings, false);
|
|
5732
|
+
const settingsSubject$ = new rxjs.BehaviorSubject(mergedSettings);
|
|
5733
|
+
const setSettings = (newSettings, options) => {
|
|
5734
|
+
if (Object.keys(newSettings).length === 0)
|
|
5735
|
+
return;
|
|
5736
|
+
const newMergedSettings = { ...settingsSubject$.value, ...newSettings };
|
|
5737
|
+
updateComputedSettings(options.manifest, newMergedSettings, options.hasVerticalWriting ?? false);
|
|
5738
|
+
settingsSubject$.next(newMergedSettings);
|
|
5739
|
+
};
|
|
5740
|
+
const recompute = (options) => {
|
|
5741
|
+
const newMergedSettings = { ...settingsSubject$.value };
|
|
5742
|
+
updateComputedSettings(options.manifest, newMergedSettings, options.hasVerticalWriting ?? false);
|
|
5743
|
+
settingsSubject$.next(newMergedSettings);
|
|
5744
|
+
};
|
|
5745
|
+
const destroy = () => {
|
|
5746
|
+
settingsSubject$.complete();
|
|
5747
|
+
};
|
|
5748
|
+
return {
|
|
5749
|
+
getSettings: () => settingsSubject$.value,
|
|
5750
|
+
setSettings,
|
|
5751
|
+
recompute,
|
|
5752
|
+
destroy,
|
|
5753
|
+
$: {
|
|
5754
|
+
settings$: settingsSubject$.asObservable().pipe(operators.distinctUntilChanged(isShallowEqual))
|
|
5755
|
+
}
|
|
5756
|
+
};
|
|
5757
|
+
};
|
|
5758
|
+
const updateComputedSettings = (newManifest, settings, hasVerticalWriting) => {
|
|
5759
|
+
settings.computedPageTurnDirection = settings.pageTurnDirection;
|
|
5760
|
+
settings.computedPageTurnAnimation = settings.pageTurnAnimation;
|
|
5761
|
+
settings.computedPageTurnMode = `controlled`;
|
|
5762
|
+
if ((newManifest == null ? void 0 : newManifest.renditionFlow) === `scrolled-continuous`) {
|
|
5763
|
+
settings.computedPageTurnMode = `scrollable`;
|
|
5764
|
+
settings.computedPageTurnDirection = `vertical`;
|
|
5765
|
+
} else if (newManifest && settings.pageTurnMode === `scrollable` && (newManifest.renditionLayout !== `pre-paginated` || !areAllItemsPrePaginated(newManifest))) {
|
|
5766
|
+
Report.warn(`pageTurnMode ${settings.pageTurnMode} incompatible with current book, switching back to default`);
|
|
5767
|
+
settings.computedPageTurnAnimation = `none`;
|
|
5768
|
+
settings.computedPageTurnMode = `controlled`;
|
|
5769
|
+
} else if (settings.pageTurnMode === `scrollable`) {
|
|
5770
|
+
settings.computedPageTurnMode = `scrollable`;
|
|
5771
|
+
settings.computedPageTurnDirection = `vertical`;
|
|
5772
|
+
}
|
|
5773
|
+
if (hasVerticalWriting && settings.computedPageTurnAnimation === `slide`) {
|
|
5774
|
+
Report.warn(
|
|
5775
|
+
`pageTurnAnimation ${settings.computedPageTurnAnimation} incompatible with current book, switching back to default`
|
|
5776
|
+
);
|
|
5777
|
+
settings.computedPageTurnAnimation = `none`;
|
|
5778
|
+
}
|
|
5779
|
+
if (settings.computedPageTurnMode === `scrollable`) {
|
|
5780
|
+
settings.computedPageTurnAnimationDuration = 0;
|
|
5781
|
+
settings.computedPageTurnAnimation = `none`;
|
|
5782
|
+
} else {
|
|
5783
|
+
settings.computedPageTurnAnimationDuration = settings.pageTurnAnimationDuration !== void 0 ? settings.pageTurnAnimationDuration : 300;
|
|
5784
|
+
}
|
|
5785
|
+
};
|
|
5623
5786
|
const IFRAME_EVENT_BRIDGE_ELEMENT_ID = `proseReaderIframeEventBridgeElement`;
|
|
5624
|
-
const createReader = ({
|
|
5787
|
+
const createReader = ({ hooks: initialHooks, ...inputSettings }) => {
|
|
5625
5788
|
const stateSubject$ = new rxjs.BehaviorSubject({
|
|
5626
5789
|
supportedPageTurnAnimation: [`fade`, `none`, `slide`],
|
|
5627
5790
|
supportedPageTurnMode: [`controlled`, `scrollable`],
|
|
5628
5791
|
supportedPageTurnDirection: [`horizontal`, `vertical`],
|
|
5629
5792
|
supportedComputedPageTurnDirection: [`horizontal`, `vertical`]
|
|
5630
5793
|
});
|
|
5631
|
-
const readySubject$ = new rxjs.Subject();
|
|
5632
5794
|
const destroy$ = new rxjs.Subject();
|
|
5633
5795
|
const selectionSubject$ = new rxjs.Subject();
|
|
5634
5796
|
const hooksSubject$ = new rxjs.BehaviorSubject(initialHooks || []);
|
|
@@ -5636,16 +5798,19 @@
|
|
|
5636
5798
|
const navigationAdjustedSubject = new rxjs.Subject();
|
|
5637
5799
|
const currentNavigationPositionSubject$ = new rxjs.BehaviorSubject({ x: 0, y: 0 });
|
|
5638
5800
|
const viewportStateSubject = new rxjs.BehaviorSubject(`free`);
|
|
5801
|
+
const settings = createSettings(inputSettings);
|
|
5639
5802
|
const context = createContext(settings);
|
|
5640
|
-
const spineItemManager = createSpineItemManager({ context });
|
|
5803
|
+
const spineItemManager = createSpineItemManager({ context, settings });
|
|
5641
5804
|
const pagination = createPagination({ context, spineItemManager });
|
|
5642
|
-
const
|
|
5643
|
-
const
|
|
5805
|
+
const elementSubject$ = new rxjs.BehaviorSubject(void 0);
|
|
5806
|
+
const element$ = elementSubject$.pipe(operators.filter(isDefined));
|
|
5807
|
+
const iframeEventBridgeElement$ = new rxjs.BehaviorSubject(void 0);
|
|
5644
5808
|
const spineItemLocator = createLocationResolver$1({ context });
|
|
5645
5809
|
const spineLocator = createLocationResolver({
|
|
5646
5810
|
context,
|
|
5647
5811
|
spineItemManager,
|
|
5648
|
-
spineItemLocator
|
|
5812
|
+
spineItemLocator,
|
|
5813
|
+
settings
|
|
5649
5814
|
});
|
|
5650
5815
|
const cfiLocator = createCfiLocator({
|
|
5651
5816
|
spineItemManager,
|
|
@@ -5654,9 +5819,10 @@
|
|
|
5654
5819
|
});
|
|
5655
5820
|
const navigation$ = navigationSubject.asObservable();
|
|
5656
5821
|
const spine = createSpine({
|
|
5657
|
-
|
|
5658
|
-
iframeEventBridgeElement
|
|
5822
|
+
element$,
|
|
5823
|
+
iframeEventBridgeElement$,
|
|
5659
5824
|
context,
|
|
5825
|
+
settings,
|
|
5660
5826
|
pagination,
|
|
5661
5827
|
spineItemManager,
|
|
5662
5828
|
hooks$: hooksSubject$,
|
|
@@ -5672,22 +5838,26 @@
|
|
|
5672
5838
|
context,
|
|
5673
5839
|
pagination,
|
|
5674
5840
|
spineItemManager,
|
|
5675
|
-
parentElement
|
|
5841
|
+
parentElement$: elementSubject$,
|
|
5676
5842
|
cfiLocator,
|
|
5677
5843
|
spineLocator,
|
|
5678
5844
|
hooks$: hooksSubject$,
|
|
5679
|
-
spine
|
|
5845
|
+
spine,
|
|
5846
|
+
settings
|
|
5680
5847
|
});
|
|
5681
|
-
containerElement.appendChild(element);
|
|
5682
|
-
element.appendChild(iframeEventBridgeElement);
|
|
5683
5848
|
viewportNavigator.$.state$.subscribe(viewportStateSubject);
|
|
5684
5849
|
viewportNavigator.$.navigation$.subscribe(navigationSubject);
|
|
5685
5850
|
viewportNavigator.$.navigationAdjustedAfterLayout$.subscribe(navigationAdjustedSubject);
|
|
5686
5851
|
viewportNavigator.$.currentNavigationPosition$.subscribe(currentNavigationPositionSubject$);
|
|
5687
5852
|
const layout = () => {
|
|
5853
|
+
var _a;
|
|
5854
|
+
const containerElement = (_a = elementSubject$.getValue()) == null ? void 0 : _a.parentElement;
|
|
5855
|
+
const element = elementSubject$.getValue();
|
|
5856
|
+
if (!element || !containerElement)
|
|
5857
|
+
throw new Error("Invalid element");
|
|
5688
5858
|
const dimensions = {
|
|
5689
|
-
width: containerElement.offsetWidth,
|
|
5690
|
-
height: containerElement.offsetHeight
|
|
5859
|
+
width: containerElement == null ? void 0 : containerElement.offsetWidth,
|
|
5860
|
+
height: containerElement == null ? void 0 : containerElement.offsetHeight
|
|
5691
5861
|
};
|
|
5692
5862
|
const margin = 0;
|
|
5693
5863
|
const marginTop = 0;
|
|
@@ -5707,12 +5877,21 @@
|
|
|
5707
5877
|
});
|
|
5708
5878
|
viewportNavigator.layout();
|
|
5709
5879
|
};
|
|
5710
|
-
const load = (manifest, loadOptions
|
|
5880
|
+
const load = (manifest, loadOptions) => {
|
|
5881
|
+
var _a;
|
|
5711
5882
|
if (context.getManifest()) {
|
|
5712
5883
|
Report.warn(`loading a new book is not supported yet`);
|
|
5713
5884
|
return;
|
|
5714
5885
|
}
|
|
5715
5886
|
Report.log(`load`, { manifest, loadOptions });
|
|
5887
|
+
const element = createWrapperElement(loadOptions.containerElement);
|
|
5888
|
+
const iframeEventBridgeElement = createIframeEventBridgeElement(loadOptions.containerElement);
|
|
5889
|
+
if (loadOptions.containerElement !== ((_a = elementSubject$.getValue()) == null ? void 0 : _a.parentElement)) {
|
|
5890
|
+
elementSubject$.next(element);
|
|
5891
|
+
iframeEventBridgeElement$.next(iframeEventBridgeElement);
|
|
5892
|
+
loadOptions.containerElement.appendChild(element);
|
|
5893
|
+
element.appendChild(iframeEventBridgeElement);
|
|
5894
|
+
}
|
|
5716
5895
|
context.load(manifest, loadOptions);
|
|
5717
5896
|
layout();
|
|
5718
5897
|
if (!loadOptions.cfi) {
|
|
@@ -5720,14 +5899,10 @@
|
|
|
5720
5899
|
} else {
|
|
5721
5900
|
viewportNavigator.goToCfi(loadOptions.cfi, { animate: false });
|
|
5722
5901
|
}
|
|
5723
|
-
readySubject$.next();
|
|
5724
5902
|
};
|
|
5725
5903
|
const registerHook = (name, fn) => {
|
|
5726
5904
|
hooksSubject$.next([...hooksSubject$.getValue(), { name, fn }]);
|
|
5727
5905
|
};
|
|
5728
|
-
const manipulateContainer = (cb) => {
|
|
5729
|
-
cb(element);
|
|
5730
|
-
};
|
|
5731
5906
|
spine.$.$.pipe(
|
|
5732
5907
|
operators.tap((event) => {
|
|
5733
5908
|
if (event.type === `onSelectionChange`) {
|
|
@@ -5742,45 +5917,42 @@
|
|
|
5742
5917
|
}),
|
|
5743
5918
|
operators.takeUntil(context.$.destroy$)
|
|
5744
5919
|
).subscribe();
|
|
5745
|
-
rxjs.merge(context.$.
|
|
5746
|
-
operators.
|
|
5747
|
-
operators.withLatestFrom(context.$.
|
|
5748
|
-
operators.map(([, hasVerticalWriting]) => {
|
|
5749
|
-
const settings2 = context.getSettings();
|
|
5920
|
+
rxjs.merge(context.$.state$, settings.$.settings$).pipe(
|
|
5921
|
+
operators.map(() => void 0),
|
|
5922
|
+
operators.withLatestFrom(context.$.state$),
|
|
5923
|
+
operators.map(([, { hasVerticalWriting }]) => {
|
|
5750
5924
|
const manifest = context.getManifest();
|
|
5751
5925
|
return {
|
|
5752
5926
|
hasVerticalWriting,
|
|
5753
5927
|
renditionFlow: manifest == null ? void 0 : manifest.renditionFlow,
|
|
5754
5928
|
renditionLayout: manifest == null ? void 0 : manifest.renditionLayout,
|
|
5755
|
-
computedPageTurnMode:
|
|
5929
|
+
computedPageTurnMode: settings.getSettings().computedPageTurnMode
|
|
5756
5930
|
};
|
|
5757
5931
|
}),
|
|
5758
5932
|
operators.distinctUntilChanged(isShallowEqual),
|
|
5759
5933
|
operators.map(
|
|
5760
|
-
({
|
|
5761
|
-
|
|
5762
|
-
|
|
5763
|
-
|
|
5764
|
-
|
|
5765
|
-
|
|
5766
|
-
|
|
5767
|
-
|
|
5768
|
-
supportedPageTurnAnimation: renditionFlow === `scrolled-continuous` || computedPageTurnMode === `scrollable` ? [`none`] : hasVerticalWriting ? [`fade`, `none`] : [`fade`, `none`, `slide`],
|
|
5769
|
-
supportedPageTurnDirection: computedPageTurnMode === `scrollable` ? [`vertical`] : renditionLayout === `reflowable` ? [`horizontal`] : [`horizontal`, `vertical`]
|
|
5770
|
-
})
|
|
5934
|
+
({ hasVerticalWriting, renditionFlow, renditionLayout, computedPageTurnMode }) => {
|
|
5935
|
+
return {
|
|
5936
|
+
...stateSubject$.value,
|
|
5937
|
+
supportedPageTurnMode: renditionFlow === `scrolled-continuous` ? [`scrollable`] : !context.areAllItemsPrePaginated() ? [`controlled`] : [`controlled`, `scrollable`],
|
|
5938
|
+
supportedPageTurnAnimation: renditionFlow === `scrolled-continuous` || computedPageTurnMode === `scrollable` ? [`none`] : hasVerticalWriting ? [`fade`, `none`] : [`fade`, `none`, `slide`],
|
|
5939
|
+
supportedPageTurnDirection: computedPageTurnMode === `scrollable` ? [`vertical`] : renditionLayout === `reflowable` ? [`horizontal`] : [`horizontal`, `vertical`]
|
|
5940
|
+
};
|
|
5941
|
+
}
|
|
5771
5942
|
),
|
|
5772
5943
|
operators.takeUntil(destroy$)
|
|
5773
5944
|
).subscribe(stateSubject$);
|
|
5774
5945
|
const destroy = () => {
|
|
5946
|
+
var _a, _b;
|
|
5947
|
+
settings.destroy();
|
|
5775
5948
|
hooksSubject$.next([]);
|
|
5776
5949
|
hooksSubject$.complete();
|
|
5777
5950
|
pagination.destroy();
|
|
5778
5951
|
context.destroy();
|
|
5779
5952
|
viewportNavigator.destroy();
|
|
5780
5953
|
spine.destroy();
|
|
5781
|
-
|
|
5782
|
-
iframeEventBridgeElement.remove();
|
|
5783
|
-
readySubject$.complete();
|
|
5954
|
+
(_a = elementSubject$.getValue()) == null ? void 0 : _a.remove();
|
|
5955
|
+
(_b = iframeEventBridgeElement$.getValue()) == null ? void 0 : _b.remove();
|
|
5784
5956
|
stateSubject$.complete();
|
|
5785
5957
|
selectionSubject$.complete();
|
|
5786
5958
|
destroy$.next();
|
|
@@ -5793,7 +5965,6 @@
|
|
|
5793
5965
|
viewportNavigator,
|
|
5794
5966
|
manipulateSpineItems: spine.manipulateSpineItems,
|
|
5795
5967
|
manipulateSpineItem: spine.manipulateSpineItem,
|
|
5796
|
-
manipulateContainer,
|
|
5797
5968
|
moveTo: viewportNavigator.moveTo,
|
|
5798
5969
|
turnLeft: viewportNavigator.turnLeft,
|
|
5799
5970
|
turnRight: viewportNavigator.turnRight,
|
|
@@ -5818,23 +5989,23 @@
|
|
|
5818
5989
|
layout,
|
|
5819
5990
|
load,
|
|
5820
5991
|
destroy,
|
|
5821
|
-
setSettings: context.setSettings,
|
|
5822
|
-
settings$: context.$.settings$,
|
|
5823
|
-
/**
|
|
5824
|
-
* @important
|
|
5825
|
-
* BehaviorSubject
|
|
5826
|
-
*/
|
|
5827
|
-
pagination$: pagination.$.info$,
|
|
5828
5992
|
spineItems$: spine.$.spineItems$,
|
|
5993
|
+
context$: context.$.state$,
|
|
5994
|
+
pagination,
|
|
5995
|
+
settings: {
|
|
5996
|
+
settings$: settings.$.settings$,
|
|
5997
|
+
getSettings: settings.getSettings,
|
|
5998
|
+
setSettings: (data) => settings.setSettings(data, context.getState())
|
|
5999
|
+
},
|
|
5829
6000
|
$: {
|
|
5830
6001
|
state$: stateSubject$.asObservable(),
|
|
5831
6002
|
/**
|
|
5832
|
-
* Dispatched when the reader has loaded a book and is
|
|
6003
|
+
* Dispatched when the reader has loaded a book and is rendering a book.
|
|
5833
6004
|
* Using navigation API and getting information about current content will
|
|
5834
6005
|
* have an effect.
|
|
5835
6006
|
* It can typically be used to hide a loading indicator.
|
|
5836
6007
|
*/
|
|
5837
|
-
|
|
6008
|
+
loadStatus$: context.$.manifest$.pipe(operators.map((manifest) => manifest ? "ready" : "idle")),
|
|
5838
6009
|
/**
|
|
5839
6010
|
* Dispatched when a change in selection happens
|
|
5840
6011
|
*/
|
|
@@ -6037,7 +6208,7 @@
|
|
|
6037
6208
|
}),
|
|
6038
6209
|
operators.takeUntil(context.$.destroy$)
|
|
6039
6210
|
).subscribe();
|
|
6040
|
-
const onLoad$ = context.$.
|
|
6211
|
+
const onLoad$ = context.$.manifest$.pipe(
|
|
6041
6212
|
operators.tap(() => {
|
|
6042
6213
|
uniqueID = Date.now().toString();
|
|
6043
6214
|
})
|
|
@@ -6189,9 +6360,9 @@
|
|
|
6189
6360
|
totalProgress = getTotalProgressFromPercentages(estimateBeforeThisItem, currentItemWeight, progressWithinThisItem);
|
|
6190
6361
|
}
|
|
6191
6362
|
if (currentSpineIndex === readingOrderLength - 1 && pageIndex === numberOfPages - 1 && totalProgress > 0.99) {
|
|
6192
|
-
return
|
|
6363
|
+
return 100;
|
|
6193
6364
|
}
|
|
6194
|
-
return totalProgress;
|
|
6365
|
+
return totalProgress * 100;
|
|
6195
6366
|
};
|
|
6196
6367
|
const getTotalProgressFromPercentages = (estimateBeforeThisItem, currentItemWeight, progressWithinThisItem) => {
|
|
6197
6368
|
return estimateBeforeThisItem + currentItemWeight * progressWithinThisItem;
|
|
@@ -6199,7 +6370,7 @@
|
|
|
6199
6370
|
const getScrollPercentageWithinItem = (context, currentPosition, currentItem) => {
|
|
6200
6371
|
const { height, width } = currentItem.getElementDimensions();
|
|
6201
6372
|
const { top, left } = reader.getAbsolutePositionOf(currentItem);
|
|
6202
|
-
if (
|
|
6373
|
+
if (reader.settings.getSettings().computedPageTurnDirection === `vertical`) {
|
|
6203
6374
|
return Math.max(0, Math.min(1, (currentPosition.y - top + context.getVisibleAreaRect().height) / height));
|
|
6204
6375
|
} else {
|
|
6205
6376
|
return Math.max(0, Math.min(1, (currentPosition.x - left + context.getVisibleAreaRect().width) / width));
|
|
@@ -6389,26 +6560,34 @@
|
|
|
6389
6560
|
container.appendChild(detailsElement);
|
|
6390
6561
|
return container;
|
|
6391
6562
|
};
|
|
6563
|
+
const publicApiEnhancer = (next) => {
|
|
6564
|
+
return (options) => {
|
|
6565
|
+
const reader = next(options);
|
|
6566
|
+
return reader;
|
|
6567
|
+
};
|
|
6568
|
+
};
|
|
6392
6569
|
const createReaderWithEnhancers = (
|
|
6393
6570
|
//__
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
|
|
6400
|
-
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
|
|
6571
|
+
publicApiEnhancer(
|
|
6572
|
+
loadingEnhancer(
|
|
6573
|
+
webkitEnhancer(
|
|
6574
|
+
fontsEnhancer(
|
|
6575
|
+
linksEnhancer(
|
|
6576
|
+
accessibilityEnhancer(
|
|
6577
|
+
resourcesEnhancer(
|
|
6578
|
+
utilsEnhancer(
|
|
6579
|
+
layoutEnhancer(
|
|
6580
|
+
zoomEnhancer(
|
|
6581
|
+
mediaEnhancer(
|
|
6582
|
+
chromeEnhancer(
|
|
6583
|
+
navigationEnhancer(
|
|
6584
|
+
themeEnhancer(
|
|
6585
|
+
hotkeysEnhancer(
|
|
6586
|
+
paginationEnhancer(
|
|
6587
|
+
progressionEnhancer(
|
|
6588
|
+
// __
|
|
6589
|
+
createReader
|
|
6590
|
+
)
|
|
6412
6591
|
)
|
|
6413
6592
|
)
|
|
6414
6593
|
)
|
|
@@ -6432,4 +6611,4 @@
|
|
|
6432
6611
|
exports2.isShallowEqual = isShallowEqual;
|
|
6433
6612
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
6434
6613
|
});
|
|
6435
|
-
//# sourceMappingURL=
|
|
6614
|
+
//# sourceMappingURL=index.umd.cjs.map
|