'use strict';

const getScrollParent = (node) => {
    if (node === null) {
        return null;
    }
    if (node.classList.contains('element_scrolled') || (node === null || node === void 0 ? void 0 : node.tagName) === 'BODY') {
        return node;
    }
    else {
        return getScrollParent(node.offsetParent);
    }
};
function positionElement({ actionElement, changedElement, intoView, }) {
    const body = intoView ? intoView : document.body;
    const parentElement = body.offsetParent;
    const contentScrolled = !!body.classList.contains('element_scrolled');
    const positionTop = contentScrolled
        ? actionElement.offsetTop - body.scrollTop + parentElement.offsetTop
        : actionElement.offsetTop - window.scrollY;
    const positionLeft = contentScrolled ? actionElement.offsetLeft + parentElement.offsetLeft : actionElement.offsetLeft;
    const changedpositionTop = (changedElement === null || changedElement === void 0 ? void 0 : changedElement.offsetHeight) > window.innerHeight - positionTop
        ? positionTop - (changedElement === null || changedElement === void 0 ? void 0 : changedElement.offsetHeight) - 16
        : positionTop + (actionElement === null || actionElement === void 0 ? void 0 : actionElement.offsetHeight) + 16;
    const changedpositionLeft = (changedElement === null || changedElement === void 0 ? void 0 : changedElement.offsetWidth) > window.innerWidth - positionLeft
        ? positionLeft + (actionElement === null || actionElement === void 0 ? void 0 : actionElement.offsetWidth) - (changedElement === null || changedElement === void 0 ? void 0 : changedElement.offsetWidth)
        : positionLeft;
    const limitedHeightScreen = window.innerHeight - (changedElement === null || changedElement === void 0 ? void 0 : changedElement.offsetHeight);
    const limitedWidthScreen = window.innerWidth - (changedElement === null || changedElement === void 0 ? void 0 : changedElement.offsetWidth);
    const result = {
        top: changedpositionTop < 8
            ? 8
            : changedpositionTop > limitedHeightScreen
                ? limitedHeightScreen - 8
                : changedpositionTop,
        left: changedpositionLeft < 0 ? 0 : changedpositionLeft > limitedWidthScreen ? limitedWidthScreen : changedpositionLeft,
    };
    return result;
}
function positionAbsoluteElement({ actionElement, changedElement, intoView, }) {
    const body = intoView ? intoView : document.body;
    const numberHeignt = body.offsetHeight < changedElement.offsetHeight ? window.screen.height : body.offsetHeight;
    const numberWidth = body.offsetWidth < changedElement.offsetWidth ? window.screen.width : body.offsetWidth;
    const heightTop = numberHeignt - actionElement.offsetTop;
    const widthLeft = numberWidth - actionElement.offsetLeft;
    const result = {
        y: heightTop < changedElement.offsetHeight + actionElement.offsetHeight ? 'top' : 'bottom',
        x: widthLeft < changedElement.offsetWidth ? 'right' : 'left',
    };
    return result;
}

exports.getScrollParent = getScrollParent;
exports.positionAbsoluteElement = positionAbsoluteElement;
exports.positionElement = positionElement;

//# sourceMappingURL=position-element-72a5bd01.js.map