@mog-sdk/node 0.1.9-beta-1 → 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.cjs CHANGED
@@ -549,9 +549,7 @@ function getPlatformPackageName() {
549
549
  }
550
550
  const pkg = platformMap[process.arch];
551
551
  if (!pkg) {
552
- throw new Error(
553
- `Unsupported architecture ${process.arch} on ${process.platform}`
554
- );
552
+ throw new Error(`Unsupported architecture ${process.arch} on ${process.platform}`);
555
553
  }
556
554
  return pkg;
557
555
  }
@@ -675,14 +673,14 @@ function deepSnakeToCamel(obj) {
675
673
  }
676
674
  return obj;
677
675
  }
678
- function createNapiTransport(engine, serdeParams) {
676
+ function createNapiTransport(engine, serdeParams, addon) {
679
677
  return {
680
678
  async call(command, args) {
681
- const fn = engine[command];
679
+ const fn = engine[command] ?? addon?.[snakeToCamel(command)];
682
680
  if (!fn) {
683
681
  throw new TransportError(
684
682
  command,
685
- `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`
683
+ `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`
686
684
  );
687
685
  }
688
686
  try {
@@ -710,7 +708,8 @@ function createNapiTransport(engine, serdeParams) {
710
708
  }
711
709
  return value;
712
710
  });
713
- const result = fn.call(engine, ...positionalArgs);
711
+ const isEngineFn = !!engine[command];
712
+ const result = fn.call(isEngineFn ? engine : addon, ...positionalArgs);
714
713
  if (typeof result === "string") {
715
714
  try {
716
715
  return deepSnakeToCamel(JSON.parse(result));
@@ -742,7 +741,7 @@ function createLazyNapiTransport(addon) {
742
741
  if (command === "compute_init") {
743
742
  const snapshotJson = typeof args.snapshot === "string" ? args.snapshot : JSON.stringify(args.snapshot);
744
743
  const engine = new addon.ComputeEngine(snapshotJson);
745
- innerTransport = createNapiTransport(engine, DEFAULT_NAPI_SERDE_PARAMS);
744
+ innerTransport = createNapiTransport(engine, DEFAULT_NAPI_SERDE_PARAMS, addon);
746
745
  const initResultJson = engine.compute_take_init_result?.();
747
746
  if (initResultJson) {
748
747
  return deepSnakeToCamel(JSON.parse(initResultJson));
@@ -6658,6 +6657,9 @@ var init_compute_bridge_gen = __esm({
6658
6657
  pivotGetAll(sheetId) {
6659
6658
  return this.core.query(this.core.transport.call("compute_pivot_get_all", { docId: this.core.docId, sheetId }));
6660
6659
  }
6660
+ pivotComputeFromSource(sheetId, pivotId, expansionState) {
6661
+ return this.core.query(this.core.transport.call("compute_pivot_compute_from_source", { docId: this.core.docId, sheetId, pivotId, expansionState }));
6662
+ }
6661
6663
  pivotRegisterDef(sheetId, pivotId, totalRows, totalCols, firstDataRow, firstDataCol) {
6662
6664
  return this.core.mutatePlain(this.core.transport.call("compute_pivot_register_def", { docId: this.core.docId, sheetId, pivotId, totalRows, totalCols, firstDataRow, firstDataCol }));
6663
6665
  }
@@ -7027,7 +7029,9 @@ var init_compute_bridge = __esm({
7027
7029
  parentId: options?.parentId ?? null
7028
7030
  }
7029
7031
  );
7030
- const tuple = normalizeBytesTuple(raw);
7032
+ const tuple = normalizeBytesTuple(
7033
+ raw
7034
+ );
7031
7035
  const result = await this.core.mutate(Promise.resolve(tuple));
7032
7036
  const comment = extractMutationData(result);
7033
7037
  if (!comment) {
@@ -7134,14 +7138,9 @@ var init_compute_bridge = __esm({
7134
7138
  // ===========================================================================
7135
7139
  /** Get protection options for a sheet. Returns per-operation permissions when protected. */
7136
7140
  async getSheetProtectionOptions(sheetId) {
7137
- const config = await this.core.query(
7138
- this.core.transport.call("compute_get_sheet_protection_config", {
7139
- docId: this.core.docId,
7140
- sheetId
7141
- })
7142
- );
7143
- if (!config.isProtected) return null;
7144
- return DEFAULT_PROTECTION_OPTIONS;
7141
+ const settings = await this.getSheetSettings(sheetId);
7142
+ if (!settings.isProtected) return null;
7143
+ return { ...DEFAULT_PROTECTION_OPTIONS, ...settings.protectionOptions };
7145
7144
  }
7146
7145
  /** Set multiple sheet settings at once (iterates entries). */
7147
7146
  async setSheetSettings(sheetId, updates) {
@@ -7181,7 +7180,8 @@ var init_compute_bridge = __esm({
7181
7180
  const tuples = edits.map(
7182
7181
  (e) => [sheetId, e.row, e.col, e.input]
7183
7182
  );
7184
- return this.batchSetCellsByPosition(tuples, false);
7183
+ const result = await this.batchSetCellsByPosition(tuples, false);
7184
+ return result;
7185
7185
  }
7186
7186
  /** Patch workbook settings — reads current, merges partial, writes full. */
7187
7187
  async patchWorkbookSettings(settings) {
@@ -7861,35 +7861,6 @@ function letterToCol(letters) {
7861
7861
  }
7862
7862
  return result - 1;
7863
7863
  }
7864
- function parseA1(address) {
7865
- const match = address.match(/^([A-Za-z]+)(\d+)$/);
7866
- if (!match) {
7867
- throw new Error(`Invalid cell address: ${address}`);
7868
- }
7869
- return {
7870
- row: parseInt(match[2], 10) - 1,
7871
- col: letterToCol(match[1])
7872
- };
7873
- }
7874
- function parseA1Range(range2) {
7875
- const [start, end] = range2.split(":");
7876
- const startPos = parseA1(start);
7877
- if (!end) {
7878
- return {
7879
- startRow: startPos.row,
7880
- startCol: startPos.col,
7881
- endRow: startPos.row,
7882
- endCol: startPos.col
7883
- };
7884
- }
7885
- const endPos = parseA1(end);
7886
- return {
7887
- startRow: Math.min(startPos.row, endPos.row),
7888
- startCol: Math.min(startPos.col, endPos.col),
7889
- endRow: Math.max(startPos.row, endPos.row),
7890
- endCol: Math.max(startPos.col, endPos.col)
7891
- };
7892
- }
7893
7864
  function toA1(row, col) {
7894
7865
  return `${colToLetter2(col)}${row + 1}`;
7895
7866
  }
@@ -8011,13 +7982,13 @@ async function getChartDataRange(ctx, chart) {
8011
7982
  const sheetId = chart.sheetId;
8012
7983
  if (!sheetId) {
8013
7984
  if (!chart.dataRange) return null;
8014
- return parseA1Range(chart.dataRange);
7985
+ return parseCellRange(chart.dataRange);
8015
7986
  }
8016
7987
  if (chart.dataRangeIdentity) {
8017
7988
  return resolveCellIdRange(ctx, sheetId, chart.dataRangeIdentity);
8018
7989
  }
8019
7990
  if (!chart.dataRange) return null;
8020
- return parseA1Range(chart.dataRange);
7991
+ return parseCellRange(chart.dataRange);
8021
7992
  }
8022
7993
  async function getMaxZIndex(ctx, sheetId) {
8023
7994
  const charts = await getAll2(ctx, sheetId);
@@ -9159,7 +9130,11 @@ var init_statistics = __esm({
9159
9130
 
9160
9131
  // ../../charts/src/core/data-extractor.ts
9161
9132
  function parseRange(range2) {
9162
- return parseA1Range(range2);
9133
+ const parsed = parseCellRange(range2);
9134
+ if (!parsed) {
9135
+ throw new Error(`Invalid cell range: ${range2}`);
9136
+ }
9137
+ return parsed;
9163
9138
  }
9164
9139
  function toNumber(value) {
9165
9140
  if (value === null || value === void 0 || value === "") {
@@ -15809,6 +15784,26 @@ var init_cell_properties = __esm({
15809
15784
  }
15810
15785
  });
15811
15786
 
15787
+ // ../../kernel/src/api/internal/value-conversions.ts
15788
+ function viewportCellValueToCellValue(cv) {
15789
+ return cv;
15790
+ }
15791
+ function viewportCellValueToString(cv) {
15792
+ if (cv === null || cv === void 0) return "";
15793
+ if (typeof cv === "string") return cv;
15794
+ if (typeof cv === "number") return String(cv);
15795
+ if (typeof cv === "boolean") return cv ? "TRUE" : "FALSE";
15796
+ if (isCellError(cv)) return errorDisplayString(cv.value);
15797
+ return "";
15798
+ }
15799
+ var init_value_conversions = __esm({
15800
+ "../../kernel/src/api/internal/value-conversions.ts"() {
15801
+ "use strict";
15802
+ init_cjs_shims();
15803
+ init_errors3();
15804
+ }
15805
+ });
15806
+
15812
15807
  // ../../kernel/src/domain/drawing/ink/ink-tool-defaults.ts
15813
15808
  function getDefaultToolSettings(tool) {
15814
15809
  return {
@@ -25172,8 +25167,7 @@ var init_pivot_bridge = __esm({
25172
25167
  "../../kernel/src/bridges/pivot-bridge.ts"() {
25173
25168
  "use strict";
25174
25169
  init_cjs_shims();
25175
- init_rich_text();
25176
- init_cell_reads();
25170
+ init_value_conversions();
25177
25171
  init_sheet_meta();
25178
25172
  init_compute_core();
25179
25173
  PivotBridge = class {
@@ -25279,30 +25273,22 @@ var init_pivot_bridge = __esm({
25279
25273
  * Uses cached result if available and valid.
25280
25274
  */
25281
25275
  async compute(sheetId, pivotId, forceRefresh = false) {
25282
- const config = await this.ctx.computeBridge.pivotGet(sheetId, pivotId);
25283
- if (!config) {
25284
- return null;
25285
- }
25286
25276
  const configVersion = this.getConfigVersion(pivotId);
25287
- const dataVersion = this.getDataVersion(config.sourceSheetId);
25277
+ const dataVersion = this.getDataVersion(sheetId);
25288
25278
  if (!forceRefresh) {
25289
25279
  const cached = this.cache.get(pivotId);
25290
25280
  if (cached && cached.configVersion === configVersion && cached.dataVersion === dataVersion) {
25291
25281
  return cached.result;
25292
25282
  }
25293
25283
  }
25294
- const data = await this.getSourceData(config);
25295
- if (!data) {
25296
- return null;
25297
- }
25298
25284
  const expansionState = this.ctx.pivotExpansionProvider?.getExpansionState(pivotId) ?? {
25299
25285
  expandedRows: {},
25300
25286
  expandedColumns: {}
25301
25287
  };
25302
25288
  try {
25303
- const result = await this.ctx.computeBridge.pivotCompute(
25304
- config,
25305
- data,
25289
+ const result = await this.ctx.computeBridge.pivotComputeFromSource(
25290
+ sheetId,
25291
+ pivotId,
25306
25292
  expansionState ?? null
25307
25293
  );
25308
25294
  this.cache.set(pivotId, {
@@ -25474,23 +25460,26 @@ var init_pivot_bridge = __esm({
25474
25460
  }
25475
25461
  /**
25476
25462
  * Get data from a cell range.
25477
- * Uses Cells domain module instead of SpreadsheetStore
25463
+ * Uses queryRange for bulk cell reading (works in all modes including headless/NAPI).
25478
25464
  */
25479
25465
  async getDataFromRange(sheetId, range2) {
25466
+ const rangeResult = await this.ctx.computeBridge.queryRange(
25467
+ sheetId,
25468
+ range2.startRow,
25469
+ range2.startCol,
25470
+ range2.endRow,
25471
+ range2.endCol
25472
+ );
25473
+ const cellMap = /* @__PURE__ */ new Map();
25474
+ for (const cell of rangeResult.cells) {
25475
+ cellMap.set(`${cell.row},${cell.col}`, cell);
25476
+ }
25480
25477
  const data = [];
25481
25478
  for (let row = range2.startRow; row <= range2.endRow; row++) {
25482
25479
  const rowData = [];
25483
25480
  for (let col = range2.startCol; col <= range2.endCol; col++) {
25484
- const cellData = await getData(this.ctx, sheetId, row, col);
25485
- let value;
25486
- if (!cellData) {
25487
- value = null;
25488
- } else if (cellData.formula !== void 0) {
25489
- value = cellData.computed ?? null;
25490
- } else {
25491
- value = cellData.raw !== void 0 ? rawToCellValue(cellData.raw) : null;
25492
- }
25493
- rowData.push(value);
25481
+ const cell = cellMap.get(`${row},${col}`);
25482
+ rowData.push(cell ? viewportCellValueToCellValue(cell.value) ?? null : null);
25494
25483
  }
25495
25484
  data.push(rowData);
25496
25485
  }
@@ -76419,7 +76408,7 @@ var init_document_lifecycle_system = __esm({
76419
76408
  await databaseBridge.initialize();
76420
76409
  } catch (err2) {
76421
76410
  const msg = err2 instanceof Error ? err2.message : String(err2);
76422
- if (msg.includes("Unknown WASM function") || msg.includes("compute_init must be called before")) {
76411
+ if (msg.includes("Unknown WASM function") || msg.includes("compute_init must be called before") || msg.includes("not found")) {
76423
76412
  console.debug(
76424
76413
  "[DocumentLifecycleSystem] DatabaseBridge unavailable in this environment \u2014 database features disabled."
76425
76414
  );
@@ -77787,7 +77776,8 @@ var WorkbookNamesImpl = class {
77787
77776
  if (typeof cell === "boolean") return "Boolean" /* Boolean */;
77788
77777
  if (typeof cell === "number") return "Double" /* Double */;
77789
77778
  if (typeof cell === "string") return "String" /* String */;
77790
- if (typeof cell === "object" && cell !== null && "type" in cell) return "Error" /* Error */;
77779
+ if (typeof cell === "object" && cell !== null && "type" in cell)
77780
+ return "Error" /* Error */;
77791
77781
  return "String" /* String */;
77792
77782
  })
77793
77783
  );
@@ -79167,20 +79157,8 @@ function analyzeStylePatterns(cells) {
79167
79157
  return lines;
79168
79158
  }
79169
79159
 
79170
- // ../../kernel/src/api/internal/value-conversions.ts
79171
- init_cjs_shims();
79172
- init_errors3();
79173
- function viewportCellValueToCellValue(cv) {
79174
- return cv;
79175
- }
79176
- function viewportCellValueToString(cv) {
79177
- if (cv === null || cv === void 0) return "";
79178
- if (typeof cv === "string") return cv;
79179
- if (typeof cv === "number") return String(cv);
79180
- if (typeof cv === "boolean") return cv ? "TRUE" : "FALSE";
79181
- if (isCellError(cv)) return errorDisplayString(cv.value);
79182
- return "";
79183
- }
79160
+ // ../../kernel/src/api/worksheet/worksheet-impl.ts
79161
+ init_value_conversions();
79184
79162
 
79185
79163
  // ../../kernel/src/api/worksheet/operations/cell-operations.ts
79186
79164
  init_cjs_shims();
@@ -79239,18 +79217,27 @@ async function setCell(ctx, sheetId, row, col, value) {
79239
79217
  throw KernelError.from(null, "COMPUTE_ERROR", `Invalid cell address: row=${row}, col=${col}`);
79240
79218
  }
79241
79219
  const input = value === null || value === void 0 ? "" : value === "" ? "\0" : String(value);
79242
- await ctx.computeBridge.setCellsByPosition(sheetId, [{ row, col, input }]);
79243
- }
79244
- async function batchSetCells(ctx, sheetId, updates) {
79245
- if (updates.length === 0) return;
79246
- const edits = updates.map(
79247
- ({ row, col, value }) => ({
79248
- row,
79249
- col,
79250
- input: typeof value === "string" && value.startsWith("=") ? value : value === null || value === void 0 ? "" : value === "" ? "\0" : String(value)
79251
- })
79252
- );
79220
+ const result = await ctx.computeBridge.setCellsByPosition(sheetId, [{ row, col, input }]);
79221
+ }
79222
+ async function setCells(ctx, sheetId, cells) {
79223
+ if (cells.length === 0) return { cellsWritten: 0 };
79224
+ const edits = cells.map((cell) => {
79225
+ let row;
79226
+ let col;
79227
+ if ("addr" in cell && typeof cell.addr === "string") {
79228
+ const resolved = resolveCell(cell.addr);
79229
+ row = resolved.row;
79230
+ col = resolved.col;
79231
+ } else {
79232
+ row = cell.row;
79233
+ col = cell.col;
79234
+ }
79235
+ const { value } = cell;
79236
+ const input = typeof value === "string" && value.startsWith("=") ? value : value === null || value === void 0 ? "" : value === "" ? "\0" : String(value);
79237
+ return { row, col, input };
79238
+ });
79253
79239
  await ctx.computeBridge.setCellsByPosition(sheetId, edits);
79240
+ return { cellsWritten: edits.length };
79254
79241
  }
79255
79242
  async function setDateValue(ctx, sheetId, row, col, year, month, day) {
79256
79243
  const cellId = await ctx.computeBridge.getCellIdAt(sheetId, row, col);
@@ -79288,13 +79275,6 @@ async function setTimeValue(ctx, sheetId, row, col, hours, minutes, seconds) {
79288
79275
  });
79289
79276
  }
79290
79277
  }
79291
- async function batchSetFormulas(ctx, sheetId, updates) {
79292
- if (updates.length === 0) return;
79293
- const edits = updates.map(
79294
- ({ row, col, formula }) => ({ row, col, input: formula })
79295
- );
79296
- await ctx.computeBridge.setCellsByPosition(sheetId, edits);
79297
- }
79298
79278
  async function relocateCells(ctx, sheetId, srcStartRow, srcStartCol, srcEndRow, srcEndCol, targetRow, targetCol) {
79299
79279
  await ctx.computeBridge.relocateCells(
79300
79280
  sheetId,
@@ -79377,10 +79357,10 @@ async function getPrecedents(ctx, sheetId, row, col) {
79377
79357
  init_cjs_shims();
79378
79358
  init_errors();
79379
79359
  function computeDirection(source, target) {
79380
- if (target.startRow > source.endRow) return "down";
79381
- if (target.endRow < source.startRow) return "up";
79382
- if (target.startCol > source.endCol) return "right";
79383
- if (target.endCol < source.startCol) return "left";
79360
+ if (target.endRow > source.endRow) return "down";
79361
+ if (target.startRow < source.startRow) return "up";
79362
+ if (target.endCol > source.endCol) return "right";
79363
+ if (target.startCol < source.startCol) return "left";
79384
79364
  return "down";
79385
79365
  }
79386
79366
  function modeToFlags(mode) {
@@ -79665,6 +79645,7 @@ async function getMergeAt(ctx, sheetId, row, col) {
79665
79645
  // ../../kernel/src/api/worksheet/operations/query-operations.ts
79666
79646
  init_cjs_shims();
79667
79647
  init_a1();
79648
+ init_value_conversions();
79668
79649
  async function getUsedRange2(ctx, sheetId) {
79669
79650
  const bounds = await ctx.computeBridge.getDataBounds(sheetId);
79670
79651
  if (!bounds) return null;
@@ -79795,6 +79776,7 @@ async function getRangeWithIdentity(ctx, sheetId, startRow, startCol, endRow, en
79795
79776
  // ../../kernel/src/api/worksheet/operations/range-operations.ts
79796
79777
  init_cjs_shims();
79797
79778
  init_errors();
79779
+ init_value_conversions();
79798
79780
  async function getRange(ctx, sheetId, range2) {
79799
79781
  const normalized = normalizeRange(range2);
79800
79782
  const rangeResult = await ctx.computeBridge.queryRange(
@@ -79829,6 +79811,30 @@ async function getRange(ctx, sheetId, range2) {
79829
79811
  }
79830
79812
  return result;
79831
79813
  }
79814
+ async function getRangeFormulas(ctx, sheetId, range2) {
79815
+ const normalized = normalizeRange(range2);
79816
+ const rangeResult = await ctx.computeBridge.queryRange(
79817
+ sheetId,
79818
+ normalized.startRow,
79819
+ normalized.startCol,
79820
+ normalized.endRow,
79821
+ normalized.endCol
79822
+ );
79823
+ const cellMap = /* @__PURE__ */ new Map();
79824
+ for (const cell of rangeResult.cells) {
79825
+ cellMap.set(`${cell.row},${cell.col}`, cell);
79826
+ }
79827
+ const result = [];
79828
+ for (let row = normalized.startRow; row <= normalized.endRow; row++) {
79829
+ const rowData = [];
79830
+ for (let col = normalized.startCol; col <= normalized.endCol; col++) {
79831
+ const cell = cellMap.get(`${row},${col}`);
79832
+ rowData.push(cell?.formula ?? null);
79833
+ }
79834
+ result.push(rowData);
79835
+ }
79836
+ return result;
79837
+ }
79832
79838
  async function setRange(ctx, sheetId, startRow, startCol, values) {
79833
79839
  if (!isValidAddress(startRow, startCol)) {
79834
79840
  throw KernelError.from(
@@ -79896,6 +79902,7 @@ async function clearRange2(ctx, sheetId, range2) {
79896
79902
  // ../../kernel/src/api/worksheet/operations/range-query-operations.ts
79897
79903
  init_cjs_shims();
79898
79904
  init_a1();
79905
+ init_value_conversions();
79899
79906
  async function clearWithMode(ctx, sheetId, range2, applyTo = "all") {
79900
79907
  const n = normalizeRange(range2);
79901
79908
  const promises = [];
@@ -80967,7 +80974,7 @@ function chartConfigToInternal(config) {
80967
80974
  visible: true,
80968
80975
  printable: true,
80969
80976
  opacity: 1,
80970
- name: config.title ?? "",
80977
+ name: config.name ?? "",
80971
80978
  createdAt: now,
80972
80979
  updatedAt: now,
80973
80980
  // FloatingObjectData discriminator
@@ -81135,7 +81142,9 @@ var WorksheetChartsImpl = class _WorksheetChartsImpl {
81135
81142
  // ===========================================================================
81136
81143
  async add(config) {
81137
81144
  if (!config.type) throw invalidChartConfig("type is required");
81138
- if (!config.dataRange) throw invalidChartConfig("dataRange is required");
81145
+ const hasSeriesValues = config.series?.some((s) => s.values);
81146
+ if (!config.dataRange && !hasSeriesValues)
81147
+ throw invalidChartConfig("dataRange is required when series[].values are not provided");
81139
81148
  const chartId = config.id || `chart-${Date.now()}-${_WorksheetChartsImpl._idCounter++}`;
81140
81149
  const configWithId = { ...config, id: chartId };
81141
81150
  const internalConfig = chartConfigToInternal(configWithId);
@@ -82232,16 +82241,22 @@ var WorksheetFormatsImpl = class {
82232
82241
  const current = await this.get(row, col);
82233
82242
  const currentIndent = current?.indent ?? 0;
82234
82243
  const newIndent = Math.max(0, Math.min(250, currentIndent + amount));
82235
- await this.ctx.computeBridge.setFormatForRanges(this.sheetId, [[row, col, row, col]], { indent: newIndent });
82244
+ await this.ctx.computeBridge.setFormatForRanges(this.sheetId, [[row, col, row, col]], {
82245
+ indent: newIndent
82246
+ });
82236
82247
  }
82237
82248
  async clearFill(a, b) {
82238
82249
  const { row, col } = resolveCell(a, b);
82239
- await this.ctx.computeBridge.setFormatForRanges(this.sheetId, [[row, col, row, col]], {
82240
- backgroundColor: "",
82241
- patternType: "none",
82242
- patternForegroundColor: "",
82243
- gradientFill: void 0
82244
- });
82250
+ const rangeTuple = [row, col, row, col];
82251
+ const current = await this.get(row, col);
82252
+ await this.ctx.computeBridge.clearFormatForRanges(this.sheetId, [rangeTuple]);
82253
+ if (current) {
82254
+ const { backgroundColor, patternType, patternForegroundColor, gradientFill, ...rest } = current;
82255
+ const hasRest = Object.keys(rest).length > 0;
82256
+ if (hasRest) {
82257
+ await this.ctx.computeBridge.setFormatForRanges(this.sheetId, [rangeTuple], rest);
82258
+ }
82259
+ }
82245
82260
  }
82246
82261
  async getNumberFormatCategory(a, b) {
82247
82262
  const { row, col } = resolveCell(a, b);
@@ -82680,14 +82695,20 @@ var WorksheetNamesImpl = class {
82680
82695
  async remove(name) {
82681
82696
  const defined = await getByName(this.ctx, name, this.sheetId);
82682
82697
  if (!defined) {
82683
- throw new KernelError("COMPUTE_ERROR", `Named range "${name}" not found in this sheet's scope.`);
82698
+ throw new KernelError(
82699
+ "COMPUTE_ERROR",
82700
+ `Named range "${name}" not found in this sheet's scope.`
82701
+ );
82684
82702
  }
82685
82703
  await remove(this.ctx, defined.id, "api");
82686
82704
  }
82687
82705
  async update(name, updates) {
82688
82706
  const defined = await getByName(this.ctx, name, this.sheetId);
82689
82707
  if (!defined) {
82690
- throw new KernelError("COMPUTE_ERROR", `Named range "${name}" not found in this sheet's scope.`);
82708
+ throw new KernelError(
82709
+ "COMPUTE_ERROR",
82710
+ `Named range "${name}" not found in this sheet's scope.`
82711
+ );
82691
82712
  }
82692
82713
  const refersToA1 = updates.reference ? updates.reference.startsWith("=") ? updates.reference : `=${updates.reference}` : void 0;
82693
82714
  await update2(
@@ -83087,12 +83108,21 @@ var WorksheetPivotsImpl = class _WorksheetPivotsImpl {
83087
83108
  );
83088
83109
  }
83089
83110
  }
83090
- return pivots.map((p) => ({
83091
- name: p.name ?? p.id,
83092
- dataSource: formatDataSource(sheetNameCache.get(p.sourceSheetId) ?? null, p.sourceRange),
83093
- contentArea: "",
83094
- filterArea: void 0
83095
- }));
83111
+ return pivots.map((p) => {
83112
+ const apiConfig = dataConfigToApiConfig(p, sheetNameCache.get(p.sourceSheetId) ?? null);
83113
+ const location = p.outputLocation ? toA1(p.outputLocation.row, p.outputLocation.col) : void 0;
83114
+ return {
83115
+ name: p.name ?? p.id,
83116
+ dataSource: apiConfig.dataSource,
83117
+ contentArea: "",
83118
+ filterArea: void 0,
83119
+ location,
83120
+ rowFields: apiConfig.rowFields,
83121
+ columnFields: apiConfig.columnFields,
83122
+ valueFields: apiConfig.valueFields,
83123
+ filterFields: apiConfig.filterFields
83124
+ };
83125
+ });
83096
83126
  }
83097
83127
  async get(name) {
83098
83128
  const pivot = await this.findPivotByName(name);
@@ -83243,6 +83273,99 @@ var WorksheetPivotsImpl = class _WorksheetPivotsImpl {
83243
83273
  async getDrillDownData(pivotId, rowKey, columnKey) {
83244
83274
  return await this.ctx.pivot.getDrillDownData(this.sheetId, pivotId, rowKey, columnKey);
83245
83275
  }
83276
+ async queryPivot(pivotName, filters) {
83277
+ const pivot = await this.findPivotByName(pivotName);
83278
+ if (!pivot) return null;
83279
+ const pivotId = pivot.id ?? pivot.name;
83280
+ const result = await this.ctx.pivot.compute(this.sheetId, pivotId);
83281
+ if (!result) return null;
83282
+ const fieldNameById = /* @__PURE__ */ new Map();
83283
+ for (const f of pivot.fields) {
83284
+ fieldNameById.set(f.id, f.name);
83285
+ }
83286
+ const rowPlacements = pivot.placements.filter((p) => p.area === "row").sort((a, b) => a.position - b.position);
83287
+ const colPlacements = pivot.placements.filter((p) => p.area === "column").sort((a, b) => a.position - b.position);
83288
+ const valuePlacements = pivot.placements.filter((p) => p.area === "value").sort((a, b) => a.position - b.position);
83289
+ const rowFieldNames = rowPlacements.map((p) => fieldNameById.get(p.fieldId) ?? p.fieldId);
83290
+ const colFieldNames = colPlacements.map((p) => fieldNameById.get(p.fieldId) ?? p.fieldId);
83291
+ const valueFieldLabels = valuePlacements.map((p) => {
83292
+ if (p.displayName) return p.displayName;
83293
+ const name = fieldNameById.get(p.fieldId) ?? p.fieldId;
83294
+ const agg = p.aggregateFunction ?? "sum";
83295
+ return `${agg.charAt(0).toUpperCase() + agg.slice(1)} of ${name}`;
83296
+ });
83297
+ const numDataCols = result.rows.length > 0 ? result.rows[0].values.length : 0;
83298
+ const colDimensionTuples = [];
83299
+ if (colPlacements.length > 0 && result.columnHeaders.length > 0) {
83300
+ for (let i = 0; i < numDataCols; i++) {
83301
+ colDimensionTuples.push({});
83302
+ }
83303
+ for (const level of result.columnHeaders) {
83304
+ const fieldName = fieldNameById.get(level.fieldId) ?? level.fieldId;
83305
+ let colIndex = 0;
83306
+ for (const header of level.headers) {
83307
+ if (!header.isSubtotal && !header.isGrandTotal) {
83308
+ for (let s = 0; s < header.span; s++) {
83309
+ if (colIndex + s < numDataCols) {
83310
+ colDimensionTuples[colIndex + s][fieldName] = header.value;
83311
+ }
83312
+ }
83313
+ }
83314
+ colIndex += header.span;
83315
+ }
83316
+ }
83317
+ }
83318
+ const records = [];
83319
+ for (const row of result.rows) {
83320
+ if (row.isSubtotal || row.isGrandTotal) continue;
83321
+ const rowDimensions = {};
83322
+ for (const header of row.headers) {
83323
+ if (header.isSubtotal || header.isGrandTotal) continue;
83324
+ const fieldName = fieldNameById.get(header.fieldId) ?? header.fieldId;
83325
+ rowDimensions[fieldName] = header.value;
83326
+ }
83327
+ if (colDimensionTuples.length > 0) {
83328
+ for (let colIdx = 0; colIdx < colDimensionTuples.length; colIdx++) {
83329
+ const colDims = colDimensionTuples[colIdx];
83330
+ if (!colDims || Object.keys(colDims).length === 0) continue;
83331
+ const dimensions = { ...rowDimensions, ...colDims };
83332
+ const values = {};
83333
+ if (valuePlacements.length <= 1) {
83334
+ values[valueFieldLabels[0] ?? "Value"] = row.values[colIdx] ?? null;
83335
+ } else {
83336
+ const valueIndex = colIdx % valuePlacements.length;
83337
+ values[valueFieldLabels[valueIndex] ?? "Value"] = row.values[colIdx] ?? null;
83338
+ }
83339
+ records.push({ dimensions, values });
83340
+ }
83341
+ } else {
83342
+ const values = {};
83343
+ for (let i = 0; i < valuePlacements.length; i++) {
83344
+ values[valueFieldLabels[i] ?? `Value${i}`] = row.values[i] ?? null;
83345
+ }
83346
+ records.push({ dimensions: rowDimensions, values });
83347
+ }
83348
+ }
83349
+ const filteredRecords = filters ? records.filter((record) => {
83350
+ for (const [field, filterValue] of Object.entries(filters)) {
83351
+ const dimValue = record.dimensions[field];
83352
+ if (Array.isArray(filterValue)) {
83353
+ if (!filterValue.some((fv) => String(fv) === String(dimValue))) return false;
83354
+ } else {
83355
+ if (String(filterValue) !== String(dimValue)) return false;
83356
+ }
83357
+ }
83358
+ return true;
83359
+ }) : records;
83360
+ return {
83361
+ pivotName,
83362
+ rowFields: rowFieldNames,
83363
+ columnFields: colFieldNames,
83364
+ valueFields: valueFieldLabels,
83365
+ records: filteredRecords,
83366
+ sourceRowCount: result.sourceRowCount
83367
+ };
83368
+ }
83246
83369
  // ===========================================================================
83247
83370
  // Expansion State (delegated to PivotExpansionStateProvider)
83248
83371
  // ===========================================================================
@@ -83628,12 +83751,18 @@ async function setPrintArea(ctx, sheetId, area) {
83628
83751
  try {
83629
83752
  const rangeParts = area.split(":");
83630
83753
  if (rangeParts.length !== 2) {
83631
- return { success: false, error: operationFailed("setPrintArea", `Invalid range format: ${area}`) };
83754
+ return {
83755
+ success: false,
83756
+ error: operationFailed("setPrintArea", `Invalid range format: ${area}`)
83757
+ };
83632
83758
  }
83633
83759
  const start = parseCellRef2(rangeParts[0]);
83634
83760
  const end = parseCellRef2(rangeParts[1]);
83635
83761
  if (!start || !end) {
83636
- return { success: false, error: operationFailed("setPrintArea", `Invalid cell reference in range: ${area}`) };
83762
+ return {
83763
+ success: false,
83764
+ error: operationFailed("setPrintArea", `Invalid cell reference in range: ${area}`)
83765
+ };
83637
83766
  }
83638
83767
  const printRange = {
83639
83768
  startRow: start.row,
@@ -83844,10 +83973,10 @@ var WorksheetProtectionImpl = class {
83844
83973
  };
83845
83974
  }
83846
83975
  async getSelectionMode() {
83847
- const options = await this.ctx.computeBridge.getSheetProtectionOptions(this.sheetId);
83848
- if (!options) return "normal";
83849
- const selectLocked = options.selectLockedCells ?? true;
83850
- const selectUnlocked = options.selectUnlockedCells ?? true;
83976
+ const settings = await this.ctx.computeBridge.getSheetSettings(this.sheetId);
83977
+ const opts = settings.protectionOptions;
83978
+ const selectLocked = opts?.selectLockedCells ?? true;
83979
+ const selectUnlocked = opts?.selectUnlockedCells ?? true;
83851
83980
  if (selectLocked && selectUnlocked) return "normal";
83852
83981
  if (!selectLocked && selectUnlocked) return "unlockedOnly";
83853
83982
  return "none";
@@ -83889,11 +84018,15 @@ var WorksheetSettingsImpl = class {
83889
84018
  );
83890
84019
  }
83891
84020
  async getStandardHeight() {
83892
- const settings = await this.ctx.computeBridge.getSheetSettings(this.sheetId);
84021
+ const settings = await this.ctx.computeBridge.getSheetSettings(
84022
+ this.sheetId
84023
+ );
83893
84024
  return settings.defaultRowHeight;
83894
84025
  }
83895
84026
  async getStandardWidth() {
83896
- const settings = await this.ctx.computeBridge.getSheetSettings(this.sheetId);
84027
+ const settings = await this.ctx.computeBridge.getSheetSettings(
84028
+ this.sheetId
84029
+ );
83897
84030
  return settings.defaultColWidth;
83898
84031
  }
83899
84032
  async setStandardWidth(width) {
@@ -83971,9 +84104,7 @@ var WorksheetSlicersImpl = class {
83971
84104
  const columnName = stored.source.columnCellId;
83972
84105
  let absCol = -1;
83973
84106
  if (table.columns.length > 0) {
83974
- const colIndex = table.columns.findIndex(
83975
- (c) => c.name === columnName || c.id === columnName
83976
- );
84107
+ const colIndex = table.columns.findIndex((c) => c.name === columnName || c.id === columnName);
83977
84108
  if (colIndex >= 0) absCol = table.range.startCol + colIndex;
83978
84109
  }
83979
84110
  if (absCol < 0 && table.hasHeaderRow) {
@@ -84010,9 +84141,7 @@ var WorksheetSlicersImpl = class {
84010
84141
  const cell = cellsJson.find((c) => c.row === r);
84011
84142
  columnData.push(extractCellValue2(cell?.value));
84012
84143
  }
84013
- const selectedSet = new Set(
84014
- stored.selectedValues.map((v) => String(v ?? ""))
84015
- );
84144
+ const selectedSet = new Set(stored.selectedValues.map((v) => String(v ?? "")));
84016
84145
  const hasSelection = selectedSet.size > 0 && !(selectedSet.size === 1 && selectedSet.has(""));
84017
84146
  const valueCounts = /* @__PURE__ */ new Map();
84018
84147
  for (const v of columnData) {
@@ -84694,7 +84823,7 @@ init_errors();
84694
84823
 
84695
84824
  // ../../kernel/src/api/worksheet/operations/table-operations.ts
84696
84825
  init_cjs_shims();
84697
- function parseA1Range2(range2) {
84826
+ function parseA1Range(range2) {
84698
84827
  const match = range2.match(/^([A-Z]+)(\d+):([A-Z]+)(\d+)$/i);
84699
84828
  if (!match) return null;
84700
84829
  return {
@@ -84732,7 +84861,7 @@ function bridgeTableToTableInfo(table) {
84732
84861
  };
84733
84862
  }
84734
84863
  function getTableColumnDataCellsFromInfo(table, colIndex) {
84735
- const parsed = parseA1Range2(table.range);
84864
+ const parsed = parseA1Range(table.range);
84736
84865
  if (!parsed) return [];
84737
84866
  const dataStartRow = table.hasHeaders ? parsed.startRow + 1 : parsed.startRow;
84738
84867
  const dataEndRow = table.showTotals ? parsed.endRow - 1 : parsed.endRow;
@@ -84746,7 +84875,7 @@ function getTableColumnDataCellsFromInfo(table, colIndex) {
84746
84875
  return cells;
84747
84876
  }
84748
84877
  function getDataBodyRangeFromInfo(table) {
84749
- const parsed = parseA1Range2(table.range);
84878
+ const parsed = parseA1Range(table.range);
84750
84879
  if (!parsed) return null;
84751
84880
  const dataStartRow = table.hasHeaders ? parsed.startRow + 1 : parsed.startRow;
84752
84881
  const dataEndRow = table.showTotals ? parsed.endRow - 1 : parsed.endRow;
@@ -84757,7 +84886,7 @@ function getDataBodyRangeFromInfo(table) {
84757
84886
  }
84758
84887
  function getHeaderRowRangeFromInfo(table) {
84759
84888
  if (!table.hasHeaders) return null;
84760
- const parsed = parseA1Range2(table.range);
84889
+ const parsed = parseA1Range(table.range);
84761
84890
  if (!parsed) return null;
84762
84891
  const startLetter = colToLetter2(parsed.startCol);
84763
84892
  const endLetter = colToLetter2(parsed.endCol);
@@ -84766,7 +84895,7 @@ function getHeaderRowRangeFromInfo(table) {
84766
84895
  }
84767
84896
  function getTotalRowRangeFromInfo(table) {
84768
84897
  if (!table.showTotals) return null;
84769
- const parsed = parseA1Range2(table.range);
84898
+ const parsed = parseA1Range(table.range);
84770
84899
  if (!parsed) return null;
84771
84900
  const startLetter = colToLetter2(parsed.startCol);
84772
84901
  const endLetter = colToLetter2(parsed.endCol);
@@ -85013,16 +85142,13 @@ var WorksheetTablesImpl = class {
85013
85142
  // Row CRUD
85014
85143
  // ---------------------------------------------------------------------------
85015
85144
  async addRow(tableName, index, values) {
85016
- const result = await this.ctx.computeBridge.addTableDataRow(
85017
- tableName,
85018
- index ?? null
85019
- );
85145
+ const result = await this.ctx.computeBridge.addTableDataRow(tableName, index ?? null);
85020
85146
  const insertRow = typeof result.data === "number" ? result.data : parseInt(result.data, 10);
85021
85147
  insertRows(this.ctx, this.sheetId, null, insertRow, 1, "api");
85022
85148
  if (values && values.length > 0) {
85023
85149
  const table = await this.get(tableName);
85024
85150
  if (!table) return;
85025
- const parsed = parseA1Range3(table.range);
85151
+ const parsed = parseA1Range2(table.range);
85026
85152
  if (!parsed) return;
85027
85153
  const edits = values.map((val, i) => ({
85028
85154
  row: insertRow,
@@ -85040,7 +85166,7 @@ var WorksheetTablesImpl = class {
85040
85166
  async getRowCount(tableName) {
85041
85167
  const table = await this.get(tableName);
85042
85168
  if (!table) throw new KernelError("COMPUTE_ERROR", `Table not found: ${tableName}`);
85043
- const parsed = parseA1Range3(table.range);
85169
+ const parsed = parseA1Range2(table.range);
85044
85170
  if (!parsed) return 0;
85045
85171
  const dataStartRow = table.hasHeaders ? parsed.startRow + 1 : parsed.startRow;
85046
85172
  const dataEndRow = table.showTotals ? parsed.endRow - 1 : parsed.endRow;
@@ -85049,7 +85175,7 @@ var WorksheetTablesImpl = class {
85049
85175
  async getRowRange(tableName, index) {
85050
85176
  const table = await this.get(tableName);
85051
85177
  if (!table) throw new KernelError("COMPUTE_ERROR", `Table not found: ${tableName}`);
85052
- const parsed = parseA1Range3(table.range);
85178
+ const parsed = parseA1Range2(table.range);
85053
85179
  if (!parsed) throw new KernelError("COMPUTE_ERROR", `Invalid table range: ${table.range}`);
85054
85180
  const dataStartRow = table.hasHeaders ? parsed.startRow + 1 : parsed.startRow;
85055
85181
  const absRow = dataStartRow + index;
@@ -85060,23 +85186,16 @@ var WorksheetTablesImpl = class {
85060
85186
  async getRowValues(tableName, index) {
85061
85187
  const table = await this.get(tableName);
85062
85188
  if (!table) throw new KernelError("COMPUTE_ERROR", `Table not found: ${tableName}`);
85063
- const parsed = parseA1Range3(table.range);
85189
+ const parsed = parseA1Range2(table.range);
85064
85190
  if (!parsed) return [];
85065
85191
  const dataStartRow = table.hasHeaders ? parsed.startRow + 1 : parsed.startRow;
85066
85192
  const absRow = dataStartRow + index;
85067
- const values = await this.ctx.computeBridge.getCellsInRange(
85068
- this.sheetId,
85069
- absRow,
85070
- parsed.startCol,
85071
- absRow,
85072
- parsed.endCol
85073
- );
85074
- return values;
85193
+ return queryRangeValues(this.ctx, this.sheetId, absRow, parsed.startCol, absRow, parsed.endCol);
85075
85194
  }
85076
85195
  async setRowValues(tableName, index, values) {
85077
85196
  const table = await this.get(tableName);
85078
85197
  if (!table) throw new KernelError("COMPUTE_ERROR", `Table not found: ${tableName}`);
85079
- const parsed = parseA1Range3(table.range);
85198
+ const parsed = parseA1Range2(table.range);
85080
85199
  if (!parsed) return;
85081
85200
  const dataStartRow = table.hasHeaders ? parsed.startRow + 1 : parsed.startRow;
85082
85201
  const absRow = dataStartRow + index;
@@ -85093,7 +85212,7 @@ var WorksheetTablesImpl = class {
85093
85212
  async getColumnDataBodyRange(tableName, columnIndex) {
85094
85213
  const table = await this.get(tableName);
85095
85214
  if (!table) 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;
@@ -85106,7 +85225,7 @@ var WorksheetTablesImpl = class {
85106
85225
  async getColumnHeaderRange(tableName, columnIndex) {
85107
85226
  const table = await this.get(tableName);
85108
85227
  if (!table || !table.hasHeaders) return null;
85109
- const parsed = parseA1Range3(table.range);
85228
+ const parsed = parseA1Range2(table.range);
85110
85229
  if (!parsed) return null;
85111
85230
  const col = parsed.startCol + columnIndex;
85112
85231
  if (col > parsed.endCol) return null;
@@ -85117,7 +85236,7 @@ var WorksheetTablesImpl = class {
85117
85236
  async getColumnRange(tableName, columnIndex) {
85118
85237
  const table = await this.get(tableName);
85119
85238
  if (!table) return null;
85120
- const parsed = parseA1Range3(table.range);
85239
+ const parsed = parseA1Range2(table.range);
85121
85240
  if (!parsed) return null;
85122
85241
  const col = parsed.startCol + columnIndex;
85123
85242
  if (col > parsed.endCol) return null;
@@ -85127,7 +85246,7 @@ var WorksheetTablesImpl = class {
85127
85246
  async getColumnTotalRange(tableName, columnIndex) {
85128
85247
  const table = await this.get(tableName);
85129
85248
  if (!table || !table.showTotals) return null;
85130
- const parsed = parseA1Range3(table.range);
85249
+ const parsed = parseA1Range2(table.range);
85131
85250
  if (!parsed) return null;
85132
85251
  const col = parsed.startCol + columnIndex;
85133
85252
  if (col > parsed.endCol) return null;
@@ -85138,26 +85257,19 @@ var WorksheetTablesImpl = class {
85138
85257
  async getColumnValues(tableName, columnIndex) {
85139
85258
  const table = await this.get(tableName);
85140
85259
  if (!table) throw new KernelError("COMPUTE_ERROR", `Table not found: ${tableName}`);
85141
- const parsed = parseA1Range3(table.range);
85260
+ const parsed = parseA1Range2(table.range);
85142
85261
  if (!parsed) return [];
85143
85262
  const col = parsed.startCol + columnIndex;
85144
85263
  if (col > parsed.endCol) return [];
85145
85264
  const dataStartRow = table.hasHeaders ? parsed.startRow + 1 : parsed.startRow;
85146
85265
  const dataEndRow = table.showTotals ? parsed.endRow - 1 : parsed.endRow;
85147
85266
  if (dataStartRow > dataEndRow) return [];
85148
- const values = await this.ctx.computeBridge.getCellsInRange(
85149
- this.sheetId,
85150
- dataStartRow,
85151
- col,
85152
- dataEndRow,
85153
- col
85154
- );
85155
- return values;
85267
+ return queryRangeValues(this.ctx, this.sheetId, dataStartRow, col, dataEndRow, col);
85156
85268
  }
85157
85269
  async setColumnValues(tableName, columnIndex, values) {
85158
85270
  const table = await this.get(tableName);
85159
85271
  if (!table) throw new KernelError("COMPUTE_ERROR", `Table not found: ${tableName}`);
85160
- const parsed = parseA1Range3(table.range);
85272
+ const parsed = parseA1Range2(table.range);
85161
85273
  if (!parsed) return;
85162
85274
  const col = parsed.startCol + columnIndex;
85163
85275
  if (col > parsed.endCol) return;
@@ -85175,25 +85287,30 @@ var WorksheetTablesImpl = class {
85175
85287
  async sortApply(tableName, fields) {
85176
85288
  const table = await this.get(tableName);
85177
85289
  if (!table) throw new KernelError("COMPUTE_ERROR", `Table not found: ${tableName}`);
85178
- const parsed = parseA1Range3(table.range);
85290
+ const parsed = parseA1Range2(table.range);
85179
85291
  if (!parsed) return;
85180
85292
  const dataStartRow = table.hasHeaders ? parsed.startRow + 1 : parsed.startRow;
85181
85293
  const dataEndRow = table.showTotals ? parsed.endRow - 1 : parsed.endRow;
85182
85294
  if (dataStartRow > dataEndRow) return;
85183
85295
  const numCols = parsed.endCol - parsed.startCol + 1;
85184
85296
  const numRows = dataEndRow - dataStartRow + 1;
85185
- const rawValues = await this.ctx.computeBridge.getCellsInRange(
85297
+ const rangeResult = await this.ctx.computeBridge.queryRange(
85186
85298
  this.sheetId,
85187
85299
  dataStartRow,
85188
85300
  parsed.startCol,
85189
85301
  dataEndRow,
85190
85302
  parsed.endCol
85191
85303
  );
85304
+ const cellMap = /* @__PURE__ */ new Map();
85305
+ for (const cell of rangeResult.cells) {
85306
+ cellMap.set(`${cell.row},${cell.col}`, cell);
85307
+ }
85192
85308
  const rows = [];
85193
85309
  for (let r = 0; r < numRows; r++) {
85194
85310
  const row = [];
85195
85311
  for (let c = 0; c < numCols; c++) {
85196
- row.push(rawValues[r * numCols + c] ?? "");
85312
+ const cell = cellMap.get(`${dataStartRow + r},${parsed.startCol + c}`);
85313
+ row.push(cell?.value ?? null);
85197
85314
  }
85198
85315
  rows.push(row);
85199
85316
  }
@@ -85219,10 +85336,11 @@ var WorksheetTablesImpl = class {
85219
85336
  for (let r = 0; r < numRows; r++) {
85220
85337
  const srcRow = rows[indices[r]];
85221
85338
  for (let c = 0; c < numCols; c++) {
85339
+ const val = srcRow[c];
85222
85340
  edits.push({
85223
85341
  row: dataStartRow + r,
85224
85342
  col: parsed.startCol + c,
85225
- input: srcRow[c]
85343
+ input: val == null ? "" : String(val)
85226
85344
  });
85227
85345
  }
85228
85346
  }
@@ -85238,7 +85356,7 @@ function letterToCol2(letters) {
85238
85356
  }
85239
85357
  return col - 1;
85240
85358
  }
85241
- function parseA1Range3(range2) {
85359
+ function parseA1Range2(range2) {
85242
85360
  const match = range2.match(/^([A-Z]+)(\d+):([A-Z]+)(\d+)$/i);
85243
85361
  if (!match) return null;
85244
85362
  return {
@@ -85248,6 +85366,27 @@ function parseA1Range3(range2) {
85248
85366
  endRow: parseInt(match[4], 10) - 1
85249
85367
  };
85250
85368
  }
85369
+ async function queryRangeValues(ctx, sheetId, startRow, startCol, endRow, endCol) {
85370
+ const rangeResult = await ctx.computeBridge.queryRange(
85371
+ sheetId,
85372
+ startRow,
85373
+ startCol,
85374
+ endRow,
85375
+ endCol
85376
+ );
85377
+ const cellMap = /* @__PURE__ */ new Map();
85378
+ for (const cell of rangeResult.cells) {
85379
+ cellMap.set(`${cell.row},${cell.col}`, cell);
85380
+ }
85381
+ const values = [];
85382
+ for (let r = startRow; r <= endRow; r++) {
85383
+ for (let c = startCol; c <= endCol; c++) {
85384
+ const cell = cellMap.get(`${r},${c}`);
85385
+ values.push(cell?.value ?? null);
85386
+ }
85387
+ }
85388
+ return values;
85389
+ }
85251
85390
 
85252
85391
  // ../../kernel/src/api/worksheet/validation.ts
85253
85392
  init_cjs_shims();
@@ -87683,6 +87822,16 @@ var WorksheetImpl = class {
87683
87822
  const formula = await getFormula(this.ctx, this.sheetId, row, col);
87684
87823
  return formula ?? null;
87685
87824
  }
87825
+ async getFormulas(range2) {
87826
+ const bounds = resolveRange(range2);
87827
+ return getRangeFormulas(this.ctx, this.sheetId, {
87828
+ sheetId: this.sheetId,
87829
+ startRow: bounds.startRow,
87830
+ startCol: bounds.startCol,
87831
+ endRow: bounds.endRow,
87832
+ endCol: bounds.endCol
87833
+ });
87834
+ }
87686
87835
  // ===========================================================================
87687
87836
  // Bulk reads
87688
87837
  // ===========================================================================
@@ -87758,13 +87907,10 @@ var WorksheetImpl = class {
87758
87907
  const { row, col } = resolveCell(address);
87759
87908
  const data = await getCell(this.ctx, this.sheetId, row, col);
87760
87909
  if (!data) return "";
87761
- const displayValue = await getDisplayValue2(this.ctx, this.sheetId, row, col);
87762
- let result = displayValue;
87910
+ const rawValue = viewportCellValueToString(data.value);
87911
+ let result = rawValue;
87763
87912
  if (data.formula) {
87764
- result = displayValue !== "" ? `${displayValue}(${data.formula})` : `(${data.formula})`;
87765
- }
87766
- if (data.value === 0 && displayValue !== "0" && displayValue !== "") {
87767
- result = `${result} [0]`;
87913
+ result = rawValue !== "" ? `${rawValue}(${data.formula})` : `(${data.formula})`;
87768
87914
  }
87769
87915
  const styleHintsStr = await getStyleHints(this.ctx, this.sheetId, row, col);
87770
87916
  if (styleHintsStr) {
@@ -87826,8 +87972,8 @@ var WorksheetImpl = class {
87826
87972
  rowValues.push(`${cellAddr}:`);
87827
87973
  continue;
87828
87974
  }
87829
- const displayValue = vc.formatted ?? viewportCellValueToString(vc.value);
87830
- let cellStr = displayValue;
87975
+ const rawValue = viewportCellValueToString(vc.value);
87976
+ let cellStr = rawValue;
87831
87977
  hasContent = true;
87832
87978
  if (vc.formula) {
87833
87979
  const abbreviation = formulaAnalysis.formulaToId.get(`${row},${col}`);
@@ -87837,10 +87983,6 @@ var WorksheetImpl = class {
87837
87983
  cellStr = `${cellStr}(=${vc.formula})`;
87838
87984
  }
87839
87985
  }
87840
- const cellValue = viewportCellValueToCellValue(vc.value);
87841
- if (cellValue === 0 && displayValue !== "0" && displayValue !== "") {
87842
- cellStr = `${cellStr} [0]`;
87843
- }
87844
87986
  rowValues.push(`${cellAddr}:${cellStr}`);
87845
87987
  }
87846
87988
  if (hasContent) {
@@ -87997,12 +88139,12 @@ var WorksheetImpl = class {
87997
88139
  cells.sort((a, b) => a.col - b.col);
87998
88140
  const rowData = [];
87999
88141
  for (const vc of cells) {
88000
- const displayValue = vc.formatted ?? viewportCellValueToString(vc.value);
88142
+ const rawValue = viewportCellValueToString(vc.value);
88001
88143
  const addr = toA1(vc.row, vc.col);
88002
88144
  if (vc.formula) {
88003
- rowData.push(`${addr}:${displayValue}(=${vc.formula})`);
88145
+ rowData.push(`${addr}:${rawValue}(=${vc.formula})`);
88004
88146
  } else {
88005
- rowData.push(`${addr}:${displayValue}`);
88147
+ rowData.push(`${addr}:${rawValue}`);
88006
88148
  }
88007
88149
  }
88008
88150
  if (rowData.length > 0) {
@@ -88052,18 +88194,31 @@ var WorksheetImpl = class {
88052
88194
  async findInRange(range2, text, options) {
88053
88195
  const parsed = parseCellRange(range2);
88054
88196
  if (!parsed) throw new KernelError("COMPUTE_ERROR", `Invalid range: "${range2}"`);
88055
- return findInRange(this.ctx, this.sheetId, { sheetId: this.sheetId, ...parsed }, text, {
88056
- caseSensitive: options?.matchCase,
88057
- wholeCell: options?.entireCell
88058
- });
88197
+ return findInRange(
88198
+ this.ctx,
88199
+ this.sheetId,
88200
+ { sheetId: this.sheetId, ...parsed },
88201
+ text,
88202
+ {
88203
+ caseSensitive: options?.matchCase,
88204
+ wholeCell: options?.entireCell
88205
+ }
88206
+ );
88059
88207
  }
88060
88208
  async replaceAll(range2, text, replacement, options) {
88061
88209
  const parsed = parseCellRange(range2);
88062
88210
  if (!parsed) throw new KernelError("COMPUTE_ERROR", `Invalid range: "${range2}"`);
88063
- return replaceAll(this.ctx, this.sheetId, { sheetId: this.sheetId, ...parsed }, text, replacement, {
88064
- caseSensitive: options?.matchCase,
88065
- wholeCell: options?.entireCell
88066
- });
88211
+ return replaceAll(
88212
+ this.ctx,
88213
+ this.sheetId,
88214
+ { sheetId: this.sheetId, ...parsed },
88215
+ text,
88216
+ replacement,
88217
+ {
88218
+ caseSensitive: options?.matchCase,
88219
+ wholeCell: options?.entireCell
88220
+ }
88221
+ );
88067
88222
  }
88068
88223
  async getExtendedRange(range2, direction, activeCell) {
88069
88224
  const parsed = parseCellRange(range2);
@@ -88086,17 +88241,26 @@ var WorksheetImpl = class {
88086
88241
  async getDisplayText(range2) {
88087
88242
  const parsed = parseCellRange(range2);
88088
88243
  if (!parsed) throw new KernelError("COMPUTE_ERROR", `Invalid range: "${range2}"`);
88089
- return getDisplayText(this.ctx, this.sheetId, { sheetId: this.sheetId, ...parsed });
88244
+ return getDisplayText(this.ctx, this.sheetId, {
88245
+ sheetId: this.sheetId,
88246
+ ...parsed
88247
+ });
88090
88248
  }
88091
88249
  async getValueTypes(range2) {
88092
88250
  const parsed = parseCellRange(range2);
88093
88251
  if (!parsed) throw new KernelError("COMPUTE_ERROR", `Invalid range: "${range2}"`);
88094
- return getValueTypes(this.ctx, this.sheetId, { sheetId: this.sheetId, ...parsed });
88252
+ return getValueTypes(this.ctx, this.sheetId, {
88253
+ sheetId: this.sheetId,
88254
+ ...parsed
88255
+ });
88095
88256
  }
88096
88257
  async getNumberFormatCategories(range2) {
88097
88258
  const parsed = parseCellRange(range2);
88098
88259
  if (!parsed) throw new KernelError("COMPUTE_ERROR", `Invalid range: "${range2}"`);
88099
- return getNumberFormatCategories(this.ctx, this.sheetId, { sheetId: this.sheetId, ...parsed });
88260
+ return getNumberFormatCategories(this.ctx, this.sheetId, {
88261
+ sheetId: this.sheetId,
88262
+ ...parsed
88263
+ });
88100
88264
  }
88101
88265
  // ===========================================================================
88102
88266
  // Sort / batch / autofill
@@ -88140,11 +88304,8 @@ var WorksheetImpl = class {
88140
88304
  if (!cellRange) throw new KernelError("COMPUTE_ERROR", `Invalid range: "${range2}"`);
88141
88305
  return fillSeries(this.ctx, this.sheetId, cellRange, options);
88142
88306
  }
88143
- async batchSetCells(updates) {
88144
- await batchSetCells(this.ctx, this.sheetId, updates);
88145
- }
88146
- async batchSetFormulas(updates) {
88147
- await batchSetFormulas(this.ctx, this.sheetId, updates);
88307
+ async setCells(cells) {
88308
+ return setCells(this.ctx, this.sheetId, cells);
88148
88309
  }
88149
88310
  // ===========================================================================
88150
88311
  // One-liner table creation
@@ -88290,11 +88451,21 @@ var WorksheetImpl = class {
88290
88451
  const sheetId = this.sheetId;
88291
88452
  const targetPos = resolveCell(targetCell);
88292
88453
  const changingPos = resolveCell(changingCell);
88293
- const formulaCellId = await getCellIdAt2(this.ctx, sheetId, targetPos.row, targetPos.col);
88454
+ const formulaCellId = await getCellIdAt2(
88455
+ this.ctx,
88456
+ sheetId,
88457
+ targetPos.row,
88458
+ targetPos.col
88459
+ );
88294
88460
  if (!formulaCellId) {
88295
88461
  throw new KernelError("COMPUTE_ERROR", `Target cell ${targetCell} has no content.`);
88296
88462
  }
88297
- const inputCellId = await getCellIdAt2(this.ctx, sheetId, changingPos.row, changingPos.col);
88463
+ const inputCellId = await getCellIdAt2(
88464
+ this.ctx,
88465
+ sheetId,
88466
+ changingPos.row,
88467
+ changingPos.col
88468
+ );
88298
88469
  if (!inputCellId) {
88299
88470
  throw new KernelError("COMPUTE_ERROR", `Changing cell ${changingCell} has no content.`);
88300
88471
  }
@@ -89833,18 +90004,42 @@ var STATISTICAL_FUNCTIONS = [
89833
90004
  ["BETAINV", C.STATISTICAL, "Returns the inverse of the beta distribution (compatibility)", 3, 5],
89834
90005
  ["BINOM.DIST", C.STATISTICAL, "Returns the binomial distribution probability", 4, 4],
89835
90006
  ["BINOM.DIST.RANGE", C.STATISTICAL, "Returns the binomial distribution probability range", 3, 4],
89836
- ["BINOM.INV", C.STATISTICAL, "Returns the smallest value for which the binomial CDF is >= criterion", 3, 3],
90007
+ [
90008
+ "BINOM.INV",
90009
+ C.STATISTICAL,
90010
+ "Returns the smallest value for which the binomial CDF is >= criterion",
90011
+ 3,
90012
+ 3
90013
+ ],
89837
90014
  ["BINOMDIST", C.STATISTICAL, "Returns the binomial distribution (compatibility)", 4, 4],
89838
90015
  ["CHIDIST", C.STATISTICAL, "Returns the chi-squared distribution (compatibility)", 2, 2],
89839
- ["CHIINV", C.STATISTICAL, "Returns the inverse of the chi-squared distribution (compatibility)", 2, 2],
90016
+ [
90017
+ "CHIINV",
90018
+ C.STATISTICAL,
90019
+ "Returns the inverse of the chi-squared distribution (compatibility)",
90020
+ 2,
90021
+ 2
90022
+ ],
89840
90023
  ["CHISQ.DIST", C.STATISTICAL, "Returns the chi-squared distribution", 3, 3],
89841
90024
  ["CHISQ.DIST.RT", C.STATISTICAL, "Returns the right-tailed chi-squared distribution", 2, 2],
89842
90025
  ["CHISQ.INV", C.STATISTICAL, "Returns the inverse of the chi-squared distribution", 2, 2],
89843
- ["CHISQ.INV.RT", C.STATISTICAL, "Returns the inverse of the right-tailed chi-squared distribution", 2, 2],
90026
+ [
90027
+ "CHISQ.INV.RT",
90028
+ C.STATISTICAL,
90029
+ "Returns the inverse of the right-tailed chi-squared distribution",
90030
+ 2,
90031
+ 2
90032
+ ],
89844
90033
  ["CHISQ.TEST", C.STATISTICAL, "Returns the chi-squared test statistic", 2, 2],
89845
90034
  ["CHITEST", C.STATISTICAL, "Returns the chi-squared test (compatibility)", 2, 2],
89846
90035
  ["CONFIDENCE", C.STATISTICAL, "Returns the confidence interval (compatibility)", 3, 3],
89847
- ["CONFIDENCE.NORM", C.STATISTICAL, "Returns the confidence interval using a normal distribution", 3, 3],
90036
+ [
90037
+ "CONFIDENCE.NORM",
90038
+ C.STATISTICAL,
90039
+ "Returns the confidence interval using a normal distribution",
90040
+ 3,
90041
+ 3
90042
+ ],
89848
90043
  ["CONFIDENCE.T", C.STATISTICAL, "Returns the confidence interval using a t-distribution", 3, 3],
89849
90044
  ["CORREL", C.STATISTICAL, "Returns the correlation coefficient between two data sets", 2, 2],
89850
90045
  ["COVAR", C.STATISTICAL, "Returns covariance (compatibility)", 2, 2],
@@ -89867,7 +90062,13 @@ var STATISTICAL_FUNCTIONS = [
89867
90062
  ["FORECAST.ETS", C.STATISTICAL, "Returns a forecasted value using exponential smoothing", 3, 7],
89868
90063
  ["FORECAST.ETS.CONFINT", C.STATISTICAL, "Returns a confidence interval for a forecast", 3, 7],
89869
90064
  ["FORECAST.ETS.SEASONALITY", C.STATISTICAL, "Returns the seasonal pattern length", 2, 4],
89870
- ["FORECAST.ETS.STAT", C.STATISTICAL, "Returns a statistical value for a time series forecast", 3, 7],
90065
+ [
90066
+ "FORECAST.ETS.STAT",
90067
+ C.STATISTICAL,
90068
+ "Returns a statistical value for a time series forecast",
90069
+ 3,
90070
+ 7
90071
+ ],
89871
90072
  ["FORECAST.LINEAR", C.STATISTICAL, "Returns a value along a linear trend", 3, 3],
89872
90073
  ["FREQUENCY", C.STATISTICAL, "Returns a frequency distribution as a vertical array", 2, 2],
89873
90074
  ["FTEST", C.STATISTICAL, "Returns the F-test (compatibility)", 2, 2],
@@ -89875,10 +90076,22 @@ var STATISTICAL_FUNCTIONS = [
89875
90076
  ["GAMMA.DIST", C.STATISTICAL, "Returns the gamma distribution", 4, 4],
89876
90077
  ["GAMMA.INV", C.STATISTICAL, "Returns the inverse of the gamma distribution", 3, 3],
89877
90078
  ["GAMMADIST", C.STATISTICAL, "Returns the gamma distribution (compatibility)", 4, 4],
89878
- ["GAMMAINV", C.STATISTICAL, "Returns the inverse of the gamma distribution (compatibility)", 3, 3],
90079
+ [
90080
+ "GAMMAINV",
90081
+ C.STATISTICAL,
90082
+ "Returns the inverse of the gamma distribution (compatibility)",
90083
+ 3,
90084
+ 3
90085
+ ],
89879
90086
  ["GAMMALN", C.STATISTICAL, "Returns the natural logarithm of the gamma function", 1, 1],
89880
90087
  ["GAMMALN.PRECISE", C.STATISTICAL, "Returns the natural logarithm of the gamma function", 1, 1],
89881
- ["GAUSS", C.STATISTICAL, "Returns 0.5 less than the standard normal cumulative distribution", 1, 1],
90088
+ [
90089
+ "GAUSS",
90090
+ C.STATISTICAL,
90091
+ "Returns 0.5 less than the standard normal cumulative distribution",
90092
+ 1,
90093
+ 1
90094
+ ],
89882
90095
  ["GEOMEAN", C.STATISTICAL, "Returns the geometric mean", 1, -1],
89883
90096
  ["GROWTH", C.STATISTICAL, "Returns values along an exponential trend", 1, 4],
89884
90097
  ["HARMEAN", C.STATISTICAL, "Returns the harmonic mean", 1, -1],
@@ -89888,24 +90101,54 @@ var STATISTICAL_FUNCTIONS = [
89888
90101
  ["KURT", C.STATISTICAL, "Returns the kurtosis of a data set", 1, -1],
89889
90102
  ["LINEST", C.STATISTICAL, "Returns the parameters of a linear trend", 1, 4],
89890
90103
  ["LOGEST", C.STATISTICAL, "Returns the parameters of an exponential trend", 1, 4],
89891
- ["LOGINV", C.STATISTICAL, "Returns the inverse of the lognormal distribution (compatibility)", 3, 3],
90104
+ [
90105
+ "LOGINV",
90106
+ C.STATISTICAL,
90107
+ "Returns the inverse of the lognormal distribution (compatibility)",
90108
+ 3,
90109
+ 3
90110
+ ],
89892
90111
  ["LOGNORM.DIST", C.STATISTICAL, "Returns the lognormal distribution", 4, 4],
89893
90112
  ["LOGNORM.INV", C.STATISTICAL, "Returns the inverse of the lognormal distribution", 3, 3],
89894
90113
  ["LOGNORMDIST", C.STATISTICAL, "Returns the lognormal distribution (compatibility)", 3, 3],
89895
90114
  ["MAXA", C.STATISTICAL, "Returns the maximum value including text and logical values", 1, -1],
89896
90115
  ["MINA", C.STATISTICAL, "Returns the minimum value including text and logical values", 1, -1],
89897
90116
  ["MODE", C.STATISTICAL, "Returns the most common value (compatibility)", 1, -1],
89898
- ["MODE.MULT", C.STATISTICAL, "Returns a vertical array of the most frequently occurring values", 1, -1],
90117
+ [
90118
+ "MODE.MULT",
90119
+ C.STATISTICAL,
90120
+ "Returns a vertical array of the most frequently occurring values",
90121
+ 1,
90122
+ -1
90123
+ ],
89899
90124
  ["NEGBINOM.DIST", C.STATISTICAL, "Returns the negative binomial distribution", 4, 4],
89900
- ["NEGBINOMDIST", C.STATISTICAL, "Returns the negative binomial distribution (compatibility)", 3, 3],
90125
+ [
90126
+ "NEGBINOMDIST",
90127
+ C.STATISTICAL,
90128
+ "Returns the negative binomial distribution (compatibility)",
90129
+ 3,
90130
+ 3
90131
+ ],
89901
90132
  ["NORM.DIST", C.STATISTICAL, "Returns the normal distribution", 4, 4],
89902
90133
  ["NORM.INV", C.STATISTICAL, "Returns the inverse of the normal distribution", 3, 3],
89903
90134
  ["NORM.S.DIST", C.STATISTICAL, "Returns the standard normal distribution", 2, 2],
89904
90135
  ["NORM.S.INV", C.STATISTICAL, "Returns the inverse of the standard normal distribution", 1, 1],
89905
90136
  ["NORMDIST", C.STATISTICAL, "Returns the normal distribution (compatibility)", 4, 4],
89906
- ["NORMINV", C.STATISTICAL, "Returns the inverse of the normal distribution (compatibility)", 3, 3],
90137
+ [
90138
+ "NORMINV",
90139
+ C.STATISTICAL,
90140
+ "Returns the inverse of the normal distribution (compatibility)",
90141
+ 3,
90142
+ 3
90143
+ ],
89907
90144
  ["NORMSDIST", C.STATISTICAL, "Returns the standard normal distribution (compatibility)", 1, 1],
89908
- ["NORMSINV", C.STATISTICAL, "Returns the inverse of the standard normal distribution (compatibility)", 1, 1],
90145
+ [
90146
+ "NORMSINV",
90147
+ C.STATISTICAL,
90148
+ "Returns the inverse of the standard normal distribution (compatibility)",
90149
+ 1,
90150
+ 1
90151
+ ],
89909
90152
  ["PEARSON", C.STATISTICAL, "Returns the Pearson product moment correlation coefficient", 2, 2],
89910
90153
  ["PERCENTILE", C.STATISTICAL, "Returns the k-th percentile of values (compatibility)", 2, 2],
89911
90154
  ["PERCENTILE.EXC", C.STATISTICAL, "Returns the k-th percentile (exclusive)", 2, 2],
@@ -89913,7 +90156,13 @@ var STATISTICAL_FUNCTIONS = [
89913
90156
  ["PERCENTRANK", C.STATISTICAL, "Returns the percentage rank (compatibility)", 2, 3],
89914
90157
  ["PERCENTRANK.EXC", C.STATISTICAL, "Returns the percentage rank (exclusive)", 2, 3],
89915
90158
  ["PERCENTRANK.INC", C.STATISTICAL, "Returns the percentage rank (inclusive)", 2, 3],
89916
- ["PHI", C.STATISTICAL, "Returns the value of the density function for a standard normal distribution", 1, 1],
90159
+ [
90160
+ "PHI",
90161
+ C.STATISTICAL,
90162
+ "Returns the value of the density function for a standard normal distribution",
90163
+ 1,
90164
+ 1
90165
+ ],
89917
90166
  ["POISSON", C.STATISTICAL, "Returns the Poisson distribution (compatibility)", 3, 3],
89918
90167
  ["POISSON.DIST", C.STATISTICAL, "Returns the Poisson distribution", 3, 3],
89919
90168
  ["PROB", C.STATISTICAL, "Returns the probability of values in a range", 3, 4],
@@ -89931,9 +90180,27 @@ var STATISTICAL_FUNCTIONS = [
89931
90180
  ["STDEV", C.STATISTICAL, "Estimates standard deviation based on a sample (compatibility)", 1, -1],
89932
90181
  ["STDEV.P", C.STATISTICAL, "Calculates standard deviation based on the entire population", 1, -1],
89933
90182
  ["STDEV.S", C.STATISTICAL, "Estimates standard deviation based on a sample", 1, -1],
89934
- ["STDEVA", C.STATISTICAL, "Estimates standard deviation including text and logical values", 1, -1],
89935
- ["STDEVP", C.STATISTICAL, "Calculates standard deviation based on the entire population (compatibility)", 1, -1],
89936
- ["STDEVPA", C.STATISTICAL, "Calculates standard deviation of a population including text and logical values", 1, -1],
90183
+ [
90184
+ "STDEVA",
90185
+ C.STATISTICAL,
90186
+ "Estimates standard deviation including text and logical values",
90187
+ 1,
90188
+ -1
90189
+ ],
90190
+ [
90191
+ "STDEVP",
90192
+ C.STATISTICAL,
90193
+ "Calculates standard deviation based on the entire population (compatibility)",
90194
+ 1,
90195
+ -1
90196
+ ],
90197
+ [
90198
+ "STDEVPA",
90199
+ C.STATISTICAL,
90200
+ "Calculates standard deviation of a population including text and logical values",
90201
+ 1,
90202
+ -1
90203
+ ],
89937
90204
  ["STEYX", C.STATISTICAL, "Returns the standard error of the predicted y-value", 2, 2],
89938
90205
  ["T.DIST", C.STATISTICAL, "Returns the Student t-distribution", 3, 3],
89939
90206
  ["T.DIST.2T", C.STATISTICAL, "Returns the two-tailed Student t-distribution", 2, 2],
@@ -89942,7 +90209,13 @@ var STATISTICAL_FUNCTIONS = [
89942
90209
  ["T.INV.2T", C.STATISTICAL, "Returns the inverse of the two-tailed Student t-distribution", 2, 2],
89943
90210
  ["T.TEST", C.STATISTICAL, "Returns the t-test statistic", 4, 4],
89944
90211
  ["TDIST", C.STATISTICAL, "Returns the Student t-distribution (compatibility)", 3, 3],
89945
- ["TINV", C.STATISTICAL, "Returns the inverse of the Student t-distribution (compatibility)", 2, 2],
90212
+ [
90213
+ "TINV",
90214
+ C.STATISTICAL,
90215
+ "Returns the inverse of the Student t-distribution (compatibility)",
90216
+ 2,
90217
+ 2
90218
+ ],
89946
90219
  ["TREND", C.STATISTICAL, "Returns values along a linear trend", 1, 4],
89947
90220
  ["TRIMMEAN", C.STATISTICAL, "Returns the mean of the interior of a data set", 2, 2],
89948
90221
  ["TTEST", C.STATISTICAL, "Returns the t-test (compatibility)", 4, 4],
@@ -89950,8 +90223,20 @@ var STATISTICAL_FUNCTIONS = [
89950
90223
  ["VAR.P", C.STATISTICAL, "Calculates variance based on the entire population", 1, -1],
89951
90224
  ["VAR.S", C.STATISTICAL, "Estimates variance based on a sample", 1, -1],
89952
90225
  ["VARA", C.STATISTICAL, "Estimates variance including text and logical values", 1, -1],
89953
- ["VARP", C.STATISTICAL, "Calculates variance based on the entire population (compatibility)", 1, -1],
89954
- ["VARPA", C.STATISTICAL, "Calculates variance of a population including text and logical values", 1, -1],
90226
+ [
90227
+ "VARP",
90228
+ C.STATISTICAL,
90229
+ "Calculates variance based on the entire population (compatibility)",
90230
+ 1,
90231
+ -1
90232
+ ],
90233
+ [
90234
+ "VARPA",
90235
+ C.STATISTICAL,
90236
+ "Calculates variance of a population including text and logical values",
90237
+ 1,
90238
+ -1
90239
+ ],
89955
90240
  ["WEIBULL", C.STATISTICAL, "Returns the Weibull distribution (compatibility)", 4, 4],
89956
90241
  ["WEIBULL.DIST", C.STATISTICAL, "Returns the Weibull distribution", 4, 4],
89957
90242
  ["Z.TEST", C.STATISTICAL, "Returns the one-tailed P-value of a z-test", 2, 3],
@@ -89959,37 +90244,103 @@ var STATISTICAL_FUNCTIONS = [
89959
90244
  ];
89960
90245
  var DATETIME_FUNCTIONS = [
89961
90246
  ["DATE", C.DATE_TIME, "Returns the serial number of a particular date", 3, 3],
89962
- ["DATEDIF", C.DATE_TIME, "Calculates the number of days, months, or years between two dates", 3, 3],
90247
+ [
90248
+ "DATEDIF",
90249
+ C.DATE_TIME,
90250
+ "Calculates the number of days, months, or years between two dates",
90251
+ 3,
90252
+ 3
90253
+ ],
89963
90254
  ["DATEVALUE", C.DATE_TIME, "Converts a date in text format to a serial number", 1, 1],
89964
90255
  ["DAY", C.DATE_TIME, "Converts a serial number to a day of the month", 1, 1],
89965
90256
  ["DAYS", C.DATE_TIME, "Returns the number of days between two dates", 2, 2],
89966
- ["DAYS360", C.DATE_TIME, "Calculates the number of days between two dates on a 360-day year", 2, 3],
89967
- ["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],
90257
+ [
90258
+ "DAYS360",
90259
+ C.DATE_TIME,
90260
+ "Calculates the number of days between two dates on a 360-day year",
90261
+ 2,
90262
+ 3
90263
+ ],
90264
+ [
90265
+ "EDATE",
90266
+ C.DATE_TIME,
90267
+ "Returns the serial number of a date that is a given number of months before or after the start date",
90268
+ 2,
90269
+ 2
90270
+ ],
89968
90271
  ["EOMONTH", C.DATE_TIME, "Returns the serial number of the last day of the month", 2, 2],
89969
90272
  ["HOUR", C.DATE_TIME, "Converts a serial number to an hour", 1, 1],
89970
90273
  ["ISOWEEKNUM", C.DATE_TIME, "Returns the ISO week number of the year", 1, 1],
89971
90274
  ["MINUTE", C.DATE_TIME, "Converts a serial number to a minute", 1, 1],
89972
90275
  ["MONTH", C.DATE_TIME, "Converts a serial number to a month", 1, 1],
89973
90276
  ["NETWORKDAYS", C.DATE_TIME, "Returns the number of whole workdays between two dates", 2, 3],
89974
- ["NETWORKDAYS.INTL", C.DATE_TIME, "Returns the number of whole workdays between two dates (custom weekends)", 2, 4],
90277
+ [
90278
+ "NETWORKDAYS.INTL",
90279
+ C.DATE_TIME,
90280
+ "Returns the number of whole workdays between two dates (custom weekends)",
90281
+ 2,
90282
+ 4
90283
+ ],
89975
90284
  ["SECOND", C.DATE_TIME, "Converts a serial number to a second", 1, 1],
89976
90285
  ["TIME", C.DATE_TIME, "Returns the serial number of a particular time", 3, 3],
89977
90286
  ["TIMEVALUE", C.DATE_TIME, "Converts a time in text format to a serial number", 1, 1],
89978
90287
  ["WEEKDAY", C.DATE_TIME, "Converts a serial number to a day of the week", 1, 2],
89979
90288
  ["WEEKNUM", C.DATE_TIME, "Returns the week number of the year", 1, 2],
89980
- ["WORKDAY", C.DATE_TIME, "Returns a date that is a given number of workdays before or after", 2, 3],
89981
- ["WORKDAY.INTL", C.DATE_TIME, "Returns a date that is a given number of workdays before or after (custom weekends)", 2, 4],
90289
+ [
90290
+ "WORKDAY",
90291
+ C.DATE_TIME,
90292
+ "Returns a date that is a given number of workdays before or after",
90293
+ 2,
90294
+ 3
90295
+ ],
90296
+ [
90297
+ "WORKDAY.INTL",
90298
+ C.DATE_TIME,
90299
+ "Returns a date that is a given number of workdays before or after (custom weekends)",
90300
+ 2,
90301
+ 4
90302
+ ],
89982
90303
  ["YEAR", C.DATE_TIME, "Converts a serial number to a year", 1, 1],
89983
- ["YEARFRAC", C.DATE_TIME, "Returns the year fraction representing the number of whole days", 2, 3]
90304
+ [
90305
+ "YEARFRAC",
90306
+ C.DATE_TIME,
90307
+ "Returns the year fraction representing the number of whole days",
90308
+ 2,
90309
+ 3
90310
+ ]
89984
90311
  ];
89985
90312
  var FINANCIAL_FUNCTIONS = [
89986
90313
  ["ACCRINT", C.FINANCIAL, "Returns the accrued interest for a security", 6, 8],
89987
- ["ACCRINTM", C.FINANCIAL, "Returns the accrued interest for a security that pays at maturity", 3, 5],
90314
+ [
90315
+ "ACCRINTM",
90316
+ C.FINANCIAL,
90317
+ "Returns the accrued interest for a security that pays at maturity",
90318
+ 3,
90319
+ 5
90320
+ ],
89988
90321
  ["AMORDEGRC", C.FINANCIAL, "Returns the depreciation for each accounting period (French)", 6, 7],
89989
- ["AMORLINC", C.FINANCIAL, "Returns the depreciation for each accounting period (French, linear)", 6, 7],
89990
- ["COUPDAYBS", C.FINANCIAL, "Returns the number of days from the beginning of the coupon period", 3, 4],
90322
+ [
90323
+ "AMORLINC",
90324
+ C.FINANCIAL,
90325
+ "Returns the depreciation for each accounting period (French, linear)",
90326
+ 6,
90327
+ 7
90328
+ ],
90329
+ [
90330
+ "COUPDAYBS",
90331
+ C.FINANCIAL,
90332
+ "Returns the number of days from the beginning of the coupon period",
90333
+ 3,
90334
+ 4
90335
+ ],
89991
90336
  ["COUPDAYS", C.FINANCIAL, "Returns the number of days in the coupon period", 3, 4],
89992
- ["COUPDAYSNC", C.FINANCIAL, "Returns the number of days from the settlement date to the next coupon", 3, 4],
90337
+ [
90338
+ "COUPDAYSNC",
90339
+ C.FINANCIAL,
90340
+ "Returns the number of days from the settlement date to the next coupon",
90341
+ 3,
90342
+ 4
90343
+ ],
89993
90344
  ["COUPNCD", C.FINANCIAL, "Returns the next coupon date after the settlement date", 3, 4],
89994
90345
  ["COUPNUM", C.FINANCIAL, "Returns the number of coupons payable", 3, 4],
89995
90346
  ["COUPPCD", C.FINANCIAL, "Returns the previous coupon date before the settlement date", 3, 4],
@@ -90014,15 +90365,39 @@ var FINANCIAL_FUNCTIONS = [
90014
90365
  ["NOMINAL", C.FINANCIAL, "Returns the annual nominal interest rate", 2, 2],
90015
90366
  ["NPER", C.FINANCIAL, "Returns the number of periods for an investment", 3, 5],
90016
90367
  ["NPV", C.FINANCIAL, "Returns the net present value of an investment", 2, -1],
90017
- ["PDURATION", C.FINANCIAL, "Returns the number of periods for an investment to reach a value", 3, 3],
90368
+ [
90369
+ "PDURATION",
90370
+ C.FINANCIAL,
90371
+ "Returns the number of periods for an investment to reach a value",
90372
+ 3,
90373
+ 3
90374
+ ],
90018
90375
  ["PMT", C.FINANCIAL, "Returns the periodic payment for an annuity", 3, 5],
90019
90376
  ["PPMT", C.FINANCIAL, "Returns the payment on the principal", 4, 6],
90020
90377
  ["PRICE", C.FINANCIAL, "Returns the price per $100 face value of a security", 6, 7],
90021
- ["PRICEDISC", C.FINANCIAL, "Returns the price per $100 face value of a discounted security", 4, 5],
90022
- ["PRICEMAT", C.FINANCIAL, "Returns the price per $100 face value of a security that pays at maturity", 5, 6],
90378
+ [
90379
+ "PRICEDISC",
90380
+ C.FINANCIAL,
90381
+ "Returns the price per $100 face value of a discounted security",
90382
+ 4,
90383
+ 5
90384
+ ],
90385
+ [
90386
+ "PRICEMAT",
90387
+ C.FINANCIAL,
90388
+ "Returns the price per $100 face value of a security that pays at maturity",
90389
+ 5,
90390
+ 6
90391
+ ],
90023
90392
  ["PV", C.FINANCIAL, "Returns the present value of an investment", 3, 5],
90024
90393
  ["RATE", C.FINANCIAL, "Returns the interest rate per period", 3, 6],
90025
- ["RECEIVED", C.FINANCIAL, "Returns the amount received at maturity for a fully invested security", 4, 5],
90394
+ [
90395
+ "RECEIVED",
90396
+ C.FINANCIAL,
90397
+ "Returns the amount received at maturity for a fully invested security",
90398
+ 4,
90399
+ 5
90400
+ ],
90026
90401
  ["RRI", C.FINANCIAL, "Returns an equivalent interest rate for growth", 3, 3],
90027
90402
  ["SLN", C.FINANCIAL, "Returns the straight-line depreciation", 3, 3],
90028
90403
  ["SYD", C.FINANCIAL, "Returns the sum-of-years digits depreciation", 4, 4],
@@ -90047,9 +90422,21 @@ var ENGINEERING_FUNCTIONS = [
90047
90422
  ["BITAND", C.ENGINEERING, "Returns a bitwise AND of two numbers", 2, 2],
90048
90423
  ["BITLSHIFT", C.ENGINEERING, "Returns a number shifted left by a specified number of bits", 2, 2],
90049
90424
  ["BITOR", C.ENGINEERING, "Returns a bitwise OR of two numbers", 2, 2],
90050
- ["BITRSHIFT", C.ENGINEERING, "Returns a number shifted right by a specified number of bits", 2, 2],
90425
+ [
90426
+ "BITRSHIFT",
90427
+ C.ENGINEERING,
90428
+ "Returns a number shifted right by a specified number of bits",
90429
+ 2,
90430
+ 2
90431
+ ],
90051
90432
  ["BITXOR", C.ENGINEERING, "Returns a bitwise XOR of two numbers", 2, 2],
90052
- ["COMPLEX", C.ENGINEERING, "Converts real and imaginary coefficients into a complex number", 2, 3],
90433
+ [
90434
+ "COMPLEX",
90435
+ C.ENGINEERING,
90436
+ "Converts real and imaginary coefficients into a complex number",
90437
+ 2,
90438
+ 3
90439
+ ],
90053
90440
  ["CONVERT", C.ENGINEERING, "Converts a number from one measurement system to another", 3, 3],
90054
90441
  ["DEC2BIN", C.ENGINEERING, "Converts a decimal number to binary", 1, 2],
90055
90442
  ["DEC2HEX", C.ENGINEERING, "Converts a decimal number to hexadecimal", 1, 2],
@@ -91603,6 +91990,14 @@ var api_spec_default = {
91603
91990
  "ask"
91604
91991
  ]
91605
91992
  },
91993
+ getFormulas: {
91994
+ signature: "getFormulas(range: string): Promise<(string | null)[][]>;",
91995
+ docstring: "Get formulas for a range. Returns 2D array: formula string or null per cell.",
91996
+ usedTypes: [],
91997
+ tags: [
91998
+ "ask"
91999
+ ]
92000
+ },
91606
92001
  getRawCellData: {
91607
92002
  signature: "getRawCellData(address: string, includeFormula?: boolean): Promise<RawCellData>;",
91608
92003
  docstring: "Get raw cell data (value, formula, format, borders, etc.) by A1 address.",
@@ -91678,7 +92073,7 @@ var api_spec_default = {
91678
92073
  ]
91679
92074
  },
91680
92075
  findDataEdge: {
91681
- signature: "findDataEdge(row: number, col: number, direction: 'up' | 'down' | 'left' | 'right'): Promise<{row: number; col: number}>;",
92076
+ signature: "findDataEdge(\n row: number,\n col: number,\n direction: 'up' | 'down' | 'left' | 'right',\n ): Promise<{ row: number; col: number }>;",
91682
92077
  docstring: "Find the data edge in a direction (Excel's Ctrl+Arrow). Single bridge call to Rust.",
91683
92078
  usedTypes: [],
91684
92079
  tags: [
@@ -91824,18 +92219,12 @@ var api_spec_default = {
91824
92219
  "action"
91825
92220
  ]
91826
92221
  },
91827
- batchSetCells: {
91828
- signature: "batchSetCells(updates: Array<{ row: number; col: number; value: any }>): Promise<void>;",
91829
- 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.",
91830
- usedTypes: [],
91831
- tags: [
91832
- "action"
91833
- ]
91834
- },
91835
- batchSetFormulas: {
91836
- signature: "batchSetFormulas(updates: Array<{ row: number; col: number; formula: string }>): Promise<void>;",
91837
- docstring: 'Batch-write cell formulas (fire-and-forget to compute engine).\nEach formula string should start with "=".',
91838
- usedTypes: [],
92222
+ setCells: {
92223
+ signature: "setCells(cells: Array<{ addr: string; value: any }>): Promise<SetCellsResult>;",
92224
+ 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.',
92225
+ usedTypes: [
92226
+ "SetCellsResult"
92227
+ ],
91839
92228
  tags: [
91840
92229
  "action"
91841
92230
  ]
@@ -92046,7 +92435,7 @@ var api_spec_default = {
92046
92435
  ]
92047
92436
  },
92048
92437
  on: {
92049
- signature: "on(event: 'sheetAdded' | 'sheetRemoved' | 'sheetRenamed' | 'activeSheetChanged', handler: (event: any) => void): () => void;",
92438
+ signature: "on(\n event: 'sheetAdded' | 'sheetRemoved' | 'sheetRenamed' | 'activeSheetChanged',\n handler: (event: any) => void,\n ): () => void;",
92050
92439
  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",
92051
92440
  usedTypes: [],
92052
92441
  tags: [
@@ -94708,7 +95097,7 @@ var api_spec_default = {
94708
95097
  ]
94709
95098
  },
94710
95099
  sortApply: {
94711
- signature: "sortApply(tableName: string, fields: Array<{ columnIndex: number; ascending?: boolean }>): Promise<void>;",
95100
+ signature: "sortApply(\n tableName: string,\n fields: Array<{ columnIndex: number; ascending?: boolean }>,\n ): Promise<void>;",
94712
95101
  docstring: "Apply sort fields to a table.\n\n@param tableName - Table name\n@param fields - Array of sort field descriptors",
94713
95102
  usedTypes: [],
94714
95103
  tags: [
@@ -94882,6 +95271,17 @@ var api_spec_default = {
94882
95271
  "ask"
94883
95272
  ]
94884
95273
  },
95274
+ queryPivot: {
95275
+ signature: "queryPivot(\n pivotName: string,\n filters?: Record<string, CellValue | CellValue[]>,\n ): Promise<PivotQueryResult | null>;",
95276
+ 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",
95277
+ usedTypes: [
95278
+ "CellValue",
95279
+ "PivotQueryResult"
95280
+ ],
95281
+ tags: [
95282
+ "ask"
95283
+ ]
95284
+ },
94885
95285
  refresh: {
94886
95286
  signature: "refresh(pivotId: string): Promise<void>;",
94887
95287
  docstring: "Refresh a pivot table (recompute without cache).\n\n@param pivotId - Pivot table ID",
@@ -94899,7 +95299,7 @@ var api_spec_default = {
94899
95299
  ]
94900
95300
  },
94901
95301
  addCalculatedField: {
94902
- signature: "addCalculatedField(\n pivotId: string,\n field: CalculatedField,\n ): Promise<void>;",
95302
+ signature: "addCalculatedField(pivotId: string, field: CalculatedField): Promise<void>;",
94903
95303
  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)",
94904
95304
  usedTypes: [
94905
95305
  "CalculatedField"
@@ -96379,8 +96779,8 @@ Example: { ignoreError: true } to suppress error indicators. */
96379
96779
  width: number;
96380
96780
  /** Chart height in cells */
96381
96781
  height: number;
96382
- /** Data range in A1 notation (e.g., "A1:D10") */
96383
- dataRange: string;
96782
+ /** Data range in A1 notation (e.g., "A1:D10"). Optional when series[].values are provided. */
96783
+ dataRange?: string;
96384
96784
  /** Series labels range in A1 notation */
96385
96785
  seriesRange?: string;
96386
96786
  /** Category labels range in A1 notation */
@@ -96978,6 +97378,16 @@ Used in condition filters where users specify rules like
96978
97378
  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}",
96979
97379
  docstring: "Pie/doughnut slice configuration for exploded slices"
96980
97380
  },
97381
+ PivotQueryRecord: {
97382
+ name: "PivotQueryRecord",
97383
+ 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}',
97384
+ docstring: "A single flat record from a pivot query result."
97385
+ },
97386
+ PivotQueryResult: {
97387
+ name: "PivotQueryResult",
97388
+ 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}",
97389
+ docstring: "Result of queryPivot() \u2014 flat, agent-friendly records instead of hierarchy trees."
97390
+ },
96981
97391
  PivotTableConfig: {
96982
97392
  name: "PivotTableConfig",
96983
97393
  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}',
@@ -96990,7 +97400,7 @@ Used in condition filters where users specify rules like
96990
97400
  },
96991
97401
  PivotTableInfo: {
96992
97402
  name: "PivotTableInfo",
96993
- 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}",
97403
+ 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}',
96994
97404
  docstring: "Summary information about an existing pivot table."
96995
97405
  },
96996
97406
  PivotValueField: {
@@ -97128,6 +97538,11 @@ Used in condition filters where users specify rules like
97128
97538
  definition: "'rows' | 'columns'",
97129
97539
  docstring: "Data series orientation"
97130
97540
  },
97541
+ SetCellsResult: {
97542
+ name: "SetCellsResult",
97543
+ 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}",
97544
+ docstring: "Result of a bulk setCells() operation."
97545
+ },
97131
97546
  ShadowAlignment: {
97132
97547
  name: "ShadowAlignment",
97133
97548
  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'",
@@ -97530,7 +97945,7 @@ Used in condition filters where users specify rules like
97530
97945
  docstring: "A summary snapshot of the entire workbook state."
97531
97946
  }
97532
97947
  },
97533
- generated: "2026-04-01T00:10:05.279Z"
97948
+ generated: "2026-04-01T18:35:30.029Z"
97534
97949
  };
97535
97950
 
97536
97951
  // src/api-describe.ts
@@ -97546,6 +97961,44 @@ var rootInterfaces = {
97546
97961
  wb: "Workbook",
97547
97962
  ws: "Worksheet"
97548
97963
  };
97964
+ var BUILTIN_TYPE_NAMES = /* @__PURE__ */ new Set([
97965
+ "Promise",
97966
+ "Partial",
97967
+ "Required",
97968
+ "Readonly",
97969
+ "Pick",
97970
+ "Omit",
97971
+ "Array",
97972
+ "Record",
97973
+ "Map",
97974
+ "Set",
97975
+ "Uint8Array",
97976
+ "ArrayBuffer",
97977
+ "Function",
97978
+ "Object",
97979
+ "Date",
97980
+ "RegExp",
97981
+ "Error",
97982
+ "Symbol",
97983
+ "string",
97984
+ "number",
97985
+ "boolean",
97986
+ "void",
97987
+ "null",
97988
+ "undefined",
97989
+ "any",
97990
+ "never",
97991
+ "unknown"
97992
+ ]);
97993
+ function extractTypeRefs(definition) {
97994
+ const refs = [];
97995
+ for (const [, name] of definition.matchAll(/\b([A-Z][A-Za-z0-9]+)\b/g)) {
97996
+ if (!BUILTIN_TYPE_NAMES.has(name)) {
97997
+ refs.push(name);
97998
+ }
97999
+ }
98000
+ return refs;
98001
+ }
97549
98002
  function getMethodsExcludingAccessors(ifaceName, root) {
97550
98003
  const iface = api_spec_default.interfaces[ifaceName];
97551
98004
  if (!iface) return [];
@@ -97641,10 +98094,20 @@ function resolveMethod(ifaceName, methodName, fullPath) {
97641
98094
  const fn = iface.functions[methodName];
97642
98095
  if (!fn) return null;
97643
98096
  const types = {};
97644
- for (const typeName of fn.usedTypes) {
98097
+ const queue = [...fn.usedTypes];
98098
+ const seen = new Set(queue);
98099
+ while (queue.length > 0) {
98100
+ const typeName = queue.shift();
97645
98101
  const resolved = resolveType(typeName);
97646
- if (resolved) {
97647
- types[typeName] = resolved;
98102
+ if (!resolved) continue;
98103
+ types[typeName] = resolved;
98104
+ if (resolved.definition) {
98105
+ for (const ref of extractTypeRefs(resolved.definition)) {
98106
+ if (!seen.has(ref)) {
98107
+ seen.add(ref);
98108
+ queue.push(ref);
98109
+ }
98110
+ }
97648
98111
  }
97649
98112
  }
97650
98113
  return {
@@ -97656,7 +98119,104 @@ function resolveMethod(ifaceName, methodName, fullPath) {
97656
98119
  types
97657
98120
  };
97658
98121
  }
97659
- var api = { describe };
98122
+ var methodCache = /* @__PURE__ */ new Map();
98123
+ function cachedResolveMethod(ifaceName, methodName, fullPath) {
98124
+ if (methodCache.has(fullPath)) return methodCache.get(fullPath);
98125
+ const result = resolveMethod(ifaceName, methodName, fullPath);
98126
+ methodCache.set(fullPath, result);
98127
+ return result;
98128
+ }
98129
+ var RESERVED_PROPS = /* @__PURE__ */ new Set([
98130
+ "name",
98131
+ "path",
98132
+ "docstring",
98133
+ "methods",
98134
+ "subApis",
98135
+ "types",
98136
+ "tags",
98137
+ "signature"
98138
+ ]);
98139
+ function buildSubApiNode(ifaceName, root, accessor) {
98140
+ const iface = api_spec_default.interfaces[ifaceName];
98141
+ const fullPath = `${root}.${accessor}`;
98142
+ const node = {
98143
+ name: ifaceName,
98144
+ path: fullPath,
98145
+ docstring: iface?.docstring ?? "",
98146
+ methods: buildMethodSummaries(ifaceName)
98147
+ };
98148
+ if (iface) {
98149
+ for (const methodName of Object.keys(iface.functions)) {
98150
+ if (RESERVED_PROPS.has(methodName)) continue;
98151
+ Object.defineProperty(node, methodName, {
98152
+ get() {
98153
+ return cachedResolveMethod(ifaceName, methodName, `${fullPath}.${methodName}`);
98154
+ },
98155
+ enumerable: true,
98156
+ configurable: true
98157
+ });
98158
+ }
98159
+ }
98160
+ return node;
98161
+ }
98162
+ function buildRootNode(root) {
98163
+ const ifaceName = rootInterfaces[root];
98164
+ const accessors = subApiAccessors[root] ?? /* @__PURE__ */ new Set();
98165
+ const node = {
98166
+ name: ifaceName,
98167
+ methods: buildMethodSummaries(ifaceName, accessors),
98168
+ subApis: [...accessors]
98169
+ };
98170
+ const subs = api_spec_default.subApis[root] ?? {};
98171
+ for (const [accessor, subIfaceName] of Object.entries(subs)) {
98172
+ if (RESERVED_PROPS.has(accessor)) continue;
98173
+ let cached;
98174
+ Object.defineProperty(node, accessor, {
98175
+ get() {
98176
+ if (!cached) cached = buildSubApiNode(subIfaceName, root, accessor);
98177
+ return cached;
98178
+ },
98179
+ enumerable: true,
98180
+ configurable: true
98181
+ });
98182
+ }
98183
+ const iface = api_spec_default.interfaces[ifaceName];
98184
+ if (iface) {
98185
+ for (const methodName of Object.keys(iface.functions)) {
98186
+ if (accessors.has(methodName) || RESERVED_PROPS.has(methodName) || methodName in node)
98187
+ continue;
98188
+ Object.defineProperty(node, methodName, {
98189
+ get() {
98190
+ return cachedResolveMethod(ifaceName, methodName, `${root}.${methodName}`);
98191
+ },
98192
+ enumerable: true,
98193
+ configurable: true
98194
+ });
98195
+ }
98196
+ }
98197
+ return node;
98198
+ }
98199
+ function buildTypesNode() {
98200
+ const node = {};
98201
+ for (const name of Object.keys(api_spec_default.types)) {
98202
+ let cached;
98203
+ Object.defineProperty(node, name, {
98204
+ get() {
98205
+ if (cached === void 0) cached = resolveType(name);
98206
+ return cached;
98207
+ },
98208
+ enumerable: true,
98209
+ configurable: true
98210
+ });
98211
+ }
98212
+ return node;
98213
+ }
98214
+ var api = {
98215
+ describe,
98216
+ wb: buildRootNode("wb"),
98217
+ ws: buildRootNode("ws"),
98218
+ types: buildTypesNode()
98219
+ };
97660
98220
 
97661
98221
  // src/boot.ts
97662
98222
  init_cjs_shims();
@@ -97779,8 +98339,6 @@ var HeadlessEngine = class {
97779
98339
  ctx: this.context,
97780
98340
  eventBus: this.context.eventBus
97781
98341
  });
97782
- this._workbook.getActiveSheet();
97783
- await this._workbook.refreshSheetMetadata();
97784
98342
  }
97785
98343
  /**
97786
98344
  * Get or set the active sheet ID.
@@ -97856,7 +98414,13 @@ var CoordinatorHandle = class _CoordinatorHandle {
97856
98414
  }
97857
98415
  push(participantId, update4, touchedSheetIds, participantSv) {
97858
98416
  const fn = this.addon["coordinator_push"];
97859
- const result = fn(this.handle, participantId, Buffer.from(update4), touchedSheetIds, Buffer.from(participantSv));
98417
+ const result = fn(
98418
+ this.handle,
98419
+ participantId,
98420
+ Buffer.from(update4),
98421
+ touchedSheetIds,
98422
+ Buffer.from(participantSv)
98423
+ );
97860
98424
  return typeof result === "string" ? JSON.parse(result) : result;
97861
98425
  }
97862
98426
  pull(participantId, participantSv) {
@@ -97993,14 +98557,7 @@ var CollaborativeEngine = class _CollaborativeEngine {
97993
98557
  await engine.computeBridge.syncApply(pushRaw.serverDiff);
97994
98558
  }
97995
98559
  }
97996
- return new _CollaborativeEngine(
97997
- engine,
97998
- coordinator,
97999
- participantId,
98000
- syncMode,
98001
- 10,
98002
- false
98003
- );
98560
+ return new _CollaborativeEngine(engine, coordinator, participantId, syncMode, 10, false);
98004
98561
  }
98005
98562
  // ---------------------------------------------------------------------------
98006
98563
  // Public API
@@ -98089,11 +98646,7 @@ var CollaborativeEngine = class _CollaborativeEngine {
98089
98646
  // ---------------------------------------------------------------------------
98090
98647
  /** Acquire a lock. Returns lock ID. */
98091
98648
  async lock(scope, ttlSeconds = 60) {
98092
- return this._coordinator.acquireLock(
98093
- this._participantId,
98094
- scope,
98095
- ttlSeconds * 1e3
98096
- );
98649
+ return this._coordinator.acquireLock(this._participantId, scope, ttlSeconds * 1e3);
98097
98650
  }
98098
98651
  /** Release a lock. */
98099
98652
  async unlock(lockId) {