javascript-excel 2.0.0-alpha.4 → 2.0.0-alpha.5

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.
package/dist/index.cjs CHANGED
@@ -10,7 +10,7 @@ const require_numfmt = require("./numfmt-BmEbm78Y.cjs");
10
10
  const require_address = require("./address-DZBHchLv.cjs");
11
11
  // src/index.ts
12
12
  /** Package version. Set from package.json by `npm run version-packages` (scripts/sync-version.mjs); a unit test checks it. */
13
- const VERSION = "2.0.0-alpha.4";
13
+ const VERSION = "2.0.0-alpha.5";
14
14
  exports.BUILTIN_NUM_FMTS = require_numfmt.BUILTIN_NUM_FMTS;
15
15
  exports.CsvError = require_errors.CsvError;
16
16
  exports.EnvironmentError = require_errors.EnvironmentError;
package/dist/index.d.cts CHANGED
@@ -277,5 +277,5 @@ export declare function encodeRange(r: RangeAddress): string;
277
277
  /** 'A1:C3' or 'A1' → range, normalised so start is top-left. */
278
278
  export declare function decodeRange(ref: string): RangeAddress;
279
279
  /** Package version. Set from package.json by `npm run version-packages` (scripts/sync-version.mjs); a unit test checks it. */
280
- export declare const VERSION = "2.0.0-alpha.4";
280
+ export declare const VERSION = "2.0.0-alpha.5";
281
281
  export { type AbortSignalLike, type Alignment, type AutoWidthOptions, type BinaryInput, type BlobLike, type BlobType, type Border, type BorderSide, type BorderStyle, type Cell, type CellAddress, type CellErrorValue, type CellInput, type CellTextOptions, type CellType, type CellValue, type Color, type ColorContext, type ColumnDef, type ColumnProps, type ColumnTotal, type ColumnWidth, type Dataset, type DatasetBlock, type DatasetOptions, type DatasetResult, type DateOptions, type DefinedName, type DocProperties, type ErrorCode, type ExcelErrorCode, type ExcelErrorOptions, type ExcelWarning, type ExcelWarningCode, type Fill, type Font, type GradientFill, type GroupColumn, type Hyperlink, type LeafColumn, type NumFmt, type PatternFill, type PatternType, type PrintSetup, type Progress, type RangeAddress, type RichText, type RichTextRun, type RowProps, type Sheet, type SheetNameProblem, type SheetView, type Style, type Theme, type ToDatasetOptions, type Workbook, type WriteOptions, XLSX_MIME, toBlob, toUint8Array };
package/dist/index.d.ts CHANGED
@@ -277,5 +277,5 @@ export declare function encodeRange(r: RangeAddress): string;
277
277
  /** 'A1:C3' or 'A1' → range, normalised so start is top-left. */
278
278
  export declare function decodeRange(ref: string): RangeAddress;
279
279
  /** Package version. Set from package.json by `npm run version-packages` (scripts/sync-version.mjs); a unit test checks it. */
280
- export declare const VERSION = "2.0.0-alpha.4";
280
+ export declare const VERSION = "2.0.0-alpha.5";
281
281
  export { type AbortSignalLike, type Alignment, type AutoWidthOptions, type BinaryInput, type BlobLike, type BlobType, type Border, type BorderSide, type BorderStyle, type Cell, type CellAddress, type CellErrorValue, type CellInput, type CellTextOptions, type CellType, type CellValue, type Color, type ColorContext, type ColumnDef, type ColumnProps, type ColumnTotal, type ColumnWidth, type Dataset, type DatasetBlock, type DatasetOptions, type DatasetResult, type DateOptions, type DefinedName, type DocProperties, type ErrorCode, type ExcelErrorCode, type ExcelErrorOptions, type ExcelWarning, type ExcelWarningCode, type Fill, type Font, type GradientFill, type GroupColumn, type Hyperlink, type LeafColumn, type NumFmt, type PatternFill, type PatternType, type PrintSetup, type Progress, type RangeAddress, type RichText, type RichTextRun, type RowProps, type Sheet, type SheetNameProblem, type SheetView, type Style, type Theme, type ToDatasetOptions, type Workbook, type WriteOptions, XLSX_MIME, toBlob, toUint8Array };
package/dist/index.js CHANGED
@@ -9,5 +9,5 @@ import { n as isDateFormat, t as BUILTIN_NUM_FMTS } from "./numfmt-DCDrX9P1.js";
9
9
  import { a as decodeRange, c as encodeRange, i as decodeCol, n as MAX_ROWS, o as encodeCell, r as decodeCell, s as encodeCol, t as MAX_COLS } from "./address-DUn7-5OS.js";
10
10
  // src/index.ts
11
11
  /** Package version. Set from package.json by `npm run version-packages` (scripts/sync-version.mjs); a unit test checks it. */
12
- const VERSION = "2.0.0-alpha.4";
12
+ const VERSION = "2.0.0-alpha.5";
13
13
  export { BUILTIN_NUM_FMTS, CsvError, EnvironmentError, ExcelError, FormatError, LimitError, MAX_COLS, MAX_ROWS, VERSION, ValidationError, XLSX_MIME, cellText, dateToSerial, decodeCell, decodeCol, decodeRange, encodeCell, encodeCol, encodeRange, fromDataset, fromDatasets, isDateFormat, isExcelError, mergeStyles, resolveColor, sanitizeSheetName, serialToDate, toBlob, toDataset, toUint8Array, validateSheetName };
package/dist/render.cjs CHANGED
@@ -95,6 +95,7 @@ function createRenderSheet(workbook, sheet, options = {}) {
95
95
  usedRows,
96
96
  usedCols,
97
97
  rowTops,
98
+ defaultRowPx,
98
99
  colLefts,
99
100
  merges,
100
101
  buckets,
@@ -176,6 +177,45 @@ function colWidth(s, col) {
176
177
  function isRowHidden(s, row) {
177
178
  return rowHeight(s, row) === 0;
178
179
  }
180
+ /** Excel's largest row height, 409 pt, in CSS px. */
181
+ const MAX_ROW_PX = 39264 / 72;
182
+ /** True when the row's height comes from the file (`rowProps[row].height`); only other rows may be auto-fitted (§5.8.1). */
183
+ function hasStoredRowHeight(s, row) {
184
+ return state(s).sh.rowProps?.[row]?.height !== void 0;
185
+ }
186
+ /**
187
+ * Sets measured heights, in CSS px at zoom 100 %, for rows without a stored height: the viewer's
188
+ * auto-fit (§5.8.1). Rows with a stored height, hidden rows and rows outside the extent are ignored.
189
+ * Heights are clamped to [default row height, 409 pt], so auto-fit only grows rows. The offset table
190
+ * is rebuilt from the first changed row onwards. Returns true when anything changed.
191
+ * (An array, not an Iterable, so the declaration works with ES5 lib typings; see Consumer TS.)
192
+ */
193
+ function setRowHeights(s, heights) {
194
+ const st = state(s);
195
+ const tops = st.rowTops;
196
+ const updates = /* @__PURE__ */ new Map();
197
+ let first = Number.POSITIVE_INFINITY;
198
+ for (const [row, px] of heights) {
199
+ if (!(Number.isInteger(row) && row >= 0 && row < st.rows) || !Number.isFinite(px)) continue;
200
+ const props = st.sh.rowProps?.[row];
201
+ if (props?.hidden || props?.height !== void 0) continue;
202
+ const current = tops[row + 1] - tops[row];
203
+ if (current === 0) continue;
204
+ const next = Math.min(MAX_ROW_PX, Math.max(st.defaultRowPx, px));
205
+ if (next !== current) {
206
+ updates.set(row, next);
207
+ if (row < first) first = row;
208
+ }
209
+ }
210
+ if (updates.size === 0) return false;
211
+ let oldTop = tops[first];
212
+ for (let r = first; r < st.rows; r++) {
213
+ const oldNext = tops[r + 1];
214
+ tops[r + 1] = tops[r] + (updates.get(r) ?? oldNext - oldTop);
215
+ oldTop = oldNext;
216
+ }
217
+ return true;
218
+ }
179
219
  function isColHidden(s, col) {
180
220
  return colWidth(s, col) === 0;
181
221
  }
@@ -735,6 +775,7 @@ exports.colLeft = colLeft;
735
775
  exports.colWidth = colWidth;
736
776
  exports.createRenderSheet = createRenderSheet;
737
777
  exports.edge = edge;
778
+ exports.hasStoredRowHeight = hasStoredRowHeight;
738
779
  exports.isColHidden = isColHidden;
739
780
  exports.isRowHidden = isRowHidden;
740
781
  exports.lastUsedCell = lastUsedCell;
@@ -746,6 +787,7 @@ exports.renderCell = renderCell;
746
787
  exports.rowAt = rowAt;
747
788
  exports.rowHeight = rowHeight;
748
789
  exports.rowTop = rowTop;
790
+ exports.setRowHeights = setRowHeights;
749
791
  exports.sheetExtent = sheetExtent;
750
792
  exports.sheetSettings = sheetSettings;
751
793
  exports.step = step;
package/dist/render.d.cts CHANGED
@@ -186,6 +186,16 @@ export declare function rowHeight(s: RenderSheet, row: number): number;
186
186
  export declare function colLeft(s: RenderSheet, col: number): number;
187
187
  export declare function colWidth(s: RenderSheet, col: number): number;
188
188
  export declare function isRowHidden(s: RenderSheet, row: number): boolean;
189
+ /** True when the row's height comes from the file (`rowProps[row].height`); only other rows may be auto-fitted (§5.8.1). */
190
+ export declare function hasStoredRowHeight(s: RenderSheet, row: number): boolean;
191
+ /**
192
+ * Sets measured heights, in CSS px at zoom 100 %, for rows without a stored height: the viewer's
193
+ * auto-fit (§5.8.1). Rows with a stored height, hidden rows and rows outside the extent are ignored.
194
+ * Heights are clamped to [default row height, 409 pt], so auto-fit only grows rows. The offset table
195
+ * is rebuilt from the first changed row onwards. Returns true when anything changed.
196
+ * (An array, not an Iterable, so the declaration works with ES5 lib typings; see Consumer TS.)
197
+ */
198
+ export declare function setRowHeights(s: RenderSheet, heights: ReadonlyArray<readonly [row: number, px: number]>): boolean;
189
199
  export declare function isColHidden(s: RenderSheet, col: number): boolean;
190
200
  export declare function rowAt(s: RenderSheet, y: number): number;
191
201
  export declare function colAt(s: RenderSheet, x: number): number;
package/dist/render.d.ts CHANGED
@@ -186,6 +186,16 @@ export declare function rowHeight(s: RenderSheet, row: number): number;
186
186
  export declare function colLeft(s: RenderSheet, col: number): number;
187
187
  export declare function colWidth(s: RenderSheet, col: number): number;
188
188
  export declare function isRowHidden(s: RenderSheet, row: number): boolean;
189
+ /** True when the row's height comes from the file (`rowProps[row].height`); only other rows may be auto-fitted (§5.8.1). */
190
+ export declare function hasStoredRowHeight(s: RenderSheet, row: number): boolean;
191
+ /**
192
+ * Sets measured heights, in CSS px at zoom 100 %, for rows without a stored height: the viewer's
193
+ * auto-fit (§5.8.1). Rows with a stored height, hidden rows and rows outside the extent are ignored.
194
+ * Heights are clamped to [default row height, 409 pt], so auto-fit only grows rows. The offset table
195
+ * is rebuilt from the first changed row onwards. Returns true when anything changed.
196
+ * (An array, not an Iterable, so the declaration works with ES5 lib typings; see Consumer TS.)
197
+ */
198
+ export declare function setRowHeights(s: RenderSheet, heights: ReadonlyArray<readonly [row: number, px: number]>): boolean;
189
199
  export declare function isColHidden(s: RenderSheet, col: number): boolean;
190
200
  export declare function rowAt(s: RenderSheet, y: number): number;
191
201
  export declare function colAt(s: RenderSheet, x: number): number;
package/dist/render.js CHANGED
@@ -94,6 +94,7 @@ function createRenderSheet(workbook, sheet, options = {}) {
94
94
  usedRows,
95
95
  usedCols,
96
96
  rowTops,
97
+ defaultRowPx,
97
98
  colLefts,
98
99
  merges,
99
100
  buckets,
@@ -175,6 +176,45 @@ function colWidth(s, col) {
175
176
  function isRowHidden(s, row) {
176
177
  return rowHeight(s, row) === 0;
177
178
  }
179
+ /** Excel's largest row height, 409 pt, in CSS px. */
180
+ const MAX_ROW_PX = 39264 / 72;
181
+ /** True when the row's height comes from the file (`rowProps[row].height`); only other rows may be auto-fitted (§5.8.1). */
182
+ function hasStoredRowHeight(s, row) {
183
+ return state(s).sh.rowProps?.[row]?.height !== void 0;
184
+ }
185
+ /**
186
+ * Sets measured heights, in CSS px at zoom 100 %, for rows without a stored height: the viewer's
187
+ * auto-fit (§5.8.1). Rows with a stored height, hidden rows and rows outside the extent are ignored.
188
+ * Heights are clamped to [default row height, 409 pt], so auto-fit only grows rows. The offset table
189
+ * is rebuilt from the first changed row onwards. Returns true when anything changed.
190
+ * (An array, not an Iterable, so the declaration works with ES5 lib typings; see Consumer TS.)
191
+ */
192
+ function setRowHeights(s, heights) {
193
+ const st = state(s);
194
+ const tops = st.rowTops;
195
+ const updates = /* @__PURE__ */ new Map();
196
+ let first = Number.POSITIVE_INFINITY;
197
+ for (const [row, px] of heights) {
198
+ if (!(Number.isInteger(row) && row >= 0 && row < st.rows) || !Number.isFinite(px)) continue;
199
+ const props = st.sh.rowProps?.[row];
200
+ if (props?.hidden || props?.height !== void 0) continue;
201
+ const current = tops[row + 1] - tops[row];
202
+ if (current === 0) continue;
203
+ const next = Math.min(MAX_ROW_PX, Math.max(st.defaultRowPx, px));
204
+ if (next !== current) {
205
+ updates.set(row, next);
206
+ if (row < first) first = row;
207
+ }
208
+ }
209
+ if (updates.size === 0) return false;
210
+ let oldTop = tops[first];
211
+ for (let r = first; r < st.rows; r++) {
212
+ const oldNext = tops[r + 1];
213
+ tops[r + 1] = tops[r] + (updates.get(r) ?? oldNext - oldTop);
214
+ oldTop = oldNext;
215
+ }
216
+ return true;
217
+ }
178
218
  function isColHidden(s, col) {
179
219
  return colWidth(s, col) === 0;
180
220
  }
@@ -729,4 +769,4 @@ function rangeStats(s, range, limit = 1e6) {
729
769
  truncated
730
770
  };
731
771
  }
732
- export { colAt, colLeft, colWidth, createRenderSheet, edge, isColHidden, isRowHidden, lastUsedCell, mergeAt, rangeAsHtml, rangeAsTsv, rangeStats, renderCell, rowAt, rowHeight, rowTop, sheetExtent, sheetSettings, step };
772
+ export { colAt, colLeft, colWidth, createRenderSheet, edge, hasStoredRowHeight, isColHidden, isRowHidden, lastUsedCell, mergeAt, rangeAsHtml, rangeAsTsv, rangeStats, renderCell, rowAt, rowHeight, rowTop, setRowHeights, sheetExtent, sheetSettings, step };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "javascript-excel",
3
- "version": "2.0.0-alpha.4",
3
+ "version": "2.0.0-alpha.5",
4
4
  "private": false,
5
5
  "description": "Read and write .xlsx and .csv files in browsers, Web Workers and Node. 2.0 is a from-scratch rewrite in progress.",
6
6
  "keywords": [