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.
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-Di5UfiSh.cjs → read-D-L3dItC.cjs} +316 -59
  13. package/dist/{read-CxMli3Om.d.ts → read-D30xHgEp.d.ts} +58 -1
  14. package/dist/{read-BQoFiqsb.js → read-DGknK1YY.js} +307 -62
  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 +55 -6
  19. package/dist/typed/docx/constructs.d.cts +6 -3
  20. package/dist/typed/docx/constructs.d.ts +6 -3
  21. package/dist/typed/docx/constructs.js +54 -6
  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 +78 -10
  27. package/dist/typed/docx/write.js +78 -10
  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-Di5UfiSh.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-BQoFiqsb.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);
@@ -93,11 +93,12 @@ function isBlockScopedHalf(half, index) {
93
93
  const trailing = index.lastContentIndex === -1 || position > index.lastContentIndex;
94
94
  return leading || trailing;
95
95
  }
96
- function runBookmarkExtents(halves, index) {
96
+ function runRangeMarkerExtents(halves, index) {
97
97
  const byId = /* @__PURE__ */ new Map();
98
98
  for (const half of halves) {
99
- const existing = byId.get(half.id);
100
- if (existing === void 0) byId.set(half.id, [half]);
99
+ const key = `${half.family}:${half.id}`;
100
+ const existing = byId.get(key);
101
+ if (existing === void 0) byId.set(key, [half]);
101
102
  else existing.push(half);
102
103
  }
103
104
  const extents = [];
@@ -107,10 +108,15 @@ function runBookmarkExtents(halves, index) {
107
108
  const open = starts[0];
108
109
  const close = ends[0];
109
110
  if (starts.length !== 1 || ends.length !== 1 || open === void 0 || close === void 0) continue;
110
- if (open.name === void 0 || close.runPosition < open.runPosition) 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;
111
117
  if (isBlockScopedHalf(open, index) && isBlockScopedHalf(close, index)) continue;
112
118
  extents.push({
113
- descriptor: bookmarkAnchorDescriptor(open.name),
119
+ descriptor,
114
120
  startRun: open.runPosition,
115
121
  endRun: close.runPosition
116
122
  });
@@ -250,6 +256,48 @@ function fieldCharType(run) {
250
256
  const fldChar = require_typed_util.childrenWithTag(run, "w:fldChar")[0];
251
257
  return fldChar === void 0 ? void 0 : require_typed_util.attr(fldChar, "w:fldCharType");
252
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
+ }
253
301
  //#endregion
254
302
  exports.PROVENANCE_CHANGE_BY_TAG = PROVENANCE_CHANGE_BY_TAG;
255
303
  exports.TABLE_OF_CONTENTS_GALLERY = TABLE_OF_CONTENTS_GALLERY;
@@ -260,6 +308,7 @@ exports.indexParagraphContent = indexParagraphContent;
260
308
  exports.insertConstructMarkers = insertConstructMarkers;
261
309
  exports.isDeletedChange = isDeletedChange;
262
310
  exports.readContentControlDescriptor = readContentControlDescriptor;
311
+ exports.readFormControlDescriptor = readFormControlDescriptor;
263
312
  exports.readProvenanceDescriptor = readProvenanceDescriptor;
264
- exports.runBookmarkExtents = runBookmarkExtents;
265
313
  exports.runInstructionText = runInstructionText;
314
+ exports.runRangeMarkerExtents = runRangeMarkerExtents;
@@ -15,14 +15,16 @@ interface ConstructExtent {
15
15
  readonly descriptor: ConstructDescriptor;
16
16
  }
17
17
  declare function insertConstructMarkers(blocks: readonly ContentBlock[], extents: readonly ConstructExtent[]): ContentBlock[];
18
- interface ParagraphBookmarkHalf {
18
+ type RangeMarkerFamily = 'bookmark' | 'comment';
19
+ interface ParagraphRangeMarkerHalf {
19
20
  readonly element: XmlElement;
21
+ readonly family: RangeMarkerFamily;
20
22
  readonly id: string;
21
23
  readonly name: string | undefined;
22
24
  readonly kind: 'start' | 'end';
23
25
  readonly runPosition: number;
24
26
  }
25
- declare function runBookmarkExtents(halves: readonly ParagraphBookmarkHalf[], index: ParagraphContentIndex): RunConstructExtent[];
27
+ declare function runRangeMarkerExtents(halves: readonly ParagraphRangeMarkerHalf[], index: ParagraphContentIndex): RunConstructExtent[];
26
28
  declare const TABLE_OF_CONTENTS_GALLERY = "Table of Contents";
27
29
  declare function readContentControlDescriptor(sdt: XmlElement): ContentControlDescriptor;
28
30
  declare const PROVENANCE_CHANGE_BY_TAG: ReadonlyMap<string, ProvenanceChange>;
@@ -31,5 +33,6 @@ declare function readProvenanceDescriptor(element: XmlElement, change: Provenanc
31
33
  declare function bookmarkAnchorDescriptor(name: string): AnchorDescriptor;
32
34
  declare function runInstructionText(run: XmlElement): string;
33
35
  declare function fieldCharType(run: XmlElement): string | undefined;
36
+ declare function readFormControlDescriptor(beginRun: XmlElement): ContentControlDescriptor | undefined;
34
37
  //#endregion
35
- export { ConstructExtent, PROVENANCE_CHANGE_BY_TAG, ParagraphBookmarkHalf, ParagraphContentIndex, TABLE_OF_CONTENTS_GALLERY, bookmarkAnchorDescriptor, contentBearingChildren, fieldCharType, indexParagraphContent, insertConstructMarkers, isDeletedChange, readContentControlDescriptor, readProvenanceDescriptor, runBookmarkExtents, 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 };
@@ -15,14 +15,16 @@ interface ConstructExtent {
15
15
  readonly descriptor: ConstructDescriptor;
16
16
  }
17
17
  declare function insertConstructMarkers(blocks: readonly ContentBlock[], extents: readonly ConstructExtent[]): ContentBlock[];
18
- interface ParagraphBookmarkHalf {
18
+ type RangeMarkerFamily = 'bookmark' | 'comment';
19
+ interface ParagraphRangeMarkerHalf {
19
20
  readonly element: XmlElement;
21
+ readonly family: RangeMarkerFamily;
20
22
  readonly id: string;
21
23
  readonly name: string | undefined;
22
24
  readonly kind: 'start' | 'end';
23
25
  readonly runPosition: number;
24
26
  }
25
- declare function runBookmarkExtents(halves: readonly ParagraphBookmarkHalf[], index: ParagraphContentIndex): RunConstructExtent[];
27
+ declare function runRangeMarkerExtents(halves: readonly ParagraphRangeMarkerHalf[], index: ParagraphContentIndex): RunConstructExtent[];
26
28
  declare const TABLE_OF_CONTENTS_GALLERY = "Table of Contents";
27
29
  declare function readContentControlDescriptor(sdt: XmlElement): ContentControlDescriptor;
28
30
  declare const PROVENANCE_CHANGE_BY_TAG: ReadonlyMap<string, ProvenanceChange>;
@@ -31,5 +33,6 @@ declare function readProvenanceDescriptor(element: XmlElement, change: Provenanc
31
33
  declare function bookmarkAnchorDescriptor(name: string): AnchorDescriptor;
32
34
  declare function runInstructionText(run: XmlElement): string;
33
35
  declare function fieldCharType(run: XmlElement): string | undefined;
36
+ declare function readFormControlDescriptor(beginRun: XmlElement): ContentControlDescriptor | undefined;
34
37
  //#endregion
35
- export { ConstructExtent, PROVENANCE_CHANGE_BY_TAG, ParagraphBookmarkHalf, ParagraphContentIndex, TABLE_OF_CONTENTS_GALLERY, bookmarkAnchorDescriptor, contentBearingChildren, fieldCharType, indexParagraphContent, insertConstructMarkers, isDeletedChange, readContentControlDescriptor, readProvenanceDescriptor, runBookmarkExtents, 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 };
@@ -92,11 +92,12 @@ function isBlockScopedHalf(half, index) {
92
92
  const trailing = index.lastContentIndex === -1 || position > index.lastContentIndex;
93
93
  return leading || trailing;
94
94
  }
95
- function runBookmarkExtents(halves, index) {
95
+ function runRangeMarkerExtents(halves, index) {
96
96
  const byId = /* @__PURE__ */ new Map();
97
97
  for (const half of halves) {
98
- const existing = byId.get(half.id);
99
- if (existing === void 0) byId.set(half.id, [half]);
98
+ const key = `${half.family}:${half.id}`;
99
+ const existing = byId.get(key);
100
+ if (existing === void 0) byId.set(key, [half]);
100
101
  else existing.push(half);
101
102
  }
102
103
  const extents = [];
@@ -106,10 +107,15 @@ function runBookmarkExtents(halves, index) {
106
107
  const open = starts[0];
107
108
  const close = ends[0];
108
109
  if (starts.length !== 1 || ends.length !== 1 || open === void 0 || close === void 0) continue;
109
- if (open.name === void 0 || close.runPosition < open.runPosition) 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;
110
116
  if (isBlockScopedHalf(open, index) && isBlockScopedHalf(close, index)) continue;
111
117
  extents.push({
112
- descriptor: bookmarkAnchorDescriptor(open.name),
118
+ descriptor,
113
119
  startRun: open.runPosition,
114
120
  endRun: close.runPosition
115
121
  });
@@ -249,5 +255,47 @@ function fieldCharType(run) {
249
255
  const fldChar = childrenWithTag(run, "w:fldChar")[0];
250
256
  return fldChar === void 0 ? void 0 : attr(fldChar, "w:fldCharType");
251
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
+ }
252
300
  //#endregion
253
- export { PROVENANCE_CHANGE_BY_TAG, TABLE_OF_CONTENTS_GALLERY, bookmarkAnchorDescriptor, contentBearingChildren, fieldCharType, indexParagraphContent, insertConstructMarkers, isDeletedChange, readContentControlDescriptor, readProvenanceDescriptor, runBookmarkExtents, 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-Di5UfiSh.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-BQoFiqsb.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 };
@@ -188,7 +188,15 @@ function interleaveRunConstructExtents(runElements, paragraph, state) {
188
188
  const fault = (0, document_schema_js.findRunConstructFault)(paragraph);
189
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
190
  const bookmarks = paragraph.constructs.filter((extent) => extent.descriptor.kind === "anchor" && extent.descriptor.anchorType === "bookmark");
191
- if (bookmarks.length === 0) return [...runElements];
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);
192
200
  const closingAt = /* @__PURE__ */ new Map();
193
201
  const openingAt = /* @__PURE__ */ new Map();
194
202
  const pointAt = /* @__PURE__ */ new Map();
@@ -212,7 +220,22 @@ function interleaveRunConstructExtents(runElements, paragraph, state) {
212
220
  push(closingAt, bookmark.endRun, close);
213
221
  }
214
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
+ }
215
237
  const out = [];
238
+ const positions = new RunPositions(runElements);
216
239
  for (let position = 0; position <= runElements.length; position++) {
217
240
  for (const close of closingAt.get(position) ?? []) out.push(close);
218
241
  for (const open of openingAt.get(position) ?? []) out.push(open);
@@ -220,6 +243,46 @@ function interleaveRunConstructExtents(runElements, paragraph, state) {
220
243
  const run = runElements[position];
221
244
  if (run !== void 0) out.push(run);
222
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
+ }
223
286
  return out;
224
287
  }
225
288
  function trailingEmptyRunElements(paragraph, element) {
@@ -636,15 +699,20 @@ function buildBlockFlow(blocks, state, deleted) {
636
699
  return buildFlowItems(parseFlow(blocks), state, deleted, void 0);
637
700
  }
638
701
  function buildSectionProperties(section) {
639
- return require_xml_fragment.el("w:sectPr", {}, [require_xml_fragment.el("w:pgSz", {
640
- "w:w": String(require_typed_shared_units.ptToTwips(section.pageSize.widthPt)),
641
- "w:h": String(require_typed_shared_units.ptToTwips(section.pageSize.heightPt))
642
- }), require_xml_fragment.el("w:pgMar", {
643
- "w:top": String(require_typed_shared_units.ptToTwips(section.margins.topPt)),
644
- "w:right": String(require_typed_shared_units.ptToTwips(section.margins.rightPt)),
645
- "w:bottom": String(require_typed_shared_units.ptToTwips(section.margins.bottomPt)),
646
- "w:left": String(require_typed_shared_units.ptToTwips(section.margins.leftPt))
647
- })]);
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
+ ]);
648
716
  }
649
717
  function attachSectionBreak(nodes, section) {
650
718
  const target = findParagraph(nodes, true);
@@ -187,7 +187,15 @@ function interleaveRunConstructExtents(runElements, paragraph, state) {
187
187
  const fault = findRunConstructFault(paragraph);
188
188
  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})`);
189
189
  const bookmarks = paragraph.constructs.filter((extent) => extent.descriptor.kind === "anchor" && extent.descriptor.anchorType === "bookmark");
190
- if (bookmarks.length === 0) return [...runElements];
190
+ const fields = paragraph.constructs.filter((extent) => extent.descriptor.kind === "field");
191
+ const links = [];
192
+ for (const extent of paragraph.constructs) if (extent.descriptor.kind === "link" && extent.descriptor.target.kind === "internal") links.push({
193
+ descriptor: extent.descriptor,
194
+ startRun: extent.startRun,
195
+ endRun: extent.endRun,
196
+ anchor: extent.descriptor.target.anchor
197
+ });
198
+ if (bookmarks.length === 0 && fields.length === 0) return wrapInternalLinks([...runElements], new RunPositions(runElements), links);
191
199
  const closingAt = /* @__PURE__ */ new Map();
192
200
  const openingAt = /* @__PURE__ */ new Map();
193
201
  const pointAt = /* @__PURE__ */ new Map();
@@ -211,7 +219,22 @@ function interleaveRunConstructExtents(runElements, paragraph, state) {
211
219
  push(closingAt, bookmark.endRun, close);
212
220
  }
213
221
  }
222
+ for (const field of fields) {
223
+ const opening = [
224
+ fieldCharRun("begin"),
225
+ el("w:r", {}, [el("w:instrText", { "xml:space": "preserve" }, [txt(encodeXmlText(field.descriptor.instruction))])]),
226
+ fieldCharRun("separate")
227
+ ];
228
+ if (field.startRun === field.endRun) {
229
+ for (const run of opening) push(pointAt, field.startRun, run);
230
+ push(pointAt, field.startRun, fieldCharRun("end"));
231
+ } else {
232
+ for (const run of opening) push(openingAt, field.startRun, run);
233
+ push(closingAt, field.endRun, fieldCharRun("end"));
234
+ }
235
+ }
214
236
  const out = [];
237
+ const positions = new RunPositions(runElements);
215
238
  for (let position = 0; position <= runElements.length; position++) {
216
239
  for (const close of closingAt.get(position) ?? []) out.push(close);
217
240
  for (const open of openingAt.get(position) ?? []) out.push(open);
@@ -219,6 +242,46 @@ function interleaveRunConstructExtents(runElements, paragraph, state) {
219
242
  const run = runElements[position];
220
243
  if (run !== void 0) out.push(run);
221
244
  }
245
+ return wrapInternalLinks(out, positions, links);
246
+ }
247
+ var RunPositions = class {
248
+ indexOfElement = /* @__PURE__ */ new Map();
249
+ constructor(runElements) {
250
+ runElements.forEach((element, index) => {
251
+ this.indexOfElement.set(element, index);
252
+ });
253
+ }
254
+ positionOf(element) {
255
+ return this.indexOfElement.get(element);
256
+ }
257
+ };
258
+ function wrapInternalLinks(elements, positions, links) {
259
+ if (links.length === 0) return elements;
260
+ let out = elements;
261
+ const wrapped = [];
262
+ for (const link of [...links].sort((a, b) => a.startRun - b.startRun || b.endRun - a.endRun)) {
263
+ let first = -1;
264
+ let last = -1;
265
+ out.forEach((element, index) => {
266
+ const position = positions.positionOf(element);
267
+ if (position === link.startRun) first = index;
268
+ if (position === link.endRun - 1) last = index;
269
+ });
270
+ if (first === -1 || last === -1 || last < first) continue;
271
+ const slice = out.slice(first, last + 1);
272
+ const overlapsWrapped = wrapped.some((range) => first <= range.last && range.first <= last);
273
+ const carriesHyperlink = slice.some((element) => element.tag === "w:hyperlink");
274
+ if (overlapsWrapped || carriesHyperlink) continue;
275
+ wrapped.push({
276
+ first,
277
+ last
278
+ });
279
+ out = [
280
+ ...out.slice(0, first),
281
+ el("w:hyperlink", { "w:anchor": encodeXmlText(link.anchor) }, slice),
282
+ ...out.slice(last + 1)
283
+ ];
284
+ }
222
285
  return out;
223
286
  }
224
287
  function trailingEmptyRunElements(paragraph, element) {
@@ -635,15 +698,20 @@ function buildBlockFlow(blocks, state, deleted) {
635
698
  return buildFlowItems(parseFlow(blocks), state, deleted, void 0);
636
699
  }
637
700
  function buildSectionProperties(section) {
638
- return el("w:sectPr", {}, [el("w:pgSz", {
639
- "w:w": String(ptToTwips(section.pageSize.widthPt)),
640
- "w:h": String(ptToTwips(section.pageSize.heightPt))
641
- }), el("w:pgMar", {
642
- "w:top": String(ptToTwips(section.margins.topPt)),
643
- "w:right": String(ptToTwips(section.margins.rightPt)),
644
- "w:bottom": String(ptToTwips(section.margins.bottomPt)),
645
- "w:left": String(ptToTwips(section.margins.leftPt))
646
- })]);
701
+ const type = section.breakType === void 0 ? [] : [el("w:type", { "w:val": section.breakType })];
702
+ return el("w:sectPr", {}, [
703
+ ...type,
704
+ el("w:pgSz", {
705
+ "w:w": String(ptToTwips(section.pageSize.widthPt)),
706
+ "w:h": String(ptToTwips(section.pageSize.heightPt))
707
+ }),
708
+ el("w:pgMar", {
709
+ "w:top": String(ptToTwips(section.margins.topPt)),
710
+ "w:right": String(ptToTwips(section.margins.rightPt)),
711
+ "w:bottom": String(ptToTwips(section.margins.bottomPt)),
712
+ "w:left": String(ptToTwips(section.margins.leftPt))
713
+ })
714
+ ]);
647
715
  }
648
716
  function attachSectionBreak(nodes, section) {
649
717
  const target = findParagraph(nodes, true);
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_read = require("../read-Di5UfiSh.cjs");
2
+ const require_read = require("../read-D-L3dItC.cjs");
3
3
  exports.readEmbeddedOoxmlPayload = require_read.readEmbeddedOoxmlPayload;
4
4
  exports.readEmbeddedPayloadPart = require_read.readEmbeddedPayloadPart;