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

var getPosition = function getPosition(targetEle, contentEle, placement, clientX) {
  var targetRect = targetEle.getBoundingClientRect();
  var contentRect = contentEle.getBoundingClientRect();
  var position = {
    top: document.documentElement.scrollTop,
    left: document.documentElement.scrollLeft
  };
  if (targetRect && contentRect) {
    var dWidth = targetRect.width - contentRect.width;
    switch (placement) {
      case "top":
        position.left += targetRect.left + dWidth / 2;
        position.top += targetRect.top - contentRect.height - 16;
        break;
      case "bottom":
        position.left += targetRect.left + dWidth / 2;
        position.top += targetRect.top + targetRect.height;
        break;
      case "mouse":
        position.left += Number(clientX);
        position.top += targetRect.top + targetRect.height + 8;
        break;
    }
    if (placement === "mouse") {
      var edges = {
        top: document.documentElement.scrollTop,
        left: document.documentElement.scrollLeft,
        right: document.documentElement.scrollLeft + document.documentElement.clientWidth,
        bottom: document.documentElement.scrollTop + document.documentElement.clientHeight
      };
      if (position.top > edges.bottom - contentRect.height) {
        position.top = document.documentElement.scrollTop + targetRect.top - contentRect.height - 8;
      }
      if (position.left > edges.right - contentRect.width) {
        position.left = edges.right - contentRect.width;
      }
    }
  }
  return position;
};

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