@prose-reader/core 1.59.0 → 1.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/createReaderWithEnhancer.d.ts +4 -45
- 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/enhancers/pagination/spine.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1220 -507
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +1157 -444
- package/dist/index.umd.cjs.map +1 -1
- package/dist/pagination/pagination.d.ts +1 -1
- package/dist/reader.d.ts +2 -2
- package/dist/settings/ReaderSettingsManager.d.ts +20 -0
- package/dist/settings/SettingsInterface.d.ts +13 -0
- package/dist/settings/SettingsManager.d.ts +17 -11
- package/dist/settings/SettingsManagerOverload.d.ts +23 -0
- package/dist/settings/types.d.ts +6 -5
- package/dist/spine/cfiLocator.d.ts +3 -3
- package/dist/spine/createSpine.d.ts +2 -2
- package/dist/spine/locationResolver.d.ts +6 -6
- package/dist/spine/navigationResolver.d.ts +2 -2
- package/dist/spineItem/commonSpineItem.d.ts +3 -3
- package/dist/spineItem/createSpineItem.d.ts +3 -3
- package/dist/spineItem/frameItem/frameItem.d.ts +3 -4
- package/dist/spineItem/frameItem/loader.d.ts +3 -4
- package/dist/spineItem/navigationResolver.d.ts +3 -3
- package/dist/spineItem/prePaginatedSpineItem.d.ts +3 -3
- package/dist/spineItem/reflowableSpineItem.d.ts +3 -3
- package/dist/spineItemManager.d.ts +6 -6
- package/dist/types/reader.d.ts +4 -4
- package/dist/utils/objects.d.ts +1 -0
- package/dist/viewportNavigator/manualViewportNavigator.d.ts +2 -2
- package/dist/viewportNavigator/panViewportNavigator.d.ts +2 -2
- package/dist/viewportNavigator/scrollViewportNavigator.d.ts +2 -2
- package/dist/viewportNavigator/viewportNavigator.d.ts +4 -4
- package/package.json +3 -3
- package/dist/enhancers/fonts.d.ts +0 -19
- 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,5 @@
|
|
|
1
|
-
import { takeUntil, Subject,
|
|
2
|
-
import {
|
|
1
|
+
import { takeUntil, Subject, combineLatest, map as map$1, switchMap, merge, EMPTY, fromEvent, withLatestFrom, NEVER, Observable, of, scheduled, animationFrameScheduler, distinctUntilChanged as distinctUntilChanged$1, startWith as startWith$1, BehaviorSubject, filter as filter$1, debounceTime, combineLatestWith, tap as tap$1, shareReplay as shareReplay$1, from, interval, iif, identity, take as take$1, forkJoin } from "rxjs";
|
|
2
|
+
import { startWith, map, shareReplay, tap, pairwise, switchMap as switchMap$1, filter, take, distinctUntilChanged, takeUntil as takeUntil$1, skip, withLatestFrom as withLatestFrom$1, share, exhaustMap, mergeMap, catchError, debounce, debounceTime as debounceTime$1, delay } from "rxjs/operators";
|
|
3
3
|
import { parseContentType, detectMimeTypeFromName } from "@prose-reader/shared";
|
|
4
4
|
const chromeEnhancer = (next) => (options) => {
|
|
5
5
|
const reader = next(options);
|
|
@@ -72,21 +72,109 @@ const getBase64FromBlob = (data) => {
|
|
|
72
72
|
reader.readAsDataURL(data);
|
|
73
73
|
});
|
|
74
74
|
};
|
|
75
|
+
function shallowMergeIfDefined(obj1, obj2) {
|
|
76
|
+
const result = { ...obj1 };
|
|
77
|
+
for (const key in obj2) {
|
|
78
|
+
if (Object.prototype.hasOwnProperty.call(obj2, key)) {
|
|
79
|
+
const value = obj2[key];
|
|
80
|
+
if (value !== void 0 || !(key in obj1)) {
|
|
81
|
+
result[key] = value;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
class SettingsManagerOverload {
|
|
88
|
+
constructor(initialSettings, settingsManager) {
|
|
89
|
+
this.settingsManager = settingsManager;
|
|
90
|
+
const inputSettings = shallowMergeIfDefined(
|
|
91
|
+
this.getDefaultSettings(),
|
|
92
|
+
initialSettings
|
|
93
|
+
);
|
|
94
|
+
this.outputSettings = this.computeOutputSettings(inputSettings);
|
|
95
|
+
this.inputSettings = shallowMergeIfDefined(
|
|
96
|
+
this.getDefaultSettings(),
|
|
97
|
+
initialSettings
|
|
98
|
+
);
|
|
99
|
+
this.outputSettingsUpdateSubject = new Subject();
|
|
100
|
+
this.settings$ = combineLatest([
|
|
101
|
+
this.settingsManager.settings$,
|
|
102
|
+
this.outputSettingsUpdateSubject.pipe(startWith(this.outputSettings))
|
|
103
|
+
]).pipe(
|
|
104
|
+
map(([parentSettings, settings]) => ({ ...parentSettings, ...settings })),
|
|
105
|
+
shareReplay(1)
|
|
106
|
+
);
|
|
107
|
+
this.settings$.subscribe();
|
|
108
|
+
}
|
|
109
|
+
_prepareUpdate(settings) {
|
|
110
|
+
const parentInputSettings = this.getCleanedParentInputSettings(settings);
|
|
111
|
+
const parentManagerPreparedUpdate = this.settingsManager._prepareUpdate(parentInputSettings);
|
|
112
|
+
const inputSettings = shallowMergeIfDefined(this.inputSettings, settings);
|
|
113
|
+
const outputSettings = this.computeOutputSettings(inputSettings);
|
|
114
|
+
const hasChanged = this.hasSettingsChanged(outputSettings);
|
|
115
|
+
return {
|
|
116
|
+
hasChanged: hasChanged || parentManagerPreparedUpdate.hasChanged,
|
|
117
|
+
commit: () => {
|
|
118
|
+
this.inputSettings = inputSettings;
|
|
119
|
+
this.outputSettings = outputSettings;
|
|
120
|
+
if (!parentManagerPreparedUpdate.hasChanged && hasChanged) {
|
|
121
|
+
this.outputSettingsUpdateSubject.next(outputSettings);
|
|
122
|
+
}
|
|
123
|
+
const parentOutputSettings = parentManagerPreparedUpdate.commit();
|
|
124
|
+
return {
|
|
125
|
+
...parentOutputSettings,
|
|
126
|
+
...outputSettings
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
update(settings) {
|
|
132
|
+
const { commit } = this._prepareUpdate(settings);
|
|
133
|
+
commit();
|
|
134
|
+
}
|
|
135
|
+
get settings() {
|
|
136
|
+
return {
|
|
137
|
+
...this.settingsManager.settings,
|
|
138
|
+
...this.outputSettings
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
destroy() {
|
|
142
|
+
this.outputSettingsUpdateSubject.complete();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
let SettingsManager$2 = class SettingsManager extends SettingsManagerOverload {
|
|
146
|
+
computeOutputSettings(settings) {
|
|
147
|
+
return settings;
|
|
148
|
+
}
|
|
149
|
+
hasSettingsChanged(newOutputSettings) {
|
|
150
|
+
return !isShallowEqual(this.outputSettings, newOutputSettings);
|
|
151
|
+
}
|
|
152
|
+
getCleanedParentInputSettings(settings) {
|
|
153
|
+
const { fontJustification, fontScale, fontWeight, lineHeight, ...rest } = settings;
|
|
154
|
+
return rest;
|
|
155
|
+
}
|
|
156
|
+
getDefaultSettings() {
|
|
157
|
+
return {
|
|
158
|
+
fontScale: 1,
|
|
159
|
+
fontWeight: "publisher",
|
|
160
|
+
lineHeight: "publisher",
|
|
161
|
+
fontJustification: "publisher"
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
};
|
|
75
165
|
const fontsEnhancer = (next) => (options) => {
|
|
76
|
-
const {
|
|
77
|
-
fontScale = 1,
|
|
78
|
-
lineHeight = `publisher`,
|
|
79
|
-
fontWeight = `publisher`,
|
|
80
|
-
fontJustification = `publisher`
|
|
81
|
-
} = options;
|
|
166
|
+
const { fontScale, lineHeight, fontWeight, fontJustification } = options;
|
|
82
167
|
const changes$ = new Subject();
|
|
83
|
-
const settings$ = new BehaviorSubject({
|
|
84
|
-
fontScale,
|
|
85
|
-
lineHeight,
|
|
86
|
-
fontWeight,
|
|
87
|
-
fontJustification
|
|
88
|
-
});
|
|
89
168
|
const reader = next(options);
|
|
169
|
+
const settingsManager = new SettingsManager$2(
|
|
170
|
+
{
|
|
171
|
+
fontScale,
|
|
172
|
+
lineHeight,
|
|
173
|
+
fontWeight,
|
|
174
|
+
fontJustification
|
|
175
|
+
},
|
|
176
|
+
reader.settings
|
|
177
|
+
);
|
|
90
178
|
const getStyle = () => `
|
|
91
179
|
${/*
|
|
92
180
|
Ideally, we would like to use !important but it could break publisher specific
|
|
@@ -98,10 +186,10 @@ const fontsEnhancer = (next) => (options) => {
|
|
|
98
186
|
*/
|
|
99
187
|
``}
|
|
100
188
|
body {
|
|
101
|
-
${settings
|
|
102
|
-
${settings
|
|
103
|
-
${settings
|
|
104
|
-
${settings
|
|
189
|
+
${settingsManager.settings.fontScale !== 1 ? `font-size: ${settingsManager.settings.fontScale}em !important;` : ``}
|
|
190
|
+
${settingsManager.settings.lineHeight !== `publisher` ? `line-height: ${settingsManager.settings.lineHeight} !important;` : ``}
|
|
191
|
+
${settingsManager.settings.fontWeight !== `publisher` ? `font-weight: ${settingsManager.settings.fontWeight} !important;` : ``}
|
|
192
|
+
${settingsManager.settings.fontJustification !== `publisher` ? `text-align: ${settingsManager.settings.fontJustification} !important;` : ``}
|
|
105
193
|
}
|
|
106
194
|
`;
|
|
107
195
|
const applyChangeToSpineItem = (requireLayout) => {
|
|
@@ -125,55 +213,32 @@ const fontsEnhancer = (next) => (options) => {
|
|
|
125
213
|
});
|
|
126
214
|
const shouldRequireLayout = (source) => source.pipe(
|
|
127
215
|
pairwise(),
|
|
128
|
-
map(([old, latest]) => {
|
|
216
|
+
map$1(([old, latest]) => {
|
|
129
217
|
if (latest.fontScale !== old.fontScale) return true;
|
|
130
218
|
if (latest.lineHeight !== old.lineHeight) return true;
|
|
131
219
|
return false;
|
|
132
220
|
})
|
|
133
221
|
);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
};
|
|
222
|
+
settingsManager.settings$.pipe(
|
|
223
|
+
shouldRequireLayout,
|
|
224
|
+
tap(applyChangeToSpineItem),
|
|
225
|
+
takeUntil(reader.$.destroy$)
|
|
226
|
+
).subscribe();
|
|
158
227
|
return {
|
|
159
228
|
...reader,
|
|
160
229
|
destroy: () => {
|
|
161
230
|
changes$.complete();
|
|
162
|
-
|
|
231
|
+
settingsManager.destroy();
|
|
163
232
|
reader.destroy();
|
|
164
233
|
},
|
|
165
|
-
settings:
|
|
166
|
-
...reader.settings,
|
|
167
|
-
setSettings,
|
|
168
|
-
settings$: settingsMerge$
|
|
169
|
-
}
|
|
234
|
+
settings: settingsManager
|
|
170
235
|
};
|
|
171
236
|
};
|
|
172
237
|
const hotkeysEnhancer = (next) => (options) => {
|
|
173
238
|
const reader = next(options);
|
|
174
239
|
const navigateOnKey = (document2) => fromEvent(document2, "keyup").pipe(
|
|
175
|
-
withLatestFrom
|
|
176
|
-
map(([e, { pageTurnDirection }]) => {
|
|
240
|
+
withLatestFrom(reader.settings.settings$),
|
|
241
|
+
map$1(([e, { pageTurnDirection }]) => {
|
|
177
242
|
if (pageTurnDirection === "horizontal") {
|
|
178
243
|
if (e.key === `ArrowRight`) {
|
|
179
244
|
reader.viewportNavigator.turnRight();
|
|
@@ -199,7 +264,9 @@ const hotkeysEnhancer = (next) => (options) => {
|
|
|
199
264
|
(spineItems) => merge(
|
|
200
265
|
...spineItems.map(
|
|
201
266
|
(item) => item.$.loaded$.pipe(
|
|
202
|
-
switchMap(
|
|
267
|
+
switchMap(
|
|
268
|
+
(iframe) => (iframe == null ? void 0 : iframe.contentDocument) ? navigateOnKey(iframe.contentDocument) : EMPTY
|
|
269
|
+
)
|
|
203
270
|
)
|
|
204
271
|
)
|
|
205
272
|
)
|
|
@@ -233,19 +300,29 @@ const createMovingSafePan$ = (reader) => {
|
|
|
233
300
|
);
|
|
234
301
|
const createResetLock$ = (source) => scheduled(source, animationFrameScheduler).pipe(
|
|
235
302
|
tap(() => {
|
|
236
|
-
iframeOverlayForAnimationsElement == null ? void 0 : iframeOverlayForAnimationsElement.style.setProperty(
|
|
303
|
+
iframeOverlayForAnimationsElement == null ? void 0 : iframeOverlayForAnimationsElement.style.setProperty(
|
|
304
|
+
`visibility`,
|
|
305
|
+
`hidden`
|
|
306
|
+
);
|
|
237
307
|
})
|
|
238
308
|
);
|
|
239
|
-
const viewportFree$ = reader.viewportNavigator.$.state$.pipe(
|
|
240
|
-
|
|
309
|
+
const viewportFree$ = reader.viewportNavigator.$.state$.pipe(
|
|
310
|
+
filter((data) => data === `free`)
|
|
311
|
+
);
|
|
312
|
+
const viewportBusy$ = reader.viewportNavigator.$.state$.pipe(
|
|
313
|
+
filter((data) => data === `busy`)
|
|
314
|
+
);
|
|
241
315
|
const lockAfterViewportBusy$ = viewportBusy$.pipe(
|
|
242
316
|
tap(() => {
|
|
243
|
-
iframeOverlayForAnimationsElement == null ? void 0 : iframeOverlayForAnimationsElement.style.setProperty(
|
|
317
|
+
iframeOverlayForAnimationsElement == null ? void 0 : iframeOverlayForAnimationsElement.style.setProperty(
|
|
318
|
+
`visibility`,
|
|
319
|
+
`visible`
|
|
320
|
+
);
|
|
244
321
|
})
|
|
245
322
|
);
|
|
246
323
|
const resetLockViewportFree$ = createResetLock$(viewportFree$).pipe(take(1));
|
|
247
324
|
const pageTurnMode$ = reader.settings.settings$.pipe(
|
|
248
|
-
map
|
|
325
|
+
map(() => reader.settings.settings.computedPageTurnMode),
|
|
249
326
|
distinctUntilChanged()
|
|
250
327
|
);
|
|
251
328
|
const handleViewportLock$ = pageTurnMode$.pipe(
|
|
@@ -257,7 +334,7 @@ const createMovingSafePan$ = (reader) => {
|
|
|
257
334
|
return merge(updateOverlayElement$, handleViewportLock$);
|
|
258
335
|
};
|
|
259
336
|
const mapKeysTo = (keys) => {
|
|
260
|
-
return map
|
|
337
|
+
return map((obj) => {
|
|
261
338
|
return Object.entries(obj).reduce(
|
|
262
339
|
(acc, [key, entry]) => {
|
|
263
340
|
if (keys.includes(key)) {
|
|
@@ -273,33 +350,70 @@ const mapKeysTo = (keys) => {
|
|
|
273
350
|
});
|
|
274
351
|
};
|
|
275
352
|
const fixReflowable = (reader) => {
|
|
276
|
-
reader.hookManager.register(
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
353
|
+
reader.hookManager.register(
|
|
354
|
+
`item.onAfterLayout`,
|
|
355
|
+
({ item, blankPagePosition, minimumWidth }) => {
|
|
356
|
+
var _a;
|
|
357
|
+
const spineItem = reader.spineItemManager.get(item.id);
|
|
358
|
+
if (!((spineItem == null ? void 0 : spineItem.item.renditionLayout) === `reflowable`)) return;
|
|
359
|
+
const { viewportDimensions } = (spineItem == null ? void 0 : spineItem.getViewPortInformation()) ?? {};
|
|
360
|
+
const { width: pageWidth } = reader.context.getPageSize();
|
|
361
|
+
const frameElement = (_a = spineItem == null ? void 0 : spineItem.spineItemFrame.getManipulableFrame()) == null ? void 0 : _a.frame;
|
|
362
|
+
if (viewportDimensions) {
|
|
363
|
+
const spineManagerWantAFullWidthItem = pageWidth < minimumWidth;
|
|
364
|
+
const noBlankPageAsked = blankPagePosition === `none`;
|
|
365
|
+
if (noBlankPageAsked && spineManagerWantAFullWidthItem) {
|
|
366
|
+
frameElement == null ? void 0 : frameElement.style.setProperty(
|
|
367
|
+
`left`,
|
|
368
|
+
reader.context.isRTL() ? `75%` : `25%`
|
|
369
|
+
);
|
|
370
|
+
}
|
|
288
371
|
}
|
|
289
372
|
}
|
|
290
|
-
|
|
373
|
+
);
|
|
291
374
|
};
|
|
292
375
|
function isDefined(arg) {
|
|
293
376
|
return arg !== null && arg !== void 0;
|
|
294
377
|
}
|
|
378
|
+
let SettingsManager$1 = class SettingsManager2 extends SettingsManagerOverload {
|
|
379
|
+
computeOutputSettings(inputSettings) {
|
|
380
|
+
return inputSettings;
|
|
381
|
+
}
|
|
382
|
+
hasSettingsChanged(newOutputSettings) {
|
|
383
|
+
return !isShallowEqual(this.outputSettings, newOutputSettings);
|
|
384
|
+
}
|
|
385
|
+
getCleanedParentInputSettings(settings) {
|
|
386
|
+
const {
|
|
387
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
388
|
+
layoutAutoResize,
|
|
389
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
390
|
+
pageHorizontalMargin,
|
|
391
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
392
|
+
pageVerticalMargin,
|
|
393
|
+
...rest
|
|
394
|
+
} = settings;
|
|
395
|
+
return rest;
|
|
396
|
+
}
|
|
397
|
+
getDefaultSettings() {
|
|
398
|
+
return {
|
|
399
|
+
layoutAutoResize: "container",
|
|
400
|
+
pageHorizontalMargin: 24,
|
|
401
|
+
pageVerticalMargin: 24
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
};
|
|
295
405
|
const SHOULD_NOT_LAYOUT = false;
|
|
296
406
|
const layoutEnhancer = (next) => (options) => {
|
|
297
|
-
const { pageHorizontalMargin
|
|
407
|
+
const { pageHorizontalMargin, pageVerticalMargin, layoutAutoResize } = options;
|
|
298
408
|
const reader = next(options);
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
409
|
+
const settingsManager = new SettingsManager$1(
|
|
410
|
+
{
|
|
411
|
+
pageHorizontalMargin,
|
|
412
|
+
pageVerticalMargin,
|
|
413
|
+
layoutAutoResize
|
|
414
|
+
},
|
|
415
|
+
reader.settings
|
|
416
|
+
);
|
|
303
417
|
reader.hookManager.register(`onViewportOffsetAdjust`, () => {
|
|
304
418
|
let hasRedrawn = false;
|
|
305
419
|
reader.spine.manipulateSpineItems(({ frame }) => {
|
|
@@ -310,24 +424,26 @@ const layoutEnhancer = (next) => (options) => {
|
|
|
310
424
|
return SHOULD_NOT_LAYOUT;
|
|
311
425
|
});
|
|
312
426
|
});
|
|
313
|
-
reader.hookManager.register(
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
`prose-layout-enhancer-css
|
|
330
|
-
|
|
427
|
+
reader.hookManager.register(
|
|
428
|
+
`item.onLayoutBeforeMeasurement`,
|
|
429
|
+
({ frame, minimumWidth, item, isImageType }) => {
|
|
430
|
+
var _a, _b;
|
|
431
|
+
const { pageHorizontalMargin: pageHorizontalMargin2 = 0, pageVerticalMargin: pageVerticalMargin2 = 0 } = settingsManager.settings;
|
|
432
|
+
const pageSize = reader.context.getPageSize();
|
|
433
|
+
if (item.renditionLayout === `reflowable` && frame.getIsReady() && !isImageType() && !frame.getViewportDimensions()) {
|
|
434
|
+
let columnWidth = pageSize.width - pageHorizontalMargin2 * 2;
|
|
435
|
+
const columnHeight = pageSize.height - pageVerticalMargin2 * 2;
|
|
436
|
+
let width = pageSize.width - pageHorizontalMargin2 * 2;
|
|
437
|
+
let columnGap = pageHorizontalMargin2 * 2;
|
|
438
|
+
if (frame.isUsingVerticalWriting()) {
|
|
439
|
+
width = minimumWidth - pageHorizontalMargin2 * 2;
|
|
440
|
+
columnWidth = columnHeight;
|
|
441
|
+
columnGap = pageVerticalMargin2 * 2;
|
|
442
|
+
}
|
|
443
|
+
(_a = frame.getManipulableFrame()) == null ? void 0 : _a.removeStyle(`prose-layout-enhancer-css`);
|
|
444
|
+
(_b = frame.getManipulableFrame()) == null ? void 0 : _b.addStyle(
|
|
445
|
+
`prose-layout-enhancer-css`,
|
|
446
|
+
`
|
|
331
447
|
body {
|
|
332
448
|
width: ${width}px !important;
|
|
333
449
|
margin: ${pageVerticalMargin2}px ${pageHorizontalMargin2}px !important;
|
|
@@ -346,14 +462,15 @@ const layoutEnhancer = (next) => (options) => {
|
|
|
346
462
|
max-width: ${columnWidth}px;
|
|
347
463
|
}
|
|
348
464
|
`
|
|
349
|
-
|
|
465
|
+
);
|
|
466
|
+
}
|
|
350
467
|
}
|
|
351
|
-
|
|
468
|
+
);
|
|
352
469
|
fixReflowable(reader);
|
|
353
470
|
let observer;
|
|
354
471
|
if (options.layoutAutoResize === `container`) {
|
|
355
472
|
reader.context.state$.pipe(
|
|
356
|
-
map
|
|
473
|
+
map((state) => state.containerElement),
|
|
357
474
|
filter(isDefined),
|
|
358
475
|
distinctUntilChanged(),
|
|
359
476
|
takeUntil$1(reader.$.destroy$)
|
|
@@ -366,7 +483,7 @@ const layoutEnhancer = (next) => (options) => {
|
|
|
366
483
|
}
|
|
367
484
|
const movingSafePan$ = createMovingSafePan$(reader);
|
|
368
485
|
movingSafePan$.subscribe();
|
|
369
|
-
|
|
486
|
+
settingsManager.settings$.pipe(
|
|
370
487
|
mapKeysTo([`pageHorizontalMargin`, `pageVerticalMargin`]),
|
|
371
488
|
distinctUntilChanged(isShallowEqual),
|
|
372
489
|
skip(1),
|
|
@@ -375,32 +492,14 @@ const layoutEnhancer = (next) => (options) => {
|
|
|
375
492
|
}),
|
|
376
493
|
takeUntil$1(reader.$.destroy$)
|
|
377
494
|
).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
495
|
return {
|
|
394
496
|
...reader,
|
|
395
497
|
destroy: () => {
|
|
498
|
+
settingsManager.destroy();
|
|
396
499
|
reader.destroy();
|
|
397
500
|
observer == null ? void 0 : observer.disconnect();
|
|
398
501
|
},
|
|
399
|
-
settings:
|
|
400
|
-
...reader.settings,
|
|
401
|
-
setSettings,
|
|
402
|
-
settings$
|
|
403
|
-
}
|
|
502
|
+
settings: settingsManager
|
|
404
503
|
};
|
|
405
504
|
};
|
|
406
505
|
const ROOT_NAMESPACE = `@prose-reader/core`;
|
|
@@ -417,7 +516,10 @@ const time = (name, targetDuration = 0) => {
|
|
|
417
516
|
return () => {
|
|
418
517
|
tick++;
|
|
419
518
|
const t1 = performance.now();
|
|
420
|
-
Report.logMetric(
|
|
519
|
+
Report.logMetric(
|
|
520
|
+
{ name: `${name} - tick ${tick}`, duration: t1 - t0 },
|
|
521
|
+
targetDuration
|
|
522
|
+
);
|
|
421
523
|
};
|
|
422
524
|
};
|
|
423
525
|
const createReport = (namespace) => ({
|
|
@@ -433,7 +535,8 @@ const createReport = (namespace) => ({
|
|
|
433
535
|
warn: (...data) => {
|
|
434
536
|
var _a;
|
|
435
537
|
if ((_a = getWindow()) == null ? void 0 : _a.__PROSE_READER_DEBUG) {
|
|
436
|
-
if (namespace)
|
|
538
|
+
if (namespace)
|
|
539
|
+
console.warn(wrap(ROOT_NAMESPACE), wrap(namespace), ...data);
|
|
437
540
|
else console.warn(wrap(ROOT_NAMESPACE), ...data);
|
|
438
541
|
}
|
|
439
542
|
},
|
|
@@ -498,7 +601,9 @@ const linksEnhancer = (next) => (options) => {
|
|
|
498
601
|
if (!element.href) return false;
|
|
499
602
|
const hrefUrl = new URL(element.href);
|
|
500
603
|
const hrefWithoutAnchor = `${hrefUrl.origin}${hrefUrl.pathname}`;
|
|
501
|
-
const hasExistingSpineItem = (_a = reader.context.manifest) == null ? void 0 : _a.spineItems.some(
|
|
604
|
+
const hasExistingSpineItem = (_a = reader.context.manifest) == null ? void 0 : _a.spineItems.some(
|
|
605
|
+
(item) => item.href === hrefWithoutAnchor
|
|
606
|
+
);
|
|
502
607
|
if (hasExistingSpineItem) {
|
|
503
608
|
reader.viewportNavigator.goToUrl(hrefUrl);
|
|
504
609
|
return true;
|
|
@@ -513,7 +618,11 @@ const linksEnhancer = (next) => (options) => {
|
|
|
513
618
|
Report.warn(`prevented click on`, element, e);
|
|
514
619
|
e.preventDefault();
|
|
515
620
|
const isNavigable = handleNavigationForClick(element);
|
|
516
|
-
subject.next({
|
|
621
|
+
subject.next({
|
|
622
|
+
event: `linkClicked`,
|
|
623
|
+
data: element,
|
|
624
|
+
isNavigable
|
|
625
|
+
});
|
|
517
626
|
}
|
|
518
627
|
})
|
|
519
628
|
);
|
|
@@ -554,14 +663,16 @@ const createNavigator = (reader) => {
|
|
|
554
663
|
goToNextSpineItem,
|
|
555
664
|
goToPreviousSpineItem,
|
|
556
665
|
goToLeftSpineItem: () => {
|
|
557
|
-
if (reader.settings.settings.computedPageTurnDirection === "vertical")
|
|
666
|
+
if (reader.settings.settings.computedPageTurnDirection === "vertical")
|
|
667
|
+
return;
|
|
558
668
|
if (reader.context.isRTL()) {
|
|
559
669
|
return goToNextSpineItem();
|
|
560
670
|
}
|
|
561
671
|
return goToPreviousSpineItem();
|
|
562
672
|
},
|
|
563
673
|
goToRightSpineItem: () => {
|
|
564
|
-
if (reader.settings.settings.computedPageTurnDirection === "vertical")
|
|
674
|
+
if (reader.settings.settings.computedPageTurnDirection === "vertical")
|
|
675
|
+
return;
|
|
565
676
|
if (reader.context.isRTL()) {
|
|
566
677
|
return goToPreviousSpineItem();
|
|
567
678
|
}
|
|
@@ -571,8 +682,8 @@ const createNavigator = (reader) => {
|
|
|
571
682
|
};
|
|
572
683
|
const createState = (reader) => {
|
|
573
684
|
return reader.pagination.paginationInfo$.pipe(
|
|
574
|
-
withLatestFrom
|
|
575
|
-
map(([paginationInfo, manifest, { computedPageTurnDirection }]) => {
|
|
685
|
+
withLatestFrom(reader.context.manifest$, reader.settings.settings$),
|
|
686
|
+
map$1(([paginationInfo, manifest, { computedPageTurnDirection }]) => {
|
|
576
687
|
const numberOfSpineItems = (manifest == null ? void 0 : manifest.spineItems.length) ?? 0;
|
|
577
688
|
const isAtAbsoluteBeginning = paginationInfo.beginSpineItemIndex === 0 && paginationInfo.beginPageIndexInSpineItem === 0;
|
|
578
689
|
const isAtAbsoluteEnd = paginationInfo.endPageIndexInSpineItem === paginationInfo.endNumberOfPagesInSpineItem - 1 && paginationInfo.endSpineItemIndex === Math.max(numberOfSpineItems - 1, 0);
|
|
@@ -599,17 +710,24 @@ const navigationEnhancer = (next) => (options) => {
|
|
|
599
710
|
};
|
|
600
711
|
};
|
|
601
712
|
const buildChaptersInfo = (href, tocItem, manifest) => {
|
|
602
|
-
const spineItemIndex = manifest.spineItems.findIndex(
|
|
713
|
+
const spineItemIndex = manifest.spineItems.findIndex(
|
|
714
|
+
(item) => item.href === href
|
|
715
|
+
);
|
|
603
716
|
return tocItem.reduce((acc, tocItem2) => {
|
|
604
717
|
const indexOfHash = tocItem2.href.indexOf(`#`);
|
|
605
718
|
const tocItemPathWithoutAnchor = indexOfHash > 0 ? tocItem2.href.substr(0, indexOfHash) : tocItem2.href;
|
|
606
|
-
const tocItemHrefWithoutFilename = tocItemPathWithoutAnchor.substring(
|
|
719
|
+
const tocItemHrefWithoutFilename = tocItemPathWithoutAnchor.substring(
|
|
720
|
+
0,
|
|
721
|
+
tocItemPathWithoutAnchor.lastIndexOf("/")
|
|
722
|
+
);
|
|
607
723
|
const hrefWithoutFilename = href.substring(0, href.lastIndexOf("/"));
|
|
608
724
|
const hrefIsChapterHref = href.endsWith(tocItemPathWithoutAnchor);
|
|
609
725
|
const hrefIsWithinChapter = hrefWithoutFilename !== "" && hrefWithoutFilename.endsWith(tocItemHrefWithoutFilename);
|
|
610
726
|
const isPossibleTocItemCandidate = hrefIsChapterHref || hrefIsWithinChapter;
|
|
611
727
|
if (isPossibleTocItemCandidate) {
|
|
612
|
-
const spineItemIndexOfPossibleCandidate = manifest.spineItems.findIndex(
|
|
728
|
+
const spineItemIndexOfPossibleCandidate = manifest.spineItems.findIndex(
|
|
729
|
+
(item) => item.href === tocItem2.href
|
|
730
|
+
);
|
|
613
731
|
const spineItemIsBeforeThisTocItem = spineItemIndex < spineItemIndexOfPossibleCandidate;
|
|
614
732
|
if (spineItemIsBeforeThisTocItem) return acc;
|
|
615
733
|
const info = {
|
|
@@ -649,12 +767,14 @@ const getChaptersInfo = (reader) => {
|
|
|
649
767
|
};
|
|
650
768
|
const trackChapterInfo = (reader) => {
|
|
651
769
|
return reader.spine.$.spineItems$.pipe(
|
|
652
|
-
startWith([]),
|
|
653
|
-
map(() => getChaptersInfo(reader))
|
|
770
|
+
startWith$1([]),
|
|
771
|
+
map$1(() => getChaptersInfo(reader))
|
|
654
772
|
);
|
|
655
773
|
};
|
|
656
774
|
const NAMESPACE$6 = `pagination`;
|
|
657
|
-
const createPagination = ({
|
|
775
|
+
const createPagination = ({
|
|
776
|
+
context
|
|
777
|
+
}) => {
|
|
658
778
|
const paginationSubject$ = new BehaviorSubject({
|
|
659
779
|
beginPageIndexInSpineItem: void 0,
|
|
660
780
|
beginNumberOfPagesInSpineItem: 0,
|
|
@@ -707,7 +827,9 @@ const createPagination = ({ context }) => {
|
|
|
707
827
|
const getPaginationInfo = () => paginationSubject$.value;
|
|
708
828
|
const paginationInfo$ = paginationSubject$.pipe(
|
|
709
829
|
distinctUntilChanged$1(isShallowEqual),
|
|
710
|
-
filter$1(
|
|
830
|
+
filter$1(
|
|
831
|
+
({ beginPageIndexInSpineItem }) => beginPageIndexInSpineItem !== void 0
|
|
832
|
+
)
|
|
711
833
|
);
|
|
712
834
|
const destroy = () => {
|
|
713
835
|
paginationSubject$.complete();
|
|
@@ -731,10 +853,14 @@ const calculateNumberOfPagesForItem = (itemWidth, pageWidth) => {
|
|
|
731
853
|
const getClosestValidOffsetFromApproximateOffsetInPages = (offset, pageWidth, itemWidth) => {
|
|
732
854
|
const numberOfPages = calculateNumberOfPagesForItem(itemWidth, pageWidth);
|
|
733
855
|
const offsetValues = [...Array(numberOfPages)].map((_, i) => i * pageWidth);
|
|
734
|
-
if (offset >= numberOfPages * pageWidth)
|
|
856
|
+
if (offset >= numberOfPages * pageWidth)
|
|
857
|
+
return offsetValues[offsetValues.length - 1] || 0;
|
|
735
858
|
return offsetValues.find((offsetRange) => offset < offsetRange + pageWidth) || 0;
|
|
736
859
|
};
|
|
737
|
-
const getSpineItemNumberOfPages = ({
|
|
860
|
+
const getSpineItemNumberOfPages = ({
|
|
861
|
+
spineItem,
|
|
862
|
+
reader
|
|
863
|
+
}) => {
|
|
738
864
|
const writingMode = spineItem.spineItemFrame.getWritingMode();
|
|
739
865
|
const { width, height } = spineItem.getElementDimensions();
|
|
740
866
|
const settings = reader.settings.settings;
|
|
@@ -742,9 +868,15 @@ const getSpineItemNumberOfPages = ({ spineItem, reader }) => {
|
|
|
742
868
|
return 1;
|
|
743
869
|
}
|
|
744
870
|
if (writingMode === `vertical-rl`) {
|
|
745
|
-
return calculateNumberOfPagesForItem(
|
|
871
|
+
return calculateNumberOfPagesForItem(
|
|
872
|
+
height,
|
|
873
|
+
reader.context.getPageSize().height
|
|
874
|
+
);
|
|
746
875
|
}
|
|
747
|
-
return calculateNumberOfPagesForItem(
|
|
876
|
+
return calculateNumberOfPagesForItem(
|
|
877
|
+
width,
|
|
878
|
+
reader.context.getPageSize().width
|
|
879
|
+
);
|
|
748
880
|
};
|
|
749
881
|
const getNumberOfPagesForAllSpineItems = (reader) => reader.spineItemManager.getAll().map((item) => {
|
|
750
882
|
return getSpineItemNumberOfPages({ spineItem: item, reader });
|
|
@@ -752,19 +884,22 @@ const getNumberOfPagesForAllSpineItems = (reader) => reader.spineItemManager.get
|
|
|
752
884
|
const trackTotalPages = (reader) => {
|
|
753
885
|
const totalPages$ = reader.spine.$.layout$.pipe(
|
|
754
886
|
debounceTime(10, animationFrameScheduler),
|
|
755
|
-
withLatestFrom
|
|
756
|
-
map(() => {
|
|
887
|
+
withLatestFrom(reader.pagination.paginationInfo$),
|
|
888
|
+
map$1(() => {
|
|
757
889
|
const numberOfPagesPerItems = getNumberOfPagesForAllSpineItems(reader);
|
|
758
890
|
return {
|
|
759
891
|
numberOfPagesPerItems,
|
|
760
892
|
/**
|
|
761
893
|
* This may be not accurate for reflowable due to dynamic load / unload.
|
|
762
894
|
*/
|
|
763
|
-
numberOfTotalPages: numberOfPagesPerItems.reduce(
|
|
895
|
+
numberOfTotalPages: numberOfPagesPerItems.reduce(
|
|
896
|
+
(acc, numberOfPagesForItem) => acc + numberOfPagesForItem,
|
|
897
|
+
0
|
|
898
|
+
)
|
|
764
899
|
};
|
|
765
900
|
}),
|
|
766
901
|
distinctUntilChanged$1(isShallowEqual),
|
|
767
|
-
startWith({
|
|
902
|
+
startWith$1({
|
|
768
903
|
numberOfPagesPerItems: [],
|
|
769
904
|
numberOfTotalPages: 0
|
|
770
905
|
})
|
|
@@ -817,14 +952,17 @@ const trackPaginationInfo = (reader) => {
|
|
|
817
952
|
const totalPages$ = trackTotalPages(reader);
|
|
818
953
|
const currentValue = new BehaviorSubject({
|
|
819
954
|
...reader.pagination.getPaginationInfo(),
|
|
820
|
-
...mapPaginationInfoToExtendedInfo(reader)(
|
|
955
|
+
...mapPaginationInfoToExtendedInfo(reader)(
|
|
956
|
+
reader.pagination.getPaginationInfo(),
|
|
957
|
+
getChaptersInfo(reader)
|
|
958
|
+
),
|
|
821
959
|
beginAbsolutePageIndex: 0,
|
|
822
960
|
endAbsolutePageIndex: 0,
|
|
823
961
|
numberOfTotalPages: 0
|
|
824
962
|
});
|
|
825
963
|
const extandedBasePagination$ = reader.pagination.paginationInfo$.pipe(
|
|
826
964
|
combineLatestWith(chaptersInfo$),
|
|
827
|
-
map(([info, chaptersInfo]) => ({
|
|
965
|
+
map$1(([info, chaptersInfo]) => ({
|
|
828
966
|
...info,
|
|
829
967
|
...mapPaginationInfoToExtendedInfo(reader)(info, chaptersInfo)
|
|
830
968
|
})),
|
|
@@ -834,11 +972,17 @@ const trackPaginationInfo = (reader) => {
|
|
|
834
972
|
extandedBasePagination$,
|
|
835
973
|
totalPages$
|
|
836
974
|
]).pipe(
|
|
837
|
-
map(([pageInfo, totalPageInfo]) => ({
|
|
975
|
+
map$1(([pageInfo, totalPageInfo]) => ({
|
|
838
976
|
...pageInfo,
|
|
839
977
|
...totalPageInfo,
|
|
840
|
-
beginAbsolutePageIndex: totalPageInfo.numberOfPagesPerItems.slice(0, pageInfo.beginSpineItemIndex).reduce(
|
|
841
|
-
|
|
978
|
+
beginAbsolutePageIndex: totalPageInfo.numberOfPagesPerItems.slice(0, pageInfo.beginSpineItemIndex).reduce(
|
|
979
|
+
(acc, numberOfPagesForItem) => acc + numberOfPagesForItem,
|
|
980
|
+
pageInfo.beginPageIndexInSpineItem ?? 0
|
|
981
|
+
),
|
|
982
|
+
endAbsolutePageIndex: totalPageInfo.numberOfPagesPerItems.slice(0, pageInfo.endSpineItemIndex).reduce(
|
|
983
|
+
(acc, numberOfPagesForItem) => acc + numberOfPagesForItem,
|
|
984
|
+
pageInfo.endPageIndexInSpineItem ?? 0
|
|
985
|
+
)
|
|
842
986
|
})),
|
|
843
987
|
tap$1((value) => {
|
|
844
988
|
currentValue.next(value);
|
|
@@ -880,9 +1024,13 @@ const defaultThemes = [
|
|
|
880
1024
|
];
|
|
881
1025
|
const themeEnhancer = (next) => (options) => {
|
|
882
1026
|
const reader = next(options);
|
|
883
|
-
const currentThemeSubject$ = new BehaviorSubject(
|
|
1027
|
+
const currentThemeSubject$ = new BehaviorSubject(
|
|
1028
|
+
options.theme ?? `bright`
|
|
1029
|
+
);
|
|
884
1030
|
const getStyle = () => {
|
|
885
|
-
const foundTheme = defaultThemes.find(
|
|
1031
|
+
const foundTheme = defaultThemes.find(
|
|
1032
|
+
(entry) => entry.name === currentThemeSubject$.value
|
|
1033
|
+
);
|
|
886
1034
|
return `
|
|
887
1035
|
body {
|
|
888
1036
|
${foundTheme !== void 0 ? `background-color: ${foundTheme.backgroundColor} !important;` : ``}
|
|
@@ -899,21 +1047,30 @@ const themeEnhancer = (next) => (options) => {
|
|
|
899
1047
|
` : ``}
|
|
900
1048
|
`;
|
|
901
1049
|
};
|
|
902
|
-
const applyChangeToSpineItemElement = ({
|
|
903
|
-
|
|
1050
|
+
const applyChangeToSpineItemElement = ({
|
|
1051
|
+
container
|
|
1052
|
+
}) => {
|
|
1053
|
+
const foundTheme = defaultThemes.find(
|
|
1054
|
+
(entry) => entry.name === currentThemeSubject$.value
|
|
1055
|
+
);
|
|
904
1056
|
if (foundTheme) {
|
|
905
|
-
container.style.setProperty(
|
|
1057
|
+
container.style.setProperty(
|
|
1058
|
+
`background-color`,
|
|
1059
|
+
foundTheme.backgroundColor
|
|
1060
|
+
);
|
|
906
1061
|
}
|
|
907
1062
|
return () => {
|
|
908
1063
|
};
|
|
909
1064
|
};
|
|
910
1065
|
const applyChangeToSpineItem = () => {
|
|
911
|
-
reader.spine.manipulateSpineItems(
|
|
912
|
-
removeStyle
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
1066
|
+
reader.spine.manipulateSpineItems(
|
|
1067
|
+
({ removeStyle, addStyle, container }) => {
|
|
1068
|
+
removeStyle(`prose-reader-theme`);
|
|
1069
|
+
addStyle(`prose-reader-theme`, getStyle());
|
|
1070
|
+
applyChangeToSpineItemElement({ container });
|
|
1071
|
+
return false;
|
|
1072
|
+
}
|
|
1073
|
+
);
|
|
917
1074
|
};
|
|
918
1075
|
reader.hookManager.register(`item.onLoad`, ({ itemId }) => {
|
|
919
1076
|
const item = reader.spineItemManager.get(itemId);
|
|
@@ -924,7 +1081,11 @@ const themeEnhancer = (next) => (options) => {
|
|
|
924
1081
|
});
|
|
925
1082
|
});
|
|
926
1083
|
reader.spine.$.spineItems$.pipe(
|
|
927
|
-
tap(
|
|
1084
|
+
tap(
|
|
1085
|
+
(items) => items.map(
|
|
1086
|
+
({ element }) => applyChangeToSpineItemElement({ container: element })
|
|
1087
|
+
)
|
|
1088
|
+
),
|
|
928
1089
|
takeUntil$1(reader.$.destroy$)
|
|
929
1090
|
).subscribe();
|
|
930
1091
|
currentThemeSubject$.pipe(
|
|
@@ -991,7 +1152,9 @@ const createElementZoomer = (reader) => {
|
|
|
991
1152
|
};
|
|
992
1153
|
const scale = (userScale) => {
|
|
993
1154
|
const imgElement = imageMagnifierContainer == null ? void 0 : imageMagnifierContainer.querySelector(`img`);
|
|
994
|
-
const roundedScale = Math.ceil(
|
|
1155
|
+
const roundedScale = Math.ceil(
|
|
1156
|
+
(userScale < 1 ? baseScale - (1 - userScale) : baseScale + (userScale - 1)) * 100
|
|
1157
|
+
) / 100;
|
|
995
1158
|
const newScale = Math.max(roundedScale, 1);
|
|
996
1159
|
if (roundedScale < 1) {
|
|
997
1160
|
imgLastPosition = { x: 0, y: 0 };
|
|
@@ -1087,7 +1250,9 @@ const createViewportZoomer = (reader) => {
|
|
|
1087
1250
|
const spineElement = reader.spine.getElement();
|
|
1088
1251
|
const viewportElement = reader.viewportNavigator.getElement();
|
|
1089
1252
|
if (!spineElement || !viewportElement) return;
|
|
1090
|
-
const roundedScale = Math.ceil(
|
|
1253
|
+
const roundedScale = Math.ceil(
|
|
1254
|
+
(userScale < 1 ? baseScale - (1 - userScale) : baseScale + (userScale - 1)) * 100
|
|
1255
|
+
) / 100;
|
|
1091
1256
|
const newScale = Math.max(roundedScale, 1);
|
|
1092
1257
|
const currentScale = spineElement.getBoundingClientRect().width / spineElement.offsetWidth;
|
|
1093
1258
|
const currentScrollTop = viewportElement.scrollTop;
|
|
@@ -1196,7 +1361,9 @@ const zoomEnhancer = (next) => (options) => {
|
|
|
1196
1361
|
isUsingScrollableZoom: isUsingScrollableViewport,
|
|
1197
1362
|
setCurrentScaleAsBase,
|
|
1198
1363
|
$: {
|
|
1199
|
-
isZooming$: currentZoomerSubject$.pipe(
|
|
1364
|
+
isZooming$: currentZoomerSubject$.pipe(
|
|
1365
|
+
switchMap((zoomer) => (zoomer == null ? void 0 : zoomer.isZooming$) || of(false))
|
|
1366
|
+
)
|
|
1200
1367
|
}
|
|
1201
1368
|
}
|
|
1202
1369
|
};
|
|
@@ -1233,22 +1400,22 @@ class Context {
|
|
|
1233
1400
|
this.destroy$ = new Subject();
|
|
1234
1401
|
this.state$ = this._stateSubject.pipe(distinctUntilChanged(isShallowEqual));
|
|
1235
1402
|
this.manifest$ = this._stateSubject.pipe(
|
|
1236
|
-
map
|
|
1403
|
+
map((state) => state.manifest),
|
|
1237
1404
|
filter(isDefined),
|
|
1238
1405
|
distinctUntilChanged()
|
|
1239
1406
|
);
|
|
1240
1407
|
this.containerElement$ = this._stateSubject.pipe(
|
|
1241
|
-
map
|
|
1408
|
+
map((state) => state.containerElement),
|
|
1242
1409
|
filter(isDefined),
|
|
1243
1410
|
distinctUntilChanged()
|
|
1244
1411
|
);
|
|
1245
1412
|
this.hasVerticalWriting$ = this._stateSubject.pipe(
|
|
1246
|
-
map
|
|
1413
|
+
map((state) => state.hasVerticalWriting),
|
|
1247
1414
|
filter(isDefined),
|
|
1248
1415
|
distinctUntilChanged()
|
|
1249
1416
|
);
|
|
1250
1417
|
this.isUsingSpreadMode$ = this._stateSubject.pipe(
|
|
1251
|
-
map
|
|
1418
|
+
map((state) => state.isUsingSpreadMode),
|
|
1252
1419
|
distinctUntilChanged()
|
|
1253
1420
|
);
|
|
1254
1421
|
this.isRTL = () => {
|
|
@@ -1343,15 +1510,21 @@ const getOriginalFrameEventFromDocumentEvent = (event) => {
|
|
|
1343
1510
|
return event[__UNSAFE_REFERENCE_ORIGINAL_IFRAME_EVENT_KEY];
|
|
1344
1511
|
};
|
|
1345
1512
|
const attachOriginalFrameEventToDocumentEvent = (event, frameEvent) => {
|
|
1346
|
-
Object.defineProperty(event, __UNSAFE_REFERENCE_ORIGINAL_IFRAME_EVENT_KEY, {
|
|
1513
|
+
Object.defineProperty(event, __UNSAFE_REFERENCE_ORIGINAL_IFRAME_EVENT_KEY, {
|
|
1514
|
+
value: frameEvent,
|
|
1515
|
+
enumerable: true
|
|
1516
|
+
});
|
|
1347
1517
|
};
|
|
1348
|
-
const createFrame$ = Report.measurePerformance(
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1518
|
+
const createFrame$ = Report.measurePerformance(
|
|
1519
|
+
`SpineItemFrame createFrame`,
|
|
1520
|
+
Infinity,
|
|
1521
|
+
() => {
|
|
1522
|
+
const frame = document.createElement(`iframe`);
|
|
1523
|
+
frame.frameBorder = `no`;
|
|
1524
|
+
frame.tabIndex = 0;
|
|
1525
|
+
frame.setAttribute(`sandbox`, `allow-same-origin allow-scripts`);
|
|
1526
|
+
frame.scrolling = `no`;
|
|
1527
|
+
frame.style.cssText = `
|
|
1355
1528
|
visibility: hidden;
|
|
1356
1529
|
overflow: hidden;
|
|
1357
1530
|
background-color: transparent;
|
|
@@ -1360,8 +1533,9 @@ const createFrame$ = Report.measurePerformance(`SpineItemFrame createFrame`, Inf
|
|
|
1360
1533
|
transition: opacity 300ms;
|
|
1361
1534
|
opacity: 0;
|
|
1362
1535
|
`;
|
|
1363
|
-
|
|
1364
|
-
}
|
|
1536
|
+
return of(frame);
|
|
1537
|
+
}
|
|
1538
|
+
);
|
|
1365
1539
|
const getIntrinsicDimensionsFromBase64Img = (data) => new Promise((resolve, reject) => {
|
|
1366
1540
|
const image = new Image();
|
|
1367
1541
|
image.src = data;
|
|
@@ -1373,7 +1547,9 @@ const getIntrinsicDimensionsFromBase64Img = (data) => new Promise((resolve, reje
|
|
|
1373
1547
|
const createHtmlPageFromResource = async (resourceResponse, item) => {
|
|
1374
1548
|
if (typeof resourceResponse === `string`) return resourceResponse;
|
|
1375
1549
|
const contentType = parseContentType(resourceResponse.headers.get(`Content-Type`) || ``) || detectMimeTypeFromName(item.href);
|
|
1376
|
-
if ([`image/jpg`, `image/jpeg`, `image/png`, `image/webp`].some(
|
|
1550
|
+
if ([`image/jpg`, `image/jpeg`, `image/png`, `image/webp`].some(
|
|
1551
|
+
(mime) => mime === contentType
|
|
1552
|
+
)) {
|
|
1377
1553
|
const data = await getBase64FromBlob(await resourceResponse.blob());
|
|
1378
1554
|
const { height, width } = await getIntrinsicDimensionsFromBase64Img(data);
|
|
1379
1555
|
return `
|
|
@@ -1416,7 +1592,6 @@ const createHtmlPageFromResource = async (resourceResponse, item) => {
|
|
|
1416
1592
|
const createLoader = ({
|
|
1417
1593
|
item,
|
|
1418
1594
|
parent,
|
|
1419
|
-
fetchResource,
|
|
1420
1595
|
context,
|
|
1421
1596
|
viewportState$,
|
|
1422
1597
|
settings,
|
|
@@ -1441,9 +1616,9 @@ const createLoader = ({
|
|
|
1441
1616
|
const unload$ = unloadSubject$.asObservable().pipe(
|
|
1442
1617
|
// @todo remove iframe when viewport is free
|
|
1443
1618
|
// @todo use takeUntil(load$) when it's the case to cancel
|
|
1444
|
-
withLatestFrom(frameElementSubject$),
|
|
1619
|
+
withLatestFrom$1(frameElementSubject$),
|
|
1445
1620
|
filter(([_, frame]) => !!frame),
|
|
1446
|
-
map
|
|
1621
|
+
map(([, frame]) => {
|
|
1447
1622
|
hookManager.destroy(`item.onLoad`, item.id);
|
|
1448
1623
|
frame == null ? void 0 : frame.remove();
|
|
1449
1624
|
frameElementSubject$.next(void 0);
|
|
@@ -1452,18 +1627,26 @@ const createLoader = ({
|
|
|
1452
1627
|
takeUntil$1(destroySubject$)
|
|
1453
1628
|
);
|
|
1454
1629
|
const load$ = loadSubject$.asObservable().pipe(
|
|
1455
|
-
withLatestFrom(isLoadedSubject$),
|
|
1630
|
+
withLatestFrom$1(isLoadedSubject$),
|
|
1456
1631
|
filter(([_, isLoaded]) => !isLoaded),
|
|
1457
1632
|
// let's ignore later load as long as the first one still runs
|
|
1458
1633
|
exhaustMap(() => {
|
|
1459
1634
|
return createFrame$().pipe(
|
|
1460
|
-
mergeMap((frame) => waitForViewportFree$.pipe(map
|
|
1635
|
+
mergeMap((frame) => waitForViewportFree$.pipe(map(() => frame))),
|
|
1461
1636
|
mergeMap((frame) => {
|
|
1462
1637
|
parent.appendChild(frame);
|
|
1463
1638
|
frameElementSubject$.next(frame);
|
|
1639
|
+
const { fetchResource } = settings.settings;
|
|
1464
1640
|
if (!fetchResource && item.href.startsWith(window.location.origin) && // we have an encoding and it's a valid html
|
|
1465
|
-
(item.mediaType && [
|
|
1466
|
-
|
|
1641
|
+
(item.mediaType && [
|
|
1642
|
+
`application/xhtml+xml`,
|
|
1643
|
+
`application/xml`,
|
|
1644
|
+
`text/html`,
|
|
1645
|
+
`text/xml`
|
|
1646
|
+
].includes(item.mediaType) || // no encoding ? then try to detect html
|
|
1647
|
+
!item.mediaType && ITEM_EXTENSION_VALID_FOR_FRAME_SRC.some(
|
|
1648
|
+
(extension) => item.href.endsWith(extension)
|
|
1649
|
+
))) {
|
|
1467
1650
|
frame == null ? void 0 : frame.setAttribute(`src`, item.href);
|
|
1468
1651
|
return of(frame);
|
|
1469
1652
|
} else {
|
|
@@ -1475,9 +1658,11 @@ const createLoader = ({
|
|
|
1475
1658
|
frame == null ? void 0 : frame.setAttribute(`srcdoc`, htmlDoc);
|
|
1476
1659
|
}
|
|
1477
1660
|
}),
|
|
1478
|
-
map
|
|
1661
|
+
map(() => frame),
|
|
1479
1662
|
catchError((e) => {
|
|
1480
|
-
Report.error(
|
|
1663
|
+
Report.error(
|
|
1664
|
+
`Error while trying to fetch or load resource for item ${item.id}`
|
|
1665
|
+
);
|
|
1481
1666
|
console.error(e);
|
|
1482
1667
|
return of(frame);
|
|
1483
1668
|
})
|
|
@@ -1505,8 +1690,12 @@ const createLoader = ({
|
|
|
1505
1690
|
const hookResults = hookManager.execute(`item.onLoad`, item.id, {
|
|
1506
1691
|
itemId: item.id,
|
|
1507
1692
|
frame
|
|
1508
|
-
}).filter(
|
|
1509
|
-
|
|
1693
|
+
}).filter(
|
|
1694
|
+
(result) => result instanceof Observable
|
|
1695
|
+
);
|
|
1696
|
+
return combineLatest([of(null), ...hookResults]).pipe(
|
|
1697
|
+
map(() => frame)
|
|
1698
|
+
);
|
|
1510
1699
|
})
|
|
1511
1700
|
);
|
|
1512
1701
|
}),
|
|
@@ -1519,16 +1708,20 @@ const createLoader = ({
|
|
|
1519
1708
|
takeUntil$1(destroySubject$)
|
|
1520
1709
|
);
|
|
1521
1710
|
const ready$ = load$.pipe(
|
|
1522
|
-
switchMap$1(
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1711
|
+
switchMap$1(
|
|
1712
|
+
(frame) => {
|
|
1713
|
+
var _a;
|
|
1714
|
+
return from(((_a = frame == null ? void 0 : frame.contentDocument) == null ? void 0 : _a.fonts.ready) || of(void 0)).pipe(
|
|
1715
|
+
takeUntil$1(unloadSubject$)
|
|
1716
|
+
);
|
|
1717
|
+
}
|
|
1718
|
+
),
|
|
1526
1719
|
share(),
|
|
1527
1720
|
makeItHot,
|
|
1528
1721
|
takeUntil$1(destroySubject$)
|
|
1529
1722
|
);
|
|
1530
|
-
merge(load$.pipe(map
|
|
1531
|
-
merge(ready$.pipe(map
|
|
1723
|
+
merge(load$.pipe(map(() => true)), unloadSubject$.pipe(map(() => false))).pipe(distinctUntilChanged(), takeUntil$1(destroySubject$)).subscribe(isLoadedSubject$);
|
|
1724
|
+
merge(ready$.pipe(map(() => true)), unloadSubject$.pipe(map(() => false))).pipe(distinctUntilChanged(), takeUntil$1(destroySubject$)).subscribe(isReadySubject$);
|
|
1532
1725
|
unload$.subscribe();
|
|
1533
1726
|
return {
|
|
1534
1727
|
load: () => loadSubject$.next(),
|
|
@@ -1563,7 +1756,6 @@ const createFrameManipulator = (frameElement) => ({
|
|
|
1563
1756
|
const createFrameItem = ({
|
|
1564
1757
|
item,
|
|
1565
1758
|
parent,
|
|
1566
|
-
fetchResource,
|
|
1567
1759
|
context,
|
|
1568
1760
|
viewportState$,
|
|
1569
1761
|
settings,
|
|
@@ -1571,12 +1763,27 @@ const createFrameItem = ({
|
|
|
1571
1763
|
}) => {
|
|
1572
1764
|
const destroySubject$ = new Subject();
|
|
1573
1765
|
const {
|
|
1574
|
-
$: {
|
|
1766
|
+
$: {
|
|
1767
|
+
unload$,
|
|
1768
|
+
loaded$,
|
|
1769
|
+
isLoaded$,
|
|
1770
|
+
isReady$,
|
|
1771
|
+
unloaded$,
|
|
1772
|
+
frameElement$,
|
|
1773
|
+
ready$
|
|
1774
|
+
},
|
|
1575
1775
|
load,
|
|
1576
1776
|
unload,
|
|
1577
1777
|
destroy: loaderDestroy,
|
|
1578
1778
|
getComputedStyleAfterLoad
|
|
1579
|
-
} = createLoader({
|
|
1779
|
+
} = createLoader({
|
|
1780
|
+
context,
|
|
1781
|
+
hookManager,
|
|
1782
|
+
item,
|
|
1783
|
+
parent,
|
|
1784
|
+
viewportState$,
|
|
1785
|
+
settings
|
|
1786
|
+
});
|
|
1580
1787
|
let isLoadedSync = false;
|
|
1581
1788
|
let isReadySync = false;
|
|
1582
1789
|
isLoaded$.subscribe({
|
|
@@ -1604,7 +1811,10 @@ const createFrameItem = ({
|
|
|
1604
1811
|
const viewPortMetaInfos = viewPortMeta.getAttribute(`content`);
|
|
1605
1812
|
if (viewPortMetaInfos) {
|
|
1606
1813
|
const width = getAttributeValueFromString(viewPortMetaInfos, `width`);
|
|
1607
|
-
const height = getAttributeValueFromString(
|
|
1814
|
+
const height = getAttributeValueFromString(
|
|
1815
|
+
viewPortMetaInfos,
|
|
1816
|
+
`height`
|
|
1817
|
+
);
|
|
1608
1818
|
if (width > 0 && height > 0) {
|
|
1609
1819
|
return {
|
|
1610
1820
|
width,
|
|
@@ -1630,8 +1840,8 @@ const createFrameItem = ({
|
|
|
1630
1840
|
return createHtmlPageFromResource(response, item);
|
|
1631
1841
|
};
|
|
1632
1842
|
const contentLayoutChange$ = merge(
|
|
1633
|
-
unloaded$.pipe(map
|
|
1634
|
-
ready$.pipe(map
|
|
1843
|
+
unloaded$.pipe(map(() => ({ isFirstLayout: false }))),
|
|
1844
|
+
ready$.pipe(map(() => ({ isFirstLayout: true })))
|
|
1635
1845
|
);
|
|
1636
1846
|
const destroy = () => {
|
|
1637
1847
|
unload();
|
|
@@ -1679,7 +1889,8 @@ const createFrameItem = ({
|
|
|
1679
1889
|
return `rtl`;
|
|
1680
1890
|
}
|
|
1681
1891
|
const direction = (_a = getComputedStyleAfterLoad()) == null ? void 0 : _a.direction;
|
|
1682
|
-
if ([`ltr`, `rtl`].includes(direction || ``))
|
|
1892
|
+
if ([`ltr`, `rtl`].includes(direction || ``))
|
|
1893
|
+
return direction;
|
|
1683
1894
|
return void 0;
|
|
1684
1895
|
},
|
|
1685
1896
|
isUsingVerticalWriting,
|
|
@@ -1751,7 +1962,10 @@ const createSelectionTracker = () => {
|
|
|
1751
1962
|
});
|
|
1752
1963
|
(_a = frameToTrack.contentDocument) == null ? void 0 : _a.addEventListener(`selectionchange`, () => {
|
|
1753
1964
|
var _a2;
|
|
1754
|
-
subject.next({
|
|
1965
|
+
subject.next({
|
|
1966
|
+
event: `selectionchange`,
|
|
1967
|
+
data: ((_a2 = frame == null ? void 0 : frame.contentWindow) == null ? void 0 : _a2.getSelection()) || null
|
|
1968
|
+
});
|
|
1755
1969
|
});
|
|
1756
1970
|
(_b = frameToTrack.contentWindow) == null ? void 0 : _b.addEventListener(`selectstart`, () => {
|
|
1757
1971
|
isSelecting = true;
|
|
@@ -1766,7 +1980,8 @@ const createSelectionTracker = () => {
|
|
|
1766
1980
|
getSelection: () => {
|
|
1767
1981
|
var _a;
|
|
1768
1982
|
const selection = (_a = frame == null ? void 0 : frame.contentWindow) == null ? void 0 : _a.getSelection();
|
|
1769
|
-
if (!(selection == null ? void 0 : selection.anchorNode) || selection.type === `None` || selection.type === `Caret`)
|
|
1983
|
+
if (!(selection == null ? void 0 : selection.anchorNode) || selection.type === `None` || selection.type === `Caret`)
|
|
1984
|
+
return void 0;
|
|
1770
1985
|
return selection;
|
|
1771
1986
|
},
|
|
1772
1987
|
$: subject.asObservable()
|
|
@@ -1781,7 +1996,11 @@ const createCommonSpineItem = ({
|
|
|
1781
1996
|
hookManager
|
|
1782
1997
|
}) => {
|
|
1783
1998
|
const destroySubject$ = new Subject();
|
|
1784
|
-
const containerElement = createContainerElement$1(
|
|
1999
|
+
const containerElement = createContainerElement$1(
|
|
2000
|
+
parentElement,
|
|
2001
|
+
item,
|
|
2002
|
+
hookManager
|
|
2003
|
+
);
|
|
1785
2004
|
const overlayElement = createOverlayElement(parentElement, item);
|
|
1786
2005
|
const fingerTracker = createFingerTracker();
|
|
1787
2006
|
const selectionTracker = createSelectionTracker();
|
|
@@ -1820,7 +2039,11 @@ const createCommonSpineItem = ({
|
|
|
1820
2039
|
(_a = spineItemFrame.getManipulableFrame()) == null ? void 0 : _a.removeStyle(`prose-reader-css`);
|
|
1821
2040
|
(_b = spineItemFrame.getManipulableFrame()) == null ? void 0 : _b.addStyle(`prose-reader-css`, cssText);
|
|
1822
2041
|
};
|
|
1823
|
-
const adjustPositionOfElement = ({
|
|
2042
|
+
const adjustPositionOfElement = ({
|
|
2043
|
+
right,
|
|
2044
|
+
left,
|
|
2045
|
+
top
|
|
2046
|
+
}) => {
|
|
1824
2047
|
if (right !== void 0) {
|
|
1825
2048
|
containerElement.style.right = `${right}px`;
|
|
1826
2049
|
} else {
|
|
@@ -1844,7 +2067,10 @@ const createCommonSpineItem = ({
|
|
|
1844
2067
|
const frameElement = (_a = spineItemFrame.getManipulableFrame()) == null ? void 0 : _a.frame;
|
|
1845
2068
|
if (containerElement && (frameElement == null ? void 0 : frameElement.contentDocument) && (frameElement == null ? void 0 : frameElement.contentWindow) && viewportDimensions) {
|
|
1846
2069
|
const computedWidthScale = pageWidth / viewportDimensions.width;
|
|
1847
|
-
const computedScale = Math.min(
|
|
2070
|
+
const computedScale = Math.min(
|
|
2071
|
+
computedWidthScale,
|
|
2072
|
+
pageHeight / viewportDimensions.height
|
|
2073
|
+
);
|
|
1848
2074
|
return { computedScale, computedWidthScale, viewportDimensions };
|
|
1849
2075
|
}
|
|
1850
2076
|
};
|
|
@@ -1897,7 +2123,11 @@ const createCommonSpineItem = ({
|
|
|
1897
2123
|
}) => {
|
|
1898
2124
|
containerElement.style.width = `${width}px`;
|
|
1899
2125
|
containerElement.style.height = `${height}px`;
|
|
1900
|
-
hookManager.execute(`item.onAfterLayout`, void 0, {
|
|
2126
|
+
hookManager.execute(`item.onAfterLayout`, void 0, {
|
|
2127
|
+
blankPagePosition,
|
|
2128
|
+
item,
|
|
2129
|
+
minimumWidth
|
|
2130
|
+
});
|
|
1901
2131
|
setLayoutDirty();
|
|
1902
2132
|
};
|
|
1903
2133
|
const translateFramePositionIntoPage = (position) => {
|
|
@@ -1950,8 +2180,8 @@ const createCommonSpineItem = ({
|
|
|
1950
2180
|
...options
|
|
1951
2181
|
});
|
|
1952
2182
|
const contentLayout$ = spineItemFrame.$.contentLayoutChange$.pipe(
|
|
1953
|
-
withLatestFrom(spineItemFrame.$.isReady$),
|
|
1954
|
-
map
|
|
2183
|
+
withLatestFrom$1(spineItemFrame.$.isReady$),
|
|
2184
|
+
map(([data, isReady]) => ({
|
|
1955
2185
|
isFirstLayout: data.isFirstLayout,
|
|
1956
2186
|
isReady
|
|
1957
2187
|
}))
|
|
@@ -2111,8 +2341,14 @@ const createPrePaginatedSpineItem = ({
|
|
|
2111
2341
|
}
|
|
2112
2342
|
const transformTranslateX = spreadPosition !== `none` ? `0` : `-50%`;
|
|
2113
2343
|
const transformOriginX = spreadPosition === `right` && blankPagePosition !== `before` ? `left` : spreadPosition === `left` || blankPagePosition === `before` && context.isRTL() ? `right` : `center`;
|
|
2114
|
-
frameElement == null ? void 0 : frameElement.style.setProperty(
|
|
2115
|
-
|
|
2344
|
+
frameElement == null ? void 0 : frameElement.style.setProperty(
|
|
2345
|
+
`transform`,
|
|
2346
|
+
`translate(${transformTranslateX}, -50%) scale(${computedScale})`
|
|
2347
|
+
);
|
|
2348
|
+
frameElement == null ? void 0 : frameElement.style.setProperty(
|
|
2349
|
+
`transform-origin`,
|
|
2350
|
+
`${transformOriginX} center`
|
|
2351
|
+
);
|
|
2116
2352
|
commonSpineItem.executeOnLayoutBeforeMeasurementHook({ minimumWidth });
|
|
2117
2353
|
} else {
|
|
2118
2354
|
commonSpineItem.injectStyle(cssLink);
|
|
@@ -2132,11 +2368,21 @@ const createPrePaginatedSpineItem = ({
|
|
|
2132
2368
|
}
|
|
2133
2369
|
}
|
|
2134
2370
|
commonSpineItem.executeOnLayoutBeforeMeasurementHook({ minimumWidth });
|
|
2135
|
-
commonSpineItem.layout({
|
|
2371
|
+
commonSpineItem.layout({
|
|
2372
|
+
width: minimumWidth,
|
|
2373
|
+
height: contentHeight,
|
|
2374
|
+
blankPagePosition,
|
|
2375
|
+
minimumWidth
|
|
2376
|
+
});
|
|
2136
2377
|
return { width: minimumWidth, height: contentHeight };
|
|
2137
2378
|
} else {
|
|
2138
2379
|
commonSpineItem.executeOnLayoutBeforeMeasurementHook({ minimumWidth });
|
|
2139
|
-
commonSpineItem.layout({
|
|
2380
|
+
commonSpineItem.layout({
|
|
2381
|
+
width: minimumWidth,
|
|
2382
|
+
height: pageHeight,
|
|
2383
|
+
blankPagePosition,
|
|
2384
|
+
minimumWidth
|
|
2385
|
+
});
|
|
2140
2386
|
}
|
|
2141
2387
|
return { width: minimumWidth, height: pageHeight };
|
|
2142
2388
|
};
|
|
@@ -2265,19 +2511,27 @@ const createReflowableSpineItem = ({
|
|
|
2265
2511
|
`left`,
|
|
2266
2512
|
blankPagePosition === `before` ? context.isRTL() ? `25%` : `75%` : blankPagePosition === `after` ? context.isRTL() ? `75%` : `25%` : `50%`
|
|
2267
2513
|
);
|
|
2268
|
-
frameElement == null ? void 0 : frameElement.style.setProperty(
|
|
2514
|
+
frameElement == null ? void 0 : frameElement.style.setProperty(
|
|
2515
|
+
`transform`,
|
|
2516
|
+
`translate(-50%, -50%) scale(${computedScale})`
|
|
2517
|
+
);
|
|
2269
2518
|
frameElement == null ? void 0 : frameElement.style.setProperty(`transform-origin`, `center center`);
|
|
2270
2519
|
} else {
|
|
2271
2520
|
const frameStyle = commonSpineItem.isImageType() ? buildStyleForReflowableImageOnly({
|
|
2272
2521
|
isScrollable: ((_g = context.manifest) == null ? void 0 : _g.renditionFlow) === `scrolled-continuous`,
|
|
2273
2522
|
enableTouch: settings.settings.computedPageTurnMode !== `scrollable`
|
|
2274
2523
|
}) : buildStyleWithMultiColumn(
|
|
2275
|
-
commonSpineItem.getDimensionsForReflowableContent(
|
|
2524
|
+
commonSpineItem.getDimensionsForReflowableContent(
|
|
2525
|
+
spineItemFrame.isUsingVerticalWriting(),
|
|
2526
|
+
minimumWidth
|
|
2527
|
+
)
|
|
2276
2528
|
);
|
|
2277
2529
|
commonSpineItem.injectStyle(frameStyle);
|
|
2278
2530
|
commonSpineItem.executeOnLayoutBeforeMeasurementHook({ minimumWidth });
|
|
2279
2531
|
if (spineItemFrame.isUsingVerticalWriting()) {
|
|
2280
|
-
const pages = Math.ceil(
|
|
2532
|
+
const pages = Math.ceil(
|
|
2533
|
+
frameElement.contentDocument.documentElement.scrollHeight / pageHeight
|
|
2534
|
+
);
|
|
2281
2535
|
contentHeight = pages * pageHeight;
|
|
2282
2536
|
spineItemFrame.staticLayout({
|
|
2283
2537
|
width: minimumWidth,
|
|
@@ -2291,7 +2545,9 @@ const createReflowableSpineItem = ({
|
|
|
2291
2545
|
height: contentHeight
|
|
2292
2546
|
});
|
|
2293
2547
|
} else {
|
|
2294
|
-
const pages = Math.ceil(
|
|
2548
|
+
const pages = Math.ceil(
|
|
2549
|
+
frameElement.contentDocument.documentElement.scrollWidth / pageWidth
|
|
2550
|
+
);
|
|
2295
2551
|
if (isGloballyPrePaginated) {
|
|
2296
2552
|
contentWidth = pageWidth;
|
|
2297
2553
|
} else {
|
|
@@ -2312,13 +2568,23 @@ const createReflowableSpineItem = ({
|
|
|
2312
2568
|
} else {
|
|
2313
2569
|
frameElement == null ? void 0 : frameElement.style.setProperty(`margin-left`, `0px`);
|
|
2314
2570
|
}
|
|
2315
|
-
commonSpineItem.layout({
|
|
2571
|
+
commonSpineItem.layout({
|
|
2572
|
+
width: contentWidth,
|
|
2573
|
+
height: contentHeight,
|
|
2574
|
+
blankPagePosition,
|
|
2575
|
+
minimumWidth
|
|
2576
|
+
});
|
|
2316
2577
|
return { width: contentWidth, height: contentHeight };
|
|
2317
2578
|
} else {
|
|
2318
2579
|
commonSpineItem.executeOnLayoutBeforeMeasurementHook({ minimumWidth });
|
|
2319
2580
|
}
|
|
2320
2581
|
const height = latestContentHeightWhenLoaded || pageHeight;
|
|
2321
|
-
commonSpineItem.layout({
|
|
2582
|
+
commonSpineItem.layout({
|
|
2583
|
+
width: minimumWidth,
|
|
2584
|
+
height,
|
|
2585
|
+
blankPagePosition,
|
|
2586
|
+
minimumWidth
|
|
2587
|
+
});
|
|
2322
2588
|
return { width: minimumWidth, height };
|
|
2323
2589
|
};
|
|
2324
2590
|
return {
|
|
@@ -2638,7 +2904,10 @@ class CFI {
|
|
|
2638
2904
|
while (str.length) {
|
|
2639
2905
|
({ parsed, offset, newDoc } = this.parse(str));
|
|
2640
2906
|
if (!parsed || offset === null) throw new Error(`Parsing failed`);
|
|
2641
|
-
if (sawComma && newDoc)
|
|
2907
|
+
if (sawComma && newDoc)
|
|
2908
|
+
throw new Error(
|
|
2909
|
+
`CFI is a range that spans multiple documents. This is not allowed`
|
|
2910
|
+
);
|
|
2642
2911
|
subParts.push(parsed);
|
|
2643
2912
|
if (newDoc || str.length - offset <= 0) {
|
|
2644
2913
|
if (sawComma === 2) {
|
|
@@ -2706,7 +2975,8 @@ class CFI {
|
|
|
2706
2975
|
while (node.parentNode) {
|
|
2707
2976
|
o = calcSiblingCount(node.parentNode.childNodes, node, offset);
|
|
2708
2977
|
if (!cfi && o.offset) cfi = `:` + o.offset;
|
|
2709
|
-
cfi =
|
|
2978
|
+
cfi = // @ts-ignore
|
|
2979
|
+
`/` + o.count + (node.id ? `[` + cfiEscape(node.id) + `]` : ``) + cfi;
|
|
2710
2980
|
node = node.parentNode;
|
|
2711
2981
|
}
|
|
2712
2982
|
return cfi;
|
|
@@ -2809,7 +3079,8 @@ class CFI {
|
|
|
2809
3079
|
return this.decodeEntities(dom, str).length;
|
|
2810
3080
|
}
|
|
2811
3081
|
getFrom() {
|
|
2812
|
-
if (!this.isRange)
|
|
3082
|
+
if (!this.isRange)
|
|
3083
|
+
throw new Error(`Trying to get beginning of non-range CFI`);
|
|
2813
3084
|
if (!this.from) {
|
|
2814
3085
|
return this.deepClone(this.parts);
|
|
2815
3086
|
}
|
|
@@ -2994,10 +3265,13 @@ class CFI {
|
|
|
2994
3265
|
}
|
|
2995
3266
|
if (cur === `:` || cur === `~` || cur === `@`) {
|
|
2996
3267
|
if (this.opts.stricter) {
|
|
2997
|
-
if (cur === `:` &&
|
|
3268
|
+
if (cur === `:` && // @ts-ignore
|
|
3269
|
+
(typeof o.temporal !== `undefined` || // @ts-ignore
|
|
3270
|
+
typeof o.spatial !== `undefined`)) {
|
|
2998
3271
|
break;
|
|
2999
3272
|
}
|
|
3000
|
-
if ((cur === `~` || cur === `@`) &&
|
|
3273
|
+
if ((cur === `~` || cur === `@`) && // @ts-ignore
|
|
3274
|
+
typeof o.offset !== `undefined`) {
|
|
3001
3275
|
break;
|
|
3002
3276
|
}
|
|
3003
3277
|
}
|
|
@@ -3060,7 +3334,8 @@ class CFI {
|
|
|
3060
3334
|
}
|
|
3061
3335
|
escape = false;
|
|
3062
3336
|
}
|
|
3063
|
-
if (!o.nodeIndex && o.nodeIndex !== 0)
|
|
3337
|
+
if (!o.nodeIndex && o.nodeIndex !== 0)
|
|
3338
|
+
throw new Error(`Missing child node index in CFI`);
|
|
3064
3339
|
return { parsed: o, offset: i, newDoc: state === `!` };
|
|
3065
3340
|
}
|
|
3066
3341
|
// The CFI counts child nodes differently from the DOM
|
|
@@ -3098,7 +3373,11 @@ class CFI {
|
|
|
3098
3373
|
if (!lastChild) {
|
|
3099
3374
|
return { node: parentNode, offset: 0 };
|
|
3100
3375
|
}
|
|
3101
|
-
return {
|
|
3376
|
+
return {
|
|
3377
|
+
node: lastChild,
|
|
3378
|
+
// @ts-ignore
|
|
3379
|
+
offset: this.trueLength(dom, lastChild.textContent)
|
|
3380
|
+
};
|
|
3102
3381
|
}
|
|
3103
3382
|
}
|
|
3104
3383
|
lastChild = child;
|
|
@@ -3185,7 +3464,8 @@ class CFI {
|
|
|
3185
3464
|
newOffset -= nodeLengths[i];
|
|
3186
3465
|
if (newOffset < 0) return { node, offset };
|
|
3187
3466
|
const nodeOffsets = [];
|
|
3188
|
-
if (!curNode.nextSibling || i + 1 >= nodeOffsets.length)
|
|
3467
|
+
if (!curNode.nextSibling || i + 1 >= nodeOffsets.length)
|
|
3468
|
+
return { node, offset };
|
|
3189
3469
|
i++;
|
|
3190
3470
|
curNode = curNode.nextSibling;
|
|
3191
3471
|
}
|
|
@@ -3214,7 +3494,12 @@ class CFI {
|
|
|
3214
3494
|
let subpart;
|
|
3215
3495
|
for (i = subparts.length - 1; i >= 0; i--) {
|
|
3216
3496
|
subpart = subparts[i];
|
|
3217
|
-
if (
|
|
3497
|
+
if (
|
|
3498
|
+
// @ts-ignore
|
|
3499
|
+
!opts.ignoreIDs && // @ts-ignore
|
|
3500
|
+
subpart.nodeID && // @ts-ignore
|
|
3501
|
+
(node = dom.getElementById(subpart.nodeID))
|
|
3502
|
+
) {
|
|
3218
3503
|
startFrom = i + 1;
|
|
3219
3504
|
break;
|
|
3220
3505
|
}
|
|
@@ -3226,9 +3511,22 @@ class CFI {
|
|
|
3226
3511
|
for (i = startFrom; i < subparts.length; i++) {
|
|
3227
3512
|
subpart = subparts[i];
|
|
3228
3513
|
if (subpart) {
|
|
3229
|
-
o = this.getChildNodeByCFIIndex(
|
|
3514
|
+
o = this.getChildNodeByCFIIndex(
|
|
3515
|
+
dom,
|
|
3516
|
+
// @ts-ignore
|
|
3517
|
+
o.node,
|
|
3518
|
+
subpart.nodeIndex,
|
|
3519
|
+
subpart.offset
|
|
3520
|
+
);
|
|
3230
3521
|
if (subpart.textLocationAssertion) {
|
|
3231
|
-
o = this.correctOffset(
|
|
3522
|
+
o = this.correctOffset(
|
|
3523
|
+
dom,
|
|
3524
|
+
// @ts-ignore
|
|
3525
|
+
o.node,
|
|
3526
|
+
subpart.offset,
|
|
3527
|
+
// @ts-ignore
|
|
3528
|
+
subpart.textLocationAssertion
|
|
3529
|
+
);
|
|
3232
3530
|
}
|
|
3233
3531
|
}
|
|
3234
3532
|
}
|
|
@@ -3270,12 +3568,14 @@ class CFI {
|
|
|
3270
3568
|
}
|
|
3271
3569
|
if (tagName === `object`) {
|
|
3272
3570
|
const data = node.getAttribute(`data`);
|
|
3273
|
-
if (!data)
|
|
3571
|
+
if (!data)
|
|
3572
|
+
throw new Error(tagName + ` element is missing 'data' attribute`);
|
|
3274
3573
|
return data;
|
|
3275
3574
|
}
|
|
3276
3575
|
if (tagName === `image` || tagName === `use`) {
|
|
3277
3576
|
const href = node.getAttribute(`xlink:href`);
|
|
3278
|
-
if (!href)
|
|
3577
|
+
if (!href)
|
|
3578
|
+
throw new Error(tagName + ` element is missing 'xlink:href' attribute`);
|
|
3279
3579
|
return href;
|
|
3280
3580
|
}
|
|
3281
3581
|
throw new Error(`No URI found`);
|
|
@@ -3447,17 +3747,26 @@ const createSpine = ({
|
|
|
3447
3747
|
spineItemsFromPosition.beginPosition,
|
|
3448
3748
|
beginSpineItem
|
|
3449
3749
|
);
|
|
3450
|
-
const beginPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3750
|
+
const beginPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3751
|
+
beginPosition,
|
|
3752
|
+
beginSpineItem
|
|
3753
|
+
);
|
|
3451
3754
|
const endPosition = spineLocator.getSpineItemPositionFromSpinePosition(
|
|
3452
3755
|
spineItemsFromPosition.endPosition,
|
|
3453
3756
|
endSpineItem
|
|
3454
3757
|
);
|
|
3455
|
-
const endPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3758
|
+
const endPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3759
|
+
endPosition,
|
|
3760
|
+
endSpineItem
|
|
3761
|
+
);
|
|
3456
3762
|
pagination.updateBeginAndEnd(
|
|
3457
3763
|
{
|
|
3458
3764
|
spineItem: beginSpineItem,
|
|
3459
3765
|
spineItemIndex: spineItemManager.getSpineItemIndex(beginSpineItem) ?? 0,
|
|
3460
|
-
pageIndex: spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3766
|
+
pageIndex: spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3767
|
+
beginPosition,
|
|
3768
|
+
beginSpineItem
|
|
3769
|
+
),
|
|
3461
3770
|
cfi: shouldUpdateBeginCfi ? cfiLocator.getCfi(beginPageIndex, beginSpineItem) : beginLastCfi,
|
|
3462
3771
|
options: {
|
|
3463
3772
|
isAtEndOfChapter: false
|
|
@@ -3466,7 +3775,10 @@ const createSpine = ({
|
|
|
3466
3775
|
{
|
|
3467
3776
|
spineItem: endSpineItem,
|
|
3468
3777
|
spineItemIndex: spineItemManager.getSpineItemIndex(endSpineItem) ?? 0,
|
|
3469
|
-
pageIndex: spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3778
|
+
pageIndex: spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3779
|
+
endPosition,
|
|
3780
|
+
endSpineItem
|
|
3781
|
+
),
|
|
3470
3782
|
cfi: shouldUpdateEndCfi ? cfiLocator.getCfi(endPageIndex, endSpineItem) : endLastCfi,
|
|
3471
3783
|
options: {
|
|
3472
3784
|
isAtEndOfChapter: false
|
|
@@ -3503,7 +3815,11 @@ const createSpine = ({
|
|
|
3503
3815
|
() => fingerTracker$.pipe(
|
|
3504
3816
|
filter(({ event: event2 }) => event2 === `fingermove`),
|
|
3505
3817
|
debounce(() => interval(1e3)),
|
|
3506
|
-
takeUntil$1(
|
|
3818
|
+
takeUntil$1(
|
|
3819
|
+
fingerTracker$.pipe(
|
|
3820
|
+
filter(({ event: event2 }) => event2 === `fingerout`)
|
|
3821
|
+
)
|
|
3822
|
+
),
|
|
3507
3823
|
tap(({ data }) => {
|
|
3508
3824
|
})
|
|
3509
3825
|
)
|
|
@@ -3540,12 +3856,18 @@ const createSpine = ({
|
|
|
3540
3856
|
spineItemsFromPosition.beginPosition,
|
|
3541
3857
|
beginSpineItem
|
|
3542
3858
|
);
|
|
3543
|
-
const beginPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3859
|
+
const beginPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3860
|
+
beginPosition,
|
|
3861
|
+
beginSpineItem
|
|
3862
|
+
);
|
|
3544
3863
|
const endPosition = spineLocator.getSpineItemPositionFromSpinePosition(
|
|
3545
3864
|
spineItemsFromPosition.endPosition,
|
|
3546
3865
|
endSpineItem
|
|
3547
3866
|
);
|
|
3548
|
-
const endPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3867
|
+
const endPageIndex = spineItemLocator.getSpineItemPageIndexFromPosition(
|
|
3868
|
+
endPosition,
|
|
3869
|
+
endSpineItem
|
|
3870
|
+
);
|
|
3549
3871
|
const endItemIndex = spineItemManager.getSpineItemIndex(endSpineItem) ?? 0;
|
|
3550
3872
|
pagination.updateBeginAndEnd(
|
|
3551
3873
|
{
|
|
@@ -3604,7 +3926,9 @@ const createSpine = ({
|
|
|
3604
3926
|
);
|
|
3605
3927
|
itemUpdateOnNavigation$.pipe(
|
|
3606
3928
|
switchMap$1((data) => {
|
|
3607
|
-
return adjustPagination(data.position).pipe(
|
|
3929
|
+
return adjustPagination(data.position).pipe(
|
|
3930
|
+
takeUntil$1(spineItemManager.$.layout$)
|
|
3931
|
+
);
|
|
3608
3932
|
}),
|
|
3609
3933
|
takeUntil$1(context.destroy$)
|
|
3610
3934
|
).subscribe();
|
|
@@ -3623,15 +3947,25 @@ const createSpine = ({
|
|
|
3623
3947
|
).pipe(
|
|
3624
3948
|
switchMap$1(() => {
|
|
3625
3949
|
return waitForViewportFree$.pipe(
|
|
3626
|
-
withLatestFrom(currentNavigationPosition$),
|
|
3627
|
-
map
|
|
3950
|
+
withLatestFrom$1(currentNavigationPosition$),
|
|
3951
|
+
map(([, currentNavigationPosition]) => {
|
|
3628
3952
|
const focusedSpineItemIndex = spineItemManager.getFocusedSpineItemIndex();
|
|
3629
3953
|
report.log(`update contents`, { focusedSpineItemIndex });
|
|
3630
3954
|
if (focusedSpineItemIndex === void 0) return;
|
|
3631
|
-
const {
|
|
3955
|
+
const {
|
|
3956
|
+
begin = focusedSpineItemIndex,
|
|
3957
|
+
end = focusedSpineItemIndex
|
|
3958
|
+
} = spineLocator.getSpineItemsFromReadingOrderPosition(
|
|
3959
|
+
currentNavigationPosition
|
|
3960
|
+
) || {};
|
|
3632
3961
|
if (begin !== focusedSpineItemIndex && end !== focusedSpineItemIndex) {
|
|
3633
|
-
Report.warn(
|
|
3634
|
-
|
|
3962
|
+
Report.warn(
|
|
3963
|
+
`Current viewport is not in sync with focus item, load from focus item rather than viewport`
|
|
3964
|
+
);
|
|
3965
|
+
spineItemManager.loadContents([
|
|
3966
|
+
focusedSpineItemIndex,
|
|
3967
|
+
focusedSpineItemIndex
|
|
3968
|
+
]);
|
|
3635
3969
|
} else {
|
|
3636
3970
|
spineItemManager.loadContents([begin, end]);
|
|
3637
3971
|
}
|
|
@@ -3690,7 +4024,10 @@ const createContainerElement = (doc) => {
|
|
|
3690
4024
|
return element;
|
|
3691
4025
|
};
|
|
3692
4026
|
const NAMESPACE$4 = `spineItemManager`;
|
|
3693
|
-
const createSpineItemManager = ({
|
|
4027
|
+
const createSpineItemManager = ({
|
|
4028
|
+
context,
|
|
4029
|
+
settings
|
|
4030
|
+
}) => {
|
|
3694
4031
|
const focus$ = new Subject();
|
|
3695
4032
|
const layout$ = new Subject();
|
|
3696
4033
|
let itemLayoutInformation = [];
|
|
@@ -3801,30 +4138,36 @@ const createSpineItemManager = ({ context, settings }) => {
|
|
|
3801
4138
|
focusedSpineItemIndex = newActiveSpineItemIndex;
|
|
3802
4139
|
focus$.next({ data: spineItemToFocus });
|
|
3803
4140
|
};
|
|
3804
|
-
const loadContents = Report.measurePerformance(
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
const
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
4141
|
+
const loadContents = Report.measurePerformance(
|
|
4142
|
+
`loadContents`,
|
|
4143
|
+
10,
|
|
4144
|
+
(rangeOfIndex) => {
|
|
4145
|
+
var _a;
|
|
4146
|
+
const [leftIndex, rightIndex] = rangeOfIndex;
|
|
4147
|
+
const numberOfAdjacentSpineItemToPreLoad = settings.settings.numberOfAdjacentSpineItemToPreLoad;
|
|
4148
|
+
const isPrePaginated = ((_a = context.manifest) == null ? void 0 : _a.renditionLayout) === `pre-paginated`;
|
|
4149
|
+
const isUsingFreeScroll = settings.settings.computedPageTurnMode === `scrollable`;
|
|
4150
|
+
orderedSpineItemsSubject$.value.forEach((orderedSpineItem, index) => {
|
|
4151
|
+
const isBeforeFocusedWithPreload = (
|
|
4152
|
+
// we never want to preload anything before on free scroll on flow because it could offset the cursor
|
|
4153
|
+
index < leftIndex && !isPrePaginated && isUsingFreeScroll ? true : index < leftIndex - numberOfAdjacentSpineItemToPreLoad
|
|
4154
|
+
);
|
|
4155
|
+
const isAfterTailWithPreload = index > rightIndex + numberOfAdjacentSpineItemToPreLoad;
|
|
4156
|
+
if (!isBeforeFocusedWithPreload && !isAfterTailWithPreload) {
|
|
4157
|
+
orderedSpineItem.loadContent();
|
|
4158
|
+
} else {
|
|
4159
|
+
orderedSpineItem.unloadContent();
|
|
4160
|
+
}
|
|
4161
|
+
});
|
|
4162
|
+
}
|
|
4163
|
+
);
|
|
3823
4164
|
const get = (indexOrId) => {
|
|
3824
4165
|
if (typeof indexOrId === `number`) {
|
|
3825
4166
|
return orderedSpineItemsSubject$.value[indexOrId];
|
|
3826
4167
|
}
|
|
3827
|
-
return orderedSpineItemsSubject$.value.find(
|
|
4168
|
+
return orderedSpineItemsSubject$.value.find(
|
|
4169
|
+
({ item }) => item.id === indexOrId
|
|
4170
|
+
);
|
|
3828
4171
|
};
|
|
3829
4172
|
const getAbsolutePositionOf = (spineItemOrIndex) => {
|
|
3830
4173
|
const indexOfItem = typeof spineItemOrIndex === `number` ? spineItemOrIndex : orderedSpineItemsSubject$.value.indexOf(spineItemOrIndex);
|
|
@@ -3909,7 +4252,9 @@ const createSpineItemManager = ({ context, settings }) => {
|
|
|
3909
4252
|
itemIsReady$: orderedSpineItemsSubject$.asObservable().pipe(
|
|
3910
4253
|
switchMap$1((items) => {
|
|
3911
4254
|
const itemsIsReady$ = items.map(
|
|
3912
|
-
(item) => item.$.isReady$.pipe(
|
|
4255
|
+
(item) => item.$.isReady$.pipe(
|
|
4256
|
+
map((isReady) => ({ item: item.item, isReady }))
|
|
4257
|
+
)
|
|
3913
4258
|
);
|
|
3914
4259
|
return merge(...itemsIsReady$);
|
|
3915
4260
|
})
|
|
@@ -3980,7 +4325,10 @@ const getFirstVisibleNodeForViewport = Report.measurePerformance(
|
|
|
3980
4325
|
);
|
|
3981
4326
|
const getFirstVisibleElementForViewport = (element, viewport) => {
|
|
3982
4327
|
let lastValidElement;
|
|
3983
|
-
const positionFromViewport = getElementOrNodePositionFromViewPort(
|
|
4328
|
+
const positionFromViewport = getElementOrNodePositionFromViewPort(
|
|
4329
|
+
element.getBoundingClientRect(),
|
|
4330
|
+
viewport
|
|
4331
|
+
);
|
|
3984
4332
|
if (positionFromViewport !== `before` && positionFromViewport !== `after`) {
|
|
3985
4333
|
lastValidElement = element;
|
|
3986
4334
|
}
|
|
@@ -3996,7 +4344,8 @@ const getFirstVisibleElementForViewport = (element, viewport) => {
|
|
|
3996
4344
|
};
|
|
3997
4345
|
function getElementOrNodePositionFromViewPort(domRect, { left, right }) {
|
|
3998
4346
|
if (domRect.left <= left && domRect.right <= left) return `before`;
|
|
3999
|
-
if (domRect.left <= left && domRect.right > left && domRect.right <= right)
|
|
4347
|
+
if (domRect.left <= left && domRect.right > left && domRect.right <= right)
|
|
4348
|
+
return `partially-before`;
|
|
4000
4349
|
if (domRect.left <= right && domRect.right > right) return `partially-after`;
|
|
4001
4350
|
if (domRect.left > right) return `after`;
|
|
4002
4351
|
return `within`;
|
|
@@ -4080,19 +4429,33 @@ const isTouchEvent = (event) => {
|
|
|
4080
4429
|
};
|
|
4081
4430
|
const createLocationResolver$1 = ({ context }) => {
|
|
4082
4431
|
const getSafePosition = (unsafeSpineItemPosition, spineItem) => ({
|
|
4083
|
-
x: Math.min(
|
|
4084
|
-
|
|
4432
|
+
x: Math.min(
|
|
4433
|
+
spineItem.getElementDimensions().width,
|
|
4434
|
+
Math.max(0, unsafeSpineItemPosition.x)
|
|
4435
|
+
),
|
|
4436
|
+
y: Math.min(
|
|
4437
|
+
spineItem.getElementDimensions().height,
|
|
4438
|
+
Math.max(0, unsafeSpineItemPosition.y)
|
|
4439
|
+
)
|
|
4085
4440
|
});
|
|
4086
4441
|
const getSpineItemPositionFromPageIndex = (pageIndex, spineItem) => {
|
|
4087
4442
|
const { width: itemWidth, height: itemHeight } = spineItem.getElementDimensions();
|
|
4088
4443
|
if (spineItem.isUsingVerticalWriting()) {
|
|
4089
|
-
const ltrRelativeOffset2 = getItemOffsetFromPageIndex(
|
|
4444
|
+
const ltrRelativeOffset2 = getItemOffsetFromPageIndex(
|
|
4445
|
+
context.getPageSize().height,
|
|
4446
|
+
pageIndex,
|
|
4447
|
+
itemHeight
|
|
4448
|
+
);
|
|
4090
4449
|
return {
|
|
4091
4450
|
x: 0,
|
|
4092
4451
|
y: ltrRelativeOffset2
|
|
4093
4452
|
};
|
|
4094
4453
|
}
|
|
4095
|
-
const ltrRelativeOffset = getItemOffsetFromPageIndex(
|
|
4454
|
+
const ltrRelativeOffset = getItemOffsetFromPageIndex(
|
|
4455
|
+
context.getPageSize().width,
|
|
4456
|
+
pageIndex,
|
|
4457
|
+
itemWidth
|
|
4458
|
+
);
|
|
4096
4459
|
if (context.isRTL()) {
|
|
4097
4460
|
return {
|
|
4098
4461
|
x: itemWidth - ltrRelativeOffset - context.getPageSize().width,
|
|
@@ -4111,7 +4474,10 @@ const createLocationResolver$1 = ({ context }) => {
|
|
|
4111
4474
|
const safePosition = getSafePosition(position, spineItem);
|
|
4112
4475
|
const offset = context.isRTL() ? itemWidth - safePosition.x - context.getPageSize().width : safePosition.x;
|
|
4113
4476
|
if (spineItem.isUsingVerticalWriting()) {
|
|
4114
|
-
const numberOfPages = calculateNumberOfPagesForItem(
|
|
4477
|
+
const numberOfPages = calculateNumberOfPagesForItem(
|
|
4478
|
+
itemHeight,
|
|
4479
|
+
pageHeight
|
|
4480
|
+
);
|
|
4115
4481
|
return getPageFromOffset(position.y, pageHeight, numberOfPages);
|
|
4116
4482
|
} else {
|
|
4117
4483
|
const numberOfPages = calculateNumberOfPagesForItem(itemWidth, pageWidth);
|
|
@@ -4125,7 +4491,11 @@ const createLocationResolver$1 = ({ context }) => {
|
|
|
4125
4491
|
const pageWidth = context.getPageSize().width;
|
|
4126
4492
|
const anchorElementBoundingRect = spineItem.getBoundingRectOfElementFromSelector(anchor);
|
|
4127
4493
|
const offsetOfAnchor = (anchorElementBoundingRect == null ? void 0 : anchorElementBoundingRect.x) || 0;
|
|
4128
|
-
return getClosestValidOffsetFromApproximateOffsetInPages(
|
|
4494
|
+
return getClosestValidOffsetFromApproximateOffsetInPages(
|
|
4495
|
+
offsetOfAnchor,
|
|
4496
|
+
pageWidth,
|
|
4497
|
+
itemWidth
|
|
4498
|
+
);
|
|
4129
4499
|
};
|
|
4130
4500
|
const getSpineItemPositionFromNode = (node, offset, spineItem) => {
|
|
4131
4501
|
var _a;
|
|
@@ -4139,7 +4509,11 @@ const createLocationResolver$1 = ({ context }) => {
|
|
|
4139
4509
|
const spineItemWidth = ((_a = spineItem.getElementDimensions()) == null ? void 0 : _a.width) || 0;
|
|
4140
4510
|
const pageWidth = context.getPageSize().width;
|
|
4141
4511
|
if (offsetOfNodeInSpineItem) {
|
|
4142
|
-
const val = getClosestValidOffsetFromApproximateOffsetInPages(
|
|
4512
|
+
const val = getClosestValidOffsetFromApproximateOffsetInPages(
|
|
4513
|
+
offsetOfNodeInSpineItem,
|
|
4514
|
+
pageWidth,
|
|
4515
|
+
spineItemWidth
|
|
4516
|
+
);
|
|
4143
4517
|
return { x: val, y: 0 };
|
|
4144
4518
|
}
|
|
4145
4519
|
return void 0;
|
|
@@ -4150,14 +4524,20 @@ const createLocationResolver$1 = ({ context }) => {
|
|
|
4150
4524
|
const frame = (_b = (_a = spineItem.spineItemFrame) == null ? void 0 : _a.getManipulableFrame()) == null ? void 0 : _b.frame;
|
|
4151
4525
|
if (((_c = frame == null ? void 0 : frame.contentWindow) == null ? void 0 : _c.document) && // very important because it is being used by next functions
|
|
4152
4526
|
frame.contentWindow.document.body !== null) {
|
|
4153
|
-
const { x: left, y: top } = getSpineItemPositionFromPageIndex(
|
|
4527
|
+
const { x: left, y: top } = getSpineItemPositionFromPageIndex(
|
|
4528
|
+
pageIndex,
|
|
4529
|
+
spineItem
|
|
4530
|
+
);
|
|
4154
4531
|
const viewport = {
|
|
4155
4532
|
left,
|
|
4156
4533
|
right: left + pageSize.width,
|
|
4157
4534
|
top,
|
|
4158
4535
|
bottom: top + pageSize.height
|
|
4159
4536
|
};
|
|
4160
|
-
const res = getFirstVisibleNodeForViewport(
|
|
4537
|
+
const res = getFirstVisibleNodeForViewport(
|
|
4538
|
+
frame.contentWindow.document,
|
|
4539
|
+
viewport
|
|
4540
|
+
);
|
|
4161
4541
|
return res;
|
|
4162
4542
|
}
|
|
4163
4543
|
return void 0;
|
|
@@ -4165,8 +4545,16 @@ const createLocationResolver$1 = ({ context }) => {
|
|
|
4165
4545
|
const getSpineItemClosestPositionFromUnsafePosition = (unsafePosition, spineItem) => {
|
|
4166
4546
|
const { width, height } = spineItem.getElementDimensions();
|
|
4167
4547
|
const adjustedPosition = {
|
|
4168
|
-
x: getClosestValidOffsetFromApproximateOffsetInPages(
|
|
4169
|
-
|
|
4548
|
+
x: getClosestValidOffsetFromApproximateOffsetInPages(
|
|
4549
|
+
unsafePosition.x,
|
|
4550
|
+
context.getPageSize().width,
|
|
4551
|
+
width
|
|
4552
|
+
),
|
|
4553
|
+
y: getClosestValidOffsetFromApproximateOffsetInPages(
|
|
4554
|
+
unsafePosition.y,
|
|
4555
|
+
context.getPageSize().height,
|
|
4556
|
+
height
|
|
4557
|
+
)
|
|
4170
4558
|
};
|
|
4171
4559
|
return adjustedPosition;
|
|
4172
4560
|
};
|
|
@@ -4200,7 +4588,9 @@ class SpineItemNavigationPosition {
|
|
|
4200
4588
|
this.y = position.y;
|
|
4201
4589
|
}
|
|
4202
4590
|
}
|
|
4203
|
-
const createNavigationResolver$1 = ({
|
|
4591
|
+
const createNavigationResolver$1 = ({
|
|
4592
|
+
context
|
|
4593
|
+
}) => {
|
|
4204
4594
|
const spineItemLocator = createLocationResolver$1({ context });
|
|
4205
4595
|
const getNavigationForLeftPage = (position, spineItem) => {
|
|
4206
4596
|
let nextPotentialPosition = {
|
|
@@ -4239,20 +4629,33 @@ const createNavigationResolver$1 = ({ context }) => {
|
|
|
4239
4629
|
const getNavigationForLastPage = (spineItem) => {
|
|
4240
4630
|
if (spineItem.isUsingVerticalWriting()) {
|
|
4241
4631
|
const pageHeight = context.getPageSize().height;
|
|
4242
|
-
const numberOfPages = calculateNumberOfPagesForItem(
|
|
4632
|
+
const numberOfPages = calculateNumberOfPagesForItem(
|
|
4633
|
+
spineItem.getElementDimensions().height,
|
|
4634
|
+
pageHeight
|
|
4635
|
+
);
|
|
4243
4636
|
return getNavigationForPage(numberOfPages - 1, spineItem);
|
|
4244
4637
|
} else {
|
|
4245
4638
|
const pageWidth = context.getPageSize().width;
|
|
4246
|
-
const numberOfPages = calculateNumberOfPagesForItem(
|
|
4639
|
+
const numberOfPages = calculateNumberOfPagesForItem(
|
|
4640
|
+
spineItem.getElementDimensions().width,
|
|
4641
|
+
pageWidth
|
|
4642
|
+
);
|
|
4247
4643
|
return getNavigationForPage(numberOfPages - 1, spineItem);
|
|
4248
4644
|
}
|
|
4249
4645
|
};
|
|
4250
4646
|
const getNavigationForPage = (pageIndex, spineItem) => {
|
|
4251
|
-
const { x, y } = spineItemLocator.getSpineItemPositionFromPageIndex(
|
|
4647
|
+
const { x, y } = spineItemLocator.getSpineItemPositionFromPageIndex(
|
|
4648
|
+
pageIndex,
|
|
4649
|
+
spineItem
|
|
4650
|
+
);
|
|
4252
4651
|
return new SpineItemNavigationPosition({ x, y });
|
|
4253
4652
|
};
|
|
4254
4653
|
const getNavigationFromNode = (spineItem, node, offset) => {
|
|
4255
|
-
const position = spineItemLocator.getSpineItemPositionFromNode(
|
|
4654
|
+
const position = spineItemLocator.getSpineItemPositionFromNode(
|
|
4655
|
+
node,
|
|
4656
|
+
offset,
|
|
4657
|
+
spineItem
|
|
4658
|
+
);
|
|
4256
4659
|
return new SpineItemNavigationPosition(position || { x: 0, y: 0 });
|
|
4257
4660
|
};
|
|
4258
4661
|
const getNavigationForPosition = (spineItem, position) => {
|
|
@@ -4286,8 +4689,12 @@ const createNavigationResolver = ({
|
|
|
4286
4689
|
`${NAMESPACE$3} wrapPositionWithSafeEdge`,
|
|
4287
4690
|
1,
|
|
4288
4691
|
(position) => {
|
|
4289
|
-
const lastSpineItem = spineItemManager.get(
|
|
4290
|
-
|
|
4692
|
+
const lastSpineItem = spineItemManager.get(
|
|
4693
|
+
spineItemManager.getLength() - 1
|
|
4694
|
+
);
|
|
4695
|
+
const distanceOfLastSpineItem = spineItemManager.getAbsolutePositionOf(
|
|
4696
|
+
lastSpineItem || 0
|
|
4697
|
+
);
|
|
4291
4698
|
const maximumYOffset = distanceOfLastSpineItem.bottom - context.getPageSize().height;
|
|
4292
4699
|
const y = Math.min(Math.max(0, position.y), maximumYOffset);
|
|
4293
4700
|
if (context.isRTL()) {
|
|
@@ -4304,7 +4711,10 @@ const createNavigationResolver = ({
|
|
|
4304
4711
|
},
|
|
4305
4712
|
{ disable: true }
|
|
4306
4713
|
);
|
|
4307
|
-
const getAdjustedPositionForSpread = ({
|
|
4714
|
+
const getAdjustedPositionForSpread = ({
|
|
4715
|
+
x,
|
|
4716
|
+
y
|
|
4717
|
+
}) => {
|
|
4308
4718
|
const isOffsetNotAtEdge = x % context.state.visibleAreaRect.width !== 0;
|
|
4309
4719
|
const correctedX = isOffsetNotAtEdge ? x - context.getPageSize().width : x;
|
|
4310
4720
|
return { x: correctedX, y };
|
|
@@ -4316,7 +4726,10 @@ const createNavigationResolver = ({
|
|
|
4316
4726
|
Report.warn(NAMESPACE$3, `unable to detect item id from cfi ${cfi}`);
|
|
4317
4727
|
} else {
|
|
4318
4728
|
const spineItemNavigation = node ? spineItemNavigator.getNavigationFromNode(spineItem, node, offset) : new SpineItemNavigationPosition({ x: 0, y: 0 });
|
|
4319
|
-
const readingPosition = locator.getSpinePositionFromSpineItemPosition(
|
|
4729
|
+
const readingPosition = locator.getSpinePositionFromSpineItemPosition(
|
|
4730
|
+
spineItemNavigation,
|
|
4731
|
+
spineItem
|
|
4732
|
+
);
|
|
4320
4733
|
return { ...getAdjustedPositionForSpread(readingPosition), spineItem };
|
|
4321
4734
|
}
|
|
4322
4735
|
return { x: 0, y: 0 };
|
|
@@ -4326,13 +4739,22 @@ const createNavigationResolver = ({
|
|
|
4326
4739
|
const xPositionForPageIndex = pageIndex * context.getPageSize().width;
|
|
4327
4740
|
return getNavigationForPosition({ x: xPositionForPageIndex, y: 0 });
|
|
4328
4741
|
}
|
|
4329
|
-
const spineItemNavigation = spineItemNavigator.getNavigationForPage(
|
|
4330
|
-
|
|
4742
|
+
const spineItemNavigation = spineItemNavigator.getNavigationForPage(
|
|
4743
|
+
pageIndex,
|
|
4744
|
+
spineItem
|
|
4745
|
+
);
|
|
4746
|
+
const readingOffset = locator.getSpinePositionFromSpineItemPosition(
|
|
4747
|
+
spineItemNavigation,
|
|
4748
|
+
spineItem
|
|
4749
|
+
);
|
|
4331
4750
|
return getAdjustedPositionForSpread(readingOffset);
|
|
4332
4751
|
};
|
|
4333
4752
|
const getNavigationForLastPage = (spineItem) => {
|
|
4334
4753
|
const spineItemNavigation = spineItemNavigator.getNavigationForLastPage(spineItem);
|
|
4335
|
-
const position = locator.getSpinePositionFromSpineItemPosition(
|
|
4754
|
+
const position = locator.getSpinePositionFromSpineItemPosition(
|
|
4755
|
+
spineItemNavigation,
|
|
4756
|
+
spineItem
|
|
4757
|
+
);
|
|
4336
4758
|
return getAdjustedPositionForSpread(position);
|
|
4337
4759
|
};
|
|
4338
4760
|
const getNavigationForSpineIndexOrId = (indexOrId) => {
|
|
@@ -4350,9 +4772,15 @@ const createNavigationResolver = ({
|
|
|
4350
4772
|
if (!spineItem) {
|
|
4351
4773
|
return defaultNavigation;
|
|
4352
4774
|
}
|
|
4353
|
-
const spineItemPosition = locator.getSpineItemPositionFromSpinePosition(
|
|
4775
|
+
const spineItemPosition = locator.getSpineItemPositionFromSpinePosition(
|
|
4776
|
+
position,
|
|
4777
|
+
spineItem
|
|
4778
|
+
);
|
|
4354
4779
|
const spineItemNavigationForRightPage = spineItemNavigator.getNavigationForRightPage(spineItemPosition, spineItem);
|
|
4355
|
-
const isNewNavigationInCurrentItem = arePositionsDifferent(
|
|
4780
|
+
const isNewNavigationInCurrentItem = arePositionsDifferent(
|
|
4781
|
+
spineItemNavigationForRightPage,
|
|
4782
|
+
spineItemPosition
|
|
4783
|
+
);
|
|
4356
4784
|
if (!isNewNavigationInCurrentItem) {
|
|
4357
4785
|
return wrapPositionWithSafeEdge(
|
|
4358
4786
|
pageTurnDirection === `horizontal` ? { x: position.x + context.getPageSize().width, y: 0 } : { y: position.y + context.getPageSize().height, x: 0 }
|
|
@@ -4372,15 +4800,27 @@ const createNavigationResolver = ({
|
|
|
4372
4800
|
if (!spineItem) {
|
|
4373
4801
|
return defaultNavigation;
|
|
4374
4802
|
}
|
|
4375
|
-
const spineItemPosition = locator.getSpineItemPositionFromSpinePosition(
|
|
4376
|
-
|
|
4377
|
-
|
|
4803
|
+
const spineItemPosition = locator.getSpineItemPositionFromSpinePosition(
|
|
4804
|
+
position,
|
|
4805
|
+
spineItem
|
|
4806
|
+
);
|
|
4807
|
+
const spineItemNavigation = spineItemNavigator.getNavigationForLeftPage(
|
|
4808
|
+
spineItemPosition,
|
|
4809
|
+
spineItem
|
|
4810
|
+
);
|
|
4811
|
+
const isNewNavigationInCurrentItem = arePositionsDifferent(
|
|
4812
|
+
spineItemNavigation,
|
|
4813
|
+
spineItemPosition
|
|
4814
|
+
);
|
|
4378
4815
|
if (!isNewNavigationInCurrentItem) {
|
|
4379
4816
|
return wrapPositionWithSafeEdge(
|
|
4380
4817
|
pageTurnDirection === `horizontal` ? { x: position.x - context.getPageSize().width, y: 0 } : { y: position.y - context.getPageSize().height, x: 0 }
|
|
4381
4818
|
);
|
|
4382
4819
|
} else {
|
|
4383
|
-
const readingOrderPosition = locator.getSpinePositionFromSpineItemPosition(
|
|
4820
|
+
const readingOrderPosition = locator.getSpinePositionFromSpineItemPosition(
|
|
4821
|
+
spineItemNavigation,
|
|
4822
|
+
spineItem
|
|
4823
|
+
);
|
|
4384
4824
|
return readingOrderPosition;
|
|
4385
4825
|
}
|
|
4386
4826
|
};
|
|
@@ -4422,7 +4862,10 @@ const createNavigationResolver = ({
|
|
|
4422
4862
|
if ((spineItemOnPosition == null ? void 0 : spineItemOnPosition.isUsingVerticalWriting()) && position.x !== navigation.x) {
|
|
4423
4863
|
return getAdjustedPositionForSpread(
|
|
4424
4864
|
wrapPositionWithSafeEdge(
|
|
4425
|
-
context.isRTL() ? { ...navigation, x: navigation.x + context.getPageSize().width } : {
|
|
4865
|
+
context.isRTL() ? { ...navigation, x: navigation.x + context.getPageSize().width } : {
|
|
4866
|
+
...navigation,
|
|
4867
|
+
x: navigation.x - context.getPageSize().width
|
|
4868
|
+
}
|
|
4426
4869
|
)
|
|
4427
4870
|
);
|
|
4428
4871
|
}
|
|
@@ -4439,7 +4882,9 @@ const createNavigationResolver = ({
|
|
|
4439
4882
|
try {
|
|
4440
4883
|
const validUrl = url instanceof URL ? url : new URL(url);
|
|
4441
4884
|
const urlWithoutAnchor = `${validUrl.origin}${validUrl.pathname}`;
|
|
4442
|
-
const existingSpineItem = (_a = context.manifest) == null ? void 0 : _a.spineItems.find(
|
|
4885
|
+
const existingSpineItem = (_a = context.manifest) == null ? void 0 : _a.spineItems.find(
|
|
4886
|
+
(item) => item.href === urlWithoutAnchor
|
|
4887
|
+
);
|
|
4443
4888
|
if (existingSpineItem) {
|
|
4444
4889
|
const spineItem = spineItemManager.get(existingSpineItem.id);
|
|
4445
4890
|
if (spineItem) {
|
|
@@ -4454,15 +4899,27 @@ const createNavigationResolver = ({
|
|
|
4454
4899
|
}
|
|
4455
4900
|
};
|
|
4456
4901
|
const getNavigationForAnchor = (anchor, spineItem) => {
|
|
4457
|
-
const position = locator.getSpinePositionFromSpineItemAnchor(
|
|
4902
|
+
const position = locator.getSpinePositionFromSpineItemAnchor(
|
|
4903
|
+
anchor,
|
|
4904
|
+
spineItem
|
|
4905
|
+
);
|
|
4458
4906
|
return getAdjustedPositionForSpread(position);
|
|
4459
4907
|
};
|
|
4460
4908
|
const getNavigationForPosition = (viewportPosition) => {
|
|
4461
4909
|
const spineItem = locator.getSpineItemFromPosition(viewportPosition);
|
|
4462
4910
|
if (spineItem) {
|
|
4463
|
-
const spineItemPosition = locator.getSpineItemPositionFromSpinePosition(
|
|
4464
|
-
|
|
4465
|
-
|
|
4911
|
+
const spineItemPosition = locator.getSpineItemPositionFromSpinePosition(
|
|
4912
|
+
viewportPosition,
|
|
4913
|
+
spineItem
|
|
4914
|
+
);
|
|
4915
|
+
const spineItemValidPosition = spineItemNavigator.getNavigationForPosition(
|
|
4916
|
+
spineItem,
|
|
4917
|
+
spineItemPosition
|
|
4918
|
+
);
|
|
4919
|
+
const viewportNavigation = locator.getSpinePositionFromSpineItemPosition(
|
|
4920
|
+
spineItemValidPosition,
|
|
4921
|
+
spineItem
|
|
4922
|
+
);
|
|
4466
4923
|
return getAdjustedPositionForSpread(viewportNavigation);
|
|
4467
4924
|
}
|
|
4468
4925
|
return { x: 0, y: 0 };
|
|
@@ -4472,7 +4929,10 @@ const createNavigationResolver = ({
|
|
|
4472
4929
|
const triggerPercentage = 0.5;
|
|
4473
4930
|
const triggerXPosition = pageTurnDirection === `horizontal` ? viewportPosition.x + context.state.visibleAreaRect.width * triggerPercentage : 0;
|
|
4474
4931
|
const triggerYPosition = pageTurnDirection === `horizontal` ? 0 : viewportPosition.y + context.state.visibleAreaRect.height * triggerPercentage;
|
|
4475
|
-
const midScreenPositionSafePosition = wrapPositionWithSafeEdge({
|
|
4932
|
+
const midScreenPositionSafePosition = wrapPositionWithSafeEdge({
|
|
4933
|
+
x: triggerXPosition,
|
|
4934
|
+
y: triggerYPosition
|
|
4935
|
+
});
|
|
4476
4936
|
return getNavigationForPosition(midScreenPositionSafePosition);
|
|
4477
4937
|
};
|
|
4478
4938
|
const isNavigationGoingForwardFrom = (to, from2) => {
|
|
@@ -4528,7 +4988,7 @@ const createScrollViewportNavigator = ({
|
|
|
4528
4988
|
return false;
|
|
4529
4989
|
};
|
|
4530
4990
|
const runOnFreePageTurnModeOnly$ = (source) => settings.settings$.pipe(
|
|
4531
|
-
map
|
|
4991
|
+
map(({ computedPageTurnMode }) => computedPageTurnMode),
|
|
4532
4992
|
distinctUntilChanged(),
|
|
4533
4993
|
switchMap$1((mode) => iif(() => mode === `controlled`, EMPTY, source))
|
|
4534
4994
|
);
|
|
@@ -4567,17 +5027,27 @@ const createScrollViewportNavigator = ({
|
|
|
4567
5027
|
};
|
|
4568
5028
|
const getCurrentViewportPosition = () => {
|
|
4569
5029
|
var _a, _b;
|
|
4570
|
-
return getScaledDownPosition({
|
|
5030
|
+
return getScaledDownPosition({
|
|
5031
|
+
x: ((_a = element$.getValue()) == null ? void 0 : _a.scrollLeft) ?? 0,
|
|
5032
|
+
y: ((_b = element$.getValue()) == null ? void 0 : _b.scrollTop) ?? 0
|
|
5033
|
+
});
|
|
4571
5034
|
};
|
|
4572
5035
|
const navigationOnScroll$ = userScroll$.pipe(
|
|
4573
5036
|
debounceTime$1(SCROLL_FINISHED_DEBOUNCE_TIMEOUT, animationFrameScheduler),
|
|
4574
|
-
withLatestFrom(currentNavigationSubject$),
|
|
5037
|
+
withLatestFrom$1(currentNavigationSubject$),
|
|
4575
5038
|
switchMap$1(() => {
|
|
4576
5039
|
var _a, _b;
|
|
4577
5040
|
const navigation = getNavigationForPosition(
|
|
4578
|
-
getScaledDownPosition({
|
|
5041
|
+
getScaledDownPosition({
|
|
5042
|
+
x: ((_a = element$.getValue()) == null ? void 0 : _a.scrollLeft) ?? 0,
|
|
5043
|
+
y: ((_b = element$.getValue()) == null ? void 0 : _b.scrollTop) ?? 0
|
|
5044
|
+
})
|
|
4579
5045
|
);
|
|
4580
|
-
return of({
|
|
5046
|
+
return of({
|
|
5047
|
+
position: navigation,
|
|
5048
|
+
animate: false,
|
|
5049
|
+
lastUserExpectedNavigation: void 0
|
|
5050
|
+
});
|
|
4581
5051
|
}),
|
|
4582
5052
|
share()
|
|
4583
5053
|
);
|
|
@@ -4588,11 +5058,11 @@ const createScrollViewportNavigator = ({
|
|
|
4588
5058
|
);
|
|
4589
5059
|
const state$ = merge(
|
|
4590
5060
|
userScroll$.pipe(
|
|
4591
|
-
map
|
|
5061
|
+
map(() => `start`),
|
|
4592
5062
|
distinctUntilChanged()
|
|
4593
5063
|
),
|
|
4594
|
-
userScrollEnd$.pipe(map
|
|
4595
|
-
).pipe(startWith
|
|
5064
|
+
userScrollEnd$.pipe(map(() => `end`))
|
|
5065
|
+
).pipe(startWith(`end`));
|
|
4596
5066
|
return {
|
|
4597
5067
|
destroy: () => {
|
|
4598
5068
|
},
|
|
@@ -4615,16 +5085,29 @@ const createManualViewportNavigator = ({
|
|
|
4615
5085
|
}) => {
|
|
4616
5086
|
const stateSubject$ = new BehaviorSubject(`end`);
|
|
4617
5087
|
const navigationTriggerSubject$ = new Subject();
|
|
4618
|
-
const turnLeft = ({
|
|
4619
|
-
|
|
4620
|
-
|
|
5088
|
+
const turnLeft = ({
|
|
5089
|
+
allowSpineItemChange = true
|
|
5090
|
+
} = {}) => navigationTriggerSubject$.next({
|
|
5091
|
+
type: `leftPage`,
|
|
5092
|
+
data: { allowSpineItemChange }
|
|
5093
|
+
});
|
|
5094
|
+
const turnRight = ({
|
|
5095
|
+
allowSpineItemChange = true
|
|
5096
|
+
} = {}) => {
|
|
5097
|
+
navigationTriggerSubject$.next({
|
|
5098
|
+
type: `rightPage`,
|
|
5099
|
+
data: { allowSpineItemChange }
|
|
5100
|
+
});
|
|
4621
5101
|
};
|
|
4622
5102
|
const goToPageOfCurrentChapter = (pageIndex) => navigationTriggerSubject$.next({ type: `chapterPage`, data: { pageIndex } });
|
|
4623
5103
|
const goToPage = (pageIndex) => navigationTriggerSubject$.next({ type: `pageIndex`, data: { pageIndex } });
|
|
4624
5104
|
const goToCfi = (cfi, options = { animate: true }) => navigationTriggerSubject$.next({ type: `cfi`, data: { cfi, ...options } });
|
|
4625
5105
|
const goToUrl = (url) => navigationTriggerSubject$.next({ type: `url`, data: url });
|
|
4626
5106
|
const goToSpineItem = (indexOrId, options = { animate: true }) => {
|
|
4627
|
-
navigationTriggerSubject$.next({
|
|
5107
|
+
navigationTriggerSubject$.next({
|
|
5108
|
+
type: `spineItem`,
|
|
5109
|
+
data: { indexOrId, ...options }
|
|
5110
|
+
});
|
|
4628
5111
|
};
|
|
4629
5112
|
const urlNavigation$ = navigationTriggerSubject$.pipe(
|
|
4630
5113
|
filter((e) => e.type === `url`),
|
|
@@ -4635,7 +5118,10 @@ const createManualViewportNavigator = ({
|
|
|
4635
5118
|
return of({
|
|
4636
5119
|
...navigation,
|
|
4637
5120
|
animate: true,
|
|
4638
|
-
lastUserExpectedNavigation: {
|
|
5121
|
+
lastUserExpectedNavigation: {
|
|
5122
|
+
type: `navigate-from-anchor`,
|
|
5123
|
+
data: navigation.url.hash
|
|
5124
|
+
}
|
|
4639
5125
|
});
|
|
4640
5126
|
}
|
|
4641
5127
|
return EMPTY;
|
|
@@ -4645,20 +5131,25 @@ const createManualViewportNavigator = ({
|
|
|
4645
5131
|
filter((e) => e.type === `spineItem`),
|
|
4646
5132
|
switchMap$1(({ data: { animate, indexOrId } }) => {
|
|
4647
5133
|
const navigation = navigator2.getNavigationForSpineIndexOrId(indexOrId);
|
|
4648
|
-
const lastUserExpectedNavigation = {
|
|
5134
|
+
const lastUserExpectedNavigation = {
|
|
5135
|
+
type: `navigate-from-previous-item`
|
|
5136
|
+
};
|
|
4649
5137
|
Report.log(NAMESPACE$2, `goToSpineItem`, { indexOrId, animate, navigation });
|
|
4650
5138
|
return of({ ...navigation, animate, lastUserExpectedNavigation });
|
|
4651
5139
|
})
|
|
4652
5140
|
);
|
|
4653
5141
|
const cfiNavigation$ = navigationTriggerSubject$.pipe(
|
|
4654
5142
|
filter((e) => e.type === `cfi`),
|
|
4655
|
-
map
|
|
5143
|
+
map(({ data: { animate, cfi } }) => {
|
|
4656
5144
|
const navigation = navigator2.getNavigationForCfi(cfi);
|
|
4657
5145
|
Report.log(NAMESPACE$2, `goToCfi`, { cfi, animate, navigation });
|
|
4658
5146
|
return {
|
|
4659
5147
|
...navigation,
|
|
4660
5148
|
animate,
|
|
4661
|
-
lastUserExpectedNavigation: {
|
|
5149
|
+
lastUserExpectedNavigation: {
|
|
5150
|
+
type: `navigate-from-cfi`,
|
|
5151
|
+
data: cfi
|
|
5152
|
+
}
|
|
4662
5153
|
};
|
|
4663
5154
|
})
|
|
4664
5155
|
);
|
|
@@ -4668,7 +5159,11 @@ const createManualViewportNavigator = ({
|
|
|
4668
5159
|
const spineItem = spineItemManager.getFocusedSpineItem();
|
|
4669
5160
|
if (spineItem) {
|
|
4670
5161
|
const navigation = navigator2.getNavigationForPage(pageIndex, spineItem);
|
|
4671
|
-
return of({
|
|
5162
|
+
return of({
|
|
5163
|
+
...navigation,
|
|
5164
|
+
lastUserExpectedNavigation: void 0,
|
|
5165
|
+
animate: true
|
|
5166
|
+
});
|
|
4672
5167
|
}
|
|
4673
5168
|
return EMPTY;
|
|
4674
5169
|
})
|
|
@@ -4701,33 +5196,38 @@ const createManualViewportNavigator = ({
|
|
|
4701
5196
|
const spineItemHasChanged = newSpineItem !== currentSpineItem;
|
|
4702
5197
|
if (spineItemHasChanged) {
|
|
4703
5198
|
if (allowSpineItemChange) {
|
|
4704
|
-
const positionOfNewSpineItemComparedToCurrentOne = spineItemManager.comparePositionOf(
|
|
4705
|
-
newSpineItem,
|
|
4706
|
-
currentSpineItem
|
|
4707
|
-
);
|
|
5199
|
+
const positionOfNewSpineItemComparedToCurrentOne = spineItemManager.comparePositionOf(newSpineItem, currentSpineItem);
|
|
4708
5200
|
if (positionOfNewSpineItemComparedToCurrentOne === `before`) {
|
|
4709
5201
|
return of({
|
|
4710
5202
|
...navigation,
|
|
4711
|
-
lastUserExpectedNavigation: {
|
|
5203
|
+
lastUserExpectedNavigation: {
|
|
5204
|
+
type: `navigate-from-next-item`
|
|
5205
|
+
},
|
|
4712
5206
|
animate: true
|
|
4713
5207
|
});
|
|
4714
5208
|
} else {
|
|
4715
5209
|
return of({
|
|
4716
5210
|
...navigation,
|
|
4717
|
-
lastUserExpectedNavigation: {
|
|
5211
|
+
lastUserExpectedNavigation: {
|
|
5212
|
+
type: `navigate-from-previous-item`
|
|
5213
|
+
},
|
|
4718
5214
|
animate: true
|
|
4719
5215
|
});
|
|
4720
5216
|
}
|
|
4721
5217
|
}
|
|
4722
5218
|
} else {
|
|
4723
|
-
return of({
|
|
5219
|
+
return of({
|
|
5220
|
+
...navigation,
|
|
5221
|
+
lastUserExpectedNavigation: void 0,
|
|
5222
|
+
animate: true
|
|
5223
|
+
});
|
|
4724
5224
|
}
|
|
4725
5225
|
return EMPTY;
|
|
4726
5226
|
}
|
|
4727
5227
|
);
|
|
4728
5228
|
const leftPageNavigation$ = navigationTriggerSubject$.pipe(
|
|
4729
5229
|
filter((e) => e.type === `leftPage`),
|
|
4730
|
-
withLatestFrom(currentNavigationSubject$),
|
|
5230
|
+
withLatestFrom$1(currentNavigationSubject$),
|
|
4731
5231
|
switchMap$1(
|
|
4732
5232
|
([
|
|
4733
5233
|
{
|
|
@@ -4736,14 +5236,18 @@ const createManualViewportNavigator = ({
|
|
|
4736
5236
|
currentNavigation
|
|
4737
5237
|
]) => {
|
|
4738
5238
|
const navigation = navigator2.getNavigationForLeftPage(currentNavigation);
|
|
4739
|
-
Report.log(NAMESPACE$2, `turnLeft`, {
|
|
5239
|
+
Report.log(NAMESPACE$2, `turnLeft`, {
|
|
5240
|
+
currentNavigation,
|
|
5241
|
+
navigation,
|
|
5242
|
+
allowSpineItemChange
|
|
5243
|
+
});
|
|
4740
5244
|
return turnPageTo$(navigation, { allowSpineItemChange });
|
|
4741
5245
|
}
|
|
4742
5246
|
)
|
|
4743
5247
|
);
|
|
4744
5248
|
const rightPageNavigation$ = navigationTriggerSubject$.pipe(
|
|
4745
5249
|
filter((e) => e.type === `rightPage`),
|
|
4746
|
-
withLatestFrom(currentNavigationSubject$),
|
|
5250
|
+
withLatestFrom$1(currentNavigationSubject$),
|
|
4747
5251
|
switchMap$1(
|
|
4748
5252
|
([
|
|
4749
5253
|
{
|
|
@@ -4752,7 +5256,11 @@ const createManualViewportNavigator = ({
|
|
|
4752
5256
|
currentNavigation
|
|
4753
5257
|
]) => {
|
|
4754
5258
|
const navigation = navigator2.getNavigationForRightPage(currentNavigation);
|
|
4755
|
-
Report.log(NAMESPACE$2, `turnRight`, {
|
|
5259
|
+
Report.log(NAMESPACE$2, `turnRight`, {
|
|
5260
|
+
currentNavigation,
|
|
5261
|
+
navigation,
|
|
5262
|
+
allowSpineItemChange
|
|
5263
|
+
});
|
|
4756
5264
|
return turnPageTo$(navigation, { allowSpineItemChange });
|
|
4757
5265
|
}
|
|
4758
5266
|
)
|
|
@@ -4771,9 +5279,11 @@ const createManualViewportNavigator = ({
|
|
|
4771
5279
|
* This is because manual navigation is not used with scroll where you can move within the same item. A manual
|
|
4772
5280
|
* navigation would theoretically always move to different items.
|
|
4773
5281
|
*/
|
|
4774
|
-
withLatestFrom(currentNavigationSubject$),
|
|
4775
|
-
filter(
|
|
4776
|
-
|
|
5282
|
+
withLatestFrom$1(currentNavigationSubject$),
|
|
5283
|
+
filter(
|
|
5284
|
+
([navigation, currentNavigation]) => navigator2.areNavigationDifferent(navigation, currentNavigation)
|
|
5285
|
+
),
|
|
5286
|
+
map(([navigation]) => navigation)
|
|
4777
5287
|
);
|
|
4778
5288
|
return {
|
|
4779
5289
|
destroy: () => {
|
|
@@ -4863,7 +5373,10 @@ const createPanViewportNavigator = ({
|
|
|
4863
5373
|
const spineItemHasChanged = newSpineItem !== currentSpineItem;
|
|
4864
5374
|
if (spineItemHasChanged) {
|
|
4865
5375
|
if (allowSpineItemChange) {
|
|
4866
|
-
if (spineItemManager.comparePositionOf(
|
|
5376
|
+
if (spineItemManager.comparePositionOf(
|
|
5377
|
+
newSpineItem,
|
|
5378
|
+
currentSpineItem
|
|
5379
|
+
) === `before`) {
|
|
4867
5380
|
return { type: `navigate-from-next-item` };
|
|
4868
5381
|
} else {
|
|
4869
5382
|
return { type: `navigate-from-previous-item` };
|
|
@@ -4876,7 +5389,7 @@ const createPanViewportNavigator = ({
|
|
|
4876
5389
|
);
|
|
4877
5390
|
const snapNavigation$ = navigationTriggerSubject$.pipe(
|
|
4878
5391
|
filter((e) => e.type === `snap`),
|
|
4879
|
-
withLatestFrom
|
|
5392
|
+
withLatestFrom(settings.settings$),
|
|
4880
5393
|
switchMap$1(
|
|
4881
5394
|
([
|
|
4882
5395
|
{
|
|
@@ -4893,7 +5406,9 @@ const createPanViewportNavigator = ({
|
|
|
4893
5406
|
x: triggerXPosition,
|
|
4894
5407
|
y: triggerYPosition
|
|
4895
5408
|
});
|
|
4896
|
-
const finalNavigation = navigator2.getNavigationForPosition(
|
|
5409
|
+
const finalNavigation = navigator2.getNavigationForPosition(
|
|
5410
|
+
midScreenPositionSafePosition
|
|
5411
|
+
);
|
|
4897
5412
|
const lastUserExpectedNavigation = getLastUserExpectedNavigation(finalNavigation);
|
|
4898
5413
|
return of({ ...finalNavigation, lastUserExpectedNavigation });
|
|
4899
5414
|
}
|
|
@@ -4945,23 +5460,30 @@ const createViewportNavigator = ({
|
|
|
4945
5460
|
locator: spineLocator
|
|
4946
5461
|
});
|
|
4947
5462
|
const adjustNavigationSubject$ = new Subject();
|
|
4948
|
-
const getCurrentViewportPosition = Report.measurePerformance(
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
5463
|
+
const getCurrentViewportPosition = Report.measurePerformance(
|
|
5464
|
+
`${NAMESPACE} getCurrentViewportPosition`,
|
|
5465
|
+
1,
|
|
5466
|
+
() => {
|
|
5467
|
+
var _a;
|
|
5468
|
+
if (settings.settings.computedPageTurnMode === `scrollable`) {
|
|
5469
|
+
return scrollViewportNavigator.getCurrentViewportPosition();
|
|
5470
|
+
}
|
|
5471
|
+
const { x, y } = ((_a = element$.getValue()) == null ? void 0 : _a.getBoundingClientRect()) ?? {
|
|
5472
|
+
x: 0,
|
|
5473
|
+
y: 0
|
|
5474
|
+
};
|
|
5475
|
+
const newValue = {
|
|
5476
|
+
// we want to round to first decimal because it's possible to have half pixel
|
|
5477
|
+
// however browser engine can also gives back x.yyyy based on their precision
|
|
5478
|
+
// @see https://stackoverflow.com/questions/13847053/difference-between-and-math-floor for ~~
|
|
5479
|
+
x: ~~(x * -1 * 10) / 10,
|
|
5480
|
+
// x: ~~(x * 10) / 10,
|
|
5481
|
+
y: ~~(Math.abs(y) * 10) / 10
|
|
5482
|
+
};
|
|
5483
|
+
currentViewportPositionMemoUnused = newValue;
|
|
5484
|
+
return currentViewportPositionMemoUnused;
|
|
4952
5485
|
}
|
|
4953
|
-
|
|
4954
|
-
const newValue = {
|
|
4955
|
-
// we want to round to first decimal because it's possible to have half pixel
|
|
4956
|
-
// however browser engine can also gives back x.yyyy based on their precision
|
|
4957
|
-
// @see https://stackoverflow.com/questions/13847053/difference-between-and-math-floor for ~~
|
|
4958
|
-
x: ~~(x * -1 * 10) / 10,
|
|
4959
|
-
// x: ~~(x * 10) / 10,
|
|
4960
|
-
y: ~~(Math.abs(y) * 10) / 10
|
|
4961
|
-
};
|
|
4962
|
-
currentViewportPositionMemoUnused = newValue;
|
|
4963
|
-
return currentViewportPositionMemoUnused;
|
|
4964
|
-
});
|
|
5486
|
+
);
|
|
4965
5487
|
const panViewportNavigator = createPanViewportNavigator({
|
|
4966
5488
|
context,
|
|
4967
5489
|
settings,
|
|
@@ -4987,8 +5509,14 @@ const createViewportNavigator = ({
|
|
|
4987
5509
|
spineItemManager,
|
|
4988
5510
|
locator: spineLocator
|
|
4989
5511
|
});
|
|
4990
|
-
const viewportNavigators = [
|
|
4991
|
-
|
|
5512
|
+
const viewportNavigators = [
|
|
5513
|
+
scrollViewportNavigator,
|
|
5514
|
+
panViewportNavigator,
|
|
5515
|
+
manualViewportNavigator
|
|
5516
|
+
];
|
|
5517
|
+
const viewportNavigatorsSharedState$ = merge(
|
|
5518
|
+
...viewportNavigators.map(({ $: { state$: state$2 } }) => state$2)
|
|
5519
|
+
);
|
|
4992
5520
|
let lastUserExpectedNavigation;
|
|
4993
5521
|
const makeItHot = (source$) => {
|
|
4994
5522
|
source$.pipe(takeUntil$1(context.destroy$)).subscribe();
|
|
@@ -5016,28 +5544,51 @@ const createViewportNavigator = ({
|
|
|
5016
5544
|
let adjustedSpinePosition = currentNavigationPositionSubject$.value;
|
|
5017
5545
|
const offsetInSpineItem = 0;
|
|
5018
5546
|
if (settings.settings.computedPageTurnMode === `scrollable`) {
|
|
5019
|
-
adjustedSpinePosition = scrollViewportNavigator.getNavigationForPosition(
|
|
5547
|
+
adjustedSpinePosition = scrollViewportNavigator.getNavigationForPosition(
|
|
5548
|
+
getCurrentViewportPosition()
|
|
5549
|
+
);
|
|
5020
5550
|
} else if ((lastUserExpectedNavigation == null ? void 0 : lastUserExpectedNavigation.type) === `navigate-from-cfi`) {
|
|
5021
|
-
adjustedSpinePosition = navigator2.getNavigationForCfi(
|
|
5022
|
-
|
|
5551
|
+
adjustedSpinePosition = navigator2.getNavigationForCfi(
|
|
5552
|
+
lastUserExpectedNavigation.data
|
|
5553
|
+
);
|
|
5554
|
+
Report.log(
|
|
5555
|
+
NAMESPACE,
|
|
5556
|
+
`adjustNavigation`,
|
|
5557
|
+
`navigate-from-cfi`,
|
|
5558
|
+
`use last cfi`
|
|
5559
|
+
);
|
|
5023
5560
|
} else if ((lastUserExpectedNavigation == null ? void 0 : lastUserExpectedNavigation.type) === `navigate-from-next-item`) {
|
|
5024
5561
|
adjustedSpinePosition = navigator2.getNavigationForLastPage(spineItem);
|
|
5025
5562
|
Report.log(NAMESPACE, `adjustNavigation`, `navigate-from-next-item`, {});
|
|
5026
5563
|
} else if ((lastUserExpectedNavigation == null ? void 0 : lastUserExpectedNavigation.type) === `navigate-from-previous-item`) {
|
|
5027
5564
|
adjustedSpinePosition = navigator2.getNavigationForPage(0, spineItem);
|
|
5028
|
-
Report.log(
|
|
5565
|
+
Report.log(
|
|
5566
|
+
NAMESPACE,
|
|
5567
|
+
`adjustNavigation`,
|
|
5568
|
+
`navigate-from-previous-item`,
|
|
5569
|
+
{}
|
|
5570
|
+
);
|
|
5029
5571
|
} else if ((lastUserExpectedNavigation == null ? void 0 : lastUserExpectedNavigation.type) === `navigate-from-anchor`) {
|
|
5030
5572
|
const anchor = lastUserExpectedNavigation.data;
|
|
5031
|
-
adjustedSpinePosition = navigator2.getNavigationForAnchor(
|
|
5573
|
+
adjustedSpinePosition = navigator2.getNavigationForAnchor(
|
|
5574
|
+
anchor,
|
|
5575
|
+
spineItem
|
|
5576
|
+
);
|
|
5032
5577
|
} else if (lastCfi) {
|
|
5033
5578
|
adjustedSpinePosition = navigator2.getNavigationForCfi(lastCfi);
|
|
5034
5579
|
Report.log(NAMESPACE, `adjustNavigation`, `use last cfi`);
|
|
5035
5580
|
} else {
|
|
5036
5581
|
const currentPageIndex = pagination.getPaginationInfo().beginPageIndexInSpineItem || 0;
|
|
5037
|
-
adjustedSpinePosition = navigator2.getNavigationForPage(
|
|
5582
|
+
adjustedSpinePosition = navigator2.getNavigationForPage(
|
|
5583
|
+
currentPageIndex,
|
|
5584
|
+
spineItem
|
|
5585
|
+
);
|
|
5038
5586
|
Report.log(NAMESPACE, `adjustNavigation`, `use guess strategy`, {});
|
|
5039
5587
|
}
|
|
5040
|
-
const areDifferent = navigator2.arePositionsDifferent(
|
|
5588
|
+
const areDifferent = navigator2.arePositionsDifferent(
|
|
5589
|
+
adjustedSpinePosition,
|
|
5590
|
+
currentNavigationPositionSubject$.value
|
|
5591
|
+
);
|
|
5041
5592
|
Report.log(NAMESPACE, `adjustNavigation`, {
|
|
5042
5593
|
areDifferent,
|
|
5043
5594
|
offsetInSpineItem,
|
|
@@ -5061,12 +5612,16 @@ const createViewportNavigator = ({
|
|
|
5061
5612
|
currentViewportPositionMemoUnused = void 0;
|
|
5062
5613
|
});
|
|
5063
5614
|
const layoutChangeSettings$ = settings.settings$.pipe(
|
|
5064
|
-
mapKeysTo([
|
|
5615
|
+
mapKeysTo([
|
|
5616
|
+
`computedPageTurnDirection`,
|
|
5617
|
+
`computedPageTurnMode`,
|
|
5618
|
+
`numberOfAdjacentSpineItemToPreLoad`
|
|
5619
|
+
]),
|
|
5065
5620
|
distinctUntilChanged(isShallowEqual),
|
|
5066
5621
|
skip(1)
|
|
5067
5622
|
);
|
|
5068
5623
|
const layout$ = merge(layoutSubject$, layoutChangeSettings$).pipe(
|
|
5069
|
-
withLatestFrom(element$),
|
|
5624
|
+
withLatestFrom$1(element$),
|
|
5070
5625
|
tap(([, element]) => {
|
|
5071
5626
|
if (settings.settings.computedPageTurnMode === `scrollable`) {
|
|
5072
5627
|
element.style.removeProperty(`transform`);
|
|
@@ -5082,7 +5637,7 @@ const createViewportNavigator = ({
|
|
|
5082
5637
|
layout$.subscribe();
|
|
5083
5638
|
const navigation$ = merge(
|
|
5084
5639
|
panViewportNavigator.$.navigation$.pipe(
|
|
5085
|
-
map
|
|
5640
|
+
map((event) => ({
|
|
5086
5641
|
...event,
|
|
5087
5642
|
position: { x: event.x, y: event.y, spineItem: event.spineItem },
|
|
5088
5643
|
animation: `snap`,
|
|
@@ -5090,7 +5645,7 @@ const createViewportNavigator = ({
|
|
|
5090
5645
|
}))
|
|
5091
5646
|
),
|
|
5092
5647
|
manualViewportNavigator.$.navigation$.pipe(
|
|
5093
|
-
map
|
|
5648
|
+
map((event) => ({
|
|
5094
5649
|
...event,
|
|
5095
5650
|
position: { x: event.x, y: event.y, spineItem: event.spineItem },
|
|
5096
5651
|
animation: event.animate ? `turn` : false,
|
|
@@ -5098,21 +5653,21 @@ const createViewportNavigator = ({
|
|
|
5098
5653
|
}))
|
|
5099
5654
|
),
|
|
5100
5655
|
adjustNavigationSubject$.pipe(
|
|
5101
|
-
map
|
|
5656
|
+
map((event) => ({
|
|
5102
5657
|
...event,
|
|
5103
5658
|
triggeredBy: `adjust`,
|
|
5104
5659
|
animation: event.animate ? `turn` : false
|
|
5105
5660
|
}))
|
|
5106
5661
|
),
|
|
5107
5662
|
scrollViewportNavigator.$.navigation$.pipe(
|
|
5108
|
-
map
|
|
5663
|
+
map((event) => ({
|
|
5109
5664
|
...event,
|
|
5110
5665
|
triggeredBy: `scroll`,
|
|
5111
5666
|
animation: event.animate ? `turn` : false
|
|
5112
5667
|
}))
|
|
5113
5668
|
)
|
|
5114
5669
|
).pipe(
|
|
5115
|
-
map
|
|
5670
|
+
map((event) => {
|
|
5116
5671
|
if (`lastUserExpectedNavigation` in event) {
|
|
5117
5672
|
lastUserExpectedNavigation = event.lastUserExpectedNavigation;
|
|
5118
5673
|
}
|
|
@@ -5132,10 +5687,10 @@ const createViewportNavigator = ({
|
|
|
5132
5687
|
})
|
|
5133
5688
|
);
|
|
5134
5689
|
const manualAdjust$ = merge(
|
|
5135
|
-
panViewportNavigator.$.moveToSubject$.asObservable().pipe(map
|
|
5690
|
+
panViewportNavigator.$.moveToSubject$.asObservable().pipe(map((event) => ({ ...event, animation: false }))),
|
|
5136
5691
|
navigationWhichRequireManualAdjust$
|
|
5137
5692
|
).pipe(
|
|
5138
|
-
map
|
|
5693
|
+
map(({ animation, position }) => {
|
|
5139
5694
|
const shouldAnimate = !(!animation || animation === `turn` && settings.settings.computedPageTurnAnimation === `none`);
|
|
5140
5695
|
return {
|
|
5141
5696
|
type: `manualAdjust`,
|
|
@@ -5147,7 +5702,7 @@ const createViewportNavigator = ({
|
|
|
5147
5702
|
share()
|
|
5148
5703
|
);
|
|
5149
5704
|
const processManualAdjust$ = merge(manualAdjust$).pipe(
|
|
5150
|
-
startWith
|
|
5705
|
+
startWith(void 0),
|
|
5151
5706
|
pairwise(),
|
|
5152
5707
|
tap(([prevEvent, currentEvent]) => {
|
|
5153
5708
|
if ((prevEvent == null ? void 0 : prevEvent.type) === `manualAdjust` && (currentEvent == null ? void 0 : currentEvent.type) !== `manualAdjust`) {
|
|
@@ -5173,10 +5728,16 @@ const createViewportNavigator = ({
|
|
|
5173
5728
|
const noAdjustmentNeeded = false;
|
|
5174
5729
|
if (data.shouldAnimate && !noAdjustmentNeeded) {
|
|
5175
5730
|
if (pageTurnAnimation === `fade`) {
|
|
5176
|
-
element$.getValue().style.setProperty(
|
|
5731
|
+
element$.getValue().style.setProperty(
|
|
5732
|
+
`transition`,
|
|
5733
|
+
`opacity ${animationDuration / 2}ms`
|
|
5734
|
+
);
|
|
5177
5735
|
element$.getValue().style.setProperty(`opacity`, `0`);
|
|
5178
5736
|
} else if (currentEvent.animation === `snap` || pageTurnAnimation === `slide`) {
|
|
5179
|
-
element$.getValue().style.setProperty(
|
|
5737
|
+
element$.getValue().style.setProperty(
|
|
5738
|
+
`transition`,
|
|
5739
|
+
`transform ${animationDuration}ms`
|
|
5740
|
+
);
|
|
5180
5741
|
element$.getValue().style.setProperty(`opacity`, `1`);
|
|
5181
5742
|
}
|
|
5182
5743
|
} else {
|
|
@@ -5222,11 +5783,16 @@ const createViewportNavigator = ({
|
|
|
5222
5783
|
takeUntil$1(context.destroy$)
|
|
5223
5784
|
);
|
|
5224
5785
|
const adjustmentState$ = merge(
|
|
5225
|
-
merge(manualAdjust$).pipe(map
|
|
5226
|
-
merge(processManualAdjust$).pipe(map
|
|
5786
|
+
merge(manualAdjust$).pipe(map(() => `start`)),
|
|
5787
|
+
merge(processManualAdjust$).pipe(map(() => `end`))
|
|
5227
5788
|
);
|
|
5228
|
-
const state$ = combineLatest([
|
|
5229
|
-
map
|
|
5789
|
+
const state$ = combineLatest([
|
|
5790
|
+
...viewportNavigators.map(({ $: { state$: state$2 } }) => state$2),
|
|
5791
|
+
adjustmentState$
|
|
5792
|
+
]).pipe(
|
|
5793
|
+
map(
|
|
5794
|
+
(states) => states.every((state) => state === `end`) ? `free` : `busy`
|
|
5795
|
+
),
|
|
5230
5796
|
distinctUntilChanged(),
|
|
5231
5797
|
shareReplay(1),
|
|
5232
5798
|
/**
|
|
@@ -5272,7 +5838,7 @@ const createViewportNavigator = ({
|
|
|
5272
5838
|
),
|
|
5273
5839
|
share()
|
|
5274
5840
|
);
|
|
5275
|
-
const parentElementSub = parentElement$.pipe(filter(isDefined), withLatestFrom(spine.element$)).subscribe(([parentElement, spineElement]) => {
|
|
5841
|
+
const parentElementSub = parentElement$.pipe(filter(isDefined), withLatestFrom$1(spine.element$)).subscribe(([parentElement, spineElement]) => {
|
|
5276
5842
|
const element = createElement(parentElement.ownerDocument, hookManager);
|
|
5277
5843
|
element.appendChild(spineElement);
|
|
5278
5844
|
parentElement.appendChild(element);
|
|
@@ -5316,7 +5882,9 @@ const createElement = (doc, hookManager) => {
|
|
|
5316
5882
|
position: relative;
|
|
5317
5883
|
`;
|
|
5318
5884
|
element.className = `${HTML_PREFIX$1}-viewport-navigator`;
|
|
5319
|
-
hookManager.execute("viewportNavigator.onBeforeContainerCreated", void 0, {
|
|
5885
|
+
hookManager.execute("viewportNavigator.onBeforeContainerCreated", void 0, {
|
|
5886
|
+
element
|
|
5887
|
+
});
|
|
5320
5888
|
return element;
|
|
5321
5889
|
};
|
|
5322
5890
|
const createLocationResolver = ({
|
|
@@ -5375,8 +5943,14 @@ const createLocationResolver = ({
|
|
|
5375
5943
|
return getSpinePositionFromSpineItemPosition({ x: 0, y: 0 }, spineItem);
|
|
5376
5944
|
};
|
|
5377
5945
|
const getSpinePositionFromSpineItemAnchor = (anchor, spineItem) => {
|
|
5378
|
-
const spineItemOffset = spineItemLocator.getSpineItemOffsetFromAnchor(
|
|
5379
|
-
|
|
5946
|
+
const spineItemOffset = spineItemLocator.getSpineItemOffsetFromAnchor(
|
|
5947
|
+
anchor,
|
|
5948
|
+
spineItem
|
|
5949
|
+
);
|
|
5950
|
+
const position = getSpinePositionFromSpineItemPosition(
|
|
5951
|
+
{ x: spineItemOffset, y: 0 },
|
|
5952
|
+
spineItem
|
|
5953
|
+
);
|
|
5380
5954
|
return position;
|
|
5381
5955
|
};
|
|
5382
5956
|
const getSpineItemsFromReadingOrderPosition = (position) => {
|
|
@@ -5385,7 +5959,10 @@ const createLocationResolver = ({
|
|
|
5385
5959
|
if (itemAtPositionIndex === void 0) return void 0;
|
|
5386
5960
|
let endPosition = position;
|
|
5387
5961
|
if (context.state.isUsingSpreadMode) {
|
|
5388
|
-
endPosition = {
|
|
5962
|
+
endPosition = {
|
|
5963
|
+
x: position.x + context.getPageSize().width,
|
|
5964
|
+
y: position.y
|
|
5965
|
+
};
|
|
5389
5966
|
}
|
|
5390
5967
|
const endItemIndex = spineItemManager.getSpineItemIndex(
|
|
5391
5968
|
getSpineItemFromPosition(endPosition) || spineItemManager.getFocusedSpineItem()
|
|
@@ -5413,9 +5990,17 @@ const createLocationResolver = ({
|
|
|
5413
5990
|
const getSpineItemPageIndexFromNode = (node, offset, spineItemOrIndex) => {
|
|
5414
5991
|
if (typeof spineItemOrIndex === `number`) {
|
|
5415
5992
|
const spineItem = spineItemManager.get(spineItemOrIndex);
|
|
5416
|
-
return spineItem ? spineItemLocator.getSpineItemPageIndexFromNode(
|
|
5993
|
+
return spineItem ? spineItemLocator.getSpineItemPageIndexFromNode(
|
|
5994
|
+
node,
|
|
5995
|
+
offset || 0,
|
|
5996
|
+
spineItem
|
|
5997
|
+
) : void 0;
|
|
5417
5998
|
}
|
|
5418
|
-
return spineItemLocator.getSpineItemPageIndexFromNode(
|
|
5999
|
+
return spineItemLocator.getSpineItemPageIndexFromNode(
|
|
6000
|
+
node,
|
|
6001
|
+
offset || 0,
|
|
6002
|
+
spineItemOrIndex
|
|
6003
|
+
);
|
|
5419
6004
|
};
|
|
5420
6005
|
return {
|
|
5421
6006
|
getSpinePositionFromSpineItemPosition,
|
|
@@ -5433,18 +6018,29 @@ const createCfiLocator = ({
|
|
|
5433
6018
|
spineItemLocator
|
|
5434
6019
|
}) => {
|
|
5435
6020
|
const getItemAnchor = (spineItem) => `|[prose~anchor~${encodeURIComponent(spineItem.item.id)}]`;
|
|
5436
|
-
const getCfi = Report.measurePerformance(
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
6021
|
+
const getCfi = Report.measurePerformance(
|
|
6022
|
+
`getCfi`,
|
|
6023
|
+
10,
|
|
6024
|
+
(pageIndex, spineItem) => {
|
|
6025
|
+
var _a, _b, _c;
|
|
6026
|
+
const nodeOrRange = spineItemLocator.getFirstNodeOrRangeAtPage(
|
|
6027
|
+
pageIndex,
|
|
6028
|
+
spineItem
|
|
6029
|
+
);
|
|
6030
|
+
const doc = (_c = (_b = (_a = spineItem.spineItemFrame.getManipulableFrame()) == null ? void 0 : _a.frame) == null ? void 0 : _b.contentWindow) == null ? void 0 : _c.document;
|
|
6031
|
+
const itemAnchor = getItemAnchor(spineItem);
|
|
6032
|
+
const offset = `|[prose~offset~${(nodeOrRange == null ? void 0 : nodeOrRange.offset) || 0}]`;
|
|
6033
|
+
if (nodeOrRange && doc) {
|
|
6034
|
+
const cfiString = CFI.generate(
|
|
6035
|
+
nodeOrRange.node,
|
|
6036
|
+
0,
|
|
6037
|
+
`${itemAnchor}${offset}`
|
|
6038
|
+
);
|
|
6039
|
+
return cfiString;
|
|
6040
|
+
}
|
|
6041
|
+
return getRootCfi(spineItem);
|
|
5445
6042
|
}
|
|
5446
|
-
|
|
5447
|
-
});
|
|
6043
|
+
);
|
|
5448
6044
|
const getRootCfi = (spineItem) => {
|
|
5449
6045
|
const itemAnchor = getItemAnchor(spineItem);
|
|
5450
6046
|
return `epubcfi(/0${itemAnchor}) `;
|
|
@@ -5491,9 +6087,22 @@ const createCfiLocator = ({
|
|
|
5491
6087
|
spineItemIndex
|
|
5492
6088
|
};
|
|
5493
6089
|
};
|
|
5494
|
-
const generateFromRange = ({
|
|
5495
|
-
|
|
5496
|
-
|
|
6090
|
+
const generateFromRange = ({
|
|
6091
|
+
startNode,
|
|
6092
|
+
start,
|
|
6093
|
+
end,
|
|
6094
|
+
endNode
|
|
6095
|
+
}, item) => {
|
|
6096
|
+
const startCFI = CFI.generate(
|
|
6097
|
+
startNode,
|
|
6098
|
+
start,
|
|
6099
|
+
`|[prose~anchor~${encodeURIComponent(item.id)}]`
|
|
6100
|
+
);
|
|
6101
|
+
const endCFI = CFI.generate(
|
|
6102
|
+
endNode,
|
|
6103
|
+
end,
|
|
6104
|
+
`|[prose~anchor~${encodeURIComponent(item.id)}]`
|
|
6105
|
+
);
|
|
5497
6106
|
return { start: startCFI, end: endCFI };
|
|
5498
6107
|
};
|
|
5499
6108
|
return {
|
|
@@ -5505,93 +6114,124 @@ const createCfiLocator = ({
|
|
|
5505
6114
|
generateFromRange
|
|
5506
6115
|
};
|
|
5507
6116
|
};
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
computedSettings.computedPageTurnMode = `scrollable`;
|
|
5519
|
-
computedSettings.computedPageTurnDirection = `vertical`;
|
|
5520
|
-
} else if (manifest && settings.pageTurnMode === `scrollable` && (manifest.renditionLayout !== `pre-paginated` || !areAllItemsPrePaginated(manifest))) {
|
|
5521
|
-
Report.warn(`pageTurnMode ${settings.pageTurnMode} incompatible with current book, switching back to default`);
|
|
5522
|
-
computedSettings.computedPageTurnAnimation = `none`;
|
|
5523
|
-
computedSettings.computedPageTurnMode = `controlled`;
|
|
5524
|
-
} else if (settings.pageTurnMode === `scrollable`) {
|
|
5525
|
-
computedSettings.computedPageTurnMode = `scrollable`;
|
|
5526
|
-
computedSettings.computedPageTurnDirection = `vertical`;
|
|
6117
|
+
class SettingsManager3 {
|
|
6118
|
+
constructor(initialSettings) {
|
|
6119
|
+
const settingsWithDefaults = {
|
|
6120
|
+
...this.getDefaultSettings(),
|
|
6121
|
+
...initialSettings
|
|
6122
|
+
};
|
|
6123
|
+
this.inputSettings = settingsWithDefaults;
|
|
6124
|
+
this.outputSettingsUpdateSubject = new Subject();
|
|
6125
|
+
this.settings$ = this.outputSettingsUpdateSubject.asObservable().pipe(shareReplay(1));
|
|
6126
|
+
this.settings$.subscribe();
|
|
5527
6127
|
}
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
|
|
5531
|
-
);
|
|
5532
|
-
|
|
6128
|
+
_prepareUpdate(settings) {
|
|
6129
|
+
const newInputSettings = shallowMergeIfDefined(this.inputSettings, settings);
|
|
6130
|
+
const state = this.getOutputSettings(newInputSettings);
|
|
6131
|
+
const hasChanged = !isShallowEqual(this.outputSettings, state);
|
|
6132
|
+
return {
|
|
6133
|
+
hasChanged,
|
|
6134
|
+
state,
|
|
6135
|
+
commit: () => {
|
|
6136
|
+
this.inputSettings = newInputSettings;
|
|
6137
|
+
this.outputSettings = state;
|
|
6138
|
+
if (hasChanged) {
|
|
6139
|
+
this.outputSettingsUpdateSubject.next(state);
|
|
6140
|
+
}
|
|
6141
|
+
return state;
|
|
6142
|
+
}
|
|
6143
|
+
};
|
|
5533
6144
|
}
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
} else {
|
|
5538
|
-
computedSettings.computedPageTurnAnimationDuration = settings.pageTurnAnimationDuration !== void 0 ? settings.pageTurnAnimationDuration : 300;
|
|
6145
|
+
update(settings) {
|
|
6146
|
+
const { commit } = this._prepareUpdate(settings);
|
|
6147
|
+
commit();
|
|
5539
6148
|
}
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
const
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
snapAnimationDuration: 300,
|
|
5553
|
-
navigationSnapThreshold: 0.3,
|
|
5554
|
-
numberOfAdjacentSpineItemToPreLoad: 0
|
|
5555
|
-
};
|
|
5556
|
-
class SettingsManager {
|
|
6149
|
+
get settings() {
|
|
6150
|
+
if (!this.outputSettings) {
|
|
6151
|
+
const { commit } = this._prepareUpdate(this.inputSettings);
|
|
6152
|
+
return commit();
|
|
6153
|
+
}
|
|
6154
|
+
return this.outputSettings;
|
|
6155
|
+
}
|
|
6156
|
+
destroy() {
|
|
6157
|
+
this.outputSettingsUpdateSubject.complete();
|
|
6158
|
+
}
|
|
6159
|
+
}
|
|
6160
|
+
class ReaderSettingsManager extends SettingsManager3 {
|
|
5557
6161
|
constructor(initialSettings, context) {
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
const settings = { ...settingsWithDefaults, ...computedSettings };
|
|
5565
|
-
this._settingsSubject$ = new BehaviorSubject(settings);
|
|
5566
|
-
this.settings$ = this._settingsSubject$.asObservable().pipe(distinctUntilChanged(isShallowEqual));
|
|
5567
|
-
const recomputeSettingsOnContextChange$ = combineLatest([context.hasVerticalWriting$, context.manifest$]).pipe(
|
|
6162
|
+
super(initialSettings);
|
|
6163
|
+
this.context = context;
|
|
6164
|
+
const recomputeSettingsOnContextChange$ = combineLatest([
|
|
6165
|
+
context.hasVerticalWriting$,
|
|
6166
|
+
context.manifest$
|
|
6167
|
+
]).pipe(
|
|
5568
6168
|
tap(() => {
|
|
5569
|
-
this.
|
|
6169
|
+
this.update(this.settings);
|
|
5570
6170
|
})
|
|
5571
6171
|
);
|
|
5572
|
-
const updateContextOnSettingsChanges$ = this.
|
|
6172
|
+
const updateContextOnSettingsChanges$ = this.settings$.pipe(
|
|
5573
6173
|
tap(({ forceSinglePageMode }) => {
|
|
5574
6174
|
context.update({ forceSinglePageMode });
|
|
5575
6175
|
})
|
|
5576
6176
|
);
|
|
5577
6177
|
merge(recomputeSettingsOnContextChange$, updateContextOnSettingsChanges$).pipe(takeUntil$1(context.destroy$)).subscribe();
|
|
6178
|
+
this.settings$.subscribe();
|
|
5578
6179
|
}
|
|
5579
|
-
|
|
5580
|
-
|
|
5581
|
-
const
|
|
5582
|
-
const
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
6180
|
+
getComputedSettings(settings) {
|
|
6181
|
+
const manifest = this.context.manifest;
|
|
6182
|
+
const hasVerticalWriting = this.context.state.hasVerticalWriting ?? false;
|
|
6183
|
+
const computedSettings = {
|
|
6184
|
+
computedPageTurnDirection: settings.pageTurnDirection,
|
|
6185
|
+
computedPageTurnAnimation: settings.pageTurnAnimation,
|
|
6186
|
+
computedPageTurnMode: `controlled`,
|
|
6187
|
+
computedPageTurnAnimationDuration: 0
|
|
6188
|
+
};
|
|
6189
|
+
if ((manifest == null ? void 0 : manifest.renditionFlow) === `scrolled-continuous`) {
|
|
6190
|
+
computedSettings.computedPageTurnMode = `scrollable`;
|
|
6191
|
+
computedSettings.computedPageTurnDirection = `vertical`;
|
|
6192
|
+
} else if (manifest && settings.pageTurnMode === `scrollable` && (manifest.renditionLayout !== `pre-paginated` || !areAllItemsPrePaginated(manifest))) {
|
|
6193
|
+
Report.warn(
|
|
6194
|
+
`pageTurnMode ${settings.pageTurnMode} incompatible with current book, switching back to default`
|
|
6195
|
+
);
|
|
6196
|
+
computedSettings.computedPageTurnAnimation = `none`;
|
|
6197
|
+
computedSettings.computedPageTurnMode = `controlled`;
|
|
6198
|
+
} else if (settings.pageTurnMode === `scrollable`) {
|
|
6199
|
+
computedSettings.computedPageTurnMode = `scrollable`;
|
|
6200
|
+
computedSettings.computedPageTurnDirection = `vertical`;
|
|
6201
|
+
}
|
|
6202
|
+
if (hasVerticalWriting && computedSettings.computedPageTurnAnimation === `slide`) {
|
|
6203
|
+
Report.warn(
|
|
6204
|
+
`pageTurnAnimation ${computedSettings.computedPageTurnAnimation} incompatible with current book, switching back to default`
|
|
6205
|
+
);
|
|
6206
|
+
computedSettings.computedPageTurnAnimation = `none`;
|
|
6207
|
+
}
|
|
6208
|
+
if (computedSettings.computedPageTurnMode === `scrollable`) {
|
|
6209
|
+
computedSettings.computedPageTurnAnimationDuration = 0;
|
|
6210
|
+
computedSettings.computedPageTurnAnimation = `none`;
|
|
6211
|
+
} else {
|
|
6212
|
+
computedSettings.computedPageTurnAnimationDuration = settings.pageTurnAnimationDuration !== void 0 ? settings.pageTurnAnimationDuration : 300;
|
|
6213
|
+
}
|
|
6214
|
+
return computedSettings;
|
|
5589
6215
|
}
|
|
5590
|
-
|
|
5591
|
-
|
|
6216
|
+
getOutputSettings(inputSettings) {
|
|
6217
|
+
const computedSettings = this.getComputedSettings(inputSettings);
|
|
6218
|
+
return { ...this.outputSettings, ...inputSettings, ...computedSettings };
|
|
5592
6219
|
}
|
|
5593
|
-
|
|
5594
|
-
|
|
6220
|
+
getDefaultSettings() {
|
|
6221
|
+
return {
|
|
6222
|
+
forceSinglePageMode: false,
|
|
6223
|
+
pageTurnAnimation: `none`,
|
|
6224
|
+
// computedPageTurnAnimation: `none`,
|
|
6225
|
+
pageTurnDirection: `horizontal`,
|
|
6226
|
+
// computedPageTurnDirection: `horizontal`,
|
|
6227
|
+
pageTurnAnimationDuration: void 0,
|
|
6228
|
+
// computedPageTurnAnimationDuration: 0,
|
|
6229
|
+
pageTurnMode: `controlled`,
|
|
6230
|
+
// computedPageTurnMode: `controlled`,
|
|
6231
|
+
snapAnimationDuration: 300,
|
|
6232
|
+
navigationSnapThreshold: 0.3,
|
|
6233
|
+
numberOfAdjacentSpineItemToPreLoad: 0
|
|
6234
|
+
};
|
|
5595
6235
|
}
|
|
5596
6236
|
}
|
|
5597
6237
|
class HookManager {
|
|
@@ -5624,7 +6264,9 @@ class HookManager {
|
|
|
5624
6264
|
};
|
|
5625
6265
|
}
|
|
5626
6266
|
execute(name, id, params) {
|
|
5627
|
-
const hooks = this._hooks.filter(
|
|
6267
|
+
const hooks = this._hooks.filter(
|
|
6268
|
+
(hook) => name === hook.name
|
|
6269
|
+
);
|
|
5628
6270
|
const fnResults = hooks.map((hook) => {
|
|
5629
6271
|
let userDestroyFn = () => of(void 0);
|
|
5630
6272
|
const destroySubject = new Subject();
|
|
@@ -5637,7 +6279,11 @@ class HookManager {
|
|
|
5637
6279
|
const result = userDestroyFn();
|
|
5638
6280
|
return result ?? of(void 0);
|
|
5639
6281
|
};
|
|
5640
|
-
const fnResult = hook.runFn({
|
|
6282
|
+
const fnResult = hook.runFn({
|
|
6283
|
+
...params,
|
|
6284
|
+
destroy$: destroySubject.asObservable(),
|
|
6285
|
+
destroy
|
|
6286
|
+
});
|
|
5641
6287
|
this._hookExecutions.push({
|
|
5642
6288
|
name,
|
|
5643
6289
|
id,
|
|
@@ -5656,7 +6302,9 @@ class HookManager {
|
|
|
5656
6302
|
name === hookInstance.name && (!id || id && id === hookInstance.id)
|
|
5657
6303
|
)
|
|
5658
6304
|
);
|
|
5659
|
-
this._hookExecutions = this._hookExecutions.filter(
|
|
6305
|
+
this._hookExecutions = this._hookExecutions.filter(
|
|
6306
|
+
(instance) => !instances.includes(instance)
|
|
6307
|
+
);
|
|
5660
6308
|
const destroyFns = instances.map(({ destroyFn }) => destroyFn());
|
|
5661
6309
|
return combineLatest(destroyFns);
|
|
5662
6310
|
}
|
|
@@ -5676,10 +6324,15 @@ const createReader = (inputSettings) => {
|
|
|
5676
6324
|
const viewportStateSubject = new BehaviorSubject(`free`);
|
|
5677
6325
|
const hookManager = new HookManager();
|
|
5678
6326
|
const context = new Context();
|
|
5679
|
-
const settingsManager = new
|
|
5680
|
-
const spineItemManager = createSpineItemManager({
|
|
6327
|
+
const settingsManager = new ReaderSettingsManager(inputSettings, context);
|
|
6328
|
+
const spineItemManager = createSpineItemManager({
|
|
6329
|
+
context,
|
|
6330
|
+
settings: settingsManager
|
|
6331
|
+
});
|
|
5681
6332
|
const pagination = createPagination({ context, spineItemManager });
|
|
5682
|
-
const elementSubject$ = new BehaviorSubject(
|
|
6333
|
+
const elementSubject$ = new BehaviorSubject(
|
|
6334
|
+
void 0
|
|
6335
|
+
);
|
|
5683
6336
|
const element$ = elementSubject$.pipe(filter(isDefined));
|
|
5684
6337
|
const spineItemLocator = createLocationResolver$1({ context });
|
|
5685
6338
|
const spineLocator = createLocationResolver({
|
|
@@ -5722,8 +6375,12 @@ const createReader = (inputSettings) => {
|
|
|
5722
6375
|
});
|
|
5723
6376
|
viewportNavigator.$.state$.subscribe(viewportStateSubject);
|
|
5724
6377
|
viewportNavigator.$.navigation$.subscribe(navigationSubject);
|
|
5725
|
-
viewportNavigator.$.navigationAdjustedAfterLayout$.subscribe(
|
|
5726
|
-
|
|
6378
|
+
viewportNavigator.$.navigationAdjustedAfterLayout$.subscribe(
|
|
6379
|
+
navigationAdjustedSubject
|
|
6380
|
+
);
|
|
6381
|
+
viewportNavigator.$.currentNavigationPosition$.subscribe(
|
|
6382
|
+
currentNavigationPositionSubject$
|
|
6383
|
+
);
|
|
5727
6384
|
const layout = () => {
|
|
5728
6385
|
var _a;
|
|
5729
6386
|
const containerElement = (_a = elementSubject$.getValue()) == null ? void 0 : _a.parentElement;
|
|
@@ -5765,7 +6422,11 @@ const createReader = (inputSettings) => {
|
|
|
5765
6422
|
elementSubject$.next(element);
|
|
5766
6423
|
loadOptions.containerElement.appendChild(element);
|
|
5767
6424
|
}
|
|
5768
|
-
context.update({
|
|
6425
|
+
context.update({
|
|
6426
|
+
manifest,
|
|
6427
|
+
...loadOptions,
|
|
6428
|
+
forceSinglePageMode: settingsManager.settings.forceSinglePageMode
|
|
6429
|
+
});
|
|
5769
6430
|
layout();
|
|
5770
6431
|
if (!loadOptions.cfi) {
|
|
5771
6432
|
viewportNavigator.goToSpineItem(0, { animate: false });
|
|
@@ -5788,9 +6449,9 @@ const createReader = (inputSettings) => {
|
|
|
5788
6449
|
takeUntil$1(context.destroy$)
|
|
5789
6450
|
).subscribe();
|
|
5790
6451
|
merge(context.state$, settingsManager.settings$).pipe(
|
|
5791
|
-
map
|
|
5792
|
-
withLatestFrom(context.state$),
|
|
5793
|
-
map
|
|
6452
|
+
map(() => void 0),
|
|
6453
|
+
withLatestFrom$1(context.state$),
|
|
6454
|
+
map(([, { hasVerticalWriting }]) => {
|
|
5794
6455
|
const manifest = context.manifest;
|
|
5795
6456
|
return {
|
|
5796
6457
|
hasVerticalWriting,
|
|
@@ -5800,7 +6461,7 @@ const createReader = (inputSettings) => {
|
|
|
5800
6461
|
};
|
|
5801
6462
|
}),
|
|
5802
6463
|
distinctUntilChanged(isShallowEqual),
|
|
5803
|
-
map
|
|
6464
|
+
map(
|
|
5804
6465
|
({
|
|
5805
6466
|
hasVerticalWriting,
|
|
5806
6467
|
renditionFlow,
|
|
@@ -5850,7 +6511,9 @@ const createReader = (inputSettings) => {
|
|
|
5850
6511
|
* have an effect.
|
|
5851
6512
|
* It can typically be used to hide a loading indicator.
|
|
5852
6513
|
*/
|
|
5853
|
-
loadStatus$: context.manifest$.pipe(
|
|
6514
|
+
loadStatus$: context.manifest$.pipe(
|
|
6515
|
+
map((manifest) => manifest ? "ready" : "idle")
|
|
6516
|
+
),
|
|
5854
6517
|
/**
|
|
5855
6518
|
* Dispatched when a change in selection happens
|
|
5856
6519
|
*/
|
|
@@ -6017,7 +6680,9 @@ const createResourcesManager = (context) => {
|
|
|
6017
6680
|
mergeMap(({ id, data }) => {
|
|
6018
6681
|
const item = retrieveItem(id);
|
|
6019
6682
|
if (!item) return EMPTY;
|
|
6020
|
-
return from(
|
|
6683
|
+
return from(
|
|
6684
|
+
forkJoin([openDatabase(`prose-reader`), from(data.blob())])
|
|
6685
|
+
).pipe(
|
|
6021
6686
|
switchMap$1(([db, blob]) => {
|
|
6022
6687
|
return from(db.put(`${uniqueID}_${item.id}`, blob));
|
|
6023
6688
|
}),
|
|
@@ -6040,7 +6705,9 @@ const createResourcesManager = (context) => {
|
|
|
6040
6705
|
return from(openDatabase(`prose-reader`)).pipe(
|
|
6041
6706
|
switchMap$1(
|
|
6042
6707
|
(db) => from(db.keys()).pipe(
|
|
6043
|
-
map
|
|
6708
|
+
map(
|
|
6709
|
+
(keys) => keys.filter((key) => !key.toString().startsWith(uniqueID))
|
|
6710
|
+
),
|
|
6044
6711
|
switchMap$1((keysToRemove) => {
|
|
6045
6712
|
const promises = keysToRemove.map((key) => db.remove(key));
|
|
6046
6713
|
return from(Promise.all(promises));
|
|
@@ -6087,7 +6754,9 @@ const mediaEnhancer = (next) => (options) => {
|
|
|
6087
6754
|
entries.forEach((entry) => {
|
|
6088
6755
|
var _a;
|
|
6089
6756
|
const frame = entry.target;
|
|
6090
|
-
const audios = Array.from(
|
|
6757
|
+
const audios = Array.from(
|
|
6758
|
+
((_a = frame.contentDocument) == null ? void 0 : _a.body.getElementsByTagName(`audio`)) || []
|
|
6759
|
+
);
|
|
6091
6760
|
if (!entry.isIntersecting) {
|
|
6092
6761
|
audios.forEach((audioElement) => {
|
|
6093
6762
|
audioElement.pause();
|
|
@@ -6166,7 +6835,11 @@ const progressionEnhancer = (next) => (options) => {
|
|
|
6166
6835
|
let totalProgress = estimateBeforeThisItem + progressWithinThisItem;
|
|
6167
6836
|
if (((_f = context.manifest) == null ? void 0 : _f.renditionFlow) === `scrolled-continuous`) {
|
|
6168
6837
|
if (currentItem.isReady()) {
|
|
6169
|
-
progressWithinThisItem = getScrollPercentageWithinItem(
|
|
6838
|
+
progressWithinThisItem = getScrollPercentageWithinItem(
|
|
6839
|
+
context,
|
|
6840
|
+
currentPosition,
|
|
6841
|
+
currentItem
|
|
6842
|
+
);
|
|
6170
6843
|
} else {
|
|
6171
6844
|
progressWithinThisItem = 0;
|
|
6172
6845
|
}
|
|
@@ -6188,9 +6861,21 @@ const progressionEnhancer = (next) => (options) => {
|
|
|
6188
6861
|
const { height, width } = currentItem.getElementDimensions();
|
|
6189
6862
|
const { top, left } = reader.spineItemManager.getAbsolutePositionOf(currentItem);
|
|
6190
6863
|
if (reader.settings.settings.computedPageTurnDirection === `vertical`) {
|
|
6191
|
-
return Math.max(
|
|
6864
|
+
return Math.max(
|
|
6865
|
+
0,
|
|
6866
|
+
Math.min(
|
|
6867
|
+
1,
|
|
6868
|
+
(currentPosition.y - top + context.state.visibleAreaRect.height) / height
|
|
6869
|
+
)
|
|
6870
|
+
);
|
|
6192
6871
|
} else {
|
|
6193
|
-
return Math.max(
|
|
6872
|
+
return Math.max(
|
|
6873
|
+
0,
|
|
6874
|
+
Math.min(
|
|
6875
|
+
1,
|
|
6876
|
+
(currentPosition.x - left + context.state.visibleAreaRect.width) / width
|
|
6877
|
+
)
|
|
6878
|
+
);
|
|
6194
6879
|
}
|
|
6195
6880
|
};
|
|
6196
6881
|
return {
|
|
@@ -6250,19 +6935,25 @@ const IS_SAFARI = navigator.userAgent.indexOf(``) > -1 && navigator.userAgent.in
|
|
|
6250
6935
|
const webkitEnhancer = (createReader2) => (options) => {
|
|
6251
6936
|
const reader = createReader2(options);
|
|
6252
6937
|
if (IS_SAFARI) {
|
|
6253
|
-
reader.hookManager.register(
|
|
6254
|
-
|
|
6938
|
+
reader.hookManager.register(
|
|
6939
|
+
"viewportNavigator.onBeforeContainerCreated",
|
|
6940
|
+
({ element }) => {
|
|
6941
|
+
element.style.cssText = `
|
|
6255
6942
|
${element.style.cssText}
|
|
6256
6943
|
-webkit-transform-style: preserve-3d;
|
|
6257
6944
|
`;
|
|
6258
|
-
|
|
6259
|
-
|
|
6260
|
-
|
|
6945
|
+
}
|
|
6946
|
+
);
|
|
6947
|
+
reader.hookManager.register(
|
|
6948
|
+
"item.onBeforeContainerCreated",
|
|
6949
|
+
({ element }) => {
|
|
6950
|
+
element.style.cssText = `
|
|
6261
6951
|
${element.style.cssText}
|
|
6262
6952
|
-webkit-transform-style: preserve-3d;
|
|
6263
6953
|
-webkit-backface-visibility: hidden;
|
|
6264
6954
|
`;
|
|
6265
|
-
|
|
6955
|
+
}
|
|
6956
|
+
);
|
|
6266
6957
|
}
|
|
6267
6958
|
return reader;
|
|
6268
6959
|
};
|
|
@@ -6285,7 +6976,7 @@ const loadingEnhancer = (next) => (options) => {
|
|
|
6285
6976
|
}, {})
|
|
6286
6977
|
);
|
|
6287
6978
|
const updateEntriesLayout$ = (entries) => combineLatest([reader.spine.$.layout$, reader.theme.$.theme$]).pipe(
|
|
6288
|
-
map
|
|
6979
|
+
map(([, theme]) => ({
|
|
6289
6980
|
width: reader.context.state.visibleAreaRect.width,
|
|
6290
6981
|
theme
|
|
6291
6982
|
})),
|
|
@@ -6293,18 +6984,24 @@ const loadingEnhancer = (next) => (options) => {
|
|
|
6293
6984
|
tap(({ width, theme }) => {
|
|
6294
6985
|
Object.values(entries).forEach((element) => {
|
|
6295
6986
|
element.style.setProperty(`max-width`, `${width}px`);
|
|
6296
|
-
element.style.setProperty(
|
|
6987
|
+
element.style.setProperty(
|
|
6988
|
+
`color`,
|
|
6989
|
+
theme === `sepia` ? `#939393` : `rgb(202, 202, 202)`
|
|
6990
|
+
);
|
|
6297
6991
|
});
|
|
6298
6992
|
})
|
|
6299
6993
|
);
|
|
6300
6994
|
const updateEntriesVisibility$ = (entries) => reader.spineItemManager.$.itemIsReady$.pipe(
|
|
6301
6995
|
tap(({ item, isReady }) => {
|
|
6302
6996
|
var _a;
|
|
6303
|
-
(_a = entries[item.id]) == null ? void 0 : _a.style.setProperty(
|
|
6997
|
+
(_a = entries[item.id]) == null ? void 0 : _a.style.setProperty(
|
|
6998
|
+
`visibility`,
|
|
6999
|
+
isReady ? `hidden` : `visible`
|
|
7000
|
+
);
|
|
6304
7001
|
})
|
|
6305
7002
|
);
|
|
6306
7003
|
const destroyEntries$ = (entries) => reader.spine.$.itemsBeforeDestroy$.pipe(
|
|
6307
|
-
map
|
|
7004
|
+
map(() => {
|
|
6308
7005
|
Object.values(entries).forEach((element) => element.remove());
|
|
6309
7006
|
return {};
|
|
6310
7007
|
})
|
|
@@ -6316,7 +7013,12 @@ const loadingEnhancer = (next) => (options) => {
|
|
|
6316
7013
|
);
|
|
6317
7014
|
items$.pipe(
|
|
6318
7015
|
switchMap$1((entries) => merge(of(entries), destroyEntries$(entries))),
|
|
6319
|
-
switchMap$1(
|
|
7016
|
+
switchMap$1(
|
|
7017
|
+
(entries) => merge(
|
|
7018
|
+
updateEntriesLayout$(entries),
|
|
7019
|
+
updateEntriesVisibility$(entries)
|
|
7020
|
+
)
|
|
7021
|
+
),
|
|
6320
7022
|
takeUntil$1(reader.$.destroy$)
|
|
6321
7023
|
).subscribe();
|
|
6322
7024
|
return {
|
|
@@ -6386,7 +7088,8 @@ const createNormalizeEventForViewport = ({
|
|
|
6386
7088
|
const eventIsComingFromBridge = event.target === iframeEventBridgeElement$.getValue();
|
|
6387
7089
|
const iframeOriginalEvent = getOriginalFrameEventFromDocumentEvent(event);
|
|
6388
7090
|
const originalFrame = (_a = iframeOriginalEvent == null ? void 0 : iframeOriginalEvent.view) == null ? void 0 : _a.frameElement;
|
|
6389
|
-
if (!eventIsComingFromBridge || !iframeOriginalEvent || !originalFrame)
|
|
7091
|
+
if (!eventIsComingFromBridge || !iframeOriginalEvent || !originalFrame)
|
|
7092
|
+
return event;
|
|
6390
7093
|
const spineItem = locator.getSpineItemFromIframe(originalFrame);
|
|
6391
7094
|
if (!spineItem) return event;
|
|
6392
7095
|
if (isPointerEvent(event)) {
|
|
@@ -6397,7 +7100,10 @@ const createNormalizeEventForViewport = ({
|
|
|
6397
7100
|
clientX,
|
|
6398
7101
|
clientY
|
|
6399
7102
|
});
|
|
6400
|
-
Object.defineProperty(newEvent, `target`, {
|
|
7103
|
+
Object.defineProperty(newEvent, `target`, {
|
|
7104
|
+
value: iframeOriginalEvent.target,
|
|
7105
|
+
enumerable: true
|
|
7106
|
+
});
|
|
6401
7107
|
return newEvent;
|
|
6402
7108
|
}
|
|
6403
7109
|
if (isMouseEvent(event)) {
|
|
@@ -6407,7 +7113,10 @@ const createNormalizeEventForViewport = ({
|
|
|
6407
7113
|
clientX,
|
|
6408
7114
|
clientY
|
|
6409
7115
|
});
|
|
6410
|
-
Object.defineProperty(newEvent, `target`, {
|
|
7116
|
+
Object.defineProperty(newEvent, `target`, {
|
|
7117
|
+
value: iframeOriginalEvent.target,
|
|
7118
|
+
enumerable: true
|
|
7119
|
+
});
|
|
6411
7120
|
return newEvent;
|
|
6412
7121
|
}
|
|
6413
7122
|
if (isTouchEvent(event)) {
|
|
@@ -6425,7 +7134,10 @@ const createNormalizeEventForViewport = ({
|
|
|
6425
7134
|
changedTouches: touches,
|
|
6426
7135
|
targetTouches: touches
|
|
6427
7136
|
});
|
|
6428
|
-
Object.defineProperty(newEvent, `target`, {
|
|
7137
|
+
Object.defineProperty(newEvent, `target`, {
|
|
7138
|
+
value: iframeOriginalEvent.target,
|
|
7139
|
+
enumerable: true
|
|
7140
|
+
});
|
|
6429
7141
|
return newEvent;
|
|
6430
7142
|
}
|
|
6431
7143
|
return event;
|
|
@@ -6567,6 +7279,7 @@ const createReaderWithEnhancers = (
|
|
|
6567
7279
|
export {
|
|
6568
7280
|
HookManager,
|
|
6569
7281
|
Report,
|
|
7282
|
+
SettingsManager3 as SettingsManager,
|
|
6570
7283
|
createReaderWithEnhancers as createReader,
|
|
6571
7284
|
groupBy,
|
|
6572
7285
|
isShallowEqual
|