/**
 * ldesign v0.3.13
 * (c) 2023 ldesign
 * @license MIT
 */

import { getWindowScroll, getElmCssPropValue, isFixed } from '../../utils/dom.mjs';
import '../../_chunks/dep-eba0ea6e.mjs';
import '../../_chunks/dep-876fb3ec.mjs';
import '../../_chunks/dep-469b4ae0.mjs';
import '../../_chunks/dep-255303ba.mjs';
import '../../_chunks/dep-b57180d0.mjs';
import '../../_chunks/dep-c8d7b6b4.mjs';
import '../../_chunks/dep-3da99438.mjs';
import '../../_chunks/dep-5717e263.mjs';
import '../../_chunks/dep-a8bcacea.mjs';
import '../../utils/easing.mjs';

function getRelativePosition(elm) {
  var relativeElm = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.body;
  var _getWindowScroll = getWindowScroll(),
    scrollTop = _getWindowScroll.scrollTop,
    scrollLeft = _getWindowScroll.scrollLeft;
  var _elm$getBoundingClien = elm.getBoundingClientRect(),
    elmTop = _elm$getBoundingClien.top,
    elmLeft = _elm$getBoundingClien.left;
  var _relativeElm$getBound = relativeElm.getBoundingClientRect(),
    relElmTop = _relativeElm$getBound.top,
    relElmLeft = _relativeElm$getBound.left;
  var relativeElmPosition = getElmCssPropValue(relativeElm, "position");
  if (relativeElm.tagName.toLowerCase() !== "body" && relativeElmPosition === "relative" || relativeElmPosition === "sticky") {
    return {
      top: elmTop - relElmTop,
      left: elmLeft - relElmLeft
    };
  }
  if (isFixed(elm)) {
    return {
      top: elmTop,
      left: elmLeft
    };
  }
  return {
    top: elmTop + scrollTop,
    left: elmLeft + scrollLeft
  };
}

export { getRelativePosition as default };
//# sourceMappingURL=getRelativePosition.mjs.map
