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