my-hotkeys 0.0.1
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/LICENSE +7 -0
- package/README.md +271 -0
- package/dist/browser/hotkeys.min.js +2 -0
- package/dist/esm/hotkeys.esm.d.ts +111 -0
- package/dist/esm/hotkeys.esm.js +336 -0
- package/package.json +81 -0
- package/src/hotkey-types.ts +336 -0
- package/src/hotkeys.ts +187 -0
- package/src/index.ts +2 -0
- package/src/internals.ts +154 -0
- package/src/log-keyboard-event.ts +30 -0
- package/src/symbols-and-aliases.ts +49 -0
- package/src/types.ts +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2024 Itai Tenenbaum
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
package/README.md
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+

|
|
2
|
+
[](https://opensource.org/licenses/MIT)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
my-hotkeys
|
|
6
|
+
==========
|
|
7
|
+
Keyboard shorcuts.
|
|
8
|
+
|
|
9
|
+
Install
|
|
10
|
+
-------
|
|
11
|
+
```sh
|
|
12
|
+
$ npm install my-hotkeys
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Basic Usage
|
|
16
|
+
-----------
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import {hotkeys} from 'my-hotkeys`;
|
|
20
|
+
```
|
|
21
|
+
```js
|
|
22
|
+
const hk = hotkeys();
|
|
23
|
+
|
|
24
|
+
// bind one:
|
|
25
|
+
hk.bind('a', doSomething);
|
|
26
|
+
|
|
27
|
+
// or multiple:
|
|
28
|
+
hk.bind({
|
|
29
|
+
'a': doSomething,
|
|
30
|
+
'ctrl-a': doSomethingElse,
|
|
31
|
+
'ctrl-alt-3': doAnotherThing,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
hk.unbind('a'); // removes a hotkey
|
|
35
|
+
|
|
36
|
+
hk.unmount(); // removes the instance's event listener
|
|
37
|
+
hk.mount(); // adds the instance's event listener
|
|
38
|
+
|
|
39
|
+
hk.destruct(); // removes all hotkeys and the event listener
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Index
|
|
43
|
+
-----
|
|
44
|
+
* [Creating an instance](#creating-an-instance)
|
|
45
|
+
* [Binding / Unbinding Keys](#binding--unbinding-keys)
|
|
46
|
+
* [Mount/Unmount the event listener](#mountunmount-the-event-listener)
|
|
47
|
+
* [Hotkeys Strings](#hotkeys-strings)
|
|
48
|
+
* [Destruction](#destruction)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
## Creating an instance
|
|
52
|
+
There are two ways to get a `Hotkeys` instance:
|
|
53
|
+
1. By calling `hotkeys` creator function (lowercased "h")
|
|
54
|
+
2. By the `Hotkeys` constructor (uppercased "H")
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
import {hotkeys} from 'my-hotkeys`;
|
|
58
|
+
|
|
59
|
+
const hk = hotkeys();
|
|
60
|
+
```
|
|
61
|
+
or:
|
|
62
|
+
```js
|
|
63
|
+
import {Hotkeys} from 'my-hotkeys`;
|
|
64
|
+
|
|
65
|
+
const hk = new Hotkeys();
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The difference between them is that `hotkeys` creator function also mounts the event listener on creation and doesn't have the ignore function argument (yet). When using the constructor you need to call `.mount()` manually (see [`.mount()`](#mount) below) and you can also set an ignore function.
|
|
69
|
+
|
|
70
|
+
Both accept an optional argument as the context element (`HTMLElement | Document`). This would be the element that listens to the keyboard events. Defaults to `document`.
|
|
71
|
+
```js
|
|
72
|
+
const hk = hotkeys(elmOrDoc);
|
|
73
|
+
// => internally: elmOrDoc.addEventListener()...
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
> **⚠ Non-browser environments:** You might need to pass in the runtime's `document` object as the constructor argument.
|
|
77
|
+
|
|
78
|
+
### Ignore Function
|
|
79
|
+
By default, the `Hotkeys` instance ignores key presses if the `event.target` element is:
|
|
80
|
+
* `<input>`
|
|
81
|
+
* `<select>`
|
|
82
|
+
* `<textarea>`
|
|
83
|
+
* `[contenteditable="true"]`
|
|
84
|
+
|
|
85
|
+
You can pass the constructor your own ignore function as the second argument. This function gets called on every `keydown` event with the `event` object. Return a truthy value to ignore the key press or a falsy value for continue executing the hotkey.
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
const hk = new Hotkeys(document, (ev: KeyboardEvent) =>
|
|
89
|
+
ev.target === mySpecialElement);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
## Binding / Unbinding Keys
|
|
94
|
+
|
|
95
|
+
### .bind()
|
|
96
|
+
* `.bind(hotkey, callback)` - hotkey string, callback
|
|
97
|
+
* `.bind({hotkey: callback})` - an object of `{hotkey:callback}`
|
|
98
|
+
|
|
99
|
+
Adds keyboard shortcuts. Does **not** add an event listener.
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
hk.bind('a', doSomething);
|
|
103
|
+
hk.bind('b', doSomethingElse);
|
|
104
|
+
|
|
105
|
+
// or:
|
|
106
|
+
|
|
107
|
+
hk.bind({
|
|
108
|
+
'a': doSomething,
|
|
109
|
+
'b': doSomethingElse,
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Each hotkey can be bound once:
|
|
114
|
+
```js
|
|
115
|
+
hk.bind('a', doSomething);
|
|
116
|
+
hk.bind('a', doSomethingElse); // -> throws Error
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Callback functions are called with the keyboard event as their only argument:
|
|
120
|
+
```js
|
|
121
|
+
function doSomething (ev: KeyboardEvent) {...}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### .unbind()
|
|
125
|
+
* `.unbind(hotkey)` - hotkey string
|
|
126
|
+
* `.unbind([hotkey...])` - an array of hotkey strings
|
|
127
|
+
|
|
128
|
+
Removes keyboard shortcuts. Does **not** remove the event listener.
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
hk.unbind('a');
|
|
132
|
+
hk.unbind('b');
|
|
133
|
+
|
|
134
|
+
// or:
|
|
135
|
+
|
|
136
|
+
hk.unbind(['a', 'b']);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### .unbindAll()
|
|
140
|
+
Unbinds all hotkeys. Does **not** remove the event listener.
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
hk.bind('A', doSomething);
|
|
144
|
+
|
|
145
|
+
hk.unbindAll();
|
|
146
|
+
|
|
147
|
+
hk.bind('B', doSomethingElse);
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Mount/Unmount the event listener
|
|
151
|
+
Each `Hotkeys` instance can only have one `keydown` keyboard event listener. The event listener is attached to the context element passed in construction. Defaults to `document`.
|
|
152
|
+
|
|
153
|
+
* `.mount()` - Attaches the event listener to the context element.
|
|
154
|
+
* `.unmount()` - Dettaches the event listener from the context element.
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
const hk = new Hotkeys(myMenu);
|
|
158
|
+
|
|
159
|
+
hk.bind('Q', doSomething);
|
|
160
|
+
|
|
161
|
+
// user presses "Q" but nothing happens
|
|
162
|
+
|
|
163
|
+
hk.mount(); // => internally: myMenu.addEventListener()...
|
|
164
|
+
|
|
165
|
+
// user presses "Q" and `doSomething` is called
|
|
166
|
+
|
|
167
|
+
hk.unmount();
|
|
168
|
+
|
|
169
|
+
// user presses "Q" but nothing happens
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Using the creator function mounts the event listener for you:
|
|
173
|
+
```js
|
|
174
|
+
const hk = hotkeys(); // <---- also mounts
|
|
175
|
+
|
|
176
|
+
hk.bind('Q', doSomething);
|
|
177
|
+
|
|
178
|
+
// user presses "Q" and `doSomething` is called
|
|
179
|
+
|
|
180
|
+
hk.unmount();
|
|
181
|
+
|
|
182
|
+
// user presses "Q" but nothing happens
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
## Hotkeys Strings
|
|
187
|
+
Currently, `my-hotkeys` supports the classic/standard/canonical way of binding keys: there are modifier keys (`Control`, `Alt`, `Shift`, `Meta`) and all the rest ("regular" keys).
|
|
188
|
+
|
|
189
|
+
A hotkey string can be a single regular key, with or without modifiers.
|
|
190
|
+
|
|
191
|
+
Modifier keys cannot be hotkeys without a regular key, i.e. `.bind('ctrl-alt')` will not work.
|
|
192
|
+
|
|
193
|
+
You can also bind by `event.code` or by symbols like `?`.
|
|
194
|
+
|
|
195
|
+
### Delimiter
|
|
196
|
+
The delimiter character is `-`, not configurable (yet?). If you want to bind `-` as a hotkey - use its alias: "Minus" (e.g. `'ctrl-minus'`).
|
|
197
|
+
|
|
198
|
+
### Examples:
|
|
199
|
+
```js
|
|
200
|
+
hk.bind({
|
|
201
|
+
'a': doSomething,
|
|
202
|
+
'ctrl-a': doSomething,
|
|
203
|
+
'ctrl-alt-a': doSomething,
|
|
204
|
+
'?': showHelp, // by symbol that may require shift
|
|
205
|
+
})
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Hotkeys are case insensitive:
|
|
209
|
+
```js
|
|
210
|
+
hk.bind('ctrl-a', doSomething)
|
|
211
|
+
// Same as:
|
|
212
|
+
hk.bind('Ctrl-A', doSomething)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
But not when you bind by a key id (`event.code`):
|
|
216
|
+
```js
|
|
217
|
+
// event.code is case sensitive
|
|
218
|
+
hk.bind('Numpad8', doSomething)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Aliases
|
|
222
|
+
Some keys have aliases for better readability or just for convenience.
|
|
223
|
+
|
|
224
|
+
> Aliases are case insensitive.
|
|
225
|
+
|
|
226
|
+
### Modifier Aliases:
|
|
227
|
+
| Key | Alias |
|
|
228
|
+
|---------|---------|
|
|
229
|
+
| Control | Ctrl |
|
|
230
|
+
| Meta | Cmd |
|
|
231
|
+
| Meta | Command |
|
|
232
|
+
|
|
233
|
+
### Regular Key Aliases:
|
|
234
|
+
| Key | Alias |
|
|
235
|
+
|------------|--------------|
|
|
236
|
+
| ArrowUp | Up |
|
|
237
|
+
| ArrowDown | Down |
|
|
238
|
+
| ArrowLeft | Left |
|
|
239
|
+
| ArrowRight | Right |
|
|
240
|
+
| | Space |
|
|
241
|
+
| + | Plus |
|
|
242
|
+
| - | Minus |
|
|
243
|
+
| = | Equal |
|
|
244
|
+
| _ | Underscore |
|
|
245
|
+
| ' | Quote |
|
|
246
|
+
| ' | Singlequote |
|
|
247
|
+
| " | Quotes |
|
|
248
|
+
| " | Doublequotes |
|
|
249
|
+
| ` | Backquote |
|
|
250
|
+
| ~ | Tilde |
|
|
251
|
+
| \\ | Backslash |
|
|
252
|
+
| Insert | Ins |
|
|
253
|
+
| Delete | Del |
|
|
254
|
+
| Escape | Esc |
|
|
255
|
+
| PageUp | PgUp |
|
|
256
|
+
| PageDown | PgDn |
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
## Destruction
|
|
260
|
+
Call `.destruct()` when its context element leaves the DOM. It will remove all of the instance's hotkeys and event listeners by calling `.unmount()` and `.unbindAll()`.
|
|
261
|
+
|
|
262
|
+
```js
|
|
263
|
+
const hk = new Hotkeys();
|
|
264
|
+
|
|
265
|
+
hk.bind('A', doSomething);
|
|
266
|
+
hk.mount();
|
|
267
|
+
|
|
268
|
+
// ...
|
|
269
|
+
|
|
270
|
+
hk.destruct();
|
|
271
|
+
```
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! my-hotkeys v0.0.1 | MIT License | © Itai Tenenbaum 2024 | git+https://github.com/taitulism/my-hotkeys */
|
|
2
|
+
var hotkeys=function(t){"use strict";function e(t,e){const n=e-t.length;return n>0?t+" ".repeat(n):t}const n={"[":"BracketLeft","]":"BracketRight",";":"Semicolon","'":"Quote","\\":"Backslash",",":"Comma","`":"Backquote","=":"Equal","-":"Minus",".":"Period","/":"Slash"},i={up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",space:" ",plus:"+",minus:"-",equal:"=",underscore:"_",quote:"'",singlequote:"'",quotes:'"',doublequotes:'"',backquote:"`",tilde:"~",backslash:"\\",ins:"Insert",del:"Delete",esc:"Escape",pgup:"PageUp",pgdn:"PageDown"},o="Control",s="Meta",r={Control:1,Alt:2,Shift:4,Meta:8},h={control:o,ctrl:o,alt:"Alt",shift:"Shift",meta:s,cmd:s,command:s},c={0:"_",1:"C",2:"A",3:"CA",4:"S",5:"CS",6:"AS",7:"CAS",8:"M",9:"CM",10:"AM",11:"CAM",12:"SM",13:"CSM",14:"ASM",15:"CASM"},u=t=>1===t.length&&/[a-zA-Z]/.test(t),f=t=>t in h;const a=t=>{const e=t.toLowerCase();return u(t)?e:(t=>t in i)(e)?i[e]:t};function d(t){if("-"===t)return{targetKey:"-",unifiedModifier:"_"};!function(t){if(!t)throw new Error("Invalid Hotkey: Empty String");if(t.startsWith("-")||t.endsWith("-")||/--/.test(t))throw new Error(`Invalid Hotkey: "${t}"`)}(t);const e=t.split("-"),n=a(e.pop()),i=function(t){if(0===t.length)return"_";const e=function(){const t={};return function(e){return!(e in t)&&(t[e]=void 0,!0)}}();let n=0;for(let i=0;i<t.length;i++){const o=t[i].toLowerCase();if(!f(o))throw new Error(`Unknown Modifier: "${o}"`);{const t=h[o],i=r[t];e(i)&&(n+=i)}}return c[n]}(e);return{targetKey:n,unifiedModifier:i,withShift:i.includes("S")}}const l=["INPUT","TEXTAREA","SELECT"],y=t=>{const{target:e}=t;if(!(e&&e instanceof HTMLElement))return!1;return l.includes(e.tagName)||e.isContentEditable};class k{constructor(t=document,i=y){this.ctxElm=t,this.ignoreFn=i,this.hotkeys=new Map,this.debugMode=!1,this.addHotkey=(t,e,i)=>{const{targetKey:o,unifiedModifier:s,withShift:r}=t;if(this.hotkeys.has(o)){const t=this.hotkeys.get(o);if(t[s])throw new Error(`Duplicated hotkey: "${i}"`);t[s]=e}else this.hotkeys.set(o,{[s]:e});if(r&&o in n){const t=n[o];this.addHotkey({targetKey:t,unifiedModifier:s},e,i)}},this.removeHotkey=t=>{const{targetKey:e,unifiedModifier:i,withShift:o}=t;if(!this.hotkeys.has(e))throw new Error("No Such Hotkey");{const t=this.hotkeys.get(e);if(t[i]&&(delete t[i],0===Object.keys(t).length&&this.hotkeys.delete(e)),o&&e in n){const t=n[e];this.removeHotkey({targetKey:t,unifiedModifier:i})}}},this.keydownHandler=t=>{this.debugMode&&function(t){const{type:n,code:i,key:o,ctrlKey:s,altKey:r,shiftKey:h,metaKey:c}=t,u=s||r||h||c,f=("keydown"===n?"🔻":"🔼")+e(o,7),a=`| id:${i} `,d=e((u?"[ ":"")+`${s?"ctrl ":""}${r?"alt ":""}${h?"shift ":""}${c?"meta ":""}`+(u?"]":""),21);console.log(f,d,a)}(t);const{key:n}=t;if(n in r)return;if(this.ignoreFn?.(t))return;const i=function(t,e){const{key:n,code:i,shiftKey:o}=t,s=u(n)?n.toLowerCase():n;if(e.has(s))return e.get(s);if(e.has(i))return e.get(i);if(o&&(t=>(t=>t.startsWith("Dig"))(t)||(t=>t.startsWith("Num")&&/\d$/.test(t))(t))(i)){const t=(t=>t[t.length-1])(i);if(e.has(t))return e.get(t)}}(t,this.hotkeys);if(!i)return;const o=function(t){const{ctrlKey:e,altKey:n,shiftKey:i,metaKey:o}=t;let s=0;return e&&(s+=r.Control),n&&(s+=r.Alt),i&&(s+=r.Shift),o&&(s+=r.Meta),c[s]}(t);if(i[o])i[o]?.(t);else if(i===this.hotkeys.get(n)&&(t=>t.shiftKey&&(t=>1===t.key.length)(t)&&!t.code.startsWith("Num"))(t)){const e=i[o.replace("S","")||"_"];e?.(t)}}}bind(t,e){if("string"==typeof t){const n=d(t);this.addHotkey(n,e,t)}else{const e=Object.entries(t);for(const[t,n]of e)this.bind(t,n)}return this}unbind(t){if("string"==typeof t){const e=d(t);this.removeHotkey(e)}else t.forEach((t=>this.unbind(t)));return this}unbindAll(){return this.hotkeys.clear(),this}mount(){return this.ctxElm.addEventListener("keydown",this.keydownHandler),this}unmount(){return this.ctxElm.removeEventListener("keydown",this.keydownHandler),this}destruct(){return this.unmount(),this.unbindAll(),this}}return t.Hotkeys=k,t.ModifierAliases=h,t.Modifiers=r,t.UnifiedModifiersMap=c,t.hotkeys=function(t=document){return new k(t).mount()},t}({});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
declare const SymbolIDs: {
|
|
2
|
+
readonly '[': "BracketLeft";
|
|
3
|
+
readonly ']': "BracketRight";
|
|
4
|
+
readonly ';': "Semicolon";
|
|
5
|
+
readonly '\'': "Quote";
|
|
6
|
+
readonly '\\': "Backslash";
|
|
7
|
+
readonly ',': "Comma";
|
|
8
|
+
readonly '`': "Backquote";
|
|
9
|
+
readonly '=': "Equal";
|
|
10
|
+
readonly '-': "Minus";
|
|
11
|
+
readonly '.': "Period";
|
|
12
|
+
readonly '/': "Slash";
|
|
13
|
+
};
|
|
14
|
+
type ISymbol = keyof typeof SymbolIDs;
|
|
15
|
+
type SymbolKeyID = typeof SymbolIDs[ISymbol];
|
|
16
|
+
declare const Aliases: {
|
|
17
|
+
readonly up: "ArrowUp";
|
|
18
|
+
readonly down: "ArrowDown";
|
|
19
|
+
readonly left: "ArrowLeft";
|
|
20
|
+
readonly right: "ArrowRight";
|
|
21
|
+
readonly space: " ";
|
|
22
|
+
readonly plus: "+";
|
|
23
|
+
readonly minus: "-";
|
|
24
|
+
readonly equal: "=";
|
|
25
|
+
readonly underscore: "_";
|
|
26
|
+
readonly quote: "'";
|
|
27
|
+
readonly singlequote: "'";
|
|
28
|
+
readonly quotes: "\"";
|
|
29
|
+
readonly doublequotes: "\"";
|
|
30
|
+
readonly backquote: "`";
|
|
31
|
+
readonly tilde: "~";
|
|
32
|
+
readonly backslash: "\\";
|
|
33
|
+
readonly ins: "Insert";
|
|
34
|
+
readonly del: "Delete";
|
|
35
|
+
readonly esc: "Escape";
|
|
36
|
+
readonly pgup: "PageUp";
|
|
37
|
+
readonly pgdn: "PageDown";
|
|
38
|
+
};
|
|
39
|
+
type Alias = keyof typeof Aliases;
|
|
40
|
+
type AliasValue = typeof Aliases[Alias];
|
|
41
|
+
|
|
42
|
+
type ContextElement = HTMLElement | Document;
|
|
43
|
+
type KeyHandler = (ev: KeyboardEvent) => void;
|
|
44
|
+
type IgnoreFn = (ev: KeyboardEvent) => boolean;
|
|
45
|
+
declare const Modifiers: {
|
|
46
|
+
readonly Control: 1;
|
|
47
|
+
readonly Alt: 2;
|
|
48
|
+
readonly Shift: 4;
|
|
49
|
+
readonly Meta: 8;
|
|
50
|
+
};
|
|
51
|
+
type Modifier = keyof typeof Modifiers;
|
|
52
|
+
declare const ModifierAliases: {
|
|
53
|
+
readonly control: "Control";
|
|
54
|
+
readonly ctrl: "Control";
|
|
55
|
+
readonly alt: "Alt";
|
|
56
|
+
readonly shift: "Shift";
|
|
57
|
+
readonly meta: "Meta";
|
|
58
|
+
readonly cmd: "Meta";
|
|
59
|
+
readonly command: "Meta";
|
|
60
|
+
};
|
|
61
|
+
type ModifierAlias = keyof typeof ModifierAliases;
|
|
62
|
+
declare const UnifiedModifiersMap: {
|
|
63
|
+
readonly 0: "_";
|
|
64
|
+
readonly 1: "C";
|
|
65
|
+
readonly 2: "A";
|
|
66
|
+
readonly 3: "CA";
|
|
67
|
+
readonly 4: "S";
|
|
68
|
+
readonly 5: "CS";
|
|
69
|
+
readonly 6: "AS";
|
|
70
|
+
readonly 7: "CAS";
|
|
71
|
+
readonly 8: "M";
|
|
72
|
+
readonly 9: "CM";
|
|
73
|
+
readonly 10: "AM";
|
|
74
|
+
readonly 11: "CAM";
|
|
75
|
+
readonly 12: "SM";
|
|
76
|
+
readonly 13: "CSM";
|
|
77
|
+
readonly 14: "ASM";
|
|
78
|
+
readonly 15: "CASM";
|
|
79
|
+
};
|
|
80
|
+
type UniModSum = keyof typeof UnifiedModifiersMap;
|
|
81
|
+
type UnifiedModifier = typeof UnifiedModifiersMap[UniModSum];
|
|
82
|
+
type CombinationHandlers = {
|
|
83
|
+
[K in UnifiedModifier]?: KeyHandler;
|
|
84
|
+
};
|
|
85
|
+
type ParsedTargetKey = AliasValue | SymbolKeyID | string;
|
|
86
|
+
type ParsedHotKey = {
|
|
87
|
+
targetKey: ParsedTargetKey;
|
|
88
|
+
unifiedModifier: UnifiedModifier;
|
|
89
|
+
withShift?: boolean;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
declare function hotkeys(ctxElm?: ContextElement): Hotkeys;
|
|
93
|
+
declare class Hotkeys {
|
|
94
|
+
ctxElm: ContextElement;
|
|
95
|
+
private ignoreFn;
|
|
96
|
+
hotkeys: Map<string, CombinationHandlers>;
|
|
97
|
+
debugMode: boolean;
|
|
98
|
+
constructor(ctxElm?: ContextElement, ignoreFn?: IgnoreFn);
|
|
99
|
+
private addHotkey;
|
|
100
|
+
private removeHotkey;
|
|
101
|
+
bind(hotkey: string, handlerFn: KeyHandler): Hotkeys;
|
|
102
|
+
bind(hotkey: Record<string, KeyHandler>): Hotkeys;
|
|
103
|
+
unbind(hotkey: string | Array<string>): this;
|
|
104
|
+
unbindAll(): this;
|
|
105
|
+
private keydownHandler;
|
|
106
|
+
mount(): this;
|
|
107
|
+
unmount(): this;
|
|
108
|
+
destruct(): this;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { type CombinationHandlers, type ContextElement, Hotkeys, type IgnoreFn, type KeyHandler, type Modifier, type ModifierAlias, ModifierAliases, Modifiers, type ParsedHotKey, type ParsedTargetKey, type UniModSum, type UnifiedModifier, UnifiedModifiersMap, hotkeys };
|