@theia/core 1.19.0 → 1.20.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.
Files changed (130) hide show
  1. package/lib/browser/color-registry.d.ts +3 -69
  2. package/lib/browser/color-registry.d.ts.map +1 -1
  3. package/lib/browser/color-registry.js +13 -27
  4. package/lib/browser/color-registry.js.map +1 -1
  5. package/lib/browser/common-frontend-contribution.d.ts +3 -3
  6. package/lib/browser/common-frontend-contribution.d.ts.map +1 -1
  7. package/lib/browser/common-frontend-contribution.js +64 -64
  8. package/lib/browser/common-frontend-contribution.js.map +1 -1
  9. package/lib/browser/core-preferences.d.ts.map +1 -1
  10. package/lib/browser/core-preferences.js +23 -20
  11. package/lib/browser/core-preferences.js.map +1 -1
  12. package/lib/browser/dialogs.d.ts.map +1 -1
  13. package/lib/browser/dialogs.js +4 -4
  14. package/lib/browser/dialogs.js.map +1 -1
  15. package/lib/browser/keyboard/browser-keyboard-frontend-contribution.js +2 -2
  16. package/lib/browser/keyboard/browser-keyboard-frontend-contribution.js.map +1 -1
  17. package/lib/browser/keyboard/browser-keyboard-layout-provider.d.ts +1 -1
  18. package/lib/browser/keyboard/browser-keyboard-layout-provider.d.ts.map +1 -1
  19. package/lib/browser/keyboard/browser-keyboard-layout-provider.spec.js +6 -4
  20. package/lib/browser/keyboard/browser-keyboard-layout-provider.spec.js.map +1 -1
  21. package/lib/browser/keyboard/keys.d.ts +2 -251
  22. package/lib/browser/keyboard/keys.d.ts.map +1 -1
  23. package/lib/browser/keyboard/keys.js +12 -614
  24. package/lib/browser/keyboard/keys.js.map +1 -1
  25. package/lib/browser/messaging/ws-connection-provider.d.ts +3 -3
  26. package/lib/browser/messaging/ws-connection-provider.d.ts.map +1 -1
  27. package/lib/browser/messaging/ws-connection-provider.js +14 -4
  28. package/lib/browser/messaging/ws-connection-provider.js.map +1 -1
  29. package/lib/browser/quick-input/quick-command-frontend-contribution.js +1 -1
  30. package/lib/browser/quick-input/quick-command-frontend-contribution.js.map +1 -1
  31. package/lib/browser/quick-input/quick-command-service.d.ts.map +1 -1
  32. package/lib/browser/quick-input/quick-command-service.js +2 -2
  33. package/lib/browser/quick-input/quick-command-service.js.map +1 -1
  34. package/lib/browser/quick-input/quick-input-service.d.ts +1 -201
  35. package/lib/browser/quick-input/quick-input-service.d.ts.map +1 -1
  36. package/lib/browser/quick-input/quick-input-service.js +11 -93
  37. package/lib/browser/quick-input/quick-input-service.js.map +1 -1
  38. package/lib/browser/shell/tab-bar-toolbar.js +1 -1
  39. package/lib/browser/shell/tab-bar-toolbar.js.map +1 -1
  40. package/lib/browser/storage-service.spec.js +1 -1
  41. package/lib/browser/storage-service.spec.js.map +1 -1
  42. package/lib/browser/theming.d.ts +5 -14
  43. package/lib/browser/theming.d.ts.map +1 -1
  44. package/lib/browser/theming.js +14 -0
  45. package/lib/browser/theming.js.map +1 -1
  46. package/lib/browser/window/default-window-service.js +1 -1
  47. package/lib/browser/window/default-window-service.js.map +1 -1
  48. package/lib/browser/window-contribution.d.ts.map +1 -1
  49. package/lib/browser/window-contribution.js +2 -2
  50. package/lib/browser/window-contribution.js.map +1 -1
  51. package/lib/common/color.d.ts +84 -0
  52. package/lib/common/color.d.ts.map +1 -0
  53. package/lib/common/color.js +44 -0
  54. package/lib/common/color.js.map +1 -0
  55. package/lib/common/command.d.ts +1 -0
  56. package/lib/common/command.d.ts.map +1 -1
  57. package/lib/common/command.js +4 -0
  58. package/lib/common/command.js.map +1 -1
  59. package/lib/common/i18n/localization.d.ts +9 -0
  60. package/lib/common/i18n/localization.d.ts.map +1 -1
  61. package/lib/common/i18n/localization.js +13 -2
  62. package/lib/common/i18n/localization.js.map +1 -1
  63. package/lib/common/keys.d.ts +269 -0
  64. package/lib/common/keys.d.ts.map +1 -0
  65. package/lib/common/keys.js +634 -0
  66. package/lib/common/keys.js.map +1 -0
  67. package/lib/common/messaging/abstract-connection-provider.d.ts +1 -1
  68. package/lib/common/messaging/abstract-connection-provider.d.ts.map +1 -1
  69. package/lib/common/messaging/abstract-connection-provider.js +3 -1
  70. package/lib/common/messaging/abstract-connection-provider.js.map +1 -1
  71. package/lib/common/messaging/proxy-factory.js +1 -1
  72. package/lib/common/messaging/proxy-factory.js.map +1 -1
  73. package/lib/common/nls.d.ts +5 -0
  74. package/lib/common/nls.d.ts.map +1 -1
  75. package/lib/common/nls.js +62 -0
  76. package/lib/common/nls.js.map +1 -1
  77. package/lib/common/path.d.ts +6 -0
  78. package/lib/common/path.d.ts.map +1 -1
  79. package/lib/common/path.js +16 -4
  80. package/lib/common/path.js.map +1 -1
  81. package/lib/common/path.spec.js +12 -0
  82. package/lib/common/path.spec.js.map +1 -1
  83. package/lib/common/promise-util.d.ts +2 -2
  84. package/lib/common/promise-util.d.ts.map +1 -1
  85. package/lib/common/promise-util.js.map +1 -1
  86. package/lib/common/quick-pick-service.d.ts +219 -1
  87. package/lib/common/quick-pick-service.d.ts.map +1 -1
  88. package/lib/common/quick-pick-service.js +108 -1
  89. package/lib/common/quick-pick-service.js.map +1 -1
  90. package/lib/common/theme.d.ts +30 -0
  91. package/lib/common/theme.d.ts.map +1 -0
  92. package/lib/common/theme.js +18 -0
  93. package/lib/common/theme.js.map +1 -0
  94. package/lib/electron-browser/menu/electron-menu-contribution.d.ts.map +1 -1
  95. package/lib/electron-browser/menu/electron-menu-contribution.js +17 -17
  96. package/lib/electron-browser/menu/electron-menu-contribution.js.map +1 -1
  97. package/lib/electron-browser/window/electron-window-preferences.js +2 -2
  98. package/lib/electron-browser/window/electron-window-preferences.js.map +1 -1
  99. package/package.json +5 -5
  100. package/src/browser/color-registry.ts +3 -85
  101. package/src/browser/common-frontend-contribution.ts +64 -64
  102. package/src/browser/core-preferences.ts +24 -21
  103. package/src/browser/dialogs.ts +4 -4
  104. package/src/browser/keyboard/browser-keyboard-frontend-contribution.ts +2 -2
  105. package/src/browser/keyboard/browser-keyboard-layout-provider.spec.ts +10 -4
  106. package/src/browser/keyboard/keys.ts +2 -675
  107. package/src/browser/messaging/ws-connection-provider.ts +13 -4
  108. package/src/browser/quick-input/quick-command-frontend-contribution.ts +1 -1
  109. package/src/browser/quick-input/quick-command-service.ts +2 -2
  110. package/src/browser/quick-input/quick-input-service.ts +1 -278
  111. package/src/browser/shell/tab-bar-toolbar.tsx +1 -1
  112. package/src/browser/storage-service.spec.ts +1 -1
  113. package/src/browser/theming.ts +6 -17
  114. package/src/browser/window/default-window-service.ts +1 -1
  115. package/src/browser/window-contribution.ts +2 -2
  116. package/src/common/color.ts +100 -0
  117. package/src/common/command.ts +10 -0
  118. package/src/common/i18n/localization.ts +13 -3
  119. package/src/common/i18n/nls.metadata.json +20421 -0
  120. package/src/common/keys.ts +693 -0
  121. package/src/common/messaging/abstract-connection-provider.ts +3 -1
  122. package/src/common/messaging/proxy-factory.ts +1 -1
  123. package/src/common/nls.ts +74 -0
  124. package/src/common/path.spec.ts +15 -0
  125. package/src/common/path.ts +16 -4
  126. package/src/common/promise-util.ts +3 -3
  127. package/src/common/quick-pick-service.ts +299 -4
  128. package/src/common/theme.ts +32 -0
  129. package/src/electron-browser/menu/electron-menu-contribution.ts +17 -17
  130. package/src/electron-browser/window/electron-window-preferences.ts +2 -2
@@ -14,621 +14,19 @@
14
14
  *
15
15
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
16
  ********************************************************************************/
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
25
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
26
+ };
17
27
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.KeysOrKeyCodes = exports.Key = exports.SpecialCases = exports.KeyModifier = exports.KeyCode = exports.KeySequence = void 0;
19
- const os_1 = require("../../common/os");
20
- var KeySequence;
21
- (function (KeySequence) {
22
- function equals(a, b) {
23
- if (a.length !== b.length) {
24
- return false;
25
- }
26
- for (let i = 0; i < a.length; i++) {
27
- if (!a[i].equals(b[i])) {
28
- return false;
29
- }
30
- }
31
- return true;
32
- }
33
- KeySequence.equals = equals;
34
- let CompareResult;
35
- (function (CompareResult) {
36
- CompareResult[CompareResult["NONE"] = 0] = "NONE";
37
- CompareResult[CompareResult["PARTIAL"] = 1] = "PARTIAL";
38
- CompareResult[CompareResult["SHADOW"] = 2] = "SHADOW";
39
- CompareResult[CompareResult["FULL"] = 3] = "FULL";
40
- })(CompareResult = KeySequence.CompareResult || (KeySequence.CompareResult = {}));
41
- /* Compares two KeySequences, returns:
42
- * FULL if the KeySequences are the same.
43
- * PARTIAL if the KeySequence a part of b.
44
- * SHADOW if the KeySequence b part of a.
45
- * NONE if the KeySequences are not the same at all.
46
- */
47
- function compare(a, b) {
48
- let first = a;
49
- let second = b;
50
- let shadow = false;
51
- if (b.length < a.length) {
52
- first = b;
53
- second = a;
54
- shadow = true;
55
- }
56
- for (let i = 0; i < first.length; i++) {
57
- if (first[i].equals(second[i]) === false) {
58
- return KeySequence.CompareResult.NONE;
59
- }
60
- }
61
- if (first.length < second.length) {
62
- if (shadow === false) {
63
- return KeySequence.CompareResult.PARTIAL;
64
- }
65
- else {
66
- return KeySequence.CompareResult.SHADOW;
67
- }
68
- }
69
- return KeySequence.CompareResult.FULL;
70
- }
71
- KeySequence.compare = compare;
72
- function parse(keybinding) {
73
- const keyCodes = [];
74
- const rawKeyCodes = keybinding.trim().split(/\s+/g);
75
- for (const rawKeyCode of rawKeyCodes) {
76
- const keyCode = KeyCode.parse(rawKeyCode);
77
- if (keyCode !== undefined) {
78
- keyCodes.push(keyCode);
79
- }
80
- }
81
- return keyCodes;
82
- }
83
- KeySequence.parse = parse;
84
- })(KeySequence = exports.KeySequence || (exports.KeySequence = {}));
85
28
  /**
86
- * Representation of a pressed key combined with key modifiers.
29
+ * @deprecated since 1.20.0. Import from `@theia/core/lib/common/keys` instead.
87
30
  */
88
- class KeyCode {
89
- constructor(schema) {
90
- const key = schema.key;
91
- if (key) {
92
- if (key.code && key.keyCode && key.easyString) {
93
- this.key = key;
94
- }
95
- else if (key.code) {
96
- this.key = Key.getKey(key.code);
97
- }
98
- else if (key.keyCode) {
99
- this.key = Key.getKey(key.keyCode);
100
- }
101
- }
102
- this.ctrl = !!schema.ctrl;
103
- this.shift = !!schema.shift;
104
- this.alt = !!schema.alt;
105
- this.meta = !!schema.meta;
106
- this.character = schema.character;
107
- }
108
- /**
109
- * Return true if this KeyCode only contains modifiers.
110
- */
111
- isModifierOnly() {
112
- return this.key === undefined;
113
- }
114
- /**
115
- * Return true if the given KeyCode is equal to this one.
116
- */
117
- equals(other) {
118
- if (this.key && (!other.key || this.key.code !== other.key.code) || !this.key && other.key) {
119
- return false;
120
- }
121
- return this.ctrl === other.ctrl && this.alt === other.alt && this.shift === other.shift && this.meta === other.meta;
122
- }
123
- /*
124
- * Return a keybinding string compatible with the `Keybinding.keybinding` property.
125
- */
126
- toString() {
127
- const result = [];
128
- if (this.meta) {
129
- result.push(SpecialCases.META);
130
- }
131
- if (this.shift) {
132
- result.push(Key.SHIFT_LEFT.easyString);
133
- }
134
- if (this.alt) {
135
- result.push(Key.ALT_LEFT.easyString);
136
- }
137
- if (this.ctrl) {
138
- result.push(Key.CONTROL_LEFT.easyString);
139
- }
140
- if (this.key) {
141
- result.push(this.key.easyString);
142
- }
143
- return result.join('+');
144
- }
145
- /**
146
- * Create a KeyCode from one of several input types.
147
- */
148
- static createKeyCode(input, eventDispatch = 'code') {
149
- if (typeof input === 'string') {
150
- const parts = input.split('+');
151
- if (!KeyCode.isModifierString(parts[0])) {
152
- return KeyCode.createKeyCode({
153
- first: Key.getKey(parts[0]),
154
- modifiers: parts.slice(1)
155
- });
156
- }
157
- return KeyCode.createKeyCode({ modifiers: parts });
158
- }
159
- else if (KeyCode.isKeyboardEvent(input)) {
160
- const key = KeyCode.toKey(input, eventDispatch);
161
- return new KeyCode({
162
- key: Key.isModifier(key.code) ? undefined : key,
163
- meta: os_1.isOSX && input.metaKey,
164
- shift: input.shiftKey,
165
- alt: input.altKey,
166
- ctrl: input.ctrlKey,
167
- character: KeyCode.toCharacter(input)
168
- });
169
- }
170
- else if (input.first || input.modifiers) {
171
- const keystroke = input;
172
- const schema = {
173
- key: keystroke.first
174
- };
175
- if (keystroke.modifiers) {
176
- if (os_1.isOSX) {
177
- schema.meta = keystroke.modifiers.some(mod => mod === KeyModifier.CtrlCmd);
178
- schema.ctrl = keystroke.modifiers.some(mod => mod === KeyModifier.MacCtrl);
179
- }
180
- else {
181
- schema.meta = false;
182
- schema.ctrl = keystroke.modifiers.some(mod => mod === KeyModifier.CtrlCmd);
183
- }
184
- schema.shift = keystroke.modifiers.some(mod => mod === KeyModifier.Shift);
185
- schema.alt = keystroke.modifiers.some(mod => mod === KeyModifier.Alt);
186
- }
187
- return new KeyCode(schema);
188
- }
189
- else {
190
- return new KeyCode(input);
191
- }
192
- }
193
- /* Reset the key hashmap, this is for testing purposes. */
194
- static resetKeyBindings() {
195
- KeyCode.keybindings = {};
196
- }
197
- /**
198
- * Parses a string and returns a KeyCode object.
199
- * @param keybinding String representation of a keybinding
200
- */
201
- static parse(keybinding) {
202
- if (KeyCode.keybindings[keybinding]) {
203
- return KeyCode.keybindings[keybinding];
204
- }
205
- const schema = {};
206
- const keys = [];
207
- let currentKey = '';
208
- for (const character of keybinding.trim().toLowerCase()) {
209
- if (currentKey && (character === '-' || character === '+')) {
210
- keys.push(currentKey);
211
- currentKey = '';
212
- }
213
- else if (character !== '+') {
214
- currentKey += character;
215
- }
216
- }
217
- if (currentKey) {
218
- keys.push(currentKey);
219
- }
220
- /* If duplicates i.e ctrl+ctrl+a or alt+alt+b or b+alt+b it is invalid */
221
- if (keys.length !== new Set(keys).size) {
222
- throw new Error(`Can't parse keybinding ${keybinding} Duplicate modifiers`);
223
- }
224
- for (let keyString of keys) {
225
- if (SPECIAL_ALIASES[keyString] !== undefined) {
226
- keyString = SPECIAL_ALIASES[keyString];
227
- }
228
- const key = EASY_TO_KEY[keyString];
229
- /* meta only works on macOS */
230
- if (keyString === SpecialCases.META) {
231
- if (os_1.isOSX) {
232
- schema.meta = true;
233
- }
234
- else {
235
- throw new Error(`Can't parse keybinding ${keybinding} meta is for OSX only`);
236
- }
237
- /* ctrlcmd for M1 keybindings that work on both macOS and other platforms */
238
- }
239
- else if (keyString === SpecialCases.CTRLCMD) {
240
- if (os_1.isOSX) {
241
- schema.meta = true;
242
- }
243
- else {
244
- schema.ctrl = true;
245
- }
246
- }
247
- else if (Key.isKey(key)) {
248
- if (Key.isModifier(key.code)) {
249
- if (key.code === Key.CONTROL_LEFT.code || key.code === Key.CONTROL_RIGHT.code) {
250
- schema.ctrl = true;
251
- }
252
- else if (key.code === Key.SHIFT_LEFT.code || key.code === Key.SHIFT_RIGHT.code) {
253
- schema.shift = true;
254
- }
255
- else if (key.code === Key.ALT_LEFT.code || key.code === Key.ALT_RIGHT.code) {
256
- schema.alt = true;
257
- }
258
- }
259
- else {
260
- schema.key = key;
261
- }
262
- }
263
- else {
264
- throw new Error(`Unrecognized key '${keyString}' in '${keybinding}'`);
265
- }
266
- }
267
- KeyCode.keybindings[keybinding] = new KeyCode(schema);
268
- return KeyCode.keybindings[keybinding];
269
- }
270
- }
271
- exports.KeyCode = KeyCode;
272
- KeyCode.keybindings = {};
273
- (function (KeyCode) {
274
- /*
275
- * Return true if the string is a modifier M1 to M4.
276
- */
277
- function isModifierString(key) {
278
- return key === KeyModifier.CtrlCmd
279
- || key === KeyModifier.Shift
280
- || key === KeyModifier.Alt
281
- || key === KeyModifier.MacCtrl;
282
- }
283
- KeyCode.isModifierString = isModifierString;
284
- /**
285
- * Different scopes have different execution environments. This means that they have different built-ins
286
- * (different global object, different constructors, etc.). This may result in unexpected results. For instance,
287
- * `[] instanceof window.frames[0].Array` will return `false`, because `Array.prototype !== window.frames[0].Array`
288
- * and arrays inherit from the former.
289
- * See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof
290
- *
291
- * Note: just add another check if the current `event.type` checking is insufficient.
292
- */
293
- function isKeyboardEvent(event) {
294
- if (typeof KeyboardEvent === 'undefined') { // This can happen in tests
295
- return false;
296
- }
297
- if (event instanceof KeyboardEvent) {
298
- return true;
299
- }
300
- const { type } = event;
301
- if (type) {
302
- return type === 'keypress' || type === 'keydown' || type === 'keyup';
303
- }
304
- return false;
305
- }
306
- KeyCode.isKeyboardEvent = isKeyboardEvent;
307
- /**
308
- * Determine the pressed key of a keyboard event. This key should correspond to the physical key according
309
- * to a standard US keyboard layout. International keyboard layouts are handled by `KeyboardLayoutService`.
310
- *
311
- * `keyIdentifier` is used to access this deprecated field:
312
- * https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyIdentifier
313
- */
314
- function toKey(event, dispatch = 'code') {
315
- const code = event.code;
316
- if (code && dispatch === 'code') {
317
- if (os_1.isOSX) {
318
- // https://github.com/eclipse-theia/theia/issues/4986
319
- const char = event.key;
320
- if (code === 'IntlBackslash' && (char === '`' || char === '~')) {
321
- return Key.BACKQUOTE;
322
- }
323
- else if (code === 'Backquote' && (char === '§' || char === '±')) {
324
- return Key.INTL_BACKSLASH;
325
- }
326
- }
327
- // https://github.com/eclipse-theia/theia/issues/7315
328
- if (code.startsWith('Numpad') && event.key && event.key.length > 1) {
329
- const k = Key.getKey(event.key);
330
- if (k) {
331
- return k;
332
- }
333
- }
334
- const key = Key.getKey(code);
335
- if (key) {
336
- return key;
337
- }
338
- }
339
- // tslint:disable-next-line: deprecation
340
- const keyCode = event.keyCode;
341
- if (keyCode) {
342
- const key = Key.getKey(keyCode);
343
- if (key) {
344
- return key;
345
- }
346
- }
347
- const keyIdentifier = event.keyIdentifier;
348
- if (keyIdentifier) {
349
- const key = Key.getKey(keyIdentifier);
350
- if (key) {
351
- return key;
352
- }
353
- }
354
- throw new Error(`Cannot get key code from the keyboard event: ${event}.`);
355
- }
356
- KeyCode.toKey = toKey;
357
- /**
358
- * Determine the actual printable character that is generated from a pressed key.
359
- * If the key does not correspond to a printable character, `undefined` is returned.
360
- * The result may be altered by modifier keys.
361
- */
362
- function toCharacter(event) {
363
- const key = event.key;
364
- // Use the key property if it contains exactly one unicode character
365
- if (key && Array.from(key).length === 1) {
366
- return key;
367
- }
368
- const charCode = event.charCode;
369
- // Use the charCode property if it does not correspond to a unicode control character
370
- if (charCode && charCode > 0x1f && !(charCode >= 0x80 && charCode <= 0x9f)) {
371
- return String.fromCharCode(charCode);
372
- }
373
- return undefined;
374
- }
375
- KeyCode.toCharacter = toCharacter;
376
- })(KeyCode = exports.KeyCode || (exports.KeyCode = {}));
377
- var KeyModifier;
378
- (function (KeyModifier) {
379
- /**
380
- * M1 is the COMMAND key on MacOS X, and the CTRL key on most other platforms.
381
- */
382
- KeyModifier["CtrlCmd"] = "M1";
383
- /**
384
- * M2 is the SHIFT key.
385
- */
386
- KeyModifier["Shift"] = "M2";
387
- /**
388
- * M3 is the Option key on MacOS X, and the ALT key on most other platforms.
389
- */
390
- KeyModifier["Alt"] = "M3";
391
- /**
392
- * M4 is the CTRL key on MacOS X, and is undefined on other platforms.
393
- */
394
- KeyModifier["MacCtrl"] = "M4";
395
- })(KeyModifier = exports.KeyModifier || (exports.KeyModifier = {}));
396
- (function (KeyModifier) {
397
- /**
398
- * The CTRL key, independently of the platform.
399
- * _Note:_ In general `KeyModifier.CtrlCmd` should be preferred over this constant.
400
- */
401
- KeyModifier.CTRL = os_1.isOSX ? KeyModifier.MacCtrl : KeyModifier.CtrlCmd;
402
- /**
403
- * An alias for the SHIFT key (`KeyModifier.Shift`).
404
- */
405
- KeyModifier.SHIFT = KeyModifier.Shift;
406
- /**
407
- * `true` if the argument represents a modifier. Otherwise, `false`.
408
- */
409
- function isModifier(key) {
410
- if (key) {
411
- switch (key) {
412
- case 'M1': // Fall through.
413
- case 'M2': // Fall through.
414
- case 'M3': // Fall through.
415
- case 'M4': return true;
416
- default: return false;
417
- }
418
- }
419
- return false;
420
- }
421
- KeyModifier.isModifier = isModifier;
422
- })(KeyModifier = exports.KeyModifier || (exports.KeyModifier = {}));
423
- const CODE_TO_KEY = {};
424
- const KEY_CODE_TO_KEY = {};
425
- const EASY_TO_KEY = {}; // From 'ctrl' to Key structure
426
- const MODIFIERS = [];
427
- const SPECIAL_ALIASES = {
428
- 'option': 'alt',
429
- 'command': 'meta',
430
- 'cmd': 'meta',
431
- 'return': 'enter',
432
- 'esc': 'escape',
433
- 'mod': 'ctrl',
434
- 'ins': 'insert',
435
- 'del': 'delete',
436
- 'control': 'ctrl',
437
- };
438
- var SpecialCases;
439
- (function (SpecialCases) {
440
- SpecialCases.META = 'meta';
441
- SpecialCases.CTRLCMD = 'ctrlcmd';
442
- })(SpecialCases = exports.SpecialCases || (exports.SpecialCases = {}));
443
- var Key;
444
- (function (Key) {
445
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
446
- function isKey(arg) {
447
- return typeof arg === 'object' && ('code' in arg) && ('keyCode' in arg);
448
- }
449
- Key.isKey = isKey;
450
- function getKey(arg) {
451
- if (typeof arg === 'number') {
452
- return KEY_CODE_TO_KEY[arg];
453
- }
454
- else {
455
- return CODE_TO_KEY[arg];
456
- }
457
- }
458
- Key.getKey = getKey;
459
- function isModifier(arg) {
460
- if (typeof arg === 'number') {
461
- return MODIFIERS.find(key => key.keyCode === arg) !== undefined;
462
- }
463
- return MODIFIERS.find(key => key.code === arg) !== undefined;
464
- }
465
- Key.isModifier = isModifier;
466
- function equals(key, keyCode) {
467
- return !!keyCode.key && key.keyCode === keyCode.key.keyCode;
468
- }
469
- Key.equals = equals;
470
- Key.BACKSPACE = { code: 'Backspace', keyCode: 8, easyString: 'backspace' };
471
- Key.TAB = { code: 'Tab', keyCode: 9, easyString: 'tab' };
472
- Key.ENTER = { code: 'Enter', keyCode: 13, easyString: 'enter' };
473
- Key.ESCAPE = { code: 'Escape', keyCode: 27, easyString: 'escape' };
474
- Key.SPACE = { code: 'Space', keyCode: 32, easyString: 'space' };
475
- Key.PAGE_UP = { code: 'PageUp', keyCode: 33, easyString: 'pageup' };
476
- Key.PAGE_DOWN = { code: 'PageDown', keyCode: 34, easyString: 'pagedown' };
477
- Key.END = { code: 'End', keyCode: 35, easyString: 'end' };
478
- Key.HOME = { code: 'Home', keyCode: 36, easyString: 'home' };
479
- Key.ARROW_LEFT = { code: 'ArrowLeft', keyCode: 37, easyString: 'left' };
480
- Key.ARROW_UP = { code: 'ArrowUp', keyCode: 38, easyString: 'up' };
481
- Key.ARROW_RIGHT = { code: 'ArrowRight', keyCode: 39, easyString: 'right' };
482
- Key.ARROW_DOWN = { code: 'ArrowDown', keyCode: 40, easyString: 'down' };
483
- Key.INSERT = { code: 'Insert', keyCode: 45, easyString: 'insert' };
484
- Key.DELETE = { code: 'Delete', keyCode: 46, easyString: 'delete' };
485
- Key.SHIFT_LEFT = { code: 'ShiftLeft', keyCode: 16, easyString: 'shift' };
486
- Key.SHIFT_RIGHT = { code: 'ShiftRight', keyCode: 16, easyString: 'shift' };
487
- Key.CONTROL_LEFT = { code: 'ControlLeft', keyCode: 17, easyString: 'ctrl' };
488
- Key.CONTROL_RIGHT = { code: 'ControlRight', keyCode: 17, easyString: 'ctrl' };
489
- Key.ALT_LEFT = { code: 'AltLeft', keyCode: 18, easyString: 'alt' };
490
- Key.ALT_RIGHT = { code: 'AltRight', keyCode: 18, easyString: 'alt' };
491
- Key.CAPS_LOCK = { code: 'CapsLock', keyCode: 20, easyString: 'capslock' };
492
- Key.OS_LEFT = { code: 'OSLeft', keyCode: 91, easyString: 'super' };
493
- Key.OS_RIGHT = { code: 'OSRight', keyCode: 92, easyString: 'super' };
494
- Key.DIGIT0 = { code: 'Digit0', keyCode: 48, easyString: '0' };
495
- Key.DIGIT1 = { code: 'Digit1', keyCode: 49, easyString: '1' };
496
- Key.DIGIT2 = { code: 'Digit2', keyCode: 50, easyString: '2' };
497
- Key.DIGIT3 = { code: 'Digit3', keyCode: 51, easyString: '3' };
498
- Key.DIGIT4 = { code: 'Digit4', keyCode: 52, easyString: '4' };
499
- Key.DIGIT5 = { code: 'Digit5', keyCode: 53, easyString: '5' };
500
- Key.DIGIT6 = { code: 'Digit6', keyCode: 54, easyString: '6' };
501
- Key.DIGIT7 = { code: 'Digit7', keyCode: 55, easyString: '7' };
502
- Key.DIGIT8 = { code: 'Digit8', keyCode: 56, easyString: '8' };
503
- Key.DIGIT9 = { code: 'Digit9', keyCode: 57, easyString: '9' };
504
- Key.KEY_A = { code: 'KeyA', keyCode: 65, easyString: 'a' };
505
- Key.KEY_B = { code: 'KeyB', keyCode: 66, easyString: 'b' };
506
- Key.KEY_C = { code: 'KeyC', keyCode: 67, easyString: 'c' };
507
- Key.KEY_D = { code: 'KeyD', keyCode: 68, easyString: 'd' };
508
- Key.KEY_E = { code: 'KeyE', keyCode: 69, easyString: 'e' };
509
- Key.KEY_F = { code: 'KeyF', keyCode: 70, easyString: 'f' };
510
- Key.KEY_G = { code: 'KeyG', keyCode: 71, easyString: 'g' };
511
- Key.KEY_H = { code: 'KeyH', keyCode: 72, easyString: 'h' };
512
- Key.KEY_I = { code: 'KeyI', keyCode: 73, easyString: 'i' };
513
- Key.KEY_J = { code: 'KeyJ', keyCode: 74, easyString: 'j' };
514
- Key.KEY_K = { code: 'KeyK', keyCode: 75, easyString: 'k' };
515
- Key.KEY_L = { code: 'KeyL', keyCode: 76, easyString: 'l' };
516
- Key.KEY_M = { code: 'KeyM', keyCode: 77, easyString: 'm' };
517
- Key.KEY_N = { code: 'KeyN', keyCode: 78, easyString: 'n' };
518
- Key.KEY_O = { code: 'KeyO', keyCode: 79, easyString: 'o' };
519
- Key.KEY_P = { code: 'KeyP', keyCode: 80, easyString: 'p' };
520
- Key.KEY_Q = { code: 'KeyQ', keyCode: 81, easyString: 'q' };
521
- Key.KEY_R = { code: 'KeyR', keyCode: 82, easyString: 'r' };
522
- Key.KEY_S = { code: 'KeyS', keyCode: 83, easyString: 's' };
523
- Key.KEY_T = { code: 'KeyT', keyCode: 84, easyString: 't' };
524
- Key.KEY_U = { code: 'KeyU', keyCode: 85, easyString: 'u' };
525
- Key.KEY_V = { code: 'KeyV', keyCode: 86, easyString: 'v' };
526
- Key.KEY_W = { code: 'KeyW', keyCode: 87, easyString: 'w' };
527
- Key.KEY_X = { code: 'KeyX', keyCode: 88, easyString: 'x' };
528
- Key.KEY_Y = { code: 'KeyY', keyCode: 89, easyString: 'y' };
529
- Key.KEY_Z = { code: 'KeyZ', keyCode: 90, easyString: 'z' };
530
- Key.MULTIPLY = { code: 'NumpadMultiply', keyCode: 106, easyString: 'multiply' };
531
- Key.ADD = { code: 'NumpadAdd', keyCode: 107, easyString: 'add' };
532
- Key.DECIMAL = { code: 'NumpadDecimal', keyCode: 108, easyString: 'decimal' };
533
- Key.SUBTRACT = { code: 'NumpadSubtract', keyCode: 109, easyString: 'subtract' };
534
- Key.DIVIDE = { code: 'NumpadDivide', keyCode: 111, easyString: 'divide' };
535
- Key.F1 = { code: 'F1', keyCode: 112, easyString: 'f1' };
536
- Key.F2 = { code: 'F2', keyCode: 113, easyString: 'f2' };
537
- Key.F3 = { code: 'F3', keyCode: 114, easyString: 'f3' };
538
- Key.F4 = { code: 'F4', keyCode: 115, easyString: 'f4' };
539
- Key.F5 = { code: 'F5', keyCode: 116, easyString: 'f5' };
540
- Key.F6 = { code: 'F6', keyCode: 117, easyString: 'f6' };
541
- Key.F7 = { code: 'F7', keyCode: 118, easyString: 'f7' };
542
- Key.F8 = { code: 'F8', keyCode: 119, easyString: 'f8' };
543
- Key.F9 = { code: 'F9', keyCode: 120, easyString: 'f9' };
544
- Key.F10 = { code: 'F10', keyCode: 121, easyString: 'f10' };
545
- Key.F11 = { code: 'F11', keyCode: 122, easyString: 'f11' };
546
- Key.F12 = { code: 'F12', keyCode: 123, easyString: 'f12' };
547
- Key.F13 = { code: 'F13', keyCode: 124, easyString: 'f13' };
548
- Key.F14 = { code: 'F14', keyCode: 125, easyString: 'f14' };
549
- Key.F15 = { code: 'F15', keyCode: 126, easyString: 'f15' };
550
- Key.F16 = { code: 'F16', keyCode: 127, easyString: 'f16' };
551
- Key.F17 = { code: 'F17', keyCode: 128, easyString: 'f17' };
552
- Key.F18 = { code: 'F18', keyCode: 129, easyString: 'f18' };
553
- Key.F19 = { code: 'F19', keyCode: 130, easyString: 'f19' };
554
- Key.F20 = { code: 'F20', keyCode: 131, easyString: 'f20' };
555
- Key.F21 = { code: 'F21', keyCode: 132, easyString: 'f21' };
556
- Key.F22 = { code: 'F22', keyCode: 133, easyString: 'f22' };
557
- Key.F23 = { code: 'F23', keyCode: 134, easyString: 'f23' };
558
- Key.F24 = { code: 'F24', keyCode: 135, easyString: 'f24' };
559
- Key.NUM_LOCK = { code: 'NumLock', keyCode: 144, easyString: 'numlock' };
560
- Key.SEMICOLON = { code: 'Semicolon', keyCode: 186, easyString: ';' };
561
- Key.EQUAL = { code: 'Equal', keyCode: 187, easyString: '=' };
562
- Key.COMMA = { code: 'Comma', keyCode: 188, easyString: ',' };
563
- Key.MINUS = { code: 'Minus', keyCode: 189, easyString: '-' };
564
- Key.PERIOD = { code: 'Period', keyCode: 190, easyString: '.' };
565
- Key.SLASH = { code: 'Slash', keyCode: 191, easyString: '/' };
566
- Key.BACKQUOTE = { code: 'Backquote', keyCode: 192, easyString: '`' };
567
- Key.INTL_RO = { code: 'IntlRo', keyCode: 193, easyString: 'intlro' };
568
- Key.BRACKET_LEFT = { code: 'BracketLeft', keyCode: 219, easyString: '[' };
569
- Key.BACKSLASH = { code: 'Backslash', keyCode: 220, easyString: '\\' };
570
- Key.BRACKET_RIGHT = { code: 'BracketRight', keyCode: 221, easyString: ']' };
571
- Key.QUOTE = { code: 'Quote', keyCode: 222, easyString: '\'' };
572
- Key.INTL_BACKSLASH = { code: 'IntlBackslash', keyCode: 229, easyString: 'intlbackslash' };
573
- Key.INTL_YEN = { code: 'IntlYen', keyCode: 255, easyString: 'intlyen' };
574
- Key.MAX_KEY_CODE = Key.INTL_YEN.keyCode;
575
- })(Key = exports.Key || (exports.Key = {}));
576
- /* -------------------- Initialize the static key mappings -------------------- */
577
- (() => {
578
- // Set the default key mappings from the constants in the Key namespace
579
- Object.keys(Key).map(prop => Reflect.get(Key, prop)).filter(key => Key.isKey(key)).forEach(key => {
580
- CODE_TO_KEY[key.code] = key;
581
- KEY_CODE_TO_KEY[key.keyCode] = key;
582
- EASY_TO_KEY[key.easyString] = key;
583
- });
584
- // Set additional key mappings
585
- CODE_TO_KEY['Numpad0'] = Key.DIGIT0;
586
- KEY_CODE_TO_KEY[96] = Key.DIGIT0;
587
- CODE_TO_KEY['Numpad1'] = Key.DIGIT1;
588
- KEY_CODE_TO_KEY[97] = Key.DIGIT1;
589
- CODE_TO_KEY['Numpad2'] = Key.DIGIT2;
590
- KEY_CODE_TO_KEY[98] = Key.DIGIT2;
591
- CODE_TO_KEY['Numpad3'] = Key.DIGIT3;
592
- KEY_CODE_TO_KEY[99] = Key.DIGIT3;
593
- CODE_TO_KEY['Numpad4'] = Key.DIGIT4;
594
- KEY_CODE_TO_KEY[100] = Key.DIGIT4;
595
- CODE_TO_KEY['Numpad5'] = Key.DIGIT5;
596
- KEY_CODE_TO_KEY[101] = Key.DIGIT5;
597
- CODE_TO_KEY['Numpad6'] = Key.DIGIT6;
598
- KEY_CODE_TO_KEY[102] = Key.DIGIT6;
599
- CODE_TO_KEY['Numpad7'] = Key.DIGIT7;
600
- KEY_CODE_TO_KEY[103] = Key.DIGIT7;
601
- CODE_TO_KEY['Numpad8'] = Key.DIGIT8;
602
- KEY_CODE_TO_KEY[104] = Key.DIGIT8;
603
- CODE_TO_KEY['Numpad9'] = Key.DIGIT9;
604
- KEY_CODE_TO_KEY[105] = Key.DIGIT9;
605
- CODE_TO_KEY['NumpadEnter'] = Key.ENTER;
606
- CODE_TO_KEY['NumpadEqual'] = Key.EQUAL;
607
- CODE_TO_KEY['MetaLeft'] = Key.OS_LEFT; // Chrome, Safari
608
- KEY_CODE_TO_KEY[224] = Key.OS_LEFT; // Firefox on Mac
609
- CODE_TO_KEY['MetaRight'] = Key.OS_RIGHT; // Chrome, Safari
610
- KEY_CODE_TO_KEY[93] = Key.OS_RIGHT; // Chrome, Safari, Edge
611
- KEY_CODE_TO_KEY[225] = Key.ALT_RIGHT; // Linux
612
- KEY_CODE_TO_KEY[110] = Key.DECIMAL; // Mac, Windows
613
- KEY_CODE_TO_KEY[59] = Key.SEMICOLON; // Firefox
614
- KEY_CODE_TO_KEY[61] = Key.EQUAL; // Firefox
615
- KEY_CODE_TO_KEY[173] = Key.MINUS; // Firefox
616
- KEY_CODE_TO_KEY[226] = Key.BACKSLASH; // Chrome, Edge on Windows
617
- KEY_CODE_TO_KEY[60] = Key.BACKSLASH; // Firefox on Linux
618
- // Set the modifier keys
619
- MODIFIERS.push(...[Key.ALT_LEFT, Key.ALT_RIGHT, Key.CONTROL_LEFT, Key.CONTROL_RIGHT, Key.OS_LEFT, Key.OS_RIGHT, Key.SHIFT_LEFT, Key.SHIFT_RIGHT]);
620
- })();
621
- var KeysOrKeyCodes;
622
- (function (KeysOrKeyCodes) {
623
- KeysOrKeyCodes.toKeyCode = (keyOrKeyCode) => keyOrKeyCode instanceof KeyCode ? keyOrKeyCode : KeyCode.createKeyCode({ first: keyOrKeyCode });
624
- KeysOrKeyCodes.toKeyCodes = (keysOrKeyCodes) => {
625
- if (keysOrKeyCodes instanceof KeyCode) {
626
- return [keysOrKeyCodes];
627
- }
628
- else if (Array.isArray(keysOrKeyCodes)) {
629
- return keysOrKeyCodes.slice().map(KeysOrKeyCodes.toKeyCode);
630
- }
631
- return [KeysOrKeyCodes.toKeyCode(keysOrKeyCodes)];
632
- };
633
- })(KeysOrKeyCodes = exports.KeysOrKeyCodes || (exports.KeysOrKeyCodes = {}));
31
+ __exportStar(require("../../common/keys"), exports);
634
32
  //# sourceMappingURL=keys.js.map