@readium/navigator 2.5.4 → 2.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +368 -324
- package/dist/index.umd.cjs +14 -14
- package/package.json +1 -1
- package/src/epub/EpubNavigator.ts +38 -15
- package/src/epub/frame/FrameManager.ts +3 -0
- package/src/epub/fxl/FXLFrameManager.ts +3 -0
- package/src/webpub/WebPubNavigator.ts +18 -5
- package/types/src/epub/EpubNavigator.d.ts +1 -0
- package/types/src/webpub/WebPubNavigator.d.ts +1 -0
package/package.json
CHANGED
|
@@ -81,6 +81,7 @@ export class EpubNavigator extends VisualNavigator implements Configurable<Confi
|
|
|
81
81
|
private _css: ReadiumCSS;
|
|
82
82
|
private _preferencesEditor: EpubPreferencesEditor | null = null;
|
|
83
83
|
private _injector: Injector | null = null;
|
|
84
|
+
private _isNavigating = false;
|
|
84
85
|
private readonly _readiumRulesPromise: Promise<IInjectableRule[]>;
|
|
85
86
|
private readonly _injectablesConfig: IInjectablesConfig;
|
|
86
87
|
private readonly _contentProtection: IContentProtectionConfig;
|
|
@@ -648,6 +649,10 @@ export class EpubNavigator extends VisualNavigator implements Configurable<Confi
|
|
|
648
649
|
}
|
|
649
650
|
}
|
|
650
651
|
await this.apply();
|
|
652
|
+
// On the initial forward walk each fresh iframe load fires
|
|
653
|
+
// positionChanged via _pong; on back-then-forward to an
|
|
654
|
+
// already-loaded frame no _pong fires, so dispatch explicitly here.
|
|
655
|
+
this.listeners.positionChanged(this.currentLocation);
|
|
651
656
|
return true;
|
|
652
657
|
}
|
|
653
658
|
|
|
@@ -754,33 +759,45 @@ export class EpubNavigator extends VisualNavigator implements Configurable<Confi
|
|
|
754
759
|
}
|
|
755
760
|
|
|
756
761
|
public goBackward(_: boolean, cb: (ok: boolean) => void): void {
|
|
762
|
+
if(this._isNavigating) { cb(false); return; }
|
|
763
|
+
this._isNavigating = true;
|
|
757
764
|
if(this._layout === Layout.fixed) {
|
|
758
|
-
this.changeResource(-1)
|
|
759
|
-
|
|
765
|
+
this.changeResource(-1).then((ok) => {
|
|
766
|
+
this._isNavigating = false;
|
|
767
|
+
cb(ok);
|
|
768
|
+
});
|
|
760
769
|
} else {
|
|
761
770
|
this._cframes[0]?.msg?.send("go_prev", undefined, async (ack) => {
|
|
762
|
-
if(ack)
|
|
763
|
-
|
|
771
|
+
if(ack) {
|
|
772
|
+
this._isNavigating = false;
|
|
764
773
|
cb(true);
|
|
765
|
-
else
|
|
766
|
-
|
|
767
|
-
|
|
774
|
+
} else {
|
|
775
|
+
const ok = await this.changeResource(-1);
|
|
776
|
+
this._isNavigating = false;
|
|
777
|
+
cb(ok);
|
|
778
|
+
}
|
|
768
779
|
});
|
|
769
780
|
}
|
|
770
781
|
}
|
|
771
782
|
|
|
772
783
|
public goForward(_: boolean, cb: (ok: boolean) => void): void {
|
|
784
|
+
if(this._isNavigating) { cb(false); return; }
|
|
785
|
+
this._isNavigating = true;
|
|
773
786
|
if(this._layout === Layout.fixed) {
|
|
774
|
-
this.changeResource(1)
|
|
775
|
-
|
|
787
|
+
this.changeResource(1).then((ok) => {
|
|
788
|
+
this._isNavigating = false;
|
|
789
|
+
cb(ok);
|
|
790
|
+
});
|
|
776
791
|
} else {
|
|
777
792
|
this._cframes[0]?.msg?.send("go_next", undefined, async (ack) => {
|
|
778
|
-
if(ack)
|
|
779
|
-
|
|
793
|
+
if(ack) {
|
|
794
|
+
this._isNavigating = false;
|
|
780
795
|
cb(true);
|
|
781
|
-
else
|
|
782
|
-
|
|
783
|
-
|
|
796
|
+
} else {
|
|
797
|
+
const ok = await this.changeResource(1);
|
|
798
|
+
this._isNavigating = false;
|
|
799
|
+
cb(ok);
|
|
800
|
+
}
|
|
784
801
|
});
|
|
785
802
|
}
|
|
786
803
|
}
|
|
@@ -903,8 +920,14 @@ export class EpubNavigator extends VisualNavigator implements Configurable<Confi
|
|
|
903
920
|
return cb(this.listeners.handleLocator(locator));
|
|
904
921
|
}
|
|
905
922
|
|
|
923
|
+
if(this._isNavigating) { cb(false); return; }
|
|
924
|
+
this._isNavigating = true;
|
|
925
|
+
|
|
906
926
|
this.currentLocation = this.positions.find(p => p.href === link!.href)!;
|
|
907
|
-
this.apply().then(() => this.loadLocator(locator, (ok) =>
|
|
927
|
+
this.apply().then(() => this.loadLocator(locator, (ok) => {
|
|
928
|
+
this._isNavigating = false;
|
|
929
|
+
cb(ok);
|
|
930
|
+
})).then(() => {
|
|
908
931
|
// Now that we've gone to the right locator, we can attach the listeners.
|
|
909
932
|
// Doing this only at this stage reduces janky UI with multiple locator updates.
|
|
910
933
|
this.attachListener();
|
|
@@ -115,6 +115,9 @@ export class FrameManager {
|
|
|
115
115
|
this.frame.style.opacity = "0";
|
|
116
116
|
this.frame.style.pointerEvents = "none";
|
|
117
117
|
this.hidden = true;
|
|
118
|
+
// Return focus to the parent document so keyboard events aren't silently
|
|
119
|
+
// swallowed by a hidden iframe whose comms channel has been halted.
|
|
120
|
+
this.frame.blur();
|
|
118
121
|
if(this.frame.parentElement) {
|
|
119
122
|
if(this.comms === undefined || !this.comms.ready) return;
|
|
120
123
|
return new Promise((res, _) => {
|
|
@@ -199,6 +199,9 @@ export class FXLFrameManager {
|
|
|
199
199
|
async unfocus(): Promise<void> {
|
|
200
200
|
if(this.frame.parentElement) {
|
|
201
201
|
if(this.comms === undefined) return;
|
|
202
|
+
// Return focus to the parent document so keyboard events aren't silently
|
|
203
|
+
// swallowed by an off-screen iframe whose comms channel has been halted.
|
|
204
|
+
this.frame.blur();
|
|
202
205
|
return new Promise((res, _) => {
|
|
203
206
|
this.comms?.send("unfocus", undefined, (_: boolean) => {
|
|
204
207
|
this.comms?.halt();
|
|
@@ -72,6 +72,7 @@ export class WebPubNavigator extends VisualNavigator implements Configurable<Web
|
|
|
72
72
|
private _css: WebPubCSS;
|
|
73
73
|
private _preferencesEditor: WebPubPreferencesEditor | null = null;
|
|
74
74
|
private readonly _injector: Injector | null = null;
|
|
75
|
+
private _isNavigating = false;
|
|
75
76
|
private readonly _contentProtection: IContentProtectionConfig;
|
|
76
77
|
private readonly _keyboardPeripherals: IKeyboardPeripheralsConfig;
|
|
77
78
|
private readonly _navigatorProtector: NavigatorProtector | null = null;
|
|
@@ -463,14 +464,20 @@ export class WebPubNavigator extends VisualNavigator implements Configurable<Web
|
|
|
463
464
|
}
|
|
464
465
|
|
|
465
466
|
goBackward(_animated: boolean, cb: (ok: boolean) => void): void {
|
|
466
|
-
this.
|
|
467
|
-
|
|
467
|
+
if(this._isNavigating) { cb(false); return; }
|
|
468
|
+
this._isNavigating = true;
|
|
469
|
+
this.changeResource(-1).then((ok) => {
|
|
470
|
+
this._isNavigating = false;
|
|
471
|
+
cb(ok);
|
|
468
472
|
});
|
|
469
473
|
}
|
|
470
474
|
|
|
471
475
|
goForward(_animated: boolean, cb: (ok: boolean) => void): void {
|
|
472
|
-
this.
|
|
473
|
-
|
|
476
|
+
if(this._isNavigating) { cb(false); return; }
|
|
477
|
+
this._isNavigating = true;
|
|
478
|
+
this.changeResource(1).then((ok) => {
|
|
479
|
+
this._isNavigating = false;
|
|
480
|
+
cb(ok);
|
|
474
481
|
});
|
|
475
482
|
}
|
|
476
483
|
|
|
@@ -581,8 +588,14 @@ export class WebPubNavigator extends VisualNavigator implements Configurable<Web
|
|
|
581
588
|
this.currentIndex = index;
|
|
582
589
|
}
|
|
583
590
|
|
|
591
|
+
if(this._isNavigating) { cb(false); return; }
|
|
592
|
+
this._isNavigating = true;
|
|
593
|
+
|
|
584
594
|
this.currentLocation = this.createCurrentLocator();
|
|
585
|
-
this.apply().then(() => this.loadLocator(locator, (ok) =>
|
|
595
|
+
this.apply().then(() => this.loadLocator(locator, (ok) => {
|
|
596
|
+
this._isNavigating = false;
|
|
597
|
+
cb(ok);
|
|
598
|
+
})).then(() => {
|
|
586
599
|
// Now that we've gone to the right locator, we can attach the listeners.
|
|
587
600
|
// Doing this only at this stage reduces janky UI with multiple locator updates.
|
|
588
601
|
this.attachListener();
|
|
@@ -50,6 +50,7 @@ export declare class EpubNavigator extends VisualNavigator implements Configurab
|
|
|
50
50
|
private _css;
|
|
51
51
|
private _preferencesEditor;
|
|
52
52
|
private _injector;
|
|
53
|
+
private _isNavigating;
|
|
53
54
|
private readonly _readiumRulesPromise;
|
|
54
55
|
private readonly _injectablesConfig;
|
|
55
56
|
private readonly _contentProtection;
|
|
@@ -44,6 +44,7 @@ export declare class WebPubNavigator extends VisualNavigator implements Configur
|
|
|
44
44
|
private _css;
|
|
45
45
|
private _preferencesEditor;
|
|
46
46
|
private readonly _injector;
|
|
47
|
+
private _isNavigating;
|
|
47
48
|
private readonly _contentProtection;
|
|
48
49
|
private readonly _keyboardPeripherals;
|
|
49
50
|
private readonly _navigatorProtector;
|