@evotecit/officeimo 0.1.2 → 0.1.4

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 (54) hide show
  1. package/README.md +59 -51
  2. package/bundles/officeimo-canopyx.js +1553 -314
  3. package/bundles/officeimo-canopyx.mjs +1497 -269
  4. package/bundles/officeimo-csv.js +18 -15
  5. package/bundles/officeimo-csv.mjs +16 -13
  6. package/bundles/officeimo-datatables.js +463 -301
  7. package/bundles/officeimo-datatables.mjs +420 -259
  8. package/bundles/officeimo-pdf.js +148 -65
  9. package/bundles/officeimo-pdf.mjs +124 -41
  10. package/bundles/officeimo-xlsx.js +177 -101
  11. package/bundles/officeimo-xlsx.mjs +149 -74
  12. package/bundles/officeimo.js +461 -299
  13. package/bundles/officeimo.mjs +419 -258
  14. package/dist/csv/index.js +16 -13
  15. package/dist/integrations/canopyx/diagnostics.d.ts +3 -0
  16. package/dist/integrations/canopyx/diagnostics.js +17 -0
  17. package/dist/integrations/canopyx/grouping.d.ts +6 -0
  18. package/dist/integrations/canopyx/grouping.js +198 -0
  19. package/dist/integrations/canopyx/index.d.ts +2 -2
  20. package/dist/integrations/canopyx/index.js +89 -15
  21. package/dist/integrations/canopyx/metadata.d.ts +4 -0
  22. package/dist/integrations/canopyx/metadata.js +51 -0
  23. package/dist/integrations/canopyx/pdf-layout.d.ts +5 -0
  24. package/dist/integrations/canopyx/pdf-layout.js +97 -0
  25. package/dist/integrations/canopyx/pdf-number.d.ts +3 -0
  26. package/dist/integrations/canopyx/pdf-number.js +64 -0
  27. package/dist/integrations/canopyx/pivot.d.ts +15 -0
  28. package/dist/integrations/canopyx/pivot.js +67 -0
  29. package/dist/integrations/canopyx/presentation.d.ts +8 -0
  30. package/dist/integrations/canopyx/presentation.js +40 -0
  31. package/dist/integrations/canopyx/rule-predicates.d.ts +3 -0
  32. package/dist/integrations/canopyx/rule-predicates.js +110 -0
  33. package/dist/integrations/canopyx/rules.d.ts +6 -0
  34. package/dist/integrations/canopyx/rules.js +176 -0
  35. package/dist/integrations/canopyx/source.js +69 -31
  36. package/dist/integrations/canopyx/types.d.ts +134 -10
  37. package/dist/integrations/canopyx/workbook.d.ts +6 -0
  38. package/dist/integrations/canopyx/workbook.js +52 -0
  39. package/dist/opc/index.js +9 -0
  40. package/dist/pdf/font-resources.js +33 -14
  41. package/dist/pdf/pages.js +60 -14
  42. package/dist/pdf/table-band-flow.js +7 -2
  43. package/dist/pdf/table-band-plan.js +9 -1
  44. package/dist/pdf/table-layout.js +6 -2
  45. package/dist/pdf/table-structure.js +9 -8
  46. package/dist/xlsx/index.d.ts +1 -1
  47. package/dist/xlsx/options.js +1 -1
  48. package/dist/xlsx/outlines.d.ts +3 -0
  49. package/dist/xlsx/outlines.js +39 -0
  50. package/dist/xlsx/types.d.ts +9 -0
  51. package/dist/xlsx/values.js +11 -2
  52. package/dist/xlsx/workbook.js +2 -0
  53. package/dist/xlsx/worksheet.js +14 -6
  54. package/package.json +2 -2
package/dist/pdf/pages.js CHANGED
@@ -21,7 +21,8 @@ export class PdfPages {
21
21
  outlines;
22
22
  references = [];
23
23
  current = 0;
24
- commands = [];
24
+ commands = "";
25
+ commandParts = [];
25
26
  commandBytes = 0;
26
27
  annotations = [];
27
28
  hyperlinks = 0;
@@ -39,6 +40,12 @@ export class PdfPages {
39
40
  pendingBookmarks = [];
40
41
  pageNumberWidth = 0;
41
42
  colors = new Map();
43
+ textFont;
44
+ textSize = 0;
45
+ textColor = "";
46
+ textPrefix = "";
47
+ rectangleLefts;
48
+ rectangleColumns = [];
42
49
  externalObjects = new Map();
43
50
  bandFlow;
44
51
  bandCellBudget = false;
@@ -105,7 +112,7 @@ export class PdfPages {
105
112
  }
106
113
  add(command) {
107
114
  this.retainPageBytes(command.length);
108
- this.commands.push(command);
115
+ this.commands += command;
109
116
  }
110
117
  retainPageBytes(length) {
111
118
  this.commandBytes += length;
@@ -125,9 +132,17 @@ export class PdfPages {
125
132
  return this.structure ? "/Artifact << /Type /" + type + " >> BDC\n" + command + "EMC\n" : command;
126
133
  }
127
134
  text(text, font, size, x, baseline, foreground = "111827", element) {
128
- const n = pdfNumber, shear = font.syntheticItalic ? .213 : 0;
129
- const command = "q " + this.rgb(foreground) + " rg " + this.rgb(foreground) + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
130
- (font.syntheticBold ? n(size * .025) + " w 2 Tr " : "0 Tr ") + "1 0 " + n(shear) + " 1 " + n(x) + " " + n(baseline) + " Tm " + font.encode(text) + " Tj ET Q\n";
135
+ const n = pdfNumber;
136
+ if (font !== this.textFont || size !== this.textSize || foreground !== this.textColor) {
137
+ const shear = font.syntheticItalic ? .213 : 0, rgb = this.rgb(foreground);
138
+ // Keep one prefix, independent of report size. Resource identity includes synthetic styling.
139
+ this.textPrefix = "q " + rgb + " rg " + rgb + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
140
+ (font.syntheticBold ? n(size * .025) + " w 2 Tr " : "0 Tr ") + "1 0 " + n(shear) + " 1 ";
141
+ this.textFont = font;
142
+ this.textSize = size;
143
+ this.textColor = foreground;
144
+ }
145
+ const command = this.textPrefix + n(x) + " " + n(baseline) + " Tm " + font.encode(text) + " Tj ET Q\n";
131
146
  this.add(this.structure && element !== undefined ? this.structure.mark(element) + command + "EMC\n" : this.artifact(command, "Pagination"));
132
147
  }
133
148
  link(link, x, bottom, width, height, element) {
@@ -157,8 +172,8 @@ export class PdfPages {
157
172
  for (const segment of line.segments) {
158
173
  const registered = marks?.get(segment), owner = registered?.owner ?? (segment.link && this.structure && element !== undefined ? this.structure.link(element, segment.link) : element);
159
174
  if (segment.glyphs) {
160
- const font = segment.font, n = pdfNumber, shear = font.syntheticItalic ? .213 : 0;
161
- let cursor = x, command = "q " + this.rgb(segment.color ?? "111827") + " rg " + this.rgb(segment.color ?? "111827") + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
175
+ const font = segment.font, n = pdfNumber, shear = font.syntheticItalic ? .213 : 0, rgb = this.rgb(segment.color ?? "111827");
176
+ let cursor = x, command = "q " + rgb + " rg " + rgb + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
162
177
  (font.syntheticBold ? n(size * .025) + " w 2 Tr " : "0 Tr ");
163
178
  for (const glyph of segment.glyphs) {
164
179
  command += "1 0 " + n(shear) + " 1 " + n(cursor + (glyph.xOffset + shear * glyph.yOffset) * size / 1000) + " " + n(baseline + glyph.yOffset * size / 1000) + " Tm " + font.encodeGlyph(glyph.id, glyph.logicalText) + " Tj\n";
@@ -206,7 +221,8 @@ export class PdfPages {
206
221
  this.current = this.objects.reserve();
207
222
  this.references.push(this.current);
208
223
  }
209
- this.commands = [];
224
+ this.commands = "";
225
+ this.commandParts = [];
210
226
  this.annotations = [];
211
227
  this.commandBytes = 0;
212
228
  this.bodyAdded = false;
@@ -289,15 +305,32 @@ export class PdfPages {
289
305
  if (!this.layout)
290
306
  throw new Error("A table layout is required before drawing rows.");
291
307
  this.bodyAdded = true;
292
- const { padding, fontSize } = this.settings, n = pdfNumber, height = lineCount * row.lineHeight + padding * 2;
308
+ const { padding, fontSize } = this.settings, n = pdfNumber, height = lineCount * row.lineHeight + padding * 2, lefts = this.layout.lefts;
309
+ // One geometry token per active physical column; table/band changes release the old tokens.
310
+ if (this.rectangleLefts !== lefts) {
311
+ this.rectangleLefts = lefts;
312
+ this.rectangleColumns = [];
313
+ }
314
+ let rectangleHeight, rectangleBottom = "", rectangleHeightText = "";
293
315
  for (const [index, cell] of row.cells.entries()) {
294
316
  if (this.bandCellBudget)
295
317
  this.settings.budget.cell(this.settings.budget.limits.maxTextCharacters === undefined ? "" :
296
318
  (cell.height === undefined ? cell.lines.slice(firstLine, firstLine + lineCount) : cell.lines).map(line => line.text).join(""));
297
- const x = this.layout.lefts[cell.first], cellHeight = cell.height ?? height;
319
+ const x = lefts[cell.first], cellHeight = cell.height ?? height;
320
+ if (cellHeight !== rectangleHeight) {
321
+ rectangleBottom = n(this.y - cellHeight);
322
+ rectangleHeightText = n(cellHeight);
323
+ rectangleHeight = cellHeight;
324
+ }
325
+ let horizontal = this.rectangleColumns[cell.first];
326
+ if (!horizontal || horizontal.x !== x || horizontal.width !== cell.width) {
327
+ horizontal = { x, width: cell.width, left: n(x), widthText: n(cell.width) };
328
+ this.rectangleColumns[cell.first] = horizontal;
329
+ }
330
+ const rectangle = horizontal.left + " " + rectangleBottom + " " + horizontal.widthText + " " + rectangleHeightText;
298
331
  if (cell.style.background)
299
- this.add(this.artifact("q " + this.rgb(cell.style.background) + " rg " + n(x) + " " + n(this.y - cellHeight) + " " + n(cell.width) + " " + n(cellHeight) + " re f Q\n"));
300
- this.add(this.artifact("q 0.82 0.85 0.89 RG 0.4 w " + n(x) + " " + n(this.y - cellHeight) + " " + n(cell.width) + " " + n(cellHeight) + " re S Q\n"));
332
+ this.add(this.artifact("q " + this.rgb(cell.style.background) + " rg " + rectangle + " re f Q\n"));
333
+ this.add(this.artifact("q 0.82 0.85 0.89 RG 0.4 w " + rectangle + " re S Q\n"));
301
334
  const element = elements?.[index], artifact = cell.semanticArtifact || repeated[index], owner = cell.link && this.structure && element !== undefined ? this.structure.link(element, cell.link) : element;
302
335
  for (let line = firstLine; line < Math.min(cell.lines.length, cell.height ? cell.lines.length : firstLine + lineCount); line++) {
303
336
  const text = cell.lines[line], left = cell.style.alignment === "right" ? cell.width - padding - text.width : cell.style.alignment === "center" ? (cell.width - text.width) / 2 : padding;
@@ -307,6 +340,7 @@ export class PdfPages {
307
340
  this.link(cell.link, x, this.y - cellHeight, cell.width, cellHeight, owner);
308
341
  }
309
342
  this.y -= row.structured ? row.height : height;
343
+ this.sealCommands();
310
344
  }
311
345
  async block(rows) {
312
346
  if (this.bandFlow)
@@ -632,9 +666,22 @@ export class PdfPages {
632
666
  marker: { line: item.marker, gap: item.markerGap, ...(label === undefined ? {} : { owner: label }) } });
633
667
  await this.structure?.complete(li);
634
668
  }
669
+ sealCommands() {
670
+ if (this.commands) {
671
+ this.commandParts.push(this.commands);
672
+ this.commands = "";
673
+ }
674
+ }
675
+ takeCommands() {
676
+ this.sealCommands();
677
+ const content = this.commandParts.join("");
678
+ // Encoding and awaited delivery own the page value; the next page starts independently.
679
+ this.commandParts = [];
680
+ return content;
681
+ }
635
682
  async finishPage() {
636
683
  const contents = this.objects.reserve(), { page, options } = this.settings;
637
- await this.objects.stream(contents, this.commands.join(""), "", options.compression !== false);
684
+ await this.objects.stream(contents, this.takeCommands(), "", options.compression !== false);
638
685
  const annotations = [];
639
686
  for (const annotation of this.annotations) {
640
687
  annotations.push(annotation.id);
@@ -646,7 +693,6 @@ export class PdfPages {
646
693
  (annotations.length ? " /Annots [" + annotations.map(id => id + " 0 R").join(" ") + "]" : "") + " >>");
647
694
  if (this.structure)
648
695
  await this.structure.finishPage();
649
- this.commands = [];
650
696
  this.annotations = [];
651
697
  this.commandBytes = 0;
652
698
  this.current = 0;
@@ -39,7 +39,7 @@ export class PdfTableBandFlow {
39
39
  await this.flush();
40
40
  }
41
41
  async row(row, allowFirstFragment = false) {
42
- const { padding, fontSize, options } = this.layout.settings, minimumLines = this.layout.minimumRowLines(row), minimumHeight = this.layout.minimumRowHeight(row);
42
+ const { padding, fontSize, options } = this.layout.settings, minimumLines = this.layout.minimumRowLines(row), minimumHeight = minimumLines * row.lineHeight + padding * 2;
43
43
  if (minimumHeight > this.painter.firstFullCapacity + .001 || minimumHeight > this.painter.continuationCapacity + .001)
44
44
  throw new RangeError("Repeated PDF identifiers must fit intact below the first and continued band headings/context.");
45
45
  // Keep ordinary rows intact when they fit fresh. A kept heading/caption can deliberately
@@ -73,9 +73,14 @@ export class PdfTableBandFlow {
73
73
  let remaining = false;
74
74
  const cells = rows[0].cells.map(cell => {
75
75
  const source = this.layout.bands[index].columns[cell.first];
76
- const repeated = this.layout.repeatedColumn(source), visible = repeated ? cell.lines : cell.lines.slice(first, first + lines);
76
+ const repeated = this.layout.repeatedColumn(source), reusable = cell.span === 1 && (cell.source?.span ?? 1) === 1 && (cell.rowSpan ?? 1) === 1 &&
77
+ cell.height === undefined && first === 0 && (repeated || lines >= cell.lines.length);
78
+ const visible = repeated || reusable ? cell.lines : cell.lines.slice(first, first + lines);
77
79
  if (!repeated && (visible.length > 0 || cell.link !== undefined))
78
80
  remaining = true;
81
+ // A complete first fragment already owns these lines and their maximum font metrics.
82
+ if (reusable)
83
+ return cell;
79
84
  const { height: _height, ...plain } = cell;
80
85
  return { ...plain, lines: visible,
81
86
  lineHeight: visible.reduce((value, line) => Math.max(value, line.lineHeight), cell.font.lineHeight(fontSize)),
@@ -43,6 +43,14 @@ export async function projectBandRows(rows, band, widths, settings, fonts) {
43
43
  for (const row of rows) {
44
44
  const cells = [];
45
45
  for (const cell of row.cells) {
46
+ // Ordinary data and leaf headings keep their captured width and lines in every band.
47
+ // Look up their physical position without allocating another per-row column index.
48
+ if (cell.span === 1) {
49
+ const first = band.columns.indexOf(cell.first);
50
+ if (first >= 0)
51
+ cells.push({ ...cell, source: cell.source ?? cell, first });
52
+ continue;
53
+ }
46
54
  for (let first = 0; first < band.columns.length;) {
47
55
  const source = band.columns[first];
48
56
  if (source < cell.first || source >= cell.first + cell.span) {
@@ -53,7 +61,7 @@ export async function projectBandRows(rows, band, widths, settings, fonts) {
53
61
  while (end < band.columns.length && band.columns[end] === band.columns[end - 1] + 1 && band.columns[end] < cell.first + cell.span)
54
62
  end++;
55
63
  const width = band.columns.slice(first, end).reduce((sum, index) => sum + widths[index], 0);
56
- const lines = cell.span === 1 ? cell.lines : await wrapPdfText(cell.captured, fonts, settings.fontSize, width - settings.padding * 2, settings, cell.style.wrapText !== false);
64
+ const lines = await wrapPdfText(cell.captured, fonts, settings.fontSize, width - settings.padding * 2, settings, cell.style.wrapText !== false);
57
65
  cells.push({ ...cell, source: cell.source ?? cell, first, span: end - first, width, lines,
58
66
  lineHeight: lines.reduce((height, line) => Math.max(height, line.lineHeight), cell.font.lineHeight(settings.fontSize)) });
59
67
  first = end;
@@ -109,8 +109,12 @@ export class PdfTableLayout {
109
109
  lines };
110
110
  }
111
111
  row(cells) {
112
- const lines = Math.max(1, ...cells.map(c => c.lines.length));
113
- const lineHeight = Math.max(this.lineHeight, ...cells.map(c => c.lineHeight));
112
+ let lines = 1, lineHeight = this.lineHeight;
113
+ for (let index = 0; index < cells.length; index++) {
114
+ const cell = cells[index];
115
+ lines = Math.max(lines, cell.lines.length);
116
+ lineHeight = Math.max(lineHeight, cell.lineHeight);
117
+ }
114
118
  return { cells, lines, lineHeight, height: lines * lineHeight + this.settings.padding * 2 };
115
119
  }
116
120
  async headers() {
@@ -49,30 +49,31 @@ export class PdfTableStructure {
49
49
  return row.cells.map(cell => this.cells.get(cell));
50
50
  const rowId = this.structure.element("TR", parent);
51
51
  this.rows.set(row, rowId);
52
- const headers = row.cells.map((cell, index) => rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex);
53
52
  // Allocate in source order, then resolve every row header before associating even earlier data cells.
54
53
  // Generated summary labels override detail roles so numeric subtotal cells never become row headers.
55
54
  const ids = row.cells.map((cell, index) => {
56
- const id = this.structure.element(headers[index] ? "TH" : "TD", rowId);
55
+ const header = rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex;
56
+ const id = this.structure.element(header ? "TH" : "TD", rowId);
57
57
  this.cells.set(cell, id);
58
58
  return id;
59
59
  });
60
- const rowHeaders = [];
60
+ let rowHeaders;
61
61
  for (let index = 0; index < ids.length; index++)
62
- if (headers[index])
63
- rowHeaders.push(await this.structure.identifier(ids[index]));
62
+ if (rowHeaderIndex === undefined ? row.cells[index].rowHeader === true : index === rowHeaderIndex)
63
+ (rowHeaders ??= []).push(await this.structure.identifier(ids[index]));
64
64
  for (let index = 0; index < row.cells.length; index++) {
65
65
  const cell = row.cells[index];
66
- if (!rowHeaders.length && cell.span === 1 && (cell.rowSpan ?? 1) === 1) {
66
+ if (!rowHeaders && cell.span === 1 && (cell.rowSpan ?? 1) === 1) {
67
67
  const attributes = this.ordinaryAttributes[cell.first] ??=
68
68
  await this.structure.attributeReference(this.attributeDictionary(cell, this.associations(cell)));
69
69
  this.structure.setAttributes(ids[index], attributes);
70
70
  continue;
71
71
  }
72
72
  const associations = this.associations(cell);
73
- if (!headers[index])
73
+ const header = rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex;
74
+ if (!header && rowHeaders)
74
75
  associations.push(...rowHeaders);
75
- this.structure.setAttributes(ids[index], this.attributes(cell, associations, headers[index] ? "Row" : undefined));
76
+ this.structure.setAttributes(ids[index], this.attributes(cell, associations, header ? "Row" : undefined));
76
77
  }
77
78
  return ids;
78
79
  }
@@ -2,7 +2,7 @@ export { Workbook } from "./workbook.js";
2
2
  export { writeXlsx, writeXlsxTo } from "./write.js";
3
3
  export { writeGroupedXlsx, writeGroupedXlsxTo, addGroupedXlsx } from "./grouped.js";
4
4
  export type { GroupedXlsxOptions, GroupedXlsxSheetOptions, GroupedXlsxWorksheet, GroupedXlsxGroupRows } from "./grouped.js";
5
- export type { RowOutline } from "./types.js";
5
+ export type { RowOutline, ColumnOutline } from "./types.js";
6
6
  export { createGroupedReport } from "../core/grouped-report.js";
7
7
  export type { GroupedReportSource, GroupedReportOptions, GroupedReportEvent, GroupedReportSummary, GroupedReportValueContext, GroupedReportLevel, GroupedReportGroup } from "../core/grouped-report.js";
8
8
  export type { XlsxOptions } from "./write.js";
@@ -2,7 +2,7 @@ import { captureFields } from "../internal/capture.js";
2
2
  /** @internal The workbook owner captures these settings before validation or adapter merging. */
3
3
  export const workbookOptionFields = ["signal", "onProgress", "limits", "sink", "dateMode", "compression", "invalidCharacterPolicy", "appProperties", "cellValueWriters", "oversizedText", "creator", "title", "subject", "description", "created", "modified"];
4
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"];
5
+ export const sheetOptionFields = ["columns", "includeHeader", "headerRows", "freezeHeader", "autoFilter", "boldHeader", "headerFill", "headerStyle", "alternatingRowStyle", "rowStyle", "cellStyle", "rowOutline", "maxOutlineLevel", "outlineSummaryBelow", "outlineSummaryRight", "columnOutlines", "rowHeight", "headerHeight", "defaultColumnWidth", "freezeColumns", "table", "autoSize", "footer", "print", "title", "mergedCells", "hyperlinks", "conditionalFormats", "dataValidation"];
6
6
  /** @internal Includes inherited format-specific ceilings before a wrapper combines stream settings. */
7
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
8
  /** @internal Capture the workbook's known ceilings without dropping supported prototype fields. */
@@ -0,0 +1,3 @@
1
+ import type { ColumnOutline } from "./types.js";
2
+ /** Capture bounded disjoint ranges before asynchronous serialization; absent columns stay visible. */
3
+ export declare function captureColumnOutlines(input: readonly ColumnOutline[] | undefined, columns: number): readonly ColumnOutline[] | undefined;
@@ -0,0 +1,39 @@
1
+ import { captureFields } from "../internal/capture.js";
2
+ /** Capture bounded disjoint ranges before asynchronous serialization; absent columns stay visible. */
3
+ export function captureColumnOutlines(input, columns) {
4
+ if (input === undefined)
5
+ return undefined;
6
+ if (!Array.isArray(input) || input.length > columns)
7
+ throw new TypeError("Column outlines must be bounded, non-overlapping ranges.");
8
+ let end = 0;
9
+ return Object.freeze(input.map(range => {
10
+ if (!range || typeof range !== "object")
11
+ throw new TypeError("Column outlines require range metadata.");
12
+ return captureFields(range, ["firstColumn", "columnCount", "level", "hidden", "collapsed"]);
13
+ }).sort((a, b) => a.firstColumn - b.firstColumn).map(range => {
14
+ const { firstColumn, columnCount, level = 0, hidden, collapsed } = range;
15
+ if (!Number.isSafeInteger(firstColumn) || firstColumn < end || !Number.isSafeInteger(columnCount) || columnCount < 1 || firstColumn + columnCount > columns)
16
+ throw new RangeError("Column outline ranges must be disjoint and within the declared columns.");
17
+ if (!Number.isInteger(level) || level < 0 || level > 7)
18
+ throw new RangeError("Column outline level must be from zero through seven.");
19
+ for (const flag of [hidden, collapsed])
20
+ if (flag !== undefined && typeof flag !== "boolean")
21
+ throw new TypeError("Column outline flags must be booleans.");
22
+ end = firstColumn + columnCount;
23
+ return Object.freeze({ firstColumn, columnCount, level, ...(hidden === undefined ? {} : { hidden }), ...(collapsed === undefined ? {} : { collapsed }) });
24
+ }));
25
+ }
26
+ /** @internal Positions are captured even when a sheet has only column outlines. */
27
+ export function validateOutlinePositions(options) {
28
+ for (const flag of [options.outlineSummaryBelow, options.outlineSummaryRight])
29
+ if (flag !== undefined && typeof flag !== "boolean")
30
+ throw new TypeError("Outline summary positions must be booleans.");
31
+ }
32
+ /** @internal Resolve at most 16,384 columns once, without retaining any worksheet body. */
33
+ export function columnOutlineMap(ranges) {
34
+ const result = new Map();
35
+ for (const range of ranges ?? [])
36
+ for (let index = range.firstColumn; index < range.firstColumn + range.columnCount; index++)
37
+ result.set(index, range);
38
+ return result;
39
+ }
@@ -48,6 +48,11 @@ export interface RowOutline {
48
48
  /** Marks a summary row whose preceding detail rows are initially hidden. */
49
49
  readonly collapsed?: boolean;
50
50
  }
51
+ /** Non-overlapping zero-based column range with native Excel outline metadata. */
52
+ export interface ColumnOutline extends RowOutline {
53
+ readonly firstColumn: number;
54
+ readonly columnCount: number;
55
+ }
51
56
  /** A real Excel table over this worksheet's header and data rows. Empty exports retain headers without a table part. */
52
57
  export interface TableOptions {
53
58
  readonly name?: string;
@@ -122,6 +127,10 @@ export interface SheetOptions<T = never> {
122
127
  readonly rowOutline?: (context: RowStyleContext) => RowOutline | undefined;
123
128
  /** Declared outline upper bound, from zero through seven; emitted before streamed rows. */
124
129
  readonly maxOutlineLevel?: number;
130
+ /** Summary position for native row/column outlines; both default to true. */
131
+ readonly outlineSummaryBelow?: boolean;
132
+ readonly outlineSummaryRight?: boolean;
133
+ readonly columnOutlines?: readonly ColumnOutline[];
125
134
  readonly rowHeight?: number;
126
135
  readonly headerHeight?: number;
127
136
  /** Fallback width in characters. Native tables default to 20 when no column width is supplied. */
@@ -52,14 +52,23 @@ export function columnName(index) {
52
52
  return name;
53
53
  }
54
54
  function clipName(text, length) { return text.slice(0, length).replace(/[\ud800-\udbff]$/, ""); }
55
+ function trimSheetNameEdges(text) {
56
+ let start = 0, end = text.length;
57
+ const removable = (character) => character === "'" || /\s/u.test(character);
58
+ while (start < end && removable(text[start]))
59
+ start++;
60
+ while (end > start && removable(text[end - 1]))
61
+ end--;
62
+ return text.slice(start, end);
63
+ }
55
64
  export function sheetName(requested, names, policy, register = true) {
56
65
  if (typeof requested !== "string")
57
66
  throw new TypeError("Sheet name must be a string.");
58
67
  // Validate and deduplicate the decoded literal value, before ST_Xstring attribute encoding.
59
68
  // A requested _xHHHH_ token is literal text; the serializer protects its leading underscore.
60
- let base = cleanXml(requested, policy).replace(/[\[\]:*?/\\]/g, "_").replace(/^[\s']+|[\s']+$/g, "");
69
+ let base = trimSheetNameEdges(cleanXml(requested, policy).replace(/[\[\]:*?/\\]/g, "_"));
61
70
  // Clipping can expose an internal apostrophe or the reserved History name.
62
- base = clipName(base, 31).replace(/[\s']+$/g, "");
71
+ base = trimSheetNameEdges(clipName(base, 31));
63
72
  if (!base)
64
73
  base = "Sheet";
65
74
  if (base.toLowerCase() === "history")
@@ -9,6 +9,7 @@ import { StyleRegistry, spreadsheetNamespace } from "./styles.js";
9
9
  import { sheetName, assertXlsxValue, copyValue } from "./values.js";
10
10
  import { copyColumns } from "../internal/rows.js";
11
11
  import { captureFields } from "../internal/capture.js";
12
+ import { captureColumnOutlines } from "./outlines.js";
12
13
  import { captureTableSpans } from "../internal/table-spans.js";
13
14
  import { assertExportValue } from "../core/presentation.js";
14
15
  import { Worksheet } from "./worksheet.js";
@@ -28,6 +29,7 @@ function captureSheet(options, policy) {
28
29
  const footer = captured.footer && captureFields(captured.footer, ["rows", "values", "totals", "style"]);
29
30
  const print = captured.print && captureFields(captured.print, ["paper", "orientation", "fitToWidth", "fitToHeight", "repeatHeaders", "margins", "header", "footer"]);
30
31
  return { ...captured, columns,
32
+ ...(captured.columnOutlines === undefined ? {} : { columnOutlines: captureColumnOutlines(captured.columnOutlines, columns.length) }),
31
33
  ...(captured.headerRows === undefined ? {} : { headerRows: captureTableSpans(captured.headerRows, columns.length) }),
32
34
  ...(footer ? { footer: { ...footer,
33
35
  ...(footer.rows === undefined ? {} : { rows: captureTableSpans(footer.rows, columns.length) }),
@@ -18,6 +18,7 @@ import { FormulaCell, formulaXml, isSubtotalFormula } from "./formula.js";
18
18
  import { prepareDataValidations, dataValidationsXml } from "./validation.js";
19
19
  import { qualifiedCell, qualifiedColumnRange, resolveDataColumn } from "./ranges.js";
20
20
  import { dataRowRanges, dataRowCount } from "./data-row-ranges.js";
21
+ import { captureColumnOutlines, columnOutlineMap, validateOutlinePositions } from "./outlines.js";
21
22
  const maximumHyperlinks = 65530;
22
23
  function checkHyperlinkCount(count) {
23
24
  if (count > maximumHyperlinks)
@@ -148,6 +149,8 @@ export class Worksheet {
148
149
  throw new TypeError("Row and style callbacks must be functions.");
149
150
  if (options.maxOutlineLevel !== undefined && (!Number.isInteger(options.maxOutlineLevel) || options.maxOutlineLevel < 0 || options.maxOutlineLevel > 7))
150
151
  throw new RangeError("Maximum outline level must be an integer from zero through seven.");
152
+ validateOutlinePositions(options);
153
+ captureColumnOutlines(options.columnOutlines, columns.length);
151
154
  if (options.rowOutline && options.maxOutlineLevel === undefined)
152
155
  throw new TypeError("A row outline callback requires maxOutlineLevel before streamed rows are written.");
153
156
  if (!options.rowOutline && options.maxOutlineLevel !== undefined)
@@ -432,17 +435,22 @@ export class Worksheet {
432
435
  const buffer = this.buffer = new ChunkedTextSink(this.entry, this.book.settings.signal), opts = this.options;
433
436
  const x = opts.freezeColumns ?? 0, y = opts.freezeHeader ? this.headerRows : 0;
434
437
  const pane = x && y ? "bottomRight" : x ? "topRight" : "bottomLeft", cell = columnName(x + 1) + (y + 1);
438
+ const outlines = columnOutlineMap(opts.columnOutlines), hasOutline = !!opts.rowOutline || outlines.size > 0;
439
+ const maxColumnLevel = Math.max(0, ...Array.from(outlines.values(), value => value.level ?? 0));
435
440
  await buffer.write(xmlDeclaration + '<worksheet xmlns="' + spreadsheetNamespace + '" xmlns:r="' + officeRelationshipsNamespace + '">' +
436
- (opts.print || opts.rowOutline ? '<sheetPr>' + (opts.rowOutline ? '<outlinePr summaryBelow="1" showOutlineSymbols="1"/>' : "") + (opts.print ? '<pageSetUpPr fitToPage="1"/>' : "") + '</sheetPr>' : "") + '<sheetViews><sheetView workbookViewId="0">' +
441
+ (opts.print || hasOutline ? '<sheetPr>' + (hasOutline ? '<outlinePr summaryBelow="' + (opts.outlineSummaryBelow === false ? "0" : "1") + '"' + (opts.outlineSummaryRight === undefined ? "" : ' summaryRight="' + (opts.outlineSummaryRight ? "1" : "0") + '"') + ' showOutlineSymbols="1"/>' : "") + (opts.print ? '<pageSetUpPr fitToPage="1"/>' : "") + '</sheetPr>' : "") + '<sheetViews><sheetView workbookViewId="0">' +
437
442
  (x || y ? '<pane' + (x ? ' xSplit="' + x + '"' : "") + (y ? ' ySplit="' + y + '"' : "") + ' topLeftCell="' + cell + '" activePane="' + pane + '" state="frozen"/><selection pane="' + pane + '" activeCell="' + cell + '" sqref="' + cell + '"/>' : "") + '</sheetView></sheetViews>' +
438
- (opts.rowOutline ? '<sheetFormatPr defaultRowHeight="15" outlineLevelRow="' + opts.maxOutlineLevel + '"/>' : ""));
443
+ (hasOutline ? '<sheetFormatPr defaultRowHeight="15"' + (opts.rowOutline ? ' outlineLevelRow="' + opts.maxOutlineLevel + '"' : "") + (outlines.size ? ' outlineLevelCol="' + maxColumnLevel + '"' : "") + '/>' : ""));
439
444
  const defaultWidth = opts.defaultColumnWidth ?? (this.table ? 20 : undefined);
440
- if (this.columns.some((_, i) => this.layout.widths[i] !== undefined || defaultWidth !== undefined)) {
445
+ if (this.columns.some((_, i) => this.layout.widths[i] !== undefined || defaultWidth !== undefined || outlines.has(i))) {
441
446
  await buffer.write('<cols>');
442
447
  for (let i = 0; i < this.columns.length; i++) {
443
- const width = this.layout.widths[i] ?? defaultWidth;
444
- if (width !== undefined)
445
- await buffer.write('<col min="' + (i + 1) + '" max="' + (i + 1) + '" width="' + width + '" customWidth="1"/>');
448
+ const width = this.layout.widths[i] ?? defaultWidth, outline = outlines.get(i);
449
+ if (width !== undefined || outline)
450
+ await buffer.write('<col min="' + (i + 1) + '" max="' + (i + 1) + '"' +
451
+ (width === undefined ? "" : ' width="' + width + '" customWidth="1"') +
452
+ (outline?.level ? ' outlineLevel="' + outline.level + '"' : "") + (outline?.hidden ? ' hidden="1"' : "") +
453
+ (outline?.collapsed ? ' collapsed="1"' : "") + '/>');
446
454
  }
447
455
  await buffer.write('</cols>');
448
456
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evotecit/officeimo",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Dependency-free OfficeIMO document libraries for browsers, workers and Node.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -83,7 +83,7 @@
83
83
  "prepack": "npm run check"
84
84
  },
85
85
  "devDependencies": {
86
- "typescript": "5.9.3"
86
+ "typescript": "7.0.2"
87
87
  },
88
88
  "engines": {
89
89
  "node": "^22.0.0 || ^24.0.0 || ^25.0.0 || ^26.0.0"