"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSize = getSize;
exports.getChildrenRect = getChildrenRect;
const CodePathNotImplemented_1 = require("../../../exception/CodePathNotImplemented");
const getRect_1 = require("./getRect");
function getSize(element) {
    if (element instanceof Text) {
        const range = document.createRange();
        range.selectNodeContents(element);
        const bb = range.getBoundingClientRect();
        const { width, height } = bb;
        return { width, height };
    }
    if (element.classList.contains('__parent')) {
        const { width, height } = getChildrenRect(element);
        return { width, height };
    }
    const bb = element.getBoundingClientRect();
    const { width, height } = bb;
    return { width, height };
}
function getChildrenRect(element) {
    if (element instanceof HTMLElement) {
        const children = Array.from(element.children);
        const { minX, maxX, minY, maxY } = children.reduce((acc, child) => {
            const { x, y, width, height } = (0, getRect_1.getRect)(child);
            return {
                minX: Math.min(acc.minX, x),
                maxX: Math.max(acc.maxX, x + width),
                minY: Math.min(acc.minY, y),
                maxY: Math.max(acc.maxY, y + height),
            };
        }, { minX: Infinity, maxX: -Infinity, minY: Infinity, maxY: -Infinity });
        const x = minX;
        const y = minY;
        const width = maxX - minX;
        const height = maxY - minY;
        return { x, y, width, height };
    }
    else if (element instanceof SVGElement) {
        throw new CodePathNotImplemented_1.CodePathNotImplementedError();
    }
    else {
        throw new CodePathNotImplemented_1.CodePathNotImplementedError();
    }
}
//# sourceMappingURL=getSize.js.map