@univerjs/engine-formula 0.1.0-beta.1 → 0.1.0-beta.3
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/{LICENSE.txt → LICENSE} +0 -2
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +4156 -3484
- package/lib/types/basics/common.d.ts +28 -26
- package/lib/types/basics/error-type.d.ts +1 -1
- package/lib/types/basics/function.d.ts +5 -1
- package/lib/types/basics/inverted-index-cache.d.ts +2 -2
- package/lib/types/basics/regex.d.ts +9 -10
- package/lib/types/commands/mutations/register-function.mutation.d.ts +30 -0
- package/lib/types/commands/mutations/unregister-function.mutation.d.ts +30 -0
- package/lib/types/controller/formula.controller.d.ts +5 -1
- package/lib/types/controller/register-function.controller.d.ts +26 -0
- package/lib/types/engine/analysis/__tests__/create-command-test-bed.d.ts +4 -0
- package/lib/types/engine/analysis/__tests__/parser.spec.d.ts +16 -0
- package/lib/types/engine/analysis/lexer-tree-builder.d.ts +1 -0
- package/lib/types/engine/ast-node/function-node.d.ts +11 -2
- package/lib/types/engine/ast-node/lambda-node.d.ts +0 -2
- package/lib/types/engine/ast-node/lambda-parameter-node.d.ts +0 -1
- package/lib/types/engine/dependency/dependency-tree.d.ts +3 -1
- package/lib/types/engine/reference-object/base-reference-object.d.ts +19 -14
- package/lib/types/engine/reference-object/range-reference-object.d.ts +2 -2
- package/lib/types/engine/utils/__tests__/object-compare.spec.d.ts +16 -0
- package/lib/types/engine/utils/__tests__/r1c1-reference.spec.d.ts +16 -0
- package/lib/types/engine/utils/__tests__/reference.spec.d.ts +16 -0
- package/lib/types/engine/utils/compare.d.ts +4 -0
- package/lib/types/engine/utils/object-compare.d.ts +1 -2
- package/lib/types/engine/utils/r1c1-reference.d.ts +19 -0
- package/lib/types/engine/utils/reference.d.ts +80 -0
- package/lib/types/engine/value-object/array-value-object.d.ts +15 -11
- package/lib/types/engine/value-object/base-value-object.d.ts +20 -6
- package/lib/types/engine/value-object/primitive-object.d.ts +1 -1
- package/lib/types/functions/array/function-map.d.ts +1 -3
- package/lib/types/functions/array/function-names.d.ts +0 -1
- package/lib/types/functions/base-function.d.ts +37 -2
- package/lib/types/functions/compatibility/function-map.d.ts +1 -3
- package/lib/types/functions/compatibility/function-names.d.ts +38 -1
- package/lib/types/functions/cube/function-names.d.ts +7 -0
- package/lib/types/functions/database/function-names.d.ts +12 -0
- package/lib/types/functions/date/function-names.d.ts +25 -0
- package/lib/types/functions/engineering/function-names.d.ts +54 -0
- package/lib/types/functions/financial/function-names.d.ts +55 -0
- package/lib/types/functions/information/function-names.d.ts +21 -0
- package/lib/types/functions/logical/function-map.d.ts +3 -1
- package/lib/types/functions/logical/function-names.d.ts +19 -0
- package/lib/types/functions/logical/lambda/index.d.ts +24 -0
- package/lib/types/functions/logical/makearray/__test__/index.spec.d.ts +16 -0
- package/lib/types/functions/lookup/address/__tests__/index.spec.d.ts +16 -0
- package/lib/types/functions/lookup/address/index.d.ts +21 -0
- package/lib/types/functions/lookup/function-map.d.ts +4 -1
- package/lib/types/functions/lookup/function-names.d.ts +36 -1
- package/lib/types/functions/lookup/indirect/__test__/index.spec.d.ts +16 -0
- package/lib/types/functions/lookup/indirect/index.d.ts +4 -3
- package/lib/types/functions/lookup/vlookup/__tests__/index.spec.d.ts +16 -0
- package/lib/types/functions/lookup/vlookup/index.d.ts +21 -0
- package/lib/types/functions/math/function-names.d.ts +75 -1
- package/lib/types/functions/math/sum/index.d.ts +1 -1
- package/lib/types/functions/math/sumif/index.d.ts +2 -3
- package/lib/types/functions/meta/compare/index.d.ts +1 -2
- package/lib/types/functions/meta/divided/index.d.ts +1 -2
- package/lib/types/functions/meta/minus/index.d.ts +1 -2
- package/lib/types/functions/meta/multiply/index.d.ts +1 -2
- package/lib/types/functions/meta/plus/index.d.ts +2 -3
- package/lib/types/functions/statistical/function-names.d.ts +107 -1
- package/lib/types/functions/text/function-map.d.ts +3 -1
- package/lib/types/functions/text/function-names.d.ts +47 -0
- package/lib/types/functions/web/function-names.d.ts +3 -0
- package/lib/types/index.d.ts +21 -0
- package/lib/types/models/formula-data.model.d.ts +3 -1
- package/lib/types/plugin.d.ts +4 -0
- package/lib/types/services/current-data.service.d.ts +1 -0
- package/lib/types/services/feature-calculation-manager.service.d.ts +1 -1
- package/lib/types/services/function.service.d.ts +4 -0
- package/lib/types/services/other-formula-manager.service.d.ts +2 -2
- package/lib/types/services/runtime.service.d.ts +11 -5
- package/lib/umd/index.js +1 -1
- package/package.json +26 -23
- /package/lib/types/functions/{array → logical}/makearray/index.d.ts +0 -0
- /package/lib/types/functions/{compatibility → text}/concatenate/index.d.ts +0 -0
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(A,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","rxjs"],m):(A=typeof globalThis<"u"?globalThis:A||self,m(A.UniverEngineFormula={},A.UniverCore,A["@wendellhu/redi"],A.rxjs))})(this,function(A,m,D,dt){"use strict";var Bi=Object.defineProperty;var ki=(A,m,D)=>m in A?Bi(A,m,{enumerable:!0,configurable:!0,writable:!0,value:D}):A[m]=D;var g=(A,m,D)=>(ki(A,typeof m!="symbol"?m+"":m,D),D);function Gt(s,r,e,t,n){for(let i=0,a=s.length;i<a;i++){const o=s[i];if(r!==o.unitId||e!==o.sheetId)continue;const{startRow:u,startColumn:l,endRow:c,endColumn:f}=o.range;if(t>=u&&t<=c&&n>=l&&n<=f)return!0}return!1}var h=(s=>(s.DIV_BY_ZERO="#DIV/0!",s.NAME="#NAME!",s.VALUE="#VALUE!",s.NUM="#NUM!",s.NA="#N/A",s.CYCLE="#CYCLE!",s.REF="#REF!",s.SPILL="#SPILL!",s.CALC="#CALC!",s.ERROR="#ERROR!",s.CONNECT="#GETTING_DATA",s.NULL="#NULL!",s))(h||{});const Ur=new Set(["#DIV/0!","#NAME!","#VALUE!","#NUM!","#N/A","#CYCLE!","#REF!","#SPILL!","#CALC!","#ERROR!","#GETTING_DATA","#NULL!"]);var Ht=(s=>(s[s.Financial=0]="Financial",s[s.Date=1]="Date",s[s.Math=2]="Math",s[s.Statistical=3]="Statistical",s[s.Lookup=4]="Lookup",s[s.Database=5]="Database",s[s.Text=6]="Text",s[s.Logical=7]="Logical",s[s.Information=8]="Information",s[s.Engineering=9]="Engineering",s[s.Cube=10]="Cube",s[s.Compatibility=11]="Compatibility",s[s.Web=12]="Web",s[s.Array=13]="Array",s[s.Univer=14]="Univer",s))(Ht||{}),G=(s=>(s.PLUS="+",s.MINUS="-",s.MULTIPLY="*",s.DIVIDED="/",s.CONCATENATE="&",s.POWER="^",s.EQUALS="=",s.NOT_EQUAL="<>",s.GREATER_THAN=">",s.GREATER_THAN_OR_EQUAL=">=",s.LESS_THAN="<",s.LESS_THAN_OR_EQUAL="<=",s))(G||{}),S=(s=>(s.EQUALS="=",s.NOT_EQUAL="<>",s.GREATER_THAN=">",s.GREATER_THAN_OR_EQUAL=">=",s.LESS_THAN="<",s.LESS_THAN_OR_EQUAL="<=",s))(S||{});const Ve=new Map([["<>",3],["<",3],[">=",3],["=",3],[">",3],["<=",3],["&",2],["+",2],["-",2],["/",1],["*",1],["^",0]]),Ue=new Set(Ve.keys()),Ir=new Set(["=","<>",">",">=","<","<="]);var T=(s=>(s.OPEN_BRACKET="(",s.CLOSE_BRACKET=")",s.COMMA=",",s.SINGLE_QUOTATION="'",s.DOUBLE_QUOTATION='"',s.OPEN_BRACES="{",s.CLOSE_BRACES="}",s.COLON=":",s.OPEN_SQUARE_BRACKET="[",s.CLOSE_SQUARE_BRACKET="]",s))(T||{}),ie=(s=>(s.PERCENTAGE="%",s.POUND="#",s))(ie||{});const Mr=new Set(["%","#"]);var V=(s=>(s.AT="@",s.MINUS="-",s))(V||{});const Yt=[...Object.values(S),...Object.values(G),...Object.values(T),...Object.values(ie),...Object.values(V)];function mt(s){return Yt.includes(s)}function vr(s){for(const r of Yt)if(s.indexOf(r)>-1)return!0;return!1}function xr(s){return s[0]==="'"&&s[s.length-1]==="'"?s.substring(1,s.length-1):s}function qt(s){const r={};return Object.keys(s).forEach(e=>{const t=s[e];r[e]==null&&(r[e]={}),Object.keys(t).forEach(n=>{const i=t[n];r[e][n]=new m.ObjectMatrix(i)})}),r}class Be{constructor(r){g(this,"_cache");this._cache=new m.LRUMap(r)}set(r,e){const t=this._hash(r);this._cache.set(t,e)}get(r){const e=this._hash(r);return this._cache.get(e)}clear(){this._cache.clear()}_hash(r){return m.hashAlgorithm(r)}}const Se=`'?\\[((?![\\/?:"<>|*\\\\]).)*\\]`,ye="((?![\\[\\]\\/?*\\\\]).)*!",ae="$",gt="\\s*?:\\s*?",Ct=`\\${ae}?[A-Za-z]+\\${ae}?[0-9]+`,Pr=`^(${V.AT})?(${Se})?(${ye})?${Ct}${gt}${Ct}$`,Et=`^(${Se})?(${ye})?\\s*?${Ct}(${ie.POUND})?$`,Vr=`^(${Se})?(${ye})?\\${ae}?[0-9]+${gt}\\${ae}?[0-9]+$`,Br=`^(${Se})?(${ye})?\\${ae}?[A-Za-z]+${gt}\\${ae}?[A-Za-z]+$`,kr=`^(${Se})?(${ye})?\\s*?\\${ae}?[0-9]+$`,jr=`^(${Se})?(${ye})?\\s*?\\${ae}?[A-Za-z]+$`,zt="[.*?]",$r="{.*?}";function Qr(s){return new RegExp(Et).test(s)||new RegExp(Pr).test(s)||new RegExp(Vr).test(s)||new RegExp(Br).test(s)}const _e="P_1",oe="R_1",be="L_1",ke="LR_1",Kt="LO_1",Gr="LET",Ie="LAMBDA";var q=(s=>(s[s.NORMAL=0]="NORMAL",s[s.NUMBER=1]="NUMBER",s[s.STRING=2]="STRING",s[s.FUNCTION=3]="FUNCTION",s[s.REFERENCE=4]="REFERENCE",s[s.ARRAY=5]="ARRAY",s))(q||{});function Xt(s){let r="";for(const e of s)typeof e=="string"?r+=e:r+=e.token;return r}class L{constructor(){g(this,"_parent");g(this,"_token",oe);g(this,"_children",[]);g(this,"_lambdaId");g(this,"_functionDefinitionPrivacyVar");g(this,"_lambdaParameter","");g(this,"_startIndex",-1);g(this,"_endIndex",-1)}dispose(){var r;this._children.forEach(e=>{typeof e!="string"&&e.dispose()}),(r=this._functionDefinitionPrivacyVar)==null||r.clear(),this._parent=null}getStartIndex(){return this._startIndex}getLambdaId(){return this._lambdaId}setLambdaId(r){this._lambdaId=r}getFunctionDefinitionPrivacyVar(){return this._functionDefinitionPrivacyVar}setLambdaPrivacyVar(r){this._functionDefinitionPrivacyVar=r}getLambdaParameter(){return this._lambdaParameter}setLambdaParameter(r){this._lambdaParameter=r}getParent(){return this._parent}setParent(r){this._parent=r}getChildren(){return this._children}setChildren(r){this._children=r}addChildren(r){this._children.push(r)}addChildrenFirst(r){this._children.unshift(r)}getToken(){return this._token}setToken(r){this._token=r}setIndex(r,e){this._startIndex=r,this._endIndex=e}replaceChild(r,e){const t=this._getIndexInParent(r);t!=null&&(this.getChildren().splice(t,1,e),e.setParent(this))}changeToParent(r){const e=this.getParent();e&&e.removeChild(this),this.setParent(r),r.getChildren().push(this)}removeChild(r){const e=this._getIndexInParent(r);e!=null&&this.getChildren().splice(e,1)}serialize(){const r=this.getToken(),e=this.getChildren(),t=[],n=e.length;for(let i=0;i<n;i++){const a=e[i];a instanceof L?t.push(a.serialize()):t.push(a)}return{token:r,st:this._startIndex,ed:this._endIndex,children:t}}_getIndexInParent(r){const e=this.getChildren(),t=e.length;for(let n=0;n<t;n++)if(e[n]===r)return n}}const Wt=1e5,pt=new Be(Wt),Nt=new Be(Wt);class je extends m.Disposable{constructor(){super(...arguments);g(this,"_currentLexerNode",new L);g(this,"_upLevel",0);g(this,"_segment","");g(this,"_bracketState",[]);g(this,"_squareBracketState",0);g(this,"_bracesState",0);g(this,"_singleQuotationState",0);g(this,"_doubleQuotationState",0);g(this,"_lambdaState",!1);g(this,"_colonState",!1);g(this,"_tableBracketState",!1)}dispose(){this._resetTemp(),this._currentLexerNode.dispose(),pt.clear(),Nt.clear()}getUpLevel(){return this._upLevel}isColonClose(){return this._colonState===!1}isColonOpen(){return this._colonState===!0}isDoubleQuotationClose(){return this._doubleQuotationState===0}isLambdaOpen(){return this._lambdaState===!0}isLambdaClose(){return this._lambdaState===!1}isSingleQuotationClose(){return this._singleQuotationState===0}isBracesClose(){return this._bracesState===0}isBracketClose(){return this._bracketState.length===0}isSquareBracketClose(){return this._squareBracketState===0}getCurrentLexerNode(){return this._currentLexerNode}getFunctionAndParameter(e,t){const n=this._getCurrentParamIndex(e,t);if(n==null||n===h.VALUE)return;const i=n[0];if(typeof i=="string")return;let a=i.getParent(),o=i;for(;a;){const u=a.getToken();if(u!==_e&&!mt(u)&&a.getStartIndex()!==-1){const l=a.getChildren().indexOf(o);return{functionName:u,paramIndex:l}}o=a,a=a.getParent()}}moveFormulaRefOffset(e,t,n){const i=this.sequenceNodesBuilder(e);if(i==null)return e;const a=[];for(let o=0,u=i.length;o<u;o++){const l=i[o];if(typeof l=="string"||l.nodeType!==q.REFERENCE){a.push(l);continue}const{token:c}=l,f=m.deserializeRangeWithSheet(c),{range:d,sheetName:p,unitId:R}=f,C=m.Rectangle.moveOffset(d,t,n);let N="";m.isValidRange(C)?N=m.serializeRangeToRefString({range:C,unitId:R,sheetName:p}):N=h.REF,a.push({...l,token:N})}return`=${Xt(a)}`}checkIfAddBracket(e){let t=0,n=e.length-1,i=e[n];for(;(i===T.CLOSE_BRACKET||i===" ")&&n>=0;)i===T.CLOSE_BRACKET&&t++,i=e[--n];const a=this._getCurrentParamIndex(e,e.length-2);if(a==null||a===h.VALUE)return 0;const o=a[0];if(typeof o=="string")return 0;let u=o.getParent(),l=0;for(;u;){const c=u.getToken();c!==_e&&c!==T.COLON&&u.getStartIndex()!==-1&&c.toUpperCase()!==Ie&&(t===0?l+=1:t--),u=u.getParent()}return l}sequenceNodesBuilder(e){const t=Nt.get(e);if(t)return[...t];const n=this._getSequenceArray(e);if(n.length===0)return;const i=this.getSequenceNode(n);return Nt.set(e,[...i]),i}getSequenceNode(e){const t=[];let n=!1;for(let i=0,a=e.length;i<a;i++){const o=e[i],u=e[i-1],{segment:l,currentString:c,cur:f}=o;if(c===T.DOUBLE_QUOTATION&&(n=!0),(l!==""||i===0)&&i!==a-1){t.push(c);continue}let d=(u==null?void 0:u.segment)||"";const p=i-d.length;let R=i-1;const C=i-1;if(i===a-1&&this._isLastMergeString(c)&&(d+=c,R+=1),d===""||Ve.has(d)){t.push(c);continue}const N=d.trim(),y=this._replacePrefixString(N);n===!0&&N[N.length-1]===T.DOUBLE_QUOTATION?(n=!1,this._pushSequenceNode(t,{nodeType:q.STRING,token:d,startIndex:p,endIndex:R},C)):new RegExp(Et).test(y)?this._pushSequenceNode(t,{nodeType:q.REFERENCE,token:d,startIndex:p,endIndex:R},C):m.Tools.isStringNumber(N)?this._pushSequenceNode(t,{nodeType:q.NUMBER,token:d,startIndex:p,endIndex:R},C):N.length>0&&this._pushSequenceNode(t,{nodeType:q.FUNCTION,token:d,startIndex:p,endIndex:R},C),(i!==a-1||!this._isLastMergeString(c))&&t.push(c)}return this._mergeSequenceNodeReference(t)}_getCurrentParamIndex(e,t){return this._nodeMaker(e,void 0,t)}_isLastMergeString(e){return e===T.DOUBLE_QUOTATION||m.Tools.isStringNumber(e)||!mt(e)}_mergeSequenceNodeReference(e){const t=[],n=e.length;let i=0;for(;i<n;){const a=e[i];if(typeof a=="string"){const o=e[i-1];if(a.trim()===T.CLOSE_BRACES&&o!=null&&typeof o!="string"&&o.nodeType===q.FUNCTION&&o.token.trim().substring(0,1)===T.OPEN_BRACES){o.nodeType=q.ARRAY,o.token+=a,o.endIndex+=a.length,i++;continue}t.push(a)}else{const o=e[i+1],u=e[i+2];o===T.COLON&&typeof a!="string"&&u!=null&&typeof u!="string"&&Qr((a.token+o+u.token).trim())&&(a.nodeType=q.REFERENCE,a.token+=o+u.token,a.endIndex=u.endIndex,i+=2),t.push(a)}i++}return t}_pushSequenceNode(e,t,n){const i=n-t.startIndex+1;e.splice(e.length-i,i,t)}_replacePrefixString(e){return e.replace(new RegExp(V.AT,"g"),"").replace(new RegExp(V.MINUS,"g"),"")}nodeMakerTest(e){return this._nodeMaker(e)}treeBuilder(e,t=!0,n){if(t===!0){const c=pt.get(e);if(c)return c}this._resetCurrentLexerNode(),this._currentLexerNode.setToken(oe);const i=[];let a=this._nodeMaker(e,i);if(a===h.VALUE||i.length===0)return a;let o=!1,u="";if(n){const{hasDefinedName:c,sequenceString:f}=n(i);o=c,u=f}if(o&&(this._resetCurrentLexerNode(),this._currentLexerNode.setToken(oe),a=this._nodeMaker(`=${u}`),a===h.VALUE))return a;const l=this._getTopNode(this._currentLexerNode);return l&&(this._currentLexerNode=l),t&&(this._suffixExpressionHandler(this._currentLexerNode),pt.set(e,this._currentLexerNode)),this._currentLexerNode}_suffixExpressionHandler(e){var o,u;const t=e.getChildren();if(!t)return;const n=t.length,i=[],a=[];for(let l=0;l<n;l++){const c=t[l];if(c instanceof L)this._suffixExpressionHandler(c),i.push(c);else{const f=c.trim();if(f==="")continue;if(Ue.has(f)){for(;a.length>0;){const d=(o=a[a.length-1])==null?void 0:o.trim();if(!d||d===T.OPEN_BRACKET)break;const p=Ve.get(d),R=Ve.get(f);if(!p||!R)break;if(R>p)i.push(a.pop());else break}a.push(c)}else if(f===T.OPEN_BRACKET)a.push(c);else if(f===T.CLOSE_BRACKET)for(;a.length>0;){const d=(u=a[a.length-1])==null?void 0:u.trim();if(!d)break;if(d===T.OPEN_BRACKET){a.pop();break}i.push(a.pop())}else i.push(c)}}for(;a.length>0;)i.push(a.pop());e.setChildren(i)}_resetCurrentLexerNode(){this._currentLexerNode=new L}_resetSegment(){this._segment=""}_openBracket(e=0){this._bracketState.push(e)}_closeBracket(){this._bracketState.pop()}_openSquareBracket(){this._squareBracketState+=1}_closeSquareBracket(){this._squareBracketState-=1}_getCurrentBracket(){const e=this._bracketState;return e[e.length-1]}_openBraces(){this._bracesState+=1}_closeBraces(){this._bracesState-=1}_openSingleQuotation(){this._singleQuotationState+=1}_closeSingleQuotation(){this._singleQuotationState-=1}_openDoubleQuotation(){this._doubleQuotationState+=1}_closeDoubleQuotation(){this._doubleQuotationState-=1}_openLambda(){this._lambdaState=!0}_closeLambda(){this._lambdaState=!1}_openColon(e){this._upLevel=e,this._colonState=!0}_closeColon(){this._upLevel=0,this._colonState=!1}_isTableBracket(){return this._tableBracketState}_openTableBracket(){this._tableBracketState=!0}_closeTableBracket(){this._tableBracketState=!1}_getLastChildCurrentLexerNode(){const e=this._currentLexerNode.getChildren();if(e&&e.length>0){const t=e[e.length-1];if(t instanceof L)return t}return!1}_getLastChildCurrent(){const e=this._currentLexerNode.getChildren();return e&&e.length>0?e[e.length-1]:!1}_setParentCurrentLexerNode(){const e=this._currentLexerNode.getParent();return e?(this._currentLexerNode=e,!0):!1}_setAncestorCurrentLexerNode(){var n,i,a,o,u,l;const e=(n=this._currentLexerNode)==null?void 0:n.getParent();let t=!1;if(e&&e.getToken()===be){if((i=e==null?void 0:e.getParent())!=null&&i.getParent()){const c=(o=(a=this._currentLexerNode.getParent())==null?void 0:a.getParent())==null?void 0:o.getParent();c&&(this._currentLexerNode=c),t=!0}}else if(e!=null&&e.getParent()){const c=(u=this._currentLexerNode.getParent())==null?void 0:u.getParent();c&&(this._currentLexerNode=c),t=!0}for(let c=0;c<this._upLevel;c++){const f=(l=this._currentLexerNode)==null?void 0:l.getParent();f&&(this._currentLexerNode=f),this._currentLexerNode?t=!0:t=!1}return t}_segmentCount(){return this._segment.trim().length}_pushSegment(e){this._segment+=e}_pushNodeToChildren(e,t=!1){if(e!==""){const n=this._currentLexerNode.getChildren();if(!(e instanceof L)&&this.isColonOpen()){const i=new L;i.setToken(e),i.setParent(this._currentLexerNode),e=i}t?n.unshift(e):n.push(e)}this.isColonOpen()&&(this._setAncestorCurrentLexerNode(),this._closeColon())}_setCurrentLexerNode(e,t=!1){this._pushNodeToChildren(e,t),e.setParent(this._currentLexerNode),this._currentLexerNode=e}_newAndPushCurrentLexerNode(e,t,n=!1){const i=new L;i.setToken(e),i.setIndex(t-e.length,t-1),this._setCurrentLexerNode(i,n)}_getTopNode(e){let t=e;for(;t!=null&&t.getParent();)t=t.getParent();return t}_removeLastChild(){this._currentLexerNode.getChildren().splice(-1)}_findPreviousToken(e,t){for(;t>=0;){const n=e[t];if(n!==" ")return n;t--}}_negativeCondition(e){return!!(Ue.has(e)||e===T.OPEN_BRACKET||e===T.COMMA||e==="")}_getSequenceArray(e){const t=[];return this._nodeMaker(e,t),t}_resetTemp(){this._currentLexerNode=new L,this._upLevel=0,this._segment="",this._bracketState=[],this._bracesState=0,this._singleQuotationState=0,this._doubleQuotationState=0,this._lambdaState=!1,this._colonState=!1}_nodeMaker(e,t,n){e.substring(0,1)===G.EQUALS&&(e=e.substring(1));const i=e.split(""),a=i.length;let o=0;for(this._resetTemp();o<a;){const u=i[o];if(n===o)return[this._currentLexerNode,u];if(u===T.OPEN_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())if(this._segmentCount()>0||this.isLambdaOpen()){this.isLambdaClose()&&(this._newAndPushCurrentLexerNode(this._segment,o),this._resetSegment()),this._openBracket(1),this._closeLambda();const l=i[o+1];if(l&&l===T.CLOSE_BRACKET){if(!this._setParentCurrentLexerNode()&&o!==a-1)return h.VALUE;o++}else l&&this._newAndPushCurrentLexerNode(_e,o)}else this._pushNodeToChildren(u),this._openBracket(0);else if(u===T.CLOSE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()){this._pushNodeToChildren(this._segment),this._resetSegment();const l=this._getCurrentBracket();if(l===0)this._pushNodeToChildren(u);else if(l===1){const c=i[o+1];if(c&&c===T.OPEN_BRACKET){if(!this._setParentCurrentLexerNode()&&o!==a-1)return h.VALUE;this._newAndPushCurrentLexerNode(be,o,!0),this._openLambda()}else if(!this._setAncestorCurrentLexerNode()&&o!==a-1)return h.VALUE}else return h.VALUE;this._closeBracket()}else if(u===T.OPEN_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(u),this._openBraces();else if(u===T.CLOSE_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(u),this._pushNodeToChildren(this._segment),this._resetSegment(),this._closeBraces();else if(u===T.OPEN_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._segment.length>0&&this._openTableBracket(),this._pushSegment(u),this._openSquareBracket();else if(u===T.CLOSE_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._closeSquareBracket(),this.isSquareBracketClose()?(this._pushSegment(u),this._isTableBracket()&&(this._pushNodeToChildren(this._segment),this._resetSegment()),this._closeTableBracket()):this._pushSegment(u);else if(u===T.DOUBLE_QUOTATION&&this.isSingleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){if(this.isDoubleQuotationClose())this._openDoubleQuotation();else{const l=i[o+1];l&&l===T.DOUBLE_QUOTATION?o++:this._closeDoubleQuotation()}this._pushSegment(u)}else if(u===T.SINGLE_QUOTATION&&this.isDoubleQuotationClose()){if(this.isSingleQuotationClose())this._openSingleQuotation();else{const l=i[o+1];l&&l===T.SINGLE_QUOTATION?o++:this._closeSingleQuotation()}this._pushSegment(u)}else if(u===T.COMMA&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=this._getCurrentBracket();if(l===1||l==null){if(this._pushNodeToChildren(this._segment),this._resetSegment(),!this._setParentCurrentLexerNode()&&o!==a-1&&l!=null)return h.VALUE;this._newAndPushCurrentLexerNode(_e,o)}else return h.VALUE}else if(u===T.COLON&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=new L;l.setToken(u);const c=new L;c.setToken(_e),c.setParent(l);const f=new L;f.setToken(_e),f.setParent(l),l.getChildren().push(c,f);let d=l,p=0;if(this._segmentCount()>0){let R,C,N=0;const y=this._segment.trim(),b=y[0],U=y[1];if(b===V.MINUS&&(R=new L,R.setToken(V.MINUS),N++),(b===V.AT||U===V.AT)&&(C=new L,C.setToken(V.AT),R&&(R.addChildren(C),C.setParent(R)),N++),N>0&&(this._segment=y.slice(N)),p=N,C)if(C.addChildren(l),l.setParent(C),C.getParent()){const Y=C.getParent();Y&&(d=Y)}else d=C;else R&&(d=R,R.addChildren(l),l.setParent(R));const F=new L;F.setToken(this._segment),F.setParent(c),c.getChildren().push(F),this._resetSegment()}else{const R=this._getLastChildCurrentLexerNode();R&&R.changeToParent(c)}this._setCurrentLexerNode(d),this._currentLexerNode=f,this._openColon(p)}else if(Mr.has(u)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){this._pushNodeToChildren(this._segment);const l=new L;l.setToken(u);const c=this._getLastChildCurrent();c instanceof L?c.changeToParent(l):c!==!1&&(l.getChildren().push(c),this._removeLastChild()),this._pushNodeToChildren(l),l.setParent(this._currentLexerNode),this._resetSegment()}else if(Ue.has(u)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){let l=this._segment.trim();if(u===G.MINUS&&l===""){const c=this._findPreviousToken(i,o-1)||"";if(this._negativeCondition(c)){this._pushSegment(G.MINUS),t==null||t.push({segment:this._segment,currentString:u,cur:o,currentLexerNode:this._currentLexerNode}),o++;continue}}else this._segment.length>0&&l===""?l=this._segment:(this._pushNodeToChildren(this._segment),l="");if(u===G.LESS_THAN||u===G.GREATER_THAN){const c=i[o+1];c&&Ue.has(u+c)?(this._pushNodeToChildren(l+u+c),o++):this._pushNodeToChildren(l+u)}else this._pushNodeToChildren(l+u);this._resetSegment()}else this._pushSegment(u);t==null||t.push({segment:this._segment,currentString:u,cur:o,currentLexerNode:this._currentLexerNode}),o++}this._pushNodeToChildren(this._segment)}}var Hr=Object.defineProperty,Yr=Object.getOwnPropertyDescriptor,qr=(s,r,e,t)=>{for(var n=t>1?void 0:t?Yr(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Hr(r,e,n),n},Zt=(s,r)=>(e,t)=>r(e,t,s);A.FormulaDataModel=class extends m.Disposable{constructor(e,t){super();g(this,"_formulaData",{});g(this,"_arrayFormulaRange",{});g(this,"_arrayFormulaCellData",{});this._currentUniverService=e,this._lexerTreeBuilder=t}clearPreviousArrayFormulaCellData(e){Object.keys(e).forEach(t=>{const n=e[t];Object.keys(n).forEach(i=>{var l,c;const a=n[i],o=(c=(l=this._arrayFormulaRange)==null?void 0:l[t])==null?void 0:c[i];if(o==null)return!0;let u=new m.ObjectMatrix;this._arrayFormulaCellData[t][i]!=null&&(u=new m.ObjectMatrix(this._arrayFormulaCellData[t][i])),a.forValue((f,d)=>{var b;const p=(b=o==null?void 0:o[f])==null?void 0:b[d];if(p==null)return!0;const{startRow:R,startColumn:C,endRow:N,endColumn:y}=p;for(let U=R;U<=N;U++)for(let F=C;F<=y;F++)u.setValue(U,F,null)}),this._arrayFormulaCellData[t][i]=u.getData()})})}mergeArrayFormulaCellData(e){Object.keys(e).forEach(t=>{const n=e[t];this._arrayFormulaRange[t]==null&&(this._arrayFormulaRange[t]={}),this._arrayFormulaCellData[t]==null&&(this._arrayFormulaCellData[t]={}),Object.keys(n).forEach(i=>{const a=n[i];let o=new m.ObjectMatrix,u=new m.ObjectMatrix;this._arrayFormulaRange[t][i]!=null&&(o=new m.ObjectMatrix(this._arrayFormulaRange[t][i])),this._arrayFormulaCellData[t][i]!=null&&(u=new m.ObjectMatrix(this._arrayFormulaCellData[t][i])),a.forValue((l,c)=>{const f=o==null?void 0:o.getValue(l,c);if(f==null)return!0;const{startRow:d,startColumn:p,endRow:R,endColumn:C}=f;for(let N=d;N<=R;N++)for(let y=p;y<=C;y++)u.setValue(N,y,null)}),a.forValue((l,c,f)=>{u.setValue(l,c,f)}),this._arrayFormulaCellData[t][i]=u.getData()})})}getFormulaData(){return this._formulaData}setFormulaData(e){this._formulaData=e}setArrayFormulaRange(e){this._arrayFormulaRange=e}getArrayFormulaRange(){return this._arrayFormulaRange}setArrayFormulaCellData(e){this._arrayFormulaCellData=e}getArrayFormulaCellData(){return this._arrayFormulaCellData}mergeArrayFormulaRange(e){Object.keys(e).forEach(t=>{const n=e[t];this._arrayFormulaRange[t]||(this._arrayFormulaRange[t]={}),Object.keys(n).forEach(i=>{const a=new m.ObjectMatrix(n[i]);let o=new m.ObjectMatrix;this._arrayFormulaRange[t][i]&&(o=new m.ObjectMatrix(this._arrayFormulaRange[t][i])),a.forValue((u,l,c)=>{o.setValue(u,l,c)}),this._arrayFormulaRange[t][i]=o.getData()})})}deleteArrayFormulaRange(e,t,n,i){var u;const a=(u=this._arrayFormulaRange[e])==null?void 0:u[t];if(a==null)return;const o=new m.ObjectMatrix(a);o.getValue(n,i)&&(o.realDeleteValue(n,i),this._arrayFormulaRange[e][t]=o.getData())}initFormulaData(){this._currentUniverService.getAllUniverSheetsInstance();const e=this._currentUniverService.getCurrentUniverSheetInstance(),t=e.getUnitId();this._formulaData[t]={},e.getSheets().forEach(i=>{const a=i.getCellMatrix(),o=i.getSheetId();Jt(this._formulaData,t,o,a)})}getCalculateData(){const e=this._currentUniverService.getAllUniverSheetsInstance(),t={},n={};for(const i of e){const a=i.getUnitId(),o=i.getSheets(),u={},l={};for(const c of o){const f=c.getSheetId(),d=c.getConfig();u[f]={cellData:new m.ObjectMatrix(d.cellData),rowCount:d.rowCount,columnCount:d.columnCount},l[c.getName()]=c.getSheetId()}t[a]=u,n[a]=l}return{allUnitData:t,unitSheetNameMap:n}}updateFormulaData(e,t,n){const i=new m.ObjectMatrix(n),a=this.getFormulaIdMap(e,t),o=new Map,u=this._formulaData;u[e]==null&&(u[e]={});const l=u[e];l[t]==null&&(l[t]={});const c=new m.ObjectMatrix(l[t]);i.forValue((f,d,p)=>{const R=(p==null?void 0:p.f)||"",C=(p==null?void 0:p.si)||"",N=m.isFormulaString(R),y=m.isFormulaId(C);if(N&&y)c.setValue(f,d,{f:R,si:C}),a.set(C,{f:R,r:f,c:d});else if(N&&!y)c.setValue(f,d,{f:R});else if(!N&&y)c.setValue(f,d,{f:"",si:C});else if(!N&&!y&&c.getValue(f,d)){const b=c.getValue(f,d),U=(b==null?void 0:b.f)||"",F=(b==null?void 0:b.si)||"";m.isFormulaString(U)&&m.isFormulaId(F)&&o.set(F,U),c.realDeleteValue(f,d)}}),c.forValue((f,d,p)=>{const R=(p==null?void 0:p.f)||"",C=(p==null?void 0:p.si)||"";if(m.isFormulaId(C)){const N=a.get(C),y=o.get(C);if(N&&!m.isFormulaString(R)){const b=N.f,U=d-N.c,F=f-N.r;c.setValue(f,d,{f:b,si:C,x:U,y:F})}else if(typeof y=="string"){const b=p.x||0,U=p.y||0,F=this._lexerTreeBuilder.moveFormulaRefOffset(y,b,U);o.set(C,{r:f,c:d,f:F}),c.setValue(f,d,{f:F,si:C})}else if(typeof y=="object"){const b=d-y.c,U=f-y.r;c.setValue(f,d,{f:y.f,si:C,x:b,y:U})}}})}getFormulaItemBySId(e,t,n){const i=this._formulaData;if(i[n]==null)return null;const a=i[n];if(a[t]==null)return null;const o=new m.ObjectMatrix(a[t]);let u=null;return o.forValue((l,c,f)=>{const{f:d,si:p,x:R=0,y:C=0}=f;if(p===e&&d.length>0&&R===0&&C===0)return u=f,!1}),u}getFormulaDataItem(e,t,n,i){var a,o,u,l;return(l=(u=(o=(a=this._formulaData)==null?void 0:a[i])==null?void 0:o[n])==null?void 0:u[e])==null?void 0:l[t]}getFormulaIdMap(e,t){const n=new Map,i=this._formulaData;if(i[e]==null)return n;const a=i[e];return a[t]==null||new m.ObjectMatrix(a[t]).forValue((u,l,c)=>{const f=(c==null?void 0:c.f)||"",d=(c==null?void 0:c.si)||"",p=(c==null?void 0:c.x)||0,R=(c==null?void 0:c.y)||0;m.isFormulaString(f)&&m.isFormulaId(d)&&p===0&&R===0&&n.set(d,{f,r:u,c:l})}),n}},A.FormulaDataModel=qr([Zt(0,m.IUniverInstanceService),Zt(1,D.Inject(je))],A.FormulaDataModel);function Jt(s,r,e,t){const n=new Map,i=new m.ObjectMatrix;t.forValue((a,o,u)=>{const l=(u==null?void 0:u.f)||"",c=(u==null?void 0:u.si)||"",f=m.isFormulaString(l),d=m.isFormulaId(c);f&&d?(i.setValue(a,o,{f:l,si:c}),n.set(c,{f:l,r:a,c:o})):f&&!d?i.setValue(a,o,{f:l}):!f&&d&&i.setValue(a,o,{f:"",si:c})}),i.forValue((a,o,u)=>{const l=(u==null?void 0:u.f)||"",c=(u==null?void 0:u.si)||"";if(m.isFormulaId(c)&&!m.isFormulaString(l)){const f=n.get(c);if(f){const d=f.f,p=o-f.c,R=a-f.r;i.setValue(a,o,{f:d,si:c,x:p,y:R})}}}),s[r][e]=i.getData()}const zr=s=>{const r=s.get(A.FormulaDataModel),e=m.Tools.deepClone(r.getArrayFormulaRange()),t=m.Tools.deepClone(r.getArrayFormulaCellData());return{arrayFormulaRange:e,arrayFormulaCellData:t}},$e={id:"formula.mutation.set-array-formula-data",type:m.CommandType.MUTATION,handler:(s,r)=>{const e=s.get(A.FormulaDataModel);return e.setArrayFormulaRange(r.arrayFormulaRange),e.setArrayFormulaCellData(r.arrayFormulaCellData),!0}},Qe={id:"formula.mutation.set-defined-name",type:m.CommandType.MUTATION,handler:()=>!0},Ge={id:"formula.mutation.remove-defined-name",type:m.CommandType.MUTATION,handler:()=>!0},At={id:"formula.mutation.set-feature-calculation",type:m.CommandType.MUTATION,handler:()=>!0},Rt={id:"formula.mutation.remove-feature-calculation",type:m.CommandType.MUTATION,handler:()=>!0},St={id:"formula.mutation.set-formula-calculation-start",type:m.CommandType.MUTATION,handler:()=>!0},yt={id:"formula.mutation.set-formula-calculation-stop",type:m.CommandType.MUTATION,handler:()=>!0},He={id:"formula.mutation.set-formula-calculation-notification",type:m.CommandType.MUTATION,handler:()=>!0},bt={id:"formula.mutation.set-formula-calculation-result",type:m.CommandType.MUTATION,handler:()=>!0},Dt={id:"formula.mutation.set-formula-data",type:m.CommandType.MUTATION,handler:(s,r)=>(s.get(A.FormulaDataModel).setFormulaData(r.formulaData),!0)},Ft={id:"formula.mutation.set-other-formula",type:m.CommandType.MUTATION,handler:()=>!0},Lt={id:"formula.mutation.remove-other-formula",type:m.CommandType.MUTATION,handler:()=>!0},er={id:"formula.mutation.set-super-table",type:m.CommandType.MUTATION,handler:()=>!0},tr={id:"formula.mutation.remove-super-table",type:m.CommandType.MUTATION,handler:()=>!0},wt={id:"formula.mutation.set-super-table-option",type:m.CommandType.MUTATION,handler:()=>!0};class Ye extends m.Disposable{isError(){return!1}isAsyncObject(){return!1}isAsyncArrayObject(){return!1}isReferenceObject(){return!1}isValueObject(){return!1}isEqualType(r){return!1}}var de=(s=>(s.FALSE="FALSE",s.TRUE="TRUE",s))(de||{}),ue=(s=>(s[s.SUCCESS=0]="SUCCESS",s[s.ERROR=1]="ERROR",s))(ue||{}),me=(s=>(s.ALL="#All",s.DATA="#Data",s.HEADERS="#Headers",s.TOTALS="#Totals",s))(me||{}),K=(s=>(s[s.FRONT=0]="FRONT",s[s.BACK=1]="BACK",s))(K||{});class Kr{constructor(){g(this,"_cache",new Map);g(this,"_continueBuildingCache",new Map)}set(r,e,t,n,i){if(!this.shouldContinueBuildingCache(r,e,t,i))return;let a=this._cache.get(r);a==null&&(a=new Map,this._cache.set(r,a));let o=a.get(e);o==null&&(o=new Map,a.set(e,o));let u=o.get(t);u==null&&(u=new Map,o.set(t,u));let l=u.get(n);l==null&&(l=[],u.set(n,l)),l.push(i)}getCellValuePositions(r,e,t){var n,i;return(i=(n=this._cache.get(r))==null?void 0:n.get(e))==null?void 0:i.get(t)}getCellPositions(r,e,t,n){var i,a,o;return(o=(a=(i=this._cache.get(r))==null?void 0:i.get(e))==null?void 0:a.get(t))==null?void 0:o.get(n)}getCellPosition(r,e,t,n,i,a){const o=this.getCellPositions(r,e,t,n);if(o!=null){for(const u of o)if(u>=i&&u<=a)return u}}setContinueBuildingCache(r,e,t,n,i){let a=this._continueBuildingCache.get(r);a==null&&(a=new Map,this._continueBuildingCache.set(r,a));let o=a.get(e);o==null&&(o=new Map,a.set(e,o));let u=o.get(t);if(u==null){u={startRow:n,endRow:i},o.set(t,u);return}u.startRow=Math.min(u.startRow,n),u.endRow=Math.max(u.endRow,i)}shouldContinueBuildingCache(r,e,t,n){var u,l;const i=(l=(u=this._continueBuildingCache.get(r))==null?void 0:u.get(e))==null?void 0:l.get(t);if(i==null)return!0;const{startRow:a,endRow:o}=i;return!(n>=a&&n<=o)}canUseCache(r,e,t,n,i){var l,c;const a=(c=(l=this._continueBuildingCache.get(r))==null?void 0:l.get(e))==null?void 0:c.get(t);if(a==null)return!1;const{startRow:o,endRow:u}=a;return!(n>u||i<o)}clear(){this._cache.clear(),this._continueBuildingCache.clear()}}const ge=new Kr;function Xr(){return new Intl.Collator(void 0,{numeric:!0}).compare}function Wr(s){return s.indexOf("*")>-1||s.indexOf("?")>-1}function rr(s,r){const e=r.replace(/~?[*?]/g,n=>n.startsWith("~")?`\\${n.substring(1)}`:n==="*"?".*":n==="?"?".":n);return new RegExp(`^${e}$`).test(s)}function nr(s){return s.replace(/~?[*?]/g,r=>r.startsWith("~")?r.substring(1):" ")}function Zr(s,r,e){let t=!1;switch(e){case S.EQUALS:t=rr(s,r);break;case S.GREATER_THAN:case S.GREATER_THAN_OR_EQUAL:t=rr(s,r)||s>nr(r);break;case S.LESS_THAN:case S.LESS_THAN_OR_EQUAL:t=s<nr(r);break}return t}class le extends Ye{constructor(r){super(),this._rawValue=r}isValueObject(){return!0}getValue(){return 0}getArrayValue(){return[]}setValue(r){}setArrayValue(r){}isArray(){return!1}isString(){return!1}isNumber(){return!1}isBoolean(){return!1}isLambda(){return!1}isError(){return!1}isNull(){return!1}getNegative(){return _.create(h.NAME)}getReciprocal(){return _.create(h.NAME)}plus(r){return _.create(h.NAME)}minus(r){return _.create(h.NAME)}multiply(r){return _.create(h.NAME)}divided(r){return _.create(h.NAME)}map(r){return _.create(h.NAME)}product(r,e){return e(this,r)}compare(r,e){return _.create(h.NAME)}wildcard(r,e){return _.create(h.NAME)}isEqual(r){return this.compare(r,S.EQUALS)}isNotEqual(r){return this.compare(r,S.NOT_EQUAL)}isGreaterThanOrEqual(r){return this.compare(r,S.GREATER_THAN_OR_EQUAL)}isLessThanOrEqual(r){return this.compare(r,S.LESS_THAN_OR_EQUAL)}isLessThan(r){return this.compare(r,S.LESS_THAN)}isGreaterThan(r){return this.compare(r,S.GREATER_THAN)}concatenateFront(r){return _.create(h.NAME)}concatenateBack(r){return _.create(h.NAME)}plusBy(r){return _.create(h.NAME)}minusBy(r){return _.create(h.NAME)}multiplyBy(r){return _.create(h.NAME)}dividedBy(r){return _.create(h.NAME)}compareBy(r,e){return _.create(h.NAME)}concatenate(r,e=K.FRONT){let t=this.getValue().toString();if(typeof r=="string")e===K.FRONT?t=r+t:t+=r;else if(typeof r=="number")e===K.FRONT?t=r.toString()+t:t+=r.toString();else if(typeof r=="boolean"){const n=r?"TRUE":"FALSE";e===K.FRONT?t=n+t:t+=n}return t}pow(r){return _.create(h.VALUE)}powInverse(r){return _.create(h.VALUE)}sqrt(){return _.create(h.VALUE)}cbrt(){return _.create(h.VALUE)}cos(){return _.create(h.VALUE)}acos(){return _.create(h.VALUE)}acosh(){return _.create(h.VALUE)}sin(){return _.create(h.VALUE)}asin(){return _.create(h.VALUE)}asinh(){return _.create(h.VALUE)}tan(){return _.create(h.VALUE)}tanh(){return _.create(h.VALUE)}atan(){return _.create(h.VALUE)}atan2(r){return _.create(h.VALUE)}atan2Inverse(r){return _.create(h.VALUE)}atanh(){return _.create(h.VALUE)}mean(){return this}median(){return this}var(){return this}std(){return this}log(){return _.create(h.VALUE)}log10(){return _.create(h.VALUE)}exp(){return _.create(h.VALUE)}abs(){return _.create(h.VALUE)}round(r){return _.create(h.VALUE)}roundInverse(r){return _.create(h.VALUE)}floor(r){return _.create(h.VALUE)}floorInverse(r){return _.create(h.VALUE)}ceil(r){return _.create(h.VALUE)}ceilInverse(r){return _.create(h.VALUE)}}class _ extends le{constructor(r,e=""){super(r),this._errorType=r,this._errorContent=e}static create(r,e){return new _(r,e)}getErrorType(){return this._errorType}getErrorContent(){return this._errorContent}isEqualType(r){return r.getErrorType()===this.getErrorType()}isError(){return!0}}var Jr=20,en=1,Ce=1e6,sr=1e6,tn=-7,rn=21,nn=!1,Me="[big.js] ",Ee=Me+"Invalid ",qe=Ee+"decimal places",sn=Ee+"rounding mode",ir=Me+"Division by zero",O={},Z=void 0,an=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function ar(){function s(r){var e=this;if(!(e instanceof s))return r===Z?ar():new s(r);if(r instanceof s)e.s=r.s,e.e=r.e,e.c=r.c.slice();else{if(typeof r!="string"){if(s.strict===!0&&typeof r!="bigint")throw TypeError(Ee+"value");r=r===0&&1/r<0?"-0":String(r)}on(e,r)}e.constructor=s}return s.prototype=O,s.DP=Jr,s.RM=en,s.NE=tn,s.PE=rn,s.strict=nn,s.roundDown=0,s.roundHalfUp=1,s.roundHalfEven=2,s.roundUp=3,s}function on(s,r){var e,t,n;if(!an.test(r))throw Error(Ee+"number");for(s.s=r.charAt(0)=="-"?(r=r.slice(1),-1):1,(e=r.indexOf("."))>-1&&(r=r.replace(".","")),(t=r.search(/e/i))>0?(e<0&&(e=t),e+=+r.slice(t+1),r=r.substring(0,t)):e<0&&(e=r.length),n=r.length,t=0;t<n&&r.charAt(t)=="0";)++t;if(t==n)s.c=[s.e=0];else{for(;n>0&&r.charAt(--n)=="0";);for(s.e=e-t-1,s.c=[],e=0;t<=n;)s.c[e++]=+r.charAt(t++)}return s}function pe(s,r,e,t){var n=s.c;if(e===Z&&(e=s.constructor.RM),e!==0&&e!==1&&e!==2&&e!==3)throw Error(sn);if(r<1)t=e===3&&(t||!!n[0])||r===0&&(e===1&&n[0]>=5||e===2&&(n[0]>5||n[0]===5&&(t||n[1]!==Z))),n.length=1,t?(s.e=s.e-r+1,n[0]=1):n[0]=s.e=0;else if(r<n.length){if(t=e===1&&n[r]>=5||e===2&&(n[r]>5||n[r]===5&&(t||n[r+1]!==Z||n[r-1]&1))||e===3&&(t||!!n[0]),n.length=r,t){for(;++n[--r]>9;)if(n[r]=0,r===0){++s.e,n.unshift(1);break}}for(r=n.length;!n[--r];)n.pop()}return s}function De(s,r,e){var t=s.e,n=s.c.join(""),i=n.length;if(r)n=n.charAt(0)+(i>1?"."+n.slice(1):"")+(t<0?"e":"e+")+t;else if(t<0){for(;++t;)n="0"+n;n="0."+n}else if(t>0)if(++t>i)for(t-=i;t--;)n+="0";else t<i&&(n=n.slice(0,t)+"."+n.slice(t));else i>1&&(n=n.charAt(0)+"."+n.slice(1));return s.s<0&&e?"-"+n:n}O.abs=function(){var s=new this.constructor(this);return s.s=1,s},O.cmp=function(s){var r,e=this,t=e.c,n=(s=new e.constructor(s)).c,i=e.s,a=s.s,o=e.e,u=s.e;if(!t[0]||!n[0])return t[0]?i:n[0]?-a:0;if(i!=a)return i;if(r=i<0,o!=u)return o>u^r?1:-1;for(a=(o=t.length)<(u=n.length)?o:u,i=-1;++i<a;)if(t[i]!=n[i])return t[i]>n[i]^r?1:-1;return o==u?0:o>u^r?1:-1},O.div=function(s){var r=this,e=r.constructor,t=r.c,n=(s=new e(s)).c,i=r.s==s.s?1:-1,a=e.DP;if(a!==~~a||a<0||a>Ce)throw Error(qe);if(!n[0])throw Error(ir);if(!t[0])return s.s=i,s.c=[s.e=0],s;var o,u,l,c,f,d=n.slice(),p=o=n.length,R=t.length,C=t.slice(0,o),N=C.length,y=s,b=y.c=[],U=0,F=a+(y.e=r.e-s.e)+1;for(y.s=i,i=F<0?0:F,d.unshift(0);N++<o;)C.push(0);do{for(l=0;l<10;l++){if(o!=(N=C.length))c=o>N?1:-1;else for(f=-1,c=0;++f<o;)if(n[f]!=C[f]){c=n[f]>C[f]?1:-1;break}if(c<0){for(u=N==o?n:d;N;){if(C[--N]<u[N]){for(f=N;f&&!C[--f];)C[f]=9;--C[f],C[N]+=10}C[N]-=u[N]}for(;!C[0];)C.shift()}else break}b[U++]=c?l:++l,C[0]&&c?C[N]=t[p]||0:C=[t[p]]}while((p++<R||C[0]!==Z)&&i--);return!b[0]&&U!=1&&(b.shift(),y.e--,F--),U>F&&pe(y,F,e.RM,C[0]!==Z),y},O.eq=function(s){return this.cmp(s)===0},O.gt=function(s){return this.cmp(s)>0},O.gte=function(s){return this.cmp(s)>-1},O.lt=function(s){return this.cmp(s)<0},O.lte=function(s){return this.cmp(s)<1},O.minus=O.sub=function(s){var r,e,t,n,i=this,a=i.constructor,o=i.s,u=(s=new a(s)).s;if(o!=u)return s.s=-u,i.plus(s);var l=i.c.slice(),c=i.e,f=s.c,d=s.e;if(!l[0]||!f[0])return f[0]?s.s=-u:l[0]?s=new a(i):s.s=1,s;if(o=c-d){for((n=o<0)?(o=-o,t=l):(d=c,t=f),t.reverse(),u=o;u--;)t.push(0);t.reverse()}else for(e=((n=l.length<f.length)?l:f).length,o=u=0;u<e;u++)if(l[u]!=f[u]){n=l[u]<f[u];break}if(n&&(t=l,l=f,f=t,s.s=-s.s),(u=(e=f.length)-(r=l.length))>0)for(;u--;)l[r++]=0;for(u=r;e>o;){if(l[--e]<f[e]){for(r=e;r&&!l[--r];)l[r]=9;--l[r],l[e]+=10}l[e]-=f[e]}for(;l[--u]===0;)l.pop();for(;l[0]===0;)l.shift(),--d;return l[0]||(s.s=1,l=[d=0]),s.c=l,s.e=d,s},O.mod=function(s){var r,e=this,t=e.constructor,n=e.s,i=(s=new t(s)).s;if(!s.c[0])throw Error(ir);return e.s=s.s=1,r=s.cmp(e)==1,e.s=n,s.s=i,r?new t(e):(n=t.DP,i=t.RM,t.DP=t.RM=0,e=e.div(s),t.DP=n,t.RM=i,this.minus(e.times(s)))},O.neg=function(){var s=new this.constructor(this);return s.s=-s.s,s},O.plus=O.add=function(s){var r,e,t,n=this,i=n.constructor;if(s=new i(s),n.s!=s.s)return s.s=-s.s,n.minus(s);var a=n.e,o=n.c,u=s.e,l=s.c;if(!o[0]||!l[0])return l[0]||(o[0]?s=new i(n):s.s=n.s),s;if(o=o.slice(),r=a-u){for(r>0?(u=a,t=l):(r=-r,t=o),t.reverse();r--;)t.push(0);t.reverse()}for(o.length-l.length<0&&(t=l,l=o,o=t),r=l.length,e=0;r;o[r]%=10)e=(o[--r]=o[r]+l[r]+e)/10|0;for(e&&(o.unshift(e),++u),r=o.length;o[--r]===0;)o.pop();return s.c=o,s.e=u,s},O.pow=function(s){var r=this,e=new r.constructor("1"),t=e,n=s<0;if(s!==~~s||s<-sr||s>sr)throw Error(Ee+"exponent");for(n&&(s=-s);s&1&&(t=t.times(r)),s>>=1,!!s;)r=r.times(r);return n?e.div(t):t},O.prec=function(s,r){if(s!==~~s||s<1||s>Ce)throw Error(Ee+"precision");return pe(new this.constructor(this),s,r)},O.round=function(s,r){if(s===Z)s=0;else if(s!==~~s||s<-Ce||s>Ce)throw Error(qe);return pe(new this.constructor(this),s+this.e+1,r)},O.sqrt=function(){var s,r,e,t=this,n=t.constructor,i=t.s,a=t.e,o=new n("0.5");if(!t.c[0])return new n(t);if(i<0)throw Error(Me+"No square root");i=Math.sqrt(t+""),i===0||i===1/0?(r=t.c.join(""),r.length+a&1||(r+="0"),i=Math.sqrt(r),a=((a+1)/2|0)-(a<0||a&1),s=new n((i==1/0?"5e":(i=i.toExponential()).slice(0,i.indexOf("e")+1))+a)):s=new n(i+""),a=s.e+(n.DP+=4);do e=s,s=o.times(e.plus(t.div(e)));while(e.c.slice(0,a).join("")!==s.c.slice(0,a).join(""));return pe(s,(n.DP-=4)+s.e+1,n.RM)},O.times=O.mul=function(s){var r,e=this,t=e.constructor,n=e.c,i=(s=new t(s)).c,a=n.length,o=i.length,u=e.e,l=s.e;if(s.s=e.s==s.s?1:-1,!n[0]||!i[0])return s.c=[s.e=0],s;for(s.e=u+l,a<o&&(r=n,n=i,i=r,l=a,a=o,o=l),r=new Array(l=a+o);l--;)r[l]=0;for(u=o;u--;){for(o=0,l=a+u;l>u;)o=r[l]+i[u]*n[l-u-1]+o,r[l--]=o%10,o=o/10|0;r[l]=o}for(o?++s.e:r.shift(),u=r.length;!r[--u];)r.pop();return s.c=r,s},O.toExponential=function(s,r){var e=this,t=e.c[0];if(s!==Z){if(s!==~~s||s<0||s>Ce)throw Error(qe);for(e=pe(new e.constructor(e),++s,r);e.c.length<s;)e.c.push(0)}return De(e,!0,!!t)},O.toFixed=function(s,r){var e=this,t=e.c[0];if(s!==Z){if(s!==~~s||s<0||s>Ce)throw Error(qe);for(e=pe(new e.constructor(e),s+e.e+1,r),s=s+e.e+1;e.c.length<s;)e.c.push(0)}return De(e,!1,!!t)},O[Symbol.for("nodejs.util.inspect.custom")]=O.toJSON=O.toString=function(){var s=this,r=s.constructor;return De(s,s.e<=r.NE||s.e>=r.PE,!!s.c[0])},O.toNumber=function(){var s=Number(De(this,!0,!0));if(this.constructor.strict===!0&&!this.eq(s.toString()))throw Error(Me+"Imprecise conversion");return s},O.toPrecision=function(s,r){var e=this,t=e.constructor,n=e.c[0];if(s!==Z){if(s!==~~s||s<1||s>Ce)throw Error(Ee+"precision");for(e=pe(new t(e),s,r);e.c.length<s;)e.c.push(0)}return De(e,s<=e.e||e.e<=t.NE||e.e>=t.PE,!!n)},O.valueOf=function(){var s=this,r=s.constructor;if(r.strict===!0)throw Error(Me+"valueOf disallowed");return De(s,s.e<=r.NE||s.e>=r.PE,!0)};var k=ar();function Tt(s){let r;switch(s){case S.EQUALS:r=S.EQUALS;break;case S.GREATER_THAN:r=S.LESS_THAN;break;case S.GREATER_THAN_OR_EQUAL:r=S.LESS_THAN_OR_EQUAL;break;case S.LESS_THAN:r=S.GREATER_THAN;break;case S.LESS_THAN_OR_EQUAL:r=S.GREATER_THAN_OR_EQUAL;break;case S.NOT_EQUAL:r=S.NOT_EQUAL;break}return r}function Ot(s,r){return k(s).times(r).toNumber()}function or(s,r){const e=10**Math.floor(r);return Math.round(Ot(s,e))/e}function ur(s,r){const e=10**Math.floor(r);return Math.floor(Ot(s,e))/e}function lr(s,r){const e=10**Math.floor(r);return Math.ceil(Ot(s,e))/e}function cr(s,r){return s**r}class hr extends le{isNull(){return!0}plus(r){return new E(0,!0).plus(r)}minus(r){return new E(0,!0).minus(r)}multiply(r){return new E(0,!0).multiply(r)}divided(r){return new E(0,!0).divided(r)}compare(r,e){return r.isString()?new j("").compare(r,e):r.isBoolean()?new Q(!1).compare(r,e):new E(0,!0).compare(r,e)}concatenateFront(r){return r.isArray()?r.concatenateBack(new j("")):new j(this.concatenate(r.getValue(),K.FRONT))}concatenateBack(r){return r.isArray()?r.concatenateFront(new j("")):new j(this.concatenate(r.getValue(),K.BACK))}plusBy(r){return new E(0).plusBy(r)}minusBy(r){return new E(0).minusBy(r)}multiplyBy(r){return new E(0).multiplyBy(r)}dividedBy(r){return new E(0).dividedBy(r)}compareBy(r,e){return typeof r=="string"?new j("").compareBy(r,e):typeof r=="boolean"?new Q(!1).compareBy(r,e):new E(0,!0).compareBy(r,e)}pow(r){return new E(0,!0).pow(r)}sqrt(){return new E(0,!0)}cbrt(){return new E(0,!0)}cos(){return new E(0,!0)}acos(){return new E(0,!0)}acosh(){return new E(0,!0)}sin(){return new E(0,!0)}asin(){return new E(0,!0)}asinh(){return new E(0,!0)}tan(){return new E(0,!0)}tanh(){return new E(0,!0)}atan(){return new E(0,!0)}atan2(r){return new E(0,!0).atan2(r)}atanh(){return new E(0,!0)}log(){return _.create(h.NUM)}log10(){return _.create(h.NUM)}exp(){return _.create(h.NUM)}abs(){return _.create(h.NUM)}round(r){return new E(0,!0).round(r)}floor(r){return new E(0,!0).floor(r)}ceil(r){return new E(0,!0).ceil(r)}}class Q extends le{constructor(e,t=!1){super(e);g(this,"_value",!1);if(t){this._value=e;return}if(typeof e=="boolean")this._value=e;else if(typeof e=="string"){const n=e.toLocaleUpperCase();n===de.TRUE?this._value=!0:n===de.FALSE&&(this._value=!1)}else e===1?this._value=!0:this._value=!1}getValue(){return this._value}isBoolean(){return!0}getNegative(){const e=this.getValue();let t=0;return e&&(t=1),new E(-t,!0)}getReciprocal(){return this.getValue()?new E(1,!0):_.create(h.DIV_BY_ZERO)}plus(e){return this._convertTonNumber().plus(e)}minus(e){return this._convertTonNumber().minus(e)}multiply(e){return this._convertTonNumber().multiply(e)}divided(e){return this._convertTonNumber().divided(e)}compare(e,t){return this._convertTonNumber().compare(e,t)}concatenateFront(e){return this._convertTonNumber().concatenateFront(e)}concatenateBack(e){return this._convertTonNumber().concatenateBack(e)}_convertTonNumber(){const e=this.getValue();let t=0;return e&&(t=1),new E(t,!0)}pow(e){return this._convertTonNumber().pow(e)}sqrt(){return this._convertTonNumber()}cbrt(){return this._convertTonNumber()}cos(){return this._convertTonNumber().cos()}acos(){return this._convertTonNumber().acos()}acosh(){return this._convertTonNumber().acosh()}sin(){return this._convertTonNumber().sin()}asin(){return this._convertTonNumber().asin()}asinh(){return this._convertTonNumber().asinh()}tan(){return this._convertTonNumber().tan()}tanh(){return this._convertTonNumber().tanh()}atan(){return this._convertTonNumber().atan()}atan2(e){return this._convertTonNumber().atan2(e)}atanh(){return this._convertTonNumber().atanh()}log(){return this._convertTonNumber().log()}log10(){return this._convertTonNumber().log10()}exp(){return this._convertTonNumber().exp()}abs(){return this._convertTonNumber().abs()}round(e){return this._convertTonNumber().round(e)}floor(e){return this._convertTonNumber().floor(e)}ceil(e){return this._convertTonNumber().ceil(e)}}class E extends le{constructor(e,t=!1){super(e);g(this,"_value",0);if(t){this._value=e;return}this._value=Number(e)}getValue(){return this._value}setValue(e){this._value=e}isNumber(){return!0}getNegative(){return new E(0).minus(this)}getReciprocal(){return new E(1).divided(this)}plus(e){if(e.isArray())return e.plus(this);const t=this.plusBy(e.getValue());return t.isError()?this:t}equalZero(){return this._value===0}minus(e){if(e.isArray()){const n=e.getNegative();return n.isError()?n:n.plus(this)}const t=this.minusBy(e.getValue());return t.isError()?this:t}multiply(e){return e.isArray()?e.multiply(this):this.multiplyBy(e.getValue())}divided(e){if(e.isArray()){const t=e.getReciprocal();return t.isError()?t:t.multiply(this)}return this.dividedBy(e.getValue())}concatenateFront(e){return e.isArray()?e.concatenateBack(this):new j(this.concatenate(e.getValue(),K.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new j(this.concatenate(e.getValue(),K.BACK))}compare(e,t){return e.isArray()?e.compare(this,Tt(t)):this.compareBy(e.getValue(),t)}plusBy(e){const t=this.getValue();if(typeof e=="string")return _.create(h.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return _.create(h.NUM);const n=k(t).plus(e).toNumber();return Number.isFinite(n)?new E(n):_.create(h.NUM)}return typeof e=="boolean"?new E(k(t).plus(e?1:0).toNumber()):this}minusBy(e){const t=this.getValue();if(typeof e=="string")return _.create(h.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return _.create(h.NUM);const n=k(t).minus(e).toNumber();return Number.isFinite(n)?new E(n):_.create(h.NUM)}return typeof e=="boolean"?new E(k(t).minus(e?1:0).toNumber()):this}multiplyBy(e){const t=this.getValue();if(typeof e=="string")return _.create(h.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return _.create(h.NUM);const n=k(t).times(e).toNumber();return Number.isFinite(n)?new E(n):_.create(h.NUM)}return typeof e=="boolean"?new E(k(t).times(e?1:0).toNumber()):this}dividedBy(e){const t=this.getValue();if(typeof e=="string")return _.create(h.VALUE);if(typeof e=="number"){if(e===0)return _.create(h.DIV_BY_ZERO);if(!Number.isFinite(t)||!Number.isFinite(e))return _.create(h.NUM);const n=k(t).div(e).toNumber();return Number.isFinite(n)?new E(n):_.create(h.NUM)}return typeof e=="boolean"?e===!1?_.create(h.DIV_BY_ZERO):new E(k(t).div(1).toNumber()):this}compareBy(e,t){const n=this.getValue();let i=!1;if(typeof e=="string")switch(t){case S.EQUALS:case S.GREATER_THAN:case S.GREATER_THAN_OR_EQUAL:i=!1;break;case S.LESS_THAN:case S.LESS_THAN_OR_EQUAL:case S.NOT_EQUAL:i=!0;break}else if(typeof e=="number")if(!Number.isFinite(n)||!Number.isFinite(e))i=this._compareInfinity(n,e,t);else switch(t){case S.EQUALS:i=k(n).eq(e);break;case S.GREATER_THAN:i=k(n).gt(e);break;case S.GREATER_THAN_OR_EQUAL:i=k(n).gte(e);break;case S.LESS_THAN:i=k(n).lt(e);break;case S.LESS_THAN_OR_EQUAL:i=k(n).lte(e);break;case S.NOT_EQUAL:i=!k(n).eq(e);break}else if(typeof e=="boolean")switch(t){case S.EQUALS:case S.GREATER_THAN:case S.GREATER_THAN_OR_EQUAL:i=!1;break;case S.LESS_THAN:case S.LESS_THAN_OR_EQUAL:case S.NOT_EQUAL:i=!0;break}return new Q(i)}pow(e){if(e.isArray())return e.powInverse(this);const t=this.getValue(),n=e.getValue();if(typeof n=="string")return _.create(h.VALUE);if(typeof n=="number"){if(!Number.isFinite(t)||!Number.isFinite(n))return _.create(h.NUM);const i=cr(t,n);return Number.isFinite(i)?new E(i):_.create(h.NUM)}return typeof n=="boolean"?new E(cr(t,n?1:0)):this}sqrt(){const e=this.getValue();if(!Number.isFinite(e))return _.create(h.NUM);const t=k(e).sqrt().toNumber();return Number.isFinite(t)?new E(t):_.create(h.NUM)}cbrt(){const e=this.getValue();if(!Number.isFinite(e))return _.create(h.NUM);const t=Math.cbrt(e);return Number.isFinite(t)?new E(t):_.create(h.NUM)}cos(){const e=this.getValue();if(!Number.isFinite(e))return _.create(h.NUM);const t=Math.cos(e);return Number.isFinite(t)?new E(t):_.create(h.NUM)}acos(){const e=this.getValue();if(!Number.isFinite(e))return _.create(h.NUM);const t=Math.acos(e);return Number.isNaN(t)?_.create(h.NUM):new E(t)}acosh(){const e=this.getValue();if(!Number.isFinite(e))return _.create(h.NUM);const t=Math.acosh(e);return Number.isNaN(t)?_.create(h.NUM):new E(t)}sin(){const e=this.getValue();if(!Number.isFinite(e))return _.create(h.NUM);const t=Math.sin(e);return Number.isFinite(t)?new E(t):_.create(h.NUM)}asin(){const e=this.getValue();if(!Number.isFinite(e))return _.create(h.NUM);const t=Math.asin(e);return Number.isNaN(t)?_.create(h.NUM):new E(t)}asinh(){const e=this.getValue();if(!Number.isFinite(e))return _.create(h.NUM);const t=Math.asinh(e);return Number.isNaN(t)?_.create(h.NUM):new E(t)}tan(){const e=this.getValue();if(!Number.isFinite(e))return _.create(h.NUM);const t=Math.tan(e);return Number.isFinite(t)?new E(t):_.create(h.NUM)}tanh(){const e=this.getValue();if(!Number.isFinite(e))return _.create(h.NUM);const t=Math.tanh(e);return Number.isFinite(t)?new E(t):_.create(h.NUM)}atan(){const e=this.getValue();if(!Number.isFinite(e))return _.create(h.NUM);const t=Math.atan(e);return Number.isFinite(t)?new E(t):_.create(h.NUM)}atan2(e){if(e.isArray())return e.atan2Inverse(this);const t=this.getValue(),n=e.getValue();if(typeof n=="string")return _.create(h.VALUE);if(typeof n=="number"){if(!Number.isFinite(t)||!Number.isFinite(n))return _.create(h.NUM);const i=Math.atan2(t,n);return Number.isFinite(i)?new E(i):_.create(h.NUM)}return typeof n=="boolean"?new E(Math.atan2(t,n?1:0)):this}atanh(){const e=this.getValue();if(!Number.isFinite(e))return _.create(h.NUM);const t=Math.atanh(e);return Number.isFinite(t)?new E(t):_.create(h.NUM)}log(){const e=this.getValue();if(typeof e=="number"&&e<=0||!Number.isFinite(e))return _.create(h.NUM);const t=Math.log(e);return Number.isFinite(t)?new E(t):_.create(h.NUM)}log10(){const e=this.getValue();if(typeof e=="number"&&e<=0||!Number.isFinite(e))return _.create(h.NUM);const t=Math.log10(e);return Number.isFinite(t)?new E(t):_.create(h.NUM)}exp(){const e=this.getValue();if(!Number.isFinite(e))return _.create(h.NUM);const t=Math.exp(e);return Number.isFinite(t)?new E(t):_.create(h.NUM)}abs(){const e=this.getValue();if(!Number.isFinite(e))return _.create(h.NUM);const t=Math.abs(e);return Number.isFinite(t)?new E(t):_.create(h.NUM)}round(e){if(e.isArray())return e.roundInverse(this);const t=this.getValue(),n=e.getValue();if(typeof n=="string")return _.create(h.VALUE);if(typeof n=="number"){if(!Number.isFinite(t)||!Number.isFinite(n))return _.create(h.NUM);const i=or(t,n);return Number.isFinite(i)?new E(i):_.create(h.NUM)}return typeof n=="boolean"?new E(or(t,n?1:0)):this}floor(e){if(e.isArray())return e.floorInverse(this);const t=this.getValue(),n=e.getValue();if(typeof n=="string")return _.create(h.VALUE);if(typeof n=="number"){if(!Number.isFinite(t)||!Number.isFinite(n))return _.create(h.NUM);const i=ur(t,n);return Number.isFinite(i)?new E(i):_.create(h.NUM)}return typeof n=="boolean"?new E(ur(t,n?1:0)):this}ceil(e){if(e.isArray())return e.ceilInverse(this);const t=this.getValue(),n=e.getValue();if(typeof n=="string")return _.create(h.VALUE);if(typeof n=="number"){if(!Number.isFinite(t)||!Number.isFinite(n))return _.create(h.NUM);const i=lr(t,n);return Number.isFinite(i)?new E(i):_.create(h.NUM)}return typeof n=="boolean"?new E(lr(t,n?1:0)):this}_compareInfinity(e,t,n){let i=!1;switch(n){case S.EQUALS:i=e===t;break;case S.GREATER_THAN:i=e>t;break;case S.GREATER_THAN_OR_EQUAL:i=e>=t;break;case S.LESS_THAN:i=e<t;break;case S.LESS_THAN_OR_EQUAL:i=e<=t;break;case S.NOT_EQUAL:i=e!==t;break}return i}}class j extends le{constructor(e,t=!1){super(e);g(this,"_value");if(t){this._value=e;return}let n=e.toString();n.charAt(0)==='"'&&n.charAt(n.length-1)==='"'&&(n=n.slice(1,-1),n=n.replace(/""/g,'"')),this._value=n}getValue(){return this._value}isString(){return!0}concatenateFront(e){return e.isArray()?e.concatenateBack(this):new j(this.concatenate(e.getValue(),K.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new j(this.concatenate(e.getValue(),K.BACK))}compare(e,t){return e.isArray()?e.compare(this,Tt(t)):this.compareBy(e.getValue(),t)}wildcard(e,t){return e.isArray()?e.wildcard(this,Tt(t)):this._checkWildcard(e.getValue(),t)}compareBy(e,t){const n=this.getValue();let i=!1;if(typeof e=="string")switch(t){case S.EQUALS:i=n===e;break;case S.GREATER_THAN:i=n>e;break;case S.GREATER_THAN_OR_EQUAL:i=n>=e;break;case S.LESS_THAN:i=n<e;break;case S.LESS_THAN_OR_EQUAL:i=n<=e;break;case S.NOT_EQUAL:i=n!==e;break}else if(typeof e=="number")switch(t){case S.EQUALS:case S.GREATER_THAN:case S.GREATER_THAN_OR_EQUAL:i=!0;break;case S.LESS_THAN:case S.LESS_THAN_OR_EQUAL:case S.NOT_EQUAL:i=!1;break}else if(typeof e=="boolean")switch(t){case S.EQUALS:case S.GREATER_THAN:case S.GREATER_THAN_OR_EQUAL:i=!1;break;case S.LESS_THAN:case S.LESS_THAN_OR_EQUAL:case S.NOT_EQUAL:i=!0;break}return new Q(i)}_checkWildcard(e,t){const n=this.getValue().toLocaleLowerCase(),i=Zr(n,e,t);return new Q(i)}}function un(s){return""}function ln(s=[]){const r=[];for(let e=0;e<s.length;e++){const t=s[e];r[e]==null&&(r[e]=[]);for(let n=0;n<t.length;n++){const i=t[n];i.isError()?r[e][n]=i.getErrorType():r[e][n]=i.getValue()}}return r}class se extends le{constructor(e){var r=(...ji)=>(super(...ji),g(this,"_value",[]),g(this,"_rowCount",-1),g(this,"_columnCount",-1),g(this,"_unitId",""),g(this,"_sheetId",""),g(this,"_currentRow",-1),g(this,"_currentColumn",-1),this);if(typeof e=="string")r(e);else{const t=un();r(t)}this._value=this._formatValue(e)}dispose(){this._value.forEach(e=>{e.forEach(t=>{t.dispose()})}),this._value=[]}getRowCount(){return this._rowCount}setRowCount(e){this._rowCount=e}getColumnCount(){return this._columnCount}setColumnCount(e){this._columnCount=e}setCurrent(e,t){this._currentRow=e,this._currentColumn=t}setUnitId(e){this._unitId=e}getUnitId(){return this._unitId}setSheetId(e){this._sheetId=e}getSheetId(){return this._sheetId}getCurrentRow(){return this._currentRow}getCurrentColumn(){return this._currentColumn}getArrayValue(){return this._value}setArrayValue(e){this._value=e}isArray(){return!0}get(e,t){return this._value[e][t]}set(e,t,n){if(e>=this._rowCount||t>=this._columnCount)throw new Error("Exceeding array bounds.");this._value[e][t]=n}getRangePosition(){const t=this.getRowCount(),n=0,i=this.getColumnCount();return{startRow:0,endRow:t-1,startColumn:n,endColumn:i-1}}iterator(e){const{startRow:t,endRow:n,startColumn:i,endColumn:a}=this.getRangePosition(),o=this.getArrayValue();for(let u=t;u<=n;u++)for(let l=i;l<=a;l++)if(e(o[u][l],u,l)===!1)return}getFirstCell(){const{startRow:e,startColumn:t}=this.getRangePosition();return this.getArrayValue()[e][t]}pick(e){const t=e.getRowCount(),n=e.getColumnCount();if(t!==this._rowCount||t!==this._rowCount)return this._createNewArray([[new E(0)]],1,1);const i=[];i[0]=[];for(let a=0;a<t;a++)for(let o=0;o<n;o++){const u=e.get(a,o),l=this.get(a,o);u.isError()||u.getValue()===!0&&i[0].push(l)}return this._createNewArray(i,1,i[0].length)}flatten(){const e=[];e[0]=[];for(let t=0;t<this._rowCount;t++)for(let n=0;n<this._rowCount;n++){const i=this.get(t,n);e[0].push(i)}return this._createNewArray(e,1,e[0].length)}slice(e,t){let n=0,i=this._rowCount-1,a=1,o=0,u=this._columnCount-1,l=1;e!=null&&(n=e[0]||0,i=e[1]||this._rowCount-1,a=e[2]||1),t!=null&&(o=t[0]||0,u=t[1]||this._columnCount-1,l=t[2]||1);const c=[],f=this._value;let d=0,p=0;for(let R=n;R<=i;R+=a){p=0,c[d]==null&&(c[d]=[]);for(let C=o;C<=u;C+=l)c[d][p]=f[R][C],p++;d++}return this._createNewArray(c,c.length,c[0].length)}sum(){let e=new E(0);return this.iterator(t=>{if(t==null)return!0;if(t.isError())return e=t,!1;e=e.plus(t)}),e}max(){let e=new E(-1/0);return this.iterator(t=>{if(t==null)return!0;if(t.isError())return e=t,!1;if(t.isString()||t.isNull())return!0;e.isLessThan(t).getValue()&&(e=t)}),e}min(){let e=new E(1/0);return this.iterator(t=>{if(t==null)return!0;if(t.isError())return e=t,!1;if(t.isString()||t.isNull())return!0;e.isGreaterThan(t).getValue()&&(e=t)}),e}count(){let e=new E(0);return this.iterator(t=>{if(t==null||t.isError()||t.isString()||t.isNull())return!0;e=e.plusBy(1)}),e}countA(){let e=new E(0);return this.iterator(t=>{if(t==null||t.isNull())return!0;e=e.plusBy(1)}),e}countBlank(){let e=new E(0);return this.iterator(t=>{if(t!=null)return!0;e=e.plusBy(1)}),e}sortByRow(e){const t=this._transposeArray(this._value);t.sort(this._sort(e)),this._value=this._transposeArray(t)}sortByColumn(e){this._value.sort(this._sort(e))}transpose(){const e=this._transposeArray(this._value),t=this._rowCount,n=this._columnCount;return this._createNewArray(e,n,t)}getNegative(){return new se("{0}").minus(this)}getReciprocal(){return new se("{1}").divided(this)}plus(e){return this._batchOperator(e,1)}minus(e){return this._batchOperator(e,0)}multiply(e){return this._batchOperator(e,2)}divided(e){return this._batchOperator(e,3)}compare(e,t){return this._batchOperator(e,4,t)}wildcard(e,t){return this._batchOperator(e,8,t)}concatenateFront(e){return this._batchOperator(e,5)}concatenateBack(e){return this._batchOperator(e,6)}product(e,t){return this._batchOperator(e,7,t)}map(e){var a,o;const t=this._rowCount,n=this._columnCount,i=[];for(let u=0;u<t;u++){const l=[];for(let c=0;c<n;c++){const f=(o=(a=this._value)==null?void 0:a[u])==null?void 0:o[c];f?f.isError()?l[c]=f:l[c]=e(f,u,c):l[c]=_.create(h.VALUE)}i.push(l)}return this._createNewArray(i,t,n)}pow(e){return this._batchOperator(e,9)}powInverse(e){return this.map(t=>t.isError()?t:e.pow(t))}sqrt(){return this.map(e=>e.isError()?e:e.sqrt())}cbrt(){return this.map(e=>e.isError()?e:e.cbrt())}cos(){return this.map(e=>e.isError()?e:e.cos())}acos(){return this.map(e=>e.isError()?e:e.acos())}acosh(){return this.map(e=>e.isError()?e:e.acosh())}sin(){return this.map(e=>e.isError()?e:e.sin())}asin(){return this.map(e=>e.isError()?e:e.asin())}asinh(){return this.map(e=>e.isError()?e:e.asinh())}tan(){return this.map(e=>e.isError()?e:e.tan())}tanh(){return this.map(e=>e.isError()?e:e.tanh())}atan(){return this.map(e=>e.isError()?e:e.atan())}atanh(){return this.map(e=>e.isError()?e:e.atanh())}atan2(e){return this._batchOperator(e,13)}atan2Inverse(e){return this.map(t=>t.isError()?t:e.atan2(t))}mean(){const e=this.sum(),t=this.countA();return e.divided(t)}median(){const e=this.flatten(),t=e.getColumnCount();if(t<=1)return e.get(0,0);if(e.sortByRow(0),t%2===0){const n=e.get(0,t/2),i=e.get(0,t/2-1);return n.plus(i).divided(new E(2,!0))}return e.get(0,(t-1)/2)}var(){const e=this.mean(),t=[];this.iterator((f,d,p)=>{(f==null||f.isError()||f.isString())&&(f=new E(0));let R=f.minus(e).pow(new E(2,!0));R.isError()&&(R=new E(0)),t[d]==null&&(t[d]=[]),t[d][p]=R});const{_rowCount:n,_columnCount:i,_unitId:a,_sheetId:o,_currentRow:u,_currentColumn:l}=this;return new se({calculateValueList:t,rowCount:n,columnCount:i,unitId:a,sheetId:o,row:u,column:l}).mean()}std(){const e=this.var();return e.isError()?e:e.sqrt()}log(){return this.map(e=>e.isError()?e:e.log())}log10(){return this.map(e=>e.isError()?e:e.log10())}exp(){return this.map(e=>e.isError()?e:e.exp())}abs(){return this.map(e=>e.isError()?e:e.abs())}round(e){return this._batchOperator(e,10)}roundInverse(e){return this.map(t=>t.isError()?t:e.round(t))}floor(e){return this._batchOperator(e,11)}floorInverse(e){return this.map(t=>t.isError()?t:e.floor(t))}ceil(e){return this._batchOperator(e,12)}ceilInverse(e){return this.map(t=>t.isError()?t:e.ceil(t))}toValue(){return ln(this._value)}_sort(e){const t=Xr();return(n,i)=>{const a=n[e],o=i[e];return a.isError()&&a.isError()?0:a.isError()?1:o.isError()?-1:t(a.getValue(),o.getValue())}}_transposeArray(e){const t=e.length,n=e[0].length,i=[];for(let a=0;a<n;a++){i[a]=[];for(let o=0;o<t;o++)i[a][o]=e[o][a]}return i}_batchOperator(e,t,n){const i=[];let a=this._rowCount,o=this._columnCount;if(e.isArray()){const l=e.getRowCount(),c=e.getColumnCount();if(a=Math.max(l,a),o=Math.max(c,o),l===1&&c===1){const f=e.getFirstCell();for(let d=0;d<o;d++)i.push(f)}else if(l===1&&this._columnCount>1){const f=e.getArrayValue();for(let d=0;d<o;d++)i.push(f[0][d])}else return this._batchOperatorArray(e,t,n)}else for(let l=0;l<o;l++)i.push(e);const u=[];for(let l=0;l<o;l++){const c=i[l];this._batchOperatorValue(c,l,u,t,n)}return this._createNewArray(u,a,o)}_batchOperatorValue(e,t,n,i,a){var p,R;const o=this._rowCount;let u=!1;const l=this.getUnitId(),c=this.getSheetId(),f=this.getCurrentRow(),d=this.getCurrentColumn();if(i===4&&(u=ge.canUseCache(l,c,t+d,f,f+o-1),u===!0)){if(a===S.EQUALS){const C=ge.getCellPositions(l,c,t+d,e.getValue());if(C!=null)for(let N=0;N<o;N++)n[N]==null&&(n[N]=[]),C.includes(N+f)?n[N][t]=new Q(!0):n[N][t]=new Q(!1)}else{const C=ge.getCellValuePositions(l,c,t+d);C!=null&&C.forEach((N,y)=>{let b;if(typeof y=="string"?b=new j(y):typeof y=="number"?b=new E(y):typeof y=="boolean"&&(b=new Q(y)),b==null)return!0;if(b.compare(e,a))for(let F=0;F<o;F++)n[F]==null&&(n[F]=[]),N.includes(F+f)?n[F][t]=new Q(!0):n[F][t]=new Q(!1)})}return}ge.setContinueBuildingCache(l,c,t+d,f,f+o-1);for(let C=0;C<o;C++){const N=(R=(p=this._value)==null?void 0:p[C])==null?void 0:R[t];if(n[C]==null&&(n[C]=[]),N&&e)if(N.isError())n[C][t]=N;else if(e.isError())n[C][t]=_.create(h.VALUE);else switch(i){case 1:n[C][t]=N.plus(e);break;case 0:n[C][t]=N.minus(e);break;case 2:n[C][t]=N.multiply(e);break;case 3:n[C][t]=N.divided(e);break;case 4:a?n[C][t]=N.compare(e,a):n[C][t]=_.create(h.VALUE);break;case 5:n[C][t]=N.concatenateFront(e);break;case 6:n[C][t]=N.concatenateBack(e);break;case 7:a?n[C][t]=N.product(e,a):n[C][t]=_.create(h.VALUE);break;case 8:a?n[C][t]=N.wildcard(e,a):n[C][t]=_.create(h.VALUE);break;case 9:n[C][t]=N.pow(e);break;case 10:n[C][t]=N.round(e);break;case 11:n[C][t]=N.floor(e);break;case 13:n[C][t]=N.atan2(e);break;case 12:n[C][t]=N.ceil(e);break}else n[C][t]=_.create(h.NA);N!=null&&(N.isError()?ge.set(l,c,t+d,N.getErrorType(),C+f):ge.set(l,c,t+d,N.getValue(),C+f))}}_batchOperatorArray(e,t,n){var f,d,p,R,C,N,y,b,U,F,Y,fe;let i=e.getRowCount(),a=e.getColumnCount();i<this._rowCount&&(i=this._rowCount),a<this._columnCount&&(a=this._columnCount);const o=[],u=e.getArrayValue(),l=this._checkArrayCalculateType(this),c=this._checkArrayCalculateType(e);for(let z=0;z<i;z++){const M=[];for(let I=0;I<a;I++){let x;l===3?x=(d=(f=this._value)==null?void 0:f[0])==null?void 0:d[0]:l===1?x=(R=(p=this._value)==null?void 0:p[0])==null?void 0:R[I]:l===2?x=(N=(C=this._value)==null?void 0:C[z])==null?void 0:N[0]:x=(b=(y=this._value)==null?void 0:y[z])==null?void 0:b[I];let P;if(c===3?P=(U=u==null?void 0:u[0])==null?void 0:U[0]:c===1?P=(F=u==null?void 0:u[0])==null?void 0:F[I]:c===2?P=(Y=u==null?void 0:u[z])==null?void 0:Y[0]:P=(fe=u==null?void 0:u[z])==null?void 0:fe[I],x&&P)if(x.isError())M[I]=x;else if(P.isError())M[I]=P;else switch(t){case 1:M[I]=x.plus(P);break;case 0:M[I]=x.minus(P);break;case 2:M[I]=x.multiply(P);break;case 3:M[I]=x.divided(P);break;case 4:n?M[I]=x.compare(P,n):M[I]=_.create(h.VALUE);break;case 5:M[I]=x.concatenateFront(P);break;case 6:M[I]=x.concatenateBack(P);break;case 7:n?M[I]=x.product(P,n):M[I]=_.create(h.VALUE);break;case 8:n?M[I]=x.wildcard(P,n):M[I]=_.create(h.VALUE);break;case 9:M[I]=x.pow(P);break;case 10:M[I]=x.round(P);break;case 13:M[I]=x.atan2(P);break;case 11:M[I]=x.floor(P);break;case 12:M[I]=x.ceil(P);break}else M[I]=_.create(h.NA)}o.push(M)}return this._createNewArray(o,i,a)}_checkArrayCalculateType(e){return e.getRowCount()===1&&e.getColumnCount()===1?3:e.getRowCount()===1?1:e.getColumnCount()===1?2:0}_formatValue(e){if(typeof e!="string")return e=e,this._rowCount=e.rowCount,this._columnCount=e.columnCount,this._unitId=e.unitId,this._sheetId=e.sheetId,this._currentRow=e.row,this._currentColumn=e.column,e.calculateValueList;e=e.slice(1,-1);const t=e.split(";"),n=t.length,i=[];let a=0;for(let o=0;o<n;o++){const l=t[o].split(","),c=l.length;a<c&&(a=c);const f=[];for(let d=0;d<c;d++){const p=l[d].trim();f.push(Fe.create(p))}i.push(f)}return this._rowCount=n,this._columnCount=a,i}_createNewArray(e,t,n){const i={calculateValueList:e,rowCount:t,columnCount:n,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:this._currentRow,column:this._currentColumn};return new se(i)}}class Fe{static create(r){if(typeof r=="boolean")return new Q(r,!0);if(typeof r=="string"){const e=r.toLocaleUpperCase();return e===de.TRUE||e===de.FALSE?new Q(e):m.isRealNum(r)?new E(r):new RegExp($r,"g").test(r)?new se(r):new j(r)}return typeof r=="number"?Number.isFinite(r)?new E(r,!0):_.create(h.NUM):_.create(h.NA)}}const cn=1e5,Ut=new Be(cn);class Le extends Ye{constructor(e){super();g(this,"_forcedSheetId","");g(this,"_forcedSheetName","");g(this,"_defaultSheetId","");g(this,"_rangeData",{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1});g(this,"_unitData",{});g(this,"_rowCount",0);g(this,"_columnCount",0);g(this,"_defaultUnitId","");g(this,"_forcedUnitId","");g(this,"_runtimeData",{});g(this,"_arrayFormulaCellData",{});g(this,"_runtimeArrayFormulaCellData",{});g(this,"_runtimeFeatureCellData",{});g(this,"_refOffsetX",0);g(this,"_refOffsetY",0);this._token=e}dispose(){this._unitData={},this._runtimeData={}}setRefOffset(e=0,t=0){this._refOffsetX=e,this._refOffsetY=t}getRefOffset(){return{x:this._refOffsetX,y:this._refOffsetY}}getRangePosition(){let e=this._rangeData.startRow,t=this._rangeData.endRow,n=this._rangeData.startColumn,i=this._rangeData.endColumn;return e===-1&&(e=0),n===-1&&(n=0),t===-1&&(t=this._rowCount-1),i===-1&&(i=this._columnCount-1),{startRow:e,endRow:t,startColumn:n,endColumn:i}}isReferenceObject(){return!0}iterator(e){const{startRow:t,endRow:n,startColumn:i,endColumn:a}=this.getRangePosition();if(this._checkIfWorksheetMiss())return e(new _(h.VALUE),t,i);for(let o=t;o<=n;o++)for(let u=i;u<=a;u++){const l=o+this._refOffsetY,c=u+this._refOffsetX;if(l<0||c<0)return e(new _(h.REF),o,u);const f=this.getCellData(l,c);let d=!1;if(f==null||m.isNullCell(f)){d=e(null,o,u);continue}const p=this.getCellValueObject(f);if(d=e(p,o,u),d===!1)return}}getFirstCell(){const{startRow:e,startColumn:t}=this.getRangePosition(),n=this.getCellData(e+this._refOffsetY,t+this._refOffsetX);return n?this.getCellValueObject(n):new E(0,!0)}getRangeData(){return this._rangeData}setRangeData(e){this._rangeData=e}getUnitId(){return this._forcedUnitId&&this._forcedUnitId.length>0?this._forcedUnitId:this._defaultUnitId}getSheetId(){return this._forcedSheetId&&this._forcedSheetId.length>0?this._forcedSheetId:this._defaultSheetId}setForcedUnitIdDirect(e){e.length>0&&(this._forcedUnitId=e)}getForcedUnitId(){return this._forcedUnitId}setForcedSheetId(e){var t;this._forcedSheetId=(t=e[this.getUnitId()])==null?void 0:t[this._forcedSheetName]}setForcedSheetIdDirect(e){this._forcedSheetId=e}getForcedSheetId(){return this._forcedSheetId}setForcedSheetName(e){e.length>0&&(this._forcedSheetName=e)}getForcedSheetName(){return this._forcedSheetName}setDefaultSheetId(e){this._defaultSheetId=e}getDefaultSheetId(){return this._defaultSheetId}setDefaultUnitId(e){this._defaultUnitId=e}getDefaultUnitId(){return this._defaultUnitId}getUnitData(){return this._unitData}setUnitData(e){this._unitData=e}getRuntimeData(){return this._runtimeData}setRuntimeData(e){this._runtimeData=e}getArrayFormulaCellData(){return this._arrayFormulaCellData}setArrayFormulaCellData(e){this._arrayFormulaCellData=e}getRuntimeArrayFormulaCellData(){return this._runtimeArrayFormulaCellData}setRuntimeArrayFormulaCellData(e){this._runtimeArrayFormulaCellData=e}getRuntimeFeatureCellData(){return this._runtimeFeatureCellData}setRuntimeFeatureCellData(e){this._runtimeFeatureCellData=e}getRowCount(){return this.getCurrentActiveSheetData().rowCount}getColumnCount(){return this.getCurrentActiveSheetData().columnCount}isCell(){return!1}isColumn(){return!1}isRow(){return!1}isRange(){return!1}isTable(){return!1}unionBy(e){return _.create(h.REF)}unionRange(e,t){return{startRow:-1,startColumn:-1,endRow:-1,endColumn:-1}}getCellValueObject(e){const t=e.v||0;return Ur.has(t)?_.create(t):e.t===m.CellValueType.NUMBER?new E(t):e.t===m.CellValueType.STRING||e.t===m.CellValueType.FORCE_STRING?new j(t):e.t===m.CellValueType.BOOLEAN?new Q(t):Fe.create(t)}getCellByRow(e){return this.getCellByPosition(e)}getCellByColumn(e){return this.getCellByPosition(void 0,e)}getCurrentActiveSheetData(){return this._unitData[this.getUnitId()][this.getSheetId()]}getCurrentRuntimeSheetData(){var e,t;return(t=(e=this._runtimeData)==null?void 0:e[this.getUnitId()])==null?void 0:t[this.getSheetId()]}getCurrentActiveArrayFormulaCellData(){var e,t;return(t=(e=this._arrayFormulaCellData)==null?void 0:e[this.getUnitId()])==null?void 0:t[this.getSheetId()]}getCurrentRuntimeActiveArrayFormulaCellData(){var e,t;return(t=(e=this._runtimeArrayFormulaCellData)==null?void 0:e[this.getUnitId()])==null?void 0:t[this.getSheetId()]}getCellData(e,t){const n=this.getCurrentActiveSheetData(),i=this.getCurrentRuntimeSheetData(),a=this.getCurrentActiveArrayFormulaCellData(),o=this.getCurrentRuntimeActiveArrayFormulaCellData();return(i==null?void 0:i.getValue(e,t))||(o==null?void 0:o.getValue(e,t))||this.getRuntimeFeatureCellValue(e,t)||(a==null?void 0:a.getValue(e,t))||n.cellData.getValue(e,t)}getRuntimeFeatureCellValue(e,t){var i;const n=Object.keys(this._runtimeFeatureCellData);for(const a of n){const o=this._runtimeFeatureCellData[a],u=(i=o==null?void 0:o[this.getUnitId()])==null?void 0:i[this.getSheetId()];if(u==null)continue;const l=u.getValue(e,t);if(l!=null)return l}}getCellByPosition(e,t){e||(e=this._rangeData.startRow),t||(t=this._rangeData.startColumn);const n=this.getCellData(e,t);return n?this.getCellValueObject(n):_.create(h.VALUE)}toArrayValueObject(){var p;const{startRow:e,endRow:t,startColumn:n,endColumn:i}=this.getRangePosition(),a=`${this.getUnitId()}_${this.getSheetId()}_${e+this._refOffsetY}_${t+this._refOffsetY}_${n+this._refOffsetX}_${i+this._refOffsetX}`,o=Ut.get(a);if(o)return o;const u=t-e+1,l=i-n+1,c=new Array(u);this.iterator((R,C,N)=>{const y=C-e,b=N-n;c[y]||(c[y]=new Array(l)),R==null&&(R=new hr(0)),c[y][b]=R});const f={calculateValueList:c,rowCount:c.length,columnCount:((p=c[0])==null?void 0:p.length)||0,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:e,column:n},d=new se(f);return Ut.set(a,d),d}toUnitRange(){return{range:this._rangeData,sheetId:this.getSheetId(),unitId:this.getUnitId()}}_checkIfWorksheetMiss(){return(this._forcedSheetId==null||this._forcedSheetId.length===0)&&this._forcedSheetName.length>0}}class hn extends Ye{constructor(r){super(),this._promise=r}isAsyncObject(){return!0}async getValue(){return this._promise}}class fn extends Ye{constructor(r){super(),this._promiseList=r}isAsyncArrayObject(){return!0}async getValue(){var t;const r=[];for(let n=0;n<this._promiseList.length;n++){const i=this._promiseList[n];r[n]==null&&(r[n]=[]);for(let a=0;a<i.length;a++){const o=i[a];o.isAsyncObject()?r[n][a]=await o.getValue():r[n][a]=o}}const e={calculateValueList:r,rowCount:r.length,columnCount:((t=r[0])==null?void 0:t.length)||0,unitId:"",sheetId:"",row:0,column:0};return new se(e)}}class fr extends Le{constructor(r,e,t){super(""),this.setRangeData(r),e&&this.setForcedSheetIdDirect(e),t&&this.setForcedUnitIdDirect(t)}isRange(){return!0}}var It=(s=>(s.MAKEARRAY="MAKEARRAY",s))(It||{});class v extends m.Disposable{constructor(r){super(),this._name=r}get name(){return this._name}isAsync(){return!1}isAddress(){return!1}calculate(...r){return _.create(h.VALUE)}checkArrayType(r){return r.isReferenceObject()||r.isValueObject()&&r.isArray()}}var ze=(s=>(s.CONCATENATE="CONCATENATE",s))(ze||{}),_n=(s=>{})(),dn=(s=>{})(),mn=(s=>{})(),gn=(s=>{})(),Cn=(s=>{})(),En=(s=>{})(),pn=(s=>{})(),Ke=(s=>(s.INDIRECT="INDIRECT",s.OFFSET="OFFSET",s))(Ke||{}),X=(s=>(s.ABS="ABS",s.ACOS="ACOS",s.ACOSH="ACOSH",s.ACOT="ACOT",s.SUM="SUM",s.SUMIF="SUMIF",s.SUMIFS="SUMIFS",s.POWER="POWER",s))(X||{}),ce=(s=>(s.AVERAGE="AVERAGE",s.COUNT="COUNT",s.MAX="MAX",s.MIN="MIN",s.COUNTA="COUNTA",s))(ce||{}),Nn=(s=>{})(),An=(s=>{})(),Rn=(s=>{})();class Sn extends m.Disposable{constructor(){super(...arguments);g(this,"_definedNameMap",new Map)}dispose(){this._definedNameMap.clear()}registerDefinedName(e,t,n){var a;this._definedNameMap.get(e)==null&&this._definedNameMap.set(e,new Map),(a=this._definedNameMap.get(e))==null||a.set(t,n)}removeDefinedName(e,t){var n;(n=this._definedNameMap.get(e))==null||n.delete(t)}getDefinedNameMap(e){return this._definedNameMap.get(e)}getValue(e,t){var n;return(n=this._definedNameMap.get(e))==null?void 0:n.get(t)}hasDefinedName(e){var n;return(((n=this._definedNameMap.get(e))==null?void 0:n.size)||0)!==0}}const Xe=D.createIdentifier("univer.formula.defined-names.service");var yn=Object.defineProperty,bn=Object.getOwnPropertyDescriptor,Dn=(s,r,e,t)=>{for(var n=t>1?void 0:t?bn(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&yn(r,e,n),n},Fn=(s,r)=>(e,t)=>r(e,t,s);let Mt=class extends m.Disposable{constructor(r){super();g(this,"_unitData",{});g(this,"_arrayFormulaCellData",{});g(this,"_formulaData",{});g(this,"_sheetNameMap",{});g(this,"_forceCalculate",!1);g(this,"_dirtyRanges",[]);g(this,"_dirtyNameMap",{});g(this,"_dirtyUnitFeatureMap",{});g(this,"_excludedCell");this._currentUniverService=r}dispose(){this._unitData={},this._formulaData={},this._arrayFormulaCellData={},this._sheetNameMap={},this._dirtyRanges=[],this._dirtyNameMap={},this._dirtyUnitFeatureMap={},this._excludedCell={}}getExcludedRange(){return this._excludedCell}getUnitData(){return this._unitData}getFormulaData(){return this._formulaData}getArrayFormulaCellData(){return this._arrayFormulaCellData}getSheetNameMap(){return this._sheetNameMap}isForceCalculate(){return this._forceCalculate}getDirtyRanges(){return this._dirtyRanges}getDirtyNameMap(){return this._dirtyNameMap}getDirtyUnitFeatureMap(){return this._dirtyUnitFeatureMap}load(r){const{allUnitData:e,unitSheetNameMap:t}=this._loadSheetData();this._unitData=e,this._formulaData=r.formulaData,this._arrayFormulaCellData=qt(r.arrayFormulaCellData),this._sheetNameMap=t,this._forceCalculate=r.forceCalculate,this._dirtyRanges=r.dirtyRanges,this._dirtyNameMap=r.dirtyNameMap,this._dirtyUnitFeatureMap=r.dirtyUnitFeatureMap,this._excludedCell=r.excludedCell}loadDirtyRangesAndExcludedCell(r,e){this._dirtyRanges=r,this._excludedCell=e}registerUnitData(r){this._unitData=r}registerFormulaData(r){this._formulaData=r}registerSheetNameMap(r){this._sheetNameMap=r}_loadSheetData(){const r=this._currentUniverService.getAllUniverSheetsInstance(),e={},t={};for(const n of r){const i=n.getUnitId(),a=n.getSheets(),o={},u={};for(const l of a){const c=l.getSheetId(),f=l.getConfig();o[c]={cellData:new m.ObjectMatrix(f.cellData),rowCount:f.rowCount,columnCount:f.columnCount},u[l.getName()]=l.getSheetId()}e[i]=o,t[i]=u}return{allUnitData:e,unitSheetNameMap:t}}};Mt=Dn([Fn(0,m.IUniverInstanceService)],Mt);const we=D.createIdentifier("univer.formula.current-data.service");var Ln=Object.defineProperty,wn=Object.getOwnPropertyDescriptor,Tn=(s,r,e,t)=>{for(var n=t>1?void 0:t?wn(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Ln(r,e,n),n},On=(s,r)=>(e,t)=>r(e,t,s),J=(s=>(s[s.IDLE=0]="IDLE",s[s.START_DEPENDENCY=1]="START_DEPENDENCY",s[s.START_CALCULATION=2]="START_CALCULATION",s[s.CURRENTLY_CALCULATING=3]="CURRENTLY_CALCULATING",s[s.START_DEPENDENCY_ARRAY_FORMULA=4]="START_DEPENDENCY_ARRAY_FORMULA",s[s.START_CALCULATION_ARRAY_FORMULA=5]="START_CALCULATION_ARRAY_FORMULA",s[s.CURRENTLY_CALCULATING_ARRAY_FORMULA=6]="CURRENTLY_CALCULATING_ARRAY_FORMULA",s[s.CALCULATION_COMPLETED=7]="CALCULATION_COMPLETED",s))(J||{}),Te=(s=>(s[s.INITIAL=0]="INITIAL",s[s.STOP_EXECUTION=1]="STOP_EXECUTION",s[s.NOT_EXECUTED=2]="NOT_EXECUTED",s[s.SUCCESS=3]="SUCCESS",s))(Te||{});let vt=class extends m.Disposable{constructor(r){super();g(this,"_formulaExecuteStage",0);g(this,"_stopState",!1);g(this,"_currentRow",0);g(this,"_currentColumn",0);g(this,"_currentSubComponentId","");g(this,"_currentUnitId","");g(this,"_runtimeData",{});g(this,"_runtimeOtherData",{});g(this,"_unitArrayFormulaRange",{});g(this,"_runtimeArrayFormulaCellData",{});g(this,"_runtimeClearArrayFormulaCellData",{});g(this,"_runtimeFeatureRange",{});g(this,"_runtimeFeatureCellData",{});g(this,"_functionsExecutedState",0);g(this,"_functionDefinitionPrivacyVar",new Map);g(this,"_totalFormulasToCalculate",0);g(this,"_completedFormulasCount",0);g(this,"_totalArrayFormulasToCalculate",0);g(this,"_completedArrayFormulasCount",0);g(this,"_isCycleDependency",!1);this._currentConfigService=r}get currentRow(){return this._currentRow}get currentColumn(){return this._currentColumn}get currentSubComponentId(){return this._currentSubComponentId}get currentUnitId(){return this._currentUnitId}dispose(){this.reset(),this._runtimeFeatureCellData={},this._runtimeFeatureRange={}}enableCycleDependency(){this._isCycleDependency=!0}disableCycleDependency(){this._isCycleDependency=!1}isCycleDependency(){return this._isCycleDependency}setTotalArrayFormulasToCalculate(r){this._totalArrayFormulasToCalculate=r}getTotalArrayFormulasToCalculate(){return this._totalArrayFormulasToCalculate}setCompletedArrayFormulasCount(r){this._completedArrayFormulasCount=r}getCompletedArrayFormulasCount(){return this._completedArrayFormulasCount}setTotalFormulasToCalculate(r){this._totalFormulasToCalculate=r}getTotalFormulasToCalculate(){return this._totalFormulasToCalculate}setCompletedFormulasCount(r){this._completedFormulasCount=r}getCompletedFormulasCount(){return this._completedFormulasCount}markedAsSuccessfullyExecuted(){this._functionsExecutedState=3}markedAsNoFunctionsExecuted(){this._functionsExecutedState=2}markedAsStopFunctionsExecuted(){this._functionsExecutedState=1}markedAsInitialFunctionsExecuted(){this._functionsExecutedState=0}stopExecution(){this._stopState=!0,this.setFormulaExecuteStage(0)}isStopExecution(){return this._stopState}setFormulaExecuteStage(r){this._formulaExecuteStage=r}getFormulaExecuteStage(){return this._formulaExecuteStage}reset(){this._formulaExecuteStage=0,this._runtimeData={},this._runtimeOtherData={},this._unitArrayFormulaRange={},this._runtimeArrayFormulaCellData={},this._runtimeClearArrayFormulaCellData={},this._functionDefinitionPrivacyVar.clear(),this.markedAsInitialFunctionsExecuted(),this._isCycleDependency=!1,this._totalFormulasToCalculate=0,this._completedFormulasCount=0}setCurrent(r,e,t,n){this._currentRow=r,this._currentColumn=e,this._currentSubComponentId=t,this._currentUnitId=n}clearFunctionDefinitionPrivacyVar(){this._functionDefinitionPrivacyVar.clear()}registerFunctionDefinitionPrivacyVar(r,e){this._functionDefinitionPrivacyVar.set(r,e)}getFunctionDefinitionPrivacyVar(r){return this._functionDefinitionPrivacyVar.get(r)}setRuntimeOtherData(r,e){const t=this._currentSubComponentId,n=this._currentUnitId;this._runtimeOtherData[n]===void 0&&(this._runtimeOtherData[n]={});const i=this._runtimeOtherData[n];i[t]===void 0&&(i[t]={});const a=i[t];a[r]=this._objectValueToCellValue(e)}setRuntimeData(r){const e=this._currentRow,t=this._currentColumn,n=this._currentSubComponentId,i=this._currentUnitId;this._runtimeData[i]==null&&(this._runtimeData[i]={});const a=this._runtimeData[i];a[n]==null&&(a[n]=new m.ObjectMatrix),this._unitArrayFormulaRange[i]==null&&(this._unitArrayFormulaRange[i]={});const o=this._unitArrayFormulaRange[i];let u=new m.ObjectMatrix;o[n]||(u=new m.ObjectMatrix(o[n])),this._runtimeArrayFormulaCellData[i]===void 0&&(this._runtimeArrayFormulaCellData[i]={});const l=this._runtimeArrayFormulaCellData[i];l[n]==null&&(l[n]=new m.ObjectMatrix),this._runtimeClearArrayFormulaCellData[i]===void 0&&(this._runtimeClearArrayFormulaCellData[i]={});const c=this._runtimeClearArrayFormulaCellData[i];c[n]==null&&(c[n]=new m.ObjectMatrix);const f=a[n],d=l[n],p=c[n];if(r.isReferenceObject()||r.isValueObject()&&r.isArray()){const R=r,{startRow:C,startColumn:N,endRow:y,endColumn:b}=R.getRangePosition();if(C===y&&N===b){const F=this._objectValueToCellValue(R.getFirstCell());f.setValue(e,t,F),p.setValue(e,t,F);return}const U={startRow:e,startColumn:t,endRow:y-C+e,endColumn:b-N+t};if(this._checkIfArrayFormulaRangeHasData(i,n,e,t,U)){const F=this._objectValueToCellValue(new _(h.SPILL));f.setValue(e,t,F),p.setValue(e,t,F)}else{const F=new _(h.SPILL);R.iterator((Y,fe,z)=>{const M=this._objectValueToCellValue(Y);if(fe===C&&z===N){if(Y!=null&&Y.isError()&&Y.isEqualType(F))return p.setValue(e,t,{}),f.setValue(e,t,{...this._objectValueToCellValue(F)}),!1;f.setValue(e,t,{...M})}d.setValue(fe-C+e,z-N+t,M)}),u.setValue(e,t,U),o[n]=u.getData()}}else{const R=this._objectValueToCellValue(r);f.setValue(e,t,R),p.setValue(e,t,R)}}getUnitData(){return this._runtimeData}getUnitArrayFormula(){return this._unitArrayFormulaRange}getRuntimeOtherData(){return this._runtimeOtherData}getRuntimeArrayFormulaCellData(){return this._runtimeArrayFormulaCellData}getRuntimeClearArrayFormulaCellData(){return this._runtimeClearArrayFormulaCellData}getRuntimeFeatureRange(){return this._runtimeFeatureRange}setRuntimeFeatureRange(r,e){this._runtimeFeatureRange[r]=e}getRuntimeFeatureCellData(){return this._runtimeFeatureCellData}setRuntimeFeatureCellData(r,e){this._runtimeFeatureCellData[r]=e}getAllRuntimeData(){return{unitData:this.getUnitData(),arrayFormulaRange:this.getUnitArrayFormula(),unitOtherData:this.getRuntimeOtherData(),functionsExecutedState:this._functionsExecutedState,arrayFormulaCellData:this.getRuntimeArrayFormulaCellData(),clearArrayFormulaCellData:this.getRuntimeClearArrayFormulaCellData(),runtimeFeatureRange:this.getRuntimeFeatureRange(),runtimeFeatureCellData:this.getRuntimeFeatureCellData()}}getRuntimeState(){return{totalFormulasToCalculate:this.getTotalFormulasToCalculate(),completedFormulasCount:this.getCompletedFormulasCount(),totalArrayFormulasToCalculate:this.getTotalArrayFormulasToCalculate(),completedArrayFormulasCount:this.getCompletedArrayFormulasCount(),stage:this.getFormulaExecuteStage()}}_objectValueToCellValue(r){if(r==null)return{v:0,t:m.CellValueType.NUMBER};if(r.isError())return{v:r.getErrorType(),t:m.CellValueType.STRING};if(r.isValueObject()){const e=r,t=e.getValue();return e.isNumber()?{v:t,t:m.CellValueType.NUMBER}:e.isBoolean()?{v:t,t:m.CellValueType.BOOLEAN}:{v:t,t:m.CellValueType.STRING}}}_checkIfArrayFormulaRangeHasData(r,e,t,n,i){var f,d,p,R,C,N;const{startRow:a,startColumn:o,endRow:u,endColumn:l}=i,c=this._currentConfigService.getUnitData();for(let y=a;y<=u;y++)for(let b=o;b<=l;b++){if(y===t&&n===b)continue;const U=(p=(d=(f=this._runtimeData)==null?void 0:f[r])==null?void 0:d[e])==null?void 0:p.getValue(y,b),F=(N=(C=(R=c==null?void 0:c[r])==null?void 0:R[e])==null?void 0:C.cellData)==null?void 0:N.getValue(y,b);if((!m.isNullCell(U)||!m.isNullCell(F))&&this._isInDirtyRange(r,e,y,b))return!0}return!1}_isInDirtyRange(r,e,t,n){const i=this._currentConfigService.getDirtyRanges();return Gt(i,r,e,t,n)}};vt=Tn([On(0,we)],vt);const ee=D.createIdentifier("univer.formula.runtime.service");var Un=Object.defineProperty,In=Object.getOwnPropertyDescriptor,Mn=(s,r,e,t)=>{for(var n=t>1?void 0:t?In(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Un(r,e,n),n},xt=(s,r)=>(e,t)=>r(e,t,s);let Ne=class extends m.Disposable{constructor(s,r,e){super(),this._definedNamesService=s,this._runtimeService=r,this._lexerTreeBuilder=e}treeBuilder(s,r=!0){return this._lexerTreeBuilder.treeBuilder(s,r,this._injectDefinedName.bind(this))}_injectDefinedName(s){var i;const r=this._runtimeService.currentUnitId;if(!this._definedNamesService.hasDefinedName(r))return{sequenceString:"",hasDefinedName:!1};const e=this._lexerTreeBuilder.getSequenceNode(s);let t="",n=!1;for(let a=0,o=e.length;a<o;a++){const u=e[a];if(typeof u=="string"){t+=u;continue}const{nodeType:l,token:c}=u;if(l===q.REFERENCE||l===q.FUNCTION){const f=(i=this._definedNamesService.getDefinedNameMap(r))==null?void 0:i.get(c);f?(t+=f,n=!0):t+=c}else t+=c}return{sequenceString:t,hasDefinedName:n}}};Ne=Mn([xt(0,Xe),xt(1,ee),xt(2,D.Inject(je))],Ne);var w=(s=>(s.REFERENCE="ReferenceNode",s.VALUE="ValueNode",s.OPERATOR="OperatorNode",s.FUNCTION="FunctionNode",s.LAMBDA="LambdaNode",s.LAMBDA_PARAMETER="LambdaNodeParameter",s.ERROR="ErrorNode",s.BASE="Base",s.ROOT="Root",s.UNION="UnionNode",s.PREFIX="PrefixNode",s.SUFFIX="SuffixNode",s.NULL="NullNode",s))(w||{});const te=new Map([["ReferenceNode",7],["ValueNode",9],["OperatorNode",8],["FunctionNode",6],["LambdaNode",1],["LambdaNodeParameter",2],["Root",10],["UnionNode",3],["PrefixNode",4],["SuffixNode",5]]);class H extends m.Disposable{constructor(e){super();g(this,"_children",[]);g(this,"_parent");g(this,"_valueObject");g(this,"_calculateState",!1);g(this,"_async",!1);g(this,"_address",!1);g(this,"_refOffsetX",0);g(this,"_refOffsetY",0);this._token=e}dispose(){var e;this._children.forEach(t=>{t.dispose()}),(e=this._valueObject)==null||e.dispose(),this._parent=null}get nodeType(){return w.BASE}isAsync(){return this._async}isAddress(){return this._address}setAsync(){this._async=!0}setAddress(){this._address=!0}getParent(){return this._parent}setParent(e){this._parent=e,e.addChildren(this)}getChildren(){return this._children}addChildren(...e){this._children.push(...e)}getToken(){return this._token}setValue(e){this._valueObject=e}getValue(){return this._valueObject}isCalculated(){return this._calculateState}setCalculated(){this._calculateState=!0}execute(){}setNotEmpty(e=!0){}setRefOffset(e=0,t=0){this._refOffsetX=e,this._refOffsetY=t}getRefOffset(){return{x:this._refOffsetX,y:this._refOffsetY}}async executeAsync(){return Promise.resolve(ue.SUCCESS)}serialize(){const e=this.getToken(),t=this.getChildren(),n=[],i=t.length;for(let o=0;o<i;o++){const u=t[o];n.push(u.serialize())}const a={token:e,nodeType:this.nodeType};return i>0&&(a.children=n),a}}class B extends H{constructor(e){super(e);g(this,"_errorValueObject");this._errorValueObject=_.create(e)}get nodeType(){return w.ERROR}static create(e){return new B(e)}getValue(){return this._errorValueObject}}const re=100;class ne extends m.Disposable{get zIndex(){return 0}create(r,e,t){let n;return r instanceof L?n=r.getToken():n=r,new H(n)}checkAndCreateNodeType(r){}}class Pt extends H{get nodeType(){return w.ROOT}execute(){const e=this.getChildren()[0];this.setValue(e.getValue())}}class _r extends ne{get zIndex(){return te.get(w.ROOT)||re}checkAndCreateNodeType(r){if(!(r instanceof L))return;if(r.getToken()===oe)return new Pt(oe)}}var $=(s=>(s.COMPARE="COMPARE",s.DIVIDED="DIVIDED",s.MINUS="MINUS",s.MULTIPLY="MULTIPLY",s.PLUS="PLUS",s.UNION="UNION",s))($||{});class dr extends m.Disposable{constructor(){super(...arguments);g(this,"_functionExecutors",new Map);g(this,"_functionDescriptions",new Map)}dispose(){this._functionExecutors.clear(),this._functionDescriptions.clear()}registerExecutors(...e){for(let t=0;t<e.length;t++){const n=e[t];this._functionExecutors.set(n.name,n)}}getExecutors(){return this._functionExecutors}getExecutor(e){return this._functionExecutors.get(e)}hasExecutor(e){return this._functionExecutors.has(e)}registerDescriptions(...e){for(let t=0;t<e.length;t++){const n=e[t];this._functionDescriptions.set(n.functionName,n)}}getDescriptions(){return this._functionDescriptions}getDescription(e){return this._functionDescriptions.get(e)}hasDescription(e){return this._functionDescriptions.has(e)}}const he=D.createIdentifier("univer.formula.function.service");var vn=Object.defineProperty,xn=Object.getOwnPropertyDescriptor,Pn=(s,r,e,t)=>{for(var n=t>1?void 0:t?xn(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&vn(r,e,n),n},mr=(s,r)=>(e,t)=>r(e,t,s);class We extends H{constructor(r,e,t){super(e),this._accessor=r,this._operatorString=e,this._functionExecutor=t}get nodeType(){return w.PREFIX}execute(){let e=this.getChildren()[0].getValue(),t;if(e==null)throw new Error("object is null");e.isReferenceObject()&&(e=e.toArrayValueObject()),this._operatorString===V.MINUS?t=this._functionExecutor.calculate(new E(0),e):this._operatorString===V.AT?t=this._handlerAT(e):t=_.create(h.VALUE),this.setValue(t)}_handlerAT(r){if(!r.isReferenceObject())return _.create(h.VALUE);const e=r;if(e.isCell())return _.create(h.VALUE);const t=this._accessor.get(ee),n=t.currentRow||0,i=t.currentColumn||0;return e.isRow()?e.getCellByColumn(i):e.isColumn()?e.getCellByRow(n):e.isRange()||e.isTable()?e.getCellByPosition():_.create(h.VALUE)}}let Ze=class extends ne{constructor(s,r){super(),this._functionService=s,this._injector=r}get zIndex(){return te.get(w.PREFIX)||re}checkAndCreateNodeType(s){if(!(s instanceof L))return;const r=s.getToken(),e=r.trim();if(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;let t="";if(e===V.MINUS)t=$.MINUS;else return e===V.AT?new We(this._injector,e):void 0;const n=this._functionService.getExecutor(t);return n?new We(this._injector,e,n):(console.error(`No function ${r}`),B.create(h.NAME))}};Ze=Pn([mr(0,he),mr(1,D.Inject(D.Injector))],Ze);var Vn=Object.defineProperty,Bn=Object.getOwnPropertyDescriptor,kn=(s,r,e,t)=>{for(var n=t>1?void 0:t?Bn(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Vn(r,e,n),n},gr=(s,r)=>(e,t)=>r(e,t,s);class jn extends H{constructor(r,e){super(r),this._functionExecutor=e,this._functionExecutor.isAsync()&&this.setAsync(),this._functionExecutor.isAddress()&&this.setAddress()}get nodeType(){return w.FUNCTION}async executeAsync(){const r=[],e=this.getChildren(),t=e.length;for(let i=0;i<t;i++){const a=e[i].getValue();a!=null&&(a.isReferenceObject()?r.push(a.toArrayValueObject()):r.push(a))}const n=this._functionExecutor.calculate(...r);return n.isAsyncObject()||n.isAsyncArrayObject()?this.setValue(await n.getValue()):this.setValue(n),Promise.resolve(ue.SUCCESS)}execute(){const r=[],e=this.getChildren(),t=e.length;for(let i=0;i<t;i++){const a=e[i].getValue();a!=null&&(a.isReferenceObject()?r.push(a.toArrayValueObject()):r.push(a))}const n=this._functionExecutor.calculate(...r);this.setValue(n)}}let Je=class extends ne{constructor(s,r){super(),this._functionService=s,this._injector=r}get zIndex(){return te.get(w.FUNCTION)||re}create(s){const r=this._functionService.getExecutor(s);return r?new jn(s,r):(console.error(`No function ${s}`),B.create(h.NAME))}checkAndCreateNodeType(s){if(typeof s=="string")return;let e=s.getToken().trim().toUpperCase(),t,n;const i=e.slice(0,2);let a=0;if(new RegExp(V.MINUS,"g").test(i)){const o=this._functionService.getExecutor($.MINUS);t=new We(this._injector,V.MINUS,o),a++}if(new RegExp(V.AT,"g").test(i)&&(n=new We(this._injector,V.AT),t&&n.setParent(t),a++),a>0&&(e=e.slice(a)),this._functionService.hasExecutor(e)){const o=this.create(e);return n?o.setParent(n):t&&o.setParent(t),o}}};Je=kn([gr(0,he),gr(1,D.Inject(D.Injector))],Je);var $n=Object.defineProperty,Qn=Object.getOwnPropertyDescriptor,Gn=(s,r,e,t)=>{for(var n=t>1?void 0:t?Qn(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&$n(r,e,n),n},Hn=(s,r)=>(e,t)=>r(e,t,s);let Oe=class extends m.Disposable{constructor(s){super(),this._runtimeService=s}dispose(){}async executeAsync(s){if(!s)return _.create(h.VALUE);await this._executeAsync(s);const r=s.getValue();if(r==null)throw new Error("node value is null");return Promise.resolve(r)}execute(s){if(!s)return _.create(h.VALUE);this._execute(s);const r=s.getValue();if(r==null)throw new Error("node value is null");return r}executePreCalculateNode(s){return s.execute(),s.getValue()}checkAsyncNode(s){const r=[];this._checkAsyncNode(s,r);for(let e=0,t=r.length;e<t;e++)if(r[e]===!0)return!0;return!1}_checkAsyncNode(s,r){const e=s.getChildren(),t=e.length;for(let n=0;n<t;n++){const i=e[n];r.push(i.isAsync()),this._checkAsyncNode(i,r)}}async _executeAsync(s){if(this._runtimeService.isStopExecution())return Promise.resolve(ue.ERROR);const r=s.getChildren(),e=r.length;for(let t=0;t<e;t++){const n=r[t];if(n.getToken().toUpperCase()===Ie&&n.isEmptyParamFunction()){await n.executeAsync();continue}await this._executeAsync(n)}return s.nodeType===w.FUNCTION&&s.isAsync()?await s.executeAsync():s.execute(),Promise.resolve(ue.SUCCESS)}_execute(s){if(this._runtimeService.isStopExecution())return ue.ERROR;const r=s.getChildren(),e=r.length;for(let t=0;t<e;t++){const n=r[t];if(n.getToken().toUpperCase()===Ie&&n.isEmptyParamFunction()){n.execute();continue}this._execute(n)}return s.execute(),ue.SUCCESS}};Oe=Gn([Hn(0,ee)],Oe);function Cr(s){return s instanceof L?s.getToken()===be:!1}function Yn(s){return s instanceof L?s.getToken()===Kt:!1}class Er extends le{constructor(e,t,n){super(0);g(this,"_lambdaPrivacyValueMap",new Map);this._lambdaNode=e,this._interpreter=t,this._lambdaPrivacyVarKeys=n,this._lambdaPrivacyValueMap.clear()}isLambda(){return!0}execute(...e){const t=this._lambdaPrivacyVarKeys.length;if(e.length!==t)return new _(h.VALUE);this._setLambdaPrivacyValueMap(e),this._setLambdaNodeValue(this._lambdaNode),this._lambdaNode.setNotEmpty(!1);let n;if(this._interpreter.checkAsyncNode(this._lambdaNode))n=new hn(this._interpreter.executeAsync(this._lambdaNode));else{const i=this._interpreter.execute(this._lambdaNode);i.isReferenceObject()?n=i.toArrayValueObject():n=i}return this._lambdaNode.setNotEmpty(!0),n}_setLambdaNodeValue(e){const t=e.getChildren(),n=t.length;for(let i=0;i<n;i++){const a=t[i];if(a.getToken()===ke){const u=a.getLambdaParameter(),l=this._lambdaPrivacyValueMap.get(u);l&&a.setValue(l);continue}this._setLambdaNodeValue(a)}}_setLambdaPrivacyValueMap(e){for(let t=0;t<e.length;t++){const n=e[t],i=this._lambdaPrivacyVarKeys[t];this._lambdaPrivacyValueMap.set(i,n)}}}var qn=Object.defineProperty,zn=Object.getOwnPropertyDescriptor,Kn=(s,r,e,t)=>{for(var n=t>1?void 0:t?zn(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&qn(r,e,n),n},pr=(s,r)=>(e,t)=>r(e,t,s);class Xn extends H{constructor(e,t,n,i){super(e);g(this,"_isNotEmpty",!0);this._lambdaId=t,this._interpreter=n,this._lambdaPrivacyVarKeys=i}get nodeType(){return w.LAMBDA}setNotEmpty(e=!1){this._isNotEmpty=e}isEmptyParamFunction(){return this.getChildren().length<2&&this._isNotEmpty}isFunctionParameter(){return this._lambdaId===null}getLambdaId(){return this._lambdaId}execute(){if(this.isEmptyParamFunction())this.setValue(new Er(this,this._interpreter,this._lambdaPrivacyVarKeys));else{const e=this.getChildren(),t=e.length;this.setValue(e[t-1].getValue())}}async executeAsync(){if(this.isEmptyParamFunction())await this.setValue(new Er(this,this._interpreter,this._lambdaPrivacyVarKeys));else{const e=this.getChildren(),t=e.length;await this.setValue(e[t-1].getValue())}return Promise.resolve(ue.SUCCESS)}}let et=class extends ne{constructor(s,r){super(),this._runtimeService=s,this._interpreter=r}get zIndex(){return te.get(w.LAMBDA)||re}create(s){const r=s.getChildren(),e=r[0];let t=r.slice(1,-1);const n=r[r.length-1];if(!(e instanceof L&&n instanceof L))return B.create(h.NAME);if(e.getToken()===be){const o=e.getChildren();if(t.length!==o.length)return B.create(h.VALUE)}else t=r.slice(0,-1);const i=m.Tools.generateRandomId(8),a=new Map;for(let o=0;o<t.length;o++){const u=t[o];if(u instanceof L){const l=u.getChildren()[0];u.setToken(Kt),a.set(l.trim(),void 0)}else return B.create(h.VALUE)}return this._runtimeService.registerFunctionDefinitionPrivacyVar(i,a),this._updateLambdaStatement(n,i,a),new Xn(s.getToken(),i,this._interpreter,[...a.keys()])}checkAndCreateNodeType(s){if(!(!(s instanceof L)||s.getToken().trim().toUpperCase()!==Ie))return this.create(s)}_updateLambdaStatement(s,r,e){this._updateTree(s,r,e)}_updateTree(s,r,e){const t=s.getChildren(),n=t.length,i=t[0];for(let a=0;a<n;a++){const o=t[a];if(!(Cr(i)&&a!==0))if(o instanceof L)this._updateTree(o,r,e);else{const u=o.trim();if(e.has(u)){const l=new L;l.setToken(ke),l.setLambdaId(r),l.setLambdaPrivacyVar(e),l.setLambdaParameter(u),t[a]=l}}}}};et=Kn([pr(0,ee),pr(1,D.Inject(Oe))],et);class Wn extends H{constructor(r,e,t){super(r),this._lambdaParameter=e,this._currentLambdaPrivacyVar=t}getLambdaParameter(){return this._lambdaParameter}getCurrentLambdaPrivacyVar(){return this._currentLambdaPrivacyVar}get nodeType(){return w.LAMBDA_PARAMETER}execute(){const r=this._getRootLexerNode(this._currentLambdaPrivacyVar.get(this._lambdaParameter));if(r)this.setValue(r.getValue());else{const e=this.getValue();(e==null||e.isError())&&this.setValue(_.create(h.SPILL))}}_getRootLexerNode(r){if(!r)return;if(r.getToken()!==ke)return r;const e=r,t=e.getCurrentLambdaPrivacyVar(),n=e.getLambdaParameter();if(t)return this._getRootLexerNode(t.get(n))}}class Nr extends ne{get zIndex(){return te.get(w.LAMBDA_PARAMETER)||re}create(r){const e=r.getFunctionDefinitionPrivacyVar(),t=r.getLambdaParameter();return e?new Wn(r.getToken(),t,e):new B(h.SPILL)}checkAndCreateNodeType(r){if(!(!(r instanceof L)||r.getToken().trim()!==ke))return this.create(r)}}class Zn extends H{constructor(r){super(r),this._operatorString=r}get nodeType(){return w.NULL}execute(){this.setValue(new hr(0))}}var Jn=Object.defineProperty,es=Object.getOwnPropertyDescriptor,ts=(s,r,e,t)=>{for(var n=t>1?void 0:t?es(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Jn(r,e,n),n},rs=(s,r)=>(e,t)=>r(e,t,s);class ns extends H{constructor(r,e){super(r),this._operatorString=r,this._functionExecutor=e}get nodeType(){return w.OPERATOR}execute(){const r=this.getChildren();this._functionExecutor.name===$.COMPARE&&this._functionExecutor.setCompareType(this.getToken());let e=r[0].getValue(),t=r[1].getValue();if(e==null||t==null)throw new Error("object1 or object2 is null");e.isReferenceObject()&&(e=e.toArrayValueObject()),t.isReferenceObject()&&(t=t.toArrayValueObject()),this.setValue(this._functionExecutor.calculate(e,t))}}let tt=class extends ne{constructor(s){super(),this._functionService=s}get zIndex(){return te.get(w.OPERATOR)||re}create(s){let r="";const e=s;e===G.PLUS?r=$.PLUS:e===G.MINUS?r=$.MINUS:e===G.MULTIPLY?r=$.MULTIPLY:e===G.DIVIDED?r=$.DIVIDED:e===G.CONCATENATE?r=ze.CONCATENATE:e===G.POWER?r=X.POWER:Ir.has(e)&&(r=$.COMPARE);const t=this._functionService.getExecutor(r);return t?new ns(e,t):(console.error(`No function ${s}`),B.create(h.NAME))}checkAndCreateNodeType(s){if(s instanceof L)return;const r=s.trim();if(!(r.charAt(0)==='"'&&r.charAt(r.length-1)==='"')&&Ue.has(r))return this.create(r)}};tt=ts([rs(0,he)],tt);class ss extends m.Disposable{constructor(){super(...arguments);g(this,"_tableMap",new Map);g(this,"_tableOptionMap",new Map)}dispose(){this._tableMap.clear(),this._tableOptionMap.clear()}remove(e,t){var n;(n=this._tableMap.get(e))==null||n.delete(t)}getTableMap(e){return this._tableMap.get(e)}getTableOptionMap(){return this._tableOptionMap}registerTable(e,t,n){var i;this._tableMap.get(e)==null&&this._tableMap.set(e,new Map),(i=this._tableMap.get(e))==null||i.set(t,n)}registerTableOptionMap(e,t){this._tableOptionMap.set(e,t)}}const Vt=D.createIdentifier("univer.formula.super-table.service");class Bt extends Le{constructor(r){super(r);const e=m.deserializeRangeWithSheet(r);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName),this.setRangeData(e.range)}isCell(){return!0}unionBy(r){if(!r.isCell())return _.create(h.REF);const e=r,t=this.unionRange(this.getRangeData(),e.getRangeData());return this._createRange(t)}unionRange(r,e){const t=r.startRow,n=r.startColumn,i=e.startRow,a=e.startColumn,o={startRow:-1,startColumn:-1,endRow:-1,endColumn:-1};return t>i?(o.startRow=i,o.endRow=t):(o.startRow=t,o.endRow=i),n>a?(o.startColumn=a,o.endColumn=n):(o.startColumn=n,o.endColumn=a),o}_createRange(r){const e=new fr(r,this.getForcedSheetId(),this.getForcedUnitId());e.setUnitData(this.getUnitData()),e.setDefaultSheetId(this.getDefaultSheetId()),e.setDefaultUnitId(this.getDefaultUnitId()),e.setRuntimeData(this.getRuntimeData()),e.setArrayFormulaCellData(this.getArrayFormulaCellData()),e.setRuntimeArrayFormulaCellData(this.getRuntimeArrayFormulaCellData()),e.setRuntimeFeatureCellData(this.getRuntimeFeatureCellData());const{x:t,y:n}=this.getRefOffset();e.setRefOffset(t,n);const i=this.getForcedSheetId();e.setForcedSheetName(this.getForcedSheetName()),i!=null&&e.setForcedSheetIdDirect(i);const a=this.getForcedUnitId();return a&&e.setForcedUnitIdDirect(a),e}}class is extends Le{constructor(r){super(r);const e=m.deserializeRangeWithSheet(r);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const t={startColumn:e.range.startColumn,startRow:-1,endColumn:-1,endRow:-1};this.setRangeData(t)}isColumn(){return!0}unionBy(r){if(!r.isColumn())return _.create(h.REF);const e=r;if(e.getForcedSheetName()!==void 0)return _.create(h.REF);const t=this.getRangeData();if(t.endColumn!==-1)return _.create(h.REF);const n=e.getRangeData().startColumn,i=t.startColumn;return n>i?t.endColumn=n:(t.startColumn=n,t.endColumn=i),this}}class as extends Le{constructor(r){super(r);const e=m.deserializeRangeWithSheet(r);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const t={startColumn:-1,startRow:e.range.startRow,endColumn:-1,endRow:-1};this.setRangeData(t)}isRow(){return!0}unionBy(r){if(!r.isRow())return _.create(h.REF);const e=r;if(e.getForcedSheetName()!==void 0)return _.create(h.REF);const t=this.getRangeData();if(t.endRow!==-1)return _.create(h.REF);const n=e.getRangeData().startRow,i=t.startRow;return n>i?t.endRow=n:(t.startRow=n,t.endRow=i),this}}class os extends Le{constructor(r,e,t,n){super(r),this._tableData=e,this._columnDataString=t;const i=this._tableData.sheetId,a=this._tableData.range,o=this._tableData.titleMap;this.setForcedSheetIdDirect(i);const u=this._stringToColumnData(this._columnDataString,o,n),l=u.startColumn,c=u.endColumn,f=u.type;let d=-1,p=-1;const R=a.startRow,C=a.startColumn;f===me.ALL?(d=R,p=C):f===me.DATA?(d=R+1,p=C):f===me.HEADERS?(d=R,p=R):f===me.TOTALS&&(d=C,p=C),this.setRangeData({startColumn:l,endColumn:c,startRow:d,endRow:p})}isTable(){return!0}_stringToColumnData(r,e,t){r=r.substring(1,-1);const n=r.indexOf(T.COMMA);let i=-1,a=-1,o=me.ALL;if(n===-1){const u=this._columnHandler(r,e);i=u.startColumn,a=u.endColumn}else{const u=r.substring(0,n).substring(1,-1),l=r.substring(n+1),c=this._columnHandler(l,e,!0);i=c.startColumn,a=c.endColumn,o=t.get(u),o||(o=me.ALL)}return{startColumn:i,endColumn:a,type:o}}_columnHandler(r,e,t=!1){let n=-1,i=-1;const a=r.indexOf(T.COLON);if(new RegExp(zt,"g").test(r)){const o=r.substring(0,a).substring(1,-1),u=r.substring(a+1).substring(1,-1);n=e.get(o)??-1,i=e.get(u)??-1}else t&&(r=r.substring(1,-1)),n=e.get(r)??-1,i=n;return{startColumn:n,endColumn:i}}}var us=Object.defineProperty,ls=Object.getOwnPropertyDescriptor,cs=(s,r,e,t)=>{for(var n=t>1?void 0:t?ls(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&us(r,e,n),n},ve=(s,r)=>(e,t)=>r(e,t,s);class rt extends H{constructor(r,e,t){super(e),this._accessor=r,this._operatorString=e,this._referenceObject=t}get nodeType(){return w.REFERENCE}execute(){const r=this._accessor.get(we),e=this._accessor.get(ee);this._referenceObject.setDefaultUnitId(e.currentUnitId),this._referenceObject.setDefaultSheetId(e.currentSubComponentId),this._referenceObject.setForcedSheetId(r.getSheetNameMap()),this._referenceObject.setUnitData(r.getUnitData()),this._referenceObject.setArrayFormulaCellData(r.getArrayFormulaCellData()),this._referenceObject.setRuntimeData(e.getUnitData()),this._referenceObject.setRuntimeArrayFormulaCellData(e.getRuntimeArrayFormulaCellData()),this._referenceObject.setRuntimeFeatureCellData(e.getRuntimeFeatureCellData());const{x:t,y:n}=this.getRefOffset();this._referenceObject.setRefOffset(t,n),this.setValue(this._referenceObject)}}let nt=class extends ne{constructor(s,r,e,t,n){super(),this._definedNamesService=s,this._superTableService=r,this._formulaRuntimeService=e,this._lexer=t,this._injector=n}get zIndex(){return te.get(w.REFERENCE)||re}checkAndCreateNodeType(s){let r=!1,e;if(s instanceof L?(r=!0,e=s.getToken().trim()):e=s.trim(),!r&&e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;if(new RegExp(Et).test(e))return new rt(this._injector,e,new Bt(e));if(r&&new RegExp(kr).test(e))return new rt(this._injector,e,new as(e));if(r&&new RegExp(jr).test(e))return new rt(this._injector,e,new is(e));const t=this._formulaRuntimeService.currentUnitId,n=this._superTableService.getTableMap(t),i=new RegExp(zt,"g"),a=e.replace(i,"");if(!r&&(n!=null&&n.has(a))){const o=i.exec(e);let u="";o&&(u=o[0]);const l=n.get(a),c=this._superTableService.getTableOptionMap();return new rt(this._injector,e,new os(e,l,u,c))}}};nt=cs([ve(0,Xe),ve(1,Vt),ve(2,ee),ve(3,D.Inject(Ne)),ve(4,D.Inject(D.Injector))],nt);var hs=Object.defineProperty,fs=Object.getOwnPropertyDescriptor,_s=(s,r,e,t)=>{for(var n=t>1?void 0:t?fs(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&hs(r,e,n),n},Ar=(s,r)=>(e,t)=>r(e,t,s);class Rr extends H{constructor(r,e,t){super(e),this._accessor=r,this._operatorString=e,this._functionExecutor=t}get nodeType(){return w.SUFFIX}execute(){let e=this.getChildren()[0].getValue(),t;if(e==null)throw new Error("object is null");this._operatorString===ie.PERCENTAGE?(e.isReferenceObject()&&(e=e.toArrayValueObject()),t=this._functionExecutor.calculate(e,new E(100))):this._operatorString===ie.POUND?t=this._handlerPound(e):t=_.create(h.VALUE),this.setValue(t)}_handlerPound(r){var c,f,d,p;if(!r.isReferenceObject()||!r.isCell())return _.create(h.VALUE);const e=this._accessor.get(we),t=this._accessor.get(Ne),n=r,i=n.getRangeData(),a=n.getUnitId(),o=n.getSheetId(),u=e.getFormulaData(),l=(p=(d=(f=(c=u==null?void 0:u[a])==null?void 0:c[o])==null?void 0:f[i.startRow])==null?void 0:d[i.startColumn])==null?void 0:p.f;return l&&t.treeBuilder(l),_.create(h.VALUE)}}let st=class extends ne{constructor(s,r){super(),this._functionService=s,this._injector=r}get zIndex(){return te.get(w.SUFFIX)||re}checkAndCreateNodeType(s){if(!(s instanceof L))return;const r=s.getToken().trim();if(r.charAt(0)==='"'&&r.charAt(r.length-1)==='"')return;let e="";if(r===ie.PERCENTAGE)e=$.DIVIDED;else return r===ie.POUND?new Rr(this._injector,r):void 0;const t=this._functionService.getExecutor(e);return t?new Rr(this._injector,r,t):(console.error(`No function ${s}`),B.create(h.NAME))}};st=_s([Ar(0,he),Ar(1,D.Inject(D.Injector))],st);var ds=Object.defineProperty,ms=Object.getOwnPropertyDescriptor,gs=(s,r,e,t)=>{for(var n=t>1?void 0:t?ms(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&ds(r,e,n),n},Cs=(s,r)=>(e,t)=>r(e,t,s);class Es extends H{constructor(r){super(r),this._operatorString=r}get nodeType(){return w.UNION}execute(){const r=this.getChildren(),e=r[0].getValue(),t=r[1].getValue();if(e==null||t==null)throw new Error("leftNode and rightNode");let n;this._operatorString===T.COLON?n=this._unionFunction(e,t):n=_.create(h.NAME),this.setValue(n)}_unionFunction(r,e){return r.isError()||e.isError()||!r.isReferenceObject()||!e.isReferenceObject()?_.create(h.REF):(r=r,e=e,r.isCell()&&e.isCell()||r.isRow()&&e.isRow()||r.isColumn()&&e.isColumn()?r.unionBy(e):_.create(h.REF))}}let it=class extends ne{constructor(s){super(),this._functionService=s}get zIndex(){return te.get(w.UNION)||re}create(s){return new Es(s)}checkAndCreateNodeType(s){if(!(s instanceof L))return;const e=s.getToken().trim();if(!(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')&&e===T.COLON)return this.create(e)}};it=gs([Cs(0,he)],it);class ps extends H{constructor(r){super(r),this._operatorString=r}get nodeType(){return w.VALUE}execute(){this.setValue(Fe.create(this._operatorString))}}class Sr extends ne{get zIndex(){return te.get(w.VALUE)||re}_checkValueNode(r){if(isNaN(Number(r))){const e=r.trim(),t=e.charAt(0),n=e.charAt(e.length-1);if(t==='"'&&n==='"')return this.create(e);if(t==="{"&&n==="}")return this.create(e);if(e===de.TRUE||e===de.FALSE)return this.create(e)}else return this.create(r)}create(r){return new ps(r)}checkAndCreateNodeType(r){if(!(r instanceof L))return this._checkValueNode(r)}}var Ns=Object.defineProperty,As=Object.getOwnPropertyDescriptor,Rs=(s,r,e,t)=>{for(var n=t>1?void 0:t?As(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Ns(r,e,n),n},W=(s,r)=>(e,t)=>r(e,t,s);let xe=class extends m.Disposable{constructor(r,e,t,n,i,a,o,u,l,c,f){super();g(this,"_astNodeFactoryList",[]);g(this,"_refOffsetX",0);g(this,"_refOffsetY",0);this._runtimeService=r,this._astRootNodeFactory=e,this._functionNodeFactory=t,this._lambdaNodeFactory=n,this._lambdaParameterNodeFactory=i,this._operatorNodeFactory=a,this._prefixNodeFactory=o,this._referenceNodeFactory=u,this._suffixNodeFactory=l,this._unionNodeFactory=c,this._valueNodeFactory=f,this._initializeAstNode()}dispose(){this._astNodeFactoryList.forEach(r=>{r.dispose()}),this._astNodeFactoryList=[]}parse(r,e=0,t=0){const n=new Pt(oe);return this._refOffsetX=e,this._refOffsetY=t,this._parse(r,n)}_lambdaParameterHandler(r,e){const t=e.getLambdaId(),n=new Pt(oe),i=this._runtimeService.getFunctionDefinitionPrivacyVar(t);if(!i)return!1;const a=[...i.keys()],o=r.getChildren(),u=o.length;for(let f=0;f<u;f++){const d=o[f];if(d instanceof L)this._parse(d,n);else return!1}const l=n.getChildren(),c=l.length;for(let f=0;f<c;f++){const d=l[f];i.set(a[f],d)}return n.setParent(e),e}_changeLetToLambda(r){const e=r.getChildren(),t=e.length;if(t%2!==1||t===0)return;const n=new L;n.setToken(Ie);const i=new L;i.setToken(be);const a=[...e];for(let u=0;u<t;u++){const l=a[u];if(!(l instanceof L))return;u%2===0?l.changeToParent(n):l.changeToParent(i)}n.addChildrenFirst(i),i.setParent(n);const o=r.getParent();return o==null||o.replaceChild(r,n),n}_getTopParent(r){let e=r;for(;e!=null&&e.getParent();)e=e.getParent();return e}_parse(r,e){const t=r.getChildren(),n=t.length,i=[];let a=null;const o=r.getToken().trim().toUpperCase();if(o===Gr){const c=this._changeLetToLambda(r);return c!=null?this._parse(c,e):B.create(h.ERROR)}if(o===_e){if(a=e,n===0)return new Zn(oe).setParent(e),a}else{if(o===be){let c=this._lambdaParameterHandler(r,e);return c===!1&&(c=B.create(h.ERROR)),c}if(a=this._checkAstNode(r),a==null)return B.create(h.ERROR)}const u=t[0];for(let c=0;c<n;c++){const f=t[c];if(Cr(u)){if(c!==0&&c!==n-1)continue}else if(Yn(f)&&c!==n-1)continue;let d=null;if(f instanceof L){if(d=this._parse(f,a),d===a)continue}else d=this._checkAstNode(f);if(d==null)return B.create(h.ERROR);if(d=this._getTopParent(d),d==null)return;switch(d.nodeType){case w.ERROR:return d;case w.FUNCTION:i.push(d);break;case w.LAMBDA:i.push(d);break;case w.LAMBDA_PARAMETER:i.push(d);break;case w.OPERATOR:{const p=i.pop(),R=i.pop();if(R)R.setParent(d);else return B.create(h.ERROR);if(p)p.setParent(d);else return B.create(h.ERROR);i.push(d);break}case w.REFERENCE:d.setRefOffset(this._refOffsetX,this._refOffsetY),i.push(d);break;case w.ROOT:i.push(d);break;case w.UNION:i.push(d);break;case w.VALUE:i.push(d);break;case w.PREFIX:i.push(d);break;case w.SUFFIX:i.push(d);break}}const l=i.length;for(let c=0;c<l;c++)i[c].setParent(a);return a}_checkAstNode(r){let e=null;const t=this._astNodeFactoryList.length;for(let n=0;n<t&&(e=this._astNodeFactoryList[n].checkAndCreateNodeType(r),e==null);n++);return e}_initializeAstNode(){this._astNodeFactoryList=[this._astRootNodeFactory,this._functionNodeFactory,this._lambdaNodeFactory,this._lambdaParameterNodeFactory,this._operatorNodeFactory,this._prefixNodeFactory,this._referenceNodeFactory,this._suffixNodeFactory,this._unionNodeFactory,this._valueNodeFactory].sort(m.sortRules)}};xe=Rs([W(0,ee),W(1,D.Inject(_r)),W(2,D.Inject(Je)),W(3,D.Inject(et)),W(4,D.Inject(Nr)),W(5,D.Inject(tt)),W(6,D.Inject(Ze)),W(7,D.Inject(nt)),W(8,D.Inject(st)),W(9,D.Inject(it)),W(10,D.Inject(Sr))],xe);class yr extends m.Disposable{constructor(){super(...arguments);g(this,"_referenceExecutorMap",new Map)}dispose(){this._referenceExecutorMap.clear()}remove(e){this._referenceExecutorMap.delete(e)}get(e){return this._referenceExecutorMap.get(e)}has(e){return this._referenceExecutorMap.has(e)}register(e,t){this._referenceExecutorMap.set(e,t)}getReferenceExecutorMap(){return this._referenceExecutorMap}}const at=D.createIdentifier("univer.formula.feature-calculation-manager.service");class br extends m.Disposable{constructor(){super(...arguments);g(this,"_otherFormulaData",{})}dispose(){this._otherFormulaData={}}remove(e){var a,o,u;const{unitId:t,subComponentId:n,formulaId:i}=e;(u=(o=(a=this._otherFormulaData)==null?void 0:a[t])==null?void 0:o[n])==null||delete u[i]}get(e){var a,o;const{unitId:t,subComponentId:n,formulaId:i}=e;return(o=(a=this._otherFormulaData[t])==null?void 0:a[n])==null?void 0:o[i]}has(e){var a,o;const{unitId:t,subComponentId:n,formulaId:i}=e;return((o=(a=this._otherFormulaData[t])==null?void 0:a[n])==null?void 0:o[i])!=null}register(e){const{unitId:t,subComponentId:n,formulaId:i,item:a}=e;this._otherFormulaData[t]&&(this._otherFormulaData[t]={}),this._otherFormulaData[t][n]&&(this._otherFormulaData[t][n]={}),this._otherFormulaData[t][n][i]=a}getOtherFormulaData(){return this._otherFormulaData}}const kt=D.createIdentifier("univer.formula.other-formula-manager.service");class jt extends m.Disposable{constructor(){super(...arguments);g(this,"node");g(this,"children",[]);g(this,"parents",[]);g(this,"formula","");g(this,"row",-1);g(this,"column",-1);g(this,"subComponentId","");g(this,"unitId","");g(this,"rangeList",[]);g(this,"formulaId");g(this,"featureId");g(this,"getDirtyData");g(this,"_state",0)}dispose(){var e;this.children.forEach(t=>{t.dispose()}),this.rangeList=[],this.parents=[],(e=this.node)==null||e.dispose()}setAdded(){this._state=1}isAdded(){return this._state===1}setSkip(){this._state=2}isSkip(){return this._state===2}inRangeData(e){const t=e.startRow,n=e.startColumn,i=e.endRow,a=e.endColumn;return!(this.row<t||this.row>i||this.column<n||this.column>a)}dependencyRange(e,t,n){var i,a;if(this.rangeList.length===0)return!1;for(let o=0,u=this.rangeList.length;o<u;o++){const l=this.rangeList[o],{unitId:c,sheetId:f,range:d}=l;if(!e.has(c))continue;const p=e.get(c);if(!p.has(f))continue;const R=p.get(f),C=(i=n==null?void 0:n[c])==null?void 0:i[f];for(const N of R){const{startRow:y,startColumn:b,endRow:U,endColumn:F}=N;if(!(d.startRow>U||d.endRow<y||d.startColumn>F||d.endColumn<b)){let Y=!0;if(C==null||C.forValue((fe,z)=>{if(fe>=d.startRow&&fe<=d.endRow&&z>=d.startColumn&&z<=d.endColumn)return Y=!1,!1}),Y)return!0}}if(((a=t[c])==null?void 0:a[f])!=null)return!0}return!1}pushChildren(e){this.children.push(e),e._pushParent(this)}pushRangeList(e){this.rangeList.push(e)}dependency(e){if(this.rangeList.length===0)return!1;for(let t=0,n=this.rangeList.length;t<n;t++){const i=this.rangeList[t],a=i.unitId,o=i.sheetId,u=i.range;if(e.unitId===a&&e.subComponentId===o&&e.inRangeData(u))return!0}return!1}_pushParent(e){this.parents.push(e)}}var Ss=Object.defineProperty,ys=Object.getOwnPropertyDescriptor,bs=(s,r,e,t)=>{for(var n=t>1?void 0:t?ys(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Ss(r,e,n),n},Ae=(s,r)=>(e,t)=>r(e,t,s);const Ds=1e5,$t=new Be(Ds);let Pe=class extends m.Disposable{constructor(r,e,t,n,i,a,o){super();g(this,"_updateRangeFlattenCache",new Map);g(this,"_dirtyUnitSheetNameMap",{});this._currentConfigService=r,this._runtimeService=e,this._otherFormulaManagerService=t,this._featureCalculationManagerService=n,this._interpreter=i,this._astTreeBuilder=a,this._lexer=o}dispose(){this._updateRangeFlattenCache.clear(),$t.clear(),this._dirtyUnitSheetNameMap={}}async generate(){this._updateRangeFlatten();const r=this._currentConfigService.getFormulaData(),e=this._otherFormulaManagerService.getOtherFormulaData(),t=await this._generateTreeList(r,e),n=this._getUpdateTreeListAndMakeDependency(t);this._checkIsCycleDependency(n)&&this._runtimeService.enableCycleDependency();const a=this._calculateRunList(n);return Promise.resolve(a)}_isCyclicUtil(r,e,t){if(!e.has(r)){e.add(r),t.add(r);for(let n=0;n<r.children.length;n++)if(!e.has(r.children[n])&&this._isCyclicUtil(r.children[n],e,t)||t.has(r.children[n]))return!0}return t.delete(r),!1}_checkIsCycleDependency(r){const e=new Set,t=new Set;for(let n=0,i=r.length;n<i;n++){const a=r[n];if(this._isCyclicUtil(a,e,t)===!0)return!0}return!1}async _generateTreeList(r,e){const t=Object.keys(r),n=Object.keys(e),i=[];for(const a of t){const o=r[a],u=Object.keys(o);for(const l of u)new m.ObjectMatrix(o[l]).forValue((f,d,p)=>{if(p==null)return!0;const{f:R,x:C,y:N}=p,y=this._generateAstNode(R,C,N),b=new jt;b.node=y,b.formula=R,b.unitId=a,b.subComponentId=l,b.row=f,b.column=d,i.push(b)})}for(const a of n){const o=e[a],u=Object.keys(o);for(const l of u){const c=o[l],f=Object.keys(c);for(const d of f){const p=c[d],{f:R}=p,C=this._generateAstNode(R),N=new jt;N.node=C,N.formula=R,N.unitId=a,N.subComponentId=l,N.formulaId=d,i.push(N)}}}this._featureCalculationManagerService.getReferenceExecutorMap().forEach((a,o)=>{const{unitId:u,subComponentId:l,dependencyRanges:c,getDirtyData:f}=a,d=new jt;d.unitId=u,d.subComponentId=l,d.getDirtyData=f,d.featureId=o,d.rangeList=c,i.push(d)});for(let a=0,o=i.length;a<o;a++){const u=i[a];if(this._runtimeService.setCurrent(u.row,u.column,u.subComponentId,u.unitId),u.node==null)continue;const l=await this._getRangeListByNode(u.node);for(let c=0,f=l.length;c<f;c++)u.pushRangeList(l[c])}return i}_updateRangeFlatten(){const r=this._currentConfigService.isForceCalculate(),e=this._currentConfigService.getDirtyRanges();if(!r){this._updateRangeFlattenCache.clear();for(let t=0;t<e.length;t++){const n=e[t],i=n.range,a=n.sheetId,o=n.unitId;this._addFlattenCache(o,a,i)}this._dirtyUnitSheetNameMap=this._currentConfigService.getDirtyNameMap()}}_generateAstNode(r,e=0,t=0){let n=$t.get(`${r}##${e}${t}`);if(n)return n;const i=this._lexer.treeBuilder(r);if(i in h)return B.create(i);if(n=this._astTreeBuilder.parse(i,e,t),n==null)throw new Error("astNode is null");return $t.set(`${r}##${e}${t}`,n),n}_addFlattenCache(r,e,t){let n=this._updateRangeFlattenCache.get(r);n==null&&(n=new Map,this._updateRangeFlattenCache.set(r,n));let i=n.get(e);i==null&&(i=[],n.set(e,i)),i.push(t)}_isPreCalculateNode(r){return r.nodeType===w.UNION||r.nodeType===w.PREFIX&&r.getToken()===V.AT||r.nodeType===w.SUFFIX&&r.getToken()===ie.POUND}_nodeTraversalRef(r,e){const t=r.getChildren(),n=t.length;for(let i=0;i<n;i++){const a=t[i];if(this._isPreCalculateNode(a)){e.push(a);continue}else a.nodeType===w.REFERENCE&&e.push(a);this._nodeTraversalRef(a,e)}}_nodeTraversalReferenceFunction(r,e){const t=r.getChildren(),n=t.length;for(let i=0;i<n;i++){const a=t[i];if(a.nodeType===w.FUNCTION&&a.isAddress()){e.push(a);continue}this._nodeTraversalReferenceFunction(a,e)}}async _executeNode(r){let e;return this._interpreter.checkAsyncNode(r)?e=await this._interpreter.executeAsync(r):e=this._interpreter.execute(r),e}async _getRangeListByNode(r){const e=[],t=[];this._nodeTraversalRef(r,e),this._nodeTraversalReferenceFunction(r,t);const n=[];for(let i=0,a=e.length;i<a;i++){const o=e[i],l=(await this._executeNode(o)).toUnitRange();n.push(l)}for(let i=0,a=t.length;i<a;i++){const o=t[i],l=(await this._executeNode(o)).toUnitRange();n.push(l)}return n}_getUpdateTreeListAndMakeDependency(r){const e=[],t=new Set,n=this._currentConfigService.isForceCalculate();for(let i=0,a=r.length;i<a;i++){const o=r[i];for(let u=0,l=r.length;u<l;u++){const c=r[u];o!==c&&o.dependency(c)&&o.pushChildren(c)}(n||o.dependencyRange(this._updateRangeFlattenCache,this._dirtyUnitSheetNameMap,this._currentConfigService.getExcludedRange())||this._includeTree(o))&&!t.has(o)&&(e.push(o),t.add(o))}return e}_includeTree(r){var l,c,f,d;const e=r.unitId,t=r.subComponentId,n=r.featureId;if(n!=null){const p=this._currentConfigService.getDirtyUnitFeatureMap();if(((c=(l=p==null?void 0:p[e])==null?void 0:l[t])==null?void 0:c[n])!=null)return!0}const i=(d=(f=this._currentConfigService.getExcludedRange())==null?void 0:f[e])==null?void 0:d[t];let a=!1;if(i==null||i.forValue((p,R)=>{if(r.row===p&&r.column===R)return a=!0,!1}),a||!this._updateRangeFlattenCache.has(e))return!1;const o=this._updateRangeFlattenCache.get(e);if(!o.has(t))return!1;const u=o.get(t);for(const p of u)if(r.inRangeData(p))return!0;return!1}_calculateRunList(r){let e=r;const t=[];for(;e.length>0;){const n=e.pop();if(n===void 0||n.isSkip())continue;if(n.isAdded()){t.push(n);continue}const i=[];for(let a=0,o=n.parents.length;a<o;a++){const u=n.parents[a];i.push(u)}i.length===0?(t.push(n),n.setSkip()):(n.setAdded(),e.push(n),e=e.concat(i))}return t.reverse()}};Pe=bs([m.OnLifecycle(m.LifecycleStages.Rendered,Pe),Ae(0,we),Ae(1,ee),Ae(2,kt),Ae(3,at),Ae(4,D.Inject(Oe)),Ae(5,D.Inject(xe)),Ae(6,D.Inject(Ne))],Pe);var Fs=Object.defineProperty,Ls=Object.getOwnPropertyDescriptor,ws=(s,r,e,t)=>{for(var n=t>1?void 0:t?Ls(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Fs(r,e,n),n},Re=(s,r)=>(e,t)=>r(e,t,s);const Ts=1;A.CalculateFormulaService=class extends m.Disposable{constructor(e,t,n,i,a,o,u){super();g(this,"_executionStartListener$",new dt.Subject);g(this,"executionStartListener$",this._executionStartListener$.asObservable());g(this,"_executionCompleteListener$",new dt.Subject);g(this,"executionCompleteListener$",this._executionCompleteListener$.asObservable());g(this,"_executionInProgressListener$",new dt.Subject);g(this,"executionInProgressListener$",this._executionInProgressListener$.asObservable());this._configService=e,this._lexer=t,this._currentConfigService=n,this._runtimeService=i,this._formulaDependencyGenerator=a,this._interpreter=o,this._astTreeBuilder=u}dispose(){}stopFormulaExecution(){this._runtimeService.stopExecution()}setRuntimeFeatureCellData(e,t){this._runtimeService.setRuntimeFeatureCellData(e,t)}setRuntimeFeatureRange(e,t){this._runtimeService.setRuntimeFeatureRange(e,t)}async execute(e){this._executionStartListener$.next(!0),this._currentConfigService.load(e),this._runtimeService.reset();const t=this._configService.getConfig("CYCLE_REFERENCE_COUNT")||Ts;for(let n=0;n<t&&(await this._execute(),!!this._runtimeService.isCycleDependency());n++);this._runtimeService.setFormulaExecuteStage(J.CALCULATION_COMPLETED),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState()),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData()),Ut.clear(),ge.clear()}async _execute(){const e=await this._apply();if(e==null)return;const{arrayFormulaRange:t,runtimeFeatureRange:n}=e,{dirtyRanges:i,excludedCell:a}=this._getArrayFormulaDirtyRangeAndExcludedRange(t,n);return i==null||i.length===0||(this._currentConfigService.loadDirtyRangesAndExcludedCell(i,a),await this._apply(!0)),!0}_getArrayFormulaDirtyRangeAndExcludedRange(e,t){const n=[],i={};return Object.keys(e).forEach(a=>{const o=e[a];Object.keys(o).forEach(u=>{const l=new m.ObjectMatrix(o[u]);if(l==null)return!0;const c=new m.ObjectMatrix;l.forValue((f,d,p)=>{c.setValue(f,d,!0),n.push({unitId:a,sheetId:u,range:p})}),i[a]==null&&(i[a]={}),i[a][u]=c})}),Object.keys(t).forEach(a=>{const o=t[a];Object.keys(o).forEach(u=>{const l=o[u];Object.keys(l).forEach(c=>{const f=l[c];if(f==null)return!0;for(const d of f)n.push({unitId:u,sheetId:c,range:d})})})}),{dirtyRanges:n,excludedCell:i}}async _apply(e=!1){e?this._runtimeService.setFormulaExecuteStage(J.START_DEPENDENCY_ARRAY_FORMULA):this._runtimeService.setFormulaExecuteStage(J.START_DEPENDENCY),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());const t=await this._formulaDependencyGenerator.generate(),n=this._interpreter;e?(this._runtimeService.setFormulaExecuteStage(J.START_CALCULATION_ARRAY_FORMULA),this._runtimeService.setTotalArrayFormulasToCalculate(t.length)):(this._runtimeService.setFormulaExecuteStage(J.START_CALCULATION),this._runtimeService.setTotalFormulasToCalculate(t.length)),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());for(let i=0,a=t.length;i<a;i++){if(await new Promise(f=>{m.requestImmediateMacroTask(f)}),this._runtimeService.isStopExecution()){this._runtimeService.setFormulaExecuteStage(J.IDLE),this._runtimeService.markedAsStopFunctionsExecuted(),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData());return}const o=t[i],u=o.node,l=o.getDirtyData;let c;if(u==null&&l==null)throw new Error("AstNode or executor is null");if(this._runtimeService.setCurrent(o.row,o.column,o.subComponentId,o.unitId),l!=null&&o.featureId!=null){const{runtimeCellData:f,dirtyRanges:d}=l(o);this._runtimeService.setRuntimeFeatureCellData(o.featureId,f),this._runtimeService.setRuntimeFeatureRange(o.featureId,d)}else u!=null&&(n.checkAsyncNode(u)?c=await n.executeAsync(u):c=n.execute(u),o.formulaId!=null?this._runtimeService.setRuntimeOtherData(o.formulaId,c):this._runtimeService.setRuntimeData(c));e?(this._runtimeService.setFormulaExecuteStage(J.CURRENTLY_CALCULATING_ARRAY_FORMULA),this._runtimeService.setCompletedArrayFormulasCount(i+1)):(this._runtimeService.setFormulaExecuteStage(J.CURRENTLY_CALCULATING),this._runtimeService.setCompletedFormulasCount(i+1)),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState())}return t.length>0?this._runtimeService.markedAsSuccessfullyExecuted():e||this._runtimeService.markedAsNoFunctionsExecuted(),this._runtimeService.getAllRuntimeData()}calculate(e,t=!0){const n=this._lexer.treeBuilder(e,t);if(Object.values(h).includes(n))return B.create(n);const i=this._astTreeBuilder.parse(n);console.log("astNode",i==null?void 0:i.serialize())}},A.CalculateFormulaService=ws([m.OnLifecycle(m.LifecycleStages.Rendered,A.CalculateFormulaService),Re(0,m.IConfigService),Re(1,D.Inject(Ne)),Re(2,we),Re(3,ee),Re(4,D.Inject(Pe)),Re(5,D.Inject(Oe)),Re(6,D.Inject(xe))],A.CalculateFormulaService);var Os=Object.defineProperty,Us=Object.getOwnPropertyDescriptor,Is=(s,r,e,t)=>{for(var n=t>1?void 0:t?Us(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Os(r,e,n),n},ot=(s,r)=>(e,t)=>r(e,t,s);let ut=class extends m.Disposable{constructor(s,r,e,t){super(),this._commandService=s,this._calculateFormulaService=r,this._currentUniverService=e,this._formulaDataModel=t,this._initialize()}_initialize(){this._commandExecutedListener(),this._initialExecuteFormulaListener(),this._initialExecuteFormulaProcessListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((s,r)=>{if(s.id===yt.id)this._calculateFormulaService.stopFormulaExecution();else if(s.id===Dt.id){const e=s.params.formulaData;this._formulaDataModel.setFormulaData(e)}else if(s.id===St.id){const e=s.params;if(e.forceCalculation===!0)this._calculate(!0);else{const{dirtyRanges:t,dirtyNameMap:n,dirtyUnitFeatureMap:i}=e;this._calculate(!1,t,n,i)}}else if(s.id===$e.id){const e=s.params;if(e==null)return;const{arrayFormulaRange:t,arrayFormulaCellData:n}=e;this._formulaDataModel.setArrayFormulaRange(t),this._formulaDataModel.setArrayFormulaCellData(n)}}))}async _calculate(s=!1,r=[],e={},t={}){if(r.length===0&&Object.keys(e).length===0&&Object.keys(t).length===0&&s===!1)return;const n=this._formulaDataModel.getFormulaData(),i=this._formulaDataModel.getArrayFormulaCellData();this._calculateFormulaService.execute({formulaData:n,arrayFormulaCellData:i,forceCalculate:s,dirtyRanges:r,dirtyNameMap:e,dirtyUnitFeatureMap:t})}_initialExecuteFormulaListener(){this._calculateFormulaService.executionCompleteListener$.subscribe(s=>{const r=s.functionsExecutedState;switch(r){case Te.NOT_EXECUTED:break;case Te.STOP_EXECUTION:break;case Te.SUCCESS:this._applyFormula(s);break;case Te.INITIAL:break}this._commandService.executeCommand(He.id,{functionsExecutedState:r},{onlyLocal:!0})})}_initialExecuteFormulaProcessListener(){this._calculateFormulaService.executionInProgressListener$.subscribe(s=>{const{totalFormulasToCalculate:r,completedFormulasCount:e,totalArrayFormulasToCalculate:t,completedArrayFormulasCount:n,stage:i}=s;t>0?console.log(`Stage ${i} Array formula.There are ${t} functions to be executed, ${n} complete.`):console.log(`Stage ${i} .There are ${r} functions to be executed, ${e} complete.`),this._commandService.executeCommand(He.id,{stageInfo:s},{onlyLocal:!0})})}async _applyFormula(s){const{unitData:r,unitOtherData:e,arrayFormulaRange:t,arrayFormulaCellData:n,clearArrayFormulaCellData:i}=s;if(!r){console.error("No sheetData from Formula Engine!");return}t&&(this._formulaDataModel.clearPreviousArrayFormulaCellData(i),this._formulaDataModel.mergeArrayFormulaCellData(n),this._formulaDataModel.mergeArrayFormulaRange(t),this._commandService.executeCommand($e.id,{arrayFormulaRange:this._formulaDataModel.getArrayFormulaRange(),arrayFormulaCellData:this._formulaDataModel.getArrayFormulaCellData()},{onlyLocal:!0})),this._commandService.executeCommand(bt.id,{unitData:r,unitOtherData:e},{onlyLocal:!0})}};ut=Is([m.OnLifecycle(m.LifecycleStages.Ready,ut),ot(0,m.ICommandService),ot(1,D.Inject(A.CalculateFormulaService)),ot(2,m.IUniverInstanceService),ot(3,D.Inject(A.FormulaDataModel))],ut);class Ms extends v{calculate(...r){if(r.length!==3)return new _(h.VALUE);let e=r[0],t=r[1];if(!(r[2].isValueObject()&&r[2].isLambda()))return new _(h.VALUE);if(e.isArray()&&(e=e.getFirstCell()),t.isArray()&&(t=t.getFirstCell()),!e.isNumber())return new _(h.VALUE);if(!t.isNumber())return new _(h.VALUE);const n=r[2],i=[];for(let a=0;a<e.getValue();a++){i[a]==null&&(i[a]=[]);for(let o=0;o<t.getValue();o++){const u=n.execute(new E(a+1),new E(o+1));i[a][o]=u}}return new fn(i)}isAsync(){return!0}}const vs=[[Ms,It.MAKEARRAY]];class xs extends v{calculate(r,e){return _.create(h.VALUE)}}const Ps=[[xs,ze.CONCATENATE]],Vs=[],Bs=[],ks=[],js=[],$s=[],Qs=[],Gs=[];class Hs extends v{calculate(r,e){return new Bt("A5")}}class Ys extends v{calculate(r,e,t,n,i){return new Bt("A5")}}const qs=[[Hs,Ke.INDIRECT],[Ys,Ke.OFFSET]];class zs extends v{calculate(r){return r.isError()?_.create(h.VALUE):(r.isReferenceObject()&&(r=r.toArrayValueObject()),r.abs())}}class Ks extends v{calculate(r){return r.isError()?_.create(h.VALUE):(r.isReferenceObject()&&(r=r.toArrayValueObject()),r.acos())}}class Xs extends v{calculate(r){return r.isError()?_.create(h.VALUE):(r.isReferenceObject()&&(r=r.toArrayValueObject()),r.acosh())}}class Ws extends v{calculate(r){return r.isError()?_.create(h.VALUE):(r.isReferenceObject()&&(r=r.toArrayValueObject()),r.isArray()?r.map(e=>e.isError()?e:Dr(e)):Dr(r))}}function Dr(s){let r=s.getValue();if(s.isBoolean()&&(r=r?1:0),!Number.isFinite(r))return _.create(h.VALUE);const e=Math.atan(1/Number(r));return Number.isNaN(e)?_.create(h.VALUE):new E(e)}class Zs extends v{calculate(r,e){return _.create(h.VALUE)}}class Js extends v{calculate(...r){let e=new E(0);for(let t=0;t<r.length;t++){let n=r[t];if(n.isError())return n;if(e.isError())return e;n.isArray()&&(n=n.sum()),e=e.plus(n)}return e}}function ei(s){const r=[S.EQUALS,S.NOT_EQUAL,S.GREATER_THAN_OR_EQUAL,S.GREATER_THAN,S.LESS_THAN_OR_EQUAL,S.LESS_THAN];for(const e of r)if(s.startsWith(e)){const t=s.substring(e.length);return[e,Fe.create(t)]}return[S.EQUALS,Fe.create(s)]}function ti(s,r){const e=s.toArrayValueObject(),t=`${r.getValue()}`,[n,i]=ei(t);return Wr(t)?e.wildcard(i,n):e.compare(i,n)}class ri extends v{calculate(...r){if(r.length<2||r.length>3)return _.create(h.NA);const e=r[0],t=r[1],n=r[2];if(e.isError()||t.isError()||n&&n.isError())return _.create(h.VALUE);let i=new E(0);if(e.isReferenceObject()||e.isValueObject()&&e.isArray()){const o=ti(e,t).getArrayValue(),u=n||e,{startRow:l,startColumn:c}=u.getRangePosition();u.iterator((f,d,p)=>{if(!(f!=null&&f.isError())){const C=o[d-l][p-c].getValue()?f:new E(0);i=i.plus(C)}})}else t.isValueObject()&&(i=this._validator(e,t));return i}_validator(r,e){const t=e.getValue();if(t){const n=t.substring(0,1),i=t.substring(1);r.compare(new E(i),n).getValue()||(r=new E(0))}return r}}class ni extends v{calculate(...r){return _.create(h.VALUE)}}const si=[[zs,X.ABS],[Ks,X.ACOS],[Xs,X.ACOSH],[Ws,X.ACOT],[Js,X.SUM],[ri,X.SUMIF],[ni,X.SUMIFS],[Zs,X.POWER]];class ii extends v{constructor(){super(...arguments);g(this,"_compareType",S.EQUALS)}setCompareType(e){this._compareType=e}calculate(e,t){return e.isError()||t.isError()?_.create(h.VALUE):(e.isReferenceObject()&&(e=e.toArrayValueObject()),t.isReferenceObject()&&(t=t.toArrayValueObject()),e.compare(t,this._compareType))}}class ai extends v{calculate(r,e){return r.isError()||e.isError()?_.create(h.VALUE):(r.isReferenceObject()&&(r=r.toArrayValueObject()),e.isReferenceObject()&&(e=e.toArrayValueObject()),!e.isArray()&&e.getValue()===0?_.create(h.DIV_BY_ZERO):r.divided(e))}}class oi extends v{calculate(r,e){return r.isError()||e.isError()?r:(r.isReferenceObject()&&(r=r.toArrayValueObject()),e.isReferenceObject()&&(e=e.toArrayValueObject()),r.minus(e))}}class ui extends v{calculate(r,e){return r.isError()||e.isError()?_.create(h.VALUE):(r.isReferenceObject()&&(r=r.toArrayValueObject()),e.isReferenceObject()&&(e=e.toArrayValueObject()),r.multiply(e))}}class li extends v{calculate(r,e){return r.isError()||e.isError()?_.create(h.VALUE):(r.isReferenceObject()&&(r=r.toArrayValueObject()),e.isReferenceObject()&&(e=e.toArrayValueObject()),r.plus(e))}}const ci=[[ii,$.COMPARE],[ai,$.DIVIDED],[oi,$.MINUS],[ui,$.MULTIPLY],[li,$.PLUS]];class hi extends v{calculate(...r){let e=new E(0),t=new E(0);for(let n=0;n<r.length;n++){const i=r[n];if(i.isError())return i;if(e.isError())return e;i.isArray()?(e=e.plus(i.sum()),t=t.plus(i.count())):i.isNull()||(t=t.plus(new E(1)))}return e.divided(t)}}class fi extends v{calculate(...r){let e=new E(0);for(let t=0;t<r.length;t++){let n=r[t];n.isError()||(n.isArray()?(n=n.count(),e=e.plus(n)):!n.isNull()&&!n.isString()&&(e=e.plus(new E(1))))}return e}}class _i extends v{calculate(...r){let e=new E(0);for(let t=0;t<r.length;t++){let n=r[t];if(n.isError()){e=e.plus(new E(1));continue}n.isArray()?(n=n.countA(),e=e.plus(n)):n.isNull()||(e=e.plus(new E(1)))}return e}}class di extends v{calculate(...r){let e=new E(-1/0);for(let t=0;t<r.length;t++){let n=r[t];if(n.isError())return n;n.isArray()&&(n=n.max()),!n.isNull()&&(e=this._validator(e,n))}return e}_validator(r,e){return r.isLessThan(e).getValue()&&(r=e),r}}class Fr extends v{calculate(...r){let e=new E(1/0);for(let t=0;t<r.length;t++){let n=r[t];if(n.isError())return n;n.isArray()&&(n=n.min()),!n.isNull()&&(e=this._validator(e,n))}return e}_validator(r,e){return r.isGreaterThan(e).getValue()&&(r=e),r}}const mi=[[hi,ce.AVERAGE],[fi,ce.COUNT],[di,ce.MAX],[Fr,ce.MIN],[Fr,ce.MIN],[_i,ce.COUNTA]],gi=[],Ci=[],Ei=[];var pi=Object.defineProperty,Ni=Object.getOwnPropertyDescriptor,Ai=(s,r,e,t)=>{for(var n=t>1?void 0:t?Ni(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&pi(r,e,n),n},Qt=(s,r)=>(e,t)=>r(e,t,s);let lt=class extends m.Disposable{constructor(s,r,e){super(),this._commandService=s,this._injector=r,this._functionService=e,this._initialize()}_initialize(){this._registerCommands(),this._registerFunctions()}_registerCommands(){[Dt,$e,St,yt,He,bt,Qe,Ge,At,Rt,Ft,Lt,er,tr,wt].forEach(s=>this.disposeWithMe(this._commandService.registerCommand(s)))}_registerFunctions(){const s=[...vs,...Ps,...Vs,...Bs,...ks,...js,...$s,...Qs,...Gs,...qs,...si,...ci,...mi,...gi,...Ci,...Ei].map(r=>{const e=r[0],t=r[1];return new e(t)});this._functionService.registerExecutors(...s)}};lt=Ai([m.OnLifecycle(m.LifecycleStages.Ready,lt),Qt(0,m.ICommandService),Qt(1,D.Inject(D.Injector)),Qt(2,he)],lt);var Ri=Object.defineProperty,Si=Object.getOwnPropertyDescriptor,yi=(s,r,e,t)=>{for(var n=t>1?void 0:t?Si(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Ri(r,e,n),n},Lr=(s,r)=>(e,t)=>r(e,t,s);let ct=class extends m.Disposable{constructor(s,r){super(),this._commandService=s,this._definedNamesService=r,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(s=>{if(s.id===Qe.id){const r=s.params;if(r==null)return;const{unitId:e,name:t,formulaOrRefString:n}=r;this._definedNamesService.registerDefinedName(e,t,n)}else if(s.id===Ge.id){const r=s.params;if(r==null)return;const{unitId:e,name:t}=r;this._definedNamesService.removeDefinedName(e,t)}}))}};ct=yi([m.OnLifecycle(m.LifecycleStages.Ready,ct),Lr(0,m.ICommandService),Lr(1,Xe)],ct);var bi=Object.defineProperty,Di=Object.getOwnPropertyDescriptor,Fi=(s,r,e,t)=>{for(var n=t>1?void 0:t?Di(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&bi(r,e,n),n},wr=(s,r)=>(e,t)=>r(e,t,s);let ht=class extends m.Disposable{constructor(s,r){super(),this._commandService=s,this._featureCalculationManagerService=r,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(s=>{if(s.id===At.id){const r=s.params;if(r==null)return;const{featureId:e,calculationParam:t}=r;this._featureCalculationManagerService.register(e,t)}else if(s.id===Rt.id){const r=s.params;if(r==null)return;const{featureId:e}=r;this._featureCalculationManagerService.remove(e)}}))}};ht=Fi([m.OnLifecycle(m.LifecycleStages.Ready,ht),wr(0,m.ICommandService),wr(1,at)],ht);var Li=Object.defineProperty,wi=Object.getOwnPropertyDescriptor,Ti=(s,r,e,t)=>{for(var n=t>1?void 0:t?wi(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Li(r,e,n),n},Tr=(s,r)=>(e,t)=>r(e,t,s);let ft=class extends m.Disposable{constructor(s,r){super(),this._commandService=s,this._otherFormulaManagerService=r,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(s=>{if(s.id===Ft.id){const r=s.params;if(r==null)return;this._otherFormulaManagerService.register(r)}else if(s.id===Lt.id){const r=s.params;if(r==null)return;this._otherFormulaManagerService.remove(r)}}))}};ft=Ti([m.OnLifecycle(m.LifecycleStages.Ready,ft),Tr(0,m.ICommandService),Tr(1,kt)],ft);var Oi=Object.defineProperty,Ui=Object.getOwnPropertyDescriptor,Ii=(s,r,e,t)=>{for(var n=t>1?void 0:t?Ui(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Oi(r,e,n),n},Or=(s,r)=>(e,t)=>r(e,t,s);let _t=class extends m.Disposable{constructor(s,r){super(),this._commandService=s,this._superTableService=r,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(s=>{if(s.id===Qe.id){const r=s.params;if(r==null)return;const{unitId:e,tableName:t,reference:n}=r;this._superTableService.registerTable(e,t,n)}else if(s.id===Ge.id){const r=s.params;if(r==null)return;const{unitId:e,tableName:t}=r;this._superTableService.remove(e,t)}else if(s.id===wt.id){const r=s.params;if(r==null)return;const{tableOption:e,tableOptionType:t}=r;this._superTableService.registerTableOptionMap(e,t)}}))}};_t=Ii([m.OnLifecycle(m.LifecycleStages.Ready,_t),Or(0,m.ICommandService),Or(1,Vt)],_t);var Mi=Object.defineProperty,vi=Object.getOwnPropertyDescriptor,xi=(s,r,e,t)=>{for(var n=t>1?void 0:t?vi(r,e):r,i=s.length-1,a;i>=0;i--)(a=s[i])&&(n=(t?a(r,e,n):a(n))||n);return t&&n&&Mi(r,e,n),n},Pi=(s,r)=>(e,t)=>r(e,t,s);const Vi="base-formula-engine";A.UniverFormulaEnginePlugin=class extends m.Plugin{constructor(r,e){super(Vi),this._config=r,this._injector=e}onStarting(){this._initialize()}_initialize(){var e;const r=[[he,{useClass:dr}],[at,{useClass:yr}],[Xe,{useClass:Sn}],[A.FormulaDataModel],[je],[lt],[ht]];(e=this._config)!=null&&e.notExecuteFormula||r.push([A.CalculateFormulaService],[kt,{useClass:br}],[Vt,{useClass:ss}],[we,{useClass:Mt}],[ee,{useClass:vt}],[ut],[ct],[ft],[_t],[Pe],[Oe],[xe],[Ne],[_r],[Je],[et],[Nr],[tt],[Ze],[nt],[st],[it],[Sr]),r.forEach(t=>this._injector.add(t))}onReady(){this._injector.get(A.FormulaDataModel).initFormulaData()}},A.UniverFormulaEnginePlugin=xi([Pi(1,D.Inject(D.Injector))],A.UniverFormulaEnginePlugin),A.ArrayValueObject=se,A.BaseFunction=v,A.BaseReferenceObject=Le,A.BaseValueObject=le,A.BooleanValueObject=Q,A.ErrorType=h,A.ErrorValueObject=_,A.FUNCTION_NAMES_ARRAY=It,A.FUNCTION_NAMES_COMPATIBILITY=ze,A.FUNCTION_NAMES_CUBE=_n,A.FUNCTION_NAMES_DATABASE=dn,A.FUNCTION_NAMES_DATE=mn,A.FUNCTION_NAMES_ENGINEERING=gn,A.FUNCTION_NAMES_FINANCIAL=Cn,A.FUNCTION_NAMES_INFORMATION=En,A.FUNCTION_NAMES_LOGICAL=pn,A.FUNCTION_NAMES_LOOKUP=Ke,A.FUNCTION_NAMES_MATH=X,A.FUNCTION_NAMES_STATISTICAL=ce,A.FUNCTION_NAMES_TEXT=Nn,A.FUNCTION_NAMES_UNIVER=An,A.FUNCTION_NAMES_WEB=Rn,A.FeatureCalculationManagerService=yr,A.FormulaExecuteStageType=J,A.FormulaExecutedStateType=Te,A.FunctionService=dr,A.FunctionType=Ht,A.IFeatureCalculationManagerService=at,A.IFunctionService=he,A.LexerNode=L,A.LexerTreeBuilder=je,A.NumberValueObject=E,A.OtherFormulaManagerService=br,A.RangeReferenceObject=fr,A.RemoveDefinedNameMutation=Ge,A.RemoveFeatureCalculationMutation=Rt,A.RemoveOtherFormulaMutation=Lt,A.RemoveSuperTableMutation=tr,A.SetArrayFormulaDataMutation=$e,A.SetArrayFormulaDataUndoMutationFactory=zr,A.SetDefinedNameMutation=Qe,A.SetFeatureCalculationMutation=At,A.SetFormulaCalculationNotificationMutation=He,A.SetFormulaCalculationResultMutation=bt,A.SetFormulaCalculationStartMutation=St,A.SetFormulaCalculationStopMutation=yt,A.SetFormulaDataMutation=Dt,A.SetOtherFormulaMutation=Ft,A.SetSuperTableMutation=er,A.SetSuperTableOptionMutation=wt,A.StringValueObject=j,A.ValueObjectFactory=Fe,A.compareToken=S,A.convertUnitDataToRuntime=qt,A.generateStringWithSequence=Xt,A.includeFormulaLexerToken=vr,A.initSheetFormulaData=Jt,A.isFormulaLexerToken=mt,A.isInDirtyRange=Gt,A.matchToken=T,A.normalizeSheetName=xr,A.sequenceNodeType=q,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(D,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","rxjs"],g):(D=typeof globalThis<"u"?globalThis:D||self,g(D.UniverEngineFormula={},D.UniverCore,D["@wendellhu/redi"],D.rxjs))})(this,function(D,g,V,Pt){"use strict";var La=Object.defineProperty;var Sa=(D,g,V)=>g in D?La(D,g,{enumerable:!0,configurable:!0,writable:!0,value:V}):D[g]=V;var p=(D,g,V)=>(Sa(D,typeof g!="symbol"?g+"":g,V),V);function ir(t,n,e,r,s){for(let i=0,a=t.length;i<a;i++){const o=t[i];if(n!==o.unitId||e!==o.sheetId)continue;const{startRow:u,startColumn:l,endRow:c,endColumn:h}=o.range;if(r>=u&&r<=c&&s>=l&&s<=h)return!0}return!1}var f=(t=>(t.DIV_BY_ZERO="#DIV/0!",t.NAME="#NAME!",t.VALUE="#VALUE!",t.NUM="#NUM!",t.NA="#N/A",t.CYCLE="#CYCLE!",t.REF="#REF!",t.SPILL="#SPILL!",t.CALC="#CALC!",t.ERROR="#ERROR!",t.CONNECT="#GETTING_DATA",t.NULL="#NULL!",t))(f||{});const Vt=new Set(Object.values(f));var ar=(t=>(t[t.Financial=0]="Financial",t[t.Date=1]="Date",t[t.Math=2]="Math",t[t.Statistical=3]="Statistical",t[t.Lookup=4]="Lookup",t[t.Database=5]="Database",t[t.Text=6]="Text",t[t.Logical=7]="Logical",t[t.Information=8]="Information",t[t.Engineering=9]="Engineering",t[t.Cube=10]="Cube",t[t.Compatibility=11]="Compatibility",t[t.Web=12]="Web",t[t.Array=13]="Array",t[t.Univer=14]="Univer",t[t.User=15]="User",t))(ar||{}),K=(t=>(t.PLUS="+",t.MINUS="-",t.MULTIPLY="*",t.DIVIDED="/",t.CONCATENATE="&",t.POWER="^",t.EQUALS="=",t.NOT_EQUAL="<>",t.GREATER_THAN=">",t.GREATER_THAN_OR_EQUAL=">=",t.LESS_THAN="<",t.LESS_THAN_OR_EQUAL="<=",t))(K||{}),y=(t=>(t.EQUALS="=",t.NOT_EQUAL="<>",t.GREATER_THAN=">",t.GREATER_THAN_OR_EQUAL=">=",t.LESS_THAN="<",t.LESS_THAN_OR_EQUAL="<=",t))(y||{});const Xe=new Map([["<>",3],["<",3],[">=",3],["=",3],[">",3],["<=",3],["&",2],["+",2],["-",2],["/",1],["*",1],["^",0]]),Fe=new Set(Xe.keys()),xn=new Set(["=","<>",">",">=","<","<="]);var O=(t=>(t.OPEN_BRACKET="(",t.CLOSE_BRACKET=")",t.COMMA=",",t.SINGLE_QUOTATION="'",t.DOUBLE_QUOTATION='"',t.OPEN_BRACES="{",t.CLOSE_BRACES="}",t.COLON=":",t.OPEN_SQUARE_BRACKET="[",t.CLOSE_SQUARE_BRACKET="]",t))(O||{}),ae=(t=>(t.PERCENTAGE="%",t.POUND="#",t))(ae||{});const On=new Set(["%","#"]);var Q=(t=>(t.AT="@",t.MINUS="-",t))(Q||{});const or=[...Object.values(y),...Object.values(K),...Object.values(O),...Object.values(ae),...Object.values(Q)];function Ge(t){return or.includes(t)}function ur(t){for(const n of or)if(t.indexOf(n)>-1)return!0;return!1}function Bn(t){return t[0]==="'"&&t[t.length-1]==="'"?t.substring(1,t.length-1):t}function lr(t){const n={};return Object.keys(t).forEach(e=>{const r=t[e];if(r==null)return!0;n[e]==null&&(n[e]={}),Object.keys(r).forEach(s=>{const i=r[s];n[e][s]=new g.ObjectMatrix(i)})}),n}const vt={id:"formula.mutation.register-function",type:g.CommandType.MUTATION,handler:()=>!0};class Ke{constructor(n){p(this,"_cache");this._cache=new g.LRUMap(n)}set(n,e){const r=this._hash(n);this._cache.set(r,e)}get(n){const e=this._hash(n);return this._cache.get(e)}clear(){this._cache.clear()}_hash(n){return g.hashAlgorithm(n)}}const oe='\\[([^\\[\\]\\/?:"<>|*\\\\]+)\\]',Un=/[^0-9]/g,Fn=/[^A-Za-z]/g;function Me(t){const n=t[0]==="$",r=t.substring(1).indexOf("$")>-1;return n&&r?g.AbsoluteRefType.ALL:n?g.AbsoluteRefType.COLUMN:r?g.AbsoluteRefType.ROW:g.AbsoluteRefType.NONE}function Mn(t){const n=t.split("!");n.length>1&&(t=n[n.length-1]);const e=t.split(":");return e.length>1?{startAbsoluteRefType:Me(e[0]),endAbsoluteRefType:Me(e[1])}:{startAbsoluteRefType:Me(e[0])}}function cr(t=g.AbsoluteRefType.NONE){let n="",e="";return t===g.AbsoluteRefType.ROW?n="$":t===g.AbsoluteRefType.COLUMN?e="$":t===g.AbsoluteRefType.ALL&&(n="$",e="$"),{rowAbsoluteString:n,columnAbsoluteString:e}}function ge(t){const{startColumn:n,startRow:e,endColumn:r,endRow:s,startAbsoluteRefType:i,endAbsoluteRefType:a,rangeType:o=g.RANGE_TYPE.NORMAL}=t,u=cr(i),l=cr(a);if(o===g.RANGE_TYPE.ROW||o===g.RANGE_TYPE.ALL){const m=`${u.rowAbsoluteString}${e+1}`,E=`${l.rowAbsoluteString}${s+1}`;return`${m}:${E}`}if(o===g.RANGE_TYPE.COLUMN){const m=`${u.columnAbsoluteString}${g.Tools.chatAtABC(n)}`,E=`${l.columnAbsoluteString}${g.Tools.chatAtABC(r)}`;return`${m}:${E}`}const c=`${u.columnAbsoluteString}${g.Tools.chatAtABC(n)}${u.rowAbsoluteString}${e+1}`,h=`${l.columnAbsoluteString}${g.Tools.chatAtABC(r)}${l.rowAbsoluteString}${s+1}`;return c===h?c:`${c}:${h}`}function hr(t,n){return Ie(t)?`'${t}'!${ge(n)}`:`${t}!${ge(n)}`}function fr(t,n,e){return Ie(t)||Ie(n)?`'[${t}]${n}'!${ge(e)}`:`[${t}]${n}!${ge(e)}`}function dr(t){const{unitId:n,sheetName:e,range:r}=t;return n!=null&&n.length>0&&e!=null&&e.length>0?fr(n,e,r):e!=null&&e.length>0?hr(e,r):ge(r)}function At(t){const n=Number.parseInt(t.replace(Un,""))-1,e=g.Tools.ABCatNum(t.replace(Fn,"")),r=Me(t);return{row:n,column:e,absoluteRefType:r}}function mr(t){const n=new RegExp(oe).exec(t);let e="";n!=null&&(e=n[0].trim(),e=e.slice(1,e.length-1),t=t.replace(new RegExp(oe),""));const r=t.indexOf("!");let s="",i="";return r>-1?(s=t.substring(0,r),s[0]==="'"&&s[s.length-1]==="'"&&(s=s.substring(1,s.length-1)),i=t.substring(r)):i=t,{refBody:i,sheetName:s,unitId:e}}function Pe(t){const{refBody:n,sheetName:e,unitId:r}=mr(t),s=n.indexOf(":");if(s===-1){const C=At(n),R=C.row,_=C.column,b=C.absoluteRefType;return{unitId:r,sheetName:e,range:{startRow:R,startColumn:_,endRow:R,endColumn:_,startAbsoluteRefType:b,endAbsoluteRefType:b}}}const i=n.substring(0,s),a=n.substring(s+1),o=At(i),u=At(a),l=o.row,c=o.column,h=u.row,m=u.column;let E=g.RANGE_TYPE.NORMAL;return isNaN(l)&&isNaN(h)?E=g.RANGE_TYPE.COLUMN:isNaN(c)&&isNaN(m)&&(E=g.RANGE_TYPE.ROW),{unitId:r,sheetName:e,range:{startRow:l,startColumn:c,endRow:h,endColumn:m,startAbsoluteRefType:o.absoluteRefType,endAbsoluteRefType:u.absoluteRefType,rangeType:E}}}function Ie(t){return t.length===0?!1:!!(ur(t)||$n(t)||kn(t)||jn(t)||/[\s!$%^&*()+\-=\[\]{};':"\\|,.<>\/?]/.test(t))}function $n(t){const n=t.match(/[1-9][0-9]{0,6}/);return/^[A-Z]+[1-9][0-9]{0,6}$/.test(t)&&n!==null&&Number.parseInt(n[0],10)<=1048576}function kn(t){return/^(R(-?[0-9]+)?C(-?[0-9]+)?|C(-?[0-9]+)?|R(-?[0-9]+)?)$/.test(t)}function jn(t){return!new RegExp("^\\p{Letter}","u").test(t.charAt(0))}const Ve="((?![\\[\\]\\/?*\\\\]).)*!",le="$",xt="\\s*?:\\s*?",Ot=`\\${le}?[A-Za-z]+\\${le}?[0-9]+`,Qn=`^(${Q.AT})?(${oe})?(${Ve})?${Ot}${xt}${Ot}$`,ze=`^(${oe})?(${Ve})?\\s*?${Ot}(${ae.POUND})?$`,gr=`^(${oe})?(${Ve})?\\${le}?[0-9]+${xt}\\${le}?[0-9]+$`,Rr=`^(${oe})?(${Ve})?\\${le}?[A-Za-z]+${xt}\\${le}?[A-Za-z]+$`,Tn=`^(${oe})?(${Ve})?\\s*?\\${le}?[0-9]+$`,Hn=`^(${oe})?(${Ve})?\\s*?\\${le}?[A-Za-z]+$`,pr="[.*?]",Yn="{.*?}";function Wn(t){return new RegExp(ze).test(t)||new RegExp(Qn).test(t)||new RegExp(gr).test(t)||new RegExp(Rr).test(t)}const Re="P_1",ce="R_1",ve="L_1",$e="LR_1",Dr="LO_1",Xn="LET",ke="LAMBDA";var z=(t=>(t[t.NORMAL=0]="NORMAL",t[t.NUMBER=1]="NUMBER",t[t.STRING=2]="STRING",t[t.FUNCTION=3]="FUNCTION",t[t.REFERENCE=4]="REFERENCE",t[t.ARRAY=5]="ARRAY",t))(z||{});function Er(t){let n="";for(const e of t)typeof e=="string"?n+=e:n+=e.token;return n}class A{constructor(){p(this,"_parent");p(this,"_token",ce);p(this,"_children",[]);p(this,"_lambdaId");p(this,"_functionDefinitionPrivacyVar");p(this,"_lambdaParameter","");p(this,"_startIndex",-1);p(this,"_endIndex",-1)}dispose(){var n;this._children.forEach(e=>{typeof e!="string"&&e.dispose()}),(n=this._functionDefinitionPrivacyVar)==null||n.clear(),this._parent=null}getStartIndex(){return this._startIndex}getLambdaId(){return this._lambdaId}setLambdaId(n){this._lambdaId=n}getFunctionDefinitionPrivacyVar(){return this._functionDefinitionPrivacyVar}setLambdaPrivacyVar(n){this._functionDefinitionPrivacyVar=n}getLambdaParameter(){return this._lambdaParameter}setLambdaParameter(n){this._lambdaParameter=n}getParent(){return this._parent}setParent(n){this._parent=n}getChildren(){return this._children}setChildren(n){this._children=n}addChildren(n){this._children.push(n)}addChildrenFirst(n){this._children.unshift(n)}getToken(){return this._token}setToken(n){this._token=n}setIndex(n,e){this._startIndex=n,this._endIndex=e}replaceChild(n,e){const r=this._getIndexInParent(n);r!=null&&(this.getChildren().splice(r,1,e),e.setParent(this))}changeToParent(n){const e=this.getParent();e&&e.removeChild(this),this.setParent(n),n.getChildren().push(this)}removeChild(n){const e=this._getIndexInParent(n);e!=null&&this.getChildren().splice(e,1)}serialize(){const n=this.getToken(),e=this.getChildren(),r=[],s=e.length;for(let i=0;i<s;i++){const a=e[i];a instanceof A?r.push(a.serialize()):r.push(a)}return{token:n,st:this._startIndex,ed:this._endIndex,children:r}}_getIndexInParent(n){const e=this.getChildren(),r=e.length;for(let s=0;s<r;s++)if(e[s]===n)return s}}const _r=1e5,Bt=new Ke(_r),Ut=new Ke(_r);class qe extends g.Disposable{constructor(){super(...arguments);p(this,"_currentLexerNode",new A);p(this,"_upLevel",0);p(this,"_segment","");p(this,"_bracketState",[]);p(this,"_squareBracketState",0);p(this,"_bracesState",0);p(this,"_singleQuotationState",0);p(this,"_doubleQuotationState",0);p(this,"_lambdaState",!1);p(this,"_colonState",!1);p(this,"_tableBracketState",!1)}dispose(){this._resetTemp(),this._currentLexerNode.dispose(),Bt.clear(),Ut.clear()}getUpLevel(){return this._upLevel}isColonClose(){return this._colonState===!1}isColonOpen(){return this._colonState===!0}isDoubleQuotationClose(){return this._doubleQuotationState===0}isLambdaOpen(){return this._lambdaState===!0}isLambdaClose(){return this._lambdaState===!1}isSingleQuotationClose(){return this._singleQuotationState===0}isBracesClose(){return this._bracesState===0}isBracketClose(){return this._bracketState.length===0}isSquareBracketClose(){return this._squareBracketState===0}getCurrentLexerNode(){return this._currentLexerNode}getFunctionAndParameter(e,r){const s=this._getCurrentParamIndex(e,r);if(s==null||s===f.VALUE)return;const i=s[0];if(typeof i=="string")return;let a=i.getParent(),o=i;for(;a;){const u=a.getToken();if(u!==Re&&!Ge(u)&&a.getStartIndex()!==-1){const l=a.getChildren().indexOf(o);return{functionName:u,paramIndex:l}}o=a,a=a.getParent()}}moveFormulaRefOffset(e,r,s){const i=this.sequenceNodesBuilder(e);if(i==null)return e;const a=[];for(let o=0,u=i.length;o<u;o++){const l=i[o];if(typeof l=="string"||l.nodeType!==z.REFERENCE){a.push(l);continue}const{token:c}=l,h=Pe(c),{range:m,sheetName:E,unitId:C}=h,R=g.Rectangle.moveOffset(m,r,s);let _="";g.isValidRange(R)?_=dr({range:R,unitId:C,sheetName:E}):_=f.REF,a.push({...l,token:_})}return`=${Er(a)}`}checkIfAddBracket(e){let r=0,s=e.length-1,i=e[s];for(;(i===O.CLOSE_BRACKET||i===" ")&&s>=0;)i===O.CLOSE_BRACKET&&r++,i=e[--s];const a=this._getCurrentParamIndex(e,e.length-2);if(a==null||a===f.VALUE)return 0;const o=a[0];if(typeof o=="string")return 0;let u=o.getParent(),l=0;for(;u;){const c=u.getToken();c!==Re&&c!==O.COLON&&u.getStartIndex()!==-1&&c.toUpperCase()!==ke&&(r===0?l+=1:r--),u=u.getParent()}return l}sequenceNodesBuilder(e){const r=Ut.get(e);if(r)return[...r];const s=this._getSequenceArray(e);if(s.length===0)return;const i=this.getSequenceNode(s);return Ut.set(e,[...i]),i}getSequenceNode(e){const r=[];let s=!1;for(let i=0,a=e.length;i<a;i++){const o=e[i],u=e[i-1],{segment:l,currentString:c,cur:h}=o;if(c===O.DOUBLE_QUOTATION&&(s=!0),(l!==""||i===0)&&i!==a-1){r.push(c);continue}let m=(u==null?void 0:u.segment)||"";const E=i-m.length;let C=i-1;const R=i-1;if(i===a-1&&this._isLastMergeString(c)&&(m+=c,C+=1),m===""||Xe.has(m)){r.push(c);continue}const _=m.trim(),b=this._replacePrefixString(_);s===!0&&_[_.length-1]===O.DOUBLE_QUOTATION?(s=!1,this._pushSequenceNode(r,{nodeType:z.STRING,token:m,startIndex:E,endIndex:C},R)):new RegExp(ze).test(b)?this._pushSequenceNode(r,{nodeType:z.REFERENCE,token:m,startIndex:E,endIndex:C},R):g.Tools.isStringNumber(_)?this._pushSequenceNode(r,{nodeType:z.NUMBER,token:m,startIndex:E,endIndex:C},R):_.length>0&&this._pushSequenceNode(r,{nodeType:z.FUNCTION,token:m,startIndex:E,endIndex:C},R),(i!==a-1||!this._isLastMergeString(c))&&r.push(c)}return this._mergeSequenceNodeReference(r)}_getCurrentParamIndex(e,r){return this._nodeMaker(e,void 0,r)}_isLastMergeString(e){return e===O.DOUBLE_QUOTATION||g.Tools.isStringNumber(e)||!Ge(e)}_mergeSequenceNodeReference(e){const r=[],s=e.length;let i=0;for(;i<s;){const a=e[i];if(typeof a=="string"){const o=e[i-1];if(a.trim()===O.CLOSE_BRACES&&o!=null&&typeof o!="string"&&o.nodeType===z.FUNCTION&&o.token.trim().substring(0,1)===O.OPEN_BRACES){o.nodeType=z.ARRAY,o.token+=a,o.endIndex+=a.length,i++;continue}r.push(a)}else{const o=e[i+1],u=e[i+2];o===O.COLON&&typeof a!="string"&&u!=null&&typeof u!="string"&&Wn((a.token+o+u.token).trim())&&(a.nodeType=z.REFERENCE,a.token+=o+u.token,a.endIndex=u.endIndex,i+=2),r.push(a)}i++}return r}_pushSequenceNode(e,r,s){const i=s-r.startIndex+1;e.splice(e.length-i,i,r)}_replacePrefixString(e){return e.replace(new RegExp(Q.AT,"g"),"").replace(new RegExp(Q.MINUS,"g"),"")}nodeMakerTest(e){return this._nodeMaker(e)}treeBuilder(e,r=!0,s){if(r===!0){const c=Bt.get(e);if(c)return c}this._resetCurrentLexerNode(),this._currentLexerNode.setToken(ce);const i=[];let a=this._nodeMaker(e,i);if(a===f.VALUE||i.length===0)return a;let o=!1,u="";if(s){const{hasDefinedName:c,sequenceString:h}=s(i);o=c,u=h}if(o&&(this._resetCurrentLexerNode(),this._currentLexerNode.setToken(ce),a=this._nodeMaker(`=${u}`),a===f.VALUE))return a;const l=this._getTopNode(this._currentLexerNode);return l&&(this._currentLexerNode=l),r&&(this._suffixExpressionHandler(this._currentLexerNode),Bt.set(e,this._currentLexerNode)),this._currentLexerNode}_suffixExpressionHandler(e){var o,u;const r=e.getChildren();if(!r)return;const s=r.length,i=[],a=[];for(let l=0;l<s;l++){const c=r[l];if(c instanceof A)this._suffixExpressionHandler(c),i.push(c);else{const h=c.trim();if(h==="")continue;if(Fe.has(h)){for(;a.length>0;){const m=(o=a[a.length-1])==null?void 0:o.trim();if(!m||m===O.OPEN_BRACKET)break;const E=Xe.get(m),C=Xe.get(h);if(!E||!C)break;if(C>E)i.push(a.pop());else break}a.push(c)}else if(h===O.OPEN_BRACKET)a.push(c);else if(h===O.CLOSE_BRACKET)for(;a.length>0;){const m=(u=a[a.length-1])==null?void 0:u.trim();if(!m)break;if(m===O.OPEN_BRACKET){a.pop();break}i.push(a.pop())}else i.push(c)}}for(;a.length>0;)i.push(a.pop());e.setChildren(i)}_resetCurrentLexerNode(){this._currentLexerNode=new A}_resetSegment(){this._segment=""}_openBracket(e=0){this._bracketState.push(e)}_closeBracket(){this._bracketState.pop()}_openSquareBracket(){this._squareBracketState+=1}_closeSquareBracket(){this._squareBracketState-=1}_getCurrentBracket(){const e=this._bracketState;return e[e.length-1]}_openBraces(){this._bracesState+=1}_closeBraces(){this._bracesState-=1}_openSingleQuotation(){this._singleQuotationState+=1}_closeSingleQuotation(){this._singleQuotationState-=1}_openDoubleQuotation(){this._doubleQuotationState+=1}_closeDoubleQuotation(){this._doubleQuotationState-=1}_openLambda(){this._lambdaState=!0}_closeLambda(){this._lambdaState=!1}_openColon(e){this._upLevel=e,this._colonState=!0}_closeColon(){this._upLevel=0,this._colonState=!1}_isTableBracket(){return this._tableBracketState}_openTableBracket(){this._tableBracketState=!0}_closeTableBracket(){this._tableBracketState=!1}_getLastChildCurrentLexerNode(){const e=this._currentLexerNode.getChildren();if(e&&e.length>0){const r=e[e.length-1];if(r instanceof A)return r}return!1}_getLastChildCurrent(){const e=this._currentLexerNode.getChildren();return e&&e.length>0?e[e.length-1]:!1}_setParentCurrentLexerNode(){const e=this._currentLexerNode.getParent();return e?(this._currentLexerNode=e,!0):!1}_setAncestorCurrentLexerNode(){var s,i,a,o,u,l;const e=(s=this._currentLexerNode)==null?void 0:s.getParent();let r=!1;if(e&&e.getToken()===ve){if((i=e==null?void 0:e.getParent())!=null&&i.getParent()){const c=(o=(a=this._currentLexerNode.getParent())==null?void 0:a.getParent())==null?void 0:o.getParent();c&&(this._currentLexerNode=c),r=!0}}else if(e!=null&&e.getParent()){const c=(u=this._currentLexerNode.getParent())==null?void 0:u.getParent();c&&(this._currentLexerNode=c),r=!0}for(let c=0;c<this._upLevel;c++){const h=(l=this._currentLexerNode)==null?void 0:l.getParent();h&&(this._currentLexerNode=h),this._currentLexerNode?r=!0:r=!1}return r}_segmentCount(){return this._segment.trim().length}_pushSegment(e){this._segment+=e}_pushNodeToChildren(e,r=!1){if(e!==""){const s=this._currentLexerNode.getChildren();if(!(e instanceof A)&&this.isColonOpen()){const i=new A;i.setToken(e),i.setParent(this._currentLexerNode),e=i}r?s.unshift(e):s.push(e)}this.isColonOpen()&&(this._setAncestorCurrentLexerNode(),this._closeColon())}_setCurrentLexerNode(e,r=!1){this._pushNodeToChildren(e,r),e.setParent(this._currentLexerNode),this._currentLexerNode=e}_newAndPushCurrentLexerNode(e,r,s=!1){const i=new A;i.setToken(e),i.setIndex(r-e.length,r-1),this._setCurrentLexerNode(i,s)}_getTopNode(e){let r=e;for(;r!=null&&r.getParent();)r=r.getParent();return r}_removeLastChild(){this._currentLexerNode.getChildren().splice(-1)}_findPreviousToken(e,r){for(;r>=0;){const s=e[r];if(s!==" ")return s;r--}}_negativeCondition(e){return!!(Fe.has(e)||e===O.OPEN_BRACKET||e===O.COMMA||e==="")}_getSequenceArray(e){const r=[];return this._nodeMaker(e,r),r}_resetTemp(){this._currentLexerNode=new A,this._upLevel=0,this._segment="",this._bracketState=[],this._bracesState=0,this._singleQuotationState=0,this._doubleQuotationState=0,this._lambdaState=!1,this._colonState=!1}_checkSimilarErrorToken(e,r,s){if(e!==ae.POUND)return!0;let i=s[++r];for(;i===" ";)i=s[++r];return!!Ge(i)}_nodeMaker(e,r,s){e.substring(0,1)===K.EQUALS&&(e=e.substring(1));const i=e.split(""),a=i.length;let o=0;for(this._resetTemp();o<a;){const u=i[o];if(s===o)return[this._currentLexerNode,u];if(u===O.OPEN_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())if(this._segmentCount()>0||this.isLambdaOpen()){this.isLambdaClose()&&(this._newAndPushCurrentLexerNode(this._segment,o),this._resetSegment()),this._openBracket(1),this._closeLambda();const l=i[o+1];if(l&&l===O.CLOSE_BRACKET){if(!this._setParentCurrentLexerNode()&&o!==a-1)return f.VALUE;o++}else l&&this._newAndPushCurrentLexerNode(Re,o)}else this._pushNodeToChildren(u),this._openBracket(0);else if(u===O.CLOSE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()){this._pushNodeToChildren(this._segment),this._resetSegment();const l=this._getCurrentBracket();if(l===0)this._pushNodeToChildren(u);else if(l===1){const c=i[o+1];if(c&&c===O.OPEN_BRACKET){if(!this._setParentCurrentLexerNode()&&o!==a-1)return f.VALUE;this._newAndPushCurrentLexerNode(ve,o,!0),this._openLambda()}else if(!this._setAncestorCurrentLexerNode()&&o!==a-1)return f.VALUE}else return f.VALUE;this._closeBracket()}else if(u===O.OPEN_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(u),this._openBraces();else if(u===O.CLOSE_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(u),this._pushNodeToChildren(this._segment),this._resetSegment(),this._closeBraces();else if(u===O.OPEN_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._segment.length>0&&this._openTableBracket(),this._pushSegment(u),this._openSquareBracket();else if(u===O.CLOSE_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._closeSquareBracket(),this.isSquareBracketClose()?(this._pushSegment(u),this._isTableBracket()&&(this._pushNodeToChildren(this._segment),this._resetSegment()),this._closeTableBracket()):this._pushSegment(u);else if(u===O.DOUBLE_QUOTATION&&this.isSingleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){if(this.isDoubleQuotationClose())this._openDoubleQuotation();else{const l=i[o+1];l&&l===O.DOUBLE_QUOTATION?o++:this._closeDoubleQuotation()}this._pushSegment(u)}else if(u===O.SINGLE_QUOTATION&&this.isDoubleQuotationClose()){if(this.isSingleQuotationClose())this._openSingleQuotation();else{const l=i[o+1];l&&l===O.SINGLE_QUOTATION?o++:this._closeSingleQuotation()}this._pushSegment(u)}else if(u===O.COMMA&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=this._getCurrentBracket();if(l===1||l==null){if(this._pushNodeToChildren(this._segment),this._resetSegment(),!this._setParentCurrentLexerNode()&&o!==a-1&&l!=null)return f.VALUE;this._newAndPushCurrentLexerNode(Re,o)}else return f.VALUE}else if(u===O.COLON&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=new A;l.setToken(u);const c=new A;c.setToken(Re),c.setParent(l);const h=new A;h.setToken(Re),h.setParent(l),l.getChildren().push(c,h);let m=l,E=0;if(this._segmentCount()>0){let C,R,_=0;const b=this._segment.trim(),L=b[0],S=b[1];if(L===Q.MINUS&&(C=new A,C.setToken(Q.MINUS),_++),(L===Q.AT||S===Q.AT)&&(R=new A,R.setToken(Q.AT),C&&(C.addChildren(R),R.setParent(C)),_++),_>0&&(this._segment=b.slice(_)),E=_,R)if(R.addChildren(l),l.setParent(R),R.getParent()){const k=R.getParent();k&&(m=k)}else m=R;else C&&(m=C,C.addChildren(l),l.setParent(C));const P=new A;P.setToken(this._segment),P.setParent(c),c.getChildren().push(P),this._resetSegment()}else{const C=this._getLastChildCurrentLexerNode();C&&C.changeToParent(c)}this._setCurrentLexerNode(m),this._currentLexerNode=h,this._openColon(E)}else if(On.has(u)&&this._checkSimilarErrorToken(u,o,i)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){this._pushNodeToChildren(this._segment);const l=new A;l.setToken(u);const c=this._getLastChildCurrent();c instanceof A?c.changeToParent(l):c!==!1&&(l.getChildren().push(c),this._removeLastChild()),this._pushNodeToChildren(l),l.setParent(this._currentLexerNode),this._resetSegment()}else if(Fe.has(u)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){let l=this._segment.trim();if(u===K.MINUS&&l===""){const c=this._findPreviousToken(i,o-1)||"";if(this._negativeCondition(c)){this._pushSegment(K.MINUS),r==null||r.push({segment:this._segment,currentString:u,cur:o,currentLexerNode:this._currentLexerNode}),o++;continue}}else this._segment.length>0&&l===""?l=this._segment:(this._pushNodeToChildren(this._segment),l="");if(u===K.LESS_THAN||u===K.GREATER_THAN){const c=i[o+1];c&&Fe.has(u+c)?(this._pushNodeToChildren(l+u+c),o++):this._pushNodeToChildren(l+u)}else this._pushNodeToChildren(l+u);this._resetSegment()}else this._pushSegment(u);r==null||r.push({segment:this._segment,currentString:u,cur:o,currentLexerNode:this._currentLexerNode}),o++}this._pushNodeToChildren(this._segment)}}var Gn=Object.defineProperty,Kn=Object.getOwnPropertyDescriptor,In=(t,n,e,r)=>{for(var s=r>1?void 0:r?Kn(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Gn(n,e,s),s},Cr=(t,n)=>(e,r)=>n(e,r,t);D.FormulaDataModel=class extends g.Disposable{constructor(e,r){super();p(this,"_formulaData",{});p(this,"_arrayFormulaRange",{});p(this,"_arrayFormulaCellData",{});this._currentUniverService=e,this._lexerTreeBuilder=r}clearPreviousArrayFormulaCellData(e){Object.keys(e).forEach(r=>{const s=e[r];if(s==null)return!0;Object.keys(s).forEach(i=>{var l,c,h,m;const a=s[i],o=(c=(l=this._arrayFormulaRange)==null?void 0:l[r])==null?void 0:c[i];if(o==null)return!0;let u=new g.ObjectMatrix;((h=this._arrayFormulaCellData[r])==null?void 0:h[i])!=null&&(u=new g.ObjectMatrix((m=this._arrayFormulaCellData[r])==null?void 0:m[i])),a.forValue((E,C)=>{var P;const R=(P=o==null?void 0:o[E])==null?void 0:P[C];if(R==null)return!0;const{startRow:_,startColumn:b,endRow:L,endColumn:S}=R;for(let k=_;k<=L;k++)for(let j=b;j<=S;j++)u.setValue(k,j,null)}),this._arrayFormulaCellData[r]&&(this._arrayFormulaCellData[r][i]=u.getData())})})}mergeArrayFormulaCellData(e){Object.keys(e).forEach(r=>{const s=e[r];if(s==null)return!0;this._arrayFormulaRange[r]==null&&(this._arrayFormulaRange[r]={}),this._arrayFormulaCellData[r]==null&&(this._arrayFormulaCellData[r]={}),Object.keys(s).forEach(i=>{var l,c,h,m;const a=s[i];let o=new g.ObjectMatrix,u=new g.ObjectMatrix;((l=this._arrayFormulaRange[r])==null?void 0:l[i])!=null&&(o=new g.ObjectMatrix((c=this._arrayFormulaRange[r])==null?void 0:c[i])),((h=this._arrayFormulaCellData[r])==null?void 0:h[i])!=null&&(u=new g.ObjectMatrix((m=this._arrayFormulaCellData[r])==null?void 0:m[i])),a.forValue((E,C)=>{const R=o==null?void 0:o.getValue(E,C);if(R==null)return!0;const{startRow:_,startColumn:b,endRow:L,endColumn:S}=R;for(let P=_;P<=L;P++)for(let k=b;k<=S;k++)u.setValue(P,k,null)}),a.forValue((E,C,R)=>{u.setValue(E,C,R)}),this._arrayFormulaCellData[r]&&(this._arrayFormulaCellData[r][i]=u.getData())})})}getFormulaData(){return this._formulaData}setFormulaData(e){this._formulaData=e}setArrayFormulaRange(e){this._arrayFormulaRange=e}getArrayFormulaRange(){return this._arrayFormulaRange}setArrayFormulaCellData(e){this._arrayFormulaCellData=e}getArrayFormulaCellData(){return this._arrayFormulaCellData}mergeArrayFormulaRange(e){Object.keys(e).forEach(r=>{const s=e[r];if(s==null)return!0;this._arrayFormulaRange[r]||(this._arrayFormulaRange[r]={}),Object.keys(s).forEach(i=>{var u,l;const a=new g.ObjectMatrix(s[i]);let o=new g.ObjectMatrix;(u=this._arrayFormulaRange[r])!=null&&u[i]&&(o=new g.ObjectMatrix((l=this._arrayFormulaRange[r])==null?void 0:l[i])),a.forValue((c,h,m)=>{o.setValue(c,h,m)}),this._arrayFormulaRange[r]&&(this._arrayFormulaRange[r][i]=o.getData())})})}deleteArrayFormulaRange(e,r,s,i){var u;const a=(u=this._arrayFormulaRange[e])==null?void 0:u[r];if(a==null)return;const o=new g.ObjectMatrix(a);o.getValue(s,i)&&(o.realDeleteValue(s,i),this._arrayFormulaRange[e]&&(this._arrayFormulaRange[e][r]=o.getData()))}initFormulaData(){this._currentUniverService.getAllUniverSheetsInstance();const e=this._currentUniverService.getCurrentUniverSheetInstance(),r=e.getUnitId();this._formulaData[r]={},e.getSheets().forEach(i=>{const a=i.getCellMatrix(),o=i.getSheetId();wr(this._formulaData,r,o,a)})}getCalculateData(){const e=this._currentUniverService.getAllUniverSheetsInstance(),r={},s={};for(const i of e){const a=i.getUnitId(),o=i.getSheets(),u={},l={};for(const c of o){const h=c.getSheetId(),m=c.getConfig();u[h]={cellData:new g.ObjectMatrix(m.cellData),rowCount:m.rowCount,columnCount:m.columnCount},l[c.getName()]=c.getSheetId()}r[a]=u,s[a]=l}return{allUnitData:r,unitSheetNameMap:s}}updateFormulaData(e,r,s){const i=new g.ObjectMatrix(s),a=this.getFormulaIdMap(e,r),o=new Map,u=this._formulaData;u[e]==null&&(u[e]={});const l=u[e];l[r]==null&&(l[r]={});const c=new g.ObjectMatrix(l[r]);i.forValue((h,m,E)=>{const C=(E==null?void 0:E.f)||"",R=(E==null?void 0:E.si)||"",_=g.isFormulaString(C),b=g.isFormulaId(R);if(_&&b)c.setValue(h,m,{f:C,si:R}),a.set(R,{f:C,r:h,c:m});else if(_&&!b)c.setValue(h,m,{f:C});else if(!_&&b)c.setValue(h,m,{f:"",si:R});else if(!_&&!b&&c.getValue(h,m)){const L=c.getValue(h,m),S=(L==null?void 0:L.f)||"",P=(L==null?void 0:L.si)||"";g.isFormulaString(S)&&g.isFormulaId(P)&&o.set(P,S),c.realDeleteValue(h,m)}}),c.forValue((h,m,E)=>{const C=(E==null?void 0:E.f)||"",R=(E==null?void 0:E.si)||"";if(g.isFormulaId(R)){const _=a.get(R),b=o.get(R);if(_&&!g.isFormulaString(C)){const L=_.f,S=m-_.c,P=h-_.r;c.setValue(h,m,{f:L,si:R,x:S,y:P})}else if(typeof b=="string"){const L=E.x||0,S=E.y||0,P=this._lexerTreeBuilder.moveFormulaRefOffset(b,L,S);o.set(R,{r:h,c:m,f:P}),c.setValue(h,m,{f:P,si:R})}else if(typeof b=="object"){const L=m-b.c,S=h-b.r;c.setValue(h,m,{f:b.f,si:R,x:L,y:S})}}})}updateArrayFormulaRange(e,r,s){var u;const i=(u=this._arrayFormulaRange[e])==null?void 0:u[r];if(!i)return;const a=new g.ObjectMatrix(i);new g.ObjectMatrix(s).forValue((l,c,h)=>{if((a==null?void 0:a.getValue(l,c))==null)return!0;const E=(h==null?void 0:h.f)||"",C=(h==null?void 0:h.si)||"",R=g.isFormulaString(E),_=g.isFormulaId(C);!R&&!_&&a.realDeleteValue(l,c)})}updateArrayFormulaCellData(e,r,s){var c,h;const i=(c=this._arrayFormulaRange[e])==null?void 0:c[r];if(!i)return;const a=new g.ObjectMatrix(i),o=(h=this._arrayFormulaCellData[e])==null?void 0:h[r];if(!o)return;const u=new g.ObjectMatrix(o);new g.ObjectMatrix(s).forValue((m,E,C)=>{const R=a==null?void 0:a.getValue(m,E);if(R==null)return!0;const _=(C==null?void 0:C.f)||"",b=(C==null?void 0:C.si)||"",L=g.isFormulaString(_),S=g.isFormulaId(b);if(!L&&!S){const{startRow:P,startColumn:k,endRow:j,endColumn:H}=R;for(let B=P;B<=j;B++)for(let v=k;v<=H;v++)u.realDeleteValue(B,v)}})}getFormulaItemBySId(e,r,s){const i=this._formulaData;if(i[s]==null)return null;const a=i[s];if((a==null?void 0:a[r])==null)return null;const o=new g.ObjectMatrix(a[r]);let u=null;return o.forValue((l,c,h)=>{const{f:m,si:E,x:C=0,y:R=0}=h;if(E===e&&m.length>0&&C===0&&R===0)return u=h,!1}),u}getFormulaDataItem(e,r,s,i){var a,o,u,l;return(l=(u=(o=(a=this._formulaData)==null?void 0:a[i])==null?void 0:o[s])==null?void 0:u[e])==null?void 0:l[r]}getFormulaIdMap(e,r){const s=new Map,i=this._formulaData;if(i[e]==null)return s;const a=i[e];return(a==null?void 0:a[r])==null||new g.ObjectMatrix(a[r]).forValue((u,l,c)=>{const h=(c==null?void 0:c.f)||"",m=(c==null?void 0:c.si)||"",E=(c==null?void 0:c.x)||0,C=(c==null?void 0:c.y)||0;g.isFormulaString(h)&&g.isFormulaId(m)&&E===0&&C===0&&s.set(m,{f:h,r:u,c:l})}),s}},D.FormulaDataModel=In([Cr(0,g.IUniverInstanceService),Cr(1,V.Inject(qe))],D.FormulaDataModel);function wr(t,n,e,r){const s=new Map,i=new g.ObjectMatrix;r.forValue((a,o,u)=>{const l=(u==null?void 0:u.f)||"",c=(u==null?void 0:u.si)||"",h=g.isFormulaString(l),m=g.isFormulaId(c);h&&m?(i.setValue(a,o,{f:l,si:c}),s.set(c,{f:l,r:a,c:o})):h&&!m?i.setValue(a,o,{f:l}):!h&&m&&i.setValue(a,o,{f:"",si:c})}),i.forValue((a,o,u)=>{const l=(u==null?void 0:u.f)||"",c=(u==null?void 0:u.si)||"";if(g.isFormulaId(c)&&!g.isFormulaString(l)){const h=s.get(c);if(h){const m=h.f,E=o-h.c,C=a-h.r;i.setValue(a,o,{f:m,si:c,x:E,y:C})}}}),t[n]&&(t[n][e]=i.getData())}const zn=t=>{const n=t.get(D.FormulaDataModel),e=g.Tools.deepClone(n.getArrayFormulaRange()),r=g.Tools.deepClone(n.getArrayFormulaCellData());return{arrayFormulaRange:e,arrayFormulaCellData:r}},Ze={id:"formula.mutation.set-array-formula-data",type:g.CommandType.MUTATION,handler:(t,n)=>{const e=t.get(D.FormulaDataModel);return e.setArrayFormulaRange(n.arrayFormulaRange),e.setArrayFormulaCellData(n.arrayFormulaCellData),!0}},Je={id:"formula.mutation.set-defined-name",type:g.CommandType.MUTATION,handler:()=>!0},Ne={id:"formula.mutation.remove-defined-name",type:g.CommandType.MUTATION,handler:()=>!0},Ft={id:"formula.mutation.set-feature-calculation",type:g.CommandType.MUTATION,handler:()=>!0},Mt={id:"formula.mutation.remove-feature-calculation",type:g.CommandType.MUTATION,handler:()=>!0},$t={id:"formula.mutation.set-formula-calculation-start",type:g.CommandType.MUTATION,handler:()=>!0},kt={id:"formula.mutation.set-formula-calculation-stop",type:g.CommandType.MUTATION,handler:()=>!0},et={id:"formula.mutation.set-formula-calculation-notification",type:g.CommandType.MUTATION,handler:()=>!0},jt={id:"formula.mutation.set-formula-calculation-result",type:g.CommandType.MUTATION,handler:()=>!0},Qt={id:"formula.mutation.set-formula-data",type:g.CommandType.MUTATION,handler:(t,n)=>(t.get(D.FormulaDataModel).setFormulaData(n.formulaData),!0)},Tt={id:"formula.mutation.set-other-formula",type:g.CommandType.MUTATION,handler:()=>!0},Ht={id:"formula.mutation.remove-other-formula",type:g.CommandType.MUTATION,handler:()=>!0},yr={id:"formula.mutation.set-super-table",type:g.CommandType.MUTATION,handler:()=>!0},br={id:"formula.mutation.remove-super-table",type:g.CommandType.MUTATION,handler:()=>!0},Yt={id:"formula.mutation.set-super-table-option",type:g.CommandType.MUTATION,handler:()=>!0},Wt={id:"formula.mutation.unregister-function",type:g.CommandType.MUTATION,handler:()=>!0};class tt extends g.Disposable{isError(){return!1}isAsyncObject(){return!1}isAsyncArrayObject(){return!1}isReferenceObject(){return!1}isValueObject(){return!1}isEqualType(n){return!1}}var pe=(t=>(t.FALSE="FALSE",t.TRUE="TRUE",t))(pe||{}),De=(t=>(t[t.SUCCESS=0]="SUCCESS",t[t.ERROR=1]="ERROR",t))(De||{}),Ee=(t=>(t.ALL="#All",t.DATA="#Data",t.HEADERS="#Headers",t.TOTALS="#Totals",t))(Ee||{}),q=(t=>(t[t.FRONT=0]="FRONT",t[t.BACK=1]="BACK",t))(q||{});class qn{constructor(){p(this,"_cache",new Map);p(this,"_continueBuildingCache",new Map)}set(n,e,r,s,i){if(!this.shouldContinueBuildingCache(n,e,r,i))return;let a=this._cache.get(n);a==null&&(a=new Map,this._cache.set(n,a));let o=a.get(e);o==null&&(o=new Map,a.set(e,o));let u=o.get(r);u==null&&(u=new Map,o.set(r,u));let l=u.get(s);l==null&&(l=[],u.set(s,l)),l.push(i)}getCellValuePositions(n,e,r){var s,i;return(i=(s=this._cache.get(n))==null?void 0:s.get(e))==null?void 0:i.get(r)}getCellPositions(n,e,r,s){var i,a,o;return(o=(a=(i=this._cache.get(n))==null?void 0:i.get(e))==null?void 0:a.get(r))==null?void 0:o.get(s)}getCellPosition(n,e,r,s,i,a){const o=this.getCellPositions(n,e,r,s);if(o!=null){for(const u of o)if(u>=i&&u<=a)return u}}setContinueBuildingCache(n,e,r,s,i){let a=this._continueBuildingCache.get(n);a==null&&(a=new Map,this._continueBuildingCache.set(n,a));let o=a.get(e);o==null&&(o=new Map,a.set(e,o));let u=o.get(r);if(u==null){u={startRow:s,endRow:i},o.set(r,u);return}u.startRow=Math.min(u.startRow,s),u.endRow=Math.max(u.endRow,i)}shouldContinueBuildingCache(n,e,r,s){var u,l;const i=(l=(u=this._continueBuildingCache.get(n))==null?void 0:u.get(e))==null?void 0:l.get(r);if(i==null)return!0;const{startRow:a,endRow:o}=i;return!(s>=a&&s<=o)}canUseCache(n,e,r,s,i){var l,c;if(r===-1||s===-1||i===-1)return!1;const a=(c=(l=this._continueBuildingCache.get(n))==null?void 0:l.get(e))==null?void 0:c.get(r);if(a==null)return!1;const{startRow:o,endRow:u}=a;return!(s>u||i<o)}clear(){this._cache.clear(),this._continueBuildingCache.clear()}}const he=new qn;var rt=(t=>(t[t.MIN=0]="MIN",t[t.MAX=1]="MAX",t))(rt||{});function Lr(){return new Intl.Collator(void 0,{numeric:!0}).compare}function Zn(t){return t.indexOf("*")>-1||t.indexOf("?")>-1}function Sr(t,n){const e=n.replace(/~?[*?]/g,s=>s.startsWith("~")?`\\${s.substring(1)}`:s==="*"?".*":s==="?"?".":s);return new RegExp(`^${e}$`).test(t)}function Pr(t){return t.replace(/~?[*?]/g,n=>n.startsWith("~")?n.substring(1):" ")}function Jn(t,n,e){let r=!1;switch(e){case y.EQUALS:r=Sr(t,n);break;case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:r=Sr(t,n)||t>Pr(n);break;case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:r=t<Pr(n);break}return r}class fe extends tt{constructor(n){super(),this._rawValue=n}isValueObject(){return!0}toUnitRange(){return{range:{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1},sheetId:"",unitId:""}}getValue(){return 0}getArrayValue(){return[]}setValue(n){}setArrayValue(n){}isArray(){return!1}isString(){return!1}isNumber(){return!1}isBoolean(){return!1}isLambda(){return!1}isError(){return!1}isNull(){return!1}sum(){return new d(f.VALUE)}max(){return new d(f.VALUE)}min(){return new d(f.VALUE)}count(){return new d(f.VALUE)}countA(){return new d(f.VALUE)}countBlank(){return new d(f.VALUE)}getNegative(){return new d(f.NAME)}getReciprocal(){return new d(f.NAME)}plus(n){return new d(f.NAME)}minus(n){return new d(f.NAME)}multiply(n){return new d(f.NAME)}divided(n){return new d(f.NAME)}map(n){return new d(f.NAME)}product(n,e){return e(this,n)}compare(n,e){return new d(f.NAME)}isEqual(n){return this.compare(n,y.EQUALS)}isNotEqual(n){return this.compare(n,y.NOT_EQUAL)}isGreaterThanOrEqual(n){return this.compare(n,y.GREATER_THAN_OR_EQUAL)}isLessThanOrEqual(n){return this.compare(n,y.LESS_THAN_OR_EQUAL)}isLessThan(n){return this.compare(n,y.LESS_THAN)}isGreaterThan(n){return this.compare(n,y.GREATER_THAN)}concatenateFront(n){return new d(f.NAME)}concatenateBack(n){return new d(f.NAME)}plusBy(n){return new d(f.NAME)}minusBy(n){return new d(f.NAME)}multiplyBy(n){return new d(f.NAME)}dividedBy(n){return new d(f.NAME)}compareBy(n,e){return new d(f.NAME)}concatenate(n,e=q.FRONT){let r=this.getValue().toString();if(typeof n=="string")e===q.FRONT?r=n+r:r+=n;else if(typeof n=="number")e===q.FRONT?r=n.toString()+r:r+=n.toString();else if(typeof n=="boolean"){const s=n?"TRUE":"FALSE";e===q.FRONT?r=s+r:r+=s}return r}pow(n){return new d(f.VALUE)}powInverse(n){return new d(f.VALUE)}sqrt(){return new d(f.VALUE)}cbrt(){return new d(f.VALUE)}cos(){return new d(f.VALUE)}acos(){return new d(f.VALUE)}acosh(){return new d(f.VALUE)}sin(){return new d(f.VALUE)}asin(){return new d(f.VALUE)}asinh(){return new d(f.VALUE)}tan(){return new d(f.VALUE)}tanh(){return new d(f.VALUE)}atan(){return new d(f.VALUE)}atan2(n){return new d(f.VALUE)}atan2Inverse(n){return new d(f.VALUE)}atanh(){return new d(f.VALUE)}mean(){return this}median(){return this}var(){return this}std(){return this}log(){return new d(f.VALUE)}log10(){return new d(f.VALUE)}exp(){return new d(f.VALUE)}abs(){return new d(f.VALUE)}round(n){return new d(f.VALUE)}roundInverse(n){return new d(f.VALUE)}floor(n){return new d(f.VALUE)}floorInverse(n){return new d(f.VALUE)}ceil(n){return new d(f.VALUE)}ceilInverse(n){return new d(f.VALUE)}}class d extends fe{constructor(n,e=""){super(n),this._errorType=n,this._errorContent=e}getValue(){return this._errorType}getErrorType(){return this._errorType}getErrorContent(){return this._errorContent}isEqualType(n){return n.getErrorType()===this.getErrorType()}isError(){return!0}}var Nn=20,es=1,_e=1e6,Vr=1e6,ts=-7,rs=21,ns=!1,je="[big.js] ",Ce=je+"Invalid ",nt=Ce+"decimal places",ss=Ce+"rounding mode",vr=je+"Division by zero",U={},te=void 0,is=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function Ar(){function t(n){var e=this;if(!(e instanceof t))return n===te?Ar():new t(n);if(n instanceof t)e.s=n.s,e.e=n.e,e.c=n.c.slice();else{if(typeof n!="string"){if(t.strict===!0&&typeof n!="bigint")throw TypeError(Ce+"value");n=n===0&&1/n<0?"-0":String(n)}as(e,n)}e.constructor=t}return t.prototype=U,t.DP=Nn,t.RM=es,t.NE=ts,t.PE=rs,t.strict=ns,t.roundDown=0,t.roundHalfUp=1,t.roundHalfEven=2,t.roundUp=3,t}function as(t,n){var e,r,s;if(!is.test(n))throw Error(Ce+"number");for(t.s=n.charAt(0)=="-"?(n=n.slice(1),-1):1,(e=n.indexOf("."))>-1&&(n=n.replace(".","")),(r=n.search(/e/i))>0?(e<0&&(e=r),e+=+n.slice(r+1),n=n.substring(0,r)):e<0&&(e=n.length),s=n.length,r=0;r<s&&n.charAt(r)=="0";)++r;if(r==s)t.c=[t.e=0];else{for(;s>0&&n.charAt(--s)=="0";);for(t.e=e-r-1,t.c=[],e=0;r<=s;)t.c[e++]=+n.charAt(r++)}return t}function we(t,n,e,r){var s=t.c;if(e===te&&(e=t.constructor.RM),e!==0&&e!==1&&e!==2&&e!==3)throw Error(ss);if(n<1)r=e===3&&(r||!!s[0])||n===0&&(e===1&&s[0]>=5||e===2&&(s[0]>5||s[0]===5&&(r||s[1]!==te))),s.length=1,r?(t.e=t.e-n+1,s[0]=1):s[0]=t.e=0;else if(n<s.length){if(r=e===1&&s[n]>=5||e===2&&(s[n]>5||s[n]===5&&(r||s[n+1]!==te||s[n-1]&1))||e===3&&(r||!!s[0]),s.length=n,r){for(;++s[--n]>9;)if(s[n]=0,n===0){++t.e,s.unshift(1);break}}for(n=s.length;!s[--n];)s.pop()}return t}function Ae(t,n,e){var r=t.e,s=t.c.join(""),i=s.length;if(n)s=s.charAt(0)+(i>1?"."+s.slice(1):"")+(r<0?"e":"e+")+r;else if(r<0){for(;++r;)s="0"+s;s="0."+s}else if(r>0)if(++r>i)for(r-=i;r--;)s+="0";else r<i&&(s=s.slice(0,r)+"."+s.slice(r));else i>1&&(s=s.charAt(0)+"."+s.slice(1));return t.s<0&&e?"-"+s:s}U.abs=function(){var t=new this.constructor(this);return t.s=1,t},U.cmp=function(t){var n,e=this,r=e.c,s=(t=new e.constructor(t)).c,i=e.s,a=t.s,o=e.e,u=t.e;if(!r[0]||!s[0])return r[0]?i:s[0]?-a:0;if(i!=a)return i;if(n=i<0,o!=u)return o>u^n?1:-1;for(a=(o=r.length)<(u=s.length)?o:u,i=-1;++i<a;)if(r[i]!=s[i])return r[i]>s[i]^n?1:-1;return o==u?0:o>u^n?1:-1},U.div=function(t){var n=this,e=n.constructor,r=n.c,s=(t=new e(t)).c,i=n.s==t.s?1:-1,a=e.DP;if(a!==~~a||a<0||a>_e)throw Error(nt);if(!s[0])throw Error(vr);if(!r[0])return t.s=i,t.c=[t.e=0],t;var o,u,l,c,h,m=s.slice(),E=o=s.length,C=r.length,R=r.slice(0,o),_=R.length,b=t,L=b.c=[],S=0,P=a+(b.e=n.e-t.e)+1;for(b.s=i,i=P<0?0:P,m.unshift(0);_++<o;)R.push(0);do{for(l=0;l<10;l++){if(o!=(_=R.length))c=o>_?1:-1;else for(h=-1,c=0;++h<o;)if(s[h]!=R[h]){c=s[h]>R[h]?1:-1;break}if(c<0){for(u=_==o?s:m;_;){if(R[--_]<u[_]){for(h=_;h&&!R[--h];)R[h]=9;--R[h],R[_]+=10}R[_]-=u[_]}for(;!R[0];)R.shift()}else break}L[S++]=c?l:++l,R[0]&&c?R[_]=r[E]||0:R=[r[E]]}while((E++<C||R[0]!==te)&&i--);return!L[0]&&S!=1&&(L.shift(),b.e--,P--),S>P&&we(b,P,e.RM,R[0]!==te),b},U.eq=function(t){return this.cmp(t)===0},U.gt=function(t){return this.cmp(t)>0},U.gte=function(t){return this.cmp(t)>-1},U.lt=function(t){return this.cmp(t)<0},U.lte=function(t){return this.cmp(t)<1},U.minus=U.sub=function(t){var n,e,r,s,i=this,a=i.constructor,o=i.s,u=(t=new a(t)).s;if(o!=u)return t.s=-u,i.plus(t);var l=i.c.slice(),c=i.e,h=t.c,m=t.e;if(!l[0]||!h[0])return h[0]?t.s=-u:l[0]?t=new a(i):t.s=1,t;if(o=c-m){for((s=o<0)?(o=-o,r=l):(m=c,r=h),r.reverse(),u=o;u--;)r.push(0);r.reverse()}else for(e=((s=l.length<h.length)?l:h).length,o=u=0;u<e;u++)if(l[u]!=h[u]){s=l[u]<h[u];break}if(s&&(r=l,l=h,h=r,t.s=-t.s),(u=(e=h.length)-(n=l.length))>0)for(;u--;)l[n++]=0;for(u=n;e>o;){if(l[--e]<h[e]){for(n=e;n&&!l[--n];)l[n]=9;--l[n],l[e]+=10}l[e]-=h[e]}for(;l[--u]===0;)l.pop();for(;l[0]===0;)l.shift(),--m;return l[0]||(t.s=1,l=[m=0]),t.c=l,t.e=m,t},U.mod=function(t){var n,e=this,r=e.constructor,s=e.s,i=(t=new r(t)).s;if(!t.c[0])throw Error(vr);return e.s=t.s=1,n=t.cmp(e)==1,e.s=s,t.s=i,n?new r(e):(s=r.DP,i=r.RM,r.DP=r.RM=0,e=e.div(t),r.DP=s,r.RM=i,this.minus(e.times(t)))},U.neg=function(){var t=new this.constructor(this);return t.s=-t.s,t},U.plus=U.add=function(t){var n,e,r,s=this,i=s.constructor;if(t=new i(t),s.s!=t.s)return t.s=-t.s,s.minus(t);var a=s.e,o=s.c,u=t.e,l=t.c;if(!o[0]||!l[0])return l[0]||(o[0]?t=new i(s):t.s=s.s),t;if(o=o.slice(),n=a-u){for(n>0?(u=a,r=l):(n=-n,r=o),r.reverse();n--;)r.push(0);r.reverse()}for(o.length-l.length<0&&(r=l,l=o,o=r),n=l.length,e=0;n;o[n]%=10)e=(o[--n]=o[n]+l[n]+e)/10|0;for(e&&(o.unshift(e),++u),n=o.length;o[--n]===0;)o.pop();return t.c=o,t.e=u,t},U.pow=function(t){var n=this,e=new n.constructor("1"),r=e,s=t<0;if(t!==~~t||t<-Vr||t>Vr)throw Error(Ce+"exponent");for(s&&(t=-t);t&1&&(r=r.times(n)),t>>=1,!!t;)n=n.times(n);return s?e.div(r):r},U.prec=function(t,n){if(t!==~~t||t<1||t>_e)throw Error(Ce+"precision");return we(new this.constructor(this),t,n)},U.round=function(t,n){if(t===te)t=0;else if(t!==~~t||t<-_e||t>_e)throw Error(nt);return we(new this.constructor(this),t+this.e+1,n)},U.sqrt=function(){var t,n,e,r=this,s=r.constructor,i=r.s,a=r.e,o=new s("0.5");if(!r.c[0])return new s(r);if(i<0)throw Error(je+"No square root");i=Math.sqrt(r+""),i===0||i===1/0?(n=r.c.join(""),n.length+a&1||(n+="0"),i=Math.sqrt(n),a=((a+1)/2|0)-(a<0||a&1),t=new s((i==1/0?"5e":(i=i.toExponential()).slice(0,i.indexOf("e")+1))+a)):t=new s(i+""),a=t.e+(s.DP+=4);do e=t,t=o.times(e.plus(r.div(e)));while(e.c.slice(0,a).join("")!==t.c.slice(0,a).join(""));return we(t,(s.DP-=4)+t.e+1,s.RM)},U.times=U.mul=function(t){var n,e=this,r=e.constructor,s=e.c,i=(t=new r(t)).c,a=s.length,o=i.length,u=e.e,l=t.e;if(t.s=e.s==t.s?1:-1,!s[0]||!i[0])return t.c=[t.e=0],t;for(t.e=u+l,a<o&&(n=s,s=i,i=n,l=a,a=o,o=l),n=new Array(l=a+o);l--;)n[l]=0;for(u=o;u--;){for(o=0,l=a+u;l>u;)o=n[l]+i[u]*s[l-u-1]+o,n[l--]=o%10,o=o/10|0;n[l]=o}for(o?++t.e:n.shift(),u=n.length;!n[--u];)n.pop();return t.c=n,t},U.toExponential=function(t,n){var e=this,r=e.c[0];if(t!==te){if(t!==~~t||t<0||t>_e)throw Error(nt);for(e=we(new e.constructor(e),++t,n);e.c.length<t;)e.c.push(0)}return Ae(e,!0,!!r)},U.toFixed=function(t,n){var e=this,r=e.c[0];if(t!==te){if(t!==~~t||t<0||t>_e)throw Error(nt);for(e=we(new e.constructor(e),t+e.e+1,n),t=t+e.e+1;e.c.length<t;)e.c.push(0)}return Ae(e,!1,!!r)},U[Symbol.for("nodejs.util.inspect.custom")]=U.toJSON=U.toString=function(){var t=this,n=t.constructor;return Ae(t,t.e<=n.NE||t.e>=n.PE,!!t.c[0])},U.toNumber=function(){var t=Number(Ae(this,!0,!0));if(this.constructor.strict===!0&&!this.eq(t.toString()))throw Error(je+"Imprecise conversion");return t},U.toPrecision=function(t,n){var e=this,r=e.constructor,s=e.c[0];if(t!==te){if(t!==~~t||t<1||t>_e)throw Error(Ce+"precision");for(e=we(new r(e),t,n);e.c.length<t;)e.c.push(0)}return Ae(e,t<=e.e||e.e<=r.NE||e.e>=r.PE,!!s)},U.valueOf=function(){var t=this,n=t.constructor;if(n.strict===!0)throw Error(je+"valueOf disallowed");return Ae(t,t.e<=n.NE||t.e>=n.PE,!0)};var Y=Ar();function xr(t){let n;switch(t){case y.EQUALS:n=y.EQUALS;break;case y.GREATER_THAN:n=y.LESS_THAN;break;case y.GREATER_THAN_OR_EQUAL:n=y.LESS_THAN_OR_EQUAL;break;case y.LESS_THAN:n=y.GREATER_THAN;break;case y.LESS_THAN_OR_EQUAL:n=y.GREATER_THAN_OR_EQUAL;break;case y.NOT_EQUAL:n=y.NOT_EQUAL;break}return n}function Xt(t,n){return Y(t).times(n).toNumber()}function Or(t,n){const e=10**Math.floor(n);return Math.round(Xt(t,e))/e}function Br(t,n){const e=10**Math.floor(n);return Math.floor(Xt(t,e))/e}function Ur(t,n){const e=10**Math.floor(n);return Math.ceil(Xt(t,e))/e}function Fr(t,n){return t**n}class Qe extends fe{isNull(){return!0}plus(n){return new w(0,!0).plus(n)}minus(n){return new w(0,!0).minus(n)}multiply(n){return new w(0,!0).multiply(n)}divided(n){return new w(0,!0).divided(n)}compare(n,e){return n.isString()?new W("").compare(n,e):n.isBoolean()?new X(!1).compare(n,e):new w(0,!0).compare(n,e)}concatenateFront(n){return n.isArray()?n.concatenateBack(new W("")):new W(this.concatenate(n.getValue(),q.FRONT))}concatenateBack(n){return n.isArray()?n.concatenateFront(new W("")):new W(this.concatenate(n.getValue(),q.BACK))}plusBy(n){return new w(0).plusBy(n)}minusBy(n){return new w(0).minusBy(n)}multiplyBy(n){return new w(0).multiplyBy(n)}dividedBy(n){return new w(0).dividedBy(n)}compareBy(n,e){return typeof n=="string"?new W("").compareBy(n,e):typeof n=="boolean"?new X(!1).compareBy(n,e):new w(0,!0).compareBy(n,e)}pow(n){return new w(0,!0).pow(n)}sqrt(){return new w(0,!0)}cbrt(){return new w(0,!0)}cos(){return new w(0,!0)}acos(){return new w(0,!0)}acosh(){return new w(0,!0)}sin(){return new w(0,!0)}asin(){return new w(0,!0)}asinh(){return new w(0,!0)}tan(){return new w(0,!0)}tanh(){return new w(0,!0)}atan(){return new w(0,!0)}atan2(n){return new w(0,!0).atan2(n)}atanh(){return new w(0,!0)}log(){return new d(f.NUM)}log10(){return new d(f.NUM)}exp(){return new d(f.NUM)}abs(){return new d(f.NUM)}round(n){return new w(0,!0).round(n)}floor(n){return new w(0,!0).floor(n)}ceil(n){return new w(0,!0).ceil(n)}}class X extends fe{constructor(e,r=!1){super(e);p(this,"_value",!1);if(r){this._value=e;return}if(typeof e=="boolean")this._value=e;else if(typeof e=="string"){const s=e.toLocaleUpperCase();s===pe.TRUE?this._value=!0:s===pe.FALSE&&(this._value=!1)}else e===1?this._value=!0:this._value=!1}getValue(){return this._value}isBoolean(){return!0}getNegative(){const e=this.getValue();let r=0;return e&&(r=1),new w(-r,!0)}getReciprocal(){return this.getValue()?new w(1,!0):new d(f.DIV_BY_ZERO)}plus(e){return this._convertTonNumber().plus(e)}minus(e){return this._convertTonNumber().minus(e)}multiply(e){return this._convertTonNumber().multiply(e)}divided(e){return this._convertTonNumber().divided(e)}compare(e,r){return this._convertTonNumber().compare(e,r)}concatenateFront(e){return this._convertTonNumber().concatenateFront(e)}concatenateBack(e){return this._convertTonNumber().concatenateBack(e)}_convertTonNumber(){const e=this.getValue();let r=0;return e&&(r=1),new w(r,!0)}pow(e){return this._convertTonNumber().pow(e)}sqrt(){return this._convertTonNumber()}cbrt(){return this._convertTonNumber()}cos(){return this._convertTonNumber().cos()}acos(){return this._convertTonNumber().acos()}acosh(){return this._convertTonNumber().acosh()}sin(){return this._convertTonNumber().sin()}asin(){return this._convertTonNumber().asin()}asinh(){return this._convertTonNumber().asinh()}tan(){return this._convertTonNumber().tan()}tanh(){return this._convertTonNumber().tanh()}atan(){return this._convertTonNumber().atan()}atan2(e){return this._convertTonNumber().atan2(e)}atanh(){return this._convertTonNumber().atanh()}log(){return this._convertTonNumber().log()}log10(){return this._convertTonNumber().log10()}exp(){return this._convertTonNumber().exp()}abs(){return this._convertTonNumber().abs()}round(e){return this._convertTonNumber().round(e)}floor(e){return this._convertTonNumber().floor(e)}ceil(e){return this._convertTonNumber().ceil(e)}}class w extends fe{constructor(e,r=!1){super(e);p(this,"_value",0);if(r){this._value=e;return}this._value=Number(e)}getValue(){return this._value}setValue(e){this._value=e}isNumber(){return!0}getNegative(){return new w(0).minus(this)}getReciprocal(){return new w(1).divided(this)}plus(e){if(e.isArray())return e.plus(this);const r=this.plusBy(e.getValue());return r.isError()?this:r}equalZero(){return this._value===0}minus(e){if(e.isArray()){const s=e.getNegative();return s.isError()?s:s.plus(this)}const r=this.minusBy(e.getValue());return r.isError()?this:r}multiply(e){return e.isArray()?e.multiply(this):this.multiplyBy(e.getValue())}divided(e){if(e.isArray()){const r=e.getReciprocal();return r.isError()?r:r.multiply(this)}return this.dividedBy(e.getValue())}concatenateFront(e){return e.isArray()?e.concatenateBack(this):new W(this.concatenate(e.getValue(),q.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new W(this.concatenate(e.getValue(),q.BACK))}compare(e,r){return e.isArray()?e.compare(this,xr(r)):this.compareBy(e.getValue(),r)}plusBy(e){const r=this.getValue();if(typeof e=="string")return new d(f.VALUE);if(typeof e=="number"){if(!Number.isFinite(r)||!Number.isFinite(e))return new d(f.NUM);const s=Y(r).plus(e).toNumber();return Number.isFinite(s)?new w(s):new d(f.NUM)}return typeof e=="boolean"?new w(Y(r).plus(e?1:0).toNumber()):this}minusBy(e){const r=this.getValue();if(typeof e=="string")return new d(f.VALUE);if(typeof e=="number"){if(!Number.isFinite(r)||!Number.isFinite(e))return new d(f.NUM);const s=Y(r).minus(e).toNumber();return Number.isFinite(s)?new w(s):new d(f.NUM)}return typeof e=="boolean"?new w(Y(r).minus(e?1:0).toNumber()):this}multiplyBy(e){const r=this.getValue();if(typeof e=="string")return new d(f.VALUE);if(typeof e=="number"){if(!Number.isFinite(r)||!Number.isFinite(e))return new d(f.NUM);const s=Y(r).times(e).toNumber();return Number.isFinite(s)?new w(s):new d(f.NUM)}return typeof e=="boolean"?new w(Y(r).times(e?1:0).toNumber()):this}dividedBy(e){const r=this.getValue();if(typeof e=="string")return new d(f.VALUE);if(typeof e=="number"){if(e===0)return new d(f.DIV_BY_ZERO);if(!Number.isFinite(r)||!Number.isFinite(e))return new d(f.NUM);const s=Y(r).div(e).toNumber();return Number.isFinite(s)?new w(s):new d(f.NUM)}return typeof e=="boolean"?e===!1?new d(f.DIV_BY_ZERO):new w(Y(r).div(1).toNumber()):this}compareBy(e,r){const s=this.getValue();let i=!1;if(typeof e=="string")switch(r){case y.EQUALS:case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:i=!1;break;case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:case y.NOT_EQUAL:i=!0;break}else if(typeof e=="number")if(!Number.isFinite(s)||!Number.isFinite(e))i=this._compareInfinity(s,e,r);else switch(r){case y.EQUALS:i=Y(s).eq(e);break;case y.GREATER_THAN:i=Y(s).gt(e);break;case y.GREATER_THAN_OR_EQUAL:i=Y(s).gte(e);break;case y.LESS_THAN:i=Y(s).lt(e);break;case y.LESS_THAN_OR_EQUAL:i=Y(s).lte(e);break;case y.NOT_EQUAL:i=!Y(s).eq(e);break}else if(typeof e=="boolean")switch(r){case y.EQUALS:case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:i=!1;break;case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:case y.NOT_EQUAL:i=!0;break}return new X(i)}pow(e){if(e.isArray())return e.powInverse(this);const r=this.getValue(),s=e.getValue();if(typeof s=="string")return new d(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(r)||!Number.isFinite(s))return new d(f.NUM);const i=Fr(r,s);return Number.isFinite(i)?new w(i):new d(f.NUM)}return typeof s=="boolean"?new w(Fr(r,s?1:0)):this}sqrt(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Y(e).sqrt().toNumber();return Number.isFinite(r)?new w(r):new d(f.NUM)}cbrt(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.cbrt(e);return Number.isFinite(r)?new w(r):new d(f.NUM)}cos(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.cos(e);return Number.isFinite(r)?new w(r):new d(f.NUM)}acos(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.acos(e);return Number.isNaN(r)?new d(f.NUM):new w(r)}acosh(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.acosh(e);return Number.isNaN(r)?new d(f.NUM):new w(r)}sin(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.sin(e);return Number.isFinite(r)?new w(r):new d(f.NUM)}asin(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.asin(e);return Number.isNaN(r)?new d(f.NUM):new w(r)}asinh(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.asinh(e);return Number.isNaN(r)?new d(f.NUM):new w(r)}tan(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.tan(e);return Number.isFinite(r)?new w(r):new d(f.NUM)}tanh(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.tanh(e);return Number.isFinite(r)?new w(r):new d(f.NUM)}atan(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.atan(e);return Number.isFinite(r)?new w(r):new d(f.NUM)}atan2(e){if(e.isArray())return e.atan2Inverse(this);const r=this.getValue(),s=e.getValue();if(typeof s=="string")return new d(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(r)||!Number.isFinite(s))return new d(f.NUM);const i=Math.atan2(r,s);return Number.isFinite(i)?new w(i):new d(f.NUM)}return typeof s=="boolean"?new w(Math.atan2(r,s?1:0)):this}atanh(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.atanh(e);return Number.isFinite(r)?new w(r):new d(f.NUM)}log(){const e=this.getValue();if(typeof e=="number"&&e<=0)return new d(f.NUM);if(!Number.isFinite(e))return new d(f.NUM);const r=Math.log(e);return Number.isFinite(r)?new w(r):new d(f.NUM)}log10(){const e=this.getValue();if(typeof e=="number"&&e<=0)return new d(f.NUM);if(!Number.isFinite(e))return new d(f.NUM);const r=Math.log10(e);return Number.isFinite(r)?new w(r):new d(f.NUM)}exp(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.exp(e);return Number.isFinite(r)?new w(r):new d(f.NUM)}abs(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.abs(e);return Number.isFinite(r)?new w(r):new d(f.NUM)}round(e){if(e.isArray())return e.roundInverse(this);const r=this.getValue(),s=e.getValue();if(typeof s=="string")return new d(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(r)||!Number.isFinite(s))return new d(f.NUM);const i=Or(r,s);return Number.isFinite(i)?new w(i):new d(f.NUM)}return typeof s=="boolean"?new w(Or(r,s?1:0)):this}floor(e){if(e.isArray())return e.floorInverse(this);const r=this.getValue(),s=e.getValue();if(typeof s=="string")return new d(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(r)||!Number.isFinite(s))return new d(f.NUM);const i=Br(r,s);return Number.isFinite(i)?new w(i):new d(f.NUM)}return typeof s=="boolean"?new w(Br(r,s?1:0)):this}ceil(e){if(e.isArray())return e.ceilInverse(this);const r=this.getValue(),s=e.getValue();if(typeof s=="string")return new d(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(r)||!Number.isFinite(s))return new d(f.NUM);const i=Ur(r,s);return Number.isFinite(i)?new w(i):new d(f.NUM)}return typeof s=="boolean"?new w(Ur(r,s?1:0)):this}_compareInfinity(e,r,s){let i=!1;switch(s){case y.EQUALS:i=e===r;break;case y.GREATER_THAN:i=e>r;break;case y.GREATER_THAN_OR_EQUAL:i=e>=r;break;case y.LESS_THAN:i=e<r;break;case y.LESS_THAN_OR_EQUAL:i=e<=r;break;case y.NOT_EQUAL:i=e!==r;break}return i}}class W extends fe{constructor(e,r=!1){super(e);p(this,"_value");if(r){this._value=e;return}let s=e.toString();s.charAt(0)==='"'&&s.charAt(s.length-1)==='"'&&(s=s.slice(1,-1),s=s.replace(/""/g,'"')),this._value=s}getValue(){return this._value}isString(){return!0}concatenateFront(e){return e.isArray()?e.concatenateBack(this):new W(this.concatenate(e.getValue(),q.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new W(this.concatenate(e.getValue(),q.BACK))}compare(e,r){return e.isArray()?e.compare(this,xr(r)):this.compareBy(e.getValue(),r)}compareBy(e,r){const s=this.getValue();let i=!1;if(typeof e=="string"){if(Zn(e))return this._checkWildcard(e,r);switch(r){case y.EQUALS:i=s===e;break;case y.GREATER_THAN:i=s>e;break;case y.GREATER_THAN_OR_EQUAL:i=s>=e;break;case y.LESS_THAN:i=s<e;break;case y.LESS_THAN_OR_EQUAL:i=s<=e;break;case y.NOT_EQUAL:i=s!==e;break}}else if(typeof e=="number")switch(r){case y.EQUALS:case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:i=!0;break;case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:case y.NOT_EQUAL:i=!1;break}else if(typeof e=="boolean")switch(r){case y.EQUALS:case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:i=!1;break;case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:case y.NOT_EQUAL:i=!0;break}return new X(i)}_checkWildcard(e,r){const s=this.getValue().toLocaleLowerCase(),i=Jn(s,e,r);return new X(i)}}function os(t){return""}function us(t=[]){const n=[];for(let e=0;e<t.length;e++){const r=t[e];n[e]==null&&(n[e]=[]);for(let s=0;s<r.length;s++){const i=r[s];n[e][s]=de.create(i)}}return n}function ls(t=[]){const n=[];for(let e=0;e<t.length;e++){const r=t[e];n[e]==null&&(n[e]=[]);for(let s=0;s<r.length;s++){const i=r[s];i.isError()?n[e][s]=i.getErrorType():n[e][s]=i.getValue()}}return n}class Z extends fe{constructor(e){var n=(...Pa)=>(super(...Pa),p(this,"_values",[]),p(this,"_rowCount",-1),p(this,"_columnCount",-1),p(this,"_unitId",""),p(this,"_sheetId",""),p(this,"_currentRow",-1),p(this,"_currentColumn",-1),p(this,"_sliceCache",new Map),p(this,"_flattenCache"),this);if(typeof e=="string")n(e);else{const r=os();n(r)}this._values=this._formatValue(e)}dispose(){this._values.forEach(e=>{e.forEach(r=>{r.dispose()})}),this._values=[],this._clearCache()}getRowCount(){return this._rowCount}setRowCount(e){this._rowCount=e}getColumnCount(){return this._columnCount}setColumnCount(e){this._columnCount=e}setCurrent(e,r){this._currentRow=e,this._currentColumn=r}setUnitId(e){this._unitId=e}getUnitId(){return this._unitId}setSheetId(e){this._sheetId=e}getSheetId(){return this._sheetId}getCurrentRow(){return this._currentRow}getCurrentColumn(){return this._currentColumn}getArrayValue(){return this._values}setArrayValue(e){this._clearCache(),this._values=e}isArray(){return!0}get(e,r){const s=this._values[e][r];return s??new Qe(0)}set(e,r,s){if(e>=this._rowCount||r>=this._columnCount)throw new Error("Exceeding array bounds.");this._clearCache(),this._values[e][r]=s}getRangePosition(){const r=this.getRowCount(),s=0,i=this.getColumnCount();return{startRow:0,endRow:r-1,startColumn:s,endColumn:i-1}}iterator(e){const{startRow:r,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),o=this.getArrayValue();for(let u=r;u<=s;u++)for(let l=i;l<=a;l++)if(e(o[u][l],u,l)===!1)return}getFirstCell(){const{startRow:e,startColumn:r}=this.getRangePosition();return this.get(e,r)}pick(e){const r=e.getRowCount(),s=e.getColumnCount();if(r!==this._rowCount||s!==this._columnCount)return this._createNewArray([[new Qe(0)]],1,1);const i=[];i[0]=[];for(let a=0;a<r;a++)for(let o=0;o<s;o++){const u=e.get(a,o),l=this.get(a,o);u.isError()||u.getValue()===!0&&i[0].push(l)}return this._createNewArray(i,1,i[0].length)}flatten(){if(this._flattenCache!=null)return this._flattenCache;const e=[];e[0]=[];for(let s=0;s<this._rowCount;s++)for(let i=0;i<this._columnCount;i++){const a=this.get(s,i);e[0].push(a)}const r=this._createNewArray(e,1,e[0].length);return this._flattenCache=r,r}slice(e,r){let s=0,i=this._rowCount,a=1,o=0,u=this._columnCount,l=1;if(e!=null&&(s=e[0]||0,i=e[1]||this._rowCount,a=e[2]||1),r!=null&&(o=r[0]||0,u=r[1]||this._columnCount,l=r[2]||1),s>=this._rowCount||o>=this._columnCount)return;const c=`${s}_${i}_${a}_${o}_${u}_${l}`,h=this._sliceCache.get(c);if(h!=null)return h;const m=[],E=this._values;let C=0,R=0;for(let S=s;S<i;S+=a){R=0,m[C]==null&&(m[C]=[]);for(let P=o;P<u;P+=l)m[C][R]=E[S][P],R++;C++}if(m.length===0||m[0].length===0)return;const _=a>1?-1:s+this._currentRow,b=l>1?-1:o+this._currentColumn,L=this._createNewArray(m,m.length,m[0].length,_,b);return this._sliceCache.set(c,L),L}sortByRow(e){const r=this._transposeArray(this._values);r.sort(this._sort(e)),this._clearCache(),this._values=this._transposeArray(r)}sortByColumn(e){this._clearCache(),this._values.sort(this._sort(e))}transpose(){const e=this._transposeArray(this._values),r=this._rowCount,s=this._columnCount;return this._createNewArray(e,s,r)}binarySearch(e,r=rt.MIN){if(e.isError())return;const a=this.flatten().getArrayValue()[0],o=Lr(),u=e.getValue().toString();let l=0,c=a.length-1,h=null;for(;l<=c;){const m=Math.floor((l+c)/2),C=a[m].getValue(),R=o(C.toString(),u);if(R===0)return m;R===-1?(l=m+1,r===rt.MIN&&(h=m)):(c=m-1,r===rt.MAX&&(h=m))}return h}sum(){let e=new w(0);return this.iterator(r=>{if(r==null)return!0;if(r.isError())return e=r,!1;e=e.plus(r)}),e}max(){let e=new w(-1/0);return this.iterator(r=>{if(r==null)return!0;if(r.isError())return e=r,!1;if(r.isString()||r.isNull())return!0;e.isLessThan(r).getValue()&&(e=r)}),e}min(){let e=new w(1/0);return this.iterator(r=>{if(r==null)return!0;if(r.isError())return e=r,!1;if(r.isString()||r.isNull())return!0;e.isGreaterThan(r).getValue()&&(e=r)}),e}count(){let e=new w(0);return this.iterator(r=>{if(r==null||r.isError()||r.isString()||r.isNull())return!0;e=e.plusBy(1)}),e}countA(){let e=new w(0);return this.iterator(r=>{if(r==null||r.isNull())return!0;e=e.plusBy(1)}),e}countBlank(){let e=new w(0);return this.iterator(r=>{if(r!=null)return!0;e=e.plusBy(1)}),e}getNegative(){return new Z("{0}").minus(this)}getReciprocal(){return new Z("{1}").divided(this)}plus(e){return this._batchOperator(e,1)}minus(e){return this._batchOperator(e,0)}multiply(e){return this._batchOperator(e,2)}divided(e){return this._batchOperator(e,3)}compare(e,r){return this._batchOperator(e,4,r)}concatenateFront(e){return this._batchOperator(e,5)}concatenateBack(e){return this._batchOperator(e,6)}product(e,r){return this._batchOperator(e,7,r)}map(e){var a,o;const r=this._rowCount,s=this._columnCount,i=[];for(let u=0;u<r;u++){const l=[];for(let c=0;c<s;c++){const h=(o=(a=this._values)==null?void 0:a[u])==null?void 0:o[c];h?h.isError()?l[c]=h:l[c]=e(h,u,c):l[c]=new d(f.VALUE)}i.push(l)}return this._createNewArray(i,r,s)}pow(e){return this._batchOperator(e,8)}powInverse(e){return this.map(r=>r.isError()?r:e.pow(r))}sqrt(){return this.map(e=>e.isError()?e:e.sqrt())}cbrt(){return this.map(e=>e.isError()?e:e.cbrt())}cos(){return this.map(e=>e.isError()?e:e.cos())}acos(){return this.map(e=>e.isError()?e:e.acos())}acosh(){return this.map(e=>e.isError()?e:e.acosh())}sin(){return this.map(e=>e.isError()?e:e.sin())}asin(){return this.map(e=>e.isError()?e:e.asin())}asinh(){return this.map(e=>e.isError()?e:e.asinh())}tan(){return this.map(e=>e.isError()?e:e.tan())}tanh(){return this.map(e=>e.isError()?e:e.tanh())}atan(){return this.map(e=>e.isError()?e:e.atan())}atanh(){return this.map(e=>e.isError()?e:e.atanh())}atan2(e){return this._batchOperator(e,12)}atan2Inverse(e){return this.map(r=>r.isError()?r:e.atan2(r))}mean(){const e=this.sum(),r=this.countA();return e.divided(r)}median(){const e=this.flatten(),r=e.getColumnCount();if(r<=1)return e.get(0,0);if(e.sortByRow(0),r%2===0){const s=e.get(0,r/2),i=e.get(0,r/2-1);return s.plus(i).divided(new w(2,!0))}return e.get(0,(r-1)/2)}var(){const e=this.mean(),r=[];this.iterator((h,m,E)=>{(h==null||h.isError()||h.isString())&&(h=new w(0));let C=h.minus(e).pow(new w(2,!0));C.isError()&&(C=new w(0)),r[m]==null&&(r[m]=[]),r[m][E]=C});const{_rowCount:s,_columnCount:i,_unitId:a,_sheetId:o,_currentRow:u,_currentColumn:l}=this;return new Z({calculateValueList:r,rowCount:s,columnCount:i,unitId:a,sheetId:o,row:u,column:l}).mean()}std(){const e=this.var();return e.isError()?e:e.sqrt()}log(){return this.map(e=>e.isError()?e:e.log())}log10(){return this.map(e=>e.isError()?e:e.log10())}exp(){return this.map(e=>e.isError()?e:e.exp())}abs(){return this.map(e=>e.isError()?e:e.abs())}round(e){return this._batchOperator(e,9)}roundInverse(e){return this.map(r=>r.isError()?r:e.round(r))}floor(e){return this._batchOperator(e,10)}floorInverse(e){return this.map(r=>r.isError()?r:e.floor(r))}ceil(e){return this._batchOperator(e,11)}ceilInverse(e){return this.map(r=>r.isError()?r:e.ceil(r))}toValue(){return ls(this._values)}_clearCache(){this._flattenCache=null,this._sliceCache.clear()}_sort(e){const r=Lr();return(s,i)=>{const a=s[e],o=i[e];return a.isError()&&a.isError()?0:a.isError()?1:o.isError()?-1:r(a.getValue(),o.getValue())}}_transposeArray(e){const r=e.length,s=e[0].length,i=[];for(let a=0;a<s;a++){i[a]=[];for(let o=0;o<r;o++)i[a][o]=e[o][a]}return i}_batchOperator(e,r,s){const i=[];let a=this._rowCount,o=this._columnCount;if(e.isArray()){const l=e.getRowCount(),c=e.getColumnCount();if(a=Math.max(l,a),o=Math.max(c,o),l===1&&c===1){const h=e.getFirstCell();for(let m=0;m<o;m++)i.push(h)}else if(l===1&&this._columnCount>1){const h=e.getArrayValue();for(let m=0;m<o;m++)i.push(h[0][m])}else return this._batchOperatorArray(e,r,s)}else for(let l=0;l<o;l++)i.push(e);const u=[];for(let l=0;l<o;l++){const c=i[l];this._batchOperatorValue(c,l,u,r,s)}return this._createNewArray(u,a,o)}_batchOperatorValue(e,r,s,i,a){var E,C;const o=this._rowCount;let u=!1;const l=this.getUnitId(),c=this.getSheetId(),h=this.getCurrentRow(),m=this.getCurrentColumn();if(i===4&&(u=he.canUseCache(l,c,r+m,h,h+o-1),u===!0)){if(a===y.EQUALS){const R=he.getCellPositions(l,c,r+m,e.getValue());for(let _=0;_<o;_++)s[_]==null&&(s[_]=[]),R!=null&&R.includes(_+h)?s[_][r]=new X(!0):s[_][r]=new X(!1)}else{const R=he.getCellValuePositions(l,c,r+m);if(R!=null)R.forEach((_,b)=>{let L;if(typeof b=="string"?L=new W(b):typeof b=="number"?L=new w(b):typeof b=="boolean"&&(L=new X(b)),L==null)return!0;if(L.compare(e,a))for(let P=0;P<o;P++)s[P]==null&&(s[P]=[]),_.includes(P+h)?s[P][r]=new X(!0):s[P][r]=new X(!1)});else for(let _=0;_<o;_++)s[_]==null&&(s[_]=[]),s[_][r]=new X(!1)}return}for(let R=0;R<o;R++){const _=(C=(E=this._values)==null?void 0:E[R])==null?void 0:C[r];if(s[R]==null&&(s[R]=[]),_&&e)if(_.isError())s[R][r]=_;else if(e.isError())s[R][r]=new d(f.VALUE);else switch(i){case 1:s[R][r]=_.plus(e);break;case 0:s[R][r]=_.minus(e);break;case 2:s[R][r]=_.multiply(e);break;case 3:s[R][r]=_.divided(e);break;case 4:a?s[R][r]=_.compare(e,a):s[R][r]=new d(f.VALUE);break;case 5:s[R][r]=_.concatenateFront(e);break;case 6:s[R][r]=_.concatenateBack(e);break;case 7:a?s[R][r]=_.product(e,a):s[R][r]=new d(f.VALUE);break;case 8:s[R][r]=_.pow(e);break;case 9:s[R][r]=_.round(e);break;case 10:s[R][r]=_.floor(e);break;case 12:s[R][r]=_.atan2(e);break;case 11:s[R][r]=_.ceil(e);break}else s[R][r]=new d(f.NA);_!=null&&(_.isError()?he.set(l,c,r+m,_.getErrorType(),R+h):_.isNull()?he.set(l,c,r+m,null,R+h):he.set(l,c,r+m,_.getValue(),R+h))}he.setContinueBuildingCache(l,c,r+m,h,h+o-1)}_batchOperatorArray(e,r,s){var h,m,E,C,R,_,b,L,S,P,k,j;let i=e.getRowCount(),a=e.getColumnCount();i<this._rowCount&&(i=this._rowCount),a<this._columnCount&&(a=this._columnCount);const o=[],u=e.getArrayValue(),l=this._checkArrayCalculateType(this),c=this._checkArrayCalculateType(e);for(let H=0;H<i;H++){const B=[];for(let v=0;v<a;v++){let F;l===3?F=(m=(h=this._values)==null?void 0:h[0])==null?void 0:m[0]:l===1?F=(C=(E=this._values)==null?void 0:E[0])==null?void 0:C[v]:l===2?F=(_=(R=this._values)==null?void 0:R[H])==null?void 0:_[0]:F=(L=(b=this._values)==null?void 0:b[H])==null?void 0:L[v];let $;if(c===3?$=(S=u==null?void 0:u[0])==null?void 0:S[0]:c===1?$=(P=u==null?void 0:u[0])==null?void 0:P[v]:c===2?$=(k=u==null?void 0:u[H])==null?void 0:k[0]:$=(j=u==null?void 0:u[H])==null?void 0:j[v],F&&$)if(F.isError())B[v]=F;else if($.isError())B[v]=$;else switch(r){case 1:B[v]=F.plus($);break;case 0:B[v]=F.minus($);break;case 2:B[v]=F.multiply($);break;case 3:B[v]=F.divided($);break;case 4:s?B[v]=F.compare($,s):B[v]=new d(f.VALUE);break;case 5:B[v]=F.concatenateFront($);break;case 6:B[v]=F.concatenateBack($);break;case 7:s?B[v]=F.product($,s):B[v]=new d(f.VALUE);break;case 8:B[v]=F.pow($);break;case 9:B[v]=F.round($);break;case 12:B[v]=F.atan2($);break;case 10:B[v]=F.floor($);break;case 11:B[v]=F.ceil($);break}else B[v]=new d(f.NA)}o.push(B)}return this._createNewArray(o,i,a)}_checkArrayCalculateType(e){return e.getRowCount()===1&&e.getColumnCount()===1?3:e.getRowCount()===1?1:e.getColumnCount()===1?2:0}_formatValue(e){if(typeof e!="string")return e=e,this._rowCount=e.rowCount,this._columnCount=e.columnCount,this._unitId=e.unitId,this._sheetId=e.sheetId,this._currentRow=e.row,this._currentColumn=e.column,e.calculateValueList;e=e.slice(1,-1);const r=e.split(";"),s=r.length,i=[];let a=0;for(let o=0;o<s;o++){const l=r[o].split(","),c=l.length;a<c&&(a=c);const h=[];for(let m=0;m<c;m++){const E=l[m].trim();h.push(de.create(E))}i.push(h)}return this._rowCount=s,this._columnCount=a,i}_createNewArray(e,r,s,i=-1,a=-1){(this._currentColumn===-1||this._currentRow===-1)&&(i=-1,a=-1);const o={calculateValueList:e,rowCount:r,columnCount:s,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:i,column:a};return new Z(o)}}class de{static create(n){if(n==null)return new Qe(0);if(typeof n=="boolean")return new X(n,!0);if(typeof n=="string"){const e=n.toLocaleUpperCase().trim();return Vt.has(e)?new d(e):e===pe.TRUE||e===pe.FALSE?new X(e):g.isRealNum(n)?new w(n):new RegExp(Yn,"g").test(n.replace(/\n/g,"").replace(/\r/g,""))?new Z(n.replace(/\n/g,"").replace(/\r/g,"")):new W(n)}return typeof n=="number"?Number.isFinite(n)?new w(n,!0):new d(f.NUM):new d(f.NA)}}const cs=1e5,Gt=new Ke(cs);class xe extends tt{constructor(e){super();p(this,"_forcedSheetId","");p(this,"_forcedSheetName","");p(this,"_defaultSheetId","");p(this,"_rangeData",{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1});p(this,"_unitData",{});p(this,"_defaultUnitId","");p(this,"_forcedUnitId","");p(this,"_runtimeData",{});p(this,"_arrayFormulaCellData",{});p(this,"_runtimeArrayFormulaCellData",{});p(this,"_runtimeFeatureCellData",{});p(this,"_refOffsetX",0);p(this,"_refOffsetY",0);this._token=e}dispose(){this._unitData={},this._runtimeData={}}isExceedRange(){const{startRow:e,endRow:r,startColumn:s,endColumn:i}=this.getRangePosition();return e<0||s<0||r>=this.getRowCount()||i>=this.getColumnCount()}setRefOffset(e=0,r=0){this._refOffsetX=e,this._refOffsetY=r}getRefOffset(){return{x:this._refOffsetX,y:this._refOffsetY}}getRangePosition(){let e=this._rangeData.startRow+this._refOffsetY,r=this._rangeData.endRow+this._refOffsetY,s=this._rangeData.startColumn+this._refOffsetX,i=this._rangeData.endColumn+this._refOffsetX;return isNaN(e)&&(e=0),isNaN(s)&&(s=0),isNaN(r)&&(r=this.getRowCount()-1),isNaN(i)&&(i=this.getColumnCount()-1),{startRow:e,endRow:r,startColumn:s,endColumn:i}}isReferenceObject(){return!0}iterator(e){const{startRow:r,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition();if(this._checkIfWorksheetMiss())return e(new d(f.VALUE),r,i);for(let o=r;o<=s;o++)for(let u=i;u<=a;u++){if(o<0||u<0)return e(new d(f.REF),o,u);const l=this.getCellData(o,u);let c=!1;if(l==null||g.isNullCell(l)){c=e(null,o,u);continue}const h=this.getCellValueObject(l);if(c=e(h,o,u),c===!1)return}}getFirstCell(){const{startRow:e,startColumn:r}=this.getRangePosition(),s=this.getCellData(e,r);return s?this.getCellValueObject(s):new w(0,!0)}getRangeData(){return this._rangeData}setRangeData(e){this._rangeData=e}getUnitId(){return this._forcedUnitId&&this._forcedUnitId.length>0?this._forcedUnitId:this._defaultUnitId}getSheetId(){return this._forcedSheetId&&this._forcedSheetId.length>0?this._forcedSheetId:this._defaultSheetId}setForcedUnitIdDirect(e){e.length>0&&(this._forcedUnitId=e)}getForcedUnitId(){return this._forcedUnitId}setForcedSheetId(e){var r;this._forcedSheetId=(r=e[this.getUnitId()])==null?void 0:r[this._forcedSheetName]}setForcedSheetIdDirect(e){this._forcedSheetId=e}getForcedSheetId(){return this._forcedSheetId}setForcedSheetName(e){e.length>0&&(this._forcedSheetName=e)}getForcedSheetName(){return this._forcedSheetName}setDefaultSheetId(e){this._defaultSheetId=e}getDefaultSheetId(){return this._defaultSheetId}setDefaultUnitId(e){this._defaultUnitId=e}getDefaultUnitId(){return this._defaultUnitId}getUnitData(){return this._unitData}setUnitData(e){this._unitData=e}getRuntimeData(){return this._runtimeData}setRuntimeData(e){this._runtimeData=e}getArrayFormulaCellData(){return this._arrayFormulaCellData}setArrayFormulaCellData(e){this._arrayFormulaCellData=e}getRuntimeArrayFormulaCellData(){return this._runtimeArrayFormulaCellData}setRuntimeArrayFormulaCellData(e){this._runtimeArrayFormulaCellData=e}getRuntimeFeatureCellData(){return this._runtimeFeatureCellData}setRuntimeFeatureCellData(e){this._runtimeFeatureCellData=e}getRowCount(){return this.getCurrentActiveSheetData().rowCount}getColumnCount(){return this.getCurrentActiveSheetData().columnCount}isCell(){return!1}isColumn(){return!1}isRow(){return!1}isRange(){return!1}isTable(){return!1}unionBy(e){return new d(f.REF)}unionRange(e,r){return{startRow:-1,startColumn:-1,endRow:-1,endColumn:-1}}getCellValueObject(e){const r=e.v||0;return Vt.has(r)?new d(r):e.t===g.CellValueType.NUMBER?new w(r):e.t===g.CellValueType.STRING||e.t===g.CellValueType.FORCE_STRING?new W(r):e.t===g.CellValueType.BOOLEAN?new X(r):de.create(r)}getCellByRow(e){return this.getCellByPosition(e)}getCellByColumn(e){return this.getCellByPosition(void 0,e)}getCurrentActiveSheetData(){return this._unitData[this.getUnitId()][this.getSheetId()]}getCurrentRuntimeSheetData(){var e,r;return(r=(e=this._runtimeData)==null?void 0:e[this.getUnitId()])==null?void 0:r[this.getSheetId()]}getCurrentActiveArrayFormulaCellData(){var e,r;return(r=(e=this._arrayFormulaCellData)==null?void 0:e[this.getUnitId()])==null?void 0:r[this.getSheetId()]}getCurrentRuntimeActiveArrayFormulaCellData(){var e,r;return(r=(e=this._runtimeArrayFormulaCellData)==null?void 0:e[this.getUnitId()])==null?void 0:r[this.getSheetId()]}getCellData(e,r){const s=this.getCurrentActiveSheetData(),i=this.getCurrentRuntimeSheetData(),a=this.getCurrentActiveArrayFormulaCellData(),o=this.getCurrentRuntimeActiveArrayFormulaCellData();return(i==null?void 0:i.getValue(e,r))||(o==null?void 0:o.getValue(e,r))||this.getRuntimeFeatureCellValue(e,r)||(a==null?void 0:a.getValue(e,r))||s.cellData.getValue(e,r)}getRuntimeFeatureCellValue(e,r){var i;const s=Object.keys(this._runtimeFeatureCellData);for(const a of s){const o=this._runtimeFeatureCellData[a],u=(i=o==null?void 0:o[this.getUnitId()])==null?void 0:i[this.getSheetId()];if(u==null)continue;const l=u.getValue(e,r);if(l!=null)return l}}getCellByPosition(e,r){e||(e=this._rangeData.startRow),r||(r=this._rangeData.startColumn);const s=this.getCellData(e,r);return s?this.getCellValueObject(s):new d(f.VALUE)}toArrayValueObject(e=!0){var C;const{startRow:r,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),o=`${this.getUnitId()}_${this.getSheetId()}_${r}_${s}_${i}_${a}`,u=Gt.get(o);if(u&&e)return u;const l=s-r+1,c=a-i+1;if(l<0||c<0)return this._getBlankArrayValueObject();const h=new Array(l);this.iterator((R,_,b)=>{const L=_-r,S=b-i;h[L]||(h[L]=new Array(c)),R==null&&(R=new Qe(0)),h[L][S]=R});const m={calculateValueList:h,rowCount:h.length,columnCount:((C=h[0])==null?void 0:C.length)||0,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:r,column:i},E=new Z(m);return e&&Gt.set(o,E),E}toUnitRange(){return{range:this.getRangePosition(),sheetId:this.getSheetId(),unitId:this.getUnitId()}}_checkIfWorksheetMiss(){return(this._forcedSheetId==null||this._forcedSheetId.length===0)&&this._forcedSheetName.length>0}_getBlankArrayValueObject(){const e={calculateValueList:[],rowCount:0,columnCount:0,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:0,column:0};return new Z(e)}}class hs extends tt{constructor(n){super(),this._promise=n}isAsyncObject(){return!0}async getValue(){return this._promise}}class fs extends tt{constructor(n){super(),this._promiseList=n}isAsyncArrayObject(){return!0}async getValue(){var r;const n=[];for(let s=0;s<this._promiseList.length;s++){const i=this._promiseList[s];n[s]==null&&(n[s]=[]);for(let a=0;a<i.length;a++){const o=i[a];o.isAsyncObject()?n[s][a]=await o.getValue():n[s][a]=o}}const e={calculateValueList:n,rowCount:n.length,columnCount:((r=n[0])==null?void 0:r.length)||0,unitId:"",sheetId:"",row:0,column:0};return new Z(e)}}class st extends xe{constructor(n,e,r){super(""),this.setRangeData(n),e&&this.setForcedSheetIdDirect(e),r&&this.setForcedUnitIdDirect(r)}isRange(){return!0}}const Mr=/[\[\]]/g;function $r(t,n){if(Mr.test(t)){const e=Number(t.replace(Mr,""));return n+e}return Number(t)-1}function Kt(t,n=0,e=0){t=t.toLocaleUpperCase();const r=t.split(/[RC]/),s=r[1],i=r[2],a=$r(s,n),o=$r(i,e);return{row:a,column:o,absoluteRefType:g.AbsoluteRefType.NONE}}function kr(t,n=0,e=0){const{refBody:r,sheetName:s,unitId:i}=mr(t),a=r.indexOf(":");if(a===-1){const R=Kt(r,n,e),_=R.row,b=R.column,L=R.absoluteRefType;return{unitId:i,sheetName:s,range:{startRow:_,startColumn:b,endRow:_,endColumn:b,startAbsoluteRefType:L,endAbsoluteRefType:L}}}const o=r.substring(0,a),u=r.substring(a+1),l=Kt(o,n,e),c=Kt(u,n,e),h=l.row,m=l.column,E=c.row,C=c.column;return{unitId:i,sheetName:s,range:{startRow:h,startColumn:m,endRow:E,endColumn:C,startAbsoluteRefType:l.absoluteRefType,endAbsoluteRefType:c.absoluteRefType}}}function ds(t){const n=it(t.startRow,t.startAbsoluteRefType,!0),e=it(t.startColumn,t.startAbsoluteRefType,!1),r=it(t.endRow,t.endAbsoluteRefType,!0),s=it(t.endColumn,t.endAbsoluteRefType,!1);return n===r&&e===s?`R${n}C${e}`:`R${n}C${e}:R${r}C${s}`}function it(t,n=g.AbsoluteRefType.ALL,e){switch(t+=1,n){case g.AbsoluteRefType.ALL:return`${t}`;case g.AbsoluteRefType.ROW:return e?`${t}`:`[${t}]`;case g.AbsoluteRefType.COLUMN:return e?`[${t}]`:`${t}`;case g.AbsoluteRefType.NONE:return`[${t}]`}}const jr=[];var ms=(t=>{})();class M extends g.Disposable{constructor(e){super();p(this,"_unitId");p(this,"_subUnitId");p(this,"_row",-1);p(this,"_column",-1);this._name=e}get name(){return this._name}get unitId(){return this._unitId}get subUnitId(){return this._subUnitId}get row(){return this._row}get column(){return this._column}isAsync(){return!1}isAddress(){return!1}isCustom(){return!1}setRefInfo(e,r,s,i){this._unitId=e,this._subUnitId=r,this._row=s,this._column=i}calculateCustom(...e){return null}calculate(...e){return new d(f.VALUE)}checkArrayType(e){return e.isReferenceObject()||e.isValueObject()&&e.isArray()}getIndexNumValue(e){if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())return e.getValue()===!1?new d(f.VALUE):1;if(e.isString()){const r=Number(e.getValue());if(isNaN(r))return new d(f.REF)}else if(e.isNumber())return e.getValue();return new d(f.VALUE)}getZeroOrOneByOneDefault(e){if(e==null)return 1;let r=1;if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())e.getValue()===!1&&(r=0);else{if(e.isString())return;e.isNumber()&&e.getValue()===0&&(r=0)}return r}}const Qr=[];var Tr=(t=>(t.BETADIST="BETADIST",t.BETAINV="BETAINV",t.BINOMDIST="BINOMDIST",t.CHIDIST="CHIDIST",t.CHIINV="CHIINV",t.CHITEST="CHITEST",t.CONFIDENCE="CONFIDENCE",t.COVAR="COVAR",t.CRITBINOM="CRITBINOM",t.EXPONDIST="EXPONDIST",t.FDIST="FDIST",t.FINV="FINV",t.FTEST="FTEST",t.GAMMADIST="GAMMADIST",t.GAMMAINV="GAMMAINV",t.HYPGEOMDIST="HYPGEOMDIST",t.LOGINV="LOGINV",t.LOGNORMDIST="LOGNORMDIST",t.MODE="MODE",t.NEGBINOMDIST="NEGBINOMDIST",t.NORMDIST="NORMDIST",t.NORMINV="NORMINV",t.NORMSDIST="NORMSDIST",t.NORMSINV="NORMSINV",t.PERCENTILE="PERCENTILE",t.PERCENTRANK="PERCENTRANK",t.POISSON="POISSON",t.QUARTILE="QUARTILE",t.RANK="RANK",t.STDEV="STDEV",t.STDEVP="STDEVP",t.TDIST="TDIST",t.TINV="TINV",t.TTEST="TTEST",t.VAR="VAR",t.VARP="VARP",t.WEIBULL="WEIBULL",t.ZTEST="ZTEST",t))(Tr||{});const Hr=[];var Yr=(t=>(t.CUBEKPIMEMBER="CUBEKPIMEMBER",t.CUBEMEMBER="CUBEMEMBER",t.CUBEMEMBERPROPERTY="CUBEMEMBERPROPERTY",t.CUBERANKEDMEMBER="CUBERANKEDMEMBER",t.CUBESET="CUBESET",t.CUBESETCOUNT="CUBESETCOUNT",t.CUBEVALUE="CUBEVALUE",t))(Yr||{});const Wr=[];var Xr=(t=>(t.DAVERAGE="DAVERAGE",t.DCOUNT="DCOUNT",t.DCOUNTA="DCOUNTA",t.DGET="DGET",t.DMAX="DMAX",t.DMIN="DMIN",t.DPRODUCT="DPRODUCT",t.DSTDEV="DSTDEV",t.DSTDEVP="DSTDEVP",t.DSUM="DSUM",t.DVAR="DVAR",t.DVARP="DVARP",t))(Xr||{});const Gr=[];var Kr=(t=>(t.DATE="DATE",t.DATEDIF="DATEDIF",t.DATEVALUE="DATEVALUE",t.DAY="DAY",t.DAYS="DAYS",t.DAYS360="DAYS360",t.EDATE="EDATE",t.EOMONTH="EOMONTH",t.HOUR="HOUR",t.ISOWEEKNUM="ISOWEEKNUM",t.MINUTE="MINUTE",t.MONTH="MONTH",t.NETWORKDAYS="NETWORKDAYS",t.NETWORKDAYS_INTL="NETWORKDAYS.INTL",t.NOW="NOW",t.SECOND="SECOND",t.TIME="TIME",t.TIMEVALUE="TIMEVALUE",t.TODAY="TODAY",t.WEEKDAY="WEEKDAY",t.WEEKNUM="WEEKNUM",t.WORKDAY="WORKDAY",t.WORKDAY_INTL="WORKDAY.INTL",t.YEAR="YEAR",t.YEARFRAC="YEARFRAC",t))(Kr||{});const Ir=[];var zr=(t=>(t.BESSELI="BESSELI",t.BESSELJ="BESSELJ",t.BESSELK="BESSELK",t.BESSELY="BESSELY",t.BIN2DEC="BIN2DEC",t.BIN2HEX="BIN2HEX",t.BIN2OCT="BIN2OCT",t.BITAND="BITAND",t.BITLSHIFT="BITLSHIFT",t.BITOR="BITOR",t.BITRSHIFT="BITRSHIFT",t.BITXOR="BITXOR",t.COMPLEX="COMPLEX",t.CONVERT="CONVERT",t.DEC2BIN="DEC2BIN",t.DEC2HEX="DEC2HEX",t.DEC2OCT="DEC2OCT",t.DELTA="DELTA",t.ERF="ERF",t.ERF_PRECISE="ERF.PRECISE",t.ERFC="ERFC",t.ERFC_PRECISE="ERFC.PRECISE",t.GESTEP="GESTEP",t.HEX2BIN="HEX2BIN",t.HEX2DEC="HEX2DEC",t.HEX2OCT="HEX2OCT",t.IMABS="IMABS",t.IMAGINARY="IMAGINARY",t.IMARGUMENT="IMARGUMENT",t.IMCONJUGATE="IMCONJUGATE",t.IMCOS="IMCOS",t.IMCOSH="IMCOSH",t.IMCOT="IMCOT",t.IMCSC="IMCSC",t.IMCSCH="IMCSCH",t.IMDIV="IMDIV",t.IMEXP="IMEXP",t.IMLN="IMLN",t.IMLOG10="IMLOG10",t.IMLOG2="IMLOG2",t.IMPOWER="IMPOWER",t.IMPRODUCT="IMPRODUCT",t.IMREAL="IMREAL",t.IMSEC="IMSEC",t.IMSECH="IMSECH",t.IMSIN="IMSIN",t.IMSINH="IMSINH",t.IMSQRT="IMSQRT",t.IMSUB="IMSUB",t.IMSUM="IMSUM",t.IMTAN="IMTAN",t.OCT2BIN="OCT2BIN",t.OCT2DEC="OCT2DEC",t.OCT2HEX="OCT2HEX",t))(zr||{});const qr=[];var Zr=(t=>(t.ACCRINT="ACCRINT",t.ACCRINTM="ACCRINTM",t.AMORDEGRC="AMORDEGRC",t.AMORLINC="AMORLINC",t.COUPDAYBS="COUPDAYBS",t.COUPDAYS="COUPDAYS",t.COUPDAYSNC="COUPDAYSNC",t.COUPNCD="COUPNCD",t.COUPNUM="COUPNUM",t.COUPPCD="COUPPCD",t.CUMIPMT="CUMIPMT",t.CUMPRINC="CUMPRINC",t.DB="DB",t.DDB="DDB",t.DISC="DISC",t.DOLLARDE="DOLLARDE",t.DOLLARFR="DOLLARFR",t.DURATION="DURATION",t.EFFECT="EFFECT",t.FV="FV",t.FVSCHEDULE="FVSCHEDULE",t.INTRATE="INTRATE",t.IPMT="IPMT",t.IRR="IRR",t.ISPMT="ISPMT",t.MDURATION="MDURATION",t.MIRR="MIRR",t.NOMINAL="NOMINAL",t.NPER="NPER",t.NPV="NPV",t.ODDFPRICE="ODDFPRICE",t.ODDFYIELD="ODDFYIELD",t.ODDLPRICE="ODDLPRICE",t.ODDLYIELD="ODDLYIELD",t.PDURATION="PDURATION",t.PMT="PMT",t.PPMT="PPMT",t.PRICE="PRICE",t.PRICEDISC="PRICEDISC",t.PRICEMAT="PRICEMAT",t.PV="PV",t.RATE="RATE",t.RECEIVED="RECEIVED",t.RRI="RRI",t.SLN="SLN",t.SYD="SYD",t.TBILLEQ="TBILLEQ",t.TBILLPRICE="TBILLPRICE",t.TBILLYIELD="TBILLYIELD",t.VDB="VDB",t.XIRR="XIRR",t.XNPV="XNPV",t.YIELD="YIELD",t.YIELDDISC="YIELDDISC",t.YIELDMAT="YIELDMAT",t))(Zr||{});const Jr=[];var Nr=(t=>(t.CELL="CELL",t.ERROR_TYPE="ERROR.TYPE",t.INFO="INFO",t.ISBLANK="ISBLANK",t.ISERR="ISERR",t.ISERROR="ISERROR",t.ISEVEN="ISEVEN",t.ISFORMULA="ISFORMULA",t.ISLOGICAL="ISLOGICAL",t.ISNA="ISNA",t.ISNONTEXT="ISNONTEXT",t.ISNUMBER="ISNUMBER",t.ISODD="ISODD",t.ISOMITTED="ISOMITTED",t.ISREF="ISREF",t.ISTEXT="ISTEXT",t.N="N",t.NA="NA",t.SHEET="SHEET",t.SHEETS="SHEETS",t.TYPE="TYPE",t))(Nr||{}),at=(t=>(t.AND="AND",t.BYCOL="BYCOL",t.BYROW="BYROW",t.FALSE="FALSE",t.IF="IF",t.IFERROR="IFERROR",t.IFNA="IFNA",t.IFS="IFS",t.LAMBDA="LAMBDA",t.LET="LET",t.MAKEARRAY="MAKEARRAY",t.MAP="MAP",t.NOT="NOT",t.OR="OR",t.REDUCE="REDUCE",t.SCAN="SCAN",t.SWITCH="SWITCH",t.TRUE="TRUE",t.XOR="XOR",t))(at||{});class gs extends M{calculate(...n){return new d(f.VALUE)}}class Rs extends M{calculate(...n){if(n.length!==3)return new d(f.VALUE);const e=this.getIndexNumValue(n[0]);if(typeof e!="number")return e;const r=this.getIndexNumValue(n[1]);if(typeof r!="number")return r;if(!(n[2].isValueObject()&&n[2].isLambda()))return new d(f.VALUE);const s=n[2],i=[];for(let a=0;a<e;a++){i[a]==null&&(i[a]=[]);for(let o=0;o<r;o++){const u=s.execute(new w(a+1),new w(o+1));i[a][o]=u}}return new fs(i)}isAsync(){return!0}}const en=[[gs,at.LAMBDA],[Rs,at.MAKEARRAY]];class ps extends M{calculate(n,e,r,s,i){if(n.isError()||e.isError()||r&&r.isError()||s&&s.isError()||i&&i.isError())return new d(f.VALUE);const a=Number(n.getValue())-1,o=Number(e.getValue())-1;if(Number.isNaN(a)||Number.isNaN(o))return new d(f.VALUE);const u=r?Ds(r.getValue()):g.AbsoluteRefType.ALL,l=this.getZeroOrOneByOneDefault(s),c=i?`${i.getValue()}`:"",h=Ie(c)?`'${c}'`:c,m={startRow:a,startColumn:o,endRow:a,endColumn:o,startAbsoluteRefType:u,endAbsoluteRefType:u},E=s&&!l?ds(m):ge(m);return new W(h!==""?`${h}!${E}`:E)}}function Ds(t){switch(t){case 1:return g.AbsoluteRefType.ALL;case 2:return g.AbsoluteRefType.ROW;case 3:return g.AbsoluteRefType.COLUMN;case 4:return g.AbsoluteRefType.NONE;default:return g.AbsoluteRefType.ALL}}var Oe=(t=>(t.ADDRESS="ADDRESS",t.AREAS="AREAS",t.CHOOSE="CHOOSE",t.CHOOSECOLS="CHOOSECOLS",t.CHOOSEROWS="CHOOSEROWS",t.COLUMN="COLUMN",t.COLUMNS="COLUMNS",t.DROP="DROP",t.EXPAND="EXPAND",t.FILTER="FILTER",t.FORMULATEXT="FORMULATEXT",t.GETPIVOTDATA="GETPIVOTDATA",t.HLOOKUP="HLOOKUP",t.HSTACK="HSTACK",t.HYPERLINK="HYPERLINK",t.IMAGE="IMAGE",t.INDEX="INDEX",t.INDIRECT="INDIRECT",t.LOOKUP="LOOKUP",t.MATCH="MATCH",t.OFFSET="OFFSET",t.ROW="ROW",t.ROWS="ROWS",t.RTD="RTD",t.SORT="SORT",t.SORTBY="SORTBY",t.TAKE="TAKE",t.TOCOL="TOCOL",t.TOROW="TOROW",t.TRANSPOSE="TRANSPOSE",t.UNIQUE="UNIQUE",t.VLOOKUP="VLOOKUP",t.VSTACK="VSTACK",t.WRAPCOLS="WRAPCOLS",t.WRAPROWS="WRAPROWS",t.XLOOKUP="XLOOKUP",t.XMATCH="XMATCH",t))(Oe||{});class It extends xe{constructor(n){super(n);const e=Pe(n);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName),this.setRangeData(e.range)}isCell(){return!0}unionBy(n){if(!n.isCell())return new d(f.REF);const e=n,r=this.unionRange(this.getRangeData(),e.getRangeData());return this._createRange(r)}unionRange(n,e){const r=n.startRow,s=n.startColumn,i=e.startRow,a=e.startColumn,o={startRow:-1,startColumn:-1,endRow:-1,endColumn:-1};return r>i?(o.startRow=i,o.endRow=r):(o.startRow=r,o.endRow=i),s>a?(o.startColumn=a,o.endColumn=s):(o.startColumn=s,o.endColumn=a),o}_createRange(n){const e=new st(n,this.getForcedSheetId(),this.getForcedUnitId());e.setUnitData(this.getUnitData()),e.setDefaultSheetId(this.getDefaultSheetId()),e.setDefaultUnitId(this.getDefaultUnitId()),e.setRuntimeData(this.getRuntimeData()),e.setArrayFormulaCellData(this.getArrayFormulaCellData()),e.setRuntimeArrayFormulaCellData(this.getRuntimeArrayFormulaCellData()),e.setRuntimeFeatureCellData(this.getRuntimeFeatureCellData());const{x:r,y:s}=this.getRefOffset();e.setRefOffset(r,s);const i=this.getForcedSheetId();e.setForcedSheetName(this.getForcedSheetName()),i!=null&&e.setForcedSheetIdDirect(i);const a=this.getForcedUnitId();return a&&e.setForcedUnitIdDirect(a),e}}class tn extends xe{constructor(n){super(n);const e=Pe(n);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const r={startColumn:e.range.startColumn,startRow:NaN,endColumn:-1,endRow:NaN};this.setRangeData(r)}isColumn(){return!0}unionBy(n){if(!n.isColumn())return new d(f.REF);const e=n;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return new d(f.REF);const r=this.getRangeData(),s=e.getRangeData().startColumn,i=r.startColumn;return s>i?r.endColumn=s:(r.startColumn=s,r.endColumn=i),this}}class rn extends xe{constructor(n){super(n);const e=Pe(n);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const r={startColumn:NaN,startRow:e.range.startRow,endColumn:NaN,endRow:-1};this.setRangeData(r)}isRow(){return!0}unionBy(n){if(!n.isRow())return new d(f.REF);const e=n;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return new d(f.REF);const r=this.getRangeData(),s=e.getRangeData().startRow,i=r.startRow;return s>i?r.endRow=s:(r.startRow=s,r.endRow=i),this}}class Es extends M{calculate(n,e){let r=this.getZeroOrOneByOneDefault(e);if(r==null&&(r=1),n.isError())return new d(f.NA);if(n.isArray()){const c=n;if(c.getRowCount()===1&&c.getColumnCount()===1)n=c.getFirstCell();else return c.map(()=>new d(f.VALUE))}if(!n.isString())return new d(f.REF);const s=n.getValue();if(r===0){const c=kr(s),{range:h,sheetName:m,unitId:E}=c,C=new st(h);return C.setForcedUnitIdDirect(E),C.setForcedSheetName(m),this._setDefault(C)}if(new RegExp(ze).test(s))return this._setDefault(new It(s));if(new RegExp(gr).test(s))return this._setDefault(new rn(s));if(new RegExp(Rr).test(s))return this._setDefault(new tn(s));const i=Pe(s),{range:a,sheetName:o,unitId:u}=i,l=new st(a);return l.setForcedUnitIdDirect(u),l.setForcedSheetName(o),this._setDefault(l)}_setDefault(n){return this.unitId==null||this.subUnitId==null?new d(f.REF):(n.setDefaultUnitId(this.unitId),n.setDefaultSheetId(this.subUnitId),n)}}class _s extends M{calculate(n,e,r,s,i){return new It("A5")}}class Cs extends M{calculate(n,e,r,s){if(n.isError())return n;if(e.isError())return new d(f.REF);if(!e.isArray())return new d(f.VALUE);if(r.isError())return new d(f.NA);if(s!=null&&s.isError())return new d(f.NA);const i=this.getZeroOrOneByOneDefault(s);if(i==null)return new d(f.VALUE);const a=this.getIndexNumValue(r);if(a instanceof d)return a;const o=e.slice(void 0,[0,1]),u=e.slice(void 0,[a-1,a]);return o==null||u==null?new d(f.VALUE):n.isArray()?n.map(l=>this._handleSingleObject(l,o,u,i)):this._handleSingleObject(n,o,u,i)}_handleSingleObject(n,e,r,s){if(s===0){const o=r.pick(e.isEqual(n)).getFirstCell();return o.isNull()?new d(f.NA):o}const i=e.binarySearch(n);if(i==null)return new d(f.NA);const a=r.get(i,0);return a.isNull()?new d(f.NA):a}}const nn=[[ps,Oe.ADDRESS],[Es,Oe.INDIRECT],[_s,Oe.OFFSET],[Cs,Oe.VLOOKUP]];class ws extends M{calculate(n){return n.isError()?new d(f.VALUE):(n.isReferenceObject()&&(n=n.toArrayValueObject()),n.abs())}}class ys extends M{calculate(n){return n.isError()?new d(f.VALUE):(n.isReferenceObject()&&(n=n.toArrayValueObject()),n.acos())}}class bs extends M{calculate(n){return n.isError()?new d(f.VALUE):(n.isReferenceObject()&&(n=n.toArrayValueObject()),n.acosh())}}class Ls extends M{calculate(n){return n.isError()?new d(f.VALUE):(n.isReferenceObject()&&(n=n.toArrayValueObject()),n.isArray()?n.map(e=>e.isError()?e:sn(e)):sn(n))}}function sn(t){let n=t.getValue();if(t.isBoolean()&&(n=n?1:0),!Number.isFinite(n))return new d(f.VALUE);const e=Math.atan(1/Number(n));return Number.isNaN(e)?new d(f.VALUE):new w(e)}var J=(t=>(t.ABS="ABS",t.ACOS="ACOS",t.ACOSH="ACOSH",t.ACOT="ACOT",t.ACOTH="ACOTH",t.AGGREGATE="AGGREGATE",t.ARABIC="ARABIC",t.ASIN="ASIN",t.ASINH="ASINH",t.ATAN="ATAN",t.ATAN2="ATAN2",t.ATANH="ATANH",t.BASE="BASE",t.CEILING="CEILING",t.CEILING_MATH="CEILING.MATH",t.CEILING_PRECISE="CEILING.PRECISE",t.COMBIN="COMBIN",t.COMBINA="COMBINA",t.COS="COS",t.COSH="COSH",t.COT="COT",t.COTH="COTH",t.CSC="CSC",t.CSCH="CSCH",t.DECIMAL="DECIMAL",t.DEGREES="DEGREES",t.EVEN="EVEN",t.EXP="EXP",t.FACT="FACT",t.FACTDOUBLE="FACTDOUBLE",t.FLOOR="FLOOR",t.FLOOR_MATH="FLOOR.MATH",t.FLOOR_PRECISE="FLOOR.PRECISE",t.GCD="GCD",t.INT="INT",t.ISO_CEILING="ISO.CEILING",t.LCM="LCM",t.LET="LET",t.LN="LN",t.LOG="LOG",t.LOG10="LOG10",t.MDETERM="MDETERM",t.MINVERSE="MINVERSE",t.MMULT="MMULT",t.MOD="MOD",t.MROUND="MROUND",t.MULTINOMIAL="MULTINOMIAL",t.MUNIT="MUNIT",t.ODD="ODD",t.PI="PI",t.POWER="POWER",t.PRODUCT="PRODUCT",t.QUOTIENT="QUOTIENT",t.RADIANS="RADIANS",t.RAND="RAND",t.RANDARRAY="RANDARRAY",t.RANDBETWEEN="RANDBETWEEN",t.ROMAN="ROMAN",t.ROUND="ROUND",t.ROUNDDOWN="ROUNDDOWN",t.ROUNDUP="ROUNDUP",t.SEC="SEC",t.SECH="SECH",t.SERIESSUM="SERIESSUM",t.SEQUENCE="SEQUENCE",t.SIGN="SIGN",t.SIN="SIN",t.SINH="SINH",t.SQRT="SQRT",t.SQRTPI="SQRTPI",t.SUBTOTAL="SUBTOTAL",t.SUM="SUM",t.SUMIF="SUMIF",t.SUMIFS="SUMIFS",t.SUMPRODUCT="SUMPRODUCT",t.SUMSQ="SUMSQ",t.SUMX2MY2="SUMX2MY2",t.SUMX2PY2="SUMX2PY2",t.SUMXMY2="SUMXMY2",t.TAN="TAN",t.TANH="TANH",t.TRUNC="TRUNC",t))(J||{});class Ss extends M{calculate(n,e){return new d(f.VALUE)}}class Ps extends M{calculate(...n){let e=new w(0);for(let r=0;r<n.length;r++){let s=n[r];if(s.isError())return s;if(s.isString())return new d(f.VALUE);if(e.isError())return e;s.isArray()&&(s=s.sum()),e=e.plus(s)}return e}}function Vs(t){const n=[y.EQUALS,y.NOT_EQUAL,y.GREATER_THAN_OR_EQUAL,y.GREATER_THAN,y.LESS_THAN_OR_EQUAL,y.LESS_THAN];for(const e of n)if(t.startsWith(e)){const r=t.substring(e.length);return[e,de.create(r)]}return[y.EQUALS,de.create(t)]}function vs(t,n,e){if(!e)if(n.isString()){const r=`${n.getValue()}`,[s,i]=Vs(r);e=s,n=i}else e=y.EQUALS;return t.compare(n,e)}class As extends M{calculate(n,e,r){return n.isError()||e.isError()||r!=null&&r.isError()?new d(f.NA):!n.isArray()||r&&!r.isArray()?new d(f.VALUE):e.isArray()?e.map(s=>this._handleSingleObject(n,s,r)):this._handleSingleObject(n,e,r)}_handleSingleObject(n,e,r){const s=vs(n,e),i=r?r.slice([0,n.getRowCount()],[0,n.getColumnCount()]):n;return i?i.pick(s).sum():new d(f.VALUE)}}class xs extends M{calculate(...n){return new d(f.VALUE)}}const an=[[ws,J.ABS],[ys,J.ACOS],[bs,J.ACOSH],[Ls,J.ACOT],[Ps,J.SUM],[As,J.SUMIF],[xs,J.SUMIFS],[Ss,J.POWER]];class Os extends M{constructor(){super(...arguments);p(this,"_compareType",y.EQUALS)}setCompareType(e){this._compareType=e}calculate(e,r){return e.isError()||r.isError()?e:e.compare(r,this._compareType)}}class Bs extends M{calculate(n,e){return n.isError()||e.isError()?n:!e.isArray()&&e.getValue()===0?new d(f.DIV_BY_ZERO):n.divided(e)}}var G=(t=>(t.COMPARE="COMPARE",t.DIVIDED="DIVIDED",t.MINUS="MINUS",t.MULTIPLY="MULTIPLY",t.PLUS="PLUS",t.UNION="UNION",t))(G||{});class Us extends M{calculate(n,e){return n.isError()||e.isError()?n:n.minus(e)}}class Fs extends M{calculate(n,e){return n.isError()?n:e.isError()?e:n.multiply(e)}}class Ms extends M{calculate(n,e){return n.isError()?n:e.isError()?e:n.plus(e)}}const on=[[Os,G.COMPARE],[Bs,G.DIVIDED],[Us,G.MINUS],[Fs,G.MULTIPLY],[Ms,G.PLUS]];class $s extends M{calculate(...n){let e=new w(0),r=new w(0);for(let s=0;s<n.length;s++){const i=n[s];if(i.isError())return i;if(e.isError())return e;i.isArray()?(e=e.plus(i.sum()),r=r.plus(i.count())):i.isNull()||(r=r.plus(new w(1)))}return e.divided(r)}}class ks extends M{calculate(...n){let e=new w(0);for(let r=0;r<n.length;r++){let s=n[r];s.isError()||(s.isArray()?(s=s.count(),e=e.plus(s)):!s.isNull()&&!s.isString()&&(e=e.plus(new w(1))))}return e}}class js extends M{calculate(...n){let e=new w(0);for(let r=0;r<n.length;r++){let s=n[r];if(s.isError()){e=e.plus(new w(1));continue}s.isArray()?(s=s.countA(),e=e.plus(s)):s.isNull()||(e=e.plus(new w(1)))}return e}}var me=(t=>(t.AVEDEV="AVEDEV",t.AVERAGE="AVERAGE",t.AVERAGEA="AVERAGEA",t.AVERAGEIF="AVERAGEIF",t.AVERAGEIFS="AVERAGEIFS",t.BETA_DIST="BETA.DIST",t.BETA_INV="BETA.INV",t.BINOM_DIST="BINOM.DIST",t.BINOM_DIST_RANGE="BINOM.DIST.RANGE",t.BINOM_INV="BINOM.INV",t.CHISQ_DIST="CHISQ.DIST",t.CHISQ_DIST_RT="CHISQ.DIST.RT",t.CHISQ_INV="CHISQ.INV",t.CHISQ_INV_RT="CHISQ.INV.RT",t.CHISQ_TEST="CHISQ.TEST",t.CONFIDENCE_NORM="CONFIDENCE.NORM",t.CONFIDENCE_T="CONFIDENCE.T",t.CORREL="CORREL",t.COUNT="COUNT",t.COUNTA="COUNTA",t.COUNTBLANK="COUNTBLANK",t.COUNTIF="COUNTIF",t.COUNTIFS="COUNTIFS",t.COVARIANCE_P="COVARIANCE.P",t.COVARIANCE_S="COVARIANCE.S",t.DEVSQ="DEVSQ",t.EXPON_DIST="EXPON.DIST",t.F_DIST="F.DIST",t.F_DIST_RT="F.DIST.RT",t.F_INV="F.INV",t.F_INV_RT="F.INV.RT",t.F_TEST="F.TEST",t.FISHER="FISHER",t.FISHERINV="FISHERINV",t.FORECAST="FORECAST",t.FORECAST_ETS="FORECAST.ETS",t.FORECAST_ETS_CONFINT="FORECAST.ETS.CONFINT",t.FORECAST_ETS_SEASONALITY="FORECAST.ETS.SEASONALITY",t.FORECAST_ETS_STAT="FORECAST.ETS.STAT",t.FORECAST_LINEAR="FORECAST.LINEAR",t.FREQUENCY="FREQUENCY",t.GAMMA="GAMMA",t.GAMMA_DIST="GAMMA.DIST",t.GAMMA_INV="GAMMA.INV",t.GAMMALN="GAMMALN",t.GAMMALN_PRECISE="GAMMALN.PRECISE",t.GAUSS="GAUSS",t.GEOMEAN="GEOMEAN",t.GROWTH="GROWTH",t.HARMEAN="HARMEAN",t.HYPGEOM_DIST="HYPGEOM.DIST",t.INTERCEPT="INTERCEPT",t.KURT="KURT",t.LARGE="LARGE",t.LINEST="LINEST",t.LOGEST="LOGEST",t.LOGNORM_DIST="LOGNORM.DIST",t.LOGNORM_INV="LOGNORM.INV",t.MAX="MAX",t.MAXA="MAXA",t.MAXIFS="MAXIFS",t.MEDIAN="MEDIAN",t.MIN="MIN",t.MINA="MINA",t.MINIFS="MINIFS",t.MODE_MULT="MODE.MULT",t.MODE_SNGL="MODE.SNGL",t.NEGBINOM_DIST="NEGBINOM.DIST",t.NORM_DIST="NORM.DIST",t.NORM_INV="NORM.INV",t.NORM_S_DIST="NORM.S.DIST",t.NORM_S_INV="NORM.S.INV",t.PEARSON="PEARSON",t.PERCENTILE_EXC="PERCENTILE.EXC",t.PERCENTILE_INC="PERCENTILE.INC",t.PERCENTRANK_EXC="PERCENTRANK.EXC",t.PERCENTRANK_INC="PERCENTRANK.INC",t.PERMUT="PERMUT",t.PERMUTATIONA="PERMUTATIONA",t.PHI="PHI",t.POISSON_DIST="POISSON.DIST",t.PROB="PROB",t.QUARTILE_EXC="QUARTILE.EXC",t.QUARTILE_INC="QUARTILE.INC",t.RANK_AVG="RANK.AVG",t.RANK_EQ="RANK.EQ",t.RSQ="RSQ",t.SKEW="SKEW",t.SKEW_P="SKEW.P",t.SLOPE="SLOPE",t.SMALL="SMALL",t.STANDARDIZE="STANDARDIZE",t.STDEV_P="STDEV.P",t.STDEV_S="STDEV.S",t.STDEVA="STDEVA",t.STDEVPA="STDEVPA",t.STEYX="STEYX",t.T_DIST="T.DIST",t.T_DIST_2T="T.DIST.2T",t.T_DIST_RT="T.DIST.RT",t.T_INV="T.INV",t.T_INV_2T="T.INV.2T",t.T_TEST="T.TEST",t.TREND="TREND",t.TRIMMEAN="TRIMMEAN",t.VAR_P="VAR.P",t.VAR_S="VAR.S",t.VARA="VARA",t.VARPA="VARPA",t.WEIBULL_DIST="WEIBULL.DIST",t.Z_TEST="Z.TEST",t))(me||{});class Qs extends M{calculate(...n){let e=new w(-1/0);for(let r=0;r<n.length;r++){let s=n[r];if(s.isError())return s;s.isArray()&&(s=s.max()),!s.isNull()&&(e=this._validator(e,s))}return e}_validator(n,e){return n.isLessThan(e).getValue()&&(n=e),n}}class un extends M{calculate(...n){let e=new w(1/0);for(let r=0;r<n.length;r++){let s=n[r];if(s.isError())return s;s.isArray()&&(s=s.min()),!s.isNull()&&(e=this._validator(e,s))}return e}_validator(n,e){return n.isGreaterThan(e).getValue()&&(n=e),n}}const ln=[[$s,me.AVERAGE],[ks,me.COUNT],[Qs,me.MAX],[un,me.MIN],[un,me.MIN],[js,me.COUNTA]];class Ts extends M{calculate(n,e){return new d(f.VALUE)}}var ot=(t=>(t.ASC="ASC",t.ARRAYTOTEXT="ARRAYTOTEXT",t.BAHTTEXT="BAHTTEXT",t.CHAR="CHAR",t.CLEAN="CLEAN",t.CODE="CODE",t.CONCAT="CONCAT",t.CONCATENATE="CONCATENATE",t.DBCS="DBCS",t.DOLLAR="DOLLAR",t.EXACT="EXACT",t.FIND="FIND",t.FINDB="FINDB",t.FIXED="FIXED",t.LEFT="LEFT",t.LEFTB="LEFTB",t.LEN="LEN",t.LENB="LENB",t.LOWER="LOWER",t.MID="MID",t.MIDB="MIDB",t.NUMBERVALUE="NUMBERVALUE",t.PHONETIC="PHONETIC",t.PROPER="PROPER",t.REPLACE="REPLACE",t.REPLACEB="REPLACEB",t.REPT="REPT",t.RIGHT="RIGHT",t.RIGHTB="RIGHTB",t.SEARCH="SEARCH",t.SEARCHB="SEARCHB",t.SUBSTITUTE="SUBSTITUTE",t.T="T",t.TEXT="TEXT",t.TEXTAFTER="TEXTAFTER",t.TEXTBEFORE="TEXTBEFORE",t.TEXTJOIN="TEXTJOIN",t.TEXTSPLIT="TEXTSPLIT",t.TRIM="TRIM",t.UNICHAR="UNICHAR",t.UNICODE="UNICODE",t.UPPER="UPPER",t.VALUE="VALUE",t.VALUETOTEXT="VALUETOTEXT",t.CALL="CALL",t.EUROCONVERT="EUROCONVERT",t.REGISTER_ID="REGISTER.ID",t))(ot||{});const cn=[[Ts,ot.CONCATENATE]],hn=[];var Hs=(t=>{})();const fn=[];var dn=(t=>(t.ENCODEURL="ENCODEURL",t.FILTERXML="FILTERXML",t.WEBSERVICE="WEBSERVICE",t))(dn||{});class Ys extends g.Disposable{constructor(){super(...arguments);p(this,"_definedNameMap",new Map)}dispose(){this._definedNameMap.clear()}registerDefinedName(e,r,s){var a;this._definedNameMap.get(e)==null&&this._definedNameMap.set(e,new Map),(a=this._definedNameMap.get(e))==null||a.set(r,s)}removeDefinedName(e,r){var s;(s=this._definedNameMap.get(e))==null||s.delete(r)}getDefinedNameMap(e){return this._definedNameMap.get(e)}getValue(e,r){var s;return(s=this._definedNameMap.get(e))==null?void 0:s.get(r)}hasDefinedName(e){var s;return(((s=this._definedNameMap.get(e))==null?void 0:s.size)||0)!==0}}const ut=V.createIdentifier("univer.formula.defined-names.service");var Ws=Object.defineProperty,Xs=Object.getOwnPropertyDescriptor,Gs=(t,n,e,r)=>{for(var s=r>1?void 0:r?Xs(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Ws(n,e,s),s},Ks=(t,n)=>(e,r)=>n(e,r,t);let zt=class extends g.Disposable{constructor(n){super();p(this,"_unitData",{});p(this,"_arrayFormulaCellData",{});p(this,"_formulaData",{});p(this,"_sheetNameMap",{});p(this,"_forceCalculate",!1);p(this,"_dirtyRanges",[]);p(this,"_dirtyNameMap",{});p(this,"_dirtyUnitFeatureMap",{});p(this,"_excludedCell");this._currentUniverService=n}dispose(){this._unitData={},this._formulaData={},this._arrayFormulaCellData={},this._sheetNameMap={},this._dirtyRanges=[],this._dirtyNameMap={},this._dirtyUnitFeatureMap={},this._excludedCell={}}getExcludedRange(){return this._excludedCell}getUnitData(){return this._unitData}getFormulaData(){return this._formulaData}getArrayFormulaCellData(){return this._arrayFormulaCellData}getSheetNameMap(){return this._sheetNameMap}isForceCalculate(){return this._forceCalculate}getDirtyRanges(){return this._dirtyRanges}getDirtyNameMap(){return this._dirtyNameMap}getDirtyUnitFeatureMap(){return this._dirtyUnitFeatureMap}load(n){if(n.allUnitData&&n.unitSheetNameMap)this._unitData=n.allUnitData,this._sheetNameMap=n.unitSheetNameMap;else{const{allUnitData:e,unitSheetNameMap:r}=this._loadSheetData();this._unitData=e,this._sheetNameMap=r}this._formulaData=n.formulaData,this._arrayFormulaCellData=lr(n.arrayFormulaCellData),this._forceCalculate=n.forceCalculate,this._dirtyRanges=n.dirtyRanges,this._dirtyNameMap=n.dirtyNameMap,this._dirtyUnitFeatureMap=n.dirtyUnitFeatureMap,this._excludedCell=n.excludedCell}loadDirtyRangesAndExcludedCell(n,e){this._dirtyRanges=n,this._excludedCell=e,this._dirtyNameMap={}}registerUnitData(n){this._unitData=n}registerFormulaData(n){this._formulaData=n}registerSheetNameMap(n){this._sheetNameMap=n}_loadSheetData(){const n=this._currentUniverService.getAllUniverSheetsInstance(),e={},r={};for(const s of n){const i=s.getUnitId(),a=s.getSheets(),o={},u={};for(const l of a){const c=l.getSheetId(),h=l.getConfig();o[c]={cellData:new g.ObjectMatrix(h.cellData),rowCount:h.rowCount,columnCount:h.columnCount},u[l.getName()]=l.getSheetId()}e[i]=o,r[i]=u}return{allUnitData:e,unitSheetNameMap:r}}};zt=Gs([Ks(0,g.IUniverInstanceService)],zt);const ye=V.createIdentifier("univer.formula.current-data.service");var Is=Object.defineProperty,zs=Object.getOwnPropertyDescriptor,qs=(t,n,e,r)=>{for(var s=r>1?void 0:r?zs(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Is(n,e,s),s},Zs=(t,n)=>(e,r)=>n(e,r,t),re=(t=>(t[t.IDLE=0]="IDLE",t[t.START_DEPENDENCY=1]="START_DEPENDENCY",t[t.START_CALCULATION=2]="START_CALCULATION",t[t.CURRENTLY_CALCULATING=3]="CURRENTLY_CALCULATING",t[t.START_DEPENDENCY_ARRAY_FORMULA=4]="START_DEPENDENCY_ARRAY_FORMULA",t[t.START_CALCULATION_ARRAY_FORMULA=5]="START_CALCULATION_ARRAY_FORMULA",t[t.CURRENTLY_CALCULATING_ARRAY_FORMULA=6]="CURRENTLY_CALCULATING_ARRAY_FORMULA",t[t.CALCULATION_COMPLETED=7]="CALCULATION_COMPLETED",t))(re||{}),Be=(t=>(t[t.INITIAL=0]="INITIAL",t[t.STOP_EXECUTION=1]="STOP_EXECUTION",t[t.NOT_EXECUTED=2]="NOT_EXECUTED",t[t.SUCCESS=3]="SUCCESS",t))(Be||{});let qt=class extends g.Disposable{constructor(n){super();p(this,"_formulaExecuteStage",0);p(this,"_stopState",!1);p(this,"_currentRow",-1);p(this,"_currentColumn",-1);p(this,"_currentRowCount",-1/0);p(this,"_currentColumnCount",-1/0);p(this,"_currentSubUnitId","");p(this,"_currentUnitId","");p(this,"_runtimeData",{});p(this,"_runtimeOtherData",{});p(this,"_unitArrayFormulaRange",{});p(this,"_runtimeArrayFormulaCellData",{});p(this,"_runtimeClearArrayFormulaCellData",{});p(this,"_runtimeFeatureRange",{});p(this,"_runtimeFeatureCellData",{});p(this,"_functionsExecutedState",0);p(this,"_functionDefinitionPrivacyVar",new Map);p(this,"_totalFormulasToCalculate",0);p(this,"_completedFormulasCount",0);p(this,"_totalArrayFormulasToCalculate",0);p(this,"_completedArrayFormulasCount",0);p(this,"_isCycleDependency",!1);this._currentConfigService=n}get currentRow(){return this._currentRow}get currentColumn(){return this._currentColumn}get currentRowCount(){return this._currentRowCount}get currentColumnCount(){return this._currentColumnCount}get currentSubUnitId(){return this._currentSubUnitId}get currentUnitId(){return this._currentUnitId}dispose(){this.reset(),this._runtimeFeatureCellData={},this._runtimeFeatureRange={}}enableCycleDependency(){this._isCycleDependency=!0}disableCycleDependency(){this._isCycleDependency=!1}isCycleDependency(){return this._isCycleDependency}setTotalArrayFormulasToCalculate(n){this._totalArrayFormulasToCalculate=n}getTotalArrayFormulasToCalculate(){return this._totalArrayFormulasToCalculate}setCompletedArrayFormulasCount(n){this._completedArrayFormulasCount=n}getCompletedArrayFormulasCount(){return this._completedArrayFormulasCount}setTotalFormulasToCalculate(n){this._totalFormulasToCalculate=n}getTotalFormulasToCalculate(){return this._totalFormulasToCalculate}setCompletedFormulasCount(n){this._completedFormulasCount=n}getCompletedFormulasCount(){return this._completedFormulasCount}markedAsSuccessfullyExecuted(){this._functionsExecutedState=3}markedAsNoFunctionsExecuted(){this._functionsExecutedState=2}markedAsStopFunctionsExecuted(){this._functionsExecutedState=1}markedAsInitialFunctionsExecuted(){this._functionsExecutedState=0}stopExecution(){this._stopState=!0,this.setFormulaExecuteStage(0)}isStopExecution(){return this._stopState}setFormulaExecuteStage(n){this._formulaExecuteStage=n}getFormulaExecuteStage(){return this._formulaExecuteStage}reset(){this._formulaExecuteStage=0,this._runtimeData={},this._runtimeOtherData={},this._unitArrayFormulaRange={},this._runtimeArrayFormulaCellData={},this._runtimeClearArrayFormulaCellData={},this._functionDefinitionPrivacyVar.clear(),this.markedAsInitialFunctionsExecuted(),this._isCycleDependency=!1,this._totalFormulasToCalculate=0,this._completedFormulasCount=0}setCurrent(n,e,r,s,i,a){this._currentRow=n,this._currentColumn=e,this._currentRowCount=r,this._currentColumnCount=s,this._currentSubUnitId=i,this._currentUnitId=a}clearFunctionDefinitionPrivacyVar(){this._functionDefinitionPrivacyVar.clear()}registerFunctionDefinitionPrivacyVar(n,e){this._functionDefinitionPrivacyVar.set(n,e)}getFunctionDefinitionPrivacyVar(n){return this._functionDefinitionPrivacyVar.get(n)}setRuntimeOtherData(n,e){const r=this._currentSubUnitId,s=this._currentUnitId;this._runtimeOtherData[s]===void 0&&(this._runtimeOtherData[s]={});const i=this._runtimeOtherData[s];i[r]===void 0&&(i[r]={});const a=i[r];a[n]=this._objectValueToCellValue(e)}setRuntimeData(n){const e=this._currentRow,r=this._currentColumn,s=this._currentRowCount,i=this.currentColumnCount,a=this._currentSubUnitId,o=this._currentUnitId;this._runtimeData[o]==null&&(this._runtimeData[o]={});const u=this._runtimeData[o];u[a]==null&&(u[a]=new g.ObjectMatrix),this._unitArrayFormulaRange[o]==null&&(this._unitArrayFormulaRange[o]={});const l=this._unitArrayFormulaRange[o];let c=new g.ObjectMatrix;l[a]&&(c=new g.ObjectMatrix(l[a])),this._runtimeArrayFormulaCellData[o]===void 0&&(this._runtimeArrayFormulaCellData[o]={});const h=this._runtimeArrayFormulaCellData[o];h[a]==null&&(h[a]=new g.ObjectMatrix),this._runtimeClearArrayFormulaCellData[o]===void 0&&(this._runtimeClearArrayFormulaCellData[o]={});const m=this._runtimeClearArrayFormulaCellData[o];m[a]==null&&(m[a]=new g.ObjectMatrix);const E=u[a],C=h[a],R=m[a];if(n.isReferenceObject()||n.isValueObject()&&n.isArray()){const _=n,{startRow:b,startColumn:L,endRow:S,endColumn:P}=_.getRangePosition();if(b===S&&L===P){const j=this._objectValueToCellValue(_.getFirstCell());E.setValue(e,r,j),R.setValue(e,r,j);return}const k={startRow:e,startColumn:r,endRow:S-b+e,endColumn:P-L+r};if(c.setValue(e,r,k),l[a]=c.getData(),this._checkIfArrayFormulaRangeHasData(o,a,e,r,k)||this._checkIfArrayFormulaExceeded(s,i,k)){const j=this._objectValueToCellValue(new d(f.SPILL));E.setValue(e,r,j),R.setValue(e,r,j)}else{const j=new d(f.SPILL);_.iterator((H,B,v)=>{const F=this._objectValueToCellValue(H);if(B===b&&v===L){if(H!=null&&H.isError()&&H.isEqualType(j))return R.setValue(e,r,{}),E.setValue(e,r,{...this._objectValueToCellValue(j)}),!1;E.setValue(e,r,{...F})}C.setValue(B-b+e,v-L+r,F)})}}else{const _=this._objectValueToCellValue(n);E.setValue(e,r,_),R.setValue(e,r,_)}}getUnitData(){return this._runtimeData}getUnitArrayFormula(){return this._unitArrayFormulaRange}getRuntimeOtherData(){return this._runtimeOtherData}getRuntimeArrayFormulaCellData(){return this._runtimeArrayFormulaCellData}getRuntimeClearArrayFormulaCellData(){return this._runtimeClearArrayFormulaCellData}getRuntimeFeatureRange(){return this._runtimeFeatureRange}setRuntimeFeatureRange(n,e){this._runtimeFeatureRange[n]=e}getRuntimeFeatureCellData(){return this._runtimeFeatureCellData}setRuntimeFeatureCellData(n,e){this._runtimeFeatureCellData[n]=e}getAllRuntimeData(){return{unitData:this.getUnitData(),arrayFormulaRange:this.getUnitArrayFormula(),unitOtherData:this.getRuntimeOtherData(),functionsExecutedState:this._functionsExecutedState,arrayFormulaCellData:this.getRuntimeArrayFormulaCellData(),clearArrayFormulaCellData:this.getRuntimeClearArrayFormulaCellData(),runtimeFeatureRange:this.getRuntimeFeatureRange(),runtimeFeatureCellData:this.getRuntimeFeatureCellData()}}getRuntimeState(){return{totalFormulasToCalculate:this.getTotalFormulasToCalculate(),completedFormulasCount:this.getCompletedFormulasCount(),totalArrayFormulasToCalculate:this.getTotalArrayFormulasToCalculate(),completedArrayFormulasCount:this.getCompletedArrayFormulasCount(),stage:this.getFormulaExecuteStage()}}_objectValueToCellValue(n){if(n==null)return{v:0,t:g.CellValueType.NUMBER};if(n.isError())return{v:n.getErrorType(),t:g.CellValueType.STRING};if(n.isValueObject()){const e=n,r=e.getValue();return e.isNumber()?{v:r,t:g.CellValueType.NUMBER}:e.isBoolean()?{v:r,t:g.CellValueType.BOOLEAN}:{v:r,t:g.CellValueType.STRING}}}_checkIfArrayFormulaRangeHasData(n,e,r,s,i){var m,E,C,R,_,b,L,S,P,k,j,H;const{startRow:a,startColumn:o,endRow:u,endColumn:l}=i,c=this._currentConfigService.getUnitData(),h=(C=(E=(m=this._unitArrayFormulaRange[n])==null?void 0:m[e])==null?void 0:E[r])==null?void 0:C[s];for(let B=a;B<=u;B++)for(let v=o;v<=l;v++){if(B===r&&s===v)continue;const F=(b=(_=(R=this._runtimeData)==null?void 0:R[n])==null?void 0:_[e])==null?void 0:b.getValue(B,v),$=(P=(S=(L=this._runtimeArrayFormulaCellData)==null?void 0:L[n])==null?void 0:S[e])==null?void 0:P.getValue(B,v),ba=(H=(j=(k=c==null?void 0:c[n])==null?void 0:k[e])==null?void 0:j.cellData)==null?void 0:H.getValue(B,v);if(!g.isNullCell(F)||!g.isNullCell($)&&!this._isInArrayFormulaRange(h,B,v)||!g.isNullCell(ba))return!0}return!1}_isInArrayFormulaRange(n,e,r){if(n==null)return!1;const{startRow:s,startColumn:i,endRow:a,endColumn:o}=n;return e>=s&&e<=a&&r>=i&&r<=o}_checkIfArrayFormulaExceeded(n,e,r){return r.endRow>=n||r.endColumn>=e}_isInDirtyRange(n,e,r,s){const i=this._currentConfigService.getDirtyRanges();return i.length===0?!0:ir(i,n,e,r,s)}};qt=qs([Zs(0,ye)],qt);const N=V.createIdentifier("univer.formula.runtime.service");var Js=Object.defineProperty,Ns=Object.getOwnPropertyDescriptor,ei=(t,n,e,r)=>{for(var s=r>1?void 0:r?Ns(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Js(n,e,s),s},Zt=(t,n)=>(e,r)=>n(e,r,t);let be=class extends g.Disposable{constructor(t,n,e){super(),this._definedNamesService=t,this._runtimeService=n,this._lexerTreeBuilder=e}treeBuilder(t,n=!0){return this._lexerTreeBuilder.treeBuilder(t,n,this._injectDefinedName.bind(this))}_injectDefinedName(t){var i;const n=this._runtimeService.currentUnitId;if(!this._definedNamesService.hasDefinedName(n))return{sequenceString:"",hasDefinedName:!1};const e=this._lexerTreeBuilder.getSequenceNode(t);let r="",s=!1;for(let a=0,o=e.length;a<o;a++){const u=e[a];if(typeof u=="string"){r+=u;continue}const{nodeType:l,token:c}=u;if(l===z.REFERENCE||l===z.FUNCTION){const h=(i=this._definedNamesService.getDefinedNameMap(n))==null?void 0:i.get(c);h?(r+=h,s=!0):r+=c}else r+=c}return{sequenceString:r,hasDefinedName:s}}};be=ei([Zt(0,ut),Zt(1,N),Zt(2,V.Inject(qe))],be);var x=(t=>(t.REFERENCE="ReferenceNode",t.VALUE="ValueNode",t.OPERATOR="OperatorNode",t.FUNCTION="FunctionNode",t.LAMBDA="LambdaNode",t.LAMBDA_PARAMETER="LambdaNodeParameter",t.ERROR="ErrorNode",t.BASE="Base",t.ROOT="Root",t.UNION="UnionNode",t.PREFIX="PrefixNode",t.SUFFIX="SuffixNode",t.NULL="NullNode",t))(x||{});const ne=new Map([["ReferenceNode",7],["ValueNode",9],["OperatorNode",8],["FunctionNode",6],["LambdaNode",1],["LambdaNodeParameter",2],["Root",10],["UnionNode",3],["PrefixNode",4],["SuffixNode",5]]);class I extends g.Disposable{constructor(e){super();p(this,"_children",[]);p(this,"_parent");p(this,"_valueObject");p(this,"_calculateState",!1);p(this,"_async",!1);p(this,"_address",!1);p(this,"_refOffsetX",0);p(this,"_refOffsetY",0);this._token=e}dispose(){var e;this._children.forEach(r=>{r.dispose()}),(e=this._valueObject)==null||e.dispose(),this._parent=null}get nodeType(){return x.BASE}isAsync(){return this._async}isAddress(){return this._address}setAsync(){this._async=!0}setAddress(){this._address=!0}getParent(){return this._parent}setParent(e){this._parent=e,e.addChildren(this)}getChildren(){return this._children}addChildren(...e){this._children.push(...e)}getToken(){return this._token}setValue(e){this._valueObject=e}getValue(){return this._valueObject}isCalculated(){return this._calculateState}setCalculated(){this._calculateState=!0}execute(){}setNotEmpty(e=!0){}setRefOffset(e=0,r=0){this._refOffsetX=e,this._refOffsetY=r}getRefOffset(){return{x:this._refOffsetX,y:this._refOffsetY}}async executeAsync(){return Promise.resolve(De.SUCCESS)}serialize(){const e=this.getToken(),r=this.getChildren(),s=[],i=r.length;for(let o=0;o<i;o++){const u=r[o];s.push(u.serialize())}const a={token:e,nodeType:this.nodeType};return i>0&&(a.children=s),a}}class T extends I{constructor(e){super(e);p(this,"_errorValueObject");this._errorValueObject=new d(e)}get nodeType(){return x.ERROR}static create(e){return new T(e)}getValue(){return this._errorValueObject}}const se=100;class ie extends g.Disposable{get zIndex(){return 0}create(n,e,r){let s;return n instanceof A?s=n.getToken():s=n,new I(s)}checkAndCreateNodeType(n){}}class Jt extends I{get nodeType(){return x.ROOT}execute(){const e=this.getChildren()[0];this.setValue(e.getValue())}}class mn extends ie{get zIndex(){return ne.get(x.ROOT)||se}checkAndCreateNodeType(n){if(!(n instanceof A))return;if(n.getToken()===ce)return new Jt(ce)}}class gn extends g.Disposable{constructor(){super(...arguments);p(this,"_functionExecutors",new Map);p(this,"_functionDescriptions",new Map)}dispose(){this._functionExecutors.clear(),this._functionDescriptions.clear()}registerExecutors(...e){for(let r=0;r<e.length;r++){const s=e[r];this._functionExecutors.set(s.name,s)}}getExecutors(){return this._functionExecutors}getExecutor(e){return this._functionExecutors.get(e)}hasExecutor(e){return this._functionExecutors.has(e)}unregisterExecutors(...e){for(let r=0;r<e.length;r++){const s=e[r];this._functionExecutors.delete(s)}}registerDescriptions(...e){for(let r=0;r<e.length;r++){const s=e[r];this._functionDescriptions.set(s.functionName,s)}}getDescriptions(){return this._functionDescriptions}getDescription(e){return this._functionDescriptions.get(e)}hasDescription(e){return this._functionDescriptions.has(e)}unregisterDescriptions(...e){for(let r=0;r<e.length;r++){const s=e[r];this._functionDescriptions.delete(s)}}}const ue=V.createIdentifier("univer.formula.function.service");var ti=Object.defineProperty,ri=Object.getOwnPropertyDescriptor,ni=(t,n,e,r)=>{for(var s=r>1?void 0:r?ri(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&ti(n,e,s),s},Rn=(t,n)=>(e,r)=>n(e,r,t);class lt extends I{constructor(n,e,r){super(e),this._accessor=n,this._operatorString=e,this._functionExecutor=r}get nodeType(){return x.PREFIX}execute(){let e=this.getChildren()[0].getValue(),r;if(e==null)throw new Error("object is null");e.isReferenceObject()&&(e=e.toArrayValueObject()),this._operatorString===Q.MINUS?r=this._functionExecutor.calculate(new w(0),e):this._operatorString===Q.AT?r=this._handlerAT(e):r=new d(f.VALUE),this.setValue(r)}_handlerAT(n){if(!n.isReferenceObject())return new d(f.VALUE);const e=n;if(e.isCell())return new d(f.VALUE);const r=this._accessor.get(N),s=r.currentRow||0,i=r.currentColumn||0;return e.isRow()?e.getCellByColumn(i):e.isColumn()?e.getCellByRow(s):e.isRange()||e.isTable()?e.getCellByPosition():new d(f.VALUE)}}let ct=class extends ie{constructor(t,n){super(),this._functionService=t,this._injector=n}get zIndex(){return ne.get(x.PREFIX)||se}checkAndCreateNodeType(t){if(!(t instanceof A))return;const n=t.getToken(),e=n.trim();if(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;let r="";if(e===Q.MINUS)r=G.MINUS;else return e===Q.AT?new lt(this._injector,e):void 0;const s=this._functionService.getExecutor(r);return s?new lt(this._injector,e,s):(console.error(`No function ${n}`),T.create(f.NAME))}};ct=ni([Rn(0,ue),Rn(1,V.Inject(V.Injector))],ct);var si=Object.defineProperty,ii=Object.getOwnPropertyDescriptor,ai=(t,n,e,r)=>{for(var s=r>1?void 0:r?ii(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&si(n,e,s),s},ht=(t,n)=>(e,r)=>n(e,r,t);class oi extends I{constructor(n,e,r,s){super(n),this._functionExecutor=e,this._currentConfigService=r,this._runtimeService=s,this._functionExecutor.isAsync()&&this.setAsync(),this._functionExecutor.isAddress()&&this.setAddress()}get nodeType(){return x.FUNCTION}async executeAsync(){const n=[],e=this.getChildren(),r=e.length;for(let a=0;a<r;a++){const o=e[a].getValue();o!=null&&(o.isReferenceObject()?n.push(o.toArrayValueObject()):n.push(o))}const s=this._calculate(n);let i;return s.isAsyncObject()||s.isAsyncArrayObject()?i=await s.getValue():i=s,this._setRefData(i),this.setValue(i),Promise.resolve(De.SUCCESS)}execute(){const n=[],e=this.getChildren(),r=e.length;for(let i=0;i<r;i++){const a=e[i].getValue();a!=null&&(a.isReferenceObject()?n.push(a.toArrayValueObject()):n.push(a))}const s=this._calculate(n);this._setRefData(s),this.setValue(s)}_calculate(n){var r;let e;if(this._setRefInfo(),this._functionExecutor.isCustom()){const s=this._functionExecutor.calculateCustom(...n.map(i=>i.isArray()?i.toValue():i.getValue()));if(typeof s!="object"||s==null)e=de.create(s);else{const i=us(s);e=new Z({calculateValueList:i,rowCount:i.length,columnCount:((r=i[0])==null?void 0:r.length)||0,unitId:"",sheetId:"",row:-1,column:-1})}}else e=this._functionExecutor.calculate(...n);return e}_setRefInfo(){const{currentUnitId:n,currentSubUnitId:e,currentRow:r,currentColumn:s}=this._runtimeService;this._functionExecutor.setRefInfo(n,e,r,s)}_setRefData(n){if(!n.isReferenceObject())return;const e=n;e.setForcedSheetId(this._currentConfigService.getSheetNameMap()),e.setUnitData(this._currentConfigService.getUnitData()),e.setArrayFormulaCellData(this._currentConfigService.getArrayFormulaCellData()),e.setRuntimeData(this._runtimeService.getUnitData()),e.setRuntimeArrayFormulaCellData(this._runtimeService.getRuntimeArrayFormulaCellData()),e.setRuntimeFeatureCellData(this._runtimeService.getRuntimeFeatureCellData())}}let ft=class extends ie{constructor(t,n,e,r){super(),this._functionService=t,this._currentConfigService=n,this._runtimeService=e,this._injector=r}get zIndex(){return ne.get(x.FUNCTION)||se}create(t){const n=this._functionService.getExecutor(t);return n?new oi(t,n,this._currentConfigService,this._runtimeService):(console.error(`No function ${t}`),T.create(f.NAME))}checkAndCreateNodeType(t){if(typeof t=="string")return;let e=t.getToken().trim().toUpperCase(),r,s;const i=e.slice(0,2);let a=0;if(new RegExp(Q.MINUS,"g").test(i)){const o=this._functionService.getExecutor(G.MINUS);r=new lt(this._injector,Q.MINUS,o),a++}if(new RegExp(Q.AT,"g").test(i)&&(s=new lt(this._injector,Q.AT),r&&s.setParent(r),a++),a>0&&(e=e.slice(a)),this._functionService.hasExecutor(e)){const o=this.create(e);return s?o.setParent(s):r&&o.setParent(r),o}}};ft=ai([ht(0,ue),ht(1,ye),ht(2,N),ht(3,V.Inject(V.Injector))],ft);var ui=Object.defineProperty,li=Object.getOwnPropertyDescriptor,ci=(t,n,e,r)=>{for(var s=r>1?void 0:r?li(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&ui(n,e,s),s},hi=(t,n)=>(e,r)=>n(e,r,t);let Ue=class extends g.Disposable{constructor(t){super(),this._runtimeService=t}dispose(){}async executeAsync(t){if(!t)return new d(f.VALUE);await this._executeAsync(t);const n=t.getValue();if(n==null)throw new Error("node value is null");return Promise.resolve(n)}execute(t){if(!t)return new d(f.VALUE);this._execute(t);const n=t.getValue();if(n==null)throw new Error("node value is null");return n}executePreCalculateNode(t){return t.execute(),t.getValue()}checkAsyncNode(t){const n=[];this._checkAsyncNode(t,n);for(let e=0,r=n.length;e<r;e++)if(n[e]===!0)return!0;return!1}_checkAsyncNode(t,n){const e=t.getChildren(),r=e.length;for(let s=0;s<r;s++){const i=e[s];n.push(i.isAsync()),this._checkAsyncNode(i,n)}}async _executeAsync(t){if(this._runtimeService.isStopExecution())return Promise.resolve(De.ERROR);const n=t.getChildren(),e=n.length;for(let r=0;r<e;r++){const s=n[r];if(s.getToken().toUpperCase()===ke&&s.isEmptyParamFunction()){s.execute();continue}await this._executeAsync(s)}return t.nodeType===x.FUNCTION&&t.isAsync()?await t.executeAsync():t.execute(),Promise.resolve(De.SUCCESS)}_execute(t){if(this._runtimeService.isStopExecution())return De.ERROR;const n=t.getChildren(),e=n.length;for(let r=0;r<e;r++){const s=n[r];if(s.getToken().toUpperCase()===ke&&s.isEmptyParamFunction()){s.execute();continue}this._execute(s)}return t.execute(),De.SUCCESS}};Ue=ci([hi(0,N)],Ue);function pn(t){return t instanceof A?t.getToken()===ve:!1}function fi(t){return t instanceof A?t.getToken()===Dr:!1}function Dn(t){if(!t)return;if(t.getToken()!==$e)return t;const n=t,e=n.getCurrentLambdaPrivacyVar(),r=n.getLambdaParameter();if(!e)return;const s=e.get(r);return s==null&&t.getValue()?t:Dn(s)}class di extends fe{constructor(e,r,s){super(0);p(this,"_lambdaPrivacyValueMap",new Map);this._lambdaNode=e,this._interpreter=r,this._lambdaPrivacyVarKeys=s,this._lambdaPrivacyValueMap.clear()}isLambda(){return!0}execute(...e){const r=this._lambdaPrivacyVarKeys.length;if(e.length!==r)return new d(f.VALUE);this._setLambdaPrivacyValueMap(e),this._setLambdaNodeValue(this._lambdaNode),this._lambdaNode.setNotEmpty(!1);let s;if(this._interpreter.checkAsyncNode(this._lambdaNode))s=new hs(this._interpreter.executeAsync(this._lambdaNode));else{const i=this._interpreter.execute(this._lambdaNode);i.isReferenceObject()?s=i.toArrayValueObject():s=i}return this._lambdaNode.setNotEmpty(!0),s}_setLambdaNodeValue(e){const r=e.getChildren(),s=r.length;for(let i=0;i<s;i++){const a=r[i];if(a.getToken()===$e){const u=a.getLambdaParameter(),l=this._lambdaPrivacyValueMap.get(u);if(l)a.setValue(l);else{const c=a.getCurrentLambdaPrivacyVar(),h=Dn(c.get(u));h!=null&&a.setValue(h.getValue())}continue}this._setLambdaNodeValue(a)}}_setLambdaPrivacyValueMap(e){for(let r=0;r<e.length;r++){const s=e[r],i=this._lambdaPrivacyVarKeys[r];this._lambdaPrivacyValueMap.set(i,s)}}}var mi=Object.defineProperty,gi=Object.getOwnPropertyDescriptor,Ri=(t,n,e,r)=>{for(var s=r>1?void 0:r?gi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&mi(n,e,s),s},En=(t,n)=>(e,r)=>n(e,r,t);class pi extends I{constructor(e,r,s,i){super(e);p(this,"_isNotEmpty",!0);this._lambdaId=r,this._interpreter=s,this._lambdaPrivacyVarKeys=i}get nodeType(){return x.LAMBDA}setNotEmpty(e=!1){this._isNotEmpty=e}isEmptyParamFunction(){return this.getChildren().length<2&&this._isNotEmpty}isFunctionParameter(){return this._lambdaId===null}getLambdaId(){return this._lambdaId}execute(){if(this.isEmptyParamFunction())this.setValue(new di(this,this._interpreter,this._lambdaPrivacyVarKeys));else{const e=this.getChildren(),r=e.length;this.setValue(e[r-1].getValue())}}}let dt=class extends ie{constructor(t,n){super(),this._runtimeService=t,this._interpreter=n}get zIndex(){return ne.get(x.LAMBDA)||se}create(t){const n=t.getChildren(),e=n[0];let r=n.slice(1,-1);const s=n[n.length-1];if(!(e instanceof A&&s instanceof A))return T.create(f.NAME);if(e.getToken()===ve){const o=e.getChildren();if(r.length!==o.length)return T.create(f.VALUE)}else r=n.slice(0,-1);const i=g.Tools.generateRandomId(8),a=new Map;for(let o=0;o<r.length;o++){const u=r[o];if(u instanceof A){const l=u.getChildren()[0];u.setToken(Dr),a.set(l.trim(),void 0)}else return T.create(f.VALUE)}return this._runtimeService.registerFunctionDefinitionPrivacyVar(i,a),this._updateLambdaStatement(s,i,a),new pi(t.getToken(),i,this._interpreter,[...a.keys()])}checkAndCreateNodeType(t){if(!(!(t instanceof A)||t.getToken().trim().toUpperCase()!==ke))return this.create(t)}_updateLambdaStatement(t,n,e){this._updateTree(t,n,e)}_updateTree(t,n,e){const r=t.getChildren(),s=r.length,i=r[0];for(let a=0;a<s;a++){const o=r[a];if(!(pn(i)&&a!==0))if(o instanceof A)this._updateTree(o,n,e);else{const u=o.trim();if(e.has(u)){const l=new A;l.setToken($e),l.setLambdaId(n),l.setLambdaPrivacyVar(e),l.setLambdaParameter(u),r[a]=l}}}}};dt=Ri([En(0,N),En(1,V.Inject(Ue))],dt);function _n(t){if(!t)return;if(t.getToken()!==$e)return t;const n=t,e=n.getCurrentLambdaPrivacyVar(),r=n.getLambdaParameter();if(e)return _n(e.get(r))}class Di extends I{constructor(n,e,r){super(n),this._lambdaParameter=e,this._currentLambdaPrivacyVar=r}getLambdaParameter(){return this._lambdaParameter}getCurrentLambdaPrivacyVar(){return this._currentLambdaPrivacyVar}get nodeType(){return x.LAMBDA_PARAMETER}execute(){const n=_n(this._currentLambdaPrivacyVar.get(this._lambdaParameter));if(n)this.setValue(n.getValue());else{const e=this.getValue();(e==null||e.isError())&&this.setValue(new d(f.SPILL))}}}class Cn extends ie{get zIndex(){return ne.get(x.LAMBDA_PARAMETER)||se}create(n){const e=n.getFunctionDefinitionPrivacyVar(),r=n.getLambdaParameter();return e?new Di(n.getToken(),r,e):new T(f.SPILL)}checkAndCreateNodeType(n){if(!(!(n instanceof A)||n.getToken().trim()!==$e))return this.create(n)}}class Ei extends I{constructor(n){super(n),this._operatorString=n}get nodeType(){return x.NULL}execute(){this.setValue(new Qe(0))}}var _i=Object.defineProperty,Ci=Object.getOwnPropertyDescriptor,wi=(t,n,e,r)=>{for(var s=r>1?void 0:r?Ci(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&_i(n,e,s),s},yi=(t,n)=>(e,r)=>n(e,r,t);class bi extends I{constructor(n,e){super(n),this._operatorString=n,this._functionExecutor=e}get nodeType(){return x.OPERATOR}execute(){const n=this.getChildren();this._functionExecutor.name===G.COMPARE&&this._functionExecutor.setCompareType(this.getToken());let e=n[0].getValue(),r=n[1].getValue();if(e==null||r==null)throw new Error("object1 or object2 is null");e.isReferenceObject()&&(e=e.toArrayValueObject()),r.isReferenceObject()&&(r=r.toArrayValueObject()),this.setValue(this._functionExecutor.calculate(e,r))}}let mt=class extends ie{constructor(t){super(),this._functionService=t}get zIndex(){return ne.get(x.OPERATOR)||se}create(t){let n="";const e=t;e===K.PLUS?n=G.PLUS:e===K.MINUS?n=G.MINUS:e===K.MULTIPLY?n=G.MULTIPLY:e===K.DIVIDED?n=G.DIVIDED:e===K.CONCATENATE?n=ot.CONCATENATE:e===K.POWER?n=J.POWER:xn.has(e)&&(n=G.COMPARE);const r=this._functionService.getExecutor(n);return r?new bi(e,r):(console.error(`No function ${t}`),T.create(f.NAME))}checkAndCreateNodeType(t){if(t instanceof A)return;const n=t.trim();if(!(n.charAt(0)==='"'&&n.charAt(n.length-1)==='"')&&Fe.has(n))return this.create(n)}};mt=wi([yi(0,ue)],mt);class Li extends g.Disposable{constructor(){super(...arguments);p(this,"_tableMap",new Map);p(this,"_tableOptionMap",new Map)}dispose(){this._tableMap.clear(),this._tableOptionMap.clear()}remove(e,r){var s;(s=this._tableMap.get(e))==null||s.delete(r)}getTableMap(e){return this._tableMap.get(e)}getTableOptionMap(){return this._tableOptionMap}registerTable(e,r,s){var i;this._tableMap.get(e)==null&&this._tableMap.set(e,new Map),(i=this._tableMap.get(e))==null||i.set(r,s)}registerTableOptionMap(e,r){this._tableOptionMap.set(e,r)}}const Nt=V.createIdentifier("univer.formula.super-table.service");class Si extends xe{constructor(n,e,r,s){super(n),this._tableData=e,this._columnDataString=r;const i=this._tableData.sheetId,a=this._tableData.range,o=this._tableData.titleMap;this.setForcedSheetIdDirect(i);const u=this._stringToColumnData(this._columnDataString,o,s),l=u.startColumn,c=u.endColumn,h=u.type;let m=-1,E=-1;const C=a.startRow,R=a.startColumn;h===Ee.ALL?(m=C,E=R):h===Ee.DATA?(m=C+1,E=R):h===Ee.HEADERS?(m=C,E=C):h===Ee.TOTALS&&(m=R,E=R),this.setRangeData({startColumn:l,endColumn:c,startRow:m,endRow:E})}isTable(){return!0}_stringToColumnData(n,e,r){n=n.substring(1,-1);const s=n.indexOf(O.COMMA);let i=-1,a=-1,o=Ee.ALL;if(s===-1){const u=this._columnHandler(n,e);i=u.startColumn,a=u.endColumn}else{const u=n.substring(0,s).substring(1,-1),l=n.substring(s+1),c=this._columnHandler(l,e,!0);i=c.startColumn,a=c.endColumn,o=r.get(u),o||(o=Ee.ALL)}return{startColumn:i,endColumn:a,type:o}}_columnHandler(n,e,r=!1){let s=-1,i=-1;const a=n.indexOf(O.COLON);if(new RegExp(pr,"g").test(n)){const o=n.substring(0,a).substring(1,-1),u=n.substring(a+1).substring(1,-1);s=e.get(o)??-1,i=e.get(u)??-1}else r&&(n=n.substring(1,-1)),s=e.get(n)??-1,i=s;return{startColumn:s,endColumn:i}}}var Pi=Object.defineProperty,Vi=Object.getOwnPropertyDescriptor,vi=(t,n,e,r)=>{for(var s=r>1?void 0:r?Vi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Pi(n,e,s),s},Te=(t,n)=>(e,r)=>n(e,r,t);class gt extends I{constructor(n,e,r){super(e),this._accessor=n,this._operatorString=e,this._referenceObject=r}get nodeType(){return x.REFERENCE}execute(){const n=this._accessor.get(ye),e=this._accessor.get(N);this._referenceObject.setDefaultUnitId(e.currentUnitId),this._referenceObject.setDefaultSheetId(e.currentSubUnitId),this._referenceObject.setForcedSheetId(n.getSheetNameMap()),this._referenceObject.setUnitData(n.getUnitData()),this._referenceObject.setArrayFormulaCellData(n.getArrayFormulaCellData()),this._referenceObject.setRuntimeData(e.getUnitData()),this._referenceObject.setRuntimeArrayFormulaCellData(e.getRuntimeArrayFormulaCellData()),this._referenceObject.setRuntimeFeatureCellData(e.getRuntimeFeatureCellData());const{x:r,y:s}=this.getRefOffset();this._referenceObject.setRefOffset(r,s),this._referenceObject.isExceedRange()?this.setValue(new d(f.NAME)):this.setValue(this._referenceObject)}}let Rt=class extends ie{constructor(t,n,e,r,s){super(),this._definedNamesService=t,this._superTableService=n,this._formulaRuntimeService=e,this._lexer=r,this._injector=s}get zIndex(){return ne.get(x.REFERENCE)||se}checkAndCreateNodeType(t){let n=!1,e;if(t instanceof A?(n=!0,e=t.getToken().trim()):e=t.trim(),!n&&e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;if(new RegExp(ze).test(e))return new gt(this._injector,e,new It(e));if(n&&new RegExp(Tn).test(e))return new gt(this._injector,e,new rn(e));if(n&&new RegExp(Hn).test(e))return new gt(this._injector,e,new tn(e));const r=this._formulaRuntimeService.currentUnitId,s=this._superTableService.getTableMap(r),i=new RegExp(pr,"g"),a=e.replace(i,"");if(!n&&(s!=null&&s.has(a))){const o=i.exec(e);let u="";o&&(u=o[0]);const l=s.get(a),c=this._superTableService.getTableOptionMap();return new gt(this._injector,e,new Si(e,l,u,c))}}};Rt=vi([Te(0,ut),Te(1,Nt),Te(2,N),Te(3,V.Inject(be)),Te(4,V.Inject(V.Injector))],Rt);var Ai=Object.defineProperty,xi=Object.getOwnPropertyDescriptor,Oi=(t,n,e,r)=>{for(var s=r>1?void 0:r?xi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Ai(n,e,s),s},wn=(t,n)=>(e,r)=>n(e,r,t);class yn extends I{constructor(n,e,r){super(e),this._accessor=n,this._operatorString=e,this._functionExecutor=r}get nodeType(){return x.SUFFIX}execute(){let e=this.getChildren()[0].getValue(),r;if(e==null)throw new Error("object is null");this._operatorString===ae.PERCENTAGE?(e.isReferenceObject()&&(e=e.toArrayValueObject()),r=this._functionExecutor.calculate(e,new w(100))):this._operatorString===ae.POUND?r=this._handlerPound(e):r=new d(f.VALUE),this.setValue(r)}_handlerPound(n){var c,h,m,E;if(!n.isReferenceObject())return new d(f.VALUE);if(!n.isCell())return new d(f.VALUE);const e=this._accessor.get(ye),r=this._accessor.get(be),s=n,i=s.getRangePosition(),a=s.getUnitId(),o=s.getSheetId(),u=e.getFormulaData(),l=(E=(m=(h=(c=u==null?void 0:u[a])==null?void 0:c[o])==null?void 0:h[i.startRow])==null?void 0:m[i.startColumn])==null?void 0:E.f;return l?(r.treeBuilder(l),new d(f.VALUE)):new d(f.VALUE)}}let pt=class extends ie{constructor(t,n){super(),this._functionService=t,this._injector=n}get zIndex(){return ne.get(x.SUFFIX)||se}checkAndCreateNodeType(t){if(!(t instanceof A))return;const n=t.getToken().trim();if(n.charAt(0)==='"'&&n.charAt(n.length-1)==='"')return;let e="";if(n===ae.PERCENTAGE)e=G.DIVIDED;else return n===ae.POUND?new yn(this._injector,n):void 0;const r=this._functionService.getExecutor(e);return r?new yn(this._injector,n,r):(console.error(`No function ${t}`),T.create(f.NAME))}};pt=Oi([wn(0,ue),wn(1,V.Inject(V.Injector))],pt);var Bi=Object.defineProperty,Ui=Object.getOwnPropertyDescriptor,Fi=(t,n,e,r)=>{for(var s=r>1?void 0:r?Ui(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Bi(n,e,s),s},Mi=(t,n)=>(e,r)=>n(e,r,t);class $i extends I{constructor(n){super(n),this._operatorString=n}get nodeType(){return x.UNION}execute(){const n=this.getChildren(),e=n[0].getValue(),r=n[1].getValue();if(e==null||r==null)throw new Error("leftNode and rightNode");let s;this._operatorString===O.COLON?s=this._unionFunction(e,r):s=new d(f.NAME),this.setValue(s)}_unionFunction(n,e){return n.isError()||e.isError()?new d(f.REF):!n.isReferenceObject()||!e.isReferenceObject()?new d(f.REF):(n=n,e=e,n.isCell()&&e.isCell()||n.isRow()&&e.isRow()||n.isColumn()&&e.isColumn()?n.unionBy(e):new d(f.REF))}}let Dt=class extends ie{constructor(t){super(),this._functionService=t}get zIndex(){return ne.get(x.UNION)||se}create(t){return new $i(t)}checkAndCreateNodeType(t){if(!(t instanceof A))return;const e=t.getToken().trim();if(!(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')&&e===O.COLON)return this.create(e)}};Dt=Fi([Mi(0,ue)],Dt);class ki extends I{constructor(n){super(n),this._operatorString=n}get nodeType(){return x.VALUE}execute(){this.setValue(de.create(this._operatorString))}}class bn extends ie{get zIndex(){return ne.get(x.VALUE)||se}_checkValueNode(n){if(isNaN(Number(n))){const e=n.trim(),r=e.charAt(0),s=e.charAt(e.length-1);if(Vt.has(e))return this.create(e);if(r==='"'&&s==='"')return this.create(e);if(r==="{"&&s==="}")return this.create(e);if(e===pe.TRUE||e===pe.FALSE)return this.create(e)}else return this.create(n)}create(n){return new ki(n)}checkAndCreateNodeType(n){if(!(n instanceof A))return this._checkValueNode(n)}}var ji=Object.defineProperty,Qi=Object.getOwnPropertyDescriptor,Ti=(t,n,e,r)=>{for(var s=r>1?void 0:r?Qi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&ji(n,e,s),s},ee=(t,n)=>(e,r)=>n(e,r,t);let He=class extends g.Disposable{constructor(n,e,r,s,i,a,o,u,l,c,h){super();p(this,"_astNodeFactoryList",[]);p(this,"_refOffsetX",0);p(this,"_refOffsetY",0);this._runtimeService=n,this._astRootNodeFactory=e,this._functionNodeFactory=r,this._lambdaNodeFactory=s,this._lambdaParameterNodeFactory=i,this._operatorNodeFactory=a,this._prefixNodeFactory=o,this._referenceNodeFactory=u,this._suffixNodeFactory=l,this._unionNodeFactory=c,this._valueNodeFactory=h,this._initializeAstNode()}dispose(){this._astNodeFactoryList.forEach(n=>{n.dispose()}),this._astNodeFactoryList=[]}parse(n,e=0,r=0){const s=new Jt(ce);return this._refOffsetX=e,this._refOffsetY=r,this._parse(n,s)}_lambdaParameterHandler(n,e){const r=e.getLambdaId(),s=new Jt(ce),i=this._runtimeService.getFunctionDefinitionPrivacyVar(r);if(!i)return!1;const a=[...i.keys()],o=n.getChildren(),u=o.length;for(let h=0;h<u;h++){const m=o[h];if(m instanceof A)this._parse(m,s);else return!1}const l=s.getChildren(),c=l.length;for(let h=0;h<c;h++){const m=l[h];i.set(a[h],m)}return s.setParent(e),e}_changeLetToLambda(n){const e=n.getChildren(),r=e.length;if(r%2!==1||r===0)return;const s=new A;s.setToken(ke);const i=new A;i.setToken(ve);const a=[...e];for(let u=0;u<r;u++){const l=a[u];if(!(l instanceof A))return;u%2===0?l.changeToParent(s):l.changeToParent(i)}s.addChildrenFirst(i),i.setParent(s);const o=n.getParent();return o==null||o.replaceChild(n,s),s}_getTopParent(n){let e=n;for(;e!=null&&e.getParent();)e=e.getParent();return e}_parse(n,e){const r=n.getChildren(),s=r.length,i=[];let a=null;const o=n.getToken().trim().toUpperCase();if(o===Xn){const c=this._changeLetToLambda(n);return c!=null?this._parse(c,e):T.create(f.ERROR)}if(o===Re){if(a=e,s===0)return new Ei(ce).setParent(e),a}else{if(o===ve){let c=this._lambdaParameterHandler(n,e);return c===!1&&(c=T.create(f.ERROR)),c}if(a=this._checkAstNode(n),a==null)return T.create(f.ERROR)}const u=r[0];for(let c=0;c<s;c++){const h=r[c];if(pn(u)){if(c!==0&&c!==s-1)continue}else if(fi(h)&&c!==s-1)continue;let m=null;if(h instanceof A){if(m=this._parse(h,a),m===a)continue}else m=this._checkAstNode(h);if(m==null)return T.create(f.NAME);if(m=this._getTopParent(m),m==null)return;switch(m.nodeType){case x.ERROR:return m;case x.FUNCTION:i.push(m);break;case x.LAMBDA:i.push(m);break;case x.LAMBDA_PARAMETER:i.push(m);break;case x.OPERATOR:{const E=i.pop(),C=i.pop();if(C)C.setParent(m);else return T.create(f.ERROR);if(E)E.setParent(m);else return T.create(f.ERROR);i.push(m);break}case x.REFERENCE:m.setRefOffset(this._refOffsetX,this._refOffsetY),i.push(m);break;case x.ROOT:i.push(m);break;case x.UNION:i.push(m);break;case x.VALUE:i.push(m);break;case x.PREFIX:i.push(m);break;case x.SUFFIX:i.push(m);break}}const l=i.length;for(let c=0;c<l;c++)i[c].setParent(a);return a}_checkAstNode(n){let e=null;const r=this._astNodeFactoryList.length;for(let s=0;s<r&&(e=this._astNodeFactoryList[s].checkAndCreateNodeType(n),e==null);s++);return e}_initializeAstNode(){this._astNodeFactoryList=[this._astRootNodeFactory,this._functionNodeFactory,this._lambdaNodeFactory,this._lambdaParameterNodeFactory,this._operatorNodeFactory,this._prefixNodeFactory,this._referenceNodeFactory,this._suffixNodeFactory,this._unionNodeFactory,this._valueNodeFactory].sort(g.sortRules)}};He=Ti([ee(0,N),ee(1,V.Inject(mn)),ee(2,V.Inject(ft)),ee(3,V.Inject(dt)),ee(4,V.Inject(Cn)),ee(5,V.Inject(mt)),ee(6,V.Inject(ct)),ee(7,V.Inject(Rt)),ee(8,V.Inject(pt)),ee(9,V.Inject(Dt)),ee(10,V.Inject(bn))],He);class Ln extends g.Disposable{constructor(){super(...arguments);p(this,"_referenceExecutorMap",new Map)}dispose(){this._referenceExecutorMap.clear()}remove(e){this._referenceExecutorMap.delete(e)}get(e){return this._referenceExecutorMap.get(e)}has(e){return this._referenceExecutorMap.has(e)}register(e,r){this._referenceExecutorMap.set(e,r)}getReferenceExecutorMap(){return this._referenceExecutorMap}}const Et=V.createIdentifier("univer.formula.feature-calculation-manager.service");class Sn extends g.Disposable{constructor(){super(...arguments);p(this,"_otherFormulaData",{})}dispose(){this._otherFormulaData={}}remove(e){var a,o,u;const{unitId:r,subUnitId:s,formulaId:i}=e;(u=(o=(a=this._otherFormulaData)==null?void 0:a[r])==null?void 0:o[s])==null||delete u[i]}get(e){var a,o;const{unitId:r,subUnitId:s,formulaId:i}=e;return(o=(a=this._otherFormulaData[r])==null?void 0:a[s])==null?void 0:o[i]}has(e){var a,o;const{unitId:r,subUnitId:s,formulaId:i}=e;return((o=(a=this._otherFormulaData[r])==null?void 0:a[s])==null?void 0:o[i])!=null}register(e){const{unitId:r,subUnitId:s,formulaId:i,item:a}=e;this._otherFormulaData[r]&&(this._otherFormulaData[r]={}),this._otherFormulaData[r][s]&&(this._otherFormulaData[r][s]={}),this._otherFormulaData[r][s][i]=a}getOtherFormulaData(){return this._otherFormulaData}}const er=V.createIdentifier("univer.formula.other-formula-manager.service");class tr extends g.Disposable{constructor(){super(...arguments);p(this,"node");p(this,"children",[]);p(this,"parents",[]);p(this,"formula","");p(this,"row",-1);p(this,"column",-1);p(this,"rowCount",-1/0);p(this,"columnCount",-1/0);p(this,"subUnitId","");p(this,"unitId","");p(this,"rangeList",[]);p(this,"formulaId");p(this,"featureId");p(this,"getDirtyData");p(this,"_state",0)}dispose(){var e;this.children.forEach(r=>{r.dispose()}),this.rangeList=[],this.parents=[],(e=this.node)==null||e.dispose()}setAdded(){this._state=1}isAdded(){return this._state===1}setSkip(){this._state=2}isSkip(){return this._state===2}inRangeData(e){const r=e.startRow,s=e.startColumn,i=e.endRow,a=e.endColumn;return!(this.row<r||this.row>i||this.column<s||this.column>a)}dependencyRange(e,r,s){var i,a;if(this.rangeList.length===0)return!1;for(let o=0,u=this.rangeList.length;o<u;o++){const l=this.rangeList[o],{unitId:c,sheetId:h,range:m}=l;if(!e.has(c))continue;const E=e.get(c);if(!E.has(h))continue;const C=E.get(h),R=(i=s==null?void 0:s[c])==null?void 0:i[h];let{startRow:_,endRow:b,startColumn:L,endColumn:S}=m;isNaN(_)&&(_=0),isNaN(L)&&(L=0),isNaN(b)&&(b=1/0),isNaN(S)&&(S=1/0);for(const P of C){const{startRow:k,startColumn:j,endRow:H,endColumn:B}=P;if(!(_>H||b<k||L>B||S<j)){let v=!0;if(R==null||R.forValue((F,$)=>{if(F>=_&&F<=b&&$>=L&&$<=S)return v=!1,!1}),v)return!0}}if(((a=r[c])==null?void 0:a[h])!=null)return!0}return!1}pushChildren(e){this.children.push(e),e._pushParent(this)}pushRangeList(e){this.rangeList.push(e)}dependency(e){if(this.rangeList.length===0)return!1;for(let r=0,s=this.rangeList.length;r<s;r++){const i=this.rangeList[r],a=i.unitId,o=i.sheetId,u=i.range;if(e.unitId===a&&e.subUnitId===o&&e.inRangeData(u))return!0}return!1}_pushParent(e){this.parents.push(e)}}var Hi=Object.defineProperty,Yi=Object.getOwnPropertyDescriptor,Wi=(t,n,e,r)=>{for(var s=r>1?void 0:r?Yi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Hi(n,e,s),s},Le=(t,n)=>(e,r)=>n(e,r,t);const Xi=1e5,rr=new Ke(Xi);let Ye=class extends g.Disposable{constructor(n,e,r,s,i,a,o){super();p(this,"_updateRangeFlattenCache",new Map);p(this,"_dirtyUnitSheetNameMap",{});this._currentConfigService=n,this._runtimeService=e,this._otherFormulaManagerService=r,this._featureCalculationManagerService=s,this._interpreter=i,this._astTreeBuilder=a,this._lexer=o}dispose(){this._updateRangeFlattenCache.clear(),rr.clear(),this._dirtyUnitSheetNameMap={}}async generate(){this._updateRangeFlatten();const n=this._currentConfigService.getFormulaData(),e=this._otherFormulaManagerService.getOtherFormulaData(),r=this._currentConfigService.getUnitData(),s=await this._generateTreeList(n,e,r),i=this._getUpdateTreeListAndMakeDependency(s);this._checkIsCycleDependency(i)&&this._runtimeService.enableCycleDependency();const o=this._calculateRunList(i);return Promise.resolve(o)}_isCyclicUtil(n,e,r){if(!e.has(n)){e.add(n),r.add(n);for(let s=0;s<n.children.length;s++)if(!e.has(n.children[s])&&this._isCyclicUtil(n.children[s],e,r)||r.has(n.children[s]))return!0}return r.delete(n),!1}_checkIsCycleDependency(n){const e=new Set,r=new Set;for(let s=0,i=n.length;s<i;s++){const a=n[s];if(this._isCyclicUtil(a,e,r)===!0)return!0}return!1}async _generateTreeList(n,e,r){const s=Object.keys(n),i=Object.keys(e),a=[];for(const o of s){const u=n[o];if(u==null)continue;const l=Object.keys(u);for(const c of l)new g.ObjectMatrix(u[c]).forValue((m,E,C)=>{if(C==null)return!0;const{f:R,x:_,y:b}=C,L=this._generateAstNode(R,_,b),S=new tr,P=r[o][c];S.node=L,S.formula=R,S.unitId=o,S.subUnitId=c,S.row=m,S.column=E,S.rowCount=P.rowCount,S.columnCount=P.columnCount,a.push(S)})}for(const o of i){const u=e[o];if(u==null)continue;const l=Object.keys(u);for(const c of l){const h=u[c];if(h==null)continue;const m=Object.keys(h);for(const E of m){const C=h[E],{f:R}=C,_=this._generateAstNode(R),b=new tr;b.node=_,b.formula=R,b.unitId=o,b.subUnitId=c,b.formulaId=E,a.push(b)}}}this._featureCalculationManagerService.getReferenceExecutorMap().forEach((o,u)=>{const{unitId:l,subUnitId:c,dependencyRanges:h,getDirtyData:m}=o,E=new tr;E.unitId=l,E.subUnitId=c,E.getDirtyData=m,E.featureId=u,E.rangeList=h,a.push(E)});for(let o=0,u=a.length;o<u;o++){const l=a[o];if(this._runtimeService.setCurrent(l.row,l.column,l.rowCount,l.columnCount,l.subUnitId,l.unitId),l.node==null)continue;const c=await this._getRangeListByNode(l.node);for(let h=0,m=c.length;h<m;h++)l.pushRangeList(c[h])}return a}_updateRangeFlatten(){const n=this._currentConfigService.isForceCalculate(),e=this._currentConfigService.getDirtyRanges();if(!n){this._updateRangeFlattenCache.clear();for(let r=0;r<e.length;r++){const s=e[r],i=s.range,a=s.sheetId,o=s.unitId;this._addFlattenCache(o,a,i)}this._dirtyUnitSheetNameMap=this._currentConfigService.getDirtyNameMap()}}_generateAstNode(n,e=0,r=0){let s=rr.get(`${n}##${e}${r}`);if(s)return s;const i=this._lexer.treeBuilder(n);if(i in f)return T.create(i);if(s=this._astTreeBuilder.parse(i,e,r),s==null)throw new Error("astNode is null");return rr.set(`${n}##${e}${r}`,s),s}_addFlattenCache(n,e,r){let s=this._updateRangeFlattenCache.get(n);s==null&&(s=new Map,this._updateRangeFlattenCache.set(n,s));let i=s.get(e);i==null&&(i=[],s.set(e,i)),i.push(r)}_isPreCalculateNode(n){return n.nodeType===x.UNION||n.nodeType===x.PREFIX&&n.getToken()===Q.AT||n.nodeType===x.SUFFIX&&n.getToken()===ae.POUND}_nodeTraversalRef(n,e){const r=n.getChildren(),s=r.length;for(let i=0;i<s;i++){const a=r[i];if(this._isPreCalculateNode(a)){e.push(a);continue}else a.nodeType===x.REFERENCE&&e.push(a);this._nodeTraversalRef(a,e)}}_nodeTraversalReferenceFunction(n,e){const r=n.getChildren(),s=r.length;for(let i=0;i<s;i++){const a=r[i];if(a.nodeType===x.FUNCTION&&a.isAddress()){e.push(a);continue}this._nodeTraversalReferenceFunction(a,e)}}async _executeNode(n){let e;return this._interpreter.checkAsyncNode(n)?e=await this._interpreter.executeAsync(n):e=this._interpreter.execute(n),e}async _getRangeListByNode(n){const e=[],r=[];this._nodeTraversalRef(n,e),this._nodeTraversalReferenceFunction(n,r);const s=[];for(let i=0,a=e.length;i<a;i++){const o=e[i],l=(await this._executeNode(o)).toUnitRange();s.push(l)}for(let i=0,a=r.length;i<a;i++){const o=r[i],l=(await this._executeNode(o)).toUnitRange();s.push(l)}return s}_getUpdateTreeListAndMakeDependency(n){const e=[],r=new Set,s=this._currentConfigService.isForceCalculate();for(let i=0,a=n.length;i<a;i++){const o=n[i];for(let u=0,l=n.length;u<l;u++){const c=n[u];o!==c&&o.dependency(c)&&o.pushChildren(c)}(s||o.dependencyRange(this._updateRangeFlattenCache,this._dirtyUnitSheetNameMap,this._currentConfigService.getExcludedRange())||this._includeTree(o))&&!r.has(o)&&(e.push(o),r.add(o))}return e}_includeTree(n){var l,c,h,m,E;const e=n.unitId,r=n.subUnitId,s=n.featureId;if(s!=null){const C=this._currentConfigService.getDirtyUnitFeatureMap();if(((c=(l=C==null?void 0:C[e])==null?void 0:l[r])==null?void 0:c[s])!=null)return!0}const i=(m=(h=this._currentConfigService.getExcludedRange())==null?void 0:h[e])==null?void 0:m[r];let a=!1;if(i==null||i.forValue((C,R)=>{if(n.row===C&&n.column===R)return a=!0,!1}),a)return!1;if(((E=this._dirtyUnitSheetNameMap[e])==null?void 0:E[r])!=null)return!0;if(!this._updateRangeFlattenCache.has(e))return!1;const o=this._updateRangeFlattenCache.get(e);if(!o.has(r))return!1;const u=o.get(r);for(const C of u)if(n.inRangeData(C))return!0;return!1}_calculateRunList(n){let e=n;const r=[];for(;e.length>0;){const s=e.pop();if(s===void 0||s.isSkip())continue;if(s.isAdded()){r.push(s);continue}const i=[];for(let a=0,o=s.parents.length;a<o;a++){const u=s.parents[a];i.push(u)}i.length===0?(r.push(s),s.setSkip()):(s.setAdded(),e.push(s),e=e.concat(i))}return r.reverse()}};Ye=Wi([g.OnLifecycle(g.LifecycleStages.Rendered,Ye),Le(0,ye),Le(1,N),Le(2,er),Le(3,Et),Le(4,V.Inject(Ue)),Le(5,V.Inject(He)),Le(6,V.Inject(be))],Ye);var Gi=Object.defineProperty,Ki=Object.getOwnPropertyDescriptor,Ii=(t,n,e,r)=>{for(var s=r>1?void 0:r?Ki(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Gi(n,e,s),s},Se=(t,n)=>(e,r)=>n(e,r,t);const zi=1;D.CalculateFormulaService=class extends g.Disposable{constructor(e,r,s,i,a,o,u){super();p(this,"_executionStartListener$",new Pt.Subject);p(this,"executionStartListener$",this._executionStartListener$.asObservable());p(this,"_executionCompleteListener$",new Pt.Subject);p(this,"executionCompleteListener$",this._executionCompleteListener$.asObservable());p(this,"_executionInProgressListener$",new Pt.Subject);p(this,"executionInProgressListener$",this._executionInProgressListener$.asObservable());this._configService=e,this._lexer=r,this._currentConfigService=s,this._runtimeService=i,this._formulaDependencyGenerator=a,this._interpreter=o,this._astTreeBuilder=u}dispose(){}stopFormulaExecution(){this._runtimeService.stopExecution()}setRuntimeFeatureCellData(e,r){this._runtimeService.setRuntimeFeatureCellData(e,r)}setRuntimeFeatureRange(e,r){this._runtimeService.setRuntimeFeatureRange(e,r)}async execute(e){this._executionStartListener$.next(!0),this._currentConfigService.load(e),this._runtimeService.reset();const r=this._configService.getConfig("CYCLE_REFERENCE_COUNT")||zi;for(let s=0;s<r&&(await this._execute(),!!this._runtimeService.isCycleDependency());s++);this._runtimeService.setFormulaExecuteStage(re.CALCULATION_COMPLETED),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState()),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData()),Gt.clear(),he.clear()}async _execute(){const e=await this._apply();if(e==null)return;const{arrayFormulaRange:r,runtimeFeatureRange:s}=e,{dirtyRanges:i,excludedCell:a}=this._getArrayFormulaDirtyRangeAndExcludedRange(r,s);return i==null||i.length===0||(this._currentConfigService.loadDirtyRangesAndExcludedCell(i,a),await this._apply(!0)),!0}_getArrayFormulaDirtyRangeAndExcludedRange(e,r){const s=[],i={};return Object.keys(e).forEach(a=>{const o=e[a];if(o==null)return!0;Object.keys(o).forEach(u=>{const l=new g.ObjectMatrix(o[u]);if(l==null)return!0;const c=new g.ObjectMatrix;l.forValue((h,m,E)=>{c.setValue(h,m,!0),s.push({unitId:a,sheetId:u,range:E})}),i[a]==null&&(i[a]={}),i[a][u]=c})}),Object.keys(r).forEach(a=>{const o=r[a];Object.keys(o).forEach(u=>{const l=o[u];if(l==null)return!0;Object.keys(l).forEach(c=>{const h=l[c];if(h==null)return!0;for(const m of h)s.push({unitId:u,sheetId:c,range:m})})})}),{dirtyRanges:s,excludedCell:i}}async _apply(e=!1){e?this._runtimeService.setFormulaExecuteStage(re.START_DEPENDENCY_ARRAY_FORMULA):this._runtimeService.setFormulaExecuteStage(re.START_DEPENDENCY),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());const r=await this._formulaDependencyGenerator.generate(),s=this._interpreter;e?(this._runtimeService.setFormulaExecuteStage(re.START_CALCULATION_ARRAY_FORMULA),this._runtimeService.setTotalArrayFormulasToCalculate(r.length)):(this._runtimeService.setFormulaExecuteStage(re.START_CALCULATION),this._runtimeService.setTotalFormulasToCalculate(r.length)),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());for(let i=0,a=r.length;i<a;i++){if(await new Promise(h=>{g.requestImmediateMacroTask(h)}),this._runtimeService.isStopExecution()){this._runtimeService.setFormulaExecuteStage(re.IDLE),this._runtimeService.markedAsStopFunctionsExecuted(),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData());return}const o=r[i],u=o.node,l=o.getDirtyData;let c;if(u==null&&l==null)throw new Error("AstNode or executor is null");if(this._runtimeService.setCurrent(o.row,o.column,o.rowCount,o.columnCount,o.subUnitId,o.unitId),l!=null&&o.featureId!=null){const{runtimeCellData:h,dirtyRanges:m}=l(o);this._runtimeService.setRuntimeFeatureCellData(o.featureId,h),this._runtimeService.setRuntimeFeatureRange(o.featureId,m)}else u!=null&&(s.checkAsyncNode(u)?c=await s.executeAsync(u):c=s.execute(u),o.formulaId!=null?this._runtimeService.setRuntimeOtherData(o.formulaId,c):this._runtimeService.setRuntimeData(c));e?(this._runtimeService.setFormulaExecuteStage(re.CURRENTLY_CALCULATING_ARRAY_FORMULA),this._runtimeService.setCompletedArrayFormulasCount(i+1)):(this._runtimeService.setFormulaExecuteStage(re.CURRENTLY_CALCULATING),this._runtimeService.setCompletedFormulasCount(i+1)),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState())}return r.length>0?this._runtimeService.markedAsSuccessfullyExecuted():e||this._runtimeService.markedAsNoFunctionsExecuted(),this._runtimeService.getAllRuntimeData()}calculate(e,r=!0){const s=this._lexer.treeBuilder(e,r);if(Object.values(f).includes(s))return T.create(s);const i=this._astTreeBuilder.parse(s);i==null||i.serialize()}},D.CalculateFormulaService=Ii([g.OnLifecycle(g.LifecycleStages.Rendered,D.CalculateFormulaService),Se(0,g.IConfigService),Se(1,V.Inject(be)),Se(2,ye),Se(3,N),Se(4,V.Inject(Ye)),Se(5,V.Inject(Ue)),Se(6,V.Inject(He))],D.CalculateFormulaService);var qi=Object.defineProperty,Zi=Object.getOwnPropertyDescriptor,Ji=(t,n,e,r)=>{for(var s=r>1?void 0:r?Zi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&qi(n,e,s),s},_t=(t,n)=>(e,r)=>n(e,r,t);let Ct=class extends g.Disposable{constructor(t,n,e,r){super(),this._commandService=t,this._calculateFormulaService=n,this._currentUniverService=e,this._formulaDataModel=r,this._initialize()}_initialize(){this._commandExecutedListener(),this._initialExecuteFormulaListener(),this._initialExecuteFormulaProcessListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{if(t.id===kt.id)this._calculateFormulaService.stopFormulaExecution();else if(t.id===Qt.id){const e=t.params.formulaData;this._formulaDataModel.setFormulaData(e)}else if(t.id===$t.id){const e=t.params;if(e.forceCalculation===!0)this._calculate(!0);else{const{dirtyRanges:r,dirtyNameMap:s,dirtyUnitFeatureMap:i}=e;this._calculate(!1,r,s,i)}}else if(t.id===Ze.id){const e=t.params;if(e==null)return;const{arrayFormulaRange:r,arrayFormulaCellData:s}=e;this._formulaDataModel.setArrayFormulaRange(r),this._formulaDataModel.setArrayFormulaCellData(s)}}))}async _calculate(t=!1,n=[],e={},r={}){if(n.length===0&&Object.keys(e).length===0&&Object.keys(r).length===0&&t===!1)return;const s=this._formulaDataModel.getFormulaData(),i=this._formulaDataModel.getArrayFormulaCellData();this._calculateFormulaService.execute({formulaData:s,arrayFormulaCellData:i,forceCalculate:t,dirtyRanges:n,dirtyNameMap:e,dirtyUnitFeatureMap:r})}_initialExecuteFormulaListener(){this._calculateFormulaService.executionCompleteListener$.subscribe(t=>{const n=t.functionsExecutedState;switch(n){case Be.NOT_EXECUTED:break;case Be.STOP_EXECUTION:break;case Be.SUCCESS:this._applyFormula(t);break;case Be.INITIAL:break}this._commandService.executeCommand(et.id,{functionsExecutedState:n},{onlyLocal:!0})})}_initialExecuteFormulaProcessListener(){this._calculateFormulaService.executionInProgressListener$.subscribe(t=>{this._commandService.executeCommand(et.id,{stageInfo:t},{onlyLocal:!0})})}async _applyFormula(t){const{unitData:n,unitOtherData:e,arrayFormulaRange:r,arrayFormulaCellData:s,clearArrayFormulaCellData:i}=t;if(!n){console.error("No sheetData from Formula Engine!");return}r&&(this._formulaDataModel.clearPreviousArrayFormulaCellData(i),this._formulaDataModel.mergeArrayFormulaCellData(s),this._formulaDataModel.mergeArrayFormulaRange(r),this._commandService.executeCommand(Ze.id,{arrayFormulaRange:this._formulaDataModel.getArrayFormulaRange(),arrayFormulaCellData:this._formulaDataModel.getArrayFormulaCellData()},{onlyLocal:!0})),this._commandService.executeCommand(jt.id,{unitData:n,unitOtherData:e},{onlyLocal:!0})}};Ct=Ji([g.OnLifecycle(g.LifecycleStages.Ready,Ct),_t(0,g.ICommandService),_t(1,V.Inject(D.CalculateFormulaService)),_t(2,g.IUniverInstanceService),_t(3,V.Inject(D.FormulaDataModel))],Ct);var Ni=Object.defineProperty,ea=Object.getOwnPropertyDescriptor,ta=(t,n,e,r)=>{for(var s=r>1?void 0:r?ea(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Ni(n,e,s),s},nr=(t,n)=>(e,r)=>n(e,r,t);let We=class extends g.Disposable{constructor(t=[],n,e,r){super(),this._function=t,this._commandService=n,this._injector=e,this._functionService=r,this._initialize()}_initialize(){this._registerCommands(),this._registerFunctions()}_registerCommands(){[Qt,Ze,$t,kt,et,jt,Je,Ne,Ft,Mt,Tt,Ht,yr,br,Yt,vt,Wt].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}_registerFunctions(){const t=[...jr,...Qr,...Hr,...Wr,...Gr,...Ir,...qr,...Jr,...en,...nn,...an,...on,...ln,...cn,...hn,...fn].concat(this._function).map(n=>{const e=n[0],r=n[1];return new e(r)});this._functionService.registerExecutors(...t)}};We=ta([g.OnLifecycle(g.LifecycleStages.Ready,We),nr(1,g.ICommandService),nr(2,V.Inject(V.Injector)),nr(3,ue)],We);var ra=Object.defineProperty,na=Object.getOwnPropertyDescriptor,sa=(t,n,e,r)=>{for(var s=r>1?void 0:r?na(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&ra(n,e,s),s},sr=(t,n)=>(e,r)=>n(e,r,t);let wt=class extends g.Disposable{constructor(t,n,e){super(),this._commandService=t,this._formulaDataModel=n,this._functionService=e,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{if(t.id===vt.id){const e=t.params;if(e==null)return;const{functions:r}=e,s=r.map(i=>{const a=i[0],o=i[1];return aa(a,o)});this._functionService.registerExecutors(...s)}else if(t.id===Wt.id){const e=t.params;if(e==null)return;const{functions:r}=e;this._functionService.unregisterExecutors(...r)}}))}};wt=sa([g.OnLifecycle(g.LifecycleStages.Ready,wt),sr(0,g.ICommandService),sr(1,V.Inject(D.FormulaDataModel)),sr(2,ue)],wt);class ia extends M{isCustom(){return!0}}function aa(t,n){const e=new ia(n),r=new Function(`return ${t}`)();return e.calculateCustom=r,e}var oa=Object.defineProperty,ua=Object.getOwnPropertyDescriptor,la=(t,n,e,r)=>{for(var s=r>1?void 0:r?ua(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&oa(n,e,s),s},Pn=(t,n)=>(e,r)=>n(e,r,t);let yt=class extends g.Disposable{constructor(t,n){super(),this._commandService=t,this._definedNamesService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===Je.id){const n=t.params;if(n==null)return;const{unitId:e,name:r,formulaOrRefString:s}=n;this._definedNamesService.registerDefinedName(e,r,s)}else if(t.id===Ne.id){const n=t.params;if(n==null)return;const{unitId:e,name:r}=n;this._definedNamesService.removeDefinedName(e,r)}}))}};yt=la([g.OnLifecycle(g.LifecycleStages.Ready,yt),Pn(0,g.ICommandService),Pn(1,ut)],yt);var ca=Object.defineProperty,ha=Object.getOwnPropertyDescriptor,fa=(t,n,e,r)=>{for(var s=r>1?void 0:r?ha(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&ca(n,e,s),s},Vn=(t,n)=>(e,r)=>n(e,r,t);let bt=class extends g.Disposable{constructor(t,n){super(),this._commandService=t,this._featureCalculationManagerService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===Ft.id){const n=t.params;if(n==null)return;const{featureId:e,calculationParam:r}=n;this._featureCalculationManagerService.register(e,r)}else if(t.id===Mt.id){const n=t.params;if(n==null)return;const{featureId:e}=n;this._featureCalculationManagerService.remove(e)}}))}};bt=fa([g.OnLifecycle(g.LifecycleStages.Ready,bt),Vn(0,g.ICommandService),Vn(1,Et)],bt);var da=Object.defineProperty,ma=Object.getOwnPropertyDescriptor,ga=(t,n,e,r)=>{for(var s=r>1?void 0:r?ma(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&da(n,e,s),s},vn=(t,n)=>(e,r)=>n(e,r,t);let Lt=class extends g.Disposable{constructor(t,n){super(),this._commandService=t,this._otherFormulaManagerService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===Tt.id){const n=t.params;if(n==null)return;this._otherFormulaManagerService.register(n)}else if(t.id===Ht.id){const n=t.params;if(n==null)return;this._otherFormulaManagerService.remove(n)}}))}};Lt=ga([g.OnLifecycle(g.LifecycleStages.Ready,Lt),vn(0,g.ICommandService),vn(1,er)],Lt);var Ra=Object.defineProperty,pa=Object.getOwnPropertyDescriptor,Da=(t,n,e,r)=>{for(var s=r>1?void 0:r?pa(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Ra(n,e,s),s},An=(t,n)=>(e,r)=>n(e,r,t);let St=class extends g.Disposable{constructor(t,n){super(),this._commandService=t,this._superTableService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===Je.id){const n=t.params;if(n==null)return;const{unitId:e,tableName:r,reference:s}=n;this._superTableService.registerTable(e,r,s)}else if(t.id===Ne.id){const n=t.params;if(n==null)return;const{unitId:e,tableName:r}=n;this._superTableService.remove(e,r)}else if(t.id===Yt.id){const n=t.params;if(n==null)return;const{tableOption:e,tableOptionType:r}=n;this._superTableService.registerTableOptionMap(e,r)}}))}};St=Da([g.OnLifecycle(g.LifecycleStages.Ready,St),An(0,g.ICommandService),An(1,Nt)],St);var Ea=Object.defineProperty,_a=Object.getOwnPropertyDescriptor,Ca=(t,n,e,r)=>{for(var s=r>1?void 0:r?_a(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Ea(n,e,s),s},wa=(t,n)=>(e,r)=>n(e,r,t);const ya="base-formula-engine";D.UniverFormulaEnginePlugin=class extends g.Plugin{constructor(n,e){super(ya),this._config=n,this._injector=e}onStarting(){this._initialize()}_initialize(){var e;const n=[[ue,{useClass:gn}],[Et,{useClass:Ln}],[ut,{useClass:Ys}],[D.FormulaDataModel],[qe],[We,{useFactory:()=>{var r;return this._injector.createInstance(We,(r=this._config)==null?void 0:r.function)}}],[bt]];(e=this._config)!=null&&e.notExecuteFormula||n.push([D.CalculateFormulaService],[er,{useClass:Sn}],[Nt,{useClass:Li}],[ye,{useClass:zt}],[N,{useClass:qt}],[Ct],[yt],[Lt],[St],[wt],[Ye],[Ue],[He],[be],[mn],[ft],[dt],[Cn],[mt],[ct],[Rt],[pt],[Dt],[bn]),n.forEach(r=>this._injector.add(r))}onReady(){this._injector.get(D.FormulaDataModel).initFormulaData()}},D.UniverFormulaEnginePlugin=Ca([wa(1,V.Inject(V.Injector))],D.UniverFormulaEnginePlugin),D.ArrayValueObject=Z,D.BaseFunction=M,D.BaseReferenceObject=xe,D.BaseValueObject=fe,D.BooleanValueObject=X,D.ErrorType=f,D.ErrorValueObject=d,D.FUNCTION_NAMES_ARRAY=ms,D.FUNCTION_NAMES_COMPATIBILITY=Tr,D.FUNCTION_NAMES_CUBE=Yr,D.FUNCTION_NAMES_DATABASE=Xr,D.FUNCTION_NAMES_DATE=Kr,D.FUNCTION_NAMES_ENGINEERING=zr,D.FUNCTION_NAMES_FINANCIAL=Zr,D.FUNCTION_NAMES_INFORMATION=Nr,D.FUNCTION_NAMES_LOGICAL=at,D.FUNCTION_NAMES_LOOKUP=Oe,D.FUNCTION_NAMES_MATH=J,D.FUNCTION_NAMES_STATISTICAL=me,D.FUNCTION_NAMES_TEXT=ot,D.FUNCTION_NAMES_UNIVER=Hs,D.FUNCTION_NAMES_WEB=dn,D.FeatureCalculationManagerService=Ln,D.FormulaExecuteStageType=re,D.FormulaExecutedStateType=Be,D.FunctionService=gn,D.FunctionType=ar,D.IFeatureCalculationManagerService=Et,D.IFunctionService=ue,D.LexerNode=A,D.LexerTreeBuilder=qe,D.NumberValueObject=w,D.OtherFormulaManagerService=Sn,D.RangeReferenceObject=st,D.RegisterFunctionMutation=vt,D.RemoveDefinedNameMutation=Ne,D.RemoveFeatureCalculationMutation=Mt,D.RemoveOtherFormulaMutation=Ht,D.RemoveSuperTableMutation=br,D.SetArrayFormulaDataMutation=Ze,D.SetArrayFormulaDataUndoMutationFactory=zn,D.SetDefinedNameMutation=Je,D.SetFeatureCalculationMutation=Ft,D.SetFormulaCalculationNotificationMutation=et,D.SetFormulaCalculationResultMutation=jt,D.SetFormulaCalculationStartMutation=$t,D.SetFormulaCalculationStopMutation=kt,D.SetFormulaDataMutation=Qt,D.SetOtherFormulaMutation=Tt,D.SetSuperTableMutation=yr,D.SetSuperTableOptionMutation=Yt,D.StringValueObject=W,D.UNIT_NAME_REGEX=oe,D.UnregisterFunctionMutation=Wt,D.ValueObjectFactory=de,D.compareToken=y,D.convertUnitDataToRuntime=lr,D.deserializeRangeForR1C1=kr,D.deserializeRangeWithSheet=Pe,D.functionArray=jr,D.functionCompatibility=Qr,D.functionCube=Hr,D.functionDatabase=Wr,D.functionDate=Gr,D.functionEngineering=Ir,D.functionFinancial=qr,D.functionInformation=Jr,D.functionLogical=en,D.functionLookup=nn,D.functionMath=an,D.functionMeta=on,D.functionStatistical=ln,D.functionText=cn,D.functionUniver=hn,D.functionWeb=fn,D.generateStringWithSequence=Er,D.getAbsoluteRefTypeWitString=Mn,D.getAbsoluteRefTypeWithSingleString=Me,D.includeFormulaLexerToken=ur,D.initSheetFormulaData=wr,D.isFormulaLexerToken=Ge,D.isInDirtyRange=ir,D.matchToken=O,D.normalizeSheetName=Bn,D.sequenceNodeType=z,D.serializeRange=ge,D.serializeRangeToRefString=dr,D.serializeRangeWithSheet=hr,D.serializeRangeWithSpreadsheet=fr,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
|