@xiee/utils 1.2.7 → 1.2.8
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/css/key-buttons.css +1 -0
- package/js/key-buttons.js +10 -4
- package/package.json +1 -1
package/css/key-buttons.css
CHANGED
package/js/key-buttons.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
(function(d) {
|
|
2
|
+
const a1 = ['Enter', 'Up', 'Down', 'Left', 'Right'];
|
|
3
|
+
const a2 = ['↵', '↑', '↓', '←', '→'];
|
|
4
|
+
function drawArrows(x) {
|
|
5
|
+
a1.map((v, i) => x = x.replace(new RegExp('>' + v + '<', 'g'), ' title="' + v + (i ? ' Arrow' : '') + '">' + a2[i] + '<'));
|
|
6
|
+
return x;
|
|
7
|
+
}
|
|
2
8
|
// 1. individual keys; 2. modifiers; 3. normal keys
|
|
3
|
-
const k1 = 'Esc|Tab|
|
|
4
|
-
Array(12).fill().map((v, i) => 'F' + (i + 1)).join('|'),
|
|
9
|
+
const k1 = 'Esc|Tab|PageUp|PageDown|Space|Delete|Home|End|PrtScr?|PrintScreen|' +
|
|
10
|
+
Array(12).fill().map((v, i) => 'F' + (i + 1)).concat(a1).join('|'),
|
|
5
11
|
k2 = 'Ctrl|Control|Shift|Alt|Cmd|Command|fn',
|
|
6
12
|
k3 = '[a-zA-Z0-9]|Click',
|
|
7
13
|
r1 = new RegExp('^(' + k1 + '|' + k2 + ')$'),
|
|
@@ -11,7 +17,7 @@
|
|
|
11
17
|
if (el.childElementCount > 0) return;
|
|
12
18
|
let t = el.innerText;
|
|
13
19
|
if (r1.test(t)) {
|
|
14
|
-
el.outerHTML = '<kbd>' + t + '</kbd>';
|
|
20
|
+
el.outerHTML = drawArrows('<kbd>' + t + '</kbd>');
|
|
15
21
|
return;
|
|
16
22
|
}
|
|
17
23
|
if (!r2.test(t)) return;
|
|
@@ -20,6 +26,6 @@
|
|
|
20
26
|
t2 += t.replace(r3, '<kbd>$1</kbd>$2');
|
|
21
27
|
t = t.replace(r3, '$3');
|
|
22
28
|
}
|
|
23
|
-
if (t === '') el.outerHTML = t2.replace(/ \+ $/, '');
|
|
29
|
+
if (t === '') el.outerHTML = drawArrows(t2.replace(/ \+ $/, ''));
|
|
24
30
|
});
|
|
25
31
|
})(document);
|