import { isShadowRoot as i, isHTMLElement as s } from "../../../../../../../@floating-ui_utils@0.2.10/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.js";
import { isJSDOM as c } from "../../../../../../../@base-ui_utils@0.2.4_@types_react@18.3.27_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@base-ui/utils/esm/detectBrowser.js";
import { FOCUSABLE_ATTRIBUTE as u, TYPEABLE_SELECTOR as a } from "./constants.js";
function h(t) {
  var e;
  let r = t.activeElement;
  for (; ((e = r == null ? void 0 : r.shadowRoot) == null ? void 0 : e.activeElement) != null; )
    r = r.shadowRoot.activeElement;
  return r;
}
function E(t, r) {
  var n;
  if (!t || !r)
    return !1;
  const e = (n = r.getRootNode) == null ? void 0 : n.call(r);
  if (t.contains(r))
    return !0;
  if (e && i(e)) {
    let o = r;
    for (; o; ) {
      if (t === o)
        return !0;
      o = o.parentNode || o.host;
    }
  }
  return !1;
}
function T(t) {
  return "composedPath" in t ? t.composedPath()[0] : t.target;
}
function p(t, r) {
  if (r == null)
    return !1;
  if ("composedPath" in t)
    return t.composedPath().includes(r);
  const e = t;
  return e.target != null && r.contains(e.target);
}
function g(t) {
  return t.matches("html,body");
}
function R(t) {
  return (t == null ? void 0 : t.ownerDocument) || document;
}
function f(t) {
  return s(t) && t.matches(a);
}
function w(t) {
  return t ? t.getAttribute("role") === "combobox" && f(t) : !1;
}
function A(t) {
  if (!t || c)
    return !0;
  try {
    return t.matches(":focus-visible");
  } catch {
    return !0;
  }
}
function y(t) {
  return t ? t.hasAttribute(u) ? t : t.querySelector(`[${u}]`) || t : null;
}
export {
  h as activeElement,
  E as contains,
  R as getDocument,
  y as getFloatingFocusElement,
  T as getTarget,
  p as isEventTargetWithin,
  g as isRootElement,
  w as isTypeableCombobox,
  f as isTypeableElement,
  A as matchesFocusVisible
};
