1
0
web/static/pkg/hotkeys-js/dist/hotkeys.common.min.js

2 lines
8.7 KiB
JavaScript
Raw Normal View History

2024-04-05 15:01:17 +00:00
/*! hotkeys-js v3.13.7 | MIT © 2024 kenny wong <wowohoo@qq.com> https://jaywcjlove.github.io/hotkeys-js */
"use strict";const isff="undefined"!=typeof navigator&&0<navigator.userAgent.toLowerCase().indexOf("firefox");function addEvent(e,t,n,o){e.addEventListener?e.addEventListener(t,n,o):e.attachEvent&&e.attachEvent("on".concat(t),n)}function removeEvent(e,t,n,o){e.removeEventListener?e.removeEventListener(t,n,o):e.detachEvent&&e.detachEvent("on".concat(t),n)}function getMods(t,e){var n=e.slice(0,e.length-1);for(let e=0;e<n.length;e++)n[e]=t[n[e].toLowerCase()];return n}function getKeys(e){var t=(e=(e="string"!=typeof e?"":e).replace(/\s/g,"")).split(",");let n=t.lastIndexOf("");for(;0<=n;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function compareArray(e,t){var n=e.length<t.length?t:e,o=e.length<t.length?e:t;let s=!0;for(let e=0;e<n.length;e++)~o.indexOf(n[e])||(s=!1);return s}const _keyMap={backspace:8,"\u232b":8,tab:9,clear:12,enter:13,"\u21a9":13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,capslock:20,num_0:96,num_1:97,num_2:98,num_3:99,num_4:100,num_5:101,num_6:102,num_7:103,num_8:104,num_9:105,num_multiply:106,num_add:107,num_enter:108,num_subtract:109,num_decimal:110,num_divide:111,"\u21ea":20,",":188,".":190,"/":191,"`":192,"-":isff?173:189,"=":isff?61:187,";":isff?59:186,"'":222,"[":219,"]":221,"\\":220},_modifier={"\u21e7":16,shift:16,"\u2325":18,alt:18,option:18,"\u2303":17,ctrl:17,control:17,"\u2318":91,cmd:91,command:91},modifierMap={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},_mods={16:!1,18:!1,17:!1,91:!1},_handlers={};for(let e=1;e<20;e++)_keyMap["f".concat(e)]=111+e;let _downKeys=[],winListendFocus=null,_scope="all";const elementEventMap=new Map,code=e=>_keyMap[e.toLowerCase()]||_modifier[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),getKey=t=>Object.keys(_keyMap).find(e=>_keyMap[e]===t),getModifier=t=>Object.keys(_modifier).find(e=>_modifier[e]===t);function setScope(e){_scope=e||"all"}function getScope(){return _scope||"all"}function getPressedKeyCodes(){return _downKeys.slice(0)}function getPressedKeyString(){return _downKeys.map(e=>getKey(e)||getModifier(e)||String.fromCharCode(e))}function getAllKeyCodes(){const s=[];return Object.keys(_handlers).forEach(e=>{_handlers[e].forEach(e=>{var{key:e,scope:t,mods:n,shortcut:o}=e;s.push({scope:t,shortcut:o,mods:n,keys:e.split("+").map(e=>code(e))})})}),s}function filter(e){var e=e.target||e.srcElement,t=e["tagName"];let n=!0;var o="INPUT"===t&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(e.type);return n=!e.isContentEditable&&(!o&&"TEXTAREA"!==t&&"SELECT"!==t||e.readOnly)?n:!1}function isPressed(e){return"string"==typeof e&&(e=code(e)),!!~_downKeys.indexOf(e)}function deleteScope(e,t){var n;let o;e=e||getScope();for(const s in _handlers)if(Object.prototype.hasOwnProperty.call(_handlers,s))for(n=_handlers[s],o=0;o<n.length;)n[o].scope===e?n.splice(o,1).forEach(e=>{e=e.element;return removeKeyEvent(e)}):o++;getScope()===e&&setScope(t||"all")}function clearModifier(e){let t=e.keyCode||e.which||e.charCode;var n=_downKeys.indexOf(t);if(n<0||_downKeys.splice(n,1),e.key&&"meta"==e.key.toLowerCase()&&_downKeys.splice(0,_downKeys.length),(t=93!==t&&224!==t?t:91)in _mods){_mods[t]=!1;for(const o in _modifier)_modifier[o]===t&&(hotkeys[o]=!1)}}function unbind(n){if(void 0===n)Object.keys(_handlers).forEach(e=>{Array.isArray(_handlers[e])&&_handlers[e].forEach(e=>eachUnbind(e)),delete _handlers[e]}),removeKeyEvent(null);else if(Array.isArray(n))n.forEach(e=>{e.key&&eachUnbind(e)});else if("object"==typeof n)n.key&&eachUnbind(n);else if("string"==typeof n){for(var o=arguments.length,s=Array(1<o?o-1:0),r=1;r<o;r++)s[r-1]=arguments[r];let[e,t]=s;"function"==typeof e&&(t=e,e=""),eachUnbind({key:n,scope:e,method:t,splitKey:"+"})}}const eachUnbind=e=>{let{key:t,scope:r,method:i,splitKey:d="+"}=e;getKeys(t).forEach(e=>{var e=e.split(d),t=e.length,n=e[t-1],n="*"===n?"*":code(n);if(_handlers[n]){r=r||getScope();const o=1<t?getMods(_modifier,e):[],s=[];_handlers[n]=_handlers[n].filter(e=>{va