odf.js 6.2.1 → 6.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 (168) hide show
  1. package/README.md +191 -17
  2. package/dist/{cascade-BDkyOmoo.d.cts → cascade-BpMwrjkB.d.cts} +1 -1
  3. package/dist/{cascade-CaVinmvp.d.ts → cascade-PDS3hgrP.d.ts} +1 -1
  4. package/dist/{codec-B72LApRl.d.cts → codec-CFdlbFLJ.d.cts} +21 -13
  5. package/dist/{codec-rbZGlr37.d.ts → codec-DTAgph2r.d.ts} +21 -13
  6. package/dist/codec.d.cts +1 -1
  7. package/dist/codec.d.ts +1 -1
  8. package/dist/{embedded-UQQNFd5U.js → embedded-BnavfkP-.js} +4 -5
  9. package/dist/{embedded-BsO-SvtW.cjs → embedded-Bxyss_ck.cjs} +15 -4
  10. package/dist/index.cjs +53 -1
  11. package/dist/index.d.cts +24 -16
  12. package/dist/index.d.ts +24 -16
  13. package/dist/index.js +19 -11
  14. package/dist/list-7FO0SDqZ.d.ts +32 -0
  15. package/dist/list-BorrTJBY.d.cts +32 -0
  16. package/dist/metadata-BUzwE_-u.d.ts +10 -0
  17. package/dist/metadata-CYXgXL_h.d.cts +10 -0
  18. package/dist/{ns-C14w-Zhf.d.cts → ns-DrleaIZQ.d.cts} +3 -1
  19. package/dist/{ns-CTyKJZeF.d.ts → ns-E0TfX9tZ.d.ts} +3 -1
  20. package/dist/ooo1/ns.cjs +9 -0
  21. package/dist/ooo1/ns.d.cts +2 -2
  22. package/dist/ooo1/ns.d.ts +2 -2
  23. package/dist/ooo1/ns.js +8 -1
  24. package/dist/ooo1/properties.cjs +30 -0
  25. package/dist/ooo1/properties.d.cts +6 -2
  26. package/dist/ooo1/properties.d.ts +6 -2
  27. package/dist/ooo1/properties.js +30 -1
  28. package/dist/ooo1/read.cjs +1 -1
  29. package/dist/ooo1/read.d.cts +1 -1
  30. package/dist/ooo1/read.d.ts +1 -1
  31. package/dist/ooo1/read.js +1 -1
  32. package/dist/ooo1/transform.cjs +290 -0
  33. package/dist/ooo1/transform.d.cts +2 -2
  34. package/dist/ooo1/transform.d.ts +2 -2
  35. package/dist/ooo1/transform.js +293 -4
  36. package/dist/ooo1/write.cjs +40 -0
  37. package/dist/ooo1/write.d.cts +2 -0
  38. package/dist/ooo1/write.d.ts +2 -0
  39. package/dist/ooo1/write.js +32 -0
  40. package/dist/package-io/scaffold.cjs +65 -0
  41. package/dist/package-io/scaffold.d.cts +2 -0
  42. package/dist/package-io/scaffold.d.ts +2 -0
  43. package/dist/package-io/scaffold.js +62 -0
  44. package/dist/paragraph-Bf6Iq5wC.d.cts +28 -0
  45. package/dist/paragraph-DtC86tft.d.ts +28 -0
  46. package/dist/{path-CK0dIPgx.d.cts → path-8HQS-J7y.d.cts} +3 -1
  47. package/dist/{path-CK0dIPgx.d.ts → path-8HQS-J7y.d.ts} +3 -1
  48. package/dist/{read-Bo1GBjSE.d.ts → read-A3CJkqVM.d.ts} +3 -1
  49. package/dist/{read-RFqq4ckj.d.cts → read-BgnLFuSi.d.cts} +1 -1
  50. package/dist/{read-3yy5EFV_.d.ts → read-CqaZ01kU.d.ts} +1 -1
  51. package/dist/{read-tpfiT_n4.d.cts → read-fphkvCpR.d.cts} +3 -1
  52. package/dist/{registry-Dajfxsbz.d.ts → registry-C_16-N6i.d.ts} +2 -0
  53. package/dist/{registry-B-ZkdQv1.d.cts → registry-PoQIRgbY.d.cts} +2 -0
  54. package/dist/scaffold-44EIMGll.d.cts +8 -0
  55. package/dist/scaffold-ehGsIpZ5.d.ts +8 -0
  56. package/dist/{shapes-QkOsc-WT.d.ts → shapes-B6Ms7ibr.d.ts} +1 -1
  57. package/dist/{shapes-BCjeY90t.d.cts → shapes-CbBc9t0y.d.cts} +1 -1
  58. package/dist/styles/properties.cjs +1 -1
  59. package/dist/styles/properties.js +2 -2
  60. package/dist/styles/registry.cjs +9 -6
  61. package/dist/styles/registry.d.cts +1 -1
  62. package/dist/styles/registry.d.ts +1 -1
  63. package/dist/styles/registry.js +9 -6
  64. package/dist/table-CECMtPxZ.d.cts +20 -0
  65. package/dist/table-XuniPr2I.d.ts +20 -0
  66. package/dist/text-B8350HA2.d.ts +17 -0
  67. package/dist/text-pmlTqzgi.d.cts +17 -0
  68. package/dist/{transform-SDysw9wx.d.cts → transform-DFCPKX7e.d.cts} +2 -1
  69. package/dist/{transform-DRr76JEu.d.ts → transform-DPliWQuD.d.ts} +2 -1
  70. package/dist/typed/draw/embedded.cjs +1 -1
  71. package/dist/typed/draw/embedded.js +1 -1
  72. package/dist/typed/draw/shapes.cjs +7 -2
  73. package/dist/typed/draw/shapes.d.cts +1 -1
  74. package/dist/typed/draw/shapes.d.ts +1 -1
  75. package/dist/typed/draw/shapes.js +7 -2
  76. package/dist/typed/draw/write-shapes.cjs +210 -0
  77. package/dist/typed/draw/write-shapes.d.cts +2 -0
  78. package/dist/typed/draw/write-shapes.d.ts +2 -0
  79. package/dist/typed/draw/write-shapes.js +203 -0
  80. package/dist/typed/draw/write-vectors.cjs +132 -0
  81. package/dist/typed/draw/write-vectors.d.cts +2 -0
  82. package/dist/typed/draw/write-vectors.d.ts +2 -0
  83. package/dist/typed/draw/write-vectors.js +129 -0
  84. package/dist/typed/odb/form.cjs +1 -1
  85. package/dist/typed/odb/form.js +1 -1
  86. package/dist/typed/odg/write.cjs +80 -0
  87. package/dist/typed/odg/write.d.cts +2 -0
  88. package/dist/typed/odg/write.d.ts +2 -0
  89. package/dist/typed/odg/write.js +77 -0
  90. package/dist/typed/odp/write.cjs +108 -0
  91. package/dist/typed/odp/write.d.cts +2 -0
  92. package/dist/typed/odp/write.d.ts +2 -0
  93. package/dist/typed/odp/write.js +105 -0
  94. package/dist/typed/ods/read.cjs +3 -1
  95. package/dist/typed/ods/read.d.cts +2 -2
  96. package/dist/typed/ods/read.d.ts +2 -2
  97. package/dist/typed/ods/read.js +2 -2
  98. package/dist/typed/ods/write.cjs +578 -0
  99. package/dist/typed/ods/write.d.cts +2 -0
  100. package/dist/typed/ods/write.d.ts +2 -0
  101. package/dist/typed/ods/write.js +575 -0
  102. package/dist/typed/odt/read.cjs +1 -1
  103. package/dist/typed/odt/read.js +1 -1
  104. package/dist/typed/odt/write.cjs +278 -0
  105. package/dist/typed/odt/write.d.cts +2 -0
  106. package/dist/typed/odt/write.d.ts +2 -0
  107. package/dist/typed/odt/write.js +275 -0
  108. package/dist/typed/shared/canonicalise.cjs +126 -0
  109. package/dist/typed/shared/canonicalise.d.cts +10 -0
  110. package/dist/typed/shared/canonicalise.d.ts +10 -0
  111. package/dist/typed/shared/canonicalise.js +120 -0
  112. package/dist/typed/shared/cascade.d.cts +1 -1
  113. package/dist/typed/shared/cascade.d.ts +1 -1
  114. package/dist/typed/shared/list.cjs +81 -0
  115. package/dist/typed/shared/list.d.cts +2 -2
  116. package/dist/typed/shared/list.d.ts +2 -2
  117. package/dist/typed/shared/list.js +75 -1
  118. package/dist/typed/shared/metadata.cjs +41 -0
  119. package/dist/typed/shared/metadata.d.cts +2 -2
  120. package/dist/typed/shared/metadata.d.ts +2 -2
  121. package/dist/typed/shared/metadata.js +41 -2
  122. package/dist/typed/shared/paragraph.cjs +118 -2
  123. package/dist/typed/shared/paragraph.d.cts +2 -2
  124. package/dist/typed/shared/paragraph.d.ts +2 -2
  125. package/dist/typed/shared/paragraph.js +117 -5
  126. package/dist/typed/shared/path.cjs +19 -0
  127. package/dist/typed/shared/path.d.cts +2 -2
  128. package/dist/typed/shared/path.d.ts +2 -2
  129. package/dist/typed/shared/path.js +18 -1
  130. package/dist/typed/shared/table.cjs +84 -0
  131. package/dist/typed/shared/table.d.cts +2 -2
  132. package/dist/typed/shared/table.d.ts +2 -2
  133. package/dist/typed/shared/table.js +84 -4
  134. package/dist/typed/shared/text.cjs +60 -0
  135. package/dist/typed/shared/text.d.cts +2 -2
  136. package/dist/typed/shared/text.d.ts +2 -2
  137. package/dist/typed/shared/text.js +60 -2
  138. package/dist/typed/shared/units.cjs +16 -1
  139. package/dist/typed/shared/units.d.cts +2 -2
  140. package/dist/typed/shared/units.d.ts +2 -2
  141. package/dist/typed/shared/units.js +16 -2
  142. package/dist/{units-BQSNkTQZ.d.cts → units-DdyaQolR.d.cts} +2 -1
  143. package/dist/{units-BQSNkTQZ.d.ts → units-DdyaQolR.d.ts} +2 -1
  144. package/dist/write-4kMi-asu.d.ts +14 -0
  145. package/dist/write-BZXpT8F6.d.cts +17 -0
  146. package/dist/write-BhG3t3fJ.d.cts +14 -0
  147. package/dist/write-BuLQmwLD.d.cts +14 -0
  148. package/dist/write-C2c4xBXs.d.cts +14 -0
  149. package/dist/write-CPATqG4v.d.cts +14 -0
  150. package/dist/write-CfTE2jY8.d.ts +14 -0
  151. package/dist/write-DttX1rTC.d.ts +14 -0
  152. package/dist/write-JERychL3.d.ts +14 -0
  153. package/dist/write-SKnCTU4C.d.ts +17 -0
  154. package/dist/write-shapes-Co7BrmMZ.d.ts +36 -0
  155. package/dist/write-shapes-D4piGKf4.d.cts +36 -0
  156. package/dist/write-vectors-B-RVHAKI.d.cts +11 -0
  157. package/dist/write-vectors-CYjZoVBW.d.ts +11 -0
  158. package/package.json +2 -2
  159. package/dist/list-DwTyo_B2.d.cts +0 -13
  160. package/dist/list-X_GJY7P3.d.ts +0 -13
  161. package/dist/metadata-01SgHkRR.d.cts +0 -7
  162. package/dist/metadata-D1SOBTh8.d.ts +0 -7
  163. package/dist/paragraph-ByTzS8Li.d.ts +0 -18
  164. package/dist/paragraph-CVULactG.d.cts +0 -18
  165. package/dist/table-CYvFMlP6.d.cts +0 -14
  166. package/dist/table-DclDgC5h.d.ts +0 -14
  167. package/dist/text-Bn3C7lnm.d.ts +0 -10
  168. package/dist/text-CDUCcwje.d.cts +0 -10
@@ -0,0 +1,278 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_media_type = require("../../media-type.cjs");
3
+ const require_xml_fragment = require("../../xml/fragment.cjs");
4
+ const require_xml_entities = require("../../xml/entities.cjs");
5
+ const require_manifest = require("../../manifest.cjs");
6
+ const require_typed_shared_units = require("../shared/units.cjs");
7
+ const require_styles_registry = require("../../styles/registry.cjs");
8
+ const require_typed_shared_metadata = require("../shared/metadata.cjs");
9
+ const require_typed_shared_list = require("../shared/list.cjs");
10
+ const require_typed_shared_paragraph = require("../shared/paragraph.cjs");
11
+ const require_typed_shared_table = require("../shared/table.cjs");
12
+ const require_package_io_scaffold = require("../../package-io/scaffold.cjs");
13
+ const require_typed_shared_canonicalise = require("../shared/canonicalise.cjs");
14
+ let document_schema_js = require("document-schema.js");
15
+ //#region src/typed/odt/write.ts
16
+ const CONTENT_PART = "content.xml";
17
+ const STYLES_PART = "styles.xml";
18
+ const PICTURES_DIRECTORY = "Pictures";
19
+ function unsupported(what, where) {
20
+ return /* @__PURE__ */ new Error(`writeOdt: ${where} carries ${what}, which this writer does not write yet -- refusing rather than producing an .odt that silently lost it. See ExaDev/documents.js for the tracked follow-up covering the fidelity constructs and embedded objects.`);
21
+ }
22
+ function assertWritableParagraph(paragraph) {
23
+ if (paragraph.constructs !== void 0 && paragraph.constructs.length > 0) throw unsupported("run-level construct extents (a field, bookmark, note, annotation, or tracked change)", "a paragraph");
24
+ }
25
+ function assertWritableBlock(block) {
26
+ if (block.kind === "constructStart" || block.kind === "constructEnd") throw unsupported("a construct boundary marker", "a section's block flow");
27
+ if (block.kind === "embeddedObject") throw unsupported("an embedded object", "a section's block flow");
28
+ if (block.kind === "paragraph") assertWritableParagraph(block);
29
+ }
30
+ function emptyAnchorParagraph(pageBreakBefore) {
31
+ return pageBreakBefore ? {
32
+ kind: "paragraph",
33
+ runs: [],
34
+ pageBreakBefore: true
35
+ } : {
36
+ kind: "paragraph",
37
+ runs: []
38
+ };
39
+ }
40
+ function planSection(section, needsLeadingParagraph, listState) {
41
+ const blocks = [];
42
+ let pendingPageBreak = false;
43
+ const pushParagraph = (paragraph) => {
44
+ blocks.push({
45
+ kind: "paragraph",
46
+ paragraph
47
+ });
48
+ };
49
+ const hasPlannedParagraph = () => {
50
+ for (let index = blocks.length - 1; index >= 0; index -= 1) if (blocks[index].kind === "paragraph") return true;
51
+ return false;
52
+ };
53
+ const closeListRun = () => {
54
+ require_typed_shared_list.closeListPlan(listState);
55
+ };
56
+ const flushPendingPageBreak = () => {
57
+ if (pendingPageBreak) {
58
+ pushParagraph(emptyAnchorParagraph(true));
59
+ closeListRun();
60
+ pendingPageBreak = false;
61
+ }
62
+ };
63
+ if (needsLeadingParagraph) {
64
+ if (section.blocks.find((block) => block.kind !== "constructStart" && block.kind !== "constructEnd")?.kind !== "paragraph") pushParagraph(emptyAnchorParagraph(false));
65
+ }
66
+ for (const block of section.blocks) {
67
+ assertWritableBlock(block);
68
+ if (block.kind === "pageBreak") {
69
+ flushPendingPageBreak();
70
+ pendingPageBreak = true;
71
+ continue;
72
+ }
73
+ if (block.kind === "paragraph") {
74
+ const canonicalId = require_typed_shared_list.planListMembership(block.list, listState);
75
+ const paragraph = require_typed_shared_canonicalise.canonicalParagraph(block, canonicalId);
76
+ pushParagraph(pendingPageBreak ? {
77
+ ...paragraph,
78
+ pageBreakBefore: true
79
+ } : paragraph);
80
+ pendingPageBreak = false;
81
+ continue;
82
+ }
83
+ if (block.kind === "table") {
84
+ flushPendingPageBreak();
85
+ closeListRun();
86
+ blocks.push({
87
+ kind: "table",
88
+ table: block
89
+ });
90
+ continue;
91
+ }
92
+ flushPendingPageBreak();
93
+ if (!hasPlannedParagraph()) pushParagraph(emptyAnchorParagraph(false));
94
+ blocks.push({
95
+ kind: "image",
96
+ image: block
97
+ });
98
+ }
99
+ flushPendingPageBreak();
100
+ return {
101
+ pageSize: section.pageSize,
102
+ margins: section.margins,
103
+ blocks
104
+ };
105
+ }
106
+ function planDocument(sections) {
107
+ if (sections.length === 0) throw new Error("writeOdt: a wordprocessing document with no sections has no page geometry to write -- an .odt always carries at least one page style, and inventing one would report back a section the document never had");
108
+ const listState = { next: 1 };
109
+ return sections.map((section, index) => planSection(section, index > 0, listState));
110
+ }
111
+ function normaliseOdtContent(document) {
112
+ if (document.kind !== "wordprocessing") throw new Error(`normaliseOdtContent: expected a 'wordprocessing' document, got '${document.kind}'`);
113
+ const planned = planDocument(document.sections);
114
+ return {
115
+ kind: "wordprocessing",
116
+ metadata: require_typed_shared_canonicalise.canonicalMetadata(document.metadata),
117
+ sections: planned.map((section, index) => {
118
+ const blocks = section.blocks.map((block) => {
119
+ switch (block.kind) {
120
+ case "paragraph": return block.paragraph;
121
+ case "table": return require_typed_shared_canonicalise.canonicalTable(block.table);
122
+ case "image": return require_typed_shared_canonicalise.canonicalImage(block.image);
123
+ }
124
+ });
125
+ return index === 0 ? {
126
+ pageSize: section.pageSize,
127
+ margins: section.margins,
128
+ blocks
129
+ } : {
130
+ pageSize: section.pageSize,
131
+ margins: section.margins,
132
+ blocks,
133
+ breakType: "nextPage"
134
+ };
135
+ })
136
+ };
137
+ }
138
+ function pageLayoutElement(name, pageSize, margins) {
139
+ return require_xml_fragment.el("style:page-layout", { "style:name": require_xml_entities.encodeXmlText(name) }, [require_xml_fragment.el("style:page-layout-properties", {
140
+ "fo:page-width": require_typed_shared_units.formatOdfLength(pageSize.widthPt),
141
+ "fo:page-height": require_typed_shared_units.formatOdfLength(pageSize.heightPt),
142
+ "style:print-orientation": pageSize.widthPt > pageSize.heightPt ? "landscape" : "portrait",
143
+ "fo:margin-top": require_typed_shared_units.formatOdfLength(margins.topPt),
144
+ "fo:margin-right": require_typed_shared_units.formatOdfLength(margins.rightPt),
145
+ "fo:margin-bottom": require_typed_shared_units.formatOdfLength(margins.bottomPt),
146
+ "fo:margin-left": require_typed_shared_units.formatOdfLength(margins.leftPt)
147
+ })]);
148
+ }
149
+ function sectionBreakStyleElement(name, masterPageName) {
150
+ return require_xml_fragment.el("style:style", {
151
+ "style:name": require_xml_entities.encodeXmlText(name),
152
+ "style:family": "paragraph",
153
+ "style:master-page-name": require_xml_entities.encodeXmlText(masterPageName)
154
+ });
155
+ }
156
+ function listStyleNameFor(kind, state) {
157
+ const existing = state.listStyleByKind.get(kind);
158
+ if (existing !== void 0) return existing;
159
+ const name = `L${state.nextListStyle}`;
160
+ state.nextListStyle += 1;
161
+ state.listStyleByKind.set(kind, name);
162
+ state.contentAutomaticStyles.children.push(require_typed_shared_list.buildOdfListStyle(name, kind));
163
+ return name;
164
+ }
165
+ function writeImageFrame(image, state) {
166
+ const extension = image.format === "png" ? "png" : "jpg";
167
+ const path = `${PICTURES_DIRECTORY}/image${state.nextImage}.${extension}`;
168
+ state.nextImage += 1;
169
+ state.pkg.parts[path] = {
170
+ kind: "binary",
171
+ base64: image.base64
172
+ };
173
+ const children = [require_xml_fragment.el("draw:image", {
174
+ "xlink:href": require_xml_entities.encodeXmlText(path),
175
+ "xlink:type": "simple",
176
+ "xlink:show": "embed",
177
+ "xlink:actuate": "onLoad"
178
+ })];
179
+ if (image.altText !== void 0) children.push(require_xml_fragment.el("svg:title", {}, [require_xml_fragment.txt(require_xml_entities.encodeXmlText(image.altText))]));
180
+ return require_xml_fragment.el("draw:frame", {
181
+ "text:anchor-type": "as-char",
182
+ "svg:width": require_typed_shared_units.formatOdfLength(image.widthPt),
183
+ "svg:height": require_typed_shared_units.formatOdfLength(image.heightPt)
184
+ }, children);
185
+ }
186
+ function writeSectionBlocks(section, parentStyleName, state, out) {
187
+ let anchorParagraph;
188
+ let openList;
189
+ const closeList = () => {
190
+ if (openList === void 0) return;
191
+ const kind = require_typed_shared_list.listKindOf(openList.numId);
192
+ const built = require_typed_shared_list.writeOdfList(openList.entries, kind === void 0 ? void 0 : listStyleNameFor(kind, state));
193
+ openList.element.attributes = built.attributes;
194
+ openList.element.children = built.children;
195
+ openList = void 0;
196
+ };
197
+ for (const [index, block] of section.blocks.entries()) {
198
+ if (block.kind === "paragraph") {
199
+ const paragraph = block.paragraph;
200
+ const element = require_typed_shared_paragraph.writeOdfParagraph(paragraph, state.registry, { ...index === 0 && parentStyleName !== void 0 ? { parentStyleName } : {} });
201
+ anchorParagraph = element;
202
+ const membership = paragraph.list;
203
+ if (membership?.numId === void 0) {
204
+ closeList();
205
+ out.push(element);
206
+ continue;
207
+ }
208
+ if (openList !== void 0 && openList.numId !== membership.numId) closeList();
209
+ if (openList === void 0) {
210
+ const listElement = require_xml_fragment.el("text:list");
211
+ openList = {
212
+ numId: membership.numId,
213
+ entries: [],
214
+ element: listElement
215
+ };
216
+ out.push(listElement);
217
+ }
218
+ openList.entries.push({
219
+ level: membership.level,
220
+ element
221
+ });
222
+ continue;
223
+ }
224
+ if (block.kind === "table") {
225
+ closeList();
226
+ anchorParagraph = void 0;
227
+ out.push(require_typed_shared_table.writeOdfTable(block.table, state.registry, `Table${state.nextTable}`));
228
+ state.nextTable += 1;
229
+ continue;
230
+ }
231
+ if (anchorParagraph === void 0) throw new Error("writeOdt: internal error -- an image block reached the writer with no anchor paragraph before it, which planSection is supposed to guarantee");
232
+ anchorParagraph.children.push(writeImageFrame(block.image, state));
233
+ }
234
+ closeList();
235
+ }
236
+ function writeOdtContent(document, options = {}) {
237
+ if (document.kind !== "wordprocessing") throw new Error(`writeOdtContent: expected a 'wordprocessing' document, got '${document.kind}' -- odf.js writes .odt from the wordprocessing arm only`);
238
+ const version = options.version ?? "1.3";
239
+ const textElement = require_xml_fragment.el("office:text");
240
+ const pkg = require_package_io_scaffold.createOdfPackage(options.template ? require_media_type.ODF_MEDIA_TYPES.ott : require_media_type.ODF_MEDIA_TYPES.odt, textElement, version);
241
+ const state = {
242
+ pkg,
243
+ registry: require_styles_registry.StyleRegistry.forPart(pkg, CONTENT_PART, { otherPart: {
244
+ pkg,
245
+ partPath: STYLES_PART
246
+ } }),
247
+ contentAutomaticStyles: require_package_io_scaffold.odfPartContainer(pkg, CONTENT_PART, "office:automatic-styles"),
248
+ stylesNamedStyles: require_package_io_scaffold.odfPartContainer(pkg, STYLES_PART, "office:styles"),
249
+ stylesAutomaticStyles: require_package_io_scaffold.odfPartContainer(pkg, STYLES_PART, "office:automatic-styles"),
250
+ masterStyles: require_package_io_scaffold.odfPartContainer(pkg, STYLES_PART, "office:master-styles"),
251
+ nextTable: 1,
252
+ nextImage: 1,
253
+ nextListStyle: 1,
254
+ listStyleByKind: /* @__PURE__ */ new Map()
255
+ };
256
+ const planned = planDocument(document.sections);
257
+ for (const [index, section] of planned.entries()) {
258
+ const masterPageName = `MP${index + 1}`;
259
+ const pageLayoutName = `PM${index + 1}`;
260
+ state.stylesAutomaticStyles.children.push(pageLayoutElement(pageLayoutName, section.pageSize, section.margins));
261
+ state.masterStyles.children.push(require_xml_fragment.el("style:master-page", {
262
+ "style:name": require_xml_entities.encodeXmlText(masterPageName),
263
+ "style:page-layout-name": require_xml_entities.encodeXmlText(pageLayoutName)
264
+ }));
265
+ if (index > 0) state.stylesNamedStyles.children.push(sectionBreakStyleElement(`${masterPageName}Start`, masterPageName));
266
+ }
267
+ for (const [index, section] of planned.entries()) writeSectionBlocks(section, index === 0 ? void 0 : `MP${index + 1}Start`, state, textElement.children);
268
+ require_typed_shared_metadata.writeOdfMetadata(pkg, document.metadata, version);
269
+ require_manifest.syncManifest(pkg, { version });
270
+ return pkg;
271
+ }
272
+ function writeOdt(document, options = {}) {
273
+ return writeOdtContent((0, document_schema_js.flattenTree)(document), options);
274
+ }
275
+ //#endregion
276
+ exports.normaliseOdtContent = normaliseOdtContent;
277
+ exports.writeOdt = writeOdt;
278
+ exports.writeOdtContent = writeOdtContent;
@@ -0,0 +1,2 @@
1
+ import { i as writeOdtContent, n as normaliseOdtContent, r as writeOdt, t as OdtWriteOptions } from "../../write-CPATqG4v.cjs";
2
+ export { OdtWriteOptions, normaliseOdtContent, writeOdt, writeOdtContent };
@@ -0,0 +1,2 @@
1
+ import { i as writeOdtContent, n as normaliseOdtContent, r as writeOdt, t as OdtWriteOptions } from "../../write-JERychL3.js";
2
+ export { OdtWriteOptions, normaliseOdtContent, writeOdt, writeOdtContent };
@@ -0,0 +1,275 @@
1
+ import { ODF_MEDIA_TYPES } from "../../media-type.js";
2
+ import { el, txt } from "../../xml/fragment.js";
3
+ import { encodeXmlText } from "../../xml/entities.js";
4
+ import { syncManifest } from "../../manifest.js";
5
+ import { formatOdfLength } from "../shared/units.js";
6
+ import { StyleRegistry } from "../../styles/registry.js";
7
+ import { writeOdfMetadata } from "../shared/metadata.js";
8
+ import { buildOdfListStyle, closeListPlan, listKindOf, planListMembership, writeOdfList } from "../shared/list.js";
9
+ import { writeOdfParagraph } from "../shared/paragraph.js";
10
+ import { writeOdfTable } from "../shared/table.js";
11
+ import { createOdfPackage, odfPartContainer } from "../../package-io/scaffold.js";
12
+ import { canonicalImage, canonicalMetadata, canonicalParagraph, canonicalTable } from "../shared/canonicalise.js";
13
+ import { flattenTree } from "document-schema.js";
14
+ //#region src/typed/odt/write.ts
15
+ const CONTENT_PART = "content.xml";
16
+ const STYLES_PART = "styles.xml";
17
+ const PICTURES_DIRECTORY = "Pictures";
18
+ function unsupported(what, where) {
19
+ return /* @__PURE__ */ new Error(`writeOdt: ${where} carries ${what}, which this writer does not write yet -- refusing rather than producing an .odt that silently lost it. See ExaDev/documents.js for the tracked follow-up covering the fidelity constructs and embedded objects.`);
20
+ }
21
+ function assertWritableParagraph(paragraph) {
22
+ if (paragraph.constructs !== void 0 && paragraph.constructs.length > 0) throw unsupported("run-level construct extents (a field, bookmark, note, annotation, or tracked change)", "a paragraph");
23
+ }
24
+ function assertWritableBlock(block) {
25
+ if (block.kind === "constructStart" || block.kind === "constructEnd") throw unsupported("a construct boundary marker", "a section's block flow");
26
+ if (block.kind === "embeddedObject") throw unsupported("an embedded object", "a section's block flow");
27
+ if (block.kind === "paragraph") assertWritableParagraph(block);
28
+ }
29
+ function emptyAnchorParagraph(pageBreakBefore) {
30
+ return pageBreakBefore ? {
31
+ kind: "paragraph",
32
+ runs: [],
33
+ pageBreakBefore: true
34
+ } : {
35
+ kind: "paragraph",
36
+ runs: []
37
+ };
38
+ }
39
+ function planSection(section, needsLeadingParagraph, listState) {
40
+ const blocks = [];
41
+ let pendingPageBreak = false;
42
+ const pushParagraph = (paragraph) => {
43
+ blocks.push({
44
+ kind: "paragraph",
45
+ paragraph
46
+ });
47
+ };
48
+ const hasPlannedParagraph = () => {
49
+ for (let index = blocks.length - 1; index >= 0; index -= 1) if (blocks[index].kind === "paragraph") return true;
50
+ return false;
51
+ };
52
+ const closeListRun = () => {
53
+ closeListPlan(listState);
54
+ };
55
+ const flushPendingPageBreak = () => {
56
+ if (pendingPageBreak) {
57
+ pushParagraph(emptyAnchorParagraph(true));
58
+ closeListRun();
59
+ pendingPageBreak = false;
60
+ }
61
+ };
62
+ if (needsLeadingParagraph) {
63
+ if (section.blocks.find((block) => block.kind !== "constructStart" && block.kind !== "constructEnd")?.kind !== "paragraph") pushParagraph(emptyAnchorParagraph(false));
64
+ }
65
+ for (const block of section.blocks) {
66
+ assertWritableBlock(block);
67
+ if (block.kind === "pageBreak") {
68
+ flushPendingPageBreak();
69
+ pendingPageBreak = true;
70
+ continue;
71
+ }
72
+ if (block.kind === "paragraph") {
73
+ const canonicalId = planListMembership(block.list, listState);
74
+ const paragraph = canonicalParagraph(block, canonicalId);
75
+ pushParagraph(pendingPageBreak ? {
76
+ ...paragraph,
77
+ pageBreakBefore: true
78
+ } : paragraph);
79
+ pendingPageBreak = false;
80
+ continue;
81
+ }
82
+ if (block.kind === "table") {
83
+ flushPendingPageBreak();
84
+ closeListRun();
85
+ blocks.push({
86
+ kind: "table",
87
+ table: block
88
+ });
89
+ continue;
90
+ }
91
+ flushPendingPageBreak();
92
+ if (!hasPlannedParagraph()) pushParagraph(emptyAnchorParagraph(false));
93
+ blocks.push({
94
+ kind: "image",
95
+ image: block
96
+ });
97
+ }
98
+ flushPendingPageBreak();
99
+ return {
100
+ pageSize: section.pageSize,
101
+ margins: section.margins,
102
+ blocks
103
+ };
104
+ }
105
+ function planDocument(sections) {
106
+ if (sections.length === 0) throw new Error("writeOdt: a wordprocessing document with no sections has no page geometry to write -- an .odt always carries at least one page style, and inventing one would report back a section the document never had");
107
+ const listState = { next: 1 };
108
+ return sections.map((section, index) => planSection(section, index > 0, listState));
109
+ }
110
+ function normaliseOdtContent(document) {
111
+ if (document.kind !== "wordprocessing") throw new Error(`normaliseOdtContent: expected a 'wordprocessing' document, got '${document.kind}'`);
112
+ const planned = planDocument(document.sections);
113
+ return {
114
+ kind: "wordprocessing",
115
+ metadata: canonicalMetadata(document.metadata),
116
+ sections: planned.map((section, index) => {
117
+ const blocks = section.blocks.map((block) => {
118
+ switch (block.kind) {
119
+ case "paragraph": return block.paragraph;
120
+ case "table": return canonicalTable(block.table);
121
+ case "image": return canonicalImage(block.image);
122
+ }
123
+ });
124
+ return index === 0 ? {
125
+ pageSize: section.pageSize,
126
+ margins: section.margins,
127
+ blocks
128
+ } : {
129
+ pageSize: section.pageSize,
130
+ margins: section.margins,
131
+ blocks,
132
+ breakType: "nextPage"
133
+ };
134
+ })
135
+ };
136
+ }
137
+ function pageLayoutElement(name, pageSize, margins) {
138
+ return el("style:page-layout", { "style:name": encodeXmlText(name) }, [el("style:page-layout-properties", {
139
+ "fo:page-width": formatOdfLength(pageSize.widthPt),
140
+ "fo:page-height": formatOdfLength(pageSize.heightPt),
141
+ "style:print-orientation": pageSize.widthPt > pageSize.heightPt ? "landscape" : "portrait",
142
+ "fo:margin-top": formatOdfLength(margins.topPt),
143
+ "fo:margin-right": formatOdfLength(margins.rightPt),
144
+ "fo:margin-bottom": formatOdfLength(margins.bottomPt),
145
+ "fo:margin-left": formatOdfLength(margins.leftPt)
146
+ })]);
147
+ }
148
+ function sectionBreakStyleElement(name, masterPageName) {
149
+ return el("style:style", {
150
+ "style:name": encodeXmlText(name),
151
+ "style:family": "paragraph",
152
+ "style:master-page-name": encodeXmlText(masterPageName)
153
+ });
154
+ }
155
+ function listStyleNameFor(kind, state) {
156
+ const existing = state.listStyleByKind.get(kind);
157
+ if (existing !== void 0) return existing;
158
+ const name = `L${state.nextListStyle}`;
159
+ state.nextListStyle += 1;
160
+ state.listStyleByKind.set(kind, name);
161
+ state.contentAutomaticStyles.children.push(buildOdfListStyle(name, kind));
162
+ return name;
163
+ }
164
+ function writeImageFrame(image, state) {
165
+ const extension = image.format === "png" ? "png" : "jpg";
166
+ const path = `${PICTURES_DIRECTORY}/image${state.nextImage}.${extension}`;
167
+ state.nextImage += 1;
168
+ state.pkg.parts[path] = {
169
+ kind: "binary",
170
+ base64: image.base64
171
+ };
172
+ const children = [el("draw:image", {
173
+ "xlink:href": encodeXmlText(path),
174
+ "xlink:type": "simple",
175
+ "xlink:show": "embed",
176
+ "xlink:actuate": "onLoad"
177
+ })];
178
+ if (image.altText !== void 0) children.push(el("svg:title", {}, [txt(encodeXmlText(image.altText))]));
179
+ return el("draw:frame", {
180
+ "text:anchor-type": "as-char",
181
+ "svg:width": formatOdfLength(image.widthPt),
182
+ "svg:height": formatOdfLength(image.heightPt)
183
+ }, children);
184
+ }
185
+ function writeSectionBlocks(section, parentStyleName, state, out) {
186
+ let anchorParagraph;
187
+ let openList;
188
+ const closeList = () => {
189
+ if (openList === void 0) return;
190
+ const kind = listKindOf(openList.numId);
191
+ const built = writeOdfList(openList.entries, kind === void 0 ? void 0 : listStyleNameFor(kind, state));
192
+ openList.element.attributes = built.attributes;
193
+ openList.element.children = built.children;
194
+ openList = void 0;
195
+ };
196
+ for (const [index, block] of section.blocks.entries()) {
197
+ if (block.kind === "paragraph") {
198
+ const paragraph = block.paragraph;
199
+ const element = writeOdfParagraph(paragraph, state.registry, { ...index === 0 && parentStyleName !== void 0 ? { parentStyleName } : {} });
200
+ anchorParagraph = element;
201
+ const membership = paragraph.list;
202
+ if (membership?.numId === void 0) {
203
+ closeList();
204
+ out.push(element);
205
+ continue;
206
+ }
207
+ if (openList !== void 0 && openList.numId !== membership.numId) closeList();
208
+ if (openList === void 0) {
209
+ const listElement = el("text:list");
210
+ openList = {
211
+ numId: membership.numId,
212
+ entries: [],
213
+ element: listElement
214
+ };
215
+ out.push(listElement);
216
+ }
217
+ openList.entries.push({
218
+ level: membership.level,
219
+ element
220
+ });
221
+ continue;
222
+ }
223
+ if (block.kind === "table") {
224
+ closeList();
225
+ anchorParagraph = void 0;
226
+ out.push(writeOdfTable(block.table, state.registry, `Table${state.nextTable}`));
227
+ state.nextTable += 1;
228
+ continue;
229
+ }
230
+ if (anchorParagraph === void 0) throw new Error("writeOdt: internal error -- an image block reached the writer with no anchor paragraph before it, which planSection is supposed to guarantee");
231
+ anchorParagraph.children.push(writeImageFrame(block.image, state));
232
+ }
233
+ closeList();
234
+ }
235
+ function writeOdtContent(document, options = {}) {
236
+ if (document.kind !== "wordprocessing") throw new Error(`writeOdtContent: expected a 'wordprocessing' document, got '${document.kind}' -- odf.js writes .odt from the wordprocessing arm only`);
237
+ const version = options.version ?? "1.3";
238
+ const textElement = el("office:text");
239
+ const pkg = createOdfPackage(options.template ? ODF_MEDIA_TYPES.ott : ODF_MEDIA_TYPES.odt, textElement, version);
240
+ const state = {
241
+ pkg,
242
+ registry: StyleRegistry.forPart(pkg, CONTENT_PART, { otherPart: {
243
+ pkg,
244
+ partPath: STYLES_PART
245
+ } }),
246
+ contentAutomaticStyles: odfPartContainer(pkg, CONTENT_PART, "office:automatic-styles"),
247
+ stylesNamedStyles: odfPartContainer(pkg, STYLES_PART, "office:styles"),
248
+ stylesAutomaticStyles: odfPartContainer(pkg, STYLES_PART, "office:automatic-styles"),
249
+ masterStyles: odfPartContainer(pkg, STYLES_PART, "office:master-styles"),
250
+ nextTable: 1,
251
+ nextImage: 1,
252
+ nextListStyle: 1,
253
+ listStyleByKind: /* @__PURE__ */ new Map()
254
+ };
255
+ const planned = planDocument(document.sections);
256
+ for (const [index, section] of planned.entries()) {
257
+ const masterPageName = `MP${index + 1}`;
258
+ const pageLayoutName = `PM${index + 1}`;
259
+ state.stylesAutomaticStyles.children.push(pageLayoutElement(pageLayoutName, section.pageSize, section.margins));
260
+ state.masterStyles.children.push(el("style:master-page", {
261
+ "style:name": encodeXmlText(masterPageName),
262
+ "style:page-layout-name": encodeXmlText(pageLayoutName)
263
+ }));
264
+ if (index > 0) state.stylesNamedStyles.children.push(sectionBreakStyleElement(`${masterPageName}Start`, masterPageName));
265
+ }
266
+ for (const [index, section] of planned.entries()) writeSectionBlocks(section, index === 0 ? void 0 : `MP${index + 1}Start`, state, textElement.children);
267
+ writeOdfMetadata(pkg, document.metadata, version);
268
+ syncManifest(pkg, { version });
269
+ return pkg;
270
+ }
271
+ function writeOdt(document, options = {}) {
272
+ return writeOdtContent(flattenTree(document), options);
273
+ }
274
+ //#endregion
275
+ export { normaliseOdtContent, writeOdt, writeOdtContent };
@@ -0,0 +1,126 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_typed_shared_paragraph = require("./paragraph.cjs");
3
+ let document_schema_js = require("document-schema.js");
4
+ //#region src/typed/shared/canonicalise.ts
5
+ function unsupportedContent(what, where) {
6
+ return /* @__PURE__ */ new Error(`${where} carries ${what}, which no ODF writer in this package can produce yet -- refusing to state a canonical form for content that would be silently lost on write. See ExaDev/documents.js for the tracked follow-up covering the fidelity constructs and embedded objects.`);
7
+ }
8
+ function canonicalColor(color) {
9
+ return (0, document_schema_js.rgbHexToColor)((0, document_schema_js.colorToRgbHex)(color));
10
+ }
11
+ function canonicalRun(run) {
12
+ const canonical = { text: run.text };
13
+ if (run.bold !== void 0) canonical.bold = run.bold;
14
+ if (run.italic !== void 0) canonical.italic = run.italic;
15
+ if (run.underline !== void 0) canonical.underline = run.underline;
16
+ if (run.strike !== void 0) canonical.strike = run.strike;
17
+ if (run.fontFamily !== void 0) canonical.fontFamily = run.fontFamily;
18
+ if (run.sizePt !== void 0) canonical.sizePt = run.sizePt;
19
+ if (run.color !== void 0) canonical.color = canonicalColor(run.color);
20
+ if (run.hyperlink !== void 0) canonical.hyperlink = run.hyperlink;
21
+ return canonical;
22
+ }
23
+ function canonicalParagraph(paragraph, listNumId) {
24
+ if (paragraph.constructs !== void 0 && paragraph.constructs.length > 0) throw unsupportedContent("run-level construct extents (a field, bookmark, note, annotation, or tracked change)", "a paragraph");
25
+ const canonical = {
26
+ kind: "paragraph",
27
+ runs: require_typed_shared_paragraph.segmentOdfParagraphRuns(paragraph.runs).map(canonicalRun)
28
+ };
29
+ if (paragraph.headingLevel !== void 0) {
30
+ canonical.headingLevel = paragraph.headingLevel;
31
+ canonical.styleId = `Heading${paragraph.headingLevel}`;
32
+ }
33
+ if (paragraph.alignment !== void 0) canonical.alignment = paragraph.alignment;
34
+ if (listNumId !== void 0 && paragraph.list !== void 0) canonical.list = {
35
+ numId: listNumId,
36
+ level: paragraph.list.level
37
+ };
38
+ if (paragraph.spacingBeforePt !== void 0) canonical.spacingBeforePt = paragraph.spacingBeforePt;
39
+ if (paragraph.spacingAfterPt !== void 0) canonical.spacingAfterPt = paragraph.spacingAfterPt;
40
+ if (paragraph.lineSpacing !== void 0) canonical.lineSpacing = paragraph.lineSpacing;
41
+ if (paragraph.indentLeftPt !== void 0) canonical.indentLeftPt = paragraph.indentLeftPt;
42
+ if (paragraph.indentFirstLinePt !== void 0) canonical.indentFirstLinePt = paragraph.indentFirstLinePt;
43
+ if (paragraph.pageBreakBefore !== void 0) canonical.pageBreakBefore = paragraph.pageBreakBefore;
44
+ if (paragraph.pageBreakAfter !== void 0) canonical.pageBreakAfter = paragraph.pageBreakAfter;
45
+ return canonical;
46
+ }
47
+ function canonicalCell(cell, covered) {
48
+ if (covered) return { blocks: [] };
49
+ const canonical = { blocks: cell.blocks.map((block) => {
50
+ if (block.kind !== "paragraph") throw unsupportedContent(`a "${block.kind}" block`, "a table cell");
51
+ return canonicalParagraph(block, void 0);
52
+ }) };
53
+ if (cell.colSpan !== void 0) canonical.colSpan = cell.colSpan;
54
+ if (cell.rowSpan !== void 0) canonical.rowSpan = cell.rowSpan;
55
+ if (cell.background !== void 0) canonical.background = canonicalColor(cell.background);
56
+ if (cell.borders !== void 0) {
57
+ const borders = {};
58
+ for (const edge of [
59
+ "left",
60
+ "right",
61
+ "top",
62
+ "bottom"
63
+ ]) {
64
+ const border = cell.borders[edge];
65
+ if (border !== void 0) borders[edge] = {
66
+ color: canonicalColor(border.color),
67
+ widthPt: border.widthPt,
68
+ style: border.style ?? "solid"
69
+ };
70
+ }
71
+ canonical.borders = borders;
72
+ }
73
+ return canonical;
74
+ }
75
+ function canonicalTable(table) {
76
+ const covered = /* @__PURE__ */ new Set();
77
+ return {
78
+ kind: "table",
79
+ columnWidthsPt: [...table.columnWidthsPt],
80
+ rows: table.rows.map((row, rowIndex) => {
81
+ const cells = row.cells.map((cell, columnIndex) => {
82
+ const key = `${rowIndex},${columnIndex}`;
83
+ const isCovered = covered.has(key);
84
+ if (!isCovered) {
85
+ const colSpan = cell.colSpan ?? 1;
86
+ const rowSpan = cell.rowSpan ?? 1;
87
+ for (let r = rowIndex; r < rowIndex + rowSpan; r += 1) for (let c = columnIndex; c < columnIndex + colSpan; c += 1) if (r !== rowIndex || c !== columnIndex) covered.add(`${r},${c}`);
88
+ }
89
+ return canonicalCell(cell, isCovered);
90
+ });
91
+ return row.heightPt === void 0 ? { cells } : {
92
+ cells,
93
+ heightPt: row.heightPt
94
+ };
95
+ })
96
+ };
97
+ }
98
+ function canonicalMetadata(metadata) {
99
+ const canonical = {};
100
+ if (metadata.title !== void 0) canonical.title = metadata.title;
101
+ if (metadata.author !== void 0) canonical.author = metadata.author;
102
+ if (metadata.subject !== void 0) canonical.subject = metadata.subject;
103
+ if (metadata.keywords !== void 0 && metadata.keywords.length > 0) canonical.keywords = [...metadata.keywords];
104
+ if (metadata.creator !== void 0) canonical.creator = metadata.creator;
105
+ if (metadata.createdIso !== void 0) canonical.createdIso = metadata.createdIso;
106
+ if (metadata.modifiedIso !== void 0) canonical.modifiedIso = metadata.modifiedIso;
107
+ return canonical;
108
+ }
109
+ function canonicalImage(image) {
110
+ const canonical = {
111
+ kind: "image",
112
+ format: image.format,
113
+ base64: image.base64,
114
+ widthPt: image.widthPt,
115
+ heightPt: image.heightPt
116
+ };
117
+ if (image.altText !== void 0) canonical.altText = image.altText;
118
+ return canonical;
119
+ }
120
+ //#endregion
121
+ exports.canonicalColor = canonicalColor;
122
+ exports.canonicalImage = canonicalImage;
123
+ exports.canonicalMetadata = canonicalMetadata;
124
+ exports.canonicalParagraph = canonicalParagraph;
125
+ exports.canonicalRun = canonicalRun;
126
+ exports.canonicalTable = canonicalTable;