@univerjs/engine-formula 0.1.0-alpha.3 → 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +2632 -2451
- package/lib/types/basics/object-class-type.d.ts +1 -0
- package/lib/types/engine/ast-node/base-ast-node.d.ts +1 -0
- package/lib/types/engine/ast-node/lambda-node.d.ts +11 -3
- package/lib/types/engine/ast-node/union-node.d.ts +2 -3
- package/lib/types/engine/reference-object/base-reference-object.d.ts +9 -3
- package/lib/types/engine/value-object/array-value-object.d.ts +1 -0
- package/lib/types/engine/value-object/base-value-object.d.ts +1 -0
- package/lib/types/engine/value-object/lambda-value-object.d.ts +30 -0
- package/lib/types/functions/array/function-map.d.ts +3 -1
- package/lib/types/functions/array/function-names.d.ts +1 -0
- package/lib/types/functions/array/makearray/index.d.ts +22 -0
- package/lib/types/functions/base-function.d.ts +2 -1
- package/lib/types/functions/compatibility/function-map.d.ts +1 -1
- package/lib/types/functions/lookup/function-map.d.ts +1 -1
- package/lib/types/functions/{statistical/count/count.d.ts → math/abs/index.d.ts} +2 -2
- package/lib/types/functions/{statistical/counta/counta.d.ts → math/acos/index.d.ts} +2 -2
- package/lib/types/functions/math/acosh/__tests__/index.spec.d.ts +16 -0
- package/lib/types/functions/{statistical/min/min.d.ts → math/acosh/index.d.ts} +2 -3
- package/lib/types/functions/math/acot/__tests__/index.spec.d.ts +16 -0
- package/lib/types/functions/math/acot/index.d.ts +21 -0
- package/lib/types/functions/math/function-map.d.ts +1 -1
- package/lib/types/functions/math/function-names.d.ts +4 -0
- package/lib/types/functions/math/sum/{sum.d.ts → index.d.ts} +2 -2
- package/lib/types/functions/math/sumif/__tests__/index.spec.d.ts +16 -0
- package/lib/types/functions/math/sumifs/__tests__/index.spec.d.ts +16 -0
- package/lib/types/functions/meta/function-map.d.ts +2 -3
- package/lib/types/functions/statistical/average/{average.d.ts → index.d.ts} +2 -2
- package/lib/types/functions/statistical/count/index.d.ts +20 -0
- package/lib/types/functions/statistical/counta/index.d.ts +20 -0
- package/lib/types/functions/statistical/function-map.d.ts +1 -1
- package/lib/types/functions/statistical/max/{max.d.ts → index.d.ts} +2 -2
- package/lib/types/functions/statistical/min/index.d.ts +21 -0
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
- package/lib/types/functions/meta/union/union.d.ts +0 -23
- /package/lib/types/functions/compatibility/concatenate/{concatenate.d.ts → index.d.ts} +0 -0
- /package/lib/types/functions/lookup/indirect/{indirect.d.ts → index.d.ts} +0 -0
- /package/lib/types/functions/lookup/offset/{offset.d.ts → index.d.ts} +0 -0
- /package/lib/types/functions/math/{sumif/__tests__/sumif.spec.d.ts → abs/__tests__/index.spec.d.ts} +0 -0
- /package/lib/types/functions/math/{sumifs/__tests__/sumifs.spec.d.ts → acos/__tests__/index.spec.d.ts} +0 -0
- /package/lib/types/functions/math/power/{power.d.ts → index.d.ts} +0 -0
- /package/lib/types/functions/math/sumif/{sumif.d.ts → index.d.ts} +0 -0
- /package/lib/types/functions/math/sumifs/{sumifs.d.ts → index.d.ts} +0 -0
- /package/lib/types/functions/meta/compare/{compare.d.ts → index.d.ts} +0 -0
- /package/lib/types/functions/meta/divided/{divided.d.ts → index.d.ts} +0 -0
- /package/lib/types/functions/meta/minus/{minus.d.ts → index.d.ts} +0 -0
- /package/lib/types/functions/meta/multiply/{multiply.d.ts → index.d.ts} +0 -0
- /package/lib/types/functions/meta/plus/{plus.d.ts → index.d.ts} +0 -0
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Fr=Object.defineProperty;var Tr=(s,r,e)=>r in s?Fr(s,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[r]=e;var C=(s,r,e)=>(Tr(s,typeof r!="symbol"?r+"":r,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@univerjs/core"),b=require("@wendellhu/redi"),lt=require("rxjs");function nr(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:c,endRow:l,endColumn:f}=o.range;if(t>=u&&t<=l&&n>=c&&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 br=new Set(["#DIV/0!","#NAME!","#VALUE!","#NUM!","#N/A","#CYCLE!","#REF!","#SPILL!","#CALC!","#ERROR!","#GETTING_DATA","#NULL!"]);var sr=(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))(sr||{}),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||{}),R=(s=>(s.EQUALS="=",s.NOT_EQUAL="<>",s.GREATER_THAN=">",s.GREATER_THAN_OR_EQUAL=">=",s.LESS_THAN="<",s.LESS_THAN_OR_EQUAL="<=",s))(R||{});const Ve=new Map([["<>",3],["<",3],[">=",3],["=",3],[">",3],["<=",3],["&",2],["+",2],["-",2],["/",1],["*",1],["^",0]]),Oe=new Set(Ve.keys()),Lr=new Set(["=","<>",">",">=","<","<="]);var L=(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))(L||{}),ae=(s=>(s.PERCENTAGE="%",s.POUND="#",s))(ae||{});const wr=new Set(["%","#"]);var v=(s=>(s.AT="@",s.MINUS="-",s))(v||{});const ir=[...Object.values(R),...Object.values(G),...Object.values(L),...Object.values(ae),...Object.values(v)];function Ct(s){return ir.includes(s)}function Or(s){for(const r of ir)if(s.indexOf(r)>-1)return!0;return!1}function Ur(s){return s[0]==="'"&&s[s.length-1]==="'"?s.substring(1,s.length-1):s}function ar(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 rt{constructor(r){C(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 ye=`'?\\[((?![\\/?:"<>|*\\\\]).)*\\]`,Fe="((?![\\[\\]\\/?*\\\\]).)*!",oe="$",Dt="\\s*?:\\s*?",pt=`\\${oe}?[A-Za-z]+\\${oe}?[0-9]+`,Ir=`^(${v.AT})?(${ye})?(${Fe})?${pt}${Dt}${pt}$`,yt=`^(${ye})?(${Fe})?\\s*?${pt}(${ae.POUND})?$`,Mr=`^(${ye})?(${Fe})?\\${oe}?[0-9]+${Dt}\\${oe}?[0-9]+$`,xr=`^(${ye})?(${Fe})?\\${oe}?[A-Za-z]+${Dt}\\${oe}?[A-Za-z]+$`,vr=`^(${ye})?(${Fe})?\\s*?\\${oe}?[0-9]+$`,Pr=`^(${ye})?(${Fe})?\\s*?\\${oe}?[A-Za-z]+$`,or="[.*?]",Vr="{.*?}";function Br(s){return new RegExp(yt).test(s)||new RegExp(Ir).test(s)||new RegExp(Mr).test(s)||new RegExp(xr).test(s)}const he="P_1",ie="R_1",Se="L_1",Ft="LR_1",ur="LO_1",kr="LET",$r="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 cr(s){let r="";for(const e of s)typeof e=="string"?r+=e:r+=e.token;return r}class F{constructor(){C(this,"_parent");C(this,"_token",ie);C(this,"_children",[]);C(this,"_lambdaId");C(this,"_functionDefinitionPrivacyVar");C(this,"_lambdaParameter","");C(this,"_startIndex",-1);C(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 F?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 lr=1e5,ht=new rt(lr),ft=new rt(lr);class nt extends m.Disposable{constructor(){super(...arguments);C(this,"_currentLexerNode",new F);C(this,"_upLevel",0);C(this,"_segment","");C(this,"_bracketState",[]);C(this,"_squareBracketState",0);C(this,"_bracesState",0);C(this,"_singleQuotationState",0);C(this,"_doubleQuotationState",0);C(this,"_lambdaState",!1);C(this,"_colonState",!1);C(this,"_tableBracketState",!1)}dispose(){this._resetTemp(),this._currentLexerNode.dispose(),ht.clear(),ft.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!==he&&!Ct(u)&&a.getStartIndex()!==-1){const c=a.getChildren().indexOf(o);return{functionName:u,paramIndex:c}}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 c=i[o];if(typeof c=="string"||c.nodeType!==q.REFERENCE){a.push(c);continue}const{token:l}=c,f=m.deserializeRangeWithSheet(l),{range:_,sheetName:E,unitId:A}=f,g=m.Rectangle.moveOffset(_,t,n);let p="";m.isValidRange(g)?p=m.serializeRangeToRefString({range:g,unitId:A,sheetName:E}):p=h.REF,a.push({...c,token:p})}return`=${cr(a)}`}checkIfAddBracket(e){let t=0,n=e.length-1,i=e[n];for(;i===L.CLOSE_BRACKET||i===" ";)i===L.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(),c=0;for(;u;){const l=u.getToken();l!==he&&l!==L.COLON&&u.getStartIndex()!==-1&&(t===0?c+=1:t--),u=u.getParent()}return c}sequenceNodesBuilder(e){const t=ft.get(e);if(t)return[...t];const n=this._getSequenceArray(e);if(n.length===0)return;const i=this.getSequenceNode(n);return ft.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:c,currentString:l,cur:f}=o;if(l===L.DOUBLE_QUOTATION&&(n=!0),(c!==""||i===0)&&i!==a-1){t.push(l);continue}let _=(u==null?void 0:u.segment)||"";const E=i-_.length;let A=i-1;const g=i-1;if(i===a-1&&this._isLastMergeString(l)&&(_+=l,A+=1),_===""||Ve.has(_)){t.push(l);continue}const p=_.trim(),S=this._replacePrefixString(p);n===!0&&p[p.length-1]===L.DOUBLE_QUOTATION?(n=!1,this._pushSequenceNode(t,{nodeType:q.STRING,token:_,startIndex:E,endIndex:A},g)):new RegExp(yt).test(S)?this._pushSequenceNode(t,{nodeType:q.REFERENCE,token:_,startIndex:E,endIndex:A},g):m.Tools.isStringNumber(p)?this._pushSequenceNode(t,{nodeType:q.NUMBER,token:_,startIndex:E,endIndex:A},g):p.length>0&&this._pushSequenceNode(t,{nodeType:q.FUNCTION,token:_,startIndex:E,endIndex:A},g),(i!==a-1||!this._isLastMergeString(l))&&t.push(l)}return this._mergeSequenceNodeReference(t)}_getCurrentParamIndex(e,t){return this._nodeMaker(e,void 0,t)}_isLastMergeString(e){return e===L.DOUBLE_QUOTATION||m.Tools.isStringNumber(e)||!Ct(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()===L.CLOSE_BRACES&&o!=null&&typeof o!="string"&&o.nodeType===q.FUNCTION&&o.token.trim().substring(0,1)===L.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===L.COLON&&typeof a!="string"&&u!=null&&typeof u!="string"&&Br((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 l=ht.get(e);if(l)return l}this._resetCurrentLexerNode(),this._currentLexerNode.setToken(ie);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:l,sequenceString:f}=n(i);o=l,u=f}if(o&&(this._resetCurrentLexerNode(),this._currentLexerNode.setToken(ie),a=this._nodeMaker(`=${u}`),a===h.VALUE))return a;const c=this._getTopNode(this._currentLexerNode);return c&&(this._currentLexerNode=c),t&&(this._suffixExpressionHandler(this._currentLexerNode),ht.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 c=0;c<n;c++){const l=t[c];if(l instanceof F)this._suffixExpressionHandler(l),i.push(l);else{const f=l.trim();if(f==="")continue;if(Oe.has(f)){for(;a.length>0;){const _=(o=a[a.length-1])==null?void 0:o.trim();if(!_||_===L.OPEN_BRACKET)break;const E=Ve.get(_),A=Ve.get(f);if(!E||!A)break;if(A>E)i.push(a.pop());else break}a.push(l)}else if(f===L.OPEN_BRACKET)a.push(l);else if(f===L.CLOSE_BRACKET)for(;a.length>0;){const _=(u=a[a.length-1])==null?void 0:u.trim();if(!_)break;if(_===L.OPEN_BRACKET){a.pop();break}i.push(a.pop())}else i.push(l)}}for(;a.length>0;)i.push(a.pop());e.setChildren(i)}_resetCurrentLexerNode(){this._currentLexerNode=new F}_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 F)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,c;const e=(n=this._currentLexerNode)==null?void 0:n.getParent();let t=!1;if(e&&e.getToken()===Se){if((i=e==null?void 0:e.getParent())!=null&&i.getParent()){const l=(o=(a=this._currentLexerNode.getParent())==null?void 0:a.getParent())==null?void 0:o.getParent();l&&(this._currentLexerNode=l),t=!0}}else if(e!=null&&e.getParent()){const l=(u=this._currentLexerNode.getParent())==null?void 0:u.getParent();l&&(this._currentLexerNode=l),t=!0}for(let l=0;l<this._upLevel;l++){const f=(c=this._currentLexerNode)==null?void 0:c.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 F)&&this.isColonOpen()){const i=new F;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 F;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!!(Oe.has(e)||e===L.OPEN_BRACKET||e===L.COMMA||e==="")}_getSequenceArray(e){const t=[];return this._nodeMaker(e,t),t}_resetTemp(){this._currentLexerNode=new F,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===L.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 c=i[o+1];if(c&&c===L.CLOSE_BRACKET){if(!this._setParentCurrentLexerNode()&&o!==a-1)return h.VALUE;o++}else c&&this._newAndPushCurrentLexerNode(he,o)}else this._pushNodeToChildren(u),this._openBracket(0);else if(u===L.CLOSE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()){this._pushNodeToChildren(this._segment),this._resetSegment();const c=this._getCurrentBracket();if(c===0)this._pushNodeToChildren(u);else if(c===1){const l=i[o+1];if(l&&l===L.OPEN_BRACKET){if(!this._setParentCurrentLexerNode()&&o!==a-1)return h.VALUE;this._newAndPushCurrentLexerNode(Se,o,!0),this._openLambda()}else if(!this._setAncestorCurrentLexerNode()&&o!==a-1)return h.VALUE}else return h.VALUE;this._closeBracket()}else if(u===L.OPEN_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(u),this._openBraces();else if(u===L.CLOSE_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(u),this._pushNodeToChildren(this._segment),this._resetSegment(),this._closeBraces();else if(u===L.OPEN_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._segment.length>0&&this._openTableBracket(),this._pushSegment(u),this._openSquareBracket();else if(u===L.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===L.DOUBLE_QUOTATION&&this.isSingleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){if(this.isDoubleQuotationClose())this._openDoubleQuotation();else{const c=i[o+1];c&&c===L.DOUBLE_QUOTATION?o++:this._closeDoubleQuotation()}this._pushSegment(u)}else if(u===L.SINGLE_QUOTATION&&this.isDoubleQuotationClose()){if(this.isSingleQuotationClose())this._openSingleQuotation();else{const c=i[o+1];c&&c===L.SINGLE_QUOTATION?o++:this._closeSingleQuotation()}this._pushSegment(u)}else if(u===L.COMMA&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const c=this._getCurrentBracket();if(c===1||c==null){if(this._pushNodeToChildren(this._segment),this._resetSegment(),!this._setParentCurrentLexerNode()&&o!==a-1&&c!=null)return h.VALUE;this._newAndPushCurrentLexerNode(he,o)}else return h.VALUE}else if(u===L.COLON&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const c=new F;c.setToken(u);const l=new F;l.setToken(he),l.setParent(c);const f=new F;f.setToken(he),f.setParent(c),c.getChildren().push(l,f);let _=c,E=0;if(this._segmentCount()>0){let A,g,p=0;const S=this._segment.trim(),D=S[0],w=S[1];if(D===v.MINUS&&(A=new F,A.setToken(v.MINUS),p++),(D===v.AT||w===v.AT)&&(g=new F,g.setToken(v.AT),A&&(A.addChildren(g),g.setParent(A)),p++),p>0&&(this._segment=S.slice(p)),E=p,g)if(g.addChildren(c),c.setParent(g),g.getParent()){const Q=g.getParent();Q&&(_=Q)}else _=g;else A&&(_=A,A.addChildren(c),c.setParent(A));const y=new F;y.setToken(this._segment),y.setParent(l),l.getChildren().push(y),this._resetSegment()}else{const A=this._getLastChildCurrentLexerNode();A&&A.changeToParent(l)}this._setCurrentLexerNode(_),this._currentLexerNode=f,this._openColon(E)}else if(wr.has(u)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){this._pushNodeToChildren(this._segment);const c=new F;c.setToken(u);const l=this._getLastChildCurrent();l instanceof F?l.changeToParent(c):l!==!1&&(c.getChildren().push(l),this._removeLastChild()),this._pushNodeToChildren(c),c.setParent(this._currentLexerNode),this._resetSegment()}else if(Oe.has(u)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){let c=this._segment.trim();if(u===G.MINUS&&c===""){const l=this._findPreviousToken(i,o-1)||"";if(this._negativeCondition(l)){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&&c===""?c=this._segment:(this._pushNodeToChildren(this._segment),c="");if(u===G.LESS_THAN||u===G.GREATER_THAN){const l=i[o+1];l&&Oe.has(u+l)?(this._pushNodeToChildren(c+u+l),o++):this._pushNodeToChildren(c+u)}else this._pushNodeToChildren(c+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 jr=Object.defineProperty,Qr=Object.getOwnPropertyDescriptor,Gr=(s,r,e,t)=>{for(var n=t>1?void 0:t?Qr(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&&jr(r,e,n),n},kt=(s,r)=>(e,t)=>r(e,t,s);exports.FormulaDataModel=class extends m.Disposable{constructor(e,t){super();C(this,"_formulaData",{});C(this,"_arrayFormulaRange",{});C(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 c,l;const a=n[i],o=(l=(c=this._arrayFormulaRange)==null?void 0:c[t])==null?void 0:l[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,_)=>{var D;const E=(D=o==null?void 0:o[f])==null?void 0:D[_];if(E==null)return!0;const{startRow:A,startColumn:g,endRow:p,endColumn:S}=E;for(let w=A;w<=p;w++)for(let y=g;y<=S;y++)u.setValue(w,y,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((c,l)=>{const f=o==null?void 0:o.getValue(c,l);if(f==null)return!0;const{startRow:_,startColumn:E,endRow:A,endColumn:g}=f;for(let p=_;p<=A;p++)for(let S=E;S<=g;S++)u.setValue(p,S,null)}),a.forValue((c,l,f)=>{u.setValue(c,l,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,c,l)=>{o.setValue(u,c,l)}),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();hr(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={},c={};for(const l of o){const f=l.getSheetId(),_=l.getConfig();u[f]={cellData:new m.ObjectMatrix(_.cellData),rowCount:_.rowCount,columnCount:_.columnCount},c[l.getName()]=l.getSheetId()}t[a]=u,n[a]=c}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 c=u[e];c[t]==null&&(c[t]={});const l=new m.ObjectMatrix(c[t]);i.forValue((f,_,E)=>{const A=(E==null?void 0:E.f)||"",g=(E==null?void 0:E.si)||"",p=m.isFormulaString(A),S=m.isFormulaId(g);if(p&&S)l.setValue(f,_,{f:A,si:g}),a.set(g,{f:A,r:f,c:_});else if(p&&!S)l.setValue(f,_,{f:A});else if(!p&&S)l.setValue(f,_,{f:"",si:g});else if(!p&&!S&&l.getValue(f,_)){const D=l.getValue(f,_),w=(D==null?void 0:D.f)||"",y=(D==null?void 0:D.si)||"";m.isFormulaString(w)&&m.isFormulaId(y)&&o.set(y,w),l.realDeleteValue(f,_)}}),l.forValue((f,_,E)=>{const A=(E==null?void 0:E.f)||"",g=(E==null?void 0:E.si)||"";if(m.isFormulaId(g)){const p=a.get(g),S=o.get(g);if(p&&!m.isFormulaString(A)){const D=p.f,w=_-p.c,y=f-p.r;l.setValue(f,_,{f:D,si:g,x:w,y})}else if(typeof S=="string"){const D=E.x||0,w=E.y||0,y=this._lexerTreeBuilder.moveFormulaRefOffset(S,D,w);o.set(g,{r:f,c:_,f:y}),l.setValue(f,_,{f:y,si:g})}else if(typeof S=="object"){const D=_-S.c,w=f-S.r;l.setValue(f,_,{f:S.f,si:g,x:D,y:w})}}})}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((c,l,f)=>{const{f:_,si:E,x:A=0,y:g=0}=f;if(E===e&&_.length>0&&A===0&&g===0)return u=f,!1}),u}getFormulaDataItem(e,t,n,i){var a,o,u,c;return(c=(u=(o=(a=this._formulaData)==null?void 0:a[i])==null?void 0:o[n])==null?void 0:u[e])==null?void 0:c[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,c,l)=>{const f=(l==null?void 0:l.f)||"",_=(l==null?void 0:l.si)||"",E=(l==null?void 0:l.x)||0,A=(l==null?void 0:l.y)||0;m.isFormulaString(f)&&m.isFormulaId(_)&&E===0&&A===0&&n.set(_,{f,r:u,c})}),n}};exports.FormulaDataModel=Gr([kt(0,m.IUniverInstanceService),kt(1,b.Inject(nt))],exports.FormulaDataModel);function hr(s,r,e,t){const n=new Map,i=new m.ObjectMatrix;t.forValue((a,o,u)=>{const c=(u==null?void 0:u.f)||"",l=(u==null?void 0:u.si)||"",f=m.isFormulaString(c),_=m.isFormulaId(l);f&&_?(i.setValue(a,o,{f:c,si:l}),n.set(l,{f:c,r:a,c:o})):f&&!_?i.setValue(a,o,{f:c}):!f&&_&&i.setValue(a,o,{f:"",si:l})}),i.forValue((a,o,u)=>{const c=(u==null?void 0:u.f)||"",l=(u==null?void 0:u.si)||"";if(m.isFormulaId(l)&&!m.isFormulaString(c)){const f=n.get(l);if(f){const _=f.f,E=o-f.c,A=a-f.r;i.setValue(a,o,{f:_,si:l,x:E,y:A})}}}),s[r][e]=i.getData()}const Hr=s=>{const r=s.get(exports.FormulaDataModel),e=m.Tools.deepClone(r.getArrayFormulaRange()),t=m.Tools.deepClone(r.getArrayFormulaCellData());return{arrayFormulaRange:e,arrayFormulaCellData:t}},He={id:"formula.mutation.set-array-formula-data",type:m.CommandType.MUTATION,handler:(s,r)=>{const e=s.get(exports.FormulaDataModel);return e.setArrayFormulaRange(r.arrayFormulaRange),e.setArrayFormulaCellData(r.arrayFormulaCellData),!0}},st={id:"formula.mutation.set-defined-name",type:m.CommandType.MUTATION,handler:()=>!0},it={id:"formula.mutation.remove-defined-name",type:m.CommandType.MUTATION,handler:()=>!0},Tt={id:"formula.mutation.set-feature-calculation",type:m.CommandType.MUTATION,handler:()=>!0},bt={id:"formula.mutation.remove-feature-calculation",type:m.CommandType.MUTATION,handler:()=>!0},Lt={id:"formula.mutation.set-formula-calculation-start",type:m.CommandType.MUTATION,handler:()=>!0},wt={id:"formula.mutation.set-formula-calculation-stop",type:m.CommandType.MUTATION,handler:()=>!0},Ye={id:"formula.mutation.set-formula-calculation-notification",type:m.CommandType.MUTATION,handler:()=>!0},Ot={id:"formula.mutation.set-formula-calculation-result",type:m.CommandType.MUTATION,handler:()=>!0},Ut={id:"formula.mutation.set-formula-data",type:m.CommandType.MUTATION,handler:(s,r)=>(s.get(exports.FormulaDataModel).setFormulaData(r.formulaData),!0)},It={id:"formula.mutation.set-other-formula",type:m.CommandType.MUTATION,handler:()=>!0},Mt={id:"formula.mutation.remove-other-formula",type:m.CommandType.MUTATION,handler:()=>!0},fr={id:"formula.mutation.set-super-table",type:m.CommandType.MUTATION,handler:()=>!0},_r={id:"formula.mutation.remove-super-table",type:m.CommandType.MUTATION,handler:()=>!0},xt={id:"formula.mutation.set-super-table-option",type:m.CommandType.MUTATION,handler:()=>!0};class dr extends m.Disposable{isError(){return!1}isAsyncObject(){return!1}isReferenceObject(){return!1}isValueObject(){return!1}isEqualType(r){return!1}}var ge=(s=>(s.FALSE="FALSE",s.TRUE="TRUE",s))(ge||{}),de=(s=>(s[s.SUCCESS=0]="SUCCESS",s[s.ERROR=1]="ERROR",s))(de||{}),fe=(s=>(s.ALL="#All",s.DATA="#Data",s.HEADERS="#Headers",s.TOTALS="#Totals",s))(fe||{}),X=(s=>(s[s.FRONT=0]="FRONT",s[s.BACK=1]="BACK",s))(X||{});class Yr{constructor(){C(this,"_cache",new Map);C(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 c=u.get(n);c==null&&(c=[],u.set(n,c)),c.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,c;const i=(c=(u=this._continueBuildingCache.get(r))==null?void 0:u.get(e))==null?void 0:c.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 c,l;const a=(l=(c=this._continueBuildingCache.get(r))==null?void 0:c.get(e))==null?void 0:l.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 _e=new Yr;function qr(){return new Intl.Collator(void 0,{numeric:!0}).compare}function zr(s){return s.indexOf("*")>-1||s.indexOf("?")>-1}function $t(s,r){const e=r.replace(/~?[*?]/g,n=>n.startsWith("~")?`\\${n.substring(1)}`:n==="*"?".*":n==="?"?".":n);return new RegExp(`^${e}$`).test(s)}function jt(s){return s.replace(/~?[*?]/g,r=>r.startsWith("~")?r.substring(1):" ")}function Xr(s,r,e){let t=!1;switch(e){case R.EQUALS:t=$t(s,r);break;case R.GREATER_THAN:case R.GREATER_THAN_OR_EQUAL:t=$t(s,r)||s>jt(r);break;case R.LESS_THAN:case R.LESS_THAN_OR_EQUAL:t=s<jt(r);break}return t}class Ee extends dr{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}isError(){return!1}isNull(){return!1}getNegative(){return d.create(h.NAME)}getReciprocal(){return d.create(h.NAME)}plus(r){return d.create(h.NAME)}minus(r){return d.create(h.NAME)}multiply(r){return d.create(h.NAME)}divided(r){return d.create(h.NAME)}map(r){return d.create(h.NAME)}product(r,e){return e(this,r)}compare(r,e){return d.create(h.NAME)}wildcard(r,e){return d.create(h.NAME)}isEqual(r){return this.compare(r,R.EQUALS)}isNotEqual(r){return this.compare(r,R.NOT_EQUAL)}isGreaterThanOrEqual(r){return this.compare(r,R.GREATER_THAN_OR_EQUAL)}isLessThanOrEqual(r){return this.compare(r,R.LESS_THAN_OR_EQUAL)}isLessThan(r){return this.compare(r,R.LESS_THAN)}isGreaterThan(r){return this.compare(r,R.GREATER_THAN)}concatenateFront(r){return d.create(h.NAME)}concatenateBack(r){return d.create(h.NAME)}plusBy(r){return d.create(h.NAME)}minusBy(r){return d.create(h.NAME)}multiplyBy(r){return d.create(h.NAME)}dividedBy(r){return d.create(h.NAME)}compareBy(r,e){return d.create(h.NAME)}concatenate(r,e=X.FRONT){let t=this.getValue().toString();if(typeof r=="string")e===X.FRONT?t=r+t:t+=r;else if(typeof r=="number")e===X.FRONT?t=r.toString()+t:t+=r.toString();else if(typeof r=="boolean"){const n=r?"TRUE":"FALSE";e===X.FRONT?t=n+t:t+=n}return t}pow(r){return d.create(h.VALUE)}powInverse(r){return d.create(h.VALUE)}sqrt(){return d.create(h.VALUE)}cbrt(){return d.create(h.VALUE)}cos(){return d.create(h.VALUE)}acos(){return d.create(h.VALUE)}acosh(){return d.create(h.VALUE)}sin(){return d.create(h.VALUE)}asin(){return d.create(h.VALUE)}asinh(){return d.create(h.VALUE)}tan(){return d.create(h.VALUE)}tanh(){return d.create(h.VALUE)}atan(){return d.create(h.VALUE)}atan2(r){return d.create(h.VALUE)}atan2Inverse(r){return d.create(h.VALUE)}atanh(){return d.create(h.VALUE)}mean(){return this}median(){return this}var(){return this}std(){return this}log(){return d.create(h.VALUE)}log10(){return d.create(h.VALUE)}exp(){return d.create(h.VALUE)}abs(){return d.create(h.VALUE)}round(r){return d.create(h.VALUE)}roundInverse(r){return d.create(h.VALUE)}floor(r){return d.create(h.VALUE)}floorInverse(r){return d.create(h.VALUE)}ceil(r){return d.create(h.VALUE)}ceilInverse(r){return d.create(h.VALUE)}}class d extends Ee{constructor(r,e=""){super(r),this._errorType=r,this._errorContent=e}static create(r,e){return new d(r,e)}getErrorType(){return this._errorType}getErrorContent(){return this._errorContent}isEqualType(r){return r.getErrorType()===this.getErrorType()}isError(){return!0}}var Kr=20,Wr=1,Ce=1e6,Qt=1e6,Zr=-7,Jr=21,en=!1,xe="[big.js] ",Ne=xe+"Invalid ",at=Ne+"decimal places",tn=Ne+"rounding mode",mr=xe+"Division by zero",O={},W=void 0,rn=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function gr(){function s(r){var e=this;if(!(e instanceof s))return r===W?gr():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(Ne+"value");r=r===0&&1/r<0?"-0":String(r)}nn(e,r)}e.constructor=s}return s.prototype=O,s.DP=Kr,s.RM=Wr,s.NE=Zr,s.PE=Jr,s.strict=en,s.roundDown=0,s.roundHalfUp=1,s.roundHalfEven=2,s.roundUp=3,s}function nn(s,r){var e,t,n;if(!rn.test(r))throw Error(Ne+"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 Ae(s,r,e,t){var n=s.c;if(e===W&&(e=s.constructor.RM),e!==0&&e!==1&&e!==2&&e!==3)throw Error(tn);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]!==W))),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]!==W||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 Te(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(at);if(!n[0])throw Error(mr);if(!t[0])return s.s=i,s.c=[s.e=0],s;var o,u,c,l,f,_=n.slice(),E=o=n.length,A=t.length,g=t.slice(0,o),p=g.length,S=s,D=S.c=[],w=0,y=a+(S.e=r.e-s.e)+1;for(S.s=i,i=y<0?0:y,_.unshift(0);p++<o;)g.push(0);do{for(c=0;c<10;c++){if(o!=(p=g.length))l=o>p?1:-1;else for(f=-1,l=0;++f<o;)if(n[f]!=g[f]){l=n[f]>g[f]?1:-1;break}if(l<0){for(u=p==o?n:_;p;){if(g[--p]<u[p]){for(f=p;f&&!g[--f];)g[f]=9;--g[f],g[p]+=10}g[p]-=u[p]}for(;!g[0];)g.shift()}else break}D[w++]=l?c:++c,g[0]&&l?g[p]=t[E]||0:g=[t[E]]}while((E++<A||g[0]!==W)&&i--);return!D[0]&&w!=1&&(D.shift(),S.e--,y--),w>y&&Ae(S,y,e.RM,g[0]!==W),S};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 c=i.c.slice(),l=i.e,f=s.c,_=s.e;if(!c[0]||!f[0])return f[0]?s.s=-u:c[0]?s=new a(i):s.s=1,s;if(o=l-_){for((n=o<0)?(o=-o,t=c):(_=l,t=f),t.reverse(),u=o;u--;)t.push(0);t.reverse()}else for(e=((n=c.length<f.length)?c:f).length,o=u=0;u<e;u++)if(c[u]!=f[u]){n=c[u]<f[u];break}if(n&&(t=c,c=f,f=t,s.s=-s.s),(u=(e=f.length)-(r=c.length))>0)for(;u--;)c[r++]=0;for(u=r;e>o;){if(c[--e]<f[e]){for(r=e;r&&!c[--r];)c[r]=9;--c[r],c[e]+=10}c[e]-=f[e]}for(;c[--u]===0;)c.pop();for(;c[0]===0;)c.shift(),--_;return c[0]||(s.s=1,c=[_=0]),s.c=c,s.e=_,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(mr);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,c=s.c;if(!o[0]||!c[0])return c[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=c):(r=-r,t=o),t.reverse();r--;)t.push(0);t.reverse()}for(o.length-c.length<0&&(t=c,c=o,o=t),r=c.length,e=0;r;o[r]%=10)e=(o[--r]=o[r]+c[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<-Qt||s>Qt)throw Error(Ne+"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(Ne+"precision");return Ae(new this.constructor(this),s,r)};O.round=function(s,r){if(s===W)s=0;else if(s!==~~s||s<-Ce||s>Ce)throw Error(at);return Ae(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(xe+"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 Ae(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,c=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+c,a<o&&(r=n,n=i,i=r,c=a,a=o,o=c),r=new Array(c=a+o);c--;)r[c]=0;for(u=o;u--;){for(o=0,c=a+u;c>u;)o=r[c]+i[u]*n[c-u-1]+o,r[c--]=o%10,o=o/10|0;r[c]=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!==W){if(s!==~~s||s<0||s>Ce)throw Error(at);for(e=Ae(new e.constructor(e),++s,r);e.c.length<s;)e.c.push(0)}return Te(e,!0,!!t)};O.toFixed=function(s,r){var e=this,t=e.c[0];if(s!==W){if(s!==~~s||s<0||s>Ce)throw Error(at);for(e=Ae(new e.constructor(e),s+e.e+1,r),s=s+e.e+1;e.c.length<s;)e.c.push(0)}return Te(e,!1,!!t)};O[Symbol.for("nodejs.util.inspect.custom")]=O.toJSON=O.toString=function(){var s=this,r=s.constructor;return Te(s,s.e<=r.NE||s.e>=r.PE,!!s.c[0])};O.toNumber=function(){var s=Number(Te(this,!0,!0));if(this.constructor.strict===!0&&!this.eq(s.toString()))throw Error(xe+"Imprecise conversion");return s};O.toPrecision=function(s,r){var e=this,t=e.constructor,n=e.c[0];if(s!==W){if(s!==~~s||s<1||s>Ce)throw Error(Ne+"precision");for(e=Ae(new t(e),s,r);e.c.length<s;)e.c.push(0)}return Te(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(xe+"valueOf disallowed");return Te(s,s.e<=r.NE||s.e>=r.PE,!0)};var k=gr();function Et(s){let r;switch(s){case R.EQUALS:r=R.EQUALS;break;case R.GREATER_THAN:r=R.LESS_THAN;break;case R.GREATER_THAN_OR_EQUAL:r=R.LESS_THAN_OR_EQUAL;break;case R.LESS_THAN:r=R.GREATER_THAN;break;case R.LESS_THAN_OR_EQUAL:r=R.GREATER_THAN_OR_EQUAL;break;case R.NOT_EQUAL:r=R.NOT_EQUAL;break}return r}function vt(s,r){return k(s).times(r).toNumber()}function Gt(s,r){const e=10**Math.floor(r);return Math.round(vt(s,e))/e}function Ht(s,r){const e=10**Math.floor(r);return Math.floor(vt(s,e))/e}function Yt(s,r){const e=10**Math.floor(r);return Math.ceil(vt(s,e))/e}function qt(s,r){return s**r}class Cr extends Ee{isNull(){return!0}plus(r){return new N(0,!0).plus(r)}minus(r){return new N(0,!0).minus(r)}multiply(r){return new N(0,!0).multiply(r)}divided(r){return new N(0,!0).divided(r)}compare(r,e){return r.isString()?new $("").compare(r,e):r.isBoolean()?new j(!1).compare(r,e):new N(0,!0).compare(r,e)}concatenateFront(r){return r.isArray()?r.concatenateBack(new $("")):new $(this.concatenate(r.getValue(),X.FRONT))}concatenateBack(r){return r.isArray()?r.concatenateFront(new $("")):new $(this.concatenate(r.getValue(),X.BACK))}plusBy(r){return new N(0).plusBy(r)}minusBy(r){return new N(0).minusBy(r)}multiplyBy(r){return new N(0).multiplyBy(r)}dividedBy(r){return new N(0).dividedBy(r)}compareBy(r,e){return typeof r=="string"?new $("").compareBy(r,e):typeof r=="boolean"?new j(!1).compareBy(r,e):new N(0,!0).compareBy(r,e)}pow(r){return new N(0,!0).pow(r)}sqrt(){return new N(0,!0)}cbrt(){return new N(0,!0)}cos(){return new N(0,!0)}acos(){return new N(0,!0)}acosh(){return new N(0,!0)}sin(){return new N(0,!0)}asin(){return new N(0,!0)}asinh(){return new N(0,!0)}tan(){return new N(0,!0)}tanh(){return new N(0,!0)}atan(){return new N(0,!0)}atan2(r){return new N(0,!0).atan2(r)}atanh(){return new N(0,!0)}log(){return d.create(h.NUM)}log10(){return d.create(h.NUM)}exp(){return d.create(h.NUM)}abs(){return d.create(h.NUM)}round(r){return new N(0,!0).round(r)}floor(r){return new N(0,!0).floor(r)}ceil(r){return new N(0,!0).ceil(r)}}class j extends Ee{constructor(e,t=!1){super(e);C(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===ge.TRUE?this._value=!0:n===ge.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 N(-t,!0)}getReciprocal(){return this.getValue()?new N(1,!0):d.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 N(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 N extends Ee{constructor(e,t=!1){super(e);C(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 N(0).minus(this)}getReciprocal(){return new N(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 $(this.concatenate(e.getValue(),X.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new $(this.concatenate(e.getValue(),X.BACK))}compare(e,t){return e.isArray()?e.compare(this,Et(t)):this.compareBy(e.getValue(),t)}plusBy(e){const t=this.getValue();if(typeof e=="string")return d.create(h.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return d.create(h.NUM);const n=k(t).plus(e).toNumber();return Number.isFinite(n)?new N(n):d.create(h.NUM)}return typeof e=="boolean"?new N(k(t).plus(e?1:0).toNumber()):this}minusBy(e){const t=this.getValue();if(typeof e=="string")return d.create(h.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return d.create(h.NUM);const n=k(t).minus(e).toNumber();return Number.isFinite(n)?new N(n):d.create(h.NUM)}return typeof e=="boolean"?new N(k(t).minus(e?1:0).toNumber()):this}multiplyBy(e){const t=this.getValue();if(typeof e=="string")return d.create(h.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return d.create(h.NUM);const n=k(t).times(e).toNumber();return Number.isFinite(n)?new N(n):d.create(h.NUM)}return typeof e=="boolean"?new N(k(t).times(e?1:0).toNumber()):this}dividedBy(e){const t=this.getValue();if(typeof e=="string")return d.create(h.VALUE);if(typeof e=="number"){if(e===0)return d.create(h.DIV_BY_ZERO);if(!Number.isFinite(t)||!Number.isFinite(e))return d.create(h.NUM);const n=k(t).div(e).toNumber();return Number.isFinite(n)?new N(n):d.create(h.NUM)}return typeof e=="boolean"?e===!1?d.create(h.DIV_BY_ZERO):new N(k(t).div(1).toNumber()):this}compareBy(e,t){const n=this.getValue();let i=!1;if(typeof e=="string")switch(t){case R.EQUALS:case R.GREATER_THAN:case R.GREATER_THAN_OR_EQUAL:i=!1;break;case R.LESS_THAN:case R.LESS_THAN_OR_EQUAL:case R.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 R.EQUALS:i=k(n).eq(e);break;case R.GREATER_THAN:i=k(n).gt(e);break;case R.GREATER_THAN_OR_EQUAL:i=k(n).gte(e);break;case R.LESS_THAN:i=k(n).lt(e);break;case R.LESS_THAN_OR_EQUAL:i=k(n).lte(e);break;case R.NOT_EQUAL:i=!k(n).eq(e);break}else if(typeof e=="boolean")switch(t){case R.EQUALS:case R.GREATER_THAN:case R.GREATER_THAN_OR_EQUAL:i=!1;break;case R.LESS_THAN:case R.LESS_THAN_OR_EQUAL:case R.NOT_EQUAL:i=!0;break}return new j(i)}pow(e){if(e.isArray())return e.powInverse(this);const t=this.getValue(),n=e.getValue();if(typeof n=="string")return d.create(h.VALUE);if(typeof n=="number"){if(!Number.isFinite(t)||!Number.isFinite(n))return d.create(h.NUM);const i=qt(t,n);return Number.isFinite(i)?new N(i):d.create(h.NUM)}return typeof n=="boolean"?new N(qt(t,n?1:0)):this}sqrt(){const e=this.getValue();if(!Number.isFinite(e))return d.create(h.NUM);const t=k(e).sqrt().toNumber();return Number.isFinite(t)?new N(t):d.create(h.NUM)}cbrt(){const e=this.getValue();if(!Number.isFinite(e))return d.create(h.NUM);const t=Math.cbrt(e);return Number.isFinite(t)?new N(t):d.create(h.NUM)}cos(){const e=this.getValue();if(!Number.isFinite(e))return d.create(h.NUM);const t=Math.cos(e);return Number.isFinite(t)?new N(t):d.create(h.NUM)}acos(){const e=this.getValue();if(!Number.isFinite(e))return d.create(h.NUM);const t=Math.acos(e);return Number.isNaN(t)?d.create(h.NUM):new N(t)}acosh(){const e=this.getValue();if(!Number.isFinite(e))return d.create(h.NUM);const t=Math.acosh(e);return Number.isNaN(t)?d.create(h.NUM):new N(t)}sin(){const e=this.getValue();if(!Number.isFinite(e))return d.create(h.NUM);const t=Math.sin(e);return Number.isFinite(t)?new N(t):d.create(h.NUM)}asin(){const e=this.getValue();if(!Number.isFinite(e))return d.create(h.NUM);const t=Math.asin(e);return Number.isNaN(t)?d.create(h.NUM):new N(t)}asinh(){const e=this.getValue();if(!Number.isFinite(e))return d.create(h.NUM);const t=Math.asinh(e);return Number.isNaN(t)?d.create(h.NUM):new N(t)}tan(){const e=this.getValue();if(!Number.isFinite(e))return d.create(h.NUM);const t=Math.tan(e);return Number.isFinite(t)?new N(t):d.create(h.NUM)}tanh(){const e=this.getValue();if(!Number.isFinite(e))return d.create(h.NUM);const t=Math.tanh(e);return Number.isFinite(t)?new N(t):d.create(h.NUM)}atan(){const e=this.getValue();if(!Number.isFinite(e))return d.create(h.NUM);const t=Math.atan(e);return Number.isFinite(t)?new N(t):d.create(h.NUM)}atan2(e){if(e.isArray())return e.atan2Inverse(this);const t=this.getValue(),n=e.getValue();if(typeof n=="string")return d.create(h.VALUE);if(typeof n=="number"){if(!Number.isFinite(t)||!Number.isFinite(n))return d.create(h.NUM);const i=Math.atan2(t,n);return Number.isFinite(i)?new N(i):d.create(h.NUM)}return typeof n=="boolean"?new N(Math.atan2(t,n?1:0)):this}atanh(){const e=this.getValue();if(!Number.isFinite(e))return d.create(h.NUM);const t=Math.atanh(e);return Number.isFinite(t)?new N(t):d.create(h.NUM)}log(){const e=this.getValue();if(typeof e=="number"&&e<=0||!Number.isFinite(e))return d.create(h.NUM);const t=Math.log(e);return Number.isFinite(t)?new N(t):d.create(h.NUM)}log10(){const e=this.getValue();if(typeof e=="number"&&e<=0||!Number.isFinite(e))return d.create(h.NUM);const t=Math.log10(e);return Number.isFinite(t)?new N(t):d.create(h.NUM)}exp(){const e=this.getValue();if(!Number.isFinite(e))return d.create(h.NUM);const t=Math.exp(e);return Number.isFinite(t)?new N(t):d.create(h.NUM)}abs(){const e=this.getValue();if(!Number.isFinite(e))return d.create(h.NUM);const t=Math.abs(e);return Number.isFinite(t)?new N(t):d.create(h.NUM)}round(e){if(e.isArray())return e.roundInverse(this);const t=this.getValue(),n=e.getValue();if(typeof n=="string")return d.create(h.VALUE);if(typeof n=="number"){if(!Number.isFinite(t)||!Number.isFinite(n))return d.create(h.NUM);const i=Gt(t,n);return Number.isFinite(i)?new N(i):d.create(h.NUM)}return typeof n=="boolean"?new N(Gt(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 d.create(h.VALUE);if(typeof n=="number"){if(!Number.isFinite(t)||!Number.isFinite(n))return d.create(h.NUM);const i=Ht(t,n);return Number.isFinite(i)?new N(i):d.create(h.NUM)}return typeof n=="boolean"?new N(Ht(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 d.create(h.VALUE);if(typeof n=="number"){if(!Number.isFinite(t)||!Number.isFinite(n))return d.create(h.NUM);const i=Yt(t,n);return Number.isFinite(i)?new N(i):d.create(h.NUM)}return typeof n=="boolean"?new N(Yt(t,n?1:0)):this}_compareInfinity(e,t,n){let i=!1;switch(n){case R.EQUALS:i=e===t;break;case R.GREATER_THAN:i=e>t;break;case R.GREATER_THAN_OR_EQUAL:i=e>=t;break;case R.LESS_THAN:i=e<t;break;case R.LESS_THAN_OR_EQUAL:i=e<=t;break;case R.NOT_EQUAL:i=e!==t;break}return i}}class $ extends Ee{constructor(e,t=!1){super(e);C(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 $(this.concatenate(e.getValue(),X.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new $(this.concatenate(e.getValue(),X.BACK))}compare(e,t){return e.isArray()?e.compare(this,Et(t)):this.compareBy(e.getValue(),t)}wildcard(e,t){return e.isArray()?e.wildcard(this,Et(t)):this._checkWildcard(e.getValue(),t)}compareBy(e,t){const n=this.getValue();let i=!1;if(typeof e=="string")switch(t){case R.EQUALS:i=n===e;break;case R.GREATER_THAN:i=n>e;break;case R.GREATER_THAN_OR_EQUAL:i=n>=e;break;case R.LESS_THAN:i=n<e;break;case R.LESS_THAN_OR_EQUAL:i=n<=e;break;case R.NOT_EQUAL:i=n!==e;break}else if(typeof e=="number")switch(t){case R.EQUALS:case R.GREATER_THAN:case R.GREATER_THAN_OR_EQUAL:i=!0;break;case R.LESS_THAN:case R.LESS_THAN_OR_EQUAL:case R.NOT_EQUAL:i=!1;break}else if(typeof e=="boolean")switch(t){case R.EQUALS:case R.GREATER_THAN:case R.GREATER_THAN_OR_EQUAL:i=!1;break;case R.LESS_THAN:case R.LESS_THAN_OR_EQUAL:case R.NOT_EQUAL:i=!0;break}return new j(i)}_checkWildcard(e,t){const n=this.getValue().toLocaleLowerCase(),i=Xr(n,e,t);return new j(i)}}function sn(s){return""}function an(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 Ee{constructor(e){var r=(...args)=>{super(...args);C(this,"_value",[]);C(this,"_rowCount",-1);C(this,"_columnCount",-1);C(this,"_unitId","");C(this,"_sheetId","");C(this,"_currentRow",-1);C(this,"_currentColumn",-1)};if(typeof e=="string")r(e);else{const t=sn();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 c=i;c<=a;c++)if(e(o[u][c],u,c)===!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 N(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),c=this.get(a,o);u.isError()||u.getValue()===!0&&i[0].push(c)}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,c=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,c=t[2]||1);const l=[],f=this._value;let _=0,E=0;for(let A=n;A<=i;A+=a){E=0,l[_]==null&&(l[_]=[]);for(let g=o;g<=u;g+=c)l[_][E]=f[A][g],E++;_++}return this._createNewArray(l,l.length,l[0].length)}sum(){let e=new N(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 N(-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 N(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 N(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 N(0);return this.iterator(t=>{if(t==null||t.isNull())return!0;e=e.plusBy(1)}),e}countBlank(){let e=new N(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 c=[];for(let l=0;l<n;l++){const f=(o=(a=this._value)==null?void 0:a[u])==null?void 0:o[l];f?f.isError()?c[l]=f:c[l]=e(f,u,l):c[l]=d.create(h.VALUE)}i.push(c)}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.count();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 N(2,!0))}return e.get(0,(t-1)/2)}var(){const e=this.flatten(),t=this.mean();let n=null;const i=[];return e.iterator((a,o,u)=>{let c=null;if(a&&a.isError())return n=!0,!1;a==null?c=new N(0):c=a.minus(t).pow(new N(2,!0)),i[o]==null&&(i[o]=[]),i[o][u]=c}),n?d.create(h.VALUE):new se("").mean()}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 an(this._value)}_sort(e){const t=qr();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 c=e.getRowCount(),l=e.getColumnCount();if(a=Math.max(c,a),o=Math.max(l,o),c===1&&l===1){const f=e.getFirstCell();for(let _=0;_<o;_++)i.push(f)}else if(c===1&&this._columnCount>1){const f=e.getArrayValue();for(let _=0;_<o;_++)i.push(f[0][_])}else return this._batchOperatorArray(e,t,n)}else for(let c=0;c<o;c++)i.push(e);const u=[];for(let c=0;c<o;c++){const l=i[c];this._batchOperatorValue(l,c,u,t,n)}return this._createNewArray(u,a,o)}_batchOperatorValue(e,t,n,i,a){var E,A;const o=this._rowCount;let u=!1;const c=this.getUnitId(),l=this.getSheetId(),f=this.getCurrentRow(),_=this.getCurrentColumn();if(i===4&&(u=_e.canUseCache(c,l,t+_,f,f+o-1),u===!0)){if(a===R.EQUALS){const g=_e.getCellPositions(c,l,t+_,e.getValue());if(g!=null)for(let p=0;p<o;p++)n[p]==null&&(n[p]=[]),g.includes(p+f)?n[p][t]=new j(!0):n[p][t]=new j(!1)}else{const g=_e.getCellValuePositions(c,l,t+_);g!=null&&g.forEach((p,S)=>{let D;if(typeof S=="string"?D=new $(S):typeof S=="number"?D=new N(S):typeof S=="boolean"&&(D=new j(S)),D==null)return!0;if(D.compare(e,a))for(let y=0;y<o;y++)n[y]==null&&(n[y]=[]),p.includes(y+f)?n[y][t]=new j(!0):n[y][t]=new j(!1)})}return}_e.setContinueBuildingCache(c,l,t+_,f,f+o-1);for(let g=0;g<o;g++){const p=(A=(E=this._value)==null?void 0:E[g])==null?void 0:A[t];if(n[g]==null&&(n[g]=[]),p&&e)if(p.isError())n[g][t]=p;else if(e.isError())n[g][t]=d.create(h.VALUE);else switch(i){case 1:n[g][t]=p.plus(e);break;case 0:n[g][t]=p.minus(e);break;case 2:n[g][t]=p.multiply(e);break;case 3:n[g][t]=p.divided(e);break;case 4:a?n[g][t]=p.compare(e,a):n[g][t]=d.create(h.VALUE);break;case 5:n[g][t]=p.concatenateFront(e);break;case 6:n[g][t]=p.concatenateBack(e);break;case 7:a?n[g][t]=p.product(e,a):n[g][t]=d.create(h.VALUE);break;case 8:a?n[g][t]=p.wildcard(e,a):n[g][t]=d.create(h.VALUE);break;case 9:n[g][t]=p.pow(e);break;case 10:n[g][t]=p.round(e);break;case 11:n[g][t]=p.floor(e);break;case 13:n[g][t]=p.atan2(e);break;case 12:n[g][t]=p.ceil(e);break}else n[g][t]=d.create(h.NA);p!=null&&(p.isError()?_e.set(c,l,t+_,p.getErrorType(),g+f):_e.set(c,l,t+_,p.getValue(),g+f))}}_batchOperatorArray(e,t,n){var f,_,E,A,g,p,S,D,w,y,Q,re;let i=e.getRowCount(),a=e.getColumnCount();i<this._rowCount&&(i=this._rowCount),a<this._columnCount&&(a=this._columnCount);const o=[],u=e.getArrayValue(),c=this._checkArrayCalculateType(this),l=this._checkArrayCalculateType(e);for(let Y=0;Y<i;Y++){const I=[];for(let U=0;U<a;U++){let M;c===3?M=(_=(f=this._value)==null?void 0:f[0])==null?void 0:_[0]:c===1?M=(A=(E=this._value)==null?void 0:E[0])==null?void 0:A[U]:c===2?M=(p=(g=this._value)==null?void 0:g[Y])==null?void 0:p[0]:M=(D=(S=this._value)==null?void 0:S[Y])==null?void 0:D[U];let x;if(l===3?x=(w=u==null?void 0:u[0])==null?void 0:w[0]:l===1?x=(y=u==null?void 0:u[0])==null?void 0:y[U]:l===2?x=(Q=u==null?void 0:u[Y])==null?void 0:Q[0]:x=(re=u==null?void 0:u[Y])==null?void 0:re[U],M&&x)if(M.isError())I[U]=M;else if(x.isError())I[U]=x;else switch(t){case 1:I[U]=M.plus(x);break;case 0:I[U]=M.minus(x);break;case 2:I[U]=M.multiply(x);break;case 3:I[U]=M.divided(x);break;case 4:n?I[U]=M.compare(x,n):I[U]=d.create(h.VALUE);break;case 5:I[U]=M.concatenateFront(x);break;case 6:I[U]=M.concatenateBack(x);break;case 7:n?I[U]=M.product(x,n):I[U]=d.create(h.VALUE);break;case 8:n?I[U]=M.wildcard(x,n):I[U]=d.create(h.VALUE);break;case 9:I[U]=M.pow(x);break;case 10:I[U]=M.round(x);break;case 13:I[U]=M.atan2(x);break;case 11:I[U]=M.floor(x);break;case 12:I[U]=M.ceil(x);break}else I[U]=d.create(h.NA)}o.push(I)}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 c=t[o].split(","),l=c.length;a<l&&(a=l);const f=[];for(let _=0;_<l;_++){const E=c[_].trim();f.push(De.create(E))}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 De{static create(r){if(typeof r=="boolean")return new j(r,!0);if(typeof r=="string"){const e=r.toLocaleUpperCase();return e===ge.TRUE||e===ge.FALSE?new j(e):m.isRealNum(r)?new N(r):new RegExp(Vr,"g").test(r)?new se(r):new $(r)}return typeof r=="number"?Number.isFinite(r)?new N(r,!0):d.create(h.NUM):d.create(h.NA)}}const on=1e5,Nt=new rt(on);class be extends dr{constructor(e){super();C(this,"_forcedSheetId","");C(this,"_forcedSheetName","");C(this,"_defaultSheetId","");C(this,"_rangeData",{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1});C(this,"_unitData",{});C(this,"_rowCount",0);C(this,"_columnCount",0);C(this,"_defaultUnitId","");C(this,"_forcedUnitId","");C(this,"_runtimeData",{});C(this,"_arrayFormulaCellData",{});C(this,"_runtimeArrayFormulaCellData",{});C(this,"_runtimeFeatureCellData",{});C(this,"_refOffsetX",0);C(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 d(h.VALUE),t,i);for(let o=t;o<=n;o++)for(let u=i;u<=a;u++){const c=o+this._refOffsetY,l=u+this._refOffsetX;if(c<0||l<0)return e(new d(h.REF),o,u);const f=this.getCellData(c,l);let _=!1;if(f==null||m.isNullCell(f)){_=e(null,o,u);continue}const E=this.getCellValueObject(f);if(_=e(E,o,u),_===!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 N(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 d.create(h.REF)}unionRange(e,t){return{startRow:-1,startColumn:-1,endRow:-1,endColumn:-1}}getCellValueObject(e){const t=e.v||0;return br.has(t)?d.create(t):e.t===m.CellValueType.NUMBER?new N(t):e.t===m.CellValueType.STRING||e.t===m.CellValueType.FORCE_STRING?new $(t):e.t===m.CellValueType.BOOLEAN?new j(t):De.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 c=u.getValue(e,t);if(c!=null)return c}}getCellByPosition(e,t){e||(e=this._rangeData.startRow),t||(t=this._rangeData.startColumn);const n=this.getCellData(e,t);return n?this.getCellValueObject(n):d.create(h.VALUE)}toArrayValueObject(){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=Nt.get(a);if(o)return o;const u=t-e+1,c=i-n+1,l=new Array(u);this.iterator((E,A,g)=>{const p=A-e,S=g-n;l[p]||(l[p]=new Array(c)),E==null&&(E=new Cr(0)),l[p][S]=E});const f={calculateValueList:l,rowCount:l.length,columnCount:l[0].length,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:e,column:n},_=new se(f);return Nt.set(a,_),_}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 pr extends be{constructor(r,e,t){super(""),this.setRangeData(r),e&&this.setForcedSheetIdDirect(e),t&&this.setForcedUnitIdDirect(t)}isRange(){return!0}}var un=(s=>{})();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 d.create(h.VALUE)}checkArrayType(r){return r.isReferenceObject()||r.isValueObject()&&r.isArray()}}var ot=(s=>(s.CONCATENATE="CONCATENATE",s))(ot||{}),cn=(s=>{})(),ln=(s=>{})(),hn=(s=>{})(),fn=(s=>{})(),_n=(s=>{})(),dn=(s=>{})(),mn=(s=>{})(),qe=(s=>(s.INDIRECT="INDIRECT",s.OFFSET="OFFSET",s))(qe||{}),me=(s=>(s.SUM="SUM",s.SUMIF="SUMIF",s.SUMIFS="SUMIFS",s.POWER="POWER",s))(me||{}),ne=(s=>(s.AVERAGE="AVERAGE",s.COUNT="COUNT",s.MAX="MAX",s.MIN="MIN",s.COUNTA="COUNTA",s))(ne||{}),gn=(s=>{})(),Cn=(s=>{})(),pn=(s=>{})();class En extends m.Disposable{constructor(){super(...arguments);C(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 ut=b.createIdentifier("univer.formula.defined-names.service");var Nn=Object.defineProperty,An=Object.getOwnPropertyDescriptor,Rn=(s,r,e,t)=>{for(var n=t>1?void 0:t?An(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&&Nn(r,e,n),n},Sn=(s,r)=>(e,t)=>r(e,t,s);let At=class extends m.Disposable{constructor(r){super();C(this,"_unitData",{});C(this,"_arrayFormulaCellData",{});C(this,"_formulaData",{});C(this,"_sheetNameMap",{});C(this,"_forceCalculate",!1);C(this,"_dirtyRanges",[]);C(this,"_dirtyNameMap",{});C(this,"_dirtyUnitFeatureMap",{});C(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=ar(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 c of a){const l=c.getSheetId(),f=c.getConfig();o[l]={cellData:new m.ObjectMatrix(f.cellData),rowCount:f.rowCount,columnCount:f.columnCount},u[c.getName()]=c.getSheetId()}e[i]=o,t[i]=u}return{allUnitData:e,unitSheetNameMap:t}}};At=Rn([Sn(0,m.IUniverInstanceService)],At);const Le=b.createIdentifier("univer.formula.current-data.service");var Dn=Object.defineProperty,yn=Object.getOwnPropertyDescriptor,Fn=(s,r,e,t)=>{for(var n=t>1?void 0:t?yn(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&&Dn(r,e,n),n},Tn=(s,r)=>(e,t)=>r(e,t,s),K=(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))(K||{}),Re=(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))(Re||{});let Rt=class extends m.Disposable{constructor(r){super();C(this,"_formulaExecuteStage",0);C(this,"_stopState",!1);C(this,"_currentRow",0);C(this,"_currentColumn",0);C(this,"_currentSubComponentId","");C(this,"_currentUnitId","");C(this,"_runtimeData",{});C(this,"_runtimeOtherData",{});C(this,"_unitArrayFormulaRange",{});C(this,"_runtimeArrayFormulaCellData",{});C(this,"_runtimeClearArrayFormulaCellData",{});C(this,"_runtimeFeatureRange",{});C(this,"_runtimeFeatureCellData",{});C(this,"_functionsExecutedState",0);C(this,"_functionDefinitionPrivacyVar",new Map);C(this,"_totalFormulasToCalculate",0);C(this,"_completedFormulasCount",0);C(this,"_totalArrayFormulasToCalculate",0);C(this,"_completedArrayFormulasCount",0);C(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 c=this._runtimeArrayFormulaCellData[i];c[n]==null&&(c[n]=new m.ObjectMatrix),this._runtimeClearArrayFormulaCellData[i]===void 0&&(this._runtimeClearArrayFormulaCellData[i]={});const l=this._runtimeClearArrayFormulaCellData[i];l[n]==null&&(l[n]=new m.ObjectMatrix);const f=a[n],_=c[n],E=l[n];if(r.isReferenceObject()||r.isValueObject()&&r.isArray()){const A=r,{startRow:g,startColumn:p,endRow:S,endColumn:D}=A.getRangePosition();if(g===S&&p===D){const y=this._objectValueToCellValue(A.getFirstCell());f.setValue(e,t,y),E.setValue(e,t,y);return}const w={startRow:e,startColumn:t,endRow:S-g+e,endColumn:D-p+t};if(this._checkIfArrayFormulaRangeHasData(i,n,e,t,w)){const y=this._objectValueToCellValue(new d(h.SPILL));f.setValue(e,t,y),E.setValue(e,t,y)}else{const y=new d(h.SPILL);A.iterator((Q,re,Y)=>{const I=this._objectValueToCellValue(Q);if(re===g&&Y===p){if(Q!=null&&Q.isError()&&Q.isEqualType(y))return E.setValue(e,t,{}),f.setValue(e,t,{...this._objectValueToCellValue(y)}),!1;f.setValue(e,t,{...I})}_.setValue(re-g+e,Y-p+t,I)}),u.setValue(e,t,w),o[n]=u.getData()}}else{const A=this._objectValueToCellValue(r);f.setValue(e,t,A),E.setValue(e,t,A)}}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,_,E,A,g,p;const{startRow:a,startColumn:o,endRow:u,endColumn:c}=i,l=this._currentConfigService.getUnitData();for(let S=a;S<=u;S++)for(let D=o;D<=c;D++){if(S===t&&n===D)continue;const w=(E=(_=(f=this._runtimeData)==null?void 0:f[r])==null?void 0:_[e])==null?void 0:E.getValue(S,D),y=(p=(g=(A=l==null?void 0:l[r])==null?void 0:A[e])==null?void 0:g.cellData)==null?void 0:p.getValue(S,D);if((!m.isNullCell(w)||!m.isNullCell(y))&&this._isInDirtyRange(r,e,S,D))return!0}return!1}_isInDirtyRange(r,e,t,n){const i=this._currentConfigService.getDirtyRanges();return nr(i,r,e,t,n)}};Rt=Fn([Tn(0,Le)],Rt);const Z=b.createIdentifier("univer.formula.runtime.service");var bn=Object.defineProperty,Ln=Object.getOwnPropertyDescriptor,wn=(s,r,e,t)=>{for(var n=t>1?void 0:t?Ln(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&&bn(r,e,n),n},_t=(s,r)=>(e,t)=>r(e,t,s);let pe=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:c,token:l}=u;if(c===q.REFERENCE||c===q.FUNCTION){const f=(i=this._definedNamesService.getDefinedNameMap(r))==null?void 0:i.get(l);f?(t+=f,n=!0):t+=l}else t+=l}return{sequenceString:t,hasDefinedName:n}}};pe=wn([_t(0,ut),_t(1,Z),_t(2,b.Inject(nt))],pe);var T=(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))(T||{});const J=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();C(this,"_children",[]);C(this,"_parent");C(this,"_valueObject");C(this,"_calculateState",!1);C(this,"_async",!1);C(this,"_address",!1);C(this,"_refOffsetX",0);C(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 T.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(){}setRefOffset(e=0,t=0){this._refOffsetX=e,this._refOffsetY=t}getRefOffset(){return{x:this._refOffsetX,y:this._refOffsetY}}async executeAsync(){return Promise.resolve(de.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 P extends H{constructor(e){super(e);C(this,"_errorValueObject");this._errorValueObject=d.create(e)}get nodeType(){return T.ERROR}static create(e){return new P(e)}getValue(){return this._errorValueObject}}const ee=100;class te extends m.Disposable{get zIndex(){return 0}create(r,e,t){let n;return r instanceof F?n=r.getToken():n=r,new H(n)}checkAndCreateNodeType(r){}}class St extends H{get nodeType(){return T.ROOT}execute(){const e=this.getChildren()[0];this.setValue(e.getValue())}}class Er extends te{get zIndex(){return J.get(T.ROOT)||ee}checkAndCreateNodeType(r){if(!(r instanceof F))return;if(r.getToken()===ie)return new St(ie)}}var B=(s=>(s.COMPARE="COMPARE",s.DIVIDED="DIVIDED",s.MINUS="MINUS",s.MULTIPLY="MULTIPLY",s.PLUS="PLUS",s.UNION="UNION",s))(B||{});class Nr extends m.Disposable{constructor(){super(...arguments);C(this,"_functionExecutors",new Map);C(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 ue=b.createIdentifier("univer.formula.function.service");var On=Object.defineProperty,Un=Object.getOwnPropertyDescriptor,In=(s,r,e,t)=>{for(var n=t>1?void 0:t?Un(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&&On(r,e,n),n},zt=(s,r)=>(e,t)=>r(e,t,s);class ze extends H{constructor(r,e,t){super(e),this._accessor=r,this._operatorString=e,this._functionExecutor=t}get nodeType(){return T.PREFIX}execute(){const e=this.getChildren()[0].getValue();let t;if(e==null)throw new Error("object is null");this._operatorString===v.MINUS?t=this._functionExecutor.calculate(new N(0),e):this._operatorString===v.AT?t=this._handlerAT(e):t=d.create(h.VALUE),this.setValue(t)}_handlerAT(r){if(!r.isReferenceObject())return d.create(h.VALUE);const e=r;if(e.isCell())return d.create(h.VALUE);const t=this._accessor.get(Z),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():d.create(h.VALUE)}}let Xe=class extends te{constructor(s,r){super(),this._functionService=s,this._injector=r}get zIndex(){return J.get(T.PREFIX)||ee}checkAndCreateNodeType(s){if(!(s instanceof F))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=B.MINUS;else return e===v.AT?new ze(this._injector,e):void 0;const n=this._functionService.getExecutor(t);return n?new ze(this._injector,e,n):(console.error(`No function ${r}`),P.create(h.NAME))}};Xe=In([zt(0,ue),zt(1,b.Inject(b.Injector))],Xe);var Mn=Object.defineProperty,xn=Object.getOwnPropertyDescriptor,vn=(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&&Mn(r,e,n),n},Xt=(s,r)=>(e,t)=>r(e,t,s);class Pn extends H{constructor(r,e){super(r),this._functionExecutor=e,this._functionExecutor.isAsync()&&this.setAsync(),this._functionExecutor.isAddress()&&this.setAddress()}get nodeType(){return T.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&&r.push(a)}const n=this._functionExecutor.calculate(...r);return n.isAsyncObject()?this.setValue(await n.getValue()):this.setValue(n),Promise.resolve(de.SUCCESS)}execute(){const r=[],e=this.getChildren(),t=e.length;for(let i=0;i<t;i++){const a=e[i].getValue();a!=null&&r.push(a)}const n=this._functionExecutor.calculate(...r);this.setValue(n)}}let Ke=class extends te{constructor(s,r){super(),this._functionService=s,this._injector=r}get zIndex(){return J.get(T.FUNCTION)||ee}create(s){const r=this._functionService.getExecutor(s);return r?new Pn(s,r):(console.error(`No function ${s}`),P.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(B.MINUS);t=new ze(this._injector,v.MINUS,o),a++}if(new RegExp(v.AT,"g").test(i)&&(n=new ze(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}}};Ke=vn([Xt(0,ue),Xt(1,b.Inject(b.Injector))],Ke);function Ar(s){return s instanceof F?s.getToken()===Se:!1}function Vn(s){return s instanceof F?s.getToken()===ur:!1}var Bn=Object.defineProperty,kn=Object.getOwnPropertyDescriptor,$n=(s,r,e,t)=>{for(var n=t>1?void 0:t?kn(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&&Bn(r,e,n),n},jn=(s,r)=>(e,t)=>r(e,t,s);const Qn="LAMBDA";class Gn extends H{constructor(r,e){super(r),this._lambdaId=e}get nodeType(){return T.LAMBDA}isFunctionParameter(){return this._lambdaId===null}getLambdaId(){return this._lambdaId}execute(){const r=this.getChildren(),e=r.length;this.setValue(r[e-1].getValue())}}let We=class extends te{constructor(s){super(),this._runtimeService=s}get zIndex(){return J.get(T.LAMBDA)||ee}create(s){const r=s.getChildren(),e=r[0];let t=r.slice(1,-1);const n=r[r.length-1];if(!(e instanceof F&&n instanceof F))return P.create(h.NAME);if(e.getToken()===Se){const o=e.getChildren();if(t.length!==o.length)return P.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 F){const c=u.getChildren()[0];u.setToken(ur),a.set(c.trim(),void 0)}else return P.create(h.VALUE)}return this._runtimeService.registerFunctionDefinitionPrivacyVar(i,a),this._updateLambdaStatement(n,i,a),new Gn(s.getToken(),i)}checkAndCreateNodeType(s){if(!(!(s instanceof F)||s.getToken().trim().toUpperCase()!==Qn))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(!(Ar(i)&&a!==0))if(o instanceof F)this._updateTree(o,r,e);else{const u=o.trim();if(e.has(u)){const c=new F;c.setToken(Ft),c.setLambdaId(r),c.setLambdaPrivacyVar(e),c.setLambdaParameter(u),t[a]=c}}}}};We=$n([jn(0,Z)],We);class Hn 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 T.LAMBDA_PARAMETER}execute(){const r=this._getRootLexerNode(this._currentLambdaPrivacyVar.get(this._lambdaParameter));r?this.setValue(r.getValue()):this.setValue(d.create(h.SPILL))}_getRootLexerNode(r){if(!r)return;if(r.getToken()!==Ft)return r;const e=r,t=e.getCurrentLambdaPrivacyVar(),n=e.getLambdaParameter();if(t)return this._getRootLexerNode(t.get(n))}}class Rr extends te{get zIndex(){return J.get(T.LAMBDA_PARAMETER)||ee}create(r){const e=r.getFunctionDefinitionPrivacyVar(),t=r.getLambdaParameter();return e?new Hn(r.getToken(),t,e):new P(h.SPILL)}checkAndCreateNodeType(r){if(!(!(r instanceof F)||r.getToken().trim()!==Ft))return this.create(r)}}class Yn extends H{constructor(r){super(r),this._operatorString=r}get nodeType(){return T.NULL}execute(){this.setValue(new Cr(0))}}var qn=Object.defineProperty,zn=Object.getOwnPropertyDescriptor,Xn=(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},Kn=(s,r)=>(e,t)=>r(e,t,s);class Wn extends H{constructor(r,e){super(r),this._operatorString=r,this._functionExecutor=e}get nodeType(){return T.OPERATOR}execute(){const r=this.getChildren();this._functionExecutor.name===B.COMPARE&&this._functionExecutor.setCompareType(this.getToken());const e=r[0].getValue(),t=r[1].getValue();if(e==null||t==null)throw new Error("object1 or object2 is null");this.setValue(this._functionExecutor.calculate(e,t))}}let Ze=class extends te{constructor(s){super(),this._functionService=s}get zIndex(){return J.get(T.OPERATOR)||ee}create(s){let r="";const e=s;e===G.PLUS?r=B.PLUS:e===G.MINUS?r=B.MINUS:e===G.MULTIPLY?r=B.MULTIPLY:e===G.DIVIDED?r=B.DIVIDED:e===G.CONCATENATE?r=ot.CONCATENATE:e===G.POWER?r=me.POWER:Lr.has(e)&&(r=B.COMPARE);const t=this._functionService.getExecutor(r);return t?new Wn(e,t):(console.error(`No function ${s}`),P.create(h.NAME))}checkAndCreateNodeType(s){if(s instanceof F)return;const r=s.trim();if(!(r.charAt(0)==='"'&&r.charAt(r.length-1)==='"')&&Oe.has(r))return this.create(r)}};Ze=Xn([Kn(0,ue)],Ze);class Zn extends m.Disposable{constructor(){super(...arguments);C(this,"_tableMap",new Map);C(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 Pt=b.createIdentifier("univer.formula.super-table.service");class Vt extends be{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 d.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 pr(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 Jn extends be{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 d.create(h.REF);const e=r;if(e.getForcedSheetName()!==void 0)return d.create(h.REF);const t=this.getRangeData();if(t.endColumn!==-1)return d.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 es extends be{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 d.create(h.REF);const e=r;if(e.getForcedSheetName()!==void 0)return d.create(h.REF);const t=this.getRangeData();if(t.endRow!==-1)return d.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 ts extends be{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),c=u.startColumn,l=u.endColumn,f=u.type;let _=-1,E=-1;const A=a.startRow,g=a.startColumn;f===fe.ALL?(_=A,E=g):f===fe.DATA?(_=A+1,E=g):f===fe.HEADERS?(_=A,E=A):f===fe.TOTALS&&(_=g,E=g),this.setRangeData({startColumn:c,endColumn:l,startRow:_,endRow:E})}isTable(){return!0}_stringToColumnData(r,e,t){r=r.substring(1,-1);const n=r.indexOf(L.COMMA);let i=-1,a=-1,o=fe.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),c=r.substring(n+1),l=this._columnHandler(c,e,!0);i=l.startColumn,a=l.endColumn,o=t.get(u),o||(o=fe.ALL)}return{startColumn:i,endColumn:a,type:o}}_columnHandler(r,e,t=!1){let n=-1,i=-1;const a=r.indexOf(L.COLON);if(new RegExp(or,"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 rs=Object.defineProperty,ns=Object.getOwnPropertyDescriptor,ss=(s,r,e,t)=>{for(var n=t>1?void 0:t?ns(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&&rs(r,e,n),n},we=(s,r)=>(e,t)=>r(e,t,s);class ve extends H{constructor(r,e,t){super(e),this._accessor=r,this._operatorString=e,this._referenceObject=t}get nodeType(){return T.REFERENCE}execute(){const r=this._accessor.get(Le),e=this._accessor.get(Z);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 Je=class extends te{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 J.get(T.REFERENCE)||ee}checkAndCreateNodeType(s){let r=!1,e;if(s instanceof F?(r=!0,e=s.getToken().trim()):e=s.trim(),!r&&e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;if(new RegExp(yt).test(e))return new ve(this._injector,e,new Vt(e));if(r&&new RegExp(vr).test(e))return new ve(this._injector,e,new es(e));if(r&&new RegExp(Pr).test(e))return new ve(this._injector,e,new Jn(e));const t=this._formulaRuntimeService.currentUnitId,n=this._superTableService.getTableMap(t),i=new RegExp(or,"g"),a=e.replace(i,"");if(!r&&(n!=null&&n.has(a))){const o=i.exec(e);let u="";o&&(u=o[0]);const c=n.get(a),l=this._superTableService.getTableOptionMap();return new ve(this._injector,e,new ts(e,c,u,l))}}};Je=ss([we(0,ut),we(1,Pt),we(2,Z),we(3,b.Inject(pe)),we(4,b.Inject(b.Injector))],Je);var is=Object.defineProperty,as=Object.getOwnPropertyDescriptor,os=(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&&is(r,e,n),n},Kt=(s,r)=>(e,t)=>r(e,t,s);class Wt extends H{constructor(r,e,t){super(e),this._accessor=r,this._operatorString=e,this._functionExecutor=t}get nodeType(){return T.SUFFIX}execute(){const e=this.getChildren()[0].getValue();let t;if(e==null)throw new Error("object is null");this._operatorString===ae.PERCENTAGE?t=this._functionExecutor.calculate(e,new N(100)):this._operatorString===ae.POUND?t=this._handlerPound(e):t=d.create(h.VALUE),this.setValue(t)}_handlerPound(r){var l,f,_,E;if(!r.isReferenceObject()||!r.isCell())return d.create(h.VALUE);const e=this._accessor.get(Le),t=this._accessor.get(pe),n=r,i=n.getRangeData(),a=n.getUnitId(),o=n.getSheetId(),u=e.getFormulaData(),c=(E=(_=(f=(l=u==null?void 0:u[a])==null?void 0:l[o])==null?void 0:f[i.startRow])==null?void 0:_[i.startColumn])==null?void 0:E.f;return c&&t.treeBuilder(c),d.create(h.VALUE)}}let et=class extends te{constructor(s,r){super(),this._functionService=s,this._injector=r}get zIndex(){return J.get(T.SUFFIX)||ee}checkAndCreateNodeType(s){if(!(s instanceof F))return;const r=s.getToken().trim();if(r.charAt(0)==='"'&&r.charAt(r.length-1)==='"')return;let e="";if(r===ae.PERCENTAGE)e=B.DIVIDED;else return r===ae.POUND?new Wt(this._injector,r):void 0;const t=this._functionService.getExecutor(e);return t?new Wt(this._injector,r,t):(console.error(`No function ${s}`),P.create(h.NAME))}};et=os([Kt(0,ue),Kt(1,b.Inject(b.Injector))],et);var us=Object.defineProperty,cs=Object.getOwnPropertyDescriptor,ls=(s,r,e,t)=>{for(var n=t>1?void 0:t?cs(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},hs=(s,r)=>(e,t)=>r(e,t,s);class fs extends H{constructor(r,e){super(r),this._operatorString=r,this._functionExecutor=e}get nodeType(){return T.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===L.COLON?n=this._functionExecutor.calculate(e,t):n=d.create(h.NAME),this.setValue(n)}}let tt=class extends te{constructor(s){super(),this._functionService=s}get zIndex(){return J.get(T.UNION)||ee}create(s){const r=this._functionService.getExecutor(B.UNION);return r?new fs(s,r):(console.error(`No function ${s}`),P.create(h.NAME))}checkAndCreateNodeType(s){if(!(s instanceof F))return;const e=s.getToken().trim();if(!(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')&&e===L.COLON)return this.create(e)}};tt=ls([hs(0,ue)],tt);class _s extends H{constructor(r){super(r),this._operatorString=r}get nodeType(){return T.VALUE}execute(){this.setValue(De.create(this._operatorString))}}class Sr extends te{get zIndex(){return J.get(T.VALUE)||ee}_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===ge.TRUE||e===ge.FALSE)return this.create(e)}else return this.create(r)}create(r){return new _s(r)}checkAndCreateNodeType(r){if(!(r instanceof F))return this._checkValueNode(r)}}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},z=(s,r)=>(e,t)=>r(e,t,s);let Ie=class extends m.Disposable{constructor(r,e,t,n,i,a,o,u,c,l,f){super();C(this,"_astNodeFactoryList",[]);C(this,"_refOffsetX",0);C(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=c,this._unionNodeFactory=l,this._valueNodeFactory=f,this._initializeAstNode()}dispose(){this._astNodeFactoryList.forEach(r=>{r.dispose()}),this._astNodeFactoryList=[]}parse(r,e=0,t=0){const n=new St(ie);return this._refOffsetX=e,this._refOffsetY=t,this._parse(r,n)}_lambdaParameterHandler(r,e){const t=e.getLambdaId(),n=new St(ie),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 _=o[f];if(_ instanceof F)this._parse(_,n);else return!1}const c=n.getChildren(),l=c.length;for(let f=0;f<l;f++){const _=c[f];i.set(a[f],_)}return n.setParent(e),e}_changeLetToLambda(r){const e=r.getChildren(),t=e.length;if(t%2!==1||t===0)return;const n=new F;n.setToken($r);const i=new F;i.setToken(Se);const a=[...e];for(let u=0;u<t;u++){const c=a[u];if(!(c instanceof F))return;u%2===0?c.changeToParent(n):c.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===kr){const l=this._changeLetToLambda(r);return l!=null?this._parse(l,e):P.create(h.ERROR)}if(o===he){if(a=e,n===0)return new Yn(ie).setParent(e),a}else{if(o===Se){let l=this._lambdaParameterHandler(r,e);return l===!1&&(l=P.create(h.ERROR)),l}if(a=this._checkAstNode(r),a==null)return P.create(h.ERROR)}const u=t[0];for(let l=0;l<n;l++){const f=t[l];if(Ar(u)){if(l!==0&&l!==n-1)continue}else if(Vn(f)&&l!==n-1)continue;let _=null;if(f instanceof F){if(_=this._parse(f,a),_===a)continue}else _=this._checkAstNode(f);if(_==null)return P.create(h.ERROR);if(_=this._getTopParent(_),_==null)return;switch(_.nodeType){case T.ERROR:return _;case T.FUNCTION:i.push(_);break;case T.LAMBDA:i.push(_);break;case T.LAMBDA_PARAMETER:i.push(_);break;case T.OPERATOR:{const E=i.pop(),A=i.pop();if(A)A.setParent(_);else return P.create(h.ERROR);if(E)E.setParent(_);else return P.create(h.ERROR);i.push(_);break}case T.REFERENCE:_.setRefOffset(this._refOffsetX,this._refOffsetY),i.push(_);break;case T.ROOT:i.push(_);break;case T.UNION:i.push(_);break;case T.VALUE:i.push(_);break;case T.PREFIX:i.push(_);break;case T.SUFFIX:i.push(_);break}}const c=i.length;for(let l=0;l<c;l++)i[l].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)}};Ie=gs([z(0,Z),z(1,b.Inject(Er)),z(2,b.Inject(Ke)),z(3,b.Inject(We)),z(4,b.Inject(Rr)),z(5,b.Inject(Ze)),z(6,b.Inject(Xe)),z(7,b.Inject(Je)),z(8,b.Inject(et)),z(9,b.Inject(tt)),z(10,b.Inject(Sr))],Ie);class Dr extends m.Disposable{constructor(){super(...arguments);C(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 ct=b.createIdentifier("univer.formula.feature-calculation-manager.service");class yr extends m.Disposable{constructor(){super(...arguments);C(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 Bt=b.createIdentifier("univer.formula.other-formula-manager.service");var Cs=Object.defineProperty,ps=Object.getOwnPropertyDescriptor,Es=(s,r,e,t)=>{for(var n=t>1?void 0:t?ps(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&&Cs(r,e,n),n},Ns=(s,r)=>(e,t)=>r(e,t,s);let Me=class extends m.Disposable{constructor(s){super(),this._runtimeService=s}dispose(){}async executeAsync(s){if(!s)return d.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 d.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(de.ERROR);const r=s.getChildren(),e=r.length;for(let t=0;t<e;t++){const n=r[t];this._executeAsync(n)}return s.nodeType===T.FUNCTION&&s.isAsync()?await s.executeAsync():s.execute(),Promise.resolve(de.SUCCESS)}_execute(s){if(this._runtimeService.isStopExecution())return de.ERROR;const r=s.getChildren(),e=r.length;for(let t=0;t<e;t++){const n=r[t];this._execute(n)}return s.execute(),de.SUCCESS}};Me=Es([Ns(0,Z)],Me);class dt extends m.Disposable{constructor(){super(...arguments);C(this,"node");C(this,"children",[]);C(this,"parents",[]);C(this,"formula","");C(this,"row",-1);C(this,"column",-1);C(this,"subComponentId","");C(this,"unitId","");C(this,"rangeList",[]);C(this,"formulaId");C(this,"featureId");C(this,"getDirtyData");C(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 c=this.rangeList[o],{unitId:l,sheetId:f,range:_}=c;if(!e.has(l))continue;const E=e.get(l);if(!E.has(f))continue;const A=E.get(f),g=(i=n==null?void 0:n[l])==null?void 0:i[f];for(const p of A){const{startRow:S,startColumn:D,endRow:w,endColumn:y}=p;if(!(_.startRow>w||_.endRow<S||_.startColumn>y||_.endColumn<D)){let Q=!0;if(g==null||g.forValue((re,Y)=>{if(re>=_.startRow&&re<=_.endRow&&Y>=_.startColumn&&Y<=_.endColumn)return Q=!1,!1}),Q)return!0}}if(((a=t[l])==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 As=Object.defineProperty,Rs=Object.getOwnPropertyDescriptor,Ss=(s,r,e,t)=>{for(var n=t>1?void 0:t?Rs(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&&As(r,e,n),n},ce=(s,r)=>(e,t)=>r(e,t,s);const Ds=1e5,mt=new rt(Ds);let Ue=class extends m.Disposable{constructor(r,e,t,n,i,a,o){super();C(this,"_updateRangeFlattenCache",new Map);C(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(),mt.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 c of u)new m.ObjectMatrix(o[c]).forValue((f,_,E)=>{if(E==null)return!0;const{f:A,x:g,y:p}=E,S=this._generateAstNode(A,g,p),D=new dt;D.node=S,D.formula=A,D.unitId=a,D.subComponentId=c,D.row=f,D.column=_,i.push(D)})}for(const a of n){const o=e[a],u=Object.keys(o);for(const c of u){const l=o[c],f=Object.keys(l);for(const _ of f){const E=l[_],{f:A}=E,g=this._generateAstNode(A),p=new dt;p.node=g,p.formula=A,p.unitId=a,p.subComponentId=c,p.formulaId=_,i.push(p)}}}this._featureCalculationManagerService.getReferenceExecutorMap().forEach((a,o)=>{const{unitId:u,subComponentId:c,dependencyRanges:l,getDirtyData:f}=a,_=new dt;_.unitId=u,_.subComponentId=c,_.getDirtyData=f,_.featureId=o,_.rangeList=l,i.push(_)});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 c=await this._getRangeListByNode(u.node);for(let l=0,f=c.length;l<f;l++)u.pushRangeList(c[l])}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=mt.get(`${r}##${e}${t}`);if(n)return n;const i=this._lexer.treeBuilder(r);if(i in h)return P.create(i);if(n=this._astTreeBuilder.parse(i,e,t),n==null)throw new Error("astNode is null");return mt.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===T.UNION||r.nodeType===T.PREFIX&&r.getToken()===v.AT||r.nodeType===T.SUFFIX&&r.getToken()===ae.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===T.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===T.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],c=(await this._executeNode(o)).toUnitRange();n.push(c)}for(let i=0,a=t.length;i<a;i++){const o=t[i],c=(await this._executeNode(o)).toUnitRange();n.push(c)}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,c=r.length;u<c;u++){const l=r[u];o!==l&&o.dependency(l)&&o.pushChildren(l)}(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 c,l,f,_;const e=r.unitId,t=r.subComponentId,n=r.featureId;if(n!=null){const E=this._currentConfigService.getDirtyUnitFeatureMap();if(((l=(c=E==null?void 0:E[e])==null?void 0:c[t])==null?void 0:l[n])!=null)return!0}const i=(_=(f=this._currentConfigService.getExcludedRange())==null?void 0:f[e])==null?void 0:_[t];let a=!1;if(i==null||i.forValue((E,A)=>{if(r.row===E&&r.column===A)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 E of u)if(r.inRangeData(E))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()}};Ue=Ss([m.OnLifecycle(m.LifecycleStages.Rendered,Ue),ce(0,Le),ce(1,Z),ce(2,Bt),ce(3,ct),ce(4,b.Inject(Me)),ce(5,b.Inject(Ie)),ce(6,b.Inject(pe))],Ue);var ys=Object.defineProperty,Fs=Object.getOwnPropertyDescriptor,Ts=(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&&ys(r,e,n),n},le=(s,r)=>(e,t)=>r(e,t,s);const bs=1;exports.CalculateFormulaService=class extends m.Disposable{constructor(e,t,n,i,a,o,u){super();C(this,"_executionStartListener$",new lt.Subject);C(this,"executionStartListener$",this._executionStartListener$.asObservable());C(this,"_executionCompleteListener$",new lt.Subject);C(this,"executionCompleteListener$",this._executionCompleteListener$.asObservable());C(this,"_executionInProgressListener$",new lt.Subject);C(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")||bs;for(let n=0;n<t&&(await this._execute(),!!this._runtimeService.isCycleDependency());n++);this._runtimeService.setFormulaExecuteStage(K.CALCULATION_COMPLETED),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState()),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData()),Nt.clear(),_e.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 c=new m.ObjectMatrix(o[u]);if(c==null)return!0;const l=new m.ObjectMatrix;c.forValue((f,_,E)=>{l.setValue(f,_,!0),n.push({unitId:a,sheetId:u,range:E})}),i[a]==null&&(i[a]={}),i[a][u]=l})}),Object.keys(t).forEach(a=>{const o=t[a];Object.keys(o).forEach(u=>{const c=o[u];Object.keys(c).forEach(l=>{const f=c[l];if(f==null)return!0;for(const _ of f)n.push({unitId:u,sheetId:l,range:_})})})}),{dirtyRanges:n,excludedCell:i}}async _apply(e=!1){e?this._runtimeService.setFormulaExecuteStage(K.START_DEPENDENCY_ARRAY_FORMULA):this._runtimeService.setFormulaExecuteStage(K.START_DEPENDENCY),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());const t=await this._formulaDependencyGenerator.generate(),n=this._interpreter;e?(this._runtimeService.setFormulaExecuteStage(K.START_CALCULATION_ARRAY_FORMULA),this._runtimeService.setTotalArrayFormulasToCalculate(t.length)):(this._runtimeService.setFormulaExecuteStage(K.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(K.IDLE),this._runtimeService.markedAsStopFunctionsExecuted(),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData());return}const o=t[i],u=o.node,c=o.getDirtyData;let l;if(u==null&&c==null)throw new Error("AstNode or executor is null");if(this._runtimeService.setCurrent(o.row,o.column,o.subComponentId,o.unitId),c!=null&&o.featureId!=null){const{runtimeCellData:f,dirtyRanges:_}=c(o);this._runtimeService.setRuntimeFeatureCellData(o.featureId,f),this._runtimeService.setRuntimeFeatureRange(o.featureId,_)}else u!=null&&(n.checkAsyncNode(u)?l=await n.executeAsync(u):l=n.execute(u),o.formulaId!=null?this._runtimeService.setRuntimeOtherData(o.formulaId,l):this._runtimeService.setRuntimeData(l));e?(this._runtimeService.setFormulaExecuteStage(K.CURRENTLY_CALCULATING_ARRAY_FORMULA),this._runtimeService.setCompletedArrayFormulasCount(i+1)):(this._runtimeService.setFormulaExecuteStage(K.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 P.create(n);const i=this._astTreeBuilder.parse(n);console.log("astNode",i==null?void 0:i.serialize())}};exports.CalculateFormulaService=Ts([m.OnLifecycle(m.LifecycleStages.Rendered,exports.CalculateFormulaService),le(0,m.IConfigService),le(1,b.Inject(pe)),le(2,Le),le(3,Z),le(4,b.Inject(Ue)),le(5,b.Inject(Me)),le(6,b.Inject(Ie))],exports.CalculateFormulaService);var Ls=Object.defineProperty,ws=Object.getOwnPropertyDescriptor,Os=(s,r,e,t)=>{for(var n=t>1?void 0:t?ws(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&&Ls(r,e,n),n},Pe=(s,r)=>(e,t)=>r(e,t,s);let Be=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===wt.id)this._calculateFormulaService.stopFormulaExecution();else if(s.id===Ut.id){const e=s.params.formulaData;this._formulaDataModel.setFormulaData(e)}else if(s.id===Lt.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===He.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 Re.NOT_EXECUTED:break;case Re.STOP_EXECUTION:break;case Re.SUCCESS:this._applyFormula(s);break;case Re.INITIAL:break}this._commandService.executeCommand(Ye.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(Ye.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(He.id,{arrayFormulaRange:this._formulaDataModel.getArrayFormulaRange(),arrayFormulaCellData:this._formulaDataModel.getArrayFormulaCellData()},{onlyLocal:!0})),this._commandService.executeCommand(Ot.id,{unitData:r,unitOtherData:e},{onlyLocal:!0})}};Be=Os([m.OnLifecycle(m.LifecycleStages.Ready,Be),Pe(0,m.ICommandService),Pe(1,b.Inject(exports.CalculateFormulaService)),Pe(2,m.IUniverInstanceService),Pe(3,b.Inject(exports.FormulaDataModel))],Be);const Us=[];class Is extends V{calculate(r,e){return d.create(h.VALUE)}}const Ms=[[Is,ot.CONCATENATE]],xs=[],vs=[],Ps=[],Vs=[],Bs=[],ks=[],$s=[];class js extends V{calculate(r,e){return new Vt("A5")}}class Qs extends V{calculate(r,e,t,n,i){return new Vt("A5")}}const Gs=[[js,qe.INDIRECT],[Qs,qe.OFFSET]];class Hs extends V{calculate(r,e){return d.create(h.VALUE)}}class Ys extends V{calculate(...r){let e=new N(0);for(let t=0;t<r.length;t++){let n=r[t];if(n.isError())return n;if(e.isError())return e;n.isReferenceObject()&&(n=n.toArrayValueObject()),n.isArray()&&(n=n.sum()),e=e.plus(n)}return e}}function qs(s){const r=[R.EQUALS,R.NOT_EQUAL,R.GREATER_THAN_OR_EQUAL,R.GREATER_THAN,R.LESS_THAN_OR_EQUAL,R.LESS_THAN];for(const e of r)if(s.startsWith(e)){const t=s.substring(e.length);return[e,De.create(t)]}return[R.EQUALS,De.create(s)]}function zs(s,r){const e=s.toArrayValueObject(),t=`${r.getValue()}`,[n,i]=qs(t);return zr(t)?e.wildcard(i,n):e.compare(i,n)}class Xs extends V{calculate(...r){if(r.length<2||r.length>3)return d.create(h.NA);const e=r[0],t=r[1],n=r[2];if(e.isError()||t.isError()||n&&n.isError())return d.create(h.VALUE);let i=new N(0);if(e.isReferenceObject()||e.isValueObject()&&e.isArray()){const o=zs(e,t).getArrayValue(),u=n||e,{startRow:c,startColumn:l}=u.getRangePosition();u.iterator((f,_,E)=>{if(!(f!=null&&f.isError())){const g=o[_-c][E-l].getValue()?f:new N(0);i=i.plus(g)}})}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 N(i),n).getValue()||(r=new N(0))}return r}}class Ks extends V{calculate(...r){return d.create(h.VALUE)}}const Ws=[[Ys,me.SUM],[Xs,me.SUMIF],[Ks,me.SUMIFS],[Hs,me.POWER]];class Zs extends V{constructor(){super(...arguments);C(this,"_compareType",R.EQUALS)}setCompareType(e){this._compareType=e}calculate(e,t){return e.isError()||t.isError()?d.create(h.VALUE):(e.isReferenceObject()&&(e=e.toArrayValueObject()),t.isReferenceObject()&&(t=t.toArrayValueObject()),e.compare(t,this._compareType))}}class Js extends V{calculate(r,e){return r.isError()||e.isError()?d.create(h.VALUE):(r.isReferenceObject()&&(r=r.toArrayValueObject()),e.isReferenceObject()&&(e=e.toArrayValueObject()),!e.isArray()&&e.getValue()===0?d.create(h.DIV_BY_ZERO):r.divided(e))}}class ei 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 ti extends V{calculate(r,e){return r.isError()||e.isError()?d.create(h.VALUE):(r.isReferenceObject()&&(r=r.toArrayValueObject()),e.isReferenceObject()&&(e=e.toArrayValueObject()),r.multiply(e))}}class ri extends V{calculate(r,e){return r.isError()||e.isError()?d.create(h.VALUE):(r.isReferenceObject()&&(r=r.toArrayValueObject()),e.isReferenceObject()&&(e=e.toArrayValueObject()),r.plus(e))}}class ni extends V{constructor(){super(...arguments);C(this,"_compareType",R.EQUALS)}setCompareType(e){this._compareType=e}calculate(e,t){return e.isError()||t.isError()||!e.isReferenceObject()||!t.isReferenceObject()?d.create(h.REF):(e=e,t=t,e.isCell()&&t.isCell()||e.isRow()&&t.isRow()||e.isColumn()&&t.isColumn()?e.unionBy(t):d.create(h.REF))}}const si=[[Zs,B.COMPARE],[Js,B.DIVIDED],[ei,B.MINUS],[ti,B.MULTIPLY],[ri,B.PLUS],[ni,B.UNION]];class ii extends V{calculate(...r){let e=new N(0),t=new N(0);for(let n=0;n<r.length;n++){let i=r[n];if(i.isError())return i;if(e.isError())return e;i.isReferenceObject()&&(i=i.toArrayValueObject()),i.isArray()?(e=e.plus(i.sum()),t=t.plus(i.count())):i.isNull()||(t=t.plus(new N(1)))}return e.divided(t)}}class ai extends V{calculate(...r){let e=new N(0);for(let t=0;t<r.length;t++){let n=r[t];n.isError()||(n.isReferenceObject()&&(n=n.toArrayValueObject()),n.isArray()?(n=n.count(),e=e.plus(n)):!n.isNull()&&!n.isString()&&(e=e.plus(new N(1))))}return e}}class oi extends V{calculate(...r){let e=new N(0);for(let t=0;t<r.length;t++){let n=r[t];if(n.isError()){e=e.plus(new N(1));continue}n.isReferenceObject()&&(n=n.toArrayValueObject()),n.isArray()?(n=n.countA(),e=e.plus(n)):n.isNull()||(e=e.plus(new N(1)))}return e}}class ui extends V{calculate(...r){let e=new N(-1/0);for(let t=0;t<r.length;t++){let n=r[t];if(n.isError())return n;n.isReferenceObject()&&(n=n.toArrayValueObject()),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 Zt extends V{calculate(...r){let e=new N(1/0);for(let t=0;t<r.length;t++){let n=r[t];if(n.isError())return n;n.isReferenceObject()&&(n=n.toArrayValueObject()),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 ci=[[ii,ne.AVERAGE],[ai,ne.COUNT],[ui,ne.MAX],[Zt,ne.MIN],[Zt,ne.MIN],[oi,ne.COUNTA]],li=[],hi=[],fi=[];var _i=Object.defineProperty,di=Object.getOwnPropertyDescriptor,mi=(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&&_i(r,e,n),n},gt=(s,r)=>(e,t)=>r(e,t,s);let ke=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(){[Ut,He,Lt,wt,Ye,Ot,st,it,Tt,bt,It,Mt,fr,_r,xt].forEach(s=>this.disposeWithMe(this._commandService.registerCommand(s)))}_registerFunctions(){const s=[...Us,...Ms,...xs,...vs,...Ps,...Vs,...Bs,...ks,...$s,...Gs,...Ws,...si,...ci,...li,...hi,...fi].map(r=>{const e=r[0],t=r[1];return new e(t)});this._functionService.registerExecutors(...s)}};ke=mi([m.OnLifecycle(m.LifecycleStages.Ready,ke),gt(0,m.ICommandService),gt(1,b.Inject(b.Injector)),gt(2,ue)],ke);var gi=Object.defineProperty,Ci=Object.getOwnPropertyDescriptor,pi=(s,r,e,t)=>{for(var n=t>1?void 0:t?Ci(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&&gi(r,e,n),n},Jt=(s,r)=>(e,t)=>r(e,t,s);let $e=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===st.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===it.id){const r=s.params;if(r==null)return;const{unitId:e,name:t}=r;this._definedNamesService.removeDefinedName(e,t)}}))}};$e=pi([m.OnLifecycle(m.LifecycleStages.Ready,$e),Jt(0,m.ICommandService),Jt(1,ut)],$e);var Ei=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&&Ei(r,e,n),n},er=(s,r)=>(e,t)=>r(e,t,s);let je=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===Tt.id){const r=s.params;if(r==null)return;const{featureId:e,calculationParam:t}=r;this._featureCalculationManagerService.register(e,t)}else if(s.id===bt.id){const r=s.params;if(r==null)return;const{featureId:e}=r;this._featureCalculationManagerService.remove(e)}}))}};je=Ai([m.OnLifecycle(m.LifecycleStages.Ready,je),er(0,m.ICommandService),er(1,ct)],je);var Ri=Object.defineProperty,Si=Object.getOwnPropertyDescriptor,Di=(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},tr=(s,r)=>(e,t)=>r(e,t,s);let Qe=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===It.id){const r=s.params;if(r==null)return;this._otherFormulaManagerService.register(r)}else if(s.id===Mt.id){const r=s.params;if(r==null)return;this._otherFormulaManagerService.remove(r)}}))}};Qe=Di([m.OnLifecycle(m.LifecycleStages.Ready,Qe),tr(0,m.ICommandService),tr(1,Bt)],Qe);var yi=Object.defineProperty,Fi=Object.getOwnPropertyDescriptor,Ti=(s,r,e,t)=>{for(var n=t>1?void 0:t?Fi(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&&yi(r,e,n),n},rr=(s,r)=>(e,t)=>r(e,t,s);let Ge=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===st.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===it.id){const r=s.params;if(r==null)return;const{unitId:e,tableName:t}=r;this._superTableService.remove(e,t)}else if(s.id===xt.id){const r=s.params;if(r==null)return;const{tableOption:e,tableOptionType:t}=r;this._superTableService.registerTableOptionMap(e,t)}}))}};Ge=Ti([m.OnLifecycle(m.LifecycleStages.Ready,Ge),rr(0,m.ICommandService),rr(1,Pt)],Ge);var bi=Object.defineProperty,Li=Object.getOwnPropertyDescriptor,wi=(s,r,e,t)=>{for(var n=t>1?void 0:t?Li(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},Oi=(s,r)=>(e,t)=>r(e,t,s);const Ui="base-formula-engine";exports.UniverFormulaEnginePlugin=class extends m.Plugin{constructor(r,e){super(Ui),this._config=r,this._injector=e}onStarting(){this._initialize()}_initialize(){var e;const r=[[ue,{useClass:Nr}],[ct,{useClass:Dr}],[ut,{useClass:En}],[exports.FormulaDataModel],[nt],[ke],[je]];(e=this._config)!=null&&e.notExecuteFormula||r.push([exports.CalculateFormulaService],[Bt,{useClass:yr}],[Pt,{useClass:Zn}],[Le,{useClass:At}],[Z,{useClass:Rt}],[Be],[$e],[Qe],[Ge],[Ue],[Me],[Ie],[pe],[Er],[Ke],[We],[Rr],[Ze],[Xe],[Je],[et],[tt],[Sr]),r.forEach(t=>this._injector.add(t))}onReady(){this._injector.get(exports.FormulaDataModel).initFormulaData()}};exports.UniverFormulaEnginePlugin=wi([Oi(1,b.Inject(b.Injector))],exports.UniverFormulaEnginePlugin);exports.ArrayValueObject=se;exports.BaseFunction=V;exports.BaseReferenceObject=be;exports.BaseValueObject=Ee;exports.BooleanValueObject=j;exports.ErrorType=h;exports.ErrorValueObject=d;exports.FUNCTION_NAMES_ARRAY=un;exports.FUNCTION_NAMES_COMPATIBILITY=ot;exports.FUNCTION_NAMES_CUBE=cn;exports.FUNCTION_NAMES_DATABASE=ln;exports.FUNCTION_NAMES_DATE=hn;exports.FUNCTION_NAMES_ENGINEERING=fn;exports.FUNCTION_NAMES_FINANCIAL=_n;exports.FUNCTION_NAMES_INFORMATION=dn;exports.FUNCTION_NAMES_LOGICAL=mn;exports.FUNCTION_NAMES_LOOKUP=qe;exports.FUNCTION_NAMES_MATH=me;exports.FUNCTION_NAMES_STATISTICAL=ne;exports.FUNCTION_NAMES_TEXT=gn;exports.FUNCTION_NAMES_UNIVER=Cn;exports.FUNCTION_NAMES_WEB=pn;exports.FeatureCalculationManagerService=Dr;exports.FormulaExecuteStageType=K;exports.FormulaExecutedStateType=Re;exports.FunctionService=Nr;exports.FunctionType=sr;exports.IFeatureCalculationManagerService=ct;exports.IFunctionService=ue;exports.LexerNode=F;exports.LexerTreeBuilder=nt;exports.NumberValueObject=N;exports.OtherFormulaManagerService=yr;exports.RangeReferenceObject=pr;exports.RemoveDefinedNameMutation=it;exports.RemoveFeatureCalculationMutation=bt;exports.RemoveOtherFormulaMutation=Mt;exports.RemoveSuperTableMutation=_r;exports.SetArrayFormulaDataMutation=He;exports.SetArrayFormulaDataUndoMutationFactory=Hr;exports.SetDefinedNameMutation=st;exports.SetFeatureCalculationMutation=Tt;exports.SetFormulaCalculationNotificationMutation=Ye;exports.SetFormulaCalculationResultMutation=Ot;exports.SetFormulaCalculationStartMutation=Lt;exports.SetFormulaCalculationStopMutation=wt;exports.SetFormulaDataMutation=Ut;exports.SetOtherFormulaMutation=It;exports.SetSuperTableMutation=fr;exports.SetSuperTableOptionMutation=xt;exports.StringValueObject=$;exports.ValueObjectFactory=De;exports.compareToken=R;exports.convertUnitDataToRuntime=ar;exports.generateStringWithSequence=cr;exports.includeFormulaLexerToken=Or;exports.initSheetFormulaData=hr;exports.isFormulaLexerToken=Ct;exports.isInDirtyRange=nr;exports.matchToken=L;exports.normalizeSheetName=Ur;exports.sequenceNodeType=q;
|
|
1
|
+
"use strict";var Or=Object.defineProperty;var Ur=(s,r,e)=>r in s?Or(s,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[r]=e;var g=(s,r,e)=>(Ur(s,typeof r!="symbol"?r+"":r,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@univerjs/core"),D=require("@wendellhu/redi"),_t=require("rxjs");function cr(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:c,endRow:l,endColumn:f}=o.range;if(t>=u&&t<=l&&n>=c&&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 Ir=new Set(["#DIV/0!","#NAME!","#VALUE!","#NUM!","#N/A","#CYCLE!","#REF!","#SPILL!","#CALC!","#ERROR!","#GETTING_DATA","#NULL!"]);var lr=(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))(lr||{}),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||{}),R=(s=>(s.EQUALS="=",s.NOT_EQUAL="<>",s.GREATER_THAN=">",s.GREATER_THAN_OR_EQUAL=">=",s.LESS_THAN="<",s.LESS_THAN_OR_EQUAL="<=",s))(R||{});const Be=new Map([["<>",3],["<",3],[">=",3],["=",3],[">",3],["<=",3],["&",2],["+",2],["-",2],["/",1],["*",1],["^",0]]),Ue=new Set(Be.keys()),Mr=new Set(["=","<>",">",">=","<","<="]);var w=(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))(w||{}),ue=(s=>(s.PERCENTAGE="%",s.POUND="#",s))(ue||{});const xr=new Set(["%","#"]);var P=(s=>(s.AT="@",s.MINUS="-",s))(P||{});const hr=[...Object.values(R),...Object.values(G),...Object.values(w),...Object.values(ue),...Object.values(P)];function Nt(s){return hr.includes(s)}function vr(s){for(const r of hr)if(s.indexOf(r)>-1)return!0;return!1}function Pr(s){return s[0]==="'"&&s[s.length-1]==="'"?s.substring(1,s.length-1):s}function fr(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 nt{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 De=`'?\\[((?![\\/?:"<>|*\\\\]).)*\\]`,Fe="((?![\\[\\]\\/?*\\\\]).)*!",ce="$",Ft="\\s*?:\\s*?",At=`\\${ce}?[A-Za-z]+\\${ce}?[0-9]+`,Vr=`^(${P.AT})?(${De})?(${Fe})?${At}${Ft}${At}$`,Lt=`^(${De})?(${Fe})?\\s*?${At}(${ue.POUND})?$`,Br=`^(${De})?(${Fe})?\\${ce}?[0-9]+${Ft}\\${ce}?[0-9]+$`,kr=`^(${De})?(${Fe})?\\${ce}?[A-Za-z]+${Ft}\\${ce}?[A-Za-z]+$`,jr=`^(${De})?(${Fe})?\\s*?\\${ce}?[0-9]+$`,$r=`^(${De})?(${Fe})?\\s*?\\${ce}?[A-Za-z]+$`,_r="[.*?]",Qr="{.*?}";function Gr(s){return new RegExp(Lt).test(s)||new RegExp(Vr).test(s)||new RegExp(Br).test(s)||new RegExp(kr).test(s)}const de="P_1",oe="R_1",Se="L_1",st="LR_1",dr="LO_1",Hr="LET",Me="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 mr(s){let r="";for(const e of s)typeof e=="string"?r+=e:r+=e.token;return r}class F{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 F?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 gr=1e5,dt=new nt(gr),mt=new nt(gr);class it extends m.Disposable{constructor(){super(...arguments);g(this,"_currentLexerNode",new F);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(),dt.clear(),mt.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!==de&&!Nt(u)&&a.getStartIndex()!==-1){const c=a.getChildren().indexOf(o);return{functionName:u,paramIndex:c}}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 c=i[o];if(typeof c=="string"||c.nodeType!==q.REFERENCE){a.push(c);continue}const{token:l}=c,f=m.deserializeRangeWithSheet(l),{range:d,sheetName:E,unitId:A}=f,C=m.Rectangle.moveOffset(d,t,n);let N="";m.isValidRange(C)?N=m.serializeRangeToRefString({range:C,unitId:A,sheetName:E}):N=h.REF,a.push({...c,token:N})}return`=${mr(a)}`}checkIfAddBracket(e){let t=0,n=e.length-1,i=e[n];for(;(i===w.CLOSE_BRACKET||i===" ")&&n>=0;)i===w.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(),c=0;for(;u;){const l=u.getToken();l!==de&&l!==w.COLON&&u.getStartIndex()!==-1&&l.toUpperCase()!==Me&&(t===0?c+=1:t--),u=u.getParent()}return c}sequenceNodesBuilder(e){const t=mt.get(e);if(t)return[...t];const n=this._getSequenceArray(e);if(n.length===0)return;const i=this.getSequenceNode(n);return mt.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:c,currentString:l,cur:f}=o;if(l===w.DOUBLE_QUOTATION&&(n=!0),(c!==""||i===0)&&i!==a-1){t.push(l);continue}let d=(u==null?void 0:u.segment)||"";const E=i-d.length;let A=i-1;const C=i-1;if(i===a-1&&this._isLastMergeString(l)&&(d+=l,A+=1),d===""||Be.has(d)){t.push(l);continue}const N=d.trim(),S=this._replacePrefixString(N);n===!0&&N[N.length-1]===w.DOUBLE_QUOTATION?(n=!1,this._pushSequenceNode(t,{nodeType:q.STRING,token:d,startIndex:E,endIndex:A},C)):new RegExp(Lt).test(S)?this._pushSequenceNode(t,{nodeType:q.REFERENCE,token:d,startIndex:E,endIndex:A},C):m.Tools.isStringNumber(N)?this._pushSequenceNode(t,{nodeType:q.NUMBER,token:d,startIndex:E,endIndex:A},C):N.length>0&&this._pushSequenceNode(t,{nodeType:q.FUNCTION,token:d,startIndex:E,endIndex:A},C),(i!==a-1||!this._isLastMergeString(l))&&t.push(l)}return this._mergeSequenceNodeReference(t)}_getCurrentParamIndex(e,t){return this._nodeMaker(e,void 0,t)}_isLastMergeString(e){return e===w.DOUBLE_QUOTATION||m.Tools.isStringNumber(e)||!Nt(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()===w.CLOSE_BRACES&&o!=null&&typeof o!="string"&&o.nodeType===q.FUNCTION&&o.token.trim().substring(0,1)===w.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===w.COLON&&typeof a!="string"&&u!=null&&typeof u!="string"&&Gr((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(P.AT,"g"),"").replace(new RegExp(P.MINUS,"g"),"")}nodeMakerTest(e){return this._nodeMaker(e)}treeBuilder(e,t=!0,n){if(t===!0){const l=dt.get(e);if(l)return l}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:l,sequenceString:f}=n(i);o=l,u=f}if(o&&(this._resetCurrentLexerNode(),this._currentLexerNode.setToken(oe),a=this._nodeMaker(`=${u}`),a===h.VALUE))return a;const c=this._getTopNode(this._currentLexerNode);return c&&(this._currentLexerNode=c),t&&(this._suffixExpressionHandler(this._currentLexerNode),dt.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 c=0;c<n;c++){const l=t[c];if(l instanceof F)this._suffixExpressionHandler(l),i.push(l);else{const f=l.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===w.OPEN_BRACKET)break;const E=Be.get(d),A=Be.get(f);if(!E||!A)break;if(A>E)i.push(a.pop());else break}a.push(l)}else if(f===w.OPEN_BRACKET)a.push(l);else if(f===w.CLOSE_BRACKET)for(;a.length>0;){const d=(u=a[a.length-1])==null?void 0:u.trim();if(!d)break;if(d===w.OPEN_BRACKET){a.pop();break}i.push(a.pop())}else i.push(l)}}for(;a.length>0;)i.push(a.pop());e.setChildren(i)}_resetCurrentLexerNode(){this._currentLexerNode=new F}_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 F)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,c;const e=(n=this._currentLexerNode)==null?void 0:n.getParent();let t=!1;if(e&&e.getToken()===Se){if((i=e==null?void 0:e.getParent())!=null&&i.getParent()){const l=(o=(a=this._currentLexerNode.getParent())==null?void 0:a.getParent())==null?void 0:o.getParent();l&&(this._currentLexerNode=l),t=!0}}else if(e!=null&&e.getParent()){const l=(u=this._currentLexerNode.getParent())==null?void 0:u.getParent();l&&(this._currentLexerNode=l),t=!0}for(let l=0;l<this._upLevel;l++){const f=(c=this._currentLexerNode)==null?void 0:c.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 F)&&this.isColonOpen()){const i=new F;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 F;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===w.OPEN_BRACKET||e===w.COMMA||e==="")}_getSequenceArray(e){const t=[];return this._nodeMaker(e,t),t}_resetTemp(){this._currentLexerNode=new F,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===w.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 c=i[o+1];if(c&&c===w.CLOSE_BRACKET){if(!this._setParentCurrentLexerNode()&&o!==a-1)return h.VALUE;o++}else c&&this._newAndPushCurrentLexerNode(de,o)}else this._pushNodeToChildren(u),this._openBracket(0);else if(u===w.CLOSE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()){this._pushNodeToChildren(this._segment),this._resetSegment();const c=this._getCurrentBracket();if(c===0)this._pushNodeToChildren(u);else if(c===1){const l=i[o+1];if(l&&l===w.OPEN_BRACKET){if(!this._setParentCurrentLexerNode()&&o!==a-1)return h.VALUE;this._newAndPushCurrentLexerNode(Se,o,!0),this._openLambda()}else if(!this._setAncestorCurrentLexerNode()&&o!==a-1)return h.VALUE}else return h.VALUE;this._closeBracket()}else if(u===w.OPEN_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(u),this._openBraces();else if(u===w.CLOSE_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(u),this._pushNodeToChildren(this._segment),this._resetSegment(),this._closeBraces();else if(u===w.OPEN_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._segment.length>0&&this._openTableBracket(),this._pushSegment(u),this._openSquareBracket();else if(u===w.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===w.DOUBLE_QUOTATION&&this.isSingleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){if(this.isDoubleQuotationClose())this._openDoubleQuotation();else{const c=i[o+1];c&&c===w.DOUBLE_QUOTATION?o++:this._closeDoubleQuotation()}this._pushSegment(u)}else if(u===w.SINGLE_QUOTATION&&this.isDoubleQuotationClose()){if(this.isSingleQuotationClose())this._openSingleQuotation();else{const c=i[o+1];c&&c===w.SINGLE_QUOTATION?o++:this._closeSingleQuotation()}this._pushSegment(u)}else if(u===w.COMMA&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const c=this._getCurrentBracket();if(c===1||c==null){if(this._pushNodeToChildren(this._segment),this._resetSegment(),!this._setParentCurrentLexerNode()&&o!==a-1&&c!=null)return h.VALUE;this._newAndPushCurrentLexerNode(de,o)}else return h.VALUE}else if(u===w.COLON&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const c=new F;c.setToken(u);const l=new F;l.setToken(de),l.setParent(c);const f=new F;f.setToken(de),f.setParent(c),c.getChildren().push(l,f);let d=c,E=0;if(this._segmentCount()>0){let A,C,N=0;const S=this._segment.trim(),y=S[0],T=S[1];if(y===P.MINUS&&(A=new F,A.setToken(P.MINUS),N++),(y===P.AT||T===P.AT)&&(C=new F,C.setToken(P.AT),A&&(A.addChildren(C),C.setParent(A)),N++),N>0&&(this._segment=S.slice(N)),E=N,C)if(C.addChildren(c),c.setParent(C),C.getParent()){const Q=C.getParent();Q&&(d=Q)}else d=C;else A&&(d=A,A.addChildren(c),c.setParent(A));const b=new F;b.setToken(this._segment),b.setParent(l),l.getChildren().push(b),this._resetSegment()}else{const A=this._getLastChildCurrentLexerNode();A&&A.changeToParent(l)}this._setCurrentLexerNode(d),this._currentLexerNode=f,this._openColon(E)}else if(xr.has(u)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){this._pushNodeToChildren(this._segment);const c=new F;c.setToken(u);const l=this._getLastChildCurrent();l instanceof F?l.changeToParent(c):l!==!1&&(c.getChildren().push(l),this._removeLastChild()),this._pushNodeToChildren(c),c.setParent(this._currentLexerNode),this._resetSegment()}else if(Ue.has(u)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){let c=this._segment.trim();if(u===G.MINUS&&c===""){const l=this._findPreviousToken(i,o-1)||"";if(this._negativeCondition(l)){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&&c===""?c=this._segment:(this._pushNodeToChildren(this._segment),c="");if(u===G.LESS_THAN||u===G.GREATER_THAN){const l=i[o+1];l&&Ue.has(u+l)?(this._pushNodeToChildren(c+u+l),o++):this._pushNodeToChildren(c+u)}else this._pushNodeToChildren(c+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 Yr=Object.defineProperty,qr=Object.getOwnPropertyDescriptor,zr=(s,r,e,t)=>{for(var n=t>1?void 0:t?qr(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&&Yr(r,e,n),n},Qt=(s,r)=>(e,t)=>r(e,t,s);exports.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 c,l;const a=n[i],o=(l=(c=this._arrayFormulaRange)==null?void 0:c[t])==null?void 0:l[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 y;const E=(y=o==null?void 0:o[f])==null?void 0:y[d];if(E==null)return!0;const{startRow:A,startColumn:C,endRow:N,endColumn:S}=E;for(let T=A;T<=N;T++)for(let b=C;b<=S;b++)u.setValue(T,b,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((c,l)=>{const f=o==null?void 0:o.getValue(c,l);if(f==null)return!0;const{startRow:d,startColumn:E,endRow:A,endColumn:C}=f;for(let N=d;N<=A;N++)for(let S=E;S<=C;S++)u.setValue(N,S,null)}),a.forValue((c,l,f)=>{u.setValue(c,l,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,c,l)=>{o.setValue(u,c,l)}),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();Cr(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={},c={};for(const l of o){const f=l.getSheetId(),d=l.getConfig();u[f]={cellData:new m.ObjectMatrix(d.cellData),rowCount:d.rowCount,columnCount:d.columnCount},c[l.getName()]=l.getSheetId()}t[a]=u,n[a]=c}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 c=u[e];c[t]==null&&(c[t]={});const l=new m.ObjectMatrix(c[t]);i.forValue((f,d,E)=>{const A=(E==null?void 0:E.f)||"",C=(E==null?void 0:E.si)||"",N=m.isFormulaString(A),S=m.isFormulaId(C);if(N&&S)l.setValue(f,d,{f:A,si:C}),a.set(C,{f:A,r:f,c:d});else if(N&&!S)l.setValue(f,d,{f:A});else if(!N&&S)l.setValue(f,d,{f:"",si:C});else if(!N&&!S&&l.getValue(f,d)){const y=l.getValue(f,d),T=(y==null?void 0:y.f)||"",b=(y==null?void 0:y.si)||"";m.isFormulaString(T)&&m.isFormulaId(b)&&o.set(b,T),l.realDeleteValue(f,d)}}),l.forValue((f,d,E)=>{const A=(E==null?void 0:E.f)||"",C=(E==null?void 0:E.si)||"";if(m.isFormulaId(C)){const N=a.get(C),S=o.get(C);if(N&&!m.isFormulaString(A)){const y=N.f,T=d-N.c,b=f-N.r;l.setValue(f,d,{f:y,si:C,x:T,y:b})}else if(typeof S=="string"){const y=E.x||0,T=E.y||0,b=this._lexerTreeBuilder.moveFormulaRefOffset(S,y,T);o.set(C,{r:f,c:d,f:b}),l.setValue(f,d,{f:b,si:C})}else if(typeof S=="object"){const y=d-S.c,T=f-S.r;l.setValue(f,d,{f:S.f,si:C,x:y,y:T})}}})}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((c,l,f)=>{const{f:d,si:E,x:A=0,y:C=0}=f;if(E===e&&d.length>0&&A===0&&C===0)return u=f,!1}),u}getFormulaDataItem(e,t,n,i){var a,o,u,c;return(c=(u=(o=(a=this._formulaData)==null?void 0:a[i])==null?void 0:o[n])==null?void 0:u[e])==null?void 0:c[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,c,l)=>{const f=(l==null?void 0:l.f)||"",d=(l==null?void 0:l.si)||"",E=(l==null?void 0:l.x)||0,A=(l==null?void 0:l.y)||0;m.isFormulaString(f)&&m.isFormulaId(d)&&E===0&&A===0&&n.set(d,{f,r:u,c})}),n}};exports.FormulaDataModel=zr([Qt(0,m.IUniverInstanceService),Qt(1,D.Inject(it))],exports.FormulaDataModel);function Cr(s,r,e,t){const n=new Map,i=new m.ObjectMatrix;t.forValue((a,o,u)=>{const c=(u==null?void 0:u.f)||"",l=(u==null?void 0:u.si)||"",f=m.isFormulaString(c),d=m.isFormulaId(l);f&&d?(i.setValue(a,o,{f:c,si:l}),n.set(l,{f:c,r:a,c:o})):f&&!d?i.setValue(a,o,{f:c}):!f&&d&&i.setValue(a,o,{f:"",si:l})}),i.forValue((a,o,u)=>{const c=(u==null?void 0:u.f)||"",l=(u==null?void 0:u.si)||"";if(m.isFormulaId(l)&&!m.isFormulaString(c)){const f=n.get(l);if(f){const d=f.f,E=o-f.c,A=a-f.r;i.setValue(a,o,{f:d,si:l,x:E,y:A})}}}),s[r][e]=i.getData()}const Kr=s=>{const r=s.get(exports.FormulaDataModel),e=m.Tools.deepClone(r.getArrayFormulaRange()),t=m.Tools.deepClone(r.getArrayFormulaCellData());return{arrayFormulaRange:e,arrayFormulaCellData:t}},Ye={id:"formula.mutation.set-array-formula-data",type:m.CommandType.MUTATION,handler:(s,r)=>{const e=s.get(exports.FormulaDataModel);return e.setArrayFormulaRange(r.arrayFormulaRange),e.setArrayFormulaCellData(r.arrayFormulaCellData),!0}},at={id:"formula.mutation.set-defined-name",type:m.CommandType.MUTATION,handler:()=>!0},ot={id:"formula.mutation.remove-defined-name",type:m.CommandType.MUTATION,handler:()=>!0},wt={id:"formula.mutation.set-feature-calculation",type:m.CommandType.MUTATION,handler:()=>!0},Tt={id:"formula.mutation.remove-feature-calculation",type:m.CommandType.MUTATION,handler:()=>!0},Ot={id:"formula.mutation.set-formula-calculation-start",type:m.CommandType.MUTATION,handler:()=>!0},Ut={id:"formula.mutation.set-formula-calculation-stop",type:m.CommandType.MUTATION,handler:()=>!0},qe={id:"formula.mutation.set-formula-calculation-notification",type:m.CommandType.MUTATION,handler:()=>!0},It={id:"formula.mutation.set-formula-calculation-result",type:m.CommandType.MUTATION,handler:()=>!0},Mt={id:"formula.mutation.set-formula-data",type:m.CommandType.MUTATION,handler:(s,r)=>(s.get(exports.FormulaDataModel).setFormulaData(r.formulaData),!0)},xt={id:"formula.mutation.set-other-formula",type:m.CommandType.MUTATION,handler:()=>!0},vt={id:"formula.mutation.remove-other-formula",type:m.CommandType.MUTATION,handler:()=>!0},pr={id:"formula.mutation.set-super-table",type:m.CommandType.MUTATION,handler:()=>!0},Er={id:"formula.mutation.remove-super-table",type:m.CommandType.MUTATION,handler:()=>!0},Pt={id:"formula.mutation.set-super-table-option",type:m.CommandType.MUTATION,handler:()=>!0};class ut extends m.Disposable{isError(){return!1}isAsyncObject(){return!1}isAsyncArrayObject(){return!1}isReferenceObject(){return!1}isValueObject(){return!1}isEqualType(r){return!1}}var Ce=(s=>(s.FALSE="FALSE",s.TRUE="TRUE",s))(Ce||{}),ae=(s=>(s[s.SUCCESS=0]="SUCCESS",s[s.ERROR=1]="ERROR",s))(ae||{}),me=(s=>(s.ALL="#All",s.DATA="#Data",s.HEADERS="#Headers",s.TOTALS="#Totals",s))(me||{}),X=(s=>(s[s.FRONT=0]="FRONT",s[s.BACK=1]="BACK",s))(X||{});class Xr{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 c=u.get(n);c==null&&(c=[],u.set(n,c)),c.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,c;const i=(c=(u=this._continueBuildingCache.get(r))==null?void 0:u.get(e))==null?void 0:c.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 c,l;const a=(l=(c=this._continueBuildingCache.get(r))==null?void 0:c.get(e))==null?void 0:l.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 Xr;function Wr(){return new Intl.Collator(void 0,{numeric:!0}).compare}function Zr(s){return s.indexOf("*")>-1||s.indexOf("?")>-1}function Gt(s,r){const e=r.replace(/~?[*?]/g,n=>n.startsWith("~")?`\\${n.substring(1)}`:n==="*"?".*":n==="?"?".":n);return new RegExp(`^${e}$`).test(s)}function Ht(s){return s.replace(/~?[*?]/g,r=>r.startsWith("~")?r.substring(1):" ")}function Jr(s,r,e){let t=!1;switch(e){case R.EQUALS:t=Gt(s,r);break;case R.GREATER_THAN:case R.GREATER_THAN_OR_EQUAL:t=Gt(s,r)||s>Ht(r);break;case R.LESS_THAN:case R.LESS_THAN_OR_EQUAL:t=s<Ht(r);break}return t}class le extends ut{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,R.EQUALS)}isNotEqual(r){return this.compare(r,R.NOT_EQUAL)}isGreaterThanOrEqual(r){return this.compare(r,R.GREATER_THAN_OR_EQUAL)}isLessThanOrEqual(r){return this.compare(r,R.LESS_THAN_OR_EQUAL)}isLessThan(r){return this.compare(r,R.LESS_THAN)}isGreaterThan(r){return this.compare(r,R.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=X.FRONT){let t=this.getValue().toString();if(typeof r=="string")e===X.FRONT?t=r+t:t+=r;else if(typeof r=="number")e===X.FRONT?t=r.toString()+t:t+=r.toString();else if(typeof r=="boolean"){const n=r?"TRUE":"FALSE";e===X.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 en=20,tn=1,pe=1e6,Yt=1e6,rn=-7,nn=21,sn=!1,ve="[big.js] ",Ne=ve+"Invalid ",ct=Ne+"decimal places",an=Ne+"rounding mode",Nr=ve+"Division by zero",O={},Z=void 0,on=/^-?(\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(Ne+"value");r=r===0&&1/r<0?"-0":String(r)}un(e,r)}e.constructor=s}return s.prototype=O,s.DP=en,s.RM=tn,s.NE=rn,s.PE=nn,s.strict=sn,s.roundDown=0,s.roundHalfUp=1,s.roundHalfEven=2,s.roundUp=3,s}function un(s,r){var e,t,n;if(!on.test(r))throw Error(Ne+"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 Ae(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(an);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 Le(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>pe)throw Error(ct);if(!n[0])throw Error(Nr);if(!t[0])return s.s=i,s.c=[s.e=0],s;var o,u,c,l,f,d=n.slice(),E=o=n.length,A=t.length,C=t.slice(0,o),N=C.length,S=s,y=S.c=[],T=0,b=a+(S.e=r.e-s.e)+1;for(S.s=i,i=b<0?0:b,d.unshift(0);N++<o;)C.push(0);do{for(c=0;c<10;c++){if(o!=(N=C.length))l=o>N?1:-1;else for(f=-1,l=0;++f<o;)if(n[f]!=C[f]){l=n[f]>C[f]?1:-1;break}if(l<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}y[T++]=l?c:++c,C[0]&&l?C[N]=t[E]||0:C=[t[E]]}while((E++<A||C[0]!==Z)&&i--);return!y[0]&&T!=1&&(y.shift(),S.e--,b--),T>b&&Ae(S,b,e.RM,C[0]!==Z),S};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 c=i.c.slice(),l=i.e,f=s.c,d=s.e;if(!c[0]||!f[0])return f[0]?s.s=-u:c[0]?s=new a(i):s.s=1,s;if(o=l-d){for((n=o<0)?(o=-o,t=c):(d=l,t=f),t.reverse(),u=o;u--;)t.push(0);t.reverse()}else for(e=((n=c.length<f.length)?c:f).length,o=u=0;u<e;u++)if(c[u]!=f[u]){n=c[u]<f[u];break}if(n&&(t=c,c=f,f=t,s.s=-s.s),(u=(e=f.length)-(r=c.length))>0)for(;u--;)c[r++]=0;for(u=r;e>o;){if(c[--e]<f[e]){for(r=e;r&&!c[--r];)c[r]=9;--c[r],c[e]+=10}c[e]-=f[e]}for(;c[--u]===0;)c.pop();for(;c[0]===0;)c.shift(),--d;return c[0]||(s.s=1,c=[d=0]),s.c=c,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(Nr);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,c=s.c;if(!o[0]||!c[0])return c[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=c):(r=-r,t=o),t.reverse();r--;)t.push(0);t.reverse()}for(o.length-c.length<0&&(t=c,c=o,o=t),r=c.length,e=0;r;o[r]%=10)e=(o[--r]=o[r]+c[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<-Yt||s>Yt)throw Error(Ne+"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>pe)throw Error(Ne+"precision");return Ae(new this.constructor(this),s,r)};O.round=function(s,r){if(s===Z)s=0;else if(s!==~~s||s<-pe||s>pe)throw Error(ct);return Ae(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(ve+"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 Ae(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,c=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+c,a<o&&(r=n,n=i,i=r,c=a,a=o,o=c),r=new Array(c=a+o);c--;)r[c]=0;for(u=o;u--;){for(o=0,c=a+u;c>u;)o=r[c]+i[u]*n[c-u-1]+o,r[c--]=o%10,o=o/10|0;r[c]=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>pe)throw Error(ct);for(e=Ae(new e.constructor(e),++s,r);e.c.length<s;)e.c.push(0)}return Le(e,!0,!!t)};O.toFixed=function(s,r){var e=this,t=e.c[0];if(s!==Z){if(s!==~~s||s<0||s>pe)throw Error(ct);for(e=Ae(new e.constructor(e),s+e.e+1,r),s=s+e.e+1;e.c.length<s;)e.c.push(0)}return Le(e,!1,!!t)};O[Symbol.for("nodejs.util.inspect.custom")]=O.toJSON=O.toString=function(){var s=this,r=s.constructor;return Le(s,s.e<=r.NE||s.e>=r.PE,!!s.c[0])};O.toNumber=function(){var s=Number(Le(this,!0,!0));if(this.constructor.strict===!0&&!this.eq(s.toString()))throw Error(ve+"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>pe)throw Error(Ne+"precision");for(e=Ae(new t(e),s,r);e.c.length<s;)e.c.push(0)}return Le(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(ve+"valueOf disallowed");return Le(s,s.e<=r.NE||s.e>=r.PE,!0)};var B=Ar();function Rt(s){let r;switch(s){case R.EQUALS:r=R.EQUALS;break;case R.GREATER_THAN:r=R.LESS_THAN;break;case R.GREATER_THAN_OR_EQUAL:r=R.LESS_THAN_OR_EQUAL;break;case R.LESS_THAN:r=R.GREATER_THAN;break;case R.LESS_THAN_OR_EQUAL:r=R.GREATER_THAN_OR_EQUAL;break;case R.NOT_EQUAL:r=R.NOT_EQUAL;break}return r}function Vt(s,r){return B(s).times(r).toNumber()}function qt(s,r){const e=10**Math.floor(r);return Math.round(Vt(s,e))/e}function zt(s,r){const e=10**Math.floor(r);return Math.floor(Vt(s,e))/e}function Kt(s,r){const e=10**Math.floor(r);return Math.ceil(Vt(s,e))/e}function Xt(s,r){return s**r}class Rr extends le{isNull(){return!0}plus(r){return new p(0,!0).plus(r)}minus(r){return new p(0,!0).minus(r)}multiply(r){return new p(0,!0).multiply(r)}divided(r){return new p(0,!0).divided(r)}compare(r,e){return r.isString()?new k("").compare(r,e):r.isBoolean()?new $(!1).compare(r,e):new p(0,!0).compare(r,e)}concatenateFront(r){return r.isArray()?r.concatenateBack(new k("")):new k(this.concatenate(r.getValue(),X.FRONT))}concatenateBack(r){return r.isArray()?r.concatenateFront(new k("")):new k(this.concatenate(r.getValue(),X.BACK))}plusBy(r){return new p(0).plusBy(r)}minusBy(r){return new p(0).minusBy(r)}multiplyBy(r){return new p(0).multiplyBy(r)}dividedBy(r){return new p(0).dividedBy(r)}compareBy(r,e){return typeof r=="string"?new k("").compareBy(r,e):typeof r=="boolean"?new $(!1).compareBy(r,e):new p(0,!0).compareBy(r,e)}pow(r){return new p(0,!0).pow(r)}sqrt(){return new p(0,!0)}cbrt(){return new p(0,!0)}cos(){return new p(0,!0)}acos(){return new p(0,!0)}acosh(){return new p(0,!0)}sin(){return new p(0,!0)}asin(){return new p(0,!0)}asinh(){return new p(0,!0)}tan(){return new p(0,!0)}tanh(){return new p(0,!0)}atan(){return new p(0,!0)}atan2(r){return new p(0,!0).atan2(r)}atanh(){return new p(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 p(0,!0).round(r)}floor(r){return new p(0,!0).floor(r)}ceil(r){return new p(0,!0).ceil(r)}}class $ 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===Ce.TRUE?this._value=!0:n===Ce.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 p(-t,!0)}getReciprocal(){return this.getValue()?new p(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 p(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 p 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 p(0).minus(this)}getReciprocal(){return new p(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 k(this.concatenate(e.getValue(),X.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new k(this.concatenate(e.getValue(),X.BACK))}compare(e,t){return e.isArray()?e.compare(this,Rt(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=B(t).plus(e).toNumber();return Number.isFinite(n)?new p(n):_.create(h.NUM)}return typeof e=="boolean"?new p(B(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=B(t).minus(e).toNumber();return Number.isFinite(n)?new p(n):_.create(h.NUM)}return typeof e=="boolean"?new p(B(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=B(t).times(e).toNumber();return Number.isFinite(n)?new p(n):_.create(h.NUM)}return typeof e=="boolean"?new p(B(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=B(t).div(e).toNumber();return Number.isFinite(n)?new p(n):_.create(h.NUM)}return typeof e=="boolean"?e===!1?_.create(h.DIV_BY_ZERO):new p(B(t).div(1).toNumber()):this}compareBy(e,t){const n=this.getValue();let i=!1;if(typeof e=="string")switch(t){case R.EQUALS:case R.GREATER_THAN:case R.GREATER_THAN_OR_EQUAL:i=!1;break;case R.LESS_THAN:case R.LESS_THAN_OR_EQUAL:case R.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 R.EQUALS:i=B(n).eq(e);break;case R.GREATER_THAN:i=B(n).gt(e);break;case R.GREATER_THAN_OR_EQUAL:i=B(n).gte(e);break;case R.LESS_THAN:i=B(n).lt(e);break;case R.LESS_THAN_OR_EQUAL:i=B(n).lte(e);break;case R.NOT_EQUAL:i=!B(n).eq(e);break}else if(typeof e=="boolean")switch(t){case R.EQUALS:case R.GREATER_THAN:case R.GREATER_THAN_OR_EQUAL:i=!1;break;case R.LESS_THAN:case R.LESS_THAN_OR_EQUAL:case R.NOT_EQUAL:i=!0;break}return new $(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=Xt(t,n);return Number.isFinite(i)?new p(i):_.create(h.NUM)}return typeof n=="boolean"?new p(Xt(t,n?1:0)):this}sqrt(){const e=this.getValue();if(!Number.isFinite(e))return _.create(h.NUM);const t=B(e).sqrt().toNumber();return Number.isFinite(t)?new p(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 p(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 p(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 p(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 p(t)}sin(){const e=this.getValue();if(!Number.isFinite(e))return _.create(h.NUM);const t=Math.sin(e);return Number.isFinite(t)?new p(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 p(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 p(t)}tan(){const e=this.getValue();if(!Number.isFinite(e))return _.create(h.NUM);const t=Math.tan(e);return Number.isFinite(t)?new p(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 p(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 p(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 p(i):_.create(h.NUM)}return typeof n=="boolean"?new p(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 p(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 p(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 p(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 p(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 p(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=qt(t,n);return Number.isFinite(i)?new p(i):_.create(h.NUM)}return typeof n=="boolean"?new p(qt(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=zt(t,n);return Number.isFinite(i)?new p(i):_.create(h.NUM)}return typeof n=="boolean"?new p(zt(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=Kt(t,n);return Number.isFinite(i)?new p(i):_.create(h.NUM)}return typeof n=="boolean"?new p(Kt(t,n?1:0)):this}_compareInfinity(e,t,n){let i=!1;switch(n){case R.EQUALS:i=e===t;break;case R.GREATER_THAN:i=e>t;break;case R.GREATER_THAN_OR_EQUAL:i=e>=t;break;case R.LESS_THAN:i=e<t;break;case R.LESS_THAN_OR_EQUAL:i=e<=t;break;case R.NOT_EQUAL:i=e!==t;break}return i}}class k 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 k(this.concatenate(e.getValue(),X.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new k(this.concatenate(e.getValue(),X.BACK))}compare(e,t){return e.isArray()?e.compare(this,Rt(t)):this.compareBy(e.getValue(),t)}wildcard(e,t){return e.isArray()?e.wildcard(this,Rt(t)):this._checkWildcard(e.getValue(),t)}compareBy(e,t){const n=this.getValue();let i=!1;if(typeof e=="string")switch(t){case R.EQUALS:i=n===e;break;case R.GREATER_THAN:i=n>e;break;case R.GREATER_THAN_OR_EQUAL:i=n>=e;break;case R.LESS_THAN:i=n<e;break;case R.LESS_THAN_OR_EQUAL:i=n<=e;break;case R.NOT_EQUAL:i=n!==e;break}else if(typeof e=="number")switch(t){case R.EQUALS:case R.GREATER_THAN:case R.GREATER_THAN_OR_EQUAL:i=!0;break;case R.LESS_THAN:case R.LESS_THAN_OR_EQUAL:case R.NOT_EQUAL:i=!1;break}else if(typeof e=="boolean")switch(t){case R.EQUALS:case R.GREATER_THAN:case R.GREATER_THAN_OR_EQUAL:i=!1;break;case R.LESS_THAN:case R.LESS_THAN_OR_EQUAL:case R.NOT_EQUAL:i=!0;break}return new $(i)}_checkWildcard(e,t){const n=this.getValue().toLocaleLowerCase(),i=Jr(n,e,t);return new $(i)}}function cn(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 ne extends le{constructor(e){var r=(...Gi)=>(super(...Gi),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=cn();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 c=i;c<=a;c++)if(e(o[u][c],u,c)===!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 p(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),c=this.get(a,o);u.isError()||u.getValue()===!0&&i[0].push(c)}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,c=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,c=t[2]||1);const l=[],f=this._value;let d=0,E=0;for(let A=n;A<=i;A+=a){E=0,l[d]==null&&(l[d]=[]);for(let C=o;C<=u;C+=c)l[d][E]=f[A][C],E++;d++}return this._createNewArray(l,l.length,l[0].length)}sum(){let e=new p(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 p(-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 p(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 p(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 p(0);return this.iterator(t=>{if(t==null||t.isNull())return!0;e=e.plusBy(1)}),e}countBlank(){let e=new p(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 ne("{0}").minus(this)}getReciprocal(){return new ne("{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 c=[];for(let l=0;l<n;l++){const f=(o=(a=this._value)==null?void 0:a[u])==null?void 0:o[l];f?f.isError()?c[l]=f:c[l]=e(f,u,l):c[l]=_.create(h.VALUE)}i.push(c)}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 p(2,!0))}return e.get(0,(t-1)/2)}var(){const e=this.mean(),t=[];this.iterator((f,d,E)=>{(f==null||f.isError()||f.isString())&&(f=new p(0));let A=f.minus(e).pow(new p(2,!0));A.isError()&&(A=new p(0)),t[d]==null&&(t[d]=[]),t[d][E]=A});const{_rowCount:n,_columnCount:i,_unitId:a,_sheetId:o,_currentRow:u,_currentColumn:c}=this;return new ne({calculateValueList:t,rowCount:n,columnCount:i,unitId:a,sheetId:o,row:u,column:c}).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=Wr();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 c=e.getRowCount(),l=e.getColumnCount();if(a=Math.max(c,a),o=Math.max(l,o),c===1&&l===1){const f=e.getFirstCell();for(let d=0;d<o;d++)i.push(f)}else if(c===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 c=0;c<o;c++)i.push(e);const u=[];for(let c=0;c<o;c++){const l=i[c];this._batchOperatorValue(l,c,u,t,n)}return this._createNewArray(u,a,o)}_batchOperatorValue(e,t,n,i,a){var E,A;const o=this._rowCount;let u=!1;const c=this.getUnitId(),l=this.getSheetId(),f=this.getCurrentRow(),d=this.getCurrentColumn();if(i===4&&(u=ge.canUseCache(c,l,t+d,f,f+o-1),u===!0)){if(a===R.EQUALS){const C=ge.getCellPositions(c,l,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 $(!0):n[N][t]=new $(!1)}else{const C=ge.getCellValuePositions(c,l,t+d);C!=null&&C.forEach((N,S)=>{let y;if(typeof S=="string"?y=new k(S):typeof S=="number"?y=new p(S):typeof S=="boolean"&&(y=new $(S)),y==null)return!0;if(y.compare(e,a))for(let b=0;b<o;b++)n[b]==null&&(n[b]=[]),N.includes(b+f)?n[b][t]=new $(!0):n[b][t]=new $(!1)})}return}ge.setContinueBuildingCache(c,l,t+d,f,f+o-1);for(let C=0;C<o;C++){const N=(A=(E=this._value)==null?void 0:E[C])==null?void 0:A[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(c,l,t+d,N.getErrorType(),C+f):ge.set(c,l,t+d,N.getValue(),C+f))}}_batchOperatorArray(e,t,n){var f,d,E,A,C,N,S,y,T,b,Q,se;let i=e.getRowCount(),a=e.getColumnCount();i<this._rowCount&&(i=this._rowCount),a<this._columnCount&&(a=this._columnCount);const o=[],u=e.getArrayValue(),c=this._checkArrayCalculateType(this),l=this._checkArrayCalculateType(e);for(let Y=0;Y<i;Y++){const I=[];for(let U=0;U<a;U++){let x;c===3?x=(d=(f=this._value)==null?void 0:f[0])==null?void 0:d[0]:c===1?x=(A=(E=this._value)==null?void 0:E[0])==null?void 0:A[U]:c===2?x=(N=(C=this._value)==null?void 0:C[Y])==null?void 0:N[0]:x=(y=(S=this._value)==null?void 0:S[Y])==null?void 0:y[U];let v;if(l===3?v=(T=u==null?void 0:u[0])==null?void 0:T[0]:l===1?v=(b=u==null?void 0:u[0])==null?void 0:b[U]:l===2?v=(Q=u==null?void 0:u[Y])==null?void 0:Q[0]:v=(se=u==null?void 0:u[Y])==null?void 0:se[U],x&&v)if(x.isError())I[U]=x;else if(v.isError())I[U]=v;else switch(t){case 1:I[U]=x.plus(v);break;case 0:I[U]=x.minus(v);break;case 2:I[U]=x.multiply(v);break;case 3:I[U]=x.divided(v);break;case 4:n?I[U]=x.compare(v,n):I[U]=_.create(h.VALUE);break;case 5:I[U]=x.concatenateFront(v);break;case 6:I[U]=x.concatenateBack(v);break;case 7:n?I[U]=x.product(v,n):I[U]=_.create(h.VALUE);break;case 8:n?I[U]=x.wildcard(v,n):I[U]=_.create(h.VALUE);break;case 9:I[U]=x.pow(v);break;case 10:I[U]=x.round(v);break;case 13:I[U]=x.atan2(v);break;case 11:I[U]=x.floor(v);break;case 12:I[U]=x.ceil(v);break}else I[U]=_.create(h.NA)}o.push(I)}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 c=t[o].split(","),l=c.length;a<l&&(a=l);const f=[];for(let d=0;d<l;d++){const E=c[d].trim();f.push(ye.create(E))}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 ne(i)}}class ye{static create(r){if(typeof r=="boolean")return new $(r,!0);if(typeof r=="string"){const e=r.toLocaleUpperCase();return e===Ce.TRUE||e===Ce.FALSE?new $(e):m.isRealNum(r)?new p(r):new RegExp(Qr,"g").test(r)?new ne(r):new k(r)}return typeof r=="number"?Number.isFinite(r)?new p(r,!0):_.create(h.NUM):_.create(h.NA)}}const hn=1e5,St=new nt(hn);class we extends ut{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 c=o+this._refOffsetY,l=u+this._refOffsetX;if(c<0||l<0)return e(new _(h.REF),o,u);const f=this.getCellData(c,l);let d=!1;if(f==null||m.isNullCell(f)){d=e(null,o,u);continue}const E=this.getCellValueObject(f);if(d=e(E,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 p(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 Ir.has(t)?_.create(t):e.t===m.CellValueType.NUMBER?new p(t):e.t===m.CellValueType.STRING||e.t===m.CellValueType.FORCE_STRING?new k(t):e.t===m.CellValueType.BOOLEAN?new $(t):ye.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 c=u.getValue(e,t);if(c!=null)return c}}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 E;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=St.get(a);if(o)return o;const u=t-e+1,c=i-n+1,l=new Array(u);this.iterator((A,C,N)=>{const S=C-e,y=N-n;l[S]||(l[S]=new Array(c)),A==null&&(A=new Rr(0)),l[S][y]=A});const f={calculateValueList:l,rowCount:l.length,columnCount:((E=l[0])==null?void 0:E.length)||0,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:e,column:n},d=new ne(f);return St.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 fn extends ut{constructor(r){super(),this._promise=r}isAsyncObject(){return!0}async getValue(){return this._promise}}class _n extends ut{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 ne(e)}}class Sr extends we{constructor(r,e,t){super(""),this.setRangeData(r),e&&this.setForcedSheetIdDirect(e),t&&this.setForcedUnitIdDirect(t)}isRange(){return!0}}var Bt=(s=>(s.MAKEARRAY="MAKEARRAY",s))(Bt||{});class M 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 lt=(s=>(s.CONCATENATE="CONCATENATE",s))(lt||{}),dn=(s=>{})(),mn=(s=>{})(),gn=(s=>{})(),Cn=(s=>{})(),pn=(s=>{})(),En=(s=>{})(),Nn=(s=>{})(),ze=(s=>(s.INDIRECT="INDIRECT",s.OFFSET="OFFSET",s))(ze||{}),K=(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))(K||{}),ie=(s=>(s.AVERAGE="AVERAGE",s.COUNT="COUNT",s.MAX="MAX",s.MIN="MIN",s.COUNTA="COUNTA",s))(ie||{}),An=(s=>{})(),Rn=(s=>{})(),Sn=(s=>{})();class yn 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 ht=D.createIdentifier("univer.formula.defined-names.service");var bn=Object.defineProperty,Dn=Object.getOwnPropertyDescriptor,Fn=(s,r,e,t)=>{for(var n=t>1?void 0:t?Dn(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&&bn(r,e,n),n},Ln=(s,r)=>(e,t)=>r(e,t,s);let yt=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=fr(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 c of a){const l=c.getSheetId(),f=c.getConfig();o[l]={cellData:new m.ObjectMatrix(f.cellData),rowCount:f.rowCount,columnCount:f.columnCount},u[c.getName()]=c.getSheetId()}e[i]=o,t[i]=u}return{allUnitData:e,unitSheetNameMap:t}}};yt=Fn([Ln(0,m.IUniverInstanceService)],yt);const Te=D.createIdentifier("univer.formula.current-data.service");var wn=Object.defineProperty,Tn=Object.getOwnPropertyDescriptor,On=(s,r,e,t)=>{for(var n=t>1?void 0:t?Tn(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&&wn(r,e,n),n},Un=(s,r)=>(e,t)=>r(e,t,s),W=(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))(W||{}),Re=(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))(Re||{});let bt=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 c=this._runtimeArrayFormulaCellData[i];c[n]==null&&(c[n]=new m.ObjectMatrix),this._runtimeClearArrayFormulaCellData[i]===void 0&&(this._runtimeClearArrayFormulaCellData[i]={});const l=this._runtimeClearArrayFormulaCellData[i];l[n]==null&&(l[n]=new m.ObjectMatrix);const f=a[n],d=c[n],E=l[n];if(r.isReferenceObject()||r.isValueObject()&&r.isArray()){const A=r,{startRow:C,startColumn:N,endRow:S,endColumn:y}=A.getRangePosition();if(C===S&&N===y){const b=this._objectValueToCellValue(A.getFirstCell());f.setValue(e,t,b),E.setValue(e,t,b);return}const T={startRow:e,startColumn:t,endRow:S-C+e,endColumn:y-N+t};if(this._checkIfArrayFormulaRangeHasData(i,n,e,t,T)){const b=this._objectValueToCellValue(new _(h.SPILL));f.setValue(e,t,b),E.setValue(e,t,b)}else{const b=new _(h.SPILL);A.iterator((Q,se,Y)=>{const I=this._objectValueToCellValue(Q);if(se===C&&Y===N){if(Q!=null&&Q.isError()&&Q.isEqualType(b))return E.setValue(e,t,{}),f.setValue(e,t,{...this._objectValueToCellValue(b)}),!1;f.setValue(e,t,{...I})}d.setValue(se-C+e,Y-N+t,I)}),u.setValue(e,t,T),o[n]=u.getData()}}else{const A=this._objectValueToCellValue(r);f.setValue(e,t,A),E.setValue(e,t,A)}}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,E,A,C,N;const{startRow:a,startColumn:o,endRow:u,endColumn:c}=i,l=this._currentConfigService.getUnitData();for(let S=a;S<=u;S++)for(let y=o;y<=c;y++){if(S===t&&n===y)continue;const T=(E=(d=(f=this._runtimeData)==null?void 0:f[r])==null?void 0:d[e])==null?void 0:E.getValue(S,y),b=(N=(C=(A=l==null?void 0:l[r])==null?void 0:A[e])==null?void 0:C.cellData)==null?void 0:N.getValue(S,y);if((!m.isNullCell(T)||!m.isNullCell(b))&&this._isInDirtyRange(r,e,S,y))return!0}return!1}_isInDirtyRange(r,e,t,n){const i=this._currentConfigService.getDirtyRanges();return cr(i,r,e,t,n)}};bt=On([Un(0,Te)],bt);const J=D.createIdentifier("univer.formula.runtime.service");var In=Object.defineProperty,Mn=Object.getOwnPropertyDescriptor,xn=(s,r,e,t)=>{for(var n=t>1?void 0:t?Mn(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&&In(r,e,n),n},gt=(s,r)=>(e,t)=>r(e,t,s);let Ee=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:c,token:l}=u;if(c===q.REFERENCE||c===q.FUNCTION){const f=(i=this._definedNamesService.getDefinedNameMap(r))==null?void 0:i.get(l);f?(t+=f,n=!0):t+=l}else t+=l}return{sequenceString:t,hasDefinedName:n}}};Ee=xn([gt(0,ht),gt(1,J),gt(2,D.Inject(it))],Ee);var L=(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))(L||{});const ee=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 L.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(ae.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 V extends H{constructor(e){super(e);g(this,"_errorValueObject");this._errorValueObject=_.create(e)}get nodeType(){return L.ERROR}static create(e){return new V(e)}getValue(){return this._errorValueObject}}const te=100;class re extends m.Disposable{get zIndex(){return 0}create(r,e,t){let n;return r instanceof F?n=r.getToken():n=r,new H(n)}checkAndCreateNodeType(r){}}class Dt extends H{get nodeType(){return L.ROOT}execute(){const e=this.getChildren()[0];this.setValue(e.getValue())}}class yr extends re{get zIndex(){return ee.get(L.ROOT)||te}checkAndCreateNodeType(r){if(!(r instanceof F))return;if(r.getToken()===oe)return new Dt(oe)}}var j=(s=>(s.COMPARE="COMPARE",s.DIVIDED="DIVIDED",s.MINUS="MINUS",s.MULTIPLY="MULTIPLY",s.PLUS="PLUS",s.UNION="UNION",s))(j||{});class br 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,Pn=Object.getOwnPropertyDescriptor,Vn=(s,r,e,t)=>{for(var n=t>1?void 0:t?Pn(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},Wt=(s,r)=>(e,t)=>r(e,t,s);class Ke extends H{constructor(r,e,t){super(e),this._accessor=r,this._operatorString=e,this._functionExecutor=t}get nodeType(){return L.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===P.MINUS?t=this._functionExecutor.calculate(new p(0),e):this._operatorString===P.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(J),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 Xe=class extends re{constructor(s,r){super(),this._functionService=s,this._injector=r}get zIndex(){return ee.get(L.PREFIX)||te}checkAndCreateNodeType(s){if(!(s instanceof F))return;const r=s.getToken(),e=r.trim();if(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;let t="";if(e===P.MINUS)t=j.MINUS;else return e===P.AT?new Ke(this._injector,e):void 0;const n=this._functionService.getExecutor(t);return n?new Ke(this._injector,e,n):(console.error(`No function ${r}`),V.create(h.NAME))}};Xe=Vn([Wt(0,he),Wt(1,D.Inject(D.Injector))],Xe);var Bn=Object.defineProperty,kn=Object.getOwnPropertyDescriptor,jn=(s,r,e,t)=>{for(var n=t>1?void 0:t?kn(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&&Bn(r,e,n),n},Zt=(s,r)=>(e,t)=>r(e,t,s);class $n extends H{constructor(r,e){super(r),this._functionExecutor=e,this._functionExecutor.isAsync()&&this.setAsync(),this._functionExecutor.isAddress()&&this.setAddress()}get nodeType(){return L.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(ae.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 We=class extends re{constructor(s,r){super(),this._functionService=s,this._injector=r}get zIndex(){return ee.get(L.FUNCTION)||te}create(s){const r=this._functionService.getExecutor(s);return r?new $n(s,r):(console.error(`No function ${s}`),V.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(P.MINUS,"g").test(i)){const o=this._functionService.getExecutor(j.MINUS);t=new Ke(this._injector,P.MINUS,o),a++}if(new RegExp(P.AT,"g").test(i)&&(n=new Ke(this._injector,P.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}}};We=jn([Zt(0,he),Zt(1,D.Inject(D.Injector))],We);var Qn=Object.defineProperty,Gn=Object.getOwnPropertyDescriptor,Hn=(s,r,e,t)=>{for(var n=t>1?void 0:t?Gn(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},Yn=(s,r)=>(e,t)=>r(e,t,s);let be=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(ae.ERROR);const r=s.getChildren(),e=r.length;for(let t=0;t<e;t++){const n=r[t];if(n.getToken().toUpperCase()===Me&&n.isEmptyParamFunction()){await n.executeAsync();continue}await this._executeAsync(n)}return s.nodeType===L.FUNCTION&&s.isAsync()?await s.executeAsync():s.execute(),Promise.resolve(ae.SUCCESS)}_execute(s){if(this._runtimeService.isStopExecution())return ae.ERROR;const r=s.getChildren(),e=r.length;for(let t=0;t<e;t++){const n=r[t];if(n.getToken().toUpperCase()===Me&&n.isEmptyParamFunction()){n.execute();continue}this._execute(n)}return s.execute(),ae.SUCCESS}};be=Hn([Yn(0,J)],be);function Dr(s){return s instanceof F?s.getToken()===Se:!1}function qn(s){return s instanceof F?s.getToken()===dr:!1}class Jt 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 fn(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()===st){const u=a.getLambdaParameter(),c=this._lambdaPrivacyValueMap.get(u);c&&a.setValue(c);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 zn=Object.defineProperty,Kn=Object.getOwnPropertyDescriptor,Xn=(s,r,e,t)=>{for(var n=t>1?void 0:t?Kn(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&&zn(r,e,n),n},er=(s,r)=>(e,t)=>r(e,t,s);class Wn 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 L.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 Jt(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 Jt(this,this._interpreter,this._lambdaPrivacyVarKeys));else{const e=this.getChildren(),t=e.length;await this.setValue(e[t-1].getValue())}return Promise.resolve(ae.SUCCESS)}}let Ze=class extends re{constructor(s,r){super(),this._runtimeService=s,this._interpreter=r}get zIndex(){return ee.get(L.LAMBDA)||te}create(s){const r=s.getChildren(),e=r[0];let t=r.slice(1,-1);const n=r[r.length-1];if(!(e instanceof F&&n instanceof F))return V.create(h.NAME);if(e.getToken()===Se){const o=e.getChildren();if(t.length!==o.length)return V.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 F){const c=u.getChildren()[0];u.setToken(dr),a.set(c.trim(),void 0)}else return V.create(h.VALUE)}return this._runtimeService.registerFunctionDefinitionPrivacyVar(i,a),this._updateLambdaStatement(n,i,a),new Wn(s.getToken(),i,this._interpreter,[...a.keys()])}checkAndCreateNodeType(s){if(!(!(s instanceof F)||s.getToken().trim().toUpperCase()!==Me))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(!(Dr(i)&&a!==0))if(o instanceof F)this._updateTree(o,r,e);else{const u=o.trim();if(e.has(u)){const c=new F;c.setToken(st),c.setLambdaId(r),c.setLambdaPrivacyVar(e),c.setLambdaParameter(u),t[a]=c}}}}};Ze=Xn([er(0,J),er(1,D.Inject(be))],Ze);class Zn 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 L.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()!==st)return r;const e=r,t=e.getCurrentLambdaPrivacyVar(),n=e.getLambdaParameter();if(t)return this._getRootLexerNode(t.get(n))}}class Fr extends re{get zIndex(){return ee.get(L.LAMBDA_PARAMETER)||te}create(r){const e=r.getFunctionDefinitionPrivacyVar(),t=r.getLambdaParameter();return e?new Zn(r.getToken(),t,e):new V(h.SPILL)}checkAndCreateNodeType(r){if(!(!(r instanceof F)||r.getToken().trim()!==st))return this.create(r)}}class Jn extends H{constructor(r){super(r),this._operatorString=r}get nodeType(){return L.NULL}execute(){this.setValue(new Rr(0))}}var es=Object.defineProperty,ts=Object.getOwnPropertyDescriptor,rs=(s,r,e,t)=>{for(var n=t>1?void 0:t?ts(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&&es(r,e,n),n},ns=(s,r)=>(e,t)=>r(e,t,s);class ss extends H{constructor(r,e){super(r),this._operatorString=r,this._functionExecutor=e}get nodeType(){return L.OPERATOR}execute(){const r=this.getChildren();this._functionExecutor.name===j.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 Je=class extends re{constructor(s){super(),this._functionService=s}get zIndex(){return ee.get(L.OPERATOR)||te}create(s){let r="";const e=s;e===G.PLUS?r=j.PLUS:e===G.MINUS?r=j.MINUS:e===G.MULTIPLY?r=j.MULTIPLY:e===G.DIVIDED?r=j.DIVIDED:e===G.CONCATENATE?r=lt.CONCATENATE:e===G.POWER?r=K.POWER:Mr.has(e)&&(r=j.COMPARE);const t=this._functionService.getExecutor(r);return t?new ss(e,t):(console.error(`No function ${s}`),V.create(h.NAME))}checkAndCreateNodeType(s){if(s instanceof F)return;const r=s.trim();if(!(r.charAt(0)==='"'&&r.charAt(r.length-1)==='"')&&Ue.has(r))return this.create(r)}};Je=rs([ns(0,he)],Je);class is 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 kt=D.createIdentifier("univer.formula.super-table.service");class jt extends we{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 Sr(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 as extends we{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 os extends we{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 us extends we{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),c=u.startColumn,l=u.endColumn,f=u.type;let d=-1,E=-1;const A=a.startRow,C=a.startColumn;f===me.ALL?(d=A,E=C):f===me.DATA?(d=A+1,E=C):f===me.HEADERS?(d=A,E=A):f===me.TOTALS&&(d=C,E=C),this.setRangeData({startColumn:c,endColumn:l,startRow:d,endRow:E})}isTable(){return!0}_stringToColumnData(r,e,t){r=r.substring(1,-1);const n=r.indexOf(w.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),c=r.substring(n+1),l=this._columnHandler(c,e,!0);i=l.startColumn,a=l.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(w.COLON);if(new RegExp(_r,"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 cs=Object.defineProperty,ls=Object.getOwnPropertyDescriptor,hs=(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&&cs(r,e,n),n},Oe=(s,r)=>(e,t)=>r(e,t,s);class Pe extends H{constructor(r,e,t){super(e),this._accessor=r,this._operatorString=e,this._referenceObject=t}get nodeType(){return L.REFERENCE}execute(){const r=this._accessor.get(Te),e=this._accessor.get(J);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 et=class extends re{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 ee.get(L.REFERENCE)||te}checkAndCreateNodeType(s){let r=!1,e;if(s instanceof F?(r=!0,e=s.getToken().trim()):e=s.trim(),!r&&e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;if(new RegExp(Lt).test(e))return new Pe(this._injector,e,new jt(e));if(r&&new RegExp(jr).test(e))return new Pe(this._injector,e,new os(e));if(r&&new RegExp($r).test(e))return new Pe(this._injector,e,new as(e));const t=this._formulaRuntimeService.currentUnitId,n=this._superTableService.getTableMap(t),i=new RegExp(_r,"g"),a=e.replace(i,"");if(!r&&(n!=null&&n.has(a))){const o=i.exec(e);let u="";o&&(u=o[0]);const c=n.get(a),l=this._superTableService.getTableOptionMap();return new Pe(this._injector,e,new us(e,c,u,l))}}};et=hs([Oe(0,ht),Oe(1,kt),Oe(2,J),Oe(3,D.Inject(Ee)),Oe(4,D.Inject(D.Injector))],et);var fs=Object.defineProperty,_s=Object.getOwnPropertyDescriptor,ds=(s,r,e,t)=>{for(var n=t>1?void 0:t?_s(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},tr=(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 L.SUFFIX}execute(){let e=this.getChildren()[0].getValue(),t;if(e==null)throw new Error("object is null");this._operatorString===ue.PERCENTAGE?(e.isReferenceObject()&&(e=e.toArrayValueObject()),t=this._functionExecutor.calculate(e,new p(100))):this._operatorString===ue.POUND?t=this._handlerPound(e):t=_.create(h.VALUE),this.setValue(t)}_handlerPound(r){var l,f,d,E;if(!r.isReferenceObject()||!r.isCell())return _.create(h.VALUE);const e=this._accessor.get(Te),t=this._accessor.get(Ee),n=r,i=n.getRangeData(),a=n.getUnitId(),o=n.getSheetId(),u=e.getFormulaData(),c=(E=(d=(f=(l=u==null?void 0:u[a])==null?void 0:l[o])==null?void 0:f[i.startRow])==null?void 0:d[i.startColumn])==null?void 0:E.f;return c&&t.treeBuilder(c),_.create(h.VALUE)}}let tt=class extends re{constructor(s,r){super(),this._functionService=s,this._injector=r}get zIndex(){return ee.get(L.SUFFIX)||te}checkAndCreateNodeType(s){if(!(s instanceof F))return;const r=s.getToken().trim();if(r.charAt(0)==='"'&&r.charAt(r.length-1)==='"')return;let e="";if(r===ue.PERCENTAGE)e=j.DIVIDED;else return r===ue.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}`),V.create(h.NAME))}};tt=ds([tr(0,he),tr(1,D.Inject(D.Injector))],tt);var ms=Object.defineProperty,gs=Object.getOwnPropertyDescriptor,Cs=(s,r,e,t)=>{for(var n=t>1?void 0:t?gs(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&&ms(r,e,n),n},ps=(s,r)=>(e,t)=>r(e,t,s);class Es extends H{constructor(r){super(r),this._operatorString=r}get nodeType(){return L.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===w.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 rt=class extends re{constructor(s){super(),this._functionService=s}get zIndex(){return ee.get(L.UNION)||te}create(s){return new Es(s)}checkAndCreateNodeType(s){if(!(s instanceof F))return;const e=s.getToken().trim();if(!(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')&&e===w.COLON)return this.create(e)}};rt=Cs([ps(0,he)],rt);class Ns extends H{constructor(r){super(r),this._operatorString=r}get nodeType(){return L.VALUE}execute(){this.setValue(ye.create(this._operatorString))}}class Lr extends re{get zIndex(){return ee.get(L.VALUE)||te}_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===Ce.TRUE||e===Ce.FALSE)return this.create(e)}else return this.create(r)}create(r){return new Ns(r)}checkAndCreateNodeType(r){if(!(r instanceof F))return this._checkValueNode(r)}}var As=Object.defineProperty,Rs=Object.getOwnPropertyDescriptor,Ss=(s,r,e,t)=>{for(var n=t>1?void 0:t?Rs(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&&As(r,e,n),n},z=(s,r)=>(e,t)=>r(e,t,s);let xe=class extends m.Disposable{constructor(r,e,t,n,i,a,o,u,c,l,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=c,this._unionNodeFactory=l,this._valueNodeFactory=f,this._initializeAstNode()}dispose(){this._astNodeFactoryList.forEach(r=>{r.dispose()}),this._astNodeFactoryList=[]}parse(r,e=0,t=0){const n=new Dt(oe);return this._refOffsetX=e,this._refOffsetY=t,this._parse(r,n)}_lambdaParameterHandler(r,e){const t=e.getLambdaId(),n=new Dt(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 F)this._parse(d,n);else return!1}const c=n.getChildren(),l=c.length;for(let f=0;f<l;f++){const d=c[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 F;n.setToken(Me);const i=new F;i.setToken(Se);const a=[...e];for(let u=0;u<t;u++){const c=a[u];if(!(c instanceof F))return;u%2===0?c.changeToParent(n):c.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===Hr){const l=this._changeLetToLambda(r);return l!=null?this._parse(l,e):V.create(h.ERROR)}if(o===de){if(a=e,n===0)return new Jn(oe).setParent(e),a}else{if(o===Se){let l=this._lambdaParameterHandler(r,e);return l===!1&&(l=V.create(h.ERROR)),l}if(a=this._checkAstNode(r),a==null)return V.create(h.ERROR)}const u=t[0];for(let l=0;l<n;l++){const f=t[l];if(Dr(u)){if(l!==0&&l!==n-1)continue}else if(qn(f)&&l!==n-1)continue;let d=null;if(f instanceof F){if(d=this._parse(f,a),d===a)continue}else d=this._checkAstNode(f);if(d==null)return V.create(h.ERROR);if(d=this._getTopParent(d),d==null)return;switch(d.nodeType){case L.ERROR:return d;case L.FUNCTION:i.push(d);break;case L.LAMBDA:i.push(d);break;case L.LAMBDA_PARAMETER:i.push(d);break;case L.OPERATOR:{const E=i.pop(),A=i.pop();if(A)A.setParent(d);else return V.create(h.ERROR);if(E)E.setParent(d);else return V.create(h.ERROR);i.push(d);break}case L.REFERENCE:d.setRefOffset(this._refOffsetX,this._refOffsetY),i.push(d);break;case L.ROOT:i.push(d);break;case L.UNION:i.push(d);break;case L.VALUE:i.push(d);break;case L.PREFIX:i.push(d);break;case L.SUFFIX:i.push(d);break}}const c=i.length;for(let l=0;l<c;l++)i[l].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=Ss([z(0,J),z(1,D.Inject(yr)),z(2,D.Inject(We)),z(3,D.Inject(Ze)),z(4,D.Inject(Fr)),z(5,D.Inject(Je)),z(6,D.Inject(Xe)),z(7,D.Inject(et)),z(8,D.Inject(tt)),z(9,D.Inject(rt)),z(10,D.Inject(Lr))],xe);class wr 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 ft=D.createIdentifier("univer.formula.feature-calculation-manager.service");class Tr 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 $t=D.createIdentifier("univer.formula.other-formula-manager.service");class Ct 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 c=this.rangeList[o],{unitId:l,sheetId:f,range:d}=c;if(!e.has(l))continue;const E=e.get(l);if(!E.has(f))continue;const A=E.get(f),C=(i=n==null?void 0:n[l])==null?void 0:i[f];for(const N of A){const{startRow:S,startColumn:y,endRow:T,endColumn:b}=N;if(!(d.startRow>T||d.endRow<S||d.startColumn>b||d.endColumn<y)){let Q=!0;if(C==null||C.forValue((se,Y)=>{if(se>=d.startRow&&se<=d.endRow&&Y>=d.startColumn&&Y<=d.endColumn)return Q=!1,!1}),Q)return!0}}if(((a=t[l])==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 ys=Object.defineProperty,bs=Object.getOwnPropertyDescriptor,Ds=(s,r,e,t)=>{for(var n=t>1?void 0:t?bs(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&&ys(r,e,n),n},fe=(s,r)=>(e,t)=>r(e,t,s);const Fs=1e5,pt=new nt(Fs);let Ie=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(),pt.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 c of u)new m.ObjectMatrix(o[c]).forValue((f,d,E)=>{if(E==null)return!0;const{f:A,x:C,y:N}=E,S=this._generateAstNode(A,C,N),y=new Ct;y.node=S,y.formula=A,y.unitId=a,y.subComponentId=c,y.row=f,y.column=d,i.push(y)})}for(const a of n){const o=e[a],u=Object.keys(o);for(const c of u){const l=o[c],f=Object.keys(l);for(const d of f){const E=l[d],{f:A}=E,C=this._generateAstNode(A),N=new Ct;N.node=C,N.formula=A,N.unitId=a,N.subComponentId=c,N.formulaId=d,i.push(N)}}}this._featureCalculationManagerService.getReferenceExecutorMap().forEach((a,o)=>{const{unitId:u,subComponentId:c,dependencyRanges:l,getDirtyData:f}=a,d=new Ct;d.unitId=u,d.subComponentId=c,d.getDirtyData=f,d.featureId=o,d.rangeList=l,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 c=await this._getRangeListByNode(u.node);for(let l=0,f=c.length;l<f;l++)u.pushRangeList(c[l])}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=pt.get(`${r}##${e}${t}`);if(n)return n;const i=this._lexer.treeBuilder(r);if(i in h)return V.create(i);if(n=this._astTreeBuilder.parse(i,e,t),n==null)throw new Error("astNode is null");return pt.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===L.UNION||r.nodeType===L.PREFIX&&r.getToken()===P.AT||r.nodeType===L.SUFFIX&&r.getToken()===ue.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===L.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===L.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],c=(await this._executeNode(o)).toUnitRange();n.push(c)}for(let i=0,a=t.length;i<a;i++){const o=t[i],c=(await this._executeNode(o)).toUnitRange();n.push(c)}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,c=r.length;u<c;u++){const l=r[u];o!==l&&o.dependency(l)&&o.pushChildren(l)}(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 c,l,f,d;const e=r.unitId,t=r.subComponentId,n=r.featureId;if(n!=null){const E=this._currentConfigService.getDirtyUnitFeatureMap();if(((l=(c=E==null?void 0:E[e])==null?void 0:c[t])==null?void 0:l[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((E,A)=>{if(r.row===E&&r.column===A)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 E of u)if(r.inRangeData(E))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()}};Ie=Ds([m.OnLifecycle(m.LifecycleStages.Rendered,Ie),fe(0,Te),fe(1,J),fe(2,$t),fe(3,ft),fe(4,D.Inject(be)),fe(5,D.Inject(xe)),fe(6,D.Inject(Ee))],Ie);var Ls=Object.defineProperty,ws=Object.getOwnPropertyDescriptor,Ts=(s,r,e,t)=>{for(var n=t>1?void 0:t?ws(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&&Ls(r,e,n),n},_e=(s,r)=>(e,t)=>r(e,t,s);const Os=1;exports.CalculateFormulaService=class extends m.Disposable{constructor(e,t,n,i,a,o,u){super();g(this,"_executionStartListener$",new _t.Subject);g(this,"executionStartListener$",this._executionStartListener$.asObservable());g(this,"_executionCompleteListener$",new _t.Subject);g(this,"executionCompleteListener$",this._executionCompleteListener$.asObservable());g(this,"_executionInProgressListener$",new _t.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")||Os;for(let n=0;n<t&&(await this._execute(),!!this._runtimeService.isCycleDependency());n++);this._runtimeService.setFormulaExecuteStage(W.CALCULATION_COMPLETED),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState()),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData()),St.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 c=new m.ObjectMatrix(o[u]);if(c==null)return!0;const l=new m.ObjectMatrix;c.forValue((f,d,E)=>{l.setValue(f,d,!0),n.push({unitId:a,sheetId:u,range:E})}),i[a]==null&&(i[a]={}),i[a][u]=l})}),Object.keys(t).forEach(a=>{const o=t[a];Object.keys(o).forEach(u=>{const c=o[u];Object.keys(c).forEach(l=>{const f=c[l];if(f==null)return!0;for(const d of f)n.push({unitId:u,sheetId:l,range:d})})})}),{dirtyRanges:n,excludedCell:i}}async _apply(e=!1){e?this._runtimeService.setFormulaExecuteStage(W.START_DEPENDENCY_ARRAY_FORMULA):this._runtimeService.setFormulaExecuteStage(W.START_DEPENDENCY),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());const t=await this._formulaDependencyGenerator.generate(),n=this._interpreter;e?(this._runtimeService.setFormulaExecuteStage(W.START_CALCULATION_ARRAY_FORMULA),this._runtimeService.setTotalArrayFormulasToCalculate(t.length)):(this._runtimeService.setFormulaExecuteStage(W.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(W.IDLE),this._runtimeService.markedAsStopFunctionsExecuted(),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData());return}const o=t[i],u=o.node,c=o.getDirtyData;let l;if(u==null&&c==null)throw new Error("AstNode or executor is null");if(this._runtimeService.setCurrent(o.row,o.column,o.subComponentId,o.unitId),c!=null&&o.featureId!=null){const{runtimeCellData:f,dirtyRanges:d}=c(o);this._runtimeService.setRuntimeFeatureCellData(o.featureId,f),this._runtimeService.setRuntimeFeatureRange(o.featureId,d)}else u!=null&&(n.checkAsyncNode(u)?l=await n.executeAsync(u):l=n.execute(u),o.formulaId!=null?this._runtimeService.setRuntimeOtherData(o.formulaId,l):this._runtimeService.setRuntimeData(l));e?(this._runtimeService.setFormulaExecuteStage(W.CURRENTLY_CALCULATING_ARRAY_FORMULA),this._runtimeService.setCompletedArrayFormulasCount(i+1)):(this._runtimeService.setFormulaExecuteStage(W.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 V.create(n);const i=this._astTreeBuilder.parse(n);console.log("astNode",i==null?void 0:i.serialize())}};exports.CalculateFormulaService=Ts([m.OnLifecycle(m.LifecycleStages.Rendered,exports.CalculateFormulaService),_e(0,m.IConfigService),_e(1,D.Inject(Ee)),_e(2,Te),_e(3,J),_e(4,D.Inject(Ie)),_e(5,D.Inject(be)),_e(6,D.Inject(xe))],exports.CalculateFormulaService);var Us=Object.defineProperty,Is=Object.getOwnPropertyDescriptor,Ms=(s,r,e,t)=>{for(var n=t>1?void 0:t?Is(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);let ke=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===Ut.id)this._calculateFormulaService.stopFormulaExecution();else if(s.id===Mt.id){const e=s.params.formulaData;this._formulaDataModel.setFormulaData(e)}else if(s.id===Ot.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===Ye.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 Re.NOT_EXECUTED:break;case Re.STOP_EXECUTION:break;case Re.SUCCESS:this._applyFormula(s);break;case Re.INITIAL:break}this._commandService.executeCommand(qe.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(qe.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(Ye.id,{arrayFormulaRange:this._formulaDataModel.getArrayFormulaRange(),arrayFormulaCellData:this._formulaDataModel.getArrayFormulaCellData()},{onlyLocal:!0})),this._commandService.executeCommand(It.id,{unitData:r,unitOtherData:e},{onlyLocal:!0})}};ke=Ms([m.OnLifecycle(m.LifecycleStages.Ready,ke),Ve(0,m.ICommandService),Ve(1,D.Inject(exports.CalculateFormulaService)),Ve(2,m.IUniverInstanceService),Ve(3,D.Inject(exports.FormulaDataModel))],ke);class xs extends M{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 p(a+1),new p(o+1));i[a][o]=u}}return new _n(i)}isAsync(){return!0}}const vs=[[xs,Bt.MAKEARRAY]];class Ps extends M{calculate(r,e){return _.create(h.VALUE)}}const Vs=[[Ps,lt.CONCATENATE]],Bs=[],ks=[],js=[],$s=[],Qs=[],Gs=[],Hs=[];class Ys extends M{calculate(r,e){return new jt("A5")}}class qs extends M{calculate(r,e,t,n,i){return new jt("A5")}}const zs=[[Ys,ze.INDIRECT],[qs,ze.OFFSET]];class Ks extends M{calculate(r){return r.isError()?_.create(h.VALUE):(r.isReferenceObject()&&(r=r.toArrayValueObject()),r.abs())}}class Xs extends M{calculate(r){return r.isError()?_.create(h.VALUE):(r.isReferenceObject()&&(r=r.toArrayValueObject()),r.acos())}}class Ws extends M{calculate(r){return r.isError()?_.create(h.VALUE):(r.isReferenceObject()&&(r=r.toArrayValueObject()),r.acosh())}}class Zs extends M{calculate(r){return r.isError()?_.create(h.VALUE):(r.isReferenceObject()&&(r=r.toArrayValueObject()),r.isArray()?r.map(e=>e.isError()?e:nr(e)):nr(r))}}function nr(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 p(e)}class Js extends M{calculate(r,e){return _.create(h.VALUE)}}class ei extends M{calculate(...r){let e=new p(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 ti(s){const r=[R.EQUALS,R.NOT_EQUAL,R.GREATER_THAN_OR_EQUAL,R.GREATER_THAN,R.LESS_THAN_OR_EQUAL,R.LESS_THAN];for(const e of r)if(s.startsWith(e)){const t=s.substring(e.length);return[e,ye.create(t)]}return[R.EQUALS,ye.create(s)]}function ri(s,r){const e=s.toArrayValueObject(),t=`${r.getValue()}`,[n,i]=ti(t);return Zr(t)?e.wildcard(i,n):e.compare(i,n)}class ni extends M{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 p(0);if(e.isReferenceObject()||e.isValueObject()&&e.isArray()){const o=ri(e,t).getArrayValue(),u=n||e,{startRow:c,startColumn:l}=u.getRangePosition();u.iterator((f,d,E)=>{if(!(f!=null&&f.isError())){const C=o[d-c][E-l].getValue()?f:new p(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 p(i),n).getValue()||(r=new p(0))}return r}}class si extends M{calculate(...r){return _.create(h.VALUE)}}const ii=[[Ks,K.ABS],[Xs,K.ACOS],[Ws,K.ACOSH],[Zs,K.ACOT],[ei,K.SUM],[ni,K.SUMIF],[si,K.SUMIFS],[Js,K.POWER]];class ai extends M{constructor(){super(...arguments);g(this,"_compareType",R.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 oi extends M{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 ui extends M{calculate(r,e){return r.isError()||e.isError()?r:(r.isReferenceObject()&&(r=r.toArrayValueObject()),e.isReferenceObject()&&(e=e.toArrayValueObject()),r.minus(e))}}class ci extends M{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 M{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 hi=[[ai,j.COMPARE],[oi,j.DIVIDED],[ui,j.MINUS],[ci,j.MULTIPLY],[li,j.PLUS]];class fi extends M{calculate(...r){let e=new p(0),t=new p(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 p(1)))}return e.divided(t)}}class _i extends M{calculate(...r){let e=new p(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 p(1))))}return e}}class di extends M{calculate(...r){let e=new p(0);for(let t=0;t<r.length;t++){let n=r[t];if(n.isError()){e=e.plus(new p(1));continue}n.isArray()?(n=n.countA(),e=e.plus(n)):n.isNull()||(e=e.plus(new p(1)))}return e}}class mi extends M{calculate(...r){let e=new p(-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 sr extends M{calculate(...r){let e=new p(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 gi=[[fi,ie.AVERAGE],[_i,ie.COUNT],[mi,ie.MAX],[sr,ie.MIN],[sr,ie.MIN],[di,ie.COUNTA]],Ci=[],pi=[],Ei=[];var Ni=Object.defineProperty,Ai=Object.getOwnPropertyDescriptor,Ri=(s,r,e,t)=>{for(var n=t>1?void 0:t?Ai(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&&Ni(r,e,n),n},Et=(s,r)=>(e,t)=>r(e,t,s);let je=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(){[Mt,Ye,Ot,Ut,qe,It,at,ot,wt,Tt,xt,vt,pr,Er,Pt].forEach(s=>this.disposeWithMe(this._commandService.registerCommand(s)))}_registerFunctions(){const s=[...vs,...Vs,...Bs,...ks,...js,...$s,...Qs,...Gs,...Hs,...zs,...ii,...hi,...gi,...Ci,...pi,...Ei].map(r=>{const e=r[0],t=r[1];return new e(t)});this._functionService.registerExecutors(...s)}};je=Ri([m.OnLifecycle(m.LifecycleStages.Ready,je),Et(0,m.ICommandService),Et(1,D.Inject(D.Injector)),Et(2,he)],je);var Si=Object.defineProperty,yi=Object.getOwnPropertyDescriptor,bi=(s,r,e,t)=>{for(var n=t>1?void 0:t?yi(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&&Si(r,e,n),n},ir=(s,r)=>(e,t)=>r(e,t,s);let $e=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===at.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===ot.id){const r=s.params;if(r==null)return;const{unitId:e,name:t}=r;this._definedNamesService.removeDefinedName(e,t)}}))}};$e=bi([m.OnLifecycle(m.LifecycleStages.Ready,$e),ir(0,m.ICommandService),ir(1,ht)],$e);var Di=Object.defineProperty,Fi=Object.getOwnPropertyDescriptor,Li=(s,r,e,t)=>{for(var n=t>1?void 0:t?Fi(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&&Di(r,e,n),n},ar=(s,r)=>(e,t)=>r(e,t,s);let Qe=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===wt.id){const r=s.params;if(r==null)return;const{featureId:e,calculationParam:t}=r;this._featureCalculationManagerService.register(e,t)}else if(s.id===Tt.id){const r=s.params;if(r==null)return;const{featureId:e}=r;this._featureCalculationManagerService.remove(e)}}))}};Qe=Li([m.OnLifecycle(m.LifecycleStages.Ready,Qe),ar(0,m.ICommandService),ar(1,ft)],Qe);var wi=Object.defineProperty,Ti=Object.getOwnPropertyDescriptor,Oi=(s,r,e,t)=>{for(var n=t>1?void 0:t?Ti(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&&wi(r,e,n),n},or=(s,r)=>(e,t)=>r(e,t,s);let Ge=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===xt.id){const r=s.params;if(r==null)return;this._otherFormulaManagerService.register(r)}else if(s.id===vt.id){const r=s.params;if(r==null)return;this._otherFormulaManagerService.remove(r)}}))}};Ge=Oi([m.OnLifecycle(m.LifecycleStages.Ready,Ge),or(0,m.ICommandService),or(1,$t)],Ge);var Ui=Object.defineProperty,Ii=Object.getOwnPropertyDescriptor,Mi=(s,r,e,t)=>{for(var n=t>1?void 0:t?Ii(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&&Ui(r,e,n),n},ur=(s,r)=>(e,t)=>r(e,t,s);let He=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===at.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===ot.id){const r=s.params;if(r==null)return;const{unitId:e,tableName:t}=r;this._superTableService.remove(e,t)}else if(s.id===Pt.id){const r=s.params;if(r==null)return;const{tableOption:e,tableOptionType:t}=r;this._superTableService.registerTableOptionMap(e,t)}}))}};He=Mi([m.OnLifecycle(m.LifecycleStages.Ready,He),ur(0,m.ICommandService),ur(1,kt)],He);var xi=Object.defineProperty,vi=Object.getOwnPropertyDescriptor,Pi=(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&&xi(r,e,n),n},Vi=(s,r)=>(e,t)=>r(e,t,s);const Bi="base-formula-engine";exports.UniverFormulaEnginePlugin=class extends m.Plugin{constructor(r,e){super(Bi),this._config=r,this._injector=e}onStarting(){this._initialize()}_initialize(){var e;const r=[[he,{useClass:br}],[ft,{useClass:wr}],[ht,{useClass:yn}],[exports.FormulaDataModel],[it],[je],[Qe]];(e=this._config)!=null&&e.notExecuteFormula||r.push([exports.CalculateFormulaService],[$t,{useClass:Tr}],[kt,{useClass:is}],[Te,{useClass:yt}],[J,{useClass:bt}],[ke],[$e],[Ge],[He],[Ie],[be],[xe],[Ee],[yr],[We],[Ze],[Fr],[Je],[Xe],[et],[tt],[rt],[Lr]),r.forEach(t=>this._injector.add(t))}onReady(){this._injector.get(exports.FormulaDataModel).initFormulaData()}};exports.UniverFormulaEnginePlugin=Pi([Vi(1,D.Inject(D.Injector))],exports.UniverFormulaEnginePlugin);exports.ArrayValueObject=ne;exports.BaseFunction=M;exports.BaseReferenceObject=we;exports.BaseValueObject=le;exports.BooleanValueObject=$;exports.ErrorType=h;exports.ErrorValueObject=_;exports.FUNCTION_NAMES_ARRAY=Bt;exports.FUNCTION_NAMES_COMPATIBILITY=lt;exports.FUNCTION_NAMES_CUBE=dn;exports.FUNCTION_NAMES_DATABASE=mn;exports.FUNCTION_NAMES_DATE=gn;exports.FUNCTION_NAMES_ENGINEERING=Cn;exports.FUNCTION_NAMES_FINANCIAL=pn;exports.FUNCTION_NAMES_INFORMATION=En;exports.FUNCTION_NAMES_LOGICAL=Nn;exports.FUNCTION_NAMES_LOOKUP=ze;exports.FUNCTION_NAMES_MATH=K;exports.FUNCTION_NAMES_STATISTICAL=ie;exports.FUNCTION_NAMES_TEXT=An;exports.FUNCTION_NAMES_UNIVER=Rn;exports.FUNCTION_NAMES_WEB=Sn;exports.FeatureCalculationManagerService=wr;exports.FormulaExecuteStageType=W;exports.FormulaExecutedStateType=Re;exports.FunctionService=br;exports.FunctionType=lr;exports.IFeatureCalculationManagerService=ft;exports.IFunctionService=he;exports.LexerNode=F;exports.LexerTreeBuilder=it;exports.NumberValueObject=p;exports.OtherFormulaManagerService=Tr;exports.RangeReferenceObject=Sr;exports.RemoveDefinedNameMutation=ot;exports.RemoveFeatureCalculationMutation=Tt;exports.RemoveOtherFormulaMutation=vt;exports.RemoveSuperTableMutation=Er;exports.SetArrayFormulaDataMutation=Ye;exports.SetArrayFormulaDataUndoMutationFactory=Kr;exports.SetDefinedNameMutation=at;exports.SetFeatureCalculationMutation=wt;exports.SetFormulaCalculationNotificationMutation=qe;exports.SetFormulaCalculationResultMutation=It;exports.SetFormulaCalculationStartMutation=Ot;exports.SetFormulaCalculationStopMutation=Ut;exports.SetFormulaDataMutation=Mt;exports.SetOtherFormulaMutation=xt;exports.SetSuperTableMutation=pr;exports.SetSuperTableOptionMutation=Pt;exports.StringValueObject=k;exports.ValueObjectFactory=ye;exports.compareToken=R;exports.convertUnitDataToRuntime=fr;exports.generateStringWithSequence=mr;exports.includeFormulaLexerToken=vr;exports.initSheetFormulaData=Cr;exports.isFormulaLexerToken=Nt;exports.isInDirtyRange=cr;exports.matchToken=w;exports.normalizeSheetName=Pr;exports.sequenceNodeType=q;
|