1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.shortcutToHumanString = exports.shortcutMatchesShortcut = exports.optionOrAltSymbol = exports.keyToSymbol = exports.isShortcutTaken = exports.isMacLike = exports.eventToShortcut = exports.eventMatchesShortcut = exports.controlOrMetaSymbol = exports.controlOrMetaKey = void 0;
|
7 |
|
8 | require("core-js/modules/es.regexp.exec.js");
|
9 |
|
10 | require("core-js/modules/es.string.match.js");
|
11 |
|
12 | require("core-js/modules/es.array.includes.js");
|
13 |
|
14 | require("core-js/modules/es.array.join.js");
|
15 |
|
16 | require("core-js/modules/es.array.find.js");
|
17 |
|
18 | require("core-js/modules/es.object.to-string.js");
|
19 |
|
20 | require("core-js/modules/es.array.map.js");
|
21 |
|
22 | var _global = _interopRequireDefault(require("global"));
|
23 |
|
24 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
25 |
|
26 | var navigator = _global.default.navigator;
|
27 |
|
28 | var isMacLike = function isMacLike() {
|
29 | return navigator && navigator.platform ? !!navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i) : false;
|
30 | };
|
31 |
|
32 | exports.isMacLike = isMacLike;
|
33 |
|
34 | var controlOrMetaSymbol = function controlOrMetaSymbol() {
|
35 | return isMacLike() ? '⌘' : 'ctrl';
|
36 | };
|
37 |
|
38 | exports.controlOrMetaSymbol = controlOrMetaSymbol;
|
39 |
|
40 | var controlOrMetaKey = function controlOrMetaKey() {
|
41 | return isMacLike() ? 'meta' : 'control';
|
42 | };
|
43 |
|
44 | exports.controlOrMetaKey = controlOrMetaKey;
|
45 |
|
46 | var optionOrAltSymbol = function optionOrAltSymbol() {
|
47 | return isMacLike() ? '⌥' : 'alt';
|
48 | };
|
49 |
|
50 | exports.optionOrAltSymbol = optionOrAltSymbol;
|
51 |
|
52 | var isShortcutTaken = function isShortcutTaken(arr1, arr2) {
|
53 | return JSON.stringify(arr1) === JSON.stringify(arr2);
|
54 | };
|
55 |
|
56 |
|
57 |
|
58 | exports.isShortcutTaken = isShortcutTaken;
|
59 |
|
60 | var eventToShortcut = function eventToShortcut(e) {
|
61 |
|
62 | if (['Meta', 'Alt', 'Control', 'Shift'].includes(e.key)) {
|
63 | return null;
|
64 | }
|
65 |
|
66 | var keys = [];
|
67 |
|
68 | if (e.altKey) {
|
69 | keys.push('alt');
|
70 | }
|
71 |
|
72 | if (e.ctrlKey) {
|
73 | keys.push('control');
|
74 | }
|
75 |
|
76 | if (e.metaKey) {
|
77 | keys.push('meta');
|
78 | }
|
79 |
|
80 | if (e.shiftKey) {
|
81 | keys.push('shift');
|
82 | }
|
83 |
|
84 | if (e.key && e.key.length === 1 && e.key !== ' ') {
|
85 | keys.push(e.key.toUpperCase());
|
86 | }
|
87 |
|
88 | if (e.key === ' ') {
|
89 | keys.push('space');
|
90 | }
|
91 |
|
92 | if (e.key === 'Escape') {
|
93 | keys.push('escape');
|
94 | }
|
95 |
|
96 | if (e.key === 'ArrowRight') {
|
97 | keys.push('ArrowRight');
|
98 | }
|
99 |
|
100 | if (e.key === 'ArrowDown') {
|
101 | keys.push('ArrowDown');
|
102 | }
|
103 |
|
104 | if (e.key === 'ArrowUp') {
|
105 | keys.push('ArrowUp');
|
106 | }
|
107 |
|
108 | if (e.key === 'ArrowLeft') {
|
109 | keys.push('ArrowLeft');
|
110 | }
|
111 |
|
112 | return keys.length > 0 ? keys : null;
|
113 | };
|
114 |
|
115 | exports.eventToShortcut = eventToShortcut;
|
116 |
|
117 | var shortcutMatchesShortcut = function shortcutMatchesShortcut(inputShortcut, shortcut) {
|
118 | if (!inputShortcut || !shortcut) return false;
|
119 | if (inputShortcut.join('') === 'shift/') inputShortcut.shift();
|
120 |
|
121 | if (inputShortcut.length !== shortcut.length) return false;
|
122 | return !inputShortcut.find(function (key, i) {
|
123 | return key !== shortcut[i];
|
124 | });
|
125 | };
|
126 |
|
127 |
|
128 | exports.shortcutMatchesShortcut = shortcutMatchesShortcut;
|
129 |
|
130 | var eventMatchesShortcut = function eventMatchesShortcut(e, shortcut) {
|
131 | return shortcutMatchesShortcut(eventToShortcut(e), shortcut);
|
132 | };
|
133 |
|
134 | exports.eventMatchesShortcut = eventMatchesShortcut;
|
135 |
|
136 | var keyToSymbol = function keyToSymbol(key) {
|
137 | if (key === 'alt') {
|
138 | return optionOrAltSymbol();
|
139 | }
|
140 |
|
141 | if (key === 'control') {
|
142 | return '⌃';
|
143 | }
|
144 |
|
145 | if (key === 'meta') {
|
146 | return '⌘';
|
147 | }
|
148 |
|
149 | if (key === 'shift') {
|
150 | return '⇧';
|
151 | }
|
152 |
|
153 | if (key === 'Enter' || key === 'Backspace' || key === 'Esc') {
|
154 | return '';
|
155 | }
|
156 |
|
157 | if (key === 'escape') {
|
158 | return '';
|
159 | }
|
160 |
|
161 | if (key === ' ') {
|
162 | return 'SPACE';
|
163 | }
|
164 |
|
165 | if (key === 'ArrowUp') {
|
166 | return '↑';
|
167 | }
|
168 |
|
169 | if (key === 'ArrowDown') {
|
170 | return '↓';
|
171 | }
|
172 |
|
173 | if (key === 'ArrowLeft') {
|
174 | return '←';
|
175 | }
|
176 |
|
177 | if (key === 'ArrowRight') {
|
178 | return '→';
|
179 | }
|
180 |
|
181 | return key.toUpperCase();
|
182 | };
|
183 |
|
184 |
|
185 | exports.keyToSymbol = keyToSymbol;
|
186 |
|
187 | var shortcutToHumanString = function shortcutToHumanString(shortcut) {
|
188 | return shortcut.map(keyToSymbol).join(' ');
|
189 | };
|
190 |
|
191 | exports.shortcutToHumanString = shortcutToHumanString; |
\ | No newline at end of file |