@univerjs/engine-formula 0.22.1 → 0.23.0

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/lib/cjs/index.js CHANGED
@@ -27,9 +27,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
 
28
28
  //#endregion
29
29
  let _univerjs_core = require("@univerjs/core");
30
- let rxjs = require("rxjs");
31
30
  let _flatten_js_interval_tree = require("@flatten-js/interval-tree");
32
31
  _flatten_js_interval_tree = __toESM(_flatten_js_interval_tree);
32
+ let rxjs = require("rxjs");
33
33
  let decimal_js = require("decimal.js");
34
34
  decimal_js = __toESM(decimal_js);
35
35
  let _univerjs_rpc = require("@univerjs/rpc");
@@ -1132,6 +1132,181 @@ let FunctionType = /* @__PURE__ */ function(FunctionType) {
1132
1132
  return FunctionType;
1133
1133
  }({});
1134
1134
 
1135
+ //#endregion
1136
+ //#region src/basics/inverted-index-cache.ts
1137
+ const DEFAULT_EMPTY_CELL_KEY = Symbol("EMPTY_CELL");
1138
+ const normalizedValueMap = /* @__PURE__ */ new Map();
1139
+ function normalizeValue(value) {
1140
+ if (normalizedValueMap.has(value)) return normalizedValueMap.get(value);
1141
+ let _value;
1142
+ if (value === null || value === void 0 || value === "") _value = DEFAULT_EMPTY_CELL_KEY;
1143
+ else if ((0, _univerjs_core.isRealNum)(value) && Number(value).toString() === value.toString()) _value = Number(value) === 0 ? 0 : Number(value);
1144
+ else if (typeof value === "string") _value = value.toLowerCase();
1145
+ else _value = value;
1146
+ normalizedValueMap.set(value, _value);
1147
+ return _value;
1148
+ }
1149
+ var InvertedIndexCache = class {
1150
+ constructor() {
1151
+ _defineProperty(this, "_cache", /* @__PURE__ */ new Map());
1152
+ _defineProperty(this, "_continueBuildingCache", /* @__PURE__ */ new Map());
1153
+ }
1154
+ set(unitId, sheetId, column, value, row, isForceUpdate = false) {
1155
+ if (!this.shouldContinueBuildingCache(unitId, sheetId, column, row) && !isForceUpdate) return;
1156
+ let unitMap = this._cache.get(unitId);
1157
+ if (unitMap == null) {
1158
+ unitMap = /* @__PURE__ */ new Map();
1159
+ this._cache.set(unitId, unitMap);
1160
+ }
1161
+ let sheetMap = unitMap.get(sheetId);
1162
+ if (sheetMap == null) {
1163
+ sheetMap = /* @__PURE__ */ new Map();
1164
+ unitMap.set(sheetId, sheetMap);
1165
+ }
1166
+ let columnMap = sheetMap.get(column);
1167
+ if (columnMap == null) {
1168
+ columnMap = /* @__PURE__ */ new Map();
1169
+ sheetMap.set(column, columnMap);
1170
+ }
1171
+ if (isForceUpdate) {
1172
+ for (const [_, _cellList] of columnMap) if (_cellList.has(row)) {
1173
+ _cellList.delete(row);
1174
+ break;
1175
+ }
1176
+ }
1177
+ const _value = normalizeValue(value);
1178
+ let cellList = columnMap.get(_value);
1179
+ if (cellList == null) {
1180
+ cellList = /* @__PURE__ */ new Set();
1181
+ columnMap.set(_value, cellList);
1182
+ }
1183
+ cellList.add(row);
1184
+ }
1185
+ getCellValuePositions(unitId, sheetId, column) {
1186
+ var _this$_cache$get;
1187
+ return (_this$_cache$get = this._cache.get(unitId)) === null || _this$_cache$get === void 0 || (_this$_cache$get = _this$_cache$get.get(sheetId)) === null || _this$_cache$get === void 0 ? void 0 : _this$_cache$get.get(column);
1188
+ }
1189
+ getCellPositions(unitId, sheetId, column, value, rowsInCache) {
1190
+ var _this$_cache$get2;
1191
+ const columnMap = (_this$_cache$get2 = this._cache.get(unitId)) === null || _this$_cache$get2 === void 0 || (_this$_cache$get2 = _this$_cache$get2.get(sheetId)) === null || _this$_cache$get2 === void 0 ? void 0 : _this$_cache$get2.get(column);
1192
+ if (!columnMap) return;
1193
+ const result = {
1194
+ errorType: null,
1195
+ matchingRows: []
1196
+ };
1197
+ const _value = normalizeValue(value);
1198
+ if (ERROR_TYPE_SET.has(_value)) result.errorType = _value;
1199
+ else if (_value === 0 || _value === DEFAULT_EMPTY_CELL_KEY) {
1200
+ const rows = [];
1201
+ const rowsForZero = columnMap.get(0);
1202
+ if (rowsForZero) rows.push(...rowsForZero);
1203
+ const rowsForEmpty = columnMap.get(DEFAULT_EMPTY_CELL_KEY);
1204
+ if (rowsForEmpty) rows.push(...rowsForEmpty);
1205
+ result.matchingRows = rows.filter((row) => rowsInCache.some(([start, end]) => row >= start && row <= end));
1206
+ } else {
1207
+ var _columnMap$get;
1208
+ result.matchingRows = Array.from((_columnMap$get = columnMap.get(_value)) !== null && _columnMap$get !== void 0 ? _columnMap$get : []).filter((row) => rowsInCache.some(([start, end]) => row >= start && row <= end));
1209
+ }
1210
+ return result;
1211
+ }
1212
+ setContinueBuildingCache(unitId, sheetId, column, startRow, endRow) {
1213
+ if (column === -1 || startRow === -1 || endRow === -1) return;
1214
+ let unitMap = this._continueBuildingCache.get(unitId);
1215
+ if (unitMap == null) {
1216
+ unitMap = /* @__PURE__ */ new Map();
1217
+ this._continueBuildingCache.set(unitId, unitMap);
1218
+ }
1219
+ let sheetMap = unitMap.get(sheetId);
1220
+ if (sheetMap == null) {
1221
+ sheetMap = /* @__PURE__ */ new Map();
1222
+ unitMap.set(sheetId, sheetMap);
1223
+ }
1224
+ let columnMap = sheetMap.get(column);
1225
+ if (columnMap == null) {
1226
+ columnMap = new _flatten_js_interval_tree.default();
1227
+ columnMap.insert([startRow, endRow]);
1228
+ sheetMap.set(column, columnMap);
1229
+ return;
1230
+ }
1231
+ this._handleNewInterval(columnMap, startRow, endRow);
1232
+ }
1233
+ shouldContinueBuildingCache(unitId, sheetId, column, row) {
1234
+ var _this$_continueBuildi;
1235
+ if (column === -1 || row === -1) return false;
1236
+ const columnMap = (_this$_continueBuildi = this._continueBuildingCache.get(unitId)) === null || _this$_continueBuildi === void 0 || (_this$_continueBuildi = _this$_continueBuildi.get(sheetId)) === null || _this$_continueBuildi === void 0 ? void 0 : _this$_continueBuildi.get(column);
1237
+ if (!columnMap) return true;
1238
+ return columnMap.search([row, row]).length === 0;
1239
+ }
1240
+ canUseCache(unitId, sheetId, column, rangeStartRow, rangeEndRow) {
1241
+ var _this$_continueBuildi2;
1242
+ const columnMap = (_this$_continueBuildi2 = this._continueBuildingCache.get(unitId)) === null || _this$_continueBuildi2 === void 0 || (_this$_continueBuildi2 = _this$_continueBuildi2.get(sheetId)) === null || _this$_continueBuildi2 === void 0 ? void 0 : _this$_continueBuildi2.get(column);
1243
+ if (column === -1 || rangeStartRow === -1 || rangeEndRow === -1 || !columnMap) return {
1244
+ rowsInCache: [],
1245
+ rowsNotInCache: []
1246
+ };
1247
+ const result = columnMap.search([rangeStartRow, rangeEndRow]);
1248
+ if (result.length === 0) return {
1249
+ rowsInCache: [],
1250
+ rowsNotInCache: []
1251
+ };
1252
+ result.sort((a, b) => a[0] - b[0]);
1253
+ const rowsInCache = [];
1254
+ const rowsNotInCache = [];
1255
+ let _rangeStartRow = rangeStartRow;
1256
+ for (let i = 0; i < result.length; i++) {
1257
+ const [start, end] = result[i];
1258
+ if (_rangeStartRow >= start) {
1259
+ if (rangeEndRow <= end) {
1260
+ rowsInCache.push([_rangeStartRow, rangeEndRow]);
1261
+ break;
1262
+ }
1263
+ rowsInCache.push([_rangeStartRow, end]);
1264
+ _rangeStartRow = end + 1;
1265
+ if (i === result.length - 1 && _rangeStartRow <= rangeEndRow) rowsNotInCache.push([_rangeStartRow, rangeEndRow]);
1266
+ } else {
1267
+ if (rangeEndRow > end) {
1268
+ rowsInCache.push([start, end]);
1269
+ rowsNotInCache.push([_rangeStartRow, start - 1]);
1270
+ _rangeStartRow = end + 1;
1271
+ if (i === result.length - 1 && _rangeStartRow <= rangeEndRow) rowsNotInCache.push([_rangeStartRow, rangeEndRow]);
1272
+ continue;
1273
+ }
1274
+ rowsInCache.push([start, rangeEndRow]);
1275
+ rowsNotInCache.push([_rangeStartRow, start - 1]);
1276
+ }
1277
+ }
1278
+ return {
1279
+ rowsInCache,
1280
+ rowsNotInCache
1281
+ };
1282
+ }
1283
+ clear() {
1284
+ this._cache.clear();
1285
+ this._continueBuildingCache.clear();
1286
+ normalizedValueMap.clear();
1287
+ }
1288
+ _handleNewInterval(columnMap, startRow, endRow) {
1289
+ let result = columnMap.search([startRow, endRow]);
1290
+ if (result.length === 0) {
1291
+ const adjacentRange = [startRow - 1 < 0 ? 0 : startRow - 1, endRow + 1];
1292
+ result = columnMap.search(adjacentRange);
1293
+ if (result.length === 0) {
1294
+ columnMap.insert([startRow, endRow]);
1295
+ return;
1296
+ }
1297
+ }
1298
+ let min = startRow;
1299
+ let max = endRow;
1300
+ for (const interval of result) {
1301
+ min = Math.min(min, interval[0]);
1302
+ max = Math.max(max, interval[1]);
1303
+ columnMap.remove(interval);
1304
+ }
1305
+ columnMap.insert([min, max]);
1306
+ }
1307
+ };
1308
+ const CELL_INVERTED_INDEX_CACHE = new InvertedIndexCache();
1309
+
1135
1310
  //#endregion
1136
1311
  //#region src/basics/match-token.ts
1137
1312
  /**
@@ -2166,159 +2341,986 @@ const SetSuperTableOptionMutation = {
2166
2341
  //#endregion
2167
2342
  //#region src/config/config.ts
2168
2343
  const ENGINE_FORMULA_PLUGIN_CONFIG_KEY = "engine-formula.config";
2344
+ const DEFAULT_CYCLE_REFERENCE_COUNT = 1;
2169
2345
  const ENGINE_FORMULA_CYCLE_REFERENCE_COUNT = "CYCLE_REFERENCE_COUNT";
2170
2346
  const ENGINE_FORMULA_RETURN_DEPENDENCY_TREE = "RETURN_DEPENDENCY_TREE";
2171
2347
  const configSymbol = Symbol(ENGINE_FORMULA_PLUGIN_CONFIG_KEY);
2172
2348
  const defaultPluginConfig = {};
2173
2349
 
2174
2350
  //#endregion
2175
- //#region src/engine/utils/reference-cache.ts
2176
- const referenceToRangeCache = new FormulaAstLRU(1e5);
2177
- function deserializeRangeWithSheetWithCache(refString) {
2178
- const refCache = referenceToRangeCache.get(refString);
2179
- if (refCache) return refCache;
2180
- const result = deserializeRangeWithSheet(refString);
2181
- referenceToRangeCache.set(refString, result);
2182
- return deserializeRangeWithSheet(refString);
2183
- }
2184
- function clearReferenceToRangeCache() {
2185
- referenceToRangeCache.clear();
2186
- }
2351
+ //#region src/functions/date/function-names.ts
2352
+ /**
2353
+ * Copyright 2023-present DreamNum Co., Ltd.
2354
+ *
2355
+ * Licensed under the Apache License, Version 2.0 (the "License");
2356
+ * you may not use this file except in compliance with the License.
2357
+ * You may obtain a copy of the License at
2358
+ *
2359
+ * http://www.apache.org/licenses/LICENSE-2.0
2360
+ *
2361
+ * Unless required by applicable law or agreed to in writing, software
2362
+ * distributed under the License is distributed on an "AS IS" BASIS,
2363
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2364
+ * See the License for the specific language governing permissions and
2365
+ * limitations under the License.
2366
+ */
2367
+ let FUNCTION_NAMES_DATE = /* @__PURE__ */ function(FUNCTION_NAMES_DATE) {
2368
+ FUNCTION_NAMES_DATE["DATE"] = "DATE";
2369
+ FUNCTION_NAMES_DATE["DATEDIF"] = "DATEDIF";
2370
+ FUNCTION_NAMES_DATE["DATEVALUE"] = "DATEVALUE";
2371
+ FUNCTION_NAMES_DATE["DAY"] = "DAY";
2372
+ FUNCTION_NAMES_DATE["DAYS"] = "DAYS";
2373
+ FUNCTION_NAMES_DATE["DAYS360"] = "DAYS360";
2374
+ FUNCTION_NAMES_DATE["EDATE"] = "EDATE";
2375
+ FUNCTION_NAMES_DATE["EOMONTH"] = "EOMONTH";
2376
+ FUNCTION_NAMES_DATE["EPOCHTODATE"] = "EPOCHTODATE";
2377
+ FUNCTION_NAMES_DATE["HOUR"] = "HOUR";
2378
+ FUNCTION_NAMES_DATE["ISOWEEKNUM"] = "ISOWEEKNUM";
2379
+ FUNCTION_NAMES_DATE["MINUTE"] = "MINUTE";
2380
+ FUNCTION_NAMES_DATE["MONTH"] = "MONTH";
2381
+ FUNCTION_NAMES_DATE["NETWORKDAYS"] = "NETWORKDAYS";
2382
+ FUNCTION_NAMES_DATE["NETWORKDAYS_INTL"] = "NETWORKDAYS.INTL";
2383
+ FUNCTION_NAMES_DATE["NOW"] = "NOW";
2384
+ FUNCTION_NAMES_DATE["SECOND"] = "SECOND";
2385
+ FUNCTION_NAMES_DATE["TIME"] = "TIME";
2386
+ FUNCTION_NAMES_DATE["TIMEVALUE"] = "TIMEVALUE";
2387
+ FUNCTION_NAMES_DATE["TO_DATE"] = "TO_DATE";
2388
+ FUNCTION_NAMES_DATE["TODAY"] = "TODAY";
2389
+ FUNCTION_NAMES_DATE["WEEKDAY"] = "WEEKDAY";
2390
+ FUNCTION_NAMES_DATE["WEEKNUM"] = "WEEKNUM";
2391
+ FUNCTION_NAMES_DATE["WORKDAY"] = "WORKDAY";
2392
+ FUNCTION_NAMES_DATE["WORKDAY_INTL"] = "WORKDAY.INTL";
2393
+ FUNCTION_NAMES_DATE["YEAR"] = "YEAR";
2394
+ FUNCTION_NAMES_DATE["YEARFRAC"] = "YEARFRAC";
2395
+ return FUNCTION_NAMES_DATE;
2396
+ }({});
2187
2397
 
2188
2398
  //#endregion
2189
- //#region src/engine/utils/sequence.ts
2190
- let sequenceNodeType = /* @__PURE__ */ function(sequenceNodeType) {
2191
- sequenceNodeType[sequenceNodeType["NORMAL"] = 0] = "NORMAL";
2192
- sequenceNodeType[sequenceNodeType["NUMBER"] = 1] = "NUMBER";
2193
- sequenceNodeType[sequenceNodeType["STRING"] = 2] = "STRING";
2194
- sequenceNodeType[sequenceNodeType["FUNCTION"] = 3] = "FUNCTION";
2195
- sequenceNodeType[sequenceNodeType["REFERENCE"] = 4] = "REFERENCE";
2196
- sequenceNodeType[sequenceNodeType["ARRAY"] = 5] = "ARRAY";
2197
- sequenceNodeType[sequenceNodeType["DEFINED_NAME"] = 6] = "DEFINED_NAME";
2198
- sequenceNodeType[sequenceNodeType["TABLE"] = 7] = "TABLE";
2199
- return sequenceNodeType;
2399
+ //#region src/functions/engineering/function-names.ts
2400
+ /**
2401
+ * Copyright 2023-present DreamNum Co., Ltd.
2402
+ *
2403
+ * Licensed under the Apache License, Version 2.0 (the "License");
2404
+ * you may not use this file except in compliance with the License.
2405
+ * You may obtain a copy of the License at
2406
+ *
2407
+ * http://www.apache.org/licenses/LICENSE-2.0
2408
+ *
2409
+ * Unless required by applicable law or agreed to in writing, software
2410
+ * distributed under the License is distributed on an "AS IS" BASIS,
2411
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2412
+ * See the License for the specific language governing permissions and
2413
+ * limitations under the License.
2414
+ */
2415
+ let FUNCTION_NAMES_ENGINEERING = /* @__PURE__ */ function(FUNCTION_NAMES_ENGINEERING) {
2416
+ FUNCTION_NAMES_ENGINEERING["BESSELI"] = "BESSELI";
2417
+ FUNCTION_NAMES_ENGINEERING["BESSELJ"] = "BESSELJ";
2418
+ FUNCTION_NAMES_ENGINEERING["BESSELK"] = "BESSELK";
2419
+ FUNCTION_NAMES_ENGINEERING["BESSELY"] = "BESSELY";
2420
+ FUNCTION_NAMES_ENGINEERING["BIN2DEC"] = "BIN2DEC";
2421
+ FUNCTION_NAMES_ENGINEERING["BIN2HEX"] = "BIN2HEX";
2422
+ FUNCTION_NAMES_ENGINEERING["BIN2OCT"] = "BIN2OCT";
2423
+ FUNCTION_NAMES_ENGINEERING["BITAND"] = "BITAND";
2424
+ FUNCTION_NAMES_ENGINEERING["BITLSHIFT"] = "BITLSHIFT";
2425
+ FUNCTION_NAMES_ENGINEERING["BITOR"] = "BITOR";
2426
+ FUNCTION_NAMES_ENGINEERING["BITRSHIFT"] = "BITRSHIFT";
2427
+ FUNCTION_NAMES_ENGINEERING["BITXOR"] = "BITXOR";
2428
+ FUNCTION_NAMES_ENGINEERING["COMPLEX"] = "COMPLEX";
2429
+ FUNCTION_NAMES_ENGINEERING["CONVERT"] = "CONVERT";
2430
+ FUNCTION_NAMES_ENGINEERING["DEC2BIN"] = "DEC2BIN";
2431
+ FUNCTION_NAMES_ENGINEERING["DEC2HEX"] = "DEC2HEX";
2432
+ FUNCTION_NAMES_ENGINEERING["DEC2OCT"] = "DEC2OCT";
2433
+ FUNCTION_NAMES_ENGINEERING["DELTA"] = "DELTA";
2434
+ FUNCTION_NAMES_ENGINEERING["ERF"] = "ERF";
2435
+ FUNCTION_NAMES_ENGINEERING["ERF_PRECISE"] = "ERF.PRECISE";
2436
+ FUNCTION_NAMES_ENGINEERING["ERFC"] = "ERFC";
2437
+ FUNCTION_NAMES_ENGINEERING["ERFC_PRECISE"] = "ERFC.PRECISE";
2438
+ FUNCTION_NAMES_ENGINEERING["GESTEP"] = "GESTEP";
2439
+ FUNCTION_NAMES_ENGINEERING["HEX2BIN"] = "HEX2BIN";
2440
+ FUNCTION_NAMES_ENGINEERING["HEX2DEC"] = "HEX2DEC";
2441
+ FUNCTION_NAMES_ENGINEERING["HEX2OCT"] = "HEX2OCT";
2442
+ FUNCTION_NAMES_ENGINEERING["IMABS"] = "IMABS";
2443
+ FUNCTION_NAMES_ENGINEERING["IMAGINARY"] = "IMAGINARY";
2444
+ FUNCTION_NAMES_ENGINEERING["IMARGUMENT"] = "IMARGUMENT";
2445
+ FUNCTION_NAMES_ENGINEERING["IMCONJUGATE"] = "IMCONJUGATE";
2446
+ FUNCTION_NAMES_ENGINEERING["IMCOS"] = "IMCOS";
2447
+ FUNCTION_NAMES_ENGINEERING["IMCOSH"] = "IMCOSH";
2448
+ FUNCTION_NAMES_ENGINEERING["IMCOT"] = "IMCOT";
2449
+ FUNCTION_NAMES_ENGINEERING["IMCOTH"] = "IMCOTH";
2450
+ FUNCTION_NAMES_ENGINEERING["IMCSC"] = "IMCSC";
2451
+ FUNCTION_NAMES_ENGINEERING["IMCSCH"] = "IMCSCH";
2452
+ FUNCTION_NAMES_ENGINEERING["IMDIV"] = "IMDIV";
2453
+ FUNCTION_NAMES_ENGINEERING["IMEXP"] = "IMEXP";
2454
+ FUNCTION_NAMES_ENGINEERING["IMLN"] = "IMLN";
2455
+ FUNCTION_NAMES_ENGINEERING["IMLOG"] = "IMLOG";
2456
+ FUNCTION_NAMES_ENGINEERING["IMLOG10"] = "IMLOG10";
2457
+ FUNCTION_NAMES_ENGINEERING["IMLOG2"] = "IMLOG2";
2458
+ FUNCTION_NAMES_ENGINEERING["IMPOWER"] = "IMPOWER";
2459
+ FUNCTION_NAMES_ENGINEERING["IMPRODUCT"] = "IMPRODUCT";
2460
+ FUNCTION_NAMES_ENGINEERING["IMREAL"] = "IMREAL";
2461
+ FUNCTION_NAMES_ENGINEERING["IMSEC"] = "IMSEC";
2462
+ FUNCTION_NAMES_ENGINEERING["IMSECH"] = "IMSECH";
2463
+ FUNCTION_NAMES_ENGINEERING["IMSIN"] = "IMSIN";
2464
+ FUNCTION_NAMES_ENGINEERING["IMSINH"] = "IMSINH";
2465
+ FUNCTION_NAMES_ENGINEERING["IMSQRT"] = "IMSQRT";
2466
+ FUNCTION_NAMES_ENGINEERING["IMSUB"] = "IMSUB";
2467
+ FUNCTION_NAMES_ENGINEERING["IMSUM"] = "IMSUM";
2468
+ FUNCTION_NAMES_ENGINEERING["IMTAN"] = "IMTAN";
2469
+ FUNCTION_NAMES_ENGINEERING["IMTANH"] = "IMTANH";
2470
+ FUNCTION_NAMES_ENGINEERING["OCT2BIN"] = "OCT2BIN";
2471
+ FUNCTION_NAMES_ENGINEERING["OCT2DEC"] = "OCT2DEC";
2472
+ FUNCTION_NAMES_ENGINEERING["OCT2HEX"] = "OCT2HEX";
2473
+ return FUNCTION_NAMES_ENGINEERING;
2200
2474
  }({});
2475
+
2476
+ //#endregion
2477
+ //#region src/functions/financial/function-names.ts
2201
2478
  /**
2202
- * Deserialize Sequence to text.
2203
- * @param newSequenceNodes
2204
- * @returns
2479
+ * Copyright 2023-present DreamNum Co., Ltd.
2480
+ *
2481
+ * Licensed under the Apache License, Version 2.0 (the "License");
2482
+ * you may not use this file except in compliance with the License.
2483
+ * You may obtain a copy of the License at
2484
+ *
2485
+ * http://www.apache.org/licenses/LICENSE-2.0
2486
+ *
2487
+ * Unless required by applicable law or agreed to in writing, software
2488
+ * distributed under the License is distributed on an "AS IS" BASIS,
2489
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2490
+ * See the License for the specific language governing permissions and
2491
+ * limitations under the License.
2205
2492
  */
2206
- function generateStringWithSequence(newSequenceNodes) {
2207
- let sequenceString = "";
2208
- for (const node of newSequenceNodes) if (typeof node === "string") sequenceString += node;
2209
- else sequenceString += node.token;
2210
- return sequenceString;
2211
- }
2493
+ let FUNCTION_NAMES_FINANCIAL = /* @__PURE__ */ function(FUNCTION_NAMES_FINANCIAL) {
2494
+ FUNCTION_NAMES_FINANCIAL["ACCRINT"] = "ACCRINT";
2495
+ FUNCTION_NAMES_FINANCIAL["ACCRINTM"] = "ACCRINTM";
2496
+ FUNCTION_NAMES_FINANCIAL["AMORDEGRC"] = "AMORDEGRC";
2497
+ FUNCTION_NAMES_FINANCIAL["AMORLINC"] = "AMORLINC";
2498
+ FUNCTION_NAMES_FINANCIAL["COUPDAYBS"] = "COUPDAYBS";
2499
+ FUNCTION_NAMES_FINANCIAL["COUPDAYS"] = "COUPDAYS";
2500
+ FUNCTION_NAMES_FINANCIAL["COUPDAYSNC"] = "COUPDAYSNC";
2501
+ FUNCTION_NAMES_FINANCIAL["COUPNCD"] = "COUPNCD";
2502
+ FUNCTION_NAMES_FINANCIAL["COUPNUM"] = "COUPNUM";
2503
+ FUNCTION_NAMES_FINANCIAL["COUPPCD"] = "COUPPCD";
2504
+ FUNCTION_NAMES_FINANCIAL["CUMIPMT"] = "CUMIPMT";
2505
+ FUNCTION_NAMES_FINANCIAL["CUMPRINC"] = "CUMPRINC";
2506
+ FUNCTION_NAMES_FINANCIAL["DB"] = "DB";
2507
+ FUNCTION_NAMES_FINANCIAL["DDB"] = "DDB";
2508
+ FUNCTION_NAMES_FINANCIAL["DISC"] = "DISC";
2509
+ FUNCTION_NAMES_FINANCIAL["DOLLARDE"] = "DOLLARDE";
2510
+ FUNCTION_NAMES_FINANCIAL["DOLLARFR"] = "DOLLARFR";
2511
+ FUNCTION_NAMES_FINANCIAL["DURATION"] = "DURATION";
2512
+ FUNCTION_NAMES_FINANCIAL["EFFECT"] = "EFFECT";
2513
+ FUNCTION_NAMES_FINANCIAL["FV"] = "FV";
2514
+ FUNCTION_NAMES_FINANCIAL["FVSCHEDULE"] = "FVSCHEDULE";
2515
+ FUNCTION_NAMES_FINANCIAL["INTRATE"] = "INTRATE";
2516
+ FUNCTION_NAMES_FINANCIAL["IPMT"] = "IPMT";
2517
+ FUNCTION_NAMES_FINANCIAL["IRR"] = "IRR";
2518
+ FUNCTION_NAMES_FINANCIAL["ISPMT"] = "ISPMT";
2519
+ FUNCTION_NAMES_FINANCIAL["MDURATION"] = "MDURATION";
2520
+ FUNCTION_NAMES_FINANCIAL["MIRR"] = "MIRR";
2521
+ FUNCTION_NAMES_FINANCIAL["NOMINAL"] = "NOMINAL";
2522
+ FUNCTION_NAMES_FINANCIAL["NPER"] = "NPER";
2523
+ FUNCTION_NAMES_FINANCIAL["NPV"] = "NPV";
2524
+ FUNCTION_NAMES_FINANCIAL["ODDFPRICE"] = "ODDFPRICE";
2525
+ FUNCTION_NAMES_FINANCIAL["ODDFYIELD"] = "ODDFYIELD";
2526
+ FUNCTION_NAMES_FINANCIAL["ODDLPRICE"] = "ODDLPRICE";
2527
+ FUNCTION_NAMES_FINANCIAL["ODDLYIELD"] = "ODDLYIELD";
2528
+ FUNCTION_NAMES_FINANCIAL["PDURATION"] = "PDURATION";
2529
+ FUNCTION_NAMES_FINANCIAL["PMT"] = "PMT";
2530
+ FUNCTION_NAMES_FINANCIAL["PPMT"] = "PPMT";
2531
+ FUNCTION_NAMES_FINANCIAL["PRICE"] = "PRICE";
2532
+ FUNCTION_NAMES_FINANCIAL["PRICEDISC"] = "PRICEDISC";
2533
+ FUNCTION_NAMES_FINANCIAL["PRICEMAT"] = "PRICEMAT";
2534
+ FUNCTION_NAMES_FINANCIAL["PV"] = "PV";
2535
+ FUNCTION_NAMES_FINANCIAL["RATE"] = "RATE";
2536
+ FUNCTION_NAMES_FINANCIAL["RECEIVED"] = "RECEIVED";
2537
+ FUNCTION_NAMES_FINANCIAL["RRI"] = "RRI";
2538
+ FUNCTION_NAMES_FINANCIAL["SLN"] = "SLN";
2539
+ FUNCTION_NAMES_FINANCIAL["SYD"] = "SYD";
2540
+ FUNCTION_NAMES_FINANCIAL["TBILLEQ"] = "TBILLEQ";
2541
+ FUNCTION_NAMES_FINANCIAL["TBILLPRICE"] = "TBILLPRICE";
2542
+ FUNCTION_NAMES_FINANCIAL["TBILLYIELD"] = "TBILLYIELD";
2543
+ FUNCTION_NAMES_FINANCIAL["VDB"] = "VDB";
2544
+ FUNCTION_NAMES_FINANCIAL["XIRR"] = "XIRR";
2545
+ FUNCTION_NAMES_FINANCIAL["XNPV"] = "XNPV";
2546
+ FUNCTION_NAMES_FINANCIAL["YIELD"] = "YIELD";
2547
+ FUNCTION_NAMES_FINANCIAL["YIELDDISC"] = "YIELDDISC";
2548
+ FUNCTION_NAMES_FINANCIAL["YIELDMAT"] = "YIELDMAT";
2549
+ return FUNCTION_NAMES_FINANCIAL;
2550
+ }({});
2212
2551
 
2213
2552
  //#endregion
2214
- //#region src/engine/analysis/lexer-node.ts
2215
- var LexerNode = class LexerNode {
2216
- constructor() {
2217
- _defineProperty(this, "_parent", void 0);
2218
- _defineProperty(this, "_token", "R_1");
2219
- _defineProperty(this, "_children", []);
2220
- _defineProperty(this, "_lambdaId", void 0);
2221
- _defineProperty(this, "_functionDefinitionPrivacyVar", void 0);
2222
- _defineProperty(this, "_lambdaParameter", "");
2223
- _defineProperty(this, "_startIndex", -1);
2224
- _defineProperty(this, "_endIndex", -1);
2225
- _defineProperty(this, "_definedNames", []);
2226
- }
2227
- dispose() {
2228
- var _this$_functionDefini;
2229
- this._children.forEach((node) => {
2230
- if (!(typeof node === "string")) node.dispose();
2231
- });
2232
- (_this$_functionDefini = this._functionDefinitionPrivacyVar) === null || _this$_functionDefini === void 0 || _this$_functionDefini.clear();
2233
- this._functionDefinitionPrivacyVar = null;
2234
- this._children = [];
2235
- this._parent = null;
2236
- this._definedNames = [];
2237
- }
2238
- getDefinedNames() {
2239
- return this._definedNames;
2240
- }
2241
- getStartIndex() {
2242
- return this._startIndex;
2243
- }
2244
- getLambdaId() {
2245
- return this._lambdaId;
2246
- }
2247
- setLambdaId(lambdaId) {
2248
- this._lambdaId = lambdaId;
2249
- }
2250
- getFunctionDefinitionPrivacyVar() {
2251
- return this._functionDefinitionPrivacyVar;
2252
- }
2253
- setLambdaPrivacyVar(lambdaPrivacyVar) {
2254
- this._functionDefinitionPrivacyVar = lambdaPrivacyVar;
2255
- }
2256
- getLambdaParameter() {
2257
- return this._lambdaParameter;
2258
- }
2259
- setLambdaParameter(lambdaParameter) {
2260
- this._lambdaParameter = lambdaParameter;
2261
- }
2262
- getParent() {
2263
- return this._parent;
2264
- }
2265
- setParent(lexerNode) {
2266
- this._parent = lexerNode;
2267
- }
2268
- getChildren() {
2269
- return this._children;
2270
- }
2271
- setChildren(children) {
2272
- this._children = children;
2273
- }
2274
- addChildren(children) {
2275
- this._children.push(children);
2276
- }
2277
- addChildrenFirst(children) {
2278
- this._children.unshift(children);
2279
- }
2280
- getToken() {
2281
- return this._token;
2282
- }
2283
- setToken(token) {
2284
- this._token = token;
2285
- }
2286
- setIndex(st, ed) {
2287
- this._startIndex = st;
2288
- this._endIndex = ed;
2289
- }
2290
- setDefinedNames(definedNames) {
2291
- this._definedNames = definedNames;
2292
- }
2293
- hasDefinedNames() {
2294
- return this._definedNames.length > 0;
2295
- }
2296
- replaceChild(lexerNode, newLexerNode) {
2297
- const i = this._getIndexInParent(lexerNode);
2298
- if (i == null) return;
2299
- this.getChildren().splice(i, 1, newLexerNode);
2300
- newLexerNode.setParent(this);
2301
- }
2302
- changeToParent(newParentLexerNode) {
2303
- const parentNode = this.getParent();
2304
- if (parentNode) parentNode.removeChild(this);
2305
- this.setParent(newParentLexerNode);
2306
- newParentLexerNode.getChildren().push(this);
2307
- }
2308
- removeChild(lexerNode) {
2309
- const i = this._getIndexInParent(lexerNode);
2310
- if (i == null) return;
2311
- this.getChildren().splice(i, 1);
2312
- }
2313
- serialize() {
2314
- const token = this.getToken();
2315
- const children = this.getChildren();
2316
- const childrenSerialization = [];
2317
- const childrenCount = children.length;
2318
- for (let i = 0; i < childrenCount; i++) {
2319
- const item = children[i];
2320
- if (item instanceof LexerNode) childrenSerialization.push(item.serialize());
2321
- else childrenSerialization.push(item);
2553
+ //#region src/functions/information/function-names.ts
2554
+ /**
2555
+ * Copyright 2023-present DreamNum Co., Ltd.
2556
+ *
2557
+ * Licensed under the Apache License, Version 2.0 (the "License");
2558
+ * you may not use this file except in compliance with the License.
2559
+ * You may obtain a copy of the License at
2560
+ *
2561
+ * http://www.apache.org/licenses/LICENSE-2.0
2562
+ *
2563
+ * Unless required by applicable law or agreed to in writing, software
2564
+ * distributed under the License is distributed on an "AS IS" BASIS,
2565
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2566
+ * See the License for the specific language governing permissions and
2567
+ * limitations under the License.
2568
+ */
2569
+ let FUNCTION_NAMES_INFORMATION = /* @__PURE__ */ function(FUNCTION_NAMES_INFORMATION) {
2570
+ FUNCTION_NAMES_INFORMATION["CELL"] = "CELL";
2571
+ FUNCTION_NAMES_INFORMATION["ERROR_TYPE"] = "ERROR.TYPE";
2572
+ FUNCTION_NAMES_INFORMATION["INFO"] = "INFO";
2573
+ FUNCTION_NAMES_INFORMATION["ISBETWEEN"] = "ISBETWEEN";
2574
+ FUNCTION_NAMES_INFORMATION["ISBLANK"] = "ISBLANK";
2575
+ FUNCTION_NAMES_INFORMATION["ISDATE"] = "ISDATE";
2576
+ FUNCTION_NAMES_INFORMATION["ISEMAIL"] = "ISEMAIL";
2577
+ FUNCTION_NAMES_INFORMATION["ISERR"] = "ISERR";
2578
+ FUNCTION_NAMES_INFORMATION["ISERROR"] = "ISERROR";
2579
+ FUNCTION_NAMES_INFORMATION["ISEVEN"] = "ISEVEN";
2580
+ FUNCTION_NAMES_INFORMATION["ISFORMULA"] = "ISFORMULA";
2581
+ FUNCTION_NAMES_INFORMATION["ISLOGICAL"] = "ISLOGICAL";
2582
+ FUNCTION_NAMES_INFORMATION["ISNA"] = "ISNA";
2583
+ FUNCTION_NAMES_INFORMATION["ISNONTEXT"] = "ISNONTEXT";
2584
+ FUNCTION_NAMES_INFORMATION["ISNUMBER"] = "ISNUMBER";
2585
+ FUNCTION_NAMES_INFORMATION["ISODD"] = "ISODD";
2586
+ FUNCTION_NAMES_INFORMATION["ISOMITTED"] = "ISOMITTED";
2587
+ FUNCTION_NAMES_INFORMATION["ISREF"] = "ISREF";
2588
+ FUNCTION_NAMES_INFORMATION["ISTEXT"] = "ISTEXT";
2589
+ FUNCTION_NAMES_INFORMATION["ISURL"] = "ISURL";
2590
+ FUNCTION_NAMES_INFORMATION["N"] = "N";
2591
+ FUNCTION_NAMES_INFORMATION["NA"] = "NA";
2592
+ FUNCTION_NAMES_INFORMATION["SHEET"] = "SHEET";
2593
+ FUNCTION_NAMES_INFORMATION["SHEETS"] = "SHEETS";
2594
+ FUNCTION_NAMES_INFORMATION["TYPE"] = "TYPE";
2595
+ return FUNCTION_NAMES_INFORMATION;
2596
+ }({});
2597
+
2598
+ //#endregion
2599
+ //#region src/functions/logical/function-names.ts
2600
+ /**
2601
+ * Copyright 2023-present DreamNum Co., Ltd.
2602
+ *
2603
+ * Licensed under the Apache License, Version 2.0 (the "License");
2604
+ * you may not use this file except in compliance with the License.
2605
+ * You may obtain a copy of the License at
2606
+ *
2607
+ * http://www.apache.org/licenses/LICENSE-2.0
2608
+ *
2609
+ * Unless required by applicable law or agreed to in writing, software
2610
+ * distributed under the License is distributed on an "AS IS" BASIS,
2611
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2612
+ * See the License for the specific language governing permissions and
2613
+ * limitations under the License.
2614
+ */
2615
+ let FUNCTION_NAMES_LOGICAL = /* @__PURE__ */ function(FUNCTION_NAMES_LOGICAL) {
2616
+ FUNCTION_NAMES_LOGICAL["AND"] = "AND";
2617
+ FUNCTION_NAMES_LOGICAL["BYCOL"] = "BYCOL";
2618
+ FUNCTION_NAMES_LOGICAL["BYROW"] = "BYROW";
2619
+ FUNCTION_NAMES_LOGICAL["FALSE"] = "FALSE";
2620
+ FUNCTION_NAMES_LOGICAL["IF"] = "IF";
2621
+ FUNCTION_NAMES_LOGICAL["IFERROR"] = "IFERROR";
2622
+ FUNCTION_NAMES_LOGICAL["IFNA"] = "IFNA";
2623
+ FUNCTION_NAMES_LOGICAL["IFS"] = "IFS";
2624
+ FUNCTION_NAMES_LOGICAL["LAMBDA"] = "LAMBDA";
2625
+ FUNCTION_NAMES_LOGICAL["LET"] = "LET";
2626
+ FUNCTION_NAMES_LOGICAL["MAKEARRAY"] = "MAKEARRAY";
2627
+ FUNCTION_NAMES_LOGICAL["MAP"] = "MAP";
2628
+ FUNCTION_NAMES_LOGICAL["NOT"] = "NOT";
2629
+ FUNCTION_NAMES_LOGICAL["OR"] = "OR";
2630
+ FUNCTION_NAMES_LOGICAL["REDUCE"] = "REDUCE";
2631
+ FUNCTION_NAMES_LOGICAL["SCAN"] = "SCAN";
2632
+ FUNCTION_NAMES_LOGICAL["SWITCH"] = "SWITCH";
2633
+ FUNCTION_NAMES_LOGICAL["TRUE"] = "TRUE";
2634
+ FUNCTION_NAMES_LOGICAL["XOR"] = "XOR";
2635
+ return FUNCTION_NAMES_LOGICAL;
2636
+ }({});
2637
+
2638
+ //#endregion
2639
+ //#region src/functions/lookup/function-names.ts
2640
+ /**
2641
+ * Copyright 2023-present DreamNum Co., Ltd.
2642
+ *
2643
+ * Licensed under the Apache License, Version 2.0 (the "License");
2644
+ * you may not use this file except in compliance with the License.
2645
+ * You may obtain a copy of the License at
2646
+ *
2647
+ * http://www.apache.org/licenses/LICENSE-2.0
2648
+ *
2649
+ * Unless required by applicable law or agreed to in writing, software
2650
+ * distributed under the License is distributed on an "AS IS" BASIS,
2651
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2652
+ * See the License for the specific language governing permissions and
2653
+ * limitations under the License.
2654
+ */
2655
+ let FUNCTION_NAMES_LOOKUP = /* @__PURE__ */ function(FUNCTION_NAMES_LOOKUP) {
2656
+ FUNCTION_NAMES_LOOKUP["ADDRESS"] = "ADDRESS";
2657
+ FUNCTION_NAMES_LOOKUP["AREAS"] = "AREAS";
2658
+ FUNCTION_NAMES_LOOKUP["CHOOSE"] = "CHOOSE";
2659
+ FUNCTION_NAMES_LOOKUP["CHOOSECOLS"] = "CHOOSECOLS";
2660
+ FUNCTION_NAMES_LOOKUP["CHOOSEROWS"] = "CHOOSEROWS";
2661
+ FUNCTION_NAMES_LOOKUP["COLUMN"] = "COLUMN";
2662
+ FUNCTION_NAMES_LOOKUP["COLUMNS"] = "COLUMNS";
2663
+ FUNCTION_NAMES_LOOKUP["DROP"] = "DROP";
2664
+ FUNCTION_NAMES_LOOKUP["EXPAND"] = "EXPAND";
2665
+ FUNCTION_NAMES_LOOKUP["FILTER"] = "FILTER";
2666
+ FUNCTION_NAMES_LOOKUP["FORMULATEXT"] = "FORMULATEXT";
2667
+ FUNCTION_NAMES_LOOKUP["GETPIVOTDATA"] = "GETPIVOTDATA";
2668
+ FUNCTION_NAMES_LOOKUP["HLOOKUP"] = "HLOOKUP";
2669
+ FUNCTION_NAMES_LOOKUP["HSTACK"] = "HSTACK";
2670
+ FUNCTION_NAMES_LOOKUP["HYPERLINK"] = "HYPERLINK";
2671
+ FUNCTION_NAMES_LOOKUP["IMAGE"] = "IMAGE";
2672
+ FUNCTION_NAMES_LOOKUP["INDEX"] = "INDEX";
2673
+ FUNCTION_NAMES_LOOKUP["INDIRECT"] = "INDIRECT";
2674
+ FUNCTION_NAMES_LOOKUP["LOOKUP"] = "LOOKUP";
2675
+ FUNCTION_NAMES_LOOKUP["MATCH"] = "MATCH";
2676
+ FUNCTION_NAMES_LOOKUP["OFFSET"] = "OFFSET";
2677
+ FUNCTION_NAMES_LOOKUP["ROW"] = "ROW";
2678
+ FUNCTION_NAMES_LOOKUP["ROWS"] = "ROWS";
2679
+ FUNCTION_NAMES_LOOKUP["RTD"] = "RTD";
2680
+ FUNCTION_NAMES_LOOKUP["SORT"] = "SORT";
2681
+ FUNCTION_NAMES_LOOKUP["SORTBY"] = "SORTBY";
2682
+ FUNCTION_NAMES_LOOKUP["TAKE"] = "TAKE";
2683
+ FUNCTION_NAMES_LOOKUP["TOCOL"] = "TOCOL";
2684
+ FUNCTION_NAMES_LOOKUP["TOROW"] = "TOROW";
2685
+ FUNCTION_NAMES_LOOKUP["TRANSPOSE"] = "TRANSPOSE";
2686
+ FUNCTION_NAMES_LOOKUP["UNIQUE"] = "UNIQUE";
2687
+ FUNCTION_NAMES_LOOKUP["VLOOKUP"] = "VLOOKUP";
2688
+ FUNCTION_NAMES_LOOKUP["VSTACK"] = "VSTACK";
2689
+ FUNCTION_NAMES_LOOKUP["WRAPCOLS"] = "WRAPCOLS";
2690
+ FUNCTION_NAMES_LOOKUP["WRAPROWS"] = "WRAPROWS";
2691
+ FUNCTION_NAMES_LOOKUP["XLOOKUP"] = "XLOOKUP";
2692
+ FUNCTION_NAMES_LOOKUP["XMATCH"] = "XMATCH";
2693
+ return FUNCTION_NAMES_LOOKUP;
2694
+ }({});
2695
+
2696
+ //#endregion
2697
+ //#region src/functions/math/function-names.ts
2698
+ /**
2699
+ * Copyright 2023-present DreamNum Co., Ltd.
2700
+ *
2701
+ * Licensed under the Apache License, Version 2.0 (the "License");
2702
+ * you may not use this file except in compliance with the License.
2703
+ * You may obtain a copy of the License at
2704
+ *
2705
+ * http://www.apache.org/licenses/LICENSE-2.0
2706
+ *
2707
+ * Unless required by applicable law or agreed to in writing, software
2708
+ * distributed under the License is distributed on an "AS IS" BASIS,
2709
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2710
+ * See the License for the specific language governing permissions and
2711
+ * limitations under the License.
2712
+ */
2713
+ let FUNCTION_NAMES_MATH = /* @__PURE__ */ function(FUNCTION_NAMES_MATH) {
2714
+ FUNCTION_NAMES_MATH["ABS"] = "ABS";
2715
+ FUNCTION_NAMES_MATH["ACOS"] = "ACOS";
2716
+ FUNCTION_NAMES_MATH["ACOSH"] = "ACOSH";
2717
+ FUNCTION_NAMES_MATH["ACOT"] = "ACOT";
2718
+ FUNCTION_NAMES_MATH["ACOTH"] = "ACOTH";
2719
+ FUNCTION_NAMES_MATH["AGGREGATE"] = "AGGREGATE";
2720
+ FUNCTION_NAMES_MATH["ARABIC"] = "ARABIC";
2721
+ FUNCTION_NAMES_MATH["ASIN"] = "ASIN";
2722
+ FUNCTION_NAMES_MATH["ASINH"] = "ASINH";
2723
+ FUNCTION_NAMES_MATH["ATAN"] = "ATAN";
2724
+ FUNCTION_NAMES_MATH["ATAN2"] = "ATAN2";
2725
+ FUNCTION_NAMES_MATH["ATANH"] = "ATANH";
2726
+ FUNCTION_NAMES_MATH["BASE"] = "BASE";
2727
+ FUNCTION_NAMES_MATH["CEILING"] = "CEILING";
2728
+ FUNCTION_NAMES_MATH["CEILING_MATH"] = "CEILING.MATH";
2729
+ FUNCTION_NAMES_MATH["CEILING_PRECISE"] = "CEILING.PRECISE";
2730
+ FUNCTION_NAMES_MATH["COMBIN"] = "COMBIN";
2731
+ FUNCTION_NAMES_MATH["COMBINA"] = "COMBINA";
2732
+ FUNCTION_NAMES_MATH["COS"] = "COS";
2733
+ FUNCTION_NAMES_MATH["COSH"] = "COSH";
2734
+ FUNCTION_NAMES_MATH["COT"] = "COT";
2735
+ FUNCTION_NAMES_MATH["COTH"] = "COTH";
2736
+ FUNCTION_NAMES_MATH["CSC"] = "CSC";
2737
+ FUNCTION_NAMES_MATH["CSCH"] = "CSCH";
2738
+ FUNCTION_NAMES_MATH["DECIMAL"] = "DECIMAL";
2739
+ FUNCTION_NAMES_MATH["DEGREES"] = "DEGREES";
2740
+ FUNCTION_NAMES_MATH["EVEN"] = "EVEN";
2741
+ FUNCTION_NAMES_MATH["EXP"] = "EXP";
2742
+ FUNCTION_NAMES_MATH["FACT"] = "FACT";
2743
+ FUNCTION_NAMES_MATH["FACTDOUBLE"] = "FACTDOUBLE";
2744
+ FUNCTION_NAMES_MATH["FLOOR"] = "FLOOR";
2745
+ FUNCTION_NAMES_MATH["FLOOR_MATH"] = "FLOOR.MATH";
2746
+ FUNCTION_NAMES_MATH["FLOOR_PRECISE"] = "FLOOR.PRECISE";
2747
+ FUNCTION_NAMES_MATH["GCD"] = "GCD";
2748
+ FUNCTION_NAMES_MATH["INT"] = "INT";
2749
+ FUNCTION_NAMES_MATH["ISO_CEILING"] = "ISO.CEILING";
2750
+ FUNCTION_NAMES_MATH["LCM"] = "LCM";
2751
+ FUNCTION_NAMES_MATH["LET"] = "LET";
2752
+ FUNCTION_NAMES_MATH["LN"] = "LN";
2753
+ FUNCTION_NAMES_MATH["LOG"] = "LOG";
2754
+ FUNCTION_NAMES_MATH["LOG10"] = "LOG10";
2755
+ FUNCTION_NAMES_MATH["MDETERM"] = "MDETERM";
2756
+ FUNCTION_NAMES_MATH["MINVERSE"] = "MINVERSE";
2757
+ FUNCTION_NAMES_MATH["MMULT"] = "MMULT";
2758
+ FUNCTION_NAMES_MATH["MOD"] = "MOD";
2759
+ FUNCTION_NAMES_MATH["MROUND"] = "MROUND";
2760
+ FUNCTION_NAMES_MATH["MULTINOMIAL"] = "MULTINOMIAL";
2761
+ FUNCTION_NAMES_MATH["MUNIT"] = "MUNIT";
2762
+ FUNCTION_NAMES_MATH["ODD"] = "ODD";
2763
+ FUNCTION_NAMES_MATH["PI"] = "PI";
2764
+ FUNCTION_NAMES_MATH["POWER"] = "POWER";
2765
+ FUNCTION_NAMES_MATH["PRODUCT"] = "PRODUCT";
2766
+ FUNCTION_NAMES_MATH["QUOTIENT"] = "QUOTIENT";
2767
+ FUNCTION_NAMES_MATH["RADIANS"] = "RADIANS";
2768
+ FUNCTION_NAMES_MATH["RAND"] = "RAND";
2769
+ FUNCTION_NAMES_MATH["RANDARRAY"] = "RANDARRAY";
2770
+ FUNCTION_NAMES_MATH["RANDBETWEEN"] = "RANDBETWEEN";
2771
+ FUNCTION_NAMES_MATH["ROMAN"] = "ROMAN";
2772
+ FUNCTION_NAMES_MATH["ROUND"] = "ROUND";
2773
+ FUNCTION_NAMES_MATH["ROUNDBANK"] = "ROUNDBANK";
2774
+ FUNCTION_NAMES_MATH["ROUNDDOWN"] = "ROUNDDOWN";
2775
+ FUNCTION_NAMES_MATH["ROUNDUP"] = "ROUNDUP";
2776
+ FUNCTION_NAMES_MATH["SEC"] = "SEC";
2777
+ FUNCTION_NAMES_MATH["SECH"] = "SECH";
2778
+ FUNCTION_NAMES_MATH["SERIESSUM"] = "SERIESSUM";
2779
+ FUNCTION_NAMES_MATH["SEQUENCE"] = "SEQUENCE";
2780
+ FUNCTION_NAMES_MATH["SIGN"] = "SIGN";
2781
+ FUNCTION_NAMES_MATH["SIN"] = "SIN";
2782
+ FUNCTION_NAMES_MATH["SINH"] = "SINH";
2783
+ FUNCTION_NAMES_MATH["SQRT"] = "SQRT";
2784
+ FUNCTION_NAMES_MATH["SQRTPI"] = "SQRTPI";
2785
+ FUNCTION_NAMES_MATH["SUBTOTAL"] = "SUBTOTAL";
2786
+ FUNCTION_NAMES_MATH["SUM"] = "SUM";
2787
+ FUNCTION_NAMES_MATH["SUMIF"] = "SUMIF";
2788
+ FUNCTION_NAMES_MATH["SUMIFS"] = "SUMIFS";
2789
+ FUNCTION_NAMES_MATH["SUMPRODUCT"] = "SUMPRODUCT";
2790
+ FUNCTION_NAMES_MATH["SUMSQ"] = "SUMSQ";
2791
+ FUNCTION_NAMES_MATH["SUMX2MY2"] = "SUMX2MY2";
2792
+ FUNCTION_NAMES_MATH["SUMX2PY2"] = "SUMX2PY2";
2793
+ FUNCTION_NAMES_MATH["SUMXMY2"] = "SUMXMY2";
2794
+ FUNCTION_NAMES_MATH["TAN"] = "TAN";
2795
+ FUNCTION_NAMES_MATH["TANH"] = "TANH";
2796
+ FUNCTION_NAMES_MATH["TRUNC"] = "TRUNC";
2797
+ return FUNCTION_NAMES_MATH;
2798
+ }({});
2799
+
2800
+ //#endregion
2801
+ //#region src/functions/statistical/function-names.ts
2802
+ /**
2803
+ * Copyright 2023-present DreamNum Co., Ltd.
2804
+ *
2805
+ * Licensed under the Apache License, Version 2.0 (the "License");
2806
+ * you may not use this file except in compliance with the License.
2807
+ * You may obtain a copy of the License at
2808
+ *
2809
+ * http://www.apache.org/licenses/LICENSE-2.0
2810
+ *
2811
+ * Unless required by applicable law or agreed to in writing, software
2812
+ * distributed under the License is distributed on an "AS IS" BASIS,
2813
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2814
+ * See the License for the specific language governing permissions and
2815
+ * limitations under the License.
2816
+ */
2817
+ let FUNCTION_NAMES_STATISTICAL = /* @__PURE__ */ function(FUNCTION_NAMES_STATISTICAL) {
2818
+ FUNCTION_NAMES_STATISTICAL["AVEDEV"] = "AVEDEV";
2819
+ FUNCTION_NAMES_STATISTICAL["AVERAGE"] = "AVERAGE";
2820
+ FUNCTION_NAMES_STATISTICAL["AVERAGE_WEIGHTED"] = "AVERAGE.WEIGHTED";
2821
+ FUNCTION_NAMES_STATISTICAL["AVERAGEA"] = "AVERAGEA";
2822
+ FUNCTION_NAMES_STATISTICAL["AVERAGEIF"] = "AVERAGEIF";
2823
+ FUNCTION_NAMES_STATISTICAL["AVERAGEIFS"] = "AVERAGEIFS";
2824
+ FUNCTION_NAMES_STATISTICAL["BETA_DIST"] = "BETA.DIST";
2825
+ FUNCTION_NAMES_STATISTICAL["BETA_INV"] = "BETA.INV";
2826
+ FUNCTION_NAMES_STATISTICAL["BINOM_DIST"] = "BINOM.DIST";
2827
+ FUNCTION_NAMES_STATISTICAL["BINOM_DIST_RANGE"] = "BINOM.DIST.RANGE";
2828
+ FUNCTION_NAMES_STATISTICAL["BINOM_INV"] = "BINOM.INV";
2829
+ FUNCTION_NAMES_STATISTICAL["CHISQ_DIST"] = "CHISQ.DIST";
2830
+ FUNCTION_NAMES_STATISTICAL["CHISQ_DIST_RT"] = "CHISQ.DIST.RT";
2831
+ FUNCTION_NAMES_STATISTICAL["CHISQ_INV"] = "CHISQ.INV";
2832
+ FUNCTION_NAMES_STATISTICAL["CHISQ_INV_RT"] = "CHISQ.INV.RT";
2833
+ FUNCTION_NAMES_STATISTICAL["CHISQ_TEST"] = "CHISQ.TEST";
2834
+ FUNCTION_NAMES_STATISTICAL["CONFIDENCE_NORM"] = "CONFIDENCE.NORM";
2835
+ FUNCTION_NAMES_STATISTICAL["CONFIDENCE_T"] = "CONFIDENCE.T";
2836
+ FUNCTION_NAMES_STATISTICAL["CORREL"] = "CORREL";
2837
+ FUNCTION_NAMES_STATISTICAL["COUNT"] = "COUNT";
2838
+ FUNCTION_NAMES_STATISTICAL["COUNTA"] = "COUNTA";
2839
+ FUNCTION_NAMES_STATISTICAL["COUNTBLANK"] = "COUNTBLANK";
2840
+ FUNCTION_NAMES_STATISTICAL["COUNTIF"] = "COUNTIF";
2841
+ FUNCTION_NAMES_STATISTICAL["COUNTIFS"] = "COUNTIFS";
2842
+ FUNCTION_NAMES_STATISTICAL["COVARIANCE_P"] = "COVARIANCE.P";
2843
+ FUNCTION_NAMES_STATISTICAL["COVARIANCE_S"] = "COVARIANCE.S";
2844
+ FUNCTION_NAMES_STATISTICAL["DEVSQ"] = "DEVSQ";
2845
+ FUNCTION_NAMES_STATISTICAL["EXPON_DIST"] = "EXPON.DIST";
2846
+ FUNCTION_NAMES_STATISTICAL["F_DIST"] = "F.DIST";
2847
+ FUNCTION_NAMES_STATISTICAL["F_DIST_RT"] = "F.DIST.RT";
2848
+ FUNCTION_NAMES_STATISTICAL["F_INV"] = "F.INV";
2849
+ FUNCTION_NAMES_STATISTICAL["F_INV_RT"] = "F.INV.RT";
2850
+ FUNCTION_NAMES_STATISTICAL["F_TEST"] = "F.TEST";
2851
+ FUNCTION_NAMES_STATISTICAL["FISHER"] = "FISHER";
2852
+ FUNCTION_NAMES_STATISTICAL["FISHERINV"] = "FISHERINV";
2853
+ FUNCTION_NAMES_STATISTICAL["FORECAST"] = "FORECAST";
2854
+ FUNCTION_NAMES_STATISTICAL["FORECAST_ETS"] = "FORECAST.ETS";
2855
+ FUNCTION_NAMES_STATISTICAL["FORECAST_ETS_CONFINT"] = "FORECAST.ETS.CONFINT";
2856
+ FUNCTION_NAMES_STATISTICAL["FORECAST_ETS_SEASONALITY"] = "FORECAST.ETS.SEASONALITY";
2857
+ FUNCTION_NAMES_STATISTICAL["FORECAST_ETS_STAT"] = "FORECAST.ETS.STAT";
2858
+ FUNCTION_NAMES_STATISTICAL["FORECAST_LINEAR"] = "FORECAST.LINEAR";
2859
+ FUNCTION_NAMES_STATISTICAL["FREQUENCY"] = "FREQUENCY";
2860
+ FUNCTION_NAMES_STATISTICAL["GAMMA"] = "GAMMA";
2861
+ FUNCTION_NAMES_STATISTICAL["GAMMA_DIST"] = "GAMMA.DIST";
2862
+ FUNCTION_NAMES_STATISTICAL["GAMMA_INV"] = "GAMMA.INV";
2863
+ FUNCTION_NAMES_STATISTICAL["GAMMALN"] = "GAMMALN";
2864
+ FUNCTION_NAMES_STATISTICAL["GAMMALN_PRECISE"] = "GAMMALN.PRECISE";
2865
+ FUNCTION_NAMES_STATISTICAL["GAUSS"] = "GAUSS";
2866
+ FUNCTION_NAMES_STATISTICAL["GEOMEAN"] = "GEOMEAN";
2867
+ FUNCTION_NAMES_STATISTICAL["GROWTH"] = "GROWTH";
2868
+ FUNCTION_NAMES_STATISTICAL["HARMEAN"] = "HARMEAN";
2869
+ FUNCTION_NAMES_STATISTICAL["HYPGEOM_DIST"] = "HYPGEOM.DIST";
2870
+ FUNCTION_NAMES_STATISTICAL["INTERCEPT"] = "INTERCEPT";
2871
+ FUNCTION_NAMES_STATISTICAL["KURT"] = "KURT";
2872
+ FUNCTION_NAMES_STATISTICAL["LARGE"] = "LARGE";
2873
+ FUNCTION_NAMES_STATISTICAL["LINEST"] = "LINEST";
2874
+ FUNCTION_NAMES_STATISTICAL["LOGEST"] = "LOGEST";
2875
+ FUNCTION_NAMES_STATISTICAL["LOGNORM_DIST"] = "LOGNORM.DIST";
2876
+ FUNCTION_NAMES_STATISTICAL["LOGNORM_INV"] = "LOGNORM.INV";
2877
+ FUNCTION_NAMES_STATISTICAL["MARGINOFERROR"] = "MARGINOFERROR";
2878
+ FUNCTION_NAMES_STATISTICAL["MAX"] = "MAX";
2879
+ FUNCTION_NAMES_STATISTICAL["MAXA"] = "MAXA";
2880
+ FUNCTION_NAMES_STATISTICAL["MAXIFS"] = "MAXIFS";
2881
+ FUNCTION_NAMES_STATISTICAL["MEDIAN"] = "MEDIAN";
2882
+ FUNCTION_NAMES_STATISTICAL["MIN"] = "MIN";
2883
+ FUNCTION_NAMES_STATISTICAL["MINA"] = "MINA";
2884
+ FUNCTION_NAMES_STATISTICAL["MINIFS"] = "MINIFS";
2885
+ FUNCTION_NAMES_STATISTICAL["MODE_MULT"] = "MODE.MULT";
2886
+ FUNCTION_NAMES_STATISTICAL["MODE_SNGL"] = "MODE.SNGL";
2887
+ FUNCTION_NAMES_STATISTICAL["NEGBINOM_DIST"] = "NEGBINOM.DIST";
2888
+ FUNCTION_NAMES_STATISTICAL["NORM_DIST"] = "NORM.DIST";
2889
+ FUNCTION_NAMES_STATISTICAL["NORM_INV"] = "NORM.INV";
2890
+ FUNCTION_NAMES_STATISTICAL["NORM_S_DIST"] = "NORM.S.DIST";
2891
+ FUNCTION_NAMES_STATISTICAL["NORM_S_INV"] = "NORM.S.INV";
2892
+ FUNCTION_NAMES_STATISTICAL["PEARSON"] = "PEARSON";
2893
+ FUNCTION_NAMES_STATISTICAL["PERCENTILE_EXC"] = "PERCENTILE.EXC";
2894
+ FUNCTION_NAMES_STATISTICAL["PERCENTILE_INC"] = "PERCENTILE.INC";
2895
+ FUNCTION_NAMES_STATISTICAL["PERCENTRANK_EXC"] = "PERCENTRANK.EXC";
2896
+ FUNCTION_NAMES_STATISTICAL["PERCENTRANK_INC"] = "PERCENTRANK.INC";
2897
+ FUNCTION_NAMES_STATISTICAL["PERMUT"] = "PERMUT";
2898
+ FUNCTION_NAMES_STATISTICAL["PERMUTATIONA"] = "PERMUTATIONA";
2899
+ FUNCTION_NAMES_STATISTICAL["PHI"] = "PHI";
2900
+ FUNCTION_NAMES_STATISTICAL["POISSON_DIST"] = "POISSON.DIST";
2901
+ FUNCTION_NAMES_STATISTICAL["PROB"] = "PROB";
2902
+ FUNCTION_NAMES_STATISTICAL["QUARTILE_EXC"] = "QUARTILE.EXC";
2903
+ FUNCTION_NAMES_STATISTICAL["QUARTILE_INC"] = "QUARTILE.INC";
2904
+ FUNCTION_NAMES_STATISTICAL["RANK_AVG"] = "RANK.AVG";
2905
+ FUNCTION_NAMES_STATISTICAL["RANK_EQ"] = "RANK.EQ";
2906
+ FUNCTION_NAMES_STATISTICAL["RSQ"] = "RSQ";
2907
+ FUNCTION_NAMES_STATISTICAL["SKEW"] = "SKEW";
2908
+ FUNCTION_NAMES_STATISTICAL["SKEW_P"] = "SKEW.P";
2909
+ FUNCTION_NAMES_STATISTICAL["SLOPE"] = "SLOPE";
2910
+ FUNCTION_NAMES_STATISTICAL["SMALL"] = "SMALL";
2911
+ FUNCTION_NAMES_STATISTICAL["STANDARDIZE"] = "STANDARDIZE";
2912
+ FUNCTION_NAMES_STATISTICAL["STDEV_P"] = "STDEV.P";
2913
+ FUNCTION_NAMES_STATISTICAL["STDEV_S"] = "STDEV.S";
2914
+ FUNCTION_NAMES_STATISTICAL["STDEVA"] = "STDEVA";
2915
+ FUNCTION_NAMES_STATISTICAL["STDEVPA"] = "STDEVPA";
2916
+ FUNCTION_NAMES_STATISTICAL["STEYX"] = "STEYX";
2917
+ FUNCTION_NAMES_STATISTICAL["T_DIST"] = "T.DIST";
2918
+ FUNCTION_NAMES_STATISTICAL["T_DIST_2T"] = "T.DIST.2T";
2919
+ FUNCTION_NAMES_STATISTICAL["T_DIST_RT"] = "T.DIST.RT";
2920
+ FUNCTION_NAMES_STATISTICAL["T_INV"] = "T.INV";
2921
+ FUNCTION_NAMES_STATISTICAL["T_INV_2T"] = "T.INV.2T";
2922
+ FUNCTION_NAMES_STATISTICAL["T_TEST"] = "T.TEST";
2923
+ FUNCTION_NAMES_STATISTICAL["TREND"] = "TREND";
2924
+ FUNCTION_NAMES_STATISTICAL["TRIMMEAN"] = "TRIMMEAN";
2925
+ FUNCTION_NAMES_STATISTICAL["VAR_P"] = "VAR.P";
2926
+ FUNCTION_NAMES_STATISTICAL["VAR_S"] = "VAR.S";
2927
+ FUNCTION_NAMES_STATISTICAL["VARA"] = "VARA";
2928
+ FUNCTION_NAMES_STATISTICAL["VARPA"] = "VARPA";
2929
+ FUNCTION_NAMES_STATISTICAL["WEIBULL_DIST"] = "WEIBULL.DIST";
2930
+ FUNCTION_NAMES_STATISTICAL["Z_TEST"] = "Z.TEST";
2931
+ return FUNCTION_NAMES_STATISTICAL;
2932
+ }({});
2933
+
2934
+ //#endregion
2935
+ //#region src/functions/text/function-names.ts
2936
+ /**
2937
+ * Copyright 2023-present DreamNum Co., Ltd.
2938
+ *
2939
+ * Licensed under the Apache License, Version 2.0 (the "License");
2940
+ * you may not use this file except in compliance with the License.
2941
+ * You may obtain a copy of the License at
2942
+ *
2943
+ * http://www.apache.org/licenses/LICENSE-2.0
2944
+ *
2945
+ * Unless required by applicable law or agreed to in writing, software
2946
+ * distributed under the License is distributed on an "AS IS" BASIS,
2947
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2948
+ * See the License for the specific language governing permissions and
2949
+ * limitations under the License.
2950
+ */
2951
+ let FUNCTION_NAMES_TEXT = /* @__PURE__ */ function(FUNCTION_NAMES_TEXT) {
2952
+ FUNCTION_NAMES_TEXT["ASC"] = "ASC";
2953
+ FUNCTION_NAMES_TEXT["ARRAYTOTEXT"] = "ARRAYTOTEXT";
2954
+ FUNCTION_NAMES_TEXT["BAHTTEXT"] = "BAHTTEXT";
2955
+ FUNCTION_NAMES_TEXT["CHAR"] = "CHAR";
2956
+ FUNCTION_NAMES_TEXT["CLEAN"] = "CLEAN";
2957
+ FUNCTION_NAMES_TEXT["CODE"] = "CODE";
2958
+ FUNCTION_NAMES_TEXT["CONCAT"] = "CONCAT";
2959
+ FUNCTION_NAMES_TEXT["CONCATENATE"] = "CONCATENATE";
2960
+ FUNCTION_NAMES_TEXT["DBCS"] = "DBCS";
2961
+ FUNCTION_NAMES_TEXT["DOLLAR"] = "DOLLAR";
2962
+ FUNCTION_NAMES_TEXT["EXACT"] = "EXACT";
2963
+ FUNCTION_NAMES_TEXT["FIND"] = "FIND";
2964
+ FUNCTION_NAMES_TEXT["FINDB"] = "FINDB";
2965
+ FUNCTION_NAMES_TEXT["FIXED"] = "FIXED";
2966
+ FUNCTION_NAMES_TEXT["LEFT"] = "LEFT";
2967
+ FUNCTION_NAMES_TEXT["LEFTB"] = "LEFTB";
2968
+ FUNCTION_NAMES_TEXT["LEN"] = "LEN";
2969
+ FUNCTION_NAMES_TEXT["LENB"] = "LENB";
2970
+ FUNCTION_NAMES_TEXT["LOWER"] = "LOWER";
2971
+ FUNCTION_NAMES_TEXT["MID"] = "MID";
2972
+ FUNCTION_NAMES_TEXT["MIDB"] = "MIDB";
2973
+ FUNCTION_NAMES_TEXT["NUMBERSTRING"] = "NUMBERSTRING";
2974
+ FUNCTION_NAMES_TEXT["NUMBERVALUE"] = "NUMBERVALUE";
2975
+ FUNCTION_NAMES_TEXT["PHONETIC"] = "PHONETIC";
2976
+ FUNCTION_NAMES_TEXT["PROPER"] = "PROPER";
2977
+ FUNCTION_NAMES_TEXT["REGEXEXTRACT"] = "REGEXEXTRACT";
2978
+ FUNCTION_NAMES_TEXT["REGEXMATCH"] = "REGEXMATCH";
2979
+ FUNCTION_NAMES_TEXT["REGEXREPLACE"] = "REGEXREPLACE";
2980
+ FUNCTION_NAMES_TEXT["REPLACE"] = "REPLACE";
2981
+ FUNCTION_NAMES_TEXT["REPLACEB"] = "REPLACEB";
2982
+ FUNCTION_NAMES_TEXT["REPT"] = "REPT";
2983
+ FUNCTION_NAMES_TEXT["RIGHT"] = "RIGHT";
2984
+ FUNCTION_NAMES_TEXT["RIGHTB"] = "RIGHTB";
2985
+ FUNCTION_NAMES_TEXT["SEARCH"] = "SEARCH";
2986
+ FUNCTION_NAMES_TEXT["SEARCHB"] = "SEARCHB";
2987
+ FUNCTION_NAMES_TEXT["SUBSTITUTE"] = "SUBSTITUTE";
2988
+ FUNCTION_NAMES_TEXT["T"] = "T";
2989
+ FUNCTION_NAMES_TEXT["TEXT"] = "TEXT";
2990
+ FUNCTION_NAMES_TEXT["TEXTAFTER"] = "TEXTAFTER";
2991
+ FUNCTION_NAMES_TEXT["TEXTBEFORE"] = "TEXTBEFORE";
2992
+ FUNCTION_NAMES_TEXT["TEXTJOIN"] = "TEXTJOIN";
2993
+ FUNCTION_NAMES_TEXT["TEXTSPLIT"] = "TEXTSPLIT";
2994
+ FUNCTION_NAMES_TEXT["TRIM"] = "TRIM";
2995
+ FUNCTION_NAMES_TEXT["UNICHAR"] = "UNICHAR";
2996
+ FUNCTION_NAMES_TEXT["UNICODE"] = "UNICODE";
2997
+ FUNCTION_NAMES_TEXT["UPPER"] = "UPPER";
2998
+ FUNCTION_NAMES_TEXT["VALUE"] = "VALUE";
2999
+ FUNCTION_NAMES_TEXT["VALUETOTEXT"] = "VALUETOTEXT";
3000
+ FUNCTION_NAMES_TEXT["CALL"] = "CALL";
3001
+ FUNCTION_NAMES_TEXT["EUROCONVERT"] = "EUROCONVERT";
3002
+ FUNCTION_NAMES_TEXT["REGISTER_ID"] = "REGISTER.ID";
3003
+ return FUNCTION_NAMES_TEXT;
3004
+ }({});
3005
+
3006
+ //#endregion
3007
+ //#region src/functions/web/function-names.ts
3008
+ /**
3009
+ * Copyright 2023-present DreamNum Co., Ltd.
3010
+ *
3011
+ * Licensed under the Apache License, Version 2.0 (the "License");
3012
+ * you may not use this file except in compliance with the License.
3013
+ * You may obtain a copy of the License at
3014
+ *
3015
+ * http://www.apache.org/licenses/LICENSE-2.0
3016
+ *
3017
+ * Unless required by applicable law or agreed to in writing, software
3018
+ * distributed under the License is distributed on an "AS IS" BASIS,
3019
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3020
+ * See the License for the specific language governing permissions and
3021
+ * limitations under the License.
3022
+ */
3023
+ let FUNCTION_NAMES_WEB = /* @__PURE__ */ function(FUNCTION_NAMES_WEB) {
3024
+ FUNCTION_NAMES_WEB["ENCODEURL"] = "ENCODEURL";
3025
+ FUNCTION_NAMES_WEB["FILTERXML"] = "FILTERXML";
3026
+ FUNCTION_NAMES_WEB["WEBSERVICE"] = "WEBSERVICE";
3027
+ return FUNCTION_NAMES_WEB;
3028
+ }({});
3029
+
3030
+ //#endregion
3031
+ //#region src/functions/new-excel-functions.ts
3032
+ const NEW_EXCEL_FUNCTIONS = new Set([
3033
+ "ACOT",
3034
+ "ACOTH",
3035
+ "ARABIC",
3036
+ "BASE",
3037
+ "CEILING.MATH",
3038
+ "CEILING.PRECISE",
3039
+ "COMBINA",
3040
+ "COT",
3041
+ "COTH",
3042
+ "CSC",
3043
+ "CSCH",
3044
+ "DECIMAL",
3045
+ "FLOOR.MATH",
3046
+ "FLOOR.PRECISE",
3047
+ "MUNIT",
3048
+ "RANDARRAY",
3049
+ "SEC",
3050
+ "SECH",
3051
+ "SEQUENCE",
3052
+ "CHOOSECOLS",
3053
+ "CHOOSEROWS",
3054
+ "DROP",
3055
+ "EXPAND",
3056
+ "FILTER",
3057
+ "FORMULATEXT",
3058
+ "HSTACK",
3059
+ "SORT",
3060
+ "SORTBY",
3061
+ "TAKE",
3062
+ "TOCOL",
3063
+ "TOROW",
3064
+ "UNIQUE",
3065
+ "VSTACK",
3066
+ "WRAPCOLS",
3067
+ "WRAPROWS",
3068
+ "XLOOKUP",
3069
+ "XMATCH",
3070
+ "BITAND",
3071
+ "BITLSHIFT",
3072
+ "BITOR",
3073
+ "BITRSHIFT",
3074
+ "BITXOR",
3075
+ "ERF.PRECISE",
3076
+ "ERFC.PRECISE",
3077
+ "IMCOSH",
3078
+ "IMCOT",
3079
+ "IMCSC",
3080
+ "IMCSCH",
3081
+ "IMSEC",
3082
+ "IMSECH",
3083
+ "IMSINH",
3084
+ "IMTAN",
3085
+ "ISFORMULA",
3086
+ "SHEET",
3087
+ "SHEETS",
3088
+ "IFNA",
3089
+ "IFS",
3090
+ "SWITCH",
3091
+ "XOR",
3092
+ "BETA.DIST",
3093
+ "BETA.INV",
3094
+ "BINOM.DIST",
3095
+ "BINOM.DIST.RANGE",
3096
+ "BINOM.INV",
3097
+ "CHISQ.DIST",
3098
+ "CHISQ.DIST.RT",
3099
+ "CHISQ.INV",
3100
+ "CHISQ.INV.RT",
3101
+ "CHISQ.TEST",
3102
+ "CONFIDENCE.NORM",
3103
+ "CONFIDENCE.T",
3104
+ "COVARIANCE.P",
3105
+ "COVARIANCE.S",
3106
+ "EXPON.DIST",
3107
+ "F.DIST",
3108
+ "F.DIST.RT",
3109
+ "F.INV",
3110
+ "F.INV.RT",
3111
+ "F.TEST",
3112
+ "FORECAST.LINEAR",
3113
+ "GAMMA",
3114
+ "GAMMA.DIST",
3115
+ "GAMMA.INV",
3116
+ "GAMMALN.PRECISE",
3117
+ "GAUSS",
3118
+ "HYPGEOM.DIST",
3119
+ "LOGNORM.DIST",
3120
+ "LOGNORM.INV",
3121
+ "MAXIFS",
3122
+ "MINIFS",
3123
+ "MODE.MULT",
3124
+ "MODE.SNGL",
3125
+ "NEGBINOM.DIST",
3126
+ "NORM.DIST",
3127
+ "NORM.INV",
3128
+ "NORM.S.DIST",
3129
+ "NORM.S.INV",
3130
+ "PERCENTILE.EXC",
3131
+ "PERCENTILE.INC",
3132
+ "PERCENTRANK.EXC",
3133
+ "PERCENTRANK.INC",
3134
+ "PERMUTATIONA",
3135
+ "PHI",
3136
+ "POISSON.DIST",
3137
+ "QUARTILE.EXC",
3138
+ "QUARTILE.INC",
3139
+ "RANK.AVG",
3140
+ "RANK.EQ",
3141
+ "SKEW.P",
3142
+ "STDEV.P",
3143
+ "STDEV.S",
3144
+ "T.DIST",
3145
+ "T.DIST.2T",
3146
+ "T.DIST.RT",
3147
+ "T.INV",
3148
+ "T.INV.2T",
3149
+ "T.TEST",
3150
+ "VAR.P",
3151
+ "VAR.S",
3152
+ "WEIBULL.DIST",
3153
+ "Z.TEST",
3154
+ "ARRAYTOTEXT",
3155
+ "ENCODEURL",
3156
+ "NUMBERVALUE",
3157
+ "TEXTAFTER",
3158
+ "TEXTBEFORE",
3159
+ "TEXTJOIN",
3160
+ "TEXTSPLIT",
3161
+ "UNICHAR",
3162
+ "UNICODE",
3163
+ "VALUETOTEXT",
3164
+ "DAYS",
3165
+ "ISOWEEKNUM",
3166
+ "PDURATION",
3167
+ "RRI",
3168
+ "BYCOL",
3169
+ "BYROW",
3170
+ "MAKEARRAY",
3171
+ "MAP",
3172
+ "REDUCE",
3173
+ "SCAN"
3174
+ ]);
3175
+
3176
+ //#endregion
3177
+ //#region src/engine/utils/reference-cache.ts
3178
+ const referenceToRangeCache = new FormulaAstLRU(1e5);
3179
+ function deserializeRangeWithSheetWithCache(refString) {
3180
+ const refCache = referenceToRangeCache.get(refString);
3181
+ if (refCache) return refCache;
3182
+ const result = deserializeRangeWithSheet(refString);
3183
+ referenceToRangeCache.set(refString, result);
3184
+ return deserializeRangeWithSheet(refString);
3185
+ }
3186
+ function clearReferenceToRangeCache() {
3187
+ referenceToRangeCache.clear();
3188
+ }
3189
+
3190
+ //#endregion
3191
+ //#region src/engine/utils/sequence.ts
3192
+ let sequenceNodeType = /* @__PURE__ */ function(sequenceNodeType) {
3193
+ sequenceNodeType[sequenceNodeType["NORMAL"] = 0] = "NORMAL";
3194
+ sequenceNodeType[sequenceNodeType["NUMBER"] = 1] = "NUMBER";
3195
+ sequenceNodeType[sequenceNodeType["STRING"] = 2] = "STRING";
3196
+ sequenceNodeType[sequenceNodeType["FUNCTION"] = 3] = "FUNCTION";
3197
+ sequenceNodeType[sequenceNodeType["REFERENCE"] = 4] = "REFERENCE";
3198
+ sequenceNodeType[sequenceNodeType["ARRAY"] = 5] = "ARRAY";
3199
+ sequenceNodeType[sequenceNodeType["DEFINED_NAME"] = 6] = "DEFINED_NAME";
3200
+ sequenceNodeType[sequenceNodeType["TABLE"] = 7] = "TABLE";
3201
+ return sequenceNodeType;
3202
+ }({});
3203
+ /**
3204
+ * Deserialize Sequence to text.
3205
+ * @param newSequenceNodes
3206
+ * @returns
3207
+ */
3208
+ function generateStringWithSequence(newSequenceNodes) {
3209
+ let sequenceString = "";
3210
+ for (const node of newSequenceNodes) if (typeof node === "string") sequenceString += node;
3211
+ else sequenceString += node.token;
3212
+ return sequenceString;
3213
+ }
3214
+
3215
+ //#endregion
3216
+ //#region src/engine/analysis/lexer-node.ts
3217
+ var LexerNode = class LexerNode {
3218
+ constructor() {
3219
+ _defineProperty(this, "_parent", void 0);
3220
+ _defineProperty(this, "_token", "R_1");
3221
+ _defineProperty(this, "_children", []);
3222
+ _defineProperty(this, "_lambdaId", void 0);
3223
+ _defineProperty(this, "_functionDefinitionPrivacyVar", void 0);
3224
+ _defineProperty(this, "_lambdaParameter", "");
3225
+ _defineProperty(this, "_startIndex", -1);
3226
+ _defineProperty(this, "_endIndex", -1);
3227
+ _defineProperty(this, "_definedNames", []);
3228
+ }
3229
+ dispose() {
3230
+ var _this$_functionDefini;
3231
+ this._children.forEach((node) => {
3232
+ if (!(typeof node === "string")) node.dispose();
3233
+ });
3234
+ (_this$_functionDefini = this._functionDefinitionPrivacyVar) === null || _this$_functionDefini === void 0 || _this$_functionDefini.clear();
3235
+ this._functionDefinitionPrivacyVar = null;
3236
+ this._children = [];
3237
+ this._parent = null;
3238
+ this._definedNames = [];
3239
+ }
3240
+ getDefinedNames() {
3241
+ return this._definedNames;
3242
+ }
3243
+ getStartIndex() {
3244
+ return this._startIndex;
3245
+ }
3246
+ getLambdaId() {
3247
+ return this._lambdaId;
3248
+ }
3249
+ setLambdaId(lambdaId) {
3250
+ this._lambdaId = lambdaId;
3251
+ }
3252
+ getFunctionDefinitionPrivacyVar() {
3253
+ return this._functionDefinitionPrivacyVar;
3254
+ }
3255
+ setLambdaPrivacyVar(lambdaPrivacyVar) {
3256
+ this._functionDefinitionPrivacyVar = lambdaPrivacyVar;
3257
+ }
3258
+ getLambdaParameter() {
3259
+ return this._lambdaParameter;
3260
+ }
3261
+ setLambdaParameter(lambdaParameter) {
3262
+ this._lambdaParameter = lambdaParameter;
3263
+ }
3264
+ getParent() {
3265
+ return this._parent;
3266
+ }
3267
+ setParent(lexerNode) {
3268
+ this._parent = lexerNode;
3269
+ }
3270
+ getChildren() {
3271
+ return this._children;
3272
+ }
3273
+ setChildren(children) {
3274
+ this._children = children;
3275
+ }
3276
+ addChildren(children) {
3277
+ this._children.push(children);
3278
+ }
3279
+ addChildrenFirst(children) {
3280
+ this._children.unshift(children);
3281
+ }
3282
+ getToken() {
3283
+ return this._token;
3284
+ }
3285
+ setToken(token) {
3286
+ this._token = token;
3287
+ }
3288
+ setIndex(st, ed) {
3289
+ this._startIndex = st;
3290
+ this._endIndex = ed;
3291
+ }
3292
+ setDefinedNames(definedNames) {
3293
+ this._definedNames = definedNames;
3294
+ }
3295
+ hasDefinedNames() {
3296
+ return this._definedNames.length > 0;
3297
+ }
3298
+ replaceChild(lexerNode, newLexerNode) {
3299
+ const i = this._getIndexInParent(lexerNode);
3300
+ if (i == null) return;
3301
+ this.getChildren().splice(i, 1, newLexerNode);
3302
+ newLexerNode.setParent(this);
3303
+ }
3304
+ changeToParent(newParentLexerNode) {
3305
+ const parentNode = this.getParent();
3306
+ if (parentNode) parentNode.removeChild(this);
3307
+ this.setParent(newParentLexerNode);
3308
+ newParentLexerNode.getChildren().push(this);
3309
+ }
3310
+ removeChild(lexerNode) {
3311
+ const i = this._getIndexInParent(lexerNode);
3312
+ if (i == null) return;
3313
+ this.getChildren().splice(i, 1);
3314
+ }
3315
+ serialize() {
3316
+ const token = this.getToken();
3317
+ const children = this.getChildren();
3318
+ const childrenSerialization = [];
3319
+ const childrenCount = children.length;
3320
+ for (let i = 0; i < childrenCount; i++) {
3321
+ const item = children[i];
3322
+ if (item instanceof LexerNode) childrenSerialization.push(item.serialize());
3323
+ else childrenSerialization.push(item);
2322
3324
  }
2323
3325
  return {
2324
3326
  token,
@@ -2355,6 +3357,19 @@ var LexerTreeBuilder = class extends _univerjs_core.Disposable {
2355
3357
  _defineProperty(this, "_colonState", false);
2356
3358
  _defineProperty(this, "_formulaErrorCount", 0);
2357
3359
  _defineProperty(this, "_tableBracketState", false);
3360
+ _defineProperty(this, "_hasNewExcelFunction", false);
3361
+ _defineProperty(this, "_lambdaFunctionParameterSet", /* @__PURE__ */ new Set());
3362
+ _defineProperty(this, "_xlpmPrefix", "_xlpm.");
3363
+ _defineProperty(this, "_xlfnPrefix", "_xlfn.");
3364
+ _defineProperty(this, "_currentUnitId", "");
3365
+ }
3366
+ _resetPrefix() {
3367
+ this._xlpmPrefix = "_xlpm.";
3368
+ this._xlfnPrefix = "_xlfn.";
3369
+ }
3370
+ _clearPrefix() {
3371
+ this._xlpmPrefix = "";
3372
+ this._xlfnPrefix = "";
2358
3373
  }
2359
3374
  dispose() {
2360
3375
  this._resetTemp();
@@ -3479,11 +4494,289 @@ var LexerTreeBuilder = class extends _univerjs_core.Disposable {
3479
4494
  });
3480
4495
  }
3481
4496
  getNewFormulaWithPrefix(formulaString, hasFunction) {
4497
+ const lexerNode = this.treeBuilder(formulaString, false);
4498
+ if (!lexerNode || lexerNode === "#VALUE!" || Array.isArray(lexerNode)) return null;
4499
+ const formulaStrings = [];
4500
+ this._hasNewExcelFunction = false;
4501
+ this._generateNewFunctionString(lexerNode, formulaStrings, hasFunction);
4502
+ if (this._hasNewExcelFunction) return `=${formulaStrings.join("")}`;
3482
4503
  return null;
3483
4504
  }
4505
+ _generateNewFunctionString(lexerNode, formulaStrings, hasFunction) {
4506
+ const token = lexerNode.getToken();
4507
+ const tokenTrim = token.trim();
4508
+ const tokenTrimUpper = tokenTrim.toUpperCase();
4509
+ const tokenForFunction = this._clearFunctionString(tokenTrimUpper);
4510
+ const isFunctionNode = hasFunction(tokenForFunction);
4511
+ let curNodeType = 0;
4512
+ if (token === "R_1") curNodeType = 3;
4513
+ else if (token === "P_1") curNodeType = 4;
4514
+ else if (token === "L_1") curNodeType = 5;
4515
+ else if (NEW_EXCEL_FUNCTIONS.has(tokenForFunction)) {
4516
+ formulaStrings.push(`${this._xlfnPrefix}${tokenTrim}`);
4517
+ this._hasNewExcelFunction = true;
4518
+ } else if (tokenTrimUpper === "LAMBDA") {
4519
+ formulaStrings.push(`${this._xlfnPrefix}${tokenTrim}`);
4520
+ this._hasNewExcelFunction = true;
4521
+ curNodeType = 2;
4522
+ } else if (tokenTrimUpper === "LET") {
4523
+ formulaStrings.push(`${this._xlfnPrefix}${tokenTrim}`);
4524
+ this._hasNewExcelFunction = true;
4525
+ curNodeType = 1;
4526
+ } else if (tokenTrimUpper === ":") curNodeType = 8;
4527
+ else if (SUFFIX_TOKEN_SET.has(tokenTrimUpper)) curNodeType = 7;
4528
+ else if (tokenTrimUpper === "-") {
4529
+ if (this._checkAddBracketForMinus(lexerNode)) curNodeType = 9;
4530
+ formulaStrings.push(token);
4531
+ } else {
4532
+ formulaStrings.push(token);
4533
+ curNodeType = 10;
4534
+ }
4535
+ if (isFunctionNode) {
4536
+ if (curNodeType !== 2 && curNodeType !== 1) curNodeType = 6;
4537
+ formulaStrings.push("(");
4538
+ } else if (curNodeType === 9) formulaStrings.push("(");
4539
+ const children = lexerNode.getChildren();
4540
+ const childrenCount = children.length;
4541
+ if (curNodeType === 2) {
4542
+ const firstChild = children[0];
4543
+ let firstIsInputIndex = 0;
4544
+ if (firstChild instanceof LexerNode) {
4545
+ if (firstChild.getToken() === "L_1") firstIsInputIndex = 1;
4546
+ }
4547
+ for (let i = firstIsInputIndex; i < childrenCount - 1; i++) {
4548
+ const item = children[i];
4549
+ if (item instanceof LexerNode) {
4550
+ const varName = item.getChildren()[0];
4551
+ if (typeof varName === "string") {
4552
+ if (this._lambdaFunctionParameterSet.has(varName)) console.error(`Lambda parameter name "${varName}" is duplicated.`);
4553
+ this._lambdaFunctionParameterSet.add(varName);
4554
+ formulaStrings.push(`${this._xlpmPrefix}${varName}`);
4555
+ this._hasNewExcelFunction = true;
4556
+ }
4557
+ }
4558
+ formulaStrings.push(",");
4559
+ }
4560
+ this._handleNewFunctionChild(children[childrenCount - 1], formulaStrings, hasFunction);
4561
+ if (firstIsInputIndex === 1) {
4562
+ formulaStrings.push(")");
4563
+ formulaStrings.push("(");
4564
+ this._generateNewFunctionString(firstChild, formulaStrings, hasFunction);
4565
+ formulaStrings.push(")");
4566
+ } else formulaStrings.push(")");
4567
+ return;
4568
+ } else if (curNodeType === 1) {
4569
+ for (let i = 0; i < childrenCount - 1; i++) {
4570
+ const item = children[i];
4571
+ if (item instanceof LexerNode && i % 2 === 0) {
4572
+ const varName = item.getChildren()[0];
4573
+ if (typeof varName === "string") {
4574
+ if (this._lambdaFunctionParameterSet.has(varName)) console.error(`Let variable name "${varName}" is duplicated.`);
4575
+ this._lambdaFunctionParameterSet.add(varName);
4576
+ formulaStrings.push(`${this._xlpmPrefix}${varName}`);
4577
+ this._hasNewExcelFunction = true;
4578
+ formulaStrings.push(",");
4579
+ continue;
4580
+ }
4581
+ }
4582
+ this._handleNewFunctionChild(item, formulaStrings, hasFunction);
4583
+ if (item instanceof LexerNode) {
4584
+ const nextItem = children[i + 1];
4585
+ if (nextItem && nextItem instanceof LexerNode) formulaStrings.push(",");
4586
+ }
4587
+ }
4588
+ this._handleNewFunctionChild(children[childrenCount - 1], formulaStrings, hasFunction);
4589
+ formulaStrings.push(")");
4590
+ return;
4591
+ } else if (curNodeType === 8) {
4592
+ const firstNode = children[0];
4593
+ const secondNode = children[1];
4594
+ this._handleNewFunctionChild(firstNode, formulaStrings, hasFunction);
4595
+ formulaStrings.push(token);
4596
+ this._handleNewFunctionChild(secondNode, formulaStrings, hasFunction);
4597
+ return;
4598
+ }
4599
+ for (let i = 0; i < childrenCount; i++) {
4600
+ const item = children[i];
4601
+ this._handleNewFunctionChild(item, formulaStrings, hasFunction);
4602
+ if (item instanceof LexerNode) {
4603
+ const nextItem = children[i + 1];
4604
+ if (nextItem && nextItem instanceof LexerNode) formulaStrings.push(",");
4605
+ }
4606
+ }
4607
+ if (curNodeType === 7) formulaStrings.push(token);
4608
+ if (isFunctionNode) formulaStrings.push(")");
4609
+ else if (curNodeType === 9) formulaStrings.push(")");
4610
+ }
4611
+ _handleNewFunctionChild(item, formulaStrings, hasFunction) {
4612
+ if (item instanceof LexerNode) this._generateNewFunctionString(item, formulaStrings, hasFunction);
4613
+ else if (this._lambdaFunctionParameterSet.has(item)) {
4614
+ formulaStrings.push(`${this._xlpmPrefix}${item}`);
4615
+ this._hasNewExcelFunction = true;
4616
+ } else formulaStrings.push(item);
4617
+ }
4618
+ _clearFunctionString(token) {
4619
+ let t = token.trim();
4620
+ if (!t) return t;
4621
+ const firstChar = t[0];
4622
+ if (firstChar === "@" || firstChar === "-" || firstChar === "+") t = t.slice(1);
4623
+ if (!t) return t;
4624
+ const lastChar = t[t.length - 1];
4625
+ if (SUFFIX_TOKEN_SET.has(lastChar)) t = t.slice(0, -1);
4626
+ return t;
4627
+ }
4628
+ _checkAddBracketForMinus(node) {
4629
+ const childrenFirst = node.getChildren()[0];
4630
+ if (!childrenFirst || !(childrenFirst instanceof LexerNode) || node.getChildren().length > 1) return false;
4631
+ const children = childrenFirst.getChildren();
4632
+ const childrenCount = children.length;
4633
+ if (childrenCount === 1) return false;
4634
+ for (let i = 0; i < childrenCount; i++) {
4635
+ const item = children[i];
4636
+ if (!(item instanceof LexerNode) && OPERATOR_TOKEN_SET.has(item)) return true;
4637
+ }
4638
+ return false;
4639
+ }
3484
4640
  getFormulaExprTree(formulaString, unitId, hasFunction, getDefinedNameName, getTable) {
4641
+ const lexerNode = this.treeBuilder(formulaString, false);
4642
+ if (!lexerNode || lexerNode === "#VALUE!" || Array.isArray(lexerNode)) return null;
4643
+ this._clearPrefix();
4644
+ this._currentUnitId = unitId;
4645
+ const newNode = this._generateExprTree(lexerNode, hasFunction, getDefinedNameName, getTable);
4646
+ this._currentUnitId = "";
4647
+ this._resetPrefix();
4648
+ return newNode;
4649
+ }
4650
+ _generateExprTree(lexerNodeRoot, hasFunction, getDefinedNameName, getTable) {
4651
+ const newNode = {
4652
+ value: "",
4653
+ children: [],
4654
+ startIndex: 0
4655
+ };
4656
+ let lexerNode = lexerNodeRoot;
4657
+ if (lexerNode instanceof LexerNode && (lexerNode.getToken() === "R_1" || lexerNode.getToken() === "P_1") && lexerNode.getChildren().length === 1) lexerNode = lexerNode.getChildren()[0];
4658
+ if (!(lexerNode instanceof LexerNode)) return this._handleTextNodeForExprTree(lexerNode, getDefinedNameName, getTable);
4659
+ const children = lexerNode.getChildren();
4660
+ const childrenCount = children.length;
4661
+ const formulaStrings = [];
4662
+ this._generateNewFunctionString(lexerNode, formulaStrings, hasFunction);
4663
+ newNode.value = formulaStrings.join("");
4664
+ newNode.startIndex = lexerNode.getStartIndex();
4665
+ const curNodeType = this._getCurNodeTypeForExprTree(lexerNode);
4666
+ if (curNodeType === 2) {
4667
+ const firstChild = children[0];
4668
+ if (firstChild instanceof LexerNode) {
4669
+ if (firstChild.getToken().trim() !== "L_1") return newNode;
4670
+ this._handleLambdaForExprTree(firstChild, newNode, hasFunction, getDefinedNameName, getTable);
4671
+ }
4672
+ return newNode;
4673
+ } else if (curNodeType === 1) {
4674
+ for (let i = 0; i < childrenCount - 1; i++) {
4675
+ const item = children[i];
4676
+ if (item instanceof LexerNode && i % 2 === 1) {
4677
+ const itemChildren = item.getChildren();
4678
+ if (itemChildren.length === 1 && !(itemChildren[0] instanceof LexerNode)) continue;
4679
+ const childNode = this._generateExprTree(item, hasFunction, getDefinedNameName, getTable);
4680
+ childNode && newNode.children.push(childNode);
4681
+ }
4682
+ }
4683
+ return newNode;
4684
+ } else if (curNodeType === 8) {
4685
+ const firstNode = children[0];
4686
+ if (firstNode instanceof LexerNode) {
4687
+ const firstChildNode = firstNode.getChildren()[0];
4688
+ if (firstChildNode instanceof LexerNode) newNode.startIndex = firstChildNode.getStartIndex();
4689
+ }
4690
+ if (this._checkColonNodeForExprTree(lexerNode)) return newNode;
4691
+ } else if (curNodeType === 7) {
4692
+ const firstNode = children[0];
4693
+ if (firstNode instanceof LexerNode) {
4694
+ const firstChildNode = firstNode.getChildren()[0];
4695
+ if (firstChildNode instanceof LexerNode) newNode.startIndex = firstChildNode.getStartIndex();
4696
+ }
4697
+ }
4698
+ this._handleChildrenForExprTree(children, curNodeType, newNode, hasFunction, getDefinedNameName, getTable);
4699
+ return newNode;
4700
+ }
4701
+ _handleChildrenForExprTree(children, curNodeType, newNode, hasFunction, getDefinedNameName, getTable) {
4702
+ for (let i = 0; i < children.length; i++) {
4703
+ let item = children[i];
4704
+ if (!(item instanceof LexerNode)) {
4705
+ const childNode = this._handleTextNodeForExprTree(item, getDefinedNameName, getTable);
4706
+ childNode && newNode.children.push(childNode);
4707
+ continue;
4708
+ }
4709
+ const itemChildren = item.getChildren();
4710
+ if (itemChildren.length === 1 && !(itemChildren[0] instanceof LexerNode)) {
4711
+ const itemChild = itemChildren[0];
4712
+ if (!getDefinedNameName(this._currentUnitId, itemChild) && !this._getTableNameFromStructuredRef(itemChild, getTable) && !isReferenceString(itemChild)) continue;
4713
+ }
4714
+ if (curNodeType === 8) {
4715
+ const refNode = itemChildren[0];
4716
+ if (refNode instanceof LexerNode) {
4717
+ if (isReferenceString(refNode.getToken().trim())) continue;
4718
+ item = refNode;
4719
+ }
4720
+ }
4721
+ const childNode = this._generateExprTree(item, hasFunction, getDefinedNameName, getTable);
4722
+ childNode && newNode.children.push(childNode);
4723
+ }
4724
+ }
4725
+ _checkColonNodeForExprTree(item) {
4726
+ const itemChildren = item.getChildren();
4727
+ if (itemChildren.length < 2) return false;
4728
+ const firstChild = itemChildren[0];
4729
+ const secondChild = itemChildren[1];
4730
+ if (!(firstChild instanceof LexerNode) || !(secondChild instanceof LexerNode)) return false;
4731
+ const firstGrandChild = firstChild.getChildren()[0];
4732
+ const secondGrandChild = secondChild.getChildren()[0];
4733
+ if (!(firstGrandChild instanceof LexerNode) || !(secondGrandChild instanceof LexerNode)) return false;
4734
+ const firstChildToken = firstGrandChild.getToken().trim();
4735
+ const secondChildToken = secondGrandChild.getToken().trim();
4736
+ if (isReferenceString(`${firstChildToken}${":"}${secondChildToken}`)) return true;
4737
+ return false;
4738
+ }
4739
+ _handleTextNodeForExprTree(item, getDefinedNameName, getTable) {
4740
+ const itemTrim = item.trim();
4741
+ if (itemTrim.startsWith("{") && itemTrim.endsWith("}") || getDefinedNameName(this._currentUnitId, itemTrim) || this._getTableNameFromStructuredRef(itemTrim, getTable) || isReferenceString(itemTrim)) return {
4742
+ value: itemTrim,
4743
+ children: [],
4744
+ startIndex: -1
4745
+ };
3485
4746
  return null;
3486
4747
  }
4748
+ _getTableNameFromStructuredRef(token, getTable) {
4749
+ const { tableName } = splitTableStructuredRef(token);
4750
+ if (getTable(this._currentUnitId, tableName)) return tableName;
4751
+ return null;
4752
+ }
4753
+ _handleLambdaForExprTree(firstChild, newNode, hasFunction, getDefinedNameName, getTable) {
4754
+ const firstGrandchildren = firstChild.getChildren();
4755
+ for (let i = 0; i < firstGrandchildren.length; i++) {
4756
+ const item = firstGrandchildren[i];
4757
+ if (!(item instanceof LexerNode)) continue;
4758
+ const itemChildren = item.getChildren();
4759
+ if (itemChildren.length === 1 && !(itemChildren[0] instanceof LexerNode)) continue;
4760
+ const childNode = this._generateExprTree(item, hasFunction, getDefinedNameName, getTable);
4761
+ childNode && newNode.children.push(childNode);
4762
+ }
4763
+ }
4764
+ _getCurNodeTypeForExprTree(lexerNode) {
4765
+ const token = lexerNode.getToken();
4766
+ const tokenTrimUpper = token.trim().toUpperCase();
4767
+ let curNodeType = 0;
4768
+ if (token === "R_1") curNodeType = 3;
4769
+ else if (token === "P_1") curNodeType = 4;
4770
+ else if (token === "L_1") curNodeType = 5;
4771
+ else if (tokenTrimUpper === "LAMBDA") curNodeType = 2;
4772
+ else if (tokenTrimUpper === "LET") curNodeType = 1;
4773
+ else if (tokenTrimUpper === ":") curNodeType = 8;
4774
+ else if (SUFFIX_TOKEN_SET.has(tokenTrimUpper)) curNodeType = 7;
4775
+ else if (tokenTrimUpper === "-") {
4776
+ if (this._checkAddBracketForMinus(lexerNode)) curNodeType = 9;
4777
+ } else curNodeType = 10;
4778
+ return curNodeType;
4779
+ }
3487
4780
  };
3488
4781
 
3489
4782
  //#endregion
@@ -3539,13 +4832,24 @@ function updateFormulaDataByCellValue(sheetFormulaDataMatrix, newSheetFormulaDat
3539
4832
  }
3540
4833
  function clearArrayFormulaCellDataByCell(arrayFormulaRangeMatrix, arrayFormulaCellDataMatrix, r, c) {
3541
4834
  const arrayFormulaRangeValue = arrayFormulaRangeMatrix === null || arrayFormulaRangeMatrix === void 0 ? void 0 : arrayFormulaRangeMatrix.getValue(r, c);
3542
- if (arrayFormulaRangeValue == null) return true;
4835
+ if (arrayFormulaRangeValue == null) {
4836
+ let changed = false;
4837
+ arrayFormulaRangeMatrix.forValue((_, __, range) => {
4838
+ if (_univerjs_core.Rectangle.contains(range, (0, _univerjs_core.cellToRange)(r, c))) {
4839
+ arrayFormulaCellDataMatrix.realDeleteValue(r, c);
4840
+ changed = true;
4841
+ return false;
4842
+ }
4843
+ });
4844
+ return changed;
4845
+ }
4846
+ const targetArrayFormulaRange = arrayFormulaRangeValue;
3543
4847
  const intersection = [];
3544
4848
  arrayFormulaRangeMatrix.forValue((rangeRow, rangeCol, range) => {
3545
4849
  if (rangeRow === r && rangeCol === c) return;
3546
- if (_univerjs_core.Rectangle.intersects(range, arrayFormulaRangeValue)) intersection.push(range);
4850
+ if (_univerjs_core.Rectangle.intersects(range, targetArrayFormulaRange)) intersection.push(range);
3547
4851
  });
3548
- const { startRow, startColumn, endRow, endColumn } = arrayFormulaRangeValue;
4852
+ const { startRow, startColumn, endRow, endColumn } = targetArrayFormulaRange;
3549
4853
  for (let row = startRow; row <= endRow; row++) for (let col = startColumn; col <= endColumn; col++) {
3550
4854
  let isOverlapping = false;
3551
4855
  const currentCell = (0, _univerjs_core.cellToRange)(row, col);
@@ -3558,6 +4862,7 @@ function clearArrayFormulaCellDataByCell(arrayFormulaRangeMatrix, arrayFormulaCe
3558
4862
  });
3559
4863
  if (!isOverlapping) arrayFormulaCellDataMatrix.realDeleteValue(row, col);
3560
4864
  }
4865
+ return true;
3561
4866
  }
3562
4867
 
3563
4868
  //#endregion
@@ -3596,7 +4901,7 @@ let FormulaDataModel = class FormulaDataModel extends _univerjs_core.Disposable
3596
4901
  const range = rangeMatrix.getValue(row, column);
3597
4902
  if (range == null) return true;
3598
4903
  const { startRow, startColumn, endRow, endColumn } = range;
3599
- for (let r = startRow; r <= endRow; r++) for (let c = startColumn; c <= endColumn; c++) arrayFormulaCellMatrixData.setValue(r, c, null);
4904
+ for (let r = startRow; r <= endRow; r++) for (let c = startColumn; c <= endColumn; c++) arrayFormulaCellMatrixData.realDeleteValue(r, c);
3600
4905
  rangeMatrix.realDeleteValue(row, column);
3601
4906
  });
3602
4907
  if (this._arrayFormulaCellData[unitId]) this._arrayFormulaCellData[unitId][sheetId] = arrayFormulaCellMatrixData.getData();
@@ -3621,10 +4926,11 @@ let FormulaDataModel = class FormulaDataModel extends _univerjs_core.Disposable
3621
4926
  const arrayFormulaRange = arrayFormulaRangeMatrix === null || arrayFormulaRangeMatrix === void 0 ? void 0 : arrayFormulaRangeMatrix.getValue(row, column);
3622
4927
  if (arrayFormulaRange == null) return true;
3623
4928
  const { startRow, startColumn, endRow, endColumn } = arrayFormulaRange;
3624
- for (let r = startRow; r <= endRow; r++) for (let c = startColumn; c <= endColumn; c++) arrayFormulaCellMatrixData.setValue(r, c, null);
4929
+ for (let r = startRow; r <= endRow; r++) for (let c = startColumn; c <= endColumn; c++) arrayFormulaCellMatrixData.realDeleteValue(r, c);
3625
4930
  });
3626
4931
  cellMatrixData.forValue((row, column, cellData) => {
3627
- arrayFormulaCellMatrixData.setValue(row, column, cellData);
4932
+ if (cellData == null) arrayFormulaCellMatrixData.realDeleteValue(row, column);
4933
+ else arrayFormulaCellMatrixData.setValue(row, column, cellData);
3628
4934
  });
3629
4935
  if (this._arrayFormulaCellData[unitId]) this._arrayFormulaCellData[unitId][sheetId] = arrayFormulaCellMatrixData.getData();
3630
4936
  });
@@ -3850,23 +5156,34 @@ let FormulaDataModel = class FormulaDataModel extends _univerjs_core.Disposable
3850
5156
  updateArrayFormulaRange(unitId, sheetId, cellValue) {
3851
5157
  var _this$_arrayFormulaRa5;
3852
5158
  const arrayFormulaRange = (_this$_arrayFormulaRa5 = this._arrayFormulaRange[unitId]) === null || _this$_arrayFormulaRa5 === void 0 ? void 0 : _this$_arrayFormulaRa5[sheetId];
3853
- if (!arrayFormulaRange) return;
5159
+ if (!arrayFormulaRange) return false;
3854
5160
  const arrayFormulaRangeMatrix = new _univerjs_core.ObjectMatrix(arrayFormulaRange);
3855
- new _univerjs_core.ObjectMatrix(cellValue).forValue((r, c, cell) => {
3856
- arrayFormulaRangeMatrix.realDeleteValue(r, c);
5161
+ const cellMatrix = new _univerjs_core.ObjectMatrix(cellValue);
5162
+ let changed = false;
5163
+ cellMatrix.forValue((r, c) => {
5164
+ if (arrayFormulaRangeMatrix.getValue(r, c) != null) {
5165
+ arrayFormulaRangeMatrix.realDeleteValue(r, c);
5166
+ changed = true;
5167
+ }
3857
5168
  });
5169
+ if (changed && this._arrayFormulaRange[unitId]) this._arrayFormulaRange[unitId][sheetId] = arrayFormulaRangeMatrix.getData();
5170
+ return changed;
3858
5171
  }
3859
5172
  updateArrayFormulaCellData(unitId, sheetId, cellValue) {
3860
5173
  var _this$_arrayFormulaRa6, _this$_arrayFormulaCe4;
3861
5174
  const arrayFormulaRange = (_this$_arrayFormulaRa6 = this._arrayFormulaRange[unitId]) === null || _this$_arrayFormulaRa6 === void 0 ? void 0 : _this$_arrayFormulaRa6[sheetId];
3862
- if (!arrayFormulaRange) return;
5175
+ if (!arrayFormulaRange) return false;
3863
5176
  const arrayFormulaRangeMatrix = new _univerjs_core.ObjectMatrix(arrayFormulaRange);
3864
5177
  const arrayFormulaCellData = (_this$_arrayFormulaCe4 = this._arrayFormulaCellData[unitId]) === null || _this$_arrayFormulaCe4 === void 0 ? void 0 : _this$_arrayFormulaCe4[sheetId];
3865
- if (!arrayFormulaCellData) return;
5178
+ if (!arrayFormulaCellData) return false;
3866
5179
  const arrayFormulaCellDataMatrix = new _univerjs_core.ObjectMatrix(arrayFormulaCellData);
3867
- new _univerjs_core.ObjectMatrix(cellValue).forValue((r, c, cell) => {
3868
- clearArrayFormulaCellDataByCell(arrayFormulaRangeMatrix, arrayFormulaCellDataMatrix, r, c);
5180
+ const cellMatrix = new _univerjs_core.ObjectMatrix(cellValue);
5181
+ let changed = false;
5182
+ cellMatrix.forValue((r, c) => {
5183
+ changed = clearArrayFormulaCellDataByCell(arrayFormulaRangeMatrix, arrayFormulaCellDataMatrix, r, c) || changed;
3869
5184
  });
5185
+ if (changed && this._arrayFormulaCellData[unitId]) this._arrayFormulaCellData[unitId][sheetId] = arrayFormulaCellDataMatrix.getData();
5186
+ return changed;
3870
5187
  }
3871
5188
  updateImageFormulaData(unitId, sheetId, cellValue) {
3872
5189
  var _this$_unitImageFormu;
@@ -3924,7 +5241,7 @@ let FormulaDataModel = class FormulaDataModel extends _univerjs_core.Disposable
3924
5241
  const column = Number(columnStr);
3925
5242
  const currentCell = sheetInstance.getCellRaw(row, column);
3926
5243
  const isFormula = (0, _univerjs_core.isFormulaString)(currentCell === null || currentCell === void 0 ? void 0 : currentCell.f) || (0, _univerjs_core.isFormulaId)(currentCell === null || currentCell === void 0 ? void 0 : currentCell.si);
3927
- const noValue = (currentCell === null || currentCell === void 0 ? void 0 : currentCell.v) === void 0 || (currentCell === null || currentCell === void 0 ? void 0 : currentCell.v) === null || (currentCell === null || currentCell === void 0 ? void 0 : currentCell.v) === "";
5244
+ const noValue = (currentCell === null || currentCell === void 0 ? void 0 : currentCell.v) === void 0 || (currentCell === null || currentCell === void 0 ? void 0 : currentCell.v) === null || (currentCell === null || currentCell === void 0 ? void 0 : currentCell.v) === "" || (currentCell === null || currentCell === void 0 ? void 0 : currentCell.v) === 0 || (currentCell === null || currentCell === void 0 ? void 0 : currentCell.v) === "0";
3928
5245
  if (!(isFormula && noValue)) continue;
3929
5246
  if (!columnRanges[column]) columnRanges[column] = [];
3930
5247
  const lastRange = columnRanges[column].slice(-1)[0];
@@ -4023,181 +5340,6 @@ function initSheetFormulaData(formulaData, unitId, sheetId, cellMatrix) {
4023
5340
  return { [unitId]: { [sheetId]: newSheetFormulaData } };
4024
5341
  }
4025
5342
 
4026
- //#endregion
4027
- //#region src/basics/inverted-index-cache.ts
4028
- const DEFAULT_EMPTY_CELL_KEY = Symbol("EMPTY_CELL");
4029
- const normalizedValueMap = /* @__PURE__ */ new Map();
4030
- function normalizeValue(value) {
4031
- if (normalizedValueMap.has(value)) return normalizedValueMap.get(value);
4032
- let _value;
4033
- if (value === null || value === void 0 || value === "") _value = DEFAULT_EMPTY_CELL_KEY;
4034
- else if ((0, _univerjs_core.isRealNum)(value) && Number(value).toString() === value.toString()) _value = Number(value) === 0 ? 0 : Number(value);
4035
- else if (typeof value === "string") _value = value.toLowerCase();
4036
- else _value = value;
4037
- normalizedValueMap.set(value, _value);
4038
- return _value;
4039
- }
4040
- var InvertedIndexCache = class {
4041
- constructor() {
4042
- _defineProperty(this, "_cache", /* @__PURE__ */ new Map());
4043
- _defineProperty(this, "_continueBuildingCache", /* @__PURE__ */ new Map());
4044
- }
4045
- set(unitId, sheetId, column, value, row, isForceUpdate = false) {
4046
- if (!this.shouldContinueBuildingCache(unitId, sheetId, column, row) && !isForceUpdate) return;
4047
- let unitMap = this._cache.get(unitId);
4048
- if (unitMap == null) {
4049
- unitMap = /* @__PURE__ */ new Map();
4050
- this._cache.set(unitId, unitMap);
4051
- }
4052
- let sheetMap = unitMap.get(sheetId);
4053
- if (sheetMap == null) {
4054
- sheetMap = /* @__PURE__ */ new Map();
4055
- unitMap.set(sheetId, sheetMap);
4056
- }
4057
- let columnMap = sheetMap.get(column);
4058
- if (columnMap == null) {
4059
- columnMap = /* @__PURE__ */ new Map();
4060
- sheetMap.set(column, columnMap);
4061
- }
4062
- if (isForceUpdate) {
4063
- for (const [_, _cellList] of columnMap) if (_cellList.has(row)) {
4064
- _cellList.delete(row);
4065
- break;
4066
- }
4067
- }
4068
- const _value = normalizeValue(value);
4069
- let cellList = columnMap.get(_value);
4070
- if (cellList == null) {
4071
- cellList = /* @__PURE__ */ new Set();
4072
- columnMap.set(_value, cellList);
4073
- }
4074
- cellList.add(row);
4075
- }
4076
- getCellValuePositions(unitId, sheetId, column) {
4077
- var _this$_cache$get;
4078
- return (_this$_cache$get = this._cache.get(unitId)) === null || _this$_cache$get === void 0 || (_this$_cache$get = _this$_cache$get.get(sheetId)) === null || _this$_cache$get === void 0 ? void 0 : _this$_cache$get.get(column);
4079
- }
4080
- getCellPositions(unitId, sheetId, column, value, rowsInCache) {
4081
- var _this$_cache$get2;
4082
- const columnMap = (_this$_cache$get2 = this._cache.get(unitId)) === null || _this$_cache$get2 === void 0 || (_this$_cache$get2 = _this$_cache$get2.get(sheetId)) === null || _this$_cache$get2 === void 0 ? void 0 : _this$_cache$get2.get(column);
4083
- if (!columnMap) return;
4084
- const result = {
4085
- errorType: null,
4086
- matchingRows: []
4087
- };
4088
- const _value = normalizeValue(value);
4089
- if (ERROR_TYPE_SET.has(_value)) result.errorType = _value;
4090
- else if (_value === 0 || _value === DEFAULT_EMPTY_CELL_KEY) {
4091
- const rows = [];
4092
- const rowsForZero = columnMap.get(0);
4093
- if (rowsForZero) rows.push(...rowsForZero);
4094
- const rowsForEmpty = columnMap.get(DEFAULT_EMPTY_CELL_KEY);
4095
- if (rowsForEmpty) rows.push(...rowsForEmpty);
4096
- result.matchingRows = rows.filter((row) => rowsInCache.some(([start, end]) => row >= start && row <= end));
4097
- } else {
4098
- var _columnMap$get;
4099
- result.matchingRows = Array.from((_columnMap$get = columnMap.get(_value)) !== null && _columnMap$get !== void 0 ? _columnMap$get : []).filter((row) => rowsInCache.some(([start, end]) => row >= start && row <= end));
4100
- }
4101
- return result;
4102
- }
4103
- setContinueBuildingCache(unitId, sheetId, column, startRow, endRow) {
4104
- if (column === -1 || startRow === -1 || endRow === -1) return;
4105
- let unitMap = this._continueBuildingCache.get(unitId);
4106
- if (unitMap == null) {
4107
- unitMap = /* @__PURE__ */ new Map();
4108
- this._continueBuildingCache.set(unitId, unitMap);
4109
- }
4110
- let sheetMap = unitMap.get(sheetId);
4111
- if (sheetMap == null) {
4112
- sheetMap = /* @__PURE__ */ new Map();
4113
- unitMap.set(sheetId, sheetMap);
4114
- }
4115
- let columnMap = sheetMap.get(column);
4116
- if (columnMap == null) {
4117
- columnMap = new _flatten_js_interval_tree.default();
4118
- columnMap.insert([startRow, endRow]);
4119
- sheetMap.set(column, columnMap);
4120
- return;
4121
- }
4122
- this._handleNewInterval(columnMap, startRow, endRow);
4123
- }
4124
- shouldContinueBuildingCache(unitId, sheetId, column, row) {
4125
- var _this$_continueBuildi;
4126
- if (column === -1 || row === -1) return false;
4127
- const columnMap = (_this$_continueBuildi = this._continueBuildingCache.get(unitId)) === null || _this$_continueBuildi === void 0 || (_this$_continueBuildi = _this$_continueBuildi.get(sheetId)) === null || _this$_continueBuildi === void 0 ? void 0 : _this$_continueBuildi.get(column);
4128
- if (!columnMap) return true;
4129
- return columnMap.search([row, row]).length === 0;
4130
- }
4131
- canUseCache(unitId, sheetId, column, rangeStartRow, rangeEndRow) {
4132
- var _this$_continueBuildi2;
4133
- const columnMap = (_this$_continueBuildi2 = this._continueBuildingCache.get(unitId)) === null || _this$_continueBuildi2 === void 0 || (_this$_continueBuildi2 = _this$_continueBuildi2.get(sheetId)) === null || _this$_continueBuildi2 === void 0 ? void 0 : _this$_continueBuildi2.get(column);
4134
- if (column === -1 || rangeStartRow === -1 || rangeEndRow === -1 || !columnMap) return {
4135
- rowsInCache: [],
4136
- rowsNotInCache: []
4137
- };
4138
- const result = columnMap.search([rangeStartRow, rangeEndRow]);
4139
- if (result.length === 0) return {
4140
- rowsInCache: [],
4141
- rowsNotInCache: []
4142
- };
4143
- result.sort((a, b) => a[0] - b[0]);
4144
- const rowsInCache = [];
4145
- const rowsNotInCache = [];
4146
- let _rangeStartRow = rangeStartRow;
4147
- for (let i = 0; i < result.length; i++) {
4148
- const [start, end] = result[i];
4149
- if (_rangeStartRow >= start) {
4150
- if (rangeEndRow <= end) {
4151
- rowsInCache.push([_rangeStartRow, rangeEndRow]);
4152
- break;
4153
- }
4154
- rowsInCache.push([_rangeStartRow, end]);
4155
- _rangeStartRow = end + 1;
4156
- if (i === result.length - 1 && _rangeStartRow <= rangeEndRow) rowsNotInCache.push([_rangeStartRow, rangeEndRow]);
4157
- } else {
4158
- if (rangeEndRow > end) {
4159
- rowsInCache.push([start, end]);
4160
- rowsNotInCache.push([_rangeStartRow, start - 1]);
4161
- _rangeStartRow = end + 1;
4162
- if (i === result.length - 1 && _rangeStartRow <= rangeEndRow) rowsNotInCache.push([_rangeStartRow, rangeEndRow]);
4163
- continue;
4164
- }
4165
- rowsInCache.push([start, rangeEndRow]);
4166
- rowsNotInCache.push([_rangeStartRow, start - 1]);
4167
- }
4168
- }
4169
- return {
4170
- rowsInCache,
4171
- rowsNotInCache
4172
- };
4173
- }
4174
- clear() {
4175
- this._cache.clear();
4176
- this._continueBuildingCache.clear();
4177
- normalizedValueMap.clear();
4178
- }
4179
- _handleNewInterval(columnMap, startRow, endRow) {
4180
- let result = columnMap.search([startRow, endRow]);
4181
- if (result.length === 0) {
4182
- const adjacentRange = [startRow - 1 < 0 ? 0 : startRow - 1, endRow + 1];
4183
- result = columnMap.search(adjacentRange);
4184
- if (result.length === 0) {
4185
- columnMap.insert([startRow, endRow]);
4186
- return;
4187
- }
4188
- }
4189
- let min = startRow;
4190
- let max = endRow;
4191
- for (const interval of result) {
4192
- min = Math.min(min, interval[0]);
4193
- max = Math.max(max, interval[1]);
4194
- columnMap.remove(interval);
4195
- }
4196
- columnMap.insert([min, max]);
4197
- }
4198
- };
4199
- const CELL_INVERTED_INDEX_CACHE = new InvertedIndexCache();
4200
-
4201
5343
  //#endregion
4202
5344
  //#region src/services/sheet-row-filtered.service.ts
4203
5345
  /**
@@ -8386,7 +9528,10 @@ let FormulaRuntimeService = class FormulaRuntimeService extends _univerjs_core.D
8386
9528
  endColumn: endColumn - startColumn + column
8387
9529
  };
8388
9530
  arrayData.setValue(row, column, arrayRange);
8389
- if (this._checkIfArrayFormulaRangeHasData(unitId, sheetId, row, column, arrayRange) || this._checkIfArrayFormulaExceeded(rowCount, columnCount, arrayRange)) {
9531
+ const hasDataInArrayFormulaRange = this._checkIfArrayFormulaRangeHasData(unitId, sheetId, row, column, arrayRange);
9532
+ const isArrayFormulaExceeded = this._checkIfArrayFormulaExceeded(rowCount, columnCount, arrayRange);
9533
+ if (hasDataInArrayFormulaRange || isArrayFormulaExceeded) {
9534
+ var _this$_currentConfigS;
8390
9535
  const errorObject = this._getValueObjectOfRuntimeData(ErrorValueObject.create("#SPILL!"));
8391
9536
  sheetData.setValue(row, column, errorObject);
8392
9537
  clearArrayUnitData.setValue(row, column, errorObject);
@@ -8396,17 +9541,21 @@ let FormulaRuntimeService = class FormulaRuntimeService extends _univerjs_core.D
8396
9541
  * In this case, you need to clear the previous range data to prevent other formulas from referencing the old values.
8397
9542
  */
8398
9543
  const unitData = this._currentConfigService.getUnitData();
9544
+ const arrayData = this._currentConfigService.getArrayFormulaCellData();
9545
+ const previousArrayFormulaRange = (_this$_currentConfigS = this._currentConfigService.getArrayFormulaRange()[unitId]) === null || _this$_currentConfigS === void 0 || (_this$_currentConfigS = _this$_currentConfigS[sheetId]) === null || _this$_currentConfigS === void 0 || (_this$_currentConfigS = _this$_currentConfigS[row]) === null || _this$_currentConfigS === void 0 ? void 0 : _this$_currentConfigS[column];
8399
9546
  objectValueRefOrArray.iterator((_, rowIndex, columnIndex) => {
8400
- var _unitData$unitId;
9547
+ var _unitData$unitId, _arrayData$unitId;
8401
9548
  const currentRow = rowIndex - startRow + row;
8402
9549
  const currentColumn = columnIndex - startColumn + column;
8403
9550
  const cell = (_unitData$unitId = unitData[unitId]) === null || _unitData$unitId === void 0 || (_unitData$unitId = _unitData$unitId[sheetId]) === null || _unitData$unitId === void 0 ? void 0 : _unitData$unitId.cellData.getValue(currentRow, currentColumn);
9551
+ const arrayDataCell = arrayData === null || arrayData === void 0 || (_arrayData$unitId = arrayData[unitId]) === null || _arrayData$unitId === void 0 || (_arrayData$unitId = _arrayData$unitId[sheetId]) === null || _arrayData$unitId === void 0 ? void 0 : _arrayData$unitId.getValue(currentRow, currentColumn);
9552
+ const shouldClearPreviousCellOfCurrentArrayFormula = this._arrayCellHasData(arrayDataCell) && this._isInArrayFormulaRange(previousArrayFormulaRange, currentRow, currentColumn) && (cell == null || this._isSameCellValue(cell, arrayDataCell));
8404
9553
  if (rowIndex === startRow && columnIndex === startColumn) runtimeArrayUnitData.setValue(row, column, errorObject);
9554
+ else if (shouldClearPreviousCellOfCurrentArrayFormula) sheetData.setValue(currentRow, currentColumn, null);
8405
9555
  else if (cell != null) {
8406
9556
  if (cell.v == null) cell.v = "";
8407
- runtimeArrayUnitData.setValue(currentRow, currentColumn, cell);
9557
+ sheetData.setValue(currentRow, currentColumn, { ...cell });
8408
9558
  } else if (this._isInOtherArrayFormulaRange(unitId, sheetId, row, column, currentRow, currentColumn)) return true;
8409
- else runtimeArrayUnitData.setValue(currentRow, currentColumn, { v: "" });
8410
9559
  });
8411
9560
  } else {
8412
9561
  const spillError = ErrorValueObject.create("#SPILL!");
@@ -8519,954 +9668,282 @@ let FormulaRuntimeService = class FormulaRuntimeService extends _univerjs_core.D
8519
9668
  getRuntimeState() {
8520
9669
  return {
8521
9670
  totalFormulasToCalculate: this.getTotalFormulasToCalculate(),
8522
- completedFormulasCount: this.getCompletedFormulasCount(),
8523
- totalArrayFormulasToCalculate: this.getTotalArrayFormulasToCalculate(),
8524
- completedArrayFormulasCount: this.getCompletedArrayFormulasCount(),
8525
- stage: this.getFormulaExecuteStage(),
8526
- formulaCycleIndex: this.getFormulaCycleIndex()
8527
- };
8528
- }
8529
- clearArrayObjectCache() {
8530
- FORMULA_REF_TO_ARRAY_CACHE.clear();
8531
- }
8532
- _checkIfArrayFormulaRangeHasData(formulaUnitId, formulaSheetId, formulaRow, formulaColumn, arrayRange) {
8533
- var _this$_unitArrayFormu;
8534
- const { startRow, startColumn, endRow, endColumn } = arrayRange;
8535
- const unitData = this._currentConfigService.getUnitData();
8536
- const arrayData = this._currentConfigService.getArrayFormulaCellData();
8537
- (_this$_unitArrayFormu = this._unitArrayFormulaRange[formulaUnitId]) === null || _this$_unitArrayFormu === void 0 || (_this$_unitArrayFormu = _this$_unitArrayFormu[formulaSheetId]) === null || _this$_unitArrayFormu === void 0 || (_this$_unitArrayFormu = _this$_unitArrayFormu[formulaRow]) === null || _this$_unitArrayFormu === void 0 || _this$_unitArrayFormu[formulaColumn];
8538
- for (let r = startRow; r <= endRow; r++) for (let c = startColumn; c <= endColumn; c++) {
8539
- var _this$_runtimeData, _arrayData$formulaUni, _unitData$formulaUnit;
8540
- if (r === formulaRow && formulaColumn === c) continue;
8541
- const cell = (_this$_runtimeData = this._runtimeData) === null || _this$_runtimeData === void 0 || (_this$_runtimeData = _this$_runtimeData[formulaUnitId]) === null || _this$_runtimeData === void 0 || (_this$_runtimeData = _this$_runtimeData[formulaSheetId]) === null || _this$_runtimeData === void 0 ? void 0 : _this$_runtimeData.getValue(r, c);
8542
- arrayData === null || arrayData === void 0 || (_arrayData$formulaUni = arrayData[formulaUnitId]) === null || _arrayData$formulaUni === void 0 || (_arrayData$formulaUni = _arrayData$formulaUni[formulaSheetId]) === null || _arrayData$formulaUni === void 0 || _arrayData$formulaUni.getValue(r, c);
8543
- const currentCell = unitData === null || unitData === void 0 || (_unitData$formulaUnit = unitData[formulaUnitId]) === null || _unitData$formulaUnit === void 0 || (_unitData$formulaUnit = _unitData$formulaUnit[formulaSheetId]) === null || _unitData$formulaUnit === void 0 || (_unitData$formulaUnit = _unitData$formulaUnit.cellData) === null || _unitData$formulaUnit === void 0 ? void 0 : _unitData$formulaUnit.getValue(r, c);
8544
- const featureCell = this._getRuntimeFeatureCellValue(r, c, formulaSheetId, formulaUnitId);
8545
- if (!isNullCellForFormula(cell) || this._isInOtherArrayFormulaRange(formulaUnitId, formulaSheetId, formulaRow, formulaColumn, r, c) || !isNullCellForFormula(currentCell) || !isNullCellForFormula(featureCell)) return true;
8546
- }
8547
- return false;
8548
- }
8549
- _getRuntimeFeatureCellValue(row, column, sheetId, unitId) {
8550
- return getRuntimeFeatureCell(row, column, sheetId, unitId, this._runtimeFeatureCellData);
8551
- }
8552
- _arrayCellHasData(cell) {
8553
- if (cell === null || cell === void 0) return false;
8554
- if (cell.v !== void 0) return true;
8555
- return false;
8556
- }
8557
- /**
8558
- * If the current array formula in the extended area intersects with the existing array formula, a #SPILL! error will be reported. Note that if other array formulas are already #SPILL!, they will not conflict with the current array formula
8559
- * @param formulaUnitId
8560
- * @param formulaSheetId
8561
- * @param formulaRow
8562
- * @param formulaColumn
8563
- * @param r
8564
- * @param c
8565
- * @returns
8566
- */
8567
- _isInOtherArrayFormulaRange(formulaUnitId, formulaSheetId, formulaRow, formulaColumn, r, c) {
8568
- var _this$_currentConfigS;
8569
- const arrayFormulaRange = (_this$_currentConfigS = this._currentConfigService.getArrayFormulaRange()[formulaUnitId]) === null || _this$_currentConfigS === void 0 ? void 0 : _this$_currentConfigS[formulaSheetId];
8570
- if (arrayFormulaRange == null) return false;
8571
- let isCellOverlapping = false;
8572
- new _univerjs_core.ObjectMatrix(arrayFormulaRange).forValue((rangeRow, rangeCol, range) => {
8573
- var _this$_runtimeData$fo;
8574
- if (rangeRow === formulaRow && rangeCol === formulaColumn) return;
8575
- const isOverlapping = this._isInArrayFormulaRange(range, r, c);
8576
- const cell = (_this$_runtimeData$fo = this._runtimeData[formulaUnitId]) === null || _this$_runtimeData$fo === void 0 || (_this$_runtimeData$fo = _this$_runtimeData$fo[formulaSheetId]) === null || _this$_runtimeData$fo === void 0 ? void 0 : _this$_runtimeData$fo.getValue(rangeRow, rangeCol);
8577
- if (isOverlapping && (cell === null || cell === void 0 ? void 0 : cell.v) !== "#SPILL!") isCellOverlapping = true;
8578
- });
8579
- return isCellOverlapping;
8580
- }
8581
- _isInArrayFormulaRange(range, r, c) {
8582
- if (range == null) return false;
8583
- const { startRow, startColumn, endRow, endColumn } = range;
8584
- if (r >= startRow && r <= endRow && c >= startColumn && c <= endColumn) return true;
8585
- return false;
8586
- }
8587
- _checkIfArrayFormulaExceeded(rowCount, columnCount, arrayRange) {
8588
- if (arrayRange.endRow >= rowCount || arrayRange.endColumn >= columnCount) return true;
8589
- return false;
8590
- }
8591
- _isInDirtyRange(unitId, sheetId, row, column) {
8592
- const dirtyRanges = this._currentConfigService.getDirtyRanges();
8593
- if (dirtyRanges.length === 0) return true;
8594
- return isInDirtyRange(dirtyRanges, unitId, sheetId, row, column);
8595
- }
8596
- };
8597
- FormulaRuntimeService = __decorate([__decorateParam(0, IFormulaCurrentConfigService), __decorateParam(1, IHyperlinkEngineFormulaService)], FormulaRuntimeService);
8598
- const IFormulaRuntimeService = (0, _univerjs_core.createIdentifier)("univer.formula.runtime.service");
8599
-
8600
- //#endregion
8601
- //#region src/engine/ast-node/node-type.ts
8602
- const NODE_ORDER_MAP = new Map([
8603
- [1, 7],
8604
- [2, 9],
8605
- [3, 8],
8606
- [4, 6],
8607
- [5, 1],
8608
- [6, 2],
8609
- [9, 10],
8610
- [10, 3],
8611
- [11, 4],
8612
- [12, 5]
8613
- ]);
8614
-
8615
- //#endregion
8616
- //#region src/engine/ast-node/base-ast-node.ts
8617
- var BaseAstNode = class {
8618
- constructor(_token) {
8619
- this._token = _token;
8620
- _defineProperty(this, "_children", []);
8621
- _defineProperty(this, "_definedNames", void 0);
8622
- _defineProperty(this, "_parent", void 0);
8623
- _defineProperty(this, "_valueObject", void 0);
8624
- _defineProperty(this, "_calculateState", false);
8625
- _defineProperty(this, "_async", false);
8626
- _defineProperty(this, "_address", false);
8627
- _defineProperty(this, "_isForcedCalculateFunction", false);
8628
- }
8629
- dispose() {
8630
- var _this$_valueObject;
8631
- this._children.forEach((node) => {
8632
- node.dispose();
8633
- });
8634
- (_this$_valueObject = this._valueObject) === null || _this$_valueObject === void 0 || _this$_valueObject.dispose();
8635
- this._valueObject = null;
8636
- this._children = [];
8637
- this._definedNames = null;
8638
- this._parent = null;
8639
- }
8640
- get nodeType() {
8641
- return 8;
8642
- }
8643
- resetCalculationState() {
8644
- this._children.forEach((node) => {
8645
- node.resetCalculationState();
8646
- });
8647
- this._valueObject = null;
8648
- this._calculateState = false;
8649
- }
8650
- isAsync() {
8651
- return this._async;
8652
- }
8653
- isAddress() {
8654
- return this._address;
8655
- }
8656
- isForcedCalculateFunction() {
8657
- return this._isForcedCalculateFunction;
8658
- }
8659
- setAsync() {
8660
- this._async = true;
8661
- }
8662
- setAddress() {
8663
- this._address = true;
8664
- }
8665
- getParent() {
8666
- return this._parent;
8667
- }
8668
- setParent(node) {
8669
- this._parent = node;
8670
- node.addChildren(this);
8671
- }
8672
- setForcedCalculateFunction() {
8673
- this._isForcedCalculateFunction = true;
8674
- }
8675
- getChildren() {
8676
- return this._children;
8677
- }
8678
- addChildren(...astNode) {
8679
- this._children.push(...astNode);
8680
- }
8681
- getToken() {
8682
- return this._token;
8683
- }
8684
- setValue(value) {
8685
- this._valueObject = value;
8686
- }
8687
- getValue() {
8688
- return this._valueObject;
8689
- }
8690
- isCalculated() {
8691
- return this._calculateState;
8692
- }
8693
- setCalculated() {
8694
- this._calculateState = true;
8695
- }
8696
- execute() {}
8697
- setNotEmpty(state = true) {}
8698
- async executeAsync() {
8699
- return Promise.resolve(0);
8700
- }
8701
- serialize() {
8702
- const token = this.getToken();
8703
- const children = this.getChildren();
8704
- const childrenSerialization = [];
8705
- const childrenCount = children.length;
8706
- for (let i = 0; i < childrenCount; i++) {
8707
- const item = children[i];
8708
- childrenSerialization.push(item.serialize());
8709
- }
8710
- const result = {
8711
- token,
8712
- nodeType: this.nodeType
8713
- };
8714
- if (childrenCount > 0) result.children = childrenSerialization;
8715
- return result;
8716
- }
8717
- hasDefinedName(definedName) {
8718
- var _this$_definedNames;
8719
- return ((_this$_definedNames = this._definedNames) === null || _this$_definedNames === void 0 ? void 0 : _this$_definedNames.includes(definedName)) || false;
8720
- }
8721
- setDefinedNames(definedNames) {
8722
- this._definedNames = definedNames;
8723
- }
8724
- getDefinedNames() {
8725
- return this._definedNames;
8726
- }
8727
- };
8728
- var ErrorNode = class ErrorNode extends BaseAstNode {
8729
- constructor(errorType) {
8730
- super(errorType);
8731
- _defineProperty(this, "_errorValueObject", void 0);
8732
- this._errorValueObject = ErrorValueObject.create(errorType);
8733
- }
8734
- get nodeType() {
8735
- return 7;
8736
- }
8737
- static create(errorType) {
8738
- return new ErrorNode(errorType);
8739
- }
8740
- getValue() {
8741
- return this._errorValueObject;
8742
- }
8743
- };
8744
-
8745
- //#endregion
8746
- //#region src/engine/ast-node/base-ast-node-factory.ts
8747
- var BaseAstNodeFactory = class {
8748
- get zIndex() {
8749
- return 0;
8750
- }
8751
- dispose() {}
8752
- create(param, currentRow, currentColumn) {
8753
- let token;
8754
- if (param instanceof LexerNode) token = param.getToken();
8755
- else token = param;
8756
- return new BaseAstNode(token);
9671
+ completedFormulasCount: this.getCompletedFormulasCount(),
9672
+ totalArrayFormulasToCalculate: this.getTotalArrayFormulasToCalculate(),
9673
+ completedArrayFormulasCount: this.getCompletedArrayFormulasCount(),
9674
+ stage: this.getFormulaExecuteStage(),
9675
+ formulaCycleIndex: this.getFormulaCycleIndex()
9676
+ };
8757
9677
  }
8758
- };
8759
-
8760
- //#endregion
8761
- //#region src/engine/ast-node/ast-root-node.ts
8762
- var AstRootNode = class extends BaseAstNode {
8763
- get nodeType() {
8764
- return 9;
9678
+ clearArrayObjectCache() {
9679
+ FORMULA_REF_TO_ARRAY_CACHE.clear();
8765
9680
  }
8766
- execute() {
8767
- const children = this.getChildren();
8768
- if (children.length > 1) {
8769
- this.setValue(ErrorValueObject.create("#VALUE!"));
8770
- return;
9681
+ _checkIfArrayFormulaRangeHasData(formulaUnitId, formulaSheetId, formulaRow, formulaColumn, arrayRange) {
9682
+ var _this$_currentConfigS2;
9683
+ const { startRow, startColumn, endRow, endColumn } = arrayRange;
9684
+ const unitData = this._currentConfigService.getUnitData();
9685
+ const arrayData = this._currentConfigService.getArrayFormulaCellData();
9686
+ const previousArrayFormulaRange = (_this$_currentConfigS2 = this._currentConfigService.getArrayFormulaRange()[formulaUnitId]) === null || _this$_currentConfigS2 === void 0 || (_this$_currentConfigS2 = _this$_currentConfigS2[formulaSheetId]) === null || _this$_currentConfigS2 === void 0 || (_this$_currentConfigS2 = _this$_currentConfigS2[formulaRow]) === null || _this$_currentConfigS2 === void 0 ? void 0 : _this$_currentConfigS2[formulaColumn];
9687
+ for (let r = startRow; r <= endRow; r++) for (let c = startColumn; c <= endColumn; c++) {
9688
+ var _this$_runtimeData, _arrayData$formulaUni, _unitData$formulaUnit;
9689
+ if (r === formulaRow && formulaColumn === c) continue;
9690
+ const cell = (_this$_runtimeData = this._runtimeData) === null || _this$_runtimeData === void 0 || (_this$_runtimeData = _this$_runtimeData[formulaUnitId]) === null || _this$_runtimeData === void 0 || (_this$_runtimeData = _this$_runtimeData[formulaSheetId]) === null || _this$_runtimeData === void 0 ? void 0 : _this$_runtimeData.getValue(r, c);
9691
+ const arrayDataCell = arrayData === null || arrayData === void 0 || (_arrayData$formulaUni = arrayData[formulaUnitId]) === null || _arrayData$formulaUni === void 0 || (_arrayData$formulaUni = _arrayData$formulaUni[formulaSheetId]) === null || _arrayData$formulaUni === void 0 ? void 0 : _arrayData$formulaUni.getValue(r, c);
9692
+ const currentCell = unitData === null || unitData === void 0 || (_unitData$formulaUnit = unitData[formulaUnitId]) === null || _unitData$formulaUnit === void 0 || (_unitData$formulaUnit = _unitData$formulaUnit[formulaSheetId]) === null || _unitData$formulaUnit === void 0 || (_unitData$formulaUnit = _unitData$formulaUnit.cellData) === null || _unitData$formulaUnit === void 0 ? void 0 : _unitData$formulaUnit.getValue(r, c);
9693
+ const featureCell = this._getRuntimeFeatureCellValue(r, c, formulaSheetId, formulaUnitId);
9694
+ const isPreviousCellOfCurrentArrayFormula = this._arrayCellHasData(arrayDataCell) && this._isInArrayFormulaRange(previousArrayFormulaRange, r, c) && (currentCell == null || this._isSameCellValue(currentCell, arrayDataCell));
9695
+ const hasRuntimeCell = !isNullCellForFormula(cell);
9696
+ const isInOtherArrayFormulaRange = this._isInOtherArrayFormulaRange(formulaUnitId, formulaSheetId, formulaRow, formulaColumn, r, c);
9697
+ const currentCellBlocks = !isNullCellForFormula(currentCell) && !isPreviousCellOfCurrentArrayFormula;
9698
+ const featureCellBlocks = !isNullCellForFormula(featureCell);
9699
+ if (hasRuntimeCell || isInOtherArrayFormulaRange || currentCellBlocks || featureCellBlocks) return true;
8771
9700
  }
8772
- const node = children[0];
8773
- if (node == null)
8774
- /**
8775
- * fix: https://github.com/dream-num/univer/issues/1415
8776
- */
8777
- this.setValue(ErrorValueObject.create("#VALUE!"));
8778
- else this.setValue(node.getValue());
9701
+ return false;
8779
9702
  }
8780
- };
8781
- var AstRootNodeFactory = class extends BaseAstNodeFactory {
8782
- get zIndex() {
8783
- return NODE_ORDER_MAP.get(9) || 100;
9703
+ _getRuntimeFeatureCellValue(row, column, sheetId, unitId) {
9704
+ return getRuntimeFeatureCell(row, column, sheetId, unitId, this._runtimeFeatureCellData);
8784
9705
  }
8785
- checkAndCreateNodeType(param) {
8786
- if (!(param instanceof LexerNode)) return;
8787
- if (param.getToken() === "R_1") return new AstRootNode("R_1");
9706
+ _arrayCellHasData(cell) {
9707
+ if (cell === null || cell === void 0) return false;
9708
+ if (cell.v !== void 0) return true;
9709
+ return false;
8788
9710
  }
8789
- };
8790
-
8791
- //#endregion
8792
- //#region src/functions/date/function-names.ts
8793
- /**
8794
- * Copyright 2023-present DreamNum Co., Ltd.
8795
- *
8796
- * Licensed under the Apache License, Version 2.0 (the "License");
8797
- * you may not use this file except in compliance with the License.
8798
- * You may obtain a copy of the License at
8799
- *
8800
- * http://www.apache.org/licenses/LICENSE-2.0
8801
- *
8802
- * Unless required by applicable law or agreed to in writing, software
8803
- * distributed under the License is distributed on an "AS IS" BASIS,
8804
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8805
- * See the License for the specific language governing permissions and
8806
- * limitations under the License.
8807
- */
8808
- let FUNCTION_NAMES_DATE = /* @__PURE__ */ function(FUNCTION_NAMES_DATE) {
8809
- FUNCTION_NAMES_DATE["DATE"] = "DATE";
8810
- FUNCTION_NAMES_DATE["DATEDIF"] = "DATEDIF";
8811
- FUNCTION_NAMES_DATE["DATEVALUE"] = "DATEVALUE";
8812
- FUNCTION_NAMES_DATE["DAY"] = "DAY";
8813
- FUNCTION_NAMES_DATE["DAYS"] = "DAYS";
8814
- FUNCTION_NAMES_DATE["DAYS360"] = "DAYS360";
8815
- FUNCTION_NAMES_DATE["EDATE"] = "EDATE";
8816
- FUNCTION_NAMES_DATE["EOMONTH"] = "EOMONTH";
8817
- FUNCTION_NAMES_DATE["EPOCHTODATE"] = "EPOCHTODATE";
8818
- FUNCTION_NAMES_DATE["HOUR"] = "HOUR";
8819
- FUNCTION_NAMES_DATE["ISOWEEKNUM"] = "ISOWEEKNUM";
8820
- FUNCTION_NAMES_DATE["MINUTE"] = "MINUTE";
8821
- FUNCTION_NAMES_DATE["MONTH"] = "MONTH";
8822
- FUNCTION_NAMES_DATE["NETWORKDAYS"] = "NETWORKDAYS";
8823
- FUNCTION_NAMES_DATE["NETWORKDAYS_INTL"] = "NETWORKDAYS.INTL";
8824
- FUNCTION_NAMES_DATE["NOW"] = "NOW";
8825
- FUNCTION_NAMES_DATE["SECOND"] = "SECOND";
8826
- FUNCTION_NAMES_DATE["TIME"] = "TIME";
8827
- FUNCTION_NAMES_DATE["TIMEVALUE"] = "TIMEVALUE";
8828
- FUNCTION_NAMES_DATE["TO_DATE"] = "TO_DATE";
8829
- FUNCTION_NAMES_DATE["TODAY"] = "TODAY";
8830
- FUNCTION_NAMES_DATE["WEEKDAY"] = "WEEKDAY";
8831
- FUNCTION_NAMES_DATE["WEEKNUM"] = "WEEKNUM";
8832
- FUNCTION_NAMES_DATE["WORKDAY"] = "WORKDAY";
8833
- FUNCTION_NAMES_DATE["WORKDAY_INTL"] = "WORKDAY.INTL";
8834
- FUNCTION_NAMES_DATE["YEAR"] = "YEAR";
8835
- FUNCTION_NAMES_DATE["YEARFRAC"] = "YEARFRAC";
8836
- return FUNCTION_NAMES_DATE;
8837
- }({});
8838
-
8839
- //#endregion
8840
- //#region src/functions/engineering/function-names.ts
8841
- /**
8842
- * Copyright 2023-present DreamNum Co., Ltd.
8843
- *
8844
- * Licensed under the Apache License, Version 2.0 (the "License");
8845
- * you may not use this file except in compliance with the License.
8846
- * You may obtain a copy of the License at
8847
- *
8848
- * http://www.apache.org/licenses/LICENSE-2.0
8849
- *
8850
- * Unless required by applicable law or agreed to in writing, software
8851
- * distributed under the License is distributed on an "AS IS" BASIS,
8852
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8853
- * See the License for the specific language governing permissions and
8854
- * limitations under the License.
8855
- */
8856
- let FUNCTION_NAMES_ENGINEERING = /* @__PURE__ */ function(FUNCTION_NAMES_ENGINEERING) {
8857
- FUNCTION_NAMES_ENGINEERING["BESSELI"] = "BESSELI";
8858
- FUNCTION_NAMES_ENGINEERING["BESSELJ"] = "BESSELJ";
8859
- FUNCTION_NAMES_ENGINEERING["BESSELK"] = "BESSELK";
8860
- FUNCTION_NAMES_ENGINEERING["BESSELY"] = "BESSELY";
8861
- FUNCTION_NAMES_ENGINEERING["BIN2DEC"] = "BIN2DEC";
8862
- FUNCTION_NAMES_ENGINEERING["BIN2HEX"] = "BIN2HEX";
8863
- FUNCTION_NAMES_ENGINEERING["BIN2OCT"] = "BIN2OCT";
8864
- FUNCTION_NAMES_ENGINEERING["BITAND"] = "BITAND";
8865
- FUNCTION_NAMES_ENGINEERING["BITLSHIFT"] = "BITLSHIFT";
8866
- FUNCTION_NAMES_ENGINEERING["BITOR"] = "BITOR";
8867
- FUNCTION_NAMES_ENGINEERING["BITRSHIFT"] = "BITRSHIFT";
8868
- FUNCTION_NAMES_ENGINEERING["BITXOR"] = "BITXOR";
8869
- FUNCTION_NAMES_ENGINEERING["COMPLEX"] = "COMPLEX";
8870
- FUNCTION_NAMES_ENGINEERING["CONVERT"] = "CONVERT";
8871
- FUNCTION_NAMES_ENGINEERING["DEC2BIN"] = "DEC2BIN";
8872
- FUNCTION_NAMES_ENGINEERING["DEC2HEX"] = "DEC2HEX";
8873
- FUNCTION_NAMES_ENGINEERING["DEC2OCT"] = "DEC2OCT";
8874
- FUNCTION_NAMES_ENGINEERING["DELTA"] = "DELTA";
8875
- FUNCTION_NAMES_ENGINEERING["ERF"] = "ERF";
8876
- FUNCTION_NAMES_ENGINEERING["ERF_PRECISE"] = "ERF.PRECISE";
8877
- FUNCTION_NAMES_ENGINEERING["ERFC"] = "ERFC";
8878
- FUNCTION_NAMES_ENGINEERING["ERFC_PRECISE"] = "ERFC.PRECISE";
8879
- FUNCTION_NAMES_ENGINEERING["GESTEP"] = "GESTEP";
8880
- FUNCTION_NAMES_ENGINEERING["HEX2BIN"] = "HEX2BIN";
8881
- FUNCTION_NAMES_ENGINEERING["HEX2DEC"] = "HEX2DEC";
8882
- FUNCTION_NAMES_ENGINEERING["HEX2OCT"] = "HEX2OCT";
8883
- FUNCTION_NAMES_ENGINEERING["IMABS"] = "IMABS";
8884
- FUNCTION_NAMES_ENGINEERING["IMAGINARY"] = "IMAGINARY";
8885
- FUNCTION_NAMES_ENGINEERING["IMARGUMENT"] = "IMARGUMENT";
8886
- FUNCTION_NAMES_ENGINEERING["IMCONJUGATE"] = "IMCONJUGATE";
8887
- FUNCTION_NAMES_ENGINEERING["IMCOS"] = "IMCOS";
8888
- FUNCTION_NAMES_ENGINEERING["IMCOSH"] = "IMCOSH";
8889
- FUNCTION_NAMES_ENGINEERING["IMCOT"] = "IMCOT";
8890
- FUNCTION_NAMES_ENGINEERING["IMCOTH"] = "IMCOTH";
8891
- FUNCTION_NAMES_ENGINEERING["IMCSC"] = "IMCSC";
8892
- FUNCTION_NAMES_ENGINEERING["IMCSCH"] = "IMCSCH";
8893
- FUNCTION_NAMES_ENGINEERING["IMDIV"] = "IMDIV";
8894
- FUNCTION_NAMES_ENGINEERING["IMEXP"] = "IMEXP";
8895
- FUNCTION_NAMES_ENGINEERING["IMLN"] = "IMLN";
8896
- FUNCTION_NAMES_ENGINEERING["IMLOG"] = "IMLOG";
8897
- FUNCTION_NAMES_ENGINEERING["IMLOG10"] = "IMLOG10";
8898
- FUNCTION_NAMES_ENGINEERING["IMLOG2"] = "IMLOG2";
8899
- FUNCTION_NAMES_ENGINEERING["IMPOWER"] = "IMPOWER";
8900
- FUNCTION_NAMES_ENGINEERING["IMPRODUCT"] = "IMPRODUCT";
8901
- FUNCTION_NAMES_ENGINEERING["IMREAL"] = "IMREAL";
8902
- FUNCTION_NAMES_ENGINEERING["IMSEC"] = "IMSEC";
8903
- FUNCTION_NAMES_ENGINEERING["IMSECH"] = "IMSECH";
8904
- FUNCTION_NAMES_ENGINEERING["IMSIN"] = "IMSIN";
8905
- FUNCTION_NAMES_ENGINEERING["IMSINH"] = "IMSINH";
8906
- FUNCTION_NAMES_ENGINEERING["IMSQRT"] = "IMSQRT";
8907
- FUNCTION_NAMES_ENGINEERING["IMSUB"] = "IMSUB";
8908
- FUNCTION_NAMES_ENGINEERING["IMSUM"] = "IMSUM";
8909
- FUNCTION_NAMES_ENGINEERING["IMTAN"] = "IMTAN";
8910
- FUNCTION_NAMES_ENGINEERING["IMTANH"] = "IMTANH";
8911
- FUNCTION_NAMES_ENGINEERING["OCT2BIN"] = "OCT2BIN";
8912
- FUNCTION_NAMES_ENGINEERING["OCT2DEC"] = "OCT2DEC";
8913
- FUNCTION_NAMES_ENGINEERING["OCT2HEX"] = "OCT2HEX";
8914
- return FUNCTION_NAMES_ENGINEERING;
8915
- }({});
8916
-
8917
- //#endregion
8918
- //#region src/functions/financial/function-names.ts
8919
- /**
8920
- * Copyright 2023-present DreamNum Co., Ltd.
8921
- *
8922
- * Licensed under the Apache License, Version 2.0 (the "License");
8923
- * you may not use this file except in compliance with the License.
8924
- * You may obtain a copy of the License at
8925
- *
8926
- * http://www.apache.org/licenses/LICENSE-2.0
8927
- *
8928
- * Unless required by applicable law or agreed to in writing, software
8929
- * distributed under the License is distributed on an "AS IS" BASIS,
8930
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8931
- * See the License for the specific language governing permissions and
8932
- * limitations under the License.
8933
- */
8934
- let FUNCTION_NAMES_FINANCIAL = /* @__PURE__ */ function(FUNCTION_NAMES_FINANCIAL) {
8935
- FUNCTION_NAMES_FINANCIAL["ACCRINT"] = "ACCRINT";
8936
- FUNCTION_NAMES_FINANCIAL["ACCRINTM"] = "ACCRINTM";
8937
- FUNCTION_NAMES_FINANCIAL["AMORDEGRC"] = "AMORDEGRC";
8938
- FUNCTION_NAMES_FINANCIAL["AMORLINC"] = "AMORLINC";
8939
- FUNCTION_NAMES_FINANCIAL["COUPDAYBS"] = "COUPDAYBS";
8940
- FUNCTION_NAMES_FINANCIAL["COUPDAYS"] = "COUPDAYS";
8941
- FUNCTION_NAMES_FINANCIAL["COUPDAYSNC"] = "COUPDAYSNC";
8942
- FUNCTION_NAMES_FINANCIAL["COUPNCD"] = "COUPNCD";
8943
- FUNCTION_NAMES_FINANCIAL["COUPNUM"] = "COUPNUM";
8944
- FUNCTION_NAMES_FINANCIAL["COUPPCD"] = "COUPPCD";
8945
- FUNCTION_NAMES_FINANCIAL["CUMIPMT"] = "CUMIPMT";
8946
- FUNCTION_NAMES_FINANCIAL["CUMPRINC"] = "CUMPRINC";
8947
- FUNCTION_NAMES_FINANCIAL["DB"] = "DB";
8948
- FUNCTION_NAMES_FINANCIAL["DDB"] = "DDB";
8949
- FUNCTION_NAMES_FINANCIAL["DISC"] = "DISC";
8950
- FUNCTION_NAMES_FINANCIAL["DOLLARDE"] = "DOLLARDE";
8951
- FUNCTION_NAMES_FINANCIAL["DOLLARFR"] = "DOLLARFR";
8952
- FUNCTION_NAMES_FINANCIAL["DURATION"] = "DURATION";
8953
- FUNCTION_NAMES_FINANCIAL["EFFECT"] = "EFFECT";
8954
- FUNCTION_NAMES_FINANCIAL["FV"] = "FV";
8955
- FUNCTION_NAMES_FINANCIAL["FVSCHEDULE"] = "FVSCHEDULE";
8956
- FUNCTION_NAMES_FINANCIAL["INTRATE"] = "INTRATE";
8957
- FUNCTION_NAMES_FINANCIAL["IPMT"] = "IPMT";
8958
- FUNCTION_NAMES_FINANCIAL["IRR"] = "IRR";
8959
- FUNCTION_NAMES_FINANCIAL["ISPMT"] = "ISPMT";
8960
- FUNCTION_NAMES_FINANCIAL["MDURATION"] = "MDURATION";
8961
- FUNCTION_NAMES_FINANCIAL["MIRR"] = "MIRR";
8962
- FUNCTION_NAMES_FINANCIAL["NOMINAL"] = "NOMINAL";
8963
- FUNCTION_NAMES_FINANCIAL["NPER"] = "NPER";
8964
- FUNCTION_NAMES_FINANCIAL["NPV"] = "NPV";
8965
- FUNCTION_NAMES_FINANCIAL["ODDFPRICE"] = "ODDFPRICE";
8966
- FUNCTION_NAMES_FINANCIAL["ODDFYIELD"] = "ODDFYIELD";
8967
- FUNCTION_NAMES_FINANCIAL["ODDLPRICE"] = "ODDLPRICE";
8968
- FUNCTION_NAMES_FINANCIAL["ODDLYIELD"] = "ODDLYIELD";
8969
- FUNCTION_NAMES_FINANCIAL["PDURATION"] = "PDURATION";
8970
- FUNCTION_NAMES_FINANCIAL["PMT"] = "PMT";
8971
- FUNCTION_NAMES_FINANCIAL["PPMT"] = "PPMT";
8972
- FUNCTION_NAMES_FINANCIAL["PRICE"] = "PRICE";
8973
- FUNCTION_NAMES_FINANCIAL["PRICEDISC"] = "PRICEDISC";
8974
- FUNCTION_NAMES_FINANCIAL["PRICEMAT"] = "PRICEMAT";
8975
- FUNCTION_NAMES_FINANCIAL["PV"] = "PV";
8976
- FUNCTION_NAMES_FINANCIAL["RATE"] = "RATE";
8977
- FUNCTION_NAMES_FINANCIAL["RECEIVED"] = "RECEIVED";
8978
- FUNCTION_NAMES_FINANCIAL["RRI"] = "RRI";
8979
- FUNCTION_NAMES_FINANCIAL["SLN"] = "SLN";
8980
- FUNCTION_NAMES_FINANCIAL["SYD"] = "SYD";
8981
- FUNCTION_NAMES_FINANCIAL["TBILLEQ"] = "TBILLEQ";
8982
- FUNCTION_NAMES_FINANCIAL["TBILLPRICE"] = "TBILLPRICE";
8983
- FUNCTION_NAMES_FINANCIAL["TBILLYIELD"] = "TBILLYIELD";
8984
- FUNCTION_NAMES_FINANCIAL["VDB"] = "VDB";
8985
- FUNCTION_NAMES_FINANCIAL["XIRR"] = "XIRR";
8986
- FUNCTION_NAMES_FINANCIAL["XNPV"] = "XNPV";
8987
- FUNCTION_NAMES_FINANCIAL["YIELD"] = "YIELD";
8988
- FUNCTION_NAMES_FINANCIAL["YIELDDISC"] = "YIELDDISC";
8989
- FUNCTION_NAMES_FINANCIAL["YIELDMAT"] = "YIELDMAT";
8990
- return FUNCTION_NAMES_FINANCIAL;
8991
- }({});
8992
-
8993
- //#endregion
8994
- //#region src/functions/information/function-names.ts
8995
- /**
8996
- * Copyright 2023-present DreamNum Co., Ltd.
8997
- *
8998
- * Licensed under the Apache License, Version 2.0 (the "License");
8999
- * you may not use this file except in compliance with the License.
9000
- * You may obtain a copy of the License at
9001
- *
9002
- * http://www.apache.org/licenses/LICENSE-2.0
9003
- *
9004
- * Unless required by applicable law or agreed to in writing, software
9005
- * distributed under the License is distributed on an "AS IS" BASIS,
9006
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9007
- * See the License for the specific language governing permissions and
9008
- * limitations under the License.
9009
- */
9010
- let FUNCTION_NAMES_INFORMATION = /* @__PURE__ */ function(FUNCTION_NAMES_INFORMATION) {
9011
- FUNCTION_NAMES_INFORMATION["CELL"] = "CELL";
9012
- FUNCTION_NAMES_INFORMATION["ERROR_TYPE"] = "ERROR.TYPE";
9013
- FUNCTION_NAMES_INFORMATION["INFO"] = "INFO";
9014
- FUNCTION_NAMES_INFORMATION["ISBETWEEN"] = "ISBETWEEN";
9015
- FUNCTION_NAMES_INFORMATION["ISBLANK"] = "ISBLANK";
9016
- FUNCTION_NAMES_INFORMATION["ISDATE"] = "ISDATE";
9017
- FUNCTION_NAMES_INFORMATION["ISEMAIL"] = "ISEMAIL";
9018
- FUNCTION_NAMES_INFORMATION["ISERR"] = "ISERR";
9019
- FUNCTION_NAMES_INFORMATION["ISERROR"] = "ISERROR";
9020
- FUNCTION_NAMES_INFORMATION["ISEVEN"] = "ISEVEN";
9021
- FUNCTION_NAMES_INFORMATION["ISFORMULA"] = "ISFORMULA";
9022
- FUNCTION_NAMES_INFORMATION["ISLOGICAL"] = "ISLOGICAL";
9023
- FUNCTION_NAMES_INFORMATION["ISNA"] = "ISNA";
9024
- FUNCTION_NAMES_INFORMATION["ISNONTEXT"] = "ISNONTEXT";
9025
- FUNCTION_NAMES_INFORMATION["ISNUMBER"] = "ISNUMBER";
9026
- FUNCTION_NAMES_INFORMATION["ISODD"] = "ISODD";
9027
- FUNCTION_NAMES_INFORMATION["ISOMITTED"] = "ISOMITTED";
9028
- FUNCTION_NAMES_INFORMATION["ISREF"] = "ISREF";
9029
- FUNCTION_NAMES_INFORMATION["ISTEXT"] = "ISTEXT";
9030
- FUNCTION_NAMES_INFORMATION["ISURL"] = "ISURL";
9031
- FUNCTION_NAMES_INFORMATION["N"] = "N";
9032
- FUNCTION_NAMES_INFORMATION["NA"] = "NA";
9033
- FUNCTION_NAMES_INFORMATION["SHEET"] = "SHEET";
9034
- FUNCTION_NAMES_INFORMATION["SHEETS"] = "SHEETS";
9035
- FUNCTION_NAMES_INFORMATION["TYPE"] = "TYPE";
9036
- return FUNCTION_NAMES_INFORMATION;
9037
- }({});
9038
-
9039
- //#endregion
9040
- //#region src/functions/logical/function-names.ts
9041
- /**
9042
- * Copyright 2023-present DreamNum Co., Ltd.
9043
- *
9044
- * Licensed under the Apache License, Version 2.0 (the "License");
9045
- * you may not use this file except in compliance with the License.
9046
- * You may obtain a copy of the License at
9047
- *
9048
- * http://www.apache.org/licenses/LICENSE-2.0
9049
- *
9050
- * Unless required by applicable law or agreed to in writing, software
9051
- * distributed under the License is distributed on an "AS IS" BASIS,
9052
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9053
- * See the License for the specific language governing permissions and
9054
- * limitations under the License.
9055
- */
9056
- let FUNCTION_NAMES_LOGICAL = /* @__PURE__ */ function(FUNCTION_NAMES_LOGICAL) {
9057
- FUNCTION_NAMES_LOGICAL["AND"] = "AND";
9058
- FUNCTION_NAMES_LOGICAL["BYCOL"] = "BYCOL";
9059
- FUNCTION_NAMES_LOGICAL["BYROW"] = "BYROW";
9060
- FUNCTION_NAMES_LOGICAL["FALSE"] = "FALSE";
9061
- FUNCTION_NAMES_LOGICAL["IF"] = "IF";
9062
- FUNCTION_NAMES_LOGICAL["IFERROR"] = "IFERROR";
9063
- FUNCTION_NAMES_LOGICAL["IFNA"] = "IFNA";
9064
- FUNCTION_NAMES_LOGICAL["IFS"] = "IFS";
9065
- FUNCTION_NAMES_LOGICAL["LAMBDA"] = "LAMBDA";
9066
- FUNCTION_NAMES_LOGICAL["LET"] = "LET";
9067
- FUNCTION_NAMES_LOGICAL["MAKEARRAY"] = "MAKEARRAY";
9068
- FUNCTION_NAMES_LOGICAL["MAP"] = "MAP";
9069
- FUNCTION_NAMES_LOGICAL["NOT"] = "NOT";
9070
- FUNCTION_NAMES_LOGICAL["OR"] = "OR";
9071
- FUNCTION_NAMES_LOGICAL["REDUCE"] = "REDUCE";
9072
- FUNCTION_NAMES_LOGICAL["SCAN"] = "SCAN";
9073
- FUNCTION_NAMES_LOGICAL["SWITCH"] = "SWITCH";
9074
- FUNCTION_NAMES_LOGICAL["TRUE"] = "TRUE";
9075
- FUNCTION_NAMES_LOGICAL["XOR"] = "XOR";
9076
- return FUNCTION_NAMES_LOGICAL;
9077
- }({});
9078
-
9079
- //#endregion
9080
- //#region src/functions/lookup/function-names.ts
9081
- /**
9082
- * Copyright 2023-present DreamNum Co., Ltd.
9083
- *
9084
- * Licensed under the Apache License, Version 2.0 (the "License");
9085
- * you may not use this file except in compliance with the License.
9086
- * You may obtain a copy of the License at
9087
- *
9088
- * http://www.apache.org/licenses/LICENSE-2.0
9089
- *
9090
- * Unless required by applicable law or agreed to in writing, software
9091
- * distributed under the License is distributed on an "AS IS" BASIS,
9092
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9093
- * See the License for the specific language governing permissions and
9094
- * limitations under the License.
9095
- */
9096
- let FUNCTION_NAMES_LOOKUP = /* @__PURE__ */ function(FUNCTION_NAMES_LOOKUP) {
9097
- FUNCTION_NAMES_LOOKUP["ADDRESS"] = "ADDRESS";
9098
- FUNCTION_NAMES_LOOKUP["AREAS"] = "AREAS";
9099
- FUNCTION_NAMES_LOOKUP["CHOOSE"] = "CHOOSE";
9100
- FUNCTION_NAMES_LOOKUP["CHOOSECOLS"] = "CHOOSECOLS";
9101
- FUNCTION_NAMES_LOOKUP["CHOOSEROWS"] = "CHOOSEROWS";
9102
- FUNCTION_NAMES_LOOKUP["COLUMN"] = "COLUMN";
9103
- FUNCTION_NAMES_LOOKUP["COLUMNS"] = "COLUMNS";
9104
- FUNCTION_NAMES_LOOKUP["DROP"] = "DROP";
9105
- FUNCTION_NAMES_LOOKUP["EXPAND"] = "EXPAND";
9106
- FUNCTION_NAMES_LOOKUP["FILTER"] = "FILTER";
9107
- FUNCTION_NAMES_LOOKUP["FORMULATEXT"] = "FORMULATEXT";
9108
- FUNCTION_NAMES_LOOKUP["GETPIVOTDATA"] = "GETPIVOTDATA";
9109
- FUNCTION_NAMES_LOOKUP["HLOOKUP"] = "HLOOKUP";
9110
- FUNCTION_NAMES_LOOKUP["HSTACK"] = "HSTACK";
9111
- FUNCTION_NAMES_LOOKUP["HYPERLINK"] = "HYPERLINK";
9112
- FUNCTION_NAMES_LOOKUP["IMAGE"] = "IMAGE";
9113
- FUNCTION_NAMES_LOOKUP["INDEX"] = "INDEX";
9114
- FUNCTION_NAMES_LOOKUP["INDIRECT"] = "INDIRECT";
9115
- FUNCTION_NAMES_LOOKUP["LOOKUP"] = "LOOKUP";
9116
- FUNCTION_NAMES_LOOKUP["MATCH"] = "MATCH";
9117
- FUNCTION_NAMES_LOOKUP["OFFSET"] = "OFFSET";
9118
- FUNCTION_NAMES_LOOKUP["ROW"] = "ROW";
9119
- FUNCTION_NAMES_LOOKUP["ROWS"] = "ROWS";
9120
- FUNCTION_NAMES_LOOKUP["RTD"] = "RTD";
9121
- FUNCTION_NAMES_LOOKUP["SORT"] = "SORT";
9122
- FUNCTION_NAMES_LOOKUP["SORTBY"] = "SORTBY";
9123
- FUNCTION_NAMES_LOOKUP["TAKE"] = "TAKE";
9124
- FUNCTION_NAMES_LOOKUP["TOCOL"] = "TOCOL";
9125
- FUNCTION_NAMES_LOOKUP["TOROW"] = "TOROW";
9126
- FUNCTION_NAMES_LOOKUP["TRANSPOSE"] = "TRANSPOSE";
9127
- FUNCTION_NAMES_LOOKUP["UNIQUE"] = "UNIQUE";
9128
- FUNCTION_NAMES_LOOKUP["VLOOKUP"] = "VLOOKUP";
9129
- FUNCTION_NAMES_LOOKUP["VSTACK"] = "VSTACK";
9130
- FUNCTION_NAMES_LOOKUP["WRAPCOLS"] = "WRAPCOLS";
9131
- FUNCTION_NAMES_LOOKUP["WRAPROWS"] = "WRAPROWS";
9132
- FUNCTION_NAMES_LOOKUP["XLOOKUP"] = "XLOOKUP";
9133
- FUNCTION_NAMES_LOOKUP["XMATCH"] = "XMATCH";
9134
- return FUNCTION_NAMES_LOOKUP;
9135
- }({});
9136
-
9137
- //#endregion
9138
- //#region src/functions/math/function-names.ts
9139
- /**
9140
- * Copyright 2023-present DreamNum Co., Ltd.
9141
- *
9142
- * Licensed under the Apache License, Version 2.0 (the "License");
9143
- * you may not use this file except in compliance with the License.
9144
- * You may obtain a copy of the License at
9145
- *
9146
- * http://www.apache.org/licenses/LICENSE-2.0
9147
- *
9148
- * Unless required by applicable law or agreed to in writing, software
9149
- * distributed under the License is distributed on an "AS IS" BASIS,
9150
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9151
- * See the License for the specific language governing permissions and
9152
- * limitations under the License.
9153
- */
9154
- let FUNCTION_NAMES_MATH = /* @__PURE__ */ function(FUNCTION_NAMES_MATH) {
9155
- FUNCTION_NAMES_MATH["ABS"] = "ABS";
9156
- FUNCTION_NAMES_MATH["ACOS"] = "ACOS";
9157
- FUNCTION_NAMES_MATH["ACOSH"] = "ACOSH";
9158
- FUNCTION_NAMES_MATH["ACOT"] = "ACOT";
9159
- FUNCTION_NAMES_MATH["ACOTH"] = "ACOTH";
9160
- FUNCTION_NAMES_MATH["AGGREGATE"] = "AGGREGATE";
9161
- FUNCTION_NAMES_MATH["ARABIC"] = "ARABIC";
9162
- FUNCTION_NAMES_MATH["ASIN"] = "ASIN";
9163
- FUNCTION_NAMES_MATH["ASINH"] = "ASINH";
9164
- FUNCTION_NAMES_MATH["ATAN"] = "ATAN";
9165
- FUNCTION_NAMES_MATH["ATAN2"] = "ATAN2";
9166
- FUNCTION_NAMES_MATH["ATANH"] = "ATANH";
9167
- FUNCTION_NAMES_MATH["BASE"] = "BASE";
9168
- FUNCTION_NAMES_MATH["CEILING"] = "CEILING";
9169
- FUNCTION_NAMES_MATH["CEILING_MATH"] = "CEILING.MATH";
9170
- FUNCTION_NAMES_MATH["CEILING_PRECISE"] = "CEILING.PRECISE";
9171
- FUNCTION_NAMES_MATH["COMBIN"] = "COMBIN";
9172
- FUNCTION_NAMES_MATH["COMBINA"] = "COMBINA";
9173
- FUNCTION_NAMES_MATH["COS"] = "COS";
9174
- FUNCTION_NAMES_MATH["COSH"] = "COSH";
9175
- FUNCTION_NAMES_MATH["COT"] = "COT";
9176
- FUNCTION_NAMES_MATH["COTH"] = "COTH";
9177
- FUNCTION_NAMES_MATH["CSC"] = "CSC";
9178
- FUNCTION_NAMES_MATH["CSCH"] = "CSCH";
9179
- FUNCTION_NAMES_MATH["DECIMAL"] = "DECIMAL";
9180
- FUNCTION_NAMES_MATH["DEGREES"] = "DEGREES";
9181
- FUNCTION_NAMES_MATH["EVEN"] = "EVEN";
9182
- FUNCTION_NAMES_MATH["EXP"] = "EXP";
9183
- FUNCTION_NAMES_MATH["FACT"] = "FACT";
9184
- FUNCTION_NAMES_MATH["FACTDOUBLE"] = "FACTDOUBLE";
9185
- FUNCTION_NAMES_MATH["FLOOR"] = "FLOOR";
9186
- FUNCTION_NAMES_MATH["FLOOR_MATH"] = "FLOOR.MATH";
9187
- FUNCTION_NAMES_MATH["FLOOR_PRECISE"] = "FLOOR.PRECISE";
9188
- FUNCTION_NAMES_MATH["GCD"] = "GCD";
9189
- FUNCTION_NAMES_MATH["INT"] = "INT";
9190
- FUNCTION_NAMES_MATH["ISO_CEILING"] = "ISO.CEILING";
9191
- FUNCTION_NAMES_MATH["LCM"] = "LCM";
9192
- FUNCTION_NAMES_MATH["LET"] = "LET";
9193
- FUNCTION_NAMES_MATH["LN"] = "LN";
9194
- FUNCTION_NAMES_MATH["LOG"] = "LOG";
9195
- FUNCTION_NAMES_MATH["LOG10"] = "LOG10";
9196
- FUNCTION_NAMES_MATH["MDETERM"] = "MDETERM";
9197
- FUNCTION_NAMES_MATH["MINVERSE"] = "MINVERSE";
9198
- FUNCTION_NAMES_MATH["MMULT"] = "MMULT";
9199
- FUNCTION_NAMES_MATH["MOD"] = "MOD";
9200
- FUNCTION_NAMES_MATH["MROUND"] = "MROUND";
9201
- FUNCTION_NAMES_MATH["MULTINOMIAL"] = "MULTINOMIAL";
9202
- FUNCTION_NAMES_MATH["MUNIT"] = "MUNIT";
9203
- FUNCTION_NAMES_MATH["ODD"] = "ODD";
9204
- FUNCTION_NAMES_MATH["PI"] = "PI";
9205
- FUNCTION_NAMES_MATH["POWER"] = "POWER";
9206
- FUNCTION_NAMES_MATH["PRODUCT"] = "PRODUCT";
9207
- FUNCTION_NAMES_MATH["QUOTIENT"] = "QUOTIENT";
9208
- FUNCTION_NAMES_MATH["RADIANS"] = "RADIANS";
9209
- FUNCTION_NAMES_MATH["RAND"] = "RAND";
9210
- FUNCTION_NAMES_MATH["RANDARRAY"] = "RANDARRAY";
9211
- FUNCTION_NAMES_MATH["RANDBETWEEN"] = "RANDBETWEEN";
9212
- FUNCTION_NAMES_MATH["ROMAN"] = "ROMAN";
9213
- FUNCTION_NAMES_MATH["ROUND"] = "ROUND";
9214
- FUNCTION_NAMES_MATH["ROUNDBANK"] = "ROUNDBANK";
9215
- FUNCTION_NAMES_MATH["ROUNDDOWN"] = "ROUNDDOWN";
9216
- FUNCTION_NAMES_MATH["ROUNDUP"] = "ROUNDUP";
9217
- FUNCTION_NAMES_MATH["SEC"] = "SEC";
9218
- FUNCTION_NAMES_MATH["SECH"] = "SECH";
9219
- FUNCTION_NAMES_MATH["SERIESSUM"] = "SERIESSUM";
9220
- FUNCTION_NAMES_MATH["SEQUENCE"] = "SEQUENCE";
9221
- FUNCTION_NAMES_MATH["SIGN"] = "SIGN";
9222
- FUNCTION_NAMES_MATH["SIN"] = "SIN";
9223
- FUNCTION_NAMES_MATH["SINH"] = "SINH";
9224
- FUNCTION_NAMES_MATH["SQRT"] = "SQRT";
9225
- FUNCTION_NAMES_MATH["SQRTPI"] = "SQRTPI";
9226
- FUNCTION_NAMES_MATH["SUBTOTAL"] = "SUBTOTAL";
9227
- FUNCTION_NAMES_MATH["SUM"] = "SUM";
9228
- FUNCTION_NAMES_MATH["SUMIF"] = "SUMIF";
9229
- FUNCTION_NAMES_MATH["SUMIFS"] = "SUMIFS";
9230
- FUNCTION_NAMES_MATH["SUMPRODUCT"] = "SUMPRODUCT";
9231
- FUNCTION_NAMES_MATH["SUMSQ"] = "SUMSQ";
9232
- FUNCTION_NAMES_MATH["SUMX2MY2"] = "SUMX2MY2";
9233
- FUNCTION_NAMES_MATH["SUMX2PY2"] = "SUMX2PY2";
9234
- FUNCTION_NAMES_MATH["SUMXMY2"] = "SUMXMY2";
9235
- FUNCTION_NAMES_MATH["TAN"] = "TAN";
9236
- FUNCTION_NAMES_MATH["TANH"] = "TANH";
9237
- FUNCTION_NAMES_MATH["TRUNC"] = "TRUNC";
9238
- return FUNCTION_NAMES_MATH;
9239
- }({});
9711
+ /**
9712
+ * If the current array formula in the extended area intersects with the existing array formula, a #SPILL! error will be reported. Note that if other array formulas are already #SPILL!, they will not conflict with the current array formula
9713
+ * @param formulaUnitId
9714
+ * @param formulaSheetId
9715
+ * @param formulaRow
9716
+ * @param formulaColumn
9717
+ * @param r
9718
+ * @param c
9719
+ * @returns
9720
+ */
9721
+ _isInOtherArrayFormulaRange(formulaUnitId, formulaSheetId, formulaRow, formulaColumn, r, c) {
9722
+ var _this$_currentConfigS3;
9723
+ const arrayFormulaRange = (_this$_currentConfigS3 = this._currentConfigService.getArrayFormulaRange()[formulaUnitId]) === null || _this$_currentConfigS3 === void 0 ? void 0 : _this$_currentConfigS3[formulaSheetId];
9724
+ if (arrayFormulaRange == null) return false;
9725
+ let isCellOverlapping = false;
9726
+ new _univerjs_core.ObjectMatrix(arrayFormulaRange).forValue((rangeRow, rangeCol, range) => {
9727
+ var _this$_runtimeData$fo;
9728
+ if (rangeRow === formulaRow && rangeCol === formulaColumn) return;
9729
+ const isOverlapping = this._isInArrayFormulaRange(range, r, c);
9730
+ const cell = (_this$_runtimeData$fo = this._runtimeData[formulaUnitId]) === null || _this$_runtimeData$fo === void 0 || (_this$_runtimeData$fo = _this$_runtimeData$fo[formulaSheetId]) === null || _this$_runtimeData$fo === void 0 ? void 0 : _this$_runtimeData$fo.getValue(rangeRow, rangeCol);
9731
+ if (isOverlapping && (cell === null || cell === void 0 ? void 0 : cell.v) !== "#SPILL!") isCellOverlapping = true;
9732
+ });
9733
+ return isCellOverlapping;
9734
+ }
9735
+ _isInArrayFormulaRange(range, r, c) {
9736
+ if (range == null) return false;
9737
+ const { startRow, startColumn, endRow, endColumn } = range;
9738
+ if (r >= startRow && r <= endRow && c >= startColumn && c <= endColumn) return true;
9739
+ return false;
9740
+ }
9741
+ _isSameCellValue(cell, arrayDataCell) {
9742
+ return (cell === null || cell === void 0 ? void 0 : cell.v) === (arrayDataCell === null || arrayDataCell === void 0 ? void 0 : arrayDataCell.v) && (cell === null || cell === void 0 ? void 0 : cell.t) === (arrayDataCell === null || arrayDataCell === void 0 ? void 0 : arrayDataCell.t);
9743
+ }
9744
+ _checkIfArrayFormulaExceeded(rowCount, columnCount, arrayRange) {
9745
+ if (arrayRange.endRow >= rowCount || arrayRange.endColumn >= columnCount) return true;
9746
+ return false;
9747
+ }
9748
+ _isInDirtyRange(unitId, sheetId, row, column) {
9749
+ const dirtyRanges = this._currentConfigService.getDirtyRanges();
9750
+ if (dirtyRanges.length === 0) return true;
9751
+ return isInDirtyRange(dirtyRanges, unitId, sheetId, row, column);
9752
+ }
9753
+ };
9754
+ FormulaRuntimeService = __decorate([__decorateParam(0, IFormulaCurrentConfigService), __decorateParam(1, IHyperlinkEngineFormulaService)], FormulaRuntimeService);
9755
+ const IFormulaRuntimeService = (0, _univerjs_core.createIdentifier)("univer.formula.runtime.service");
9240
9756
 
9241
9757
  //#endregion
9242
- //#region src/functions/statistical/function-names.ts
9243
- /**
9244
- * Copyright 2023-present DreamNum Co., Ltd.
9245
- *
9246
- * Licensed under the Apache License, Version 2.0 (the "License");
9247
- * you may not use this file except in compliance with the License.
9248
- * You may obtain a copy of the License at
9249
- *
9250
- * http://www.apache.org/licenses/LICENSE-2.0
9251
- *
9252
- * Unless required by applicable law or agreed to in writing, software
9253
- * distributed under the License is distributed on an "AS IS" BASIS,
9254
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9255
- * See the License for the specific language governing permissions and
9256
- * limitations under the License.
9257
- */
9258
- let FUNCTION_NAMES_STATISTICAL = /* @__PURE__ */ function(FUNCTION_NAMES_STATISTICAL) {
9259
- FUNCTION_NAMES_STATISTICAL["AVEDEV"] = "AVEDEV";
9260
- FUNCTION_NAMES_STATISTICAL["AVERAGE"] = "AVERAGE";
9261
- FUNCTION_NAMES_STATISTICAL["AVERAGE_WEIGHTED"] = "AVERAGE.WEIGHTED";
9262
- FUNCTION_NAMES_STATISTICAL["AVERAGEA"] = "AVERAGEA";
9263
- FUNCTION_NAMES_STATISTICAL["AVERAGEIF"] = "AVERAGEIF";
9264
- FUNCTION_NAMES_STATISTICAL["AVERAGEIFS"] = "AVERAGEIFS";
9265
- FUNCTION_NAMES_STATISTICAL["BETA_DIST"] = "BETA.DIST";
9266
- FUNCTION_NAMES_STATISTICAL["BETA_INV"] = "BETA.INV";
9267
- FUNCTION_NAMES_STATISTICAL["BINOM_DIST"] = "BINOM.DIST";
9268
- FUNCTION_NAMES_STATISTICAL["BINOM_DIST_RANGE"] = "BINOM.DIST.RANGE";
9269
- FUNCTION_NAMES_STATISTICAL["BINOM_INV"] = "BINOM.INV";
9270
- FUNCTION_NAMES_STATISTICAL["CHISQ_DIST"] = "CHISQ.DIST";
9271
- FUNCTION_NAMES_STATISTICAL["CHISQ_DIST_RT"] = "CHISQ.DIST.RT";
9272
- FUNCTION_NAMES_STATISTICAL["CHISQ_INV"] = "CHISQ.INV";
9273
- FUNCTION_NAMES_STATISTICAL["CHISQ_INV_RT"] = "CHISQ.INV.RT";
9274
- FUNCTION_NAMES_STATISTICAL["CHISQ_TEST"] = "CHISQ.TEST";
9275
- FUNCTION_NAMES_STATISTICAL["CONFIDENCE_NORM"] = "CONFIDENCE.NORM";
9276
- FUNCTION_NAMES_STATISTICAL["CONFIDENCE_T"] = "CONFIDENCE.T";
9277
- FUNCTION_NAMES_STATISTICAL["CORREL"] = "CORREL";
9278
- FUNCTION_NAMES_STATISTICAL["COUNT"] = "COUNT";
9279
- FUNCTION_NAMES_STATISTICAL["COUNTA"] = "COUNTA";
9280
- FUNCTION_NAMES_STATISTICAL["COUNTBLANK"] = "COUNTBLANK";
9281
- FUNCTION_NAMES_STATISTICAL["COUNTIF"] = "COUNTIF";
9282
- FUNCTION_NAMES_STATISTICAL["COUNTIFS"] = "COUNTIFS";
9283
- FUNCTION_NAMES_STATISTICAL["COVARIANCE_P"] = "COVARIANCE.P";
9284
- FUNCTION_NAMES_STATISTICAL["COVARIANCE_S"] = "COVARIANCE.S";
9285
- FUNCTION_NAMES_STATISTICAL["DEVSQ"] = "DEVSQ";
9286
- FUNCTION_NAMES_STATISTICAL["EXPON_DIST"] = "EXPON.DIST";
9287
- FUNCTION_NAMES_STATISTICAL["F_DIST"] = "F.DIST";
9288
- FUNCTION_NAMES_STATISTICAL["F_DIST_RT"] = "F.DIST.RT";
9289
- FUNCTION_NAMES_STATISTICAL["F_INV"] = "F.INV";
9290
- FUNCTION_NAMES_STATISTICAL["F_INV_RT"] = "F.INV.RT";
9291
- FUNCTION_NAMES_STATISTICAL["F_TEST"] = "F.TEST";
9292
- FUNCTION_NAMES_STATISTICAL["FISHER"] = "FISHER";
9293
- FUNCTION_NAMES_STATISTICAL["FISHERINV"] = "FISHERINV";
9294
- FUNCTION_NAMES_STATISTICAL["FORECAST"] = "FORECAST";
9295
- FUNCTION_NAMES_STATISTICAL["FORECAST_ETS"] = "FORECAST.ETS";
9296
- FUNCTION_NAMES_STATISTICAL["FORECAST_ETS_CONFINT"] = "FORECAST.ETS.CONFINT";
9297
- FUNCTION_NAMES_STATISTICAL["FORECAST_ETS_SEASONALITY"] = "FORECAST.ETS.SEASONALITY";
9298
- FUNCTION_NAMES_STATISTICAL["FORECAST_ETS_STAT"] = "FORECAST.ETS.STAT";
9299
- FUNCTION_NAMES_STATISTICAL["FORECAST_LINEAR"] = "FORECAST.LINEAR";
9300
- FUNCTION_NAMES_STATISTICAL["FREQUENCY"] = "FREQUENCY";
9301
- FUNCTION_NAMES_STATISTICAL["GAMMA"] = "GAMMA";
9302
- FUNCTION_NAMES_STATISTICAL["GAMMA_DIST"] = "GAMMA.DIST";
9303
- FUNCTION_NAMES_STATISTICAL["GAMMA_INV"] = "GAMMA.INV";
9304
- FUNCTION_NAMES_STATISTICAL["GAMMALN"] = "GAMMALN";
9305
- FUNCTION_NAMES_STATISTICAL["GAMMALN_PRECISE"] = "GAMMALN.PRECISE";
9306
- FUNCTION_NAMES_STATISTICAL["GAUSS"] = "GAUSS";
9307
- FUNCTION_NAMES_STATISTICAL["GEOMEAN"] = "GEOMEAN";
9308
- FUNCTION_NAMES_STATISTICAL["GROWTH"] = "GROWTH";
9309
- FUNCTION_NAMES_STATISTICAL["HARMEAN"] = "HARMEAN";
9310
- FUNCTION_NAMES_STATISTICAL["HYPGEOM_DIST"] = "HYPGEOM.DIST";
9311
- FUNCTION_NAMES_STATISTICAL["INTERCEPT"] = "INTERCEPT";
9312
- FUNCTION_NAMES_STATISTICAL["KURT"] = "KURT";
9313
- FUNCTION_NAMES_STATISTICAL["LARGE"] = "LARGE";
9314
- FUNCTION_NAMES_STATISTICAL["LINEST"] = "LINEST";
9315
- FUNCTION_NAMES_STATISTICAL["LOGEST"] = "LOGEST";
9316
- FUNCTION_NAMES_STATISTICAL["LOGNORM_DIST"] = "LOGNORM.DIST";
9317
- FUNCTION_NAMES_STATISTICAL["LOGNORM_INV"] = "LOGNORM.INV";
9318
- FUNCTION_NAMES_STATISTICAL["MARGINOFERROR"] = "MARGINOFERROR";
9319
- FUNCTION_NAMES_STATISTICAL["MAX"] = "MAX";
9320
- FUNCTION_NAMES_STATISTICAL["MAXA"] = "MAXA";
9321
- FUNCTION_NAMES_STATISTICAL["MAXIFS"] = "MAXIFS";
9322
- FUNCTION_NAMES_STATISTICAL["MEDIAN"] = "MEDIAN";
9323
- FUNCTION_NAMES_STATISTICAL["MIN"] = "MIN";
9324
- FUNCTION_NAMES_STATISTICAL["MINA"] = "MINA";
9325
- FUNCTION_NAMES_STATISTICAL["MINIFS"] = "MINIFS";
9326
- FUNCTION_NAMES_STATISTICAL["MODE_MULT"] = "MODE.MULT";
9327
- FUNCTION_NAMES_STATISTICAL["MODE_SNGL"] = "MODE.SNGL";
9328
- FUNCTION_NAMES_STATISTICAL["NEGBINOM_DIST"] = "NEGBINOM.DIST";
9329
- FUNCTION_NAMES_STATISTICAL["NORM_DIST"] = "NORM.DIST";
9330
- FUNCTION_NAMES_STATISTICAL["NORM_INV"] = "NORM.INV";
9331
- FUNCTION_NAMES_STATISTICAL["NORM_S_DIST"] = "NORM.S.DIST";
9332
- FUNCTION_NAMES_STATISTICAL["NORM_S_INV"] = "NORM.S.INV";
9333
- FUNCTION_NAMES_STATISTICAL["PEARSON"] = "PEARSON";
9334
- FUNCTION_NAMES_STATISTICAL["PERCENTILE_EXC"] = "PERCENTILE.EXC";
9335
- FUNCTION_NAMES_STATISTICAL["PERCENTILE_INC"] = "PERCENTILE.INC";
9336
- FUNCTION_NAMES_STATISTICAL["PERCENTRANK_EXC"] = "PERCENTRANK.EXC";
9337
- FUNCTION_NAMES_STATISTICAL["PERCENTRANK_INC"] = "PERCENTRANK.INC";
9338
- FUNCTION_NAMES_STATISTICAL["PERMUT"] = "PERMUT";
9339
- FUNCTION_NAMES_STATISTICAL["PERMUTATIONA"] = "PERMUTATIONA";
9340
- FUNCTION_NAMES_STATISTICAL["PHI"] = "PHI";
9341
- FUNCTION_NAMES_STATISTICAL["POISSON_DIST"] = "POISSON.DIST";
9342
- FUNCTION_NAMES_STATISTICAL["PROB"] = "PROB";
9343
- FUNCTION_NAMES_STATISTICAL["QUARTILE_EXC"] = "QUARTILE.EXC";
9344
- FUNCTION_NAMES_STATISTICAL["QUARTILE_INC"] = "QUARTILE.INC";
9345
- FUNCTION_NAMES_STATISTICAL["RANK_AVG"] = "RANK.AVG";
9346
- FUNCTION_NAMES_STATISTICAL["RANK_EQ"] = "RANK.EQ";
9347
- FUNCTION_NAMES_STATISTICAL["RSQ"] = "RSQ";
9348
- FUNCTION_NAMES_STATISTICAL["SKEW"] = "SKEW";
9349
- FUNCTION_NAMES_STATISTICAL["SKEW_P"] = "SKEW.P";
9350
- FUNCTION_NAMES_STATISTICAL["SLOPE"] = "SLOPE";
9351
- FUNCTION_NAMES_STATISTICAL["SMALL"] = "SMALL";
9352
- FUNCTION_NAMES_STATISTICAL["STANDARDIZE"] = "STANDARDIZE";
9353
- FUNCTION_NAMES_STATISTICAL["STDEV_P"] = "STDEV.P";
9354
- FUNCTION_NAMES_STATISTICAL["STDEV_S"] = "STDEV.S";
9355
- FUNCTION_NAMES_STATISTICAL["STDEVA"] = "STDEVA";
9356
- FUNCTION_NAMES_STATISTICAL["STDEVPA"] = "STDEVPA";
9357
- FUNCTION_NAMES_STATISTICAL["STEYX"] = "STEYX";
9358
- FUNCTION_NAMES_STATISTICAL["T_DIST"] = "T.DIST";
9359
- FUNCTION_NAMES_STATISTICAL["T_DIST_2T"] = "T.DIST.2T";
9360
- FUNCTION_NAMES_STATISTICAL["T_DIST_RT"] = "T.DIST.RT";
9361
- FUNCTION_NAMES_STATISTICAL["T_INV"] = "T.INV";
9362
- FUNCTION_NAMES_STATISTICAL["T_INV_2T"] = "T.INV.2T";
9363
- FUNCTION_NAMES_STATISTICAL["T_TEST"] = "T.TEST";
9364
- FUNCTION_NAMES_STATISTICAL["TREND"] = "TREND";
9365
- FUNCTION_NAMES_STATISTICAL["TRIMMEAN"] = "TRIMMEAN";
9366
- FUNCTION_NAMES_STATISTICAL["VAR_P"] = "VAR.P";
9367
- FUNCTION_NAMES_STATISTICAL["VAR_S"] = "VAR.S";
9368
- FUNCTION_NAMES_STATISTICAL["VARA"] = "VARA";
9369
- FUNCTION_NAMES_STATISTICAL["VARPA"] = "VARPA";
9370
- FUNCTION_NAMES_STATISTICAL["WEIBULL_DIST"] = "WEIBULL.DIST";
9371
- FUNCTION_NAMES_STATISTICAL["Z_TEST"] = "Z.TEST";
9372
- return FUNCTION_NAMES_STATISTICAL;
9373
- }({});
9758
+ //#region src/engine/ast-node/node-type.ts
9759
+ const NODE_ORDER_MAP = new Map([
9760
+ [1, 7],
9761
+ [2, 9],
9762
+ [3, 8],
9763
+ [4, 6],
9764
+ [5, 1],
9765
+ [6, 2],
9766
+ [9, 10],
9767
+ [10, 3],
9768
+ [11, 4],
9769
+ [12, 5]
9770
+ ]);
9374
9771
 
9375
9772
  //#endregion
9376
- //#region src/functions/text/function-names.ts
9377
- /**
9378
- * Copyright 2023-present DreamNum Co., Ltd.
9379
- *
9380
- * Licensed under the Apache License, Version 2.0 (the "License");
9381
- * you may not use this file except in compliance with the License.
9382
- * You may obtain a copy of the License at
9383
- *
9384
- * http://www.apache.org/licenses/LICENSE-2.0
9385
- *
9386
- * Unless required by applicable law or agreed to in writing, software
9387
- * distributed under the License is distributed on an "AS IS" BASIS,
9388
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9389
- * See the License for the specific language governing permissions and
9390
- * limitations under the License.
9391
- */
9392
- let FUNCTION_NAMES_TEXT = /* @__PURE__ */ function(FUNCTION_NAMES_TEXT) {
9393
- FUNCTION_NAMES_TEXT["ASC"] = "ASC";
9394
- FUNCTION_NAMES_TEXT["ARRAYTOTEXT"] = "ARRAYTOTEXT";
9395
- FUNCTION_NAMES_TEXT["BAHTTEXT"] = "BAHTTEXT";
9396
- FUNCTION_NAMES_TEXT["CHAR"] = "CHAR";
9397
- FUNCTION_NAMES_TEXT["CLEAN"] = "CLEAN";
9398
- FUNCTION_NAMES_TEXT["CODE"] = "CODE";
9399
- FUNCTION_NAMES_TEXT["CONCAT"] = "CONCAT";
9400
- FUNCTION_NAMES_TEXT["CONCATENATE"] = "CONCATENATE";
9401
- FUNCTION_NAMES_TEXT["DBCS"] = "DBCS";
9402
- FUNCTION_NAMES_TEXT["DOLLAR"] = "DOLLAR";
9403
- FUNCTION_NAMES_TEXT["EXACT"] = "EXACT";
9404
- FUNCTION_NAMES_TEXT["FIND"] = "FIND";
9405
- FUNCTION_NAMES_TEXT["FINDB"] = "FINDB";
9406
- FUNCTION_NAMES_TEXT["FIXED"] = "FIXED";
9407
- FUNCTION_NAMES_TEXT["LEFT"] = "LEFT";
9408
- FUNCTION_NAMES_TEXT["LEFTB"] = "LEFTB";
9409
- FUNCTION_NAMES_TEXT["LEN"] = "LEN";
9410
- FUNCTION_NAMES_TEXT["LENB"] = "LENB";
9411
- FUNCTION_NAMES_TEXT["LOWER"] = "LOWER";
9412
- FUNCTION_NAMES_TEXT["MID"] = "MID";
9413
- FUNCTION_NAMES_TEXT["MIDB"] = "MIDB";
9414
- FUNCTION_NAMES_TEXT["NUMBERSTRING"] = "NUMBERSTRING";
9415
- FUNCTION_NAMES_TEXT["NUMBERVALUE"] = "NUMBERVALUE";
9416
- FUNCTION_NAMES_TEXT["PHONETIC"] = "PHONETIC";
9417
- FUNCTION_NAMES_TEXT["PROPER"] = "PROPER";
9418
- FUNCTION_NAMES_TEXT["REGEXEXTRACT"] = "REGEXEXTRACT";
9419
- FUNCTION_NAMES_TEXT["REGEXMATCH"] = "REGEXMATCH";
9420
- FUNCTION_NAMES_TEXT["REGEXREPLACE"] = "REGEXREPLACE";
9421
- FUNCTION_NAMES_TEXT["REPLACE"] = "REPLACE";
9422
- FUNCTION_NAMES_TEXT["REPLACEB"] = "REPLACEB";
9423
- FUNCTION_NAMES_TEXT["REPT"] = "REPT";
9424
- FUNCTION_NAMES_TEXT["RIGHT"] = "RIGHT";
9425
- FUNCTION_NAMES_TEXT["RIGHTB"] = "RIGHTB";
9426
- FUNCTION_NAMES_TEXT["SEARCH"] = "SEARCH";
9427
- FUNCTION_NAMES_TEXT["SEARCHB"] = "SEARCHB";
9428
- FUNCTION_NAMES_TEXT["SUBSTITUTE"] = "SUBSTITUTE";
9429
- FUNCTION_NAMES_TEXT["T"] = "T";
9430
- FUNCTION_NAMES_TEXT["TEXT"] = "TEXT";
9431
- FUNCTION_NAMES_TEXT["TEXTAFTER"] = "TEXTAFTER";
9432
- FUNCTION_NAMES_TEXT["TEXTBEFORE"] = "TEXTBEFORE";
9433
- FUNCTION_NAMES_TEXT["TEXTJOIN"] = "TEXTJOIN";
9434
- FUNCTION_NAMES_TEXT["TEXTSPLIT"] = "TEXTSPLIT";
9435
- FUNCTION_NAMES_TEXT["TRIM"] = "TRIM";
9436
- FUNCTION_NAMES_TEXT["UNICHAR"] = "UNICHAR";
9437
- FUNCTION_NAMES_TEXT["UNICODE"] = "UNICODE";
9438
- FUNCTION_NAMES_TEXT["UPPER"] = "UPPER";
9439
- FUNCTION_NAMES_TEXT["VALUE"] = "VALUE";
9440
- FUNCTION_NAMES_TEXT["VALUETOTEXT"] = "VALUETOTEXT";
9441
- FUNCTION_NAMES_TEXT["CALL"] = "CALL";
9442
- FUNCTION_NAMES_TEXT["EUROCONVERT"] = "EUROCONVERT";
9443
- FUNCTION_NAMES_TEXT["REGISTER_ID"] = "REGISTER.ID";
9444
- return FUNCTION_NAMES_TEXT;
9445
- }({});
9773
+ //#region src/engine/ast-node/base-ast-node.ts
9774
+ var BaseAstNode = class {
9775
+ constructor(_token) {
9776
+ this._token = _token;
9777
+ _defineProperty(this, "_children", []);
9778
+ _defineProperty(this, "_definedNames", void 0);
9779
+ _defineProperty(this, "_parent", void 0);
9780
+ _defineProperty(this, "_valueObject", void 0);
9781
+ _defineProperty(this, "_calculateState", false);
9782
+ _defineProperty(this, "_async", false);
9783
+ _defineProperty(this, "_address", false);
9784
+ _defineProperty(this, "_isForcedCalculateFunction", false);
9785
+ }
9786
+ dispose() {
9787
+ var _this$_valueObject;
9788
+ this._children.forEach((node) => {
9789
+ node.dispose();
9790
+ });
9791
+ (_this$_valueObject = this._valueObject) === null || _this$_valueObject === void 0 || _this$_valueObject.dispose();
9792
+ this._valueObject = null;
9793
+ this._children = [];
9794
+ this._definedNames = null;
9795
+ this._parent = null;
9796
+ }
9797
+ get nodeType() {
9798
+ return 8;
9799
+ }
9800
+ resetCalculationState() {
9801
+ this._children.forEach((node) => {
9802
+ node.resetCalculationState();
9803
+ });
9804
+ this._valueObject = null;
9805
+ this._calculateState = false;
9806
+ }
9807
+ isAsync() {
9808
+ return this._async;
9809
+ }
9810
+ isAddress() {
9811
+ return this._address;
9812
+ }
9813
+ isForcedCalculateFunction() {
9814
+ return this._isForcedCalculateFunction;
9815
+ }
9816
+ setAsync() {
9817
+ this._async = true;
9818
+ }
9819
+ setAddress() {
9820
+ this._address = true;
9821
+ }
9822
+ getParent() {
9823
+ return this._parent;
9824
+ }
9825
+ setParent(node) {
9826
+ this._parent = node;
9827
+ node.addChildren(this);
9828
+ }
9829
+ setForcedCalculateFunction() {
9830
+ this._isForcedCalculateFunction = true;
9831
+ }
9832
+ getChildren() {
9833
+ return this._children;
9834
+ }
9835
+ addChildren(...astNode) {
9836
+ this._children.push(...astNode);
9837
+ }
9838
+ getToken() {
9839
+ return this._token;
9840
+ }
9841
+ setValue(value) {
9842
+ this._valueObject = value;
9843
+ }
9844
+ getValue() {
9845
+ return this._valueObject;
9846
+ }
9847
+ isCalculated() {
9848
+ return this._calculateState;
9849
+ }
9850
+ setCalculated() {
9851
+ this._calculateState = true;
9852
+ }
9853
+ execute() {}
9854
+ setNotEmpty(state = true) {}
9855
+ async executeAsync() {
9856
+ return Promise.resolve(0);
9857
+ }
9858
+ serialize() {
9859
+ const token = this.getToken();
9860
+ const children = this.getChildren();
9861
+ const childrenSerialization = [];
9862
+ const childrenCount = children.length;
9863
+ for (let i = 0; i < childrenCount; i++) {
9864
+ const item = children[i];
9865
+ childrenSerialization.push(item.serialize());
9866
+ }
9867
+ const result = {
9868
+ token,
9869
+ nodeType: this.nodeType
9870
+ };
9871
+ if (childrenCount > 0) result.children = childrenSerialization;
9872
+ return result;
9873
+ }
9874
+ hasDefinedName(definedName) {
9875
+ var _this$_definedNames;
9876
+ return ((_this$_definedNames = this._definedNames) === null || _this$_definedNames === void 0 ? void 0 : _this$_definedNames.includes(definedName)) || false;
9877
+ }
9878
+ setDefinedNames(definedNames) {
9879
+ this._definedNames = definedNames;
9880
+ }
9881
+ getDefinedNames() {
9882
+ return this._definedNames;
9883
+ }
9884
+ };
9885
+ var ErrorNode = class ErrorNode extends BaseAstNode {
9886
+ constructor(errorType) {
9887
+ super(errorType);
9888
+ _defineProperty(this, "_errorValueObject", void 0);
9889
+ this._errorValueObject = ErrorValueObject.create(errorType);
9890
+ }
9891
+ get nodeType() {
9892
+ return 7;
9893
+ }
9894
+ static create(errorType) {
9895
+ return new ErrorNode(errorType);
9896
+ }
9897
+ getValue() {
9898
+ return this._errorValueObject;
9899
+ }
9900
+ };
9446
9901
 
9447
9902
  //#endregion
9448
- //#region src/functions/web/function-names.ts
9449
- /**
9450
- * Copyright 2023-present DreamNum Co., Ltd.
9451
- *
9452
- * Licensed under the Apache License, Version 2.0 (the "License");
9453
- * you may not use this file except in compliance with the License.
9454
- * You may obtain a copy of the License at
9455
- *
9456
- * http://www.apache.org/licenses/LICENSE-2.0
9457
- *
9458
- * Unless required by applicable law or agreed to in writing, software
9459
- * distributed under the License is distributed on an "AS IS" BASIS,
9460
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9461
- * See the License for the specific language governing permissions and
9462
- * limitations under the License.
9463
- */
9464
- let FUNCTION_NAMES_WEB = /* @__PURE__ */ function(FUNCTION_NAMES_WEB) {
9465
- FUNCTION_NAMES_WEB["ENCODEURL"] = "ENCODEURL";
9466
- FUNCTION_NAMES_WEB["FILTERXML"] = "FILTERXML";
9467
- FUNCTION_NAMES_WEB["WEBSERVICE"] = "WEBSERVICE";
9468
- return FUNCTION_NAMES_WEB;
9469
- }({});
9903
+ //#region src/engine/ast-node/base-ast-node-factory.ts
9904
+ var BaseAstNodeFactory = class {
9905
+ get zIndex() {
9906
+ return 0;
9907
+ }
9908
+ dispose() {}
9909
+ create(param, currentRow, currentColumn) {
9910
+ let token;
9911
+ if (param instanceof LexerNode) token = param.getToken();
9912
+ else token = param;
9913
+ return new BaseAstNode(token);
9914
+ }
9915
+ };
9916
+
9917
+ //#endregion
9918
+ //#region src/engine/ast-node/ast-root-node.ts
9919
+ var AstRootNode = class extends BaseAstNode {
9920
+ get nodeType() {
9921
+ return 9;
9922
+ }
9923
+ execute() {
9924
+ const children = this.getChildren();
9925
+ if (children.length > 1) {
9926
+ this.setValue(ErrorValueObject.create("#VALUE!"));
9927
+ return;
9928
+ }
9929
+ const node = children[0];
9930
+ if (node == null)
9931
+ /**
9932
+ * fix: https://github.com/dream-num/univer/issues/1415
9933
+ */
9934
+ this.setValue(ErrorValueObject.create("#VALUE!"));
9935
+ else this.setValue(node.getValue());
9936
+ }
9937
+ };
9938
+ var AstRootNodeFactory = class extends BaseAstNodeFactory {
9939
+ get zIndex() {
9940
+ return NODE_ORDER_MAP.get(9) || 100;
9941
+ }
9942
+ checkAndCreateNodeType(param) {
9943
+ if (!(param instanceof LexerNode)) return;
9944
+ if (param.getToken() === "R_1") return new AstRootNode("R_1");
9945
+ }
9946
+ };
9470
9947
 
9471
9948
  //#endregion
9472
9949
  //#region src/functions/column-like-functions.ts
@@ -9493,7 +9970,8 @@ const FORMULA_CACHE_LRU_COUNT = 5e3;
9493
9970
  const FORMULA_AST_CACHE = new FormulaAstLRU(FORMULA_CACHE_LRU_COUNT);
9494
9971
  function generateAstNode(unitId, formulaString, lexer, astTreeBuilder, currentConfigService) {
9495
9972
  let astNode = FORMULA_AST_CACHE.get(`${unitId}${formulaString}`);
9496
- if (astNode && !isDirtyDefinedForNode(astNode, currentConfigService)) return astNode;
9973
+ const noCache = checkIsChangedByDefinedName(unitId, formulaString, currentConfigService);
9974
+ if (!noCache && astNode && !isDirtyDefinedForNode(astNode, currentConfigService)) return astNode;
9497
9975
  const lexerNode = lexer.treeBuilder(formulaString);
9498
9976
  if (ERROR_TYPE_SET.has(lexerNode)) return ErrorNode.create(lexerNode);
9499
9977
  astNode = astTreeBuilder.parse(lexerNode);
@@ -9501,9 +9979,20 @@ function generateAstNode(unitId, formulaString, lexer, astTreeBuilder, currentCo
9501
9979
  console.error("generateAstNode astNode is null");
9502
9980
  return ErrorNode.create(lexerNode);
9503
9981
  }
9504
- FORMULA_AST_CACHE.set(`${unitId}${formulaString}`, astNode);
9982
+ if (!noCache) FORMULA_AST_CACHE.set(`${unitId}${formulaString}`, astNode);
9505
9983
  return astNode;
9506
9984
  }
9985
+ function checkIsChangedByDefinedName(unitId, formula, currentConfigService) {
9986
+ const unitDefinedNameMap = currentConfigService.getDirtyDefinedNameMap()[unitId];
9987
+ if (unitDefinedNameMap == null) return false;
9988
+ const formulaText = normalizeFormulaText(formula);
9989
+ const names = Object.keys(unitDefinedNameMap);
9990
+ for (let i = 0, len = names.length; i < len; i++) if (normalizeFormulaText(names[i]) === formulaText) return true;
9991
+ return false;
9992
+ }
9993
+ function normalizeFormulaText(formula) {
9994
+ return formula.startsWith("=") ? formula.slice(1) : formula;
9995
+ }
9507
9996
  function isDirtyDefinedForNode(node, currentConfigService) {
9508
9997
  const definedNameMap = currentConfigService.getDirtyDefinedNameMap();
9509
9998
  const executeUnitId = currentConfigService.getExecuteUnitId();
@@ -11367,6 +11856,8 @@ var DependencyManagerBaseService = class extends _univerjs_core.Disposable {
11367
11856
  updateDependencyTreeDirtyState(treeId, isDirty) {
11368
11857
  throw new Error("Method not implemented.");
11369
11858
  }
11859
+ openKdTree() {}
11860
+ closeKdTree() {}
11370
11861
  };
11371
11862
  /**
11372
11863
  * Passively marked as dirty, register the reference and execution actions of the feature plugin.
@@ -11378,89 +11869,16 @@ var DependencyManagerService = class extends DependencyManagerBaseService {
11378
11869
  constructor(..._args2) {
11379
11870
  super(..._args2);
11380
11871
  _defineProperty(this, "_allTreeMap", /* @__PURE__ */ new Map());
11381
- }
11382
- dispose() {
11383
- super.dispose();
11384
- this.reset();
11385
- }
11386
- buildDependencyTree(shouldBeBuildTrees, dependencyTrees = []) {
11387
- const allTrees = this.getAllTree();
11388
- if (shouldBeBuildTrees.length === 0) {
11389
- this._buildReverseDependency(allTrees, dependencyTrees);
11390
- return allTrees;
11391
- }
11392
- this._buildDependencyTree(allTrees, shouldBeBuildTrees);
11393
- this._buildReverseDependency(allTrees, shouldBeBuildTrees);
11394
- return allTrees;
11395
- }
11396
- /**
11397
- * Build the dependency relationship between the trees.
11398
- * @param allTrees all FormulaDependencyTree
11399
- * @param shouldBeBuildTrees FormulaDependencyTree[] | FormulaDependencyTreeCache
11400
- */
11401
- _buildDependencyTree(allTrees, shouldBeBuildTrees) {
11402
- const shouldBeBuildTreeMap = /* @__PURE__ */ new Map();
11403
- for (let i = 0; i < shouldBeBuildTrees.length; i++) {
11404
- const tree = shouldBeBuildTrees[i];
11405
- shouldBeBuildTreeMap.set(tree.treeId, tree);
11406
- }
11407
- for (let i = 0; i < allTrees.length; i++) {
11408
- const tree = allTrees[i];
11409
- const RTreeItem = tree.toRTreeItem();
11410
- const searchResults = this._dependencyRTreeCache.bulkSearch(RTreeItem);
11411
- for (const id of searchResults) {
11412
- const shouldBeBuildTree = shouldBeBuildTreeMap.get(id);
11413
- if (shouldBeBuildTree && tree !== shouldBeBuildTree && !shouldBeBuildTree.hasChildren(tree.treeId)) shouldBeBuildTree.pushChildren(tree);
11414
- }
11415
- }
11416
- shouldBeBuildTreeMap.clear();
11417
- }
11418
- /**
11419
- * Build the reverse dependency relationship between the trees.
11420
- * @param allTrees
11421
- * @param dependencyTrees
11422
- */
11423
- _buildReverseDependency(allTrees, dependencyTrees) {
11424
- const allTreeMap = /* @__PURE__ */ new Map();
11425
- for (let i = 0; i < allTrees.length; i++) {
11426
- const tree = allTrees[i];
11427
- allTreeMap.set(tree.treeId, tree);
11428
- }
11429
- for (let i = 0; i < dependencyTrees.length; i++) {
11430
- const tree = dependencyTrees[i];
11431
- const RTreeItem = tree.toRTreeItem();
11432
- const searchResults = this._dependencyRTreeCache.bulkSearch(RTreeItem);
11433
- for (const id of searchResults) {
11434
- const allTree = allTreeMap.get(id);
11435
- if (allTree && tree !== allTree && !allTree.hasChildren(tree.treeId)) allTree.pushChildren(tree);
11436
- }
11437
- }
11438
- allTreeMap.clear();
11439
- }
11440
- /**
11441
- * Get all FormulaDependencyTree from _otherFormulaData, _featureFormulaData, _formulaData
11442
- * return FormulaDependencyTree[]
11443
- */
11444
- getAllTree() {
11445
- const trees = [];
11446
- this._allTreeMap.forEach((tree) => {
11447
- tree.resetState();
11448
- trees.push(tree);
11449
- });
11450
- return trees;
11451
- }
11452
- getTreeById(treeId) {
11453
- return this._allTreeMap.get(treeId);
11872
+ _defineProperty(this, "_dependencyRTreeCache", new _univerjs_core.RTree(true));
11454
11873
  }
11455
11874
  reset() {
11456
11875
  this._otherFormulaData.clear();
11457
11876
  this._featureFormulaData.clear();
11458
11877
  this._formulaData.clear();
11459
- this._definedNameMap.clear();
11460
- this._otherFormulaDataMainData.clear();
11461
11878
  this._dependencyRTreeCache.clear();
11462
11879
  this._allTreeMap.clear();
11463
11880
  this._restDependencyTreeId();
11881
+ this._otherFormulaDataMainData.clear();
11464
11882
  }
11465
11883
  addOtherFormulaDependency(unitId, sheetId, formulaId, dependencyTree) {
11466
11884
  if (!this._otherFormulaData.has(unitId)) this._otherFormulaData.set(unitId, /* @__PURE__ */ new Map());
@@ -11469,7 +11887,6 @@ var DependencyManagerService = class extends DependencyManagerBaseService {
11469
11887
  const sheetMap = unitMap.get(sheetId);
11470
11888
  if (!sheetMap.has(formulaId)) sheetMap.set(formulaId, new _univerjs_core.ObjectMatrix());
11471
11889
  sheetMap.get(formulaId).setValue(dependencyTree.refOffsetX, dependencyTree.refOffsetY, dependencyTree.treeId);
11472
- this._addAllTreeMap(dependencyTree);
11473
11890
  }
11474
11891
  removeOtherFormulaDependency(unitId, sheetId, formulaIds) {
11475
11892
  const unitMap = this._otherFormulaData.get(unitId);
@@ -11480,7 +11897,6 @@ var DependencyManagerService = class extends DependencyManagerBaseService {
11480
11897
  if (treeSet == null) return;
11481
11898
  treeSet.forValue((row, column, treeId) => {
11482
11899
  this._removeDependencyRTreeCache(treeId);
11483
- this.clearDependencyForTree(this._allTreeMap.get(treeId));
11484
11900
  this._removeAllTreeMap(treeId);
11485
11901
  });
11486
11902
  sheetMap.delete(formulaId);
@@ -11499,11 +11915,7 @@ var DependencyManagerService = class extends DependencyManagerBaseService {
11499
11915
  const formulaTreeSet = sheetMap.get(formulaId);
11500
11916
  if (formulaTreeSet == null) continue;
11501
11917
  formulaTreeSet.forValue((row, column, treeId) => {
11502
- const tree = this._allTreeMap.get(treeId);
11503
- if (tree) {
11504
- this.clearDependencyForTree(tree);
11505
- this._removeAllTreeMap(treeId);
11506
- }
11918
+ if (this._allTreeMap.get(treeId)) this._removeAllTreeMap(treeId);
11507
11919
  });
11508
11920
  this._otherFormulaDataMainData.delete(formulaId);
11509
11921
  }
@@ -11516,11 +11928,7 @@ var DependencyManagerService = class extends DependencyManagerBaseService {
11516
11928
  const formulaTreeSet = sheetMap.get(formulaId);
11517
11929
  if (formulaTreeSet == null) continue;
11518
11930
  formulaTreeSet.forValue((row, column, treeId) => {
11519
- const tree = this._allTreeMap.get(treeId);
11520
- if (tree) {
11521
- this.clearDependencyForTree(tree);
11522
- this._removeAllTreeMap(treeId);
11523
- }
11931
+ if (this._allTreeMap.get(treeId)) this._removeAllTreeMap(treeId);
11524
11932
  });
11525
11933
  this._otherFormulaDataMainData.delete(formulaId);
11526
11934
  }
@@ -11533,7 +11941,6 @@ var DependencyManagerService = class extends DependencyManagerBaseService {
11533
11941
  const unitMap = this._featureFormulaData.get(unitId);
11534
11942
  if (!unitMap.has(sheetId)) unitMap.set(sheetId, /* @__PURE__ */ new Map());
11535
11943
  unitMap.get(sheetId).set(featureId, dependencyTree.treeId);
11536
- this._addAllTreeMap(dependencyTree);
11537
11944
  }
11538
11945
  removeFeatureFormulaDependency(unitId, sheetId, featureIds) {
11539
11946
  const unitMap = this._featureFormulaData.get(unitId);
@@ -11544,7 +11951,6 @@ var DependencyManagerService = class extends DependencyManagerBaseService {
11544
11951
  if (deleteTreeId == null) return;
11545
11952
  this._removeDependencyRTreeCache(deleteTreeId);
11546
11953
  sheetMap.delete(featureId);
11547
- this.clearDependencyForTree(this._allTreeMap.get(deleteTreeId));
11548
11954
  this._removeAllTreeMap(deleteTreeId);
11549
11955
  });
11550
11956
  }
@@ -11556,7 +11962,6 @@ var DependencyManagerService = class extends DependencyManagerBaseService {
11556
11962
  this._removeDependencyRTreeCacheById(unitId, sheetId);
11557
11963
  sheetMap.forEach((featureTreeId) => {
11558
11964
  if (featureTreeId == null) return;
11559
- this.clearDependencyForTree(this._allTreeMap.get(featureTreeId));
11560
11965
  this._removeAllTreeMap(featureTreeId);
11561
11966
  });
11562
11967
  sheetMap.clear();
@@ -11565,7 +11970,6 @@ var DependencyManagerService = class extends DependencyManagerBaseService {
11565
11970
  this._removeDependencyRTreeCacheById(unitId, sheetId);
11566
11971
  sheetMap.forEach((featureTreeId) => {
11567
11972
  if (featureTreeId == null) return;
11568
- this.clearDependencyForTree(this._allTreeMap.get(featureTreeId));
11569
11973
  this._removeAllTreeMap(featureTreeId);
11570
11974
  });
11571
11975
  });
@@ -11577,7 +11981,6 @@ var DependencyManagerService = class extends DependencyManagerBaseService {
11577
11981
  const unitMap = this._formulaData.get(unitId);
11578
11982
  if (!unitMap.has(sheetId)) unitMap.set(sheetId, new _univerjs_core.ObjectMatrix());
11579
11983
  unitMap.get(sheetId).setValue(row, column, dependencyTree.treeId);
11580
- this._addAllTreeMap(dependencyTree);
11581
11984
  }
11582
11985
  removeFormulaDependency(unitId, sheetId, row, column) {
11583
11986
  const unitMap = this._formulaData.get(unitId);
@@ -11587,7 +11990,6 @@ var DependencyManagerService = class extends DependencyManagerBaseService {
11587
11990
  if (deleteTreeId == null) return;
11588
11991
  this._removeDependencyRTreeCache(deleteTreeId);
11589
11992
  sheetMatrix.realDeleteValue(row, column);
11590
- this.clearDependencyForTree(this._allTreeMap.get(deleteTreeId));
11591
11993
  this._removeAllTreeMap(deleteTreeId);
11592
11994
  }
11593
11995
  }
@@ -11598,7 +12000,6 @@ var DependencyManagerService = class extends DependencyManagerBaseService {
11598
12000
  this._removeDependencyRTreeCacheById(unitId, sheetId);
11599
12001
  sheetMatrix.forValue((row, column, treeId) => {
11600
12002
  if (treeId == null) return true;
11601
- this.clearDependencyForTree(this._allTreeMap.get(treeId));
11602
12003
  this._removeAllTreeMap(treeId);
11603
12004
  });
11604
12005
  sheetMatrix.reset();
@@ -11607,47 +12008,23 @@ var DependencyManagerService = class extends DependencyManagerBaseService {
11607
12008
  this._removeDependencyRTreeCacheById(unitId, sheetId);
11608
12009
  sheetMatrix.forValue((row, column, treeId) => {
11609
12010
  if (treeId == null) return true;
11610
- this.clearDependencyForTree(this._allTreeMap.get(treeId));
11611
12011
  this._removeAllTreeMap(treeId);
11612
12012
  });
11613
12013
  });
11614
12014
  this._formulaData.delete(unitId);
11615
12015
  }
11616
12016
  }
11617
- /**
11618
- * Clear the dependency relationship of the tree.
11619
- * establish the relationship between the parent and the child.
11620
- * @param shouldBeClearTree
11621
- */
11622
- clearDependencyForTree(shouldBeClearTree) {
11623
- if (shouldBeClearTree == null) return;
11624
- const parents = shouldBeClearTree.parents;
11625
- const children = shouldBeClearTree.children;
11626
- const allTreeMap = this._allTreeMap;
11627
- for (const parentTreeId of parents) {
11628
- const parent = allTreeMap.get(parentTreeId);
11629
- parent === null || parent === void 0 || parent.children.delete(shouldBeClearTree.treeId);
11630
- }
11631
- for (const childTreeId of children) {
11632
- const child = allTreeMap.get(childTreeId);
11633
- child === null || child === void 0 || child.parents.delete(shouldBeClearTree.treeId);
11634
- }
11635
- shouldBeClearTree.dispose();
11636
- }
11637
12017
  _removeDependencyRTreeCache(treeId) {
11638
12018
  if (treeId == null) return;
11639
12019
  const treeRangeMap = this._allTreeMap.get(treeId);
11640
12020
  if (treeRangeMap) {
11641
12021
  const searchRanges = [];
11642
- for (let i = 0; i < treeRangeMap.rangeList.length; i++) {
11643
- const { unitId, sheetId, range } = treeRangeMap.rangeList[i];
11644
- searchRanges.push({
11645
- unitId,
11646
- sheetId,
11647
- range,
11648
- id: treeId
11649
- });
11650
- }
12022
+ for (const [unitId, sheetMap] of treeRangeMap) for (const [sheetId, range] of sheetMap) searchRanges.push({
12023
+ unitId,
12024
+ sheetId,
12025
+ range,
12026
+ id: treeId
12027
+ });
11651
12028
  this._dependencyRTreeCache.bulkRemove(searchRanges);
11652
12029
  }
11653
12030
  }
@@ -11658,23 +12035,100 @@ var DependencyManagerService = class extends DependencyManagerBaseService {
11658
12035
  if (treeSet) {
11659
12036
  for (const treeId of treeSet) {
11660
12037
  this._removeDependencyRTreeCache(treeId);
11661
- this.clearDependencyForTree(this._allTreeMap.get(treeId));
11662
12038
  this._removeAllTreeMap(treeId);
11663
12039
  }
11664
12040
  treeSet.clear();
11665
12041
  }
11666
12042
  }
11667
12043
  }
12044
+ openKdTree() {
12045
+ this._dependencyRTreeCache.openKdTree();
12046
+ }
12047
+ closeKdTree() {
12048
+ this._dependencyRTreeCache.closeKdTree();
12049
+ }
11668
12050
  _removeAllTreeMap(treeId) {
11669
12051
  if (treeId == null) return;
11670
12052
  this._allTreeMap.delete(treeId);
11671
12053
  }
11672
12054
  _addAllTreeMap(tree) {
11673
- this._allTreeMap.set(tree.treeId, tree);
12055
+ const rangeList = tree.rangeList;
12056
+ let oldTreeMap = this._allTreeMap.get(tree.treeId);
12057
+ for (let i = 0; i < rangeList.length; i++) {
12058
+ var _oldTreeMap$get, _oldTreeMap$get2;
12059
+ let { unitId, sheetId, range } = rangeList[i];
12060
+ if (!oldTreeMap) {
12061
+ oldTreeMap = /* @__PURE__ */ new Map();
12062
+ this._allTreeMap.set(tree.treeId, oldTreeMap);
12063
+ }
12064
+ if (!oldTreeMap.has(unitId)) oldTreeMap.set(unitId, /* @__PURE__ */ new Map());
12065
+ const oldRange = oldTreeMap === null || oldTreeMap === void 0 || (_oldTreeMap$get = oldTreeMap.get(unitId)) === null || _oldTreeMap$get === void 0 ? void 0 : _oldTreeMap$get.get(sheetId);
12066
+ if (oldRange) range = {
12067
+ startRow: Math.min(range.startRow, oldRange.startRow),
12068
+ startColumn: Math.min(range.startColumn, oldRange.startColumn),
12069
+ endRow: Math.max(range.endRow, oldRange.endRow),
12070
+ endColumn: Math.max(range.endColumn, oldRange.endColumn)
12071
+ };
12072
+ (_oldTreeMap$get2 = oldTreeMap.get(unitId)) === null || _oldTreeMap$get2 === void 0 || _oldTreeMap$get2.set(sheetId, range);
12073
+ }
11674
12074
  }
11675
- updateDependencyTreeDirtyState(treeId, isDirty) {
11676
- const tree = this._allTreeMap.get(treeId);
11677
- if (tree) tree.isDirty = isDirty;
12075
+ dispose() {
12076
+ super.dispose();
12077
+ this.reset();
12078
+ }
12079
+ buildDependencyTree(shouldBeBuildTrees, dependencyTrees = []) {
12080
+ const allTrees = this.getAllTree();
12081
+ if (shouldBeBuildTrees.length === 0) {
12082
+ this._buildReverseDependency(allTrees, dependencyTrees);
12083
+ return allTrees;
12084
+ }
12085
+ this._buildDependencyTree(allTrees, shouldBeBuildTrees);
12086
+ this._buildReverseDependency(allTrees, shouldBeBuildTrees);
12087
+ return allTrees;
12088
+ }
12089
+ /**
12090
+ * Build the dependency relationship between the trees.
12091
+ * @param allTrees all FormulaDependencyTree
12092
+ * @param shouldBeBuildTrees FormulaDependencyTree[] | FormulaDependencyTreeCache
12093
+ */
12094
+ _buildDependencyTree(allTrees, shouldBeBuildTrees) {
12095
+ const shouldBeBuildTreeMap = /* @__PURE__ */ new Map();
12096
+ for (let i = 0; i < shouldBeBuildTrees.length; i++) {
12097
+ const tree = shouldBeBuildTrees[i];
12098
+ shouldBeBuildTreeMap.set(tree.treeId, tree);
12099
+ }
12100
+ for (let i = 0; i < allTrees.length; i++) {
12101
+ const tree = allTrees[i];
12102
+ const RTreeItem = tree.toRTreeItem();
12103
+ const searchResults = this._dependencyRTreeCache.bulkSearch(RTreeItem);
12104
+ for (const id of searchResults) {
12105
+ const shouldBeBuildTree = shouldBeBuildTreeMap.get(id);
12106
+ if (shouldBeBuildTree && tree !== shouldBeBuildTree && !shouldBeBuildTree.hasChildren(tree.treeId)) shouldBeBuildTree.pushChildren(tree);
12107
+ }
12108
+ }
12109
+ shouldBeBuildTreeMap.clear();
12110
+ }
12111
+ /**
12112
+ * Build the reverse dependency relationship between the trees.
12113
+ * @param allTrees
12114
+ * @param dependencyTrees
12115
+ */
12116
+ _buildReverseDependency(allTrees, dependencyTrees) {
12117
+ const allTreeMap = /* @__PURE__ */ new Map();
12118
+ for (let i = 0; i < allTrees.length; i++) {
12119
+ const tree = allTrees[i];
12120
+ allTreeMap.set(tree.treeId, tree);
12121
+ }
12122
+ for (let i = 0; i < dependencyTrees.length; i++) {
12123
+ const tree = dependencyTrees[i];
12124
+ const RTreeItem = tree.toRTreeItem();
12125
+ const searchResults = this._dependencyRTreeCache.bulkSearch(RTreeItem);
12126
+ for (const id of searchResults) {
12127
+ const allTree = allTreeMap.get(id);
12128
+ if (allTree && tree !== allTree && !allTree.hasChildren(tree.treeId)) allTree.pushChildren(tree);
12129
+ }
12130
+ }
12131
+ allTreeMap.clear();
11678
12132
  }
11679
12133
  };
11680
12134
  const IDependencyManagerService = (0, _univerjs_core.createIdentifier)("univer.formula.dependency-manager.service");
@@ -12217,12 +12671,14 @@ let FormulaDependencyGenerator = class FormulaDependencyGenerator extends _unive
12217
12671
  this._lexerTreeBuilder = _lexerTreeBuilder;
12218
12672
  _defineProperty(this, "_updateRangeFlattenCache", /* @__PURE__ */ new Map());
12219
12673
  _defineProperty(this, "_dependencyRTreeCacheForAddressFunction", new _univerjs_core.RTree());
12674
+ _defineProperty(this, "_dependencyTreeCache", /* @__PURE__ */ new Map());
12220
12675
  _defineProperty(this, "_executedAddressFunctionNodeIds", /* @__PURE__ */ new Set());
12221
12676
  _defineProperty(this, "_formulaDependencyTreeModel", /* @__PURE__ */ new Map());
12222
12677
  this._initUnitDispose();
12223
12678
  }
12224
12679
  dispose() {
12225
12680
  super.dispose();
12681
+ this._dependencyTreeCache.clear();
12226
12682
  this._updateRangeFlattenCache.clear();
12227
12683
  this._dependencyRTreeCacheForAddressFunction.clear();
12228
12684
  FORMULA_AST_CACHE.clear();
@@ -12252,87 +12708,301 @@ let FormulaDependencyGenerator = class FormulaDependencyGenerator extends _unive
12252
12708
  });
12253
12709
  });
12254
12710
  const unitData = this._currentConfigService.getUnitData();
12255
- const treeList = await this._generateTreeList(formulaData, otherFormulaData, unitData);
12256
- if (isCalculateTreeModel) this._runtimeService.setDependencyTreeModelData(this._getAllDependencyJson(treeList));
12257
- const updateTreeList = this._getUpdateTreeListAndMakeDependency(treeList);
12258
- let finalTreeList = this._calculateRunList(updateTreeList);
12259
- if (this._dependencyFeatureCalculation(finalTreeList)) {
12260
- finalTreeList.forEach((tree) => {
12261
- tree.resetState();
12262
- });
12263
- finalTreeList = this._calculateRunList(finalTreeList);
12264
- }
12711
+ await this._generateTreeList(formulaData, otherFormulaData, unitData);
12712
+ this._dependencyManagerService.openKdTree();
12713
+ const updateTreeList = this._getUpdateTreeListAndMakeDependency();
12714
+ const finalTreeList = this._calculateRunList(updateTreeList);
12265
12715
  if (this._checkIsCycleDependency(finalTreeList)) this._runtimeService.enableCycleDependency();
12716
+ if (isCalculateTreeModel) this._runtimeService.setDependencyTreeModelData(this._getAllDependencyJson(Array.from(this._dependencyTreeCache.values())));
12717
+ this._dependencyTreeCache.clear();
12266
12718
  this._dependencyRTreeCacheForAddressFunction.clear();
12719
+ this._dependencyManagerService.closeKdTree();
12267
12720
  this._runtimeService.clearArrayObjectCache();
12268
12721
  return Promise.resolve(finalTreeList);
12269
12722
  }
12270
- _dependencyFeatureCalculation(newTreeList) {
12271
- const featureMap = this._featureCalculationManagerService.getReferenceExecutorMap();
12272
- if (featureMap.size === 0) return;
12723
+ _isCyclicUtilMap(treeId, colorMap) {
12724
+ const WHITE = 0;
12725
+ const GRAY = 1;
12726
+ const BLACK = 2;
12727
+ const stack = [treeId];
12728
+ while (stack.length > 0) {
12729
+ const currentTreeId = stack[stack.length - 1];
12730
+ if ((colorMap.get(currentTreeId) || WHITE) === WHITE) {
12731
+ colorMap.set(currentTreeId, GRAY);
12732
+ const node = this._dependencyTreeCache.get(currentTreeId);
12733
+ if (node == null) {
12734
+ colorMap.set(currentTreeId, BLACK);
12735
+ stack.pop();
12736
+ continue;
12737
+ }
12738
+ const parents = this._dependencyManagerService.searchDependency(node.toRTreeItem());
12739
+ for (const parentTreeId of parents) {
12740
+ const parentColor = colorMap.get(parentTreeId) || WHITE;
12741
+ if (parentColor === GRAY) return true;
12742
+ else if (parentColor === WHITE) stack.push(parentTreeId);
12743
+ }
12744
+ } else {
12745
+ colorMap.set(currentTreeId, BLACK);
12746
+ stack.pop();
12747
+ }
12748
+ }
12749
+ return false;
12750
+ }
12751
+ _checkIsCycleDependency(treeList) {
12752
+ const colorMap = /* @__PURE__ */ new Map();
12753
+ for (const tree of treeList) if (!colorMap.has(tree.treeId)) {
12754
+ if (this._isCyclicUtilMap(tree.treeId, colorMap)) return true;
12755
+ }
12756
+ colorMap.clear();
12757
+ return false;
12758
+ }
12759
+ _getFeatureFormulaTree(featureId, treeId, params) {
12760
+ const { unitId, subUnitId, dependencyRanges, getDirtyData } = params;
12761
+ const FDtree = new FormulaDependencyTree(treeId || generateRandomDependencyTreeId(this._dependencyManagerService));
12762
+ FDtree.unitId = unitId;
12763
+ FDtree.subUnitId = subUnitId;
12764
+ FDtree.rangeList = dependencyRanges;
12765
+ FDtree.getDirtyData = getDirtyData;
12766
+ const allDependency = getDirtyData(this._currentConfigService.getDirtyData(), this._runtimeService.getAllRuntimeData());
12767
+ FDtree.featureDirtyRanges = this._convertDirtyRangesToUnitRange(allDependency.dirtyRanges);
12768
+ FDtree.featureId = featureId;
12769
+ FDtree.type = 2;
12770
+ this._dependencyManagerService.addFeatureFormulaDependency(unitId, subUnitId, featureId, FDtree);
12771
+ this._dependencyTreeCache.set(FDtree.treeId, FDtree);
12772
+ if (this._dependencyManagerService.getFeatureFormulaDependency(params.unitId, params.subUnitId, featureId)) FDtree.isCache = true;
12773
+ return FDtree;
12774
+ }
12775
+ _registerOtherFormulas(otherFormulaData, otherFormulaDataKeys, treeList) {
12273
12776
  /**
12274
- * Clear the dependency relationships of all featureCalculation nodes in the tree.
12275
- * Because each execution requires rebuilding the reverse dependencies,
12276
- * the previous dependencies may become outdated due to data changes in applications such as pivot tables,
12277
- * which can result in an outdated dirty mark range.
12777
+ * Register formulas in doc, slide, and other types of applications.
12278
12778
  */
12279
- this._clearFeatureCalculationNode(newTreeList);
12280
- let hasFeatureCalculation = false;
12281
- featureMap.forEach((subUnitMap, _) => {
12282
- subUnitMap.forEach((featureMap, _) => {
12283
- featureMap.forEach((params, featureId) => {
12284
- const { unitId, subUnitId, getDirtyData } = params;
12285
- const allDependency = getDirtyData(this._currentConfigService.getDirtyData(), this._runtimeService.getAllRuntimeData());
12286
- const dirtyRanges = this._convertDirtyRangesToUnitRange(allDependency.dirtyRanges);
12287
- const intersectTrees = this._intersectFeatureCalculation(dirtyRanges, newTreeList, {
12288
- unitId,
12289
- subUnitId,
12290
- featureId
12291
- });
12292
- if (intersectTrees.length > 0) {
12293
- let featureTree = this._getExistTreeList({
12294
- unitId,
12295
- subUnitId,
12296
- featureId
12297
- }, newTreeList);
12298
- if (featureTree == null) {
12299
- featureTree = this._getFeatureFormulaTree(featureId, generateRandomDependencyTreeId(this._dependencyManagerService), params);
12300
- newTreeList.push(featureTree);
12779
+ for (const unitId of otherFormulaDataKeys) {
12780
+ const subComponentData = otherFormulaData[unitId];
12781
+ if (subComponentData == null) continue;
12782
+ const subComponentKeys = Object.keys(subComponentData);
12783
+ for (const subUnitId of subComponentKeys) {
12784
+ const subFormulaData = subComponentData[subUnitId];
12785
+ if (subFormulaData == null) continue;
12786
+ const { rowCount = Infinity, columnCount = Infinity } = this._currentConfigService.getSheetRowColumnCount(unitId, subUnitId) || {};
12787
+ const subFormulaDataKeys = Object.keys(subFormulaData);
12788
+ for (const subFormulaDataId of subFormulaDataKeys) {
12789
+ var _treeMatrix$getValue;
12790
+ const hasOtherFormula = this._dependencyManagerService.hasOtherFormulaDataMainData(subFormulaDataId);
12791
+ const { f: formulaString, ranges } = subFormulaData[subFormulaDataId];
12792
+ let isCache = false;
12793
+ if (hasOtherFormula) isCache = true;
12794
+ const { firstRow, firstColumn } = this._getFirstCellOfRange(ranges);
12795
+ const treeMatrix = this._dependencyManagerService.getOtherFormulaDependency(unitId, subUnitId, subFormulaDataId);
12796
+ const firstFDtree = new FormulaDependencyTree((_treeMatrix$getValue = treeMatrix === null || treeMatrix === void 0 ? void 0 : treeMatrix.getValue(0, 0)) !== null && _treeMatrix$getValue !== void 0 ? _treeMatrix$getValue : generateRandomDependencyTreeId(this._dependencyManagerService));
12797
+ for (let i = 0; i < ranges.length; i++) {
12798
+ const range = ranges[i];
12799
+ const { startRow, startColumn } = range;
12800
+ let { endRow, endColumn } = range;
12801
+ endRow = Math.min(endRow, rowCount - 1);
12802
+ endColumn = Math.min(endColumn, columnCount - 1);
12803
+ for (let r = startRow; r <= endRow; r++) for (let c = startColumn; c <= endColumn; c++) {
12804
+ const x = c - firstColumn;
12805
+ const y = r - firstRow;
12806
+ if (x === 0 && y === 0) {
12807
+ firstFDtree.formula = formulaString;
12808
+ firstFDtree.unitId = unitId;
12809
+ firstFDtree.subUnitId = subUnitId;
12810
+ firstFDtree.formulaId = subFormulaDataId;
12811
+ firstFDtree.type = 1;
12812
+ firstFDtree.isCache = isCache;
12813
+ treeList.push(firstFDtree);
12814
+ this._dependencyTreeCache.set(firstFDtree.treeId, firstFDtree);
12815
+ this._dependencyManagerService.addOtherFormulaDependency(unitId, subUnitId, subFormulaDataId, firstFDtree);
12816
+ this._dependencyManagerService.addFormulaDependencyByDefinedName(firstFDtree);
12817
+ continue;
12818
+ }
12819
+ const virtual = new FormulaDependencyTreeVirtual();
12820
+ virtual.treeId = (treeMatrix === null || treeMatrix === void 0 ? void 0 : treeMatrix.getValue(x, y)) || generateRandomDependencyTreeId(this._dependencyManagerService);
12821
+ virtual.refTree = firstFDtree;
12822
+ virtual.refOffsetX = x;
12823
+ virtual.refOffsetY = y;
12824
+ virtual.isCache = isCache;
12825
+ virtual.type = 1;
12826
+ this._dependencyManagerService.addOtherFormulaDependency(unitId, subUnitId, subFormulaDataId, virtual);
12827
+ this._dependencyManagerService.addFormulaDependencyByDefinedName(virtual);
12828
+ treeList.push(virtual);
12829
+ this._dependencyTreeCache.set(virtual.treeId, virtual);
12301
12830
  }
12302
- featureTree.parents = /* @__PURE__ */ new Set();
12303
- intersectTrees.forEach((tree) => {
12304
- if (tree.hasChildren(featureTree.treeId)) return;
12305
- tree.pushChildren(featureTree);
12306
- });
12307
- hasFeatureCalculation = true;
12308
12831
  }
12832
+ this._dependencyManagerService.addOtherFormulaDependencyMainData(subFormulaDataId);
12833
+ }
12834
+ }
12835
+ }
12836
+ }
12837
+ _registerFormulas(formulaDataKeys, formulaData, unitData, treeList) {
12838
+ /**
12839
+ * Register formulas in the sheet.
12840
+ */
12841
+ for (const unitId of formulaDataKeys) {
12842
+ const sheetData = formulaData[unitId];
12843
+ if (sheetData == null) continue;
12844
+ const sheetDataKeys = Object.keys(sheetData);
12845
+ for (const sheetId of sheetDataKeys) {
12846
+ const matrixData = new _univerjs_core.ObjectMatrix(sheetData[sheetId] || {});
12847
+ const sIdCache = /* @__PURE__ */ new Map();
12848
+ matrixData.forValue((row, column, formulaDataItem) => {
12849
+ if (formulaDataItem == null) return true;
12850
+ const { x = 0, y = 0, si } = formulaDataItem;
12851
+ if (!(x === 0 && y === 0 && si != null)) return true;
12852
+ const FDtree = this._createFDtree(unitId, sheetId, row, column, unitData, formulaDataItem);
12853
+ const treeId = this._dependencyManagerService.getFormulaDependency(unitId, sheetId, row, column);
12854
+ if (treeId != null) FDtree.treeId = treeId;
12855
+ else {
12856
+ this._dependencyManagerService.addFormulaDependency(unitId, sheetId, row, column, FDtree);
12857
+ this._dependencyManagerService.addFormulaDependencyByDefinedName(FDtree);
12858
+ }
12859
+ sIdCache.set(si, FDtree);
12860
+ treeList.push(FDtree);
12861
+ this._dependencyTreeCache.set(FDtree.treeId, FDtree);
12309
12862
  });
12310
- });
12311
- });
12312
- return hasFeatureCalculation;
12863
+ matrixData.forValue((row, column, formulaDataItem) => {
12864
+ if (formulaDataItem == null) return true;
12865
+ const { x = 0, y = 0, si } = formulaDataItem;
12866
+ if (x === 0 && y === 0 && si != null) return true;
12867
+ let FDtree;
12868
+ if (si && sIdCache.has(si)) {
12869
+ const cache = sIdCache.get(si);
12870
+ FDtree = this._createVirtualFDtree(cache, formulaDataItem);
12871
+ } else FDtree = this._createFDtree(unitId, sheetId, row, column, unitData, formulaDataItem);
12872
+ const treeId = this._dependencyManagerService.getFormulaDependency(unitId, sheetId, row, column);
12873
+ if (treeId != null) FDtree.treeId = treeId;
12874
+ else {
12875
+ this._dependencyManagerService.addFormulaDependency(unitId, sheetId, row, column, FDtree);
12876
+ this._dependencyManagerService.addFormulaDependencyByDefinedName(FDtree);
12877
+ }
12878
+ treeList.push(FDtree);
12879
+ this._dependencyTreeCache.set(FDtree.treeId, FDtree);
12880
+ });
12881
+ sIdCache.clear();
12882
+ }
12883
+ }
12884
+ }
12885
+ _createFDtree(unitId, sheetId, row, column, unitData, formulaDataItem) {
12886
+ const { f: formulaString, x = 0, y = 0 } = formulaDataItem;
12887
+ const FDtree = new FormulaDependencyTree(generateRandomDependencyTreeId(this._dependencyManagerService));
12888
+ const sheetItem = unitData[unitId][sheetId];
12889
+ FDtree.formula = formulaString;
12890
+ FDtree.unitId = unitId;
12891
+ FDtree.subUnitId = sheetId;
12892
+ FDtree.row = row;
12893
+ FDtree.column = column;
12894
+ FDtree.rowCount = sheetItem.rowCount;
12895
+ FDtree.columnCount = sheetItem.columnCount;
12896
+ return FDtree;
12313
12897
  }
12314
- _clearFeatureCalculationNode(newTreeList) {
12315
- const featureMap = this._featureCalculationManagerService.getReferenceExecutorMap();
12316
- newTreeList.forEach((tree) => {
12317
- const newChildren = /* @__PURE__ */ new Set();
12318
- for (const childTreeId of tree.children) {
12319
- var _featureMap$get;
12320
- const child = this._dependencyManagerService.getTreeById(childTreeId);
12321
- if (!child) continue;
12322
- if (!child.featureId) newChildren.add(childTreeId);
12323
- else if (!((_featureMap$get = featureMap.get(tree.unitId)) === null || _featureMap$get === void 0 || (_featureMap$get = _featureMap$get.get(tree.subUnitId)) === null || _featureMap$get === void 0 ? void 0 : _featureMap$get.has(child.featureId))) newChildren.add(childTreeId);
12898
+ /**
12899
+ * Build a formula dependency tree based on the dependency relationships.
12900
+ * @param treeList
12901
+ */
12902
+ _getUpdateTreeListAndMakeDependency() {
12903
+ const newTreeList = [];
12904
+ const existTree = /* @__PURE__ */ new Set();
12905
+ const forceCalculate = this._currentConfigService.isForceCalculate();
12906
+ const dirtyRanges = this._currentConfigService.getDirtyRanges();
12907
+ const treeIds = this._dependencyManagerService.searchDependency(dirtyRanges);
12908
+ const addressSearchResults = this._dependencyRTreeCacheForAddressFunction.bulkSearch(dirtyRanges);
12909
+ for (const addressSearchResult of addressSearchResults) treeIds.add(addressSearchResult);
12910
+ for (const [treeId, tree] of this._dependencyTreeCache)
12911
+ /**
12912
+ * forceCalculate: Mandatory calculation, adding all formulas to dependencies
12913
+ * tree.dependencyRange: Formula dependent modification range
12914
+ * includeTree: modification range contains formula
12915
+ */
12916
+ if ((forceCalculate || tree.isDirty || tree.dependencySheetName(this._currentConfigService.getDirtyNameMap()) || treeIds.has(treeId) && !tree.isExcludeRange(this._currentConfigService.getExcludedRange())) && !existTree.has(treeId)) {
12917
+ newTreeList.push(tree);
12918
+ existTree.add(treeId);
12919
+ }
12920
+ for (const [treeId, tree] of this._dependencyTreeCache) {
12921
+ if (tree.isVirtual) continue;
12922
+ tree.rangeList.length = 0;
12923
+ }
12924
+ return newTreeList;
12925
+ }
12926
+ _getTreeById(treeId) {
12927
+ return this._dependencyTreeCache.get(treeId);
12928
+ }
12929
+ _getTreeNode(tree) {
12930
+ return generateAstNode(tree.unitId, tree.formula, this._lexer, this._astTreeBuilder, this._currentConfigService);
12931
+ }
12932
+ *_traverse(treeList, skippedTreeIds) {
12933
+ const stack = treeList;
12934
+ const cacheStack = /* @__PURE__ */ new Set();
12935
+ while (stack.length > 0) {
12936
+ const tree = stack.pop();
12937
+ cacheStack.clear();
12938
+ if (tree === void 0 || tree.isSkip()) continue;
12939
+ if (tree.isAdded()) {
12940
+ yield tree;
12941
+ tree.setSkip();
12942
+ skippedTreeIds.add(tree.treeId);
12943
+ continue;
12324
12944
  }
12325
- tree.children = newChildren;
12326
- const newParents = /* @__PURE__ */ new Set();
12327
- for (const parentTreeId of tree.parents) {
12328
- var _featureMap$get2;
12329
- const parent = this._dependencyManagerService.getTreeById(parentTreeId);
12330
- if (!parent) continue;
12331
- if (!parent.featureId) newParents.add(parentTreeId);
12332
- else if (!((_featureMap$get2 = featureMap.get(tree.unitId)) === null || _featureMap$get2 === void 0 || (_featureMap$get2 = _featureMap$get2.get(tree.subUnitId)) === null || _featureMap$get2 === void 0 ? void 0 : _featureMap$get2.has(parent.featureId))) newParents.add(parentTreeId);
12945
+ const searchResults = this._dependencyManagerService.searchDependency(tree.toRTreeItem(), skippedTreeIds);
12946
+ const addressSearchResults = this._dependencyRTreeCacheForAddressFunction.bulkSearch(tree.toRTreeItem(), skippedTreeIds);
12947
+ for (const addressSearchResult of addressSearchResults) searchResults.add(addressSearchResult);
12948
+ for (const parentTreeId of searchResults) {
12949
+ const parentTree = this._dependencyTreeCache.get(parentTreeId);
12950
+ if (!parentTree) {
12951
+ console.error("Dependency tree not found for treeId:", parentTreeId);
12952
+ continue;
12953
+ }
12954
+ if (parentTree.isAdded() || tree.isSkip()) continue;
12955
+ cacheStack.add(parentTree);
12333
12956
  }
12334
- tree.parents = newParents;
12335
- });
12957
+ searchResults.clear();
12958
+ if (cacheStack.size === 0) {
12959
+ yield tree;
12960
+ tree.setSkip();
12961
+ skippedTreeIds.add(tree.treeId);
12962
+ } else {
12963
+ tree.setAdded();
12964
+ stack.push(tree);
12965
+ for (const cacheTree of cacheStack) stack.push(cacheTree);
12966
+ }
12967
+ }
12968
+ stack.length = 0;
12969
+ cacheStack.clear();
12970
+ }
12971
+ _calculateRunList(treeList) {
12972
+ const formulaRunList = [];
12973
+ const skippedTreeIds = /* @__PURE__ */ new Set();
12974
+ for (const tree of this._traverse(treeList, skippedTreeIds)) formulaRunList.push(tree);
12975
+ return formulaRunList;
12976
+ }
12977
+ async _getAllTreeList() {
12978
+ await this._initializeGenerateTreeList();
12979
+ return Array.from(this._dependencyTreeCache.values());
12980
+ }
12981
+ _getDependencyTreeParenIds(tree) {
12982
+ return this._dependencyManagerService.searchDependency(tree.toRTreeItem());
12983
+ }
12984
+ _getDependencyTreeChildrenIds(tree) {
12985
+ const childrenIds = /* @__PURE__ */ new Set();
12986
+ const rangeList = tree.rangeList;
12987
+ for (const [treeId, dependencyTree] of this._dependencyTreeCache) for (const unitRange of rangeList) {
12988
+ const unitId = unitRange.unitId;
12989
+ const sheetId = unitRange.sheetId;
12990
+ if (dependencyTree.unitId !== unitId || dependencyTree.subUnitId !== sheetId) continue;
12991
+ const range = unitRange.range;
12992
+ if (dependencyTree.inRangeData(range)) {
12993
+ childrenIds.add(treeId);
12994
+ break;
12995
+ }
12996
+ }
12997
+ return childrenIds;
12998
+ }
12999
+ _startFormulaDependencyTreeModel() {
13000
+ this._dependencyManagerService.openKdTree();
13001
+ }
13002
+ _endFormulaDependencyTreeModel() {
13003
+ this._formulaDependencyTreeModel.clear();
13004
+ this._dependencyTreeCache.clear();
13005
+ this._dependencyManagerService.closeKdTree();
12336
13006
  }
12337
13007
  /**
12338
13008
  * TODO @DR-Univer: The next step will be to try changing the incoming dirtyRanges to an array, thus avoiding conversion.
@@ -12354,23 +13024,6 @@ let FormulaDependencyGenerator = class FormulaDependencyGenerator extends _unive
12354
13024
  }
12355
13025
  return unitRange;
12356
13026
  }
12357
- _intersectFeatureCalculation(dirtyRanges, newTreeList, param) {
12358
- const dependencyTree = [];
12359
- const treeIds = this._dependencyManagerService.searchDependency(dirtyRanges);
12360
- for (let i = 0, len = newTreeList.length; i < len; i++) {
12361
- const tree = newTreeList[i];
12362
- if (tree.unitId === param.unitId && tree.subUnitId === param.subUnitId && tree.featureId === param.featureId) continue;
12363
- if (treeIds.has(tree.treeId)) dependencyTree.push(tree);
12364
- }
12365
- return dependencyTree;
12366
- }
12367
- _getExistTreeList(param, treeList) {
12368
- const { unitId, subUnitId, featureId } = param;
12369
- for (let i = 0, len = treeList.length; i < len; i++) {
12370
- const tree = treeList[i];
12371
- if (tree.unitId === unitId && tree.subUnitId === subUnitId && tree.featureId === featureId) return tree;
12372
- }
12373
- }
12374
13027
  _isCyclicUtil(treeId, visited, recursionStack) {
12375
13028
  const node = this._dependencyManagerService.getTreeById(treeId);
12376
13029
  if (node == null) return false;
@@ -12385,15 +13038,6 @@ let FormulaDependencyGenerator = class FormulaDependencyGenerator extends _unive
12385
13038
  recursionStack.delete(node.treeId);
12386
13039
  return false;
12387
13040
  }
12388
- _checkIsCycleDependency(treeList) {
12389
- const visited = /* @__PURE__ */ new Set();
12390
- const recursionStack = /* @__PURE__ */ new Set();
12391
- for (let i = 0, len = treeList.length; i < len; i++) {
12392
- const tree = treeList[i];
12393
- if (this._isCyclicUtil(tree.treeId, visited, recursionStack) === true) return true;
12394
- }
12395
- return false;
12396
- }
12397
13041
  /**
12398
13042
  * Generate nodes for the dependency tree, where each node contains all the reference data ranges included in each formula.
12399
13043
  * @param formulaData
@@ -12440,82 +13084,6 @@ let FormulaDependencyGenerator = class FormulaDependencyGenerator extends _unive
12440
13084
  });
12441
13085
  });
12442
13086
  }
12443
- _getFeatureFormulaTree(featureId, treeId, params) {
12444
- const { unitId, subUnitId, dependencyRanges, getDirtyData } = params;
12445
- const FDtree = new FormulaDependencyTree(treeId || generateRandomDependencyTreeId(this._dependencyManagerService));
12446
- FDtree.unitId = unitId;
12447
- FDtree.subUnitId = subUnitId;
12448
- FDtree.rangeList = dependencyRanges;
12449
- FDtree.getDirtyData = getDirtyData;
12450
- const allDependency = getDirtyData(this._currentConfigService.getDirtyData(), this._runtimeService.getAllRuntimeData());
12451
- FDtree.featureDirtyRanges = this._convertDirtyRangesToUnitRange(allDependency.dirtyRanges);
12452
- FDtree.featureId = featureId;
12453
- FDtree.type = 2;
12454
- this._dependencyManagerService.addFeatureFormulaDependency(unitId, subUnitId, featureId, FDtree);
12455
- if (this._dependencyManagerService.getFeatureFormulaDependency(params.unitId, params.subUnitId, featureId)) FDtree.isCache = true;
12456
- return FDtree;
12457
- }
12458
- _registerOtherFormulas(otherFormulaData, otherFormulaDataKeys, treeList) {
12459
- /**
12460
- * Register formulas in doc, slide, and other types of applications.
12461
- */
12462
- for (const unitId of otherFormulaDataKeys) {
12463
- const subComponentData = otherFormulaData[unitId];
12464
- if (subComponentData == null) continue;
12465
- const subComponentKeys = Object.keys(subComponentData);
12466
- for (const subUnitId of subComponentKeys) {
12467
- const subFormulaData = subComponentData[subUnitId];
12468
- if (subFormulaData == null) continue;
12469
- const { rowCount = Infinity, columnCount = Infinity } = this._currentConfigService.getSheetRowColumnCount(unitId, subUnitId) || {};
12470
- const subFormulaDataKeys = Object.keys(subFormulaData);
12471
- for (const subFormulaDataId of subFormulaDataKeys) {
12472
- const hasOtherFormula = this._dependencyManagerService.hasOtherFormulaDataMainData(subFormulaDataId);
12473
- const { f: formulaString, ranges } = subFormulaData[subFormulaDataId];
12474
- let isCache = false;
12475
- if (hasOtherFormula) isCache = true;
12476
- const node = generateAstNode(unitId, formulaString, this._lexer, this._astTreeBuilder, this._currentConfigService);
12477
- const { firstRow, firstColumn } = this._getFirstCellOfRange(ranges);
12478
- const treeMatrix = this._dependencyManagerService.getOtherFormulaDependency(unitId, subUnitId, subFormulaDataId);
12479
- const firstFDtree = new FormulaDependencyTree((treeMatrix === null || treeMatrix === void 0 ? void 0 : treeMatrix.getValue(0, 0)) || generateRandomDependencyTreeId(this._dependencyManagerService));
12480
- for (let i = 0; i < ranges.length; i++) {
12481
- const range = ranges[i];
12482
- const { startRow, startColumn } = range;
12483
- let { endRow, endColumn } = range;
12484
- endRow = Math.min(endRow, rowCount - 1);
12485
- endColumn = Math.min(endColumn, columnCount - 1);
12486
- for (let r = startRow; r <= endRow; r++) for (let c = startColumn; c <= endColumn; c++) {
12487
- const x = c - firstColumn;
12488
- const y = r - firstRow;
12489
- if (x === 0 && y === 0) {
12490
- firstFDtree.node = node;
12491
- firstFDtree.formula = formulaString;
12492
- firstFDtree.unitId = unitId;
12493
- firstFDtree.subUnitId = subUnitId;
12494
- firstFDtree.formulaId = subFormulaDataId;
12495
- firstFDtree.type = 1;
12496
- firstFDtree.isCache = isCache;
12497
- treeList.push(firstFDtree);
12498
- this._dependencyManagerService.addOtherFormulaDependency(unitId, subUnitId, subFormulaDataId, firstFDtree);
12499
- this._dependencyManagerService.addFormulaDependencyByDefinedName(firstFDtree);
12500
- continue;
12501
- }
12502
- const virtual = new FormulaDependencyTreeVirtual();
12503
- virtual.treeId = (treeMatrix === null || treeMatrix === void 0 ? void 0 : treeMatrix.getValue(x, y)) || generateRandomDependencyTreeId(this._dependencyManagerService);
12504
- virtual.refTree = firstFDtree;
12505
- virtual.refOffsetX = x;
12506
- virtual.refOffsetY = y;
12507
- virtual.isCache = isCache;
12508
- virtual.type = 1;
12509
- this._dependencyManagerService.addOtherFormulaDependency(unitId, subUnitId, subFormulaDataId, virtual);
12510
- this._dependencyManagerService.addFormulaDependencyByDefinedName(virtual);
12511
- treeList.push(virtual);
12512
- }
12513
- }
12514
- this._dependencyManagerService.addOtherFormulaDependencyMainData(subFormulaDataId);
12515
- }
12516
- }
12517
- }
12518
- }
12519
13087
  _getFirstCellOfRange(ranges) {
12520
13088
  const range = ranges[0];
12521
13089
  return {
@@ -12523,72 +13091,6 @@ let FormulaDependencyGenerator = class FormulaDependencyGenerator extends _unive
12523
13091
  firstColumn: range.startColumn
12524
13092
  };
12525
13093
  }
12526
- _registerFormulas(formulaDataKeys, formulaData, unitData, treeList) {
12527
- /**
12528
- * Register formulas in the sheet.
12529
- */
12530
- for (const unitId of formulaDataKeys) {
12531
- const sheetData = formulaData[unitId];
12532
- if (sheetData == null) continue;
12533
- const sheetDataKeys = Object.keys(sheetData);
12534
- for (const sheetId of sheetDataKeys) {
12535
- const matrixData = new _univerjs_core.ObjectMatrix(sheetData[sheetId] || {});
12536
- const sIdCache = /* @__PURE__ */ new Map();
12537
- matrixData.forValue((row, column, formulaDataItem) => {
12538
- if (formulaDataItem == null) return true;
12539
- const { x = 0, y = 0, si } = formulaDataItem;
12540
- if (!(x === 0 && y === 0 && si != null)) return true;
12541
- const FDtree = this._createFDtree(unitId, sheetId, row, column, unitData, formulaDataItem);
12542
- const treeId = this._dependencyManagerService.getFormulaDependency(unitId, sheetId, row, column);
12543
- if (treeId != null) {
12544
- FDtree.treeId = treeId;
12545
- FDtree.isCache = true;
12546
- this._dependencyManagerService.updateDependencyTreeDirtyState(treeId, false);
12547
- } else {
12548
- this._dependencyManagerService.addFormulaDependency(unitId, sheetId, row, column, FDtree);
12549
- this._dependencyManagerService.addFormulaDependencyByDefinedName(FDtree);
12550
- }
12551
- sIdCache.set(si, FDtree);
12552
- treeList.push(FDtree);
12553
- });
12554
- matrixData.forValue((row, column, formulaDataItem) => {
12555
- if (formulaDataItem == null) return true;
12556
- const { x = 0, y = 0, si } = formulaDataItem;
12557
- if (x === 0 && y === 0 && si != null) return true;
12558
- let FDtree;
12559
- if (si && sIdCache.has(si)) {
12560
- const cache = sIdCache.get(si);
12561
- FDtree = this._createVirtualFDtree(cache, formulaDataItem);
12562
- } else FDtree = this._createFDtree(unitId, sheetId, row, column, unitData, formulaDataItem);
12563
- const treeId = this._dependencyManagerService.getFormulaDependency(unitId, sheetId, row, column);
12564
- if (treeId != null) {
12565
- FDtree.treeId = treeId;
12566
- FDtree.isCache = true;
12567
- this._dependencyManagerService.updateDependencyTreeDirtyState(treeId, false);
12568
- } else {
12569
- this._dependencyManagerService.addFormulaDependency(unitId, sheetId, row, column, FDtree);
12570
- this._dependencyManagerService.addFormulaDependencyByDefinedName(FDtree);
12571
- }
12572
- treeList.push(FDtree);
12573
- });
12574
- sIdCache.clear();
12575
- }
12576
- }
12577
- }
12578
- _createFDtree(unitId, sheetId, row, column, unitData, formulaDataItem) {
12579
- const { f: formulaString, x = 0, y = 0 } = formulaDataItem;
12580
- const FDtree = new FormulaDependencyTree(generateRandomDependencyTreeId(this._dependencyManagerService));
12581
- const sheetItem = unitData[unitId][sheetId];
12582
- FDtree.node = generateAstNode(unitId, formulaString, this._lexer, this._astTreeBuilder, this._currentConfigService);
12583
- FDtree.formula = formulaString;
12584
- FDtree.unitId = unitId;
12585
- FDtree.subUnitId = sheetId;
12586
- FDtree.row = row;
12587
- FDtree.column = column;
12588
- FDtree.rowCount = sheetItem.rowCount;
12589
- FDtree.columnCount = sheetItem.columnCount;
12590
- return FDtree;
12591
- }
12592
13094
  _createVirtualFDtree(tree, formulaDataItem) {
12593
13095
  const { x = 0, y = 0 } = formulaDataItem;
12594
13096
  const virtual = new FormulaDependencyTreeVirtual();
@@ -12698,9 +13200,6 @@ let FormulaDependencyGenerator = class FormulaDependencyGenerator extends _unive
12698
13200
  this._nodeTraversalReferenceFunction(node, referenceFunctionList);
12699
13201
  return referenceFunctionList;
12700
13202
  }
12701
- _getTreeNode(tree) {
12702
- return tree.node;
12703
- }
12704
13203
  async _buildDirtyRangesByAddressFunction(treeDependencyCache, tree) {
12705
13204
  const addressFunctionNodes = tree.addressFunctionNodes;
12706
13205
  if (addressFunctionNodes.length === 0) return;
@@ -12803,9 +13302,6 @@ let FormulaDependencyGenerator = class FormulaDependencyGenerator extends _unive
12803
13302
  if (newDirtyRanges.length > 0) this._searchDependencyByAddressFunction(treeDependencyCache, newDirtyRanges, searchResults);
12804
13303
  return searchResults;
12805
13304
  }
12806
- _getTreeById(treeId) {
12807
- return this._dependencyManagerService.getTreeById(treeId);
12808
- }
12809
13305
  _addDependencyTreeByAddressFunction(tree, addressFunctionRangeList) {
12810
13306
  const searchRanges = [];
12811
13307
  for (let i = 0; i < addressFunctionRangeList.length; i++) {
@@ -12834,33 +13330,6 @@ let FormulaDependencyGenerator = class FormulaDependencyGenerator extends _unive
12834
13330
  }
12835
13331
  return rangeList;
12836
13332
  }
12837
- /**
12838
- * Build a formula dependency tree based on the dependency relationships.
12839
- * @param treeList
12840
- */
12841
- _getUpdateTreeListAndMakeDependency(treeList) {
12842
- const newTreeList = [];
12843
- const existTree = /* @__PURE__ */ new Set();
12844
- const forceCalculate = this._currentConfigService.isForceCalculate();
12845
- const dirtyRanges = this._currentConfigService.getDirtyRanges();
12846
- const treeIds = this._dependencyManagerService.searchDependency(dirtyRanges);
12847
- const addressSearchResults = this._dependencyRTreeCacheForAddressFunction.bulkSearch(dirtyRanges);
12848
- for (const addressSearchResult of addressSearchResults) treeIds.add(addressSearchResult);
12849
- const allTree = this._dependencyManagerService.buildDependencyTree(treeList);
12850
- for (const tree of allTree) {
12851
- const treeId = tree.treeId;
12852
- /**
12853
- * forceCalculate: Mandatory calculation, adding all formulas to dependencies
12854
- * tree.dependencyRange: Formula dependent modification range
12855
- * includeTree: modification range contains formula
12856
- */
12857
- if ((forceCalculate || tree.isDirty || tree.dependencySheetName(this._currentConfigService.getDirtyNameMap()) || treeIds.has(treeId) && !tree.isExcludeRange(this._currentConfigService.getExcludedRange())) && !existTree.has(treeId)) {
12858
- newTreeList.push(tree);
12859
- existTree.add(treeId);
12860
- }
12861
- }
12862
- return newTreeList;
12863
- }
12864
13333
  _includeTreeFeature(tree) {
12865
13334
  const unitId = tree.unitId;
12866
13335
  const subUnitId = tree.subUnitId;
@@ -12932,63 +13401,12 @@ let FormulaDependencyGenerator = class FormulaDependencyGenerator extends _unive
12932
13401
  for (const range of ranges) if (tree.inRangeData(range)) return true;
12933
13402
  return false;
12934
13403
  }
12935
- /**
12936
- * Generate the final formula calculation order array by traversing the dependency tree established via depth-first search.
12937
- * @param treeList
12938
- */
12939
- _calculateRunList(treeList) {
12940
- treeList.length;
12941
- const stack = treeList;
12942
- const formulaRunList = [];
12943
- const cacheStack = [];
12944
- while (stack.length > 0) {
12945
- const tree = stack.pop();
12946
- if (tree === void 0 || tree.isSkip()) continue;
12947
- if (tree.isAdded()) {
12948
- formulaRunList.push(tree);
12949
- tree.setSkip();
12950
- continue;
12951
- }
12952
- cacheStack.length = 0;
12953
- for (const parentTreeId of tree.parents) {
12954
- const parentTree = this._dependencyManagerService.getTreeById(parentTreeId);
12955
- if (!parentTree) {
12956
- console.error("Dependency tree not found for treeId:", parentTreeId);
12957
- continue;
12958
- }
12959
- if (parentTree.isAdded() || tree.isSkip()) continue;
12960
- cacheStack.push(parentTree);
12961
- }
12962
- const addressSearchResults = this._dependencyRTreeCacheForAddressFunction.bulkSearch(tree.toRTreeItem());
12963
- for (const parentTreeId of addressSearchResults) {
12964
- const parentTree = this._dependencyManagerService.getTreeById(parentTreeId);
12965
- if (!parentTree) {
12966
- console.error("Dependency tree not found for treeId:", parentTreeId);
12967
- continue;
12968
- }
12969
- if (parentTree.isAdded() || tree.isSkip()) continue;
12970
- cacheStack.push(parentTree);
12971
- }
12972
- if (cacheStack.length === 0) {
12973
- formulaRunList.push(tree);
12974
- tree.setSkip();
12975
- } else {
12976
- tree.setAdded();
12977
- stack.push(tree, ...cacheStack);
12978
- }
12979
- }
12980
- return formulaRunList;
12981
- }
12982
13404
  async _initializeGenerateTreeList() {
12983
13405
  const formulaData = this._currentConfigService.getFormulaData();
12984
13406
  const otherFormulaData = this._otherFormulaManagerService.getOtherFormulaData();
12985
13407
  const unitData = this._currentConfigService.getUnitData();
12986
13408
  return await this._generateTreeList(formulaData, otherFormulaData, unitData);
12987
13409
  }
12988
- async _getAllTreeList() {
12989
- const treeList = await this._initializeGenerateTreeList();
12990
- return this._dependencyManagerService.buildDependencyTree(treeList);
12991
- }
12992
13410
  _getTreeModel(treeId) {
12993
13411
  let treeModel = this._formulaDependencyTreeModel.get(treeId);
12994
13412
  if (!treeModel) {
@@ -13002,12 +13420,6 @@ let FormulaDependencyGenerator = class FormulaDependencyGenerator extends _unive
13002
13420
  }
13003
13421
  return treeModel;
13004
13422
  }
13005
- _getDependencyTreeParenIds(tree) {
13006
- return tree.parents;
13007
- }
13008
- _getDependencyTreeChildrenIds(tree) {
13009
- return tree.children;
13010
- }
13011
13423
  _getFormulaDependencyTreeModel(tree) {
13012
13424
  const treeModel = this._getTreeModel(tree.treeId);
13013
13425
  const parentIds = this._getDependencyTreeParenIds(tree);
@@ -13020,10 +13432,6 @@ let FormulaDependencyGenerator = class FormulaDependencyGenerator extends _unive
13020
13432
  }
13021
13433
  return treeModel;
13022
13434
  }
13023
- _endFormulaDependencyTreeModel() {
13024
- this._formulaDependencyTreeModel.clear();
13025
- }
13026
- _startFormulaDependencyTreeModel() {}
13027
13435
  _getAllDependencyJson(treeList) {
13028
13436
  this._startFormulaDependencyTreeModel();
13029
13437
  const results = [];
@@ -13271,7 +13679,7 @@ let CalculateFormulaService = class CalculateFormulaService extends _univerjs_co
13271
13679
  if (isArrayFormulaState) this._runtimeService.setFormulaExecuteStage(5);
13272
13680
  else this._runtimeService.setFormulaExecuteStage(2);
13273
13681
  this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());
13274
- const treeList = (await this._formulaDependencyGenerator.generate(this._isCalculateTreeModel)).reverse();
13682
+ const treeList = await this._formulaDependencyGenerator.generate(this._isCalculateTreeModel);
13275
13683
  const interpreter = this._interpreter;
13276
13684
  if (isArrayFormulaState) {
13277
13685
  this._runtimeService.setFormulaExecuteStage(6);
@@ -13284,11 +13692,16 @@ let CalculateFormulaService = class CalculateFormulaService extends _univerjs_co
13284
13692
  let pendingTasks = [];
13285
13693
  const config = this._configService.getConfig(ENGINE_FORMULA_PLUGIN_CONFIG_KEY);
13286
13694
  const intervalCount = (config === null || config === void 0 ? void 0 : config.intervalCount) || 500;
13695
+ let i = 0;
13287
13696
  const treeCount = treeList.length;
13288
- for (let i = 0; i < treeCount; i++) {
13289
- var _nodeData$node;
13290
- const tree = treeList[i];
13291
- const nodeData = tree.nodeData;
13697
+ while (treeList.length > 0) {
13698
+ const tree = treeList.pop();
13699
+ const node = generateAstNode(tree.unitId, tree.formula, this._lexer, this._astTreeBuilder, this._currentConfigService);
13700
+ const nodeData = {
13701
+ node,
13702
+ refOffsetX: tree.refOffsetX,
13703
+ refOffsetY: tree.refOffsetY
13704
+ };
13292
13705
  const getDirtyData = tree.getDirtyData;
13293
13706
  if (i % intervalCount === 0) {
13294
13707
  /**
@@ -13330,7 +13743,8 @@ let CalculateFormulaService = class CalculateFormulaService extends _univerjs_co
13330
13743
  if (tree.formulaId != null) this._runtimeService.setRuntimeOtherData(tree.formulaId, tree.refOffsetX, tree.refOffsetY, value);
13331
13744
  else this._runtimeService.setRuntimeData(value);
13332
13745
  }
13333
- (_nodeData$node = nodeData.node) === null || _nodeData$node === void 0 || _nodeData$node.resetCalculationState();
13746
+ node.resetCalculationState();
13747
+ i++;
13334
13748
  }
13335
13749
  pendingTasks.forEach((cancel) => cancel());
13336
13750
  pendingTasks = [];
@@ -15843,13 +16257,26 @@ function isRowHidden(rowData, rowIndex) {
15843
16257
  if (!row) return false;
15844
16258
  return row.hd === _univerjs_core.BooleanNumber.TRUE;
15845
16259
  }
16260
+ const NESTED_AGGREGATE_FORMULA_CACHE = /* @__PURE__ */ new WeakMap();
15846
16261
  function isNestedAggregateOrSubtotal(cellData, rowIndex, columnIndex, sheetId, unitId, formulaDataModel) {
15847
16262
  const cellValue = cellData.getValue(rowIndex, columnIndex);
15848
- if ((cellValue === null || cellValue === void 0 ? void 0 : cellValue.f) || (cellValue === null || cellValue === void 0 ? void 0 : cellValue.si)) {
15849
- const formulaString = formulaDataModel.getFormulaStringByCell(rowIndex, columnIndex, sheetId, unitId);
15850
- if (formulaString && (formulaString.indexOf(`${"SUBTOTAL"}(`) > -1 || formulaString.indexOf(`${"AGGREGATE"}(`) > -1)) return true;
15851
- }
15852
- return false;
16263
+ if (!(cellValue === null || cellValue === void 0 ? void 0 : cellValue.f) && !(cellValue === null || cellValue === void 0 ? void 0 : cellValue.si)) return false;
16264
+ if (typeof cellValue.f === "string") return hasNestedAggregateFormula(cellValue.f);
16265
+ if (cellValue.si == null) return false;
16266
+ let cache = NESTED_AGGREGATE_FORMULA_CACHE.get(formulaDataModel);
16267
+ if (cache == null) {
16268
+ cache = /* @__PURE__ */ new Map();
16269
+ NESTED_AGGREGATE_FORMULA_CACHE.set(formulaDataModel, cache);
16270
+ }
16271
+ const cacheKey = `${unitId}\0${sheetId}\0${cellValue.si}`;
16272
+ const cached = cache.get(cacheKey);
16273
+ if (cached != null) return cached;
16274
+ const result = hasNestedAggregateFormula(formulaDataModel.getFormulaStringByCell(rowIndex, columnIndex, sheetId, unitId));
16275
+ cache.set(cacheKey, result);
16276
+ return result;
16277
+ }
16278
+ function hasNestedAggregateFormula(formulaString) {
16279
+ return !!formulaString && (formulaString.indexOf(`${"SUBTOTAL"}(`) > -1 || formulaString.indexOf(`${"AGGREGATE"}(`) > -1);
15853
16280
  }
15854
16281
  function getModeSnglResult(valueCountMap, valueMaxCount) {
15855
16282
  const result = Object.entries(valueCountMap).filter(([_, { count }]) => count === valueMaxCount).sort((a, b) => a[1].order - b[1].order).map(([value]) => +value);
@@ -15924,40 +16351,54 @@ function getAggregateResult(options, refs) {
15924
16351
  });
15925
16352
  if (errorValueObject === null || errorValueObject === void 0 ? void 0 : errorValueObject.isError()) return errorValueObject;
15926
16353
  }
16354
+ let result;
15927
16355
  switch (type) {
15928
16356
  case "AVERAGE":
15929
- if (n === 0) return ErrorValueObject.create("#DIV/0!");
15930
- return NumberValueObject.create(sum / n);
15931
- case "COUNT": return NumberValueObject.create(count);
15932
- case "COUNTA": return NumberValueObject.create(counta);
15933
- case "MAX": return NumberValueObject.create(max);
15934
- case "MIN": return NumberValueObject.create(min);
15935
- case "PRODUCT": return NumberValueObject.create(n === 0 ? 0 : product);
16357
+ result = n === 0 ? ErrorValueObject.create("#DIV/0!") : NumberValueObject.create(sum / n);
16358
+ break;
16359
+ case "COUNT":
16360
+ result = NumberValueObject.create(count);
16361
+ break;
16362
+ case "COUNTA":
16363
+ result = NumberValueObject.create(counta);
16364
+ break;
16365
+ case "MAX":
16366
+ result = NumberValueObject.create(max);
16367
+ break;
16368
+ case "MIN":
16369
+ result = NumberValueObject.create(min);
16370
+ break;
16371
+ case "PRODUCT":
16372
+ result = NumberValueObject.create(n === 0 ? 0 : product);
16373
+ break;
15936
16374
  case "STDEV":
15937
16375
  case "STDEV.S":
15938
- if (n < 2) return ErrorValueObject.create("#DIV/0!");
15939
- return createNewArray([valueObjects], 1, n).std(1);
16376
+ result = n < 2 ? ErrorValueObject.create("#DIV/0!") : createNewArray([valueObjects], 1, n).std(1);
16377
+ break;
15940
16378
  case "STDEVP":
15941
16379
  case "STDEV.P":
15942
- if (n === 0) return ErrorValueObject.create("#DIV/0!");
15943
- return createNewArray([valueObjects], 1, n).std();
15944
- case "SUM": return NumberValueObject.create(sum);
16380
+ result = n === 0 ? ErrorValueObject.create("#DIV/0!") : createNewArray([valueObjects], 1, n).std();
16381
+ break;
16382
+ case "SUM":
16383
+ result = NumberValueObject.create(sum);
16384
+ break;
15945
16385
  case "VAR":
15946
16386
  case "VAR.S":
15947
- if (n < 2) return ErrorValueObject.create("#DIV/0!");
15948
- return createNewArray([valueObjects], 1, n).var(1);
16387
+ result = n < 2 ? ErrorValueObject.create("#DIV/0!") : createNewArray([valueObjects], 1, n).var(1);
16388
+ break;
15949
16389
  case "VARP":
15950
16390
  case "VAR.P":
15951
- if (n === 0) return ErrorValueObject.create("#DIV/0!");
15952
- return createNewArray([valueObjects], 1, n).var();
16391
+ result = n === 0 ? ErrorValueObject.create("#DIV/0!") : createNewArray([valueObjects], 1, n).var();
16392
+ break;
15953
16393
  case "MEDIAN":
15954
- if (n === 0) return ErrorValueObject.create("#NUM!");
15955
- return getMedianResult(valueObjects.map((vo) => +vo.getValue()));
16394
+ result = n === 0 ? ErrorValueObject.create("#NUM!") : getMedianResult(valueObjects.map((vo) => +vo.getValue()));
16395
+ break;
15956
16396
  case "MODE.SNGL":
15957
- if (valueCountOrder === 0 || valueMaxCount === 1) return ErrorValueObject.create("#N/A");
15958
- return getModeSnglResult(valueCountMap, valueMaxCount);
15959
- default: return ErrorValueObject.create("#VALUE!");
16397
+ result = valueCountOrder === 0 || valueMaxCount === 1 ? ErrorValueObject.create("#N/A") : getModeSnglResult(valueCountMap, valueMaxCount);
16398
+ break;
16399
+ default: result = ErrorValueObject.create("#VALUE!");
15960
16400
  }
16401
+ return result;
15961
16402
  }
15962
16403
  function getArrayValuesByAggregateIgnoreOptions(array, options, formulaDataModel) {
15963
16404
  const { ignoreRowHidden = false, ignoreErrorValues = false, ignoreNested = false } = options !== null && options !== void 0 ? options : {};
@@ -39960,152 +40401,6 @@ const ALL_IMPLEMENTED_FUNCTIONS = [
39960
40401
  ];
39961
40402
  const ALL_IMPLEMENTED_FUNCTIONS_SET = new Set(ALL_IMPLEMENTED_FUNCTIONS.map(([_, name]) => name));
39962
40403
 
39963
- //#endregion
39964
- //#region src/functions/new-excel-functions.ts
39965
- const NEW_EXCEL_FUNCTIONS = new Set([
39966
- "ACOT",
39967
- "ACOTH",
39968
- "ARABIC",
39969
- "BASE",
39970
- "CEILING.MATH",
39971
- "CEILING.PRECISE",
39972
- "COMBINA",
39973
- "COT",
39974
- "COTH",
39975
- "CSC",
39976
- "CSCH",
39977
- "DECIMAL",
39978
- "FLOOR.MATH",
39979
- "FLOOR.PRECISE",
39980
- "MUNIT",
39981
- "RANDARRAY",
39982
- "SEC",
39983
- "SECH",
39984
- "SEQUENCE",
39985
- "CHOOSECOLS",
39986
- "CHOOSEROWS",
39987
- "DROP",
39988
- "EXPAND",
39989
- "FILTER",
39990
- "FORMULATEXT",
39991
- "HSTACK",
39992
- "SORT",
39993
- "SORTBY",
39994
- "TAKE",
39995
- "TOCOL",
39996
- "TOROW",
39997
- "UNIQUE",
39998
- "VSTACK",
39999
- "WRAPCOLS",
40000
- "WRAPROWS",
40001
- "XLOOKUP",
40002
- "XMATCH",
40003
- "BITAND",
40004
- "BITLSHIFT",
40005
- "BITOR",
40006
- "BITRSHIFT",
40007
- "BITXOR",
40008
- "ERF.PRECISE",
40009
- "ERFC.PRECISE",
40010
- "IMCOSH",
40011
- "IMCOT",
40012
- "IMCSC",
40013
- "IMCSCH",
40014
- "IMSEC",
40015
- "IMSECH",
40016
- "IMSINH",
40017
- "IMTAN",
40018
- "ISFORMULA",
40019
- "SHEET",
40020
- "SHEETS",
40021
- "IFNA",
40022
- "IFS",
40023
- "SWITCH",
40024
- "XOR",
40025
- "BETA.DIST",
40026
- "BETA.INV",
40027
- "BINOM.DIST",
40028
- "BINOM.DIST.RANGE",
40029
- "BINOM.INV",
40030
- "CHISQ.DIST",
40031
- "CHISQ.DIST.RT",
40032
- "CHISQ.INV",
40033
- "CHISQ.INV.RT",
40034
- "CHISQ.TEST",
40035
- "CONFIDENCE.NORM",
40036
- "CONFIDENCE.T",
40037
- "COVARIANCE.P",
40038
- "COVARIANCE.S",
40039
- "EXPON.DIST",
40040
- "F.DIST",
40041
- "F.DIST.RT",
40042
- "F.INV",
40043
- "F.INV.RT",
40044
- "F.TEST",
40045
- "FORECAST.LINEAR",
40046
- "GAMMA",
40047
- "GAMMA.DIST",
40048
- "GAMMA.INV",
40049
- "GAMMALN.PRECISE",
40050
- "GAUSS",
40051
- "HYPGEOM.DIST",
40052
- "LOGNORM.DIST",
40053
- "LOGNORM.INV",
40054
- "MAXIFS",
40055
- "MINIFS",
40056
- "MODE.MULT",
40057
- "MODE.SNGL",
40058
- "NEGBINOM.DIST",
40059
- "NORM.DIST",
40060
- "NORM.INV",
40061
- "NORM.S.DIST",
40062
- "NORM.S.INV",
40063
- "PERCENTILE.EXC",
40064
- "PERCENTILE.INC",
40065
- "PERCENTRANK.EXC",
40066
- "PERCENTRANK.INC",
40067
- "PERMUTATIONA",
40068
- "PHI",
40069
- "POISSON.DIST",
40070
- "QUARTILE.EXC",
40071
- "QUARTILE.INC",
40072
- "RANK.AVG",
40073
- "RANK.EQ",
40074
- "SKEW.P",
40075
- "STDEV.P",
40076
- "STDEV.S",
40077
- "T.DIST",
40078
- "T.DIST.2T",
40079
- "T.DIST.RT",
40080
- "T.INV",
40081
- "T.INV.2T",
40082
- "T.TEST",
40083
- "VAR.P",
40084
- "VAR.S",
40085
- "WEIBULL.DIST",
40086
- "Z.TEST",
40087
- "ARRAYTOTEXT",
40088
- "ENCODEURL",
40089
- "NUMBERVALUE",
40090
- "TEXTAFTER",
40091
- "TEXTBEFORE",
40092
- "TEXTJOIN",
40093
- "TEXTSPLIT",
40094
- "UNICHAR",
40095
- "UNICODE",
40096
- "VALUETOTEXT",
40097
- "DAYS",
40098
- "ISOWEEKNUM",
40099
- "PDURATION",
40100
- "RRI",
40101
- "BYCOL",
40102
- "BYROW",
40103
- "MAKEARRAY",
40104
- "MAP",
40105
- "REDUCE",
40106
- "SCAN"
40107
- ]);
40108
-
40109
40404
  //#endregion
40110
40405
  //#region src/functions/univer/function-names.ts
40111
40406
  /**
@@ -40152,7 +40447,7 @@ function getObjectValue(result, isUseStrip = false) {
40152
40447
  //#endregion
40153
40448
  //#region package.json
40154
40449
  var name = "@univerjs/engine-formula";
40155
- var version = "0.22.1";
40450
+ var version = "0.23.0";
40156
40451
 
40157
40452
  //#endregion
40158
40453
  //#region src/services/global-computing-status.service.ts
@@ -40551,6 +40846,7 @@ let RegisterOtherFormulaService = class RegisterOtherFormulaService extends _uni
40551
40846
  } }
40552
40847
  };
40553
40848
  this._commandService.executeCommand(SetOtherFormulaMutation.id, params, { onlyLocal: true }).then(() => {
40849
+ if (this._disposed) return;
40554
40850
  this._commandService.executeCommand(OtherFormulaMarkDirty.id, { [unitId]: { [subUnitId]: { [formulaId]: true } } }, { onlyLocal: true });
40555
40851
  });
40556
40852
  };
@@ -40738,6 +41034,7 @@ exports.BaseReferenceObject = BaseReferenceObject;
40738
41034
  exports.BaseValueObject = BaseValueObject;
40739
41035
  exports.BooleanValue = BooleanValue;
40740
41036
  exports.BooleanValueObject = BooleanValueObject;
41037
+ exports.CELL_INVERTED_INDEX_CACHE = CELL_INVERTED_INDEX_CACHE;
40741
41038
  Object.defineProperty(exports, 'CalculateController', {
40742
41039
  enumerable: true,
40743
41040
  get: function () {
@@ -40751,6 +41048,7 @@ Object.defineProperty(exports, 'CalculateFormulaService', {
40751
41048
  }
40752
41049
  });
40753
41050
  exports.CustomFunction = CustomFunction;
41051
+ exports.DEFAULT_CYCLE_REFERENCE_COUNT = DEFAULT_CYCLE_REFERENCE_COUNT;
40754
41052
  exports.DEFAULT_INTERVAL_COUNT = DEFAULT_INTERVAL_COUNT;
40755
41053
  exports.DEFAULT_TOKEN_LAMBDA_FUNCTION_NAME = DEFAULT_TOKEN_LAMBDA_FUNCTION_NAME;
40756
41054
  exports.DEFAULT_TOKEN_LET_FUNCTION_NAME = DEFAULT_TOKEN_LET_FUNCTION_NAME;
@@ -40771,6 +41069,7 @@ exports.ENGINE_FORMULA_RETURN_DEPENDENCY_TREE = ENGINE_FORMULA_RETURN_DEPENDENCY
40771
41069
  exports.ERROR_TYPE_SET = ERROR_TYPE_SET;
40772
41070
  exports.ErrorType = ErrorType;
40773
41071
  exports.ErrorValueObject = ErrorValueObject;
41072
+ exports.FORMULA_REF_TO_ARRAY_CACHE = FORMULA_REF_TO_ARRAY_CACHE;
40774
41073
  exports.FUNCTION_NAMES_ARRAY = FUNCTION_NAMES_ARRAY;
40775
41074
  exports.FUNCTION_NAMES_COMPATIBILITY = FUNCTION_NAMES_COMPATIBILITY;
40776
41075
  exports.FUNCTION_NAMES_CUBE = FUNCTION_NAMES_CUBE;