@office-kit/xlsx 0.8.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 (220) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +319 -0
  3. package/THIRD_PARTY_NOTICES.md +56 -0
  4. package/dist/cell/cell.d.ts +234 -0
  5. package/dist/cell/index.d.ts +4 -0
  6. package/dist/cell/rich-text.d.ts +37 -0
  7. package/dist/cell-D9CaNKnU.mjs +320 -0
  8. package/dist/cell-D9CaNKnU.mjs.map +1 -0
  9. package/dist/cell-style-BEDjMX1y.mjs +1579 -0
  10. package/dist/cell-style-BEDjMX1y.mjs.map +1 -0
  11. package/dist/cell.mjs +2 -0
  12. package/dist/chart/chart-xml.d.ts +16 -0
  13. package/dist/chart/chart.d.ts +735 -0
  14. package/dist/chart/cx/chartex-xml.d.ts +6 -0
  15. package/dist/chart/cx/chartex.d.ts +279 -0
  16. package/dist/chart/index.d.ts +6 -0
  17. package/dist/chart/user-shapes-xml.d.ts +4 -0
  18. package/dist/chart/user-shapes.d.ts +61 -0
  19. package/dist/chart.mjs +232 -0
  20. package/dist/chart.mjs.map +1 -0
  21. package/dist/chartsheet/chartsheet-xml.d.ts +17 -0
  22. package/dist/chartsheet/chartsheet.d.ts +121 -0
  23. package/dist/chartsheet/index.d.ts +2 -0
  24. package/dist/chartsheet-C3-tqkPy.mjs +23 -0
  25. package/dist/chartsheet-C3-tqkPy.mjs.map +1 -0
  26. package/dist/chartsheet.mjs +2 -0
  27. package/dist/colors-ovWAwnZI.mjs +67 -0
  28. package/dist/colors-ovWAwnZI.mjs.map +1 -0
  29. package/dist/compat/numbers.d.ts +14 -0
  30. package/dist/coordinate-96Ecci4d.mjs +276 -0
  31. package/dist/coordinate-96Ecci4d.mjs.map +1 -0
  32. package/dist/datetime-B2ySVlXt.mjs +71 -0
  33. package/dist/datetime-B2ySVlXt.mjs.map +1 -0
  34. package/dist/defined-names-CviWmtQg.mjs +89 -0
  35. package/dist/defined-names-CviWmtQg.mjs.map +1 -0
  36. package/dist/differential-D4dg-qtZ.mjs +37 -0
  37. package/dist/differential-D4dg-qtZ.mjs.map +1 -0
  38. package/dist/drawing/anchor.d.ts +63 -0
  39. package/dist/drawing/dml/colors.d.ts +109 -0
  40. package/dist/drawing/dml/dml-xml.d.ts +35 -0
  41. package/dist/drawing/dml/effect.d.ts +92 -0
  42. package/dist/drawing/dml/fill.d.ts +115 -0
  43. package/dist/drawing/dml/geometry.d.ts +113 -0
  44. package/dist/drawing/dml/line.d.ts +41 -0
  45. package/dist/drawing/dml/shape-properties.d.ts +33 -0
  46. package/dist/drawing/dml/text.d.ts +218 -0
  47. package/dist/drawing/drawing-xml.d.ts +5 -0
  48. package/dist/drawing/drawing.d.ts +117 -0
  49. package/dist/drawing/image.d.ts +40 -0
  50. package/dist/drawing/index.d.ts +14 -0
  51. package/dist/drawing-BxzLuryn.mjs +415 -0
  52. package/dist/drawing-BxzLuryn.mjs.map +1 -0
  53. package/dist/drawing.mjs +119 -0
  54. package/dist/drawing.mjs.map +1 -0
  55. package/dist/escape-DFTE7ZJc.mjs +51 -0
  56. package/dist/escape-DFTE7ZJc.mjs.map +1 -0
  57. package/dist/exceptions-D-CFwxgm.mjs +37 -0
  58. package/dist/exceptions-D-CFwxgm.mjs.map +1 -0
  59. package/dist/formula/tokenizer.d.ts +61 -0
  60. package/dist/formula/translate.d.ts +67 -0
  61. package/dist/inference-B3ES3KEJ.mjs +42 -0
  62. package/dist/inference-B3ES3KEJ.mjs.map +1 -0
  63. package/dist/io/browser.d.ts +41 -0
  64. package/dist/io/index.d.ts +7 -0
  65. package/dist/io/load.d.ts +46 -0
  66. package/dist/io/node-fs.d.ts +62 -0
  67. package/dist/io/node-save.d.ts +3 -0
  68. package/dist/io/node.d.ts +17 -0
  69. package/dist/io/save.d.ts +14 -0
  70. package/dist/io/sink.d.ts +54 -0
  71. package/dist/io/source.d.ts +14 -0
  72. package/dist/io.mjs +212 -0
  73. package/dist/io.mjs.map +1 -0
  74. package/dist/load-D5cbhoGx.mjs +1069 -0
  75. package/dist/load-D5cbhoGx.mjs.map +1 -0
  76. package/dist/manifest-Dps1-OpP.mjs +801 -0
  77. package/dist/manifest-Dps1-OpP.mjs.map +1 -0
  78. package/dist/node.d.ts +3 -0
  79. package/dist/node.mjs +308 -0
  80. package/dist/node.mjs.map +1 -0
  81. package/dist/packaging/core.d.ts +45 -0
  82. package/dist/packaging/custom.d.ts +62 -0
  83. package/dist/packaging/extended.d.ts +45 -0
  84. package/dist/packaging/index.d.ts +10 -0
  85. package/dist/packaging/manifest.d.ts +24 -0
  86. package/dist/packaging/relationships.d.ts +30 -0
  87. package/dist/packaging.mjs +2 -0
  88. package/dist/parser-DuLejQy1.mjs +156 -0
  89. package/dist/parser-DuLejQy1.mjs.map +1 -0
  90. package/dist/reader-D1fNW9k1.mjs +534 -0
  91. package/dist/reader-D1fNW9k1.mjs.map +1 -0
  92. package/dist/save-RohQtgEZ.mjs +745 -0
  93. package/dist/save-RohQtgEZ.mjs.map +1 -0
  94. package/dist/schema/core.d.ts +133 -0
  95. package/dist/schema/index.d.ts +3 -0
  96. package/dist/schema/serialize.d.ts +6 -0
  97. package/dist/schema.mjs +2 -0
  98. package/dist/serialize-55EnT30e.mjs +254 -0
  99. package/dist/serialize-55EnT30e.mjs.map +1 -0
  100. package/dist/serializer-BwbgHYJV.mjs +116 -0
  101. package/dist/serializer-BwbgHYJV.mjs.map +1 -0
  102. package/dist/streaming/index.d.ts +2 -0
  103. package/dist/streaming/read-only.d.ts +38 -0
  104. package/dist/streaming/write-only.d.ts +47 -0
  105. package/dist/streaming.mjs +612 -0
  106. package/dist/streaming.mjs.map +1 -0
  107. package/dist/styles/alignment.d.ts +33 -0
  108. package/dist/styles/alignment.schema.d.ts +3 -0
  109. package/dist/styles/borders.d.ts +40 -0
  110. package/dist/styles/borders.schema.d.ts +4 -0
  111. package/dist/styles/cell-style.d.ts +270 -0
  112. package/dist/styles/colors.d.ts +128 -0
  113. package/dist/styles/colors.schema.d.ts +3 -0
  114. package/dist/styles/differential.d.ts +41 -0
  115. package/dist/styles/fills.d.ts +54 -0
  116. package/dist/styles/fills.schema.d.ts +6 -0
  117. package/dist/styles/fonts.d.ts +44 -0
  118. package/dist/styles/fonts.schema.d.ts +3 -0
  119. package/dist/styles/index.d.ts +21 -0
  120. package/dist/styles/named-styles.d.ts +52 -0
  121. package/dist/styles/numbers.d.ts +39 -0
  122. package/dist/styles/numbers.schema.d.ts +3 -0
  123. package/dist/styles/protection.d.ts +9 -0
  124. package/dist/styles/protection.schema.d.ts +3 -0
  125. package/dist/styles/stylesheet-reader.d.ts +7 -0
  126. package/dist/styles/stylesheet-writer.d.ts +3 -0
  127. package/dist/styles/stylesheet.d.ts +95 -0
  128. package/dist/styles.mjs +4 -0
  129. package/dist/stylesheet-writer-C2eRmn22.mjs +8624 -0
  130. package/dist/stylesheet-writer-C2eRmn22.mjs.map +1 -0
  131. package/dist/table-DkX6UniA.mjs +113 -0
  132. package/dist/table-DkX6UniA.mjs.map +1 -0
  133. package/dist/tree-Bbs1C8Rc.mjs +192 -0
  134. package/dist/tree-Bbs1C8Rc.mjs.map +1 -0
  135. package/dist/units-rOMQqXh2.mjs +41 -0
  136. package/dist/units-rOMQqXh2.mjs.map +1 -0
  137. package/dist/user-shapes-DfmCGKB0.mjs +252 -0
  138. package/dist/user-shapes-DfmCGKB0.mjs.map +1 -0
  139. package/dist/utf8-D91g1XTG.mjs +143 -0
  140. package/dist/utf8-D91g1XTG.mjs.map +1 -0
  141. package/dist/utils/coordinate.d.ts +103 -0
  142. package/dist/utils/css.d.ts +18 -0
  143. package/dist/utils/datetime.d.ts +38 -0
  144. package/dist/utils/escape.d.ts +34 -0
  145. package/dist/utils/exceptions.d.ts +34 -0
  146. package/dist/utils/index.d.ts +11 -0
  147. package/dist/utils/inference.d.ts +24 -0
  148. package/dist/utils/stable-stringify.d.ts +7 -0
  149. package/dist/utils/units.d.ts +14 -0
  150. package/dist/utils/utf8.d.ts +1 -0
  151. package/dist/utils.mjs +39 -0
  152. package/dist/utils.mjs.map +1 -0
  153. package/dist/workbook/calc-properties.d.ts +47 -0
  154. package/dist/workbook/defined-names.d.ts +121 -0
  155. package/dist/workbook/file-recovery.d.ts +11 -0
  156. package/dist/workbook/file-sharing.d.ts +14 -0
  157. package/dist/workbook/file-version.d.ts +13 -0
  158. package/dist/workbook/function-groups.d.ts +10 -0
  159. package/dist/workbook/index.d.ts +24 -0
  160. package/dist/workbook/protection.d.ts +35 -0
  161. package/dist/workbook/shared-strings.d.ts +57 -0
  162. package/dist/workbook/smart-tags.d.ts +13 -0
  163. package/dist/workbook/views.d.ts +89 -0
  164. package/dist/workbook/workbook-properties.d.ts +57 -0
  165. package/dist/workbook/workbook.d.ts +643 -0
  166. package/dist/workbook-HGYNRBlV.mjs +636 -0
  167. package/dist/workbook-HGYNRBlV.mjs.map +1 -0
  168. package/dist/workbook.mjs +58 -0
  169. package/dist/workbook.mjs.map +1 -0
  170. package/dist/worksheet/auto-filter.d.ts +34 -0
  171. package/dist/worksheet/cell-range.d.ts +121 -0
  172. package/dist/worksheet/comments-xml.d.ts +24 -0
  173. package/dist/worksheet/comments.d.ts +13 -0
  174. package/dist/worksheet/conditional-formatting.d.ts +150 -0
  175. package/dist/worksheet/custom-sheet-views.d.ts +43 -0
  176. package/dist/worksheet/data-consolidate.d.ts +29 -0
  177. package/dist/worksheet/data-validations.d.ts +72 -0
  178. package/dist/worksheet/dimensions.d.ts +40 -0
  179. package/dist/worksheet/errors.d.ts +40 -0
  180. package/dist/worksheet/hyperlinks.d.ts +42 -0
  181. package/dist/worksheet/index.d.ts +46 -0
  182. package/dist/worksheet/ole-objects.d.ts +37 -0
  183. package/dist/worksheet/page-setup.d.ts +173 -0
  184. package/dist/worksheet/phonetic.d.ts +11 -0
  185. package/dist/worksheet/properties.d.ts +34 -0
  186. package/dist/worksheet/protected-ranges.d.ts +19 -0
  187. package/dist/worksheet/protection.d.ts +44 -0
  188. package/dist/worksheet/reader.d.ts +38 -0
  189. package/dist/worksheet/scenarios.d.ts +36 -0
  190. package/dist/worksheet/smart-tags.d.ts +23 -0
  191. package/dist/worksheet/sort-state.d.ts +28 -0
  192. package/dist/worksheet/table-xml.d.ts +5 -0
  193. package/dist/worksheet/table.d.ts +80 -0
  194. package/dist/worksheet/views.d.ts +47 -0
  195. package/dist/worksheet/web-publish.d.ts +21 -0
  196. package/dist/worksheet/worksheet.d.ts +935 -0
  197. package/dist/worksheet/writer.d.ts +72 -0
  198. package/dist/worksheet-CmCNoIgD.mjs +1726 -0
  199. package/dist/worksheet-CmCNoIgD.mjs.map +1 -0
  200. package/dist/worksheet.mjs +247 -0
  201. package/dist/worksheet.mjs.map +1 -0
  202. package/dist/writer-DspzfkNA.mjs +221 -0
  203. package/dist/writer-DspzfkNA.mjs.map +1 -0
  204. package/dist/xml/index.d.ts +10 -0
  205. package/dist/xml/iterparse.d.ts +22 -0
  206. package/dist/xml/namespaces.d.ts +91 -0
  207. package/dist/xml/parser.d.ts +7 -0
  208. package/dist/xml/serializer.d.ts +14 -0
  209. package/dist/xml/stream-writer.d.ts +39 -0
  210. package/dist/xml/tree.d.ts +37 -0
  211. package/dist/xml.mjs +140 -0
  212. package/dist/xml.mjs.map +1 -0
  213. package/dist/zip/decompression-guard.d.ts +70 -0
  214. package/dist/zip/index.d.ts +6 -0
  215. package/dist/zip/random-access-reader.d.ts +16 -0
  216. package/dist/zip/reader.d.ts +45 -0
  217. package/dist/zip/writer.d.ts +65 -0
  218. package/dist/zip/zip64-patch.d.ts +12 -0
  219. package/dist/zip.mjs +3 -0
  220. package/package.json +147 -0
@@ -0,0 +1,745 @@
1
+ import { i as OpenXmlIoError, o as OpenXmlSchemaError } from "./exceptions-D-CFwxgm.mjs";
2
+ import { m as IMAGE_FORMAT_MIME, p as IMAGE_FORMAT_EXTENSION } from "./drawing-BxzLuryn.mjs";
3
+ import { n as escapeXmlAttr, r as escapeXmlText } from "./escape-DFTE7ZJc.mjs";
4
+ import { M as CPROPS_TYPE, _ as ARC_WORKBOOK_RELS, c as ARC_CONTENT_TYPES, ct as PKG_REL_NS, f as ARC_ROOT_RELS, ft as SHEET_MAIN_NS, g as ARC_WORKBOOK, h as ARC_THEME, l as ARC_CORE, lt as REL_NS, m as ARC_STYLE, mt as THEME_TYPE, p as ARC_SHARED_STRINGS, pt as STYLES_TYPE, s as ARC_APP, u as ARC_CUSTOM, ut as SHARED_STRINGS_TYPE, wt as XLSX_TYPE, x as CHARTEX_TYPE, yt as WORKSHEET_TYPE } from "./tree-Bbs1C8Rc.mjs";
5
+ import { S as chartExToBytes, T as chartToBytes, h as chartsheetToBytes, i as commentsToBytes, o as placeholderVmlDrawing, p as drawingToBytes, r as tableToBytes, t as stylesheetToBytes, v as worksheetToBytes, x as userShapesToBytes } from "./stylesheet-writer-C2eRmn22.mjs";
6
+ import { t as serializeXml } from "./serializer-BwbgHYJV.mjs";
7
+ import { V as corePropsToBytes, a as makeManifest, l as extendedPropsToBytes, n as addOverride, rt as relsToBytes, s as manifestToBytes, t as addDefault, tt as makeRelationships, v as customPropsToBytes } from "./manifest-Dps1-OpP.mjs";
8
+ import { A as sharedStringsToBytes, E as makeSharedStrings, S as validateSheetTitle } from "./workbook-HGYNRBlV.mjs";
9
+ import { t as createZipWriter } from "./writer-DspzfkNA.mjs";
10
+ //#region src/io/save.ts
11
+ const CORE_PROPS_TYPE = "application/vnd.openxmlformats-package.core-properties+xml";
12
+ const EXT_PROPS_TYPE = "application/vnd.openxmlformats-officedocument.extended-properties+xml";
13
+ const CORE_PROPS_REL = `${PKG_REL_NS}/metadata/core-properties`;
14
+ const EXT_PROPS_REL = `${REL_NS}/extended-properties`;
15
+ const CUSTOM_PROPS_REL = `${REL_NS}/custom-properties`;
16
+ const THEME_REL = `${REL_NS}/theme`;
17
+ const TABLE_REL = `${REL_NS}/table`;
18
+ const TABLE_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml";
19
+ const COMMENTS_REL = `${REL_NS}/comments`;
20
+ const VML_DRAWING_REL = `${REL_NS}/vmlDrawing`;
21
+ const COMMENTS_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml";
22
+ const VML_DRAWING_TYPE = "application/vnd.openxmlformats-officedocument.vmlDrawing";
23
+ const DRAWING_REL = `${REL_NS}/drawing`;
24
+ const DRAWING_TYPE = "application/vnd.openxmlformats-officedocument.drawing+xml";
25
+ const CHART_REL = `${REL_NS}/chart`;
26
+ const CHARTEX_REL = "http://schemas.microsoft.com/office/2014/relationships/chartEx";
27
+ const CHART_TYPE = "application/vnd.openxmlformats-officedocument.drawingml.chart+xml";
28
+ const IMAGE_REL = `${REL_NS}/image`;
29
+ const CHARTSHEET_REL = `${REL_NS}/chartsheet`;
30
+ const CHARTSHEET_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml";
31
+ const CHART_USER_SHAPES_REL = `${REL_NS}/chartUserShapes`;
32
+ /** Convenience: serialise a Workbook to an in-memory `Uint8Array` xlsx.
33
+ *
34
+ * Browser-safe: this path uses an in-memory `Uint8Array` sink and never
35
+ * touches Node's `Buffer` global, so it works unchanged in browser bundles.
36
+ */
37
+ async function workbookToBytes(wb, opts = {}) {
38
+ const sink = toUint8ArraySink();
39
+ await saveWorkbook(wb, sink, opts);
40
+ return sink.result();
41
+ }
42
+ const toUint8ArraySink = () => {
43
+ const chunks = [];
44
+ let finalised;
45
+ const finalise = () => {
46
+ if (finalised !== void 0) return finalised;
47
+ let total = 0;
48
+ for (const c of chunks) total += c.byteLength;
49
+ const out = new Uint8Array(total);
50
+ let off = 0;
51
+ for (const c of chunks) {
52
+ out.set(c, off);
53
+ off += c.byteLength;
54
+ }
55
+ finalised = out;
56
+ chunks.length = 0;
57
+ return out;
58
+ };
59
+ return {
60
+ toBytes() {
61
+ return {
62
+ write(chunk) {
63
+ if (finalised !== void 0) throw new OpenXmlIoError("workbookToBytes sink: write after finish");
64
+ if (!(chunk instanceof Uint8Array)) throw new OpenXmlIoError("workbookToBytes sink: chunk is not a Uint8Array");
65
+ chunks.push(chunk);
66
+ },
67
+ async finish() {
68
+ return finalise();
69
+ },
70
+ abort() {
71
+ if (finalised !== void 0) return;
72
+ finalised = new Uint8Array(0);
73
+ chunks.length = 0;
74
+ }
75
+ };
76
+ },
77
+ result() {
78
+ return finalise();
79
+ }
80
+ };
81
+ };
82
+ /**
83
+ * Validate every sheet title against Excel's character + length rules and
84
+ * confirm titles are unique within the workbook. Catches bad state introduced
85
+ * via direct mutation (`ws.title = ...`) that bypassed the public mutators.
86
+ *
87
+ * Without this gate, a workbook with an invalid sheet name would round-trip to
88
+ * an xlsx Excel rejects with a generic "file is corrupt" dialog on open —
89
+ * making it hard to diagnose. Raising at save time keeps the bad state
90
+ * recoverable: callers can `renameSheet` and retry.
91
+ */
92
+ const validateSheetTitles = (wb) => {
93
+ const seen = /* @__PURE__ */ new Map();
94
+ for (let i = 0; i < wb.sheets.length; i++) {
95
+ const ref = wb.sheets[i];
96
+ if (!ref) continue;
97
+ const title = ref.sheet.title;
98
+ const reason = validateSheetTitle(title);
99
+ if (reason) throw new OpenXmlSchemaError(`saveWorkbook: sheet[${i}] title "${title}": ${reason}`);
100
+ const lower = title.toLowerCase();
101
+ const prior = seen.get(lower);
102
+ if (prior !== void 0) throw new OpenXmlSchemaError(`saveWorkbook: sheet[${i}] title "${title}" collides with sheet[${prior}] (Excel treats sheet names case-insensitively for uniqueness).`);
103
+ seen.set(lower, i);
104
+ }
105
+ };
106
+ /** Save a workbook through the given sink. Returns once `finalize()` resolves. */
107
+ async function saveWorkbook(wb, sink, _opts = {}) {
108
+ validateSheetTitles(wb);
109
+ const writer = createZipWriter(sink);
110
+ try {
111
+ await saveWorkbookImpl(wb, writer);
112
+ } catch (err) {
113
+ writer.abort(err);
114
+ throw err;
115
+ }
116
+ }
117
+ async function saveWorkbookImpl(wb, writer) {
118
+ const sst = makeSharedStrings();
119
+ const sheetEmits = [];
120
+ const tableEmits = [];
121
+ let nextTableId = 1;
122
+ const commentEmits = [];
123
+ let nextCommentsId = 1;
124
+ const drawingEmits = [];
125
+ let nextDrawingId = 1;
126
+ const chartEmits = [];
127
+ let nextChartId = 1;
128
+ const userShapeEmits = [];
129
+ let nextUserShapesId = 1;
130
+ const imageEmits = [];
131
+ const imageExts = /* @__PURE__ */ new Set();
132
+ let nextImageId = 1;
133
+ let nextWorksheetId = 1;
134
+ let nextChartsheetId = 1;
135
+ const claimedRIds = /* @__PURE__ */ new Set();
136
+ for (const ref of wb.sheets) if (ref.rId !== void 0) claimedRIds.add(ref.rId);
137
+ if (wb.workbookRelOriginalIds) {
138
+ for (const v of Object.values(wb.workbookRelOriginalIds)) if (typeof v === "string") claimedRIds.add(v);
139
+ }
140
+ if (wb.workbookRelsExtras) for (const e of wb.workbookRelsExtras) claimedRIds.add(e.id);
141
+ let nextRIdCursor = 1;
142
+ const allocateRId = () => {
143
+ let id = `rId${nextRIdCursor}`;
144
+ while (claimedRIds.has(id)) {
145
+ nextRIdCursor++;
146
+ id = `rId${nextRIdCursor}`;
147
+ }
148
+ claimedRIds.add(id);
149
+ nextRIdCursor++;
150
+ return id;
151
+ };
152
+ wb.sheets.forEach((ref, _i) => {
153
+ const isChartsheet = ref.kind === "chartsheet";
154
+ const target = isChartsheet ? `chartsheets/sheet${nextChartsheetId}.xml` : `worksheets/sheet${nextWorksheetId}.xml`;
155
+ const archivePath = isChartsheet ? `xl/chartsheets/sheet${nextChartsheetId}.xml` : `xl/worksheets/sheet${nextWorksheetId}.xml`;
156
+ if (isChartsheet) nextChartsheetId++;
157
+ else nextWorksheetId++;
158
+ const sheetRels = makeRelationships();
159
+ const sheetRelsClaimed = /* @__PURE__ */ new Set();
160
+ const sheetRelsExtras = ref.kind === "worksheet" ? ref.sheet.relsExtras ?? [] : [];
161
+ for (const e of sheetRelsExtras) sheetRelsClaimed.add(e.id);
162
+ let sheetRIdCursor = 1;
163
+ const allocateSheetRId = () => {
164
+ let id = `rId${sheetRIdCursor}`;
165
+ while (sheetRelsClaimed.has(id) || sheetRels.rels.some((r) => r.id === id)) {
166
+ sheetRIdCursor++;
167
+ id = `rId${sheetRIdCursor}`;
168
+ }
169
+ sheetRIdCursor++;
170
+ return id;
171
+ };
172
+ const registerTable = (table) => {
173
+ const tableId = nextTableId++;
174
+ const rId = allocateSheetRId();
175
+ sheetRels.rels.push({
176
+ id: rId,
177
+ type: TABLE_REL,
178
+ target: `../tables/table${tableId}.xml`
179
+ });
180
+ const xmlTable = {
181
+ ...table,
182
+ id: tableId
183
+ };
184
+ tableEmits.push({
185
+ id: tableId,
186
+ bytes: tableToBytes(xmlTable)
187
+ });
188
+ return { rId };
189
+ };
190
+ const registerComments = (comments) => {
191
+ const id = nextCommentsId++;
192
+ const commentsRelId = allocateSheetRId();
193
+ sheetRels.rels.push({
194
+ id: commentsRelId,
195
+ type: COMMENTS_REL,
196
+ target: `../comments${id}.xml`
197
+ });
198
+ const vmlRelId = allocateSheetRId();
199
+ sheetRels.rels.push({
200
+ id: vmlRelId,
201
+ type: VML_DRAWING_REL,
202
+ target: `../drawings/vmlDrawing${id}.vml`
203
+ });
204
+ commentEmits.push({
205
+ id,
206
+ commentsBytes: commentsToBytes(comments),
207
+ vmlBytes: placeholderVmlDrawing(comments)
208
+ });
209
+ return { vmlRelId };
210
+ };
211
+ const registerDrawing = (drawing) => {
212
+ const id = nextDrawingId++;
213
+ const rId = allocateSheetRId();
214
+ sheetRels.rels.push({
215
+ id: rId,
216
+ type: DRAWING_REL,
217
+ target: `../drawings/drawing${id}.xml`
218
+ });
219
+ const drawingRels = makeRelationships();
220
+ const itemsForXml = [];
221
+ for (const item of drawing.items) if (item.content.kind === "chart" && (item.content.chart.space || item.content.chart.cxSpace)) {
222
+ const chartId = nextChartId++;
223
+ const chartRId = `rId${drawingRels.rels.length + 1}`;
224
+ const isCxChart = item.content.chart.cxSpace !== void 0;
225
+ drawingRels.rels.push({
226
+ id: chartRId,
227
+ type: isCxChart ? CHARTEX_REL : CHART_REL,
228
+ target: `../charts/chart${chartId}.xml`
229
+ });
230
+ if (item.content.chart.cxSpace) chartEmits.push({
231
+ id: chartId,
232
+ bytes: chartExToBytes(item.content.chart.cxSpace),
233
+ isCx: true
234
+ });
235
+ else if (item.content.chart.space) {
236
+ const space = item.content.chart.space;
237
+ let userShapesRId;
238
+ let chartRelsFile;
239
+ if (space.userShapes && space.userShapes.shapes.length > 0) {
240
+ const userShapesId = nextUserShapesId++;
241
+ userShapesRId = "rId1";
242
+ chartRelsFile = makeRelationships();
243
+ chartRelsFile.rels.push({
244
+ id: userShapesRId,
245
+ type: CHART_USER_SHAPES_REL,
246
+ target: `../drawings/chartDrawing${userShapesId}.xml`
247
+ });
248
+ userShapeEmits.push({
249
+ id: userShapesId,
250
+ bytes: userShapesToBytes(space.userShapes)
251
+ });
252
+ }
253
+ const chartEmit = {
254
+ id: chartId,
255
+ bytes: chartToBytes(space, userShapesRId !== void 0 ? { userShapesRId } : {}),
256
+ isCx: false
257
+ };
258
+ if (chartRelsFile) chartEmit.rels = chartRelsFile;
259
+ chartEmits.push(chartEmit);
260
+ }
261
+ itemsForXml.push({
262
+ anchor: item.anchor,
263
+ content: {
264
+ kind: "chart",
265
+ chart: {
266
+ rId: chartRId,
267
+ ...item.content.chart.cxSpace ? { isCx: true } : {}
268
+ }
269
+ }
270
+ });
271
+ } else if (item.content.kind === "picture" && item.content.picture.image) {
272
+ const img = item.content.picture.image;
273
+ const ext = IMAGE_FORMAT_EXTENSION[img.format];
274
+ const imageId = nextImageId++;
275
+ const picRId = `rId${drawingRels.rels.length + 1}`;
276
+ drawingRels.rels.push({
277
+ id: picRId,
278
+ type: IMAGE_REL,
279
+ target: `../media/image${imageId}.${ext}`
280
+ });
281
+ imageEmits.push({
282
+ id: imageId,
283
+ ext,
284
+ bytes: img.bytes
285
+ });
286
+ imageExts.add(ext);
287
+ itemsForXml.push({
288
+ anchor: item.anchor,
289
+ content: {
290
+ kind: "picture",
291
+ picture: {
292
+ rId: picRId,
293
+ ...item.content.picture.name !== void 0 ? { name: item.content.picture.name } : {},
294
+ ...item.content.picture.descr !== void 0 ? { descr: item.content.picture.descr } : {},
295
+ ...item.content.picture.hidden !== void 0 ? { hidden: item.content.picture.hidden } : {},
296
+ ...item.content.picture.spPr ? { spPr: item.content.picture.spPr } : {}
297
+ }
298
+ }
299
+ });
300
+ } else itemsForXml.push(item);
301
+ const emit = {
302
+ id,
303
+ bytes: drawingToBytes({ items: itemsForXml })
304
+ };
305
+ if (drawingRels.rels.length > 0) emit.rels = drawingRels;
306
+ drawingEmits.push(emit);
307
+ return { rId };
308
+ };
309
+ let bytes;
310
+ if (ref.kind === "worksheet") bytes = worksheetToBytes(ref.sheet, {
311
+ sharedStrings: sst,
312
+ date1904: wb.date1904,
313
+ rels: sheetRels,
314
+ registerTable,
315
+ registerComments,
316
+ registerDrawing
317
+ });
318
+ else {
319
+ let drawingRId;
320
+ if (ref.sheet.drawing) drawingRId = registerDrawing(ref.sheet.drawing).rId;
321
+ bytes = chartsheetToBytes(ref.sheet, drawingRId !== void 0 ? { drawingRId } : {});
322
+ }
323
+ for (const e of sheetRelsExtras) sheetRels.rels.push({
324
+ id: e.id,
325
+ type: e.type,
326
+ target: e.target
327
+ });
328
+ const emit = {
329
+ id: ref.rId ?? allocateRId(),
330
+ target,
331
+ bytes,
332
+ relType: isChartsheet ? CHARTSHEET_REL : `${REL_NS}/worksheet`,
333
+ archivePath,
334
+ contentType: isChartsheet ? CHARTSHEET_TYPE : WORKSHEET_TYPE
335
+ };
336
+ if (sheetRels.rels.length > 0) emit.rels = sheetRels;
337
+ sheetEmits.push(emit);
338
+ });
339
+ const wbRels = makeRelationships();
340
+ wbRels.rels = sheetEmits.map((e) => ({
341
+ id: e.id,
342
+ type: e.relType,
343
+ target: e.target
344
+ }));
345
+ const orig = wb.workbookRelOriginalIds;
346
+ if (sst.entries.length > 0) wbRels.rels.push({
347
+ id: orig?.sharedStrings ?? allocateRId(),
348
+ type: `${REL_NS}/sharedStrings`,
349
+ target: "sharedStrings.xml"
350
+ });
351
+ wbRels.rels.push({
352
+ id: orig?.styles ?? allocateRId(),
353
+ type: `${REL_NS}/styles`,
354
+ target: "styles.xml"
355
+ });
356
+ if (wb.themeXml) wbRels.rels.push({
357
+ id: orig?.theme ?? allocateRId(),
358
+ type: THEME_REL,
359
+ target: "theme/theme1.xml"
360
+ });
361
+ if (wb.vbaProject) wbRels.rels.push({
362
+ id: orig?.vbaProject ?? allocateRId(),
363
+ type: `${REL_NS}/vbaProject`,
364
+ target: "vbaProject.bin"
365
+ });
366
+ if (wb.workbookRelsExtras) for (const e of wb.workbookRelsExtras) wbRels.rels.push({
367
+ id: e.id,
368
+ type: e.type,
369
+ target: e.target
370
+ });
371
+ const workbookXml = serializeWorkbookXml(wb, sheetEmits.map((e) => e.id));
372
+ await writer.addEntry(ARC_WORKBOOK, new TextEncoder().encode(workbookXml));
373
+ await writer.addEntry(ARC_WORKBOOK_RELS, relsToBytes(wbRels));
374
+ for (const e of sheetEmits) {
375
+ await writer.addEntry(e.archivePath, e.bytes);
376
+ if (e.rels) {
377
+ const slash = e.archivePath.lastIndexOf("/");
378
+ const dir = e.archivePath.slice(0, slash);
379
+ const file = e.archivePath.slice(slash + 1);
380
+ await writer.addEntry(`${dir}/_rels/${file}.rels`, relsToBytes(e.rels));
381
+ }
382
+ }
383
+ for (const t of tableEmits) await writer.addEntry(`xl/tables/table${t.id}.xml`, t.bytes);
384
+ for (const c of commentEmits) {
385
+ await writer.addEntry(`xl/comments${c.id}.xml`, c.commentsBytes);
386
+ await writer.addEntry(`xl/drawings/vmlDrawing${c.id}.vml`, c.vmlBytes);
387
+ }
388
+ for (const d of drawingEmits) {
389
+ await writer.addEntry(`xl/drawings/drawing${d.id}.xml`, d.bytes);
390
+ if (d.rels) await writer.addEntry(`xl/drawings/_rels/drawing${d.id}.xml.rels`, relsToBytes(d.rels));
391
+ }
392
+ for (const c of chartEmits) {
393
+ await writer.addEntry(`xl/charts/chart${c.id}.xml`, c.bytes);
394
+ if (c.rels) await writer.addEntry(`xl/charts/_rels/chart${c.id}.xml.rels`, relsToBytes(c.rels));
395
+ }
396
+ for (const us of userShapeEmits) await writer.addEntry(`xl/drawings/chartDrawing${us.id}.xml`, us.bytes);
397
+ for (const img of imageEmits) await writer.addEntry(`xl/media/image${img.id}.${img.ext}`, img.bytes);
398
+ await writer.addEntry(ARC_STYLE, stylesheetToBytes(wb.styles));
399
+ if (sst.entries.length > 0) await writer.addEntry(ARC_SHARED_STRINGS, sharedStringsToBytes(sst));
400
+ if (wb.themeXml) await writer.addEntry(ARC_THEME, wb.themeXml);
401
+ if (wb.properties) await writer.addEntry(ARC_CORE, corePropsToBytes(wb.properties));
402
+ if (wb.appProperties) await writer.addEntry(ARC_APP, extendedPropsToBytes(wb.appProperties));
403
+ if (wb.customProperties) await writer.addEntry(ARC_CUSTOM, customPropsToBytes(wb.customProperties));
404
+ if (wb.vbaProject) await writer.addEntry("xl/vbaProject.bin", wb.vbaProject);
405
+ if (wb.vbaSignature) await writer.addEntry("xl/vbaProjectSignature.bin", wb.vbaSignature);
406
+ if (wb.passthrough) for (const [path, bytes] of wb.passthrough) await writer.addEntry(path, bytes);
407
+ const rootRels = { rels: [] };
408
+ rootRels.rels.push({
409
+ id: "rId1",
410
+ type: `${REL_NS}/officeDocument`,
411
+ target: "xl/workbook.xml"
412
+ });
413
+ if (wb.properties) rootRels.rels.push({
414
+ id: `rId${rootRels.rels.length + 1}`,
415
+ type: CORE_PROPS_REL,
416
+ target: "docProps/core.xml"
417
+ });
418
+ if (wb.appProperties) rootRels.rels.push({
419
+ id: `rId${rootRels.rels.length + 1}`,
420
+ type: EXT_PROPS_REL,
421
+ target: "docProps/app.xml"
422
+ });
423
+ if (wb.customProperties) rootRels.rels.push({
424
+ id: `rId${rootRels.rels.length + 1}`,
425
+ type: CUSTOM_PROPS_REL,
426
+ target: "docProps/custom.xml"
427
+ });
428
+ await writer.addEntry(ARC_ROOT_RELS, relsToBytes(rootRels));
429
+ const manifest = makeManifest();
430
+ addDefault(manifest, "rels", "application/vnd.openxmlformats-package.relationships+xml");
431
+ addDefault(manifest, "xml", "application/xml");
432
+ const workbookContentType = wb.vbaProject ? "application/vnd.ms-excel.sheet.macroEnabled.main+xml" : XLSX_TYPE;
433
+ addOverride(manifest, `/${ARC_WORKBOOK}`, workbookContentType);
434
+ for (const e of sheetEmits) addOverride(manifest, `/${e.archivePath}`, e.contentType);
435
+ addOverride(manifest, `/${ARC_STYLE}`, STYLES_TYPE);
436
+ if (sst.entries.length > 0) addOverride(manifest, `/${ARC_SHARED_STRINGS}`, SHARED_STRINGS_TYPE);
437
+ if (wb.themeXml) addOverride(manifest, `/${ARC_THEME}`, THEME_TYPE);
438
+ for (const t of tableEmits) addOverride(manifest, `/xl/tables/table${t.id}.xml`, TABLE_TYPE);
439
+ if (commentEmits.length > 0) addDefault(manifest, "vml", VML_DRAWING_TYPE);
440
+ for (const c of commentEmits) addOverride(manifest, `/xl/comments${c.id}.xml`, COMMENTS_TYPE);
441
+ for (const d of drawingEmits) addOverride(manifest, `/xl/drawings/drawing${d.id}.xml`, DRAWING_TYPE);
442
+ for (const c of chartEmits) addOverride(manifest, `/xl/charts/chart${c.id}.xml`, c.isCx ? CHARTEX_TYPE : CHART_TYPE);
443
+ for (const us of userShapeEmits) addOverride(manifest, `/xl/drawings/chartDrawing${us.id}.xml`, DRAWING_TYPE);
444
+ if (wb.vbaProject) addDefault(manifest, "bin", "application/vnd.ms-office.vbaProject");
445
+ if (wb.passthrough) for (const path of wb.passthrough.keys()) {
446
+ const ct = wb.passthroughContentTypes?.get(path);
447
+ if (ct !== void 0) addOverride(manifest, `/${path}`, ct);
448
+ }
449
+ for (const ext of imageExts) {
450
+ const fmt = (Object.entries(IMAGE_FORMAT_EXTENSION).find(([, e]) => e === ext) ?? [])[0];
451
+ if (fmt) addDefault(manifest, ext, IMAGE_FORMAT_MIME[fmt]);
452
+ }
453
+ if (wb.properties) addOverride(manifest, `/${ARC_CORE}`, CORE_PROPS_TYPE);
454
+ if (wb.appProperties) addOverride(manifest, `/${ARC_APP}`, EXT_PROPS_TYPE);
455
+ if (wb.customProperties) addOverride(manifest, `/${ARC_CUSTOM}`, CPROPS_TYPE);
456
+ await writer.addEntry(ARC_CONTENT_TYPES, manifestToBytes(manifest));
457
+ await writer.finalize();
458
+ }
459
+ /** Serialise the minimum `<workbook><sheets/></workbook>` Excel needs to load a sheet list. */
460
+ function serializeWorkbookXml(wb, sheetRIds) {
461
+ const parts = ["<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>", `<workbook xmlns="${SHEET_MAIN_NS}" xmlns:r="${REL_NS}">`];
462
+ if (wb.fileVersion) {
463
+ const fv = serializeFileVersion(wb.fileVersion);
464
+ if (fv) parts.push(fv);
465
+ }
466
+ if (wb.fileSharing) {
467
+ const fs = serializeFileSharing(wb.fileSharing);
468
+ if (fs) parts.push(fs);
469
+ }
470
+ if (wb.workbookXmlExtras?.beforeSheets) for (const node of wb.workbookXmlExtras.beforeSheets) parts.push(serializeChildNode(node));
471
+ const effectiveWp = effectiveWorkbookProperties(wb);
472
+ if (effectiveWp) {
473
+ const wp = serializeWorkbookProperties(effectiveWp);
474
+ if (wp) parts.push(wp);
475
+ }
476
+ if (wb.workbookProtection) {
477
+ const wp = serializeWorkbookProtection(wb.workbookProtection);
478
+ if (wp) parts.push(wp);
479
+ }
480
+ if (wb.bookViews && wb.bookViews.length > 0) parts.push(serializeBookViews(wb.bookViews));
481
+ parts.push("<sheets>");
482
+ wb.sheets.forEach((ref, i) => {
483
+ const stateAttr = ref.state === "visible" ? "" : ` state="${ref.state}"`;
484
+ const rId = sheetRIds[i] ?? `rId${i + 1}`;
485
+ parts.push(`<sheet name="${escapeAttr(ref.sheet.title)}" sheetId="${ref.sheetId}"${stateAttr} r:id="${rId}"/>`);
486
+ });
487
+ parts.push("</sheets>");
488
+ if (wb.definedNames.length > 0) {
489
+ parts.push("<definedNames>");
490
+ for (const dn of wb.definedNames) {
491
+ let attrs = ` name="${escapeAttr(dn.name)}"`;
492
+ if (dn.scope !== void 0) attrs += ` localSheetId="${dn.scope}"`;
493
+ if (dn.hidden) attrs += " hidden=\"1\"";
494
+ if (dn.comment !== void 0) attrs += ` comment="${escapeAttr(dn.comment)}"`;
495
+ parts.push(`<definedName${attrs}>${escapeText(dn.value)}</definedName>`);
496
+ }
497
+ parts.push("</definedNames>");
498
+ }
499
+ if (wb.functionGroups) {
500
+ const fg = serializeFunctionGroups(wb.functionGroups);
501
+ if (fg) parts.push(fg);
502
+ }
503
+ if (wb.externalReferences && wb.externalReferences.length > 0) {
504
+ const inner = ["<externalReferences>"];
505
+ for (const er of wb.externalReferences) inner.push(`<externalReference r:id="${escapeAttr(er.rId)}"/>`);
506
+ inner.push("</externalReferences>");
507
+ parts.push(inner.join(""));
508
+ }
509
+ if (wb.pivotCaches && wb.pivotCaches.length > 0) {
510
+ const inner = ["<pivotCaches>"];
511
+ for (const pc of wb.pivotCaches) inner.push(`<pivotCache cacheId="${pc.cacheId}" r:id="${escapeAttr(pc.rId)}"/>`);
512
+ inner.push("</pivotCaches>");
513
+ parts.push(inner.join(""));
514
+ }
515
+ if (wb.calcProperties) {
516
+ const cp = serializeCalcProperties(wb.calcProperties);
517
+ if (cp) parts.push(cp);
518
+ }
519
+ if (wb.oleSize !== void 0) parts.push(`<oleSize ref="${escapeAttr(wb.oleSize)}"/>`);
520
+ if (wb.customWorkbookViews && wb.customWorkbookViews.length > 0) parts.push(serializeCustomWorkbookViews(wb.customWorkbookViews));
521
+ if (wb.smartTagPr) {
522
+ const stp = serializeSmartTagPr(wb.smartTagPr);
523
+ if (stp) parts.push(stp);
524
+ }
525
+ if (wb.smartTagTypes && wb.smartTagTypes.length > 0) parts.push(serializeSmartTagTypes(wb.smartTagTypes));
526
+ if (wb.workbookXmlExtras?.afterSheets) for (const node of wb.workbookXmlExtras.afterSheets) parts.push(serializeChildNode(node));
527
+ if (wb.fileRecoveryPr) {
528
+ const fp = serializeFileRecoveryPr(wb.fileRecoveryPr);
529
+ if (fp) parts.push(fp);
530
+ }
531
+ parts.push("</workbook>");
532
+ return parts.join("");
533
+ }
534
+ function serializeCalcProperties(cp) {
535
+ let attrs = "";
536
+ if (cp.calcId !== void 0) attrs += ` calcId="${cp.calcId}"`;
537
+ if (cp.calcMode !== void 0) attrs += ` calcMode="${cp.calcMode}"`;
538
+ if (cp.fullCalcOnLoad !== void 0) attrs += ` fullCalcOnLoad="${cp.fullCalcOnLoad ? "1" : "0"}"`;
539
+ if (cp.refMode !== void 0) attrs += ` refMode="${cp.refMode}"`;
540
+ if (cp.iterate !== void 0) attrs += ` iterate="${cp.iterate ? "1" : "0"}"`;
541
+ if (cp.iterateCount !== void 0) attrs += ` iterateCount="${cp.iterateCount}"`;
542
+ if (cp.iterateDelta !== void 0) attrs += ` iterateDelta="${cp.iterateDelta}"`;
543
+ if (cp.fullPrecision !== void 0) attrs += ` fullPrecision="${cp.fullPrecision ? "1" : "0"}"`;
544
+ if (cp.calcCompleted !== void 0) attrs += ` calcCompleted="${cp.calcCompleted ? "1" : "0"}"`;
545
+ if (cp.calcOnSave !== void 0) attrs += ` calcOnSave="${cp.calcOnSave ? "1" : "0"}"`;
546
+ if (cp.concurrentCalc !== void 0) attrs += ` concurrentCalc="${cp.concurrentCalc ? "1" : "0"}"`;
547
+ if (cp.concurrentManualCount !== void 0) attrs += ` concurrentManualCount="${cp.concurrentManualCount}"`;
548
+ if (cp.forceFullCalc !== void 0) attrs += ` forceFullCalc="${cp.forceFullCalc ? "1" : "0"}"`;
549
+ if (attrs.length === 0) return void 0;
550
+ return `<calcPr${attrs}/>`;
551
+ }
552
+ function serializeFunctionGroups(fg) {
553
+ let attrs = "";
554
+ if (fg.builtInGroupCount !== void 0) attrs += ` builtInGroupCount="${fg.builtInGroupCount}"`;
555
+ if (fg.groups.length === 0 && attrs.length === 0) return void 0;
556
+ if (fg.groups.length === 0) return `<functionGroups${attrs}/>`;
557
+ const inner = [`<functionGroups${attrs}>`];
558
+ for (const g of fg.groups) inner.push(`<functionGroup name="${escapeAttr(g.name)}"/>`);
559
+ inner.push("</functionGroups>");
560
+ return inner.join("");
561
+ }
562
+ function serializeSmartTagPr(stp) {
563
+ let attrs = "";
564
+ if (stp.embed !== void 0) attrs += ` embed="${stp.embed ? "1" : "0"}"`;
565
+ if (stp.show !== void 0) attrs += ` show="${stp.show}"`;
566
+ if (attrs.length === 0) return void 0;
567
+ return `<smartTagPr${attrs}/>`;
568
+ }
569
+ function serializeSmartTagTypes(tags) {
570
+ const inner = ["<smartTagTypes>"];
571
+ for (const t of tags) {
572
+ let attrs = "";
573
+ if (t.namespaceUri !== void 0) attrs += ` namespaceUri="${escapeAttr(t.namespaceUri)}"`;
574
+ if (t.name !== void 0) attrs += ` name="${escapeAttr(t.name)}"`;
575
+ if (t.url !== void 0) attrs += ` url="${escapeAttr(t.url)}"`;
576
+ inner.push(`<smartTagType${attrs}/>`);
577
+ }
578
+ inner.push("</smartTagTypes>");
579
+ return inner.join("");
580
+ }
581
+ function serializeFileRecoveryPr(fp) {
582
+ let attrs = "";
583
+ if (fp.autoRecover !== void 0) attrs += ` autoRecover="${fp.autoRecover ? "1" : "0"}"`;
584
+ if (fp.crashSave !== void 0) attrs += ` crashSave="${fp.crashSave ? "1" : "0"}"`;
585
+ if (fp.dataExtractLoad !== void 0) attrs += ` dataExtractLoad="${fp.dataExtractLoad ? "1" : "0"}"`;
586
+ if (fp.repairLoad !== void 0) attrs += ` repairLoad="${fp.repairLoad ? "1" : "0"}"`;
587
+ if (attrs.length === 0) return void 0;
588
+ return `<fileRecoveryPr${attrs}/>`;
589
+ }
590
+ function serializeFileSharing(fs) {
591
+ let attrs = "";
592
+ if (fs.readOnlyRecommended !== void 0) attrs += ` readOnlyRecommended="${fs.readOnlyRecommended ? "1" : "0"}"`;
593
+ if (fs.userName !== void 0) attrs += ` userName="${escapeAttr(fs.userName)}"`;
594
+ if (fs.reservationPassword !== void 0) attrs += ` reservationPassword="${escapeAttr(fs.reservationPassword)}"`;
595
+ if (fs.algorithmName !== void 0) attrs += ` algorithmName="${escapeAttr(fs.algorithmName)}"`;
596
+ if (fs.hashValue !== void 0) attrs += ` hashValue="${escapeAttr(fs.hashValue)}"`;
597
+ if (fs.saltValue !== void 0) attrs += ` saltValue="${escapeAttr(fs.saltValue)}"`;
598
+ if (fs.spinCount !== void 0) attrs += ` spinCount="${fs.spinCount}"`;
599
+ if (attrs.length === 0) return void 0;
600
+ return `<fileSharing${attrs}/>`;
601
+ }
602
+ function serializeFileVersion(fv) {
603
+ let attrs = "";
604
+ if (fv.appName !== void 0) attrs += ` appName="${escapeAttr(fv.appName)}"`;
605
+ if (fv.lastEdited !== void 0) attrs += ` lastEdited="${escapeAttr(fv.lastEdited)}"`;
606
+ if (fv.lowestEdited !== void 0) attrs += ` lowestEdited="${escapeAttr(fv.lowestEdited)}"`;
607
+ if (fv.rupBuild !== void 0) attrs += ` rupBuild="${escapeAttr(fv.rupBuild)}"`;
608
+ if (fv.codeName !== void 0) attrs += ` codeName="${escapeAttr(fv.codeName)}"`;
609
+ if (attrs.length === 0) return void 0;
610
+ return `<fileVersion${attrs}/>`;
611
+ }
612
+ function effectiveWorkbookProperties(wb) {
613
+ const explicit = wb.workbookProperties;
614
+ if (explicit) {
615
+ if (wb.date1904 && explicit.date1904 === void 0) return {
616
+ ...explicit,
617
+ date1904: true
618
+ };
619
+ return explicit;
620
+ }
621
+ if (wb.date1904) return { date1904: true };
622
+ }
623
+ function serializeWorkbookProperties(wp) {
624
+ let attrs = "";
625
+ for (const k of [
626
+ "date1904",
627
+ "dateCompatibility",
628
+ "showBorderUnselectedTables",
629
+ "filterPrivacy",
630
+ "promptedSolutions",
631
+ "showInkAnnotation",
632
+ "backupFile",
633
+ "saveExternalLinkValues",
634
+ "hidePivotFieldList",
635
+ "showPivotChartFilter",
636
+ "allowRefreshQuery",
637
+ "publishItems",
638
+ "checkCompatibility",
639
+ "autoCompressPictures",
640
+ "refreshAllConnections"
641
+ ]) {
642
+ const v = wp[k];
643
+ if (v !== void 0) attrs += ` ${k}="${v ? "1" : "0"}"`;
644
+ }
645
+ if (wp.showObjects !== void 0) attrs += ` showObjects="${wp.showObjects}"`;
646
+ if (wp.updateLinks !== void 0) attrs += ` updateLinks="${wp.updateLinks}"`;
647
+ if (wp.codeName !== void 0) attrs += ` codeName="${escapeAttr(wp.codeName)}"`;
648
+ if (wp.defaultThemeVersion !== void 0) attrs += ` defaultThemeVersion="${wp.defaultThemeVersion}"`;
649
+ if (attrs.length === 0) return void 0;
650
+ return `<workbookPr${attrs}/>`;
651
+ }
652
+ function serializeCustomWorkbookViews(views) {
653
+ const parts = ["<customWorkbookViews>"];
654
+ for (const v of views) {
655
+ let attrs = ` name="${escapeAttr(v.name)}" guid="${escapeAttr(v.guid)}"`;
656
+ if (v.autoUpdate !== void 0) attrs += ` autoUpdate="${v.autoUpdate ? "1" : "0"}"`;
657
+ if (v.mergeInterval !== void 0) attrs += ` mergeInterval="${v.mergeInterval}"`;
658
+ if (v.changesSavedWin !== void 0) attrs += ` changesSavedWin="${v.changesSavedWin ? "1" : "0"}"`;
659
+ if (v.onlySync !== void 0) attrs += ` onlySync="${v.onlySync ? "1" : "0"}"`;
660
+ if (v.personalView !== void 0) attrs += ` personalView="${v.personalView ? "1" : "0"}"`;
661
+ if (v.includePrintSettings !== void 0) attrs += ` includePrintSettings="${v.includePrintSettings ? "1" : "0"}"`;
662
+ if (v.includeHiddenRowCol !== void 0) attrs += ` includeHiddenRowCol="${v.includeHiddenRowCol ? "1" : "0"}"`;
663
+ if (v.maximized !== void 0) attrs += ` maximized="${v.maximized ? "1" : "0"}"`;
664
+ if (v.minimized !== void 0) attrs += ` minimized="${v.minimized ? "1" : "0"}"`;
665
+ if (v.showHorizontalScroll !== void 0) attrs += ` showHorizontalScroll="${v.showHorizontalScroll ? "1" : "0"}"`;
666
+ if (v.showVerticalScroll !== void 0) attrs += ` showVerticalScroll="${v.showVerticalScroll ? "1" : "0"}"`;
667
+ if (v.showSheetTabs !== void 0) attrs += ` showSheetTabs="${v.showSheetTabs ? "1" : "0"}"`;
668
+ if (v.xWindow !== void 0) attrs += ` xWindow="${v.xWindow}"`;
669
+ if (v.yWindow !== void 0) attrs += ` yWindow="${v.yWindow}"`;
670
+ attrs += ` windowWidth="${v.windowWidth}" windowHeight="${v.windowHeight}"`;
671
+ if (v.tabRatio !== void 0) attrs += ` tabRatio="${v.tabRatio}"`;
672
+ attrs += ` activeSheetId="${v.activeSheetId}"`;
673
+ if (v.showFormulaBar !== void 0) attrs += ` showFormulaBar="${v.showFormulaBar ? "1" : "0"}"`;
674
+ if (v.showStatusbar !== void 0) attrs += ` showStatusbar="${v.showStatusbar ? "1" : "0"}"`;
675
+ if (v.showComments !== void 0) attrs += ` showComments="${v.showComments}"`;
676
+ if (v.showObjects !== void 0) attrs += ` showObjects="${v.showObjects}"`;
677
+ parts.push(`<customWorkbookView${attrs}/>`);
678
+ }
679
+ parts.push("</customWorkbookViews>");
680
+ return parts.join("");
681
+ }
682
+ function serializeBookViews(views) {
683
+ const parts = ["<bookViews>"];
684
+ for (const v of views) {
685
+ let attrs = "";
686
+ if (v.visibility !== void 0) attrs += ` visibility="${v.visibility}"`;
687
+ if (v.minimized !== void 0) attrs += ` minimized="${v.minimized ? "1" : "0"}"`;
688
+ if (v.showHorizontalScroll !== void 0) attrs += ` showHorizontalScroll="${v.showHorizontalScroll ? "1" : "0"}"`;
689
+ if (v.showVerticalScroll !== void 0) attrs += ` showVerticalScroll="${v.showVerticalScroll ? "1" : "0"}"`;
690
+ if (v.showSheetTabs !== void 0) attrs += ` showSheetTabs="${v.showSheetTabs ? "1" : "0"}"`;
691
+ if (v.xWindow !== void 0) attrs += ` xWindow="${v.xWindow}"`;
692
+ if (v.yWindow !== void 0) attrs += ` yWindow="${v.yWindow}"`;
693
+ if (v.windowWidth !== void 0) attrs += ` windowWidth="${v.windowWidth}"`;
694
+ if (v.windowHeight !== void 0) attrs += ` windowHeight="${v.windowHeight}"`;
695
+ if (v.tabRatio !== void 0) attrs += ` tabRatio="${v.tabRatio}"`;
696
+ if (v.firstSheet !== void 0) attrs += ` firstSheet="${v.firstSheet}"`;
697
+ if (v.activeTab !== void 0) attrs += ` activeTab="${v.activeTab}"`;
698
+ if (v.autoFilterDateGrouping !== void 0) attrs += ` autoFilterDateGrouping="${v.autoFilterDateGrouping ? "1" : "0"}"`;
699
+ parts.push(`<workbookView${attrs}/>`);
700
+ }
701
+ parts.push("</bookViews>");
702
+ return parts.join("");
703
+ }
704
+ function serializeWorkbookProtection(wp) {
705
+ let attrs = "";
706
+ for (const k of [
707
+ "workbookPassword",
708
+ "workbookPasswordCharacterSet",
709
+ "workbookAlgorithmName",
710
+ "workbookHashValue",
711
+ "workbookSaltValue",
712
+ "revisionsPassword",
713
+ "revisionsPasswordCharacterSet",
714
+ "revisionsAlgorithmName",
715
+ "revisionsHashValue",
716
+ "revisionsSaltValue"
717
+ ]) {
718
+ const v = wp[k];
719
+ if (v !== void 0) attrs += ` ${k}="${escapeAttr(v)}"`;
720
+ }
721
+ if (wp.workbookSpinCount !== void 0) attrs += ` workbookSpinCount="${wp.workbookSpinCount}"`;
722
+ if (wp.revisionsSpinCount !== void 0) attrs += ` revisionsSpinCount="${wp.revisionsSpinCount}"`;
723
+ if (wp.lockStructure !== void 0) attrs += ` lockStructure="${wp.lockStructure ? "1" : "0"}"`;
724
+ if (wp.lockWindows !== void 0) attrs += ` lockWindows="${wp.lockWindows ? "1" : "0"}"`;
725
+ if (wp.lockRevision !== void 0) attrs += ` lockRevision="${wp.lockRevision ? "1" : "0"}"`;
726
+ if (attrs.length === 0) return void 0;
727
+ return `<workbookProtection${attrs}/>`;
728
+ }
729
+ const escapeText = escapeXmlText;
730
+ const escapeAttr = escapeXmlAttr;
731
+ /**
732
+ * Serialise an XmlNode child of `<workbook>` for inline injection back into the
733
+ * workbook XML stream. Reuses serializeXml then strips the declaration.
734
+ * Captured nodes carry Clark-notation names so namespace prefixes get
735
+ * reallocated by serializeXml — Excel tolerates the extra `xmlns="…"`
736
+ * declarations on each captured root.
737
+ */
738
+ function serializeChildNode(node) {
739
+ const bytes = serializeXml(node, { xmlDeclaration: false });
740
+ return new TextDecoder().decode(bytes);
741
+ }
742
+ //#endregion
743
+ export { workbookToBytes as n, saveWorkbook as t };
744
+
745
+ //# sourceMappingURL=save-RohQtgEZ.mjs.map