import { j as i, $ as p, k as v } from "./utils-V7nfNEif.es.js";
import { $ as E, b as m, c as k } from "./openLink-m90p5mer.es.js";
import { useEffect as y, useState as M } from "react";
import { $ as H } from "./SSRProvider-CQ9PmFV6.es.js";
function O(e) {
  return e.pointerType === "" && e.isTrusted ? !0 : E() && e.pointerType ? e.type === "click" && e.buttons === 1 : e.detail === 0 && !e.pointerType;
}
function P(e) {
  return !E() && e.width === 0 && e.height === 0 || e.width === 1 && e.height === 1 && e.pressure === 0 && e.detail === 0 && e.pointerType === "mouse";
}
let a = null, u = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Map(), f = !1, l = !1;
const I = {
  Tab: !0,
  Escape: !0
};
function s(e, r) {
  for (let t of u) t(e, r);
}
function K(e) {
  return !(e.metaKey || !k() && e.altKey || e.ctrlKey || e.key === "Control" || e.key === "Shift" || e.key === "Meta");
}
function c(e) {
  f = !0, !m.isOpening && K(e) && (a = "keyboard", s("keyboard", e));
}
function o(e) {
  a = "pointer", "pointerType" in e && e.pointerType, (e.type === "mousedown" || e.type === "pointerdown") && (f = !0, s("pointer", e));
}
function L(e) {
  !m.isOpening && O(e) && (f = !0, a = "virtual");
}
function w(e) {
  e.target === window || e.target === document || v || !e.isTrusted || (!f && !l && (a = "virtual", s("virtual", e)), f = !1, l = !1);
}
function T() {
  v || (f = !1, l = !0);
}
function h(e) {
  if (typeof window > "u" || typeof document > "u" || d.get(i(e))) return;
  const r = i(e), t = p(e);
  let n = r.HTMLElement.prototype.focus;
  r.HTMLElement.prototype.focus = function() {
    f = !0, n.apply(this, arguments);
  }, t.addEventListener("keydown", c, !0), t.addEventListener("keyup", c, !0), t.addEventListener("click", L, !0), r.addEventListener("focus", w, !0), r.addEventListener("blur", T, !1), typeof PointerEvent < "u" ? (t.addEventListener("pointerdown", o, !0), t.addEventListener("pointermove", o, !0), t.addEventListener("pointerup", o, !0)) : process.env.NODE_ENV === "test" && (t.addEventListener("mousedown", o, !0), t.addEventListener("mousemove", o, !0), t.addEventListener("mouseup", o, !0)), r.addEventListener("beforeunload", () => {
    S(e);
  }, {
    once: !0
  }), d.set(r, {
    focus: n
  });
}
const S = (e, r) => {
  const t = i(e), n = p(e);
  r && n.removeEventListener("DOMContentLoaded", r), d.has(t) && (t.HTMLElement.prototype.focus = d.get(t).focus, n.removeEventListener("keydown", c, !0), n.removeEventListener("keyup", c, !0), n.removeEventListener("click", L, !0), t.removeEventListener("focus", w, !0), t.removeEventListener("blur", T, !1), typeof PointerEvent < "u" ? (n.removeEventListener("pointerdown", o, !0), n.removeEventListener("pointermove", o, !0), n.removeEventListener("pointerup", o, !0)) : process.env.NODE_ENV === "test" && (n.removeEventListener("mousedown", o, !0), n.removeEventListener("mousemove", o, !0), n.removeEventListener("mouseup", o, !0)), d.delete(t));
};
function C() {
  return a !== "pointer";
}
function V() {
  return a;
}
function A(e) {
  a = e, s(e, null);
}
function W() {
  h();
  let [e, r] = M(a);
  return y(() => {
    let t = () => {
      r(a);
    };
    return u.add(t), () => {
      u.delete(t);
    };
  }, []), H() ? null : e;
}
const j = /* @__PURE__ */ new Set([
  "checkbox",
  "radio",
  "range",
  "color",
  "file",
  "image",
  "button",
  "submit",
  "reset"
]);
function F(e, r, t) {
  let n = p(t?.target);
  const $ = typeof window < "u" ? i(t?.target).HTMLInputElement : HTMLInputElement, b = typeof window < "u" ? i(t?.target).HTMLTextAreaElement : HTMLTextAreaElement, g = typeof window < "u" ? i(t?.target).HTMLElement : HTMLElement, x = typeof window < "u" ? i(t?.target).KeyboardEvent : KeyboardEvent;
  return e = e || n.activeElement instanceof $ && !j.has(n.activeElement.type) || n.activeElement instanceof b || n.activeElement instanceof g && n.activeElement.isContentEditable, !(e && r === "keyboard" && t instanceof x && !I[t.key]);
}
function U(e, r, t) {
  h(), y(() => {
    let n = ($, b) => {
      F(!!t?.isTextInput, $, b) && e(C());
    };
    return u.add(n), () => {
      u.delete(n);
    };
  }, r);
}
export {
  C as $,
  U as a,
  V as b,
  A as c,
  P as d,
  O as e,
  W as f
};
//# sourceMappingURL=useFocusVisible-_CKiSck5.es.js.map
