ooxml.js 4.3.0 → 4.4.0
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/README.md +6 -6
- package/dist/{codec-DNjHjEDm.d.cts → codec-CoqS3uGe.d.cts} +2 -2
- package/dist/{codec-BrTMlL0a.d.ts → codec-CzqiAWdz.d.ts} +4 -4
- package/dist/codec.d.cts +1 -1
- package/dist/codec.d.ts +1 -1
- package/dist/{content-UlQ-Nhgi.d.cts → content-C79O3esU.d.cts} +6 -1
- package/dist/{content-t6ZfmfQM.d.ts → content-MEmp_Rlx.d.ts} +6 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/{read-Di5UfiSh.cjs → read-D-L3dItC.cjs} +316 -59
- package/dist/{read-CxMli3Om.d.ts → read-D30xHgEp.d.ts} +58 -1
- package/dist/{read-BQoFiqsb.js → read-DGknK1YY.js} +307 -62
- package/dist/{read-CDX1WbiF.d.cts → read-LTgVJIPU.d.cts} +58 -1
- package/dist/typed/document-package.cjs +8 -2
- package/dist/typed/document-package.js +8 -2
- package/dist/typed/docx/constructs.cjs +55 -6
- package/dist/typed/docx/constructs.d.cts +6 -3
- package/dist/typed/docx/constructs.d.ts +6 -3
- package/dist/typed/docx/constructs.js +54 -6
- package/dist/typed/docx/read.cjs +3 -1
- package/dist/typed/docx/read.d.cts +2 -2
- package/dist/typed/docx/read.d.ts +2 -2
- package/dist/typed/docx/read.js +2 -2
- package/dist/typed/docx/write.cjs +78 -10
- package/dist/typed/docx/write.js +78 -10
- package/dist/typed/embedded.cjs +1 -1
- package/dist/typed/embedded.js +1 -1
- package/dist/typed/pptx/read.cjs +1 -1
- package/dist/typed/pptx/read.js +1 -1
- package/dist/typed/xlsx/build.cjs +1 -1
- package/dist/typed/xlsx/build.js +1 -1
- package/dist/typed/xlsx/content.cjs +42 -1
- package/dist/typed/xlsx/content.d.cts +2 -2
- package/dist/typed/xlsx/content.d.ts +2 -2
- package/dist/typed/xlsx/content.js +42 -2
- package/dist/typed/xlsx/definitions.cjs +54 -0
- package/dist/typed/xlsx/definitions.d.cts +6 -0
- package/dist/typed/xlsx/definitions.d.ts +6 -0
- package/dist/typed/xlsx/definitions.js +53 -0
- package/dist/typed/xlsx/drawings.cjs +170 -0
- package/dist/typed/xlsx/drawings.d.cts +7 -0
- package/dist/typed/xlsx/drawings.d.ts +7 -0
- package/dist/typed/xlsx/drawings.js +169 -0
- package/dist/typed/xlsx/units.cjs +2 -0
- package/dist/typed/xlsx/units.d.cts +2 -1
- package/dist/typed/xlsx/units.d.ts +2 -1
- package/dist/typed/xlsx/units.js +2 -1
- package/package.json +2 -2
|
@@ -22,6 +22,7 @@ const PptxDocumentSchema = zod.z.object({
|
|
|
22
22
|
slides: zod.z.array(document_schema_js.ContentSlideSchema)
|
|
23
23
|
});
|
|
24
24
|
const PRESENTATION_PATH = "ppt/presentation.xml";
|
|
25
|
+
const SLIDE_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide";
|
|
25
26
|
const TABLE_GRAPHIC_URI = "http://schemas.openxmlformats.org/drawingml/2006/table";
|
|
26
27
|
const CHART_GRAPHIC_URI = "http://schemas.openxmlformats.org/drawingml/2006/chart";
|
|
27
28
|
const DIAGRAM_GRAPHIC_URI = "http://schemas.openxmlformats.org/drawingml/2006/diagram";
|
|
@@ -78,6 +79,14 @@ function readHyperlink(rPr, slideRels) {
|
|
|
78
79
|
const rel = rId === void 0 ? void 0 : slideRels.get(rId);
|
|
79
80
|
return rel?.targetMode === "External" ? rel.target : void 0;
|
|
80
81
|
}
|
|
82
|
+
function readInternalSlideJump(runEl, slideRels) {
|
|
83
|
+
const rPr = require_typed_util.childrenWithTag(runEl, "a:rPr")[0];
|
|
84
|
+
if (rPr === void 0) return;
|
|
85
|
+
const hlink = require_typed_util.childrenWithTag(rPr, "a:hlinkClick")[0];
|
|
86
|
+
const rId = hlink === void 0 ? void 0 : require_typed_util.attr(hlink, "r:id");
|
|
87
|
+
const rel = rId === void 0 ? void 0 : slideRels.get(rId);
|
|
88
|
+
return rel !== void 0 && rel.targetMode !== "External" && rel.type === SLIDE_REL_TYPE ? rel.target : void 0;
|
|
89
|
+
}
|
|
81
90
|
function readRun$1(runEl, cascadeBase, context, slideRels) {
|
|
82
91
|
const rPr = require_typed_util.childrenWithTag(runEl, "a:rPr")[0];
|
|
83
92
|
const merged = mergeRunProperties(cascadeBase, rPr === void 0 ? {} : require_typed_pptx_inherit.readRunPropertiesFromElement(rPr, context));
|
|
@@ -125,16 +134,47 @@ function readParagraph$1(pEl, placeholderType, context, slideRels) {
|
|
|
125
134
|
const pPrDefRPr = pPr === void 0 ? void 0 : require_typed_util.childrenWithTag(pPr, "a:defRPr")[0];
|
|
126
135
|
const paragraphDefaults = pPrDefRPr === void 0 ? masterDefaults : mergeRunProperties(masterDefaults, require_typed_pptx_inherit.readRunPropertiesFromElement(pPrDefRPr, context));
|
|
127
136
|
const runs = [];
|
|
137
|
+
const fieldExtents = [];
|
|
138
|
+
const linkExtents = [];
|
|
128
139
|
for (const child of pEl.children) {
|
|
129
140
|
if (child.type !== "element") continue;
|
|
130
|
-
if (child.tag === "a:r" || child.tag === "a:fld")
|
|
131
|
-
|
|
141
|
+
if (child.tag === "a:r" || child.tag === "a:fld") {
|
|
142
|
+
runs.push(readRun$1(child, paragraphDefaults, context, slideRels));
|
|
143
|
+
if (child.tag === "a:fld") {
|
|
144
|
+
const type = require_typed_util.attr(child, "type");
|
|
145
|
+
if (type !== void 0) {
|
|
146
|
+
const cached = require_typed_util.childrenWithTag(child, "a:t")[0];
|
|
147
|
+
fieldExtents.push({
|
|
148
|
+
descriptor: {
|
|
149
|
+
kind: "field",
|
|
150
|
+
instruction: type,
|
|
151
|
+
cachedResult: cached === void 0 ? "" : require_typed_util.textContent(cached)
|
|
152
|
+
},
|
|
153
|
+
startRun: runs.length - 1,
|
|
154
|
+
endRun: runs.length
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const jumpTarget = readInternalSlideJump(child, slideRels);
|
|
159
|
+
if (jumpTarget !== void 0) linkExtents.push({
|
|
160
|
+
descriptor: {
|
|
161
|
+
kind: "link",
|
|
162
|
+
target: {
|
|
163
|
+
kind: "internal",
|
|
164
|
+
anchor: jumpTarget
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
startRun: runs.length - 1,
|
|
168
|
+
endRun: runs.length
|
|
169
|
+
});
|
|
170
|
+
} else if (child.tag === "a:br") runs.push({ text: "\n" });
|
|
132
171
|
}
|
|
133
172
|
const marL = pPr === void 0 ? void 0 : require_typed_util.attr(pPr, "marL");
|
|
134
173
|
const indent = pPr === void 0 ? void 0 : require_typed_util.attr(pPr, "indent");
|
|
135
174
|
return {
|
|
136
175
|
kind: "paragraph",
|
|
137
176
|
runs,
|
|
177
|
+
...fieldExtents.length + linkExtents.length > 0 ? { constructs: [...fieldExtents, ...linkExtents] } : {},
|
|
138
178
|
alignment: pPr === void 0 ? void 0 : readAlignment(require_typed_util.attr(pPr, "algn")),
|
|
139
179
|
list: outlineLevel === void 0 ? void 0 : { level: outlineLevel },
|
|
140
180
|
spacingBeforePt: readAbsoluteSpacingPt(pPr === void 0 ? void 0 : require_typed_util.childrenWithTag(pPr, "a:spcBef")[0]),
|
|
@@ -492,20 +532,42 @@ function readNestedDocument(objectKind, nested) {
|
|
|
492
532
|
//#endregion
|
|
493
533
|
//#region src/typed/docx/read.ts
|
|
494
534
|
const CommentSchema = zod.z.object({
|
|
535
|
+
id: zod.z.string().optional(),
|
|
495
536
|
author: zod.z.string().optional(),
|
|
496
537
|
text: zod.z.string()
|
|
497
538
|
});
|
|
498
539
|
const FootnoteSchema = zod.z.object({
|
|
540
|
+
id: zod.z.string().optional(),
|
|
499
541
|
type: zod.z.string().optional(),
|
|
500
542
|
text: zod.z.string()
|
|
501
543
|
});
|
|
544
|
+
const HeaderFooterPartSchema = zod.z.object({
|
|
545
|
+
path: zod.z.string(),
|
|
546
|
+
kind: zod.z.enum(["header", "footer"]),
|
|
547
|
+
blocks: zod.z.array(document_schema_js.ContentBlockSchema)
|
|
548
|
+
});
|
|
549
|
+
const SectionHeaderFooterReferencesSchema = zod.z.object({
|
|
550
|
+
header: zod.z.partialRecord(zod.z.enum([
|
|
551
|
+
"default",
|
|
552
|
+
"first",
|
|
553
|
+
"even"
|
|
554
|
+
]), zod.z.string()).optional(),
|
|
555
|
+
footer: zod.z.partialRecord(zod.z.enum([
|
|
556
|
+
"default",
|
|
557
|
+
"first",
|
|
558
|
+
"even"
|
|
559
|
+
]), zod.z.string()).optional()
|
|
560
|
+
});
|
|
502
561
|
const DocxDocumentSchema = zod.z.object({
|
|
503
562
|
metadata: require_typed_shared_metadata.DocumentMetadataSchema,
|
|
504
563
|
sections: zod.z.array(document_schema_js.ContentSectionSchema),
|
|
505
564
|
comments: zod.z.array(CommentSchema),
|
|
506
565
|
footnotes: zod.z.array(FootnoteSchema),
|
|
566
|
+
endnotes: zod.z.array(FootnoteSchema),
|
|
507
567
|
headers: zod.z.array(zod.z.string()),
|
|
508
568
|
footers: zod.z.array(zod.z.string()),
|
|
569
|
+
headerFooterParts: zod.z.array(HeaderFooterPartSchema),
|
|
570
|
+
sectionHeaderFooters: zod.z.array(SectionHeaderFooterReferencesSchema),
|
|
509
571
|
numbering: zod.z.record(zod.z.string(), require_typed_docx_numbering.NumberingDefinitionSchema)
|
|
510
572
|
});
|
|
511
573
|
const DOCUMENT_PART_PATH = "word/document.xml";
|
|
@@ -541,6 +603,11 @@ function readMargins(sectPr) {
|
|
|
541
603
|
leftPt: left === void 0 ? DEFAULT_MARGIN_PT : require_typed_shared_units.twipsToPt(Number(left))
|
|
542
604
|
};
|
|
543
605
|
}
|
|
606
|
+
function readSectionBreakType(sectPr) {
|
|
607
|
+
const type = require_typed_util.childrenWithTag(sectPr, "w:type")[0];
|
|
608
|
+
const val = type === void 0 ? void 0 : require_typed_util.attr(type, "w:val");
|
|
609
|
+
return val === "nextPage" || val === "continuous" || val === "evenPage" || val === "oddPage" ? val : void 0;
|
|
610
|
+
}
|
|
544
611
|
function readListMembership(pPr) {
|
|
545
612
|
const numPr = pPr === void 0 ? void 0 : require_typed_util.childrenWithTag(pPr, "w:numPr")[0];
|
|
546
613
|
if (numPr === void 0) return;
|
|
@@ -662,62 +729,175 @@ function readRun(run, paragraph, context) {
|
|
|
662
729
|
color: props.color
|
|
663
730
|
};
|
|
664
731
|
}
|
|
665
|
-
function
|
|
732
|
+
function newParagraphRunEvents() {
|
|
733
|
+
return {
|
|
734
|
+
halves: [],
|
|
735
|
+
fields: [],
|
|
736
|
+
simpleFields: [],
|
|
737
|
+
pointAnchors: [],
|
|
738
|
+
links: []
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
function readParagraphRuns(paragraph, ctx, carryDeletions, events) {
|
|
666
742
|
const runs = [];
|
|
667
743
|
let fieldState = "none";
|
|
744
|
+
const openFields = [];
|
|
745
|
+
const recordRangeMarkerHalf = (node, family, start) => {
|
|
746
|
+
const id = require_typed_util.attr(node, "w:id");
|
|
747
|
+
if (id === void 0) return;
|
|
748
|
+
const name = require_typed_util.attr(node, "w:name");
|
|
749
|
+
events.halves.push({
|
|
750
|
+
element: node,
|
|
751
|
+
family,
|
|
752
|
+
id,
|
|
753
|
+
name: start && family === "bookmark" && name !== void 0 ? require_typed_util.decodeEntities(name) : void 0,
|
|
754
|
+
kind: start ? "start" : "end",
|
|
755
|
+
runPosition: runs.length
|
|
756
|
+
});
|
|
757
|
+
};
|
|
758
|
+
const recordReferenceAnchor = (run) => {
|
|
759
|
+
for (const child of run.children) {
|
|
760
|
+
if (child.type !== "element") continue;
|
|
761
|
+
const anchorType = child.tag === "w:footnoteReference" ? "footnote" : child.tag === "w:endnoteReference" ? "endnote" : child.tag === "w:commentReference" ? "comment" : void 0;
|
|
762
|
+
const id = anchorType === void 0 ? void 0 : require_typed_util.attr(child, "w:id");
|
|
763
|
+
if (anchorType !== void 0 && id !== void 0) events.pointAnchors.push({
|
|
764
|
+
descriptor: {
|
|
765
|
+
kind: "anchor",
|
|
766
|
+
anchorType,
|
|
767
|
+
name: id
|
|
768
|
+
},
|
|
769
|
+
runPosition: runs.length - 1
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
};
|
|
668
773
|
function walk(nodes, hyperlinkTarget) {
|
|
669
774
|
for (const node of nodes) {
|
|
670
775
|
if (node.type !== "element") continue;
|
|
671
776
|
if (node.tag === "w:r") {
|
|
672
777
|
const type = require_typed_docx_constructs.fieldCharType(node);
|
|
673
778
|
if (type !== void 0) {
|
|
674
|
-
if (type === "begin")
|
|
675
|
-
|
|
676
|
-
|
|
779
|
+
if (type === "begin") {
|
|
780
|
+
fieldState = "code";
|
|
781
|
+
openFields.push({
|
|
782
|
+
startRun: runs.length,
|
|
783
|
+
instruction: "",
|
|
784
|
+
beginElement: node,
|
|
785
|
+
formControl: require_typed_docx_constructs.readFormControlDescriptor(node)
|
|
786
|
+
});
|
|
787
|
+
} else if (type === "separate") fieldState = "result";
|
|
788
|
+
else if (type === "end") {
|
|
789
|
+
fieldState = "none";
|
|
790
|
+
const open = openFields.pop();
|
|
791
|
+
if (open !== void 0) events.fields.push({
|
|
792
|
+
descriptor: open.formControl ?? {
|
|
793
|
+
kind: "field",
|
|
794
|
+
instruction: open.instruction
|
|
795
|
+
},
|
|
796
|
+
startRun: open.startRun,
|
|
797
|
+
endRun: runs.length,
|
|
798
|
+
beginElement: open.beginElement,
|
|
799
|
+
endElement: node
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
continue;
|
|
803
|
+
}
|
|
804
|
+
if (fieldState === "code") {
|
|
805
|
+
const open = openFields[openFields.length - 1];
|
|
806
|
+
if (open !== void 0) open.instruction += require_typed_docx_constructs.runInstructionText(node);
|
|
677
807
|
continue;
|
|
678
808
|
}
|
|
679
|
-
if (fieldState === "code") continue;
|
|
680
809
|
const run = readRun(node, paragraph, ctx.styles);
|
|
681
810
|
runs.push(hyperlinkTarget === void 0 ? run : {
|
|
682
811
|
...run,
|
|
683
812
|
hyperlink: hyperlinkTarget
|
|
684
813
|
});
|
|
685
|
-
|
|
686
|
-
else if (node.tag === "w:
|
|
814
|
+
recordReferenceAnchor(node);
|
|
815
|
+
} else if (node.tag === "w:fldSimple") {
|
|
816
|
+
const startRun = runs.length;
|
|
817
|
+
walk(node.children, hyperlinkTarget);
|
|
818
|
+
events.simpleFields.push({
|
|
819
|
+
descriptor: {
|
|
820
|
+
kind: "field",
|
|
821
|
+
instruction: require_typed_util.decodeEntities(require_typed_util.attr(node, "w:instr") ?? "")
|
|
822
|
+
},
|
|
823
|
+
startRun,
|
|
824
|
+
endRun: runs.length,
|
|
825
|
+
element: node
|
|
826
|
+
});
|
|
827
|
+
} else if (node.tag === "w:hyperlink") {
|
|
687
828
|
const rId = require_typed_util.attr(node, "r:id");
|
|
688
829
|
const target = rId === void 0 ? void 0 : ctx.rels.get(rId)?.target;
|
|
689
|
-
|
|
830
|
+
if (target === void 0) {
|
|
831
|
+
const anchor = require_typed_util.attr(node, "w:anchor");
|
|
832
|
+
const startRun = runs.length;
|
|
833
|
+
walk(node.children, hyperlinkTarget);
|
|
834
|
+
if (anchor !== void 0 && runs.length > startRun) events.links.push({
|
|
835
|
+
anchor: require_typed_util.decodeEntities(anchor),
|
|
836
|
+
startRun,
|
|
837
|
+
endRun: runs.length
|
|
838
|
+
});
|
|
839
|
+
continue;
|
|
840
|
+
}
|
|
841
|
+
walk(node.children, target);
|
|
690
842
|
} else if (node.tag === "w:ins" || node.tag === "w:moveTo") walk(node.children, hyperlinkTarget);
|
|
691
843
|
else if (node.tag === "w:del" || node.tag === "w:moveFrom") {
|
|
692
844
|
if (carryDeletions) walk(node.children, hyperlinkTarget);
|
|
693
845
|
} else if (node.tag === "w:sdt") {
|
|
694
846
|
const sdtContent = require_typed_util.childrenWithTag(node, "w:sdtContent")[0];
|
|
695
847
|
if (sdtContent !== void 0) walk(sdtContent.children, hyperlinkTarget);
|
|
696
|
-
} else if (node.tag === "w:bookmarkStart" || node.tag === "w:bookmarkEnd")
|
|
697
|
-
|
|
698
|
-
if (id !== void 0) {
|
|
699
|
-
const name = require_typed_util.attr(node, "w:name");
|
|
700
|
-
halves.push({
|
|
701
|
-
element: node,
|
|
702
|
-
id,
|
|
703
|
-
name: node.tag === "w:bookmarkStart" && name !== void 0 ? require_typed_util.decodeEntities(name) : void 0,
|
|
704
|
-
kind: node.tag === "w:bookmarkStart" ? "start" : "end",
|
|
705
|
-
runPosition: runs.length
|
|
706
|
-
});
|
|
707
|
-
}
|
|
708
|
-
}
|
|
848
|
+
} else if (node.tag === "w:bookmarkStart" || node.tag === "w:bookmarkEnd") recordRangeMarkerHalf(node, "bookmark", node.tag === "w:bookmarkStart");
|
|
849
|
+
else if (node.tag === "w:commentRangeStart" || node.tag === "w:commentRangeEnd") recordRangeMarkerHalf(node, "comment", node.tag === "w:commentRangeStart");
|
|
709
850
|
}
|
|
710
851
|
}
|
|
711
852
|
walk(paragraph.children, void 0);
|
|
712
853
|
return runs;
|
|
713
854
|
}
|
|
855
|
+
function isBlockScopedField(event, index) {
|
|
856
|
+
const begin = index.elements.indexOf(event.beginElement);
|
|
857
|
+
const end = index.elements.indexOf(event.endElement);
|
|
858
|
+
return begin !== -1 && end !== -1 && begin === index.firstContentIndex && end === index.lastContentIndex;
|
|
859
|
+
}
|
|
860
|
+
function isBlockScopedSimpleField(event, index) {
|
|
861
|
+
const position = index.elements.indexOf(event.element);
|
|
862
|
+
return position !== -1 && index.firstContentIndex === position && index.lastContentIndex === position;
|
|
863
|
+
}
|
|
864
|
+
function assembleRunConstructs(events, index) {
|
|
865
|
+
const extents = require_typed_docx_constructs.runRangeMarkerExtents(events.halves, index);
|
|
866
|
+
for (const field of events.fields) if (!isBlockScopedField(field, index)) extents.push({
|
|
867
|
+
descriptor: field.descriptor,
|
|
868
|
+
startRun: field.startRun,
|
|
869
|
+
endRun: field.endRun
|
|
870
|
+
});
|
|
871
|
+
for (const simple of events.simpleFields) if (!isBlockScopedSimpleField(simple, index)) extents.push({
|
|
872
|
+
descriptor: simple.descriptor,
|
|
873
|
+
startRun: simple.startRun,
|
|
874
|
+
endRun: simple.endRun
|
|
875
|
+
});
|
|
876
|
+
for (const link of events.links) extents.push({
|
|
877
|
+
descriptor: {
|
|
878
|
+
kind: "link",
|
|
879
|
+
target: {
|
|
880
|
+
kind: "internal",
|
|
881
|
+
anchor: link.anchor
|
|
882
|
+
}
|
|
883
|
+
},
|
|
884
|
+
startRun: link.startRun,
|
|
885
|
+
endRun: link.endRun
|
|
886
|
+
});
|
|
887
|
+
for (const anchor of events.pointAnchors) extents.push({
|
|
888
|
+
descriptor: anchor.descriptor,
|
|
889
|
+
startRun: anchor.runPosition,
|
|
890
|
+
endRun: anchor.runPosition
|
|
891
|
+
});
|
|
892
|
+
return extents;
|
|
893
|
+
}
|
|
714
894
|
function readParagraph(paragraph, ctx, carryDeletions) {
|
|
715
895
|
const pPr = require_typed_util.childrenWithTag(paragraph, "w:pPr")[0];
|
|
716
896
|
const pStyleEl = pPr === void 0 ? void 0 : require_typed_util.childrenWithTag(pPr, "w:pStyle")[0];
|
|
717
897
|
const props = require_typed_docx_styles.resolveParagraphProperties(paragraph, ctx.styles);
|
|
718
|
-
const
|
|
719
|
-
const runs = readParagraphRuns(paragraph, ctx, carryDeletions,
|
|
720
|
-
const constructs =
|
|
898
|
+
const events = newParagraphRunEvents();
|
|
899
|
+
const runs = readParagraphRuns(paragraph, ctx, carryDeletions, events);
|
|
900
|
+
const constructs = assembleRunConstructs(events, require_typed_docx_constructs.indexParagraphContent(paragraph));
|
|
721
901
|
return {
|
|
722
902
|
kind: "paragraph",
|
|
723
903
|
runs,
|
|
@@ -847,16 +1027,17 @@ function newFlowState() {
|
|
|
847
1027
|
blocks: [],
|
|
848
1028
|
extents: [],
|
|
849
1029
|
sectionBreaks: [],
|
|
850
|
-
|
|
1030
|
+
rangeMarkerEvents: [],
|
|
851
1031
|
openFields: [],
|
|
852
1032
|
order: 0
|
|
853
1033
|
};
|
|
854
1034
|
}
|
|
855
|
-
function
|
|
1035
|
+
function resolveRangeMarkerExtents(events) {
|
|
856
1036
|
const byId = /* @__PURE__ */ new Map();
|
|
857
1037
|
for (const event of events) {
|
|
858
|
-
const
|
|
859
|
-
|
|
1038
|
+
const key = `${event.family}:${event.id}`;
|
|
1039
|
+
const existing = byId.get(key);
|
|
1040
|
+
if (existing === void 0) byId.set(key, [event]);
|
|
860
1041
|
else existing.push(event);
|
|
861
1042
|
}
|
|
862
1043
|
const extents = [];
|
|
@@ -866,12 +1047,17 @@ function resolveBookmarkExtents(events) {
|
|
|
866
1047
|
const open = start[0];
|
|
867
1048
|
const close = end[0];
|
|
868
1049
|
if (start.length !== 1 || end.length !== 1 || open === void 0 || close === void 0) continue;
|
|
869
|
-
|
|
1050
|
+
const descriptor = open.family === "comment" ? {
|
|
1051
|
+
kind: "anchor",
|
|
1052
|
+
anchorType: "comment",
|
|
1053
|
+
name: open.id
|
|
1054
|
+
} : open.name === void 0 ? void 0 : require_typed_docx_constructs.bookmarkAnchorDescriptor(open.name);
|
|
1055
|
+
if (descriptor === void 0 || !open.qualified || !close.qualified || close.index < open.index) continue;
|
|
870
1056
|
extents.push({
|
|
871
1057
|
startIndex: open.index,
|
|
872
1058
|
endIndex: close.index,
|
|
873
1059
|
order: open.order,
|
|
874
|
-
descriptor
|
|
1060
|
+
descriptor
|
|
875
1061
|
});
|
|
876
1062
|
}
|
|
877
1063
|
return extents;
|
|
@@ -887,18 +1073,21 @@ function wholeParagraphTrackedChange(index) {
|
|
|
887
1073
|
change
|
|
888
1074
|
};
|
|
889
1075
|
}
|
|
890
|
-
function
|
|
1076
|
+
function recordParagraphRangeMarkers(index, paragraphIndex, endIndex, state) {
|
|
891
1077
|
index.elements.forEach((element, position) => {
|
|
892
|
-
if (element.tag !== "w:bookmarkStart" && element.tag !== "w:bookmarkEnd") return;
|
|
1078
|
+
if (element.tag !== "w:bookmarkStart" && element.tag !== "w:bookmarkEnd" && element.tag !== "w:commentRangeStart" && element.tag !== "w:commentRangeEnd") return;
|
|
893
1079
|
const id = require_typed_util.attr(element, "w:id");
|
|
894
1080
|
if (id === void 0) return;
|
|
1081
|
+
const family = element.tag === "w:bookmarkStart" || element.tag === "w:bookmarkEnd" ? "bookmark" : "comment";
|
|
1082
|
+
const start = element.tag === "w:bookmarkStart" || element.tag === "w:commentRangeStart";
|
|
895
1083
|
const leading = index.firstContentIndex === -1 || position < index.firstContentIndex;
|
|
896
1084
|
const trailing = index.lastContentIndex === -1 || position > index.lastContentIndex;
|
|
897
|
-
if (
|
|
1085
|
+
if (start) {
|
|
898
1086
|
const name = require_typed_util.attr(element, "w:name");
|
|
899
|
-
state.
|
|
1087
|
+
state.rangeMarkerEvents.push({
|
|
1088
|
+
family,
|
|
900
1089
|
id,
|
|
901
|
-
name:
|
|
1090
|
+
name: family === "bookmark" && name !== void 0 ? require_typed_util.decodeEntities(name) : void 0,
|
|
902
1091
|
kind: "start",
|
|
903
1092
|
index: leading ? paragraphIndex : endIndex,
|
|
904
1093
|
qualified: leading || trailing,
|
|
@@ -906,7 +1095,8 @@ function recordParagraphBookmarks(index, paragraphIndex, endIndex, state) {
|
|
|
906
1095
|
});
|
|
907
1096
|
return;
|
|
908
1097
|
}
|
|
909
|
-
state.
|
|
1098
|
+
state.rangeMarkerEvents.push({
|
|
1099
|
+
family,
|
|
910
1100
|
id,
|
|
911
1101
|
name: void 0,
|
|
912
1102
|
kind: "end",
|
|
@@ -939,7 +1129,8 @@ function scanParagraphFields(index, paragraphIndex, endIndex, state) {
|
|
|
939
1129
|
inCode: true,
|
|
940
1130
|
startIndex: paragraphIndex,
|
|
941
1131
|
qualifiedStart: position === 0,
|
|
942
|
-
order: state.order
|
|
1132
|
+
order: state.order++,
|
|
1133
|
+
formControl: require_typed_docx_constructs.readFormControlDescriptor(child)
|
|
943
1134
|
});
|
|
944
1135
|
return;
|
|
945
1136
|
}
|
|
@@ -954,7 +1145,7 @@ function scanParagraphFields(index, paragraphIndex, endIndex, state) {
|
|
|
954
1145
|
startIndex: open.startIndex,
|
|
955
1146
|
endIndex,
|
|
956
1147
|
order: open.order,
|
|
957
|
-
descriptor: {
|
|
1148
|
+
descriptor: open.formControl ?? {
|
|
958
1149
|
kind: "field",
|
|
959
1150
|
instruction: open.instruction
|
|
960
1151
|
}
|
|
@@ -980,7 +1171,7 @@ function collectParagraph(paragraph, ctx, state, carryDeletions) {
|
|
|
980
1171
|
order: state.order++,
|
|
981
1172
|
descriptor: require_typed_docx_constructs.readProvenanceDescriptor(tracked.element, tracked.change)
|
|
982
1173
|
});
|
|
983
|
-
|
|
1174
|
+
recordParagraphRangeMarkers(index, paragraphIndex, endIndex, state);
|
|
984
1175
|
scanParagraphFields(index, paragraphIndex, endIndex, state);
|
|
985
1176
|
const pPr = require_typed_util.childrenWithTag(paragraph, "w:pPr")[0];
|
|
986
1177
|
const sectPr = pPr === void 0 ? void 0 : require_typed_util.childrenWithTag(pPr, "w:sectPr")[0];
|
|
@@ -1031,12 +1222,13 @@ function collectFlowNodes(nodes, ctx, state, carryDeletions) {
|
|
|
1031
1222
|
if (target !== void 0) collectFlowNodes(target.children, ctx, state, carryDeletions);
|
|
1032
1223
|
continue;
|
|
1033
1224
|
}
|
|
1034
|
-
if (node.tag === "w:bookmarkStart") {
|
|
1225
|
+
if (node.tag === "w:bookmarkStart" || node.tag === "w:commentRangeStart") {
|
|
1035
1226
|
const id = require_typed_util.attr(node, "w:id");
|
|
1036
1227
|
const name = require_typed_util.attr(node, "w:name");
|
|
1037
|
-
if (id !== void 0) state.
|
|
1228
|
+
if (id !== void 0) state.rangeMarkerEvents.push({
|
|
1229
|
+
family: node.tag === "w:bookmarkStart" ? "bookmark" : "comment",
|
|
1038
1230
|
id,
|
|
1039
|
-
name:
|
|
1231
|
+
name: node.tag === "w:bookmarkStart" && name !== void 0 ? require_typed_util.decodeEntities(name) : void 0,
|
|
1040
1232
|
kind: "start",
|
|
1041
1233
|
index: state.blocks.length,
|
|
1042
1234
|
qualified: true,
|
|
@@ -1044,9 +1236,10 @@ function collectFlowNodes(nodes, ctx, state, carryDeletions) {
|
|
|
1044
1236
|
});
|
|
1045
1237
|
continue;
|
|
1046
1238
|
}
|
|
1047
|
-
if (node.tag === "w:bookmarkEnd") {
|
|
1239
|
+
if (node.tag === "w:bookmarkEnd" || node.tag === "w:commentRangeEnd") {
|
|
1048
1240
|
const id = require_typed_util.attr(node, "w:id");
|
|
1049
|
-
if (id !== void 0) state.
|
|
1241
|
+
if (id !== void 0) state.rangeMarkerEvents.push({
|
|
1242
|
+
family: node.tag === "w:bookmarkEnd" ? "bookmark" : "comment",
|
|
1050
1243
|
id,
|
|
1051
1244
|
name: void 0,
|
|
1052
1245
|
kind: "end",
|
|
@@ -1065,13 +1258,46 @@ function collectFlowNodes(nodes, ctx, state, carryDeletions) {
|
|
|
1065
1258
|
function readBlockScope(nodes, ctx, carryDeletions) {
|
|
1066
1259
|
const state = newFlowState();
|
|
1067
1260
|
collectFlowNodes(nodes, ctx, state, carryDeletions);
|
|
1068
|
-
return require_typed_docx_constructs.insertConstructMarkers(state.blocks, [...state.extents, ...
|
|
1261
|
+
return require_typed_docx_constructs.insertConstructMarkers(state.blocks, [...state.extents, ...resolveRangeMarkerExtents(state.rangeMarkerEvents)]);
|
|
1262
|
+
}
|
|
1263
|
+
function readSectionHeaderFooters(sectPr, ctx) {
|
|
1264
|
+
const references = {};
|
|
1265
|
+
for (const tag of ["w:headerReference", "w:footerReference"]) {
|
|
1266
|
+
const slot = {};
|
|
1267
|
+
for (const reference of require_typed_util.childrenWithTag(sectPr, tag)) {
|
|
1268
|
+
const type = require_typed_util.attr(reference, "w:type");
|
|
1269
|
+
const rId = require_typed_util.attr(reference, "r:id");
|
|
1270
|
+
const target = rId === void 0 ? void 0 : ctx.rels.get(rId)?.target;
|
|
1271
|
+
if ((type === "default" || type === "first" || type === "even") && target !== void 0) slot[type] = target;
|
|
1272
|
+
}
|
|
1273
|
+
if (Object.keys(slot).length > 0) references[tag === "w:headerReference" ? "header" : "footer"] = slot;
|
|
1274
|
+
}
|
|
1275
|
+
return references;
|
|
1276
|
+
}
|
|
1277
|
+
function readHeaderFooterParts(pkg, ctx, referencedPaths) {
|
|
1278
|
+
const parts = [];
|
|
1279
|
+
for (const path of [...referencedPaths].sort()) {
|
|
1280
|
+
const root = require_typed_util.rootElement(pkg.parts[path]);
|
|
1281
|
+
if (root === void 0) continue;
|
|
1282
|
+
const kind = root.tag === "w:ftr" ? "footer" : "header";
|
|
1283
|
+
const partCtx = {
|
|
1284
|
+
styles: ctx.styles,
|
|
1285
|
+
rels: require_typed_util.resolveRelationships(pkg, path),
|
|
1286
|
+
pkg
|
|
1287
|
+
};
|
|
1288
|
+
parts.push({
|
|
1289
|
+
path,
|
|
1290
|
+
kind,
|
|
1291
|
+
blocks: readBlockScope(root.children, partCtx, false)
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
return parts;
|
|
1069
1295
|
}
|
|
1070
1296
|
function readSections(body, ctx) {
|
|
1071
1297
|
const state = newFlowState();
|
|
1072
1298
|
collectFlowNodes(body.children, ctx, state, false);
|
|
1073
|
-
const extents = [...state.extents, ...
|
|
1074
|
-
function sliceSection(pageSize, margins, from, to) {
|
|
1299
|
+
const extents = [...state.extents, ...resolveRangeMarkerExtents(state.rangeMarkerEvents)];
|
|
1300
|
+
function sliceSection(pageSize, margins, breakType, from, to) {
|
|
1075
1301
|
const contained = extents.filter((extent) => extent.startIndex >= from && extent.endIndex <= to).map((extent) => ({
|
|
1076
1302
|
...extent,
|
|
1077
1303
|
startIndex: extent.startIndex - from,
|
|
@@ -1080,18 +1306,27 @@ function readSections(body, ctx) {
|
|
|
1080
1306
|
return {
|
|
1081
1307
|
pageSize,
|
|
1082
1308
|
margins,
|
|
1309
|
+
...breakType === void 0 ? {} : { breakType },
|
|
1083
1310
|
blocks: require_typed_docx_constructs.insertConstructMarkers(state.blocks.slice(from, to), contained)
|
|
1084
1311
|
};
|
|
1085
1312
|
}
|
|
1086
1313
|
const sections = [];
|
|
1314
|
+
const headerFooters = [];
|
|
1087
1315
|
let from = 0;
|
|
1088
1316
|
for (const sectionBreak of state.sectionBreaks) {
|
|
1089
|
-
sections.push(sliceSection(readPageSize(sectionBreak.sectPr), readMargins(sectionBreak.sectPr), from, sectionBreak.index));
|
|
1317
|
+
sections.push(sliceSection(readPageSize(sectionBreak.sectPr), readMargins(sectionBreak.sectPr), readSectionBreakType(sectionBreak.sectPr), from, sectionBreak.index));
|
|
1318
|
+
headerFooters.push(readSectionHeaderFooters(sectionBreak.sectPr, ctx));
|
|
1090
1319
|
from = sectionBreak.index;
|
|
1091
1320
|
}
|
|
1092
|
-
if (from < state.blocks.length || sections.length === 0)
|
|
1321
|
+
if (from < state.blocks.length || sections.length === 0) {
|
|
1322
|
+
sections.push(sliceSection(document_schema_js.PAGE_SIZE_LETTER, DEFAULT_MARGINS, void 0, from, state.blocks.length));
|
|
1323
|
+
headerFooters.push({});
|
|
1324
|
+
}
|
|
1093
1325
|
sections.forEach((section, sectionIndex) => require_typed_shared_source_path.assignSourcePaths(section.blocks, `sections[${sectionIndex}]`));
|
|
1094
|
-
return
|
|
1326
|
+
return {
|
|
1327
|
+
sections,
|
|
1328
|
+
headerFooters
|
|
1329
|
+
};
|
|
1095
1330
|
}
|
|
1096
1331
|
function readDocumentTheme(pkg, docRels) {
|
|
1097
1332
|
for (const rel of docRels.values()) if (rel.type.endsWith(THEME_REL_SUFFIX)) {
|
|
@@ -1101,14 +1336,18 @@ function readDocumentTheme(pkg, docRels) {
|
|
|
1101
1336
|
return require_typed_shared_drawingml.EMPTY_THEME;
|
|
1102
1337
|
}
|
|
1103
1338
|
function readComment(comment) {
|
|
1339
|
+
const id = require_typed_util.attr(comment, "w:id");
|
|
1104
1340
|
const author = require_typed_util.attr(comment, "w:author");
|
|
1105
1341
|
const result = { text: require_typed_util.elementsWithTag(comment.children, "w:t").map(require_typed_util.textContent).join("") };
|
|
1342
|
+
if (id !== void 0) result.id = id;
|
|
1106
1343
|
if (author !== void 0) result.author = author;
|
|
1107
1344
|
return result;
|
|
1108
1345
|
}
|
|
1109
1346
|
function readFootnote(footnote) {
|
|
1347
|
+
const id = require_typed_util.attr(footnote, "w:id");
|
|
1110
1348
|
const type = require_typed_util.attr(footnote, "w:type");
|
|
1111
1349
|
const result = { text: require_typed_util.elementsWithTag(footnote.children, "w:t").map(require_typed_util.textContent).join("") };
|
|
1350
|
+
if (id !== void 0) result.id = id;
|
|
1112
1351
|
if (type !== void 0) result.type = type;
|
|
1113
1352
|
return result;
|
|
1114
1353
|
}
|
|
@@ -1117,14 +1356,14 @@ function readComments(pkg) {
|
|
|
1117
1356
|
if (root === void 0) return [];
|
|
1118
1357
|
return require_typed_util.childrenWithTag(root, "w:comment").map(readComment);
|
|
1119
1358
|
}
|
|
1120
|
-
function
|
|
1121
|
-
const root = require_typed_util.rootElement(pkg.parts[
|
|
1359
|
+
function readNotesPart(pkg, path, noteTag) {
|
|
1360
|
+
const root = require_typed_util.rootElement(pkg.parts[path]);
|
|
1122
1361
|
if (root === void 0) return [];
|
|
1123
1362
|
const out = [];
|
|
1124
|
-
for (const
|
|
1125
|
-
const type = require_typed_util.attr(
|
|
1363
|
+
for (const note of require_typed_util.childrenWithTag(root, noteTag)) {
|
|
1364
|
+
const type = require_typed_util.attr(note, "w:type");
|
|
1126
1365
|
if (type === "separator" || type === "continuationSeparator") continue;
|
|
1127
|
-
out.push(readFootnote(
|
|
1366
|
+
out.push(readFootnote(note));
|
|
1128
1367
|
}
|
|
1129
1368
|
return out;
|
|
1130
1369
|
}
|
|
@@ -1152,13 +1391,19 @@ function readDocxContent(pkg) {
|
|
|
1152
1391
|
rels: docRels,
|
|
1153
1392
|
pkg
|
|
1154
1393
|
};
|
|
1394
|
+
const { sections, headerFooters } = readSections(body, ctx);
|
|
1395
|
+
const referencedPaths = /* @__PURE__ */ new Set();
|
|
1396
|
+
for (const references of headerFooters) for (const slot of [references.header, references.footer]) for (const path of Object.values(slot ?? {})) referencedPaths.add(path);
|
|
1155
1397
|
return {
|
|
1156
1398
|
metadata: require_typed_shared_metadata.readCoreProperties(pkg),
|
|
1157
|
-
sections
|
|
1399
|
+
sections,
|
|
1158
1400
|
comments: readComments(pkg),
|
|
1159
|
-
footnotes:
|
|
1401
|
+
footnotes: readNotesPart(pkg, "word/footnotes.xml", "w:footnote"),
|
|
1402
|
+
endnotes: readNotesPart(pkg, "word/endnotes.xml", "w:endnote"),
|
|
1160
1403
|
headers: readHeaderFooterText(pkg, "word/header"),
|
|
1161
1404
|
footers: readHeaderFooterText(pkg, "word/footer"),
|
|
1405
|
+
headerFooterParts: readHeaderFooterParts(pkg, ctx, referencedPaths),
|
|
1406
|
+
sectionHeaderFooters: headerFooters,
|
|
1162
1407
|
numbering: require_typed_docx_numbering.readNumberingDefinitions(pkg)
|
|
1163
1408
|
};
|
|
1164
1409
|
}
|
|
@@ -1181,12 +1426,24 @@ Object.defineProperty(exports, "FootnoteSchema", {
|
|
|
1181
1426
|
return FootnoteSchema;
|
|
1182
1427
|
}
|
|
1183
1428
|
});
|
|
1429
|
+
Object.defineProperty(exports, "HeaderFooterPartSchema", {
|
|
1430
|
+
enumerable: true,
|
|
1431
|
+
get: function() {
|
|
1432
|
+
return HeaderFooterPartSchema;
|
|
1433
|
+
}
|
|
1434
|
+
});
|
|
1184
1435
|
Object.defineProperty(exports, "PptxDocumentSchema", {
|
|
1185
1436
|
enumerable: true,
|
|
1186
1437
|
get: function() {
|
|
1187
1438
|
return PptxDocumentSchema;
|
|
1188
1439
|
}
|
|
1189
1440
|
});
|
|
1441
|
+
Object.defineProperty(exports, "SectionHeaderFooterReferencesSchema", {
|
|
1442
|
+
enumerable: true,
|
|
1443
|
+
get: function() {
|
|
1444
|
+
return SectionHeaderFooterReferencesSchema;
|
|
1445
|
+
}
|
|
1446
|
+
});
|
|
1190
1447
|
Object.defineProperty(exports, "readDocxContent", {
|
|
1191
1448
|
enumerable: true,
|
|
1192
1449
|
get: function() {
|