"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.withTextMeasure = void 0;
exports.measureText = measureText;
const text_utils_1 = require("../../common/text_utils");
const canvas_1 = require("../../renderers/canvas");
const withTextMeasure = (fun) => {
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');
    return fun(ctx ? measureText(ctx) : () => ({ width: 0, height: 0 }));
};
exports.withTextMeasure = withTextMeasure;
function measureText(ctx) {
    return (text, font, fontSize, lineHeight = 1) => {
        if (text.length === 0) {
            return { width: 0, height: fontSize * lineHeight };
        }
        return (0, canvas_1.withContext)(ctx, (ctx) => {
            ctx.font = (0, text_utils_1.cssFontShorthand)(font, fontSize);
            const { width } = ctx.measureText(text);
            return { width, height: fontSize * lineHeight };
        });
    };
}
//# sourceMappingURL=canvas_text_bbox_calculator.js.map