/*
 * SDK Pullenti Unitext, version 4.33, fabruary 2026. Copyright (c) 2013-2026, Pullenti. All rights reserved. 
 * Non-Commercial Freeware and Commercial Software. 
 * This class is generated using the converter UniSharping (www.unisharping.ru) from Pullenti C# project. 
 * The latest version of the code is available on the site www.pullenti.ru
 */

const Utils = require("./../unisharp/Utils");
const StringBuilder = require("./../unisharp/StringBuilder");

const MiscHelper = require("./../util/MiscHelper");
const UnitextImage = require("./UnitextImage");
const UnitextStyledFragmentType = require("./UnitextStyledFragmentType");
const UnitextContainerType = require("./UnitextContainerType");
const UnitextItem = require("./UnitextItem");
const LocCorrTyp = require("./internal/uni/LocCorrTyp");

/**
 * Контейнер других элементов
 * 
 */
class UnitextContainer extends UnitextItem {
    
    constructor() {
        super();
        this.children = new Array();
        this.typ = UnitextContainerType.UNDEFINED;
        this.data = null;
        this.userData = null;
        this.htmlStyle = null;
        this.htmlClass = null;
        this.m_IsInline = -1;
    }
    
    static _getBoxChars(it) {
        const UnitextPlaintext = require("./UnitextPlaintext");
        let pl = Utils.as(it, UnitextPlaintext);
        if (pl === null) 
            return 0;
        let co = 0;
        for (const ch of pl.text) {
            if ((ch.charCodeAt(0)) >= 0x2500 && (ch.charCodeAt(0)) <= 0x257F) 
                co++;
        }
        return co;
    }
    
    static _getUnderlineChars(it) {
        const UnitextPlaintext = require("./UnitextPlaintext");
        let pl = Utils.as(it, UnitextPlaintext);
        if (pl === null) 
            return 0;
        let co = 0;
        for (const ch of pl.text) {
            if (ch === '_' || ch === '_') 
                co++;
        }
        return co;
    }
    
    optimize(isContainer, pars) {
        const UnitextPlaintext = require("./UnitextPlaintext");
        const UnitextDocblock = require("./UnitextDocblock");
        const UnitextFootnote = require("./UnitextFootnote");
        const UnitextNewline = require("./UnitextNewline");
        const UnitextPagebreak = require("./UnitextPagebreak");
        const UnitextTable = require("./UnitextTable");
        if (this.children === null || this.children.length === 0) {
            if (this.typ === UnitextContainerType.SHAPE) 
                return this;
            return null;
        }
        for (let i = 0; i < this.children.length; i++) {
            if (i === 17) {
            }
            let ch0 = this.children[i];
            ch0.parent = this;
            if (ch0 instanceof UnitextTable) {
            }
            let ch = ch0.optimize(false, pars);
            if (ch === null) {
                this.children.splice(i, 1);
                i--;
            }
            else 
                this.children[i] = ch;
        }
        if (this.children.length >= 30) {
        }
        for (let i = this.children.length - 1; i >= 0; i--) {
            let cnt = Utils.as(this.children[i], UnitextContainer);
            if (cnt === null) 
                continue;
            if (i === 0) {
            }
            if (cnt.pageSectionId !== null && this.pageSectionId !== null && cnt.pageSectionId !== this.pageSectionId) 
                continue;
            if (cnt.typ === UnitextContainerType.SHAPE && cnt.children.length > 0 && (cnt.children[cnt.children.length - 1] instanceof UnitextNewline)) {
                let nl = cnt.children[cnt.children.length - 1];
                cnt.children.splice(cnt.children.length - 1, 1);
                this.children.splice(i + 1, 0, nl);
                nl.parent = this;
                continue;
            }
            if (cnt.typ !== UnitextContainerType.UNDEFINED) 
                continue;
            this.children.splice(i, 1);
            for (const chh of cnt.children) {
                if (chh.pageSectionId === null) 
                    chh.pageSectionId = cnt.pageSectionId;
            }
            this.children.splice(i, 0, ...cnt.children);
        }
        if (this.children.length === 7) {
        }
        for (let i = 0; i < (this.children.length - 1); i++) {
            let ch = this.children[i];
            let ch1 = this.children[i + 1];
            if ((ch instanceof UnitextPagebreak) && (ch1 instanceof UnitextPagebreak)) {
                this.children.splice(i + 1, 1);
                i--;
                continue;
            }
            if (ch instanceof UnitextNewline) {
                if (ch1 instanceof UnitextNewline) {
                    let ii = 0;
                    for (ii = i + 1; ii < this.children.length; ii++) {
                        if (!(this.children[ii] instanceof UnitextNewline)) 
                            break;
                        else 
                            ch.count += this.children[ii].count;
                    }
                    this.children.splice(i + 1, ii - i - 1);
                    i--;
                }
                else if (ch1 instanceof UnitextPagebreak) {
                    this.children.splice(i, 1);
                    i--;
                }
                continue;
            }
            if ((ch instanceof UnitextTable) && !(ch1 instanceof UnitextNewline) && !(ch1 instanceof UnitextPagebreak)) {
                this.children.splice(i + 1, 0, new UnitextNewline());
                continue;
            }
            if ((ch instanceof UnitextPlaintext) && ch.isWhitespaces) {
                if ((ch1 instanceof UnitextNewline) || (ch1 instanceof UnitextPagebreak)) {
                    this.children.splice(i, 1);
                    i--;
                    if (i >= 0) 
                        i--;
                    continue;
                }
            }
            if ((ch instanceof UnitextContainer) && !ch.isInline && (ch1 instanceof UnitextNewline)) {
                ch.children.push(ch1);
                this.children.splice(i + 1, 1);
                i--;
                continue;
            }
            if ((ch instanceof UnitextContainer) && (ch1 instanceof UnitextContainer)) {
                let cnt = Utils.as(ch, UnitextContainer);
                let cnt1 = Utils.as(ch1, UnitextContainer);
                if (cnt.typ === cnt1.typ && cnt.pageSectionId === cnt1.pageSectionId) {
                    for (const chh of cnt1.children) {
                        if (chh.pageSectionId === null) 
                            chh.pageSectionId = cnt1.pageSectionId;
                    }
                    cnt.children.splice(cnt.children.length, 0, ...cnt1.children);
                    this.children.splice(i + 1, 1);
                    i--;
                    continue;
                }
            }
            if ((ch instanceof UnitextPlaintext) && (ch1 instanceof UnitextPlaintext)) {
                if (ch.typ === ch1.typ) {
                    if (ch.m_StyledFrag !== null && ch1.m_StyledFrag !== null && ch.m_StyledFrag.styleId !== ch1.m_StyledFrag.styleId) 
                        continue;
                    if (ch.pageSection !== ch1.pageSection) 
                        continue;
                    ch.mergeWith(Utils.as(ch1, UnitextPlaintext));
                    this.children.splice(i + 1, 1);
                    i--;
                    continue;
                }
            }
            if (pars !== null && !pars.correctParams.concatTables) {
            }
            else {
                if ((ch instanceof UnitextTable) && (ch1 instanceof UnitextTable) && ch.pageSectionId === ch1.pageSectionId) {
                    if (ch.tryAppend(Utils.as(ch1, UnitextTable))) {
                        this.children.splice(i + 1, 1);
                        i--;
                        continue;
                    }
                }
                if (((((i + 2) < this.children.length) && (ch instanceof UnitextTable) && (this.children[i + 2] instanceof UnitextTable)) && (ch1 instanceof UnitextNewline) && (ch1.count < 3)) && ch.tryAppend(Utils.as(this.children[i + 2], UnitextTable))) {
                    this.children.splice(i + 1, 1);
                    this.children.splice(i + 1, 1);
                    i--;
                    continue;
                }
            }
            if ((ch instanceof UnitextPlaintext) && (((ch1 instanceof UnitextNewline) || (ch1 instanceof UnitextPagebreak) || (ch1 instanceof UnitextFootnote)))) 
                ch.correct(LocCorrTyp.TRIMEND, null);
        }
        for (let i = 0; i < (this.children.length - 1); i++) {
            if ((this.children[i] instanceof UnitextDocblock) && (((this.children[i + 1] instanceof UnitextPagebreak) || (this.children[i + 1] instanceof UnitextNewline)))) {
                if (this.children[i]._appendChild(this.children[i + 1])) {
                    this.children.splice(i + 1, 1);
                    this.children[i].optimize(false, pars);
                    i--;
                }
            }
        }
        if (isContainer) {
            for (let i = this.children.length - 1; i >= 0; i--) {
                if (this.children[i].isWhitespaces) 
                    this.children.splice(i, 1);
                else 
                    break;
            }
            for (let i = 0; i < this.children.length; i++) {
                if (this.children[i].isWhitespaces) {
                    this.children.splice(i, 1);
                    i--;
                }
                else 
                    break;
            }
        }
        for (let i = 0; i < this.children.length; i++) {
            let co = UnitextContainer._getBoxChars(this.children[i]);
            if (co === 0) 
                continue;
            let i1 = i;
            let no = 1;
            let cou = 1;
            for (let j = i + 1; j < this.children.length; j++) {
                if (this.children[j].isWhitespaces) 
                    continue;
                co = UnitextContainer._getBoxChars(this.children[j]);
                if (co > 0) {
                    no = 1;
                    i1 = j;
                    cou++;
                    if (cou > 3) 
                        no++;
                    if (cou > 10) 
                        no++;
                }
                else {
                    co = UnitextContainer._getUnderlineChars(this.children[j]);
                    if (co > 10) {
                        no = 1;
                        i1 = j;
                        cou++;
                        if (cou > 3) 
                            no++;
                        if (cou > 10) 
                            no++;
                    }
                    if (co > 3) 
                        cou++;
                    else if ((--no) === 0) 
                        break;
                }
            }
            for (; (i1 + 1) < this.children.length; i1++) {
                if (!this.children[i1 + 1].isWhitespaces && (UnitextContainer._getUnderlineChars(this.children[i1 + 1]) < 3)) 
                    break;
            }
            for (let j = i - 1; j >= 0; j--) {
                if (this.children[j].isWhitespaces) 
                    continue;
                if (UnitextContainer._getUnderlineChars(this.children[j]) < 3) 
                    break;
                i = j;
            }
            if (i === 0 && i1 === (this.children.length - 1) && this.typ === UnitextContainerType.UNDEFINED) {
                this.typ = UnitextContainerType.MONOSPACE;
                break;
            }
            let cnt = UnitextContainer._new587(UnitextContainerType.MONOSPACE, this);
            for (let j = i; j <= i1; j++) {
                cnt.children.push(this.children[j]);
                this.children[j].parent = cnt;
            }
            this.children.splice(i, (i1 - i) + 1);
            this.children.splice(i, 0, cnt);
        }
        if (this.children.length === 0) 
            return null;
        if (this.typ !== UnitextContainerType.UNDEFINED) {
            if (this.children[0] instanceof UnitextPlaintext) {
                if (Utils.startsWithString(this.children[0].text.trim(), "КОНСУЛЬТАНТПЛЮС", true)) 
                    this.children[0].ignorable = true;
            }
        }
        if (this.children.length === 1) {
            if (this.typ === UnitextContainerType.SHAPE && (this.children[0] instanceof UnitextImage)) 
                return this.children[0];
            if (!this.isInline && this.children[0].isInline) 
                return this;
            if (this.children[0] instanceof UnitextContainer) {
                let ch = Utils.as(this.children[0], UnitextContainer);
                if (ch.typ === this.typ) {
                    if (this.children[0].pageSectionId === null) 
                        this.children[0].pageSectionId = this.pageSectionId;
                    if (this.id !== null && this.children[0].id === null) 
                        this.children[0].id = this.id;
                    return this.children[0];
                }
                if (this.typ === UnitextContainerType.HEAD || this.typ === UnitextContainerType.TAIL) {
                    if (ch.typ === UnitextContainerType.UNDEFINED) {
                        if (this.pageSectionId === null) 
                            this.pageSectionId = this.children[0].pageSectionId;
                        this.children.splice(0, this.children.length);
                        this.children.splice(this.children.length, 0, ...ch.children);
                    }
                    return this;
                }
            }
            if (this.typ === UnitextContainerType.UNDEFINED) {
                if (this.children[0].pageSectionId === null) 
                    this.children[0].pageSectionId = this.pageSectionId;
                if (this.id !== null && this.children[0].id === null) 
                    this.children[0].id = this.id;
                return this.children[0];
            }
        }
        for (let i = 0; i < (this.children.length - 1); i++) {
            let tab0 = Utils.as(this.children[i], UnitextTable);
            if (tab0 === null || (tab0.colsCount < 2)) 
                continue;
            let j = 0;
            let hasSpec = false;
            let txtLen = 0;
            let tab1 = null;
            for (j = i + 1; j < this.children.length; j++) {
                let ch = this.children[j];
                tab1 = Utils.as(ch, UnitextTable);
                if (tab1 !== null) 
                    break;
                if ((ch instanceof UnitextNewline) || (ch instanceof UnitextPagebreak)) 
                    continue;
                let pl = Utils.as(ch, UnitextPlaintext);
                if (pl === null) 
                    break;
                if (Utils.startsWithString(pl.text, "ВХ", true) || Utils.startsWithString(pl.text, "ИСХ", true)) 
                    hasSpec = true;
                txtLen += pl.text.length;
                if (txtLen > 200) 
                    break;
            }
            if (tab1 === null || !hasSpec) 
                continue;
            if (tab1.colsCount !== tab0.colsCount) 
                continue;
            if (!tab0.appendTable(tab1, true, false)) 
                continue;
            this.children.splice(i + 1, j - i);
            i--;
        }
        return this;
    }
    
    get innerTag() {
        return "cnt";
    }
    
    clone() {
        let res = new UnitextContainer();
        res._cloneFrom2(this);
        return res;
    }
    
    _cloneFrom2(src) {
        this._cloneFrom(src);
        this.typ = src.typ;
        this.htmlStyle = src.htmlStyle;
        this.htmlClass = src.htmlClass;
        this.data = src.data;
        this.userData = src.userData;
        this.m_IsInline = src.m_IsInline;
        for (const ch of src.children) {
            this.children.push(ch.clone());
        }
    }
    
    get startsOnNewline() {
        if (this.children.length === 0) 
            return false;
        return this.children[0].startsOnNewline;
    }
    
    findById(_id) {
        if (this.id === _id) 
            return this;
        for (const ch of this.children) {
            let res = ch.findById(_id);
            if (res !== null) 
                return res;
        }
        return null;
    }
    
    /**
     * Получить индекс дочернего элемента из списка Children (работает быстро)
     * @param it исколмый элемент
     * @return индекс или -1
     */
    getChildIndexOf(it) {
        if ((it.beginChar > 0 && this.children.length > 20 && this.beginChar <= it.beginChar) && it.endChar <= this.endChar) {
            let i = Utils.intDiv(this.children.length, 2);
            let d = Utils.intDiv(this.children.length, 4);
            if (d === 0) 
                d = 1;
            let k = d + 2;
            while (k > 0) {
                if (i >= this.children.length || (i < 0)) 
                    break;
                if (this.children[i] === it) 
                    return i;
                if (this.children[i].beginChar < it.beginChar) 
                    i += d;
                else if (this.children[i].endChar > it.beginChar) 
                    i -= d;
                else 
                    i += d;
                d = Utils.intDiv(d, 2);
                if (d === 0) {
                    d = 1;
                    k--;
                }
            }
        }
        return this.children.indexOf(it);
    }
    
    toString() {
        let res = ((this.typ === UnitextContainerType.UNDEFINED ? "Container" : this.typ.toString()) + " " + (this.children === null ? 0 : this.children.length) + " items");
        if (this.htmlTitle !== null) 
            res = (res + " " + this.htmlTitle);
        return res;
    }
    
    getPlaintext(res, pars) {
        if (pars !== null && pars.setPositions) 
            this.beginChar = res.length;
        if (this.ignorable && pars !== null) 
            pars.ignoreLevel++;
        if (this.children === null || this.children.length === 0) {
        }
        else if (this.typ === UnitextContainerType.SHAPE && pars !== null && pars.ignoreShapes) {
        }
        else {
            if (this.typ === UnitextContainerType.SHAPE && pars !== null && res.length > 0) {
                let ch = res.charAt(res.length - 1);
                if (Utils.isLetterOrDigit(ch)) 
                    res.append(pars.newLine);
            }
            for (const ch of this.children) {
                ch.getPlaintext(res, (pars != null ? pars : UnitextItem.m_DefParams));
                if (pars !== null && pars.maxTextLength > 0 && res.length > pars.maxTextLength) 
                    break;
            }
            if (this.typ === UnitextContainerType.SHAPE && pars !== null) 
                res.append(pars.newLine);
        }
        if (pars !== null && pars.setPositions) 
            this.endChar = res.length - 1;
        if (this.ignorable && pars !== null) 
            pars.ignoreLevel--;
    }
    
    getHtml(res, par) {
        const UnitextDocblock = require("./UnitextDocblock");
        const UnitextNewline = require("./UnitextNewline");
        const UnitextDocument = require("./UnitextDocument");
        if (par.hideEditionsAndComments) {
            if (this.typ === UnitextContainerType.EDITION || this.typ === UnitextContainerType.COMMENT) 
                return;
        }
        if (!par.callBefore(this, res)) 
            return;
        let _id = "";
        if (this.id !== null) 
            _id = (" id=\"" + this.id + "\"");
        if (par !== null && par.outBeginEndChars && this.beginChar <= this.endChar) 
            _id = (_id + " bc=\"" + this.beginChar + "\" ec=\"" + this.endChar + "\"");
        if (((this.children === null || this.children.length === 0)) && this.typ !== UnitextContainerType.SHAPE && this.typ !== UnitextContainerType.FORMULA) {
            par.callAfter(this, res);
            return;
        }
        let isDiv = false;
        let isSpan = false;
        let isPre = false;
        let tit = (this.typ === UnitextContainerType.UNDEFINED ? "" : this.typ.toString().toLowerCase());
        if (this.htmlTitle !== null) {
            let tmp = new StringBuilder();
            MiscHelper.correctHtmlValue(tmp, this.htmlTitle, true, false, false);
            tit = tmp.toString();
        }
        else 
            for (let p = this.parent; p !== null; p = p.parent) {
                if (p.htmlTitle !== null) {
                    tit = "";
                    break;
                }
            }
        if (!Utils.isNullOrEmpty(tit)) 
            tit = (" title=\"" + tit + "\"");
        if (!Utils.isNullOrEmpty(this.htmlClass)) 
            tit = (tit + " class=\"" + this.htmlClass + "\"");
        let style = null;
        if (par !== null && this.id !== null && par.styles.containsKey(this.id)) 
            style = par.styles.get(this.id);
        if (style === null) 
            style = this.htmlStyle;
        if (this.htmlClass !== null) {
            isDiv = !this.isInline;
            isSpan = !isDiv;
            if (isDiv) 
                res.append("\r\n");
            res.append("<").append((isDiv ? "div" : "span")).append(" ").append(_id).append(tit).append(">");
        }
        else if (style !== null) {
            isDiv = !this.isInline;
            isSpan = !isDiv;
            if (isDiv) 
                res.append("\r\n");
            res.append("<").append((isDiv ? "div" : "span")).append(" style=\"").append(style).append("\" ").append(_id).append(tit).append(">");
        }
        else if (this.typ === UnitextContainerType.SHAPE) {
            res.append("\r\n<div style=\"border-width:2pt;border-color:green;border-style:dotted;margin:10pt;padding:5pt\" ").append(_id).append(tit).append(">");
            isDiv = true;
        }
        else if (this.typ === UnitextContainerType.FORMULA) {
            isDiv = !this.isInline;
            isSpan = !isDiv;
            if (isDiv) 
                res.append("\r\n");
            res.append("\r\n<").append((isDiv ? "div" : "span")).append(" style=\"border-width:2pt;border-color:blue;border-style:dotted;margin:5pt;padding:5pt\" ").append(tit).append(_id).append(">");
        }
        else if (this.typ === UnitextContainerType.MONOSPACE) {
            res.append("\r\n<div style=\"font-family:monospace\" ").append(_id).append(tit).append(">");
            res.append("<pre>");
            isDiv = true;
            isPre = true;
        }
        else if (this.typ === UnitextContainerType.CONTENTCONTROL) {
            isDiv = !this.isInline;
            isSpan = !isDiv;
            if (isDiv) 
                res.append("\r\n");
            res.append("<").append((isDiv ? "div" : "span")).append(" style=\"background-color:lightyellow;border:1pt solid black\" ").append(_id).append(tit).append(">");
        }
        else if (this.typ === UnitextContainerType.RIGHTALIGN) {
            res.append("\r\n<div style=\"font-weight:normal;font-style:italic;text-align:right\" ").append(_id).append(tit).append(">");
            isDiv = true;
        }
        else if (this.typ === UnitextContainerType.EDITION || this.typ === UnitextContainerType.COMMENT) {
            if (this.typ === UnitextContainerType.COMMENT && this.isInline) 
                isSpan = true;
            else {
                isDiv = true;
                res.append("\r\n");
            }
            res.append("<").append((isSpan ? "span" : "div")).append(" ").append(_id).append(" style=\"font-weight: normal;font-style: italic;").append("font-size: smaller;color: gray").append("\"").append(tit).append(">");
        }
        else if (((this.typ === UnitextContainerType.HEAD || ((this.typ === UnitextContainerType.NAME && (this.parent instanceof UnitextDocblock))))) && !this.isInline) {
            let ali = "center";
            let marg = 10;
            let db = Utils.as(this.parent, UnitextDocblock);
            if (db !== null && db.typname !== null) {
                if (((Utils.compareStrings(db.typname, "Clause", true) === 0 || Utils.compareStrings(db.typname, "Mail", true) === 0 || Utils.compareStrings(db.typname, "Chapter", true) === 0) || Utils.compareStrings(db.typname, "Paragraph", true) === 0 || Utils.compareStrings(db.typname, "SubParagraph", true) === 0) || Utils.compareStrings(db.typname, "Section", true) === 0 || Utils.compareStrings(db.typname, "Subsection", true) === 0) {
                    ali = "left";
                    marg = 10;
                }
            }
            res.append("\r\n<div style=\"text-align:").append(ali).append(";margin-bottom:").append(marg).append("pt\" ").append(_id).append(tit).append(">");
            isDiv = true;
        }
        else if (this.typ === UnitextContainerType.DIRECTIVE) {
            res.append("\r\n<div style=\"text-align:center;text-decoration:underline\" ").append(_id).append(tit).append(">");
            isDiv = true;
        }
        else if (this.typ === UnitextContainerType.TAIL) {
            res.append("\r\n<div style=\"text-align:right\" ").append(_id).append(tit).append(">");
            isDiv = true;
        }
        else if (this.typ === UnitextContainerType.HIGHLIGHTING) {
            res.append("<span style=\"background-color:yellow\" ").append(_id).append(tit).append(">");
            isSpan = true;
        }
        else if (this.typ !== UnitextContainerType.UNDEFINED) {
            if (this.parent !== null && (this.parent.parent instanceof UnitextDocblock) && Utils.compareStrings((this.parent.parent.typname != null ? this.parent.parent.typname : ""), "INDEXITEM", true) === 0) {
                res.append("<span").append(_id).append(((tit != null ? tit : ""))).append(">");
                isSpan = true;
            }
            else 
                res.append("<b ").append(_id).append(((tit != null ? tit : ""))).append(">");
        }
        else if (((this.parent instanceof UnitextDocument) && par !== null && par.outStyles) && this.m_StyledFrag !== null && this.m_StyledFrag.style !== null) {
            res.append("\r\n<div").append(_id).append(" style=\"");
            this.m_StyledFrag.style.getHtml(res);
            res.append("\"").append(tit).append(">");
            isDiv = true;
        }
        else if (!Utils.isNullOrEmpty(_id)) {
            res.append("<span").append(_id).append(((tit != null ? tit : ""))).append(">");
            isSpan = true;
        }
        let outStyles = false;
        if (par !== null && par.outStyles && !this.isInline) {
            if (this.getStyledFragment(-1) !== null) 
                outStyles = true;
        }
        let curStFr = null;
        if (this.children.length === 13) {
        }
        for (let i = 0; i < this.children.length; i++) {
            let ch = this.children[i];
            if (i === 9) {
            }
            if (ch instanceof UnitextNewline) {
                if (ch.count === 1) {
                    if (((i + 1) < this.children.length) && this.children[i + 1].startsOnNewline) 
                        continue;
                    if ((i + 1) === this.children.length && this.parent !== null && !this.parent.isInline) 
                        continue;
                }
            }
            if (outStyles) {
                let fr = ch.getStyledFragment(-1);
                if (fr !== null && fr.typ === UnitextStyledFragmentType.INLINE) 
                    fr = fr.parent;
                if (fr === null) {
                    if (curStFr !== null) {
                        curStFr = null;
                        res.append("</").append((isSpan ? "span" : "div")).append(">");
                    }
                }
                else if (fr !== curStFr) {
                    if (curStFr !== null) 
                        res.append("</div>");
                    curStFr = null;
                    if (fr.styleId > 0 && fr.style !== null) {
                        curStFr = fr;
                        res.append("\r\n<").append((isSpan ? "span" : "div")).append(" style=\"");
                        fr.style.getHtml(res);
                        res.append("\">");
                    }
                }
            }
            ch.getHtml(res, par);
            if (par !== null && res.length > par.maxHtmlSize) 
                break;
        }
        if (curStFr !== null) 
            res.append("</").append((isSpan ? "span" : "div")).append(">");
        if (isPre) 
            res.append("</pre>");
        if (isDiv) {
            res.append("</div>\r\n");
            if (par !== null) 
                par._outFootnotes(res);
        }
        else if (isSpan) 
            res.append("</span>");
        else if (this.typ !== UnitextContainerType.UNDEFINED) 
            res.append("</b>");
        par.callAfter(this, res);
    }
    
    getXml(xml) {
        xml.writeStartElement("container");
        this._writeXmlAttrs(xml);
        if (this.typ !== UnitextContainerType.UNDEFINED) 
            xml.writeAttributeString("type", this.typ.toString().toLowerCase());
        if (this.data !== null) 
            xml.writeAttributeString("data", MiscHelper.correctXmlValue(this.data));
        if (!Utils.isNullOrEmpty(this.htmlStyle)) 
            xml.writeAttributeString("style", MiscHelper.correctXmlValue(this.htmlStyle));
        if (this.m_IsInline >= 0) 
            xml.writeAttributeString("inline", (this.m_IsInline > 0 ? "true" : "false"));
        for (const ch of this.children) {
            ch.getXml(xml);
        }
        xml.writeEndElement();
    }
    
    fromXml(xml) {
        const UnitextHelper = require("./internal/uni/UnitextHelper");
        super.fromXml(xml);
        if (xml.attributes !== null) {
            for (const a of xml.attributes) {
                if (a.local_name === "type") {
                    try {
                        this.typ = UnitextContainerType.of(a.value);
                    } catch (ex588) {
                    }
                }
                else if (a.local_name === "data") 
                    this.data = a.value;
                else if (a.local_name === "style") 
                    this.htmlStyle = a.value;
                else if (a.local_name === "inline") 
                    this.m_IsInline = (a.value === "true" ? 1 : 0);
            }
        }
        for (const x of xml.child_nodes) {
            let it = UnitextHelper.createItem(x, this);
            if (it !== null) 
                this.children.push(it);
        }
    }
    
    get isWhitespaces() {
        for (const ch of this.children) {
            if (!ch.isWhitespaces) 
                return false;
        }
        return true;
    }
    
    get isInline() {
        const UnitextDocument = require("./UnitextDocument");
        const UnitextListitem = require("./UnitextListitem");
        if (this.m_IsInline >= 0) 
            return this.m_IsInline > 0;
        if (this.parent instanceof UnitextListitem) 
            return false;
        if (this.children !== null) {
            for (const ch of this.children) {
                if (!ch.isInline) 
                    return false;
            }
        }
        if (this.parent === null || (this.parent instanceof UnitextDocument)) 
            return false;
        return true;
    }
    set isInline(value) {
        this.m_IsInline = (value ? 1 : 0);
        return value;
    }
    
    getAllItems(res, lev) {
        if (lev > 20) {
        }
        if (res !== null) 
            res.push(this);
        if (this.children !== null) {
            for (const ch of this.children) {
                ch.parent = this;
                ch.getAllItems(res, lev + 1);
            }
        }
    }
    
    addPlainTextPos(d) {
        super.addPlainTextPos(d);
        for (const ch of this.children) {
            ch.addPlainTextPos(d);
        }
    }
    
    correct(_typ, _data) {
        for (const ch of this.children) {
            ch.correct(_typ, _data);
        }
    }
    
    replaceChild(old, ne) {
        let i = this.getChildIndexOf(old);
        if (i < 0) 
            return false;
        this.children[i] = ne;
        ne.parent = this;
        return true;
    }
    
    setDefaultTextPos(cp, res) {
        this.beginChar = cp.value;
        for (const ch of this.children) {
            ch.setDefaultTextPos(cp, res);
            ch.parent = this;
        }
        this.endChar = cp.value - 1;
    }
    
    static _new94(_arg1) {
        let res = new UnitextContainer();
        res.typ = _arg1;
        return res;
    }
    
    static _new396(_arg1) {
        let res = new UnitextContainer();
        res.endChar = _arg1;
        return res;
    }
    
    static _new401(_arg1, _arg2, _arg3, _arg4) {
        let res = new UnitextContainer();
        res.parent = _arg1;
        res.beginChar = _arg2;
        res.endChar = _arg3;
        res.id = _arg4;
        return res;
    }
    
    static _new451(_arg1, _arg2) {
        let res = new UnitextContainer();
        res.typ = _arg1;
        res.m_StyledFrag = _arg2;
        return res;
    }
    
    static _new587(_arg1, _arg2) {
        let res = new UnitextContainer();
        res.typ = _arg1;
        res.parent = _arg2;
        return res;
    }
    
    static _new590(_arg1) {
        let res = new UnitextContainer();
        res.beginChar = _arg1;
        return res;
    }
    
    static _new595(_arg1, _arg2, _arg3) {
        let res = new UnitextContainer();
        res.beginChar = _arg1;
        res.endChar = _arg2;
        res.parent = _arg3;
        return res;
    }
}


module.exports = UnitextContainer