<commit_before>import {Context} from '../../core/context';

export class Bounds {
    constructor(readonly left: number, readonly top: number, readonly width: number, readonly height: number) {}

    add(x: number, y: number, w: number, h: number): Bounds {
        return new Bounds(this.left + x, this.top + y, this.width + w, this.height + h);
    }

    static fromClientRect(context: Context, clientRect: ClientRect): Bounds {
        return new Bounds(
            clientRect.left + context.windowBounds.left,
            clientRect.top + context.windowBounds.top,
            clientRect.width,
            clientRect.height
        );
    }

    static fromDOMRectList(context: Context, domRectList: DOMRectList): Bounds {
        const domRect = domRectList[0];
        return domRect
            ? new Bounds(
                  domRect.x + context.windowBounds.left,
                  domRect.y + context.windowBounds.top,
                  domRect.width,
                  domRect.height
              )
            : Bounds.EMPTY;
    }

    static EMPTY = new Bounds(0, 0, 0, 0);
}

export const parseBounds = (context: Context, node: Element): Bounds => {
    return Bounds.fromClientRect(context, node.getBoundingClientRect());
};

export const parseDocumentSize = (document: Document): Bounds => {
    const body = document.body;
    const documentElement = document.documentElement;

    if (!body || !documentElement) {
        throw new Error(`Unable to get document size`);
    }
    const width = Math.max(
        Math.max(body.scrollWidth, documentElement.scrollWidth),
        Math.max(body.offsetWidth, documentElement.offsetWidth),<commit_msg>fix: ios text wrapping with 0 width rect (#2786)<commit_after>import {Context} from '../../core/context';

export class Bounds {
    constructor(readonly left: number, readonly top: number, readonly width: number, readonly height: number) {}

    add(x: number, y: number, w: number, h: number): Bounds {
        return new Bounds(this.left + x, this.top + y, this.width + w, this.height + h);
    }

    static fromClientRect(context: Context, clientRect: ClientRect): Bounds {
        return new Bounds(
            clientRect.left + context.windowBounds.left,
            clientRect.top + context.windowBounds.top,
            clientRect.width,
            clientRect.height
        );
    }

    static fromDOMRectList(context: Context, domRectList: DOMRectList): Bounds {
        const domRect = Array.from(domRectList).find(rect => rect.width !== 0);
        return domRect
            ? new Bounds(
                  domRect.x + context.windowBounds.left,
                  domRect.y + context.windowBounds.top,
                  domRect.width,
                  domRect.height
              )
            : Bounds.EMPTY;
    }

    static EMPTY = new Bounds(0, 0, 0, 0);
}

export const parseBounds = (context: Context, node: Element): Bounds => {
    return Bounds.fromClientRect(context, node.getBoundingClientRect());
};

export const parseDocumentSize = (document: Document): Bounds => {
    const body = document.body;
    const documentElement = document.documentElement;

    if (!body || !documentElement) {
        throw new Error(`Unable to get document size`);
    }
    const width = Math.max(
        Math.max(body.scrollWidth, documentElement.scrollWidth),
        Math.max(body.offsetWidth, documentElement.offsetWidth),
{'fraction_non_alphanumeric': 0.10964526531808853, 'fraction_numerical': 0.0043975373790677225, 'mean_word_length': 2.4959016393442623, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '4520022', 'n_tokens_mistral': 962, 'n_tokens_neox': 934, 'n_words': 249}