@evotecit/officeimo 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1502,6 +1502,8 @@ const { OfficeIMOError } = _m2;
1502
1502
  const { ChunkedTextSink } = _m3;
1503
1503
 
1504
1504
  const xmlDeclaration = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
1505
+ const xmlEscapes = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&apos;",
1506
+ "\r": "&#13;", "\n": "&#10;", "\t": "&#9;" };
1505
1507
  /** XML 1.0 characters; Unicode mode retains valid surrogate pairs. */
1506
1508
  function cleanXml(value, policy = "strip") {
1507
1509
  if (policy !== "strip" && policy !== "reject")
@@ -1513,9 +1515,7 @@ function cleanXml(value, policy = "strip") {
1513
1515
  }
1514
1516
  /** Escape data, including whitespace that XML parsers otherwise normalize. */
1515
1517
  function escapeXml(value, policy = "strip") {
1516
- const escapes = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&apos;",
1517
- "\r": "&#13;", "\n": "&#10;", "\t": "&#9;" };
1518
- return cleanXml(value, policy).replace(/[&<>"'\r\n\t]/g, c => escapes[c]);
1518
+ return cleanXml(value, policy).replace(/[&<>"'\r\n\t]/g, c => xmlEscapes[c]);
1519
1519
  }
1520
1520
  /** Encode an OOXML ST_Xstring attribute without interpreting literal escape tokens as characters. */
1521
1521
  function escapeOoxmlAttribute(value, policy = "strip") {
@@ -2113,8 +2113,11 @@ class OpcPackage {
2113
2113
  return uri;
2114
2114
  }
2115
2115
  addPart(part) {
2116
- const uri = this.reserve(part.uri, part.contentType);
2117
- this.parts.set(uri.toLowerCase(), { ...part, uri, data: part.data instanceof Uint8Array ? new Uint8Array(part.data) : part.data });
2116
+ const { uri: requestedUri, contentType, data } = part;
2117
+ // Structural accessors and byte ownership are captured before reserving metadata.
2118
+ const capturedData = data instanceof Uint8Array ? new Uint8Array(data) : data;
2119
+ const uri = this.reserve(requestedUri, contentType);
2120
+ this.parts.set(uri.toLowerCase(), { uri, contentType, data: capturedData });
2118
2121
  }
2119
2122
  /** @internal */
2120
2123
  addPrepared(uri, type, prepared) {
@@ -2139,17 +2142,19 @@ class OpcPackage {
2139
2142
  checkAbort(this.options.signal);
2140
2143
  this.open();
2141
2144
  source = source === "/" ? source : partUri(source);
2142
- if (!/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(relationship.id))
2145
+ const { id, type, target: requestedTarget, external } = relationship;
2146
+ this.open();
2147
+ if (!/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(id))
2143
2148
  throw new TypeError("Relationship id must be an XML ID.");
2144
- if (!/^[A-Za-z][A-Za-z0-9+.-]*:[^\s<>"']+$/.test(relationship.type))
2149
+ if (!/^[A-Za-z][A-Za-z0-9+.-]*:[^\s<>"']+$/.test(type))
2145
2150
  throw new TypeError("Relationship type must be an absolute URI.");
2146
- const target = relationship.external ? relationship.target : partUri(relationship.target);
2147
- if (relationship.external && (!target || /[\u0000-\u0020]/.test(target)))
2151
+ const target = external ? requestedTarget : partUri(requestedTarget);
2152
+ if (external && (!target || /[\u0000-\u0020]/.test(target)))
2148
2153
  throw new TypeError("Invalid external relationship target.");
2149
2154
  const key = source.toLowerCase(), list = this.relationships.get(key) ?? new Map();
2150
- if (list.has(relationship.id))
2151
- throw new TypeError("Duplicate relationship id: " + relationship.id);
2152
- list.set(relationship.id, { ...relationship, target });
2155
+ if (list.has(id))
2156
+ throw new TypeError("Duplicate relationship id: " + id);
2157
+ list.set(id, { id, type, target, ...(external === undefined ? {} : { external }) });
2153
2158
  this.relationships.set(key, list);
2154
2159
  }
2155
2160
  setProperties(core = {}, app = {}) {
@@ -3960,7 +3965,8 @@ class Worksheet {
3960
3965
  });
3961
3966
  const originalCharacters = typeof value === "string" ? value.length : 0;
3962
3967
  let reservedCharacters = this.preserved || header || footer ? originalCharacters : undefined;
3963
- if (type === "string" && cleanXml(value, this.book.settings.invalidCharacterPolicy).length > 32767) {
3968
+ // Cleaning removes characters; ordinary strings cannot cross Excel's limit.
3969
+ if (type === "string" && originalCharacters > 32767 && cleanXml(value, this.book.settings.invalidCharacterPolicy).length > 32767) {
3964
3970
  const cell = col.letter + row;
3965
3971
  if (link || this.linkedCells.has(cell))
3966
3972
  throw new TypeError("A text-preservation cell cannot also have an external hyperlink.");
@@ -5158,12 +5164,15 @@ class Workbook {
5158
5164
  });
5159
5165
  }
5160
5166
  addPart(part) {
5167
+ this.assertOpen();
5168
+ const { uri, contentType, data, relationship } = part;
5169
+ const capturedRelationship = relationship && { id: relationship.id, type: relationship.type, source: relationship.source };
5161
5170
  this.assertOpen();
5162
5171
  // Reserve now so collisions and invalid names fail at the call site.
5163
- this.package.addPart(part);
5164
- if (part.relationship) {
5165
- const { source, ...rel } = part.relationship;
5166
- this.package.addRelationship(source ?? "/xl/workbook.xml", { ...rel, target: part.uri });
5172
+ this.package.addPart({ uri, contentType, data });
5173
+ if (capturedRelationship) {
5174
+ const { source, id, type } = capturedRelationship;
5175
+ this.package.addRelationship(source ?? "/xl/workbook.xml", { id, type, target: uri });
5167
5176
  }
5168
5177
  }
5169
5178
  /** Complete the archive and return counts. Does not close or dispose a caller-owned sink. */
@@ -8860,7 +8869,7 @@ class PdfPages {
8860
8869
  // Charge physical repeats without recapturing callbacks or making them semantic duplicates.
8861
8870
  for (const cell of header.cells)
8862
8871
  if (!this.bandCellBudget && this.paintedHeaderBudgetCells.has(cell.source ?? cell))
8863
- this.settings.budget.cell(cell.lines.map(line => line.text).join(""));
8872
+ this.settings.budget.cell(this.settings.budget.limits.maxTextCharacters === undefined ? "" : cell.lines.map(line => line.text).join(""));
8864
8873
  const elements = this.tableStructure ? header.cells.map(cell => this.tableStructure.owner(cell.source ?? cell)) : undefined;
8865
8874
  const repeated = header.cells.map(cell => this.paintedHeaderCells.has(cell.source ?? cell));
8866
8875
  this.draw(header, 0, header.lines, elements, repeated);
@@ -8881,7 +8890,8 @@ class PdfPages {
8881
8890
  const { padding, fontSize } = this.settings, n = pdfNumber, height = lineCount * row.lineHeight + padding * 2;
8882
8891
  for (const [index, cell] of row.cells.entries()) {
8883
8892
  if (this.bandCellBudget)
8884
- this.settings.budget.cell((cell.height === undefined ? cell.lines.slice(firstLine, firstLine + lineCount) : cell.lines).map(line => line.text).join(""));
8893
+ this.settings.budget.cell(this.settings.budget.limits.maxTextCharacters === undefined ? "" :
8894
+ (cell.height === undefined ? cell.lines.slice(firstLine, firstLine + lineCount) : cell.lines).map(line => line.text).join(""));
8885
8895
  const x = this.layout.lefts[cell.first], cellHeight = cell.height ?? height;
8886
8896
  if (cell.style.background)
8887
8897
  this.add(this.artifact("q " + this.rgb(cell.style.background) + " rg " + n(x) + " " + n(this.y - cellHeight) + " " + n(cell.width) + " " + n(cellHeight) + " re f Q\n"));