@prose-reader/core 1.58.0 → 1.60.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/createReaderWithEnhancer.d.ts +4 -48
- package/dist/enhancers/fonts/SettingsManager.d.ts +10 -0
- package/dist/enhancers/fonts/fonts.d.ts +7 -0
- package/dist/enhancers/fonts/types.d.ts +9 -0
- package/dist/enhancers/layoutEnhancer/SettingsManager.d.ts +10 -0
- package/dist/enhancers/layoutEnhancer/layoutEnhancer.d.ts +5 -8
- package/dist/enhancers/layoutEnhancer/types.d.ts +5 -7
- package/dist/index.js +290 -212
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +223 -145
- package/dist/index.umd.cjs.map +1 -1
- package/dist/reader.d.ts +2 -2
- package/dist/settings/ReaderSettingsManager.d.ts +32 -0
- package/dist/settings/SettingsInterface.d.ts +13 -0
- package/dist/settings/SettingsManagerOverload.d.ts +23 -0
- package/dist/settings/types.d.ts +7 -6
- package/dist/spine/createSpine.d.ts +2 -2
- package/dist/spine/locationResolver.d.ts +2 -2
- package/dist/spine/navigationResolver.d.ts +2 -2
- package/dist/spineItem/commonSpineItem.d.ts +2 -2
- package/dist/spineItem/createSpineItem.d.ts +2 -2
- package/dist/spineItem/frameItem/frameItem.d.ts +2 -2
- package/dist/spineItem/frameItem/loader.d.ts +2 -2
- package/dist/spineItem/navigationResolver.d.ts +2 -2
- package/dist/spineItem/prePaginatedSpineItem.d.ts +2 -2
- package/dist/spineItem/reflowableSpineItem.d.ts +2 -2
- package/dist/spineItemManager.d.ts +2 -2
- package/dist/types/reader.d.ts +4 -4
- package/dist/utils/objects.d.ts +1 -0
- package/dist/viewportNavigator/panViewportNavigator.d.ts +2 -2
- package/dist/viewportNavigator/scrollViewportNavigator.d.ts +2 -2
- package/dist/viewportNavigator/viewportNavigator.d.ts +2 -2
- package/package.json +3 -3
- package/dist/enhancers/fonts.d.ts +0 -19
- package/dist/settings/SettingsManager.d.ts +0 -14
- package/dist/settings/defaultSettings.d.ts +0 -3
- package/dist/settings/getComputedSettings.d.ts +0 -4
- package/dist/utils/compose.d.ts +0 -8
package/dist/index.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var _context;
|
|
9
|
+
import { takeUntil, Subject, combineLatest, map as map$1, switchMap, merge, EMPTY, fromEvent, withLatestFrom, NEVER, Observable, of, scheduled, animationFrameScheduler, distinctUntilChanged as distinctUntilChanged$1, startWith as startWith$1, BehaviorSubject, filter as filter$1, debounceTime, combineLatestWith, tap as tap$1, shareReplay as shareReplay$1, from, interval, iif, identity, take as take$1, forkJoin } from "rxjs";
|
|
10
|
+
import { startWith, map, shareReplay, tap, pairwise, switchMap as switchMap$1, filter, take, distinctUntilChanged, takeUntil as takeUntil$1, skip, withLatestFrom as withLatestFrom$1, share, exhaustMap, mergeMap, catchError, debounce, debounceTime as debounceTime$1, delay } from "rxjs/operators";
|
|
3
11
|
import { parseContentType, detectMimeTypeFromName } from "@prose-reader/shared";
|
|
4
12
|
const chromeEnhancer = (next) => (options) => {
|
|
5
13
|
const reader = next(options);
|
|
@@ -72,21 +80,98 @@ const getBase64FromBlob = (data) => {
|
|
|
72
80
|
reader.readAsDataURL(data);
|
|
73
81
|
});
|
|
74
82
|
};
|
|
83
|
+
function shallowMergeIfDefined(obj1, obj2) {
|
|
84
|
+
const result = { ...obj1 };
|
|
85
|
+
for (const key in obj2) {
|
|
86
|
+
if (Object.prototype.hasOwnProperty.call(obj2, key)) {
|
|
87
|
+
const value = obj2[key];
|
|
88
|
+
if (value !== void 0 || !(key in obj1)) {
|
|
89
|
+
result[key] = value;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
class SettingsManagerOverload {
|
|
96
|
+
constructor(initialSettings, settingsManager) {
|
|
97
|
+
this.settingsManager = settingsManager;
|
|
98
|
+
this.inputSettings = shallowMergeIfDefined(this.getDefaultSettings(), initialSettings);
|
|
99
|
+
this.outputSettings = this.computeOutputSettings();
|
|
100
|
+
this.outputSettingsUpdateSubject = new Subject();
|
|
101
|
+
this.settings$ = combineLatest([
|
|
102
|
+
this.settingsManager.settings$,
|
|
103
|
+
this.outputSettingsUpdateSubject.pipe(startWith(this.outputSettings))
|
|
104
|
+
]).pipe(
|
|
105
|
+
map(([parentSettings, settings]) => ({ ...parentSettings, ...settings })),
|
|
106
|
+
shareReplay(1)
|
|
107
|
+
);
|
|
108
|
+
this.settings$.subscribe();
|
|
109
|
+
}
|
|
110
|
+
_prepareUpdate(settings) {
|
|
111
|
+
const parentInputSettings = this.getCleanedParentInputSettings(settings);
|
|
112
|
+
const parentManagerPreparedUpdate = this.settingsManager._prepareUpdate(parentInputSettings);
|
|
113
|
+
this.inputSettings = { ...this.inputSettings, ...settings };
|
|
114
|
+
const outputSettings = this.computeOutputSettings();
|
|
115
|
+
const hasChanged = this.hasSettingsChanged(outputSettings);
|
|
116
|
+
console.log({ outputSettings, hasChanged, parentManagerPreparedUpdate });
|
|
117
|
+
return {
|
|
118
|
+
hasChanged: hasChanged || parentManagerPreparedUpdate.hasChanged,
|
|
119
|
+
commit: () => {
|
|
120
|
+
this.outputSettings = outputSettings;
|
|
121
|
+
if (!parentManagerPreparedUpdate.hasChanged && hasChanged) {
|
|
122
|
+
this.outputSettingsUpdateSubject.next(outputSettings);
|
|
123
|
+
}
|
|
124
|
+
parentManagerPreparedUpdate.commit();
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
update(settings) {
|
|
129
|
+
const { commit } = this._prepareUpdate(settings);
|
|
130
|
+
commit();
|
|
131
|
+
}
|
|
132
|
+
get settings() {
|
|
133
|
+
return {
|
|
134
|
+
...this.settingsManager.settings,
|
|
135
|
+
...this.outputSettings
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
destroy() {
|
|
139
|
+
this.outputSettingsUpdateSubject.complete();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
let SettingsManager$1 = class SettingsManager extends SettingsManagerOverload {
|
|
143
|
+
computeOutputSettings() {
|
|
144
|
+
return this.inputSettings;
|
|
145
|
+
}
|
|
146
|
+
hasSettingsChanged(newOutputSettings) {
|
|
147
|
+
return !isShallowEqual(this.outputSettings, newOutputSettings);
|
|
148
|
+
}
|
|
149
|
+
getCleanedParentInputSettings(settings) {
|
|
150
|
+
const { fontJustification, fontScale, fontWeight, lineHeight, ...rest } = settings;
|
|
151
|
+
return rest;
|
|
152
|
+
}
|
|
153
|
+
getDefaultSettings() {
|
|
154
|
+
return {
|
|
155
|
+
fontScale: 1,
|
|
156
|
+
fontWeight: "publisher",
|
|
157
|
+
lineHeight: "publisher",
|
|
158
|
+
fontJustification: "publisher"
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
};
|
|
75
162
|
const fontsEnhancer = (next) => (options) => {
|
|
76
|
-
const {
|
|
77
|
-
fontScale = 1,
|
|
78
|
-
lineHeight = `publisher`,
|
|
79
|
-
fontWeight = `publisher`,
|
|
80
|
-
fontJustification = `publisher`
|
|
81
|
-
} = options;
|
|
163
|
+
const { fontScale, lineHeight, fontWeight, fontJustification } = options;
|
|
82
164
|
const changes$ = new Subject();
|
|
83
|
-
const settings$ = new BehaviorSubject({
|
|
84
|
-
fontScale,
|
|
85
|
-
lineHeight,
|
|
86
|
-
fontWeight,
|
|
87
|
-
fontJustification
|
|
88
|
-
});
|
|
89
165
|
const reader = next(options);
|
|
166
|
+
const settingsManager = new SettingsManager$1(
|
|
167
|
+
{
|
|
168
|
+
fontScale,
|
|
169
|
+
lineHeight,
|
|
170
|
+
fontWeight,
|
|
171
|
+
fontJustification
|
|
172
|
+
},
|
|
173
|
+
reader.settings
|
|
174
|
+
);
|
|
90
175
|
const getStyle = () => `
|
|
91
176
|
${/*
|
|
92
177
|
Ideally, we would like to use !important but it could break publisher specific
|
|
@@ -98,10 +183,10 @@ const fontsEnhancer = (next) => (options) => {
|
|
|
98
183
|
*/
|
|
99
184
|
``}
|
|
100
185
|
body {
|
|
101
|
-
${settings
|
|
102
|
-
${settings
|
|
103
|
-
${settings
|
|
104
|
-
${settings
|
|
186
|
+
${settingsManager.settings.fontScale !== 1 ? `font-size: ${settingsManager.settings.fontScale}em !important;` : ``}
|
|
187
|
+
${settingsManager.settings.lineHeight !== `publisher` ? `line-height: ${settingsManager.settings.lineHeight} !important;` : ``}
|
|
188
|
+
${settingsManager.settings.fontWeight !== `publisher` ? `font-weight: ${settingsManager.settings.fontWeight} !important;` : ``}
|
|
189
|
+
${settingsManager.settings.fontJustification !== `publisher` ? `text-align: ${settingsManager.settings.fontJustification} !important;` : ``}
|
|
105
190
|
}
|
|
106
191
|
`;
|
|
107
192
|
const applyChangeToSpineItem = (requireLayout) => {
|
|
@@ -125,55 +210,28 @@ const fontsEnhancer = (next) => (options) => {
|
|
|
125
210
|
});
|
|
126
211
|
const shouldRequireLayout = (source) => source.pipe(
|
|
127
212
|
pairwise(),
|
|
128
|
-
map(([old, latest]) => {
|
|
213
|
+
map$1(([old, latest]) => {
|
|
129
214
|
if (latest.fontScale !== old.fontScale) return true;
|
|
130
215
|
if (latest.lineHeight !== old.lineHeight) return true;
|
|
131
216
|
return false;
|
|
132
217
|
})
|
|
133
218
|
);
|
|
134
|
-
|
|
135
|
-
withLatestFrom(settings$),
|
|
136
|
-
map(([changes, settings]) => ({
|
|
137
|
-
fontJustification: changes.fontJustification ?? settings.fontJustification,
|
|
138
|
-
fontWeight: changes.fontWeight ?? settings.fontWeight,
|
|
139
|
-
lineHeight: changes.lineHeight ?? settings.lineHeight,
|
|
140
|
-
fontScale: Math.max(0.01, changes.fontScale ?? settings.fontScale)
|
|
141
|
-
})),
|
|
142
|
-
distinctUntilChanged(isShallowEqual),
|
|
143
|
-
shareReplay(1)
|
|
144
|
-
);
|
|
145
|
-
newSettings$.subscribe(settings$);
|
|
146
|
-
settings$.pipe(shouldRequireLayout, tap(applyChangeToSpineItem), takeUntil(reader.$.destroy$)).subscribe();
|
|
147
|
-
const settingsMerge$ = combineLatest([reader.settings.settings$, settings$]).pipe(
|
|
148
|
-
map(([innerSettings, settings]) => ({
|
|
149
|
-
...innerSettings,
|
|
150
|
-
...settings
|
|
151
|
-
}))
|
|
152
|
-
);
|
|
153
|
-
const setSettings = (settings) => {
|
|
154
|
-
const { fontJustification: fontJustification2, fontScale: fontScale2, fontWeight: fontWeight2, lineHeight: lineHeight2, ...passthroughSettings } = settings;
|
|
155
|
-
changes$.next({ fontJustification: fontJustification2, fontScale: fontScale2, fontWeight: fontWeight2, lineHeight: lineHeight2 });
|
|
156
|
-
reader.settings.setSettings(passthroughSettings);
|
|
157
|
-
};
|
|
219
|
+
settingsManager.settings$.pipe(shouldRequireLayout, tap(applyChangeToSpineItem), takeUntil(reader.$.destroy$)).subscribe();
|
|
158
220
|
return {
|
|
159
221
|
...reader,
|
|
160
222
|
destroy: () => {
|
|
161
223
|
changes$.complete();
|
|
162
|
-
|
|
224
|
+
settingsManager.destroy();
|
|
163
225
|
reader.destroy();
|
|
164
226
|
},
|
|
165
|
-
settings:
|
|
166
|
-
...reader.settings,
|
|
167
|
-
setSettings,
|
|
168
|
-
settings$: settingsMerge$
|
|
169
|
-
}
|
|
227
|
+
settings: settingsManager
|
|
170
228
|
};
|
|
171
229
|
};
|
|
172
230
|
const hotkeysEnhancer = (next) => (options) => {
|
|
173
231
|
const reader = next(options);
|
|
174
232
|
const navigateOnKey = (document2) => fromEvent(document2, "keyup").pipe(
|
|
175
|
-
withLatestFrom
|
|
176
|
-
map(([e, { pageTurnDirection }]) => {
|
|
233
|
+
withLatestFrom(reader.settings.settings$),
|
|
234
|
+
map$1(([e, { pageTurnDirection }]) => {
|
|
177
235
|
if (pageTurnDirection === "horizontal") {
|
|
178
236
|
if (e.key === `ArrowRight`) {
|
|
179
237
|
reader.viewportNavigator.turnRight();
|
|
@@ -245,7 +303,7 @@ const createMovingSafePan$ = (reader) => {
|
|
|
245
303
|
);
|
|
246
304
|
const resetLockViewportFree$ = createResetLock$(viewportFree$).pipe(take(1));
|
|
247
305
|
const pageTurnMode$ = reader.settings.settings$.pipe(
|
|
248
|
-
map
|
|
306
|
+
map(() => reader.settings.settings.computedPageTurnMode),
|
|
249
307
|
distinctUntilChanged()
|
|
250
308
|
);
|
|
251
309
|
const handleViewportLock$ = pageTurnMode$.pipe(
|
|
@@ -257,7 +315,7 @@ const createMovingSafePan$ = (reader) => {
|
|
|
257
315
|
return merge(updateOverlayElement$, handleViewportLock$);
|
|
258
316
|
};
|
|
259
317
|
const mapKeysTo = (keys) => {
|
|
260
|
-
return map
|
|
318
|
+
return map((obj) => {
|
|
261
319
|
return Object.entries(obj).reduce(
|
|
262
320
|
(acc, [key, entry]) => {
|
|
263
321
|
if (keys.includes(key)) {
|
|
@@ -292,14 +350,37 @@ const fixReflowable = (reader) => {
|
|
|
292
350
|
function isDefined(arg) {
|
|
293
351
|
return arg !== null && arg !== void 0;
|
|
294
352
|
}
|
|
353
|
+
class SettingsManager2 extends SettingsManagerOverload {
|
|
354
|
+
computeOutputSettings() {
|
|
355
|
+
return this.inputSettings;
|
|
356
|
+
}
|
|
357
|
+
hasSettingsChanged(newOutputSettings) {
|
|
358
|
+
return !isShallowEqual(this.outputSettings, newOutputSettings);
|
|
359
|
+
}
|
|
360
|
+
getCleanedParentInputSettings(settings) {
|
|
361
|
+
const { layoutAutoResize, pageHorizontalMargin, pageVerticalMargin, ...rest } = settings;
|
|
362
|
+
return rest;
|
|
363
|
+
}
|
|
364
|
+
getDefaultSettings() {
|
|
365
|
+
return {
|
|
366
|
+
layoutAutoResize: "container",
|
|
367
|
+
pageHorizontalMargin: 24,
|
|
368
|
+
pageVerticalMargin: 24
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
}
|
|
295
372
|
const SHOULD_NOT_LAYOUT = false;
|
|
296
373
|
const layoutEnhancer = (next) => (options) => {
|
|
297
|
-
const { pageHorizontalMargin
|
|
374
|
+
const { pageHorizontalMargin, pageVerticalMargin, layoutAutoResize } = options;
|
|
298
375
|
const reader = next(options);
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
376
|
+
const settingsManager = new SettingsManager2(
|
|
377
|
+
{
|
|
378
|
+
pageHorizontalMargin,
|
|
379
|
+
pageVerticalMargin,
|
|
380
|
+
layoutAutoResize
|
|
381
|
+
},
|
|
382
|
+
reader.settings
|
|
383
|
+
);
|
|
303
384
|
reader.hookManager.register(`onViewportOffsetAdjust`, () => {
|
|
304
385
|
let hasRedrawn = false;
|
|
305
386
|
reader.spine.manipulateSpineItems(({ frame }) => {
|
|
@@ -312,7 +393,7 @@ const layoutEnhancer = (next) => (options) => {
|
|
|
312
393
|
});
|
|
313
394
|
reader.hookManager.register(`item.onLayoutBeforeMeasurement`, ({ frame, minimumWidth, item, isImageType }) => {
|
|
314
395
|
var _a, _b;
|
|
315
|
-
const { pageHorizontalMargin: pageHorizontalMargin2 = 0, pageVerticalMargin: pageVerticalMargin2 = 0 } =
|
|
396
|
+
const { pageHorizontalMargin: pageHorizontalMargin2 = 0, pageVerticalMargin: pageVerticalMargin2 = 0 } = settingsManager.settings;
|
|
316
397
|
const pageSize = reader.context.getPageSize();
|
|
317
398
|
if (item.renditionLayout === `reflowable` && frame.getIsReady() && !isImageType() && !frame.getViewportDimensions()) {
|
|
318
399
|
let columnWidth = pageSize.width - pageHorizontalMargin2 * 2;
|
|
@@ -353,7 +434,7 @@ const layoutEnhancer = (next) => (options) => {
|
|
|
353
434
|
let observer;
|
|
354
435
|
if (options.layoutAutoResize === `container`) {
|
|
355
436
|
reader.context.state$.pipe(
|
|
356
|
-
map
|
|
437
|
+
map((state) => state.containerElement),
|
|
357
438
|
filter(isDefined),
|
|
358
439
|
distinctUntilChanged(),
|
|
359
440
|
takeUntil$1(reader.$.destroy$)
|
|
@@ -366,7 +447,7 @@ const layoutEnhancer = (next) => (options) => {
|
|
|
366
447
|
}
|
|
367
448
|
const movingSafePan$ = createMovingSafePan$(reader);
|
|
368
449
|
movingSafePan$.subscribe();
|
|
369
|
-
|
|
450
|
+
settingsManager.settings$.pipe(
|
|
370
451
|
mapKeysTo([`pageHorizontalMargin`, `pageVerticalMargin`]),
|
|
371
452
|
distinctUntilChanged(isShallowEqual),
|
|
372
453
|
skip(1),
|
|
@@ -375,32 +456,14 @@ const layoutEnhancer = (next) => (options) => {
|
|
|
375
456
|
}),
|
|
376
457
|
takeUntil$1(reader.$.destroy$)
|
|
377
458
|
).subscribe();
|
|
378
|
-
const settings$ = combineLatest([reader.settings.settings$, settingsSubject$.asObservable()]).pipe(
|
|
379
|
-
map$1(([innerSettings, settings]) => ({
|
|
380
|
-
...innerSettings,
|
|
381
|
-
...settings
|
|
382
|
-
}))
|
|
383
|
-
);
|
|
384
|
-
const setSettings = ({ pageVerticalMargin: pageVerticalMargin2, pageHorizontalMargin: pageHorizontalMargin2, ...rest }) => {
|
|
385
|
-
if (pageHorizontalMargin2 !== void 0 || pageVerticalMargin2 !== void 0) {
|
|
386
|
-
settingsSubject$.next({
|
|
387
|
-
pageHorizontalMargin: pageHorizontalMargin2 ?? settingsSubject$.value.pageHorizontalMargin,
|
|
388
|
-
pageVerticalMargin: pageVerticalMargin2 ?? settingsSubject$.value.pageVerticalMargin
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
reader.settings.setSettings(rest);
|
|
392
|
-
};
|
|
393
459
|
return {
|
|
394
460
|
...reader,
|
|
395
461
|
destroy: () => {
|
|
462
|
+
settingsManager.destroy();
|
|
396
463
|
reader.destroy();
|
|
397
464
|
observer == null ? void 0 : observer.disconnect();
|
|
398
465
|
},
|
|
399
|
-
settings:
|
|
400
|
-
...reader.settings,
|
|
401
|
-
setSettings,
|
|
402
|
-
settings$
|
|
403
|
-
}
|
|
466
|
+
settings: settingsManager
|
|
404
467
|
};
|
|
405
468
|
};
|
|
406
469
|
const ROOT_NAMESPACE = `@prose-reader/core`;
|
|
@@ -571,8 +634,8 @@ const createNavigator = (reader) => {
|
|
|
571
634
|
};
|
|
572
635
|
const createState = (reader) => {
|
|
573
636
|
return reader.pagination.paginationInfo$.pipe(
|
|
574
|
-
withLatestFrom
|
|
575
|
-
map(([paginationInfo, manifest, { computedPageTurnDirection }]) => {
|
|
637
|
+
withLatestFrom(reader.context.manifest$, reader.settings.settings$),
|
|
638
|
+
map$1(([paginationInfo, manifest, { computedPageTurnDirection }]) => {
|
|
576
639
|
const numberOfSpineItems = (manifest == null ? void 0 : manifest.spineItems.length) ?? 0;
|
|
577
640
|
const isAtAbsoluteBeginning = paginationInfo.beginSpineItemIndex === 0 && paginationInfo.beginPageIndexInSpineItem === 0;
|
|
578
641
|
const isAtAbsoluteEnd = paginationInfo.endPageIndexInSpineItem === paginationInfo.endNumberOfPagesInSpineItem - 1 && paginationInfo.endSpineItemIndex === Math.max(numberOfSpineItems - 1, 0);
|
|
@@ -649,8 +712,8 @@ const getChaptersInfo = (reader) => {
|
|
|
649
712
|
};
|
|
650
713
|
const trackChapterInfo = (reader) => {
|
|
651
714
|
return reader.spine.$.spineItems$.pipe(
|
|
652
|
-
startWith([]),
|
|
653
|
-
map(() => getChaptersInfo(reader))
|
|
715
|
+
startWith$1([]),
|
|
716
|
+
map$1(() => getChaptersInfo(reader))
|
|
654
717
|
);
|
|
655
718
|
};
|
|
656
719
|
const NAMESPACE$6 = `pagination`;
|
|
@@ -752,8 +815,8 @@ const getNumberOfPagesForAllSpineItems = (reader) => reader.spineItemManager.get
|
|
|
752
815
|
const trackTotalPages = (reader) => {
|
|
753
816
|
const totalPages$ = reader.spine.$.layout$.pipe(
|
|
754
817
|
debounceTime(10, animationFrameScheduler),
|
|
755
|
-
withLatestFrom
|
|
756
|
-
map(() => {
|
|
818
|
+
withLatestFrom(reader.pagination.paginationInfo$),
|
|
819
|
+
map$1(() => {
|
|
757
820
|
const numberOfPagesPerItems = getNumberOfPagesForAllSpineItems(reader);
|
|
758
821
|
return {
|
|
759
822
|
numberOfPagesPerItems,
|
|
@@ -764,7 +827,7 @@ const trackTotalPages = (reader) => {
|
|
|
764
827
|
};
|
|
765
828
|
}),
|
|
766
829
|
distinctUntilChanged$1(isShallowEqual),
|
|
767
|
-
startWith({
|
|
830
|
+
startWith$1({
|
|
768
831
|
numberOfPagesPerItems: [],
|
|
769
832
|
numberOfTotalPages: 0
|
|
770
833
|
})
|
|
@@ -824,7 +887,7 @@ const trackPaginationInfo = (reader) => {
|
|
|
824
887
|
});
|
|
825
888
|
const extandedBasePagination$ = reader.pagination.paginationInfo$.pipe(
|
|
826
889
|
combineLatestWith(chaptersInfo$),
|
|
827
|
-
map(([info, chaptersInfo]) => ({
|
|
890
|
+
map$1(([info, chaptersInfo]) => ({
|
|
828
891
|
...info,
|
|
829
892
|
...mapPaginationInfoToExtendedInfo(reader)(info, chaptersInfo)
|
|
830
893
|
})),
|
|
@@ -834,7 +897,7 @@ const trackPaginationInfo = (reader) => {
|
|
|
834
897
|
extandedBasePagination$,
|
|
835
898
|
totalPages$
|
|
836
899
|
]).pipe(
|
|
837
|
-
map(([pageInfo, totalPageInfo]) => ({
|
|
900
|
+
map$1(([pageInfo, totalPageInfo]) => ({
|
|
838
901
|
...pageInfo,
|
|
839
902
|
...totalPageInfo,
|
|
840
903
|
beginAbsolutePageIndex: totalPageInfo.numberOfPagesPerItems.slice(0, pageInfo.beginSpineItemIndex).reduce((acc, numberOfPagesForItem) => acc + numberOfPagesForItem, pageInfo.beginPageIndexInSpineItem ?? 0),
|
|
@@ -1233,22 +1296,22 @@ class Context {
|
|
|
1233
1296
|
this.destroy$ = new Subject();
|
|
1234
1297
|
this.state$ = this._stateSubject.pipe(distinctUntilChanged(isShallowEqual));
|
|
1235
1298
|
this.manifest$ = this._stateSubject.pipe(
|
|
1236
|
-
map
|
|
1299
|
+
map((state) => state.manifest),
|
|
1237
1300
|
filter(isDefined),
|
|
1238
1301
|
distinctUntilChanged()
|
|
1239
1302
|
);
|
|
1240
1303
|
this.containerElement$ = this._stateSubject.pipe(
|
|
1241
|
-
map
|
|
1304
|
+
map((state) => state.containerElement),
|
|
1242
1305
|
filter(isDefined),
|
|
1243
1306
|
distinctUntilChanged()
|
|
1244
1307
|
);
|
|
1245
1308
|
this.hasVerticalWriting$ = this._stateSubject.pipe(
|
|
1246
|
-
map
|
|
1309
|
+
map((state) => state.hasVerticalWriting),
|
|
1247
1310
|
filter(isDefined),
|
|
1248
1311
|
distinctUntilChanged()
|
|
1249
1312
|
);
|
|
1250
1313
|
this.isUsingSpreadMode$ = this._stateSubject.pipe(
|
|
1251
|
-
map
|
|
1314
|
+
map((state) => state.isUsingSpreadMode),
|
|
1252
1315
|
distinctUntilChanged()
|
|
1253
1316
|
);
|
|
1254
1317
|
this.isRTL = () => {
|
|
@@ -1441,9 +1504,9 @@ const createLoader = ({
|
|
|
1441
1504
|
const unload$ = unloadSubject$.asObservable().pipe(
|
|
1442
1505
|
// @todo remove iframe when viewport is free
|
|
1443
1506
|
// @todo use takeUntil(load$) when it's the case to cancel
|
|
1444
|
-
withLatestFrom(frameElementSubject$),
|
|
1507
|
+
withLatestFrom$1(frameElementSubject$),
|
|
1445
1508
|
filter(([_, frame]) => !!frame),
|
|
1446
|
-
map
|
|
1509
|
+
map(([, frame]) => {
|
|
1447
1510
|
hookManager.destroy(`item.onLoad`, item.id);
|
|
1448
1511
|
frame == null ? void 0 : frame.remove();
|
|
1449
1512
|
frameElementSubject$.next(void 0);
|
|
@@ -1452,12 +1515,12 @@ const createLoader = ({
|
|
|
1452
1515
|
takeUntil$1(destroySubject$)
|
|
1453
1516
|
);
|
|
1454
1517
|
const load$ = loadSubject$.asObservable().pipe(
|
|
1455
|
-
withLatestFrom(isLoadedSubject$),
|
|
1518
|
+
withLatestFrom$1(isLoadedSubject$),
|
|
1456
1519
|
filter(([_, isLoaded]) => !isLoaded),
|
|
1457
1520
|
// let's ignore later load as long as the first one still runs
|
|
1458
1521
|
exhaustMap(() => {
|
|
1459
1522
|
return createFrame$().pipe(
|
|
1460
|
-
mergeMap((frame) => waitForViewportFree$.pipe(map
|
|
1523
|
+
mergeMap((frame) => waitForViewportFree$.pipe(map(() => frame))),
|
|
1461
1524
|
mergeMap((frame) => {
|
|
1462
1525
|
parent.appendChild(frame);
|
|
1463
1526
|
frameElementSubject$.next(frame);
|
|
@@ -1475,7 +1538,7 @@ const createLoader = ({
|
|
|
1475
1538
|
frame == null ? void 0 : frame.setAttribute(`srcdoc`, htmlDoc);
|
|
1476
1539
|
}
|
|
1477
1540
|
}),
|
|
1478
|
-
map
|
|
1541
|
+
map(() => frame),
|
|
1479
1542
|
catchError((e) => {
|
|
1480
1543
|
Report.error(`Error while trying to fetch or load resource for item ${item.id}`);
|
|
1481
1544
|
console.error(e);
|
|
@@ -1506,7 +1569,7 @@ const createLoader = ({
|
|
|
1506
1569
|
itemId: item.id,
|
|
1507
1570
|
frame
|
|
1508
1571
|
}).filter((result) => result instanceof Observable);
|
|
1509
|
-
return combineLatest([of(null), ...hookResults]).pipe(map
|
|
1572
|
+
return combineLatest([of(null), ...hookResults]).pipe(map(() => frame));
|
|
1510
1573
|
})
|
|
1511
1574
|
);
|
|
1512
1575
|
}),
|
|
@@ -1527,8 +1590,8 @@ const createLoader = ({
|
|
|
1527
1590
|
makeItHot,
|
|
1528
1591
|
takeUntil$1(destroySubject$)
|
|
1529
1592
|
);
|
|
1530
|
-
merge(load$.pipe(map
|
|
1531
|
-
merge(ready$.pipe(map
|
|
1593
|
+
merge(load$.pipe(map(() => true)), unloadSubject$.pipe(map(() => false))).pipe(distinctUntilChanged(), takeUntil$1(destroySubject$)).subscribe(isLoadedSubject$);
|
|
1594
|
+
merge(ready$.pipe(map(() => true)), unloadSubject$.pipe(map(() => false))).pipe(distinctUntilChanged(), takeUntil$1(destroySubject$)).subscribe(isReadySubject$);
|
|
1532
1595
|
unload$.subscribe();
|
|
1533
1596
|
return {
|
|
1534
1597
|
load: () => loadSubject$.next(),
|
|
@@ -1630,8 +1693,8 @@ const createFrameItem = ({
|
|
|
1630
1693
|
return createHtmlPageFromResource(response, item);
|
|
1631
1694
|
};
|
|
1632
1695
|
const contentLayoutChange$ = merge(
|
|
1633
|
-
unloaded$.pipe(map
|
|
1634
|
-
ready$.pipe(map
|
|
1696
|
+
unloaded$.pipe(map(() => ({ isFirstLayout: false }))),
|
|
1697
|
+
ready$.pipe(map(() => ({ isFirstLayout: true })))
|
|
1635
1698
|
);
|
|
1636
1699
|
const destroy = () => {
|
|
1637
1700
|
unload();
|
|
@@ -1950,8 +2013,8 @@ const createCommonSpineItem = ({
|
|
|
1950
2013
|
...options
|
|
1951
2014
|
});
|
|
1952
2015
|
const contentLayout$ = spineItemFrame.$.contentLayoutChange$.pipe(
|
|
1953
|
-
withLatestFrom(spineItemFrame.$.isReady$),
|
|
1954
|
-
map
|
|
2016
|
+
withLatestFrom$1(spineItemFrame.$.isReady$),
|
|
2017
|
+
map(([data, isReady]) => ({
|
|
1955
2018
|
isFirstLayout: data.isFirstLayout,
|
|
1956
2019
|
isReady
|
|
1957
2020
|
}))
|
|
@@ -3623,8 +3686,8 @@ const createSpine = ({
|
|
|
3623
3686
|
).pipe(
|
|
3624
3687
|
switchMap$1(() => {
|
|
3625
3688
|
return waitForViewportFree$.pipe(
|
|
3626
|
-
withLatestFrom(currentNavigationPosition$),
|
|
3627
|
-
map
|
|
3689
|
+
withLatestFrom$1(currentNavigationPosition$),
|
|
3690
|
+
map(([, currentNavigationPosition]) => {
|
|
3628
3691
|
const focusedSpineItemIndex = spineItemManager.getFocusedSpineItemIndex();
|
|
3629
3692
|
report.log(`update contents`, { focusedSpineItemIndex });
|
|
3630
3693
|
if (focusedSpineItemIndex === void 0) return;
|
|
@@ -3909,7 +3972,7 @@ const createSpineItemManager = ({ context, settings }) => {
|
|
|
3909
3972
|
itemIsReady$: orderedSpineItemsSubject$.asObservable().pipe(
|
|
3910
3973
|
switchMap$1((items) => {
|
|
3911
3974
|
const itemsIsReady$ = items.map(
|
|
3912
|
-
(item) => item.$.isReady$.pipe(map
|
|
3975
|
+
(item) => item.$.isReady$.pipe(map((isReady) => ({ item: item.item, isReady })))
|
|
3913
3976
|
);
|
|
3914
3977
|
return merge(...itemsIsReady$);
|
|
3915
3978
|
})
|
|
@@ -4528,7 +4591,7 @@ const createScrollViewportNavigator = ({
|
|
|
4528
4591
|
return false;
|
|
4529
4592
|
};
|
|
4530
4593
|
const runOnFreePageTurnModeOnly$ = (source) => settings.settings$.pipe(
|
|
4531
|
-
map
|
|
4594
|
+
map(({ computedPageTurnMode }) => computedPageTurnMode),
|
|
4532
4595
|
distinctUntilChanged(),
|
|
4533
4596
|
switchMap$1((mode) => iif(() => mode === `controlled`, EMPTY, source))
|
|
4534
4597
|
);
|
|
@@ -4571,7 +4634,7 @@ const createScrollViewportNavigator = ({
|
|
|
4571
4634
|
};
|
|
4572
4635
|
const navigationOnScroll$ = userScroll$.pipe(
|
|
4573
4636
|
debounceTime$1(SCROLL_FINISHED_DEBOUNCE_TIMEOUT, animationFrameScheduler),
|
|
4574
|
-
withLatestFrom(currentNavigationSubject$),
|
|
4637
|
+
withLatestFrom$1(currentNavigationSubject$),
|
|
4575
4638
|
switchMap$1(() => {
|
|
4576
4639
|
var _a, _b;
|
|
4577
4640
|
const navigation = getNavigationForPosition(
|
|
@@ -4588,11 +4651,11 @@ const createScrollViewportNavigator = ({
|
|
|
4588
4651
|
);
|
|
4589
4652
|
const state$ = merge(
|
|
4590
4653
|
userScroll$.pipe(
|
|
4591
|
-
map
|
|
4654
|
+
map(() => `start`),
|
|
4592
4655
|
distinctUntilChanged()
|
|
4593
4656
|
),
|
|
4594
|
-
userScrollEnd$.pipe(map
|
|
4595
|
-
).pipe(startWith
|
|
4657
|
+
userScrollEnd$.pipe(map(() => `end`))
|
|
4658
|
+
).pipe(startWith(`end`));
|
|
4596
4659
|
return {
|
|
4597
4660
|
destroy: () => {
|
|
4598
4661
|
},
|
|
@@ -4652,7 +4715,7 @@ const createManualViewportNavigator = ({
|
|
|
4652
4715
|
);
|
|
4653
4716
|
const cfiNavigation$ = navigationTriggerSubject$.pipe(
|
|
4654
4717
|
filter((e) => e.type === `cfi`),
|
|
4655
|
-
map
|
|
4718
|
+
map(({ data: { animate, cfi } }) => {
|
|
4656
4719
|
const navigation = navigator2.getNavigationForCfi(cfi);
|
|
4657
4720
|
Report.log(NAMESPACE$2, `goToCfi`, { cfi, animate, navigation });
|
|
4658
4721
|
return {
|
|
@@ -4727,7 +4790,7 @@ const createManualViewportNavigator = ({
|
|
|
4727
4790
|
);
|
|
4728
4791
|
const leftPageNavigation$ = navigationTriggerSubject$.pipe(
|
|
4729
4792
|
filter((e) => e.type === `leftPage`),
|
|
4730
|
-
withLatestFrom(currentNavigationSubject$),
|
|
4793
|
+
withLatestFrom$1(currentNavigationSubject$),
|
|
4731
4794
|
switchMap$1(
|
|
4732
4795
|
([
|
|
4733
4796
|
{
|
|
@@ -4743,7 +4806,7 @@ const createManualViewportNavigator = ({
|
|
|
4743
4806
|
);
|
|
4744
4807
|
const rightPageNavigation$ = navigationTriggerSubject$.pipe(
|
|
4745
4808
|
filter((e) => e.type === `rightPage`),
|
|
4746
|
-
withLatestFrom(currentNavigationSubject$),
|
|
4809
|
+
withLatestFrom$1(currentNavigationSubject$),
|
|
4747
4810
|
switchMap$1(
|
|
4748
4811
|
([
|
|
4749
4812
|
{
|
|
@@ -4771,9 +4834,9 @@ const createManualViewportNavigator = ({
|
|
|
4771
4834
|
* This is because manual navigation is not used with scroll where you can move within the same item. A manual
|
|
4772
4835
|
* navigation would theoretically always move to different items.
|
|
4773
4836
|
*/
|
|
4774
|
-
withLatestFrom(currentNavigationSubject$),
|
|
4837
|
+
withLatestFrom$1(currentNavigationSubject$),
|
|
4775
4838
|
filter(([navigation, currentNavigation]) => navigator2.areNavigationDifferent(navigation, currentNavigation)),
|
|
4776
|
-
map
|
|
4839
|
+
map(([navigation]) => navigation)
|
|
4777
4840
|
);
|
|
4778
4841
|
return {
|
|
4779
4842
|
destroy: () => {
|
|
@@ -4876,7 +4939,7 @@ const createPanViewportNavigator = ({
|
|
|
4876
4939
|
);
|
|
4877
4940
|
const snapNavigation$ = navigationTriggerSubject$.pipe(
|
|
4878
4941
|
filter((e) => e.type === `snap`),
|
|
4879
|
-
withLatestFrom
|
|
4942
|
+
withLatestFrom(settings.settings$),
|
|
4880
4943
|
switchMap$1(
|
|
4881
4944
|
([
|
|
4882
4945
|
{
|
|
@@ -5066,7 +5129,7 @@ const createViewportNavigator = ({
|
|
|
5066
5129
|
skip(1)
|
|
5067
5130
|
);
|
|
5068
5131
|
const layout$ = merge(layoutSubject$, layoutChangeSettings$).pipe(
|
|
5069
|
-
withLatestFrom(element$),
|
|
5132
|
+
withLatestFrom$1(element$),
|
|
5070
5133
|
tap(([, element]) => {
|
|
5071
5134
|
if (settings.settings.computedPageTurnMode === `scrollable`) {
|
|
5072
5135
|
element.style.removeProperty(`transform`);
|
|
@@ -5082,7 +5145,7 @@ const createViewportNavigator = ({
|
|
|
5082
5145
|
layout$.subscribe();
|
|
5083
5146
|
const navigation$ = merge(
|
|
5084
5147
|
panViewportNavigator.$.navigation$.pipe(
|
|
5085
|
-
map
|
|
5148
|
+
map((event) => ({
|
|
5086
5149
|
...event,
|
|
5087
5150
|
position: { x: event.x, y: event.y, spineItem: event.spineItem },
|
|
5088
5151
|
animation: `snap`,
|
|
@@ -5090,7 +5153,7 @@ const createViewportNavigator = ({
|
|
|
5090
5153
|
}))
|
|
5091
5154
|
),
|
|
5092
5155
|
manualViewportNavigator.$.navigation$.pipe(
|
|
5093
|
-
map
|
|
5156
|
+
map((event) => ({
|
|
5094
5157
|
...event,
|
|
5095
5158
|
position: { x: event.x, y: event.y, spineItem: event.spineItem },
|
|
5096
5159
|
animation: event.animate ? `turn` : false,
|
|
@@ -5098,21 +5161,21 @@ const createViewportNavigator = ({
|
|
|
5098
5161
|
}))
|
|
5099
5162
|
),
|
|
5100
5163
|
adjustNavigationSubject$.pipe(
|
|
5101
|
-
map
|
|
5164
|
+
map((event) => ({
|
|
5102
5165
|
...event,
|
|
5103
5166
|
triggeredBy: `adjust`,
|
|
5104
5167
|
animation: event.animate ? `turn` : false
|
|
5105
5168
|
}))
|
|
5106
5169
|
),
|
|
5107
5170
|
scrollViewportNavigator.$.navigation$.pipe(
|
|
5108
|
-
map
|
|
5171
|
+
map((event) => ({
|
|
5109
5172
|
...event,
|
|
5110
5173
|
triggeredBy: `scroll`,
|
|
5111
5174
|
animation: event.animate ? `turn` : false
|
|
5112
5175
|
}))
|
|
5113
5176
|
)
|
|
5114
5177
|
).pipe(
|
|
5115
|
-
map
|
|
5178
|
+
map((event) => {
|
|
5116
5179
|
if (`lastUserExpectedNavigation` in event) {
|
|
5117
5180
|
lastUserExpectedNavigation = event.lastUserExpectedNavigation;
|
|
5118
5181
|
}
|
|
@@ -5132,10 +5195,10 @@ const createViewportNavigator = ({
|
|
|
5132
5195
|
})
|
|
5133
5196
|
);
|
|
5134
5197
|
const manualAdjust$ = merge(
|
|
5135
|
-
panViewportNavigator.$.moveToSubject$.asObservable().pipe(map
|
|
5198
|
+
panViewportNavigator.$.moveToSubject$.asObservable().pipe(map((event) => ({ ...event, animation: false }))),
|
|
5136
5199
|
navigationWhichRequireManualAdjust$
|
|
5137
5200
|
).pipe(
|
|
5138
|
-
map
|
|
5201
|
+
map(({ animation, position }) => {
|
|
5139
5202
|
const shouldAnimate = !(!animation || animation === `turn` && settings.settings.computedPageTurnAnimation === `none`);
|
|
5140
5203
|
return {
|
|
5141
5204
|
type: `manualAdjust`,
|
|
@@ -5147,7 +5210,7 @@ const createViewportNavigator = ({
|
|
|
5147
5210
|
share()
|
|
5148
5211
|
);
|
|
5149
5212
|
const processManualAdjust$ = merge(manualAdjust$).pipe(
|
|
5150
|
-
startWith
|
|
5213
|
+
startWith(void 0),
|
|
5151
5214
|
pairwise(),
|
|
5152
5215
|
tap(([prevEvent, currentEvent]) => {
|
|
5153
5216
|
if ((prevEvent == null ? void 0 : prevEvent.type) === `manualAdjust` && (currentEvent == null ? void 0 : currentEvent.type) !== `manualAdjust`) {
|
|
@@ -5157,7 +5220,7 @@ const createViewportNavigator = ({
|
|
|
5157
5220
|
}),
|
|
5158
5221
|
switchMap$1(([, currentEvent]) => {
|
|
5159
5222
|
if ((currentEvent == null ? void 0 : currentEvent.type) !== `manualAdjust`) return EMPTY;
|
|
5160
|
-
const animationDuration = currentEvent.animation === `snap` ? settings.settings.
|
|
5223
|
+
const animationDuration = currentEvent.animation === `snap` ? settings.settings.snapAnimationDuration : settings.settings.computedPageTurnAnimationDuration;
|
|
5161
5224
|
const pageTurnAnimation = currentEvent.animation === `snap` ? `slide` : settings.settings.computedPageTurnAnimation;
|
|
5162
5225
|
return of(currentEvent).pipe(
|
|
5163
5226
|
/**
|
|
@@ -5222,11 +5285,11 @@ const createViewportNavigator = ({
|
|
|
5222
5285
|
takeUntil$1(context.destroy$)
|
|
5223
5286
|
);
|
|
5224
5287
|
const adjustmentState$ = merge(
|
|
5225
|
-
merge(manualAdjust$).pipe(map
|
|
5226
|
-
merge(processManualAdjust$).pipe(map
|
|
5288
|
+
merge(manualAdjust$).pipe(map(() => `start`)),
|
|
5289
|
+
merge(processManualAdjust$).pipe(map(() => `end`))
|
|
5227
5290
|
);
|
|
5228
5291
|
const state$ = combineLatest([...viewportNavigators.map(({ $: { state$: state$2 } }) => state$2), adjustmentState$]).pipe(
|
|
5229
|
-
map
|
|
5292
|
+
map((states) => states.every((state) => state === `end`) ? `free` : `busy`),
|
|
5230
5293
|
distinctUntilChanged(),
|
|
5231
5294
|
shareReplay(1),
|
|
5232
5295
|
/**
|
|
@@ -5272,7 +5335,7 @@ const createViewportNavigator = ({
|
|
|
5272
5335
|
),
|
|
5273
5336
|
share()
|
|
5274
5337
|
);
|
|
5275
|
-
const parentElementSub = parentElement$.pipe(filter(isDefined), withLatestFrom(spine.element$)).subscribe(([parentElement, spineElement]) => {
|
|
5338
|
+
const parentElementSub = parentElement$.pipe(filter(isDefined), withLatestFrom$1(spine.element$)).subscribe(([parentElement, spineElement]) => {
|
|
5276
5339
|
const element = createElement(parentElement.ownerDocument, hookManager);
|
|
5277
5340
|
element.appendChild(spineElement);
|
|
5278
5341
|
parentElement.appendChild(element);
|
|
@@ -5505,96 +5568,111 @@ const createCfiLocator = ({
|
|
|
5505
5568
|
generateFromRange
|
|
5506
5569
|
};
|
|
5507
5570
|
};
|
|
5508
|
-
|
|
5509
|
-
const manifest = context.manifest;
|
|
5510
|
-
const hasVerticalWriting = context.state.hasVerticalWriting ?? false;
|
|
5511
|
-
const computedSettings = {
|
|
5512
|
-
computedPageTurnDirection: settings.pageTurnDirection,
|
|
5513
|
-
computedPageTurnAnimation: settings.pageTurnAnimation,
|
|
5514
|
-
computedPageTurnMode: `controlled`,
|
|
5515
|
-
computedPageTurnAnimationDuration: 0,
|
|
5516
|
-
computedSnapAnimationDuration: 0
|
|
5517
|
-
};
|
|
5518
|
-
if ((manifest == null ? void 0 : manifest.renditionFlow) === `scrolled-continuous`) {
|
|
5519
|
-
computedSettings.computedPageTurnMode = `scrollable`;
|
|
5520
|
-
computedSettings.computedPageTurnDirection = `vertical`;
|
|
5521
|
-
} else if (manifest && settings.pageTurnMode === `scrollable` && (manifest.renditionLayout !== `pre-paginated` || !areAllItemsPrePaginated(manifest))) {
|
|
5522
|
-
Report.warn(`pageTurnMode ${settings.pageTurnMode} incompatible with current book, switching back to default`);
|
|
5523
|
-
computedSettings.computedPageTurnAnimation = `none`;
|
|
5524
|
-
computedSettings.computedPageTurnMode = `controlled`;
|
|
5525
|
-
} else if (settings.pageTurnMode === `scrollable`) {
|
|
5526
|
-
computedSettings.computedPageTurnMode = `scrollable`;
|
|
5527
|
-
computedSettings.computedPageTurnDirection = `vertical`;
|
|
5528
|
-
}
|
|
5529
|
-
if (hasVerticalWriting && computedSettings.computedPageTurnAnimation === `slide`) {
|
|
5530
|
-
Report.warn(
|
|
5531
|
-
`pageTurnAnimation ${computedSettings.computedPageTurnAnimation} incompatible with current book, switching back to default`
|
|
5532
|
-
);
|
|
5533
|
-
computedSettings.computedPageTurnAnimation = `none`;
|
|
5534
|
-
}
|
|
5535
|
-
if (computedSettings.computedPageTurnMode === `scrollable`) {
|
|
5536
|
-
computedSettings.computedPageTurnAnimationDuration = 0;
|
|
5537
|
-
computedSettings.computedPageTurnAnimation = `none`;
|
|
5538
|
-
} else {
|
|
5539
|
-
computedSettings.computedPageTurnAnimationDuration = settings.pageTurnAnimationDuration !== void 0 ? settings.pageTurnAnimationDuration : 300;
|
|
5540
|
-
}
|
|
5541
|
-
return computedSettings;
|
|
5542
|
-
};
|
|
5543
|
-
const defaultSettings = {
|
|
5544
|
-
forceSinglePageMode: false,
|
|
5545
|
-
pageTurnAnimation: `none`,
|
|
5546
|
-
// computedPageTurnAnimation: `none`,
|
|
5547
|
-
pageTurnDirection: `horizontal`,
|
|
5548
|
-
// computedPageTurnDirection: `horizontal`,
|
|
5549
|
-
pageTurnAnimationDuration: void 0,
|
|
5550
|
-
// computedPageTurnAnimationDuration: 0,
|
|
5551
|
-
pageTurnMode: `controlled`,
|
|
5552
|
-
// computedPageTurnMode: `controlled`,
|
|
5553
|
-
// computedSnapAnimationDuration: 300,
|
|
5554
|
-
navigationSnapThreshold: 0.3,
|
|
5555
|
-
numberOfAdjacentSpineItemToPreLoad: 0
|
|
5556
|
-
};
|
|
5557
|
-
class SettingsManager {
|
|
5571
|
+
class ReaderSettingsManager {
|
|
5558
5572
|
constructor(initialSettings, context) {
|
|
5559
|
-
this
|
|
5573
|
+
__privateAdd(this, _context);
|
|
5574
|
+
__privateSet(this, _context, context);
|
|
5560
5575
|
const settingsWithDefaults = {
|
|
5561
|
-
...
|
|
5576
|
+
...this.getDefaultSettings(),
|
|
5562
5577
|
...initialSettings
|
|
5563
5578
|
};
|
|
5564
|
-
const
|
|
5565
|
-
|
|
5566
|
-
this.
|
|
5567
|
-
this.settings$ = this.
|
|
5579
|
+
const outputSettings = this.getOutputSettings(settingsWithDefaults);
|
|
5580
|
+
this.outputSettings = outputSettings;
|
|
5581
|
+
this.outputSettingsUpdateSubject = new Subject();
|
|
5582
|
+
this.settings$ = this.outputSettingsUpdateSubject.asObservable().pipe(startWith(this.settings), shareReplay(1));
|
|
5568
5583
|
const recomputeSettingsOnContextChange$ = combineLatest([context.hasVerticalWriting$, context.manifest$]).pipe(
|
|
5569
5584
|
tap(() => {
|
|
5570
|
-
this.
|
|
5585
|
+
this.update(this.settings);
|
|
5571
5586
|
})
|
|
5572
5587
|
);
|
|
5573
|
-
const updateContextOnSettingsChanges$ = this.
|
|
5588
|
+
const updateContextOnSettingsChanges$ = this.settings$.pipe(
|
|
5574
5589
|
tap(({ forceSinglePageMode }) => {
|
|
5575
5590
|
context.update({ forceSinglePageMode });
|
|
5576
5591
|
})
|
|
5577
5592
|
);
|
|
5578
5593
|
merge(recomputeSettingsOnContextChange$, updateContextOnSettingsChanges$).pipe(takeUntil$1(context.destroy$)).subscribe();
|
|
5594
|
+
this.settings$.subscribe();
|
|
5595
|
+
}
|
|
5596
|
+
getComputedSettings(settings) {
|
|
5597
|
+
const manifest = __privateGet(this, _context).manifest;
|
|
5598
|
+
const hasVerticalWriting = __privateGet(this, _context).state.hasVerticalWriting ?? false;
|
|
5599
|
+
const computedSettings = {
|
|
5600
|
+
computedPageTurnDirection: settings.pageTurnDirection,
|
|
5601
|
+
computedPageTurnAnimation: settings.pageTurnAnimation,
|
|
5602
|
+
computedPageTurnMode: `controlled`,
|
|
5603
|
+
computedPageTurnAnimationDuration: 0
|
|
5604
|
+
};
|
|
5605
|
+
if ((manifest == null ? void 0 : manifest.renditionFlow) === `scrolled-continuous`) {
|
|
5606
|
+
computedSettings.computedPageTurnMode = `scrollable`;
|
|
5607
|
+
computedSettings.computedPageTurnDirection = `vertical`;
|
|
5608
|
+
} else if (manifest && settings.pageTurnMode === `scrollable` && (manifest.renditionLayout !== `pre-paginated` || !areAllItemsPrePaginated(manifest))) {
|
|
5609
|
+
Report.warn(`pageTurnMode ${settings.pageTurnMode} incompatible with current book, switching back to default`);
|
|
5610
|
+
computedSettings.computedPageTurnAnimation = `none`;
|
|
5611
|
+
computedSettings.computedPageTurnMode = `controlled`;
|
|
5612
|
+
} else if (settings.pageTurnMode === `scrollable`) {
|
|
5613
|
+
computedSettings.computedPageTurnMode = `scrollable`;
|
|
5614
|
+
computedSettings.computedPageTurnDirection = `vertical`;
|
|
5615
|
+
}
|
|
5616
|
+
if (hasVerticalWriting && computedSettings.computedPageTurnAnimation === `slide`) {
|
|
5617
|
+
Report.warn(
|
|
5618
|
+
`pageTurnAnimation ${computedSettings.computedPageTurnAnimation} incompatible with current book, switching back to default`
|
|
5619
|
+
);
|
|
5620
|
+
computedSettings.computedPageTurnAnimation = `none`;
|
|
5621
|
+
}
|
|
5622
|
+
if (computedSettings.computedPageTurnMode === `scrollable`) {
|
|
5623
|
+
computedSettings.computedPageTurnAnimationDuration = 0;
|
|
5624
|
+
computedSettings.computedPageTurnAnimation = `none`;
|
|
5625
|
+
} else {
|
|
5626
|
+
computedSettings.computedPageTurnAnimationDuration = settings.pageTurnAnimationDuration !== void 0 ? settings.pageTurnAnimationDuration : 300;
|
|
5627
|
+
}
|
|
5628
|
+
return computedSettings;
|
|
5579
5629
|
}
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
const
|
|
5583
|
-
|
|
5584
|
-
|
|
5630
|
+
_prepareUpdate(settings) {
|
|
5631
|
+
const state = this.getOutputSettings(settings);
|
|
5632
|
+
const hasChanged = !isShallowEqual(this.outputSettings, state);
|
|
5633
|
+
return {
|
|
5634
|
+
hasChanged,
|
|
5635
|
+
state,
|
|
5636
|
+
commit: () => {
|
|
5637
|
+
this.outputSettings = state;
|
|
5638
|
+
if (hasChanged) {
|
|
5639
|
+
this.outputSettingsUpdateSubject.next(state);
|
|
5640
|
+
}
|
|
5641
|
+
}
|
|
5642
|
+
};
|
|
5643
|
+
}
|
|
5644
|
+
getOutputSettings(inputSettings) {
|
|
5645
|
+
const computedSettings = this.getComputedSettings({ ...this.outputSettings, ...inputSettings });
|
|
5646
|
+
return { ...this.outputSettings, ...inputSettings, ...computedSettings };
|
|
5585
5647
|
}
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5648
|
+
getDefaultSettings() {
|
|
5649
|
+
return {
|
|
5650
|
+
forceSinglePageMode: false,
|
|
5651
|
+
pageTurnAnimation: `none`,
|
|
5652
|
+
// computedPageTurnAnimation: `none`,
|
|
5653
|
+
pageTurnDirection: `horizontal`,
|
|
5654
|
+
// computedPageTurnDirection: `horizontal`,
|
|
5655
|
+
pageTurnAnimationDuration: void 0,
|
|
5656
|
+
// computedPageTurnAnimationDuration: 0,
|
|
5657
|
+
pageTurnMode: `controlled`,
|
|
5658
|
+
// computedPageTurnMode: `controlled`,
|
|
5659
|
+
snapAnimationDuration: 300,
|
|
5660
|
+
navigationSnapThreshold: 0.3,
|
|
5661
|
+
numberOfAdjacentSpineItemToPreLoad: 0
|
|
5662
|
+
};
|
|
5663
|
+
}
|
|
5664
|
+
update(settings) {
|
|
5665
|
+
const { commit } = this._prepareUpdate(settings);
|
|
5666
|
+
commit();
|
|
5590
5667
|
}
|
|
5591
5668
|
get settings() {
|
|
5592
|
-
return this.
|
|
5669
|
+
return this.outputSettings;
|
|
5593
5670
|
}
|
|
5594
5671
|
destroy() {
|
|
5595
|
-
this.
|
|
5672
|
+
this.outputSettingsUpdateSubject.complete();
|
|
5596
5673
|
}
|
|
5597
5674
|
}
|
|
5675
|
+
_context = new WeakMap();
|
|
5598
5676
|
class HookManager {
|
|
5599
5677
|
constructor() {
|
|
5600
5678
|
this._hooks = [];
|
|
@@ -5677,7 +5755,7 @@ const createReader = (inputSettings) => {
|
|
|
5677
5755
|
const viewportStateSubject = new BehaviorSubject(`free`);
|
|
5678
5756
|
const hookManager = new HookManager();
|
|
5679
5757
|
const context = new Context();
|
|
5680
|
-
const settingsManager = new
|
|
5758
|
+
const settingsManager = new ReaderSettingsManager(inputSettings, context);
|
|
5681
5759
|
const spineItemManager = createSpineItemManager({ context, settings: settingsManager });
|
|
5682
5760
|
const pagination = createPagination({ context, spineItemManager });
|
|
5683
5761
|
const elementSubject$ = new BehaviorSubject(void 0);
|
|
@@ -5789,9 +5867,9 @@ const createReader = (inputSettings) => {
|
|
|
5789
5867
|
takeUntil$1(context.destroy$)
|
|
5790
5868
|
).subscribe();
|
|
5791
5869
|
merge(context.state$, settingsManager.settings$).pipe(
|
|
5792
|
-
map
|
|
5793
|
-
withLatestFrom(context.state$),
|
|
5794
|
-
map
|
|
5870
|
+
map(() => void 0),
|
|
5871
|
+
withLatestFrom$1(context.state$),
|
|
5872
|
+
map(([, { hasVerticalWriting }]) => {
|
|
5795
5873
|
const manifest = context.manifest;
|
|
5796
5874
|
return {
|
|
5797
5875
|
hasVerticalWriting,
|
|
@@ -5801,7 +5879,7 @@ const createReader = (inputSettings) => {
|
|
|
5801
5879
|
};
|
|
5802
5880
|
}),
|
|
5803
5881
|
distinctUntilChanged(isShallowEqual),
|
|
5804
|
-
map
|
|
5882
|
+
map(
|
|
5805
5883
|
({
|
|
5806
5884
|
hasVerticalWriting,
|
|
5807
5885
|
renditionFlow,
|
|
@@ -5851,7 +5929,7 @@ const createReader = (inputSettings) => {
|
|
|
5851
5929
|
* have an effect.
|
|
5852
5930
|
* It can typically be used to hide a loading indicator.
|
|
5853
5931
|
*/
|
|
5854
|
-
loadStatus$: context.manifest$.pipe(map
|
|
5932
|
+
loadStatus$: context.manifest$.pipe(map((manifest) => manifest ? "ready" : "idle")),
|
|
5855
5933
|
/**
|
|
5856
5934
|
* Dispatched when a change in selection happens
|
|
5857
5935
|
*/
|
|
@@ -6041,7 +6119,7 @@ const createResourcesManager = (context) => {
|
|
|
6041
6119
|
return from(openDatabase(`prose-reader`)).pipe(
|
|
6042
6120
|
switchMap$1(
|
|
6043
6121
|
(db) => from(db.keys()).pipe(
|
|
6044
|
-
map
|
|
6122
|
+
map((keys) => keys.filter((key) => !key.toString().startsWith(uniqueID))),
|
|
6045
6123
|
switchMap$1((keysToRemove) => {
|
|
6046
6124
|
const promises = keysToRemove.map((key) => db.remove(key));
|
|
6047
6125
|
return from(Promise.all(promises));
|
|
@@ -6286,7 +6364,7 @@ const loadingEnhancer = (next) => (options) => {
|
|
|
6286
6364
|
}, {})
|
|
6287
6365
|
);
|
|
6288
6366
|
const updateEntriesLayout$ = (entries) => combineLatest([reader.spine.$.layout$, reader.theme.$.theme$]).pipe(
|
|
6289
|
-
map
|
|
6367
|
+
map(([, theme]) => ({
|
|
6290
6368
|
width: reader.context.state.visibleAreaRect.width,
|
|
6291
6369
|
theme
|
|
6292
6370
|
})),
|
|
@@ -6305,7 +6383,7 @@ const loadingEnhancer = (next) => (options) => {
|
|
|
6305
6383
|
})
|
|
6306
6384
|
);
|
|
6307
6385
|
const destroyEntries$ = (entries) => reader.spine.$.itemsBeforeDestroy$.pipe(
|
|
6308
|
-
map
|
|
6386
|
+
map(() => {
|
|
6309
6387
|
Object.values(entries).forEach((element) => element.remove());
|
|
6310
6388
|
return {};
|
|
6311
6389
|
})
|