@evotecit/officeimo 0.0.0-stage → 0.1.1

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 (261) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1222 -2
  3. package/bundles/officeimo-canopyx.js +11741 -0
  4. package/bundles/officeimo-canopyx.mjs +11639 -0
  5. package/bundles/officeimo-csv.js +1264 -0
  6. package/bundles/officeimo-csv.mjs +1239 -0
  7. package/bundles/officeimo-datatables.js +12018 -0
  8. package/bundles/officeimo-datatables.mjs +11915 -0
  9. package/bundles/officeimo-execution.js +1513 -0
  10. package/bundles/officeimo-execution.mjs +1489 -0
  11. package/bundles/officeimo-pdf.js +7009 -0
  12. package/bundles/officeimo-pdf.mjs +6946 -0
  13. package/bundles/officeimo-xlsx.js +5344 -0
  14. package/bundles/officeimo-xlsx.mjs +5290 -0
  15. package/bundles/officeimo.js +11468 -0
  16. package/bundles/officeimo.mjs +11369 -0
  17. package/dist/core/dates.d.ts +1 -0
  18. package/dist/core/dates.js +16 -0
  19. package/dist/core/errors.d.ts +12 -0
  20. package/dist/core/errors.js +31 -0
  21. package/dist/core/grouped-report.d.ts +87 -0
  22. package/dist/core/grouped-report.js +252 -0
  23. package/dist/core/index.d.ts +74 -0
  24. package/dist/core/index.js +37 -0
  25. package/dist/core/iteration.d.ts +7 -0
  26. package/dist/core/iteration.js +149 -0
  27. package/dist/core/limits.d.ts +7 -0
  28. package/dist/core/limits.js +56 -0
  29. package/dist/core/links.d.ts +5 -0
  30. package/dist/core/links.js +14 -0
  31. package/dist/core/presentation.d.ts +29 -0
  32. package/dist/core/presentation.js +59 -0
  33. package/dist/core/progress.d.ts +1 -0
  34. package/dist/core/progress.js +10 -0
  35. package/dist/core/sinks.d.ts +33 -0
  36. package/dist/core/sinks.js +102 -0
  37. package/dist/core/table.d.ts +8 -0
  38. package/dist/core/table.js +1 -0
  39. package/dist/core/value-text.d.ts +7 -0
  40. package/dist/core/value-text.js +13 -0
  41. package/dist/csv/index.d.ts +44 -0
  42. package/dist/csv/index.js +133 -0
  43. package/dist/csv/options.d.ts +1 -0
  44. package/dist/csv/options.js +8 -0
  45. package/dist/csv/structured-rows.d.ts +3 -0
  46. package/dist/csv/structured-rows.js +15 -0
  47. package/dist/execution/host.d.ts +5 -0
  48. package/dist/execution/host.js +164 -0
  49. package/dist/execution/index.d.ts +3 -0
  50. package/dist/execution/index.js +2 -0
  51. package/dist/execution/protocol.d.ts +48 -0
  52. package/dist/execution/protocol.js +173 -0
  53. package/dist/execution/types.d.ts +42 -0
  54. package/dist/execution/types.js +1 -0
  55. package/dist/execution/worker.d.ts +3 -0
  56. package/dist/execution/worker.js +147 -0
  57. package/dist/index.d.ts +32 -0
  58. package/dist/index.js +14 -0
  59. package/dist/integrations/canopyx/dates.d.ts +1 -0
  60. package/dist/integrations/canopyx/dates.js +34 -0
  61. package/dist/integrations/canopyx/index.d.ts +10 -0
  62. package/dist/integrations/canopyx/index.js +45 -0
  63. package/dist/integrations/canopyx/source.d.ts +3 -0
  64. package/dist/integrations/canopyx/source.js +122 -0
  65. package/dist/integrations/canopyx/types.d.ts +83 -0
  66. package/dist/integrations/canopyx/types.js +1 -0
  67. package/dist/integrations/datatables/api.d.ts +1 -0
  68. package/dist/integrations/datatables/api.js +27 -0
  69. package/dist/integrations/datatables/headings.d.ts +1 -0
  70. package/dist/integrations/datatables/headings.js +65 -0
  71. package/dist/integrations/datatables/index.d.ts +12 -0
  72. package/dist/integrations/datatables/index.js +167 -0
  73. package/dist/integrations/datatables/snapshot.d.ts +3 -0
  74. package/dist/integrations/datatables/snapshot.js +206 -0
  75. package/dist/integrations/datatables/types.d.ts +98 -0
  76. package/dist/integrations/datatables/types.js +1 -0
  77. package/dist/integrations/options.d.ts +13 -0
  78. package/dist/integrations/options.js +34 -0
  79. package/dist/internal/capture.d.ts +4 -0
  80. package/dist/internal/capture.js +14 -0
  81. package/dist/internal/columns.d.ts +27 -0
  82. package/dist/internal/columns.js +1 -0
  83. package/dist/internal/crc32.d.ts +6 -0
  84. package/dist/internal/crc32.js +17 -0
  85. package/dist/internal/export-values.d.ts +3 -0
  86. package/dist/internal/export-values.js +14 -0
  87. package/dist/internal/rows.d.ts +6 -0
  88. package/dist/internal/rows.js +77 -0
  89. package/dist/internal/table-spans.d.ts +11 -0
  90. package/dist/internal/table-spans.js +58 -0
  91. package/dist/internal/totals.d.ts +15 -0
  92. package/dist/internal/totals.js +42 -0
  93. package/dist/opc/index.d.ts +67 -0
  94. package/dist/opc/index.js +233 -0
  95. package/dist/opc/properties.d.ts +15 -0
  96. package/dist/opc/properties.js +18 -0
  97. package/dist/opc/uri.d.ts +5 -0
  98. package/dist/opc/uri.js +41 -0
  99. package/dist/pdf/annotations.d.ts +1 -0
  100. package/dist/pdf/annotations.js +38 -0
  101. package/dist/pdf/binary.d.ts +6 -0
  102. package/dist/pdf/binary.js +24 -0
  103. package/dist/pdf/document-drawings.d.ts +15 -0
  104. package/dist/pdf/document-drawings.js +237 -0
  105. package/dist/pdf/document-grouped.d.ts +1 -0
  106. package/dist/pdf/document-grouped.js +244 -0
  107. package/dist/pdf/document-images.d.ts +19 -0
  108. package/dist/pdf/document-images.js +125 -0
  109. package/dist/pdf/document-types.d.ts +160 -0
  110. package/dist/pdf/document-types.js +1 -0
  111. package/dist/pdf/document-vectors.d.ts +11 -0
  112. package/dist/pdf/document-vectors.js +77 -0
  113. package/dist/pdf/document.d.ts +9 -0
  114. package/dist/pdf/document.js +270 -0
  115. package/dist/pdf/drawing-types.d.ts +53 -0
  116. package/dist/pdf/drawing-types.js +1 -0
  117. package/dist/pdf/font-resources.d.ts +43 -0
  118. package/dist/pdf/font-resources.js +202 -0
  119. package/dist/pdf/font-support.d.ts +1 -0
  120. package/dist/pdf/font-support.js +60 -0
  121. package/dist/pdf/font.d.ts +17 -0
  122. package/dist/pdf/font.js +56 -0
  123. package/dist/pdf/grouped-table.d.ts +6 -0
  124. package/dist/pdf/grouped-table.js +40 -0
  125. package/dist/pdf/grouped-types.d.ts +34 -0
  126. package/dist/pdf/grouped-types.js +1 -0
  127. package/dist/pdf/grouped.d.ts +10 -0
  128. package/dist/pdf/grouped.js +37 -0
  129. package/dist/pdf/index.d.ts +22 -0
  130. package/dist/pdf/index.js +8 -0
  131. package/dist/pdf/inline-text.d.ts +30 -0
  132. package/dist/pdf/inline-text.js +183 -0
  133. package/dist/pdf/inline-types.d.ts +15 -0
  134. package/dist/pdf/inline-types.js +1 -0
  135. package/dist/pdf/list-layout.d.ts +6 -0
  136. package/dist/pdf/list-layout.js +49 -0
  137. package/dist/pdf/objects.d.ts +2 -0
  138. package/dist/pdf/objects.js +320 -0
  139. package/dist/pdf/outlines.d.ts +1 -0
  140. package/dist/pdf/outlines.js +55 -0
  141. package/dist/pdf/page-context.d.ts +1 -0
  142. package/dist/pdf/page-context.js +12 -0
  143. package/dist/pdf/pages.d.ts +1 -0
  144. package/dist/pdf/pages.js +678 -0
  145. package/dist/pdf/paragraph-layout.d.ts +21 -0
  146. package/dist/pdf/paragraph-layout.js +71 -0
  147. package/dist/pdf/paragraph-styles.d.ts +1 -0
  148. package/dist/pdf/paragraph-styles.js +66 -0
  149. package/dist/pdf/png.d.ts +9 -0
  150. package/dist/pdf/png.js +259 -0
  151. package/dist/pdf/preflight.d.ts +7 -0
  152. package/dist/pdf/preflight.js +32 -0
  153. package/dist/pdf/presentation-settings.d.ts +5 -0
  154. package/dist/pdf/presentation-settings.js +28 -0
  155. package/dist/pdf/providers/harfbuzz.d.ts +60 -0
  156. package/dist/pdf/providers/harfbuzz.js +112 -0
  157. package/dist/pdf/providers/unicode13-profile.d.ts +2 -0
  158. package/dist/pdf/providers/unicode13-profile.js +115 -0
  159. package/dist/pdf/section-types.d.ts +15 -0
  160. package/dist/pdf/section-types.js +40 -0
  161. package/dist/pdf/session.d.ts +25 -0
  162. package/dist/pdf/session.js +55 -0
  163. package/dist/pdf/settings.d.ts +17 -0
  164. package/dist/pdf/settings.js +196 -0
  165. package/dist/pdf/shaped-text.d.ts +5 -0
  166. package/dist/pdf/shaped-text.js +205 -0
  167. package/dist/pdf/standard-widths.d.ts +1 -0
  168. package/dist/pdf/standard-widths.js +317 -0
  169. package/dist/pdf/structure-parent-tree.d.ts +1 -0
  170. package/dist/pdf/structure-parent-tree.js +57 -0
  171. package/dist/pdf/structure.d.ts +6 -0
  172. package/dist/pdf/structure.js +302 -0
  173. package/dist/pdf/table-band-flow.d.ts +34 -0
  174. package/dist/pdf/table-band-flow.js +129 -0
  175. package/dist/pdf/table-band-plan.d.ts +10 -0
  176. package/dist/pdf/table-band-plan.js +83 -0
  177. package/dist/pdf/table-layout.d.ts +75 -0
  178. package/dist/pdf/table-layout.js +217 -0
  179. package/dist/pdf/table-structure.d.ts +1 -0
  180. package/dist/pdf/table-structure.js +108 -0
  181. package/dist/pdf/text-shaping-types.d.ts +39 -0
  182. package/dist/pdf/text-shaping-types.js +1 -0
  183. package/dist/pdf/text.d.ts +13 -0
  184. package/dist/pdf/text.js +101 -0
  185. package/dist/pdf/truetype-subset.d.ts +5 -0
  186. package/dist/pdf/truetype-subset.js +217 -0
  187. package/dist/pdf/truetype.d.ts +1 -0
  188. package/dist/pdf/truetype.js +235 -0
  189. package/dist/pdf/types.d.ts +171 -0
  190. package/dist/pdf/types.js +1 -0
  191. package/dist/pdf/write.d.ts +6 -0
  192. package/dist/pdf/write.js +57 -0
  193. package/dist/pdf/xref.d.ts +1 -0
  194. package/dist/pdf/xref.js +30 -0
  195. package/dist/xlsx/attachments.d.ts +30 -0
  196. package/dist/xlsx/attachments.js +67 -0
  197. package/dist/xlsx/chart-bindings.d.ts +1 -0
  198. package/dist/xlsx/chart-bindings.js +122 -0
  199. package/dist/xlsx/chart-types.d.ts +73 -0
  200. package/dist/xlsx/chart-types.js +1 -0
  201. package/dist/xlsx/chart-xml.d.ts +2 -0
  202. package/dist/xlsx/chart-xml.js +103 -0
  203. package/dist/xlsx/charts.d.ts +1 -0
  204. package/dist/xlsx/charts.js +159 -0
  205. package/dist/xlsx/conditional-formatting.d.ts +1 -0
  206. package/dist/xlsx/conditional-formatting.js +158 -0
  207. package/dist/xlsx/conditional-types.d.ts +64 -0
  208. package/dist/xlsx/conditional-types.js +1 -0
  209. package/dist/xlsx/data-row-ranges.d.ts +5 -0
  210. package/dist/xlsx/data-row-ranges.js +39 -0
  211. package/dist/xlsx/differential-styles.d.ts +1 -0
  212. package/dist/xlsx/differential-styles.js +102 -0
  213. package/dist/xlsx/formula.d.ts +8 -0
  214. package/dist/xlsx/formula.js +104 -0
  215. package/dist/xlsx/grouped-layout.d.ts +61 -0
  216. package/dist/xlsx/grouped-layout.js +79 -0
  217. package/dist/xlsx/grouped.d.ts +16 -0
  218. package/dist/xlsx/grouped.js +161 -0
  219. package/dist/xlsx/index.d.ts +24 -0
  220. package/dist/xlsx/index.js +10 -0
  221. package/dist/xlsx/layout.d.ts +1 -0
  222. package/dist/xlsx/layout.js +186 -0
  223. package/dist/xlsx/options.d.ts +1 -0
  224. package/dist/xlsx/options.js +16 -0
  225. package/dist/xlsx/portable.d.ts +27 -0
  226. package/dist/xlsx/portable.js +44 -0
  227. package/dist/xlsx/preservation.d.ts +1 -0
  228. package/dist/xlsx/preservation.js +60 -0
  229. package/dist/xlsx/ranges.d.ts +1 -0
  230. package/dist/xlsx/ranges.js +24 -0
  231. package/dist/xlsx/regions.d.ts +1 -0
  232. package/dist/xlsx/regions.js +97 -0
  233. package/dist/xlsx/structured-rows.d.ts +11 -0
  234. package/dist/xlsx/structured-rows.js +28 -0
  235. package/dist/xlsx/style-xml.d.ts +1 -0
  236. package/dist/xlsx/style-xml.js +6 -0
  237. package/dist/xlsx/styles.d.ts +70 -0
  238. package/dist/xlsx/styles.js +203 -0
  239. package/dist/xlsx/table.d.ts +12 -0
  240. package/dist/xlsx/table.js +35 -0
  241. package/dist/xlsx/types.d.ts +180 -0
  242. package/dist/xlsx/types.js +1 -0
  243. package/dist/xlsx/validation-types.d.ts +18 -0
  244. package/dist/xlsx/validation-types.js +1 -0
  245. package/dist/xlsx/validation.d.ts +1 -0
  246. package/dist/xlsx/validation.js +92 -0
  247. package/dist/xlsx/values.d.ts +13 -0
  248. package/dist/xlsx/values.js +87 -0
  249. package/dist/xlsx/workbook.d.ts +50 -0
  250. package/dist/xlsx/workbook.js +452 -0
  251. package/dist/xlsx/worksheet.d.ts +71 -0
  252. package/dist/xlsx/worksheet.js +700 -0
  253. package/dist/xlsx/write.d.ts +15 -0
  254. package/dist/xlsx/write.js +47 -0
  255. package/dist/xml/index.d.ts +24 -0
  256. package/dist/xml/index.js +74 -0
  257. package/dist/zip/entry.d.ts +39 -0
  258. package/dist/zip/entry.js +122 -0
  259. package/dist/zip/index.d.ts +44 -0
  260. package/dist/zip/index.js +248 -0
  261. package/package.json +104 -4
@@ -0,0 +1,186 @@
1
+ import { ExportCell } from "../core/presentation.js";
2
+ import { isDate } from "../core/dates.js";
3
+ import { Cell, cellText, columnName } from "./values.js";
4
+ import { FormulaCell } from "./formula.js";
5
+ import { escapeOoxmlAttribute } from "../xml/index.js";
6
+ import { MergeRegions } from "./regions.js";
7
+ import { OfficeIMOError } from "../core/errors.js";
8
+ import { createTotals } from "../internal/totals.js";
9
+ import { StructuredRows } from "./structured-rows.js";
10
+ /** @internal A computed formula with a numeric cache; no public arbitrary-formula input. */
11
+ export class ComputedTotal {
12
+ value;
13
+ formula;
14
+ operation;
15
+ constructor(value, formula, operation) {
16
+ this.value = value;
17
+ this.formula = formula;
18
+ this.operation = operation;
19
+ }
20
+ }
21
+ /** @internal Bounded report layout and incremental numeric aggregates. */
22
+ export class ReportLayout {
23
+ columns;
24
+ options;
25
+ headings;
26
+ merges;
27
+ headerRows;
28
+ firstHeaderRow;
29
+ regions;
30
+ widths;
31
+ sampleRows;
32
+ structuredFooter;
33
+ footerRows;
34
+ mergeCount;
35
+ aggregates;
36
+ constructor(columns, options, policy, maximumMerges = 10000, maximumSampleCells = 100000) {
37
+ this.columns = columns;
38
+ this.options = options;
39
+ const titleRows = options.title === undefined ? 0 : 1;
40
+ if (options.title !== undefined) {
41
+ if (!columns.length)
42
+ throw new TypeError("Report titles require declared columns.");
43
+ if (typeof options.title.text !== "string")
44
+ throw new TypeError("Report title text must be a string.");
45
+ cellText(options.title.text, policy);
46
+ if (options.title.height !== undefined && (!Number.isFinite(options.title.height) || options.title.height <= 0 || options.title.height > 409))
47
+ throw new RangeError("Title height must be positive and at most 409 points.");
48
+ }
49
+ const depth = Math.max(0, ...columns.map(c => c.groups?.length ?? 0));
50
+ if (options.headerRows === undefined) {
51
+ if (depth > 16)
52
+ throw new RangeError("Grouped headings support at most 16 levels.");
53
+ if (depth && options.includeHeader === false)
54
+ throw new TypeError("Grouped headings require leaf headers.");
55
+ }
56
+ const headings = [], merges = [];
57
+ if (titleRows && columns.length > 1)
58
+ merges.push("A1:" + columnName(columns.length) + "1");
59
+ if (options.headerRows !== undefined && options.includeHeader !== false) {
60
+ const structured = new StructuredRows(options.headerRows, columns.length);
61
+ if ((options.table || options.autoFilter) && !structured.matchesLeaf(columns.map(c => c.header)))
62
+ throw new TypeError("Native tables and autofilters require an unmerged final heading row matching the declared leaf headers.");
63
+ headings.push(...structured.values);
64
+ merges.push(...structured.merges(titleRows));
65
+ }
66
+ else if (options.includeHeader !== false) {
67
+ for (let level = 0; level < depth; level++) {
68
+ const values = columns.map(c => c.groups?.[level] ?? "");
69
+ for (const value of values)
70
+ cellText(value, policy);
71
+ for (let first = 0; first < columns.length;) {
72
+ let last = first;
73
+ const prefix = JSON.stringify(columns[first].groups?.slice(0, level + 1));
74
+ while (last + 1 < columns.length && values[first] && JSON.stringify(columns[last + 1].groups?.slice(0, level + 1)) === prefix)
75
+ last++;
76
+ if (last > first) {
77
+ merges.push(columnName(first + 1) + (level + 1 + titleRows) + ":" + columnName(last + 1) + (level + 1 + titleRows));
78
+ for (let i = first + 1; i <= last; i++)
79
+ values[i] = "";
80
+ }
81
+ first = last + 1;
82
+ }
83
+ headings.push(values);
84
+ }
85
+ if (columns.length)
86
+ headings.push(columns.map(c => c.header));
87
+ }
88
+ this.headerRows = titleRows + headings.length;
89
+ this.firstHeaderRow = columns.length && options.includeHeader !== false ? titleRows + 1 : 0;
90
+ if (options.mergedCells !== undefined && !Array.isArray(options.mergedCells))
91
+ throw new TypeError("Merged ranges must be an array.");
92
+ if (options.footer?.rows !== undefined && (options.footer.values !== undefined || options.footer.totals !== undefined))
93
+ throw new TypeError("Structured footer rows cannot accompany footer values or totals.");
94
+ this.structuredFooter = options.footer?.rows === undefined ? undefined : new StructuredRows(options.footer.rows, columns.length);
95
+ this.footerRows = this.structuredFooter?.values.length ?? (options.footer ? 1 : 0);
96
+ this.mergeCount = merges.length + (options.mergedCells?.length ?? 0) + (this.structuredFooter?.mergeCount ?? 0);
97
+ if (this.mergeCount > maximumMerges)
98
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxMergedRanges exceeded.");
99
+ this.regions = new MergeRegions([...merges, ...(options.mergedCells ?? [])], columns.length, maximumMerges);
100
+ if (options.table)
101
+ for (const ref of options.mergedCells ?? [])
102
+ if (Number(ref.split(":")[1].match(/\d+$/)[0]) >= this.headerRows)
103
+ throw new TypeError("Merged ranges cannot intersect a native table.");
104
+ this.headings = headings;
105
+ this.merges = this.regions.references;
106
+ const sizing = options.autoSize;
107
+ this.sampleRows = sizing ? sizing.sampleRows ?? Math.min(100, Math.floor(maximumSampleCells / Math.max(1, columns.length))) : 0;
108
+ if (!Number.isInteger(this.sampleRows) || this.sampleRows < 0 || this.sampleRows > 1048576)
109
+ throw new RangeError("Width sampling must use from 0 through 1,048,576 rows within its buffer budgets.");
110
+ const min = sizing?.minWidth ?? 8, max = sizing?.maxWidth ?? 60;
111
+ if (!Number.isFinite(min) || !Number.isFinite(max) || min < 0 || min > max || max > 255)
112
+ throw new RangeError("Width bounds must satisfy 0 <= minWidth <= maxWidth <= 255.");
113
+ this.widths = columns.map(c => c.width ?? (sizing ? Math.max(min, Math.min(max, c.header.length + 2)) : undefined));
114
+ if (options.footer?.values && options.footer.values.length > columns.length)
115
+ throw new RangeError("Footer has more values than declared columns.");
116
+ this.aggregates = createTotals(columns, options.footer?.totals);
117
+ if (options.print)
118
+ validatePrint(options.print, policy);
119
+ }
120
+ /** Resolve appended footer coordinates only after the streamed data row count is known. */
121
+ finalRegions(rows, maximumMerges) {
122
+ return this.structuredFooter ? new MergeRegions([...this.merges, ...this.structuredFooter.merges(this.headerRows + rows)], this.columns.length, maximumMerges) : this.regions;
123
+ }
124
+ sample(values) {
125
+ const min = this.options.autoSize?.minWidth ?? 8, max = this.options.autoSize?.maxWidth ?? 60;
126
+ values.forEach((value, i) => {
127
+ if (!this.columns[i] || this.columns[i].width !== undefined)
128
+ return;
129
+ const raw = value instanceof FormulaCell ? value.cachedValue : value instanceof ExportCell ? value.text ?? value.value : value instanceof Cell ? value.value : value;
130
+ const text = isDate(raw) ? Number.isFinite(raw.getTime()) ? raw.toISOString() : "" : raw == null ? "" : String(raw);
131
+ // Inspect at most a small prefix. A single long value cannot make a huge sampling allocation.
132
+ const length = Math.max(0, ...text.slice(0, Math.ceil(max * 4)).split(/\r?\n/).map(line => [...line].length));
133
+ this.widths[i] = Math.max(this.widths[i] ?? min, Math.min(max, length + 2));
134
+ });
135
+ }
136
+ accept(index, value) {
137
+ this.aggregates[index].accept(value);
138
+ }
139
+ footer(rows) {
140
+ return this.columns.map((_, i) => {
141
+ const total = this.aggregates[i], operation = total.operation;
142
+ if (!operation)
143
+ return this.options.footer?.values?.[i];
144
+ const value = total.value();
145
+ return new ComputedTotal(value, totalFormula(operation, columnName(i + 1), this.headerRows, rows), operation);
146
+ });
147
+ }
148
+ }
149
+ /** @internal Worksheet formulas and native table metadata must describe the same calculation. */
150
+ export function totalFormula(operation, letter, headerRows, rows) {
151
+ const code = { sum: 109, count: 102, average: 101, min: 105, max: 104 }[operation];
152
+ const guarded = ["average", "min", "max"].includes(operation);
153
+ const range = letter + (headerRows + 1) + ":" + letter + (headerRows + rows), subtotal = "SUBTOTAL(" + code + "," + range + ")";
154
+ return !rows ? guarded ? '""' : "0" : guarded ? 'IF(SUBTOTAL(102,' + range + ')=0,"",' + subtotal + ')' : subtotal;
155
+ }
156
+ function validatePrint(options, policy) {
157
+ if (options.paper !== undefined && !["A4", "Letter"].includes(options.paper))
158
+ throw new TypeError("Print paper must be A4 or Letter.");
159
+ if (options.orientation !== undefined && !["portrait", "landscape"].includes(options.orientation))
160
+ throw new TypeError("Invalid print orientation.");
161
+ for (const value of [options.fitToWidth, options.fitToHeight])
162
+ if (value !== undefined && (!Number.isInteger(value) || value < 0 || value > 32767))
163
+ throw new RangeError("Print fit dimensions must be integers from 0 through 32,767.");
164
+ for (const value of Object.values(options.margins ?? {}))
165
+ if (!Number.isFinite(value) || value < 0 || value > 10)
166
+ throw new RangeError("Print margins must be from 0 through 10 inches.");
167
+ for (const text of [options.header, options.footer])
168
+ if (text !== undefined) {
169
+ if (typeof text !== "string" || text.length > 250)
170
+ throw new TypeError("Print header/footer must be strings of at most 250 UTF-16 units.");
171
+ cellText(text, policy);
172
+ if (("&C" + text.replace(/&/g, "&&")).length > 255)
173
+ throw new RangeError("Encoded print header/footer exceeds Excel's 255-character limit.");
174
+ }
175
+ }
176
+ /** @internal XML follows the worksheet schema's pageMargins/pageSetup/headerFooter order. */
177
+ export function printXml(options, policy) {
178
+ if (!options)
179
+ return "";
180
+ const margins = { left: .25, right: .25, top: .5, bottom: .5, header: .2, footer: .2, ...options.margins };
181
+ return '<pageMargins' + Object.entries(margins).map(([key, value]) => ' ' + key + '="' + value + '"').join("") + '/>' +
182
+ '<pageSetup paperSize="' + (options.paper === "Letter" ? 1 : 9) + '" orientation="' + (options.orientation ?? "landscape") + '" fitToWidth="' + (options.fitToWidth ?? 1) + '" fitToHeight="' + (options.fitToHeight ?? 0) + '"/>' +
183
+ (options.header !== undefined || options.footer !== undefined ? '<headerFooter>' +
184
+ (options.header === undefined ? "" : '<oddHeader>' + escapeOoxmlAttribute("&C" + options.header.replace(/&/g, "&&"), policy) + '</oddHeader>') +
185
+ (options.footer === undefined ? "" : '<oddFooter>' + escapeOoxmlAttribute("&C" + options.footer.replace(/&/g, "&&"), policy) + '</oddFooter>') + '</headerFooter>' : "");
186
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { captureFields } from "../internal/capture.js";
2
+ /** @internal The workbook owner captures these settings before validation or adapter merging. */
3
+ export const workbookOptionFields = ["signal", "onProgress", "limits", "sink", "dateMode", "compression", "invalidCharacterPolicy", "appProperties", "cellValueWriters", "oversizedText", "creator", "title", "subject", "description", "created", "modified"];
4
+ /** @internal Worksheet settings also used by the portable sheet owner. */
5
+ export const sheetOptionFields = ["columns", "includeHeader", "headerRows", "freezeHeader", "autoFilter", "boldHeader", "headerFill", "headerStyle", "alternatingRowStyle", "rowStyle", "cellStyle", "rowOutline", "maxOutlineLevel", "rowHeight", "headerHeight", "defaultColumnWidth", "freezeColumns", "table", "autoSize", "footer", "print", "title", "mergedCells", "hyperlinks", "conditionalFormats", "dataValidation"];
6
+ /** @internal Includes inherited format-specific ceilings before a wrapper combines stream settings. */
7
+ export const workbookLimitFields = ["maxRows", "maxCells", "maxTextCharacters", "maxOutputBytes", "maxStyles", "maxSheets", "maxOverflowCharacters", "maxHyperlinks", "maxImageBytes", "maxBufferedCells", "maxBufferedCharacters", "maxMergedRanges", "maxConditionalFormats", "maxDifferentialStyles", "maxCharts", "maxChartPoints", "maxChartTextCharacters", "maxFormulaCharacters", "maxDataValidations", "maxValidationTextCharacters"];
8
+ /** @internal Capture the workbook's known ceilings without dropping supported prototype fields. */
9
+ export function captureWorkbookLimits(limits) {
10
+ return captureFields(limits, workbookLimitFields);
11
+ }
12
+ /** @internal One immutable-input capture for direct workbooks and thin portable writers. */
13
+ export function captureWorkbookOptions(options) {
14
+ const captured = captureFields(options, workbookOptionFields);
15
+ return { ...captured, ...(captured.limits === undefined ? {} : { limits: captureWorkbookLimits(captured.limits) }) };
16
+ }
@@ -0,0 +1,27 @@
1
+ import type { ExportValue } from "../core/presentation.js";
2
+ import type { CellStyle, Font, Fill, Border } from "./styles.js";
3
+ import type { WorkbookOptions, SheetOptions, CellWriterContext, RowStyleContext, CellStyleContext, ReportTitle, FooterOptions } from "./types.js";
4
+ /** Style definitions that do not refer to a workbook's component indexes. */
5
+ export interface PortableCellStyle extends Omit<CellStyle, "font" | "fill" | "border" | "numberFormat"> {
6
+ readonly font?: Font;
7
+ readonly fill?: Fill;
8
+ readonly border?: Border;
9
+ readonly numberFormat?: string;
10
+ }
11
+ /** Settings for writers that own their workbook and accept resolved portable values. */
12
+ export interface PortableWorkbookOptions extends Omit<WorkbookOptions, "sink" | "cellValueWriters"> {
13
+ readonly cellValueWriters?: Readonly<Record<string, (value: import("../core/index.js").CellValue, context: CellWriterContext) => ExportValue>>;
14
+ }
15
+ /** Report layout and presentation without workbook-local style or Cell indexes. */
16
+ export interface PortableSheetOptions extends Omit<SheetOptions, "columns" | "headerStyle" | "alternatingRowStyle" | "rowStyle" | "cellStyle" | "title" | "footer"> {
17
+ readonly alternatingRowStyle?: PortableCellStyle;
18
+ readonly rowStyle?: (context: RowStyleContext) => PortableCellStyle | undefined;
19
+ readonly cellStyle?: (context: CellStyleContext) => PortableCellStyle | undefined;
20
+ readonly title?: Omit<ReportTitle, "style"> & {
21
+ readonly style?: PortableCellStyle;
22
+ };
23
+ readonly footer?: Omit<FooterOptions, "values" | "style"> & {
24
+ readonly values?: readonly ExportValue[];
25
+ readonly style?: PortableCellStyle;
26
+ };
27
+ }
@@ -0,0 +1,44 @@
1
+ import { ExportCell, assertScalar } from "../core/presentation.js";
2
+ import { captureWorkbookOptions, sheetOptionFields } from "./options.js";
3
+ import { captureFields } from "../internal/capture.js";
4
+ function style(patch) {
5
+ for (const component of ["font", "fill", "border", "numberFormat"])
6
+ if (typeof patch?.[component] === "number")
7
+ throw new TypeError("Workbook-local style indexes require the advanced Workbook API; use style definitions.");
8
+ return patch;
9
+ }
10
+ function value(result) {
11
+ if (!(result instanceof ExportCell))
12
+ assertScalar(result);
13
+ return result;
14
+ }
15
+ /** @internal Qualify the portable boundary before source/destination activity. */
16
+ export function portableSheet(options = {}) {
17
+ options = captureFields(options, sheetOptionFields);
18
+ if (options.headerStyle !== undefined)
19
+ throw new TypeError("Workbook-local header styles require the advanced Workbook API; use boldHeader and headerFill.");
20
+ style(options.alternatingRowStyle);
21
+ style(options.title?.style);
22
+ style(options.footer?.style);
23
+ options.footer?.values?.forEach(value);
24
+ const rowStyle = options.rowStyle, cellStyle = options.cellStyle;
25
+ for (const callback of [rowStyle, cellStyle])
26
+ if (callback !== undefined && typeof callback !== "function")
27
+ throw new TypeError("Style callbacks must be functions.");
28
+ return { ...options, ...(rowStyle ? { rowStyle: (context) => style(rowStyle(context)) } : {}),
29
+ ...(cellStyle ? { cellStyle: (context) => style(cellStyle(context)) } : {}) };
30
+ }
31
+ /** @internal Keep custom writers inside the same portable value contract. */
32
+ export function portableWorkbook(options = {}) {
33
+ options = captureWorkbookOptions(options);
34
+ const writers = options.cellValueWriters;
35
+ if (!writers)
36
+ return options;
37
+ const wrapped = Object.create(null);
38
+ for (const [type, writer] of Object.entries(writers)) {
39
+ if (typeof writer !== "function")
40
+ throw new TypeError("Cell value writers must be functions.");
41
+ wrapped[type] = (input, context) => value(writer(input, context));
42
+ }
43
+ return { ...options, cellValueWriters: wrapped };
44
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,60 @@
1
+ import { OfficeIMOError } from "../core/errors.js";
2
+ import { cleanXml } from "../xml/index.js";
3
+ /** @internal Overflow is deliberately bounded: ZIP worksheet entries cannot be interleaved. */
4
+ export class TextOverflow {
5
+ sheetName;
6
+ maximum;
7
+ policy;
8
+ reserve;
9
+ entries = [];
10
+ characters = 0;
11
+ rows = 0;
12
+ constructor(sheetName, maximum, policy, reserve) {
13
+ this.sheetName = sheetName;
14
+ this.maximum = maximum;
15
+ this.policy = policy;
16
+ this.reserve = reserve;
17
+ }
18
+ add(sheet, cell, value) {
19
+ const text = cleanXml(value, this.policy);
20
+ if (this.characters + text.length > this.maximum)
21
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxOverflowCharacters exceeded; use CSV or raise the bounded preservation limit.");
22
+ let parts = 0;
23
+ for (const _ of splitText(text)) {
24
+ void _;
25
+ parts++;
26
+ }
27
+ if (this.rows + parts > 1048575)
28
+ throw new OfficeIMOError("RESOURCE_LIMIT", "Text overflow exceeds the worksheet row limit.");
29
+ this.reserve(parts * 5, text.length + parts * (sheet.length + cell.length), this.rows + parts);
30
+ const first = this.rows + 2;
31
+ this.entries.push({ sheet, cell, text, first, parts });
32
+ this.rows += parts;
33
+ this.characters += text.length;
34
+ const marker = "\n[Full text: " + this.sheetName + "!D" + first + "; " + parts + " parts]";
35
+ return { preview: clipText(text, 32767 - marker.length) + marker, location: "'" + this.sheetName.replace(/'/g, "''") + "'!D" + first };
36
+ }
37
+ *values() {
38
+ for (const entry of this.entries) {
39
+ let part = 0;
40
+ for (const text of splitText(entry.text))
41
+ yield [entry.sheet, entry.cell, ++part, text, entry.parts];
42
+ }
43
+ }
44
+ clear() { this.entries = []; this.characters = 0; this.rows = 0; }
45
+ }
46
+ /** @internal Clip at a UTF-16 boundary without splitting a valid supplementary character. */
47
+ export function clipText(text, maximum) {
48
+ let end = Math.min(maximum, text.length);
49
+ if (end < text.length && /[\ud800-\udbff]/.test(text[end - 1] ?? ""))
50
+ end--;
51
+ return text.slice(0, end);
52
+ }
53
+ function* splitText(text) {
54
+ let offset = 0;
55
+ while (offset < text.length) {
56
+ const part = clipText(text.slice(offset, offset + 32768), 32767);
57
+ offset += part.length;
58
+ yield part;
59
+ }
60
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ import { columnName } from "./values.js";
2
+ /** @internal Data-column selectors use stable keys or one-based worksheet columns. */
3
+ export function resolveDataColumn(columns, value, context = "Data") {
4
+ if (typeof value === "string") {
5
+ const matches = columns.flatMap((column, index) => column.key === value ? [index + 1] : []);
6
+ if (matches.length !== 1)
7
+ throw new TypeError(context + " column keys must identify exactly one declared column.");
8
+ return matches[0];
9
+ }
10
+ if (!Number.isInteger(value) || value < 1 || value > columns.length)
11
+ throw new RangeError(context + " column numbers must be one-based and within declared columns.");
12
+ return value;
13
+ }
14
+ /** @internal Formula references use literal final worksheet names and finite physical coordinates. */
15
+ export function qualifiedColumnRange(sheetName, column, firstRow, rows) {
16
+ if (!Number.isSafeInteger(firstRow) || firstRow < 1 || !Number.isSafeInteger(rows) || rows < 1 || firstRow + rows - 1 > 1048576)
17
+ throw new RangeError("A data range must fit within Excel's worksheet rows.");
18
+ const letter = columnName(column);
19
+ return "'" + sheetName.replace(/'/g, "''") + "'!$" + letter + "$" + firstRow + ":$" + letter + "$" + (firstRow + rows - 1);
20
+ }
21
+ /** @internal A series header is a single cell rather than a one-cell range. */
22
+ export function qualifiedCell(sheetName, column, row) {
23
+ return qualifiedColumnRange(sheetName, column, row, 1).split(":")[0];
24
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,97 @@
1
+ import { OfficeIMOError } from "../core/errors.js";
2
+ import { cellPosition } from "./attachments.js";
3
+ function indexRows(regions) {
4
+ if (!regions.length)
5
+ return undefined;
6
+ const ordered = [...regions].sort((a, b) => a.top - b.top), middle = ordered[Math.floor(ordered.length / 2)].top;
7
+ const crossing = [], before = [], after = [];
8
+ for (const region of ordered)
9
+ (region.bottom < middle ? before : region.top > middle ? after : crossing).push(region);
10
+ const left = indexRows(before), right = indexRows(after);
11
+ return { middle, starts: crossing, ends: [...crossing].sort((a, b) => b.bottom - a.bottom), ...(left ? { before: left } : {}), ...(right ? { after: right } : {}) };
12
+ }
13
+ function rowRegions(index, row, output) {
14
+ if (!index)
15
+ return;
16
+ for (const region of row <= index.middle ? index.starts : index.ends) {
17
+ if (row <= index.middle ? region.top > row : region.bottom < row)
18
+ break;
19
+ output.push(region);
20
+ }
21
+ rowRegions(row < index.middle ? index.before : row > index.middle ? index.after : undefined, row, output);
22
+ }
23
+ /** @internal Retained metadata only. Row lookup avoids scanning every merge for every exported cell. */
24
+ export class MergeRegions {
25
+ references;
26
+ index;
27
+ currentRow = -1;
28
+ current = [];
29
+ lastRow;
30
+ constructor(references, columns, maximum) {
31
+ if (references.length > maximum)
32
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxMergedRanges exceeded.");
33
+ if (!references.length) {
34
+ this.references = Object.freeze([]);
35
+ this.lastRow = 0;
36
+ this.index = undefined;
37
+ return;
38
+ }
39
+ const regions = references.map(ref => {
40
+ if (typeof ref !== "string" || ref.split(":").length !== 2)
41
+ throw new TypeError("Merged ranges require uppercase A1:B2 references.");
42
+ const [first, last] = ref.split(":"), start = cellPosition(first), end = cellPosition(last);
43
+ if (end.row < start.row || end.column < start.column || (end.row === start.row && end.column === start.column))
44
+ throw new RangeError("Merged ranges require ordered distinct cells.");
45
+ if (end.column > columns)
46
+ throw new RangeError("Merged ranges must stay within declared columns.");
47
+ return { ref, top: start.row, bottom: end.row, left: start.column, right: end.column };
48
+ });
49
+ // A row sweep and column range tree detect rectangle overlaps without a quadratic pair scan.
50
+ const events = regions.flatMap(r => [{ row: r.top, delta: 1, region: r }, { row: r.bottom + 1, delta: -1, region: r }]).sort((a, b) => a.row - b.row || a.delta - b.delta);
51
+ const counts = new Int32Array(65536), lazy = new Int32Array(65536);
52
+ function update(node, first, last, left, right, delta) {
53
+ if (left <= first && last <= right) {
54
+ counts[node] = counts[node] + delta;
55
+ lazy[node] = lazy[node] + delta;
56
+ return;
57
+ }
58
+ const middle = (first + last) >>> 1;
59
+ if (left <= middle)
60
+ update(node * 2, first, middle, left, right, delta);
61
+ if (right > middle)
62
+ update(node * 2 + 1, middle + 1, last, left, right, delta);
63
+ counts[node] = lazy[node] + Math.max(counts[node * 2], counts[node * 2 + 1]);
64
+ }
65
+ for (const event of events) {
66
+ update(1, 1, 16384, event.region.left, event.region.right, event.delta);
67
+ if (counts[1] > 1)
68
+ throw new TypeError("Merged ranges must not overlap: " + event.region.ref);
69
+ }
70
+ this.references = Object.freeze(regions.map(r => r.ref));
71
+ this.lastRow = regions.reduce((last, r) => Math.max(last, r.bottom), 0);
72
+ this.index = indexRows(regions);
73
+ }
74
+ covered(column, row) {
75
+ if (!this.index || row > this.lastRow)
76
+ return false;
77
+ if (this.currentRow !== row) {
78
+ this.current = [];
79
+ rowRegions(this.index, row, this.current);
80
+ this.current.sort((a, b) => a.left - b.left);
81
+ this.currentRow = row;
82
+ }
83
+ let first = 0, last = this.current.length - 1;
84
+ while (first <= last) {
85
+ const middle = (first + last) >>> 1, region = this.current[middle];
86
+ if (column < region.left)
87
+ last = middle - 1;
88
+ else if (column > region.right)
89
+ first = middle + 1;
90
+ else
91
+ return row !== region.top || column !== region.left;
92
+ }
93
+ return false;
94
+ }
95
+ validateRows(rows) { if (this.lastRow > rows)
96
+ throw new RangeError("Merged ranges must stay within exported rows."); }
97
+ }
@@ -0,0 +1,11 @@
1
+ import type { TableSpanRows } from "../core/index.js";
2
+ /** Bounded heading/footer values and relative merges captured before row production. */
3
+ export declare class StructuredRows {
4
+ readonly values: readonly (readonly unknown[])[];
5
+ private readonly ranges;
6
+ constructor(rows: TableSpanRows, columns: number);
7
+ get mergeCount(): number;
8
+ merges(offset: number): readonly string[];
9
+ /** A native filter/table requires one real leaf cell for each declared column. */
10
+ matchesLeaf(headers: readonly string[]): boolean;
11
+ }
@@ -0,0 +1,28 @@
1
+ import { ExportCell } from "../core/presentation.js";
2
+ import { tableSpans } from "../internal/table-spans.js";
3
+ import { copyValue, columnName } from "./values.js";
4
+ /** Bounded heading/footer values and relative merges captured before row production. */
5
+ export class StructuredRows {
6
+ values;
7
+ ranges;
8
+ constructor(rows, columns) {
9
+ const anchors = tableSpans(rows, columns), ranges = [];
10
+ this.values = anchors.map((row, level) => {
11
+ const values = Array(columns).fill(undefined);
12
+ for (const anchor of row) {
13
+ values[anchor.first] = copyValue(anchor.value);
14
+ if (anchor.span > 1 || anchor.rowSpan > 1)
15
+ ranges.push({ first: anchor.first + 1, last: anchor.first + anchor.span, top: level + 1, bottom: level + anchor.rowSpan });
16
+ }
17
+ return Object.freeze(values);
18
+ });
19
+ this.ranges = ranges;
20
+ }
21
+ get mergeCount() { return this.ranges.length; }
22
+ merges(offset) { return this.ranges.map(r => columnName(r.first) + (r.top + offset) + ":" + columnName(r.last) + (r.bottom + offset)); }
23
+ /** A native filter/table requires one real leaf cell for each declared column. */
24
+ matchesLeaf(headers) {
25
+ const last = this.values.length;
26
+ return !this.ranges.some(r => r.bottom === last) && this.values[last - 1].every((value, index) => (value instanceof ExportCell ? value.value : value) === headers[index]);
27
+ }
28
+ }
@@ -0,0 +1 @@
1
+ export declare function colorArgb(value: string): string;
@@ -0,0 +1,6 @@
1
+ export function colorArgb(value) {
2
+ if (typeof value !== "string" || !/^#?(?:[0-9a-f]{6}|[0-9a-f]{8})$/i.test(value))
3
+ throw new TypeError("Color must be RGB or ARGB hex.");
4
+ const color = value.replace(/^#/, "").toUpperCase();
5
+ return color.length === 6 ? "FF" + color : color;
6
+ }
@@ -0,0 +1,70 @@
1
+ import type { InvalidCharacterPolicy } from "../xml/index.js";
2
+ import type { Alignment } from "../core/index.js";
3
+ export { colorArgb } from "./style-xml.js";
4
+ export declare const spreadsheetNamespace = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
5
+ export interface Font {
6
+ readonly name?: string;
7
+ readonly size?: number;
8
+ readonly bold?: boolean;
9
+ readonly italic?: boolean;
10
+ readonly underline?: boolean;
11
+ readonly strike?: boolean;
12
+ readonly color?: string;
13
+ }
14
+ export interface Fill {
15
+ readonly pattern?: "none" | "gray125" | "solid";
16
+ readonly color?: string;
17
+ }
18
+ export type BorderLineStyle = "thin" | "medium" | "dashed" | "dotted" | "thick" | "double" | "hair" | "dashDot" | "dashDotDot" | "slantDashDot" | "mediumDashed" | "mediumDashDot" | "mediumDashDotDot";
19
+ export interface BorderEdge {
20
+ readonly style: BorderLineStyle;
21
+ readonly color?: string;
22
+ }
23
+ export interface Border {
24
+ readonly left?: BorderEdge;
25
+ readonly right?: BorderEdge;
26
+ readonly top?: BorderEdge;
27
+ readonly bottom?: BorderEdge;
28
+ }
29
+ export interface CellStyle {
30
+ readonly font?: number | Font;
31
+ readonly fill?: number | Fill;
32
+ readonly border?: number | Border;
33
+ readonly numberFormat?: string | number;
34
+ readonly wrapText?: boolean;
35
+ readonly alignment?: Alignment;
36
+ readonly verticalAlignment?: "top" | "center" | "bottom" | "justify" | "distributed";
37
+ }
38
+ export declare const NumberFormats: {
39
+ readonly General: "General";
40
+ readonly Integer: "0";
41
+ readonly Decimal: "0.00";
42
+ readonly Percent: "0.00%";
43
+ readonly Date: "yyyy-mm-dd";
44
+ readonly DateTime: "yyyy-mm-dd hh:mm:ss";
45
+ };
46
+ /** Workbook-owned indexes. Definition inputs are normalized and copied, never retained by reference. */
47
+ export declare class StyleRegistry {
48
+ private readonly policy;
49
+ private readonly maximum;
50
+ private readonly differential;
51
+ private readonly fonts;
52
+ private readonly fills;
53
+ private readonly borders;
54
+ private readonly formats;
55
+ private readonly styles;
56
+ private readonly indexes;
57
+ private readonly fontIndexes;
58
+ private readonly fillIndexes;
59
+ private readonly borderIndexes;
60
+ constructor(policy?: InvalidCharacterPolicy, maximum?: number, maximumDifferential?: number);
61
+ addFont(font: Font): number;
62
+ addFill(fill: Fill): number;
63
+ addBorder(border: Border): number;
64
+ addNumberFormat(format: string): number;
65
+ add(style?: CellStyle): number;
66
+ validateStyle(id: number): number;
67
+ /** Overlay presentation while retaining the base number format, font fields and border edges. Numeric component indexes replace a component. */
68
+ compose(base: number, overlay: CellStyle): number;
69
+ toXml(): string;
70
+ }