@univerjs/engine-formula 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(D,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","rxjs"],d):(D=typeof globalThis<"u"?globalThis:D||self,d(D.UniverEngineFormula={},D.UniverCore,D["@wendellhu/redi"],D.rxjs))})(this,function(D,d,B,Ft){"use strict";var Su=Object.defineProperty;var Lu=(D,d,B)=>d in D?Su(D,d,{enumerable:!0,configurable:!0,writable:!0,value:B}):D[d]=B;var p=(D,d,B)=>(Lu(D,typeof d!="symbol"?d+"":d,B),B);function Er(n,r,e,t,s){for(let i=0,a=n.length;i<a;i++){const u=n[i];if(r!==u.unitId||e!==u.sheetId)continue;const{startRow:o,startColumn:l,endRow:f,endColumn:m}=u.range;if(t>=o&&t<=f&&s>=l&&s<=m)return!0}return!1}var c=(n=>(n.DIV_BY_ZERO="#DIV/0!",n.NAME="#NAME?",n.VALUE="#VALUE!",n.NUM="#NUM!",n.NA="#N/A",n.CYCLE="#CYCLE!",n.REF="#REF!",n.SPILL="#SPILL!",n.CALC="#CALC!",n.ERROR="#ERROR!",n.CONNECT="#GETTING_DATA",n.NULL="#NULL!",n))(c||{});const Ne=new Set(Object.values(c));var wr=(n=>(n[n.Financial=0]="Financial",n[n.Date=1]="Date",n[n.Math=2]="Math",n[n.Statistical=3]="Statistical",n[n.Lookup=4]="Lookup",n[n.Database=5]="Database",n[n.Text=6]="Text",n[n.Logical=7]="Logical",n[n.Information=8]="Information",n[n.Engineering=9]="Engineering",n[n.Cube=10]="Cube",n[n.Compatibility=11]="Compatibility",n[n.Web=12]="Web",n[n.Array=13]="Array",n[n.Univer=14]="Univer",n[n.User=15]="User",n))(wr||{}),J=(n=>(n.PLUS="+",n.MINUS="-",n.MULTIPLY="*",n.DIVIDED="/",n.CONCATENATE="&",n.POWER="^",n.EQUALS="=",n.NOT_EQUAL="<>",n.GREATER_THAN=">",n.GREATER_THAN_OR_EQUAL=">=",n.LESS_THAN="<",n.LESS_THAN_OR_EQUAL="<=",n))(J||{}),b=(n=>(n.EQUALS="=",n.NOT_EQUAL="<>",n.GREATER_THAN=">",n.GREATER_THAN_OR_EQUAL=">=",n.LESS_THAN="<",n.LESS_THAN_OR_EQUAL="<=",n))(b||{});const et=new Map([["<>",3],["<",3],[">=",3],["=",3],[">",3],["<=",3],["&",2],["+",2],["-",2],["/",1],["*",1],["^",0]]),He=new Set(et.keys()),zn=new Set(["=","<>",">",">=","<","<="]);var O=(n=>(n.OPEN_BRACKET="(",n.CLOSE_BRACKET=")",n.COMMA=",",n.SINGLE_QUOTATION="'",n.DOUBLE_QUOTATION='"',n.OPEN_BRACES="{",n.CLOSE_BRACES="}",n.COLON=":",n.OPEN_SQUARE_BRACKET="[",n.CLOSE_SQUARE_BRACKET="]",n))(O||{}),he=(n=>(n.PERCENTAGE="%",n.POUND="#",n))(he||{});const Zn=new Set(["%","#"]);var Y=(n=>(n.AT="@",n.MINUS="-",n))(Y||{});const _r=[...Object.values(b),...Object.values(J),...Object.values(O),...Object.values(he),...Object.values(Y)];function tt(n){return _r.includes(n)}function Cr(n){for(const r of _r)if(n.indexOf(r)>-1)return!0;return!1}function Jn(n){return n[0]==="'"&&n[n.length-1]==="'"?n.substring(1,n.length-1):n}function pr(n){const r={};return Object.keys(n).forEach(e=>{const t=n[e];if(t==null)return!0;r[e]==null&&(r[e]={}),Object.keys(t).forEach(s=>{const i=t[s];r[e][s]=new d.ObjectMatrix(i)})}),r}const $t={id:"formula.mutation.register-function",type:d.CommandType.MUTATION,handler:()=>!0};class rt{constructor(r){p(this,"_cache");this._cache=new d.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 d.hashAlgorithm(r)}}const kt='\\[([^\\[\\]\\/?:"<>|*\\\\]+)\\]',Nn="((?![\\[\\]\\/?*\\\\]).)*!",de="$",It="\\s*?:\\s*?",Me=`'?(${kt})?(${Nn})?'?`,Tt=`\\${de}?[A-Za-z]+\\${de}?[0-9]+`,es=`^(${Y.AT})?${Me}${Tt}${It}${Tt}$`,nt=`^${Me}\\s*?${Tt}(${he.POUND})?$`,Dr=`^${Me}\\${de}?[0-9]+${It}\\${de}?[0-9]+$`,yr=`^${Me}\\${de}?[A-Za-z]+${It}\\${de}?[A-Za-z]+$`,ts=`^${Me}\\s*?\\${de}?[0-9]+$`,rs=`^${Me}\\s*?\\${de}?[A-Za-z]+$`,br="[.*?]",ns="{.*?}";function Sr(n){return new RegExp(nt).test(n)||new RegExp(es).test(n)||new RegExp(Dr).test(n)||new RegExp(yr).test(n)}const pe="P_1",Re="R_1",Oe="L_1",je="LR_1",Lr="LO_1",ss="LET",We="LAMBDA",is=/[^0-9]/g,as=/[^A-Za-z]/g;function Xe(n){const r=n[0]==="$",t=n.substring(1).indexOf("$")>-1;return r&&t?d.AbsoluteRefType.ALL:r?d.AbsoluteRefType.COLUMN:t?d.AbsoluteRefType.ROW:d.AbsoluteRefType.NONE}function us(n){const r=n.split("!");r.length>1&&(n=r[r.length-1]);const e=n.split(":");return e.length>1?{startAbsoluteRefType:Xe(e[0]),endAbsoluteRefType:Xe(e[1])}:{startAbsoluteRefType:Xe(e[0])}}function Ar(n=d.AbsoluteRefType.NONE){let r="",e="";return n===d.AbsoluteRefType.ROW?r="$":n===d.AbsoluteRefType.COLUMN?e="$":n===d.AbsoluteRefType.ALL&&(r="$",e="$"),{rowAbsoluteString:r,columnAbsoluteString:e}}function De(n){const{startColumn:r,startRow:e,endColumn:t,endRow:s,startAbsoluteRefType:i,endAbsoluteRefType:a,rangeType:u=d.RANGE_TYPE.NORMAL}=n,o=Ar(i),l=Ar(a);if(u===d.RANGE_TYPE.ROW||u===d.RANGE_TYPE.ALL){const g=`${o.rowAbsoluteString}${e+1}`,R=`${l.rowAbsoluteString}${s+1}`;return`${g}:${R}`}if(u===d.RANGE_TYPE.COLUMN){const g=`${o.columnAbsoluteString}${d.Tools.chatAtABC(r)}`,R=`${l.columnAbsoluteString}${d.Tools.chatAtABC(t)}`;return`${g}:${R}`}const f=`${o.columnAbsoluteString}${d.Tools.chatAtABC(r)}${o.rowAbsoluteString}${e+1}`,m=`${l.columnAbsoluteString}${d.Tools.chatAtABC(t)}${l.rowAbsoluteString}${s+1}`;return f===m?f:`${f}:${m}`}function Pr(n,r){return st(n)?`'${n}'!${De(r)}`:`${n}!${De(r)}`}function Vr(n,r,e){return st(n)||st(r)?`'[${n}]${r}'!${De(e)}`:`[${n}]${r}!${De(e)}`}function xr(n){const{unitId:r,sheetName:e,range:t}=n;return r!=null&&r.length>0&&e!=null&&e.length>0?Vr(r,e,t):e!=null&&e.length>0?Pr(e,t):De(t)}function Qt(n){const r=Number.parseInt(n.replace(is,""))-1,e=d.Tools.ABCatNum(n.replace(as,"")),t=Xe(n);return{row:r,column:e,absoluteRefType:t}}function vr(n){const r=new RegExp(kt).exec(n);let e="";r!=null&&(e=r[0].trim(),e=e.slice(1,e.length-1),n=n.replace(new RegExp(kt),""));const t=n.indexOf("!");let s="",i="";return t>-1?(s=n.substring(0,t),s[0]==="'"&&s[s.length-1]==="'"&&(s=s.substring(1,s.length-1)),i=n.substring(t)):i=n,{refBody:i,sheetName:s,unitId:e}}function Fe(n){const{refBody:r,sheetName:e,unitId:t}=vr(n),s=r.indexOf(":");if(s===-1){const w=Qt(r),E=w.row,C=w.column,y=w.absoluteRefType;return{unitId:t,sheetName:e,range:{startRow:E,startColumn:C,endRow:E,endColumn:C,startAbsoluteRefType:y,endAbsoluteRefType:y}}}const i=r.substring(0,s),a=r.substring(s+1),u=Qt(i),o=Qt(a),l=u.row,f=u.column,m=o.row,g=o.column;let R=d.RANGE_TYPE.NORMAL;return Number.isNaN(l)&&Number.isNaN(m)?R=d.RANGE_TYPE.COLUMN:Number.isNaN(f)&&Number.isNaN(g)&&(R=d.RANGE_TYPE.ROW),{unitId:t,sheetName:e,range:{startRow:l,startColumn:f,endRow:m,endColumn:g,startAbsoluteRefType:u.absoluteRefType,endAbsoluteRefType:o.absoluteRefType,rangeType:R}}}function st(n){return n.length===0?!1:!!(Cr(n)||os(n)||ls(n)||cs(n)||/[\s!$%^&*()+\-=\[\]{};':"\\|,.<>\/?]/.test(n))}function os(n){const r=n.match(/[1-9][0-9]{0,6}/);return/^[A-Z]+[1-9][0-9]{0,6}$/.test(n)&&r!==null&&Number.parseInt(r[0],10)<=1048576}function ls(n){return/^(R(-?[0-9]+)?C(-?[0-9]+)?|C(-?[0-9]+)?|R(-?[0-9]+)?)$/.test(n)}function cs(n){return!new RegExp("^\\p{Letter}","u").test(n.charAt(0))}var te=(n=>(n[n.NORMAL=0]="NORMAL",n[n.NUMBER=1]="NUMBER",n[n.STRING=2]="STRING",n[n.FUNCTION=3]="FUNCTION",n[n.REFERENCE=4]="REFERENCE",n[n.ARRAY=5]="ARRAY",n))(te||{});function Br(n){let r="";for(const e of n)typeof e=="string"?r+=e:r+=e.token;return r}class U{constructor(){p(this,"_parent");p(this,"_token",Re);p(this,"_children",[]);p(this,"_lambdaId");p(this,"_functionDefinitionPrivacyVar");p(this,"_lambdaParameter","");p(this,"_startIndex",-1);p(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=[],s=e.length;for(let i=0;i<s;i++){const a=e[i];a instanceof U?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 s=0;s<t;s++)if(e[s]===r)return s}}const Ur=1e5,Yt=new rt(Ur),Ht=new rt(Ur);class it extends d.Disposable{constructor(){super(...arguments);p(this,"_currentLexerNode",new U);p(this,"_upLevel",0);p(this,"_segment","");p(this,"_bracketState",[]);p(this,"_squareBracketState",0);p(this,"_bracesState",0);p(this,"_singleQuotationState",0);p(this,"_doubleQuotationState",0);p(this,"_lambdaState",!1);p(this,"_colonState",!1);p(this,"_tableBracketState",!1)}dispose(){this._resetTemp(),this._currentLexerNode.dispose(),Yt.clear(),Ht.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 s=this._getCurrentParamIndex(e,t);if(s==null||s===c.VALUE)return;const i=s[0];if(typeof i=="string")return;let a=i.getParent(),u=i;for(;a;){const o=a.getToken();if(o!==pe&&!tt(o)&&a.getStartIndex()!==-1){const l=a.getChildren().indexOf(u);return{functionName:o,paramIndex:l}}u=a,a=a.getParent()}}moveFormulaRefOffset(e,t,s){const i=this.sequenceNodesBuilder(e);if(i==null)return e;const a=[];for(let u=0,o=i.length;u<o;u++){const l=i[u];if(typeof l=="string"||l.nodeType!==te.REFERENCE){a.push(l);continue}const{token:f}=l,m=Fe(f),{range:g,sheetName:R,unitId:w}=m,E=d.Rectangle.moveOffset(g,t,s);let C="";d.isValidRange(E)?C=xr({range:E,unitId:w,sheetName:R}):C=c.REF,a.push({...l,token:C})}return`=${Br(a)}`}checkIfAddBracket(e){let t=0,s=e.length-1,i=e[s];for(;(i===O.CLOSE_BRACKET||i===" ")&&s>=0;)i===O.CLOSE_BRACKET&&t++,i=e[--s];const a=this._getCurrentParamIndex(e,e.length-2);if(a==null||a===c.VALUE)return 0;const u=a[0];if(typeof u=="string")return 0;let o=u.getParent(),l=0;for(a[1]===O.OPEN_BRACKET&&l++;o;){const f=o.getToken();f!==pe&&f!==O.COLON&&o.getStartIndex()!==-1&&f.toUpperCase()!==We&&(t===0?l+=1:t--),o=o.getParent()}return l}sequenceNodesBuilder(e){const t=Ht.get(e);if(t)return[...t];const s=this._getSequenceArray(e);if(s.length===0)return;const i=this.getSequenceNode(s);return Ht.set(e,[...i]),i}getSequenceNode(e){const t=[];let s=!1;for(let i=0,a=e.length;i<a;i++){const u=e[i],o=e[i-1],{segment:l,currentString:f,cur:m}=u;if(f===O.DOUBLE_QUOTATION&&(s=!0),(l!==""||i===0)&&i!==a-1){t.push(f);continue}let g=(o==null?void 0:o.segment)||"";const R=i-g.length;let w=i-1;const E=i-1;if(i===a-1&&this._isLastMergeString(f)&&(g+=f,w+=1),g===""||et.has(g)){t.push(f);continue}const C=g.trim(),y=this._replacePrefixString(C);s===!0&&C[C.length-1]===O.DOUBLE_QUOTATION?(s=!1,this._pushSequenceNode(t,{nodeType:te.STRING,token:g,startIndex:R,endIndex:w},E)):new RegExp(nt).test(y)?this._pushSequenceNode(t,{nodeType:te.REFERENCE,token:g,startIndex:R,endIndex:w},E):d.Tools.isStringNumber(C)?this._pushSequenceNode(t,{nodeType:te.NUMBER,token:g,startIndex:R,endIndex:w},E):C.length>0&&this._pushSequenceNode(t,{nodeType:te.FUNCTION,token:g,startIndex:R,endIndex:w},E),(i!==a-1||!this._isLastMergeString(f))&&t.push(f)}return this._mergeSequenceNodeReference(t)}_getCurrentParamIndex(e,t){return this._nodeMaker(e,void 0,t)}_isLastMergeString(e){return e===O.DOUBLE_QUOTATION||d.Tools.isStringNumber(e)||!tt(e)}_mergeSequenceNodeReference(e){const t=[],s=e.length;let i=0;for(;i<s;){const a=e[i];if(typeof a=="string"){const u=e[i-1];if(a.trim()===O.CLOSE_BRACES&&u!=null&&typeof u!="string"&&u.nodeType===te.FUNCTION&&u.token.trim().substring(0,1)===O.OPEN_BRACES){u.nodeType=te.ARRAY,u.token+=a,u.endIndex+=a.length,i++;continue}t.push(a)}else{const u=e[i+1],o=e[i+2];u===O.COLON&&typeof a!="string"&&o!=null&&typeof o!="string"&&Sr((a.token+u+o.token).trim())&&(a.nodeType=te.REFERENCE,a.token+=u+o.token,a.endIndex=o.endIndex,i+=2),t.push(a)}i++}return t}_pushSequenceNode(e,t,s){const i=s-t.startIndex+1;e.splice(e.length-i,i,t)}_replacePrefixString(e){return e.replace(new RegExp(Y.AT,"g"),"").replace(new RegExp(Y.MINUS,"g"),"")}nodeMakerTest(e){return this._nodeMaker(e)}treeBuilder(e,t=!0,s){if(t===!0){const f=Yt.get(e);if(f)return f}this._resetCurrentLexerNode(),this._currentLexerNode.setToken(Re);const i=[];let a=this._nodeMaker(e,i);if(a===c.VALUE||i.length===0)return a;let u=!1,o="";if(s){const{hasDefinedName:f,sequenceString:m}=s(i);u=f,o=m}if(u&&(this._resetCurrentLexerNode(),this._currentLexerNode.setToken(Re),a=this._nodeMaker(`=${o}`),a===c.VALUE))return a;const l=this._getTopNode(this._currentLexerNode);return l&&(this._currentLexerNode=l),t&&(this._suffixExpressionHandler(this._currentLexerNode),Yt.set(e,this._currentLexerNode)),this._currentLexerNode}_suffixExpressionHandler(e){var u,o;const t=e.getChildren();if(!t)return;const s=t.length,i=[],a=[];for(let l=0;l<s;l++){const f=t[l];if(f instanceof U)this._suffixExpressionHandler(f),i.push(f);else{const m=f.trim();if(m==="")continue;if(He.has(m)){for(;a.length>0;){const g=(u=a[a.length-1])==null?void 0:u.trim();if(!g||g===O.OPEN_BRACKET)break;const R=et.get(g),w=et.get(m);if(!R||!w)break;if(w>=R)i.push(a.pop());else break}a.push(f)}else if(m===O.OPEN_BRACKET)a.push(f);else if(m===O.CLOSE_BRACKET)for(;a.length>0;){const g=(o=a[a.length-1])==null?void 0:o.trim();if(!g)break;if(g===O.OPEN_BRACKET){a.pop();break}i.push(a.pop())}else i.push(f)}}for(;a.length>0;)i.push(a.pop());e.setChildren(i)}_resetCurrentLexerNode(){this._currentLexerNode=new U}_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 U)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 s,i,a,u,o,l;const e=(s=this._currentLexerNode)==null?void 0:s.getParent();let t=!1;if(e&&e.getToken()===Oe){if((i=e==null?void 0:e.getParent())!=null&&i.getParent()){const f=(u=(a=this._currentLexerNode.getParent())==null?void 0:a.getParent())==null?void 0:u.getParent();f&&(this._currentLexerNode=f),t=!0}}else if(e!=null&&e.getParent()){const f=(o=this._currentLexerNode.getParent())==null?void 0:o.getParent();f&&(this._currentLexerNode=f),t=!0}for(let f=0;f<this._upLevel;f++){const m=(l=this._currentLexerNode)==null?void 0:l.getParent();m&&(this._currentLexerNode=m),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 s=this._currentLexerNode.getChildren();if(!(e instanceof U)&&this.isColonOpen()){const i=new U;i.setToken(e),i.setParent(this._currentLexerNode),e=i}t?s.unshift(e):s.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,s=!1){const i=new U;i.setToken(e),i.setIndex(t-e.length,t-1),this._setCurrentLexerNode(i,s)}_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 s=e[t];if(s!==" ")return s;t--}}_negativeCondition(e){return!!(He.has(e)||e===O.OPEN_BRACKET||e===O.COMMA||e==="")}_getSequenceArray(e){const t=[];return this._nodeMaker(e,t),t}_resetTemp(){this._currentLexerNode=new U,this._upLevel=0,this._segment="",this._bracketState=[],this._bracesState=0,this._singleQuotationState=0,this._doubleQuotationState=0,this._lambdaState=!1,this._colonState=!1}_checkSimilarErrorToken(e,t,s){if(e!==he.POUND)return!0;let i=s[++t];for(;i===" ";)i=s[++t];return!!tt(i)}_nodeMaker(e,t,s){e.substring(0,1)===J.EQUALS&&(e=e.substring(1));const i=e.split(""),a=i.length;let u=0;for(this._resetTemp();u<a;){const o=i[u];if(s===u)return[this._currentLexerNode,o];if(o===O.OPEN_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())if(this._segmentCount()>0||this.isLambdaOpen()){this.isLambdaClose()&&(this._newAndPushCurrentLexerNode(this._segment,u),this._resetSegment()),this._openBracket(1),this._closeLambda();const l=i[u+1];if(l&&l===O.CLOSE_BRACKET){if(!this._setParentCurrentLexerNode()&&u!==a-1)return c.VALUE;u++}else l&&this._newAndPushCurrentLexerNode(pe,u)}else this._pushNodeToChildren(o),this._openBracket(0);else if(o===O.CLOSE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()){this._pushNodeToChildren(this._segment),this._resetSegment();const l=this._getCurrentBracket();if(l===0)this._pushNodeToChildren(o);else if(l===1){const f=i[u+1];if(f&&f===O.OPEN_BRACKET){if(!this._setParentCurrentLexerNode()&&u!==a-1)return c.VALUE;this._newAndPushCurrentLexerNode(Oe,u,!0),this._openLambda()}else if(!this._setAncestorCurrentLexerNode()&&u!==a-1)return c.VALUE}else return c.VALUE;this._closeBracket()}else if(o===O.OPEN_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(o),this._openBraces();else if(o===O.CLOSE_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(o),this._pushNodeToChildren(this._segment),this._resetSegment(),this._closeBraces();else if(o===O.OPEN_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._segment.length>0&&this._openTableBracket(),this._pushSegment(o),this._openSquareBracket();else if(o===O.CLOSE_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._closeSquareBracket(),this.isSquareBracketClose()?(this._pushSegment(o),this._isTableBracket()&&(this._pushNodeToChildren(this._segment),this._resetSegment()),this._closeTableBracket()):this._pushSegment(o);else if(o===O.DOUBLE_QUOTATION&&this.isSingleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){if(this.isDoubleQuotationClose())this._openDoubleQuotation();else{const l=i[u+1];l&&l===O.DOUBLE_QUOTATION?u++:this._closeDoubleQuotation()}this._pushSegment(o)}else if(o===O.SINGLE_QUOTATION&&this.isDoubleQuotationClose()){if(this.isSingleQuotationClose())this._openSingleQuotation();else{const l=i[u+1];l&&l===O.SINGLE_QUOTATION?u++:this._closeSingleQuotation()}this._pushSegment(o)}else if(o===O.COMMA&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=this._getCurrentBracket();if(l===1||l==null){if(this._pushNodeToChildren(this._segment),this._resetSegment(),!this._setParentCurrentLexerNode()&&u!==a-1&&l!=null)return c.VALUE;this._newAndPushCurrentLexerNode(pe,u)}else return c.VALUE}else if(o===O.COLON&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=new U;l.setToken(o);const f=new U;f.setToken(pe),f.setParent(l);const m=new U;m.setToken(pe),m.setParent(l),l.getChildren().push(f,m);let g=l,R=0;if(this._segmentCount()>0){let w,E,C=0;const y=this._segment.trim(),S=y[0],L=y[1];if(S===Y.MINUS&&(w=new U,w.setToken(Y.MINUS),C++),(S===Y.AT||L===Y.AT)&&(E=new U,E.setToken(Y.AT),w&&(w.addChildren(E),E.setParent(w)),C++),C>0&&(this._segment=y.slice(C)),R=C,E)if(E.addChildren(l),l.setParent(E),E.getParent()){const I=E.getParent();I&&(g=I)}else g=E;else w&&(g=w,w.addChildren(l),l.setParent(w));const V=new U;V.setToken(this._segment),V.setParent(f),f.getChildren().push(V),this._resetSegment()}else{const w=this._getLastChildCurrentLexerNode();w&&w.changeToParent(f)}this._setCurrentLexerNode(g),this._currentLexerNode=m,this._openColon(R)}else if(Zn.has(o)&&this._checkSimilarErrorToken(o,u,i)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){this._pushNodeToChildren(this._segment);const l=new U;l.setToken(o);const f=this._getLastChildCurrent();f instanceof U?f.changeToParent(l):f!==!1&&(l.getChildren().push(f),this._removeLastChild()),this._pushNodeToChildren(l),l.setParent(this._currentLexerNode),this._resetSegment()}else if(He.has(o)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){let l=this._segment.trim();if(o===J.MINUS&&l===""){const f=this._findPreviousToken(i,u-1)||"";if(this._negativeCondition(f)){this._pushSegment(J.MINUS),t==null||t.push({segment:this._segment,currentString:o,cur:u,currentLexerNode:this._currentLexerNode}),u++;continue}}else this._segment.length>0&&l===""?l=this._segment:(this._pushNodeToChildren(this._segment),l="");if(o===J.LESS_THAN||o===J.GREATER_THAN){const f=i[u+1];f&&He.has(o+f)?(this._pushNodeToChildren(l+o+f),u++):this._pushNodeToChildren(l+o)}else this._pushNodeToChildren(l+o);this._resetSegment()}else this._pushSegment(o);t==null||t.push({segment:this._segment,currentString:o,cur:u,currentLexerNode:this._currentLexerNode}),u++}this._pushNodeToChildren(this._segment)}}var fs=Object.defineProperty,hs=Object.getOwnPropertyDescriptor,ms=(n,r,e,t)=>{for(var s=t>1?void 0:t?hs(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&fs(r,e,s),s},Mr=(n,r)=>(e,t)=>r(e,t,n);D.FormulaDataModel=class extends d.Disposable{constructor(e,t){super();p(this,"_formulaData",{});p(this,"_arrayFormulaRange",{});p(this,"_arrayFormulaCellData",{});p(this,"_numfmtItemMap",{});this._currentUniverService=e,this._lexerTreeBuilder=t}clearPreviousArrayFormulaCellData(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;Object.keys(s).forEach(i=>{var l,f,m,g;const a=s[i],u=(f=(l=this._arrayFormulaRange)==null?void 0:l[t])==null?void 0:f[i];if(u==null)return!0;let o=new d.ObjectMatrix;((m=this._arrayFormulaCellData[t])==null?void 0:m[i])!=null&&(o=new d.ObjectMatrix((g=this._arrayFormulaCellData[t])==null?void 0:g[i])),a.forValue((R,w)=>{var V;const E=(V=u==null?void 0:u[R])==null?void 0:V[w];if(E==null)return!0;const{startRow:C,startColumn:y,endRow:S,endColumn:L}=E;for(let I=C;I<=S;I++)for(let Q=y;Q<=L;Q++)o.setValue(I,Q,null)}),this._arrayFormulaCellData[t]&&(this._arrayFormulaCellData[t][i]=o.getData())})})}mergeArrayFormulaCellData(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;this._arrayFormulaRange[t]==null&&(this._arrayFormulaRange[t]={}),this._arrayFormulaCellData[t]==null&&(this._arrayFormulaCellData[t]={}),Object.keys(s).forEach(i=>{var l,f,m,g;const a=s[i];let u=new d.ObjectMatrix,o=new d.ObjectMatrix;((l=this._arrayFormulaRange[t])==null?void 0:l[i])!=null&&(u=new d.ObjectMatrix((f=this._arrayFormulaRange[t])==null?void 0:f[i])),((m=this._arrayFormulaCellData[t])==null?void 0:m[i])!=null&&(o=new d.ObjectMatrix((g=this._arrayFormulaCellData[t])==null?void 0:g[i])),a.forValue((R,w)=>{const E=u==null?void 0:u.getValue(R,w);if(E==null)return!0;const{startRow:C,startColumn:y,endRow:S,endColumn:L}=E;for(let V=C;V<=S;V++)for(let I=y;I<=L;I++)o.setValue(V,I,null)}),a.forValue((R,w,E)=>{o.setValue(R,w,E)}),this._arrayFormulaCellData[t]&&(this._arrayFormulaCellData[t][i]=o.getData())})})}getFormulaData(){return this._formulaData}setFormulaData(e){this._formulaData=e}getArrayFormulaRange(){return this._arrayFormulaRange}setArrayFormulaRange(e){this._arrayFormulaRange=e}getArrayFormulaCellData(){return this._arrayFormulaCellData}setArrayFormulaCellData(e){this._arrayFormulaCellData=e}getNumfmtItemMap(){return this._numfmtItemMap}getNumfmtValue(e,t,s,i){var a,u,o;return(o=(u=(a=this._numfmtItemMap[e])==null?void 0:a[t])==null?void 0:u[s])==null?void 0:o[i]}setNumfmtItemMap(e){this._numfmtItemMap=e}updateNumfmtItemMap(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;this._numfmtItemMap[t]==null&&(this._numfmtItemMap[t]={}),Object.keys(s).forEach(i=>{const a=s[i],u=new d.ObjectMatrix(a);this._numfmtItemMap[t][i]==null&&(this._numfmtItemMap[t][i]={}),u.forValue((o,l,f)=>{this._numfmtItemMap[t][i][o]==null&&(this._numfmtItemMap[t][i][o]={}),this._numfmtItemMap[t][i][o][l]=f})})})}mergeArrayFormulaRange(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;this._arrayFormulaRange[t]||(this._arrayFormulaRange[t]={}),Object.keys(s).forEach(i=>{var o,l;const a=new d.ObjectMatrix(s[i]);let u=new d.ObjectMatrix;(o=this._arrayFormulaRange[t])!=null&&o[i]&&(u=new d.ObjectMatrix((l=this._arrayFormulaRange[t])==null?void 0:l[i])),a.forValue((f,m,g)=>{u.setValue(f,m,g)}),this._arrayFormulaRange[t]&&(this._arrayFormulaRange[t][i]=u.getData())})})}deleteArrayFormulaRange(e,t,s,i){var o;const a=(o=this._arrayFormulaRange[e])==null?void 0:o[t];if(a==null)return;const u=new d.ObjectMatrix(a);u.getValue(s,i)&&(u.realDeleteValue(s,i),this._arrayFormulaRange[e]&&(this._arrayFormulaRange[e][t]=u.getData()))}initFormulaData(){if(this._currentUniverService.getAllUniverSheetsInstance().length===0)return;const t=this._currentUniverService.getCurrentUniverSheetInstance(),s=t.getUnitId();this._formulaData[s]={},t.getSheets().forEach(a=>{const u=a.getCellMatrix(),o=a.getSheetId();Or(this._formulaData,s,o,u)})}getCalculateData(){const e=this._currentUniverService.getAllUniverSheetsInstance(),t={},s={};for(const i of e){const a=i.getUnitId(),u=i.getSheets(),o={},l={};for(const f of u){const m=f.getSheetId(),g=f.getConfig();o[m]={cellData:new d.ObjectMatrix(g.cellData),rowCount:g.rowCount,columnCount:g.columnCount,rowData:g.rowData,columnData:g.columnData},l[f.getName()]=f.getSheetId()}t[a]=o,s[a]=l}return{allUnitData:t,unitSheetNameMap:s}}updateFormulaData(e,t,s){const i=new d.ObjectMatrix(s),a=this.getFormulaIdMap(e,t),u=new Map,o=this._formulaData;o[e]==null&&(o[e]={});const l=o[e];l[t]==null&&(l[t]={});const f=new d.ObjectMatrix(l[t]);i.forValue((m,g,R)=>{const w=(R==null?void 0:R.f)||"",E=(R==null?void 0:R.si)||"",C=d.isFormulaString(w),y=d.isFormulaId(E);if(C&&y)f.setValue(m,g,{f:w,si:E}),a.set(E,{f:w,r:m,c:g});else if(C&&!y)f.setValue(m,g,{f:w});else if(!C&&y)f.setValue(m,g,{f:"",si:E});else if(!C&&!y&&f.getValue(m,g)){const S=f.getValue(m,g),L=(S==null?void 0:S.f)||"",V=(S==null?void 0:S.si)||"";d.isFormulaString(L)&&d.isFormulaId(V)&&u.set(V,L),f.realDeleteValue(m,g)}}),f.forValue((m,g,R)=>{const w=(R==null?void 0:R.f)||"",E=(R==null?void 0:R.si)||"";if(d.isFormulaId(E)){const C=a.get(E),y=u.get(E);if(C&&!d.isFormulaString(w)){const S=C.f,L=g-C.c,V=m-C.r;f.setValue(m,g,{f:S,si:E,x:L,y:V})}else if(typeof y=="string"){const S=R.x||0,L=R.y||0,V=this._lexerTreeBuilder.moveFormulaRefOffset(y,S,L);u.set(E,{r:m,c:g,f:V}),f.setValue(m,g,{f:V,si:E})}else if(typeof y=="object"){const S=g-y.c,L=m-y.r;f.setValue(m,g,{f:y.f,si:E,x:S,y:L})}}})}updateArrayFormulaRange(e,t,s){var o;const i=(o=this._arrayFormulaRange[e])==null?void 0:o[t];if(!i)return;const a=new d.ObjectMatrix(i);new d.ObjectMatrix(s).forValue((l,f,m)=>{if((a==null?void 0:a.getValue(l,f))==null)return!0;const R=(m==null?void 0:m.f)||"",w=(m==null?void 0:m.si)||"",E=d.isFormulaString(R),C=d.isFormulaId(w);!E&&!C&&a.realDeleteValue(l,f)})}updateArrayFormulaCellData(e,t,s){var f,m;const i=(f=this._arrayFormulaRange[e])==null?void 0:f[t];if(!i)return;const a=new d.ObjectMatrix(i),u=(m=this._arrayFormulaCellData[e])==null?void 0:m[t];if(!u)return;const o=new d.ObjectMatrix(u);new d.ObjectMatrix(s).forValue((g,R,w)=>{const E=a==null?void 0:a.getValue(g,R);if(E==null)return!0;const C=(w==null?void 0:w.f)||"",y=(w==null?void 0:w.si)||"",S=d.isFormulaString(C),L=d.isFormulaId(y);if(!S&&!L){const{startRow:V,startColumn:I,endRow:Q,endColumn:T}=E;for(let x=V;x<=Q;x++)for(let v=I;v<=T;v++)o.realDeleteValue(x,v)}})}updateNumfmtData(e,t,s){var f,m;const i=(f=this._arrayFormulaRange[e])==null?void 0:f[t],a=new d.ObjectMatrix(i),u=(m=this._numfmtItemMap[e])==null?void 0:m[t];if(!u)return;const o=new d.ObjectMatrix(u);new d.ObjectMatrix(s).forValue((g,R,w)=>{const E=(w==null?void 0:w.f)||"",C=(w==null?void 0:w.si)||"",y=d.isFormulaString(E),S=d.isFormulaId(C);if(!y&&!S){o.setValue(g,R,null);const L=a.getValue(g,R);if(L){const{startRow:V,startColumn:I,endRow:Q,endColumn:T}=L;for(let x=V;x<=Q;x++)for(let v=I;v<=T;v++)o.setValue(x,v,null)}}})}getFormulaItemBySId(e,t,s){const i=this._formulaData;if(i[s]==null)return null;const a=i[s];if((a==null?void 0:a[t])==null)return null;const u=new d.ObjectMatrix(a[t]);let o=null;return u.forValue((l,f,m)=>{const{f:g,si:R,x:w=0,y:E=0}=m;if(R===e&&g.length>0&&w===0&&E===0)return o=m,!1}),o}getFormulaDataItem(e,t,s,i){var a,u,o,l;return(l=(o=(u=(a=this._formulaData)==null?void 0:a[i])==null?void 0:u[s])==null?void 0:o[e])==null?void 0:l[t]}getFormulaIdMap(e,t){const s=new Map,i=this._formulaData;if(i[e]==null)return s;const a=i[e];return(a==null?void 0:a[t])==null||new d.ObjectMatrix(a[t]).forValue((o,l,f)=>{const m=(f==null?void 0:f.f)||"",g=(f==null?void 0:f.si)||"",R=(f==null?void 0:f.x)||0,w=(f==null?void 0:f.y)||0;d.isFormulaString(m)&&d.isFormulaId(g)&&R===0&&w===0&&s.set(g,{f:m,r:o,c:l})}),s}},D.FormulaDataModel=ms([Mr(0,d.IUniverInstanceService),Mr(1,B.Inject(it))],D.FormulaDataModel);function Or(n,r,e,t){const s=new Map,i=new d.ObjectMatrix;t.forValue((a,u,o)=>{const l=(o==null?void 0:o.f)||"",f=(o==null?void 0:o.si)||"",m=d.isFormulaString(l),g=d.isFormulaId(f);m&&g?(i.setValue(a,u,{f:l,si:f}),s.set(f,{f:l,r:a,c:u})):m&&!g?i.setValue(a,u,{f:l}):!m&&g&&i.setValue(a,u,{f:"",si:f})}),i.forValue((a,u,o)=>{const l=(o==null?void 0:o.f)||"",f=(o==null?void 0:o.si)||"";if(d.isFormulaId(f)&&!d.isFormulaString(l)){const m=s.get(f);if(m){const g=m.f,R=u-m.c,w=a-m.r;i.setValue(a,u,{f:g,si:f,x:R,y:w})}}}),n[r]&&(n[r][e]=i.getData())}const gs=n=>{const r=n.get(D.FormulaDataModel),e=d.Tools.deepClone(r.getArrayFormulaRange()),t=d.Tools.deepClone(r.getArrayFormulaCellData());return{arrayFormulaRange:e,arrayFormulaCellData:t}},at={id:"formula.mutation.set-array-formula-data",type:d.CommandType.MUTATION,handler:(n,r)=>{const e=n.get(D.FormulaDataModel);return e.setArrayFormulaRange(r.arrayFormulaRange),e.setArrayFormulaCellData(r.arrayFormulaCellData),!0}},ut={id:"formula.mutation.set-defined-name",type:d.CommandType.MUTATION,handler:()=>!0},ot={id:"formula.mutation.remove-defined-name",type:d.CommandType.MUTATION,handler:()=>!0},jt={id:"formula.mutation.set-feature-calculation",type:d.CommandType.MUTATION,handler:()=>!0},Wt={id:"formula.mutation.remove-feature-calculation",type:d.CommandType.MUTATION,handler:()=>!0},Xt={id:"formula.mutation.set-formula-calculation-start",type:d.CommandType.MUTATION,handler:()=>!0},Gt={id:"formula.mutation.set-formula-calculation-stop",type:d.CommandType.MUTATION,handler:()=>!0},lt={id:"formula.mutation.set-formula-calculation-notification",type:d.CommandType.MUTATION,handler:()=>!0},Kt={id:"formula.mutation.set-formula-calculation-result",type:d.CommandType.MUTATION,handler:()=>!0},qt={id:"formula.mutation.set-formula-data",type:d.CommandType.MUTATION,handler:(n,r)=>(n.get(D.FormulaDataModel).setFormulaData(r.formulaData),!0)},zt={id:"formula.mutation.set-other-formula",type:d.CommandType.MUTATION,handler:()=>!0},Zt={id:"formula.mutation.remove-other-formula",type:d.CommandType.MUTATION,handler:()=>!0},Fr={id:"formula.mutation.set-super-table",type:d.CommandType.MUTATION,handler:()=>!0},$r={id:"formula.mutation.remove-super-table",type:d.CommandType.MUTATION,handler:()=>!0},Jt={id:"formula.mutation.set-super-table-option",type:d.CommandType.MUTATION,handler:()=>!0},Nt={id:"formula.mutation.unregister-function",type:d.CommandType.MUTATION,handler:()=>!0};class ct extends d.Disposable{constructor(){super(...arguments);p(this,"pattern","")}getPattern(){return this.pattern}setPattern(e){this.pattern=e}isError(){return!1}isAsyncObject(){return!1}isAsyncArrayObject(){return!1}isReferenceObject(){return!1}isValueObject(){return!1}isEqualType(e){return!1}}var ye=(n=>(n.FALSE="FALSE",n.TRUE="TRUE",n))(ye||{}),be=(n=>(n[n.SUCCESS=0]="SUCCESS",n[n.ERROR=1]="ERROR",n))(be||{}),Se=(n=>(n.ALL="#All",n.DATA="#Data",n.HEADERS="#Headers",n.TOTALS="#Totals",n))(Se||{}),re=(n=>(n[n.FRONT=0]="FRONT",n[n.BACK=1]="BACK",n))(re||{});class ds{constructor(){p(this,"_cache",new Map);p(this,"_continueBuildingCache",new Map)}set(r,e,t,s,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 u=a.get(e);u==null&&(u=new Map,a.set(e,u));let o=u.get(t);o==null&&(o=new Map,u.set(t,o));let l=o.get(s);l==null&&(l=[],o.set(s,l)),l.push(i)}getCellValuePositions(r,e,t){var s,i;return(i=(s=this._cache.get(r))==null?void 0:s.get(e))==null?void 0:i.get(t)}getCellPositions(r,e,t,s){var i,a,u;return(u=(a=(i=this._cache.get(r))==null?void 0:i.get(e))==null?void 0:a.get(t))==null?void 0:u.get(s)}getCellPosition(r,e,t,s,i,a){const u=this.getCellPositions(r,e,t,s);if(u!=null){for(const o of u)if(o>=i&&o<=a)return o}}setContinueBuildingCache(r,e,t,s,i){let a=this._continueBuildingCache.get(r);a==null&&(a=new Map,this._continueBuildingCache.set(r,a));let u=a.get(e);u==null&&(u=new Map,a.set(e,u));let o=u.get(t);if(o==null){o={startRow:s,endRow:i},u.set(t,o);return}o.startRow=Math.min(o.startRow,s),o.endRow=Math.max(o.endRow,i)}shouldContinueBuildingCache(r,e,t,s){var o,l;const i=(l=(o=this._continueBuildingCache.get(r))==null?void 0:o.get(e))==null?void 0:l.get(t);if(i==null)return!0;const{startRow:a,endRow:u}=i;return!(s>=a&&s<=u)}canUseCache(r,e,t,s,i){var l,f;if(t===-1||s===-1||i===-1)return!1;const a=(f=(l=this._continueBuildingCache.get(r))==null?void 0:l.get(e))==null?void 0:f.get(t);if(a==null)return!1;const{startRow:u,endRow:o}=a;return!(s>o||i<u)}clear(){this._cache.clear(),this._continueBuildingCache.clear()}}const Ee=new ds;var me=(n=>(n[n.MIN=0]="MIN",n[n.MAX=1]="MAX",n))(me||{}),q=(n=>(n[n.NORMAL=0]="NORMAL",n[n.MIN=1]="MIN",n[n.MAX=2]="MAX",n))(q||{});function kr(){return Intl&&Intl.Collator?new Intl.Collator(void 0,{numeric:!1}).compare:(n,r)=>n.localeCompare(r)}function Rs(n){return n.indexOf("*")>-1||n.indexOf("?")>-1}function Ir(n,r){const e=r.replace(/~?[*?]/g,s=>s.startsWith("~")?`\\${s.substring(1)}`:s==="*"?".*":s==="?"?".":s);return new RegExp(`^${e}$`).test(n)}function Tr(n){return n.replace(/~?[*?]/g,r=>r.startsWith("~")?r.substring(1):" ")}function Es(n,r,e){let t=!1;switch(e){case b.EQUALS:t=Ir(n,r);break;case b.GREATER_THAN:case b.GREATER_THAN_OR_EQUAL:t=Ir(n,r)||n>Tr(r);break;case b.LESS_THAN:case b.LESS_THAN_OR_EQUAL:t=n<Tr(r);break}return t}class we extends ct{constructor(r){super(),this._rawValue=r}isValueObject(){return!0}toUnitRange(){return{range:{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1},sheetId:"",unitId:""}}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}sum(){return new h(c.VALUE)}max(){return new h(c.VALUE)}min(){return new h(c.VALUE)}count(){return new h(c.VALUE)}countA(){return new h(c.VALUE)}countBlank(){return new h(c.VALUE)}getNegative(){return new h(c.NAME)}getReciprocal(){return new h(c.NAME)}plus(r){return new h(c.NAME)}minus(r){return new h(c.NAME)}multiply(r){return new h(c.NAME)}divided(r){return new h(c.NAME)}mod(r){return new h(c.VALUE)}map(r){return new h(c.NAME)}mapValue(r){return new h(c.NAME)}product(r,e){return e(this,r)}compare(r,e){return new h(c.NAME)}isEqual(r){return this.compare(r,b.EQUALS)}isNotEqual(r){return this.compare(r,b.NOT_EQUAL)}isGreaterThanOrEqual(r){return this.compare(r,b.GREATER_THAN_OR_EQUAL)}isLessThanOrEqual(r){return this.compare(r,b.LESS_THAN_OR_EQUAL)}isLessThan(r){return this.compare(r,b.LESS_THAN)}isGreaterThan(r){return this.compare(r,b.GREATER_THAN)}concatenateFront(r){return new h(c.NAME)}concatenateBack(r){return new h(c.NAME)}plusBy(r){return new h(c.NAME)}minusBy(r){return new h(c.NAME)}multiplyBy(r){return new h(c.NAME)}dividedBy(r){return new h(c.NAME)}modInverse(r){return new h(c.VALUE)}compareBy(r,e){return new h(c.NAME)}concatenate(r,e=re.FRONT){let t=this.getValue().toString();if(typeof r=="string")e===re.FRONT?t=r+t:t+=r;else if(typeof r=="number")e===re.FRONT?t=r.toString()+t:t+=r.toString();else if(typeof r=="boolean"){const s=r?"TRUE":"FALSE";e===re.FRONT?t=s+t:t+=s}return t}pow(r){return new h(c.VALUE)}powInverse(r){return new h(c.VALUE)}sqrt(){return new h(c.VALUE)}cbrt(){return new h(c.VALUE)}cos(){return new h(c.VALUE)}acos(){return new h(c.VALUE)}acosh(){return new h(c.VALUE)}sin(){return new h(c.VALUE)}asin(){return new h(c.VALUE)}asinh(){return new h(c.VALUE)}tan(){return new h(c.VALUE)}tanh(){return new h(c.VALUE)}atan(){return new h(c.VALUE)}atan2(r){return new h(c.VALUE)}atan2Inverse(r){return new h(c.VALUE)}atanh(){return new h(c.VALUE)}mean(){return this}median(){return this}var(){return this}std(){return this}log(){return new h(c.VALUE)}log10(){return new h(c.VALUE)}exp(){return new h(c.VALUE)}abs(){return new h(c.VALUE)}round(r){return new h(c.VALUE)}roundInverse(r){return new h(c.VALUE)}floor(r){return new h(c.VALUE)}floorInverse(r){return new h(c.VALUE)}ceil(r){return new h(c.VALUE)}ceilInverse(r){return new h(c.VALUE)}}class h extends we{constructor(r,e=""){super(r),this._errorType=r,this._errorContent=e}getValue(){return this._errorType}getErrorType(){return this._errorType}getErrorContent(){return this._errorContent}isEqualType(r){return r.getErrorType()===this.getErrorType()}isError(){return!0}}var ws=20,_s=1,Le=1e6,Qr=1e6,Cs=-7,ps=21,Ds=!1,Ge="[big.js] ",Ae=Ge+"Invalid ",ft=Ae+"decimal places",ys=Ae+"rounding mode",Yr=Ge+"Division by zero",F={},ae=void 0,bs=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function Hr(){function n(r){var e=this;if(!(e instanceof n))return r===ae?Hr():new n(r);if(r instanceof n)e.s=r.s,e.e=r.e,e.c=r.c.slice();else{if(typeof r!="string"){if(n.strict===!0&&typeof r!="bigint")throw TypeError(Ae+"value");r=r===0&&1/r<0?"-0":String(r)}Ss(e,r)}e.constructor=n}return n.prototype=F,n.DP=ws,n.RM=_s,n.NE=Cs,n.PE=ps,n.strict=Ds,n.roundDown=0,n.roundHalfUp=1,n.roundHalfEven=2,n.roundUp=3,n}function Ss(n,r){var e,t,s;if(!bs.test(r))throw Error(Ae+"number");for(n.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),s=r.length,t=0;t<s&&r.charAt(t)=="0";)++t;if(t==s)n.c=[n.e=0];else{for(;s>0&&r.charAt(--s)=="0";);for(n.e=e-t-1,n.c=[],e=0;t<=s;)n.c[e++]=+r.charAt(t++)}return n}function Pe(n,r,e,t){var s=n.c;if(e===ae&&(e=n.constructor.RM),e!==0&&e!==1&&e!==2&&e!==3)throw Error(ys);if(r<1)t=e===3&&(t||!!s[0])||r===0&&(e===1&&s[0]>=5||e===2&&(s[0]>5||s[0]===5&&(t||s[1]!==ae))),s.length=1,t?(n.e=n.e-r+1,s[0]=1):s[0]=n.e=0;else if(r<s.length){if(t=e===1&&s[r]>=5||e===2&&(s[r]>5||s[r]===5&&(t||s[r+1]!==ae||s[r-1]&1))||e===3&&(t||!!s[0]),s.length=r,t){for(;++s[--r]>9;)if(s[r]=0,r===0){++n.e,s.unshift(1);break}}for(r=s.length;!s[--r];)s.pop()}return n}function $e(n,r,e){var t=n.e,s=n.c.join(""),i=s.length;if(r)s=s.charAt(0)+(i>1?"."+s.slice(1):"")+(t<0?"e":"e+")+t;else if(t<0){for(;++t;)s="0"+s;s="0."+s}else if(t>0)if(++t>i)for(t-=i;t--;)s+="0";else t<i&&(s=s.slice(0,t)+"."+s.slice(t));else i>1&&(s=s.charAt(0)+"."+s.slice(1));return n.s<0&&e?"-"+s:s}F.abs=function(){var n=new this.constructor(this);return n.s=1,n},F.cmp=function(n){var r,e=this,t=e.c,s=(n=new e.constructor(n)).c,i=e.s,a=n.s,u=e.e,o=n.e;if(!t[0]||!s[0])return t[0]?i:s[0]?-a:0;if(i!=a)return i;if(r=i<0,u!=o)return u>o^r?1:-1;for(a=(u=t.length)<(o=s.length)?u:o,i=-1;++i<a;)if(t[i]!=s[i])return t[i]>s[i]^r?1:-1;return u==o?0:u>o^r?1:-1},F.div=function(n){var r=this,e=r.constructor,t=r.c,s=(n=new e(n)).c,i=r.s==n.s?1:-1,a=e.DP;if(a!==~~a||a<0||a>Le)throw Error(ft);if(!s[0])throw Error(Yr);if(!t[0])return n.s=i,n.c=[n.e=0],n;var u,o,l,f,m,g=s.slice(),R=u=s.length,w=t.length,E=t.slice(0,u),C=E.length,y=n,S=y.c=[],L=0,V=a+(y.e=r.e-n.e)+1;for(y.s=i,i=V<0?0:V,g.unshift(0);C++<u;)E.push(0);do{for(l=0;l<10;l++){if(u!=(C=E.length))f=u>C?1:-1;else for(m=-1,f=0;++m<u;)if(s[m]!=E[m]){f=s[m]>E[m]?1:-1;break}if(f<0){for(o=C==u?s:g;C;){if(E[--C]<o[C]){for(m=C;m&&!E[--m];)E[m]=9;--E[m],E[C]+=10}E[C]-=o[C]}for(;!E[0];)E.shift()}else break}S[L++]=f?l:++l,E[0]&&f?E[C]=t[R]||0:E=[t[R]]}while((R++<w||E[0]!==ae)&&i--);return!S[0]&&L!=1&&(S.shift(),y.e--,V--),L>V&&Pe(y,V,e.RM,E[0]!==ae),y},F.eq=function(n){return this.cmp(n)===0},F.gt=function(n){return this.cmp(n)>0},F.gte=function(n){return this.cmp(n)>-1},F.lt=function(n){return this.cmp(n)<0},F.lte=function(n){return this.cmp(n)<1},F.minus=F.sub=function(n){var r,e,t,s,i=this,a=i.constructor,u=i.s,o=(n=new a(n)).s;if(u!=o)return n.s=-o,i.plus(n);var l=i.c.slice(),f=i.e,m=n.c,g=n.e;if(!l[0]||!m[0])return m[0]?n.s=-o:l[0]?n=new a(i):n.s=1,n;if(u=f-g){for((s=u<0)?(u=-u,t=l):(g=f,t=m),t.reverse(),o=u;o--;)t.push(0);t.reverse()}else for(e=((s=l.length<m.length)?l:m).length,u=o=0;o<e;o++)if(l[o]!=m[o]){s=l[o]<m[o];break}if(s&&(t=l,l=m,m=t,n.s=-n.s),(o=(e=m.length)-(r=l.length))>0)for(;o--;)l[r++]=0;for(o=r;e>u;){if(l[--e]<m[e]){for(r=e;r&&!l[--r];)l[r]=9;--l[r],l[e]+=10}l[e]-=m[e]}for(;l[--o]===0;)l.pop();for(;l[0]===0;)l.shift(),--g;return l[0]||(n.s=1,l=[g=0]),n.c=l,n.e=g,n},F.mod=function(n){var r,e=this,t=e.constructor,s=e.s,i=(n=new t(n)).s;if(!n.c[0])throw Error(Yr);return e.s=n.s=1,r=n.cmp(e)==1,e.s=s,n.s=i,r?new t(e):(s=t.DP,i=t.RM,t.DP=t.RM=0,e=e.div(n),t.DP=s,t.RM=i,this.minus(e.times(n)))},F.neg=function(){var n=new this.constructor(this);return n.s=-n.s,n},F.plus=F.add=function(n){var r,e,t,s=this,i=s.constructor;if(n=new i(n),s.s!=n.s)return n.s=-n.s,s.minus(n);var a=s.e,u=s.c,o=n.e,l=n.c;if(!u[0]||!l[0])return l[0]||(u[0]?n=new i(s):n.s=s.s),n;if(u=u.slice(),r=a-o){for(r>0?(o=a,t=l):(r=-r,t=u),t.reverse();r--;)t.push(0);t.reverse()}for(u.length-l.length<0&&(t=l,l=u,u=t),r=l.length,e=0;r;u[r]%=10)e=(u[--r]=u[r]+l[r]+e)/10|0;for(e&&(u.unshift(e),++o),r=u.length;u[--r]===0;)u.pop();return n.c=u,n.e=o,n},F.pow=function(n){var r=this,e=new r.constructor("1"),t=e,s=n<0;if(n!==~~n||n<-Qr||n>Qr)throw Error(Ae+"exponent");for(s&&(n=-n);n&1&&(t=t.times(r)),n>>=1,!!n;)r=r.times(r);return s?e.div(t):t},F.prec=function(n,r){if(n!==~~n||n<1||n>Le)throw Error(Ae+"precision");return Pe(new this.constructor(this),n,r)},F.round=function(n,r){if(n===ae)n=0;else if(n!==~~n||n<-Le||n>Le)throw Error(ft);return Pe(new this.constructor(this),n+this.e+1,r)},F.sqrt=function(){var n,r,e,t=this,s=t.constructor,i=t.s,a=t.e,u=new s("0.5");if(!t.c[0])return new s(t);if(i<0)throw Error(Ge+"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),n=new s((i==1/0?"5e":(i=i.toExponential()).slice(0,i.indexOf("e")+1))+a)):n=new s(i+""),a=n.e+(s.DP+=4);do e=n,n=u.times(e.plus(t.div(e)));while(e.c.slice(0,a).join("")!==n.c.slice(0,a).join(""));return Pe(n,(s.DP-=4)+n.e+1,s.RM)},F.times=F.mul=function(n){var r,e=this,t=e.constructor,s=e.c,i=(n=new t(n)).c,a=s.length,u=i.length,o=e.e,l=n.e;if(n.s=e.s==n.s?1:-1,!s[0]||!i[0])return n.c=[n.e=0],n;for(n.e=o+l,a<u&&(r=s,s=i,i=r,l=a,a=u,u=l),r=new Array(l=a+u);l--;)r[l]=0;for(o=u;o--;){for(u=0,l=a+o;l>o;)u=r[l]+i[o]*s[l-o-1]+u,r[l--]=u%10,u=u/10|0;r[l]=u}for(u?++n.e:r.shift(),o=r.length;!r[--o];)r.pop();return n.c=r,n},F.toExponential=function(n,r){var e=this,t=e.c[0];if(n!==ae){if(n!==~~n||n<0||n>Le)throw Error(ft);for(e=Pe(new e.constructor(e),++n,r);e.c.length<n;)e.c.push(0)}return $e(e,!0,!!t)},F.toFixed=function(n,r){var e=this,t=e.c[0];if(n!==ae){if(n!==~~n||n<0||n>Le)throw Error(ft);for(e=Pe(new e.constructor(e),n+e.e+1,r),n=n+e.e+1;e.c.length<n;)e.c.push(0)}return $e(e,!1,!!t)},F[Symbol.for("nodejs.util.inspect.custom")]=F.toJSON=F.toString=function(){var n=this,r=n.constructor;return $e(n,n.e<=r.NE||n.e>=r.PE,!!n.c[0])},F.toNumber=function(){var n=Number($e(this,!0,!0));if(this.constructor.strict===!0&&!this.eq(n.toString()))throw Error(Ge+"Imprecise conversion");return n},F.toPrecision=function(n,r){var e=this,t=e.constructor,s=e.c[0];if(n!==ae){if(n!==~~n||n<1||n>Le)throw Error(Ae+"precision");for(e=Pe(new t(e),n,r);e.c.length<n;)e.c.push(0)}return $e(e,n<=e.e||e.e<=t.NE||e.e>=t.PE,!!s)},F.valueOf=function(){var n=this,r=n.constructor;if(r.strict===!0)throw Error(Ge+"valueOf disallowed");return $e(n,n.e<=r.NE||n.e>=r.PE,!0)};var H=Hr();function jr(n){let r;switch(n){case b.EQUALS:r=b.EQUALS;break;case b.GREATER_THAN:r=b.LESS_THAN;break;case b.GREATER_THAN_OR_EQUAL:r=b.LESS_THAN_OR_EQUAL;break;case b.LESS_THAN:r=b.GREATER_THAN;break;case b.LESS_THAN_OR_EQUAL:r=b.GREATER_THAN_OR_EQUAL;break;case b.NOT_EQUAL:r=b.NOT_EQUAL;break}return r}function er(n,r){return H(n).times(r).toNumber()}function Wr(n,r){const e=10**Math.floor(r);return Math.round(er(n,e))/e}function Xr(n,r){const e=10**Math.floor(r);return Math.floor(er(n,e))/e}function Gr(n,r){const e=10**Math.floor(r);return Math.ceil(er(n,e))/e}function Kr(n,r){const e=new H(n),t=new H(r),s=Math.floor(n/r);return e.minus(t.times(s)).toNumber()}function qr(n,r){return n**r}class ue extends we{isNull(){return!0}plus(r){return new _(0,!0).plus(r)}minus(r){return new _(0,!0).minus(r)}multiply(r){return new _(0,!0).multiply(r)}divided(r){return new _(0,!0).divided(r)}mod(r){return new _(0,!0).mod(r)}compare(r,e){return r.isString()?new X("").compare(r,e):r.isBoolean()?new P(!1).compare(r,e):new _(0,!0).compare(r,e)}concatenateFront(r){return r.isArray()?r.concatenateBack(new X("")):new X(this.concatenate(r.getValue(),re.FRONT))}concatenateBack(r){return r.isArray()?r.concatenateFront(new X("")):new X(this.concatenate(r.getValue(),re.BACK))}plusBy(r){return new _(0).plusBy(r)}minusBy(r){return new _(0).minusBy(r)}multiplyBy(r){return new _(0).multiplyBy(r)}dividedBy(r){return new _(0).dividedBy(r)}compareBy(r,e){return typeof r=="string"?new X("").compareBy(r,e):typeof r=="boolean"?new P(!1).compareBy(r,e):new _(0,!0).compareBy(r,e)}pow(r){return new _(0,!0).pow(r)}sqrt(){return new _(0,!0).sqrt()}cbrt(){return new _(0,!0).cbrt()}cos(){return new _(0,!0).cos()}acos(){return new _(0,!0).acos()}acosh(){return new _(0,!0).acosh()}sin(){return new _(0,!0).sin()}asin(){return new _(0,!0).asin()}asinh(){return new _(0,!0).asinh()}tan(){return new _(0,!0).tan()}tanh(){return new _(0,!0).tanh()}atan(){return new _(0,!0).atan()}atan2(r){return new _(0,!0).atan2(r)}atanh(){return new _(0,!0).atanh()}log(){return new h(c.NUM)}log10(){return new h(c.NUM)}exp(){return new _(0,!0).exp()}abs(){return new _(0,!0).abs()}round(r){return new _(0,!0).round(r)}floor(r){return new _(0,!0).floor(r)}ceil(r){return new _(0,!0).ceil(r)}}class P extends we{constructor(e,t=!1){super(e);p(this,"_value",!1);if(t){this._value=e;return}if(typeof e=="boolean")this._value=e;else if(typeof e=="string"){const s=e.toLocaleUpperCase();s===ye.TRUE?this._value=!0:s===ye.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 _(-t,!0)}getReciprocal(){return this.getValue()?new _(1,!0):new h(c.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)}mod(e){return this._convertTonNumber().mod(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 _(t,!0)}pow(e){return this._convertTonNumber().pow(e)}sqrt(){return this._convertTonNumber().sqrt()}cbrt(){return this._convertTonNumber().cbrt()}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 _ extends we{constructor(e,t=!1){super(e);p(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 _(0).minus(this)}getReciprocal(){return new _(1).divided(this)}plus(e){if(e.isArray())return e.plus(this);const t=this.plusBy(e.getValue());return t.isError()||t.setPattern(this.getPattern()||e.getPattern()),t}equalZero(){return this._value===0}minus(e){if(e.isArray()){const s=e.getNegative();return s.isError()?s:s.plus(this)}const t=this.minusBy(e.getValue());return t.isError()?this:(t.setPattern(this.getPattern()||e.getPattern()),t)}multiply(e){if(e.isArray())return e.multiply(this);const t=this.multiplyBy(e.getValue());return t.setPattern(this.getPattern()||e.getPattern()),t}divided(e){if(e.isArray()){const s=e.getReciprocal();return s.isError()?s:s.multiply(this)}const t=this.dividedBy(e.getValue());return t.setPattern(this.getPattern()||e.getPattern()),t}mod(e){if(e.isArray())return e.modInverse(this);const t=this.getValue(),s=e.getValue();if(e.isNull())return new h(c.DIV_BY_ZERO);if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(s===0)return new h(c.DIV_BY_ZERO);if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=Kr(t,s);return Number.isFinite(i)?new _(i):new h(c.NUM)}if(typeof s=="boolean"){const i=s?1:0;return i===0?new h(c.DIV_BY_ZERO):new _(Kr(t,i))}return this}concatenateFront(e){return e.isArray()?e.concatenateBack(this):new X(this.concatenate(e.getValue(),re.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new X(this.concatenate(e.getValue(),re.BACK))}compare(e,t){return e.isArray()?e.compare(this,jr(t)):this.compareBy(e.getValue(),t)}plusBy(e){const t=this.getValue();if(typeof e=="string")return Ne.has(e)?new h(e):new h(c.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return new h(c.NUM);const s=H(t).plus(e).toNumber();return Number.isFinite(s)?new _(s):new h(c.NUM)}return typeof e=="boolean"?new _(H(t).plus(e?1:0).toNumber()):this}minusBy(e){const t=this.getValue();if(typeof e=="string")return new h(c.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return new h(c.NUM);const s=H(t).minus(e).toNumber();return Number.isFinite(s)?new _(s):new h(c.NUM)}return typeof e=="boolean"?new _(H(t).minus(e?1:0).toNumber()):this}multiplyBy(e){const t=this.getValue();if(typeof e=="string")return new h(c.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return new h(c.NUM);const s=H(t).times(e).toNumber();return Number.isFinite(s)?new _(s):new h(c.NUM)}return typeof e=="boolean"?new _(H(t).times(e?1:0).toNumber()):this}dividedBy(e){const t=this.getValue();if(typeof e=="string")return new h(c.VALUE);if(typeof e=="number"){if(e===0)return new h(c.DIV_BY_ZERO);if(!Number.isFinite(t)||!Number.isFinite(e))return new h(c.NUM);const s=H(t).div(e).toNumber();return Number.isFinite(s)?new _(s):new h(c.NUM)}return typeof e=="boolean"?e===!1?new h(c.DIV_BY_ZERO):new _(H(t).div(1).toNumber()):this}compareBy(e,t){const s=this.getValue();let i=!1;if(typeof e=="string")switch(t){case b.EQUALS:case b.GREATER_THAN:case b.GREATER_THAN_OR_EQUAL:i=!1;break;case b.LESS_THAN:case b.LESS_THAN_OR_EQUAL:case b.NOT_EQUAL:i=!0;break}else if(typeof e=="number")if(!Number.isFinite(s)||!Number.isFinite(e))i=this._compareInfinity(s,e,t);else switch(t){case b.EQUALS:i=H(s).eq(e);break;case b.GREATER_THAN:i=H(s).gt(e);break;case b.GREATER_THAN_OR_EQUAL:i=H(s).gte(e);break;case b.LESS_THAN:i=H(s).lt(e);break;case b.LESS_THAN_OR_EQUAL:i=H(s).lte(e);break;case b.NOT_EQUAL:i=!H(s).eq(e);break}else if(typeof e=="boolean")switch(t){case b.EQUALS:case b.GREATER_THAN:case b.GREATER_THAN_OR_EQUAL:i=!1;break;case b.LESS_THAN:case b.LESS_THAN_OR_EQUAL:case b.NOT_EQUAL:i=!0;break}return new P(i)}pow(e){if(e.isArray())return e.powInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=qr(t,s);return Number.isFinite(i)?new _(i):new h(c.NUM)}return typeof s=="boolean"?new _(qr(t,s?1:0)):this}sqrt(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=H(e).sqrt().toNumber();return Number.isFinite(t)?new _(t):new h(c.NUM)}cbrt(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.cbrt(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}cos(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.cos(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}acos(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.acos(e);return Number.isNaN(t)?new h(c.NUM):new _(t)}acosh(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.acosh(e);return Number.isNaN(t)?new h(c.NUM):new _(t)}sin(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.sin(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}asin(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.asin(e);return Number.isNaN(t)?new h(c.NUM):new _(t)}asinh(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.asinh(e);return Number.isNaN(t)?new h(c.NUM):new _(t)}tan(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.tan(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}tanh(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.tanh(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}atan(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.atan(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}atan2(e){if(e.isArray())return e.atan2Inverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=Math.atan2(t,s);return Number.isFinite(i)?new _(i):new h(c.NUM)}return typeof s=="boolean"?new _(Math.atan2(t,s?1:0)):this}atanh(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.atanh(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}log(){const e=this.getValue();if(typeof e=="number"&&e<=0)return new h(c.NUM);if(!Number.isFinite(e))return new h(c.NUM);const t=Math.log(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}log10(){const e=this.getValue();if(typeof e=="number"&&e<=0)return new h(c.NUM);if(!Number.isFinite(e))return new h(c.NUM);const t=Math.log10(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}exp(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.exp(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}abs(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.abs(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}round(e){if(e.isArray())return e.roundInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=Wr(t,s);return Number.isFinite(i)?new _(i):new h(c.NUM)}return typeof s=="boolean"?new _(Wr(t,s?1:0)):this}floor(e){if(e.isArray())return e.floorInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=Xr(t,s);return Number.isFinite(i)?new _(i):new h(c.NUM)}return typeof s=="boolean"?new _(Xr(t,s?1:0)):this}ceil(e){if(e.isArray())return e.ceilInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=Gr(t,s);return Number.isFinite(i)?new _(i):new h(c.NUM)}return typeof s=="boolean"?new _(Gr(t,s?1:0)):this}_compareInfinity(e,t,s){let i=!1;switch(s){case b.EQUALS:i=e===t;break;case b.GREATER_THAN:i=e>t;break;case b.GREATER_THAN_OR_EQUAL:i=e>=t;break;case b.LESS_THAN:i=e<t;break;case b.LESS_THAN_OR_EQUAL:i=e<=t;break;case b.NOT_EQUAL:i=e!==t;break}return i}}class X extends we{constructor(e,t=!1){super(e);p(this,"_value");if(t){this._value=e;return}let s=e.toString();s.charAt(0)==='"'&&s.charAt(s.length-1)==='"'&&(s=s.slice(1,-1),s=s.replace(/""/g,'"')),this._value=s}getValue(){return this._value}isString(){return!0}concatenateFront(e){return e.isArray()?e.concatenateBack(this):new X(this.concatenate(e.getValue(),re.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new X(this.concatenate(e.getValue(),re.BACK))}compare(e,t){return e.isArray()?e.compare(this,jr(t)):this.compareBy(e.getValue(),t)}compareBy(e,t){const s=this.getValue();let i=!1;if(typeof e=="string"){if(Rs(e))return this._checkWildcard(e,t);switch(t){case b.EQUALS:i=s===e;break;case b.GREATER_THAN:i=s>e;break;case b.GREATER_THAN_OR_EQUAL:i=s>=e;break;case b.LESS_THAN:i=s<e;break;case b.LESS_THAN_OR_EQUAL:i=s<=e;break;case b.NOT_EQUAL:i=s!==e;break}}else if(typeof e=="number")switch(t){case b.NOT_EQUAL:case b.GREATER_THAN:case b.GREATER_THAN_OR_EQUAL:i=!0;break;case b.EQUALS:case b.LESS_THAN:case b.LESS_THAN_OR_EQUAL:i=!1;break}else if(typeof e=="boolean")switch(t){case b.EQUALS:case b.GREATER_THAN:case b.GREATER_THAN_OR_EQUAL:i=!1;break;case b.LESS_THAN:case b.LESS_THAN_OR_EQUAL:case b.NOT_EQUAL:i=!0;break}return new P(i)}_checkWildcard(e,t){const s=this.getValue().toLocaleLowerCase(),i=Es(s,e,t);return new P(i)}}function Ls(n){return""}function As(n=[]){const r=[];for(let e=0;e<n.length;e++){const t=n[e];r[e]==null&&(r[e]=[]);for(let s=0;s<t.length;s++){const i=t[s];r[e][s]=_e.create(i)}}return r}function Ps(n=[]){const r=[];for(let e=0;e<n.length;e++){const t=n[e];r[e]==null&&(r[e]=[]);for(let s=0;s<t.length;s++){const i=t[s];i.isError()?r[e][s]=i.getErrorType():r[e][s]=i.getValue()}}return r}class z extends we{constructor(e){super(typeof e=="string"?e:Ls());p(this,"_values",[]);p(this,"_rowCount",-1);p(this,"_columnCount",-1);p(this,"_unitId","");p(this,"_sheetId","");p(this,"_currentRow",-1);p(this,"_currentColumn",-1);p(this,"_sliceCache",new Map);p(this,"_flattenCache");p(this,"_flattenPosition");this._values=this._formatValue(e)}dispose(){this._values.forEach(e=>{e.forEach(t=>{t.dispose()})}),this._values=[],this._clearCache()}clone(){return this.map(e=>e)}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._values}setArrayValue(e){this._clearCache(),this._values=e}isArray(){return!0}get(e,t){const s=this._values[e];if(s==null)return new ue(0);const i=s[t];return i==null?new ue(0):i}getRealValue(e,t){const s=this._values[e];if(s==null)return null;const i=s[t];return i==null?null:i}set(e,t,s){if(e>=this._rowCount||t>=this._columnCount)throw new Error("Exceeding array bounds.");this._clearCache(),this._values[e][t]=s}getRangePosition(){const t=this.getRowCount(),s=0,i=this.getColumnCount();return{startRow:0,endRow:t-1,startColumn:s,endColumn:i-1}}iterator(e){const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),u=this.getArrayValue();for(let o=t;o<=s;o++)for(let l=i;l<=a;l++)if(e(u[o][l],o,l)===!1)return}iteratorReverse(e){const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),u=this.getArrayValue();for(let o=s;o>=t;o--)for(let l=a;l>=i;l--)if(e(u[o][l],o,l)===!1)return}getLastTruePosition(){let e;return this.iteratorReverse((t,s,i)=>{if(t!=null&&t.isBoolean()&&t.getValue()===!0)return e={row:s,column:i},!1}),e}getFirstTruePosition(){let e;return this.iterator((t,s,i)=>{if(t!=null&&t.isBoolean()&&t.getValue()===!0)return e={row:s,column:i},!1}),e}getFirstCell(){const{startRow:e,startColumn:t}=this.getRangePosition();return this.get(e,t)}getLastCell(){const{endRow:e,endColumn:t}=this.getRangePosition();return this.get(e,t)}pick(e){const t=e.getRowCount(),s=e.getColumnCount();if(t!==this._rowCount||s!==this._columnCount)return this._createNewArray([[new ue(0)]],1,1);const i=[];i[0]=[];for(let a=0;a<t;a++)for(let u=0;u<s;u++){const o=e.get(a,u),l=this.get(a,u);o.isError()||o.getValue()===!0&&i[0].push(l)}return this._createNewArray(i,1,i[0].length)}flatten(){if(this._flattenCache!=null)return this._flattenCache;const e=[];e[0]=[];for(let s=0;s<this._rowCount;s++)for(let i=0;i<this._columnCount;i++){const a=this.get(s,i);e[0].push(a)}const t=this._createNewArray(e,1,e[0].length);return this._flattenCache=t,t}flattenPosition(){if(this._flattenPosition!=null)return this._flattenPosition;const e=[],t=[],s=[],i=[];let a=0;for(let o=0;o<this._rowCount;o++)for(let l=0;l<this._columnCount;l++){const f=this.get(o,l);if(f.isError()||f.isNull()){a++;continue}f.isString()?(e.push(f),s.push(a++)):(t.push(f),i.push(a++))}const u={stringArray:e,numberArray:t,stringPosition:s,numberPosition:i};return this._flattenPosition=u,u}slice(e,t){let s=0,i=this._rowCount,a=1,u=0,o=this._columnCount,l=1;if(e!=null&&(s=e[0]||0,i=e[1]||this._rowCount,a=e[2]||1),t!=null&&(u=t[0]||0,o=t[1]||this._columnCount,l=t[2]||1),s>=this._rowCount||u>=this._columnCount)return;const f=`${s}_${i}_${a}_${u}_${o}_${l}`,m=this._sliceCache.get(f);if(m!=null)return m;const g=[],R=this._values;let w=0,E=0;for(let L=s;L<i;L+=a){E=0,g[w]==null&&(g[w]=[]);for(let V=u;V<o;V+=l)g[w][E]=R[L][V],E++;w++}if(g.length===0||g[0].length===0)return;const C=a>1?-1:s+this._currentRow,y=l>1?-1:u+this._currentColumn,S=this._createNewArray(g,g.length,g[0].length,C,y);return this._sliceCache.set(f,S),S}sortByRow(e){const t=this._transposeArray(this._values);t.sort(this._sort(e)),this._clearCache(),this._values=this._transposeArray(t)}sortByColumn(e){this._clearCache(),this._values.sort(this._sort(e))}transpose(){const e=this._transposeArray(this._values),t=this._rowCount,s=this._columnCount;return this._createNewArray(e,s,t)}orderSearch(e,t=q.MIN,s=!1,i=!1){let a,u,o,l;const f=(m,g,R)=>{if(m==null)return!0;let w;if(i===!0?w=m.compare(e,b.EQUALS):w=m.isEqual(e),(w==null?void 0:w.getValue())===!0)return a=m,o={row:g,column:R},!1;t===q.MAX?m.isGreaterThan(e).getValue()===!0&&(u==null||m.minus(e).abs().isLessThanOrEqual(u.minus(e).abs()).getValue()===!0)&&(u=m,l={row:g,column:R}):t===q.MIN&&m.isLessThan(e).getValue()===!0&&(u==null||m.minus(e).abs().isLessThanOrEqual(u.minus(e).abs()).getValue()===!0)&&(u=m,l={row:g,column:R})};if(s){const m=this._values.length;if(this._values[0]==null)return;const g=this._values[0].length;for(let R=m-1;R>=0;R--)for(let w=g-1;w>=0;w--){const E=this._values[R][w];f(E,R,w)}}else this.iterator((m,g,R)=>{f(m,g,R)});if(a!=null)return o;if(u!=null)return l}binarySearch(e,t=me.MIN){if(e.isError())return;const{stringArray:s,stringPosition:i,numberArray:a,numberPosition:u}=this.flattenPosition();return e.isString()?this._binarySearch(e,s,i,t):this._binarySearch(e,a,u,t)}_binarySearch(e,t,s,i=me.MIN){const a=kr(),u=e.getValue().toString();let o=0,l=t.length-1,f=null;for(;o<=l;){const m=Math.floor((o+l)/2),g=t[m];let R=0;if(g.isNull())R=1;else{const w=g.getValue();R=a(w.toString(),u)}if(R===0)return s[m];R===-1?(o=m+1,i===me.MIN&&(f=m)):(l=m-1,i===me.MAX&&(f=m))}if(f!=null)return s[f]}sum(){let e=new _(0);return this.iterator(t=>{if(t==null||t.isString()||t.isBoolean()||t.isNull())return!0;if(t.isError())return e=t,!1;e=e.plus(t)}),e}max(){let e=new _(Number.NEGATIVE_INFINITY);return this.iterator(t=>{if(t==null)return!0;if(t.isError())return e=t,!1;if(t.isString()||t.isNull()||t.isBoolean())return!0;e.isLessThan(t).getValue()&&(e=t)}),e}min(){let e=new _(Number.POSITIVE_INFINITY);return this.iterator(t=>{if(t==null)return!0;if(t.isError())return e=t,!1;if(t.isString()||t.isNull()||t.isBoolean())return!0;e.isGreaterThan(t).getValue()&&(e=t)}),e}count(){let e=new _(0);return this.iterator(t=>{if(t==null||t.isError()||t.isString()||t.isNull()||t.isBoolean())return!0;e=e.plusBy(1)}),e}countA(){let e=new _(0);return this.iterator(t=>{if(t==null||t.isNull())return!0;e=e.plusBy(1)}),e}countBlank(){let e=new _(0);return this.iterator(t=>{if(t!=null&&!t.isNull())return!0;e=e.plusBy(1)}),e}getNegative(){return new z("{0}").minus(this)}getReciprocal(){return new z("{1}").divided(this)}plus(e){return this._batchOperator(e,1)}minus(e){return this._batchOperator(e,0)}multiply(e){return this._batchOperator(e,2)}divided(e){return this._batchOperator(e,3)}mod(e){return this._batchOperator(e,4)}modInverse(e){return this.map(t=>t.isError()?t:e.mod(t))}compare(e,t){return this._batchOperator(e,5,t)}concatenateFront(e){return this._batchOperator(e,6)}concatenateBack(e){return this._batchOperator(e,7)}product(e,t){return this._batchOperator(e,8,t)}map(e){const t=(s,i,a)=>s.isError()?s:e(s,i,a);return this.mapValue(t)}mapValue(e){var a,u;const t=this._rowCount,s=this._columnCount,i=[];for(let o=0;o<t;o++){const l=[];for(let f=0;f<s;f++){const m=(u=(a=this._values)==null?void 0:a[o])==null?void 0:u[f];m?l[f]=e(m,o,f):l[f]=new h(c.VALUE)}i.push(l)}return this._createNewArray(i,t,s)}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(e=0){const t=this.sum(),s=this.count();return t.divided(e===0?s:s.minusBy(1))}median(){const e=this.flattenPosition().numberArray,t=this._createNewArray([e],1,e.length),s=t.getColumnCount();if(s<=1)return t.get(0,0);if(t.sortByRow(0),s%2===0){const i=t.get(0,s/2),a=t.get(0,s/2-1);return i.plus(a).divided(new _(2,!0))}return t.get(0,(s-1)/2)}var(e=0){const t=this.mean(),s=[[]];this.iterator(f=>{if(f==null||f.isError()||f.isString()||f.isBoolean()||f.isNull())return;const m=f.minus(t).pow(new _(2,!0));m.isError()||s[0].push(m)});const{_unitId:i,_sheetId:a,_currentRow:u,_currentColumn:o}=this;return new z({calculateValueList:s,rowCount:1,columnCount:s[0].length,unitId:i,sheetId:a,row:u,column:o}).mean(e)}std(e=0){const t=this.var(e);return t.isError()?t:t.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 Ps(this._values)}_clearCache(){this._flattenCache=null,this._sliceCache.clear()}_sort(e){const t=kr();return(s,i)=>{const a=s[e],u=i[e];return a.isError()&&a.isError()?0:a.isError()?1:u.isError()?-1:t(a.getValue(),u.getValue())}}_transposeArray(e){const t=e.length,s=e[0].length,i=[];for(let a=0;a<s;a++){i[a]=[];for(let u=0;u<t;u++)i[a][u]=e[u][a]}return i}_batchOperator(e,t,s){const i=[];let a=this._rowCount,u=this._columnCount;if(e.isArray()){const l=e.getRowCount(),f=e.getColumnCount();if(a=Math.max(l,a),u=Math.max(f,u),l===1&&f===1){const m=e.getFirstCell();for(let g=0;g<u;g++)i.push(m)}else if(l===1&&this._columnCount>1){const m=e.getArrayValue();for(let g=0;g<u;g++)i.push(m[0][g])}else return this._batchOperatorArray(e,t,s)}else for(let l=0;l<u;l++)i.push(e);const o=[];for(let l=0;l<u;l++){const f=i[l];this._batchOperatorValue(f,l,o,t,s)}return this._createNewArray(o,a,u)}_batchOperatorValue(e,t,s,i,a){var R,w;const u=this._rowCount;let o=!1;const l=this.getUnitId(),f=this.getSheetId(),m=this.getCurrentRow(),g=this.getCurrentColumn();if(i===5&&(o=Ee.canUseCache(l,f,t+g,m,m+u-1),o===!0)){if(a===b.EQUALS){const E=Ee.getCellPositions(l,f,t+g,e.getValue());for(let C=0;C<u;C++)s[C]==null&&(s[C]=[]),E!=null&&E.includes(C+m)?s[C][t]=new P(!0):s[C][t]=new P(!1)}else{const E=Ee.getCellValuePositions(l,f,t+g);if(E!=null){E.forEach((C,y)=>{let S=new ue(0);typeof y=="string"?S=new X(y):typeof y=="number"?S=new _(y):typeof y=="boolean"&&(S=new P(y)),S.compare(e,a).getValue()===!0&&C.forEach(V=>{V>=m&&V<=m+u-1&&(s[V-m]==null&&(s[V-m]=[]),s[V-m][t]=new P(!0))})});for(let C=0;C<u;C++)s[C]==null&&(s[C]=[]),s[C][t]==null&&(s[C][t]=new P(!1))}else for(let C=0;C<u;C++)s[C]==null&&(s[C]=[]),s[C][t]=new P(!1)}return}for(let E=0;E<u;E++){const C=(w=(R=this._values)==null?void 0:R[E])==null?void 0:w[t];if(s[E]==null&&(s[E]=[]),C&&e)if(C.isError())s[E][t]=C;else if(e.isError())s[E][t]=e;else switch(i){case 1:s[E][t]=C.plus(e);break;case 0:s[E][t]=C.minus(e);break;case 2:s[E][t]=C.multiply(e);break;case 3:s[E][t]=C.divided(e);break;case 4:s[E][t]=C.mod(e);break;case 5:a?s[E][t]=C.compare(e,a):s[E][t]=new h(c.VALUE);break;case 6:s[E][t]=C.concatenateFront(e);break;case 7:s[E][t]=C.concatenateBack(e);break;case 8:a?s[E][t]=C.product(e,a):s[E][t]=new h(c.VALUE);break;case 9:s[E][t]=C.pow(e);break;case 10:s[E][t]=C.round(e);break;case 11:s[E][t]=C.floor(e);break;case 13:s[E][t]=C.atan2(e);break;case 12:s[E][t]=C.ceil(e);break}else s[E][t]=new h(c.NA);C!=null&&(C.isError()?Ee.set(l,f,t+g,C.getErrorType(),E+m):C.isNull()?Ee.set(l,f,t+g,null,E+m):Ee.set(l,f,t+g,C.getValue(),E+m))}Ee.setContinueBuildingCache(l,f,t+g,m,m+u-1)}_batchOperatorArray(e,t,s){var m,g,R,w,E,C,y,S,L,V,I,Q;let i=e.getRowCount(),a=e.getColumnCount();i<this._rowCount&&(i=this._rowCount),a<this._columnCount&&(a=this._columnCount);const u=[],o=e.getArrayValue(),l=this._checkArrayCalculateType(this),f=this._checkArrayCalculateType(e);for(let T=0;T<i;T++){const x=[];for(let v=0;v<a;v++){let $;l===3?$=(g=(m=this._values)==null?void 0:m[0])==null?void 0:g[0]:l===1?$=(w=(R=this._values)==null?void 0:R[0])==null?void 0:w[v]:l===2?$=(C=(E=this._values)==null?void 0:E[T])==null?void 0:C[0]:$=(S=(y=this._values)==null?void 0:y[T])==null?void 0:S[v];let k;if(f===3?k=(L=o==null?void 0:o[0])==null?void 0:L[0]:f===1?k=(V=o==null?void 0:o[0])==null?void 0:V[v]:f===2?k=(I=o==null?void 0:o[T])==null?void 0:I[0]:k=(Q=o==null?void 0:o[T])==null?void 0:Q[v],$&&k)if($.isError())x[v]=$;else if(k.isError())x[v]=k;else switch(t){case 1:x[v]=$.plus(k);break;case 0:x[v]=$.minus(k);break;case 2:x[v]=$.multiply(k);break;case 3:x[v]=$.divided(k);break;case 4:x[v]=$.mod(k);break;case 5:s?x[v]=$.compare(k,s):x[v]=new h(c.VALUE);break;case 6:x[v]=$.concatenateFront(k);break;case 7:x[v]=$.concatenateBack(k);break;case 8:s?x[v]=$.product(k,s):x[v]=new h(c.VALUE);break;case 9:x[v]=$.pow(k);break;case 10:x[v]=$.round(k);break;case 13:x[v]=$.atan2(k);break;case 11:x[v]=$.floor(k);break;case 12:x[v]=$.ceil(k);break}else x[v]=new h(c.NA)}u.push(x)}return this._createNewArray(u,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(";"),s=t.length,i=[];let a=0;for(let u=0;u<s;u++){const l=t[u].split(","),f=l.length;a<f&&(a=f);const m=[];for(let g=0;g<f;g++){const R=l[g].trim();m.push(_e.create(R))}i.push(m)}return this._rowCount=s,this._columnCount=a,i}_createNewArray(e,t,s,i=-1,a=-1){(this._currentColumn===-1||this._currentRow===-1)&&(i=-1,a=-1);const u={calculateValueList:e,rowCount:t,columnCount:s,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:i,column:a};return new z(u)}}class _e{static create(r){if(r==null)return new ue(0);if(typeof r=="boolean")return new P(r,!0);if(typeof r=="string"){const e=r.toLocaleUpperCase().trim();return Ne.has(e)?new h(e):e===ye.TRUE||e===ye.FALSE?new P(e):d.isRealNum(r)?new _(r):new RegExp(ns,"g").test(r.replace(/\n/g,"").replace(/\r/g,""))?new z(r.replace(/\n/g,"").replace(/\r/g,"")):new X(r)}return typeof r=="number"?Number.isFinite(r)?new _(r,!0):new h(c.NUM):new h(c.NA)}}function Vs(n){if(n===null)return 0;if(n!=null&&n.p){const r=n==null?void 0:n.p.body;if(r==null)return 0;const e=r.dataStream;return e.substring(e.length-2,e.length)===d.DEFAULT_EMPTY_DOCUMENT_VALUE?e.substring(0,e.length-2):e}return(n==null?void 0:n.v)||0}const xs=1e5,tr=new rt(xs);class ke extends ct{constructor(e){super();p(this,"_forcedSheetId","");p(this,"_forcedSheetName","");p(this,"_defaultSheetId","");p(this,"_rangeData",{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1});p(this,"_unitData",{});p(this,"_defaultUnitId","");p(this,"_forcedUnitId","");p(this,"_runtimeData",{});p(this,"_arrayFormulaCellData",{});p(this,"_runtimeArrayFormulaCellData",{});p(this,"_runtimeFeatureCellData",{});p(this,"_numfmtItemData",{});p(this,"_refOffsetX",0);p(this,"_refOffsetY",0);this._token=e}dispose(){this._unitData={},this._runtimeData={}}isExceedRange(){const{startRow:e,endRow:t,startColumn:s,endColumn:i}=this.getRangePosition();return e<0||s<0||t>=this.getRowCount()||i>=this.getColumnCount()}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+this._refOffsetY,t=this._rangeData.endRow+this._refOffsetY,s=this._rangeData.startColumn+this._refOffsetX,i=this._rangeData.endColumn+this._refOffsetX;return isNaN(e)&&(e=0),isNaN(s)&&(s=0),isNaN(t)&&(t=this.getRowCount()-1),isNaN(i)&&(i=this.getColumnCount()-1),{startRow:e,endRow:t,startColumn:s,endColumn:i}}isReferenceObject(){return!0}iterator(e){var l,f,m;const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition();if(this._checkIfWorksheetMiss())return e(new h(c.VALUE),t,i);const u=this._forcedUnitId||this._defaultUnitId,o=this._forcedSheetId||this._defaultSheetId;for(let g=t;g<=s;g++)for(let R=i;R<=a;R++){if(g<0||R<0)return e(new h(c.REF),g,R);const w=this.getCellData(g,R);let E=!1;if(w==null||d.isNullCell(w)){E=e(null,g,R);continue}const C=this.getCellValueObject(w),y=(m=(f=(l=this._numfmtItemData[u])==null?void 0:l[o])==null?void 0:f[g])==null?void 0:m[R];if(y&&C.setPattern(y),E=e(C,g,R),E===!1)return}}getFirstCell(){var l,f,m;const{startRow:e,startColumn:t}=this.getRangePosition(),s=this.getCellData(e,t);if(!s)return new _(0,!0);const i=this.getCellValueObject(s),a=this._forcedUnitId||this._defaultUnitId,u=this._forcedSheetId||this._defaultSheetId,o=(m=(f=(l=this._numfmtItemData[a])==null?void 0:l[u])==null?void 0:f[e])==null?void 0:m[t];return o&&i.setPattern(o),i}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}getNumfmtItemData(){return this._numfmtItemData}setNumfmtItemData(e){this._numfmtItemData=e}getRowCount(){return this.getCurrentActiveSheetData().rowCount}getColumnCount(){return this.getCurrentActiveSheetData().columnCount}getRowData(){return this.getCurrentActiveSheetData().rowData}getColumnData(){return this.getCurrentActiveSheetData().columnData}isCell(){return!1}isColumn(){return!1}isRow(){return!1}isRange(){return!1}isTable(){return!1}unionBy(e){return new h(c.REF)}unionRange(e,t){return{startRow:-1,startColumn:-1,endRow:-1,endColumn:-1}}getCellValueObject(e){const t=Vs(e);return Ne.has(t)?new h(t):e.t===d.CellValueType.NUMBER?new _(t):e.t===d.CellValueType.STRING||e.t===d.CellValueType.FORCE_STRING?new X(t):e.t===d.CellValueType.BOOLEAN?new P(t):_e.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 s=this.getCurrentActiveSheetData(),i=this.getCurrentRuntimeSheetData(),a=this.getCurrentActiveArrayFormulaCellData(),u=this.getCurrentRuntimeActiveArrayFormulaCellData();return(i==null?void 0:i.getValue(e,t))||(u==null?void 0:u.getValue(e,t))||this.getRuntimeFeatureCellValue(e,t)||(a==null?void 0:a.getValue(e,t))||(s==null?void 0:s.cellData.getValue(e,t))}getRuntimeFeatureCellValue(e,t){var i;const s=Object.keys(this._runtimeFeatureCellData);for(const a of s){const u=this._runtimeFeatureCellData[a],o=(i=u==null?void 0:u[this.getUnitId()])==null?void 0:i[this.getSheetId()];if(o==null)continue;const l=o.getValue(e,t);if(l!=null)return l}}getCellByPosition(e,t){e||(e=this._rangeData.startRow),t||(t=this._rangeData.startColumn);const s=this.getCellData(e,t);return s?this.getCellValueObject(s):new h(c.VALUE)}toArrayValueObject(e=!0){var w;const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),u=`${this.getUnitId()}_${this.getSheetId()}_${t}_${s}_${i}_${a}`,o=tr.get(u);if(o&&e)return o;const l=s-t+1,f=a-i+1;if(l<0||f<0)return this._getBlankArrayValueObject();const m=new Array(l);this.iterator((E,C,y)=>{const S=C-t,L=y-i;m[S]||(m[S]=new Array(f)),E==null&&(E=new ue(0)),m[S][L]=E});const g={calculateValueList:m,rowCount:m.length,columnCount:((w=m[0])==null?void 0:w.length)||0,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:t,column:i},R=new z(g);return e&&tr.set(u,R),R}toUnitRange(){return{range:this.getRangePosition(),sheetId:this.getSheetId(),unitId:this.getUnitId()}}_checkIfWorksheetMiss(){return(this._forcedSheetId==null||this._forcedSheetId.length===0)&&this._forcedSheetName.length>0}_getBlankArrayValueObject(){const e={calculateValueList:[],rowCount:0,columnCount:0,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:0,column:0};return new z(e)}}class vs extends ct{constructor(r){super(),this._promise=r}isAsyncObject(){return!0}async getValue(){return this._promise}}class Bs extends ct{constructor(r){super(),this._promiseList=r}isAsyncArrayObject(){return!0}async getValue(){var t;const r=[];for(let s=0;s<this._promiseList.length;s++){const i=this._promiseList[s];r[s]==null&&(r[s]=[]);for(let a=0;a<i.length;a++){const u=i[a];u.isAsyncObject()?r[s][a]=await u.getValue():r[s][a]=u}}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 z(e)}}class Ke extends ke{constructor(r,e,t){super(""),this.setRangeData(r),e&&this.setForcedSheetIdDirect(e),t&&this.setForcedUnitIdDirect(t)}isRange(){return!0}}const zr=/[\[\]]/g;function Zr(n,r){if(zr.test(n)){const e=Number(n.replace(zr,""));return r+e}return Number(n)-1}function rr(n,r=0,e=0){n=n.toLocaleUpperCase();const t=n.split(/[RC]/),s=t[1],i=t[2],a=Zr(s,r),u=Zr(i,e);return{row:a,column:u,absoluteRefType:d.AbsoluteRefType.NONE}}function Jr(n,r=0,e=0){const{refBody:t,sheetName:s,unitId:i}=vr(n),a=t.indexOf(":");if(a===-1){const E=rr(t,r,e),C=E.row,y=E.column,S=E.absoluteRefType;return{unitId:i,sheetName:s,range:{startRow:C,startColumn:y,endRow:C,endColumn:y,startAbsoluteRefType:S,endAbsoluteRefType:S}}}const u=t.substring(0,a),o=t.substring(a+1),l=rr(u,r,e),f=rr(o,r,e),m=l.row,g=l.column,R=f.row,w=f.column;return{unitId:i,sheetName:s,range:{startRow:m,startColumn:g,endRow:R,endColumn:w,startAbsoluteRefType:l.absoluteRefType,endAbsoluteRefType:f.absoluteRefType}}}function Us(n){const r=ht(n.startRow,n.startAbsoluteRefType,!0),e=ht(n.startColumn,n.startAbsoluteRefType,!1),t=ht(n.endRow,n.endAbsoluteRefType,!0),s=ht(n.endColumn,n.endAbsoluteRefType,!1);return r===t&&e===s?`R${r}C${e}`:`R${r}C${e}:R${t}C${s}`}function ht(n,r=d.AbsoluteRefType.ALL,e){switch(n+=1,r){case d.AbsoluteRefType.ALL:return`${n}`;case d.AbsoluteRefType.ROW:return e?`${n}`:`[${n}]`;case d.AbsoluteRefType.COLUMN:return e?`[${n}]`:`${n}`;case d.AbsoluteRefType.NONE:return`[${n}]`}}const Nr=[];var Ms=(n=>{})();function mt(n){const r=n.getValue();let e=0;return r&&(e=1),new _(e,!0)}function j(n,r,e,t){const s=[];if(e.isArray()){const i=e.getRowCount(),a=e.getColumnCount();if(i===1&&a===1){const u=e.getFirstCell();for(let o=0;o<n;o++){const l=[];for(let f=0;f<r;f++)l.push(u);s.push(l)}}else if(i===1&&a>1)for(let u=0;u<n;u++){const o=[];for(let l=0;l<r;l++){const f=e.getRealValue(0,l)||(t!=null?t:new ue(0));o.push(f)}s.push(o)}else if(a===1&&i>1)for(let u=0;u<n;u++){const o=[];for(let l=0;l<r;l++){const f=e.getRealValue(u,0)||(t!=null?t:new ue(0));o.push(f)}s.push(o)}else for(let u=0;u<n;u++){const o=[];for(let l=0;l<r;l++){const f=e.getRealValue(u,l)||(t!=null?t:new ue(0));o.push(f)}s.push(o)}}else for(let i=0;i<n;i++){const a=[];for(let u=0;u<r;u++)a.push(e);s.push(a)}return gt(s,n,r)}function gt(n,r,e){const t={calculateValueList:n,rowCount:r,columnCount:e,unitId:"",sheetId:"",row:-1,column:-1};return new z(t)}class A extends d.Disposable{constructor(e){super();p(this,"_unitId");p(this,"_subUnitId");p(this,"_row",-1);p(this,"_column",-1);p(this,"needsExpandParams",!1);p(this,"needsReferenceObject",!1);this._name=e}get name(){return this._name}get unitId(){return this._unitId}get subUnitId(){return this._subUnitId}get row(){return this._row}get column(){return this._column}isAsync(){return!1}isAddress(){return!1}isCustom(){return!1}setRefInfo(e,t,s,i){this._unitId=e,this._subUnitId=t,this._row=s,this._column=i}calculateCustom(...e){return null}calculate(...e){return new h(c.VALUE)}checkArrayType(e){return e.isReferenceObject()||e.isValueObject()&&e.isArray()}getIndexNumValue(e,t=1){if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())return e.getValue()===!1?new h(c.VALUE):t;if(e.isString()){const s=Number(e.getValue());return isNaN(s)?new h(c.REF):s}else if(e.isNumber())return e.getValue();return new h(c.VALUE)}getZeroOrOneByOneDefault(e){if(e==null)return 1;let t=1;if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())e.getValue()===!1&&(t=0);else{if(e.isString())return;e.isNumber()&&e.getValue()===0&&(t=0)}return t}getMatchTypeValue(e){if(e==null)return 1;let t=1;if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())e.getValue()===!1&&(t=0);else{if(e.isString())return;if(e.isNumber()){const s=e.getValue();s<=0&&(t=s)}}return t}binarySearch(e,t,s,i){const a=t.binarySearch(e,i);if(a==null)return new h(c.NA);let u;return s.getRowCount()===1?u=s.get(0,a):u=s.get(a,0),u.isNull()?new h(c.NA):u}equalSearch(e,t,s,i=!0){const a=s.pick(t.isEqual(e));let u;return i?u=a.getFirstCell():u=a.getLastCell(),u.isNull()?new h(c.NA):u}fuzzySearch(e,t,s,i=!0){const a=s.pick(t.compare(e,b.EQUALS));let u;return i?u=a.getFirstCell():u=a.getLastCell(),u.isNull()?new h(c.NA):u}orderSearch(e,t,s,i=q.MIN,a=!1){const u=t.orderSearch(e,i,a);if(u==null)return new h(c.NA);const o=s.get(u.row,u.column);return o.isNull()?new h(c.NA):o}binarySearchExpand(e,t,s,i=0,a){const u=t.binarySearch(e,a);return u==null?new h(c.NA):i===0?s.slice([u,u+1]):s.slice(void 0,[u,u+1])}equalSearchExpand(e,t,s,i=!0,a=0){const u=t.isEqual(e);let o;return i?o=u.getFirstTruePosition():o=u.getLastTruePosition(),o==null?new h(c.NA):a===0?s.slice([o.row,o.row+1]):s.slice(void 0,[o.column,o.column+1])}fuzzySearchExpand(e,t,s,i=!0,a=0){const u=t.compare(e,b.EQUALS);let o;return i?o=u.getFirstTruePosition():o=u.getLastTruePosition(),o==null?new h(c.NA):a===0?s.slice([o.row,o.row+1]):s.slice(void 0,[o.column,o.column+1])}orderSearchExpand(e,t,s,i=q.MIN,a=!1,u=0){const o=t.orderSearch(e,i,a);return o==null?new h(c.NA):u===0?s.slice([o.row,o.row+1]):s.slice(void 0,[o.column,o.column+1])}flattenArray(e,t=!0){const s=[];s[0]=[];for(let i=0;i<e.length;i++){let a=e[i];if(a.isError())return a;if(a.isString()){const u=a.getValue();if(!d.isRealNum(u))return new h(c.VALUE);a=new _(u)}if(a.isBoolean()&&(a=mt(a)),a.isNull()&&(a=new _(0)),a.isArray()){let u;if(a.iterator(o=>{if(o==null||o.isNull()||t&&(o.isString()||o.isBoolean()))return!0;if(o=this._includingLogicalValuesAndText(o),o.isError())return u=o,!1;s[0].push(o)}),u!=null&&u.isError())return u}else s[0].push(a)}return gt(s,1,s[0].length)}_includingLogicalValuesAndText(e){if(e.isBoolean()&&(e=mt(e)),e.isString()){const t=Number(e.getValue());e=new _(isNaN(t)?0:t)}return e}}class en extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r);return e.isError()?e:e.std()}}class tn extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r);return e.isError()?e:e.std(1)}}class rn extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r);return e.isError()?e:e.var()}}class nn extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r);return e.isError()?e:e.var(1)}}var Ie=(n=>(n.BETADIST="BETADIST",n.BETAINV="BETAINV",n.BINOMDIST="BINOMDIST",n.CHIDIST="CHIDIST",n.CHIINV="CHIINV",n.CHITEST="CHITEST",n.CONFIDENCE="CONFIDENCE",n.COVAR="COVAR",n.CRITBINOM="CRITBINOM",n.EXPONDIST="EXPONDIST",n.FDIST="FDIST",n.FINV="FINV",n.FTEST="FTEST",n.GAMMADIST="GAMMADIST",n.GAMMAINV="GAMMAINV",n.HYPGEOMDIST="HYPGEOMDIST",n.LOGINV="LOGINV",n.LOGNORMDIST="LOGNORMDIST",n.MODE="MODE",n.NEGBINOMDIST="NEGBINOMDIST",n.NORMDIST="NORMDIST",n.NORMINV="NORMINV",n.NORMSDIST="NORMSDIST",n.NORMSINV="NORMSINV",n.PERCENTILE="PERCENTILE",n.PERCENTRANK="PERCENTRANK",n.POISSON="POISSON",n.QUARTILE="QUARTILE",n.RANK="RANK",n.STDEV="STDEV",n.STDEVP="STDEVP",n.TDIST="TDIST",n.TINV="TINV",n.TTEST="TTEST",n.VAR="VAR",n.VARP="VARP",n.WEIBULL="WEIBULL",n.ZTEST="ZTEST",n))(Ie||{});const sn=[[tn,Ie.STDEV],[en,Ie.STDEVP],[nn,Ie.VAR],[rn,Ie.VARP]],an=[];var un=(n=>(n.CUBEKPIMEMBER="CUBEKPIMEMBER",n.CUBEMEMBER="CUBEMEMBER",n.CUBEMEMBERPROPERTY="CUBEMEMBERPROPERTY",n.CUBERANKEDMEMBER="CUBERANKEDMEMBER",n.CUBESET="CUBESET",n.CUBESETCOUNT="CUBESETCOUNT",n.CUBEVALUE="CUBEVALUE",n))(un||{});const on=[];var ln=(n=>(n.DAVERAGE="DAVERAGE",n.DCOUNT="DCOUNT",n.DCOUNTA="DCOUNTA",n.DGET="DGET",n.DMAX="DMAX",n.DMIN="DMIN",n.DPRODUCT="DPRODUCT",n.DSTDEV="DSTDEV",n.DSTDEVP="DSTDEVP",n.DSUM="DSUM",n.DVAR="DVAR",n.DVARP="DVARP",n))(ln||{});const nr="yyyy-mm-dd;@";function sr(n){const r=new Date(Date.UTC(1900,0,1)),e=new Date(Date.UTC(1900,1,28)),t=Date.UTC(n.getFullYear(),n.getMonth(),n.getDate());let s=(t-r.getTime())/(1e3*3600*24);return t>e.getTime()&&(s+=1),Math.floor(s)+1}function dt(n){const r=new Date(Date.UTC(1900,0,1)),e=new Date(Date.UTC(1900,1,28));let t=Math.floor(n)-1;return t>(e.getTime()-r.getTime())/(1e3*3600*24)&&(t-=1),new Date(r.getTime()+t*(1e3*3600*24))}function ir(n){if(!/^\d{4}[-/](0?[1-9]|1[012])[-/](0?[1-9]|[12][0-9]|3[01])$/.test(n))return!1;const e=n.replace(/-/g,"/").replace(/T.+/,""),t=new Date(`${e}`);if(Number.isNaN(t.getTime()))return!1;const s=t.getFullYear(),i=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getDate().toString().padStart(2,"0"),u=`${s}-${i}-${a}`;return n.replace(/\//g,"-").split("-").map(l=>l.padStart(2,"0")).join("-")===u}class Os extends A{calculate(r,e,t){if(r==null||e==null||t==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return e;if(t.isError())return t;const s=Math.max(r.isArray()?r.getRowCount():1,e.isArray()?e.getRowCount():1,t.isArray()?t.getRowCount():1),i=Math.max(r.isArray()?r.getColumnCount():1,e.isArray()?e.getColumnCount():1,t.isArray()?t.getColumnCount():1),a=j(s,i,r),u=j(s,i,e),o=j(s,i,t);return a.map((l,f,m)=>{const g=u.get(f,m),R=o.get(f,m);if(l.isError())return l;if(g.isError())return g;if(R.isError())return R;if(l.isString()||g.isString()||R.isString())return new h(c.VALUE);let w=+l.getValue();const E=Math.floor(+g.getValue()),C=+R.getValue();if(w<0||w>9999)return new h(c.NUM);w>=0&&w<1899&&(w+=1900);const y=new Date(w,E-1,C),S=sr(y);if(S<0)return new h(c.NUM);const L=new _(S);return L.setPattern(nr),L})}}class Fs extends A{calculate(r){return r==null?new h(c.NA):r.isArray()?r.map(e=>this._handleSingleObject(e)):this._handleSingleObject(r)}_handleSingleObject(r){if(r.isError())return r;let e;const t=r.getValue();if(r.isString()){if(!ir(`${t}`))return new h(c.VALUE);e=new Date(`${t}`)}else{const a=+r.getValue();if(a<0)return new h(c.NUM);if(a===0)return new _(0);e=dt(a)}const s=e.getDate();return new _(s)}}class $s extends A{calculate(r,e){if(r==null||e==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return e;const t=Math.max(r.isArray()?r.getRowCount():1,e.isArray()?e.getRowCount():1),s=Math.max(r.isArray()?r.getColumnCount():1,e.isArray()?e.getColumnCount():1),i=j(t,s,r),a=j(t,s,e);return i.map((u,o,l)=>{const f=a.get(o,l);if(u.isError())return u;if(f.isError())return f;if(u.isString()||u.isBoolean()||f.isString()||f.isBoolean())return new h(c.VALUE);const m=+u.getValue();if(m<0)return new h(c.NUM);const g=Math.floor(+f.getValue()),R=dt(m),w=R.getUTCFullYear(),E=R.getUTCMonth()+g,C=R.getUTCDate(),y=new Date(Date.UTC(w,E,C)),S=sr(y),L=new _(S);return L.setPattern(nr),L})}}var Ce=(n=>(n.DATE="DATE",n.DATEDIF="DATEDIF",n.DATEVALUE="DATEVALUE",n.DAY="DAY",n.DAYS="DAYS",n.DAYS360="DAYS360",n.EDATE="EDATE",n.EOMONTH="EOMONTH",n.HOUR="HOUR",n.ISOWEEKNUM="ISOWEEKNUM",n.MINUTE="MINUTE",n.MONTH="MONTH",n.NETWORKDAYS="NETWORKDAYS",n.NETWORKDAYS_INTL="NETWORKDAYS.INTL",n.NOW="NOW",n.SECOND="SECOND",n.TIME="TIME",n.TIMEVALUE="TIMEVALUE",n.TODAY="TODAY",n.WEEKDAY="WEEKDAY",n.WEEKNUM="WEEKNUM",n.WORKDAY="WORKDAY",n.WORKDAY_INTL="WORKDAY.INTL",n.YEAR="YEAR",n.YEARFRAC="YEARFRAC",n))(Ce||{});class ks extends A{calculate(r){return r==null?new h(c.NA):r.isArray()?r.map(e=>this._handleSingleObject(e)):this._handleSingleObject(r)}_handleSingleObject(r){if(r.isError())return r;let e;const t=r.getValue();if(r.isString()){if(!ir(`${t}`))return new h(c.VALUE);e=new Date(`${t}`)}else{const a=+r.getValue();if(a<0)return new h(c.NUM);if(a===0)return new _(1);e=dt(a)}const s=e.getUTCMonth()+1;return new _(s)}}class Is extends A{calculate(r){if(r)return new h(c.NA);const e=sr(new Date),t=new _(e);return t.setPattern(nr),t}}class Ts extends A{calculate(r){return r==null?new h(c.NA):r.isArray()?r.map(e=>this._handleSingleObject(e)):this._handleSingleObject(r)}_handleSingleObject(r){if(r.isError())return r;let e;const t=r.getValue();if(r.isString()){if(!ir(`${t}`))return new h(c.VALUE);e=new Date(`${t}`)}else{const a=+t;if(a<0)return new h(c.NUM);if(a===0)return new _(1900);e=dt(a)}const s=e.getUTCFullYear();return new _(s)}}const cn=[[Os,Ce.DATE],[Fs,Ce.DAY],[$s,Ce.EDATE],[ks,Ce.MONTH],[Is,Ce.TODAY],[Ts,Ce.YEAR]],fn=[];var hn=(n=>(n.BESSELI="BESSELI",n.BESSELJ="BESSELJ",n.BESSELK="BESSELK",n.BESSELY="BESSELY",n.BIN2DEC="BIN2DEC",n.BIN2HEX="BIN2HEX",n.BIN2OCT="BIN2OCT",n.BITAND="BITAND",n.BITLSHIFT="BITLSHIFT",n.BITOR="BITOR",n.BITRSHIFT="BITRSHIFT",n.BITXOR="BITXOR",n.COMPLEX="COMPLEX",n.CONVERT="CONVERT",n.DEC2BIN="DEC2BIN",n.DEC2HEX="DEC2HEX",n.DEC2OCT="DEC2OCT",n.DELTA="DELTA",n.ERF="ERF",n.ERF_PRECISE="ERF.PRECISE",n.ERFC="ERFC",n.ERFC_PRECISE="ERFC.PRECISE",n.GESTEP="GESTEP",n.HEX2BIN="HEX2BIN",n.HEX2DEC="HEX2DEC",n.HEX2OCT="HEX2OCT",n.IMABS="IMABS",n.IMAGINARY="IMAGINARY",n.IMARGUMENT="IMARGUMENT",n.IMCONJUGATE="IMCONJUGATE",n.IMCOS="IMCOS",n.IMCOSH="IMCOSH",n.IMCOT="IMCOT",n.IMCSC="IMCSC",n.IMCSCH="IMCSCH",n.IMDIV="IMDIV",n.IMEXP="IMEXP",n.IMLN="IMLN",n.IMLOG10="IMLOG10",n.IMLOG2="IMLOG2",n.IMPOWER="IMPOWER",n.IMPRODUCT="IMPRODUCT",n.IMREAL="IMREAL",n.IMSEC="IMSEC",n.IMSECH="IMSECH",n.IMSIN="IMSIN",n.IMSINH="IMSINH",n.IMSQRT="IMSQRT",n.IMSUB="IMSUB",n.IMSUM="IMSUM",n.IMTAN="IMTAN",n.OCT2BIN="OCT2BIN",n.OCT2DEC="OCT2DEC",n.OCT2HEX="OCT2HEX",n))(hn||{});const mn=[];var gn=(n=>(n.ACCRINT="ACCRINT",n.ACCRINTM="ACCRINTM",n.AMORDEGRC="AMORDEGRC",n.AMORLINC="AMORLINC",n.COUPDAYBS="COUPDAYBS",n.COUPDAYS="COUPDAYS",n.COUPDAYSNC="COUPDAYSNC",n.COUPNCD="COUPNCD",n.COUPNUM="COUPNUM",n.COUPPCD="COUPPCD",n.CUMIPMT="CUMIPMT",n.CUMPRINC="CUMPRINC",n.DB="DB",n.DDB="DDB",n.DISC="DISC",n.DOLLARDE="DOLLARDE",n.DOLLARFR="DOLLARFR",n.DURATION="DURATION",n.EFFECT="EFFECT",n.FV="FV",n.FVSCHEDULE="FVSCHEDULE",n.INTRATE="INTRATE",n.IPMT="IPMT",n.IRR="IRR",n.ISPMT="ISPMT",n.MDURATION="MDURATION",n.MIRR="MIRR",n.NOMINAL="NOMINAL",n.NPER="NPER",n.NPV="NPV",n.ODDFPRICE="ODDFPRICE",n.ODDFYIELD="ODDFYIELD",n.ODDLPRICE="ODDLPRICE",n.ODDLYIELD="ODDLYIELD",n.PDURATION="PDURATION",n.PMT="PMT",n.PPMT="PPMT",n.PRICE="PRICE",n.PRICEDISC="PRICEDISC",n.PRICEMAT="PRICEMAT",n.PV="PV",n.RATE="RATE",n.RECEIVED="RECEIVED",n.RRI="RRI",n.SLN="SLN",n.SYD="SYD",n.TBILLEQ="TBILLEQ",n.TBILLPRICE="TBILLPRICE",n.TBILLYIELD="TBILLYIELD",n.VDB="VDB",n.XIRR="XIRR",n.XNPV="XNPV",n.YIELD="YIELD",n.YIELDDISC="YIELDDISC",n.YIELDMAT="YIELDMAT",n))(gn||{}),ne=(n=>(n.CELL="CELL",n.ERROR_TYPE="ERROR.TYPE",n.INFO="INFO",n.ISBLANK="ISBLANK",n.ISERR="ISERR",n.ISERROR="ISERROR",n.ISEVEN="ISEVEN",n.ISFORMULA="ISFORMULA",n.ISLOGICAL="ISLOGICAL",n.ISNA="ISNA",n.ISNONTEXT="ISNONTEXT",n.ISNUMBER="ISNUMBER",n.ISODD="ISODD",n.ISOMITTED="ISOMITTED",n.ISREF="ISREF",n.ISTEXT="ISTEXT",n.N="N",n.NA="NA",n.SHEET="SHEET",n.SHEETS="SHEETS",n.TYPE="TYPE",n))(ne||{});class Qs extends A{calculate(r){return r==null?new h(c.NA):r.isNull()?new P(!0):r.isArray()?r.mapValue(e=>e.isNull()?new P(!0):new P(!1)):new P(!1)}}class Ys extends A{calculate(r){return r==null?new h(c.NA):r.getValue()===c.NA?new P(!1):r.isError()?new P(!0):r.isArray()?r.mapValue(e=>e.getValue()===c.NA?new P(!1):e.isError()?new P(!0):new P(!1)):new P(!1)}}class Hs extends A{calculate(r){return r==null?new h(c.NA):r.isError()?new P(!0):r.isArray()?r.mapValue(e=>e.isError()?new P(!0):new P(!1)):new P(!1)}}class js extends A{calculate(r){return r==null?new h(c.NA):r.isBoolean()?new P(!0):r.isArray()?r.mapValue(e=>e.isBoolean()?new P(!0):new P(!1)):new P(!1)}}class Ws extends A{calculate(r){return r==null?new h(c.NA):r.getValue()===c.NA?new P(!0):r.isArray()?r.mapValue(e=>e.getValue()===c.NA?new P(!0):new P(!1)):new P(!1)}}class Xs extends A{calculate(r){return r==null?new h(c.NA):!r.isArray()&&!r.isString()?new P(!0):r.isArray()?r.mapValue(e=>e.isString()?new P(!1):new P(!0)):new P(!1)}}class Gs extends A{calculate(r){return r==null?new h(c.NA):r.isNumber()?new P(!0):r.isArray()?r.mapValue(e=>e.isNumber()?new P(!0):new P(!1)):new P(!1)}}class Ks extends A{constructor(){super(...arguments);p(this,"needsReferenceObject",!0)}calculate(e){return e==null?new h(c.NA):e.isReferenceObject()?new P(!0):new P(!1)}}class qs extends A{calculate(r){return r==null?new h(c.NA):r.isString()?new P(!0):r.isArray()?r.mapValue(e=>e.isString()?new P(!0):new P(!1)):new P(!1)}}const dn=[[Qs,ne.ISBLANK],[Ys,ne.ISERR],[Hs,ne.ISERROR],[js,ne.ISLOGICAL],[Ws,ne.ISNA],[Xs,ne.ISNONTEXT],[Gs,ne.ISNUMBER],[Ks,ne.ISREF],[qs,ne.ISTEXT]];class zs extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=!0,t=!0,s=null;for(const i of r){if(i.isError())return i;if(i.isArray()){if(i.iterator(a=>{if(a!=null&&a.isError())return s=a,!1;(a!=null&&a.isBoolean()||a!=null&&a.isNumber())&&(e=e&&!!a.getValue(),t=!1)}),s)return s}else(i.isBoolean()||i.isNumber())&&(e=e&&!!i.getValue(),t=!1)}return t?new h(c.VALUE):new P(e)}}var Ve=(n=>(n.AND="AND",n.BYCOL="BYCOL",n.BYROW="BYROW",n.FALSE="FALSE",n.IF="IF",n.IFERROR="IFERROR",n.IFNA="IFNA",n.IFS="IFS",n.LAMBDA="LAMBDA",n.LET="LET",n.MAKEARRAY="MAKEARRAY",n.MAP="MAP",n.NOT="NOT",n.OR="OR",n.REDUCE="REDUCE",n.SCAN="SCAN",n.SWITCH="SWITCH",n.TRUE="TRUE",n.XOR="XOR",n))(Ve||{});class Zs extends A{calculate(r,e,t=new P(!1)){if(r==null||e==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return e;if(r=this._getSingleValueObject(r),!r.isArray())return r.getValue()?e:t;const s=Math.max(r.isArray()?r.getRowCount():1,e.isArray()?e.getRowCount():1,t.isArray()?t.getRowCount():1),i=Math.max(r.isArray()?r.getColumnCount():1,e.isArray()?e.getColumnCount():1,t.isArray()?t.getColumnCount():1),a=j(s,i,r),u=j(s,i,e,new h(c.NA)),o=j(s,i,t,new h(c.NA));return a.map((l,f,m)=>{if(l.isNull())return new h(c.NA);{const g=u.get(f,m),R=o.get(f,m);return this._calculateSingleCell(l,g,R)}})}_getSingleValueObject(r){return r.isArray()&&r.getRowCount()===1&&r.getColumnCount()===1?r.getFirstCell():r}_calculateSingleCell(r,e,t){return r.isNull()?new h(c.NA):r.getValue()?e.isNull()?new h(c.NA):e:t.isNull()?new h(c.NA):t}}class Js extends A{calculate(r,e){if(r==null||e==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return e;if(!r.isArray())return r.isError()?e:r;const t=Math.max(r.isArray()?r.getRowCount():1,e.isArray()?e.getRowCount():1),s=Math.max(r.isArray()?r.getColumnCount():1,e.isArray()?e.getColumnCount():1),i=j(t,s,r),a=j(t,s,e);return i.iterator((u,o,l)=>{u!=null&&u.isError()&&i.set(o,l,a.get(o,l))}),i}}class Ns extends A{calculate(...r){return new h(c.VALUE)}}class ei extends A{calculate(...r){if(r.length!==3)return new h(c.VALUE);const e=this.getIndexNumValue(r[0]);if(typeof e!="number")return e;const t=this.getIndexNumValue(r[1]);if(typeof t!="number")return t;if(!(r[2].isValueObject()&&r[2].isLambda()))return new h(c.VALUE);const s=r[2],i=[];for(let a=0;a<e;a++){i[a]==null&&(i[a]=[]);for(let u=0;u<t;u++){const o=s.execute(new _(a+1),new _(u+1));i[a][u]=o}}return new Bs(i)}isAsync(){return!0}}const Rn=[[zs,Ve.AND],[Ns,Ve.LAMBDA],[ei,Ve.MAKEARRAY],[Zs,Ve.IF],[Js,Ve.IFERROR]];class ti extends A{calculate(r,e,t,s,i){if(r==null||e==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return e;if(t!=null&&t.isError())return t;if(s!=null&&s.isError())return s;if(i!=null&&i.isError())return i;const a=Number(r.getValue())-1,u=Number(e.getValue())-1;if(Number.isNaN(a)||Number.isNaN(u))return new h(c.VALUE);const o=t?ri(t.getValue()):d.AbsoluteRefType.ALL,l=this.getZeroOrOneByOneDefault(s),f=i?`${i.getValue()}`:"",m=st(f)?`'${f}'`:f,g={startRow:a,startColumn:u,endRow:a,endColumn:u,startAbsoluteRefType:o,endAbsoluteRefType:o},R=s&&!l?Us(g):De(g);return new X(m!==""?`${m}!${R}`:R)}}function ri(n){switch(n){case 1:return d.AbsoluteRefType.ALL;case 2:return d.AbsoluteRefType.ROW;case 3:return d.AbsoluteRefType.COLUMN;case 4:return d.AbsoluteRefType.NONE;default:return d.AbsoluteRefType.ALL}}class ni extends A{calculate(r){if(r==null)return new _(this.column+1);if(r.isError())return r;if(!r.isArray())return new h(c.NA);const e=r.getCurrentColumn(),t=r.getColumnCount(),s=[];for(let a=0;a<t;a++)s.push(new _(e+a+1));const i={calculateValueList:[s],rowCount:1,columnCount:t,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return new z(i)}}class si extends A{calculate(r){if(r==null)return new h(c.NA);if(r.isError())return r;if(r.isString()||r.isNumber()||r.isBoolean())return new _(1);if(!r.isArray())return new h(c.NA);const e=r.getColumnCount();return new _(e)}}var G=(n=>(n.ADDRESS="ADDRESS",n.AREAS="AREAS",n.CHOOSE="CHOOSE",n.CHOOSECOLS="CHOOSECOLS",n.CHOOSEROWS="CHOOSEROWS",n.COLUMN="COLUMN",n.COLUMNS="COLUMNS",n.DROP="DROP",n.EXPAND="EXPAND",n.FILTER="FILTER",n.FORMULATEXT="FORMULATEXT",n.GETPIVOTDATA="GETPIVOTDATA",n.HLOOKUP="HLOOKUP",n.HSTACK="HSTACK",n.HYPERLINK="HYPERLINK",n.IMAGE="IMAGE",n.INDEX="INDEX",n.INDIRECT="INDIRECT",n.LOOKUP="LOOKUP",n.MATCH="MATCH",n.OFFSET="OFFSET",n.ROW="ROW",n.ROWS="ROWS",n.RTD="RTD",n.SORT="SORT",n.SORTBY="SORTBY",n.TAKE="TAKE",n.TOCOL="TOCOL",n.TOROW="TOROW",n.TRANSPOSE="TRANSPOSE",n.UNIQUE="UNIQUE",n.VLOOKUP="VLOOKUP",n.VSTACK="VSTACK",n.WRAPCOLS="WRAPCOLS",n.WRAPROWS="WRAPROWS",n.XLOOKUP="XLOOKUP",n.XMATCH="XMATCH",n))(G||{});class ii extends A{calculate(r,e,t,s){if(r==null||e==null||t==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return new h(c.REF);if(!e.isArray())return new h(c.NA);if(t.isError())return new h(c.NA);if(s!=null&&s.isError())return new h(c.NA);const i=this.getZeroOrOneByOneDefault(s);if(i==null)return new h(c.VALUE);const a=this.getIndexNumValue(t);if(a instanceof h)return a;const u=e.slice([0,1]),o=e.slice([a-1,a]);return u==null||o==null?new h(c.REF):r.isArray()?r.map(l=>this._handleSingleObject(l,u,o,i)):this._handleSingleObject(r,u,o,i)}_handleSingleObject(r,e,t,s){return s===0?this.equalSearch(r,e,t):this.binarySearch(r,e,t)}}class En extends ke{constructor(r){super(r);const e=Fe(r);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName),this.setRangeData(e.range)}isCell(){return!0}unionBy(r){if(!r.isCell())return new h(c.REF);const e=r,t=this.unionRange(this.getRangeData(),e.getRangeData());return this._createRange(t)}unionRange(r,e){const t=r.startRow,s=r.startColumn,i=e.startRow,a=e.startColumn,u={startRow:-1,startColumn:-1,endRow:-1,endColumn:-1};return t>i?(u.startRow=i,u.endRow=t):(u.startRow=t,u.endRow=i),s>a?(u.startColumn=a,u.endColumn=s):(u.startColumn=s,u.endColumn=a),u}_createRange(r){const e=new Ke(r,this.getForcedSheetId(),this.getForcedUnitId());e.setUnitData(this.getUnitData()),e.setDefaultSheetId(this.getDefaultSheetId()),e.setDefaultUnitId(this.getDefaultUnitId()),e.setRuntimeData(this.getRuntimeData()),e.setNumfmtItemData(this.getNumfmtItemData()),e.setArrayFormulaCellData(this.getArrayFormulaCellData()),e.setRuntimeArrayFormulaCellData(this.getRuntimeArrayFormulaCellData()),e.setRuntimeFeatureCellData(this.getRuntimeFeatureCellData());const{x:t,y:s}=this.getRefOffset();e.setRefOffset(t,s);const i=this.getForcedSheetId();e.setForcedSheetName(this.getForcedSheetName()),i!=null&&e.setForcedSheetIdDirect(i);const a=this.getForcedUnitId();return a&&e.setForcedUnitIdDirect(a),e}}class wn extends ke{constructor(r){super(r);const e=Fe(r);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const t={startColumn:e.range.startColumn,startRow:Number.NaN,endColumn:-1,endRow:Number.NaN};this.setRangeData(t)}isColumn(){return!0}unionBy(r){if(!r.isColumn())return new h(c.REF);const e=r;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return new h(c.REF);const t=this.getRangeData(),s=e.getRangeData().startColumn,i=t.startColumn;return s>i?t.endColumn=s:(t.startColumn=s,t.endColumn=i),this}}class _n extends ke{constructor(r){super(r);const e=Fe(r);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const t={startColumn:Number.NaN,startRow:e.range.startRow,endColumn:Number.NaN,endRow:-1};this.setRangeData(t)}isRow(){return!0}unionBy(r){if(!r.isRow())return new h(c.REF);const e=r;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return new h(c.REF);const t=this.getRangeData(),s=e.getRangeData().startRow,i=t.startRow;return s>i?t.endRow=s:(t.startRow=s,t.endRow=i),this}}class ai extends A{calculate(r,e){if(r==null)return new h(c.NA);if(r.isError())return r;let t=this.getZeroOrOneByOneDefault(e);if(t==null&&(t=1),r.isArray()){const f=r;if(f.getRowCount()===1&&f.getColumnCount()===1)r=f.getFirstCell();else return f.map(()=>new h(c.VALUE))}if(!r.isString())return new h(c.REF);const s=r.getValue();if(t===0){const f=Jr(s),{range:m,sheetName:g,unitId:R}=f,w=new Ke(m);return w.setForcedUnitIdDirect(R),w.setForcedSheetName(g),this._setDefault(w)}if(new RegExp(nt).test(s))return this._setDefault(new En(s));if(new RegExp(Dr).test(s))return this._setDefault(new _n(s));if(new RegExp(yr).test(s))return this._setDefault(new wn(s));const i=Fe(s),{range:a,sheetName:u,unitId:o}=i,l=new Ke(a);return l.setForcedUnitIdDirect(o),l.setForcedSheetName(u),this._setDefault(l)}_setDefault(r){return this.unitId==null||this.subUnitId==null?new h(c.REF):(r.setDefaultUnitId(this.unitId),r.setDefaultSheetId(this.subUnitId),r)}}class ui extends A{constructor(){super(...arguments);p(this,"needsExpandParams",!0)}calculate(e,t,s){return e==null||t==null?new h(c.NA):e.isError()?e:t.isError()?new h(c.REF):t.isArray()?s!=null&&s.isError()?s:t.getColumnCount()===1||t.getRowCount()===1?s!=null&&!s.isArray()?new h(c.REF):this._handleVector(e,t,s):this._handleArray(e,t):new h(c.VALUE)}_handleVector(e,t,s){if(s==null)s=t;else if(s.getRowCount()!==t.getRowCount()||s.getColumnCount()!==t.getColumnCount())return new h(c.REF);return e.isArray()?e.map(i=>this.binarySearch(i,t,s)):this.binarySearch(e,t,s)}_handleArray(e,t){const s=t.getRowCount(),i=t.getColumnCount();let a,u;return i>s?(a=t.slice([0,1]),u=t.slice([s-1,s])):(a=t.slice(void 0,[0,1]),u=t.slice(void 0,[i-1,i])),a==null||u==null?new h(c.VALUE):e.isArray()?e.map(o=>this.binarySearch(o,a,u)):this.binarySearch(e,a,u)}}class oi extends A{calculate(r,e,t){if(r==null||e==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return new h(c.REF);if(!e.isArray())return new h(c.VALUE);const s=e.getRowCount(),i=e.getColumnCount();if(s!==1&&i!==1)return new h(c.NA);if(t!=null&&t.isError())return new h(c.NA);const a=this.getMatchTypeValue(t);return a==null?new h(c.VALUE):r.isArray()?r.map(u=>this._handleSingleObject(u,e,a)):this._handleSingleObject(r,e,a)}_handleSingleObject(r,e,t){const s=this._getSearchModeValue(t),i=e.orderSearch(r,s);if(i==null)return new h(c.NA);if(i instanceof h)return i;const a=e.getRowCount()===1?i.column+1:i.row+1;return new _(a)}_getSearchModeValue(r){switch(r){case 1:return q.MIN;case 0:return q.NORMAL;case-1:return q.MAX}}}class li extends A{calculate(r,e,t,s,i){var x,v;if(r==null||e==null||t==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return e;if(t.isError())return t;if(s!=null&&s.isError())return s;if(i!=null&&i.isError())return i;if(!r.isArray())return new h(c.VALUE);const a=r.getCurrentRow(),u=r.getCurrentColumn(),o=this.getIndexNumValue(e),l=this.getIndexNumValue(t);if(typeof o!="number"||typeof l!="number")return new h(c.VALUE);const f=a+o,m=u+l;if(f<0||m<0||f>1048576||m>16384)return new h(c.REF);const g=(x=s&&this.getIndexNumValue(s))!=null?x:1,R=(v=i&&this.getIndexNumValue(i))!=null?v:1;if(typeof g!="number"||typeof R!="number")return new h(c.VALUE);if(g===0||R===0)return new h(c.REF);const w=g>0?f+g-1:f+g+1,E=R>0?m+R-1:m+R+1;if(w<0||E<0||w>1048576||E>16384)return new h(c.REF);const C=f<w?f:w,y=m<E?m:E,S=f>w?f:w,L=m>E?m:E,V={startRow:C,startColumn:y,endRow:S,endColumn:L},I=r.getUnitId(),Q=r.getSheetId(),T=new Ke(V,Q,I);return this._setDefault(T)}_setDefault(r){return this.unitId==null||this.subUnitId==null?new h(c.REF):(r.setDefaultUnitId(this.unitId),r.setDefaultSheetId(this.subUnitId),r)}}class ci extends A{calculate(r){if(r==null)return new _(this.row+1);if(r.isError())return r;if(!r.isArray())return new h(c.NA);const e=r.getCurrentRow(),t=r.getRowCount(),s=[];for(let a=0;a<t;a++)s.push([new _(e+a+1)]);const i={calculateValueList:s,rowCount:t,columnCount:1,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return new z(i)}}class fi extends A{calculate(r){if(r==null)return new h(c.NA);if(r.isError())return r;if(r.isString()||r.isNumber()||r.isBoolean())return new _(1);if(!r.isArray())return new h(c.NA);const e=r.getRowCount();return new _(e)}}class hi extends A{calculate(r,e,t,s){if(r==null||e==null||t==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return new h(c.REF);if(!e.isArray())return new h(c.VALUE);if(t.isError())return new h(c.NA);if(s!=null&&s.isError())return new h(c.NA);const i=this.getZeroOrOneByOneDefault(s);if(i==null)return new h(c.VALUE);const a=this.getIndexNumValue(t);if(a instanceof h)return a;const u=e.slice(void 0,[0,1]),o=e.slice(void 0,[a-1,a]);return u==null||o==null?new h(c.VALUE):r.isArray()?r.map(l=>this._handleSingleObject(l,u,o,i)):this._handleSingleObject(r,u,o,i)}_handleSingleObject(r,e,t,s){return s===0?this.equalSearch(r,e,t):this.binarySearch(r,e,t)}}class mi extends A{calculate(r,e,t,s,i,a){if(r==null||e==null||t==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return new h(c.REF);if(!e.isArray())return new h(c.VALUE);const u=e.getRowCount(),o=e.getColumnCount();if(u!==1&&o!==1)return new h(c.VALUE);if(t.isError())return new h(c.REF);if(!t.isArray())return new h(c.VALUE);const l=t.getRowCount(),f=t.getColumnCount();if(u!==l&&o!==f)return new h(c.VALUE);if(s!=null&&s.isError())return new h(c.NA);if(i!=null&&i.isError())return new h(c.NA);if(a!=null&&a.isError())return new h(c.NA);s==null&&(s=new h(c.NA));const m=this.getIndexNumValue(i||new _(0));if(m instanceof h)return m;const g=this.getIndexNumValue(a||new _(1));if(g instanceof h)return g;if(r.isArray()){let E;return u===1?E=t.slice([0,1]):E=t.slice(void 0,[0,1]),E==null?new h(c.NA):r.map(C=>{const y=this._handleSingleObject(C,e,E,m,g);return y.isError()?s:y})}if(o===f&&u===l){const E=this._handleSingleObject(r,e,t,m,g);return E.isError()?s:E}let R=0;o===f&&(R=1);const w=this._handleExpandObject(r,e,t,m,g,R);return w==null?new h(c.NA):w}_handleExpandObject(r,e,t,s,i,a=0){return(i===2||i===-2)&&s!==2?this.binarySearchExpand(r,e,t,a,this._getSearchModeValue(i)):s===2?this.fuzzySearchExpand(r,e,t,i!==-1,a):s===-1||s===1?this.orderSearchExpand(r,e,t,s===1?q.MAX:q.MIN,i===-1,a):this.equalSearchExpand(r,e,t,i!==-1,a)}_handleSingleObject(r,e,t,s,i){return(i===2||i===-2)&&s!==2?this.binarySearch(r,e,t,this._getSearchModeValue(i)):s===2?this.fuzzySearch(r,e,t,i!==-1):s===-1||s===1?this.orderSearch(r,e,t,s===1?q.MAX:q.MIN,i===-1):this.equalSearch(r,e,t,i!==-1)}_getSearchModeValue(r){return r===-2?me.MAX:me.MIN}}class gi extends A{calculate(r,e,t,s){if(r==null||e==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return new h(c.REF);if(!e.isArray())return new h(c.VALUE);const i=e.getRowCount(),a=e.getColumnCount();if(i!==1&&a!==1)return new h(c.VALUE);if(t!=null&&t.isError())return new h(c.NA);if(s!=null&&s.isError())return new h(c.NA);const u=this.getIndexNumValue(t||new _(0));if(u instanceof h)return u;const o=this.getIndexNumValue(s||new _(1));return o instanceof h?o:r.isArray()?r.map(l=>this._handleSingleObject(l,e,u,o)):this._handleSingleObject(r,e,u,o)}_handleSingleObject(r,e,t,s){let i;if((s===2||s===-2)&&t!==2){const a=this._getSearchModeValue(s);i=e.binarySearch(r,a)}else if(t===2){const a=e.compare(r,b.EQUALS);let u;if(s!==-1?u=a.getFirstTruePosition():u=a.getLastTruePosition(),u==null)return new h(c.NA);i=e.getRowCount()===1?u.column:u.row}else if(t===-1||t===1){const a=e.orderSearch(r,t===1?q.MAX:q.MIN,s===-1);if(a==null)return new h(c.NA);if(a instanceof h)return a;i=e.getRowCount()===1?a.column:a.row}else{const a=e.isEqual(r);let u;if(s!==-1?u=a.getFirstTruePosition():u=a.getLastTruePosition(),u==null)return new h(c.NA);i=e.getRowCount()===1?u.column:u.row}return i==null?new h(c.NA):new _(i+1)}_getSearchModeValue(r){return r===-2?me.MAX:me.MIN}}class di extends A{calculate(r,e,t,s){if(r==null)return new h(c.NA);if(r.isError())return r;if(e!=null&&e.isError())return e;if(t!=null&&t.isError())return t;if(s!=null&&s.isError())return s;if(!r.isArray())return new h(c.REF);const i=r.getRowCount(),a=r.getColumnCount();i===1&&a>1&&t==null?(t=e!=null?e:new _(0),e=new _(0)):(e=e!=null?e:new _(0),t=t!=null?t:new _(0)),s=s!=null?s:new _(1);const u=Math.max(e.isArray()?e.getRowCount():1,t.isArray()?t.getRowCount():1,s.isArray()?s.getRowCount():1),o=Math.max(e.isArray()?e.getColumnCount():1,t.isArray()?t.getColumnCount():1,s.isArray()?s.getColumnCount():1);if(u===1&&o===1)return this._calculateSingleCell(r,e,t,s);{const l=j(u,o,e,new h(c.NA)),f=j(u,o,t,new h(c.NA)),m=j(u,o,s,new h(c.NA));return l.map((g,R,w)=>{const E=f.get(R,w),C=m.get(R,w),y=this._calculateSingleCell(r,g,E,C);return y.isArray()?y.getFirstCell():y})}}_calculateSingleCell(r,e,t,s){if(e.isError())return e;const i=this._getNumberValue(e);if(i===void 0||i<0)return new h(c.VALUE);if(t.isError())return t;const a=this._getNumberValue(t);if(a===void 0||a<0)return new h(c.VALUE);if(s.isError())return s;const u=this._getAreaNumberValue(s);if(u===void 0||u<1)return new h(c.VALUE);const o=i===0?[void 0]:[i-1,i],l=a===0?[void 0]:[a-1,a],f=r.slice(o,l);return f||new h(c.REF)}_getNumberValue(r){if(r==null)return 0;let e=0;if(r.isBoolean())r.getValue()===!0&&(e=1);else{if(r.isString())return;r.isNumber()?e=Math.floor(r.getValue()):r.isNull()&&(e=0)}return e}_getAreaNumberValue(r){if(r==null)return 1;let e=0;if(r.isBoolean())r.getValue()===!0&&(e=1);else{if(r.isString())return;r.isNumber()?e=Math.floor(r.getValue()):r.isNull()&&(e=0)}return e}}const Cn=[[ti,G.ADDRESS],[ni,G.COLUMN],[si,G.COLUMNS],[di,G.INDEX],[ai,G.INDIRECT],[li,G.OFFSET],[ci,G.ROW],[fi,G.ROWS],[hi,G.VLOOKUP],[ui,G.LOOKUP],[oi,G.MATCH],[ii,G.HLOOKUP],[mi,G.XLOOKUP],[gi,G.XMATCH]];class Ri extends A{calculate(r){return r==null?new h(c.NA):r.isError()?new h(c.VALUE):r.abs()}}class Ei extends A{calculate(r){return r==null?new h(c.NA):r.isError()?r:r.acos()}}class wi extends A{calculate(r){return r==null?new h(c.NA):r.isError()?new h(c.VALUE):r.acosh()}}class _i extends A{calculate(r){return r==null?new h(c.NA):r.isError()?r:r.isArray()?r.map(e=>e.isError()?e:pn(e)):pn(r)}}function pn(n){let r=n.getValue();if(n.isBoolean()&&(r=r?1:0),!Number.isFinite(r))return new h(c.VALUE);const e=Math.atan(1/Number(r));return Number.isNaN(e)?new h(c.VALUE):new _(e)}var N=(n=>(n.ABS="ABS",n.ACOS="ACOS",n.ACOSH="ACOSH",n.ACOT="ACOT",n.ACOTH="ACOTH",n.AGGREGATE="AGGREGATE",n.ARABIC="ARABIC",n.ASIN="ASIN",n.ASINH="ASINH",n.ATAN="ATAN",n.ATAN2="ATAN2",n.ATANH="ATANH",n.BASE="BASE",n.CEILING="CEILING",n.CEILING_MATH="CEILING.MATH",n.CEILING_PRECISE="CEILING.PRECISE",n.COMBIN="COMBIN",n.COMBINA="COMBINA",n.COS="COS",n.COSH="COSH",n.COT="COT",n.COTH="COTH",n.CSC="CSC",n.CSCH="CSCH",n.DECIMAL="DECIMAL",n.DEGREES="DEGREES",n.EVEN="EVEN",n.EXP="EXP",n.FACT="FACT",n.FACTDOUBLE="FACTDOUBLE",n.FLOOR="FLOOR",n.FLOOR_MATH="FLOOR.MATH",n.FLOOR_PRECISE="FLOOR.PRECISE",n.GCD="GCD",n.INT="INT",n.ISO_CEILING="ISO.CEILING",n.LCM="LCM",n.LET="LET",n.LN="LN",n.LOG="LOG",n.LOG10="LOG10",n.MDETERM="MDETERM",n.MINVERSE="MINVERSE",n.MMULT="MMULT",n.MOD="MOD",n.MROUND="MROUND",n.MULTINOMIAL="MULTINOMIAL",n.MUNIT="MUNIT",n.ODD="ODD",n.PI="PI",n.POWER="POWER",n.PRODUCT="PRODUCT",n.QUOTIENT="QUOTIENT",n.RADIANS="RADIANS",n.RAND="RAND",n.RANDARRAY="RANDARRAY",n.RANDBETWEEN="RANDBETWEEN",n.ROMAN="ROMAN",n.ROUND="ROUND",n.ROUNDDOWN="ROUNDDOWN",n.ROUNDUP="ROUNDUP",n.SEC="SEC",n.SECH="SECH",n.SERIESSUM="SERIESSUM",n.SEQUENCE="SEQUENCE",n.SIGN="SIGN",n.SIN="SIN",n.SINH="SINH",n.SQRT="SQRT",n.SQRTPI="SQRTPI",n.SUBTOTAL="SUBTOTAL",n.SUM="SUM",n.SUMIF="SUMIF",n.SUMIFS="SUMIFS",n.SUMPRODUCT="SUMPRODUCT",n.SUMSQ="SUMSQ",n.SUMX2MY2="SUMX2MY2",n.SUMX2PY2="SUMX2PY2",n.SUMXMY2="SUMXMY2",n.TAN="TAN",n.TANH="TANH",n.TRUNC="TRUNC",n))(N||{});class Ci extends A{calculate(r,e){return r==null||e==null?new h(c.NA):r.isError()?r:e.isError()?e:r.mod(e)}}class pi extends A{calculate(r,e){return r==null||e==null?new h(c.NA):r.isError()?r:e.isError()?e:r.pow(e)}}class Di extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new _(1);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError())return s;if(s.isString()){const i=s.getValue();if(!d.isRealNum(i))return new h(c.VALUE);s=new _(i)}if(s.isArray()&&(s=this._multiplyArray(s),s.isError()))return s;if(!s.isNull()&&(e=e.multiply(s),e.isError()))return e}return e}_multiplyArray(r){let e=new _(1);return r.iterator(t=>{if(t==null||t.isString()||t.isBoolean()||t.isNull())return!0;if(t.isError())return e=t,!1;e=e.multiply(t)}),e}}class yi extends A{constructor(){super(...arguments);p(this,"needsReferenceObject",!0)}calculate(e,...t){if(e==null)return new h(c.NA);if(e.isError())return e;if(t.length===0)return new h(c.NA);if(e.isReferenceObject()){const s=[];return e.iterator((i,a,u)=>{s[a]==null&&(s[a]=[]),s[a][u]=this._handleSingleObject(i,...t)}),gt(s,s.length,s[0].length)}return this._handleSingleObject(e,...t)}_handleSingleObject(e,...t){const s=this._getIndexNumValue(e);let i;if(s instanceof h)return s;switch(s){case 1:i=this._average(!1,...t);break;case 2:i=this._count(!1,...t);break;case 3:i=this._counta(!1,...t);break;case 4:i=this._max(!1,...t);break;case 5:i=this._min(!1,...t);break;case 6:i=this._product(!1,...t);break;case 7:i=this._stdev(!1,...t);break;case 8:i=this._stdevp(!1,...t);break;case 9:i=this._sum(!1,...t);break;case 10:i=this._var(!1,...t);break;case 11:i=this._varp(!1,...t);break;case 101:i=this._average(!0,...t);break;case 102:i=this._count(!0,...t);break;case 103:i=this._counta(!0,...t);break;case 104:i=this._max(!0,...t);break;case 105:i=this._min(!0,...t);break;case 106:i=this._product(!0,...t);break;case 107:i=this._stdev(!0,...t);break;case 108:i=this._stdevp(!0,...t);break;case 109:i=this._sum(!0,...t);break;case 110:i=this._var(!0,...t);break;case 111:i=this._varp(!0,...t);break;default:i=new h(c.VALUE)}return i}_getIndexNumValue(e){const t=e?Number(e.getValue()):0;if(isNaN(t))return new h(c.VALUE);const s=Math.floor(t);return s>=1&&s<=11||s>=101&&s<=111?s:new h(c.VALUE)}_average(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.mean()}_count(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.count()}_counta(e,...t){let s=new _(0);for(let i=0;i<t.length;i++){const a=t[i];if(!a.isReferenceObject())return new h(c.VALUE);const u=a.getRowData();a.iterator((o,l)=>{if(e&&this._isRowHidden(u,l)||o==null||o.isNull())return!0;s=s.plusBy(1)})}return s}_max(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new _(0):s.max()}_min(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new _(0):s.min()}_product(e,...t){const s=this._flattenRefArray(e,...t);if(s.isError())return s;if(this._isBlankArrayObject(s))return new _(0);let i=new _(1);return s.iterator(a=>{i=i.multiply(a)}),i}_stdev(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new h(c.DIV_BY_ZERO):s.std(1)}_stdevp(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new h(c.DIV_BY_ZERO):s.std()}_sum(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.sum()}_var(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new h(c.DIV_BY_ZERO):s.var(1)}_varp(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new h(c.DIV_BY_ZERO):s.var()}_flattenRefArray(e,...t){const s=[];s[0]=[];for(let i=0;i<t.length;i++){const a=t[i];if(a.isError())return a;if(!a.isReferenceObject())return new h(c.VALUE);const u=a.getRowData();let o;if(a.iterator((l,f)=>{if(e&&this._isRowHidden(u,f)||l==null||l.isNull()||l.isString()||l.isBoolean())return!0;if(l.isError())return o=l,!1;s[0].push(l)}),o!=null&&o.isError())return o}return gt(s,1,s[0].length)}_isRowHidden(e,t){const s=e[t];return s?s.hd===d.BooleanNumber.TRUE:!1}_isBlankArrayObject(e){return e.getArrayValue()[0].length===0}}class bi extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new _(0);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError())return s;if(s.isString()){const i=s.getValue();if(!d.isRealNum(i))return new h(c.VALUE);s=new _(i)}if(s.isArray()&&(s=s.sum()),e=e.plus(s),e.isError())return e}return e}}function Si(n){const r=[b.EQUALS,b.NOT_EQUAL,b.GREATER_THAN_OR_EQUAL,b.GREATER_THAN,b.LESS_THAN_OR_EQUAL,b.LESS_THAN];for(const e of r)if(n.startsWith(e)){const t=n.substring(e.length);return[e,_e.create(t)]}return[b.EQUALS,_e.create(n)]}function Dn(n,r,e){if(!e)if(r.isString()){const t=`${r.getValue()}`,[s,i]=Si(t);e=s,r=i}else e=b.EQUALS;return n.compare(r,e)}function Li(n,r){const e=Math.max(n.isArray()?n.getRowCount():1,r.isArray()?r.getRowCount():1),t=Math.max(n.isArray()?n.getColumnCount():1,r.isArray()?r.getColumnCount():1),s=j(e,t,n),i=j(e,t,r);return s.mapValue((a,u,o)=>{const l=i.get(u,o);return a!=null&&a.isError()?a:l!=null&&l.isError()?l:a!=null&&a.isBoolean()&&(l!=null&&l.isBoolean())?new P(a.getValue()&&l.getValue()):new P(!1)})}class Ai extends A{calculate(r,e,t){return r==null||e==null?new h(c.NA):r.isError()||e.isError()||t!=null&&t.isError()?new h(c.NA):!r.isArray()||t&&!t.isArray()?new h(c.VALUE):e.isArray()?e.map(s=>this._handleSingleObject(r,s,t)):this._handleSingleObject(r,e,t)}_handleSingleObject(r,e,t){const s=Dn(r,e),i=t?t.slice([0,r.getRowCount()],[0,r.getColumnCount()]):r;return i?i.pick(s).sum():new h(c.VALUE)}}class Pi extends A{calculate(r,...e){if(r==null)return new h(c.NA);if(e.length<2)return new h(c.NA);if(r.isError())return new h(c.NA);if(!r.isArray())return new h(c.VALUE);if(e.length<2||e.length%2!==0)return new h(c.VALUE);if(e.some((f,m)=>m%2===0&&!f.isArray()))return new h(c.VALUE);const t=r.getRowCount(),s=r.getColumnCount();let i=0,a=0;e.forEach((f,m)=>{if(m%2===1)if(f.isArray()){const g=f;i=Math.max(i,g.getRowCount()),a=Math.max(a,g.getColumnCount())}else i=Math.max(i,1),a=Math.max(a,1)});const u=[];for(let f=0;f<e.length;f++){if(f%2===1)continue;const m=e[f],g=m.getRowCount(),R=m.getColumnCount();if(g!==t||R!==s)return j(i,a,new h(c.NA));const w=e[f+1];j(i,a,w,new h(c.NA)).iterator((C,y,S)=>{if(!C)return;const L=Dn(m,C);if(u[y]===void 0&&(u[y]=[]),u[y][S]===void 0){u[y][S]=L;return}u[y][S]=Li(u[y][S],L)})}const o=u.map(f=>f.map(m=>r.pick(m).sum())),l={calculateValueList:o,rowCount:o.length,columnCount:o[0].length,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return new z(l)}}const yn=[[Ri,N.ABS],[Ei,N.ACOS],[wi,N.ACOSH],[_i,N.ACOT],[Ci,N.MOD],[yi,N.SUBTOTAL],[bi,N.SUM],[Ai,N.SUMIF],[Pi,N.SUMIFS],[pi,N.POWER],[Di,N.PRODUCT]];class Vi extends A{constructor(){super(...arguments);p(this,"_compareType",b.EQUALS)}setCompareType(e){this._compareType=e}calculate(e,t){return e.isError()||t.isError()?e:e.compare(t,this._compareType)}}class xi extends A{calculate(r,e){return r.isError()||e.isError()?r:!e.isArray()&&e.getValue()===0?new h(c.DIV_BY_ZERO):r.divided(e)}}var Z=(n=>(n.COMPARE="COMPARE",n.DIVIDED="DIVIDED",n.MINUS="MINUS",n.MULTIPLY="MULTIPLY",n.PLUS="PLUS",n.UNION="UNION",n))(Z||{});class vi extends A{calculate(r,e){return r.isError()||e.isError()?r:r.minus(e)}}class Bi extends A{calculate(r,e){return r.isError()?r:e.isError()?e:r.multiply(e)}}class Ui extends A{calculate(r,e){return r.isError()?r:e.isError()?e:r.plus(e)}}const bn=[[Vi,Z.COMPARE],[xi,Z.DIVIDED],[vi,Z.MINUS],[Bi,Z.MULTIPLY],[Ui,Z.PLUS]];class Mi extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new _(0),t=new _(0);for(let s=0;s<r.length;s++){let i=r[s];if(i.isError())return i;if(i.isString()){const a=i.getValue();if(!d.isRealNum(a))return new h(c.VALUE);i=new _(a)}if(i.isArray()){if(e=e.plus(i.sum()),e.isError())return e;t=t.plus(i.count())}else i.isNull()||(e=e.plus(new _(i.getValue())),t=t.plus(new _(1)))}return e.divided(t)}}class Oi extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new _(0);for(let t=0;t<r.length;t++){let s=r[t];if(!s.isError())if(s.isArray())s=s.count(),e=e.plus(s);else if(s.isString()){const i=s.getValue();d.isRealNum(i)&&(e=e.plus(new _(1)))}else s.isNull()||(e=e.plus(new _(1)))}return e}}class Fi extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new _(0);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError()){e=e.plus(new _(1));continue}s.isArray()?(s=s.countA(),e=e.plus(s)):s.isNull()||(e=e.plus(new _(1)))}return e}}var K=(n=>(n.AVEDEV="AVEDEV",n.AVERAGE="AVERAGE",n.AVERAGEA="AVERAGEA",n.AVERAGEIF="AVERAGEIF",n.AVERAGEIFS="AVERAGEIFS",n.BETA_DIST="BETA.DIST",n.BETA_INV="BETA.INV",n.BINOM_DIST="BINOM.DIST",n.BINOM_DIST_RANGE="BINOM.DIST.RANGE",n.BINOM_INV="BINOM.INV",n.CHISQ_DIST="CHISQ.DIST",n.CHISQ_DIST_RT="CHISQ.DIST.RT",n.CHISQ_INV="CHISQ.INV",n.CHISQ_INV_RT="CHISQ.INV.RT",n.CHISQ_TEST="CHISQ.TEST",n.CONFIDENCE_NORM="CONFIDENCE.NORM",n.CONFIDENCE_T="CONFIDENCE.T",n.CORREL="CORREL",n.COUNT="COUNT",n.COUNTA="COUNTA",n.COUNTBLANK="COUNTBLANK",n.COUNTIF="COUNTIF",n.COUNTIFS="COUNTIFS",n.COVARIANCE_P="COVARIANCE.P",n.COVARIANCE_S="COVARIANCE.S",n.DEVSQ="DEVSQ",n.EXPON_DIST="EXPON.DIST",n.F_DIST="F.DIST",n.F_DIST_RT="F.DIST.RT",n.F_INV="F.INV",n.F_INV_RT="F.INV.RT",n.F_TEST="F.TEST",n.FISHER="FISHER",n.FISHERINV="FISHERINV",n.FORECAST="FORECAST",n.FORECAST_ETS="FORECAST.ETS",n.FORECAST_ETS_CONFINT="FORECAST.ETS.CONFINT",n.FORECAST_ETS_SEASONALITY="FORECAST.ETS.SEASONALITY",n.FORECAST_ETS_STAT="FORECAST.ETS.STAT",n.FORECAST_LINEAR="FORECAST.LINEAR",n.FREQUENCY="FREQUENCY",n.GAMMA="GAMMA",n.GAMMA_DIST="GAMMA.DIST",n.GAMMA_INV="GAMMA.INV",n.GAMMALN="GAMMALN",n.GAMMALN_PRECISE="GAMMALN.PRECISE",n.GAUSS="GAUSS",n.GEOMEAN="GEOMEAN",n.GROWTH="GROWTH",n.HARMEAN="HARMEAN",n.HYPGEOM_DIST="HYPGEOM.DIST",n.INTERCEPT="INTERCEPT",n.KURT="KURT",n.LARGE="LARGE",n.LINEST="LINEST",n.LOGEST="LOGEST",n.LOGNORM_DIST="LOGNORM.DIST",n.LOGNORM_INV="LOGNORM.INV",n.MAX="MAX",n.MAXA="MAXA",n.MAXIFS="MAXIFS",n.MEDIAN="MEDIAN",n.MIN="MIN",n.MINA="MINA",n.MINIFS="MINIFS",n.MODE_MULT="MODE.MULT",n.MODE_SNGL="MODE.SNGL",n.NEGBINOM_DIST="NEGBINOM.DIST",n.NORM_DIST="NORM.DIST",n.NORM_INV="NORM.INV",n.NORM_S_DIST="NORM.S.DIST",n.NORM_S_INV="NORM.S.INV",n.PEARSON="PEARSON",n.PERCENTILE_EXC="PERCENTILE.EXC",n.PERCENTILE_INC="PERCENTILE.INC",n.PERCENTRANK_EXC="PERCENTRANK.EXC",n.PERCENTRANK_INC="PERCENTRANK.INC",n.PERMUT="PERMUT",n.PERMUTATIONA="PERMUTATIONA",n.PHI="PHI",n.POISSON_DIST="POISSON.DIST",n.PROB="PROB",n.QUARTILE_EXC="QUARTILE.EXC",n.QUARTILE_INC="QUARTILE.INC",n.RANK_AVG="RANK.AVG",n.RANK_EQ="RANK.EQ",n.RSQ="RSQ",n.SKEW="SKEW",n.SKEW_P="SKEW.P",n.SLOPE="SLOPE",n.SMALL="SMALL",n.STANDARDIZE="STANDARDIZE",n.STDEV_P="STDEV.P",n.STDEV_S="STDEV.S",n.STDEVA="STDEVA",n.STDEVPA="STDEVPA",n.STEYX="STEYX",n.T_DIST="T.DIST",n.T_DIST_2T="T.DIST.2T",n.T_DIST_RT="T.DIST.RT",n.T_INV="T.INV",n.T_INV_2T="T.INV.2T",n.T_TEST="T.TEST",n.TREND="TREND",n.TRIMMEAN="TRIMMEAN",n.VAR_P="VAR.P",n.VAR_S="VAR.S",n.VARA="VARA",n.VARPA="VARPA",n.WEIBULL_DIST="WEIBULL.DIST",n.Z_TEST="Z.TEST",n))(K||{});class $i extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new _(Number.NEGATIVE_INFINITY);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError())return s;if(s.isString()){const i=s.getValue();if(!d.isRealNum(i))return new h(c.VALUE);s=new _(i)}if(s.isBoolean()&&(s=mt(s)),s.isArray()&&(s=s.max(),s.isError()))return s;s.isNull()||(e=this._validator(e,s))}return e}_validator(r,e){return r.isLessThan(e).getValue()&&(r=e),r}}class Sn extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new _(Number.POSITIVE_INFINITY);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError())return s;if(s.isString()){const i=s.getValue();if(!d.isRealNum(i))return new h(c.VALUE);s=new _(i)}if(s.isBoolean()&&(s=mt(s)),s.isArray()&&(s=s.min(),s.isError()))return s;s.isNull()||(e=this._validator(e,s))}return e}_validator(r,e){return r.isGreaterThan(e).getValue()&&(r=e),r}}class ki extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r,!1);return e.isError()?e:e.std(1)}}class Ii extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r,!1);return e.isError()?e:e.std()}}class Ti extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r,!1);return e.isError()?e:e.var(1)}}class Qi extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r,!1);return e.isError()?e:e.var()}}const Ln=[[Mi,K.AVERAGE],[Oi,K.COUNT],[$i,K.MAX],[Sn,K.MIN],[Sn,K.MIN],[Fi,K.COUNTA],[en,K.STDEV_P],[tn,K.STDEV_S],[ki,K.STDEVA],[Ii,K.STDEVPA],[rn,K.VAR_P],[nn,K.VAR_S],[Ti,K.VARA],[Qi,K.VARPA]];class Yi extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=0,t=0;r.forEach(i=>{if(i.isArray()){const a=i;e=Math.max(e,a.getRowCount()),t=Math.max(t,a.getColumnCount())}else e=Math.max(e,1),t=Math.max(t,1)});let s=null;for(const i of r)s=j(e,t,i,new h(c.NA)).mapValue((u,o,l)=>{var R,w;const f=s&&s.get(o,l);if(f!=null&&f.isError())return f;if(u.isError())return u;const m=f!=null&&f.isNull()?"":(R=f==null?void 0:f.getValue())!=null?R:"",g=u!=null&&u.isNull()?"":(w=u==null?void 0:u.getValue())!=null?w:"";return new X(`${m}${g}`)});return s||new h(c.VALUE)}}var Rt=(n=>(n.ASC="ASC",n.ARRAYTOTEXT="ARRAYTOTEXT",n.BAHTTEXT="BAHTTEXT",n.CHAR="CHAR",n.CLEAN="CLEAN",n.CODE="CODE",n.CONCAT="CONCAT",n.CONCATENATE="CONCATENATE",n.DBCS="DBCS",n.DOLLAR="DOLLAR",n.EXACT="EXACT",n.FIND="FIND",n.FINDB="FINDB",n.FIXED="FIXED",n.LEFT="LEFT",n.LEFTB="LEFTB",n.LEN="LEN",n.LENB="LENB",n.LOWER="LOWER",n.MID="MID",n.MIDB="MIDB",n.NUMBERVALUE="NUMBERVALUE",n.PHONETIC="PHONETIC",n.PROPER="PROPER",n.REPLACE="REPLACE",n.REPLACEB="REPLACEB",n.REPT="REPT",n.RIGHT="RIGHT",n.RIGHTB="RIGHTB",n.SEARCH="SEARCH",n.SEARCHB="SEARCHB",n.SUBSTITUTE="SUBSTITUTE",n.T="T",n.TEXT="TEXT",n.TEXTAFTER="TEXTAFTER",n.TEXTBEFORE="TEXTBEFORE",n.TEXTJOIN="TEXTJOIN",n.TEXTSPLIT="TEXTSPLIT",n.TRIM="TRIM",n.UNICHAR="UNICHAR",n.UNICODE="UNICODE",n.UPPER="UPPER",n.VALUE="VALUE",n.VALUETOTEXT="VALUETOTEXT",n.CALL="CALL",n.EUROCONVERT="EUROCONVERT",n.REGISTER_ID="REGISTER.ID",n))(Rt||{});const An=[[Yi,Rt.CONCATENATE]],Pn=[];var Hi=(n=>{})();const Vn=[];var xn=(n=>(n.ENCODEURL="ENCODEURL",n.FILTERXML="FILTERXML",n.WEBSERVICE="WEBSERVICE",n))(xn||{});class ji extends d.Disposable{constructor(){super(...arguments);p(this,"_definedNameMap",new Map)}dispose(){this._definedNameMap.clear()}registerDefinedName(e,t,s){var a;this._definedNameMap.get(e)==null&&this._definedNameMap.set(e,new Map),(a=this._definedNameMap.get(e))==null||a.set(t,s)}removeDefinedName(e,t){var s;(s=this._definedNameMap.get(e))==null||s.delete(t)}getDefinedNameMap(e){return this._definedNameMap.get(e)}getValue(e,t){var s;return(s=this._definedNameMap.get(e))==null?void 0:s.get(t)}hasDefinedName(e){var s;return(((s=this._definedNameMap.get(e))==null?void 0:s.size)||0)!==0}}const Et=B.createIdentifier("univer.formula.defined-names.service");var Wi=Object.defineProperty,Xi=Object.getOwnPropertyDescriptor,Gi=(n,r,e,t)=>{for(var s=t>1?void 0:t?Xi(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Wi(r,e,s),s},Ki=(n,r)=>(e,t)=>r(e,t,n);let ar=class extends d.Disposable{constructor(r){super();p(this,"_unitData",{});p(this,"_arrayFormulaCellData",{});p(this,"_formulaData",{});p(this,"_sheetNameMap",{});p(this,"_forceCalculate",!1);p(this,"_dirtyRanges",[]);p(this,"_dirtyNameMap",{});p(this,"_numfmtItemMap",{});p(this,"_dirtyUnitFeatureMap",{});p(this,"_excludedCell");this._currentUniverService=r}dispose(){this._unitData={},this._formulaData={},this._arrayFormulaCellData={},this._sheetNameMap={},this._dirtyRanges=[],this._dirtyNameMap={},this._numfmtItemMap={},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}getNumfmtItemMap(){return this._numfmtItemMap}getDirtyUnitFeatureMap(){return this._dirtyUnitFeatureMap}load(r){if(r.allUnitData&&r.unitSheetNameMap)this._unitData=r.allUnitData,this._sheetNameMap=r.unitSheetNameMap;else{const{allUnitData:e,unitSheetNameMap:t}=this._loadSheetData();this._unitData=e,this._sheetNameMap=t}this._formulaData=r.formulaData,this._arrayFormulaCellData=pr(r.arrayFormulaCellData),this._forceCalculate=r.forceCalculate,this._dirtyRanges=r.dirtyRanges,this._dirtyNameMap=r.dirtyNameMap,this._numfmtItemMap=r.numfmtItemMap,this._dirtyUnitFeatureMap=r.dirtyUnitFeatureMap,this._excludedCell=r.excludedCell,this._mergeNameMap(this._sheetNameMap,this._dirtyNameMap)}loadDirtyRangesAndExcludedCell(r,e){this._dirtyRanges=r,this._excludedCell=e,this._dirtyNameMap={}}registerUnitData(r){this._unitData=r}registerFormulaData(r){this._formulaData=r}registerSheetNameMap(r){this._sheetNameMap=r}_mergeNameMap(r,e){Object.keys(e).forEach(t=>{e[t]&&Object.keys(e[t]).forEach(s=>{r[t]==null&&(r[t]={}),r[t][e[t][s]]=s})})}_loadSheetData(){const r=this._currentUniverService.getAllUniverSheetsInstance(),e={},t={};for(const s of r){const i=s.getUnitId(),a=s.getSheets(),u={},o={};for(const l of a){const f=l.getSheetId(),m=l.getConfig();u[f]={cellData:new d.ObjectMatrix(m.cellData),rowCount:m.rowCount,columnCount:m.columnCount,rowData:m.rowData,columnData:m.columnData},o[l.getName()]=l.getSheetId()}e[i]=u,t[i]=o}return{allUnitData:e,unitSheetNameMap:t}}};ar=Gi([Ki(0,d.IUniverInstanceService)],ar);const xe=B.createIdentifier("univer.formula.current-data.service");var qi=Object.defineProperty,zi=Object.getOwnPropertyDescriptor,Zi=(n,r,e,t)=>{for(var s=t>1?void 0:t?zi(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&qi(r,e,s),s},Ji=(n,r)=>(e,t)=>r(e,t,n),oe=(n=>(n[n.IDLE=0]="IDLE",n[n.START_DEPENDENCY=1]="START_DEPENDENCY",n[n.START_CALCULATION=2]="START_CALCULATION",n[n.CURRENTLY_CALCULATING=3]="CURRENTLY_CALCULATING",n[n.START_DEPENDENCY_ARRAY_FORMULA=4]="START_DEPENDENCY_ARRAY_FORMULA",n[n.START_CALCULATION_ARRAY_FORMULA=5]="START_CALCULATION_ARRAY_FORMULA",n[n.CURRENTLY_CALCULATING_ARRAY_FORMULA=6]="CURRENTLY_CALCULATING_ARRAY_FORMULA",n[n.CALCULATION_COMPLETED=7]="CALCULATION_COMPLETED",n))(oe||{}),Te=(n=>(n[n.INITIAL=0]="INITIAL",n[n.STOP_EXECUTION=1]="STOP_EXECUTION",n[n.NOT_EXECUTED=2]="NOT_EXECUTED",n[n.SUCCESS=3]="SUCCESS",n))(Te||{});let ur=class extends d.Disposable{constructor(r){super();p(this,"_formulaExecuteStage",0);p(this,"_stopState",!1);p(this,"_currentRow",-1);p(this,"_currentColumn",-1);p(this,"_currentRowCount",Number.NEGATIVE_INFINITY);p(this,"_currentColumnCount",Number.NEGATIVE_INFINITY);p(this,"_currentSubUnitId","");p(this,"_currentUnitId","");p(this,"_runtimeData",{});p(this,"_runtimeOtherData",{});p(this,"_unitArrayFormulaRange",{});p(this,"_runtimeArrayFormulaCellData",{});p(this,"_runtimeClearArrayFormulaCellData",{});p(this,"_numfmtItemMap",{});p(this,"_runtimeFeatureRange",{});p(this,"_runtimeFeatureCellData",{});p(this,"_functionsExecutedState",0);p(this,"_functionDefinitionPrivacyVar",new Map);p(this,"_totalFormulasToCalculate",0);p(this,"_completedFormulasCount",0);p(this,"_totalArrayFormulasToCalculate",0);p(this,"_completedArrayFormulasCount",0);p(this,"_isCycleDependency",!1);this._currentConfigService=r}get currentRow(){return this._currentRow}get currentColumn(){return this._currentColumn}get currentRowCount(){return this._currentRowCount}get currentColumnCount(){return this._currentColumnCount}get currentSubUnitId(){return this._currentSubUnitId}get currentUnitId(){return this._currentUnitId}dispose(){this.reset(),this._runtimeFeatureCellData={},this._runtimeFeatureRange={}}enableCycleDependency(){this._isCycleDependency=!0}disableCycleDependency(){this._isCycleDependency=!1}isCycleDependency(){return this._isCycleDependency}setTotalArrayFormulasToCalculate(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._numfmtItemMap={},this._runtimeArrayFormulaCellData={},this._runtimeClearArrayFormulaCellData={},this._functionDefinitionPrivacyVar.clear(),this.markedAsInitialFunctionsExecuted(),this._isCycleDependency=!1,this._totalFormulasToCalculate=0,this._completedFormulasCount=0}setCurrent(r,e,t,s,i,a){this._currentRow=r,this._currentColumn=e,this._currentRowCount=t,this._currentColumnCount=s,this._currentSubUnitId=i,this._currentUnitId=a}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._currentSubUnitId,s=this._currentUnitId;this._runtimeOtherData[s]===void 0&&(this._runtimeOtherData[s]={});const i=this._runtimeOtherData[s];i[t]===void 0&&(i[t]={});const a=i[t];a[r]=this._objectValueToCellValue(e)}setRuntimeData(r){const e=this._currentRow,t=this._currentColumn,s=this._currentRowCount,i=this.currentColumnCount,a=this._currentSubUnitId,u=this._currentUnitId;this._runtimeData[u]==null&&(this._runtimeData[u]={});const o=this._runtimeData[u];o[a]==null&&(o[a]=new d.ObjectMatrix),this._unitArrayFormulaRange[u]==null&&(this._unitArrayFormulaRange[u]={}),this._numfmtItemMap[u]==null&&(this._numfmtItemMap[u]={}),this._numfmtItemMap[u][a]==null&&(this._numfmtItemMap[u][a]={});const l=this._numfmtItemMap[u][a],f=this._unitArrayFormulaRange[u];let m=new d.ObjectMatrix;f[a]&&(m=new d.ObjectMatrix(f[a])),this._runtimeArrayFormulaCellData[u]===void 0&&(this._runtimeArrayFormulaCellData[u]={});const g=this._runtimeArrayFormulaCellData[u];g[a]==null&&(g[a]=new d.ObjectMatrix),this._runtimeClearArrayFormulaCellData[u]===void 0&&(this._runtimeClearArrayFormulaCellData[u]={});const R=this._runtimeClearArrayFormulaCellData[u];R[a]==null&&(R[a]=new d.ObjectMatrix);const w=o[a],E=g[a],C=R[a];if(r.isReferenceObject()||r.isValueObject()&&r.isArray()){const y=r,{startRow:S,startColumn:L,endRow:V,endColumn:I}=y.getRangePosition();if(S===V&&L===I){const T=y.getFirstCell(),x=this._objectValueToCellValue(T);w.setValue(e,t,x),C.setValue(e,t,x),l[e]==null&&(l[e]={}),l[e][t]=T.getPattern();return}const Q={startRow:e,startColumn:t,endRow:V-S+e,endColumn:I-L+t};if(m.setValue(e,t,Q),f[a]=m.getData(),this._checkIfArrayFormulaRangeHasData(u,a,e,t,Q)||this._checkIfArrayFormulaExceeded(s,i,Q)){const T=this._objectValueToCellValue(new h(c.SPILL));w.setValue(e,t,T),C.setValue(e,t,T)}else{const T=new h(c.SPILL);y.iterator((x,v,$)=>{const k=this._objectValueToCellValue(x);if(v===S&&$===L){if(x!=null&&x.isError()&&x.isEqualType(T))return C.setValue(e,t,{}),w.setValue(e,t,{...this._objectValueToCellValue(T)}),!1;w.setValue(e,t,{...k})}const Ye=v-S+e,Kn=$-L+t;E.setValue(Ye,Kn,k);const qn=x==null?void 0:x.getPattern();qn&&(l[Ye]==null&&(l[Ye]={}),l[Ye][Kn]=qn)})}}else{const y=this._objectValueToCellValue(r);w.setValue(e,t,y),l[e]==null&&(l[e]={}),l[e][t]=r.getPattern(),C.setValue(e,t,y)}}getUnitData(){return this._runtimeData}getUnitArrayFormula(){return this._unitArrayFormulaRange}getNumfmtItemMap(){return this._numfmtItemMap}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(),numfmtItemMap:this.getNumfmtItemMap(),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:d.CellValueType.NUMBER};if(r.isError())return{v:r.getErrorType(),t:d.CellValueType.STRING};if(r.isValueObject()){const e=r,t=e.getValue();return e.isNumber()?{v:t,t:d.CellValueType.NUMBER}:e.isBoolean()?{v:t,t:d.CellValueType.BOOLEAN}:e.isString()&&d.isRealNum(t)?{v:t,t:d.CellValueType.FORCE_STRING}:{v:t,t:d.CellValueType.STRING}}}_checkIfArrayFormulaRangeHasData(r,e,t,s,i){var g,R,w,E,C,y,S,L,V,I,Q,T;const{startRow:a,startColumn:u,endRow:o,endColumn:l}=i,f=this._currentConfigService.getUnitData(),m=(w=(R=(g=this._unitArrayFormulaRange[r])==null?void 0:g[e])==null?void 0:R[t])==null?void 0:w[s];for(let x=a;x<=o;x++)for(let v=u;v<=l;v++){if(x===t&&s===v)continue;const $=(y=(C=(E=this._runtimeData)==null?void 0:E[r])==null?void 0:C[e])==null?void 0:y.getValue(x,v),k=(V=(L=(S=this._runtimeArrayFormulaCellData)==null?void 0:S[r])==null?void 0:L[e])==null?void 0:V.getValue(x,v),Ye=(T=(Q=(I=f==null?void 0:f[r])==null?void 0:I[e])==null?void 0:Q.cellData)==null?void 0:T.getValue(x,v);if(!d.isNullCell($)||!d.isNullCell(k)&&!this._isInArrayFormulaRange(m,x,v)||!d.isNullCell(Ye))return!0}return!1}_isInArrayFormulaRange(r,e,t){if(r==null)return!1;const{startRow:s,startColumn:i,endRow:a,endColumn:u}=r;return e>=s&&e<=a&&t>=i&&t<=u}_checkIfArrayFormulaExceeded(r,e,t){return t.endRow>=r||t.endColumn>=e}_isInDirtyRange(r,e,t,s){const i=this._currentConfigService.getDirtyRanges();return i.length===0?!0:Er(i,r,e,t,s)}};ur=Zi([Ji(0,xe)],ur);const se=B.createIdentifier("univer.formula.runtime.service");var Ni=Object.defineProperty,ea=Object.getOwnPropertyDescriptor,ta=(n,r,e,t)=>{for(var s=t>1?void 0:t?ea(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Ni(r,e,s),s},or=(n,r)=>(e,t)=>r(e,t,n);let ve=class extends d.Disposable{constructor(n,r,e){super(),this._definedNamesService=n,this._runtimeService=r,this._lexerTreeBuilder=e}treeBuilder(n,r=!0){return this._lexerTreeBuilder.treeBuilder(n,r,this._injectDefinedName.bind(this))}_injectDefinedName(n){var i;const r=this._runtimeService.currentUnitId;if(!this._definedNamesService.hasDefinedName(r))return{sequenceString:"",hasDefinedName:!1};const e=this._lexerTreeBuilder.getSequenceNode(n);let t="",s=!1;for(let a=0,u=e.length;a<u;a++){const o=e[a];if(typeof o=="string"){t+=o;continue}const{nodeType:l,token:f}=o;if(l===te.REFERENCE||l===te.FUNCTION){const m=(i=this._definedNamesService.getDefinedNameMap(r))==null?void 0:i.get(f);m?(t+=m,s=!0):t+=f}else t+=f}return{sequenceString:t,hasDefinedName:s}}};ve=ta([or(0,Et),or(1,se),or(2,B.Inject(it))],ve);var M=(n=>(n.REFERENCE="ReferenceNode",n.VALUE="ValueNode",n.OPERATOR="OperatorNode",n.FUNCTION="FunctionNode",n.LAMBDA="LambdaNode",n.LAMBDA_PARAMETER="LambdaNodeParameter",n.ERROR="ErrorNode",n.BASE="Base",n.ROOT="Root",n.UNION="UnionNode",n.PREFIX="PrefixNode",n.SUFFIX="SuffixNode",n.NULL="NullNode",n))(M||{});const le=new Map([["ReferenceNode",7],["ValueNode",9],["OperatorNode",8],["FunctionNode",6],["LambdaNode",1],["LambdaNodeParameter",2],["Root",10],["UnionNode",3],["PrefixNode",4],["SuffixNode",5]]);class ee extends d.Disposable{constructor(e){super();p(this,"_children",[]);p(this,"_parent");p(this,"_valueObject");p(this,"_calculateState",!1);p(this,"_async",!1);p(this,"_address",!1);p(this,"_refOffsetX",0);p(this,"_refOffsetY",0);this._token=e}dispose(){var e;this._children.forEach(t=>{t.dispose()}),(e=this._valueObject)==null||e.dispose(),this._parent=null}get nodeType(){return M.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(be.SUCCESS)}serialize(){const e=this.getToken(),t=this.getChildren(),s=[],i=t.length;for(let u=0;u<i;u++){const o=t[u];s.push(o.serialize())}const a={token:e,nodeType:this.nodeType};return i>0&&(a.children=s),a}}class W extends ee{constructor(e){super(e);p(this,"_errorValueObject");this._errorValueObject=new h(e)}get nodeType(){return M.ERROR}static create(e){return new W(e)}getValue(){return this._errorValueObject}}const ce=100;class fe extends d.Disposable{get zIndex(){return 0}create(r,e,t){let s;return r instanceof U?s=r.getToken():s=r,new ee(s)}checkAndCreateNodeType(r){}}class lr extends ee{get nodeType(){return M.ROOT}execute(){const e=this.getChildren()[0];this.setValue(e.getValue())}}class vn extends fe{get zIndex(){return le.get(M.ROOT)||ce}checkAndCreateNodeType(r){if(!(r instanceof U))return;if(r.getToken()===Re)return new lr(Re)}}class Bn extends d.Disposable{constructor(){super(...arguments);p(this,"_functionExecutors",new Map);p(this,"_functionDescriptions",new Map)}dispose(){this._functionExecutors.clear(),this._functionDescriptions.clear()}registerExecutors(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionExecutors.set(s.name,s)}}getExecutors(){return this._functionExecutors}getExecutor(e){return this._functionExecutors.get(e)}hasExecutor(e){return this._functionExecutors.has(e)}unregisterExecutors(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionExecutors.delete(s)}}registerDescriptions(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionDescriptions.set(s.functionName,s)}}getDescriptions(){return this._functionDescriptions}getDescription(e){return this._functionDescriptions.get(e)}hasDescription(e){return this._functionDescriptions.has(e)}unregisterDescriptions(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionDescriptions.delete(s)}}}const ge=B.createIdentifier("univer.formula.function.service");var ra=Object.defineProperty,na=Object.getOwnPropertyDescriptor,sa=(n,r,e,t)=>{for(var s=t>1?void 0:t?na(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&ra(r,e,s),s},Un=(n,r)=>(e,t)=>r(e,t,n);class wt extends ee{constructor(r,e,t){super(e),this._accessor=r,this._operatorString=e,this._functionExecutor=t}get nodeType(){return M.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===Y.MINUS?t=this._functionExecutor.calculate(new _(0),e):this._operatorString===Y.AT?t=this._handlerAT(e):t=new h(c.VALUE),this.setValue(t)}_handlerAT(r){if(!r.isReferenceObject())return new h(c.VALUE);const e=r;if(e.isCell())return new h(c.VALUE);const t=this._accessor.get(se),s=t.currentRow||0,i=t.currentColumn||0;return e.isRow()?e.getCellByColumn(i):e.isColumn()?e.getCellByRow(s):e.isRange()||e.isTable()?e.getCellByPosition():new h(c.VALUE)}}let _t=class extends fe{constructor(n,r){super(),this._functionService=n,this._injector=r}get zIndex(){return le.get(M.PREFIX)||ce}checkAndCreateNodeType(n){if(!(n instanceof U))return;const r=n.getToken(),e=r.trim();if(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;let t="";if(e===Y.MINUS)t=Z.MINUS;else return e===Y.AT?new wt(this._injector,e):void 0;const s=this._functionService.getExecutor(t);return s?new wt(this._injector,e,s):(console.error(`No function ${r}`),W.create(c.NAME))}};_t=sa([Un(0,ge),Un(1,B.Inject(B.Injector))],_t);var ia=Object.defineProperty,aa=Object.getOwnPropertyDescriptor,ua=(n,r,e,t)=>{for(var s=t>1?void 0:t?aa(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&ia(r,e,s),s},Ct=(n,r)=>(e,t)=>r(e,t,n);class oa extends ee{constructor(r,e,t,s){super(r),this._functionExecutor=e,this._currentConfigService=t,this._runtimeService=s,this._functionExecutor.isAsync()&&this.setAsync(),this._functionExecutor.isAddress()&&this.setAddress()}get nodeType(){return M.FUNCTION}async executeAsync(){const r=[],e=this.getChildren(),t=e.length;this._compatibility();for(let a=0;a<t;a++){const u=e[a].getValue();u!=null&&(u.isReferenceObject()?r.push(u.toArrayValueObject()):r.push(u))}const s=this._calculate(r);let i;return s.isAsyncObject()||s.isAsyncArrayObject()?i=await s.getValue():i=s,this._setRefData(i),this.setValue(i),Promise.resolve(be.SUCCESS)}execute(){const r=[],e=this.getChildren(),t=e.length;this._compatibility();for(let i=0;i<t;i++){const a=e[i].getValue();a!=null&&(a.isReferenceObject()&&!this._functionExecutor.needsReferenceObject?r.push(a.toArrayValueObject()):r.push(a))}const s=this._calculate(r);this._setRefData(s),this.setValue(s)}_compatibility(){this._lookupCompatibility()}_lookupCompatibility(){const r=this.getChildren(),e=r.length;if(!this._functionExecutor.needsExpandParams||e!==3)return;const t=r[1].getValue(),s=r[2].getValue();if(!(t!=null&&t.isReferenceObject())&&!(s!=null&&s.isReferenceObject()))return;const i=t.getRangeData(),a=s.getRangeData(),{startRow:u,startColumn:o,endRow:l,endColumn:f}=i,m=l-u+1,g=f-o+1,{startRow:R,startColumn:w,endRow:E,endColumn:C}=a,y=E-R+1,S=C-w+1;m!==y&&(a.endRow+=m-y),g!==S&&(a.endColumn+=g-S)}_calculate(r){var t;let e;if(this._setRefInfo(),this._functionExecutor.isCustom()){const s=this._functionExecutor.calculateCustom(...r.map(i=>i.isArray()?i.toValue():i.getValue()));if(typeof s!="object"||s==null)e=_e.create(s);else{const i=As(s);e=new z({calculateValueList:i,rowCount:i.length,columnCount:((t=i[0])==null?void 0:t.length)||0,unitId:"",sheetId:"",row:-1,column:-1})}}else e=this._functionExecutor.calculate(...r);return e}_setRefInfo(){const{currentUnitId:r,currentSubUnitId:e,currentRow:t,currentColumn:s}=this._runtimeService;this._functionExecutor.setRefInfo(r,e,t,s)}_setRefData(r){if(!r.isReferenceObject())return;const e=r;e.setForcedSheetId(this._currentConfigService.getSheetNameMap()),e.setUnitData(this._currentConfigService.getUnitData()),e.setArrayFormulaCellData(this._currentConfigService.getArrayFormulaCellData()),e.setRuntimeData(this._runtimeService.getUnitData()),e.setRuntimeArrayFormulaCellData(this._runtimeService.getRuntimeArrayFormulaCellData()),e.setRuntimeFeatureCellData(this._runtimeService.getRuntimeFeatureCellData())}}let pt=class extends fe{constructor(n,r,e,t){super(),this._functionService=n,this._currentConfigService=r,this._runtimeService=e,this._injector=t}get zIndex(){return le.get(M.FUNCTION)||ce}create(n){const r=this._functionService.getExecutor(n);return r?new oa(n,r,this._currentConfigService,this._runtimeService):(console.error(`No function ${n}`),W.create(c.NAME))}checkAndCreateNodeType(n){if(typeof n=="string")return;let e=n.getToken().trim().toUpperCase(),t,s;const i=e.slice(0,2);let a=0;if(new RegExp(Y.MINUS,"g").test(i)){const u=this._functionService.getExecutor(Z.MINUS);t=new wt(this._injector,Y.MINUS,u),a++}if(new RegExp(Y.AT,"g").test(i)&&(s=new wt(this._injector,Y.AT),t&&s.setParent(t),a++),a>0&&(e=e.slice(a)),this._functionService.hasExecutor(e)){const u=this.create(e);return s?u.setParent(s):t&&u.setParent(t),u}}};pt=ua([Ct(0,ge),Ct(1,xe),Ct(2,se),Ct(3,B.Inject(B.Injector))],pt);var la=Object.defineProperty,ca=Object.getOwnPropertyDescriptor,fa=(n,r,e,t)=>{for(var s=t>1?void 0:t?ca(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&la(r,e,s),s},ha=(n,r)=>(e,t)=>r(e,t,n);let Qe=class extends d.Disposable{constructor(n){super(),this._runtimeService=n}dispose(){}async executeAsync(n){if(!n)return new h(c.VALUE);await this._executeAsync(n);const r=n.getValue();if(r==null)throw new Error("node value is null");return Promise.resolve(r)}execute(n){if(!n)return new h(c.VALUE);this._execute(n);const r=n.getValue();if(r==null)throw new Error("node value is null");return r}executePreCalculateNode(n){return n.execute(),n.getValue()}checkAsyncNode(n){const r=[];this._checkAsyncNode(n,r);for(let e=0,t=r.length;e<t;e++)if(r[e]===!0)return!0;return!1}_checkAsyncNode(n,r){const e=n.getChildren(),t=e.length;for(let s=0;s<t;s++){const i=e[s];r.push(i.isAsync()),this._checkAsyncNode(i,r)}}async _executeAsync(n){if(this._runtimeService.isStopExecution())return Promise.resolve(be.ERROR);const r=n.getChildren(),e=r.length;for(let t=0;t<e;t++){const s=r[t];if(s.getToken().toUpperCase()===We&&s.isEmptyParamFunction()){s.execute();continue}await this._executeAsync(s)}return n.nodeType===M.FUNCTION&&n.isAsync()?await n.executeAsync():n.execute(),Promise.resolve(be.SUCCESS)}_execute(n){if(this._runtimeService.isStopExecution())return be.ERROR;const r=n.getChildren(),e=r.length;for(let t=0;t<e;t++){const s=r[t];if(s.getToken().toUpperCase()===We&&s.isEmptyParamFunction()){s.execute();continue}this._execute(s)}return n.execute(),be.SUCCESS}};Qe=fa([ha(0,se)],Qe);function Mn(n){return n instanceof U?n.getToken()===Oe:!1}function ma(n){return n instanceof U?n.getToken()===Lr:!1}function On(n){if(!n)return;if(n.getToken()!==je)return n;const r=n,e=r.getCurrentLambdaPrivacyVar(),t=r.getLambdaParameter();if(!e)return;const s=e.get(t);return s==null&&n.getValue()?n:On(s)}class ga extends we{constructor(e,t,s){super(0);p(this,"_lambdaPrivacyValueMap",new Map);this._lambdaNode=e,this._interpreter=t,this._lambdaPrivacyVarKeys=s,this._lambdaPrivacyValueMap.clear()}isLambda(){return!0}execute(...e){const t=this._lambdaPrivacyVarKeys.length;if(e.length!==t)return new h(c.VALUE);this._setLambdaPrivacyValueMap(e),this._setLambdaNodeValue(this._lambdaNode),this._lambdaNode.setNotEmpty(!1);let s;if(this._interpreter.checkAsyncNode(this._lambdaNode))s=new vs(this._interpreter.executeAsync(this._lambdaNode));else{const i=this._interpreter.execute(this._lambdaNode);i.isReferenceObject()?s=i.toArrayValueObject():s=i}return this._lambdaNode.setNotEmpty(!0),s}_setLambdaNodeValue(e){const t=e.getChildren(),s=t.length;for(let i=0;i<s;i++){const a=t[i];if(a.getToken()===je){const o=a.getLambdaParameter(),l=this._lambdaPrivacyValueMap.get(o);if(l)a.setValue(l);else{const f=a.getCurrentLambdaPrivacyVar(),m=On(f.get(o));m!=null&&a.setValue(m.getValue())}continue}this._setLambdaNodeValue(a)}}_setLambdaPrivacyValueMap(e){for(let t=0;t<e.length;t++){const s=e[t],i=this._lambdaPrivacyVarKeys[t];this._lambdaPrivacyValueMap.set(i,s)}}}var da=Object.defineProperty,Ra=Object.getOwnPropertyDescriptor,Ea=(n,r,e,t)=>{for(var s=t>1?void 0:t?Ra(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&da(r,e,s),s},Fn=(n,r)=>(e,t)=>r(e,t,n);class wa extends ee{constructor(e,t,s,i){super(e);p(this,"_isNotEmpty",!0);this._lambdaId=t,this._interpreter=s,this._lambdaPrivacyVarKeys=i}get nodeType(){return M.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 ga(this,this._interpreter,this._lambdaPrivacyVarKeys));else{const e=this.getChildren(),t=e.length;this.setValue(e[t-1].getValue())}}}let Dt=class extends fe{constructor(n,r){super(),this._runtimeService=n,this._interpreter=r}get zIndex(){return le.get(M.LAMBDA)||ce}create(n){const r=n.getChildren(),e=r[0];let t=r.slice(1,-1);const s=r[r.length-1];if(!(e instanceof U&&s instanceof U))return W.create(c.NAME);if(e.getToken()===Oe){const u=e.getChildren();if(t.length!==u.length)return W.create(c.VALUE)}else t=r.slice(0,-1);const i=d.Tools.generateRandomId(8),a=new Map;for(let u=0;u<t.length;u++){const o=t[u];if(o instanceof U){const l=o.getChildren()[0];o.setToken(Lr),a.set(l.trim(),void 0)}else return W.create(c.VALUE)}return this._runtimeService.registerFunctionDefinitionPrivacyVar(i,a),this._updateLambdaStatement(s,i,a),new wa(n.getToken(),i,this._interpreter,[...a.keys()])}checkAndCreateNodeType(n){if(!(!(n instanceof U)||n.getToken().trim().toUpperCase()!==We))return this.create(n)}_updateLambdaStatement(n,r,e){this._updateTree(n,r,e)}_updateTree(n,r,e){const t=n.getChildren(),s=t.length,i=t[0];for(let a=0;a<s;a++){const u=t[a];if(!(Mn(i)&&a!==0))if(u instanceof U)this._updateTree(u,r,e);else{const o=u.trim();if(e.has(o)){const l=new U;l.setToken(je),l.setLambdaId(r),l.setLambdaPrivacyVar(e),l.setLambdaParameter(o),t[a]=l}}}}};Dt=Ea([Fn(0,se),Fn(1,B.Inject(Qe))],Dt);function $n(n){if(!n)return;if(n.getToken()!==je)return n;const r=n,e=r.getCurrentLambdaPrivacyVar(),t=r.getLambdaParameter();if(e)return $n(e.get(t))}class _a extends ee{constructor(r,e,t){super(r),this._lambdaParameter=e,this._currentLambdaPrivacyVar=t}getLambdaParameter(){return this._lambdaParameter}getCurrentLambdaPrivacyVar(){return this._currentLambdaPrivacyVar}get nodeType(){return M.LAMBDA_PARAMETER}execute(){const r=$n(this._currentLambdaPrivacyVar.get(this._lambdaParameter));if(r)this.setValue(r.getValue());else{const e=this.getValue();(e==null||e.isError())&&this.setValue(new h(c.SPILL))}}}class kn extends fe{get zIndex(){return le.get(M.LAMBDA_PARAMETER)||ce}create(r){const e=r.getFunctionDefinitionPrivacyVar(),t=r.getLambdaParameter();return e?new _a(r.getToken(),t,e):new W(c.SPILL)}checkAndCreateNodeType(r){if(!(!(r instanceof U)||r.getToken().trim()!==je))return this.create(r)}}class Ca extends ee{constructor(r){super(r),this._operatorString=r}get nodeType(){return M.NULL}execute(){this.setValue(new ue(0))}}var pa=Object.defineProperty,Da=Object.getOwnPropertyDescriptor,ya=(n,r,e,t)=>{for(var s=t>1?void 0:t?Da(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&pa(r,e,s),s},ba=(n,r)=>(e,t)=>r(e,t,n);class Sa extends ee{constructor(r,e){super(r),this._operatorString=r,this._functionExecutor=e}get nodeType(){return M.OPERATOR}execute(){const r=this.getChildren();this._functionExecutor.name===Z.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 yt=class extends fe{constructor(n){super(),this._functionService=n}get zIndex(){return le.get(M.OPERATOR)||ce}create(n){let r="";const e=n;e===J.PLUS?r=Z.PLUS:e===J.MINUS?r=Z.MINUS:e===J.MULTIPLY?r=Z.MULTIPLY:e===J.DIVIDED?r=Z.DIVIDED:e===J.CONCATENATE?r=Rt.CONCATENATE:e===J.POWER?r=N.POWER:zn.has(e)&&(r=Z.COMPARE);const t=this._functionService.getExecutor(r);return t?new Sa(e,t):(console.error(`No function ${n}`),W.create(c.NAME))}checkAndCreateNodeType(n){if(n instanceof U)return;const r=n.trim();if(!(r.charAt(0)==='"'&&r.charAt(r.length-1)==='"')&&He.has(r))return this.create(r)}};yt=ya([ba(0,ge)],yt);class La extends d.Disposable{constructor(){super(...arguments);p(this,"_tableMap",new Map);p(this,"_tableOptionMap",new Map)}dispose(){this._tableMap.clear(),this._tableOptionMap.clear()}remove(e,t){var s;(s=this._tableMap.get(e))==null||s.delete(t)}getTableMap(e){return this._tableMap.get(e)}getTableOptionMap(){return this._tableOptionMap}registerTable(e,t,s){var i;this._tableMap.get(e)==null&&this._tableMap.set(e,new Map),(i=this._tableMap.get(e))==null||i.set(t,s)}registerTableOptionMap(e,t){this._tableOptionMap.set(e,t)}}const cr=B.createIdentifier("univer.formula.super-table.service");class Aa extends ke{constructor(r,e,t,s){super(r),this._tableData=e,this._columnDataString=t;const i=this._tableData.sheetId,a=this._tableData.range,u=this._tableData.titleMap;this.setForcedSheetIdDirect(i);const o=this._stringToColumnData(this._columnDataString,u,s),l=o.startColumn,f=o.endColumn,m=o.type;let g=-1,R=-1;const w=a.startRow,E=a.startColumn;m===Se.ALL?(g=w,R=E):m===Se.DATA?(g=w+1,R=E):m===Se.HEADERS?(g=w,R=w):m===Se.TOTALS&&(g=E,R=E),this.setRangeData({startColumn:l,endColumn:f,startRow:g,endRow:R})}isTable(){return!0}_stringToColumnData(r,e,t){r=r.substring(1,-1);const s=r.indexOf(O.COMMA);let i=-1,a=-1,u=Se.ALL;if(s===-1){const o=this._columnHandler(r,e);i=o.startColumn,a=o.endColumn}else{const o=r.substring(0,s).substring(1,-1),l=r.substring(s+1),f=this._columnHandler(l,e,!0);i=f.startColumn,a=f.endColumn,u=t.get(o),u||(u=Se.ALL)}return{startColumn:i,endColumn:a,type:u}}_columnHandler(r,e,t=!1){var u,o,l;let s=-1,i=-1;const a=r.indexOf(O.COLON);if(new RegExp(br,"g").test(r)){const f=r.substring(0,a).substring(1,-1),m=r.substring(a+1).substring(1,-1);s=(u=e.get(f))!=null?u:-1,i=(o=e.get(m))!=null?o:-1}else t&&(r=r.substring(1,-1)),s=(l=e.get(r))!=null?l:-1,i=s;return{startColumn:s,endColumn:i}}}var Pa=Object.defineProperty,Va=Object.getOwnPropertyDescriptor,xa=(n,r,e,t)=>{for(var s=t>1?void 0:t?Va(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Pa(r,e,s),s},qe=(n,r)=>(e,t)=>r(e,t,n);class bt extends ee{constructor(r,e,t,s=!1){super(e),this._accessor=r,this._operatorString=e,this._referenceObject=t,this._isPrepareMerge=s}get nodeType(){return M.REFERENCE}execute(){const r=this._accessor.get(xe),e=this._accessor.get(se);this._referenceObject.setDefaultUnitId(e.currentUnitId),this._referenceObject.setDefaultSheetId(e.currentSubUnitId),this._referenceObject.setForcedSheetId(r.getSheetNameMap()),this._referenceObject.setUnitData(r.getUnitData()),this._referenceObject.setArrayFormulaCellData(r.getArrayFormulaCellData()),this._referenceObject.setRuntimeData(e.getUnitData()),this._referenceObject.setNumfmtItemData(r.getNumfmtItemMap()),this._referenceObject.setRuntimeArrayFormulaCellData(e.getRuntimeArrayFormulaCellData()),this._referenceObject.setRuntimeFeatureCellData(e.getRuntimeFeatureCellData());const{x:t,y:s}=this.getRefOffset();this._referenceObject.setRefOffset(t,s),!this._isPrepareMerge&&this._referenceObject.isExceedRange()?this.setValue(new h(c.NAME)):this.setValue(this._referenceObject)}}let St=class extends fe{constructor(n,r,e,t,s){super(),this._definedNamesService=n,this._superTableService=r,this._formulaRuntimeService=e,this._lexer=t,this._injector=s}get zIndex(){return le.get(M.REFERENCE)||ce}checkAndCreateNodeType(n){var o,l;let r=!1,e,t=!1;if(n instanceof U?(r=!0,e=n.getToken().trim(),((l=(o=n.getParent())==null?void 0:o.getParent())==null?void 0:l.getToken().trim())===O.COLON&&(t=!0)):e=n.trim(),!r&&e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;if(new RegExp(nt).test(e))return new bt(this._injector,e,new En(e),t);if(r&&new RegExp(ts).test(e))return new bt(this._injector,e,new _n(e),t);if(r&&new RegExp(rs).test(e))return new bt(this._injector,e,new wn(e),t);const s=this._formulaRuntimeService.currentUnitId,i=this._superTableService.getTableMap(s),a=new RegExp(br,"g"),u=e.replace(a,"");if(!r&&(i!=null&&i.has(u))){const f=a.exec(e);let m="";f&&(m=f[0]);const g=i.get(u),R=this._superTableService.getTableOptionMap();return new bt(this._injector,e,new Aa(e,g,m,R))}}};St=xa([qe(0,Et),qe(1,cr),qe(2,se),qe(3,B.Inject(ve)),qe(4,B.Inject(B.Injector))],St);var va=Object.defineProperty,Ba=Object.getOwnPropertyDescriptor,Ua=(n,r,e,t)=>{for(var s=t>1?void 0:t?Ba(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&va(r,e,s),s},In=(n,r)=>(e,t)=>r(e,t,n);class Tn extends ee{constructor(r,e,t){super(e),this._accessor=r,this._operatorString=e,this._functionExecutor=t}get nodeType(){return M.SUFFIX}execute(){let e=this.getChildren()[0].getValue(),t;if(e==null)throw new Error("object is null");this._operatorString===he.PERCENTAGE?(e.isReferenceObject()&&(e=e.toArrayValueObject()),t=this._functionExecutor.calculate(e,new _(100)),t.setPattern("0.00%")):this._operatorString===he.POUND?t=this._handlerPound(e):t=new h(c.VALUE),this.setValue(t)}_handlerPound(r){var f,m,g,R;if(!r.isReferenceObject())return new h(c.VALUE);if(!r.isCell())return new h(c.VALUE);const e=this._accessor.get(xe),t=this._accessor.get(ve),s=r,i=s.getRangePosition(),a=s.getUnitId(),u=s.getSheetId(),o=e.getFormulaData(),l=(R=(g=(m=(f=o==null?void 0:o[a])==null?void 0:f[u])==null?void 0:m[i.startRow])==null?void 0:g[i.startColumn])==null?void 0:R.f;return l?(t.treeBuilder(l),new h(c.VALUE)):new h(c.VALUE)}}let Lt=class extends fe{constructor(n,r){super(),this._functionService=n,this._injector=r}get zIndex(){return le.get(M.SUFFIX)||ce}checkAndCreateNodeType(n){if(!(n instanceof U))return;const r=n.getToken().trim();if(r.charAt(0)==='"'&&r.charAt(r.length-1)==='"')return;let e="";if(r===he.PERCENTAGE)e=Z.DIVIDED;else return r===he.POUND?new Tn(this._injector,r):void 0;const t=this._functionService.getExecutor(e);return t?new Tn(this._injector,r,t):(console.error(`No function ${n}`),W.create(c.NAME))}};Lt=Ua([In(0,ge),In(1,B.Inject(B.Injector))],Lt);var Ma=Object.defineProperty,Oa=Object.getOwnPropertyDescriptor,Fa=(n,r,e,t)=>{for(var s=t>1?void 0:t?Oa(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Ma(r,e,s),s},$a=(n,r)=>(e,t)=>r(e,t,n);class ka extends ee{constructor(r){super(r),this._operatorString=r}get nodeType(){return M.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 s;this._operatorString===O.COLON?s=this._unionFunction(e,t):s=new h(c.NAME),this.setValue(s)}_unionFunction(r,e){return r.isError()||e.isError()?new h(c.REF):!r.isReferenceObject()||!e.isReferenceObject()?new h(c.REF):(r=r,e=e,r.isCell()&&e.isCell()||r.isRow()&&e.isRow()||r.isColumn()&&e.isColumn()?r.unionBy(e):new h(c.REF))}}let At=class extends fe{constructor(n){super(),this._functionService=n}get zIndex(){return le.get(M.UNION)||ce}create(n){return new ka(n)}checkAndCreateNodeType(n){if(!(n instanceof U))return;const e=n.getToken().trim();if(!(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')&&e===O.COLON)return this.create(e)}};At=Fa([$a(0,ge)],At);class Ia extends ee{constructor(r){super(r),this._operatorString=r}get nodeType(){return M.VALUE}execute(){this.setValue(_e.create(this._operatorString))}}class Qn extends fe{get zIndex(){return le.get(M.VALUE)||ce}_checkValueNode(r){if(Number.isNaN(Number(r))){const e=r.trim(),t=e.charAt(0),s=e.charAt(e.length-1);if(Ne.has(e))return this.create(e);if(t==='"'&&s==='"')return this.create(e);if(t==="{"&&s==="}")return this.create(e);const i=e.toUpperCase();if(i===ye.TRUE||i===ye.FALSE)return this.create(i)}else return this.create(r)}create(r){return new Ia(r)}checkAndCreateNodeType(r){if(!(r instanceof U))return this._checkValueNode(r)}}var Ta=Object.defineProperty,Qa=Object.getOwnPropertyDescriptor,Ya=(n,r,e,t)=>{for(var s=t>1?void 0:t?Qa(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Ta(r,e,s),s},ie=(n,r)=>(e,t)=>r(e,t,n);let ze=class extends d.Disposable{constructor(r,e,t,s,i,a,u,o,l,f,m){super();p(this,"_astNodeFactoryList",[]);p(this,"_refOffsetX",0);p(this,"_refOffsetY",0);this._runtimeService=r,this._astRootNodeFactory=e,this._functionNodeFactory=t,this._lambdaNodeFactory=s,this._lambdaParameterNodeFactory=i,this._operatorNodeFactory=a,this._prefixNodeFactory=u,this._referenceNodeFactory=o,this._suffixNodeFactory=l,this._unionNodeFactory=f,this._valueNodeFactory=m,this._initializeAstNode()}dispose(){this._astNodeFactoryList.forEach(r=>{r.dispose()}),this._astNodeFactoryList=[]}parse(r,e=0,t=0){const s=new lr(Re);return this._refOffsetX=e,this._refOffsetY=t,this._parse(r,s)}_lambdaParameterHandler(r,e){const t=e.getLambdaId(),s=new lr(Re),i=this._runtimeService.getFunctionDefinitionPrivacyVar(t);if(!i)return!1;const a=[...i.keys()],u=r.getChildren(),o=u.length;for(let m=0;m<o;m++){const g=u[m];if(g instanceof U)this._parse(g,s);else return!1}const l=s.getChildren(),f=l.length;for(let m=0;m<f;m++){const g=l[m];i.set(a[m],g)}return s.setParent(e),e}_changeLetToLambda(r){const e=r.getChildren(),t=e.length;if(t%2!==1||t===0)return;const s=new U;s.setToken(We);const i=new U;i.setToken(Oe);const a=[...e];for(let o=0;o<t;o++){const l=a[o];if(!(l instanceof U))return;o%2===0?l.changeToParent(s):l.changeToParent(i)}s.addChildrenFirst(i),i.setParent(s);const u=r.getParent();return u==null||u.replaceChild(r,s),s}_getTopParent(r){let e=r;for(;e!=null&&e.getParent();)e=e.getParent();return e}_parse(r,e){const t=r.getChildren(),s=t.length,i=[];let a=null;const u=r.getToken().trim().toUpperCase();if(u===ss){const f=this._changeLetToLambda(r);return f!=null?this._parse(f,e):W.create(c.ERROR)}if(u===pe){if(a=e,s===0)return new Ca(Re).setParent(e),a}else{if(u===Oe){let f=this._lambdaParameterHandler(r,e);return f===!1&&(f=W.create(c.ERROR)),f}if(a=this._checkAstNode(r),a==null)return W.create(c.ERROR)}const o=t[0];for(let f=0;f<s;f++){const m=t[f];if(Mn(o)){if(f!==0&&f!==s-1)continue}else if(ma(m)&&f!==s-1)continue;let g=null;if(m instanceof U){if(g=this._parse(m,a),g===a)continue}else g=this._checkAstNode(m);if(g==null)return W.create(c.NAME);if(g=this._getTopParent(g),g==null)return;switch(g.nodeType){case M.ERROR:return g;case M.FUNCTION:i.push(g);break;case M.LAMBDA:i.push(g);break;case M.LAMBDA_PARAMETER:i.push(g);break;case M.OPERATOR:{const R=i.pop(),w=i.pop();if(w)w.setParent(g);else return W.create(c.ERROR);if(R)R.setParent(g);else return W.create(c.ERROR);i.push(g);break}case M.REFERENCE:g.setRefOffset(this._refOffsetX,this._refOffsetY),i.push(g);break;case M.ROOT:i.push(g);break;case M.UNION:i.push(g);break;case M.VALUE:i.push(g);break;case M.PREFIX:i.push(g);break;case M.SUFFIX:i.push(g);break}}const l=i.length;for(let f=0;f<l;f++)i[f].setParent(a);return a}_checkAstNode(r){let e=null;const t=this._astNodeFactoryList.length;for(let s=0;s<t&&(e=this._astNodeFactoryList[s].checkAndCreateNodeType(r),e==null);s++);return e}_initializeAstNode(){this._astNodeFactoryList=[this._astRootNodeFactory,this._functionNodeFactory,this._lambdaNodeFactory,this._lambdaParameterNodeFactory,this._operatorNodeFactory,this._prefixNodeFactory,this._referenceNodeFactory,this._suffixNodeFactory,this._unionNodeFactory,this._valueNodeFactory].sort(d.sortRules)}};ze=Ya([ie(0,se),ie(1,B.Inject(vn)),ie(2,B.Inject(pt)),ie(3,B.Inject(Dt)),ie(4,B.Inject(kn)),ie(5,B.Inject(yt)),ie(6,B.Inject(_t)),ie(7,B.Inject(St)),ie(8,B.Inject(Lt)),ie(9,B.Inject(At)),ie(10,B.Inject(Qn))],ze);class Yn extends d.Disposable{constructor(){super(...arguments);p(this,"_referenceExecutorMap",new Map)}dispose(){this._referenceExecutorMap.clear()}remove(e){this._referenceExecutorMap.delete(e)}get(e){return this._referenceExecutorMap.get(e)}has(e){return this._referenceExecutorMap.has(e)}register(e,t){this._referenceExecutorMap.set(e,t)}getReferenceExecutorMap(){return this._referenceExecutorMap}}const Pt=B.createIdentifier("univer.formula.feature-calculation-manager.service");class Hn extends d.Disposable{constructor(){super(...arguments);p(this,"_otherFormulaData",{})}dispose(){this._otherFormulaData={}}remove(e){var a,u,o;const{unitId:t,subUnitId:s,formulaId:i}=e;(o=(u=(a=this._otherFormulaData)==null?void 0:a[t])==null?void 0:u[s])==null||delete o[i]}get(e){var a,u;const{unitId:t,subUnitId:s,formulaId:i}=e;return(u=(a=this._otherFormulaData[t])==null?void 0:a[s])==null?void 0:u[i]}has(e){var a,u;const{unitId:t,subUnitId:s,formulaId:i}=e;return((u=(a=this._otherFormulaData[t])==null?void 0:a[s])==null?void 0:u[i])!=null}register(e){const{unitId:t,subUnitId:s,formulaId:i,item:a}=e;this._otherFormulaData[t]&&(this._otherFormulaData[t]={}),this._otherFormulaData[t][s]&&(this._otherFormulaData[t][s]={}),this._otherFormulaData[t][s][i]=a}getOtherFormulaData(){return this._otherFormulaData}}const fr=B.createIdentifier("univer.formula.other-formula-manager.service");class hr extends d.Disposable{constructor(){super(...arguments);p(this,"node");p(this,"children",[]);p(this,"parents",[]);p(this,"formula","");p(this,"row",-1);p(this,"column",-1);p(this,"rowCount",Number.NEGATIVE_INFINITY);p(this,"columnCount",Number.NEGATIVE_INFINITY);p(this,"subUnitId","");p(this,"unitId","");p(this,"rangeList",[]);p(this,"formulaId");p(this,"featureId");p(this,"getDirtyData");p(this,"_state",0)}dispose(){var e;this.children.forEach(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,s=e.startColumn,i=e.endRow,a=e.endColumn;return!(this.row<t||this.row>i||this.column<s||this.column>a)}dependencyRange(e,t,s){var i,a;if(this.rangeList.length===0)return!1;for(let u=0,o=this.rangeList.length;u<o;u++){const l=this.rangeList[u],{unitId:f,sheetId:m,range:g}=l;if(((i=t[f])==null?void 0:i[m])!=null)return!0;if(!e.has(f))continue;const R=e.get(f);if(!R.has(m))continue;const w=R.get(m),E=(a=s==null?void 0:s[f])==null?void 0:a[m];let{startRow:C,endRow:y,startColumn:S,endColumn:L}=g;isNaN(C)&&(C=0),isNaN(S)&&(S=0),isNaN(y)&&(y=Number.POSITIVE_INFINITY),isNaN(L)&&(L=Number.POSITIVE_INFINITY);for(const V of w){const{startRow:I,startColumn:Q,endRow:T,endColumn:x}=V;if(!(C>T||y<I||S>x||L<Q)){let v=!0;if(E==null||E.forValue(($,k)=>{if($>=C&&$<=y&&k>=S&&k<=L)return v=!1,!1}),v)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,s=this.rangeList.length;t<s;t++){const i=this.rangeList[t],a=i.unitId,u=i.sheetId,o=i.range;if(e.unitId===a&&e.subUnitId===u&&e.inRangeData(o))return!0}return!1}_pushParent(e){this.parents.push(e)}}var Ha=Object.defineProperty,ja=Object.getOwnPropertyDescriptor,Wa=(n,r,e,t)=>{for(var s=t>1?void 0:t?ja(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Ha(r,e,s),s},Be=(n,r)=>(e,t)=>r(e,t,n);const Xa=1e5,mr=new rt(Xa);let Ze=class extends d.Disposable{constructor(r,e,t,s,i,a,u){super();p(this,"_updateRangeFlattenCache",new Map);p(this,"_dirtyUnitSheetNameMap",{});this._currentConfigService=r,this._runtimeService=e,this._otherFormulaManagerService=t,this._featureCalculationManagerService=s,this._interpreter=i,this._astTreeBuilder=a,this._lexer=u}dispose(){this._updateRangeFlattenCache.clear(),mr.clear(),this._dirtyUnitSheetNameMap={}}async generate(){this._updateRangeFlatten();const r=this._currentConfigService.getFormulaData(),e=this._otherFormulaManagerService.getOtherFormulaData(),t=this._currentConfigService.getUnitData(),s=await this._generateTreeList(r,e,t),i=this._getUpdateTreeListAndMakeDependency(s);this._checkIsCycleDependency(i)&&this._runtimeService.enableCycleDependency();const u=this._calculateRunList(i);return Promise.resolve(u)}_isCyclicUtil(r,e,t){if(!e.has(r)){e.add(r),t.add(r);for(let s=0;s<r.children.length;s++)if(!e.has(r.children[s])&&this._isCyclicUtil(r.children[s],e,t)||t.has(r.children[s]))return!0}return t.delete(r),!1}_checkIsCycleDependency(r){const e=new Set,t=new Set;for(let s=0,i=r.length;s<i;s++){const a=r[s];if(this._isCyclicUtil(a,e,t)===!0)return!0}return!1}async _generateTreeList(r,e,t){const s=Object.keys(r),i=Object.keys(e),a=[];for(const u of s){const o=r[u];if(o==null)continue;const l=Object.keys(o);for(const f of l)new d.ObjectMatrix(o[f]).forValue((g,R,w)=>{if(w==null)return!0;const{f:E,x:C,y}=w,S=this._generateAstNode(E,C,y),L=new hr,V=t[u][f];L.node=S,L.formula=E,L.unitId=u,L.subUnitId=f,L.row=g,L.column=R,L.rowCount=V.rowCount,L.columnCount=V.columnCount,a.push(L)})}for(const u of i){const o=e[u];if(o==null)continue;const l=Object.keys(o);for(const f of l){const m=o[f];if(m==null)continue;const g=Object.keys(m);for(const R of g){const w=m[R],{f:E}=w,C=this._generateAstNode(E),y=new hr;y.node=C,y.formula=E,y.unitId=u,y.subUnitId=f,y.formulaId=R,a.push(y)}}}this._featureCalculationManagerService.getReferenceExecutorMap().forEach((u,o)=>{const{unitId:l,subUnitId:f,dependencyRanges:m,getDirtyData:g}=u,R=new hr;R.unitId=l,R.subUnitId=f,R.getDirtyData=g,R.featureId=o,R.rangeList=m,a.push(R)});for(let u=0,o=a.length;u<o;u++){const l=a[u];if(this._runtimeService.setCurrent(l.row,l.column,l.rowCount,l.columnCount,l.subUnitId,l.unitId),l.node==null)continue;const f=await this._getRangeListByNode(l.node);for(let m=0,g=f.length;m<g;m++)l.pushRangeList(f[m])}return a}_updateRangeFlatten(){const r=this._currentConfigService.isForceCalculate(),e=this._currentConfigService.getDirtyRanges();if(!r){this._updateRangeFlattenCache.clear();for(let t=0;t<e.length;t++){const s=e[t],i=s.range,a=s.sheetId,u=s.unitId;this._addFlattenCache(u,a,i)}this._dirtyUnitSheetNameMap=this._currentConfigService.getDirtyNameMap()}}_generateAstNode(r,e=0,t=0){let s=mr.get(`${r}##${e}${t}`);if(s)return s;const i=this._lexer.treeBuilder(r);if(i in c)return W.create(i);if(s=this._astTreeBuilder.parse(i,e,t),s==null)throw new Error("astNode is null");return mr.set(`${r}##${e}${t}`,s),s}_addFlattenCache(r,e,t){let s=this._updateRangeFlattenCache.get(r);s==null&&(s=new Map,this._updateRangeFlattenCache.set(r,s));let i=s.get(e);i==null&&(i=[],s.set(e,i)),i.push(t)}_isPreCalculateNode(r){return r.nodeType===M.UNION||r.nodeType===M.PREFIX&&r.getToken()===Y.AT||r.nodeType===M.SUFFIX&&r.getToken()===he.POUND}_nodeTraversalRef(r,e){const t=r.getChildren(),s=t.length;for(let i=0;i<s;i++){const a=t[i];if(this._isPreCalculateNode(a)){e.push(a);continue}else a.nodeType===M.REFERENCE&&e.push(a);this._nodeTraversalRef(a,e)}}_nodeTraversalReferenceFunction(r,e){const t=r.getChildren(),s=t.length;for(let i=0;i<s;i++){const a=t[i];if(a.nodeType===M.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 s=[];for(let i=0,a=e.length;i<a;i++){const u=e[i],l=(await this._executeNode(u)).toUnitRange();s.push(l)}for(let i=0,a=t.length;i<a;i++){const u=t[i],l=(await this._executeNode(u)).toUnitRange();s.push(l)}return s}_getUpdateTreeListAndMakeDependency(r){const e=[],t=new Set,s=this._currentConfigService.isForceCalculate();for(let i=0,a=r.length;i<a;i++){const u=r[i];for(let o=0,l=r.length;o<l;o++){const f=r[o];u!==f&&u.dependency(f)&&u.pushChildren(f)}(s||u.dependencyRange(this._updateRangeFlattenCache,this._dirtyUnitSheetNameMap,this._currentConfigService.getExcludedRange())||this._includeTree(u))&&!t.has(u)&&(e.push(u),t.add(u))}return e}_includeTree(r){var l,f,m,g,R;const e=r.unitId,t=r.subUnitId,s=r.featureId;if(s!=null){const w=this._currentConfigService.getDirtyUnitFeatureMap();if(((f=(l=w==null?void 0:w[e])==null?void 0:l[t])==null?void 0:f[s])!=null)return!0}const i=(g=(m=this._currentConfigService.getExcludedRange())==null?void 0:m[e])==null?void 0:g[t];let a=!1;if(i==null||i.forValue((w,E)=>{if(r.row===w&&r.column===E)return a=!0,!1}),a)return!1;if(((R=this._dirtyUnitSheetNameMap[e])==null?void 0:R[t])!=null)return!0;if(!this._updateRangeFlattenCache.has(e))return!1;const u=this._updateRangeFlattenCache.get(e);if(!u.has(t))return!1;const o=u.get(t);for(const w of o)if(r.inRangeData(w))return!0;return!1}_calculateRunList(r){let e=r;const t=[];for(;e.length>0;){const s=e.pop();if(s===void 0||s.isSkip())continue;if(s.isAdded()){t.push(s);continue}const i=[];for(let a=0,u=s.parents.length;a<u;a++){const o=s.parents[a];i.push(o)}i.length===0?(t.push(s),s.setSkip()):(s.setAdded(),e.push(s),e=e.concat(i))}return t.reverse()}};Ze=Wa([d.OnLifecycle(d.LifecycleStages.Rendered,Ze),Be(0,xe),Be(1,se),Be(2,fr),Be(3,Pt),Be(4,B.Inject(Qe)),Be(5,B.Inject(ze)),Be(6,B.Inject(ve))],Ze);var Ga=Object.defineProperty,Ka=Object.getOwnPropertyDescriptor,qa=(n,r,e,t)=>{for(var s=t>1?void 0:t?Ka(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Ga(r,e,s),s},Ue=(n,r)=>(e,t)=>r(e,t,n);const za=1;D.CalculateFormulaService=class extends d.Disposable{constructor(e,t,s,i,a,u,o){super();p(this,"_executionStartListener$",new Ft.Subject);p(this,"executionStartListener$",this._executionStartListener$.asObservable());p(this,"_executionCompleteListener$",new Ft.Subject);p(this,"executionCompleteListener$",this._executionCompleteListener$.asObservable());p(this,"_executionInProgressListener$",new Ft.Subject);p(this,"executionInProgressListener$",this._executionInProgressListener$.asObservable());this._configService=e,this._lexer=t,this._currentConfigService=s,this._runtimeService=i,this._formulaDependencyGenerator=a,this._interpreter=u,this._astTreeBuilder=o}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")||za;for(let s=0;s<t&&(await this._execute(),!!this._runtimeService.isCycleDependency());s++);this._runtimeService.setFormulaExecuteStage(oe.CALCULATION_COMPLETED),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState()),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData()),tr.clear(),Ee.clear()}async _execute(){const e=await this._apply();if(e==null)return;const{arrayFormulaRange:t,runtimeFeatureRange:s}=e,{dirtyRanges:i,excludedCell:a}=this._getArrayFormulaDirtyRangeAndExcludedRange(t,s);return i==null||i.length===0||(this._currentConfigService.loadDirtyRangesAndExcludedCell(i,a),await this._apply(!0)),!0}_getArrayFormulaDirtyRangeAndExcludedRange(e,t){const s=[],i={};return Object.keys(e).forEach(a=>{const u=e[a];if(u==null)return!0;Object.keys(u).forEach(o=>{const l=new d.ObjectMatrix(u[o]);if(l==null)return!0;const f=new d.ObjectMatrix;l.forValue((m,g,R)=>{f.setValue(m,g,!0),s.push({unitId:a,sheetId:o,range:R})}),i[a]==null&&(i[a]={}),i[a][o]=f})}),Object.keys(t).forEach(a=>{const u=t[a];Object.keys(u).forEach(o=>{const l=u[o];if(l==null)return!0;Object.keys(l).forEach(f=>{const m=l[f];if(m==null)return!0;for(const g of m)s.push({unitId:o,sheetId:f,range:g})})})}),{dirtyRanges:s,excludedCell:i}}async _apply(e=!1){e?this._runtimeService.setFormulaExecuteStage(oe.START_DEPENDENCY_ARRAY_FORMULA):this._runtimeService.setFormulaExecuteStage(oe.START_DEPENDENCY),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());const t=await this._formulaDependencyGenerator.generate(),s=this._interpreter;e?(this._runtimeService.setFormulaExecuteStage(oe.START_CALCULATION_ARRAY_FORMULA),this._runtimeService.setTotalArrayFormulasToCalculate(t.length)):(this._runtimeService.setFormulaExecuteStage(oe.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(m=>{d.requestImmediateMacroTask(m)}),this._runtimeService.isStopExecution()){this._runtimeService.setFormulaExecuteStage(oe.IDLE),this._runtimeService.markedAsStopFunctionsExecuted(),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData());return}const u=t[i],o=u.node,l=u.getDirtyData;let f;if(o==null&&l==null)throw new Error("AstNode or executor is null");if(this._runtimeService.setCurrent(u.row,u.column,u.rowCount,u.columnCount,u.subUnitId,u.unitId),l!=null&&u.featureId!=null){const{runtimeCellData:m,dirtyRanges:g}=l(u);this._runtimeService.setRuntimeFeatureCellData(u.featureId,m),this._runtimeService.setRuntimeFeatureRange(u.featureId,g)}else o!=null&&(s.checkAsyncNode(o)?f=await s.executeAsync(o):f=s.execute(o),u.formulaId!=null?this._runtimeService.setRuntimeOtherData(u.formulaId,f):this._runtimeService.setRuntimeData(f));e?(this._runtimeService.setFormulaExecuteStage(oe.CURRENTLY_CALCULATING_ARRAY_FORMULA),this._runtimeService.setCompletedArrayFormulasCount(i+1)):(this._runtimeService.setFormulaExecuteStage(oe.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 s=this._lexer.treeBuilder(e,t);if(Object.values(c).includes(s))return W.create(s);const i=this._astTreeBuilder.parse(s);i==null||i.serialize()}},D.CalculateFormulaService=qa([d.OnLifecycle(d.LifecycleStages.Rendered,D.CalculateFormulaService),Ue(0,d.IConfigService),Ue(1,B.Inject(ve)),Ue(2,xe),Ue(3,se),Ue(4,B.Inject(Ze)),Ue(5,B.Inject(Qe)),Ue(6,B.Inject(ze))],D.CalculateFormulaService);const gr={id:"formula.mutation.set-numfmt-formula-data",type:d.CommandType.MUTATION,handler:(n,r)=>(n.get(D.FormulaDataModel).updateNumfmtItemMap(r.numfmtItemMap),!0)};var Za=Object.defineProperty,Ja=Object.getOwnPropertyDescriptor,Na=(n,r,e,t)=>{for(var s=t>1?void 0:t?Ja(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Za(r,e,s),s},Vt=(n,r)=>(e,t)=>r(e,t,n);let xt=class extends d.Disposable{constructor(n,r,e,t){super(),this._commandService=n,this._calculateFormulaService=r,this._currentUniverService=e,this._formulaDataModel=t,this._initialize()}_initialize(){this._commandExecutedListener(),this._initialExecuteFormulaListener(),this._initialExecuteFormulaProcessListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((n,r)=>{if(n.id===Gt.id)this._calculateFormulaService.stopFormulaExecution();else if(n.id===qt.id){const e=n.params.formulaData;this._formulaDataModel.setFormulaData(e)}else if(n.id===Xt.id){const e=n.params;if(e.forceCalculation===!0)this._calculate(!0);else{const{dirtyRanges:t,dirtyNameMap:s,dirtyUnitFeatureMap:i,numfmtItemMap:a}=e;this._calculate(!1,t,s,i,a)}}else if(n.id===at.id){const e=n.params;if(e==null)return;const{arrayFormulaRange:t,arrayFormulaCellData:s}=e;this._formulaDataModel.setArrayFormulaRange(t),this._formulaDataModel.setArrayFormulaCellData(s)}}))}async _calculate(n=!1,r=[],e={},t={},s={}){if(r.length===0&&Object.keys(e).length===0&&Object.keys(t).length===0&&n===!1)return;const i=this._formulaDataModel.getFormulaData(),a=this._formulaDataModel.getArrayFormulaCellData();this._calculateFormulaService.execute({formulaData:i,arrayFormulaCellData:a,forceCalculate:n,dirtyRanges:r,dirtyNameMap:e,dirtyUnitFeatureMap:t,numfmtItemMap:s})}_initialExecuteFormulaListener(){this._calculateFormulaService.executionCompleteListener$.subscribe(n=>{const r=n.functionsExecutedState;switch(r){case Te.NOT_EXECUTED:break;case Te.STOP_EXECUTION:break;case Te.SUCCESS:this._applyFormula(n);break;case Te.INITIAL:break}this._commandService.executeCommand(lt.id,{functionsExecutedState:r},{onlyLocal:!0})})}_initialExecuteFormulaProcessListener(){this._calculateFormulaService.executionInProgressListener$.subscribe(n=>{this._commandService.executeCommand(lt.id,{stageInfo:n},{onlyLocal:!0})})}async _applyFormula(n){const{unitData:r,unitOtherData:e,arrayFormulaRange:t,arrayFormulaCellData:s,clearArrayFormulaCellData:i,numfmtItemMap:a}=n;if(!r){console.error("No sheetData from Formula Engine!");return}t&&(this._formulaDataModel.clearPreviousArrayFormulaCellData(i),this._formulaDataModel.mergeArrayFormulaCellData(s),this._formulaDataModel.mergeArrayFormulaRange(t),this._commandService.executeCommand(at.id,{arrayFormulaRange:this._formulaDataModel.getArrayFormulaRange(),arrayFormulaCellData:this._formulaDataModel.getArrayFormulaCellData()},{onlyLocal:!0})),d.Tools.isEmptyObject(a)||this._commandService.executeCommand(gr.id,{numfmtItemMap:a},{onlyLocal:!0}),this._commandService.executeCommand(Kt.id,{unitData:r,unitOtherData:e},{onlyLocal:!0})}};xt=Na([d.OnLifecycle(d.LifecycleStages.Ready,xt),Vt(0,d.ICommandService),Vt(1,B.Inject(D.CalculateFormulaService)),Vt(2,d.IUniverInstanceService),Vt(3,B.Inject(D.FormulaDataModel))],xt);var eu=Object.defineProperty,tu=Object.getOwnPropertyDescriptor,ru=(n,r,e,t)=>{for(var s=t>1?void 0:t?tu(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&eu(r,e,s),s},dr=(n,r)=>(e,t)=>r(e,t,n);let Je=class extends d.Disposable{constructor(n=[],r,e,t){super(),this._function=n,this._commandService=r,this._injector=e,this._functionService=t,this._initialize()}_initialize(){this._registerCommands(),this._registerFunctions()}_registerCommands(){[qt,at,Xt,Gt,lt,Kt,gr,ut,ot,jt,Wt,zt,Zt,Fr,$r,Jt,$t,Nt].forEach(n=>this.disposeWithMe(this._commandService.registerCommand(n)))}_registerFunctions(){const n=[...Nr,...sn,...an,...on,...cn,...fn,...mn,...dn,...Rn,...Cn,...yn,...bn,...Ln,...An,...Pn,...Vn].concat(this._function).map(r=>{const e=r[0],t=r[1];return new e(t)});this._functionService.registerExecutors(...n)}};Je=ru([d.OnLifecycle(d.LifecycleStages.Ready,Je),dr(1,d.ICommandService),dr(2,B.Inject(B.Injector)),dr(3,ge)],Je);var nu=Object.defineProperty,su=Object.getOwnPropertyDescriptor,iu=(n,r,e,t)=>{for(var s=t>1?void 0:t?su(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&nu(r,e,s),s},Rr=(n,r)=>(e,t)=>r(e,t,n);let vt=class extends d.Disposable{constructor(n,r,e){super(),this._commandService=n,this._formulaDataModel=r,this._functionService=e,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((n,r)=>{if(n.id===$t.id){const e=n.params;if(e==null)return;const{functions:t}=e,s=t.map(i=>{const a=i[0],u=i[1];return uu(a,u)});this._functionService.registerExecutors(...s)}else if(n.id===Nt.id){const e=n.params;if(e==null)return;const{functions:t}=e;this._functionService.unregisterExecutors(...t)}}))}};vt=iu([d.OnLifecycle(d.LifecycleStages.Ready,vt),Rr(0,d.ICommandService),Rr(1,B.Inject(D.FormulaDataModel)),Rr(2,ge)],vt);class au extends A{isCustom(){return!0}}function uu(n,r){const e=new au(r),t=new Function(`return ${n}`)();return e.calculateCustom=t,e}var ou=Object.defineProperty,lu=Object.getOwnPropertyDescriptor,cu=(n,r,e,t)=>{for(var s=t>1?void 0:t?lu(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&ou(r,e,s),s},jn=(n,r)=>(e,t)=>r(e,t,n);let Bt=class extends d.Disposable{constructor(n,r){super(),this._commandService=n,this._definedNamesService=r,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===ut.id){const r=n.params;if(r==null)return;const{unitId:e,name:t,formulaOrRefString:s}=r;this._definedNamesService.registerDefinedName(e,t,s)}else if(n.id===ot.id){const r=n.params;if(r==null)return;const{unitId:e,name:t}=r;this._definedNamesService.removeDefinedName(e,t)}}))}};Bt=cu([d.OnLifecycle(d.LifecycleStages.Ready,Bt),jn(0,d.ICommandService),jn(1,Et)],Bt);var fu=Object.defineProperty,hu=Object.getOwnPropertyDescriptor,mu=(n,r,e,t)=>{for(var s=t>1?void 0:t?hu(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&fu(r,e,s),s},Wn=(n,r)=>(e,t)=>r(e,t,n);let Ut=class extends d.Disposable{constructor(n,r){super(),this._commandService=n,this._featureCalculationManagerService=r,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===jt.id){const r=n.params;if(r==null)return;const{featureId:e,calculationParam:t}=r;this._featureCalculationManagerService.register(e,t)}else if(n.id===Wt.id){const r=n.params;if(r==null)return;const{featureId:e}=r;this._featureCalculationManagerService.remove(e)}}))}};Ut=mu([d.OnLifecycle(d.LifecycleStages.Ready,Ut),Wn(0,d.ICommandService),Wn(1,Pt)],Ut);var gu=Object.defineProperty,du=Object.getOwnPropertyDescriptor,Ru=(n,r,e,t)=>{for(var s=t>1?void 0:t?du(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&gu(r,e,s),s},Xn=(n,r)=>(e,t)=>r(e,t,n);let Mt=class extends d.Disposable{constructor(n,r){super(),this._commandService=n,this._otherFormulaManagerService=r,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===zt.id){const r=n.params;if(r==null)return;this._otherFormulaManagerService.register(r)}else if(n.id===Zt.id){const r=n.params;if(r==null)return;this._otherFormulaManagerService.remove(r)}}))}};Mt=Ru([d.OnLifecycle(d.LifecycleStages.Ready,Mt),Xn(0,d.ICommandService),Xn(1,fr)],Mt);var Eu=Object.defineProperty,wu=Object.getOwnPropertyDescriptor,_u=(n,r,e,t)=>{for(var s=t>1?void 0:t?wu(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Eu(r,e,s),s},Gn=(n,r)=>(e,t)=>r(e,t,n);let Ot=class extends d.Disposable{constructor(n,r){super(),this._commandService=n,this._superTableService=r,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===ut.id){const r=n.params;if(r==null)return;const{unitId:e,tableName:t,reference:s}=r;this._superTableService.registerTable(e,t,s)}else if(n.id===ot.id){const r=n.params;if(r==null)return;const{unitId:e,tableName:t}=r;this._superTableService.remove(e,t)}else if(n.id===Jt.id){const r=n.params;if(r==null)return;const{tableOption:e,tableOptionType:t}=r;this._superTableService.registerTableOptionMap(e,t)}}))}};Ot=_u([d.OnLifecycle(d.LifecycleStages.Ready,Ot),Gn(0,d.ICommandService),Gn(1,cr)],Ot);var Cu=Object.defineProperty,pu=Object.getOwnPropertyDescriptor,Du=(n,r,e,t)=>{for(var s=t>1?void 0:t?pu(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Cu(r,e,s),s},yu=(n,r)=>(e,t)=>r(e,t,n);const bu="base-formula-engine";D.UniverFormulaEnginePlugin=class extends d.Plugin{constructor(r,e){super(bu),this._config=r,this._injector=e}onStarting(){this._initialize()}_initialize(){var e;const r=[[ge,{useClass:Bn}],[Pt,{useClass:Yn}],[Et,{useClass:ji}],[D.FormulaDataModel],[it],[Je,{useFactory:()=>{var t;return this._injector.createInstance(Je,(t=this._config)==null?void 0:t.function)}}],[Ut]];(e=this._config)!=null&&e.notExecuteFormula||r.push([D.CalculateFormulaService],[fr,{useClass:Hn}],[cr,{useClass:La}],[xe,{useClass:ar}],[se,{useClass:ur}],[xt],[Bt],[Mt],[Ot],[vt],[Ze],[Qe],[ze],[ve],[vn],[pt],[Dt],[kn],[yt],[_t],[St],[Lt],[At],[Qn]),r.forEach(t=>this._injector.add(t))}onReady(){this._injector.get(D.FormulaDataModel).initFormulaData()}},D.UniverFormulaEnginePlugin=Du([yu(1,B.Inject(B.Injector))],D.UniverFormulaEnginePlugin),D.ArrayValueObject=z,D.BaseFunction=A,D.BaseReferenceObject=ke,D.BaseValueObject=we,D.BooleanValueObject=P,D.ErrorType=c,D.ErrorValueObject=h,D.FUNCTION_NAMES_ARRAY=Ms,D.FUNCTION_NAMES_COMPATIBILITY=Ie,D.FUNCTION_NAMES_CUBE=un,D.FUNCTION_NAMES_DATABASE=ln,D.FUNCTION_NAMES_DATE=Ce,D.FUNCTION_NAMES_ENGINEERING=hn,D.FUNCTION_NAMES_FINANCIAL=gn,D.FUNCTION_NAMES_INFORMATION=ne,D.FUNCTION_NAMES_LOGICAL=Ve,D.FUNCTION_NAMES_LOOKUP=G,D.FUNCTION_NAMES_MATH=N,D.FUNCTION_NAMES_STATISTICAL=K,D.FUNCTION_NAMES_TEXT=Rt,D.FUNCTION_NAMES_UNIVER=Hi,D.FUNCTION_NAMES_WEB=xn,D.FeatureCalculationManagerService=Yn,D.FormulaExecuteStageType=oe,D.FormulaExecutedStateType=Te,D.FunctionService=Bn,D.FunctionType=wr,D.IFeatureCalculationManagerService=Pt,D.IFunctionService=ge,D.LexerNode=U,D.LexerTreeBuilder=it,D.NumberValueObject=_,D.OtherFormulaManagerService=Hn,D.RangeReferenceObject=Ke,D.RegisterFunctionMutation=$t,D.RemoveDefinedNameMutation=ot,D.RemoveFeatureCalculationMutation=Wt,D.RemoveOtherFormulaMutation=Zt,D.RemoveSuperTableMutation=$r,D.SetArrayFormulaDataMutation=at,D.SetArrayFormulaDataUndoMutationFactory=gs,D.SetDefinedNameMutation=ut,D.SetFeatureCalculationMutation=jt,D.SetFormulaCalculationNotificationMutation=lt,D.SetFormulaCalculationResultMutation=Kt,D.SetFormulaCalculationStartMutation=Xt,D.SetFormulaCalculationStopMutation=Gt,D.SetFormulaDataMutation=qt,D.SetNumfmtFormulaDataMutation=gr,D.SetOtherFormulaMutation=zt,D.SetSuperTableMutation=Fr,D.SetSuperTableOptionMutation=Jt,D.StringValueObject=X,D.UnregisterFunctionMutation=Nt,D.ValueObjectFactory=_e,D.compareToken=b,D.convertUnitDataToRuntime=pr,D.deserializeRangeForR1C1=Jr,D.deserializeRangeWithSheet=Fe,D.functionArray=Nr,D.functionCompatibility=sn,D.functionCube=an,D.functionDatabase=on,D.functionDate=cn,D.functionEngineering=fn,D.functionFinancial=mn,D.functionInformation=dn,D.functionLogical=Rn,D.functionLookup=Cn,D.functionMath=yn,D.functionMeta=bn,D.functionStatistical=Ln,D.functionText=An,D.functionUniver=Pn,D.functionWeb=Vn,D.generateStringWithSequence=Br,D.getAbsoluteRefTypeWitString=us,D.getAbsoluteRefTypeWithSingleString=Xe,D.includeFormulaLexerToken=Cr,D.initSheetFormulaData=Or,D.isFormulaLexerToken=tt,D.isInDirtyRange=Er,D.isReferenceString=Sr,D.matchToken=O,D.normalizeSheetName=Jn,D.operatorToken=J,D.sequenceNodeType=te,D.serializeRange=De,D.serializeRangeToRefString=xr,D.serializeRangeWithSheet=Pr,D.serializeRangeWithSpreadsheet=Vr,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
1
+ (function(D,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","rxjs"],d):(D=typeof globalThis<"u"?globalThis:D||self,d(D.UniverEngineFormula={},D.UniverCore,D["@wendellhu/redi"],D.rxjs))})(this,function(D,d,B,Ft){"use strict";var Ou=Object.defineProperty;var Mu=(D,d,B)=>d in D?Ou(D,d,{enumerable:!0,configurable:!0,writable:!0,value:B}):D[d]=B;var p=(D,d,B)=>(Mu(D,typeof d!="symbol"?d+"":d,B),B);function Er(n,r,e,t,s){for(let i=0,a=n.length;i<a;i++){const u=n[i];if(r!==u.unitId||e!==u.sheetId)continue;const{startRow:o,startColumn:l,endRow:f,endColumn:m}=u.range;if(t>=o&&t<=f&&s>=l&&s<=m)return!0}return!1}var c=(n=>(n.DIV_BY_ZERO="#DIV/0!",n.NAME="#NAME?",n.VALUE="#VALUE!",n.NUM="#NUM!",n.NA="#N/A",n.CYCLE="#CYCLE!",n.REF="#REF!",n.SPILL="#SPILL!",n.CALC="#CALC!",n.ERROR="#ERROR!",n.CONNECT="#GETTING_DATA",n.NULL="#NULL!",n))(c||{});const je=new Set(Object.values(c));var _r=(n=>(n[n.Financial=0]="Financial",n[n.Date=1]="Date",n[n.Math=2]="Math",n[n.Statistical=3]="Statistical",n[n.Lookup=4]="Lookup",n[n.Database=5]="Database",n[n.Text=6]="Text",n[n.Logical=7]="Logical",n[n.Information=8]="Information",n[n.Engineering=9]="Engineering",n[n.Cube=10]="Cube",n[n.Compatibility=11]="Compatibility",n[n.Web=12]="Web",n[n.Array=13]="Array",n[n.Univer=14]="Univer",n[n.User=15]="User",n))(_r||{}),Y=(n=>(n.PLUS="+",n.MINUS="-",n.MULTIPLY="*",n.DIVIDED="/",n.CONCATENATE="&",n.POWER="^",n.EQUALS="=",n.NOT_EQUAL="<>",n.GREATER_THAN=">",n.GREATER_THAN_OR_EQUAL=">=",n.LESS_THAN="<",n.LESS_THAN_OR_EQUAL="<=",n))(Y||{}),S=(n=>(n.EQUALS="=",n.NOT_EQUAL="<>",n.GREATER_THAN=">",n.GREATER_THAN_OR_EQUAL=">=",n.LESS_THAN="<",n.LESS_THAN_OR_EQUAL="<=",n))(S||{});const tt=new Map([["<>",3],["<",3],[">=",3],["=",3],[">",3],["<=",3],["&",2],["+",2],["-",2],["/",1],["*",1],["^",0]]),De=new Set(tt.keys()),Zn=new Set(["=","<>",">",">=","<","<="]);var U=(n=>(n.OPEN_BRACKET="(",n.CLOSE_BRACKET=")",n.COMMA=",",n.SINGLE_QUOTATION="'",n.DOUBLE_QUOTATION='"',n.OPEN_BRACES="{",n.CLOSE_BRACES="}",n.COLON=":",n.OPEN_SQUARE_BRACKET="[",n.CLOSE_SQUARE_BRACKET="]",n))(U||{}),me=(n=>(n.PERCENTAGE="%",n.POUND="#",n))(me||{});const Jn=new Set(["%","#"]);var H=(n=>(n.AT="@",n.MINUS="-",n))(H||{});const Nn=" ",wr=[...Object.values(S),...Object.values(Y),...Object.values(U),...Object.values(me),...Object.values(H)];function We(n){return wr.includes(n)}function Cr(n){for(const r of wr)if(n.indexOf(r)>-1)return!0;return!1}function es(n){return n[0]==="'"&&n[n.length-1]==="'"?n.substring(1,n.length-1):n}function ts(n){return We(n)&&n!==U.CLOSE_BRACES&&n!==U.CLOSE_BRACKET&&n!==U.SINGLE_QUOTATION&&n!==U.DOUBLE_QUOTATION||n===" "}function pr(n){const r={};return Object.keys(n).forEach(e=>{const t=n[e];if(t==null)return!0;r[e]==null&&(r[e]={}),Object.keys(t).forEach(s=>{const i=t[s];r[e][s]=new d.ObjectMatrix(i)})}),r}function rs(n){const r={};return Object.keys(n).forEach(e=>{const t=n[e];if(t==null)return!0;r[e]==null&&(r[e]={}),Object.keys(t).forEach(s=>{const i=t[s];r[e][s]=i.getData()})}),r}const $t={id:"formula.mutation.register-function",type:d.CommandType.MUTATION,handler:()=>!0};class rt{constructor(r){p(this,"_cache");this._cache=new d.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 d.hashAlgorithm(r)}}const kt='\\[([^\\[\\]\\/?:"<>|*\\\\]+)\\]',ns="((?![\\[\\]\\/?*\\\\]).)*!",Ee="$",Tt="\\s*?:\\s*?",Oe=`'?(${kt})?(${ns})?'?`,It=`\\${Ee}?[A-Za-z]+\\${Ee}?[0-9]+`,ss=`^(${H.AT})?${Oe}${It}${Tt}${It}$`,nt=`^${Oe}\\s*?${It}(${me.POUND})?$`,Dr=`^${Oe}\\${Ee}?[0-9]+${Tt}\\${Ee}?[0-9]+$`,yr=`^${Oe}\\${Ee}?[A-Za-z]+${Tt}\\${Ee}?[A-Za-z]+$`,is=`^${Oe}\\s*?\\${Ee}?[0-9]+$`,as=`^${Oe}\\s*?\\${Ee}?[A-Za-z]+$`,Sr="[.*?]",us="{.*?}";function br(n){return new RegExp(nt).test(n)||new RegExp(ss).test(n)||new RegExp(Dr).test(n)||new RegExp(yr).test(n)}const ge="P_1",_e="R_1",Me="L_1",Xe="LR_1",Lr="LO_1",os="LET",Ge="LAMBDA",ls="CUBE",cs=/[^0-9]/g,fs=/[^A-Za-z]/g;function Ke(n){const r=n[0]==="$",t=n.substring(1).indexOf("$")>-1;return r&&t?d.AbsoluteRefType.ALL:r?d.AbsoluteRefType.COLUMN:t?d.AbsoluteRefType.ROW:d.AbsoluteRefType.NONE}function hs(n){const r=n.split("!");r.length>1&&(n=r[r.length-1]);const e=n.split(":");return e.length>1?{startAbsoluteRefType:Ke(e[0]),endAbsoluteRefType:Ke(e[1])}:{startAbsoluteRefType:Ke(e[0])}}function Ar(n=d.AbsoluteRefType.NONE){let r="",e="";return n===d.AbsoluteRefType.ROW?r="$":n===d.AbsoluteRefType.COLUMN?e="$":n===d.AbsoluteRefType.ALL&&(r="$",e="$"),{rowAbsoluteString:r,columnAbsoluteString:e}}function ye(n){const{startColumn:r,startRow:e,endColumn:t,endRow:s,startAbsoluteRefType:i,endAbsoluteRefType:a,rangeType:u=d.RANGE_TYPE.NORMAL}=n,o=Ar(i),l=Ar(a);if(u===d.RANGE_TYPE.ROW||u===d.RANGE_TYPE.ALL){const g=`${o.rowAbsoluteString}${e+1}`,R=`${l.rowAbsoluteString}${s+1}`;return`${g}:${R}`}if(u===d.RANGE_TYPE.COLUMN){const g=`${o.columnAbsoluteString}${d.Tools.chatAtABC(r)}`,R=`${l.columnAbsoluteString}${d.Tools.chatAtABC(t)}`;return`${g}:${R}`}const f=`${o.columnAbsoluteString}${d.Tools.chatAtABC(r)}${o.rowAbsoluteString}${e+1}`,m=`${l.columnAbsoluteString}${d.Tools.chatAtABC(t)}${l.rowAbsoluteString}${s+1}`;return f===m?f:`${f}:${m}`}function Pr(n,r){return st(n)?`'${n}'!${ye(r)}`:`${n}!${ye(r)}`}function Vr(n,r,e){return st(n)||st(r)?`'[${n}]${r}'!${ye(e)}`:`[${n}]${r}!${ye(e)}`}function xr(n){const{unitId:r,sheetName:e,range:t}=n;return r!=null&&r.length>0&&e!=null&&e.length>0?Vr(r,e,t):e!=null&&e.length>0?Pr(e,t):ye(t)}function Qt(n){const r=Number.parseInt(n.replace(cs,""))-1,e=d.Tools.ABCatNum(n.replace(fs,"")),t=Ke(n);return{row:r,column:e,absoluteRefType:t}}function vr(n){const r=new RegExp(kt).exec(n);let e="";r!=null&&(e=r[0].trim(),e=e.slice(1,e.length-1),n=n.replace(new RegExp(kt),""));const t=n.indexOf("!");let s="",i="";return t>-1?(s=n.substring(0,t),s[0]==="'"&&s[s.length-1]==="'"&&(s=s.substring(1,s.length-1)),i=n.substring(t)):i=n,{refBody:i,sheetName:s,unitId:e}}function Fe(n){const{refBody:r,sheetName:e,unitId:t}=vr(n),s=r.indexOf(":");if(s===-1){const _=Qt(r),E=_.row,C=_.column,y=_.absoluteRefType;return{unitId:t,sheetName:e,range:{startRow:E,startColumn:C,endRow:E,endColumn:C,startAbsoluteRefType:y,endAbsoluteRefType:y}}}const i=r.substring(0,s),a=r.substring(s+1),u=Qt(i),o=Qt(a),l=u.row,f=u.column,m=o.row,g=o.column;let R=d.RANGE_TYPE.NORMAL;return Number.isNaN(l)&&Number.isNaN(m)?R=d.RANGE_TYPE.COLUMN:Number.isNaN(f)&&Number.isNaN(g)&&(R=d.RANGE_TYPE.ROW),{unitId:t,sheetName:e,range:{startRow:l,startColumn:f,endRow:m,endColumn:g,startAbsoluteRefType:u.absoluteRefType,endAbsoluteRefType:o.absoluteRefType,rangeType:R}}}function st(n){return n.length===0?!1:!!(Cr(n)||ms(n)||gs(n)||ds(n)||/[\s!$%^&*()+\-=\[\]{};':"\\|,.<>\/?]/.test(n))}function ms(n){const r=n.match(/[1-9][0-9]{0,6}/);return/^[A-Z]+[1-9][0-9]{0,6}$/.test(n)&&r!==null&&Number.parseInt(r[0],10)<=1048576}function gs(n){return/^(R(-?[0-9]+)?C(-?[0-9]+)?|C(-?[0-9]+)?|R(-?[0-9]+)?)$/.test(n)}function ds(n){return!new RegExp("^\\p{Letter}","u").test(n.charAt(0))}var te=(n=>(n[n.NORMAL=0]="NORMAL",n[n.NUMBER=1]="NUMBER",n[n.STRING=2]="STRING",n[n.FUNCTION=3]="FUNCTION",n[n.REFERENCE=4]="REFERENCE",n[n.ARRAY=5]="ARRAY",n))(te||{});function Br(n){let r="";for(const e of n)typeof e=="string"?r+=e:r+=e.token;return r}class O{constructor(){p(this,"_parent");p(this,"_token",_e);p(this,"_children",[]);p(this,"_lambdaId");p(this,"_functionDefinitionPrivacyVar");p(this,"_lambdaParameter","");p(this,"_startIndex",-1);p(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=[],s=e.length;for(let i=0;i<s;i++){const a=e[i];a instanceof O?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 s=0;s<t;s++)if(e[s]===r)return s}}const Ur=1e5,Yt=new rt(Ur),Ht=new rt(Ur);class it extends d.Disposable{constructor(){super(...arguments);p(this,"_currentLexerNode",new O);p(this,"_upLevel",0);p(this,"_segment","");p(this,"_bracketState",[]);p(this,"_squareBracketState",0);p(this,"_bracesState",0);p(this,"_singleQuotationState",0);p(this,"_doubleQuotationState",0);p(this,"_lambdaState",!1);p(this,"_colonState",!1);p(this,"_tableBracketState",!1)}dispose(){this._resetTemp(),this._currentLexerNode.dispose(),Yt.clear(),Ht.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 s=this._getCurrentParamIndex(e,t);if(s==null||s===c.VALUE)return;const i=s[0];if(typeof i=="string")return;let a=i.getParent(),u=i;for(;a;){const o=a.getToken();if(o!==ge&&!We(o)&&a.getStartIndex()!==-1){const l=a.getChildren().indexOf(u);return{functionName:o,paramIndex:l}}u=a,a=a.getParent()}}moveFormulaRefOffset(e,t,s){const i=this.sequenceNodesBuilder(e);if(i==null)return e;const a=[];for(let u=0,o=i.length;u<o;u++){const l=i[u];if(typeof l=="string"||l.nodeType!==te.REFERENCE){a.push(l);continue}const{token:f}=l,m=Fe(f),{range:g,sheetName:R,unitId:_}=m,E=d.Rectangle.moveOffset(g,t,s);let C="";d.isValidRange(E)?C=xr({range:E,unitId:_,sheetName:R}):C=c.REF,a.push({...l,token:C})}return`=${Br(a)}`}checkIfAddBracket(e){let t=0,s=e.length-1,i=e[s];for(;(i===U.CLOSE_BRACKET||i===" ")&&s>=0;)i===U.CLOSE_BRACKET&&t++,i=e[--s];const a=this._getCurrentParamIndex(e,e.length-2);if(a==null||a===c.VALUE)return 0;const u=a[0];if(typeof u=="string")return 0;let o=u.getParent(),l=0;for(a[1]===U.OPEN_BRACKET&&l++;o;){const f=o.getToken();f!==ge&&f!==U.COLON&&o.getStartIndex()!==-1&&f.toUpperCase()!==Ge&&(t===0?l+=1:t--),o=o.getParent()}return l}sequenceNodesBuilder(e){const t=Ht.get(e);if(t)return[...t];const s=this._getSequenceArray(e);if(s.length===0)return;const i=this.getSequenceNode(s);return Ht.set(e,[...i]),i}getSequenceNode(e){const t=[];let s=!1;for(let i=0,a=e.length;i<a;i++){const u=e[i],o=e[i-1],{segment:l,currentString:f}=u;if(f===U.DOUBLE_QUOTATION&&(s=!0),(l!==""||i===0)&&i!==a-1){t.push(f);continue}let m=(o==null?void 0:o.segment)||"",g=i-m.length,R=i-1,_=i-1;if(i===a-1&&this._isLastMergeString(f)&&(m+=f,R+=1),m===""||tt.has(m)){t.push(f);continue}const E=m.trim(),C=this._replacePrefixString(E);if(s===!0&&E[E.length-1]===U.DOUBLE_QUOTATION)s=!1,this._pushSequenceNode(t,{nodeType:te.STRING,token:m,startIndex:g,endIndex:R},_);else if(new RegExp(nt).test(C)){if(C.length!==E.length){const y=E.length-C.length;_+=y,g+=y,m=this._replacePrefixString(m)}this._pushSequenceNode(t,{nodeType:te.REFERENCE,token:m,startIndex:g,endIndex:R},_)}else d.Tools.isStringNumber(E)?this._pushSequenceNode(t,{nodeType:te.NUMBER,token:m,startIndex:g,endIndex:R},_):E.length>0&&this._pushSequenceNode(t,{nodeType:te.FUNCTION,token:m,startIndex:g,endIndex:R},_);(i!==a-1||!this._isLastMergeString(f))&&t.push(f)}return this._mergeSequenceNodeReference(t)}_getCurrentParamIndex(e,t){return this._nodeMaker(e,void 0,t)}_isLastMergeString(e){return e===U.DOUBLE_QUOTATION||d.Tools.isStringNumber(e)||!We(e)}_mergeSequenceNodeReference(e){const t=[],s=e.length;let i=0;for(;i<s;){const a=e[i];if(typeof a=="string"){const u=e[i-1];if(a.trim()===U.CLOSE_BRACES&&u!=null&&typeof u!="string"&&u.nodeType===te.FUNCTION&&u.token.trim().substring(0,1)===U.OPEN_BRACES){u.nodeType=te.ARRAY,u.token+=a,u.endIndex+=a.length,i++;continue}t.push(a)}else{const u=e[i+1],o=e[i+2];u===U.COLON&&typeof a!="string"&&o!=null&&typeof o!="string"&&br((a.token+u+o.token).trim())&&(a.nodeType=te.REFERENCE,a.token+=u+o.token,a.endIndex=o.endIndex,i+=2),t.push(a)}i++}return t}_pushSequenceNode(e,t,s){const i=s-t.startIndex+1;e.splice(e.length-i,i,t)}_replacePrefixString(e){const t=[];let s=!1;for(let i=0,a=e.length;i<a;i++){const u=e[i];if(u===Nn&&!s)t.push(u);else{if(!s&&(u===H.AT||u===H.MINUS))continue;t.push(u),s=!0}}return t.join("")}nodeMakerTest(e){return this._nodeMaker(e)}treeBuilder(e,t=!0,s){if(t===!0){const f=Yt.get(e);if(f)return f}this._resetCurrentLexerNode(),this._currentLexerNode.setToken(_e);const i=[];let a=this._nodeMaker(e,i);if(a===c.VALUE||i.length===0)return a;let u=!1,o="";if(s){const{hasDefinedName:f,sequenceString:m}=s(i);u=f,o=m}if(u&&(this._resetCurrentLexerNode(),this._currentLexerNode.setToken(_e),a=this._nodeMaker(`=${o}`),a===c.VALUE))return a;const l=this._getTopNode(this._currentLexerNode);if(l&&(this._currentLexerNode=l),t){if(!this._suffixExpressionHandler(this._currentLexerNode))return c.VALUE;Yt.set(e,this._currentLexerNode)}return this._currentLexerNode}_suffixExpressionHandler(e){var u,o;const t=e.getChildren();if(!t)return!1;const s=t.length,i=[],a=[];for(let l=0;l<s;l++){const f=t[l];if(f instanceof O)this._suffixExpressionHandler(f),i.push(f);else{const m=f.trim();if(m==="")continue;if(De.has(m)){if(m===Y.PLUS&&this._deletePlusForPreNode(t[l-1]))continue;if(m!==Y.PLUS&&m!==Y.MINUS&&this._deletePlusForPreNode(t[l-1]))return!1;for(;a.length>0;){const g=(u=a[a.length-1])==null?void 0:u.trim();if(!g||g===U.OPEN_BRACKET)break;const R=tt.get(g),_=tt.get(m);if(!R||!_)break;if(_>=R)i.push(a.pop());else break}a.push(f)}else if(m===U.OPEN_BRACKET)a.push(f);else if(m===U.CLOSE_BRACKET){if(this._checkOpenBracket(t[l-1])||this._checkOperator(t[l-1]))return!1;for(;a.length>0;){const g=(o=a[a.length-1])==null?void 0:o.trim();if(!g)break;if(g===U.OPEN_BRACKET){a.pop();break}i.push(a.pop())}}else{if(this._checkCloseBracket(t[l-1]))return!1;i.push(f)}}}for(;a.length>0;){const l=a.pop();if(l===U.OPEN_BRACKET||l===U.CLOSE_BRACKET)return!1;i.push(l)}return e.setChildren(i),!0}_checkCloseBracket(e){return e===U.CLOSE_BRACKET}_checkOpenBracket(e){return e===U.OPEN_BRACKET}_checkOperator(e){return e==null||e instanceof O?!1:De.has(e)}_deletePlusForPreNode(e){if(e==null)return!0;if(!(e instanceof O)){const t=e.trim();if(De.has(t)||t===U.OPEN_BRACKET)return!0}return!1}_resetCurrentLexerNode(){this._currentLexerNode=new O}_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]}_changeCurrentBracket(e){const t=this._bracketState;t[t.length-1]=e}_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 O)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 s,i,a,u,o,l;const e=(s=this._currentLexerNode)==null?void 0:s.getParent();let t=!1;if(e&&e.getToken()===Me){if((i=e==null?void 0:e.getParent())!=null&&i.getParent()){const f=(u=(a=this._currentLexerNode.getParent())==null?void 0:a.getParent())==null?void 0:u.getParent();f&&(this._currentLexerNode=f),t=!0}}else if(e!=null&&e.getParent()){const f=(o=this._currentLexerNode.getParent())==null?void 0:o.getParent();f&&(this._currentLexerNode=f),t=!0}for(let f=0;f<this._upLevel;f++){const m=(l=this._currentLexerNode)==null?void 0:l.getParent();m&&(this._currentLexerNode=m),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 s=this._currentLexerNode.getChildren();if(!(e instanceof O)&&this.isColonOpen()){const i=new O;i.setToken(e),i.setParent(this._currentLexerNode),e=i}t?s.unshift(e):s.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,s=!1){const i=new O;i.setToken(e),i.setIndex(t-e.length,t-1),this._setCurrentLexerNode(i,s)}_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 s=e[t];if(s!==" ")return s;t--}}_negativeCondition(e){return!!(De.has(e)||e===U.OPEN_BRACKET||e===U.COMMA||e==="")}_getSequenceArray(e){const t=[];return this._nodeMaker(e,t),t}_resetTemp(){this._currentLexerNode=new O,this._upLevel=0,this._segment="",this._bracketState=[],this._bracesState=0,this._singleQuotationState=0,this._doubleQuotationState=0,this._lambdaState=!1,this._colonState=!1}_checkSimilarErrorToken(e,t,s){if(e!==me.POUND)return!0;let i=s[++t];for(;i===" ";)i=s[++t];return!!We(i)}_nodeMaker(e,t,s){e.substring(0,1)===Y.EQUALS&&(e=e.substring(1));let i=!1;e.substring(0,1)===Y.MINUS&&(e=`0${e}`,i=!0);const a=e.split(""),u=a.length;let o=0;for(this._resetTemp();o<u;){const l=a[o];if(s===o)return[this._currentLexerNode,l];if(l===U.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 f=a[o+1];if(f&&f===U.CLOSE_BRACKET){if(!this._setParentCurrentLexerNode()&&o!==u-1)return c.VALUE;o++}else f&&this._newAndPushCurrentLexerNode(ge,o)}else this._pushNodeToChildren(l),this._openBracket(0);else if(l===U.CLOSE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()){this._pushNodeToChildren(this._segment),this._resetSegment();const f=this._getCurrentBracket();if(f===0)this._pushNodeToChildren(l);else if(f===1){const m=a[o+1];if(m&&m===U.OPEN_BRACKET){if(!this._setParentCurrentLexerNode()&&o!==u-1)return c.VALUE;this._newAndPushCurrentLexerNode(Me,o,!0),this._openLambda()}else if(!this._setAncestorCurrentLexerNode()&&o!==u-1)return c.VALUE}else return c.VALUE;this._closeBracket()}else if(l===U.OPEN_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(l),this._openBraces();else if(l===U.CLOSE_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(l),this._pushNodeToChildren(this._segment),this._resetSegment(),this._closeBraces();else if(l===U.OPEN_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._segment.length>0&&this._openTableBracket(),this._pushSegment(l),this._openSquareBracket();else if(l===U.CLOSE_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._closeSquareBracket(),this.isSquareBracketClose()?(this._pushSegment(l),this._isTableBracket()&&(this._pushNodeToChildren(this._segment),this._resetSegment()),this._closeTableBracket()):this._pushSegment(l);else if(l===U.DOUBLE_QUOTATION&&this.isSingleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){if(this.isDoubleQuotationClose())this._openDoubleQuotation();else{const f=a[o+1];f&&f===U.DOUBLE_QUOTATION?o++:this._closeDoubleQuotation()}this._pushSegment(l)}else if(l===U.SINGLE_QUOTATION&&this.isDoubleQuotationClose()){if(this.isSingleQuotationClose())this._openSingleQuotation();else{const f=a[o+1];f&&f===U.SINGLE_QUOTATION?o++:this._closeSingleQuotation()}this._pushSegment(l)}else if(l===U.COMMA&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const f=this._getCurrentBracket();if(f===1||f==null){if(this._pushNodeToChildren(this._segment),this._resetSegment(),!this._setParentCurrentLexerNode()&&o!==u-1&&f!=null)return c.VALUE;this._newAndPushCurrentLexerNode(ge,o)}else{const m=new O;m.setToken(ls);const g=new O;g.setToken(ge),g.changeToParent(m);const R=this._currentLexerNode.getParent();if(R&&R.getToken()===U.COLON){const _=R.getParent();if(!_)return c.VALUE;R.changeToParent(g),_.setChildren([]),m.changeToParent(_)}else return c.VALUE;this._changeCurrentBracket(1),this._pushNodeToChildren(this._segment),this._resetSegment(),this._currentLexerNode=m,this._newAndPushCurrentLexerNode(ge,o)}}else if(l===U.COLON&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const f=new O;f.setToken(l);const m=new O;m.setToken(ge),m.setParent(f);const g=new O;g.setToken(ge),g.setParent(f),f.getChildren().push(m,g);let R=f,_=0;if(this._segmentCount()>0){let E,C,y=0;const b=this._segment.trim(),L=b[0],V=b[1];if(L===H.MINUS&&(E=new O,E.setToken(H.MINUS),y++),(L===H.AT||V===H.AT)&&(C=new O,C.setToken(H.AT),E&&(E.addChildren(C),C.setParent(E)),y++),y>0&&(this._segment=b.slice(y)),_=y,C)if(C.addChildren(f),f.setParent(C),C.getParent()){const Q=C.getParent();Q&&(R=Q)}else R=C;else E&&(R=E,E.addChildren(f),f.setParent(E));const T=new O;T.setToken(this._segment),T.setParent(m),m.getChildren().push(T),this._resetSegment()}else{const E=this._getLastChildCurrentLexerNode();E&&E.changeToParent(m)}this._setCurrentLexerNode(R),this._currentLexerNode=g,this._openColon(_)}else if(Jn.has(l)&&this._checkSimilarErrorToken(l,o,a)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){this._pushNodeToChildren(this._segment);const f=new O;f.setToken(l);const m=this._getLastChildCurrent();m instanceof O?m.changeToParent(f):m!==!1&&(f.getChildren().push(m),this._removeLastChild()),this._pushNodeToChildren(f),f.setParent(this._currentLexerNode),this._resetSegment()}else if(De.has(l)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){let f=this._segment.trim();if(l===Y.MINUS&&f===""){const m=this._findPreviousToken(a,o-1)||"";if(this._negativeCondition(m)){this._pushSegment(Y.MINUS),i&&o===0||t==null||t.push({segment:this._segment,currentString:l,cur:o,currentLexerNode:this._currentLexerNode}),o++;continue}}else if(this._segment.length>0&&a[o-1]&&a[o-1].toUpperCase()==="E"&&(l===Y.MINUS||l===Y.PLUS)){this._pushSegment(l),i&&o===0||t==null||t.push({segment:this._segment,currentString:l,cur:o,currentLexerNode:this._currentLexerNode}),o++;continue}else this._segment.length>0&&f===""?f=this._segment:(this._pushNodeToChildren(this._segment),f="");if(l===Y.LESS_THAN||l===Y.GREATER_THAN){const m=a[o+1];m&&De.has(l+m)?(this._pushNodeToChildren(f+l+m),o++):this._pushNodeToChildren(f+l)}else this._pushNodeToChildren(f+l);this._resetSegment()}else this._pushSegment(l);i&&o===0||t==null||t.push({segment:this._segment,currentString:l,cur:o,currentLexerNode:this._currentLexerNode}),o++}this._pushNodeToChildren(this._segment)}}var Rs=Object.defineProperty,Es=Object.getOwnPropertyDescriptor,_s=(n,r,e,t)=>{for(var s=t>1?void 0:t?Es(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Rs(r,e,s),s},Or=(n,r)=>(e,t)=>r(e,t,n);D.FormulaDataModel=class extends d.Disposable{constructor(e,t){super();p(this,"_formulaData",{});p(this,"_arrayFormulaRange",{});p(this,"_arrayFormulaCellData",{});p(this,"_numfmtItemMap",{});this._currentUniverService=e,this._lexerTreeBuilder=t}clearPreviousArrayFormulaCellData(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;Object.keys(s).forEach(i=>{var l,f,m,g;const a=s[i],u=(f=(l=this._arrayFormulaRange)==null?void 0:l[t])==null?void 0:f[i];if(u==null)return!0;let o=new d.ObjectMatrix;((m=this._arrayFormulaCellData[t])==null?void 0:m[i])!=null&&(o=new d.ObjectMatrix((g=this._arrayFormulaCellData[t])==null?void 0:g[i])),a.forValue((R,_)=>{var V;const E=(V=u==null?void 0:u[R])==null?void 0:V[_];if(E==null)return!0;const{startRow:C,startColumn:y,endRow:b,endColumn:L}=E;for(let T=C;T<=b;T++)for(let Q=y;Q<=L;Q++)o.setValue(T,Q,null)}),this._arrayFormulaCellData[t]&&(this._arrayFormulaCellData[t][i]=o.getData())})})}mergeArrayFormulaCellData(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;this._arrayFormulaRange[t]==null&&(this._arrayFormulaRange[t]={}),this._arrayFormulaCellData[t]==null&&(this._arrayFormulaCellData[t]={}),Object.keys(s).forEach(i=>{var l,f,m,g;const a=s[i];let u=new d.ObjectMatrix,o=new d.ObjectMatrix;((l=this._arrayFormulaRange[t])==null?void 0:l[i])!=null&&(u=new d.ObjectMatrix((f=this._arrayFormulaRange[t])==null?void 0:f[i])),((m=this._arrayFormulaCellData[t])==null?void 0:m[i])!=null&&(o=new d.ObjectMatrix((g=this._arrayFormulaCellData[t])==null?void 0:g[i])),a.forValue((R,_)=>{const E=u==null?void 0:u.getValue(R,_);if(E==null)return!0;const{startRow:C,startColumn:y,endRow:b,endColumn:L}=E;for(let V=C;V<=b;V++)for(let T=y;T<=L;T++)o.setValue(V,T,null)}),a.forValue((R,_,E)=>{o.setValue(R,_,E)}),this._arrayFormulaCellData[t]&&(this._arrayFormulaCellData[t][i]=o.getData())})})}getFormulaData(){return this._formulaData}setFormulaData(e){this._formulaData=e}getArrayFormulaRange(){return this._arrayFormulaRange}setArrayFormulaRange(e){this._arrayFormulaRange=e}getArrayFormulaCellData(){return this._arrayFormulaCellData}setArrayFormulaCellData(e){this._arrayFormulaCellData=e}getNumfmtItemMap(){return this._numfmtItemMap}getNumfmtValue(e,t,s,i){var a,u,o;return(o=(u=(a=this._numfmtItemMap[e])==null?void 0:a[t])==null?void 0:u[s])==null?void 0:o[i]}setNumfmtItemMap(e){this._numfmtItemMap=e}updateNumfmtItemMap(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;this._numfmtItemMap[t]==null&&(this._numfmtItemMap[t]={}),Object.keys(s).forEach(i=>{const a=s[i],u=new d.ObjectMatrix(a);this._numfmtItemMap[t][i]==null&&(this._numfmtItemMap[t][i]={}),u.forValue((o,l,f)=>{this._numfmtItemMap[t][i][o]==null&&(this._numfmtItemMap[t][i][o]={}),this._numfmtItemMap[t][i][o][l]=f})})})}mergeArrayFormulaRange(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;this._arrayFormulaRange[t]||(this._arrayFormulaRange[t]={}),Object.keys(s).forEach(i=>{var o,l;const a=new d.ObjectMatrix(s[i]);let u=new d.ObjectMatrix;(o=this._arrayFormulaRange[t])!=null&&o[i]&&(u=new d.ObjectMatrix((l=this._arrayFormulaRange[t])==null?void 0:l[i])),a.forValue((f,m,g)=>{u.setValue(f,m,g)}),this._arrayFormulaRange[t]&&(this._arrayFormulaRange[t][i]=u.getData())})})}deleteArrayFormulaRange(e,t,s,i){var o;const a=(o=this._arrayFormulaRange[e])==null?void 0:o[t];if(a==null)return;const u=new d.ObjectMatrix(a);u.getValue(s,i)&&(u.realDeleteValue(s,i),this._arrayFormulaRange[e]&&(this._arrayFormulaRange[e][t]=u.getData()))}initFormulaData(){if(this._currentUniverService.getAllUniverSheetsInstance().length===0)return;const t=this._currentUniverService.getCurrentUniverSheetInstance(),s=t.getUnitId();this._formulaData[s]={},t.getSheets().forEach(a=>{const u=a.getCellMatrix(),o=a.getSheetId();Mr(this._formulaData,s,o,u)})}getCalculateData(){const e=this._currentUniverService.getAllUniverSheetsInstance(),t={},s={};for(const i of e){const a=i.getUnitId(),u=i.getSheets(),o={},l={};for(const f of u){const m=f.getSheetId(),g=f.getConfig();o[m]={cellData:new d.ObjectMatrix(g.cellData),rowCount:g.rowCount,columnCount:g.columnCount,rowData:g.rowData,columnData:g.columnData},l[f.getName()]=f.getSheetId()}t[a]=o,s[a]=l}return{allUnitData:t,unitSheetNameMap:s}}updateFormulaData(e,t,s){const i=new d.ObjectMatrix(s),a=this.getFormulaIdMap(e,t),u=new Map,o=this._formulaData;o[e]==null&&(o[e]={});const l=o[e];l[t]==null&&(l[t]={});const f=new d.ObjectMatrix(l[t]);i.forValue((m,g,R)=>{const _=(R==null?void 0:R.f)||"",E=(R==null?void 0:R.si)||"",C=d.isFormulaString(_),y=d.isFormulaId(E);if(C&&y)f.setValue(m,g,{f:_,si:E}),a.set(E,{f:_,r:m,c:g});else if(C&&!y)f.setValue(m,g,{f:_});else if(!C&&y)f.setValue(m,g,{f:"",si:E});else if(!C&&!y&&f.getValue(m,g)){const b=f.getValue(m,g),L=(b==null?void 0:b.f)||"",V=(b==null?void 0:b.si)||"";d.isFormulaString(L)&&d.isFormulaId(V)&&u.set(V,L),f.realDeleteValue(m,g)}}),f.forValue((m,g,R)=>{const _=(R==null?void 0:R.f)||"",E=(R==null?void 0:R.si)||"";if(d.isFormulaId(E)){const C=a.get(E),y=u.get(E);if(C&&!d.isFormulaString(_)){const b=C.f,L=g-C.c,V=m-C.r;f.setValue(m,g,{f:b,si:E,x:L,y:V})}else if(typeof y=="string"){const b=R.x||0,L=R.y||0,V=this._lexerTreeBuilder.moveFormulaRefOffset(y,b,L);u.set(E,{r:m,c:g,f:V}),f.setValue(m,g,{f:V,si:E})}else if(typeof y=="object"){const b=g-y.c,L=m-y.r;f.setValue(m,g,{f:y.f,si:E,x:b,y:L})}}})}updateArrayFormulaRange(e,t,s){var o;const i=(o=this._arrayFormulaRange[e])==null?void 0:o[t];if(!i)return;const a=new d.ObjectMatrix(i);new d.ObjectMatrix(s).forValue((l,f,m)=>{if((a==null?void 0:a.getValue(l,f))==null)return!0;const R=(m==null?void 0:m.f)||"",_=(m==null?void 0:m.si)||"",E=d.isFormulaString(R),C=d.isFormulaId(_);!E&&!C&&a.realDeleteValue(l,f)})}updateArrayFormulaCellData(e,t,s){var f,m;const i=(f=this._arrayFormulaRange[e])==null?void 0:f[t];if(!i)return;const a=new d.ObjectMatrix(i),u=(m=this._arrayFormulaCellData[e])==null?void 0:m[t];if(!u)return;const o=new d.ObjectMatrix(u);new d.ObjectMatrix(s).forValue((g,R,_)=>{const E=a==null?void 0:a.getValue(g,R);if(E==null)return!0;const C=(_==null?void 0:_.f)||"",y=(_==null?void 0:_.si)||"",b=d.isFormulaString(C),L=d.isFormulaId(y);if(!b&&!L){const{startRow:V,startColumn:T,endRow:Q,endColumn:I}=E;for(let x=V;x<=Q;x++)for(let v=T;v<=I;v++)o.realDeleteValue(x,v)}})}updateNumfmtData(e,t,s){var f,m;const i=(f=this._arrayFormulaRange[e])==null?void 0:f[t],a=new d.ObjectMatrix(i),u=(m=this._numfmtItemMap[e])==null?void 0:m[t];if(!u)return;const o=new d.ObjectMatrix(u);new d.ObjectMatrix(s).forValue((g,R,_)=>{const E=(_==null?void 0:_.f)||"",C=(_==null?void 0:_.si)||"",y=d.isFormulaString(E),b=d.isFormulaId(C);if(!y&&!b){o.setValue(g,R,null);const L=a.getValue(g,R);if(L){const{startRow:V,startColumn:T,endRow:Q,endColumn:I}=L;for(let x=V;x<=Q;x++)for(let v=T;v<=I;v++)o.setValue(x,v,null)}}})}getFormulaItemBySId(e,t,s){const i=this._formulaData;if(i[s]==null)return null;const a=i[s];if((a==null?void 0:a[t])==null)return null;const u=new d.ObjectMatrix(a[t]);let o=null;return u.forValue((l,f,m)=>{const{f:g,si:R,x:_=0,y:E=0}=m;if(R===e&&g.length>0&&_===0&&E===0)return o=m,!1}),o}getFormulaDataItem(e,t,s,i){var a,u,o,l;return(l=(o=(u=(a=this._formulaData)==null?void 0:a[i])==null?void 0:u[s])==null?void 0:o[e])==null?void 0:l[t]}getFormulaIdMap(e,t){const s=new Map,i=this._formulaData;if(i[e]==null)return s;const a=i[e];return(a==null?void 0:a[t])==null||new d.ObjectMatrix(a[t]).forValue((o,l,f)=>{const m=(f==null?void 0:f.f)||"",g=(f==null?void 0:f.si)||"",R=(f==null?void 0:f.x)||0,_=(f==null?void 0:f.y)||0;d.isFormulaString(m)&&d.isFormulaId(g)&&R===0&&_===0&&s.set(g,{f:m,r:o,c:l})}),s}},D.FormulaDataModel=_s([Or(0,d.IUniverInstanceService),Or(1,B.Inject(it))],D.FormulaDataModel);function Mr(n,r,e,t){const s=new Map,i=new d.ObjectMatrix;t.forValue((a,u,o)=>{const l=(o==null?void 0:o.f)||"",f=(o==null?void 0:o.si)||"",m=d.isFormulaString(l),g=d.isFormulaId(f);m&&g?(i.setValue(a,u,{f:l,si:f}),s.set(f,{f:l,r:a,c:u})):m&&!g?i.setValue(a,u,{f:l}):!m&&g&&i.setValue(a,u,{f:"",si:f})}),i.forValue((a,u,o)=>{const l=(o==null?void 0:o.f)||"",f=(o==null?void 0:o.si)||"";if(d.isFormulaId(f)&&!d.isFormulaString(l)){const m=s.get(f);if(m){const g=m.f,R=u-m.c,_=a-m.r;i.setValue(a,u,{f:g,si:f,x:R,y:_})}}}),n[r]&&(n[r][e]=i.getData())}const ws=n=>{const r=n.get(D.FormulaDataModel),e=d.Tools.deepClone(r.getArrayFormulaRange()),t=d.Tools.deepClone(r.getArrayFormulaCellData());return{arrayFormulaRange:e,arrayFormulaCellData:t}},at={id:"formula.mutation.set-array-formula-data",type:d.CommandType.MUTATION,handler:(n,r)=>{const e=n.get(D.FormulaDataModel);return e.setArrayFormulaRange(r.arrayFormulaRange),e.setArrayFormulaCellData(r.arrayFormulaCellData),!0}},ut={id:"formula.mutation.set-defined-name",type:d.CommandType.MUTATION,handler:()=>!0},ot={id:"formula.mutation.remove-defined-name",type:d.CommandType.MUTATION,handler:()=>!0},jt={id:"formula.mutation.set-feature-calculation",type:d.CommandType.MUTATION,handler:()=>!0},Wt={id:"formula.mutation.remove-feature-calculation",type:d.CommandType.MUTATION,handler:()=>!0},Xt={id:"formula.mutation.set-formula-calculation-start",type:d.CommandType.MUTATION,handler:()=>!0},Gt={id:"formula.mutation.set-formula-calculation-stop",type:d.CommandType.MUTATION,handler:()=>!0},lt={id:"formula.mutation.set-formula-calculation-notification",type:d.CommandType.MUTATION,handler:()=>!0},Kt={id:"formula.mutation.set-formula-calculation-result",type:d.CommandType.MUTATION,handler:()=>!0},zt={id:"formula.mutation.set-formula-data",type:d.CommandType.MUTATION,handler:(n,r)=>(n.get(D.FormulaDataModel).setFormulaData(r.formulaData),!0)},qt={id:"formula.mutation.set-other-formula",type:d.CommandType.MUTATION,handler:()=>!0},Zt={id:"formula.mutation.remove-other-formula",type:d.CommandType.MUTATION,handler:()=>!0},Fr={id:"formula.mutation.set-super-table",type:d.CommandType.MUTATION,handler:()=>!0},$r={id:"formula.mutation.remove-super-table",type:d.CommandType.MUTATION,handler:()=>!0},Jt={id:"formula.mutation.set-super-table-option",type:d.CommandType.MUTATION,handler:()=>!0},Nt={id:"formula.mutation.unregister-function",type:d.CommandType.MUTATION,handler:()=>!0};class ct extends d.Disposable{constructor(){super(...arguments);p(this,"pattern","")}getPattern(){return this.pattern}setPattern(e){this.pattern=e}isError(){return!1}isAsyncObject(){return!1}isAsyncArrayObject(){return!1}isReferenceObject(){return!1}isValueObject(){return!1}isEqualType(e){return!1}}var Se=(n=>(n.FALSE="FALSE",n.TRUE="TRUE",n))(Se||{}),be=(n=>(n[n.SUCCESS=0]="SUCCESS",n[n.ERROR=1]="ERROR",n))(be||{}),Le=(n=>(n.ALL="#All",n.DATA="#Data",n.HEADERS="#Headers",n.TOTALS="#Totals",n))(Le||{}),ne=(n=>(n[n.FRONT=0]="FRONT",n[n.BACK=1]="BACK",n))(ne||{});class Cs{constructor(){p(this,"_cache",new Map);p(this,"_continueBuildingCache",new Map)}set(r,e,t,s,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 u=a.get(e);u==null&&(u=new Map,a.set(e,u));let o=u.get(t);o==null&&(o=new Map,u.set(t,o));let l=o.get(s);l==null&&(l=[],o.set(s,l)),l.push(i)}getCellValuePositions(r,e,t){var s,i;return(i=(s=this._cache.get(r))==null?void 0:s.get(e))==null?void 0:i.get(t)}getCellPositions(r,e,t,s){var i,a,u;return(u=(a=(i=this._cache.get(r))==null?void 0:i.get(e))==null?void 0:a.get(t))==null?void 0:u.get(s)}getCellPosition(r,e,t,s,i,a){const u=this.getCellPositions(r,e,t,s);if(u!=null){for(const o of u)if(o>=i&&o<=a)return o}}setContinueBuildingCache(r,e,t,s,i){let a=this._continueBuildingCache.get(r);a==null&&(a=new Map,this._continueBuildingCache.set(r,a));let u=a.get(e);u==null&&(u=new Map,a.set(e,u));let o=u.get(t);if(o==null){o={startRow:s,endRow:i},u.set(t,o);return}o.startRow=Math.min(o.startRow,s),o.endRow=Math.max(o.endRow,i)}shouldContinueBuildingCache(r,e,t,s){var o,l;const i=(l=(o=this._continueBuildingCache.get(r))==null?void 0:o.get(e))==null?void 0:l.get(t);if(i==null)return!0;const{startRow:a,endRow:u}=i;return!(s>=a&&s<=u)}canUseCache(r,e,t,s,i){var l,f;if(t===-1||s===-1||i===-1)return!1;const a=(f=(l=this._continueBuildingCache.get(r))==null?void 0:l.get(e))==null?void 0:f.get(t);if(a==null)return!1;const{startRow:u,endRow:o}=a;return!(s>o||i<u)}clear(){this._cache.clear(),this._continueBuildingCache.clear()}}const we=new Cs;var de=(n=>(n[n.MIN=0]="MIN",n[n.MAX=1]="MAX",n))(de||{}),Z=(n=>(n[n.NORMAL=0]="NORMAL",n[n.MIN=1]="MIN",n[n.MAX=2]="MAX",n))(Z||{});function kr(){return Intl&&Intl.Collator?new Intl.Collator(void 0,{numeric:!1}).compare:(n,r)=>n.localeCompare(r)}function ps(n){return n.indexOf("*")>-1||n.indexOf("?")>-1}function Tr(n,r){const e=ys(r).replace(/~?[*?]/g,s=>s.startsWith("~")?`\\${s.substring(1)}`:s==="*"?".*":s==="?"?".":s);return new RegExp(`^${e}$`).test(n)}function Ir(n){return n.replace(/~?[*?]/g,r=>r.startsWith("~")?r.substring(1):" ")}function Ds(n,r,e){let t=!1;switch(e){case S.EQUALS:t=Tr(n,r);break;case S.GREATER_THAN:case S.GREATER_THAN_OR_EQUAL:t=Tr(n,r)||n>Ir(r);break;case S.LESS_THAN:case S.LESS_THAN_OR_EQUAL:t=n<Ir(r);break}return t}function ys(n){return n.replace(/[.+^${}()|[\]\\]/g,"\\$&")}class Re extends ct{constructor(r){super(),this._rawValue=r}isValueObject(){return!0}toUnitRange(){return{range:{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1},sheetId:"",unitId:""}}getValue(){return 0}getArrayValue(){return[]}setValue(r){}setArrayValue(r){}isCube(){return!1}isArray(){return!1}isString(){return!1}isNumber(){return!1}isBoolean(){return!1}isLambda(){return!1}isError(){return!1}isNull(){return!1}sum(){return new h(c.VALUE)}max(){return new h(c.VALUE)}min(){return new h(c.VALUE)}count(){return new h(c.VALUE)}countA(){return new h(c.VALUE)}countBlank(){return new h(c.VALUE)}getNegative(){return new h(c.NAME)}getReciprocal(){return new h(c.NAME)}plus(r){return new h(c.NAME)}minus(r){return new h(c.NAME)}multiply(r){return new h(c.NAME)}divided(r){return new h(c.NAME)}mod(r){return new h(c.VALUE)}map(r){return new h(c.NAME)}mapValue(r){return new h(c.NAME)}product(r,e){return e(this,r)}compare(r,e){return new h(c.NAME)}isEqual(r){return this.compare(r,S.EQUALS)}isNotEqual(r){return this.compare(r,S.NOT_EQUAL)}isGreaterThanOrEqual(r){return this.compare(r,S.GREATER_THAN_OR_EQUAL)}isLessThanOrEqual(r){return this.compare(r,S.LESS_THAN_OR_EQUAL)}isLessThan(r){return this.compare(r,S.LESS_THAN)}isGreaterThan(r){return this.compare(r,S.GREATER_THAN)}concatenateFront(r){return new h(c.NAME)}concatenateBack(r){return new h(c.NAME)}plusBy(r){return new h(c.NAME)}minusBy(r){return new h(c.NAME)}multiplyBy(r){return new h(c.NAME)}dividedBy(r){return new h(c.NAME)}modInverse(r){return new h(c.VALUE)}compareBy(r,e){return new h(c.NAME)}concatenate(r,e=ne.FRONT){let t=this.getValue().toString();if(typeof r=="string")e===ne.FRONT?t=r+t:t+=r;else if(typeof r=="number")e===ne.FRONT?t=r.toString()+t:t+=r.toString();else if(typeof r=="boolean"){const s=r?"TRUE":"FALSE";e===ne.FRONT?t=s+t:t+=s}return t}pow(r){return new h(c.VALUE)}powInverse(r){return new h(c.VALUE)}sqrt(){return new h(c.VALUE)}cbrt(){return new h(c.VALUE)}cos(){return new h(c.VALUE)}acos(){return new h(c.VALUE)}acosh(){return new h(c.VALUE)}sin(){return new h(c.VALUE)}asin(){return new h(c.VALUE)}asinh(){return new h(c.VALUE)}tan(){return new h(c.VALUE)}tanh(){return new h(c.VALUE)}atan(){return new h(c.VALUE)}atan2(r){return new h(c.VALUE)}atan2Inverse(r){return new h(c.VALUE)}atanh(){return new h(c.VALUE)}mean(){return this}median(){return this}var(){return this}std(){return this}log(){return new h(c.VALUE)}log10(){return new h(c.VALUE)}exp(){return new h(c.VALUE)}abs(){return new h(c.VALUE)}round(r){return new h(c.VALUE)}roundInverse(r){return new h(c.VALUE)}floor(r){return new h(c.VALUE)}floorInverse(r){return new h(c.VALUE)}ceil(r){return new h(c.VALUE)}ceilInverse(r){return new h(c.VALUE)}}class h extends Re{constructor(r,e=""){super(r),this._errorType=r,this._errorContent=e}getValue(){return this._errorType}getErrorType(){return this._errorType}getErrorContent(){return this._errorContent}isEqualType(r){return r.getErrorType()===this.getErrorType()}isError(){return!0}}var Ss=20,bs=1,Ae=1e6,Qr=1e6,Ls=-7,As=21,Ps=!1,ze="[big.js] ",Pe=ze+"Invalid ",ft=Pe+"decimal places",Vs=Pe+"rounding mode",Yr=ze+"Division by zero",F={},ue=void 0,xs=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function Hr(){function n(r){var e=this;if(!(e instanceof n))return r===ue?Hr():new n(r);if(r instanceof n)e.s=r.s,e.e=r.e,e.c=r.c.slice();else{if(typeof r!="string"){if(n.strict===!0&&typeof r!="bigint")throw TypeError(Pe+"value");r=r===0&&1/r<0?"-0":String(r)}vs(e,r)}e.constructor=n}return n.prototype=F,n.DP=Ss,n.RM=bs,n.NE=Ls,n.PE=As,n.strict=Ps,n.roundDown=0,n.roundHalfUp=1,n.roundHalfEven=2,n.roundUp=3,n}function vs(n,r){var e,t,s;if(!xs.test(r))throw Error(Pe+"number");for(n.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),s=r.length,t=0;t<s&&r.charAt(t)=="0";)++t;if(t==s)n.c=[n.e=0];else{for(;s>0&&r.charAt(--s)=="0";);for(n.e=e-t-1,n.c=[],e=0;t<=s;)n.c[e++]=+r.charAt(t++)}return n}function Ve(n,r,e,t){var s=n.c;if(e===ue&&(e=n.constructor.RM),e!==0&&e!==1&&e!==2&&e!==3)throw Error(Vs);if(r<1)t=e===3&&(t||!!s[0])||r===0&&(e===1&&s[0]>=5||e===2&&(s[0]>5||s[0]===5&&(t||s[1]!==ue))),s.length=1,t?(n.e=n.e-r+1,s[0]=1):s[0]=n.e=0;else if(r<s.length){if(t=e===1&&s[r]>=5||e===2&&(s[r]>5||s[r]===5&&(t||s[r+1]!==ue||s[r-1]&1))||e===3&&(t||!!s[0]),s.length=r,t){for(;++s[--r]>9;)if(s[r]=0,r===0){++n.e,s.unshift(1);break}}for(r=s.length;!s[--r];)s.pop()}return n}function $e(n,r,e){var t=n.e,s=n.c.join(""),i=s.length;if(r)s=s.charAt(0)+(i>1?"."+s.slice(1):"")+(t<0?"e":"e+")+t;else if(t<0){for(;++t;)s="0"+s;s="0."+s}else if(t>0)if(++t>i)for(t-=i;t--;)s+="0";else t<i&&(s=s.slice(0,t)+"."+s.slice(t));else i>1&&(s=s.charAt(0)+"."+s.slice(1));return n.s<0&&e?"-"+s:s}F.abs=function(){var n=new this.constructor(this);return n.s=1,n},F.cmp=function(n){var r,e=this,t=e.c,s=(n=new e.constructor(n)).c,i=e.s,a=n.s,u=e.e,o=n.e;if(!t[0]||!s[0])return t[0]?i:s[0]?-a:0;if(i!=a)return i;if(r=i<0,u!=o)return u>o^r?1:-1;for(a=(u=t.length)<(o=s.length)?u:o,i=-1;++i<a;)if(t[i]!=s[i])return t[i]>s[i]^r?1:-1;return u==o?0:u>o^r?1:-1},F.div=function(n){var r=this,e=r.constructor,t=r.c,s=(n=new e(n)).c,i=r.s==n.s?1:-1,a=e.DP;if(a!==~~a||a<0||a>Ae)throw Error(ft);if(!s[0])throw Error(Yr);if(!t[0])return n.s=i,n.c=[n.e=0],n;var u,o,l,f,m,g=s.slice(),R=u=s.length,_=t.length,E=t.slice(0,u),C=E.length,y=n,b=y.c=[],L=0,V=a+(y.e=r.e-n.e)+1;for(y.s=i,i=V<0?0:V,g.unshift(0);C++<u;)E.push(0);do{for(l=0;l<10;l++){if(u!=(C=E.length))f=u>C?1:-1;else for(m=-1,f=0;++m<u;)if(s[m]!=E[m]){f=s[m]>E[m]?1:-1;break}if(f<0){for(o=C==u?s:g;C;){if(E[--C]<o[C]){for(m=C;m&&!E[--m];)E[m]=9;--E[m],E[C]+=10}E[C]-=o[C]}for(;!E[0];)E.shift()}else break}b[L++]=f?l:++l,E[0]&&f?E[C]=t[R]||0:E=[t[R]]}while((R++<_||E[0]!==ue)&&i--);return!b[0]&&L!=1&&(b.shift(),y.e--,V--),L>V&&Ve(y,V,e.RM,E[0]!==ue),y},F.eq=function(n){return this.cmp(n)===0},F.gt=function(n){return this.cmp(n)>0},F.gte=function(n){return this.cmp(n)>-1},F.lt=function(n){return this.cmp(n)<0},F.lte=function(n){return this.cmp(n)<1},F.minus=F.sub=function(n){var r,e,t,s,i=this,a=i.constructor,u=i.s,o=(n=new a(n)).s;if(u!=o)return n.s=-o,i.plus(n);var l=i.c.slice(),f=i.e,m=n.c,g=n.e;if(!l[0]||!m[0])return m[0]?n.s=-o:l[0]?n=new a(i):n.s=1,n;if(u=f-g){for((s=u<0)?(u=-u,t=l):(g=f,t=m),t.reverse(),o=u;o--;)t.push(0);t.reverse()}else for(e=((s=l.length<m.length)?l:m).length,u=o=0;o<e;o++)if(l[o]!=m[o]){s=l[o]<m[o];break}if(s&&(t=l,l=m,m=t,n.s=-n.s),(o=(e=m.length)-(r=l.length))>0)for(;o--;)l[r++]=0;for(o=r;e>u;){if(l[--e]<m[e]){for(r=e;r&&!l[--r];)l[r]=9;--l[r],l[e]+=10}l[e]-=m[e]}for(;l[--o]===0;)l.pop();for(;l[0]===0;)l.shift(),--g;return l[0]||(n.s=1,l=[g=0]),n.c=l,n.e=g,n},F.mod=function(n){var r,e=this,t=e.constructor,s=e.s,i=(n=new t(n)).s;if(!n.c[0])throw Error(Yr);return e.s=n.s=1,r=n.cmp(e)==1,e.s=s,n.s=i,r?new t(e):(s=t.DP,i=t.RM,t.DP=t.RM=0,e=e.div(n),t.DP=s,t.RM=i,this.minus(e.times(n)))},F.neg=function(){var n=new this.constructor(this);return n.s=-n.s,n},F.plus=F.add=function(n){var r,e,t,s=this,i=s.constructor;if(n=new i(n),s.s!=n.s)return n.s=-n.s,s.minus(n);var a=s.e,u=s.c,o=n.e,l=n.c;if(!u[0]||!l[0])return l[0]||(u[0]?n=new i(s):n.s=s.s),n;if(u=u.slice(),r=a-o){for(r>0?(o=a,t=l):(r=-r,t=u),t.reverse();r--;)t.push(0);t.reverse()}for(u.length-l.length<0&&(t=l,l=u,u=t),r=l.length,e=0;r;u[r]%=10)e=(u[--r]=u[r]+l[r]+e)/10|0;for(e&&(u.unshift(e),++o),r=u.length;u[--r]===0;)u.pop();return n.c=u,n.e=o,n},F.pow=function(n){var r=this,e=new r.constructor("1"),t=e,s=n<0;if(n!==~~n||n<-Qr||n>Qr)throw Error(Pe+"exponent");for(s&&(n=-n);n&1&&(t=t.times(r)),n>>=1,!!n;)r=r.times(r);return s?e.div(t):t},F.prec=function(n,r){if(n!==~~n||n<1||n>Ae)throw Error(Pe+"precision");return Ve(new this.constructor(this),n,r)},F.round=function(n,r){if(n===ue)n=0;else if(n!==~~n||n<-Ae||n>Ae)throw Error(ft);return Ve(new this.constructor(this),n+this.e+1,r)},F.sqrt=function(){var n,r,e,t=this,s=t.constructor,i=t.s,a=t.e,u=new s("0.5");if(!t.c[0])return new s(t);if(i<0)throw Error(ze+"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),n=new s((i==1/0?"5e":(i=i.toExponential()).slice(0,i.indexOf("e")+1))+a)):n=new s(i+""),a=n.e+(s.DP+=4);do e=n,n=u.times(e.plus(t.div(e)));while(e.c.slice(0,a).join("")!==n.c.slice(0,a).join(""));return Ve(n,(s.DP-=4)+n.e+1,s.RM)},F.times=F.mul=function(n){var r,e=this,t=e.constructor,s=e.c,i=(n=new t(n)).c,a=s.length,u=i.length,o=e.e,l=n.e;if(n.s=e.s==n.s?1:-1,!s[0]||!i[0])return n.c=[n.e=0],n;for(n.e=o+l,a<u&&(r=s,s=i,i=r,l=a,a=u,u=l),r=new Array(l=a+u);l--;)r[l]=0;for(o=u;o--;){for(u=0,l=a+o;l>o;)u=r[l]+i[o]*s[l-o-1]+u,r[l--]=u%10,u=u/10|0;r[l]=u}for(u?++n.e:r.shift(),o=r.length;!r[--o];)r.pop();return n.c=r,n},F.toExponential=function(n,r){var e=this,t=e.c[0];if(n!==ue){if(n!==~~n||n<0||n>Ae)throw Error(ft);for(e=Ve(new e.constructor(e),++n,r);e.c.length<n;)e.c.push(0)}return $e(e,!0,!!t)},F.toFixed=function(n,r){var e=this,t=e.c[0];if(n!==ue){if(n!==~~n||n<0||n>Ae)throw Error(ft);for(e=Ve(new e.constructor(e),n+e.e+1,r),n=n+e.e+1;e.c.length<n;)e.c.push(0)}return $e(e,!1,!!t)},F[Symbol.for("nodejs.util.inspect.custom")]=F.toJSON=F.toString=function(){var n=this,r=n.constructor;return $e(n,n.e<=r.NE||n.e>=r.PE,!!n.c[0])},F.toNumber=function(){var n=Number($e(this,!0,!0));if(this.constructor.strict===!0&&!this.eq(n.toString()))throw Error(ze+"Imprecise conversion");return n},F.toPrecision=function(n,r){var e=this,t=e.constructor,s=e.c[0];if(n!==ue){if(n!==~~n||n<1||n>Ae)throw Error(Pe+"precision");for(e=Ve(new t(e),n,r);e.c.length<n;)e.c.push(0)}return $e(e,n<=e.e||e.e<=t.NE||e.e>=t.PE,!!s)},F.valueOf=function(){var n=this,r=n.constructor;if(r.strict===!0)throw Error(ze+"valueOf disallowed");return $e(n,n.e<=r.NE||n.e>=r.PE,!0)};var j=Hr();function jr(n){let r;switch(n){case S.EQUALS:r=S.EQUALS;break;case S.GREATER_THAN:r=S.LESS_THAN;break;case S.GREATER_THAN_OR_EQUAL:r=S.LESS_THAN_OR_EQUAL;break;case S.LESS_THAN:r=S.GREATER_THAN;break;case S.LESS_THAN_OR_EQUAL:r=S.GREATER_THAN_OR_EQUAL;break;case S.NOT_EQUAL:r=S.NOT_EQUAL;break}return r}function er(n,r){return j(n).times(r).toNumber()}function Wr(n,r){const e=10**Math.floor(r);return Math.round(er(n,e))/e}function Xr(n,r){const e=10**Math.floor(r);return Math.floor(er(n,e))/e}function Gr(n,r){const e=10**Math.floor(r);return Math.ceil(er(n,e))/e}function Kr(n,r){const e=new j(n),t=new j(r),s=Math.floor(n/r);return e.minus(t.times(s)).toNumber()}function zr(n,r){return n**r}class re extends Re{isNull(){return!0}plus(r){return new w(0,!0).plus(r)}minus(r){return new w(0,!0).minus(r)}multiply(r){return new w(0,!0).multiply(r)}divided(r){return new w(0,!0).divided(r)}mod(r){return new w(0,!0).mod(r)}compare(r,e){return r.isString()?new X("").compare(r,e):r.isBoolean()?new P(!1).compare(r,e):new w(0,!0).compare(r,e)}concatenateFront(r){return r.isArray()?r.concatenateBack(new X("")):new X(this.concatenate(r.getValue(),ne.FRONT))}concatenateBack(r){return r.isArray()?r.concatenateFront(new X("")):new X(this.concatenate(r.getValue(),ne.BACK))}plusBy(r){return new w(0).plusBy(r)}minusBy(r){return new w(0).minusBy(r)}multiplyBy(r){return new w(0).multiplyBy(r)}dividedBy(r){return new w(0).dividedBy(r)}compareBy(r,e){return typeof r=="string"?new X("").compareBy(r,e):typeof r=="boolean"?new P(!1).compareBy(r,e):new w(0,!0).compareBy(r,e)}pow(r){return new w(0,!0).pow(r)}sqrt(){return new w(0,!0).sqrt()}cbrt(){return new w(0,!0).cbrt()}cos(){return new w(0,!0).cos()}acos(){return new w(0,!0).acos()}acosh(){return new w(0,!0).acosh()}sin(){return new w(0,!0).sin()}asin(){return new w(0,!0).asin()}asinh(){return new w(0,!0).asinh()}tan(){return new w(0,!0).tan()}tanh(){return new w(0,!0).tanh()}atan(){return new w(0,!0).atan()}atan2(r){return new w(0,!0).atan2(r)}atanh(){return new w(0,!0).atanh()}log(){return new h(c.NUM)}log10(){return new h(c.NUM)}exp(){return new w(0,!0).exp()}abs(){return new w(0,!0).abs()}round(r){return new w(0,!0).round(r)}floor(r){return new w(0,!0).floor(r)}ceil(r){return new w(0,!0).ceil(r)}}class P extends Re{constructor(e,t=!1){super(e);p(this,"_value",!1);if(t){this._value=e;return}if(typeof e=="boolean")this._value=e;else if(typeof e=="string"){const s=e.toLocaleUpperCase();s===Se.TRUE?this._value=!0:s===Se.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 w(-t,!0)}getReciprocal(){return this.getValue()?new w(1,!0):new h(c.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)}mod(e){return this._convertTonNumber().mod(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 w(t,!0)}pow(e){return this._convertTonNumber().pow(e)}sqrt(){return this._convertTonNumber().sqrt()}cbrt(){return this._convertTonNumber().cbrt()}cos(){return this._convertTonNumber().cos()}acos(){return this._convertTonNumber().acos()}acosh(){return this._convertTonNumber().acosh()}sin(){return this._convertTonNumber().sin()}asin(){return this._convertTonNumber().asin()}asinh(){return this._convertTonNumber().asinh()}tan(){return this._convertTonNumber().tan()}tanh(){return this._convertTonNumber().tanh()}atan(){return this._convertTonNumber().atan()}atan2(e){return this._convertTonNumber().atan2(e)}atanh(){return this._convertTonNumber().atanh()}log(){return this._convertTonNumber().log()}log10(){return this._convertTonNumber().log10()}exp(){return this._convertTonNumber().exp()}abs(){return this._convertTonNumber().abs()}round(e){return this._convertTonNumber().round(e)}floor(e){return this._convertTonNumber().floor(e)}ceil(e){return this._convertTonNumber().ceil(e)}}class w extends Re{constructor(e,t=!1){super(e);p(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 w(0).minus(this)}getReciprocal(){return new w(1).divided(this)}plus(e){if(e.isArray())return e.plus(this);const t=this.plusBy(e.getValue());return t.isError()||t.setPattern(this.getPattern()||e.getPattern()),t}equalZero(){return this._value===0}minus(e){if(e.isArray()){const s=e.getNegative();return s.isError()?s:s.plus(this)}const t=this.minusBy(e.getValue());return t.isError()?this:(t.setPattern(this.getPattern()||e.getPattern()),t)}multiply(e){if(e.isArray())return e.multiply(this);const t=this.multiplyBy(e.getValue());return t.setPattern(this.getPattern()||e.getPattern()),t}divided(e){if(e.isArray()){const s=e.getReciprocal();return s.isError()?s:s.multiply(this)}const t=this.dividedBy(e.getValue());return t.setPattern(this.getPattern()||e.getPattern()),t}mod(e){if(e.isArray())return e.modInverse(this);const t=this.getValue(),s=e.getValue();if(e.isNull())return new h(c.DIV_BY_ZERO);if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(s===0)return new h(c.DIV_BY_ZERO);if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=Kr(t,s);return Number.isFinite(i)?new w(i):new h(c.NUM)}if(typeof s=="boolean"){const i=s?1:0;return i===0?new h(c.DIV_BY_ZERO):new w(Kr(t,i))}return this}concatenateFront(e){return e.isArray()?e.concatenateBack(this):new X(this.concatenate(e.getValue(),ne.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new X(this.concatenate(e.getValue(),ne.BACK))}compare(e,t){return e.isArray()?e.compare(this,jr(t)):this.compareBy(e.getValue(),t)}plusBy(e){const t=this.getValue();if(typeof e=="string")return je.has(e)?new h(e):new h(c.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return new h(c.NUM);const s=j(t).plus(e).toNumber();return Number.isFinite(s)?new w(s):new h(c.NUM)}return typeof e=="boolean"?new w(j(t).plus(e?1:0).toNumber()):this}minusBy(e){const t=this.getValue();if(typeof e=="string")return new h(c.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return new h(c.NUM);const s=j(t).minus(e).toNumber();return Number.isFinite(s)?new w(s):new h(c.NUM)}return typeof e=="boolean"?new w(j(t).minus(e?1:0).toNumber()):this}multiplyBy(e){const t=this.getValue();if(typeof e=="string")return new h(c.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return new h(c.NUM);const s=j(t).times(e).toNumber();return Number.isFinite(s)?new w(s):new h(c.NUM)}return typeof e=="boolean"?new w(j(t).times(e?1:0).toNumber()):this}dividedBy(e){const t=this.getValue();if(typeof e=="string")return new h(c.VALUE);if(typeof e=="number"){if(e===0)return new h(c.DIV_BY_ZERO);if(!Number.isFinite(t)||!Number.isFinite(e))return new h(c.NUM);const s=j(t).div(e).toNumber();return Number.isFinite(s)?new w(s):new h(c.NUM)}return typeof e=="boolean"?e===!1?new h(c.DIV_BY_ZERO):new w(j(t).div(1).toNumber()):this}compareBy(e,t){const s=this.getValue();let i=!1;if(typeof e=="string")switch(t){case S.EQUALS:case S.GREATER_THAN:case S.GREATER_THAN_OR_EQUAL:i=!1;break;case S.LESS_THAN:case S.LESS_THAN_OR_EQUAL:case S.NOT_EQUAL:i=!0;break}else if(typeof e=="number")if(!Number.isFinite(s)||!Number.isFinite(e))i=this._compareInfinity(s,e,t);else switch(t){case S.EQUALS:i=j(s).eq(e);break;case S.GREATER_THAN:i=j(s).gt(e);break;case S.GREATER_THAN_OR_EQUAL:i=j(s).gte(e);break;case S.LESS_THAN:i=j(s).lt(e);break;case S.LESS_THAN_OR_EQUAL:i=j(s).lte(e);break;case S.NOT_EQUAL:i=!j(s).eq(e);break}else if(typeof e=="boolean")switch(t){case S.EQUALS:case S.GREATER_THAN:case S.GREATER_THAN_OR_EQUAL:i=!1;break;case S.LESS_THAN:case S.LESS_THAN_OR_EQUAL:case S.NOT_EQUAL:i=!0;break}return new P(i)}pow(e){if(e.isArray())return e.powInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=zr(t,s);return Number.isFinite(i)?new w(i):new h(c.NUM)}return typeof s=="boolean"?new w(zr(t,s?1:0)):this}sqrt(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=j(e).sqrt().toNumber();return Number.isFinite(t)?new w(t):new h(c.NUM)}cbrt(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.cbrt(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}cos(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.cos(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}acos(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.acos(e);return Number.isNaN(t)?new h(c.NUM):new w(t)}acosh(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.acosh(e);return Number.isNaN(t)?new h(c.NUM):new w(t)}sin(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.sin(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}asin(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.asin(e);return Number.isNaN(t)?new h(c.NUM):new w(t)}asinh(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.asinh(e);return Number.isNaN(t)?new h(c.NUM):new w(t)}tan(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.tan(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}tanh(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.tanh(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}atan(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.atan(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}atan2(e){if(e.isArray())return e.atan2Inverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=Math.atan2(t,s);return Number.isFinite(i)?new w(i):new h(c.NUM)}return typeof s=="boolean"?new w(Math.atan2(t,s?1:0)):this}atanh(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.atanh(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}log(){const e=this.getValue();if(typeof e=="number"&&e<=0)return new h(c.NUM);if(!Number.isFinite(e))return new h(c.NUM);const t=Math.log(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}log10(){const e=this.getValue();if(typeof e=="number"&&e<=0)return new h(c.NUM);if(!Number.isFinite(e))return new h(c.NUM);const t=Math.log10(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}exp(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.exp(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}abs(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.abs(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}round(e){if(e.isArray())return e.roundInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=Wr(t,s);return Number.isFinite(i)?new w(i):new h(c.NUM)}return typeof s=="boolean"?new w(Wr(t,s?1:0)):this}floor(e){if(e.isArray())return e.floorInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=Xr(t,s);return Number.isFinite(i)?new w(i):new h(c.NUM)}return typeof s=="boolean"?new w(Xr(t,s?1:0)):this}ceil(e){if(e.isArray())return e.ceilInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=Gr(t,s);return Number.isFinite(i)?new w(i):new h(c.NUM)}return typeof s=="boolean"?new w(Gr(t,s?1:0)):this}_compareInfinity(e,t,s){let i=!1;switch(s){case S.EQUALS:i=e===t;break;case S.GREATER_THAN:i=e>t;break;case S.GREATER_THAN_OR_EQUAL:i=e>=t;break;case S.LESS_THAN:i=e<t;break;case S.LESS_THAN_OR_EQUAL:i=e<=t;break;case S.NOT_EQUAL:i=e!==t;break}return i}}class X extends Re{constructor(e,t=!1){super(e);p(this,"_value");if(t){this._value=e;return}let s=e.toString();s.charAt(0)==='"'&&s.charAt(s.length-1)==='"'&&(s=s.slice(1,-1),s=s.replace(/""/g,'"')),this._value=s}getValue(){return this._value}isString(){return!0}concatenateFront(e){return e.isArray()?e.concatenateBack(this):new X(this.concatenate(e.getValue(),ne.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new X(this.concatenate(e.getValue(),ne.BACK))}compare(e,t){return e.isArray()?e.compare(this,jr(t)):this.compareBy(e.getValue(),t)}compareBy(e,t){const s=this.getValue();let i=!1;if(typeof e=="string"){if(ps(e))return this._checkWildcard(e,t);switch(t){case S.EQUALS:i=s===e;break;case S.GREATER_THAN:i=s>e;break;case S.GREATER_THAN_OR_EQUAL:i=s>=e;break;case S.LESS_THAN:i=s<e;break;case S.LESS_THAN_OR_EQUAL:i=s<=e;break;case S.NOT_EQUAL:i=s!==e;break}}else if(typeof e=="number")switch(t){case S.NOT_EQUAL:case S.GREATER_THAN:case S.GREATER_THAN_OR_EQUAL:i=!0;break;case S.EQUALS:case S.LESS_THAN:case S.LESS_THAN_OR_EQUAL:i=!1;break}else if(typeof e=="boolean")switch(t){case S.EQUALS:case S.GREATER_THAN:case S.GREATER_THAN_OR_EQUAL:i=!1;break;case S.LESS_THAN:case S.LESS_THAN_OR_EQUAL:case S.NOT_EQUAL:i=!0;break}return new P(i)}_checkWildcard(e,t){const s=this.getValue().toLocaleLowerCase(),i=Ds(s,e,t);return new P(i)}}function Bs(n){return""}function Us(n=[]){const r=[];for(let e=0;e<n.length;e++){const t=n[e];r[e]==null&&(r[e]=[]);for(let s=0;s<t.length;s++){const i=t[s];r[e][s]=Ce.create(i)}}return r}function Os(n=[]){const r=[];for(let e=0;e<n.length;e++){const t=n[e];r[e]==null&&(r[e]=[]);for(let s=0;s<t.length;s++){const i=t[s];i.isError()?r[e][s]=i.getErrorType():r[e][s]=i.getValue()}}return r}class J extends Re{constructor(e){super(typeof e=="string"?e:Bs());p(this,"_values",[]);p(this,"_rowCount",-1);p(this,"_columnCount",-1);p(this,"_unitId","");p(this,"_sheetId","");p(this,"_currentRow",-1);p(this,"_currentColumn",-1);p(this,"_sliceCache",new Map);p(this,"_flattenCache");p(this,"_flattenPosition");this._values=this._formatValue(e)}dispose(){this._values.forEach(e=>{e.forEach(t=>{t.dispose()})}),this._values=[],this._clearCache()}clone(){return this.map(e=>e)}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._values}setArrayValue(e){this._clearCache(),this._values=e}isArray(){return!0}get(e,t){const s=this._values[e];if(s==null)return new re(0);const i=s[t];return i==null?new re(0):i}getRealValue(e,t){const s=this._values[e];if(s==null)return null;const i=s[t];return i==null?null:i}set(e,t,s){if(e>=this._rowCount||t>=this._columnCount)throw new Error("Exceeding array bounds.");this._clearCache(),this._values[e][t]=s}getRangePosition(){const t=this.getRowCount(),s=0,i=this.getColumnCount();return{startRow:0,endRow:t-1,startColumn:s,endColumn:i-1}}iterator(e){const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),u=this.getArrayValue();for(let o=t;o<=s;o++)for(let l=i;l<=a;l++)if(e(u[o][l],o,l)===!1)return}iteratorReverse(e){const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),u=this.getArrayValue();for(let o=s;o>=t;o--)for(let l=a;l>=i;l--)if(e(u[o][l],o,l)===!1)return}getLastTruePosition(){let e;return this.iteratorReverse((t,s,i)=>{if(t!=null&&t.isBoolean()&&t.getValue()===!0)return e={row:s,column:i},!1}),e}getFirstTruePosition(){let e;return this.iterator((t,s,i)=>{if(t!=null&&t.isBoolean()&&t.getValue()===!0)return e={row:s,column:i},!1}),e}getFirstCell(){const{startRow:e,startColumn:t}=this.getRangePosition();return this.get(e,t)}getLastCell(){const{endRow:e,endColumn:t}=this.getRangePosition();return this.get(e,t)}pick(e){const t=e.getRowCount(),s=e.getColumnCount();if(t!==this._rowCount||s!==this._columnCount)return this._createNewArray([[new re(0)]],1,1);const i=[];i[0]=[];for(let a=0;a<t;a++)for(let u=0;u<s;u++){const o=e.get(a,u),l=this.get(a,u);o.isError()||o.getValue()===!0&&i[0].push(l)}return this._createNewArray(i,1,i[0].length)}flatten(){if(this._flattenCache!=null)return this._flattenCache;const e=[];e[0]=[];for(let s=0;s<this._rowCount;s++)for(let i=0;i<this._columnCount;i++){const a=this.get(s,i);e[0].push(a)}const t=this._createNewArray(e,1,e[0].length);return this._flattenCache=t,t}flattenPosition(){if(this._flattenPosition!=null)return this._flattenPosition;const e=[],t=[],s=[],i=[];let a=0;for(let o=0;o<this._rowCount;o++)for(let l=0;l<this._columnCount;l++){const f=this.get(o,l);if(f.isError()||f.isNull()){a++;continue}f.isString()?(e.push(f),s.push(a++)):(t.push(f),i.push(a++))}const u={stringArray:e,numberArray:t,stringPosition:s,numberPosition:i};return this._flattenPosition=u,u}slice(e,t){let s=0,i=this._rowCount,a=1,u=0,o=this._columnCount,l=1;if(e!=null&&(s=e[0]||0,i=e[1]||this._rowCount,a=e[2]||1),t!=null&&(u=t[0]||0,o=t[1]||this._columnCount,l=t[2]||1),s>=this._rowCount||u>=this._columnCount)return;const f=`${s}_${i}_${a}_${u}_${o}_${l}`,m=this._sliceCache.get(f);if(m!=null)return m;const g=[],R=this._values;let _=0,E=0;for(let L=s;L<i;L+=a){E=0,g[_]==null&&(g[_]=[]);for(let V=u;V<o;V+=l)g[_][E]=R[L][V],E++;_++}if(g.length===0||g[0].length===0)return;const C=a>1?-1:s+this._currentRow,y=l>1?-1:u+this._currentColumn,b=this._createNewArray(g,g.length,g[0].length,C,y);return this._sliceCache.set(f,b),b}sortByRow(e){const t=this._transposeArray(this._values);t.sort(this._sort(e)),this._clearCache(),this._values=this._transposeArray(t)}sortByColumn(e){this._clearCache(),this._values.sort(this._sort(e))}transpose(){const e=this._transposeArray(this._values),t=this._rowCount,s=this._columnCount;return this._createNewArray(e,s,t)}orderSearch(e,t=Z.MIN,s=!1,i=!1){let a,u,o,l;const f=(m,g,R)=>{if(m==null)return!0;let _;if(i===!0?_=m.compare(e,S.EQUALS):_=m.isEqual(e),(_==null?void 0:_.getValue())===!0)return a=m,o={row:g,column:R},!1;t===Z.MAX?m.isGreaterThan(e).getValue()===!0&&(u==null||m.minus(e).abs().isLessThanOrEqual(u.minus(e).abs()).getValue()===!0)&&(u=m,l={row:g,column:R}):t===Z.MIN&&m.isLessThan(e).getValue()===!0&&(u==null||m.minus(e).abs().isLessThanOrEqual(u.minus(e).abs()).getValue()===!0)&&(u=m,l={row:g,column:R})};if(s){const m=this._values.length;if(this._values[0]==null)return;const g=this._values[0].length;for(let R=m-1;R>=0;R--)for(let _=g-1;_>=0;_--){const E=this._values[R][_];f(E,R,_)}}else this.iterator((m,g,R)=>{f(m,g,R)});if(a!=null)return o;if(u!=null)return l}binarySearch(e,t=de.MIN){if(e.isError())return;const{stringArray:s,stringPosition:i,numberArray:a,numberPosition:u}=this.flattenPosition();return e.isString()?this._binarySearch(e,s,i,t):this._binarySearch(e,a,u,t)}_binarySearch(e,t,s,i=de.MIN){const a=kr(),u=e.getValue().toString();let o=0,l=t.length-1,f=null;for(;o<=l;){const m=Math.floor((o+l)/2),g=t[m];let R=0;if(g.isNull())R=1;else{const _=g.getValue();R=a(_.toString(),u)}if(R===0)return s[m];R===-1?(o=m+1,i===de.MIN&&(f=m)):(l=m-1,i===de.MAX&&(f=m))}if(f!=null)return s[f]}sum(){let e=new w(0);return this.iterator(t=>{if(t==null||t.isString()||t.isBoolean()||t.isNull())return!0;if(t.isError())return e=t,!1;e=e.plus(t)}),e}max(){let e=new w(Number.NEGATIVE_INFINITY);return this.iterator(t=>{if(t==null)return!0;if(t.isError())return e=t,!1;if(t.isString()||t.isNull()||t.isBoolean())return!0;e.isLessThan(t).getValue()&&(e=t)}),e}min(){let e=new w(Number.POSITIVE_INFINITY);return this.iterator(t=>{if(t==null)return!0;if(t.isError())return e=t,!1;if(t.isString()||t.isNull()||t.isBoolean())return!0;e.isGreaterThan(t).getValue()&&(e=t)}),e}count(){let e=new w(0);return this.iterator(t=>{if(t==null||t.isError()||t.isString()||t.isNull()||t.isBoolean())return!0;e=e.plusBy(1)}),e}countA(){let e=new w(0);return this.iterator(t=>{if(t==null||t.isNull())return!0;e=e.plusBy(1)}),e}countBlank(){let e=new w(0);return this.iterator(t=>{if(t!=null&&!t.isNull())return!0;e=e.plusBy(1)}),e}getNegative(){return new J("{0}").minus(this)}getReciprocal(){return new J("{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)}mod(e){return this._batchOperator(e,4)}modInverse(e){return this.map(t=>t.isError()?t:e.mod(t))}compare(e,t){return this._batchOperator(e,5,t)}concatenateFront(e){return this._batchOperator(e,6)}concatenateBack(e){return this._batchOperator(e,7)}product(e,t){return this._batchOperator(e,8,t)}map(e){const t=(s,i,a)=>s.isError()?s:e(s,i,a);return this.mapValue(t)}mapValue(e){var a,u;const t=this._rowCount,s=this._columnCount,i=[];for(let o=0;o<t;o++){const l=[];for(let f=0;f<s;f++){const m=(u=(a=this._values)==null?void 0:a[o])==null?void 0:u[f];m?l[f]=e(m,o,f):l[f]=new h(c.VALUE)}i.push(l)}return this._createNewArray(i,t,s)}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(e=0){const t=this.sum(),s=this.count();return t.divided(e===0?s:s.minusBy(1))}median(){const e=this.flattenPosition().numberArray,t=this._createNewArray([e],1,e.length),s=t.getColumnCount();if(s<=1)return t.get(0,0);if(t.sortByRow(0),s%2===0){const i=t.get(0,s/2),a=t.get(0,s/2-1);return i.plus(a).divided(new w(2,!0))}return t.get(0,(s-1)/2)}var(e=0){const t=this.mean(),s=[[]];this.iterator(f=>{if(f==null||f.isError()||f.isString()||f.isBoolean()||f.isNull())return;const m=f.minus(t).pow(new w(2,!0));m.isError()||s[0].push(m)});const{_unitId:i,_sheetId:a,_currentRow:u,_currentColumn:o}=this;return new J({calculateValueList:s,rowCount:1,columnCount:s[0].length,unitId:i,sheetId:a,row:u,column:o}).mean(e)}std(e=0){const t=this.var(e);return t.isError()?t:t.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 Os(this._values)}_clearCache(){this._flattenCache=null,this._sliceCache.clear()}_sort(e){const t=kr();return(s,i)=>{const a=s[e],u=i[e];return a.isError()&&a.isError()?0:a.isError()?1:u.isError()?-1:t(a.getValue(),u.getValue())}}_transposeArray(e){const t=e.length,s=e[0].length,i=[];for(let a=0;a<s;a++){i[a]=[];for(let u=0;u<t;u++)i[a][u]=e[u][a]}return i}_batchOperator(e,t,s){const i=[];let a=this._rowCount,u=this._columnCount;if(e.isArray()){const l=e.getRowCount(),f=e.getColumnCount();if(a=Math.max(l,a),u=Math.max(f,u),l===1&&f===1){const m=e.getFirstCell();for(let g=0;g<u;g++)i.push(m)}else if(l===1&&this._columnCount>1){const m=e.getArrayValue();for(let g=0;g<u;g++)i.push(m[0][g])}else return this._batchOperatorArray(e,t,s)}else for(let l=0;l<u;l++)i.push(e);const o=[];for(let l=0;l<u;l++){const f=i[l];this._batchOperatorValue(f,l,o,t,s)}return this._createNewArray(o,a,u)}_batchOperatorValue(e,t,s,i,a){var R,_;const u=this._rowCount;let o=!1;const l=this.getUnitId(),f=this.getSheetId(),m=this.getCurrentRow(),g=this.getCurrentColumn();if(i===5&&(o=we.canUseCache(l,f,t+g,m,m+u-1),o===!0)){if(a===S.EQUALS){const E=we.getCellPositions(l,f,t+g,e.getValue());for(let C=0;C<u;C++)s[C]==null&&(s[C]=[]),E!=null&&E.includes(C+m)?s[C][t]=new P(!0):s[C][t]=new P(!1)}else{const E=we.getCellValuePositions(l,f,t+g);if(E!=null){E.forEach((C,y)=>{let b=new re(0);typeof y=="string"?b=new X(y):typeof y=="number"?b=new w(y):typeof y=="boolean"&&(b=new P(y)),b.compare(e,a).getValue()===!0&&C.forEach(V=>{V>=m&&V<=m+u-1&&(s[V-m]==null&&(s[V-m]=[]),s[V-m][t]=new P(!0))})});for(let C=0;C<u;C++)s[C]==null&&(s[C]=[]),s[C][t]==null&&(s[C][t]=new P(!1))}else for(let C=0;C<u;C++)s[C]==null&&(s[C]=[]),s[C][t]=new P(!1)}return}for(let E=0;E<u;E++){const C=(_=(R=this._values)==null?void 0:R[E])==null?void 0:_[t];if(s[E]==null&&(s[E]=[]),C&&e)if(C.isError())s[E][t]=C;else if(e.isError())s[E][t]=e;else switch(i){case 1:s[E][t]=C.plus(e);break;case 0:s[E][t]=C.minus(e);break;case 2:s[E][t]=C.multiply(e);break;case 3:s[E][t]=C.divided(e);break;case 4:s[E][t]=C.mod(e);break;case 5:a?s[E][t]=C.compare(e,a):s[E][t]=new h(c.VALUE);break;case 6:s[E][t]=C.concatenateFront(e);break;case 7:s[E][t]=C.concatenateBack(e);break;case 8:a?s[E][t]=C.product(e,a):s[E][t]=new h(c.VALUE);break;case 9:s[E][t]=C.pow(e);break;case 10:s[E][t]=C.round(e);break;case 11:s[E][t]=C.floor(e);break;case 13:s[E][t]=C.atan2(e);break;case 12:s[E][t]=C.ceil(e);break}else s[E][t]=new h(c.NA);C!=null&&(C.isError()?we.set(l,f,t+g,C.getErrorType(),E+m):C.isNull()?we.set(l,f,t+g,null,E+m):we.set(l,f,t+g,C.getValue(),E+m))}we.setContinueBuildingCache(l,f,t+g,m,m+u-1)}_batchOperatorArray(e,t,s){var m,g,R,_,E,C,y,b,L,V,T,Q;let i=e.getRowCount(),a=e.getColumnCount();i<this._rowCount&&(i=this._rowCount),a<this._columnCount&&(a=this._columnCount);const u=[],o=e.getArrayValue(),l=this._checkArrayCalculateType(this),f=this._checkArrayCalculateType(e);for(let I=0;I<i;I++){const x=[];for(let v=0;v<a;v++){let $;l===3?$=(g=(m=this._values)==null?void 0:m[0])==null?void 0:g[0]:l===1?$=(_=(R=this._values)==null?void 0:R[0])==null?void 0:_[v]:l===2?$=(C=(E=this._values)==null?void 0:E[I])==null?void 0:C[0]:$=(b=(y=this._values)==null?void 0:y[I])==null?void 0:b[v];let k;if(f===3?k=(L=o==null?void 0:o[0])==null?void 0:L[0]:f===1?k=(V=o==null?void 0:o[0])==null?void 0:V[v]:f===2?k=(T=o==null?void 0:o[I])==null?void 0:T[0]:k=(Q=o==null?void 0:o[I])==null?void 0:Q[v],$&&k)if($.isError())x[v]=$;else if(k.isError())x[v]=k;else switch(t){case 1:x[v]=$.plus(k);break;case 0:x[v]=$.minus(k);break;case 2:x[v]=$.multiply(k);break;case 3:x[v]=$.divided(k);break;case 4:x[v]=$.mod(k);break;case 5:s?x[v]=$.compare(k,s):x[v]=new h(c.VALUE);break;case 6:x[v]=$.concatenateFront(k);break;case 7:x[v]=$.concatenateBack(k);break;case 8:s?x[v]=$.product(k,s):x[v]=new h(c.VALUE);break;case 9:x[v]=$.pow(k);break;case 10:x[v]=$.round(k);break;case 13:x[v]=$.atan2(k);break;case 11:x[v]=$.floor(k);break;case 12:x[v]=$.ceil(k);break}else x[v]=new h(c.NA)}u.push(x)}return this._createNewArray(u,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(";"),s=t.length,i=[];let a=0;for(let u=0;u<s;u++){const l=t[u].split(","),f=l.length;a<f&&(a=f);const m=[];for(let g=0;g<f;g++){const R=l[g].trim();m.push(Ce.create(R))}i.push(m)}return this._rowCount=s,this._columnCount=a,i}_createNewArray(e,t,s,i=-1,a=-1){(this._currentColumn===-1||this._currentRow===-1)&&(i=-1,a=-1);const u={calculateValueList:e,rowCount:t,columnCount:s,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:i,column:a};return new J(u)}}class Ce{static create(r){if(r==null)return new re(0);if(typeof r=="boolean")return new P(r,!0);if(typeof r=="string"){const e=r.toLocaleUpperCase().trim();return je.has(e)?new h(e):e===Se.TRUE||e===Se.FALSE?new P(e):d.isRealNum(r)?new w(r):new RegExp(us,"g").test(r.replace(/\n/g,"").replace(/\r/g,""))?new J(r.replace(/\n/g,"").replace(/\r/g,"")):new X(r)}return typeof r=="number"?Number.isFinite(r)?new w(r,!0):new h(c.NUM):new h(c.NA)}}function Ms(n){if(n===null)return 0;if(n!=null&&n.p){const r=n==null?void 0:n.p.body;if(r==null)return 0;const e=r.dataStream;return e.substring(e.length-2,e.length)===d.DEFAULT_EMPTY_DOCUMENT_VALUE?e.substring(0,e.length-2):e}return(n==null?void 0:n.v)||0}const Fs=1e5,tr=new rt(Fs);class ke extends ct{constructor(e){super();p(this,"_forcedSheetId","");p(this,"_forcedSheetName","");p(this,"_defaultSheetId","");p(this,"_rangeData",{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1});p(this,"_unitData",{});p(this,"_defaultUnitId","");p(this,"_forcedUnitId","");p(this,"_runtimeData",{});p(this,"_arrayFormulaCellData",{});p(this,"_runtimeArrayFormulaCellData",{});p(this,"_runtimeFeatureCellData",{});p(this,"_numfmtItemData",{});p(this,"_refOffsetX",0);p(this,"_refOffsetY",0);this._token=e}dispose(){this._unitData={},this._runtimeData={}}isExceedRange(){const{startRow:e,endRow:t,startColumn:s,endColumn:i}=this.getRangePosition();return e<0||s<0||t>=this.getRowCount()||i>=this.getColumnCount()}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+this._refOffsetY,t=this._rangeData.endRow+this._refOffsetY,s=this._rangeData.startColumn+this._refOffsetX,i=this._rangeData.endColumn+this._refOffsetX;return isNaN(e)&&(e=0),isNaN(s)&&(s=0),isNaN(t)&&(t=this.getRowCount()-1),isNaN(i)&&(i=this.getColumnCount()-1),{startRow:e,endRow:t,startColumn:s,endColumn:i}}isReferenceObject(){return!0}iterator(e){var l,f,m;const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition();if(this._checkIfWorksheetMiss())return e(new h(c.VALUE),t,i);const u=this._forcedUnitId||this._defaultUnitId,o=this._forcedSheetId||this._defaultSheetId;for(let g=t;g<=s;g++)for(let R=i;R<=a;R++){if(g<0||R<0)return e(new h(c.REF),g,R);const _=this.getCellData(g,R);let E=!1;if(_==null||d.isNullCell(_)){E=e(null,g,R);continue}const C=this.getCellValueObject(_),y=(m=(f=(l=this._numfmtItemData[u])==null?void 0:l[o])==null?void 0:f[g])==null?void 0:m[R];if(y&&C.setPattern(y),E=e(C,g,R),E===!1)return}}getFirstCell(){var l,f,m;const{startRow:e,startColumn:t}=this.getRangePosition(),s=this.getCellData(e,t);if(!s)return new w(0,!0);const i=this.getCellValueObject(s),a=this._forcedUnitId||this._defaultUnitId,u=this._forcedSheetId||this._defaultSheetId,o=(m=(f=(l=this._numfmtItemData[a])==null?void 0:l[u])==null?void 0:f[e])==null?void 0:m[t];return o&&i.setPattern(o),i}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}getNumfmtItemData(){return this._numfmtItemData}setNumfmtItemData(e){this._numfmtItemData=e}getRowCount(){return this.getCurrentActiveSheetData().rowCount}getColumnCount(){return this.getCurrentActiveSheetData().columnCount}getRowData(){return this.getCurrentActiveSheetData().rowData}getColumnData(){return this.getCurrentActiveSheetData().columnData}isCell(){return!1}isColumn(){return!1}isRow(){return!1}isRange(){return!1}isTable(){return!1}unionBy(e){return new h(c.REF)}unionRange(e,t){return{startRow:-1,startColumn:-1,endRow:-1,endColumn:-1}}getCellValueObject(e){const t=Ms(e);return je.has(t)?new h(t):e.t===d.CellValueType.NUMBER?new w(t):e.t===d.CellValueType.STRING||e.t===d.CellValueType.FORCE_STRING?new X(t):e.t===d.CellValueType.BOOLEAN?new P(t):Ce.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 s=this.getCurrentActiveSheetData(),i=this.getCurrentRuntimeSheetData(),a=this.getCurrentActiveArrayFormulaCellData(),u=this.getCurrentRuntimeActiveArrayFormulaCellData();return(i==null?void 0:i.getValue(e,t))||(u==null?void 0:u.getValue(e,t))||this.getRuntimeFeatureCellValue(e,t)||(a==null?void 0:a.getValue(e,t))||(s==null?void 0:s.cellData.getValue(e,t))}getRuntimeFeatureCellValue(e,t){var i;const s=Object.keys(this._runtimeFeatureCellData);for(const a of s){const u=this._runtimeFeatureCellData[a],o=(i=u==null?void 0:u[this.getUnitId()])==null?void 0:i[this.getSheetId()];if(o==null)continue;const l=o.getValue(e,t);if(l!=null)return l}}getCellByPosition(e,t){e||(e=this._rangeData.startRow),t||(t=this._rangeData.startColumn);const s=this.getCellData(e,t);return s?this.getCellValueObject(s):new h(c.VALUE)}toArrayValueObject(e=!0){var _;const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),u=`${this.getUnitId()}_${this.getSheetId()}_${t}_${s}_${i}_${a}`,o=tr.get(u);if(o&&e)return o;const l=s-t+1,f=a-i+1;if(l<0||f<0)return this._getBlankArrayValueObject();const m=new Array(l);this.iterator((E,C,y)=>{const b=C-t,L=y-i;m[b]||(m[b]=new Array(f)),E==null&&(E=new re(0)),m[b][L]=E});const g={calculateValueList:m,rowCount:m.length,columnCount:((_=m[0])==null?void 0:_.length)||0,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:t,column:i},R=new J(g);return e&&tr.set(u,R),R}toUnitRange(){return{range:this.getRangePosition(),sheetId:this.getSheetId(),unitId:this.getUnitId()}}_checkIfWorksheetMiss(){return(this._forcedSheetId==null||this._forcedSheetId.length===0)&&this._forcedSheetName.length>0}_getBlankArrayValueObject(){const e={calculateValueList:[],rowCount:0,columnCount:0,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:0,column:0};return new J(e)}}class $s extends ct{constructor(r){super(),this._promise=r}isAsyncObject(){return!0}async getValue(){return this._promise}}class ks extends ct{constructor(r){super(),this._promiseList=r}isAsyncArrayObject(){return!0}async getValue(){var t;const r=[];for(let s=0;s<this._promiseList.length;s++){const i=this._promiseList[s];r[s]==null&&(r[s]=[]);for(let a=0;a<i.length;a++){const u=i[a];u.isAsyncObject()?r[s][a]=await u.getValue():r[s][a]=u}}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 J(e)}}class qe extends ke{constructor(r,e,t){super(""),this.setRangeData(r),e&&this.setForcedSheetIdDirect(e),t&&this.setForcedUnitIdDirect(t)}isRange(){return!0}}const qr=/[\[\]]/g;function Zr(n,r){if(qr.test(n)){const e=Number(n.replace(qr,""));return r+e}return Number(n)-1}function rr(n,r=0,e=0){n=n.toLocaleUpperCase();const t=n.split(/[RC]/),s=t[1],i=t[2],a=Zr(s,r),u=Zr(i,e);return{row:a,column:u,absoluteRefType:d.AbsoluteRefType.NONE}}function Jr(n,r=0,e=0){const{refBody:t,sheetName:s,unitId:i}=vr(n),a=t.indexOf(":");if(a===-1){const E=rr(t,r,e),C=E.row,y=E.column,b=E.absoluteRefType;return{unitId:i,sheetName:s,range:{startRow:C,startColumn:y,endRow:C,endColumn:y,startAbsoluteRefType:b,endAbsoluteRefType:b}}}const u=t.substring(0,a),o=t.substring(a+1),l=rr(u,r,e),f=rr(o,r,e),m=l.row,g=l.column,R=f.row,_=f.column;return{unitId:i,sheetName:s,range:{startRow:m,startColumn:g,endRow:R,endColumn:_,startAbsoluteRefType:l.absoluteRefType,endAbsoluteRefType:f.absoluteRefType}}}function Ts(n){const r=ht(n.startRow,n.startAbsoluteRefType,!0),e=ht(n.startColumn,n.startAbsoluteRefType,!1),t=ht(n.endRow,n.endAbsoluteRefType,!0),s=ht(n.endColumn,n.endAbsoluteRefType,!1);return r===t&&e===s?`R${r}C${e}`:`R${r}C${e}:R${t}C${s}`}function ht(n,r=d.AbsoluteRefType.ALL,e){switch(n+=1,r){case d.AbsoluteRefType.ALL:return`${n}`;case d.AbsoluteRefType.ROW:return e?`${n}`:`[${n}]`;case d.AbsoluteRefType.COLUMN:return e?`[${n}]`:`${n}`;case d.AbsoluteRefType.NONE:return`[${n}]`}}const Nr=[];var Is=(n=>{})();function mt(n){const r=n.getValue();let e=0;return r&&(e=1),new w(e,!0)}function W(n,r,e,t){const s=[];if(e.isArray()){const i=e.getRowCount(),a=e.getColumnCount();if(i===1&&a===1){const u=e.getFirstCell();for(let o=0;o<n;o++){const l=[];for(let f=0;f<r;f++)l.push(u);s.push(l)}}else if(i===1&&a>1)for(let u=0;u<n;u++){const o=[];for(let l=0;l<r;l++){const f=e.getRealValue(0,l)||(t!=null?t:new re(0));o.push(f)}s.push(o)}else if(a===1&&i>1)for(let u=0;u<n;u++){const o=[];for(let l=0;l<r;l++){const f=e.getRealValue(u,0)||(t!=null?t:new re(0));o.push(f)}s.push(o)}else for(let u=0;u<n;u++){const o=[];for(let l=0;l<r;l++){const f=e.getRealValue(u,l)||(t!=null?t:new re(0));o.push(f)}s.push(o)}}else for(let i=0;i<n;i++){const a=[];for(let u=0;u<r;u++)a.push(e);s.push(a)}return gt(s,n,r)}function gt(n,r,e){const t={calculateValueList:n,rowCount:r,columnCount:e,unitId:"",sheetId:"",row:-1,column:-1};return new J(t)}class A extends d.Disposable{constructor(e){super();p(this,"_unitId");p(this,"_subUnitId");p(this,"_row",-1);p(this,"_column",-1);p(this,"needsExpandParams",!1);p(this,"needsReferenceObject",!1);this._name=e}get name(){return this._name}get unitId(){return this._unitId}get subUnitId(){return this._subUnitId}get row(){return this._row}get column(){return this._column}isAsync(){return!1}isAddress(){return!1}isCustom(){return!1}setRefInfo(e,t,s,i){this._unitId=e,this._subUnitId=t,this._row=s,this._column=i}calculateCustom(...e){return null}calculate(...e){return new h(c.VALUE)}checkArrayType(e){return e.isReferenceObject()||e.isValueObject()&&e.isArray()}getIndexNumValue(e,t=1){if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())return e.getValue()===!1?new h(c.VALUE):t;if(e.isString()){const s=Number(e.getValue());return isNaN(s)?new h(c.REF):s}else if(e.isNumber())return e.getValue();return new h(c.VALUE)}getZeroOrOneByOneDefault(e){if(e==null)return 1;let t=1;if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())e.getValue()===!1&&(t=0);else{if(e.isString())return;e.isNumber()&&e.getValue()===0&&(t=0)}return t}getMatchTypeValue(e){if(e==null)return 1;let t=1;if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())e.getValue()===!1&&(t=0);else{if(e.isString())return;if(e.isNumber()){const s=e.getValue();s<=0&&(t=s)}}return t}binarySearch(e,t,s,i){const a=t.binarySearch(e,i);if(a==null)return new h(c.NA);let u;return s.getRowCount()===1?u=s.get(0,a):u=s.get(a,0),u.isNull()?new h(c.NA):u}equalSearch(e,t,s,i=!0){const a=s.pick(t.isEqual(e));let u;return i?u=a.getFirstCell():u=a.getLastCell(),u.isNull()?new h(c.NA):u}fuzzySearch(e,t,s,i=!0){const a=s.pick(t.compare(e,S.EQUALS));let u;return i?u=a.getFirstCell():u=a.getLastCell(),u.isNull()?new h(c.NA):u}orderSearch(e,t,s,i=Z.MIN,a=!1){const u=t.orderSearch(e,i,a);if(u==null)return new h(c.NA);const o=s.get(u.row,u.column);return o.isNull()?new h(c.NA):o}binarySearchExpand(e,t,s,i=0,a){const u=t.binarySearch(e,a);return u==null?new h(c.NA):i===0?s.slice([u,u+1]):s.slice(void 0,[u,u+1])}equalSearchExpand(e,t,s,i=!0,a=0){const u=t.isEqual(e);let o;return i?o=u.getFirstTruePosition():o=u.getLastTruePosition(),o==null?new h(c.NA):a===0?s.slice([o.row,o.row+1]):s.slice(void 0,[o.column,o.column+1])}fuzzySearchExpand(e,t,s,i=!0,a=0){const u=t.compare(e,S.EQUALS);let o;return i?o=u.getFirstTruePosition():o=u.getLastTruePosition(),o==null?new h(c.NA):a===0?s.slice([o.row,o.row+1]):s.slice(void 0,[o.column,o.column+1])}orderSearchExpand(e,t,s,i=Z.MIN,a=!1,u=0){const o=t.orderSearch(e,i,a);return o==null?new h(c.NA):u===0?s.slice([o.row,o.row+1]):s.slice(void 0,[o.column,o.column+1])}flattenArray(e,t=!0){const s=[];s[0]=[];for(let i=0;i<e.length;i++){let a=e[i];if(a.isError())return a;if(a.isString()){const u=a.getValue();if(!d.isRealNum(u))return new h(c.VALUE);a=new w(u)}if(a.isBoolean()&&(a=mt(a)),a.isNull()&&(a=new w(0)),a.isArray()){let u;if(a.iterator(o=>{if(o==null||o.isNull()||t&&(o.isString()||o.isBoolean()))return!0;if(o=this._includingLogicalValuesAndText(o),o.isError())return u=o,!1;s[0].push(o)}),u!=null&&u.isError())return u}else s[0].push(a)}return gt(s,1,s[0].length)}_includingLogicalValuesAndText(e){if(e.isBoolean()&&(e=mt(e)),e.isString()){const t=Number(e.getValue());e=new w(isNaN(t)?0:t)}return e}}class en extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r);return e.isError()?e:e.std()}}class tn extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r);return e.isError()?e:e.std(1)}}class rn extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r);return e.isError()?e:e.var()}}class nn extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r);return e.isError()?e:e.var(1)}}var Te=(n=>(n.BETADIST="BETADIST",n.BETAINV="BETAINV",n.BINOMDIST="BINOMDIST",n.CHIDIST="CHIDIST",n.CHIINV="CHIINV",n.CHITEST="CHITEST",n.CONFIDENCE="CONFIDENCE",n.COVAR="COVAR",n.CRITBINOM="CRITBINOM",n.EXPONDIST="EXPONDIST",n.FDIST="FDIST",n.FINV="FINV",n.FTEST="FTEST",n.GAMMADIST="GAMMADIST",n.GAMMAINV="GAMMAINV",n.HYPGEOMDIST="HYPGEOMDIST",n.LOGINV="LOGINV",n.LOGNORMDIST="LOGNORMDIST",n.MODE="MODE",n.NEGBINOMDIST="NEGBINOMDIST",n.NORMDIST="NORMDIST",n.NORMINV="NORMINV",n.NORMSDIST="NORMSDIST",n.NORMSINV="NORMSINV",n.PERCENTILE="PERCENTILE",n.PERCENTRANK="PERCENTRANK",n.POISSON="POISSON",n.QUARTILE="QUARTILE",n.RANK="RANK",n.STDEV="STDEV",n.STDEVP="STDEVP",n.TDIST="TDIST",n.TINV="TINV",n.TTEST="TTEST",n.VAR="VAR",n.VARP="VARP",n.WEIBULL="WEIBULL",n.ZTEST="ZTEST",n))(Te||{});const sn=[[tn,Te.STDEV],[en,Te.STDEVP],[nn,Te.VAR],[rn,Te.VARP]],an=[];var un=(n=>(n.CUBEKPIMEMBER="CUBEKPIMEMBER",n.CUBEMEMBER="CUBEMEMBER",n.CUBEMEMBERPROPERTY="CUBEMEMBERPROPERTY",n.CUBERANKEDMEMBER="CUBERANKEDMEMBER",n.CUBESET="CUBESET",n.CUBESETCOUNT="CUBESETCOUNT",n.CUBEVALUE="CUBEVALUE",n))(un||{});const on=[];var ln=(n=>(n.DAVERAGE="DAVERAGE",n.DCOUNT="DCOUNT",n.DCOUNTA="DCOUNTA",n.DGET="DGET",n.DMAX="DMAX",n.DMIN="DMIN",n.DPRODUCT="DPRODUCT",n.DSTDEV="DSTDEV",n.DSTDEVP="DSTDEVP",n.DSUM="DSUM",n.DVAR="DVAR",n.DVARP="DVARP",n))(ln||{});const nr="yyyy-mm-dd;@";function sr(n){const r=new Date(Date.UTC(1900,0,1)),e=new Date(Date.UTC(1900,1,28)),t=Date.UTC(n.getFullYear(),n.getMonth(),n.getDate());let s=(t-r.getTime())/(1e3*3600*24);return t>e.getTime()&&(s+=1),Math.floor(s)+1}function dt(n){const r=new Date(Date.UTC(1900,0,1)),e=new Date(Date.UTC(1900,1,28));let t=Math.floor(n)-1;return t>(e.getTime()-r.getTime())/(1e3*3600*24)&&(t-=1),new Date(r.getTime()+t*(1e3*3600*24))}function ir(n){if(!/^\d{4}[-/](0?[1-9]|1[012])[-/](0?[1-9]|[12][0-9]|3[01])$/.test(n))return!1;const e=n.replace(/-/g,"/").replace(/T.+/,""),t=new Date(`${e}`);if(Number.isNaN(t.getTime()))return!1;const s=t.getFullYear(),i=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getDate().toString().padStart(2,"0"),u=`${s}-${i}-${a}`;return n.replace(/\//g,"-").split("-").map(l=>l.padStart(2,"0")).join("-")===u}class Qs extends A{calculate(r,e,t){if(r==null||e==null||t==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return e;if(t.isError())return t;const s=Math.max(r.isArray()?r.getRowCount():1,e.isArray()?e.getRowCount():1,t.isArray()?t.getRowCount():1),i=Math.max(r.isArray()?r.getColumnCount():1,e.isArray()?e.getColumnCount():1,t.isArray()?t.getColumnCount():1),a=W(s,i,r),u=W(s,i,e),o=W(s,i,t);return a.map((l,f,m)=>{const g=u.get(f,m),R=o.get(f,m);if(l.isError())return l;if(g.isError())return g;if(R.isError())return R;if(l.isString()||g.isString()||R.isString())return new h(c.VALUE);let _=+l.getValue();const E=Math.floor(+g.getValue()),C=+R.getValue();if(_<0||_>9999)return new h(c.NUM);_>=0&&_<1899&&(_+=1900);const y=new Date(_,E-1,C),b=sr(y);if(b<0)return new h(c.NUM);const L=new w(b);return L.setPattern(nr),L})}}class Ys extends A{calculate(r){return r==null?new h(c.NA):r.isArray()?r.map(e=>this._handleSingleObject(e)):this._handleSingleObject(r)}_handleSingleObject(r){if(r.isError())return r;let e;const t=r.getValue();if(r.isString()){if(!ir(`${t}`))return new h(c.VALUE);e=new Date(`${t}`)}else{const a=+r.getValue();if(a<0)return new h(c.NUM);if(a===0)return new w(0);e=dt(a)}const s=e.getDate();return new w(s)}}class Hs extends A{calculate(r,e){if(r==null||e==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return e;const t=Math.max(r.isArray()?r.getRowCount():1,e.isArray()?e.getRowCount():1),s=Math.max(r.isArray()?r.getColumnCount():1,e.isArray()?e.getColumnCount():1),i=W(t,s,r),a=W(t,s,e);return i.map((u,o,l)=>{const f=a.get(o,l);if(u.isError())return u;if(f.isError())return f;if(u.isString()||u.isBoolean()||f.isString()||f.isBoolean())return new h(c.VALUE);const m=+u.getValue();if(m<0)return new h(c.NUM);const g=Math.floor(+f.getValue()),R=dt(m),_=R.getUTCFullYear(),E=R.getUTCMonth()+g,C=R.getUTCDate(),y=new Date(Date.UTC(_,E,C)),b=sr(y),L=new w(b);return L.setPattern(nr),L})}}var pe=(n=>(n.DATE="DATE",n.DATEDIF="DATEDIF",n.DATEVALUE="DATEVALUE",n.DAY="DAY",n.DAYS="DAYS",n.DAYS360="DAYS360",n.EDATE="EDATE",n.EOMONTH="EOMONTH",n.HOUR="HOUR",n.ISOWEEKNUM="ISOWEEKNUM",n.MINUTE="MINUTE",n.MONTH="MONTH",n.NETWORKDAYS="NETWORKDAYS",n.NETWORKDAYS_INTL="NETWORKDAYS.INTL",n.NOW="NOW",n.SECOND="SECOND",n.TIME="TIME",n.TIMEVALUE="TIMEVALUE",n.TODAY="TODAY",n.WEEKDAY="WEEKDAY",n.WEEKNUM="WEEKNUM",n.WORKDAY="WORKDAY",n.WORKDAY_INTL="WORKDAY.INTL",n.YEAR="YEAR",n.YEARFRAC="YEARFRAC",n))(pe||{});class js extends A{calculate(r){return r==null?new h(c.NA):r.isArray()?r.map(e=>this._handleSingleObject(e)):this._handleSingleObject(r)}_handleSingleObject(r){if(r.isError())return r;let e;const t=r.getValue();if(r.isString()){if(!ir(`${t}`))return new h(c.VALUE);e=new Date(`${t}`)}else{const a=+r.getValue();if(a<0)return new h(c.NUM);if(a===0)return new w(1);e=dt(a)}const s=e.getUTCMonth()+1;return new w(s)}}class Ws extends A{calculate(r){if(r)return new h(c.NA);const e=sr(new Date),t=new w(e);return t.setPattern(nr),t}}class Xs extends A{calculate(r){return r==null?new h(c.NA):r.isArray()?r.map(e=>this._handleSingleObject(e)):this._handleSingleObject(r)}_handleSingleObject(r){if(r.isError())return r;let e;const t=r.getValue();if(r.isString()){if(!ir(`${t}`))return new h(c.VALUE);e=new Date(`${t}`)}else{const a=+t;if(a<0)return new h(c.NUM);if(a===0)return new w(1900);e=dt(a)}const s=e.getUTCFullYear();return new w(s)}}const cn=[[Qs,pe.DATE],[Ys,pe.DAY],[Hs,pe.EDATE],[js,pe.MONTH],[Ws,pe.TODAY],[Xs,pe.YEAR]],fn=[];var hn=(n=>(n.BESSELI="BESSELI",n.BESSELJ="BESSELJ",n.BESSELK="BESSELK",n.BESSELY="BESSELY",n.BIN2DEC="BIN2DEC",n.BIN2HEX="BIN2HEX",n.BIN2OCT="BIN2OCT",n.BITAND="BITAND",n.BITLSHIFT="BITLSHIFT",n.BITOR="BITOR",n.BITRSHIFT="BITRSHIFT",n.BITXOR="BITXOR",n.COMPLEX="COMPLEX",n.CONVERT="CONVERT",n.DEC2BIN="DEC2BIN",n.DEC2HEX="DEC2HEX",n.DEC2OCT="DEC2OCT",n.DELTA="DELTA",n.ERF="ERF",n.ERF_PRECISE="ERF.PRECISE",n.ERFC="ERFC",n.ERFC_PRECISE="ERFC.PRECISE",n.GESTEP="GESTEP",n.HEX2BIN="HEX2BIN",n.HEX2DEC="HEX2DEC",n.HEX2OCT="HEX2OCT",n.IMABS="IMABS",n.IMAGINARY="IMAGINARY",n.IMARGUMENT="IMARGUMENT",n.IMCONJUGATE="IMCONJUGATE",n.IMCOS="IMCOS",n.IMCOSH="IMCOSH",n.IMCOT="IMCOT",n.IMCSC="IMCSC",n.IMCSCH="IMCSCH",n.IMDIV="IMDIV",n.IMEXP="IMEXP",n.IMLN="IMLN",n.IMLOG10="IMLOG10",n.IMLOG2="IMLOG2",n.IMPOWER="IMPOWER",n.IMPRODUCT="IMPRODUCT",n.IMREAL="IMREAL",n.IMSEC="IMSEC",n.IMSECH="IMSECH",n.IMSIN="IMSIN",n.IMSINH="IMSINH",n.IMSQRT="IMSQRT",n.IMSUB="IMSUB",n.IMSUM="IMSUM",n.IMTAN="IMTAN",n.OCT2BIN="OCT2BIN",n.OCT2DEC="OCT2DEC",n.OCT2HEX="OCT2HEX",n))(hn||{});const mn=[];var gn=(n=>(n.ACCRINT="ACCRINT",n.ACCRINTM="ACCRINTM",n.AMORDEGRC="AMORDEGRC",n.AMORLINC="AMORLINC",n.COUPDAYBS="COUPDAYBS",n.COUPDAYS="COUPDAYS",n.COUPDAYSNC="COUPDAYSNC",n.COUPNCD="COUPNCD",n.COUPNUM="COUPNUM",n.COUPPCD="COUPPCD",n.CUMIPMT="CUMIPMT",n.CUMPRINC="CUMPRINC",n.DB="DB",n.DDB="DDB",n.DISC="DISC",n.DOLLARDE="DOLLARDE",n.DOLLARFR="DOLLARFR",n.DURATION="DURATION",n.EFFECT="EFFECT",n.FV="FV",n.FVSCHEDULE="FVSCHEDULE",n.INTRATE="INTRATE",n.IPMT="IPMT",n.IRR="IRR",n.ISPMT="ISPMT",n.MDURATION="MDURATION",n.MIRR="MIRR",n.NOMINAL="NOMINAL",n.NPER="NPER",n.NPV="NPV",n.ODDFPRICE="ODDFPRICE",n.ODDFYIELD="ODDFYIELD",n.ODDLPRICE="ODDLPRICE",n.ODDLYIELD="ODDLYIELD",n.PDURATION="PDURATION",n.PMT="PMT",n.PPMT="PPMT",n.PRICE="PRICE",n.PRICEDISC="PRICEDISC",n.PRICEMAT="PRICEMAT",n.PV="PV",n.RATE="RATE",n.RECEIVED="RECEIVED",n.RRI="RRI",n.SLN="SLN",n.SYD="SYD",n.TBILLEQ="TBILLEQ",n.TBILLPRICE="TBILLPRICE",n.TBILLYIELD="TBILLYIELD",n.VDB="VDB",n.XIRR="XIRR",n.XNPV="XNPV",n.YIELD="YIELD",n.YIELDDISC="YIELDDISC",n.YIELDMAT="YIELDMAT",n))(gn||{}),se=(n=>(n.CELL="CELL",n.ERROR_TYPE="ERROR.TYPE",n.INFO="INFO",n.ISBLANK="ISBLANK",n.ISERR="ISERR",n.ISERROR="ISERROR",n.ISEVEN="ISEVEN",n.ISFORMULA="ISFORMULA",n.ISLOGICAL="ISLOGICAL",n.ISNA="ISNA",n.ISNONTEXT="ISNONTEXT",n.ISNUMBER="ISNUMBER",n.ISODD="ISODD",n.ISOMITTED="ISOMITTED",n.ISREF="ISREF",n.ISTEXT="ISTEXT",n.N="N",n.NA="NA",n.SHEET="SHEET",n.SHEETS="SHEETS",n.TYPE="TYPE",n))(se||{});class Gs extends A{calculate(r){return r==null?new h(c.NA):r.isNull()?new P(!0):r.isArray()?r.mapValue(e=>e.isNull()?new P(!0):new P(!1)):new P(!1)}}class Ks extends A{calculate(r){return r==null?new h(c.NA):r.getValue()===c.NA?new P(!1):r.isError()?new P(!0):r.isArray()?r.mapValue(e=>e.getValue()===c.NA?new P(!1):e.isError()?new P(!0):new P(!1)):new P(!1)}}class zs extends A{calculate(r){return r==null?new h(c.NA):r.isError()?new P(!0):r.isArray()?r.mapValue(e=>e.isError()?new P(!0):new P(!1)):new P(!1)}}class qs extends A{calculate(r){return r==null?new h(c.NA):r.isBoolean()?new P(!0):r.isArray()?r.mapValue(e=>e.isBoolean()?new P(!0):new P(!1)):new P(!1)}}class Zs extends A{calculate(r){return r==null?new h(c.NA):r.getValue()===c.NA?new P(!0):r.isArray()?r.mapValue(e=>e.getValue()===c.NA?new P(!0):new P(!1)):new P(!1)}}class Js extends A{calculate(r){return r==null?new h(c.NA):!r.isArray()&&!r.isString()?new P(!0):r.isArray()?r.mapValue(e=>e.isString()?new P(!1):new P(!0)):new P(!1)}}class Ns extends A{calculate(r){return r==null?new h(c.NA):r.isNumber()?new P(!0):r.isArray()?r.mapValue(e=>e.isNumber()?new P(!0):new P(!1)):new P(!1)}}class ei extends A{constructor(){super(...arguments);p(this,"needsReferenceObject",!0)}calculate(e){return e==null?new h(c.NA):e.isReferenceObject()?new P(!0):new P(!1)}}class ti extends A{calculate(r){return r==null?new h(c.NA):r.isString()?new P(!0):r.isArray()?r.mapValue(e=>e.isString()?new P(!0):new P(!1)):new P(!1)}}const dn=[[Gs,se.ISBLANK],[Ks,se.ISERR],[zs,se.ISERROR],[qs,se.ISLOGICAL],[Zs,se.ISNA],[Js,se.ISNONTEXT],[Ns,se.ISNUMBER],[ei,se.ISREF],[ti,se.ISTEXT]];class ri extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=!0,t=!0,s=null;for(const i of r){if(i.isError())return i;if(i.isArray()){if(i.iterator(a=>{if(a!=null&&a.isError())return s=a,!1;(a!=null&&a.isBoolean()||a!=null&&a.isNumber())&&(e=e&&!!a.getValue(),t=!1)}),s)return s}else(i.isBoolean()||i.isNumber())&&(e=e&&!!i.getValue(),t=!1)}return t?new h(c.VALUE):new P(e)}}var xe=(n=>(n.AND="AND",n.BYCOL="BYCOL",n.BYROW="BYROW",n.FALSE="FALSE",n.IF="IF",n.IFERROR="IFERROR",n.IFNA="IFNA",n.IFS="IFS",n.LAMBDA="LAMBDA",n.LET="LET",n.MAKEARRAY="MAKEARRAY",n.MAP="MAP",n.NOT="NOT",n.OR="OR",n.REDUCE="REDUCE",n.SCAN="SCAN",n.SWITCH="SWITCH",n.TRUE="TRUE",n.XOR="XOR",n))(xe||{});class ni extends A{calculate(r,e,t=new P(!1)){if(r==null||e==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return e;if(r=this._getSingleValueObject(r),!r.isArray())return r.getValue()?e:t;const s=Math.max(r.isArray()?r.getRowCount():1,e.isArray()?e.getRowCount():1,t.isArray()?t.getRowCount():1),i=Math.max(r.isArray()?r.getColumnCount():1,e.isArray()?e.getColumnCount():1,t.isArray()?t.getColumnCount():1),a=W(s,i,r),u=W(s,i,e,new h(c.NA)),o=W(s,i,t,new h(c.NA));return a.map((l,f,m)=>{if(l.isNull())return new h(c.NA);{const g=u.get(f,m),R=o.get(f,m);return this._calculateSingleCell(l,g,R)}})}_getSingleValueObject(r){return r.isArray()&&r.getRowCount()===1&&r.getColumnCount()===1?r.getFirstCell():r}_calculateSingleCell(r,e,t){return r.isNull()?new h(c.NA):r.getValue()?e.isNull()?new h(c.NA):e:t.isNull()?new h(c.NA):t}}class si extends A{calculate(r,e){if(r==null||e==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return e;if(!r.isArray())return r.isError()?e:r;const t=Math.max(r.isArray()?r.getRowCount():1,e.isArray()?e.getRowCount():1),s=Math.max(r.isArray()?r.getColumnCount():1,e.isArray()?e.getColumnCount():1),i=W(t,s,r),a=W(t,s,e);return i.iterator((u,o,l)=>{u!=null&&u.isError()&&i.set(o,l,a.get(o,l))}),i}}class ii extends A{calculate(...r){return new h(c.VALUE)}}class ai extends A{calculate(...r){if(r.length!==3)return new h(c.VALUE);const e=this.getIndexNumValue(r[0]);if(typeof e!="number")return e;const t=this.getIndexNumValue(r[1]);if(typeof t!="number")return t;if(!(r[2].isValueObject()&&r[2].isLambda()))return new h(c.VALUE);const s=r[2],i=[];for(let a=0;a<e;a++){i[a]==null&&(i[a]=[]);for(let u=0;u<t;u++){const o=s.execute(new w(a+1),new w(u+1));i[a][u]=o}}return new ks(i)}isAsync(){return!0}}const Rn=[[ri,xe.AND],[ii,xe.LAMBDA],[ai,xe.MAKEARRAY],[ni,xe.IF],[si,xe.IFERROR]];class ui extends A{calculate(r,e,t,s,i){if(r==null||e==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return e;if(t!=null&&t.isError())return t;if(s!=null&&s.isError())return s;if(i!=null&&i.isError())return i;const a=Number(r.getValue())-1,u=Number(e.getValue())-1;if(Number.isNaN(a)||Number.isNaN(u))return new h(c.VALUE);const o=t?oi(t.getValue()):d.AbsoluteRefType.ALL,l=this.getZeroOrOneByOneDefault(s),f=i?`${i.getValue()}`:"",m=st(f)?`'${f}'`:f,g={startRow:a,startColumn:u,endRow:a,endColumn:u,startAbsoluteRefType:o,endAbsoluteRefType:o},R=s&&!l?Ts(g):ye(g);return new X(m!==""?`${m}!${R}`:R)}}function oi(n){switch(n){case 1:return d.AbsoluteRefType.ALL;case 2:return d.AbsoluteRefType.ROW;case 3:return d.AbsoluteRefType.COLUMN;case 4:return d.AbsoluteRefType.NONE;default:return d.AbsoluteRefType.ALL}}class li extends A{calculate(r){if(r==null)return new w(this.column+1);if(r.isError())return r;if(!r.isArray())return new h(c.NA);const e=r.getCurrentColumn(),t=r.getColumnCount(),s=[];for(let a=0;a<t;a++)s.push(new w(e+a+1));const i={calculateValueList:[s],rowCount:1,columnCount:t,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return new J(i)}}class ci extends A{calculate(r){if(r==null)return new h(c.NA);if(r.isError())return r;if(r.isString()||r.isNumber()||r.isBoolean())return new w(1);if(!r.isArray())return new h(c.NA);const e=r.getColumnCount();return new w(e)}}var K=(n=>(n.ADDRESS="ADDRESS",n.AREAS="AREAS",n.CHOOSE="CHOOSE",n.CHOOSECOLS="CHOOSECOLS",n.CHOOSEROWS="CHOOSEROWS",n.COLUMN="COLUMN",n.COLUMNS="COLUMNS",n.DROP="DROP",n.EXPAND="EXPAND",n.FILTER="FILTER",n.FORMULATEXT="FORMULATEXT",n.GETPIVOTDATA="GETPIVOTDATA",n.HLOOKUP="HLOOKUP",n.HSTACK="HSTACK",n.HYPERLINK="HYPERLINK",n.IMAGE="IMAGE",n.INDEX="INDEX",n.INDIRECT="INDIRECT",n.LOOKUP="LOOKUP",n.MATCH="MATCH",n.OFFSET="OFFSET",n.ROW="ROW",n.ROWS="ROWS",n.RTD="RTD",n.SORT="SORT",n.SORTBY="SORTBY",n.TAKE="TAKE",n.TOCOL="TOCOL",n.TOROW="TOROW",n.TRANSPOSE="TRANSPOSE",n.UNIQUE="UNIQUE",n.VLOOKUP="VLOOKUP",n.VSTACK="VSTACK",n.WRAPCOLS="WRAPCOLS",n.WRAPROWS="WRAPROWS",n.XLOOKUP="XLOOKUP",n.XMATCH="XMATCH",n))(K||{});class fi extends A{calculate(r,e,t,s){if(r==null||e==null||t==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return new h(c.REF);if(!e.isArray())return new h(c.NA);if(t.isError())return new h(c.NA);if(s!=null&&s.isError())return new h(c.NA);const i=this.getZeroOrOneByOneDefault(s);if(i==null)return new h(c.VALUE);const a=this.getIndexNumValue(t);if(a instanceof h)return a;const u=e.slice([0,1]),o=e.slice([a-1,a]);return u==null||o==null?new h(c.REF):r.isArray()?r.map(l=>this._handleSingleObject(l,u,o,i)):this._handleSingleObject(r,u,o,i)}_handleSingleObject(r,e,t,s){return s===0?this.equalSearch(r,e,t):this.binarySearch(r,e,t)}}class En extends ke{constructor(r){super(r);const e=Fe(r);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName),this.setRangeData(e.range)}isCell(){return!0}unionBy(r){if(!r.isCell())return new h(c.REF);const e=r,t=this.unionRange(this.getRangeData(),e.getRangeData());return this._createRange(t)}unionRange(r,e){const t=r.startRow,s=r.startColumn,i=e.startRow,a=e.startColumn,u={startRow:-1,startColumn:-1,endRow:-1,endColumn:-1};return t>i?(u.startRow=i,u.endRow=t):(u.startRow=t,u.endRow=i),s>a?(u.startColumn=a,u.endColumn=s):(u.startColumn=s,u.endColumn=a),u}_createRange(r){const e=new qe(r,this.getForcedSheetId(),this.getForcedUnitId());e.setUnitData(this.getUnitData()),e.setDefaultSheetId(this.getDefaultSheetId()),e.setDefaultUnitId(this.getDefaultUnitId()),e.setRuntimeData(this.getRuntimeData()),e.setNumfmtItemData(this.getNumfmtItemData()),e.setArrayFormulaCellData(this.getArrayFormulaCellData()),e.setRuntimeArrayFormulaCellData(this.getRuntimeArrayFormulaCellData()),e.setRuntimeFeatureCellData(this.getRuntimeFeatureCellData());const{x:t,y:s}=this.getRefOffset();e.setRefOffset(t,s);const i=this.getForcedSheetId();e.setForcedSheetName(this.getForcedSheetName()),i!=null&&e.setForcedSheetIdDirect(i);const a=this.getForcedUnitId();return a&&e.setForcedUnitIdDirect(a),e}}class _n extends ke{constructor(r){super(r);const e=Fe(r);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const t={startColumn:e.range.startColumn,startRow:Number.NaN,endColumn:-1,endRow:Number.NaN};this.setRangeData(t)}isColumn(){return!0}unionBy(r){if(!r.isColumn())return new h(c.REF);const e=r;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return new h(c.REF);const t=this.getRangeData(),s=e.getRangeData().startColumn,i=t.startColumn;return s>i?t.endColumn=s:(t.startColumn=s,t.endColumn=i),this}}class wn extends ke{constructor(r){super(r);const e=Fe(r);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const t={startColumn:Number.NaN,startRow:e.range.startRow,endColumn:Number.NaN,endRow:-1};this.setRangeData(t)}isRow(){return!0}unionBy(r){if(!r.isRow())return new h(c.REF);const e=r;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return new h(c.REF);const t=this.getRangeData(),s=e.getRangeData().startRow,i=t.startRow;return s>i?t.endRow=s:(t.startRow=s,t.endRow=i),this}}class hi extends A{calculate(r,e){if(r==null)return new h(c.NA);if(r.isError())return r;let t=this.getZeroOrOneByOneDefault(e);if(t==null&&(t=1),r.isArray()){const f=r;if(f.getRowCount()===1&&f.getColumnCount()===1)r=f.getFirstCell();else return f.map(()=>new h(c.VALUE))}if(!r.isString())return new h(c.REF);const s=r.getValue();if(t===0){const f=Jr(s),{range:m,sheetName:g,unitId:R}=f,_=new qe(m);return _.setForcedUnitIdDirect(R),_.setForcedSheetName(g),this._setDefault(_)}if(new RegExp(nt).test(s))return this._setDefault(new En(s));if(new RegExp(Dr).test(s))return this._setDefault(new wn(s));if(new RegExp(yr).test(s))return this._setDefault(new _n(s));const i=Fe(s),{range:a,sheetName:u,unitId:o}=i,l=new qe(a);return l.setForcedUnitIdDirect(o),l.setForcedSheetName(u),this._setDefault(l)}_setDefault(r){return this.unitId==null||this.subUnitId==null?new h(c.REF):(r.setDefaultUnitId(this.unitId),r.setDefaultSheetId(this.subUnitId),r)}}class mi extends A{constructor(){super(...arguments);p(this,"needsExpandParams",!0)}calculate(e,t,s){return e==null||t==null?new h(c.NA):e.isError()?e:t.isError()?new h(c.REF):t.isArray()?s!=null&&s.isError()?s:t.getColumnCount()===1||t.getRowCount()===1?s!=null&&!s.isArray()?new h(c.REF):this._handleVector(e,t,s):this._handleArray(e,t):new h(c.VALUE)}_handleVector(e,t,s){if(s==null)s=t;else if(s.getRowCount()!==t.getRowCount()||s.getColumnCount()!==t.getColumnCount())return new h(c.REF);return e.isArray()?e.map(i=>this.binarySearch(i,t,s)):this.binarySearch(e,t,s)}_handleArray(e,t){const s=t.getRowCount(),i=t.getColumnCount();let a,u;return i>s?(a=t.slice([0,1]),u=t.slice([s-1,s])):(a=t.slice(void 0,[0,1]),u=t.slice(void 0,[i-1,i])),a==null||u==null?new h(c.VALUE):e.isArray()?e.map(o=>this.binarySearch(o,a,u)):this.binarySearch(e,a,u)}}class gi extends A{calculate(r,e,t){if(r==null||e==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return new h(c.REF);if(!e.isArray())return new h(c.VALUE);const s=e.getRowCount(),i=e.getColumnCount();if(s!==1&&i!==1)return new h(c.NA);if(t!=null&&t.isError())return new h(c.NA);const a=this.getMatchTypeValue(t);return a==null?new h(c.VALUE):r.isArray()?r.map(u=>this._handleSingleObject(u,e,a)):this._handleSingleObject(r,e,a)}_handleSingleObject(r,e,t){const s=this._getSearchModeValue(t),i=e.orderSearch(r,s);if(i==null)return new h(c.NA);if(i instanceof h)return i;const a=e.getRowCount()===1?i.column+1:i.row+1;return new w(a)}_getSearchModeValue(r){switch(r){case 1:return Z.MIN;case 0:return Z.NORMAL;case-1:return Z.MAX}}}class di extends A{calculate(r,e,t,s,i){var x,v;if(r==null||e==null||t==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return e;if(t.isError())return t;if(s!=null&&s.isError())return s;if(i!=null&&i.isError())return i;if(!r.isArray())return new h(c.VALUE);const a=r.getCurrentRow(),u=r.getCurrentColumn(),o=this.getIndexNumValue(e),l=this.getIndexNumValue(t);if(typeof o!="number"||typeof l!="number")return new h(c.VALUE);const f=a+o,m=u+l;if(f<0||m<0||f>1048576||m>16384)return new h(c.REF);const g=(x=s&&this.getIndexNumValue(s))!=null?x:1,R=(v=i&&this.getIndexNumValue(i))!=null?v:1;if(typeof g!="number"||typeof R!="number")return new h(c.VALUE);if(g===0||R===0)return new h(c.REF);const _=g>0?f+g-1:f+g+1,E=R>0?m+R-1:m+R+1;if(_<0||E<0||_>1048576||E>16384)return new h(c.REF);const C=f<_?f:_,y=m<E?m:E,b=f>_?f:_,L=m>E?m:E,V={startRow:C,startColumn:y,endRow:b,endColumn:L},T=r.getUnitId(),Q=r.getSheetId(),I=new qe(V,Q,T);return this._setDefault(I)}_setDefault(r){return this.unitId==null||this.subUnitId==null?new h(c.REF):(r.setDefaultUnitId(this.unitId),r.setDefaultSheetId(this.subUnitId),r)}}class Ri extends A{calculate(r){if(r==null)return new w(this.row+1);if(r.isError())return r;if(!r.isArray())return new h(c.NA);const e=r.getCurrentRow(),t=r.getRowCount(),s=[];for(let a=0;a<t;a++)s.push([new w(e+a+1)]);const i={calculateValueList:s,rowCount:t,columnCount:1,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return new J(i)}}class Ei extends A{calculate(r){if(r==null)return new h(c.NA);if(r.isError())return r;if(r.isString()||r.isNumber()||r.isBoolean())return new w(1);if(!r.isArray())return new h(c.NA);const e=r.getRowCount();return new w(e)}}class _i extends A{calculate(r,e,t,s){if(r==null||e==null||t==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return new h(c.REF);if(!e.isArray())return new h(c.VALUE);if(t.isError())return new h(c.NA);if(s!=null&&s.isError())return new h(c.NA);const i=this.getZeroOrOneByOneDefault(s);if(i==null)return new h(c.VALUE);const a=this.getIndexNumValue(t);if(a instanceof h)return a;const u=e.slice(void 0,[0,1]),o=e.slice(void 0,[a-1,a]);return u==null||o==null?new h(c.VALUE):r.isArray()?r.map(l=>this._handleSingleObject(l,u,o,i)):this._handleSingleObject(r,u,o,i)}_handleSingleObject(r,e,t,s){return s===0?this.equalSearch(r,e,t):this.binarySearch(r,e,t)}}class wi extends A{calculate(r,e,t,s,i,a){if(r==null||e==null||t==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return new h(c.REF);if(!e.isArray())return new h(c.VALUE);const u=e.getRowCount(),o=e.getColumnCount();if(u!==1&&o!==1)return new h(c.VALUE);if(t.isError())return new h(c.REF);if(!t.isArray())return new h(c.VALUE);const l=t.getRowCount(),f=t.getColumnCount();if(u!==l&&o!==f)return new h(c.VALUE);if(s!=null&&s.isError())return new h(c.NA);if(i!=null&&i.isError())return new h(c.NA);if(a!=null&&a.isError())return new h(c.NA);s==null&&(s=new h(c.NA));const m=this.getIndexNumValue(i||new w(0));if(m instanceof h)return m;const g=this.getIndexNumValue(a||new w(1));if(g instanceof h)return g;if(r.isArray()){let E;return u===1?E=t.slice([0,1]):E=t.slice(void 0,[0,1]),E==null?new h(c.NA):r.map(C=>{const y=this._handleSingleObject(C,e,E,m,g);return y.isError()?s:y})}if(o===f&&u===l){const E=this._handleSingleObject(r,e,t,m,g);return E.isError()?s:E}let R=0;o===f&&(R=1);const _=this._handleExpandObject(r,e,t,m,g,R);return _==null?new h(c.NA):_}_handleExpandObject(r,e,t,s,i,a=0){return(i===2||i===-2)&&s!==2?this.binarySearchExpand(r,e,t,a,this._getSearchModeValue(i)):s===2?this.fuzzySearchExpand(r,e,t,i!==-1,a):s===-1||s===1?this.orderSearchExpand(r,e,t,s===1?Z.MAX:Z.MIN,i===-1,a):this.equalSearchExpand(r,e,t,i!==-1,a)}_handleSingleObject(r,e,t,s,i){return(i===2||i===-2)&&s!==2?this.binarySearch(r,e,t,this._getSearchModeValue(i)):s===2?this.fuzzySearch(r,e,t,i!==-1):s===-1||s===1?this.orderSearch(r,e,t,s===1?Z.MAX:Z.MIN,i===-1):this.equalSearch(r,e,t,i!==-1)}_getSearchModeValue(r){return r===-2?de.MAX:de.MIN}}class Ci extends A{calculate(r,e,t,s){if(r==null||e==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return new h(c.REF);if(!e.isArray())return new h(c.VALUE);const i=e.getRowCount(),a=e.getColumnCount();if(i!==1&&a!==1)return new h(c.VALUE);if(t!=null&&t.isError())return new h(c.NA);if(s!=null&&s.isError())return new h(c.NA);const u=this.getIndexNumValue(t||new w(0));if(u instanceof h)return u;const o=this.getIndexNumValue(s||new w(1));return o instanceof h?o:r.isArray()?r.map(l=>this._handleSingleObject(l,e,u,o)):this._handleSingleObject(r,e,u,o)}_handleSingleObject(r,e,t,s){let i;if((s===2||s===-2)&&t!==2){const a=this._getSearchModeValue(s);i=e.binarySearch(r,a)}else if(t===2){const a=e.compare(r,S.EQUALS);let u;if(s!==-1?u=a.getFirstTruePosition():u=a.getLastTruePosition(),u==null)return new h(c.NA);i=e.getRowCount()===1?u.column:u.row}else if(t===-1||t===1){const a=e.orderSearch(r,t===1?Z.MAX:Z.MIN,s===-1);if(a==null)return new h(c.NA);if(a instanceof h)return a;i=e.getRowCount()===1?a.column:a.row}else{const a=e.isEqual(r);let u;if(s!==-1?u=a.getFirstTruePosition():u=a.getLastTruePosition(),u==null)return new h(c.NA);i=e.getRowCount()===1?u.column:u.row}return i==null?new h(c.NA):new w(i+1)}_getSearchModeValue(r){return r===-2?de.MAX:de.MIN}}class pi extends A{calculate(r,e,t,s){if(r==null)return new h(c.NA);if(r.isError())return r;if(e!=null&&e.isError())return e;if(t!=null&&t.isError())return t;if(s!=null&&s.isError())return s;if(!r.isArray())return new h(c.REF);const i=r.getRowCount(),a=r.getColumnCount();i===1&&a>1&&t==null?(t=e!=null?e:new w(0),e=new w(0)):(e=e!=null?e:new w(0),t=t!=null?t:new w(0)),s=s!=null?s:new w(1);const u=Math.max(e.isArray()?e.getRowCount():1,t.isArray()?t.getRowCount():1,s.isArray()?s.getRowCount():1),o=Math.max(e.isArray()?e.getColumnCount():1,t.isArray()?t.getColumnCount():1,s.isArray()?s.getColumnCount():1);if(u===1&&o===1)return this._calculateSingleCell(r,e,t,s);{const l=W(u,o,e,new h(c.NA)),f=W(u,o,t,new h(c.NA)),m=W(u,o,s,new h(c.NA));return l.map((g,R,_)=>{const E=f.get(R,_),C=m.get(R,_),y=this._calculateSingleCell(r,g,E,C);return y.isArray()?y.getFirstCell():y})}}_calculateSingleCell(r,e,t,s){if(e.isError())return e;const i=this._getNumberValue(e);if(i===void 0||i<0)return new h(c.VALUE);if(t.isError())return t;const a=this._getNumberValue(t);if(a===void 0||a<0)return new h(c.VALUE);if(s.isError())return s;const u=this._getAreaNumberValue(s);if(u===void 0||u<1)return new h(c.VALUE);const o=i===0?[void 0]:[i-1,i],l=a===0?[void 0]:[a-1,a],f=r.slice(o,l);return f||new h(c.REF)}_getNumberValue(r){if(r==null)return 0;let e=0;if(r.isBoolean())r.getValue()===!0&&(e=1);else{if(r.isString())return;r.isNumber()?e=Math.floor(r.getValue()):r.isNull()&&(e=0)}return e}_getAreaNumberValue(r){if(r==null)return 1;let e=0;if(r.isBoolean())r.getValue()===!0&&(e=1);else{if(r.isString())return;r.isNumber()?e=Math.floor(r.getValue()):r.isNull()&&(e=0)}return e}}const Cn=[[ui,K.ADDRESS],[li,K.COLUMN],[ci,K.COLUMNS],[pi,K.INDEX],[hi,K.INDIRECT],[di,K.OFFSET],[Ri,K.ROW],[Ei,K.ROWS],[_i,K.VLOOKUP],[mi,K.LOOKUP],[gi,K.MATCH],[fi,K.HLOOKUP],[wi,K.XLOOKUP],[Ci,K.XMATCH]];class Di extends A{calculate(r){return r==null?new h(c.NA):r.isError()?new h(c.VALUE):r.abs()}}class yi extends A{calculate(r){return r==null?new h(c.NA):r.isError()?r:r.acos()}}class Si extends A{calculate(r){return r==null?new h(c.NA):r.isError()?new h(c.VALUE):r.acosh()}}class bi extends A{calculate(r){return r==null?new h(c.NA):r.isError()?r:r.isArray()?r.map(e=>e.isError()?e:pn(e)):pn(r)}}function pn(n){let r=n.getValue();if(n.isBoolean()&&(r=r?1:0),!Number.isFinite(r))return new h(c.VALUE);const e=Math.atan(1/Number(r));return Number.isNaN(e)?new h(c.VALUE):new w(e)}var N=(n=>(n.ABS="ABS",n.ACOS="ACOS",n.ACOSH="ACOSH",n.ACOT="ACOT",n.ACOTH="ACOTH",n.AGGREGATE="AGGREGATE",n.ARABIC="ARABIC",n.ASIN="ASIN",n.ASINH="ASINH",n.ATAN="ATAN",n.ATAN2="ATAN2",n.ATANH="ATANH",n.BASE="BASE",n.CEILING="CEILING",n.CEILING_MATH="CEILING.MATH",n.CEILING_PRECISE="CEILING.PRECISE",n.COMBIN="COMBIN",n.COMBINA="COMBINA",n.COS="COS",n.COSH="COSH",n.COT="COT",n.COTH="COTH",n.CSC="CSC",n.CSCH="CSCH",n.DECIMAL="DECIMAL",n.DEGREES="DEGREES",n.EVEN="EVEN",n.EXP="EXP",n.FACT="FACT",n.FACTDOUBLE="FACTDOUBLE",n.FLOOR="FLOOR",n.FLOOR_MATH="FLOOR.MATH",n.FLOOR_PRECISE="FLOOR.PRECISE",n.GCD="GCD",n.INT="INT",n.ISO_CEILING="ISO.CEILING",n.LCM="LCM",n.LET="LET",n.LN="LN",n.LOG="LOG",n.LOG10="LOG10",n.MDETERM="MDETERM",n.MINVERSE="MINVERSE",n.MMULT="MMULT",n.MOD="MOD",n.MROUND="MROUND",n.MULTINOMIAL="MULTINOMIAL",n.MUNIT="MUNIT",n.ODD="ODD",n.PI="PI",n.POWER="POWER",n.PRODUCT="PRODUCT",n.QUOTIENT="QUOTIENT",n.RADIANS="RADIANS",n.RAND="RAND",n.RANDARRAY="RANDARRAY",n.RANDBETWEEN="RANDBETWEEN",n.ROMAN="ROMAN",n.ROUND="ROUND",n.ROUNDDOWN="ROUNDDOWN",n.ROUNDUP="ROUNDUP",n.SEC="SEC",n.SECH="SECH",n.SERIESSUM="SERIESSUM",n.SEQUENCE="SEQUENCE",n.SIGN="SIGN",n.SIN="SIN",n.SINH="SINH",n.SQRT="SQRT",n.SQRTPI="SQRTPI",n.SUBTOTAL="SUBTOTAL",n.SUM="SUM",n.SUMIF="SUMIF",n.SUMIFS="SUMIFS",n.SUMPRODUCT="SUMPRODUCT",n.SUMSQ="SUMSQ",n.SUMX2MY2="SUMX2MY2",n.SUMX2PY2="SUMX2PY2",n.SUMXMY2="SUMXMY2",n.TAN="TAN",n.TANH="TANH",n.TRUNC="TRUNC",n))(N||{});class Li extends A{calculate(r,e){return r==null||e==null?new h(c.NA):r.isError()?r:e.isError()?e:r.mod(e)}}class Ai extends A{calculate(r,e){return r==null||e==null?new h(c.NA):r.isError()?r:e.isError()?e:r.pow(e)}}class Pi extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new w(1);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError())return s;if(s.isString()){const i=s.getValue();if(!d.isRealNum(i))return new h(c.VALUE);s=new w(i)}if(s.isArray()&&(s=this._multiplyArray(s),s.isError()))return s;if(!s.isNull()&&(e=e.multiply(s),e.isError()))return e}return e}_multiplyArray(r){let e=new w(1);return r.iterator(t=>{if(t==null||t.isString()||t.isBoolean()||t.isNull())return!0;if(t.isError())return e=t,!1;e=e.multiply(t)}),e}}class Vi extends A{constructor(){super(...arguments);p(this,"needsReferenceObject",!0)}calculate(e,...t){if(e==null)return new h(c.NA);if(e.isError())return e;if(t.length===0)return new h(c.NA);if(e.isReferenceObject()){const s=[];return e.iterator((i,a,u)=>{s[a]==null&&(s[a]=[]),s[a][u]=this._handleSingleObject(i,...t)}),gt(s,s.length,s[0].length)}return this._handleSingleObject(e,...t)}_handleSingleObject(e,...t){const s=this._getIndexNumValue(e);let i;if(s instanceof h)return s;switch(s){case 1:i=this._average(!1,...t);break;case 2:i=this._count(!1,...t);break;case 3:i=this._counta(!1,...t);break;case 4:i=this._max(!1,...t);break;case 5:i=this._min(!1,...t);break;case 6:i=this._product(!1,...t);break;case 7:i=this._stdev(!1,...t);break;case 8:i=this._stdevp(!1,...t);break;case 9:i=this._sum(!1,...t);break;case 10:i=this._var(!1,...t);break;case 11:i=this._varp(!1,...t);break;case 101:i=this._average(!0,...t);break;case 102:i=this._count(!0,...t);break;case 103:i=this._counta(!0,...t);break;case 104:i=this._max(!0,...t);break;case 105:i=this._min(!0,...t);break;case 106:i=this._product(!0,...t);break;case 107:i=this._stdev(!0,...t);break;case 108:i=this._stdevp(!0,...t);break;case 109:i=this._sum(!0,...t);break;case 110:i=this._var(!0,...t);break;case 111:i=this._varp(!0,...t);break;default:i=new h(c.VALUE)}return i}_getIndexNumValue(e){const t=e?Number(e.getValue()):0;if(isNaN(t))return new h(c.VALUE);const s=Math.floor(t);return s>=1&&s<=11||s>=101&&s<=111?s:new h(c.VALUE)}_average(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.mean()}_count(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.count()}_counta(e,...t){let s=new w(0);for(let i=0;i<t.length;i++){const a=t[i];if(!a.isReferenceObject())return new h(c.VALUE);const u=a.getRowData();a.iterator((o,l)=>{if(e&&this._isRowHidden(u,l)||o==null||o.isNull())return!0;s=s.plusBy(1)})}return s}_max(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new w(0):s.max()}_min(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new w(0):s.min()}_product(e,...t){const s=this._flattenRefArray(e,...t);if(s.isError())return s;if(this._isBlankArrayObject(s))return new w(0);let i=new w(1);return s.iterator(a=>{i=i.multiply(a)}),i}_stdev(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new h(c.DIV_BY_ZERO):s.std(1)}_stdevp(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new h(c.DIV_BY_ZERO):s.std()}_sum(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.sum()}_var(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new h(c.DIV_BY_ZERO):s.var(1)}_varp(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new h(c.DIV_BY_ZERO):s.var()}_flattenRefArray(e,...t){const s=[];s[0]=[];for(let i=0;i<t.length;i++){const a=t[i];if(a.isError())return a;if(!a.isReferenceObject())return new h(c.VALUE);const u=a.getRowData();let o;if(a.iterator((l,f)=>{if(e&&this._isRowHidden(u,f)||l==null||l.isNull()||l.isString()||l.isBoolean())return!0;if(l.isError())return o=l,!1;s[0].push(l)}),o!=null&&o.isError())return o}return gt(s,1,s[0].length)}_isRowHidden(e,t){const s=e[t];return s?s.hd===d.BooleanNumber.TRUE:!1}_isBlankArrayObject(e){return e.getArrayValue()[0].length===0}}class xi extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new w(0);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError())return s;if(s.isString()){const i=s.getValue();if(!d.isRealNum(i))return new h(c.VALUE);s=new w(i)}if(s.isArray()&&(s=s.sum()),e=e.plus(s),e.isError())return e}return e}}function vi(n){const r=[S.EQUALS,S.NOT_EQUAL,S.GREATER_THAN_OR_EQUAL,S.GREATER_THAN,S.LESS_THAN_OR_EQUAL,S.LESS_THAN];for(const e of r)if(n.startsWith(e)){const t=n.substring(e.length);return[e,Ce.create(t)]}return[S.EQUALS,Ce.create(n)]}function Dn(n,r,e){if(!e)if(r.isString()){const t=`${r.getValue()}`,[s,i]=vi(t);e=s,r=i}else e=S.EQUALS;return n.compare(r,e)}function Bi(n,r){const e=Math.max(n.isArray()?n.getRowCount():1,r.isArray()?r.getRowCount():1),t=Math.max(n.isArray()?n.getColumnCount():1,r.isArray()?r.getColumnCount():1),s=W(e,t,n),i=W(e,t,r);return s.mapValue((a,u,o)=>{const l=i.get(u,o);return a!=null&&a.isError()?a:l!=null&&l.isError()?l:a!=null&&a.isBoolean()&&(l!=null&&l.isBoolean())?new P(a.getValue()&&l.getValue()):new P(!1)})}class Ui extends A{calculate(r,e,t){return r==null||e==null?new h(c.NA):r.isError()||e.isError()||t!=null&&t.isError()?new h(c.NA):!r.isArray()||t&&!t.isArray()?new h(c.VALUE):e.isArray()?e.map(s=>this._handleSingleObject(r,s,t)):this._handleSingleObject(r,e,t)}_handleSingleObject(r,e,t){const s=Dn(r,e),i=t?t.slice([0,r.getRowCount()],[0,r.getColumnCount()]):r;return i?i.pick(s).sum():new h(c.VALUE)}}class Oi extends A{calculate(r,...e){if(r==null)return new h(c.NA);if(e.length<2)return new h(c.NA);if(r.isError())return new h(c.NA);if(!r.isArray())return new h(c.VALUE);if(e.length<2||e.length%2!==0)return new h(c.VALUE);if(e.some((f,m)=>m%2===0&&!f.isArray()))return new h(c.VALUE);const t=r.getRowCount(),s=r.getColumnCount();let i=0,a=0;e.forEach((f,m)=>{if(m%2===1)if(f.isArray()){const g=f;i=Math.max(i,g.getRowCount()),a=Math.max(a,g.getColumnCount())}else i=Math.max(i,1),a=Math.max(a,1)});const u=[];for(let f=0;f<e.length;f++){if(f%2===1)continue;const m=e[f],g=m.getRowCount(),R=m.getColumnCount();if(g!==t||R!==s)return W(i,a,new h(c.NA));const _=e[f+1];W(i,a,_,new h(c.NA)).iterator((C,y,b)=>{if(!C)return;const L=Dn(m,C);if(u[y]===void 0&&(u[y]=[]),u[y][b]===void 0){u[y][b]=L;return}u[y][b]=Bi(u[y][b],L)})}const o=u.map(f=>f.map(m=>r.pick(m).sum())),l={calculateValueList:o,rowCount:o.length,columnCount:o[0].length,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return new J(l)}}const yn=[[Di,N.ABS],[yi,N.ACOS],[Si,N.ACOSH],[bi,N.ACOT],[Li,N.MOD],[Vi,N.SUBTOTAL],[xi,N.SUM],[Ui,N.SUMIF],[Oi,N.SUMIFS],[Ai,N.POWER],[Pi,N.PRODUCT]];class Mi extends A{constructor(){super(...arguments);p(this,"_compareType",S.EQUALS)}setCompareType(e){this._compareType=e}calculate(e,t){return e.isError()?e:t.isError()?t:e.compare(t,this._compareType)}}class Fi extends Re{constructor(e){super("");p(this,"_values",[]);this._values=e}isCube(){return!0}sum(){const e=new w(0);return this._values.forEach(t=>{e.plus(t.sum())}),e}max(){let e=new w(Number.NEGATIVE_INFINITY);return this._values.forEach(t=>{const s=t.max();e.isLessThan(s)&&(e=s)}),e}min(){let e=new w(Number.POSITIVE_INFINITY);return this._values.forEach(t=>{const s=t.max();e.isGreaterThan(s)&&(e=s)}),e}count(){const e=new w(0);return this._values.forEach(t=>{e.plus(t.count())}),e}countA(){const e=new w(0);return this._values.forEach(t=>{e.plus(t.countA())}),e}countBlank(){const e=new w(0);return this._values.forEach(t=>{e.plus(t.countBlank())}),e}}class $i extends A{calculate(...r){if(r.length===0)return new h(c.VALUE);const e=[];for(let t=0;t<r.length;t++){const s=r[t];if(s.isError())return s;if(!s.isArray())return new h(c.VALUE);e.push(s)}return new Fi(e)}}class ki extends A{calculate(r,e){return r.isError()?r:e.isError()?e:!e.isArray()&&e.getValue()===0?new h(c.DIV_BY_ZERO):r.divided(e)}}var z=(n=>(n.COMPARE="COMPARE",n.DIVIDED="DIVIDED",n.MINUS="MINUS",n.MULTIPLY="MULTIPLY",n.PLUS="PLUS",n.UNION="UNION",n.CUBE="CUBE",n))(z||{});class Ti extends A{calculate(r,e){return r.isError()?r:e.isError()?e:r.minus(e)}}class Ii extends A{calculate(r,e){return r.isError()?r:e.isError()?e:r.multiply(e)}}class Qi extends A{calculate(r,e){return r.isError()?r:e.isError()?e:r.plus(e)}}const Sn=[[Mi,z.COMPARE],[ki,z.DIVIDED],[Ti,z.MINUS],[Ii,z.MULTIPLY],[Qi,z.PLUS],[$i,z.CUBE]];class Yi extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new w(0),t=new w(0);for(let s=0;s<r.length;s++){let i=r[s];if(i.isError())return i;if(i.isString()){const a=i.getValue();if(!d.isRealNum(a))return new h(c.VALUE);i=new w(a)}if(i.isArray()){if(e=e.plus(i.sum()),e.isError())return e;t=t.plus(i.count())}else i.isNull()||(e=e.plus(new w(i.getValue())),t=t.plus(new w(1)))}return e.divided(t)}}class Hi extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new w(0);for(let t=0;t<r.length;t++){let s=r[t];if(!s.isError())if(s.isArray())s=s.count(),e=e.plus(s);else if(s.isString()){const i=s.getValue();d.isRealNum(i)&&(e=e.plus(new w(1)))}else s.isNull()||(e=e.plus(new w(1)))}return e}}class ji extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new w(0);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError()){e=e.plus(new w(1));continue}s.isArray()?(s=s.countA(),e=e.plus(s)):s.isNull()||(e=e.plus(new w(1)))}return e}}var q=(n=>(n.AVEDEV="AVEDEV",n.AVERAGE="AVERAGE",n.AVERAGEA="AVERAGEA",n.AVERAGEIF="AVERAGEIF",n.AVERAGEIFS="AVERAGEIFS",n.BETA_DIST="BETA.DIST",n.BETA_INV="BETA.INV",n.BINOM_DIST="BINOM.DIST",n.BINOM_DIST_RANGE="BINOM.DIST.RANGE",n.BINOM_INV="BINOM.INV",n.CHISQ_DIST="CHISQ.DIST",n.CHISQ_DIST_RT="CHISQ.DIST.RT",n.CHISQ_INV="CHISQ.INV",n.CHISQ_INV_RT="CHISQ.INV.RT",n.CHISQ_TEST="CHISQ.TEST",n.CONFIDENCE_NORM="CONFIDENCE.NORM",n.CONFIDENCE_T="CONFIDENCE.T",n.CORREL="CORREL",n.COUNT="COUNT",n.COUNTA="COUNTA",n.COUNTBLANK="COUNTBLANK",n.COUNTIF="COUNTIF",n.COUNTIFS="COUNTIFS",n.COVARIANCE_P="COVARIANCE.P",n.COVARIANCE_S="COVARIANCE.S",n.DEVSQ="DEVSQ",n.EXPON_DIST="EXPON.DIST",n.F_DIST="F.DIST",n.F_DIST_RT="F.DIST.RT",n.F_INV="F.INV",n.F_INV_RT="F.INV.RT",n.F_TEST="F.TEST",n.FISHER="FISHER",n.FISHERINV="FISHERINV",n.FORECAST="FORECAST",n.FORECAST_ETS="FORECAST.ETS",n.FORECAST_ETS_CONFINT="FORECAST.ETS.CONFINT",n.FORECAST_ETS_SEASONALITY="FORECAST.ETS.SEASONALITY",n.FORECAST_ETS_STAT="FORECAST.ETS.STAT",n.FORECAST_LINEAR="FORECAST.LINEAR",n.FREQUENCY="FREQUENCY",n.GAMMA="GAMMA",n.GAMMA_DIST="GAMMA.DIST",n.GAMMA_INV="GAMMA.INV",n.GAMMALN="GAMMALN",n.GAMMALN_PRECISE="GAMMALN.PRECISE",n.GAUSS="GAUSS",n.GEOMEAN="GEOMEAN",n.GROWTH="GROWTH",n.HARMEAN="HARMEAN",n.HYPGEOM_DIST="HYPGEOM.DIST",n.INTERCEPT="INTERCEPT",n.KURT="KURT",n.LARGE="LARGE",n.LINEST="LINEST",n.LOGEST="LOGEST",n.LOGNORM_DIST="LOGNORM.DIST",n.LOGNORM_INV="LOGNORM.INV",n.MAX="MAX",n.MAXA="MAXA",n.MAXIFS="MAXIFS",n.MEDIAN="MEDIAN",n.MIN="MIN",n.MINA="MINA",n.MINIFS="MINIFS",n.MODE_MULT="MODE.MULT",n.MODE_SNGL="MODE.SNGL",n.NEGBINOM_DIST="NEGBINOM.DIST",n.NORM_DIST="NORM.DIST",n.NORM_INV="NORM.INV",n.NORM_S_DIST="NORM.S.DIST",n.NORM_S_INV="NORM.S.INV",n.PEARSON="PEARSON",n.PERCENTILE_EXC="PERCENTILE.EXC",n.PERCENTILE_INC="PERCENTILE.INC",n.PERCENTRANK_EXC="PERCENTRANK.EXC",n.PERCENTRANK_INC="PERCENTRANK.INC",n.PERMUT="PERMUT",n.PERMUTATIONA="PERMUTATIONA",n.PHI="PHI",n.POISSON_DIST="POISSON.DIST",n.PROB="PROB",n.QUARTILE_EXC="QUARTILE.EXC",n.QUARTILE_INC="QUARTILE.INC",n.RANK_AVG="RANK.AVG",n.RANK_EQ="RANK.EQ",n.RSQ="RSQ",n.SKEW="SKEW",n.SKEW_P="SKEW.P",n.SLOPE="SLOPE",n.SMALL="SMALL",n.STANDARDIZE="STANDARDIZE",n.STDEV_P="STDEV.P",n.STDEV_S="STDEV.S",n.STDEVA="STDEVA",n.STDEVPA="STDEVPA",n.STEYX="STEYX",n.T_DIST="T.DIST",n.T_DIST_2T="T.DIST.2T",n.T_DIST_RT="T.DIST.RT",n.T_INV="T.INV",n.T_INV_2T="T.INV.2T",n.T_TEST="T.TEST",n.TREND="TREND",n.TRIMMEAN="TRIMMEAN",n.VAR_P="VAR.P",n.VAR_S="VAR.S",n.VARA="VARA",n.VARPA="VARPA",n.WEIBULL_DIST="WEIBULL.DIST",n.Z_TEST="Z.TEST",n))(q||{});class Wi extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new w(Number.NEGATIVE_INFINITY);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError())return s;if(s.isString()){const i=s.getValue();if(!d.isRealNum(i))return new h(c.VALUE);s=new w(i)}if(s.isBoolean()&&(s=mt(s)),s.isArray()&&(s=s.max(),s.isError()))return s;s.isNull()||(e=this._validator(e,s))}return e}_validator(r,e){return r.isLessThan(e).getValue()&&(r=e),r}}class bn extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new w(Number.POSITIVE_INFINITY);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError())return s;if(s.isString()){const i=s.getValue();if(!d.isRealNum(i))return new h(c.VALUE);s=new w(i)}if(s.isBoolean()&&(s=mt(s)),s.isArray()&&(s=s.min(),s.isError()))return s;s.isNull()||(e=this._validator(e,s))}return e}_validator(r,e){return r.isGreaterThan(e).getValue()&&(r=e),r}}class Xi extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r,!1);return e.isError()?e:e.std(1)}}class Gi extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r,!1);return e.isError()?e:e.std()}}class Ki extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r,!1);return e.isError()?e:e.var(1)}}class zi extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r,!1);return e.isError()?e:e.var()}}const Ln=[[Yi,q.AVERAGE],[Hi,q.COUNT],[Wi,q.MAX],[bn,q.MIN],[bn,q.MIN],[ji,q.COUNTA],[en,q.STDEV_P],[tn,q.STDEV_S],[Xi,q.STDEVA],[Gi,q.STDEVPA],[rn,q.VAR_P],[nn,q.VAR_S],[Ki,q.VARA],[zi,q.VARPA]];class qi extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=0,t=0;r.forEach(i=>{if(i.isArray()){const a=i;e=Math.max(e,a.getRowCount()),t=Math.max(t,a.getColumnCount())}else e=Math.max(e,1),t=Math.max(t,1)});let s=null;for(const i of r)s=W(e,t,i,new h(c.NA)).mapValue((u,o,l)=>{var R,_;const f=s&&s.get(o,l);if(f!=null&&f.isError())return f;if(u.isError())return u;const m=f!=null&&f.isNull()?"":(R=f==null?void 0:f.getValue())!=null?R:"",g=u!=null&&u.isNull()?"":(_=u==null?void 0:u.getValue())!=null?_:"";return new X(`${m}${g}`)});return s||new h(c.VALUE)}}var Rt=(n=>(n.ASC="ASC",n.ARRAYTOTEXT="ARRAYTOTEXT",n.BAHTTEXT="BAHTTEXT",n.CHAR="CHAR",n.CLEAN="CLEAN",n.CODE="CODE",n.CONCAT="CONCAT",n.CONCATENATE="CONCATENATE",n.DBCS="DBCS",n.DOLLAR="DOLLAR",n.EXACT="EXACT",n.FIND="FIND",n.FINDB="FINDB",n.FIXED="FIXED",n.LEFT="LEFT",n.LEFTB="LEFTB",n.LEN="LEN",n.LENB="LENB",n.LOWER="LOWER",n.MID="MID",n.MIDB="MIDB",n.NUMBERVALUE="NUMBERVALUE",n.PHONETIC="PHONETIC",n.PROPER="PROPER",n.REPLACE="REPLACE",n.REPLACEB="REPLACEB",n.REPT="REPT",n.RIGHT="RIGHT",n.RIGHTB="RIGHTB",n.SEARCH="SEARCH",n.SEARCHB="SEARCHB",n.SUBSTITUTE="SUBSTITUTE",n.T="T",n.TEXT="TEXT",n.TEXTAFTER="TEXTAFTER",n.TEXTBEFORE="TEXTBEFORE",n.TEXTJOIN="TEXTJOIN",n.TEXTSPLIT="TEXTSPLIT",n.TRIM="TRIM",n.UNICHAR="UNICHAR",n.UNICODE="UNICODE",n.UPPER="UPPER",n.VALUE="VALUE",n.VALUETOTEXT="VALUETOTEXT",n.CALL="CALL",n.EUROCONVERT="EUROCONVERT",n.REGISTER_ID="REGISTER.ID",n))(Rt||{});const An=[[qi,Rt.CONCATENATE]],Pn=[];var Zi=(n=>{})();const Vn=[];var xn=(n=>(n.ENCODEURL="ENCODEURL",n.FILTERXML="FILTERXML",n.WEBSERVICE="WEBSERVICE",n))(xn||{});class Ji extends d.Disposable{constructor(){super(...arguments);p(this,"_definedNameMap",new Map)}dispose(){this._definedNameMap.clear()}registerDefinedName(e,t,s){var a;this._definedNameMap.get(e)==null&&this._definedNameMap.set(e,new Map),(a=this._definedNameMap.get(e))==null||a.set(t,s)}removeDefinedName(e,t){var s;(s=this._definedNameMap.get(e))==null||s.delete(t)}getDefinedNameMap(e){return this._definedNameMap.get(e)}getValue(e,t){var s;return(s=this._definedNameMap.get(e))==null?void 0:s.get(t)}hasDefinedName(e){var s;return(((s=this._definedNameMap.get(e))==null?void 0:s.size)||0)!==0}}const Et=B.createIdentifier("univer.formula.defined-names.service");var Ni=Object.defineProperty,ea=Object.getOwnPropertyDescriptor,ta=(n,r,e,t)=>{for(var s=t>1?void 0:t?ea(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Ni(r,e,s),s},ra=(n,r)=>(e,t)=>r(e,t,n);let ar=class extends d.Disposable{constructor(r){super();p(this,"_unitData",{});p(this,"_arrayFormulaCellData",{});p(this,"_formulaData",{});p(this,"_sheetNameMap",{});p(this,"_forceCalculate",!1);p(this,"_dirtyRanges",[]);p(this,"_dirtyNameMap",{});p(this,"_numfmtItemMap",{});p(this,"_dirtyUnitFeatureMap",{});p(this,"_excludedCell");this._currentUniverService=r}dispose(){this._unitData={},this._formulaData={},this._arrayFormulaCellData={},this._sheetNameMap={},this._dirtyRanges=[],this._dirtyNameMap={},this._numfmtItemMap={},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}getNumfmtItemMap(){return this._numfmtItemMap}getDirtyUnitFeatureMap(){return this._dirtyUnitFeatureMap}load(r){if(r.allUnitData&&r.unitSheetNameMap)this._unitData=r.allUnitData,this._sheetNameMap=r.unitSheetNameMap;else{const{allUnitData:e,unitSheetNameMap:t}=this._loadSheetData();this._unitData=e,this._sheetNameMap=t}this._formulaData=r.formulaData,this._arrayFormulaCellData=pr(r.arrayFormulaCellData),this._forceCalculate=r.forceCalculate,this._dirtyRanges=r.dirtyRanges,this._dirtyNameMap=r.dirtyNameMap,this._numfmtItemMap=r.numfmtItemMap,this._dirtyUnitFeatureMap=r.dirtyUnitFeatureMap,this._excludedCell=r.excludedCell,this._mergeNameMap(this._sheetNameMap,this._dirtyNameMap)}loadDirtyRangesAndExcludedCell(r,e){this._dirtyRanges=r,this._excludedCell=e,this._dirtyNameMap={}}registerUnitData(r){this._unitData=r}registerFormulaData(r){this._formulaData=r}registerSheetNameMap(r){this._sheetNameMap=r}_mergeNameMap(r,e){Object.keys(e).forEach(t=>{e[t]&&Object.keys(e[t]).forEach(s=>{r[t]==null&&(r[t]={}),r[t][e[t][s]]=s})})}_loadSheetData(){const r=this._currentUniverService.getAllUniverSheetsInstance(),e={},t={};for(const s of r){const i=s.getUnitId(),a=s.getSheets(),u={},o={};for(const l of a){const f=l.getSheetId(),m=l.getConfig();u[f]={cellData:new d.ObjectMatrix(m.cellData),rowCount:m.rowCount,columnCount:m.columnCount,rowData:m.rowData,columnData:m.columnData},o[l.getName()]=l.getSheetId()}e[i]=u,t[i]=o}return{allUnitData:e,unitSheetNameMap:t}}};ar=ta([ra(0,d.IUniverInstanceService)],ar);const ve=B.createIdentifier("univer.formula.current-data.service");var na=Object.defineProperty,sa=Object.getOwnPropertyDescriptor,ia=(n,r,e,t)=>{for(var s=t>1?void 0:t?sa(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&na(r,e,s),s},aa=(n,r)=>(e,t)=>r(e,t,n),oe=(n=>(n[n.IDLE=0]="IDLE",n[n.START_DEPENDENCY=1]="START_DEPENDENCY",n[n.START_CALCULATION=2]="START_CALCULATION",n[n.CURRENTLY_CALCULATING=3]="CURRENTLY_CALCULATING",n[n.START_DEPENDENCY_ARRAY_FORMULA=4]="START_DEPENDENCY_ARRAY_FORMULA",n[n.START_CALCULATION_ARRAY_FORMULA=5]="START_CALCULATION_ARRAY_FORMULA",n[n.CURRENTLY_CALCULATING_ARRAY_FORMULA=6]="CURRENTLY_CALCULATING_ARRAY_FORMULA",n[n.CALCULATION_COMPLETED=7]="CALCULATION_COMPLETED",n))(oe||{}),Ie=(n=>(n[n.INITIAL=0]="INITIAL",n[n.STOP_EXECUTION=1]="STOP_EXECUTION",n[n.NOT_EXECUTED=2]="NOT_EXECUTED",n[n.SUCCESS=3]="SUCCESS",n))(Ie||{});let ur=class extends d.Disposable{constructor(r){super();p(this,"_formulaExecuteStage",0);p(this,"_stopState",!1);p(this,"_currentRow",-1);p(this,"_currentColumn",-1);p(this,"_currentRowCount",Number.NEGATIVE_INFINITY);p(this,"_currentColumnCount",Number.NEGATIVE_INFINITY);p(this,"_currentSubUnitId","");p(this,"_currentUnitId","");p(this,"_runtimeData",{});p(this,"_runtimeOtherData",{});p(this,"_unitArrayFormulaRange",{});p(this,"_runtimeArrayFormulaCellData",{});p(this,"_runtimeClearArrayFormulaCellData",{});p(this,"_numfmtItemMap",{});p(this,"_runtimeFeatureRange",{});p(this,"_runtimeFeatureCellData",{});p(this,"_functionsExecutedState",0);p(this,"_functionDefinitionPrivacyVar",new Map);p(this,"_totalFormulasToCalculate",0);p(this,"_completedFormulasCount",0);p(this,"_totalArrayFormulasToCalculate",0);p(this,"_completedArrayFormulasCount",0);p(this,"_isCycleDependency",!1);this._currentConfigService=r}get currentRow(){return this._currentRow}get currentColumn(){return this._currentColumn}get currentRowCount(){return this._currentRowCount}get currentColumnCount(){return this._currentColumnCount}get currentSubUnitId(){return this._currentSubUnitId}get currentUnitId(){return this._currentUnitId}dispose(){this.reset(),this._runtimeFeatureCellData={},this._runtimeFeatureRange={}}enableCycleDependency(){this._isCycleDependency=!0}disableCycleDependency(){this._isCycleDependency=!1}isCycleDependency(){return this._isCycleDependency}setTotalArrayFormulasToCalculate(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._numfmtItemMap={},this._runtimeArrayFormulaCellData={},this._runtimeClearArrayFormulaCellData={},this._functionDefinitionPrivacyVar.clear(),this.markedAsInitialFunctionsExecuted(),this._isCycleDependency=!1,this._totalFormulasToCalculate=0,this._completedFormulasCount=0}setCurrent(r,e,t,s,i,a){this._currentRow=r,this._currentColumn=e,this._currentRowCount=t,this._currentColumnCount=s,this._currentSubUnitId=i,this._currentUnitId=a}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._currentSubUnitId,s=this._currentUnitId;this._runtimeOtherData[s]===void 0&&(this._runtimeOtherData[s]={});const i=this._runtimeOtherData[s];i[t]===void 0&&(i[t]={});const a=i[t];a[r]=this._objectValueToCellValue(e)}setRuntimeData(r){const e=this._currentRow,t=this._currentColumn,s=this._currentRowCount,i=this.currentColumnCount,a=this._currentSubUnitId,u=this._currentUnitId;this._runtimeData[u]==null&&(this._runtimeData[u]={});const o=this._runtimeData[u];o[a]==null&&(o[a]=new d.ObjectMatrix),this._unitArrayFormulaRange[u]==null&&(this._unitArrayFormulaRange[u]={}),this._numfmtItemMap[u]==null&&(this._numfmtItemMap[u]={}),this._numfmtItemMap[u][a]==null&&(this._numfmtItemMap[u][a]={});const l=this._numfmtItemMap[u][a],f=this._unitArrayFormulaRange[u];let m=new d.ObjectMatrix;f[a]&&(m=new d.ObjectMatrix(f[a])),this._runtimeArrayFormulaCellData[u]===void 0&&(this._runtimeArrayFormulaCellData[u]={});const g=this._runtimeArrayFormulaCellData[u];g[a]==null&&(g[a]=new d.ObjectMatrix),this._runtimeClearArrayFormulaCellData[u]===void 0&&(this._runtimeClearArrayFormulaCellData[u]={});const R=this._runtimeClearArrayFormulaCellData[u];R[a]==null&&(R[a]=new d.ObjectMatrix);const _=o[a],E=g[a],C=R[a];if(r.isReferenceObject()||r.isValueObject()&&r.isArray()){const y=r,{startRow:b,startColumn:L,endRow:V,endColumn:T}=y.getRangePosition();if(b===V&&L===T){const I=y.getFirstCell(),x=this._objectValueToCellValue(I);_.setValue(e,t,x),C.setValue(e,t,x),l[e]==null&&(l[e]={}),l[e][t]=I.getPattern();return}const Q={startRow:e,startColumn:t,endRow:V-b+e,endColumn:T-L+t};if(m.setValue(e,t,Q),f[a]=m.getData(),this._checkIfArrayFormulaRangeHasData(u,a,e,t,Q)||this._checkIfArrayFormulaExceeded(s,i,Q)){const I=this._objectValueToCellValue(new h(c.SPILL));_.setValue(e,t,I),C.setValue(e,t,I)}else{const I=new h(c.SPILL);y.iterator((x,v,$)=>{const k=this._objectValueToCellValue(x);if(v===b&&$===L){if(x!=null&&x.isError()&&x.isEqualType(I))return C.setValue(e,t,{}),_.setValue(e,t,{...this._objectValueToCellValue(I)}),!1;_.setValue(e,t,{...k})}const He=v-b+e,zn=$-L+t;E.setValue(He,zn,k);const qn=x==null?void 0:x.getPattern();qn&&(l[He]==null&&(l[He]={}),l[He][zn]=qn)})}}else{const y=this._objectValueToCellValue(r);_.setValue(e,t,y),l[e]==null&&(l[e]={}),l[e][t]=r.getPattern(),C.setValue(e,t,y)}}getUnitData(){return this._runtimeData}getUnitArrayFormula(){return this._unitArrayFormulaRange}getNumfmtItemMap(){return this._numfmtItemMap}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(),numfmtItemMap:this.getNumfmtItemMap(),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:d.CellValueType.NUMBER};if(r.isError())return{v:r.getErrorType(),t:d.CellValueType.STRING};if(r.isValueObject()){const e=r,t=e.getValue();return e.isNumber()?{v:t,t:d.CellValueType.NUMBER}:e.isBoolean()?{v:t,t:d.CellValueType.BOOLEAN}:e.isString()&&d.isRealNum(t)?{v:t,t:d.CellValueType.FORCE_STRING}:{v:t,t:d.CellValueType.STRING}}}_checkIfArrayFormulaRangeHasData(r,e,t,s,i){var g,R,_,E,C,y,b,L,V,T,Q,I;const{startRow:a,startColumn:u,endRow:o,endColumn:l}=i,f=this._currentConfigService.getUnitData(),m=(_=(R=(g=this._unitArrayFormulaRange[r])==null?void 0:g[e])==null?void 0:R[t])==null?void 0:_[s];for(let x=a;x<=o;x++)for(let v=u;v<=l;v++){if(x===t&&s===v)continue;const $=(y=(C=(E=this._runtimeData)==null?void 0:E[r])==null?void 0:C[e])==null?void 0:y.getValue(x,v),k=(V=(L=(b=this._runtimeArrayFormulaCellData)==null?void 0:b[r])==null?void 0:L[e])==null?void 0:V.getValue(x,v),He=(I=(Q=(T=f==null?void 0:f[r])==null?void 0:T[e])==null?void 0:Q.cellData)==null?void 0:I.getValue(x,v);if(!d.isNullCell($)||!d.isNullCell(k)&&!this._isInArrayFormulaRange(m,x,v)||!d.isNullCell(He))return!0}return!1}_isInArrayFormulaRange(r,e,t){if(r==null)return!1;const{startRow:s,startColumn:i,endRow:a,endColumn:u}=r;return e>=s&&e<=a&&t>=i&&t<=u}_checkIfArrayFormulaExceeded(r,e,t){return t.endRow>=r||t.endColumn>=e}_isInDirtyRange(r,e,t,s){const i=this._currentConfigService.getDirtyRanges();return i.length===0?!0:Er(i,r,e,t,s)}};ur=ia([aa(0,ve)],ur);const ie=B.createIdentifier("univer.formula.runtime.service");var ua=Object.defineProperty,oa=Object.getOwnPropertyDescriptor,la=(n,r,e,t)=>{for(var s=t>1?void 0:t?oa(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&ua(r,e,s),s},or=(n,r)=>(e,t)=>r(e,t,n);let Qe=class extends d.Disposable{constructor(n,r,e){super(),this._definedNamesService=n,this._runtimeService=r,this._lexerTreeBuilder=e}treeBuilder(n,r=!0){return this._lexerTreeBuilder.treeBuilder(n,r,this._injectDefinedName.bind(this))}_injectDefinedName(n){var i;const r=this._runtimeService.currentUnitId;if(!this._definedNamesService.hasDefinedName(r))return{sequenceString:"",hasDefinedName:!1};const e=this._lexerTreeBuilder.getSequenceNode(n);let t="",s=!1;for(let a=0,u=e.length;a<u;a++){const o=e[a];if(typeof o=="string"){t+=o;continue}const{nodeType:l,token:f}=o;if(l===te.REFERENCE||l===te.FUNCTION){const m=(i=this._definedNamesService.getDefinedNameMap(r))==null?void 0:i.get(f);m?(t+=m,s=!0):t+=f}else t+=f}return{sequenceString:t,hasDefinedName:s}}};Qe=la([or(0,Et),or(1,ie),or(2,B.Inject(it))],Qe);var M=(n=>(n.REFERENCE="ReferenceNode",n.VALUE="ValueNode",n.OPERATOR="OperatorNode",n.FUNCTION="FunctionNode",n.LAMBDA="LambdaNode",n.LAMBDA_PARAMETER="LambdaNodeParameter",n.ERROR="ErrorNode",n.BASE="Base",n.ROOT="Root",n.UNION="UnionNode",n.PREFIX="PrefixNode",n.SUFFIX="SuffixNode",n.NULL="NullNode",n))(M||{});const le=new Map([["ReferenceNode",7],["ValueNode",9],["OperatorNode",8],["FunctionNode",6],["LambdaNode",1],["LambdaNodeParameter",2],["Root",10],["UnionNode",3],["PrefixNode",4],["SuffixNode",5]]);class ee extends d.Disposable{constructor(e){super();p(this,"_children",[]);p(this,"_parent");p(this,"_valueObject");p(this,"_calculateState",!1);p(this,"_async",!1);p(this,"_address",!1);p(this,"_refOffsetX",0);p(this,"_refOffsetY",0);this._token=e}dispose(){var e;this._children.forEach(t=>{t.dispose()}),(e=this._valueObject)==null||e.dispose(),this._parent=null}get nodeType(){return M.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(be.SUCCESS)}serialize(){const e=this.getToken(),t=this.getChildren(),s=[],i=t.length;for(let u=0;u<i;u++){const o=t[u];s.push(o.serialize())}const a={token:e,nodeType:this.nodeType};return i>0&&(a.children=s),a}}class G extends ee{constructor(e){super(e);p(this,"_errorValueObject");this._errorValueObject=new h(e)}get nodeType(){return M.ERROR}static create(e){return new G(e)}getValue(){return this._errorValueObject}}const ce=100;class fe extends d.Disposable{get zIndex(){return 0}create(r,e,t){let s;return r instanceof O?s=r.getToken():s=r,new ee(s)}checkAndCreateNodeType(r){}}class lr extends ee{get nodeType(){return M.ROOT}execute(){const e=this.getChildren()[0];e==null?this.setValue(new h(c.VALUE)):this.setValue(e.getValue())}}class vn extends fe{get zIndex(){return le.get(M.ROOT)||ce}checkAndCreateNodeType(r){if(!(r instanceof O))return;if(r.getToken()===_e)return new lr(_e)}}class Bn extends d.Disposable{constructor(){super(...arguments);p(this,"_functionExecutors",new Map);p(this,"_functionDescriptions",new Map)}dispose(){this._functionExecutors.clear(),this._functionDescriptions.clear()}registerExecutors(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionExecutors.set(s.name,s)}}getExecutors(){return this._functionExecutors}getExecutor(e){return this._functionExecutors.get(e)}hasExecutor(e){return this._functionExecutors.has(e)}unregisterExecutors(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionExecutors.delete(s)}}registerDescriptions(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionDescriptions.set(s.functionName,s)}}getDescriptions(){return this._functionDescriptions}getDescription(e){return this._functionDescriptions.get(e)}hasDescription(e){return this._functionDescriptions.has(e)}unregisterDescriptions(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionDescriptions.delete(s)}}}const he=B.createIdentifier("univer.formula.function.service");var ca=Object.defineProperty,fa=Object.getOwnPropertyDescriptor,ha=(n,r,e,t)=>{for(var s=t>1?void 0:t?fa(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&ca(r,e,s),s},Un=(n,r)=>(e,t)=>r(e,t,n);class _t extends ee{constructor(r,e,t){super(e),this._accessor=r,this._operatorString=e,this._functionExecutor=t}get nodeType(){return M.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===H.MINUS?t=this._functionExecutor.calculate(new w(0),e):this._operatorString===H.AT?t=this._handlerAT(e):t=new h(c.VALUE),this.setValue(t)}_handlerAT(r){if(!r.isReferenceObject())return new h(c.VALUE);const e=r;if(e.isCell())return new h(c.VALUE);const t=this._accessor.get(ie),s=t.currentRow||0,i=t.currentColumn||0;return e.isRow()?e.getCellByColumn(i):e.isColumn()?e.getCellByRow(s):e.isRange()||e.isTable()?e.getCellByPosition():new h(c.VALUE)}}let wt=class extends fe{constructor(n,r){super(),this._functionService=n,this._injector=r}get zIndex(){return le.get(M.PREFIX)||ce}checkAndCreateNodeType(n){if(!(n instanceof O))return;const r=n.getToken(),e=r.trim();if(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;let t="";if(e===H.MINUS)t=z.MINUS;else return e===H.AT?new _t(this._injector,e):void 0;const s=this._functionService.getExecutor(t);return s?new _t(this._injector,e,s):(console.error(`No function ${r}`),G.create(c.NAME))}};wt=ha([Un(0,he),Un(1,B.Inject(B.Injector))],wt);function On(n,r,e){let t,s;const i=n.slice(0,2);let a=0;if(new RegExp(H.MINUS,"g").test(i)){const u=r.getExecutor(z.MINUS);t=new _t(e,H.MINUS,u),a++}return new RegExp(H.AT,"g").test(i)&&(s=new _t(e,H.AT),t&&s.setParent(t),a++),a>0&&(n=n.slice(a)),{tokenTrim:n,minusPrefixNode:t,atPrefixNode:s}}var ma=Object.defineProperty,ga=Object.getOwnPropertyDescriptor,da=(n,r,e,t)=>{for(var s=t>1?void 0:t?ga(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&ma(r,e,s),s},Ct=(n,r)=>(e,t)=>r(e,t,n);class Ra extends ee{constructor(r,e,t,s){super(r),this._functionExecutor=e,this._currentConfigService=t,this._runtimeService=s,this._functionExecutor.isAsync()&&this.setAsync(),this._functionExecutor.isAddress()&&this.setAddress()}get nodeType(){return M.FUNCTION}async executeAsync(){const r=[],e=this.getChildren(),t=e.length;this._compatibility();for(let a=0;a<t;a++){const u=e[a].getValue();u!=null&&(u.isReferenceObject()?r.push(u.toArrayValueObject()):r.push(u))}const s=this._calculate(r);let i;return s.isAsyncObject()||s.isAsyncArrayObject()?i=await s.getValue():i=s,this._setRefData(i),this.setValue(i),Promise.resolve(be.SUCCESS)}execute(){const r=[],e=this.getChildren(),t=e.length;this._compatibility();for(let i=0;i<t;i++){const a=e[i].getValue();a!=null&&(a.isReferenceObject()&&!this._functionExecutor.needsReferenceObject?r.push(a.toArrayValueObject()):r.push(a))}const s=this._calculate(r);this._setRefData(s),this.setValue(s)}_compatibility(){this._lookupCompatibility()}_lookupCompatibility(){const r=this.getChildren(),e=r.length;if(!this._functionExecutor.needsExpandParams||e!==3)return;const t=r[1].getValue(),s=r[2].getValue();if(!(t!=null&&t.isReferenceObject())&&!(s!=null&&s.isReferenceObject()))return;const i=t.getRangeData(),a=s.getRangeData(),{startRow:u,startColumn:o,endRow:l,endColumn:f}=i,m=l-u+1,g=f-o+1,{startRow:R,startColumn:_,endRow:E,endColumn:C}=a,y=E-R+1,b=C-_+1;m!==y&&(a.endRow+=m-y),g!==b&&(a.endColumn+=g-b)}_calculate(r){var t;let e;if(this._setRefInfo(),this._functionExecutor.isCustom()){const s=this._functionExecutor.calculateCustom(...r.map(i=>i.isArray()?i.toValue():i.getValue()));if(typeof s!="object"||s==null)e=Ce.create(s);else{const i=Us(s);e=new J({calculateValueList:i,rowCount:i.length,columnCount:((t=i[0])==null?void 0:t.length)||0,unitId:"",sheetId:"",row:-1,column:-1})}}else e=this._functionExecutor.calculate(...r);return e}_setRefInfo(){const{currentUnitId:r,currentSubUnitId:e,currentRow:t,currentColumn:s}=this._runtimeService;this._functionExecutor.setRefInfo(r,e,t,s)}_setRefData(r){if(!r.isReferenceObject())return;const e=r;e.setForcedSheetId(this._currentConfigService.getSheetNameMap()),e.setUnitData(this._currentConfigService.getUnitData()),e.setArrayFormulaCellData(this._currentConfigService.getArrayFormulaCellData()),e.setRuntimeData(this._runtimeService.getUnitData()),e.setRuntimeArrayFormulaCellData(this._runtimeService.getRuntimeArrayFormulaCellData()),e.setRuntimeFeatureCellData(this._runtimeService.getRuntimeFeatureCellData())}}let pt=class extends fe{constructor(n,r,e,t){super(),this._functionService=n,this._currentConfigService=r,this._runtimeService=e,this._injector=t}get zIndex(){return le.get(M.FUNCTION)||ce}create(n){const r=this._functionService.getExecutor(n);return r?new Ra(n,r,this._currentConfigService,this._runtimeService):(console.error(`No function ${n}`),G.create(c.NAME))}checkAndCreateNodeType(n){if(typeof n=="string")return;const r=n.getToken(),{tokenTrim:e,minusPrefixNode:t,atPrefixNode:s}=On(r.trim(),this._functionService,this._injector);if(!Number.isNaN(Number(e)))return G.create(c.VALUE);const i=e.toUpperCase();if(this._functionService.hasExecutor(i)){const a=this.create(i);return s?a.setParent(s):t&&a.setParent(t),a}}};pt=da([Ct(0,he),Ct(1,ve),Ct(2,ie),Ct(3,B.Inject(B.Injector))],pt);var Ea=Object.defineProperty,_a=Object.getOwnPropertyDescriptor,wa=(n,r,e,t)=>{for(var s=t>1?void 0:t?_a(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Ea(r,e,s),s},Ca=(n,r)=>(e,t)=>r(e,t,n);let Ye=class extends d.Disposable{constructor(n){super(),this._runtimeService=n}dispose(){}async executeAsync(n){if(!n)return new h(c.VALUE);await this._executeAsync(n);const r=n.getValue();if(r==null)throw new Error("node value is null");return Promise.resolve(r)}execute(n){if(!n)return new h(c.VALUE);this._execute(n);const r=n.getValue();if(r==null)throw new Error("node value is null");return r}executePreCalculateNode(n){return n.execute(),n.getValue()}checkAsyncNode(n){const r=[];this._checkAsyncNode(n,r);for(let e=0,t=r.length;e<t;e++)if(r[e]===!0)return!0;return!1}_checkAsyncNode(n,r){const e=n.getChildren(),t=e.length;for(let s=0;s<t;s++){const i=e[s];r.push(i.isAsync()),this._checkAsyncNode(i,r)}}async _executeAsync(n){if(this._runtimeService.isStopExecution())return Promise.resolve(be.ERROR);const r=n.getChildren(),e=r.length;for(let t=0;t<e;t++){const s=r[t];if(s.getToken().toUpperCase()===Ge&&s.isEmptyParamFunction()){s.execute();continue}await this._executeAsync(s)}return n.nodeType===M.FUNCTION&&n.isAsync()?await n.executeAsync():n.execute(),Promise.resolve(be.SUCCESS)}_execute(n){if(this._runtimeService.isStopExecution())return be.ERROR;const r=n.getChildren(),e=r.length;for(let t=0;t<e;t++){const s=r[t];if(s.getToken().toUpperCase()===Ge&&s.isEmptyParamFunction()){s.execute();continue}this._execute(s)}return n.execute(),be.SUCCESS}};Ye=wa([Ca(0,ie)],Ye);function Mn(n){return n instanceof O?n.getToken()===Me:!1}function pa(n){return n instanceof O?n.getToken()===Lr:!1}function Fn(n){if(!n)return;if(n.getToken()!==Xe)return n;const r=n,e=r.getCurrentLambdaPrivacyVar(),t=r.getLambdaParameter();if(!e)return;const s=e.get(t);return s==null&&n.getValue()?n:Fn(s)}class Da extends Re{constructor(e,t,s){super(0);p(this,"_lambdaPrivacyValueMap",new Map);this._lambdaNode=e,this._interpreter=t,this._lambdaPrivacyVarKeys=s,this._lambdaPrivacyValueMap.clear()}isLambda(){return!0}execute(...e){const t=this._lambdaPrivacyVarKeys.length;if(e.length!==t)return new h(c.VALUE);this._setLambdaPrivacyValueMap(e),this._setLambdaNodeValue(this._lambdaNode),this._lambdaNode.setNotEmpty(!1);let s;if(this._interpreter.checkAsyncNode(this._lambdaNode))s=new $s(this._interpreter.executeAsync(this._lambdaNode));else{const i=this._interpreter.execute(this._lambdaNode);i.isReferenceObject()?s=i.toArrayValueObject():s=i}return this._lambdaNode.setNotEmpty(!0),s}_setLambdaNodeValue(e){const t=e.getChildren(),s=t.length;for(let i=0;i<s;i++){const a=t[i];if(a.getToken()===Xe){const o=a.getLambdaParameter(),l=this._lambdaPrivacyValueMap.get(o);if(l)a.setValue(l);else{const f=a.getCurrentLambdaPrivacyVar(),m=Fn(f.get(o));m!=null&&a.setValue(m.getValue())}continue}this._setLambdaNodeValue(a)}}_setLambdaPrivacyValueMap(e){for(let t=0;t<e.length;t++){const s=e[t],i=this._lambdaPrivacyVarKeys[t];this._lambdaPrivacyValueMap.set(i,s)}}}var ya=Object.defineProperty,Sa=Object.getOwnPropertyDescriptor,ba=(n,r,e,t)=>{for(var s=t>1?void 0:t?Sa(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&ya(r,e,s),s},$n=(n,r)=>(e,t)=>r(e,t,n);class La extends ee{constructor(e,t,s,i){super(e);p(this,"_isNotEmpty",!0);this._lambdaId=t,this._interpreter=s,this._lambdaPrivacyVarKeys=i}get nodeType(){return M.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 Da(this,this._interpreter,this._lambdaPrivacyVarKeys));else{const e=this.getChildren(),t=e.length;this.setValue(e[t-1].getValue())}}}let Dt=class extends fe{constructor(n,r){super(),this._runtimeService=n,this._interpreter=r}get zIndex(){return le.get(M.LAMBDA)||ce}create(n){const r=n.getChildren(),e=r[0];let t=r.slice(1,-1);const s=r[r.length-1];if(!(e instanceof O&&s instanceof O))return G.create(c.NAME);if(e.getToken()===Me){const u=e.getChildren();if(t.length!==u.length)return G.create(c.VALUE)}else t=r.slice(0,-1);const i=d.Tools.generateRandomId(8),a=new Map;for(let u=0;u<t.length;u++){const o=t[u];if(o instanceof O){const l=o.getChildren()[0];o.setToken(Lr),a.set(l.trim(),void 0)}else return G.create(c.VALUE)}return this._runtimeService.registerFunctionDefinitionPrivacyVar(i,a),this._updateLambdaStatement(s,i,a),new La(n.getToken(),i,this._interpreter,[...a.keys()])}checkAndCreateNodeType(n){if(!(!(n instanceof O)||n.getToken().trim().toUpperCase()!==Ge))return this.create(n)}_updateLambdaStatement(n,r,e){this._updateTree(n,r,e)}_updateTree(n,r,e){const t=n.getChildren(),s=t.length,i=t[0];for(let a=0;a<s;a++){const u=t[a];if(!(Mn(i)&&a!==0))if(u instanceof O)this._updateTree(u,r,e);else{const o=u.trim();if(e.has(o)){const l=new O;l.setToken(Xe),l.setLambdaId(r),l.setLambdaPrivacyVar(e),l.setLambdaParameter(o),t[a]=l}}}}};Dt=ba([$n(0,ie),$n(1,B.Inject(Ye))],Dt);function kn(n){if(!n)return;if(n.getToken()!==Xe)return n;const r=n,e=r.getCurrentLambdaPrivacyVar(),t=r.getLambdaParameter();if(e)return kn(e.get(t))}class Aa extends ee{constructor(r,e,t){super(r),this._lambdaParameter=e,this._currentLambdaPrivacyVar=t}getLambdaParameter(){return this._lambdaParameter}getCurrentLambdaPrivacyVar(){return this._currentLambdaPrivacyVar}get nodeType(){return M.LAMBDA_PARAMETER}execute(){const r=kn(this._currentLambdaPrivacyVar.get(this._lambdaParameter));if(r)this.setValue(r.getValue());else{const e=this.getValue();(e==null||e.isError())&&this.setValue(new h(c.SPILL))}}}class Tn extends fe{get zIndex(){return le.get(M.LAMBDA_PARAMETER)||ce}create(r){const e=r.getFunctionDefinitionPrivacyVar(),t=r.getLambdaParameter();return e?new Aa(r.getToken(),t,e):new G(c.SPILL)}checkAndCreateNodeType(r){if(!(!(r instanceof O)||r.getToken().trim()!==Xe))return this.create(r)}}class Pa extends ee{constructor(r){super(r),this._operatorString=r}get nodeType(){return M.NULL}execute(){this.setValue(new re(0))}}var Va=Object.defineProperty,xa=Object.getOwnPropertyDescriptor,va=(n,r,e,t)=>{for(var s=t>1?void 0:t?xa(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Va(r,e,s),s},Ba=(n,r)=>(e,t)=>r(e,t,n);class Ua extends ee{constructor(r,e){super(r),this._operatorString=r,this._functionExecutor=e}get nodeType(){return M.OPERATOR}execute(){var i,a;const r=this.getChildren();this._functionExecutor.name===z.COMPARE&&this._functionExecutor.setCompareType(this.getToken());let e=(i=r[0])==null?void 0:i.getValue(),t=(a=r[1])==null?void 0:a.getValue();const s=this.getToken();if((e==null||t==null)&&s!==Y.MINUS&&s!==Y.PLUS){this.setValue(new h(c.VALUE));return}e==null&&(e=new re(0)),t==null&&(t=new re(0)),e.isReferenceObject()&&(e=e.toArrayValueObject()),t.isReferenceObject()&&(t=t.toArrayValueObject()),this.setValue(this._functionExecutor.calculate(e,t))}}let yt=class extends fe{constructor(n){super(),this._functionService=n}get zIndex(){return le.get(M.OPERATOR)||ce}create(n){let r="";const e=n;e===Y.PLUS?r=z.PLUS:e===Y.MINUS?r=z.MINUS:e===Y.MULTIPLY?r=z.MULTIPLY:e===Y.DIVIDED?r=z.DIVIDED:e===Y.CONCATENATE?r=Rt.CONCATENATE:e===Y.POWER?r=N.POWER:Zn.has(e)&&(r=z.COMPARE);const t=this._functionService.getExecutor(r);return t?new Ua(e,t):(console.error(`No function ${n}`),G.create(c.NAME))}checkAndCreateNodeType(n){if(n instanceof O)return;const r=n.trim();if(!(r.charAt(0)==='"'&&r.charAt(r.length-1)==='"')&&De.has(r))return this.create(r)}};yt=va([Ba(0,he)],yt);class Oa extends d.Disposable{constructor(){super(...arguments);p(this,"_tableMap",new Map);p(this,"_tableOptionMap",new Map)}dispose(){this._tableMap.clear(),this._tableOptionMap.clear()}remove(e,t){var s;(s=this._tableMap.get(e))==null||s.delete(t)}getTableMap(e){return this._tableMap.get(e)}getTableOptionMap(){return this._tableOptionMap}registerTable(e,t,s){var i;this._tableMap.get(e)==null&&this._tableMap.set(e,new Map),(i=this._tableMap.get(e))==null||i.set(t,s)}registerTableOptionMap(e,t){this._tableOptionMap.set(e,t)}}const cr=B.createIdentifier("univer.formula.super-table.service");class Ma extends ke{constructor(r,e,t,s){super(r),this._tableData=e,this._columnDataString=t;const i=this._tableData.sheetId,a=this._tableData.range,u=this._tableData.titleMap;this.setForcedSheetIdDirect(i);const o=this._stringToColumnData(this._columnDataString,u,s),l=o.startColumn,f=o.endColumn,m=o.type;let g=-1,R=-1;const _=a.startRow,E=a.startColumn;m===Le.ALL?(g=_,R=E):m===Le.DATA?(g=_+1,R=E):m===Le.HEADERS?(g=_,R=_):m===Le.TOTALS&&(g=E,R=E),this.setRangeData({startColumn:l,endColumn:f,startRow:g,endRow:R})}isTable(){return!0}_stringToColumnData(r,e,t){r=r.substring(1,-1);const s=r.indexOf(U.COMMA);let i=-1,a=-1,u=Le.ALL;if(s===-1){const o=this._columnHandler(r,e);i=o.startColumn,a=o.endColumn}else{const o=r.substring(0,s).substring(1,-1),l=r.substring(s+1),f=this._columnHandler(l,e,!0);i=f.startColumn,a=f.endColumn,u=t.get(o),u||(u=Le.ALL)}return{startColumn:i,endColumn:a,type:u}}_columnHandler(r,e,t=!1){var u,o,l;let s=-1,i=-1;const a=r.indexOf(U.COLON);if(new RegExp(Sr,"g").test(r)){const f=r.substring(0,a).substring(1,-1),m=r.substring(a+1).substring(1,-1);s=(u=e.get(f))!=null?u:-1,i=(o=e.get(m))!=null?o:-1}else t&&(r=r.substring(1,-1)),s=(l=e.get(r))!=null?l:-1,i=s;return{startColumn:s,endColumn:i}}}var Fa=Object.defineProperty,$a=Object.getOwnPropertyDescriptor,ka=(n,r,e,t)=>{for(var s=t>1?void 0:t?$a(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Fa(r,e,s),s},Ze=(n,r)=>(e,t)=>r(e,t,n);class St extends ee{constructor(r,e,t,s=!1){super(e),this._accessor=r,this._operatorString=e,this._referenceObject=t,this._isPrepareMerge=s}get nodeType(){return M.REFERENCE}execute(){const r=this._accessor.get(ve),e=this._accessor.get(ie);this._referenceObject.setDefaultUnitId(e.currentUnitId),this._referenceObject.setDefaultSheetId(e.currentSubUnitId),this._referenceObject.setForcedSheetId(r.getSheetNameMap()),this._referenceObject.setUnitData(r.getUnitData()),this._referenceObject.setArrayFormulaCellData(r.getArrayFormulaCellData()),this._referenceObject.setRuntimeData(e.getUnitData()),this._referenceObject.setNumfmtItemData(r.getNumfmtItemMap()),this._referenceObject.setRuntimeArrayFormulaCellData(e.getRuntimeArrayFormulaCellData()),this._referenceObject.setRuntimeFeatureCellData(e.getRuntimeFeatureCellData());const{x:t,y:s}=this.getRefOffset();this._referenceObject.setRefOffset(t,s),!this._isPrepareMerge&&this._referenceObject.isExceedRange()?this.setValue(new h(c.NAME)):this.setValue(this._referenceObject)}}let bt=class extends fe{constructor(n,r,e,t,s){super(),this._definedNamesService=n,this._superTableService=r,this._formulaRuntimeService=e,this._functionService=t,this._injector=s}get zIndex(){return le.get(M.REFERENCE)||ce}checkAndCreateNodeType(n){var o,l;let r=!1,e,t=!1;n instanceof O?(r=!0,e=n.getToken().trim(),((l=(o=n.getParent())==null?void 0:o.getParent())==null?void 0:l.getToken().trim())===U.COLON&&(t=!0)):e=n.trim();const{tokenTrim:s,minusPrefixNode:i,atPrefixNode:a}=On(e,this._functionService,this._injector);if(!r&&s.charAt(0)==='"'&&s.charAt(s.length-1)==='"')return;let u;if(new RegExp(nt).test(s))u=new St(this._injector,s,new En(s),t);else if(r&&new RegExp(is).test(s))u=new St(this._injector,s,new wn(s),t);else if(r&&new RegExp(as).test(s))u=new St(this._injector,s,new _n(s),t);else{const f=this._formulaRuntimeService.currentUnitId,m=this._superTableService.getTableMap(f),g=new RegExp(Sr,"g"),R=s.replace(g,"");if(!r&&(m!=null&&m.has(R))){const _=g.exec(s);let E="";_&&(E=_[0]);const C=m.get(R),y=this._superTableService.getTableOptionMap();u=new St(this._injector,s,new Ma(s,C,E,y))}}if(u)return a?u.setParent(a):i&&u.setParent(i),u}};bt=ka([Ze(0,Et),Ze(1,cr),Ze(2,ie),Ze(3,he),Ze(4,B.Inject(B.Injector))],bt);var Ta=Object.defineProperty,Ia=Object.getOwnPropertyDescriptor,Qa=(n,r,e,t)=>{for(var s=t>1?void 0:t?Ia(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Ta(r,e,s),s},In=(n,r)=>(e,t)=>r(e,t,n);class Qn extends ee{constructor(r,e,t){super(e),this._accessor=r,this._operatorString=e,this._functionExecutor=t}get nodeType(){return M.SUFFIX}execute(){let e=this.getChildren()[0].getValue(),t;if(e==null)throw new Error("object is null");this._operatorString===me.PERCENTAGE?(e.isReferenceObject()&&(e=e.toArrayValueObject()),t=this._functionExecutor.calculate(e,new w(100)),t.setPattern("0.00%")):this._operatorString===me.POUND?t=this._handlerPound(e):t=new h(c.VALUE),this.setValue(t)}_handlerPound(r){var f,m,g,R;if(!r.isReferenceObject())return new h(c.VALUE);if(!r.isCell())return new h(c.VALUE);const e=this._accessor.get(ve),t=this._accessor.get(Qe),s=r,i=s.getRangePosition(),a=s.getUnitId(),u=s.getSheetId(),o=e.getFormulaData(),l=(R=(g=(m=(f=o==null?void 0:o[a])==null?void 0:f[u])==null?void 0:m[i.startRow])==null?void 0:g[i.startColumn])==null?void 0:R.f;return l?(t.treeBuilder(l),new h(c.VALUE)):new h(c.VALUE)}}let Lt=class extends fe{constructor(n,r){super(),this._functionService=n,this._injector=r}get zIndex(){return le.get(M.SUFFIX)||ce}checkAndCreateNodeType(n){if(!(n instanceof O))return;const r=n.getToken().trim();if(r.charAt(0)==='"'&&r.charAt(r.length-1)==='"')return;let e="";if(r===me.PERCENTAGE)e=z.DIVIDED;else return r===me.POUND?new Qn(this._injector,r):void 0;const t=this._functionService.getExecutor(e);return t?new Qn(this._injector,r,t):(console.error(`No function ${n}`),G.create(c.NAME))}};Lt=Qa([In(0,he),In(1,B.Inject(B.Injector))],Lt);var Ya=Object.defineProperty,Ha=Object.getOwnPropertyDescriptor,ja=(n,r,e,t)=>{for(var s=t>1?void 0:t?Ha(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Ya(r,e,s),s},Wa=(n,r)=>(e,t)=>r(e,t,n);class Xa extends ee{constructor(r){super(r),this._operatorString=r}get nodeType(){return M.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 s;this._operatorString===U.COLON?s=this._unionFunction(e,t):s=new h(c.NAME),this.setValue(s)}_unionFunction(r,e){return r.isError()||e.isError()?new h(c.REF):!r.isReferenceObject()||!e.isReferenceObject()?new h(c.REF):(r=r,e=e,r.isCell()&&e.isCell()||r.isRow()&&e.isRow()||r.isColumn()&&e.isColumn()?r.unionBy(e):new h(c.REF))}}let At=class extends fe{constructor(n){super(),this._functionService=n}get zIndex(){return le.get(M.UNION)||ce}create(n){return new Xa(n)}checkAndCreateNodeType(n){if(!(n instanceof O))return;const e=n.getToken().trim();if(!(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')&&e===U.COLON)return this.create(e)}};At=ja([Wa(0,he)],At);class Ga extends ee{constructor(r){super(r),this._operatorString=r}get nodeType(){return M.VALUE}execute(){this.setValue(Ce.create(this._operatorString))}}class Yn extends fe{get zIndex(){return le.get(M.VALUE)||ce}_checkValueNode(r){if(Number.isNaN(Number(r))){const e=r.trim(),t=e.charAt(0),s=e.charAt(e.length-1);if(je.has(e))return this.create(e);if(t==='"'&&s==='"')return this.create(e);if(t==="{"&&s==="}")return this.create(e);const i=e.toUpperCase();if(i===Se.TRUE||i===Se.FALSE)return this.create(i)}else return this.create(r)}create(r){return new Ga(r)}checkAndCreateNodeType(r){if(!(r instanceof O))return this._checkValueNode(r)}}function Ka(n){let r=n;for(;r!=null&&r.getParent();)r=r.getParent();return r}var za=Object.defineProperty,qa=Object.getOwnPropertyDescriptor,Za=(n,r,e,t)=>{for(var s=t>1?void 0:t?qa(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&za(r,e,s),s},ae=(n,r)=>(e,t)=>r(e,t,n);let Je=class extends d.Disposable{constructor(r,e,t,s,i,a,u,o,l,f,m){super();p(this,"_astNodeFactoryList",[]);p(this,"_refOffsetX",0);p(this,"_refOffsetY",0);this._runtimeService=r,this._astRootNodeFactory=e,this._functionNodeFactory=t,this._lambdaNodeFactory=s,this._lambdaParameterNodeFactory=i,this._operatorNodeFactory=a,this._prefixNodeFactory=u,this._referenceNodeFactory=o,this._suffixNodeFactory=l,this._unionNodeFactory=f,this._valueNodeFactory=m,this._initializeAstNode()}dispose(){this._astNodeFactoryList.forEach(r=>{r.dispose()}),this._astNodeFactoryList=[]}parse(r,e=0,t=0){const s=new lr(_e);return this._refOffsetX=e,this._refOffsetY=t,this._parse(r,s)}_lambdaParameterHandler(r,e){const t=e.getLambdaId(),s=new lr(_e),i=this._runtimeService.getFunctionDefinitionPrivacyVar(t);if(!i)return!1;const a=[...i.keys()],u=r.getChildren(),o=u.length;for(let m=0;m<o;m++){const g=u[m];if(g instanceof O)this._parse(g,s);else return!1}const l=s.getChildren(),f=l.length;for(let m=0;m<f;m++){const g=l[m];i.set(a[m],g)}return s.setParent(e),e}_changeLetToLambda(r){const e=r.getChildren(),t=e.length;if(t%2!==1||t===0)return;const s=new O;s.setToken(Ge);const i=new O;i.setToken(Me);const a=[...e];for(let o=0;o<t;o++){const l=a[o];if(!(l instanceof O))return;o%2===0?l.changeToParent(s):l.changeToParent(i)}s.addChildrenFirst(i),i.setParent(s);const u=r.getParent();return u==null||u.replaceChild(r,s),s}_parse(r,e){const t=r.getChildren(),s=t.length,i=[];let a=null;const u=r.getToken().trim().toUpperCase();if(u===os){const f=this._changeLetToLambda(r);return f!=null?this._parse(f,e):G.create(c.ERROR)}if(u===ge){if(a=e,s===0)return new Pa(_e).setParent(e),a}else{if(u===Me){let f=this._lambdaParameterHandler(r,e);return f===!1&&(f=G.create(c.ERROR)),f}if(a=this._checkAstNode(r),a==null)return G.create(c.ERROR)}const o=t[0];for(let f=0;f<s;f++){const m=t[f];if(Mn(o)){if(f!==0&&f!==s-1)continue}else if(pa(m)&&f!==s-1)continue;let g=null;if(m instanceof O){if(g=this._parse(m,a),g===a)continue}else g=this._checkAstNode(m);if(g==null)return G.create(c.NAME);if(g=Ka(g),g==null)return;switch(g.nodeType){case M.ERROR:return g;case M.FUNCTION:i.push(g);break;case M.LAMBDA:i.push(g);break;case M.LAMBDA_PARAMETER:i.push(g);break;case M.OPERATOR:{const R=i.pop(),_=i.pop();_&&_.setParent(g),R&&R.setParent(g),i.push(g);break}case M.REFERENCE:g.setRefOffset(this._refOffsetX,this._refOffsetY),i.push(g);break;case M.ROOT:i.push(g);break;case M.UNION:i.push(g);break;case M.VALUE:i.push(g);break;case M.PREFIX:i.push(g);break;case M.SUFFIX:i.push(g);break}}const l=i.length;for(let f=0;f<l;f++)i[f].setParent(a);return a}_checkAstNode(r){let e=null;const t=this._astNodeFactoryList.length;for(let s=0;s<t&&(e=this._astNodeFactoryList[s].checkAndCreateNodeType(r),e==null);s++);return e}_initializeAstNode(){this._astNodeFactoryList=[this._astRootNodeFactory,this._functionNodeFactory,this._lambdaNodeFactory,this._lambdaParameterNodeFactory,this._operatorNodeFactory,this._prefixNodeFactory,this._referenceNodeFactory,this._suffixNodeFactory,this._unionNodeFactory,this._valueNodeFactory].sort(d.sortRules)}};Je=Za([ae(0,ie),ae(1,B.Inject(vn)),ae(2,B.Inject(pt)),ae(3,B.Inject(Dt)),ae(4,B.Inject(Tn)),ae(5,B.Inject(yt)),ae(6,B.Inject(wt)),ae(7,B.Inject(bt)),ae(8,B.Inject(Lt)),ae(9,B.Inject(At)),ae(10,B.Inject(Yn))],Je);class Hn extends d.Disposable{constructor(){super(...arguments);p(this,"_referenceExecutorMap",new Map)}dispose(){this._referenceExecutorMap.clear()}remove(e){this._referenceExecutorMap.delete(e)}get(e){return this._referenceExecutorMap.get(e)}has(e){return this._referenceExecutorMap.has(e)}register(e,t){this._referenceExecutorMap.set(e,t)}getReferenceExecutorMap(){return this._referenceExecutorMap}}const Pt=B.createIdentifier("univer.formula.feature-calculation-manager.service");class jn extends d.Disposable{constructor(){super(...arguments);p(this,"_otherFormulaData",{})}dispose(){this._otherFormulaData={}}remove(e){var a,u,o;const{unitId:t,subUnitId:s,formulaId:i}=e;(o=(u=(a=this._otherFormulaData)==null?void 0:a[t])==null?void 0:u[s])==null||delete o[i]}get(e){var a,u;const{unitId:t,subUnitId:s,formulaId:i}=e;return(u=(a=this._otherFormulaData[t])==null?void 0:a[s])==null?void 0:u[i]}has(e){var a,u;const{unitId:t,subUnitId:s,formulaId:i}=e;return((u=(a=this._otherFormulaData[t])==null?void 0:a[s])==null?void 0:u[i])!=null}register(e){const{unitId:t,subUnitId:s,formulaId:i,item:a}=e;this._otherFormulaData[t]&&(this._otherFormulaData[t]={}),this._otherFormulaData[t][s]&&(this._otherFormulaData[t][s]={}),this._otherFormulaData[t][s][i]=a}getOtherFormulaData(){return this._otherFormulaData}}const fr=B.createIdentifier("univer.formula.other-formula-manager.service");class hr extends d.Disposable{constructor(){super(...arguments);p(this,"node");p(this,"children",[]);p(this,"parents",[]);p(this,"formula","");p(this,"row",-1);p(this,"column",-1);p(this,"rowCount",Number.NEGATIVE_INFINITY);p(this,"columnCount",Number.NEGATIVE_INFINITY);p(this,"subUnitId","");p(this,"unitId","");p(this,"rangeList",[]);p(this,"formulaId");p(this,"featureId");p(this,"getDirtyData");p(this,"_state",0)}dispose(){var e;this.children.forEach(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,s=e.startColumn,i=e.endRow,a=e.endColumn;return!(this.row<t||this.row>i||this.column<s||this.column>a)}dependencyRange(e,t,s){var i,a;if(this.rangeList.length===0)return!1;for(let u=0,o=this.rangeList.length;u<o;u++){const l=this.rangeList[u],{unitId:f,sheetId:m,range:g}=l;if(((i=t[f])==null?void 0:i[m])!=null)return!0;if(!e.has(f))continue;const R=e.get(f);if(!R.has(m))continue;const _=R.get(m),E=(a=s==null?void 0:s[f])==null?void 0:a[m];let{startRow:C,endRow:y,startColumn:b,endColumn:L}=g;isNaN(C)&&(C=0),isNaN(b)&&(b=0),isNaN(y)&&(y=Number.POSITIVE_INFINITY),isNaN(L)&&(L=Number.POSITIVE_INFINITY);for(const V of _){const{startRow:T,startColumn:Q,endRow:I,endColumn:x}=V;if(!(C>I||y<T||b>x||L<Q)){let v=!0;if(E==null||E.forValue(($,k)=>{if($>=C&&$<=y&&k>=b&&k<=L)return v=!1,!1}),v)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,s=this.rangeList.length;t<s;t++){const i=this.rangeList[t],a=i.unitId,u=i.sheetId,o=i.range;if(e.unitId===a&&e.subUnitId===u&&e.inRangeData(o))return!0}return!1}_pushParent(e){this.parents.push(e)}}var Ja=Object.defineProperty,Na=Object.getOwnPropertyDescriptor,eu=(n,r,e,t)=>{for(var s=t>1?void 0:t?Na(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Ja(r,e,s),s},Be=(n,r)=>(e,t)=>r(e,t,n);const tu=1e5,mr=new rt(tu);let Ne=class extends d.Disposable{constructor(r,e,t,s,i,a,u){super();p(this,"_updateRangeFlattenCache",new Map);p(this,"_dirtyUnitSheetNameMap",{});this._currentConfigService=r,this._runtimeService=e,this._otherFormulaManagerService=t,this._featureCalculationManagerService=s,this._interpreter=i,this._astTreeBuilder=a,this._lexer=u}dispose(){this._updateRangeFlattenCache.clear(),mr.clear(),this._dirtyUnitSheetNameMap={}}async generate(){this._updateRangeFlatten();const r=this._currentConfigService.getFormulaData(),e=this._otherFormulaManagerService.getOtherFormulaData(),t=this._currentConfigService.getUnitData(),s=await this._generateTreeList(r,e,t),i=this._getUpdateTreeListAndMakeDependency(s);this._checkIsCycleDependency(i)&&this._runtimeService.enableCycleDependency();const u=this._calculateRunList(i);return Promise.resolve(u)}_isCyclicUtil(r,e,t){if(!e.has(r)){e.add(r),t.add(r);for(let s=0;s<r.children.length;s++)if(!e.has(r.children[s])&&this._isCyclicUtil(r.children[s],e,t)||t.has(r.children[s]))return!0}return t.delete(r),!1}_checkIsCycleDependency(r){const e=new Set,t=new Set;for(let s=0,i=r.length;s<i;s++){const a=r[s];if(this._isCyclicUtil(a,e,t)===!0)return!0}return!1}async _generateTreeList(r,e,t){const s=Object.keys(r),i=Object.keys(e),a=[];for(const u of s){const o=r[u];if(o==null)continue;const l=Object.keys(o);for(const f of l)new d.ObjectMatrix(o[f]).forValue((g,R,_)=>{if(_==null)return!0;const{f:E,x:C,y}=_,b=this._generateAstNode(E,C,y),L=new hr,V=t[u][f];L.node=b,L.formula=E,L.unitId=u,L.subUnitId=f,L.row=g,L.column=R,L.rowCount=V.rowCount,L.columnCount=V.columnCount,a.push(L)})}for(const u of i){const o=e[u];if(o==null)continue;const l=Object.keys(o);for(const f of l){const m=o[f];if(m==null)continue;const g=Object.keys(m);for(const R of g){const _=m[R],{f:E}=_,C=this._generateAstNode(E),y=new hr;y.node=C,y.formula=E,y.unitId=u,y.subUnitId=f,y.formulaId=R,a.push(y)}}}this._featureCalculationManagerService.getReferenceExecutorMap().forEach((u,o)=>{const{unitId:l,subUnitId:f,dependencyRanges:m,getDirtyData:g}=u,R=new hr;R.unitId=l,R.subUnitId=f,R.getDirtyData=g,R.featureId=o,R.rangeList=m,a.push(R)});for(let u=0,o=a.length;u<o;u++){const l=a[u];if(this._runtimeService.setCurrent(l.row,l.column,l.rowCount,l.columnCount,l.subUnitId,l.unitId),l.node==null)continue;const f=await this._getRangeListByNode(l.node);for(let m=0,g=f.length;m<g;m++)l.pushRangeList(f[m])}return a}_updateRangeFlatten(){const r=this._currentConfigService.isForceCalculate(),e=this._currentConfigService.getDirtyRanges();if(!r){this._updateRangeFlattenCache.clear();for(let t=0;t<e.length;t++){const s=e[t],i=s.range,a=s.sheetId,u=s.unitId;this._addFlattenCache(u,a,i)}this._dirtyUnitSheetNameMap=this._currentConfigService.getDirtyNameMap()}}_generateAstNode(r,e=0,t=0){let s=mr.get(`${r}##${e}${t}`);if(s)return s;const i=this._lexer.treeBuilder(r);if(je.has(i))return G.create(i);if(s=this._astTreeBuilder.parse(i,e,t),s==null)throw new Error("astNode is null");return mr.set(`${r}##${e}${t}`,s),s}_addFlattenCache(r,e,t){let s=this._updateRangeFlattenCache.get(r);s==null&&(s=new Map,this._updateRangeFlattenCache.set(r,s));let i=s.get(e);i==null&&(i=[],s.set(e,i)),i.push(t)}_isPreCalculateNode(r){return r.nodeType===M.UNION||r.nodeType===M.PREFIX&&r.getToken()===H.AT||r.nodeType===M.SUFFIX&&r.getToken()===me.POUND}_nodeTraversalRef(r,e){const t=r.getChildren(),s=t.length;for(let i=0;i<s;i++){const a=t[i];if(this._isPreCalculateNode(a)){e.push(a);continue}else a.nodeType===M.REFERENCE&&e.push(a);this._nodeTraversalRef(a,e)}}_nodeTraversalReferenceFunction(r,e){const t=r.getChildren(),s=t.length;for(let i=0;i<s;i++){const a=t[i];if(a.nodeType===M.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 s=[];for(let i=0,a=e.length;i<a;i++){const u=e[i],l=(await this._executeNode(u)).toUnitRange();s.push(l)}for(let i=0,a=t.length;i<a;i++){const u=t[i],l=(await this._executeNode(u)).toUnitRange();s.push(l)}return s}_getUpdateTreeListAndMakeDependency(r){const e=[],t=new Set,s=this._currentConfigService.isForceCalculate();for(let i=0,a=r.length;i<a;i++){const u=r[i];for(let o=0,l=r.length;o<l;o++){const f=r[o];u!==f&&u.dependency(f)&&u.pushChildren(f)}(s||u.dependencyRange(this._updateRangeFlattenCache,this._dirtyUnitSheetNameMap,this._currentConfigService.getExcludedRange())||this._includeTree(u))&&!t.has(u)&&(e.push(u),t.add(u))}return e}_includeTree(r){var l,f,m,g,R;const e=r.unitId,t=r.subUnitId,s=r.featureId;if(s!=null){const _=this._currentConfigService.getDirtyUnitFeatureMap();if(((f=(l=_==null?void 0:_[e])==null?void 0:l[t])==null?void 0:f[s])!=null)return!0}const i=(g=(m=this._currentConfigService.getExcludedRange())==null?void 0:m[e])==null?void 0:g[t];let a=!1;if(i==null||i.forValue((_,E)=>{if(r.row===_&&r.column===E)return a=!0,!1}),a)return!1;if(((R=this._dirtyUnitSheetNameMap[e])==null?void 0:R[t])!=null)return!0;if(!this._updateRangeFlattenCache.has(e))return!1;const u=this._updateRangeFlattenCache.get(e);if(!u.has(t))return!1;const o=u.get(t);for(const _ of o)if(r.inRangeData(_))return!0;return!1}_calculateRunList(r){let e=r;const t=[];for(;e.length>0;){const s=e.pop();if(s===void 0||s.isSkip())continue;if(s.isAdded()){t.push(s);continue}const i=[];for(let a=0,u=s.parents.length;a<u;a++){const o=s.parents[a];i.push(o)}i.length===0?(t.push(s),s.setSkip()):(s.setAdded(),e.push(s),e=e.concat(i))}return t.reverse()}};Ne=eu([d.OnLifecycle(d.LifecycleStages.Rendered,Ne),Be(0,ve),Be(1,ie),Be(2,fr),Be(3,Pt),Be(4,B.Inject(Ye)),Be(5,B.Inject(Je)),Be(6,B.Inject(Qe))],Ne);var ru=Object.defineProperty,nu=Object.getOwnPropertyDescriptor,su=(n,r,e,t)=>{for(var s=t>1?void 0:t?nu(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&ru(r,e,s),s},Ue=(n,r)=>(e,t)=>r(e,t,n);const iu=1;D.CalculateFormulaService=class extends d.Disposable{constructor(e,t,s,i,a,u,o){super();p(this,"_executionStartListener$",new Ft.Subject);p(this,"executionStartListener$",this._executionStartListener$.asObservable());p(this,"_executionCompleteListener$",new Ft.Subject);p(this,"executionCompleteListener$",this._executionCompleteListener$.asObservable());p(this,"_executionInProgressListener$",new Ft.Subject);p(this,"executionInProgressListener$",this._executionInProgressListener$.asObservable());this._configService=e,this._lexer=t,this._currentConfigService=s,this._runtimeService=i,this._formulaDependencyGenerator=a,this._interpreter=u,this._astTreeBuilder=o}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")||iu;for(let s=0;s<t&&(await this._execute(),!!this._runtimeService.isCycleDependency());s++);this._runtimeService.setFormulaExecuteStage(oe.CALCULATION_COMPLETED),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState()),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData()),tr.clear(),we.clear()}async _execute(){const e=await this._apply();if(e==null)return;const{arrayFormulaRange:t,runtimeFeatureRange:s}=e,{dirtyRanges:i,excludedCell:a}=this._getArrayFormulaDirtyRangeAndExcludedRange(t,s);return i==null||i.length===0||(this._currentConfigService.loadDirtyRangesAndExcludedCell(i,a),await this._apply(!0)),!0}_getArrayFormulaDirtyRangeAndExcludedRange(e,t){const s=[],i={};return Object.keys(e).forEach(a=>{const u=e[a];if(u==null)return!0;Object.keys(u).forEach(o=>{const l=new d.ObjectMatrix(u[o]);if(l==null)return!0;const f=new d.ObjectMatrix;l.forValue((m,g,R)=>{f.setValue(m,g,!0),s.push({unitId:a,sheetId:o,range:R})}),i[a]==null&&(i[a]={}),i[a][o]=f})}),Object.keys(t).forEach(a=>{const u=t[a];Object.keys(u).forEach(o=>{const l=u[o];if(l==null)return!0;Object.keys(l).forEach(f=>{const m=l[f];if(m==null)return!0;for(const g of m)s.push({unitId:o,sheetId:f,range:g})})})}),{dirtyRanges:s,excludedCell:i}}async _apply(e=!1){e?this._runtimeService.setFormulaExecuteStage(oe.START_DEPENDENCY_ARRAY_FORMULA):this._runtimeService.setFormulaExecuteStage(oe.START_DEPENDENCY),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());const t=await this._formulaDependencyGenerator.generate(),s=this._interpreter;e?(this._runtimeService.setFormulaExecuteStage(oe.START_CALCULATION_ARRAY_FORMULA),this._runtimeService.setTotalArrayFormulasToCalculate(t.length)):(this._runtimeService.setFormulaExecuteStage(oe.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(m=>{d.requestImmediateMacroTask(m)}),this._runtimeService.isStopExecution()){this._runtimeService.setFormulaExecuteStage(oe.IDLE),this._runtimeService.markedAsStopFunctionsExecuted(),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData());return}const u=t[i],o=u.node,l=u.getDirtyData;let f;if(o==null&&l==null)throw new Error("AstNode or executor is null");if(this._runtimeService.setCurrent(u.row,u.column,u.rowCount,u.columnCount,u.subUnitId,u.unitId),l!=null&&u.featureId!=null){const{runtimeCellData:m,dirtyRanges:g}=l(u);this._runtimeService.setRuntimeFeatureCellData(u.featureId,m),this._runtimeService.setRuntimeFeatureRange(u.featureId,g)}else o!=null&&(s.checkAsyncNode(o)?f=await s.executeAsync(o):f=s.execute(o),u.formulaId!=null?this._runtimeService.setRuntimeOtherData(u.formulaId,f):this._runtimeService.setRuntimeData(f));e?(this._runtimeService.setFormulaExecuteStage(oe.CURRENTLY_CALCULATING_ARRAY_FORMULA),this._runtimeService.setCompletedArrayFormulasCount(i+1)):(this._runtimeService.setFormulaExecuteStage(oe.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 s=this._lexer.treeBuilder(e,t);if(Object.values(c).includes(s))return G.create(s);const i=this._astTreeBuilder.parse(s);i==null||i.serialize()}},D.CalculateFormulaService=su([d.OnLifecycle(d.LifecycleStages.Rendered,D.CalculateFormulaService),Ue(0,d.IConfigService),Ue(1,B.Inject(Qe)),Ue(2,ve),Ue(3,ie),Ue(4,B.Inject(Ne)),Ue(5,B.Inject(Ye)),Ue(6,B.Inject(Je))],D.CalculateFormulaService);const gr={id:"formula.mutation.set-numfmt-formula-data",type:d.CommandType.MUTATION,handler:(n,r)=>(n.get(D.FormulaDataModel).updateNumfmtItemMap(r.numfmtItemMap),!0)};var au=Object.defineProperty,uu=Object.getOwnPropertyDescriptor,ou=(n,r,e,t)=>{for(var s=t>1?void 0:t?uu(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&au(r,e,s),s},Vt=(n,r)=>(e,t)=>r(e,t,n);let xt=class extends d.Disposable{constructor(n,r,e,t){super(),this._commandService=n,this._calculateFormulaService=r,this._currentUniverService=e,this._formulaDataModel=t,this._initialize()}_initialize(){this._commandExecutedListener(),this._initialExecuteFormulaListener(),this._initialExecuteFormulaProcessListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((n,r)=>{if(n.id===Gt.id)this._calculateFormulaService.stopFormulaExecution();else if(n.id===zt.id){const e=n.params.formulaData;this._formulaDataModel.setFormulaData(e)}else if(n.id===Xt.id){const e=n.params;if(e.forceCalculation===!0)this._calculate(!0);else{const{dirtyRanges:t,dirtyNameMap:s,dirtyUnitFeatureMap:i,numfmtItemMap:a}=e;this._calculate(!1,t,s,i,a)}}else if(n.id===at.id){const e=n.params;if(e==null)return;const{arrayFormulaRange:t,arrayFormulaCellData:s}=e;this._formulaDataModel.setArrayFormulaRange(t),this._formulaDataModel.setArrayFormulaCellData(s)}}))}async _calculate(n=!1,r=[],e={},t={},s={}){if(r.length===0&&Object.keys(e).length===0&&Object.keys(t).length===0&&n===!1)return;const i=this._formulaDataModel.getFormulaData(),a=this._formulaDataModel.getArrayFormulaCellData();this._calculateFormulaService.execute({formulaData:i,arrayFormulaCellData:a,forceCalculate:n,dirtyRanges:r,dirtyNameMap:e,dirtyUnitFeatureMap:t,numfmtItemMap:s})}_initialExecuteFormulaListener(){this._calculateFormulaService.executionCompleteListener$.subscribe(n=>{const r=n.functionsExecutedState;switch(r){case Ie.NOT_EXECUTED:break;case Ie.STOP_EXECUTION:break;case Ie.SUCCESS:this._applyFormula(n);break;case Ie.INITIAL:break}this._commandService.executeCommand(lt.id,{functionsExecutedState:r},{onlyLocal:!0})})}_initialExecuteFormulaProcessListener(){this._calculateFormulaService.executionInProgressListener$.subscribe(n=>{this._commandService.executeCommand(lt.id,{stageInfo:n},{onlyLocal:!0})})}async _applyFormula(n){const{unitData:r,unitOtherData:e,arrayFormulaRange:t,arrayFormulaCellData:s,clearArrayFormulaCellData:i,numfmtItemMap:a}=n;if(!r){console.error("No sheetData from Formula Engine!");return}t&&(this._formulaDataModel.clearPreviousArrayFormulaCellData(i),this._formulaDataModel.mergeArrayFormulaCellData(s),this._formulaDataModel.mergeArrayFormulaRange(t),this._commandService.executeCommand(at.id,{arrayFormulaRange:this._formulaDataModel.getArrayFormulaRange(),arrayFormulaCellData:this._formulaDataModel.getArrayFormulaCellData()},{onlyLocal:!0})),d.Tools.isEmptyObject(a)||this._commandService.executeCommand(gr.id,{numfmtItemMap:a},{onlyLocal:!0}),this._commandService.executeCommand(Kt.id,{unitData:rs(r),unitOtherData:e},{onlyLocal:!0})}};xt=ou([d.OnLifecycle(d.LifecycleStages.Ready,xt),Vt(0,d.ICommandService),Vt(1,B.Inject(D.CalculateFormulaService)),Vt(2,d.IUniverInstanceService),Vt(3,B.Inject(D.FormulaDataModel))],xt);var lu=Object.defineProperty,cu=Object.getOwnPropertyDescriptor,fu=(n,r,e,t)=>{for(var s=t>1?void 0:t?cu(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&lu(r,e,s),s},dr=(n,r)=>(e,t)=>r(e,t,n);let et=class extends d.Disposable{constructor(n=[],r,e,t){super(),this._function=n,this._commandService=r,this._injector=e,this._functionService=t,this._initialize()}_initialize(){this._registerCommands(),this._registerFunctions()}_registerCommands(){[zt,at,Xt,Gt,lt,Kt,gr,ut,ot,jt,Wt,qt,Zt,Fr,$r,Jt,$t,Nt].forEach(n=>this.disposeWithMe(this._commandService.registerCommand(n)))}_registerFunctions(){const n=[...Nr,...sn,...an,...on,...cn,...fn,...mn,...dn,...Rn,...Cn,...yn,...Sn,...Ln,...An,...Pn,...Vn].concat(this._function).map(r=>{const e=r[0],t=r[1];return new e(t)});this._functionService.registerExecutors(...n)}};et=fu([d.OnLifecycle(d.LifecycleStages.Ready,et),dr(1,d.ICommandService),dr(2,B.Inject(B.Injector)),dr(3,he)],et);var hu=Object.defineProperty,mu=Object.getOwnPropertyDescriptor,gu=(n,r,e,t)=>{for(var s=t>1?void 0:t?mu(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&hu(r,e,s),s},Rr=(n,r)=>(e,t)=>r(e,t,n);let vt=class extends d.Disposable{constructor(n,r,e){super(),this._commandService=n,this._formulaDataModel=r,this._functionService=e,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((n,r)=>{if(n.id===$t.id){const e=n.params;if(e==null)return;const{functions:t}=e,s=t.map(i=>{const a=i[0],u=i[1];return Ru(a,u)});this._functionService.registerExecutors(...s)}else if(n.id===Nt.id){const e=n.params;if(e==null)return;const{functions:t}=e;this._functionService.unregisterExecutors(...t)}}))}};vt=gu([d.OnLifecycle(d.LifecycleStages.Ready,vt),Rr(0,d.ICommandService),Rr(1,B.Inject(D.FormulaDataModel)),Rr(2,he)],vt);class du extends A{isCustom(){return!0}}function Ru(n,r){const e=new du(r),t=new Function(`return ${n}`)();return e.calculateCustom=t,e}var Eu=Object.defineProperty,_u=Object.getOwnPropertyDescriptor,wu=(n,r,e,t)=>{for(var s=t>1?void 0:t?_u(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Eu(r,e,s),s},Wn=(n,r)=>(e,t)=>r(e,t,n);let Bt=class extends d.Disposable{constructor(n,r){super(),this._commandService=n,this._definedNamesService=r,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===ut.id){const r=n.params;if(r==null)return;const{unitId:e,name:t,formulaOrRefString:s}=r;this._definedNamesService.registerDefinedName(e,t,s)}else if(n.id===ot.id){const r=n.params;if(r==null)return;const{unitId:e,name:t}=r;this._definedNamesService.removeDefinedName(e,t)}}))}};Bt=wu([d.OnLifecycle(d.LifecycleStages.Ready,Bt),Wn(0,d.ICommandService),Wn(1,Et)],Bt);var Cu=Object.defineProperty,pu=Object.getOwnPropertyDescriptor,Du=(n,r,e,t)=>{for(var s=t>1?void 0:t?pu(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Cu(r,e,s),s},Xn=(n,r)=>(e,t)=>r(e,t,n);let Ut=class extends d.Disposable{constructor(n,r){super(),this._commandService=n,this._featureCalculationManagerService=r,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===jt.id){const r=n.params;if(r==null)return;const{featureId:e,calculationParam:t}=r;this._featureCalculationManagerService.register(e,t)}else if(n.id===Wt.id){const r=n.params;if(r==null)return;const{featureId:e}=r;this._featureCalculationManagerService.remove(e)}}))}};Ut=Du([d.OnLifecycle(d.LifecycleStages.Ready,Ut),Xn(0,d.ICommandService),Xn(1,Pt)],Ut);var yu=Object.defineProperty,Su=Object.getOwnPropertyDescriptor,bu=(n,r,e,t)=>{for(var s=t>1?void 0:t?Su(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&yu(r,e,s),s},Gn=(n,r)=>(e,t)=>r(e,t,n);let Ot=class extends d.Disposable{constructor(n,r){super(),this._commandService=n,this._otherFormulaManagerService=r,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===qt.id){const r=n.params;if(r==null)return;this._otherFormulaManagerService.register(r)}else if(n.id===Zt.id){const r=n.params;if(r==null)return;this._otherFormulaManagerService.remove(r)}}))}};Ot=bu([d.OnLifecycle(d.LifecycleStages.Ready,Ot),Gn(0,d.ICommandService),Gn(1,fr)],Ot);var Lu=Object.defineProperty,Au=Object.getOwnPropertyDescriptor,Pu=(n,r,e,t)=>{for(var s=t>1?void 0:t?Au(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Lu(r,e,s),s},Kn=(n,r)=>(e,t)=>r(e,t,n);let Mt=class extends d.Disposable{constructor(n,r){super(),this._commandService=n,this._superTableService=r,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===ut.id){const r=n.params;if(r==null)return;const{unitId:e,tableName:t,reference:s}=r;this._superTableService.registerTable(e,t,s)}else if(n.id===ot.id){const r=n.params;if(r==null)return;const{unitId:e,tableName:t}=r;this._superTableService.remove(e,t)}else if(n.id===Jt.id){const r=n.params;if(r==null)return;const{tableOption:e,tableOptionType:t}=r;this._superTableService.registerTableOptionMap(e,t)}}))}};Mt=Pu([d.OnLifecycle(d.LifecycleStages.Ready,Mt),Kn(0,d.ICommandService),Kn(1,cr)],Mt);var Vu=Object.defineProperty,xu=Object.getOwnPropertyDescriptor,vu=(n,r,e,t)=>{for(var s=t>1?void 0:t?xu(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Vu(r,e,s),s},Bu=(n,r)=>(e,t)=>r(e,t,n);const Uu="base-formula-engine";D.UniverFormulaEnginePlugin=class extends d.Plugin{constructor(r,e){super(Uu),this._config=r,this._injector=e}onStarting(){this._initialize()}_initialize(){var e;const r=[[he,{useClass:Bn}],[Pt,{useClass:Hn}],[Et,{useClass:Ji}],[D.FormulaDataModel],[it],[et,{useFactory:()=>{var t;return this._injector.createInstance(et,(t=this._config)==null?void 0:t.function)}}],[Ut]];(e=this._config)!=null&&e.notExecuteFormula||r.push([D.CalculateFormulaService],[fr,{useClass:jn}],[cr,{useClass:Oa}],[ve,{useClass:ar}],[ie,{useClass:ur}],[xt],[Bt],[Ot],[Mt],[vt],[Ne],[Ye],[Je],[Qe],[vn],[pt],[Dt],[Tn],[yt],[wt],[bt],[Lt],[At],[Yn]),r.forEach(t=>this._injector.add(t))}onReady(){this._injector.get(D.FormulaDataModel).initFormulaData()}},D.UniverFormulaEnginePlugin=vu([Bu(1,B.Inject(B.Injector))],D.UniverFormulaEnginePlugin),D.ArrayValueObject=J,D.BaseFunction=A,D.BaseReferenceObject=ke,D.BaseValueObject=Re,D.BooleanValueObject=P,D.ErrorType=c,D.ErrorValueObject=h,D.FUNCTION_NAMES_ARRAY=Is,D.FUNCTION_NAMES_COMPATIBILITY=Te,D.FUNCTION_NAMES_CUBE=un,D.FUNCTION_NAMES_DATABASE=ln,D.FUNCTION_NAMES_DATE=pe,D.FUNCTION_NAMES_ENGINEERING=hn,D.FUNCTION_NAMES_FINANCIAL=gn,D.FUNCTION_NAMES_INFORMATION=se,D.FUNCTION_NAMES_LOGICAL=xe,D.FUNCTION_NAMES_LOOKUP=K,D.FUNCTION_NAMES_MATH=N,D.FUNCTION_NAMES_STATISTICAL=q,D.FUNCTION_NAMES_TEXT=Rt,D.FUNCTION_NAMES_UNIVER=Zi,D.FUNCTION_NAMES_WEB=xn,D.FeatureCalculationManagerService=Hn,D.FormulaExecuteStageType=oe,D.FormulaExecutedStateType=Ie,D.FunctionService=Bn,D.FunctionType=_r,D.IFeatureCalculationManagerService=Pt,D.IFunctionService=he,D.LexerNode=O,D.LexerTreeBuilder=it,D.NumberValueObject=w,D.OtherFormulaManagerService=jn,D.RangeReferenceObject=qe,D.RegisterFunctionMutation=$t,D.RemoveDefinedNameMutation=ot,D.RemoveFeatureCalculationMutation=Wt,D.RemoveOtherFormulaMutation=Zt,D.RemoveSuperTableMutation=$r,D.SetArrayFormulaDataMutation=at,D.SetArrayFormulaDataUndoMutationFactory=ws,D.SetDefinedNameMutation=ut,D.SetFeatureCalculationMutation=jt,D.SetFormulaCalculationNotificationMutation=lt,D.SetFormulaCalculationResultMutation=Kt,D.SetFormulaCalculationStartMutation=Xt,D.SetFormulaCalculationStopMutation=Gt,D.SetFormulaDataMutation=zt,D.SetNumfmtFormulaDataMutation=gr,D.SetOtherFormulaMutation=qt,D.SetSuperTableMutation=Fr,D.SetSuperTableOptionMutation=Jt,D.StringValueObject=X,D.UnregisterFunctionMutation=Nt,D.ValueObjectFactory=Ce,D.compareToken=S,D.convertUnitDataToRuntime=pr,D.deserializeRangeForR1C1=Jr,D.deserializeRangeWithSheet=Fe,D.functionArray=Nr,D.functionCompatibility=sn,D.functionCube=an,D.functionDatabase=on,D.functionDate=cn,D.functionEngineering=fn,D.functionFinancial=mn,D.functionInformation=dn,D.functionLogical=Rn,D.functionLookup=Cn,D.functionMath=yn,D.functionMeta=Sn,D.functionStatistical=Ln,D.functionText=An,D.functionUniver=Pn,D.functionWeb=Vn,D.generateStringWithSequence=Br,D.getAbsoluteRefTypeWitString=hs,D.getAbsoluteRefTypeWithSingleString=Ke,D.includeFormulaLexerToken=Cr,D.initSheetFormulaData=Mr,D.isFormulaLexerToken=We,D.isInDirtyRange=Er,D.isReferenceString=br,D.matchRefDrawToken=ts,D.matchToken=U,D.normalizeSheetName=es,D.operatorToken=Y,D.sequenceNodeType=te,D.serializeRange=ye,D.serializeRangeToRefString=xr,D.serializeRangeWithSheet=Pr,D.serializeRangeWithSpreadsheet=Vr,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});