hotkeys-js
Advanced tools
Comparing version 3.9.5 to 3.10.0
/**! | ||
* hotkeys-js v3.9.5 | ||
* hotkeys-js v3.10.0 | ||
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies. | ||
@@ -170,2 +170,14 @@ * | ||
return _keyMap[x.toLowerCase()] || _modifier[x.toLowerCase()] || x.toUpperCase().charCodeAt(0); | ||
}; | ||
var getKey = function getKey(x) { | ||
return Object.keys(_keyMap).find(function (k) { | ||
return _keyMap[k] === x; | ||
}); | ||
}; | ||
var getModifier = function getModifier(x) { | ||
return Object.keys(_modifier).find(function (k) { | ||
return _modifier[k] === x; | ||
}); | ||
}; // 设置获取当前范围(默认为'所有') | ||
@@ -186,2 +198,8 @@ | ||
return _downKeys.slice(0); | ||
} | ||
function getPressedKeyString() { | ||
return _downKeys.map(function (c) { | ||
return getKey(c) || getModifier(c) || String.fromCharCode(c); | ||
}); | ||
} // 表单控件控件判断 返回 Boolean | ||
@@ -571,2 +589,3 @@ // hotkey is effective only when filter return true | ||
var _api = { | ||
getPressedKeyString: getPressedKeyString, | ||
setScope: setScope, | ||
@@ -573,0 +592,0 @@ getScope: getScope, |
@@ -1,2 +0,2 @@ | ||
/*! hotkeys-js v3.9.5 | MIT © 2022 kenny wong <wowohoo@qq.com> http://jaywcjlove.github.io/hotkeys */ | ||
"use strict";var isff="undefined"!=typeof navigator&&0<navigator.userAgent.toLowerCase().indexOf("firefox");function addEvent(e,n,t,o){e.addEventListener?e.addEventListener(n,t,o):e.attachEvent&&e.attachEvent("on".concat(n),function(){t(window.event)})}function getMods(e,n){for(var t=n.slice(0,n.length-1),o=0;o<t.length;o++)t[o]=e[t[o].toLowerCase()];return t}function getKeys(e){for(var n=(e=(e="string"!=typeof e?"":e).replace(/\s/g,"")).split(","),t=n.lastIndexOf("");0<=t;)n[t-1]+=",",n.splice(t,1),t=n.lastIndexOf("");return n}function compareArray(e,n){for(var t=e.length<n.length?n:e,o=e.length<n.length?e:n,s=!0,i=0;i<t.length;i++)~o.indexOf(t[i])||(s=!1);return s}for(var _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={},k=1;k<20;k++)_keyMap["f".concat(k)]=111+k;var _downKeys=[],winListendFocus=!1,_scope="all",elementHasBindEvent=[],code=function(e){return _keyMap[e.toLowerCase()]||_modifier[e.toLowerCase()]||e.toUpperCase().charCodeAt(0)};function setScope(e){_scope=e||"all"}function getScope(){return _scope||"all"}function getPressedKeyCodes(){return _downKeys.slice(0)}function filter(e){var e=e.target||e.srcElement,n=e.tagName;return!e.isContentEditable&&("INPUT"!==n&&"TEXTAREA"!==n&&"SELECT"!==n||e.readOnly)?!0:!1}function isPressed(e){return"string"==typeof e&&(e=code(e)),!!~_downKeys.indexOf(e)}function deleteScope(e,n){var t,o,s;for(s in e=e||getScope(),_handlers)if(Object.prototype.hasOwnProperty.call(_handlers,s))for(t=_handlers[s],o=0;o<t.length;)t[o].scope===e?t.splice(o,1):o++;getScope()===e&&setScope(n||"all")}function clearModifier(e){var n=e.keyCode||e.which||e.charCode,t=_downKeys.indexOf(n);if(t<0||_downKeys.splice(t,1),e.key&&"meta"==e.key.toLowerCase()&&_downKeys.splice(0,_downKeys.length),(n=93!==n&&224!==n?n:91)in _mods)for(var o in _mods[n]=!1,_modifier)_modifier[o]===n&&(hotkeys[o]=!1)}function unbind(e){if(void 0===e)Object.keys(_handlers).forEach(function(e){return delete _handlers[e]});else if(Array.isArray(e))e.forEach(function(e){e.key&&eachUnbind(e)});else if("object"==typeof e)e.key&&eachUnbind(e);else if("string"==typeof e){for(var n=arguments.length,t=Array(1<n?n-1:0),o=1;o<n;o++)t[o-1]=arguments[o];var s=t[0],i=t[1];"function"==typeof s&&(i=s,s=""),eachUnbind({key:e,scope:s,method:i,splitKey:"+"})}}var eachUnbind=function(e){var s=e.scope,i=e.method,n=e.splitKey,r=void 0===n?"+":n;getKeys(e.key).forEach(function(e){var n,e=e.split(r),t=e.length,o=e[t-1],o="*"===o?"*":code(o);_handlers[o]&&(s=s||getScope(),n=1<t?getMods(_modifier,e):[],_handlers[o]=_handlers[o].filter(function(e){return!((!i||e.method===i)&&e.scope===s&&compareArray(e.mods,n))}))})};function eventHandler(e,n,t,o){var s;if(n.element===o&&(n.scope===t||"all"===n.scope)){for(var i in s=0<n.mods.length,_mods)Object.prototype.hasOwnProperty.call(_mods,i)&&(!_mods[i]&&~n.mods.indexOf(+i)||_mods[i]&&!~n.mods.indexOf(+i))&&(s=!1);(0!==n.mods.length||_mods[16]||_mods[18]||_mods[17]||_mods[91])&&!s&&"*"!==n.shortcut||!1===n.method(e,n)&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0))}}function dispatch(t,e){var n=_handlers["*"],o=t.keyCode||t.which||t.charCode;if(hotkeys.filter.call(this,t)){if(~_downKeys.indexOf(o=93!==o&&224!==o?o:91)||229===o||_downKeys.push(o),["ctrlKey","altKey","shiftKey","metaKey"].forEach(function(e){var n=modifierMap[e];t[e]&&!~_downKeys.indexOf(n)?_downKeys.push(n):!t[e]&&~_downKeys.indexOf(n)?_downKeys.splice(_downKeys.indexOf(n),1):"metaKey"!==e||!t[e]||3!==_downKeys.length||t.ctrlKey||t.shiftKey||t.altKey||(_downKeys=_downKeys.slice(_downKeys.indexOf(n)))}),o in _mods){for(var s in _mods[o]=!0,_modifier)_modifier[s]===o&&(hotkeys[s]=!0);if(!n)return}for(var i in _mods)Object.prototype.hasOwnProperty.call(_mods,i)&&(_mods[i]=t[modifierMap[i]]);t.getModifierState&&(!t.altKey||t.ctrlKey)&&t.getModifierState("AltGraph")&&(~_downKeys.indexOf(17)||_downKeys.push(17),~_downKeys.indexOf(18)||_downKeys.push(18),_mods[17]=!0,_mods[18]=!0);var r=getScope();if(n)for(var d=0;d<n.length;d++)n[d].scope===r&&("keydown"===t.type&&n[d].keydown||"keyup"===t.type&&n[d].keyup)&&eventHandler(t,n[d],r,e);if(o in _handlers)for(var a=0;a<_handlers[o].length;a++)if(("keydown"===t.type&&_handlers[o][a].keydown||"keyup"===t.type&&_handlers[o][a].keyup)&&_handlers[o][a].key){for(var c=_handlers[o][a],l=c.key.split(c.splitKey),f=[],y=0;y<l.length;y++)f.push(code(l[y]));f.sort().join("")===_downKeys.sort().join("")&&eventHandler(t,c,r,e)}}}function isElementBind(e){return!!~elementHasBindEvent.indexOf(e)}function hotkeys(e,n,t){_downKeys=[];var o=getKeys(e),s=[],i="all",r=document,d=0,a=!1,c=!0,l="+",f=!1;for(void 0===t&&"function"==typeof n&&(t=n),"[object Object]"===Object.prototype.toString.call(n)&&(n.scope&&(i=n.scope),n.element&&(r=n.element),n.keyup&&(a=n.keyup),void 0!==n.keydown&&(c=n.keydown),void 0!==n.capture&&(f=n.capture),"string"==typeof n.splitKey&&(l=n.splitKey)),"string"==typeof n&&(i=n);d<o.length;d++)s=[],1<(e=o[d].split(l)).length&&(s=getMods(_modifier,e)),(e="*"===(e=e[e.length-1])?"*":code(e))in _handlers||(_handlers[e]=[]),_handlers[e].push({keyup:a,keydown:c,scope:i,mods:s,shortcut:o[d],method:t,key:o[d],splitKey:l,element:r});void 0!==r&&!isElementBind(r)&&window&&(elementHasBindEvent.push(r),addEvent(r,"keydown",function(e){dispatch(e,r)},f),winListendFocus||(winListendFocus=!0,addEvent(window,"focus",function(){_downKeys=[]},f)),addEvent(r,"keyup",function(e){dispatch(e,r),clearModifier(e)},f))}function trigger(n){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"all";Object.keys(_handlers).forEach(function(e){e=_handlers[e].find(function(e){return e.scope===t&&e.shortcut===n});e&&e.method&&e.method()})}var a,_hotkeys,_api={setScope:setScope,getScope:getScope,deleteScope:deleteScope,getPressedKeyCodes:getPressedKeyCodes,isPressed:isPressed,filter:filter,trigger:trigger,unbind:unbind,keyMap:_keyMap,modifier:_modifier,modifierMap:modifierMap};for(a in _api)Object.prototype.hasOwnProperty.call(_api,a)&&(hotkeys[a]=_api[a]);"undefined"!=typeof window&&(_hotkeys=window.hotkeys,hotkeys.noConflict=function(e){return e&&window.hotkeys===hotkeys&&(window.hotkeys=_hotkeys),hotkeys},window.hotkeys=hotkeys),module.exports=hotkeys; | ||
/*! hotkeys-js v3.10.0 | MIT © 2022 kenny wong <wowohoo@qq.com> http://jaywcjlove.github.io/hotkeys */ | ||
"use strict";var isff="undefined"!=typeof navigator&&0<navigator.userAgent.toLowerCase().indexOf("firefox");function addEvent(e,n,t,o){e.addEventListener?e.addEventListener(n,t,o):e.attachEvent&&e.attachEvent("on".concat(n),function(){t(window.event)})}function getMods(e,n){for(var t=n.slice(0,n.length-1),o=0;o<t.length;o++)t[o]=e[t[o].toLowerCase()];return t}function getKeys(e){for(var n=(e=(e="string"!=typeof e?"":e).replace(/\s/g,"")).split(","),t=n.lastIndexOf("");0<=t;)n[t-1]+=",",n.splice(t,1),t=n.lastIndexOf("");return n}function compareArray(e,n){for(var t=e.length<n.length?n:e,o=e.length<n.length?e:n,r=!0,i=0;i<t.length;i++)~o.indexOf(t[i])||(r=!1);return r}for(var _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={},k=1;k<20;k++)_keyMap["f".concat(k)]=111+k;var _downKeys=[],winListendFocus=!1,_scope="all",elementHasBindEvent=[],code=function(e){return _keyMap[e.toLowerCase()]||_modifier[e.toLowerCase()]||e.toUpperCase().charCodeAt(0)},getKey=function(n){return Object.keys(_keyMap).find(function(e){return _keyMap[e]===n})},getModifier=function(n){return Object.keys(_modifier).find(function(e){return _modifier[e]===n})};function setScope(e){_scope=e||"all"}function getScope(){return _scope||"all"}function getPressedKeyCodes(){return _downKeys.slice(0)}function getPressedKeyString(){return _downKeys.map(function(e){return getKey(e)||getModifier(e)||String.fromCharCode(e)})}function filter(e){var e=e.target||e.srcElement,n=e.tagName;return!e.isContentEditable&&("INPUT"!==n&&"TEXTAREA"!==n&&"SELECT"!==n||e.readOnly)?!0:!1}function isPressed(e){return"string"==typeof e&&(e=code(e)),!!~_downKeys.indexOf(e)}function deleteScope(e,n){var t,o,r;for(r in e=e||getScope(),_handlers)if(Object.prototype.hasOwnProperty.call(_handlers,r))for(t=_handlers[r],o=0;o<t.length;)t[o].scope===e?t.splice(o,1):o++;getScope()===e&&setScope(n||"all")}function clearModifier(e){var n=e.keyCode||e.which||e.charCode,t=_downKeys.indexOf(n);if(t<0||_downKeys.splice(t,1),e.key&&"meta"==e.key.toLowerCase()&&_downKeys.splice(0,_downKeys.length),(n=93!==n&&224!==n?n:91)in _mods)for(var o in _mods[n]=!1,_modifier)_modifier[o]===n&&(hotkeys[o]=!1)}function unbind(e){if(void 0===e)Object.keys(_handlers).forEach(function(e){return delete _handlers[e]});else if(Array.isArray(e))e.forEach(function(e){e.key&&eachUnbind(e)});else if("object"==typeof e)e.key&&eachUnbind(e);else if("string"==typeof e){for(var n=arguments.length,t=Array(1<n?n-1:0),o=1;o<n;o++)t[o-1]=arguments[o];var r=t[0],i=t[1];"function"==typeof r&&(i=r,r=""),eachUnbind({key:e,scope:r,method:i,splitKey:"+"})}}var eachUnbind=function(e){var r=e.scope,i=e.method,n=e.splitKey,s=void 0===n?"+":n;getKeys(e.key).forEach(function(e){var n,e=e.split(s),t=e.length,o=e[t-1],o="*"===o?"*":code(o);_handlers[o]&&(r=r||getScope(),n=1<t?getMods(_modifier,e):[],_handlers[o]=_handlers[o].filter(function(e){return!((!i||e.method===i)&&e.scope===r&&compareArray(e.mods,n))}))})};function eventHandler(e,n,t,o){var r;if(n.element===o&&(n.scope===t||"all"===n.scope)){for(var i in r=0<n.mods.length,_mods)Object.prototype.hasOwnProperty.call(_mods,i)&&(!_mods[i]&&~n.mods.indexOf(+i)||_mods[i]&&!~n.mods.indexOf(+i))&&(r=!1);(0!==n.mods.length||_mods[16]||_mods[18]||_mods[17]||_mods[91])&&!r&&"*"!==n.shortcut||!1===n.method(e,n)&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0))}}function dispatch(t,e){var n=_handlers["*"],o=t.keyCode||t.which||t.charCode;if(hotkeys.filter.call(this,t)){if(~_downKeys.indexOf(o=93!==o&&224!==o?o:91)||229===o||_downKeys.push(o),["ctrlKey","altKey","shiftKey","metaKey"].forEach(function(e){var n=modifierMap[e];t[e]&&!~_downKeys.indexOf(n)?_downKeys.push(n):!t[e]&&~_downKeys.indexOf(n)?_downKeys.splice(_downKeys.indexOf(n),1):"metaKey"!==e||!t[e]||3!==_downKeys.length||t.ctrlKey||t.shiftKey||t.altKey||(_downKeys=_downKeys.slice(_downKeys.indexOf(n)))}),o in _mods){for(var r in _mods[o]=!0,_modifier)_modifier[r]===o&&(hotkeys[r]=!0);if(!n)return}for(var i in _mods)Object.prototype.hasOwnProperty.call(_mods,i)&&(_mods[i]=t[modifierMap[i]]);t.getModifierState&&(!t.altKey||t.ctrlKey)&&t.getModifierState("AltGraph")&&(~_downKeys.indexOf(17)||_downKeys.push(17),~_downKeys.indexOf(18)||_downKeys.push(18),_mods[17]=!0,_mods[18]=!0);var s=getScope();if(n)for(var d=0;d<n.length;d++)n[d].scope===s&&("keydown"===t.type&&n[d].keydown||"keyup"===t.type&&n[d].keyup)&&eventHandler(t,n[d],s,e);if(o in _handlers)for(var a=0;a<_handlers[o].length;a++)if(("keydown"===t.type&&_handlers[o][a].keydown||"keyup"===t.type&&_handlers[o][a].keyup)&&_handlers[o][a].key){for(var c=_handlers[o][a],f=c.key.split(c.splitKey),l=[],y=0;y<f.length;y++)l.push(code(f[y]));l.sort().join("")===_downKeys.sort().join("")&&eventHandler(t,c,s,e)}}}function isElementBind(e){return!!~elementHasBindEvent.indexOf(e)}function hotkeys(e,n,t){_downKeys=[];var o=getKeys(e),r=[],i="all",s=document,d=0,a=!1,c=!0,f="+",l=!1;for(void 0===t&&"function"==typeof n&&(t=n),"[object Object]"===Object.prototype.toString.call(n)&&(n.scope&&(i=n.scope),n.element&&(s=n.element),n.keyup&&(a=n.keyup),void 0!==n.keydown&&(c=n.keydown),void 0!==n.capture&&(l=n.capture),"string"==typeof n.splitKey&&(f=n.splitKey)),"string"==typeof n&&(i=n);d<o.length;d++)r=[],1<(e=o[d].split(f)).length&&(r=getMods(_modifier,e)),(e="*"===(e=e[e.length-1])?"*":code(e))in _handlers||(_handlers[e]=[]),_handlers[e].push({keyup:a,keydown:c,scope:i,mods:r,shortcut:o[d],method:t,key:o[d],splitKey:f,element:s});void 0!==s&&!isElementBind(s)&&window&&(elementHasBindEvent.push(s),addEvent(s,"keydown",function(e){dispatch(e,s)},l),winListendFocus||(winListendFocus=!0,addEvent(window,"focus",function(){_downKeys=[]},l)),addEvent(s,"keyup",function(e){dispatch(e,s),clearModifier(e)},l))}function trigger(n){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"all";Object.keys(_handlers).forEach(function(e){e=_handlers[e].find(function(e){return e.scope===t&&e.shortcut===n});e&&e.method&&e.method()})}var a,_hotkeys,_api={getPressedKeyString:getPressedKeyString,setScope:setScope,getScope:getScope,deleteScope:deleteScope,getPressedKeyCodes:getPressedKeyCodes,isPressed:isPressed,filter:filter,trigger:trigger,unbind:unbind,keyMap:_keyMap,modifier:_modifier,modifierMap:modifierMap};for(a in _api)Object.prototype.hasOwnProperty.call(_api,a)&&(hotkeys[a]=_api[a]);"undefined"!=typeof window&&(_hotkeys=window.hotkeys,hotkeys.noConflict=function(e){return e&&window.hotkeys===hotkeys&&(window.hotkeys=_hotkeys),hotkeys},window.hotkeys=hotkeys),module.exports=hotkeys; |
/**! | ||
* hotkeys-js v3.9.5 | ||
* hotkeys-js v3.10.0 | ||
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies. | ||
@@ -168,2 +168,14 @@ * | ||
return _keyMap[x.toLowerCase()] || _modifier[x.toLowerCase()] || x.toUpperCase().charCodeAt(0); | ||
}; | ||
var getKey = function getKey(x) { | ||
return Object.keys(_keyMap).find(function (k) { | ||
return _keyMap[k] === x; | ||
}); | ||
}; | ||
var getModifier = function getModifier(x) { | ||
return Object.keys(_modifier).find(function (k) { | ||
return _modifier[k] === x; | ||
}); | ||
}; // 设置获取当前范围(默认为'所有') | ||
@@ -184,2 +196,8 @@ | ||
return _downKeys.slice(0); | ||
} | ||
function getPressedKeyString() { | ||
return _downKeys.map(function (c) { | ||
return getKey(c) || getModifier(c) || String.fromCharCode(c); | ||
}); | ||
} // 表单控件控件判断 返回 Boolean | ||
@@ -569,2 +587,3 @@ // hotkey is effective only when filter return true | ||
var _api = { | ||
getPressedKeyString: getPressedKeyString, | ||
setScope: setScope, | ||
@@ -571,0 +590,0 @@ getScope: getScope, |
/**! | ||
* hotkeys-js v3.9.5 | ||
* hotkeys-js v3.10.0 | ||
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies. | ||
@@ -174,2 +174,14 @@ * | ||
return _keyMap[x.toLowerCase()] || _modifier[x.toLowerCase()] || x.toUpperCase().charCodeAt(0); | ||
}; | ||
var getKey = function getKey(x) { | ||
return Object.keys(_keyMap).find(function (k) { | ||
return _keyMap[k] === x; | ||
}); | ||
}; | ||
var getModifier = function getModifier(x) { | ||
return Object.keys(_modifier).find(function (k) { | ||
return _modifier[k] === x; | ||
}); | ||
}; // 设置获取当前范围(默认为'所有') | ||
@@ -190,2 +202,8 @@ | ||
return _downKeys.slice(0); | ||
} | ||
function getPressedKeyString() { | ||
return _downKeys.map(function (c) { | ||
return getKey(c) || getModifier(c) || String.fromCharCode(c); | ||
}); | ||
} // 表单控件控件判断 返回 Boolean | ||
@@ -575,2 +593,3 @@ // hotkey is effective only when filter return true | ||
var _api = { | ||
getPressedKeyString: getPressedKeyString, | ||
setScope: setScope, | ||
@@ -577,0 +596,0 @@ getScope: getScope, |
@@ -1,2 +0,2 @@ | ||
/*! hotkeys-js v3.9.5 | MIT © 2022 kenny wong <wowohoo@qq.com> http://jaywcjlove.github.io/hotkeys */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).hotkeys=t()}(this,function(){"use strict";var e="undefined"!=typeof navigator&&0<navigator.userAgent.toLowerCase().indexOf("firefox");function p(e,t,n,o){e.addEventListener?e.addEventListener(t,n,o):e.attachEvent&&e.attachEvent("on".concat(t),function(){n(window.event)})}function d(e,t){for(var n=t.slice(0,t.length-1),o=0;o<n.length;o++)n[o]=e[n[o].toLowerCase()];return n}function y(e){for(var t=(e=(e="string"!=typeof e?"":e).replace(/\s/g,"")).split(","),n=t.lastIndexOf("");0<=n;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}for(var t={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,"-":e?173:189,"=":e?61:187,";":e?59:186,"'":222,"[":219,"]":221,"\\":220},h={"\u21e7":16,shift:16,"\u2325":18,alt:18,option:18,"\u2303":17,ctrl:17,control:17,"\u2318":91,cmd:91,command:91},m={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},g={16:!1,18:!1,17:!1,91:!1},v={},n=1;n<20;n++)t["f".concat(n)]=111+n;var k=[],w=!1,o="all",O=[],K=function(e){return t[e.toLowerCase()]||h[e.toLowerCase()]||e.toUpperCase().charCodeAt(0)};function r(e){o=e||"all"}function b(){return o||"all"}function f(e){var i=e.scope,r=e.method,t=e.splitKey,f=void 0===t?"+":t;y(e.key).forEach(function(e){var t,e=e.split(f),n=e.length,o=e[n-1],o="*"===o?"*":K(o);v[o]&&(i=i||b(),t=1<n?d(h,e):[],v[o]=v[o].filter(function(e){return!((!r||e.method===r)&&e.scope===i&&function(e,t){for(var n=e.length<t.length?t:e,o=e.length<t.length?e:t,i=!0,r=0;r<n.length;r++)~o.indexOf(n[r])||(i=!1);return i}(e.mods,t))}))})}function x(e,t,n,o){var i;if(t.element===o&&(t.scope===n||"all"===t.scope)){for(var r in i=0<t.mods.length,g)Object.prototype.hasOwnProperty.call(g,r)&&(!g[r]&&~t.mods.indexOf(+r)||g[r]&&!~t.mods.indexOf(+r))&&(i=!1);(0!==t.mods.length||g[16]||g[18]||g[17]||g[91])&&!i&&"*"!==t.shortcut||!1===t.method(e,t)&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0))}}function _(n,e){var t=v["*"],o=n.keyCode||n.which||n.charCode;if(C.filter.call(this,n)){if(~k.indexOf(o=93!==o&&224!==o?o:91)||229===o||k.push(o),["ctrlKey","altKey","shiftKey","metaKey"].forEach(function(e){var t=m[e];n[e]&&!~k.indexOf(t)?k.push(t):!n[e]&&~k.indexOf(t)?k.splice(k.indexOf(t),1):"metaKey"!==e||!n[e]||3!==k.length||n.ctrlKey||n.shiftKey||n.altKey||(k=k.slice(k.indexOf(t)))}),o in g){for(var i in g[o]=!0,h)h[i]===o&&(C[i]=!0);if(!t)return}for(var r in g)Object.prototype.hasOwnProperty.call(g,r)&&(g[r]=n[m[r]]);n.getModifierState&&(!n.altKey||n.ctrlKey)&&n.getModifierState("AltGraph")&&(~k.indexOf(17)||k.push(17),~k.indexOf(18)||k.push(18),g[17]=!0,g[18]=!0);var f=b();if(t)for(var a=0;a<t.length;a++)t[a].scope===f&&("keydown"===n.type&&t[a].keydown||"keyup"===n.type&&t[a].keyup)&&x(n,t[a],f,e);if(o in v)for(var c=0;c<v[o].length;c++)if(("keydown"===n.type&&v[o][c].keydown||"keyup"===n.type&&v[o][c].keyup)&&v[o][c].key){for(var l=v[o][c],s=l.key.split(l.splitKey),u=[],p=0;p<s.length;p++)u.push(K(s[p]));u.sort().join("")===k.sort().join("")&&x(n,l,f,e)}}}function C(e,t,n){k=[];var o=y(e),i=[],r="all",f=document,a=0,c=!1,l=!0,s="+",u=!1;for(void 0===n&&"function"==typeof t&&(n=t),"[object Object]"===Object.prototype.toString.call(t)&&(t.scope&&(r=t.scope),t.element&&(f=t.element),t.keyup&&(c=t.keyup),void 0!==t.keydown&&(l=t.keydown),void 0!==t.capture&&(u=t.capture),"string"==typeof t.splitKey&&(s=t.splitKey)),"string"==typeof t&&(r=t);a<o.length;a++)i=[],1<(e=o[a].split(s)).length&&(i=d(h,e)),(e="*"===(e=e[e.length-1])?"*":K(e))in v||(v[e]=[]),v[e].push({keyup:c,keydown:l,scope:r,mods:i,shortcut:o[a],method:n,key:o[a],splitKey:s,element:f});void 0!==f&&(t=f,!~O.indexOf(t))&&window&&(O.push(f),p(f,"keydown",function(e){_(e,f)},u),w||(w=!0,p(window,"focus",function(){k=[]},u)),p(f,"keyup",function(e){_(e,f);var t=e.keyCode||e.which||e.charCode,n=k.indexOf(t);if(n<0||k.splice(n,1),e.key&&"meta"==e.key.toLowerCase()&&k.splice(0,k.length),(t=93!==t&&224!==t?t:91)in g)for(var o in g[t]=!1,h)h[o]===t&&(C[o]=!1)},u))}var i,a,c={setScope:r,getScope:b,deleteScope:function(e,t){var n,o,i;for(i in e=e||b(),v)if(Object.prototype.hasOwnProperty.call(v,i))for(n=v[i],o=0;o<n.length;)n[o].scope===e?n.splice(o,1):o++;b()===e&&r(t||"all")},getPressedKeyCodes:function(){return k.slice(0)},isPressed:function(e){return"string"==typeof e&&(e=K(e)),!!~k.indexOf(e)},filter:function(e){var t=(e=e.target||e.srcElement).tagName;return!e.isContentEditable&&("INPUT"!==t&&"TEXTAREA"!==t&&"SELECT"!==t||e.readOnly)?!0:!1},trigger:function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"all";Object.keys(v).forEach(function(e){e=v[e].find(function(e){return e.scope===n&&e.shortcut===t});e&&e.method&&e.method()})},unbind:function(e){if(void 0===e)Object.keys(v).forEach(function(e){return delete v[e]});else if(Array.isArray(e))e.forEach(function(e){e.key&&f(e)});else if("object"==typeof e)e.key&&f(e);else if("string"==typeof e){for(var t=arguments.length,n=Array(1<t?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];var i=n[0],r=n[1];"function"==typeof i&&(r=i,i=""),f({key:e,scope:i,method:r,splitKey:"+"})}},keyMap:t,modifier:h,modifierMap:m};for(i in c)Object.prototype.hasOwnProperty.call(c,i)&&(C[i]=c[i]);return"undefined"!=typeof window&&(a=window.hotkeys,C.noConflict=function(e){return e&&window.hotkeys===C&&(window.hotkeys=a),C},window.hotkeys=C),C}); | ||
/*! hotkeys-js v3.10.0 | MIT © 2022 kenny wong <wowohoo@qq.com> http://jaywcjlove.github.io/hotkeys */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).hotkeys=t()}(this,function(){"use strict";var e="undefined"!=typeof navigator&&0<navigator.userAgent.toLowerCase().indexOf("firefox");function d(e,t,n,o){e.addEventListener?e.addEventListener(t,n,o):e.attachEvent&&e.attachEvent("on".concat(t),function(){n(window.event)})}function p(e,t){for(var n=t.slice(0,t.length-1),o=0;o<n.length;o++)n[o]=e[n[o].toLowerCase()];return n}function y(e){for(var t=(e=(e="string"!=typeof e?"":e).replace(/\s/g,"")).split(","),n=t.lastIndexOf("");0<=n;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}for(var o={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,"-":e?173:189,"=":e?61:187,";":e?59:186,"'":222,"[":219,"]":221,"\\":220},h={"\u21e7":16,shift:16,"\u2325":18,alt:18,option:18,"\u2303":17,ctrl:17,control:17,"\u2318":91,cmd:91,command:91},m={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},g={16:!1,18:!1,17:!1,91:!1},v={},t=1;t<20;t++)o["f".concat(t)]=111+t;var k=[],w=!1,n="all",O=[],K=function(e){return o[e.toLowerCase()]||h[e.toLowerCase()]||e.toUpperCase().charCodeAt(0)};function i(e){n=e||"all"}function b(){return n||"all"}function f(e){var r=e.scope,i=e.method,t=e.splitKey,f=void 0===t?"+":t;y(e.key).forEach(function(e){var t,e=e.split(f),n=e.length,o=e[n-1],o="*"===o?"*":K(o);v[o]&&(r=r||b(),t=1<n?p(h,e):[],v[o]=v[o].filter(function(e){return!((!i||e.method===i)&&e.scope===r&&function(e,t){for(var n=e.length<t.length?t:e,o=e.length<t.length?e:t,r=!0,i=0;i<n.length;i++)~o.indexOf(n[i])||(r=!1);return r}(e.mods,t))}))})}function x(e,t,n,o){var r;if(t.element===o&&(t.scope===n||"all"===t.scope)){for(var i in r=0<t.mods.length,g)Object.prototype.hasOwnProperty.call(g,i)&&(!g[i]&&~t.mods.indexOf(+i)||g[i]&&!~t.mods.indexOf(+i))&&(r=!1);(0!==t.mods.length||g[16]||g[18]||g[17]||g[91])&&!r&&"*"!==t.shortcut||!1===t.method(e,t)&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0))}}function C(n,e){var t=v["*"],o=n.keyCode||n.which||n.charCode;if(_.filter.call(this,n)){if(~k.indexOf(o=93!==o&&224!==o?o:91)||229===o||k.push(o),["ctrlKey","altKey","shiftKey","metaKey"].forEach(function(e){var t=m[e];n[e]&&!~k.indexOf(t)?k.push(t):!n[e]&&~k.indexOf(t)?k.splice(k.indexOf(t),1):"metaKey"!==e||!n[e]||3!==k.length||n.ctrlKey||n.shiftKey||n.altKey||(k=k.slice(k.indexOf(t)))}),o in g){for(var r in g[o]=!0,h)h[r]===o&&(_[r]=!0);if(!t)return}for(var i in g)Object.prototype.hasOwnProperty.call(g,i)&&(g[i]=n[m[i]]);n.getModifierState&&(!n.altKey||n.ctrlKey)&&n.getModifierState("AltGraph")&&(~k.indexOf(17)||k.push(17),~k.indexOf(18)||k.push(18),g[17]=!0,g[18]=!0);var f=b();if(t)for(var c=0;c<t.length;c++)t[c].scope===f&&("keydown"===n.type&&t[c].keydown||"keyup"===n.type&&t[c].keyup)&&x(n,t[c],f,e);if(o in v)for(var a=0;a<v[o].length;a++)if(("keydown"===n.type&&v[o][a].keydown||"keyup"===n.type&&v[o][a].keyup)&&v[o][a].key){for(var l=v[o][a],s=l.key.split(l.splitKey),u=[],d=0;d<s.length;d++)u.push(K(s[d]));u.sort().join("")===k.sort().join("")&&x(n,l,f,e)}}}function _(e,t,n){k=[];var o=y(e),r=[],i="all",f=document,c=0,a=!1,l=!0,s="+",u=!1;for(void 0===n&&"function"==typeof t&&(n=t),"[object Object]"===Object.prototype.toString.call(t)&&(t.scope&&(i=t.scope),t.element&&(f=t.element),t.keyup&&(a=t.keyup),void 0!==t.keydown&&(l=t.keydown),void 0!==t.capture&&(u=t.capture),"string"==typeof t.splitKey&&(s=t.splitKey)),"string"==typeof t&&(i=t);c<o.length;c++)r=[],1<(e=o[c].split(s)).length&&(r=p(h,e)),(e="*"===(e=e[e.length-1])?"*":K(e))in v||(v[e]=[]),v[e].push({keyup:a,keydown:l,scope:i,mods:r,shortcut:o[c],method:n,key:o[c],splitKey:s,element:f});void 0!==f&&(t=f,!~O.indexOf(t))&&window&&(O.push(f),d(f,"keydown",function(e){C(e,f)},u),w||(w=!0,d(window,"focus",function(){k=[]},u)),d(f,"keyup",function(e){C(e,f);var t=e.keyCode||e.which||e.charCode,n=k.indexOf(t);if(n<0||k.splice(n,1),e.key&&"meta"==e.key.toLowerCase()&&k.splice(0,k.length),(t=93!==t&&224!==t?t:91)in g)for(var o in g[t]=!1,h)h[o]===t&&(_[o]=!1)},u))}var r,c,a={getPressedKeyString:function(){return k.map(function(e){return n=e,Object.keys(o).find(function(e){return o[e]===n})||(t=e,Object.keys(h).find(function(e){return h[e]===t}))||String.fromCharCode(e);var t,n})},setScope:i,getScope:b,deleteScope:function(e,t){var n,o,r;for(r in e=e||b(),v)if(Object.prototype.hasOwnProperty.call(v,r))for(n=v[r],o=0;o<n.length;)n[o].scope===e?n.splice(o,1):o++;b()===e&&i(t||"all")},getPressedKeyCodes:function(){return k.slice(0)},isPressed:function(e){return"string"==typeof e&&(e=K(e)),!!~k.indexOf(e)},filter:function(e){var t=(e=e.target||e.srcElement).tagName;return!e.isContentEditable&&("INPUT"!==t&&"TEXTAREA"!==t&&"SELECT"!==t||e.readOnly)?!0:!1},trigger:function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"all";Object.keys(v).forEach(function(e){e=v[e].find(function(e){return e.scope===n&&e.shortcut===t});e&&e.method&&e.method()})},unbind:function(e){if(void 0===e)Object.keys(v).forEach(function(e){return delete v[e]});else if(Array.isArray(e))e.forEach(function(e){e.key&&f(e)});else if("object"==typeof e)e.key&&f(e);else if("string"==typeof e){for(var t=arguments.length,n=Array(1<t?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];var r=n[0],i=n[1];"function"==typeof r&&(i=r,r=""),f({key:e,scope:r,method:i,splitKey:"+"})}},keyMap:o,modifier:h,modifierMap:m};for(r in a)Object.prototype.hasOwnProperty.call(a,r)&&(_[r]=a[r]);return"undefined"!=typeof window&&(c=window.hotkeys,_.noConflict=function(e){return e&&window.hotkeys===_&&(window.hotkeys=c),_},window.hotkeys=_),_}); |
{ | ||
"name": "hotkeys-js", | ||
"description": "A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.", | ||
"version": "3.9.5", | ||
"version": "3.10.0", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "types": "index.d.ts", |
@@ -37,4 +37,4 @@ # Hotkeys | ||
// Prevent the default refresh event under WINDOWS system | ||
event.preventDefault() | ||
alert('you pressed F5!') | ||
event.preventDefault() | ||
alert('you pressed F5!') | ||
}); | ||
@@ -89,9 +89,9 @@ ``` | ||
`⌘` Command() | ||
`⌃` Control | ||
`⌥` Option(alt) | ||
`⇧` Shift | ||
`⇪` Caps Lock(Capital) | ||
~~`fn` Does not support fn~~ | ||
`↩︎` return/Enter space | ||
`⌘` Command() | ||
`⌃` Control | ||
`⌥` Option(alt) | ||
`⇧` Shift | ||
`⇪` Caps Lock(Capital) | ||
~~`fn` Does not support fn~~ | ||
`↩︎` return/Enter space | ||
@@ -123,3 +123,3 @@ ## Defining Shortcuts | ||
hotkeys('a', function(event,handler){ | ||
//event.srcElement: input | ||
//event.srcElement: input | ||
//event.target: input | ||
@@ -129,3 +129,3 @@ if(event.target === "input"){ | ||
} | ||
alert('you pressed a!') | ||
alert('you pressed a!') | ||
}); | ||
@@ -158,3 +158,3 @@ | ||
#### option | ||
#### option | ||
@@ -172,3 +172,3 @@ - `scope<String>` | ||
element: document.getElementById('wrapper'), | ||
}, function(){ | ||
}, function(){ | ||
console.log('do something else'); | ||
@@ -249,3 +249,3 @@ }); | ||
}); | ||
hotkeys('o, enter', 'files', function(){ | ||
hotkeys('o, enter', 'files', function(){ | ||
console.log('do something else'); | ||
@@ -340,2 +340,13 @@ }); | ||
### getPressedKeyStrings | ||
Returns an array of key codes currently pressed. | ||
```js | ||
hotkeys('command+ctrl+shift+a,f', function(){ | ||
console.log(hotkeys.getPressedKeyString()); //=> ['⌘', '⌃', '⇧', 'A', 'F'] | ||
}) | ||
``` | ||
### filter | ||
@@ -375,8 +386,8 @@ | ||
hotkeys() | ||
// -->Uncaught TypeError: hotkeys is not a function(anonymous function) | ||
// @ VM2170:2InjectedScript._evaluateOn | ||
// @ VM2165:883InjectedScript._evaluateAndWrap | ||
// -->Uncaught TypeError: hotkeys is not a function(anonymous function) | ||
// @ VM2170:2InjectedScript._evaluateOn | ||
// @ VM2165:883InjectedScript._evaluateAndWrap | ||
// @ VM2165:816InjectedScript.evaluate @ VM2165:682 | ||
``` | ||
## Development | ||
@@ -383,0 +394,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
83082
1535
426