@cj-tech-master/excelts 2.0.1-canary.20251228093548.379d895 → 3.0.0-canary.20251228183403.d3eb98d

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @cj-tech-master/excelts v2.0.1-canary.20251228093548.379d895
2
+ * @cj-tech-master/excelts v3.0.0-canary.20251228183403.d3eb98d
3
3
  * TypeScript Excel Workbook Manager - Read and Write xlsx and csv Files.
4
4
  * (c) 2025 cjnoname
5
5
  * Released under the MIT License
@@ -2999,7 +2999,7 @@ function makePivotTable(worksheet, model) {
2999
2999
  validate(worksheet, model, source);
3000
3000
  const { rows, values } = model;
3001
3001
  const columns = model.columns ?? [];
3002
- const cacheFields = makeCacheFields(source, [...rows, ...columns]);
3002
+ const cacheFields = makeCacheFields(source, [...rows, ...columns], values);
3003
3003
  const nameToIndex = cacheFields.reduce((result, cacheField, index) => {
3004
3004
  result[cacheField.name] = index;
3005
3005
  return result;
@@ -3034,9 +3034,10 @@ function validate(_worksheet, model, source) {
3034
3034
  if (model.values.length < 1) throw new Error("Must have at least one value.");
3035
3035
  if (model.values.length > 1 && columns.length > 0) throw new Error("It is currently not possible to have multiple values when columns are specified. Please either supply an empty array for columns or a single value.");
3036
3036
  }
3037
- function makeCacheFields(source, fieldNamesWithSharedItems) {
3037
+ function makeCacheFields(source, fieldNamesWithSharedItems, valueFieldNames) {
3038
3038
  const names = source.getRow(1).values;
3039
3039
  const sharedItemsFields = new Set(fieldNamesWithSharedItems);
3040
+ const valueFields = new Set(valueFieldNames);
3040
3041
  const aggregate = (columnIndex) => {
3041
3042
  const columnValues = source.getColumn(columnIndex).values;
3042
3043
  const uniqueValues = /* @__PURE__ */ new Set();
@@ -3071,7 +3072,7 @@ function makeCacheFields(source, fieldNamesWithSharedItems) {
3071
3072
  name,
3072
3073
  sharedItems: aggregate(columnIndex)
3073
3074
  });
3074
- else {
3075
+ else if (valueFields.has(name)) {
3075
3076
  const minMax = getMinMax(columnIndex);
3076
3077
  result.push({
3077
3078
  name,
@@ -3079,7 +3080,10 @@ function makeCacheFields(source, fieldNamesWithSharedItems) {
3079
3080
  minValue: minMax?.minValue,
3080
3081
  maxValue: minMax?.maxValue
3081
3082
  });
3082
- }
3083
+ } else result.push({
3084
+ name,
3085
+ sharedItems: null
3086
+ });
3083
3087
  }
3084
3088
  return result;
3085
3089
  }
@@ -14680,9 +14684,25 @@ var CacheField = class {
14680
14684
  }
14681
14685
  render() {
14682
14686
  const escapedName = xmlEncode(this.name);
14683
- if (this.sharedItems === null) return `<cacheField name="${escapedName}" numFmtId="0">
14684
- <sharedItems containsSemiMixedTypes="0" containsString="0" containsNumber="1" containsInteger="1"${this.minValue !== void 0 && this.maxValue !== void 0 ? ` minValue="${this.minValue}" maxValue="${this.maxValue}"` : ""} />
14687
+ if (this.sharedItems === null) {
14688
+ if (this.minValue === void 0 || this.maxValue === void 0) return `<cacheField name="${escapedName}" numFmtId="0">
14689
+ <sharedItems />
14690
+ </cacheField>`;
14691
+ return `<cacheField name="${escapedName}" numFmtId="0">
14692
+ <sharedItems containsSemiMixedTypes="0" containsString="0" containsNumber="1" containsInteger="1" minValue="${this.minValue}" maxValue="${this.maxValue}" />
14685
14693
  </cacheField>`;
14694
+ }
14695
+ const allNumeric = this.sharedItems.length > 0 && this.sharedItems.every((item) => typeof item === "number" && Number.isFinite(item));
14696
+ const allInteger = allNumeric && this.sharedItems.every((item) => Number.isInteger(item));
14697
+ if (allNumeric) {
14698
+ const minValue = Math.min(...this.sharedItems);
14699
+ const maxValue = Math.max(...this.sharedItems);
14700
+ return `<cacheField name="${escapedName}" numFmtId="0">
14701
+ <sharedItems containsSemiMixedTypes="0" containsString="0" containsNumber="1"${allInteger ? " containsInteger=\"1\"" : ""} minValue="${minValue}" maxValue="${maxValue}" count="${this.sharedItems.length}">
14702
+ ${this.sharedItems.map((item) => `<n v="${item}" />`).join("")}
14703
+ </sharedItems>
14704
+ </cacheField>`;
14705
+ }
14686
14706
  return `<cacheField name="${escapedName}" numFmtId="0">
14687
14707
  <sharedItems count="${this.sharedItems.length}">
14688
14708
  ${this.sharedItems.map((item) => `<s v="${xmlEncode(String(item))}" />`).join("")}
@@ -14736,16 +14756,13 @@ var CacheFieldXform = class extends BaseXform {
14736
14756
  break;
14737
14757
  case "sharedItems":
14738
14758
  this.inSharedItems = true;
14739
- if (attributes.containsNumber === "1" || attributes.containsInteger === "1") {
14740
- if (this.model) {
14741
- this.model.containsNumber = attributes.containsNumber === "1";
14742
- this.model.containsInteger = attributes.containsInteger === "1";
14743
- if (attributes.minValue !== void 0) this.model.minValue = parseFloat(attributes.minValue);
14744
- if (attributes.maxValue !== void 0) this.model.maxValue = parseFloat(attributes.maxValue);
14745
- this.model.sharedItems = null;
14746
- }
14747
- } else if (this.model) {
14759
+ if (this.model) {
14760
+ this.model.containsNumber = attributes.containsNumber === "1";
14761
+ this.model.containsInteger = attributes.containsInteger === "1";
14762
+ if (attributes.minValue !== void 0) this.model.minValue = parseFloat(attributes.minValue);
14763
+ if (attributes.maxValue !== void 0) this.model.maxValue = parseFloat(attributes.maxValue);
14748
14764
  if (parseInt(attributes.count || "0", 10) > 0) this.model.sharedItems = [];
14765
+ else this.model.sharedItems = null;
14749
14766
  }
14750
14767
  break;
14751
14768
  case "s":
@@ -15409,13 +15426,14 @@ function renderPivotFields(pivotTable) {
15409
15426
  const colSet = new Set(pivotTable.columns);
15410
15427
  const valueSet = new Set(pivotTable.values);
15411
15428
  return pivotTable.cacheFields.map((cacheField, fieldIndex) => {
15412
- return renderPivotField(rowSet.has(fieldIndex) ? "row" : colSet.has(fieldIndex) ? "column" : valueSet.has(fieldIndex) ? "value" : null, cacheField.sharedItems);
15429
+ return renderPivotField(rowSet.has(fieldIndex), colSet.has(fieldIndex), valueSet.has(fieldIndex), cacheField.sharedItems);
15413
15430
  }).join("");
15414
15431
  }
15415
- function renderPivotField(fieldType, sharedItems) {
15416
- if (fieldType === "row" || fieldType === "column") {
15417
- const axis = fieldType === "row" ? "axisRow" : "axisCol";
15418
- const axisAttributes = "compact=\"0\" outline=\"0\" showAll=\"0\"";
15432
+ function renderPivotField(isRow, isCol, isValue, sharedItems) {
15433
+ if (isRow || isCol) {
15434
+ const axis = isRow ? "axisRow" : "axisCol";
15435
+ let axisAttributes = "compact=\"0\" outline=\"0\" showAll=\"0\"";
15436
+ if (isValue) axisAttributes = `dataField="1" ${axisAttributes}`;
15419
15437
  const itemsXml = [...sharedItems.map((_item, index) => `<item x="${index}" />`), "<item t=\"default\" />"].join("\n ");
15420
15438
  return `
15421
15439
  <pivotField axis="${axis}" ${axisAttributes}>
@@ -15427,7 +15445,7 @@ function renderPivotField(fieldType, sharedItems) {
15427
15445
  }
15428
15446
  return `
15429
15447
  <pivotField
15430
- ${fieldType === "value" ? "dataField=\"1\"" : ""}
15448
+ ${isValue ? "dataField=\"1\"" : ""}
15431
15449
  compact="0" outline="0" showAll="0" defaultSubtotal="0"
15432
15450
  />
15433
15451
  `;