import { viewport as c } from "./index-enums.js";
import v from "./index-getViewportRect.js";
import C from "./index-getDocumentRect.js";
import x from "./index-listScrollParents.js";
import b from "./index-getOffsetParent.js";
import E from "./index-getDocumentElement.js";
import P from "./index-getComputedStyle.js";
import { isHTMLElement as w, isElement as m } from "./index-instanceOf.js";
import T from "./index-getBoundingClientRect.js";
import H from "./index-getParentNode.js";
import N from "./index-contains.js";
import y from "./index-getNodeName.js";
import l from "./index-rectToClientRect.js";
import { max as u, min as a } from "./index-math.js";
function B(i, r) {
  var t = T(i, !1, r === "fixed");
  return t.top = t.top + i.clientTop, t.left = t.left + i.clientLeft, t.bottom = t.top + i.clientHeight, t.right = t.left + i.clientWidth, t.width = i.clientWidth, t.height = i.clientHeight, t.x = t.left, t.y = t.top, t;
}
function d(i, r, t) {
  return r === c ? l(v(i, t)) : m(r) ? B(r, t) : l(C(E(i)));
}
function D(i) {
  var r = x(H(i)), t = ["absolute", "fixed"].indexOf(P(i).position) >= 0, e = t && w(i) ? b(i) : i;
  return m(e) ? r.filter(function(p) {
    return m(p) && N(p, e) && y(p) !== "body";
  }) : [];
}
function J(i, r, t, e) {
  var p = r === "clippingParents" ? D(i) : [].concat(r), g = [].concat(p, [t]), h = g[0], o = g.reduce(function(n, s) {
    var f = d(i, s, e);
    return n.top = u(f.top, n.top), n.right = a(f.right, n.right), n.bottom = a(f.bottom, n.bottom), n.left = u(f.left, n.left), n;
  }, d(i, h, e));
  return o.width = o.right - o.left, o.height = o.bottom - o.top, o.x = o.left, o.y = o.top, o;
}
export {
  J as default
};
