@readium/navigator-html-injectables 2.4.2-beta.1 → 2.4.2-beta.3

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-html-injectables",
3
- "version": "2.4.2-beta.1",
3
+ "version": "2.4.2-beta.3",
4
4
  "type": "module",
5
5
  "description": "An embeddable solution for connecting frames of HTML publications with a Readium Navigator",
6
6
  "author": "readium",
@@ -19,19 +19,30 @@ export class KeyCombinationManager {
19
19
  */
20
20
  public match(event: KeyboardEvent, combos: KeyCombo[]): boolean {
21
21
  for (const combo of combos) {
22
- const keyMatch = event.keyCode === combo.keyCode;
23
- const ctrlMatch = combo.ctrl === undefined || event.ctrlKey === combo.ctrl;
24
- const shiftMatch = combo.shift === undefined || event.shiftKey === combo.shift;
25
- const altMatch = combo.alt === undefined || event.altKey === combo.alt;
26
- const metaMatch = combo.meta === undefined || event.metaKey === combo.meta;
27
-
28
- if (keyMatch && ctrlMatch && shiftMatch && altMatch && metaMatch) {
22
+ if (this.matchesCombo(event, combo)) {
29
23
  return true;
30
24
  }
31
25
  }
32
26
  return false;
33
27
  }
34
28
 
29
+ private matchesCombo(event: KeyboardEvent, combo: KeyCombo): boolean {
30
+ return event.keyCode === combo.keyCode &&
31
+ this.matchesModifier(event.ctrlKey, combo.ctrl) &&
32
+ this.matchesModifier(event.shiftKey, combo.shift) &&
33
+ this.matchesModifier(event.altKey, combo.alt) &&
34
+ this.matchesModifier(event.metaKey, combo.meta);
35
+ }
36
+
37
+ private matchesModifier(eventModifier: boolean, comboModifier?: boolean): boolean {
38
+ if (comboModifier === undefined) {
39
+ // Modifier not specified: must NOT be pressed
40
+ return !eventModifier;
41
+ }
42
+ // Modifier specified: must match exactly
43
+ return eventModifier === comboModifier;
44
+ }
45
+
35
46
  /**
36
47
  * Creates an event handler that will call the provided handler when any of the key combinations match
37
48
  */
@@ -139,7 +150,7 @@ export class KeyCombinationManager {
139
150
  if (this.match(event, [handlerConfig])) {
140
151
  const suppress = handlerConfig.suppressOnInteractiveElement;
141
152
  if (suppress) {
142
- const active = document.activeElement;
153
+ const active = (wnd?.document ?? document).activeElement;
143
154
  if (Array.isArray(suppress) ? suppress.some(sel => active?.matches(sel)) : isInteractiveElement(active)) return;
144
155
  }
145
156
  event.preventDefault();
@@ -14,6 +14,8 @@ export declare class KeyCombinationManager {
14
14
  * Checks if the given keyboard event matches any of the provided key combinations
15
15
  */
16
16
  match(event: KeyboardEvent, combos: KeyCombo[]): boolean;
17
+ private matchesCombo;
18
+ private matchesModifier;
17
19
  /**
18
20
  * Creates an event handler that will call the provided handler when any of the key combinations match
19
21
  */