@readium/navigator 2.5.2-beta.2 → 2.5.2-beta.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readium/navigator",
3
- "version": "2.5.2-beta.2",
3
+ "version": "2.5.2-beta.4",
4
4
  "type": "module",
5
5
  "description": "Next generation SDK for publications in Web Apps",
6
6
  "author": "readium",
@@ -3,6 +3,7 @@ import { FrameComms } from "./FrameComms.ts";
3
3
  import type { ReadiumWindow } from "../../../../navigator-html-injectables/types/src/helpers/dom";
4
4
  import { sML } from "../../helpers/index.ts";
5
5
  import type { IContentProtectionConfig, IKeyboardPeripheralsConfig } from "../../Navigator.ts";
6
+ import { KeyboardConditionBridge } from "../../peripherals/KeyboardConditionBridge.ts";
6
7
 
7
8
 
8
9
  export class FrameManager {
@@ -14,6 +15,7 @@ export class FrameManager {
14
15
  private destroyed: boolean = false;
15
16
  private readonly contentProtectionConfig: IContentProtectionConfig;
16
17
  private readonly keyboardPeripheralsConfig: IKeyboardPeripheralsConfig;
18
+ private conditionBridge?: KeyboardConditionBridge;
17
19
  private currModules: ModuleName[] = [];
18
20
 
19
21
  constructor(
@@ -74,9 +76,17 @@ export class FrameManager {
74
76
  // Send content protection config
75
77
  this.comms!.send("peripherals_protection", this.contentProtectionConfig);
76
78
 
77
- // Send keyboard peripherals separately
79
+ // Send keyboard peripherals, filtered through condition bridge
78
80
  if (this.keyboardPeripheralsConfig && this.keyboardPeripheralsConfig.length > 0) {
79
- this.comms!.send("keyboard_peripherals", this.keyboardPeripheralsConfig);
81
+ this.conditionBridge?.destroy();
82
+ this.conditionBridge = new KeyboardConditionBridge(
83
+ this.keyboardPeripheralsConfig,
84
+ (serializable) => {
85
+ if (serializable.length > 0)
86
+ this.comms!.send("keyboard_peripherals", serializable);
87
+ }
88
+ );
89
+ this.conditionBridge.setup();
80
90
  }
81
91
 
82
92
  // Apply scroll protection
@@ -91,6 +101,7 @@ export class FrameManager {
91
101
  }
92
102
 
93
103
  async destroy() {
104
+ this.conditionBridge?.destroy();
94
105
  await this.hide();
95
106
  this.loader?.destroy();
96
107
  this.frame.remove();
@@ -0,0 +1,47 @@
1
+ import { KeyCombo, KeyboardPeripheral } from "@readium/navigator-html-injectables";
2
+
3
+ export class KeyboardConditionBridge {
4
+ private unsubs: Array<() => void> = [];
5
+ private conditionValues = new Map<KeyCombo, boolean>();
6
+
7
+ constructor(
8
+ private config: KeyboardPeripheral[],
9
+ private onUpdate: (serializable: KeyboardPeripheral[]) => void
10
+ ) {}
11
+
12
+ setup() {
13
+ let initializing = true;
14
+
15
+ this.config.forEach(peripheral =>
16
+ peripheral.keyCombos.forEach(combo => {
17
+ if (combo.condition) {
18
+ const unsub = combo.condition.subscribe((value) => {
19
+ this.conditionValues.set(combo, value);
20
+ if (!initializing) this.onUpdate(this.buildSerializable());
21
+ });
22
+ this.unsubs.push(unsub);
23
+ }
24
+ })
25
+ );
26
+
27
+ initializing = false;
28
+ this.onUpdate(this.buildSerializable());
29
+ }
30
+
31
+ private buildSerializable(): KeyboardPeripheral[] {
32
+ return this.config
33
+ .map(peripheral => ({
34
+ ...peripheral,
35
+ keyCombos: peripheral.keyCombos
36
+ .filter(combo => !combo.condition || this.conditionValues.get(combo) === true)
37
+ .map(({ condition, ...rest }) => rest),
38
+ }))
39
+ .filter(p => p.keyCombos.length > 0);
40
+ }
41
+
42
+ destroy() {
43
+ this.unsubs.forEach(u => u());
44
+ this.unsubs = [];
45
+ this.conditionValues.clear();
46
+ }
47
+ }
@@ -3,6 +3,7 @@ import { FrameComms } from "../epub/frame/FrameComms.ts";
3
3
  import type { ReadiumWindow } from "../../../navigator-html-injectables/types/src/helpers/dom";
4
4
  import { sML } from "../helpers/index.ts";
5
5
  import { IContentProtectionConfig, IKeyboardPeripheralsConfig } from "../Navigator.ts";
6
+ import { KeyboardConditionBridge } from "../peripherals/KeyboardConditionBridge.ts";
6
7
 
7
8
  export class WebPubFrameManager {
8
9
  private frame: HTMLIFrameElement;
@@ -13,6 +14,7 @@ export class WebPubFrameManager {
13
14
  private destroyed: boolean = false;
14
15
  private readonly contentProtectionConfig: IContentProtectionConfig;
15
16
  private readonly keyboardPeripheralsConfig: IKeyboardPeripheralsConfig;
17
+ private conditionBridge?: KeyboardConditionBridge;
16
18
  private currModules: ModuleName[] = [];
17
19
 
18
20
  constructor(
@@ -72,9 +74,17 @@ export class WebPubFrameManager {
72
74
  // Send content protection config
73
75
  this.comms!.send("peripherals_protection", this.contentProtectionConfig);
74
76
 
75
- // Send keyboard peripherals separately
77
+ // Send keyboard peripherals, filtered through condition bridge
76
78
  if (this.keyboardPeripheralsConfig && this.keyboardPeripheralsConfig.length > 0) {
77
- this.comms!.send("keyboard_peripherals", this.keyboardPeripheralsConfig);
79
+ this.conditionBridge?.destroy();
80
+ this.conditionBridge = new KeyboardConditionBridge(
81
+ this.keyboardPeripheralsConfig,
82
+ (serializable) => {
83
+ if (serializable.length > 0)
84
+ this.comms!.send("keyboard_peripherals", serializable);
85
+ }
86
+ );
87
+ this.conditionBridge.setup();
78
88
  }
79
89
 
80
90
  // Apply scroll protection if enabled
@@ -89,6 +99,7 @@ export class WebPubFrameManager {
89
99
  }
90
100
 
91
101
  async destroy() {
102
+ this.conditionBridge?.destroy();
92
103
  await this.hide();
93
104
  this.loader?.destroy();
94
105
  this.frame.remove();
@@ -10,6 +10,7 @@ export declare class FrameManager {
10
10
  private destroyed;
11
11
  private readonly contentProtectionConfig;
12
12
  private readonly keyboardPeripheralsConfig;
13
+ private conditionBridge?;
13
14
  private currModules;
14
15
  constructor(source: string, contentProtectionConfig?: IContentProtectionConfig, keyboardPeripheralsConfig?: IKeyboardPeripheralsConfig);
15
16
  load(modules: ModuleName[]): Promise<Window>;
@@ -0,0 +1,11 @@
1
+ import { KeyboardPeripheral } from "@readium/navigator-html-injectables";
2
+ export declare class KeyboardConditionBridge {
3
+ private config;
4
+ private onUpdate;
5
+ private unsubs;
6
+ private conditionValues;
7
+ constructor(config: KeyboardPeripheral[], onUpdate: (serializable: KeyboardPeripheral[]) => void);
8
+ setup(): void;
9
+ private buildSerializable;
10
+ destroy(): void;
11
+ }
@@ -10,6 +10,7 @@ export declare class WebPubFrameManager {
10
10
  private destroyed;
11
11
  private readonly contentProtectionConfig;
12
12
  private readonly keyboardPeripheralsConfig;
13
+ private conditionBridge?;
13
14
  private currModules;
14
15
  constructor(source: string, contentProtectionConfig?: IContentProtectionConfig, keyboardPeripheralsConfig?: IKeyboardPeripheralsConfig);
15
16
  load(modules?: ModuleName[]): Promise<Window>;