@guruhotel/aura-hooks
Version:
🪝 Hooks library designed by the Guruhotel team for Aura UI
1 lines • 838 B
JavaScript
function e(e){const t=e.toLowerCase().split("+").map((e=>e.trim())),r={alt:t.includes("alt"),ctrl:t.includes("ctrl"),meta:t.includes("meta"),mod:t.includes("mod"),shift:t.includes("shift")},n=["alt","ctrl","meta","shift","mod"];return{...r,key:t.find((e=>!n.includes(e)))}}function t(t){return r=>function(e,t){const{alt:r,ctrl:n,meta:o,mod:s,shift:i,key:a}=e,{altKey:c,ctrlKey:l,metaKey:u,shiftKey:f,key:d}=t;if(r!==c)return!1;if(s){if(!l&&!u)return!1}else{if(n!==l)return!1;if(o!==u)return!1}return i===f&&!(!a||d.toLowerCase()!==a.toLowerCase()&&t.code.replace("Key","").toLowerCase()!==a.toLowerCase())}(e(t),r)}exports.__esModule=!0,exports.getHotkeyHandler=function(e){return r=>{const n="nativeEvent"in r?r.nativeEvent:r;e.forEach((([e,o])=>{t(e)(n)&&(r.preventDefault(),o(n))}))}},exports.getHotkeyMatcher=t,exports.parseHotkey=e;