/**! * hotkeys-js v3.11.2 * A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies. * * Copyright (c) 2023 kenny wong * https://jaywcjlove.github.io/hotkeys-js * Licensed under the MIT license */ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var isff = typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase().indexOf('firefox') > 0 : false; // 绑定事件 function addEvent(object, event, method, useCapture) { if (object.addEventListener) { object.addEventListener(event, method, useCapture); } else if (object.attachEvent) { object.attachEvent("on".concat(event), function () { method(window.event); }); } } // 修饰键转换成对应的键码 function getMods(modifier, key) { var mods = key.slice(0, key.length - 1); for (var i = 0; i < mods.length; i++) mods[i] = modifier[mods[i].toLowerCase()]; return mods; } // 处理传的key字符串转换成数组 function getKeys(key) { if (typeof key !== 'string') key = ''; key = key.replace(/\s/g, ''); // 匹配任何空白字符,包括空格、制表符、换页符等等 var keys = key.split(','); // 同时设置多个快捷键,以','分割 var index = keys.lastIndexOf(''); // 快捷键可能包含',',需特殊处理 for (; index >= 0;) { keys[index - 1] += ','; keys.splice(index, 1); index = keys.lastIndexOf(''); } return keys; } // 比较修饰键的数组 function compareArray(a1, a2) { var arr1 = a1.length >= a2.length ? a1 : a2; var arr2 = a1.length >= a2.length ? a2 : a1; var isIndex = true; for (var i = 0; i < arr1.length; i++) { if (arr2.indexOf(arr1[i]) === -1) isIndex = false; } return isIndex; } // Special Keys var _keyMap = { backspace: 8, '⌫': 8, tab: 9, clear: 12, enter: 13, '↩': 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, '⇪': 20, ',': 188, '.': 190, '/': 191, '`': 192, '-': isff ? 173 : 189, '=': isff ? 61 : 187, ';': isff ? 59 : 186, '\'': 222, '[': 219, ']': 221, '\\': 220 }; // Modifier Keys var _modifier = { // shiftKey '⇧': 16, shift: 16, // altKey '⌥': 18, alt: 18, option: 18, // ctrlKey '⌃': 17, ctrl: 17, control: 17, // metaKey '⌘': 91, cmd: 91, command: 91 }; var modifierMap = { 16: 'shiftKey', 18: 'altKey', 17: 'ctrlKey', 91: 'metaKey', shiftKey: 16, ctrlKey: 17, altKey: 18, metaKey: 91 }; var _mods = { 16: false, 18: false, 17: false, 91: false }; var _handlers = {}; // F1~F12 special key for (var k = 1; k < 20; k++) { _keyMap["f".concat(k)] = 111 + k; } var _downKeys = []; // 记录摁下的绑定键 var winListendFocus = false; // window是否已经监听了focus事件 var _scope = 'all'; // 默认热键范围 var elementHasBindEvent = []; // 已绑定事件的节点记录 // 返回键码 var code = function code(x) { 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; }); }; // 设置获取当前范围(默认为'所有') function setScope(scope) { _scope = scope || 'all'; } // 获取当前范围 function getScope() { return _scope || 'all'; } // 获取摁下绑定键的键值 function getPressedKeyCodes() { return _downKeys.slice(0); } function getPressedKeyString() { return _downKeys.map(function (c) { return getKey(c) || getModifier(c) || String.fromCharCode(c); }); } function getAllKeyCodes() { var _ref; return (_ref = []).concat.apply(_ref, _toConsumableArray(Object.values(_handlers))).map(function (_ref2) { var key = _ref2.key, scope = _ref2.scope, mods = _ref2.mods, shortcut = _ref2.shortcut; return { scope: scope, shortcut: shortcut, mods: mods, keys: key.split('+').map(function (k) { return code(k); }) }; }); } // 表单控件控件判断 返回 Boolean // hotkey is effective only when filter return true function filter(event) { var target = event.target || event.srcElement; var tagName = target.tagName; var flag = true; // ignore: isContentEditable === 'true', and