@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
@@ -1806,19 +1806,24 @@ _modules.set("945379594834125fea38bc00f02ef077409dd15f6ed67279e63e89afe0bb944b",
1806
1806
  return _exports;
1807
1807
  })();
1808
1808
 
1809
- const _m23 = _modules.get("6cfd3e806439f6301003a2d1699a74fdfa574d935550ab62b97b528728eaee1f") ?? (() => {
1809
+ const _m23 = _modules.get("4eea31c4336d3c43bc743739843a3ef31803d8f0ed553f5645ee9de2554eb244") ?? (() => {
1810
1810
  /** @internal Notify synchronously; observe an accidental promise before rejecting its unsupported use. */
1811
1811
  function notifyProgress(callback, progress) {
1812
+ notifySynchronously("onProgress", callback, progress);
1813
+ }
1814
+ /** @internal Run a host notification that must finish before the export continues. A returned promise is observed,
1815
+ * so its rejection is never unhandled, and the export fails instead of reporting success before the callback ends. */
1816
+ function notifySynchronously(name, callback, value) {
1812
1817
  if (!callback)
1813
1818
  return;
1814
- const result = callback(progress);
1819
+ const result = callback(value);
1815
1820
  if (result && typeof result.then === "function") {
1816
1821
  void Promise.resolve(result).catch(() => { });
1817
- throw new TypeError("onProgress must be synchronous.");
1822
+ throw new TypeError(name + " must be synchronous.");
1818
1823
  }
1819
1824
  }
1820
- const _exports = Object.freeze({ notifyProgress: notifyProgress });
1821
- _modules.set("6cfd3e806439f6301003a2d1699a74fdfa574d935550ab62b97b528728eaee1f", _exports);
1825
+ const _exports = Object.freeze({ notifyProgress: notifyProgress, notifySynchronously: notifySynchronously });
1826
+ _modules.set("4eea31c4336d3c43bc743739843a3ef31803d8f0ed553f5645ee9de2554eb244", _exports);
1822
1827
  return _exports;
1823
1828
  })();
1824
1829
 
@@ -1945,7 +1950,7 @@ _modules.set("6ae88f25e1c09d00fbb828917498569f883fae88ec25d37caebaf8a2b802b148",
1945
1950
  return _exports;
1946
1951
  })();
1947
1952
 
1948
- const _m24 = _modules.get("077c3c668f1457253dba044e6f6be7f7afd28a8976ed20c764bd5d5dc7c41889") ?? (() => {
1953
+ const _m24 = _modules.get("8d96d0024443ac9aeaea70e9324b53aacef098c2385d4e6a89a76d184e28556a") ?? (() => {
1949
1954
  const { escapeOoxmlAttribute, cleanXml, xmlDeclaration } = _m17;
1950
1955
 
1951
1956
  const { OfficeIMOError } = _m2;
@@ -1957,6 +1962,24 @@ const { DifferentialStyles } = _m26;
1957
1962
 
1958
1963
 
1959
1964
  const spreadsheetNamespace = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
1965
+ const borderStyles = ["thin", "medium", "dashed", "dotted", "thick", "double", "hair", "dashDot", "dashDotDot", "slantDashDot", "mediumDashed", "mediumDashDot", "mediumDashDotDot"];
1966
+ /** @internal Validate and normalize border edges without registering a workbook style. */
1967
+ function normalizeBorder(border) {
1968
+ if (!border || typeof border !== "object")
1969
+ throw new TypeError("A border must be an object of edges.");
1970
+ const result = {};
1971
+ for (const side of ["left", "right", "top", "bottom"]) {
1972
+ const edge = border[side];
1973
+ if (edge) {
1974
+ // Read each property once, so the validated edge is the one that is stored.
1975
+ const { style, color } = edge;
1976
+ if (!borderStyles.includes(style))
1977
+ throw new TypeError("Invalid border style.");
1978
+ result[side] = { style, ...(color ? { color: colorArgb(color) } : {}) };
1979
+ }
1980
+ }
1981
+ return result;
1982
+ }
1960
1983
  const NumberFormats = { General: "General", Integer: "0", Decimal: "0.00", Percent: "0.00%", Date: "yyyy-mm-dd", DateTime: "yyyy-mm-dd hh:mm:ss" };
1961
1984
  function index(value, count, kind) {
1962
1985
  if (!Number.isInteger(value) || value < 0 || value >= count)
@@ -2029,32 +2052,24 @@ class StyleRegistry {
2029
2052
  /** @internal */
2030
2053
  addDifferentials(styles) { this.checkDifferentials(styles); return this.differential.add(styles); }
2031
2054
  addFont(font) {
2032
- if (font.name !== undefined && typeof font.name !== "string")
2055
+ const { name: requested, size: requestedSize, bold, italic, underline, strike, color } = font;
2056
+ if (requested !== undefined && typeof requested !== "string")
2033
2057
  throw new TypeError("Font name must be a string.");
2034
- const name = cleanXml(font.name ?? "Calibri", this.policy), size = font.size ?? 11;
2058
+ const name = cleanXml(requested ?? "Calibri", this.policy), size = requestedSize ?? 11;
2035
2059
  if (typeof name !== "string" || !name || name.length > 31)
2036
2060
  throw new TypeError("Font name must contain 1 through 31 characters.");
2037
2061
  if (!Number.isFinite(size) || size <= 0 || size > 409)
2038
2062
  throw new RangeError("Font size must be positive and at most 409.");
2039
- 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);
2063
+ return deduplicate(this.fonts, this.fontIndexes, { name, size, bold: !!bold, italic: !!italic, underline: !!underline, strike: !!strike, color: color ? colorArgb(color) : "" }, this.maximum);
2040
2064
  }
2041
2065
  addFill(fill) {
2042
- const pattern = fill.pattern ?? (fill.color ? "solid" : "none");
2043
- if (!["none", "gray125", "solid"].includes(pattern) || (pattern === "solid" && !fill.color) || (pattern !== "solid" && fill.color))
2066
+ const { color } = fill, pattern = fill.pattern ?? (color ? "solid" : "none");
2067
+ if (!["none", "gray125", "solid"].includes(pattern) || (pattern === "solid" && !color) || (pattern !== "solid" && color))
2044
2068
  throw new TypeError("A solid fill requires a color; none and gray125 have no color.");
2045
- return deduplicate(this.fills, this.fillIndexes, { pattern, color: fill.color ? colorArgb(fill.color) : "" }, this.maximum + 1);
2069
+ return deduplicate(this.fills, this.fillIndexes, { pattern, color: color ? colorArgb(color) : "" }, this.maximum + 1);
2046
2070
  }
2047
2071
  addBorder(border) {
2048
- const result = {};
2049
- for (const side of ["left", "right", "top", "bottom"]) {
2050
- const edge = border[side];
2051
- if (edge) {
2052
- if (!["thin", "medium", "dashed", "dotted", "thick", "double", "hair", "dashDot", "dashDotDot", "slantDashDot", "mediumDashed", "mediumDashDot", "mediumDashDotDot"].includes(edge.style))
2053
- throw new TypeError("Invalid border style.");
2054
- result[side] = { style: edge.style, ...(edge.color ? { color: colorArgb(edge.color) } : {}) };
2055
- }
2056
- }
2057
- return deduplicate(this.borders, this.borderIndexes, result, this.maximum);
2072
+ return deduplicate(this.borders, this.borderIndexes, normalizeBorder(border), this.maximum);
2058
2073
  }
2059
2074
  addNumberFormat(format) {
2060
2075
  if (typeof format !== "string" || !format || format.length > 255)
@@ -2120,7 +2135,7 @@ class StyleRegistry {
2120
2135
  return this.compose(base, { numberFormat: this.styles[this.validateStyle(dateStyle)].numberFormat });
2121
2136
  }
2122
2137
  /** @internal Column shorthand and header style composition. */
2123
- forColumn(column, header = false, fill, date = false) {
2138
+ forColumn(column, header = false, fill, date = false, border) {
2124
2139
  const base = !header && column.style !== undefined ? this.styles[this.validateStyle(column.style)] : undefined;
2125
2140
  const format = column.format !== undefined ? column.format || NumberFormats.General : base?.numberFormat || (column.type === "date" || date ? NumberFormats.DateTime : NumberFormats.General);
2126
2141
  return this.add({
@@ -2129,7 +2144,7 @@ class StyleRegistry {
2129
2144
  wrapText: column.wrapText ?? base?.wrapText ?? false,
2130
2145
  ...(column.alignment ? { alignment: column.alignment } : base?.alignment ? { alignment: base.alignment } : {}),
2131
2146
  ...(base?.verticalAlignment ? { verticalAlignment: base.verticalAlignment } : {}),
2132
- ...(header ? { font: { bold: true } } : {}), ...(fill ? { fill: { color: fill } } : {})
2147
+ ...(header ? { font: { bold: true } } : {}), ...(fill ? { fill: { color: fill } } : {}), ...(border ? { border } : {})
2133
2148
  });
2134
2149
  }
2135
2150
  toXml() {
@@ -2154,8 +2169,8 @@ class StyleRegistry {
2154
2169
  }).join("") + '</cellXfs><cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles>' + this.differential.toXml() + '</styleSheet>';
2155
2170
  }
2156
2171
  }
2157
- const _exports = Object.freeze({ colorArgb: _m25.colorArgb, spreadsheetNamespace: spreadsheetNamespace, NumberFormats: NumberFormats, validateStylePatch: validateStylePatch, copyStylePatch: copyStylePatch, StyleRegistry: StyleRegistry });
2158
- _modules.set("077c3c668f1457253dba044e6f6be7f7afd28a8976ed20c764bd5d5dc7c41889", _exports);
2172
+ const _exports = Object.freeze({ colorArgb: _m25.colorArgb, spreadsheetNamespace: spreadsheetNamespace, normalizeBorder: normalizeBorder, NumberFormats: NumberFormats, validateStylePatch: validateStylePatch, copyStylePatch: copyStylePatch, StyleRegistry: StyleRegistry });
2173
+ _modules.set("8d96d0024443ac9aeaea70e9324b53aacef098c2385d4e6a89a76d184e28556a", _exports);
2159
2174
  return _exports;
2160
2175
  })();
2161
2176
 
@@ -3375,14 +3390,14 @@ _modules.set("13fa96d976e4dec7343dd3a392829567f1fcb574324a98f5a5d3a61c9a0dc27d",
3375
3390
  return _exports;
3376
3391
  })();
3377
3392
 
3378
- const _m31 = _modules.get("a61e744201bb537b635b367b1764bd85892101d55e00b8c78faec8be89577376") ?? (() => {
3393
+ const _m31 = _modules.get("d5957683aa1945575924c89c63b427878e6e6e47ef5c229dc524b1879d146499") ?? (() => {
3379
3394
  const { checkAbort, consumeRows, inputRows, pause, taskYieldDue } = _m4;
3380
3395
 
3381
3396
  const { ChunkedTextSink, BlobByteSink } = _m3;
3382
3397
 
3383
3398
  const { OfficeIMOError } = _m2;
3384
3399
 
3385
- const { notifyProgress } = _m23;
3400
+ const { notifyProgress, notifySynchronously } = _m23;
3386
3401
 
3387
3402
  const { copyColumns, createRowProjector } = _m11;
3388
3403
 
@@ -3454,8 +3469,14 @@ class Worksheet {
3454
3469
  pendingCharacters = 0;
3455
3470
  reservedLayout = false;
3456
3471
  internalLinks = [];
3472
+ // Evicted entries become holes and are compacted in one pass when the links are read, keeping eviction O(1).
3457
3473
  links = [];
3474
+ evictedLinks = 0;
3458
3475
  linkedCells = new Set();
3476
+ /** Indexes in `links` of data-cell links that `hyperlinkOverflow: "drop"` may give up, in row order. */
3477
+ droppable = [];
3478
+ droppableLinks = new WeakSet();
3479
+ droppedLinks = 0;
3459
3480
  pictures = [];
3460
3481
  nativeCharts = [];
3461
3482
  conditional;
@@ -3486,8 +3507,9 @@ class Worksheet {
3486
3507
  book.checkLinks(this.links.length);
3487
3508
  this.declared = this.columns.map((column, i) => ({ column, letter: columnName(i + 1),
3488
3509
  style: book.styles.forColumn(column), dateStyle: book.styles.forColumn(column, false, undefined, true),
3489
- headerStyle: this.headerRows ? options.headerStyle ?? book.styles.forColumn({ header: column.header, ...(column.wrapText === undefined ? {} : { wrapText: column.wrapText }),
3490
- ...(column.alignment === undefined ? {} : { alignment: column.alignment }) }, options.boldHeader !== false, options.headerFill) : 0
3510
+ headerStyle: this.headerRows ? options.headerStyle ?? book.styles.forColumn({ header: column.header,
3511
+ ...((options.headerWrap ?? column.wrapText) === undefined ? {} : { wrapText: options.headerWrap ?? column.wrapText }),
3512
+ ...(column.alignment === undefined ? {} : { alignment: column.alignment }) }, options.boldHeader !== false, options.headerFill, false, options.headerBorder) : 0
3491
3513
  }));
3492
3514
  // Register conditional styles only after worksheet construction can no longer reject its options.
3493
3515
  this.conditional = new ConditionalFormats(conditional, book.styles);
@@ -3539,6 +3561,8 @@ class Worksheet {
3539
3561
  throw new TypeError("A frozen header or autofilter requires a header row.");
3540
3562
  if (options.headerFill !== undefined)
3541
3563
  colorArgb(options.headerFill);
3564
+ if (options.headerWrap !== undefined && typeof options.headerWrap !== "boolean")
3565
+ throw new TypeError("headerWrap must be boolean.");
3542
3566
  if (options.headerStyle !== undefined)
3543
3567
  book.styles.validateStyle(options.headerStyle);
3544
3568
  if (options.alternatingRowStyle !== undefined)
@@ -3664,7 +3688,8 @@ class Worksheet {
3664
3688
  const cell = col.letter + row;
3665
3689
  if (link || this.linkedCells.has(cell))
3666
3690
  throw new TypeError("A text-preservation cell cannot also have an external hyperlink.");
3667
- checkHyperlinkCount(this.links.length + this.internalLinks.length + 1);
3691
+ this.makeLinkRoom();
3692
+ checkHyperlinkCount(this.linkCount + 1);
3668
3693
  this.book.checkLinks(1);
3669
3694
  // Replace a generated cell's original reservation with its preview and overflow records.
3670
3695
  if (reservedCharacters !== undefined) {
@@ -3678,7 +3703,7 @@ class Worksheet {
3678
3703
  value = preserved.preview;
3679
3704
  }
3680
3705
  if (link)
3681
- this.appendHyperlink({ cell: col.letter + row, ...link });
3706
+ this.appendHyperlink({ cell: col.letter + row, ...link }, !header && !footer && !title && this.book.settings.hyperlinkOverflow === "drop");
3682
3707
  if (type === "date")
3683
3708
  value = excelDate(value, this.book.settings.dateMode);
3684
3709
  if (!header && !footer && visible && (!formula || !isSubtotalFormula(formula)))
@@ -3987,20 +4012,61 @@ class Worksheet {
3987
4012
  throw this.error;
3988
4013
  this.appendHyperlink(link);
3989
4014
  }
3990
- appendHyperlink(link) {
4015
+ appendHyperlink(link, droppable = false) {
4016
+ // Validate before any overflow decision, so a dropped link can never hide an unsafe target.
3991
4017
  const copied = copyHyperlink(link, this.book.settings.invalidCharacterPolicy);
3992
4018
  const position = cellPosition(copied.cell);
3993
4019
  if (this.layout.regions.covered(position.column, position.row))
3994
4020
  throw new TypeError("Hyperlinks cannot address a covered merged cell.");
3995
4021
  if (this.linkedCells.has(copied.cell))
3996
4022
  throw new TypeError("Duplicate hyperlink cell: " + copied.cell);
3997
- checkHyperlinkCount(this.links.length + this.internalLinks.length + 1);
4023
+ if (droppable && this.linkCount >= maximumHyperlinks) {
4024
+ this.droppedLinks++;
4025
+ return;
4026
+ }
4027
+ if (!droppable)
4028
+ this.makeLinkRoom();
4029
+ checkHyperlinkCount(this.linkCount + 1);
3998
4030
  this.book.retainLink();
4031
+ if (droppable) {
4032
+ this.droppable.push(this.links.length);
4033
+ this.droppableLinks.add(copied);
4034
+ }
3999
4035
  this.links.push(copied);
4000
4036
  this.linkedCells.add(copied.cell);
4001
4037
  }
4038
+ /** Links the worksheet holds now, not counting evicted holes. */
4039
+ get linkCount() { return this.links.length - this.evictedLinks + this.internalLinks.length; }
4040
+ /** A full worksheet gives up its latest data-cell link for a link that cannot be dropped. Hyperlinks are serialized after
4041
+ * the rows, so the cell keeps its written value. The entry becomes a hole, so other indexes stay valid until compaction. */
4042
+ makeLinkRoom() {
4043
+ if (this.linkCount < maximumHyperlinks || !this.droppable.length)
4044
+ return;
4045
+ const index = this.droppable.pop(), removed = this.links[index];
4046
+ this.links[index] = undefined;
4047
+ this.evictedLinks++;
4048
+ this.linkedCells.delete(removed.cell);
4049
+ this.book.releaseLink();
4050
+ this.droppedLinks++;
4051
+ }
4052
+ /** One ordered pass removes evicted holes and rebuilds the droppable indexes. */
4053
+ compactLinks() {
4054
+ if (this.evictedLinks) {
4055
+ const kept = [], droppable = [];
4056
+ for (const link of this.links)
4057
+ if (link) {
4058
+ if (this.droppableLinks.has(link))
4059
+ droppable.push(kept.length);
4060
+ kept.push(link);
4061
+ }
4062
+ this.links = kept;
4063
+ this.droppable = droppable;
4064
+ this.evictedLinks = 0;
4065
+ }
4066
+ return this.links;
4067
+ }
4002
4068
  /** @internal */
4003
- get hyperlinks() { return this.links; }
4069
+ get hyperlinks() { return this.compactLinks(); }
4004
4070
  /** @internal */
4005
4071
  get images() { return this.pictures; }
4006
4072
  /** @internal An empty export has no data table; it still emits the declared headers. */
@@ -4051,7 +4117,7 @@ class Worksheet {
4051
4117
  for (const binding of this.chartSources)
4052
4118
  binding.finish();
4053
4119
  this.chartSources.length = 0;
4054
- for (const link of this.links) {
4120
+ for (const link of this.compactLinks()) {
4055
4121
  const position = cellPosition(link.cell);
4056
4122
  if (position.column > this.columns.length || position.row > this.totalRows)
4057
4123
  throw new RangeError("Hyperlinks must address cells within the exported rows and columns.");
@@ -4081,8 +4147,11 @@ class Worksheet {
4081
4147
  await this.buffer.write(xml);
4082
4148
  for (const xml of dataValidationsXml(this.validations, this.headerRows, this.count, detailRanges))
4083
4149
  await this.buffer.write(xml);
4084
- if (this.links.length || this.internalLinks.length)
4085
- await this.buffer.write(hyperlinksXml(this.links, this.book.settings.invalidCharacterPolicy, this.internalLinks));
4150
+ if (this.droppedLinks)
4151
+ notifySynchronously("onHyperlinkOverflow", this.book.settings.onHyperlinkOverflow, Object.freeze({ sheetName: this.name, dropped: this.droppedLinks }));
4152
+ const links = this.compactLinks();
4153
+ if (links.length || this.internalLinks.length)
4154
+ await this.buffer.write(hyperlinksXml(links, this.book.settings.invalidCharacterPolicy, this.internalLinks));
4086
4155
  await this.buffer.write(printXml(this.options.print, this.book.settings.invalidCharacterPolicy));
4087
4156
  if (this.pictures.length || this.nativeCharts.length)
4088
4157
  await this.buffer.write('<drawing r:id="drawing"/>');
@@ -4107,11 +4176,11 @@ class Worksheet {
4107
4176
  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); }
4108
4177
  }
4109
4178
  const _exports = Object.freeze({ Worksheet: Worksheet });
4110
- _modules.set("a61e744201bb537b635b367b1764bd85892101d55e00b8c78faec8be89577376", _exports);
4179
+ _modules.set("d5957683aa1945575924c89c63b427878e6e6e47ef5c229dc524b1879d146499", _exports);
4111
4180
  return _exports;
4112
4181
  })();
4113
4182
 
4114
- const _m41 = _modules.get("1b4698baf9a9c9b3505988abac9f83967c32cf37483d70a949ae89c4485532a4") ?? (() => {
4183
+ const _m41 = _modules.get("c84eae41cd3066f5463d88a1f467117b37dd9e9c9ccd8c0f8a106aa41631fea0") ?? (() => {
4115
4184
  const { escapeOoxmlAttribute, escapeXml, xmlDeclaration } = _m17;
4116
4185
 
4117
4186
  const { cellText, columnName } = _m27;
@@ -4154,7 +4223,7 @@ function tableXml(table, rowCount, policy, headerRow = 1, footer) {
4154
4223
  '" showColumnStripes="' + (options.bandedColumns ? 1 : 0) + '"/></table>';
4155
4224
  }
4156
4225
  const _exports = Object.freeze({ defineTable: defineTable, tableXml: tableXml });
4157
- _modules.set("1b4698baf9a9c9b3505988abac9f83967c32cf37483d70a949ae89c4485532a4", _exports);
4226
+ _modules.set("c84eae41cd3066f5463d88a1f467117b37dd9e9c9ccd8c0f8a106aa41631fea0", _exports);
4158
4227
  return _exports;
4159
4228
  })();
4160
4229
 
@@ -4226,13 +4295,13 @@ _modules.set("0c395783b9d7cc62dd39a21adeb698ad4a61e2c89f7b1fc8712e2eb2ccfe9d92",
4226
4295
  return _exports;
4227
4296
  })();
4228
4297
 
4229
- const _m43 = _modules.get("477ff98f49343b8ec4213008254b57a60dd42d07cb9843b3791d5e5f8e295865") ?? (() => {
4298
+ const _m43 = _modules.get("fd70ccda89f27c6b874c8840ac944b3ec723dbdef3dfe7600f7bdb81f4660c96") ?? (() => {
4230
4299
  const { captureFields } = _m10;
4231
4300
 
4232
4301
  /** @internal The workbook owner captures these settings before validation or adapter merging. */
4233
- const workbookOptionFields = ["signal", "onProgress", "limits", "sink", "dateMode", "compression", "invalidCharacterPolicy", "appProperties", "cellValueWriters", "oversizedText", "creator", "title", "subject", "description", "created", "modified"];
4302
+ const workbookOptionFields = ["signal", "onProgress", "limits", "sink", "dateMode", "compression", "invalidCharacterPolicy", "appProperties", "cellValueWriters", "oversizedText", "hyperlinkOverflow", "onHyperlinkOverflow", "creator", "title", "subject", "description", "created", "modified"];
4234
4303
  /** @internal Worksheet settings also used by the portable sheet owner. */
4235
- 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"];
4304
+ 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"];
4236
4305
  /** @internal Includes inherited format-specific ceilings before a wrapper combines stream settings. */
4237
4306
  const workbookLimitFields = ["maxRows", "maxCells", "maxTextCharacters", "maxOutputBytes", "maxStyles", "maxSheets", "maxOverflowCharacters", "maxHyperlinks", "maxImageBytes", "maxBufferedCells", "maxBufferedCharacters", "maxMergedRanges", "maxConditionalFormats", "maxDifferentialStyles", "maxCharts", "maxChartPoints", "maxChartTextCharacters", "maxFormulaCharacters", "maxDataValidations", "maxValidationTextCharacters"];
4238
4307
  /** @internal Capture the workbook's known ceilings without dropping supported prototype fields. */
@@ -4245,7 +4314,7 @@ function captureWorkbookOptions(options) {
4245
4314
  return { ...captured, ...(captured.limits === undefined ? {} : { limits: captureWorkbookLimits(captured.limits) }) };
4246
4315
  }
4247
4316
  const _exports = Object.freeze({ workbookOptionFields: workbookOptionFields, sheetOptionFields: sheetOptionFields, workbookLimitFields: workbookLimitFields, captureWorkbookLimits: captureWorkbookLimits, captureWorkbookOptions: captureWorkbookOptions });
4248
- _modules.set("477ff98f49343b8ec4213008254b57a60dd42d07cb9843b3791d5e5f8e295865", _exports);
4317
+ _modules.set("fd70ccda89f27c6b874c8840ac944b3ec723dbdef3dfe7600f7bdb81f4660c96", _exports);
4249
4318
  return _exports;
4250
4319
  })();
4251
4320
 
@@ -4552,7 +4621,7 @@ _modules.set("24f1417c3c320a8a41137c28f70b72091256c63010be0c88b684dce85f54950c",
4552
4621
  return _exports;
4553
4622
  })();
4554
4623
 
4555
- const _m22 = _modules.get("e89ecd2f5e1738c6e88f72ac2bcac70dfaa81b4aa86edf333e9b395cf2212e2a") ?? (() => {
4624
+ const _m22 = _modules.get("a34a46ed9564c388d5f3ca087c70819f8aa897e469ca50f8547233c264a8e8af") ?? (() => {
4556
4625
  const { beginTask, checkAbort, pause, taskYieldDue } = _m4;
4557
4626
 
4558
4627
  const { OfficeIMOError } = _m2;
@@ -4567,7 +4636,7 @@ const { OpcPackage, officeRelationshipsNamespace, relationshipTypes, corePropert
4567
4636
 
4568
4637
  const { escapeOoxmlAttribute, cleanXml, xmlDeclaration } = _m17;
4569
4638
 
4570
- const { StyleRegistry, spreadsheetNamespace } = _m24;
4639
+ const { StyleRegistry, spreadsheetNamespace, normalizeBorder } = _m24;
4571
4640
 
4572
4641
  const { sheetName, assertXlsxValue, copyValue } = _m27;
4573
4642
 
@@ -4608,6 +4677,8 @@ function captureSheet(options, policy) {
4608
4677
  return { ...captured, columns,
4609
4678
  ...(captured.columnOutlines === undefined ? {} : { columnOutlines: captureColumnOutlines(captured.columnOutlines, columns.length) }),
4610
4679
  ...(captured.headerRows === undefined ? {} : { headerRows: captureTableSpans(captured.headerRows, columns.length) }),
4680
+ // Preflight and every header style read this one snapshot of the edges.
4681
+ ...(captured.headerBorder === undefined ? {} : { headerBorder: normalizeBorder(captured.headerBorder) }),
4611
4682
  ...(footer ? { footer: { ...footer,
4612
4683
  ...(footer.rows === undefined ? {} : { rows: captureTableSpans(footer.rows, columns.length) }),
4613
4684
  ...(footer.values === undefined ? {} : { values: footer.values.map(copyValue) }) } } : {}),
@@ -4683,6 +4754,10 @@ class Workbook {
4683
4754
  throw new RangeError("compression must be auto or store.");
4684
4755
  if (options.oversizedText !== undefined && !["reject", "preserve"].includes(options.oversizedText))
4685
4756
  throw new RangeError("oversizedText must be reject or preserve.");
4757
+ if (options.hyperlinkOverflow !== undefined && !["reject", "drop"].includes(options.hyperlinkOverflow))
4758
+ throw new RangeError("hyperlinkOverflow must be reject or drop.");
4759
+ if (options.onHyperlinkOverflow !== undefined && typeof options.onHyperlinkOverflow !== "function")
4760
+ throw new TypeError("onHyperlinkOverflow must be a function.");
4686
4761
  cleanXml("", policy);
4687
4762
  corePropertiesXml(options, policy);
4688
4763
  this.budget = new ExportBudget(options.limits);
@@ -4760,6 +4835,8 @@ class Workbook {
4760
4835
  }
4761
4836
  /** @internal Reserve a preflighted worksheet batch or one row hyperlink. */
4762
4837
  retainLink(count = 1) { this.checkLinks(count); this.links += count; }
4838
+ /** @internal A worksheet dropped a data-cell link it had retained. */
4839
+ releaseLink() { this.links--; }
4763
4840
  /** @internal */
4764
4841
  checkImage(bytes) {
4765
4842
  if (this.settings.limits?.maxImageBytes !== undefined && this.imageBytes + bytes > this.settings.limits.maxImageBytes)
@@ -5033,11 +5110,11 @@ class Workbook {
5033
5110
  }
5034
5111
  }
5035
5112
  const _exports = Object.freeze({ Workbook: Workbook });
5036
- _modules.set("e89ecd2f5e1738c6e88f72ac2bcac70dfaa81b4aa86edf333e9b395cf2212e2a", _exports);
5113
+ _modules.set("a34a46ed9564c388d5f3ca087c70819f8aa897e469ca50f8547233c264a8e8af", _exports);
5037
5114
  return _exports;
5038
5115
  })();
5039
5116
 
5040
- const _m47 = _modules.get("a10003e971cd5ec2cee127bc9b029a0aa06fe3d50112838929d7a04a55e177c0") ?? (() => {
5117
+ const _m47 = _modules.get("d6884428c3e4d15a691ecf2523372a03b32de22a890edfbfc9961f2dc92711c2") ?? (() => {
5041
5118
  const { ExportCell, assertScalar } = _m5;
5042
5119
 
5043
5120
  const { captureWorkbookOptions, sheetOptionFields } = _m43;
@@ -5059,7 +5136,7 @@ function value(result) {
5059
5136
  function portableSheet(options = {}) {
5060
5137
  options = captureFields(options, sheetOptionFields);
5061
5138
  if (options.headerStyle !== undefined)
5062
- throw new TypeError("Workbook-local header styles require the advanced Workbook API; use boldHeader and headerFill.");
5139
+ throw new TypeError("Workbook-local header styles require the advanced Workbook API; use boldHeader, headerFill, headerBorder and headerWrap.");
5063
5140
  style(options.alternatingRowStyle);
5064
5141
  style(options.title?.style);
5065
5142
  style(options.footer?.style);
@@ -5086,11 +5163,11 @@ function portableWorkbook(options = {}) {
5086
5163
  return { ...options, cellValueWriters: wrapped };
5087
5164
  }
5088
5165
  const _exports = Object.freeze({ portableSheet: portableSheet, portableWorkbook: portableWorkbook });
5089
- _modules.set("a10003e971cd5ec2cee127bc9b029a0aa06fe3d50112838929d7a04a55e177c0", _exports);
5166
+ _modules.set("d6884428c3e4d15a691ecf2523372a03b32de22a890edfbfc9961f2dc92711c2", _exports);
5090
5167
  return _exports;
5091
5168
  })();
5092
5169
 
5093
- const _m46 = _modules.get("5bfd5c9c5e179305b9bebd6cb0d6a0d75e974b223e119e0fd4fbb773325f1e63") ?? (() => {
5170
+ const _m46 = _modules.get("b9b1793c41e466048fe823422088a6fcc1fd8393c67293df3f0cd83a5d5ec7e1") ?? (() => {
5094
5171
  const { withDestination } = _m3;
5095
5172
 
5096
5173
  const { copyColumns } = _m11;
@@ -5145,11 +5222,11 @@ async function writeXlsxTo(rows, destination, configuration) {
5145
5222
  });
5146
5223
  }
5147
5224
  const _exports = Object.freeze({ writeXlsx: writeXlsx, writeXlsxTo: writeXlsxTo });
5148
- _modules.set("5bfd5c9c5e179305b9bebd6cb0d6a0d75e974b223e119e0fd4fbb773325f1e63", _exports);
5225
+ _modules.set("b9b1793c41e466048fe823422088a6fcc1fd8393c67293df3f0cd83a5d5ec7e1", _exports);
5149
5226
  return _exports;
5150
5227
  })();
5151
5228
 
5152
- const _m49 = _modules.get("dd34d5fd89869a0f953f3f2b3fd27ac83be29e68f76c9087fae3d33095aeda7c") ?? (() => {
5229
+ const _m49 = _modules.get("ba0e1f29c8de5d46b966b7b097260529e42b80f662e92a7f9e8add22df747a50") ?? (() => {
5153
5230
  const { assertGroupedReportSource } = _m8;
5154
5231
 
5155
5232
  const { captureFields } = _m10;
@@ -5238,11 +5315,11 @@ function prepareGroupedSheet(report, configuration, maxConditionalFormats = 1000
5238
5315
  ...(options.grandTotalStyle ? { grandTotalStyle: copyStylePatch(options.grandTotalStyle) } : {}) };
5239
5316
  }
5240
5317
  const _exports = Object.freeze({ groupedOptionFields: groupedOptionFields, prepareGroupedSheet: prepareGroupedSheet });
5241
- _modules.set("dd34d5fd89869a0f953f3f2b3fd27ac83be29e68f76c9087fae3d33095aeda7c", _exports);
5318
+ _modules.set("ba0e1f29c8de5d46b966b7b097260529e42b80f662e92a7f9e8add22df747a50", _exports);
5242
5319
  return _exports;
5243
5320
  })();
5244
5321
 
5245
- const _m48 = _modules.get("2ba62cdf88d559804bb84b20e9816b2de0f232401b7431ac414699a607d554a4") ?? (() => {
5322
+ const _m48 = _modules.get("d7cfa6a7b1be9758925a4ccb860a80a33eb0de2c88c80cc55e438213595f2b71") ?? (() => {
5246
5323
  const { groupedReportOperation } = _m8;
5247
5324
 
5248
5325
  const { checkAbort, withAbort } = _m4;
@@ -5415,14 +5492,14 @@ async function writeGroupedXlsxTo(report, destination, options) {
5415
5492
  return withDestination(destination, async (sink) => (await write(report, prepared, sink)).result);
5416
5493
  }
5417
5494
  const _exports = Object.freeze({ addGroupedXlsx: addGroupedXlsx, writeGroupedXlsx: writeGroupedXlsx, writeGroupedXlsxTo: writeGroupedXlsxTo });
5418
- _modules.set("2ba62cdf88d559804bb84b20e9816b2de0f232401b7431ac414699a607d554a4", _exports);
5495
+ _modules.set("d7cfa6a7b1be9758925a4ccb860a80a33eb0de2c88c80cc55e438213595f2b71", _exports);
5419
5496
  return _exports;
5420
5497
  })();
5421
5498
 
5422
- const _m21 = _modules.get("d6587a933b36ccfdba9a2a252389924ac8461f672b3a500082cceb5e53c8b0b6") ?? (() => {
5499
+ const _m21 = _modules.get("edf1bf5cb6d749de0e6823397df6610a6c1cc88768898c1b4d7083ee96ef6759") ?? (() => {
5423
5500
 
5424
5501
  const _exports = Object.freeze({ Workbook: _m22.Workbook, writeXlsx: _m46.writeXlsx, writeXlsxTo: _m46.writeXlsxTo, writeGroupedXlsx: _m48.writeGroupedXlsx, writeGroupedXlsxTo: _m48.writeGroupedXlsxTo, addGroupedXlsx: _m48.addGroupedXlsx, createGroupedReport: _m8.createGroupedReport, Worksheet: _m31.Worksheet, Cell: _m27.Cell, FormulaCell: _m28.FormulaCell, StyleRegistry: _m24.StyleRegistry, NumberFormats: _m24.NumberFormats, saveBlob: _m1.saveBlob, ExportCell: _m5.ExportCell });
5425
- _modules.set("d6587a933b36ccfdba9a2a252389924ac8461f672b3a500082cceb5e53c8b0b6", _exports);
5502
+ _modules.set("edf1bf5cb6d749de0e6823397df6610a6c1cc88768898c1b4d7083ee96ef6759", _exports);
5426
5503
  return _exports;
5427
5504
  })();
5428
5505
 
@@ -5482,7 +5559,7 @@ _modules.set("f0627ba89e5c8fcb376ebe3ce72dcc8d68c34952981f8703e36b8bb1a9894208",
5482
5559
  return _exports;
5483
5560
  })();
5484
5561
 
5485
- const _m50 = _modules.get("b48bcab805d4c75294dd8d8e8dc57f96d9db3f5af31a8f0ddc6562f010f566e4") ?? (() => {
5562
+ const _m50 = _modules.get("406ac6c93ee68eae70c6f52a1e6f4c56b84f43cae12576040c766dcc5598a580") ?? (() => {
5486
5563
  const { beginTask, checkAbort, consumeRows, taskYieldDue, withAbort } = _m4;
5487
5564
 
5488
5565
  const { BlobByteSink, ChunkedTextSink, withDestination } = _m3;
@@ -5632,7 +5709,7 @@ async function writeCsv(rows, configuration) {
5632
5709
  }
5633
5710
  }
5634
5711
  const _exports = Object.freeze({ saveBlob: _m1.saveBlob, ExportCell: _m5.ExportCell, writeCsvTo: writeCsvTo, writeCsv: writeCsv });
5635
- _modules.set("b48bcab805d4c75294dd8d8e8dc57f96d9db3f5af31a8f0ddc6562f010f566e4", _exports);
5712
+ _modules.set("406ac6c93ee68eae70c6f52a1e6f4c56b84f43cae12576040c766dcc5598a580", _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 } = _m16;
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,17 +11861,17 @@ _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
 
11633
- const _m0 = _modules.get("24797253ebcf6e25ce43ac76d1f16d0ce85b477a461faa1d167dabbea8e43968") ?? (() => {
11871
+ const _m0 = _modules.get("9bbfb2fef7625be5b610e82b6ee2d1cd50af97c40c82ef07531ae92c803e47c1") ?? (() => {
11634
11872
 
11635
11873
  const _exports = Object.freeze({ core: _m1, zip: _m14, xml: _m17, opc: _m18, xlsx: _m21, csv: _m50, pdf: _m54, Workbook: _m21.Workbook, Worksheet: _m21.Worksheet, Cell: _m21.Cell, FormulaCell: _m21.FormulaCell, StyleRegistry: _m21.StyleRegistry, NumberFormats: _m21.NumberFormats, writeXlsx: _m21.writeXlsx, writeXlsxTo: _m21.writeXlsxTo, writeCsv: _m50.writeCsv, writeCsvTo: _m50.writeCsvTo, createGroupedReport: _m8.createGroupedReport, writeGroupedXlsx: _m48.writeGroupedXlsx, writeGroupedXlsxTo: _m48.writeGroupedXlsxTo, addGroupedXlsx: _m48.addGroupedXlsx, writeGroupedPdf: _m83.writeGroupedPdf, writeGroupedPdfTo: _m83.writeGroupedPdfTo, pdfGroupedTable: _m83.pdfGroupedTable, writePdf: _m54.writePdf, writePdfTo: _m54.writePdfTo, writePdfDocument: _m54.writePdfDocument, writePdfDocumentTo: _m54.writePdfDocumentTo, pdfTable: _m54.pdfTable, PdfFont: _m54.PdfFont, preflightPdfText: _m54.preflightPdfText, OfficeIMOError: _m1.OfficeIMOError, NotSupportedError: _m1.NotSupportedError, detectFeatures: _m1.detectFeatures, saveBlob: _m1.saveBlob, ExportCell: _m1.ExportCell });
11636
- _modules.set("24797253ebcf6e25ce43ac76d1f16d0ce85b477a461faa1d167dabbea8e43968", _exports);
11874
+ _modules.set("9bbfb2fef7625be5b610e82b6ee2d1cd50af97c40c82ef07531ae92c803e47c1", _exports);
11637
11875
  return _exports;
11638
11876
  })();
11639
11877
  Object.assign(officeimo, _m0);