"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.measureText = measureText;
function measureText(ctx, str, fontSize, maxWidth) {
    ctx.font = `${Math.ceil(fontSize)}px Inconsolata`;
    const textMetrics = ctx.measureText('xHÁQWÍjgpqy');
    const { fontBoundingBoxAscent, fontBoundingBoxDescent } = textMetrics;
    const lineHeight = Math.abs(fontBoundingBoxAscent) + Math.abs(fontBoundingBoxDescent);
    const words = str.trim().length === 0 ? [str] : str.split(' ');
    const lines = [];
    let currentLine = words[0];
    for (let i = 1; i < words.length; i++) {
        const word = words[i];
        const width = ctx.measureText(currentLine + ' ' + word).width;
        if (width < maxWidth) {
            currentLine += ' ' + word;
        }
        else {
            lines.push(currentLine);
            currentLine = word;
        }
    }
    lines.push(currentLine);
    const height = lineHeight * lines.length;
    const width = Math.max(...lines.map((line) => ctx.measureText(line).width));
    return {
        width,
        height,
    };
}
//# sourceMappingURL=measureText.js.map