@evotecit/officeimo 0.1.19 → 0.1.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/README.md +44 -10
  2. package/bundles/officeimo-canopyx-adapter.js +147 -65
  3. package/bundles/officeimo-canopyx-adapter.min.js +1 -1
  4. package/bundles/officeimo-canopyx-adapter.min.mjs +1 -1
  5. package/bundles/officeimo-canopyx-adapter.mjs +134 -53
  6. package/bundles/officeimo-canopyx.js +554 -234
  7. package/bundles/officeimo-canopyx.min.js +1 -1
  8. package/bundles/officeimo-canopyx.min.mjs +1 -1
  9. package/bundles/officeimo-canopyx.mjs +477 -158
  10. package/bundles/officeimo-chartforgex-adapter.js +1924 -0
  11. package/bundles/officeimo-chartforgex-adapter.min.js +2 -0
  12. package/bundles/officeimo-chartforgex-adapter.min.mjs +2 -0
  13. package/bundles/officeimo-chartforgex-adapter.mjs +1910 -0
  14. package/bundles/officeimo-chartforgex.js +13594 -0
  15. package/bundles/officeimo-chartforgex.min.js +2 -0
  16. package/bundles/officeimo-chartforgex.min.mjs +2 -0
  17. package/bundles/officeimo-chartforgex.mjs +13487 -0
  18. package/bundles/officeimo-csv.js +12 -7
  19. package/bundles/officeimo-csv.min.js +1 -1
  20. package/bundles/officeimo-csv.min.mjs +1 -1
  21. package/bundles/officeimo-csv.mjs +8 -3
  22. package/bundles/officeimo-datatables-adapter.js +11 -11
  23. package/bundles/officeimo-datatables-adapter.min.js +1 -1
  24. package/bundles/officeimo-datatables-adapter.min.mjs +1 -1
  25. package/bundles/officeimo-datatables-adapter.mjs +7 -7
  26. package/bundles/officeimo-datatables.js +418 -180
  27. package/bundles/officeimo-datatables.min.js +1 -1
  28. package/bundles/officeimo-datatables.min.mjs +1 -1
  29. package/bundles/officeimo-datatables.mjs +350 -112
  30. package/bundles/officeimo-execution.js +14 -9
  31. package/bundles/officeimo-execution.min.js +1 -1
  32. package/bundles/officeimo-execution.min.mjs +1 -1
  33. package/bundles/officeimo-execution.mjs +8 -3
  34. package/bundles/officeimo-pdf.js +286 -120
  35. package/bundles/officeimo-pdf.min.js +1 -1
  36. package/bundles/officeimo-pdf.min.mjs +1 -1
  37. package/bundles/officeimo-pdf.mjs +244 -78
  38. package/bundles/officeimo-xlsx.js +136 -59
  39. package/bundles/officeimo-xlsx.min.js +1 -1
  40. package/bundles/officeimo-xlsx.min.mjs +1 -1
  41. package/bundles/officeimo-xlsx.mjs +114 -37
  42. package/bundles/officeimo.js +416 -178
  43. package/bundles/officeimo.min.js +1 -1
  44. package/bundles/officeimo.min.mjs +1 -1
  45. package/bundles/officeimo.mjs +351 -113
  46. package/dist/core/progress.js +7 -2
  47. package/dist/index.d.ts +1 -1
  48. package/dist/integrations/canopyx/index.js +13 -4
  49. package/dist/integrations/canopyx/pdf-number.js +9 -6
  50. package/dist/integrations/canopyx/rule-predicates.d.ts +1 -1
  51. package/dist/integrations/canopyx/rule-predicates.js +2 -1
  52. package/dist/integrations/canopyx/rules.d.ts +1 -1
  53. package/dist/integrations/canopyx/rules.js +11 -13
  54. package/dist/integrations/canopyx/source.js +57 -7
  55. package/dist/integrations/canopyx/tones.d.ts +10 -0
  56. package/dist/integrations/canopyx/tones.js +12 -0
  57. package/dist/integrations/canopyx/types.d.ts +8 -1
  58. package/dist/integrations/chartforgex/capture.d.ts +31 -0
  59. package/dist/integrations/chartforgex/capture.js +103 -0
  60. package/dist/integrations/chartforgex/index.d.ts +13 -0
  61. package/dist/integrations/chartforgex/index.js +88 -0
  62. package/dist/integrations/chartforgex/svg-drawing.d.ts +5 -0
  63. package/dist/integrations/chartforgex/svg-drawing.js +775 -0
  64. package/dist/integrations/chartforgex/svg-geometry.d.ts +23 -0
  65. package/dist/integrations/chartforgex/svg-geometry.js +304 -0
  66. package/dist/integrations/chartforgex/svg-image.d.ts +9 -0
  67. package/dist/integrations/chartforgex/svg-image.js +46 -0
  68. package/dist/integrations/chartforgex/svg-markup.d.ts +10 -0
  69. package/dist/integrations/chartforgex/svg-markup.js +124 -0
  70. package/dist/integrations/chartforgex/svg-paint.d.ts +16 -0
  71. package/dist/integrations/chartforgex/svg-paint.js +146 -0
  72. package/dist/integrations/chartforgex/types.d.ts +77 -0
  73. package/dist/integrations/chartforgex/types.js +1 -0
  74. package/dist/integrations/chartforgex/winansi.d.ts +4 -0
  75. package/dist/integrations/chartforgex/winansi.js +48 -0
  76. package/dist/integrations/chartforgex/workbook.d.ts +12 -0
  77. package/dist/integrations/chartforgex/workbook.js +137 -0
  78. package/dist/pdf/document-drawings.d.ts +1 -1
  79. package/dist/pdf/document-drawings.js +91 -17
  80. package/dist/pdf/document-images.d.ts +7 -1
  81. package/dist/pdf/document-images.js +59 -24
  82. package/dist/pdf/document-types.d.ts +3 -1
  83. package/dist/pdf/document.d.ts +2 -2
  84. package/dist/pdf/document.js +3 -1
  85. package/dist/pdf/drawing-types.d.ts +37 -10
  86. package/dist/pdf/font-resources.d.ts +1 -1
  87. package/dist/pdf/font-resources.js +6 -3
  88. package/dist/pdf/index.d.ts +1 -1
  89. package/dist/pdf/pages.js +15 -0
  90. package/dist/pdf/png.d.ts +11 -2
  91. package/dist/pdf/png.js +50 -23
  92. package/dist/pdf/session.js +3 -2
  93. package/dist/pdf/settings.d.ts +2 -2
  94. package/dist/pdf/settings.js +7 -3
  95. package/dist/xlsx/options.js +2 -2
  96. package/dist/xlsx/portable.js +1 -1
  97. package/dist/xlsx/styles.js +28 -18
  98. package/dist/xlsx/types.d.ts +13 -1
  99. package/dist/xlsx/workbook.js +9 -1
  100. package/dist/xlsx/worksheet.d.ts +13 -1
  101. package/dist/xlsx/worksheet.js +65 -11
  102. package/package.json +9 -2
@@ -972,19 +972,24 @@ _modules.set("81b3d47c02b7d8443b79e02b3cfb52032d6b73d9a3fb592b777ebe028ad0ef00",
972
972
  return _exports;
973
973
  })();
974
974
 
975
- const _m14 = _modules.get("6cfd3e806439f6301003a2d1699a74fdfa574d935550ab62b97b528728eaee1f") ?? (() => {
975
+ const _m14 = _modules.get("4eea31c4336d3c43bc743739843a3ef31803d8f0ed553f5645ee9de2554eb244") ?? (() => {
976
976
  /** @internal Notify synchronously; observe an accidental promise before rejecting its unsupported use. */
977
977
  function notifyProgress(callback, progress) {
978
+ notifySynchronously("onProgress", callback, progress);
979
+ }
980
+ /** @internal Run a host notification that must finish before the export continues. A returned promise is observed,
981
+ * so its rejection is never unhandled, and the export fails instead of reporting success before the callback ends. */
982
+ function notifySynchronously(name, callback, value) {
978
983
  if (!callback)
979
984
  return;
980
- const result = callback(progress);
985
+ const result = callback(value);
981
986
  if (result && typeof result.then === "function") {
982
987
  void Promise.resolve(result).catch(() => { });
983
- throw new TypeError("onProgress must be synchronous.");
988
+ throw new TypeError(name + " must be synchronous.");
984
989
  }
985
990
  }
986
- const _exports = Object.freeze({ notifyProgress: notifyProgress });
987
- _modules.set("6cfd3e806439f6301003a2d1699a74fdfa574d935550ab62b97b528728eaee1f", _exports);
991
+ const _exports = Object.freeze({ notifyProgress: notifyProgress, notifySynchronously: notifySynchronously });
992
+ _modules.set("4eea31c4336d3c43bc743739843a3ef31803d8f0ed553f5645ee9de2554eb244", _exports);
988
993
  return _exports;
989
994
  })();
990
995
 
@@ -1110,7 +1115,7 @@ _modules.set("f0627ba89e5c8fcb376ebe3ce72dcc8d68c34952981f8703e36b8bb1a9894208",
1110
1115
  return _exports;
1111
1116
  })();
1112
1117
 
1113
- const _m15 = _modules.get("b48bcab805d4c75294dd8d8e8dc57f96d9db3f5af31a8f0ddc6562f010f566e4") ?? (() => {
1118
+ const _m15 = _modules.get("406ac6c93ee68eae70c6f52a1e6f4c56b84f43cae12576040c766dcc5598a580") ?? (() => {
1114
1119
  const { beginTask, checkAbort, consumeRows, taskYieldDue, withAbort } = _m4;
1115
1120
 
1116
1121
  const { BlobByteSink, ChunkedTextSink, withDestination } = _m3;
@@ -1260,7 +1265,7 @@ async function writeCsv(rows, configuration) {
1260
1265
  }
1261
1266
  }
1262
1267
  const _exports = Object.freeze({ saveBlob: _m1.saveBlob, ExportCell: _m5.ExportCell, writeCsvTo: writeCsvTo, writeCsv: writeCsv });
1263
- _modules.set("b48bcab805d4c75294dd8d8e8dc57f96d9db3f5af31a8f0ddc6562f010f566e4", _exports);
1268
+ _modules.set("406ac6c93ee68eae70c6f52a1e6f4c56b84f43cae12576040c766dcc5598a580", _exports);
1264
1269
  return _exports;
1265
1270
  })();
1266
1271
 
@@ -2221,7 +2226,7 @@ _modules.set("6ae88f25e1c09d00fbb828917498569f883fae88ec25d37caebaf8a2b802b148",
2221
2226
  return _exports;
2222
2227
  })();
2223
2228
 
2224
- const _m29 = _modules.get("077c3c668f1457253dba044e6f6be7f7afd28a8976ed20c764bd5d5dc7c41889") ?? (() => {
2229
+ const _m29 = _modules.get("8d96d0024443ac9aeaea70e9324b53aacef098c2385d4e6a89a76d184e28556a") ?? (() => {
2225
2230
  const { escapeOoxmlAttribute, cleanXml, xmlDeclaration } = _m25;
2226
2231
 
2227
2232
  const { OfficeIMOError } = _m2;
@@ -2233,6 +2238,24 @@ const { DifferentialStyles } = _m31;
2233
2238
 
2234
2239
 
2235
2240
  const spreadsheetNamespace = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
2241
+ const borderStyles = ["thin", "medium", "dashed", "dotted", "thick", "double", "hair", "dashDot", "dashDotDot", "slantDashDot", "mediumDashed", "mediumDashDot", "mediumDashDotDot"];
2242
+ /** @internal Validate and normalize border edges without registering a workbook style. */
2243
+ function normalizeBorder(border) {
2244
+ if (!border || typeof border !== "object")
2245
+ throw new TypeError("A border must be an object of edges.");
2246
+ const result = {};
2247
+ for (const side of ["left", "right", "top", "bottom"]) {
2248
+ const edge = border[side];
2249
+ if (edge) {
2250
+ // Read each property once, so the validated edge is the one that is stored.
2251
+ const { style, color } = edge;
2252
+ if (!borderStyles.includes(style))
2253
+ throw new TypeError("Invalid border style.");
2254
+ result[side] = { style, ...(color ? { color: colorArgb(color) } : {}) };
2255
+ }
2256
+ }
2257
+ return result;
2258
+ }
2236
2259
  const NumberFormats = { General: "General", Integer: "0", Decimal: "0.00", Percent: "0.00%", Date: "yyyy-mm-dd", DateTime: "yyyy-mm-dd hh:mm:ss" };
2237
2260
  function index(value, count, kind) {
2238
2261
  if (!Number.isInteger(value) || value < 0 || value >= count)
@@ -2305,32 +2328,24 @@ class StyleRegistry {
2305
2328
  /** @internal */
2306
2329
  addDifferentials(styles) { this.checkDifferentials(styles); return this.differential.add(styles); }
2307
2330
  addFont(font) {
2308
- if (font.name !== undefined && typeof font.name !== "string")
2331
+ const { name: requested, size: requestedSize, bold, italic, underline, strike, color } = font;
2332
+ if (requested !== undefined && typeof requested !== "string")
2309
2333
  throw new TypeError("Font name must be a string.");
2310
- const name = cleanXml(font.name ?? "Calibri", this.policy), size = font.size ?? 11;
2334
+ const name = cleanXml(requested ?? "Calibri", this.policy), size = requestedSize ?? 11;
2311
2335
  if (typeof name !== "string" || !name || name.length > 31)
2312
2336
  throw new TypeError("Font name must contain 1 through 31 characters.");
2313
2337
  if (!Number.isFinite(size) || size <= 0 || size > 409)
2314
2338
  throw new RangeError("Font size must be positive and at most 409.");
2315
- return deduplicate(this.fonts, this.fontIndexes, { name, size, bold: !!font.bold, italic: !!font.italic, underline: !!font.underline, strike: !!font.strike, color: font.color ? colorArgb(font.color) : "" }, this.maximum);
2339
+ return deduplicate(this.fonts, this.fontIndexes, { name, size, bold: !!bold, italic: !!italic, underline: !!underline, strike: !!strike, color: color ? colorArgb(color) : "" }, this.maximum);
2316
2340
  }
2317
2341
  addFill(fill) {
2318
- const pattern = fill.pattern ?? (fill.color ? "solid" : "none");
2319
- if (!["none", "gray125", "solid"].includes(pattern) || (pattern === "solid" && !fill.color) || (pattern !== "solid" && fill.color))
2342
+ const { color } = fill, pattern = fill.pattern ?? (color ? "solid" : "none");
2343
+ if (!["none", "gray125", "solid"].includes(pattern) || (pattern === "solid" && !color) || (pattern !== "solid" && color))
2320
2344
  throw new TypeError("A solid fill requires a color; none and gray125 have no color.");
2321
- return deduplicate(this.fills, this.fillIndexes, { pattern, color: fill.color ? colorArgb(fill.color) : "" }, this.maximum + 1);
2345
+ return deduplicate(this.fills, this.fillIndexes, { pattern, color: color ? colorArgb(color) : "" }, this.maximum + 1);
2322
2346
  }
2323
2347
  addBorder(border) {
2324
- const result = {};
2325
- for (const side of ["left", "right", "top", "bottom"]) {
2326
- const edge = border[side];
2327
- if (edge) {
2328
- if (!["thin", "medium", "dashed", "dotted", "thick", "double", "hair", "dashDot", "dashDotDot", "slantDashDot", "mediumDashed", "mediumDashDot", "mediumDashDotDot"].includes(edge.style))
2329
- throw new TypeError("Invalid border style.");
2330
- result[side] = { style: edge.style, ...(edge.color ? { color: colorArgb(edge.color) } : {}) };
2331
- }
2332
- }
2333
- return deduplicate(this.borders, this.borderIndexes, result, this.maximum);
2348
+ return deduplicate(this.borders, this.borderIndexes, normalizeBorder(border), this.maximum);
2334
2349
  }
2335
2350
  addNumberFormat(format) {
2336
2351
  if (typeof format !== "string" || !format || format.length > 255)
@@ -2396,7 +2411,7 @@ class StyleRegistry {
2396
2411
  return this.compose(base, { numberFormat: this.styles[this.validateStyle(dateStyle)].numberFormat });
2397
2412
  }
2398
2413
  /** @internal Column shorthand and header style composition. */
2399
- forColumn(column, header = false, fill, date = false) {
2414
+ forColumn(column, header = false, fill, date = false, border) {
2400
2415
  const base = !header && column.style !== undefined ? this.styles[this.validateStyle(column.style)] : undefined;
2401
2416
  const format = column.format !== undefined ? column.format || NumberFormats.General : base?.numberFormat || (column.type === "date" || date ? NumberFormats.DateTime : NumberFormats.General);
2402
2417
  return this.add({
@@ -2405,7 +2420,7 @@ class StyleRegistry {
2405
2420
  wrapText: column.wrapText ?? base?.wrapText ?? false,
2406
2421
  ...(column.alignment ? { alignment: column.alignment } : base?.alignment ? { alignment: base.alignment } : {}),
2407
2422
  ...(base?.verticalAlignment ? { verticalAlignment: base.verticalAlignment } : {}),
2408
- ...(header ? { font: { bold: true } } : {}), ...(fill ? { fill: { color: fill } } : {})
2423
+ ...(header ? { font: { bold: true } } : {}), ...(fill ? { fill: { color: fill } } : {}), ...(border ? { border } : {})
2409
2424
  });
2410
2425
  }
2411
2426
  toXml() {
@@ -2430,8 +2445,8 @@ class StyleRegistry {
2430
2445
  }).join("") + '</cellXfs><cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles>' + this.differential.toXml() + '</styleSheet>';
2431
2446
  }
2432
2447
  }
2433
- const _exports = Object.freeze({ colorArgb: _m30.colorArgb, spreadsheetNamespace: spreadsheetNamespace, NumberFormats: NumberFormats, validateStylePatch: validateStylePatch, copyStylePatch: copyStylePatch, StyleRegistry: StyleRegistry });
2434
- _modules.set("077c3c668f1457253dba044e6f6be7f7afd28a8976ed20c764bd5d5dc7c41889", _exports);
2448
+ const _exports = Object.freeze({ colorArgb: _m30.colorArgb, spreadsheetNamespace: spreadsheetNamespace, normalizeBorder: normalizeBorder, NumberFormats: NumberFormats, validateStylePatch: validateStylePatch, copyStylePatch: copyStylePatch, StyleRegistry: StyleRegistry });
2449
+ _modules.set("8d96d0024443ac9aeaea70e9324b53aacef098c2385d4e6a89a76d184e28556a", _exports);
2435
2450
  return _exports;
2436
2451
  })();
2437
2452
 
@@ -3585,14 +3600,14 @@ _modules.set("13fa96d976e4dec7343dd3a392829567f1fcb574324a98f5a5d3a61c9a0dc27d",
3585
3600
  return _exports;
3586
3601
  })();
3587
3602
 
3588
- const _m35 = _modules.get("a61e744201bb537b635b367b1764bd85892101d55e00b8c78faec8be89577376") ?? (() => {
3603
+ const _m35 = _modules.get("d5957683aa1945575924c89c63b427878e6e6e47ef5c229dc524b1879d146499") ?? (() => {
3589
3604
  const { checkAbort, consumeRows, inputRows, pause, taskYieldDue } = _m4;
3590
3605
 
3591
3606
  const { ChunkedTextSink, BlobByteSink } = _m3;
3592
3607
 
3593
3608
  const { OfficeIMOError } = _m2;
3594
3609
 
3595
- const { notifyProgress } = _m14;
3610
+ const { notifyProgress, notifySynchronously } = _m14;
3596
3611
 
3597
3612
  const { copyColumns, createRowProjector } = _m11;
3598
3613
 
@@ -3664,8 +3679,14 @@ class Worksheet {
3664
3679
  pendingCharacters = 0;
3665
3680
  reservedLayout = false;
3666
3681
  internalLinks = [];
3682
+ // Evicted entries become holes and are compacted in one pass when the links are read, keeping eviction O(1).
3667
3683
  links = [];
3684
+ evictedLinks = 0;
3668
3685
  linkedCells = new Set();
3686
+ /** Indexes in `links` of data-cell links that `hyperlinkOverflow: "drop"` may give up, in row order. */
3687
+ droppable = [];
3688
+ droppableLinks = new WeakSet();
3689
+ droppedLinks = 0;
3669
3690
  pictures = [];
3670
3691
  nativeCharts = [];
3671
3692
  conditional;
@@ -3696,8 +3717,9 @@ class Worksheet {
3696
3717
  book.checkLinks(this.links.length);
3697
3718
  this.declared = this.columns.map((column, i) => ({ column, letter: columnName(i + 1),
3698
3719
  style: book.styles.forColumn(column), dateStyle: book.styles.forColumn(column, false, undefined, true),
3699
- headerStyle: this.headerRows ? options.headerStyle ?? book.styles.forColumn({ header: column.header, ...(column.wrapText === undefined ? {} : { wrapText: column.wrapText }),
3700
- ...(column.alignment === undefined ? {} : { alignment: column.alignment }) }, options.boldHeader !== false, options.headerFill) : 0
3720
+ headerStyle: this.headerRows ? options.headerStyle ?? book.styles.forColumn({ header: column.header,
3721
+ ...((options.headerWrap ?? column.wrapText) === undefined ? {} : { wrapText: options.headerWrap ?? column.wrapText }),
3722
+ ...(column.alignment === undefined ? {} : { alignment: column.alignment }) }, options.boldHeader !== false, options.headerFill, false, options.headerBorder) : 0
3701
3723
  }));
3702
3724
  // Register conditional styles only after worksheet construction can no longer reject its options.
3703
3725
  this.conditional = new ConditionalFormats(conditional, book.styles);
@@ -3749,6 +3771,8 @@ class Worksheet {
3749
3771
  throw new TypeError("A frozen header or autofilter requires a header row.");
3750
3772
  if (options.headerFill !== undefined)
3751
3773
  colorArgb(options.headerFill);
3774
+ if (options.headerWrap !== undefined && typeof options.headerWrap !== "boolean")
3775
+ throw new TypeError("headerWrap must be boolean.");
3752
3776
  if (options.headerStyle !== undefined)
3753
3777
  book.styles.validateStyle(options.headerStyle);
3754
3778
  if (options.alternatingRowStyle !== undefined)
@@ -3874,7 +3898,8 @@ class Worksheet {
3874
3898
  const cell = col.letter + row;
3875
3899
  if (link || this.linkedCells.has(cell))
3876
3900
  throw new TypeError("A text-preservation cell cannot also have an external hyperlink.");
3877
- checkHyperlinkCount(this.links.length + this.internalLinks.length + 1);
3901
+ this.makeLinkRoom();
3902
+ checkHyperlinkCount(this.linkCount + 1);
3878
3903
  this.book.checkLinks(1);
3879
3904
  // Replace a generated cell's original reservation with its preview and overflow records.
3880
3905
  if (reservedCharacters !== undefined) {
@@ -3888,7 +3913,7 @@ class Worksheet {
3888
3913
  value = preserved.preview;
3889
3914
  }
3890
3915
  if (link)
3891
- this.appendHyperlink({ cell: col.letter + row, ...link });
3916
+ this.appendHyperlink({ cell: col.letter + row, ...link }, !header && !footer && !title && this.book.settings.hyperlinkOverflow === "drop");
3892
3917
  if (type === "date")
3893
3918
  value = excelDate(value, this.book.settings.dateMode);
3894
3919
  if (!header && !footer && visible && (!formula || !isSubtotalFormula(formula)))
@@ -4197,20 +4222,61 @@ class Worksheet {
4197
4222
  throw this.error;
4198
4223
  this.appendHyperlink(link);
4199
4224
  }
4200
- appendHyperlink(link) {
4225
+ appendHyperlink(link, droppable = false) {
4226
+ // Validate before any overflow decision, so a dropped link can never hide an unsafe target.
4201
4227
  const copied = copyHyperlink(link, this.book.settings.invalidCharacterPolicy);
4202
4228
  const position = cellPosition(copied.cell);
4203
4229
  if (this.layout.regions.covered(position.column, position.row))
4204
4230
  throw new TypeError("Hyperlinks cannot address a covered merged cell.");
4205
4231
  if (this.linkedCells.has(copied.cell))
4206
4232
  throw new TypeError("Duplicate hyperlink cell: " + copied.cell);
4207
- checkHyperlinkCount(this.links.length + this.internalLinks.length + 1);
4233
+ if (droppable && this.linkCount >= maximumHyperlinks) {
4234
+ this.droppedLinks++;
4235
+ return;
4236
+ }
4237
+ if (!droppable)
4238
+ this.makeLinkRoom();
4239
+ checkHyperlinkCount(this.linkCount + 1);
4208
4240
  this.book.retainLink();
4241
+ if (droppable) {
4242
+ this.droppable.push(this.links.length);
4243
+ this.droppableLinks.add(copied);
4244
+ }
4209
4245
  this.links.push(copied);
4210
4246
  this.linkedCells.add(copied.cell);
4211
4247
  }
4248
+ /** Links the worksheet holds now, not counting evicted holes. */
4249
+ get linkCount() { return this.links.length - this.evictedLinks + this.internalLinks.length; }
4250
+ /** A full worksheet gives up its latest data-cell link for a link that cannot be dropped. Hyperlinks are serialized after
4251
+ * the rows, so the cell keeps its written value. The entry becomes a hole, so other indexes stay valid until compaction. */
4252
+ makeLinkRoom() {
4253
+ if (this.linkCount < maximumHyperlinks || !this.droppable.length)
4254
+ return;
4255
+ const index = this.droppable.pop(), removed = this.links[index];
4256
+ this.links[index] = undefined;
4257
+ this.evictedLinks++;
4258
+ this.linkedCells.delete(removed.cell);
4259
+ this.book.releaseLink();
4260
+ this.droppedLinks++;
4261
+ }
4262
+ /** One ordered pass removes evicted holes and rebuilds the droppable indexes. */
4263
+ compactLinks() {
4264
+ if (this.evictedLinks) {
4265
+ const kept = [], droppable = [];
4266
+ for (const link of this.links)
4267
+ if (link) {
4268
+ if (this.droppableLinks.has(link))
4269
+ droppable.push(kept.length);
4270
+ kept.push(link);
4271
+ }
4272
+ this.links = kept;
4273
+ this.droppable = droppable;
4274
+ this.evictedLinks = 0;
4275
+ }
4276
+ return this.links;
4277
+ }
4212
4278
  /** @internal */
4213
- get hyperlinks() { return this.links; }
4279
+ get hyperlinks() { return this.compactLinks(); }
4214
4280
  /** @internal */
4215
4281
  get images() { return this.pictures; }
4216
4282
  /** @internal An empty export has no data table; it still emits the declared headers. */
@@ -4261,7 +4327,7 @@ class Worksheet {
4261
4327
  for (const binding of this.chartSources)
4262
4328
  binding.finish();
4263
4329
  this.chartSources.length = 0;
4264
- for (const link of this.links) {
4330
+ for (const link of this.compactLinks()) {
4265
4331
  const position = cellPosition(link.cell);
4266
4332
  if (position.column > this.columns.length || position.row > this.totalRows)
4267
4333
  throw new RangeError("Hyperlinks must address cells within the exported rows and columns.");
@@ -4291,8 +4357,11 @@ class Worksheet {
4291
4357
  await this.buffer.write(xml);
4292
4358
  for (const xml of dataValidationsXml(this.validations, this.headerRows, this.count, detailRanges))
4293
4359
  await this.buffer.write(xml);
4294
- if (this.links.length || this.internalLinks.length)
4295
- await this.buffer.write(hyperlinksXml(this.links, this.book.settings.invalidCharacterPolicy, this.internalLinks));
4360
+ if (this.droppedLinks)
4361
+ notifySynchronously("onHyperlinkOverflow", this.book.settings.onHyperlinkOverflow, Object.freeze({ sheetName: this.name, dropped: this.droppedLinks }));
4362
+ const links = this.compactLinks();
4363
+ if (links.length || this.internalLinks.length)
4364
+ await this.buffer.write(hyperlinksXml(links, this.book.settings.invalidCharacterPolicy, this.internalLinks));
4296
4365
  await this.buffer.write(printXml(this.options.print, this.book.settings.invalidCharacterPolicy));
4297
4366
  if (this.pictures.length || this.nativeCharts.length)
4298
4367
  await this.buffer.write('<drawing r:id="drawing"/>');
@@ -4317,11 +4386,11 @@ class Worksheet {
4317
4386
  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); }
4318
4387
  }
4319
4388
  const _exports = Object.freeze({ Worksheet: Worksheet });
4320
- _modules.set("a61e744201bb537b635b367b1764bd85892101d55e00b8c78faec8be89577376", _exports);
4389
+ _modules.set("d5957683aa1945575924c89c63b427878e6e6e47ef5c229dc524b1879d146499", _exports);
4321
4390
  return _exports;
4322
4391
  })();
4323
4392
 
4324
- const _m45 = _modules.get("1b4698baf9a9c9b3505988abac9f83967c32cf37483d70a949ae89c4485532a4") ?? (() => {
4393
+ const _m45 = _modules.get("c84eae41cd3066f5463d88a1f467117b37dd9e9c9ccd8c0f8a106aa41631fea0") ?? (() => {
4325
4394
  const { escapeOoxmlAttribute, escapeXml, xmlDeclaration } = _m25;
4326
4395
 
4327
4396
  const { cellText, columnName } = _m32;
@@ -4364,7 +4433,7 @@ function tableXml(table, rowCount, policy, headerRow = 1, footer) {
4364
4433
  '" showColumnStripes="' + (options.bandedColumns ? 1 : 0) + '"/></table>';
4365
4434
  }
4366
4435
  const _exports = Object.freeze({ defineTable: defineTable, tableXml: tableXml });
4367
- _modules.set("1b4698baf9a9c9b3505988abac9f83967c32cf37483d70a949ae89c4485532a4", _exports);
4436
+ _modules.set("c84eae41cd3066f5463d88a1f467117b37dd9e9c9ccd8c0f8a106aa41631fea0", _exports);
4368
4437
  return _exports;
4369
4438
  })();
4370
4439
 
@@ -4436,13 +4505,13 @@ _modules.set("0c395783b9d7cc62dd39a21adeb698ad4a61e2c89f7b1fc8712e2eb2ccfe9d92",
4436
4505
  return _exports;
4437
4506
  })();
4438
4507
 
4439
- const _m47 = _modules.get("477ff98f49343b8ec4213008254b57a60dd42d07cb9843b3791d5e5f8e295865") ?? (() => {
4508
+ const _m47 = _modules.get("fd70ccda89f27c6b874c8840ac944b3ec723dbdef3dfe7600f7bdb81f4660c96") ?? (() => {
4440
4509
  const { captureFields } = _m10;
4441
4510
 
4442
4511
  /** @internal The workbook owner captures these settings before validation or adapter merging. */
4443
- const workbookOptionFields = ["signal", "onProgress", "limits", "sink", "dateMode", "compression", "invalidCharacterPolicy", "appProperties", "cellValueWriters", "oversizedText", "creator", "title", "subject", "description", "created", "modified"];
4512
+ const workbookOptionFields = ["signal", "onProgress", "limits", "sink", "dateMode", "compression", "invalidCharacterPolicy", "appProperties", "cellValueWriters", "oversizedText", "hyperlinkOverflow", "onHyperlinkOverflow", "creator", "title", "subject", "description", "created", "modified"];
4444
4513
  /** @internal Worksheet settings also used by the portable sheet owner. */
4445
- const sheetOptionFields = ["columns", "includeHeader", "headerRows", "freezeHeader", "autoFilter", "boldHeader", "headerFill", "headerStyle", "alternatingRowStyle", "rowStyle", "cellStyle", "rowOutline", "maxOutlineLevel", "outlineSummaryBelow", "outlineSummaryRight", "columnOutlines", "rowHeight", "headerHeight", "defaultColumnWidth", "freezeColumns", "table", "autoSize", "footer", "print", "title", "mergedCells", "hyperlinks", "conditionalFormats", "dataValidation"];
4514
+ const sheetOptionFields = ["columns", "includeHeader", "headerRows", "freezeHeader", "autoFilter", "boldHeader", "headerFill", "headerBorder", "headerWrap", "headerStyle", "alternatingRowStyle", "rowStyle", "cellStyle", "rowOutline", "maxOutlineLevel", "outlineSummaryBelow", "outlineSummaryRight", "columnOutlines", "rowHeight", "headerHeight", "defaultColumnWidth", "freezeColumns", "table", "autoSize", "footer", "print", "title", "mergedCells", "hyperlinks", "conditionalFormats", "dataValidation"];
4446
4515
  /** @internal Includes inherited format-specific ceilings before a wrapper combines stream settings. */
4447
4516
  const workbookLimitFields = ["maxRows", "maxCells", "maxTextCharacters", "maxOutputBytes", "maxStyles", "maxSheets", "maxOverflowCharacters", "maxHyperlinks", "maxImageBytes", "maxBufferedCells", "maxBufferedCharacters", "maxMergedRanges", "maxConditionalFormats", "maxDifferentialStyles", "maxCharts", "maxChartPoints", "maxChartTextCharacters", "maxFormulaCharacters", "maxDataValidations", "maxValidationTextCharacters"];
4448
4517
  /** @internal Capture the workbook's known ceilings without dropping supported prototype fields. */
@@ -4455,7 +4524,7 @@ function captureWorkbookOptions(options) {
4455
4524
  return { ...captured, ...(captured.limits === undefined ? {} : { limits: captureWorkbookLimits(captured.limits) }) };
4456
4525
  }
4457
4526
  const _exports = Object.freeze({ workbookOptionFields: workbookOptionFields, sheetOptionFields: sheetOptionFields, workbookLimitFields: workbookLimitFields, captureWorkbookLimits: captureWorkbookLimits, captureWorkbookOptions: captureWorkbookOptions });
4458
- _modules.set("477ff98f49343b8ec4213008254b57a60dd42d07cb9843b3791d5e5f8e295865", _exports);
4527
+ _modules.set("fd70ccda89f27c6b874c8840ac944b3ec723dbdef3dfe7600f7bdb81f4660c96", _exports);
4459
4528
  return _exports;
4460
4529
  })();
4461
4530
 
@@ -4762,7 +4831,7 @@ _modules.set("24f1417c3c320a8a41137c28f70b72091256c63010be0c88b684dce85f54950c",
4762
4831
  return _exports;
4763
4832
  })();
4764
4833
 
4765
- const _m21 = _modules.get("e89ecd2f5e1738c6e88f72ac2bcac70dfaa81b4aa86edf333e9b395cf2212e2a") ?? (() => {
4834
+ const _m21 = _modules.get("a34a46ed9564c388d5f3ca087c70819f8aa897e469ca50f8547233c264a8e8af") ?? (() => {
4766
4835
  const { beginTask, checkAbort, pause, taskYieldDue } = _m4;
4767
4836
 
4768
4837
  const { OfficeIMOError } = _m2;
@@ -4777,7 +4846,7 @@ const { OpcPackage, officeRelationshipsNamespace, relationshipTypes, corePropert
4777
4846
 
4778
4847
  const { escapeOoxmlAttribute, cleanXml, xmlDeclaration } = _m25;
4779
4848
 
4780
- const { StyleRegistry, spreadsheetNamespace } = _m29;
4849
+ const { StyleRegistry, spreadsheetNamespace, normalizeBorder } = _m29;
4781
4850
 
4782
4851
  const { sheetName, assertXlsxValue, copyValue } = _m32;
4783
4852
 
@@ -4818,6 +4887,8 @@ function captureSheet(options, policy) {
4818
4887
  return { ...captured, columns,
4819
4888
  ...(captured.columnOutlines === undefined ? {} : { columnOutlines: captureColumnOutlines(captured.columnOutlines, columns.length) }),
4820
4889
  ...(captured.headerRows === undefined ? {} : { headerRows: captureTableSpans(captured.headerRows, columns.length) }),
4890
+ // Preflight and every header style read this one snapshot of the edges.
4891
+ ...(captured.headerBorder === undefined ? {} : { headerBorder: normalizeBorder(captured.headerBorder) }),
4821
4892
  ...(footer ? { footer: { ...footer,
4822
4893
  ...(footer.rows === undefined ? {} : { rows: captureTableSpans(footer.rows, columns.length) }),
4823
4894
  ...(footer.values === undefined ? {} : { values: footer.values.map(copyValue) }) } } : {}),
@@ -4893,6 +4964,10 @@ class Workbook {
4893
4964
  throw new RangeError("compression must be auto or store.");
4894
4965
  if (options.oversizedText !== undefined && !["reject", "preserve"].includes(options.oversizedText))
4895
4966
  throw new RangeError("oversizedText must be reject or preserve.");
4967
+ if (options.hyperlinkOverflow !== undefined && !["reject", "drop"].includes(options.hyperlinkOverflow))
4968
+ throw new RangeError("hyperlinkOverflow must be reject or drop.");
4969
+ if (options.onHyperlinkOverflow !== undefined && typeof options.onHyperlinkOverflow !== "function")
4970
+ throw new TypeError("onHyperlinkOverflow must be a function.");
4896
4971
  cleanXml("", policy);
4897
4972
  corePropertiesXml(options, policy);
4898
4973
  this.budget = new ExportBudget(options.limits);
@@ -4970,6 +5045,8 @@ class Workbook {
4970
5045
  }
4971
5046
  /** @internal Reserve a preflighted worksheet batch or one row hyperlink. */
4972
5047
  retainLink(count = 1) { this.checkLinks(count); this.links += count; }
5048
+ /** @internal A worksheet dropped a data-cell link it had retained. */
5049
+ releaseLink() { this.links--; }
4973
5050
  /** @internal */
4974
5051
  checkImage(bytes) {
4975
5052
  if (this.settings.limits?.maxImageBytes !== undefined && this.imageBytes + bytes > this.settings.limits.maxImageBytes)
@@ -5243,11 +5320,11 @@ class Workbook {
5243
5320
  }
5244
5321
  }
5245
5322
  const _exports = Object.freeze({ Workbook: Workbook });
5246
- _modules.set("e89ecd2f5e1738c6e88f72ac2bcac70dfaa81b4aa86edf333e9b395cf2212e2a", _exports);
5323
+ _modules.set("a34a46ed9564c388d5f3ca087c70819f8aa897e469ca50f8547233c264a8e8af", _exports);
5247
5324
  return _exports;
5248
5325
  })();
5249
5326
 
5250
- const _m51 = _modules.get("a10003e971cd5ec2cee127bc9b029a0aa06fe3d50112838929d7a04a55e177c0") ?? (() => {
5327
+ const _m51 = _modules.get("d6884428c3e4d15a691ecf2523372a03b32de22a890edfbfc9961f2dc92711c2") ?? (() => {
5251
5328
  const { ExportCell, assertScalar } = _m5;
5252
5329
 
5253
5330
  const { captureWorkbookOptions, sheetOptionFields } = _m47;
@@ -5269,7 +5346,7 @@ function value(result) {
5269
5346
  function portableSheet(options = {}) {
5270
5347
  options = captureFields(options, sheetOptionFields);
5271
5348
  if (options.headerStyle !== undefined)
5272
- throw new TypeError("Workbook-local header styles require the advanced Workbook API; use boldHeader and headerFill.");
5349
+ throw new TypeError("Workbook-local header styles require the advanced Workbook API; use boldHeader, headerFill, headerBorder and headerWrap.");
5273
5350
  style(options.alternatingRowStyle);
5274
5351
  style(options.title?.style);
5275
5352
  style(options.footer?.style);
@@ -5296,11 +5373,11 @@ function portableWorkbook(options = {}) {
5296
5373
  return { ...options, cellValueWriters: wrapped };
5297
5374
  }
5298
5375
  const _exports = Object.freeze({ portableSheet: portableSheet, portableWorkbook: portableWorkbook });
5299
- _modules.set("a10003e971cd5ec2cee127bc9b029a0aa06fe3d50112838929d7a04a55e177c0", _exports);
5376
+ _modules.set("d6884428c3e4d15a691ecf2523372a03b32de22a890edfbfc9961f2dc92711c2", _exports);
5300
5377
  return _exports;
5301
5378
  })();
5302
5379
 
5303
- const _m50 = _modules.get("5bfd5c9c5e179305b9bebd6cb0d6a0d75e974b223e119e0fd4fbb773325f1e63") ?? (() => {
5380
+ const _m50 = _modules.get("b9b1793c41e466048fe823422088a6fcc1fd8393c67293df3f0cd83a5d5ec7e1") ?? (() => {
5304
5381
  const { withDestination } = _m3;
5305
5382
 
5306
5383
  const { copyColumns } = _m11;
@@ -5355,11 +5432,11 @@ async function writeXlsxTo(rows, destination, configuration) {
5355
5432
  });
5356
5433
  }
5357
5434
  const _exports = Object.freeze({ writeXlsx: writeXlsx, writeXlsxTo: writeXlsxTo });
5358
- _modules.set("5bfd5c9c5e179305b9bebd6cb0d6a0d75e974b223e119e0fd4fbb773325f1e63", _exports);
5435
+ _modules.set("b9b1793c41e466048fe823422088a6fcc1fd8393c67293df3f0cd83a5d5ec7e1", _exports);
5359
5436
  return _exports;
5360
5437
  })();
5361
5438
 
5362
- const _m53 = _modules.get("dd34d5fd89869a0f953f3f2b3fd27ac83be29e68f76c9087fae3d33095aeda7c") ?? (() => {
5439
+ const _m53 = _modules.get("ba0e1f29c8de5d46b966b7b097260529e42b80f662e92a7f9e8add22df747a50") ?? (() => {
5363
5440
  const { assertGroupedReportSource } = _m8;
5364
5441
 
5365
5442
  const { captureFields } = _m10;
@@ -5448,11 +5525,11 @@ function prepareGroupedSheet(report, configuration, maxConditionalFormats = 1000
5448
5525
  ...(options.grandTotalStyle ? { grandTotalStyle: copyStylePatch(options.grandTotalStyle) } : {}) };
5449
5526
  }
5450
5527
  const _exports = Object.freeze({ groupedOptionFields: groupedOptionFields, prepareGroupedSheet: prepareGroupedSheet });
5451
- _modules.set("dd34d5fd89869a0f953f3f2b3fd27ac83be29e68f76c9087fae3d33095aeda7c", _exports);
5528
+ _modules.set("ba0e1f29c8de5d46b966b7b097260529e42b80f662e92a7f9e8add22df747a50", _exports);
5452
5529
  return _exports;
5453
5530
  })();
5454
5531
 
5455
- const _m52 = _modules.get("2ba62cdf88d559804bb84b20e9816b2de0f232401b7431ac414699a607d554a4") ?? (() => {
5532
+ const _m52 = _modules.get("d7cfa6a7b1be9758925a4ccb860a80a33eb0de2c88c80cc55e438213595f2b71") ?? (() => {
5456
5533
  const { groupedReportOperation } = _m8;
5457
5534
 
5458
5535
  const { checkAbort, withAbort } = _m4;
@@ -5625,14 +5702,14 @@ async function writeGroupedXlsxTo(report, destination, options) {
5625
5702
  return withDestination(destination, async (sink) => (await write(report, prepared, sink)).result);
5626
5703
  }
5627
5704
  const _exports = Object.freeze({ addGroupedXlsx: addGroupedXlsx, writeGroupedXlsx: writeGroupedXlsx, writeGroupedXlsxTo: writeGroupedXlsxTo });
5628
- _modules.set("2ba62cdf88d559804bb84b20e9816b2de0f232401b7431ac414699a607d554a4", _exports);
5705
+ _modules.set("d7cfa6a7b1be9758925a4ccb860a80a33eb0de2c88c80cc55e438213595f2b71", _exports);
5629
5706
  return _exports;
5630
5707
  })();
5631
5708
 
5632
- const _m20 = _modules.get("d6587a933b36ccfdba9a2a252389924ac8461f672b3a500082cceb5e53c8b0b6") ?? (() => {
5709
+ const _m20 = _modules.get("edf1bf5cb6d749de0e6823397df6610a6c1cc88768898c1b4d7083ee96ef6759") ?? (() => {
5633
5710
 
5634
5711
  const _exports = Object.freeze({ Workbook: _m21.Workbook, writeXlsx: _m50.writeXlsx, writeXlsxTo: _m50.writeXlsxTo, writeGroupedXlsx: _m52.writeGroupedXlsx, writeGroupedXlsxTo: _m52.writeGroupedXlsxTo, addGroupedXlsx: _m52.addGroupedXlsx, createGroupedReport: _m8.createGroupedReport, Worksheet: _m35.Worksheet, Cell: _m32.Cell, FormulaCell: _m33.FormulaCell, StyleRegistry: _m29.StyleRegistry, NumberFormats: _m29.NumberFormats, saveBlob: _m1.saveBlob, ExportCell: _m5.ExportCell });
5635
- _modules.set("d6587a933b36ccfdba9a2a252389924ac8461f672b3a500082cceb5e53c8b0b6", _exports);
5712
+ _modules.set("edf1bf5cb6d749de0e6823397df6610a6c1cc88768898c1b4d7083ee96ef6759", _exports);
5636
5713
  return _exports;
5637
5714
  })();
5638
5715
 
@@ -5745,7 +5822,7 @@ _modules.set("278e6adc6a5d4491e688589ef165bd1aa9cc74f557da6f9d6bdf53ecc0c6df47",
5745
5822
  return _exports;
5746
5823
  })();
5747
5824
 
5748
- const _m56 = _modules.get("4a089607f7cbe50e13d4382d1cc4e5f6ce32c5773bbec2df84178710f54d9a38") ?? (() => {
5825
+ const _m56 = _modules.get("6c92204b587bb12cfa85c60eb1fd921804dfa51304538c7be3353e2927551b02") ?? (() => {
5749
5826
  const { OfficeIMOError } = _m2;
5750
5827
 
5751
5828
  const { ExportBudget } = _m9;
@@ -5772,12 +5849,16 @@ const sizes = {
5772
5849
  };
5773
5850
  /** @internal Shared capture schema for thin format adapters and the grouped writer. */
5774
5851
  const pdfOptionFields = ["columns", "signal", "onProgress", "limits", "textShaper", "textDirection", "pageSize", "orientation", "margins", "fonts", "tagged", "fontSize",
5775
- "title", "messageTop", "messageBottom", "includeHeader", "headerRows", "footer", "headerPresentation", "footerPresentation", "alternateRowColor", "padding",
5852
+ "title", "metadataTitle", "messageTop", "messageBottom", "includeHeader", "headerRows", "footer", "headerPresentation", "footerPresentation", "alternateRowColor", "padding",
5776
5853
  "columnWidths", "wideTable", "pageHeader", "pageFooter", "pageNumbers", "pageNumberLabels", "booleanText", "formatValue", "formatRuns", "compression", "paragraphStyles"];
5777
5854
  /** @internal Complete PDF limit schema used when a host combines format and shared limits. */
5778
5855
  const pdfLimitFields = ["maxRows", "maxCells", "maxTextCharacters", "maxOutputBytes", "maxPages", "maxColumns", "maxTableBands", "maxTableWindowRows", "maxCellCharacters", "maxTextRuns", "maxGroupBlocks", "maxRowLines",
5779
5856
  "maxFontBytes", "maxPageBytes", "maxHyperlinks", "maxImageBytes", "maxImagePixels", "maxImageWorkingBytes", "maxVectorCommands", "maxDrawingElements", "maxStructureElements",
5780
5857
  "maxMarkedContentReferences", "maxSections", "maxBookmarks", "maxListItems", "maxParagraphStyles"];
5858
+ /** @internal Default ceilings shared by the drawing writer and its producers. */
5859
+ const pdfDrawingLimits = Object.freeze({ maxVectorCommands: 100000, maxDrawingElements: 100000 });
5860
+ /** @internal Maximum number of retained drawing levels including the leaf. */
5861
+ const pdfDrawingMaxDepth = 32;
5781
5862
  /** @internal Capture supported structural properties once, including class-based options with prototype accessors. */
5782
5863
  function capturePdfOptions(input) {
5783
5864
  if (!input || typeof input !== "object" || Array.isArray(input))
@@ -5888,7 +5969,7 @@ function settings(input, document = false) {
5888
5969
  footerPresentation: Object.freeze({ background: "eef2f6", bold: true, ...presentation(configuration.footerPresentation) }) };
5889
5970
  const budget = new ExportBudget(options.limits);
5890
5971
  const limits = { maxPages: 10000, maxColumns: 1024, maxTableBands: 64, maxTableWindowRows: 256, maxCellCharacters: 1000000, maxTextRuns: 10000, maxGroupBlocks: 256, maxRowLines: 100000, maxFontBytes: 16 * 1024 * 1024, maxPageBytes: 8 * 1024 * 1024, maxHyperlinks: 100000,
5891
- maxImageBytes: 32 * 1024 * 1024, maxImagePixels: 16 * 1024 * 1024, maxVectorCommands: 100000, maxDrawingElements: 100000,
5972
+ maxImageBytes: 32 * 1024 * 1024, maxImagePixels: 16 * 1024 * 1024, ...pdfDrawingLimits,
5892
5973
  maxStructureElements: 1000000, maxMarkedContentReferences: 2000000,
5893
5974
  maxListItems: 100000, maxParagraphStyles: 256, maxSections: 1000, maxBookmarks: 10000 };
5894
5975
  for (const key of Object.keys(limits)) {
@@ -5916,7 +5997,7 @@ function settings(input, document = false) {
5916
5997
  const fontSize = positive(options.fontSize ?? 9, "Font size", 144), padding = options.padding ?? 4;
5917
5998
  if (!Number.isFinite(padding) || padding < 0 || padding > 72)
5918
5999
  throw new RangeError("PDF padding must be from 0 through 72 points.");
5919
- for (const key of ["title", "messageTop", "messageBottom"])
6000
+ for (const key of ["title", "metadataTitle", "messageTop", "messageBottom"])
5920
6001
  if (options[key] !== undefined && typeof options[key] !== "string")
5921
6002
  throw new TypeError(key + " must be text.");
5922
6003
  for (const key of ["pageHeader", "pageFooter"])
@@ -5952,8 +6033,8 @@ function settings(input, document = false) {
5952
6033
  repeatedColumns: document ? Object.freeze([]) : repeatedColumns(options.wideTable, columns),
5953
6034
  limits: { ...limits, ...(maxImageWorkingBytes === undefined ? {} : { maxImageWorkingBytes }) }, budget };
5954
6035
  }
5955
- const _exports = Object.freeze({ positive: _m58.positive, color: _m58.color, presentation: _m58.presentation, pdfOptionFields: pdfOptionFields, pdfLimitFields: pdfLimitFields, capturePdfOptions: capturePdfOptions, capturePdfLimits: capturePdfLimits, captureWideTable: captureWideTable, settings: settings });
5956
- _modules.set("4a089607f7cbe50e13d4382d1cc4e5f6ce32c5773bbec2df84178710f54d9a38", _exports);
6036
+ const _exports = Object.freeze({ positive: _m58.positive, color: _m58.color, presentation: _m58.presentation, pdfOptionFields: pdfOptionFields, pdfLimitFields: pdfLimitFields, pdfDrawingLimits: pdfDrawingLimits, pdfDrawingMaxDepth: pdfDrawingMaxDepth, capturePdfOptions: capturePdfOptions, capturePdfLimits: capturePdfLimits, captureWideTable: captureWideTable, settings: settings });
6037
+ _modules.set("6c92204b587bb12cfa85c60eb1fd921804dfa51304538c7be3353e2927551b02", _exports);
5957
6038
  return _exports;
5958
6039
  })();
5959
6040
 
@@ -7278,7 +7359,7 @@ _modules.set("59911f0fe023545e9e97521b268551078bdc4c5f303e446a13b7d52f905e8070",
7278
7359
  return _exports;
7279
7360
  })();
7280
7361
 
7281
- const _m62 = _modules.get("4d4736e6b8e2aaecc6f6c1b124b7e6bc0a5e141dcc725edf0ad4847d87fca1b3") ?? (() => {
7362
+ const _m62 = _modules.get("7825c87ba92a9992baf6b5c8a5e146948268985c31584ef9c8bf395359942e4f") ?? (() => {
7282
7363
  const { NotSupportedError, OfficeIMOError } = _m2;
7283
7364
 
7284
7365
  const { fontProgram } = _m63;
@@ -7479,7 +7560,7 @@ class PdfFontResources {
7479
7560
  this.fontBytes += bytes;
7480
7561
  this.registered.add(font);
7481
7562
  }
7482
- select(bold = false, italic = false, explicit) {
7563
+ select(bold = false, italic = false, explicit, standardForMissingFace = false) {
7483
7564
  if (explicit)
7484
7565
  this.registerFont(explicit);
7485
7566
  let selections = this.selections;
@@ -7489,10 +7570,13 @@ class PdfFontResources {
7489
7570
  if (!found)
7490
7571
  this.explicitSelections.set(explicit, selections);
7491
7572
  }
7492
- const key = (bold ? 2 : 0) | (italic ? 1 : 0), existing = selections.get(key);
7573
+ const fallback = standardForMissingFace && !explicit && this.fonts !== undefined &&
7574
+ this.fonts[bold ? italic ? "boldItalic" : "bold" : italic ? "italic" : "regular"] === undefined;
7575
+ const key = (bold ? 2 : 0) | (italic ? 1 : 0) | (fallback ? 4 : 0), existing = selections.get(key);
7493
7576
  if (existing)
7494
7577
  return existing;
7495
- const { font, syntheticBold, syntheticItalic } = explicit ? { font: explicit, syntheticBold: bold, syntheticItalic: italic } : selectFont(this.fonts, bold, italic);
7578
+ const { font, syntheticBold, syntheticItalic } = explicit ? { font: explicit, syntheticBold: bold, syntheticItalic: italic } :
7579
+ selectFont(fallback ? undefined : this.fonts, bold, italic);
7496
7580
  const shared = font ? this.programs.get(font) : undefined;
7497
7581
  const resource = new PdfFontResource(this.resources.length + 1, bold, italic, font, this.objects, syntheticBold, syntheticItalic, shared, this.signal);
7498
7582
  if (!shared) {
@@ -7506,7 +7590,7 @@ class PdfFontResources {
7506
7590
  dictionary() { return "<< " + this.resources.map(f => "/" + f.name + " " + f.object + " 0 R").join(" ") + " >>"; }
7507
7591
  }
7508
7592
  const _exports = Object.freeze({ PdfFontResource: PdfFontResource, PdfFontResources: PdfFontResources });
7509
- _modules.set("4d4736e6b8e2aaecc6f6c1b124b7e6bc0a5e141dcc725edf0ad4847d87fca1b3", _exports);
7593
+ _modules.set("7825c87ba92a9992baf6b5c8a5e146948268985c31584ef9c8bf395359942e4f", _exports);
7510
7594
  return _exports;
7511
7595
  })();
7512
7596
 
@@ -7835,7 +7919,7 @@ _modules.set("8be3fb029e08d100ce8ffcf50916d5ba7f7bc00d62156cc33815fd58554a9ed6",
7835
7919
  return _exports;
7836
7920
  })();
7837
7921
 
7838
- const _m71 = _modules.get("0a1c79b51ac9a164b86197239117df6497f45ca2892b423b1ec77a663ccc1c47") ?? (() => {
7922
+ const _m71 = _modules.get("abbfad7ffb3c318822659c9fbde9126630ce2c137dc2e2b88402148424255e2d") ?? (() => {
7839
7923
  const { NotSupportedError, OfficeIMOError } = _m2;
7840
7924
 
7841
7925
  const { copyExportLink } = _m7;
@@ -8027,11 +8111,11 @@ async function wrapPdfText(captured, fonts, size, width, settings, wrap = true)
8027
8111
  return lines;
8028
8112
  }
8029
8113
  const _exports = Object.freeze({ capturePdfText: capturePdfText, wrapPdfText: wrapPdfText });
8030
- _modules.set("0a1c79b51ac9a164b86197239117df6497f45ca2892b423b1ec77a663ccc1c47", _exports);
8114
+ _modules.set("abbfad7ffb3c318822659c9fbde9126630ce2c137dc2e2b88402148424255e2d", _exports);
8031
8115
  return _exports;
8032
8116
  })();
8033
8117
 
8034
- const _m73 = _modules.get("2f40af05ba09102fe440c1d46385b64cecdd233371771796c9ae4e8d523f2cea") ?? (() => {
8118
+ const _m73 = _modules.get("04b189837f06067364240b6731efdf86d61d81fd0848fac3666f25c5f27817b8") ?? (() => {
8035
8119
  const { OfficeIMOError } = _m2;
8036
8120
 
8037
8121
  const { wrapPdfText } = _m71;
@@ -8126,11 +8210,11 @@ function alignBandBlocks(bands, settings) {
8126
8210
  cells: row.cells.map(cell => ({ ...cell, height: heights.slice(index, index + (cell.rowSpan ?? 1)).reduce((sum, value) => sum + value, 0) })) })));
8127
8211
  }
8128
8212
  const _exports = Object.freeze({ planTableBands: planTableBands, projectBandRows: projectBandRows, alignBandBlocks: alignBandBlocks });
8129
- _modules.set("2f40af05ba09102fe440c1d46385b64cecdd233371771796c9ae4e8d523f2cea", _exports);
8213
+ _modules.set("04b189837f06067364240b6731efdf86d61d81fd0848fac3666f25c5f27817b8", _exports);
8130
8214
  return _exports;
8131
8215
  })();
8132
8216
 
8133
- const _m69 = _modules.get("ad81357e627d3100e1068a8ce521aa1c1cd65de5c6c6ab36f807a3e5da50d874") ?? (() => {
8217
+ const _m69 = _modules.get("6fd77694f46f8c87510a82e8a58a3c424099d6172bfb1942f92d048b39169945") ?? (() => {
8134
8218
  const { ExportCell } = _m5;
8135
8219
 
8136
8220
  const { copyExportLink } = _m7;
@@ -8361,7 +8445,7 @@ class PdfTableLayout {
8361
8445
  }
8362
8446
  }
8363
8447
  const _exports = Object.freeze({ PdfTableLayout: PdfTableLayout });
8364
- _modules.set("ad81357e627d3100e1068a8ce521aa1c1cd65de5c6c6ab36f807a3e5da50d874", _exports);
8448
+ _modules.set("6fd77694f46f8c87510a82e8a58a3c424099d6172bfb1942f92d048b39169945", _exports);
8365
8449
  return _exports;
8366
8450
  })();
8367
8451
 
@@ -8717,7 +8801,7 @@ _modules.set("c68d18d668366fb9b96d1b53c79dc6305f84cb83c05e4942fcf1cdf96ed1a73f",
8717
8801
  return _exports;
8718
8802
  })();
8719
8803
 
8720
- const _m79 = _modules.get("a66257a32f03d958aa57be4de9da7f80b708cebca26b5cc6404de0ee11bfe052") ?? (() => {
8804
+ const _m79 = _modules.get("8fc594bfca7312071f0f128ad25fb929d023d176323e66e389cddd27032a4d15") ?? (() => {
8721
8805
  const { settings } = _m56;
8722
8806
 
8723
8807
  /** @internal Every section derives from captured document defaults, never the preceding section. */
@@ -8732,11 +8816,11 @@ function sectionSettings(base, section) {
8732
8816
  return { ...base, page: derived.page, margins: derived.margins, options };
8733
8817
  }
8734
8818
  const _exports = Object.freeze({ sectionSettings: sectionSettings });
8735
- _modules.set("a66257a32f03d958aa57be4de9da7f80b708cebca26b5cc6404de0ee11bfe052", _exports);
8819
+ _modules.set("8fc594bfca7312071f0f128ad25fb929d023d176323e66e389cddd27032a4d15", _exports);
8736
8820
  return _exports;
8737
8821
  })();
8738
8822
 
8739
- const _m74 = _modules.get("3ed7114181be5a3066742336da574fef7f2fc04ee6dfc5e64211f3bedad4cab9") ?? (() => {
8823
+ const _m74 = _modules.get("c16c0303d9d4be12ab9e0bab7cfdac73b252ed233c9689e3e0141cc8115aa941") ?? (() => {
8740
8824
  const { OfficeIMOError } = _m2;
8741
8825
 
8742
8826
  const { checkAbort } = _m4;
@@ -8797,6 +8881,7 @@ class PdfPages {
8797
8881
  rectangleLefts;
8798
8882
  rectangleColumns = [];
8799
8883
  externalObjects = new Map();
8884
+ opacityStates = new Map();
8800
8885
  bandFlow;
8801
8886
  bandCellBudget = false;
8802
8887
  tableElement;
@@ -9379,6 +9464,20 @@ class PdfPages {
9379
9464
  }
9380
9465
  async pageBreak() { await this.ensureStarted(); await this.finishPage(); await this.start(false); }
9381
9466
  registerXObject(name, id) { this.externalObjects.set(name, id); }
9467
+ /** One shared constant-opacity graphics state per serialized alpha value. */
9468
+ opacityState(alpha) {
9469
+ const value = pdfNumber(alpha);
9470
+ let name = this.opacityStates.get(value);
9471
+ if (!name) {
9472
+ name = "GA" + (this.opacityStates.size + 1);
9473
+ this.opacityStates.set(value, name);
9474
+ }
9475
+ return name;
9476
+ }
9477
+ graphicsStates() {
9478
+ const entries = [...this.opacityStates].map(([alpha, name]) => "/" + name + " << /ca " + alpha + " /CA " + alpha + " >>");
9479
+ return entries.length ? " /ExtGState << " + entries.join(" ") + " >>" : "";
9480
+ }
9382
9481
  /** Height after the existing fit-to-page graphic policy, used by heading keep constraints. */
9383
9482
  graphicHeight(width, height) {
9384
9483
  const { page, margins } = this.settings;
@@ -9474,7 +9573,7 @@ class PdfPages {
9474
9573
  }
9475
9574
  }
9476
9575
  const _exports = Object.freeze({ PdfPages: PdfPages });
9477
- _modules.set("3ed7114181be5a3066742336da574fef7f2fc04ee6dfc5e64211f3bedad4cab9", _exports);
9576
+ _modules.set("c16c0303d9d4be12ab9e0bab7cfdac73b252ed233c9689e3e0141cc8115aa941", _exports);
9478
9577
  return _exports;
9479
9578
  })();
9480
9579
 
@@ -9917,7 +10016,7 @@ _modules.set("52c78ca6833cee7e5a96b657e2c00172d550176daf2c95e742692f8416977bea",
9917
10016
  return _exports;
9918
10017
  })();
9919
10018
 
9920
- const _m59 = _modules.get("afdad27eb363e8de0c3bd69ebf358860eb76f5c6fb29f43a87635807cb7fc273") ?? (() => {
10019
+ const _m59 = _modules.get("3de6cb5a744388b84e9e2295a2e580e70ab993d44bbb4c94da5f98daba11c350") ?? (() => {
9921
10020
  const { PdfObjects, unicodeHex } = _m60;
9922
10021
 
9923
10022
  const { PdfFontResources } = _m62;
@@ -9969,22 +10068,23 @@ class PdfWriteSession {
9969
10068
  await pages.finish();
9970
10069
  for (const font of fonts.resources)
9971
10070
  await font.write(objects, options.compression !== false);
9972
- await objects.object(this.resources, "<< /Font " + fonts.dictionary() + pages.xobjects() + " >>");
10071
+ await objects.object(this.resources, "<< /Font " + fonts.dictionary() + pages.xobjects() + pages.graphicsStates() + " >>");
9973
10072
  await objects.object(this.parent, "<< /Type /Pages /Count " + pages.references.length + " /Kids [" + pages.references.map(id => id + " 0 R").join(" ") + "] >>");
9974
10073
  if (this.structure)
9975
10074
  await this.structure.finish();
9976
10075
  await this.outlines.finish();
9977
10076
  await objects.object(this.root, "<< /Type /Catalog /Pages " + this.parent + " 0 R" + (this.structure?.catalogDictionary ?? "") + this.outlines.catalogDictionary + " >>");
9978
- await objects.object(this.info, "<< /Producer (OfficeIMO.js)" + (options.title === undefined ? "" : " /Title <feff" + unicodeHex(options.title) + ">") + " >>");
10077
+ const title = options.metadataTitle ?? options.title;
10078
+ await objects.object(this.info, "<< /Producer (OfficeIMO.js)" + (title === undefined ? "" : " /Title <feff" + unicodeHex(title) + ">") + " >>");
9979
10079
  await objects.finish(this.root, this.info);
9980
10080
  }
9981
10081
  }
9982
10082
  const _exports = Object.freeze({ PdfWriteSession: PdfWriteSession });
9983
- _modules.set("afdad27eb363e8de0c3bd69ebf358860eb76f5c6fb29f43a87635807cb7fc273", _exports);
10083
+ _modules.set("3de6cb5a744388b84e9e2295a2e580e70ab993d44bbb4c94da5f98daba11c350", _exports);
9984
10084
  return _exports;
9985
10085
  })();
9986
10086
 
9987
- const _m55 = _modules.get("45cf9fd6b6293c1a83bc8554e1bcb5cf119f44701fbad7849f39a712cab5074b") ?? (() => {
10087
+ const _m55 = _modules.get("01ffda1779a340d72e953fd6e02429f341c89fcab28eb0fce4dc8beb65a5fd43") ?? (() => {
9988
10088
  const { BlobByteSink, withDestination } = _m3;
9989
10089
 
9990
10090
  const { beginTask, checkAbort, consumeRows, pause, taskYieldDue } = _m4;
@@ -10049,11 +10149,11 @@ async function writePdfTo(rows, destination, configuration) {
10049
10149
  });
10050
10150
  }
10051
10151
  const _exports = Object.freeze({ writePdf: writePdf, writePdfTo: writePdfTo });
10052
- _modules.set("45cf9fd6b6293c1a83bc8554e1bcb5cf119f44701fbad7849f39a712cab5074b", _exports);
10152
+ _modules.set("01ffda1779a340d72e953fd6e02429f341c89fcab28eb0fce4dc8beb65a5fd43", _exports);
10053
10153
  return _exports;
10054
10154
  })();
10055
10155
 
10056
- const _m86 = _modules.get("749d1ec5422c0087787f525ef42e3b8d3a94d2b70eb5e42d2e3723a870777ad6") ?? (() => {
10156
+ const _m86 = _modules.get("6b0244b5ec6d550c705b4e4cbb47997331f1ecd99e2bf8a06f7c646eebbffbf8") ?? (() => {
10057
10157
  const { NotSupportedError, OfficeIMOError } = _m2;
10058
10158
 
10059
10159
  const { checkAbort, pause, taskYieldDue, withAbort } = _m4;
@@ -10062,15 +10162,10 @@ const { Crc32 } = _m28;
10062
10162
 
10063
10163
  const signature = [137, 80, 78, 71, 13, 10, 26, 10];
10064
10164
  const unsupportedChunks = new Set(["PLTE", "tRNS", "iCCP", "sRGB", "gAMA", "cHRM", "cICP", "mDCV", "cLLI", "sBIT", "eXIf", "acTL", "fcTL", "fdAT"]);
10065
- /** Decode the static unprofiled 8-bit RGB/RGBA profile without canvas or a second compression engine. */
10066
- async function pngPixels(inputSource, maxPixels, signal, maxWorkingBytes) {
10165
+ /** Decode an owned static unprofiled PNG without canvas or a second compression engine. */
10166
+ async function pngPixels(source, shape, signal) {
10067
10167
  checkAbort(signal);
10068
- const shape = pngShape(inputSource, maxPixels);
10069
10168
  const imagePixels = shape.width * shape.height;
10070
- const workingBytes = inputSource.length + imagePixels * shape.components + (shape.components === 4 ? shape.width * 8 : 0);
10071
- if (maxWorkingBytes !== undefined && workingBytes > maxWorkingBytes)
10072
- throw new OfficeIMOError("RESOURCE_LIMIT", "maxImageWorkingBytes exceeded by PNG source, image planes and scanlines.");
10073
- const source = new Uint8Array(inputSource);
10074
10169
  const header = await pngHeader(source, shape, signal);
10075
10170
  checkAbort(signal);
10076
10171
  let stream;
@@ -10084,9 +10179,6 @@ async function pngPixels(inputSource, maxPixels, signal, maxWorkingBytes) {
10084
10179
  }
10085
10180
  const { width, height, components } = header, rowBytes = width * components;
10086
10181
  const expected = (rowBytes + 1) * height;
10087
- // All dimensions and the exact filtered length are bounded before allocating decoded pixels.
10088
- if (!Number.isSafeInteger(expected) || expected > 0x7fffffff)
10089
- throw new OfficeIMOError("RESOURCE_LIMIT", "PNG filtered data exceeds the supported decoded byte length.");
10090
10182
  // RGBA is reconstructed one scanline at a time directly into PDF RGB/alpha planes.
10091
10183
  // It never retains an additional full interleaved RGBA image.
10092
10184
  const pixels = new Uint8Array(width * height * 3), alpha = components === 4 ? new Uint8Array(imagePixels) : undefined;
@@ -10234,20 +10326,55 @@ async function verifyPngZlibEnd(source, header, expected, signal) {
10234
10326
  reader.releaseLock();
10235
10327
  }
10236
10328
  }
10329
+ function pngChunk(source, view, offset) {
10330
+ if (offset + 12 > source.length)
10331
+ throw new TypeError("Truncated PNG chunk.");
10332
+ const length = view.getUint32(offset), end = offset + 12 + length;
10333
+ if (length > 0x7fffffff || end > source.length)
10334
+ throw new TypeError("Truncated or oversized PNG chunk.");
10335
+ const type = String.fromCharCode(...source.subarray(offset + 4, offset + 8));
10336
+ if (!/^[A-Za-z]{2}[A-Z][A-Za-z]$/.test(type))
10337
+ throw new TypeError("Invalid PNG chunk type.");
10338
+ return { length, end, type };
10339
+ }
10340
+ function checkAncillaryChunk(type) {
10341
+ if (unsupportedChunks.has(type))
10342
+ throw new NotSupportedError("PNG chunk " + type + "; normalize color, orientation, transparency or animation first");
10343
+ if (type.charCodeAt(0) < 97)
10344
+ throw new NotSupportedError("Required PNG chunk " + type);
10345
+ }
10346
+ /** Check the image profile for SVG placement without inflating pixels. Embedding still verifies CRCs and image data. */
10347
+ function pngEmbeddableSize(source) {
10348
+ const shape = pngShape(source, Infinity);
10349
+ const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
10350
+ let hasData = false, dataClosed = false;
10351
+ for (let offset = 33; offset < source.length;) {
10352
+ const { length, end, type } = pngChunk(source, view, offset);
10353
+ if (type === "IEND") {
10354
+ if (length === 0 && hasData && end === source.length)
10355
+ return shape;
10356
+ break;
10357
+ }
10358
+ if (type === "IDAT") {
10359
+ if (dataClosed)
10360
+ throw new TypeError("PNG IDAT chunks must be consecutive.");
10361
+ hasData = true;
10362
+ }
10363
+ else {
10364
+ checkAncillaryChunk(type);
10365
+ dataClosed ||= hasData;
10366
+ }
10367
+ offset = end;
10368
+ }
10369
+ throw new TypeError("PNG requires a final empty IEND after IDAT.");
10370
+ }
10237
10371
  /** Verify the complete source and critical chunk order before any decompressed image allocation. */
10238
10372
  async function pngHeader(source, shape, signal) {
10239
10373
  const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
10240
10374
  let firstData = 0, dataEnd = 0, lastDataByte = -1, dataClosed = false;
10241
10375
  for (let offset = 8; offset < source.length;) {
10242
10376
  checkAbort(signal);
10243
- if (offset + 12 > source.length)
10244
- throw new TypeError("Truncated PNG chunk.");
10245
- const length = view.getUint32(offset), end = offset + 12 + length;
10246
- if (length > 0x7fffffff || end > source.length)
10247
- throw new TypeError("Truncated or oversized PNG chunk.");
10248
- const type = String.fromCharCode(...source.subarray(offset + 4, offset + 8));
10249
- if (!/^[A-Za-z]{2}[A-Z][A-Za-z]$/.test(type))
10250
- throw new TypeError("Invalid PNG chunk type.");
10377
+ const { length, end, type } = pngChunk(source, view, offset);
10251
10378
  const crc = new Crc32();
10252
10379
  for (let p = offset + 4; p < end - 4; p += 65536) {
10253
10380
  crc.update(source.subarray(p, Math.min(end - 4, p + 65536)));
@@ -10279,17 +10406,14 @@ async function pngHeader(source, shape, signal) {
10279
10406
  throw new TypeError("PNG requires a final empty IEND after IDAT.");
10280
10407
  return { ...shape, firstData, dataEnd, lastDataByte };
10281
10408
  }
10282
- if (unsupportedChunks.has(type))
10283
- throw new NotSupportedError("PNG chunk " + type + "; normalize color, orientation, transparency or animation first");
10284
- if ((source[offset + 4] & 32) === 0)
10285
- throw new NotSupportedError("Required PNG chunk " + type);
10409
+ checkAncillaryChunk(type);
10286
10410
  }
10287
10411
  offset = end;
10288
10412
  }
10289
10413
  throw new TypeError("PNG requires a complete final IEND chunk.");
10290
10414
  }
10291
10415
  /** Check source metadata synchronously, before capturing source bytes or allocating any image plane. */
10292
- function pngShape(source, maxPixels) {
10416
+ function pngShape(source, maxPixels, maxWorkingBytes) {
10293
10417
  if (source.length < 33 || signature.some((value, index) => source[index] !== value))
10294
10418
  throw new TypeError("Invalid PNG signature or truncated IHDR.");
10295
10419
  const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
@@ -10309,6 +10433,9 @@ function pngShape(source, maxPixels) {
10309
10433
  const components = source[25] === 6 ? 4 : 3;
10310
10434
  if (!Number.isSafeInteger((width * components + 1) * height) || (width * components + 1) * height > 0x7fffffff)
10311
10435
  throw new OfficeIMOError("RESOURCE_LIMIT", "PNG filtered data exceeds the supported decoded byte length.");
10436
+ const workingBytes = source.length + width * height * components + (components === 4 ? width * 8 : 0);
10437
+ if (maxWorkingBytes !== undefined && workingBytes > maxWorkingBytes)
10438
+ throw new OfficeIMOError("RESOURCE_LIMIT", "maxImageWorkingBytes exceeded by PNG source, image planes and scanlines.");
10312
10439
  return { width, height, components };
10313
10440
  }
10314
10441
  function paeth(left, up, upperLeft) {
@@ -10316,64 +10443,93 @@ function paeth(left, up, upperLeft) {
10316
10443
  const a = Math.abs(prediction - left), b = Math.abs(prediction - up), c = Math.abs(prediction - upperLeft);
10317
10444
  return a <= b && a <= c ? left : b <= c ? up : upperLeft;
10318
10445
  }
10319
- const _exports = Object.freeze({ pngPixels: pngPixels });
10320
- _modules.set("749d1ec5422c0087787f525ef42e3b8d3a94d2b70eb5e42d2e3723a870777ad6", _exports);
10446
+ const _exports = Object.freeze({ pngPixels: pngPixels, pngEmbeddableSize: pngEmbeddableSize, pngShape: pngShape });
10447
+ _modules.set("6b0244b5ec6d550c705b4e4cbb47997331f1ecd99e2bf8a06f7c646eebbffbf8", _exports);
10321
10448
  return _exports;
10322
10449
  })();
10323
10450
 
10324
- const _m85 = _modules.get("7dca2d9ca5c43893abdaf86df5b1bcb1f3de3d5d33532d082fdfe04711999d21") ?? (() => {
10451
+ const _m85 = _modules.get("32ca4982f963f400829c2e364b7d3479f36d91740dafb32d600f29b5cac487ec") ?? (() => {
10325
10452
  const { NotSupportedError, OfficeIMOError } = _m2;
10326
10453
 
10327
10454
  const { checkAbort, pause, taskYieldDue } = _m4;
10328
10455
 
10329
- const { pngPixels } = _m86;
10456
+ const { pngPixels, pngShape } = _m86;
10330
10457
 
10331
10458
  /** Shared document image resources; source objects are captured on first consumption. */
10332
10459
  class PdfDocumentImages {
10333
10460
  objects;
10334
10461
  settings;
10335
10462
  images = new Map();
10463
+ snapshots = new WeakMap();
10336
10464
  bytes = 0;
10465
+ pendingBytes = 0;
10337
10466
  constructor(objects, settings) {
10338
10467
  this.objects = objects;
10339
10468
  this.settings = settings;
10340
10469
  }
10341
- async prepare(image) {
10342
- const existing = this.images.get(image);
10343
- if (existing)
10344
- return existing;
10470
+ /** Own a drawing image before preparing earlier elements can yield to the caller. */
10471
+ snapshot(image) {
10472
+ if (this.images.has(image) || this.snapshots.has(image))
10473
+ return;
10474
+ const captured = this.capture(image);
10475
+ this.snapshots.set(image, captured);
10476
+ this.pendingBytes += captured.data.length;
10477
+ }
10478
+ capture(image) {
10345
10479
  const { limits, options } = this.settings;
10480
+ checkAbort(options.signal);
10346
10481
  if (!image || typeof image !== "object")
10347
10482
  throw new TypeError("PDF images require a byte array.");
10348
- const data = image.data, format = image.format;
10483
+ const format = image.format;
10484
+ // Dimension getters may change a resizable backing buffer. Read them before measuring the byte view.
10485
+ const raw = format === "rgb" || format === "rgba" ? image : undefined;
10486
+ const widthValue = raw?.width, heightValue = raw?.height;
10487
+ const data = image.data;
10349
10488
  if (!(data instanceof Uint8Array))
10350
10489
  throw new TypeError("PDF images require a byte array.");
10351
10490
  const byteLength = data.length;
10352
- if (this.bytes + byteLength > limits.maxImageBytes)
10491
+ if (this.bytes + this.pendingBytes + byteLength > limits.maxImageBytes)
10353
10492
  throw new OfficeIMOError("RESOURCE_LIMIT", "maxImageBytes exceeded.");
10354
- let width, height, components, decoded, decodedAlpha;
10355
10493
  const maximumWorkingBytes = limits.maxImageWorkingBytes;
10356
- if (format === "png")
10357
- ({ width, height, components, data: decoded, alpha: decodedAlpha } = await pngPixels(data, limits.maxImagePixels, options.signal, maximumWorkingBytes));
10358
- else if (format === "jpeg")
10359
- ({ width, height, components } = jpegSize(data));
10494
+ if (format === "png") {
10495
+ const shape = pngShape(data, limits.maxImagePixels, maximumWorkingBytes);
10496
+ return { format, shape, data: new Uint8Array(data) };
10497
+ }
10498
+ let shape;
10499
+ if (format === "jpeg")
10500
+ shape = jpegSize(data);
10360
10501
  else if (format === "rgb" || format === "rgba") {
10361
- ({ width, height } = image);
10362
- components = format === "rgba" ? 4 : 3;
10502
+ shape = { width: widthValue, height: heightValue, components: format === "rgba" ? 4 : 3 };
10363
10503
  }
10364
10504
  else
10365
10505
  throw new NotSupportedError("PDF images support unprofiled PNG/JPEG or decoded RGB/RGBA pixels.");
10506
+ const { width, height, components } = shape;
10366
10507
  if (!Number.isSafeInteger(width) || !Number.isSafeInteger(height) || width < 1 || height < 1 ||
10367
10508
  !Number.isSafeInteger(width * height) || width * height > limits.maxImagePixels)
10368
10509
  throw new OfficeIMOError("RESOURCE_LIMIT", "Image dimensions must be positive integers within maxImagePixels.");
10369
- if ((format === "rgb" || format === "rgba") && byteLength !== width * height * components)
10510
+ if (format !== "jpeg" && byteLength !== width * height * components)
10370
10511
  throw new RangeError("Raw image bytes must match width × height × channels exactly.");
10371
- if (format !== "png" && maximumWorkingBytes !== undefined && byteLength + (components === 4 ? width * height : 0) > maximumWorkingBytes)
10512
+ if (maximumWorkingBytes !== undefined && byteLength + (components === 4 ? width * height : 0) > maximumWorkingBytes)
10372
10513
  throw new OfficeIMOError("RESOURCE_LIMIT", "maxImageWorkingBytes exceeded by image snapshot and alpha plane.");
10514
+ return { format, shape, data: new Uint8Array(data) };
10515
+ }
10516
+ async prepare(image) {
10517
+ const existing = this.images.get(image);
10518
+ if (existing)
10519
+ return existing;
10520
+ const { options } = this.settings, snapshot = this.snapshots.get(image);
10521
+ const source = snapshot ?? this.capture(image);
10522
+ if (snapshot) {
10523
+ this.snapshots.delete(image);
10524
+ this.pendingBytes -= source.data.length;
10525
+ }
10526
+ this.bytes += source.data.length;
10527
+ const { format } = source;
10528
+ const decoded = format === "png" ? await pngPixels(source.data, source.shape, options.signal) : undefined;
10529
+ const { width, height, components } = decoded ?? source.shape;
10373
10530
  checkAbort(options.signal);
10374
10531
  const id = this.objects.reserve(), name = "Image" + (this.images.size + 1);
10375
- this.bytes += byteLength;
10376
- const captured = decoded ?? new Uint8Array(data);
10532
+ const captured = decoded?.data ?? source.data, decodedAlpha = decoded?.alpha;
10377
10533
  let pixels = captured, alpha = decodedAlpha, mask;
10378
10534
  if (components === 4) {
10379
10535
  // Compact the owned RGBA snapshot in place. Forward writes never overwrite unread channels.
@@ -10395,20 +10551,22 @@ class PdfDocumentImages {
10395
10551
  mask = this.objects.reserve();
10396
10552
  await this.objects.stream(mask, alpha, "/Type /XObject /Subtype /Image /Width " + width + " /Height " + height + " /ColorSpace /DeviceGray /BitsPerComponent 8", options.compression !== false, true);
10397
10553
  }
10554
+ const jpegFilter = format === "jpeg" ? " /Filter /DCTDecode" +
10555
+ (source.shape.colorTransform === 0 ? " /DecodeParms << /ColorTransform 0 >>" : "") : "";
10398
10556
  const dictionary = "/Type /XObject /Subtype /Image /Width " + width + " /Height " + height + " /ColorSpace /" +
10399
10557
  (components === 1 ? "DeviceGray" : "DeviceRGB") + " /BitsPerComponent 8" + (mask ? " /SMask " + mask + " 0 R" : "") +
10400
- (format === "jpeg" ? " /Filter /DCTDecode" : "");
10558
+ jpegFilter;
10401
10559
  await this.objects.stream(id, pixels, dictionary, format === "jpeg" ? false : options.compression !== false, true);
10402
10560
  const resource = { name, id, width, height };
10403
10561
  this.images.set(image, resource);
10404
10562
  return resource;
10405
10563
  }
10406
10564
  }
10407
- /** Inspect bounded JPEG headers; JPEG entropy decoding remains the independent reader's job. */
10565
+ /** @internal Inspect bounded JPEG headers; JPEG entropy decoding remains the independent reader's job. */
10408
10566
  function jpegSize(bytes) {
10409
10567
  if (bytes.length < 4 || bytes[0] !== 255 || bytes[1] !== 216 || bytes[bytes.length - 2] !== 255 || bytes[bytes.length - 1] !== 217)
10410
10568
  throw new TypeError("JPEG images need complete SOI/EOI markers.");
10411
- let result;
10569
+ let result, rgb = false, adobe = false;
10412
10570
  for (let p = 2; p < bytes.length;) {
10413
10571
  if (bytes[p++] !== 255)
10414
10572
  throw new TypeError("Invalid JPEG marker.");
@@ -10418,7 +10576,8 @@ function jpegSize(bytes) {
10418
10576
  if (marker === 218) {
10419
10577
  if (!result)
10420
10578
  throw new TypeError("JPEG scan precedes its frame header.");
10421
- return result;
10579
+ // PDF decoders otherwise assume a color transform for three-component JPEGs.
10580
+ return rgb && !adobe ? { ...result, colorTransform: 0 } : result;
10422
10581
  }
10423
10582
  if (marker === 217)
10424
10583
  break;
@@ -10427,6 +10586,8 @@ function jpegSize(bytes) {
10427
10586
  const length = bytes[p] * 256 + bytes[p + 1], end = p + length;
10428
10587
  if (length < 2 || end > bytes.length)
10429
10588
  throw new TypeError("Truncated JPEG segment.");
10589
+ if (marker === 238 && length >= 14 && String.fromCharCode(...bytes.subarray(p + 2, p + 7)) === "Adobe")
10590
+ adobe = true;
10430
10591
  if (marker === 226 && length >= 14 && String.fromCharCode(...bytes.subarray(p + 2, p + 14)) === "ICC_PROFILE\0")
10431
10592
  throw new NotSupportedError("Normalize ICC-profiled JPEG colors before PDF embedding.");
10432
10593
  if (marker === 225 && length >= 8 && String.fromCharCode(...bytes.subarray(p + 2, p + 8)) === "Exif\0\0")
@@ -10439,7 +10600,8 @@ function jpegSize(bytes) {
10439
10600
  throw new NotSupportedError("PDF JPEG images require grayscale or RGB components; CMYK is unsupported.");
10440
10601
  if (components === 3) {
10441
10602
  const ids = [bytes[p + 8], bytes[p + 11], bytes[p + 14]].join(",");
10442
- if (ids !== "1,2,3" && ids !== "82,71,66")
10603
+ rgb = ids === "82,71,66";
10604
+ if (ids !== "1,2,3" && !rgb)
10443
10605
  throw new NotSupportedError("Unsupported JPEG component color layout.");
10444
10606
  }
10445
10607
  if (result)
@@ -10450,12 +10612,12 @@ function jpegSize(bytes) {
10450
10612
  }
10451
10613
  throw new TypeError("JPEG image has no complete frame and scan.");
10452
10614
  }
10453
- const _exports = Object.freeze({ PdfDocumentImages: PdfDocumentImages });
10454
- _modules.set("7dca2d9ca5c43893abdaf86df5b1bcb1f3de3d5d33532d082fdfe04711999d21", _exports);
10615
+ const _exports = Object.freeze({ PdfDocumentImages: PdfDocumentImages, jpegSize: jpegSize });
10616
+ _modules.set("32ca4982f963f400829c2e364b7d3479f36d91740dafb32d600f29b5cac487ec", _exports);
10455
10617
  return _exports;
10456
10618
  })();
10457
10619
 
10458
- const _m87 = _modules.get("3290c84fdf80725af802f497d947bc088aa8d93d9db0a33f6f829f9153aa6fd6") ?? (() => {
10620
+ const _m87 = _modules.get("9ba2dfd6f5c8ef9b1a51427ddee0d0971b139afdd49a175bf6525812ca7d87c8") ?? (() => {
10459
10621
  const { OfficeIMOError } = _m2;
10460
10622
 
10461
10623
  const { checkAbort, pause, taskYieldDue } = _m4;
@@ -10538,16 +10700,16 @@ async function vectorCommands(block, settings, used) {
10538
10700
  commands.join("") + (fill !== undefined && stroke !== undefined ? "B" : fill !== undefined ? "f" : "S") + (fill !== undefined && fillRule === "evenodd" ? "*" : "") + "\n" };
10539
10701
  }
10540
10702
  const _exports = Object.freeze({ vectorCommands: vectorCommands });
10541
- _modules.set("3290c84fdf80725af802f497d947bc088aa8d93d9db0a33f6f829f9153aa6fd6", _exports);
10703
+ _modules.set("9ba2dfd6f5c8ef9b1a51427ddee0d0971b139afdd49a175bf6525812ca7d87c8", _exports);
10542
10704
  return _exports;
10543
10705
  })();
10544
10706
 
10545
- const _m88 = _modules.get("da9ad00f94b9ae28e2e3de796928ff0c4eab1d73382b1441e7d779fad4278ef7") ?? (() => {
10707
+ const _m88 = _modules.get("da0657c49ac1393409d051be5e5dd70d2a0dc5221d363b422d7da31e9b940ea2") ?? (() => {
10546
10708
  const { NotSupportedError, OfficeIMOError } = _m2;
10547
10709
 
10548
10710
  const { checkAbort, pause, taskYieldDue } = _m4;
10549
10711
 
10550
- const { color, positive } = _m56;
10712
+ const { color, pdfDrawingMaxDepth, positive } = _m56;
10551
10713
 
10552
10714
  const { pdfNumber: n } = _m60;
10553
10715
 
@@ -10569,22 +10731,50 @@ function clipRectangle(value) {
10569
10731
  const clip = record(value, ["x", "y", "width", "height"], "drawing clip");
10570
10732
  return { x: coordinate(clip.x), y: coordinate(clip.y), width: positive(clip.width, "Drawing clip width", 1000000), height: positive(clip.height, "Drawing clip height", 1000000) };
10571
10733
  }
10734
+ /** A PDF dash array: 1 through 16 nonnegative lengths, not all zero, and a finite phase. */
10735
+ function dashPattern(value, offset) {
10736
+ if (value === undefined) {
10737
+ if (offset !== undefined)
10738
+ throw new TypeError("Drawing dashOffset requires dash.");
10739
+ return "";
10740
+ }
10741
+ if (!Array.isArray(value) || !value.length || value.length > 16)
10742
+ throw new TypeError("Drawing dash must list 1 through 16 nonnegative lengths with at least one positive length.");
10743
+ const lengths = Array.from(value, item => {
10744
+ if (typeof item !== "number" || !Number.isFinite(item) || item < 0 || item > 14400)
10745
+ throw new TypeError("Drawing dash lengths must be from 0 through 14,400 points.");
10746
+ return n(item);
10747
+ });
10748
+ if (lengths.every(length => length === "0"))
10749
+ throw new TypeError("Drawing dash needs a positive length after PDF rounding.");
10750
+ let phase = coordinate(offset ?? 0);
10751
+ if (phase < 0) {
10752
+ // Work in serialized thousandths of a point. Odd arrays repeat twice before the paint state repeats.
10753
+ const period = lengths.reduce((sum, length) => sum + Math.round(Number(length) * 1000), 0) * (lengths.length % 2 ? 2 : 1);
10754
+ phase = ((Math.round(phase * 1000) % period + period) % period) / 1000;
10755
+ }
10756
+ return "[" + lengths.join(" ") + "] " + n(phase) + " d\n";
10757
+ }
10572
10758
  async function cooperate(settings) {
10573
10759
  if (taskYieldDue())
10574
10760
  await pause();
10575
10761
  checkAbort(settings.options.signal);
10576
10762
  }
10577
10763
  /** Take ownership of one bounded schema before any cooperative or font work can run caller code. */
10578
- function captureDrawing(drawing, settings, used) {
10764
+ function captureDrawing(drawing, settings, used, images) {
10579
10765
  checkAbort(settings.options.signal);
10580
- const root = record(drawing, ["version", "width", "height", "elements"], "drawing");
10581
- if (root.version !== 1)
10582
- throw new NotSupportedError("Only portable drawing version 1 is supported.");
10766
+ const root = record(drawing, ["version", "width", "height", "elements", "standardFonts"], "drawing");
10767
+ const standardFonts = root.standardFonts;
10768
+ if (standardFonts !== undefined && typeof standardFonts !== "boolean")
10769
+ throw new TypeError("Drawing standardFonts must be boolean.");
10770
+ const version = root.version;
10771
+ if (version !== 1 && version !== 2)
10772
+ throw new NotSupportedError("Only portable drawing versions 1 and 2 are supported.");
10583
10773
  const width = positive(root.width, "Drawing width"), height = positive(root.height, "Drawing height");
10584
10774
  let commands = used.commands, elements = used.elements;
10585
10775
  const ancestors = new Set();
10586
10776
  function path(value) {
10587
- record(value, ["kind", "commands", "fill", "stroke", "strokeWidth", "fillRule", "lineCap", "lineJoin"], "drawing path");
10777
+ record(value, ["kind", "commands", "fill", "stroke", "strokeWidth", "fillRule", "lineCap", "lineJoin", "miterLimit", "dash", "dashOffset"], "drawing path");
10588
10778
  const source = value.commands;
10589
10779
  if (!Array.isArray(source))
10590
10780
  throw new TypeError("Drawing path commands must be an array.");
@@ -10606,6 +10796,10 @@ function captureDrawing(drawing, settings, used) {
10606
10796
  throw new TypeError("Invalid drawing lineCap.");
10607
10797
  if (lineJoin !== undefined && !["miter", "round", "bevel"].includes(lineJoin))
10608
10798
  throw new TypeError("Invalid drawing lineJoin.");
10799
+ const miterLimit = positive(value.miterLimit ?? 10, "Drawing miter limit", 1000000);
10800
+ if (miterLimit < 1)
10801
+ throw new RangeError("Drawing miter limit must be at least 1.");
10802
+ const dash = dashPattern(value.dash, value.dashOffset);
10609
10803
  for (let i = 0; i < snapshot.length; i++) {
10610
10804
  const c = snapshot[i];
10611
10805
  if (!c || typeof c !== "object")
@@ -10638,11 +10832,12 @@ function captureDrawing(drawing, settings, used) {
10638
10832
  if (!started)
10639
10833
  throw new TypeError("A drawing path needs at least one command.");
10640
10834
  return { kind: "path", commands: copied, style: (fill === undefined ? "" : fill + " rg\n") + (stroke === undefined ? "" : stroke + " RG\n" + n(strokeWidth) + " w\n") +
10641
- String(["butt", "round", "square"].indexOf(lineCap ?? "butt")) + " J\n" + String(["miter", "round", "bevel"].indexOf(lineJoin ?? "miter")) + " j\n10 M\n",
10835
+ String(["butt", "round", "square"].indexOf(lineCap ?? "butt")) + " J\n" + String(["miter", "round", "bevel"].indexOf(lineJoin ?? "miter")) +
10836
+ " j\n" + n(miterLimit) + " M\n" + dash,
10642
10837
  paint: (fill !== undefined && stroke !== undefined ? "B" : fill !== undefined ? "f" : "S") + (fill !== undefined && fillRule === "evenodd" ? "*" : "") + "\n" };
10643
10838
  }
10644
10839
  function text(value) {
10645
- record(value, ["kind", "text", "x", "y", "font", "fontSize", "color"], "drawing text");
10840
+ record(value, ["kind", "text", "x", "y", "font", "fontSize", "color", "anchor", "rotation"], "drawing text");
10646
10841
  const snapshot = value.text, slot = value.font;
10647
10842
  if (typeof snapshot !== "string")
10648
10843
  throw new TypeError("Drawing text must be a string.");
@@ -10653,14 +10848,33 @@ function captureDrawing(drawing, settings, used) {
10653
10848
  if (!["regular", "bold", "italic", "boldItalic"].includes(slot))
10654
10849
  throw new TypeError("Invalid drawing font slot.");
10655
10850
  const x = coordinate(value.x), y = coordinate(value.y), size = positive(value.fontSize, "Drawing font size"), foreground = color(value.color);
10851
+ const anchor = value.anchor, rotation = value.rotation ?? 0;
10852
+ if (anchor !== undefined && !["start", "middle", "end"].includes(anchor))
10853
+ throw new TypeError("Invalid drawing text anchor.");
10854
+ if (typeof rotation !== "number" || !Number.isFinite(rotation) || Math.abs(rotation) > 360)
10855
+ throw new RangeError("Drawing text rotation must be finite degrees within -360 through 360.");
10656
10856
  settings.budget.cell(snapshot);
10657
- return { kind: "text", text: snapshot, x, y, size, color: foreground, font: slot };
10857
+ // Quarter turns stay exact so upright and vertical axis labels keep integral matrices.
10858
+ const turn = rotation % 90 === 0 ? (((rotation / 90) % 4) + 4) % 4 : -1, radians = rotation * Math.PI / 180;
10859
+ const cos = turn < 0 ? Math.cos(radians) : [1, 0, -1, 0][turn], sin = turn < 0 ? Math.sin(radians) : [0, 1, 0, -1][turn];
10860
+ return { kind: "text", text: snapshot, x, y, size, color: foreground, font: slot, anchor: anchor === "middle" ? .5 : anchor === "end" ? 1 : 0, cos, sin };
10861
+ }
10862
+ function image(value) {
10863
+ record(value, ["kind", "image", "x", "y", "width", "height", "opacity"], "drawing image");
10864
+ const x = coordinate(value.x), y = coordinate(value.y), suppliedOpacity = value.opacity;
10865
+ const opacity = suppliedOpacity === undefined ? 1 : suppliedOpacity;
10866
+ const width = positive(value.width, "Drawing image width", 1000000), height = positive(value.height, "Drawing image height", 1000000);
10867
+ if (typeof opacity !== "number" || !(opacity >= 0 && opacity <= 1))
10868
+ throw new RangeError("Drawing image opacity must be from 0 through 1.");
10869
+ const source = value.image;
10870
+ images.snapshot(source);
10871
+ return { kind: "image", image: source, x, y, width, height, opacity };
10658
10872
  }
10659
10873
  function children(input, depth) {
10660
10874
  if (!Array.isArray(input))
10661
10875
  throw new TypeError("Drawing elements must be an array.");
10662
- if (depth > 32 && input.length)
10663
- throw new RangeError("Drawing groups support at most 32 element levels.");
10876
+ if (depth > pdfDrawingMaxDepth && input.length)
10877
+ throw new RangeError("Drawing groups support at most " + pdfDrawingMaxDepth + " element levels.");
10664
10878
  if (elements + input.length > settings.limits.maxDrawingElements)
10665
10879
  throw new OfficeIMOError("RESOURCE_LIMIT", "maxDrawingElements exceeded.");
10666
10880
  checkAbort(settings.options.signal);
@@ -10678,6 +10892,8 @@ function captureDrawing(drawing, settings, used) {
10678
10892
  output.push(path(value));
10679
10893
  else if (kind === "text")
10680
10894
  output.push(text(value));
10895
+ else if (kind === "image" && version === 2)
10896
+ output.push(image(value));
10681
10897
  else if (kind === "group") {
10682
10898
  record(value, ["kind", "clip", "elements"], "drawing group");
10683
10899
  const clipValue = value.clip, clip = clipValue === undefined ? undefined : clipRectangle(clipValue);
@@ -10694,29 +10910,35 @@ function captureDrawing(drawing, settings, used) {
10694
10910
  }
10695
10911
  const plan = children(root.elements, 1);
10696
10912
  checkAbort(settings.options.signal);
10697
- return { width, height, plan, commands: commands - used.commands, elements: elements - used.elements };
10913
+ return { width, height, plan, commands: commands - used.commands, elements: elements - used.elements, standardFonts: standardFonts === true };
10698
10914
  }
10699
10915
  /** Preflight and paint owned records. The existing font owner retains glyph maps and subsets. */
10700
- async function prepareDrawing(drawing, settings, fonts, used) {
10916
+ async function prepareDrawing(drawing, settings, fonts, used, resources) {
10701
10917
  // A drawing's bounded capture is synchronous; yielding here would leave later caller records borrowed.
10702
- const captured = captureDrawing(drawing, settings, used), drawingFonts = new Map();
10918
+ const { images } = resources, captured = captureDrawing(drawing, settings, used, images), drawingFonts = new Map();
10703
10919
  function fontFor(slot) {
10704
10920
  const existing = drawingFonts.get(slot);
10705
10921
  if (existing)
10706
10922
  return existing;
10707
- const font = fonts.select(slot === "bold" || slot === "boldItalic", slot === "italic" || slot === "boldItalic");
10708
- if (!font.program || font.syntheticBold || font.syntheticItalic)
10923
+ const font = fonts.select(slot === "bold" || slot === "boldItalic", slot === "italic" || slot === "boldItalic", undefined, captured.standardFonts);
10924
+ if (font.syntheticBold || font.syntheticItalic || !font.program && !captured.standardFonts)
10709
10925
  throw new NotSupportedError("Drawing text without an exact embedded font face at fonts." + slot);
10710
10926
  drawingFonts.set(slot, font);
10711
10927
  return font;
10712
10928
  }
10713
10929
  // The work budget belongs to the drawing, including short runs in separate sibling groups.
10714
10930
  let preflightCharacters = 0, preflightElements = 0;
10931
+ const imageNames = new Map();
10715
10932
  async function preflight(nodes) {
10716
10933
  for (let i = 0; i < nodes.length; i++) {
10717
10934
  const node = nodes[i];
10718
10935
  if (node.kind === "group")
10719
10936
  await preflight(node.children);
10937
+ else if (node.kind === "image" && !imageNames.has(node.image)) {
10938
+ const resource = await images.prepare(node.image);
10939
+ resources.registerImage(resource.name, resource.id);
10940
+ imageNames.set(node.image, resource.name);
10941
+ }
10720
10942
  else if (node.kind === "text") {
10721
10943
  const font = fontFor(node.font);
10722
10944
  for (const character of node.text) {
@@ -10759,9 +10981,23 @@ async function prepareDrawing(drawing, settings, fonts, used) {
10759
10981
  }
10760
10982
  add(node.paint);
10761
10983
  }
10984
+ else if (node.kind === "image") {
10985
+ // Image space is a unit square with a bottom-left origin; the drawing's y axis points down.
10986
+ if (node.opacity < 1)
10987
+ add("/" + resources.opacity(node.opacity) + " gs\n");
10988
+ add([node.width, 0, 0, -node.height, node.x, node.y + node.height].map(n).join(" ") + " cm /" + imageNames.get(node.image) + " Do\n");
10989
+ }
10762
10990
  else {
10763
10991
  const font = fontFor(node.font);
10764
- add(node.color + " rg\nBT /" + font.name + " " + n(node.size) + " Tf 0 Tr 1 0 0 -1 " + n(node.x) + " " + n(node.y) + " Tm <");
10992
+ let shift = 0;
10993
+ if (node.anchor) {
10994
+ for (const character of node.text)
10995
+ shift += font.width(character.codePointAt(0));
10996
+ shift *= node.size / 1000 * node.anchor;
10997
+ }
10998
+ // Text space is upright in the drawing's downward y axis; rotation turns the baseline clockwise about its anchor.
10999
+ add(node.color + " rg\nBT /" + font.name + " " + n(node.size) + " Tf 0 Tr " +
11000
+ [node.cos, node.sin, node.sin, -node.cos, node.x - shift * node.cos, node.y - shift * node.sin].map(n).join(" ") + " Tm <");
10765
11001
  let chunk = "";
10766
11002
  for (const character of node.text) {
10767
11003
  chunk += character;
@@ -10785,11 +11021,11 @@ async function prepareDrawing(drawing, settings, fonts, used) {
10785
11021
  return { width: captured.width, height: captured.height, content: fragments.join(""), commands: captured.commands, elements: captured.elements };
10786
11022
  }
10787
11023
  const _exports = Object.freeze({ checkDrawingBlock: checkDrawingBlock, prepareDrawing: prepareDrawing });
10788
- _modules.set("da9ad00f94b9ae28e2e3de796928ff0c4eab1d73382b1441e7d779fad4278ef7", _exports);
11024
+ _modules.set("da0657c49ac1393409d051be5e5dd70d2a0dc5221d363b422d7da31e9b940ea2", _exports);
10789
11025
  return _exports;
10790
11026
  })();
10791
11027
 
10792
- const _m89 = _modules.get("5e4503b77b357ee6d9fad1f52690085b0f0b140cd3b550b63c5100ed95a92f88") ?? (() => {
11028
+ const _m89 = _modules.get("37923737a6bcae4c342ab023bd3cb01ddeaced28543718aad078b51b54d8f31d") ?? (() => {
10793
11029
  const { OfficeIMOError } = _m2;
10794
11030
 
10795
11031
  const { capturePdfText, wrapPdfText } = _m71;
@@ -10869,11 +11105,11 @@ function paragraphStartHeight(paragraphs) {
10869
11105
  return required;
10870
11106
  }
10871
11107
  const _exports = Object.freeze({ captureParagraph: captureParagraph, captureCaption: captureCaption, prepareParagraph: prepareParagraph, checkParagraphBuffer: checkParagraphBuffer, paragraphStartHeight: paragraphStartHeight });
10872
- _modules.set("5e4503b77b357ee6d9fad1f52690085b0f0b140cd3b550b63c5100ed95a92f88", _exports);
11108
+ _modules.set("37923737a6bcae4c342ab023bd3cb01ddeaced28543718aad078b51b54d8f31d", _exports);
10873
11109
  return _exports;
10874
11110
  })();
10875
11111
 
10876
- const _m90 = _modules.get("1d57c429705ae0cbc14d98dcfef4c8a6c2df06f391c8f58e99cacb02f2d1cbc7") ?? (() => {
11112
+ const _m90 = _modules.get("964206f2e7c45a34e414d4d690243bf90eb4cf99793e13d1cda834de3d386773") ?? (() => {
10877
11113
  const { capturePdfText, wrapPdfText } = _m71;
10878
11114
 
10879
11115
  const { captureParagraph, prepareParagraph } = _m89;
@@ -10927,11 +11163,11 @@ async function prepareListItem(item, index, options, settings, fonts) {
10927
11163
  height: paragraph.height + lineHeight - first.lineHeight, firstHeight: paragraph.spaceBefore + lineHeight } };
10928
11164
  }
10929
11165
  const _exports = Object.freeze({ captureListOptions: captureListOptions, prepareListItem: prepareListItem });
10930
- _modules.set("1d57c429705ae0cbc14d98dcfef4c8a6c2df06f391c8f58e99cacb02f2d1cbc7", _exports);
11166
+ _modules.set("964206f2e7c45a34e414d4d690243bf90eb4cf99793e13d1cda834de3d386773", _exports);
10931
11167
  return _exports;
10932
11168
  })();
10933
11169
 
10934
- const _m92 = _modules.get("d04686d2c067355dfd215333b83eb5f79f96e9e4be49f942e050f21ac0795343") ?? (() => {
11170
+ const _m92 = _modules.get("f254a333f483757dc21be9d40dbd3ca51013d32a3c646b564270e3902226a590") ?? (() => {
10935
11171
  const { assertGroupedReportSource } = _m8;
10936
11172
 
10937
11173
  const { captureFields } = _m10;
@@ -10977,11 +11213,11 @@ function captureGroupedPdfTableOptions(configuration) {
10977
11213
  ...(captured.footerPresentation === undefined ? {} : { footerPresentation: presentation(captured.footerPresentation) }) });
10978
11214
  }
10979
11215
  const _exports = Object.freeze({ groupedPdfLabelFields: groupedPdfLabelFields, groupedPdfTableFields: groupedPdfTableFields, pdfGroupedTable: pdfGroupedTable, captureGroupedPdfTableOptions: captureGroupedPdfTableOptions });
10980
- _modules.set("d04686d2c067355dfd215333b83eb5f79f96e9e4be49f942e050f21ac0795343", _exports);
11216
+ _modules.set("f254a333f483757dc21be9d40dbd3ca51013d32a3c646b564270e3902226a590", _exports);
10981
11217
  return _exports;
10982
11218
  })();
10983
11219
 
10984
- const _m91 = _modules.get("289fa3a052c7fbab2a3ca0fb91fb9974db709d24b7d850f1175810258f0409a0") ?? (() => {
11220
+ const _m91 = _modules.get("a3ebee86ff33369e9ebc8b994d71bad32497a55433a313c426676277cb660d2f") ?? (() => {
10985
11221
  const { assertGroupedReportSource, groupedReportOperation } = _m8;
10986
11222
 
10987
11223
  const { consumeRows } = _m4;
@@ -11235,11 +11471,11 @@ async function renderGroupedPdfTable(block, context) {
11235
11471
  }
11236
11472
  }
11237
11473
  const _exports = Object.freeze({ renderGroupedPdfTable: renderGroupedPdfTable });
11238
- _modules.set("289fa3a052c7fbab2a3ca0fb91fb9974db709d24b7d850f1175810258f0409a0", _exports);
11474
+ _modules.set("a3ebee86ff33369e9ebc8b994d71bad32497a55433a313c426676277cb660d2f", _exports);
11239
11475
  return _exports;
11240
11476
  })();
11241
11477
 
11242
- const _m84 = _modules.get("9051bf9fc3168e24b53b16c123a42816198456846003fb49191c03a18cdab904") ?? (() => {
11478
+ const _m84 = _modules.get("e7fe5a5c6b675c6217db5f5a72d8883609e8417ee3c6f3c2184d375463f93231") ?? (() => {
11243
11479
  const { BlobByteSink, withDestination } = _m3;
11244
11480
 
11245
11481
  const { OfficeIMOError } = _m2;
@@ -11489,7 +11725,9 @@ async function writePdfDocumentTo(blocks, destination, configuration = {}) {
11489
11725
  const inputDrawing = block.drawing, capturedCaption = snapshotCaption(block.caption), alternative = graphicAlternative(block, pages.settings), alignment = graphicAlignment(block.alignment);
11490
11726
  if (capturedCaption && alternative === undefined)
11491
11727
  throw new TypeError("A captioned PDF graphic requires alternativeText and cannot be decorative.");
11492
- const drawing = await prepareDrawing(inputDrawing, pages.settings, fonts, { commands, elements: drawingElements }), caption = await prepareCaption(capturedCaption);
11728
+ const drawing = await prepareDrawing(inputDrawing, pages.settings, fonts, { commands, elements: drawingElements }, {
11729
+ images, registerImage: (name, id) => pages.registerXObject(name, id), opacity: alpha => pages.opacityState(alpha)
11730
+ }), caption = await prepareCaption(capturedCaption);
11493
11731
  commands += drawing.commands;
11494
11732
  drawingElements += drawing.elements;
11495
11733
  await flushParagraphs((caption?.height ?? 0) + pages.graphicHeight(drawing.width, drawing.height));
@@ -11529,11 +11767,11 @@ function captureTableOptions(options) {
11529
11767
  return { ...captured, ...(captured.wideTable === undefined ? {} : { wideTable: captureWideTable(captured.wideTable) }) };
11530
11768
  }
11531
11769
  const _exports = Object.freeze({ pdfTable: pdfTable, writePdfDocument: writePdfDocument, writePdfDocumentTo: writePdfDocumentTo });
11532
- _modules.set("9051bf9fc3168e24b53b16c123a42816198456846003fb49191c03a18cdab904", _exports);
11770
+ _modules.set("e7fe5a5c6b675c6217db5f5a72d8883609e8417ee3c6f3c2184d375463f93231", _exports);
11533
11771
  return _exports;
11534
11772
  })();
11535
11773
 
11536
- const _m83 = _modules.get("abe76e52ffeed11ab42477c83ddde1d1d7de28b803096436b5b23cb153af58ba") ?? (() => {
11774
+ const _m83 = _modules.get("37e4a768d57818c4335fd3d61b9b7aae633cde303e7634579655a6a3de4a86ce") ?? (() => {
11537
11775
  const { assertGroupedReportSource } = _m8;
11538
11776
 
11539
11777
  const { BlobByteSink } = _m3;
@@ -11579,7 +11817,7 @@ async function writeGroupedPdfTo(report, destination, configuration) {
11579
11817
  return writePdfDocumentTo([pdfGroupedTable(report, tableOptions)], destination, documentOptions);
11580
11818
  }
11581
11819
  const _exports = Object.freeze({ pdfGroupedTable: _m92.pdfGroupedTable, writeGroupedPdf: writeGroupedPdf, writeGroupedPdfTo: writeGroupedPdfTo });
11582
- _modules.set("abe76e52ffeed11ab42477c83ddde1d1d7de28b803096436b5b23cb153af58ba", _exports);
11820
+ _modules.set("37e4a768d57818c4335fd3d61b9b7aae633cde303e7634579655a6a3de4a86ce", _exports);
11583
11821
  return _exports;
11584
11822
  })();
11585
11823
 
@@ -11623,10 +11861,10 @@ _modules.set("3d777096288d1be55a05a80bc015d4674212e587703f25a7e7cf99a8065feb86",
11623
11861
  return _exports;
11624
11862
  })();
11625
11863
 
11626
- const _m54 = _modules.get("027aafa08408056b10d7d717d63d1f7c0ee20ecfc68213aa66feacc75ec525fe") ?? (() => {
11864
+ const _m54 = _modules.get("344fd55ffe1a37b32a8eb6a2bdaa14dff90e0fee0f37282457f9e4c3b7bce1ca") ?? (() => {
11627
11865
 
11628
11866
  const _exports = Object.freeze({ writePdf: _m55.writePdf, writePdfTo: _m55.writePdfTo, writeGroupedPdf: _m83.writeGroupedPdf, writeGroupedPdfTo: _m83.writeGroupedPdfTo, pdfGroupedTable: _m83.pdfGroupedTable, createGroupedReport: _m8.createGroupedReport, writePdfDocument: _m84.writePdfDocument, writePdfDocumentTo: _m84.writePdfDocumentTo, pdfTable: _m84.pdfTable, PdfFont: _m63.PdfFont, preflightPdfText: _m93.preflightPdfText, ExportCell: _m5.ExportCell, saveBlob: _m1.saveBlob });
11629
- _modules.set("027aafa08408056b10d7d717d63d1f7c0ee20ecfc68213aa66feacc75ec525fe", _exports);
11867
+ _modules.set("344fd55ffe1a37b32a8eb6a2bdaa14dff90e0fee0f37282457f9e4c3b7bce1ca", _exports);
11630
11868
  return _exports;
11631
11869
  })();
11632
11870
 
@@ -12000,7 +12238,7 @@ _modules.set("8edb7b3b19d6555ea24a92d771d532dc0448ad18101fdf663217b4c518b5a31b",
12000
12238
  return _exports;
12001
12239
  })();
12002
12240
 
12003
- const _m97 = _modules.get("7b12a415e92cc9ef7212fb3a88007cb6dc37f9f30077165d4897cfa8052f9a3c") ?? (() => {
12241
+ const _m97 = _modules.get("2ab57874b786ef4d2b4841b9072fedd27d40c308f72c6548962810139359deb9") ?? (() => {
12004
12242
  const { captureFields } = _m10;
12005
12243
 
12006
12244
  const { ExportBudget } = _m9;
@@ -12041,11 +12279,11 @@ function capturePdfOptions(input = {}) {
12041
12279
  return { ...options, ...(options.limits === undefined ? {} : { limits: capturePdfLimits(options.limits) }) };
12042
12280
  }
12043
12281
  const _exports = Object.freeze({ captureCommonLimits: captureCommonLimits, mergeAdapterLimits: mergeAdapterLimits, captureXlsxOptions: captureXlsxOptions, captureCsvOptions: captureCsvOptions, capturePdfOptions: capturePdfOptions });
12044
- _modules.set("7b12a415e92cc9ef7212fb3a88007cb6dc37f9f30077165d4897cfa8052f9a3c", _exports);
12282
+ _modules.set("2ab57874b786ef4d2b4841b9072fedd27d40c308f72c6548962810139359deb9", _exports);
12045
12283
  return _exports;
12046
12284
  })();
12047
12285
 
12048
- const _m0 = _modules.get("f5f1435b6f22ab08d91f4a58bb66e975d4427bcaf5697011e28bfa9e74b2a2ca") ?? (() => {
12286
+ const _m0 = _modules.get("147109a7d787a3eec697dcd8a556224afda45a042eedd08346b113f10a56a59c") ?? (() => {
12049
12287
  const { BlobByteSink, checkAbort, saveBlob } = _m1;
12050
12288
 
12051
12289
  const { notifyProgress } = _m14;
@@ -12228,7 +12466,7 @@ function registerDataTablesButtons(host, options = {}) {
12228
12466
  }
12229
12467
  }
12230
12468
  const _exports = Object.freeze({ createDataTablesExport: _m96.createDataTablesExport, ExportCell: _m5.ExportCell, PdfFont: _m63.PdfFont, writeDataTableTo: writeDataTableTo, exportDataTable: exportDataTable, registerDataTablesButtons: registerDataTablesButtons });
12231
- _modules.set("f5f1435b6f22ab08d91f4a58bb66e975d4427bcaf5697011e28bfa9e74b2a2ca", _exports);
12469
+ _modules.set("147109a7d787a3eec697dcd8a556224afda45a042eedd08346b113f10a56a59c", _exports);
12232
12470
  return _exports;
12233
12471
  })();
12234
12472
  Object.assign(officeimo, _m0);