@cj-tech-master/excelts 4.2.3-canary.20260115111903.b80904d → 4.2.3-canary.20260122073152.a9bb6b0

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 (40) hide show
  1. package/dist/browser/modules/csv/csv-core.d.ts +0 -9
  2. package/dist/browser/modules/csv/csv.browser.js +3 -3
  3. package/dist/browser/modules/excel/utils/passthrough-manager.d.ts +77 -0
  4. package/dist/browser/modules/excel/utils/passthrough-manager.js +129 -0
  5. package/dist/browser/modules/excel/workbook.d.ts +8 -0
  6. package/dist/browser/modules/excel/workbook.js +9 -1
  7. package/dist/browser/modules/excel/worksheet.d.ts +4 -0
  8. package/dist/browser/modules/excel/worksheet.js +4 -1
  9. package/dist/browser/modules/excel/xlsx/xform/core/content-types-xform.js +16 -10
  10. package/dist/browser/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.d.ts +34 -11
  11. package/dist/browser/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.js +256 -86
  12. package/dist/browser/modules/excel/xlsx/xform/sheet/worksheet-xform.js +38 -11
  13. package/dist/browser/modules/excel/xlsx/xlsx.browser.d.ts +36 -1
  14. package/dist/browser/modules/excel/xlsx/xlsx.browser.js +213 -131
  15. package/dist/cjs/modules/csv/csv.browser.js +3 -3
  16. package/dist/cjs/modules/excel/utils/passthrough-manager.js +133 -0
  17. package/dist/cjs/modules/excel/workbook.js +9 -1
  18. package/dist/cjs/modules/excel/worksheet.js +4 -1
  19. package/dist/cjs/modules/excel/xlsx/xform/core/content-types-xform.js +16 -10
  20. package/dist/cjs/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.js +256 -86
  21. package/dist/cjs/modules/excel/xlsx/xform/sheet/worksheet-xform.js +38 -11
  22. package/dist/cjs/modules/excel/xlsx/xlsx.browser.js +213 -131
  23. package/dist/esm/modules/csv/csv.browser.js +3 -3
  24. package/dist/esm/modules/excel/utils/passthrough-manager.js +129 -0
  25. package/dist/esm/modules/excel/workbook.js +9 -1
  26. package/dist/esm/modules/excel/worksheet.js +4 -1
  27. package/dist/esm/modules/excel/xlsx/xform/core/content-types-xform.js +16 -10
  28. package/dist/esm/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.js +256 -86
  29. package/dist/esm/modules/excel/xlsx/xform/sheet/worksheet-xform.js +38 -11
  30. package/dist/esm/modules/excel/xlsx/xlsx.browser.js +213 -131
  31. package/dist/iife/excelts.iife.js +512 -241
  32. package/dist/iife/excelts.iife.js.map +1 -1
  33. package/dist/iife/excelts.iife.min.js +24 -51
  34. package/dist/types/modules/csv/csv-core.d.ts +0 -9
  35. package/dist/types/modules/excel/utils/passthrough-manager.d.ts +77 -0
  36. package/dist/types/modules/excel/workbook.d.ts +8 -0
  37. package/dist/types/modules/excel/worksheet.d.ts +4 -0
  38. package/dist/types/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.d.ts +34 -11
  39. package/dist/types/modules/excel/xlsx/xlsx.browser.d.ts +36 -1
  40. package/package.json +2 -2
@@ -34,6 +34,7 @@ import { StreamingZip, ZipDeflateFile } from "../../archive/zip/stream.js";
34
34
  import { ZipParser } from "../../archive/unzip/zip-parser.js";
35
35
  import { PassThrough, concatUint8Arrays } from "../../stream/index.browser.js";
36
36
  import { commentsPath, commentsRelTargetFromWorksheetName, ctrlPropPath, drawingPath, drawingRelsPath, OOXML_REL_TARGETS, pivotTableRelTargetFromWorksheetName, pivotCacheDefinitionRelTargetFromWorkbook, getCommentsIndexFromPath, getDrawingNameFromPath, getDrawingNameFromRelsPath, getMediaFilenameFromPath, mediaPath, getPivotCacheDefinitionNameFromPath, getPivotCacheDefinitionNameFromRelsPath, getPivotCacheRecordsNameFromPath, getPivotTableNameFromPath, getPivotTableNameFromRelsPath, pivotCacheDefinitionPath, pivotCacheDefinitionRelsPath, pivotCacheDefinitionRelTargetFromPivotTable, pivotCacheRecordsPath, pivotCacheRecordsRelTarget, pivotTablePath, pivotTableRelsPath, getTableNameFromPath, tablePath, tableRelTargetFromWorksheetName, themePath, getThemeNameFromPath, getVmlDrawingNameFromPath, getWorksheetNoFromWorksheetPath, getWorksheetNoFromWorksheetRelsPath, isBinaryEntryPath, normalizeZipPath, OOXML_PATHS, vmlDrawingRelTargetFromWorksheetName, vmlDrawingPath, worksheetPath, worksheetRelsPath } from "../utils/ooxml-paths.js";
37
+ import { PassthroughManager } from "../utils/passthrough-manager.js";
37
38
  class StreamingZipWriterAdapter {
38
39
  constructor(options) {
39
40
  this.events = new Map();
@@ -201,6 +202,7 @@ class XLSX {
201
202
  this.addDrawings(zip, model);
202
203
  this.addTables(zip, model);
203
204
  this.addPivotTables(zip, model);
205
+ this.addPassthrough(zip, model);
204
206
  await Promise.all([this.addThemes(zip, model), this.addStyles(zip, model)]);
205
207
  await this.addFeaturePropertyBag(zip, model);
206
208
  await this.addMedia(zip, model);
@@ -300,8 +302,12 @@ class XLSX {
300
302
  * This is the foundation for TRUE streaming reads on platforms that have a
301
303
  * streaming ZIP parser (e.g. Node.js `modules/archive` Parse).
302
304
  */
303
- async loadFromZipEntries(entries, options) {
304
- const model = {
305
+ /**
306
+ * Create an empty model for parsing XLSX files.
307
+ * Shared by loadFromZipEntries and loadFromFiles.
308
+ */
309
+ createEmptyModel() {
310
+ return {
305
311
  worksheets: [],
306
312
  worksheetHash: {},
307
313
  worksheetRels: [],
@@ -310,6 +316,8 @@ class XLSX {
310
316
  mediaIndex: {},
311
317
  drawings: {},
312
318
  drawingRels: {},
319
+ // Raw drawing XML data for passthrough (when drawing contains chart references)
320
+ rawDrawings: {},
313
321
  comments: {},
314
322
  tables: {},
315
323
  vmlDrawings: {},
@@ -317,8 +325,104 @@ class XLSX {
317
325
  pivotTableRels: {},
318
326
  pivotCacheDefinitions: {},
319
327
  pivotCacheDefinitionRels: {},
320
- pivotCacheRecords: {}
328
+ pivotCacheRecords: {},
329
+ // Passthrough storage for unknown/unsupported files (charts, etc.)
330
+ passthrough: {}
321
331
  };
332
+ }
333
+ /**
334
+ * Collect all data from a stream into a single Uint8Array.
335
+ * Reusable helper for passthrough and drawing processing.
336
+ */
337
+ async collectStreamData(stream) {
338
+ const chunks = [];
339
+ await new Promise((resolve, reject) => {
340
+ stream.on("data", (chunk) => {
341
+ if (typeof chunk === "string") {
342
+ chunks.push(new TextEncoder().encode(chunk));
343
+ }
344
+ else if (chunk instanceof Uint8Array) {
345
+ chunks.push(chunk);
346
+ }
347
+ else {
348
+ chunks.push(new Uint8Array(chunk));
349
+ }
350
+ });
351
+ stream.on("end", () => resolve());
352
+ stream.on("error", reject);
353
+ });
354
+ return concatUint8Arrays(chunks);
355
+ }
356
+ /**
357
+ * Check if a drawing has chart references in its relationships
358
+ */
359
+ drawingHasChartReference(drawing) {
360
+ return (drawing.rels && drawing.rels.some((rel) => rel.Target && rel.Target.includes("/charts/")));
361
+ }
362
+ /**
363
+ * Check if a drawing rels list references charts.
364
+ * Used to decide whether we need to keep raw drawing XML for passthrough.
365
+ */
366
+ drawingRelsHasChartReference(drawingRels) {
367
+ return (Array.isArray(drawingRels) &&
368
+ drawingRels.some(rel => typeof rel?.Target === "string" && rel.Target.includes("/charts/")));
369
+ }
370
+ /**
371
+ * Process a known OOXML entry (workbook, styles, shared strings, etc.)
372
+ * Returns true if handled, false if should be passed to _processDefaultEntry
373
+ */
374
+ async _processKnownEntry(stream, model, entryName, options) {
375
+ const sheetNo = getWorksheetNoFromWorksheetPath(entryName);
376
+ if (sheetNo !== undefined) {
377
+ await this._processWorksheetEntry(stream, model, sheetNo, options, entryName);
378
+ return true;
379
+ }
380
+ switch (entryName) {
381
+ case OOXML_PATHS.rootRels:
382
+ model.globalRels = await this.parseRels(stream);
383
+ return true;
384
+ case OOXML_PATHS.xlWorkbook: {
385
+ const workbook = await this.parseWorkbook(stream);
386
+ model.sheets = workbook.sheets;
387
+ model.definedNames = workbook.definedNames;
388
+ model.views = workbook.views;
389
+ model.properties = workbook.properties;
390
+ model.calcProperties = workbook.calcProperties;
391
+ model.pivotCaches = workbook.pivotCaches;
392
+ return true;
393
+ }
394
+ case OOXML_PATHS.xlSharedStrings:
395
+ model.sharedStrings = new SharedStringsXform();
396
+ await model.sharedStrings.parseStream(stream);
397
+ return true;
398
+ case OOXML_PATHS.xlWorkbookRels:
399
+ model.workbookRels = await this.parseRels(stream);
400
+ return true;
401
+ case OOXML_PATHS.docPropsApp: {
402
+ const appXform = new AppXform();
403
+ const appProperties = await appXform.parseStream(stream);
404
+ if (appProperties) {
405
+ model.company = appProperties.company;
406
+ model.manager = appProperties.manager;
407
+ }
408
+ return true;
409
+ }
410
+ case OOXML_PATHS.docPropsCore: {
411
+ const coreXform = new CoreXform();
412
+ const coreProperties = await coreXform.parseStream(stream);
413
+ Object.assign(model, coreProperties);
414
+ return true;
415
+ }
416
+ case OOXML_PATHS.xlStyles:
417
+ model.styles = new StylesXform();
418
+ await model.styles.parseStream(stream);
419
+ return true;
420
+ default:
421
+ return false;
422
+ }
423
+ }
424
+ async loadFromZipEntries(entries, options) {
425
+ const model = this.createEmptyModel();
322
426
  for await (const entry of entries) {
323
427
  let drained = false;
324
428
  const drainEntry = async () => {
@@ -335,58 +439,12 @@ class XLSX {
335
439
  const entryName = normalizeZipPath(entry.name);
336
440
  const stream = entry.stream;
337
441
  try {
338
- const sheetNo = getWorksheetNoFromWorksheetPath(entryName);
339
- if (sheetNo !== undefined) {
340
- await this._processWorksheetEntry(stream, model, sheetNo, options, entryName);
341
- continue;
342
- }
343
- switch (entryName) {
344
- case OOXML_PATHS.rootRels:
345
- model.globalRels = await this.parseRels(stream);
346
- break;
347
- case OOXML_PATHS.xlWorkbook: {
348
- const workbook = await this.parseWorkbook(stream);
349
- model.sheets = workbook.sheets;
350
- model.definedNames = workbook.definedNames;
351
- model.views = workbook.views;
352
- model.properties = workbook.properties;
353
- model.calcProperties = workbook.calcProperties;
354
- model.pivotCaches = workbook.pivotCaches;
355
- break;
356
- }
357
- case OOXML_PATHS.xlSharedStrings:
358
- model.sharedStrings = new SharedStringsXform();
359
- await model.sharedStrings.parseStream(stream);
360
- break;
361
- case OOXML_PATHS.xlWorkbookRels:
362
- model.workbookRels = await this.parseRels(stream);
363
- break;
364
- case OOXML_PATHS.docPropsApp: {
365
- const appXform = new AppXform();
366
- const appProperties = await appXform.parseStream(stream);
367
- if (appProperties) {
368
- model.company = appProperties.company;
369
- model.manager = appProperties.manager;
370
- }
371
- break;
372
- }
373
- case OOXML_PATHS.docPropsCore: {
374
- const coreXform = new CoreXform();
375
- const coreProperties = await coreXform.parseStream(stream);
376
- Object.assign(model, coreProperties);
377
- break;
378
- }
379
- case OOXML_PATHS.xlStyles:
380
- model.styles = new StylesXform();
381
- await model.styles.parseStream(stream);
382
- break;
383
- default: {
384
- const handled = await this._processDefaultEntry(stream, model, entryName);
385
- if (!handled) {
386
- // Important for true streaming parsers: always consume unknown entries
387
- await drainEntry();
388
- }
389
- break;
442
+ const handled = await this._processKnownEntry(stream, model, entryName, options);
443
+ if (!handled) {
444
+ const defaultHandled = await this._processDefaultEntry(stream, model, entryName);
445
+ if (!defaultHandled) {
446
+ // Important for true streaming parsers: always consume unknown entries
447
+ await drainEntry();
390
448
  }
391
449
  }
392
450
  }
@@ -500,6 +558,15 @@ class XLSX {
500
558
  drawingXform.reconcile(drawing, drawingOptions);
501
559
  }
502
560
  });
561
+ // Trim raw drawings for non-chart drawings to avoid bloating the serialized workbook model.
562
+ if (model.rawDrawings && model.drawingRels) {
563
+ for (const name of Object.keys(model.rawDrawings)) {
564
+ const drawingRel = model.drawingRels[name];
565
+ if (drawingRel && !this.drawingRelsHasChartReference(drawingRel)) {
566
+ delete model.rawDrawings[name];
567
+ }
568
+ }
569
+ }
503
570
  // reconcile tables with the default styles
504
571
  const tableOptions = {
505
572
  styles: model.styles
@@ -516,6 +583,7 @@ class XLSX {
516
583
  mediaIndex: model.mediaIndex,
517
584
  date1904: model.properties && model.properties.date1904,
518
585
  drawings: model.drawings,
586
+ drawingRels: model.drawingRels,
519
587
  comments: model.comments,
520
588
  tables: model.tables,
521
589
  vmlDrawings: model.vmlDrawings,
@@ -692,9 +760,15 @@ class XLSX {
692
760
  }
693
761
  }
694
762
  async _processDrawingEntry(entry, model, name) {
763
+ // Collect raw data first so we can preserve drawings that reference charts.
764
+ const rawData = await this.collectStreamData(entry);
765
+ // Parse the drawing for normal processing (images, etc.)
695
766
  const xform = new DrawingXform();
696
- const drawing = await xform.parseStream(entry);
767
+ const xmlString = this.bufferToString(rawData);
768
+ const drawing = await xform.parseStream(this.createTextStream(xmlString));
697
769
  model.drawings[name] = drawing;
770
+ // Store raw data; reconcile() may later drop it if charts are not referenced.
771
+ model.rawDrawings[name] = rawData;
698
772
  }
699
773
  async _processDrawingRelsEntry(entry, model, name) {
700
774
  const xform = new RelationshipsXform();
@@ -769,24 +843,7 @@ class XLSX {
769
843
  // loadFromFiles - shared logic for loading from pre-extracted ZIP data
770
844
  // ===========================================================================
771
845
  async loadFromFiles(zipData, options) {
772
- const model = {
773
- worksheets: [],
774
- worksheetHash: {},
775
- worksheetRels: [],
776
- themes: {},
777
- media: [],
778
- mediaIndex: {},
779
- drawings: {},
780
- drawingRels: {},
781
- comments: {},
782
- tables: {},
783
- vmlDrawings: {},
784
- pivotTables: {},
785
- pivotTableRels: {},
786
- pivotCacheDefinitions: {},
787
- pivotCacheDefinitionRels: {},
788
- pivotCacheRecords: {}
789
- };
846
+ const model = this.createEmptyModel();
790
847
  const entries = Object.keys(zipData).map(name => ({
791
848
  name,
792
849
  dir: name.endsWith("/"),
@@ -800,54 +857,10 @@ class XLSX {
800
857
  const stream = isBinaryEntry
801
858
  ? this.createBinaryStream(entry.data)
802
859
  : this.createTextStream(this.bufferToString(entry.data));
803
- const sheetNo = getWorksheetNoFromWorksheetPath(entryName);
804
- if (sheetNo !== undefined) {
805
- await this._processWorksheetEntry(stream, model, sheetNo, options, entryName);
806
- }
807
- else {
808
- switch (entryName) {
809
- case OOXML_PATHS.rootRels:
810
- model.globalRels = await this.parseRels(stream);
811
- break;
812
- case OOXML_PATHS.xlWorkbook: {
813
- const workbook = await this.parseWorkbook(stream);
814
- model.sheets = workbook.sheets;
815
- model.definedNames = workbook.definedNames;
816
- model.views = workbook.views;
817
- model.properties = workbook.properties;
818
- model.calcProperties = workbook.calcProperties;
819
- model.pivotCaches = workbook.pivotCaches;
820
- break;
821
- }
822
- case OOXML_PATHS.xlSharedStrings:
823
- model.sharedStrings = new SharedStringsXform();
824
- await model.sharedStrings.parseStream(stream);
825
- break;
826
- case OOXML_PATHS.xlWorkbookRels:
827
- model.workbookRels = await this.parseRels(stream);
828
- break;
829
- case OOXML_PATHS.docPropsApp: {
830
- const appXform = new AppXform();
831
- const appProperties = await appXform.parseStream(stream);
832
- if (appProperties) {
833
- model.company = appProperties.company;
834
- model.manager = appProperties.manager;
835
- }
836
- break;
837
- }
838
- case OOXML_PATHS.docPropsCore: {
839
- const coreXform = new CoreXform();
840
- const coreProperties = await coreXform.parseStream(stream);
841
- Object.assign(model, coreProperties);
842
- break;
843
- }
844
- case OOXML_PATHS.xlStyles:
845
- model.styles = new StylesXform();
846
- await model.styles.parseStream(stream);
847
- break;
848
- default:
849
- await this._processDefaultEntry(stream, model, entryName);
850
- }
860
+ const handled = await this._processKnownEntry(stream, model, entryName, options);
861
+ if (!handled) {
862
+ // Pass raw entry data for drawings to enable passthrough
863
+ await this._processDefaultEntry(stream, model, entryName, entry.data);
851
864
  }
852
865
  }
853
866
  }
@@ -857,11 +870,11 @@ class XLSX {
857
870
  }
858
871
  /**
859
872
  * Process default entries (drawings, comments, tables, etc.)
873
+ * @param rawData Optional raw entry data for passthrough preservation (used by loadFromFiles)
860
874
  */
861
- async _processDefaultEntry(stream, model, entryName) {
862
- const worksheetRelsSheetNo = getWorksheetNoFromWorksheetRelsPath(entryName);
863
- if (worksheetRelsSheetNo !== undefined) {
864
- const sheetNo = worksheetRelsSheetNo;
875
+ async _processDefaultEntry(stream, model, entryName, rawData) {
876
+ const sheetNo = getWorksheetNoFromWorksheetRelsPath(entryName);
877
+ if (sheetNo !== undefined) {
865
878
  await this._processWorksheetRelsEntry(stream, model, sheetNo);
866
879
  return true;
867
880
  }
@@ -873,6 +886,10 @@ class XLSX {
873
886
  const drawingName = getDrawingNameFromPath(entryName);
874
887
  if (drawingName) {
875
888
  await this._processDrawingEntry(stream, model, drawingName);
889
+ // For loadFromFiles path, store raw data for passthrough (drawings with charts)
890
+ if (rawData) {
891
+ model.rawDrawings[drawingName] = rawData;
892
+ }
876
893
  return true;
877
894
  }
878
895
  const drawingRelsName = getDrawingNameFromRelsPath(entryName);
@@ -927,8 +944,27 @@ class XLSX {
927
944
  await this._processPivotCacheRecordsEntry(stream, model, pivotCacheRecordsName);
928
945
  return true;
929
946
  }
947
+ // Store passthrough files (charts, etc.) for preservation
948
+ if (PassthroughManager.isPassthroughPath(entryName)) {
949
+ // If raw data is available (loadFromFiles path), use it directly
950
+ if (rawData) {
951
+ model.passthrough[entryName] = rawData;
952
+ }
953
+ else {
954
+ await this._processPassthroughEntry(stream, model, entryName);
955
+ }
956
+ return true;
957
+ }
930
958
  return false;
931
959
  }
960
+ /**
961
+ * Store a passthrough file for preservation during read/write cycles.
962
+ * These files are not parsed but stored as raw bytes to be written back unchanged.
963
+ */
964
+ async _processPassthroughEntry(stream, model, entryName) {
965
+ const data = await this.collectStreamData(stream);
966
+ model.passthrough[entryName] = data;
967
+ }
932
968
  // ===========================================================================
933
969
  // Write methods - shared by all platforms
934
970
  // ===========================================================================
@@ -1071,14 +1107,46 @@ class XLSX {
1071
1107
  addDrawings(zip, model) {
1072
1108
  const drawingXform = new DrawingXform();
1073
1109
  const relsXform = new RelationshipsXform();
1110
+ const rawDrawings = model.rawDrawings || {};
1074
1111
  model.worksheets.forEach((worksheet) => {
1075
1112
  const { drawing } = worksheet;
1076
1113
  if (drawing) {
1077
- drawingXform.prepare(drawing);
1078
- let xml = drawingXform.toXml(drawing);
1079
- zip.append(xml, { name: drawingPath(drawing.name) });
1080
- xml = relsXform.toXml(drawing.rels);
1081
- zip.append(xml, { name: drawingRelsPath(drawing.name) });
1114
+ // Check if drawing rels contain chart references using helper
1115
+ const hasChartReference = this.drawingHasChartReference(drawing);
1116
+ if (hasChartReference && rawDrawings[drawing.name]) {
1117
+ // Use raw data for drawings with chart references (passthrough)
1118
+ zip.append(rawDrawings[drawing.name], { name: drawingPath(drawing.name) });
1119
+ }
1120
+ else {
1121
+ // Use regenerated XML for normal drawings (images, shapes)
1122
+ // Filter out invalid anchors (null, undefined, or missing content)
1123
+ const filteredAnchors = (drawing.anchors || []).filter((a) => {
1124
+ if (a == null) {
1125
+ return false;
1126
+ }
1127
+ // Form controls have range.br and shape properties
1128
+ if (a.range?.br && a.shape) {
1129
+ return true;
1130
+ }
1131
+ // One-cell anchors need a valid picture
1132
+ if (!a.br && !a.picture) {
1133
+ return false;
1134
+ }
1135
+ // Two-cell anchors need either picture or shape
1136
+ if (a.br && !a.picture && !a.shape) {
1137
+ return false;
1138
+ }
1139
+ return true;
1140
+ });
1141
+ const drawingForWrite = drawing.anchors
1142
+ ? { ...drawing, anchors: filteredAnchors }
1143
+ : drawing;
1144
+ drawingXform.prepare(drawingForWrite);
1145
+ const xml = drawingXform.toXml(drawingForWrite);
1146
+ zip.append(xml, { name: drawingPath(drawing.name) });
1147
+ }
1148
+ const relsXml = relsXform.toXml(drawing.rels);
1149
+ zip.append(relsXml, { name: drawingRelsPath(drawing.name) });
1082
1150
  }
1083
1151
  });
1084
1152
  }
@@ -1093,6 +1161,15 @@ class XLSX {
1093
1161
  });
1094
1162
  });
1095
1163
  }
1164
+ /**
1165
+ * Write passthrough files (charts, etc.) that were preserved during read.
1166
+ * These files are written back unchanged to preserve unsupported features.
1167
+ */
1168
+ addPassthrough(zip, model) {
1169
+ const passthroughManager = new PassthroughManager();
1170
+ passthroughManager.fromRecord(model.passthrough || {});
1171
+ passthroughManager.writeToZip(zip);
1172
+ }
1096
1173
  addPivotTables(zip, model) {
1097
1174
  if (!model.pivotTables.length) {
1098
1175
  return;
@@ -1185,6 +1262,11 @@ class XLSX {
1185
1262
  });
1186
1263
  // ContentTypesXform expects this flag
1187
1264
  model.hasCheckboxes = model.styles.hasCheckboxes;
1265
+ // Build passthroughContentTypes for ContentTypesXform using PassthroughManager
1266
+ const passthrough = model.passthrough || {};
1267
+ const passthroughManager = new PassthroughManager();
1268
+ passthroughManager.fromRecord(passthrough);
1269
+ model.passthroughContentTypes = passthroughManager.getContentTypes();
1188
1270
  }
1189
1271
  }
1190
1272
  XLSX.RelType = RelType;
@@ -119,7 +119,7 @@ class CSV {
119
119
  const dateFormats = options?.dateFormats ?? DEFAULT_DATE_FORMATS;
120
120
  const map = options?.map ||
121
121
  createDefaultValueMapper(dateFormats, {
122
- decimalSeparator: options?.valueMapperOptions?.decimalSeparator ?? options?.parserOptions?.decimalSeparator
122
+ decimalSeparator: options?.valueMapperOptions?.decimalSeparator
123
123
  });
124
124
  const rows = (0, csv_core_1.parseCsv)(str, options?.parserOptions);
125
125
  for (const row of rows) {
@@ -161,7 +161,7 @@ class CSV {
161
161
  const dateFormats = options?.dateFormats ?? DEFAULT_DATE_FORMATS;
162
162
  const map = options?.map ||
163
163
  createDefaultValueMapper(dateFormats, {
164
- decimalSeparator: options?.valueMapperOptions?.decimalSeparator ?? options?.parserOptions?.decimalSeparator
164
+ decimalSeparator: options?.valueMapperOptions?.decimalSeparator
165
165
  });
166
166
  const parser = new csv_stream_1.CsvParserStream(options?.parserOptions);
167
167
  return new Promise((resolve, reject) => {
@@ -231,7 +231,7 @@ class CSV {
231
231
  const dateFormats = options?.dateFormats ?? DEFAULT_DATE_FORMATS;
232
232
  const map = options?.map ||
233
233
  createDefaultValueMapper(dateFormats, {
234
- decimalSeparator: options?.valueMapperOptions?.decimalSeparator ?? options?.parserOptions?.decimalSeparator
234
+ decimalSeparator: options?.valueMapperOptions?.decimalSeparator
235
235
  });
236
236
  const parser = new csv_stream_1.CsvParserStream(options?.parserOptions);
237
237
  parser.on("data", (row) => worksheet.addRow(row.map(map)));
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ /**
3
+ * PassthroughManager - Manages passthrough files for round-trip preservation
4
+ *
5
+ * This module handles files that are not fully parsed by the library but need to be
6
+ * preserved during read/write cycles (e.g., charts, sparklines, slicers).
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.PassthroughManager = void 0;
10
+ // Pre-compiled regex patterns for content type detection (performance optimization)
11
+ const chartXmlRegex = /^xl\/charts\/chart\d+\.xml$/;
12
+ const chartStyleXmlRegex = /^xl\/charts\/style\d+\.xml$/;
13
+ const chartColorsXmlRegex = /^xl\/charts\/colors\d+\.xml$/;
14
+ /**
15
+ * Content type definitions for passthrough files
16
+ */
17
+ const PASSTHROUGH_CONTENT_TYPES = new Map([
18
+ [chartXmlRegex, "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"],
19
+ [chartStyleXmlRegex, "application/vnd.ms-office.chartstyle+xml"],
20
+ [chartColorsXmlRegex, "application/vnd.ms-office.chartcolorstyle+xml"]
21
+ ]);
22
+ /**
23
+ * Passthrough path prefixes that should be preserved
24
+ */
25
+ const PASSTHROUGH_PREFIXES = ["xl/charts/"];
26
+ /**
27
+ * PassthroughManager handles storage and retrieval of passthrough files
28
+ * that need to be preserved during Excel read/write cycles.
29
+ */
30
+ class PassthroughManager {
31
+ constructor() {
32
+ this.files = new Map();
33
+ }
34
+ /**
35
+ * Check if a path should be treated as passthrough
36
+ */
37
+ static isPassthroughPath(path) {
38
+ return PASSTHROUGH_PREFIXES.some(prefix => path.startsWith(prefix));
39
+ }
40
+ /**
41
+ * Get the content type for a passthrough file path
42
+ * @returns Content type string or undefined if unknown
43
+ */
44
+ static getContentType(path) {
45
+ // Chart relationships are handled by Default extension="rels"
46
+ if (path.startsWith("xl/charts/_rels/")) {
47
+ return undefined;
48
+ }
49
+ for (const [regex, contentType] of PASSTHROUGH_CONTENT_TYPES) {
50
+ if (regex.test(path)) {
51
+ return contentType;
52
+ }
53
+ }
54
+ return undefined;
55
+ }
56
+ /**
57
+ * Add a file to passthrough storage
58
+ */
59
+ add(path, data) {
60
+ this.files.set(path, data);
61
+ }
62
+ /**
63
+ * Get a file from passthrough storage
64
+ */
65
+ get(path) {
66
+ return this.files.get(path);
67
+ }
68
+ /**
69
+ * Check if a file exists in passthrough storage
70
+ */
71
+ has(path) {
72
+ return this.files.has(path);
73
+ }
74
+ /**
75
+ * Get all stored paths
76
+ */
77
+ getPaths() {
78
+ return [...this.files.keys()];
79
+ }
80
+ /**
81
+ * Get all files as a record (for serialization)
82
+ */
83
+ toRecord() {
84
+ const record = {};
85
+ for (const [path, data] of this.files) {
86
+ record[path] = data;
87
+ }
88
+ return record;
89
+ }
90
+ /**
91
+ * Load files from a record (for deserialization)
92
+ */
93
+ fromRecord(record) {
94
+ this.files.clear();
95
+ for (const [path, data] of Object.entries(record)) {
96
+ this.files.set(path, data);
97
+ }
98
+ }
99
+ /**
100
+ * Get content types for all stored files that have known types
101
+ */
102
+ getContentTypes() {
103
+ const contentTypes = [];
104
+ for (const path of this.files.keys()) {
105
+ const contentType = PassthroughManager.getContentType(path);
106
+ if (contentType) {
107
+ contentTypes.push({ partName: path, contentType });
108
+ }
109
+ }
110
+ return contentTypes;
111
+ }
112
+ /**
113
+ * Write all passthrough files to a ZIP writer
114
+ */
115
+ writeToZip(zip) {
116
+ for (const [path, data] of this.files) {
117
+ zip.append(data, { name: path });
118
+ }
119
+ }
120
+ /**
121
+ * Clear all stored files
122
+ */
123
+ clear() {
124
+ this.files.clear();
125
+ }
126
+ /**
127
+ * Get the number of stored files
128
+ */
129
+ get size() {
130
+ return this.files.size;
131
+ }
132
+ }
133
+ exports.PassthroughManager = PassthroughManager;
@@ -41,6 +41,8 @@ class Workbook {
41
41
  this.views = [];
42
42
  this.media = [];
43
43
  this.pivotTables = [];
44
+ this._passthrough = {};
45
+ this._rawDrawings = {};
44
46
  this._definedNames = new defined_names_1.DefinedNames();
45
47
  }
46
48
  // ===========================================================================
@@ -254,7 +256,9 @@ class Workbook {
254
256
  themes: this._themes,
255
257
  media: this.media,
256
258
  pivotTables: this.pivotTables,
257
- calcProperties: this.calcProperties
259
+ calcProperties: this.calcProperties,
260
+ passthrough: this._passthrough,
261
+ rawDrawings: this._rawDrawings
258
262
  };
259
263
  }
260
264
  set model(value) {
@@ -295,6 +299,10 @@ class Workbook {
295
299
  // Handle pivot tables - either newly created or loaded from file
296
300
  // Loaded pivot tables come from loadedPivotTables after reconciliation
297
301
  this.pivotTables = value.pivotTables || value.loadedPivotTables || [];
302
+ // Preserve passthrough files (charts, etc.) for round-trip preservation
303
+ this._passthrough = value.passthrough || {};
304
+ // Preserve raw drawing data for drawings with chart references
305
+ this._rawDrawings = value.rawDrawings || {};
298
306
  }
299
307
  }
300
308
  exports.Workbook = Workbook;
@@ -900,7 +900,8 @@ class Worksheet {
900
900
  tables: Object.values(this.tables).map(table => table.model),
901
901
  pivotTables: this.pivotTables,
902
902
  conditionalFormattings: this.conditionalFormattings,
903
- formControls: this.formControls.map(fc => fc.model)
903
+ formControls: this.formControls.map(fc => fc.model),
904
+ drawing: this._drawing
904
905
  };
905
906
  // =================================================
906
907
  // columns
@@ -968,6 +969,8 @@ class Worksheet {
968
969
  this.conditionalFormattings = value.conditionalFormattings;
969
970
  // Form controls are currently write-only (not parsed from XLSX)
970
971
  this.formControls = [];
972
+ // Preserve loaded drawing data (charts, etc.)
973
+ this._drawing = value.drawing;
971
974
  }
972
975
  }
973
976
  exports.Worksheet = Worksheet;