import { useState as T, useRef as P, useCallback as z, useLayoutEffect as G, useEffect as J, useContext as M, createContext as N } from "react";
import "../../../../../../_virtual/jsx-runtime.js";
function S() {
  return S = Object.assign ? Object.assign.bind() : function(e) {
    for (var t = 1; t < arguments.length; t++) {
      var r = arguments[t];
      for (var o in r) ({}).hasOwnProperty.call(r, o) && (e[o] = r[o]);
    }
    return e;
  }, S.apply(null, arguments);
}
var O = ["shift", "alt", "meta", "mod", "ctrl"], Q = {
  esc: "escape",
  return: "enter",
  ".": "period",
  ",": "comma",
  "-": "slash",
  " ": "space",
  "`": "backquote",
  "#": "backslash",
  "+": "bracketright",
  ShiftLeft: "shift",
  ShiftRight: "shift",
  AltLeft: "alt",
  AltRight: "alt",
  MetaLeft: "meta",
  MetaRight: "meta",
  OSLeft: "meta",
  OSRight: "meta",
  ControlLeft: "ctrl",
  ControlRight: "ctrl"
};
function d(e) {
  return (e && Q[e] || e || "").trim().toLowerCase().replace(/key|digit|numpad|arrow/, "");
}
function U(e) {
  return O.includes(e);
}
function H(e, t) {
  return t === void 0 && (t = ","), e.split(t);
}
function A(e, t, r) {
  t === void 0 && (t = "+");
  var o = e.toLocaleLowerCase().split(t).map(function(l) {
    return d(l);
  }), a = {
    alt: o.includes("alt"),
    ctrl: o.includes("ctrl") || o.includes("control"),
    shift: o.includes("shift"),
    meta: o.includes("meta"),
    mod: o.includes("mod")
  }, s = o.filter(function(l) {
    return !O.includes(l);
  });
  return S({}, a, {
    keys: s,
    description: r,
    hotkey: e
  });
}
(function() {
  typeof document < "u" && (document.addEventListener("keydown", function(e) {
    e.key !== void 0 && I([d(e.key), d(e.code)]);
  }), document.addEventListener("keyup", function(e) {
    e.key !== void 0 && q([d(e.key), d(e.code)]);
  })), typeof window < "u" && window.addEventListener("blur", function() {
    y.clear();
  });
})();
var y = /* @__PURE__ */ new Set();
function R(e) {
  return Array.isArray(e);
}
function V(e, t) {
  t === void 0 && (t = ",");
  var r = R(e) ? e : e.split(t);
  return r.every(function(o) {
    return y.has(o.trim().toLowerCase());
  });
}
function I(e) {
  var t = Array.isArray(e) ? e : [e];
  y.has("meta") && y.forEach(function(r) {
    return !U(r) && y.delete(r.toLowerCase());
  }), t.forEach(function(r) {
    return y.add(r.toLowerCase());
  });
}
function q(e) {
  var t = Array.isArray(e) ? e : [e];
  e === "meta" ? y.clear() : t.forEach(function(r) {
    return y.delete(r.toLowerCase());
  });
}
function X(e, t, r) {
  (typeof r == "function" && r(e, t) || r === !0) && e.preventDefault();
}
function Y(e, t, r) {
  return typeof r == "function" ? r(e, t) : r === !0 || r === void 0;
}
function Z(e) {
  return W(e, ["input", "textarea", "select"]);
}
function W(e, t) {
  t === void 0 && (t = !1);
  var r = e.target, o = e.composed, a = null;
  return ee(r) && o ? a = e.composedPath()[0] && e.composedPath()[0].tagName : a = r && r.tagName, R(t) ? !!(a && t && t.some(function(s) {
    var l;
    return s.toLowerCase() === ((l = a) == null ? void 0 : l.toLowerCase());
  })) : !!(a && t && t);
}
function ee(e) {
  return !!e.tagName && !e.tagName.startsWith("-") && e.tagName.includes("-");
}
function te(e, t) {
  return e.length === 0 && t ? (console.warn('A hotkey has the "scopes" option set, however no active scopes were found. If you want to use the global scopes feature, you need to wrap your app in a <HotkeysProvider>'), !0) : t ? e.some(function(r) {
    return t.includes(r);
  }) || e.includes("*") : !0;
}
var ne = function(t, r, o) {
  o === void 0 && (o = !1);
  var a = r.alt, s = r.meta, l = r.mod, h = r.shift, v = r.ctrl, u = r.keys, g = t.key, w = t.code, m = t.ctrlKey, n = t.metaKey, K = t.shiftKey, E = t.altKey, c = d(w), f = g.toLowerCase();
  if (!(u != null && u.includes(c)) && !(u != null && u.includes(f)) && !["ctrl", "control", "unknown", "meta", "alt", "shift", "os"].includes(c))
    return !1;
  if (!o) {
    if (a === !E && f !== "alt" || h === !K && f !== "shift")
      return !1;
    if (l) {
      if (!n && !m)
        return !1;
    } else if (s === !n && f !== "meta" && f !== "os" || v === !m && f !== "ctrl" && f !== "control")
      return !1;
  }
  return u && u.length === 1 && (u.includes(f) || u.includes(c)) ? !0 : u ? V(u) : !u;
}, re = /* @__PURE__ */ N(void 0), oe = function() {
  return M(re);
};
function F(e, t) {
  return e && t && typeof e == "object" && typeof t == "object" ? Object.keys(e).length === Object.keys(t).length && //@ts-ignore
  Object.keys(e).reduce(function(r, o) {
    return r && F(e[o], t[o]);
  }, !0) : e === t;
}
var ie = /* @__PURE__ */ N({
  hotkeys: [],
  enabledScopes: [],
  toggleScope: function() {
  },
  enableScope: function() {
  },
  disableScope: function() {
  }
}), ue = function() {
  return M(ie);
};
function ae(e) {
  var t = P(void 0);
  return F(t.current, e) || (t.current = e), t.current;
}
var D = function(t) {
  t.stopPropagation(), t.preventDefault(), t.stopImmediatePropagation();
}, se = typeof window < "u" ? G : J;
function ce(e, t, r, o) {
  var a = T(null), s = a[0], l = a[1], h = P(!1), v = r instanceof Array ? o instanceof Array ? void 0 : o : r, u = R(e) ? e.join(v?.splitKey) : e, g = r instanceof Array ? r : o instanceof Array ? o : void 0, w = z(t, g ?? []), m = P(w);
  g ? m.current = w : m.current = t;
  var n = ae(v), K = ue(), E = K.enabledScopes, c = oe();
  return se(function() {
    if (!(n?.enabled === !1 || !te(E, n?.scopes))) {
      var f = function(i, b) {
        var x;
        if (b === void 0 && (b = !1), !(Z(i) && !W(i, n?.enableOnFormTags))) {
          if (s !== null) {
            var L = s.getRootNode();
            if ((L instanceof Document || L instanceof ShadowRoot) && L.activeElement !== s && !s.contains(L.activeElement)) {
              D(i);
              return;
            }
          }
          (x = i.target) != null && x.isContentEditable && !(n != null && n.enableOnContentEditable) || H(u, n?.splitKey).forEach(function($) {
            var B, k = A($, n?.combinationKey);
            if (ne(i, k, n?.ignoreModifiers) || (B = k.keys) != null && B.includes("*")) {
              if (n != null && n.ignoreEventWhen != null && n.ignoreEventWhen(i) || b && h.current)
                return;
              if (X(i, k, n?.preventDefault), !Y(i, k, n?.enabled)) {
                D(i);
                return;
              }
              m.current(i, k), b || (h.current = !0);
            }
          });
        }
      }, _ = function(i) {
        i.key !== void 0 && (I(d(i.code)), (n?.keydown === void 0 && n?.keyup !== !0 || n != null && n.keydown) && f(i));
      }, j = function(i) {
        i.key !== void 0 && (q(d(i.code)), h.current = !1, n != null && n.keyup && f(i, !0));
      }, C = s || v?.document || document;
      return C.addEventListener("keyup", j), C.addEventListener("keydown", _), c && H(u, n?.splitKey).forEach(function(p) {
        return c.addHotkey(A(p, n?.combinationKey, n?.description));
      }), function() {
        C.removeEventListener("keyup", j), C.removeEventListener("keydown", _), c && H(u, n?.splitKey).forEach(function(p) {
          return c.removeHotkey(A(p, n?.combinationKey, n?.description));
        });
      };
    }
  }, [s, u, n, E]), l;
}
export {
  V as isHotkeyPressed,
  ce as useHotkeys,
  ue as useHotkeysContext
};
//# sourceMappingURL=react-hotkeys-hook.esm.js.map
