ooxml.js 4.2.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.
Files changed (50) hide show
  1. package/README.md +6 -6
  2. package/dist/{codec-DNjHjEDm.d.cts → codec-CoqS3uGe.d.cts} +2 -2
  3. package/dist/{codec-BrTMlL0a.d.ts → codec-CzqiAWdz.d.ts} +4 -4
  4. package/dist/codec.d.cts +1 -1
  5. package/dist/codec.d.ts +1 -1
  6. package/dist/{content-UlQ-Nhgi.d.cts → content-C79O3esU.d.cts} +6 -1
  7. package/dist/{content-t6ZfmfQM.d.ts → content-MEmp_Rlx.d.ts} +6 -1
  8. package/dist/index.cjs +1 -1
  9. package/dist/index.d.cts +3 -3
  10. package/dist/index.d.ts +3 -3
  11. package/dist/index.js +1 -1
  12. package/dist/{read-C3AaxcT9.cjs → read-D-L3dItC.cjs} +318 -45
  13. package/dist/{read-CxMli3Om.d.ts → read-D30xHgEp.d.ts} +58 -1
  14. package/dist/{read-fuJpC4BH.js → read-DGknK1YY.js} +309 -48
  15. package/dist/{read-CDX1WbiF.d.cts → read-LTgVJIPU.d.cts} +58 -1
  16. package/dist/typed/document-package.cjs +8 -2
  17. package/dist/typed/document-package.js +8 -2
  18. package/dist/typed/docx/constructs.cjs +81 -0
  19. package/dist/typed/docx/constructs.d.cts +13 -2
  20. package/dist/typed/docx/constructs.d.ts +13 -2
  21. package/dist/typed/docx/constructs.js +80 -1
  22. package/dist/typed/docx/read.cjs +3 -1
  23. package/dist/typed/docx/read.d.cts +2 -2
  24. package/dist/typed/docx/read.d.ts +2 -2
  25. package/dist/typed/docx/read.js +2 -2
  26. package/dist/typed/docx/write.cjs +117 -10
  27. package/dist/typed/docx/write.js +118 -11
  28. package/dist/typed/embedded.cjs +1 -1
  29. package/dist/typed/embedded.js +1 -1
  30. package/dist/typed/pptx/read.cjs +1 -1
  31. package/dist/typed/pptx/read.js +1 -1
  32. package/dist/typed/xlsx/build.cjs +1 -1
  33. package/dist/typed/xlsx/build.js +1 -1
  34. package/dist/typed/xlsx/content.cjs +42 -1
  35. package/dist/typed/xlsx/content.d.cts +2 -2
  36. package/dist/typed/xlsx/content.d.ts +2 -2
  37. package/dist/typed/xlsx/content.js +42 -2
  38. package/dist/typed/xlsx/definitions.cjs +54 -0
  39. package/dist/typed/xlsx/definitions.d.cts +6 -0
  40. package/dist/typed/xlsx/definitions.d.ts +6 -0
  41. package/dist/typed/xlsx/definitions.js +53 -0
  42. package/dist/typed/xlsx/drawings.cjs +170 -0
  43. package/dist/typed/xlsx/drawings.d.cts +7 -0
  44. package/dist/typed/xlsx/drawings.d.ts +7 -0
  45. package/dist/typed/xlsx/drawings.js +169 -0
  46. package/dist/typed/xlsx/units.cjs +2 -0
  47. package/dist/typed/xlsx/units.d.cts +2 -1
  48. package/dist/typed/xlsx/units.d.ts +2 -1
  49. package/dist/typed/xlsx/units.js +2 -1
  50. 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") runs.push(readRun$1(child, paragraphDefaults, context, slideRels));
131
- else if (child.tag === "a:br") runs.push({ text: "\n" });
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,50 +729,179 @@ function readRun(run, paragraph, context) {
662
729
  color: props.color
663
730
  };
664
731
  }
665
- function readParagraphRuns(paragraph, ctx, carryDeletions) {
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") fieldState = "code";
675
- else if (type === "separate") fieldState = "result";
676
- else if (type === "end") fieldState = "none";
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
- } else if (node.tag === "w:fldSimple") walk(node.children, hyperlinkTarget);
686
- else if (node.tag === "w:hyperlink") {
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
- walk(node.children, target ?? hyperlinkTarget);
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
- }
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");
697
850
  }
698
851
  }
699
852
  walk(paragraph.children, void 0);
700
853
  return runs;
701
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
+ }
702
894
  function readParagraph(paragraph, ctx, carryDeletions) {
703
895
  const pPr = require_typed_util.childrenWithTag(paragraph, "w:pPr")[0];
704
896
  const pStyleEl = pPr === void 0 ? void 0 : require_typed_util.childrenWithTag(pPr, "w:pStyle")[0];
705
897
  const props = require_typed_docx_styles.resolveParagraphProperties(paragraph, ctx.styles);
898
+ const events = newParagraphRunEvents();
899
+ const runs = readParagraphRuns(paragraph, ctx, carryDeletions, events);
900
+ const constructs = assembleRunConstructs(events, require_typed_docx_constructs.indexParagraphContent(paragraph));
706
901
  return {
707
902
  kind: "paragraph",
708
- runs: readParagraphRuns(paragraph, ctx, carryDeletions),
903
+ runs,
904
+ ...constructs.length > 0 ? { constructs } : {},
709
905
  styleId: pStyleEl === void 0 ? void 0 : require_typed_util.attr(pStyleEl, "w:val"),
710
906
  headingLevel: props.outlineLvl === void 0 ? void 0 : (0, document_schema_js.clampHeadingLevel)(props.outlineLvl + 1),
711
907
  alignment: props.alignment,
@@ -831,16 +1027,17 @@ function newFlowState() {
831
1027
  blocks: [],
832
1028
  extents: [],
833
1029
  sectionBreaks: [],
834
- bookmarkEvents: [],
1030
+ rangeMarkerEvents: [],
835
1031
  openFields: [],
836
1032
  order: 0
837
1033
  };
838
1034
  }
839
- function resolveBookmarkExtents(events) {
1035
+ function resolveRangeMarkerExtents(events) {
840
1036
  const byId = /* @__PURE__ */ new Map();
841
1037
  for (const event of events) {
842
- const existing = byId.get(event.id);
843
- if (existing === void 0) byId.set(event.id, [event]);
1038
+ const key = `${event.family}:${event.id}`;
1039
+ const existing = byId.get(key);
1040
+ if (existing === void 0) byId.set(key, [event]);
844
1041
  else existing.push(event);
845
1042
  }
846
1043
  const extents = [];
@@ -850,12 +1047,17 @@ function resolveBookmarkExtents(events) {
850
1047
  const open = start[0];
851
1048
  const close = end[0];
852
1049
  if (start.length !== 1 || end.length !== 1 || open === void 0 || close === void 0) continue;
853
- if (open.name === void 0 || !open.qualified || !close.qualified || close.index < open.index) continue;
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;
854
1056
  extents.push({
855
1057
  startIndex: open.index,
856
1058
  endIndex: close.index,
857
1059
  order: open.order,
858
- descriptor: require_typed_docx_constructs.bookmarkAnchorDescriptor(open.name)
1060
+ descriptor
859
1061
  });
860
1062
  }
861
1063
  return extents;
@@ -871,18 +1073,21 @@ function wholeParagraphTrackedChange(index) {
871
1073
  change
872
1074
  };
873
1075
  }
874
- function recordParagraphBookmarks(index, paragraphIndex, endIndex, state) {
1076
+ function recordParagraphRangeMarkers(index, paragraphIndex, endIndex, state) {
875
1077
  index.elements.forEach((element, position) => {
876
- 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;
877
1079
  const id = require_typed_util.attr(element, "w:id");
878
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";
879
1083
  const leading = index.firstContentIndex === -1 || position < index.firstContentIndex;
880
1084
  const trailing = index.lastContentIndex === -1 || position > index.lastContentIndex;
881
- if (element.tag === "w:bookmarkStart") {
1085
+ if (start) {
882
1086
  const name = require_typed_util.attr(element, "w:name");
883
- state.bookmarkEvents.push({
1087
+ state.rangeMarkerEvents.push({
1088
+ family,
884
1089
  id,
885
- name: name === void 0 ? void 0 : require_typed_util.decodeEntities(name),
1090
+ name: family === "bookmark" && name !== void 0 ? require_typed_util.decodeEntities(name) : void 0,
886
1091
  kind: "start",
887
1092
  index: leading ? paragraphIndex : endIndex,
888
1093
  qualified: leading || trailing,
@@ -890,7 +1095,8 @@ function recordParagraphBookmarks(index, paragraphIndex, endIndex, state) {
890
1095
  });
891
1096
  return;
892
1097
  }
893
- state.bookmarkEvents.push({
1098
+ state.rangeMarkerEvents.push({
1099
+ family,
894
1100
  id,
895
1101
  name: void 0,
896
1102
  kind: "end",
@@ -923,7 +1129,8 @@ function scanParagraphFields(index, paragraphIndex, endIndex, state) {
923
1129
  inCode: true,
924
1130
  startIndex: paragraphIndex,
925
1131
  qualifiedStart: position === 0,
926
- order: state.order++
1132
+ order: state.order++,
1133
+ formControl: require_typed_docx_constructs.readFormControlDescriptor(child)
927
1134
  });
928
1135
  return;
929
1136
  }
@@ -938,7 +1145,7 @@ function scanParagraphFields(index, paragraphIndex, endIndex, state) {
938
1145
  startIndex: open.startIndex,
939
1146
  endIndex,
940
1147
  order: open.order,
941
- descriptor: {
1148
+ descriptor: open.formControl ?? {
942
1149
  kind: "field",
943
1150
  instruction: open.instruction
944
1151
  }
@@ -964,7 +1171,7 @@ function collectParagraph(paragraph, ctx, state, carryDeletions) {
964
1171
  order: state.order++,
965
1172
  descriptor: require_typed_docx_constructs.readProvenanceDescriptor(tracked.element, tracked.change)
966
1173
  });
967
- recordParagraphBookmarks(index, paragraphIndex, endIndex, state);
1174
+ recordParagraphRangeMarkers(index, paragraphIndex, endIndex, state);
968
1175
  scanParagraphFields(index, paragraphIndex, endIndex, state);
969
1176
  const pPr = require_typed_util.childrenWithTag(paragraph, "w:pPr")[0];
970
1177
  const sectPr = pPr === void 0 ? void 0 : require_typed_util.childrenWithTag(pPr, "w:sectPr")[0];
@@ -1015,12 +1222,13 @@ function collectFlowNodes(nodes, ctx, state, carryDeletions) {
1015
1222
  if (target !== void 0) collectFlowNodes(target.children, ctx, state, carryDeletions);
1016
1223
  continue;
1017
1224
  }
1018
- if (node.tag === "w:bookmarkStart") {
1225
+ if (node.tag === "w:bookmarkStart" || node.tag === "w:commentRangeStart") {
1019
1226
  const id = require_typed_util.attr(node, "w:id");
1020
1227
  const name = require_typed_util.attr(node, "w:name");
1021
- if (id !== void 0) state.bookmarkEvents.push({
1228
+ if (id !== void 0) state.rangeMarkerEvents.push({
1229
+ family: node.tag === "w:bookmarkStart" ? "bookmark" : "comment",
1022
1230
  id,
1023
- name: name === void 0 ? void 0 : require_typed_util.decodeEntities(name),
1231
+ name: node.tag === "w:bookmarkStart" && name !== void 0 ? require_typed_util.decodeEntities(name) : void 0,
1024
1232
  kind: "start",
1025
1233
  index: state.blocks.length,
1026
1234
  qualified: true,
@@ -1028,9 +1236,10 @@ function collectFlowNodes(nodes, ctx, state, carryDeletions) {
1028
1236
  });
1029
1237
  continue;
1030
1238
  }
1031
- if (node.tag === "w:bookmarkEnd") {
1239
+ if (node.tag === "w:bookmarkEnd" || node.tag === "w:commentRangeEnd") {
1032
1240
  const id = require_typed_util.attr(node, "w:id");
1033
- if (id !== void 0) state.bookmarkEvents.push({
1241
+ if (id !== void 0) state.rangeMarkerEvents.push({
1242
+ family: node.tag === "w:bookmarkEnd" ? "bookmark" : "comment",
1034
1243
  id,
1035
1244
  name: void 0,
1036
1245
  kind: "end",
@@ -1049,13 +1258,46 @@ function collectFlowNodes(nodes, ctx, state, carryDeletions) {
1049
1258
  function readBlockScope(nodes, ctx, carryDeletions) {
1050
1259
  const state = newFlowState();
1051
1260
  collectFlowNodes(nodes, ctx, state, carryDeletions);
1052
- return require_typed_docx_constructs.insertConstructMarkers(state.blocks, [...state.extents, ...resolveBookmarkExtents(state.bookmarkEvents)]);
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;
1053
1295
  }
1054
1296
  function readSections(body, ctx) {
1055
1297
  const state = newFlowState();
1056
1298
  collectFlowNodes(body.children, ctx, state, false);
1057
- const extents = [...state.extents, ...resolveBookmarkExtents(state.bookmarkEvents)];
1058
- function sliceSection(pageSize, margins, from, to) {
1299
+ const extents = [...state.extents, ...resolveRangeMarkerExtents(state.rangeMarkerEvents)];
1300
+ function sliceSection(pageSize, margins, breakType, from, to) {
1059
1301
  const contained = extents.filter((extent) => extent.startIndex >= from && extent.endIndex <= to).map((extent) => ({
1060
1302
  ...extent,
1061
1303
  startIndex: extent.startIndex - from,
@@ -1064,18 +1306,27 @@ function readSections(body, ctx) {
1064
1306
  return {
1065
1307
  pageSize,
1066
1308
  margins,
1309
+ ...breakType === void 0 ? {} : { breakType },
1067
1310
  blocks: require_typed_docx_constructs.insertConstructMarkers(state.blocks.slice(from, to), contained)
1068
1311
  };
1069
1312
  }
1070
1313
  const sections = [];
1314
+ const headerFooters = [];
1071
1315
  let from = 0;
1072
1316
  for (const sectionBreak of state.sectionBreaks) {
1073
- 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));
1074
1319
  from = sectionBreak.index;
1075
1320
  }
1076
- if (from < state.blocks.length || sections.length === 0) sections.push(sliceSection(document_schema_js.PAGE_SIZE_LETTER, DEFAULT_MARGINS, from, state.blocks.length));
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
+ }
1077
1325
  sections.forEach((section, sectionIndex) => require_typed_shared_source_path.assignSourcePaths(section.blocks, `sections[${sectionIndex}]`));
1078
- return sections;
1326
+ return {
1327
+ sections,
1328
+ headerFooters
1329
+ };
1079
1330
  }
1080
1331
  function readDocumentTheme(pkg, docRels) {
1081
1332
  for (const rel of docRels.values()) if (rel.type.endsWith(THEME_REL_SUFFIX)) {
@@ -1085,14 +1336,18 @@ function readDocumentTheme(pkg, docRels) {
1085
1336
  return require_typed_shared_drawingml.EMPTY_THEME;
1086
1337
  }
1087
1338
  function readComment(comment) {
1339
+ const id = require_typed_util.attr(comment, "w:id");
1088
1340
  const author = require_typed_util.attr(comment, "w:author");
1089
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;
1090
1343
  if (author !== void 0) result.author = author;
1091
1344
  return result;
1092
1345
  }
1093
1346
  function readFootnote(footnote) {
1347
+ const id = require_typed_util.attr(footnote, "w:id");
1094
1348
  const type = require_typed_util.attr(footnote, "w:type");
1095
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;
1096
1351
  if (type !== void 0) result.type = type;
1097
1352
  return result;
1098
1353
  }
@@ -1101,14 +1356,14 @@ function readComments(pkg) {
1101
1356
  if (root === void 0) return [];
1102
1357
  return require_typed_util.childrenWithTag(root, "w:comment").map(readComment);
1103
1358
  }
1104
- function readFootnotes(pkg) {
1105
- const root = require_typed_util.rootElement(pkg.parts["word/footnotes.xml"]);
1359
+ function readNotesPart(pkg, path, noteTag) {
1360
+ const root = require_typed_util.rootElement(pkg.parts[path]);
1106
1361
  if (root === void 0) return [];
1107
1362
  const out = [];
1108
- for (const fn of require_typed_util.childrenWithTag(root, "w:footnote")) {
1109
- const type = require_typed_util.attr(fn, "w:type");
1363
+ for (const note of require_typed_util.childrenWithTag(root, noteTag)) {
1364
+ const type = require_typed_util.attr(note, "w:type");
1110
1365
  if (type === "separator" || type === "continuationSeparator") continue;
1111
- out.push(readFootnote(fn));
1366
+ out.push(readFootnote(note));
1112
1367
  }
1113
1368
  return out;
1114
1369
  }
@@ -1136,13 +1391,19 @@ function readDocxContent(pkg) {
1136
1391
  rels: docRels,
1137
1392
  pkg
1138
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);
1139
1397
  return {
1140
1398
  metadata: require_typed_shared_metadata.readCoreProperties(pkg),
1141
- sections: readSections(body, ctx),
1399
+ sections,
1142
1400
  comments: readComments(pkg),
1143
- footnotes: readFootnotes(pkg),
1401
+ footnotes: readNotesPart(pkg, "word/footnotes.xml", "w:footnote"),
1402
+ endnotes: readNotesPart(pkg, "word/endnotes.xml", "w:endnote"),
1144
1403
  headers: readHeaderFooterText(pkg, "word/header"),
1145
1404
  footers: readHeaderFooterText(pkg, "word/footer"),
1405
+ headerFooterParts: readHeaderFooterParts(pkg, ctx, referencedPaths),
1406
+ sectionHeaderFooters: headerFooters,
1146
1407
  numbering: require_typed_docx_numbering.readNumberingDefinitions(pkg)
1147
1408
  };
1148
1409
  }
@@ -1165,12 +1426,24 @@ Object.defineProperty(exports, "FootnoteSchema", {
1165
1426
  return FootnoteSchema;
1166
1427
  }
1167
1428
  });
1429
+ Object.defineProperty(exports, "HeaderFooterPartSchema", {
1430
+ enumerable: true,
1431
+ get: function() {
1432
+ return HeaderFooterPartSchema;
1433
+ }
1434
+ });
1168
1435
  Object.defineProperty(exports, "PptxDocumentSchema", {
1169
1436
  enumerable: true,
1170
1437
  get: function() {
1171
1438
  return PptxDocumentSchema;
1172
1439
  }
1173
1440
  });
1441
+ Object.defineProperty(exports, "SectionHeaderFooterReferencesSchema", {
1442
+ enumerable: true,
1443
+ get: function() {
1444
+ return SectionHeaderFooterReferencesSchema;
1445
+ }
1446
+ });
1174
1447
  Object.defineProperty(exports, "readDocxContent", {
1175
1448
  enumerable: true,
1176
1449
  get: function() {