@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.
@@ -1371,6 +1371,8 @@ const { OfficeIMOError } = _m2;
1371
1371
  const { ChunkedTextSink } = _m3;
1372
1372
 
1373
1373
  const xmlDeclaration = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
1374
+ const xmlEscapes = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&apos;",
1375
+ "\r": "&#13;", "\n": "&#10;", "\t": "&#9;" };
1374
1376
  /** XML 1.0 characters; Unicode mode retains valid surrogate pairs. */
1375
1377
  function cleanXml(value, policy = "strip") {
1376
1378
  if (policy !== "strip" && policy !== "reject")
@@ -1382,9 +1384,7 @@ function cleanXml(value, policy = "strip") {
1382
1384
  }
1383
1385
  /** Escape data, including whitespace that XML parsers otherwise normalize. */
1384
1386
  function escapeXml(value, policy = "strip") {
1385
- const escapes = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&apos;",
1386
- "\r": "&#13;", "\n": "&#10;", "\t": "&#9;" };
1387
- return cleanXml(value, policy).replace(/[&<>"'\r\n\t]/g, c => escapes[c]);
1387
+ return cleanXml(value, policy).replace(/[&<>"'\r\n\t]/g, c => xmlEscapes[c]);
1388
1388
  }
1389
1389
  /** Encode an OOXML ST_Xstring attribute without interpreting literal escape tokens as characters. */
1390
1390
  function escapeOoxmlAttribute(value, policy = "strip") {
@@ -1617,8 +1617,11 @@ class OpcPackage {
1617
1617
  return uri;
1618
1618
  }
1619
1619
  addPart(part) {
1620
- const uri = this.reserve(part.uri, part.contentType);
1621
- this.parts.set(uri.toLowerCase(), { ...part, uri, data: part.data instanceof Uint8Array ? new Uint8Array(part.data) : part.data });
1620
+ const { uri: requestedUri, contentType, data } = part;
1621
+ // Structural accessors and byte ownership are captured before reserving metadata.
1622
+ const capturedData = data instanceof Uint8Array ? new Uint8Array(data) : data;
1623
+ const uri = this.reserve(requestedUri, contentType);
1624
+ this.parts.set(uri.toLowerCase(), { uri, contentType, data: capturedData });
1622
1625
  }
1623
1626
  /** @internal */
1624
1627
  addPrepared(uri, type, prepared) {
@@ -1643,17 +1646,19 @@ class OpcPackage {
1643
1646
  checkAbort(this.options.signal);
1644
1647
  this.open();
1645
1648
  source = source === "/" ? source : partUri(source);
1646
- if (!/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(relationship.id))
1649
+ const { id, type, target: requestedTarget, external } = relationship;
1650
+ this.open();
1651
+ if (!/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(id))
1647
1652
  throw new TypeError("Relationship id must be an XML ID.");
1648
- if (!/^[A-Za-z][A-Za-z0-9+.-]*:[^\s<>"']+$/.test(relationship.type))
1653
+ if (!/^[A-Za-z][A-Za-z0-9+.-]*:[^\s<>"']+$/.test(type))
1649
1654
  throw new TypeError("Relationship type must be an absolute URI.");
1650
- const target = relationship.external ? relationship.target : partUri(relationship.target);
1651
- if (relationship.external && (!target || /[\u0000-\u0020]/.test(target)))
1655
+ const target = external ? requestedTarget : partUri(requestedTarget);
1656
+ if (external && (!target || /[\u0000-\u0020]/.test(target)))
1652
1657
  throw new TypeError("Invalid external relationship target.");
1653
1658
  const key = source.toLowerCase(), list = this.relationships.get(key) ?? new Map();
1654
- if (list.has(relationship.id))
1655
- throw new TypeError("Duplicate relationship id: " + relationship.id);
1656
- list.set(relationship.id, { ...relationship, target });
1659
+ if (list.has(id))
1660
+ throw new TypeError("Duplicate relationship id: " + id);
1661
+ list.set(id, { id, type, target, ...(external === undefined ? {} : { external }) });
1657
1662
  this.relationships.set(key, list);
1658
1663
  }
1659
1664
  setProperties(core = {}, app = {}) {
@@ -3544,7 +3549,8 @@ class Worksheet {
3544
3549
  });
3545
3550
  const originalCharacters = typeof value === "string" ? value.length : 0;
3546
3551
  let reservedCharacters = this.preserved || header || footer ? originalCharacters : undefined;
3547
- if (type === "string" && cleanXml(value, this.book.settings.invalidCharacterPolicy).length > 32767) {
3552
+ // Cleaning removes characters; ordinary strings cannot cross Excel's limit.
3553
+ if (type === "string" && originalCharacters > 32767 && cleanXml(value, this.book.settings.invalidCharacterPolicy).length > 32767) {
3548
3554
  const cell = col.letter + row;
3549
3555
  if (link || this.linkedCells.has(cell))
3550
3556
  throw new TypeError("A text-preservation cell cannot also have an external hyperlink.");
@@ -4764,12 +4770,15 @@ class Workbook {
4764
4770
  });
4765
4771
  }
4766
4772
  addPart(part) {
4773
+ this.assertOpen();
4774
+ const { uri, contentType, data, relationship } = part;
4775
+ const capturedRelationship = relationship && { id: relationship.id, type: relationship.type, source: relationship.source };
4767
4776
  this.assertOpen();
4768
4777
  // Reserve now so collisions and invalid names fail at the call site.
4769
- this.package.addPart(part);
4770
- if (part.relationship) {
4771
- const { source, ...rel } = part.relationship;
4772
- this.package.addRelationship(source ?? "/xl/workbook.xml", { ...rel, target: part.uri });
4778
+ this.package.addPart({ uri, contentType, data });
4779
+ if (capturedRelationship) {
4780
+ const { source, id, type } = capturedRelationship;
4781
+ this.package.addRelationship(source ?? "/xl/workbook.xml", { id, type, target: uri });
4773
4782
  }
4774
4783
  }
4775
4784
  /** Complete the archive and return counts. Does not close or dispose a caller-owned sink. */
@@ -8816,7 +8825,7 @@ class PdfPages {
8816
8825
  // Charge physical repeats without recapturing callbacks or making them semantic duplicates.
8817
8826
  for (const cell of header.cells)
8818
8827
  if (!this.bandCellBudget && this.paintedHeaderBudgetCells.has(cell.source ?? cell))
8819
- this.settings.budget.cell(cell.lines.map(line => line.text).join(""));
8828
+ this.settings.budget.cell(this.settings.budget.limits.maxTextCharacters === undefined ? "" : cell.lines.map(line => line.text).join(""));
8820
8829
  const elements = this.tableStructure ? header.cells.map(cell => this.tableStructure.owner(cell.source ?? cell)) : undefined;
8821
8830
  const repeated = header.cells.map(cell => this.paintedHeaderCells.has(cell.source ?? cell));
8822
8831
  this.draw(header, 0, header.lines, elements, repeated);
@@ -8837,7 +8846,8 @@ class PdfPages {
8837
8846
  const { padding, fontSize } = this.settings, n = pdfNumber, height = lineCount * row.lineHeight + padding * 2;
8838
8847
  for (const [index, cell] of row.cells.entries()) {
8839
8848
  if (this.bandCellBudget)
8840
- this.settings.budget.cell((cell.height === undefined ? cell.lines.slice(firstLine, firstLine + lineCount) : cell.lines).map(line => line.text).join(""));
8849
+ this.settings.budget.cell(this.settings.budget.limits.maxTextCharacters === undefined ? "" :
8850
+ (cell.height === undefined ? cell.lines.slice(firstLine, firstLine + lineCount) : cell.lines).map(line => line.text).join(""));
8841
8851
  const x = this.layout.lefts[cell.first], cellHeight = cell.height ?? height;
8842
8852
  if (cell.style.background)
8843
8853
  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"));
package/dist/opc/index.js CHANGED
@@ -86,8 +86,11 @@ export class OpcPackage {
86
86
  return uri;
87
87
  }
88
88
  addPart(part) {
89
- const uri = this.reserve(part.uri, part.contentType);
90
- this.parts.set(uri.toLowerCase(), { ...part, uri, data: part.data instanceof Uint8Array ? new Uint8Array(part.data) : part.data });
89
+ const { uri: requestedUri, contentType, data } = part;
90
+ // Structural accessors and byte ownership are captured before reserving metadata.
91
+ const capturedData = data instanceof Uint8Array ? new Uint8Array(data) : data;
92
+ const uri = this.reserve(requestedUri, contentType);
93
+ this.parts.set(uri.toLowerCase(), { uri, contentType, data: capturedData });
91
94
  }
92
95
  /** @internal */
93
96
  addPrepared(uri, type, prepared) {
@@ -112,17 +115,19 @@ export class OpcPackage {
112
115
  checkAbort(this.options.signal);
113
116
  this.open();
114
117
  source = source === "/" ? source : partUri(source);
115
- if (!/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(relationship.id))
118
+ const { id, type, target: requestedTarget, external } = relationship;
119
+ this.open();
120
+ if (!/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(id))
116
121
  throw new TypeError("Relationship id must be an XML ID.");
117
- if (!/^[A-Za-z][A-Za-z0-9+.-]*:[^\s<>"']+$/.test(relationship.type))
122
+ if (!/^[A-Za-z][A-Za-z0-9+.-]*:[^\s<>"']+$/.test(type))
118
123
  throw new TypeError("Relationship type must be an absolute URI.");
119
- const target = relationship.external ? relationship.target : partUri(relationship.target);
120
- if (relationship.external && (!target || /[\u0000-\u0020]/.test(target)))
124
+ const target = external ? requestedTarget : partUri(requestedTarget);
125
+ if (external && (!target || /[\u0000-\u0020]/.test(target)))
121
126
  throw new TypeError("Invalid external relationship target.");
122
127
  const key = source.toLowerCase(), list = this.relationships.get(key) ?? new Map();
123
- if (list.has(relationship.id))
124
- throw new TypeError("Duplicate relationship id: " + relationship.id);
125
- list.set(relationship.id, { ...relationship, target });
128
+ if (list.has(id))
129
+ throw new TypeError("Duplicate relationship id: " + id);
130
+ list.set(id, { id, type, target, ...(external === undefined ? {} : { external }) });
126
131
  this.relationships.set(key, list);
127
132
  }
128
133
  setProperties(core = {}, app = {}) {
package/dist/pdf/pages.js CHANGED
@@ -271,7 +271,7 @@ export class PdfPages {
271
271
  // Charge physical repeats without recapturing callbacks or making them semantic duplicates.
272
272
  for (const cell of header.cells)
273
273
  if (!this.bandCellBudget && this.paintedHeaderBudgetCells.has(cell.source ?? cell))
274
- this.settings.budget.cell(cell.lines.map(line => line.text).join(""));
274
+ this.settings.budget.cell(this.settings.budget.limits.maxTextCharacters === undefined ? "" : cell.lines.map(line => line.text).join(""));
275
275
  const elements = this.tableStructure ? header.cells.map(cell => this.tableStructure.owner(cell.source ?? cell)) : undefined;
276
276
  const repeated = header.cells.map(cell => this.paintedHeaderCells.has(cell.source ?? cell));
277
277
  this.draw(header, 0, header.lines, elements, repeated);
@@ -292,7 +292,8 @@ export class PdfPages {
292
292
  const { padding, fontSize } = this.settings, n = pdfNumber, height = lineCount * row.lineHeight + padding * 2;
293
293
  for (const [index, cell] of row.cells.entries()) {
294
294
  if (this.bandCellBudget)
295
- this.settings.budget.cell((cell.height === undefined ? cell.lines.slice(firstLine, firstLine + lineCount) : cell.lines).map(line => line.text).join(""));
295
+ this.settings.budget.cell(this.settings.budget.limits.maxTextCharacters === undefined ? "" :
296
+ (cell.height === undefined ? cell.lines.slice(firstLine, firstLine + lineCount) : cell.lines).map(line => line.text).join(""));
296
297
  const x = this.layout.lefts[cell.first], cellHeight = cell.height ?? height;
297
298
  if (cell.style.background)
298
299
  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"));
@@ -315,12 +315,15 @@ export class Workbook {
315
315
  });
316
316
  }
317
317
  addPart(part) {
318
+ this.assertOpen();
319
+ const { uri, contentType, data, relationship } = part;
320
+ const capturedRelationship = relationship && { id: relationship.id, type: relationship.type, source: relationship.source };
318
321
  this.assertOpen();
319
322
  // Reserve now so collisions and invalid names fail at the call site.
320
- this.package.addPart(part);
321
- if (part.relationship) {
322
- const { source, ...rel } = part.relationship;
323
- this.package.addRelationship(source ?? "/xl/workbook.xml", { ...rel, target: part.uri });
323
+ this.package.addPart({ uri, contentType, data });
324
+ if (capturedRelationship) {
325
+ const { source, id, type } = capturedRelationship;
326
+ this.package.addRelationship(source ?? "/xl/workbook.xml", { id, type, target: uri });
324
327
  }
325
328
  }
326
329
  /** Complete the archive and return counts. Does not close or dispose a caller-owned sink. */
@@ -257,7 +257,8 @@ export class Worksheet {
257
257
  });
258
258
  const originalCharacters = typeof value === "string" ? value.length : 0;
259
259
  let reservedCharacters = this.preserved || header || footer ? originalCharacters : undefined;
260
- if (type === "string" && cleanXml(value, this.book.settings.invalidCharacterPolicy).length > 32767) {
260
+ // Cleaning removes characters; ordinary strings cannot cross Excel's limit.
261
+ if (type === "string" && originalCharacters > 32767 && cleanXml(value, this.book.settings.invalidCharacterPolicy).length > 32767) {
261
262
  const cell = col.letter + row;
262
263
  if (link || this.linkedCells.has(cell))
263
264
  throw new TypeError("A text-preservation cell cannot also have an external hyperlink.");
package/dist/xml/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { OfficeIMOError } from "../core/errors.js";
2
2
  import { ChunkedTextSink } from "../core/sinks.js";
3
3
  export const xmlDeclaration = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
4
+ const xmlEscapes = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&apos;",
5
+ "\r": "&#13;", "\n": "&#10;", "\t": "&#9;" };
4
6
  /** XML 1.0 characters; Unicode mode retains valid surrogate pairs. */
5
7
  export function cleanXml(value, policy = "strip") {
6
8
  if (policy !== "strip" && policy !== "reject")
@@ -12,9 +14,7 @@ export function cleanXml(value, policy = "strip") {
12
14
  }
13
15
  /** Escape data, including whitespace that XML parsers otherwise normalize. */
14
16
  export function escapeXml(value, policy = "strip") {
15
- const escapes = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&apos;",
16
- "\r": "&#13;", "\n": "&#10;", "\t": "&#9;" };
17
- return cleanXml(value, policy).replace(/[&<>"'\r\n\t]/g, c => escapes[c]);
17
+ return cleanXml(value, policy).replace(/[&<>"'\r\n\t]/g, c => xmlEscapes[c]);
18
18
  }
19
19
  /** Encode an OOXML ST_Xstring attribute without interpreting literal escape tokens as characters. */
20
20
  export function escapeOoxmlAttribute(value, policy = "strip") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evotecit/officeimo",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Dependency-free OfficeIMO document libraries for browsers, workers and Node.",
5
5
  "type": "module",
6
6
  "license": "MIT",