"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeOffscreenCanvas = exports.getOffscreenCanvas = void 0;
const classnames_1 = require("../common/constant/classnames");
const OFFSCREEN_CANVAS_DOM_ID = `${classnames_1.S2_PREFIX_CLS}-offscreen-canvas`;
/**
 * 获取工具 canvas
 * 需要把 canvas 插入到 body 下，继承全局的 css 样式（如 letter-spacing）
 * 否则后续的 measureText 与实际渲染会有较大差异
 */
const getOffscreenCanvas = () => {
    let canvas = document.getElementById(OFFSCREEN_CANVAS_DOM_ID);
    if (canvas) {
        return canvas;
    }
    canvas = document.createElement('canvas');
    canvas.id = OFFSCREEN_CANVAS_DOM_ID;
    canvas.style.display = 'none';
    document.body.appendChild(canvas);
    return canvas;
};
exports.getOffscreenCanvas = getOffscreenCanvas;
/**
 * 移除工具 canvas
 */
const removeOffscreenCanvas = () => {
    var _a;
    (_a = document.getElementById(OFFSCREEN_CANVAS_DOM_ID)) === null || _a === void 0 ? void 0 : _a.remove();
};
exports.removeOffscreenCanvas = removeOffscreenCanvas;
//# sourceMappingURL=canvas.js.map