const R = /* @__PURE__ */ new Set(), f = /* @__PURE__ */ new WeakMap(), T = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), N = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakSet();
let g, k = 0, $ = 0;
const p = "__aa_tgt", W = "__aa_del", S = "__aa_new", Q = (t) => {
  const e = Z(t);
  e && e.forEach((o) => tt(o));
}, U = (t) => {
  t.forEach((e) => {
    e.target === g && V(), f.has(e.target) && y(e.target);
  });
};
function G(t) {
  const e = A.get(t);
  e?.disconnect();
  let o = f.get(t), n = 0;
  const i = 5;
  o || (o = O(t), f.set(t, o));
  const { offsetWidth: s, offsetHeight: r } = g, d = [
    o.top - i,
    s - (o.left + i + o.width),
    r - (o.top + i + o.height),
    o.left - i
  ].map((c) => `${-1 * Math.floor(c)}px`).join(" "), l = new IntersectionObserver(() => {
    ++n > 1 && y(t);
  }, {
    root: g,
    threshold: 1,
    rootMargin: d
  });
  l.observe(t), A.set(t, l);
}
function y(t) {
  clearTimeout(N.get(t));
  const e = P(t), o = C(e) ? 500 : e.duration;
  N.set(t, setTimeout(async () => {
    const n = v.get(t);
    try {
      await n?.finished, f.set(t, O(t)), G(t);
    } catch {
    }
  }, o));
}
function V() {
  clearTimeout(N.get(g)), N.set(g, setTimeout(() => {
    R.forEach((t) => I(t, (e) => D(() => y(e))));
  }, 100));
}
function J(t) {
  setTimeout(() => {
    q.set(t, setInterval(() => D(y.bind(null, t)), 2e3));
  }, Math.round(2e3 * Math.random()));
}
function D(t) {
  typeof requestIdleCallback == "function" ? requestIdleCallback(() => t()) : requestAnimationFrame(() => t());
}
let _, E;
const K = typeof window < "u" && "ResizeObserver" in window;
K && (g = document.documentElement, _ = new MutationObserver(Q), E = new ResizeObserver(U), window.addEventListener("scroll", () => {
  $ = window.scrollY, k = window.scrollX;
}), E.observe(g));
function Z(t) {
  return t.reduce((n, i) => [
    ...n,
    ...Array.from(i.addedNodes),
    ...Array.from(i.removedNodes)
  ], []).every((n) => n.nodeName === "#comment") ? !1 : t.reduce((n, i) => {
    if (n === !1)
      return !1;
    if (i.target instanceof Element) {
      if (L(i.target), !n.has(i.target)) {
        n.add(i.target);
        for (let s = 0; s < i.target.children.length; s++) {
          const r = i.target.children.item(s);
          if (r) {
            if (W in r)
              return !1;
            L(i.target, r), n.add(r);
          }
        }
      }
      if (i.removedNodes.length)
        for (let s = 0; s < i.removedNodes.length; s++) {
          const r = i.removedNodes[s];
          if (W in r)
            return !1;
          r instanceof Element && (n.add(r), L(i.target, r), T.set(r, [
            i.previousSibling,
            i.nextSibling
          ]));
        }
    }
    return n;
  }, /* @__PURE__ */ new Set());
}
function L(t, e) {
  !e && !(p in t) ? Object.defineProperty(t, p, { value: t }) : e && !(p in e) && Object.defineProperty(e, p, { value: t });
}
function tt(t) {
  var e;
  const o = t.isConnected, n = f.has(t);
  o && T.has(t) && T.delete(t), v.has(t) && ((e = v.get(t)) === null || e === void 0 || e.cancel()), S in t ? X(t) : n && o ? nt(t) : n && !o ? ot(t) : X(t);
}
function h(t) {
  return Number(t.replace(/[^0-9.\-]/g, ""));
}
function et(t) {
  let e = t.parentElement;
  for (; e; ) {
    if (e.scrollLeft || e.scrollTop)
      return { x: e.scrollLeft, y: e.scrollTop };
    e = e.parentElement;
  }
  return { x: 0, y: 0 };
}
function O(t) {
  const e = t.getBoundingClientRect(), { x: o, y: n } = et(t);
  return {
    top: e.top + n,
    left: e.left + o,
    width: e.width,
    height: e.height
  };
}
function H(t, e, o) {
  let n = e.width, i = e.height, s = o.width, r = o.height;
  const a = getComputedStyle(t);
  if (a.getPropertyValue("box-sizing") === "content-box") {
    const l = h(a.paddingTop) + h(a.paddingBottom) + h(a.borderTopWidth) + h(a.borderBottomWidth), c = h(a.paddingLeft) + h(a.paddingRight) + h(a.borderRightWidth) + h(a.borderLeftWidth);
    n -= c, s -= c, i -= l, r -= l;
  }
  return [n, s, i, r].map(Math.round);
}
function P(t) {
  return p in t && M.has(t[p]) ? M.get(t[p]) : { duration: 250, easing: "ease-in-out" };
}
function F(t) {
  if (p in t)
    return t[p];
}
function j(t) {
  const e = F(t);
  return e ? x.has(e) : !1;
}
function I(t, ...e) {
  e.forEach((o) => o(t, M.has(t)));
  for (let o = 0; o < t.children.length; o++) {
    const n = t.children.item(o);
    n && e.forEach((i) => i(n, M.has(n)));
  }
}
function z(t) {
  return Array.isArray(t) ? t : [t];
}
function C(t) {
  return typeof t == "function";
}
function nt(t) {
  const e = f.get(t), o = O(t);
  if (!j(t))
    return f.set(t, o);
  let n;
  if (!e)
    return;
  const i = P(t);
  if (typeof i != "function") {
    const s = e.left - o.left, r = e.top - o.top, [a, d, l, c] = H(t, e, o), m = {
      transform: `translate(${s}px, ${r}px)`
    }, u = {
      transform: "translate(0, 0)"
    };
    a !== d && (m.width = `${a}px`, u.width = `${d}px`), l !== c && (m.height = `${l}px`, u.height = `${c}px`), n = t.animate([m, u], {
      duration: i.duration,
      easing: i.easing
    });
  } else {
    const [s] = z(i(t, "remain", e, o));
    n = new Animation(s), n.play();
  }
  v.set(t, n), f.set(t, o), n.addEventListener("finish", y.bind(null, t));
}
function X(t) {
  S in t && delete t[S];
  const e = O(t);
  f.set(t, e);
  const o = P(t);
  if (!j(t))
    return;
  let n;
  if (typeof o != "function")
    n = t.animate([
      { transform: "scale(.98)", opacity: 0 },
      { transform: "scale(0.98)", opacity: 0, offset: 0.5 },
      { transform: "scale(1)", opacity: 1 }
    ], {
      duration: o.duration * 1.5,
      easing: "ease-in"
    });
  else {
    const [i] = z(o(t, "add", e));
    n = new Animation(i), n.play();
  }
  v.set(t, n), n.addEventListener("finish", y.bind(null, t));
}
function Y(t, e) {
  var o;
  t.remove(), f.delete(t), T.delete(t), v.delete(t), (o = A.get(t)) === null || o === void 0 || o.disconnect(), setTimeout(() => {
    if (W in t && delete t[W], Object.defineProperty(t, S, { value: !0, configurable: !0 }), e && t instanceof HTMLElement)
      for (const n in e)
        t.style[n] = "";
  }, 0);
}
function ot(t) {
  var e;
  if (!T.has(t) || !f.has(t))
    return;
  const [o, n] = T.get(t);
  Object.defineProperty(t, W, { value: !0, configurable: !0 });
  const i = window.scrollX, s = window.scrollY;
  if (n && n.parentNode && n.parentNode instanceof Element ? n.parentNode.insertBefore(t, n) : o && o.parentNode ? o.parentNode.appendChild(t) : (e = F(t)) === null || e === void 0 || e.appendChild(t), !j(t))
    return Y(t);
  const [r, a, d, l] = st(t), c = P(t), m = f.get(t);
  (i !== k || s !== $) && it(t, i, s, c);
  let u, w = {
    position: "absolute",
    top: `${r}px`,
    left: `${a}px`,
    width: `${d}px`,
    height: `${l}px`,
    margin: "0",
    pointerEvents: "none",
    transformOrigin: "center",
    zIndex: "100"
  };
  if (!C(c))
    Object.assign(t.style, w), u = t.animate([
      {
        transform: "scale(1)",
        opacity: 1
      },
      {
        transform: "scale(.98)",
        opacity: 0
      }
    ], { duration: c.duration, easing: "ease-out" });
  else {
    const [B, b] = z(c(t, "remove", m));
    b?.styleReset !== !1 && (w = b?.styleReset || w, Object.assign(t.style, w)), u = new Animation(B), u.play();
  }
  v.set(t, u), u.addEventListener("finish", Y.bind(null, t, w));
}
function it(t, e, o, n) {
  const i = k - e, s = $ - o, r = document.documentElement.style.scrollBehavior;
  if (getComputedStyle(g).scrollBehavior === "smooth" && (document.documentElement.style.scrollBehavior = "auto"), window.scrollTo(window.scrollX + i, window.scrollY + s), !t.parentElement)
    return;
  const d = t.parentElement;
  let l = d.clientHeight, c = d.clientWidth;
  const m = performance.now();
  function u() {
    requestAnimationFrame(() => {
      if (!C(n)) {
        const w = l - d.clientHeight, B = c - d.clientWidth;
        m + n.duration > performance.now() ? (window.scrollTo({
          left: window.scrollX - B,
          top: window.scrollY - w
        }), l = d.clientHeight, c = d.clientWidth, u()) : document.documentElement.style.scrollBehavior = r;
      }
    });
  }
  u();
}
function st(t) {
  const e = f.get(t), [o, , n] = H(t, e, O(t));
  let i = t.parentElement;
  for (; i && (getComputedStyle(i).position === "static" || i instanceof HTMLBodyElement); )
    i = i.parentElement;
  i || (i = document.body);
  const s = getComputedStyle(i), r = f.get(i) || O(i), a = Math.round(e.top - r.top) - h(s.borderTopWidth), d = Math.round(e.left - r.left) - h(s.borderLeftWidth);
  return [a, d, o, n];
}
function rt(t, e = {}) {
  return _ && E && (window.matchMedia("(prefers-reduced-motion: reduce)").matches && !C(e) && !e.disrespectUserMotionPreference || (x.add(t), getComputedStyle(t).position === "static" && Object.assign(t.style, { position: "relative" }), I(t, y, J, (i) => E?.observe(i)), C(e) ? M.set(t, e) : M.set(t, { duration: 250, easing: "ease-in-out", ...e }), _.observe(t, { childList: !0 }), R.add(t))), Object.freeze({
    parent: t,
    enable: () => {
      x.add(t);
    },
    disable: () => {
      x.delete(t);
    },
    isEnabled: () => x.has(t)
  });
}
export {
  rt as default,
  H as getTransitionSizes
};
//# sourceMappingURL=index.js.map
