@evotecit/officeimo 0.1.0 → 0.1.2

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 (49) hide show
  1. package/README.md +13 -10
  2. package/bundles/officeimo-canopyx.js +842 -377
  3. package/bundles/officeimo-canopyx.mjs +729 -265
  4. package/bundles/officeimo-csv.js +29 -19
  5. package/bundles/officeimo-csv.mjs +17 -7
  6. package/bundles/officeimo-datatables.js +835 -379
  7. package/bundles/officeimo-datatables.mjs +723 -268
  8. package/bundles/officeimo-execution.js +35 -25
  9. package/bundles/officeimo-execution.mjs +17 -7
  10. package/bundles/officeimo-pdf.js +737 -291
  11. package/bundles/officeimo-pdf.mjs +688 -243
  12. package/bundles/officeimo-xlsx.js +114 -94
  13. package/bundles/officeimo-xlsx.mjs +48 -28
  14. package/bundles/officeimo.js +819 -363
  15. package/bundles/officeimo.mjs +709 -254
  16. package/dist/core/index.d.ts +2 -0
  17. package/dist/core/iteration.js +2 -2
  18. package/dist/core/sinks.js +2 -1
  19. package/dist/integrations/canopyx/source.js +13 -7
  20. package/dist/integrations/datatables/snapshot.js +3 -3
  21. package/dist/internal/rows.js +13 -4
  22. package/dist/opc/index.js +14 -9
  23. package/dist/pdf/document-grouped.js +72 -22
  24. package/dist/pdf/font-resources.js +2 -1
  25. package/dist/pdf/inline-text.js +50 -9
  26. package/dist/pdf/objects.js +188 -11
  27. package/dist/pdf/pages.js +28 -28
  28. package/dist/pdf/paragraph-layout.d.ts +2 -0
  29. package/dist/pdf/paragraph-layout.js +9 -4
  30. package/dist/pdf/session.js +1 -1
  31. package/dist/pdf/settings.d.ts +2 -0
  32. package/dist/pdf/settings.js +27 -2
  33. package/dist/pdf/structure.js +80 -28
  34. package/dist/pdf/table-band-flow.js +26 -11
  35. package/dist/pdf/table-band-plan.js +1 -3
  36. package/dist/pdf/table-layout.d.ts +4 -0
  37. package/dist/pdf/table-layout.js +22 -10
  38. package/dist/pdf/table-structure.js +28 -12
  39. package/dist/pdf/text.js +5 -0
  40. package/dist/pdf/types.d.ts +4 -2
  41. package/dist/pdf/xref.d.ts +1 -0
  42. package/dist/pdf/xref.js +30 -0
  43. package/dist/xlsx/values.js +3 -2
  44. package/dist/xlsx/workbook.js +7 -4
  45. package/dist/xlsx/worksheet.js +2 -1
  46. package/dist/xml/index.js +3 -3
  47. package/dist/zip/entry.js +1 -1
  48. package/dist/zip/index.js +1 -1
  49. package/package.json +1 -1
@@ -42,10 +42,10 @@ _modules.set("d5c945064d81fdd257960f48c421125e106e5f270427d170bb05587dd96a44ea",
42
42
  return _exports;
43
43
  })();
44
44
 
45
- const _m4 = _modules.get("1ae4f4554ececbf0fc1e5d32f40275e35f228dca922cfc0760ae681fd9690d7e") ?? (() => {
45
+ const _m4 = _modules.get("87c24efeaa0f1579c19afeeb4918caeb4f8f65a88d24a246e2cfd712b37dbac3") ?? (() => {
46
46
  function checkAbort(signal) {
47
47
  if (signal?.aborted)
48
- throw signal.reason ?? new DOMException("Export cancelled.", "AbortError");
48
+ throw signal.reason;
49
49
  }
50
50
  /** Race a pending producer or sink operation without leaving abort listeners behind. */
51
51
  function withAbort(promise, signal) {
@@ -53,7 +53,7 @@ function withAbort(promise, signal) {
53
53
  return Promise.resolve(promise);
54
54
  return new Promise((resolve, reject) => {
55
55
  const cleanup = () => signal.removeEventListener("abort", abort);
56
- const abort = () => { cleanup(); reject(signal.reason ?? new DOMException("Export cancelled.", "AbortError")); };
56
+ const abort = () => { cleanup(); reject(signal.reason); };
57
57
  signal.addEventListener("abort", abort, { once: true });
58
58
  Promise.resolve(promise).then(value => { cleanup(); resolve(value); }, error => { cleanup(); reject(error); });
59
59
  if (signal.aborted)
@@ -193,11 +193,11 @@ function pause() {
193
193
  });
194
194
  }
195
195
  const _exports = Object.freeze({ checkAbort: checkAbort, withAbort: withAbort, inputRows: inputRows, rowsFromBatches: rowsFromBatches, concatRows: concatRows, consumeRows: consumeRows, beginTask: beginTask, taskYieldDue: taskYieldDue, pause: pause });
196
- _modules.set("1ae4f4554ececbf0fc1e5d32f40275e35f228dca922cfc0760ae681fd9690d7e", _exports);
196
+ _modules.set("87c24efeaa0f1579c19afeeb4918caeb4f8f65a88d24a246e2cfd712b37dbac3", _exports);
197
197
  return _exports;
198
198
  })();
199
199
 
200
- const _m3 = _modules.get("0c4bd256ca66b488390b27a6d197e5ba99ae051ae662621b67a5e80b0479eefc") ?? (() => {
200
+ const _m3 = _modules.get("5337d1e3bd5ae0c1d10a476fcd31540d20337ccf7aa93c7e9e26c2b1a7dab92b") ?? (() => {
201
201
  const { checkAbort, consumeRows, withAbort, pause, taskYieldDue } = _m4;
202
202
 
203
203
  const { OfficeIMOError } = _m2;
@@ -207,8 +207,9 @@ async function withDestination(destination, operation) {
207
207
  // Native streams can belong to another browser realm; constructor identity is not portable.
208
208
  if (destination && typeof destination.getWriter === "function") {
209
209
  const writer = destination.getWriter();
210
+ // Native streams may retain accepted chunks after write resolves.
210
211
  try {
211
- return await operation({ write: bytes => writer.write(bytes) });
212
+ return await operation({ write: bytes => writer.write(new Uint8Array(bytes)) });
212
213
  }
213
214
  finally {
214
215
  writer.releaseLock();
@@ -302,7 +303,7 @@ async function writeBytes(source, sink, signal) {
302
303
  });
303
304
  }
304
305
  const _exports = Object.freeze({ withDestination: withDestination, BlobByteSink: BlobByteSink, ChunkedTextSink: ChunkedTextSink, writeBytes: writeBytes });
305
- _modules.set("0c4bd256ca66b488390b27a6d197e5ba99ae051ae662621b67a5e80b0479eefc", _exports);
306
+ _modules.set("5337d1e3bd5ae0c1d10a476fcd31540d20337ccf7aa93c7e9e26c2b1a7dab92b", _exports);
306
307
  return _exports;
307
308
  })();
308
309
 
@@ -499,7 +500,7 @@ _modules.set("42faf379960e5674a6fdfa8c8fca0bb68bbd74587231248d2524d7004def3671",
499
500
  return _exports;
500
501
  })();
501
502
 
502
- const _m11 = _modules.get("c15eede1e0b2a0a81c7153114bbb20e411413650f1c70c29bbda627241c59dbd") ?? (() => {
503
+ const _m11 = _modules.get("0391fe35ea7d02b25804ab4d0e7543136d6bb615f368f268c74aa135f23aa6bc") ?? (() => {
503
504
  const { assertExportValue } = _m5;
504
505
 
505
506
  const { checkAbort } = _m4;
@@ -512,11 +513,18 @@ function createRowProjector(columns, worksheet, signal, validate = assertExportV
512
513
  const getters = columns.some(column => column.value);
513
514
  return (row, rowIndex = 0) => {
514
515
  if (Array.isArray(row) && !getters) {
515
- if (row.length > columns.length)
516
+ const length = row.length;
517
+ if (length > columns.length)
516
518
  throw new RangeError("Row has more values than declared columns.");
517
- for (const value of row)
519
+ // Resolve each positional value once, just like key/value projections. Returning the
520
+ // source array would let an accessor change a value after the portable-value check.
521
+ const values = new Array(length);
522
+ for (let index = 0; index < length; index++) {
523
+ const value = row[index];
518
524
  validate(value);
519
- return row;
525
+ values[index] = value;
526
+ }
527
+ return values;
520
528
  }
521
529
  if (!row || typeof row !== "object" || isDate(row))
522
530
  throw new TypeError("A row must be an array or object.");
@@ -545,7 +553,7 @@ function createRowProjector(columns, worksheet, signal, validate = assertExportV
545
553
  };
546
554
  }
547
555
  /** @internal Shared metadata fields for full columns and adapter-owned partial overrides. */
548
- const columnOptionFields = ["header", "key", "value", "width", "type", "format", "wrapText", "alignment", "groups", "style", "valueFormatter"];
556
+ const columnOptionFields = ["header", "key", "value", "width", "type", "format", "wrapText", "alignment", "rowHeader", "groups", "style", "valueFormatter"];
549
557
  function copyColumns(columns, workbookStyles = false) {
550
558
  if (!Array.isArray(columns))
551
559
  throw new TypeError("Declare the columns in export order.");
@@ -561,6 +569,8 @@ function copyColumns(columns, workbookStyles = false) {
561
569
  throw new TypeError("Each column needs a string header and an optional string key.");
562
570
  if (captured.value !== undefined && typeof captured.value !== "function")
563
571
  throw new TypeError("Column value getters must be functions.");
572
+ if (captured.rowHeader !== undefined && typeof captured.rowHeader !== "boolean")
573
+ throw new TypeError("Column rowHeader must be boolean.");
564
574
  if (captured.groups !== undefined) {
565
575
  if (!Array.isArray(captured.groups))
566
576
  throw new TypeError("Column groups must be an array of strings.");
@@ -573,7 +583,7 @@ function copyColumns(columns, workbookStyles = false) {
573
583
  });
574
584
  }
575
585
  const _exports = Object.freeze({ createRowProjector: createRowProjector, columnOptionFields: columnOptionFields, copyColumns: copyColumns });
576
- _modules.set("c15eede1e0b2a0a81c7153114bbb20e411413650f1c70c29bbda627241c59dbd", _exports);
586
+ _modules.set("0391fe35ea7d02b25804ab4d0e7543136d6bb615f368f268c74aa135f23aa6bc", _exports);
577
587
  return _exports;
578
588
  })();
579
589
 
@@ -647,7 +657,7 @@ _modules.set("e95bb0e3f342d1379b67a3d541fa808e06361da8460169a6aec152ee7deb69b2",
647
657
  return _exports;
648
658
  })();
649
659
 
650
- const _m8 = _modules.get("18d120e0ba2b5d6d4a098d72a6f558dec1c936c1f1a0e4996c6d240a928c931e") ?? (() => {
660
+ const _m8 = _modules.get("046b305cdccf817d847addb75a778131622de23f2840830bbe1c0c26053a68c0") ?? (() => {
651
661
  const { ExportCell, assertScalar } = _m5;
652
662
 
653
663
  const { isDate } = _m6;
@@ -909,11 +919,11 @@ function createGroupedReport(rows, options) {
909
919
  return source;
910
920
  }
911
921
  const _exports = Object.freeze({ assertGroupedReportSource: assertGroupedReportSource, groupedReportEvents: groupedReportEvents, groupedReportOperation: groupedReportOperation, createGroupedReport: createGroupedReport });
912
- _modules.set("18d120e0ba2b5d6d4a098d72a6f558dec1c936c1f1a0e4996c6d240a928c931e", _exports);
922
+ _modules.set("046b305cdccf817d847addb75a778131622de23f2840830bbe1c0c26053a68c0", _exports);
913
923
  return _exports;
914
924
  })();
915
925
 
916
- const _m1 = _modules.get("4af46fa949e848316dc59f9073630c7949316a763a7c9a753335d276c580b8e6") ?? (() => {
926
+ const _m1 = _modules.get("81b3d47c02b7d8443b79e02b3cfb52032d6b73d9a3fb592b777ebe028ad0ef00") ?? (() => {
917
927
 
918
928
 
919
929
 
@@ -958,7 +968,7 @@ function saveBlob(blob, fileName) {
958
968
  }
959
969
  }
960
970
  const _exports = Object.freeze({ OfficeIMOError: _m2.OfficeIMOError, NotSupportedError: _m2.NotSupportedError, BlobByteSink: _m3.BlobByteSink, ChunkedTextSink: _m3.ChunkedTextSink, writeBytes: _m3.writeBytes, ExportCell: _m5.ExportCell, createGroupedReport: _m8.createGroupedReport, checkAbort: _m4.checkAbort, withAbort: _m4.withAbort, inputRows: _m4.inputRows, pause: _m4.pause, detectFeatures: detectFeatures, saveBlob: saveBlob });
961
- _modules.set("4af46fa949e848316dc59f9073630c7949316a763a7c9a753335d276c580b8e6", _exports);
971
+ _modules.set("81b3d47c02b7d8443b79e02b3cfb52032d6b73d9a3fb592b777ebe028ad0ef00", _exports);
962
972
  return _exports;
963
973
  })();
964
974
 
@@ -1100,7 +1110,7 @@ _modules.set("f0627ba89e5c8fcb376ebe3ce72dcc8d68c34952981f8703e36b8bb1a9894208",
1100
1110
  return _exports;
1101
1111
  })();
1102
1112
 
1103
- const _m15 = _modules.get("9c3d47f5bb21af4555c6ad7b10e216b7c957f2e71027f576989d75e7cf563d1d") ?? (() => {
1113
+ const _m15 = _modules.get("b6dbf755b495baef5c7d7651e6a55b2098f2ee304edca2c8b285a0bd7ec127a1") ?? (() => {
1104
1114
  const { beginTask, checkAbort, consumeRows, taskYieldDue, withAbort } = _m4;
1105
1115
 
1106
1116
  const { BlobByteSink, ChunkedTextSink, withDestination } = _m3;
@@ -1247,7 +1257,7 @@ async function writeCsv(rows, configuration) {
1247
1257
  }
1248
1258
  }
1249
1259
  const _exports = Object.freeze({ saveBlob: _m1.saveBlob, ExportCell: _m5.ExportCell, writeCsvTo: writeCsvTo, writeCsv: writeCsv });
1250
- _modules.set("9c3d47f5bb21af4555c6ad7b10e216b7c957f2e71027f576989d75e7cf563d1d", _exports);
1260
+ _modules.set("b6dbf755b495baef5c7d7651e6a55b2098f2ee304edca2c8b285a0bd7ec127a1", _exports);
1251
1261
  return _exports;
1252
1262
  })();
1253
1263
 
@@ -1299,12 +1309,14 @@ _modules.set("8ece66b561682170c879991995105163f4c484c8355d5e451fc6f52a9fbc3f82",
1299
1309
  return _exports;
1300
1310
  })();
1301
1311
 
1302
- const _m25 = _modules.get("47668dc33afddf93a09736e08c39f34d52518f2bf719e5ef386363758f42e4b7") ?? (() => {
1312
+ const _m25 = _modules.get("227236fd7adc9472e188831b8f16fdc69338c4d779f2b69a8abbd8dbfa95b585") ?? (() => {
1303
1313
  const { OfficeIMOError } = _m2;
1304
1314
 
1305
1315
  const { ChunkedTextSink } = _m3;
1306
1316
 
1307
1317
  const xmlDeclaration = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
1318
+ const xmlEscapes = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&apos;",
1319
+ "\r": "&#13;", "\n": "&#10;", "\t": "&#9;" };
1308
1320
  /** XML 1.0 characters; Unicode mode retains valid surrogate pairs. */
1309
1321
  function cleanXml(value, policy = "strip") {
1310
1322
  if (policy !== "strip" && policy !== "reject")
@@ -1316,9 +1328,7 @@ function cleanXml(value, policy = "strip") {
1316
1328
  }
1317
1329
  /** Escape data, including whitespace that XML parsers otherwise normalize. */
1318
1330
  function escapeXml(value, policy = "strip") {
1319
- const escapes = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&apos;",
1320
- "\r": "&#13;", "\n": "&#10;", "\t": "&#9;" };
1321
- return cleanXml(value, policy).replace(/[&<>"'\r\n\t]/g, c => escapes[c]);
1331
+ return cleanXml(value, policy).replace(/[&<>"'\r\n\t]/g, c => xmlEscapes[c]);
1322
1332
  }
1323
1333
  /** Encode an OOXML ST_Xstring attribute without interpreting literal escape tokens as characters. */
1324
1334
  function escapeOoxmlAttribute(value, policy = "strip") {
@@ -1377,11 +1387,11 @@ class XmlWriter {
1377
1387
  throw new OfficeIMOError("INVALID_STATE", "XML writer is closed."); }
1378
1388
  }
1379
1389
  const _exports = Object.freeze({ xmlDeclaration: xmlDeclaration, cleanXml: cleanXml, escapeXml: escapeXml, escapeOoxmlAttribute: escapeOoxmlAttribute, validateXmlName: validateXmlName, XmlWriter: XmlWriter });
1380
- _modules.set("47668dc33afddf93a09736e08c39f34d52518f2bf719e5ef386363758f42e4b7", _exports);
1390
+ _modules.set("227236fd7adc9472e188831b8f16fdc69338c4d779f2b69a8abbd8dbfa95b585", _exports);
1381
1391
  return _exports;
1382
1392
  })();
1383
1393
 
1384
- const _m24 = _modules.get("75f1dfdbbf7685a7bfd416b8d7d4b82698a1852f973cf0264456086cf8c20723") ?? (() => {
1394
+ const _m24 = _modules.get("56b2057461a668e8c90abd1fbf4f13ff93efd9854e590c82a195799f0f842c2a") ?? (() => {
1385
1395
  const { escapeXml, xmlDeclaration } = _m25;
1386
1396
 
1387
1397
  const { isDate } = _m6;
@@ -1403,7 +1413,7 @@ function appPropertiesXml(properties = {}, policy = "strip") {
1403
1413
  '<Application>' + escapeXml(properties.application ?? "OfficeIMO", policy) + '</Application><Company>' + escapeXml(properties.company ?? "", policy) + '</Company></Properties>';
1404
1414
  }
1405
1415
  const _exports = Object.freeze({ corePropertiesXml: corePropertiesXml, appPropertiesXml: appPropertiesXml });
1406
- _modules.set("75f1dfdbbf7685a7bfd416b8d7d4b82698a1852f973cf0264456086cf8c20723", _exports);
1416
+ _modules.set("56b2057461a668e8c90abd1fbf4f13ff93efd9854e590c82a195799f0f842c2a", _exports);
1407
1417
  return _exports;
1408
1418
  })();
1409
1419
 
@@ -1430,7 +1440,7 @@ _modules.set("790c15edc51b308be3e7d8222630d407f8c79c31ab21ba0b9f92c00f44ab4021",
1430
1440
  return _exports;
1431
1441
  })();
1432
1442
 
1433
- const _m27 = _modules.get("34b448ff5052fe659ccb250d80fc2a0b13ab82890f50132ef5c9e51da369a582") ?? (() => {
1443
+ const _m27 = _modules.get("597d152d20a2a28ee5cd6d4243a79a71ce8b83769a77441bfc944aadc0a6efbd") ?? (() => {
1434
1444
  const { checkAbort, withAbort } = _m4;
1435
1445
 
1436
1446
  const { OfficeIMOError } = _m2;
@@ -1461,7 +1471,7 @@ class EntryWriter {
1461
1471
  closed = false;
1462
1472
  cleaned = false;
1463
1473
  lifetime = new AbortController();
1464
- abort = () => { this.fail(this.signal?.reason ?? new DOMException("Export cancelled.", "AbortError")); };
1474
+ abort = () => { this.fail(this.signal?.reason); };
1465
1475
  constructor(compression, sink, signal) {
1466
1476
  this.sink = sink;
1467
1477
  this.signal = signal;
@@ -1558,11 +1568,11 @@ class EntryWriter {
1558
1568
  }
1559
1569
  }
1560
1570
  const _exports = Object.freeze({ Crc32: _m28.Crc32, zipLimit: zipLimit, zipSize: zipSize, EntryWriter: EntryWriter });
1561
- _modules.set("34b448ff5052fe659ccb250d80fc2a0b13ab82890f50132ef5c9e51da369a582", _exports);
1571
+ _modules.set("597d152d20a2a28ee5cd6d4243a79a71ce8b83769a77441bfc944aadc0a6efbd", _exports);
1562
1572
  return _exports;
1563
1573
  })();
1564
1574
 
1565
- const _m26 = _modules.get("cc7c3953e35bb436d0f5fe5c35a60b7e97a00d2e729df52d219d9e246f326b32") ?? (() => {
1575
+ const _m26 = _modules.get("699a019e0c3f317a62bf3a6e59b76b6cf1645908b0f1b1f157c18f4d4f368dfb") ?? (() => {
1566
1576
 
1567
1577
 
1568
1578
  const { EntryWriter, zipSize } = _m27;
@@ -1626,7 +1636,7 @@ class ZipWriter {
1626
1636
  /** Pending header/directory writes and source reads must also stop on explicit discard. */
1627
1637
  async acceptance(operation) {
1628
1638
  const signal = this.options.signal;
1629
- const abort = () => this.lifetime.abort(signal?.reason ?? new DOMException("Export cancelled.", "AbortError"));
1639
+ const abort = () => this.lifetime.abort(signal?.reason);
1630
1640
  signal?.addEventListener("abort", abort, { once: true });
1631
1641
  try {
1632
1642
  checkAbort(signal);
@@ -1818,11 +1828,11 @@ class ZipWriter {
1818
1828
  }
1819
1829
  }
1820
1830
  const _exports = Object.freeze({ Crc32: _m27.Crc32, validateEntryName: validateEntryName, ZipWriter: ZipWriter });
1821
- _modules.set("cc7c3953e35bb436d0f5fe5c35a60b7e97a00d2e729df52d219d9e246f326b32", _exports);
1831
+ _modules.set("699a019e0c3f317a62bf3a6e59b76b6cf1645908b0f1b1f157c18f4d4f368dfb", _exports);
1822
1832
  return _exports;
1823
1833
  })();
1824
1834
 
1825
- const _m22 = _modules.get("c982e9efabd891df539c26c513a3e9cf5a644ae13516f48f9d19f7ed6b584c06") ?? (() => {
1835
+ const _m22 = _modules.get("4d4856357f94ecbeea67d111ff5e97f916ccc6be6aaefde219d461c6ad10a8c5") ?? (() => {
1826
1836
 
1827
1837
 
1828
1838
 
@@ -1921,8 +1931,11 @@ class OpcPackage {
1921
1931
  return uri;
1922
1932
  }
1923
1933
  addPart(part) {
1924
- const uri = this.reserve(part.uri, part.contentType);
1925
- this.parts.set(uri.toLowerCase(), { ...part, uri, data: part.data instanceof Uint8Array ? new Uint8Array(part.data) : part.data });
1934
+ const { uri: requestedUri, contentType, data } = part;
1935
+ // Structural accessors and byte ownership are captured before reserving metadata.
1936
+ const capturedData = data instanceof Uint8Array ? new Uint8Array(data) : data;
1937
+ const uri = this.reserve(requestedUri, contentType);
1938
+ this.parts.set(uri.toLowerCase(), { uri, contentType, data: capturedData });
1926
1939
  }
1927
1940
  /** @internal */
1928
1941
  addPrepared(uri, type, prepared) {
@@ -1947,17 +1960,19 @@ class OpcPackage {
1947
1960
  checkAbort(this.options.signal);
1948
1961
  this.open();
1949
1962
  source = source === "/" ? source : partUri(source);
1950
- if (!/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(relationship.id))
1963
+ const { id, type, target: requestedTarget, external } = relationship;
1964
+ this.open();
1965
+ if (!/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(id))
1951
1966
  throw new TypeError("Relationship id must be an XML ID.");
1952
- if (!/^[A-Za-z][A-Za-z0-9+.-]*:[^\s<>"']+$/.test(relationship.type))
1967
+ if (!/^[A-Za-z][A-Za-z0-9+.-]*:[^\s<>"']+$/.test(type))
1953
1968
  throw new TypeError("Relationship type must be an absolute URI.");
1954
- const target = relationship.external ? relationship.target : partUri(relationship.target);
1955
- if (relationship.external && (!target || /[\u0000-\u0020]/.test(target)))
1969
+ const target = external ? requestedTarget : partUri(requestedTarget);
1970
+ if (external && (!target || /[\u0000-\u0020]/.test(target)))
1956
1971
  throw new TypeError("Invalid external relationship target.");
1957
1972
  const key = source.toLowerCase(), list = this.relationships.get(key) ?? new Map();
1958
- if (list.has(relationship.id))
1959
- throw new TypeError("Duplicate relationship id: " + relationship.id);
1960
- list.set(relationship.id, { ...relationship, target });
1973
+ if (list.has(id))
1974
+ throw new TypeError("Duplicate relationship id: " + id);
1975
+ list.set(id, { id, type, target, ...(external === undefined ? {} : { external }) });
1961
1976
  this.relationships.set(key, list);
1962
1977
  }
1963
1978
  setProperties(core = {}, app = {}) {
@@ -2067,7 +2082,7 @@ class OpcPackage {
2067
2082
  }
2068
2083
  }
2069
2084
  const _exports = Object.freeze({ partUri: _m23.partUri, relationshipPartUri: _m23.relationshipPartUri, relativePartTarget: _m23.relativePartTarget, corePropertiesXml: _m24.corePropertiesXml, appPropertiesXml: _m24.appPropertiesXml, relationshipsNamespace: relationshipsNamespace, officeRelationshipsNamespace: officeRelationshipsNamespace, contentTypesNamespace: contentTypesNamespace, relationshipTypes: relationshipTypes, ContentTypes: ContentTypes, OpcPackage: OpcPackage });
2070
- _modules.set("c982e9efabd891df539c26c513a3e9cf5a644ae13516f48f9d19f7ed6b584c06", _exports);
2085
+ _modules.set("4d4856357f94ecbeea67d111ff5e97f916ccc6be6aaefde219d461c6ad10a8c5", _exports);
2071
2086
  return _exports;
2072
2087
  })();
2073
2088
 
@@ -2083,7 +2098,7 @@ _modules.set("204def412284dfb11df9aececd57c8c0455db2927ebdb483dd255e7b29f6f359",
2083
2098
  return _exports;
2084
2099
  })();
2085
2100
 
2086
- const _m31 = _modules.get("27f56318b4276c3e6f79cfb300855315ff9cd1897d4748fa2f306b2deef98c36") ?? (() => {
2101
+ const _m31 = _modules.get("6ae88f25e1c09d00fbb828917498569f883fae88ec25d37caebaf8a2b802b148") ?? (() => {
2087
2102
  const { OfficeIMOError } = _m2;
2088
2103
 
2089
2104
  const { cleanXml, escapeOoxmlAttribute } = _m25;
@@ -2190,11 +2205,11 @@ function differentialXml(style, policy, numberFormat) {
2190
2205
  return xml;
2191
2206
  }
2192
2207
  const _exports = Object.freeze({ fields: fields, optionalBoolean: optionalBoolean, DifferentialStyles: DifferentialStyles, differentialXml: differentialXml });
2193
- _modules.set("27f56318b4276c3e6f79cfb300855315ff9cd1897d4748fa2f306b2deef98c36", _exports);
2208
+ _modules.set("6ae88f25e1c09d00fbb828917498569f883fae88ec25d37caebaf8a2b802b148", _exports);
2194
2209
  return _exports;
2195
2210
  })();
2196
2211
 
2197
- const _m29 = _modules.get("bf7ec82677b616a41d07306ba385b32456bc03509817c13bbe65a1ba390a6253") ?? (() => {
2212
+ const _m29 = _modules.get("077c3c668f1457253dba044e6f6be7f7afd28a8976ed20c764bd5d5dc7c41889") ?? (() => {
2198
2213
  const { escapeOoxmlAttribute, cleanXml, xmlDeclaration } = _m25;
2199
2214
 
2200
2215
  const { OfficeIMOError } = _m2;
@@ -2404,11 +2419,11 @@ class StyleRegistry {
2404
2419
  }
2405
2420
  }
2406
2421
  const _exports = Object.freeze({ colorArgb: _m30.colorArgb, spreadsheetNamespace: spreadsheetNamespace, NumberFormats: NumberFormats, validateStylePatch: validateStylePatch, copyStylePatch: copyStylePatch, StyleRegistry: StyleRegistry });
2407
- _modules.set("bf7ec82677b616a41d07306ba385b32456bc03509817c13bbe65a1ba390a6253", _exports);
2422
+ _modules.set("077c3c668f1457253dba044e6f6be7f7afd28a8976ed20c764bd5d5dc7c41889", _exports);
2408
2423
  return _exports;
2409
2424
  })();
2410
2425
 
2411
- const _m33 = _modules.get("6d0c9930eb0b5d96d92b93ba72759417a324dfd119a592c5a2ee4de0ff3495ec") ?? (() => {
2426
+ const _m33 = _modules.get("f1de2157d2aefa347a314940eb7f89c16545e11f69923920e605409433742f93") ?? (() => {
2412
2427
  const { NotSupportedError } = _m2;
2413
2428
 
2414
2429
  const { cleanXml, escapeXml } = _m25;
@@ -2516,11 +2531,11 @@ function formulaXml(cell) {
2516
2531
  return "<f>" + escapeXml(cell.formula, "reject") + "</f><v>" + (cell.cachedValue ?? "") + "</v>";
2517
2532
  }
2518
2533
  const _exports = Object.freeze({ FormulaCell: FormulaCell, isSubtotalFormula: isSubtotalFormula, formulaXml: formulaXml });
2519
- _modules.set("6d0c9930eb0b5d96d92b93ba72759417a324dfd119a592c5a2ee4de0ff3495ec", _exports);
2534
+ _modules.set("f1de2157d2aefa347a314940eb7f89c16545e11f69923920e605409433742f93", _exports);
2520
2535
  return _exports;
2521
2536
  })();
2522
2537
 
2523
- const _m32 = _modules.get("45bcbd0fd875662d537921217d5e747170e665dedc70927041f59d5782ed21b0") ?? (() => {
2538
+ const _m32 = _modules.get("4bce839e90e3ef590aa1b224ffd9c4bdf24d7639b93bdf879f9a0d79de4cd0e4") ?? (() => {
2524
2539
  const { cleanXml, escapeXml } = _m25;
2525
2540
 
2526
2541
  const { assertExportValue, assertScalar } = _m5;
@@ -2584,12 +2599,13 @@ function sheetName(requested, names, policy, register = true) {
2584
2599
  throw new TypeError("Sheet name must be a string.");
2585
2600
  // Validate and deduplicate the decoded literal value, before ST_Xstring attribute encoding.
2586
2601
  // A requested _xHHHH_ token is literal text; the serializer protects its leading underscore.
2587
- let base = cleanXml(requested, policy).replace(/[\[\]:*?/\\]/g, "_").trim().replace(/^'+|'+$/g, "").trim();
2602
+ let base = cleanXml(requested, policy).replace(/[\[\]:*?/\\]/g, "_").replace(/^[\s']+|[\s']+$/g, "");
2603
+ // Clipping can expose an internal apostrophe or the reserved History name.
2604
+ base = clipName(base, 31).replace(/[\s']+$/g, "");
2588
2605
  if (!base)
2589
2606
  base = "Sheet";
2590
2607
  if (base.toLowerCase() === "history")
2591
2608
  base += "_";
2592
- base = clipName(base, 31);
2593
2609
  let name = base, suffix = 2;
2594
2610
  while (names.has(name.toLowerCase())) {
2595
2611
  const tail = " (" + suffix++ + ")";
@@ -2612,11 +2628,11 @@ function excelDate(date, mode) {
2612
2628
  return (time - Date.UTC(1899, 11, 31)) / 86400000 + (time >= Date.UTC(1900, 2, 1) ? 1 : 0);
2613
2629
  }
2614
2630
  const _exports = Object.freeze({ Cell: Cell, assertXlsxValue: assertXlsxValue, copyValue: copyValue, cellText: cellText, inlineText: inlineText, columnName: columnName, sheetName: sheetName, excelDate: excelDate });
2615
- _modules.set("45bcbd0fd875662d537921217d5e747170e665dedc70927041f59d5782ed21b0", _exports);
2631
+ _modules.set("4bce839e90e3ef590aa1b224ffd9c4bdf24d7639b93bdf879f9a0d79de4cd0e4", _exports);
2616
2632
  return _exports;
2617
2633
  })();
2618
2634
 
2619
- const _m36 = _modules.get("7e3adf1ed8ebd3d36cf5e10c55f94387f7044e585e7a1e14fbf597db4e2e4fea") ?? (() => {
2635
+ const _m36 = _modules.get("84c16159c55cf4c0af5d3c67510302694946ae99c6c685fc09314069ee3da5c5") ?? (() => {
2620
2636
  const { ChunkedTextSink } = _m3;
2621
2637
 
2622
2638
  const { escapeXml, xmlDeclaration } = _m25;
@@ -2725,11 +2741,11 @@ async function writeChartXml(chart, destination, policy, signal) {
2725
2741
  await text.close();
2726
2742
  }
2727
2743
  const _exports = Object.freeze({ chartNamespace: chartNamespace, chartContentType: chartContentType, chartAnchorXml: chartAnchorXml, writeChartXml: writeChartXml });
2728
- _modules.set("7e3adf1ed8ebd3d36cf5e10c55f94387f7044e585e7a1e14fbf597db4e2e4fea", _exports);
2744
+ _modules.set("84c16159c55cf4c0af5d3c67510302694946ae99c6c685fc09314069ee3da5c5", _exports);
2729
2745
  return _exports;
2730
2746
  })();
2731
2747
 
2732
- const _m35 = _modules.get("2a8fdd646d18edd986a29c54b3860ff16650da92d97b03a7cdd3cacd843c5246") ?? (() => {
2748
+ const _m35 = _modules.get("9d4496a1ff3d58ac0b9dcd7304e6861184df30700c344329157899639df7b5e4") ?? (() => {
2733
2749
  const { cleanXml, escapeXml, escapeOoxmlAttribute, xmlDeclaration } = _m25;
2734
2750
 
2735
2751
  const { copyExportLink } = _m7;
@@ -2803,11 +2819,11 @@ function drawingXml(images, policy, charts = []) {
2803
2819
  }
2804
2820
  const drawingContentType = "application/vnd.openxmlformats-officedocument.drawing+xml";
2805
2821
  const _exports = Object.freeze({ copyDrawingAnchor: copyDrawingAnchor, cellPosition: cellPosition, copyHyperlink: copyHyperlink, copyImage: copyImage, hyperlinksXml: hyperlinksXml, drawingXml: drawingXml, drawingContentType: drawingContentType });
2806
- _modules.set("2a8fdd646d18edd986a29c54b3860ff16650da92d97b03a7cdd3cacd843c5246", _exports);
2822
+ _modules.set("9d4496a1ff3d58ac0b9dcd7304e6861184df30700c344329157899639df7b5e4", _exports);
2807
2823
  return _exports;
2808
2824
  })();
2809
2825
 
2810
- const _m38 = _modules.get("dbb48ba4ffa2659e2972a395c603d203c11ea8addb71c38103c006d6d7937506") ?? (() => {
2826
+ const _m38 = _modules.get("4c91e257806f805b473340527db7ce3404c98ac27db0a775ff047dc3dded10cc") ?? (() => {
2811
2827
  const { OfficeIMOError } = _m2;
2812
2828
 
2813
2829
  const { cellPosition } = _m35;
@@ -2908,11 +2924,11 @@ class MergeRegions {
2908
2924
  throw new RangeError("Merged ranges must stay within exported rows."); }
2909
2925
  }
2910
2926
  const _exports = Object.freeze({ MergeRegions: MergeRegions });
2911
- _modules.set("dbb48ba4ffa2659e2972a395c603d203c11ea8addb71c38103c006d6d7937506", _exports);
2927
+ _modules.set("4c91e257806f805b473340527db7ce3404c98ac27db0a775ff047dc3dded10cc", _exports);
2912
2928
  return _exports;
2913
2929
  })();
2914
2930
 
2915
- const _m39 = _modules.get("b9d400aa8d995edccef22cef96a0e14cb28ce2071c42d8cf29de94d74fe82355") ?? (() => {
2931
+ const _m39 = _modules.get("47efdc8f108b0e995accdd63fd1addea0e4de507010cbf0975417e7151636360") ?? (() => {
2916
2932
  const { ExportCell } = _m5;
2917
2933
 
2918
2934
  const { tableSpans } = _m17;
@@ -2945,11 +2961,11 @@ class StructuredRows {
2945
2961
  }
2946
2962
  }
2947
2963
  const _exports = Object.freeze({ StructuredRows: StructuredRows });
2948
- _modules.set("b9d400aa8d995edccef22cef96a0e14cb28ce2071c42d8cf29de94d74fe82355", _exports);
2964
+ _modules.set("47efdc8f108b0e995accdd63fd1addea0e4de507010cbf0975417e7151636360", _exports);
2949
2965
  return _exports;
2950
2966
  })();
2951
2967
 
2952
- const _m37 = _modules.get("26966342ea634f631f6b1e684842fb8d3a01e38fe33cac9b74261ba9ff4c11cb") ?? (() => {
2968
+ const _m37 = _modules.get("23615ba776e7025e5e40cde325ad13799a7eeae6c88cb2ed74395222f91e6a81") ?? (() => {
2953
2969
  const { ExportCell } = _m5;
2954
2970
 
2955
2971
  const { isDate } = _m6;
@@ -3146,11 +3162,11 @@ function printXml(options, policy) {
3146
3162
  (options.footer === undefined ? "" : '<oddFooter>' + escapeOoxmlAttribute("&C" + options.footer.replace(/&/g, "&&"), policy) + '</oddFooter>') + '</headerFooter>' : "");
3147
3163
  }
3148
3164
  const _exports = Object.freeze({ ComputedTotal: ComputedTotal, ReportLayout: ReportLayout, totalFormula: totalFormula, printXml: printXml });
3149
- _modules.set("26966342ea634f631f6b1e684842fb8d3a01e38fe33cac9b74261ba9ff4c11cb", _exports);
3165
+ _modules.set("23615ba776e7025e5e40cde325ad13799a7eeae6c88cb2ed74395222f91e6a81", _exports);
3150
3166
  return _exports;
3151
3167
  })();
3152
3168
 
3153
- const _m41 = _modules.get("4d984092c5be653d0d5c8c910638fe0c0d560f8e74ea34c1a7b52b24be29fbf5") ?? (() => {
3169
+ const _m41 = _modules.get("7845d79cd22590bbefc767802abfe3f805e8f68807521cef8d07ecc42db0b491") ?? (() => {
3154
3170
  const { columnName } = _m32;
3155
3171
 
3156
3172
  /** @internal Data-column selectors use stable keys or one-based worksheet columns. */
@@ -3177,11 +3193,11 @@ function qualifiedCell(sheetName, column, row) {
3177
3193
  return qualifiedColumnRange(sheetName, column, row, 1).split(":")[0];
3178
3194
  }
3179
3195
  const _exports = Object.freeze({ resolveDataColumn: resolveDataColumn, qualifiedColumnRange: qualifiedColumnRange, qualifiedCell: qualifiedCell });
3180
- _modules.set("4d984092c5be653d0d5c8c910638fe0c0d560f8e74ea34c1a7b52b24be29fbf5", _exports);
3196
+ _modules.set("7845d79cd22590bbefc767802abfe3f805e8f68807521cef8d07ecc42db0b491", _exports);
3181
3197
  return _exports;
3182
3198
  })();
3183
3199
 
3184
- const _m42 = _modules.get("216c77d37374c34583daebcedae5d725280614b84266d0048b25fc94d816bbad") ?? (() => {
3200
+ const _m42 = _modules.get("4892a7dafefc4d82567cd2bd4cc8da5470cee4dbf546e6473f782f44bd4bbe35") ?? (() => {
3185
3201
  const { OfficeIMOError } = _m2;
3186
3202
 
3187
3203
  const { columnName } = _m32;
@@ -3224,11 +3240,11 @@ function dataRowReference(firstColumn, lastColumn, headerRows, dataRows, ranges)
3224
3240
  return reference || undefined;
3225
3241
  }
3226
3242
  const _exports = Object.freeze({ retainDataRowRanges: retainDataRowRanges, dataRowRanges: dataRowRanges, dataRowCount: dataRowCount, dataRowReference: dataRowReference });
3227
- _modules.set("216c77d37374c34583daebcedae5d725280614b84266d0048b25fc94d816bbad", _exports);
3243
+ _modules.set("4892a7dafefc4d82567cd2bd4cc8da5470cee4dbf546e6473f782f44bd4bbe35", _exports);
3228
3244
  return _exports;
3229
3245
  })();
3230
3246
 
3231
- const _m40 = _modules.get("a1fdc34474873603d9907928d65684efabe0bfce470a26305f49b46b5fb5b12a") ?? (() => {
3247
+ const _m40 = _modules.get("736b2b2fc3489642263dbaf677544e8a270eea6b8efb0cc26c67346e66cab118") ?? (() => {
3232
3248
  const { cleanXml, escapeXml, escapeOoxmlAttribute } = _m25;
3233
3249
 
3234
3250
  const { cellPosition } = _m35;
@@ -3394,11 +3410,11 @@ class ConditionalFormats {
3394
3410
  }
3395
3411
  }
3396
3412
  const _exports = Object.freeze({ prepareConditionalFormats: prepareConditionalFormats, ConditionalFormats: ConditionalFormats });
3397
- _modules.set("a1fdc34474873603d9907928d65684efabe0bfce470a26305f49b46b5fb5b12a", _exports);
3413
+ _modules.set("736b2b2fc3489642263dbaf677544e8a270eea6b8efb0cc26c67346e66cab118", _exports);
3398
3414
  return _exports;
3399
3415
  })();
3400
3416
 
3401
- const _m43 = _modules.get("082c5d69b3ae3fbd0b4477ae5cfd07155401158d890162c4a223eb67ffeb489b") ?? (() => {
3417
+ const _m43 = _modules.get("860c88d97ba76e8713c14d56967152e369d2f08f50ffada68827a9c220881c61") ?? (() => {
3402
3418
  const { OfficeIMOError } = _m2;
3403
3419
 
3404
3420
  const { checkAbort } = _m4;
@@ -3498,11 +3514,11 @@ function* dataValidationsXml(prepared, headerRows, dataRows, ranges) {
3498
3514
  yield '</dataValidations>';
3499
3515
  }
3500
3516
  const _exports = Object.freeze({ prepareDataValidations: prepareDataValidations, dataValidationsXml: dataValidationsXml });
3501
- _modules.set("082c5d69b3ae3fbd0b4477ae5cfd07155401158d890162c4a223eb67ffeb489b", _exports);
3517
+ _modules.set("860c88d97ba76e8713c14d56967152e369d2f08f50ffada68827a9c220881c61", _exports);
3502
3518
  return _exports;
3503
3519
  })();
3504
3520
 
3505
- const _m34 = _modules.get("5d200c22b866a7be40782b9b348f2ad3b781abd8434f420d780e89aa65ede587") ?? (() => {
3521
+ const _m34 = _modules.get("b99287e3e329b75007119103112a699c368d8237b37fa79e083b0014a21952e4") ?? (() => {
3506
3522
  const { checkAbort, consumeRows, inputRows, pause, taskYieldDue } = _m4;
3507
3523
 
3508
3524
  const { ChunkedTextSink, BlobByteSink } = _m3;
@@ -3782,7 +3798,8 @@ class Worksheet {
3782
3798
  });
3783
3799
  const originalCharacters = typeof value === "string" ? value.length : 0;
3784
3800
  let reservedCharacters = this.preserved || header || footer ? originalCharacters : undefined;
3785
- if (type === "string" && cleanXml(value, this.book.settings.invalidCharacterPolicy).length > 32767) {
3801
+ // Cleaning removes characters; ordinary strings cannot cross Excel's limit.
3802
+ if (type === "string" && originalCharacters > 32767 && cleanXml(value, this.book.settings.invalidCharacterPolicy).length > 32767) {
3786
3803
  const cell = col.letter + row;
3787
3804
  if (link || this.linkedCells.has(cell))
3788
3805
  throw new TypeError("A text-preservation cell cannot also have an external hyperlink.");
@@ -4224,11 +4241,11 @@ class Worksheet {
4224
4241
  async discard(error) { this.failed = true; this.error = error; this.pending = []; this.pendingCharacters = 0; this.prepared = undefined; this.buffer = undefined; this.nativeCharts.length = 0; this.chartSources.length = 0; this.output.discard(); await this.entry?.discard(error); }
4225
4242
  }
4226
4243
  const _exports = Object.freeze({ Worksheet: Worksheet });
4227
- _modules.set("5d200c22b866a7be40782b9b348f2ad3b781abd8434f420d780e89aa65ede587", _exports);
4244
+ _modules.set("b99287e3e329b75007119103112a699c368d8237b37fa79e083b0014a21952e4", _exports);
4228
4245
  return _exports;
4229
4246
  })();
4230
4247
 
4231
- const _m44 = _modules.get("87ebdbcd48a4e7d39257ef5bdfe726a889dbf5eaf3cd3f51a0205bf65090f6cf") ?? (() => {
4248
+ const _m44 = _modules.get("7f1b6bb321e8055ba5269c0fe0933cf02f9a4ce269d3b8e4a64cc63d8398954a") ?? (() => {
4232
4249
  const { escapeOoxmlAttribute, escapeXml, xmlDeclaration } = _m25;
4233
4250
 
4234
4251
  const { cellText, columnName } = _m32;
@@ -4271,11 +4288,11 @@ function tableXml(table, rowCount, policy, headerRow = 1, footer) {
4271
4288
  '" showColumnStripes="' + (options.bandedColumns ? 1 : 0) + '"/></table>';
4272
4289
  }
4273
4290
  const _exports = Object.freeze({ defineTable: defineTable, tableXml: tableXml });
4274
- _modules.set("87ebdbcd48a4e7d39257ef5bdfe726a889dbf5eaf3cd3f51a0205bf65090f6cf", _exports);
4291
+ _modules.set("7f1b6bb321e8055ba5269c0fe0933cf02f9a4ce269d3b8e4a64cc63d8398954a", _exports);
4275
4292
  return _exports;
4276
4293
  })();
4277
4294
 
4278
- const _m45 = _modules.get("9c165af1760666d37381c410b96136694d28d86e1e5fcf4847f2d1087bb952f4") ?? (() => {
4295
+ const _m45 = _modules.get("0c395783b9d7cc62dd39a21adeb698ad4a61e2c89f7b1fc8712e2eb2ccfe9d92") ?? (() => {
4279
4296
  const { OfficeIMOError } = _m2;
4280
4297
 
4281
4298
  const { cleanXml } = _m25;
@@ -4339,7 +4356,7 @@ function* splitText(text) {
4339
4356
  }
4340
4357
  }
4341
4358
  const _exports = Object.freeze({ TextOverflow: TextOverflow, clipText: clipText });
4342
- _modules.set("9c165af1760666d37381c410b96136694d28d86e1e5fcf4847f2d1087bb952f4", _exports);
4359
+ _modules.set("0c395783b9d7cc62dd39a21adeb698ad4a61e2c89f7b1fc8712e2eb2ccfe9d92", _exports);
4343
4360
  return _exports;
4344
4361
  })();
4345
4362
 
@@ -4366,7 +4383,7 @@ _modules.set("e00bc0213b723678d050e3e1f11b39ed3d6b0b0fd6a39b403beb1a6bef69e282",
4366
4383
  return _exports;
4367
4384
  })();
4368
4385
 
4369
- const _m48 = _modules.get("bd66b325c9055258132735218be91a78281910aaac042bcac4c5b0f594e35379") ?? (() => {
4386
+ const _m48 = _modules.get("35db01801a6b2e3e0c5acd7493e56f04b5b41b1d57afa8be28b8358378ad6494") ?? (() => {
4370
4387
  const { checkAbort } = _m4;
4371
4388
 
4372
4389
  const { NotSupportedError, OfficeIMOError } = _m2;
@@ -4494,11 +4511,11 @@ function prepareChartBinding(input, descriptor, budgets, signal, type = "columnC
4494
4511
  }, finish });
4495
4512
  }
4496
4513
  const _exports = Object.freeze({ captureChartRange: captureChartRange, prepareChartBinding: prepareChartBinding });
4497
- _modules.set("bd66b325c9055258132735218be91a78281910aaac042bcac4c5b0f594e35379", _exports);
4514
+ _modules.set("35db01801a6b2e3e0c5acd7493e56f04b5b41b1d57afa8be28b8358378ad6494", _exports);
4498
4515
  return _exports;
4499
4516
  })();
4500
4517
 
4501
- const _m47 = _modules.get("1a72338dda567009c435c547ffc3b6a8e798369b5455bb94c629f8fab0771eb7") ?? (() => {
4518
+ const _m47 = _modules.get("6ff482aba6cf0b524cf20f6a4f8af16b842a49f36448b14e73beaf838885d219") ?? (() => {
4502
4519
  const { checkAbort } = _m4;
4503
4520
 
4504
4521
  const { NotSupportedError, OfficeIMOError } = _m2;
@@ -4665,11 +4682,11 @@ function prepareChart(input, policy, availablePoints, availableText, signal, res
4665
4682
  points, textCharacters });
4666
4683
  }
4667
4684
  const _exports = Object.freeze({ prepareChart: prepareChart });
4668
- _modules.set("1a72338dda567009c435c547ffc3b6a8e798369b5455bb94c629f8fab0771eb7", _exports);
4685
+ _modules.set("6ff482aba6cf0b524cf20f6a4f8af16b842a49f36448b14e73beaf838885d219", _exports);
4669
4686
  return _exports;
4670
4687
  })();
4671
4688
 
4672
- const _m21 = _modules.get("ae55b8ef5a8ee860d084264e4184cae35d6b359c73b70c059503e435df68f397") ?? (() => {
4689
+ const _m21 = _modules.get("0f11efc0d52501e827898643b33f7fa42365115a892aa801634ecea3f3603681") ?? (() => {
4673
4690
  const { beginTask, checkAbort, pause, taskYieldDue } = _m4;
4674
4691
 
4675
4692
  const { OfficeIMOError } = _m2;
@@ -5008,12 +5025,15 @@ class Workbook {
5008
5025
  });
5009
5026
  }
5010
5027
  addPart(part) {
5028
+ this.assertOpen();
5029
+ const { uri, contentType, data, relationship } = part;
5030
+ const capturedRelationship = relationship && { id: relationship.id, type: relationship.type, source: relationship.source };
5011
5031
  this.assertOpen();
5012
5032
  // Reserve now so collisions and invalid names fail at the call site.
5013
- this.package.addPart(part);
5014
- if (part.relationship) {
5015
- const { source, ...rel } = part.relationship;
5016
- this.package.addRelationship(source ?? "/xl/workbook.xml", { ...rel, target: part.uri });
5033
+ this.package.addPart({ uri, contentType, data });
5034
+ if (capturedRelationship) {
5035
+ const { source, id, type } = capturedRelationship;
5036
+ this.package.addRelationship(source ?? "/xl/workbook.xml", { id, type, target: uri });
5017
5037
  }
5018
5038
  }
5019
5039
  /** Complete the archive and return counts. Does not close or dispose a caller-owned sink. */
@@ -5144,7 +5164,7 @@ class Workbook {
5144
5164
  }
5145
5165
  }
5146
5166
  const _exports = Object.freeze({ Workbook: Workbook });
5147
- _modules.set("ae55b8ef5a8ee860d084264e4184cae35d6b359c73b70c059503e435df68f397", _exports);
5167
+ _modules.set("0f11efc0d52501e827898643b33f7fa42365115a892aa801634ecea3f3603681", _exports);
5148
5168
  return _exports;
5149
5169
  })();
5150
5170
 
@@ -5201,7 +5221,7 @@ _modules.set("89111eab1f3857529c2d0cd849f16598097e62bd73841211b9c66ccc7b1b7ca2",
5201
5221
  return _exports;
5202
5222
  })();
5203
5223
 
5204
- const _m49 = _modules.get("d4f8b447d0a2834af0ecb5f89766e5402a65980c89f3a4973b4493cac65051b4") ?? (() => {
5224
+ const _m49 = _modules.get("8d425cd3abec2c5e0140f71239bbeacbae0e57524ed70a8e545f80286c4a1308") ?? (() => {
5205
5225
  const { withDestination } = _m3;
5206
5226
 
5207
5227
  const { copyColumns } = _m11;
@@ -5256,11 +5276,11 @@ async function writeXlsxTo(rows, destination, configuration) {
5256
5276
  });
5257
5277
  }
5258
5278
  const _exports = Object.freeze({ writeXlsx: writeXlsx, writeXlsxTo: writeXlsxTo });
5259
- _modules.set("d4f8b447d0a2834af0ecb5f89766e5402a65980c89f3a4973b4493cac65051b4", _exports);
5279
+ _modules.set("8d425cd3abec2c5e0140f71239bbeacbae0e57524ed70a8e545f80286c4a1308", _exports);
5260
5280
  return _exports;
5261
5281
  })();
5262
5282
 
5263
- const _m52 = _modules.get("1c910dc1be8cd6844c1384524ba7c64dc75d80ff09de2fbd5a4752b9cdfd943b") ?? (() => {
5283
+ const _m52 = _modules.get("02f1b8fe9368420b22d79efc01f2b37794fc40aaf8150161b3b7623fcdc0d71f") ?? (() => {
5264
5284
  const { assertGroupedReportSource } = _m8;
5265
5285
 
5266
5286
  const { captureFields } = _m10;
@@ -5349,11 +5369,11 @@ function prepareGroupedSheet(report, configuration, maxConditionalFormats = 1000
5349
5369
  ...(options.grandTotalStyle ? { grandTotalStyle: copyStylePatch(options.grandTotalStyle) } : {}) };
5350
5370
  }
5351
5371
  const _exports = Object.freeze({ groupedOptionFields: groupedOptionFields, prepareGroupedSheet: prepareGroupedSheet });
5352
- _modules.set("1c910dc1be8cd6844c1384524ba7c64dc75d80ff09de2fbd5a4752b9cdfd943b", _exports);
5372
+ _modules.set("02f1b8fe9368420b22d79efc01f2b37794fc40aaf8150161b3b7623fcdc0d71f", _exports);
5353
5373
  return _exports;
5354
5374
  })();
5355
5375
 
5356
- const _m51 = _modules.get("59f736fd5084497af8fb6fd211c910f5980174a39d31641216eda50f6d78bb63") ?? (() => {
5376
+ const _m51 = _modules.get("6b646c4d57b8f8f452eaa7e61d2935bab09681aceb6064b8600bf73ca10b8f4e") ?? (() => {
5357
5377
  const { groupedReportOperation } = _m8;
5358
5378
 
5359
5379
  const { checkAbort, withAbort } = _m4;
@@ -5526,14 +5546,14 @@ async function writeGroupedXlsxTo(report, destination, options) {
5526
5546
  return withDestination(destination, async (sink) => (await write(report, prepared, sink)).result);
5527
5547
  }
5528
5548
  const _exports = Object.freeze({ addGroupedXlsx: addGroupedXlsx, writeGroupedXlsx: writeGroupedXlsx, writeGroupedXlsxTo: writeGroupedXlsxTo });
5529
- _modules.set("59f736fd5084497af8fb6fd211c910f5980174a39d31641216eda50f6d78bb63", _exports);
5549
+ _modules.set("6b646c4d57b8f8f452eaa7e61d2935bab09681aceb6064b8600bf73ca10b8f4e", _exports);
5530
5550
  return _exports;
5531
5551
  })();
5532
5552
 
5533
- const _m20 = _modules.get("5f2337c50c0e9b88b7a8095f5b5df2f3fde33723e3115223465178731cfab42d") ?? (() => {
5553
+ const _m20 = _modules.get("9fbdb5c6f6af75d87ac6cb47771fe48fa6527be2cb7d16dbad56e4213e2f7195") ?? (() => {
5534
5554
 
5535
5555
  const _exports = Object.freeze({ Workbook: _m21.Workbook, writeXlsx: _m49.writeXlsx, writeXlsxTo: _m49.writeXlsxTo, writeGroupedXlsx: _m51.writeGroupedXlsx, writeGroupedXlsxTo: _m51.writeGroupedXlsxTo, addGroupedXlsx: _m51.addGroupedXlsx, createGroupedReport: _m8.createGroupedReport, Worksheet: _m34.Worksheet, Cell: _m32.Cell, FormulaCell: _m33.FormulaCell, StyleRegistry: _m29.StyleRegistry, NumberFormats: _m29.NumberFormats, saveBlob: _m1.saveBlob, ExportCell: _m5.ExportCell });
5536
- _modules.set("5f2337c50c0e9b88b7a8095f5b5df2f3fde33723e3115223465178731cfab42d", _exports);
5556
+ _modules.set("9fbdb5c6f6af75d87ac6cb47771fe48fa6527be2cb7d16dbad56e4213e2f7195", _exports);
5537
5557
  return _exports;
5538
5558
  })();
5539
5559
 
@@ -5646,7 +5666,7 @@ _modules.set("278e6adc6a5d4491e688589ef165bd1aa9cc74f557da6f9d6bdf53ecc0c6df47",
5646
5666
  return _exports;
5647
5667
  })();
5648
5668
 
5649
- const _m55 = _modules.get("87a3335ede8f46b6e42f2c03e68f3df802321aa23c52dc4cdfb11165529a5270") ?? (() => {
5669
+ const _m55 = _modules.get("4a089607f7cbe50e13d4382d1cc4e5f6ce32c5773bbec2df84178710f54d9a38") ?? (() => {
5650
5670
  const { OfficeIMOError } = _m2;
5651
5671
 
5652
5672
  const { ExportBudget } = _m9;
@@ -5721,10 +5741,34 @@ function captureWideTable(input) {
5721
5741
  if (repeatColumns !== undefined && !Array.isArray(repeatColumns))
5722
5742
  throw new TypeError("repeatColumns must be an array.");
5723
5743
  const repeats = repeatColumns === undefined ? [] : [...repeatColumns];
5724
- if (repeats.some((value, index) => !Number.isSafeInteger(value) || value < 0 || index > 0 && value <= repeats[index - 1]))
5725
- throw new RangeError("repeatColumns must contain sorted unique nonnegative indices.");
5744
+ if (repeats.some(value => typeof value === "number" ? !Number.isSafeInteger(value) || value < 0 : typeof value !== "string" || !value.length))
5745
+ throw new RangeError("repeatColumns must contain nonnegative indices or nonempty stable keys.");
5746
+ if (repeats.every(value => typeof value === "number") && repeats.some((value, index) => index > 0 && value <= repeats[index - 1]))
5747
+ throw new RangeError("Numeric repeatColumns must contain sorted unique nonnegative indices.");
5726
5748
  return Object.freeze({ mode, ...(minimumColumnWidth === undefined ? {} : { minimumColumnWidth }), repeatColumns: Object.freeze(repeats) });
5727
5749
  }
5750
+ /** Resolve identities against this table's captured selection, without consulting a grid or opening its rows. */
5751
+ function repeatedColumns(policy, columns) {
5752
+ if (typeof policy !== "object")
5753
+ return Object.freeze([]);
5754
+ const selected = new Set();
5755
+ for (const selector of policy.repeatColumns ?? []) {
5756
+ let position;
5757
+ if (typeof selector === "number")
5758
+ position = selector;
5759
+ else {
5760
+ position = columns.findIndex(column => column.key === selector);
5761
+ if (position < 0 || columns.some((column, index) => index !== position && column.key === selector))
5762
+ throw new TypeError("repeatColumns requires an unambiguous selected column key: " + selector);
5763
+ }
5764
+ if (position >= columns.length)
5765
+ throw new RangeError("repeatColumns index exceeds the declared columns.");
5766
+ if (selected.has(position))
5767
+ throw new TypeError("repeatColumns selects the same column more than once.");
5768
+ selected.add(position);
5769
+ }
5770
+ return Object.freeze([...selected].sort((left, right) => left - right));
5771
+ }
5728
5772
  function settings(input, document = false) {
5729
5773
  const configuration = { ...capturePdfOptions(input) };
5730
5774
  configuration.booleanText = captureBooleanText(configuration.booleanText);
@@ -5826,18 +5870,78 @@ function settings(input, document = false) {
5826
5870
  }
5827
5871
  const maxImageWorkingBytes = options.limits?.maxImageWorkingBytes;
5828
5872
  return { options: { ...options, paragraphStyles }, paragraphStyles, page, margins, fontSize, padding,
5873
+ repeatedColumns: document ? Object.freeze([]) : repeatedColumns(options.wideTable, columns),
5829
5874
  limits: { ...limits, ...(maxImageWorkingBytes === undefined ? {} : { maxImageWorkingBytes }) }, budget };
5830
5875
  }
5831
5876
  const _exports = Object.freeze({ positive: _m57.positive, color: _m57.color, presentation: _m57.presentation, pdfOptionFields: pdfOptionFields, pdfLimitFields: pdfLimitFields, capturePdfOptions: capturePdfOptions, capturePdfLimits: capturePdfLimits, captureWideTable: captureWideTable, settings: settings });
5832
- _modules.set("87a3335ede8f46b6e42f2c03e68f3df802321aa23c52dc4cdfb11165529a5270", _exports);
5877
+ _modules.set("4a089607f7cbe50e13d4382d1cc4e5f6ce32c5773bbec2df84178710f54d9a38", _exports);
5878
+ return _exports;
5879
+ })();
5880
+
5881
+ const _m60 = _modules.get("e3d39f39aebcbaf063fd8221df0d9cb5902ad2545a9d9e474bb59d47f15e2c01") ?? (() => {
5882
+ /** @internal One type byte, an eight-byte offset/container number and a two-byte generation/index. */
5883
+ const pdfXrefEntryBytes = 11;
5884
+ function unsigned(bytes, offset, value, width) {
5885
+ if (!Number.isSafeInteger(value) || value < 0 || value >= 2 ** (width * 8))
5886
+ throw new RangeError("Invalid PDF cross-reference field.");
5887
+ // Bitwise shifts truncate to 32 bits. Arithmetic preserves every supported byte offset.
5888
+ for (let index = width - 1; index >= 0; index--) {
5889
+ bytes[offset + index] = value % 256;
5890
+ value = Math.floor(value / 256);
5891
+ }
5892
+ }
5893
+ /** @internal Stream a complete single-section xref, including its own ordinary-object entry.
5894
+ * A defined member index means that the location is an object-stream number rather than a byte offset. */
5895
+ function* pdfXrefChunks(locations, indices) {
5896
+ if (locations.length !== indices.length)
5897
+ throw new Error("PDF cross-reference locations must align.");
5898
+ const perChunk = Math.floor(32768 / pdfXrefEntryBytes);
5899
+ for (let first = 0; first < locations.length; first += perChunk) {
5900
+ const count = Math.min(perChunk, locations.length - first), bytes = new Uint8Array(count * pdfXrefEntryBytes);
5901
+ for (let index = 0; index < count; index++) {
5902
+ const id = first + index, position = index * pdfXrefEntryBytes, location = locations[id], member = indices.at(id);
5903
+ if (location === undefined)
5904
+ throw new Error("PDF contains unwritten objects.");
5905
+ bytes[position] = id === 0 ? 0 : member === undefined ? 1 : 2;
5906
+ unsigned(bytes, position + 1, location, 8);
5907
+ unsigned(bytes, position + 9, id === 0 ? 65535 : member ?? 0, 2);
5908
+ }
5909
+ yield bytes;
5910
+ }
5911
+ }
5912
+ const _exports = Object.freeze({ pdfXrefEntryBytes: pdfXrefEntryBytes, pdfXrefChunks: pdfXrefChunks });
5913
+ _modules.set("e3d39f39aebcbaf063fd8221df0d9cb5902ad2545a9d9e474bb59d47f15e2c01", _exports);
5833
5914
  return _exports;
5834
5915
  })();
5835
5916
 
5836
- const _m59 = _modules.get("5424d3dd13b6ba1c76052de820b3d99e9bac24c012ea36e41b04fd99c779ee8c") ?? (() => {
5917
+ const _m59 = _modules.get("e716b8b1da464094622f5f671518493c78e63ff22a029d61544d2d193b63ce8f") ?? (() => {
5837
5918
  const { checkAbort, withAbort, pause, taskYieldDue } = _m4;
5838
5919
 
5839
5920
  const { OfficeIMOError } = _m2;
5840
5921
 
5922
+ const { pdfXrefChunks, pdfXrefEntryBytes } = _m60;
5923
+
5924
+ const compactObjectCount = 256, compactObjectBytes = 32768;
5925
+ const compactIndexChunkEntries = 4096;
5926
+ /** Lazy Uint16 chunks store compact membership; untouched zero slots denote ordinary objects. */
5927
+ class PdfCompactIndices {
5928
+ count;
5929
+ chunks = [];
5930
+ constructor(count) {
5931
+ this.count = count;
5932
+ }
5933
+ get length() { return this.count; }
5934
+ reserve() { this.count++; }
5935
+ set(id, member) {
5936
+ const chunk = this.chunks[Math.floor(id / compactIndexChunkEntries)] ??= new Uint16Array(compactIndexChunkEntries);
5937
+ // The current batch cap permits indices 0..255; adding one preserves index 255 as 256.
5938
+ chunk[id % compactIndexChunkEntries] = member + 1;
5939
+ }
5940
+ at(id) {
5941
+ const encoded = this.chunks[Math.floor(id / compactIndexChunkEntries)]?.[id % compactIndexChunkEntries] ?? 0;
5942
+ return encoded ? encoded - 1 : undefined;
5943
+ }
5944
+ }
5841
5945
  function pdfNumber(value) {
5842
5946
  if (!Number.isFinite(value) || Math.abs(value) > 1e9)
5843
5947
  throw new RangeError("PDF coordinates and metrics must be finite and bounded.");
@@ -5854,25 +5958,33 @@ function unicodeHex(text) {
5854
5958
  }
5855
5959
  return hex;
5856
5960
  }
5857
- /** @internal Forward-only PDF objects. Only xref offsets and page references survive a completed page. */
5961
+ /** @internal Forward-only PDF objects. Completed objects retain only their xref location. */
5858
5962
  class PdfObjects {
5859
5963
  sink;
5860
5964
  signal;
5861
5965
  maxBytes;
5966
+ compressObjects;
5862
5967
  offsets = [0];
5968
+ // A defined index changes the corresponding full-width offset into an object-stream number.
5969
+ // Membership chunks are allocated only when a compact member needs their ID range.
5970
+ compactIndices;
5971
+ compactBatch;
5972
+ compactArena;
5973
+ compactUnavailable = false;
5863
5974
  encoder = new TextEncoder();
5864
5975
  buffer = new Uint8Array(32768);
5865
5976
  buffered = 0;
5866
5977
  bytes = 0;
5867
- constructor(sink, signal, maxBytes = Number.MAX_SAFE_INTEGER) {
5978
+ constructor(sink, signal, maxBytes = Number.MAX_SAFE_INTEGER, compressObjects = false) {
5868
5979
  this.sink = sink;
5869
5980
  this.signal = signal;
5870
5981
  this.maxBytes = maxBytes;
5982
+ this.compressObjects = compressObjects;
5871
5983
  }
5872
- reserve() { this.offsets.push(undefined); return this.offsets.length - 1; }
5984
+ reserve() { this.offsets.push(undefined); this.compactIndices?.reserve(); return this.offsets.length - 1; }
5873
5985
  async raw(bytes) {
5874
5986
  checkAbort(this.signal);
5875
- if (this.bytes + bytes.length > this.maxBytes)
5987
+ if (!Number.isSafeInteger(this.bytes + bytes.length) || this.bytes + bytes.length > this.maxBytes)
5876
5988
  throw new OfficeIMOError("RESOURCE_LIMIT", "maxOutputBytes exceeded.");
5877
5989
  this.bytes += bytes.length;
5878
5990
  for (let offset = 0; offset < bytes.length;) {
@@ -5881,21 +5993,139 @@ class PdfObjects {
5881
5993
  offset += n;
5882
5994
  this.buffered += n;
5883
5995
  if (this.buffered === this.buffer.length)
5884
- await this.flush();
5996
+ await this.flushBytes();
5885
5997
  }
5886
5998
  }
5887
5999
  async text(text) { await this.raw(this.encoder.encode(text)); }
5888
6000
  async flush() {
6001
+ await this.flushCompact();
6002
+ await this.flushBytes();
6003
+ }
6004
+ /** Publish completed page bytes without forcing a partial structure container to end. */
6005
+ async flushBytes() {
5889
6006
  if (this.buffered) {
5890
6007
  const bytes = this.buffer.subarray(0, this.buffered);
5891
6008
  await withAbort(Promise.resolve(this.sink.write(bytes)), this.signal);
5892
- this.buffer = new Uint8Array(32768);
6009
+ // The sink borrows this view until acceptance; failed or cancelled writes must not reuse it.
5893
6010
  this.buffered = 0;
5894
6011
  }
5895
6012
  if (taskYieldDue())
5896
6013
  await pause();
5897
6014
  checkAbort(this.signal);
5898
6015
  }
6016
+ /** @internal Append only when an existing compact batch can accept a member without async work. */
6017
+ tryCompactObject(id, body) {
6018
+ checkAbort(this.signal);
6019
+ this.validateObject(id);
6020
+ const batch = this.compactBatch;
6021
+ if (!batch || !this.compressObjects || this.compactUnavailable || typeof CompressionStream !== "function" ||
6022
+ body.length > compactObjectBytes || batch.ids.length + 1 >= compactObjectCount)
6023
+ return false;
6024
+ const indexBytes = String(id).length + String(batch.bodyBytes).length + 2;
6025
+ const written = this.encodeCompactBody(body, batch.bodyBytes, compactObjectBytes - batch.indexBytes - indexBytes - batch.bodyBytes - 2);
6026
+ if (written === undefined)
6027
+ return false;
6028
+ this.storeCompactBody(batch, id, written);
6029
+ return true;
6030
+ }
6031
+ /** Small logical structure values share one bounded object-stream container. Other callers keep
6032
+ * ordinary objects; unavailable deflate preserves the classic representation before packing starts. */
6033
+ async compactObject(id, body) {
6034
+ checkAbort(this.signal);
6035
+ this.validateObject(id);
6036
+ if (!this.compressObjects || this.compactUnavailable || body.length > compactObjectBytes)
6037
+ return this.object(id, body);
6038
+ if (typeof CompressionStream !== "function") {
6039
+ if (this.compactIndices)
6040
+ throw new Error("PDF object compression became unavailable.");
6041
+ this.compactUnavailable = true;
6042
+ return this.object(id, body);
6043
+ }
6044
+ const firstIndexBytes = String(id).length + 4;
6045
+ let batch = this.compactBatch;
6046
+ const indexBytes = String(id).length + String(batch?.bodyBytes ?? 0).length + 2;
6047
+ let written = batch && batch.ids.length < compactObjectCount ? this.encodeCompactBody(body, batch.bodyBytes, compactObjectBytes - batch.indexBytes - indexBytes - batch.bodyBytes - 2) : undefined;
6048
+ if (batch && written === undefined) {
6049
+ // Partial encodings only touch the uncommitted suffix. Flush the committed prefix and retry
6050
+ // the whole string so a multibyte scalar is never split between containers.
6051
+ await this.flushCompact();
6052
+ batch = undefined;
6053
+ checkAbort(this.signal);
6054
+ }
6055
+ if (!batch) {
6056
+ written = this.encodeCompactBody(body, 0, compactObjectBytes - firstIndexBytes - 1);
6057
+ if (written === undefined)
6058
+ return this.object(id, body);
6059
+ let compressor;
6060
+ // Probe before selecting the compact representation. Later batches need no idle native
6061
+ // codec while they accumulate, including while ordinary page streams are compressed.
6062
+ if (!this.compactIndices) {
6063
+ try {
6064
+ compressor = new CompressionStream("deflate");
6065
+ }
6066
+ catch {
6067
+ this.compactUnavailable = true;
6068
+ return this.object(id, body);
6069
+ }
6070
+ }
6071
+ batch = { id: this.reserve(), compressor, ids: [], bodyOffsets: [], bodyBytes: 0, indexBytes: 1 };
6072
+ this.compactIndices ??= new PdfCompactIndices(this.offsets.length);
6073
+ this.compactBatch = batch;
6074
+ }
6075
+ this.storeCompactBody(batch, id, written);
6076
+ if (batch.ids.length === compactObjectCount)
6077
+ await this.flushCompact();
6078
+ }
6079
+ storeCompactBody(batch, id, written) {
6080
+ this.offsets[id] = batch.id;
6081
+ this.compactIndices.set(id, batch.ids.length);
6082
+ batch.indexBytes += String(id).length + String(batch.bodyBytes).length + 2;
6083
+ batch.ids.push(id);
6084
+ batch.bodyOffsets.push(batch.bodyBytes);
6085
+ this.compactArena[batch.bodyBytes + written] = 10;
6086
+ batch.bodyBytes += written + 1;
6087
+ }
6088
+ /** An incomplete encoding leaves only scratch bytes beyond the committed batch prefix. */
6089
+ encodeCompactBody(body, offset, available) {
6090
+ if (available < 0)
6091
+ return undefined;
6092
+ const destination = (this.compactArena ??= new Uint8Array(compactObjectBytes)).subarray(offset, offset + available);
6093
+ if (typeof this.encoder.encodeInto === "function") {
6094
+ const result = this.encoder.encodeInto(body, destination);
6095
+ return result.read === body.length ? result.written : undefined;
6096
+ }
6097
+ // Preserve TextEncoder implementations that only expose encode().
6098
+ const bytes = this.encoder.encode(body);
6099
+ if (bytes.length > available)
6100
+ return undefined;
6101
+ destination.set(bytes);
6102
+ return bytes.length;
6103
+ }
6104
+ async flushCompact() {
6105
+ const batch = this.compactBatch;
6106
+ if (!batch)
6107
+ return;
6108
+ this.compactBatch = undefined;
6109
+ let index = "";
6110
+ for (let member = 0; member < batch.ids.length; member++)
6111
+ index += batch.ids[member] + " " + batch.bodyOffsets[member] + " ";
6112
+ const header = this.encoder.encode(index + "\n"), count = batch.ids.length;
6113
+ // Keep the index separate from the arena. Reuse waits for the compressed read or all raw
6114
+ // writes below, so later members cannot overwrite a borrowed batch body.
6115
+ const body = this.compactArena.subarray(0, batch.bodyBytes);
6116
+ batch.ids.length = 0;
6117
+ batch.bodyOffsets.length = 0;
6118
+ if (batch.compressor) {
6119
+ await this.compressedStream(batch.id, body, "/Type /ObjStm /N " + count + " /First " + header.length, batch.compressor, header);
6120
+ }
6121
+ else {
6122
+ this.start(batch.id);
6123
+ await this.text(batch.id + " 0 obj\n<< /Length " + (header.length + body.length) + " /Type /ObjStm /N " + count + " /First " + header.length + " >>\nstream\n");
6124
+ await this.raw(header);
6125
+ await this.raw(body);
6126
+ await this.text("\nendstream\nendobj\n");
6127
+ }
6128
+ }
5899
6129
  async object(id, body) {
5900
6130
  this.start(id);
5901
6131
  if (typeof body === "string") {
@@ -5919,9 +6149,12 @@ class PdfObjects {
5919
6149
  }
5920
6150
  await this.text(chunk + "\nendobj\n");
5921
6151
  }
5922
- start(id) {
5923
- if (!Number.isInteger(id) || id <= 0 || id >= this.offsets.length || this.offsets[id] !== undefined)
6152
+ validateObject(id) {
6153
+ if (!Number.isSafeInteger(id) || id <= 0 || id >= this.offsets.length || this.offsets[id] !== undefined)
5924
6154
  throw new Error("Invalid PDF object state.");
6155
+ }
6156
+ start(id) {
6157
+ this.validateObject(id);
5925
6158
  this.offsets[id] = this.bytes;
5926
6159
  }
5927
6160
  async stream(id, source, dictionary = "", compression = true, owned = false) {
@@ -5942,7 +6175,15 @@ class PdfObjects {
5942
6175
  }
5943
6176
  // Verified internal producers can transfer immutable ownership; other byte sources retain the defensive snapshot.
5944
6177
  const sourceBytes = typeof source === "string" || owned ? bytes : new Uint8Array(bytes);
5945
- const input = new ReadableStream({ start(controller) { controller.enqueue(sourceBytes); controller.close(); } });
6178
+ await this.compressedStream(id, sourceBytes, dictionary, compressor);
6179
+ }
6180
+ async compressedStream(id, sourceBytes, dictionary, compressor, prefix) {
6181
+ const input = new ReadableStream({ start(controller) {
6182
+ if (prefix)
6183
+ controller.enqueue(prefix);
6184
+ controller.enqueue(sourceBytes);
6185
+ controller.close();
6186
+ } });
5946
6187
  const reader = input.pipeThrough(compressor).getReader(), lengthId = this.reserve();
5947
6188
  let length = 0, complete = false;
5948
6189
  try {
@@ -5967,10 +6208,14 @@ class PdfObjects {
5967
6208
  }
5968
6209
  }
5969
6210
  async finish(root, info) {
5970
- if (this.offsets.slice(1).some(offset => offset === undefined))
5971
- throw new Error("PDF contains unwritten objects.");
6211
+ await this.flushCompact();
6212
+ for (let id = 1; id < this.offsets.length; id++)
6213
+ if (this.offsets[id] === undefined)
6214
+ throw new Error("PDF contains unwritten objects.");
5972
6215
  if (this.bytes > 9999999999)
5973
6216
  throw new OfficeIMOError("RESOURCE_LIMIT", "PDF exceeds classic cross-reference offset capacity.");
6217
+ if (this.compactIndices)
6218
+ return this.finishCompact(root, info);
5974
6219
  const start = this.bytes;
5975
6220
  await this.text("xref\n0 " + this.offsets.length + "\n0000000000 65535 f \n");
5976
6221
  for (let i = 1; i < this.offsets.length; i++)
@@ -5978,13 +6223,27 @@ class PdfObjects {
5978
6223
  await this.text("trailer\n<< /Size " + this.offsets.length + " /Root " + root + " 0 R /Info " + info + " 0 R >>\nstartxref\n" + start + "\n%%EOF\n");
5979
6224
  await this.flush();
5980
6225
  }
6226
+ /** Xref payloads have a known length and are emitted in bounded chunks, without another copy
6227
+ * of the document's random-access location arrays or a whole-xref compression buffer. */
6228
+ async finishCompact(root, info) {
6229
+ const id = this.reserve(), start = this.bytes, length = this.offsets.length * pdfXrefEntryBytes;
6230
+ if (!Number.isSafeInteger(length))
6231
+ throw new OfficeIMOError("RESOURCE_LIMIT", "PDF cross-reference stream is too large.");
6232
+ this.start(id);
6233
+ await this.text(id + " 0 obj\n<< /Type /XRef /Size " + this.offsets.length + " /W [1 8 2] /Root " + root + " 0 R /Info " + info +
6234
+ " 0 R /Length " + length + " >>\nstream\n");
6235
+ for (const chunk of pdfXrefChunks(this.offsets, this.compactIndices))
6236
+ await this.raw(chunk);
6237
+ await this.text("\nendstream\nendobj\nstartxref\n" + start + "\n%%EOF\n");
6238
+ await this.flushBytes();
6239
+ }
5981
6240
  }
5982
6241
  const _exports = Object.freeze({ pdfNumber: pdfNumber, unicodeHex: unicodeHex, PdfObjects: PdfObjects });
5983
- _modules.set("5424d3dd13b6ba1c76052de820b3d99e9bac24c012ea36e41b04fd99c779ee8c", _exports);
6242
+ _modules.set("e716b8b1da464094622f5f671518493c78e63ff22a029d61544d2d193b63ce8f", _exports);
5984
6243
  return _exports;
5985
6244
  })();
5986
6245
 
5987
- const _m63 = _modules.get("1e169e6ecdeceff319b5da4bf01f4c653c1a3d9e8ad696b141bf8ac52d9f446c") ?? (() => {
6246
+ const _m64 = _modules.get("1e169e6ecdeceff319b5da4bf01f4c653c1a3d9e8ad696b141bf8ac52d9f446c") ?? (() => {
5988
6247
  /** @internal Bounded big-endian reader used for caller-provided TrueType programs. */
5989
6248
  class FontReader {
5990
6249
  bytes;
@@ -6014,8 +6273,8 @@ _modules.set("1e169e6ecdeceff319b5da4bf01f4c653c1a3d9e8ad696b141bf8ac52d9f446c",
6014
6273
  return _exports;
6015
6274
  })();
6016
6275
 
6017
- const _m64 = _modules.get("0534e48516ba3859978bb5f21d4ddfb17b4276c5e4650a7c7d6d384c25f6b681") ?? (() => {
6018
- const { align4 } = _m63;
6276
+ const _m65 = _modules.get("ecf6c6ab2f9c5f747338d0d59d9f2cae0b006d9d2a210bcb1545db1f046eb80c") ?? (() => {
6277
+ const { align4 } = _m64;
6019
6278
 
6020
6279
  const { checkAbort, pause, taskYieldDue } = _m4;
6021
6280
 
@@ -6235,16 +6494,16 @@ function* checksumSteps(bytes) {
6235
6494
  return sum;
6236
6495
  }
6237
6496
  const _exports = Object.freeze({ subsetTrueType: subsetTrueType, subsetTrueTypeCooperatively: subsetTrueTypeCooperatively });
6238
- _modules.set("0534e48516ba3859978bb5f21d4ddfb17b4276c5e4650a7c7d6d384c25f6b681", _exports);
6497
+ _modules.set("ecf6c6ab2f9c5f747338d0d59d9f2cae0b006d9d2a210bcb1545db1f046eb80c", _exports);
6239
6498
  return _exports;
6240
6499
  })();
6241
6500
 
6242
- const _m62 = _modules.get("77a2a9756cb6f59426300e1b3e601bd68acacdd40e6c30fbeb3cc99607c84891") ?? (() => {
6501
+ const _m63 = _modules.get("2e1fa1582af797386e2e2914c0a27237309b1692a3cc2be688f46590eb74480d") ?? (() => {
6243
6502
  const { NotSupportedError } = _m2;
6244
6503
 
6245
- const { FontReader } = _m63;
6504
+ const { FontReader } = _m64;
6246
6505
 
6247
- const { subsetTrueType, subsetTrueTypeCooperatively } = _m64;
6506
+ const { subsetTrueType, subsetTrueTypeCooperatively } = _m65;
6248
6507
 
6249
6508
  const { checkAbort, pause, taskYieldDue } = _m4;
6250
6509
 
@@ -6480,12 +6739,12 @@ function* parseFont(reader) {
6480
6739
  return { tables, glyphCount, units, ascent, descent, bbox, widths, offsets, canSubset, cmaps };
6481
6740
  }
6482
6741
  const _exports = Object.freeze({ TrueTypeFont: TrueTypeFont });
6483
- _modules.set("77a2a9756cb6f59426300e1b3e601bd68acacdd40e6c30fbeb3cc99607c84891", _exports);
6742
+ _modules.set("2e1fa1582af797386e2e2914c0a27237309b1692a3cc2be688f46590eb74480d", _exports);
6484
6743
  return _exports;
6485
6744
  })();
6486
6745
 
6487
- const _m61 = _modules.get("832d36356946811343532af7b630ef1c2016b6a48d0897282f4be774e20a1de2") ?? (() => {
6488
- const { TrueTypeFont } = _m62;
6746
+ const _m62 = _modules.get("d9c1509dff0538488752433e47cd0927ece5f93c559ad0e32dc56602dfd44596") ?? (() => {
6747
+ const { TrueTypeFont } = _m63;
6489
6748
 
6490
6749
  const { beginTask, checkAbort } = _m4;
6491
6750
 
@@ -6544,11 +6803,11 @@ class PdfFont {
6544
6803
  toBytes() { return fontProgram(this).bytes.slice(); }
6545
6804
  }
6546
6805
  const _exports = Object.freeze({ fontProgram: fontProgram, PdfFont: PdfFont });
6547
- _modules.set("832d36356946811343532af7b630ef1c2016b6a48d0897282f4be774e20a1de2", _exports);
6806
+ _modules.set("d9c1509dff0538488752433e47cd0927ece5f93c559ad0e32dc56602dfd44596", _exports);
6548
6807
  return _exports;
6549
6808
  })();
6550
6809
 
6551
- const _m66 = _modules.get("1ed4965a6e2963a91190baa8a58ada8ce0edde8fe653bcb6609002e872af0d61") ?? (() => {
6810
+ const _m67 = _modules.get("1ed4965a6e2963a91190baa8a58ada8ce0edde8fe653bcb6609002e872af0d61") ?? (() => {
6552
6811
  // Generated by scripts/pdf-widths.mjs from OfficeIMO.Pdf's Adobe AFM-derived metrics.
6553
6812
  const helveticaWidths = new Map([
6554
6813
  [32, [278, 278]],
@@ -6871,12 +7130,12 @@ _modules.set("1ed4965a6e2963a91190baa8a58ada8ce0edde8fe653bcb6609002e872af0d61",
6871
7130
  return _exports;
6872
7131
  })();
6873
7132
 
6874
- const _m65 = _modules.get("cb116ec8bc322f9c03d14c60009ac989d78b64636b24d77b44f5eece758dfbde") ?? (() => {
7133
+ const _m66 = _modules.get("59911f0fe023545e9e97521b268551078bdc4c5f303e446a13b7d52f905e8070") ?? (() => {
6875
7134
  const { OfficeIMOError } = _m2;
6876
7135
 
6877
- const { PdfFont, fontProgram } = _m61;
7136
+ const { PdfFont, fontProgram } = _m62;
6878
7137
 
6879
- const { helveticaWidths } = _m66;
7138
+ const { helveticaWidths } = _m67;
6880
7139
 
6881
7140
  const winAnsiExtras = new Map([0x20ac, 0, 0x201a, 0x192, 0x201e, 0x2026, 0x2020, 0x2021, 0x2c6, 0x2030, 0x160, 0x2039, 0x152, 0, 0x17d, 0, 0, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x2dc, 0x2122, 0x161, 0x203a, 0x153, 0, 0x17e, 0x178].map((cp, i) => [cp, i + 128]));
6882
7141
  /** @internal Called after scalar support succeeds when encoding a standard-font run. */
@@ -6936,21 +7195,22 @@ function selectFont(fonts, bold, italic) {
6936
7195
  return { font, syntheticBold: !!font && bold && !exact, syntheticItalic: !!font && italic && !exact };
6937
7196
  }
6938
7197
  const _exports = Object.freeze({ standardCode: standardCode, resolveScalar: resolveScalar, validateFonts: validateFonts, selectFont: selectFont });
6939
- _modules.set("cb116ec8bc322f9c03d14c60009ac989d78b64636b24d77b44f5eece758dfbde", _exports);
7198
+ _modules.set("59911f0fe023545e9e97521b268551078bdc4c5f303e446a13b7d52f905e8070", _exports);
6940
7199
  return _exports;
6941
7200
  })();
6942
7201
 
6943
- const _m60 = _modules.get("1b9b0585e9faa850e57fc123c307e79711fd1fb6e877b9f14dff1995a019d5b4") ?? (() => {
7202
+ const _m61 = _modules.get("7da602b40c346a3838e75963f9a3f10c95ac5ce08a7b0a23b9d96f8898a01db7") ?? (() => {
6944
7203
  const { NotSupportedError, OfficeIMOError } = _m2;
6945
7204
 
6946
- const { fontProgram } = _m61;
7205
+ const { fontProgram } = _m62;
6947
7206
 
6948
- const { resolveScalar, selectFont, standardCode, validateFonts } = _m65;
7207
+ const { resolveScalar, selectFont, standardCode, validateFonts } = _m66;
6949
7208
 
6950
7209
  const { pdfNumber, unicodeHex } = _m59;
6951
7210
 
6952
7211
  const { checkAbort, pause, taskYieldDue } = _m4;
6953
7212
 
7213
+ const standardHexBytes = Object.freeze(Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, "0")));
6954
7214
  class PdfFontResource {
6955
7215
  index;
6956
7216
  bold;
@@ -7013,7 +7273,7 @@ class PdfFontResource {
7013
7273
  for (const char of text) {
7014
7274
  const cp = char.codePointAt(0);
7015
7275
  this.width(cp);
7016
- hex += (this.program ? this.mappings.get(cp).cid : standardCode(cp)).toString(16).padStart(this.program ? 4 : 2, "0");
7276
+ hex += this.program ? this.mappings.get(cp).cid.toString(16).padStart(4, "0") : standardHexBytes[standardCode(cp)];
7017
7277
  }
7018
7278
  return "<" + hex + ">";
7019
7279
  }
@@ -7148,11 +7408,11 @@ class PdfFontResources {
7148
7408
  dictionary() { return "<< " + this.resources.map(f => "/" + f.name + " " + f.object + " 0 R").join(" ") + " >>"; }
7149
7409
  }
7150
7410
  const _exports = Object.freeze({ PdfFontResource: PdfFontResource, PdfFontResources: PdfFontResources });
7151
- _modules.set("1b9b0585e9faa850e57fc123c307e79711fd1fb6e877b9f14dff1995a019d5b4", _exports);
7411
+ _modules.set("7da602b40c346a3838e75963f9a3f10c95ac5ce08a7b0a23b9d96f8898a01db7", _exports);
7152
7412
  return _exports;
7153
7413
  })();
7154
7414
 
7155
- const _m68 = _modules.get("4201fbf42dfbfff0db44c5296d810e8eb98e2be18116bac5c8dc4b6046f72e71") ?? (() => {
7415
+ const _m69 = _modules.get("253db2c0eab1f298fda61fb40a5ddaacbf6ad12a7408ee3d8c12d27f88e7ca27") ?? (() => {
7156
7416
  const { OfficeIMOError } = _m2;
7157
7417
 
7158
7418
  const { ExportCell, assertExportValue } = _m5;
@@ -7163,6 +7423,11 @@ const { isDate } = _m6;
7163
7423
 
7164
7424
  const { defaultBooleanText } = _m18;
7165
7425
 
7426
+ /** @internal Charge displayed characters: tabs paint four spaces, while CR/LF only separate lines.
7427
+ * Raw text remains authoritative for input limits and layout. Skip normalization when no text ceiling observes it. */
7428
+ function pdfBudgetText(text, budget) {
7429
+ return budget.limits.maxTextCharacters === undefined ? text : text.replace(/[\t\r\n]/g, character => character === "\t" ? " " : "");
7430
+ }
7166
7431
  function synchronousText(value, name) {
7167
7432
  if (typeof value === "string")
7168
7433
  return value;
@@ -7254,12 +7519,12 @@ function* wrapSteps(text, font, size, width, maxCharacters, maxLines, wrap) {
7254
7519
  }
7255
7520
  return lines;
7256
7521
  }
7257
- const _exports = Object.freeze({ synchronousText: synchronousText, displayText: displayText, wrapText: wrapText, wrapTextCooperatively: wrapTextCooperatively });
7258
- _modules.set("4201fbf42dfbfff0db44c5296d810e8eb98e2be18116bac5c8dc4b6046f72e71", _exports);
7522
+ const _exports = Object.freeze({ pdfBudgetText: pdfBudgetText, synchronousText: synchronousText, displayText: displayText, wrapText: wrapText, wrapTextCooperatively: wrapTextCooperatively });
7523
+ _modules.set("253db2c0eab1f298fda61fb40a5ddaacbf6ad12a7408ee3d8c12d27f88e7ca27", _exports);
7259
7524
  return _exports;
7260
7525
  })();
7261
7526
 
7262
- const _m70 = _modules.get("1a586388978acf7fd9edef2207a526d0d36336e55020e79c863580e612e9d775") ?? (() => {
7527
+ const _m71 = _modules.get("8be3fb029e08d100ce8ffcf50916d5ba7f7bc00d62156cc33815fd58554a9ed6") ?? (() => {
7263
7528
  const { NotSupportedError, OfficeIMOError } = _m2;
7264
7529
 
7265
7530
  const { checkAbort, pause, taskYieldDue, withAbort } = _m4;
@@ -7468,11 +7733,11 @@ async function wrapShapedPdfText(captured, fonts, size, width, settings, wrap) {
7468
7733
  return lines;
7469
7734
  }
7470
7735
  const _exports = Object.freeze({ wrapShapedPdfText: wrapShapedPdfText });
7471
- _modules.set("1a586388978acf7fd9edef2207a526d0d36336e55020e79c863580e612e9d775", _exports);
7736
+ _modules.set("8be3fb029e08d100ce8ffcf50916d5ba7f7bc00d62156cc33815fd58554a9ed6", _exports);
7472
7737
  return _exports;
7473
7738
  })();
7474
7739
 
7475
- const _m69 = _modules.get("b51711edc0702a2ed2cb63ed106ca8b53fcb5c281571cb495a29cb72d37241fe") ?? (() => {
7740
+ const _m70 = _modules.get("0a1c79b51ac9a164b86197239117df6497f45ca2892b423b1ec77a663ccc1c47") ?? (() => {
7476
7741
  const { NotSupportedError, OfficeIMOError } = _m2;
7477
7742
 
7478
7743
  const { copyExportLink } = _m7;
@@ -7481,21 +7746,30 @@ const { checkAbort, pause, taskYieldDue } = _m4;
7481
7746
 
7482
7747
  const { presentation, color } = _m55;
7483
7748
 
7484
- const { wrapShapedPdfText } = _m70;
7749
+ const { wrapShapedPdfText } = _m71;
7485
7750
 
7486
- const { PdfFont } = _m61;
7751
+ const { PdfFont } = _m62;
7487
7752
 
7488
- /** @internal A run list is a PDF presentation value, never an alternate shared table value model. */
7489
- function capturePdfText(value, base, settings, fonts, countEmpty = true) {
7490
- const input = typeof value === "string" ? [{ text: value }] : value;
7753
+ const { pdfBudgetText } = _m69;
7754
+
7755
+ /** @internal Callers supply an owned, validated, frozen base presentation. A run list is a PDF presentation value, never an alternate shared table value model. */
7756
+ function capturePdfText(value, base, settings, fonts, countEmpty = true, reserveBudget = true) {
7757
+ if (typeof value === "string") {
7758
+ if (value.length > settings.limits.maxCellCharacters)
7759
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxCellCharacters exceeded.");
7760
+ if (reserveBudget && (value.length || countEmpty))
7761
+ settings.budget.reserve(1, pdfBudgetText(value, settings.budget).length);
7762
+ return Object.freeze({ text: value, runs: Object.freeze([Object.freeze({ text: value, style: base })]) });
7763
+ }
7764
+ const input = value;
7491
7765
  if (!Array.isArray(input)) {
7492
7766
  if (input && typeof input.then === "function")
7493
7767
  void Promise.resolve(input).catch(() => { });
7494
7768
  throw new TypeError("PDF text must be a string or a synchronous array of text runs.");
7495
7769
  }
7496
- if (typeof value !== "string" && input.length > settings.limits.maxTextRuns)
7770
+ if (input.length > settings.limits.maxTextRuns)
7497
7771
  throw new OfficeIMOError("RESOURCE_LIMIT", "maxTextRuns exceeded.");
7498
- let characters = 0;
7772
+ let characters = 0, budgetCharacters = 0;
7499
7773
  const runs = [];
7500
7774
  for (const run of input) {
7501
7775
  if (!run || typeof run !== "object" || Object.keys(run).some(key => !["text", "bold", "italic", "color", "link", "font"].includes(key)))
@@ -7511,14 +7785,16 @@ function capturePdfText(value, base, settings, fonts, countEmpty = true) {
7511
7785
  characters += text.length;
7512
7786
  if (characters > settings.limits.maxCellCharacters)
7513
7787
  throw new OfficeIMOError("RESOURCE_LIMIT", "maxCellCharacters exceeded.");
7788
+ if (reserveBudget)
7789
+ budgetCharacters += pdfBudgetText(text, settings.budget).length;
7514
7790
  const style = presentation({ ...base, ...(bold === undefined ? {} : { bold }), ...(italic === undefined ? {} : { italic }), ...(color === undefined ? {} : { color }) });
7515
7791
  if (settings.options.tagged && link !== undefined && text.length && !text.trim())
7516
7792
  throw new TypeError("Tagged PDF inline links require nonempty displayed text.");
7517
7793
  runs.push(Object.freeze({ text, style, ...(font === undefined ? {} : { font }), ...(link === undefined ? {} : { link: copyExportLink(link) }) }));
7518
7794
  }
7519
7795
  // Reserve before allocating a joined rich-text value or retaining it in a kept paragraph chain.
7520
- if (characters || countEmpty)
7521
- settings.budget.reserve(1, characters);
7796
+ if (reserveBudget && (characters || countEmpty))
7797
+ settings.budget.reserve(1, budgetCharacters);
7522
7798
  return Object.freeze({ text: runs.map(run => run.text).join(""), runs: Object.freeze(runs) });
7523
7799
  }
7524
7800
  /** @internal Greedy wrapping over the continuous text stream, preserving run emphasis and URI geometry. */
@@ -7527,8 +7803,39 @@ async function wrapPdfText(captured, fonts, size, width, settings, wrap = true)
7527
7803
  return wrapShapedPdfText(captured, fonts, size, width, settings, wrap);
7528
7804
  const { signal } = settings.options, { text, runs } = captured;
7529
7805
  checkAbort(signal);
7530
- const faces = runs.map(run => fonts.select(run.style.bold, run.style.italic, run.font));
7531
- const fallback = fonts.select(), lines = [];
7806
+ // Keep font-selection order while deferring a single-run face array until wrapping needs it.
7807
+ const single = runs.length === 1 ? runs[0] : undefined;
7808
+ const singleFace = single && fonts.select(single.style.bold, single.style.italic, single.font);
7809
+ const selectedFaces = singleFace ? undefined : runs.map(run => fonts.select(run.style.bold, run.style.italic, run.font));
7810
+ const fallback = fonts.select();
7811
+ // Short fitting runs need no per-character layout arrays. Longer text keeps the existing
7812
+ // cooperative checkpoints; controls or the first overflowing advance use the general path.
7813
+ if (single && text.length > 0 && text.length < 4096) {
7814
+ const run = single, font = singleFace;
7815
+ let widthSoFar = 0, fits = true;
7816
+ for (let offset = 0; offset < text.length;) {
7817
+ const scalar = text.codePointAt(offset);
7818
+ if (scalar === 9 || scalar === 10 || scalar === 13) {
7819
+ fits = false;
7820
+ break;
7821
+ }
7822
+ const advance = font.width(scalar) * size / 1000;
7823
+ if (advance > width + .001 || widthSoFar + advance > width + .001) {
7824
+ fits = false;
7825
+ break;
7826
+ }
7827
+ widthSoFar += advance;
7828
+ offset += scalar > 0xffff ? 2 : 1;
7829
+ }
7830
+ if (fits) {
7831
+ if (settings.limits.maxRowLines < 1)
7832
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxRowLines exceeded.");
7833
+ return [{ text, width: widthSoFar, segments: [{ text, width: widthSoFar, font,
7834
+ ...(run.style.color === undefined ? {} : { color: run.style.color }), ...(run.link ? { link: run.link } : {}) }],
7835
+ lineHeight: font.lineHeight(size), ascent: Math.max(0, (font.program?.ascent ?? 800) * size / 1000) }];
7836
+ }
7837
+ }
7838
+ const faces = selectedFaces ?? [singleFace], lines = [];
7532
7839
  let chars = [], advances = [], owners = [], measured = 0, breakAt = -1;
7533
7840
  let runIndex = 0, runEnd = runs[0]?.text.length ?? 0, scanned = 0;
7534
7841
  const emit = (count) => {
@@ -7622,23 +7929,21 @@ async function wrapPdfText(captured, fonts, size, width, settings, wrap = true)
7622
7929
  return lines;
7623
7930
  }
7624
7931
  const _exports = Object.freeze({ capturePdfText: capturePdfText, wrapPdfText: wrapPdfText });
7625
- _modules.set("b51711edc0702a2ed2cb63ed106ca8b53fcb5c281571cb495a29cb72d37241fe", _exports);
7932
+ _modules.set("0a1c79b51ac9a164b86197239117df6497f45ca2892b423b1ec77a663ccc1c47", _exports);
7626
7933
  return _exports;
7627
7934
  })();
7628
7935
 
7629
- const _m71 = _modules.get("58480ded0056f234aea5e0c26637308eea7708e97ccc9987242b62c4dbc4f9b8") ?? (() => {
7936
+ const _m72 = _modules.get("9a88773878eacc51df9f05bb5ee90cc2b683b083ebea8fb54375092301388e96") ?? (() => {
7630
7937
  const { OfficeIMOError } = _m2;
7631
7938
 
7632
- const { wrapPdfText } = _m69;
7939
+ const { wrapPdfText } = _m70;
7633
7940
 
7634
7941
  /** Plan without opening a source. Exact column widths never shrink in band mode. */
7635
7942
  function planTableBands(widths, settings) {
7636
7943
  const policy = settings.options.wideTable;
7637
7944
  if (typeof policy !== "object")
7638
7945
  return undefined;
7639
- const available = settings.page.width - settings.margins.left - settings.margins.right, repeats = policy.repeatColumns ?? [];
7640
- if (repeats.some(index => index >= widths.length))
7641
- throw new RangeError("repeatColumns index exceeds the declared columns.");
7946
+ const available = settings.page.width - settings.margins.left - settings.margins.right, repeats = settings.repeatedColumns;
7642
7947
  const repeated = new Set(repeats), rest = widths.map((_, index) => index).filter(index => !repeated.has(index));
7643
7948
  const prefix = repeats.reduce((sum, index) => sum + widths[index], 0);
7644
7949
  if (prefix > available + .001)
@@ -7715,11 +8020,11 @@ function alignBandBlocks(bands, settings) {
7715
8020
  cells: row.cells.map(cell => ({ ...cell, height: heights.slice(index, index + (cell.rowSpan ?? 1)).reduce((sum, value) => sum + value, 0) })) })));
7716
8021
  }
7717
8022
  const _exports = Object.freeze({ planTableBands: planTableBands, projectBandRows: projectBandRows, alignBandBlocks: alignBandBlocks });
7718
- _modules.set("58480ded0056f234aea5e0c26637308eea7708e97ccc9987242b62c4dbc4f9b8", _exports);
8023
+ _modules.set("9a88773878eacc51df9f05bb5ee90cc2b683b083ebea8fb54375092301388e96", _exports);
7719
8024
  return _exports;
7720
8025
  })();
7721
8026
 
7722
- const _m67 = _modules.get("49d84273bffe31099c2dd7f47ecb6d4a7de7b6efd0d3b7e3e02761bcb3646c9c") ?? (() => {
8027
+ const _m68 = _modules.get("07d2da8d8b93f12f172a48b97c1807e485555cf608e2eaa5b7610aa91d4a5305") ?? (() => {
7723
8028
  const { ExportCell } = _m5;
7724
8029
 
7725
8030
  const { copyExportLink } = _m7;
@@ -7730,11 +8035,11 @@ const { createTotals } = _m12;
7730
8035
 
7731
8036
  const { presentation, positive } = _m55;
7732
8037
 
7733
- const { displayText } = _m68;
8038
+ const { displayText, pdfBudgetText } = _m69;
7734
8039
 
7735
- const { capturePdfText, wrapPdfText } = _m69;
8040
+ const { capturePdfText, wrapPdfText } = _m70;
7736
8041
 
7737
- const { planTableBands, projectBandRows, alignBandBlocks } = _m71;
8042
+ const { planTableBands, projectBandRows, alignBandBlocks } = _m72;
7738
8043
 
7739
8044
  class PdfTableLayout {
7740
8045
  settings;
@@ -7747,11 +8052,13 @@ class PdfTableLayout {
7747
8052
  totals;
7748
8053
  repeatedColumns;
7749
8054
  structuredBandRows = new WeakMap();
8055
+ /** Plain/alternate ordinary-data defaults, validated only when a column first needs them. */
8056
+ dataPresentations = [];
7750
8057
  constructor(settings, fonts) {
7751
8058
  this.settings = settings;
7752
8059
  this.fonts = fonts;
7753
8060
  const { options, padding, fontSize, page, margins } = settings, columns = options.columns, available = page.width - margins.left - margins.right;
7754
- this.repeatedColumns = new Set(typeof options.wideTable === "object" ? options.wideTable.repeatColumns : []);
8061
+ this.repeatedColumns = new Set(settings.repeatedColumns);
7755
8062
  let digit;
7756
8063
  if (options.columnWidths && options.columnWidths.length !== columns.length)
7757
8064
  throw new RangeError("columnWidths must declare one point width per column.");
@@ -7792,13 +8099,22 @@ class PdfTableLayout {
7792
8099
  this.headings = headings;
7793
8100
  this.totals = createTotals(columns, options.footer?.totals);
7794
8101
  }
7795
- async cell(value, first, span, row, style) {
8102
+ async cell(value, first, span, row, style, ordinaryData = false) {
7796
8103
  const { options, padding, fontSize, budget } = this.settings, column = options.columns[first];
7797
8104
  const own = value instanceof ExportCell ? value.presentation : undefined;
7798
8105
  const link = value instanceof ExportCell && value.link ? copyExportLink(value.link) : undefined;
7799
- const combined = presentation({ ...(column.alignment === undefined ? {} : { alignment: column.alignment }),
7800
- ...(column.wrapText === undefined ? {} : { wrapText: column.wrapText }), ...style, ...own });
7801
- const font = this.fonts.select(combined.bold, combined.italic), width = this.widths.slice(first, first + span).reduce((n, w) => n + w, 0);
8106
+ const alternate = ordinaryData && row % 2 && options.alternateRowColor ? options.alternateRowColor : undefined;
8107
+ const slot = first * 2 + (alternate ? 1 : 0), reusable = ordinaryData && own === undefined;
8108
+ let combined = reusable ? this.dataPresentations[slot] : undefined;
8109
+ if (!combined) {
8110
+ const rowStyle = ordinaryData ? alternate ? { background: alternate } : {} : style;
8111
+ combined = presentation({ ...(column.alignment === undefined ? {} : { alignment: column.alignment }),
8112
+ ...(column.wrapText === undefined ? {} : { wrapText: column.wrapText }), ...rowStyle, ...own });
8113
+ // Validate only the first reached default; an authored cell may override invalid column defaults.
8114
+ if (reusable)
8115
+ this.dataPresentations[slot] = combined;
8116
+ }
8117
+ const font = this.fonts.select(combined.bold, combined.italic), width = span === 1 ? this.widths[first] : this.widths.slice(first, first + span).reduce((n, w) => n + w, 0);
7802
8118
  const context = { rowIndex: row, columnIndex: first, column }, raw = value instanceof ExportCell ? value.value : value;
7803
8119
  let text;
7804
8120
  if (options.formatRuns && row >= 0 && !(value instanceof ExportCell && value.text !== undefined)) {
@@ -7817,10 +8133,11 @@ class PdfTableLayout {
7817
8133
  throw new TypeError("Tagged PDF cell links require nonempty displayed text.");
7818
8134
  if (link && captured.runs.some(run => run.link))
7819
8135
  throw new TypeError("A PDF cell link cannot be combined with inline run links.");
8136
+ const budgetText = pdfBudgetText(captured.text, budget);
7820
8137
  if (this.bands)
7821
- budget.release(1, captured.text.length);
8138
+ budget.release(1, budgetText.length);
7822
8139
  else
7823
- budget.cell(captured.text, captured.text.length);
8140
+ budget.cell(budgetText, budgetText.length);
7824
8141
  const lines = await wrapPdfText(captured, this.fonts, fontSize, width - padding * 2, this.settings, combined.wrapText !== false);
7825
8142
  return { first, span, width, font, style: combined, lineHeight: lines.reduce((height, line) => Math.max(height, line.lineHeight), font.lineHeight(fontSize)),
7826
8143
  ...(link ? { link } : {}), ...(this.bands ? { captured } : {}),
@@ -7919,8 +8236,8 @@ class PdfTableLayout {
7919
8236
  const value = values[column], raw = value instanceof ExportCell ? value.value : value;
7920
8237
  if (!footer)
7921
8238
  this.totals[column].accept(raw);
7922
- const style = footer ? options.footerPresentation ?? {} : index % 2 && options.alternateRowColor ? { background: options.alternateRowColor } : {};
7923
- cells.push(await this.cell(value, column, 1, index, style));
8239
+ const cell = await this.cell(value, column, 1, index, footer ? options.footerPresentation ?? {} : undefined, !footer);
8240
+ cells.push(!footer && options.columns[column].rowHeader ? { ...cell, rowHeader: true } : cell);
7924
8241
  }
7925
8242
  return this.row(cells);
7926
8243
  }
@@ -7934,11 +8251,11 @@ class PdfTableLayout {
7934
8251
  }
7935
8252
  }
7936
8253
  const _exports = Object.freeze({ PdfTableLayout: PdfTableLayout });
7937
- _modules.set("49d84273bffe31099c2dd7f47ecb6d4a7de7b6efd0d3b7e3e02761bcb3646c9c", _exports);
8254
+ _modules.set("07d2da8d8b93f12f172a48b97c1807e485555cf608e2eaa5b7610aa91d4a5305", _exports);
7938
8255
  return _exports;
7939
8256
  })();
7940
8257
 
7941
- const _m73 = _modules.get("fc3b4b4c188e35a35e2451638421293be30b545b691151f1605295d87223a981") ?? (() => {
8258
+ const _m74 = _modules.get("67ad5f4adbd6bc0dddafe5cf82638d46d150237f4ff0bee15c0ace652d5095f4") ?? (() => {
7942
8259
  const { OfficeIMOError } = _m2;
7943
8260
 
7944
8261
  const { checkAbort } = _m4;
@@ -7982,7 +8299,7 @@ class PdfTableBandFlow {
7982
8299
  await this.flush();
7983
8300
  }
7984
8301
  async row(row, allowFirstFragment = false) {
7985
- const { padding, options } = this.layout.settings, minimumLines = this.layout.minimumRowLines(row), minimumHeight = this.layout.minimumRowHeight(row);
8302
+ const { padding, fontSize, options } = this.layout.settings, minimumLines = this.layout.minimumRowLines(row), minimumHeight = this.layout.minimumRowHeight(row);
7986
8303
  if (minimumHeight > this.painter.firstFullCapacity + .001 || minimumHeight > this.painter.continuationCapacity + .001)
7987
8304
  throw new RangeError("Repeated PDF identifiers must fit intact below the first and continued band headings/context.");
7988
8305
  // Keep ordinary rows intact when they fit fresh. A kept heading/caption can deliberately
@@ -8008,16 +8325,29 @@ class PdfTableBandFlow {
8008
8325
  const lines = Math.min(row.lines - first, Math.floor((this.capacity - this.height - padding * 2 + .001) / row.lineHeight));
8009
8326
  if (lines < 1)
8010
8327
  throw new RangeError("PDF page cannot fit a table line below horizontal band headings.");
8011
- const paintedLines = Math.max(lines, minimumLines), height = paintedLines * row.lineHeight + padding * 2;
8328
+ // Reserve one shared logical fragment, but paint only each band's visible cell geometry.
8329
+ const reservedLines = Math.max(lines, minimumLines), height = reservedLines * row.lineHeight + padding * 2;
8012
8330
  const projected = await this.layout.bandRows([row]);
8013
- const fragments = projected.map((rows, index) => [{ ...rows[0], lines: paintedLines, height,
8014
- cells: rows[0].cells.map(cell => {
8015
- const source = this.layout.bands[index].columns[cell.first];
8016
- const visible = this.layout.repeatedColumn(source) ? cell.lines : cell.lines.slice(first, first + lines);
8017
- const { height: _height, ...plain } = cell;
8018
- return { ...plain, lines: visible, ...(first > 0 && this.layout.repeatedColumn(source) ? { semanticArtifact: true } : {}) };
8019
- }) }]);
8020
- await this.accept({ rows: fragments, height, count: 1, completed: first + lines >= row.lines ? [row] : [] });
8331
+ const exhaustedBands = [];
8332
+ const fragments = projected.map((rows, index) => {
8333
+ let remaining = false;
8334
+ const cells = rows[0].cells.map(cell => {
8335
+ const source = this.layout.bands[index].columns[cell.first];
8336
+ const repeated = this.layout.repeatedColumn(source), visible = repeated ? cell.lines : cell.lines.slice(first, first + lines);
8337
+ if (!repeated && (visible.length > 0 || cell.link !== undefined))
8338
+ remaining = true;
8339
+ const { height: _height, ...plain } = cell;
8340
+ return { ...plain, lines: visible,
8341
+ lineHeight: visible.reduce((value, line) => Math.max(value, line.lineHeight), cell.font.lineHeight(fontSize)),
8342
+ ...(first > 0 && repeated ? { semanticArtifact: true } : {}) };
8343
+ });
8344
+ const fragmentLines = Math.max(1, ...cells.map(cell => cell.lines.length));
8345
+ const lineHeight = Math.max(this.layout.lineHeight, ...cells.filter(cell => cell.lines.length > 0).map(cell => cell.lineHeight));
8346
+ // Never omit an initial/new row, a structured block, or a nonrepeated link obligation.
8347
+ exhaustedBands.push(first > 0 && !remaining);
8348
+ return [{ ...rows[0], cells, lines: fragmentLines, lineHeight, height: fragmentLines * lineHeight + padding * 2 }];
8349
+ });
8350
+ await this.accept({ rows: fragments, height, count: 1, completed: first + lines >= row.lines ? [row] : [], exhaustedBands });
8021
8351
  first += lines;
8022
8352
  if (first < row.lines)
8023
8353
  await this.flush();
@@ -8029,7 +8359,7 @@ class PdfTableBandFlow {
8029
8359
  throw new OfficeIMOError("RESOURCE_LIMIT", "A structured PDF block exceeds maxTableWindowRows.");
8030
8360
  for (const row of rows)
8031
8361
  await this.painter.prepareRow?.(row);
8032
- await this.accept({ rows: projected, height, count: rows.length, completed: rows });
8362
+ await this.accept({ rows: projected, height, count: rows.length, completed: rows, exhaustedBands: projected.map(() => false) });
8033
8363
  }
8034
8364
  async keptRows(rows, allowFirstFragment = false) {
8035
8365
  const height = rows.reduce((sum, row) => sum + row.height, 0), fits = height <= this.painter.continuationCapacity + .001;
@@ -8043,6 +8373,8 @@ class PdfTableBandFlow {
8043
8373
  return;
8044
8374
  for (let band = 0; band < this.layout.bands.length; band++) {
8045
8375
  checkAbort(this.layout.settings.options.signal);
8376
+ if (!this.firstWindow && this.entries.length > 0 && this.entries.every(entry => entry.exhaustedBands[band]))
8377
+ continue;
8046
8378
  await this.painter.paint(band, this.headings[band], this.entries.flatMap(entry => entry.rows[band]), this.firstWindow ? this.caption : this.continuation, this.firstWindow, band === 0);
8047
8379
  }
8048
8380
  for (const entry of this.entries)
@@ -8056,11 +8388,11 @@ class PdfTableBandFlow {
8056
8388
  }
8057
8389
  }
8058
8390
  const _exports = Object.freeze({ PdfTableBandFlow: PdfTableBandFlow });
8059
- _modules.set("fc3b4b4c188e35a35e2451638421293be30b545b691151f1605295d87223a981", _exports);
8391
+ _modules.set("67ad5f4adbd6bc0dddafe5cf82638d46d150237f4ff0bee15c0ace652d5095f4", _exports);
8060
8392
  return _exports;
8061
8393
  })();
8062
8394
 
8063
- const _m74 = _modules.get("2d9fcf56989ea33b92c7f79cc6e1b06b7f5a82cf421559ce3e2f6b67813a17c3") ?? (() => {
8395
+ const _m75 = _modules.get("b52424ed74721dce3a2621456888fe1c6af0490627063e56f690df9abcb1dfff") ?? (() => {
8064
8396
  /** @internal Source-cell identities survive page fragments and horizontal band projections.
8065
8397
  * Only column headers and still-owned row objects remain reachable from this table owner. */
8066
8398
  class PdfTableStructure {
@@ -8070,6 +8402,8 @@ class PdfTableStructure {
8070
8402
  cells = new WeakMap();
8071
8403
  rows = new WeakMap();
8072
8404
  columnHeaders = [];
8405
+ /** Ordinary cells without row headers share immutable dictionary references, bounded by column count. */
8406
+ ordinaryAttributes = [];
8073
8407
  headerCount = 0;
8074
8408
  headersPrepared = false;
8075
8409
  constructor(structure, table, headers) {
@@ -8110,19 +8444,30 @@ class PdfTableStructure {
8110
8444
  return row.cells.map(cell => this.cells.get(cell));
8111
8445
  const rowId = this.structure.element("TR", parent);
8112
8446
  this.rows.set(row, rowId);
8113
- const ids = [];
8114
- let rowHeaderIdentifier;
8115
- // Allocating in source-column order preserves the record's logical reading order.
8447
+ const headers = row.cells.map((cell, index) => rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex);
8448
+ // Allocate in source order, then resolve every row header before associating even earlier data cells.
8449
+ // Generated summary labels override detail roles so numeric subtotal cells never become row headers.
8450
+ const ids = row.cells.map((cell, index) => {
8451
+ const id = this.structure.element(headers[index] ? "TH" : "TD", rowId);
8452
+ this.cells.set(cell, id);
8453
+ return id;
8454
+ });
8455
+ const rowHeaders = [];
8456
+ for (let index = 0; index < ids.length; index++)
8457
+ if (headers[index])
8458
+ rowHeaders.push(await this.structure.identifier(ids[index]));
8116
8459
  for (let index = 0; index < row.cells.length; index++) {
8117
- const cell = row.cells[index], isRowHeader = index === rowHeaderIndex;
8460
+ const cell = row.cells[index];
8461
+ if (!rowHeaders.length && cell.span === 1 && (cell.rowSpan ?? 1) === 1) {
8462
+ const attributes = this.ordinaryAttributes[cell.first] ??=
8463
+ await this.structure.attributeReference(this.attributeDictionary(cell, this.associations(cell)));
8464
+ this.structure.setAttributes(ids[index], attributes);
8465
+ continue;
8466
+ }
8118
8467
  const associations = this.associations(cell);
8119
- if (rowHeaderIdentifier !== undefined && !isRowHeader)
8120
- associations.push(rowHeaderIdentifier);
8121
- const id = this.structure.element(isRowHeader ? "TH" : "TD", rowId, this.attributes(cell, associations, isRowHeader ? "Row" : undefined));
8122
- this.cells.set(cell, id);
8123
- ids.push(id);
8124
- if (isRowHeader)
8125
- rowHeaderIdentifier = await this.structure.identifier(id);
8468
+ if (!headers[index])
8469
+ associations.push(...rowHeaders);
8470
+ this.structure.setAttributes(ids[index], this.attributes(cell, associations, headers[index] ? "Row" : undefined));
8126
8471
  }
8127
8472
  return ids;
8128
8473
  }
@@ -8148,17 +8493,20 @@ class PdfTableStructure {
8148
8493
  return [...headers].sort((left, right) => left.order - right.order).map(header => header.identifier);
8149
8494
  }
8150
8495
  attributes(cell, headers, scope) {
8151
- return " /A << /O /Table" + (scope === undefined ? "" : " /Scope /" + scope) +
8496
+ return " /A " + this.attributeDictionary(cell, headers, scope);
8497
+ }
8498
+ attributeDictionary(cell, headers, scope) {
8499
+ return "<< /O /Table" + (scope === undefined ? "" : " /Scope /" + scope) +
8152
8500
  (cell.span > 1 ? " /ColSpan " + cell.span : "") + ((cell.rowSpan ?? 1) > 1 ? " /RowSpan " + cell.rowSpan : "") +
8153
8501
  (headers.length ? " /Headers [" + headers.map(id => "(" + id + ")").join(" ") + "]" : "") + " >>";
8154
8502
  }
8155
8503
  }
8156
8504
  const _exports = Object.freeze({ PdfTableStructure: PdfTableStructure });
8157
- _modules.set("2d9fcf56989ea33b92c7f79cc6e1b06b7f5a82cf421559ce3e2f6b67813a17c3", _exports);
8505
+ _modules.set("b52424ed74721dce3a2621456888fe1c6af0490627063e56f690df9abcb1dfff", _exports);
8158
8506
  return _exports;
8159
8507
  })();
8160
8508
 
8161
- const _m75 = _modules.get("c5f5a4892d01de11258381c667d72e97f69410f87c8ddb307be3a7bbb3d6857a") ?? (() => {
8509
+ const _m76 = _modules.get("09c712096a1028af340e275d5a273e870546413797e71ed709657ad0482ea170") ?? (() => {
8162
8510
  const { OfficeIMOError } = _m2;
8163
8511
 
8164
8512
  const { pdfNumber, unicodeHex } = _m59;
@@ -8200,11 +8548,11 @@ function linkAnnotation(link, x, bottom, width, height, maxBytes, structParent,
8200
8548
  (link.tooltip === undefined ? "" : " /Contents <feff" + unicodeHex(link.tooltip) + ">") + " >>";
8201
8549
  }
8202
8550
  const _exports = Object.freeze({ linkAnnotation: linkAnnotation });
8203
- _modules.set("c5f5a4892d01de11258381c667d72e97f69410f87c8ddb307be3a7bbb3d6857a", _exports);
8551
+ _modules.set("09c712096a1028af340e275d5a273e870546413797e71ed709657ad0482ea170", _exports);
8204
8552
  return _exports;
8205
8553
  })();
8206
8554
 
8207
- const _m76 = _modules.get("93a48e0c780b5ff91a51fef40169622179fe47eb3f3bd159989ce92f83b57b80") ?? (() => {
8555
+ const _m77 = _modules.get("c68d18d668366fb9b96d1b53c79dc6305f84cb83c05e4942fcf1cdf96ed1a73f") ?? (() => {
8208
8556
  const { OfficeIMOError } = _m2;
8209
8557
 
8210
8558
  const { unicodeHex } = _m59;
@@ -8249,11 +8597,11 @@ function captureSection(block, settings) {
8249
8597
  ...(pageNumbers === undefined ? {} : { pageNumbers }) });
8250
8598
  }
8251
8599
  const _exports = Object.freeze({ captureBookmark: captureBookmark, captureSection: captureSection });
8252
- _modules.set("93a48e0c780b5ff91a51fef40169622179fe47eb3f3bd159989ce92f83b57b80", _exports);
8600
+ _modules.set("c68d18d668366fb9b96d1b53c79dc6305f84cb83c05e4942fcf1cdf96ed1a73f", _exports);
8253
8601
  return _exports;
8254
8602
  })();
8255
8603
 
8256
- const _m77 = _modules.get("31017b0c80e6e8ace64ed268298a4f155b992b295138be6ad0bffe8d9365710d") ?? (() => {
8604
+ const _m78 = _modules.get("a66257a32f03d958aa57be4de9da7f80b708cebca26b5cc6404de0ee11bfe052") ?? (() => {
8257
8605
  const { settings } = _m55;
8258
8606
 
8259
8607
  /** @internal Every section derives from captured document defaults, never the preceding section. */
@@ -8268,11 +8616,11 @@ function sectionSettings(base, section) {
8268
8616
  return { ...base, page: derived.page, margins: derived.margins, options };
8269
8617
  }
8270
8618
  const _exports = Object.freeze({ sectionSettings: sectionSettings });
8271
- _modules.set("31017b0c80e6e8ace64ed268298a4f155b992b295138be6ad0bffe8d9365710d", _exports);
8619
+ _modules.set("a66257a32f03d958aa57be4de9da7f80b708cebca26b5cc6404de0ee11bfe052", _exports);
8272
8620
  return _exports;
8273
8621
  })();
8274
8622
 
8275
- const _m72 = _modules.get("d0559c6c6f06cb5c1ba8d2494280159aa12c9514566498ca28b1a4a7fefd92db") ?? (() => {
8623
+ const _m73 = _modules.get("a7fca40cb8c75af206111c90db36839b4648982beeb4179efda0ddd1ee366210") ?? (() => {
8276
8624
  const { OfficeIMOError } = _m2;
8277
8625
 
8278
8626
  const { checkAbort } = _m4;
@@ -8281,19 +8629,19 @@ const { pdfNumber } = _m59;
8281
8629
 
8282
8630
  const { color } = _m55;
8283
8631
 
8284
- const { PdfTableBandFlow } = _m73;
8632
+ const { PdfTableBandFlow } = _m74;
8285
8633
 
8286
- const { PdfTableStructure } = _m74;
8634
+ const { PdfTableStructure } = _m75;
8287
8635
 
8288
- const { wrapText, wrapTextCooperatively, synchronousText } = _m68;
8636
+ const { wrapText, wrapTextCooperatively, synchronousText, pdfBudgetText } = _m69;
8289
8637
 
8290
- const { linkAnnotation } = _m75;
8638
+ const { linkAnnotation } = _m76;
8291
8639
 
8292
8640
  const { unicodeHex } = _m59;
8293
8641
 
8294
- const { captureSection, captureBookmark } = _m76;
8642
+ const { captureSection, captureBookmark } = _m77;
8295
8643
 
8296
- const { sectionSettings } = _m77;
8644
+ const { sectionSettings } = _m78;
8297
8645
 
8298
8646
  /** @internal One page of drawing commands and O(page count) references, never the complete report body. */
8299
8647
  class PdfPages {
@@ -8431,8 +8779,9 @@ class PdfPages {
8431
8779
  const lineActualText = !this.structure && line.actualText !== undefined && line.actualText.length > 0;
8432
8780
  if (lineActualText)
8433
8781
  this.add("/Span << /ActualText <FEFF" + unicodeHex(line.actualText) + "> >> BDC\n");
8434
- const marks = new Map();
8782
+ let marks;
8435
8783
  if (line.actualText !== undefined && this.structure && element !== undefined) {
8784
+ marks = new Map();
8436
8785
  // Allocate MCIDs/Link children in logical order, then paint the independently positioned visual order.
8437
8786
  for (const segment of [...line.segments].sort((a, b) => (a.logicalStart ?? 0) - (b.logicalStart ?? 0))) {
8438
8787
  const owner = segment.link ? this.structure.link(element, segment.link) : element;
@@ -8440,7 +8789,7 @@ class PdfPages {
8440
8789
  }
8441
8790
  }
8442
8791
  for (const segment of line.segments) {
8443
- const registered = marks.get(segment), owner = registered?.owner ?? (segment.link && this.structure && element !== undefined ? this.structure.link(element, segment.link) : element);
8792
+ const registered = marks?.get(segment), owner = registered?.owner ?? (segment.link && this.structure && element !== undefined ? this.structure.link(element, segment.link) : element);
8444
8793
  if (segment.glyphs) {
8445
8794
  const font = segment.font, n = pdfNumber, shear = font.syntheticItalic ? .213 : 0;
8446
8795
  let cursor = x, command = "q " + this.rgb(segment.color ?? "111827") + " rg " + this.rgb(segment.color ?? "111827") + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
@@ -8474,7 +8823,7 @@ class PdfPages {
8474
8823
  decoration(text, x, y, width) {
8475
8824
  if (!text)
8476
8825
  return;
8477
- this.settings.budget.cell(text);
8826
+ this.settings.budget.cell(pdfBudgetText(text, this.settings.budget));
8478
8827
  const font = this.fonts.select(), lines = wrapText(text, font, this.settings.fontSize, width, this.settings.limits.maxCellCharacters, 1, false);
8479
8828
  this.text(lines[0].text, font, this.settings.fontSize, x, y);
8480
8829
  }
@@ -8535,9 +8884,7 @@ class PdfPages {
8535
8884
  }
8536
8885
  const headers = preparedHeadings ?? (tableHeadings && this.layout ? this.activeHeadings ??= await this.layout.headers() : []), headerHeight = headers.reduce((n, h) => n + h.height, 0), continuation = tableHeadings && this.layout ? this.continuationCaption : undefined;
8537
8886
  if (continuation?.lines.length) {
8538
- if (this.continuationCaptionPaints++ > 0)
8539
- this.settings.budget.cell(continuation.text.text);
8540
- else
8887
+ if (this.continuationCaptionPaints++ === 0)
8541
8888
  this.tableCaptionOwner = this.captionAnnotations(continuation, this.tableCaptionOwner);
8542
8889
  await this.paragraphs([continuation], headerHeight + lineHeight + this.settings.padding * 2, true, { artifact: true, ...(this.tableCaptionOwner === undefined ? {} : { annotationParent: this.tableCaptionOwner }) });
8543
8890
  }
@@ -8558,7 +8905,7 @@ class PdfPages {
8558
8905
  // Charge physical repeats without recapturing callbacks or making them semantic duplicates.
8559
8906
  for (const cell of header.cells)
8560
8907
  if (!this.bandCellBudget && this.paintedHeaderBudgetCells.has(cell.source ?? cell))
8561
- this.settings.budget.cell(cell.lines.map(line => line.text).join(""));
8908
+ this.settings.budget.cell(this.settings.budget.limits.maxTextCharacters === undefined ? "" : cell.lines.map(line => line.text).join(""));
8562
8909
  const elements = this.tableStructure ? header.cells.map(cell => this.tableStructure.owner(cell.source ?? cell)) : undefined;
8563
8910
  const repeated = header.cells.map(cell => this.paintedHeaderCells.has(cell.source ?? cell));
8564
8911
  this.draw(header, 0, header.lines, elements, repeated);
@@ -8579,7 +8926,8 @@ class PdfPages {
8579
8926
  const { padding, fontSize } = this.settings, n = pdfNumber, height = lineCount * row.lineHeight + padding * 2;
8580
8927
  for (const [index, cell] of row.cells.entries()) {
8581
8928
  if (this.bandCellBudget)
8582
- this.settings.budget.cell((cell.height === undefined ? cell.lines.slice(firstLine, firstLine + lineCount) : cell.lines).map(line => line.text).join(""));
8929
+ this.settings.budget.cell(this.settings.budget.limits.maxTextCharacters === undefined ? "" :
8930
+ (cell.height === undefined ? cell.lines.slice(firstLine, firstLine + lineCount) : cell.lines).map(line => line.text).join(""));
8583
8931
  const x = this.layout.lefts[cell.first], cellHeight = cell.height ?? height;
8584
8932
  if (cell.style.background)
8585
8933
  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"));
@@ -8655,7 +9003,7 @@ class PdfPages {
8655
9003
  async paragraph(text, style = {}, size = this.settings.fontSize, paginate = true, headingLevel) {
8656
9004
  await this.ensureStarted();
8657
9005
  const { margins, page, limits } = this.settings, font = this.fonts.select(style.bold, style.italic), lineHeight = font.lineHeight(size);
8658
- this.settings.budget.cell(text);
9006
+ this.settings.budget.cell(pdfBudgetText(text, this.settings.budget));
8659
9007
  const lines = await wrapTextCooperatively(text, font, size, page.width - margins.left - margins.right, limits.maxCellCharacters, limits.maxRowLines, true, this.settings.options.signal);
8660
9008
  if (lineHeight > page.height - margins.top - margins.bottom)
8661
9009
  throw new RangeError("PDF page cannot fit a paragraph line at the selected font metrics.");
@@ -8698,6 +9046,8 @@ class PdfPages {
8698
9046
  if (keepTogether && visible.length)
8699
9047
  await this.reserveSpace(visible.reduce((height, paragraph) => height + paragraph.height, 0) + reservations.at(-1), "Kept PDF paragraph group");
8700
9048
  for (const [index, paragraph] of visible.entries()) {
9049
+ if (paragraph.budgetOnPaint)
9050
+ this.settings.budget.cell(pdfBudgetText(paragraph.text.text, this.settings.budget));
8701
9051
  if (paragraph.keepTogether || paragraph.keepWithNext)
8702
9052
  await this.reserveSpace(paragraph.height + reservations[index], "Kept PDF paragraph chain");
8703
9053
  const { margins, page } = this.settings;
@@ -8750,10 +9100,11 @@ class PdfPages {
8750
9100
  /** The generated summary label is a row heading; no localized text/style inference is used. */
8751
9101
  summary(row) { this.summaryRows.add(row); }
8752
9102
  /** Begin an independent table on the current page, retaining its headings on continuation pages.
8753
- * Group context uses captionArtifact: it stays visually complete without duplicating logical headings. */
8754
- async beginTable(layout, preparedHeadings, minimumDataHeight = layout.lineHeight + this.settings.padding * 2, caption, continuationCaption, headingsOnNewPageOnly = false, captionArtifact = false) {
9103
+ * Group context uses captionArtifact: it stays visually complete without duplicating logical headings.
9104
+ * An already-painted opening path only suppresses its artifact caption on that existing page. */
9105
+ async beginTable(layout, preparedHeadings, minimumDataHeight = layout.lineHeight + this.settings.padding * 2, caption, continuationCaption, headingsOnNewPageOnly = false, captionArtifact = false, openingContextAlreadyPainted = false) {
8755
9106
  if (layout.bands)
8756
- return this.beginBands(layout, preparedHeadings, minimumDataHeight, caption, continuationCaption, captionArtifact);
9107
+ return this.beginBands(layout, preparedHeadings, minimumDataHeight, caption, continuationCaption, captionArtifact, openingContextAlreadyPainted);
8757
9108
  await this.ensureStarted();
8758
9109
  this.layout = layout;
8759
9110
  this.paintedHeaderCells = new WeakSet();
@@ -8767,7 +9118,7 @@ class PdfPages {
8767
9118
  // Its own headings remain available when it moves or splits onto a fresh page.
8768
9119
  const initialHeadings = headingsOnNewPageOnly && this.bodyAdded && !this.structure ? [] : headings;
8769
9120
  const height = initialHeadings.reduce((n, row) => n + row.height, 0);
8770
- if (caption) {
9121
+ if (caption && !(captionArtifact && openingContextAlreadyPainted)) {
8771
9122
  await this.reserveSpace(caption.height + height + minimumDataHeight, "Kept PDF table caption and first data fragment");
8772
9123
  this.tableCaptionOwner = captionArtifact ? this.captionAnnotations(caption)
8773
9124
  : caption.lines.length ? this.structure?.element("Caption", this.tableElement) : undefined;
@@ -8789,7 +9140,7 @@ class PdfPages {
8789
9140
  this.dataTop = this.y;
8790
9141
  }
8791
9142
  /** Bind the bounded logical-window owner to the existing physical page painter. */
8792
- async beginBands(layout, preparedHeadings, minimumDataHeight, caption, continuation, captionArtifact) {
9143
+ async beginBands(layout, preparedHeadings, minimumDataHeight, caption, continuation, captionArtifact, openingContextAlreadyPainted) {
8793
9144
  await this.ensureStarted();
8794
9145
  const logicalHeadings = preparedHeadings ?? await layout.headers(), headings = await layout.bandRows(logicalHeadings, true);
8795
9146
  const headerHeight = headings[0].reduce((sum, row) => sum + row.height, 0), { page, margins, padding } = this.settings;
@@ -8798,13 +9149,15 @@ class PdfPages {
8798
9149
  const continuationCapacity = page.height - margins.top - margins.bottom - headerHeight - (continuation?.height ?? 0);
8799
9150
  if (continuationCapacity + .001 < layout.lineHeight + padding * 2)
8800
9151
  throw new RangeError("PDF band headings and continuation context leave no room for a data line.");
8801
- if (this.y - margins.bottom - headerHeight - (caption?.height ?? 0) + .001 < minimum)
9152
+ let openingContextPainted = captionArtifact && openingContextAlreadyPainted;
9153
+ if (this.y - margins.bottom - headerHeight - (openingContextPainted ? 0 : caption?.height ?? 0) + .001 < minimum) {
8802
9154
  await this.pageBreak();
8803
- let initialOffset = page.height - margins.top - this.y;
8804
- const firstCapacity = this.y - margins.bottom - headerHeight - (caption?.height ?? 0);
9155
+ openingContextPainted = false;
9156
+ }
9157
+ const firstCapacity = this.y - margins.bottom - headerHeight - (openingContextPainted ? 0 : caption?.height ?? 0);
8805
9158
  if (firstCapacity + .001 < minimum)
8806
9159
  throw new RangeError("PDF band caption and headings leave no room for a data line.");
8807
- let captionPaints = 0, continuationPaints = 0;
9160
+ let continuationPaints = 0;
8808
9161
  this.tableElement = this.structure?.element("Table", this.groupParent);
8809
9162
  this.paintedHeaderCells = new WeakSet();
8810
9163
  let captionElement = this.structure && caption?.lines.length ? captionArtifact ? this.captionAnnotations(caption)
@@ -8818,21 +9171,16 @@ class PdfPages {
8818
9171
  this.bandFlow = new PdfTableBandFlow(layout, headings, { firstCapacity, firstFullCapacity, continuationCapacity,
8819
9172
  prepareRow: async (row) => { await this.tableStructure?.prepareHeaders(); await this.rowElements(row); },
8820
9173
  completeRow: async (row) => { await this.tableStructure?.completeRow(row.source ?? row); },
8821
- moveFirstToFreshPage: async () => { await this.pageBreak(); initialOffset = 0; },
9174
+ moveFirstToFreshPage: async () => { await this.pageBreak(); openingContextPainted = false; },
8822
9175
  paint: async (band, headers, rows, currentCaption, firstWindow, firstBand) => {
8823
9176
  if (!(firstWindow && firstBand))
8824
9177
  await this.pageBreak();
8825
- if (firstWindow && !firstBand)
8826
- this.y -= initialOffset;
8827
9178
  const frame = layout.bands[band];
8828
9179
  this.layout = { lefts: frame.lefts, lineHeight: layout.lineHeight, headers: async () => headers };
8829
9180
  this.bandCellBudget = true;
8830
9181
  try {
8831
- if (currentCaption?.lines.length) {
8832
- const paints = firstWindow ? captionPaints++ : continuationPaints++;
8833
- if (paints > 0)
8834
- this.settings.budget.cell(currentCaption.text.text);
8835
- if (!firstWindow && paints === 0)
9182
+ if (currentCaption?.lines.length && !(firstWindow && firstBand && openingContextPainted)) {
9183
+ if (!firstWindow && continuationPaints++ === 0)
8836
9184
  captionElement = this.captionAnnotations(currentCaption, captionElement);
8837
9185
  const annotationParent = captionElement;
8838
9186
  await this.paragraphs([currentCaption], headerHeight + minimum, true, firstWindow && firstBand && !captionArtifact ? { role: "Caption", keepOpen: true, ...(captionElement === undefined ? {} : { owner: captionElement }) }
@@ -8936,7 +9284,7 @@ class PdfPages {
8936
9284
  this.annotations = [];
8937
9285
  this.commandBytes = 0;
8938
9286
  this.current = 0;
8939
- await this.objects.flush();
9287
+ await this.objects.flushBytes();
8940
9288
  }
8941
9289
  async finish() {
8942
9290
  if (this.bandFlow) {
@@ -8964,11 +9312,11 @@ class PdfPages {
8964
9312
  }
8965
9313
  }
8966
9314
  const _exports = Object.freeze({ PdfPages: PdfPages });
8967
- _modules.set("d0559c6c6f06cb5c1ba8d2494280159aa12c9514566498ca28b1a4a7fefd92db", _exports);
9315
+ _modules.set("a7fca40cb8c75af206111c90db36839b4648982beeb4179efda0ddd1ee366210", _exports);
8968
9316
  return _exports;
8969
9317
  })();
8970
9318
 
8971
- const _m79 = _modules.get("7a58e8ccb5164de51db14e39ca9695af6487c354df909509f0ae6bfac8ae3887") ?? (() => {
9319
+ const _m80 = _modules.get("7a58e8ccb5164de51db14e39ca9695af6487c354df909509f0ae6bfac8ae3887") ?? (() => {
8972
9320
  /** @internal Incremental PDF number tree: at most 64 entries/children per retained level. */
8973
9321
  class PdfParentTree {
8974
9322
  objects;
@@ -9031,15 +9379,38 @@ _modules.set("7a58e8ccb5164de51db14e39ca9695af6487c354df909509f0ae6bfac8ae3887",
9031
9379
  return _exports;
9032
9380
  })();
9033
9381
 
9034
- const _m78 = _modules.get("b37e74556d1c4d6d8617e6b585127f56635e2ea8e03105a026031f5d3adbce9e") ?? (() => {
9382
+ const _m79 = _modules.get("1c1828a3d6dfc2edda674566203e7aa8e97c984114b7928df13cb373859977d0") ?? (() => {
9035
9383
  const { OfficeIMOError } = _m2;
9036
9384
 
9037
9385
  const { checkAbort } = _m4;
9038
9386
 
9039
9387
  const { unicodeHex } = _m59;
9040
9388
 
9041
- const { PdfParentTree } = _m79;
9389
+ const { PdfParentTree } = _m80;
9042
9390
 
9391
+ /** Same-page marked content uses integer K; cross-page MCR and annotation OBJR stay explicit. */
9392
+ function structureChild(child) {
9393
+ return typeof child === "number" ? (child < 0 ? -child - 1 + " " : child + " 0 R ") : child + " ";
9394
+ }
9395
+ function structurePrefix(element) {
9396
+ return "<< /Type /StructElem /S /" + element.role + " /P " + element.parent + " 0 R" +
9397
+ (element.markedPage === undefined ? "" : " /Pg " + element.markedPage + " 0 R") +
9398
+ (element.identifier === undefined ? "" : " /ID (" + element.identifier + ")") + " /K [";
9399
+ }
9400
+ /** Keep the same bounded small-object representation for both completion paths. */
9401
+ function compactStructureBody(element, prefix) {
9402
+ const remaining = 32768 - prefix.length - element.attributes.length - 4;
9403
+ if (remaining < 0)
9404
+ return undefined;
9405
+ let children = "";
9406
+ for (const child of element.children) {
9407
+ const token = structureChild(child);
9408
+ if (children.length + token.length > remaining)
9409
+ return undefined;
9410
+ children += token;
9411
+ }
9412
+ return prefix + children + "]" + element.attributes + " >>";
9413
+ }
9043
9414
  /** A sorted name tree retains only a small open leaf and branch at each level. */
9044
9415
  class PdfStructureIds {
9045
9416
  objects;
@@ -9129,7 +9500,7 @@ class PdfStructure {
9129
9500
  checkAbort(this.settings.options.signal);
9130
9501
  if (++this.allocated > this.settings.limits.maxStructureElements)
9131
9502
  throw new OfficeIMOError("RESOURCE_LIMIT", "maxStructureElements exceeded.");
9132
- const id = this.objects.reserve(), element = { id, parent, role, children: [], attributes, linkIdentities: [] };
9503
+ const id = this.objects.reserve(), element = { id, parent, role, children: [], attributes };
9133
9504
  this.elements.set(id, element);
9134
9505
  const owner = this.elements.get(parent);
9135
9506
  // A continuation-only linked caption is discovered during painting, after rows may exist.
@@ -9140,6 +9511,20 @@ class PdfStructure {
9140
9511
  owner?.children.push(id);
9141
9512
  return id;
9142
9513
  }
9514
+ /** Attach resolved table associations while a source-ordered logical element is still open. */
9515
+ setAttributes(elementId, attributes) {
9516
+ const element = this.elements.get(elementId);
9517
+ if (!element)
9518
+ throw new Error("PDF structure attributes require an open logical owner.");
9519
+ element.attributes = attributes;
9520
+ }
9521
+ /** Write one immutable attribute dictionary. Its caller owns the bounded scope of reference reuse. */
9522
+ async attributeReference(dictionary) {
9523
+ checkAbort(this.settings.options.signal);
9524
+ const id = this.objects.reserve();
9525
+ await this.objects.object(id, dictionary);
9526
+ return " /A " + id + " 0 R";
9527
+ }
9143
9528
  /** Flat visual sections share the same logical Document and cumulative resource policy. */
9144
9529
  async beginSection() {
9145
9530
  await this.complete(this.section);
@@ -9173,7 +9558,8 @@ class PdfStructure {
9173
9558
  return existing;
9174
9559
  const id = this.element("Link", parent, alternativeText === undefined ? "" : " /Alt <feff" + unicodeHex(alternativeText) + ">");
9175
9560
  parents.set(parent, id);
9176
- this.elements.get(parent).linkIdentities.push(identity);
9561
+ const owner = this.elements.get(parent);
9562
+ (owner.linkIdentities ??= []).push(identity);
9177
9563
  return id;
9178
9564
  }
9179
9565
  /** Associate a native annotation in both directions: OBJR child and annotation ParentTree entry. */
@@ -9196,7 +9582,9 @@ class PdfStructure {
9196
9582
  throw new Error("Marked content requires an open logical owner.");
9197
9583
  const mcid = this.pageParents.length;
9198
9584
  this.pageParents.push(elementId);
9199
- element.children.push("<< /Type /MCR /Pg " + this.pageId + " 0 R /MCID " + mcid + " >>");
9585
+ element.markedPage ??= this.pageId;
9586
+ element.children.push(element.markedPage === this.pageId ? -(mcid + 1) :
9587
+ "<< /Type /MCR /Pg " + this.pageId + " 0 R /MCID " + mcid + " >>");
9200
9588
  return "/" + element.role + " << /MCID " + mcid + (actualText === undefined ? "" : " /ActualText <FEFF" + unicodeHex(actualText) + ">") + " >> BDC\n";
9201
9589
  }
9202
9590
  get pageDictionary() { return " /StructParents " + this.pageKey + " /Tabs /S"; }
@@ -9220,37 +9608,49 @@ class PdfStructure {
9220
9608
  if (!element)
9221
9609
  return;
9222
9610
  for (const child of element.children)
9223
- if (typeof child === "number" && this.elements.has(child))
9611
+ if (typeof child === "number" && child > 0 && !this.completeBuffered(child))
9224
9612
  await this.complete(child);
9225
9613
  checkAbort(this.settings.options.signal);
9226
- const prefix = "<< /Type /StructElem /S /" + element.role + " /P " + element.parent + " 0 R" +
9227
- (element.identifier === undefined ? "" : " /ID (" + element.identifier + ")") + " /K [";
9228
- const remaining = 32768 - prefix.length - element.attributes.length - 4;
9229
- let children = "", small = remaining >= 0;
9230
- if (small)
9231
- for (const child of element.children) {
9232
- const token = typeof child === "number" ? child + " 0 R " : child + " ";
9233
- if (children.length + token.length > remaining) {
9234
- small = false;
9235
- break;
9236
- }
9237
- children += token;
9238
- }
9614
+ const prefix = structurePrefix(element), body = compactStructureBody(element, prefix);
9239
9615
  // Most table cells/rows fit in one encoding. Large parents and alternatives remain streamed.
9240
- await this.objects.object(id, small ? prefix + children + "]" + element.attributes + " >>" : this.body(element));
9241
- for (const identity of element.linkIdentities) {
9242
- const parents = this.links.get(identity);
9243
- parents?.delete(id);
9244
- if (!parents?.size)
9245
- this.links.delete(identity);
9246
- }
9247
- this.elements.delete(id);
9248
- }
9249
- *body(element) {
9250
- yield "<< /Type /StructElem /S /" + element.role + " /P " + element.parent + " 0 R" +
9251
- (element.identifier === undefined ? "" : " /ID (" + element.identifier + ")") + " /K [";
9616
+ if (body !== undefined) {
9617
+ if (!this.objects.tryCompactObject(id, body))
9618
+ await this.objects.compactObject(id, body);
9619
+ }
9620
+ else
9621
+ await this.objects.object(id, this.body(element, prefix));
9622
+ this.releaseElement(element);
9623
+ }
9624
+ /** Close already-bufferable children without creating an async chain per leaf. A false result
9625
+ * leaves the current owner open for the existing awaited flush or ordinary-object path. */
9626
+ completeBuffered(id) {
9627
+ const element = this.elements.get(id);
9628
+ if (!element)
9629
+ return true;
9630
+ for (const child of element.children)
9631
+ if (typeof child === "number" && child > 0 && !this.completeBuffered(child))
9632
+ return false;
9633
+ checkAbort(this.settings.options.signal);
9634
+ const body = compactStructureBody(element, structurePrefix(element));
9635
+ if (body === undefined || !this.objects.tryCompactObject(id, body))
9636
+ return false;
9637
+ this.releaseElement(element);
9638
+ return true;
9639
+ }
9640
+ releaseElement(element) {
9641
+ if (element.linkIdentities)
9642
+ for (const identity of element.linkIdentities) {
9643
+ const parents = this.links.get(identity);
9644
+ parents?.delete(element.id);
9645
+ if (!parents?.size)
9646
+ this.links.delete(identity);
9647
+ }
9648
+ this.elements.delete(element.id);
9649
+ }
9650
+ *body(element, prefix) {
9651
+ yield prefix;
9252
9652
  for (const child of element.children)
9253
- yield typeof child === "number" ? child + " 0 R " : child + " ";
9653
+ yield structureChild(child);
9254
9654
  yield "]" + element.attributes + " >>";
9255
9655
  }
9256
9656
  async completeRow(cells) {
@@ -9287,11 +9687,11 @@ function graphicAlternative(value, settings) {
9287
9687
  return alternativeText;
9288
9688
  }
9289
9689
  const _exports = Object.freeze({ PdfStructure: PdfStructure, graphicAlternative: graphicAlternative });
9290
- _modules.set("b37e74556d1c4d6d8617e6b585127f56635e2ea8e03105a026031f5d3adbce9e", _exports);
9690
+ _modules.set("1c1828a3d6dfc2edda674566203e7aa8e97c984114b7928df13cb373859977d0", _exports);
9291
9691
  return _exports;
9292
9692
  })();
9293
9693
 
9294
- const _m80 = _modules.get("29578404bfc3df4d4b6b8036db67bd83212dbfe6182fadb62c55beb0584b5ca8") ?? (() => {
9694
+ const _m81 = _modules.get("52c78ca6833cee7e5a96b657e2c00172d550176daf2c95e742692f8416977bea") ?? (() => {
9295
9695
  const { OfficeIMOError } = _m2;
9296
9696
 
9297
9697
  const { checkAbort } = _m4;
@@ -9351,22 +9751,22 @@ class PdfOutlines {
9351
9751
  }
9352
9752
  }
9353
9753
  const _exports = Object.freeze({ PdfOutlines: PdfOutlines });
9354
- _modules.set("29578404bfc3df4d4b6b8036db67bd83212dbfe6182fadb62c55beb0584b5ca8", _exports);
9754
+ _modules.set("52c78ca6833cee7e5a96b657e2c00172d550176daf2c95e742692f8416977bea", _exports);
9355
9755
  return _exports;
9356
9756
  })();
9357
9757
 
9358
- const _m58 = _modules.get("50d54cd77023f226b6e16a5fd158bb587e58b21cbf9b731e51b093c4bc32afac") ?? (() => {
9758
+ const _m58 = _modules.get("eb2c981b4568b33deca2137956ace31ea621b6a6287755ec234336d0a7c23cfc") ?? (() => {
9359
9759
  const { PdfObjects, unicodeHex } = _m59;
9360
9760
 
9361
- const { PdfFontResources } = _m60;
9761
+ const { PdfFontResources } = _m61;
9362
9762
 
9363
- const { PdfTableLayout } = _m67;
9763
+ const { PdfTableLayout } = _m68;
9364
9764
 
9365
- const { PdfPages } = _m72;
9765
+ const { PdfPages } = _m73;
9366
9766
 
9367
- const { PdfStructure } = _m78;
9767
+ const { PdfStructure } = _m79;
9368
9768
 
9369
- const { PdfOutlines } = _m80;
9769
+ const { PdfOutlines } = _m81;
9370
9770
 
9371
9771
  /** One resource/catalog owner shared by table convenience exports and composed documents. */
9372
9772
  class PdfWriteSession {
@@ -9383,7 +9783,7 @@ class PdfWriteSession {
9383
9783
  info;
9384
9784
  constructor(sink, settings, table = false) {
9385
9785
  this.settings = settings;
9386
- this.objects = new PdfObjects(sink, settings.options.signal, settings.budget.limits.maxOutputBytes);
9786
+ this.objects = new PdfObjects(sink, settings.options.signal, settings.budget.limits.maxOutputBytes, settings.options.compression !== false);
9387
9787
  this.root = this.objects.reserve();
9388
9788
  this.parent = this.objects.reserve();
9389
9789
  this.resources = this.objects.reserve();
@@ -9418,11 +9818,11 @@ class PdfWriteSession {
9418
9818
  }
9419
9819
  }
9420
9820
  const _exports = Object.freeze({ PdfWriteSession: PdfWriteSession });
9421
- _modules.set("50d54cd77023f226b6e16a5fd158bb587e58b21cbf9b731e51b093c4bc32afac", _exports);
9821
+ _modules.set("eb2c981b4568b33deca2137956ace31ea621b6a6287755ec234336d0a7c23cfc", _exports);
9422
9822
  return _exports;
9423
9823
  })();
9424
9824
 
9425
- const _m54 = _modules.get("b236032efbf4bb6015fe9a546f753fac23127635b62114367e3c67776de83f5b") ?? (() => {
9825
+ const _m54 = _modules.get("98eb735e985f873ed0ffc628449a20d1f3bb729a87b6d6b3099b6f308438fcb5") ?? (() => {
9426
9826
  const { BlobByteSink, withDestination } = _m3;
9427
9827
 
9428
9828
  const { beginTask, checkAbort, consumeRows, pause, taskYieldDue } = _m4;
@@ -9487,11 +9887,11 @@ async function writePdfTo(rows, destination, configuration) {
9487
9887
  });
9488
9888
  }
9489
9889
  const _exports = Object.freeze({ writePdf: writePdf, writePdfTo: writePdfTo });
9490
- _modules.set("b236032efbf4bb6015fe9a546f753fac23127635b62114367e3c67776de83f5b", _exports);
9890
+ _modules.set("98eb735e985f873ed0ffc628449a20d1f3bb729a87b6d6b3099b6f308438fcb5", _exports);
9491
9891
  return _exports;
9492
9892
  })();
9493
9893
 
9494
- const _m84 = _modules.get("55eee1527c670926d154776e46828f4a0f8ae4df5c041a62ff851925b349f9db") ?? (() => {
9894
+ const _m85 = _modules.get("749d1ec5422c0087787f525ef42e3b8d3a94d2b70eb5e42d2e3723a870777ad6") ?? (() => {
9495
9895
  const { NotSupportedError, OfficeIMOError } = _m2;
9496
9896
 
9497
9897
  const { checkAbort, pause, taskYieldDue, withAbort } = _m4;
@@ -9755,16 +10155,16 @@ function paeth(left, up, upperLeft) {
9755
10155
  return a <= b && a <= c ? left : b <= c ? up : upperLeft;
9756
10156
  }
9757
10157
  const _exports = Object.freeze({ pngPixels: pngPixels });
9758
- _modules.set("55eee1527c670926d154776e46828f4a0f8ae4df5c041a62ff851925b349f9db", _exports);
10158
+ _modules.set("749d1ec5422c0087787f525ef42e3b8d3a94d2b70eb5e42d2e3723a870777ad6", _exports);
9759
10159
  return _exports;
9760
10160
  })();
9761
10161
 
9762
- const _m83 = _modules.get("f7e93a79ae9f66b8bbc83d3534c0f5b8df6e85447494ee0532d86f7c53aa7746") ?? (() => {
10162
+ const _m84 = _modules.get("7dca2d9ca5c43893abdaf86df5b1bcb1f3de3d5d33532d082fdfe04711999d21") ?? (() => {
9763
10163
  const { NotSupportedError, OfficeIMOError } = _m2;
9764
10164
 
9765
10165
  const { checkAbort, pause, taskYieldDue } = _m4;
9766
10166
 
9767
- const { pngPixels } = _m84;
10167
+ const { pngPixels } = _m85;
9768
10168
 
9769
10169
  /** Shared document image resources; source objects are captured on first consumption. */
9770
10170
  class PdfDocumentImages {
@@ -9889,11 +10289,11 @@ function jpegSize(bytes) {
9889
10289
  throw new TypeError("JPEG image has no complete frame and scan.");
9890
10290
  }
9891
10291
  const _exports = Object.freeze({ PdfDocumentImages: PdfDocumentImages });
9892
- _modules.set("f7e93a79ae9f66b8bbc83d3534c0f5b8df6e85447494ee0532d86f7c53aa7746", _exports);
10292
+ _modules.set("7dca2d9ca5c43893abdaf86df5b1bcb1f3de3d5d33532d082fdfe04711999d21", _exports);
9893
10293
  return _exports;
9894
10294
  })();
9895
10295
 
9896
- const _m85 = _modules.get("7904dbe183e98e39e18538292dfe007832e8efe39b812f98f1ec5bc96d4e5459") ?? (() => {
10296
+ const _m86 = _modules.get("3290c84fdf80725af802f497d947bc088aa8d93d9db0a33f6f829f9153aa6fd6") ?? (() => {
9897
10297
  const { OfficeIMOError } = _m2;
9898
10298
 
9899
10299
  const { checkAbort, pause, taskYieldDue } = _m4;
@@ -9976,11 +10376,11 @@ async function vectorCommands(block, settings, used) {
9976
10376
  commands.join("") + (fill !== undefined && stroke !== undefined ? "B" : fill !== undefined ? "f" : "S") + (fill !== undefined && fillRule === "evenodd" ? "*" : "") + "\n" };
9977
10377
  }
9978
10378
  const _exports = Object.freeze({ vectorCommands: vectorCommands });
9979
- _modules.set("7904dbe183e98e39e18538292dfe007832e8efe39b812f98f1ec5bc96d4e5459", _exports);
10379
+ _modules.set("3290c84fdf80725af802f497d947bc088aa8d93d9db0a33f6f829f9153aa6fd6", _exports);
9980
10380
  return _exports;
9981
10381
  })();
9982
10382
 
9983
- const _m86 = _modules.get("3bd0bb004f6877b01eb84161fdbcdee0e02df16f4d746e0c2b58d0e001e8a1fe") ?? (() => {
10383
+ const _m87 = _modules.get("da9ad00f94b9ae28e2e3de796928ff0c4eab1d73382b1441e7d779fad4278ef7") ?? (() => {
9984
10384
  const { NotSupportedError, OfficeIMOError } = _m2;
9985
10385
 
9986
10386
  const { checkAbort, pause, taskYieldDue } = _m4;
@@ -10223,25 +10623,27 @@ async function prepareDrawing(drawing, settings, fonts, used) {
10223
10623
  return { width: captured.width, height: captured.height, content: fragments.join(""), commands: captured.commands, elements: captured.elements };
10224
10624
  }
10225
10625
  const _exports = Object.freeze({ checkDrawingBlock: checkDrawingBlock, prepareDrawing: prepareDrawing });
10226
- _modules.set("3bd0bb004f6877b01eb84161fdbcdee0e02df16f4d746e0c2b58d0e001e8a1fe", _exports);
10626
+ _modules.set("da9ad00f94b9ae28e2e3de796928ff0c4eab1d73382b1441e7d779fad4278ef7", _exports);
10227
10627
  return _exports;
10228
10628
  })();
10229
10629
 
10230
- const _m87 = _modules.get("7e360ac48a118b9a220b682e942dcf53d2e14ed8e0730a8fde6df009828b0966") ?? (() => {
10630
+ const _m88 = _modules.get("5e4503b77b357ee6d9fad1f52690085b0f0b140cd3b550b63c5100ed95a92f88") ?? (() => {
10231
10631
  const { OfficeIMOError } = _m2;
10232
10632
 
10233
- const { capturePdfText, wrapPdfText } = _m69;
10633
+ const { capturePdfText, wrapPdfText } = _m70;
10234
10634
 
10235
10635
  const { positive } = _m55;
10236
10636
 
10237
10637
  const { resolveParagraphStyle } = _m56;
10238
10638
 
10239
- const { captureBookmark } = _m76;
10639
+ const { captureBookmark } = _m77;
10240
10640
 
10241
10641
  const { captureFields } = _m10;
10242
10642
 
10643
+ const { pdfBudgetText } = _m69;
10644
+
10243
10645
  /** @internal Copy public paragraph input before any cooperative layout or source enumeration. */
10244
- function captureParagraph(block, settings, fonts) {
10646
+ function captureParagraph(block, settings, fonts, budgetOnPaint = false) {
10245
10647
  if (!block || block.kind !== "paragraph")
10246
10648
  throw new TypeError("PDF paragraph groups accept paragraph blocks only.");
10247
10649
  const { text, headingLevel, presentation: inputStyle, fontSize, keepTogether, keepWithNext, spaceBefore, spaceAfter, style: styleName, bookmark: inputBookmark } = block;
@@ -10254,7 +10656,8 @@ function captureParagraph(block, settings, fonts) {
10254
10656
  }, settings.paragraphStyles);
10255
10657
  const style = resolved.presentation ?? Object.freeze({}), size = positive(resolved.fontSize ?? settings.fontSize, "Paragraph font size", 144);
10256
10658
  const bookmark = captureBookmark(inputBookmark, settings);
10257
- return Object.freeze({ text: capturePdfText(text, style, settings, fonts, false), style, size,
10659
+ return Object.freeze({ text: capturePdfText(text, style, settings, fonts, false, !budgetOnPaint), style, size,
10660
+ ...(budgetOnPaint ? { budgetOnPaint: true } : {}),
10258
10661
  ...(headingLevel === undefined ? {} : { headingLevel }), ...(bookmark === undefined ? {} : { bookmark }),
10259
10662
  keepTogether: resolved.keepTogether ?? false, keepWithNext: resolved.keepWithNext ?? false,
10260
10663
  spaceBefore: resolved.spaceBefore ?? 0, spaceAfter: resolved.spaceAfter ?? 8 });
@@ -10265,13 +10668,16 @@ function captureCaption(caption, settings, fonts) {
10265
10668
  Object.keys(caption).some(key => !["text", "style", "fontSize", "presentation", "spaceBefore", "spaceAfter"].includes(key)))
10266
10669
  throw new TypeError("PDF captions support text, style, fontSize, presentation, spaceBefore and spaceAfter.");
10267
10670
  return captureParagraph({ ...captureFields(caption, ["text", "style", "fontSize", "presentation", "spaceBefore", "spaceAfter"]),
10268
- kind: "paragraph", keepTogether: true, keepWithNext: true }, settings, fonts);
10671
+ kind: "paragraph", keepTogether: true, keepWithNext: true }, settings, fonts, true);
10269
10672
  }
10270
10673
  /** @internal Layout is bounded by the same per-cell text and wrapped-line limits as table cells. */
10271
10674
  async function prepareParagraph(captured, settings, fonts, width = settings.page.width - settings.margins.left - settings.margins.right) {
10272
10675
  if (!captured.text.text)
10273
10676
  return { ...captured, lines: [], height: 0, firstHeight: 0 };
10274
- settings.budget.cell(captured.text.text, captured.text.text.length);
10677
+ if (!captured.budgetOnPaint) {
10678
+ const budgetText = pdfBudgetText(captured.text.text, settings.budget);
10679
+ settings.budget.cell(budgetText, budgetText.length);
10680
+ }
10275
10681
  const lines = await wrapPdfText(captured.text, fonts, captured.size, positive(width, "Paragraph width"), settings);
10276
10682
  return { ...captured, lines, height: captured.spaceBefore + lines.reduce((height, line) => height + line.lineHeight, 0) + captured.spaceAfter,
10277
10683
  firstHeight: captured.spaceBefore + lines[0].lineHeight };
@@ -10301,14 +10707,14 @@ function paragraphStartHeight(paragraphs) {
10301
10707
  return required;
10302
10708
  }
10303
10709
  const _exports = Object.freeze({ captureParagraph: captureParagraph, captureCaption: captureCaption, prepareParagraph: prepareParagraph, checkParagraphBuffer: checkParagraphBuffer, paragraphStartHeight: paragraphStartHeight });
10304
- _modules.set("7e360ac48a118b9a220b682e942dcf53d2e14ed8e0730a8fde6df009828b0966", _exports);
10710
+ _modules.set("5e4503b77b357ee6d9fad1f52690085b0f0b140cd3b550b63c5100ed95a92f88", _exports);
10305
10711
  return _exports;
10306
10712
  })();
10307
10713
 
10308
- const _m88 = _modules.get("57e348628775da4857f6a81eb64a59b0ce1669657fa7b1fa2a7bb17485be2475") ?? (() => {
10309
- const { capturePdfText, wrapPdfText } = _m69;
10714
+ const _m89 = _modules.get("1d57c429705ae0cbc14d98dcfef4c8a6c2df06f391c8f58e99cacb02f2d1cbc7") ?? (() => {
10715
+ const { capturePdfText, wrapPdfText } = _m70;
10310
10716
 
10311
- const { captureParagraph, prepareParagraph } = _m87;
10717
+ const { captureParagraph, prepareParagraph } = _m88;
10312
10718
 
10313
10719
  const { resolveParagraphStyle } = _m56;
10314
10720
 
@@ -10359,11 +10765,11 @@ async function prepareListItem(item, index, options, settings, fonts) {
10359
10765
  height: paragraph.height + lineHeight - first.lineHeight, firstHeight: paragraph.spaceBefore + lineHeight } };
10360
10766
  }
10361
10767
  const _exports = Object.freeze({ captureListOptions: captureListOptions, prepareListItem: prepareListItem });
10362
- _modules.set("57e348628775da4857f6a81eb64a59b0ce1669657fa7b1fa2a7bb17485be2475", _exports);
10768
+ _modules.set("1d57c429705ae0cbc14d98dcfef4c8a6c2df06f391c8f58e99cacb02f2d1cbc7", _exports);
10363
10769
  return _exports;
10364
10770
  })();
10365
10771
 
10366
- const _m90 = _modules.get("0c51d89c5cf0ebfeddbe03d5cd04c8bd29a78cdf70b244a68d44fdf82f0f0016") ?? (() => {
10772
+ const _m91 = _modules.get("d04686d2c067355dfd215333b83eb5f79f96e9e4be49f942e050f21ac0795343") ?? (() => {
10367
10773
  const { assertGroupedReportSource } = _m8;
10368
10774
 
10369
10775
  const { captureFields } = _m10;
@@ -10409,26 +10815,26 @@ function captureGroupedPdfTableOptions(configuration) {
10409
10815
  ...(captured.footerPresentation === undefined ? {} : { footerPresentation: presentation(captured.footerPresentation) }) });
10410
10816
  }
10411
10817
  const _exports = Object.freeze({ groupedPdfLabelFields: groupedPdfLabelFields, groupedPdfTableFields: groupedPdfTableFields, pdfGroupedTable: pdfGroupedTable, captureGroupedPdfTableOptions: captureGroupedPdfTableOptions });
10412
- _modules.set("0c51d89c5cf0ebfeddbe03d5cd04c8bd29a78cdf70b244a68d44fdf82f0f0016", _exports);
10818
+ _modules.set("d04686d2c067355dfd215333b83eb5f79f96e9e4be49f942e050f21ac0795343", _exports);
10413
10819
  return _exports;
10414
10820
  })();
10415
10821
 
10416
- const _m89 = _modules.get("1b926dd1b74341a9639f4b5672eff09e7f4454be52608ee78d5782bf3417f0f7") ?? (() => {
10822
+ const _m90 = _modules.get("d43e573fd5bad18a7ec2d71752168c422c4f8fabbc51f1cef8e3ba389f298715") ?? (() => {
10417
10823
  const { assertGroupedReportSource, groupedReportOperation } = _m8;
10418
10824
 
10419
10825
  const { consumeRows } = _m4;
10420
10826
 
10421
10827
  const { ExportCell } = _m5;
10422
10828
 
10423
- const { captureGroupedPdfTableOptions } = _m90;
10829
+ const { captureGroupedPdfTableOptions } = _m91;
10424
10830
 
10425
10831
  const { settings } = _m55;
10426
10832
 
10427
- const { PdfTableLayout } = _m67;
10833
+ const { PdfTableLayout } = _m68;
10428
10834
 
10429
- const { captureCaption, captureParagraph, prepareParagraph } = _m87;
10835
+ const { captureCaption, captureParagraph, prepareParagraph } = _m88;
10430
10836
 
10431
- const { synchronousText } = _m68;
10837
+ const { synchronousText } = _m69;
10432
10838
 
10433
10839
  /** @internal Render one analytical source in the existing document session. Retain one detail row and
10434
10840
  * at most four closing subtotals. All captions, rows, pages, bytes and fonts use the document owners. */
@@ -10457,10 +10863,44 @@ async function renderGroupedPdfTable(block, context) {
10457
10863
  const continuationLabels = new WeakMap();
10458
10864
  let pending;
10459
10865
  const closing = [];
10460
- const summaryValues = (label, values) => Object.freeze([
10866
+ const aggregatePositions = report.columns.flatMap((column, index) => Object.hasOwn(report.totals, column.key) ? [index] : []);
10867
+ const summaryValues = (label, values, positions) => Object.freeze([
10461
10868
  new ExportCell(label, { text: label, presentation: table.options.footerPresentation }),
10462
- ...values.map(value => new ExportCell(value, { presentation: table.options.footerPresentation }))
10869
+ ...(positions ? positions.map(index => values[index]) : values).map(value => new ExportCell(value, { presentation: table.options.footerPresentation }))
10463
10870
  ]);
10871
+ // Independent summaries have no detail values in non-aggregate columns. Project their
10872
+ // declared operations, including zero/null results, rather than emitting label-only bands.
10873
+ // Keep callback positions in the original source model after this physical projection.
10874
+ const summaryLayouts = new Map();
10875
+ const summaryLayout = (grand) => {
10876
+ const existing = summaryLayouts.get(grand);
10877
+ if (existing)
10878
+ return existing;
10879
+ const positions = [0, ...aggregatePositions.map(index => index + 1)];
10880
+ const projected = positions.map(position => {
10881
+ const column = columns[position];
10882
+ if (!grand)
10883
+ return column;
10884
+ const { groups: _groups, ...leaf } = column;
10885
+ return leaf;
10886
+ });
10887
+ const originalPosition = (position) => {
10888
+ const columnIndex = positions[position.columnIndex];
10889
+ return { ...position, columnIndex, column: columns[columnIndex] };
10890
+ };
10891
+ const repeatColumns = positions.flatMap((position, index) => position === 0 || table.repeatedColumns.includes(position) ? [index] : []);
10892
+ const wideTable = table.options.wideTable;
10893
+ const projectedSettings = { ...sharedTable,
10894
+ repeatedColumns: Object.freeze(repeatColumns), options: { ...table.options, columns: projected,
10895
+ ...(table.options.columnWidths === undefined ? {} : { columnWidths: positions.map(position => table.options.columnWidths[position]) }),
10896
+ ...(typeof wideTable !== "object" ? {} : { wideTable: { ...wideTable, repeatColumns } }),
10897
+ ...(table.options.formatValue === undefined ? {} : { formatValue: (value, position) => table.options.formatValue(value, originalPosition(position)) }),
10898
+ ...(table.options.formatRuns === undefined ? {} : { formatRuns: (value, position) => table.options.formatRuns(value, originalPosition(position)) })
10899
+ } };
10900
+ const projectedLayout = new PdfTableLayout(projectedSettings, fonts);
10901
+ summaryLayouts.set(grand, projectedLayout);
10902
+ return projectedLayout;
10903
+ };
10464
10904
  const prepareGroupContext = async () => {
10465
10905
  const caption = await prepareParagraph(captureCaption({ text: path.map(group => group.label).join("\n"),
10466
10906
  presentation: { bold: true }, spaceAfter: 4 }, pages.settings, fonts), pages.settings, fonts);
@@ -10523,26 +10963,46 @@ async function renderGroupedPdfTable(block, context) {
10523
10963
  ...(group.label.trim() ? { bookmark: { title: group.label, level: (groupHeadingLevel + group.level) } } : {})
10524
10964
  }, pages.settings, fonts), pages.settings, fonts));
10525
10965
  const groupHeight = groupHeadings.reduce((height, heading) => height + heading.height, 0);
10526
- await context.flushParagraphs((caption?.height ?? 0) + groupHeight + headingHeight + minimum);
10527
- let followingHeight = groupHeight + caption.height + headingHeight + minimum;
10966
+ // Newly opened semantic headings already paint the end of this path. Only the open
10967
+ // ancestor prefix needs an artifact here; later physical bands still paint the full path.
10968
+ const ancestorCaption = semantic && semanticDepth > 0 ? await prepareParagraph(captureCaption({
10969
+ text: path.slice(0, semanticDepth).map(group => group.label).join("\n"), presentation: { bold: true }, spaceAfter: 4
10970
+ }, pages.settings, fonts), pages.settings, fonts) : undefined;
10971
+ const openingHeight = semantic ? (ancestorCaption?.height ?? 0) + groupHeight : caption.height;
10972
+ await context.flushParagraphs(openingHeight + headingHeight + minimum);
10973
+ if (ancestorCaption)
10974
+ await pages.paragraphs([ancestorCaption], groupHeight + headingHeight + minimum, true, { artifact: true });
10975
+ let followingHeight = groupHeight + (semantic ? 0 : caption.height) + headingHeight + minimum;
10528
10976
  for (const heading of groupHeadings) {
10529
10977
  followingHeight -= heading.height;
10530
10978
  await pages.beginGroup(semanticDepth++, heading, followingHeight);
10531
10979
  }
10532
- await pages.beginTable(layout, headings, minimum, caption, continuation, false, semantic);
10980
+ await pages.beginTable(layout, headings, minimum, caption, continuation, false, semantic, semantic);
10533
10981
  started = true;
10534
10982
  firstFragment = (caption?.lines.length ?? 0) > 0 || groupHeadings.some(heading => heading.lines.length > 0);
10535
10983
  };
10536
- const semanticSubtotal = async (row, level) => {
10984
+ const semanticSubtotal = async (row, level, values) => {
10985
+ if (level === report.groupBy.length - 1) {
10986
+ // A leaf's own subtotal shares its detail table and header identities. Keep the last
10987
+ // detail/summary bundle when it fits; the existing flow owns continuation and limits.
10988
+ pages.summary(row);
10989
+ closing.push(row);
10990
+ await finishLeaf();
10991
+ await pages.endGroup(level);
10992
+ semanticDepth = level;
10993
+ path = path.slice(0, level);
10994
+ return;
10995
+ }
10537
10996
  await finishLeaf();
10538
10997
  const { caption, continuation } = await prepareGroupContext();
10539
- const minimum = layout.minimumRowHeight(row);
10540
- await context.flushParagraphs(caption.height + headingHeight + minimum);
10998
+ const projected = summaryLayout(false), summaryHeadings = await projected.headers();
10999
+ const summaryRow = await projected.data(values, 0, true), minimum = projected.minimumRowHeight(summaryRow);
11000
+ await context.flushParagraphs(caption.height + await projected.blockHeight(summaryHeadings) + minimum);
10541
11001
  // An ancestor subtotal belongs to that ancestor's section, never the final child's table.
10542
11002
  // Its own visible column headings keep the separate logical summary table truthful.
10543
- await pages.beginTable(layout, headings, minimum, caption, continuation, false, true);
10544
- pages.summary(row);
10545
- await pages.row(row, caption.lines.length > 0 || headings.length > 0);
11003
+ await pages.beginTable(projected, summaryHeadings, minimum, caption, continuation, false, true);
11004
+ pages.summary(summaryRow);
11005
+ await pages.row(summaryRow, caption.lines.length > 0 || summaryHeadings.length > 0);
10546
11006
  await pages.endTable();
10547
11007
  await pages.endGroup(level);
10548
11008
  semanticDepth = level;
@@ -10552,25 +11012,19 @@ async function renderGroupedPdfTable(block, context) {
10552
11012
  await finishLeaf();
10553
11013
  if (!includeGrandTotal && summary.rows !== 0)
10554
11014
  return;
10555
- const completeColumns = summary.rows === 0 ? columns : columns.map(column => {
10556
- const { groups: _groups, ...leaf } = column;
10557
- return leaf;
10558
- });
10559
- const completeTable = settings({ ...table.options, columns: completeColumns,
10560
- includeHeader: input.includeHeader ?? true });
10561
- const completeLayout = summary.rows === 0 ? layout : new PdfTableLayout({ ...completeTable, budget: prepared.budget }, fonts);
11015
+ const completeLayout = summary.rows === 0 ? layout : summaryLayout(true);
10562
11016
  const completeHeadings = summary.rows === 0 ? headings : await completeLayout.headers();
10563
11017
  rowIndex = -1;
10564
11018
  let total;
10565
11019
  if (includeGrandTotal) {
10566
11020
  context.acceptRow(false);
10567
- total = await completeLayout.data(summaryValues(synchronousText(grandTotalLabel(summary), "grandTotalLabel"), summary.totals), 0, true);
11021
+ total = await completeLayout.data(summaryValues(synchronousText(grandTotalLabel(summary), "grandTotalLabel"), summary.totals, summary.rows === 0 ? undefined : aggregatePositions), 0, true);
10568
11022
  }
10569
11023
  if (!completeHeadings.length && !total)
10570
11024
  return;
10571
11025
  const minimum = total ? completeLayout.minimumRowHeight(total) : 0;
10572
11026
  await context.flushParagraphs(await completeLayout.blockHeight(completeHeadings) + minimum);
10573
- await pages.beginTable(completeLayout, completeHeadings, minimum, undefined, undefined, !semantic && summary.rows !== 0);
11027
+ await pages.beginTable(completeLayout, completeHeadings, minimum);
10574
11028
  if (total) {
10575
11029
  if (semantic)
10576
11030
  pages.summary(total);
@@ -10598,9 +11052,11 @@ async function renderGroupedPdfTable(block, context) {
10598
11052
  case "groupEnd": {
10599
11053
  rowIndex = -1;
10600
11054
  context.acceptRow(false);
10601
- const row = await layout.data(summaryValues(synchronousText(subtotalLabel(event), "subtotalLabel"), event.totals), 0, true);
11055
+ const separate = semantic && event.level !== report.groupBy.length - 1;
11056
+ const values = summaryValues(synchronousText(subtotalLabel(event), "subtotalLabel"), event.totals, separate ? aggregatePositions : undefined);
11057
+ const row = separate ? undefined : await layout.data(values, 0, true);
10602
11058
  if (semantic)
10603
- await semanticSubtotal(row, event.level);
11059
+ await semanticSubtotal(row, event.level, values);
10604
11060
  else
10605
11061
  closing.push(row);
10606
11062
  break;
@@ -10617,11 +11073,11 @@ async function renderGroupedPdfTable(block, context) {
10617
11073
  }
10618
11074
  }
10619
11075
  const _exports = Object.freeze({ renderGroupedPdfTable: renderGroupedPdfTable });
10620
- _modules.set("1b926dd1b74341a9639f4b5672eff09e7f4454be52608ee78d5782bf3417f0f7", _exports);
11076
+ _modules.set("d43e573fd5bad18a7ec2d71752168c422c4f8fabbc51f1cef8e3ba389f298715", _exports);
10621
11077
  return _exports;
10622
11078
  })();
10623
11079
 
10624
- const _m82 = _modules.get("0b53b552fbfad950bf3455ae0266ec34d40deadc96dd3e1fe03d26cce63ea40f") ?? (() => {
11080
+ const _m83 = _modules.get("f6c70e9a0bed09b5a1c61a662ad7d3faf731c911f574e2df285f669bd643b947") ?? (() => {
10625
11081
  const { BlobByteSink, withDestination } = _m3;
10626
11082
 
10627
11083
  const { OfficeIMOError } = _m2;
@@ -10638,25 +11094,25 @@ const { settings, captureWideTable } = _m55;
10638
11094
 
10639
11095
  const { pdfNumber: n } = _m59;
10640
11096
 
10641
- const { PdfTableLayout } = _m67;
11097
+ const { PdfTableLayout } = _m68;
10642
11098
 
10643
11099
  const { PdfWriteSession } = _m58;
10644
11100
 
10645
- const { PdfDocumentImages } = _m83;
11101
+ const { PdfDocumentImages } = _m84;
10646
11102
 
10647
- const { vectorCommands } = _m85;
11103
+ const { vectorCommands } = _m86;
10648
11104
 
10649
- const { graphicAlternative } = _m78;
11105
+ const { graphicAlternative } = _m79;
10650
11106
 
10651
- const { checkDrawingBlock, prepareDrawing } = _m86;
11107
+ const { checkDrawingBlock, prepareDrawing } = _m87;
10652
11108
 
10653
- const { captureParagraph, captureCaption, prepareParagraph, checkParagraphBuffer, paragraphStartHeight } = _m87;
11109
+ const { captureParagraph, captureCaption, prepareParagraph, checkParagraphBuffer, paragraphStartHeight } = _m88;
10654
11110
 
10655
- const { captureListOptions, prepareListItem } = _m88;
11111
+ const { captureListOptions, prepareListItem } = _m89;
10656
11112
 
10657
- const { captureSection } = _m76;
11113
+ const { captureSection } = _m77;
10658
11114
 
10659
- const { renderGroupedPdfTable } = _m89;
11115
+ const { renderGroupedPdfTable } = _m90;
10660
11116
 
10661
11117
  const tableOptionFields = ["columns", "includeHeader", "headerRows", "footer", "headerPresentation", "footerPresentation", "alternateRowColor", "columnWidths", "wideTable", "formatValue", "formatRuns"];
10662
11118
  /** Capture typed columns for a single-use table source in a composed document. */
@@ -10911,22 +11367,22 @@ function captureTableOptions(options) {
10911
11367
  return { ...captured, ...(captured.wideTable === undefined ? {} : { wideTable: captureWideTable(captured.wideTable) }) };
10912
11368
  }
10913
11369
  const _exports = Object.freeze({ pdfTable: pdfTable, writePdfDocument: writePdfDocument, writePdfDocumentTo: writePdfDocumentTo });
10914
- _modules.set("0b53b552fbfad950bf3455ae0266ec34d40deadc96dd3e1fe03d26cce63ea40f", _exports);
11370
+ _modules.set("f6c70e9a0bed09b5a1c61a662ad7d3faf731c911f574e2df285f669bd643b947", _exports);
10915
11371
  return _exports;
10916
11372
  })();
10917
11373
 
10918
- const _m81 = _modules.get("3f9d005ed3e31b1080249d471774fa84044f9fa1ec30d71d01d3c2cf77818c4d") ?? (() => {
11374
+ const _m82 = _modules.get("879a0adeb3c62918085a071cbc37f221eb89a0fd73d56ebb5e9cfe0d49db8ee9") ?? (() => {
10919
11375
  const { assertGroupedReportSource } = _m8;
10920
11376
 
10921
11377
  const { BlobByteSink } = _m3;
10922
11378
 
10923
- const { writePdfDocumentTo } = _m82;
11379
+ const { writePdfDocumentTo } = _m83;
10924
11380
 
10925
11381
  const { pdfOptionFields } = _m55;
10926
11382
 
10927
11383
  const { captureFields } = _m10;
10928
11384
 
10929
- const { pdfGroupedTable, groupedPdfLabelFields, groupedPdfTableFields } = _m90;
11385
+ const { pdfGroupedTable, groupedPdfLabelFields, groupedPdfTableFields } = _m91;
10930
11386
 
10931
11387
 
10932
11388
 
@@ -10960,15 +11416,15 @@ async function writeGroupedPdfTo(report, destination, configuration) {
10960
11416
  delete documentOptions.footer;
10961
11417
  return writePdfDocumentTo([pdfGroupedTable(report, tableOptions)], destination, documentOptions);
10962
11418
  }
10963
- const _exports = Object.freeze({ pdfGroupedTable: _m90.pdfGroupedTable, writeGroupedPdf: writeGroupedPdf, writeGroupedPdfTo: writeGroupedPdfTo });
10964
- _modules.set("3f9d005ed3e31b1080249d471774fa84044f9fa1ec30d71d01d3c2cf77818c4d", _exports);
11419
+ const _exports = Object.freeze({ pdfGroupedTable: _m91.pdfGroupedTable, writeGroupedPdf: writeGroupedPdf, writeGroupedPdfTo: writeGroupedPdfTo });
11420
+ _modules.set("879a0adeb3c62918085a071cbc37f221eb89a0fd73d56ebb5e9cfe0d49db8ee9", _exports);
10965
11421
  return _exports;
10966
11422
  })();
10967
11423
 
10968
- const _m91 = _modules.get("6ac9b32affc9008e5bd8620fd3792022dfdcd4e0fe51c678bb2ba26bcbe95fd9") ?? (() => {
10969
- const { fontProgram } = _m61;
11424
+ const _m92 = _modules.get("3d777096288d1be55a05a80bc015d4674212e587703f25a7e7cf99a8065feb86") ?? (() => {
11425
+ const { fontProgram } = _m62;
10970
11426
 
10971
- const { resolveScalar, selectFont, validateFonts } = _m65;
11427
+ const { resolveScalar, selectFont, validateFonts } = _m66;
10972
11428
 
10973
11429
  /**
10974
11430
  * Check one text run against the writer's selected font and scalar-layout rules.
@@ -11001,18 +11457,18 @@ function preflightPdfText(text, options = {}) {
11001
11457
  return { supported: true };
11002
11458
  }
11003
11459
  const _exports = Object.freeze({ preflightPdfText: preflightPdfText });
11004
- _modules.set("6ac9b32affc9008e5bd8620fd3792022dfdcd4e0fe51c678bb2ba26bcbe95fd9", _exports);
11460
+ _modules.set("3d777096288d1be55a05a80bc015d4674212e587703f25a7e7cf99a8065feb86", _exports);
11005
11461
  return _exports;
11006
11462
  })();
11007
11463
 
11008
- const _m53 = _modules.get("71169c44be949c319579ad95fc607b6a64115646c56e93cb6b58d6b9e26fb0bf") ?? (() => {
11464
+ const _m53 = _modules.get("2deab7b4ccb08bed297341ddb563d8fcf74277aff38c1dfc3d9edd61c0d98481") ?? (() => {
11009
11465
 
11010
- const _exports = Object.freeze({ writePdf: _m54.writePdf, writePdfTo: _m54.writePdfTo, writeGroupedPdf: _m81.writeGroupedPdf, writeGroupedPdfTo: _m81.writeGroupedPdfTo, pdfGroupedTable: _m81.pdfGroupedTable, createGroupedReport: _m8.createGroupedReport, writePdfDocument: _m82.writePdfDocument, writePdfDocumentTo: _m82.writePdfDocumentTo, pdfTable: _m82.pdfTable, PdfFont: _m61.PdfFont, preflightPdfText: _m91.preflightPdfText, ExportCell: _m5.ExportCell, saveBlob: _m1.saveBlob });
11011
- _modules.set("71169c44be949c319579ad95fc607b6a64115646c56e93cb6b58d6b9e26fb0bf", _exports);
11466
+ const _exports = Object.freeze({ writePdf: _m54.writePdf, writePdfTo: _m54.writePdfTo, writeGroupedPdf: _m82.writeGroupedPdf, writeGroupedPdfTo: _m82.writeGroupedPdfTo, pdfGroupedTable: _m82.pdfGroupedTable, createGroupedReport: _m8.createGroupedReport, writePdfDocument: _m83.writePdfDocument, writePdfDocumentTo: _m83.writePdfDocumentTo, pdfTable: _m83.pdfTable, PdfFont: _m62.PdfFont, preflightPdfText: _m92.preflightPdfText, ExportCell: _m5.ExportCell, saveBlob: _m1.saveBlob });
11467
+ _modules.set("2deab7b4ccb08bed297341ddb563d8fcf74277aff38c1dfc3d9edd61c0d98481", _exports);
11012
11468
  return _exports;
11013
11469
  })();
11014
11470
 
11015
- const _m92 = _modules.get("e37eb5f0298d8bc9492db790f163f4a1d6d8b4293981cfdacfcd9d9810ec9b7f") ?? (() => {
11471
+ const _m93 = _modules.get("e37eb5f0298d8bc9492db790f163f4a1d6d8b4293981cfdacfcd9d9810ec9b7f") ?? (() => {
11016
11472
  /** @internal Runtime-checked calls across the optional third-party API boundary. */
11017
11473
  function call(owner, name, ...args) {
11018
11474
  const fn = member(owner, name);
@@ -11045,12 +11501,12 @@ _modules.set("e37eb5f0298d8bc9492db790f163f4a1d6d8b4293981cfdacfcd9d9810ec9b7f",
11045
11501
  return _exports;
11046
11502
  })();
11047
11503
 
11048
- const _m93 = _modules.get("0e5ede7759618ed3ec827d34fbd62b205f3a5241650504807c24e5323a2496a5") ?? (() => {
11504
+ const _m94 = _modules.get("0e5ede7759618ed3ec827d34fbd62b205f3a5241650504807c24e5323a2496a5") ?? (() => {
11049
11505
  const { ExportCell, assertExportValue } = _m5;
11050
11506
 
11051
11507
  const { tableSpans } = _m17;
11052
11508
 
11053
- const { member } = _m92;
11509
+ const { member } = _m93;
11054
11510
 
11055
11511
  /** @internal */
11056
11512
  function value(input) {
@@ -11119,18 +11575,18 @@ _modules.set("0e5ede7759618ed3ec827d34fbd62b205f3a5241650504807c24e5323a2496a5",
11119
11575
  return _exports;
11120
11576
  })();
11121
11577
 
11122
- const _m94 = _modules.get("c5a0fad0264a40f2d2fd98103420511fc42e3e3fe1d67889bd550927a1b9e196") ?? (() => {
11578
+ const _m95 = _modules.get("355177890a4e7a43de040650e9c2359a6ccf105705bc6231f51db5975a838d3d") ?? (() => {
11123
11579
  const { checkAbort, pause, rowsFromBatches, taskYieldDue } = _m4;
11124
11580
 
11125
11581
  const { ExportBudget } = _m9;
11126
11582
 
11127
11583
  const { captureFields } = _m10;
11128
11584
 
11129
- const { columnOptionFields } = _m11;
11585
+ const { columnOptionFields, copyColumns } = _m11;
11130
11586
 
11131
- const { array, call, indexes, member } = _m92;
11587
+ const { array, call, indexes, member } = _m93;
11132
11588
 
11133
- const { headings, text, value } = _m93;
11589
+ const { headings, text, value } = _m94;
11134
11590
 
11135
11591
  function safeOptions(options) {
11136
11592
  options = captureFields(options, ["rows", "columns", "modifier", "orthogonal", "stripHtml", "stripNewlines", "decodeEntities", "escapeExcelFormula", "trim", "format", "customizeData"]);
@@ -11205,10 +11661,10 @@ function captureDataTablesExport(host, table, options = {}, omitted) {
11205
11661
  for (const index of columnIndexes)
11206
11662
  if (member(options.columnOptions?.[index], "value") !== undefined)
11207
11663
  throw new TypeError("DataTables columnOptions describes columns; resolve values with project.");
11208
- const columns = Object.freeze(leaf.map((label, index) => Object.freeze({
11664
+ const columns = Object.freeze(copyColumns(leaf.map((label, index) => ({
11209
11665
  header: text(label), key: "dt:" + columnIndexes[index], ...options.columnOptions?.[columnIndexes[index]],
11210
11666
  ...(heading.groups[index].length ? { groups: Object.freeze(heading.groups[index]) } : {})
11211
- })));
11667
+ }))).map(column => Object.freeze(column)));
11212
11668
  // Explicit heading overrides also apply to CSV's leaf heading.
11213
11669
  if (!heading.structure)
11214
11670
  heading.rows[heading.rows.length - 1] = columns.map(column => column.header);
@@ -11333,11 +11789,11 @@ function captureDataTablesExport(host, table, options = {}, omitted) {
11333
11789
  ...(footerHeading?.structure ? { footerStructure: footerHeading.structure } : {}), rowCount: count, rows });
11334
11790
  }
11335
11791
  const _exports = Object.freeze({ createDataTablesExport: createDataTablesExport, captureDataTablesExport: captureDataTablesExport });
11336
- _modules.set("c5a0fad0264a40f2d2fd98103420511fc42e3e3fe1d67889bd550927a1b9e196", _exports);
11792
+ _modules.set("355177890a4e7a43de040650e9c2359a6ccf105705bc6231f51db5975a838d3d", _exports);
11337
11793
  return _exports;
11338
11794
  })();
11339
11795
 
11340
- const _m95 = _modules.get("46b68ddd3bfb2a9f845c2684cd1de5fc4212610a87dc8da7d3e35fefc2a34367") ?? (() => {
11796
+ const _m96 = _modules.get("58066519dce31ad3bb7f5f5c377585d3374a84578358ad519e2c021efa1a26f8") ?? (() => {
11341
11797
  const { captureFields } = _m10;
11342
11798
 
11343
11799
  const { ExportBudget } = _m9;
@@ -11378,11 +11834,11 @@ function capturePdfOptions(input = {}) {
11378
11834
  return { ...options, ...(options.limits === undefined ? {} : { limits: capturePdfLimits(options.limits) }) };
11379
11835
  }
11380
11836
  const _exports = Object.freeze({ captureCommonLimits: captureCommonLimits, mergeAdapterLimits: mergeAdapterLimits, captureXlsxOptions: captureXlsxOptions, captureCsvOptions: captureCsvOptions, capturePdfOptions: capturePdfOptions });
11381
- _modules.set("46b68ddd3bfb2a9f845c2684cd1de5fc4212610a87dc8da7d3e35fefc2a34367", _exports);
11837
+ _modules.set("58066519dce31ad3bb7f5f5c377585d3374a84578358ad519e2c021efa1a26f8", _exports);
11382
11838
  return _exports;
11383
11839
  })();
11384
11840
 
11385
- const _m0 = _modules.get("a51cb067a86727f5fa111223487be3c47d95fddc3e466cd52e395c99cbbf4b3b") ?? (() => {
11841
+ const _m0 = _modules.get("6b9445ed732777e080cae1728163a9d7e22fe1738368c4ee7c6656795e609c72") ?? (() => {
11386
11842
  const { BlobByteSink, checkAbort, saveBlob } = _m1;
11387
11843
 
11388
11844
  const { notifyProgress } = _m14;
@@ -11395,15 +11851,15 @@ const { writePdfTo } = _m53;
11395
11851
 
11396
11852
  const { portableSheet, portableWorkbook } = _m50;
11397
11853
 
11398
- const { call, member } = _m92;
11854
+ const { call, member } = _m93;
11399
11855
 
11400
- const { value } = _m93;
11856
+ const { value } = _m94;
11401
11857
 
11402
- const { captureDataTablesExport } = _m94;
11858
+ const { captureDataTablesExport } = _m95;
11403
11859
 
11404
11860
  const { captureFields } = _m10;
11405
11861
 
11406
- const { captureCommonLimits, captureXlsxOptions, captureCsvOptions, capturePdfOptions, mergeAdapterLimits } = _m95;
11862
+ const { captureCommonLimits, captureXlsxOptions, captureCsvOptions, capturePdfOptions, mergeAdapterLimits } = _m96;
11407
11863
 
11408
11864
 
11409
11865
 
@@ -11564,8 +12020,8 @@ function registerDataTablesButtons(host, options = {}) {
11564
12020
  };
11565
12021
  }
11566
12022
  }
11567
- const _exports = Object.freeze({ createDataTablesExport: _m94.createDataTablesExport, ExportCell: _m5.ExportCell, PdfFont: _m61.PdfFont, writeDataTableTo: writeDataTableTo, exportDataTable: exportDataTable, registerDataTablesButtons: registerDataTablesButtons });
11568
- _modules.set("a51cb067a86727f5fa111223487be3c47d95fddc3e466cd52e395c99cbbf4b3b", _exports);
12023
+ const _exports = Object.freeze({ createDataTablesExport: _m95.createDataTablesExport, ExportCell: _m5.ExportCell, PdfFont: _m62.PdfFont, writeDataTableTo: writeDataTableTo, exportDataTable: exportDataTable, registerDataTablesButtons: registerDataTablesButtons });
12024
+ _modules.set("6b9445ed732777e080cae1728163a9d7e22fe1738368c4ee7c6656795e609c72", _exports);
11569
12025
  return _exports;
11570
12026
  })();
11571
12027
  Object.assign(officeimo, _m0);