import { a as O, f as ge, g as ve, b as p, e as c, l as j, $ as N } from "./utils-oAGBWzI5.es.js";
import { a as Te } from "./focusSafely-Cwb0Tyy6.es.js";
import { f as ae, b as $e } from "./platform-Z5fvtFmM.es.js";
import ye, { useState as Pe, useRef as be, useMemo as he, useEffect as W, useContext as Ee } from "react";
import { c as K, $ as oe, e as me } from "./mergeProps-Dsl8k3Ig.es.js";
import { $ as Se } from "./focusWithoutScrolling-CDw3JYiq.es.js";
import { d as q } from "./openLink-BNz58j4a.es.js";
import { $ as xe } from "./useGlobalListeners-BOOfV5Wh.es.js";
import { $ as ke } from "./useSyncRef-BpLviItW.es.js";
import { d as Ke, e as J } from "./useFocusVisible-B3HmFL2Q.es.js";
import { flushSync as we } from "react-dom";
function Oe(r, n) {
  if (n.has(r))
    throw new TypeError("Cannot initialize the same private elements twice on an object");
}
function Me(r, n, a) {
  Oe(r, n), n.set(r, a);
}
let _ = "default", G = "", X = /* @__PURE__ */ new WeakMap();
function Q(r) {
  if (ae()) {
    if (_ === "default") {
      const n = O(r);
      G = n.documentElement.style.webkitUserSelect, n.documentElement.style.webkitUserSelect = "none";
    }
    _ = "disabled";
  } else if (r instanceof HTMLElement || r instanceof SVGElement) {
    let n = "userSelect" in r.style ? "userSelect" : "webkitUserSelect";
    X.set(r, r.style[n]), r.style[n] = "none";
  }
}
function H(r) {
  if (ae()) {
    if (_ !== "disabled") return;
    _ = "restoring", setTimeout(() => {
      Te(() => {
        if (_ === "restoring") {
          const n = O(r);
          n.documentElement.style.webkitUserSelect === "none" && (n.documentElement.style.webkitUserSelect = G || ""), G = "", _ = "default";
        }
      });
    }, 300);
  } else if ((r instanceof HTMLElement || r instanceof SVGElement) && r && X.has(r)) {
    let n = X.get(r), a = "userSelect" in r.style ? "userSelect" : "webkitUserSelect";
    r.style[a] === "none" && (r.style[a] = n), r.getAttribute("style") === "" && r.removeAttribute("style"), X.delete(r);
  }
}
const le = /* @__PURE__ */ ye.createContext({
  register: () => {
  }
});
le.displayName = "PressResponderContext";
function _e(r, n) {
  return n.get ? n.get.call(r) : n.value;
}
function fe(r, n, a) {
  if (!n.has(r)) throw new TypeError("attempted to " + a + " private field on non-instance");
  return n.get(r);
}
function Ce(r, n) {
  var a = fe(r, n, "get");
  return _e(r, a);
}
function Ie(r, n, a) {
  if (n.set) n.set.call(r, a);
  else {
    if (!n.writable)
      throw new TypeError("attempted to set read only private field");
    n.value = a;
  }
}
function Z(r, n, a) {
  var l = fe(r, n, "set");
  return Ie(r, l, a), a;
}
function Ue(r) {
  let n = Ee(le);
  if (n) {
    let { register: a, ...l } = n;
    r = oe(l, r), a();
  }
  return ke(n, r.ref), r;
}
var D = /* @__PURE__ */ new WeakMap();
class Y {
  continuePropagation() {
    Z(this, D, !1);
  }
  get shouldStopPropagation() {
    return Ce(this, D);
  }
  constructor(n, a, l, d) {
    Me(this, D, {
      writable: !0,
      value: void 0
    }), Z(this, D, !0);
    var P;
    let b = (P = d?.target) !== null && P !== void 0 ? P : l.currentTarget;
    const v = b?.getBoundingClientRect();
    let C, S = 0, I, T = null;
    l.clientX != null && l.clientY != null && (I = l.clientX, T = l.clientY), v && (I != null && T != null ? (C = I - v.left, S = T - v.top) : (C = v.width / 2, S = v.height / 2)), this.type = n, this.pointerType = a, this.target = l.currentTarget, this.shiftKey = l.shiftKey, this.metaKey = l.metaKey, this.ctrlKey = l.ctrlKey, this.altKey = l.altKey, this.x = C, this.y = S;
  }
}
const ee = /* @__PURE__ */ Symbol("linkClicked"), te = "react-aria-pressable-style", re = "data-react-aria-pressable";
function Je(r) {
  let { onPress: n, onPressChange: a, onPressStart: l, onPressEnd: d, onPressUp: P, onClick: b, isDisabled: v, isPressed: C, preventFocusOnPress: S, shouldCancelOnPointerExit: I, allowTextSelectionOnPress: T, ref: R, ...ce } = Ue(r), [pe, z] = Pe(!1), M = be({
    isPressed: !1,
    ignoreEmulatedMouseEvents: !1,
    didFirePressStart: !1,
    isTriggeringEvent: !1,
    activePointerId: null,
    target: null,
    isOverTarget: !1,
    pointerType: null,
    disposables: []
  }), { addGlobalListener: x, removeAllGlobalListeners: U } = xe(), h = K((e, s) => {
    let g = M.current;
    if (v || g.didFirePressStart) return !1;
    let i = !0;
    if (g.isTriggeringEvent = !0, l) {
      let u = new Y("pressstart", s, e);
      l(u), i = u.shouldStopPropagation;
    }
    return a && a(!0), g.isTriggeringEvent = !1, g.didFirePressStart = !0, z(!0), i;
  }), y = K((e, s, g = !0) => {
    let i = M.current;
    if (!i.didFirePressStart) return !1;
    i.didFirePressStart = !1, i.isTriggeringEvent = !0;
    let u = !0;
    if (d) {
      let t = new Y("pressend", s, e);
      d(t), u = t.shouldStopPropagation;
    }
    if (a && a(!1), z(!1), n && g && !v) {
      let t = new Y("press", s, e);
      n(t), u && (u = t.shouldStopPropagation);
    }
    return i.isTriggeringEvent = !1, u;
  }), k = K((e, s) => {
    let g = M.current;
    if (v) return !1;
    if (P) {
      g.isTriggeringEvent = !0;
      let i = new Y("pressup", s, e);
      return P(i), g.isTriggeringEvent = !1, i.shouldStopPropagation;
    }
    return !0;
  }), $ = K((e) => {
    let s = M.current;
    if (s.isPressed && s.target) {
      s.didFirePressStart && s.pointerType != null && y(w(s.target, e), s.pointerType, !1), s.isPressed = !1, s.isOverTarget = !1, s.activePointerId = null, s.pointerType = null, U(), T || H(s.target);
      for (let g of s.disposables) g();
      s.disposables = [];
    }
  }), L = K((e) => {
    I && $(e);
  }), A = K((e) => {
    v || b?.(e);
  }), F = K((e, s) => {
    if (!v && b) {
      let g = new MouseEvent("click", e);
      ge(g, s), b(ve(g));
    }
  }), de = he(() => {
    let e = M.current, s = {
      onKeyDown(i) {
        if (B(i.nativeEvent, i.currentTarget) && p(i.currentTarget, c(i.nativeEvent))) {
          var u;
          se(c(i.nativeEvent), i.key) && i.preventDefault();
          let t = !0;
          if (!e.isPressed && !i.repeat) {
            e.target = i.currentTarget, e.isPressed = !0, e.pointerType = "keyboard", t = h(i, "keyboard");
            let o = i.currentTarget, f = (E) => {
              B(E, o) && !E.repeat && p(o, c(E)) && e.target && k(w(e.target, E), "keyboard");
            };
            x(O(i.currentTarget), "keyup", me(f, g), !0);
          }
          t && i.stopPropagation(), i.metaKey && $e() && ((u = e.metaKeyEvents) === null || u === void 0 || u.set(i.key, i.nativeEvent));
        } else i.key === "Meta" && (e.metaKeyEvents = /* @__PURE__ */ new Map());
      },
      onClick(i) {
        if (!(i && !p(i.currentTarget, c(i.nativeEvent))) && i && i.button === 0 && !e.isTriggeringEvent && !q.isOpening) {
          let u = !0;
          if (v && i.preventDefault(), !e.ignoreEmulatedMouseEvents && !e.isPressed && (e.pointerType === "virtual" || J(i.nativeEvent))) {
            let t = h(i, "virtual"), o = k(i, "virtual"), f = y(i, "virtual");
            A(i), u = t && o && f;
          } else if (e.isPressed && e.pointerType !== "keyboard") {
            let t = e.pointerType || i.nativeEvent.pointerType || "virtual", o = k(w(i.currentTarget, i), t), f = y(w(i.currentTarget, i), t, !0);
            u = o && f, e.isOverTarget = !1, A(i), $(i);
          }
          e.ignoreEmulatedMouseEvents = !1, u && i.stopPropagation();
        }
      }
    }, g = (i) => {
      var u;
      if (e.isPressed && e.target && B(i, e.target)) {
        var t;
        se(c(i), i.key) && i.preventDefault();
        let f = c(i), E = p(e.target, c(i));
        y(w(e.target, i), "keyboard", E), E && F(i, e.target), U(), i.key !== "Enter" && V(e.target) && p(e.target, f) && !i[ee] && (i[ee] = !0, q(e.target, i, !1)), e.isPressed = !1, (t = e.metaKeyEvents) === null || t === void 0 || t.delete(i.key);
      } else if (i.key === "Meta" && (!((u = e.metaKeyEvents) === null || u === void 0) && u.size)) {
        var o;
        let f = e.metaKeyEvents;
        e.metaKeyEvents = void 0;
        for (let E of f.values()) (o = e.target) === null || o === void 0 || o.dispatchEvent(new KeyboardEvent("keyup", E));
      }
    };
    if (typeof PointerEvent < "u") {
      s.onPointerDown = (t) => {
        if (t.button !== 0 || !p(t.currentTarget, c(t.nativeEvent))) return;
        if (Ke(t.nativeEvent)) {
          e.pointerType = "virtual";
          return;
        }
        e.pointerType = t.pointerType;
        let o = !0;
        if (!e.isPressed) {
          e.isPressed = !0, e.isOverTarget = !0, e.activePointerId = t.pointerId, e.target = t.currentTarget, T || Q(e.target), o = h(t, e.pointerType);
          let f = c(t.nativeEvent);
          "releasePointerCapture" in f && f.releasePointerCapture(t.pointerId), x(O(t.currentTarget), "pointerup", i, !1), x(O(t.currentTarget), "pointercancel", u, !1);
        }
        o && t.stopPropagation();
      }, s.onMouseDown = (t) => {
        if (p(t.currentTarget, c(t.nativeEvent)) && t.button === 0) {
          if (S) {
            let o = j(t.target);
            o && e.disposables.push(o);
          }
          t.stopPropagation();
        }
      }, s.onPointerUp = (t) => {
        !p(t.currentTarget, c(t.nativeEvent)) || e.pointerType === "virtual" || t.button === 0 && !e.isPressed && k(t, e.pointerType || t.pointerType);
      }, s.onPointerEnter = (t) => {
        t.pointerId === e.activePointerId && e.target && !e.isOverTarget && e.pointerType != null && (e.isOverTarget = !0, h(w(e.target, t), e.pointerType));
      }, s.onPointerLeave = (t) => {
        t.pointerId === e.activePointerId && e.target && e.isOverTarget && e.pointerType != null && (e.isOverTarget = !1, y(w(e.target, t), e.pointerType, !1), L(t));
      };
      let i = (t) => {
        if (t.pointerId === e.activePointerId && e.isPressed && t.button === 0 && e.target) {
          if (p(e.target, c(t)) && e.pointerType != null) {
            let o = !1, f = setTimeout(() => {
              e.isPressed && e.target instanceof HTMLElement && (o ? $(t) : (Se(e.target), e.target.click()));
            }, 80);
            x(t.currentTarget, "click", () => o = !0, !0), e.disposables.push(() => clearTimeout(f));
          } else $(t);
          e.isOverTarget = !1;
        }
      }, u = (t) => {
        $(t);
      };
      s.onDragStart = (t) => {
        p(t.currentTarget, c(t.nativeEvent)) && $(t);
      };
    } else if (process.env.NODE_ENV === "test") {
      s.onMouseDown = (t) => {
        if (t.button !== 0 || !p(t.currentTarget, c(t.nativeEvent))) return;
        if (e.ignoreEmulatedMouseEvents) {
          t.stopPropagation();
          return;
        }
        if (e.isPressed = !0, e.isOverTarget = !0, e.target = t.currentTarget, e.pointerType = J(t.nativeEvent) ? "virtual" : "mouse", we(() => h(t, e.pointerType)) && t.stopPropagation(), S) {
          let f = j(t.target);
          f && e.disposables.push(f);
        }
        x(O(t.currentTarget), "mouseup", i, !1);
      }, s.onMouseEnter = (t) => {
        if (!p(t.currentTarget, c(t.nativeEvent))) return;
        let o = !0;
        e.isPressed && !e.ignoreEmulatedMouseEvents && e.pointerType != null && (e.isOverTarget = !0, o = h(t, e.pointerType)), o && t.stopPropagation();
      }, s.onMouseLeave = (t) => {
        if (!p(t.currentTarget, c(t.nativeEvent))) return;
        let o = !0;
        e.isPressed && !e.ignoreEmulatedMouseEvents && e.pointerType != null && (e.isOverTarget = !1, o = y(t, e.pointerType, !1), L(t)), o && t.stopPropagation();
      }, s.onMouseUp = (t) => {
        p(t.currentTarget, c(t.nativeEvent)) && !e.ignoreEmulatedMouseEvents && t.button === 0 && !e.isPressed && k(t, e.pointerType || "mouse");
      };
      let i = (t) => {
        if (t.button === 0) {
          if (e.ignoreEmulatedMouseEvents) {
            e.ignoreEmulatedMouseEvents = !1;
            return;
          }
          e.target && e.target.contains(t.target) && e.pointerType != null || $(t), e.isOverTarget = !1;
        }
      };
      s.onTouchStart = (t) => {
        if (!p(t.currentTarget, c(t.nativeEvent))) return;
        let o = Le(t.nativeEvent);
        if (!o) return;
        e.activePointerId = o.identifier, e.ignoreEmulatedMouseEvents = !0, e.isOverTarget = !0, e.isPressed = !0, e.target = t.currentTarget, e.pointerType = "touch", T || Q(e.target), h(m(e.target, t), e.pointerType) && t.stopPropagation(), x(N(t.currentTarget), "scroll", u, !0);
      }, s.onTouchMove = (t) => {
        if (!p(t.currentTarget, c(t.nativeEvent))) return;
        if (!e.isPressed) {
          t.stopPropagation();
          return;
        }
        let o = ne(t.nativeEvent, e.activePointerId), f = !0;
        o && ie(o, t.currentTarget) ? !e.isOverTarget && e.pointerType != null && (e.isOverTarget = !0, f = h(m(e.target, t), e.pointerType)) : e.isOverTarget && e.pointerType != null && (e.isOverTarget = !1, f = y(m(e.target, t), e.pointerType, !1), L(m(e.target, t))), f && t.stopPropagation();
      }, s.onTouchEnd = (t) => {
        if (!p(t.currentTarget, c(t.nativeEvent))) return;
        if (!e.isPressed) {
          t.stopPropagation();
          return;
        }
        let o = ne(t.nativeEvent, e.activePointerId), f = !0;
        o && ie(o, t.currentTarget) && e.pointerType != null ? (k(m(e.target, t), e.pointerType), f = y(m(e.target, t), e.pointerType), F(t.nativeEvent, e.target)) : e.isOverTarget && e.pointerType != null && (f = y(m(e.target, t), e.pointerType, !1)), f && t.stopPropagation(), e.isPressed = !1, e.activePointerId = null, e.isOverTarget = !1, e.ignoreEmulatedMouseEvents = !0, e.target && !T && H(e.target), U();
      }, s.onTouchCancel = (t) => {
        p(t.currentTarget, c(t.nativeEvent)) && (t.stopPropagation(), e.isPressed && $(m(e.target, t)));
      };
      let u = (t) => {
        e.isPressed && p(c(t), e.target) && $({
          currentTarget: e.target,
          shiftKey: !1,
          ctrlKey: !1,
          metaKey: !1,
          altKey: !1
        });
      };
      s.onDragStart = (t) => {
        p(t.currentTarget, c(t.nativeEvent)) && $(t);
      };
    }
    return s;
  }, [
    x,
    v,
    S,
    U,
    T,
    $,
    L,
    y,
    h,
    k,
    A,
    F
  ]);
  return W(() => {
    if (!R || process.env.NODE_ENV === "test") return;
    const e = O(R.current);
    if (!e || !e.head || e.getElementById(te)) return;
    const s = e.createElement("style");
    s.id = te, s.textContent = `
@layer {
  [${re}] {
    touch-action: pan-x pan-y pinch-zoom;
  }
}
    `.trim(), e.head.prepend(s);
  }, [
    R
  ]), W(() => {
    let e = M.current;
    return () => {
      var s;
      T || H((s = e.target) !== null && s !== void 0 ? s : void 0);
      for (let g of e.disposables) g();
      e.disposables = [];
    };
  }, [
    T
  ]), {
    isPressed: C || pe,
    pressProps: oe(ce, de, {
      [re]: !0
    })
  };
}
function V(r) {
  return r.tagName === "A" && r.hasAttribute("href");
}
function B(r, n) {
  const { key: a, code: l } = r, d = n, P = d.getAttribute("role");
  return (a === "Enter" || a === " " || a === "Spacebar" || l === "Space") && !(d instanceof N(d).HTMLInputElement && !ue(d, a) || d instanceof N(d).HTMLTextAreaElement || d.isContentEditable) && // Links should only trigger with Enter key
  !((P === "link" || !P && V(d)) && a !== "Enter");
}
function Le(r) {
  const { targetTouches: n } = r;
  return n.length > 0 ? n[0] : null;
}
function ne(r, n) {
  const a = r.changedTouches;
  for (let l = 0; l < a.length; l++) {
    const d = a[l];
    if (d.identifier === n) return d;
  }
  return null;
}
function m(r, n) {
  let a = 0, l = 0;
  return n.targetTouches && n.targetTouches.length === 1 && (a = n.targetTouches[0].clientX, l = n.targetTouches[0].clientY), {
    currentTarget: r,
    shiftKey: n.shiftKey,
    ctrlKey: n.ctrlKey,
    metaKey: n.metaKey,
    altKey: n.altKey,
    clientX: a,
    clientY: l
  };
}
function w(r, n) {
  let a = n.clientX, l = n.clientY;
  return {
    currentTarget: r,
    shiftKey: n.shiftKey,
    ctrlKey: n.ctrlKey,
    metaKey: n.metaKey,
    altKey: n.altKey,
    clientX: a,
    clientY: l
  };
}
function De(r) {
  let n = 0, a = 0;
  return r.width !== void 0 ? n = r.width / 2 : r.radiusX !== void 0 && (n = r.radiusX), r.height !== void 0 ? a = r.height / 2 : r.radiusY !== void 0 && (a = r.radiusY), {
    top: r.clientY - a,
    right: r.clientX + n,
    bottom: r.clientY + a,
    left: r.clientX - n
  };
}
function Ye(r, n) {
  return !(r.left > n.right || n.left > r.right || r.top > n.bottom || n.top > r.bottom);
}
function ie(r, n) {
  let a = n.getBoundingClientRect(), l = De(r);
  return Ye(a, l);
}
function Xe(r) {
  return r instanceof HTMLInputElement ? !1 : r instanceof HTMLButtonElement ? r.type !== "submit" && r.type !== "reset" : !V(r);
}
function se(r, n) {
  return r instanceof HTMLInputElement ? !ue(r, n) : Xe(r);
}
const Re = /* @__PURE__ */ new Set([
  "checkbox",
  "radio",
  "range",
  "color",
  "file",
  "image",
  "button",
  "submit",
  "reset"
]);
function ue(r, n) {
  return r.type === "checkbox" || r.type === "radio" ? n === " " : Re.has(r.type);
}
export {
  Je as $,
  Me as _,
  H as a,
  Q as b,
  le as c
};
//# sourceMappingURL=usePress-BuLomD_X.es.js.map
