forked from ai/keyux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (35 loc) · 1.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
export * from './focus-group.js'
export * from './hotkey.js'
export * from './hidden.js'
export * from './press.js'
export * from './jump.js'
export * from './overrides.js'
export function startKeyUX(window, plugins) {
let unbinds = plugins.map(plugin => plugin(window))
return () => {
unbinds.forEach(unbind => unbind())
}
}
export function likelyWithKeyboard(window = globalThis) {
let agent = window.navigator.userAgent.toLowerCase()
return !['iphone', 'ipad', 'android'].some(device => agent.includes(device))
}
export function getHotKeyHint(window, code, transformers = []) {
let realCode = code
for (let transformer of transformers) {
realCode = transformer[1](realCode, window, 'r')
}
let prettyParts = realCode
.split('+')
.map(part => part[0].toUpperCase() + part.slice(1))
if (window.navigator.platform.indexOf('Mac') === 0) {
return prettyParts
.join('')
.replace(/(.*)Meta(.*)/, '⌘ $1$2')
.replace(/(.*)Shift(.*)/, '⇧ $1$2')
.replace(/(.*)Alt(.*)/, '⌥ $1$2')
.replace(/(.*)Ctrl(.*)/, '⌃ $1$2')
} else {
return prettyParts.join(' + ')
}
}