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