@cxl/keyboard 0.0.2 → 1.0.0
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 +2 -2
- package/amd/index.d.ts +76 -10
- package/amd/index.js +1 -155
- package/index.d.ts +76 -10
- package/index.js +139 -59
- package/index.min.js +1 -2
- package/mjs/index.d.ts +91 -0
- package/mjs/index.js +1 -0
- package/package.json +7 -9
- package/test.js +220 -6
- package/amd/index.js.map +0 -1
- package/amd/index.min.js +0 -2
- package/amd/index.min.js.map +0 -1
- package/index.js.map +0 -1
- package/index.min.js.map +0 -1
- package/test.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/%40cxl%2Fkeyboard)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Keyboard Handling Library
|
|
6
6
|
|
|
7
7
|
## Project Details
|
|
8
8
|
|
|
9
|
-
- Branch Version: [0.0
|
|
9
|
+
- Branch Version: [1.0.0](https://npmjs.com/package/@cxl/keyboard/v/1.0.0)
|
|
10
10
|
- License: UNLICENSED
|
|
11
11
|
- Documentation: [Link](https://cxlio.github.io/cxl/keyboard)
|
|
12
12
|
- Report Issues: [Github](https://github.com/cxlio/cxl/issues)
|
package/amd/index.d.ts
CHANGED
|
@@ -1,26 +1,92 @@
|
|
|
1
1
|
/// <amd-module name="@cxl/keyboard" />
|
|
2
|
-
|
|
3
|
-
export interface Key {
|
|
2
|
+
interface Key {
|
|
4
3
|
ctrlKey: boolean;
|
|
5
4
|
altKey: boolean;
|
|
6
5
|
shiftKey: boolean;
|
|
7
6
|
metaKey: boolean;
|
|
8
7
|
key: string;
|
|
8
|
+
code: string;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* The `KeyboardOptions` interface defines the configuration needed to handle keyboard interactions with
|
|
12
|
+
* a specific HTML element.
|
|
13
|
+
*/
|
|
10
14
|
export interface KeyboardOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Specifies the HTML element on which keyboard events are captured.
|
|
17
|
+
* This element will receive focus and listen for key events.
|
|
18
|
+
*/
|
|
11
19
|
element: HTMLElement;
|
|
20
|
+
/**
|
|
21
|
+
* A callback function that processes key events. It receives the current key being pressed
|
|
22
|
+
* and the sequence of keys accumulated so far. It returns `true` or `false` to indicate whether
|
|
23
|
+
* the sequence was consumed.
|
|
24
|
+
*/
|
|
12
25
|
onKey: (key: string, sequence: string[]) => boolean;
|
|
26
|
+
/**
|
|
27
|
+
* The time in milliseconds to wait between key presses before resetting the sequence.
|
|
28
|
+
* Defaults to 250ms if not provided, ensuring thoughtful key sequences rather than accidental key presses.
|
|
29
|
+
*/
|
|
13
30
|
delay?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Optional parameter to specify a custom `KeyboardLayout`.
|
|
33
|
+
* Defaults to 'en-US' if not provided. This affects how key combinations and modifier keys are interpreted.
|
|
34
|
+
*/
|
|
14
35
|
layout?: KeyboardLayout;
|
|
36
|
+
/**
|
|
37
|
+
* Boolean indicating whether to capture key events in the capture phase.
|
|
38
|
+
* This determines when the event listener reacts in the event propagation flow.
|
|
39
|
+
*/
|
|
40
|
+
capture?: boolean;
|
|
15
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* The `KeyboardLayout` interface describes how a keyboard layout should be structured internally.
|
|
44
|
+
*/
|
|
16
45
|
export interface KeyboardLayout {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
46
|
+
/**
|
|
47
|
+
* A mapping of shifted keys to their non-shifted counterparts, used to accurately
|
|
48
|
+
* interpret which character a shifted key press represents.
|
|
49
|
+
*/
|
|
50
|
+
shiftMap: Record<string, string | undefined>;
|
|
51
|
+
/**
|
|
52
|
+
* Maps the representation of keys when combined with the alt key.
|
|
53
|
+
*/
|
|
54
|
+
translate(ev: Key): string;
|
|
55
|
+
/**
|
|
56
|
+
* Indicates whether the 'meta' or 'ctrl' key is the primary modifier used for commands,
|
|
57
|
+
* differing based on the operating system (e.g., 'metaKey' for macOS).
|
|
58
|
+
*/
|
|
59
|
+
modKey?: 'metaKey' | 'ctrlKey';
|
|
20
60
|
}
|
|
21
|
-
export declare const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
61
|
+
export declare const KeyboardLayoutData: Record<string, KeyboardLayout>;
|
|
62
|
+
/**
|
|
63
|
+
* The `handleKeyboard` function sets up event listeners to handle keyboard events on a given HTML element.
|
|
64
|
+
* It accepts a configuration object (`KeyboardOptions`) which includes the target HTML element, a callback
|
|
65
|
+
* `onKey` to handle keyboard sequences, a `delay` for typing sequence recognition, an optional keyboard
|
|
66
|
+
* layout, and an optional capture mode for events.
|
|
67
|
+
*
|
|
68
|
+
* - Defaults the delay to 250ms if not specified, using this delay to determine when to treat subsequent
|
|
69
|
+
* key presses as part of the same sequence or a new one.
|
|
70
|
+
* - Determines the keyboard layout, either from the provided options or defaults, which affects how keys
|
|
71
|
+
* (especially with modifiers) are interpreted.
|
|
72
|
+
* - Adds a `keydown` event listener to the provided element, allowing modification of event behavior such
|
|
73
|
+
* as propagation and default handling based on the `onKey` callback result.
|
|
74
|
+
* - Builds a key sequence based on timing and calls the `onKey` handler with the assembled sequence,
|
|
75
|
+
* stopping event propagation based on handler response.
|
|
76
|
+
* - The handler uses the sequence to manage shortcuts and performs preventative measures against default
|
|
77
|
+
* browser actions.
|
|
78
|
+
* @return A cleanup function that removes the event listener.
|
|
79
|
+
*/
|
|
80
|
+
export declare function handleKeyboard({ element, onKey, delay, layout, capture, }: KeyboardOptions): () => void;
|
|
81
|
+
export declare function parseKey(key: string, layout?: KeyboardLayout): Key[];
|
|
82
|
+
/**
|
|
83
|
+
* Converts a string representing a key combination into a normalized string format.
|
|
84
|
+
* This function takes a `key` string and an optional `layout` object (defaults to the user's layout).
|
|
85
|
+
* It uses `parseKey` to break the key combination into individual `Key` objects, each representing
|
|
86
|
+
* a parsed key press. It then converts each `Key` object back to a string using `keyboardEventToString`,
|
|
87
|
+
* considering the layout's details like `shiftedKeys` and `shiftMap`. The resulting
|
|
88
|
+
* strings are concatenated with spaces and returned as the normalized form. This is useful
|
|
89
|
+
* for ensuring consistent representation of key sequences across different keyboard layouts.
|
|
90
|
+
*/
|
|
26
91
|
export declare function normalize(key: string, layout?: KeyboardLayout): string;
|
|
92
|
+
export {};
|
package/amd/index.js
CHANGED
|
@@ -1,155 +1 @@
|
|
|
1
|
-
define("@cxl/keyboard",
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.normalize = exports.parseKey = exports.getDefaultLayout = exports.handleKeyboard = exports.TranslateKey = exports.Pass = void 0;
|
|
5
|
-
exports.Pass = {};
|
|
6
|
-
const navigator = typeof window !== 'undefined'
|
|
7
|
-
? window.navigator
|
|
8
|
-
: { language: 'en-US', platform: 'nodejs' };
|
|
9
|
-
const IS_MAC = /Mac|iPod|iPhone|iPad/;
|
|
10
|
-
const PARSE_KEY = /(shift|ctrl|control|alt|option|meta|command|cmd|mod|\w+)(\s*\+|\s)?/g;
|
|
11
|
-
const SHIFT_MAP = {
|
|
12
|
-
'/': '?',
|
|
13
|
-
'.': '>',
|
|
14
|
-
',': '<',
|
|
15
|
-
"'": '"',
|
|
16
|
-
';': ':',
|
|
17
|
-
'[': '{',
|
|
18
|
-
']': '}',
|
|
19
|
-
'\\': '|',
|
|
20
|
-
'`': '~',
|
|
21
|
-
'=': '+',
|
|
22
|
-
'-': '_',
|
|
23
|
-
'1': '!',
|
|
24
|
-
'2': '@',
|
|
25
|
-
'3': '#',
|
|
26
|
-
'4': '$',
|
|
27
|
-
'5': '%',
|
|
28
|
-
'6': '^',
|
|
29
|
-
'7': '&',
|
|
30
|
-
'8': '*',
|
|
31
|
-
'9': '(',
|
|
32
|
-
'0': ')',
|
|
33
|
-
};
|
|
34
|
-
const KeyboardLayoutData = {
|
|
35
|
-
'en-US': {
|
|
36
|
-
shiftedKeys: Object.values(SHIFT_MAP),
|
|
37
|
-
shiftMap: SHIFT_MAP,
|
|
38
|
-
modKey: IS_MAC.test(navigator.platform) ? 'metaKey' : 'ctrlKey',
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
exports.TranslateKey = {
|
|
42
|
-
Shift: '',
|
|
43
|
-
Alt: '',
|
|
44
|
-
Meta: '',
|
|
45
|
-
Control: '',
|
|
46
|
-
ArrowUp: 'up',
|
|
47
|
-
ArrowDown: 'down',
|
|
48
|
-
ArrowLeft: 'left',
|
|
49
|
-
ArrowRight: 'right',
|
|
50
|
-
Escape: 'esc',
|
|
51
|
-
};
|
|
52
|
-
function keyboardEventToString(ev, { shiftedKeys }) {
|
|
53
|
-
const key = ev.key;
|
|
54
|
-
if (!key ||
|
|
55
|
-
key === 'Shift' ||
|
|
56
|
-
key === 'Alt' ||
|
|
57
|
-
key === 'Meta' ||
|
|
58
|
-
key === 'Control')
|
|
59
|
-
return '';
|
|
60
|
-
const ch = exports.TranslateKey[key] || key.toLowerCase();
|
|
61
|
-
let result;
|
|
62
|
-
if (ev.ctrlKey)
|
|
63
|
-
result = 'ctrl';
|
|
64
|
-
if (ev.altKey)
|
|
65
|
-
result = result ? result + '+alt' : 'alt';
|
|
66
|
-
if (ev.shiftKey && !shiftedKeys.includes(ch))
|
|
67
|
-
result = result ? result + '+shift' : 'shift';
|
|
68
|
-
if (ev.metaKey)
|
|
69
|
-
result = result ? result + '+meta' : 'meta';
|
|
70
|
-
return result ? result + '+' + ch : ch;
|
|
71
|
-
}
|
|
72
|
-
function handleKeyboard({ element, onKey, delay, layout, }) {
|
|
73
|
-
const D = delay === undefined ? 250 : delay;
|
|
74
|
-
const locale = navigator.language;
|
|
75
|
-
let sequence = [];
|
|
76
|
-
let lastT = 0;
|
|
77
|
-
const newLayout = layout || KeyboardLayoutData[locale] || KeyboardLayoutData['en-US'];
|
|
78
|
-
function handler(ev) {
|
|
79
|
-
const k = keyboardEventToString(ev, newLayout);
|
|
80
|
-
let t = Date.now();
|
|
81
|
-
if (!k)
|
|
82
|
-
return;
|
|
83
|
-
if (t - lastT < D)
|
|
84
|
-
sequence.push(k);
|
|
85
|
-
else
|
|
86
|
-
sequence = [k];
|
|
87
|
-
const seq = sequence.slice(0);
|
|
88
|
-
do {
|
|
89
|
-
if (onKey(seq.join(' '), sequence) !== false) {
|
|
90
|
-
ev.stopPropagation();
|
|
91
|
-
ev.preventDefault();
|
|
92
|
-
t = 0;
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
seq.shift();
|
|
96
|
-
} while (seq.length);
|
|
97
|
-
lastT = t;
|
|
98
|
-
}
|
|
99
|
-
element.addEventListener('keydown', handler);
|
|
100
|
-
return () => element.removeEventListener('keydown', handler);
|
|
101
|
-
}
|
|
102
|
-
exports.handleKeyboard = handleKeyboard;
|
|
103
|
-
function getDefaultLayout() {
|
|
104
|
-
return (KeyboardLayoutData[navigator === null || navigator === void 0 ? void 0 : navigator.language] || KeyboardLayoutData['en-US']);
|
|
105
|
-
}
|
|
106
|
-
exports.getDefaultLayout = getDefaultLayout;
|
|
107
|
-
function newKey() {
|
|
108
|
-
return {
|
|
109
|
-
ctrlKey: false,
|
|
110
|
-
shiftKey: false,
|
|
111
|
-
metaKey: false,
|
|
112
|
-
altKey: false,
|
|
113
|
-
key: '',
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
function parseKey(key, { modKey, shiftMap } = getDefaultLayout()) {
|
|
117
|
-
const sequence = [];
|
|
118
|
-
let match;
|
|
119
|
-
let event = newKey();
|
|
120
|
-
while ((match = PARSE_KEY.exec(key.toLowerCase()))) {
|
|
121
|
-
const ch = match[1];
|
|
122
|
-
if (ch === 'shift')
|
|
123
|
-
event.shiftKey = true;
|
|
124
|
-
else if (ch === 'ctrl' || ch === 'control')
|
|
125
|
-
event.ctrlKey = true;
|
|
126
|
-
else if (ch === 'alt' || ch === 'option')
|
|
127
|
-
event.altKey = true;
|
|
128
|
-
else if (ch === 'meta' || ch === 'cmd' || ch === 'command')
|
|
129
|
-
event.metaKey = true;
|
|
130
|
-
else if (ch === 'mod')
|
|
131
|
-
event[modKey] = true;
|
|
132
|
-
else {
|
|
133
|
-
const shifted = shiftMap[ch];
|
|
134
|
-
if (shifted)
|
|
135
|
-
event.shiftKey = false;
|
|
136
|
-
event.key = shifted || ch;
|
|
137
|
-
}
|
|
138
|
-
if (match[2] !== '+') {
|
|
139
|
-
sequence.push(event);
|
|
140
|
-
event = newKey();
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return sequence;
|
|
144
|
-
}
|
|
145
|
-
exports.parseKey = parseKey;
|
|
146
|
-
function normalize(key, layout = getDefaultLayout()) {
|
|
147
|
-
const sequence = parseKey(key, layout);
|
|
148
|
-
let i = sequence.length;
|
|
149
|
-
while (i--)
|
|
150
|
-
sequence[i] = keyboardEventToString(sequence[i], layout);
|
|
151
|
-
return sequence.join(' ');
|
|
152
|
-
}
|
|
153
|
-
exports.normalize = normalize;
|
|
154
|
-
});
|
|
155
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
define("@cxl/keyboard",["require","exports"],(function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.KeyboardLayoutData=void 0,t.handleKeyboard=function({element:e,onKey:a,delay:n,layout:r,capture:s}){const c=void 0===n?250:n,y=o.language;let u=[],d=0;r||(r=t.KeyboardLayoutData[y]||t.KeyboardLayoutData["en-US"]);const f=l(r);function K(e){const t=i(e,f);let o=Date.now();if(!t)return;o-d<c?u.push(t):u=[t];const n=u.slice(0);do{if(!1!==a(n.join(" "),u)){e.stopPropagation(),e.preventDefault(),o=0;break}n.shift()}while(n.length);d=o}return e.addEventListener("keydown",K,{capture:s}),()=>e.removeEventListener("keydown",K,{capture:s})},t.parseKey=function(e,t=s()){return c(e,l(t))},t.normalize=function(e,t=s()){const o=l(t);return c(e,o).map((e=>i(e,o))).join(" ")};const o="undefined"!=typeof window?window.navigator:{language:"en-US",platform:"nodejs"},a=/Mac|iPod|iPhone|iPad/,n=/(shift|ctrl|control|alt|option|meta|command|cmd|mod|[^\s+]+)(\s*\+|\s)?/g,r={ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right",Escape:"esc",Space:"space",Backquote:"`",Minus:"-",Equal:"=",BracketLeft:"[",BracketRight:"]",Quote:"'",Backslash:"\\",Apostrophe:"'",Semicolon:";",Comma:",",Period:".",Slash:"/"};function i(e,{translate:t}){const o=e.key;if(!o||"Shift"===o||"Alt"===o||"Meta"===o||"Control"===o||"Dead"===o&&!e.altKey)return"";const a=t(e);let n;return e.ctrlKey&&(n="ctrl"),e.altKey&&(n=n?n+"+alt":"alt"),e.shiftKey&&(n=n?n+"+shift":"shift"),e.metaKey&&(n=n?n+"+meta":"meta"),n?n+"+"+a:a}function s(){return t.KeyboardLayoutData[o?.language]||t.KeyboardLayoutData["en-US"]}function c(e,{modKey:t,shiftMap:o}){const a=[];let r,i={ctrlKey:!1,shiftKey:!1,metaKey:!1,altKey:!1,key:"",code:""};for(;r=n.exec(e.toLowerCase());){const e=r[1];if("shift"===e)i.shiftKey=!0;else if("ctrl"===e||"control"===e)i.ctrlKey=!0;else if("alt"===e||"option"===e)i.altKey=!0;else if("meta"===e||"cmd"===e||"command"===e)i.metaKey=!0;else if("mod"===e)i[t]=!0;else{const t=o[e];t?(i.key=t,i.shiftKey=!0):i.key=e}"+"!==r[2]&&(a.push(i),i={ctrlKey:!1,shiftKey:!1,metaKey:!1,altKey:!1,key:"",code:""})}return a}function l(e){return{modKey:a.test(o.platform)?"metaKey":"ctrlKey",...e}}t.KeyboardLayoutData={"en-US":{shiftMap:{"?":"/",">":".","<":",",'"':"'",":":";","{":"[","}":"]","|":"\\","~":"`","+":"=",_:"-","!":"1","@":"2","#":"3",$:"4","%":"5","^":"6","&":"7","*":"8","(":"9",")":"0"},translate:({code:e,key:t})=>r[e]||(e.startsWith("Key")?e.slice(3).toLowerCase():e.startsWith("Digit")?e.slice(5):t.toLowerCase())}}}));
|
package/index.d.ts
CHANGED
|
@@ -1,26 +1,92 @@
|
|
|
1
1
|
/// <amd-module name="@cxl/keyboard" />
|
|
2
|
-
|
|
3
|
-
export interface Key {
|
|
2
|
+
interface Key {
|
|
4
3
|
ctrlKey: boolean;
|
|
5
4
|
altKey: boolean;
|
|
6
5
|
shiftKey: boolean;
|
|
7
6
|
metaKey: boolean;
|
|
8
7
|
key: string;
|
|
8
|
+
code: string;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* The `KeyboardOptions` interface defines the configuration needed to handle keyboard interactions with
|
|
12
|
+
* a specific HTML element.
|
|
13
|
+
*/
|
|
10
14
|
export interface KeyboardOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Specifies the HTML element on which keyboard events are captured.
|
|
17
|
+
* This element will receive focus and listen for key events.
|
|
18
|
+
*/
|
|
11
19
|
element: HTMLElement;
|
|
20
|
+
/**
|
|
21
|
+
* A callback function that processes key events. It receives the current key being pressed
|
|
22
|
+
* and the sequence of keys accumulated so far. It returns `true` or `false` to indicate whether
|
|
23
|
+
* the sequence was consumed.
|
|
24
|
+
*/
|
|
12
25
|
onKey: (key: string, sequence: string[]) => boolean;
|
|
26
|
+
/**
|
|
27
|
+
* The time in milliseconds to wait between key presses before resetting the sequence.
|
|
28
|
+
* Defaults to 250ms if not provided, ensuring thoughtful key sequences rather than accidental key presses.
|
|
29
|
+
*/
|
|
13
30
|
delay?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Optional parameter to specify a custom `KeyboardLayout`.
|
|
33
|
+
* Defaults to 'en-US' if not provided. This affects how key combinations and modifier keys are interpreted.
|
|
34
|
+
*/
|
|
14
35
|
layout?: KeyboardLayout;
|
|
36
|
+
/**
|
|
37
|
+
* Boolean indicating whether to capture key events in the capture phase.
|
|
38
|
+
* This determines when the event listener reacts in the event propagation flow.
|
|
39
|
+
*/
|
|
40
|
+
capture?: boolean;
|
|
15
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* The `KeyboardLayout` interface describes how a keyboard layout should be structured internally.
|
|
44
|
+
*/
|
|
16
45
|
export interface KeyboardLayout {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
46
|
+
/**
|
|
47
|
+
* A mapping of shifted keys to their non-shifted counterparts, used to accurately
|
|
48
|
+
* interpret which character a shifted key press represents.
|
|
49
|
+
*/
|
|
50
|
+
shiftMap: Record<string, string | undefined>;
|
|
51
|
+
/**
|
|
52
|
+
* Maps the representation of keys when combined with the alt key.
|
|
53
|
+
*/
|
|
54
|
+
translate(ev: Key): string;
|
|
55
|
+
/**
|
|
56
|
+
* Indicates whether the 'meta' or 'ctrl' key is the primary modifier used for commands,
|
|
57
|
+
* differing based on the operating system (e.g., 'metaKey' for macOS).
|
|
58
|
+
*/
|
|
59
|
+
modKey?: 'metaKey' | 'ctrlKey';
|
|
20
60
|
}
|
|
21
|
-
export declare const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
61
|
+
export declare const KeyboardLayoutData: Record<string, KeyboardLayout>;
|
|
62
|
+
/**
|
|
63
|
+
* The `handleKeyboard` function sets up event listeners to handle keyboard events on a given HTML element.
|
|
64
|
+
* It accepts a configuration object (`KeyboardOptions`) which includes the target HTML element, a callback
|
|
65
|
+
* `onKey` to handle keyboard sequences, a `delay` for typing sequence recognition, an optional keyboard
|
|
66
|
+
* layout, and an optional capture mode for events.
|
|
67
|
+
*
|
|
68
|
+
* - Defaults the delay to 250ms if not specified, using this delay to determine when to treat subsequent
|
|
69
|
+
* key presses as part of the same sequence or a new one.
|
|
70
|
+
* - Determines the keyboard layout, either from the provided options or defaults, which affects how keys
|
|
71
|
+
* (especially with modifiers) are interpreted.
|
|
72
|
+
* - Adds a `keydown` event listener to the provided element, allowing modification of event behavior such
|
|
73
|
+
* as propagation and default handling based on the `onKey` callback result.
|
|
74
|
+
* - Builds a key sequence based on timing and calls the `onKey` handler with the assembled sequence,
|
|
75
|
+
* stopping event propagation based on handler response.
|
|
76
|
+
* - The handler uses the sequence to manage shortcuts and performs preventative measures against default
|
|
77
|
+
* browser actions.
|
|
78
|
+
* @return A cleanup function that removes the event listener.
|
|
79
|
+
*/
|
|
80
|
+
export declare function handleKeyboard({ element, onKey, delay, layout, capture, }: KeyboardOptions): () => void;
|
|
81
|
+
export declare function parseKey(key: string, layout?: KeyboardLayout): Key[];
|
|
82
|
+
/**
|
|
83
|
+
* Converts a string representing a key combination into a normalized string format.
|
|
84
|
+
* This function takes a `key` string and an optional `layout` object (defaults to the user's layout).
|
|
85
|
+
* It uses `parseKey` to break the key combination into individual `Key` objects, each representing
|
|
86
|
+
* a parsed key press. It then converts each `Key` object back to a string using `keyboardEventToString`,
|
|
87
|
+
* considering the layout's details like `shiftedKeys` and `shiftMap`. The resulting
|
|
88
|
+
* strings are concatenated with spaces and returned as the normalized form. This is useful
|
|
89
|
+
* for ensuring consistent representation of key sequences across different keyboard layouts.
|
|
90
|
+
*/
|
|
26
91
|
export declare function normalize(key: string, layout?: KeyboardLayout): string;
|
|
92
|
+
export {};
|
package/index.js
CHANGED
|
@@ -1,79 +1,131 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.KeyboardLayoutData = void 0;
|
|
4
|
+
exports.handleKeyboard = handleKeyboard;
|
|
5
|
+
exports.parseKey = parseKey;
|
|
6
|
+
exports.normalize = normalize;
|
|
7
|
+
///<amd-module name="@cxl/keyboard"/>
|
|
5
8
|
const navigator = typeof window !== 'undefined'
|
|
6
9
|
? window.navigator
|
|
7
10
|
: { language: 'en-US', platform: 'nodejs' };
|
|
8
11
|
const IS_MAC = /Mac|iPod|iPhone|iPad/;
|
|
9
|
-
const PARSE_KEY = /(shift|ctrl|control|alt|option|meta|command|cmd|mod
|
|
12
|
+
const PARSE_KEY = /(shift|ctrl|control|alt|option|meta|command|cmd|mod|[^\s+]+)(\s*\+|\s)?/g;
|
|
10
13
|
const SHIFT_MAP = {
|
|
11
|
-
'
|
|
12
|
-
'
|
|
13
|
-
'
|
|
14
|
-
"'
|
|
15
|
-
'
|
|
16
|
-
'
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'4'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
'
|
|
14
|
+
'?': '/',
|
|
15
|
+
'>': '.',
|
|
16
|
+
'<': ',',
|
|
17
|
+
'"': "'",
|
|
18
|
+
':': ';',
|
|
19
|
+
'{': '[',
|
|
20
|
+
'}': ']',
|
|
21
|
+
'|': '\\',
|
|
22
|
+
'~': '`',
|
|
23
|
+
'+': '=',
|
|
24
|
+
_: '-',
|
|
25
|
+
'!': '1',
|
|
26
|
+
'@': '2',
|
|
27
|
+
'#': '3',
|
|
28
|
+
$: '4',
|
|
29
|
+
'%': '5',
|
|
30
|
+
'^': '6',
|
|
31
|
+
'&': '7',
|
|
32
|
+
'*': '8',
|
|
33
|
+
'(': '9',
|
|
34
|
+
')': '0',
|
|
32
35
|
};
|
|
33
|
-
const
|
|
34
|
-
'en-US': {
|
|
35
|
-
shiftedKeys: Object.values(SHIFT_MAP),
|
|
36
|
-
shiftMap: SHIFT_MAP,
|
|
37
|
-
modKey: IS_MAC.test(navigator.platform) ? 'metaKey' : 'ctrlKey',
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
exports.TranslateKey = {
|
|
41
|
-
Shift: '',
|
|
42
|
-
Alt: '',
|
|
43
|
-
Meta: '',
|
|
44
|
-
Control: '',
|
|
36
|
+
const TranslateKey = {
|
|
45
37
|
ArrowUp: 'up',
|
|
46
38
|
ArrowDown: 'down',
|
|
47
39
|
ArrowLeft: 'left',
|
|
48
40
|
ArrowRight: 'right',
|
|
49
41
|
Escape: 'esc',
|
|
42
|
+
Space: 'space',
|
|
43
|
+
Backquote: '`',
|
|
44
|
+
Minus: '-',
|
|
45
|
+
Equal: '=',
|
|
46
|
+
BracketLeft: '[',
|
|
47
|
+
BracketRight: ']',
|
|
48
|
+
Quote: "'",
|
|
49
|
+
Backslash: '\\',
|
|
50
|
+
Apostrophe: "'",
|
|
51
|
+
Semicolon: ';',
|
|
52
|
+
Comma: ',',
|
|
53
|
+
Period: '.',
|
|
54
|
+
Slash: '/',
|
|
50
55
|
};
|
|
51
|
-
|
|
56
|
+
exports.KeyboardLayoutData = {
|
|
57
|
+
'en-US': {
|
|
58
|
+
shiftMap: SHIFT_MAP,
|
|
59
|
+
translate({ code, key }) {
|
|
60
|
+
const translated = TranslateKey[code];
|
|
61
|
+
if (translated)
|
|
62
|
+
return translated;
|
|
63
|
+
if (code.startsWith('Key'))
|
|
64
|
+
return code.slice(3).toLowerCase();
|
|
65
|
+
if (code.startsWith('Digit'))
|
|
66
|
+
return code.slice(5);
|
|
67
|
+
return key.toLowerCase();
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* The `keyboardEventToString` function converts a `Key` object to a string that represents the key combination pressed.
|
|
73
|
+
* It checks individual modifier keys (`ctrlKey`, `altKey`, `shiftKey`, and `metaKey`) and constructs a concatenated
|
|
74
|
+
* string reflecting these modifiers followed by the translated character key.
|
|
75
|
+
*
|
|
76
|
+
* Exceptions include when the `key` is 'Shift', 'Alt', 'Meta', 'Control', or 'Dead' without an `altKey`,
|
|
77
|
+
* as these are discarded (represented by an empty string). If no modifiers are pressed, it directly returns
|
|
78
|
+
* the translated character.
|
|
79
|
+
*
|
|
80
|
+
* This conversion provides a consistent way to describe key combinations as strings, essential for handling
|
|
81
|
+
* and processing keyboard shortcuts or sequences in the application.
|
|
82
|
+
*/
|
|
83
|
+
function keyboardEventToString(ev, { translate }) {
|
|
52
84
|
const key = ev.key;
|
|
53
85
|
if (!key ||
|
|
54
86
|
key === 'Shift' ||
|
|
55
87
|
key === 'Alt' ||
|
|
56
88
|
key === 'Meta' ||
|
|
57
|
-
key === 'Control'
|
|
89
|
+
key === 'Control' ||
|
|
90
|
+
(key === 'Dead' && !ev.altKey))
|
|
58
91
|
return '';
|
|
59
|
-
const ch =
|
|
92
|
+
const ch = translate(ev);
|
|
60
93
|
let result;
|
|
61
94
|
if (ev.ctrlKey)
|
|
62
95
|
result = 'ctrl';
|
|
63
96
|
if (ev.altKey)
|
|
64
97
|
result = result ? result + '+alt' : 'alt';
|
|
65
|
-
if (ev.shiftKey
|
|
98
|
+
if (ev.shiftKey)
|
|
66
99
|
result = result ? result + '+shift' : 'shift';
|
|
67
100
|
if (ev.metaKey)
|
|
68
101
|
result = result ? result + '+meta' : 'meta';
|
|
69
102
|
return result ? result + '+' + ch : ch;
|
|
70
103
|
}
|
|
71
|
-
|
|
104
|
+
/**
|
|
105
|
+
* The `handleKeyboard` function sets up event listeners to handle keyboard events on a given HTML element.
|
|
106
|
+
* It accepts a configuration object (`KeyboardOptions`) which includes the target HTML element, a callback
|
|
107
|
+
* `onKey` to handle keyboard sequences, a `delay` for typing sequence recognition, an optional keyboard
|
|
108
|
+
* layout, and an optional capture mode for events.
|
|
109
|
+
*
|
|
110
|
+
* - Defaults the delay to 250ms if not specified, using this delay to determine when to treat subsequent
|
|
111
|
+
* key presses as part of the same sequence or a new one.
|
|
112
|
+
* - Determines the keyboard layout, either from the provided options or defaults, which affects how keys
|
|
113
|
+
* (especially with modifiers) are interpreted.
|
|
114
|
+
* - Adds a `keydown` event listener to the provided element, allowing modification of event behavior such
|
|
115
|
+
* as propagation and default handling based on the `onKey` callback result.
|
|
116
|
+
* - Builds a key sequence based on timing and calls the `onKey` handler with the assembled sequence,
|
|
117
|
+
* stopping event propagation based on handler response.
|
|
118
|
+
* - The handler uses the sequence to manage shortcuts and performs preventative measures against default
|
|
119
|
+
* browser actions.
|
|
120
|
+
* @return A cleanup function that removes the event listener.
|
|
121
|
+
*/
|
|
122
|
+
function handleKeyboard({ element, onKey, delay, layout, capture, }) {
|
|
72
123
|
const D = delay === undefined ? 250 : delay;
|
|
73
124
|
const locale = navigator.language;
|
|
74
125
|
let sequence = [];
|
|
75
126
|
let lastT = 0;
|
|
76
|
-
|
|
127
|
+
layout || (layout = exports.KeyboardLayoutData[locale] || exports.KeyboardLayoutData['en-US']);
|
|
128
|
+
const newLayout = augmentLayout(layout);
|
|
77
129
|
function handler(ev) {
|
|
78
130
|
const k = keyboardEventToString(ev, newLayout);
|
|
79
131
|
let t = Date.now();
|
|
@@ -95,14 +147,16 @@ function handleKeyboard({ element, onKey, delay, layout, }) {
|
|
|
95
147
|
} while (seq.length);
|
|
96
148
|
lastT = t;
|
|
97
149
|
}
|
|
98
|
-
element.addEventListener('keydown', handler);
|
|
99
|
-
return () => element.removeEventListener('keydown', handler);
|
|
150
|
+
element.addEventListener('keydown', handler, { capture });
|
|
151
|
+
return () => element.removeEventListener('keydown', handler, { capture });
|
|
100
152
|
}
|
|
101
|
-
|
|
153
|
+
// Retrieves the default `KeyboardLayout` based on the current user's language settings from `navigator.language`.
|
|
154
|
+
// Falls back to the 'en-US' layout if the user's specific language is not available in `KeyboardLayoutData`.
|
|
155
|
+
// This function helps ensure that the keyboard handling can adapt to the most appropriate layout for the user,
|
|
156
|
+
// facilitating the accurate interpretation of key sequences and modifiers according to locale preferences.
|
|
102
157
|
function getDefaultLayout() {
|
|
103
|
-
return (KeyboardLayoutData[navigator
|
|
158
|
+
return (exports.KeyboardLayoutData[navigator?.language] || exports.KeyboardLayoutData['en-US']);
|
|
104
159
|
}
|
|
105
|
-
exports.getDefaultLayout = getDefaultLayout;
|
|
106
160
|
function newKey() {
|
|
107
161
|
return {
|
|
108
162
|
ctrlKey: false,
|
|
@@ -110,9 +164,19 @@ function newKey() {
|
|
|
110
164
|
metaKey: false,
|
|
111
165
|
altKey: false,
|
|
112
166
|
key: '',
|
|
167
|
+
code: '',
|
|
113
168
|
};
|
|
114
169
|
}
|
|
115
|
-
|
|
170
|
+
/**
|
|
171
|
+
* This function, `parseKey`, takes a key combination string and splits it into a sequence of `Key` objects.
|
|
172
|
+
* It uses regular expressions to identify each part of the key combination, accounting for modifier keys
|
|
173
|
+
* like 'shift', 'ctrl', 'alt', 'meta', and 'mod', the latter being dependent on the `modKey` from the
|
|
174
|
+
* `KeyboardLayout` (either 'ctrlKey' or 'metaKey' depending on the platform). For non-modifier keys, it
|
|
175
|
+
* checks if the `shiftKey` is active and if the key should be shifted using the `shiftMap`. This logic
|
|
176
|
+
* ensures the function captures accurate key state details in preparation for further handling like matching
|
|
177
|
+
* key sequences in the `handleKeyboard` function.
|
|
178
|
+
*/
|
|
179
|
+
function _parseKey(key, { modKey, shiftMap }) {
|
|
116
180
|
const sequence = [];
|
|
117
181
|
let match;
|
|
118
182
|
let event = newKey();
|
|
@@ -130,9 +194,12 @@ function parseKey(key, { modKey, shiftMap } = getDefaultLayout()) {
|
|
|
130
194
|
event[modKey] = true;
|
|
131
195
|
else {
|
|
132
196
|
const shifted = shiftMap[ch];
|
|
133
|
-
if (shifted)
|
|
134
|
-
event.
|
|
135
|
-
|
|
197
|
+
if (shifted) {
|
|
198
|
+
event.key = shifted;
|
|
199
|
+
event.shiftKey = true;
|
|
200
|
+
}
|
|
201
|
+
else
|
|
202
|
+
event.key = ch;
|
|
136
203
|
}
|
|
137
204
|
if (match[2] !== '+') {
|
|
138
205
|
sequence.push(event);
|
|
@@ -141,13 +208,26 @@ function parseKey(key, { modKey, shiftMap } = getDefaultLayout()) {
|
|
|
141
208
|
}
|
|
142
209
|
return sequence;
|
|
143
210
|
}
|
|
144
|
-
|
|
211
|
+
function augmentLayout(layout) {
|
|
212
|
+
return {
|
|
213
|
+
modKey: IS_MAC.test(navigator.platform) ? 'metaKey' : 'ctrlKey',
|
|
214
|
+
...layout,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
function parseKey(key, layout = getDefaultLayout()) {
|
|
218
|
+
return _parseKey(key, augmentLayout(layout));
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Converts a string representing a key combination into a normalized string format.
|
|
222
|
+
* This function takes a `key` string and an optional `layout` object (defaults to the user's layout).
|
|
223
|
+
* It uses `parseKey` to break the key combination into individual `Key` objects, each representing
|
|
224
|
+
* a parsed key press. It then converts each `Key` object back to a string using `keyboardEventToString`,
|
|
225
|
+
* considering the layout's details like `shiftedKeys` and `shiftMap`. The resulting
|
|
226
|
+
* strings are concatenated with spaces and returned as the normalized form. This is useful
|
|
227
|
+
* for ensuring consistent representation of key sequences across different keyboard layouts.
|
|
228
|
+
*/
|
|
145
229
|
function normalize(key, layout = getDefaultLayout()) {
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
sequence[i] = keyboardEventToString(sequence[i], layout);
|
|
150
|
-
return sequence.join(' ');
|
|
230
|
+
const newLayout = augmentLayout(layout);
|
|
231
|
+
const sequence = _parseKey(key, newLayout);
|
|
232
|
+
return sequence.map(key => keyboardEventToString(key, newLayout)).join(' ');
|
|
151
233
|
}
|
|
152
|
-
exports.normalize = normalize;
|
|
153
|
-
//# sourceMappingURL=index.js.map
|
package/index.min.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.
|
|
2
|
-
//# sourceMappingURL=index.min.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.KeyboardLayoutData=void 0,exports.handleKeyboard=handleKeyboard,exports.parseKey=parseKey,exports.normalize=normalize;const navigator="undefined"!=typeof window?window.navigator:{language:"en-US",platform:"nodejs"},IS_MAC=/Mac|iPod|iPhone|iPad/,PARSE_KEY=/(shift|ctrl|control|alt|option|meta|command|cmd|mod|[^\s+]+)(\s*\+|\s)?/g,SHIFT_MAP={"?":"/",">":".","<":",",'"':"'",":":";","{":"[","}":"]","|":"\\","~":"`","+":"=",_:"-","!":"1","@":"2","#":"3",$:"4","%":"5","^":"6","&":"7","*":"8","(":"9",")":"0"},TranslateKey={ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right",Escape:"esc",Space:"space",Backquote:"`",Minus:"-",Equal:"=",BracketLeft:"[",BracketRight:"]",Quote:"'",Backslash:"\\",Apostrophe:"'",Semicolon:";",Comma:",",Period:".",Slash:"/"};function keyboardEventToString(e,{translate:t}){const a=e.key;if(!a||"Shift"===a||"Alt"===a||"Meta"===a||"Control"===a||"Dead"===a&&!e.altKey)return"";const o=t(e);let n;return e.ctrlKey&&(n="ctrl"),e.altKey&&(n=n?n+"+alt":"alt"),e.shiftKey&&(n=n?n+"+shift":"shift"),e.metaKey&&(n=n?n+"+meta":"meta"),n?n+"+"+o:o}function handleKeyboard({element:e,onKey:t,delay:a,layout:o,capture:n}){const r=void 0===a?250:a,s=navigator.language;let i=[],y=0;o||(o=exports.KeyboardLayoutData[s]||exports.KeyboardLayoutData["en-US"]);const l=augmentLayout(o);function u(e){const a=keyboardEventToString(e,l);let o=Date.now();if(!a)return;o-y<r?i.push(a):i=[a];const n=i.slice(0);do{if(!1!==t(n.join(" "),i)){e.stopPropagation(),e.preventDefault(),o=0;break}n.shift()}while(n.length);y=o}return e.addEventListener("keydown",u,{capture:n}),()=>e.removeEventListener("keydown",u,{capture:n})}function getDefaultLayout(){return exports.KeyboardLayoutData[navigator?.language]||exports.KeyboardLayoutData["en-US"]}function newKey(){return{ctrlKey:!1,shiftKey:!1,metaKey:!1,altKey:!1,key:"",code:""}}function _parseKey(e,{modKey:t,shiftMap:a}){const o=[];let n,r=newKey();for(;n=PARSE_KEY.exec(e.toLowerCase());){const e=n[1];if("shift"===e)r.shiftKey=!0;else if("ctrl"===e||"control"===e)r.ctrlKey=!0;else if("alt"===e||"option"===e)r.altKey=!0;else if("meta"===e||"cmd"===e||"command"===e)r.metaKey=!0;else if("mod"===e)r[t]=!0;else{const t=a[e];t?(r.key=t,r.shiftKey=!0):r.key=e}"+"!==n[2]&&(o.push(r),r=newKey())}return o}function augmentLayout(e){return{modKey:IS_MAC.test(navigator.platform)?"metaKey":"ctrlKey",...e}}function parseKey(e,t=getDefaultLayout()){return _parseKey(e,augmentLayout(t))}function normalize(e,t=getDefaultLayout()){const a=augmentLayout(t);return _parseKey(e,a).map((e=>keyboardEventToString(e,a))).join(" ")}exports.KeyboardLayoutData={"en-US":{shiftMap:SHIFT_MAP,translate({code:e,key:t}){const a=TranslateKey[e];return a||(e.startsWith("Key")?e.slice(3).toLowerCase():e.startsWith("Digit")?e.slice(5):t.toLowerCase())}}};
|
package/mjs/index.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
interface Key {
|
|
2
|
+
ctrlKey: boolean;
|
|
3
|
+
altKey: boolean;
|
|
4
|
+
shiftKey: boolean;
|
|
5
|
+
metaKey: boolean;
|
|
6
|
+
key: string;
|
|
7
|
+
code: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The `KeyboardOptions` interface defines the configuration needed to handle keyboard interactions with
|
|
11
|
+
* a specific HTML element.
|
|
12
|
+
*/
|
|
13
|
+
export interface KeyboardOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Specifies the HTML element on which keyboard events are captured.
|
|
16
|
+
* This element will receive focus and listen for key events.
|
|
17
|
+
*/
|
|
18
|
+
element: HTMLElement;
|
|
19
|
+
/**
|
|
20
|
+
* A callback function that processes key events. It receives the current key being pressed
|
|
21
|
+
* and the sequence of keys accumulated so far. It returns `true` or `false` to indicate whether
|
|
22
|
+
* the sequence was consumed.
|
|
23
|
+
*/
|
|
24
|
+
onKey: (key: string, sequence: string[]) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The time in milliseconds to wait between key presses before resetting the sequence.
|
|
27
|
+
* Defaults to 250ms if not provided, ensuring thoughtful key sequences rather than accidental key presses.
|
|
28
|
+
*/
|
|
29
|
+
delay?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Optional parameter to specify a custom `KeyboardLayout`.
|
|
32
|
+
* Defaults to 'en-US' if not provided. This affects how key combinations and modifier keys are interpreted.
|
|
33
|
+
*/
|
|
34
|
+
layout?: KeyboardLayout;
|
|
35
|
+
/**
|
|
36
|
+
* Boolean indicating whether to capture key events in the capture phase.
|
|
37
|
+
* This determines when the event listener reacts in the event propagation flow.
|
|
38
|
+
*/
|
|
39
|
+
capture?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The `KeyboardLayout` interface describes how a keyboard layout should be structured internally.
|
|
43
|
+
*/
|
|
44
|
+
export interface KeyboardLayout {
|
|
45
|
+
/**
|
|
46
|
+
* A mapping of shifted keys to their non-shifted counterparts, used to accurately
|
|
47
|
+
* interpret which character a shifted key press represents.
|
|
48
|
+
*/
|
|
49
|
+
shiftMap: Record<string, string | undefined>;
|
|
50
|
+
/**
|
|
51
|
+
* Maps the representation of keys when combined with the alt key.
|
|
52
|
+
*/
|
|
53
|
+
translate(ev: Key): string;
|
|
54
|
+
/**
|
|
55
|
+
* Indicates whether the 'meta' or 'ctrl' key is the primary modifier used for commands,
|
|
56
|
+
* differing based on the operating system (e.g., 'metaKey' for macOS).
|
|
57
|
+
*/
|
|
58
|
+
modKey?: 'metaKey' | 'ctrlKey';
|
|
59
|
+
}
|
|
60
|
+
export declare const KeyboardLayoutData: Record<string, KeyboardLayout>;
|
|
61
|
+
/**
|
|
62
|
+
* The `handleKeyboard` function sets up event listeners to handle keyboard events on a given HTML element.
|
|
63
|
+
* It accepts a configuration object (`KeyboardOptions`) which includes the target HTML element, a callback
|
|
64
|
+
* `onKey` to handle keyboard sequences, a `delay` for typing sequence recognition, an optional keyboard
|
|
65
|
+
* layout, and an optional capture mode for events.
|
|
66
|
+
*
|
|
67
|
+
* - Defaults the delay to 250ms if not specified, using this delay to determine when to treat subsequent
|
|
68
|
+
* key presses as part of the same sequence or a new one.
|
|
69
|
+
* - Determines the keyboard layout, either from the provided options or defaults, which affects how keys
|
|
70
|
+
* (especially with modifiers) are interpreted.
|
|
71
|
+
* - Adds a `keydown` event listener to the provided element, allowing modification of event behavior such
|
|
72
|
+
* as propagation and default handling based on the `onKey` callback result.
|
|
73
|
+
* - Builds a key sequence based on timing and calls the `onKey` handler with the assembled sequence,
|
|
74
|
+
* stopping event propagation based on handler response.
|
|
75
|
+
* - The handler uses the sequence to manage shortcuts and performs preventative measures against default
|
|
76
|
+
* browser actions.
|
|
77
|
+
* @return A cleanup function that removes the event listener.
|
|
78
|
+
*/
|
|
79
|
+
export declare function handleKeyboard({ element, onKey, delay, layout, capture, }: KeyboardOptions): () => void;
|
|
80
|
+
export declare function parseKey(key: string, layout?: KeyboardLayout): Key[];
|
|
81
|
+
/**
|
|
82
|
+
* Converts a string representing a key combination into a normalized string format.
|
|
83
|
+
* This function takes a `key` string and an optional `layout` object (defaults to the user's layout).
|
|
84
|
+
* It uses `parseKey` to break the key combination into individual `Key` objects, each representing
|
|
85
|
+
* a parsed key press. It then converts each `Key` object back to a string using `keyboardEventToString`,
|
|
86
|
+
* considering the layout's details like `shiftedKeys` and `shiftMap`. The resulting
|
|
87
|
+
* strings are concatenated with spaces and returned as the normalized form. This is useful
|
|
88
|
+
* for ensuring consistent representation of key sequences across different keyboard layouts.
|
|
89
|
+
*/
|
|
90
|
+
export declare function normalize(key: string, layout?: KeyboardLayout): string;
|
|
91
|
+
export {};
|
package/mjs/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const navigator="undefined"!=typeof window?window.navigator:{language:"en-US",platform:"nodejs"},IS_MAC=/Mac|iPod|iPhone|iPad/,PARSE_KEY=/(shift|ctrl|control|alt|option|meta|command|cmd|mod|[^\s+]+)(\s*\+|\s)?/g,SHIFT_MAP={"?":"/",">":".","<":",",'"':"'",":":";","{":"[","}":"]","|":"\\","~":"`","+":"=",_:"-","!":"1","@":"2","#":"3",$:"4","%":"5","^":"6","&":"7","*":"8","(":"9",")":"0"},TranslateKey={ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right",Escape:"esc",Space:"space",Backquote:"`",Minus:"-",Equal:"=",BracketLeft:"[",BracketRight:"]",Quote:"'",Backslash:"\\",Apostrophe:"'",Semicolon:";",Comma:",",Period:".",Slash:"/"};export const KeyboardLayoutData={"en-US":{shiftMap:SHIFT_MAP,translate:({code:e,key:t})=>TranslateKey[e]||(e.startsWith("Key")?e.slice(3).toLowerCase():e.startsWith("Digit")?e.slice(5):t.toLowerCase())}};function keyboardEventToString(e,{translate:t}){const a=e.key;if(!a||"Shift"===a||"Alt"===a||"Meta"===a||"Control"===a||"Dead"===a&&!e.altKey)return"";const o=t(e);let n;return e.ctrlKey&&(n="ctrl"),e.altKey&&(n=n?n+"+alt":"alt"),e.shiftKey&&(n=n?n+"+shift":"shift"),e.metaKey&&(n=n?n+"+meta":"meta"),n?n+"+"+o:o}export function handleKeyboard({element:e,onKey:t,delay:a,layout:o,capture:n}){const r=void 0===a?250:a,i=navigator.language;let s=[],y=0;o||(o=KeyboardLayoutData[i]||KeyboardLayoutData["en-US"]);const l=augmentLayout(o);function u(e){const a=keyboardEventToString(e,l);let o=Date.now();if(!a)return;o-y<r?s.push(a):s=[a];const n=s.slice(0);do{if(!1!==t(n.join(" "),s)){e.stopPropagation(),e.preventDefault(),o=0;break}n.shift()}while(n.length);y=o}return e.addEventListener("keydown",u,{capture:n}),()=>e.removeEventListener("keydown",u,{capture:n})}function getDefaultLayout(){return KeyboardLayoutData[navigator?.language]||KeyboardLayoutData["en-US"]}function newKey(){return{ctrlKey:!1,shiftKey:!1,metaKey:!1,altKey:!1,key:"",code:""}}function _parseKey(e,{modKey:t,shiftMap:a}){const o=[];let n,r=newKey();for(;n=PARSE_KEY.exec(e.toLowerCase());){const e=n[1];if("shift"===e)r.shiftKey=!0;else if("ctrl"===e||"control"===e)r.ctrlKey=!0;else if("alt"===e||"option"===e)r.altKey=!0;else if("meta"===e||"cmd"===e||"command"===e)r.metaKey=!0;else if("mod"===e)r[t]=!0;else{const t=a[e];t?(r.key=t,r.shiftKey=!0):r.key=e}"+"!==n[2]&&(o.push(r),r=newKey())}return o}function augmentLayout(e){return{modKey:IS_MAC.test(navigator.platform)?"metaKey":"ctrlKey",...e}}export function parseKey(e,t=getDefaultLayout()){return _parseKey(e,augmentLayout(t))}export function normalize(e,t=getDefaultLayout()){const a=augmentLayout(t);return _parseKey(e,a).map((e=>keyboardEventToString(e,a))).join(" ")}
|
package/package.json
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cxl/keyboard",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Keyboard Handling Library",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"files": [
|
|
7
7
|
"*.js",
|
|
8
8
|
"*.d.ts",
|
|
9
|
-
"*.
|
|
9
|
+
"*.css",
|
|
10
10
|
"amd/*.js",
|
|
11
11
|
"amd/*.d.ts",
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"es6/*.d.ts",
|
|
15
|
-
"es6/*.js.map",
|
|
12
|
+
"mjs/*.js",
|
|
13
|
+
"mjs/*.d.ts",
|
|
16
14
|
"LICENSE",
|
|
17
15
|
"*.md"
|
|
18
16
|
],
|
|
19
17
|
"main": "index.js",
|
|
20
|
-
"browser": "amd/index.
|
|
18
|
+
"browser": "amd/index.js",
|
|
21
19
|
"homepage": "https://cxlio.github.io/cxl/keyboard",
|
|
22
20
|
"bugs": "https://github.com/cxlio/cxl/issues",
|
|
23
21
|
"repository": {
|
|
@@ -25,4 +23,4 @@
|
|
|
25
23
|
"url": "https://github.com/cxlio/cxl.git",
|
|
26
24
|
"directory": "keyboard"
|
|
27
25
|
}
|
|
28
|
-
}
|
|
26
|
+
}
|
package/test.js
CHANGED
|
@@ -4,22 +4,236 @@ const spec_1 = require("@cxl/spec");
|
|
|
4
4
|
const index_js_1 = require("@cxl/keyboard");
|
|
5
5
|
exports.default = (0, spec_1.spec)('keyboard', s => {
|
|
6
6
|
s.test('normalize', it => {
|
|
7
|
+
it.should('handle empty and null inputs', a => {
|
|
8
|
+
a.equal((0, index_js_1.normalize)(''), '');
|
|
9
|
+
});
|
|
7
10
|
it.should('parse single keys', a => {
|
|
8
11
|
a.equal((0, index_js_1.normalize)(' x '), 'x');
|
|
12
|
+
a.equal((0, index_js_1.normalize)('ctrl+x'), 'ctrl+x');
|
|
9
13
|
});
|
|
10
14
|
it.should('parse multiple keys', a => {
|
|
11
15
|
a.equal((0, index_js_1.normalize)(' x y'), 'x y');
|
|
16
|
+
a.equal((0, index_js_1.normalize)('x y'), 'x y');
|
|
12
17
|
a.equal((0, index_js_1.normalize)('ctrl+shift+x'), 'ctrl+shift+x');
|
|
13
18
|
});
|
|
14
19
|
it.should('parse mod key', a => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
const layout = {
|
|
21
|
+
...index_js_1.KeyboardLayoutData['en-US'],
|
|
22
|
+
modKey: 'ctrlKey',
|
|
23
|
+
};
|
|
24
|
+
a.equal((0, index_js_1.normalize)('mod+x', layout), 'ctrl+x');
|
|
25
|
+
a.equal((0, index_js_1.normalize)('x+mod', layout), 'ctrl+x');
|
|
26
|
+
a.equal((0, index_js_1.normalize)('MOD+X', layout), 'ctrl+x');
|
|
27
|
+
layout.modKey = 'metaKey';
|
|
28
|
+
a.equal((0, index_js_1.normalize)('mod+x', layout), 'meta+x');
|
|
29
|
+
a.equal((0, index_js_1.normalize)('x+mod', layout), 'meta+x');
|
|
30
|
+
a.equal((0, index_js_1.normalize)('MOD+X', layout), 'meta+x');
|
|
18
31
|
});
|
|
19
32
|
it.should('normalize shifted keys', a => {
|
|
20
|
-
a.equal((0, index_js_1.normalize)('
|
|
21
|
-
a.equal((0, index_js_1.normalize)('shift+
|
|
33
|
+
a.equal((0, index_js_1.normalize)('%'), 'shift+5');
|
|
34
|
+
a.equal((0, index_js_1.normalize)('shift+A'), 'shift+a');
|
|
35
|
+
a.equal((0, index_js_1.normalize)('shift+y'), 'shift+y');
|
|
36
|
+
a.equal((0, index_js_1.normalize)('shift+ctrl+5'), 'ctrl+shift+5');
|
|
37
|
+
a.equal((0, index_js_1.normalize)('ctrl+%'), 'ctrl+shift+5');
|
|
38
|
+
});
|
|
39
|
+
it.should('handle non character keys', a => {
|
|
40
|
+
a.equal((0, index_js_1.normalize)(':'), 'shift+;');
|
|
41
|
+
a.equal((0, index_js_1.normalize)('/'), '/');
|
|
42
|
+
a.equal((0, index_js_1.normalize)('.'), '.');
|
|
43
|
+
a.equal((0, index_js_1.normalize)('?'), 'shift+/');
|
|
44
|
+
a.equal((0, index_js_1.normalize)('shift+/'), 'shift+/');
|
|
45
|
+
//a.equal(normalize('shift++'), 'shift+=');
|
|
46
|
+
a.equal((0, index_js_1.normalize)('shift+?'), 'shift+/');
|
|
47
|
+
a.equal((0, index_js_1.normalize)('ctrl+:'), 'ctrl+shift+;');
|
|
48
|
+
a.equal((0, index_js_1.normalize)('ctrl+shift+?'), 'ctrl+shift+/');
|
|
49
|
+
a.equal((0, index_js_1.normalize)(';'), ';');
|
|
50
|
+
});
|
|
51
|
+
it.should('normalize special keys with modifiers', a => {
|
|
52
|
+
a.equal((0, index_js_1.normalize)('ctrl+alt+del'), 'ctrl+alt+del');
|
|
53
|
+
a.equal((0, index_js_1.normalize)('ctrl+shift+esc'), 'ctrl+shift+esc');
|
|
54
|
+
});
|
|
55
|
+
it.should('handle case sensitivity', a => {
|
|
56
|
+
a.equal((0, index_js_1.normalize)('CTRL+A'), 'ctrl+a');
|
|
57
|
+
a.equal((0, index_js_1.normalize)('Shift+Y'), 'shift+y');
|
|
58
|
+
});
|
|
59
|
+
/*it.should('handle complex sequences', a => {
|
|
60
|
+
a.equal(
|
|
61
|
+
normalize(' ctrl + shift + x ctrl+y'),
|
|
62
|
+
'ctrl+shift+x ctrl+y',
|
|
63
|
+
);
|
|
64
|
+
});*/
|
|
65
|
+
});
|
|
66
|
+
s.test('parseKey', it => {
|
|
67
|
+
it.should('correctly parse simple keys without modifiers', a => {
|
|
68
|
+
const result = (0, index_js_1.parseKey)('a');
|
|
69
|
+
a.equal(result.length, 1);
|
|
70
|
+
a.equal(result[0].key, 'a');
|
|
71
|
+
a.equal(result[0].shiftKey, false);
|
|
72
|
+
a.equal(result[0].ctrlKey, false);
|
|
73
|
+
a.equal(result[0].altKey, false);
|
|
74
|
+
a.equal(result[0].metaKey, false);
|
|
75
|
+
});
|
|
76
|
+
it.should('correctly parse modifier keys', a => {
|
|
77
|
+
const result = (0, index_js_1.parseKey)('shift+b');
|
|
78
|
+
a.equal(result.length, 1);
|
|
79
|
+
a.equal(result[0].key, 'b');
|
|
80
|
+
a.equal(result[0].shiftKey, true);
|
|
81
|
+
a.equal(result[0].ctrlKey, false);
|
|
82
|
+
a.equal(result[0].altKey, false);
|
|
83
|
+
a.equal(result[0].metaKey, false);
|
|
84
|
+
});
|
|
85
|
+
it.should('correctly parse multiple keys with modifiers', a => {
|
|
86
|
+
const result = (0, index_js_1.parseKey)('ctrl+alt+del');
|
|
87
|
+
a.equal(result.length, 1);
|
|
88
|
+
a.equal(result[0].key, 'del');
|
|
89
|
+
a.equal(result[0].shiftKey, false);
|
|
90
|
+
a.equal(result[0].ctrlKey, true);
|
|
91
|
+
a.equal(result[0].altKey, true);
|
|
92
|
+
a.equal(result[0].metaKey, false);
|
|
93
|
+
});
|
|
94
|
+
it.should('handle key sequences separated by spaces', a => {
|
|
95
|
+
const result = (0, index_js_1.parseKey)('ctrl+a ctrl+b');
|
|
96
|
+
a.equal(result.length, 2);
|
|
97
|
+
a.equal(result[0].key, 'a');
|
|
98
|
+
a.equal(result[0].ctrlKey, true);
|
|
99
|
+
a.equal(result[1].key, 'b');
|
|
100
|
+
a.equal(result[1].ctrlKey, true);
|
|
101
|
+
});
|
|
102
|
+
it.should('map mod key to the correct modifier', a => {
|
|
103
|
+
const layout = index_js_1.KeyboardLayoutData['en-US'];
|
|
104
|
+
const result = (0, index_js_1.parseKey)('mod+c', { ...layout, modKey: 'ctrlKey' });
|
|
105
|
+
a.equal(result.length, 1);
|
|
106
|
+
a.equal(result[0].key, 'c');
|
|
107
|
+
a.equal(result[0].ctrlKey, true);
|
|
108
|
+
const result2 = (0, index_js_1.parseKey)('mod+c', { ...layout, modKey: 'metaKey' });
|
|
109
|
+
a.equal(result2.length, 1);
|
|
110
|
+
a.equal(result2[0].key, 'c');
|
|
111
|
+
a.equal(result2[0].metaKey, true);
|
|
112
|
+
});
|
|
113
|
+
it.should('handle shifted characters correctly', a => {
|
|
114
|
+
const result = (0, index_js_1.parseKey)('shift+1');
|
|
115
|
+
a.equal(result.length, 1);
|
|
116
|
+
a.equal(result[0].key, '1'); // assuming shift+1 maps to '@' in shiftMap
|
|
117
|
+
a.equal(result[0].shiftKey, true);
|
|
118
|
+
});
|
|
119
|
+
it.should('handle keys with special characters', a => {
|
|
120
|
+
const result = (0, index_js_1.parseKey)('ctrl+shift+1');
|
|
121
|
+
a.equal(result.length, 1);
|
|
122
|
+
a.equal(result[0].key, '1');
|
|
123
|
+
a.equal(result[0].ctrlKey, true);
|
|
124
|
+
a.equal(result[0].shiftKey, true);
|
|
125
|
+
});
|
|
126
|
+
it.should('handle unsupported modifier combinations', a => {
|
|
127
|
+
const result = (0, index_js_1.parseKey)('ctrl+alt+meta+z');
|
|
128
|
+
a.equal(result.length, 1);
|
|
129
|
+
a.equal(result[0].key, 'z');
|
|
130
|
+
a.equal(result[0].ctrlKey, true);
|
|
131
|
+
a.equal(result[0].altKey, true);
|
|
132
|
+
a.equal(result[0].metaKey, true);
|
|
133
|
+
});
|
|
134
|
+
it.should('correctly parse special character keys', a => {
|
|
135
|
+
const result = (0, index_js_1.parseKey)('ctrl+alt+!');
|
|
136
|
+
a.equal(result.length, 1);
|
|
137
|
+
a.equal(result[0].key, '1');
|
|
138
|
+
a.equal(result[0].ctrlKey, true);
|
|
139
|
+
a.equal(result[0].altKey, true);
|
|
140
|
+
a.equal(result[0].shiftKey, true);
|
|
141
|
+
});
|
|
142
|
+
it.should('handle unsupported character sequences', a => {
|
|
143
|
+
const result = (0, index_js_1.parseKey)('ctrl+alt+ctrl+z');
|
|
144
|
+
a.equal(result.length, 1);
|
|
145
|
+
a.equal(result[0].key, 'z');
|
|
146
|
+
a.equal(result[0].ctrlKey, true);
|
|
147
|
+
a.equal(result[0].altKey, true);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
s.test('handleKeyboard', it => {
|
|
151
|
+
it.should('call onKey with the correct sequence', (a) => {
|
|
152
|
+
// Setup a mock element
|
|
153
|
+
const elementMock = a.element('div');
|
|
154
|
+
const on = a.spyFn(elementMock, 'addEventListener');
|
|
155
|
+
const off = a.spyFn(elementMock, 'removeEventListener');
|
|
156
|
+
// Setup a mock callback
|
|
157
|
+
const onKeyMock = (0, spec_1.mockFn)(key => (key === 'a b' ? true : false));
|
|
158
|
+
// Register the handler
|
|
159
|
+
const dispose = (0, index_js_1.handleKeyboard)({
|
|
160
|
+
element: elementMock,
|
|
161
|
+
onKey: onKeyMock,
|
|
162
|
+
delay: 100,
|
|
163
|
+
layout: undefined,
|
|
164
|
+
capture: false,
|
|
165
|
+
});
|
|
166
|
+
// Simulate keydown events
|
|
167
|
+
const eventA = new KeyboardEvent('keydown', { key: 'a' });
|
|
168
|
+
const eventB = new KeyboardEvent('keydown', { key: 'b' });
|
|
169
|
+
// This will call the handler linked to the event
|
|
170
|
+
a.assert(typeof on.lastEvent?.arguments[1] === 'function');
|
|
171
|
+
on.lastEvent?.arguments[1](eventA);
|
|
172
|
+
a.equal(onKeyMock.lastArguments?.[0], 'a');
|
|
173
|
+
on.lastEvent?.arguments[1](eventB);
|
|
174
|
+
a.equal(onKeyMock.lastArguments?.[0], 'a b');
|
|
175
|
+
// Cleanup
|
|
176
|
+
dispose();
|
|
177
|
+
a.equal(off.lastEvent?.called, 1);
|
|
178
|
+
});
|
|
179
|
+
it.should('reset sequence after delay', async (a) => {
|
|
180
|
+
const elementMock = a.element('div');
|
|
181
|
+
const on = a.spyFn(elementMock, 'addEventListener');
|
|
182
|
+
const off = a.spyFn(elementMock, 'removeEventListener');
|
|
183
|
+
const onKeyMock = (0, spec_1.mockFn)(key => (key === 'a b' ? true : false));
|
|
184
|
+
const dispose = (0, index_js_1.handleKeyboard)({
|
|
185
|
+
element: elementMock,
|
|
186
|
+
onKey: onKeyMock,
|
|
187
|
+
delay: 100,
|
|
188
|
+
layout: undefined,
|
|
189
|
+
capture: false,
|
|
190
|
+
});
|
|
191
|
+
// Simulate keydown event
|
|
192
|
+
const eventA = new KeyboardEvent('keydown', { key: 'a' });
|
|
193
|
+
a.assert(typeof on.lastEvent?.arguments[1] === 'function');
|
|
194
|
+
on.lastEvent?.arguments[1](eventA);
|
|
195
|
+
// Advance time beyond delay
|
|
196
|
+
await new Promise(resolve => setTimeout(resolve, 200));
|
|
197
|
+
a.equal(onKeyMock.lastArguments?.[0], 'a');
|
|
198
|
+
// Simulate another keydown event
|
|
199
|
+
const eventC = new KeyboardEvent('keydown', { key: 'c' });
|
|
200
|
+
on.lastEvent?.arguments[1](eventC);
|
|
201
|
+
a.equal(onKeyMock.lastArguments?.[0], 'c');
|
|
202
|
+
// Cleanup
|
|
203
|
+
dispose();
|
|
204
|
+
a.equal(off.lastEvent?.called, 1);
|
|
205
|
+
});
|
|
206
|
+
it.should('handle rapid key presses correctly', (a) => {
|
|
207
|
+
const elementMock = a.element('div');
|
|
208
|
+
const on = a.spyFn(elementMock, 'addEventListener');
|
|
209
|
+
const onKeyMock = (0, spec_1.mockFn)(key => key === 'x y');
|
|
210
|
+
const dispose = (0, index_js_1.handleKeyboard)({
|
|
211
|
+
element: elementMock,
|
|
212
|
+
onKey: onKeyMock,
|
|
213
|
+
delay: 100,
|
|
214
|
+
layout: undefined,
|
|
215
|
+
capture: false,
|
|
216
|
+
});
|
|
217
|
+
const eventX = new KeyboardEvent('keydown', { key: 'x' });
|
|
218
|
+
const eventY = new KeyboardEvent('keydown', { key: 'y' });
|
|
219
|
+
a.assert(typeof on.lastEvent?.arguments[1] === 'function');
|
|
220
|
+
on.lastEvent?.arguments[1](eventX);
|
|
221
|
+
on.lastEvent?.arguments[1](eventY);
|
|
222
|
+
a.equal(onKeyMock.lastArguments?.[0], 'x y');
|
|
223
|
+
dispose();
|
|
224
|
+
});
|
|
225
|
+
it.should('verify event listener is removed on dispose', (a) => {
|
|
226
|
+
const elementMock = a.element('div');
|
|
227
|
+
const off = a.spyFn(elementMock, 'removeEventListener');
|
|
228
|
+
const dispose = (0, index_js_1.handleKeyboard)({
|
|
229
|
+
element: elementMock,
|
|
230
|
+
onKey: (0, spec_1.mockFn)(() => true),
|
|
231
|
+
delay: 100,
|
|
232
|
+
layout: undefined,
|
|
233
|
+
capture: false,
|
|
234
|
+
});
|
|
235
|
+
dispose();
|
|
236
|
+
a.equal(off.lastEvent?.called, 1);
|
|
22
237
|
});
|
|
23
238
|
});
|
|
24
239
|
});
|
|
25
|
-
//# sourceMappingURL=test.js.map
|
package/amd/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../keyboard/index.ts"],"names":[],"mappings":";;;;IA0Ba,QAAA,IAAI,GAAG,EAAE,CAAC;IAEvB,MAAM,SAAS,GACd,OAAO,MAAM,KAAK,WAAW;QAC5B,CAAC,CAAC,MAAM,CAAC,SAAS;QAClB,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;IAE9C,MAAM,MAAM,GAAG,sBAAsB,CAAC;IACtC,MAAM,SAAS,GAAG,sEAAsE,CAAC;IACzF,MAAM,SAAS,GAAG;QACjB,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG;QACR,IAAI,EAAE,GAAG;QACT,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,G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3B,CAAC;IAND,8BAMC"}
|
package/amd/index.min.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
define("@cxl/keyboard",["require","exports"],(function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.normalize=t.parseKey=t.getDefaultLayout=t.handleKeyboard=t.TranslateKey=t.Pass=void 0,t.Pass={};const n="undefined"!=typeof window?window.navigator:{language:"en-US",platform:"nodejs"},o=/(shift|ctrl|control|alt|option|meta|command|cmd|mod|\w+)(\s*\+|\s)?/g,a={"/":"?",".":">",",":"<","'":'"',";":":","[":"{","]":"}","\\":"|","`":"~","=":"+","-":"_",1:"!",2:"@",3:"#",4:"$",5:"%",6:"^",7:"&",8:"*",9:"(",0:")"},r={"en-US":{shiftedKeys:Object.values(a),shiftMap:a,modKey:/Mac|iPod|iPhone|iPad/.test(n.platform)?"metaKey":"ctrlKey"}};function l(e,{shiftedKeys:n}){const o=e.key;if(!o||"Shift"===o||"Alt"===o||"Meta"===o||"Control"===o)return"";const a=t.TranslateKey[o]||o.toLowerCase();let r;return e.ctrlKey&&(r="ctrl"),e.altKey&&(r=r?r+"+alt":"alt"),e.shiftKey&&!n.includes(a)&&(r=r?r+"+shift":"shift"),e.metaKey&&(r=r?r+"+meta":"meta"),r?r+"+"+a:a}function s(){return r[null==n?void 0:n.language]||r["en-US"]}function i(e,{modKey:t,shiftMap:n}=s()){const a=[];let r,l={ctrlKey:!1,shiftKey:!1,metaKey:!1,altKey:!1,key:""};for(;r=o.exec(e.toLowerCase());){const e=r[1];if("shift"===e)l.shiftKey=!0;else if("ctrl"===e||"control"===e)l.ctrlKey=!0;else if("alt"===e||"option"===e)l.altKey=!0;else if("meta"===e||"cmd"===e||"command"===e)l.metaKey=!0;else if("mod"===e)l[t]=!0;else{const t=n[e];t&&(l.shiftKey=!1),l.key=t||e}"+"!==r[2]&&(a.push(l),l={ctrlKey:!1,shiftKey:!1,metaKey:!1,altKey:!1,key:""})}return a}t.TranslateKey={Shift:"",Alt:"",Meta:"",Control:"",ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right",Escape:"esc"},t.handleKeyboard=function({element:e,onKey:t,delay:o,layout:a}){const s=void 0===o?250:o,i=n.language;let f=[],y=0;const c=a||r[i]||r["en-US"];function d(e){const n=l(e,c);let o=Date.now();if(!n)return;o-y<s?f.push(n):f=[n];const a=f.slice(0);do{if(!1!==t(a.join(" "),f)){e.stopPropagation(),e.preventDefault(),o=0;break}a.shift()}while(a.length);y=o}return e.addEventListener("keydown",d),()=>e.removeEventListener("keydown",d)},t.getDefaultLayout=s,t.parseKey=i,t.normalize=function(e,t=s()){const n=i(e,t);let o=n.length;for(;o--;)n[o]=l(n[o],t);return n.join(" ")}}));
|
|
2
|
-
//# sourceMappingURL=index.min.js.map
|
package/amd/index.min.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../keyboard/index.ts"],"names":["exports","Pass","navigator","window","language","platform","PARSE_KEY","SHIFT_MAP","/",".",",","'",";","[","]","\\","`","=","-","1","2","3","4","5","6","7","8","9","0","KeyboardLayoutData","en-US","shiftedKeys","Object","values","shiftMap","modKey","test","keyboardEventToString","ev","key","ch","TranslateKey","toLowerCase","result","ctrlKey","altKey","shiftKey","includes","metaKey","getDefaultLayout","parseKey","sequence","match","event","exec","shifted","push","Shift","Alt","Meta","Control","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Escape","handleKeyboard","element","onKey","delay","layout","D","undefined","locale","lastT","newLayout","handler","k","t","Date","now","seq","slice","join","stopPropagation","preventDefault","shift","length","addEventListener","removeEventListener","normalize","i"],"mappings":"kNA0BaA,EAAAC,KAAO,GAEpB,MAAMC,EACa,oBAAXC,OACJA,OAAOD,UACP,CAAEE,SAAU,QAASC,SAAU,UAG7BC,EAAY,uEACZC,EAAY,CACjBC,IAAK,IACLC,IAAK,IACLC,IAAK,IACLC,IAAK,IACLC,IAAK,IACLC,IAAK,IACLC,IAAK,IACLC,KAAM,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,EAAWD,EAASX,EAAK+B,GAC/B,IAAIqB,EAAIxC,EAASoC,OACjB,KAAOI,KACLxC,EAAiBwC,GAAKtD,EAAsBc,EAASwC,GAAIrB,GAC3D,OAAOnB,EAASgC,KAAK"}
|
package/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../keyboard/index.ts"],"names":[],"mappings":";;;AA0Ba,QAAA,IAAI,GAAG,EAAE,CAAC;AAEvB,MAAM,SAAS,GACd,OAAO,MAAM,KAAK,WAAW;IAC5B,CAAC,CAAC,MAAM,CAAC,SAAS;IAClB,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;AAE9C,MAAM,MAAM,GAAG,sBAAsB,CAAC;AACtC,MAAM,SAAS,GAAG,sEAAsE,CAAC;AACzF,MAAM,SAAS,GAAG;IACjB,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,IAAI,EAAE,GAAG;IACT,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;CACR,CAAC;AAEF,MAAM,kBAAkB,GAAmC;IAC1D,OAAO,EAAE;QACR,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;QACrC,QAAQ,EAAE,SAAS;QACnB,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,S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,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;aACvC;YACJ,MAAM,OAAO,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;YAC7B,IAAI,OAAO;gBAAE,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC;YACpC,KAAK,CAAC,GAAG,GAAG,OAAO,IAAI,EAAE,CAAC;SAC1B;QAED,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;YACrB,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACrB,KAAK,GAAG,MAAM,EAAE,CAAC;SACjB;KACD;IACD,OAAO,QAAQ,CAAC;AACjB,CAAC;AA9BD,4BA8BC;AAED,SAAgB,SAAS,CAAC,GAAW,EAAE,MAAM,GAAG,gBAAgB,EAAE;IACjE,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACvC,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE;QACR,QAAgB,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACnE,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAND,8BAMC"}
|
package/index.min.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../keyboard/index.ts"],"names":["exports","Pass","navigator","window","language","platform","IS_MAC","PARSE_KEY","SHIFT_MAP","/",".",",","'",";","[","]","\\","`","=","-","1","2","3","4","5","6","7","8","9","0","KeyboardLayoutData","en-US","shiftedKeys","Object","values","shiftMap","modKey","test","keyboardEventToString","ev","key","ch","TranslateKey","toLowerCase","result","ctrlKey","altKey","shiftKey","includes","metaKey","handleKeyboard","element","onKey","delay","layout","D","undefined","locale","sequence","lastT","newLayout","handler","k","t","Date","now","push","seq","slice","join","stopPropagation","preventDefault","shift","length","addEventListener","removeEventListener","getDefaultLayout","newKey","parseKey","match","event","exec","shifted","normalize","i","Shift","Alt","Meta","Control","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Escape"],"mappings":"gMA0BaA,QAAAC,KAAO,GAEpB,MAAMC,UACa,oBAAXC,OACJA,OAAOD,UACP,CAAEE,SAAU,QAASC,SAAU,UAE7BC,OAAS,uBACTC,UAAY,uEACZC,UAAY,CACjBC,IAAK,IACLC,IAAK,IACLC,IAAK,IACLC,IAAK,IACLC,IAAK,IACLC,IAAK,IACLC,IAAK,IACLC,KAAM,IACNC,IAAK,IACLC,IAAK,IACLC,IAAK,IACLC,EAAK,IACLC,EAAK,IACLC,EAAK,IACLC,EAAK,IACLC,EAAK,IACLC,EAAK,IACLC,EAAK,IACLC,EAAK,IACLC,EAAK,IACLC,EAAK,KAGAC,mBAAqD,CAC1DC,QAAS,CACRC,YAAaC,OAAOC,OAAO1B,WAC3B2B,SAAU3B,UACV4B,OAAQ9B,OAAO+B,KAAKnC,UAAUG,UAAY,UAAY,YAgBxD,SAASiC,sBACRC,GACAP,YAAEA,IAEF,MAAMQ,EAAMD,EAAGC,IACf,IACEA,GACO,UAARA,GACQ,QAARA,GACQ,SAARA,GACQ,YAARA,EAEA,MAAO,GAER,MAAMC,EAAKzC,QAAA0C,aAAaF,IAAQA,EAAIG,cACpC,IAAIC,EAOJ,OANIL,EAAGM,UAASD,EAAS,QACrBL,EAAGO,SAAQF,EAASA,EAASA,EAAS,OAAS,OAC/CL,EAAGQ,WAAaf,EAAYgB,SAASP,KACxCG,EAASA,EAASA,EAAS,SAAW,SACnCL,EAAGU,UAASL,EAASA,EAASA,EAAS,QAAU,QAE9CA,EAASA,EAAS,IAAMH,EAAKA,EAGrC,SAAgBS,gBAAeC,QAC9BA,EAAOC,MACPA,EAAKC,MACLA,EAAKC,OACLA,IAEA,MAAMC,OAAcC,IAAVH,EAAsB,IAAMA,EAChCI,EAASvD,UAAUE,SACzB,IAAIsD,EAAqB,GACrBC,EAA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