"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextXform = void 0;
const base_xform_1 = require("../base-xform.js");
//   <t xml:space="preserve"> is </t>
class TextXform extends base_xform_1.BaseXform {
    get tag() {
        return "t";
    }
    render(xmlStream, model) {
        xmlStream.openNode("t");
        if (/^\s|\n|\s$/.test(model)) {
            xmlStream.addAttribute("xml:space", "preserve");
        }
        xmlStream.writeText(model);
        xmlStream.closeNode();
    }
    parseOpen(node) {
        if (node.name === "t") {
            this._text = [];
            this.model = "";
            return true;
        }
        return false;
    }
    parseText(text) {
        this._text.push(text);
        // Update model immediately after receiving text
        this.model = this._text
            .join("")
            .replace(/_x([0-9A-F]{4})_/g, ($0, $1) => String.fromCharCode(parseInt($1, 16)));
    }
    parseClose() {
        return false;
    }
}
exports.TextXform = TextXform;
