import { $ as f, a as v, k as p } from "./utils-oAGBWzI5.es.js";
import { d as E, b as x } from "./platform-Z5fvtFmM.es.js";
import { useEffect as m, useState as k } from "react";
import { $ as M } from "./SSRProvider-eIEwc-2s.es.js";
function H(e) {
  return e.pointerType === "" && e.isTrusted ? !0 : E() && e.pointerType ? e.type === "click" && e.buttons === 1 : e.detail === 0 && !e.pointerType;
}
function B(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(), i = /* @__PURE__ */ new Map(), d = !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 || !x() && e.altKey || e.ctrlKey || e.key === "Control" || e.key === "Shift" || e.key === "Meta");
}
function c(e) {
  d = !0, K(e) && (a = "keyboard", s("keyboard", e));
}
function o(e) {
  a = "pointer", (e.type === "mousedown" || e.type === "pointerdown") && (d = !0, s("pointer", e));
}
function y(e) {
  H(e) && (d = !0, a = "virtual");
}
function L(e) {
  e.target === window || e.target === document || p || !e.isTrusted || (!d && !l && (a = "virtual", s("virtual", e)), d = !1, l = !1);
}
function w() {
  p || (d = !1, l = !0);
}
function T(e) {
  if (typeof window > "u" || typeof document > "u" || i.get(f(e))) return;
  const r = f(e), t = v(e);
  let n = r.HTMLElement.prototype.focus;
  r.HTMLElement.prototype.focus = function() {
    d = !0, n.apply(this, arguments);
  }, t.addEventListener("keydown", c, !0), t.addEventListener("keyup", c, !0), t.addEventListener("click", y, !0), r.addEventListener("focus", L, !0), r.addEventListener("blur", w, !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", () => {
    O(e);
  }, {
    once: !0
  }), i.set(r, {
    focus: n
  });
}
const O = (e, r) => {
  const t = f(e), n = v(e);
  r && n.removeEventListener("DOMContentLoaded", r), i.has(t) && (t.HTMLElement.prototype.focus = i.get(t).focus, n.removeEventListener("keydown", c, !0), n.removeEventListener("keyup", c, !0), n.removeEventListener("click", y, !0), t.removeEventListener("focus", L, !0), t.removeEventListener("blur", w, !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)), i.delete(t));
};
function S() {
  return a !== "pointer";
}
function P() {
  return a;
}
function V(e) {
  a = e, s(e, null);
}
function A() {
  T();
  let [e, r] = k(a);
  return m(() => {
    let t = () => {
      r(a);
    };
    return u.add(t), () => {
      u.delete(t);
    };
  }, []), M() ? null : e;
}
const C = /* @__PURE__ */ new Set([
  "checkbox",
  "radio",
  "range",
  "color",
  "file",
  "image",
  "button",
  "submit",
  "reset"
]);
function F(e, r, t) {
  let n = v(t?.target);
  const $ = typeof window < "u" ? f(t?.target).HTMLInputElement : HTMLInputElement, b = typeof window < "u" ? f(t?.target).HTMLTextAreaElement : HTMLTextAreaElement, h = typeof window < "u" ? f(t?.target).HTMLElement : HTMLElement, g = typeof window < "u" ? f(t?.target).KeyboardEvent : KeyboardEvent;
  return e = e || n.activeElement instanceof $ && !C.has(n.activeElement.type) || n.activeElement instanceof b || n.activeElement instanceof h && n.activeElement.isContentEditable, !(e && r === "keyboard" && t instanceof g && !I[t.key]);
}
function W(e, r, t) {
  T(), m(() => {
    let n = ($, b) => {
      F(!!t?.isTextInput, $, b) && e(S());
    };
    return u.add(n), () => {
      u.delete(n);
    };
  }, r);
}
export {
  S as $,
  W as a,
  P as b,
  V as c,
  B as d,
  H as e,
  A as f
};
//# sourceMappingURL=useFocusVisible-B3HmFL2Q.es.js.map
