@evotecit/officeimo 0.1.9 → 0.1.21

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 (43) hide show
  1. package/README.md +6 -3
  2. package/bundles/officeimo-canopyx-adapter.js +123 -61
  3. package/bundles/officeimo-canopyx-adapter.min.js +1 -1
  4. package/bundles/officeimo-canopyx-adapter.min.mjs +1 -1
  5. package/bundles/officeimo-canopyx-adapter.mjs +109 -48
  6. package/bundles/officeimo-canopyx.js +179 -102
  7. package/bundles/officeimo-canopyx.min.js +1 -1
  8. package/bundles/officeimo-canopyx.min.mjs +1 -1
  9. package/bundles/officeimo-canopyx.mjs +145 -69
  10. package/bundles/officeimo-datatables-adapter.js +7 -7
  11. package/bundles/officeimo-datatables-adapter.min.js +1 -1
  12. package/bundles/officeimo-datatables-adapter.min.mjs +1 -1
  13. package/bundles/officeimo-datatables-adapter.mjs +3 -3
  14. package/bundles/officeimo-datatables.js +63 -48
  15. package/bundles/officeimo-datatables.min.js +1 -1
  16. package/bundles/officeimo-datatables.min.mjs +1 -1
  17. package/bundles/officeimo-datatables.mjs +39 -24
  18. package/bundles/officeimo-xlsx.js +59 -44
  19. package/bundles/officeimo-xlsx.min.js +1 -1
  20. package/bundles/officeimo-xlsx.min.mjs +1 -1
  21. package/bundles/officeimo-xlsx.mjs +39 -24
  22. package/bundles/officeimo.js +61 -46
  23. package/bundles/officeimo.min.js +1 -1
  24. package/bundles/officeimo.min.mjs +1 -1
  25. package/bundles/officeimo.mjs +40 -25
  26. package/dist/integrations/canopyx/index.js +4 -2
  27. package/dist/integrations/canopyx/metadata.js +1 -1
  28. package/dist/integrations/canopyx/pdf-number.js +9 -6
  29. package/dist/integrations/canopyx/rule-predicates.d.ts +1 -1
  30. package/dist/integrations/canopyx/rule-predicates.js +2 -1
  31. package/dist/integrations/canopyx/rules.d.ts +1 -1
  32. package/dist/integrations/canopyx/rules.js +11 -13
  33. package/dist/integrations/canopyx/source.js +44 -7
  34. package/dist/integrations/canopyx/tones.d.ts +10 -0
  35. package/dist/integrations/canopyx/tones.js +12 -0
  36. package/dist/integrations/canopyx/types.d.ts +10 -2
  37. package/dist/xlsx/options.js +1 -1
  38. package/dist/xlsx/portable.js +1 -1
  39. package/dist/xlsx/styles.js +28 -18
  40. package/dist/xlsx/types.d.ts +5 -1
  41. package/dist/xlsx/workbook.js +3 -1
  42. package/dist/xlsx/worksheet.js +5 -2
  43. package/package.json +1 -1
@@ -4,6 +4,24 @@ import { colorArgb } from "./style-xml.js";
4
4
  import { DifferentialStyles } from "./differential-styles.js";
5
5
  export { colorArgb } from "./style-xml.js";
6
6
  export const spreadsheetNamespace = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
7
+ const borderStyles = ["thin", "medium", "dashed", "dotted", "thick", "double", "hair", "dashDot", "dashDotDot", "slantDashDot", "mediumDashed", "mediumDashDot", "mediumDashDotDot"];
8
+ /** @internal Validate and normalize border edges without registering a workbook style. */
9
+ export function normalizeBorder(border) {
10
+ if (!border || typeof border !== "object")
11
+ throw new TypeError("A border must be an object of edges.");
12
+ const result = {};
13
+ for (const side of ["left", "right", "top", "bottom"]) {
14
+ const edge = border[side];
15
+ if (edge) {
16
+ // Read each property once, so the validated edge is the one that is stored.
17
+ const { style, color } = edge;
18
+ if (!borderStyles.includes(style))
19
+ throw new TypeError("Invalid border style.");
20
+ result[side] = { style, ...(color ? { color: colorArgb(color) } : {}) };
21
+ }
22
+ }
23
+ return result;
24
+ }
7
25
  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
26
  function index(value, count, kind) {
9
27
  if (!Number.isInteger(value) || value < 0 || value >= count)
@@ -76,32 +94,24 @@ export class StyleRegistry {
76
94
  /** @internal */
77
95
  addDifferentials(styles) { this.checkDifferentials(styles); return this.differential.add(styles); }
78
96
  addFont(font) {
79
- if (font.name !== undefined && typeof font.name !== "string")
97
+ const { name: requested, size: requestedSize, bold, italic, underline, strike, color } = font;
98
+ if (requested !== undefined && typeof requested !== "string")
80
99
  throw new TypeError("Font name must be a string.");
81
- const name = cleanXml(font.name ?? "Calibri", this.policy), size = font.size ?? 11;
100
+ const name = cleanXml(requested ?? "Calibri", this.policy), size = requestedSize ?? 11;
82
101
  if (typeof name !== "string" || !name || name.length > 31)
83
102
  throw new TypeError("Font name must contain 1 through 31 characters.");
84
103
  if (!Number.isFinite(size) || size <= 0 || size > 409)
85
104
  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);
105
+ return deduplicate(this.fonts, this.fontIndexes, { name, size, bold: !!bold, italic: !!italic, underline: !!underline, strike: !!strike, color: color ? colorArgb(color) : "" }, this.maximum);
87
106
  }
88
107
  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))
108
+ const { color } = fill, pattern = fill.pattern ?? (color ? "solid" : "none");
109
+ if (!["none", "gray125", "solid"].includes(pattern) || (pattern === "solid" && !color) || (pattern !== "solid" && color))
91
110
  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);
111
+ return deduplicate(this.fills, this.fillIndexes, { pattern, color: color ? colorArgb(color) : "" }, this.maximum + 1);
93
112
  }
94
113
  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);
114
+ return deduplicate(this.borders, this.borderIndexes, normalizeBorder(border), this.maximum);
105
115
  }
106
116
  addNumberFormat(format) {
107
117
  if (typeof format !== "string" || !format || format.length > 255)
@@ -167,7 +177,7 @@ export class StyleRegistry {
167
177
  return this.compose(base, { numberFormat: this.styles[this.validateStyle(dateStyle)].numberFormat });
168
178
  }
169
179
  /** @internal Column shorthand and header style composition. */
170
- forColumn(column, header = false, fill, date = false) {
180
+ forColumn(column, header = false, fill, date = false, border) {
171
181
  const base = !header && column.style !== undefined ? this.styles[this.validateStyle(column.style)] : undefined;
172
182
  const format = column.format !== undefined ? column.format || NumberFormats.General : base?.numberFormat || (column.type === "date" || date ? NumberFormats.DateTime : NumberFormats.General);
173
183
  return this.add({
@@ -176,7 +186,7 @@ export class StyleRegistry {
176
186
  wrapText: column.wrapText ?? base?.wrapText ?? false,
177
187
  ...(column.alignment ? { alignment: column.alignment } : base?.alignment ? { alignment: base.alignment } : {}),
178
188
  ...(base?.verticalAlignment ? { verticalAlignment: base.verticalAlignment } : {}),
179
- ...(header ? { font: { bold: true } } : {}), ...(fill ? { fill: { color: fill } } : {})
189
+ ...(header ? { font: { bold: true } } : {}), ...(fill ? { fill: { color: fill } } : {}), ...(border ? { border } : {})
180
190
  });
181
191
  }
182
192
  toXml() {
@@ -6,7 +6,7 @@ import type { Compression } from "../zip/index.js";
6
6
  import type { PackagePart, Relationship } from "../opc/index.js";
7
7
  import type { CoreProperties, AppProperties } from "../opc/index.js";
8
8
  import type { Cell } from "./values.js";
9
- import type { CellStyle } from "./styles.js";
9
+ import type { Border, CellStyle } from "./styles.js";
10
10
  import type { Hyperlink } from "./attachments.js";
11
11
  import type { ExportValue } from "../core/presentation.js";
12
12
  import type { ConditionalFormat } from "./conditional-types.js";
@@ -118,6 +118,10 @@ export interface SheetOptions<T = never> {
118
118
  readonly autoFilter?: boolean;
119
119
  readonly boldHeader?: boolean;
120
120
  readonly headerFill?: string;
121
+ /** Header-row border edges, for example a thin bottom rule under the headings. Ignored when headerStyle is set. */
122
+ readonly headerBorder?: Border;
123
+ /** Wrap every header cell; omitted, a header wraps only when its column does. Ignored when headerStyle is set. */
124
+ readonly headerWrap?: boolean;
121
125
  readonly headerStyle?: number;
122
126
  /** Presentation patches retain column number/date formats. The second data row gets this patch first. */
123
127
  readonly alternatingRowStyle?: CellStyle;
@@ -5,7 +5,7 @@ import { ChunkedTextSink } from "../core/sinks.js";
5
5
  import { ExportBudget } from "../core/limits.js";
6
6
  import { OpcPackage, officeRelationshipsNamespace, relationshipTypes, corePropertiesXml } from "../opc/index.js";
7
7
  import { escapeOoxmlAttribute, cleanXml, xmlDeclaration } from "../xml/index.js";
8
- import { StyleRegistry, spreadsheetNamespace } from "./styles.js";
8
+ import { StyleRegistry, spreadsheetNamespace, normalizeBorder } 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";
@@ -31,6 +31,8 @@ function captureSheet(options, policy) {
31
31
  return { ...captured, columns,
32
32
  ...(captured.columnOutlines === undefined ? {} : { columnOutlines: captureColumnOutlines(captured.columnOutlines, columns.length) }),
33
33
  ...(captured.headerRows === undefined ? {} : { headerRows: captureTableSpans(captured.headerRows, columns.length) }),
34
+ // Preflight and every header style read this one snapshot of the edges.
35
+ ...(captured.headerBorder === undefined ? {} : { headerBorder: normalizeBorder(captured.headerBorder) }),
34
36
  ...(footer ? { footer: { ...footer,
35
37
  ...(footer.rows === undefined ? {} : { rows: captureTableSpans(footer.rows, columns.length) }),
36
38
  ...(footer.values === undefined ? {} : { values: footer.values.map(copyValue) }) } } : {}),
@@ -87,8 +87,9 @@ export class Worksheet {
87
87
  book.checkLinks(this.links.length);
88
88
  this.declared = this.columns.map((column, i) => ({ column, letter: columnName(i + 1),
89
89
  style: book.styles.forColumn(column), dateStyle: book.styles.forColumn(column, false, undefined, true),
90
- headerStyle: this.headerRows ? options.headerStyle ?? book.styles.forColumn({ header: column.header, ...(column.wrapText === undefined ? {} : { wrapText: column.wrapText }),
91
- ...(column.alignment === undefined ? {} : { alignment: column.alignment }) }, options.boldHeader !== false, options.headerFill) : 0
90
+ headerStyle: this.headerRows ? options.headerStyle ?? book.styles.forColumn({ header: column.header,
91
+ ...((options.headerWrap ?? column.wrapText) === undefined ? {} : { wrapText: options.headerWrap ?? column.wrapText }),
92
+ ...(column.alignment === undefined ? {} : { alignment: column.alignment }) }, options.boldHeader !== false, options.headerFill, false, options.headerBorder) : 0
92
93
  }));
93
94
  // Register conditional styles only after worksheet construction can no longer reject its options.
94
95
  this.conditional = new ConditionalFormats(conditional, book.styles);
@@ -140,6 +141,8 @@ export class Worksheet {
140
141
  throw new TypeError("A frozen header or autofilter requires a header row.");
141
142
  if (options.headerFill !== undefined)
142
143
  colorArgb(options.headerFill);
144
+ if (options.headerWrap !== undefined && typeof options.headerWrap !== "boolean")
145
+ throw new TypeError("headerWrap must be boolean.");
143
146
  if (options.headerStyle !== undefined)
144
147
  book.styles.validateStyle(options.headerStyle);
145
148
  if (options.alternatingRowStyle !== undefined)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evotecit/officeimo",
3
- "version": "0.1.9",
3
+ "version": "0.1.21",
4
4
  "description": "Dependency-free OfficeIMO document libraries for browsers, workers and Node.",
5
5
  "type": "module",
6
6
  "license": "MIT",