umbr-key-master 1.0.2 → 1.0.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/README.md CHANGED
@@ -1,107 +1,120 @@
1
1
  # KeyMaster
2
2
 
3
- `KeyMaster` is a TypeScript library for managing complex keyboard shortcuts and key combinations in the browser. It allows you to register callbacks for specific key sequences, supporting all W3C/DOM-standard key types.
3
+ `KeyMaster` is a TypeScript library for managing complex keyboard shortcuts and key combinations in the browser. It allows you to register callbacks for specific key sequences, supporting all W3C/DOM-standard key values.
4
4
 
5
5
  ---
6
6
 
7
7
  ## Features
8
8
 
9
- * Listen to single keys or combinations of multiple keys.
10
- * Supports all standard key types, including:
11
-
12
- * Alphabet keys (A-Z)
13
- * Control characters (Enter, Escape, etc.)
14
- * Modifier keys (Shift, Ctrl, Alt, Meta)
15
- * Navigation keys (Arrow keys, Home, End, etc.)
16
- * Function keys (F1-F12)
17
- * Multimedia and Audio keys
18
- * And more…
19
- * Optional callback data via a custom function.
20
- * Easy registration and removal of callbacks.
21
- * Handles multiple key presses simultaneously.
22
- * Safe cleanup of event listeners.
9
+ * **Multi-Key Support**: Listen to single keys or complex combinations (e.g., `Ctrl + Shift + S`).
10
+ * **Standard Compliant**: Supports all standard key types defined by the W3C UI Events spec:
11
+ * **Alphabet keys** (A-Z)
12
+ * **Control keys** (Enter, Escape, Backspace)
13
+ * **Modifier keys** (Shift, Ctrl, Alt, Meta)
14
+ * **Navigation keys** (Arrow keys, Home, End)
15
+ * **Function keys** (F1-F12)
16
+ * **Multimedia & Device keys**
17
+
18
+
19
+ * **Contextual Data**: Pass custom data or state to your callbacks automatically.
20
+ * **Memory Safe**: Simple `dispose()` method to clean up event listeners and prevent memory leaks.
23
21
 
24
22
  ---
25
23
 
26
24
  ## Installation
27
25
 
28
26
  ```bash
29
- npm i umbr-key-master
27
+ npm install umbr-key-master
28
+
30
29
  ```
31
30
 
32
31
  ---
33
32
 
34
33
  ## Usage
35
34
 
36
- ```ts
37
- import { KeyMaster } from "umbr-key-master";
38
- import { Alphabet, ModifierKey } from "umbr-key-master/w3";
35
+ ```typescript
36
+ import { KeyMaster, PressableKey } from "umbr-key-master";
39
37
 
40
- // Optional function to provide custom data to callbacks
41
- const getData = () => ({ user: "Alice" });
38
+ // 1. (Optional) Define a function to provide context/data to your callbacks
39
+ const getContext = () => ({
40
+ timestamp: Date.now(),
41
+ activeEditor: "main-text-area"
42
+ });
42
43
 
43
- // Initialize KeyMaster
44
- const km = new KeyMaster(getData);
44
+ // 2. Initialize KeyMaster
45
+ const km = new KeyMaster(getContext);
45
46
 
46
- // Register a key combination (Shift + A)
47
- km.add([ModifierKey.Shift, Alphabet.A], (data) => {
48
- console.log("Shift + A pressed!", data);
47
+ // 3. Register a key combination (e.g., Shift + A)
48
+ // Note: Key strings match W3C "key" values
49
+ km.add(["Shift", "a"], (data) => {
50
+ console.log("Combination triggered!", data);
49
51
  });
50
52
 
51
- // Register another combination (Ctrl + B)
52
- km.add([ModifierKey.Control, Alphabet.B], () => {
53
- console.log("Ctrl + B pressed!");
53
+ // 4. Register a single key callback
54
+ km.add(["Enter"], () => {
55
+ console.log("Enter key was pressed");
54
56
  });
55
57
 
56
- // Remove a callback
57
- const callback = (data: any) => console.log("This will be removed", data);
58
- km.add([Alphabet.C], callback);
59
- km.remove(callback);
58
+ // 5. Removing a callback
59
+ const myCallback = () => console.log("Temporary shortcut");
60
+ km.add(["Control", "s"], myCallback);
61
+
62
+ // Later...
63
+ km.remove(myCallback);
60
64
 
61
- // Dispose when done to clean up event listeners
65
+ // 6. Clean up when the component or page is destroyed
62
66
  km.dispose();
67
+
63
68
  ```
64
69
 
65
70
  ---
66
71
 
67
- ## API
72
+ ## API Reference
68
73
 
69
- ### `constructor(getDataFunc?: () => any | Promise<any>)`
74
+ ### `constructor(getDataFunc?: GetDataCallback)`
70
75
 
71
- * `getDataFunc` (optional): Function that returns custom data passed to callbacks.
76
+ Initializes the listener.
72
77
 
73
- ### `add(targetKeys: PressableKey[], callback: KeyCallback)`
78
+ * **`getDataFunc`**: (Optional) A sync or async function. The return value of this function is passed as the first argument to every triggered callback.
74
79
 
75
- * Registers a callback for a specific key combination.
76
- * `targetKeys`: Array of keys to listen for.
77
- * `callback`: Function to execute when the keys are pressed.
80
+ ### `add(targetKeys: PressableKey[], callback: KeyCallback): void`
78
81
 
79
- ### `remove(callback: KeyCallback)`
82
+ Registers a callback to a specific combination.
80
83
 
81
- * Removes a previously registered callback.
84
+ * **`targetKeys`**: An array of `PressableKey` strings. The order does not matter as the library sorts them internally.
85
+ * **`callback`**: The function to run when all keys in the array (and *only* those keys) are held down.
82
86
 
83
- ### `dispose()`
87
+ ### `remove(callback: KeyCallback): void`
84
88
 
85
- * Cleans up all event listeners and callbacks. Call this before destroying KeyMaster.
89
+ Unregisters a specific callback function from all key combinations it was assigned to.
90
+
91
+ ### `dispose(): void`
92
+
93
+ Removes the `keydown` and `keyup` listeners from the `document` and clears all internal maps. Use this during component unmounting or page transitions.
86
94
 
87
95
  ---
88
96
 
89
- ## Key Types
97
+ ## Supported Key Categories
90
98
 
91
- The library supports all keys defined in the W3C UI Events/DOM specification. Examples include:
99
+ The library utilizes the full W3C UI Events key set. Common categories include:
92
100
 
93
- * `Alphabet` A-Z
94
- * `ControlCharacter` Enter, Escape, Backspace, etc.
95
- * `ModifierKey` Shift, Control, Alt, Meta
96
- * `NavigationKey` ArrowUp, ArrowDown, Home, End
97
- * `FunctionKey` F1-F12
98
- * `MultimediaKey` VolumeUp, Play, Pause
99
- * `AudioKey` Mute, VolumeDown
100
- * `WhitespaceKey` → Space, Tab
101
- * And many more…
101
+ | Category | Examples |
102
+ | --- | --- |
103
+ | **Modifiers** | `Shift`, `Control`, `Alt`, `Meta` |
104
+ | **Navigation** | `ArrowUp`, `ArrowDown`, `Home`, `PageUp` |
105
+ | **Editing** | `Backspace`, `Delete`, `Enter`, `Tab` |
106
+ | **UI Control** | `Escape`, `ContextMenu`, `Pause` |
107
+ | **Functions** | `F1` through `F20` |
108
+
109
+ ---
102
110
 
103
111
  ## License
104
112
 
105
113
  MIT © Yousaf Wazir
106
114
 
107
115
 
116
+ # Building
117
+
118
+ - Change version up - push git change
119
+ - Run `npm run build`
120
+ - Run `npm run pubish`
package/dist/index.d.ts CHANGED
@@ -1,46 +1,63 @@
1
- import { Alphabet, AudioKey, ControlCharacter, DeviceKey, EditingKey, FunctionKey, GlyphModifierKey, IMEKey, ModifierKey, MultimediaKey, MultimediaNumpadKey, NavigationKey, SpecialKey, SpeechKey, UIKey, WhitespaceKey } from "./w3";
1
+ import { DeviceKey, EditingKey, FunctionKey, GlyphModifierKey, ModifierKey, NavigationKey, SpecialKey, UIEventUnicodeKey, UIKey, UnicodeControlKey, WhitespaceKey } from "./w3ckeyAttributeValues";
2
2
  /**
3
- * Helper used to get custom data to pass to your callback when its conditions are met
3
+ * Additional options for the KeyMaster instance.
4
4
  */
5
- type GetDataCallback = (() => any | Promise<any>) | null;
5
+ export type KeyMasterOptions = {
6
+ /**
7
+ * If true, key comparisons will ignore casing (e.g., 'A' and 'a' are treated as the same key).
8
+ * @default false
9
+ */
10
+ caseInsensitive?: boolean;
11
+ };
12
+ /**
13
+ * A function used to retrieve custom data passed to callbacks when conditions are met.
14
+ */
15
+ export type GetDataCallback = (() => any | Promise<any>) | null;
6
16
  /**
7
- * The key value of a keydown can be mapped from W3C UI Events / DOM spec
8
- *
9
- * these are what a keydown / keyup `key` value can be and is what you can pass to listen to specific combinations to trigger logic
17
+ * Union type of valid key values mapped from the W3C UI Events / DOM specification.
10
18
  */
11
- type PressableKey = Alphabet | ControlCharacter | GlyphModifierKey | SpecialKey | ModifierKey | WhitespaceKey | NavigationKey | EditingKey | UIKey | DeviceKey | IMEKey | FunctionKey | MultimediaKey | MultimediaNumpadKey | AudioKey | SpeechKey;
19
+ export type PressableKey = UIEventUnicodeKey | UnicodeControlKey | GlyphModifierKey | SpecialKey | ModifierKey | WhitespaceKey | NavigationKey | EditingKey | UIKey | DeviceKey | FunctionKey;
12
20
  /**
13
- * Custom callback to run when the specific keys registered are met
21
+ * A callback function executed when registered key combinations are triggered.
14
22
  */
15
- type KeyCallback = (...args: any[]) => any | Promise<any>;
23
+ export type KeyCallback = (data: any) => any | Promise<any>;
16
24
  /**
17
- * Represents a key combination manager that holds callbacks to run for specific key combinations
25
+ * Manages keyboard shortcuts and multi-key combinations.
26
+ * Supports case-insensitive matching and contextual data injection.
18
27
  */
19
28
  export declare class KeyMaster {
20
29
  private _getData;
21
- /**
22
- * Holds a list of current keys being pressed down
23
- */
24
30
  private readonly _keys;
31
+ private readonly _callbacks;
32
+ private _options;
25
33
  /**
26
- * Contains all the callbacks to run
34
+ * @param getDataFunc - Optional helper to provide data to callbacks.
35
+ * @param options - Configuration options for key handling.
27
36
  */
28
- private readonly _callbacks;
29
- constructor(getDataFunc?: GetDataCallback);
37
+ constructor(getDataFunc?: GetDataCallback, options?: KeyMasterOptions);
30
38
  /**
31
- * Creates a key for list of pressable keys
32
- * @param keys The list of keys to make an ID for specific callbacks
33
- * @returns Key
39
+ * Normalizes an array of keys into a sorted string ID.
40
+ * Handles case normalization if caseInsensitive is enabled.
34
41
  */
35
42
  private makeKey;
36
43
  private handleKeyDown;
37
- private run;
38
44
  private handleKeyUp;
45
+ /**
46
+ * Executes a list of callbacks with injected data.
47
+ */
48
+ private run;
49
+ /**
50
+ * Registers a callback for a specific combination of keys.
51
+ * @param targetKeys - Array of keys (e.g., ["Control", "S"]).
52
+ * @param callback - Function to trigger.
53
+ */
39
54
  add(targetKeys: PressableKey[], callback: KeyCallback): void;
55
+ /**
56
+ * Removes a callback from all registered combinations.
57
+ */
40
58
  remove(callback: KeyCallback): void;
41
59
  /**
42
- * Call before destroying to clean up event listeners
60
+ * Cleans up event listeners and internal state.
43
61
  */
44
62
  dispose(): void;
45
63
  }
46
- export {};
package/dist/index.js CHANGED
@@ -8,43 +8,54 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  /**
11
- * Represents a key combination manager that holds callbacks to run for specific key combinations
11
+ * Manages keyboard shortcuts and multi-key combinations.
12
+ * Supports case-insensitive matching and contextual data injection.
12
13
  */
13
14
  export class KeyMaster {
14
- constructor(getDataFunc = null) {
15
+ /**
16
+ * @param getDataFunc - Optional helper to provide data to callbacks.
17
+ * @param options - Configuration options for key handling.
18
+ */
19
+ constructor(getDataFunc = null, options = {}) {
15
20
  this._getData = null;
16
- /**
17
- * Holds a list of current keys being pressed down
18
- */
19
21
  this._keys = new Set();
20
- /**
21
- * Contains all the callbacks to run
22
- */
23
22
  this._callbacks = new Map();
24
23
  this.handleKeyDown = (event) => {
25
- this._keys.add(event.key);
24
+ const keyToStore = this._options.caseInsensitive
25
+ ? event.key.toLowerCase()
26
+ : event.key;
27
+ this._keys.add(keyToStore);
26
28
  const pressed = Array.from(this._keys.values());
27
- const key = this.makeKey(pressed);
28
- const callbacks = this._callbacks.get(key);
29
+ const comboId = this.makeKey(pressed);
30
+ const callbacks = this._callbacks.get(comboId);
29
31
  if (callbacks) {
30
32
  this.run(callbacks);
31
33
  }
32
34
  };
33
35
  this.handleKeyUp = (event) => {
34
- this._keys.delete(event.key);
36
+ const keyToRemove = this._options.caseInsensitive
37
+ ? event.key.toLowerCase()
38
+ : event.key;
39
+ this._keys.delete(keyToRemove);
35
40
  };
36
41
  this._getData = getDataFunc;
42
+ this._options = Object.assign({ caseInsensitive: false }, options);
37
43
  document.addEventListener("keydown", this.handleKeyDown);
38
44
  document.addEventListener("keyup", this.handleKeyUp);
39
45
  }
40
46
  /**
41
- * Creates a key for list of pressable keys
42
- * @param keys The list of keys to make an ID for specific callbacks
43
- * @returns Key
47
+ * Normalizes an array of keys into a sorted string ID.
48
+ * Handles case normalization if caseInsensitive is enabled.
44
49
  */
45
50
  makeKey(keys) {
46
- return keys.sort().join("_");
51
+ const normalizedKeys = this._options.caseInsensitive
52
+ ? keys.map((k) => k.toLowerCase())
53
+ : keys;
54
+ return normalizedKeys.sort().join("_");
47
55
  }
56
+ /**
57
+ * Executes a list of callbacks with injected data.
58
+ */
48
59
  run(callbacks) {
49
60
  return __awaiter(this, void 0, void 0, function* () {
50
61
  const data = this._getData ? yield this._getData() : null;
@@ -53,26 +64,34 @@ export class KeyMaster {
53
64
  }
54
65
  });
55
66
  }
67
+ /**
68
+ * Registers a callback for a specific combination of keys.
69
+ * @param targetKeys - Array of keys (e.g., ["Control", "S"]).
70
+ * @param callback - Function to trigger.
71
+ */
56
72
  add(targetKeys, callback) {
57
- const key = this.makeKey(targetKeys);
58
- if (!this._callbacks.has(key)) {
59
- this._callbacks.set(key, []);
73
+ const comboId = this.makeKey(targetKeys);
74
+ if (!this._callbacks.has(comboId)) {
75
+ this._callbacks.set(comboId, []);
60
76
  }
61
- this._callbacks.get(key).push(callback);
77
+ this._callbacks.get(comboId).push(callback);
62
78
  }
79
+ /**
80
+ * Removes a callback from all registered combinations.
81
+ */
63
82
  remove(callback) {
64
- for (const [key, callbacks] of this._callbacks.entries()) {
83
+ for (const [comboId, callbacks] of this._callbacks.entries()) {
65
84
  const index = callbacks.indexOf(callback);
66
85
  if (index !== -1) {
67
86
  callbacks.splice(index, 1);
68
87
  if (callbacks.length === 0) {
69
- this._callbacks.delete(key);
88
+ this._callbacks.delete(comboId);
70
89
  }
71
90
  }
72
91
  }
73
92
  }
74
93
  /**
75
- * Call before destroying to clean up event listeners
94
+ * Cleans up event listeners and internal state.
76
95
  */
77
96
  dispose() {
78
97
  document.removeEventListener("keydown", this.handleKeyDown);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;AAoDA;;GAEG;AACH,MAAM,OAAO,SAAS;IAapB,YAAY,cAA+B,IAAI;QAZvC,aAAQ,GAAoB,IAAI,CAAC;QAEzC;;WAEG;QACc,UAAK,GAAG,IAAI,GAAG,EAAgB,CAAC;QAEjD;;WAEG;QACc,eAAU,GA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CAAC,OAAO,EAAE,EAAE,CAAC;YAC7D,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAC1C,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;gBACjB,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;gBAC3B,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBAC3B,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBAClC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACH,OAAO;QACL,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAC5D,QAAQ,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACxD,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,242 @@
1
+ /**
2
+ * Contains the Keyboard Event key Attribute Values from https://www.w3.org/TR/uievents-key/#key-attr-values mapped into Typescript types
3
+ */
4
+ /**
5
+ * @see {@link https://www.w3.org/TR/uievents-key/#keys-unicode}
6
+ * 2.1. Unicode Values
7
+ * * A key string is a string containing a 0 or 1 non-control characters
8
+ * ("base" characters) followed by 0 or more combining characters.
9
+ * The string MUST be in Normalized Form C (NFC).
10
+ */
11
+ /**
12
+ * Standard English (Latin-1) printable character set used as key attribute values.
13
+ */
14
+ export type UnicodeKeyEnglish = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" | "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "!" | '"' | "#" | "$" | "%" | "&" | "'" | "(" | ")" | "*" | "+" | "," | "-" | "." | "/" | ":" | ";" | "<" | "=" | ">" | "?" | "@" | "[" | "\\" | "]" | "^" | "_" | "`" | "{" | "|" | "}" | "~";
15
+ /**
16
+ * Non-control whitespace Unicode characters defined in the spec.
17
+ * Note: Tab and Enter are defined as named control keys in § 2.1.1.
18
+ */
19
+ export type UnicodeWhitespaceKey =
20
+ /** U+0020 Space */
21
+ " "
22
+ /** U+00A0 No-Break Space */
23
+ | "\u00A0"
24
+ /** U+2009 Thin Space */
25
+ | "\u2009"
26
+ /** U+3000 Ideographic Space */
27
+ | "\u3000";
28
+ /**
29
+ * Union of Section 2.1 compliant English characters and whitespace.
30
+ */
31
+ export type UIEventUnicodeKey = UnicodeKeyEnglish | UnicodeWhitespaceKey;
32
+ /**
33
+ * @see {@link https://www.w3.org/TR/uievents-key/#keys-unicode}
34
+ * 2.1.1. Control Characters
35
+ * * A small number of characters in the Unicode "Cc" General Category
36
+ * are supported as named key attribute values.
37
+ */
38
+ export type UnicodeControlKey =
39
+ /** U+0008 */
40
+ "Backspace"
41
+ /** U+0009 */
42
+ | "Tab"
43
+ /** U+000D */
44
+ | "Enter"
45
+ /** U+001B */
46
+ | "Escape"
47
+ /** U+007F */
48
+ | "Delete";
49
+ /**
50
+ * @see {@link https://www.w3.org/TR/uievents-key/#keys-unicode}
51
+ * 2.2. Selecting key Attribute Values
52
+ * * A glyph modifier key is any of the following modifier keys:
53
+ * Shift, CapsLock or AltGr.
54
+ */
55
+ export type GlyphModifierKey = "Shift" | "CapsLock" | "AltGr";
56
+ /**
57
+ * @see {@link https://www.w3.org/TR/uievents-key/#keys-unicode}
58
+ * 3.1. Special Keys
59
+ * * This key value is used when an implementation is unable to identify
60
+ * another key value, due to either hardware, platform, or software constraints.
61
+ */
62
+ export type SpecialKey = "Unidentified";
63
+ /**
64
+ * @see {@link https://www.w3.org/TR/uievents-key/#keys-unicode}
65
+ * 3.2. Modifier Keys
66
+ * * Modifier keys enable alternate functions for interpreting keyboard input.
67
+ */
68
+ export type ModifierKey =
69
+ /** The Alt (Alternative) key. Used also for the Apple Option key. */
70
+ "Alt"
71
+ /** The Alternate Graphics (AltGr or AltGraph) key. */
72
+ | "AltGraph"
73
+ /** The Caps Lock (Capital) key. Toggles capital character lock. */
74
+ | "CapsLock"
75
+ /** The Control or Ctrl key. */
76
+ | "Control"
77
+ /** The Function switch Fn key. Often handled in hardware. */
78
+ | "Fn"
79
+ /** The Function-Lock (FnLock or F-Lock) key. */
80
+ | "FnLock"
81
+ /** The Meta key. Used for the Windows Logo key and Apple Command key. */
82
+ | "Meta"
83
+ /** The NumLock or Number Lock key. */
84
+ | "NumLock"
85
+ /** The Scroll Lock key. */
86
+ | "ScrollLock"
87
+ /** The Shift key. */
88
+ | "Shift"
89
+ /** The Symbol modifier key (virtual keyboards). */
90
+ | "Symbol"
91
+ /** The Symbol Lock key. */
92
+ | "SymbolLock"
93
+ /** Legacy: The Hyper key. */
94
+ | "Hyper"
95
+ /** Legacy: The Super key. */
96
+ | "Super";
97
+ /**
98
+ * @see {@link https://www.w3.org/TR/uievents-key/#keys-unicode}
99
+ * 3.3. Whitespace Keys
100
+ * * This section defines keys that represent whitespace-related actions.
101
+ */
102
+ export type WhitespaceKey =
103
+ /** * The Enter or ↵ key. Used for Return (Macintosh) and
104
+ * Android KEYCODE_DPAD_CENTER.
105
+ */
106
+ "Enter"
107
+ /** The Horizontal Tabulation Tab key. */
108
+ | "Tab";
109
+ /**
110
+ * @see {@link https://www.w3.org/TR/uievents-key/#keys-unicode}
111
+ * 3.4. Navigation Keys
112
+ * * Navigation keys are used for moving the cursor or scrolling the viewport.
113
+ */
114
+ export type NavigationKey =
115
+ /** The down arrow key. (KEYCODE_DPAD_DOWN) */
116
+ "ArrowDown"
117
+ /** The left arrow key. (KEYCODE_DPAD_LEFT) */
118
+ | "ArrowLeft"
119
+ /** The right arrow key. (KEYCODE_DPAD_RIGHT) */
120
+ | "ArrowRight"
121
+ /** The up arrow key. (KEYCODE_DPAD_UP) */
122
+ | "ArrowUp"
123
+ /** The End key. (KEYCODE_MOVE_END) */
124
+ | "End"
125
+ /** The Home key. (KEYCODE_MOVE_HOME) */
126
+ | "Home"
127
+ /** The Page Down key. */
128
+ | "PageDown"
129
+ /** The Page Up key. */
130
+ | "PageUp";
131
+ /**
132
+ * @see {@link https://www.w3.org/TR/uievents-key/#keys-unicode}
133
+ * 3.5. Editing Keys
134
+ * * Editing keys are used for manipulating text or content.
135
+ */
136
+ export type EditingKey =
137
+ /** The Backspace key. Also used for the 'Delete' label on MacOS. */
138
+ "Backspace"
139
+ /** Remove the currently selected input. */
140
+ | "Clear"
141
+ /** Copy the current selection. (APPCOMMAND_COPY) */
142
+ | "Copy"
143
+ /** The Cursor Select (Crsel) key. */
144
+ | "CrSel"
145
+ /** Cut the current selection. (APPCOMMAND_CUT) */
146
+ | "Cut"
147
+ /** The Delete (Del) Key. Also used for MacOS 'Delete' + 'Fn'. */
148
+ | "Delete"
149
+ /** The Erase to End of Field key. */
150
+ | "EraseEof"
151
+ /** The Extend Selection (Exsel) key. */
152
+ | "ExSel"
153
+ /** The Insert (Ins) key. (KEYCODE_INSERT) */
154
+ | "Insert"
155
+ /** The Paste key. (APPCOMMAND_PASTE) */
156
+ | "Paste"
157
+ /** Redo the last action. (APPCOMMAND_REDO) */
158
+ | "Redo"
159
+ /** Undo the last action. (APPCOMMAND_UNDO) */
160
+ | "Undo";
161
+ /**
162
+ * @see {@link https://www.w3.org/TR/uievents-key/#keys-unicode}
163
+ * 3.6. UI Keys
164
+ * * UI keys are used for user interface interactions, such as menus,
165
+ * dialogs, and application-level commands.
166
+ */
167
+ export type UIKey =
168
+ /** The Accept (Commit, OK) key. */
169
+ "Accept"
170
+ /** The Again key, to redo or repeat an action. */
171
+ | "Again"
172
+ /** The Attention (Attn) key. */
173
+ | "Attn"
174
+ /** The Cancel key. */
175
+ | "Cancel"
176
+ /** Show the application’s context menu. */
177
+ | "ContextMenu"
178
+ /** The Esc key, used to exit or "escape" the current context. */
179
+ | "Escape"
180
+ /** The Execute key. */
181
+ | "Execute"
182
+ /** Open the Find dialog. (APPCOMMAND_FIND) */
183
+ | "Find"
184
+ /** Open a help dialog. (APPCOMMAND_HELP, KEYCODE_HELP) */
185
+ | "Help"
186
+ /** Pause the current state. Not for media; use "MediaPause" instead. */
187
+ | "Pause"
188
+ /** Play or resume the current state. Not for media; use "MediaPlay" instead. */
189
+ | "Play"
190
+ /** The properties (Props) key. */
191
+ | "Props"
192
+ /** The Select key. */
193
+ | "Select"
194
+ /** The ZoomIn key. (KEYCODE_ZOOM_IN) */
195
+ | "ZoomIn"
196
+ /** The ZoomOut key. (KEYCODE_ZOOM_OUT) */
197
+ | "ZoomOut";
198
+ /**
199
+ * @see {@link https://www.w3.org/TR/uievents-key/#keys-unicode}
200
+ * 3.7. Device Keys
201
+ * * Device keys represent physical hardware controls, such as screen
202
+ * brightness and power management.
203
+ */
204
+ export type DeviceKey =
205
+ /** The Brightness Down key. (KEYCODE_BRIGHTNESS_DOWN) */
206
+ "BrightnessDown"
207
+ /** The Brightness Up key. (KEYCODE_BRIGHTNESS_UP) */
208
+ | "BrightnessUp"
209
+ /** Toggle removable media to eject or insert. (KEYCODE_MEDIA_EJECT) */
210
+ | "Eject"
211
+ /** The LogOff key. */
212
+ | "LogOff"
213
+ /** Toggle power state. Note: May not be exposed to the OS. (KEYCODE_POWER) */
214
+ | "Power"
215
+ /** The PowerOff key. Sometimes called PowerDown. */
216
+ | "PowerOff"
217
+ /** The Print Screen or SnapShot key. */
218
+ | "PrintScreen"
219
+ /** The Hibernate key. Saves state to disk and shuts down. */
220
+ | "Hibernate"
221
+ /** The Standby key. Low-power mode; sometimes labeled Suspend or Sleep. (KEYCODE_SLEEP) */
222
+ | "Standby"
223
+ /** The WakeUp key. (KEYCODE_WAKEUP) */
224
+ | "WakeUp";
225
+ /**
226
+ * @see {@link https://www.w3.org/TR/uievents-key/#keys-unicode}
227
+ * 3.9. General-Purpose Function Keys
228
+ * * General purpose function keys. Additional function key names are
229
+ * implicitly defined by incrementing the base-10 index at the end.
230
+ */
231
+ export type FunctionKey =
232
+ /** Explicitly defined function keys F1 through F12 */
233
+ "F1" | "F2" | "F3" | "F4" | "F5" | "F6" | "F7" | "F8" | "F9" | "F10" | "F11" | "F12"
234
+ /** * Implicitly defined F-keys (e.g., "F24").
235
+ * This template literal covers any string starting with F and a number.
236
+ */
237
+ | `F${number}`
238
+ /** Explicitly defined virtual function keys Soft1 through Soft4 */
239
+ | "Soft1" | "Soft2" | "Soft3" | "Soft4"
240
+ /** * Implicitly defined Soft-keys (e.g., "Soft8").
241
+ */
242
+ | `Soft${number}`;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Contains the Keyboard Event key Attribute Values from https://www.w3.org/TR/uievents-key/#key-attr-values mapped into Typescript types
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=w3ckeyAttributeValues.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"w3ckeyAttributeValues.js","sourceRoot":"","sources":["../src/w3ckeyAttributeValues.ts"],"names":[],"mappings":"AAAA;;GAEG"}
package/package.json CHANGED
@@ -1,25 +1,39 @@
1
- {
2
- "name": "umbr-key-master",
3
- "version": "1.0.2",
4
- "description": "JS library for managing complex keyboard shortcuts and key combinations in the browser",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "scripts": {
8
- "build": "tsc"
9
- },
10
- "keywords": [
11
- "key",
12
- "keyboard",
13
- "shortcut",
14
- "combination"
15
- ],
16
- "author": "Yousaf Wazir",
17
- "license": "ISC",
18
- "files": [
19
- "dist",
20
- "README.md"
21
- ],
22
- "devDependencies": {
23
- "typescript": "^5.9.3"
24
- }
25
- }
1
+ {
2
+ "name": "umbr-key-master",
3
+ "version": "1.0.4",
4
+ "description": "A lightweight, type-safe TypeScript library for managing complex keyboard shortcuts and multi-key combinations in the browser.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/UmbrellaCrow612/key-master.git"
10
+ },
11
+ "scripts": {
12
+ "build": "tsc"
13
+ },
14
+ "keywords": [
15
+ "key",
16
+ "keyboard",
17
+ "shortcut",
18
+ "hotkeys",
19
+ "key-combinations",
20
+ "typescript",
21
+ "dom-events",
22
+ "w3c-keys",
23
+ "event-listener",
24
+ "keyboard-manager"
25
+ ],
26
+ "author": "Yousaf Wazir",
27
+ "license": "ISC",
28
+ "bugs": {
29
+ "url": "https://github.com/UmbrellaCrow612/key-master/issues"
30
+ },
31
+ "homepage": "https://github.com/UmbrellaCrow612/key-master#readme",
32
+ "files": [
33
+ "dist",
34
+ "README.md"
35
+ ],
36
+ "devDependencies": {
37
+ "typescript": "^5.9.3"
38
+ }
39
+ }
package/dist/w3.d.ts DELETED
@@ -1,23 +0,0 @@
1
- /**
2
- * Mapped from https://www.w3.org/TR/uievents-key/#key-attr-values (only english set) for all values a keydown / keyup `key` can be mapped into
3
- * TS types for better intelisense
4
- */
5
- /**
6
- * Contains all english alphabet charcters inclduing uppercase
7
- */
8
- export type Alphabet = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" | "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z";
9
- export type ControlCharacter = "Backspace" | "Tab" | "Enter" | "Escape" | "Delete";
10
- export type GlyphModifierKey = "Shift" | "CapsLock" | "AltGr";
11
- export type SpecialKey = "Unidentified";
12
- export type ModifierKey = "Alt" | "AltGraph" | "CapsLock" | "Control" | "Fn" | "FnLock" | "Meta" | "NumLock" | "ScrollLock" | "Shift" | "Symbol" | "SymbolLock" | "Hyper" | "Super";
13
- export type WhitespaceKey = "Enter" | "Tab";
14
- export type NavigationKey = "ArrowDown" | "ArrowLeft" | "ArrowRight" | "ArrowUp" | "End" | "Home" | "GoHome" | "PageDown" | "PageUp";
15
- export type EditingKey = "Backspace" | "Clear" | "Copy" | "CrSel" | "Cut" | "Delete" | "EraseEof" | "ExSel" | "Insert" | "Paste" | "Redo" | "Undo";
16
- export type UIKey = "Accept" | "Again" | "Attn" | "Cancel" | "ContextMenu" | "Escape" | "Execute" | "Find" | "Help" | "Pause" | "Play" | "Props" | "Select" | "ZoomIn" | "ZoomOut";
17
- export type DeviceKey = "BrightnessDown" | "BrightnessUp" | "Eject" | "LogOff" | "Power" | "PowerOff" | "PrintScreen" | "Hibernate" | "Standby" | "WakeUp";
18
- export type IMEKey = "AllCandidates" | "Alphanumeric" | "CodeInput" | "Compose" | "Convert" | "Dead" | "FinalMode" | "GroupFirst" | "GroupLast" | "GroupNext" | "GroupPrevious" | "ModeChange" | "NextCandidate" | "NonConvert" | "PreviousCandidate" | "Process" | "SingleCandidate" | "HangulMode" | "HanjaMode" | "JunjaMode" | "Eisu" | "Hankaku" | "Hiragana" | "HiraganaKatakana" | "KanaMode" | "KanjiMode" | "Katakana" | "Romaji" | "Zenkaku" | "ZenkakuHankaku";
19
- export type FunctionKey = "F1" | "F2" | "F3" | "F4" | "F5" | "F6" | "F7" | "F8" | "F9" | "F10" | "F11" | "F12" | "Soft1" | "Soft2" | "Soft3" | "Soft4";
20
- export type MultimediaKey = "ChannelDown" | "ChannelUp" | "Close" | "MailForward" | "MailReply" | "MailSend" | "MediaClose" | "MediaFastForward" | "MediaPause" | "MediaPlay" | "MediaPlayPause" | "MediaRecord" | "MediaRewind" | "MediaStop" | "MediaTrackNext" | "MediaTrackPrevious" | "New" | "Open" | "Print" | "Save" | "SpellCheck";
21
- export type MultimediaNumpadKey = "Key11" | "Key12";
22
- export type AudioKey = "AudioBalanceLeft" | "AudioBalanceRight" | "AudioBassBoostDown" | "AudioBassBoostToggle" | "AudioBassBoostUp" | "AudioFaderFront" | "AudioFaderRear" | "AudioSurroundModeNext" | "AudioTrebleDown" | "AudioTrebleUp" | "AudioVolumeDown" | "AudioVolumeUp" | "AudioVolumeMute" | "MicrophoneToggle" | "MicrophoneVolumeDown" | "MicrophoneVolumeUp" | "MicrophoneVolumeMute";
23
- export type SpeechKey = "SpeechCorrectionList" | "SpeechInputToggle";
package/dist/w3.js DELETED
@@ -1,6 +0,0 @@
1
- /**
2
- * Mapped from https://www.w3.org/TR/uievents-key/#key-attr-values (only english set) for all values a keydown / keyup `key` can be mapped into
3
- * TS types for better intelisense
4
- */
5
- export {};
6
- //# sourceMappingURL=w3.js.map
package/dist/w3.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"w3.js","sourceRoot":"","sources":["../src/w3.ts"],"names":[],"mappings":"AAAA;;;GAGG"}