const $ = (t) => typeof t == "object" && t != null && t.nodeType === 1, tt = (t, o) => (!o || t !== "hidden") && t !== "visible" && t !== "clip", G = (t, o) => {
  if (t.clientHeight < t.scrollHeight || t.clientWidth < t.scrollWidth) {
    const s = getComputedStyle(t, null);
    return tt(s.overflowY, o) || tt(s.overflowX, o) || ((h) => {
      const c = ((l) => {
        if (!l.ownerDocument || !l.ownerDocument.defaultView)
          return null;
        try {
          return l.ownerDocument.defaultView.frameElement;
        } catch {
          return null;
        }
      })(h);
      return !!c && (c.clientHeight < h.scrollHeight || c.clientWidth < h.scrollWidth);
    })(t);
  }
  return !1;
}, S = (t, o, s, h, c, l, f, n) => l < t && f > o || l > t && f < o ? 0 : l <= t && n <= s || f >= o && n >= s ? l - t - h : f > o && n < s || l < t && n > s ? f - o + c : 0, nt = (t) => {
  const o = t.parentElement;
  return o ?? (t.getRootNode().host || null);
}, lt = (t, o) => {
  var s, h, c, l;
  if (typeof document > "u")
    return [];
  const { scrollMode: f, block: n, inline: u, boundary: X, skipOverflowHiddenElements: et } = o, ot = typeof X == "function" ? X : (p) => p !== X;
  if (!$(t))
    throw new TypeError("Invalid target");
  const J = document.scrollingElement || document.documentElement, M = [];
  let r = t;
  for (; $(r) && ot(r); ) {
    if (r = nt(r), r === J) {
      M.push(r);
      break;
    }
    r != null && r === document.body && G(r) && !G(document.documentElement) || r != null && G(r, et) && M.push(r);
  }
  const m = (h = (s = window.visualViewport) == null ? void 0 : s.width) != null ? h : innerWidth, w = (l = (c = window.visualViewport) == null ? void 0 : c.height) != null ? l : innerHeight, { scrollX: W, scrollY: b } = window, { height: H, width: y, top: v, right: Y, bottom: j, left: E } = t.getBoundingClientRect(), { top: K, right: P, bottom: Q, left: U } = ((p) => {
    const e = window.getComputedStyle(p);
    return { top: parseFloat(e.scrollMarginTop) || 0, right: parseFloat(e.scrollMarginRight) || 0, bottom: parseFloat(e.scrollMarginBottom) || 0, left: parseFloat(e.scrollMarginLeft) || 0 };
  })(t);
  let i = n === "start" || n === "nearest" ? v - K : n === "end" ? j + Q : v + H / 2 - K + Q, d = u === "center" ? E + y / 2 - U + P : u === "end" ? Y + P : E - U;
  const N = [];
  for (let p = 0; p < M.length; p++) {
    const e = M[p], { height: T, width: x, top: B, right: O, bottom: q, left: C } = e.getBoundingClientRect();
    if (f === "if-needed" && v >= 0 && E >= 0 && j <= w && Y <= m && v >= B && j <= q && E >= C && Y <= O)
      return N;
    const F = getComputedStyle(e), I = parseInt(F.borderLeftWidth, 10), R = parseInt(F.borderTopWidth, 10), V = parseInt(F.borderRightWidth, 10), k = parseInt(F.borderBottomWidth, 10);
    let a = 0, g = 0;
    const D = "offsetWidth" in e ? e.offsetWidth - e.clientWidth - I - V : 0, L = "offsetHeight" in e ? e.offsetHeight - e.clientHeight - R - k : 0, z = "offsetWidth" in e ? e.offsetWidth === 0 ? 0 : x / e.offsetWidth : 0, A = "offsetHeight" in e ? e.offsetHeight === 0 ? 0 : T / e.offsetHeight : 0;
    if (J === e)
      a = n === "start" ? i : n === "end" ? i - w : n === "nearest" ? S(b, b + w, w, R, k, b + i, b + i + H, H) : i - w / 2, g = u === "start" ? d : u === "center" ? d - m / 2 : u === "end" ? d - m : S(W, W + m, m, I, V, W + d, W + d + y, y), a = Math.max(0, a + b), g = Math.max(0, g + W);
    else {
      a = n === "start" ? i - B - R : n === "end" ? i - q + k + L : n === "nearest" ? S(B, q, T, R, k + L, i, i + H, H) : i - (B + T / 2) + L / 2, g = u === "start" ? d - C - I : u === "center" ? d - (C + x / 2) + D / 2 : u === "end" ? d - O + V + D : S(C, O, x, I, V + D, d, d + y, y);
      const { scrollLeft: Z, scrollTop: _ } = e;
      a = A === 0 ? 0 : Math.max(0, Math.min(_ + a / A, e.scrollHeight - T / A + L)), g = z === 0 ? 0 : Math.max(0, Math.min(Z + g / z, e.scrollWidth - x / z + D)), i += _ - a, d += Z - g;
    }
    N.push({ el: e, top: a, left: g });
  }
  return N;
};
export {
  lt as compute
};
