@cj-tech-master/excelts 4.2.3-canary.20260115111903.b80904d → 4.2.3-canary.20260122075539.cc11b20

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 (48) 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/parse-sax.d.ts +0 -3
  4. package/dist/browser/modules/excel/utils/parse-sax.js +13 -32
  5. package/dist/browser/modules/excel/utils/passthrough-manager.d.ts +77 -0
  6. package/dist/browser/modules/excel/utils/passthrough-manager.js +129 -0
  7. package/dist/browser/modules/excel/workbook.d.ts +8 -0
  8. package/dist/browser/modules/excel/workbook.js +9 -1
  9. package/dist/browser/modules/excel/worksheet.d.ts +4 -0
  10. package/dist/browser/modules/excel/worksheet.js +4 -1
  11. package/dist/browser/modules/excel/xlsx/xform/base-xform.js +68 -1
  12. package/dist/browser/modules/excel/xlsx/xform/core/content-types-xform.js +16 -10
  13. package/dist/browser/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.d.ts +34 -11
  14. package/dist/browser/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.js +256 -86
  15. package/dist/browser/modules/excel/xlsx/xform/sheet/worksheet-xform.js +38 -11
  16. package/dist/browser/modules/excel/xlsx/xlsx.browser.d.ts +36 -1
  17. package/dist/browser/modules/excel/xlsx/xlsx.browser.js +213 -131
  18. package/dist/cjs/modules/csv/csv.browser.js +3 -3
  19. package/dist/cjs/modules/excel/utils/parse-sax.js +13 -32
  20. package/dist/cjs/modules/excel/utils/passthrough-manager.js +133 -0
  21. package/dist/cjs/modules/excel/workbook.js +9 -1
  22. package/dist/cjs/modules/excel/worksheet.js +4 -1
  23. package/dist/cjs/modules/excel/xlsx/xform/base-xform.js +68 -1
  24. package/dist/cjs/modules/excel/xlsx/xform/core/content-types-xform.js +16 -10
  25. package/dist/cjs/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.js +256 -86
  26. package/dist/cjs/modules/excel/xlsx/xform/sheet/worksheet-xform.js +38 -11
  27. package/dist/cjs/modules/excel/xlsx/xlsx.browser.js +213 -131
  28. package/dist/esm/modules/csv/csv.browser.js +3 -3
  29. package/dist/esm/modules/excel/utils/parse-sax.js +13 -32
  30. package/dist/esm/modules/excel/utils/passthrough-manager.js +129 -0
  31. package/dist/esm/modules/excel/workbook.js +9 -1
  32. package/dist/esm/modules/excel/worksheet.js +4 -1
  33. package/dist/esm/modules/excel/xlsx/xform/base-xform.js +68 -1
  34. package/dist/esm/modules/excel/xlsx/xform/core/content-types-xform.js +16 -10
  35. package/dist/esm/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.js +256 -86
  36. package/dist/esm/modules/excel/xlsx/xform/sheet/worksheet-xform.js +38 -11
  37. package/dist/esm/modules/excel/xlsx/xlsx.browser.js +213 -131
  38. package/dist/iife/excelts.iife.js +571 -267
  39. package/dist/iife/excelts.iife.js.map +1 -1
  40. package/dist/iife/excelts.iife.min.js +25 -52
  41. package/dist/types/modules/csv/csv-core.d.ts +0 -9
  42. package/dist/types/modules/excel/utils/parse-sax.d.ts +0 -3
  43. package/dist/types/modules/excel/utils/passthrough-manager.d.ts +77 -0
  44. package/dist/types/modules/excel/workbook.d.ts +8 -0
  45. package/dist/types/modules/excel/worksheet.d.ts +4 -0
  46. package/dist/types/modules/excel/xlsx/xform/pivot-table/pivot-table-xform.d.ts +34 -11
  47. package/dist/types/modules/excel/xlsx/xlsx.browser.d.ts +36 -1
  48. package/package.json +2 -2
@@ -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;
@@ -3,6 +3,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseXform = void 0;
4
4
  const parse_sax_1 = require("../../utils/parse-sax.js");
5
5
  const xml_stream_1 = require("../../utils/xml-stream.js");
6
+ // HAN CELL namespace prefix normalization
7
+ // HAN CELL uses non-standard namespace prefixes (ep:, cp:, dc:, etc.)
8
+ // See: https://github.com/exceljs/exceljs/issues/3014
9
+ const HAN_CELL_PREFIXES = new Set(["ep", "cp", "dc", "dcterms", "dcmitype", "vt"]);
10
+ const SPREADSHEETML_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
11
+ // Detect HAN CELL mode from first tag. Returns:
12
+ // - undefined: normal file (no prefix handling needed)
13
+ // - null: HAN CELL file without spreadsheetml prefix (uses static prefixes only)
14
+ // - string: HAN CELL file with spreadsheetml prefix (e.g., "x")
15
+ function detectHanCellPrefix(tagName, attrs) {
16
+ for (const key in attrs) {
17
+ if (key.length > 6 && key.startsWith("xmlns:")) {
18
+ const prefix = key.slice(6);
19
+ // Check for spreadsheetml namespace prefix
20
+ if (attrs[key] === SPREADSHEETML_NS) {
21
+ return prefix;
22
+ }
23
+ // Check if xmlns declares a known HAN CELL prefix (e.g., xmlns:dc, xmlns:dcterms)
24
+ if (HAN_CELL_PREFIXES.has(prefix)) {
25
+ return null;
26
+ }
27
+ }
28
+ }
29
+ // Check if tag name has a known static prefix
30
+ const i = tagName.indexOf(":");
31
+ return i !== -1 && HAN_CELL_PREFIXES.has(tagName.slice(0, i)) ? null : undefined;
32
+ }
33
+ // Strip known namespace prefix from element name
34
+ function stripPrefix(name, nsPrefix) {
35
+ const i = name.indexOf(":");
36
+ if (i === -1) {
37
+ return name;
38
+ }
39
+ const p = name.slice(0, i);
40
+ return p === nsPrefix || HAN_CELL_PREFIXES.has(p) ? name.slice(i + 1) : name;
41
+ }
6
42
  // Base class for Xforms
7
43
  class BaseXform {
8
44
  // ============================================================
@@ -54,19 +90,50 @@ class BaseXform {
54
90
  // destroys the underlying stream and can surface as AbortError (ABORT_ERR).
55
91
  let done = false;
56
92
  let finalModel;
93
+ // HAN CELL compatibility: 0 = not checked, 1 = normal file, 2 = HAN CELL file
94
+ let nsMode = 0;
95
+ let nsPrefix = null;
57
96
  for await (const events of saxParser) {
58
97
  if (done) {
59
98
  continue;
60
99
  }
61
100
  for (const { eventType, value } of events) {
62
101
  if (eventType === "opentag") {
102
+ // Fast path for normal Excel files (majority case)
103
+ if (nsMode === 1) {
104
+ this.parseOpen(value);
105
+ continue;
106
+ }
107
+ // First tag - detect mode
108
+ if (nsMode === 0) {
109
+ const prefix = detectHanCellPrefix(value.name, value.attributes);
110
+ if (prefix === undefined) {
111
+ nsMode = 1;
112
+ this.parseOpen(value);
113
+ continue;
114
+ }
115
+ nsMode = 2;
116
+ nsPrefix = prefix;
117
+ }
118
+ // HAN CELL mode - strip prefix
119
+ value.name = stripPrefix(value.name, nsPrefix);
63
120
  this.parseOpen(value);
64
121
  }
65
122
  else if (eventType === "text") {
66
123
  this.parseText(value);
67
124
  }
68
125
  else if (eventType === "closetag") {
69
- if (!this.parseClose(value.name)) {
126
+ // Fast path for normal files
127
+ if (nsMode === 1) {
128
+ if (!this.parseClose(value.name)) {
129
+ done = true;
130
+ finalModel = this.model;
131
+ break;
132
+ }
133
+ continue;
134
+ }
135
+ // HAN CELL mode - strip prefix
136
+ if (!this.parseClose(stripPrefix(value.name, nsPrefix))) {
70
137
  done = true;
71
138
  finalModel = this.model;
72
139
  break;
@@ -96,11 +96,16 @@ class ContentTypesXform extends base_xform_1.BaseXform {
96
96
  });
97
97
  });
98
98
  }
99
- if (model.commentRefs) {
99
+ // VML extension is needed for comments or form controls
100
+ const hasComments = model.commentRefs && model.commentRefs.length > 0;
101
+ const hasFormControls = model.formControlRefs && model.formControlRefs.length > 0;
102
+ if (hasComments || hasFormControls) {
100
103
  xmlStream.leafNode("Default", {
101
104
  Extension: "vml",
102
105
  ContentType: "application/vnd.openxmlformats-officedocument.vmlDrawing"
103
106
  });
107
+ }
108
+ if (hasComments) {
104
109
  model.commentRefs.forEach(({ commentName }) => {
105
110
  xmlStream.leafNode("Override", {
106
111
  PartName: (0, ooxml_paths_1.toContentTypesPartName)((0, ooxml_paths_1.commentsPathFromName)(commentName)),
@@ -108,15 +113,7 @@ class ContentTypesXform extends base_xform_1.BaseXform {
108
113
  });
109
114
  });
110
115
  }
111
- // Add form control (ctrlProps) content types
112
- if (model.formControlRefs) {
113
- // Ensure vml extension is declared (may already be declared for comments)
114
- if (!model.commentRefs) {
115
- xmlStream.leafNode("Default", {
116
- Extension: "vml",
117
- ContentType: "application/vnd.openxmlformats-officedocument.vmlDrawing"
118
- });
119
- }
116
+ if (hasFormControls) {
120
117
  for (const ctrlPropId of model.formControlRefs) {
121
118
  xmlStream.leafNode("Override", {
122
119
  PartName: (0, ooxml_paths_1.toContentTypesPartName)((0, ooxml_paths_1.ctrlPropPath)(ctrlPropId)),
@@ -124,6 +121,15 @@ class ContentTypesXform extends base_xform_1.BaseXform {
124
121
  });
125
122
  }
126
123
  }
124
+ // Add passthrough content types (charts, etc.)
125
+ if (model.passthroughContentTypes) {
126
+ for (const { partName, contentType } of model.passthroughContentTypes) {
127
+ xmlStream.leafNode("Override", {
128
+ PartName: (0, ooxml_paths_1.toContentTypesPartName)(partName),
129
+ ContentType: contentType
130
+ });
131
+ }
132
+ }
127
133
  xmlStream.leafNode("Override", {
128
134
  PartName: (0, ooxml_paths_1.toContentTypesPartName)(ooxml_paths_1.OOXML_PATHS.docPropsCore),
129
135
  ContentType: "application/vnd.openxmlformats-package.core-properties+xml"