<commit_before>import getStyleComputedProperty from './getStyleComputedProperty';
import includeScroll from './includeScroll';
import getScrollParent from './getScrollParent';
import getBoundingClientRect from './getBoundingClientRect';

export default function getOffsetRectRelativeToArbitraryNode(children, parent) {
    const childrenRect = getBoundingClientRect(children);
    const parentRect = getBoundingClientRect(parent);
    const scrollParent = getScrollParent(children);
    let offsets = {
        top: childrenRect.top - parentRect.top,
        left: childrenRect.left - parentRect.left,
        bottom: childrenRect.top - parentRect.top + childrenRect.height,
        right: childrenRect.left - parentRect.left + childrenRect.width,
        width: childrenRect.width,
        height: childrenRect.height,
    };

    // Subtract margins of documentElement in case it's being used as parent
    // we do this only on HTML because it's the only element that behaves
    // differently when margins are applied to it. The margins are included in
    // the box of the documentElement, in the other cases not.
    if (parent.nodeName === 'HTML') {
        const styles = getStyleComputedProperty(parent);
        const borderTopWidth = Number(styles.borderTopWidth.split('px')[0]);
        const borderLeftWidth = Number(styles.borderLeftWidth.split('px')[0]);
        const marginTop = Number(styles.marginTop.split('px')[0]);
        const marginLeft = Number(styles.marginLeft.split('px')[0]);

        offsets.top -= borderTopWidth - marginTop;
        offsets.bottom -= borderTopWidth - marginTop;
        offsets.left -= borderLeftWidth - marginLeft;
        offsets.right -= borderLeftWidth - marginLeft;

        // Attach marginTop and marginLeft because in some circumstances we may need them
        offsets.marginTop = marginTop;
        offsets.marginLeft = marginLeft;
    }

    if (parent.contains(scrollParent)) {
        const isIE10 = navigator.appVersion.indexOf('MSIE 10') !== -1;
        if (isIE10 || scrollParent.nodeName !== 'BODY') {
            offsets = includeScroll(offsets, parent);
        }
    }

    return offsets;
}<commit_msg>Fixed IE10 tests<commit_after>import getStyleComputedProperty from './getStyleComputedProperty';
import includeScroll from './includeScroll';
import getScrollParent from './getScrollParent';
import getBoundingClientRect from './getBoundingClientRect';

export default function getOffsetRectRelativeToArbitraryNode(children, parent) {
    const isIE10 = navigator.appVersion.indexOf('MSIE 10') !== -1;
    const childrenRect = getBoundingClientRect(children);
    const parentRect = getBoundingClientRect(parent);
    const scrollParent = getScrollParent(children);
    let offsets = {
        top: childrenRect.top - parentRect.top,
        left: childrenRect.left - parentRect.left,
        bottom: childrenRect.top - parentRect.top + childrenRect.height,
        right: childrenRect.left - parentRect.left + childrenRect.width,
        width: childrenRect.width,
        height: childrenRect.height,
    };

    // Subtract margins of documentElement in case it's being used as parent
    // we do this only on HTML because it's the only element that behaves
    // differently when margins are applied to it. The margins are included in
    // the box of the documentElement, in the other cases not.
    if (parent.nodeName === 'HTML') {
        const styles = getStyleComputedProperty(parent);
        const borderTopWidth = isIE10 ? 0 : +(styles.borderTopWidth.split('px')[0]);
        const borderLeftWidth = isIE10 ? 0 : +(styles.borderLeftWidth.split('px')[0]);
        const marginTop = isIE10 ? 0 : +(styles.marginTop.split('px')[0]);
        const marginLeft = isIE10 ? 0 : +(styles.marginLeft.split('px')[0]);

        offsets.top -= borderTopWidth - marginTop;
        offsets.bottom -= borderTopWidth - marginTop;
        offsets.left -= borderLeftWidth - marginLeft;
        offsets.right -= borderLeftWidth - marginLeft;

        // Attach marginTop and marginLeft because in some circumstances we may need them
        offsets.marginTop = marginTop;
        offsets.marginLeft = marginLeft;
    }

    if (parent.contains(scrollParent) && (isIE10 || scrollParent.nodeName !== 'BODY')) {
        offsets = includeScroll(offsets, parent);
    }

    return offsets;
}
{'fraction_non_alphanumeric': 0.10098691760385586, 'fraction_numerical': 0.008262565985770026, 'mean_word_length': 3.310583580613254, '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': '3136305', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1150, 'n_words': 325}