@evotecit/officeimo 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +13 -10
  2. package/bundles/officeimo-canopyx.js +842 -377
  3. package/bundles/officeimo-canopyx.mjs +729 -265
  4. package/bundles/officeimo-csv.js +29 -19
  5. package/bundles/officeimo-csv.mjs +17 -7
  6. package/bundles/officeimo-datatables.js +835 -379
  7. package/bundles/officeimo-datatables.mjs +723 -268
  8. package/bundles/officeimo-execution.js +35 -25
  9. package/bundles/officeimo-execution.mjs +17 -7
  10. package/bundles/officeimo-pdf.js +737 -291
  11. package/bundles/officeimo-pdf.mjs +688 -243
  12. package/bundles/officeimo-xlsx.js +114 -94
  13. package/bundles/officeimo-xlsx.mjs +48 -28
  14. package/bundles/officeimo.js +819 -363
  15. package/bundles/officeimo.mjs +709 -254
  16. package/dist/core/index.d.ts +2 -0
  17. package/dist/core/iteration.js +2 -2
  18. package/dist/core/sinks.js +2 -1
  19. package/dist/integrations/canopyx/source.js +13 -7
  20. package/dist/integrations/datatables/snapshot.js +3 -3
  21. package/dist/internal/rows.js +13 -4
  22. package/dist/opc/index.js +14 -9
  23. package/dist/pdf/document-grouped.js +72 -22
  24. package/dist/pdf/font-resources.js +2 -1
  25. package/dist/pdf/inline-text.js +50 -9
  26. package/dist/pdf/objects.js +188 -11
  27. package/dist/pdf/pages.js +28 -28
  28. package/dist/pdf/paragraph-layout.d.ts +2 -0
  29. package/dist/pdf/paragraph-layout.js +9 -4
  30. package/dist/pdf/session.js +1 -1
  31. package/dist/pdf/settings.d.ts +2 -0
  32. package/dist/pdf/settings.js +27 -2
  33. package/dist/pdf/structure.js +80 -28
  34. package/dist/pdf/table-band-flow.js +26 -11
  35. package/dist/pdf/table-band-plan.js +1 -3
  36. package/dist/pdf/table-layout.d.ts +4 -0
  37. package/dist/pdf/table-layout.js +22 -10
  38. package/dist/pdf/table-structure.js +28 -12
  39. package/dist/pdf/text.js +5 -0
  40. package/dist/pdf/types.d.ts +4 -2
  41. package/dist/pdf/xref.d.ts +1 -0
  42. package/dist/pdf/xref.js +30 -0
  43. package/dist/xlsx/values.js +3 -2
  44. package/dist/xlsx/workbook.js +7 -4
  45. package/dist/xlsx/worksheet.js +2 -1
  46. package/dist/xml/index.js +3 -3
  47. package/dist/zip/entry.js +1 -1
  48. package/dist/zip/index.js +1 -1
  49. package/package.json +1 -1
@@ -2,7 +2,7 @@
2
2
  const _m2 = (() => {
3
3
  function checkAbort(signal) {
4
4
  if (signal?.aborted)
5
- throw signal.reason ?? new DOMException("Export cancelled.", "AbortError");
5
+ throw signal.reason;
6
6
  }
7
7
  /** Race a pending producer or sink operation without leaving abort listeners behind. */
8
8
  function withAbort(promise, signal) {
@@ -10,7 +10,7 @@ function withAbort(promise, signal) {
10
10
  return Promise.resolve(promise);
11
11
  return new Promise((resolve, reject) => {
12
12
  const cleanup = () => signal.removeEventListener("abort", abort);
13
- const abort = () => { cleanup(); reject(signal.reason ?? new DOMException("Export cancelled.", "AbortError")); };
13
+ const abort = () => { cleanup(); reject(signal.reason); };
14
14
  signal.addEventListener("abort", abort, { once: true });
15
15
  Promise.resolve(promise).then(value => { cleanup(); resolve(value); }, error => { cleanup(); reject(error); });
16
16
  if (signal.aborted)
@@ -214,8 +214,9 @@ async function withDestination(destination, operation) {
214
214
  // Native streams can belong to another browser realm; constructor identity is not portable.
215
215
  if (destination && typeof destination.getWriter === "function") {
216
216
  const writer = destination.getWriter();
217
+ // Native streams may retain accepted chunks after write resolves.
217
218
  try {
218
- return await operation({ write: bytes => writer.write(bytes) });
219
+ return await operation({ write: bytes => writer.write(new Uint8Array(bytes)) });
219
220
  }
220
221
  finally {
221
222
  writer.releaseLock();
@@ -447,6 +448,8 @@ const { OfficeIMOError } = _m3;
447
448
  const { ChunkedTextSink } = _m5;
448
449
 
449
450
  const xmlDeclaration = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
451
+ const xmlEscapes = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&apos;",
452
+ "\r": "&#13;", "\n": "&#10;", "\t": "&#9;" };
450
453
  /** XML 1.0 characters; Unicode mode retains valid surrogate pairs. */
451
454
  function cleanXml(value, policy = "strip") {
452
455
  if (policy !== "strip" && policy !== "reject")
@@ -458,9 +461,7 @@ function cleanXml(value, policy = "strip") {
458
461
  }
459
462
  /** Escape data, including whitespace that XML parsers otherwise normalize. */
460
463
  function escapeXml(value, policy = "strip") {
461
- const escapes = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&apos;",
462
- "\r": "&#13;", "\n": "&#10;", "\t": "&#9;" };
463
- return cleanXml(value, policy).replace(/[&<>"'\r\n\t]/g, c => escapes[c]);
464
+ return cleanXml(value, policy).replace(/[&<>"'\r\n\t]/g, c => xmlEscapes[c]);
464
465
  }
465
466
  /** Encode an OOXML ST_Xstring attribute without interpreting literal escape tokens as characters. */
466
467
  function escapeOoxmlAttribute(value, policy = "strip") {
@@ -621,7 +622,7 @@ class EntryWriter {
621
622
  closed = false;
622
623
  cleaned = false;
623
624
  lifetime = new AbortController();
624
- abort = () => { this.fail(this.signal?.reason ?? new DOMException("Export cancelled.", "AbortError")); };
625
+ abort = () => { this.fail(this.signal?.reason); };
625
626
  constructor(compression, sink, signal) {
626
627
  this.sink = sink;
627
628
  this.signal = signal;
@@ -785,7 +786,7 @@ class ZipWriter {
785
786
  /** Pending header/directory writes and source reads must also stop on explicit discard. */
786
787
  async acceptance(operation) {
787
788
  const signal = this.options.signal;
788
- const abort = () => this.lifetime.abort(signal?.reason ?? new DOMException("Export cancelled.", "AbortError"));
789
+ const abort = () => this.lifetime.abort(signal?.reason);
789
790
  signal?.addEventListener("abort", abort, { once: true });
790
791
  try {
791
792
  checkAbort(signal);
@@ -1079,8 +1080,11 @@ class OpcPackage {
1079
1080
  return uri;
1080
1081
  }
1081
1082
  addPart(part) {
1082
- const uri = this.reserve(part.uri, part.contentType);
1083
- this.parts.set(uri.toLowerCase(), { ...part, uri, data: part.data instanceof Uint8Array ? new Uint8Array(part.data) : part.data });
1083
+ const { uri: requestedUri, contentType, data } = part;
1084
+ // Structural accessors and byte ownership are captured before reserving metadata.
1085
+ const capturedData = data instanceof Uint8Array ? new Uint8Array(data) : data;
1086
+ const uri = this.reserve(requestedUri, contentType);
1087
+ this.parts.set(uri.toLowerCase(), { uri, contentType, data: capturedData });
1084
1088
  }
1085
1089
  /** @internal */
1086
1090
  addPrepared(uri, type, prepared) {
@@ -1105,17 +1109,19 @@ class OpcPackage {
1105
1109
  checkAbort(this.options.signal);
1106
1110
  this.open();
1107
1111
  source = source === "/" ? source : partUri(source);
1108
- if (!/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(relationship.id))
1112
+ const { id, type, target: requestedTarget, external } = relationship;
1113
+ this.open();
1114
+ if (!/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(id))
1109
1115
  throw new TypeError("Relationship id must be an XML ID.");
1110
- if (!/^[A-Za-z][A-Za-z0-9+.-]*:[^\s<>"']+$/.test(relationship.type))
1116
+ if (!/^[A-Za-z][A-Za-z0-9+.-]*:[^\s<>"']+$/.test(type))
1111
1117
  throw new TypeError("Relationship type must be an absolute URI.");
1112
- const target = relationship.external ? relationship.target : partUri(relationship.target);
1113
- if (relationship.external && (!target || /[\u0000-\u0020]/.test(target)))
1118
+ const target = external ? requestedTarget : partUri(requestedTarget);
1119
+ if (external && (!target || /[\u0000-\u0020]/.test(target)))
1114
1120
  throw new TypeError("Invalid external relationship target.");
1115
1121
  const key = source.toLowerCase(), list = this.relationships.get(key) ?? new Map();
1116
- if (list.has(relationship.id))
1117
- throw new TypeError("Duplicate relationship id: " + relationship.id);
1118
- list.set(relationship.id, { ...relationship, target });
1122
+ if (list.has(id))
1123
+ throw new TypeError("Duplicate relationship id: " + id);
1124
+ list.set(id, { id, type, target, ...(external === undefined ? {} : { external }) });
1119
1125
  this.relationships.set(key, list);
1120
1126
  }
1121
1127
  setProperties(core = {}, app = {}) {
@@ -1843,12 +1849,13 @@ function sheetName(requested, names, policy, register = true) {
1843
1849
  throw new TypeError("Sheet name must be a string.");
1844
1850
  // Validate and deduplicate the decoded literal value, before ST_Xstring attribute encoding.
1845
1851
  // A requested _xHHHH_ token is literal text; the serializer protects its leading underscore.
1846
- let base = cleanXml(requested, policy).replace(/[\[\]:*?/\\]/g, "_").trim().replace(/^'+|'+$/g, "").trim();
1852
+ let base = cleanXml(requested, policy).replace(/[\[\]:*?/\\]/g, "_").replace(/^[\s']+|[\s']+$/g, "");
1853
+ // Clipping can expose an internal apostrophe or the reserved History name.
1854
+ base = clipName(base, 31).replace(/[\s']+$/g, "");
1847
1855
  if (!base)
1848
1856
  base = "Sheet";
1849
1857
  if (base.toLowerCase() === "history")
1850
1858
  base += "_";
1851
- base = clipName(base, 31);
1852
1859
  let name = base, suffix = 2;
1853
1860
  while (names.has(name.toLowerCase())) {
1854
1861
  const tail = " (" + suffix++ + ")";
@@ -1887,11 +1894,18 @@ function createRowProjector(columns, worksheet, signal, validate = assertExportV
1887
1894
  const getters = columns.some(column => column.value);
1888
1895
  return (row, rowIndex = 0) => {
1889
1896
  if (Array.isArray(row) && !getters) {
1890
- if (row.length > columns.length)
1897
+ const length = row.length;
1898
+ if (length > columns.length)
1891
1899
  throw new RangeError("Row has more values than declared columns.");
1892
- for (const value of row)
1900
+ // Resolve each positional value once, just like key/value projections. Returning the
1901
+ // source array would let an accessor change a value after the portable-value check.
1902
+ const values = new Array(length);
1903
+ for (let index = 0; index < length; index++) {
1904
+ const value = row[index];
1893
1905
  validate(value);
1894
- return row;
1906
+ values[index] = value;
1907
+ }
1908
+ return values;
1895
1909
  }
1896
1910
  if (!row || typeof row !== "object" || isDate(row))
1897
1911
  throw new TypeError("A row must be an array or object.");
@@ -1920,7 +1934,7 @@ function createRowProjector(columns, worksheet, signal, validate = assertExportV
1920
1934
  };
1921
1935
  }
1922
1936
  /** @internal Shared metadata fields for full columns and adapter-owned partial overrides. */
1923
- const columnOptionFields = ["header", "key", "value", "width", "type", "format", "wrapText", "alignment", "groups", "style", "valueFormatter"];
1937
+ const columnOptionFields = ["header", "key", "value", "width", "type", "format", "wrapText", "alignment", "rowHeader", "groups", "style", "valueFormatter"];
1924
1938
  function copyColumns(columns, workbookStyles = false) {
1925
1939
  if (!Array.isArray(columns))
1926
1940
  throw new TypeError("Declare the columns in export order.");
@@ -1936,6 +1950,8 @@ function copyColumns(columns, workbookStyles = false) {
1936
1950
  throw new TypeError("Each column needs a string header and an optional string key.");
1937
1951
  if (captured.value !== undefined && typeof captured.value !== "function")
1938
1952
  throw new TypeError("Column value getters must be functions.");
1953
+ if (captured.rowHeader !== undefined && typeof captured.rowHeader !== "boolean")
1954
+ throw new TypeError("Column rowHeader must be boolean.");
1939
1955
  if (captured.groups !== undefined) {
1940
1956
  if (!Array.isArray(captured.groups))
1941
1957
  throw new TypeError("Column groups must be an array of strings.");
@@ -3220,7 +3236,8 @@ class Worksheet {
3220
3236
  });
3221
3237
  const originalCharacters = typeof value === "string" ? value.length : 0;
3222
3238
  let reservedCharacters = this.preserved || header || footer ? originalCharacters : undefined;
3223
- if (type === "string" && cleanXml(value, this.book.settings.invalidCharacterPolicy).length > 32767) {
3239
+ // Cleaning removes characters; ordinary strings cannot cross Excel's limit.
3240
+ if (type === "string" && originalCharacters > 32767 && cleanXml(value, this.book.settings.invalidCharacterPolicy).length > 32767) {
3224
3241
  const cell = col.letter + row;
3225
3242
  if (link || this.linkedCells.has(cell))
3226
3243
  throw new TypeError("A text-preservation cell cannot also have an external hyperlink.");
@@ -4440,12 +4457,15 @@ class Workbook {
4440
4457
  });
4441
4458
  }
4442
4459
  addPart(part) {
4460
+ this.assertOpen();
4461
+ const { uri, contentType, data, relationship } = part;
4462
+ const capturedRelationship = relationship && { id: relationship.id, type: relationship.type, source: relationship.source };
4443
4463
  this.assertOpen();
4444
4464
  // Reserve now so collisions and invalid names fail at the call site.
4445
- this.package.addPart(part);
4446
- if (part.relationship) {
4447
- const { source, ...rel } = part.relationship;
4448
- this.package.addRelationship(source ?? "/xl/workbook.xml", { ...rel, target: part.uri });
4465
+ this.package.addPart({ uri, contentType, data });
4466
+ if (capturedRelationship) {
4467
+ const { source, id, type } = capturedRelationship;
4468
+ this.package.addRelationship(source ?? "/xl/workbook.xml", { id, type, target: uri });
4449
4469
  }
4450
4470
  }
4451
4471
  /** Complete the archive and return counts. Does not close or dispose a caller-owned sink. */