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
@@ -3,15 +3,39 @@ import { z } from "zod";
3
3
  import { ContentBlock } from "document-schema.js";
4
4
  //#region src/typed/docx/read.d.ts
5
5
  declare const CommentSchema: z.ZodObject<{
6
+ id: z.ZodOptional<z.ZodString>;
6
7
  author: z.ZodOptional<z.ZodString>;
7
8
  text: z.ZodString;
8
9
  }, z.core.$strip>;
9
10
  type Comment = z.infer<typeof CommentSchema>;
10
11
  declare const FootnoteSchema: z.ZodObject<{
12
+ id: z.ZodOptional<z.ZodString>;
11
13
  type: z.ZodOptional<z.ZodString>;
12
14
  text: z.ZodString;
13
15
  }, z.core.$strip>;
14
16
  type Footnote = z.infer<typeof FootnoteSchema>;
17
+ declare const HeaderFooterPartSchema: z.ZodObject<{
18
+ path: z.ZodString;
19
+ kind: z.ZodEnum<{
20
+ header: "header";
21
+ footer: "footer";
22
+ }>;
23
+ blocks: z.ZodArray<z.ZodCustom<ContentBlock, ContentBlock>>;
24
+ }, z.core.$strip>;
25
+ type HeaderFooterPart = z.infer<typeof HeaderFooterPartSchema>;
26
+ declare const SectionHeaderFooterReferencesSchema: z.ZodObject<{
27
+ header: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
28
+ default: "default";
29
+ first: "first";
30
+ even: "even";
31
+ }> & z.core.$partial, z.ZodString>>;
32
+ footer: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
33
+ default: "default";
34
+ first: "first";
35
+ even: "even";
36
+ }> & z.core.$partial, z.ZodString>>;
37
+ }, z.core.$strip>;
38
+ type SectionHeaderFooterReferences = z.infer<typeof SectionHeaderFooterReferencesSchema>;
15
39
  declare const DocxDocumentSchema: z.ZodObject<{
16
40
  metadata: z.ZodObject<{
17
41
  title: z.ZodOptional<z.ZodString>;
@@ -34,6 +58,12 @@ declare const DocxDocumentSchema: z.ZodObject<{
34
58
  leftPt: z.ZodNumber;
35
59
  }, z.core.$strip>;
36
60
  blocks: z.ZodArray<z.ZodCustom<ContentBlock, ContentBlock>>;
61
+ breakType: z.ZodOptional<z.ZodEnum<{
62
+ nextPage: "nextPage";
63
+ continuous: "continuous";
64
+ evenPage: "evenPage";
65
+ oddPage: "oddPage";
66
+ }>>;
37
67
  source: z.ZodOptional<z.ZodObject<{
38
68
  format: z.ZodEnum<{
39
69
  docx: "docx";
@@ -53,15 +83,42 @@ declare const DocxDocumentSchema: z.ZodObject<{
53
83
  }, z.core.$strict>>;
54
84
  }, z.core.$strip>>;
55
85
  comments: z.ZodArray<z.ZodObject<{
86
+ id: z.ZodOptional<z.ZodString>;
56
87
  author: z.ZodOptional<z.ZodString>;
57
88
  text: z.ZodString;
58
89
  }, z.core.$strip>>;
59
90
  footnotes: z.ZodArray<z.ZodObject<{
91
+ id: z.ZodOptional<z.ZodString>;
92
+ type: z.ZodOptional<z.ZodString>;
93
+ text: z.ZodString;
94
+ }, z.core.$strip>>;
95
+ endnotes: z.ZodArray<z.ZodObject<{
96
+ id: z.ZodOptional<z.ZodString>;
60
97
  type: z.ZodOptional<z.ZodString>;
61
98
  text: z.ZodString;
62
99
  }, z.core.$strip>>;
63
100
  headers: z.ZodArray<z.ZodString>;
64
101
  footers: z.ZodArray<z.ZodString>;
102
+ headerFooterParts: z.ZodArray<z.ZodObject<{
103
+ path: z.ZodString;
104
+ kind: z.ZodEnum<{
105
+ header: "header";
106
+ footer: "footer";
107
+ }>;
108
+ blocks: z.ZodArray<z.ZodCustom<ContentBlock, ContentBlock>>;
109
+ }, z.core.$strip>>;
110
+ sectionHeaderFooters: z.ZodArray<z.ZodObject<{
111
+ header: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
112
+ default: "default";
113
+ first: "first";
114
+ even: "even";
115
+ }> & z.core.$partial, z.ZodString>>;
116
+ footer: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
117
+ default: "default";
118
+ first: "first";
119
+ even: "even";
120
+ }> & z.core.$partial, z.ZodString>>;
121
+ }, z.core.$strip>>;
65
122
  numbering: z.ZodRecord<z.ZodString, z.ZodObject<{
66
123
  levels: z.ZodRecord<z.ZodString, z.ZodObject<{
67
124
  format: z.ZodString;
@@ -74,4 +131,4 @@ declare const DocxDocumentSchema: z.ZodObject<{
74
131
  type DocxDocument = z.infer<typeof DocxDocumentSchema>;
75
132
  declare function readDocxContent(pkg: Package): DocxDocument;
76
133
  //#endregion
77
- export { Footnote as a, DocxDocumentSchema as i, CommentSchema as n, FootnoteSchema as o, DocxDocument as r, readDocxContent as s, Comment as t };
134
+ export { Footnote as a, HeaderFooterPartSchema as c, readDocxContent as d, DocxDocumentSchema as i, SectionHeaderFooterReferences as l, CommentSchema as n, FootnoteSchema as o, DocxDocument as r, HeaderFooterPart as s, Comment as t, SectionHeaderFooterReferencesSchema as u };
@@ -1,8 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_read = require("../read-C3AaxcT9.cjs");
2
+ const require_read = require("../read-D-L3dItC.cjs");
3
3
  const require_typed_xlsx_content = require("./xlsx/content.cjs");
4
4
  const require_typed_xlsx_build = require("./xlsx/build.cjs");
5
5
  const require_typed_docx_write = require("./docx/write.cjs");
6
+ const require_typed_xlsx_definitions = require("./xlsx/definitions.cjs");
6
7
  let document_schema_js = require("document-schema.js");
7
8
  //#region src/typed/document-package.ts
8
9
  function readDocx(pkg) {
@@ -27,7 +28,12 @@ function readPptx(pkg) {
27
28
  });
28
29
  }
29
30
  function readXlsx(pkg) {
30
- return (0, document_schema_js.assemblePackage)(require_typed_xlsx_content.readXlsxContent(pkg));
31
+ const definitions = require_typed_xlsx_definitions.readWorkbookDefinitions(pkg);
32
+ const tree = (0, document_schema_js.assemblePackage)(require_typed_xlsx_content.readXlsxContent(pkg));
33
+ return definitions === void 0 ? tree : {
34
+ ...tree,
35
+ definitions
36
+ };
31
37
  }
32
38
  function buildXlsxPackage(document) {
33
39
  const content = (0, document_schema_js.flattenPackage)(document);
@@ -1,7 +1,8 @@
1
- import { c as readPptxContent, i as readDocxContent } from "../read-fuJpC4BH.js";
1
+ import { o as readDocxContent, u as readPptxContent } from "../read-DGknK1YY.js";
2
2
  import { readXlsxContent } from "./xlsx/content.js";
3
3
  import { buildXlsxPackageFromContent } from "./xlsx/build.js";
4
4
  import { buildDocxPackageFromContent } from "./docx/write.js";
5
+ import { readWorkbookDefinitions } from "./xlsx/definitions.js";
5
6
  import { assemblePackage, flattenPackage } from "document-schema.js";
6
7
  //#region src/typed/document-package.ts
7
8
  function readDocx(pkg) {
@@ -26,7 +27,12 @@ function readPptx(pkg) {
26
27
  });
27
28
  }
28
29
  function readXlsx(pkg) {
29
- return assemblePackage(readXlsxContent(pkg));
30
+ const definitions = readWorkbookDefinitions(pkg);
31
+ const tree = assemblePackage(readXlsxContent(pkg));
32
+ return definitions === void 0 ? tree : {
33
+ ...tree,
34
+ definitions
35
+ };
30
36
  }
31
37
  function buildXlsxPackage(document) {
32
38
  const content = flattenPackage(document);
@@ -86,6 +86,43 @@ function insertConstructMarkers(blocks, extents) {
86
86
  }
87
87
  return out;
88
88
  }
89
+ function isBlockScopedHalf(half, index) {
90
+ const position = index.elements.indexOf(half.element);
91
+ if (position === -1) return false;
92
+ const leading = index.firstContentIndex === -1 || position < index.firstContentIndex;
93
+ const trailing = index.lastContentIndex === -1 || position > index.lastContentIndex;
94
+ return leading || trailing;
95
+ }
96
+ function runRangeMarkerExtents(halves, index) {
97
+ const byId = /* @__PURE__ */ new Map();
98
+ for (const half of halves) {
99
+ const key = `${half.family}:${half.id}`;
100
+ const existing = byId.get(key);
101
+ if (existing === void 0) byId.set(key, [half]);
102
+ else existing.push(half);
103
+ }
104
+ const extents = [];
105
+ for (const pair of byId.values()) {
106
+ const starts = pair.filter((half) => half.kind === "start");
107
+ const ends = pair.filter((half) => half.kind === "end");
108
+ const open = starts[0];
109
+ const close = ends[0];
110
+ if (starts.length !== 1 || ends.length !== 1 || open === void 0 || close === void 0) continue;
111
+ const descriptor = open.family === "comment" ? {
112
+ kind: "anchor",
113
+ anchorType: "comment",
114
+ name: open.id
115
+ } : open.name === void 0 ? void 0 : bookmarkAnchorDescriptor(open.name);
116
+ if (descriptor === void 0 || close.runPosition < open.runPosition) continue;
117
+ if (isBlockScopedHalf(open, index) && isBlockScopedHalf(close, index)) continue;
118
+ extents.push({
119
+ descriptor,
120
+ startRun: open.runPosition,
121
+ endRun: close.runPosition
122
+ });
123
+ }
124
+ return extents;
125
+ }
89
126
  const CONTROL_TYPE_BY_TAG = /* @__PURE__ */ new Map([
90
127
  ["w:richText", "richText"],
91
128
  ["w:text", "plainText"],
@@ -219,6 +256,48 @@ function fieldCharType(run) {
219
256
  const fldChar = require_typed_util.childrenWithTag(run, "w:fldChar")[0];
220
257
  return fldChar === void 0 ? void 0 : require_typed_util.attr(fldChar, "w:fldCharType");
221
258
  }
259
+ const FORM_CONTROL_TYPE_BY_TAG = /* @__PURE__ */ new Map([
260
+ ["w:checkBox", "checkbox"],
261
+ ["w:ddList", "dropDown"],
262
+ ["w:textInput", "plainText"]
263
+ ]);
264
+ function readOnOff(element) {
265
+ if (element === void 0) return;
266
+ const val = require_typed_util.attr(element, "w:val");
267
+ return val === void 0 || val !== "0" && val !== "false" && val !== "off";
268
+ }
269
+ function readFormControlDescriptor(beginRun) {
270
+ const ffData = require_typed_util.childrenWithTag(beginRun, "w:ffData")[0];
271
+ if (ffData === void 0) return;
272
+ const descriptor = {
273
+ kind: "contentControl",
274
+ controlType: "richText",
275
+ source: {
276
+ format: "docx",
277
+ xml: require_xml_build.buildXml([ffData])
278
+ }
279
+ };
280
+ const name = require_typed_util.childrenWithTag(ffData, "w:name")[0];
281
+ const nameVal = name === void 0 ? void 0 : require_typed_util.attr(name, "w:val");
282
+ if (nameVal !== void 0) descriptor.tag = require_typed_util.decodeEntities(nameVal);
283
+ for (const child of ffData.children) {
284
+ if (child.type !== "element") continue;
285
+ const controlType = FORM_CONTROL_TYPE_BY_TAG.get(child.tag);
286
+ if (controlType === void 0) continue;
287
+ descriptor.controlType = controlType;
288
+ if (child.tag === "w:checkBox") descriptor.checked = readOnOff(require_typed_util.childrenWithTag(child, "w:checked")[0]) ?? readOnOff(require_typed_util.childrenWithTag(child, "w:default")[0]) ?? false;
289
+ else if (child.tag === "w:ddList") {
290
+ const options = [];
291
+ for (const item of require_typed_util.childrenWithTag(child, "w:listItem")) {
292
+ const value = require_typed_util.attr(item, "w:displayText") ?? require_typed_util.attr(item, "w:val");
293
+ if (value !== void 0) options.push(require_typed_util.decodeEntities(value));
294
+ }
295
+ if (options.length > 0) descriptor.options = options;
296
+ }
297
+ break;
298
+ }
299
+ return descriptor;
300
+ }
222
301
  //#endregion
223
302
  exports.PROVENANCE_CHANGE_BY_TAG = PROVENANCE_CHANGE_BY_TAG;
224
303
  exports.TABLE_OF_CONTENTS_GALLERY = TABLE_OF_CONTENTS_GALLERY;
@@ -229,5 +308,7 @@ exports.indexParagraphContent = indexParagraphContent;
229
308
  exports.insertConstructMarkers = insertConstructMarkers;
230
309
  exports.isDeletedChange = isDeletedChange;
231
310
  exports.readContentControlDescriptor = readContentControlDescriptor;
311
+ exports.readFormControlDescriptor = readFormControlDescriptor;
232
312
  exports.readProvenanceDescriptor = readProvenanceDescriptor;
233
313
  exports.runInstructionText = runInstructionText;
314
+ exports.runRangeMarkerExtents = runRangeMarkerExtents;
@@ -1,5 +1,5 @@
1
1
  import { l as XmlElement } from "../../node-CkBWRjNR.cjs";
2
- import { AnchorDescriptor, ConstructDescriptor, ContentBlock, ContentControlDescriptor, ProvenanceChange, ProvenanceDescriptor } from "document-schema.js";
2
+ import { AnchorDescriptor, ConstructDescriptor, ContentBlock, ContentControlDescriptor, ProvenanceChange, ProvenanceDescriptor, RunConstructExtent } from "document-schema.js";
3
3
  //#region src/typed/docx/constructs.d.ts
4
4
  interface ParagraphContentIndex {
5
5
  readonly elements: readonly XmlElement[];
@@ -15,6 +15,16 @@ interface ConstructExtent {
15
15
  readonly descriptor: ConstructDescriptor;
16
16
  }
17
17
  declare function insertConstructMarkers(blocks: readonly ContentBlock[], extents: readonly ConstructExtent[]): ContentBlock[];
18
+ type RangeMarkerFamily = 'bookmark' | 'comment';
19
+ interface ParagraphRangeMarkerHalf {
20
+ readonly element: XmlElement;
21
+ readonly family: RangeMarkerFamily;
22
+ readonly id: string;
23
+ readonly name: string | undefined;
24
+ readonly kind: 'start' | 'end';
25
+ readonly runPosition: number;
26
+ }
27
+ declare function runRangeMarkerExtents(halves: readonly ParagraphRangeMarkerHalf[], index: ParagraphContentIndex): RunConstructExtent[];
18
28
  declare const TABLE_OF_CONTENTS_GALLERY = "Table of Contents";
19
29
  declare function readContentControlDescriptor(sdt: XmlElement): ContentControlDescriptor;
20
30
  declare const PROVENANCE_CHANGE_BY_TAG: ReadonlyMap<string, ProvenanceChange>;
@@ -23,5 +33,6 @@ declare function readProvenanceDescriptor(element: XmlElement, change: Provenanc
23
33
  declare function bookmarkAnchorDescriptor(name: string): AnchorDescriptor;
24
34
  declare function runInstructionText(run: XmlElement): string;
25
35
  declare function fieldCharType(run: XmlElement): string | undefined;
36
+ declare function readFormControlDescriptor(beginRun: XmlElement): ContentControlDescriptor | undefined;
26
37
  //#endregion
27
- export { ConstructExtent, PROVENANCE_CHANGE_BY_TAG, ParagraphContentIndex, TABLE_OF_CONTENTS_GALLERY, bookmarkAnchorDescriptor, contentBearingChildren, fieldCharType, indexParagraphContent, insertConstructMarkers, isDeletedChange, readContentControlDescriptor, readProvenanceDescriptor, runInstructionText };
38
+ export { ConstructExtent, PROVENANCE_CHANGE_BY_TAG, ParagraphContentIndex, ParagraphRangeMarkerHalf, RangeMarkerFamily, TABLE_OF_CONTENTS_GALLERY, bookmarkAnchorDescriptor, contentBearingChildren, fieldCharType, indexParagraphContent, insertConstructMarkers, isDeletedChange, readContentControlDescriptor, readFormControlDescriptor, readProvenanceDescriptor, runInstructionText, runRangeMarkerExtents };
@@ -1,5 +1,5 @@
1
1
  import { l as XmlElement } from "../../node-CkBWRjNR.js";
2
- import { AnchorDescriptor, ConstructDescriptor, ContentBlock, ContentControlDescriptor, ProvenanceChange, ProvenanceDescriptor } from "document-schema.js";
2
+ import { AnchorDescriptor, ConstructDescriptor, ContentBlock, ContentControlDescriptor, ProvenanceChange, ProvenanceDescriptor, RunConstructExtent } from "document-schema.js";
3
3
  //#region src/typed/docx/constructs.d.ts
4
4
  interface ParagraphContentIndex {
5
5
  readonly elements: readonly XmlElement[];
@@ -15,6 +15,16 @@ interface ConstructExtent {
15
15
  readonly descriptor: ConstructDescriptor;
16
16
  }
17
17
  declare function insertConstructMarkers(blocks: readonly ContentBlock[], extents: readonly ConstructExtent[]): ContentBlock[];
18
+ type RangeMarkerFamily = 'bookmark' | 'comment';
19
+ interface ParagraphRangeMarkerHalf {
20
+ readonly element: XmlElement;
21
+ readonly family: RangeMarkerFamily;
22
+ readonly id: string;
23
+ readonly name: string | undefined;
24
+ readonly kind: 'start' | 'end';
25
+ readonly runPosition: number;
26
+ }
27
+ declare function runRangeMarkerExtents(halves: readonly ParagraphRangeMarkerHalf[], index: ParagraphContentIndex): RunConstructExtent[];
18
28
  declare const TABLE_OF_CONTENTS_GALLERY = "Table of Contents";
19
29
  declare function readContentControlDescriptor(sdt: XmlElement): ContentControlDescriptor;
20
30
  declare const PROVENANCE_CHANGE_BY_TAG: ReadonlyMap<string, ProvenanceChange>;
@@ -23,5 +33,6 @@ declare function readProvenanceDescriptor(element: XmlElement, change: Provenanc
23
33
  declare function bookmarkAnchorDescriptor(name: string): AnchorDescriptor;
24
34
  declare function runInstructionText(run: XmlElement): string;
25
35
  declare function fieldCharType(run: XmlElement): string | undefined;
36
+ declare function readFormControlDescriptor(beginRun: XmlElement): ContentControlDescriptor | undefined;
26
37
  //#endregion
27
- export { ConstructExtent, PROVENANCE_CHANGE_BY_TAG, ParagraphContentIndex, TABLE_OF_CONTENTS_GALLERY, bookmarkAnchorDescriptor, contentBearingChildren, fieldCharType, indexParagraphContent, insertConstructMarkers, isDeletedChange, readContentControlDescriptor, readProvenanceDescriptor, runInstructionText };
38
+ export { ConstructExtent, PROVENANCE_CHANGE_BY_TAG, ParagraphContentIndex, ParagraphRangeMarkerHalf, RangeMarkerFamily, TABLE_OF_CONTENTS_GALLERY, bookmarkAnchorDescriptor, contentBearingChildren, fieldCharType, indexParagraphContent, insertConstructMarkers, isDeletedChange, readContentControlDescriptor, readFormControlDescriptor, readProvenanceDescriptor, runInstructionText, runRangeMarkerExtents };
@@ -85,6 +85,43 @@ function insertConstructMarkers(blocks, extents) {
85
85
  }
86
86
  return out;
87
87
  }
88
+ function isBlockScopedHalf(half, index) {
89
+ const position = index.elements.indexOf(half.element);
90
+ if (position === -1) return false;
91
+ const leading = index.firstContentIndex === -1 || position < index.firstContentIndex;
92
+ const trailing = index.lastContentIndex === -1 || position > index.lastContentIndex;
93
+ return leading || trailing;
94
+ }
95
+ function runRangeMarkerExtents(halves, index) {
96
+ const byId = /* @__PURE__ */ new Map();
97
+ for (const half of halves) {
98
+ const key = `${half.family}:${half.id}`;
99
+ const existing = byId.get(key);
100
+ if (existing === void 0) byId.set(key, [half]);
101
+ else existing.push(half);
102
+ }
103
+ const extents = [];
104
+ for (const pair of byId.values()) {
105
+ const starts = pair.filter((half) => half.kind === "start");
106
+ const ends = pair.filter((half) => half.kind === "end");
107
+ const open = starts[0];
108
+ const close = ends[0];
109
+ if (starts.length !== 1 || ends.length !== 1 || open === void 0 || close === void 0) continue;
110
+ const descriptor = open.family === "comment" ? {
111
+ kind: "anchor",
112
+ anchorType: "comment",
113
+ name: open.id
114
+ } : open.name === void 0 ? void 0 : bookmarkAnchorDescriptor(open.name);
115
+ if (descriptor === void 0 || close.runPosition < open.runPosition) continue;
116
+ if (isBlockScopedHalf(open, index) && isBlockScopedHalf(close, index)) continue;
117
+ extents.push({
118
+ descriptor,
119
+ startRun: open.runPosition,
120
+ endRun: close.runPosition
121
+ });
122
+ }
123
+ return extents;
124
+ }
88
125
  const CONTROL_TYPE_BY_TAG = /* @__PURE__ */ new Map([
89
126
  ["w:richText", "richText"],
90
127
  ["w:text", "plainText"],
@@ -218,5 +255,47 @@ function fieldCharType(run) {
218
255
  const fldChar = childrenWithTag(run, "w:fldChar")[0];
219
256
  return fldChar === void 0 ? void 0 : attr(fldChar, "w:fldCharType");
220
257
  }
258
+ const FORM_CONTROL_TYPE_BY_TAG = /* @__PURE__ */ new Map([
259
+ ["w:checkBox", "checkbox"],
260
+ ["w:ddList", "dropDown"],
261
+ ["w:textInput", "plainText"]
262
+ ]);
263
+ function readOnOff(element) {
264
+ if (element === void 0) return;
265
+ const val = attr(element, "w:val");
266
+ return val === void 0 || val !== "0" && val !== "false" && val !== "off";
267
+ }
268
+ function readFormControlDescriptor(beginRun) {
269
+ const ffData = childrenWithTag(beginRun, "w:ffData")[0];
270
+ if (ffData === void 0) return;
271
+ const descriptor = {
272
+ kind: "contentControl",
273
+ controlType: "richText",
274
+ source: {
275
+ format: "docx",
276
+ xml: buildXml([ffData])
277
+ }
278
+ };
279
+ const name = childrenWithTag(ffData, "w:name")[0];
280
+ const nameVal = name === void 0 ? void 0 : attr(name, "w:val");
281
+ if (nameVal !== void 0) descriptor.tag = decodeEntities(nameVal);
282
+ for (const child of ffData.children) {
283
+ if (child.type !== "element") continue;
284
+ const controlType = FORM_CONTROL_TYPE_BY_TAG.get(child.tag);
285
+ if (controlType === void 0) continue;
286
+ descriptor.controlType = controlType;
287
+ if (child.tag === "w:checkBox") descriptor.checked = readOnOff(childrenWithTag(child, "w:checked")[0]) ?? readOnOff(childrenWithTag(child, "w:default")[0]) ?? false;
288
+ else if (child.tag === "w:ddList") {
289
+ const options = [];
290
+ for (const item of childrenWithTag(child, "w:listItem")) {
291
+ const value = attr(item, "w:displayText") ?? attr(item, "w:val");
292
+ if (value !== void 0) options.push(decodeEntities(value));
293
+ }
294
+ if (options.length > 0) descriptor.options = options;
295
+ }
296
+ break;
297
+ }
298
+ return descriptor;
299
+ }
221
300
  //#endregion
222
- export { PROVENANCE_CHANGE_BY_TAG, TABLE_OF_CONTENTS_GALLERY, bookmarkAnchorDescriptor, contentBearingChildren, fieldCharType, indexParagraphContent, insertConstructMarkers, isDeletedChange, readContentControlDescriptor, readProvenanceDescriptor, runInstructionText };
301
+ export { PROVENANCE_CHANGE_BY_TAG, TABLE_OF_CONTENTS_GALLERY, bookmarkAnchorDescriptor, contentBearingChildren, fieldCharType, indexParagraphContent, insertConstructMarkers, isDeletedChange, readContentControlDescriptor, readFormControlDescriptor, readProvenanceDescriptor, runInstructionText, runRangeMarkerExtents };
@@ -1,6 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_read = require("../../read-C3AaxcT9.cjs");
2
+ const require_read = require("../../read-D-L3dItC.cjs");
3
3
  exports.CommentSchema = require_read.CommentSchema;
4
4
  exports.DocxDocumentSchema = require_read.DocxDocumentSchema;
5
5
  exports.FootnoteSchema = require_read.FootnoteSchema;
6
+ exports.HeaderFooterPartSchema = require_read.HeaderFooterPartSchema;
7
+ exports.SectionHeaderFooterReferencesSchema = require_read.SectionHeaderFooterReferencesSchema;
6
8
  exports.readDocxContent = require_read.readDocxContent;
@@ -1,2 +1,2 @@
1
- import { a as Footnote, i as DocxDocumentSchema, n as CommentSchema, o as FootnoteSchema, r as DocxDocument, s as readDocxContent, t as Comment } from "../../read-CDX1WbiF.cjs";
2
- export { Comment, CommentSchema, DocxDocument, DocxDocumentSchema, Footnote, FootnoteSchema, readDocxContent };
1
+ import { a as Footnote, c as HeaderFooterPartSchema, d as readDocxContent, i as DocxDocumentSchema, l as SectionHeaderFooterReferences, n as CommentSchema, o as FootnoteSchema, r as DocxDocument, s as HeaderFooterPart, t as Comment, u as SectionHeaderFooterReferencesSchema } from "../../read-LTgVJIPU.cjs";
2
+ export { Comment, CommentSchema, DocxDocument, DocxDocumentSchema, Footnote, FootnoteSchema, HeaderFooterPart, HeaderFooterPartSchema, SectionHeaderFooterReferences, SectionHeaderFooterReferencesSchema, readDocxContent };
@@ -1,2 +1,2 @@
1
- import { a as Footnote, i as DocxDocumentSchema, n as CommentSchema, o as FootnoteSchema, r as DocxDocument, s as readDocxContent, t as Comment } from "../../read-CxMli3Om.js";
2
- export { Comment, CommentSchema, DocxDocument, DocxDocumentSchema, Footnote, FootnoteSchema, readDocxContent };
1
+ import { a as Footnote, c as HeaderFooterPartSchema, d as readDocxContent, i as DocxDocumentSchema, l as SectionHeaderFooterReferences, n as CommentSchema, o as FootnoteSchema, r as DocxDocument, s as HeaderFooterPart, t as Comment, u as SectionHeaderFooterReferencesSchema } from "../../read-D30xHgEp.js";
2
+ export { Comment, CommentSchema, DocxDocument, DocxDocumentSchema, Footnote, FootnoteSchema, HeaderFooterPart, HeaderFooterPartSchema, SectionHeaderFooterReferences, SectionHeaderFooterReferencesSchema, readDocxContent };
@@ -1,2 +1,2 @@
1
- import { i as readDocxContent, n as DocxDocumentSchema, r as FootnoteSchema, t as CommentSchema } from "../../read-fuJpC4BH.js";
2
- export { CommentSchema, DocxDocumentSchema, FootnoteSchema, readDocxContent };
1
+ import { a as SectionHeaderFooterReferencesSchema, i as HeaderFooterPartSchema, n as DocxDocumentSchema, o as readDocxContent, r as FootnoteSchema, t as CommentSchema } from "../../read-DGknK1YY.js";
2
+ export { CommentSchema, DocxDocumentSchema, FootnoteSchema, HeaderFooterPartSchema, SectionHeaderFooterReferencesSchema, readDocxContent };
@@ -179,10 +179,112 @@ function buildParagraph(paragraph, state, pageBreakBefore, deleted, provenance)
179
179
  const changeTag = provenance === void 0 ? void 0 : TRACKED_CHANGE_TAG_BY_CHANGE[provenance.change];
180
180
  const pPr = properties === void 0 && changeTag !== void 0 ? require_xml_fragment.el("w:pPr", {}, []) : properties;
181
181
  if (pPr !== void 0 && changeTag !== void 0 && provenance !== void 0) pPr.children.push(require_xml_fragment.el("w:rPr", {}, [require_xml_fragment.el(changeTag, trackChangeAttrs(state, provenance))]));
182
- const runs = paragraph.runs.map((run) => buildRun(run, state, deleted));
182
+ const runs = interleaveRunConstructExtents(paragraph.runs.map((run) => buildRun(run, state, deleted)), paragraph, state);
183
183
  const content = changeTag === void 0 || provenance === void 0 ? runs : [require_xml_fragment.el(changeTag, trackChangeAttrs(state, provenance), runs)];
184
184
  return require_xml_fragment.el("w:p", {}, [...pPr === void 0 ? [] : [pPr], ...content]);
185
185
  }
186
+ function interleaveRunConstructExtents(runElements, paragraph, state) {
187
+ if (paragraph.constructs === void 0) return [...runElements];
188
+ const fault = (0, document_schema_js.findRunConstructFault)(paragraph);
189
+ if (fault !== void 0) throw new Error(`buildDocxPackageFromContent: run-level construct extent at index ${String(fault.index)} of a paragraph does not name real runs (${fault.kind})`);
190
+ const bookmarks = paragraph.constructs.filter((extent) => extent.descriptor.kind === "anchor" && extent.descriptor.anchorType === "bookmark");
191
+ const fields = paragraph.constructs.filter((extent) => extent.descriptor.kind === "field");
192
+ const links = [];
193
+ for (const extent of paragraph.constructs) if (extent.descriptor.kind === "link" && extent.descriptor.target.kind === "internal") links.push({
194
+ descriptor: extent.descriptor,
195
+ startRun: extent.startRun,
196
+ endRun: extent.endRun,
197
+ anchor: extent.descriptor.target.anchor
198
+ });
199
+ if (bookmarks.length === 0 && fields.length === 0) return wrapInternalLinks([...runElements], new RunPositions(runElements), links);
200
+ const closingAt = /* @__PURE__ */ new Map();
201
+ const openingAt = /* @__PURE__ */ new Map();
202
+ const pointAt = /* @__PURE__ */ new Map();
203
+ const push = (map, position, element) => {
204
+ const existing = map.get(position);
205
+ if (existing === void 0) map.set(position, [element]);
206
+ else existing.push(element);
207
+ };
208
+ for (const bookmark of bookmarks) {
209
+ const id = String(state.nextMarkerId++);
210
+ const open = require_xml_fragment.el("w:bookmarkStart", {
211
+ "w:id": id,
212
+ "w:name": require_xml_entities.encodeXmlText(bookmark.descriptor.name)
213
+ });
214
+ const close = require_xml_fragment.el("w:bookmarkEnd", { "w:id": id });
215
+ if (bookmark.startRun === bookmark.endRun) {
216
+ push(pointAt, bookmark.startRun, open);
217
+ push(pointAt, bookmark.startRun, close);
218
+ } else {
219
+ push(openingAt, bookmark.startRun, open);
220
+ push(closingAt, bookmark.endRun, close);
221
+ }
222
+ }
223
+ for (const field of fields) {
224
+ const opening = [
225
+ fieldCharRun("begin"),
226
+ require_xml_fragment.el("w:r", {}, [require_xml_fragment.el("w:instrText", { "xml:space": "preserve" }, [require_xml_fragment.txt(require_xml_entities.encodeXmlText(field.descriptor.instruction))])]),
227
+ fieldCharRun("separate")
228
+ ];
229
+ if (field.startRun === field.endRun) {
230
+ for (const run of opening) push(pointAt, field.startRun, run);
231
+ push(pointAt, field.startRun, fieldCharRun("end"));
232
+ } else {
233
+ for (const run of opening) push(openingAt, field.startRun, run);
234
+ push(closingAt, field.endRun, fieldCharRun("end"));
235
+ }
236
+ }
237
+ const out = [];
238
+ const positions = new RunPositions(runElements);
239
+ for (let position = 0; position <= runElements.length; position++) {
240
+ for (const close of closingAt.get(position) ?? []) out.push(close);
241
+ for (const open of openingAt.get(position) ?? []) out.push(open);
242
+ for (const half of pointAt.get(position) ?? []) out.push(half);
243
+ const run = runElements[position];
244
+ if (run !== void 0) out.push(run);
245
+ }
246
+ return wrapInternalLinks(out, positions, links);
247
+ }
248
+ var RunPositions = class {
249
+ indexOfElement = /* @__PURE__ */ new Map();
250
+ constructor(runElements) {
251
+ runElements.forEach((element, index) => {
252
+ this.indexOfElement.set(element, index);
253
+ });
254
+ }
255
+ positionOf(element) {
256
+ return this.indexOfElement.get(element);
257
+ }
258
+ };
259
+ function wrapInternalLinks(elements, positions, links) {
260
+ if (links.length === 0) return elements;
261
+ let out = elements;
262
+ const wrapped = [];
263
+ for (const link of [...links].sort((a, b) => a.startRun - b.startRun || b.endRun - a.endRun)) {
264
+ let first = -1;
265
+ let last = -1;
266
+ out.forEach((element, index) => {
267
+ const position = positions.positionOf(element);
268
+ if (position === link.startRun) first = index;
269
+ if (position === link.endRun - 1) last = index;
270
+ });
271
+ if (first === -1 || last === -1 || last < first) continue;
272
+ const slice = out.slice(first, last + 1);
273
+ const overlapsWrapped = wrapped.some((range) => first <= range.last && range.first <= last);
274
+ const carriesHyperlink = slice.some((element) => element.tag === "w:hyperlink");
275
+ if (overlapsWrapped || carriesHyperlink) continue;
276
+ wrapped.push({
277
+ first,
278
+ last
279
+ });
280
+ out = [
281
+ ...out.slice(0, first),
282
+ require_xml_fragment.el("w:hyperlink", { "w:anchor": require_xml_entities.encodeXmlText(link.anchor) }, slice),
283
+ ...out.slice(last + 1)
284
+ ];
285
+ }
286
+ return out;
287
+ }
186
288
  function trailingEmptyRunElements(paragraph, element) {
187
289
  const runElements = [];
188
290
  for (const child of element.children) if (child.type === "element" && (child.tag === "w:r" || child.tag === "w:hyperlink")) runElements.push(child);
@@ -597,15 +699,20 @@ function buildBlockFlow(blocks, state, deleted) {
597
699
  return buildFlowItems(parseFlow(blocks), state, deleted, void 0);
598
700
  }
599
701
  function buildSectionProperties(section) {
600
- return require_xml_fragment.el("w:sectPr", {}, [require_xml_fragment.el("w:pgSz", {
601
- "w:w": String(require_typed_shared_units.ptToTwips(section.pageSize.widthPt)),
602
- "w:h": String(require_typed_shared_units.ptToTwips(section.pageSize.heightPt))
603
- }), require_xml_fragment.el("w:pgMar", {
604
- "w:top": String(require_typed_shared_units.ptToTwips(section.margins.topPt)),
605
- "w:right": String(require_typed_shared_units.ptToTwips(section.margins.rightPt)),
606
- "w:bottom": String(require_typed_shared_units.ptToTwips(section.margins.bottomPt)),
607
- "w:left": String(require_typed_shared_units.ptToTwips(section.margins.leftPt))
608
- })]);
702
+ const type = section.breakType === void 0 ? [] : [require_xml_fragment.el("w:type", { "w:val": section.breakType })];
703
+ return require_xml_fragment.el("w:sectPr", {}, [
704
+ ...type,
705
+ require_xml_fragment.el("w:pgSz", {
706
+ "w:w": String(require_typed_shared_units.ptToTwips(section.pageSize.widthPt)),
707
+ "w:h": String(require_typed_shared_units.ptToTwips(section.pageSize.heightPt))
708
+ }),
709
+ require_xml_fragment.el("w:pgMar", {
710
+ "w:top": String(require_typed_shared_units.ptToTwips(section.margins.topPt)),
711
+ "w:right": String(require_typed_shared_units.ptToTwips(section.margins.rightPt)),
712
+ "w:bottom": String(require_typed_shared_units.ptToTwips(section.margins.bottomPt)),
713
+ "w:left": String(require_typed_shared_units.ptToTwips(section.margins.leftPt))
714
+ })
715
+ ]);
609
716
  }
610
717
  function attachSectionBreak(nodes, section) {
611
718
  const target = findParagraph(nodes, true);