const e = "undefined" != typeof navigator && navigator.userAgent.toLowerCase().indexOf("firefox") > 0;
function t(e2, t2, n2, o2) {
  e2.addEventListener ? e2.addEventListener(t2, n2, o2) : e2.attachEvent && e2.attachEvent("on".concat(t2), n2);
}
function n(e2, t2, n2, o2) {
  e2.removeEventListener ? e2.removeEventListener(t2, n2, o2) : e2.detachEvent && e2.detachEvent("on".concat(t2), n2);
}
function o(e2, t2) {
  const n2 = t2.slice(0, t2.length - 1);
  for (let t3 = 0; t3 < n2.length; t3++)
    n2[t3] = e2[n2[t3].toLowerCase()];
  return n2;
}
function r(e2) {
  "string" != typeof e2 && (e2 = "");
  const t2 = (e2 = e2.replace(/\s/g, "")).split(",");
  let n2 = t2.lastIndexOf("");
  for (; n2 >= 0; )
    t2[n2 - 1] += ",", t2.splice(n2, 1), n2 = t2.lastIndexOf("");
  return t2;
}
const c = { 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, arrowup: 38, arrowdown: 40, arrowleft: 37, arrowright: 39, 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, "-": e ? 173 : 189, "=": e ? 61 : 187, ";": e ? 59 : 186, "'": 222, "{": 219, "}": 221, "[": 219, "]": 221, "\\": 220 }, s = { "⇧": 16, shift: 16, "⌥": 18, alt: 18, option: 18, "⌃": 17, ctrl: 17, control: 17, "⌘": 91, cmd: 91, meta: 91, command: 91 }, i = { 16: "shiftKey", 18: "altKey", 17: "ctrlKey", 91: "metaKey", shiftKey: 16, ctrlKey: 17, altKey: 18, metaKey: 91 }, l = { 16: false, 18: false, 17: false, 91: false }, a = {};
for (let e2 = 1; e2 < 20; e2++)
  c["f".concat(e2)] = 111 + e2;
let f = [], p = null, u = "all";
const y = /* @__PURE__ */ new Map(), d = (e2) => c[e2.toLowerCase()] || s[e2.toLowerCase()] || e2.toUpperCase().charCodeAt(0);
function h(e2) {
  u = e2 || "all";
}
function k() {
  return u || "all";
}
function m(e2) {
  if (void 0 === e2)
    Object.keys(a).forEach((e3) => {
      Array.isArray(a[e3]) && a[e3].forEach((e4) => w(e4)), delete a[e3];
    }), v(null);
  else if (Array.isArray(e2))
    e2.forEach((e3) => {
      e3.key && w(e3);
    });
  else if ("object" == typeof e2)
    e2.key && w(e2);
  else if ("string" == typeof e2) {
    for (var t2 = arguments.length, n2 = new Array(t2 > 1 ? t2 - 1 : 0), o2 = 1; o2 < t2; o2++)
      n2[o2 - 1] = arguments[o2];
    let [r2, c2] = n2;
    "function" == typeof r2 && (c2 = r2, r2 = ""), w({ key: e2, scope: r2, method: c2, splitKey: "+" });
  }
}
const w = (e2) => {
  let { key: t2, scope: n2, method: c2, splitKey: i2 = "+" } = e2;
  r(t2).forEach((e3) => {
    const t3 = e3.split(i2), r2 = t3.length, l2 = t3[r2 - 1], f2 = "*" === l2 ? "*" : d(l2);
    if (!a[f2])
      return;
    n2 || (n2 = k());
    const p2 = r2 > 1 ? o(s, t3) : [], u2 = [];
    a[f2] = a[f2].filter((e4) => {
      const t4 = (!c2 || e4.method === c2) && e4.scope === n2 && function(e5, t5) {
        const n3 = e5.length >= t5.length ? e5 : t5, o2 = e5.length >= t5.length ? t5 : e5;
        let r3 = true;
        for (let e6 = 0; e6 < n3.length; e6++)
          -1 === o2.indexOf(n3[e6]) && (r3 = false);
        return r3;
      }(e4.mods, p2);
      return t4 && u2.push(e4.element), !t4;
    }), u2.forEach((e4) => v(e4));
  });
};
function g(e2, t2, n2, o2) {
  if (t2.element !== o2)
    return;
  let r2;
  if (t2.scope === n2 || "all" === t2.scope) {
    r2 = t2.mods.length > 0;
    for (const e3 in l)
      Object.prototype.hasOwnProperty.call(l, e3) && (!l[e3] && t2.mods.indexOf(+e3) > -1 || l[e3] && -1 === t2.mods.indexOf(+e3)) && (r2 = false);
    (0 !== t2.mods.length || l[16] || l[18] || l[17] || l[91]) && !r2 && "*" !== t2.shortcut || (t2.keys = [], t2.keys = t2.keys.concat(f), false === t2.method(e2, t2) && (e2.preventDefault ? e2.preventDefault() : e2.returnValue = false, e2.stopPropagation && e2.stopPropagation(), e2.cancelBubble && (e2.cancelBubble = true)));
  }
}
function O(e2, t2) {
  const n2 = a["*"];
  let o2 = e2.keyCode || e2.which || e2.charCode;
  if (e2.key && "capslock" === e2.key.toLowerCase())
    return;
  if (!b.filter.call(this, e2))
    return;
  if (93 !== o2 && 224 !== o2 || (o2 = 91), -1 === f.indexOf(o2) && 229 !== o2 && f.push(o2), ["metaKey", "ctrlKey", "altKey", "shiftKey"].forEach((t3) => {
    const n3 = i[t3];
    e2[t3] && -1 === f.indexOf(n3) ? f.push(n3) : !e2[t3] && f.indexOf(n3) > -1 ? f.splice(f.indexOf(n3), 1) : "metaKey" === t3 && e2[t3] && (f = f.filter((e3) => e3 in i || e3 === o2));
  }), o2 in l) {
    l[o2] = true;
    for (const t3 in s)
      if (Object.prototype.hasOwnProperty.call(s, t3)) {
        const n3 = i[s[t3]];
        b[t3] = e2[n3];
      }
    if (!n2)
      return;
  }
  for (const t3 in l)
    Object.prototype.hasOwnProperty.call(l, t3) && (l[t3] = e2[i[t3]]);
  e2.getModifierState && (!e2.altKey || e2.ctrlKey) && e2.getModifierState("AltGraph") && (-1 === f.indexOf(17) && f.push(17), -1 === f.indexOf(18) && f.push(18), l[17] = true, l[18] = true);
  const r2 = k();
  if (n2)
    for (let o3 = 0; o3 < n2.length; o3++)
      n2[o3].scope === r2 && ("keydown" === e2.type && n2[o3].keydown || "keyup" === e2.type && n2[o3].keyup) && g(e2, n2[o3], r2, t2);
  if (!(o2 in a))
    return;
  const c2 = a[o2], p2 = c2.length;
  for (let n3 = 0; n3 < p2; n3++)
    if (("keydown" === e2.type && c2[n3].keydown || "keyup" === e2.type && c2[n3].keyup) && c2[n3].key) {
      const o3 = c2[n3], { splitKey: s2 } = o3, i2 = o3.key.split(s2), l2 = [];
      for (let e3 = 0; e3 < i2.length; e3++)
        l2.push(d(i2[e3]));
      l2.sort().join("") === f.sort().join("") && g(e2, o3, r2, t2);
    }
}
function b(e2, n2, c2) {
  f = [];
  const i2 = r(e2);
  let u2 = [], h2 = "all", k2 = document, w2 = 0, g2 = false, v2 = true, E2 = "+", K = false, C = false;
  for (void 0 === c2 && "function" == typeof n2 && (c2 = n2), "[object Object]" === Object.prototype.toString.call(n2) && (n2.scope && (h2 = n2.scope), n2.element && (k2 = n2.element), n2.keyup && (g2 = n2.keyup), void 0 !== n2.keydown && (v2 = n2.keydown), void 0 !== n2.capture && (K = n2.capture), "string" == typeof n2.splitKey && (E2 = n2.splitKey), true === n2.single && (C = true)), "string" == typeof n2 && (h2 = n2), C && m(e2, h2); w2 < i2.length; w2++)
    u2 = [], (e2 = i2[w2].split(E2)).length > 1 && (u2 = o(s, e2)), (e2 = "*" === (e2 = e2[e2.length - 1]) ? "*" : d(e2)) in a || (a[e2] = []), a[e2].push({ keyup: g2, keydown: v2, scope: h2, mods: u2, shortcut: i2[w2], method: c2, key: i2[w2], splitKey: E2, element: k2 });
  if (void 0 !== k2 && window) {
    if (!y.has(k2)) {
      const e3 = function() {
        return O(arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : window.event, k2);
      }, n3 = function() {
        let e4 = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : window.event;
        O(e4, k2), function(e5) {
          let t2 = e5.keyCode || e5.which || e5.charCode;
          e5.key && "capslock" === e5.key.toLowerCase() && (t2 = d(e5.key));
          const n4 = f.indexOf(t2);
          if (n4 >= 0 && f.splice(n4, 1), e5.key && "meta" === e5.key.toLowerCase() && f.splice(0, f.length), 93 !== t2 && 224 !== t2 || (t2 = 91), t2 in l) {
            l[t2] = false;
            for (const e6 in s)
              s[e6] === t2 && (b[e6] = false);
          }
        }(e4);
      };
      y.set(k2, { keydownListener: e3, keyupListenr: n3, capture: K }), t(k2, "keydown", e3, K), t(k2, "keyup", n3, K);
    }
    if (!p) {
      const e3 = () => {
        f = [];
      };
      p = { listener: e3, capture: K }, t(window, "focus", e3, K);
    }
  }
}
function v(e2) {
  const t2 = Object.values(a).flat();
  if (t2.findIndex((t3) => {
    let { element: n2 } = t3;
    return n2 === e2;
  }) < 0) {
    const { keydownListener: t3, keyupListenr: o2, capture: r2 } = y.get(e2) || {};
    t3 && o2 && (n(e2, "keyup", o2, r2), n(e2, "keydown", t3, r2), y.delete(e2));
  }
  if (t2.length <= 0 || y.size <= 0) {
    if (Object.keys(y).forEach((e3) => {
      const { keydownListener: t3, keyupListenr: o2, capture: r2 } = y.get(e3) || {};
      t3 && o2 && (n(e3, "keyup", o2, r2), n(e3, "keydown", t3, r2), y.delete(e3));
    }), y.clear(), Object.keys(a).forEach((e3) => delete a[e3]), p) {
      const { listener: e3, capture: t3 } = p;
      n(window, "focus", e3, t3), p = null;
    }
  }
}
const E = { getPressedKeyString: function() {
  return f.map((e2) => {
    return t2 = e2, Object.keys(c).find((e3) => c[e3] === t2) || ((e3) => Object.keys(s).find((t3) => s[t3] === e3))(e2) || String.fromCharCode(e2);
    var t2;
  });
}, setScope: h, getScope: k, deleteScope: function(e2, t2) {
  let n2, o2;
  e2 || (e2 = k());
  for (const t3 in a)
    if (Object.prototype.hasOwnProperty.call(a, t3))
      for (n2 = a[t3], o2 = 0; o2 < n2.length; )
        if (n2[o2].scope === e2) {
          n2.splice(o2, 1).forEach((e3) => {
            let { element: t4 } = e3;
            return v(t4);
          });
        } else
          o2++;
  k() === e2 && h(t2 || "all");
}, getPressedKeyCodes: function() {
  return f.slice(0);
}, getAllKeyCodes: function() {
  const e2 = [];
  return Object.keys(a).forEach((t2) => {
    a[t2].forEach((t3) => {
      let { key: n2, scope: o2, mods: r2, shortcut: c2 } = t3;
      e2.push({ scope: o2, shortcut: c2, mods: r2, keys: n2.split("+").map((e3) => d(e3)) });
    });
  }), e2;
}, isPressed: function(e2) {
  return "string" == typeof e2 && (e2 = d(e2)), -1 !== f.indexOf(e2);
}, filter: function(e2) {
  const t2 = e2.target || e2.srcElement, { tagName: n2 } = t2;
  let o2 = true;
  const r2 = "INPUT" === n2 && !["checkbox", "radio", "range", "button", "file", "reset", "submit", "color"].includes(t2.type);
  return (t2.isContentEditable || (r2 || "TEXTAREA" === n2 || "SELECT" === n2) && !t2.readOnly) && (o2 = false), o2;
}, trigger: function(e2) {
  let t2 = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "all";
  Object.keys(a).forEach((n2) => {
    a[n2].filter((n3) => n3.scope === t2 && n3.shortcut === e2).forEach((e3) => {
      e3 && e3.method && e3.method();
    });
  });
}, unbind: m, keyMap: c, modifier: s, modifierMap: i };
for (const e2 in E)
  Object.prototype.hasOwnProperty.call(E, e2) && (b[e2] = E[e2]);
if ("undefined" != typeof window) {
  const e2 = window.hotkeys;
  b.noConflict = (t2) => (t2 && window.hotkeys === b && (window.hotkeys = e2), b), window.hotkeys = b;
}
export {
  b as h
};
