@evotecit/officeimo 0.1.19 → 0.1.43

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 (102) hide show
  1. package/README.md +44 -10
  2. package/bundles/officeimo-canopyx-adapter.js +147 -65
  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 +134 -53
  6. package/bundles/officeimo-canopyx.js +554 -234
  7. package/bundles/officeimo-canopyx.min.js +1 -1
  8. package/bundles/officeimo-canopyx.min.mjs +1 -1
  9. package/bundles/officeimo-canopyx.mjs +477 -158
  10. package/bundles/officeimo-chartforgex-adapter.js +1924 -0
  11. package/bundles/officeimo-chartforgex-adapter.min.js +2 -0
  12. package/bundles/officeimo-chartforgex-adapter.min.mjs +2 -0
  13. package/bundles/officeimo-chartforgex-adapter.mjs +1910 -0
  14. package/bundles/officeimo-chartforgex.js +13594 -0
  15. package/bundles/officeimo-chartforgex.min.js +2 -0
  16. package/bundles/officeimo-chartforgex.min.mjs +2 -0
  17. package/bundles/officeimo-chartforgex.mjs +13487 -0
  18. package/bundles/officeimo-csv.js +12 -7
  19. package/bundles/officeimo-csv.min.js +1 -1
  20. package/bundles/officeimo-csv.min.mjs +1 -1
  21. package/bundles/officeimo-csv.mjs +8 -3
  22. package/bundles/officeimo-datatables-adapter.js +11 -11
  23. package/bundles/officeimo-datatables-adapter.min.js +1 -1
  24. package/bundles/officeimo-datatables-adapter.min.mjs +1 -1
  25. package/bundles/officeimo-datatables-adapter.mjs +7 -7
  26. package/bundles/officeimo-datatables.js +418 -180
  27. package/bundles/officeimo-datatables.min.js +1 -1
  28. package/bundles/officeimo-datatables.min.mjs +1 -1
  29. package/bundles/officeimo-datatables.mjs +350 -112
  30. package/bundles/officeimo-execution.js +14 -9
  31. package/bundles/officeimo-execution.min.js +1 -1
  32. package/bundles/officeimo-execution.min.mjs +1 -1
  33. package/bundles/officeimo-execution.mjs +8 -3
  34. package/bundles/officeimo-pdf.js +286 -120
  35. package/bundles/officeimo-pdf.min.js +1 -1
  36. package/bundles/officeimo-pdf.min.mjs +1 -1
  37. package/bundles/officeimo-pdf.mjs +244 -78
  38. package/bundles/officeimo-xlsx.js +136 -59
  39. package/bundles/officeimo-xlsx.min.js +1 -1
  40. package/bundles/officeimo-xlsx.min.mjs +1 -1
  41. package/bundles/officeimo-xlsx.mjs +114 -37
  42. package/bundles/officeimo.js +416 -178
  43. package/bundles/officeimo.min.js +1 -1
  44. package/bundles/officeimo.min.mjs +1 -1
  45. package/bundles/officeimo.mjs +351 -113
  46. package/dist/core/progress.js +7 -2
  47. package/dist/index.d.ts +1 -1
  48. package/dist/integrations/canopyx/index.js +13 -4
  49. package/dist/integrations/canopyx/pdf-number.js +9 -6
  50. package/dist/integrations/canopyx/rule-predicates.d.ts +1 -1
  51. package/dist/integrations/canopyx/rule-predicates.js +2 -1
  52. package/dist/integrations/canopyx/rules.d.ts +1 -1
  53. package/dist/integrations/canopyx/rules.js +11 -13
  54. package/dist/integrations/canopyx/source.js +57 -7
  55. package/dist/integrations/canopyx/tones.d.ts +10 -0
  56. package/dist/integrations/canopyx/tones.js +12 -0
  57. package/dist/integrations/canopyx/types.d.ts +8 -1
  58. package/dist/integrations/chartforgex/capture.d.ts +31 -0
  59. package/dist/integrations/chartforgex/capture.js +103 -0
  60. package/dist/integrations/chartforgex/index.d.ts +13 -0
  61. package/dist/integrations/chartforgex/index.js +88 -0
  62. package/dist/integrations/chartforgex/svg-drawing.d.ts +5 -0
  63. package/dist/integrations/chartforgex/svg-drawing.js +775 -0
  64. package/dist/integrations/chartforgex/svg-geometry.d.ts +23 -0
  65. package/dist/integrations/chartforgex/svg-geometry.js +304 -0
  66. package/dist/integrations/chartforgex/svg-image.d.ts +9 -0
  67. package/dist/integrations/chartforgex/svg-image.js +46 -0
  68. package/dist/integrations/chartforgex/svg-markup.d.ts +10 -0
  69. package/dist/integrations/chartforgex/svg-markup.js +124 -0
  70. package/dist/integrations/chartforgex/svg-paint.d.ts +16 -0
  71. package/dist/integrations/chartforgex/svg-paint.js +146 -0
  72. package/dist/integrations/chartforgex/types.d.ts +77 -0
  73. package/dist/integrations/chartforgex/types.js +1 -0
  74. package/dist/integrations/chartforgex/winansi.d.ts +4 -0
  75. package/dist/integrations/chartforgex/winansi.js +48 -0
  76. package/dist/integrations/chartforgex/workbook.d.ts +12 -0
  77. package/dist/integrations/chartforgex/workbook.js +137 -0
  78. package/dist/pdf/document-drawings.d.ts +1 -1
  79. package/dist/pdf/document-drawings.js +91 -17
  80. package/dist/pdf/document-images.d.ts +7 -1
  81. package/dist/pdf/document-images.js +59 -24
  82. package/dist/pdf/document-types.d.ts +3 -1
  83. package/dist/pdf/document.d.ts +2 -2
  84. package/dist/pdf/document.js +3 -1
  85. package/dist/pdf/drawing-types.d.ts +37 -10
  86. package/dist/pdf/font-resources.d.ts +1 -1
  87. package/dist/pdf/font-resources.js +6 -3
  88. package/dist/pdf/index.d.ts +1 -1
  89. package/dist/pdf/pages.js +15 -0
  90. package/dist/pdf/png.d.ts +11 -2
  91. package/dist/pdf/png.js +50 -23
  92. package/dist/pdf/session.js +3 -2
  93. package/dist/pdf/settings.d.ts +2 -2
  94. package/dist/pdf/settings.js +7 -3
  95. package/dist/xlsx/options.js +2 -2
  96. package/dist/xlsx/portable.js +1 -1
  97. package/dist/xlsx/styles.js +28 -18
  98. package/dist/xlsx/types.d.ts +13 -1
  99. package/dist/xlsx/workbook.js +9 -1
  100. package/dist/xlsx/worksheet.d.ts +13 -1
  101. package/dist/xlsx/worksheet.js +65 -11
  102. package/package.json +9 -2
@@ -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";
@@ -74,6 +74,14 @@ export interface WorkbookOptions extends StreamOptions, CoreProperties {
74
74
  readonly cellValueWriters?: Readonly<Record<string, CellValueWriter>>;
75
75
  /** Reject by default. Preserve keeps a bounded preview and the full text in numbered overflow-sheet chunks. */
76
76
  readonly oversizedText?: "reject" | "preserve";
77
+ /** Excel allows 65,530 hyperlinks per worksheet. Reject by default. Drop keeps every configured, header, footer and
78
+ * text-preservation link, and fills the remaining room with data-cell links in row order; later data cells keep their value without the link. */
79
+ readonly hyperlinkOverflow?: "reject" | "drop";
80
+ /** Called synchronously once per worksheet that dropped data-cell links under `hyperlinkOverflow: "drop"`. */
81
+ readonly onHyperlinkOverflow?: (overflow: {
82
+ readonly sheetName: string;
83
+ readonly dropped: number;
84
+ }) => void;
77
85
  }
78
86
  export interface WorkbookLimits extends ExportLimits {
79
87
  readonly maxStyles?: number;
@@ -118,6 +126,10 @@ export interface SheetOptions<T = never> {
118
126
  readonly autoFilter?: boolean;
119
127
  readonly boldHeader?: boolean;
120
128
  readonly headerFill?: string;
129
+ /** Header-row border edges, for example a thin bottom rule under the headings. Ignored when headerStyle is set. */
130
+ readonly headerBorder?: Border;
131
+ /** Wrap every header cell; omitted, a header wraps only when its column does. Ignored when headerStyle is set. */
132
+ readonly headerWrap?: boolean;
121
133
  readonly headerStyle?: number;
122
134
  /** Presentation patches retain column number/date formats. The second data row gets this patch first. */
123
135
  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) }) } } : {}),
@@ -106,6 +108,10 @@ export class Workbook {
106
108
  throw new RangeError("compression must be auto or store.");
107
109
  if (options.oversizedText !== undefined && !["reject", "preserve"].includes(options.oversizedText))
108
110
  throw new RangeError("oversizedText must be reject or preserve.");
111
+ if (options.hyperlinkOverflow !== undefined && !["reject", "drop"].includes(options.hyperlinkOverflow))
112
+ throw new RangeError("hyperlinkOverflow must be reject or drop.");
113
+ if (options.onHyperlinkOverflow !== undefined && typeof options.onHyperlinkOverflow !== "function")
114
+ throw new TypeError("onHyperlinkOverflow must be a function.");
109
115
  cleanXml("", policy);
110
116
  corePropertiesXml(options, policy);
111
117
  this.budget = new ExportBudget(options.limits);
@@ -183,6 +189,8 @@ export class Workbook {
183
189
  }
184
190
  /** @internal Reserve a preflighted worksheet batch or one row hyperlink. */
185
191
  retainLink(count = 1) { this.checkLinks(count); this.links += count; }
192
+ /** @internal A worksheet dropped a data-cell link it had retained. */
193
+ releaseLink() { this.links--; }
186
194
  /** @internal */
187
195
  checkImage(bytes) {
188
196
  if (this.settings.limits?.maxImageBytes !== undefined && this.imageBytes + bytes > this.settings.limits.maxImageBytes)
@@ -35,8 +35,13 @@ export declare class Worksheet<T = never> {
35
35
  private pendingCharacters;
36
36
  private reservedLayout;
37
37
  private readonly internalLinks;
38
- private readonly links;
38
+ private links;
39
+ private evictedLinks;
39
40
  private readonly linkedCells;
41
+ /** Indexes in `links` of data-cell links that `hyperlinkOverflow: "drop"` may give up, in row order. */
42
+ private droppable;
43
+ private readonly droppableLinks;
44
+ private droppedLinks;
40
45
  private readonly pictures;
41
46
  private readonly nativeCharts;
42
47
  private readonly conditional;
@@ -66,6 +71,13 @@ export declare class Worksheet<T = never> {
66
71
  /** Attach an external report link to a cell without changing its literal value. */
67
72
  addHyperlink(link: Hyperlink): void;
68
73
  private appendHyperlink;
74
+ /** Links the worksheet holds now, not counting evicted holes. */
75
+ private get linkCount();
76
+ /** A full worksheet gives up its latest data-cell link for a link that cannot be dropped. Hyperlinks are serialized after
77
+ * the rows, so the cell keeps its written value. The entry becomes a hole, so other indexes stay valid until compaction. */
78
+ private makeLinkRoom;
79
+ /** One ordered pass removes evicted holes and rebuilds the droppable indexes. */
80
+ private compactLinks;
69
81
  /** Complete this worksheet. A streamed workbook can then start its next worksheet. */
70
82
  close(): Promise<void>;
71
83
  }
@@ -1,7 +1,7 @@
1
1
  import { checkAbort, consumeRows, inputRows, pause, taskYieldDue } from "../core/iteration.js";
2
2
  import { ChunkedTextSink, BlobByteSink } from "../core/sinks.js";
3
3
  import { OfficeIMOError } from "../core/errors.js";
4
- import { notifyProgress } from "../core/progress.js";
4
+ import { notifyProgress, notifySynchronously } from "../core/progress.js";
5
5
  import { copyColumns, createRowProjector } from "../internal/rows.js";
6
6
  import { EntryWriter } from "../zip/entry.js";
7
7
  import { xmlDeclaration } from "../xml/index.js";
@@ -55,8 +55,14 @@ export class Worksheet {
55
55
  pendingCharacters = 0;
56
56
  reservedLayout = false;
57
57
  internalLinks = [];
58
+ // Evicted entries become holes and are compacted in one pass when the links are read, keeping eviction O(1).
58
59
  links = [];
60
+ evictedLinks = 0;
59
61
  linkedCells = new Set();
62
+ /** Indexes in `links` of data-cell links that `hyperlinkOverflow: "drop"` may give up, in row order. */
63
+ droppable = [];
64
+ droppableLinks = new WeakSet();
65
+ droppedLinks = 0;
60
66
  pictures = [];
61
67
  nativeCharts = [];
62
68
  conditional;
@@ -87,8 +93,9 @@ export class Worksheet {
87
93
  book.checkLinks(this.links.length);
88
94
  this.declared = this.columns.map((column, i) => ({ column, letter: columnName(i + 1),
89
95
  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
96
+ headerStyle: this.headerRows ? options.headerStyle ?? book.styles.forColumn({ header: column.header,
97
+ ...((options.headerWrap ?? column.wrapText) === undefined ? {} : { wrapText: options.headerWrap ?? column.wrapText }),
98
+ ...(column.alignment === undefined ? {} : { alignment: column.alignment }) }, options.boldHeader !== false, options.headerFill, false, options.headerBorder) : 0
92
99
  }));
93
100
  // Register conditional styles only after worksheet construction can no longer reject its options.
94
101
  this.conditional = new ConditionalFormats(conditional, book.styles);
@@ -140,6 +147,8 @@ export class Worksheet {
140
147
  throw new TypeError("A frozen header or autofilter requires a header row.");
141
148
  if (options.headerFill !== undefined)
142
149
  colorArgb(options.headerFill);
150
+ if (options.headerWrap !== undefined && typeof options.headerWrap !== "boolean")
151
+ throw new TypeError("headerWrap must be boolean.");
143
152
  if (options.headerStyle !== undefined)
144
153
  book.styles.validateStyle(options.headerStyle);
145
154
  if (options.alternatingRowStyle !== undefined)
@@ -265,7 +274,8 @@ export class Worksheet {
265
274
  const cell = col.letter + row;
266
275
  if (link || this.linkedCells.has(cell))
267
276
  throw new TypeError("A text-preservation cell cannot also have an external hyperlink.");
268
- checkHyperlinkCount(this.links.length + this.internalLinks.length + 1);
277
+ this.makeLinkRoom();
278
+ checkHyperlinkCount(this.linkCount + 1);
269
279
  this.book.checkLinks(1);
270
280
  // Replace a generated cell's original reservation with its preview and overflow records.
271
281
  if (reservedCharacters !== undefined) {
@@ -279,7 +289,7 @@ export class Worksheet {
279
289
  value = preserved.preview;
280
290
  }
281
291
  if (link)
282
- this.appendHyperlink({ cell: col.letter + row, ...link });
292
+ this.appendHyperlink({ cell: col.letter + row, ...link }, !header && !footer && !title && this.book.settings.hyperlinkOverflow === "drop");
283
293
  if (type === "date")
284
294
  value = excelDate(value, this.book.settings.dateMode);
285
295
  if (!header && !footer && visible && (!formula || !isSubtotalFormula(formula)))
@@ -588,20 +598,61 @@ export class Worksheet {
588
598
  throw this.error;
589
599
  this.appendHyperlink(link);
590
600
  }
591
- appendHyperlink(link) {
601
+ appendHyperlink(link, droppable = false) {
602
+ // Validate before any overflow decision, so a dropped link can never hide an unsafe target.
592
603
  const copied = copyHyperlink(link, this.book.settings.invalidCharacterPolicy);
593
604
  const position = cellPosition(copied.cell);
594
605
  if (this.layout.regions.covered(position.column, position.row))
595
606
  throw new TypeError("Hyperlinks cannot address a covered merged cell.");
596
607
  if (this.linkedCells.has(copied.cell))
597
608
  throw new TypeError("Duplicate hyperlink cell: " + copied.cell);
598
- checkHyperlinkCount(this.links.length + this.internalLinks.length + 1);
609
+ if (droppable && this.linkCount >= maximumHyperlinks) {
610
+ this.droppedLinks++;
611
+ return;
612
+ }
613
+ if (!droppable)
614
+ this.makeLinkRoom();
615
+ checkHyperlinkCount(this.linkCount + 1);
599
616
  this.book.retainLink();
617
+ if (droppable) {
618
+ this.droppable.push(this.links.length);
619
+ this.droppableLinks.add(copied);
620
+ }
600
621
  this.links.push(copied);
601
622
  this.linkedCells.add(copied.cell);
602
623
  }
624
+ /** Links the worksheet holds now, not counting evicted holes. */
625
+ get linkCount() { return this.links.length - this.evictedLinks + this.internalLinks.length; }
626
+ /** A full worksheet gives up its latest data-cell link for a link that cannot be dropped. Hyperlinks are serialized after
627
+ * the rows, so the cell keeps its written value. The entry becomes a hole, so other indexes stay valid until compaction. */
628
+ makeLinkRoom() {
629
+ if (this.linkCount < maximumHyperlinks || !this.droppable.length)
630
+ return;
631
+ const index = this.droppable.pop(), removed = this.links[index];
632
+ this.links[index] = undefined;
633
+ this.evictedLinks++;
634
+ this.linkedCells.delete(removed.cell);
635
+ this.book.releaseLink();
636
+ this.droppedLinks++;
637
+ }
638
+ /** One ordered pass removes evicted holes and rebuilds the droppable indexes. */
639
+ compactLinks() {
640
+ if (this.evictedLinks) {
641
+ const kept = [], droppable = [];
642
+ for (const link of this.links)
643
+ if (link) {
644
+ if (this.droppableLinks.has(link))
645
+ droppable.push(kept.length);
646
+ kept.push(link);
647
+ }
648
+ this.links = kept;
649
+ this.droppable = droppable;
650
+ this.evictedLinks = 0;
651
+ }
652
+ return this.links;
653
+ }
603
654
  /** @internal */
604
- get hyperlinks() { return this.links; }
655
+ get hyperlinks() { return this.compactLinks(); }
605
656
  /** @internal */
606
657
  get images() { return this.pictures; }
607
658
  /** @internal An empty export has no data table; it still emits the declared headers. */
@@ -652,7 +703,7 @@ export class Worksheet {
652
703
  for (const binding of this.chartSources)
653
704
  binding.finish();
654
705
  this.chartSources.length = 0;
655
- for (const link of this.links) {
706
+ for (const link of this.compactLinks()) {
656
707
  const position = cellPosition(link.cell);
657
708
  if (position.column > this.columns.length || position.row > this.totalRows)
658
709
  throw new RangeError("Hyperlinks must address cells within the exported rows and columns.");
@@ -682,8 +733,11 @@ export class Worksheet {
682
733
  await this.buffer.write(xml);
683
734
  for (const xml of dataValidationsXml(this.validations, this.headerRows, this.count, detailRanges))
684
735
  await this.buffer.write(xml);
685
- if (this.links.length || this.internalLinks.length)
686
- await this.buffer.write(hyperlinksXml(this.links, this.book.settings.invalidCharacterPolicy, this.internalLinks));
736
+ if (this.droppedLinks)
737
+ notifySynchronously("onHyperlinkOverflow", this.book.settings.onHyperlinkOverflow, Object.freeze({ sheetName: this.name, dropped: this.droppedLinks }));
738
+ const links = this.compactLinks();
739
+ if (links.length || this.internalLinks.length)
740
+ await this.buffer.write(hyperlinksXml(links, this.book.settings.invalidCharacterPolicy, this.internalLinks));
687
741
  await this.buffer.write(printXml(this.options.print, this.book.settings.invalidCharacterPolicy));
688
742
  if (this.pictures.length || this.nativeCharts.length)
689
743
  await this.buffer.write('<drawing r:id="drawing"/>');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evotecit/officeimo",
3
- "version": "0.1.19",
3
+ "version": "0.1.43",
4
4
  "description": "Dependency-free OfficeIMO document libraries for browsers, workers and Node.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -56,7 +56,12 @@
56
56
  "types": "./dist/integrations/canopyx/index.d.ts",
57
57
  "import": "./dist/integrations/canopyx/index.js"
58
58
  },
59
+ "./integrations/chartforgex": {
60
+ "types": "./dist/integrations/chartforgex/index.d.ts",
61
+ "import": "./dist/integrations/chartforgex/index.js"
62
+ },
59
63
  "./canopyx.js": "./bundles/officeimo-canopyx.js",
64
+ "./chartforgex.js": "./bundles/officeimo-chartforgex.js",
60
65
  "./datatables.js": "./bundles/officeimo-datatables.js",
61
66
  "./classic.js": "./bundles/officeimo.js",
62
67
  "./xlsx.js": "./bundles/officeimo-xlsx.js",
@@ -65,6 +70,7 @@
65
70
  "./execution.js": "./bundles/officeimo-execution.js",
66
71
  "./canopyx-adapter.js": "./bundles/officeimo-canopyx-adapter.js",
67
72
  "./datatables-adapter.js": "./bundles/officeimo-datatables-adapter.js",
73
+ "./chartforgex-adapter.js": "./bundles/officeimo-chartforgex-adapter.js",
68
74
  "./bundles/*": "./bundles/*"
69
75
  },
70
76
  "files": [
@@ -105,6 +111,7 @@
105
111
  "excel",
106
112
  "browser",
107
113
  "streaming",
108
- "typescript"
114
+ "typescript",
115
+ "chartforgex"
109
116
  ]
110
117
  }