import { isHTMLElement as E } from "../../utils/is-html-element.es.js";
import { isDragActive as v } from "../drag/state/is-active.es.js";
import { isNodeOrChild as L } from "../utils/is-node-or-child.es.js";
import { isPrimaryPointer as g } from "../utils/is-primary-pointer.es.js";
import { setupGesture as T } from "../utils/setup.es.js";
import { isElementKeyboardAccessible as h } from "./utils/is-keyboard-accessible.es.js";
import { enableKeyboardPress as y } from "./utils/keyboard.es.js";
import { isPressing as d } from "./utils/state.es.js";
function m(s) {
  return g(s) && !v();
}
const p = /* @__PURE__ */ new WeakSet();
function H(s, l, o = {}) {
  const [u, i, w] = T(s, o), P = (e) => {
    const n = e.currentTarget;
    if (!m(e) || p.has(e))
      return;
    d.add(n), o.stopPropagation && p.add(e);
    const t = l(n, e), a = (r, b) => {
      window.removeEventListener("pointerup", c), window.removeEventListener("pointercancel", f), d.has(n) && d.delete(n), m(r) && typeof t == "function" && t(r, { success: b });
    }, c = (r) => {
      a(r, n === window || n === document || o.useGlobalTarget || L(n, r.target));
    }, f = (r) => {
      a(r, !1);
    };
    window.addEventListener("pointerup", c, i), window.addEventListener("pointercancel", f, i);
  };
  return u.forEach((e) => {
    (o.useGlobalTarget ? window : e).addEventListener("pointerdown", P, i), E(e) && (e.addEventListener("focus", (t) => y(t, i)), !h(e) && !e.hasAttribute("tabindex") && (e.tabIndex = 0));
  }), w;
}
export {
  H as press
};
//# sourceMappingURL=index.es.js.map
