import { isFirefox as N, isSafari as x } from "./BrowserDetector.js";
import { MonotonicInterpolant as v } from "./MonotonicInterpolant.js";
const X = 1;
function Y(t) {
  const e = t.nodeType === X ? t : t.parentElement;
  if (!e)
    return null;
  const { top: n, left: r } = e.getBoundingClientRect();
  return {
    x: r,
    y: n
  };
}
function W(t) {
  return {
    x: t.clientX,
    y: t.clientY
  };
}
function M(t) {
  var e;
  return t.nodeName === "IMG" && (N() || !(!((e = document.documentElement) === null || e === void 0) && e.contains(t)));
}
function C(t, e, n, r) {
  let c = t ? e.width : n, o = t ? e.height : r;
  return x() && t && (o /= window.devicePixelRatio, c /= window.devicePixelRatio), {
    dragPreviewWidth: c,
    dragPreviewHeight: o
  };
}
function F(t, e, n, r, c) {
  const o = M(e), u = Y(o ? t : e), i = {
    x: n.x - u.x,
    y: n.y - u.y
  }, { offsetWidth: f, offsetHeight: s } = t, { anchorX: h, anchorY: p } = r, { dragPreviewWidth: g, dragPreviewHeight: a } = C(o, e, f, s), m = () => {
    let w = new v([
      0,
      0.5,
      1
    ], [
      // Dock to the top
      i.y,
      // Align at the center
      i.y / s * a,
      // Dock to the bottom
      i.y + a - s
    ]).interpolate(p);
    return x() && o && (w += (window.devicePixelRatio - 1) * a), w;
  }, y = () => new v([
    0,
    0.5,
    1
  ], [
    // Dock to the left
    i.x,
    // Align at the center
    i.x / f * g,
    // Dock to the right
    i.x + g - f
  ]).interpolate(h), { offsetX: l, offsetY: d } = c, P = l === 0 || l, O = d === 0 || d;
  return {
    x: P ? l : y(),
    y: O ? d : m()
  };
}
export {
  F as getDragPreviewOffset,
  W as getEventClientOffset,
  Y as getNodeClientOffset
};
//# sourceMappingURL=OffsetUtils.js.map
