@evotecit/officeimo 0.1.2 → 0.1.3

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 (37) hide show
  1. package/README.md +43 -49
  2. package/bundles/officeimo-canopyx.js +966 -122
  3. package/bundles/officeimo-canopyx.mjs +929 -92
  4. package/bundles/officeimo-csv.js +18 -15
  5. package/bundles/officeimo-csv.mjs +16 -13
  6. package/bundles/officeimo-datatables.js +168 -82
  7. package/bundles/officeimo-datatables.mjs +140 -54
  8. package/bundles/officeimo-pdf.js +148 -65
  9. package/bundles/officeimo-pdf.mjs +124 -41
  10. package/bundles/officeimo.js +168 -82
  11. package/bundles/officeimo.mjs +140 -54
  12. package/dist/csv/index.js +16 -13
  13. package/dist/integrations/canopyx/diagnostics.d.ts +3 -0
  14. package/dist/integrations/canopyx/diagnostics.js +17 -0
  15. package/dist/integrations/canopyx/grouping.d.ts +6 -0
  16. package/dist/integrations/canopyx/grouping.js +188 -0
  17. package/dist/integrations/canopyx/index.d.ts +2 -2
  18. package/dist/integrations/canopyx/index.js +72 -15
  19. package/dist/integrations/canopyx/metadata.d.ts +4 -0
  20. package/dist/integrations/canopyx/metadata.js +51 -0
  21. package/dist/integrations/canopyx/presentation.d.ts +8 -0
  22. package/dist/integrations/canopyx/presentation.js +40 -0
  23. package/dist/integrations/canopyx/rule-predicates.d.ts +3 -0
  24. package/dist/integrations/canopyx/rule-predicates.js +110 -0
  25. package/dist/integrations/canopyx/rules.d.ts +6 -0
  26. package/dist/integrations/canopyx/rules.js +176 -0
  27. package/dist/integrations/canopyx/source.js +24 -22
  28. package/dist/integrations/canopyx/types.d.ts +89 -8
  29. package/dist/integrations/canopyx/workbook.d.ts +6 -0
  30. package/dist/integrations/canopyx/workbook.js +52 -0
  31. package/dist/pdf/font-resources.js +33 -14
  32. package/dist/pdf/pages.js +60 -14
  33. package/dist/pdf/table-band-flow.js +7 -2
  34. package/dist/pdf/table-band-plan.js +9 -1
  35. package/dist/pdf/table-layout.js +6 -2
  36. package/dist/pdf/table-structure.js +9 -8
  37. package/package.json +1 -1
@@ -1111,29 +1111,32 @@ const { captureCsvOptions } = _m19;
1111
1111
 
1112
1112
 
1113
1113
 
1114
- function csvField(value, delimiter, protect, quote, booleanText, nullValue) {
1115
- if (value == null && nullValue !== undefined)
1116
- value = nullValue;
1114
+ function csvField(value, delimiter, protect, quote, booleanText) {
1115
+ const kind = typeof value;
1117
1116
  let text;
1118
1117
  if (value == null)
1119
1118
  text = "";
1119
+ else if (kind === "string")
1120
+ text = value;
1121
+ else if (kind === "number") {
1122
+ text = Number.isFinite(value) ? String(value) : "";
1123
+ // Numeric text has no CSV delimiter, quote or line break to escape.
1124
+ return quote === "all" ? '"' + text + '"' : text;
1125
+ }
1126
+ else if (kind === "boolean")
1127
+ text = booleanText[value ? "true" : "false"];
1120
1128
  else if (isDate(value))
1121
1129
  text = Number.isFinite(value.getTime()) ? value.toISOString() : "";
1122
- else if (typeof value === "boolean")
1123
- text = booleanText[value ? "true" : "false"];
1124
- else if (typeof value === "number")
1125
- text = Number.isFinite(value) ? String(value) : "";
1126
- else if (typeof value === "string")
1127
- text = value;
1128
1130
  else {
1129
1131
  if (typeof value.then === "function")
1130
1132
  void Promise.resolve(value).catch(() => { });
1131
1133
  throw new TypeError("CSV cells and formatter results must be synchronous strings, numbers, booleans, Dates or null.");
1132
1134
  }
1133
- if (protect && (typeof value === "string" || typeof value === "boolean") && /^ *[=+\-@\t\r\n]/.test(text))
1135
+ // Only ASCII spaces, controls and markers through @ can begin the protected prefix.
1136
+ if (protect && (kind === "string" || kind === "boolean") && text.charCodeAt(0) <= 64 && /^ *[=+\-@\t\r\n]/.test(text))
1134
1137
  text = "'" + text;
1135
- return quote === "all" || (quote === "strings" && typeof value === "string") || text.includes(delimiter) || /["\r\n]/.test(text)
1136
- ? '"' + text.replace(/"/g, '""') + '"' : text;
1138
+ return quote === "all" || (quote === "strings" && kind === "string") || text.includes(delimiter) || /["\r\n]/.test(text)
1139
+ ? '"' + (text.includes('"') ? text.replace(/"/g, '""') : text) + '"' : text;
1137
1140
  }
1138
1141
  async function writeCsvTo(rows, destination, configuration) {
1139
1142
  const options = captureCsvOptions(configuration);
@@ -1185,7 +1188,7 @@ async function write(rows, sink, options) {
1185
1188
  value = options.nullValue;
1186
1189
  budget.cell(typeof value === "boolean" ? booleanText[value ? "true" : "false"] : value);
1187
1190
  checkAbort(signal);
1188
- text += (i ? delimiter : "") + csvField(value, delimiter, protect, quote, booleanText, options.nullValue);
1191
+ text += (i ? delimiter : "") + csvField(value, delimiter, protect, quote, booleanText);
1189
1192
  if (text.length >= buffer.chunkSize || (i & 127) === 127 && taskYieldDue()) {
1190
1193
  if (buffer.append(text))
1191
1194
  return buffer.flush().then(() => record(values, header, i + 1, snapshot));
@@ -7141,7 +7144,8 @@ const { pdfNumber, unicodeHex } = _m59;
7141
7144
 
7142
7145
  const { checkAbort, pause, taskYieldDue } = _m4;
7143
7146
 
7144
- const standardHexBytes = Object.freeze(Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, "0")));
7147
+ const hexBytes = Object.freeze(Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, "0")));
7148
+ function cidHex(cid) { return hexBytes[cid >>> 8] + hexBytes[cid & 255]; }
7145
7149
  class PdfFontResource {
7146
7150
  index;
7147
7151
  bold;
@@ -7172,12 +7176,16 @@ class PdfFontResource {
7172
7176
  width(scalar) {
7173
7177
  if (this.shared)
7174
7178
  return this.shared.width(scalar);
7175
- const existing = this.mappings.get(scalar);
7176
- if (existing)
7177
- return existing.width;
7178
- const standard = this.standardWidths.get(scalar);
7179
- if (standard !== undefined)
7180
- return standard;
7179
+ if (this.program) {
7180
+ const existing = this.mappings.get(scalar);
7181
+ if (existing)
7182
+ return existing.width;
7183
+ }
7184
+ else {
7185
+ const standard = this.standardWidths.get(scalar);
7186
+ if (standard !== undefined)
7187
+ return standard;
7188
+ }
7181
7189
  const resolved = resolveScalar(scalar, this.program, this.bold);
7182
7190
  if (!resolved.supported) {
7183
7191
  if (resolved.code === "unpaired-surrogate")
@@ -7190,7 +7198,8 @@ class PdfFontResource {
7190
7198
  }
7191
7199
  if (this.mappings.size >= 65535)
7192
7200
  throw new OfficeIMOError("RESOURCE_LIMIT", "A PDF font supports at most 65,535 distinct Unicode scalars.");
7193
- const mapping = { cid: this.mappings.size + 1, glyph: resolved.glyph, width: resolved.width, text: String.fromCodePoint(scalar) };
7201
+ const cid = this.mappings.size + 1;
7202
+ const mapping = { cid, hex: cidHex(cid), glyph: resolved.glyph, width: resolved.width, text: String.fromCodePoint(scalar) };
7194
7203
  this.mappings.set(scalar, mapping);
7195
7204
  return mapping.width;
7196
7205
  }
@@ -7203,8 +7212,20 @@ class PdfFontResource {
7203
7212
  let hex = "";
7204
7213
  for (const char of text) {
7205
7214
  const cp = char.codePointAt(0);
7206
- this.width(cp);
7207
- hex += this.program ? this.mappings.get(cp).cid.toString(16).padStart(4, "0") : standardHexBytes[standardCode(cp)];
7215
+ if (this.program) {
7216
+ let mapping = this.mappings.get(cp);
7217
+ // Layout normally registered the scalar already; validate only a newly painted scalar.
7218
+ if (!mapping) {
7219
+ this.width(cp);
7220
+ mapping = this.mappings.get(cp);
7221
+ }
7222
+ hex += mapping.hex;
7223
+ }
7224
+ else {
7225
+ if (!this.standardWidths.has(cp))
7226
+ this.width(cp);
7227
+ hex += hexBytes[standardCode(cp)];
7228
+ }
7208
7229
  }
7209
7230
  return "<" + hex + ">";
7210
7231
  }
@@ -7219,10 +7240,11 @@ class PdfFontResource {
7219
7240
  if (!mapping) {
7220
7241
  if (this.mappings.size >= 65535)
7221
7242
  throw new OfficeIMOError("RESOURCE_LIMIT", "A PDF font supports at most 65,535 distinct CID mappings.");
7222
- mapping = { cid: this.mappings.size + 1, glyph, width: this.program.widths[glyph], text };
7243
+ const cid = this.mappings.size + 1;
7244
+ mapping = { cid, hex: cidHex(cid), glyph, width: this.program.widths[glyph], text };
7223
7245
  this.mappings.set(key, mapping);
7224
7246
  }
7225
- return "<" + mapping.cid.toString(16).padStart(4, "0") + ">";
7247
+ return "<" + mapping.hex + ">";
7226
7248
  }
7227
7249
  async write(objects, compression) {
7228
7250
  checkAbort(this.signal);
@@ -7271,7 +7293,7 @@ class PdfFontResource {
7271
7293
  const batch = mapped.slice(i, i + 100);
7272
7294
  cmap += batch.length + " beginbfchar\n";
7273
7295
  for (const [, m] of batch)
7274
- cmap += "<" + m.cid.toString(16).padStart(4, "0") + "> <" + unicodeHex(m.text) + ">\n";
7296
+ cmap += "<" + m.hex + "> <" + unicodeHex(m.text) + ">\n";
7275
7297
  cmap += "endbfchar\n";
7276
7298
  if (taskYieldDue())
7277
7299
  await pause();
@@ -7322,7 +7344,7 @@ class PdfFontResources {
7322
7344
  if (!found)
7323
7345
  this.explicitSelections.set(explicit, selections);
7324
7346
  }
7325
- const key = String(bold) + String(italic), existing = selections.get(key);
7347
+ const key = (bold ? 2 : 0) | (italic ? 1 : 0), existing = selections.get(key);
7326
7348
  if (existing)
7327
7349
  return existing;
7328
7350
  const { font, syntheticBold, syntheticItalic } = explicit ? { font: explicit, syntheticBold: bold, syntheticItalic: italic } : selectFont(this.fonts, bold, italic);
@@ -7908,6 +7930,14 @@ async function projectBandRows(rows, band, widths, settings, fonts) {
7908
7930
  for (const row of rows) {
7909
7931
  const cells = [];
7910
7932
  for (const cell of row.cells) {
7933
+ // Ordinary data and leaf headings keep their captured width and lines in every band.
7934
+ // Look up their physical position without allocating another per-row column index.
7935
+ if (cell.span === 1) {
7936
+ const first = band.columns.indexOf(cell.first);
7937
+ if (first >= 0)
7938
+ cells.push({ ...cell, source: cell.source ?? cell, first });
7939
+ continue;
7940
+ }
7911
7941
  for (let first = 0; first < band.columns.length;) {
7912
7942
  const source = band.columns[first];
7913
7943
  if (source < cell.first || source >= cell.first + cell.span) {
@@ -7918,7 +7948,7 @@ async function projectBandRows(rows, band, widths, settings, fonts) {
7918
7948
  while (end < band.columns.length && band.columns[end] === band.columns[end - 1] + 1 && band.columns[end] < cell.first + cell.span)
7919
7949
  end++;
7920
7950
  const width = band.columns.slice(first, end).reduce((sum, index) => sum + widths[index], 0);
7921
- const lines = cell.span === 1 ? cell.lines : await wrapPdfText(cell.captured, fonts, settings.fontSize, width - settings.padding * 2, settings, cell.style.wrapText !== false);
7951
+ const lines = await wrapPdfText(cell.captured, fonts, settings.fontSize, width - settings.padding * 2, settings, cell.style.wrapText !== false);
7922
7952
  cells.push({ ...cell, source: cell.source ?? cell, first, span: end - first, width, lines,
7923
7953
  lineHeight: lines.reduce((height, line) => Math.max(height, line.lineHeight), cell.font.lineHeight(settings.fontSize)) });
7924
7954
  first = end;
@@ -8070,8 +8100,12 @@ class PdfTableLayout {
8070
8100
  lines };
8071
8101
  }
8072
8102
  row(cells) {
8073
- const lines = Math.max(1, ...cells.map(c => c.lines.length));
8074
- const lineHeight = Math.max(this.lineHeight, ...cells.map(c => c.lineHeight));
8103
+ let lines = 1, lineHeight = this.lineHeight;
8104
+ for (let index = 0; index < cells.length; index++) {
8105
+ const cell = cells[index];
8106
+ lines = Math.max(lines, cell.lines.length);
8107
+ lineHeight = Math.max(lineHeight, cell.lineHeight);
8108
+ }
8075
8109
  return { cells, lines, lineHeight, height: lines * lineHeight + this.settings.padding * 2 };
8076
8110
  }
8077
8111
  async headers() {
@@ -8224,7 +8258,7 @@ class PdfTableBandFlow {
8224
8258
  await this.flush();
8225
8259
  }
8226
8260
  async row(row, allowFirstFragment = false) {
8227
- const { padding, fontSize, options } = this.layout.settings, minimumLines = this.layout.minimumRowLines(row), minimumHeight = this.layout.minimumRowHeight(row);
8261
+ const { padding, fontSize, options } = this.layout.settings, minimumLines = this.layout.minimumRowLines(row), minimumHeight = minimumLines * row.lineHeight + padding * 2;
8228
8262
  if (minimumHeight > this.painter.firstFullCapacity + .001 || minimumHeight > this.painter.continuationCapacity + .001)
8229
8263
  throw new RangeError("Repeated PDF identifiers must fit intact below the first and continued band headings/context.");
8230
8264
  // Keep ordinary rows intact when they fit fresh. A kept heading/caption can deliberately
@@ -8258,9 +8292,14 @@ class PdfTableBandFlow {
8258
8292
  let remaining = false;
8259
8293
  const cells = rows[0].cells.map(cell => {
8260
8294
  const source = this.layout.bands[index].columns[cell.first];
8261
- const repeated = this.layout.repeatedColumn(source), visible = repeated ? cell.lines : cell.lines.slice(first, first + lines);
8295
+ const repeated = this.layout.repeatedColumn(source), reusable = cell.span === 1 && (cell.source?.span ?? 1) === 1 && (cell.rowSpan ?? 1) === 1 &&
8296
+ cell.height === undefined && first === 0 && (repeated || lines >= cell.lines.length);
8297
+ const visible = repeated || reusable ? cell.lines : cell.lines.slice(first, first + lines);
8262
8298
  if (!repeated && (visible.length > 0 || cell.link !== undefined))
8263
8299
  remaining = true;
8300
+ // A complete first fragment already owns these lines and their maximum font metrics.
8301
+ if (reusable)
8302
+ return cell;
8264
8303
  const { height: _height, ...plain } = cell;
8265
8304
  return { ...plain, lines: visible,
8266
8305
  lineHeight: visible.reduce((value, line) => Math.max(value, line.lineHeight), cell.font.lineHeight(fontSize)),
@@ -8368,30 +8407,31 @@ class PdfTableStructure {
8368
8407
  return row.cells.map(cell => this.cells.get(cell));
8369
8408
  const rowId = this.structure.element("TR", parent);
8370
8409
  this.rows.set(row, rowId);
8371
- const headers = row.cells.map((cell, index) => rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex);
8372
8410
  // Allocate in source order, then resolve every row header before associating even earlier data cells.
8373
8411
  // Generated summary labels override detail roles so numeric subtotal cells never become row headers.
8374
8412
  const ids = row.cells.map((cell, index) => {
8375
- const id = this.structure.element(headers[index] ? "TH" : "TD", rowId);
8413
+ const header = rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex;
8414
+ const id = this.structure.element(header ? "TH" : "TD", rowId);
8376
8415
  this.cells.set(cell, id);
8377
8416
  return id;
8378
8417
  });
8379
- const rowHeaders = [];
8418
+ let rowHeaders;
8380
8419
  for (let index = 0; index < ids.length; index++)
8381
- if (headers[index])
8382
- rowHeaders.push(await this.structure.identifier(ids[index]));
8420
+ if (rowHeaderIndex === undefined ? row.cells[index].rowHeader === true : index === rowHeaderIndex)
8421
+ (rowHeaders ??= []).push(await this.structure.identifier(ids[index]));
8383
8422
  for (let index = 0; index < row.cells.length; index++) {
8384
8423
  const cell = row.cells[index];
8385
- if (!rowHeaders.length && cell.span === 1 && (cell.rowSpan ?? 1) === 1) {
8424
+ if (!rowHeaders && cell.span === 1 && (cell.rowSpan ?? 1) === 1) {
8386
8425
  const attributes = this.ordinaryAttributes[cell.first] ??=
8387
8426
  await this.structure.attributeReference(this.attributeDictionary(cell, this.associations(cell)));
8388
8427
  this.structure.setAttributes(ids[index], attributes);
8389
8428
  continue;
8390
8429
  }
8391
8430
  const associations = this.associations(cell);
8392
- if (!headers[index])
8431
+ const header = rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex;
8432
+ if (!header && rowHeaders)
8393
8433
  associations.push(...rowHeaders);
8394
- this.structure.setAttributes(ids[index], this.attributes(cell, associations, headers[index] ? "Row" : undefined));
8434
+ this.structure.setAttributes(ids[index], this.attributes(cell, associations, header ? "Row" : undefined));
8395
8435
  }
8396
8436
  return ids;
8397
8437
  }
@@ -8575,7 +8615,8 @@ class PdfPages {
8575
8615
  outlines;
8576
8616
  references = [];
8577
8617
  current = 0;
8578
- commands = [];
8618
+ commands = "";
8619
+ commandParts = [];
8579
8620
  commandBytes = 0;
8580
8621
  annotations = [];
8581
8622
  hyperlinks = 0;
@@ -8593,6 +8634,12 @@ class PdfPages {
8593
8634
  pendingBookmarks = [];
8594
8635
  pageNumberWidth = 0;
8595
8636
  colors = new Map();
8637
+ textFont;
8638
+ textSize = 0;
8639
+ textColor = "";
8640
+ textPrefix = "";
8641
+ rectangleLefts;
8642
+ rectangleColumns = [];
8596
8643
  externalObjects = new Map();
8597
8644
  bandFlow;
8598
8645
  bandCellBudget = false;
@@ -8659,7 +8706,7 @@ class PdfPages {
8659
8706
  }
8660
8707
  add(command) {
8661
8708
  this.retainPageBytes(command.length);
8662
- this.commands.push(command);
8709
+ this.commands += command;
8663
8710
  }
8664
8711
  retainPageBytes(length) {
8665
8712
  this.commandBytes += length;
@@ -8679,9 +8726,17 @@ class PdfPages {
8679
8726
  return this.structure ? "/Artifact << /Type /" + type + " >> BDC\n" + command + "EMC\n" : command;
8680
8727
  }
8681
8728
  text(text, font, size, x, baseline, foreground = "111827", element) {
8682
- const n = pdfNumber, shear = font.syntheticItalic ? .213 : 0;
8683
- const command = "q " + this.rgb(foreground) + " rg " + this.rgb(foreground) + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
8684
- (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";
8729
+ const n = pdfNumber;
8730
+ if (font !== this.textFont || size !== this.textSize || foreground !== this.textColor) {
8731
+ const shear = font.syntheticItalic ? .213 : 0, rgb = this.rgb(foreground);
8732
+ // Keep one prefix, independent of report size. Resource identity includes synthetic styling.
8733
+ this.textPrefix = "q " + rgb + " rg " + rgb + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
8734
+ (font.syntheticBold ? n(size * .025) + " w 2 Tr " : "0 Tr ") + "1 0 " + n(shear) + " 1 ";
8735
+ this.textFont = font;
8736
+ this.textSize = size;
8737
+ this.textColor = foreground;
8738
+ }
8739
+ const command = this.textPrefix + n(x) + " " + n(baseline) + " Tm " + font.encode(text) + " Tj ET Q\n";
8685
8740
  this.add(this.structure && element !== undefined ? this.structure.mark(element) + command + "EMC\n" : this.artifact(command, "Pagination"));
8686
8741
  }
8687
8742
  link(link, x, bottom, width, height, element) {
@@ -8711,8 +8766,8 @@ class PdfPages {
8711
8766
  for (const segment of line.segments) {
8712
8767
  const registered = marks?.get(segment), owner = registered?.owner ?? (segment.link && this.structure && element !== undefined ? this.structure.link(element, segment.link) : element);
8713
8768
  if (segment.glyphs) {
8714
- const font = segment.font, n = pdfNumber, shear = font.syntheticItalic ? .213 : 0;
8715
- let cursor = x, command = "q " + this.rgb(segment.color ?? "111827") + " rg " + this.rgb(segment.color ?? "111827") + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
8769
+ const font = segment.font, n = pdfNumber, shear = font.syntheticItalic ? .213 : 0, rgb = this.rgb(segment.color ?? "111827");
8770
+ let cursor = x, command = "q " + rgb + " rg " + rgb + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
8716
8771
  (font.syntheticBold ? n(size * .025) + " w 2 Tr " : "0 Tr ");
8717
8772
  for (const glyph of segment.glyphs) {
8718
8773
  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";
@@ -8760,7 +8815,8 @@ class PdfPages {
8760
8815
  this.current = this.objects.reserve();
8761
8816
  this.references.push(this.current);
8762
8817
  }
8763
- this.commands = [];
8818
+ this.commands = "";
8819
+ this.commandParts = [];
8764
8820
  this.annotations = [];
8765
8821
  this.commandBytes = 0;
8766
8822
  this.bodyAdded = false;
@@ -8843,15 +8899,32 @@ class PdfPages {
8843
8899
  if (!this.layout)
8844
8900
  throw new Error("A table layout is required before drawing rows.");
8845
8901
  this.bodyAdded = true;
8846
- const { padding, fontSize } = this.settings, n = pdfNumber, height = lineCount * row.lineHeight + padding * 2;
8902
+ const { padding, fontSize } = this.settings, n = pdfNumber, height = lineCount * row.lineHeight + padding * 2, lefts = this.layout.lefts;
8903
+ // One geometry token per active physical column; table/band changes release the old tokens.
8904
+ if (this.rectangleLefts !== lefts) {
8905
+ this.rectangleLefts = lefts;
8906
+ this.rectangleColumns = [];
8907
+ }
8908
+ let rectangleHeight, rectangleBottom = "", rectangleHeightText = "";
8847
8909
  for (const [index, cell] of row.cells.entries()) {
8848
8910
  if (this.bandCellBudget)
8849
8911
  this.settings.budget.cell(this.settings.budget.limits.maxTextCharacters === undefined ? "" :
8850
8912
  (cell.height === undefined ? cell.lines.slice(firstLine, firstLine + lineCount) : cell.lines).map(line => line.text).join(""));
8851
- const x = this.layout.lefts[cell.first], cellHeight = cell.height ?? height;
8913
+ const x = lefts[cell.first], cellHeight = cell.height ?? height;
8914
+ if (cellHeight !== rectangleHeight) {
8915
+ rectangleBottom = n(this.y - cellHeight);
8916
+ rectangleHeightText = n(cellHeight);
8917
+ rectangleHeight = cellHeight;
8918
+ }
8919
+ let horizontal = this.rectangleColumns[cell.first];
8920
+ if (!horizontal || horizontal.x !== x || horizontal.width !== cell.width) {
8921
+ horizontal = { x, width: cell.width, left: n(x), widthText: n(cell.width) };
8922
+ this.rectangleColumns[cell.first] = horizontal;
8923
+ }
8924
+ const rectangle = horizontal.left + " " + rectangleBottom + " " + horizontal.widthText + " " + rectangleHeightText;
8852
8925
  if (cell.style.background)
8853
- 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"));
8854
- 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"));
8926
+ this.add(this.artifact("q " + this.rgb(cell.style.background) + " rg " + rectangle + " re f Q\n"));
8927
+ this.add(this.artifact("q 0.82 0.85 0.89 RG 0.4 w " + rectangle + " re S Q\n"));
8855
8928
  const element = elements?.[index], artifact = cell.semanticArtifact || repeated[index], owner = cell.link && this.structure && element !== undefined ? this.structure.link(element, cell.link) : element;
8856
8929
  for (let line = firstLine; line < Math.min(cell.lines.length, cell.height ? cell.lines.length : firstLine + lineCount); line++) {
8857
8930
  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;
@@ -8861,6 +8934,7 @@ class PdfPages {
8861
8934
  this.link(cell.link, x, this.y - cellHeight, cell.width, cellHeight, owner);
8862
8935
  }
8863
8936
  this.y -= row.structured ? row.height : height;
8937
+ this.sealCommands();
8864
8938
  }
8865
8939
  async block(rows) {
8866
8940
  if (this.bandFlow)
@@ -9186,9 +9260,22 @@ class PdfPages {
9186
9260
  marker: { line: item.marker, gap: item.markerGap, ...(label === undefined ? {} : { owner: label }) } });
9187
9261
  await this.structure?.complete(li);
9188
9262
  }
9263
+ sealCommands() {
9264
+ if (this.commands) {
9265
+ this.commandParts.push(this.commands);
9266
+ this.commands = "";
9267
+ }
9268
+ }
9269
+ takeCommands() {
9270
+ this.sealCommands();
9271
+ const content = this.commandParts.join("");
9272
+ // Encoding and awaited delivery own the page value; the next page starts independently.
9273
+ this.commandParts = [];
9274
+ return content;
9275
+ }
9189
9276
  async finishPage() {
9190
9277
  const contents = this.objects.reserve(), { page, options } = this.settings;
9191
- await this.objects.stream(contents, this.commands.join(""), "", options.compression !== false);
9278
+ await this.objects.stream(contents, this.takeCommands(), "", options.compression !== false);
9192
9279
  const annotations = [];
9193
9280
  for (const annotation of this.annotations) {
9194
9281
  annotations.push(annotation.id);
@@ -9200,7 +9287,6 @@ class PdfPages {
9200
9287
  (annotations.length ? " /Annots [" + annotations.map(id => id + " 0 R").join(" ") + "]" : "") + " >>");
9201
9288
  if (this.structure)
9202
9289
  await this.structure.finishPage();
9203
- this.commands = [];
9204
9290
  this.annotations = [];
9205
9291
  this.commandBytes = 0;
9206
9292
  this.current = 0;