@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
@@ -2352,7 +2352,7 @@ _modules.set("59911f0fe023545e9e97521b268551078bdc4c5f303e446a13b7d52f905e8070",
2352
2352
  return _exports;
2353
2353
  })();
2354
2354
 
2355
- const _m21 = _modules.get("7da602b40c346a3838e75963f9a3f10c95ac5ce08a7b0a23b9d96f8898a01db7") ?? (() => {
2355
+ const _m21 = _modules.get("4d4736e6b8e2aaecc6f6c1b124b7e6bc0a5e141dcc725edf0ad4847d87fca1b3") ?? (() => {
2356
2356
  const { NotSupportedError, OfficeIMOError } = _m4;
2357
2357
 
2358
2358
  const { fontProgram } = _m22;
@@ -2363,7 +2363,8 @@ const { pdfNumber, unicodeHex } = _m19;
2363
2363
 
2364
2364
  const { checkAbort, pause, taskYieldDue } = _m3;
2365
2365
 
2366
- const standardHexBytes = Object.freeze(Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, "0")));
2366
+ const hexBytes = Object.freeze(Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, "0")));
2367
+ function cidHex(cid) { return hexBytes[cid >>> 8] + hexBytes[cid & 255]; }
2367
2368
  class PdfFontResource {
2368
2369
  index;
2369
2370
  bold;
@@ -2394,12 +2395,16 @@ class PdfFontResource {
2394
2395
  width(scalar) {
2395
2396
  if (this.shared)
2396
2397
  return this.shared.width(scalar);
2397
- const existing = this.mappings.get(scalar);
2398
- if (existing)
2399
- return existing.width;
2400
- const standard = this.standardWidths.get(scalar);
2401
- if (standard !== undefined)
2402
- return standard;
2398
+ if (this.program) {
2399
+ const existing = this.mappings.get(scalar);
2400
+ if (existing)
2401
+ return existing.width;
2402
+ }
2403
+ else {
2404
+ const standard = this.standardWidths.get(scalar);
2405
+ if (standard !== undefined)
2406
+ return standard;
2407
+ }
2403
2408
  const resolved = resolveScalar(scalar, this.program, this.bold);
2404
2409
  if (!resolved.supported) {
2405
2410
  if (resolved.code === "unpaired-surrogate")
@@ -2412,7 +2417,8 @@ class PdfFontResource {
2412
2417
  }
2413
2418
  if (this.mappings.size >= 65535)
2414
2419
  throw new OfficeIMOError("RESOURCE_LIMIT", "A PDF font supports at most 65,535 distinct Unicode scalars.");
2415
- const mapping = { cid: this.mappings.size + 1, glyph: resolved.glyph, width: resolved.width, text: String.fromCodePoint(scalar) };
2420
+ const cid = this.mappings.size + 1;
2421
+ const mapping = { cid, hex: cidHex(cid), glyph: resolved.glyph, width: resolved.width, text: String.fromCodePoint(scalar) };
2416
2422
  this.mappings.set(scalar, mapping);
2417
2423
  return mapping.width;
2418
2424
  }
@@ -2425,8 +2431,20 @@ class PdfFontResource {
2425
2431
  let hex = "";
2426
2432
  for (const char of text) {
2427
2433
  const cp = char.codePointAt(0);
2428
- this.width(cp);
2429
- hex += this.program ? this.mappings.get(cp).cid.toString(16).padStart(4, "0") : standardHexBytes[standardCode(cp)];
2434
+ if (this.program) {
2435
+ let mapping = this.mappings.get(cp);
2436
+ // Layout normally registered the scalar already; validate only a newly painted scalar.
2437
+ if (!mapping) {
2438
+ this.width(cp);
2439
+ mapping = this.mappings.get(cp);
2440
+ }
2441
+ hex += mapping.hex;
2442
+ }
2443
+ else {
2444
+ if (!this.standardWidths.has(cp))
2445
+ this.width(cp);
2446
+ hex += hexBytes[standardCode(cp)];
2447
+ }
2430
2448
  }
2431
2449
  return "<" + hex + ">";
2432
2450
  }
@@ -2441,10 +2459,11 @@ class PdfFontResource {
2441
2459
  if (!mapping) {
2442
2460
  if (this.mappings.size >= 65535)
2443
2461
  throw new OfficeIMOError("RESOURCE_LIMIT", "A PDF font supports at most 65,535 distinct CID mappings.");
2444
- mapping = { cid: this.mappings.size + 1, glyph, width: this.program.widths[glyph], text };
2462
+ const cid = this.mappings.size + 1;
2463
+ mapping = { cid, hex: cidHex(cid), glyph, width: this.program.widths[glyph], text };
2445
2464
  this.mappings.set(key, mapping);
2446
2465
  }
2447
- return "<" + mapping.cid.toString(16).padStart(4, "0") + ">";
2466
+ return "<" + mapping.hex + ">";
2448
2467
  }
2449
2468
  async write(objects, compression) {
2450
2469
  checkAbort(this.signal);
@@ -2493,7 +2512,7 @@ class PdfFontResource {
2493
2512
  const batch = mapped.slice(i, i + 100);
2494
2513
  cmap += batch.length + " beginbfchar\n";
2495
2514
  for (const [, m] of batch)
2496
- cmap += "<" + m.cid.toString(16).padStart(4, "0") + "> <" + unicodeHex(m.text) + ">\n";
2515
+ cmap += "<" + m.hex + "> <" + unicodeHex(m.text) + ">\n";
2497
2516
  cmap += "endbfchar\n";
2498
2517
  if (taskYieldDue())
2499
2518
  await pause();
@@ -2544,7 +2563,7 @@ class PdfFontResources {
2544
2563
  if (!found)
2545
2564
  this.explicitSelections.set(explicit, selections);
2546
2565
  }
2547
- const key = String(bold) + String(italic), existing = selections.get(key);
2566
+ const key = (bold ? 2 : 0) | (italic ? 1 : 0), existing = selections.get(key);
2548
2567
  if (existing)
2549
2568
  return existing;
2550
2569
  const { font, syntheticBold, syntheticItalic } = explicit ? { font: explicit, syntheticBold: bold, syntheticItalic: italic } : selectFont(this.fonts, bold, italic);
@@ -2561,7 +2580,7 @@ class PdfFontResources {
2561
2580
  dictionary() { return "<< " + this.resources.map(f => "/" + f.name + " " + f.object + " 0 R").join(" ") + " >>"; }
2562
2581
  }
2563
2582
  const _exports = Object.freeze({ PdfFontResource: PdfFontResource, PdfFontResources: PdfFontResources });
2564
- _modules.set("7da602b40c346a3838e75963f9a3f10c95ac5ce08a7b0a23b9d96f8898a01db7", _exports);
2583
+ _modules.set("4d4736e6b8e2aaecc6f6c1b124b7e6bc0a5e141dcc725edf0ad4847d87fca1b3", _exports);
2565
2584
  return _exports;
2566
2585
  })();
2567
2586
 
@@ -3134,7 +3153,7 @@ _modules.set("0a1c79b51ac9a164b86197239117df6497f45ca2892b423b1ec77a663ccc1c47",
3134
3153
  return _exports;
3135
3154
  })();
3136
3155
 
3137
- const _m33 = _modules.get("9a88773878eacc51df9f05bb5ee90cc2b683b083ebea8fb54375092301388e96") ?? (() => {
3156
+ const _m33 = _modules.get("2f40af05ba09102fe440c1d46385b64cecdd233371771796c9ae4e8d523f2cea") ?? (() => {
3138
3157
  const { OfficeIMOError } = _m4;
3139
3158
 
3140
3159
  const { wrapPdfText } = _m31;
@@ -3182,6 +3201,14 @@ async function projectBandRows(rows, band, widths, settings, fonts) {
3182
3201
  for (const row of rows) {
3183
3202
  const cells = [];
3184
3203
  for (const cell of row.cells) {
3204
+ // Ordinary data and leaf headings keep their captured width and lines in every band.
3205
+ // Look up their physical position without allocating another per-row column index.
3206
+ if (cell.span === 1) {
3207
+ const first = band.columns.indexOf(cell.first);
3208
+ if (first >= 0)
3209
+ cells.push({ ...cell, source: cell.source ?? cell, first });
3210
+ continue;
3211
+ }
3185
3212
  for (let first = 0; first < band.columns.length;) {
3186
3213
  const source = band.columns[first];
3187
3214
  if (source < cell.first || source >= cell.first + cell.span) {
@@ -3192,7 +3219,7 @@ async function projectBandRows(rows, band, widths, settings, fonts) {
3192
3219
  while (end < band.columns.length && band.columns[end] === band.columns[end - 1] + 1 && band.columns[end] < cell.first + cell.span)
3193
3220
  end++;
3194
3221
  const width = band.columns.slice(first, end).reduce((sum, index) => sum + widths[index], 0);
3195
- const lines = cell.span === 1 ? cell.lines : await wrapPdfText(cell.captured, fonts, settings.fontSize, width - settings.padding * 2, settings, cell.style.wrapText !== false);
3222
+ const lines = await wrapPdfText(cell.captured, fonts, settings.fontSize, width - settings.padding * 2, settings, cell.style.wrapText !== false);
3196
3223
  cells.push({ ...cell, source: cell.source ?? cell, first, span: end - first, width, lines,
3197
3224
  lineHeight: lines.reduce((height, line) => Math.max(height, line.lineHeight), cell.font.lineHeight(settings.fontSize)) });
3198
3225
  first = end;
@@ -3221,11 +3248,11 @@ function alignBandBlocks(bands, settings) {
3221
3248
  cells: row.cells.map(cell => ({ ...cell, height: heights.slice(index, index + (cell.rowSpan ?? 1)).reduce((sum, value) => sum + value, 0) })) })));
3222
3249
  }
3223
3250
  const _exports = Object.freeze({ planTableBands: planTableBands, projectBandRows: projectBandRows, alignBandBlocks: alignBandBlocks });
3224
- _modules.set("9a88773878eacc51df9f05bb5ee90cc2b683b083ebea8fb54375092301388e96", _exports);
3251
+ _modules.set("2f40af05ba09102fe440c1d46385b64cecdd233371771796c9ae4e8d523f2cea", _exports);
3225
3252
  return _exports;
3226
3253
  })();
3227
3254
 
3228
- const _m28 = _modules.get("07d2da8d8b93f12f172a48b97c1807e485555cf608e2eaa5b7610aa91d4a5305") ?? (() => {
3255
+ const _m28 = _modules.get("ad81357e627d3100e1068a8ce521aa1c1cd65de5c6c6ab36f807a3e5da50d874") ?? (() => {
3229
3256
  const { ExportCell } = _m7;
3230
3257
 
3231
3258
  const { copyExportLink } = _m9;
@@ -3345,8 +3372,12 @@ class PdfTableLayout {
3345
3372
  lines };
3346
3373
  }
3347
3374
  row(cells) {
3348
- const lines = Math.max(1, ...cells.map(c => c.lines.length));
3349
- const lineHeight = Math.max(this.lineHeight, ...cells.map(c => c.lineHeight));
3375
+ let lines = 1, lineHeight = this.lineHeight;
3376
+ for (let index = 0; index < cells.length; index++) {
3377
+ const cell = cells[index];
3378
+ lines = Math.max(lines, cell.lines.length);
3379
+ lineHeight = Math.max(lineHeight, cell.lineHeight);
3380
+ }
3350
3381
  return { cells, lines, lineHeight, height: lines * lineHeight + this.settings.padding * 2 };
3351
3382
  }
3352
3383
  async headers() {
@@ -3452,11 +3483,11 @@ class PdfTableLayout {
3452
3483
  }
3453
3484
  }
3454
3485
  const _exports = Object.freeze({ PdfTableLayout: PdfTableLayout });
3455
- _modules.set("07d2da8d8b93f12f172a48b97c1807e485555cf608e2eaa5b7610aa91d4a5305", _exports);
3486
+ _modules.set("ad81357e627d3100e1068a8ce521aa1c1cd65de5c6c6ab36f807a3e5da50d874", _exports);
3456
3487
  return _exports;
3457
3488
  })();
3458
3489
 
3459
- const _m35 = _modules.get("67ad5f4adbd6bc0dddafe5cf82638d46d150237f4ff0bee15c0ace652d5095f4") ?? (() => {
3490
+ const _m35 = _modules.get("9ea74d93c18250e809a7be745444b886bcd5ec924a78e6ab004d649789db1f72") ?? (() => {
3460
3491
  const { OfficeIMOError } = _m4;
3461
3492
 
3462
3493
  const { checkAbort } = _m3;
@@ -3500,7 +3531,7 @@ class PdfTableBandFlow {
3500
3531
  await this.flush();
3501
3532
  }
3502
3533
  async row(row, allowFirstFragment = false) {
3503
- const { padding, fontSize, options } = this.layout.settings, minimumLines = this.layout.minimumRowLines(row), minimumHeight = this.layout.minimumRowHeight(row);
3534
+ const { padding, fontSize, options } = this.layout.settings, minimumLines = this.layout.minimumRowLines(row), minimumHeight = minimumLines * row.lineHeight + padding * 2;
3504
3535
  if (minimumHeight > this.painter.firstFullCapacity + .001 || minimumHeight > this.painter.continuationCapacity + .001)
3505
3536
  throw new RangeError("Repeated PDF identifiers must fit intact below the first and continued band headings/context.");
3506
3537
  // Keep ordinary rows intact when they fit fresh. A kept heading/caption can deliberately
@@ -3534,9 +3565,14 @@ class PdfTableBandFlow {
3534
3565
  let remaining = false;
3535
3566
  const cells = rows[0].cells.map(cell => {
3536
3567
  const source = this.layout.bands[index].columns[cell.first];
3537
- const repeated = this.layout.repeatedColumn(source), visible = repeated ? cell.lines : cell.lines.slice(first, first + lines);
3568
+ const repeated = this.layout.repeatedColumn(source), reusable = cell.span === 1 && (cell.source?.span ?? 1) === 1 && (cell.rowSpan ?? 1) === 1 &&
3569
+ cell.height === undefined && first === 0 && (repeated || lines >= cell.lines.length);
3570
+ const visible = repeated || reusable ? cell.lines : cell.lines.slice(first, first + lines);
3538
3571
  if (!repeated && (visible.length > 0 || cell.link !== undefined))
3539
3572
  remaining = true;
3573
+ // A complete first fragment already owns these lines and their maximum font metrics.
3574
+ if (reusable)
3575
+ return cell;
3540
3576
  const { height: _height, ...plain } = cell;
3541
3577
  return { ...plain, lines: visible,
3542
3578
  lineHeight: visible.reduce((value, line) => Math.max(value, line.lineHeight), cell.font.lineHeight(fontSize)),
@@ -3589,11 +3625,11 @@ class PdfTableBandFlow {
3589
3625
  }
3590
3626
  }
3591
3627
  const _exports = Object.freeze({ PdfTableBandFlow: PdfTableBandFlow });
3592
- _modules.set("67ad5f4adbd6bc0dddafe5cf82638d46d150237f4ff0bee15c0ace652d5095f4", _exports);
3628
+ _modules.set("9ea74d93c18250e809a7be745444b886bcd5ec924a78e6ab004d649789db1f72", _exports);
3593
3629
  return _exports;
3594
3630
  })();
3595
3631
 
3596
- const _m36 = _modules.get("b52424ed74721dce3a2621456888fe1c6af0490627063e56f690df9abcb1dfff") ?? (() => {
3632
+ const _m36 = _modules.get("9deed79565a5da5009f7a01579df8d6a3f019b78eb7b17d831c7964840e9a6bf") ?? (() => {
3597
3633
  /** @internal Source-cell identities survive page fragments and horizontal band projections.
3598
3634
  * Only column headers and still-owned row objects remain reachable from this table owner. */
3599
3635
  class PdfTableStructure {
@@ -3645,30 +3681,31 @@ class PdfTableStructure {
3645
3681
  return row.cells.map(cell => this.cells.get(cell));
3646
3682
  const rowId = this.structure.element("TR", parent);
3647
3683
  this.rows.set(row, rowId);
3648
- const headers = row.cells.map((cell, index) => rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex);
3649
3684
  // Allocate in source order, then resolve every row header before associating even earlier data cells.
3650
3685
  // Generated summary labels override detail roles so numeric subtotal cells never become row headers.
3651
3686
  const ids = row.cells.map((cell, index) => {
3652
- const id = this.structure.element(headers[index] ? "TH" : "TD", rowId);
3687
+ const header = rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex;
3688
+ const id = this.structure.element(header ? "TH" : "TD", rowId);
3653
3689
  this.cells.set(cell, id);
3654
3690
  return id;
3655
3691
  });
3656
- const rowHeaders = [];
3692
+ let rowHeaders;
3657
3693
  for (let index = 0; index < ids.length; index++)
3658
- if (headers[index])
3659
- rowHeaders.push(await this.structure.identifier(ids[index]));
3694
+ if (rowHeaderIndex === undefined ? row.cells[index].rowHeader === true : index === rowHeaderIndex)
3695
+ (rowHeaders ??= []).push(await this.structure.identifier(ids[index]));
3660
3696
  for (let index = 0; index < row.cells.length; index++) {
3661
3697
  const cell = row.cells[index];
3662
- if (!rowHeaders.length && cell.span === 1 && (cell.rowSpan ?? 1) === 1) {
3698
+ if (!rowHeaders && cell.span === 1 && (cell.rowSpan ?? 1) === 1) {
3663
3699
  const attributes = this.ordinaryAttributes[cell.first] ??=
3664
3700
  await this.structure.attributeReference(this.attributeDictionary(cell, this.associations(cell)));
3665
3701
  this.structure.setAttributes(ids[index], attributes);
3666
3702
  continue;
3667
3703
  }
3668
3704
  const associations = this.associations(cell);
3669
- if (!headers[index])
3705
+ const header = rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex;
3706
+ if (!header && rowHeaders)
3670
3707
  associations.push(...rowHeaders);
3671
- this.structure.setAttributes(ids[index], this.attributes(cell, associations, headers[index] ? "Row" : undefined));
3708
+ this.structure.setAttributes(ids[index], this.attributes(cell, associations, header ? "Row" : undefined));
3672
3709
  }
3673
3710
  return ids;
3674
3711
  }
@@ -3703,7 +3740,7 @@ class PdfTableStructure {
3703
3740
  }
3704
3741
  }
3705
3742
  const _exports = Object.freeze({ PdfTableStructure: PdfTableStructure });
3706
- _modules.set("b52424ed74721dce3a2621456888fe1c6af0490627063e56f690df9abcb1dfff", _exports);
3743
+ _modules.set("9deed79565a5da5009f7a01579df8d6a3f019b78eb7b17d831c7964840e9a6bf", _exports);
3707
3744
  return _exports;
3708
3745
  })();
3709
3746
 
@@ -3821,7 +3858,7 @@ _modules.set("a66257a32f03d958aa57be4de9da7f80b708cebca26b5cc6404de0ee11bfe052",
3821
3858
  return _exports;
3822
3859
  })();
3823
3860
 
3824
- const _m34 = _modules.get("a7fca40cb8c75af206111c90db36839b4648982beeb4179efda0ddd1ee366210") ?? (() => {
3861
+ const _m34 = _modules.get("3ed7114181be5a3066742336da574fef7f2fc04ee6dfc5e64211f3bedad4cab9") ?? (() => {
3825
3862
  const { OfficeIMOError } = _m4;
3826
3863
 
3827
3864
  const { checkAbort } = _m3;
@@ -3856,7 +3893,8 @@ class PdfPages {
3856
3893
  outlines;
3857
3894
  references = [];
3858
3895
  current = 0;
3859
- commands = [];
3896
+ commands = "";
3897
+ commandParts = [];
3860
3898
  commandBytes = 0;
3861
3899
  annotations = [];
3862
3900
  hyperlinks = 0;
@@ -3874,6 +3912,12 @@ class PdfPages {
3874
3912
  pendingBookmarks = [];
3875
3913
  pageNumberWidth = 0;
3876
3914
  colors = new Map();
3915
+ textFont;
3916
+ textSize = 0;
3917
+ textColor = "";
3918
+ textPrefix = "";
3919
+ rectangleLefts;
3920
+ rectangleColumns = [];
3877
3921
  externalObjects = new Map();
3878
3922
  bandFlow;
3879
3923
  bandCellBudget = false;
@@ -3940,7 +3984,7 @@ class PdfPages {
3940
3984
  }
3941
3985
  add(command) {
3942
3986
  this.retainPageBytes(command.length);
3943
- this.commands.push(command);
3987
+ this.commands += command;
3944
3988
  }
3945
3989
  retainPageBytes(length) {
3946
3990
  this.commandBytes += length;
@@ -3960,9 +4004,17 @@ class PdfPages {
3960
4004
  return this.structure ? "/Artifact << /Type /" + type + " >> BDC\n" + command + "EMC\n" : command;
3961
4005
  }
3962
4006
  text(text, font, size, x, baseline, foreground = "111827", element) {
3963
- const n = pdfNumber, shear = font.syntheticItalic ? .213 : 0;
3964
- const command = "q " + this.rgb(foreground) + " rg " + this.rgb(foreground) + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
3965
- (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";
4007
+ const n = pdfNumber;
4008
+ if (font !== this.textFont || size !== this.textSize || foreground !== this.textColor) {
4009
+ const shear = font.syntheticItalic ? .213 : 0, rgb = this.rgb(foreground);
4010
+ // Keep one prefix, independent of report size. Resource identity includes synthetic styling.
4011
+ this.textPrefix = "q " + rgb + " rg " + rgb + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
4012
+ (font.syntheticBold ? n(size * .025) + " w 2 Tr " : "0 Tr ") + "1 0 " + n(shear) + " 1 ";
4013
+ this.textFont = font;
4014
+ this.textSize = size;
4015
+ this.textColor = foreground;
4016
+ }
4017
+ const command = this.textPrefix + n(x) + " " + n(baseline) + " Tm " + font.encode(text) + " Tj ET Q\n";
3966
4018
  this.add(this.structure && element !== undefined ? this.structure.mark(element) + command + "EMC\n" : this.artifact(command, "Pagination"));
3967
4019
  }
3968
4020
  link(link, x, bottom, width, height, element) {
@@ -3992,8 +4044,8 @@ class PdfPages {
3992
4044
  for (const segment of line.segments) {
3993
4045
  const registered = marks?.get(segment), owner = registered?.owner ?? (segment.link && this.structure && element !== undefined ? this.structure.link(element, segment.link) : element);
3994
4046
  if (segment.glyphs) {
3995
- const font = segment.font, n = pdfNumber, shear = font.syntheticItalic ? .213 : 0;
3996
- let cursor = x, command = "q " + this.rgb(segment.color ?? "111827") + " rg " + this.rgb(segment.color ?? "111827") + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
4047
+ const font = segment.font, n = pdfNumber, shear = font.syntheticItalic ? .213 : 0, rgb = this.rgb(segment.color ?? "111827");
4048
+ let cursor = x, command = "q " + rgb + " rg " + rgb + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
3997
4049
  (font.syntheticBold ? n(size * .025) + " w 2 Tr " : "0 Tr ");
3998
4050
  for (const glyph of segment.glyphs) {
3999
4051
  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";
@@ -4041,7 +4093,8 @@ class PdfPages {
4041
4093
  this.current = this.objects.reserve();
4042
4094
  this.references.push(this.current);
4043
4095
  }
4044
- this.commands = [];
4096
+ this.commands = "";
4097
+ this.commandParts = [];
4045
4098
  this.annotations = [];
4046
4099
  this.commandBytes = 0;
4047
4100
  this.bodyAdded = false;
@@ -4124,15 +4177,32 @@ class PdfPages {
4124
4177
  if (!this.layout)
4125
4178
  throw new Error("A table layout is required before drawing rows.");
4126
4179
  this.bodyAdded = true;
4127
- const { padding, fontSize } = this.settings, n = pdfNumber, height = lineCount * row.lineHeight + padding * 2;
4180
+ const { padding, fontSize } = this.settings, n = pdfNumber, height = lineCount * row.lineHeight + padding * 2, lefts = this.layout.lefts;
4181
+ // One geometry token per active physical column; table/band changes release the old tokens.
4182
+ if (this.rectangleLefts !== lefts) {
4183
+ this.rectangleLefts = lefts;
4184
+ this.rectangleColumns = [];
4185
+ }
4186
+ let rectangleHeight, rectangleBottom = "", rectangleHeightText = "";
4128
4187
  for (const [index, cell] of row.cells.entries()) {
4129
4188
  if (this.bandCellBudget)
4130
4189
  this.settings.budget.cell(this.settings.budget.limits.maxTextCharacters === undefined ? "" :
4131
4190
  (cell.height === undefined ? cell.lines.slice(firstLine, firstLine + lineCount) : cell.lines).map(line => line.text).join(""));
4132
- const x = this.layout.lefts[cell.first], cellHeight = cell.height ?? height;
4191
+ const x = lefts[cell.first], cellHeight = cell.height ?? height;
4192
+ if (cellHeight !== rectangleHeight) {
4193
+ rectangleBottom = n(this.y - cellHeight);
4194
+ rectangleHeightText = n(cellHeight);
4195
+ rectangleHeight = cellHeight;
4196
+ }
4197
+ let horizontal = this.rectangleColumns[cell.first];
4198
+ if (!horizontal || horizontal.x !== x || horizontal.width !== cell.width) {
4199
+ horizontal = { x, width: cell.width, left: n(x), widthText: n(cell.width) };
4200
+ this.rectangleColumns[cell.first] = horizontal;
4201
+ }
4202
+ const rectangle = horizontal.left + " " + rectangleBottom + " " + horizontal.widthText + " " + rectangleHeightText;
4133
4203
  if (cell.style.background)
4134
- 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"));
4135
- 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"));
4204
+ this.add(this.artifact("q " + this.rgb(cell.style.background) + " rg " + rectangle + " re f Q\n"));
4205
+ this.add(this.artifact("q 0.82 0.85 0.89 RG 0.4 w " + rectangle + " re S Q\n"));
4136
4206
  const element = elements?.[index], artifact = cell.semanticArtifact || repeated[index], owner = cell.link && this.structure && element !== undefined ? this.structure.link(element, cell.link) : element;
4137
4207
  for (let line = firstLine; line < Math.min(cell.lines.length, cell.height ? cell.lines.length : firstLine + lineCount); line++) {
4138
4208
  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;
@@ -4142,6 +4212,7 @@ class PdfPages {
4142
4212
  this.link(cell.link, x, this.y - cellHeight, cell.width, cellHeight, owner);
4143
4213
  }
4144
4214
  this.y -= row.structured ? row.height : height;
4215
+ this.sealCommands();
4145
4216
  }
4146
4217
  async block(rows) {
4147
4218
  if (this.bandFlow)
@@ -4467,9 +4538,22 @@ class PdfPages {
4467
4538
  marker: { line: item.marker, gap: item.markerGap, ...(label === undefined ? {} : { owner: label }) } });
4468
4539
  await this.structure?.complete(li);
4469
4540
  }
4541
+ sealCommands() {
4542
+ if (this.commands) {
4543
+ this.commandParts.push(this.commands);
4544
+ this.commands = "";
4545
+ }
4546
+ }
4547
+ takeCommands() {
4548
+ this.sealCommands();
4549
+ const content = this.commandParts.join("");
4550
+ // Encoding and awaited delivery own the page value; the next page starts independently.
4551
+ this.commandParts = [];
4552
+ return content;
4553
+ }
4470
4554
  async finishPage() {
4471
4555
  const contents = this.objects.reserve(), { page, options } = this.settings;
4472
- await this.objects.stream(contents, this.commands.join(""), "", options.compression !== false);
4556
+ await this.objects.stream(contents, this.takeCommands(), "", options.compression !== false);
4473
4557
  const annotations = [];
4474
4558
  for (const annotation of this.annotations) {
4475
4559
  annotations.push(annotation.id);
@@ -4481,7 +4565,6 @@ class PdfPages {
4481
4565
  (annotations.length ? " /Annots [" + annotations.map(id => id + " 0 R").join(" ") + "]" : "") + " >>");
4482
4566
  if (this.structure)
4483
4567
  await this.structure.finishPage();
4484
- this.commands = [];
4485
4568
  this.annotations = [];
4486
4569
  this.commandBytes = 0;
4487
4570
  this.current = 0;
@@ -4513,7 +4596,7 @@ class PdfPages {
4513
4596
  }
4514
4597
  }
4515
4598
  const _exports = Object.freeze({ PdfPages: PdfPages });
4516
- _modules.set("a7fca40cb8c75af206111c90db36839b4648982beeb4179efda0ddd1ee366210", _exports);
4599
+ _modules.set("3ed7114181be5a3066742336da574fef7f2fc04ee6dfc5e64211f3bedad4cab9", _exports);
4517
4600
  return _exports;
4518
4601
  })();
4519
4602
 
@@ -4956,7 +5039,7 @@ _modules.set("52c78ca6833cee7e5a96b657e2c00172d550176daf2c95e742692f8416977bea",
4956
5039
  return _exports;
4957
5040
  })();
4958
5041
 
4959
- const _m18 = _modules.get("eb2c981b4568b33deca2137956ace31ea621b6a6287755ec234336d0a7c23cfc") ?? (() => {
5042
+ const _m18 = _modules.get("afdad27eb363e8de0c3bd69ebf358860eb76f5c6fb29f43a87635807cb7fc273") ?? (() => {
4960
5043
  const { PdfObjects, unicodeHex } = _m19;
4961
5044
 
4962
5045
  const { PdfFontResources } = _m21;
@@ -5019,11 +5102,11 @@ class PdfWriteSession {
5019
5102
  }
5020
5103
  }
5021
5104
  const _exports = Object.freeze({ PdfWriteSession: PdfWriteSession });
5022
- _modules.set("eb2c981b4568b33deca2137956ace31ea621b6a6287755ec234336d0a7c23cfc", _exports);
5105
+ _modules.set("afdad27eb363e8de0c3bd69ebf358860eb76f5c6fb29f43a87635807cb7fc273", _exports);
5023
5106
  return _exports;
5024
5107
  })();
5025
5108
 
5026
- const _m1 = _modules.get("98eb735e985f873ed0ffc628449a20d1f3bb729a87b6d6b3099b6f308438fcb5") ?? (() => {
5109
+ const _m1 = _modules.get("45cf9fd6b6293c1a83bc8554e1bcb5cf119f44701fbad7849f39a712cab5074b") ?? (() => {
5027
5110
  const { BlobByteSink, withDestination } = _m2;
5028
5111
 
5029
5112
  const { beginTask, checkAbort, consumeRows, pause, taskYieldDue } = _m3;
@@ -5088,7 +5171,7 @@ async function writePdfTo(rows, destination, configuration) {
5088
5171
  });
5089
5172
  }
5090
5173
  const _exports = Object.freeze({ writePdf: writePdf, writePdfTo: writePdfTo });
5091
- _modules.set("98eb735e985f873ed0ffc628449a20d1f3bb729a87b6d6b3099b6f308438fcb5", _exports);
5174
+ _modules.set("45cf9fd6b6293c1a83bc8554e1bcb5cf119f44701fbad7849f39a712cab5074b", _exports);
5092
5175
  return _exports;
5093
5176
  })();
5094
5177
 
@@ -6309,7 +6392,7 @@ _modules.set("d04686d2c067355dfd215333b83eb5f79f96e9e4be49f942e050f21ac0795343",
6309
6392
  return _exports;
6310
6393
  })();
6311
6394
 
6312
- const _m53 = _modules.get("d43e573fd5bad18a7ec2d71752168c422c4f8fabbc51f1cef8e3ba389f298715") ?? (() => {
6395
+ const _m53 = _modules.get("289fa3a052c7fbab2a3ca0fb91fb9974db709d24b7d850f1175810258f0409a0") ?? (() => {
6313
6396
  const { assertGroupedReportSource, groupedReportOperation } = _m44;
6314
6397
 
6315
6398
  const { consumeRows } = _m3;
@@ -6563,11 +6646,11 @@ async function renderGroupedPdfTable(block, context) {
6563
6646
  }
6564
6647
  }
6565
6648
  const _exports = Object.freeze({ renderGroupedPdfTable: renderGroupedPdfTable });
6566
- _modules.set("d43e573fd5bad18a7ec2d71752168c422c4f8fabbc51f1cef8e3ba389f298715", _exports);
6649
+ _modules.set("289fa3a052c7fbab2a3ca0fb91fb9974db709d24b7d850f1175810258f0409a0", _exports);
6567
6650
  return _exports;
6568
6651
  })();
6569
6652
 
6570
- const _m45 = _modules.get("f6c70e9a0bed09b5a1c61a662ad7d3faf731c911f574e2df285f669bd643b947") ?? (() => {
6653
+ const _m45 = _modules.get("9051bf9fc3168e24b53b16c123a42816198456846003fb49191c03a18cdab904") ?? (() => {
6571
6654
  const { BlobByteSink, withDestination } = _m2;
6572
6655
 
6573
6656
  const { OfficeIMOError } = _m4;
@@ -6857,11 +6940,11 @@ function captureTableOptions(options) {
6857
6940
  return { ...captured, ...(captured.wideTable === undefined ? {} : { wideTable: captureWideTable(captured.wideTable) }) };
6858
6941
  }
6859
6942
  const _exports = Object.freeze({ pdfTable: pdfTable, writePdfDocument: writePdfDocument, writePdfDocumentTo: writePdfDocumentTo });
6860
- _modules.set("f6c70e9a0bed09b5a1c61a662ad7d3faf731c911f574e2df285f669bd643b947", _exports);
6943
+ _modules.set("9051bf9fc3168e24b53b16c123a42816198456846003fb49191c03a18cdab904", _exports);
6861
6944
  return _exports;
6862
6945
  })();
6863
6946
 
6864
- const _m43 = _modules.get("879a0adeb3c62918085a071cbc37f221eb89a0fd73d56ebb5e9cfe0d49db8ee9") ?? (() => {
6947
+ const _m43 = _modules.get("abe76e52ffeed11ab42477c83ddde1d1d7de28b803096436b5b23cb153af58ba") ?? (() => {
6865
6948
  const { assertGroupedReportSource } = _m44;
6866
6949
 
6867
6950
  const { BlobByteSink } = _m2;
@@ -6907,7 +6990,7 @@ async function writeGroupedPdfTo(report, destination, configuration) {
6907
6990
  return writePdfDocumentTo([pdfGroupedTable(report, tableOptions)], destination, documentOptions);
6908
6991
  }
6909
6992
  const _exports = Object.freeze({ pdfGroupedTable: _m54.pdfGroupedTable, writeGroupedPdf: writeGroupedPdf, writeGroupedPdfTo: writeGroupedPdfTo });
6910
- _modules.set("879a0adeb3c62918085a071cbc37f221eb89a0fd73d56ebb5e9cfe0d49db8ee9", _exports);
6993
+ _modules.set("abe76e52ffeed11ab42477c83ddde1d1d7de28b803096436b5b23cb153af58ba", _exports);
6911
6994
  return _exports;
6912
6995
  })();
6913
6996
 
@@ -7000,10 +7083,10 @@ _modules.set("81b3d47c02b7d8443b79e02b3cfb52032d6b73d9a3fb592b777ebe028ad0ef00",
7000
7083
  return _exports;
7001
7084
  })();
7002
7085
 
7003
- const _m0 = _modules.get("2deab7b4ccb08bed297341ddb563d8fcf74277aff38c1dfc3d9edd61c0d98481") ?? (() => {
7086
+ const _m0 = _modules.get("027aafa08408056b10d7d717d63d1f7c0ee20ecfc68213aa66feacc75ec525fe") ?? (() => {
7004
7087
 
7005
7088
  const _exports = Object.freeze({ writePdf: _m1.writePdf, writePdfTo: _m1.writePdfTo, writeGroupedPdf: _m43.writeGroupedPdf, writeGroupedPdfTo: _m43.writeGroupedPdfTo, pdfGroupedTable: _m43.pdfGroupedTable, createGroupedReport: _m44.createGroupedReport, writePdfDocument: _m45.writePdfDocument, writePdfDocumentTo: _m45.writePdfDocumentTo, pdfTable: _m45.pdfTable, PdfFont: _m22.PdfFont, preflightPdfText: _m55.preflightPdfText, ExportCell: _m7.ExportCell, saveBlob: _m56.saveBlob });
7006
- _modules.set("2deab7b4ccb08bed297341ddb563d8fcf74277aff38c1dfc3d9edd61c0d98481", _exports);
7089
+ _modules.set("027aafa08408056b10d7d717d63d1f7c0ee20ecfc68213aa66feacc75ec525fe", _exports);
7007
7090
  return _exports;
7008
7091
  })();
7009
7092
  Object.assign(officeimo, _m0, { core: _m56, pdf: _m0 });