Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hotkeys-js

Package Overview
Dependencies
Maintainers
1
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hotkeys-js - npm Package Compare versions

Comparing version 3.13.1 to 3.13.2

7

dist/hotkeys.common.js
/**!
* hotkeys-js v3.13.1
* hotkeys-js v3.13.2
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.

@@ -501,2 +501,5 @@ *

// 如果只允许单个callback,先unbind
if (single) unbind(key, scope);
// 对于每个快捷键进行处理

@@ -516,4 +519,2 @@ for (; i < keys.length; i++) {

if (!(key in _handlers)) _handlers[key] = [];
// 如果只允许单个callback,重新设置_handlers
if (single) _handlers[key] = [];
_handlers[key].push({

@@ -520,0 +521,0 @@ keyup,

@@ -1,2 +0,2 @@

/*! hotkeys-js v3.13.1 | MIT © 2023 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,o,n){e.addEventListener?e.addEventListener(t,o,n):e.attachEvent&&e.attachEvent("on".concat(t),()=>{o(window.event)})}function getMods(t,e){var o=e.slice(0,e.length-1);for(let e=0;e<o.length;e++)o[e]=t[o[e].toLowerCase()];return o}function getKeys(e){var t=(e=(e="string"!=typeof e?"":e).replace(/\s/g,"")).split(",");let o=t.lastIndexOf("");for(;0<=o;)t[o-1]+=",",t.splice(o,1),o=t.lastIndexOf("");return t}function compareArray(e,t){var o=e.length<t.length?t:e,n=e.length<t.length?e:t;let s=!0;for(let e=0;e<o.length;e++)~n.indexOf(o[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=!1,_scope="all";const elementHasBindEvent=[],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:o,shortcut:n}=e;s.push({scope:t,shortcut:n,mods:o,keys:e.split("+").map(e=>code(e))})})}),s}function filter(e){var e=e.target||e.srcElement,t=e["tagName"];let o=!e.isContentEditable&&("INPUT"!==t&&"TEXTAREA"!==t&&"SELECT"!==t||e.readOnly)?!0:!1;return o}function isPressed(e){return"string"==typeof e&&(e=code(e)),!!~_downKeys.indexOf(e)}function deleteScope(e,t){var o;let n;e=e||getScope();for(const s in _handlers)if(Object.prototype.hasOwnProperty.call(_handlers,s))for(o=_handlers[s],n=0;n<o.length;)o[n].scope===e?o.splice(n,1):n++;getScope()===e&&setScope(t||"all")}function clearModifier(e){let t=e.keyCode||e.which||e.charCode;var o=_downKeys.indexOf(t);if(o<0||_downKeys.splice(o,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 n in _modifier)_modifier[n]===t&&(hotkeys[n]=!1)}}function unbind(o){if(void 0===o)Object.keys(_handlers).forEach(e=>delete _handlers[e]);else if(Array.isArray(o))o.forEach(e=>{e.key&&eachUnbind(e)});else if("object"==typeof o)o.key&&eachUnbind(o);else if("string"==typeof o){for(var n=arguments.length,s=Array(1<n?n-1:0),d=1;d<n;d++)s[d-1]=arguments[d];let[e,t]=s;"function"==typeof e&&(t=e,e=""),eachUnbind({key:o,scope:e,method:t,splitKey:"+"})}}const eachUnbind=e=>{let{key:t,scope:s,method:d,splitKey:i="+"}=e;getKeys(t).forEach(e=>{var e=e.split(i),t=e.length,o=e[t-1],o="*"===o?"*":code(o);if(_handlers[o]){s=s||getScope();const n=1<t?getMods(_modifier,e):[];_handlers[o]=_handlers[o].filter(e=>{return!((!d||e.method===d)&&e.scope===s&&compareArray(e.mods,n))})}})};function eventHandler(t,o,n,e){if(o.element===e){let e;if(o.scope===n||"all"===o.scope){e=0<o.mods.length;for(const s in _mods)Object.prototype.hasOwnProperty.call(_mods,s)&&(!_mods[s]&&~o.mods.indexOf(+s)||_mods[s]&&!~o.mods.indexOf(+s))&&(e=!1);(0!==o.mods.length||_mods[16]||_mods[18]||_mods[17]||_mods[91])&&!e&&"*"!==o.shortcut||(o.keys=[],o.keys=o.keys.concat(_downKeys),!1===o.method(t,o)&&(t.preventDefault?t.preventDefault():t.returnValue=!1,t.stopPropagation&&t.stopPropagation(),t.cancelBubble)&&(t.cancelBubble=!0))}}}function dispatch(o,t){var n=_handlers["*"];let s=o.keyCode||o.which||o.charCode;if(hotkeys.filter.call(this,o)){if(93!==s&&224!==s||(s=91),~_downKeys.indexOf(s)||229===s||_downKeys.push(s),["ctrlKey","altKey","shiftKey","metaKey"].forEach(e=>{var t=modifierMap[e];o[e]&&!~_downKeys.indexOf(t)?_downKeys.push(t):!o[e]&&~_downKeys.indexOf(t)?_downKeys.splice(_downKeys.indexOf(t),1):"metaKey"!==e||!o[e]||3!==_downKeys.length||o.ctrlKey||o.shiftKey||o.altKey||(_downKeys=_downKeys.slice(_downKeys.indexOf(t)))}),s in _mods){_mods[s]=!0;for(const e in _modifier)_modifier[e]===s&&(hotkeys[e]=!0);if(!n)return}for(const c in _mods)Object.prototype.hasOwnProperty.call(_mods,c)&&(_mods[c]=o[modifierMap[c]]);o.getModifierState&&(!o.altKey||o.ctrlKey)&&o.getModifierState("AltGraph")&&(~_downKeys.indexOf(17)||_downKeys.push(17),~_downKeys.indexOf(18)||_downKeys.push(18),_mods[17]=!0,_mods[18]=!0);var d=getScope();if(n)for(let e=0;e<n.length;e++)n[e].scope===d&&("keydown"===o.type&&n[e].keydown||"keyup"===o.type&&n[e].keyup)&&eventHandler(o,n[e],d,t);if(s in _handlers)for(let e=0;e<_handlers[s].length;e++)if(("keydown"===o.type&&_handlers[s][e].keydown||"keyup"===o.type&&_handlers[s][e].keyup)&&_handlers[s][e].key){var i=_handlers[s][e],r=i["splitKey"],l=i.key.split(r),a=[];for(let e=0;e<l.length;e++)a.push(code(l[e]));a.sort().join("")===_downKeys.sort().join("")&&eventHandler(o,i,d,t)}}}function isElementBind(e){return!!~elementHasBindEvent.indexOf(e)}function hotkeys(e,t,o){_downKeys=[];var n=getKeys(e);let s=[],d="all",i=document,r=0,l=!1,a=!0,c="+",y=!1,f=!1;for(void 0===o&&"function"==typeof t&&(o=t),"[object Object]"===Object.prototype.toString.call(t)&&(t.scope&&(d=t.scope),t.element&&(i=t.element),t.keyup&&(l=t.keyup),void 0!==t.keydown&&(a=t.keydown),void 0!==t.capture&&(y=t.capture),"string"==typeof t.splitKey&&(c=t.splitKey),!0===t.single)&&(f=!0),"string"==typeof t&&(d=t);r<n.length;r++)e=n[r].split(c),s=[],1<e.length&&(s=getMods(_modifier,e)),(e="*"===(e=e[e.length-1])?"*":code(e))in _handlers||(_handlers[e]=[]),f&&(_handlers[e]=[]),_handlers[e].push({keyup:l,keydown:a,scope:d,mods:s,shortcut:n[r],method:o,key:n[r],splitKey:c,element:i});void 0!==i&&!isElementBind(i)&&window&&(elementHasBindEvent.push(i),addEvent(i,"keydown",e=>{dispatch(e,i)},y),winListendFocus||(winListendFocus=!0,addEvent(window,"focus",()=>{_downKeys=[]},y)),addEvent(i,"keyup",e=>{dispatch(e,i),clearModifier(e)},y))}function trigger(t){let o=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"all";Object.keys(_handlers).forEach(e=>{_handlers[e].filter(e=>e.scope===o&&e.shortcut===t).forEach(e=>{e&&e.method&&e.method()})})}const _api={getPressedKeyString:getPressedKeyString,setScope:setScope,getScope:getScope,deleteScope:deleteScope,getPressedKeyCodes:getPressedKeyCodes,getAllKeyCodes:getAllKeyCodes,isPressed:isPressed,filter:filter,trigger:trigger,unbind:unbind,keyMap:_keyMap,modifier:_modifier,modifierMap:modifierMap};for(const f0 in _api)Object.prototype.hasOwnProperty.call(_api,f0)&&(hotkeys[f0]=_api[f0]);if("undefined"!=typeof window){const g0=window.hotkeys;hotkeys.noConflict=e=>(e&&window.hotkeys===hotkeys&&(window.hotkeys=g0),hotkeys),window.hotkeys=hotkeys}module.exports=hotkeys;
/*! hotkeys-js v3.13.2 | MIT © 2023 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,o,n){e.addEventListener?e.addEventListener(t,o,n):e.attachEvent&&e.attachEvent("on".concat(t),()=>{o(window.event)})}function getMods(t,e){var o=e.slice(0,e.length-1);for(let e=0;e<o.length;e++)o[e]=t[o[e].toLowerCase()];return o}function getKeys(e){var t=(e=(e="string"!=typeof e?"":e).replace(/\s/g,"")).split(",");let o=t.lastIndexOf("");for(;0<=o;)t[o-1]+=",",t.splice(o,1),o=t.lastIndexOf("");return t}function compareArray(e,t){var o=e.length<t.length?t:e,n=e.length<t.length?e:t;let s=!0;for(let e=0;e<o.length;e++)~n.indexOf(o[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=!1,_scope="all";const elementHasBindEvent=[],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:o,shortcut:n}=e;s.push({scope:t,shortcut:n,mods:o,keys:e.split("+").map(e=>code(e))})})}),s}function filter(e){var e=e.target||e.srcElement,t=e["tagName"];let o=!e.isContentEditable&&("INPUT"!==t&&"TEXTAREA"!==t&&"SELECT"!==t||e.readOnly)?!0:!1;return o}function isPressed(e){return"string"==typeof e&&(e=code(e)),!!~_downKeys.indexOf(e)}function deleteScope(e,t){var o;let n;e=e||getScope();for(const s in _handlers)if(Object.prototype.hasOwnProperty.call(_handlers,s))for(o=_handlers[s],n=0;n<o.length;)o[n].scope===e?o.splice(n,1):n++;getScope()===e&&setScope(t||"all")}function clearModifier(e){let t=e.keyCode||e.which||e.charCode;var o=_downKeys.indexOf(t);if(o<0||_downKeys.splice(o,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 n in _modifier)_modifier[n]===t&&(hotkeys[n]=!1)}}function unbind(o){if(void 0===o)Object.keys(_handlers).forEach(e=>delete _handlers[e]);else if(Array.isArray(o))o.forEach(e=>{e.key&&eachUnbind(e)});else if("object"==typeof o)o.key&&eachUnbind(o);else if("string"==typeof o){for(var n=arguments.length,s=Array(1<n?n-1:0),d=1;d<n;d++)s[d-1]=arguments[d];let[e,t]=s;"function"==typeof e&&(t=e,e=""),eachUnbind({key:o,scope:e,method:t,splitKey:"+"})}}const eachUnbind=e=>{let{key:t,scope:s,method:d,splitKey:i="+"}=e;getKeys(t).forEach(e=>{var e=e.split(i),t=e.length,o=e[t-1],o="*"===o?"*":code(o);if(_handlers[o]){s=s||getScope();const n=1<t?getMods(_modifier,e):[];_handlers[o]=_handlers[o].filter(e=>{return!((!d||e.method===d)&&e.scope===s&&compareArray(e.mods,n))})}})};function eventHandler(t,o,n,e){if(o.element===e){let e;if(o.scope===n||"all"===o.scope){e=0<o.mods.length;for(const s in _mods)Object.prototype.hasOwnProperty.call(_mods,s)&&(!_mods[s]&&~o.mods.indexOf(+s)||_mods[s]&&!~o.mods.indexOf(+s))&&(e=!1);(0!==o.mods.length||_mods[16]||_mods[18]||_mods[17]||_mods[91])&&!e&&"*"!==o.shortcut||(o.keys=[],o.keys=o.keys.concat(_downKeys),!1===o.method(t,o)&&(t.preventDefault?t.preventDefault():t.returnValue=!1,t.stopPropagation&&t.stopPropagation(),t.cancelBubble)&&(t.cancelBubble=!0))}}}function dispatch(o,t){var n=_handlers["*"];let s=o.keyCode||o.which||o.charCode;if(hotkeys.filter.call(this,o)){if(93!==s&&224!==s||(s=91),~_downKeys.indexOf(s)||229===s||_downKeys.push(s),["ctrlKey","altKey","shiftKey","metaKey"].forEach(e=>{var t=modifierMap[e];o[e]&&!~_downKeys.indexOf(t)?_downKeys.push(t):!o[e]&&~_downKeys.indexOf(t)?_downKeys.splice(_downKeys.indexOf(t),1):"metaKey"!==e||!o[e]||3!==_downKeys.length||o.ctrlKey||o.shiftKey||o.altKey||(_downKeys=_downKeys.slice(_downKeys.indexOf(t)))}),s in _mods){_mods[s]=!0;for(const e in _modifier)_modifier[e]===s&&(hotkeys[e]=!0);if(!n)return}for(const c in _mods)Object.prototype.hasOwnProperty.call(_mods,c)&&(_mods[c]=o[modifierMap[c]]);o.getModifierState&&(!o.altKey||o.ctrlKey)&&o.getModifierState("AltGraph")&&(~_downKeys.indexOf(17)||_downKeys.push(17),~_downKeys.indexOf(18)||_downKeys.push(18),_mods[17]=!0,_mods[18]=!0);var d=getScope();if(n)for(let e=0;e<n.length;e++)n[e].scope===d&&("keydown"===o.type&&n[e].keydown||"keyup"===o.type&&n[e].keyup)&&eventHandler(o,n[e],d,t);if(s in _handlers)for(let e=0;e<_handlers[s].length;e++)if(("keydown"===o.type&&_handlers[s][e].keydown||"keyup"===o.type&&_handlers[s][e].keyup)&&_handlers[s][e].key){var i=_handlers[s][e],r=i["splitKey"],l=i.key.split(r),a=[];for(let e=0;e<l.length;e++)a.push(code(l[e]));a.sort().join("")===_downKeys.sort().join("")&&eventHandler(o,i,d,t)}}}function isElementBind(e){return!!~elementHasBindEvent.indexOf(e)}function hotkeys(e,t,o){_downKeys=[];var n=getKeys(e);let s=[],d="all",i=document,r=0,l=!1,a=!0,c="+",y=!1,f=!1;for(void 0===o&&"function"==typeof t&&(o=t),"[object Object]"===Object.prototype.toString.call(t)&&(t.scope&&(d=t.scope),t.element&&(i=t.element),t.keyup&&(l=t.keyup),void 0!==t.keydown&&(a=t.keydown),void 0!==t.capture&&(y=t.capture),"string"==typeof t.splitKey&&(c=t.splitKey),!0===t.single)&&(f=!0),"string"==typeof t&&(d=t),f&&unbind(e,d);r<n.length;r++)e=n[r].split(c),s=[],1<e.length&&(s=getMods(_modifier,e)),(e="*"===(e=e[e.length-1])?"*":code(e))in _handlers||(_handlers[e]=[]),_handlers[e].push({keyup:l,keydown:a,scope:d,mods:s,shortcut:n[r],method:o,key:n[r],splitKey:c,element:i});void 0!==i&&!isElementBind(i)&&window&&(elementHasBindEvent.push(i),addEvent(i,"keydown",e=>{dispatch(e,i)},y),winListendFocus||(winListendFocus=!0,addEvent(window,"focus",()=>{_downKeys=[]},y)),addEvent(i,"keyup",e=>{dispatch(e,i),clearModifier(e)},y))}function trigger(t){let o=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"all";Object.keys(_handlers).forEach(e=>{_handlers[e].filter(e=>e.scope===o&&e.shortcut===t).forEach(e=>{e&&e.method&&e.method()})})}const _api={getPressedKeyString:getPressedKeyString,setScope:setScope,getScope:getScope,deleteScope:deleteScope,getPressedKeyCodes:getPressedKeyCodes,getAllKeyCodes:getAllKeyCodes,isPressed:isPressed,filter:filter,trigger:trigger,unbind:unbind,keyMap:_keyMap,modifier:_modifier,modifierMap:modifierMap};for(const f0 in _api)Object.prototype.hasOwnProperty.call(_api,f0)&&(hotkeys[f0]=_api[f0]);if("undefined"!=typeof window){const g0=window.hotkeys;hotkeys.noConflict=e=>(e&&window.hotkeys===hotkeys&&(window.hotkeys=g0),hotkeys),window.hotkeys=hotkeys}module.exports=hotkeys;
/**!
* hotkeys-js v3.13.1
* hotkeys-js v3.13.2
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.

@@ -499,2 +499,5 @@ *

// 如果只允许单个callback,先unbind
if (single) unbind(key, scope);
// 对于每个快捷键进行处理

@@ -514,4 +517,2 @@ for (; i < keys.length; i++) {

if (!(key in _handlers)) _handlers[key] = [];
// 如果只允许单个callback,重新设置_handlers
if (single) _handlers[key] = [];
_handlers[key].push({

@@ -518,0 +519,0 @@ keyup,

/**!
* hotkeys-js v3.13.1
* hotkeys-js v3.13.2
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.

@@ -505,2 +505,5 @@ *

// 如果只允许单个callback,先unbind
if (single) unbind(key, scope);
// 对于每个快捷键进行处理

@@ -520,4 +523,2 @@ for (; i < keys.length; i++) {

if (!(key in _handlers)) _handlers[key] = [];
// 如果只允许单个callback,重新设置_handlers
if (single) _handlers[key] = [];
_handlers[key].push({

@@ -524,0 +525,0 @@ keyup,

@@ -1,2 +0,2 @@

/*! hotkeys-js v3.13.1 | MIT © 2023 kenny wong <wowohoo@qq.com> https://jaywcjlove.github.io/hotkeys-js */
!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 y(e,t,n,o){e.addEventListener?e.addEventListener(t,n,o):e.attachEvent&&e.attachEvent("on".concat(t),()=>{n(window.event)})}function u(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 h(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}const 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},m={"\u21e7":16,shift:16,"\u2325":18,alt:18,option:18,"\u2303":17,ctrl:17,control:17,"\u2318":91,cmd:91,command:91},p={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},k={};for(let e=1;e<20;e++)o["f".concat(e)]=111+e;let w=[],v=!1,t="all";const O=[],K=e=>o[e.toLowerCase()]||m[e.toLowerCase()]||e.toUpperCase().charCodeAt(0);function i(e){t=e||"all"}function d(){return t||"all"}const s=e=>{let{key:t,scope:r,method:i,splitKey:s="+"}=e;h(t).forEach(e=>{var e=e.split(s),t=e.length,n=e[t-1],n="*"===n?"*":K(n);if(k[n]){r=r||d();const o=1<t?u(m,e):[];k[n]=k[n].filter(e=>{return!((!i||e.method===i)&&e.scope===r&&function(e,t){var n=e.length<t.length?t:e,o=e.length<t.length?e:t;let r=!0;for(let e=0;e<n.length;e++)~o.indexOf(n[e])||(r=!1);return r}(e.mods,o))})}})};function b(t,n,o,e){if(n.element===e){let e;if(n.scope===o||"all"===n.scope){e=0<n.mods.length;for(const r in g)Object.prototype.hasOwnProperty.call(g,r)&&(!g[r]&&~n.mods.indexOf(+r)||g[r]&&!~n.mods.indexOf(+r))&&(e=!1);(0!==n.mods.length||g[16]||g[18]||g[17]||g[91])&&!e&&"*"!==n.shortcut||(n.keys=[],n.keys=n.keys.concat(w),!1===n.method(t,n)&&(t.preventDefault?t.preventDefault():t.returnValue=!1,t.stopPropagation&&t.stopPropagation(),t.cancelBubble)&&(t.cancelBubble=!0))}}}function x(n,t){var o=k["*"];let r=n.keyCode||n.which||n.charCode;if(C.filter.call(this,n)){if(93!==r&&224!==r||(r=91),~w.indexOf(r)||229===r||w.push(r),["ctrlKey","altKey","shiftKey","metaKey"].forEach(e=>{var t=p[e];n[e]&&!~w.indexOf(t)?w.push(t):!n[e]&&~w.indexOf(t)?w.splice(w.indexOf(t),1):"metaKey"!==e||!n[e]||3!==w.length||n.ctrlKey||n.shiftKey||n.altKey||(w=w.slice(w.indexOf(t)))}),r in g){g[r]=!0;for(const e in m)m[e]===r&&(C[e]=!0);if(!o)return}for(const a in g)Object.prototype.hasOwnProperty.call(g,a)&&(g[a]=n[p[a]]);n.getModifierState&&(!n.altKey||n.ctrlKey)&&n.getModifierState("AltGraph")&&(~w.indexOf(17)||w.push(17),~w.indexOf(18)||w.push(18),g[17]=!0,g[18]=!0);var i=d();if(o)for(let e=0;e<o.length;e++)o[e].scope===i&&("keydown"===n.type&&o[e].keydown||"keyup"===n.type&&o[e].keyup)&&b(n,o[e],i,t);if(r in k)for(let e=0;e<k[r].length;e++)if(("keydown"===n.type&&k[r][e].keydown||"keyup"===n.type&&k[r][e].keyup)&&k[r][e].key){var s=k[r][e],l=s["splitKey"],c=s.key.split(l),f=[];for(let e=0;e<c.length;e++)f.push(K(c[e]));f.sort().join("")===w.sort().join("")&&b(n,s,i,t)}}}function C(e,t,n){w=[];var o=h(e);let r=[],i="all",s=document,l=0,c=!1,f=!0,a="+",p=!1,d=!1;for(void 0===n&&"function"==typeof t&&(n=t),"[object Object]"===Object.prototype.toString.call(t)&&(t.scope&&(i=t.scope),t.element&&(s=t.element),t.keyup&&(c=t.keyup),void 0!==t.keydown&&(f=t.keydown),void 0!==t.capture&&(p=t.capture),"string"==typeof t.splitKey&&(a=t.splitKey),!0===t.single)&&(d=!0),"string"==typeof t&&(i=t);l<o.length;l++)e=o[l].split(a),r=[],1<e.length&&(r=u(m,e)),(e="*"===(e=e[e.length-1])?"*":K(e))in k||(k[e]=[]),d&&(k[e]=[]),k[e].push({keyup:c,keydown:f,scope:i,mods:r,shortcut:o[l],method:n,key:o[l],splitKey:a,element:s});void 0!==s&&(t=s,!~O.indexOf(t))&&window&&(O.push(s),y(s,"keydown",e=>{x(e,s)},p),v||(v=!0,y(window,"focus",()=>{w=[]},p)),y(s,"keyup",t=>{x(t,s);{let e=t.keyCode||t.which||t.charCode;var n=w.indexOf(e);if(n<0||w.splice(n,1),t.key&&"meta"==t.key.toLowerCase()&&w.splice(0,w.length),(e=93!==e&&224!==e?e:91)in g){g[e]=!1;for(const o in m)m[o]===e&&(C[o]=!1)}}},p))}var n={getPressedKeyString:function(){return w.map(e=>{return n=e,Object.keys(o).find(e=>o[e]===n)||(t=e,Object.keys(m).find(e=>m[e]===t))||String.fromCharCode(e);var t,n})},setScope:i,getScope:d,deleteScope:function(e,t){var n;let o;e=e||d();for(const r in k)if(Object.prototype.hasOwnProperty.call(k,r))for(n=k[r],o=0;o<n.length;)n[o].scope===e?n.splice(o,1):o++;d()===e&&i(t||"all")},getPressedKeyCodes:function(){return w.slice(0)},getAllKeyCodes:function(){const r=[];return Object.keys(k).forEach(e=>{k[e].forEach(e=>{var{key:e,scope:t,mods:n,shortcut:o}=e;r.push({scope:t,shortcut:o,mods:n,keys:e.split("+").map(e=>K(e))})})}),r},isPressed:function(e){return"string"==typeof e&&(e=K(e)),!!~w.indexOf(e)},filter:function(e){var t=(e=e.target||e.srcElement)["tagName"];let n=!e.isContentEditable&&("INPUT"!==t&&"TEXTAREA"!==t&&"SELECT"!==t||e.readOnly)?!0:!1;return n},trigger:function(t){let n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"all";Object.keys(k).forEach(e=>{k[e].filter(e=>e.scope===n&&e.shortcut===t).forEach(e=>{e&&e.method&&e.method()})})},unbind:function(n){if(void 0===n)Object.keys(k).forEach(e=>delete k[e]);else if(Array.isArray(n))n.forEach(e=>{e.key&&s(e)});else if("object"==typeof n)n.key&&s(n);else if("string"==typeof n){for(var o=arguments.length,r=Array(1<o?o-1:0),i=1;i<o;i++)r[i-1]=arguments[i];let[e,t]=r;"function"==typeof e&&(t=e,e=""),s({key:n,scope:e,method:t,splitKey:"+"})}},keyMap:o,modifier:m,modifierMap:p};for(const r in n)Object.prototype.hasOwnProperty.call(n,r)&&(C[r]=n[r]);if("undefined"!=typeof window){const l=window.hotkeys;C.noConflict=e=>(e&&window.hotkeys===C&&(window.hotkeys=l),C),window.hotkeys=C}return C});
/*! hotkeys-js v3.13.2 | MIT © 2023 kenny wong <wowohoo@qq.com> https://jaywcjlove.github.io/hotkeys-js */
!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 y(e,t,n,o){e.addEventListener?e.addEventListener(t,n,o):e.attachEvent&&e.attachEvent("on".concat(t),()=>{n(window.event)})}function u(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 h(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}const 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},m={"\u21e7":16,shift:16,"\u2325":18,alt:18,option:18,"\u2303":17,ctrl:17,control:17,"\u2318":91,cmd:91,command:91},p={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},k={};for(let e=1;e<20;e++)o["f".concat(e)]=111+e;let w=[],v=!1,t="all";const O=[],K=e=>o[e.toLowerCase()]||m[e.toLowerCase()]||e.toUpperCase().charCodeAt(0);function i(e){t=e||"all"}function d(){return t||"all"}function b(n){if(void 0===n)Object.keys(k).forEach(e=>delete k[e]);else if(Array.isArray(n))n.forEach(e=>{e.key&&s(e)});else if("object"==typeof n)n.key&&s(n);else if("string"==typeof n){for(var o=arguments.length,r=Array(1<o?o-1:0),i=1;i<o;i++)r[i-1]=arguments[i];let[e,t]=r;"function"==typeof e&&(t=e,e=""),s({key:n,scope:e,method:t,splitKey:"+"})}}const s=e=>{let{key:t,scope:r,method:i,splitKey:s="+"}=e;h(t).forEach(e=>{var e=e.split(s),t=e.length,n=e[t-1],n="*"===n?"*":K(n);if(k[n]){r=r||d();const o=1<t?u(m,e):[];k[n]=k[n].filter(e=>{return!((!i||e.method===i)&&e.scope===r&&function(e,t){var n=e.length<t.length?t:e,o=e.length<t.length?e:t;let r=!0;for(let e=0;e<n.length;e++)~o.indexOf(n[e])||(r=!1);return r}(e.mods,o))})}})};function x(t,n,o,e){if(n.element===e){let e;if(n.scope===o||"all"===n.scope){e=0<n.mods.length;for(const r in g)Object.prototype.hasOwnProperty.call(g,r)&&(!g[r]&&~n.mods.indexOf(+r)||g[r]&&!~n.mods.indexOf(+r))&&(e=!1);(0!==n.mods.length||g[16]||g[18]||g[17]||g[91])&&!e&&"*"!==n.shortcut||(n.keys=[],n.keys=n.keys.concat(w),!1===n.method(t,n)&&(t.preventDefault?t.preventDefault():t.returnValue=!1,t.stopPropagation&&t.stopPropagation(),t.cancelBubble)&&(t.cancelBubble=!0))}}}function C(n,t){var o=k["*"];let r=n.keyCode||n.which||n.charCode;if(E.filter.call(this,n)){if(93!==r&&224!==r||(r=91),~w.indexOf(r)||229===r||w.push(r),["ctrlKey","altKey","shiftKey","metaKey"].forEach(e=>{var t=p[e];n[e]&&!~w.indexOf(t)?w.push(t):!n[e]&&~w.indexOf(t)?w.splice(w.indexOf(t),1):"metaKey"!==e||!n[e]||3!==w.length||n.ctrlKey||n.shiftKey||n.altKey||(w=w.slice(w.indexOf(t)))}),r in g){g[r]=!0;for(const e in m)m[e]===r&&(E[e]=!0);if(!o)return}for(const a in g)Object.prototype.hasOwnProperty.call(g,a)&&(g[a]=n[p[a]]);n.getModifierState&&(!n.altKey||n.ctrlKey)&&n.getModifierState("AltGraph")&&(~w.indexOf(17)||w.push(17),~w.indexOf(18)||w.push(18),g[17]=!0,g[18]=!0);var i=d();if(o)for(let e=0;e<o.length;e++)o[e].scope===i&&("keydown"===n.type&&o[e].keydown||"keyup"===n.type&&o[e].keyup)&&x(n,o[e],i,t);if(r in k)for(let e=0;e<k[r].length;e++)if(("keydown"===n.type&&k[r][e].keydown||"keyup"===n.type&&k[r][e].keyup)&&k[r][e].key){var s=k[r][e],l=s["splitKey"],c=s.key.split(l),f=[];for(let e=0;e<c.length;e++)f.push(K(c[e]));f.sort().join("")===w.sort().join("")&&x(n,s,i,t)}}}function E(e,t,n){w=[];var o=h(e);let r=[],i="all",s=document,l=0,c=!1,f=!0,a="+",p=!1,d=!1;for(void 0===n&&"function"==typeof t&&(n=t),"[object Object]"===Object.prototype.toString.call(t)&&(t.scope&&(i=t.scope),t.element&&(s=t.element),t.keyup&&(c=t.keyup),void 0!==t.keydown&&(f=t.keydown),void 0!==t.capture&&(p=t.capture),"string"==typeof t.splitKey&&(a=t.splitKey),!0===t.single)&&(d=!0),"string"==typeof t&&(i=t),d&&b(e,i);l<o.length;l++)e=o[l].split(a),r=[],1<e.length&&(r=u(m,e)),(e="*"===(e=e[e.length-1])?"*":K(e))in k||(k[e]=[]),k[e].push({keyup:c,keydown:f,scope:i,mods:r,shortcut:o[l],method:n,key:o[l],splitKey:a,element:s});void 0!==s&&(t=s,!~O.indexOf(t))&&window&&(O.push(s),y(s,"keydown",e=>{C(e,s)},p),v||(v=!0,y(window,"focus",()=>{w=[]},p)),y(s,"keyup",t=>{C(t,s);{let e=t.keyCode||t.which||t.charCode;var n=w.indexOf(e);if(n<0||w.splice(n,1),t.key&&"meta"==t.key.toLowerCase()&&w.splice(0,w.length),(e=93!==e&&224!==e?e:91)in g){g[e]=!1;for(const o in m)m[o]===e&&(E[o]=!1)}}},p))}var n={getPressedKeyString:function(){return w.map(e=>{return n=e,Object.keys(o).find(e=>o[e]===n)||(t=e,Object.keys(m).find(e=>m[e]===t))||String.fromCharCode(e);var t,n})},setScope:i,getScope:d,deleteScope:function(e,t){var n;let o;e=e||d();for(const r in k)if(Object.prototype.hasOwnProperty.call(k,r))for(n=k[r],o=0;o<n.length;)n[o].scope===e?n.splice(o,1):o++;d()===e&&i(t||"all")},getPressedKeyCodes:function(){return w.slice(0)},getAllKeyCodes:function(){const r=[];return Object.keys(k).forEach(e=>{k[e].forEach(e=>{var{key:e,scope:t,mods:n,shortcut:o}=e;r.push({scope:t,shortcut:o,mods:n,keys:e.split("+").map(e=>K(e))})})}),r},isPressed:function(e){return"string"==typeof e&&(e=K(e)),!!~w.indexOf(e)},filter:function(e){var t=(e=e.target||e.srcElement)["tagName"];let n=!e.isContentEditable&&("INPUT"!==t&&"TEXTAREA"!==t&&"SELECT"!==t||e.readOnly)?!0:!1;return n},trigger:function(t){let n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"all";Object.keys(k).forEach(e=>{k[e].filter(e=>e.scope===n&&e.shortcut===t).forEach(e=>{e&&e.method&&e.method()})})},unbind:b,keyMap:o,modifier:m,modifierMap:p};for(const r in n)Object.prototype.hasOwnProperty.call(n,r)&&(E[r]=n[r]);if("undefined"!=typeof window){const l=window.hotkeys;E.noConflict=e=>(e&&window.hotkeys===E&&(window.hotkeys=l),E),window.hotkeys=E}return E});
{
"name": "hotkeys-js",
"description": "A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.",
"version": "3.13.1",
"version": "3.13.2",
"main": "index.js",

@@ -6,0 +6,0 @@ "types": "index.d.ts",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc