@office-open/docx 0.9.4 → 0.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{context-CA7wUvmY.mjs → context-DfxK5XnG.mjs} +43 -1076
- package/dist/context-DfxK5XnG.mjs.map +1 -0
- package/dist/{core-properties-CR-T1Wqh.d.mts → core-properties-DMRyJWDp.d.mts} +693 -677
- package/dist/core-properties-DMRyJWDp.d.mts.map +1 -0
- package/dist/{document-B_uvEH8b.mjs → document-D2OTVcbX.mjs} +2290 -1013
- package/dist/document-D2OTVcbX.mjs.map +1 -0
- package/dist/{generate-_AmBlI4o.mjs → generate-B2i9hUSF.mjs} +3 -3
- package/dist/{generate-_AmBlI4o.mjs.map → generate-B2i9hUSF.mjs.map} +1 -1
- package/dist/generate.d.mts +1 -1
- package/dist/generate.mjs +1 -1
- package/dist/index.d.mts +12 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/{parse-7SJ1sm-D.mjs → parse-DqXV5xqQ.mjs} +3 -28
- package/dist/parse-DqXV5xqQ.mjs.map +1 -0
- package/dist/parse.d.mts +1 -1
- package/dist/parse.mjs +1 -1
- package/dist/patch/index.d.mts +1 -1
- package/dist/patch/index.mjs +1 -1
- package/package.json +3 -3
- package/dist/context-CA7wUvmY.mjs.map +0 -1
- package/dist/core-properties-CR-T1Wqh.d.mts.map +0 -1
- package/dist/document-B_uvEH8b.mjs.map +0 -1
- package/dist/parse-7SJ1sm-D.mjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as stringifyParagraphInline, Ct as Media, E as tableDesc, F as parseDrawingRun, J as altChunkDesc, M as parseMathChildren, O as parseSdtProperties, Q as sdtBlockDesc, X as customXmlBlockDesc, Z as parseCustomXmlPr, at as stringifyRunProperties, ct as parsedRunToOptions, ht as parseFormFieldData, it as stringifyParagraphProperties, k as stringifyChildDispatch, n as sectionPropertiesDesc, ot as parseRun, rt as subDocDesc, st as parseRunProperties, ut as BorderStyle, wt as createTransformation } from "./document-D2OTVcbX.mjs";
|
|
2
2
|
import { Relationships, ThemeColor, convertInchesToTwip, decimalNumber, derivePasswordHash, hexColorValue, toUint8Array, uCharHexNumber, uniqueId, uniqueNumericIdCreator, uniqueUuid } from "@office-open/core";
|
|
3
|
-
import { attr, attrBool, attrNum, children,
|
|
3
|
+
import { attr, attrBool, attrNum, children, escapeXml, findChild, js2xml, textOf, xml2js } from "@office-open/xml";
|
|
4
4
|
import { ChartCollection } from "@office-open/core/chart";
|
|
5
5
|
import { SmartArtCollection } from "@office-open/core/smartart";
|
|
6
6
|
//#region src/parts/paragraph/formatting/alignment.ts
|
|
@@ -598,462 +598,6 @@ const TABLE_BORDERS_NONE = {
|
|
|
598
598
|
top: NONE_BORDER
|
|
599
599
|
};
|
|
600
600
|
//#endregion
|
|
601
|
-
//#region src/parts/paragraph/run/run-parse.ts
|
|
602
|
-
/**
|
|
603
|
-
* Run properties parser for DOCX documents.
|
|
604
|
-
*
|
|
605
|
-
* Parses w:rPr Element trees into RunPropertiesOptions objects.
|
|
606
|
-
*
|
|
607
|
-
* @module
|
|
608
|
-
*/
|
|
609
|
-
/**
|
|
610
|
-
* Parse a w:rPr element into RunPropertiesOptions.
|
|
611
|
-
*/
|
|
612
|
-
function parseRunProperties(el) {
|
|
613
|
-
const opts = {};
|
|
614
|
-
const rStyle = findChild(el, "w:rStyle");
|
|
615
|
-
if (rStyle) opts.style = attr(rStyle, "w:val");
|
|
616
|
-
const font = findChild(el, "w:rFonts");
|
|
617
|
-
if (font) {
|
|
618
|
-
const ascii = attr(font, "w:ascii");
|
|
619
|
-
const eastAsia = attr(font, "w:eastAsia");
|
|
620
|
-
const hAnsi = attr(font, "w:hAnsi");
|
|
621
|
-
const cs = attr(font, "w:cs");
|
|
622
|
-
const hint = attr(font, "w:hint");
|
|
623
|
-
if (ascii && !eastAsia && !hAnsi && !cs) opts.font = hint ? {
|
|
624
|
-
name: ascii,
|
|
625
|
-
hint
|
|
626
|
-
} : ascii;
|
|
627
|
-
else {
|
|
628
|
-
const fontObj = {};
|
|
629
|
-
if (ascii) fontObj.ascii = ascii;
|
|
630
|
-
if (eastAsia) fontObj.eastAsia = eastAsia;
|
|
631
|
-
if (hAnsi) fontObj.hAnsi = hAnsi;
|
|
632
|
-
if (cs) fontObj.cs = cs;
|
|
633
|
-
if (hint) fontObj.hint = hint;
|
|
634
|
-
opts.font = fontObj;
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
const bold = findChild(el, "w:b");
|
|
638
|
-
if (bold) opts.bold = attrBool(bold, "w:val") ?? true;
|
|
639
|
-
const boldCs = findChild(el, "w:bCs");
|
|
640
|
-
if (boldCs) opts.boldComplexScript = attrBool(boldCs, "w:val") ?? true;
|
|
641
|
-
const italic = findChild(el, "w:i");
|
|
642
|
-
if (italic) opts.italic = attrBool(italic, "w:val") ?? true;
|
|
643
|
-
const italicCs = findChild(el, "w:iCs");
|
|
644
|
-
if (italicCs) opts.italicComplexScript = attrBool(italicCs, "w:val") ?? true;
|
|
645
|
-
const underline = findChild(el, "w:u");
|
|
646
|
-
if (underline) {
|
|
647
|
-
const ul = {};
|
|
648
|
-
const uType = attr(underline, "w:val");
|
|
649
|
-
if (uType) ul.type = uType;
|
|
650
|
-
const uColor = colorAttr(underline, "w:color");
|
|
651
|
-
if (uColor) ul.color = uColor;
|
|
652
|
-
opts.underline = ul;
|
|
653
|
-
}
|
|
654
|
-
for (const [name, optKey] of [
|
|
655
|
-
["w:strike", "strike"],
|
|
656
|
-
["w:dstrike", "doubleStrike"],
|
|
657
|
-
["w:outline", "outline"],
|
|
658
|
-
["w:shadow", "shadow"],
|
|
659
|
-
["w:emboss", "emboss"],
|
|
660
|
-
["w:imprint", "imprint"],
|
|
661
|
-
["w:vanish", "vanish"],
|
|
662
|
-
["w:webHidden", "webHidden"],
|
|
663
|
-
["w:noProof", "noProof"],
|
|
664
|
-
["w:snapToGrid", "snapToGrid"],
|
|
665
|
-
["w:smallCaps", "smallCaps"],
|
|
666
|
-
["w:caps", "allCaps"],
|
|
667
|
-
["w:rtl", "rightToLeft"],
|
|
668
|
-
["w:cs", "complexScript"],
|
|
669
|
-
["w:specVanish", "specVanish"],
|
|
670
|
-
["w:oMath", "math"]
|
|
671
|
-
]) {
|
|
672
|
-
const child = findChild(el, name);
|
|
673
|
-
if (child) opts[optKey] = attrBool(child, "w:val") ?? true;
|
|
674
|
-
}
|
|
675
|
-
const color = findChild(el, "w:color");
|
|
676
|
-
if (color) {
|
|
677
|
-
const c = colorAttr(color, "w:val");
|
|
678
|
-
const themeColor = attr(color, "w:themeColor");
|
|
679
|
-
const themeTint = attr(color, "w:themeTint");
|
|
680
|
-
const themeShade = attr(color, "w:themeShade");
|
|
681
|
-
if (themeColor || themeTint || themeShade) {
|
|
682
|
-
const colorObj = {};
|
|
683
|
-
if (c) colorObj.val = c;
|
|
684
|
-
if (themeColor) colorObj.themeColor = themeColor;
|
|
685
|
-
if (themeTint) colorObj.themeTint = themeTint;
|
|
686
|
-
if (themeShade) colorObj.themeShade = themeShade;
|
|
687
|
-
opts.color = colorObj;
|
|
688
|
-
} else if (c) opts.color = c;
|
|
689
|
-
}
|
|
690
|
-
const sz = findChild(el, "w:sz");
|
|
691
|
-
if (sz) {
|
|
692
|
-
const halfPts = attrNum(sz, "w:val");
|
|
693
|
-
if (halfPts !== void 0) opts.size = halfPts / 2;
|
|
694
|
-
}
|
|
695
|
-
const szCs = findChild(el, "w:szCs");
|
|
696
|
-
if (szCs) {
|
|
697
|
-
const halfPts = attrNum(szCs, "w:val");
|
|
698
|
-
if (halfPts !== void 0) opts.sizeComplexScript = halfPts / 2;
|
|
699
|
-
}
|
|
700
|
-
const highlight = findChild(el, "w:highlight");
|
|
701
|
-
if (highlight) {
|
|
702
|
-
const val = attr(highlight, "w:val");
|
|
703
|
-
if (val) opts.highlight = val;
|
|
704
|
-
}
|
|
705
|
-
const highlightCs = findChild(el, "w:highlightCs");
|
|
706
|
-
if (highlightCs) {
|
|
707
|
-
const val = attr(highlightCs, "w:val");
|
|
708
|
-
if (val) opts.highlightComplexScript = val;
|
|
709
|
-
}
|
|
710
|
-
const vertAlign = findChild(el, "w:vertAlign");
|
|
711
|
-
if (vertAlign) {
|
|
712
|
-
const val = attr(vertAlign, "w:val");
|
|
713
|
-
if (val === "subscript") opts.subScript = true;
|
|
714
|
-
else if (val === "superscript") opts.superScript = true;
|
|
715
|
-
}
|
|
716
|
-
const effect = findChild(el, "w:effect");
|
|
717
|
-
if (effect) {
|
|
718
|
-
const val = attr(effect, "w:val");
|
|
719
|
-
if (val) opts.effect = val;
|
|
720
|
-
}
|
|
721
|
-
const emphasisMark = findChild(el, "w:em");
|
|
722
|
-
if (emphasisMark) {
|
|
723
|
-
const val = attr(emphasisMark, "w:val");
|
|
724
|
-
if (val) opts.emphasisMark = { type: val };
|
|
725
|
-
}
|
|
726
|
-
const spacing = findChild(el, "w:spacing");
|
|
727
|
-
if (spacing) {
|
|
728
|
-
const val = attrNum(spacing, "w:val");
|
|
729
|
-
if (val !== void 0) opts.characterSpacing = val;
|
|
730
|
-
}
|
|
731
|
-
const scale = findChild(el, "w:w");
|
|
732
|
-
if (scale) {
|
|
733
|
-
const val = attrNum(scale, "w:val");
|
|
734
|
-
if (val !== void 0) opts.scale = val;
|
|
735
|
-
}
|
|
736
|
-
const kern = findChild(el, "w:kern");
|
|
737
|
-
if (kern) {
|
|
738
|
-
const val = attrNum(kern, "w:val");
|
|
739
|
-
if (val !== void 0) opts.kern = val;
|
|
740
|
-
}
|
|
741
|
-
const position = findChild(el, "w:position");
|
|
742
|
-
if (position) {
|
|
743
|
-
const val = attr(position, "w:val");
|
|
744
|
-
if (val !== void 0) opts.position = val;
|
|
745
|
-
}
|
|
746
|
-
const fitText = findChild(el, "w:fitText");
|
|
747
|
-
if (fitText) {
|
|
748
|
-
const val = attrNum(fitText, "w:val");
|
|
749
|
-
if (val !== void 0) opts.fitText = val;
|
|
750
|
-
}
|
|
751
|
-
const lang = findChild(el, "w:lang");
|
|
752
|
-
if (lang) {
|
|
753
|
-
const langObj = {};
|
|
754
|
-
const val = attr(lang, "w:val");
|
|
755
|
-
if (val) langObj.value = val;
|
|
756
|
-
const eastAsia = attr(lang, "w:eastAsia");
|
|
757
|
-
if (eastAsia) langObj.eastAsia = eastAsia;
|
|
758
|
-
const bidi = attr(lang, "w:bidi");
|
|
759
|
-
if (bidi) langObj.bidirectional = bidi;
|
|
760
|
-
if (Object.keys(langObj).length > 0) opts.language = langObj;
|
|
761
|
-
}
|
|
762
|
-
const bdr = findChild(el, "w:bdr");
|
|
763
|
-
if (bdr) opts.border = parseBorder(bdr);
|
|
764
|
-
const shd = findChild(el, "w:shd");
|
|
765
|
-
if (shd) opts.shading = parseShading(shd);
|
|
766
|
-
const eastAsianLayout = findChild(el, "w:eastAsianLayout");
|
|
767
|
-
if (eastAsianLayout) opts.eastAsianLayout = parseEastAsianLayout(eastAsianLayout);
|
|
768
|
-
const contentPart = findChild(el, "w:contentPart");
|
|
769
|
-
if (contentPart) {
|
|
770
|
-
const rId = attr(contentPart, "r:id");
|
|
771
|
-
if (rId) opts.contentPartRId = rId;
|
|
772
|
-
}
|
|
773
|
-
const rPrChange = findChild(el, "w:rPrChange");
|
|
774
|
-
if (rPrChange) {
|
|
775
|
-
const rev = {};
|
|
776
|
-
const author = attr(rPrChange, "w:author");
|
|
777
|
-
if (author) rev.author = author;
|
|
778
|
-
const date = attr(rPrChange, "w:date");
|
|
779
|
-
if (date) rev.date = date;
|
|
780
|
-
const id = attrNum(rPrChange, "w:id");
|
|
781
|
-
if (id !== void 0) rev.id = id;
|
|
782
|
-
const innerRPr = findChild(rPrChange, "w:rPr");
|
|
783
|
-
if (innerRPr) Object.assign(rev, parseRunProperties(innerRPr));
|
|
784
|
-
if (Object.keys(rev).length > 0) opts.revision = rev;
|
|
785
|
-
}
|
|
786
|
-
return opts;
|
|
787
|
-
}
|
|
788
|
-
/**
|
|
789
|
-
* Parse a w:bdr element into BorderOptions.
|
|
790
|
-
*/
|
|
791
|
-
function parseBorder(el) {
|
|
792
|
-
const opts = {};
|
|
793
|
-
const style = attr(el, "w:val");
|
|
794
|
-
if (style) opts.style = style;
|
|
795
|
-
const color = colorAttr(el, "w:color");
|
|
796
|
-
if (color) opts.color = color;
|
|
797
|
-
const size = attrNum(el, "w:sz");
|
|
798
|
-
if (size !== void 0) opts.size = size;
|
|
799
|
-
const space = attrNum(el, "w:space");
|
|
800
|
-
if (space !== void 0) opts.space = space;
|
|
801
|
-
const shadow = attrBool(el, "w:shadow");
|
|
802
|
-
if (shadow !== void 0) opts.shadow = shadow;
|
|
803
|
-
const frame = attrBool(el, "w:frame");
|
|
804
|
-
if (frame !== void 0) opts.frame = frame;
|
|
805
|
-
return opts;
|
|
806
|
-
}
|
|
807
|
-
/**
|
|
808
|
-
* Parse a w:shd element into ShadingAttributesProperties.
|
|
809
|
-
*/
|
|
810
|
-
function parseShading(el) {
|
|
811
|
-
const opts = {};
|
|
812
|
-
const fill = colorAttr(el, "w:fill");
|
|
813
|
-
if (fill) opts.fill = fill;
|
|
814
|
-
const color = colorAttr(el, "w:color");
|
|
815
|
-
if (color) opts.color = color;
|
|
816
|
-
const type = attr(el, "w:val");
|
|
817
|
-
if (type) opts.type = type;
|
|
818
|
-
return opts;
|
|
819
|
-
}
|
|
820
|
-
/**
|
|
821
|
-
* Parse a w:eastAsianLayout element into EastAsianLayoutOptions.
|
|
822
|
-
*/
|
|
823
|
-
function parseEastAsianLayout(el) {
|
|
824
|
-
const opts = {};
|
|
825
|
-
const id = attrNum(el, "w:id");
|
|
826
|
-
if (id !== void 0) opts.id = id;
|
|
827
|
-
const combine = attrBool(el, "w:combine");
|
|
828
|
-
if (combine !== void 0) opts.combine = combine;
|
|
829
|
-
const combineBrackets = attr(el, "w:combineBrackets");
|
|
830
|
-
if (combineBrackets) opts.combineBrackets = combineBrackets;
|
|
831
|
-
const vert = attrBool(el, "w:vert");
|
|
832
|
-
if (vert !== void 0) opts.vert = vert;
|
|
833
|
-
const vertCompress = attrBool(el, "w:vertCompress");
|
|
834
|
-
if (vertCompress !== void 0) opts.vertCompress = vertCompress;
|
|
835
|
-
return opts;
|
|
836
|
-
}
|
|
837
|
-
/** Matches w:br[@w:type="page"] → PageBreak */
|
|
838
|
-
const PARSED_PAGE_BREAK = Symbol("PageBreak");
|
|
839
|
-
/** Matches w:br (line break) */
|
|
840
|
-
const PARSED_LINE_BREAK = Symbol("LineBreak");
|
|
841
|
-
/** Matches w:tab */
|
|
842
|
-
const PARSED_TAB = Symbol("Tab");
|
|
843
|
-
/** Matches w:cr */
|
|
844
|
-
const PARSED_CR = Symbol("CarriageReturn");
|
|
845
|
-
/** Matches w:noBreakHyphen */
|
|
846
|
-
const PARSED_NO_BREAK_HYPHEN = Symbol("NoBreakHyphen");
|
|
847
|
-
/** Matches w:softHyphen */
|
|
848
|
-
const PARSED_SOFT_HYPHEN = Symbol("SoftHyphen");
|
|
849
|
-
/** Matches w:footnoteRef — auto-generated by Footnote class */
|
|
850
|
-
const PARSED_FOOTNOTE_REF = Symbol("FootnoteRef");
|
|
851
|
-
/** Matches w:br[@w:type="column"] */
|
|
852
|
-
const PARSED_COLUMN_BREAK = Symbol("ColumnBreak");
|
|
853
|
-
/** Matches w:dayShort */
|
|
854
|
-
const PARSED_DAY_SHORT = Symbol("DayShort");
|
|
855
|
-
/** Matches w:monthShort */
|
|
856
|
-
const PARSED_MONTH_SHORT = Symbol("MonthShort");
|
|
857
|
-
/** Matches w:yearShort */
|
|
858
|
-
const PARSED_YEAR_SHORT = Symbol("YearShort");
|
|
859
|
-
/** Matches w:dayLong */
|
|
860
|
-
const PARSED_DAY_LONG = Symbol("DayLong");
|
|
861
|
-
/** Matches w:monthLong */
|
|
862
|
-
const PARSED_MONTH_LONG = Symbol("MonthLong");
|
|
863
|
-
/** Matches w:yearLong */
|
|
864
|
-
const PARSED_YEAR_LONG = Symbol("YearLong");
|
|
865
|
-
/** Matches w:annotationRef */
|
|
866
|
-
const PARSED_ANNOTATION_REF = Symbol("AnnotationRef");
|
|
867
|
-
/** Matches w:separator */
|
|
868
|
-
const PARSED_SEPARATOR = Symbol("Separator");
|
|
869
|
-
/** Matches w:continuationSeparator */
|
|
870
|
-
const PARSED_CONTINUATION_SEPARATOR = Symbol("ContinuationSeparator");
|
|
871
|
-
/** Matches w:pgNum */
|
|
872
|
-
const PARSED_PG_NUM = Symbol("PgNum");
|
|
873
|
-
/** Matches w:lastRenderedPageBreak */
|
|
874
|
-
const PARSED_LAST_RENDERED_PAGE_BREAK = Symbol("LastRenderedPageBreak");
|
|
875
|
-
/**
|
|
876
|
-
* Parse a w:r element into run data.
|
|
877
|
-
* Returns { properties, children } where children are parsed run content items.
|
|
878
|
-
*/
|
|
879
|
-
function parseRun(el, _ctx) {
|
|
880
|
-
const rPr = findChild(el, "w:rPr");
|
|
881
|
-
const properties = rPr ? parseRunProperties(rPr) : void 0;
|
|
882
|
-
const children = [];
|
|
883
|
-
for (const child of el.elements ?? []) switch (child.name) {
|
|
884
|
-
case "w:rPr": break;
|
|
885
|
-
case "w:t": {
|
|
886
|
-
const preserveSpace = attrBool(child, "xml:space");
|
|
887
|
-
let text = textOf(child);
|
|
888
|
-
if (preserveSpace && text) {}
|
|
889
|
-
children.push(text);
|
|
890
|
-
break;
|
|
891
|
-
}
|
|
892
|
-
case "w:delText": {
|
|
893
|
-
const text = textOf(child);
|
|
894
|
-
if (text) children.push(text);
|
|
895
|
-
break;
|
|
896
|
-
}
|
|
897
|
-
case "w:br": {
|
|
898
|
-
const brType = attr(child, "w:type");
|
|
899
|
-
if (brType === "page") children.push(PARSED_PAGE_BREAK);
|
|
900
|
-
else if (brType === "column") children.push(PARSED_COLUMN_BREAK);
|
|
901
|
-
else children.push(PARSED_LINE_BREAK);
|
|
902
|
-
break;
|
|
903
|
-
}
|
|
904
|
-
case "w:tab":
|
|
905
|
-
children.push(PARSED_TAB);
|
|
906
|
-
break;
|
|
907
|
-
case "w:cr":
|
|
908
|
-
children.push(PARSED_CR);
|
|
909
|
-
break;
|
|
910
|
-
case "w:noBreakHyphen":
|
|
911
|
-
children.push(PARSED_NO_BREAK_HYPHEN);
|
|
912
|
-
break;
|
|
913
|
-
case "w:softHyphen":
|
|
914
|
-
children.push(PARSED_SOFT_HYPHEN);
|
|
915
|
-
break;
|
|
916
|
-
case "w:commentReference": {
|
|
917
|
-
const id = attrNum(child, "w:id");
|
|
918
|
-
if (id !== void 0) children.push({ commentReference: id });
|
|
919
|
-
break;
|
|
920
|
-
}
|
|
921
|
-
case "w:drawing":
|
|
922
|
-
case "w:pict": break;
|
|
923
|
-
case "w:sym": {
|
|
924
|
-
const charVal = attr(child, "w:char");
|
|
925
|
-
const fontVal = attr(child, "w:font");
|
|
926
|
-
if (charVal) children.push({ symbolRun: {
|
|
927
|
-
char: charVal,
|
|
928
|
-
symbolfont: fontVal ?? "Wingdings"
|
|
929
|
-
} });
|
|
930
|
-
break;
|
|
931
|
-
}
|
|
932
|
-
case "w:footnoteReference": {
|
|
933
|
-
const id = attrNum(child, "w:id");
|
|
934
|
-
if (id !== void 0) children.push({ footnoteReference: id });
|
|
935
|
-
break;
|
|
936
|
-
}
|
|
937
|
-
case "w:endnoteReference": {
|
|
938
|
-
const id = attrNum(child, "w:id");
|
|
939
|
-
if (id !== void 0) children.push({ endnoteReference: id });
|
|
940
|
-
break;
|
|
941
|
-
}
|
|
942
|
-
case "w:footnoteRef":
|
|
943
|
-
case "w:endnoteRef":
|
|
944
|
-
children.push(PARSED_FOOTNOTE_REF);
|
|
945
|
-
break;
|
|
946
|
-
case "w:dayShort":
|
|
947
|
-
children.push(PARSED_DAY_SHORT);
|
|
948
|
-
break;
|
|
949
|
-
case "w:monthShort":
|
|
950
|
-
children.push(PARSED_MONTH_SHORT);
|
|
951
|
-
break;
|
|
952
|
-
case "w:yearShort":
|
|
953
|
-
children.push(PARSED_YEAR_SHORT);
|
|
954
|
-
break;
|
|
955
|
-
case "w:dayLong":
|
|
956
|
-
children.push(PARSED_DAY_LONG);
|
|
957
|
-
break;
|
|
958
|
-
case "w:monthLong":
|
|
959
|
-
children.push(PARSED_MONTH_LONG);
|
|
960
|
-
break;
|
|
961
|
-
case "w:yearLong":
|
|
962
|
-
children.push(PARSED_YEAR_LONG);
|
|
963
|
-
break;
|
|
964
|
-
case "w:annotationRef":
|
|
965
|
-
children.push(PARSED_ANNOTATION_REF);
|
|
966
|
-
break;
|
|
967
|
-
case "w:separator":
|
|
968
|
-
children.push(PARSED_SEPARATOR);
|
|
969
|
-
break;
|
|
970
|
-
case "w:continuationSeparator":
|
|
971
|
-
children.push(PARSED_CONTINUATION_SEPARATOR);
|
|
972
|
-
break;
|
|
973
|
-
case "w:pgNum":
|
|
974
|
-
children.push(PARSED_PG_NUM);
|
|
975
|
-
break;
|
|
976
|
-
case "w:lastRenderedPageBreak":
|
|
977
|
-
children.push(PARSED_LAST_RENDERED_PAGE_BREAK);
|
|
978
|
-
break;
|
|
979
|
-
default: break;
|
|
980
|
-
}
|
|
981
|
-
return {
|
|
982
|
-
properties,
|
|
983
|
-
children
|
|
984
|
-
};
|
|
985
|
-
}
|
|
986
|
-
/**
|
|
987
|
-
* Convert parsed run data into an RunOptions suitable for the Document constructor.
|
|
988
|
-
* Simplifies the parsed children into text + break format.
|
|
989
|
-
* If the run contains only a commentReference, returns { commentReference: id } instead.
|
|
990
|
-
* If the run only contains footnoteRef/endnoteRef (auto-generated), returns empty options.
|
|
991
|
-
*
|
|
992
|
-
* When empty run elements (tab, noBreakHyphen, date fields, etc.) are present,
|
|
993
|
-
* uses children[] format to preserve them for round-trip fidelity.
|
|
994
|
-
*/
|
|
995
|
-
/** Mapping from parse symbols to RunOptions child objects for empty elements. */
|
|
996
|
-
const SYMBOL_TO_CHILD = new Map([
|
|
997
|
-
[PARSED_TAB, { tab: true }],
|
|
998
|
-
[PARSED_CR, { carriageReturn: true }],
|
|
999
|
-
[PARSED_NO_BREAK_HYPHEN, { noBreakHyphen: true }],
|
|
1000
|
-
[PARSED_SOFT_HYPHEN, { softHyphen: true }],
|
|
1001
|
-
[PARSED_DAY_SHORT, { dayShort: true }],
|
|
1002
|
-
[PARSED_MONTH_SHORT, { monthShort: true }],
|
|
1003
|
-
[PARSED_YEAR_SHORT, { yearShort: true }],
|
|
1004
|
-
[PARSED_DAY_LONG, { dayLong: true }],
|
|
1005
|
-
[PARSED_MONTH_LONG, { monthLong: true }],
|
|
1006
|
-
[PARSED_YEAR_LONG, { yearLong: true }],
|
|
1007
|
-
[PARSED_ANNOTATION_REF, { annotationRef: true }],
|
|
1008
|
-
[PARSED_SEPARATOR, { separator: true }],
|
|
1009
|
-
[PARSED_CONTINUATION_SEPARATOR, { continuationSeparator: true }],
|
|
1010
|
-
[PARSED_PG_NUM, { pgNum: true }],
|
|
1011
|
-
[PARSED_LAST_RENDERED_PAGE_BREAK, { lastRenderedPageBreak: true }]
|
|
1012
|
-
]);
|
|
1013
|
-
function parsedRunToOptions(parsed) {
|
|
1014
|
-
const contentChildren = parsed.children.filter((c) => c !== PARSED_FOOTNOTE_REF);
|
|
1015
|
-
if (contentChildren.length === 0 && parsed.children.some((c) => c === PARSED_FOOTNOTE_REF)) return null;
|
|
1016
|
-
const opts = { ...parsed.properties };
|
|
1017
|
-
const isRefChild = (c) => typeof c === "object" && c !== null && ("commentReference" in c || "footnoteReference" in c || "endnoteReference" in c);
|
|
1018
|
-
const refChildren = contentChildren.filter(isRefChild);
|
|
1019
|
-
const nonRefChildren = contentChildren.filter((c) => !isRefChild(c));
|
|
1020
|
-
if (refChildren.length > 0 && nonRefChildren.length === 0) return refChildren[0];
|
|
1021
|
-
const symbolIdx = nonRefChildren.findIndex((c) => typeof c === "object" && c !== null && "symbolRun" in c);
|
|
1022
|
-
if (symbolIdx >= 0 && nonRefChildren.length === 1 && !parsed.properties) return nonRefChildren[symbolIdx];
|
|
1023
|
-
const textParts = [];
|
|
1024
|
-
let breakCount = 0;
|
|
1025
|
-
let hasPageBreak = false;
|
|
1026
|
-
let hasColumnBreak = false;
|
|
1027
|
-
const extraChildren = [];
|
|
1028
|
-
for (const child of nonRefChildren) if (typeof child === "string") textParts.push(child);
|
|
1029
|
-
else if (child === PARSED_LINE_BREAK) breakCount++;
|
|
1030
|
-
else if (child === PARSED_PAGE_BREAK) hasPageBreak = true;
|
|
1031
|
-
else if (child === PARSED_COLUMN_BREAK) hasColumnBreak = true;
|
|
1032
|
-
else {
|
|
1033
|
-
const mapped = SYMBOL_TO_CHILD.get(child);
|
|
1034
|
-
if (mapped) extraChildren.push(mapped);
|
|
1035
|
-
}
|
|
1036
|
-
if (extraChildren.length > 0) {
|
|
1037
|
-
const children = [];
|
|
1038
|
-
for (const child of nonRefChildren) if (typeof child === "string") children.push(child);
|
|
1039
|
-
else if (child === PARSED_LINE_BREAK) children.push({ break: 1 });
|
|
1040
|
-
else if (child === PARSED_PAGE_BREAK) children.push({ pageBreak: true });
|
|
1041
|
-
else if (child === PARSED_COLUMN_BREAK) children.push({ columnBreak: true });
|
|
1042
|
-
else {
|
|
1043
|
-
const mapped = SYMBOL_TO_CHILD.get(child);
|
|
1044
|
-
if (mapped) children.push(mapped);
|
|
1045
|
-
}
|
|
1046
|
-
opts.children = children;
|
|
1047
|
-
} else {
|
|
1048
|
-
if (textParts.length > 0) opts.text = textParts.join("");
|
|
1049
|
-
if (breakCount > 0) opts.break = breakCount;
|
|
1050
|
-
if (hasPageBreak) opts.pageBreak = true;
|
|
1051
|
-
if (hasColumnBreak) opts.columnBreak = true;
|
|
1052
|
-
}
|
|
1053
|
-
if (Object.keys(opts).length === 0 && textParts.length === 0 && breakCount === 0 && !hasPageBreak && !hasColumnBreak && extraChildren.length === 0) return null;
|
|
1054
|
-
return opts;
|
|
1055
|
-
}
|
|
1056
|
-
//#endregion
|
|
1057
601
|
//#region src/parts/numbering/level.ts
|
|
1058
602
|
/**
|
|
1059
603
|
* Number format types for list levels.
|
|
@@ -2072,7 +1616,7 @@ function parseStyleElement(el, parseParagraphProperties, ctx) {
|
|
|
2072
1616
|
*
|
|
2073
1617
|
* @module
|
|
2074
1618
|
*/
|
|
2075
|
-
function escapeAttr$
|
|
1619
|
+
function escapeAttr$1(s) {
|
|
2076
1620
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
2077
1621
|
}
|
|
2078
1622
|
/** Derive the namespace-prefixed val attribute from the element tag. */
|
|
@@ -2086,12 +1630,12 @@ function numVal(tag, val) {
|
|
|
2086
1630
|
return val !== void 0 ? `<${tag} ${valAttr(tag)}="${val}"/>` : "";
|
|
2087
1631
|
}
|
|
2088
1632
|
function strVal(tag, val) {
|
|
2089
|
-
return val !== void 0 ? `<${tag} ${valAttr(tag)}="${escapeAttr$
|
|
1633
|
+
return val !== void 0 ? `<${tag} ${valAttr(tag)}="${escapeAttr$1(val)}"/>` : "";
|
|
2090
1634
|
}
|
|
2091
1635
|
/** Build attribute string from key-value pairs, skipping undefined. */
|
|
2092
1636
|
function attrStr(attrs) {
|
|
2093
1637
|
const parts = [];
|
|
2094
|
-
for (const [k, v] of Object.entries(attrs)) if (v !== void 0) parts.push(`${k}="${escapeAttr$
|
|
1638
|
+
for (const [k, v] of Object.entries(attrs)) if (v !== void 0) parts.push(`${k}="${escapeAttr$1(String(v))}"`);
|
|
2095
1639
|
return parts.join(" ");
|
|
2096
1640
|
}
|
|
2097
1641
|
/** Self-closing element with attributes only. */
|
|
@@ -2100,7 +1644,7 @@ function attrEl(tag, attrs) {
|
|
|
2100
1644
|
return a ? `<${tag} ${a}/>` : `<${tag}/>`;
|
|
2101
1645
|
}
|
|
2102
1646
|
function compatSetting(name, val) {
|
|
2103
|
-
return `<w:compatSetting w:name="${escapeAttr$
|
|
1647
|
+
return `<w:compatSetting w:name="${escapeAttr$1(name)}" w:uri="http://schemas.microsoft.com/office/word" w:val="${val}"/>`;
|
|
2104
1648
|
}
|
|
2105
1649
|
function maybeDerive(password, hashValue) {
|
|
2106
1650
|
return password !== void 0 && hashValue === void 0 ? derivePasswordHash(password) : void 0;
|
|
@@ -3623,29 +3167,8 @@ function parseCustomXmlInline(el, ctx) {
|
|
|
3623
3167
|
if (uri) cx.uri = uri;
|
|
3624
3168
|
const pr = findChild(el, "w:customXmlPr");
|
|
3625
3169
|
if (pr) {
|
|
3626
|
-
const
|
|
3627
|
-
|
|
3628
|
-
if (placeholder) {
|
|
3629
|
-
const pval = attr(placeholder, "w:val");
|
|
3630
|
-
if (pval) cxPr.placeholder = pval;
|
|
3631
|
-
}
|
|
3632
|
-
const attrsList = [];
|
|
3633
|
-
for (const a of pr.elements ?? []) {
|
|
3634
|
-
if (a.name !== "w:attr") continue;
|
|
3635
|
-
const name = attr(a, "w:name");
|
|
3636
|
-
const val = attr(a, "w:val");
|
|
3637
|
-
if (name && val) {
|
|
3638
|
-
const ao = {
|
|
3639
|
-
name,
|
|
3640
|
-
val
|
|
3641
|
-
};
|
|
3642
|
-
const auri = attr(a, "w:uri");
|
|
3643
|
-
if (auri) ao.uri = auri;
|
|
3644
|
-
attrsList.push(ao);
|
|
3645
|
-
}
|
|
3646
|
-
}
|
|
3647
|
-
if (attrsList.length > 0) cxPr.attrs = attrsList;
|
|
3648
|
-
if (cxPr.placeholder !== void 0 || cxPr.attrs !== void 0) cx.customXmlPr = cxPr;
|
|
3170
|
+
const parsed = parseCustomXmlPr(pr);
|
|
3171
|
+
if (parsed.placeholder !== void 0 || parsed.attributes !== void 0) cx.customXmlPr = parsed;
|
|
3649
3172
|
}
|
|
3650
3173
|
const content = parseContainerChildren(el, ctx);
|
|
3651
3174
|
if (content.length > 0) cx.children = content;
|
|
@@ -3678,17 +3201,19 @@ function parseCustomXmlRangeStart(el) {
|
|
|
3678
3201
|
/**
|
|
3679
3202
|
* Parse a w:p element into ParagraphOptions.
|
|
3680
3203
|
*/
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3204
|
+
/**
|
|
3205
|
+
* Parse run-level children shared by paragraphs and inline-SDT content.
|
|
3206
|
+
* Includes the field accumulator that collapses form/complex fields spanning
|
|
3207
|
+
* multiple w:r runs into a single child.
|
|
3208
|
+
*/
|
|
3209
|
+
function parseRunLevelChildren(elements, ctx) {
|
|
3685
3210
|
const childList = [];
|
|
3686
3211
|
let fieldKind = null;
|
|
3687
3212
|
let pendingFormField = null;
|
|
3688
3213
|
let pendingInstruction = "";
|
|
3689
3214
|
let pendingResult = "";
|
|
3690
3215
|
let collectingResult = false;
|
|
3691
|
-
for (const child of
|
|
3216
|
+
for (const child of elements ?? []) switch (child.name) {
|
|
3692
3217
|
case "w:pPr": break;
|
|
3693
3218
|
case "w:r": {
|
|
3694
3219
|
const fldCharEl = findChild(child, "w:fldChar");
|
|
@@ -4048,8 +3573,27 @@ function parseParagraph(el, ctx) {
|
|
|
4048
3573
|
if (id !== void 0) childList.push({ customXmlMoveToRangeEnd: id });
|
|
4049
3574
|
break;
|
|
4050
3575
|
}
|
|
3576
|
+
case "w:sdt": {
|
|
3577
|
+
const sdtPr = findChild(child, "w:sdtPr");
|
|
3578
|
+
const properties = sdtPr ? parseSdtProperties(sdtPr) : {};
|
|
3579
|
+
const sdtEndPr = findChild(child, "w:sdtEndPr");
|
|
3580
|
+
const endProperties = sdtEndPr ? parseRunProperties(sdtEndPr) : void 0;
|
|
3581
|
+
const sdtChildren = parseRunLevelChildren(findChild(child, "w:sdtContent")?.elements, ctx);
|
|
3582
|
+
const sdt = { properties };
|
|
3583
|
+
if (sdtChildren.length > 0) sdt.children = sdtChildren;
|
|
3584
|
+
if (endProperties) sdt.endProperties = endProperties;
|
|
3585
|
+
childList.push({ sdt });
|
|
3586
|
+
break;
|
|
3587
|
+
}
|
|
4051
3588
|
default: break;
|
|
4052
3589
|
}
|
|
3590
|
+
return childList;
|
|
3591
|
+
}
|
|
3592
|
+
function parseParagraph(el, ctx) {
|
|
3593
|
+
const opts = {};
|
|
3594
|
+
const pPr = findChild(el, "w:pPr");
|
|
3595
|
+
if (pPr) Object.assign(opts, parseParagraphProperties(pPr, ctx));
|
|
3596
|
+
const childList = parseRunLevelChildren(el.elements, ctx);
|
|
4053
3597
|
if (childList.length > 0) {
|
|
4054
3598
|
if (childList.every((c) => typeof c === "object" && c !== null && "text" in c && Object.keys(c).length === 1)) {
|
|
4055
3599
|
const combined = childList.map((c) => c.text).join("");
|
|
@@ -4156,151 +3700,6 @@ const endnotesDesc = {
|
|
|
4156
3700
|
}
|
|
4157
3701
|
};
|
|
4158
3702
|
//#endregion
|
|
4159
|
-
//#region src/parts/sdt/sdt-parse.ts
|
|
4160
|
-
/**
|
|
4161
|
-
* Structured Document Tag parser for DOCX documents.
|
|
4162
|
-
*
|
|
4163
|
-
* Parses w:sdt elements into SdtPropertiesOptions + children.
|
|
4164
|
-
*
|
|
4165
|
-
* @module
|
|
4166
|
-
*/
|
|
4167
|
-
/**
|
|
4168
|
-
* Parse w:sdtPr element into SdtPropertiesOptions.
|
|
4169
|
-
*/
|
|
4170
|
-
function parseSdtProperties(el) {
|
|
4171
|
-
const opts = {};
|
|
4172
|
-
const alias = findChild(el, "w:alias");
|
|
4173
|
-
if (alias) opts.alias = attr(alias, "w:val");
|
|
4174
|
-
const tag = findChild(el, "w:tag");
|
|
4175
|
-
if (tag) {
|
|
4176
|
-
const val = attr(tag, "w:val");
|
|
4177
|
-
if (val) opts.tag = val;
|
|
4178
|
-
}
|
|
4179
|
-
const id = findChild(el, "w:id");
|
|
4180
|
-
if (id) {
|
|
4181
|
-
const val = attrNum(id, "w:val");
|
|
4182
|
-
if (val !== void 0) opts.id = val;
|
|
4183
|
-
}
|
|
4184
|
-
const lock = findChild(el, "w:lock");
|
|
4185
|
-
if (lock) {
|
|
4186
|
-
const val = attr(lock, "w:val");
|
|
4187
|
-
if (val) opts.lock = val;
|
|
4188
|
-
}
|
|
4189
|
-
const temporary = findChild(el, "w:temporary");
|
|
4190
|
-
if (temporary) opts.temporary = attrBool(temporary, "w:val") ?? true;
|
|
4191
|
-
const showingPlcHdr = findChild(el, "w:showingPlcHdr");
|
|
4192
|
-
if (showingPlcHdr) opts.showingPlaceholder = attrBool(showingPlcHdr, "w:val") ?? true;
|
|
4193
|
-
const label = findChild(el, "w:label");
|
|
4194
|
-
if (label) {
|
|
4195
|
-
const val = attrNum(label, "w:val");
|
|
4196
|
-
if (val !== void 0) opts.label = val;
|
|
4197
|
-
}
|
|
4198
|
-
const tabIndex = findChild(el, "w:tabIndex");
|
|
4199
|
-
if (tabIndex) {
|
|
4200
|
-
const val = attrNum(tabIndex, "w:val");
|
|
4201
|
-
if (val !== void 0) opts.tabIndex = val;
|
|
4202
|
-
}
|
|
4203
|
-
const dataBinding = findChild(el, "w:dataBinding");
|
|
4204
|
-
if (dataBinding) opts.dataBinding = {
|
|
4205
|
-
xpath: attr(dataBinding, "w:xpath") ?? "",
|
|
4206
|
-
storeItemID: attr(dataBinding, "w:storeItemID") ?? "",
|
|
4207
|
-
prefixMappings: attr(dataBinding, "w:prefixMappings")
|
|
4208
|
-
};
|
|
4209
|
-
if (findChild(el, "w:equation")) opts.equation = true;
|
|
4210
|
-
else if (findChild(el, "w:comboBox")) {
|
|
4211
|
-
const comboBox = findChild(el, "w:comboBox");
|
|
4212
|
-
const items = [];
|
|
4213
|
-
for (const li of children(comboBox, "w:listItem")) items.push({
|
|
4214
|
-
displayText: attr(li, "w:displayText"),
|
|
4215
|
-
value: attr(li, "w:value")
|
|
4216
|
-
});
|
|
4217
|
-
opts.comboBox = {
|
|
4218
|
-
items: items.length > 0 ? items : void 0,
|
|
4219
|
-
lastValue: attr(comboBox, "w:lastValue")
|
|
4220
|
-
};
|
|
4221
|
-
} else if (findChild(el, "w:date")) {
|
|
4222
|
-
const date = findChild(el, "w:date");
|
|
4223
|
-
const dateOpts = {};
|
|
4224
|
-
const dateFormat = findChild(date, "w:dateFormat");
|
|
4225
|
-
if (dateFormat) dateOpts.dateFormat = textOf(dateFormat);
|
|
4226
|
-
const lid = findChild(date, "w:lid");
|
|
4227
|
-
if (lid) dateOpts.languageId = textOf(lid);
|
|
4228
|
-
const storeMapped = findChild(date, "w:storeMappedDataAs");
|
|
4229
|
-
if (storeMapped) dateOpts.storeMappedDataAs = attr(storeMapped, "w:val");
|
|
4230
|
-
const calendar = findChild(date, "w:calendar");
|
|
4231
|
-
if (calendar) dateOpts.calendar = attr(calendar, "w:val");
|
|
4232
|
-
const fullDate = attr(date, "w:fullDate");
|
|
4233
|
-
if (fullDate) dateOpts.fullDate = fullDate;
|
|
4234
|
-
opts.date = dateOpts;
|
|
4235
|
-
} else if (findChild(el, "w:dropDownList")) {
|
|
4236
|
-
const ddl = findChild(el, "w:dropDownList");
|
|
4237
|
-
const items = [];
|
|
4238
|
-
for (const li of children(ddl, "w:listItem")) items.push({
|
|
4239
|
-
displayText: attr(li, "w:displayText"),
|
|
4240
|
-
value: attr(li, "w:value")
|
|
4241
|
-
});
|
|
4242
|
-
opts.dropDownList = {
|
|
4243
|
-
items: items.length > 0 ? items : void 0,
|
|
4244
|
-
lastValue: attr(ddl, "w:lastValue")
|
|
4245
|
-
};
|
|
4246
|
-
} else if (findChild(el, "w:picture")) opts.picture = true;
|
|
4247
|
-
else if (findChild(el, "w:richText")) opts.richText = true;
|
|
4248
|
-
else if (findChild(el, "w:text")) opts.text = { multiLine: attrBool(findChild(el, "w:text"), "w:multiLine") };
|
|
4249
|
-
else if (findChild(el, "w:citation")) opts.citation = true;
|
|
4250
|
-
else if (findChild(el, "w:group")) opts.group = true;
|
|
4251
|
-
else if (findChild(el, "w:bibliography")) opts.bibliography = true;
|
|
4252
|
-
else if (findChild(el, "w:docPartObj")) {
|
|
4253
|
-
const dp = findChild(el, "w:docPartObj");
|
|
4254
|
-
opts.docPartObj = {};
|
|
4255
|
-
const gallery = findChild(dp, "w:docPartGallery");
|
|
4256
|
-
if (gallery) opts.docPartObj.gallery = attr(gallery, "w:val");
|
|
4257
|
-
const category = findChild(dp, "w:docPartCategory");
|
|
4258
|
-
if (category) opts.docPartObj.category = attr(category, "w:val");
|
|
4259
|
-
} else if (findChild(el, "w:docPartList")) {
|
|
4260
|
-
const dp = findChild(el, "w:docPartList");
|
|
4261
|
-
opts.docPartList = {};
|
|
4262
|
-
const gallery = findChild(dp, "w:docPartGallery");
|
|
4263
|
-
if (gallery) opts.docPartList.gallery = attr(gallery, "w:val");
|
|
4264
|
-
const category = findChild(dp, "w:docPartCategory");
|
|
4265
|
-
if (category) opts.docPartList.category = attr(category, "w:val");
|
|
4266
|
-
} else if (findChild(el, "w14:checkbox")) {
|
|
4267
|
-
const cb = findChild(el, "w14:checkbox");
|
|
4268
|
-
const cbObj = {};
|
|
4269
|
-
const checked = findChild(cb, "w14:checked");
|
|
4270
|
-
if (checked) cbObj.checked = attrBool(checked, "w14:val") ?? true;
|
|
4271
|
-
const checkedState = findChild(cb, "w14:checkedState");
|
|
4272
|
-
if (checkedState) cbObj.checkedState = {
|
|
4273
|
-
val: attr(checkedState, "w14:val") ?? "",
|
|
4274
|
-
font: attr(checkedState, "w14:font")
|
|
4275
|
-
};
|
|
4276
|
-
const uncheckedState = findChild(cb, "w14:uncheckedState");
|
|
4277
|
-
if (uncheckedState) cbObj.uncheckedState = {
|
|
4278
|
-
val: attr(uncheckedState, "w14:val") ?? "",
|
|
4279
|
-
font: attr(uncheckedState, "w14:font")
|
|
4280
|
-
};
|
|
4281
|
-
opts.checkbox = cbObj;
|
|
4282
|
-
}
|
|
4283
|
-
return opts;
|
|
4284
|
-
}
|
|
4285
|
-
/**
|
|
4286
|
-
* Parse a block-level w:sdt element.
|
|
4287
|
-
* Returns an object suitable for the { sdt: ... } SectionChild variant.
|
|
4288
|
-
*/
|
|
4289
|
-
function parseSdtBlock(el, ctx, parseChildren) {
|
|
4290
|
-
const sdtPr = findChild(el, "w:sdtPr");
|
|
4291
|
-
const properties = sdtPr ? parseSdtProperties(sdtPr) : {};
|
|
4292
|
-
const sdtContent = findChild(el, "w:sdtContent");
|
|
4293
|
-
let childList;
|
|
4294
|
-
if (sdtContent) {
|
|
4295
|
-
childList = parseChildren(sdtContent.elements ?? [], ctx);
|
|
4296
|
-
if (childList.length === 0) childList = void 0;
|
|
4297
|
-
}
|
|
4298
|
-
return {
|
|
4299
|
-
properties,
|
|
4300
|
-
children: childList
|
|
4301
|
-
};
|
|
4302
|
-
}
|
|
4303
|
-
//#endregion
|
|
4304
3703
|
//#region src/parts/perm-start.ts
|
|
4305
3704
|
/**
|
|
4306
3705
|
* Permission range markers for WordprocessingML document protection.
|
|
@@ -4481,7 +3880,7 @@ const fontTableDesc = {
|
|
|
4481
3880
|
};
|
|
4482
3881
|
//#endregion
|
|
4483
3882
|
//#region src/parts/bibliography.ts
|
|
4484
|
-
function escapeXml$
|
|
3883
|
+
function escapeXml$1(s) {
|
|
4485
3884
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
4486
3885
|
}
|
|
4487
3886
|
const SOURCE_FIELDS = [
|
|
@@ -4506,13 +3905,13 @@ const bibliographyDesc = {
|
|
|
4506
3905
|
kind: "custom",
|
|
4507
3906
|
stringify(opts, _ctx) {
|
|
4508
3907
|
const attrParts = ["xmlns:b=\"http://schemas.openxmlformats.org/officeDocument/2006/bibliography\""];
|
|
4509
|
-
if (opts.styleName !== void 0) attrParts.push(`StyleName="${escapeXml$
|
|
3908
|
+
if (opts.styleName !== void 0) attrParts.push(`StyleName="${escapeXml$1(opts.styleName)}"`);
|
|
4510
3909
|
const parts = [`<b:Sources ${attrParts.join(" ")}>`];
|
|
4511
3910
|
for (const source of opts.sources) {
|
|
4512
3911
|
const sourceParts = [];
|
|
4513
3912
|
for (const [tagName, key] of SOURCE_FIELDS) {
|
|
4514
3913
|
const value = source[key];
|
|
4515
|
-
if (value !== void 0) sourceParts.push(`<b:${tagName}>${escapeXml$
|
|
3914
|
+
if (value !== void 0) sourceParts.push(`<b:${tagName}>${escapeXml$1(value)}</b:${tagName}>`);
|
|
4516
3915
|
}
|
|
4517
3916
|
parts.push(`<b:Source>${sourceParts.join("")}</b:Source>`);
|
|
4518
3917
|
}
|
|
@@ -4697,15 +4096,15 @@ const glossaryDesc = {
|
|
|
4697
4096
|
};
|
|
4698
4097
|
//#endregion
|
|
4699
4098
|
//#region src/parts/comments.ts
|
|
4700
|
-
function escapeAttr
|
|
4099
|
+
function escapeAttr(s) {
|
|
4701
4100
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
4702
4101
|
}
|
|
4703
4102
|
const COMMENTS_NS = "xmlns:aink=\"http://schemas.microsoft.com/office/drawing/2016/ink\" xmlns:am3d=\"http://schemas.microsoft.com/office/drawing/2017/model3d\" xmlns:cx=\"http://schemas.microsoft.com/office/drawing/2014/chartex\" xmlns:cx1=\"http://schemas.microsoft.com/office/drawing/2015/9/8/chartex\" xmlns:cx2=\"http://schemas.microsoft.com/office/drawing/2015/10/21/chartex\" xmlns:cx3=\"http://schemas.microsoft.com/office/drawing/2016/5/9/chartex\" xmlns:cx4=\"http://schemas.microsoft.com/office/drawing/2016/5/10/chartex\" xmlns:cx5=\"http://schemas.microsoft.com/office/drawing/2016/5/11/chartex\" xmlns:cx6=\"http://schemas.microsoft.com/office/drawing/2016/5/12/chartex\" xmlns:cx7=\"http://schemas.microsoft.com/office/drawing/2016/5/13/chartex\" xmlns:cx8=\"http://schemas.microsoft.com/office/drawing/2016/5/14/chartex\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:w16=\"http://schemas.microsoft.com/office/word/2018/wordml\" xmlns:w16cex=\"http://schemas.microsoft.com/office/word/2018/wordml/cex\" xmlns:w16cid=\"http://schemas.microsoft.com/office/word/2016/wordml/cid\" xmlns:w16sdtdh=\"http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash\" xmlns:w16se=\"http://schemas.microsoft.com/office/word/2015/wordml/symex\" xmlns:wne=\"http://schemas.openxmlformats.org/office/word/2006/wordml\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\"";
|
|
4704
4103
|
function stringifyComment(opts, ctx) {
|
|
4705
4104
|
const dateStr = typeof opts.date === "string" ? opts.date : (opts.date ?? /* @__PURE__ */ new Date()).toISOString();
|
|
4706
|
-
const attrs = [`w:id="${opts.id}"`, `w:date="${escapeAttr
|
|
4707
|
-
if (opts.author !== void 0) attrs.push(`w:author="${escapeAttr
|
|
4708
|
-
if (opts.initials !== void 0) attrs.push(`w:initials="${escapeAttr
|
|
4105
|
+
const attrs = [`w:id="${opts.id}"`, `w:date="${escapeAttr(dateStr)}"`];
|
|
4106
|
+
if (opts.author !== void 0) attrs.push(`w:author="${escapeAttr(opts.author)}"`);
|
|
4107
|
+
if (opts.initials !== void 0) attrs.push(`w:initials="${escapeAttr(opts.initials)}"`);
|
|
4709
4108
|
const parts = [];
|
|
4710
4109
|
for (const child of opts.children) parts.push(stringifyParagraphInline(child, ctx));
|
|
4711
4110
|
return `<w:comment ${attrs.join(" ")}>${parts.join("")}</w:comment>`;
|
|
@@ -4980,438 +4379,6 @@ const relationshipsDesc = {
|
|
|
4980
4379
|
}
|
|
4981
4380
|
};
|
|
4982
4381
|
//#endregion
|
|
4983
|
-
//#region src/parts/bodychildren.ts
|
|
4984
|
-
/**
|
|
4985
|
-
* Body-level child descriptors for DOCX.
|
|
4986
|
-
*
|
|
4987
|
-
* Provides descriptor-based stringification for section children.
|
|
4988
|
-
* All types use pure string builders — zero class instantiation, zero toXml().
|
|
4989
|
-
*
|
|
4990
|
-
* @module
|
|
4991
|
-
*/
|
|
4992
|
-
function escapeAttr(s) {
|
|
4993
|
-
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
4994
|
-
}
|
|
4995
|
-
const ALTCHUNK_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk";
|
|
4996
|
-
function wrapHtmlDocument(fragment) {
|
|
4997
|
-
if (/<(!DOCTYPE|html|HTML)/i.test(fragment)) return fragment;
|
|
4998
|
-
return `<!DOCTYPE html>\n<html><head><meta charset="utf-8"></head>\n<body>${fragment}</body></html>`;
|
|
4999
|
-
}
|
|
5000
|
-
const altChunkDesc = {
|
|
5001
|
-
kind: "custom",
|
|
5002
|
-
stringify(opts, ctx) {
|
|
5003
|
-
const relId = uniqueId();
|
|
5004
|
-
const extension = opts.extension;
|
|
5005
|
-
const partPath = `afchunks/afchunk${relId}.${extension}`;
|
|
5006
|
-
const rawData = typeof opts.data === "string" ? new TextEncoder().encode(opts.data) : opts.data;
|
|
5007
|
-
const data = opts.contentType === "text/html" && typeof opts.data === "string" ? new TextEncoder().encode(wrapHtmlDocument(opts.data)) : rawData;
|
|
5008
|
-
ctx.fileData.document.relationships.addRelationship(relId, ALTCHUNK_REL_TYPE, partPath);
|
|
5009
|
-
ctx.fileData.altChunks.addAltChunk(relId, {
|
|
5010
|
-
key: relId,
|
|
5011
|
-
data,
|
|
5012
|
-
path: partPath,
|
|
5013
|
-
extension,
|
|
5014
|
-
contentType: opts.contentType
|
|
5015
|
-
});
|
|
5016
|
-
const rId = `rId${relId}`;
|
|
5017
|
-
if (opts.matchSrc) return `<w:altChunk r:id="${rId}"><w:altChunkPr><w:matchSrc/></w:altChunkPr></w:altChunk>`;
|
|
5018
|
-
return `<w:altChunk r:id="${rId}"/>`;
|
|
5019
|
-
},
|
|
5020
|
-
parse(el, ctx) {
|
|
5021
|
-
const rId = attr(el, "r:id");
|
|
5022
|
-
const opts = {};
|
|
5023
|
-
const altChunkPr = findChild(el, "w:altChunkPr");
|
|
5024
|
-
if (altChunkPr && findChild(altChunkPr, "w:matchSrc")) opts.matchSrc = true;
|
|
5025
|
-
const dctx = ctx;
|
|
5026
|
-
if (rId) {
|
|
5027
|
-
const path = dctx.resolveRelationship(rId);
|
|
5028
|
-
if (path) {
|
|
5029
|
-
const data = dctx.getRaw(path);
|
|
5030
|
-
if (data) {
|
|
5031
|
-
opts.data = data;
|
|
5032
|
-
switch (path.split(".").pop() ?? "txt") {
|
|
5033
|
-
case "html":
|
|
5034
|
-
opts.contentType = "text/html";
|
|
5035
|
-
opts.extension = "html";
|
|
5036
|
-
break;
|
|
5037
|
-
case "rtf":
|
|
5038
|
-
opts.contentType = "application/rtf";
|
|
5039
|
-
opts.extension = "rtf";
|
|
5040
|
-
break;
|
|
5041
|
-
default:
|
|
5042
|
-
opts.contentType = "text/plain";
|
|
5043
|
-
opts.extension = "txt";
|
|
5044
|
-
break;
|
|
5045
|
-
}
|
|
5046
|
-
}
|
|
5047
|
-
}
|
|
5048
|
-
}
|
|
5049
|
-
return opts;
|
|
5050
|
-
}
|
|
5051
|
-
};
|
|
5052
|
-
const SUBDOC_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/subDocument";
|
|
5053
|
-
const subDocDesc = {
|
|
5054
|
-
kind: "custom",
|
|
5055
|
-
stringify(opts, ctx) {
|
|
5056
|
-
const relId = uniqueId();
|
|
5057
|
-
const partPath = `subdocs/subdoc${relId}.docx`;
|
|
5058
|
-
const data = typeof opts.data === "string" ? new TextEncoder().encode(opts.data) : opts.data;
|
|
5059
|
-
ctx.fileData.document.relationships.addRelationship(relId, SUBDOC_REL_TYPE, partPath);
|
|
5060
|
-
ctx.fileData.subDocs.addSubDoc(relId, {
|
|
5061
|
-
data,
|
|
5062
|
-
path: partPath
|
|
5063
|
-
});
|
|
5064
|
-
return `<w:subDoc r:id="rId${relId}"/>`;
|
|
5065
|
-
},
|
|
5066
|
-
parse(el, ctx) {
|
|
5067
|
-
const rId = attr(el, "r:id");
|
|
5068
|
-
const dctx = ctx;
|
|
5069
|
-
if (rId) {
|
|
5070
|
-
const path = dctx.resolveRelationship(rId);
|
|
5071
|
-
if (path) {
|
|
5072
|
-
const data = dctx.getRaw(path);
|
|
5073
|
-
if (data) return { data };
|
|
5074
|
-
}
|
|
5075
|
-
}
|
|
5076
|
-
return { data: new Uint8Array(0) };
|
|
5077
|
-
}
|
|
5078
|
-
};
|
|
5079
|
-
function escapeXml$1(s) {
|
|
5080
|
-
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
5081
|
-
}
|
|
5082
|
-
function sdtListItemXml(item, forceValue) {
|
|
5083
|
-
const attrs = [];
|
|
5084
|
-
if (item.displayText !== void 0) attrs.push(`w:displayText="${escapeXml$1(item.displayText)}"`);
|
|
5085
|
-
const value = item.value ?? (forceValue ? item.displayText : void 0);
|
|
5086
|
-
if (value !== void 0) attrs.push(`w:value="${escapeXml$1(value)}"`);
|
|
5087
|
-
return `<w:listItem ${attrs.join(" ")}/>`;
|
|
5088
|
-
}
|
|
5089
|
-
function sdtListTypeXml(name, options) {
|
|
5090
|
-
const parts = [];
|
|
5091
|
-
if (options.items) for (const item of options.items) parts.push(sdtListItemXml(item, name === "w:dropDownList"));
|
|
5092
|
-
const attrs = [];
|
|
5093
|
-
if (options.lastValue !== void 0) attrs.push(`w:lastValue="${escapeXml$1(options.lastValue)}"`);
|
|
5094
|
-
const attrStr = attrs.length ? " " + attrs.join(" ") : "";
|
|
5095
|
-
return parts.length ? `<${name}${attrStr}>${parts.join("")}</${name}>` : `<${name}${attrStr}/>`;
|
|
5096
|
-
}
|
|
5097
|
-
function sdtDateXml(options) {
|
|
5098
|
-
const parts = [];
|
|
5099
|
-
if (options.dateFormat !== void 0) parts.push(`<w:dateFormat w:val="${escapeXml$1(options.dateFormat)}"/>`);
|
|
5100
|
-
if (options.languageId !== void 0) parts.push(`<w:lid w:val="${escapeXml$1(options.languageId)}"/>`);
|
|
5101
|
-
if (options.storeMappedDataAs !== void 0) parts.push(`<w:storeMappedDataAs w:val="${options.storeMappedDataAs}"/>`);
|
|
5102
|
-
if (options.calendar !== void 0) parts.push(`<w:calendar w:val="${options.calendar}"/>`);
|
|
5103
|
-
const attrs = [];
|
|
5104
|
-
if (options.fullDate !== void 0) attrs.push(`w:fullDate="${options.fullDate}"`);
|
|
5105
|
-
const attrStr = attrs.length ? " " + attrs.join(" ") : "";
|
|
5106
|
-
return parts.length ? `<w:date${attrStr}>${parts.join("")}</w:date>` : `<w:date${attrStr}/>`;
|
|
5107
|
-
}
|
|
5108
|
-
function sdtDataBindingXml(options) {
|
|
5109
|
-
const attrs = [`w:xpath="${escapeXml$1(options.xpath)}"`, `w:storeItemID="${escapeXml$1(options.storeItemID)}"`];
|
|
5110
|
-
if (options.prefixMappings !== void 0) attrs.push(`w:prefixMappings="${escapeXml$1(options.prefixMappings)}"`);
|
|
5111
|
-
return `<w:dataBinding ${attrs.join(" ")}/>`;
|
|
5112
|
-
}
|
|
5113
|
-
function sdtDocPartXml(name, options) {
|
|
5114
|
-
const parts = [];
|
|
5115
|
-
if (options.gallery !== void 0) parts.push(`<w:docPartGallery w:val="${escapeXml$1(options.gallery)}"/>`);
|
|
5116
|
-
if (options.category !== void 0) parts.push(`<w:docPartCategory w:val="${escapeXml$1(options.category)}"/>`);
|
|
5117
|
-
if (options.unique !== void 0) parts.push(options.unique ? "<w:docPartUnique/>" : "<w:docPartUnique w:val=\"0\"/>");
|
|
5118
|
-
return parts.length ? `<${name}>${parts.join("")}</${name}>` : `<${name}/>`;
|
|
5119
|
-
}
|
|
5120
|
-
function onOffAttr(name, val) {
|
|
5121
|
-
return val ? `<${name}/>` : `<${name} w:val="0"/>`;
|
|
5122
|
-
}
|
|
5123
|
-
const W14_NS = "xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"";
|
|
5124
|
-
/** Default symbol font for checkbox content controls (CT_SdtCheckboxSymbol). */
|
|
5125
|
-
const CHECKBOX_FONT = "MS Gothic";
|
|
5126
|
-
const DEFAULT_CHECKED = {
|
|
5127
|
-
val: "2612",
|
|
5128
|
-
font: CHECKBOX_FONT
|
|
5129
|
-
};
|
|
5130
|
-
const DEFAULT_UNCHECKED = {
|
|
5131
|
-
val: "2610",
|
|
5132
|
-
font: CHECKBOX_FONT
|
|
5133
|
-
};
|
|
5134
|
-
/**
|
|
5135
|
-
* Build a w14:checkbox element (Word 2010+ content control checkbox).
|
|
5136
|
-
*
|
|
5137
|
-
* Lives in the w14 extension namespace; emitted with an inline xmlns:w14 so it
|
|
5138
|
-
* is valid wherever w:sdtPr appears. validate.ts tolerates the w14 namespace.
|
|
5139
|
-
*/
|
|
5140
|
-
function sdtCheckboxXml(opts) {
|
|
5141
|
-
const checked = opts.checkedState ?? DEFAULT_CHECKED;
|
|
5142
|
-
const unchecked = opts.uncheckedState ?? DEFAULT_UNCHECKED;
|
|
5143
|
-
return `<w14:checkbox ${W14_NS}>${(opts.checked ? "<w14:checked/>" : "<w14:checked w14:val=\"0\"/>") + `<w14:checkedState w14:val="${escapeXml$1(checked.val)}" w14:font="${escapeXml$1(checked.font ?? CHECKBOX_FONT)}"/><w14:uncheckedState w14:val="${escapeXml$1(unchecked.val)}" w14:font="${escapeXml$1(unchecked.font ?? CHECKBOX_FONT)}"/>`}</w14:checkbox>`;
|
|
5144
|
-
}
|
|
5145
|
-
function stringifySdtPr(opts) {
|
|
5146
|
-
const parts = [];
|
|
5147
|
-
if (opts.alias !== void 0) parts.push(`<w:alias w:val="${escapeXml$1(opts.alias)}"/>`);
|
|
5148
|
-
if (opts.tag !== void 0) parts.push(`<w:tag w:val="${escapeXml$1(opts.tag)}"/>`);
|
|
5149
|
-
if (opts.id !== void 0) parts.push(`<w:id w:val="${opts.id}"/>`);
|
|
5150
|
-
if (opts.lock !== void 0) parts.push(`<w:lock w:val="${opts.lock}"/>`);
|
|
5151
|
-
if (opts.temporary !== void 0) parts.push(onOffAttr("w:temporary", opts.temporary));
|
|
5152
|
-
const effectiveShowingPlcHdr = opts.showingPlaceholder ?? false;
|
|
5153
|
-
if (opts.showingPlaceholder !== void 0 || effectiveShowingPlcHdr) parts.push(onOffAttr("w:showingPlcHdr", effectiveShowingPlcHdr));
|
|
5154
|
-
if (opts.dataBinding) parts.push(sdtDataBindingXml(opts.dataBinding));
|
|
5155
|
-
if (opts.label !== void 0) parts.push(`<w:label w:val="${opts.label}"/>`);
|
|
5156
|
-
if (opts.tabIndex !== void 0) parts.push(`<w:tabIndex w:val="${opts.tabIndex}"/>`);
|
|
5157
|
-
if (opts.equation) parts.push("<w:equation/>");
|
|
5158
|
-
else if (opts.comboBox) parts.push(sdtListTypeXml("w:comboBox", opts.comboBox));
|
|
5159
|
-
else if (opts.date) parts.push(sdtDateXml(opts.date));
|
|
5160
|
-
else if (opts.docPartObj) parts.push(sdtDocPartXml("w:docPartObj", opts.docPartObj));
|
|
5161
|
-
else if (opts.docPartList) parts.push(sdtDocPartXml("w:docPartList", opts.docPartList));
|
|
5162
|
-
else if (opts.dropDownList) parts.push(sdtListTypeXml("w:dropDownList", opts.dropDownList));
|
|
5163
|
-
else if (opts.picture) parts.push("<w:picture/>");
|
|
5164
|
-
else if (opts.richText) parts.push("<w:richText/>");
|
|
5165
|
-
else if (opts.text !== void 0) {
|
|
5166
|
-
const multiLine = opts.text.multiLine ?? false;
|
|
5167
|
-
parts.push(`<w:text w:multiLine="${multiLine}"/>`);
|
|
5168
|
-
} else if (opts.citation) parts.push("<w:citation/>");
|
|
5169
|
-
else if (opts.group) parts.push("<w:group/>");
|
|
5170
|
-
else if (opts.bibliography) parts.push("<w:bibliography/>");
|
|
5171
|
-
else if (opts.checkbox) parts.push(sdtCheckboxXml(opts.checkbox));
|
|
5172
|
-
return parts.length ? `<w:sdtPr>${parts.join("")}</w:sdtPr>` : "<w:sdtPr/>";
|
|
5173
|
-
}
|
|
5174
|
-
/** Parse w:sdtPr element into SdtPropertiesOptions. */
|
|
5175
|
-
function parseSdtPr(el) {
|
|
5176
|
-
const opts = {};
|
|
5177
|
-
const alias = findChild(el, "w:alias");
|
|
5178
|
-
if (alias) opts.alias = attr(alias, "w:val");
|
|
5179
|
-
const tag = findChild(el, "w:tag");
|
|
5180
|
-
if (tag) {
|
|
5181
|
-
const val = attr(tag, "w:val");
|
|
5182
|
-
if (val) opts.tag = val;
|
|
5183
|
-
}
|
|
5184
|
-
const id = findChild(el, "w:id");
|
|
5185
|
-
if (id) {
|
|
5186
|
-
const val = attrNum(id, "w:val");
|
|
5187
|
-
if (val !== void 0) opts.id = val;
|
|
5188
|
-
}
|
|
5189
|
-
const lock = findChild(el, "w:lock");
|
|
5190
|
-
if (lock) {
|
|
5191
|
-
const val = attr(lock, "w:val");
|
|
5192
|
-
if (val) opts.lock = val;
|
|
5193
|
-
}
|
|
5194
|
-
const temporary = findChild(el, "w:temporary");
|
|
5195
|
-
if (temporary) opts.temporary = attrBool(temporary, "w:val") ?? true;
|
|
5196
|
-
const showingPlcHdr = findChild(el, "w:showingPlcHdr");
|
|
5197
|
-
if (showingPlcHdr) opts.showingPlaceholder = attrBool(showingPlcHdr, "w:val") ?? true;
|
|
5198
|
-
const label = findChild(el, "w:label");
|
|
5199
|
-
if (label) {
|
|
5200
|
-
const val = attrNum(label, "w:val");
|
|
5201
|
-
if (val !== void 0) opts.label = val;
|
|
5202
|
-
}
|
|
5203
|
-
const tabIndex = findChild(el, "w:tabIndex");
|
|
5204
|
-
if (tabIndex) {
|
|
5205
|
-
const val = attrNum(tabIndex, "w:val");
|
|
5206
|
-
if (val !== void 0) opts.tabIndex = val;
|
|
5207
|
-
}
|
|
5208
|
-
const dataBinding = findChild(el, "w:dataBinding");
|
|
5209
|
-
if (dataBinding) opts.dataBinding = {
|
|
5210
|
-
xpath: attr(dataBinding, "w:xpath") ?? "",
|
|
5211
|
-
storeItemID: attr(dataBinding, "w:storeItemID") ?? "",
|
|
5212
|
-
prefixMappings: attr(dataBinding, "w:prefixMappings")
|
|
5213
|
-
};
|
|
5214
|
-
if (findChild(el, "w:equation")) opts.equation = true;
|
|
5215
|
-
else if (findChild(el, "w:comboBox")) {
|
|
5216
|
-
const comboBox = findChild(el, "w:comboBox");
|
|
5217
|
-
const items = [];
|
|
5218
|
-
for (const li of children(comboBox, "w:listItem")) items.push({
|
|
5219
|
-
displayText: attr(li, "w:displayText"),
|
|
5220
|
-
value: attr(li, "w:value")
|
|
5221
|
-
});
|
|
5222
|
-
opts.comboBox = {
|
|
5223
|
-
items: items.length > 0 ? items : void 0,
|
|
5224
|
-
lastValue: attr(comboBox, "w:lastValue")
|
|
5225
|
-
};
|
|
5226
|
-
} else if (findChild(el, "w:date")) {
|
|
5227
|
-
const date = findChild(el, "w:date");
|
|
5228
|
-
const dateOpts = {};
|
|
5229
|
-
const dateFormat = findChild(date, "w:dateFormat");
|
|
5230
|
-
if (dateFormat) dateOpts.dateFormat = textOf(dateFormat);
|
|
5231
|
-
const lid = findChild(date, "w:lid");
|
|
5232
|
-
if (lid) dateOpts.languageId = textOf(lid);
|
|
5233
|
-
const storeMapped = findChild(date, "w:storeMappedDataAs");
|
|
5234
|
-
if (storeMapped) dateOpts.storeMappedDataAs = attr(storeMapped, "w:val");
|
|
5235
|
-
const calendar = findChild(date, "w:calendar");
|
|
5236
|
-
if (calendar) dateOpts.calendar = attr(calendar, "w:val");
|
|
5237
|
-
const fullDate = attr(date, "w:fullDate");
|
|
5238
|
-
if (fullDate) dateOpts.fullDate = fullDate;
|
|
5239
|
-
opts.date = dateOpts;
|
|
5240
|
-
} else if (findChild(el, "w:docPartObj")) {
|
|
5241
|
-
const dp = findChild(el, "w:docPartObj");
|
|
5242
|
-
const dpObj = {};
|
|
5243
|
-
const gallery = findChild(dp, "w:docPartGallery");
|
|
5244
|
-
if (gallery) dpObj.gallery = attr(gallery, "w:val");
|
|
5245
|
-
const category = findChild(dp, "w:docPartCategory");
|
|
5246
|
-
if (category) dpObj.category = attr(category, "w:val");
|
|
5247
|
-
if (findChild(dp, "w:docPartUnique")) dpObj.unique = true;
|
|
5248
|
-
opts.docPartObj = dpObj;
|
|
5249
|
-
} else if (findChild(el, "w:docPartList")) {
|
|
5250
|
-
const dp = findChild(el, "w:docPartList");
|
|
5251
|
-
const dpObj = {};
|
|
5252
|
-
const gallery = findChild(dp, "w:docPartGallery");
|
|
5253
|
-
if (gallery) dpObj.gallery = attr(gallery, "w:val");
|
|
5254
|
-
const category = findChild(dp, "w:docPartCategory");
|
|
5255
|
-
if (category) dpObj.category = attr(category, "w:val");
|
|
5256
|
-
if (findChild(dp, "w:docPartUnique")) dpObj.unique = true;
|
|
5257
|
-
opts.docPartList = dpObj;
|
|
5258
|
-
} else if (findChild(el, "w:dropDownList")) {
|
|
5259
|
-
const ddl = findChild(el, "w:dropDownList");
|
|
5260
|
-
const items = [];
|
|
5261
|
-
for (const li of children(ddl, "w:listItem")) items.push({
|
|
5262
|
-
displayText: attr(li, "w:displayText"),
|
|
5263
|
-
value: attr(li, "w:value")
|
|
5264
|
-
});
|
|
5265
|
-
opts.dropDownList = {
|
|
5266
|
-
items: items.length > 0 ? items : void 0,
|
|
5267
|
-
lastValue: attr(ddl, "w:lastValue")
|
|
5268
|
-
};
|
|
5269
|
-
} else if (findChild(el, "w:picture")) opts.picture = true;
|
|
5270
|
-
else if (findChild(el, "w:richText")) opts.richText = true;
|
|
5271
|
-
else if (findChild(el, "w:text")) opts.text = { multiLine: attrBool(findChild(el, "w:text"), "w:multiLine") };
|
|
5272
|
-
else if (findChild(el, "w:citation")) opts.citation = true;
|
|
5273
|
-
else if (findChild(el, "w:group")) opts.group = true;
|
|
5274
|
-
else if (findChild(el, "w:bibliography")) opts.bibliography = true;
|
|
5275
|
-
else if (findChild(el, "w14:checkbox")) {
|
|
5276
|
-
const cb = findChild(el, "w14:checkbox");
|
|
5277
|
-
const cbObj = {};
|
|
5278
|
-
const checked = findChild(cb, "w14:checked");
|
|
5279
|
-
if (checked) cbObj.checked = attrBool(checked, "w14:val") ?? true;
|
|
5280
|
-
const checkedState = findChild(cb, "w14:checkedState");
|
|
5281
|
-
if (checkedState) cbObj.checkedState = {
|
|
5282
|
-
val: attr(checkedState, "w14:val") ?? "",
|
|
5283
|
-
font: attr(checkedState, "w14:font")
|
|
5284
|
-
};
|
|
5285
|
-
const uncheckedState = findChild(cb, "w14:uncheckedState");
|
|
5286
|
-
if (uncheckedState) cbObj.uncheckedState = {
|
|
5287
|
-
val: attr(uncheckedState, "w14:val") ?? "",
|
|
5288
|
-
font: attr(uncheckedState, "w14:font")
|
|
5289
|
-
};
|
|
5290
|
-
opts.checkbox = cbObj;
|
|
5291
|
-
}
|
|
5292
|
-
return opts;
|
|
5293
|
-
}
|
|
5294
|
-
/** Parse w:customXmlPr element into CustomXmlPrOptions. */
|
|
5295
|
-
function parseCustomXmlPr(el) {
|
|
5296
|
-
const opts = {};
|
|
5297
|
-
const placeholder = findChild(el, "w:placeholder");
|
|
5298
|
-
if (placeholder) {
|
|
5299
|
-
const val = attr(placeholder, "w:val");
|
|
5300
|
-
if (val) opts.placeholder = val;
|
|
5301
|
-
}
|
|
5302
|
-
const attributes = [];
|
|
5303
|
-
for (const child of el.elements ?? []) {
|
|
5304
|
-
if (child.name !== "w:attr") continue;
|
|
5305
|
-
const name = attr(child, "w:name");
|
|
5306
|
-
const val = attr(child, "w:val");
|
|
5307
|
-
if (name && val) {
|
|
5308
|
-
const attrOpts = {
|
|
5309
|
-
name,
|
|
5310
|
-
val
|
|
5311
|
-
};
|
|
5312
|
-
const uriVal = attr(child, "w:uri");
|
|
5313
|
-
if (uriVal) attrOpts.uri = uriVal;
|
|
5314
|
-
attributes.push(attrOpts);
|
|
5315
|
-
}
|
|
5316
|
-
}
|
|
5317
|
-
if (attributes.length > 0) opts.attributes = attributes;
|
|
5318
|
-
return opts;
|
|
5319
|
-
}
|
|
5320
|
-
/** Body child element parsing callback for SDT/customXml content. */
|
|
5321
|
-
let _parseBodyChild;
|
|
5322
|
-
/** Register the body child parser (called from parse/body.ts to break circular dependency). */
|
|
5323
|
-
function setBodyParseChild(parser) {
|
|
5324
|
-
_parseBodyChild = parser;
|
|
5325
|
-
}
|
|
5326
|
-
function parseBodyChildren(elements, ctx) {
|
|
5327
|
-
if (!_parseBodyChild) return [];
|
|
5328
|
-
const result = [];
|
|
5329
|
-
for (const el of elements) result.push(_parseBodyChild(el, ctx));
|
|
5330
|
-
return result;
|
|
5331
|
-
}
|
|
5332
|
-
const sdtBlockDesc = {
|
|
5333
|
-
kind: "custom",
|
|
5334
|
-
stringify(opts, ctx) {
|
|
5335
|
-
const parts = ["<w:sdt>"];
|
|
5336
|
-
parts.push(stringifySdtPr(opts.properties));
|
|
5337
|
-
const endPrInner = opts.endProperties ? stringifyRunPropertiesInner(opts.endProperties) : void 0;
|
|
5338
|
-
parts.push(endPrInner ? `<w:sdtEndPr>${endPrInner}</w:sdtEndPr>` : "<w:sdtEndPr/>");
|
|
5339
|
-
if (opts.properties.checkbox) {
|
|
5340
|
-
const cb = opts.properties.checkbox;
|
|
5341
|
-
const symbol = cb.checked ?? false ? cb.checkedState ?? DEFAULT_CHECKED : cb.uncheckedState ?? DEFAULT_UNCHECKED;
|
|
5342
|
-
const font = escapeXml$1(symbol.font ?? CHECKBOX_FONT);
|
|
5343
|
-
const char = escapeXml$1(String.fromCodePoint(parseInt(symbol.val, 16)));
|
|
5344
|
-
parts.push(`<w:sdtContent><w:p><w:r><w:rPr><w:rFonts w:ascii="${font}" w:hAnsi="${font}"/></w:rPr><w:t>${char}</w:t></w:r></w:p></w:sdtContent>`);
|
|
5345
|
-
} else if (opts.children && opts.children.length > 0) {
|
|
5346
|
-
const contentParts = [];
|
|
5347
|
-
for (const child of opts.children) contentParts.push(ctx.stringifyChild(child, ctx));
|
|
5348
|
-
const contentBody = contentParts.join("");
|
|
5349
|
-
parts.push(contentBody ? `<w:sdtContent>${contentBody}</w:sdtContent>` : "<w:sdtContent/>");
|
|
5350
|
-
}
|
|
5351
|
-
parts.push("</w:sdt>");
|
|
5352
|
-
return parts.join("");
|
|
5353
|
-
},
|
|
5354
|
-
parse(el, ctx) {
|
|
5355
|
-
const dctx = ctx;
|
|
5356
|
-
const sdtPr = findChild(el, "w:sdtPr");
|
|
5357
|
-
const properties = sdtPr ? parseSdtPr(sdtPr) : {};
|
|
5358
|
-
let endProperties;
|
|
5359
|
-
const sdtEndPr = findChild(el, "w:sdtEndPr");
|
|
5360
|
-
if (sdtEndPr) endProperties = parseRunProperties(sdtEndPr);
|
|
5361
|
-
const sdtContent = findChild(el, "w:sdtContent");
|
|
5362
|
-
let childList;
|
|
5363
|
-
if (sdtContent && sdtContent.elements?.length) {
|
|
5364
|
-
childList = parseBodyChildren(sdtContent.elements, dctx);
|
|
5365
|
-
if (childList.length === 0) childList = void 0;
|
|
5366
|
-
}
|
|
5367
|
-
return {
|
|
5368
|
-
properties,
|
|
5369
|
-
children: childList,
|
|
5370
|
-
endProperties
|
|
5371
|
-
};
|
|
5372
|
-
}
|
|
5373
|
-
};
|
|
5374
|
-
function buildCustomXmlPrXml(pr) {
|
|
5375
|
-
const parts = ["<w:customXmlPr>"];
|
|
5376
|
-
if (pr.placeholder !== void 0) parts.push(`<w:placeholder w:val="${escapeAttr(pr.placeholder)}"/>`);
|
|
5377
|
-
if (pr.attributes) for (const attr of pr.attributes) {
|
|
5378
|
-
const attrParts = [`w:name="${escapeAttr(attr.name)}"`, `w:val="${escapeAttr(attr.val)}"`];
|
|
5379
|
-
if (attr.uri !== void 0) attrParts.push(`w:uri="${escapeAttr(attr.uri)}"`);
|
|
5380
|
-
parts.push(`<w:attr ${attrParts.join(" ")}/>`);
|
|
5381
|
-
}
|
|
5382
|
-
parts.push("</w:customXmlPr>");
|
|
5383
|
-
return parts.join("");
|
|
5384
|
-
}
|
|
5385
|
-
const customXmlBlockDesc = {
|
|
5386
|
-
kind: "custom",
|
|
5387
|
-
stringify(opts, ctx) {
|
|
5388
|
-
const attrs = [`w:element="${escapeAttr(opts.element)}"`];
|
|
5389
|
-
if (opts.uri !== void 0) attrs.push(`w:uri="${escapeAttr(opts.uri)}"`);
|
|
5390
|
-
const parts = [`<w:customXml ${attrs.join(" ")}>`];
|
|
5391
|
-
if (opts.customXmlPr) parts.push(buildCustomXmlPrXml(opts.customXmlPr));
|
|
5392
|
-
if (opts.children) for (const child of opts.children) parts.push(ctx.stringifyChild(child, ctx));
|
|
5393
|
-
parts.push("</w:customXml>");
|
|
5394
|
-
return parts.join("");
|
|
5395
|
-
},
|
|
5396
|
-
parse(el, ctx) {
|
|
5397
|
-
const dctx = ctx;
|
|
5398
|
-
const opts = {};
|
|
5399
|
-
const element = attr(el, "w:element");
|
|
5400
|
-
if (element) opts.element = element;
|
|
5401
|
-
const uri = attr(el, "w:uri");
|
|
5402
|
-
if (uri) opts.uri = uri;
|
|
5403
|
-
const xmlPr = findChild(el, "w:customXmlPr");
|
|
5404
|
-
if (xmlPr) opts.customXmlPr = parseCustomXmlPr(xmlPr);
|
|
5405
|
-
const childList = [];
|
|
5406
|
-
for (const child of el.elements ?? []) {
|
|
5407
|
-
if (child.name === "w:customXmlPr") continue;
|
|
5408
|
-
if (_parseBodyChild) childList.push(_parseBodyChild(child, dctx));
|
|
5409
|
-
}
|
|
5410
|
-
if (childList.length > 0) opts.children = childList;
|
|
5411
|
-
return opts;
|
|
5412
|
-
}
|
|
5413
|
-
};
|
|
5414
|
-
//#endregion
|
|
5415
4382
|
//#region src/parts/core-properties.ts
|
|
5416
4383
|
const corePropertiesDesc = {
|
|
5417
4384
|
kind: "custom",
|
|
@@ -6144,6 +5111,6 @@ var DocxReadContext = class {
|
|
|
6144
5111
|
}
|
|
6145
5112
|
};
|
|
6146
5113
|
//#endregion
|
|
6147
|
-
export {
|
|
5114
|
+
export { PositionalTabLeader as $, stringifyTableOfContents as A, Numbering as B, EditGroupType as C, parseParagraphProperties as D, parseParagraph as E, settingsDesc as F, TableLayoutType as G, LevelFormat as H, Styles as I, RelativeVerticalPosition as J, OverlapType as K, buildNumberingCache as L, SdtDateMappingType as M, SdtLock as N, stringifyBodyChild as O, StyleLevel as P, PositionalTabAlignment as Q, buildStyleCache as R, AltChunkCollection as S, footnotesDesc as T, LevelSuffix as U, parseNumberingDefinitions as V, TABLE_BORDERS_NONE as W, ProofErrorType as X, TableAnchorType as Y, RubyAlign as Z, glossaryDesc as _, framesetXml as a, TextEffect as at, CharacterSet as b, customPropertiesDesc as c, TextboxTightWrapType as ct, buildContentTypes as d, AlignmentType as dt, PositionalTabRelativeTo as et, contentTypesDesc as f, DocPartType as g, DocPartGallery as h, frameXml as i, HighlightColor as it, parseToc as j, stringifyDocumentXml as k, corePropertiesDesc as l, HeadingLevel as lt, DocPartBehavior as m, DocxWriteContext as n, UnderlineType as nt, webSettingsDesc as o, PageNumber as ot, commentsDesc as p, RelativeHorizontalPosition as q, TargetScreenSize as r, createImageData as rt, appPropertiesDesc as s, TextAlignmentType as st, DocxReadContext as t, EmphasisMarkType as tt, relationshipsDesc as u, LineRuleType as ut, bibliographyDesc as v, endnotesDesc as w, SubDocCollection as x, fontTableDesc as y, parseStyleDefinitions as z };
|
|
6148
5115
|
|
|
6149
|
-
//# sourceMappingURL=context-
|
|
5116
|
+
//# sourceMappingURL=context-DfxK5XnG.mjs.map
|