<commit_before>import getOffsetParent from './getOffsetParent';
import getScrollParent from './getScrollParent';
import getOffsetRect from './getOffsetRect';
import getPosition from './getPosition';
import getOffsetRectRelativeToCustomParent from './getOffsetRectRelativeToCustomParent';
import getTotalScroll from './getTotalScroll';
import isFixed from './isFixed';
import getWindowSizes from './getWindowSizes';

/**
 * Computed the boundaries limits and return them
 * @method
 * @memberof Popper.Utils
 * @param {Object} data - Object containing the property "offsets" generated by `_getOffsets`
 * @param {Number} padding - Boundaries padding
 * @param {Element} boundariesElement - Element used to define the boundaries
 * @returns {Object} Coordinates of the boundaries
 */
export default function getBoundaries(popper, padding, boundariesElement) {
    // NOTE: 1 DOM access here
    let boundaries = { top: 0, left: 0 };
    const offsetParent = getOffsetParent(popper);
    const scrollParent = getScrollParent(popper);
    const html = window.document.documentElement;

    if (boundariesElement === 'window') {
        // WINDOW
        const { height, width } = getWindowSizes();
        boundaries = {
            top: 0,
            right: width,
            bottom: height,
            left: 0
        };
    } else if (boundariesElement === 'viewport') {
        // VIEWPORT
        const { left, top } = getOffsetRect(offsetParent);
        const { clientWidth: width, clientHeight: height } = html;

        if (getPosition(popper) === 'fixed') {
            boundaries.right = width;
            boundaries.bottom = height;
        } else {
            boundaries = {
                top: 0 - top,
                right: width - left,
                bottom: height - top,
                left: 0 - left
            };
        }
    } else if (boundariesElement === 'scrollParent' || scrollParent === boundariesElement) {
        // SCROLL PARENT IS BOUNDARIES ELEMENT
        if (scrollParent.nodeName === 'BODY') {
            const { height, width } = getWindowSizes();
            boundaries.right = width;
            boundaries.bottom = height;
        } else {
            boundaries = getOffsetRectRelativeToCustomParent(scrollParent, offsetParent, isFixed(popper));
        }
    } else {
        // BOUNDARIES ELEMENT
        boundaries = getOffsetRectRelativeToCustomParent(boundariesElement, offsetParent, isFixed(popper));
    }

    const scrollLeft = getTotalScroll(popper, 'left');
    const scrollTop = getTotalScroll(popper, 'top');
    boundaries.right += scrollLeft;
    boundaries.bottom += scrollTop;

    // Add paddings
    boundaries.left += padding;
    boundaries.top += padding;
    boundaries.right -= padding;
    boundaries.bottom -= padding;

    return boundaries;
}
<commit_msg>code cleanup + optimizations<commit_after>import getOffsetParent from './getOffsetParent';
import getScrollParent from './getScrollParent';
import getOffsetRect from './getOffsetRect';
import getPosition from './getPosition';
import getOffsetRectRelativeToCustomParent from './getOffsetRectRelativeToCustomParent';
import getTotalScroll from './getTotalScroll';
import isFixed from './isFixed';
import getWindowSizes from './getWindowSizes';

/**
 * Computed the boundaries limits and return them
 * @method
 * @memberof Popper.Utils
 * @param {Object} data - Object containing the property "offsets" generated by `_getOffsets`
 * @param {Number} padding - Boundaries padding
 * @param {Element} boundariesElement - Element used to define the boundaries
 * @returns {Object} Coordinates of the boundaries
 */
export default function getBoundaries(popper, padding, boundariesElement) {
    // NOTE: 1 DOM access here
    let boundaries = { top: 0, left: 0 };
    const offsetParent = getOffsetParent(popper);

    // Handle viewport case
    if (boundariesElement === 'viewport') {
        const { left, top } = getOffsetRect(offsetParent);
        const { clientWidth: width, clientHeight: height } = window.document.documentElement;

        if (getPosition(popper) === 'fixed') {
            boundaries.right = width;
            boundaries.bottom = height;
        } else {
            boundaries = {
                top: 0 - top,
                right: width - left,
                bottom: height - top,
                left: 0 - left
            };
        }
    }
    // Handle other cases based on DOM element used as boundaries
    else {
        let boundariesNode;
        if (boundariesElement === 'scrollParent') {
            boundariesNode = getScrollParent(popper);
        } else if (boundariesElement === 'window') {
            boundariesNode = window.document.body;
        } else {
            boundariesNode = boundariesElement;
        }

        // In case of BODY, we need a different computation
        if (boundariesNode.nodeName === 'BODY') {
            const { height, width } = getWindowSizes();
            boundaries.right = width;
            boundaries.bottom = height;
        }
        // for all the other DOM elements, this one is good
        else {
            boundaries = getOffsetRectRelativeToCustomParent(boundariesNode, offsetParent, isFixed(popper));
        }
    }

    const scrollLeft = getTotalScroll(popper, 'left');
    const scrollTop = getTotalScroll(popper, 'top');
    boundaries.right += scrollLeft;
    boundaries.bottom += scrollTop;

    // Add paddings
    boundaries.left += padding;
    boundaries.top += padding;
    boundaries.right -= padding;
    boundaries.bottom -= padding;

    return boundaries;
}

{'fraction_non_alphanumeric': 0.10148029249152844, 'fraction_numerical': 0.002140181915462814, 'mean_word_length': 2.62508080155139, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7568717', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1437, 'n_words': 428}