@evotecit/officeimo 0.0.0-stage → 0.1.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 (259) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1219 -2
  3. package/bundles/officeimo-canopyx.js +11286 -0
  4. package/bundles/officeimo-canopyx.mjs +11185 -0
  5. package/bundles/officeimo-csv.js +1254 -0
  6. package/bundles/officeimo-csv.mjs +1229 -0
  7. package/bundles/officeimo-datatables.js +11572 -0
  8. package/bundles/officeimo-datatables.mjs +11470 -0
  9. package/bundles/officeimo-execution.js +1503 -0
  10. package/bundles/officeimo-execution.mjs +1479 -0
  11. package/bundles/officeimo-pdf.js +6564 -0
  12. package/bundles/officeimo-pdf.mjs +6502 -0
  13. package/bundles/officeimo-xlsx.js +5333 -0
  14. package/bundles/officeimo-xlsx.mjs +5279 -0
  15. package/bundles/officeimo.js +11022 -0
  16. package/bundles/officeimo.mjs +10924 -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 +72 -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 +101 -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 +116 -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 +68 -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 +194 -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 +201 -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 +142 -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 +143 -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 +679 -0
  145. package/dist/pdf/paragraph-layout.d.ts +19 -0
  146. package/dist/pdf/paragraph-layout.js +66 -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 +15 -0
  164. package/dist/pdf/settings.js +171 -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 +250 -0
  173. package/dist/pdf/table-band-flow.d.ts +34 -0
  174. package/dist/pdf/table-band-flow.js +114 -0
  175. package/dist/pdf/table-band-plan.d.ts +10 -0
  176. package/dist/pdf/table-band-plan.js +85 -0
  177. package/dist/pdf/table-layout.d.ts +71 -0
  178. package/dist/pdf/table-layout.js +205 -0
  179. package/dist/pdf/table-structure.d.ts +1 -0
  180. package/dist/pdf/table-structure.js +92 -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 +96 -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 +169 -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/xlsx/attachments.d.ts +30 -0
  194. package/dist/xlsx/attachments.js +67 -0
  195. package/dist/xlsx/chart-bindings.d.ts +1 -0
  196. package/dist/xlsx/chart-bindings.js +122 -0
  197. package/dist/xlsx/chart-types.d.ts +73 -0
  198. package/dist/xlsx/chart-types.js +1 -0
  199. package/dist/xlsx/chart-xml.d.ts +2 -0
  200. package/dist/xlsx/chart-xml.js +103 -0
  201. package/dist/xlsx/charts.d.ts +1 -0
  202. package/dist/xlsx/charts.js +159 -0
  203. package/dist/xlsx/conditional-formatting.d.ts +1 -0
  204. package/dist/xlsx/conditional-formatting.js +158 -0
  205. package/dist/xlsx/conditional-types.d.ts +64 -0
  206. package/dist/xlsx/conditional-types.js +1 -0
  207. package/dist/xlsx/data-row-ranges.d.ts +5 -0
  208. package/dist/xlsx/data-row-ranges.js +39 -0
  209. package/dist/xlsx/differential-styles.d.ts +1 -0
  210. package/dist/xlsx/differential-styles.js +102 -0
  211. package/dist/xlsx/formula.d.ts +8 -0
  212. package/dist/xlsx/formula.js +104 -0
  213. package/dist/xlsx/grouped-layout.d.ts +61 -0
  214. package/dist/xlsx/grouped-layout.js +79 -0
  215. package/dist/xlsx/grouped.d.ts +16 -0
  216. package/dist/xlsx/grouped.js +161 -0
  217. package/dist/xlsx/index.d.ts +24 -0
  218. package/dist/xlsx/index.js +10 -0
  219. package/dist/xlsx/layout.d.ts +1 -0
  220. package/dist/xlsx/layout.js +186 -0
  221. package/dist/xlsx/options.d.ts +1 -0
  222. package/dist/xlsx/options.js +16 -0
  223. package/dist/xlsx/portable.d.ts +27 -0
  224. package/dist/xlsx/portable.js +44 -0
  225. package/dist/xlsx/preservation.d.ts +1 -0
  226. package/dist/xlsx/preservation.js +60 -0
  227. package/dist/xlsx/ranges.d.ts +1 -0
  228. package/dist/xlsx/ranges.js +24 -0
  229. package/dist/xlsx/regions.d.ts +1 -0
  230. package/dist/xlsx/regions.js +97 -0
  231. package/dist/xlsx/structured-rows.d.ts +11 -0
  232. package/dist/xlsx/structured-rows.js +28 -0
  233. package/dist/xlsx/style-xml.d.ts +1 -0
  234. package/dist/xlsx/style-xml.js +6 -0
  235. package/dist/xlsx/styles.d.ts +70 -0
  236. package/dist/xlsx/styles.js +203 -0
  237. package/dist/xlsx/table.d.ts +12 -0
  238. package/dist/xlsx/table.js +35 -0
  239. package/dist/xlsx/types.d.ts +180 -0
  240. package/dist/xlsx/types.js +1 -0
  241. package/dist/xlsx/validation-types.d.ts +18 -0
  242. package/dist/xlsx/validation-types.js +1 -0
  243. package/dist/xlsx/validation.d.ts +1 -0
  244. package/dist/xlsx/validation.js +92 -0
  245. package/dist/xlsx/values.d.ts +13 -0
  246. package/dist/xlsx/values.js +86 -0
  247. package/dist/xlsx/workbook.d.ts +50 -0
  248. package/dist/xlsx/workbook.js +452 -0
  249. package/dist/xlsx/worksheet.d.ts +71 -0
  250. package/dist/xlsx/worksheet.js +700 -0
  251. package/dist/xlsx/write.d.ts +15 -0
  252. package/dist/xlsx/write.js +47 -0
  253. package/dist/xml/index.d.ts +24 -0
  254. package/dist/xml/index.js +74 -0
  255. package/dist/zip/entry.d.ts +39 -0
  256. package/dist/zip/entry.js +122 -0
  257. package/dist/zip/index.d.ts +44 -0
  258. package/dist/zip/index.js +248 -0
  259. package/package.json +104 -4
@@ -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
+ }
@@ -0,0 +1,203 @@
1
+ import { escapeOoxmlAttribute, cleanXml, xmlDeclaration } from "../xml/index.js";
2
+ import { OfficeIMOError } from "../core/errors.js";
3
+ import { colorArgb } from "./style-xml.js";
4
+ import { DifferentialStyles } from "./differential-styles.js";
5
+ export { colorArgb } from "./style-xml.js";
6
+ export const spreadsheetNamespace = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
7
+ export const NumberFormats = { General: "General", Integer: "0", Decimal: "0.00", Percent: "0.00%", Date: "yyyy-mm-dd", DateTime: "yyyy-mm-dd hh:mm:ss" };
8
+ function index(value, count, kind) {
9
+ if (!Number.isInteger(value) || value < 0 || value >= count)
10
+ throw new RangeError("Unknown " + kind + " index.");
11
+ return value;
12
+ }
13
+ function deduplicate(items, indexes, item, maximum) {
14
+ const key = JSON.stringify(item), found = indexes.get(key);
15
+ if (found !== undefined)
16
+ return found;
17
+ if (items.length >= maximum)
18
+ throw new OfficeIMOError("RESOURCE_LIMIT", "Style component limit exceeded.");
19
+ const id = items.length;
20
+ items.push(item);
21
+ indexes.set(key, id);
22
+ return id;
23
+ }
24
+ /** @internal Observe unsupported promises immediately, even when cell precedence skips the patch. */
25
+ export function validateStylePatch(patch) {
26
+ if (!patch || typeof patch !== "object" || Array.isArray(patch))
27
+ throw new TypeError("A style patch must be a CellStyle object.");
28
+ if (typeof patch.then === "function") {
29
+ void Promise.resolve(patch).catch(() => { });
30
+ throw new TypeError("Style patches must be synchronous CellStyle objects.");
31
+ }
32
+ }
33
+ /** @internal Capture reusable option patches without retaining caller-owned nested components. */
34
+ export function copyStylePatch(patch) {
35
+ validateStylePatch(patch);
36
+ return Object.freeze({ ...patch,
37
+ ...(typeof patch.font === "object" ? { font: Object.freeze({ ...patch.font }) } : {}),
38
+ ...(typeof patch.fill === "object" ? { fill: Object.freeze({ ...patch.fill }) } : {}),
39
+ ...(typeof patch.border === "object" ? { border: Object.freeze(Object.fromEntries(Object.entries(patch.border).map(([side, edge]) => [side, Object.freeze({ ...edge })]))) } : {})
40
+ });
41
+ }
42
+ /** Workbook-owned indexes. Definition inputs are normalized and copied, never retained by reference. */
43
+ export class StyleRegistry {
44
+ policy;
45
+ maximum;
46
+ differential;
47
+ fonts = [{ name: "Calibri", size: 11, bold: false, italic: false, underline: false, strike: false, color: "" }];
48
+ fills = [{ pattern: "none", color: "" }, { pattern: "gray125", color: "" }];
49
+ borders = [{}];
50
+ formats = new Map();
51
+ styles = [];
52
+ indexes = new Map();
53
+ fontIndexes = new Map(this.fonts.map((v, i) => [JSON.stringify(v), i]));
54
+ fillIndexes = new Map(this.fills.map((v, i) => [JSON.stringify(v), i]));
55
+ borderIndexes = new Map(this.borders.map((v, i) => [JSON.stringify(v), i]));
56
+ constructor(policy = "strip", maximum = 64000, maximumDifferential = 1000) {
57
+ this.policy = policy;
58
+ this.maximum = maximum;
59
+ if (!Number.isSafeInteger(maximum) || maximum < 1 || maximum > 64000)
60
+ throw new RangeError("maxStyles must be from 1 through 64,000.");
61
+ if (!Number.isSafeInteger(maximumDifferential) || maximumDifferential < 0)
62
+ throw new RangeError("maxDifferentialStyles must be a nonnegative safe integer.");
63
+ this.differential = new DifferentialStyles(policy, maximumDifferential, format => this.addNumberFormat(format));
64
+ cleanXml("", policy);
65
+ this.add();
66
+ }
67
+ /** @internal */
68
+ checkDifferentials(styles) {
69
+ // A batch must not register some dxfs before its shared number-format capacity fails.
70
+ const formats = new Set(styles.flatMap(style => style.numberFormat === undefined ? [] : [cleanXml(style.numberFormat, this.policy)])
71
+ .filter(format => format !== "General" && !this.formats.has(format)));
72
+ if (this.formats.size + formats.size > 65372)
73
+ throw new RangeError("Too many number formats.");
74
+ this.differential.check(styles);
75
+ }
76
+ /** @internal */
77
+ addDifferentials(styles) { this.checkDifferentials(styles); return this.differential.add(styles); }
78
+ addFont(font) {
79
+ if (font.name !== undefined && typeof font.name !== "string")
80
+ throw new TypeError("Font name must be a string.");
81
+ const name = cleanXml(font.name ?? "Calibri", this.policy), size = font.size ?? 11;
82
+ if (typeof name !== "string" || !name || name.length > 31)
83
+ throw new TypeError("Font name must contain 1 through 31 characters.");
84
+ if (!Number.isFinite(size) || size <= 0 || size > 409)
85
+ throw new RangeError("Font size must be positive and at most 409.");
86
+ return deduplicate(this.fonts, this.fontIndexes, { name, size, bold: !!font.bold, italic: !!font.italic, underline: !!font.underline, strike: !!font.strike, color: font.color ? colorArgb(font.color) : "" }, this.maximum);
87
+ }
88
+ addFill(fill) {
89
+ const pattern = fill.pattern ?? (fill.color ? "solid" : "none");
90
+ if (!["none", "gray125", "solid"].includes(pattern) || (pattern === "solid" && !fill.color) || (pattern !== "solid" && fill.color))
91
+ throw new TypeError("A solid fill requires a color; none and gray125 have no color.");
92
+ return deduplicate(this.fills, this.fillIndexes, { pattern, color: fill.color ? colorArgb(fill.color) : "" }, this.maximum + 1);
93
+ }
94
+ addBorder(border) {
95
+ const result = {};
96
+ for (const side of ["left", "right", "top", "bottom"]) {
97
+ const edge = border[side];
98
+ if (edge) {
99
+ if (!["thin", "medium", "dashed", "dotted", "thick", "double", "hair", "dashDot", "dashDotDot", "slantDashDot", "mediumDashed", "mediumDashDot", "mediumDashDotDot"].includes(edge.style))
100
+ throw new TypeError("Invalid border style.");
101
+ result[side] = { style: edge.style, ...(edge.color ? { color: colorArgb(edge.color) } : {}) };
102
+ }
103
+ }
104
+ return deduplicate(this.borders, this.borderIndexes, result, this.maximum);
105
+ }
106
+ addNumberFormat(format) {
107
+ if (typeof format !== "string" || !format || format.length > 255)
108
+ throw new TypeError("Number format must contain 1 through 255 characters.");
109
+ format = cleanXml(format, this.policy);
110
+ if (!format)
111
+ throw new TypeError("Number format must contain XML-valid characters.");
112
+ if (format === "General")
113
+ return 0;
114
+ let id = this.formats.get(format);
115
+ if (id === undefined) {
116
+ if (this.formats.size >= 65372)
117
+ throw new RangeError("Too many number formats.");
118
+ id = this.formats.size + 164;
119
+ this.formats.set(format, id);
120
+ }
121
+ return id;
122
+ }
123
+ add(style = {}) {
124
+ const font = typeof style.font === "number" ? index(style.font, this.fonts.length, "font") : style.font ? this.addFont(style.font) : 0;
125
+ const fill = typeof style.fill === "number" ? index(style.fill, this.fills.length, "fill") : style.fill ? this.addFill(style.fill) : 0;
126
+ const border = typeof style.border === "number" ? index(style.border, this.borders.length, "border") : style.border ? this.addBorder(style.border) : 0;
127
+ let numberFormat = 0;
128
+ if (typeof style.numberFormat === "string")
129
+ numberFormat = this.addNumberFormat(style.numberFormat);
130
+ else if (style.numberFormat !== undefined) {
131
+ numberFormat = style.numberFormat;
132
+ if (!Number.isInteger(numberFormat) || numberFormat < 0 || (numberFormat > 163 && ![...this.formats.values()].includes(numberFormat)))
133
+ throw new RangeError("Unknown number format index.");
134
+ }
135
+ if (style.alignment !== undefined && !["left", "center", "right", "fill", "justify", "distributed"].includes(style.alignment))
136
+ throw new TypeError("Invalid horizontal alignment.");
137
+ if (style.verticalAlignment !== undefined && !["top", "center", "bottom", "justify", "distributed"].includes(style.verticalAlignment))
138
+ throw new TypeError("Invalid vertical alignment.");
139
+ const registered = { font, fill, border, numberFormat, wrapText: !!style.wrapText, alignment: style.alignment ?? "", verticalAlignment: style.verticalAlignment ?? "" };
140
+ const key = JSON.stringify(registered), found = this.indexes.get(key);
141
+ if (found !== undefined)
142
+ return found;
143
+ if (this.styles.length >= this.maximum)
144
+ throw new OfficeIMOError("RESOURCE_LIMIT", "Workbook exceeds its cell style limit.");
145
+ const id = this.styles.length;
146
+ this.styles.push(registered);
147
+ this.indexes.set(key, id);
148
+ return id;
149
+ }
150
+ validateStyle(id) { return index(id, this.styles.length, "cell style"); }
151
+ /** Overlay presentation while retaining the base number format, font fields and border edges. Numeric component indexes replace a component. */
152
+ compose(base, overlay) {
153
+ validateStylePatch(overlay);
154
+ const source = this.styles[this.validateStyle(base)];
155
+ return this.add({
156
+ font: source.font, fill: source.fill, border: source.border, numberFormat: source.numberFormat,
157
+ wrapText: source.wrapText,
158
+ ...(source.alignment ? { alignment: source.alignment } : {}),
159
+ ...(source.verticalAlignment ? { verticalAlignment: source.verticalAlignment } : {}),
160
+ ...overlay,
161
+ ...(typeof overlay.font === "object" ? { font: { ...this.fonts[source.font], ...overlay.font } } : {}),
162
+ ...(typeof overlay.border === "object" ? { border: { ...this.borders[source.border], ...overlay.border } } : {})
163
+ });
164
+ }
165
+ /** @internal Typed headings retain header appearance and the column's date number format. */
166
+ dateHeader(base, dateStyle) {
167
+ return this.compose(base, { numberFormat: this.styles[this.validateStyle(dateStyle)].numberFormat });
168
+ }
169
+ /** @internal Column shorthand and header style composition. */
170
+ forColumn(column, header = false, fill, date = false) {
171
+ const base = !header && column.style !== undefined ? this.styles[this.validateStyle(column.style)] : undefined;
172
+ const format = column.format !== undefined ? column.format || NumberFormats.General : base?.numberFormat || (column.type === "date" || date ? NumberFormats.DateTime : NumberFormats.General);
173
+ return this.add({
174
+ ...(base ? { font: base.font, fill: base.fill, border: base.border } : {}),
175
+ numberFormat: format,
176
+ wrapText: column.wrapText ?? base?.wrapText ?? false,
177
+ ...(column.alignment ? { alignment: column.alignment } : base?.alignment ? { alignment: base.alignment } : {}),
178
+ ...(base?.verticalAlignment ? { verticalAlignment: base.verticalAlignment } : {}),
179
+ ...(header ? { font: { bold: true } } : {}), ...(fill ? { fill: { color: fill } } : {})
180
+ });
181
+ }
182
+ toXml() {
183
+ const fontXml = (f) => '<font>' + (f.bold ? '<b/>' : "") + (f.italic ? '<i/>' : "") + (f.underline ? '<u/>' : "") + (f.strike ? '<strike/>' : "") + '<sz val="' + f.size + '"/>' +
184
+ (f.color ? '<color rgb="' + f.color + '"/>' : "") + '<name val="' + escapeOoxmlAttribute(f.name, this.policy) + '"/></font>';
185
+ const borderXml = (b) => '<border>' + ["left", "right", "top", "bottom"].map(side => {
186
+ const edge = b[side];
187
+ return edge ? '<' + side + ' style="' + edge.style + '">' + (edge.color ? '<color rgb="' + edge.color + '"/>' : "") + '</' + side + '>' : '<' + side + '/>';
188
+ }).join("") + '<diagonal/></border>';
189
+ return xmlDeclaration + '<styleSheet xmlns="' + spreadsheetNamespace + '">' +
190
+ '<numFmts count="' + this.formats.size + '">' + [...this.formats].map(([format, id]) => '<numFmt numFmtId="' + id + '" formatCode="' + escapeOoxmlAttribute(format, this.policy) + '"/>').join("") + '</numFmts>' +
191
+ '<fonts count="' + this.fonts.length + '">' + this.fonts.map(fontXml).join("") + '</fonts>' +
192
+ '<fills count="' + this.fills.length + '">' + this.fills.map(f => '<fill><patternFill patternType="' + f.pattern + '">' +
193
+ (f.color ? '<fgColor rgb="' + f.color + '"/><bgColor indexed="64"/>' : "") + '</patternFill></fill>').join("") + '</fills>' +
194
+ '<borders count="' + this.borders.length + '">' + this.borders.map(borderXml).join("") + '</borders>' +
195
+ '<cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"/></cellStyleXfs>' +
196
+ '<cellXfs count="' + this.styles.length + '">' + this.styles.map(s => {
197
+ const alignment = s.wrapText || s.alignment || s.verticalAlignment ? '<alignment' + (s.wrapText ? ' wrapText="1"' : "") + (s.alignment ? ' horizontal="' + s.alignment + '"' : "") + (s.verticalAlignment ? ' vertical="' + s.verticalAlignment + '"' : "") + '/>' : "";
198
+ return '<xf numFmtId="' + s.numberFormat + '" fontId="' + s.font + '" fillId="' + s.fill + '" borderId="' + s.border + '" xfId="0"' +
199
+ (s.numberFormat ? ' applyNumberFormat="1"' : "") + (s.font ? ' applyFont="1"' : "") + (s.fill ? ' applyFill="1"' : "") +
200
+ (s.border ? ' applyBorder="1"' : "") + (alignment ? ' applyAlignment="1"' : "") + '>' + alignment + '</xf>';
201
+ }).join("") + '</cellXfs><cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles>' + this.differential.toXml() + '</styleSheet>';
202
+ }
203
+ }
@@ -0,0 +1,12 @@
1
+ import type { ProjectionColumn } from "../internal/columns.js";
2
+ import type { InvalidCharacterPolicy } from "../xml/index.js";
3
+ import type { TableOptions, FooterOptions } from "./types.js";
4
+ export interface TableDefinition {
5
+ readonly id: number;
6
+ readonly name: string;
7
+ readonly headers: readonly string[];
8
+ readonly keys: readonly string[];
9
+ readonly options: Readonly<TableOptions>;
10
+ }
11
+ export declare function defineTable(id: number, options: TableOptions, columns: readonly ProjectionColumn[], policy: InvalidCharacterPolicy): TableDefinition;
12
+ export declare function tableXml(table: TableDefinition, rowCount: number, policy: InvalidCharacterPolicy, headerRow?: number, footer?: FooterOptions): string;
@@ -0,0 +1,35 @@
1
+ import { escapeOoxmlAttribute, escapeXml, xmlDeclaration } from "../xml/index.js";
2
+ import { cellText, columnName } from "./values.js";
3
+ import { spreadsheetNamespace } from "./styles.js";
4
+ import { ExportCell } from "../core/presentation.js";
5
+ import { Cell } from "./values.js";
6
+ import { totalFormula } from "./layout.js";
7
+ export function defineTable(id, options, columns, policy) {
8
+ const name = options.name ?? "Table" + id;
9
+ if (typeof name !== "string" || name.length > 255 || !/^[A-Za-z_][A-Za-z0-9_.]*$/.test(name) ||
10
+ /^(?:[A-Za-z]{1,3}[1-9][0-9]*|R[1-9][0-9]*C[1-9][0-9]*|R|C)$/i.test(name))
11
+ throw new TypeError("Table names must be ASCII identifiers, at most 255 characters, and cannot be cell references.");
12
+ const style = options.style ?? "TableStyleMedium2", match = /^TableStyle(Light|Medium|Dark)([1-9][0-9]?)$/.exec(style);
13
+ if (!match || Number(match[2]) > ({ Light: 21, Medium: 28, Dark: 11 }[match[1]] ?? 0))
14
+ throw new TypeError("Unknown built-in Excel table style.");
15
+ const headers = columns.map(column => cellText(column.header, policy));
16
+ if (!headers.length || headers.some(header => !header.trim() || header.length > 255) || new Set(headers.map(header => header.toLowerCase())).size !== headers.length)
17
+ throw new TypeError("Excel tables require nonblank, unique headers of at most 255 characters.");
18
+ return Object.freeze({ id, name, headers: Object.freeze(headers), keys: Object.freeze(columns.map(c => c.key ?? c.header)), options: Object.freeze({ ...options, style }) });
19
+ }
20
+ export function tableXml(table, rowCount, policy, headerRow = 1, footer) {
21
+ const dataRef = "A" + headerRow + ":" + columnName(table.headers.length) + (rowCount + headerRow), ref = "A" + headerRow + ":" + columnName(table.headers.length) + (rowCount + headerRow + (footer ? 1 : 0)), options = table.options;
22
+ const name = escapeOoxmlAttribute(table.name, policy);
23
+ return xmlDeclaration + '<table xmlns="' + spreadsheetNamespace + '" id="' + table.id + '" name="' + name + '" displayName="' + name + '" ref="' + ref + '"' + (footer ? ' totalsRowCount="1"' : ' totalsRowShown="0"') + '>' +
24
+ '<autoFilter ref="' + dataRef + '"/><tableColumns count="' + table.headers.length + '">' +
25
+ table.headers.map((header, i) => {
26
+ const key = table.keys[i], operation = footer?.totals && Object.prototype.hasOwnProperty.call(footer.totals, key) ? footer.totals[key] : undefined, supplied = footer?.values?.[i], value = supplied instanceof Cell || supplied instanceof ExportCell ? supplied.value : supplied;
27
+ const custom = operation && ["average", "min", "max"].includes(operation);
28
+ const attributes = operation ? ' totalsRowFunction="' + (custom ? "custom" : operation === "count" ? "countNums" : operation) + '"' : typeof value === "string" ? ' totalsRowLabel="' + escapeOoxmlAttribute(value, policy) + '"' : "";
29
+ return '<tableColumn id="' + (i + 1) + '" name="' + escapeOoxmlAttribute(header, policy) + '"' + attributes +
30
+ (custom ? '><totalsRowFormula>' + escapeXml(totalFormula(operation, columnName(i + 1), headerRow, rowCount), policy) + '</totalsRowFormula></tableColumn>' : '/>');
31
+ }).join("") +
32
+ '</tableColumns><tableStyleInfo name="' + options.style + '" showFirstColumn="' + (options.firstColumn ? 1 : 0) +
33
+ '" showLastColumn="' + (options.lastColumn ? 1 : 0) + '" showRowStripes="' + (options.bandedRows !== false ? 1 : 0) +
34
+ '" showColumnStripes="' + (options.bandedColumns ? 1 : 0) + '"/></table>';
35
+ }