@mog-sdk/node 0.1.9-beta.2 → 0.1.9

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.js CHANGED
@@ -527,9 +527,7 @@ function getPlatformPackageName() {
527
527
  }
528
528
  const pkg = platformMap[process.arch];
529
529
  if (!pkg) {
530
- throw new Error(
531
- `Unsupported architecture ${process.arch} on ${process.platform}`
532
- );
530
+ throw new Error(`Unsupported architecture ${process.arch} on ${process.platform}`);
533
531
  }
534
532
  return pkg;
535
533
  }
@@ -652,14 +650,14 @@ function deepSnakeToCamel(obj) {
652
650
  }
653
651
  return obj;
654
652
  }
655
- function createNapiTransport(engine, serdeParams) {
653
+ function createNapiTransport(engine, serdeParams, addon) {
656
654
  return {
657
655
  async call(command, args) {
658
- const fn = engine[command];
656
+ const fn = engine[command] ?? addon?.[snakeToCamel(command)];
659
657
  if (!fn) {
660
658
  throw new TransportError(
661
659
  command,
662
- `Method "${command}" not found on napi engine. The compute-core-napi binary is likely out of date \u2014 rebuild with: cd compute-core-napi && npm run build`
660
+ `Method "${command}" not found on napi engine${addon ? " or addon module" : ""}. The compute-core-napi binary is likely out of date \u2014 rebuild with: cd compute-core-napi && npm run build`
663
661
  );
664
662
  }
665
663
  try {
@@ -687,7 +685,8 @@ function createNapiTransport(engine, serdeParams) {
687
685
  }
688
686
  return value;
689
687
  });
690
- const result = fn.call(engine, ...positionalArgs);
688
+ const isEngineFn = !!engine[command];
689
+ const result = fn.call(isEngineFn ? engine : addon, ...positionalArgs);
691
690
  if (typeof result === "string") {
692
691
  try {
693
692
  return deepSnakeToCamel(JSON.parse(result));
@@ -719,7 +718,7 @@ function createLazyNapiTransport(addon) {
719
718
  if (command === "compute_init") {
720
719
  const snapshotJson = typeof args.snapshot === "string" ? args.snapshot : JSON.stringify(args.snapshot);
721
720
  const engine = new addon.ComputeEngine(snapshotJson);
722
- innerTransport = createNapiTransport(engine, DEFAULT_NAPI_SERDE_PARAMS);
721
+ innerTransport = createNapiTransport(engine, DEFAULT_NAPI_SERDE_PARAMS, addon);
723
722
  const initResultJson = engine.compute_take_init_result?.();
724
723
  if (initResultJson) {
725
724
  return deepSnakeToCamel(JSON.parse(initResultJson));
@@ -6635,6 +6634,9 @@ var init_compute_bridge_gen = __esm({
6635
6634
  pivotGetAll(sheetId) {
6636
6635
  return this.core.query(this.core.transport.call("compute_pivot_get_all", { docId: this.core.docId, sheetId }));
6637
6636
  }
6637
+ pivotComputeFromSource(sheetId, pivotId, expansionState) {
6638
+ return this.core.query(this.core.transport.call("compute_pivot_compute_from_source", { docId: this.core.docId, sheetId, pivotId, expansionState }));
6639
+ }
6638
6640
  pivotRegisterDef(sheetId, pivotId, totalRows, totalCols, firstDataRow, firstDataCol) {
6639
6641
  return this.core.mutatePlain(this.core.transport.call("compute_pivot_register_def", { docId: this.core.docId, sheetId, pivotId, totalRows, totalCols, firstDataRow, firstDataCol }));
6640
6642
  }
@@ -7004,7 +7006,9 @@ var init_compute_bridge = __esm({
7004
7006
  parentId: options?.parentId ?? null
7005
7007
  }
7006
7008
  );
7007
- const tuple = normalizeBytesTuple(raw);
7009
+ const tuple = normalizeBytesTuple(
7010
+ raw
7011
+ );
7008
7012
  const result = await this.core.mutate(Promise.resolve(tuple));
7009
7013
  const comment = extractMutationData(result);
7010
7014
  if (!comment) {
@@ -7111,14 +7115,9 @@ var init_compute_bridge = __esm({
7111
7115
  // ===========================================================================
7112
7116
  /** Get protection options for a sheet. Returns per-operation permissions when protected. */
7113
7117
  async getSheetProtectionOptions(sheetId) {
7114
- const config = await this.core.query(
7115
- this.core.transport.call("compute_get_sheet_protection_config", {
7116
- docId: this.core.docId,
7117
- sheetId
7118
- })
7119
- );
7120
- if (!config.isProtected) return null;
7121
- return DEFAULT_PROTECTION_OPTIONS;
7118
+ const settings = await this.getSheetSettings(sheetId);
7119
+ if (!settings.isProtected) return null;
7120
+ return { ...DEFAULT_PROTECTION_OPTIONS, ...settings.protectionOptions };
7122
7121
  }
7123
7122
  /** Set multiple sheet settings at once (iterates entries). */
7124
7123
  async setSheetSettings(sheetId, updates) {
@@ -7158,7 +7157,8 @@ var init_compute_bridge = __esm({
7158
7157
  const tuples = edits.map(
7159
7158
  (e) => [sheetId, e.row, e.col, e.input]
7160
7159
  );
7161
- return this.batchSetCellsByPosition(tuples, false);
7160
+ const result = await this.batchSetCellsByPosition(tuples, false);
7161
+ return result;
7162
7162
  }
7163
7163
  /** Patch workbook settings — reads current, merges partial, writes full. */
7164
7164
  async patchWorkbookSettings(settings) {
@@ -7838,35 +7838,6 @@ function letterToCol(letters) {
7838
7838
  }
7839
7839
  return result - 1;
7840
7840
  }
7841
- function parseA1(address) {
7842
- const match = address.match(/^([A-Za-z]+)(\d+)$/);
7843
- if (!match) {
7844
- throw new Error(`Invalid cell address: ${address}`);
7845
- }
7846
- return {
7847
- row: parseInt(match[2], 10) - 1,
7848
- col: letterToCol(match[1])
7849
- };
7850
- }
7851
- function parseA1Range(range2) {
7852
- const [start, end] = range2.split(":");
7853
- const startPos = parseA1(start);
7854
- if (!end) {
7855
- return {
7856
- startRow: startPos.row,
7857
- startCol: startPos.col,
7858
- endRow: startPos.row,
7859
- endCol: startPos.col
7860
- };
7861
- }
7862
- const endPos = parseA1(end);
7863
- return {
7864
- startRow: Math.min(startPos.row, endPos.row),
7865
- startCol: Math.min(startPos.col, endPos.col),
7866
- endRow: Math.max(startPos.row, endPos.row),
7867
- endCol: Math.max(startPos.col, endPos.col)
7868
- };
7869
- }
7870
7841
  function toA1(row, col) {
7871
7842
  return `${colToLetter2(col)}${row + 1}`;
7872
7843
  }
@@ -7988,13 +7959,13 @@ async function getChartDataRange(ctx, chart) {
7988
7959
  const sheetId = chart.sheetId;
7989
7960
  if (!sheetId) {
7990
7961
  if (!chart.dataRange) return null;
7991
- return parseA1Range(chart.dataRange);
7962
+ return parseCellRange(chart.dataRange);
7992
7963
  }
7993
7964
  if (chart.dataRangeIdentity) {
7994
7965
  return resolveCellIdRange(ctx, sheetId, chart.dataRangeIdentity);
7995
7966
  }
7996
7967
  if (!chart.dataRange) return null;
7997
- return parseA1Range(chart.dataRange);
7968
+ return parseCellRange(chart.dataRange);
7998
7969
  }
7999
7970
  async function getMaxZIndex(ctx, sheetId) {
8000
7971
  const charts = await getAll2(ctx, sheetId);
@@ -9136,7 +9107,11 @@ var init_statistics = __esm({
9136
9107
 
9137
9108
  // ../../charts/src/core/data-extractor.ts
9138
9109
  function parseRange(range2) {
9139
- return parseA1Range(range2);
9110
+ const parsed = parseCellRange(range2);
9111
+ if (!parsed) {
9112
+ throw new Error(`Invalid cell range: ${range2}`);
9113
+ }
9114
+ return parsed;
9140
9115
  }
9141
9116
  function toNumber(value) {
9142
9117
  if (value === null || value === void 0 || value === "") {
@@ -15786,6 +15761,26 @@ var init_cell_properties = __esm({
15786
15761
  }
15787
15762
  });
15788
15763
 
15764
+ // ../../kernel/src/api/internal/value-conversions.ts
15765
+ function viewportCellValueToCellValue(cv) {
15766
+ return cv;
15767
+ }
15768
+ function viewportCellValueToString(cv) {
15769
+ if (cv === null || cv === void 0) return "";
15770
+ if (typeof cv === "string") return cv;
15771
+ if (typeof cv === "number") return String(cv);
15772
+ if (typeof cv === "boolean") return cv ? "TRUE" : "FALSE";
15773
+ if (isCellError(cv)) return errorDisplayString(cv.value);
15774
+ return "";
15775
+ }
15776
+ var init_value_conversions = __esm({
15777
+ "../../kernel/src/api/internal/value-conversions.ts"() {
15778
+ "use strict";
15779
+ init_esm_shims();
15780
+ init_errors3();
15781
+ }
15782
+ });
15783
+
15789
15784
  // ../../kernel/src/domain/drawing/ink/ink-tool-defaults.ts
15790
15785
  function getDefaultToolSettings(tool) {
15791
15786
  return {
@@ -25149,8 +25144,7 @@ var init_pivot_bridge = __esm({
25149
25144
  "../../kernel/src/bridges/pivot-bridge.ts"() {
25150
25145
  "use strict";
25151
25146
  init_esm_shims();
25152
- init_rich_text();
25153
- init_cell_reads();
25147
+ init_value_conversions();
25154
25148
  init_sheet_meta();
25155
25149
  init_compute_core();
25156
25150
  PivotBridge = class {
@@ -25256,30 +25250,22 @@ var init_pivot_bridge = __esm({
25256
25250
  * Uses cached result if available and valid.
25257
25251
  */
25258
25252
  async compute(sheetId, pivotId, forceRefresh = false) {
25259
- const config = await this.ctx.computeBridge.pivotGet(sheetId, pivotId);
25260
- if (!config) {
25261
- return null;
25262
- }
25263
25253
  const configVersion = this.getConfigVersion(pivotId);
25264
- const dataVersion = this.getDataVersion(config.sourceSheetId);
25254
+ const dataVersion = this.getDataVersion(sheetId);
25265
25255
  if (!forceRefresh) {
25266
25256
  const cached = this.cache.get(pivotId);
25267
25257
  if (cached && cached.configVersion === configVersion && cached.dataVersion === dataVersion) {
25268
25258
  return cached.result;
25269
25259
  }
25270
25260
  }
25271
- const data = await this.getSourceData(config);
25272
- if (!data) {
25273
- return null;
25274
- }
25275
25261
  const expansionState = this.ctx.pivotExpansionProvider?.getExpansionState(pivotId) ?? {
25276
25262
  expandedRows: {},
25277
25263
  expandedColumns: {}
25278
25264
  };
25279
25265
  try {
25280
- const result = await this.ctx.computeBridge.pivotCompute(
25281
- config,
25282
- data,
25266
+ const result = await this.ctx.computeBridge.pivotComputeFromSource(
25267
+ sheetId,
25268
+ pivotId,
25283
25269
  expansionState ?? null
25284
25270
  );
25285
25271
  this.cache.set(pivotId, {
@@ -25451,23 +25437,26 @@ var init_pivot_bridge = __esm({
25451
25437
  }
25452
25438
  /**
25453
25439
  * Get data from a cell range.
25454
- * Uses Cells domain module instead of SpreadsheetStore
25440
+ * Uses queryRange for bulk cell reading (works in all modes including headless/NAPI).
25455
25441
  */
25456
25442
  async getDataFromRange(sheetId, range2) {
25443
+ const rangeResult = await this.ctx.computeBridge.queryRange(
25444
+ sheetId,
25445
+ range2.startRow,
25446
+ range2.startCol,
25447
+ range2.endRow,
25448
+ range2.endCol
25449
+ );
25450
+ const cellMap = /* @__PURE__ */ new Map();
25451
+ for (const cell of rangeResult.cells) {
25452
+ cellMap.set(`${cell.row},${cell.col}`, cell);
25453
+ }
25457
25454
  const data = [];
25458
25455
  for (let row = range2.startRow; row <= range2.endRow; row++) {
25459
25456
  const rowData = [];
25460
25457
  for (let col = range2.startCol; col <= range2.endCol; col++) {
25461
- const cellData = await getData(this.ctx, sheetId, row, col);
25462
- let value;
25463
- if (!cellData) {
25464
- value = null;
25465
- } else if (cellData.formula !== void 0) {
25466
- value = cellData.computed ?? null;
25467
- } else {
25468
- value = cellData.raw !== void 0 ? rawToCellValue(cellData.raw) : null;
25469
- }
25470
- rowData.push(value);
25458
+ const cell = cellMap.get(`${row},${col}`);
25459
+ rowData.push(cell ? viewportCellValueToCellValue(cell.value) ?? null : null);
25471
25460
  }
25472
25461
  data.push(rowData);
25473
25462
  }
@@ -76396,7 +76385,7 @@ var init_document_lifecycle_system = __esm({
76396
76385
  await databaseBridge.initialize();
76397
76386
  } catch (err2) {
76398
76387
  const msg = err2 instanceof Error ? err2.message : String(err2);
76399
- if (msg.includes("Unknown WASM function") || msg.includes("compute_init must be called before")) {
76388
+ if (msg.includes("Unknown WASM function") || msg.includes("compute_init must be called before") || msg.includes("not found")) {
76400
76389
  console.debug(
76401
76390
  "[DocumentLifecycleSystem] DatabaseBridge unavailable in this environment \u2014 database features disabled."
76402
76391
  );
@@ -77753,7 +77742,8 @@ var WorkbookNamesImpl = class {
77753
77742
  if (typeof cell === "boolean") return "Boolean" /* Boolean */;
77754
77743
  if (typeof cell === "number") return "Double" /* Double */;
77755
77744
  if (typeof cell === "string") return "String" /* String */;
77756
- if (typeof cell === "object" && cell !== null && "type" in cell) return "Error" /* Error */;
77745
+ if (typeof cell === "object" && cell !== null && "type" in cell)
77746
+ return "Error" /* Error */;
77757
77747
  return "String" /* String */;
77758
77748
  })
77759
77749
  );
@@ -79133,20 +79123,8 @@ function analyzeStylePatterns(cells) {
79133
79123
  return lines;
79134
79124
  }
79135
79125
 
79136
- // ../../kernel/src/api/internal/value-conversions.ts
79137
- init_esm_shims();
79138
- init_errors3();
79139
- function viewportCellValueToCellValue(cv) {
79140
- return cv;
79141
- }
79142
- function viewportCellValueToString(cv) {
79143
- if (cv === null || cv === void 0) return "";
79144
- if (typeof cv === "string") return cv;
79145
- if (typeof cv === "number") return String(cv);
79146
- if (typeof cv === "boolean") return cv ? "TRUE" : "FALSE";
79147
- if (isCellError(cv)) return errorDisplayString(cv.value);
79148
- return "";
79149
- }
79126
+ // ../../kernel/src/api/worksheet/worksheet-impl.ts
79127
+ init_value_conversions();
79150
79128
 
79151
79129
  // ../../kernel/src/api/worksheet/operations/cell-operations.ts
79152
79130
  init_esm_shims();
@@ -79205,18 +79183,27 @@ async function setCell(ctx, sheetId, row, col, value) {
79205
79183
  throw KernelError.from(null, "COMPUTE_ERROR", `Invalid cell address: row=${row}, col=${col}`);
79206
79184
  }
79207
79185
  const input = value === null || value === void 0 ? "" : value === "" ? "\0" : String(value);
79208
- await ctx.computeBridge.setCellsByPosition(sheetId, [{ row, col, input }]);
79209
- }
79210
- async function batchSetCells(ctx, sheetId, updates) {
79211
- if (updates.length === 0) return;
79212
- const edits = updates.map(
79213
- ({ row, col, value }) => ({
79214
- row,
79215
- col,
79216
- input: typeof value === "string" && value.startsWith("=") ? value : value === null || value === void 0 ? "" : value === "" ? "\0" : String(value)
79217
- })
79218
- );
79186
+ const result = await ctx.computeBridge.setCellsByPosition(sheetId, [{ row, col, input }]);
79187
+ }
79188
+ async function setCells(ctx, sheetId, cells) {
79189
+ if (cells.length === 0) return { cellsWritten: 0 };
79190
+ const edits = cells.map((cell) => {
79191
+ let row;
79192
+ let col;
79193
+ if ("addr" in cell && typeof cell.addr === "string") {
79194
+ const resolved = resolveCell(cell.addr);
79195
+ row = resolved.row;
79196
+ col = resolved.col;
79197
+ } else {
79198
+ row = cell.row;
79199
+ col = cell.col;
79200
+ }
79201
+ const { value } = cell;
79202
+ const input = typeof value === "string" && value.startsWith("=") ? value : value === null || value === void 0 ? "" : value === "" ? "\0" : String(value);
79203
+ return { row, col, input };
79204
+ });
79219
79205
  await ctx.computeBridge.setCellsByPosition(sheetId, edits);
79206
+ return { cellsWritten: edits.length };
79220
79207
  }
79221
79208
  async function setDateValue(ctx, sheetId, row, col, year, month, day) {
79222
79209
  const cellId = await ctx.computeBridge.getCellIdAt(sheetId, row, col);
@@ -79254,13 +79241,6 @@ async function setTimeValue(ctx, sheetId, row, col, hours, minutes, seconds) {
79254
79241
  });
79255
79242
  }
79256
79243
  }
79257
- async function batchSetFormulas(ctx, sheetId, updates) {
79258
- if (updates.length === 0) return;
79259
- const edits = updates.map(
79260
- ({ row, col, formula }) => ({ row, col, input: formula })
79261
- );
79262
- await ctx.computeBridge.setCellsByPosition(sheetId, edits);
79263
- }
79264
79244
  async function relocateCells(ctx, sheetId, srcStartRow, srcStartCol, srcEndRow, srcEndCol, targetRow, targetCol) {
79265
79245
  await ctx.computeBridge.relocateCells(
79266
79246
  sheetId,
@@ -79631,6 +79611,7 @@ async function getMergeAt(ctx, sheetId, row, col) {
79631
79611
  // ../../kernel/src/api/worksheet/operations/query-operations.ts
79632
79612
  init_esm_shims();
79633
79613
  init_a1();
79614
+ init_value_conversions();
79634
79615
  async function getUsedRange2(ctx, sheetId) {
79635
79616
  const bounds = await ctx.computeBridge.getDataBounds(sheetId);
79636
79617
  if (!bounds) return null;
@@ -79761,6 +79742,7 @@ async function getRangeWithIdentity(ctx, sheetId, startRow, startCol, endRow, en
79761
79742
  // ../../kernel/src/api/worksheet/operations/range-operations.ts
79762
79743
  init_esm_shims();
79763
79744
  init_errors();
79745
+ init_value_conversions();
79764
79746
  async function getRange(ctx, sheetId, range2) {
79765
79747
  const normalized = normalizeRange(range2);
79766
79748
  const rangeResult = await ctx.computeBridge.queryRange(
@@ -79795,6 +79777,30 @@ async function getRange(ctx, sheetId, range2) {
79795
79777
  }
79796
79778
  return result;
79797
79779
  }
79780
+ async function getRangeFormulas(ctx, sheetId, range2) {
79781
+ const normalized = normalizeRange(range2);
79782
+ const rangeResult = await ctx.computeBridge.queryRange(
79783
+ sheetId,
79784
+ normalized.startRow,
79785
+ normalized.startCol,
79786
+ normalized.endRow,
79787
+ normalized.endCol
79788
+ );
79789
+ const cellMap = /* @__PURE__ */ new Map();
79790
+ for (const cell of rangeResult.cells) {
79791
+ cellMap.set(`${cell.row},${cell.col}`, cell);
79792
+ }
79793
+ const result = [];
79794
+ for (let row = normalized.startRow; row <= normalized.endRow; row++) {
79795
+ const rowData = [];
79796
+ for (let col = normalized.startCol; col <= normalized.endCol; col++) {
79797
+ const cell = cellMap.get(`${row},${col}`);
79798
+ rowData.push(cell?.formula ?? null);
79799
+ }
79800
+ result.push(rowData);
79801
+ }
79802
+ return result;
79803
+ }
79798
79804
  async function setRange(ctx, sheetId, startRow, startCol, values) {
79799
79805
  if (!isValidAddress(startRow, startCol)) {
79800
79806
  throw KernelError.from(
@@ -79862,6 +79868,7 @@ async function clearRange2(ctx, sheetId, range2) {
79862
79868
  // ../../kernel/src/api/worksheet/operations/range-query-operations.ts
79863
79869
  init_esm_shims();
79864
79870
  init_a1();
79871
+ init_value_conversions();
79865
79872
  async function clearWithMode(ctx, sheetId, range2, applyTo = "all") {
79866
79873
  const n = normalizeRange(range2);
79867
79874
  const promises = [];
@@ -80933,7 +80940,7 @@ function chartConfigToInternal(config) {
80933
80940
  visible: true,
80934
80941
  printable: true,
80935
80942
  opacity: 1,
80936
- name: config.title ?? "",
80943
+ name: config.name ?? "",
80937
80944
  createdAt: now,
80938
80945
  updatedAt: now,
80939
80946
  // FloatingObjectData discriminator
@@ -81101,7 +81108,9 @@ var WorksheetChartsImpl = class _WorksheetChartsImpl {
81101
81108
  // ===========================================================================
81102
81109
  async add(config) {
81103
81110
  if (!config.type) throw invalidChartConfig("type is required");
81104
- if (!config.dataRange) throw invalidChartConfig("dataRange is required");
81111
+ const hasSeriesValues = config.series?.some((s) => s.values);
81112
+ if (!config.dataRange && !hasSeriesValues)
81113
+ throw invalidChartConfig("dataRange is required when series[].values are not provided");
81105
81114
  const chartId = config.id || `chart-${Date.now()}-${_WorksheetChartsImpl._idCounter++}`;
81106
81115
  const configWithId = { ...config, id: chartId };
81107
81116
  const internalConfig = chartConfigToInternal(configWithId);
@@ -82198,16 +82207,22 @@ var WorksheetFormatsImpl = class {
82198
82207
  const current = await this.get(row, col);
82199
82208
  const currentIndent = current?.indent ?? 0;
82200
82209
  const newIndent = Math.max(0, Math.min(250, currentIndent + amount));
82201
- await this.ctx.computeBridge.setFormatForRanges(this.sheetId, [[row, col, row, col]], { indent: newIndent });
82210
+ await this.ctx.computeBridge.setFormatForRanges(this.sheetId, [[row, col, row, col]], {
82211
+ indent: newIndent
82212
+ });
82202
82213
  }
82203
82214
  async clearFill(a, b) {
82204
82215
  const { row, col } = resolveCell(a, b);
82205
- await this.ctx.computeBridge.setFormatForRanges(this.sheetId, [[row, col, row, col]], {
82206
- backgroundColor: "",
82207
- patternType: "none",
82208
- patternForegroundColor: "",
82209
- gradientFill: void 0
82210
- });
82216
+ const rangeTuple = [row, col, row, col];
82217
+ const current = await this.get(row, col);
82218
+ await this.ctx.computeBridge.clearFormatForRanges(this.sheetId, [rangeTuple]);
82219
+ if (current) {
82220
+ const { backgroundColor, patternType, patternForegroundColor, gradientFill, ...rest } = current;
82221
+ const hasRest = Object.keys(rest).length > 0;
82222
+ if (hasRest) {
82223
+ await this.ctx.computeBridge.setFormatForRanges(this.sheetId, [rangeTuple], rest);
82224
+ }
82225
+ }
82211
82226
  }
82212
82227
  async getNumberFormatCategory(a, b) {
82213
82228
  const { row, col } = resolveCell(a, b);
@@ -82646,14 +82661,20 @@ var WorksheetNamesImpl = class {
82646
82661
  async remove(name) {
82647
82662
  const defined = await getByName(this.ctx, name, this.sheetId);
82648
82663
  if (!defined) {
82649
- throw new KernelError("COMPUTE_ERROR", `Named range "${name}" not found in this sheet's scope.`);
82664
+ throw new KernelError(
82665
+ "COMPUTE_ERROR",
82666
+ `Named range "${name}" not found in this sheet's scope.`
82667
+ );
82650
82668
  }
82651
82669
  await remove(this.ctx, defined.id, "api");
82652
82670
  }
82653
82671
  async update(name, updates) {
82654
82672
  const defined = await getByName(this.ctx, name, this.sheetId);
82655
82673
  if (!defined) {
82656
- throw new KernelError("COMPUTE_ERROR", `Named range "${name}" not found in this sheet's scope.`);
82674
+ throw new KernelError(
82675
+ "COMPUTE_ERROR",
82676
+ `Named range "${name}" not found in this sheet's scope.`
82677
+ );
82657
82678
  }
82658
82679
  const refersToA1 = updates.reference ? updates.reference.startsWith("=") ? updates.reference : `=${updates.reference}` : void 0;
82659
82680
  await update2(
@@ -83053,12 +83074,21 @@ var WorksheetPivotsImpl = class _WorksheetPivotsImpl {
83053
83074
  );
83054
83075
  }
83055
83076
  }
83056
- return pivots.map((p) => ({
83057
- name: p.name ?? p.id,
83058
- dataSource: formatDataSource(sheetNameCache.get(p.sourceSheetId) ?? null, p.sourceRange),
83059
- contentArea: "",
83060
- filterArea: void 0
83061
- }));
83077
+ return pivots.map((p) => {
83078
+ const apiConfig = dataConfigToApiConfig(p, sheetNameCache.get(p.sourceSheetId) ?? null);
83079
+ const location = p.outputLocation ? toA1(p.outputLocation.row, p.outputLocation.col) : void 0;
83080
+ return {
83081
+ name: p.name ?? p.id,
83082
+ dataSource: apiConfig.dataSource,
83083
+ contentArea: "",
83084
+ filterArea: void 0,
83085
+ location,
83086
+ rowFields: apiConfig.rowFields,
83087
+ columnFields: apiConfig.columnFields,
83088
+ valueFields: apiConfig.valueFields,
83089
+ filterFields: apiConfig.filterFields
83090
+ };
83091
+ });
83062
83092
  }
83063
83093
  async get(name) {
83064
83094
  const pivot = await this.findPivotByName(name);
@@ -83209,6 +83239,99 @@ var WorksheetPivotsImpl = class _WorksheetPivotsImpl {
83209
83239
  async getDrillDownData(pivotId, rowKey, columnKey) {
83210
83240
  return await this.ctx.pivot.getDrillDownData(this.sheetId, pivotId, rowKey, columnKey);
83211
83241
  }
83242
+ async queryPivot(pivotName, filters) {
83243
+ const pivot = await this.findPivotByName(pivotName);
83244
+ if (!pivot) return null;
83245
+ const pivotId = pivot.id ?? pivot.name;
83246
+ const result = await this.ctx.pivot.compute(this.sheetId, pivotId);
83247
+ if (!result) return null;
83248
+ const fieldNameById = /* @__PURE__ */ new Map();
83249
+ for (const f of pivot.fields) {
83250
+ fieldNameById.set(f.id, f.name);
83251
+ }
83252
+ const rowPlacements = pivot.placements.filter((p) => p.area === "row").sort((a, b) => a.position - b.position);
83253
+ const colPlacements = pivot.placements.filter((p) => p.area === "column").sort((a, b) => a.position - b.position);
83254
+ const valuePlacements = pivot.placements.filter((p) => p.area === "value").sort((a, b) => a.position - b.position);
83255
+ const rowFieldNames = rowPlacements.map((p) => fieldNameById.get(p.fieldId) ?? p.fieldId);
83256
+ const colFieldNames = colPlacements.map((p) => fieldNameById.get(p.fieldId) ?? p.fieldId);
83257
+ const valueFieldLabels = valuePlacements.map((p) => {
83258
+ if (p.displayName) return p.displayName;
83259
+ const name = fieldNameById.get(p.fieldId) ?? p.fieldId;
83260
+ const agg = p.aggregateFunction ?? "sum";
83261
+ return `${agg.charAt(0).toUpperCase() + agg.slice(1)} of ${name}`;
83262
+ });
83263
+ const numDataCols = result.rows.length > 0 ? result.rows[0].values.length : 0;
83264
+ const colDimensionTuples = [];
83265
+ if (colPlacements.length > 0 && result.columnHeaders.length > 0) {
83266
+ for (let i = 0; i < numDataCols; i++) {
83267
+ colDimensionTuples.push({});
83268
+ }
83269
+ for (const level of result.columnHeaders) {
83270
+ const fieldName = fieldNameById.get(level.fieldId) ?? level.fieldId;
83271
+ let colIndex = 0;
83272
+ for (const header of level.headers) {
83273
+ if (!header.isSubtotal && !header.isGrandTotal) {
83274
+ for (let s = 0; s < header.span; s++) {
83275
+ if (colIndex + s < numDataCols) {
83276
+ colDimensionTuples[colIndex + s][fieldName] = header.value;
83277
+ }
83278
+ }
83279
+ }
83280
+ colIndex += header.span;
83281
+ }
83282
+ }
83283
+ }
83284
+ const records = [];
83285
+ for (const row of result.rows) {
83286
+ if (row.isSubtotal || row.isGrandTotal) continue;
83287
+ const rowDimensions = {};
83288
+ for (const header of row.headers) {
83289
+ if (header.isSubtotal || header.isGrandTotal) continue;
83290
+ const fieldName = fieldNameById.get(header.fieldId) ?? header.fieldId;
83291
+ rowDimensions[fieldName] = header.value;
83292
+ }
83293
+ if (colDimensionTuples.length > 0) {
83294
+ for (let colIdx = 0; colIdx < colDimensionTuples.length; colIdx++) {
83295
+ const colDims = colDimensionTuples[colIdx];
83296
+ if (!colDims || Object.keys(colDims).length === 0) continue;
83297
+ const dimensions = { ...rowDimensions, ...colDims };
83298
+ const values = {};
83299
+ if (valuePlacements.length <= 1) {
83300
+ values[valueFieldLabels[0] ?? "Value"] = row.values[colIdx] ?? null;
83301
+ } else {
83302
+ const valueIndex = colIdx % valuePlacements.length;
83303
+ values[valueFieldLabels[valueIndex] ?? "Value"] = row.values[colIdx] ?? null;
83304
+ }
83305
+ records.push({ dimensions, values });
83306
+ }
83307
+ } else {
83308
+ const values = {};
83309
+ for (let i = 0; i < valuePlacements.length; i++) {
83310
+ values[valueFieldLabels[i] ?? `Value${i}`] = row.values[i] ?? null;
83311
+ }
83312
+ records.push({ dimensions: rowDimensions, values });
83313
+ }
83314
+ }
83315
+ const filteredRecords = filters ? records.filter((record) => {
83316
+ for (const [field, filterValue] of Object.entries(filters)) {
83317
+ const dimValue = record.dimensions[field];
83318
+ if (Array.isArray(filterValue)) {
83319
+ if (!filterValue.some((fv) => String(fv) === String(dimValue))) return false;
83320
+ } else {
83321
+ if (String(filterValue) !== String(dimValue)) return false;
83322
+ }
83323
+ }
83324
+ return true;
83325
+ }) : records;
83326
+ return {
83327
+ pivotName,
83328
+ rowFields: rowFieldNames,
83329
+ columnFields: colFieldNames,
83330
+ valueFields: valueFieldLabels,
83331
+ records: filteredRecords,
83332
+ sourceRowCount: result.sourceRowCount
83333
+ };
83334
+ }
83212
83335
  // ===========================================================================
83213
83336
  // Expansion State (delegated to PivotExpansionStateProvider)
83214
83337
  // ===========================================================================
@@ -83594,12 +83717,18 @@ async function setPrintArea(ctx, sheetId, area) {
83594
83717
  try {
83595
83718
  const rangeParts = area.split(":");
83596
83719
  if (rangeParts.length !== 2) {
83597
- return { success: false, error: operationFailed("setPrintArea", `Invalid range format: ${area}`) };
83720
+ return {
83721
+ success: false,
83722
+ error: operationFailed("setPrintArea", `Invalid range format: ${area}`)
83723
+ };
83598
83724
  }
83599
83725
  const start = parseCellRef2(rangeParts[0]);
83600
83726
  const end = parseCellRef2(rangeParts[1]);
83601
83727
  if (!start || !end) {
83602
- return { success: false, error: operationFailed("setPrintArea", `Invalid cell reference in range: ${area}`) };
83728
+ return {
83729
+ success: false,
83730
+ error: operationFailed("setPrintArea", `Invalid cell reference in range: ${area}`)
83731
+ };
83603
83732
  }
83604
83733
  const printRange = {
83605
83734
  startRow: start.row,
@@ -83810,10 +83939,10 @@ var WorksheetProtectionImpl = class {
83810
83939
  };
83811
83940
  }
83812
83941
  async getSelectionMode() {
83813
- const options = await this.ctx.computeBridge.getSheetProtectionOptions(this.sheetId);
83814
- if (!options) return "normal";
83815
- const selectLocked = options.selectLockedCells ?? true;
83816
- const selectUnlocked = options.selectUnlockedCells ?? true;
83942
+ const settings = await this.ctx.computeBridge.getSheetSettings(this.sheetId);
83943
+ const opts = settings.protectionOptions;
83944
+ const selectLocked = opts?.selectLockedCells ?? true;
83945
+ const selectUnlocked = opts?.selectUnlockedCells ?? true;
83817
83946
  if (selectLocked && selectUnlocked) return "normal";
83818
83947
  if (!selectLocked && selectUnlocked) return "unlockedOnly";
83819
83948
  return "none";
@@ -83855,11 +83984,15 @@ var WorksheetSettingsImpl = class {
83855
83984
  );
83856
83985
  }
83857
83986
  async getStandardHeight() {
83858
- const settings = await this.ctx.computeBridge.getSheetSettings(this.sheetId);
83987
+ const settings = await this.ctx.computeBridge.getSheetSettings(
83988
+ this.sheetId
83989
+ );
83859
83990
  return settings.defaultRowHeight;
83860
83991
  }
83861
83992
  async getStandardWidth() {
83862
- const settings = await this.ctx.computeBridge.getSheetSettings(this.sheetId);
83993
+ const settings = await this.ctx.computeBridge.getSheetSettings(
83994
+ this.sheetId
83995
+ );
83863
83996
  return settings.defaultColWidth;
83864
83997
  }
83865
83998
  async setStandardWidth(width) {
@@ -83937,9 +84070,7 @@ var WorksheetSlicersImpl = class {
83937
84070
  const columnName = stored.source.columnCellId;
83938
84071
  let absCol = -1;
83939
84072
  if (table.columns.length > 0) {
83940
- const colIndex = table.columns.findIndex(
83941
- (c) => c.name === columnName || c.id === columnName
83942
- );
84073
+ const colIndex = table.columns.findIndex((c) => c.name === columnName || c.id === columnName);
83943
84074
  if (colIndex >= 0) absCol = table.range.startCol + colIndex;
83944
84075
  }
83945
84076
  if (absCol < 0 && table.hasHeaderRow) {
@@ -83976,9 +84107,7 @@ var WorksheetSlicersImpl = class {
83976
84107
  const cell = cellsJson.find((c) => c.row === r);
83977
84108
  columnData.push(extractCellValue2(cell?.value));
83978
84109
  }
83979
- const selectedSet = new Set(
83980
- stored.selectedValues.map((v) => String(v ?? ""))
83981
- );
84110
+ const selectedSet = new Set(stored.selectedValues.map((v) => String(v ?? "")));
83982
84111
  const hasSelection = selectedSet.size > 0 && !(selectedSet.size === 1 && selectedSet.has(""));
83983
84112
  const valueCounts = /* @__PURE__ */ new Map();
83984
84113
  for (const v of columnData) {
@@ -84660,7 +84789,7 @@ init_errors();
84660
84789
 
84661
84790
  // ../../kernel/src/api/worksheet/operations/table-operations.ts
84662
84791
  init_esm_shims();
84663
- function parseA1Range2(range2) {
84792
+ function parseA1Range(range2) {
84664
84793
  const match = range2.match(/^([A-Z]+)(\d+):([A-Z]+)(\d+)$/i);
84665
84794
  if (!match) return null;
84666
84795
  return {
@@ -84698,7 +84827,7 @@ function bridgeTableToTableInfo(table) {
84698
84827
  };
84699
84828
  }
84700
84829
  function getTableColumnDataCellsFromInfo(table, colIndex) {
84701
- const parsed = parseA1Range2(table.range);
84830
+ const parsed = parseA1Range(table.range);
84702
84831
  if (!parsed) return [];
84703
84832
  const dataStartRow = table.hasHeaders ? parsed.startRow + 1 : parsed.startRow;
84704
84833
  const dataEndRow = table.showTotals ? parsed.endRow - 1 : parsed.endRow;
@@ -84712,7 +84841,7 @@ function getTableColumnDataCellsFromInfo(table, colIndex) {
84712
84841
  return cells;
84713
84842
  }
84714
84843
  function getDataBodyRangeFromInfo(table) {
84715
- const parsed = parseA1Range2(table.range);
84844
+ const parsed = parseA1Range(table.range);
84716
84845
  if (!parsed) return null;
84717
84846
  const dataStartRow = table.hasHeaders ? parsed.startRow + 1 : parsed.startRow;
84718
84847
  const dataEndRow = table.showTotals ? parsed.endRow - 1 : parsed.endRow;
@@ -84723,7 +84852,7 @@ function getDataBodyRangeFromInfo(table) {
84723
84852
  }
84724
84853
  function getHeaderRowRangeFromInfo(table) {
84725
84854
  if (!table.hasHeaders) return null;
84726
- const parsed = parseA1Range2(table.range);
84855
+ const parsed = parseA1Range(table.range);
84727
84856
  if (!parsed) return null;
84728
84857
  const startLetter = colToLetter2(parsed.startCol);
84729
84858
  const endLetter = colToLetter2(parsed.endCol);
@@ -84732,7 +84861,7 @@ function getHeaderRowRangeFromInfo(table) {
84732
84861
  }
84733
84862
  function getTotalRowRangeFromInfo(table) {
84734
84863
  if (!table.showTotals) return null;
84735
- const parsed = parseA1Range2(table.range);
84864
+ const parsed = parseA1Range(table.range);
84736
84865
  if (!parsed) return null;
84737
84866
  const startLetter = colToLetter2(parsed.startCol);
84738
84867
  const endLetter = colToLetter2(parsed.endCol);
@@ -84979,16 +85108,13 @@ var WorksheetTablesImpl = class {
84979
85108
  // Row CRUD
84980
85109
  // ---------------------------------------------------------------------------
84981
85110
  async addRow(tableName, index, values) {
84982
- const result = await this.ctx.computeBridge.addTableDataRow(
84983
- tableName,
84984
- index ?? null
84985
- );
85111
+ const result = await this.ctx.computeBridge.addTableDataRow(tableName, index ?? null);
84986
85112
  const insertRow = typeof result.data === "number" ? result.data : parseInt(result.data, 10);
84987
85113
  insertRows(this.ctx, this.sheetId, null, insertRow, 1, "api");
84988
85114
  if (values && values.length > 0) {
84989
85115
  const table = await this.get(tableName);
84990
85116
  if (!table) return;
84991
- const parsed = parseA1Range3(table.range);
85117
+ const parsed = parseA1Range2(table.range);
84992
85118
  if (!parsed) return;
84993
85119
  const edits = values.map((val, i) => ({
84994
85120
  row: insertRow,
@@ -85006,7 +85132,7 @@ var WorksheetTablesImpl = class {
85006
85132
  async getRowCount(tableName) {
85007
85133
  const table = await this.get(tableName);
85008
85134
  if (!table) throw new KernelError("COMPUTE_ERROR", `Table not found: ${tableName}`);
85009
- const parsed = parseA1Range3(table.range);
85135
+ const parsed = parseA1Range2(table.range);
85010
85136
  if (!parsed) return 0;
85011
85137
  const dataStartRow = table.hasHeaders ? parsed.startRow + 1 : parsed.startRow;
85012
85138
  const dataEndRow = table.showTotals ? parsed.endRow - 1 : parsed.endRow;
@@ -85015,7 +85141,7 @@ var WorksheetTablesImpl = class {
85015
85141
  async getRowRange(tableName, index) {
85016
85142
  const table = await this.get(tableName);
85017
85143
  if (!table) throw new KernelError("COMPUTE_ERROR", `Table not found: ${tableName}`);
85018
- const parsed = parseA1Range3(table.range);
85144
+ const parsed = parseA1Range2(table.range);
85019
85145
  if (!parsed) throw new KernelError("COMPUTE_ERROR", `Invalid table range: ${table.range}`);
85020
85146
  const dataStartRow = table.hasHeaders ? parsed.startRow + 1 : parsed.startRow;
85021
85147
  const absRow = dataStartRow + index;
@@ -85026,23 +85152,16 @@ var WorksheetTablesImpl = class {
85026
85152
  async getRowValues(tableName, index) {
85027
85153
  const table = await this.get(tableName);
85028
85154
  if (!table) throw new KernelError("COMPUTE_ERROR", `Table not found: ${tableName}`);
85029
- const parsed = parseA1Range3(table.range);
85155
+ const parsed = parseA1Range2(table.range);
85030
85156
  if (!parsed) return [];
85031
85157
  const dataStartRow = table.hasHeaders ? parsed.startRow + 1 : parsed.startRow;
85032
85158
  const absRow = dataStartRow + index;
85033
- const values = await this.ctx.computeBridge.getCellsInRange(
85034
- this.sheetId,
85035
- absRow,
85036
- parsed.startCol,
85037
- absRow,
85038
- parsed.endCol
85039
- );
85040
- return values;
85159
+ return queryRangeValues(this.ctx, this.sheetId, absRow, parsed.startCol, absRow, parsed.endCol);
85041
85160
  }
85042
85161
  async setRowValues(tableName, index, values) {
85043
85162
  const table = await this.get(tableName);
85044
85163
  if (!table) throw new KernelError("COMPUTE_ERROR", `Table not found: ${tableName}`);
85045
- const parsed = parseA1Range3(table.range);
85164
+ const parsed = parseA1Range2(table.range);
85046
85165
  if (!parsed) return;
85047
85166
  const dataStartRow = table.hasHeaders ? parsed.startRow + 1 : parsed.startRow;
85048
85167
  const absRow = dataStartRow + index;
@@ -85059,7 +85178,7 @@ var WorksheetTablesImpl = class {
85059
85178
  async getColumnDataBodyRange(tableName, columnIndex) {
85060
85179
  const table = await this.get(tableName);
85061
85180
  if (!table) return null;
85062
- const parsed = parseA1Range3(table.range);
85181
+ const parsed = parseA1Range2(table.range);
85063
85182
  if (!parsed) return null;
85064
85183
  const col = parsed.startCol + columnIndex;
85065
85184
  if (col > parsed.endCol) return null;
@@ -85072,7 +85191,7 @@ var WorksheetTablesImpl = class {
85072
85191
  async getColumnHeaderRange(tableName, columnIndex) {
85073
85192
  const table = await this.get(tableName);
85074
85193
  if (!table || !table.hasHeaders) return null;
85075
- const parsed = parseA1Range3(table.range);
85194
+ const parsed = parseA1Range2(table.range);
85076
85195
  if (!parsed) return null;
85077
85196
  const col = parsed.startCol + columnIndex;
85078
85197
  if (col > parsed.endCol) return null;
@@ -85083,7 +85202,7 @@ var WorksheetTablesImpl = class {
85083
85202
  async getColumnRange(tableName, columnIndex) {
85084
85203
  const table = await this.get(tableName);
85085
85204
  if (!table) return null;
85086
- const parsed = parseA1Range3(table.range);
85205
+ const parsed = parseA1Range2(table.range);
85087
85206
  if (!parsed) return null;
85088
85207
  const col = parsed.startCol + columnIndex;
85089
85208
  if (col > parsed.endCol) return null;
@@ -85093,7 +85212,7 @@ var WorksheetTablesImpl = class {
85093
85212
  async getColumnTotalRange(tableName, columnIndex) {
85094
85213
  const table = await this.get(tableName);
85095
85214
  if (!table || !table.showTotals) return null;
85096
- const parsed = parseA1Range3(table.range);
85215
+ const parsed = parseA1Range2(table.range);
85097
85216
  if (!parsed) return null;
85098
85217
  const col = parsed.startCol + columnIndex;
85099
85218
  if (col > parsed.endCol) return null;
@@ -85104,26 +85223,19 @@ var WorksheetTablesImpl = class {
85104
85223
  async getColumnValues(tableName, columnIndex) {
85105
85224
  const table = await this.get(tableName);
85106
85225
  if (!table) throw new KernelError("COMPUTE_ERROR", `Table not found: ${tableName}`);
85107
- const parsed = parseA1Range3(table.range);
85226
+ const parsed = parseA1Range2(table.range);
85108
85227
  if (!parsed) return [];
85109
85228
  const col = parsed.startCol + columnIndex;
85110
85229
  if (col > parsed.endCol) return [];
85111
85230
  const dataStartRow = table.hasHeaders ? parsed.startRow + 1 : parsed.startRow;
85112
85231
  const dataEndRow = table.showTotals ? parsed.endRow - 1 : parsed.endRow;
85113
85232
  if (dataStartRow > dataEndRow) return [];
85114
- const values = await this.ctx.computeBridge.getCellsInRange(
85115
- this.sheetId,
85116
- dataStartRow,
85117
- col,
85118
- dataEndRow,
85119
- col
85120
- );
85121
- return values;
85233
+ return queryRangeValues(this.ctx, this.sheetId, dataStartRow, col, dataEndRow, col);
85122
85234
  }
85123
85235
  async setColumnValues(tableName, columnIndex, values) {
85124
85236
  const table = await this.get(tableName);
85125
85237
  if (!table) throw new KernelError("COMPUTE_ERROR", `Table not found: ${tableName}`);
85126
- const parsed = parseA1Range3(table.range);
85238
+ const parsed = parseA1Range2(table.range);
85127
85239
  if (!parsed) return;
85128
85240
  const col = parsed.startCol + columnIndex;
85129
85241
  if (col > parsed.endCol) return;
@@ -85141,25 +85253,30 @@ var WorksheetTablesImpl = class {
85141
85253
  async sortApply(tableName, fields) {
85142
85254
  const table = await this.get(tableName);
85143
85255
  if (!table) throw new KernelError("COMPUTE_ERROR", `Table not found: ${tableName}`);
85144
- const parsed = parseA1Range3(table.range);
85256
+ const parsed = parseA1Range2(table.range);
85145
85257
  if (!parsed) return;
85146
85258
  const dataStartRow = table.hasHeaders ? parsed.startRow + 1 : parsed.startRow;
85147
85259
  const dataEndRow = table.showTotals ? parsed.endRow - 1 : parsed.endRow;
85148
85260
  if (dataStartRow > dataEndRow) return;
85149
85261
  const numCols = parsed.endCol - parsed.startCol + 1;
85150
85262
  const numRows = dataEndRow - dataStartRow + 1;
85151
- const rawValues = await this.ctx.computeBridge.getCellsInRange(
85263
+ const rangeResult = await this.ctx.computeBridge.queryRange(
85152
85264
  this.sheetId,
85153
85265
  dataStartRow,
85154
85266
  parsed.startCol,
85155
85267
  dataEndRow,
85156
85268
  parsed.endCol
85157
85269
  );
85270
+ const cellMap = /* @__PURE__ */ new Map();
85271
+ for (const cell of rangeResult.cells) {
85272
+ cellMap.set(`${cell.row},${cell.col}`, cell);
85273
+ }
85158
85274
  const rows = [];
85159
85275
  for (let r = 0; r < numRows; r++) {
85160
85276
  const row = [];
85161
85277
  for (let c = 0; c < numCols; c++) {
85162
- row.push(rawValues[r * numCols + c] ?? "");
85278
+ const cell = cellMap.get(`${dataStartRow + r},${parsed.startCol + c}`);
85279
+ row.push(cell?.value ?? null);
85163
85280
  }
85164
85281
  rows.push(row);
85165
85282
  }
@@ -85185,10 +85302,11 @@ var WorksheetTablesImpl = class {
85185
85302
  for (let r = 0; r < numRows; r++) {
85186
85303
  const srcRow = rows[indices[r]];
85187
85304
  for (let c = 0; c < numCols; c++) {
85305
+ const val = srcRow[c];
85188
85306
  edits.push({
85189
85307
  row: dataStartRow + r,
85190
85308
  col: parsed.startCol + c,
85191
- input: srcRow[c]
85309
+ input: val == null ? "" : String(val)
85192
85310
  });
85193
85311
  }
85194
85312
  }
@@ -85204,7 +85322,7 @@ function letterToCol2(letters) {
85204
85322
  }
85205
85323
  return col - 1;
85206
85324
  }
85207
- function parseA1Range3(range2) {
85325
+ function parseA1Range2(range2) {
85208
85326
  const match = range2.match(/^([A-Z]+)(\d+):([A-Z]+)(\d+)$/i);
85209
85327
  if (!match) return null;
85210
85328
  return {
@@ -85214,6 +85332,27 @@ function parseA1Range3(range2) {
85214
85332
  endRow: parseInt(match[4], 10) - 1
85215
85333
  };
85216
85334
  }
85335
+ async function queryRangeValues(ctx, sheetId, startRow, startCol, endRow, endCol) {
85336
+ const rangeResult = await ctx.computeBridge.queryRange(
85337
+ sheetId,
85338
+ startRow,
85339
+ startCol,
85340
+ endRow,
85341
+ endCol
85342
+ );
85343
+ const cellMap = /* @__PURE__ */ new Map();
85344
+ for (const cell of rangeResult.cells) {
85345
+ cellMap.set(`${cell.row},${cell.col}`, cell);
85346
+ }
85347
+ const values = [];
85348
+ for (let r = startRow; r <= endRow; r++) {
85349
+ for (let c = startCol; c <= endCol; c++) {
85350
+ const cell = cellMap.get(`${r},${c}`);
85351
+ values.push(cell?.value ?? null);
85352
+ }
85353
+ }
85354
+ return values;
85355
+ }
85217
85356
 
85218
85357
  // ../../kernel/src/api/worksheet/validation.ts
85219
85358
  init_esm_shims();
@@ -87649,6 +87788,16 @@ var WorksheetImpl = class {
87649
87788
  const formula = await getFormula(this.ctx, this.sheetId, row, col);
87650
87789
  return formula ?? null;
87651
87790
  }
87791
+ async getFormulas(range2) {
87792
+ const bounds = resolveRange(range2);
87793
+ return getRangeFormulas(this.ctx, this.sheetId, {
87794
+ sheetId: this.sheetId,
87795
+ startRow: bounds.startRow,
87796
+ startCol: bounds.startCol,
87797
+ endRow: bounds.endRow,
87798
+ endCol: bounds.endCol
87799
+ });
87800
+ }
87652
87801
  // ===========================================================================
87653
87802
  // Bulk reads
87654
87803
  // ===========================================================================
@@ -87724,13 +87873,10 @@ var WorksheetImpl = class {
87724
87873
  const { row, col } = resolveCell(address);
87725
87874
  const data = await getCell(this.ctx, this.sheetId, row, col);
87726
87875
  if (!data) return "";
87727
- const displayValue = await getDisplayValue2(this.ctx, this.sheetId, row, col);
87728
- let result = displayValue;
87876
+ const rawValue = viewportCellValueToString(data.value);
87877
+ let result = rawValue;
87729
87878
  if (data.formula) {
87730
- result = displayValue !== "" ? `${displayValue}(${data.formula})` : `(${data.formula})`;
87731
- }
87732
- if (data.value === 0 && displayValue !== "0" && displayValue !== "") {
87733
- result = `${result} [0]`;
87879
+ result = rawValue !== "" ? `${rawValue}(${data.formula})` : `(${data.formula})`;
87734
87880
  }
87735
87881
  const styleHintsStr = await getStyleHints(this.ctx, this.sheetId, row, col);
87736
87882
  if (styleHintsStr) {
@@ -87792,8 +87938,8 @@ var WorksheetImpl = class {
87792
87938
  rowValues.push(`${cellAddr}:`);
87793
87939
  continue;
87794
87940
  }
87795
- const displayValue = vc.formatted ?? viewportCellValueToString(vc.value);
87796
- let cellStr = displayValue;
87941
+ const rawValue = viewportCellValueToString(vc.value);
87942
+ let cellStr = rawValue;
87797
87943
  hasContent = true;
87798
87944
  if (vc.formula) {
87799
87945
  const abbreviation = formulaAnalysis.formulaToId.get(`${row},${col}`);
@@ -87803,10 +87949,6 @@ var WorksheetImpl = class {
87803
87949
  cellStr = `${cellStr}(=${vc.formula})`;
87804
87950
  }
87805
87951
  }
87806
- const cellValue = viewportCellValueToCellValue(vc.value);
87807
- if (cellValue === 0 && displayValue !== "0" && displayValue !== "") {
87808
- cellStr = `${cellStr} [0]`;
87809
- }
87810
87952
  rowValues.push(`${cellAddr}:${cellStr}`);
87811
87953
  }
87812
87954
  if (hasContent) {
@@ -87963,12 +88105,12 @@ var WorksheetImpl = class {
87963
88105
  cells.sort((a, b) => a.col - b.col);
87964
88106
  const rowData = [];
87965
88107
  for (const vc of cells) {
87966
- const displayValue = vc.formatted ?? viewportCellValueToString(vc.value);
88108
+ const rawValue = viewportCellValueToString(vc.value);
87967
88109
  const addr = toA1(vc.row, vc.col);
87968
88110
  if (vc.formula) {
87969
- rowData.push(`${addr}:${displayValue}(=${vc.formula})`);
88111
+ rowData.push(`${addr}:${rawValue}(=${vc.formula})`);
87970
88112
  } else {
87971
- rowData.push(`${addr}:${displayValue}`);
88113
+ rowData.push(`${addr}:${rawValue}`);
87972
88114
  }
87973
88115
  }
87974
88116
  if (rowData.length > 0) {
@@ -88018,18 +88160,31 @@ var WorksheetImpl = class {
88018
88160
  async findInRange(range2, text, options) {
88019
88161
  const parsed = parseCellRange(range2);
88020
88162
  if (!parsed) throw new KernelError("COMPUTE_ERROR", `Invalid range: "${range2}"`);
88021
- return findInRange(this.ctx, this.sheetId, { sheetId: this.sheetId, ...parsed }, text, {
88022
- caseSensitive: options?.matchCase,
88023
- wholeCell: options?.entireCell
88024
- });
88163
+ return findInRange(
88164
+ this.ctx,
88165
+ this.sheetId,
88166
+ { sheetId: this.sheetId, ...parsed },
88167
+ text,
88168
+ {
88169
+ caseSensitive: options?.matchCase,
88170
+ wholeCell: options?.entireCell
88171
+ }
88172
+ );
88025
88173
  }
88026
88174
  async replaceAll(range2, text, replacement, options) {
88027
88175
  const parsed = parseCellRange(range2);
88028
88176
  if (!parsed) throw new KernelError("COMPUTE_ERROR", `Invalid range: "${range2}"`);
88029
- return replaceAll(this.ctx, this.sheetId, { sheetId: this.sheetId, ...parsed }, text, replacement, {
88030
- caseSensitive: options?.matchCase,
88031
- wholeCell: options?.entireCell
88032
- });
88177
+ return replaceAll(
88178
+ this.ctx,
88179
+ this.sheetId,
88180
+ { sheetId: this.sheetId, ...parsed },
88181
+ text,
88182
+ replacement,
88183
+ {
88184
+ caseSensitive: options?.matchCase,
88185
+ wholeCell: options?.entireCell
88186
+ }
88187
+ );
88033
88188
  }
88034
88189
  async getExtendedRange(range2, direction, activeCell) {
88035
88190
  const parsed = parseCellRange(range2);
@@ -88052,17 +88207,26 @@ var WorksheetImpl = class {
88052
88207
  async getDisplayText(range2) {
88053
88208
  const parsed = parseCellRange(range2);
88054
88209
  if (!parsed) throw new KernelError("COMPUTE_ERROR", `Invalid range: "${range2}"`);
88055
- return getDisplayText(this.ctx, this.sheetId, { sheetId: this.sheetId, ...parsed });
88210
+ return getDisplayText(this.ctx, this.sheetId, {
88211
+ sheetId: this.sheetId,
88212
+ ...parsed
88213
+ });
88056
88214
  }
88057
88215
  async getValueTypes(range2) {
88058
88216
  const parsed = parseCellRange(range2);
88059
88217
  if (!parsed) throw new KernelError("COMPUTE_ERROR", `Invalid range: "${range2}"`);
88060
- return getValueTypes(this.ctx, this.sheetId, { sheetId: this.sheetId, ...parsed });
88218
+ return getValueTypes(this.ctx, this.sheetId, {
88219
+ sheetId: this.sheetId,
88220
+ ...parsed
88221
+ });
88061
88222
  }
88062
88223
  async getNumberFormatCategories(range2) {
88063
88224
  const parsed = parseCellRange(range2);
88064
88225
  if (!parsed) throw new KernelError("COMPUTE_ERROR", `Invalid range: "${range2}"`);
88065
- return getNumberFormatCategories(this.ctx, this.sheetId, { sheetId: this.sheetId, ...parsed });
88226
+ return getNumberFormatCategories(this.ctx, this.sheetId, {
88227
+ sheetId: this.sheetId,
88228
+ ...parsed
88229
+ });
88066
88230
  }
88067
88231
  // ===========================================================================
88068
88232
  // Sort / batch / autofill
@@ -88106,11 +88270,8 @@ var WorksheetImpl = class {
88106
88270
  if (!cellRange) throw new KernelError("COMPUTE_ERROR", `Invalid range: "${range2}"`);
88107
88271
  return fillSeries(this.ctx, this.sheetId, cellRange, options);
88108
88272
  }
88109
- async batchSetCells(updates) {
88110
- await batchSetCells(this.ctx, this.sheetId, updates);
88111
- }
88112
- async batchSetFormulas(updates) {
88113
- await batchSetFormulas(this.ctx, this.sheetId, updates);
88273
+ async setCells(cells) {
88274
+ return setCells(this.ctx, this.sheetId, cells);
88114
88275
  }
88115
88276
  // ===========================================================================
88116
88277
  // One-liner table creation
@@ -88256,11 +88417,21 @@ var WorksheetImpl = class {
88256
88417
  const sheetId = this.sheetId;
88257
88418
  const targetPos = resolveCell(targetCell);
88258
88419
  const changingPos = resolveCell(changingCell);
88259
- const formulaCellId = await getCellIdAt2(this.ctx, sheetId, targetPos.row, targetPos.col);
88420
+ const formulaCellId = await getCellIdAt2(
88421
+ this.ctx,
88422
+ sheetId,
88423
+ targetPos.row,
88424
+ targetPos.col
88425
+ );
88260
88426
  if (!formulaCellId) {
88261
88427
  throw new KernelError("COMPUTE_ERROR", `Target cell ${targetCell} has no content.`);
88262
88428
  }
88263
- const inputCellId = await getCellIdAt2(this.ctx, sheetId, changingPos.row, changingPos.col);
88429
+ const inputCellId = await getCellIdAt2(
88430
+ this.ctx,
88431
+ sheetId,
88432
+ changingPos.row,
88433
+ changingPos.col
88434
+ );
88264
88435
  if (!inputCellId) {
88265
88436
  throw new KernelError("COMPUTE_ERROR", `Changing cell ${changingCell} has no content.`);
88266
88437
  }
@@ -89799,18 +89970,42 @@ var STATISTICAL_FUNCTIONS = [
89799
89970
  ["BETAINV", C.STATISTICAL, "Returns the inverse of the beta distribution (compatibility)", 3, 5],
89800
89971
  ["BINOM.DIST", C.STATISTICAL, "Returns the binomial distribution probability", 4, 4],
89801
89972
  ["BINOM.DIST.RANGE", C.STATISTICAL, "Returns the binomial distribution probability range", 3, 4],
89802
- ["BINOM.INV", C.STATISTICAL, "Returns the smallest value for which the binomial CDF is >= criterion", 3, 3],
89973
+ [
89974
+ "BINOM.INV",
89975
+ C.STATISTICAL,
89976
+ "Returns the smallest value for which the binomial CDF is >= criterion",
89977
+ 3,
89978
+ 3
89979
+ ],
89803
89980
  ["BINOMDIST", C.STATISTICAL, "Returns the binomial distribution (compatibility)", 4, 4],
89804
89981
  ["CHIDIST", C.STATISTICAL, "Returns the chi-squared distribution (compatibility)", 2, 2],
89805
- ["CHIINV", C.STATISTICAL, "Returns the inverse of the chi-squared distribution (compatibility)", 2, 2],
89982
+ [
89983
+ "CHIINV",
89984
+ C.STATISTICAL,
89985
+ "Returns the inverse of the chi-squared distribution (compatibility)",
89986
+ 2,
89987
+ 2
89988
+ ],
89806
89989
  ["CHISQ.DIST", C.STATISTICAL, "Returns the chi-squared distribution", 3, 3],
89807
89990
  ["CHISQ.DIST.RT", C.STATISTICAL, "Returns the right-tailed chi-squared distribution", 2, 2],
89808
89991
  ["CHISQ.INV", C.STATISTICAL, "Returns the inverse of the chi-squared distribution", 2, 2],
89809
- ["CHISQ.INV.RT", C.STATISTICAL, "Returns the inverse of the right-tailed chi-squared distribution", 2, 2],
89992
+ [
89993
+ "CHISQ.INV.RT",
89994
+ C.STATISTICAL,
89995
+ "Returns the inverse of the right-tailed chi-squared distribution",
89996
+ 2,
89997
+ 2
89998
+ ],
89810
89999
  ["CHISQ.TEST", C.STATISTICAL, "Returns the chi-squared test statistic", 2, 2],
89811
90000
  ["CHITEST", C.STATISTICAL, "Returns the chi-squared test (compatibility)", 2, 2],
89812
90001
  ["CONFIDENCE", C.STATISTICAL, "Returns the confidence interval (compatibility)", 3, 3],
89813
- ["CONFIDENCE.NORM", C.STATISTICAL, "Returns the confidence interval using a normal distribution", 3, 3],
90002
+ [
90003
+ "CONFIDENCE.NORM",
90004
+ C.STATISTICAL,
90005
+ "Returns the confidence interval using a normal distribution",
90006
+ 3,
90007
+ 3
90008
+ ],
89814
90009
  ["CONFIDENCE.T", C.STATISTICAL, "Returns the confidence interval using a t-distribution", 3, 3],
89815
90010
  ["CORREL", C.STATISTICAL, "Returns the correlation coefficient between two data sets", 2, 2],
89816
90011
  ["COVAR", C.STATISTICAL, "Returns covariance (compatibility)", 2, 2],
@@ -89833,7 +90028,13 @@ var STATISTICAL_FUNCTIONS = [
89833
90028
  ["FORECAST.ETS", C.STATISTICAL, "Returns a forecasted value using exponential smoothing", 3, 7],
89834
90029
  ["FORECAST.ETS.CONFINT", C.STATISTICAL, "Returns a confidence interval for a forecast", 3, 7],
89835
90030
  ["FORECAST.ETS.SEASONALITY", C.STATISTICAL, "Returns the seasonal pattern length", 2, 4],
89836
- ["FORECAST.ETS.STAT", C.STATISTICAL, "Returns a statistical value for a time series forecast", 3, 7],
90031
+ [
90032
+ "FORECAST.ETS.STAT",
90033
+ C.STATISTICAL,
90034
+ "Returns a statistical value for a time series forecast",
90035
+ 3,
90036
+ 7
90037
+ ],
89837
90038
  ["FORECAST.LINEAR", C.STATISTICAL, "Returns a value along a linear trend", 3, 3],
89838
90039
  ["FREQUENCY", C.STATISTICAL, "Returns a frequency distribution as a vertical array", 2, 2],
89839
90040
  ["FTEST", C.STATISTICAL, "Returns the F-test (compatibility)", 2, 2],
@@ -89841,10 +90042,22 @@ var STATISTICAL_FUNCTIONS = [
89841
90042
  ["GAMMA.DIST", C.STATISTICAL, "Returns the gamma distribution", 4, 4],
89842
90043
  ["GAMMA.INV", C.STATISTICAL, "Returns the inverse of the gamma distribution", 3, 3],
89843
90044
  ["GAMMADIST", C.STATISTICAL, "Returns the gamma distribution (compatibility)", 4, 4],
89844
- ["GAMMAINV", C.STATISTICAL, "Returns the inverse of the gamma distribution (compatibility)", 3, 3],
90045
+ [
90046
+ "GAMMAINV",
90047
+ C.STATISTICAL,
90048
+ "Returns the inverse of the gamma distribution (compatibility)",
90049
+ 3,
90050
+ 3
90051
+ ],
89845
90052
  ["GAMMALN", C.STATISTICAL, "Returns the natural logarithm of the gamma function", 1, 1],
89846
90053
  ["GAMMALN.PRECISE", C.STATISTICAL, "Returns the natural logarithm of the gamma function", 1, 1],
89847
- ["GAUSS", C.STATISTICAL, "Returns 0.5 less than the standard normal cumulative distribution", 1, 1],
90054
+ [
90055
+ "GAUSS",
90056
+ C.STATISTICAL,
90057
+ "Returns 0.5 less than the standard normal cumulative distribution",
90058
+ 1,
90059
+ 1
90060
+ ],
89848
90061
  ["GEOMEAN", C.STATISTICAL, "Returns the geometric mean", 1, -1],
89849
90062
  ["GROWTH", C.STATISTICAL, "Returns values along an exponential trend", 1, 4],
89850
90063
  ["HARMEAN", C.STATISTICAL, "Returns the harmonic mean", 1, -1],
@@ -89854,24 +90067,54 @@ var STATISTICAL_FUNCTIONS = [
89854
90067
  ["KURT", C.STATISTICAL, "Returns the kurtosis of a data set", 1, -1],
89855
90068
  ["LINEST", C.STATISTICAL, "Returns the parameters of a linear trend", 1, 4],
89856
90069
  ["LOGEST", C.STATISTICAL, "Returns the parameters of an exponential trend", 1, 4],
89857
- ["LOGINV", C.STATISTICAL, "Returns the inverse of the lognormal distribution (compatibility)", 3, 3],
90070
+ [
90071
+ "LOGINV",
90072
+ C.STATISTICAL,
90073
+ "Returns the inverse of the lognormal distribution (compatibility)",
90074
+ 3,
90075
+ 3
90076
+ ],
89858
90077
  ["LOGNORM.DIST", C.STATISTICAL, "Returns the lognormal distribution", 4, 4],
89859
90078
  ["LOGNORM.INV", C.STATISTICAL, "Returns the inverse of the lognormal distribution", 3, 3],
89860
90079
  ["LOGNORMDIST", C.STATISTICAL, "Returns the lognormal distribution (compatibility)", 3, 3],
89861
90080
  ["MAXA", C.STATISTICAL, "Returns the maximum value including text and logical values", 1, -1],
89862
90081
  ["MINA", C.STATISTICAL, "Returns the minimum value including text and logical values", 1, -1],
89863
90082
  ["MODE", C.STATISTICAL, "Returns the most common value (compatibility)", 1, -1],
89864
- ["MODE.MULT", C.STATISTICAL, "Returns a vertical array of the most frequently occurring values", 1, -1],
90083
+ [
90084
+ "MODE.MULT",
90085
+ C.STATISTICAL,
90086
+ "Returns a vertical array of the most frequently occurring values",
90087
+ 1,
90088
+ -1
90089
+ ],
89865
90090
  ["NEGBINOM.DIST", C.STATISTICAL, "Returns the negative binomial distribution", 4, 4],
89866
- ["NEGBINOMDIST", C.STATISTICAL, "Returns the negative binomial distribution (compatibility)", 3, 3],
90091
+ [
90092
+ "NEGBINOMDIST",
90093
+ C.STATISTICAL,
90094
+ "Returns the negative binomial distribution (compatibility)",
90095
+ 3,
90096
+ 3
90097
+ ],
89867
90098
  ["NORM.DIST", C.STATISTICAL, "Returns the normal distribution", 4, 4],
89868
90099
  ["NORM.INV", C.STATISTICAL, "Returns the inverse of the normal distribution", 3, 3],
89869
90100
  ["NORM.S.DIST", C.STATISTICAL, "Returns the standard normal distribution", 2, 2],
89870
90101
  ["NORM.S.INV", C.STATISTICAL, "Returns the inverse of the standard normal distribution", 1, 1],
89871
90102
  ["NORMDIST", C.STATISTICAL, "Returns the normal distribution (compatibility)", 4, 4],
89872
- ["NORMINV", C.STATISTICAL, "Returns the inverse of the normal distribution (compatibility)", 3, 3],
90103
+ [
90104
+ "NORMINV",
90105
+ C.STATISTICAL,
90106
+ "Returns the inverse of the normal distribution (compatibility)",
90107
+ 3,
90108
+ 3
90109
+ ],
89873
90110
  ["NORMSDIST", C.STATISTICAL, "Returns the standard normal distribution (compatibility)", 1, 1],
89874
- ["NORMSINV", C.STATISTICAL, "Returns the inverse of the standard normal distribution (compatibility)", 1, 1],
90111
+ [
90112
+ "NORMSINV",
90113
+ C.STATISTICAL,
90114
+ "Returns the inverse of the standard normal distribution (compatibility)",
90115
+ 1,
90116
+ 1
90117
+ ],
89875
90118
  ["PEARSON", C.STATISTICAL, "Returns the Pearson product moment correlation coefficient", 2, 2],
89876
90119
  ["PERCENTILE", C.STATISTICAL, "Returns the k-th percentile of values (compatibility)", 2, 2],
89877
90120
  ["PERCENTILE.EXC", C.STATISTICAL, "Returns the k-th percentile (exclusive)", 2, 2],
@@ -89879,7 +90122,13 @@ var STATISTICAL_FUNCTIONS = [
89879
90122
  ["PERCENTRANK", C.STATISTICAL, "Returns the percentage rank (compatibility)", 2, 3],
89880
90123
  ["PERCENTRANK.EXC", C.STATISTICAL, "Returns the percentage rank (exclusive)", 2, 3],
89881
90124
  ["PERCENTRANK.INC", C.STATISTICAL, "Returns the percentage rank (inclusive)", 2, 3],
89882
- ["PHI", C.STATISTICAL, "Returns the value of the density function for a standard normal distribution", 1, 1],
90125
+ [
90126
+ "PHI",
90127
+ C.STATISTICAL,
90128
+ "Returns the value of the density function for a standard normal distribution",
90129
+ 1,
90130
+ 1
90131
+ ],
89883
90132
  ["POISSON", C.STATISTICAL, "Returns the Poisson distribution (compatibility)", 3, 3],
89884
90133
  ["POISSON.DIST", C.STATISTICAL, "Returns the Poisson distribution", 3, 3],
89885
90134
  ["PROB", C.STATISTICAL, "Returns the probability of values in a range", 3, 4],
@@ -89897,9 +90146,27 @@ var STATISTICAL_FUNCTIONS = [
89897
90146
  ["STDEV", C.STATISTICAL, "Estimates standard deviation based on a sample (compatibility)", 1, -1],
89898
90147
  ["STDEV.P", C.STATISTICAL, "Calculates standard deviation based on the entire population", 1, -1],
89899
90148
  ["STDEV.S", C.STATISTICAL, "Estimates standard deviation based on a sample", 1, -1],
89900
- ["STDEVA", C.STATISTICAL, "Estimates standard deviation including text and logical values", 1, -1],
89901
- ["STDEVP", C.STATISTICAL, "Calculates standard deviation based on the entire population (compatibility)", 1, -1],
89902
- ["STDEVPA", C.STATISTICAL, "Calculates standard deviation of a population including text and logical values", 1, -1],
90149
+ [
90150
+ "STDEVA",
90151
+ C.STATISTICAL,
90152
+ "Estimates standard deviation including text and logical values",
90153
+ 1,
90154
+ -1
90155
+ ],
90156
+ [
90157
+ "STDEVP",
90158
+ C.STATISTICAL,
90159
+ "Calculates standard deviation based on the entire population (compatibility)",
90160
+ 1,
90161
+ -1
90162
+ ],
90163
+ [
90164
+ "STDEVPA",
90165
+ C.STATISTICAL,
90166
+ "Calculates standard deviation of a population including text and logical values",
90167
+ 1,
90168
+ -1
90169
+ ],
89903
90170
  ["STEYX", C.STATISTICAL, "Returns the standard error of the predicted y-value", 2, 2],
89904
90171
  ["T.DIST", C.STATISTICAL, "Returns the Student t-distribution", 3, 3],
89905
90172
  ["T.DIST.2T", C.STATISTICAL, "Returns the two-tailed Student t-distribution", 2, 2],
@@ -89908,7 +90175,13 @@ var STATISTICAL_FUNCTIONS = [
89908
90175
  ["T.INV.2T", C.STATISTICAL, "Returns the inverse of the two-tailed Student t-distribution", 2, 2],
89909
90176
  ["T.TEST", C.STATISTICAL, "Returns the t-test statistic", 4, 4],
89910
90177
  ["TDIST", C.STATISTICAL, "Returns the Student t-distribution (compatibility)", 3, 3],
89911
- ["TINV", C.STATISTICAL, "Returns the inverse of the Student t-distribution (compatibility)", 2, 2],
90178
+ [
90179
+ "TINV",
90180
+ C.STATISTICAL,
90181
+ "Returns the inverse of the Student t-distribution (compatibility)",
90182
+ 2,
90183
+ 2
90184
+ ],
89912
90185
  ["TREND", C.STATISTICAL, "Returns values along a linear trend", 1, 4],
89913
90186
  ["TRIMMEAN", C.STATISTICAL, "Returns the mean of the interior of a data set", 2, 2],
89914
90187
  ["TTEST", C.STATISTICAL, "Returns the t-test (compatibility)", 4, 4],
@@ -89916,8 +90189,20 @@ var STATISTICAL_FUNCTIONS = [
89916
90189
  ["VAR.P", C.STATISTICAL, "Calculates variance based on the entire population", 1, -1],
89917
90190
  ["VAR.S", C.STATISTICAL, "Estimates variance based on a sample", 1, -1],
89918
90191
  ["VARA", C.STATISTICAL, "Estimates variance including text and logical values", 1, -1],
89919
- ["VARP", C.STATISTICAL, "Calculates variance based on the entire population (compatibility)", 1, -1],
89920
- ["VARPA", C.STATISTICAL, "Calculates variance of a population including text and logical values", 1, -1],
90192
+ [
90193
+ "VARP",
90194
+ C.STATISTICAL,
90195
+ "Calculates variance based on the entire population (compatibility)",
90196
+ 1,
90197
+ -1
90198
+ ],
90199
+ [
90200
+ "VARPA",
90201
+ C.STATISTICAL,
90202
+ "Calculates variance of a population including text and logical values",
90203
+ 1,
90204
+ -1
90205
+ ],
89921
90206
  ["WEIBULL", C.STATISTICAL, "Returns the Weibull distribution (compatibility)", 4, 4],
89922
90207
  ["WEIBULL.DIST", C.STATISTICAL, "Returns the Weibull distribution", 4, 4],
89923
90208
  ["Z.TEST", C.STATISTICAL, "Returns the one-tailed P-value of a z-test", 2, 3],
@@ -89925,37 +90210,103 @@ var STATISTICAL_FUNCTIONS = [
89925
90210
  ];
89926
90211
  var DATETIME_FUNCTIONS = [
89927
90212
  ["DATE", C.DATE_TIME, "Returns the serial number of a particular date", 3, 3],
89928
- ["DATEDIF", C.DATE_TIME, "Calculates the number of days, months, or years between two dates", 3, 3],
90213
+ [
90214
+ "DATEDIF",
90215
+ C.DATE_TIME,
90216
+ "Calculates the number of days, months, or years between two dates",
90217
+ 3,
90218
+ 3
90219
+ ],
89929
90220
  ["DATEVALUE", C.DATE_TIME, "Converts a date in text format to a serial number", 1, 1],
89930
90221
  ["DAY", C.DATE_TIME, "Converts a serial number to a day of the month", 1, 1],
89931
90222
  ["DAYS", C.DATE_TIME, "Returns the number of days between two dates", 2, 2],
89932
- ["DAYS360", C.DATE_TIME, "Calculates the number of days between two dates on a 360-day year", 2, 3],
89933
- ["EDATE", C.DATE_TIME, "Returns the serial number of a date that is a given number of months before or after the start date", 2, 2],
90223
+ [
90224
+ "DAYS360",
90225
+ C.DATE_TIME,
90226
+ "Calculates the number of days between two dates on a 360-day year",
90227
+ 2,
90228
+ 3
90229
+ ],
90230
+ [
90231
+ "EDATE",
90232
+ C.DATE_TIME,
90233
+ "Returns the serial number of a date that is a given number of months before or after the start date",
90234
+ 2,
90235
+ 2
90236
+ ],
89934
90237
  ["EOMONTH", C.DATE_TIME, "Returns the serial number of the last day of the month", 2, 2],
89935
90238
  ["HOUR", C.DATE_TIME, "Converts a serial number to an hour", 1, 1],
89936
90239
  ["ISOWEEKNUM", C.DATE_TIME, "Returns the ISO week number of the year", 1, 1],
89937
90240
  ["MINUTE", C.DATE_TIME, "Converts a serial number to a minute", 1, 1],
89938
90241
  ["MONTH", C.DATE_TIME, "Converts a serial number to a month", 1, 1],
89939
90242
  ["NETWORKDAYS", C.DATE_TIME, "Returns the number of whole workdays between two dates", 2, 3],
89940
- ["NETWORKDAYS.INTL", C.DATE_TIME, "Returns the number of whole workdays between two dates (custom weekends)", 2, 4],
90243
+ [
90244
+ "NETWORKDAYS.INTL",
90245
+ C.DATE_TIME,
90246
+ "Returns the number of whole workdays between two dates (custom weekends)",
90247
+ 2,
90248
+ 4
90249
+ ],
89941
90250
  ["SECOND", C.DATE_TIME, "Converts a serial number to a second", 1, 1],
89942
90251
  ["TIME", C.DATE_TIME, "Returns the serial number of a particular time", 3, 3],
89943
90252
  ["TIMEVALUE", C.DATE_TIME, "Converts a time in text format to a serial number", 1, 1],
89944
90253
  ["WEEKDAY", C.DATE_TIME, "Converts a serial number to a day of the week", 1, 2],
89945
90254
  ["WEEKNUM", C.DATE_TIME, "Returns the week number of the year", 1, 2],
89946
- ["WORKDAY", C.DATE_TIME, "Returns a date that is a given number of workdays before or after", 2, 3],
89947
- ["WORKDAY.INTL", C.DATE_TIME, "Returns a date that is a given number of workdays before or after (custom weekends)", 2, 4],
90255
+ [
90256
+ "WORKDAY",
90257
+ C.DATE_TIME,
90258
+ "Returns a date that is a given number of workdays before or after",
90259
+ 2,
90260
+ 3
90261
+ ],
90262
+ [
90263
+ "WORKDAY.INTL",
90264
+ C.DATE_TIME,
90265
+ "Returns a date that is a given number of workdays before or after (custom weekends)",
90266
+ 2,
90267
+ 4
90268
+ ],
89948
90269
  ["YEAR", C.DATE_TIME, "Converts a serial number to a year", 1, 1],
89949
- ["YEARFRAC", C.DATE_TIME, "Returns the year fraction representing the number of whole days", 2, 3]
90270
+ [
90271
+ "YEARFRAC",
90272
+ C.DATE_TIME,
90273
+ "Returns the year fraction representing the number of whole days",
90274
+ 2,
90275
+ 3
90276
+ ]
89950
90277
  ];
89951
90278
  var FINANCIAL_FUNCTIONS = [
89952
90279
  ["ACCRINT", C.FINANCIAL, "Returns the accrued interest for a security", 6, 8],
89953
- ["ACCRINTM", C.FINANCIAL, "Returns the accrued interest for a security that pays at maturity", 3, 5],
90280
+ [
90281
+ "ACCRINTM",
90282
+ C.FINANCIAL,
90283
+ "Returns the accrued interest for a security that pays at maturity",
90284
+ 3,
90285
+ 5
90286
+ ],
89954
90287
  ["AMORDEGRC", C.FINANCIAL, "Returns the depreciation for each accounting period (French)", 6, 7],
89955
- ["AMORLINC", C.FINANCIAL, "Returns the depreciation for each accounting period (French, linear)", 6, 7],
89956
- ["COUPDAYBS", C.FINANCIAL, "Returns the number of days from the beginning of the coupon period", 3, 4],
90288
+ [
90289
+ "AMORLINC",
90290
+ C.FINANCIAL,
90291
+ "Returns the depreciation for each accounting period (French, linear)",
90292
+ 6,
90293
+ 7
90294
+ ],
90295
+ [
90296
+ "COUPDAYBS",
90297
+ C.FINANCIAL,
90298
+ "Returns the number of days from the beginning of the coupon period",
90299
+ 3,
90300
+ 4
90301
+ ],
89957
90302
  ["COUPDAYS", C.FINANCIAL, "Returns the number of days in the coupon period", 3, 4],
89958
- ["COUPDAYSNC", C.FINANCIAL, "Returns the number of days from the settlement date to the next coupon", 3, 4],
90303
+ [
90304
+ "COUPDAYSNC",
90305
+ C.FINANCIAL,
90306
+ "Returns the number of days from the settlement date to the next coupon",
90307
+ 3,
90308
+ 4
90309
+ ],
89959
90310
  ["COUPNCD", C.FINANCIAL, "Returns the next coupon date after the settlement date", 3, 4],
89960
90311
  ["COUPNUM", C.FINANCIAL, "Returns the number of coupons payable", 3, 4],
89961
90312
  ["COUPPCD", C.FINANCIAL, "Returns the previous coupon date before the settlement date", 3, 4],
@@ -89980,15 +90331,39 @@ var FINANCIAL_FUNCTIONS = [
89980
90331
  ["NOMINAL", C.FINANCIAL, "Returns the annual nominal interest rate", 2, 2],
89981
90332
  ["NPER", C.FINANCIAL, "Returns the number of periods for an investment", 3, 5],
89982
90333
  ["NPV", C.FINANCIAL, "Returns the net present value of an investment", 2, -1],
89983
- ["PDURATION", C.FINANCIAL, "Returns the number of periods for an investment to reach a value", 3, 3],
90334
+ [
90335
+ "PDURATION",
90336
+ C.FINANCIAL,
90337
+ "Returns the number of periods for an investment to reach a value",
90338
+ 3,
90339
+ 3
90340
+ ],
89984
90341
  ["PMT", C.FINANCIAL, "Returns the periodic payment for an annuity", 3, 5],
89985
90342
  ["PPMT", C.FINANCIAL, "Returns the payment on the principal", 4, 6],
89986
90343
  ["PRICE", C.FINANCIAL, "Returns the price per $100 face value of a security", 6, 7],
89987
- ["PRICEDISC", C.FINANCIAL, "Returns the price per $100 face value of a discounted security", 4, 5],
89988
- ["PRICEMAT", C.FINANCIAL, "Returns the price per $100 face value of a security that pays at maturity", 5, 6],
90344
+ [
90345
+ "PRICEDISC",
90346
+ C.FINANCIAL,
90347
+ "Returns the price per $100 face value of a discounted security",
90348
+ 4,
90349
+ 5
90350
+ ],
90351
+ [
90352
+ "PRICEMAT",
90353
+ C.FINANCIAL,
90354
+ "Returns the price per $100 face value of a security that pays at maturity",
90355
+ 5,
90356
+ 6
90357
+ ],
89989
90358
  ["PV", C.FINANCIAL, "Returns the present value of an investment", 3, 5],
89990
90359
  ["RATE", C.FINANCIAL, "Returns the interest rate per period", 3, 6],
89991
- ["RECEIVED", C.FINANCIAL, "Returns the amount received at maturity for a fully invested security", 4, 5],
90360
+ [
90361
+ "RECEIVED",
90362
+ C.FINANCIAL,
90363
+ "Returns the amount received at maturity for a fully invested security",
90364
+ 4,
90365
+ 5
90366
+ ],
89992
90367
  ["RRI", C.FINANCIAL, "Returns an equivalent interest rate for growth", 3, 3],
89993
90368
  ["SLN", C.FINANCIAL, "Returns the straight-line depreciation", 3, 3],
89994
90369
  ["SYD", C.FINANCIAL, "Returns the sum-of-years digits depreciation", 4, 4],
@@ -90013,9 +90388,21 @@ var ENGINEERING_FUNCTIONS = [
90013
90388
  ["BITAND", C.ENGINEERING, "Returns a bitwise AND of two numbers", 2, 2],
90014
90389
  ["BITLSHIFT", C.ENGINEERING, "Returns a number shifted left by a specified number of bits", 2, 2],
90015
90390
  ["BITOR", C.ENGINEERING, "Returns a bitwise OR of two numbers", 2, 2],
90016
- ["BITRSHIFT", C.ENGINEERING, "Returns a number shifted right by a specified number of bits", 2, 2],
90391
+ [
90392
+ "BITRSHIFT",
90393
+ C.ENGINEERING,
90394
+ "Returns a number shifted right by a specified number of bits",
90395
+ 2,
90396
+ 2
90397
+ ],
90017
90398
  ["BITXOR", C.ENGINEERING, "Returns a bitwise XOR of two numbers", 2, 2],
90018
- ["COMPLEX", C.ENGINEERING, "Converts real and imaginary coefficients into a complex number", 2, 3],
90399
+ [
90400
+ "COMPLEX",
90401
+ C.ENGINEERING,
90402
+ "Converts real and imaginary coefficients into a complex number",
90403
+ 2,
90404
+ 3
90405
+ ],
90019
90406
  ["CONVERT", C.ENGINEERING, "Converts a number from one measurement system to another", 3, 3],
90020
90407
  ["DEC2BIN", C.ENGINEERING, "Converts a decimal number to binary", 1, 2],
90021
90408
  ["DEC2HEX", C.ENGINEERING, "Converts a decimal number to hexadecimal", 1, 2],
@@ -91569,6 +91956,14 @@ var api_spec_default = {
91569
91956
  "ask"
91570
91957
  ]
91571
91958
  },
91959
+ getFormulas: {
91960
+ signature: "getFormulas(range: string): Promise<(string | null)[][]>;",
91961
+ docstring: "Get formulas for a range. Returns 2D array: formula string or null per cell.",
91962
+ usedTypes: [],
91963
+ tags: [
91964
+ "ask"
91965
+ ]
91966
+ },
91572
91967
  getRawCellData: {
91573
91968
  signature: "getRawCellData(address: string, includeFormula?: boolean): Promise<RawCellData>;",
91574
91969
  docstring: "Get raw cell data (value, formula, format, borders, etc.) by A1 address.",
@@ -91644,7 +92039,7 @@ var api_spec_default = {
91644
92039
  ]
91645
92040
  },
91646
92041
  findDataEdge: {
91647
- signature: "findDataEdge(row: number, col: number, direction: 'up' | 'down' | 'left' | 'right'): Promise<{row: number; col: number}>;",
92042
+ signature: "findDataEdge(\n row: number,\n col: number,\n direction: 'up' | 'down' | 'left' | 'right',\n ): Promise<{ row: number; col: number }>;",
91648
92043
  docstring: "Find the data edge in a direction (Excel's Ctrl+Arrow). Single bridge call to Rust.",
91649
92044
  usedTypes: [],
91650
92045
  tags: [
@@ -91790,18 +92185,12 @@ var api_spec_default = {
91790
92185
  "action"
91791
92186
  ]
91792
92187
  },
91793
- batchSetCells: {
91794
- signature: "batchSetCells(updates: Array<{ row: number; col: number; value: any }>): Promise<void>;",
91795
- docstring: "Batch-write cell values (fire-and-forget to compute engine).\nMore efficient than calling setCell() in a loop \u2014 sends one batch IPC call.",
91796
- usedTypes: [],
91797
- tags: [
91798
- "action"
91799
- ]
91800
- },
91801
- batchSetFormulas: {
91802
- signature: "batchSetFormulas(updates: Array<{ row: number; col: number; formula: string }>): Promise<void>;",
91803
- docstring: 'Batch-write cell formulas (fire-and-forget to compute engine).\nEach formula string should start with "=".',
91804
- usedTypes: [],
92188
+ setCells: {
92189
+ signature: "setCells(cells: Array<{ addr: string; value: any }>): Promise<SetCellsResult>;",
92190
+ docstring: 'Bulk-write scattered cell values and/or formulas in a single IPC call.\nValues starting with "=" are treated as formulas.\n\nSupports both A1 addressing and numeric (row, col) addressing.',
92191
+ usedTypes: [
92192
+ "SetCellsResult"
92193
+ ],
91805
92194
  tags: [
91806
92195
  "action"
91807
92196
  ]
@@ -92012,7 +92401,7 @@ var api_spec_default = {
92012
92401
  ]
92013
92402
  },
92014
92403
  on: {
92015
- signature: "on(event: 'sheetAdded' | 'sheetRemoved' | 'sheetRenamed' | 'activeSheetChanged', handler: (event: any) => void): () => void;",
92404
+ signature: "on(\n event: 'sheetAdded' | 'sheetRemoved' | 'sheetRenamed' | 'activeSheetChanged',\n handler: (event: any) => void,\n ): () => void;",
92016
92405
  docstring: "Subscribe to sheet collection events.\nFires for: sheetAdded, sheetRemoved, sheetRenamed, activeSheetChanged.\n\n@param event - Event type\n@param handler - Event handler\n@returns Unsubscribe function",
92017
92406
  usedTypes: [],
92018
92407
  tags: [
@@ -94674,7 +95063,7 @@ var api_spec_default = {
94674
95063
  ]
94675
95064
  },
94676
95065
  sortApply: {
94677
- signature: "sortApply(tableName: string, fields: Array<{ columnIndex: number; ascending?: boolean }>): Promise<void>;",
95066
+ signature: "sortApply(\n tableName: string,\n fields: Array<{ columnIndex: number; ascending?: boolean }>,\n ): Promise<void>;",
94678
95067
  docstring: "Apply sort fields to a table.\n\n@param tableName - Table name\n@param fields - Array of sort field descriptors",
94679
95068
  usedTypes: [],
94680
95069
  tags: [
@@ -94848,6 +95237,17 @@ var api_spec_default = {
94848
95237
  "ask"
94849
95238
  ]
94850
95239
  },
95240
+ queryPivot: {
95241
+ signature: "queryPivot(\n pivotName: string,\n filters?: Record<string, CellValue | CellValue[]>,\n ): Promise<PivotQueryResult | null>;",
95242
+ docstring: "Query a pivot table by name, returning flat records optionally filtered by dimension values.\nEliminates the need to manually traverse hierarchical PivotTableResult trees.\n\n@param pivotName - Pivot table name\n@param filters - Optional dimension filters: field name \u2192 value or array of values to include\n@returns Flat query result, or null if pivot not found or not computable",
95243
+ usedTypes: [
95244
+ "CellValue",
95245
+ "PivotQueryResult"
95246
+ ],
95247
+ tags: [
95248
+ "ask"
95249
+ ]
95250
+ },
94851
95251
  refresh: {
94852
95252
  signature: "refresh(pivotId: string): Promise<void>;",
94853
95253
  docstring: "Refresh a pivot table (recompute without cache).\n\n@param pivotId - Pivot table ID",
@@ -94865,7 +95265,7 @@ var api_spec_default = {
94865
95265
  ]
94866
95266
  },
94867
95267
  addCalculatedField: {
94868
- signature: "addCalculatedField(\n pivotId: string,\n field: CalculatedField,\n ): Promise<void>;",
95268
+ signature: "addCalculatedField(pivotId: string, field: CalculatedField): Promise<void>;",
94869
95269
  docstring: "Add a calculated field to a pivot table.\n\n@param pivotId - Pivot table ID\n@param field - Calculated field definition (fieldId, name, formula)",
94870
95270
  usedTypes: [
94871
95271
  "CalculatedField"
@@ -96345,8 +96745,8 @@ Example: { ignoreError: true } to suppress error indicators. */
96345
96745
  width: number;
96346
96746
  /** Chart height in cells */
96347
96747
  height: number;
96348
- /** Data range in A1 notation (e.g., "A1:D10") */
96349
- dataRange: string;
96748
+ /** Data range in A1 notation (e.g., "A1:D10"). Optional when series[].values are provided. */
96749
+ dataRange?: string;
96350
96750
  /** Series labels range in A1 notation */
96351
96751
  seriesRange?: string;
96352
96752
  /** Category labels range in A1 notation */
@@ -96944,6 +97344,16 @@ Used in condition filters where users specify rules like
96944
97344
  definition: "{\n /** Index of slice to explode (pull out from center) */\n explodedIndex?: number;\n /** Array of indices to explode */\n explodedIndices?: number[];\n /** Distance to explode (0-1, default 0.1) */\n explodeOffset?: number;\n /** Allow clicking to select/explode slices */\n selectable?: boolean;\n}",
96945
97345
  docstring: "Pie/doughnut slice configuration for exploded slices"
96946
97346
  },
97347
+ PivotQueryRecord: {
97348
+ name: "PivotQueryRecord",
97349
+ definition: '{\n /** Dimension values keyed by field name (e.g., { Region: "North", Year: 2021 }) */\n dimensions: Record<string, CellValue>;\n /** Aggregated values keyed by value field label (e.g., { "Sum of Amount": 110 }) */\n values: Record<string, CellValue>;\n}',
97350
+ docstring: "A single flat record from a pivot query result."
97351
+ },
97352
+ PivotQueryResult: {
97353
+ name: "PivotQueryResult",
97354
+ definition: "{\n /** Pivot table name */\n pivotName: string;\n /** Row dimension field names */\n rowFields: string[];\n /** Column dimension field names */\n columnFields: string[];\n /** Value field labels */\n valueFields: string[];\n /** Flat records \u2014 one per data intersection, excluding subtotals and grand totals */\n records: PivotQueryRecord[];\n /** Total source row count */\n sourceRowCount: number;\n}",
97355
+ docstring: "Result of queryPivot() \u2014 flat, agent-friendly records instead of hierarchy trees."
97356
+ },
96947
97357
  PivotTableConfig: {
96948
97358
  name: "PivotTableConfig",
96949
97359
  definition: '{\n /** Pivot table name */\n name: string;\n /** Source data range in A1 notation (e.g., "Sheet1!A1:E100") */\n dataSource: string;\n /** Target sheet name (defaults to a new sheet) */\n targetSheet?: string;\n /** Target cell address (defaults to A1) */\n targetAddress?: string;\n /** Field names for the row area */\n rowFields?: string[];\n /** Field names for the column area */\n columnFields?: string[];\n /** Value field configurations */\n valueFields?: PivotValueField[];\n /** Field names for the filter area */\n filterFields?: string[];\n}',
@@ -96956,7 +97366,7 @@ Used in condition filters where users specify rules like
96956
97366
  },
96957
97367
  PivotTableInfo: {
96958
97368
  name: "PivotTableInfo",
96959
- definition: "{\n /** Pivot table name */\n name: string;\n /** Source data range */\n dataSource: string;\n /** Range occupied by the pivot table content */\n contentArea: string;\n /** Range occupied by filter dropdowns (if any) */\n filterArea?: string;\n}",
97369
+ definition: '{\n /** Pivot table name */\n name: string;\n /** Source data range (e.g., "Sheet1!A1:D100") */\n dataSource: string;\n /** Range occupied by the pivot table content */\n contentArea: string;\n /** Range occupied by filter dropdowns (if any) */\n filterArea?: string;\n /** Output anchor location as A1 reference (e.g., "G1") */\n location?: string;\n /** Row dimension field names */\n rowFields?: string[];\n /** Column dimension field names */\n columnFields?: string[];\n /** Value fields with aggregation info */\n valueFields?: PivotValueField[];\n /** Filter field names */\n filterFields?: string[];\n}',
96960
97370
  docstring: "Summary information about an existing pivot table."
96961
97371
  },
96962
97372
  PivotValueField: {
@@ -97094,6 +97504,11 @@ Used in condition filters where users specify rules like
97094
97504
  definition: "'rows' | 'columns'",
97095
97505
  docstring: "Data series orientation"
97096
97506
  },
97507
+ SetCellsResult: {
97508
+ name: "SetCellsResult",
97509
+ definition: "{\n /** Number of cells successfully written */\n cellsWritten: number;\n /** Per-cell errors, if any (omitted when all succeed) */\n errors?: Array<{ addr: string; error: string }>;\n}",
97510
+ docstring: "Result of a bulk setCells() operation."
97511
+ },
97097
97512
  ShadowAlignment: {
97098
97513
  name: "ShadowAlignment",
97099
97514
  definition: "| 'tl' // Top-left\n | 't' // Top-center\n | 'tr' // Top-right\n | 'l' // Middle-left\n | 'ctr' // Center\n | 'r' // Middle-right\n | 'bl' // Bottom-left\n | 'b' // Bottom-center\n | 'br'",
@@ -97496,7 +97911,7 @@ Used in condition filters where users specify rules like
97496
97911
  docstring: "A summary snapshot of the entire workbook state."
97497
97912
  }
97498
97913
  },
97499
- generated: "2026-04-01T03:19:27.745Z"
97914
+ generated: "2026-04-01T18:35:30.029Z"
97500
97915
  };
97501
97916
 
97502
97917
  // src/api-describe.ts
@@ -97512,6 +97927,44 @@ var rootInterfaces = {
97512
97927
  wb: "Workbook",
97513
97928
  ws: "Worksheet"
97514
97929
  };
97930
+ var BUILTIN_TYPE_NAMES = /* @__PURE__ */ new Set([
97931
+ "Promise",
97932
+ "Partial",
97933
+ "Required",
97934
+ "Readonly",
97935
+ "Pick",
97936
+ "Omit",
97937
+ "Array",
97938
+ "Record",
97939
+ "Map",
97940
+ "Set",
97941
+ "Uint8Array",
97942
+ "ArrayBuffer",
97943
+ "Function",
97944
+ "Object",
97945
+ "Date",
97946
+ "RegExp",
97947
+ "Error",
97948
+ "Symbol",
97949
+ "string",
97950
+ "number",
97951
+ "boolean",
97952
+ "void",
97953
+ "null",
97954
+ "undefined",
97955
+ "any",
97956
+ "never",
97957
+ "unknown"
97958
+ ]);
97959
+ function extractTypeRefs(definition) {
97960
+ const refs = [];
97961
+ for (const [, name] of definition.matchAll(/\b([A-Z][A-Za-z0-9]+)\b/g)) {
97962
+ if (!BUILTIN_TYPE_NAMES.has(name)) {
97963
+ refs.push(name);
97964
+ }
97965
+ }
97966
+ return refs;
97967
+ }
97515
97968
  function getMethodsExcludingAccessors(ifaceName, root) {
97516
97969
  const iface = api_spec_default.interfaces[ifaceName];
97517
97970
  if (!iface) return [];
@@ -97607,10 +98060,20 @@ function resolveMethod(ifaceName, methodName, fullPath) {
97607
98060
  const fn = iface.functions[methodName];
97608
98061
  if (!fn) return null;
97609
98062
  const types = {};
97610
- for (const typeName of fn.usedTypes) {
98063
+ const queue = [...fn.usedTypes];
98064
+ const seen = new Set(queue);
98065
+ while (queue.length > 0) {
98066
+ const typeName = queue.shift();
97611
98067
  const resolved = resolveType(typeName);
97612
- if (resolved) {
97613
- types[typeName] = resolved;
98068
+ if (!resolved) continue;
98069
+ types[typeName] = resolved;
98070
+ if (resolved.definition) {
98071
+ for (const ref of extractTypeRefs(resolved.definition)) {
98072
+ if (!seen.has(ref)) {
98073
+ seen.add(ref);
98074
+ queue.push(ref);
98075
+ }
98076
+ }
97614
98077
  }
97615
98078
  }
97616
98079
  return {
@@ -97622,7 +98085,104 @@ function resolveMethod(ifaceName, methodName, fullPath) {
97622
98085
  types
97623
98086
  };
97624
98087
  }
97625
- var api = { describe };
98088
+ var methodCache = /* @__PURE__ */ new Map();
98089
+ function cachedResolveMethod(ifaceName, methodName, fullPath) {
98090
+ if (methodCache.has(fullPath)) return methodCache.get(fullPath);
98091
+ const result = resolveMethod(ifaceName, methodName, fullPath);
98092
+ methodCache.set(fullPath, result);
98093
+ return result;
98094
+ }
98095
+ var RESERVED_PROPS = /* @__PURE__ */ new Set([
98096
+ "name",
98097
+ "path",
98098
+ "docstring",
98099
+ "methods",
98100
+ "subApis",
98101
+ "types",
98102
+ "tags",
98103
+ "signature"
98104
+ ]);
98105
+ function buildSubApiNode(ifaceName, root, accessor) {
98106
+ const iface = api_spec_default.interfaces[ifaceName];
98107
+ const fullPath = `${root}.${accessor}`;
98108
+ const node = {
98109
+ name: ifaceName,
98110
+ path: fullPath,
98111
+ docstring: iface?.docstring ?? "",
98112
+ methods: buildMethodSummaries(ifaceName)
98113
+ };
98114
+ if (iface) {
98115
+ for (const methodName of Object.keys(iface.functions)) {
98116
+ if (RESERVED_PROPS.has(methodName)) continue;
98117
+ Object.defineProperty(node, methodName, {
98118
+ get() {
98119
+ return cachedResolveMethod(ifaceName, methodName, `${fullPath}.${methodName}`);
98120
+ },
98121
+ enumerable: true,
98122
+ configurable: true
98123
+ });
98124
+ }
98125
+ }
98126
+ return node;
98127
+ }
98128
+ function buildRootNode(root) {
98129
+ const ifaceName = rootInterfaces[root];
98130
+ const accessors = subApiAccessors[root] ?? /* @__PURE__ */ new Set();
98131
+ const node = {
98132
+ name: ifaceName,
98133
+ methods: buildMethodSummaries(ifaceName, accessors),
98134
+ subApis: [...accessors]
98135
+ };
98136
+ const subs = api_spec_default.subApis[root] ?? {};
98137
+ for (const [accessor, subIfaceName] of Object.entries(subs)) {
98138
+ if (RESERVED_PROPS.has(accessor)) continue;
98139
+ let cached;
98140
+ Object.defineProperty(node, accessor, {
98141
+ get() {
98142
+ if (!cached) cached = buildSubApiNode(subIfaceName, root, accessor);
98143
+ return cached;
98144
+ },
98145
+ enumerable: true,
98146
+ configurable: true
98147
+ });
98148
+ }
98149
+ const iface = api_spec_default.interfaces[ifaceName];
98150
+ if (iface) {
98151
+ for (const methodName of Object.keys(iface.functions)) {
98152
+ if (accessors.has(methodName) || RESERVED_PROPS.has(methodName) || methodName in node)
98153
+ continue;
98154
+ Object.defineProperty(node, methodName, {
98155
+ get() {
98156
+ return cachedResolveMethod(ifaceName, methodName, `${root}.${methodName}`);
98157
+ },
98158
+ enumerable: true,
98159
+ configurable: true
98160
+ });
98161
+ }
98162
+ }
98163
+ return node;
98164
+ }
98165
+ function buildTypesNode() {
98166
+ const node = {};
98167
+ for (const name of Object.keys(api_spec_default.types)) {
98168
+ let cached;
98169
+ Object.defineProperty(node, name, {
98170
+ get() {
98171
+ if (cached === void 0) cached = resolveType(name);
98172
+ return cached;
98173
+ },
98174
+ enumerable: true,
98175
+ configurable: true
98176
+ });
98177
+ }
98178
+ return node;
98179
+ }
98180
+ var api = {
98181
+ describe,
98182
+ wb: buildRootNode("wb"),
98183
+ ws: buildRootNode("ws"),
98184
+ types: buildTypesNode()
98185
+ };
97626
98186
 
97627
98187
  // src/boot.ts
97628
98188
  init_esm_shims();
@@ -97745,8 +98305,6 @@ var HeadlessEngine = class {
97745
98305
  ctx: this.context,
97746
98306
  eventBus: this.context.eventBus
97747
98307
  });
97748
- this._workbook.getActiveSheet();
97749
- await this._workbook.refreshSheetMetadata();
97750
98308
  }
97751
98309
  /**
97752
98310
  * Get or set the active sheet ID.
@@ -97822,7 +98380,13 @@ var CoordinatorHandle = class _CoordinatorHandle {
97822
98380
  }
97823
98381
  push(participantId, update4, touchedSheetIds, participantSv) {
97824
98382
  const fn = this.addon["coordinator_push"];
97825
- const result = fn(this.handle, participantId, Buffer.from(update4), touchedSheetIds, Buffer.from(participantSv));
98383
+ const result = fn(
98384
+ this.handle,
98385
+ participantId,
98386
+ Buffer.from(update4),
98387
+ touchedSheetIds,
98388
+ Buffer.from(participantSv)
98389
+ );
97826
98390
  return typeof result === "string" ? JSON.parse(result) : result;
97827
98391
  }
97828
98392
  pull(participantId, participantSv) {
@@ -97959,14 +98523,7 @@ var CollaborativeEngine = class _CollaborativeEngine {
97959
98523
  await engine.computeBridge.syncApply(pushRaw.serverDiff);
97960
98524
  }
97961
98525
  }
97962
- return new _CollaborativeEngine(
97963
- engine,
97964
- coordinator,
97965
- participantId,
97966
- syncMode,
97967
- 10,
97968
- false
97969
- );
98526
+ return new _CollaborativeEngine(engine, coordinator, participantId, syncMode, 10, false);
97970
98527
  }
97971
98528
  // ---------------------------------------------------------------------------
97972
98529
  // Public API
@@ -98055,11 +98612,7 @@ var CollaborativeEngine = class _CollaborativeEngine {
98055
98612
  // ---------------------------------------------------------------------------
98056
98613
  /** Acquire a lock. Returns lock ID. */
98057
98614
  async lock(scope, ttlSeconds = 60) {
98058
- return this._coordinator.acquireLock(
98059
- this._participantId,
98060
- scope,
98061
- ttlSeconds * 1e3
98062
- );
98615
+ return this._coordinator.acquireLock(this._participantId, scope, ttlSeconds * 1e3);
98063
98616
  }
98064
98617
  /** Release a lock. */
98065
98618
  async unlock(lockId) {