/*
 * 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 Hashtable = require("./../../../unisharp/Hashtable");
const RefOutArgWrapper = require("./../../../unisharp/RefOutArgWrapper");
const StringBuilder = require("./../../../unisharp/StringBuilder");
const Stream = require("./../../../unisharp/Stream");

const UnitextPlaintext = require("./../../UnitextPlaintext");
const UnitextImage = require("./../../UnitextImage");
const UnitextContainer = require("./../../UnitextContainer");
const UnitextItem = require("./../../UnitextItem");
const Sprm = require("./Sprm");
const StyleDefinition = require("./StyleDefinition");
const UnitextPlaintextType = require("./../../UnitextPlaintextType");
const IUnitextGenNumStyle = require("./../uni/IUnitextGenNumStyle");
const UnitextHyperlink = require("./../../UnitextHyperlink");
const UnitextList = require("./../../UnitextList");
const UnitextGenNumStyle = require("./../uni/UnitextGenNumStyle");
const StyleCollection = require("./StyleCollection");
const UniTextGenNumType = require("./../uni/UniTextGenNumType");
const UniTextGenNumLevel = require("./../uni/UniTextGenNumLevel");
const DocNumStyles = require("./DocNumStyles");
const CharacterFormatting = require("./CharacterFormatting");
const Prl = require("./Prl");
const Paragraph = require("./Paragraph");
const MiscHelper = require("./../../../util/MiscHelper");
const FcCompressedMapping = require("./FcCompressedMapping");
const UniTextGenCell = require("./../uni/UniTextGenCell");
const UnitextComment = require("./../../UnitextComment");
const BasicTypesReader = require("./BasicTypesReader");
const UnitextFootnote = require("./../../UnitextFootnote");
const WingdingsHelper = require("./../misc/WingdingsHelper");
const SinglePropertyModifiers = require("./SinglePropertyModifiers");
const ExtendedName = require("./ExtendedName");
const FibStructuresReader = require("./FibStructuresReader");
const MSOfficeHelper = require("./MSOfficeHelper");
const FibRbFcLcb97 = require("./FibRbFcLcb97");
const FibRgLw97 = require("./FibRgLw97");
const UnitextPagesection = require("./../../UnitextPagesection");
const UnitextTable = require("./../../UnitextTable");
const UnitextPagesectionItem = require("./../../UnitextPagesectionItem");
const UnitextGenTable = require("./../uni/UnitextGenTable");
const UnitextGen = require("./../uni/UnitextGen");
const FormattingLevel = require("./FormattingLevel");
const ReadUtils = require("./ReadUtils");
const UnitextContainerType = require("./../../UnitextContainerType");

// Word document model.
// See specification for explanations.
// [MS-DOC]: Word Binary File Format (.doc) Structure Specification
// Release: Thursday, August 27, 2009
class WordDocument {
    
    constructor() {
        this.text = new StringBuilder();
        this.fileCharacterPositions = null;
        this.m_Paragraphs = new Array();
        this.m_Formattings = null;
        this.m_StyleDefinitionsMap = null;
        this.defaultPrls = null;
        this.m_NumStyles = new Hashtable();
        this.comment = null;
        this.m_Error = false;
        this.m_Footnotes = new Hashtable();
        this.m_Comments = new Hashtable();
        this.m_SuperTexts = new Hashtable();
        this.m_SubTexts = new Hashtable();
        this.m_Shapes = new Hashtable();
        this.m_Dels = null;
        this.lfos = new Array();
        this.lstfs = new Array();
    }
    
    get paragraphs() {
        return this.m_Paragraphs;
    }
    
    get formattings() {
        return this.m_Formattings;
    }
    
    get styleDefinitions() {
        return this.m_StyleDefinitionsMap.values;
    }
    
    get styleDefinitionsMap() {
        return this.m_StyleDefinitionsMap;
    }
    
    load(system, doc = null) {
        let wordDocumentStreamName = "WordDocument";
        let str = system.getRootStorage();
        let wordDocumentStorage = str.findStorage(ExtendedName.fromString(wordDocumentStreamName));
        let wordDocumentStream = wordDocumentStorage.createStream(); 
        try {
            let fib = null;
            fib = FibStructuresReader.readFib(wordDocumentStream);
            if (fib !== null) {
                let tableStreamName = WordDocument.getTableStreamName(fib);
                let tableStorage = system.getRootStorage().findStorage(ExtendedName.fromString(tableStreamName));
                if (tableStorage !== null) {
                    let tableStream = tableStorage.createStream(); 
                    try {
                        this.loadContent(wordDocumentStream, tableStream, fib, doc);
                    }
                    finally {
                        tableStream.close();
                    }
                }
            }
            else {
                wordDocumentStream.position = 0;
                let buf = new Uint8Array(wordDocumentStream.length);
                let i = wordDocumentStream.read(buf, 0, buf.length);
                if (i < 0x20) 
                    return;
                let ddd = MSOfficeHelper._uniFromWord6orEarly(buf);
                if (ddd !== null) 
                    doc.content = ddd.content;
            }
        }
        finally {
            wordDocumentStream.close();
        }
    }
    
    static getTableStreamName(fib) {
        return (fib._base.fWhichTblStm ? "1Table" : "0Table");
    }
    
    loadContent(wordDocumentStream, tableStream, fib, doc) {
        let fib97 = Utils.as(fib.fibRgLw, FibRgLw97);
        if (fib97 === null) 
            return;
        let fibLc97 = Utils.as(fib.fibRgFcLcbBlob, FibRbFcLcb97);
        if (fibLc97 === null) 
            return;
        let pos = fibLc97.fcClx;
        tableStream.position = pos;
        let iii = fibLc97.lcbClx;
        let clx = BasicTypesReader.readClx(tableStream, iii);
        this.loadCharacters(wordDocumentStream, clx);
        try {
            let plcfBtePapxOffset = fib.fibRgFcLcbBlob.fcPlcfBtePapx;
            tableStream.position = plcfBtePapxOffset;
            let plcfBtePapxLength = fib.fibRgFcLcbBlob.lcbPlcfBtePapx;
            let plcfBtePapx = BasicTypesReader.readPlcfBtePapx(tableStream, plcfBtePapxLength);
            this.loadParagraphs(wordDocumentStream, clx, plcfBtePapx);
            let plcfBteChpxOffset = fib.fibRgFcLcbBlob.fcPlcfBteChpx;
            tableStream.position = plcfBteChpxOffset;
            let plcfBteChpxLength = fib.fibRgFcLcbBlob.lcbPlcfBteChpx;
            let plcBteChpx = BasicTypesReader.readPlcBteChpx(tableStream, plcfBteChpxLength);
            this.loadCharacterFormatting(wordDocumentStream, plcBteChpx);
            let stshOffset = fib.fibRgFcLcbBlob.fcStshf;
            tableStream.position = stshOffset;
            let stshLength = fib.fibRgFcLcbBlob.lcbStshf;
            let stsh = BasicTypesReader.readStsh(tableStream, stshLength);
            this.loadStsh(wordDocumentStream, stsh);
            tableStream.position = fibLc97.fcPlfLfo;
            this.loadLFOS(tableStream, fibLc97.lcbPlfLfo);
            tableStream.position = fibLc97.fcPlfLst;
            this.loadLSTFs(tableStream, fibLc97.lcbPlfLst);
        } catch (ex) {
        }
        if (doc !== null) {
            this.m_Dels = new Uint8Array(this.text.length);
            if (this.m_Formattings !== null) {
                for (const f of this.m_Formattings) {
                    if (f.length === 1) {
                        let dat = f.getProperty(SinglePropertyModifiers.sprmCSymbol);
                        if (dat !== null && dat.length === 4) {
                            let nnn = dat[3];
                            nnn <<= (8);
                            nnn |= (dat[2]);
                            if (Utils.compareUnsigned(nnn, 0xF000) > 0) 
                                nnn -= (0xF000);
                            if (f.pos >= 0 && (f.pos < this.text.length)) {
                                let ch0 = this.text.charAt(f.pos);
                                this.text.setCharAt(f.pos, WingdingsHelper.getUnicode(nnn));
                                if (this.text.charAt(f.pos) === (String.fromCharCode(0))) 
                                    this.text.setCharAt(f.pos, String.fromCharCode(nnn));
                            }
                        }
                    }
                    let sty = f.getStyles(FormattingLevel.CHARACTER);
                    if (sty !== null) {
                        if (sty.toString().includes("CFRMarkDel")) {
                            for (let ii = f.pos; ii < (f.pos + f.length); ii++) {
                                this.m_Dels[ii] = 1;
                            }
                        }
                    }
                }
            }
            let totalText = this.text.toString();
            let gen = new UnitextGen();
            if (this.m_Paragraphs === null || this.m_Paragraphs.length === 0) {
                gen.appendText(totalText, false);
                doc.content = gen.finish(true, null);
                return;
            }
            if (this.m_Formattings !== null) {
                for (let i = 0; i < this.m_Formattings.length; i++) {
                    let f = this.m_Formattings[i];
                    let dat = f.getProperty(SinglePropertyModifiers.sprmCIss);
                    if (f.pos > (84223 - 10) && (f.pos < (84223 + 10))) {
                    }
                    if ((dat !== null && dat.length === 1 && dat[0] === (1)) && (f.length < 10)) {
                        let tmp = totalText.substring(f.pos, f.pos + f.length);
                        if (!this.m_SuperTexts.containsKey(f.pos)) 
                            this.m_SuperTexts.put(f.pos, tmp);
                    }
                    if ((dat !== null && dat.length === 1 && dat[0] === (2)) && (f.length < 10)) {
                        let tmp = totalText.substring(f.pos, f.pos + f.length);
                        if (!this.m_SubTexts.containsKey(f.pos)) 
                            this.m_SubTexts.put(f.pos, tmp);
                    }
                }
            }
            for (let k = 0; k < 2; k++) {
                tableStream.position = (k === 0 ? fibLc97.fcPlcffndRef : fibLc97.fcPlcfendRef);
                let cps = BasicTypesReader.readCPs(tableStream, (k === 0 ? fibLc97.lcbPlcffndRef : fibLc97.lcbPlcfendRef));
                tableStream.position = (k === 0 ? fibLc97.fcPlcffndTxt : fibLc97.fcPlcfendTxt);
                let cps2 = BasicTypesReader.readCPs(tableStream, (k === 0 ? fibLc97.lcbPlcffndTxt : fibLc97.lcbPlcfendTxt));
                if (cps.length > 2 && gen !== null) {
                    let pos0 = fib97.ccpText;
                    let len = fib97.ccpFtn;
                    if (k === 1) {
                        pos0 += (((fib97.ccpFtn) + (fib97.ccpHdd) + (fib97.ccpAtn)));
                        len = fib97.ccpEdn;
                    }
                    let ttt = totalText.substring(pos0, pos0 + len);
                    for (let i = 0; (i < (cps.length - 2)) && (i < cps2.length); i++) {
                        let cp = cps[i];
                        if ((cp < 0) || cp >= pos0) 
                            continue;
                        let ge = new UnitextGen();
                        let max = ((i + 1) < (cps2.length - 2) ? cps2[i + 1] : len);
                        this._createUni(ge, null, 0, pos0 + cps2[i], pos0 + max, totalText, 0);
                        if (!this.m_Footnotes.containsKey(cp)) {
                            let fn = UnitextFootnote._new513(k === 1, ge.finish(true, null));
                            this.m_Footnotes.put(cp, fn);
                        }
                    }
                }
            }
            tableStream.position = fibLc97.fcPlcfandTxt;
            let cpsat2 = BasicTypesReader.readCPs(tableStream, fibLc97.lcbPlcfandTxt);
            tableStream.position = fibLc97.fcPlcfandRef;
            let cpsat = BasicTypesReader.readCPs(tableStream, cpsat2.length * 4);
            if (cpsat.length === cpsat2.length) {
                let pos0 = ((fib97.ccpText) + (fib97.ccpFtn) + (fib97.ccpHdd));
                let len = fib97.ccpAtn;
                let ttt = totalText.substring(pos0, pos0 + len);
                for (let i = 0; i < (cpsat.length - 2); i++) {
                    let cp = cpsat[i];
                    if ((cp < 0) || cp >= pos0) 
                        continue;
                    let ge = new UnitextGen();
                    let max = ((i + 1) < (cpsat.length - 2) ? cpsat2[i + 1] : len);
                    this._createUni(ge, null, 0, pos0 + cpsat2[i], pos0 + max, totalText, 0);
                    let cc = ge.finish(true, null);
                    if (cc === null) 
                        continue;
                    let tmp = new StringBuilder();
                    cc.getPlaintext(tmp, null);
                    if (tmp.length < 1) 
                        continue;
                    let cmt = UnitextComment._new50(tmp.toString());
                    this.m_Comments.put(cp, cmt);
                }
            }
            if (Utils.compareUnsigned(fib97.ccpTxbx, 0) > 0) {
                let pos0 = ((fib97.ccpText) + (fib97.ccpFtn) + (fib97.ccpHdd)) + (fib97.ccpAtn) + (fib97.ccpEdn);
                let len = fib97.ccpTxbx;
                let ttt = totalText.substring(pos0, pos0 + len);
                if (Utils.compareUnsigned(fibLc97.lcbPlcfTxbxBkd, 0) > 0 && Utils.compareUnsigned(fibLc97.lcbPlcftxbxTxt, 0) > 0) {
                    tableStream.position = fibLc97.fcPlcftxbxTxt;
                    let k2 = (Utils.intDiv(((fibLc97.lcbPlcftxbxTxt) - 4), 26));
                    let cps2 = BasicTypesReader.readCPs(tableStream, ((k2 + 1)) * 4);
                    let texts2 = new Array();
                    for (let ii = 0; ii < (cps2.length - 2); ii++) {
                        let ge = new UnitextGen();
                        let max = ((ii + 1) < (cps2.length - 2) ? cps2[ii + 1] : len);
                        this._createUni(ge, null, 0, pos0 + cps2[ii], pos0 + max, totalText, 0);
                        let cc = ge.finish(true, null);
                        let cnt = UnitextContainer._new94(UnitextContainerType.SHAPE);
                        if (cc !== null) 
                            cnt.children.push(cc);
                        texts2.push(cnt);
                    }
                    let lids = new Array();
                    for (let ii = 0; ii < k2; ii++) {
                        tableStream.position = tableStream.position + (14);
                        lids.push(ReadUtils.readInt(tableStream));
                        tableStream.position = tableStream.position + (4);
                    }
                    tableStream.position = fibLc97.fcPlcSpaMom;
                    let kk = (Utils.intDiv(((fibLc97.lcbPlcSpaMom) - 4), 30));
                    let cps3 = BasicTypesReader.readCPs(tableStream, ((kk + 1)) * 4);
                    let lids2 = new Array();
                    for (let ii = 0; ii < kk; ii++) {
                        lids2.push(ReadUtils.readInt(tableStream));
                        tableStream.position = tableStream.position + (22);
                    }
                    for (let ii = lids2.length - 1; ii >= 0; ii--) {
                        let j = lids.indexOf(lids2[ii]);
                        if (j >= 0) {
                            this.m_Shapes.put(cps3[ii], texts2[j]);
                            texts2.splice(j, 1);
                            lids.splice(j, 1);
                            lids2.splice(ii, 1);
                            cps3.splice(ii, 1);
                        }
                    }
                    for (let ii = lids2.length - 1; ii >= 0; ii--) {
                        let cnt = new UnitextContainer();
                        for (let j = lids.length - 1; j >= 0; j--) {
                            if (lids[j] > lids2[ii]) {
                                cnt.children.splice(0, 0, texts2[j]);
                                lids.splice(j, 1);
                                texts2.splice(j, 1);
                            }
                        }
                        if (cnt.children.length > 0) 
                            this.m_Shapes.put(cps3[ii], cnt);
                    }
                }
            }
            this._createUni(gen, null, 0, 0, fib97.ccpText, totalText, 0);
            doc.content = gen.finish(true, null);
            if (Utils.compareUnsigned(fibLc97.lcbPlcfHdd, 0) != 0) {
                tableStream.position = fibLc97.fcPlcfHdd;
                let strs = BasicTypesReader.readCPs(tableStream, fibLc97.lcbPlcfHdd);
                if (strs.length > 7) {
                    let pos0 = (fib97.ccpText) + (fib97.ccpFtn);
                    let len = fib97.ccpHdd;
                    let sub = totalText.substring(pos0, pos0 + len);
                    let sect = new UnitextPagesection();
                    for (let k = 0; k < 2; k++) {
                        let gg = new UnitextGen();
                        for (let ii = 0; ii < 2; ii++) {
                            let jj = 7 + ii;
                            if (k > 0) 
                                jj += 2;
                            if ((jj < strs.length) && (strs[jj] < strs[jj + 1])) 
                                this._createUni(gg, null, 0, pos0 + strs[jj], (pos0 + strs[jj + 1]) - 1, totalText, 0);
                        }
                        let fi = gg.finish(true, null);
                        if (fi !== null) 
                            sect.items.push(UnitextPagesectionItem._new276(fi, k > 0));
                    }
                    if (sect.items.length > 0) 
                        doc.sections.push(sect);
                }
            }
            return;
        }
    }
    
    _createUni(gen, blk, i0, p0, p1, txt, level) {
        if (level > 30) 
            return;
        if (i0 === 32) {
        }
        let tmp = new StringBuilder();
        for (let i = i0; i < this.m_Paragraphs.length; i++) {
            let p = this.m_Paragraphs[i];
            if (p.pos === 496) {
            }
            if (p.pos >= p1) 
                break;
            if ((p.pos < p0) || (p.pos + p.length) > p1) 
                continue;
            if (gen !== null) {
            }
            let data = [ ];
            if (p.isInTable && gen !== null && blk === null) {
                let tab = new UnitextGenTable();
                let ro = new Array();
                let allids = new Array();
                let hasHugePapxRows = new Array();
                let cgen = new UnitextGen();
                for (; i < this.m_Paragraphs.length; i++) {
                    let pp = this.m_Paragraphs[i];
                    if (!pp.isInTable && pp.isTableCellEnd && pp.length <= 2) {
                        if (ro.length > 0) {
                            data = pp.getProperty(SinglePropertyModifiers.sprmPHugePapx);
                            if (data !== null) 
                                hasHugePapxRows.push(tab.cells.length);
                            tab.cells.push(ro);
                        }
                        ro = new Array();
                        continue;
                    }
                    if (!pp.isInTable) {{
                                i--;
                                break;
                            }
                    }
                    if (pp.tableDepth < p.tableDepth) {{
                                i--;
                                break;
                            }
                    }
                    if (pp.tableDepth > p.tableDepth) {
                        let i1 = 0;
                        for (i1 = i + 1; i1 < this.m_Paragraphs.length; i1++) {
                            if (pp.tableDepth > this.m_Paragraphs[i1].tableDepth && this.m_Paragraphs[i1].tableDepth === p.tableDepth) 
                                break;
                        }
                        let gt = new UnitextGen();
                        this._createUni(cgen, null, i, pp.pos, this.m_Paragraphs[i1 - 1].pos + this.m_Paragraphs[i1 - 1].length, txt, level + 1);
                        i = i1;
                        if (i1 < this.m_Paragraphs.length) 
                            pp = this.m_Paragraphs[i1];
                    }
                    if (pp.isTableRowEnd) {
                        data = pp.getProperty(SinglePropertyModifiers.sprmTDefTable);
                        if (data !== null && data.length > 0) {
                            let cou = data[0];
                            if (cou === ro.length) {
                                for (let ii = 1, cc = 0; (ii < data.length) && (cc < ro.length); ii += 2,cc++) {
                                    let iid = data[ii + 1];
                                    iid <<= (8);
                                    iid |= (data[ii]);
                                    ro[cc].tag = iid;
                                    if (!allids.includes(iid)) 
                                        allids.push(iid);
                                }
                            }
                        }
                        if (ro.length > 0) 
                            tab.cells.push(ro);
                        ro = new Array();
                        continue;
                    }
                    this._createUni(cgen, new UnitextTable(), i, pp.pos, pp.pos + pp.length, txt, level + 1);
                    if (pp.isTableCellEnd) {
                        let cel = new UniTextGenCell();
                        ro.push(cel);
                        cel.content = cgen.finish(true, null);
                        cgen = new UnitextGen();
                    }
                }
                if (ro.length > 0) 
                    tab.cells.push(ro);
                for (let ii = 0; ii < tab.cells.length; ii++) {
                    let hasColSpan = false;
                    for (let jj = 0; jj < tab.cells[ii].length; jj++) {
                        let cel = tab.cells[ii][jj];
                        let cid = allids.indexOf(cel.tag);
                        if (cid < 0) 
                            continue;
                        if ((jj + 1) === tab.cells[ii].length) {
                            if (((cid + 1) < allids.length) && !hasHugePapxRows.includes(cid)) {
                                hasColSpan = true;
                                cel.colSpan = allids.length - cid;
                            }
                        }
                        else {
                            let cel2 = tab.cells[ii][jj + 1];
                            let cid2 = allids.indexOf(cel2.tag);
                            if (cid2 < 0) 
                                continue;
                            if ((cid + 1) < cid2) {
                                hasColSpan = true;
                                cel.colSpan = cid2 - cid;
                            }
                        }
                    }
                    if (hasColSpan || !hasHugePapxRows.includes(ii) || (ii + 1) === tab.cells.length) 
                        continue;
                    let row0 = tab.cells[ii];
                    let row1 = tab.cells[ii + 1];
                    if (row0.length < row1.length) {
                        let emp = 0;
                        for (const vv of row1) {
                            if (vv.content === null) 
                                emp++;
                        }
                        if ((emp + 1) === row0.length) {
                            let fne = 0;
                            for (; fne < row1.length; fne++) {
                                if (row1[fne].content !== null) 
                                    break;
                            }
                            row0[fne].colSpan = row1.length - emp;
                        }
                        else 
                            tab.mayHasError = true;
                    }
                    else if (row0.length > row1.length) 
                        tab.mayHasError = true;
                }
                if (gen !== null) {
                    let utab = tab.convert();
                    if (utab !== null) {
                        gen.append(utab, null, -1, false);
                        gen.appendNewline(false, false);
                    }
                }
                continue;
            }
            if (p.isList && gen !== null && !(blk instanceof UnitextList)) {
                data = p.getProperty(SinglePropertyModifiers.sprmPIlfo);
                let num = null;
                if (data !== null && data.length > 1) {
                    let ilfo = data[1];
                    ilfo <<= 8;
                    ilfo |= (data[0]);
                    ilfo--;
                    if (ilfo >= 0 && (ilfo < this.lfos.length)) {
                        let wrapnum541 = new RefOutArgWrapper();
                        this.m_NumStyles.tryGetValue(this.lfos[ilfo].lsid, wrapnum541);
                        num = wrapnum541.value;
                    }
                }
                if (this.m_Dels[p.pos] !== (0)) 
                    continue;
                let gg = new UnitextGen();
                this._createUni(gg, new UnitextList(), i, p.pos, p.pos + p.length, txt, level + 1);
                let gg1 = gg.finish(num !== null, null);
                gen.append(gg1, num, p.listLevel, false);
                continue;
            }
            if (gen === null) 
                continue;
            tmp.length = 0;
            tmp.append(txt.substring(p.pos, p.pos + p.length));
            let cp = p.pos;
            for (let ii = 0; ii < tmp.length; ii++,cp++) {
                let ch = tmp.charAt(ii);
                if (this.m_Dels[cp] !== (0)) {
                    if (ii > 0) 
                        gen.appendText(tmp.toString().substring(0, 0 + ii), false);
                    for (; ii < tmp.length; ii++,cp++) {
                        if (this.m_Dels[cp] === (0)) 
                            break;
                    }
                    if (ii < tmp.length) 
                        tmp.remove(0, ii);
                    else 
                        tmp.length = 0;
                    ii = -1;
                    cp--;
                    continue;
                }
                let sup = null;
                let isSub = false;
                let wrapsup547 = new RefOutArgWrapper();
                let inoutres548 = this.m_SuperTexts.tryGetValue(cp, wrapsup547);
                sup = wrapsup547.value;
                if (inoutres548) {
                }
                else {
                    let wrapsup542 = new RefOutArgWrapper();
                    let inoutres543 = this.m_SubTexts.tryGetValue(cp, wrapsup542);
                    sup = wrapsup542.value;
                    if (inoutres543) 
                        isSub = true;
                }
                if (sup !== null) {
                    if (cp === 84223) {
                    }
                    if (ii > 0) 
                        gen.appendText(tmp.toString().substring(0, 0 + ii), false);
                    let stxt = sup.trim();
                    if (!Utils.isNullOrEmpty(stxt)) 
                        gen.append(UnitextPlaintext._new58(stxt, (isSub ? UnitextPlaintextType.SUB : UnitextPlaintextType.SUP)), null, -1, false);
                    else {
                    }
                    ii += sup.length;
                    if (sup.length > 0) 
                        cp += (sup.length - 1);
                    if (ii < tmp.length) 
                        tmp.remove(0, ii);
                    else 
                        tmp.length = 0;
                    ii = -1;
                    continue;
                }
                if ((ch.charCodeAt(0)) < 0x15) {
                }
                if ((ch.charCodeAt(0)) === 0x13) {
                    let tmp2 = new StringBuilder();
                    let tmp3 = null;
                    let shape = null;
                    let lev = 1;
                    let ii0 = ii;
                    cp++;
                    ii++;
                    while (true) {
                        for (; ii < tmp.length; ii++,cp++) {
                            ch = tmp.charAt(ii);
                            if ((ch.charCodeAt(0)) === 0x13) 
                                lev++;
                            else if ((ch.charCodeAt(0)) === 0x15) {
                                lev--;
                                if (lev <= 0) 
                                    break;
                            }
                            else if ((ch.charCodeAt(0)) === 0x14 && lev === 1) {
                                if (tmp3 === null) 
                                    tmp3 = new StringBuilder();
                            }{
                                    tmp2.append(ch);
                                    if (tmp3 !== null && (ch.charCodeAt(0)) !== 0x14) 
                                        tmp3.append(ch);
                                }
                            if (this.m_Shapes.containsKey(cp)) 
                                shape = this.m_Shapes.get(cp);
                        }
                        if (lev === 0) 
                            break;
                        if (tmp2.toString().trim().startsWith("TOC")) 
                            break;
                        if ((i + 1) >= this.m_Paragraphs.length) 
                            break;
                        i++;
                        p = this.m_Paragraphs[i];
                        cp = p.pos - 1;
                        tmp.append(txt.substring(p.pos, p.pos + p.length));
                    }
                    let str0 = Utils.trimStartString(tmp2.toString());
                    if (lev === 0 || ((lev === 1 && str0.startsWith("TOC")))) {
                        let str = MSOfficeHelper.extractSpecText(str0);
                        if (ii0 > 0) 
                            gen.appendText(tmp.toString().substring(0, 0 + ii0), false);
                        if (str !== null) {
                            let hyperlink = null;
                            if (str0.startsWith("HYPERLINK") && (str0.indexOf("PAGEREF") < 0)) {
                                let jj0 = str0.indexOf('"');
                                let jj1 = str0.indexOf('"', jj0 + 1);
                                if (jj0 > 0 && jj1 > (jj0 + 1)) 
                                    hyperlink = str0.substring(jj0 + 1, jj0 + 1 + jj1 - jj0 - 1);
                            }
                            if (hyperlink !== null) {
                                let hr = UnitextHyperlink._new59(hyperlink);
                                hr.content = UnitextPlaintext._new57(str);
                                gen.append(hr, null, -1, false);
                            }
                            else 
                                gen.appendText(str, false);
                        }
                        else if (tmp3 !== null) {
                            let tt = tmp3.toString();
                            if (!gen.lastText.endsWith(tt)) 
                                gen.appendText(tt, false);
                        }
                        if (shape !== null) 
                            gen.append(shape, null, -1, false);
                        if ((ii + 1) >= tmp.length) 
                            tmp.length = 0;
                        else 
                            tmp.remove(0, ii + 1);
                        ii = -1;
                        continue;
                    }
                }
                if (this.m_Footnotes !== null) {
                    if (this.m_Footnotes.containsKey(cp)) {
                        if ((ch.charCodeAt(0)) !== 0x2) 
                            this.m_Footnotes.get(cp).customMark = (ch);
                        if (ii > 0) 
                            gen.appendText(tmp.toString().substring(0, 0 + ii), false);
                        gen.append(this.m_Footnotes.get(cp), null, -1, false);
                        tmp.remove(0, ii + 1);
                        ii = -1;
                        continue;
                    }
                }
                if ((ch.charCodeAt(0)) === 0xB) {
                    if (ii > 0) 
                        gen.appendText(tmp.toString().substring(0, 0 + ii), false);
                    gen.appendNewline(false, false);
                    tmp.remove(0, ii + 1);
                    ii = -1;
                    continue;
                }
                if ((ch.charCodeAt(0)) === 0xC) {
                    if (ii > 0) 
                        gen.appendText(tmp.toString().substring(0, 0 + ii), false);
                    gen.appendPagebreak();
                    tmp.remove(0, ii + 1);
                    ii = -1;
                    continue;
                }
                if ((ch.charCodeAt(0)) === 0xD || (ch.charCodeAt(0)) === 0xA) {
                }
                if ((ch.charCodeAt(0)) === 5 && this.m_Comments !== null && this.m_Comments.containsKey(cp)) {
                    if (ii > 0) 
                        gen.appendText(tmp.toString().substring(0, 0 + ii), false);
                    gen.append(this.m_Comments.get(cp), null, -1, false);
                    tmp.remove(0, ii + 1);
                    ii = -1;
                    continue;
                }
                if ((((ch.charCodeAt(0)) === 7 || (ch.charCodeAt(0)) === 2 || (ch.charCodeAt(0)) === 5) || (ch.charCodeAt(0)) === 3 || (ch.charCodeAt(0)) === 4) || (ch.charCodeAt(0)) === 0x1F) {
                    tmp.remove(ii, 1);
                    ii--;
                    continue;
                }
                if ((ch.charCodeAt(0)) === 1 || (ch.charCodeAt(0)) === 8) {
                    if (ii > 0) 
                        gen.appendText(tmp.toString().substring(0, 0 + ii), false);
                    if (this.m_Shapes.containsKey(cp)) 
                        gen.append(this.m_Shapes.get(cp), null, -1, false);
                    else 
                        gen.append(new UnitextImage(), null, -1, false);
                    tmp.remove(0, ii + 1);
                    ii = -1;
                    continue;
                }
                if ((ch.charCodeAt(0)) !== 6 && (ch.charCodeAt(0)) !== 0xD && ((ch.charCodeAt(0)) < 0x20)) {
                    if (ii >= 0 && (ii < tmp.length)) 
                        tmp.setCharAt(ii, ' ');
                }
            }
            if (tmp.length > 0) 
                gen.appendText(tmp.toString(), false);
        }
    }
    
    loadStsh(wordDocumentStream, stsh) {
        this.m_StyleDefinitionsMap = new Hashtable();
        for (let istd = 0; istd < stsh.rglpstd.length; istd++) {
            let std = stsh.rglpstd[istd];
            if (std === null) 
                continue;
            let def = new StyleDefinition(this, std);
            this.m_StyleDefinitionsMap.put(istd, def);
        }
        let _defaultPrls = new Array();
        let ftcBi = stsh.stshi.ftcBi;
        _defaultPrls.push(new Prl(new Sprm(SinglePropertyModifiers.sprmCFtcBi), Utils.objectToBytes(ftcBi, 'short')));
        let ftcAsci = stsh.stshi.stshif.ftcAsci;
        _defaultPrls.push(new Prl(new Sprm(SinglePropertyModifiers.sprmCRgFtc0), Utils.objectToBytes(ftcAsci, 'short')));
        let ftcFE = stsh.stshi.stshif.ftcFE;
        _defaultPrls.push(new Prl(new Sprm(SinglePropertyModifiers.sprmCRgFtc1), Utils.objectToBytes(ftcFE, 'short')));
        let ftcOther = stsh.stshi.stshif.ftcOther;
        _defaultPrls.push(new Prl(new Sprm(SinglePropertyModifiers.sprmCRgFtc2), Utils.objectToBytes(ftcOther, 'short')));
        this.defaultPrls = _defaultPrls;
    }
    
    loadCharacterFormatting(wordDocumentStream, plcfBteChpx) {
        let _formattings = new Array();
        for (let i = 0; i < plcfBteChpx.aPnBteChpx.length; i++) {
            wordDocumentStream.position = (plcfBteChpx.aPnBteChpx[i]) * 512;
            try {
                let papxFkp = BasicTypesReader.readChpxFkp(wordDocumentStream);
                for (let j = 0; j < papxFkp.rgb.length; j++) {
                    let startFc = papxFkp.rgfc[j];
                    let endFc = papxFkp.rgfc[j + 1];
                    let fc = WordDocument._findPos123(this.fileCharacterPositions, startFc, endFc);
                    if (fc === null) 
                        continue;
                    if (startFc < fc.offset) 
                        startFc = fc.offset;
                    if (endFc > (fc.offset + (fc.bytesPerCharacter * fc.length))) 
                        endFc = fc.offset + (fc.bytesPerCharacter * fc.length);
                    let para = new CharacterFormatting(this, Utils.intDiv((startFc - fc.offset), fc.bytesPerCharacter), Utils.intDiv((endFc - startFc), fc.bytesPerCharacter), fc, papxFkp.rgb[j].value);
                    _formattings.push(para);
                }
            } catch (ex549) {
            }
        }
        for (let ii = 0; ii < _formattings.length; ii++) {
            let ch = false;
            for (let jj = 0; jj < (_formattings.length - 1); jj++) {
                if (_formattings[jj].offset > _formattings[jj + 1].offset) {
                    let f = _formattings[jj];
                    _formattings[jj] = _formattings[jj + 1];
                    _formattings[jj + 1] = f;
                    ch = true;
                }
            }
            if (!ch) 
                break;
        }
        this.m_Formattings = _formattings;
    }
    
    static _findPos123(arr, startFc, endFc) {
        for (const f of arr) {
            if (!((endFc <= f.offset || ((f.offset + (f.bytesPerCharacter * f.length)) < startFc)))) 
                return f;
        }
        return null;
    }
    
    loadParagraphs(wordDocumentStream, clx, plcfBtePapx) {
        this.m_Paragraphs = new Array();
        for (let i = 0; i < plcfBtePapx.aPnBtePapx.length; i++) {
            wordDocumentStream.position = (plcfBtePapx.aPnBtePapx[i]) * 512;
            let er = false;
            let wraper550 = new RefOutArgWrapper();
            let papxFkp = BasicTypesReader.readPapxFkp(wordDocumentStream, wraper550);
            er = wraper550.value;
            if (er) 
                this.m_Error = true;
            for (let j = 0; j < papxFkp.rgbx.length; j++) {
                let startFc = papxFkp.rgfc[j];
                let endFc = papxFkp.rgfc[j + 1];
                let fc = WordDocument._findPos123(this.fileCharacterPositions, startFc, endFc);
                if (fc === null) 
                    continue;
                if (startFc < fc.offset) 
                    startFc = fc.offset;
                if (endFc > (fc.offset + (fc.bytesPerCharacter * fc.length))) 
                    endFc = fc.offset + (fc.bytesPerCharacter * fc.length);
                let para = new Paragraph(this, Utils.intDiv((startFc - fc.offset), fc.bytesPerCharacter), Utils.intDiv((endFc - startFc), fc.bytesPerCharacter), fc, papxFkp.rgbx[j].value);
                this.m_Paragraphs.push(para);
            }
        }
        for (let ii = 0; ii < this.m_Paragraphs.length; ii++) {
            let ch = false;
            for (let jj = 0; jj < (this.m_Paragraphs.length - 1); jj++) {
                if (this.m_Paragraphs[jj].compareTo(this.m_Paragraphs[jj + 1]) > 0) {
                    let p = this.m_Paragraphs[jj];
                    this.m_Paragraphs[jj] = this.m_Paragraphs[jj + 1];
                    this.m_Paragraphs[jj + 1] = p;
                    ch = true;
                }
            }
            if (!ch) 
                break;
        }
        for (let i = 0; i < (this.m_Paragraphs.length - 1); i++) {
            if ((this.m_Paragraphs[i].pos + this.m_Paragraphs[i].length) < this.m_Paragraphs[i + 1].pos) 
                this.m_Paragraphs[i].length = (this.m_Paragraphs[i + 1].pos - this.m_Paragraphs[i].pos);
        }
    }
    
    loadCharacters(wordDocumentStream, clx) {
        if (clx === null) 
            return;
        let plcPcd = clx.pcdt.plcPcd;
        let fileCharacters = Array(plcPcd.pcds.length).fill(null);
        let position = 0;
        for (let i = 0; i < plcPcd.pcds.length; i++) {
            let length = ((plcPcd.cPs[i + 1]) - (plcPcd.cPs[i]));
            let offset = plcPcd.pcds[i].fc.fc;
            let compressed = plcPcd.pcds[i].fc.fCompressed;
            if (compressed) {
                let txt = Array(length).fill('\0');
                wordDocumentStream.position = Utils.intDiv(offset, 2);
                let data = ReadUtils.readExact(wordDocumentStream, length);
                FcCompressedMapping.getChars(data, 0, length, txt, 0);
                this.text.append(txt);
            }
            else {
                wordDocumentStream.position = offset;
                let data = ReadUtils.readExact(wordDocumentStream, length * 2);
                let txt = MiscHelper.decodeStringUnicode(data, 0, -1);
                this.text.append(txt);
            }
            let fc = new WordDocument.FileCharacterPosition();
            fc.offset = (compressed ? Utils.intDiv(offset, 2) : offset);
            fc.bytesPerCharacter = (compressed ? 1 : 2);
            fc.length = length;
            fc.characterIndex = position;
            fc.prls = this.expandPrm(plcPcd.pcds[i].prm, clx);
            fileCharacters[i] = fc;
            position += length;
        }
        let li = Array.from(fileCharacters);
        for (let ii = 0; ii < li.length; ii++) {
            let ch = false;
            for (let jj = 0; jj < (li.length - 1); jj++) {
                if (li[jj].offset > li[jj + 1].offset) {
                    let f = li[jj];
                    li[jj] = li[jj + 1];
                    li[jj + 1] = f;
                    ch = true;
                }
            }
            if (!ch) 
                break;
        }
        fileCharacters = li;
        this.fileCharacterPositions = fileCharacters;
    }
    
    expandPrm(prm, clx) {
        if (prm.fComplex) {
            let index = prm.igrpprl;
            return clx.rgPrc[index].grpPrl;
        }
        else if (Utils.compareUnsigned(prm.prm, 0x0000) != 0) {
            let sprm = 0;
            let wrapsprm551 = new RefOutArgWrapper();
            let inoutres552 = SinglePropertyModifiers.prm0Map.tryGetValue(prm.isprm, wrapsprm551);
            sprm = wrapsprm551.value;
            if (!inoutres552) 
                throw new Error("Invalid Prm: isprm");
            let value = prm.val;
            let prl = new Prl(new Sprm(sprm), new Uint8Array([value]));
            return [prl];
        }
        else 
            return Array(0).fill(null);
    }
    
    getDefaults() {
        let li = new Array();
        li.push(this.defaultPrls);
        return new StyleCollection(li);
    }
    
    getStyle(characterPosition, level) {
        let prls = new Array();
        if ((level.value()) >= (FormattingLevel.CHARACTER.value())) {
            for (const formatting of this.m_Formattings) {
                if (formatting.fileCharacterPosition.contains(characterPosition)) {
                    if ((level.value()) >= (FormattingLevel.CHARACTERSTYLE.value())) {
                        let definition = formatting.style;
                        if (definition !== null) 
                            definition.expandStyles(prls);
                    }
                }
            }
        }
        if ((level.value()) >= (FormattingLevel.PARAGRAPH.value())) {
            for (const paragraph of this.m_Paragraphs) {
                if (paragraph.fileCharacterPosition.contains(characterPosition)) {
                    if ((level.value()) >= (FormattingLevel.PARAGRAPHSTYLE.value())) {
                        let definition = paragraph.style;
                        definition.expandStyles(prls);
                    }
                }
            }
        }
        if ((level.value()) >= (FormattingLevel.PART.value())) {
            for (const fcp of this.fileCharacterPositions) {
                if (fcp.contains(characterPosition)) 
                    prls.push(fcp.prls);
            }
        }
        if ((level.value()) >= (FormattingLevel.GLOBAL.value())) 
            prls.push(this.defaultPrls);
        return new StyleCollection(prls);
    }
    
    loadLFOS(wordDocumentStream, length) {
        if (length < 10) 
            return;
        let cou = ReadUtils.readInt(wordDocumentStream);
        length -= 4;
        for (let i = 0; i < cou; i++) {
            let lfo = new WordDocument.LFO();
            this.lfos.push(lfo);
            lfo.lsid = ReadUtils.readInt(wordDocumentStream);
            length -= 4;
            wordDocumentStream.position = wordDocumentStream.position + (8);
            length -= 8;
            lfo.datCount = wordDocumentStream.readByte();
            length--;
            lfo.ibstFltAutoNum = wordDocumentStream.readByte();
            length--;
            wordDocumentStream.position = wordDocumentStream.position + (2);
            length -= 2;
        }
        for (let i = 0; i < cou; i++) {
            if (length < 4) 
                break;
            let cp = ReadUtils.readInt(wordDocumentStream);
            length -= 4;
            for (let j = 0; j < this.lfos[i].datCount; j++) {
                if (length < 10) 
                    break;
            }
        }
    }
    
    loadLSTFs(wordDocumentStream, length) {
        let cou = ReadUtils.readShort(wordDocumentStream);
        length -= 2;
        for (let i = 0; i < cou; i++) {
            let lstf = new WordDocument.LSTF();
            this.lstfs.push(lstf);
            lstf.lsid = ReadUtils.readInt(wordDocumentStream);
            length -= 4;
            let num = new UnitextGenNumStyle();
            num.id = lstf.lsid.toString();
            if (!this.m_NumStyles.containsKey(lstf.lsid)) 
                this.m_NumStyles.put(lstf.lsid, num);
            ReadUtils.readInt(wordDocumentStream);
            length -= 4;
            wordDocumentStream.read(lstf.istds, 0, 18);
            length -= 18;
            let b = wordDocumentStream.readByte();
            wordDocumentStream.readByte();
            length -= 2;
            if ((((b) & 1)) !== 0) 
                lstf.fSimpleList = true;
            if ((((b) & 4)) !== 0) 
                lstf.fAutoNum = true;
        }
        for (let i = 0; i < cou; i++) {
            let lstf = this.lstfs[i];
            let num = this.m_NumStyles.get(lstf.lsid);
            for (let j = 0; j < ((lstf.fSimpleList ? 1 : 9)); j++) {
                let lvl = new WordDocument.LVL();
                lstf.lvls.push(lvl);
                lvl.iStartAt = ReadUtils.readInt(wordDocumentStream);
                length -= 4;
                lvl.nfc = wordDocumentStream.readByte();
                length--;
                let bb = wordDocumentStream.readByte();
                length--;
                wordDocumentStream.read(lvl.rgbxchNums, 0, 9);
                length -= 9;
                lvl.ixchFollow = wordDocumentStream.readByte();
                length--;
                lvl.dxaIndentSav = ReadUtils.readInt(wordDocumentStream);
                length -= 4;
                ReadUtils.readInt(wordDocumentStream);
                length -= 4;
                lvl.cbGrpprlChpx = wordDocumentStream.readByte();
                length--;
                lvl.cbGrpprlPapx = wordDocumentStream.readByte();
                length--;
                lvl.ilvlRestartLim = wordDocumentStream.readByte();
                length--;
                wordDocumentStream.readByte();
                length--;
                wordDocumentStream.position = wordDocumentStream.position + ((lvl.cbGrpprlChpx) + (lvl.cbGrpprlPapx));
                length -= ((lvl.cbGrpprlChpx) + (lvl.cbGrpprlPapx));
                let tmp = new StringBuilder();
                let slen = ReadUtils.readShort(wordDocumentStream);
                length -= 2;
                for (let k = 0; k < slen; k++) {
                    let cod = ReadUtils.readShort(wordDocumentStream);
                    let ch = String.fromCharCode(cod);
                    if (Utils.compareUnsigned(cod, 0x20) >= 0) {
                        if (Utils.compareUnsigned(cod, 0xF000) >= 0) {
                            let chh = WingdingsHelper.getUnicode((cod) - 0xF000);
                            if ((chh.charCodeAt(0)) !== 0) 
                                ch = chh;
                        }
                        tmp.append(ch);
                    }
                    else 
                        tmp.append("%").append((((ch.charCodeAt(0)) + 1)));
                    length -= 2;
                }
                lvl.xstname = tmp.toString();
                let nl = new UniTextGenNumLevel();
                num.levels.push(nl);
                nl.format = lvl.xstname;
                nl.start = lvl.iStartAt;
                let mnem = null;
                let wrapmnem553 = new RefOutArgWrapper();
                let inoutres554 = WordDocument.M_NUM_TYPES_MAP.tryGetValue(lvl.nfc, wrapmnem553);
                mnem = wrapmnem553.value;
                if (inoutres554) 
                    nl.type = DocNumStyles.getNumTyp(mnem);
                else 
                    nl.type = UniTextGenNumType.DECIMAL;
            }
        }
    }
    
    static static_constructor() {
        WordDocument.M_NUM_TYPES_MAP = new Hashtable();
        WordDocument.M_NUM_TYPES_MAP.put(0x00, "decimal msonfcUCRoman");
        WordDocument.M_NUM_TYPES_MAP.put(0x01, "upperRoman");
        WordDocument.M_NUM_TYPES_MAP.put(0x02, "lowerRoman");
        WordDocument.M_NUM_TYPES_MAP.put(0x03, "upperLetter");
        WordDocument.M_NUM_TYPES_MAP.put(0x04, "lowerLetter");
        WordDocument.M_NUM_TYPES_MAP.put(0x05, "ordinal");
        WordDocument.M_NUM_TYPES_MAP.put(0x06, "cardinalText");
        WordDocument.M_NUM_TYPES_MAP.put(0x07, "ordinalText");
        WordDocument.M_NUM_TYPES_MAP.put(0x08, "hex");
        WordDocument.M_NUM_TYPES_MAP.put(0x09, "chicago");
        WordDocument.M_NUM_TYPES_MAP.put(0x0A, "ideographDigital");
        WordDocument.M_NUM_TYPES_MAP.put(0x0B, "japaneseCounting");
        WordDocument.M_NUM_TYPES_MAP.put(0x0C, "Aiueo");
        WordDocument.M_NUM_TYPES_MAP.put(0x0D, "Iroha");
        WordDocument.M_NUM_TYPES_MAP.put(0x0E, "decimalFullWidth");
        WordDocument.M_NUM_TYPES_MAP.put(0x0F, "decimalHalfWidth");
        WordDocument.M_NUM_TYPES_MAP.put(0x10, "japaneseLegal");
        WordDocument.M_NUM_TYPES_MAP.put(0x11, "japaneseDigitalTenThousand");
        WordDocument.M_NUM_TYPES_MAP.put(0x12, "decimalEnclosedCircle");
        WordDocument.M_NUM_TYPES_MAP.put(0x13, "decimalFullWidth2");
        WordDocument.M_NUM_TYPES_MAP.put(0x14, "aiueoFullWidth");
        WordDocument.M_NUM_TYPES_MAP.put(0x15, "irohaFullWidth");
        WordDocument.M_NUM_TYPES_MAP.put(0x16, "decimalZero");
        WordDocument.M_NUM_TYPES_MAP.put(0x17, "bullet");
        WordDocument.M_NUM_TYPES_MAP.put(0x18, "ganada");
        WordDocument.M_NUM_TYPES_MAP.put(0x19, "chosung");
        WordDocument.M_NUM_TYPES_MAP.put(0x1A, "decimalEnclosedFullstop");
        WordDocument.M_NUM_TYPES_MAP.put(0x1D, "ideographEnclosedCircle");
        WordDocument.M_NUM_TYPES_MAP.put(0x1E, "ideographTraditional");
        WordDocument.M_NUM_TYPES_MAP.put(0x1F, "ideographZodiac");
        WordDocument.M_NUM_TYPES_MAP.put(0x20, "ideographZodiacTraditional");
        WordDocument.M_NUM_TYPES_MAP.put(0x21, "taiwaneseCounting");
        WordDocument.M_NUM_TYPES_MAP.put(0x22, "ideographLegalTraditional");
        WordDocument.M_NUM_TYPES_MAP.put(0x23, "taiwaneseCountingThousand");
        WordDocument.M_NUM_TYPES_MAP.put(0x24, "taiwaneseDigital");
        WordDocument.M_NUM_TYPES_MAP.put(0x25, "chineseCounting");
        WordDocument.M_NUM_TYPES_MAP.put(0x26, "chineseLegalSimplified");
        WordDocument.M_NUM_TYPES_MAP.put(0x27, "chineseCountingThousand");
        WordDocument.M_NUM_TYPES_MAP.put(0x28, "decimal");
        WordDocument.M_NUM_TYPES_MAP.put(0x29, "koreanDigital");
        WordDocument.M_NUM_TYPES_MAP.put(0x2A, "koreanCounting");
        WordDocument.M_NUM_TYPES_MAP.put(0x2B, "koreanLegal");
        WordDocument.M_NUM_TYPES_MAP.put(0x2C, "koreanDigital2");
        WordDocument.M_NUM_TYPES_MAP.put(0x2D, "hebrew1");
        WordDocument.M_NUM_TYPES_MAP.put(0x2E, "arabicAlpha");
        WordDocument.M_NUM_TYPES_MAP.put(0x2F, "hebrew2");
        WordDocument.M_NUM_TYPES_MAP.put(0x30, "arabicAbjad");
        WordDocument.M_NUM_TYPES_MAP.put(0x31, "hindiVowels");
        WordDocument.M_NUM_TYPES_MAP.put(0x32, "hindiConsonants");
        WordDocument.M_NUM_TYPES_MAP.put(0x33, "hindiNumbers");
        WordDocument.M_NUM_TYPES_MAP.put(0x34, "hindiCounting");
        WordDocument.M_NUM_TYPES_MAP.put(0x35, "thaiLetters");
        WordDocument.M_NUM_TYPES_MAP.put(0x36, "thaiNumbers");
        WordDocument.M_NUM_TYPES_MAP.put(0x37, "thaiCounting");
        WordDocument.M_NUM_TYPES_MAP.put(0x38, "vietnameseCounting");
        WordDocument.M_NUM_TYPES_MAP.put(0x39, "numberInDash");
        WordDocument.M_NUM_TYPES_MAP.put(0x3A, "russianLower");
        WordDocument.M_NUM_TYPES_MAP.put(0x3B, "russianUpper");
    }
}


WordDocument.FileCharacterPosition = class  {
    
    constructor() {
        this.offset = 0;
        this.length = 0;
        this.characterIndex = 0;
        this.bytesPerCharacter = 0;
        this.prls = null;
    }
    
    toString() {
        const SinglePropertyModifiers = require("./SinglePropertyModifiers");
        let res = new StringBuilder();
        res.append("CharIndex:").append(this.characterIndex).append(" Offset:").append(this.offset).append(" Len:").append(this.length);
        if (this.prls !== null) {
            for (const prl of this.prls) {
                res.append(" ").append((Utils.notNull(SinglePropertyModifiers.getSprmName(prl.sprm.sprm), "?")));
            }
        }
        return res.toString();
    }
    
    contains(position) {
        return this.characterIndex <= position && (position < (this.characterIndex + this.length));
    }
}


WordDocument.LFO = class  {
    
    constructor() {
        this.lsid = 0;
        this.datCount = 0;
        this.ibstFltAutoNum = 0;
        this.lvls = new Array();
    }
}


WordDocument.LFOData = class  {
}


WordDocument.LFOLVL = class  {
    
    constructor() {
        this.iStartAt = 0;
    }
}


WordDocument.LSTF = class  {
    
    constructor() {
        this.lsid = 0;
        this.istds = new Uint8Array(18);
        this.fSimpleList = false;
        this.fAutoNum = false;
        this.lvls = new Array();
    }
}


WordDocument.LVL = class  {
    
    constructor() {
        this.iStartAt = 0;
        this.nfc = 0;
        this.rgbxchNums = new Uint8Array(9);
        this.ixchFollow = 0;
        this.dxaIndentSav = 0;
        this.cbGrpprlChpx = 0;
        this.cbGrpprlPapx = 0;
        this.ilvlRestartLim = 0;
        this.xstname = null;
    }
}


WordDocument.static_constructor();

module.exports = WordDocument