@univerjs/engine-formula 0.1.0-beta.3 → 0.1.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +3535 -2988
- package/lib/types/basics/common.d.ts +1 -1
- package/lib/types/basics/error-type.d.ts +1 -1
- package/lib/types/engine/ast-node/reference-node.d.ts +2 -1
- package/lib/types/engine/utils/array-object.d.ts +19 -0
- package/lib/types/engine/utils/compare.d.ts +5 -0
- package/lib/types/engine/utils/object-compare.d.ts +7 -0
- package/lib/types/engine/value-object/array-value-object.d.ts +37 -3
- package/lib/types/engine/value-object/base-value-object.d.ts +1 -0
- package/lib/types/functions/__tests__/{create-command-test-bed.d.ts → create-function-test-bed.d.ts} +1 -1
- package/lib/types/functions/base-function.d.ts +16 -1
- package/lib/types/functions/information/function-map.d.ts +3 -1
- package/lib/types/functions/information/isblank/__tests__/index.spec.d.ts +16 -0
- package/lib/types/functions/information/isblank/index.d.ts +20 -0
- package/lib/types/functions/logical/and/__tests__/index.spec.d.ts +16 -0
- package/lib/types/functions/logical/and/index.d.ts +20 -0
- package/lib/types/functions/logical/function-map.d.ts +2 -1
- package/lib/types/functions/logical/if/__tests__/index.spec.d.ts +16 -0
- package/lib/types/functions/logical/if/index.d.ts +22 -0
- package/lib/types/functions/logical/iferror/__tests__/index.spec.d.ts +16 -0
- package/lib/types/functions/logical/iferror/index.d.ts +20 -0
- package/lib/types/functions/lookup/function-map.d.ts +4 -1
- package/lib/types/functions/lookup/hlookup/__tests__/index.spec.d.ts +16 -0
- package/lib/types/functions/lookup/hlookup/index.d.ts +21 -0
- package/lib/types/functions/lookup/lookup/__tests__/index.spec.d.ts +16 -0
- package/lib/types/functions/lookup/lookup/index.d.ts +23 -0
- package/lib/types/functions/lookup/offset/__tests__/index.spec.d.ts +16 -0
- package/lib/types/functions/lookup/offset/index.d.ts +5 -3
- package/lib/types/functions/lookup/xlookup/__tests__/index.spec.d.ts +16 -0
- package/lib/types/functions/lookup/xlookup/index.d.ts +24 -0
- package/lib/types/functions/math/sumifs/index.d.ts +3 -2
- package/lib/types/functions/text/concatenate/__tests__/index.spec.d.ts +16 -0
- package/lib/types/functions/text/concatenate/index.d.ts +2 -3
- package/lib/types/services/current-data.service.d.ts +1 -0
- package/lib/umd/index.js +1 -1
- package/package.json +4 -4
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var An=Object.defineProperty;var On=(t,n,e)=>n in t?An(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e;var p=(t,n,e)=>(On(t,typeof n!="symbol"?n+"":n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("@univerjs/core"),P=require("@wendellhu/redi"),St=require("rxjs");function Sr(t,n,e,r,s){for(let i=0,a=t.length;i<a;i++){const o=t[i];if(n!==o.unitId||e!==o.sheetId)continue;const{startRow:u,startColumn:l,endRow:c,endColumn:h}=o.range;if(r>=u&&r<=c&&s>=l&&s<=h)return!0}return!1}var f=(t=>(t.DIV_BY_ZERO="#DIV/0!",t.NAME="#NAME!",t.VALUE="#VALUE!",t.NUM="#NUM!",t.NA="#N/A",t.CYCLE="#CYCLE!",t.REF="#REF!",t.SPILL="#SPILL!",t.CALC="#CALC!",t.ERROR="#ERROR!",t.CONNECT="#GETTING_DATA",t.NULL="#NULL!",t))(f||{});const Tt=new Set(Object.values(f));var Pr=(t=>(t[t.Financial=0]="Financial",t[t.Date=1]="Date",t[t.Math=2]="Math",t[t.Statistical=3]="Statistical",t[t.Lookup=4]="Lookup",t[t.Database=5]="Database",t[t.Text=6]="Text",t[t.Logical=7]="Logical",t[t.Information=8]="Information",t[t.Engineering=9]="Engineering",t[t.Cube=10]="Cube",t[t.Compatibility=11]="Compatibility",t[t.Web=12]="Web",t[t.Array=13]="Array",t[t.Univer=14]="Univer",t[t.User=15]="User",t))(Pr||{}),G=(t=>(t.PLUS="+",t.MINUS="-",t.MULTIPLY="*",t.DIVIDED="/",t.CONCATENATE="&",t.POWER="^",t.EQUALS="=",t.NOT_EQUAL="<>",t.GREATER_THAN=">",t.GREATER_THAN_OR_EQUAL=">=",t.LESS_THAN="<",t.LESS_THAN_OR_EQUAL="<=",t))(G||{}),w=(t=>(t.EQUALS="=",t.NOT_EQUAL="<>",t.GREATER_THAN=">",t.GREATER_THAN_OR_EQUAL=">=",t.LESS_THAN="<",t.LESS_THAN_OR_EQUAL="<=",t))(w||{});const Ie=new Map([["<>",3],["<",3],[">=",3],["=",3],[">",3],["<=",3],["&",2],["+",2],["-",2],["/",1],["*",1],["^",0]]),Fe=new Set(Ie.keys()),Bn=new Set(["=","<>",">",">=","<","<="]);var O=(t=>(t.OPEN_BRACKET="(",t.CLOSE_BRACKET=")",t.COMMA=",",t.SINGLE_QUOTATION="'",t.DOUBLE_QUOTATION='"',t.OPEN_BRACES="{",t.CLOSE_BRACES="}",t.COLON=":",t.OPEN_SQUARE_BRACKET="[",t.CLOSE_SQUARE_BRACKET="]",t))(O||{}),ie=(t=>(t.PERCENTAGE="%",t.POUND="#",t))(ie||{});const Un=new Set(["%","#"]);var j=(t=>(t.AT="@",t.MINUS="-",t))(j||{});const xr=[...Object.values(w),...Object.values(G),...Object.values(O),...Object.values(ie),...Object.values(j)];function ze(t){return xr.includes(t)}function Vr(t){for(const n of xr)if(t.indexOf(n)>-1)return!0;return!1}function Fn(t){return t[0]==="'"&&t[t.length-1]==="'"?t.substring(1,t.length-1):t}function vr(t){const n={};return Object.keys(t).forEach(e=>{const r=t[e];if(r==null)return!0;n[e]==null&&(n[e]={}),Object.keys(r).forEach(s=>{const i=r[s];n[e][s]=new g.ObjectMatrix(i)})}),n}const Ht={id:"formula.mutation.register-function",type:g.CommandType.MUTATION,handler:()=>!0};class Rt{constructor(n){p(this,"_cache");this._cache=new g.LRUMap(n)}set(n,e){const r=this._hash(n);this._cache.set(r,e)}get(n){const e=this._hash(n);return this._cache.get(e)}clear(){this._cache.clear()}_hash(n){return g.hashAlgorithm(n)}}const ae='\\[([^\\[\\]\\/?:"<>|*\\\\]+)\\]',Mn=/[^0-9]/g,$n=/[^A-Za-z]/g;function Me(t){const n=t[0]==="$",r=t.substring(1).indexOf("$")>-1;return n&&r?g.AbsoluteRefType.ALL:n?g.AbsoluteRefType.COLUMN:r?g.AbsoluteRefType.ROW:g.AbsoluteRefType.NONE}function kn(t){const n=t.split("!");n.length>1&&(t=n[n.length-1]);const e=t.split(":");return e.length>1?{startAbsoluteRefType:Me(e[0]),endAbsoluteRefType:Me(e[1])}:{startAbsoluteRefType:Me(e[0])}}function sr(t=g.AbsoluteRefType.NONE){let n="",e="";return t===g.AbsoluteRefType.ROW?n="$":t===g.AbsoluteRefType.COLUMN?e="$":t===g.AbsoluteRefType.ALL&&(n="$",e="$"),{rowAbsoluteString:n,columnAbsoluteString:e}}function Ee(t){const{startColumn:n,startRow:e,endColumn:r,endRow:s,startAbsoluteRefType:i,endAbsoluteRefType:a,rangeType:o=g.RANGE_TYPE.NORMAL}=t,u=sr(i),l=sr(a);if(o===g.RANGE_TYPE.ROW||o===g.RANGE_TYPE.ALL){const m=`${u.rowAbsoluteString}${e+1}`,D=`${l.rowAbsoluteString}${s+1}`;return`${m}:${D}`}if(o===g.RANGE_TYPE.COLUMN){const m=`${u.columnAbsoluteString}${g.Tools.chatAtABC(n)}`,D=`${l.columnAbsoluteString}${g.Tools.chatAtABC(r)}`;return`${m}:${D}`}const c=`${u.columnAbsoluteString}${g.Tools.chatAtABC(n)}${u.rowAbsoluteString}${e+1}`,h=`${l.columnAbsoluteString}${g.Tools.chatAtABC(r)}${l.rowAbsoluteString}${s+1}`;return c===h?c:`${c}:${h}`}function Ar(t,n){return nt(t)?`'${t}'!${Ee(n)}`:`${t}!${Ee(n)}`}function Or(t,n,e){return nt(t)||nt(n)?`'[${t}]${n}'!${Ee(e)}`:`[${t}]${n}!${Ee(e)}`}function Br(t){const{unitId:n,sheetName:e,range:r}=t;return n!=null&&n.length>0&&e!=null&&e.length>0?Or(n,e,r):e!=null&&e.length>0?Ar(e,r):Ee(r)}function Pt(t){const n=Number.parseInt(t.replace(Mn,""))-1,e=g.Tools.ABCatNum(t.replace($n,"")),r=Me(t);return{row:n,column:e,absoluteRefType:r}}function Ur(t){const n=new RegExp(ae).exec(t);let e="";n!=null&&(e=n[0].trim(),e=e.slice(1,e.length-1),t=t.replace(new RegExp(ae),""));const r=t.indexOf("!");let s="",i="";return r>-1?(s=t.substring(0,r),s[0]==="'"&&s[s.length-1]==="'"&&(s=s.substring(1,s.length-1)),i=t.substring(r)):i=t,{refBody:i,sheetName:s,unitId:e}}function ve(t){const{refBody:n,sheetName:e,unitId:r}=Ur(t),s=n.indexOf(":");if(s===-1){const _=Pt(n),R=_.row,E=_.column,y=_.absoluteRefType;return{unitId:r,sheetName:e,range:{startRow:R,startColumn:E,endRow:R,endColumn:E,startAbsoluteRefType:y,endAbsoluteRefType:y}}}const i=n.substring(0,s),a=n.substring(s+1),o=Pt(i),u=Pt(a),l=o.row,c=o.column,h=u.row,m=u.column;let D=g.RANGE_TYPE.NORMAL;return isNaN(l)&&isNaN(h)?D=g.RANGE_TYPE.COLUMN:isNaN(c)&&isNaN(m)&&(D=g.RANGE_TYPE.ROW),{unitId:r,sheetName:e,range:{startRow:l,startColumn:c,endRow:h,endColumn:m,startAbsoluteRefType:o.absoluteRefType,endAbsoluteRefType:u.absoluteRefType,rangeType:D}}}function nt(t){return t.length===0?!1:!!(Vr(t)||jn(t)||Qn(t)||Tn(t)||/[\s!$%^&*()+\-=\[\]{};':"\\|,.<>\/?]/.test(t))}function jn(t){const n=t.match(/[1-9][0-9]{0,6}/);return/^[A-Z]+[1-9][0-9]{0,6}$/.test(t)&&n!==null&&Number.parseInt(n[0],10)<=1048576}function Qn(t){return/^(R(-?[0-9]+)?C(-?[0-9]+)?|C(-?[0-9]+)?|R(-?[0-9]+)?)$/.test(t)}function Tn(t){return!new RegExp("^\\p{Letter}","u").test(t.charAt(0))}const Ae="((?![\\[\\]\\/?*\\\\]).)*!",he="$",Yt="\\s*?:\\s*?",Mt=`\\${he}?[A-Za-z]+\\${he}?[0-9]+`,Hn=`^(${j.AT})?(${ae})?(${Ae})?${Mt}${Yt}${Mt}$`,pt=`^(${ae})?(${Ae})?\\s*?${Mt}(${ie.POUND})?$`,Fr=`^(${ae})?(${Ae})?\\${he}?[0-9]+${Yt}\\${he}?[0-9]+$`,Mr=`^(${ae})?(${Ae})?\\${he}?[A-Za-z]+${Yt}\\${he}?[A-Za-z]+$`,Yn=`^(${ae})?(${Ae})?\\s*?\\${he}?[0-9]+$`,Wn=`^(${ae})?(${Ae})?\\s*?\\${he}?[A-Za-z]+$`,$r="[.*?]",Xn="{.*?}";function Gn(t){return new RegExp(pt).test(t)||new RegExp(Hn).test(t)||new RegExp(Fr).test(t)||new RegExp(Mr).test(t)}const Re="P_1",ce="R_1",xe="L_1",He="LR_1",kr="LO_1",Kn="LET",je="LAMBDA";var I=(t=>(t[t.NORMAL=0]="NORMAL",t[t.NUMBER=1]="NUMBER",t[t.STRING=2]="STRING",t[t.FUNCTION=3]="FUNCTION",t[t.REFERENCE=4]="REFERENCE",t[t.ARRAY=5]="ARRAY",t))(I||{});function jr(t){let n="";for(const e of t)typeof e=="string"?n+=e:n+=e.token;return n}class V{constructor(){p(this,"_parent");p(this,"_token",ce);p(this,"_children",[]);p(this,"_lambdaId");p(this,"_functionDefinitionPrivacyVar");p(this,"_lambdaParameter","");p(this,"_startIndex",-1);p(this,"_endIndex",-1)}dispose(){var n;this._children.forEach(e=>{typeof e!="string"&&e.dispose()}),(n=this._functionDefinitionPrivacyVar)==null||n.clear(),this._parent=null}getStartIndex(){return this._startIndex}getLambdaId(){return this._lambdaId}setLambdaId(n){this._lambdaId=n}getFunctionDefinitionPrivacyVar(){return this._functionDefinitionPrivacyVar}setLambdaPrivacyVar(n){this._functionDefinitionPrivacyVar=n}getLambdaParameter(){return this._lambdaParameter}setLambdaParameter(n){this._lambdaParameter=n}getParent(){return this._parent}setParent(n){this._parent=n}getChildren(){return this._children}setChildren(n){this._children=n}addChildren(n){this._children.push(n)}addChildrenFirst(n){this._children.unshift(n)}getToken(){return this._token}setToken(n){this._token=n}setIndex(n,e){this._startIndex=n,this._endIndex=e}replaceChild(n,e){const r=this._getIndexInParent(n);r!=null&&(this.getChildren().splice(r,1,e),e.setParent(this))}changeToParent(n){const e=this.getParent();e&&e.removeChild(this),this.setParent(n),n.getChildren().push(this)}removeChild(n){const e=this._getIndexInParent(n);e!=null&&this.getChildren().splice(e,1)}serialize(){const n=this.getToken(),e=this.getChildren(),r=[],s=e.length;for(let i=0;i<s;i++){const a=e[i];a instanceof V?r.push(a.serialize()):r.push(a)}return{token:n,st:this._startIndex,ed:this._endIndex,children:r}}_getIndexInParent(n){const e=this.getChildren(),r=e.length;for(let s=0;s<r;s++)if(e[s]===n)return s}}const Qr=1e5,xt=new Rt(Qr),Vt=new Rt(Qr);class Dt extends g.Disposable{constructor(){super(...arguments);p(this,"_currentLexerNode",new V);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(),xt.clear(),Vt.clear()}getUpLevel(){return this._upLevel}isColonClose(){return this._colonState===!1}isColonOpen(){return this._colonState===!0}isDoubleQuotationClose(){return this._doubleQuotationState===0}isLambdaOpen(){return this._lambdaState===!0}isLambdaClose(){return this._lambdaState===!1}isSingleQuotationClose(){return this._singleQuotationState===0}isBracesClose(){return this._bracesState===0}isBracketClose(){return this._bracketState.length===0}isSquareBracketClose(){return this._squareBracketState===0}getCurrentLexerNode(){return this._currentLexerNode}getFunctionAndParameter(e,r){const s=this._getCurrentParamIndex(e,r);if(s==null||s===f.VALUE)return;const i=s[0];if(typeof i=="string")return;let a=i.getParent(),o=i;for(;a;){const u=a.getToken();if(u!==Re&&!ze(u)&&a.getStartIndex()!==-1){const l=a.getChildren().indexOf(o);return{functionName:u,paramIndex:l}}o=a,a=a.getParent()}}moveFormulaRefOffset(e,r,s){const i=this.sequenceNodesBuilder(e);if(i==null)return e;const a=[];for(let o=0,u=i.length;o<u;o++){const l=i[o];if(typeof l=="string"||l.nodeType!==I.REFERENCE){a.push(l);continue}const{token:c}=l,h=ve(c),{range:m,sheetName:D,unitId:_}=h,R=g.Rectangle.moveOffset(m,r,s);let E="";g.isValidRange(R)?E=Br({range:R,unitId:_,sheetName:D}):E=f.REF,a.push({...l,token:E})}return`=${jr(a)}`}checkIfAddBracket(e){let r=0,s=e.length-1,i=e[s];for(;(i===O.CLOSE_BRACKET||i===" ")&&s>=0;)i===O.CLOSE_BRACKET&&r++,i=e[--s];const a=this._getCurrentParamIndex(e,e.length-2);if(a==null||a===f.VALUE)return 0;const o=a[0];if(typeof o=="string")return 0;let u=o.getParent(),l=0;for(;u;){const c=u.getToken();c!==Re&&c!==O.COLON&&u.getStartIndex()!==-1&&c.toUpperCase()!==je&&(r===0?l+=1:r--),u=u.getParent()}return l}sequenceNodesBuilder(e){const r=Vt.get(e);if(r)return[...r];const s=this._getSequenceArray(e);if(s.length===0)return;const i=this.getSequenceNode(s);return Vt.set(e,[...i]),i}getSequenceNode(e){const r=[];let s=!1;for(let i=0,a=e.length;i<a;i++){const o=e[i],u=e[i-1],{segment:l,currentString:c,cur:h}=o;if(c===O.DOUBLE_QUOTATION&&(s=!0),(l!==""||i===0)&&i!==a-1){r.push(c);continue}let m=(u==null?void 0:u.segment)||"";const D=i-m.length;let _=i-1;const R=i-1;if(i===a-1&&this._isLastMergeString(c)&&(m+=c,_+=1),m===""||Ie.has(m)){r.push(c);continue}const E=m.trim(),y=this._replacePrefixString(E);s===!0&&E[E.length-1]===O.DOUBLE_QUOTATION?(s=!1,this._pushSequenceNode(r,{nodeType:I.STRING,token:m,startIndex:D,endIndex:_},R)):new RegExp(pt).test(y)?this._pushSequenceNode(r,{nodeType:I.REFERENCE,token:m,startIndex:D,endIndex:_},R):g.Tools.isStringNumber(E)?this._pushSequenceNode(r,{nodeType:I.NUMBER,token:m,startIndex:D,endIndex:_},R):E.length>0&&this._pushSequenceNode(r,{nodeType:I.FUNCTION,token:m,startIndex:D,endIndex:_},R),(i!==a-1||!this._isLastMergeString(c))&&r.push(c)}return this._mergeSequenceNodeReference(r)}_getCurrentParamIndex(e,r){return this._nodeMaker(e,void 0,r)}_isLastMergeString(e){return e===O.DOUBLE_QUOTATION||g.Tools.isStringNumber(e)||!ze(e)}_mergeSequenceNodeReference(e){const r=[],s=e.length;let i=0;for(;i<s;){const a=e[i];if(typeof a=="string"){const o=e[i-1];if(a.trim()===O.CLOSE_BRACES&&o!=null&&typeof o!="string"&&o.nodeType===I.FUNCTION&&o.token.trim().substring(0,1)===O.OPEN_BRACES){o.nodeType=I.ARRAY,o.token+=a,o.endIndex+=a.length,i++;continue}r.push(a)}else{const o=e[i+1],u=e[i+2];o===O.COLON&&typeof a!="string"&&u!=null&&typeof u!="string"&&Gn((a.token+o+u.token).trim())&&(a.nodeType=I.REFERENCE,a.token+=o+u.token,a.endIndex=u.endIndex,i+=2),r.push(a)}i++}return r}_pushSequenceNode(e,r,s){const i=s-r.startIndex+1;e.splice(e.length-i,i,r)}_replacePrefixString(e){return e.replace(new RegExp(j.AT,"g"),"").replace(new RegExp(j.MINUS,"g"),"")}nodeMakerTest(e){return this._nodeMaker(e)}treeBuilder(e,r=!0,s){if(r===!0){const c=xt.get(e);if(c)return c}this._resetCurrentLexerNode(),this._currentLexerNode.setToken(ce);const i=[];let a=this._nodeMaker(e,i);if(a===f.VALUE||i.length===0)return a;let o=!1,u="";if(s){const{hasDefinedName:c,sequenceString:h}=s(i);o=c,u=h}if(o&&(this._resetCurrentLexerNode(),this._currentLexerNode.setToken(ce),a=this._nodeMaker(`=${u}`),a===f.VALUE))return a;const l=this._getTopNode(this._currentLexerNode);return l&&(this._currentLexerNode=l),r&&(this._suffixExpressionHandler(this._currentLexerNode),xt.set(e,this._currentLexerNode)),this._currentLexerNode}_suffixExpressionHandler(e){var o,u;const r=e.getChildren();if(!r)return;const s=r.length,i=[],a=[];for(let l=0;l<s;l++){const c=r[l];if(c instanceof V)this._suffixExpressionHandler(c),i.push(c);else{const h=c.trim();if(h==="")continue;if(Fe.has(h)){for(;a.length>0;){const m=(o=a[a.length-1])==null?void 0:o.trim();if(!m||m===O.OPEN_BRACKET)break;const D=Ie.get(m),_=Ie.get(h);if(!D||!_)break;if(_>D)i.push(a.pop());else break}a.push(c)}else if(h===O.OPEN_BRACKET)a.push(c);else if(h===O.CLOSE_BRACKET)for(;a.length>0;){const m=(u=a[a.length-1])==null?void 0:u.trim();if(!m)break;if(m===O.OPEN_BRACKET){a.pop();break}i.push(a.pop())}else i.push(c)}}for(;a.length>0;)i.push(a.pop());e.setChildren(i)}_resetCurrentLexerNode(){this._currentLexerNode=new V}_resetSegment(){this._segment=""}_openBracket(e=0){this._bracketState.push(e)}_closeBracket(){this._bracketState.pop()}_openSquareBracket(){this._squareBracketState+=1}_closeSquareBracket(){this._squareBracketState-=1}_getCurrentBracket(){const e=this._bracketState;return e[e.length-1]}_openBraces(){this._bracesState+=1}_closeBraces(){this._bracesState-=1}_openSingleQuotation(){this._singleQuotationState+=1}_closeSingleQuotation(){this._singleQuotationState-=1}_openDoubleQuotation(){this._doubleQuotationState+=1}_closeDoubleQuotation(){this._doubleQuotationState-=1}_openLambda(){this._lambdaState=!0}_closeLambda(){this._lambdaState=!1}_openColon(e){this._upLevel=e,this._colonState=!0}_closeColon(){this._upLevel=0,this._colonState=!1}_isTableBracket(){return this._tableBracketState}_openTableBracket(){this._tableBracketState=!0}_closeTableBracket(){this._tableBracketState=!1}_getLastChildCurrentLexerNode(){const e=this._currentLexerNode.getChildren();if(e&&e.length>0){const r=e[e.length-1];if(r instanceof V)return r}return!1}_getLastChildCurrent(){const e=this._currentLexerNode.getChildren();return e&&e.length>0?e[e.length-1]:!1}_setParentCurrentLexerNode(){const e=this._currentLexerNode.getParent();return e?(this._currentLexerNode=e,!0):!1}_setAncestorCurrentLexerNode(){var s,i,a,o,u,l;const e=(s=this._currentLexerNode)==null?void 0:s.getParent();let r=!1;if(e&&e.getToken()===xe){if((i=e==null?void 0:e.getParent())!=null&&i.getParent()){const c=(o=(a=this._currentLexerNode.getParent())==null?void 0:a.getParent())==null?void 0:o.getParent();c&&(this._currentLexerNode=c),r=!0}}else if(e!=null&&e.getParent()){const c=(u=this._currentLexerNode.getParent())==null?void 0:u.getParent();c&&(this._currentLexerNode=c),r=!0}for(let c=0;c<this._upLevel;c++){const h=(l=this._currentLexerNode)==null?void 0:l.getParent();h&&(this._currentLexerNode=h),this._currentLexerNode?r=!0:r=!1}return r}_segmentCount(){return this._segment.trim().length}_pushSegment(e){this._segment+=e}_pushNodeToChildren(e,r=!1){if(e!==""){const s=this._currentLexerNode.getChildren();if(!(e instanceof V)&&this.isColonOpen()){const i=new V;i.setToken(e),i.setParent(this._currentLexerNode),e=i}r?s.unshift(e):s.push(e)}this.isColonOpen()&&(this._setAncestorCurrentLexerNode(),this._closeColon())}_setCurrentLexerNode(e,r=!1){this._pushNodeToChildren(e,r),e.setParent(this._currentLexerNode),this._currentLexerNode=e}_newAndPushCurrentLexerNode(e,r,s=!1){const i=new V;i.setToken(e),i.setIndex(r-e.length,r-1),this._setCurrentLexerNode(i,s)}_getTopNode(e){let r=e;for(;r!=null&&r.getParent();)r=r.getParent();return r}_removeLastChild(){this._currentLexerNode.getChildren().splice(-1)}_findPreviousToken(e,r){for(;r>=0;){const s=e[r];if(s!==" ")return s;r--}}_negativeCondition(e){return!!(Fe.has(e)||e===O.OPEN_BRACKET||e===O.COMMA||e==="")}_getSequenceArray(e){const r=[];return this._nodeMaker(e,r),r}_resetTemp(){this._currentLexerNode=new V,this._upLevel=0,this._segment="",this._bracketState=[],this._bracesState=0,this._singleQuotationState=0,this._doubleQuotationState=0,this._lambdaState=!1,this._colonState=!1}_checkSimilarErrorToken(e,r,s){if(e!==ie.POUND)return!0;let i=s[++r];for(;i===" ";)i=s[++r];return!!ze(i)}_nodeMaker(e,r,s){e.substring(0,1)===G.EQUALS&&(e=e.substring(1));const i=e.split(""),a=i.length;let o=0;for(this._resetTemp();o<a;){const u=i[o];if(s===o)return[this._currentLexerNode,u];if(u===O.OPEN_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())if(this._segmentCount()>0||this.isLambdaOpen()){this.isLambdaClose()&&(this._newAndPushCurrentLexerNode(this._segment,o),this._resetSegment()),this._openBracket(1),this._closeLambda();const l=i[o+1];if(l&&l===O.CLOSE_BRACKET){if(!this._setParentCurrentLexerNode()&&o!==a-1)return f.VALUE;o++}else l&&this._newAndPushCurrentLexerNode(Re,o)}else this._pushNodeToChildren(u),this._openBracket(0);else if(u===O.CLOSE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()){this._pushNodeToChildren(this._segment),this._resetSegment();const l=this._getCurrentBracket();if(l===0)this._pushNodeToChildren(u);else if(l===1){const c=i[o+1];if(c&&c===O.OPEN_BRACKET){if(!this._setParentCurrentLexerNode()&&o!==a-1)return f.VALUE;this._newAndPushCurrentLexerNode(xe,o,!0),this._openLambda()}else if(!this._setAncestorCurrentLexerNode()&&o!==a-1)return f.VALUE}else return f.VALUE;this._closeBracket()}else if(u===O.OPEN_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(u),this._openBraces();else if(u===O.CLOSE_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(u),this._pushNodeToChildren(this._segment),this._resetSegment(),this._closeBraces();else if(u===O.OPEN_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._segment.length>0&&this._openTableBracket(),this._pushSegment(u),this._openSquareBracket();else if(u===O.CLOSE_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._closeSquareBracket(),this.isSquareBracketClose()?(this._pushSegment(u),this._isTableBracket()&&(this._pushNodeToChildren(this._segment),this._resetSegment()),this._closeTableBracket()):this._pushSegment(u);else if(u===O.DOUBLE_QUOTATION&&this.isSingleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){if(this.isDoubleQuotationClose())this._openDoubleQuotation();else{const l=i[o+1];l&&l===O.DOUBLE_QUOTATION?o++:this._closeDoubleQuotation()}this._pushSegment(u)}else if(u===O.SINGLE_QUOTATION&&this.isDoubleQuotationClose()){if(this.isSingleQuotationClose())this._openSingleQuotation();else{const l=i[o+1];l&&l===O.SINGLE_QUOTATION?o++:this._closeSingleQuotation()}this._pushSegment(u)}else if(u===O.COMMA&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=this._getCurrentBracket();if(l===1||l==null){if(this._pushNodeToChildren(this._segment),this._resetSegment(),!this._setParentCurrentLexerNode()&&o!==a-1&&l!=null)return f.VALUE;this._newAndPushCurrentLexerNode(Re,o)}else return f.VALUE}else if(u===O.COLON&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=new V;l.setToken(u);const c=new V;c.setToken(Re),c.setParent(l);const h=new V;h.setToken(Re),h.setParent(l),l.getChildren().push(c,h);let m=l,D=0;if(this._segmentCount()>0){let _,R,E=0;const y=this._segment.trim(),b=y[0],L=y[1];if(b===j.MINUS&&(_=new V,_.setToken(j.MINUS),E++),(b===j.AT||L===j.AT)&&(R=new V,R.setToken(j.AT),_&&(_.addChildren(R),R.setParent(_)),E++),E>0&&(this._segment=y.slice(E)),D=E,R)if(R.addChildren(l),l.setParent(R),R.getParent()){const $=R.getParent();$&&(m=$)}else m=R;else _&&(m=_,_.addChildren(l),l.setParent(_));const S=new V;S.setToken(this._segment),S.setParent(c),c.getChildren().push(S),this._resetSegment()}else{const _=this._getLastChildCurrentLexerNode();_&&_.changeToParent(c)}this._setCurrentLexerNode(m),this._currentLexerNode=h,this._openColon(D)}else if(Un.has(u)&&this._checkSimilarErrorToken(u,o,i)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){this._pushNodeToChildren(this._segment);const l=new V;l.setToken(u);const c=this._getLastChildCurrent();c instanceof V?c.changeToParent(l):c!==!1&&(l.getChildren().push(c),this._removeLastChild()),this._pushNodeToChildren(l),l.setParent(this._currentLexerNode),this._resetSegment()}else if(Fe.has(u)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){let l=this._segment.trim();if(u===G.MINUS&&l===""){const c=this._findPreviousToken(i,o-1)||"";if(this._negativeCondition(c)){this._pushSegment(G.MINUS),r==null||r.push({segment:this._segment,currentString:u,cur:o,currentLexerNode:this._currentLexerNode}),o++;continue}}else this._segment.length>0&&l===""?l=this._segment:(this._pushNodeToChildren(this._segment),l="");if(u===G.LESS_THAN||u===G.GREATER_THAN){const c=i[o+1];c&&Fe.has(u+c)?(this._pushNodeToChildren(l+u+c),o++):this._pushNodeToChildren(l+u)}else this._pushNodeToChildren(l+u);this._resetSegment()}else this._pushSegment(u);r==null||r.push({segment:this._segment,currentString:u,cur:o,currentLexerNode:this._currentLexerNode}),o++}this._pushNodeToChildren(this._segment)}}var In=Object.defineProperty,zn=Object.getOwnPropertyDescriptor,qn=(t,n,e,r)=>{for(var s=r>1?void 0:r?zn(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&In(n,e,s),s},ir=(t,n)=>(e,r)=>n(e,r,t);exports.FormulaDataModel=class extends g.Disposable{constructor(e,r){super();p(this,"_formulaData",{});p(this,"_arrayFormulaRange",{});p(this,"_arrayFormulaCellData",{});this._currentUniverService=e,this._lexerTreeBuilder=r}clearPreviousArrayFormulaCellData(e){Object.keys(e).forEach(r=>{const s=e[r];if(s==null)return!0;Object.keys(s).forEach(i=>{var l,c,h,m;const a=s[i],o=(c=(l=this._arrayFormulaRange)==null?void 0:l[r])==null?void 0:c[i];if(o==null)return!0;let u=new g.ObjectMatrix;((h=this._arrayFormulaCellData[r])==null?void 0:h[i])!=null&&(u=new g.ObjectMatrix((m=this._arrayFormulaCellData[r])==null?void 0:m[i])),a.forValue((D,_)=>{var S;const R=(S=o==null?void 0:o[D])==null?void 0:S[_];if(R==null)return!0;const{startRow:E,startColumn:y,endRow:b,endColumn:L}=R;for(let $=E;$<=b;$++)for(let k=y;k<=L;k++)u.setValue($,k,null)}),this._arrayFormulaCellData[r]&&(this._arrayFormulaCellData[r][i]=u.getData())})})}mergeArrayFormulaCellData(e){Object.keys(e).forEach(r=>{const s=e[r];if(s==null)return!0;this._arrayFormulaRange[r]==null&&(this._arrayFormulaRange[r]={}),this._arrayFormulaCellData[r]==null&&(this._arrayFormulaCellData[r]={}),Object.keys(s).forEach(i=>{var l,c,h,m;const a=s[i];let o=new g.ObjectMatrix,u=new g.ObjectMatrix;((l=this._arrayFormulaRange[r])==null?void 0:l[i])!=null&&(o=new g.ObjectMatrix((c=this._arrayFormulaRange[r])==null?void 0:c[i])),((h=this._arrayFormulaCellData[r])==null?void 0:h[i])!=null&&(u=new g.ObjectMatrix((m=this._arrayFormulaCellData[r])==null?void 0:m[i])),a.forValue((D,_)=>{const R=o==null?void 0:o.getValue(D,_);if(R==null)return!0;const{startRow:E,startColumn:y,endRow:b,endColumn:L}=R;for(let S=E;S<=b;S++)for(let $=y;$<=L;$++)u.setValue(S,$,null)}),a.forValue((D,_,R)=>{u.setValue(D,_,R)}),this._arrayFormulaCellData[r]&&(this._arrayFormulaCellData[r][i]=u.getData())})})}getFormulaData(){return this._formulaData}setFormulaData(e){this._formulaData=e}setArrayFormulaRange(e){this._arrayFormulaRange=e}getArrayFormulaRange(){return this._arrayFormulaRange}setArrayFormulaCellData(e){this._arrayFormulaCellData=e}getArrayFormulaCellData(){return this._arrayFormulaCellData}mergeArrayFormulaRange(e){Object.keys(e).forEach(r=>{const s=e[r];if(s==null)return!0;this._arrayFormulaRange[r]||(this._arrayFormulaRange[r]={}),Object.keys(s).forEach(i=>{var u,l;const a=new g.ObjectMatrix(s[i]);let o=new g.ObjectMatrix;(u=this._arrayFormulaRange[r])!=null&&u[i]&&(o=new g.ObjectMatrix((l=this._arrayFormulaRange[r])==null?void 0:l[i])),a.forValue((c,h,m)=>{o.setValue(c,h,m)}),this._arrayFormulaRange[r]&&(this._arrayFormulaRange[r][i]=o.getData())})})}deleteArrayFormulaRange(e,r,s,i){var u;const a=(u=this._arrayFormulaRange[e])==null?void 0:u[r];if(a==null)return;const o=new g.ObjectMatrix(a);o.getValue(s,i)&&(o.realDeleteValue(s,i),this._arrayFormulaRange[e]&&(this._arrayFormulaRange[e][r]=o.getData()))}initFormulaData(){this._currentUniverService.getAllUniverSheetsInstance();const e=this._currentUniverService.getCurrentUniverSheetInstance(),r=e.getUnitId();this._formulaData[r]={},e.getSheets().forEach(i=>{const a=i.getCellMatrix(),o=i.getSheetId();Tr(this._formulaData,r,o,a)})}getCalculateData(){const e=this._currentUniverService.getAllUniverSheetsInstance(),r={},s={};for(const i of e){const a=i.getUnitId(),o=i.getSheets(),u={},l={};for(const c of o){const h=c.getSheetId(),m=c.getConfig();u[h]={cellData:new g.ObjectMatrix(m.cellData),rowCount:m.rowCount,columnCount:m.columnCount},l[c.getName()]=c.getSheetId()}r[a]=u,s[a]=l}return{allUnitData:r,unitSheetNameMap:s}}updateFormulaData(e,r,s){const i=new g.ObjectMatrix(s),a=this.getFormulaIdMap(e,r),o=new Map,u=this._formulaData;u[e]==null&&(u[e]={});const l=u[e];l[r]==null&&(l[r]={});const c=new g.ObjectMatrix(l[r]);i.forValue((h,m,D)=>{const _=(D==null?void 0:D.f)||"",R=(D==null?void 0:D.si)||"",E=g.isFormulaString(_),y=g.isFormulaId(R);if(E&&y)c.setValue(h,m,{f:_,si:R}),a.set(R,{f:_,r:h,c:m});else if(E&&!y)c.setValue(h,m,{f:_});else if(!E&&y)c.setValue(h,m,{f:"",si:R});else if(!E&&!y&&c.getValue(h,m)){const b=c.getValue(h,m),L=(b==null?void 0:b.f)||"",S=(b==null?void 0:b.si)||"";g.isFormulaString(L)&&g.isFormulaId(S)&&o.set(S,L),c.realDeleteValue(h,m)}}),c.forValue((h,m,D)=>{const _=(D==null?void 0:D.f)||"",R=(D==null?void 0:D.si)||"";if(g.isFormulaId(R)){const E=a.get(R),y=o.get(R);if(E&&!g.isFormulaString(_)){const b=E.f,L=m-E.c,S=h-E.r;c.setValue(h,m,{f:b,si:R,x:L,y:S})}else if(typeof y=="string"){const b=D.x||0,L=D.y||0,S=this._lexerTreeBuilder.moveFormulaRefOffset(y,b,L);o.set(R,{r:h,c:m,f:S}),c.setValue(h,m,{f:S,si:R})}else if(typeof y=="object"){const b=m-y.c,L=h-y.r;c.setValue(h,m,{f:y.f,si:R,x:b,y:L})}}})}updateArrayFormulaRange(e,r,s){var u;const i=(u=this._arrayFormulaRange[e])==null?void 0:u[r];if(!i)return;const a=new g.ObjectMatrix(i);new g.ObjectMatrix(s).forValue((l,c,h)=>{if((a==null?void 0:a.getValue(l,c))==null)return!0;const D=(h==null?void 0:h.f)||"",_=(h==null?void 0:h.si)||"",R=g.isFormulaString(D),E=g.isFormulaId(_);!R&&!E&&a.realDeleteValue(l,c)})}updateArrayFormulaCellData(e,r,s){var c,h;const i=(c=this._arrayFormulaRange[e])==null?void 0:c[r];if(!i)return;const a=new g.ObjectMatrix(i),o=(h=this._arrayFormulaCellData[e])==null?void 0:h[r];if(!o)return;const u=new g.ObjectMatrix(o);new g.ObjectMatrix(s).forValue((m,D,_)=>{const R=a==null?void 0:a.getValue(m,D);if(R==null)return!0;const E=(_==null?void 0:_.f)||"",y=(_==null?void 0:_.si)||"",b=g.isFormulaString(E),L=g.isFormulaId(y);if(!b&&!L){const{startRow:S,startColumn:$,endRow:k,endColumn:Q}=R;for(let A=S;A<=k;A++)for(let x=$;x<=Q;x++)u.realDeleteValue(A,x)}})}getFormulaItemBySId(e,r,s){const i=this._formulaData;if(i[s]==null)return null;const a=i[s];if((a==null?void 0:a[r])==null)return null;const o=new g.ObjectMatrix(a[r]);let u=null;return o.forValue((l,c,h)=>{const{f:m,si:D,x:_=0,y:R=0}=h;if(D===e&&m.length>0&&_===0&&R===0)return u=h,!1}),u}getFormulaDataItem(e,r,s,i){var a,o,u,l;return(l=(u=(o=(a=this._formulaData)==null?void 0:a[i])==null?void 0:o[s])==null?void 0:u[e])==null?void 0:l[r]}getFormulaIdMap(e,r){const s=new Map,i=this._formulaData;if(i[e]==null)return s;const a=i[e];return(a==null?void 0:a[r])==null||new g.ObjectMatrix(a[r]).forValue((u,l,c)=>{const h=(c==null?void 0:c.f)||"",m=(c==null?void 0:c.si)||"",D=(c==null?void 0:c.x)||0,_=(c==null?void 0:c.y)||0;g.isFormulaString(h)&&g.isFormulaId(m)&&D===0&&_===0&&s.set(m,{f:h,r:u,c:l})}),s}};exports.FormulaDataModel=qn([ir(0,g.IUniverInstanceService),ir(1,P.Inject(Dt))],exports.FormulaDataModel);function Tr(t,n,e,r){const s=new Map,i=new g.ObjectMatrix;r.forValue((a,o,u)=>{const l=(u==null?void 0:u.f)||"",c=(u==null?void 0:u.si)||"",h=g.isFormulaString(l),m=g.isFormulaId(c);h&&m?(i.setValue(a,o,{f:l,si:c}),s.set(c,{f:l,r:a,c:o})):h&&!m?i.setValue(a,o,{f:l}):!h&&m&&i.setValue(a,o,{f:"",si:c})}),i.forValue((a,o,u)=>{const l=(u==null?void 0:u.f)||"",c=(u==null?void 0:u.si)||"";if(g.isFormulaId(c)&&!g.isFormulaString(l)){const h=s.get(c);if(h){const m=h.f,D=o-h.c,_=a-h.r;i.setValue(a,o,{f:m,si:c,x:D,y:_})}}}),t[n]&&(t[n][e]=i.getData())}const Zn=t=>{const n=t.get(exports.FormulaDataModel),e=g.Tools.deepClone(n.getArrayFormulaRange()),r=g.Tools.deepClone(n.getArrayFormulaCellData());return{arrayFormulaRange:e,arrayFormulaCellData:r}},st={id:"formula.mutation.set-array-formula-data",type:g.CommandType.MUTATION,handler:(t,n)=>{const e=t.get(exports.FormulaDataModel);return e.setArrayFormulaRange(n.arrayFormulaRange),e.setArrayFormulaCellData(n.arrayFormulaCellData),!0}},Et={id:"formula.mutation.set-defined-name",type:g.CommandType.MUTATION,handler:()=>!0},_t={id:"formula.mutation.remove-defined-name",type:g.CommandType.MUTATION,handler:()=>!0},Wt={id:"formula.mutation.set-feature-calculation",type:g.CommandType.MUTATION,handler:()=>!0},Xt={id:"formula.mutation.remove-feature-calculation",type:g.CommandType.MUTATION,handler:()=>!0},Gt={id:"formula.mutation.set-formula-calculation-start",type:g.CommandType.MUTATION,handler:()=>!0},Kt={id:"formula.mutation.set-formula-calculation-stop",type:g.CommandType.MUTATION,handler:()=>!0},it={id:"formula.mutation.set-formula-calculation-notification",type:g.CommandType.MUTATION,handler:()=>!0},It={id:"formula.mutation.set-formula-calculation-result",type:g.CommandType.MUTATION,handler:()=>!0},zt={id:"formula.mutation.set-formula-data",type:g.CommandType.MUTATION,handler:(t,n)=>(t.get(exports.FormulaDataModel).setFormulaData(n.formulaData),!0)},qt={id:"formula.mutation.set-other-formula",type:g.CommandType.MUTATION,handler:()=>!0},Zt={id:"formula.mutation.remove-other-formula",type:g.CommandType.MUTATION,handler:()=>!0},Hr={id:"formula.mutation.set-super-table",type:g.CommandType.MUTATION,handler:()=>!0},Yr={id:"formula.mutation.remove-super-table",type:g.CommandType.MUTATION,handler:()=>!0},Jt={id:"formula.mutation.set-super-table-option",type:g.CommandType.MUTATION,handler:()=>!0},Nt={id:"formula.mutation.unregister-function",type:g.CommandType.MUTATION,handler:()=>!0};class Ct extends g.Disposable{isError(){return!1}isAsyncObject(){return!1}isAsyncArrayObject(){return!1}isReferenceObject(){return!1}isValueObject(){return!1}isEqualType(n){return!1}}var _e=(t=>(t.FALSE="FALSE",t.TRUE="TRUE",t))(_e||{}),De=(t=>(t[t.SUCCESS=0]="SUCCESS",t[t.ERROR=1]="ERROR",t))(De||{}),pe=(t=>(t.ALL="#All",t.DATA="#Data",t.HEADERS="#Headers",t.TOTALS="#Totals",t))(pe||{}),Z=(t=>(t[t.FRONT=0]="FRONT",t[t.BACK=1]="BACK",t))(Z||{});class Jn{constructor(){p(this,"_cache",new Map);p(this,"_continueBuildingCache",new Map)}set(n,e,r,s,i){if(!this.shouldContinueBuildingCache(n,e,r,i))return;let a=this._cache.get(n);a==null&&(a=new Map,this._cache.set(n,a));let o=a.get(e);o==null&&(o=new Map,a.set(e,o));let u=o.get(r);u==null&&(u=new Map,o.set(r,u));let l=u.get(s);l==null&&(l=[],u.set(s,l)),l.push(i)}getCellValuePositions(n,e,r){var s,i;return(i=(s=this._cache.get(n))==null?void 0:s.get(e))==null?void 0:i.get(r)}getCellPositions(n,e,r,s){var i,a,o;return(o=(a=(i=this._cache.get(n))==null?void 0:i.get(e))==null?void 0:a.get(r))==null?void 0:o.get(s)}getCellPosition(n,e,r,s,i,a){const o=this.getCellPositions(n,e,r,s);if(o!=null){for(const u of o)if(u>=i&&u<=a)return u}}setContinueBuildingCache(n,e,r,s,i){let a=this._continueBuildingCache.get(n);a==null&&(a=new Map,this._continueBuildingCache.set(n,a));let o=a.get(e);o==null&&(o=new Map,a.set(e,o));let u=o.get(r);if(u==null){u={startRow:s,endRow:i},o.set(r,u);return}u.startRow=Math.min(u.startRow,s),u.endRow=Math.max(u.endRow,i)}shouldContinueBuildingCache(n,e,r,s){var u,l;const i=(l=(u=this._continueBuildingCache.get(n))==null?void 0:u.get(e))==null?void 0:l.get(r);if(i==null)return!0;const{startRow:a,endRow:o}=i;return!(s>=a&&s<=o)}canUseCache(n,e,r,s,i){var l,c;if(r===-1||s===-1||i===-1)return!1;const a=(c=(l=this._continueBuildingCache.get(n))==null?void 0:l.get(e))==null?void 0:c.get(r);if(a==null)return!1;const{startRow:o,endRow:u}=a;return!(s>u||i<o)}clear(){this._cache.clear(),this._continueBuildingCache.clear()}}const ue=new Jn;var qe=(t=>(t[t.MIN=0]="MIN",t[t.MAX=1]="MAX",t))(qe||{});function ar(){return new Intl.Collator(void 0,{numeric:!0}).compare}function Nn(t){return t.indexOf("*")>-1||t.indexOf("?")>-1}function or(t,n){const e=n.replace(/~?[*?]/g,s=>s.startsWith("~")?`\\${s.substring(1)}`:s==="*"?".*":s==="?"?".":s);return new RegExp(`^${e}$`).test(t)}function ur(t){return t.replace(/~?[*?]/g,n=>n.startsWith("~")?n.substring(1):" ")}function es(t,n,e){let r=!1;switch(e){case w.EQUALS:r=or(t,n);break;case w.GREATER_THAN:case w.GREATER_THAN_OR_EQUAL:r=or(t,n)||t>ur(n);break;case w.LESS_THAN:case w.LESS_THAN_OR_EQUAL:r=t<ur(n);break}return r}class de extends Ct{constructor(n){super(),this._rawValue=n}isValueObject(){return!0}toUnitRange(){return{range:{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1},sheetId:"",unitId:""}}getValue(){return 0}getArrayValue(){return[]}setValue(n){}setArrayValue(n){}isArray(){return!1}isString(){return!1}isNumber(){return!1}isBoolean(){return!1}isLambda(){return!1}isError(){return!1}isNull(){return!1}sum(){return new d(f.VALUE)}max(){return new d(f.VALUE)}min(){return new d(f.VALUE)}count(){return new d(f.VALUE)}countA(){return new d(f.VALUE)}countBlank(){return new d(f.VALUE)}getNegative(){return new d(f.NAME)}getReciprocal(){return new d(f.NAME)}plus(n){return new d(f.NAME)}minus(n){return new d(f.NAME)}multiply(n){return new d(f.NAME)}divided(n){return new d(f.NAME)}map(n){return new d(f.NAME)}product(n,e){return e(this,n)}compare(n,e){return new d(f.NAME)}isEqual(n){return this.compare(n,w.EQUALS)}isNotEqual(n){return this.compare(n,w.NOT_EQUAL)}isGreaterThanOrEqual(n){return this.compare(n,w.GREATER_THAN_OR_EQUAL)}isLessThanOrEqual(n){return this.compare(n,w.LESS_THAN_OR_EQUAL)}isLessThan(n){return this.compare(n,w.LESS_THAN)}isGreaterThan(n){return this.compare(n,w.GREATER_THAN)}concatenateFront(n){return new d(f.NAME)}concatenateBack(n){return new d(f.NAME)}plusBy(n){return new d(f.NAME)}minusBy(n){return new d(f.NAME)}multiplyBy(n){return new d(f.NAME)}dividedBy(n){return new d(f.NAME)}compareBy(n,e){return new d(f.NAME)}concatenate(n,e=Z.FRONT){let r=this.getValue().toString();if(typeof n=="string")e===Z.FRONT?r=n+r:r+=n;else if(typeof n=="number")e===Z.FRONT?r=n.toString()+r:r+=n.toString();else if(typeof n=="boolean"){const s=n?"TRUE":"FALSE";e===Z.FRONT?r=s+r:r+=s}return r}pow(n){return new d(f.VALUE)}powInverse(n){return new d(f.VALUE)}sqrt(){return new d(f.VALUE)}cbrt(){return new d(f.VALUE)}cos(){return new d(f.VALUE)}acos(){return new d(f.VALUE)}acosh(){return new d(f.VALUE)}sin(){return new d(f.VALUE)}asin(){return new d(f.VALUE)}asinh(){return new d(f.VALUE)}tan(){return new d(f.VALUE)}tanh(){return new d(f.VALUE)}atan(){return new d(f.VALUE)}atan2(n){return new d(f.VALUE)}atan2Inverse(n){return new d(f.VALUE)}atanh(){return new d(f.VALUE)}mean(){return this}median(){return this}var(){return this}std(){return this}log(){return new d(f.VALUE)}log10(){return new d(f.VALUE)}exp(){return new d(f.VALUE)}abs(){return new d(f.VALUE)}round(n){return new d(f.VALUE)}roundInverse(n){return new d(f.VALUE)}floor(n){return new d(f.VALUE)}floorInverse(n){return new d(f.VALUE)}ceil(n){return new d(f.VALUE)}ceilInverse(n){return new d(f.VALUE)}}class d extends de{constructor(n,e=""){super(n),this._errorType=n,this._errorContent=e}getValue(){return this._errorType}getErrorType(){return this._errorType}getErrorContent(){return this._errorContent}isEqualType(n){return n.getErrorType()===this.getErrorType()}isError(){return!0}}var ts=20,rs=1,Ce=1e6,lr=1e6,ns=-7,ss=21,is=!1,Ye="[big.js] ",ye=Ye+"Invalid ",wt=ye+"decimal places",as=ye+"rounding mode",Wr=Ye+"Division by zero",B={},te=void 0,os=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function Xr(){function t(n){var e=this;if(!(e instanceof t))return n===te?Xr():new t(n);if(n instanceof t)e.s=n.s,e.e=n.e,e.c=n.c.slice();else{if(typeof n!="string"){if(t.strict===!0&&typeof n!="bigint")throw TypeError(ye+"value");n=n===0&&1/n<0?"-0":String(n)}us(e,n)}e.constructor=t}return t.prototype=B,t.DP=ts,t.RM=rs,t.NE=ns,t.PE=ss,t.strict=is,t.roundDown=0,t.roundHalfUp=1,t.roundHalfEven=2,t.roundUp=3,t}function us(t,n){var e,r,s;if(!os.test(n))throw Error(ye+"number");for(t.s=n.charAt(0)=="-"?(n=n.slice(1),-1):1,(e=n.indexOf("."))>-1&&(n=n.replace(".","")),(r=n.search(/e/i))>0?(e<0&&(e=r),e+=+n.slice(r+1),n=n.substring(0,r)):e<0&&(e=n.length),s=n.length,r=0;r<s&&n.charAt(r)=="0";)++r;if(r==s)t.c=[t.e=0];else{for(;s>0&&n.charAt(--s)=="0";);for(t.e=e-r-1,t.c=[],e=0;r<=s;)t.c[e++]=+n.charAt(r++)}return t}function be(t,n,e,r){var s=t.c;if(e===te&&(e=t.constructor.RM),e!==0&&e!==1&&e!==2&&e!==3)throw Error(as);if(n<1)r=e===3&&(r||!!s[0])||n===0&&(e===1&&s[0]>=5||e===2&&(s[0]>5||s[0]===5&&(r||s[1]!==te))),s.length=1,r?(t.e=t.e-n+1,s[0]=1):s[0]=t.e=0;else if(n<s.length){if(r=e===1&&s[n]>=5||e===2&&(s[n]>5||s[n]===5&&(r||s[n+1]!==te||s[n-1]&1))||e===3&&(r||!!s[0]),s.length=n,r){for(;++s[--n]>9;)if(s[n]=0,n===0){++t.e,s.unshift(1);break}}for(n=s.length;!s[--n];)s.pop()}return t}function Oe(t,n,e){var r=t.e,s=t.c.join(""),i=s.length;if(n)s=s.charAt(0)+(i>1?"."+s.slice(1):"")+(r<0?"e":"e+")+r;else if(r<0){for(;++r;)s="0"+s;s="0."+s}else if(r>0)if(++r>i)for(r-=i;r--;)s+="0";else r<i&&(s=s.slice(0,r)+"."+s.slice(r));else i>1&&(s=s.charAt(0)+"."+s.slice(1));return t.s<0&&e?"-"+s:s}B.abs=function(){var t=new this.constructor(this);return t.s=1,t};B.cmp=function(t){var n,e=this,r=e.c,s=(t=new e.constructor(t)).c,i=e.s,a=t.s,o=e.e,u=t.e;if(!r[0]||!s[0])return r[0]?i:s[0]?-a:0;if(i!=a)return i;if(n=i<0,o!=u)return o>u^n?1:-1;for(a=(o=r.length)<(u=s.length)?o:u,i=-1;++i<a;)if(r[i]!=s[i])return r[i]>s[i]^n?1:-1;return o==u?0:o>u^n?1:-1};B.div=function(t){var n=this,e=n.constructor,r=n.c,s=(t=new e(t)).c,i=n.s==t.s?1:-1,a=e.DP;if(a!==~~a||a<0||a>Ce)throw Error(wt);if(!s[0])throw Error(Wr);if(!r[0])return t.s=i,t.c=[t.e=0],t;var o,u,l,c,h,m=s.slice(),D=o=s.length,_=r.length,R=r.slice(0,o),E=R.length,y=t,b=y.c=[],L=0,S=a+(y.e=n.e-t.e)+1;for(y.s=i,i=S<0?0:S,m.unshift(0);E++<o;)R.push(0);do{for(l=0;l<10;l++){if(o!=(E=R.length))c=o>E?1:-1;else for(h=-1,c=0;++h<o;)if(s[h]!=R[h]){c=s[h]>R[h]?1:-1;break}if(c<0){for(u=E==o?s:m;E;){if(R[--E]<u[E]){for(h=E;h&&!R[--h];)R[h]=9;--R[h],R[E]+=10}R[E]-=u[E]}for(;!R[0];)R.shift()}else break}b[L++]=c?l:++l,R[0]&&c?R[E]=r[D]||0:R=[r[D]]}while((D++<_||R[0]!==te)&&i--);return!b[0]&&L!=1&&(b.shift(),y.e--,S--),L>S&&be(y,S,e.RM,R[0]!==te),y};B.eq=function(t){return this.cmp(t)===0};B.gt=function(t){return this.cmp(t)>0};B.gte=function(t){return this.cmp(t)>-1};B.lt=function(t){return this.cmp(t)<0};B.lte=function(t){return this.cmp(t)<1};B.minus=B.sub=function(t){var n,e,r,s,i=this,a=i.constructor,o=i.s,u=(t=new a(t)).s;if(o!=u)return t.s=-u,i.plus(t);var l=i.c.slice(),c=i.e,h=t.c,m=t.e;if(!l[0]||!h[0])return h[0]?t.s=-u:l[0]?t=new a(i):t.s=1,t;if(o=c-m){for((s=o<0)?(o=-o,r=l):(m=c,r=h),r.reverse(),u=o;u--;)r.push(0);r.reverse()}else for(e=((s=l.length<h.length)?l:h).length,o=u=0;u<e;u++)if(l[u]!=h[u]){s=l[u]<h[u];break}if(s&&(r=l,l=h,h=r,t.s=-t.s),(u=(e=h.length)-(n=l.length))>0)for(;u--;)l[n++]=0;for(u=n;e>o;){if(l[--e]<h[e]){for(n=e;n&&!l[--n];)l[n]=9;--l[n],l[e]+=10}l[e]-=h[e]}for(;l[--u]===0;)l.pop();for(;l[0]===0;)l.shift(),--m;return l[0]||(t.s=1,l=[m=0]),t.c=l,t.e=m,t};B.mod=function(t){var n,e=this,r=e.constructor,s=e.s,i=(t=new r(t)).s;if(!t.c[0])throw Error(Wr);return e.s=t.s=1,n=t.cmp(e)==1,e.s=s,t.s=i,n?new r(e):(s=r.DP,i=r.RM,r.DP=r.RM=0,e=e.div(t),r.DP=s,r.RM=i,this.minus(e.times(t)))};B.neg=function(){var t=new this.constructor(this);return t.s=-t.s,t};B.plus=B.add=function(t){var n,e,r,s=this,i=s.constructor;if(t=new i(t),s.s!=t.s)return t.s=-t.s,s.minus(t);var a=s.e,o=s.c,u=t.e,l=t.c;if(!o[0]||!l[0])return l[0]||(o[0]?t=new i(s):t.s=s.s),t;if(o=o.slice(),n=a-u){for(n>0?(u=a,r=l):(n=-n,r=o),r.reverse();n--;)r.push(0);r.reverse()}for(o.length-l.length<0&&(r=l,l=o,o=r),n=l.length,e=0;n;o[n]%=10)e=(o[--n]=o[n]+l[n]+e)/10|0;for(e&&(o.unshift(e),++u),n=o.length;o[--n]===0;)o.pop();return t.c=o,t.e=u,t};B.pow=function(t){var n=this,e=new n.constructor("1"),r=e,s=t<0;if(t!==~~t||t<-lr||t>lr)throw Error(ye+"exponent");for(s&&(t=-t);t&1&&(r=r.times(n)),t>>=1,!!t;)n=n.times(n);return s?e.div(r):r};B.prec=function(t,n){if(t!==~~t||t<1||t>Ce)throw Error(ye+"precision");return be(new this.constructor(this),t,n)};B.round=function(t,n){if(t===te)t=0;else if(t!==~~t||t<-Ce||t>Ce)throw Error(wt);return be(new this.constructor(this),t+this.e+1,n)};B.sqrt=function(){var t,n,e,r=this,s=r.constructor,i=r.s,a=r.e,o=new s("0.5");if(!r.c[0])return new s(r);if(i<0)throw Error(Ye+"No square root");i=Math.sqrt(r+""),i===0||i===1/0?(n=r.c.join(""),n.length+a&1||(n+="0"),i=Math.sqrt(n),a=((a+1)/2|0)-(a<0||a&1),t=new s((i==1/0?"5e":(i=i.toExponential()).slice(0,i.indexOf("e")+1))+a)):t=new s(i+""),a=t.e+(s.DP+=4);do e=t,t=o.times(e.plus(r.div(e)));while(e.c.slice(0,a).join("")!==t.c.slice(0,a).join(""));return be(t,(s.DP-=4)+t.e+1,s.RM)};B.times=B.mul=function(t){var n,e=this,r=e.constructor,s=e.c,i=(t=new r(t)).c,a=s.length,o=i.length,u=e.e,l=t.e;if(t.s=e.s==t.s?1:-1,!s[0]||!i[0])return t.c=[t.e=0],t;for(t.e=u+l,a<o&&(n=s,s=i,i=n,l=a,a=o,o=l),n=new Array(l=a+o);l--;)n[l]=0;for(u=o;u--;){for(o=0,l=a+u;l>u;)o=n[l]+i[u]*s[l-u-1]+o,n[l--]=o%10,o=o/10|0;n[l]=o}for(o?++t.e:n.shift(),u=n.length;!n[--u];)n.pop();return t.c=n,t};B.toExponential=function(t,n){var e=this,r=e.c[0];if(t!==te){if(t!==~~t||t<0||t>Ce)throw Error(wt);for(e=be(new e.constructor(e),++t,n);e.c.length<t;)e.c.push(0)}return Oe(e,!0,!!r)};B.toFixed=function(t,n){var e=this,r=e.c[0];if(t!==te){if(t!==~~t||t<0||t>Ce)throw Error(wt);for(e=be(new e.constructor(e),t+e.e+1,n),t=t+e.e+1;e.c.length<t;)e.c.push(0)}return Oe(e,!1,!!r)};B[Symbol.for("nodejs.util.inspect.custom")]=B.toJSON=B.toString=function(){var t=this,n=t.constructor;return Oe(t,t.e<=n.NE||t.e>=n.PE,!!t.c[0])};B.toNumber=function(){var t=Number(Oe(this,!0,!0));if(this.constructor.strict===!0&&!this.eq(t.toString()))throw Error(Ye+"Imprecise conversion");return t};B.toPrecision=function(t,n){var e=this,r=e.constructor,s=e.c[0];if(t!==te){if(t!==~~t||t<1||t>Ce)throw Error(ye+"precision");for(e=be(new r(e),t,n);e.c.length<t;)e.c.push(0)}return Oe(e,t<=e.e||e.e<=r.NE||e.e>=r.PE,!!s)};B.valueOf=function(){var t=this,n=t.constructor;if(n.strict===!0)throw Error(Ye+"valueOf disallowed");return Oe(t,t.e<=n.NE||t.e>=n.PE,!0)};var H=Xr();function Gr(t){let n;switch(t){case w.EQUALS:n=w.EQUALS;break;case w.GREATER_THAN:n=w.LESS_THAN;break;case w.GREATER_THAN_OR_EQUAL:n=w.LESS_THAN_OR_EQUAL;break;case w.LESS_THAN:n=w.GREATER_THAN;break;case w.LESS_THAN_OR_EQUAL:n=w.GREATER_THAN_OR_EQUAL;break;case w.NOT_EQUAL:n=w.NOT_EQUAL;break}return n}function er(t,n){return H(t).times(n).toNumber()}function cr(t,n){const e=10**Math.floor(n);return Math.round(er(t,e))/e}function hr(t,n){const e=10**Math.floor(n);return Math.floor(er(t,e))/e}function fr(t,n){const e=10**Math.floor(n);return Math.ceil(er(t,e))/e}function dr(t,n){return t**n}class Qe extends de{isNull(){return!0}plus(n){return new C(0,!0).plus(n)}minus(n){return new C(0,!0).minus(n)}multiply(n){return new C(0,!0).multiply(n)}divided(n){return new C(0,!0).divided(n)}compare(n,e){return n.isString()?new Y("").compare(n,e):n.isBoolean()?new W(!1).compare(n,e):new C(0,!0).compare(n,e)}concatenateFront(n){return n.isArray()?n.concatenateBack(new Y("")):new Y(this.concatenate(n.getValue(),Z.FRONT))}concatenateBack(n){return n.isArray()?n.concatenateFront(new Y("")):new Y(this.concatenate(n.getValue(),Z.BACK))}plusBy(n){return new C(0).plusBy(n)}minusBy(n){return new C(0).minusBy(n)}multiplyBy(n){return new C(0).multiplyBy(n)}dividedBy(n){return new C(0).dividedBy(n)}compareBy(n,e){return typeof n=="string"?new Y("").compareBy(n,e):typeof n=="boolean"?new W(!1).compareBy(n,e):new C(0,!0).compareBy(n,e)}pow(n){return new C(0,!0).pow(n)}sqrt(){return new C(0,!0)}cbrt(){return new C(0,!0)}cos(){return new C(0,!0)}acos(){return new C(0,!0)}acosh(){return new C(0,!0)}sin(){return new C(0,!0)}asin(){return new C(0,!0)}asinh(){return new C(0,!0)}tan(){return new C(0,!0)}tanh(){return new C(0,!0)}atan(){return new C(0,!0)}atan2(n){return new C(0,!0).atan2(n)}atanh(){return new C(0,!0)}log(){return new d(f.NUM)}log10(){return new d(f.NUM)}exp(){return new d(f.NUM)}abs(){return new d(f.NUM)}round(n){return new C(0,!0).round(n)}floor(n){return new C(0,!0).floor(n)}ceil(n){return new C(0,!0).ceil(n)}}class W extends de{constructor(e,r=!1){super(e);p(this,"_value",!1);if(r){this._value=e;return}if(typeof e=="boolean")this._value=e;else if(typeof e=="string"){const s=e.toLocaleUpperCase();s===_e.TRUE?this._value=!0:s===_e.FALSE&&(this._value=!1)}else e===1?this._value=!0:this._value=!1}getValue(){return this._value}isBoolean(){return!0}getNegative(){const e=this.getValue();let r=0;return e&&(r=1),new C(-r,!0)}getReciprocal(){return this.getValue()?new C(1,!0):new d(f.DIV_BY_ZERO)}plus(e){return this._convertTonNumber().plus(e)}minus(e){return this._convertTonNumber().minus(e)}multiply(e){return this._convertTonNumber().multiply(e)}divided(e){return this._convertTonNumber().divided(e)}compare(e,r){return this._convertTonNumber().compare(e,r)}concatenateFront(e){return this._convertTonNumber().concatenateFront(e)}concatenateBack(e){return this._convertTonNumber().concatenateBack(e)}_convertTonNumber(){const e=this.getValue();let r=0;return e&&(r=1),new C(r,!0)}pow(e){return this._convertTonNumber().pow(e)}sqrt(){return this._convertTonNumber()}cbrt(){return this._convertTonNumber()}cos(){return this._convertTonNumber().cos()}acos(){return this._convertTonNumber().acos()}acosh(){return this._convertTonNumber().acosh()}sin(){return this._convertTonNumber().sin()}asin(){return this._convertTonNumber().asin()}asinh(){return this._convertTonNumber().asinh()}tan(){return this._convertTonNumber().tan()}tanh(){return this._convertTonNumber().tanh()}atan(){return this._convertTonNumber().atan()}atan2(e){return this._convertTonNumber().atan2(e)}atanh(){return this._convertTonNumber().atanh()}log(){return this._convertTonNumber().log()}log10(){return this._convertTonNumber().log10()}exp(){return this._convertTonNumber().exp()}abs(){return this._convertTonNumber().abs()}round(e){return this._convertTonNumber().round(e)}floor(e){return this._convertTonNumber().floor(e)}ceil(e){return this._convertTonNumber().ceil(e)}}class C extends de{constructor(e,r=!1){super(e);p(this,"_value",0);if(r){this._value=e;return}this._value=Number(e)}getValue(){return this._value}setValue(e){this._value=e}isNumber(){return!0}getNegative(){return new C(0).minus(this)}getReciprocal(){return new C(1).divided(this)}plus(e){if(e.isArray())return e.plus(this);const r=this.plusBy(e.getValue());return r.isError()?this:r}equalZero(){return this._value===0}minus(e){if(e.isArray()){const s=e.getNegative();return s.isError()?s:s.plus(this)}const r=this.minusBy(e.getValue());return r.isError()?this:r}multiply(e){return e.isArray()?e.multiply(this):this.multiplyBy(e.getValue())}divided(e){if(e.isArray()){const r=e.getReciprocal();return r.isError()?r:r.multiply(this)}return this.dividedBy(e.getValue())}concatenateFront(e){return e.isArray()?e.concatenateBack(this):new Y(this.concatenate(e.getValue(),Z.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new Y(this.concatenate(e.getValue(),Z.BACK))}compare(e,r){return e.isArray()?e.compare(this,Gr(r)):this.compareBy(e.getValue(),r)}plusBy(e){const r=this.getValue();if(typeof e=="string")return new d(f.VALUE);if(typeof e=="number"){if(!Number.isFinite(r)||!Number.isFinite(e))return new d(f.NUM);const s=H(r).plus(e).toNumber();return Number.isFinite(s)?new C(s):new d(f.NUM)}return typeof e=="boolean"?new C(H(r).plus(e?1:0).toNumber()):this}minusBy(e){const r=this.getValue();if(typeof e=="string")return new d(f.VALUE);if(typeof e=="number"){if(!Number.isFinite(r)||!Number.isFinite(e))return new d(f.NUM);const s=H(r).minus(e).toNumber();return Number.isFinite(s)?new C(s):new d(f.NUM)}return typeof e=="boolean"?new C(H(r).minus(e?1:0).toNumber()):this}multiplyBy(e){const r=this.getValue();if(typeof e=="string")return new d(f.VALUE);if(typeof e=="number"){if(!Number.isFinite(r)||!Number.isFinite(e))return new d(f.NUM);const s=H(r).times(e).toNumber();return Number.isFinite(s)?new C(s):new d(f.NUM)}return typeof e=="boolean"?new C(H(r).times(e?1:0).toNumber()):this}dividedBy(e){const r=this.getValue();if(typeof e=="string")return new d(f.VALUE);if(typeof e=="number"){if(e===0)return new d(f.DIV_BY_ZERO);if(!Number.isFinite(r)||!Number.isFinite(e))return new d(f.NUM);const s=H(r).div(e).toNumber();return Number.isFinite(s)?new C(s):new d(f.NUM)}return typeof e=="boolean"?e===!1?new d(f.DIV_BY_ZERO):new C(H(r).div(1).toNumber()):this}compareBy(e,r){const s=this.getValue();let i=!1;if(typeof e=="string")switch(r){case w.EQUALS:case w.GREATER_THAN:case w.GREATER_THAN_OR_EQUAL:i=!1;break;case w.LESS_THAN:case w.LESS_THAN_OR_EQUAL:case w.NOT_EQUAL:i=!0;break}else if(typeof e=="number")if(!Number.isFinite(s)||!Number.isFinite(e))i=this._compareInfinity(s,e,r);else switch(r){case w.EQUALS:i=H(s).eq(e);break;case w.GREATER_THAN:i=H(s).gt(e);break;case w.GREATER_THAN_OR_EQUAL:i=H(s).gte(e);break;case w.LESS_THAN:i=H(s).lt(e);break;case w.LESS_THAN_OR_EQUAL:i=H(s).lte(e);break;case w.NOT_EQUAL:i=!H(s).eq(e);break}else if(typeof e=="boolean")switch(r){case w.EQUALS:case w.GREATER_THAN:case w.GREATER_THAN_OR_EQUAL:i=!1;break;case w.LESS_THAN:case w.LESS_THAN_OR_EQUAL:case w.NOT_EQUAL:i=!0;break}return new W(i)}pow(e){if(e.isArray())return e.powInverse(this);const r=this.getValue(),s=e.getValue();if(typeof s=="string")return new d(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(r)||!Number.isFinite(s))return new d(f.NUM);const i=dr(r,s);return Number.isFinite(i)?new C(i):new d(f.NUM)}return typeof s=="boolean"?new C(dr(r,s?1:0)):this}sqrt(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=H(e).sqrt().toNumber();return Number.isFinite(r)?new C(r):new d(f.NUM)}cbrt(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.cbrt(e);return Number.isFinite(r)?new C(r):new d(f.NUM)}cos(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.cos(e);return Number.isFinite(r)?new C(r):new d(f.NUM)}acos(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.acos(e);return Number.isNaN(r)?new d(f.NUM):new C(r)}acosh(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.acosh(e);return Number.isNaN(r)?new d(f.NUM):new C(r)}sin(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.sin(e);return Number.isFinite(r)?new C(r):new d(f.NUM)}asin(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.asin(e);return Number.isNaN(r)?new d(f.NUM):new C(r)}asinh(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.asinh(e);return Number.isNaN(r)?new d(f.NUM):new C(r)}tan(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.tan(e);return Number.isFinite(r)?new C(r):new d(f.NUM)}tanh(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.tanh(e);return Number.isFinite(r)?new C(r):new d(f.NUM)}atan(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.atan(e);return Number.isFinite(r)?new C(r):new d(f.NUM)}atan2(e){if(e.isArray())return e.atan2Inverse(this);const r=this.getValue(),s=e.getValue();if(typeof s=="string")return new d(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(r)||!Number.isFinite(s))return new d(f.NUM);const i=Math.atan2(r,s);return Number.isFinite(i)?new C(i):new d(f.NUM)}return typeof s=="boolean"?new C(Math.atan2(r,s?1:0)):this}atanh(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.atanh(e);return Number.isFinite(r)?new C(r):new d(f.NUM)}log(){const e=this.getValue();if(typeof e=="number"&&e<=0)return new d(f.NUM);if(!Number.isFinite(e))return new d(f.NUM);const r=Math.log(e);return Number.isFinite(r)?new C(r):new d(f.NUM)}log10(){const e=this.getValue();if(typeof e=="number"&&e<=0)return new d(f.NUM);if(!Number.isFinite(e))return new d(f.NUM);const r=Math.log10(e);return Number.isFinite(r)?new C(r):new d(f.NUM)}exp(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.exp(e);return Number.isFinite(r)?new C(r):new d(f.NUM)}abs(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.abs(e);return Number.isFinite(r)?new C(r):new d(f.NUM)}round(e){if(e.isArray())return e.roundInverse(this);const r=this.getValue(),s=e.getValue();if(typeof s=="string")return new d(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(r)||!Number.isFinite(s))return new d(f.NUM);const i=cr(r,s);return Number.isFinite(i)?new C(i):new d(f.NUM)}return typeof s=="boolean"?new C(cr(r,s?1:0)):this}floor(e){if(e.isArray())return e.floorInverse(this);const r=this.getValue(),s=e.getValue();if(typeof s=="string")return new d(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(r)||!Number.isFinite(s))return new d(f.NUM);const i=hr(r,s);return Number.isFinite(i)?new C(i):new d(f.NUM)}return typeof s=="boolean"?new C(hr(r,s?1:0)):this}ceil(e){if(e.isArray())return e.ceilInverse(this);const r=this.getValue(),s=e.getValue();if(typeof s=="string")return new d(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(r)||!Number.isFinite(s))return new d(f.NUM);const i=fr(r,s);return Number.isFinite(i)?new C(i):new d(f.NUM)}return typeof s=="boolean"?new C(fr(r,s?1:0)):this}_compareInfinity(e,r,s){let i=!1;switch(s){case w.EQUALS:i=e===r;break;case w.GREATER_THAN:i=e>r;break;case w.GREATER_THAN_OR_EQUAL:i=e>=r;break;case w.LESS_THAN:i=e<r;break;case w.LESS_THAN_OR_EQUAL:i=e<=r;break;case w.NOT_EQUAL:i=e!==r;break}return i}}class Y extends de{constructor(e,r=!1){super(e);p(this,"_value");if(r){this._value=e;return}let s=e.toString();s.charAt(0)==='"'&&s.charAt(s.length-1)==='"'&&(s=s.slice(1,-1),s=s.replace(/""/g,'"')),this._value=s}getValue(){return this._value}isString(){return!0}concatenateFront(e){return e.isArray()?e.concatenateBack(this):new Y(this.concatenate(e.getValue(),Z.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new Y(this.concatenate(e.getValue(),Z.BACK))}compare(e,r){return e.isArray()?e.compare(this,Gr(r)):this.compareBy(e.getValue(),r)}compareBy(e,r){const s=this.getValue();let i=!1;if(typeof e=="string"){if(Nn(e))return this._checkWildcard(e,r);switch(r){case w.EQUALS:i=s===e;break;case w.GREATER_THAN:i=s>e;break;case w.GREATER_THAN_OR_EQUAL:i=s>=e;break;case w.LESS_THAN:i=s<e;break;case w.LESS_THAN_OR_EQUAL:i=s<=e;break;case w.NOT_EQUAL:i=s!==e;break}}else if(typeof e=="number")switch(r){case w.EQUALS:case w.GREATER_THAN:case w.GREATER_THAN_OR_EQUAL:i=!0;break;case w.LESS_THAN:case w.LESS_THAN_OR_EQUAL:case w.NOT_EQUAL:i=!1;break}else if(typeof e=="boolean")switch(r){case w.EQUALS:case w.GREATER_THAN:case w.GREATER_THAN_OR_EQUAL:i=!1;break;case w.LESS_THAN:case w.LESS_THAN_OR_EQUAL:case w.NOT_EQUAL:i=!0;break}return new W(i)}_checkWildcard(e,r){const s=this.getValue().toLocaleLowerCase(),i=es(s,e,r);return new W(i)}}function ls(t){return""}function cs(t=[]){const n=[];for(let e=0;e<t.length;e++){const r=t[e];n[e]==null&&(n[e]=[]);for(let s=0;s<r.length;s++){const i=r[s];n[e][s]=fe.create(i)}}return n}function hs(t=[]){const n=[];for(let e=0;e<t.length;e++){const r=t[e];n[e]==null&&(n[e]=[]);for(let s=0;s<r.length;s++){const i=r[s];i.isError()?n[e][s]=i.getErrorType():n[e][s]=i.getValue()}}return n}class J extends de{constructor(e){var n=(...va)=>(super(...va),p(this,"_values",[]),p(this,"_rowCount",-1),p(this,"_columnCount",-1),p(this,"_unitId",""),p(this,"_sheetId",""),p(this,"_currentRow",-1),p(this,"_currentColumn",-1),p(this,"_sliceCache",new Map),p(this,"_flattenCache"),this);if(typeof e=="string")n(e);else{const r=ls();n(r)}this._values=this._formatValue(e)}dispose(){this._values.forEach(e=>{e.forEach(r=>{r.dispose()})}),this._values=[],this._clearCache()}getRowCount(){return this._rowCount}setRowCount(e){this._rowCount=e}getColumnCount(){return this._columnCount}setColumnCount(e){this._columnCount=e}setCurrent(e,r){this._currentRow=e,this._currentColumn=r}setUnitId(e){this._unitId=e}getUnitId(){return this._unitId}setSheetId(e){this._sheetId=e}getSheetId(){return this._sheetId}getCurrentRow(){return this._currentRow}getCurrentColumn(){return this._currentColumn}getArrayValue(){return this._values}setArrayValue(e){this._clearCache(),this._values=e}isArray(){return!0}get(e,r){const s=this._values[e][r];return s??new Qe(0)}set(e,r,s){if(e>=this._rowCount||r>=this._columnCount)throw new Error("Exceeding array bounds.");this._clearCache(),this._values[e][r]=s}getRangePosition(){const r=this.getRowCount(),s=0,i=this.getColumnCount();return{startRow:0,endRow:r-1,startColumn:s,endColumn:i-1}}iterator(e){const{startRow:r,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),o=this.getArrayValue();for(let u=r;u<=s;u++)for(let l=i;l<=a;l++)if(e(o[u][l],u,l)===!1)return}getFirstCell(){const{startRow:e,startColumn:r}=this.getRangePosition();return this.get(e,r)}pick(e){const r=e.getRowCount(),s=e.getColumnCount();if(r!==this._rowCount||s!==this._columnCount)return this._createNewArray([[new Qe(0)]],1,1);const i=[];i[0]=[];for(let a=0;a<r;a++)for(let o=0;o<s;o++){const u=e.get(a,o),l=this.get(a,o);u.isError()||u.getValue()===!0&&i[0].push(l)}return this._createNewArray(i,1,i[0].length)}flatten(){if(this._flattenCache!=null)return this._flattenCache;const e=[];e[0]=[];for(let s=0;s<this._rowCount;s++)for(let i=0;i<this._columnCount;i++){const a=this.get(s,i);e[0].push(a)}const r=this._createNewArray(e,1,e[0].length);return this._flattenCache=r,r}slice(e,r){let s=0,i=this._rowCount,a=1,o=0,u=this._columnCount,l=1;if(e!=null&&(s=e[0]||0,i=e[1]||this._rowCount,a=e[2]||1),r!=null&&(o=r[0]||0,u=r[1]||this._columnCount,l=r[2]||1),s>=this._rowCount||o>=this._columnCount)return;const c=`${s}_${i}_${a}_${o}_${u}_${l}`,h=this._sliceCache.get(c);if(h!=null)return h;const m=[],D=this._values;let _=0,R=0;for(let L=s;L<i;L+=a){R=0,m[_]==null&&(m[_]=[]);for(let S=o;S<u;S+=l)m[_][R]=D[L][S],R++;_++}if(m.length===0||m[0].length===0)return;const E=a>1?-1:s+this._currentRow,y=l>1?-1:o+this._currentColumn,b=this._createNewArray(m,m.length,m[0].length,E,y);return this._sliceCache.set(c,b),b}sortByRow(e){const r=this._transposeArray(this._values);r.sort(this._sort(e)),this._clearCache(),this._values=this._transposeArray(r)}sortByColumn(e){this._clearCache(),this._values.sort(this._sort(e))}transpose(){const e=this._transposeArray(this._values),r=this._rowCount,s=this._columnCount;return this._createNewArray(e,s,r)}binarySearch(e,r=qe.MIN){if(e.isError())return;const a=this.flatten().getArrayValue()[0],o=ar(),u=e.getValue().toString();let l=0,c=a.length-1,h=null;for(;l<=c;){const m=Math.floor((l+c)/2),_=a[m].getValue(),R=o(_.toString(),u);if(R===0)return m;R===-1?(l=m+1,r===qe.MIN&&(h=m)):(c=m-1,r===qe.MAX&&(h=m))}return h}sum(){let e=new C(0);return this.iterator(r=>{if(r==null)return!0;if(r.isError())return e=r,!1;e=e.plus(r)}),e}max(){let e=new C(-1/0);return this.iterator(r=>{if(r==null)return!0;if(r.isError())return e=r,!1;if(r.isString()||r.isNull())return!0;e.isLessThan(r).getValue()&&(e=r)}),e}min(){let e=new C(1/0);return this.iterator(r=>{if(r==null)return!0;if(r.isError())return e=r,!1;if(r.isString()||r.isNull())return!0;e.isGreaterThan(r).getValue()&&(e=r)}),e}count(){let e=new C(0);return this.iterator(r=>{if(r==null||r.isError()||r.isString()||r.isNull())return!0;e=e.plusBy(1)}),e}countA(){let e=new C(0);return this.iterator(r=>{if(r==null||r.isNull())return!0;e=e.plusBy(1)}),e}countBlank(){let e=new C(0);return this.iterator(r=>{if(r!=null)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)}compare(e,r){return this._batchOperator(e,4,r)}concatenateFront(e){return this._batchOperator(e,5)}concatenateBack(e){return this._batchOperator(e,6)}product(e,r){return this._batchOperator(e,7,r)}map(e){var a,o;const r=this._rowCount,s=this._columnCount,i=[];for(let u=0;u<r;u++){const l=[];for(let c=0;c<s;c++){const h=(o=(a=this._values)==null?void 0:a[u])==null?void 0:o[c];h?h.isError()?l[c]=h:l[c]=e(h,u,c):l[c]=new d(f.VALUE)}i.push(l)}return this._createNewArray(i,r,s)}pow(e){return this._batchOperator(e,8)}powInverse(e){return this.map(r=>r.isError()?r:e.pow(r))}sqrt(){return this.map(e=>e.isError()?e:e.sqrt())}cbrt(){return this.map(e=>e.isError()?e:e.cbrt())}cos(){return this.map(e=>e.isError()?e:e.cos())}acos(){return this.map(e=>e.isError()?e:e.acos())}acosh(){return this.map(e=>e.isError()?e:e.acosh())}sin(){return this.map(e=>e.isError()?e:e.sin())}asin(){return this.map(e=>e.isError()?e:e.asin())}asinh(){return this.map(e=>e.isError()?e:e.asinh())}tan(){return this.map(e=>e.isError()?e:e.tan())}tanh(){return this.map(e=>e.isError()?e:e.tanh())}atan(){return this.map(e=>e.isError()?e:e.atan())}atanh(){return this.map(e=>e.isError()?e:e.atanh())}atan2(e){return this._batchOperator(e,12)}atan2Inverse(e){return this.map(r=>r.isError()?r:e.atan2(r))}mean(){const e=this.sum(),r=this.countA();return e.divided(r)}median(){const e=this.flatten(),r=e.getColumnCount();if(r<=1)return e.get(0,0);if(e.sortByRow(0),r%2===0){const s=e.get(0,r/2),i=e.get(0,r/2-1);return s.plus(i).divided(new C(2,!0))}return e.get(0,(r-1)/2)}var(){const e=this.mean(),r=[];this.iterator((h,m,D)=>{(h==null||h.isError()||h.isString())&&(h=new C(0));let _=h.minus(e).pow(new C(2,!0));_.isError()&&(_=new C(0)),r[m]==null&&(r[m]=[]),r[m][D]=_});const{_rowCount:s,_columnCount:i,_unitId:a,_sheetId:o,_currentRow:u,_currentColumn:l}=this;return new J({calculateValueList:r,rowCount:s,columnCount:i,unitId:a,sheetId:o,row:u,column:l}).mean()}std(){const e=this.var();return e.isError()?e:e.sqrt()}log(){return this.map(e=>e.isError()?e:e.log())}log10(){return this.map(e=>e.isError()?e:e.log10())}exp(){return this.map(e=>e.isError()?e:e.exp())}abs(){return this.map(e=>e.isError()?e:e.abs())}round(e){return this._batchOperator(e,9)}roundInverse(e){return this.map(r=>r.isError()?r:e.round(r))}floor(e){return this._batchOperator(e,10)}floorInverse(e){return this.map(r=>r.isError()?r:e.floor(r))}ceil(e){return this._batchOperator(e,11)}ceilInverse(e){return this.map(r=>r.isError()?r:e.ceil(r))}toValue(){return hs(this._values)}_clearCache(){this._flattenCache=null,this._sliceCache.clear()}_sort(e){const r=ar();return(s,i)=>{const a=s[e],o=i[e];return a.isError()&&a.isError()?0:a.isError()?1:o.isError()?-1:r(a.getValue(),o.getValue())}}_transposeArray(e){const r=e.length,s=e[0].length,i=[];for(let a=0;a<s;a++){i[a]=[];for(let o=0;o<r;o++)i[a][o]=e[o][a]}return i}_batchOperator(e,r,s){const i=[];let a=this._rowCount,o=this._columnCount;if(e.isArray()){const l=e.getRowCount(),c=e.getColumnCount();if(a=Math.max(l,a),o=Math.max(c,o),l===1&&c===1){const h=e.getFirstCell();for(let m=0;m<o;m++)i.push(h)}else if(l===1&&this._columnCount>1){const h=e.getArrayValue();for(let m=0;m<o;m++)i.push(h[0][m])}else return this._batchOperatorArray(e,r,s)}else for(let l=0;l<o;l++)i.push(e);const u=[];for(let l=0;l<o;l++){const c=i[l];this._batchOperatorValue(c,l,u,r,s)}return this._createNewArray(u,a,o)}_batchOperatorValue(e,r,s,i,a){var D,_;const o=this._rowCount;let u=!1;const l=this.getUnitId(),c=this.getSheetId(),h=this.getCurrentRow(),m=this.getCurrentColumn();if(i===4&&(u=ue.canUseCache(l,c,r+m,h,h+o-1),u===!0)){if(a===w.EQUALS){const R=ue.getCellPositions(l,c,r+m,e.getValue());for(let E=0;E<o;E++)s[E]==null&&(s[E]=[]),R!=null&&R.includes(E+h)?s[E][r]=new W(!0):s[E][r]=new W(!1)}else{const R=ue.getCellValuePositions(l,c,r+m);if(R!=null)R.forEach((E,y)=>{let b;if(typeof y=="string"?b=new Y(y):typeof y=="number"?b=new C(y):typeof y=="boolean"&&(b=new W(y)),b==null)return!0;if(b.compare(e,a))for(let S=0;S<o;S++)s[S]==null&&(s[S]=[]),E.includes(S+h)?s[S][r]=new W(!0):s[S][r]=new W(!1)});else for(let E=0;E<o;E++)s[E]==null&&(s[E]=[]),s[E][r]=new W(!1)}return}for(let R=0;R<o;R++){const E=(_=(D=this._values)==null?void 0:D[R])==null?void 0:_[r];if(s[R]==null&&(s[R]=[]),E&&e)if(E.isError())s[R][r]=E;else if(e.isError())s[R][r]=new d(f.VALUE);else switch(i){case 1:s[R][r]=E.plus(e);break;case 0:s[R][r]=E.minus(e);break;case 2:s[R][r]=E.multiply(e);break;case 3:s[R][r]=E.divided(e);break;case 4:a?s[R][r]=E.compare(e,a):s[R][r]=new d(f.VALUE);break;case 5:s[R][r]=E.concatenateFront(e);break;case 6:s[R][r]=E.concatenateBack(e);break;case 7:a?s[R][r]=E.product(e,a):s[R][r]=new d(f.VALUE);break;case 8:s[R][r]=E.pow(e);break;case 9:s[R][r]=E.round(e);break;case 10:s[R][r]=E.floor(e);break;case 12:s[R][r]=E.atan2(e);break;case 11:s[R][r]=E.ceil(e);break}else s[R][r]=new d(f.NA);E!=null&&(E.isError()?ue.set(l,c,r+m,E.getErrorType(),R+h):E.isNull()?ue.set(l,c,r+m,null,R+h):ue.set(l,c,r+m,E.getValue(),R+h))}ue.setContinueBuildingCache(l,c,r+m,h,h+o-1)}_batchOperatorArray(e,r,s){var h,m,D,_,R,E,y,b,L,S,$,k;let i=e.getRowCount(),a=e.getColumnCount();i<this._rowCount&&(i=this._rowCount),a<this._columnCount&&(a=this._columnCount);const o=[],u=e.getArrayValue(),l=this._checkArrayCalculateType(this),c=this._checkArrayCalculateType(e);for(let Q=0;Q<i;Q++){const A=[];for(let x=0;x<a;x++){let U;l===3?U=(m=(h=this._values)==null?void 0:h[0])==null?void 0:m[0]:l===1?U=(_=(D=this._values)==null?void 0:D[0])==null?void 0:_[x]:l===2?U=(E=(R=this._values)==null?void 0:R[Q])==null?void 0:E[0]:U=(b=(y=this._values)==null?void 0:y[Q])==null?void 0:b[x];let M;if(c===3?M=(L=u==null?void 0:u[0])==null?void 0:L[0]:c===1?M=(S=u==null?void 0:u[0])==null?void 0:S[x]:c===2?M=($=u==null?void 0:u[Q])==null?void 0:$[0]:M=(k=u==null?void 0:u[Q])==null?void 0:k[x],U&&M)if(U.isError())A[x]=U;else if(M.isError())A[x]=M;else switch(r){case 1:A[x]=U.plus(M);break;case 0:A[x]=U.minus(M);break;case 2:A[x]=U.multiply(M);break;case 3:A[x]=U.divided(M);break;case 4:s?A[x]=U.compare(M,s):A[x]=new d(f.VALUE);break;case 5:A[x]=U.concatenateFront(M);break;case 6:A[x]=U.concatenateBack(M);break;case 7:s?A[x]=U.product(M,s):A[x]=new d(f.VALUE);break;case 8:A[x]=U.pow(M);break;case 9:A[x]=U.round(M);break;case 12:A[x]=U.atan2(M);break;case 10:A[x]=U.floor(M);break;case 11:A[x]=U.ceil(M);break}else A[x]=new d(f.NA)}o.push(A)}return this._createNewArray(o,i,a)}_checkArrayCalculateType(e){return e.getRowCount()===1&&e.getColumnCount()===1?3:e.getRowCount()===1?1:e.getColumnCount()===1?2:0}_formatValue(e){if(typeof e!="string")return e=e,this._rowCount=e.rowCount,this._columnCount=e.columnCount,this._unitId=e.unitId,this._sheetId=e.sheetId,this._currentRow=e.row,this._currentColumn=e.column,e.calculateValueList;e=e.slice(1,-1);const r=e.split(";"),s=r.length,i=[];let a=0;for(let o=0;o<s;o++){const l=r[o].split(","),c=l.length;a<c&&(a=c);const h=[];for(let m=0;m<c;m++){const D=l[m].trim();h.push(fe.create(D))}i.push(h)}return this._rowCount=s,this._columnCount=a,i}_createNewArray(e,r,s,i=-1,a=-1){(this._currentColumn===-1||this._currentRow===-1)&&(i=-1,a=-1);const o={calculateValueList:e,rowCount:r,columnCount:s,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:i,column:a};return new J(o)}}class fe{static create(n){if(n==null)return new Qe(0);if(typeof n=="boolean")return new W(n,!0);if(typeof n=="string"){const e=n.toLocaleUpperCase().trim();return Tt.has(e)?new d(e):e===_e.TRUE||e===_e.FALSE?new W(e):g.isRealNum(n)?new C(n):new RegExp(Xn,"g").test(n.replace(/\n/g,"").replace(/\r/g,""))?new J(n.replace(/\n/g,"").replace(/\r/g,"")):new Y(n)}return typeof n=="number"?Number.isFinite(n)?new C(n,!0):new d(f.NUM):new d(f.NA)}}const fs=1e5,$t=new Rt(fs);class Be 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,"_refOffsetX",0);p(this,"_refOffsetY",0);this._token=e}dispose(){this._unitData={},this._runtimeData={}}isExceedRange(){const{startRow:e,endRow:r,startColumn:s,endColumn:i}=this.getRangePosition();return e<0||s<0||r>=this.getRowCount()||i>=this.getColumnCount()}setRefOffset(e=0,r=0){this._refOffsetX=e,this._refOffsetY=r}getRefOffset(){return{x:this._refOffsetX,y:this._refOffsetY}}getRangePosition(){let e=this._rangeData.startRow+this._refOffsetY,r=this._rangeData.endRow+this._refOffsetY,s=this._rangeData.startColumn+this._refOffsetX,i=this._rangeData.endColumn+this._refOffsetX;return isNaN(e)&&(e=0),isNaN(s)&&(s=0),isNaN(r)&&(r=this.getRowCount()-1),isNaN(i)&&(i=this.getColumnCount()-1),{startRow:e,endRow:r,startColumn:s,endColumn:i}}isReferenceObject(){return!0}iterator(e){const{startRow:r,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition();if(this._checkIfWorksheetMiss())return e(new d(f.VALUE),r,i);for(let o=r;o<=s;o++)for(let u=i;u<=a;u++){if(o<0||u<0)return e(new d(f.REF),o,u);const l=this.getCellData(o,u);let c=!1;if(l==null||g.isNullCell(l)){c=e(null,o,u);continue}const h=this.getCellValueObject(l);if(c=e(h,o,u),c===!1)return}}getFirstCell(){const{startRow:e,startColumn:r}=this.getRangePosition(),s=this.getCellData(e,r);return s?this.getCellValueObject(s):new C(0,!0)}getRangeData(){return this._rangeData}setRangeData(e){this._rangeData=e}getUnitId(){return this._forcedUnitId&&this._forcedUnitId.length>0?this._forcedUnitId:this._defaultUnitId}getSheetId(){return this._forcedSheetId&&this._forcedSheetId.length>0?this._forcedSheetId:this._defaultSheetId}setForcedUnitIdDirect(e){e.length>0&&(this._forcedUnitId=e)}getForcedUnitId(){return this._forcedUnitId}setForcedSheetId(e){var r;this._forcedSheetId=(r=e[this.getUnitId()])==null?void 0:r[this._forcedSheetName]}setForcedSheetIdDirect(e){this._forcedSheetId=e}getForcedSheetId(){return this._forcedSheetId}setForcedSheetName(e){e.length>0&&(this._forcedSheetName=e)}getForcedSheetName(){return this._forcedSheetName}setDefaultSheetId(e){this._defaultSheetId=e}getDefaultSheetId(){return this._defaultSheetId}setDefaultUnitId(e){this._defaultUnitId=e}getDefaultUnitId(){return this._defaultUnitId}getUnitData(){return this._unitData}setUnitData(e){this._unitData=e}getRuntimeData(){return this._runtimeData}setRuntimeData(e){this._runtimeData=e}getArrayFormulaCellData(){return this._arrayFormulaCellData}setArrayFormulaCellData(e){this._arrayFormulaCellData=e}getRuntimeArrayFormulaCellData(){return this._runtimeArrayFormulaCellData}setRuntimeArrayFormulaCellData(e){this._runtimeArrayFormulaCellData=e}getRuntimeFeatureCellData(){return this._runtimeFeatureCellData}setRuntimeFeatureCellData(e){this._runtimeFeatureCellData=e}getRowCount(){return this.getCurrentActiveSheetData().rowCount}getColumnCount(){return this.getCurrentActiveSheetData().columnCount}isCell(){return!1}isColumn(){return!1}isRow(){return!1}isRange(){return!1}isTable(){return!1}unionBy(e){return new d(f.REF)}unionRange(e,r){return{startRow:-1,startColumn:-1,endRow:-1,endColumn:-1}}getCellValueObject(e){const r=e.v||0;return Tt.has(r)?new d(r):e.t===g.CellValueType.NUMBER?new C(r):e.t===g.CellValueType.STRING||e.t===g.CellValueType.FORCE_STRING?new Y(r):e.t===g.CellValueType.BOOLEAN?new W(r):fe.create(r)}getCellByRow(e){return this.getCellByPosition(e)}getCellByColumn(e){return this.getCellByPosition(void 0,e)}getCurrentActiveSheetData(){return this._unitData[this.getUnitId()][this.getSheetId()]}getCurrentRuntimeSheetData(){var e,r;return(r=(e=this._runtimeData)==null?void 0:e[this.getUnitId()])==null?void 0:r[this.getSheetId()]}getCurrentActiveArrayFormulaCellData(){var e,r;return(r=(e=this._arrayFormulaCellData)==null?void 0:e[this.getUnitId()])==null?void 0:r[this.getSheetId()]}getCurrentRuntimeActiveArrayFormulaCellData(){var e,r;return(r=(e=this._runtimeArrayFormulaCellData)==null?void 0:e[this.getUnitId()])==null?void 0:r[this.getSheetId()]}getCellData(e,r){const s=this.getCurrentActiveSheetData(),i=this.getCurrentRuntimeSheetData(),a=this.getCurrentActiveArrayFormulaCellData(),o=this.getCurrentRuntimeActiveArrayFormulaCellData();return(i==null?void 0:i.getValue(e,r))||(o==null?void 0:o.getValue(e,r))||this.getRuntimeFeatureCellValue(e,r)||(a==null?void 0:a.getValue(e,r))||s.cellData.getValue(e,r)}getRuntimeFeatureCellValue(e,r){var i;const s=Object.keys(this._runtimeFeatureCellData);for(const a of s){const o=this._runtimeFeatureCellData[a],u=(i=o==null?void 0:o[this.getUnitId()])==null?void 0:i[this.getSheetId()];if(u==null)continue;const l=u.getValue(e,r);if(l!=null)return l}}getCellByPosition(e,r){e||(e=this._rangeData.startRow),r||(r=this._rangeData.startColumn);const s=this.getCellData(e,r);return s?this.getCellValueObject(s):new d(f.VALUE)}toArrayValueObject(e=!0){var _;const{startRow:r,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),o=`${this.getUnitId()}_${this.getSheetId()}_${r}_${s}_${i}_${a}`,u=$t.get(o);if(u&&e)return u;const l=s-r+1,c=a-i+1;if(l<0||c<0)return this._getBlankArrayValueObject();const h=new Array(l);this.iterator((R,E,y)=>{const b=E-r,L=y-i;h[b]||(h[b]=new Array(c)),R==null&&(R=new Qe(0)),h[b][L]=R});const m={calculateValueList:h,rowCount:h.length,columnCount:((_=h[0])==null?void 0:_.length)||0,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:r,column:i},D=new J(m);return e&&$t.set(o,D),D}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 ds extends Ct{constructor(n){super(),this._promise=n}isAsyncObject(){return!0}async getValue(){return this._promise}}class ms extends Ct{constructor(n){super(),this._promiseList=n}isAsyncArrayObject(){return!0}async getValue(){var r;const n=[];for(let s=0;s<this._promiseList.length;s++){const i=this._promiseList[s];n[s]==null&&(n[s]=[]);for(let a=0;a<i.length;a++){const o=i[a];o.isAsyncObject()?n[s][a]=await o.getValue():n[s][a]=o}}const e={calculateValueList:n,rowCount:n.length,columnCount:((r=n[0])==null?void 0:r.length)||0,unitId:"",sheetId:"",row:0,column:0};return new J(e)}}class at extends Be{constructor(n,e,r){super(""),this.setRangeData(n),e&&this.setForcedSheetIdDirect(e),r&&this.setForcedUnitIdDirect(r)}isRange(){return!0}}const mr=/[\[\]]/g;function gr(t,n){if(mr.test(t)){const e=Number(t.replace(mr,""));return n+e}return Number(t)-1}function vt(t,n=0,e=0){t=t.toLocaleUpperCase();const r=t.split(/[RC]/),s=r[1],i=r[2],a=gr(s,n),o=gr(i,e);return{row:a,column:o,absoluteRefType:g.AbsoluteRefType.NONE}}function Kr(t,n=0,e=0){const{refBody:r,sheetName:s,unitId:i}=Ur(t),a=r.indexOf(":");if(a===-1){const R=vt(r,n,e),E=R.row,y=R.column,b=R.absoluteRefType;return{unitId:i,sheetName:s,range:{startRow:E,startColumn:y,endRow:E,endColumn:y,startAbsoluteRefType:b,endAbsoluteRefType:b}}}const o=r.substring(0,a),u=r.substring(a+1),l=vt(o,n,e),c=vt(u,n,e),h=l.row,m=l.column,D=c.row,_=c.column;return{unitId:i,sheetName:s,range:{startRow:h,startColumn:m,endRow:D,endColumn:_,startAbsoluteRefType:l.absoluteRefType,endAbsoluteRefType:c.absoluteRefType}}}function gs(t){const n=We(t.startRow,t.startAbsoluteRefType,!0),e=We(t.startColumn,t.startAbsoluteRefType,!1),r=We(t.endRow,t.endAbsoluteRefType,!0),s=We(t.endColumn,t.endAbsoluteRefType,!1);return n===r&&e===s?`R${n}C${e}`:`R${n}C${e}:R${r}C${s}`}function We(t,n=g.AbsoluteRefType.ALL,e){switch(t+=1,n){case g.AbsoluteRefType.ALL:return`${t}`;case g.AbsoluteRefType.ROW:return e?`${t}`:`[${t}]`;case g.AbsoluteRefType.COLUMN:return e?`[${t}]`:`${t}`;case g.AbsoluteRefType.NONE:return`[${t}]`}}const Ir=[];var Rs=(t=>{})();class F extends g.Disposable{constructor(e){super();p(this,"_unitId");p(this,"_subUnitId");p(this,"_row",-1);p(this,"_column",-1);this._name=e}get name(){return this._name}get unitId(){return this._unitId}get subUnitId(){return this._subUnitId}get row(){return this._row}get column(){return this._column}isAsync(){return!1}isAddress(){return!1}isCustom(){return!1}setRefInfo(e,r,s,i){this._unitId=e,this._subUnitId=r,this._row=s,this._column=i}calculateCustom(...e){return null}calculate(...e){return new d(f.VALUE)}checkArrayType(e){return e.isReferenceObject()||e.isValueObject()&&e.isArray()}getIndexNumValue(e){if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())return e.getValue()===!1?new d(f.VALUE):1;if(e.isString()){const r=Number(e.getValue());if(isNaN(r))return new d(f.REF)}else if(e.isNumber())return e.getValue();return new d(f.VALUE)}getZeroOrOneByOneDefault(e){if(e==null)return 1;let r=1;if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())e.getValue()===!1&&(r=0);else{if(e.isString())return;e.isNumber()&&e.getValue()===0&&(r=0)}return r}}const zr=[];var qr=(t=>(t.BETADIST="BETADIST",t.BETAINV="BETAINV",t.BINOMDIST="BINOMDIST",t.CHIDIST="CHIDIST",t.CHIINV="CHIINV",t.CHITEST="CHITEST",t.CONFIDENCE="CONFIDENCE",t.COVAR="COVAR",t.CRITBINOM="CRITBINOM",t.EXPONDIST="EXPONDIST",t.FDIST="FDIST",t.FINV="FINV",t.FTEST="FTEST",t.GAMMADIST="GAMMADIST",t.GAMMAINV="GAMMAINV",t.HYPGEOMDIST="HYPGEOMDIST",t.LOGINV="LOGINV",t.LOGNORMDIST="LOGNORMDIST",t.MODE="MODE",t.NEGBINOMDIST="NEGBINOMDIST",t.NORMDIST="NORMDIST",t.NORMINV="NORMINV",t.NORMSDIST="NORMSDIST",t.NORMSINV="NORMSINV",t.PERCENTILE="PERCENTILE",t.PERCENTRANK="PERCENTRANK",t.POISSON="POISSON",t.QUARTILE="QUARTILE",t.RANK="RANK",t.STDEV="STDEV",t.STDEVP="STDEVP",t.TDIST="TDIST",t.TINV="TINV",t.TTEST="TTEST",t.VAR="VAR",t.VARP="VARP",t.WEIBULL="WEIBULL",t.ZTEST="ZTEST",t))(qr||{});const Zr=[];var Jr=(t=>(t.CUBEKPIMEMBER="CUBEKPIMEMBER",t.CUBEMEMBER="CUBEMEMBER",t.CUBEMEMBERPROPERTY="CUBEMEMBERPROPERTY",t.CUBERANKEDMEMBER="CUBERANKEDMEMBER",t.CUBESET="CUBESET",t.CUBESETCOUNT="CUBESETCOUNT",t.CUBEVALUE="CUBEVALUE",t))(Jr||{});const Nr=[];var en=(t=>(t.DAVERAGE="DAVERAGE",t.DCOUNT="DCOUNT",t.DCOUNTA="DCOUNTA",t.DGET="DGET",t.DMAX="DMAX",t.DMIN="DMIN",t.DPRODUCT="DPRODUCT",t.DSTDEV="DSTDEV",t.DSTDEVP="DSTDEVP",t.DSUM="DSUM",t.DVAR="DVAR",t.DVARP="DVARP",t))(en||{});const tn=[];var rn=(t=>(t.DATE="DATE",t.DATEDIF="DATEDIF",t.DATEVALUE="DATEVALUE",t.DAY="DAY",t.DAYS="DAYS",t.DAYS360="DAYS360",t.EDATE="EDATE",t.EOMONTH="EOMONTH",t.HOUR="HOUR",t.ISOWEEKNUM="ISOWEEKNUM",t.MINUTE="MINUTE",t.MONTH="MONTH",t.NETWORKDAYS="NETWORKDAYS",t.NETWORKDAYS_INTL="NETWORKDAYS.INTL",t.NOW="NOW",t.SECOND="SECOND",t.TIME="TIME",t.TIMEVALUE="TIMEVALUE",t.TODAY="TODAY",t.WEEKDAY="WEEKDAY",t.WEEKNUM="WEEKNUM",t.WORKDAY="WORKDAY",t.WORKDAY_INTL="WORKDAY.INTL",t.YEAR="YEAR",t.YEARFRAC="YEARFRAC",t))(rn||{});const nn=[];var sn=(t=>(t.BESSELI="BESSELI",t.BESSELJ="BESSELJ",t.BESSELK="BESSELK",t.BESSELY="BESSELY",t.BIN2DEC="BIN2DEC",t.BIN2HEX="BIN2HEX",t.BIN2OCT="BIN2OCT",t.BITAND="BITAND",t.BITLSHIFT="BITLSHIFT",t.BITOR="BITOR",t.BITRSHIFT="BITRSHIFT",t.BITXOR="BITXOR",t.COMPLEX="COMPLEX",t.CONVERT="CONVERT",t.DEC2BIN="DEC2BIN",t.DEC2HEX="DEC2HEX",t.DEC2OCT="DEC2OCT",t.DELTA="DELTA",t.ERF="ERF",t.ERF_PRECISE="ERF.PRECISE",t.ERFC="ERFC",t.ERFC_PRECISE="ERFC.PRECISE",t.GESTEP="GESTEP",t.HEX2BIN="HEX2BIN",t.HEX2DEC="HEX2DEC",t.HEX2OCT="HEX2OCT",t.IMABS="IMABS",t.IMAGINARY="IMAGINARY",t.IMARGUMENT="IMARGUMENT",t.IMCONJUGATE="IMCONJUGATE",t.IMCOS="IMCOS",t.IMCOSH="IMCOSH",t.IMCOT="IMCOT",t.IMCSC="IMCSC",t.IMCSCH="IMCSCH",t.IMDIV="IMDIV",t.IMEXP="IMEXP",t.IMLN="IMLN",t.IMLOG10="IMLOG10",t.IMLOG2="IMLOG2",t.IMPOWER="IMPOWER",t.IMPRODUCT="IMPRODUCT",t.IMREAL="IMREAL",t.IMSEC="IMSEC",t.IMSECH="IMSECH",t.IMSIN="IMSIN",t.IMSINH="IMSINH",t.IMSQRT="IMSQRT",t.IMSUB="IMSUB",t.IMSUM="IMSUM",t.IMTAN="IMTAN",t.OCT2BIN="OCT2BIN",t.OCT2DEC="OCT2DEC",t.OCT2HEX="OCT2HEX",t))(sn||{});const an=[];var on=(t=>(t.ACCRINT="ACCRINT",t.ACCRINTM="ACCRINTM",t.AMORDEGRC="AMORDEGRC",t.AMORLINC="AMORLINC",t.COUPDAYBS="COUPDAYBS",t.COUPDAYS="COUPDAYS",t.COUPDAYSNC="COUPDAYSNC",t.COUPNCD="COUPNCD",t.COUPNUM="COUPNUM",t.COUPPCD="COUPPCD",t.CUMIPMT="CUMIPMT",t.CUMPRINC="CUMPRINC",t.DB="DB",t.DDB="DDB",t.DISC="DISC",t.DOLLARDE="DOLLARDE",t.DOLLARFR="DOLLARFR",t.DURATION="DURATION",t.EFFECT="EFFECT",t.FV="FV",t.FVSCHEDULE="FVSCHEDULE",t.INTRATE="INTRATE",t.IPMT="IPMT",t.IRR="IRR",t.ISPMT="ISPMT",t.MDURATION="MDURATION",t.MIRR="MIRR",t.NOMINAL="NOMINAL",t.NPER="NPER",t.NPV="NPV",t.ODDFPRICE="ODDFPRICE",t.ODDFYIELD="ODDFYIELD",t.ODDLPRICE="ODDLPRICE",t.ODDLYIELD="ODDLYIELD",t.PDURATION="PDURATION",t.PMT="PMT",t.PPMT="PPMT",t.PRICE="PRICE",t.PRICEDISC="PRICEDISC",t.PRICEMAT="PRICEMAT",t.PV="PV",t.RATE="RATE",t.RECEIVED="RECEIVED",t.RRI="RRI",t.SLN="SLN",t.SYD="SYD",t.TBILLEQ="TBILLEQ",t.TBILLPRICE="TBILLPRICE",t.TBILLYIELD="TBILLYIELD",t.VDB="VDB",t.XIRR="XIRR",t.XNPV="XNPV",t.YIELD="YIELD",t.YIELDDISC="YIELDDISC",t.YIELDMAT="YIELDMAT",t))(on||{});const un=[];var ln=(t=>(t.CELL="CELL",t.ERROR_TYPE="ERROR.TYPE",t.INFO="INFO",t.ISBLANK="ISBLANK",t.ISERR="ISERR",t.ISERROR="ISERROR",t.ISEVEN="ISEVEN",t.ISFORMULA="ISFORMULA",t.ISLOGICAL="ISLOGICAL",t.ISNA="ISNA",t.ISNONTEXT="ISNONTEXT",t.ISNUMBER="ISNUMBER",t.ISODD="ISODD",t.ISOMITTED="ISOMITTED",t.ISREF="ISREF",t.ISTEXT="ISTEXT",t.N="N",t.NA="NA",t.SHEET="SHEET",t.SHEETS="SHEETS",t.TYPE="TYPE",t))(ln||{}),ot=(t=>(t.AND="AND",t.BYCOL="BYCOL",t.BYROW="BYROW",t.FALSE="FALSE",t.IF="IF",t.IFERROR="IFERROR",t.IFNA="IFNA",t.IFS="IFS",t.LAMBDA="LAMBDA",t.LET="LET",t.MAKEARRAY="MAKEARRAY",t.MAP="MAP",t.NOT="NOT",t.OR="OR",t.REDUCE="REDUCE",t.SCAN="SCAN",t.SWITCH="SWITCH",t.TRUE="TRUE",t.XOR="XOR",t))(ot||{});class ps extends F{calculate(...n){return new d(f.VALUE)}}class Ds extends F{calculate(...n){if(n.length!==3)return new d(f.VALUE);const e=this.getIndexNumValue(n[0]);if(typeof e!="number")return e;const r=this.getIndexNumValue(n[1]);if(typeof r!="number")return r;if(!(n[2].isValueObject()&&n[2].isLambda()))return new d(f.VALUE);const s=n[2],i=[];for(let a=0;a<e;a++){i[a]==null&&(i[a]=[]);for(let o=0;o<r;o++){const u=s.execute(new C(a+1),new C(o+1));i[a][o]=u}}return new ms(i)}isAsync(){return!0}}const cn=[[ps,ot.LAMBDA],[Ds,ot.MAKEARRAY]];class Es extends F{calculate(n,e,r,s,i){if(n.isError()||e.isError()||r&&r.isError()||s&&s.isError()||i&&i.isError())return new d(f.VALUE);const a=Number(n.getValue())-1,o=Number(e.getValue())-1;if(Number.isNaN(a)||Number.isNaN(o))return new d(f.VALUE);const u=r?_s(r.getValue()):g.AbsoluteRefType.ALL,l=this.getZeroOrOneByOneDefault(s),c=i?`${i.getValue()}`:"",h=nt(c)?`'${c}'`:c,m={startRow:a,startColumn:o,endRow:a,endColumn:o,startAbsoluteRefType:u,endAbsoluteRefType:u},D=s&&!l?gs(m):Ee(m);return new Y(h!==""?`${h}!${D}`:D)}}function _s(t){switch(t){case 1:return g.AbsoluteRefType.ALL;case 2:return g.AbsoluteRefType.ROW;case 3:return g.AbsoluteRefType.COLUMN;case 4:return g.AbsoluteRefType.NONE;default:return g.AbsoluteRefType.ALL}}var Se=(t=>(t.ADDRESS="ADDRESS",t.AREAS="AREAS",t.CHOOSE="CHOOSE",t.CHOOSECOLS="CHOOSECOLS",t.CHOOSEROWS="CHOOSEROWS",t.COLUMN="COLUMN",t.COLUMNS="COLUMNS",t.DROP="DROP",t.EXPAND="EXPAND",t.FILTER="FILTER",t.FORMULATEXT="FORMULATEXT",t.GETPIVOTDATA="GETPIVOTDATA",t.HLOOKUP="HLOOKUP",t.HSTACK="HSTACK",t.HYPERLINK="HYPERLINK",t.IMAGE="IMAGE",t.INDEX="INDEX",t.INDIRECT="INDIRECT",t.LOOKUP="LOOKUP",t.MATCH="MATCH",t.OFFSET="OFFSET",t.ROW="ROW",t.ROWS="ROWS",t.RTD="RTD",t.SORT="SORT",t.SORTBY="SORTBY",t.TAKE="TAKE",t.TOCOL="TOCOL",t.TOROW="TOROW",t.TRANSPOSE="TRANSPOSE",t.UNIQUE="UNIQUE",t.VLOOKUP="VLOOKUP",t.VSTACK="VSTACK",t.WRAPCOLS="WRAPCOLS",t.WRAPROWS="WRAPROWS",t.XLOOKUP="XLOOKUP",t.XMATCH="XMATCH",t))(Se||{});class tr extends Be{constructor(n){super(n);const e=ve(n);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName),this.setRangeData(e.range)}isCell(){return!0}unionBy(n){if(!n.isCell())return new d(f.REF);const e=n,r=this.unionRange(this.getRangeData(),e.getRangeData());return this._createRange(r)}unionRange(n,e){const r=n.startRow,s=n.startColumn,i=e.startRow,a=e.startColumn,o={startRow:-1,startColumn:-1,endRow:-1,endColumn:-1};return r>i?(o.startRow=i,o.endRow=r):(o.startRow=r,o.endRow=i),s>a?(o.startColumn=a,o.endColumn=s):(o.startColumn=s,o.endColumn=a),o}_createRange(n){const e=new at(n,this.getForcedSheetId(),this.getForcedUnitId());e.setUnitData(this.getUnitData()),e.setDefaultSheetId(this.getDefaultSheetId()),e.setDefaultUnitId(this.getDefaultUnitId()),e.setRuntimeData(this.getRuntimeData()),e.setArrayFormulaCellData(this.getArrayFormulaCellData()),e.setRuntimeArrayFormulaCellData(this.getRuntimeArrayFormulaCellData()),e.setRuntimeFeatureCellData(this.getRuntimeFeatureCellData());const{x:r,y:s}=this.getRefOffset();e.setRefOffset(r,s);const i=this.getForcedSheetId();e.setForcedSheetName(this.getForcedSheetName()),i!=null&&e.setForcedSheetIdDirect(i);const a=this.getForcedUnitId();return a&&e.setForcedUnitIdDirect(a),e}}class hn extends Be{constructor(n){super(n);const e=ve(n);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const r={startColumn:e.range.startColumn,startRow:NaN,endColumn:-1,endRow:NaN};this.setRangeData(r)}isColumn(){return!0}unionBy(n){if(!n.isColumn())return new d(f.REF);const e=n;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return new d(f.REF);const r=this.getRangeData(),s=e.getRangeData().startColumn,i=r.startColumn;return s>i?r.endColumn=s:(r.startColumn=s,r.endColumn=i),this}}class fn extends Be{constructor(n){super(n);const e=ve(n);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const r={startColumn:NaN,startRow:e.range.startRow,endColumn:NaN,endRow:-1};this.setRangeData(r)}isRow(){return!0}unionBy(n){if(!n.isRow())return new d(f.REF);const e=n;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return new d(f.REF);const r=this.getRangeData(),s=e.getRangeData().startRow,i=r.startRow;return s>i?r.endRow=s:(r.startRow=s,r.endRow=i),this}}class Cs extends F{calculate(n,e){let r=this.getZeroOrOneByOneDefault(e);if(r==null&&(r=1),n.isError())return new d(f.NA);if(n.isArray()){const c=n;if(c.getRowCount()===1&&c.getColumnCount()===1)n=c.getFirstCell();else return c.map(()=>new d(f.VALUE))}if(!n.isString())return new d(f.REF);const s=n.getValue();if(r===0){const c=Kr(s),{range:h,sheetName:m,unitId:D}=c,_=new at(h);return _.setForcedUnitIdDirect(D),_.setForcedSheetName(m),this._setDefault(_)}if(new RegExp(pt).test(s))return this._setDefault(new tr(s));if(new RegExp(Fr).test(s))return this._setDefault(new fn(s));if(new RegExp(Mr).test(s))return this._setDefault(new hn(s));const i=ve(s),{range:a,sheetName:o,unitId:u}=i,l=new at(a);return l.setForcedUnitIdDirect(u),l.setForcedSheetName(o),this._setDefault(l)}_setDefault(n){return this.unitId==null||this.subUnitId==null?new d(f.REF):(n.setDefaultUnitId(this.unitId),n.setDefaultSheetId(this.subUnitId),n)}}class ws extends F{calculate(n,e,r,s,i){return new tr("A5")}}class ys extends F{calculate(n,e,r,s){if(n.isError())return n;if(e.isError())return new d(f.REF);if(!e.isArray())return new d(f.VALUE);if(r.isError())return new d(f.NA);if(s!=null&&s.isError())return new d(f.NA);const i=this.getZeroOrOneByOneDefault(s);if(i==null)return new d(f.VALUE);const a=this.getIndexNumValue(r);if(a instanceof d)return a;const o=e.slice(void 0,[0,1]),u=e.slice(void 0,[a-1,a]);return o==null||u==null?new d(f.VALUE):n.isArray()?n.map(l=>this._handleSingleObject(l,o,u,i)):this._handleSingleObject(n,o,u,i)}_handleSingleObject(n,e,r,s){if(s===0){const o=r.pick(e.isEqual(n)).getFirstCell();return o.isNull()?new d(f.NA):o}const i=e.binarySearch(n);if(i==null)return new d(f.NA);const a=r.get(i,0);return a.isNull()?new d(f.NA):a}}const dn=[[Es,Se.ADDRESS],[Cs,Se.INDIRECT],[ws,Se.OFFSET],[ys,Se.VLOOKUP]];class bs extends F{calculate(n){return n.isError()?new d(f.VALUE):(n.isReferenceObject()&&(n=n.toArrayValueObject()),n.abs())}}class Ls extends F{calculate(n){return n.isError()?new d(f.VALUE):(n.isReferenceObject()&&(n=n.toArrayValueObject()),n.acos())}}class Ss extends F{calculate(n){return n.isError()?new d(f.VALUE):(n.isReferenceObject()&&(n=n.toArrayValueObject()),n.acosh())}}class Ps extends F{calculate(n){return n.isError()?new d(f.VALUE):(n.isReferenceObject()&&(n=n.toArrayValueObject()),n.isArray()?n.map(e=>e.isError()?e:Rr(e)):Rr(n))}}function Rr(t){let n=t.getValue();if(t.isBoolean()&&(n=n?1:0),!Number.isFinite(n))return new d(f.VALUE);const e=Math.atan(1/Number(n));return Number.isNaN(e)?new d(f.VALUE):new C(e)}var q=(t=>(t.ABS="ABS",t.ACOS="ACOS",t.ACOSH="ACOSH",t.ACOT="ACOT",t.ACOTH="ACOTH",t.AGGREGATE="AGGREGATE",t.ARABIC="ARABIC",t.ASIN="ASIN",t.ASINH="ASINH",t.ATAN="ATAN",t.ATAN2="ATAN2",t.ATANH="ATANH",t.BASE="BASE",t.CEILING="CEILING",t.CEILING_MATH="CEILING.MATH",t.CEILING_PRECISE="CEILING.PRECISE",t.COMBIN="COMBIN",t.COMBINA="COMBINA",t.COS="COS",t.COSH="COSH",t.COT="COT",t.COTH="COTH",t.CSC="CSC",t.CSCH="CSCH",t.DECIMAL="DECIMAL",t.DEGREES="DEGREES",t.EVEN="EVEN",t.EXP="EXP",t.FACT="FACT",t.FACTDOUBLE="FACTDOUBLE",t.FLOOR="FLOOR",t.FLOOR_MATH="FLOOR.MATH",t.FLOOR_PRECISE="FLOOR.PRECISE",t.GCD="GCD",t.INT="INT",t.ISO_CEILING="ISO.CEILING",t.LCM="LCM",t.LET="LET",t.LN="LN",t.LOG="LOG",t.LOG10="LOG10",t.MDETERM="MDETERM",t.MINVERSE="MINVERSE",t.MMULT="MMULT",t.MOD="MOD",t.MROUND="MROUND",t.MULTINOMIAL="MULTINOMIAL",t.MUNIT="MUNIT",t.ODD="ODD",t.PI="PI",t.POWER="POWER",t.PRODUCT="PRODUCT",t.QUOTIENT="QUOTIENT",t.RADIANS="RADIANS",t.RAND="RAND",t.RANDARRAY="RANDARRAY",t.RANDBETWEEN="RANDBETWEEN",t.ROMAN="ROMAN",t.ROUND="ROUND",t.ROUNDDOWN="ROUNDDOWN",t.ROUNDUP="ROUNDUP",t.SEC="SEC",t.SECH="SECH",t.SERIESSUM="SERIESSUM",t.SEQUENCE="SEQUENCE",t.SIGN="SIGN",t.SIN="SIN",t.SINH="SINH",t.SQRT="SQRT",t.SQRTPI="SQRTPI",t.SUBTOTAL="SUBTOTAL",t.SUM="SUM",t.SUMIF="SUMIF",t.SUMIFS="SUMIFS",t.SUMPRODUCT="SUMPRODUCT",t.SUMSQ="SUMSQ",t.SUMX2MY2="SUMX2MY2",t.SUMX2PY2="SUMX2PY2",t.SUMXMY2="SUMXMY2",t.TAN="TAN",t.TANH="TANH",t.TRUNC="TRUNC",t))(q||{});class xs extends F{calculate(n,e){return new d(f.VALUE)}}class Vs extends F{calculate(...n){let e=new C(0);for(let r=0;r<n.length;r++){let s=n[r];if(s.isError())return s;if(s.isString())return new d(f.VALUE);if(e.isError())return e;s.isArray()&&(s=s.sum()),e=e.plus(s)}return e}}function vs(t){const n=[w.EQUALS,w.NOT_EQUAL,w.GREATER_THAN_OR_EQUAL,w.GREATER_THAN,w.LESS_THAN_OR_EQUAL,w.LESS_THAN];for(const e of n)if(t.startsWith(e)){const r=t.substring(e.length);return[e,fe.create(r)]}return[w.EQUALS,fe.create(t)]}function As(t,n,e){if(!e)if(n.isString()){const r=`${n.getValue()}`,[s,i]=vs(r);e=s,n=i}else e=w.EQUALS;return t.compare(n,e)}class Os extends F{calculate(n,e,r){return n.isError()||e.isError()||r!=null&&r.isError()?new d(f.NA):!n.isArray()||r&&!r.isArray()?new d(f.VALUE):e.isArray()?e.map(s=>this._handleSingleObject(n,s,r)):this._handleSingleObject(n,e,r)}_handleSingleObject(n,e,r){const s=As(n,e),i=r?r.slice([0,n.getRowCount()],[0,n.getColumnCount()]):n;return i?i.pick(s).sum():new d(f.VALUE)}}class Bs extends F{calculate(...n){return new d(f.VALUE)}}const mn=[[bs,q.ABS],[Ls,q.ACOS],[Ss,q.ACOSH],[Ps,q.ACOT],[Vs,q.SUM],[Os,q.SUMIF],[Bs,q.SUMIFS],[xs,q.POWER]];class Us extends F{constructor(){super(...arguments);p(this,"_compareType",w.EQUALS)}setCompareType(e){this._compareType=e}calculate(e,r){return e.isError()||r.isError()?e:e.compare(r,this._compareType)}}class Fs extends F{calculate(n,e){return n.isError()||e.isError()?n:!e.isArray()&&e.getValue()===0?new d(f.DIV_BY_ZERO):n.divided(e)}}var X=(t=>(t.COMPARE="COMPARE",t.DIVIDED="DIVIDED",t.MINUS="MINUS",t.MULTIPLY="MULTIPLY",t.PLUS="PLUS",t.UNION="UNION",t))(X||{});class Ms extends F{calculate(n,e){return n.isError()||e.isError()?n:n.minus(e)}}class $s extends F{calculate(n,e){return n.isError()?n:e.isError()?e:n.multiply(e)}}class ks extends F{calculate(n,e){return n.isError()?n:e.isError()?e:n.plus(e)}}const gn=[[Us,X.COMPARE],[Fs,X.DIVIDED],[Ms,X.MINUS],[$s,X.MULTIPLY],[ks,X.PLUS]];class js extends F{calculate(...n){let e=new C(0),r=new C(0);for(let s=0;s<n.length;s++){const i=n[s];if(i.isError())return i;if(e.isError())return e;i.isArray()?(e=e.plus(i.sum()),r=r.plus(i.count())):i.isNull()||(r=r.plus(new C(1)))}return e.divided(r)}}class Qs extends F{calculate(...n){let e=new C(0);for(let r=0;r<n.length;r++){let s=n[r];s.isError()||(s.isArray()?(s=s.count(),e=e.plus(s)):!s.isNull()&&!s.isString()&&(e=e.plus(new C(1))))}return e}}class Ts extends F{calculate(...n){let e=new C(0);for(let r=0;r<n.length;r++){let s=n[r];if(s.isError()){e=e.plus(new C(1));continue}s.isArray()?(s=s.countA(),e=e.plus(s)):s.isNull()||(e=e.plus(new C(1)))}return e}}var le=(t=>(t.AVEDEV="AVEDEV",t.AVERAGE="AVERAGE",t.AVERAGEA="AVERAGEA",t.AVERAGEIF="AVERAGEIF",t.AVERAGEIFS="AVERAGEIFS",t.BETA_DIST="BETA.DIST",t.BETA_INV="BETA.INV",t.BINOM_DIST="BINOM.DIST",t.BINOM_DIST_RANGE="BINOM.DIST.RANGE",t.BINOM_INV="BINOM.INV",t.CHISQ_DIST="CHISQ.DIST",t.CHISQ_DIST_RT="CHISQ.DIST.RT",t.CHISQ_INV="CHISQ.INV",t.CHISQ_INV_RT="CHISQ.INV.RT",t.CHISQ_TEST="CHISQ.TEST",t.CONFIDENCE_NORM="CONFIDENCE.NORM",t.CONFIDENCE_T="CONFIDENCE.T",t.CORREL="CORREL",t.COUNT="COUNT",t.COUNTA="COUNTA",t.COUNTBLANK="COUNTBLANK",t.COUNTIF="COUNTIF",t.COUNTIFS="COUNTIFS",t.COVARIANCE_P="COVARIANCE.P",t.COVARIANCE_S="COVARIANCE.S",t.DEVSQ="DEVSQ",t.EXPON_DIST="EXPON.DIST",t.F_DIST="F.DIST",t.F_DIST_RT="F.DIST.RT",t.F_INV="F.INV",t.F_INV_RT="F.INV.RT",t.F_TEST="F.TEST",t.FISHER="FISHER",t.FISHERINV="FISHERINV",t.FORECAST="FORECAST",t.FORECAST_ETS="FORECAST.ETS",t.FORECAST_ETS_CONFINT="FORECAST.ETS.CONFINT",t.FORECAST_ETS_SEASONALITY="FORECAST.ETS.SEASONALITY",t.FORECAST_ETS_STAT="FORECAST.ETS.STAT",t.FORECAST_LINEAR="FORECAST.LINEAR",t.FREQUENCY="FREQUENCY",t.GAMMA="GAMMA",t.GAMMA_DIST="GAMMA.DIST",t.GAMMA_INV="GAMMA.INV",t.GAMMALN="GAMMALN",t.GAMMALN_PRECISE="GAMMALN.PRECISE",t.GAUSS="GAUSS",t.GEOMEAN="GEOMEAN",t.GROWTH="GROWTH",t.HARMEAN="HARMEAN",t.HYPGEOM_DIST="HYPGEOM.DIST",t.INTERCEPT="INTERCEPT",t.KURT="KURT",t.LARGE="LARGE",t.LINEST="LINEST",t.LOGEST="LOGEST",t.LOGNORM_DIST="LOGNORM.DIST",t.LOGNORM_INV="LOGNORM.INV",t.MAX="MAX",t.MAXA="MAXA",t.MAXIFS="MAXIFS",t.MEDIAN="MEDIAN",t.MIN="MIN",t.MINA="MINA",t.MINIFS="MINIFS",t.MODE_MULT="MODE.MULT",t.MODE_SNGL="MODE.SNGL",t.NEGBINOM_DIST="NEGBINOM.DIST",t.NORM_DIST="NORM.DIST",t.NORM_INV="NORM.INV",t.NORM_S_DIST="NORM.S.DIST",t.NORM_S_INV="NORM.S.INV",t.PEARSON="PEARSON",t.PERCENTILE_EXC="PERCENTILE.EXC",t.PERCENTILE_INC="PERCENTILE.INC",t.PERCENTRANK_EXC="PERCENTRANK.EXC",t.PERCENTRANK_INC="PERCENTRANK.INC",t.PERMUT="PERMUT",t.PERMUTATIONA="PERMUTATIONA",t.PHI="PHI",t.POISSON_DIST="POISSON.DIST",t.PROB="PROB",t.QUARTILE_EXC="QUARTILE.EXC",t.QUARTILE_INC="QUARTILE.INC",t.RANK_AVG="RANK.AVG",t.RANK_EQ="RANK.EQ",t.RSQ="RSQ",t.SKEW="SKEW",t.SKEW_P="SKEW.P",t.SLOPE="SLOPE",t.SMALL="SMALL",t.STANDARDIZE="STANDARDIZE",t.STDEV_P="STDEV.P",t.STDEV_S="STDEV.S",t.STDEVA="STDEVA",t.STDEVPA="STDEVPA",t.STEYX="STEYX",t.T_DIST="T.DIST",t.T_DIST_2T="T.DIST.2T",t.T_DIST_RT="T.DIST.RT",t.T_INV="T.INV",t.T_INV_2T="T.INV.2T",t.T_TEST="T.TEST",t.TREND="TREND",t.TRIMMEAN="TRIMMEAN",t.VAR_P="VAR.P",t.VAR_S="VAR.S",t.VARA="VARA",t.VARPA="VARPA",t.WEIBULL_DIST="WEIBULL.DIST",t.Z_TEST="Z.TEST",t))(le||{});class Hs extends F{calculate(...n){let e=new C(-1/0);for(let r=0;r<n.length;r++){let s=n[r];if(s.isError())return s;s.isArray()&&(s=s.max()),!s.isNull()&&(e=this._validator(e,s))}return e}_validator(n,e){return n.isLessThan(e).getValue()&&(n=e),n}}class pr extends F{calculate(...n){let e=new C(1/0);for(let r=0;r<n.length;r++){let s=n[r];if(s.isError())return s;s.isArray()&&(s=s.min()),!s.isNull()&&(e=this._validator(e,s))}return e}_validator(n,e){return n.isGreaterThan(e).getValue()&&(n=e),n}}const Rn=[[js,le.AVERAGE],[Qs,le.COUNT],[Hs,le.MAX],[pr,le.MIN],[pr,le.MIN],[Ts,le.COUNTA]];class Ys extends F{calculate(n,e){return new d(f.VALUE)}}var yt=(t=>(t.ASC="ASC",t.ARRAYTOTEXT="ARRAYTOTEXT",t.BAHTTEXT="BAHTTEXT",t.CHAR="CHAR",t.CLEAN="CLEAN",t.CODE="CODE",t.CONCAT="CONCAT",t.CONCATENATE="CONCATENATE",t.DBCS="DBCS",t.DOLLAR="DOLLAR",t.EXACT="EXACT",t.FIND="FIND",t.FINDB="FINDB",t.FIXED="FIXED",t.LEFT="LEFT",t.LEFTB="LEFTB",t.LEN="LEN",t.LENB="LENB",t.LOWER="LOWER",t.MID="MID",t.MIDB="MIDB",t.NUMBERVALUE="NUMBERVALUE",t.PHONETIC="PHONETIC",t.PROPER="PROPER",t.REPLACE="REPLACE",t.REPLACEB="REPLACEB",t.REPT="REPT",t.RIGHT="RIGHT",t.RIGHTB="RIGHTB",t.SEARCH="SEARCH",t.SEARCHB="SEARCHB",t.SUBSTITUTE="SUBSTITUTE",t.T="T",t.TEXT="TEXT",t.TEXTAFTER="TEXTAFTER",t.TEXTBEFORE="TEXTBEFORE",t.TEXTJOIN="TEXTJOIN",t.TEXTSPLIT="TEXTSPLIT",t.TRIM="TRIM",t.UNICHAR="UNICHAR",t.UNICODE="UNICODE",t.UPPER="UPPER",t.VALUE="VALUE",t.VALUETOTEXT="VALUETOTEXT",t.CALL="CALL",t.EUROCONVERT="EUROCONVERT",t.REGISTER_ID="REGISTER.ID",t))(yt||{});const pn=[[Ys,yt.CONCATENATE]],Dn=[];var Ws=(t=>{})();const En=[];var _n=(t=>(t.ENCODEURL="ENCODEURL",t.FILTERXML="FILTERXML",t.WEBSERVICE="WEBSERVICE",t))(_n||{});class Xs extends g.Disposable{constructor(){super(...arguments);p(this,"_definedNameMap",new Map)}dispose(){this._definedNameMap.clear()}registerDefinedName(e,r,s){var a;this._definedNameMap.get(e)==null&&this._definedNameMap.set(e,new Map),(a=this._definedNameMap.get(e))==null||a.set(r,s)}removeDefinedName(e,r){var s;(s=this._definedNameMap.get(e))==null||s.delete(r)}getDefinedNameMap(e){return this._definedNameMap.get(e)}getValue(e,r){var s;return(s=this._definedNameMap.get(e))==null?void 0:s.get(r)}hasDefinedName(e){var s;return(((s=this._definedNameMap.get(e))==null?void 0:s.size)||0)!==0}}const bt=P.createIdentifier("univer.formula.defined-names.service");var Gs=Object.defineProperty,Ks=Object.getOwnPropertyDescriptor,Is=(t,n,e,r)=>{for(var s=r>1?void 0:r?Ks(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Gs(n,e,s),s},zs=(t,n)=>(e,r)=>n(e,r,t);let kt=class extends g.Disposable{constructor(n){super();p(this,"_unitData",{});p(this,"_arrayFormulaCellData",{});p(this,"_formulaData",{});p(this,"_sheetNameMap",{});p(this,"_forceCalculate",!1);p(this,"_dirtyRanges",[]);p(this,"_dirtyNameMap",{});p(this,"_dirtyUnitFeatureMap",{});p(this,"_excludedCell");this._currentUniverService=n}dispose(){this._unitData={},this._formulaData={},this._arrayFormulaCellData={},this._sheetNameMap={},this._dirtyRanges=[],this._dirtyNameMap={},this._dirtyUnitFeatureMap={},this._excludedCell={}}getExcludedRange(){return this._excludedCell}getUnitData(){return this._unitData}getFormulaData(){return this._formulaData}getArrayFormulaCellData(){return this._arrayFormulaCellData}getSheetNameMap(){return this._sheetNameMap}isForceCalculate(){return this._forceCalculate}getDirtyRanges(){return this._dirtyRanges}getDirtyNameMap(){return this._dirtyNameMap}getDirtyUnitFeatureMap(){return this._dirtyUnitFeatureMap}load(n){if(n.allUnitData&&n.unitSheetNameMap)this._unitData=n.allUnitData,this._sheetNameMap=n.unitSheetNameMap;else{const{allUnitData:e,unitSheetNameMap:r}=this._loadSheetData();this._unitData=e,this._sheetNameMap=r}this._formulaData=n.formulaData,this._arrayFormulaCellData=vr(n.arrayFormulaCellData),this._forceCalculate=n.forceCalculate,this._dirtyRanges=n.dirtyRanges,this._dirtyNameMap=n.dirtyNameMap,this._dirtyUnitFeatureMap=n.dirtyUnitFeatureMap,this._excludedCell=n.excludedCell}loadDirtyRangesAndExcludedCell(n,e){this._dirtyRanges=n,this._excludedCell=e,this._dirtyNameMap={}}registerUnitData(n){this._unitData=n}registerFormulaData(n){this._formulaData=n}registerSheetNameMap(n){this._sheetNameMap=n}_loadSheetData(){const n=this._currentUniverService.getAllUniverSheetsInstance(),e={},r={};for(const s of n){const i=s.getUnitId(),a=s.getSheets(),o={},u={};for(const l of a){const c=l.getSheetId(),h=l.getConfig();o[c]={cellData:new g.ObjectMatrix(h.cellData),rowCount:h.rowCount,columnCount:h.columnCount},u[l.getName()]=l.getSheetId()}e[i]=o,r[i]=u}return{allUnitData:e,unitSheetNameMap:r}}};kt=Is([zs(0,g.IUniverInstanceService)],kt);const Le=P.createIdentifier("univer.formula.current-data.service");var qs=Object.defineProperty,Zs=Object.getOwnPropertyDescriptor,Js=(t,n,e,r)=>{for(var s=r>1?void 0:r?Zs(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&qs(n,e,s),s},Ns=(t,n)=>(e,r)=>n(e,r,t),ee=(t=>(t[t.IDLE=0]="IDLE",t[t.START_DEPENDENCY=1]="START_DEPENDENCY",t[t.START_CALCULATION=2]="START_CALCULATION",t[t.CURRENTLY_CALCULATING=3]="CURRENTLY_CALCULATING",t[t.START_DEPENDENCY_ARRAY_FORMULA=4]="START_DEPENDENCY_ARRAY_FORMULA",t[t.START_CALCULATION_ARRAY_FORMULA=5]="START_CALCULATION_ARRAY_FORMULA",t[t.CURRENTLY_CALCULATING_ARRAY_FORMULA=6]="CURRENTLY_CALCULATING_ARRAY_FORMULA",t[t.CALCULATION_COMPLETED=7]="CALCULATION_COMPLETED",t))(ee||{}),Pe=(t=>(t[t.INITIAL=0]="INITIAL",t[t.STOP_EXECUTION=1]="STOP_EXECUTION",t[t.NOT_EXECUTED=2]="NOT_EXECUTED",t[t.SUCCESS=3]="SUCCESS",t))(Pe||{});let jt=class extends g.Disposable{constructor(n){super();p(this,"_formulaExecuteStage",0);p(this,"_stopState",!1);p(this,"_currentRow",-1);p(this,"_currentColumn",-1);p(this,"_currentRowCount",-1/0);p(this,"_currentColumnCount",-1/0);p(this,"_currentSubUnitId","");p(this,"_currentUnitId","");p(this,"_runtimeData",{});p(this,"_runtimeOtherData",{});p(this,"_unitArrayFormulaRange",{});p(this,"_runtimeArrayFormulaCellData",{});p(this,"_runtimeClearArrayFormulaCellData",{});p(this,"_runtimeFeatureRange",{});p(this,"_runtimeFeatureCellData",{});p(this,"_functionsExecutedState",0);p(this,"_functionDefinitionPrivacyVar",new Map);p(this,"_totalFormulasToCalculate",0);p(this,"_completedFormulasCount",0);p(this,"_totalArrayFormulasToCalculate",0);p(this,"_completedArrayFormulasCount",0);p(this,"_isCycleDependency",!1);this._currentConfigService=n}get currentRow(){return this._currentRow}get currentColumn(){return this._currentColumn}get currentRowCount(){return this._currentRowCount}get currentColumnCount(){return this._currentColumnCount}get currentSubUnitId(){return this._currentSubUnitId}get currentUnitId(){return this._currentUnitId}dispose(){this.reset(),this._runtimeFeatureCellData={},this._runtimeFeatureRange={}}enableCycleDependency(){this._isCycleDependency=!0}disableCycleDependency(){this._isCycleDependency=!1}isCycleDependency(){return this._isCycleDependency}setTotalArrayFormulasToCalculate(n){this._totalArrayFormulasToCalculate=n}getTotalArrayFormulasToCalculate(){return this._totalArrayFormulasToCalculate}setCompletedArrayFormulasCount(n){this._completedArrayFormulasCount=n}getCompletedArrayFormulasCount(){return this._completedArrayFormulasCount}setTotalFormulasToCalculate(n){this._totalFormulasToCalculate=n}getTotalFormulasToCalculate(){return this._totalFormulasToCalculate}setCompletedFormulasCount(n){this._completedFormulasCount=n}getCompletedFormulasCount(){return this._completedFormulasCount}markedAsSuccessfullyExecuted(){this._functionsExecutedState=3}markedAsNoFunctionsExecuted(){this._functionsExecutedState=2}markedAsStopFunctionsExecuted(){this._functionsExecutedState=1}markedAsInitialFunctionsExecuted(){this._functionsExecutedState=0}stopExecution(){this._stopState=!0,this.setFormulaExecuteStage(0)}isStopExecution(){return this._stopState}setFormulaExecuteStage(n){this._formulaExecuteStage=n}getFormulaExecuteStage(){return this._formulaExecuteStage}reset(){this._formulaExecuteStage=0,this._runtimeData={},this._runtimeOtherData={},this._unitArrayFormulaRange={},this._runtimeArrayFormulaCellData={},this._runtimeClearArrayFormulaCellData={},this._functionDefinitionPrivacyVar.clear(),this.markedAsInitialFunctionsExecuted(),this._isCycleDependency=!1,this._totalFormulasToCalculate=0,this._completedFormulasCount=0}setCurrent(n,e,r,s,i,a){this._currentRow=n,this._currentColumn=e,this._currentRowCount=r,this._currentColumnCount=s,this._currentSubUnitId=i,this._currentUnitId=a}clearFunctionDefinitionPrivacyVar(){this._functionDefinitionPrivacyVar.clear()}registerFunctionDefinitionPrivacyVar(n,e){this._functionDefinitionPrivacyVar.set(n,e)}getFunctionDefinitionPrivacyVar(n){return this._functionDefinitionPrivacyVar.get(n)}setRuntimeOtherData(n,e){const r=this._currentSubUnitId,s=this._currentUnitId;this._runtimeOtherData[s]===void 0&&(this._runtimeOtherData[s]={});const i=this._runtimeOtherData[s];i[r]===void 0&&(i[r]={});const a=i[r];a[n]=this._objectValueToCellValue(e)}setRuntimeData(n){const e=this._currentRow,r=this._currentColumn,s=this._currentRowCount,i=this.currentColumnCount,a=this._currentSubUnitId,o=this._currentUnitId;this._runtimeData[o]==null&&(this._runtimeData[o]={});const u=this._runtimeData[o];u[a]==null&&(u[a]=new g.ObjectMatrix),this._unitArrayFormulaRange[o]==null&&(this._unitArrayFormulaRange[o]={});const l=this._unitArrayFormulaRange[o];let c=new g.ObjectMatrix;l[a]&&(c=new g.ObjectMatrix(l[a])),this._runtimeArrayFormulaCellData[o]===void 0&&(this._runtimeArrayFormulaCellData[o]={});const h=this._runtimeArrayFormulaCellData[o];h[a]==null&&(h[a]=new g.ObjectMatrix),this._runtimeClearArrayFormulaCellData[o]===void 0&&(this._runtimeClearArrayFormulaCellData[o]={});const m=this._runtimeClearArrayFormulaCellData[o];m[a]==null&&(m[a]=new g.ObjectMatrix);const D=u[a],_=h[a],R=m[a];if(n.isReferenceObject()||n.isValueObject()&&n.isArray()){const E=n,{startRow:y,startColumn:b,endRow:L,endColumn:S}=E.getRangePosition();if(y===L&&b===S){const k=this._objectValueToCellValue(E.getFirstCell());D.setValue(e,r,k),R.setValue(e,r,k);return}const $={startRow:e,startColumn:r,endRow:L-y+e,endColumn:S-b+r};if(c.setValue(e,r,$),l[a]=c.getData(),this._checkIfArrayFormulaRangeHasData(o,a,e,r,$)||this._checkIfArrayFormulaExceeded(s,i,$)){const k=this._objectValueToCellValue(new d(f.SPILL));D.setValue(e,r,k),R.setValue(e,r,k)}else{const k=new d(f.SPILL);E.iterator((Q,A,x)=>{const U=this._objectValueToCellValue(Q);if(A===y&&x===b){if(Q!=null&&Q.isError()&&Q.isEqualType(k))return R.setValue(e,r,{}),D.setValue(e,r,{...this._objectValueToCellValue(k)}),!1;D.setValue(e,r,{...U})}_.setValue(A-y+e,x-b+r,U)})}}else{const E=this._objectValueToCellValue(n);D.setValue(e,r,E),R.setValue(e,r,E)}}getUnitData(){return this._runtimeData}getUnitArrayFormula(){return this._unitArrayFormulaRange}getRuntimeOtherData(){return this._runtimeOtherData}getRuntimeArrayFormulaCellData(){return this._runtimeArrayFormulaCellData}getRuntimeClearArrayFormulaCellData(){return this._runtimeClearArrayFormulaCellData}getRuntimeFeatureRange(){return this._runtimeFeatureRange}setRuntimeFeatureRange(n,e){this._runtimeFeatureRange[n]=e}getRuntimeFeatureCellData(){return this._runtimeFeatureCellData}setRuntimeFeatureCellData(n,e){this._runtimeFeatureCellData[n]=e}getAllRuntimeData(){return{unitData:this.getUnitData(),arrayFormulaRange:this.getUnitArrayFormula(),unitOtherData:this.getRuntimeOtherData(),functionsExecutedState:this._functionsExecutedState,arrayFormulaCellData:this.getRuntimeArrayFormulaCellData(),clearArrayFormulaCellData:this.getRuntimeClearArrayFormulaCellData(),runtimeFeatureRange:this.getRuntimeFeatureRange(),runtimeFeatureCellData:this.getRuntimeFeatureCellData()}}getRuntimeState(){return{totalFormulasToCalculate:this.getTotalFormulasToCalculate(),completedFormulasCount:this.getCompletedFormulasCount(),totalArrayFormulasToCalculate:this.getTotalArrayFormulasToCalculate(),completedArrayFormulasCount:this.getCompletedArrayFormulasCount(),stage:this.getFormulaExecuteStage()}}_objectValueToCellValue(n){if(n==null)return{v:0,t:g.CellValueType.NUMBER};if(n.isError())return{v:n.getErrorType(),t:g.CellValueType.STRING};if(n.isValueObject()){const e=n,r=e.getValue();return e.isNumber()?{v:r,t:g.CellValueType.NUMBER}:e.isBoolean()?{v:r,t:g.CellValueType.BOOLEAN}:{v:r,t:g.CellValueType.STRING}}}_checkIfArrayFormulaRangeHasData(n,e,r,s,i){var m,D,_,R,E,y,b,L,S,$,k,Q;const{startRow:a,startColumn:o,endRow:u,endColumn:l}=i,c=this._currentConfigService.getUnitData(),h=(_=(D=(m=this._unitArrayFormulaRange[n])==null?void 0:m[e])==null?void 0:D[r])==null?void 0:_[s];for(let A=a;A<=u;A++)for(let x=o;x<=l;x++){if(A===r&&s===x)continue;const U=(y=(E=(R=this._runtimeData)==null?void 0:R[n])==null?void 0:E[e])==null?void 0:y.getValue(A,x),M=(S=(L=(b=this._runtimeArrayFormulaCellData)==null?void 0:b[n])==null?void 0:L[e])==null?void 0:S.getValue(A,x),vn=(Q=(k=($=c==null?void 0:c[n])==null?void 0:$[e])==null?void 0:k.cellData)==null?void 0:Q.getValue(A,x);if(!g.isNullCell(U)||!g.isNullCell(M)&&!this._isInArrayFormulaRange(h,A,x)||!g.isNullCell(vn))return!0}return!1}_isInArrayFormulaRange(n,e,r){if(n==null)return!1;const{startRow:s,startColumn:i,endRow:a,endColumn:o}=n;return e>=s&&e<=a&&r>=i&&r<=o}_checkIfArrayFormulaExceeded(n,e,r){return r.endRow>=n||r.endColumn>=e}_isInDirtyRange(n,e,r,s){const i=this._currentConfigService.getDirtyRanges();return i.length===0?!0:Sr(i,n,e,r,s)}};jt=Js([Ns(0,Le)],jt);const N=P.createIdentifier("univer.formula.runtime.service");var ei=Object.defineProperty,ti=Object.getOwnPropertyDescriptor,ri=(t,n,e,r)=>{for(var s=r>1?void 0:r?ti(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&ei(n,e,s),s},At=(t,n)=>(e,r)=>n(e,r,t);let we=class extends g.Disposable{constructor(t,n,e){super(),this._definedNamesService=t,this._runtimeService=n,this._lexerTreeBuilder=e}treeBuilder(t,n=!0){return this._lexerTreeBuilder.treeBuilder(t,n,this._injectDefinedName.bind(this))}_injectDefinedName(t){var i;const n=this._runtimeService.currentUnitId;if(!this._definedNamesService.hasDefinedName(n))return{sequenceString:"",hasDefinedName:!1};const e=this._lexerTreeBuilder.getSequenceNode(t);let r="",s=!1;for(let a=0,o=e.length;a<o;a++){const u=e[a];if(typeof u=="string"){r+=u;continue}const{nodeType:l,token:c}=u;if(l===I.REFERENCE||l===I.FUNCTION){const h=(i=this._definedNamesService.getDefinedNameMap(n))==null?void 0:i.get(c);h?(r+=h,s=!0):r+=c}else r+=c}return{sequenceString:r,hasDefinedName:s}}};we=ri([At(0,bt),At(1,N),At(2,P.Inject(Dt))],we);var v=(t=>(t.REFERENCE="ReferenceNode",t.VALUE="ValueNode",t.OPERATOR="OperatorNode",t.FUNCTION="FunctionNode",t.LAMBDA="LambdaNode",t.LAMBDA_PARAMETER="LambdaNodeParameter",t.ERROR="ErrorNode",t.BASE="Base",t.ROOT="Root",t.UNION="UnionNode",t.PREFIX="PrefixNode",t.SUFFIX="SuffixNode",t.NULL="NullNode",t))(v||{});const re=new Map([["ReferenceNode",7],["ValueNode",9],["OperatorNode",8],["FunctionNode",6],["LambdaNode",1],["LambdaNodeParameter",2],["Root",10],["UnionNode",3],["PrefixNode",4],["SuffixNode",5]]);class K extends g.Disposable{constructor(e){super();p(this,"_children",[]);p(this,"_parent");p(this,"_valueObject");p(this,"_calculateState",!1);p(this,"_async",!1);p(this,"_address",!1);p(this,"_refOffsetX",0);p(this,"_refOffsetY",0);this._token=e}dispose(){var e;this._children.forEach(r=>{r.dispose()}),(e=this._valueObject)==null||e.dispose(),this._parent=null}get nodeType(){return v.BASE}isAsync(){return this._async}isAddress(){return this._address}setAsync(){this._async=!0}setAddress(){this._address=!0}getParent(){return this._parent}setParent(e){this._parent=e,e.addChildren(this)}getChildren(){return this._children}addChildren(...e){this._children.push(...e)}getToken(){return this._token}setValue(e){this._valueObject=e}getValue(){return this._valueObject}isCalculated(){return this._calculateState}setCalculated(){this._calculateState=!0}execute(){}setNotEmpty(e=!0){}setRefOffset(e=0,r=0){this._refOffsetX=e,this._refOffsetY=r}getRefOffset(){return{x:this._refOffsetX,y:this._refOffsetY}}async executeAsync(){return Promise.resolve(De.SUCCESS)}serialize(){const e=this.getToken(),r=this.getChildren(),s=[],i=r.length;for(let o=0;o<i;o++){const u=r[o];s.push(u.serialize())}const a={token:e,nodeType:this.nodeType};return i>0&&(a.children=s),a}}class T extends K{constructor(e){super(e);p(this,"_errorValueObject");this._errorValueObject=new d(e)}get nodeType(){return v.ERROR}static create(e){return new T(e)}getValue(){return this._errorValueObject}}const ne=100;class se extends g.Disposable{get zIndex(){return 0}create(n,e,r){let s;return n instanceof V?s=n.getToken():s=n,new K(s)}checkAndCreateNodeType(n){}}class Qt extends K{get nodeType(){return v.ROOT}execute(){const e=this.getChildren()[0];this.setValue(e.getValue())}}class Cn extends se{get zIndex(){return re.get(v.ROOT)||ne}checkAndCreateNodeType(n){if(!(n instanceof V))return;if(n.getToken()===ce)return new Qt(ce)}}class wn extends g.Disposable{constructor(){super(...arguments);p(this,"_functionExecutors",new Map);p(this,"_functionDescriptions",new Map)}dispose(){this._functionExecutors.clear(),this._functionDescriptions.clear()}registerExecutors(...e){for(let r=0;r<e.length;r++){const s=e[r];this._functionExecutors.set(s.name,s)}}getExecutors(){return this._functionExecutors}getExecutor(e){return this._functionExecutors.get(e)}hasExecutor(e){return this._functionExecutors.has(e)}unregisterExecutors(...e){for(let r=0;r<e.length;r++){const s=e[r];this._functionExecutors.delete(s)}}registerDescriptions(...e){for(let r=0;r<e.length;r++){const s=e[r];this._functionDescriptions.set(s.functionName,s)}}getDescriptions(){return this._functionDescriptions}getDescription(e){return this._functionDescriptions.get(e)}hasDescription(e){return this._functionDescriptions.has(e)}unregisterDescriptions(...e){for(let r=0;r<e.length;r++){const s=e[r];this._functionDescriptions.delete(s)}}}const oe=P.createIdentifier("univer.formula.function.service");var ni=Object.defineProperty,si=Object.getOwnPropertyDescriptor,ii=(t,n,e,r)=>{for(var s=r>1?void 0:r?si(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&ni(n,e,s),s},Dr=(t,n)=>(e,r)=>n(e,r,t);class ut extends K{constructor(n,e,r){super(e),this._accessor=n,this._operatorString=e,this._functionExecutor=r}get nodeType(){return v.PREFIX}execute(){let e=this.getChildren()[0].getValue(),r;if(e==null)throw new Error("object is null");e.isReferenceObject()&&(e=e.toArrayValueObject()),this._operatorString===j.MINUS?r=this._functionExecutor.calculate(new C(0),e):this._operatorString===j.AT?r=this._handlerAT(e):r=new d(f.VALUE),this.setValue(r)}_handlerAT(n){if(!n.isReferenceObject())return new d(f.VALUE);const e=n;if(e.isCell())return new d(f.VALUE);const r=this._accessor.get(N),s=r.currentRow||0,i=r.currentColumn||0;return e.isRow()?e.getCellByColumn(i):e.isColumn()?e.getCellByRow(s):e.isRange()||e.isTable()?e.getCellByPosition():new d(f.VALUE)}}let lt=class extends se{constructor(t,n){super(),this._functionService=t,this._injector=n}get zIndex(){return re.get(v.PREFIX)||ne}checkAndCreateNodeType(t){if(!(t instanceof V))return;const n=t.getToken(),e=n.trim();if(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;let r="";if(e===j.MINUS)r=X.MINUS;else return e===j.AT?new ut(this._injector,e):void 0;const s=this._functionService.getExecutor(r);return s?new ut(this._injector,e,s):(console.error(`No function ${n}`),T.create(f.NAME))}};lt=ii([Dr(0,oe),Dr(1,P.Inject(P.Injector))],lt);var ai=Object.defineProperty,oi=Object.getOwnPropertyDescriptor,ui=(t,n,e,r)=>{for(var s=r>1?void 0:r?oi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&ai(n,e,s),s},Xe=(t,n)=>(e,r)=>n(e,r,t);class li extends K{constructor(n,e,r,s){super(n),this._functionExecutor=e,this._currentConfigService=r,this._runtimeService=s,this._functionExecutor.isAsync()&&this.setAsync(),this._functionExecutor.isAddress()&&this.setAddress()}get nodeType(){return v.FUNCTION}async executeAsync(){const n=[],e=this.getChildren(),r=e.length;for(let a=0;a<r;a++){const o=e[a].getValue();o!=null&&(o.isReferenceObject()?n.push(o.toArrayValueObject()):n.push(o))}const s=this._calculate(n);let i;return s.isAsyncObject()||s.isAsyncArrayObject()?i=await s.getValue():i=s,this._setRefData(i),this.setValue(i),Promise.resolve(De.SUCCESS)}execute(){const n=[],e=this.getChildren(),r=e.length;for(let i=0;i<r;i++){const a=e[i].getValue();a!=null&&(a.isReferenceObject()?n.push(a.toArrayValueObject()):n.push(a))}const s=this._calculate(n);this._setRefData(s),this.setValue(s)}_calculate(n){var r;let e;if(this._setRefInfo(),this._functionExecutor.isCustom()){const s=this._functionExecutor.calculateCustom(...n.map(i=>i.isArray()?i.toValue():i.getValue()));if(typeof s!="object"||s==null)e=fe.create(s);else{const i=cs(s);e=new J({calculateValueList:i,rowCount:i.length,columnCount:((r=i[0])==null?void 0:r.length)||0,unitId:"",sheetId:"",row:-1,column:-1})}}else e=this._functionExecutor.calculate(...n);return e}_setRefInfo(){const{currentUnitId:n,currentSubUnitId:e,currentRow:r,currentColumn:s}=this._runtimeService;this._functionExecutor.setRefInfo(n,e,r,s)}_setRefData(n){if(!n.isReferenceObject())return;const e=n;e.setForcedSheetId(this._currentConfigService.getSheetNameMap()),e.setUnitData(this._currentConfigService.getUnitData()),e.setArrayFormulaCellData(this._currentConfigService.getArrayFormulaCellData()),e.setRuntimeData(this._runtimeService.getUnitData()),e.setRuntimeArrayFormulaCellData(this._runtimeService.getRuntimeArrayFormulaCellData()),e.setRuntimeFeatureCellData(this._runtimeService.getRuntimeFeatureCellData())}}let ct=class extends se{constructor(t,n,e,r){super(),this._functionService=t,this._currentConfigService=n,this._runtimeService=e,this._injector=r}get zIndex(){return re.get(v.FUNCTION)||ne}create(t){const n=this._functionService.getExecutor(t);return n?new li(t,n,this._currentConfigService,this._runtimeService):(console.error(`No function ${t}`),T.create(f.NAME))}checkAndCreateNodeType(t){if(typeof t=="string")return;let e=t.getToken().trim().toUpperCase(),r,s;const i=e.slice(0,2);let a=0;if(new RegExp(j.MINUS,"g").test(i)){const o=this._functionService.getExecutor(X.MINUS);r=new ut(this._injector,j.MINUS,o),a++}if(new RegExp(j.AT,"g").test(i)&&(s=new ut(this._injector,j.AT),r&&s.setParent(r),a++),a>0&&(e=e.slice(a)),this._functionService.hasExecutor(e)){const o=this.create(e);return s?o.setParent(s):r&&o.setParent(r),o}}};ct=ui([Xe(0,oe),Xe(1,Le),Xe(2,N),Xe(3,P.Inject(P.Injector))],ct);var ci=Object.defineProperty,hi=Object.getOwnPropertyDescriptor,fi=(t,n,e,r)=>{for(var s=r>1?void 0:r?hi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&ci(n,e,s),s},di=(t,n)=>(e,r)=>n(e,r,t);let Ve=class extends g.Disposable{constructor(t){super(),this._runtimeService=t}dispose(){}async executeAsync(t){if(!t)return new d(f.VALUE);await this._executeAsync(t);const n=t.getValue();if(n==null)throw new Error("node value is null");return Promise.resolve(n)}execute(t){if(!t)return new d(f.VALUE);this._execute(t);const n=t.getValue();if(n==null)throw new Error("node value is null");return n}executePreCalculateNode(t){return t.execute(),t.getValue()}checkAsyncNode(t){const n=[];this._checkAsyncNode(t,n);for(let e=0,r=n.length;e<r;e++)if(n[e]===!0)return!0;return!1}_checkAsyncNode(t,n){const e=t.getChildren(),r=e.length;for(let s=0;s<r;s++){const i=e[s];n.push(i.isAsync()),this._checkAsyncNode(i,n)}}async _executeAsync(t){if(this._runtimeService.isStopExecution())return Promise.resolve(De.ERROR);const n=t.getChildren(),e=n.length;for(let r=0;r<e;r++){const s=n[r];if(s.getToken().toUpperCase()===je&&s.isEmptyParamFunction()){s.execute();continue}await this._executeAsync(s)}return t.nodeType===v.FUNCTION&&t.isAsync()?await t.executeAsync():t.execute(),Promise.resolve(De.SUCCESS)}_execute(t){if(this._runtimeService.isStopExecution())return De.ERROR;const n=t.getChildren(),e=n.length;for(let r=0;r<e;r++){const s=n[r];if(s.getToken().toUpperCase()===je&&s.isEmptyParamFunction()){s.execute();continue}this._execute(s)}return t.execute(),De.SUCCESS}};Ve=fi([di(0,N)],Ve);function yn(t){return t instanceof V?t.getToken()===xe:!1}function mi(t){return t instanceof V?t.getToken()===kr:!1}function bn(t){if(!t)return;if(t.getToken()!==He)return t;const n=t,e=n.getCurrentLambdaPrivacyVar(),r=n.getLambdaParameter();if(!e)return;const s=e.get(r);return s==null&&t.getValue()?t:bn(s)}class gi extends de{constructor(e,r,s){super(0);p(this,"_lambdaPrivacyValueMap",new Map);this._lambdaNode=e,this._interpreter=r,this._lambdaPrivacyVarKeys=s,this._lambdaPrivacyValueMap.clear()}isLambda(){return!0}execute(...e){const r=this._lambdaPrivacyVarKeys.length;if(e.length!==r)return new d(f.VALUE);this._setLambdaPrivacyValueMap(e),this._setLambdaNodeValue(this._lambdaNode),this._lambdaNode.setNotEmpty(!1);let s;if(this._interpreter.checkAsyncNode(this._lambdaNode))s=new ds(this._interpreter.executeAsync(this._lambdaNode));else{const i=this._interpreter.execute(this._lambdaNode);i.isReferenceObject()?s=i.toArrayValueObject():s=i}return this._lambdaNode.setNotEmpty(!0),s}_setLambdaNodeValue(e){const r=e.getChildren(),s=r.length;for(let i=0;i<s;i++){const a=r[i];if(a.getToken()===He){const u=a.getLambdaParameter(),l=this._lambdaPrivacyValueMap.get(u);if(l)a.setValue(l);else{const c=a.getCurrentLambdaPrivacyVar(),h=bn(c.get(u));h!=null&&a.setValue(h.getValue())}continue}this._setLambdaNodeValue(a)}}_setLambdaPrivacyValueMap(e){for(let r=0;r<e.length;r++){const s=e[r],i=this._lambdaPrivacyVarKeys[r];this._lambdaPrivacyValueMap.set(i,s)}}}var Ri=Object.defineProperty,pi=Object.getOwnPropertyDescriptor,Di=(t,n,e,r)=>{for(var s=r>1?void 0:r?pi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Ri(n,e,s),s},Er=(t,n)=>(e,r)=>n(e,r,t);class Ei extends K{constructor(e,r,s,i){super(e);p(this,"_isNotEmpty",!0);this._lambdaId=r,this._interpreter=s,this._lambdaPrivacyVarKeys=i}get nodeType(){return v.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 gi(this,this._interpreter,this._lambdaPrivacyVarKeys));else{const e=this.getChildren(),r=e.length;this.setValue(e[r-1].getValue())}}}let ht=class extends se{constructor(t,n){super(),this._runtimeService=t,this._interpreter=n}get zIndex(){return re.get(v.LAMBDA)||ne}create(t){const n=t.getChildren(),e=n[0];let r=n.slice(1,-1);const s=n[n.length-1];if(!(e instanceof V&&s instanceof V))return T.create(f.NAME);if(e.getToken()===xe){const o=e.getChildren();if(r.length!==o.length)return T.create(f.VALUE)}else r=n.slice(0,-1);const i=g.Tools.generateRandomId(8),a=new Map;for(let o=0;o<r.length;o++){const u=r[o];if(u instanceof V){const l=u.getChildren()[0];u.setToken(kr),a.set(l.trim(),void 0)}else return T.create(f.VALUE)}return this._runtimeService.registerFunctionDefinitionPrivacyVar(i,a),this._updateLambdaStatement(s,i,a),new Ei(t.getToken(),i,this._interpreter,[...a.keys()])}checkAndCreateNodeType(t){if(!(!(t instanceof V)||t.getToken().trim().toUpperCase()!==je))return this.create(t)}_updateLambdaStatement(t,n,e){this._updateTree(t,n,e)}_updateTree(t,n,e){const r=t.getChildren(),s=r.length,i=r[0];for(let a=0;a<s;a++){const o=r[a];if(!(yn(i)&&a!==0))if(o instanceof V)this._updateTree(o,n,e);else{const u=o.trim();if(e.has(u)){const l=new V;l.setToken(He),l.setLambdaId(n),l.setLambdaPrivacyVar(e),l.setLambdaParameter(u),r[a]=l}}}}};ht=Di([Er(0,N),Er(1,P.Inject(Ve))],ht);function Ln(t){if(!t)return;if(t.getToken()!==He)return t;const n=t,e=n.getCurrentLambdaPrivacyVar(),r=n.getLambdaParameter();if(e)return Ln(e.get(r))}class _i extends K{constructor(n,e,r){super(n),this._lambdaParameter=e,this._currentLambdaPrivacyVar=r}getLambdaParameter(){return this._lambdaParameter}getCurrentLambdaPrivacyVar(){return this._currentLambdaPrivacyVar}get nodeType(){return v.LAMBDA_PARAMETER}execute(){const n=Ln(this._currentLambdaPrivacyVar.get(this._lambdaParameter));if(n)this.setValue(n.getValue());else{const e=this.getValue();(e==null||e.isError())&&this.setValue(new d(f.SPILL))}}}class Sn extends se{get zIndex(){return re.get(v.LAMBDA_PARAMETER)||ne}create(n){const e=n.getFunctionDefinitionPrivacyVar(),r=n.getLambdaParameter();return e?new _i(n.getToken(),r,e):new T(f.SPILL)}checkAndCreateNodeType(n){if(!(!(n instanceof V)||n.getToken().trim()!==He))return this.create(n)}}class Ci extends K{constructor(n){super(n),this._operatorString=n}get nodeType(){return v.NULL}execute(){this.setValue(new Qe(0))}}var wi=Object.defineProperty,yi=Object.getOwnPropertyDescriptor,bi=(t,n,e,r)=>{for(var s=r>1?void 0:r?yi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&wi(n,e,s),s},Li=(t,n)=>(e,r)=>n(e,r,t);class Si extends K{constructor(n,e){super(n),this._operatorString=n,this._functionExecutor=e}get nodeType(){return v.OPERATOR}execute(){const n=this.getChildren();this._functionExecutor.name===X.COMPARE&&this._functionExecutor.setCompareType(this.getToken());let e=n[0].getValue(),r=n[1].getValue();if(e==null||r==null)throw new Error("object1 or object2 is null");e.isReferenceObject()&&(e=e.toArrayValueObject()),r.isReferenceObject()&&(r=r.toArrayValueObject()),this.setValue(this._functionExecutor.calculate(e,r))}}let ft=class extends se{constructor(t){super(),this._functionService=t}get zIndex(){return re.get(v.OPERATOR)||ne}create(t){let n="";const e=t;e===G.PLUS?n=X.PLUS:e===G.MINUS?n=X.MINUS:e===G.MULTIPLY?n=X.MULTIPLY:e===G.DIVIDED?n=X.DIVIDED:e===G.CONCATENATE?n=yt.CONCATENATE:e===G.POWER?n=q.POWER:Bn.has(e)&&(n=X.COMPARE);const r=this._functionService.getExecutor(n);return r?new Si(e,r):(console.error(`No function ${t}`),T.create(f.NAME))}checkAndCreateNodeType(t){if(t instanceof V)return;const n=t.trim();if(!(n.charAt(0)==='"'&&n.charAt(n.length-1)==='"')&&Fe.has(n))return this.create(n)}};ft=bi([Li(0,oe)],ft);class Pi extends g.Disposable{constructor(){super(...arguments);p(this,"_tableMap",new Map);p(this,"_tableOptionMap",new Map)}dispose(){this._tableMap.clear(),this._tableOptionMap.clear()}remove(e,r){var s;(s=this._tableMap.get(e))==null||s.delete(r)}getTableMap(e){return this._tableMap.get(e)}getTableOptionMap(){return this._tableOptionMap}registerTable(e,r,s){var i;this._tableMap.get(e)==null&&this._tableMap.set(e,new Map),(i=this._tableMap.get(e))==null||i.set(r,s)}registerTableOptionMap(e,r){this._tableOptionMap.set(e,r)}}const rr=P.createIdentifier("univer.formula.super-table.service");class xi extends Be{constructor(n,e,r,s){super(n),this._tableData=e,this._columnDataString=r;const i=this._tableData.sheetId,a=this._tableData.range,o=this._tableData.titleMap;this.setForcedSheetIdDirect(i);const u=this._stringToColumnData(this._columnDataString,o,s),l=u.startColumn,c=u.endColumn,h=u.type;let m=-1,D=-1;const _=a.startRow,R=a.startColumn;h===pe.ALL?(m=_,D=R):h===pe.DATA?(m=_+1,D=R):h===pe.HEADERS?(m=_,D=_):h===pe.TOTALS&&(m=R,D=R),this.setRangeData({startColumn:l,endColumn:c,startRow:m,endRow:D})}isTable(){return!0}_stringToColumnData(n,e,r){n=n.substring(1,-1);const s=n.indexOf(O.COMMA);let i=-1,a=-1,o=pe.ALL;if(s===-1){const u=this._columnHandler(n,e);i=u.startColumn,a=u.endColumn}else{const u=n.substring(0,s).substring(1,-1),l=n.substring(s+1),c=this._columnHandler(l,e,!0);i=c.startColumn,a=c.endColumn,o=r.get(u),o||(o=pe.ALL)}return{startColumn:i,endColumn:a,type:o}}_columnHandler(n,e,r=!1){let s=-1,i=-1;const a=n.indexOf(O.COLON);if(new RegExp($r,"g").test(n)){const o=n.substring(0,a).substring(1,-1),u=n.substring(a+1).substring(1,-1);s=e.get(o)??-1,i=e.get(u)??-1}else r&&(n=n.substring(1,-1)),s=e.get(n)??-1,i=s;return{startColumn:s,endColumn:i}}}var Vi=Object.defineProperty,vi=Object.getOwnPropertyDescriptor,Ai=(t,n,e,r)=>{for(var s=r>1?void 0:r?vi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Vi(n,e,s),s},Ue=(t,n)=>(e,r)=>n(e,r,t);class Ge extends K{constructor(n,e,r){super(e),this._accessor=n,this._operatorString=e,this._referenceObject=r}get nodeType(){return v.REFERENCE}execute(){const n=this._accessor.get(Le),e=this._accessor.get(N);this._referenceObject.setDefaultUnitId(e.currentUnitId),this._referenceObject.setDefaultSheetId(e.currentSubUnitId),this._referenceObject.setForcedSheetId(n.getSheetNameMap()),this._referenceObject.setUnitData(n.getUnitData()),this._referenceObject.setArrayFormulaCellData(n.getArrayFormulaCellData()),this._referenceObject.setRuntimeData(e.getUnitData()),this._referenceObject.setRuntimeArrayFormulaCellData(e.getRuntimeArrayFormulaCellData()),this._referenceObject.setRuntimeFeatureCellData(e.getRuntimeFeatureCellData());const{x:r,y:s}=this.getRefOffset();this._referenceObject.setRefOffset(r,s),this._referenceObject.isExceedRange()?this.setValue(new d(f.NAME)):this.setValue(this._referenceObject)}}let dt=class extends se{constructor(t,n,e,r,s){super(),this._definedNamesService=t,this._superTableService=n,this._formulaRuntimeService=e,this._lexer=r,this._injector=s}get zIndex(){return re.get(v.REFERENCE)||ne}checkAndCreateNodeType(t){let n=!1,e;if(t instanceof V?(n=!0,e=t.getToken().trim()):e=t.trim(),!n&&e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;if(new RegExp(pt).test(e))return new Ge(this._injector,e,new tr(e));if(n&&new RegExp(Yn).test(e))return new Ge(this._injector,e,new fn(e));if(n&&new RegExp(Wn).test(e))return new Ge(this._injector,e,new hn(e));const r=this._formulaRuntimeService.currentUnitId,s=this._superTableService.getTableMap(r),i=new RegExp($r,"g"),a=e.replace(i,"");if(!n&&(s!=null&&s.has(a))){const o=i.exec(e);let u="";o&&(u=o[0]);const l=s.get(a),c=this._superTableService.getTableOptionMap();return new Ge(this._injector,e,new xi(e,l,u,c))}}};dt=Ai([Ue(0,bt),Ue(1,rr),Ue(2,N),Ue(3,P.Inject(we)),Ue(4,P.Inject(P.Injector))],dt);var Oi=Object.defineProperty,Bi=Object.getOwnPropertyDescriptor,Ui=(t,n,e,r)=>{for(var s=r>1?void 0:r?Bi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Oi(n,e,s),s},_r=(t,n)=>(e,r)=>n(e,r,t);class Cr extends K{constructor(n,e,r){super(e),this._accessor=n,this._operatorString=e,this._functionExecutor=r}get nodeType(){return v.SUFFIX}execute(){let e=this.getChildren()[0].getValue(),r;if(e==null)throw new Error("object is null");this._operatorString===ie.PERCENTAGE?(e.isReferenceObject()&&(e=e.toArrayValueObject()),r=this._functionExecutor.calculate(e,new C(100))):this._operatorString===ie.POUND?r=this._handlerPound(e):r=new d(f.VALUE),this.setValue(r)}_handlerPound(n){var c,h,m,D;if(!n.isReferenceObject())return new d(f.VALUE);if(!n.isCell())return new d(f.VALUE);const e=this._accessor.get(Le),r=this._accessor.get(we),s=n,i=s.getRangePosition(),a=s.getUnitId(),o=s.getSheetId(),u=e.getFormulaData(),l=(D=(m=(h=(c=u==null?void 0:u[a])==null?void 0:c[o])==null?void 0:h[i.startRow])==null?void 0:m[i.startColumn])==null?void 0:D.f;return l?(r.treeBuilder(l),new d(f.VALUE)):new d(f.VALUE)}}let mt=class extends se{constructor(t,n){super(),this._functionService=t,this._injector=n}get zIndex(){return re.get(v.SUFFIX)||ne}checkAndCreateNodeType(t){if(!(t instanceof V))return;const n=t.getToken().trim();if(n.charAt(0)==='"'&&n.charAt(n.length-1)==='"')return;let e="";if(n===ie.PERCENTAGE)e=X.DIVIDED;else return n===ie.POUND?new Cr(this._injector,n):void 0;const r=this._functionService.getExecutor(e);return r?new Cr(this._injector,n,r):(console.error(`No function ${t}`),T.create(f.NAME))}};mt=Ui([_r(0,oe),_r(1,P.Inject(P.Injector))],mt);var Fi=Object.defineProperty,Mi=Object.getOwnPropertyDescriptor,$i=(t,n,e,r)=>{for(var s=r>1?void 0:r?Mi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Fi(n,e,s),s},ki=(t,n)=>(e,r)=>n(e,r,t);class ji extends K{constructor(n){super(n),this._operatorString=n}get nodeType(){return v.UNION}execute(){const n=this.getChildren(),e=n[0].getValue(),r=n[1].getValue();if(e==null||r==null)throw new Error("leftNode and rightNode");let s;this._operatorString===O.COLON?s=this._unionFunction(e,r):s=new d(f.NAME),this.setValue(s)}_unionFunction(n,e){return n.isError()||e.isError()?new d(f.REF):!n.isReferenceObject()||!e.isReferenceObject()?new d(f.REF):(n=n,e=e,n.isCell()&&e.isCell()||n.isRow()&&e.isRow()||n.isColumn()&&e.isColumn()?n.unionBy(e):new d(f.REF))}}let gt=class extends se{constructor(t){super(),this._functionService=t}get zIndex(){return re.get(v.UNION)||ne}create(t){return new ji(t)}checkAndCreateNodeType(t){if(!(t instanceof V))return;const e=t.getToken().trim();if(!(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')&&e===O.COLON)return this.create(e)}};gt=$i([ki(0,oe)],gt);class Qi extends K{constructor(n){super(n),this._operatorString=n}get nodeType(){return v.VALUE}execute(){this.setValue(fe.create(this._operatorString))}}class Pn extends se{get zIndex(){return re.get(v.VALUE)||ne}_checkValueNode(n){if(isNaN(Number(n))){const e=n.trim(),r=e.charAt(0),s=e.charAt(e.length-1);if(Tt.has(e))return this.create(e);if(r==='"'&&s==='"')return this.create(e);if(r==="{"&&s==="}")return this.create(e);if(e===_e.TRUE||e===_e.FALSE)return this.create(e)}else return this.create(n)}create(n){return new Qi(n)}checkAndCreateNodeType(n){if(!(n instanceof V))return this._checkValueNode(n)}}var Ti=Object.defineProperty,Hi=Object.getOwnPropertyDescriptor,Yi=(t,n,e,r)=>{for(var s=r>1?void 0:r?Hi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Ti(n,e,s),s},z=(t,n)=>(e,r)=>n(e,r,t);let Te=class extends g.Disposable{constructor(n,e,r,s,i,a,o,u,l,c,h){super();p(this,"_astNodeFactoryList",[]);p(this,"_refOffsetX",0);p(this,"_refOffsetY",0);this._runtimeService=n,this._astRootNodeFactory=e,this._functionNodeFactory=r,this._lambdaNodeFactory=s,this._lambdaParameterNodeFactory=i,this._operatorNodeFactory=a,this._prefixNodeFactory=o,this._referenceNodeFactory=u,this._suffixNodeFactory=l,this._unionNodeFactory=c,this._valueNodeFactory=h,this._initializeAstNode()}dispose(){this._astNodeFactoryList.forEach(n=>{n.dispose()}),this._astNodeFactoryList=[]}parse(n,e=0,r=0){const s=new Qt(ce);return this._refOffsetX=e,this._refOffsetY=r,this._parse(n,s)}_lambdaParameterHandler(n,e){const r=e.getLambdaId(),s=new Qt(ce),i=this._runtimeService.getFunctionDefinitionPrivacyVar(r);if(!i)return!1;const a=[...i.keys()],o=n.getChildren(),u=o.length;for(let h=0;h<u;h++){const m=o[h];if(m instanceof V)this._parse(m,s);else return!1}const l=s.getChildren(),c=l.length;for(let h=0;h<c;h++){const m=l[h];i.set(a[h],m)}return s.setParent(e),e}_changeLetToLambda(n){const e=n.getChildren(),r=e.length;if(r%2!==1||r===0)return;const s=new V;s.setToken(je);const i=new V;i.setToken(xe);const a=[...e];for(let u=0;u<r;u++){const l=a[u];if(!(l instanceof V))return;u%2===0?l.changeToParent(s):l.changeToParent(i)}s.addChildrenFirst(i),i.setParent(s);const o=n.getParent();return o==null||o.replaceChild(n,s),s}_getTopParent(n){let e=n;for(;e!=null&&e.getParent();)e=e.getParent();return e}_parse(n,e){const r=n.getChildren(),s=r.length,i=[];let a=null;const o=n.getToken().trim().toUpperCase();if(o===Kn){const c=this._changeLetToLambda(n);return c!=null?this._parse(c,e):T.create(f.ERROR)}if(o===Re){if(a=e,s===0)return new Ci(ce).setParent(e),a}else{if(o===xe){let c=this._lambdaParameterHandler(n,e);return c===!1&&(c=T.create(f.ERROR)),c}if(a=this._checkAstNode(n),a==null)return T.create(f.ERROR)}const u=r[0];for(let c=0;c<s;c++){const h=r[c];if(yn(u)){if(c!==0&&c!==s-1)continue}else if(mi(h)&&c!==s-1)continue;let m=null;if(h instanceof V){if(m=this._parse(h,a),m===a)continue}else m=this._checkAstNode(h);if(m==null)return T.create(f.NAME);if(m=this._getTopParent(m),m==null)return;switch(m.nodeType){case v.ERROR:return m;case v.FUNCTION:i.push(m);break;case v.LAMBDA:i.push(m);break;case v.LAMBDA_PARAMETER:i.push(m);break;case v.OPERATOR:{const D=i.pop(),_=i.pop();if(_)_.setParent(m);else return T.create(f.ERROR);if(D)D.setParent(m);else return T.create(f.ERROR);i.push(m);break}case v.REFERENCE:m.setRefOffset(this._refOffsetX,this._refOffsetY),i.push(m);break;case v.ROOT:i.push(m);break;case v.UNION:i.push(m);break;case v.VALUE:i.push(m);break;case v.PREFIX:i.push(m);break;case v.SUFFIX:i.push(m);break}}const l=i.length;for(let c=0;c<l;c++)i[c].setParent(a);return a}_checkAstNode(n){let e=null;const r=this._astNodeFactoryList.length;for(let s=0;s<r&&(e=this._astNodeFactoryList[s].checkAndCreateNodeType(n),e==null);s++);return e}_initializeAstNode(){this._astNodeFactoryList=[this._astRootNodeFactory,this._functionNodeFactory,this._lambdaNodeFactory,this._lambdaParameterNodeFactory,this._operatorNodeFactory,this._prefixNodeFactory,this._referenceNodeFactory,this._suffixNodeFactory,this._unionNodeFactory,this._valueNodeFactory].sort(g.sortRules)}};Te=Yi([z(0,N),z(1,P.Inject(Cn)),z(2,P.Inject(ct)),z(3,P.Inject(ht)),z(4,P.Inject(Sn)),z(5,P.Inject(ft)),z(6,P.Inject(lt)),z(7,P.Inject(dt)),z(8,P.Inject(mt)),z(9,P.Inject(gt)),z(10,P.Inject(Pn))],Te);class xn extends g.Disposable{constructor(){super(...arguments);p(this,"_referenceExecutorMap",new Map)}dispose(){this._referenceExecutorMap.clear()}remove(e){this._referenceExecutorMap.delete(e)}get(e){return this._referenceExecutorMap.get(e)}has(e){return this._referenceExecutorMap.has(e)}register(e,r){this._referenceExecutorMap.set(e,r)}getReferenceExecutorMap(){return this._referenceExecutorMap}}const Lt=P.createIdentifier("univer.formula.feature-calculation-manager.service");class Vn extends g.Disposable{constructor(){super(...arguments);p(this,"_otherFormulaData",{})}dispose(){this._otherFormulaData={}}remove(e){var a,o,u;const{unitId:r,subUnitId:s,formulaId:i}=e;(u=(o=(a=this._otherFormulaData)==null?void 0:a[r])==null?void 0:o[s])==null||delete u[i]}get(e){var a,o;const{unitId:r,subUnitId:s,formulaId:i}=e;return(o=(a=this._otherFormulaData[r])==null?void 0:a[s])==null?void 0:o[i]}has(e){var a,o;const{unitId:r,subUnitId:s,formulaId:i}=e;return((o=(a=this._otherFormulaData[r])==null?void 0:a[s])==null?void 0:o[i])!=null}register(e){const{unitId:r,subUnitId:s,formulaId:i,item:a}=e;this._otherFormulaData[r]&&(this._otherFormulaData[r]={}),this._otherFormulaData[r][s]&&(this._otherFormulaData[r][s]={}),this._otherFormulaData[r][s][i]=a}getOtherFormulaData(){return this._otherFormulaData}}const nr=P.createIdentifier("univer.formula.other-formula-manager.service");class Ot extends g.Disposable{constructor(){super(...arguments);p(this,"node");p(this,"children",[]);p(this,"parents",[]);p(this,"formula","");p(this,"row",-1);p(this,"column",-1);p(this,"rowCount",-1/0);p(this,"columnCount",-1/0);p(this,"subUnitId","");p(this,"unitId","");p(this,"rangeList",[]);p(this,"formulaId");p(this,"featureId");p(this,"getDirtyData");p(this,"_state",0)}dispose(){var e;this.children.forEach(r=>{r.dispose()}),this.rangeList=[],this.parents=[],(e=this.node)==null||e.dispose()}setAdded(){this._state=1}isAdded(){return this._state===1}setSkip(){this._state=2}isSkip(){return this._state===2}inRangeData(e){const r=e.startRow,s=e.startColumn,i=e.endRow,a=e.endColumn;return!(this.row<r||this.row>i||this.column<s||this.column>a)}dependencyRange(e,r,s){var i,a;if(this.rangeList.length===0)return!1;for(let o=0,u=this.rangeList.length;o<u;o++){const l=this.rangeList[o],{unitId:c,sheetId:h,range:m}=l;if(!e.has(c))continue;const D=e.get(c);if(!D.has(h))continue;const _=D.get(h),R=(i=s==null?void 0:s[c])==null?void 0:i[h];let{startRow:E,endRow:y,startColumn:b,endColumn:L}=m;isNaN(E)&&(E=0),isNaN(b)&&(b=0),isNaN(y)&&(y=1/0),isNaN(L)&&(L=1/0);for(const S of _){const{startRow:$,startColumn:k,endRow:Q,endColumn:A}=S;if(!(E>Q||y<$||b>A||L<k)){let x=!0;if(R==null||R.forValue((U,M)=>{if(U>=E&&U<=y&&M>=b&&M<=L)return x=!1,!1}),x)return!0}}if(((a=r[c])==null?void 0:a[h])!=null)return!0}return!1}pushChildren(e){this.children.push(e),e._pushParent(this)}pushRangeList(e){this.rangeList.push(e)}dependency(e){if(this.rangeList.length===0)return!1;for(let r=0,s=this.rangeList.length;r<s;r++){const i=this.rangeList[r],a=i.unitId,o=i.sheetId,u=i.range;if(e.unitId===a&&e.subUnitId===o&&e.inRangeData(u))return!0}return!1}_pushParent(e){this.parents.push(e)}}var Wi=Object.defineProperty,Xi=Object.getOwnPropertyDescriptor,Gi=(t,n,e,r)=>{for(var s=r>1?void 0:r?Xi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Wi(n,e,s),s},me=(t,n)=>(e,r)=>n(e,r,t);const Ki=1e5,Bt=new Rt(Ki);let $e=class extends g.Disposable{constructor(n,e,r,s,i,a,o){super();p(this,"_updateRangeFlattenCache",new Map);p(this,"_dirtyUnitSheetNameMap",{});this._currentConfigService=n,this._runtimeService=e,this._otherFormulaManagerService=r,this._featureCalculationManagerService=s,this._interpreter=i,this._astTreeBuilder=a,this._lexer=o}dispose(){this._updateRangeFlattenCache.clear(),Bt.clear(),this._dirtyUnitSheetNameMap={}}async generate(){this._updateRangeFlatten();const n=this._currentConfigService.getFormulaData(),e=this._otherFormulaManagerService.getOtherFormulaData(),r=this._currentConfigService.getUnitData(),s=await this._generateTreeList(n,e,r),i=this._getUpdateTreeListAndMakeDependency(s);this._checkIsCycleDependency(i)&&this._runtimeService.enableCycleDependency();const o=this._calculateRunList(i);return Promise.resolve(o)}_isCyclicUtil(n,e,r){if(!e.has(n)){e.add(n),r.add(n);for(let s=0;s<n.children.length;s++)if(!e.has(n.children[s])&&this._isCyclicUtil(n.children[s],e,r)||r.has(n.children[s]))return!0}return r.delete(n),!1}_checkIsCycleDependency(n){const e=new Set,r=new Set;for(let s=0,i=n.length;s<i;s++){const a=n[s];if(this._isCyclicUtil(a,e,r)===!0)return!0}return!1}async _generateTreeList(n,e,r){const s=Object.keys(n),i=Object.keys(e),a=[];for(const o of s){const u=n[o];if(u==null)continue;const l=Object.keys(u);for(const c of l)new g.ObjectMatrix(u[c]).forValue((m,D,_)=>{if(_==null)return!0;const{f:R,x:E,y}=_,b=this._generateAstNode(R,E,y),L=new Ot,S=r[o][c];L.node=b,L.formula=R,L.unitId=o,L.subUnitId=c,L.row=m,L.column=D,L.rowCount=S.rowCount,L.columnCount=S.columnCount,a.push(L)})}for(const o of i){const u=e[o];if(u==null)continue;const l=Object.keys(u);for(const c of l){const h=u[c];if(h==null)continue;const m=Object.keys(h);for(const D of m){const _=h[D],{f:R}=_,E=this._generateAstNode(R),y=new Ot;y.node=E,y.formula=R,y.unitId=o,y.subUnitId=c,y.formulaId=D,a.push(y)}}}this._featureCalculationManagerService.getReferenceExecutorMap().forEach((o,u)=>{const{unitId:l,subUnitId:c,dependencyRanges:h,getDirtyData:m}=o,D=new Ot;D.unitId=l,D.subUnitId=c,D.getDirtyData=m,D.featureId=u,D.rangeList=h,a.push(D)});for(let o=0,u=a.length;o<u;o++){const l=a[o];if(this._runtimeService.setCurrent(l.row,l.column,l.rowCount,l.columnCount,l.subUnitId,l.unitId),l.node==null)continue;const c=await this._getRangeListByNode(l.node);for(let h=0,m=c.length;h<m;h++)l.pushRangeList(c[h])}return a}_updateRangeFlatten(){const n=this._currentConfigService.isForceCalculate(),e=this._currentConfigService.getDirtyRanges();if(!n){this._updateRangeFlattenCache.clear();for(let r=0;r<e.length;r++){const s=e[r],i=s.range,a=s.sheetId,o=s.unitId;this._addFlattenCache(o,a,i)}this._dirtyUnitSheetNameMap=this._currentConfigService.getDirtyNameMap()}}_generateAstNode(n,e=0,r=0){let s=Bt.get(`${n}##${e}${r}`);if(s)return s;const i=this._lexer.treeBuilder(n);if(i in f)return T.create(i);if(s=this._astTreeBuilder.parse(i,e,r),s==null)throw new Error("astNode is null");return Bt.set(`${n}##${e}${r}`,s),s}_addFlattenCache(n,e,r){let s=this._updateRangeFlattenCache.get(n);s==null&&(s=new Map,this._updateRangeFlattenCache.set(n,s));let i=s.get(e);i==null&&(i=[],s.set(e,i)),i.push(r)}_isPreCalculateNode(n){return n.nodeType===v.UNION||n.nodeType===v.PREFIX&&n.getToken()===j.AT||n.nodeType===v.SUFFIX&&n.getToken()===ie.POUND}_nodeTraversalRef(n,e){const r=n.getChildren(),s=r.length;for(let i=0;i<s;i++){const a=r[i];if(this._isPreCalculateNode(a)){e.push(a);continue}else a.nodeType===v.REFERENCE&&e.push(a);this._nodeTraversalRef(a,e)}}_nodeTraversalReferenceFunction(n,e){const r=n.getChildren(),s=r.length;for(let i=0;i<s;i++){const a=r[i];if(a.nodeType===v.FUNCTION&&a.isAddress()){e.push(a);continue}this._nodeTraversalReferenceFunction(a,e)}}async _executeNode(n){let e;return this._interpreter.checkAsyncNode(n)?e=await this._interpreter.executeAsync(n):e=this._interpreter.execute(n),e}async _getRangeListByNode(n){const e=[],r=[];this._nodeTraversalRef(n,e),this._nodeTraversalReferenceFunction(n,r);const s=[];for(let i=0,a=e.length;i<a;i++){const o=e[i],l=(await this._executeNode(o)).toUnitRange();s.push(l)}for(let i=0,a=r.length;i<a;i++){const o=r[i],l=(await this._executeNode(o)).toUnitRange();s.push(l)}return s}_getUpdateTreeListAndMakeDependency(n){const e=[],r=new Set,s=this._currentConfigService.isForceCalculate();for(let i=0,a=n.length;i<a;i++){const o=n[i];for(let u=0,l=n.length;u<l;u++){const c=n[u];o!==c&&o.dependency(c)&&o.pushChildren(c)}(s||o.dependencyRange(this._updateRangeFlattenCache,this._dirtyUnitSheetNameMap,this._currentConfigService.getExcludedRange())||this._includeTree(o))&&!r.has(o)&&(e.push(o),r.add(o))}return e}_includeTree(n){var l,c,h,m,D;const e=n.unitId,r=n.subUnitId,s=n.featureId;if(s!=null){const _=this._currentConfigService.getDirtyUnitFeatureMap();if(((c=(l=_==null?void 0:_[e])==null?void 0:l[r])==null?void 0:c[s])!=null)return!0}const i=(m=(h=this._currentConfigService.getExcludedRange())==null?void 0:h[e])==null?void 0:m[r];let a=!1;if(i==null||i.forValue((_,R)=>{if(n.row===_&&n.column===R)return a=!0,!1}),a)return!1;if(((D=this._dirtyUnitSheetNameMap[e])==null?void 0:D[r])!=null)return!0;if(!this._updateRangeFlattenCache.has(e))return!1;const o=this._updateRangeFlattenCache.get(e);if(!o.has(r))return!1;const u=o.get(r);for(const _ of u)if(n.inRangeData(_))return!0;return!1}_calculateRunList(n){let e=n;const r=[];for(;e.length>0;){const s=e.pop();if(s===void 0||s.isSkip())continue;if(s.isAdded()){r.push(s);continue}const i=[];for(let a=0,o=s.parents.length;a<o;a++){const u=s.parents[a];i.push(u)}i.length===0?(r.push(s),s.setSkip()):(s.setAdded(),e.push(s),e=e.concat(i))}return r.reverse()}};$e=Gi([g.OnLifecycle(g.LifecycleStages.Rendered,$e),me(0,Le),me(1,N),me(2,nr),me(3,Lt),me(4,P.Inject(Ve)),me(5,P.Inject(Te)),me(6,P.Inject(we))],$e);var Ii=Object.defineProperty,zi=Object.getOwnPropertyDescriptor,qi=(t,n,e,r)=>{for(var s=r>1?void 0:r?zi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Ii(n,e,s),s},ge=(t,n)=>(e,r)=>n(e,r,t);const Zi=1;exports.CalculateFormulaService=class extends g.Disposable{constructor(e,r,s,i,a,o,u){super();p(this,"_executionStartListener$",new St.Subject);p(this,"executionStartListener$",this._executionStartListener$.asObservable());p(this,"_executionCompleteListener$",new St.Subject);p(this,"executionCompleteListener$",this._executionCompleteListener$.asObservable());p(this,"_executionInProgressListener$",new St.Subject);p(this,"executionInProgressListener$",this._executionInProgressListener$.asObservable());this._configService=e,this._lexer=r,this._currentConfigService=s,this._runtimeService=i,this._formulaDependencyGenerator=a,this._interpreter=o,this._astTreeBuilder=u}dispose(){}stopFormulaExecution(){this._runtimeService.stopExecution()}setRuntimeFeatureCellData(e,r){this._runtimeService.setRuntimeFeatureCellData(e,r)}setRuntimeFeatureRange(e,r){this._runtimeService.setRuntimeFeatureRange(e,r)}async execute(e){this._executionStartListener$.next(!0),this._currentConfigService.load(e),this._runtimeService.reset();const r=this._configService.getConfig("CYCLE_REFERENCE_COUNT")||Zi;for(let s=0;s<r&&(await this._execute(),!!this._runtimeService.isCycleDependency());s++);this._runtimeService.setFormulaExecuteStage(ee.CALCULATION_COMPLETED),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState()),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData()),$t.clear(),ue.clear()}async _execute(){const e=await this._apply();if(e==null)return;const{arrayFormulaRange:r,runtimeFeatureRange:s}=e,{dirtyRanges:i,excludedCell:a}=this._getArrayFormulaDirtyRangeAndExcludedRange(r,s);return i==null||i.length===0||(this._currentConfigService.loadDirtyRangesAndExcludedCell(i,a),await this._apply(!0)),!0}_getArrayFormulaDirtyRangeAndExcludedRange(e,r){const s=[],i={};return Object.keys(e).forEach(a=>{const o=e[a];if(o==null)return!0;Object.keys(o).forEach(u=>{const l=new g.ObjectMatrix(o[u]);if(l==null)return!0;const c=new g.ObjectMatrix;l.forValue((h,m,D)=>{c.setValue(h,m,!0),s.push({unitId:a,sheetId:u,range:D})}),i[a]==null&&(i[a]={}),i[a][u]=c})}),Object.keys(r).forEach(a=>{const o=r[a];Object.keys(o).forEach(u=>{const l=o[u];if(l==null)return!0;Object.keys(l).forEach(c=>{const h=l[c];if(h==null)return!0;for(const m of h)s.push({unitId:u,sheetId:c,range:m})})})}),{dirtyRanges:s,excludedCell:i}}async _apply(e=!1){e?this._runtimeService.setFormulaExecuteStage(ee.START_DEPENDENCY_ARRAY_FORMULA):this._runtimeService.setFormulaExecuteStage(ee.START_DEPENDENCY),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());const r=await this._formulaDependencyGenerator.generate(),s=this._interpreter;e?(this._runtimeService.setFormulaExecuteStage(ee.START_CALCULATION_ARRAY_FORMULA),this._runtimeService.setTotalArrayFormulasToCalculate(r.length)):(this._runtimeService.setFormulaExecuteStage(ee.START_CALCULATION),this._runtimeService.setTotalFormulasToCalculate(r.length)),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());for(let i=0,a=r.length;i<a;i++){if(await new Promise(h=>{g.requestImmediateMacroTask(h)}),this._runtimeService.isStopExecution()){this._runtimeService.setFormulaExecuteStage(ee.IDLE),this._runtimeService.markedAsStopFunctionsExecuted(),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData());return}const o=r[i],u=o.node,l=o.getDirtyData;let c;if(u==null&&l==null)throw new Error("AstNode or executor is null");if(this._runtimeService.setCurrent(o.row,o.column,o.rowCount,o.columnCount,o.subUnitId,o.unitId),l!=null&&o.featureId!=null){const{runtimeCellData:h,dirtyRanges:m}=l(o);this._runtimeService.setRuntimeFeatureCellData(o.featureId,h),this._runtimeService.setRuntimeFeatureRange(o.featureId,m)}else u!=null&&(s.checkAsyncNode(u)?c=await s.executeAsync(u):c=s.execute(u),o.formulaId!=null?this._runtimeService.setRuntimeOtherData(o.formulaId,c):this._runtimeService.setRuntimeData(c));e?(this._runtimeService.setFormulaExecuteStage(ee.CURRENTLY_CALCULATING_ARRAY_FORMULA),this._runtimeService.setCompletedArrayFormulasCount(i+1)):(this._runtimeService.setFormulaExecuteStage(ee.CURRENTLY_CALCULATING),this._runtimeService.setCompletedFormulasCount(i+1)),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState())}return r.length>0?this._runtimeService.markedAsSuccessfullyExecuted():e||this._runtimeService.markedAsNoFunctionsExecuted(),this._runtimeService.getAllRuntimeData()}calculate(e,r=!0){const s=this._lexer.treeBuilder(e,r);if(Object.values(f).includes(s))return T.create(s);const i=this._astTreeBuilder.parse(s);i==null||i.serialize()}};exports.CalculateFormulaService=qi([g.OnLifecycle(g.LifecycleStages.Rendered,exports.CalculateFormulaService),ge(0,g.IConfigService),ge(1,P.Inject(we)),ge(2,Le),ge(3,N),ge(4,P.Inject($e)),ge(5,P.Inject(Ve)),ge(6,P.Inject(Te))],exports.CalculateFormulaService);var Ji=Object.defineProperty,Ni=Object.getOwnPropertyDescriptor,ea=(t,n,e,r)=>{for(var s=r>1?void 0:r?Ni(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Ji(n,e,s),s},Ke=(t,n)=>(e,r)=>n(e,r,t);let Ze=class extends g.Disposable{constructor(t,n,e,r){super(),this._commandService=t,this._calculateFormulaService=n,this._currentUniverService=e,this._formulaDataModel=r,this._initialize()}_initialize(){this._commandExecutedListener(),this._initialExecuteFormulaListener(),this._initialExecuteFormulaProcessListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{if(t.id===Kt.id)this._calculateFormulaService.stopFormulaExecution();else if(t.id===zt.id){const e=t.params.formulaData;this._formulaDataModel.setFormulaData(e)}else if(t.id===Gt.id){const e=t.params;if(e.forceCalculation===!0)this._calculate(!0);else{const{dirtyRanges:r,dirtyNameMap:s,dirtyUnitFeatureMap:i}=e;this._calculate(!1,r,s,i)}}else if(t.id===st.id){const e=t.params;if(e==null)return;const{arrayFormulaRange:r,arrayFormulaCellData:s}=e;this._formulaDataModel.setArrayFormulaRange(r),this._formulaDataModel.setArrayFormulaCellData(s)}}))}async _calculate(t=!1,n=[],e={},r={}){if(n.length===0&&Object.keys(e).length===0&&Object.keys(r).length===0&&t===!1)return;const s=this._formulaDataModel.getFormulaData(),i=this._formulaDataModel.getArrayFormulaCellData();this._calculateFormulaService.execute({formulaData:s,arrayFormulaCellData:i,forceCalculate:t,dirtyRanges:n,dirtyNameMap:e,dirtyUnitFeatureMap:r})}_initialExecuteFormulaListener(){this._calculateFormulaService.executionCompleteListener$.subscribe(t=>{const n=t.functionsExecutedState;switch(n){case Pe.NOT_EXECUTED:break;case Pe.STOP_EXECUTION:break;case Pe.SUCCESS:this._applyFormula(t);break;case Pe.INITIAL:break}this._commandService.executeCommand(it.id,{functionsExecutedState:n},{onlyLocal:!0})})}_initialExecuteFormulaProcessListener(){this._calculateFormulaService.executionInProgressListener$.subscribe(t=>{this._commandService.executeCommand(it.id,{stageInfo:t},{onlyLocal:!0})})}async _applyFormula(t){const{unitData:n,unitOtherData:e,arrayFormulaRange:r,arrayFormulaCellData:s,clearArrayFormulaCellData:i}=t;if(!n){console.error("No sheetData from Formula Engine!");return}r&&(this._formulaDataModel.clearPreviousArrayFormulaCellData(i),this._formulaDataModel.mergeArrayFormulaCellData(s),this._formulaDataModel.mergeArrayFormulaRange(r),this._commandService.executeCommand(st.id,{arrayFormulaRange:this._formulaDataModel.getArrayFormulaRange(),arrayFormulaCellData:this._formulaDataModel.getArrayFormulaCellData()},{onlyLocal:!0})),this._commandService.executeCommand(It.id,{unitData:n,unitOtherData:e},{onlyLocal:!0})}};Ze=ea([g.OnLifecycle(g.LifecycleStages.Ready,Ze),Ke(0,g.ICommandService),Ke(1,P.Inject(exports.CalculateFormulaService)),Ke(2,g.IUniverInstanceService),Ke(3,P.Inject(exports.FormulaDataModel))],Ze);var ta=Object.defineProperty,ra=Object.getOwnPropertyDescriptor,na=(t,n,e,r)=>{for(var s=r>1?void 0:r?ra(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&ta(n,e,s),s},Ut=(t,n)=>(e,r)=>n(e,r,t);let ke=class extends g.Disposable{constructor(t=[],n,e,r){super(),this._function=t,this._commandService=n,this._injector=e,this._functionService=r,this._initialize()}_initialize(){this._registerCommands(),this._registerFunctions()}_registerCommands(){[zt,st,Gt,Kt,it,It,Et,_t,Wt,Xt,qt,Zt,Hr,Yr,Jt,Ht,Nt].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}_registerFunctions(){const t=[...Ir,...zr,...Zr,...Nr,...tn,...nn,...an,...un,...cn,...dn,...mn,...gn,...Rn,...pn,...Dn,...En].concat(this._function).map(n=>{const e=n[0],r=n[1];return new e(r)});this._functionService.registerExecutors(...t)}};ke=na([g.OnLifecycle(g.LifecycleStages.Ready,ke),Ut(1,g.ICommandService),Ut(2,P.Inject(P.Injector)),Ut(3,oe)],ke);var sa=Object.defineProperty,ia=Object.getOwnPropertyDescriptor,aa=(t,n,e,r)=>{for(var s=r>1?void 0:r?ia(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&sa(n,e,s),s},Ft=(t,n)=>(e,r)=>n(e,r,t);let Je=class extends g.Disposable{constructor(t,n,e){super(),this._commandService=t,this._formulaDataModel=n,this._functionService=e,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{if(t.id===Ht.id){const e=t.params;if(e==null)return;const{functions:r}=e,s=r.map(i=>{const a=i[0],o=i[1];return ua(a,o)});this._functionService.registerExecutors(...s)}else if(t.id===Nt.id){const e=t.params;if(e==null)return;const{functions:r}=e;this._functionService.unregisterExecutors(...r)}}))}};Je=aa([g.OnLifecycle(g.LifecycleStages.Ready,Je),Ft(0,g.ICommandService),Ft(1,P.Inject(exports.FormulaDataModel)),Ft(2,oe)],Je);class oa extends F{isCustom(){return!0}}function ua(t,n){const e=new oa(n),r=new Function(`return ${t}`)();return e.calculateCustom=r,e}var la=Object.defineProperty,ca=Object.getOwnPropertyDescriptor,ha=(t,n,e,r)=>{for(var s=r>1?void 0:r?ca(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&la(n,e,s),s},wr=(t,n)=>(e,r)=>n(e,r,t);let Ne=class extends g.Disposable{constructor(t,n){super(),this._commandService=t,this._definedNamesService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===Et.id){const n=t.params;if(n==null)return;const{unitId:e,name:r,formulaOrRefString:s}=n;this._definedNamesService.registerDefinedName(e,r,s)}else if(t.id===_t.id){const n=t.params;if(n==null)return;const{unitId:e,name:r}=n;this._definedNamesService.removeDefinedName(e,r)}}))}};Ne=ha([g.OnLifecycle(g.LifecycleStages.Ready,Ne),wr(0,g.ICommandService),wr(1,bt)],Ne);var fa=Object.defineProperty,da=Object.getOwnPropertyDescriptor,ma=(t,n,e,r)=>{for(var s=r>1?void 0:r?da(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&fa(n,e,s),s},yr=(t,n)=>(e,r)=>n(e,r,t);let et=class extends g.Disposable{constructor(t,n){super(),this._commandService=t,this._featureCalculationManagerService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===Wt.id){const n=t.params;if(n==null)return;const{featureId:e,calculationParam:r}=n;this._featureCalculationManagerService.register(e,r)}else if(t.id===Xt.id){const n=t.params;if(n==null)return;const{featureId:e}=n;this._featureCalculationManagerService.remove(e)}}))}};et=ma([g.OnLifecycle(g.LifecycleStages.Ready,et),yr(0,g.ICommandService),yr(1,Lt)],et);var ga=Object.defineProperty,Ra=Object.getOwnPropertyDescriptor,pa=(t,n,e,r)=>{for(var s=r>1?void 0:r?Ra(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&ga(n,e,s),s},br=(t,n)=>(e,r)=>n(e,r,t);let tt=class extends g.Disposable{constructor(t,n){super(),this._commandService=t,this._otherFormulaManagerService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===qt.id){const n=t.params;if(n==null)return;this._otherFormulaManagerService.register(n)}else if(t.id===Zt.id){const n=t.params;if(n==null)return;this._otherFormulaManagerService.remove(n)}}))}};tt=pa([g.OnLifecycle(g.LifecycleStages.Ready,tt),br(0,g.ICommandService),br(1,nr)],tt);var Da=Object.defineProperty,Ea=Object.getOwnPropertyDescriptor,_a=(t,n,e,r)=>{for(var s=r>1?void 0:r?Ea(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Da(n,e,s),s},Lr=(t,n)=>(e,r)=>n(e,r,t);let rt=class extends g.Disposable{constructor(t,n){super(),this._commandService=t,this._superTableService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===Et.id){const n=t.params;if(n==null)return;const{unitId:e,tableName:r,reference:s}=n;this._superTableService.registerTable(e,r,s)}else if(t.id===_t.id){const n=t.params;if(n==null)return;const{unitId:e,tableName:r}=n;this._superTableService.remove(e,r)}else if(t.id===Jt.id){const n=t.params;if(n==null)return;const{tableOption:e,tableOptionType:r}=n;this._superTableService.registerTableOptionMap(e,r)}}))}};rt=_a([g.OnLifecycle(g.LifecycleStages.Ready,rt),Lr(0,g.ICommandService),Lr(1,rr)],rt);var Ca=Object.defineProperty,wa=Object.getOwnPropertyDescriptor,ya=(t,n,e,r)=>{for(var s=r>1?void 0:r?wa(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Ca(n,e,s),s},ba=(t,n)=>(e,r)=>n(e,r,t);const La="base-formula-engine";exports.UniverFormulaEnginePlugin=class extends g.Plugin{constructor(n,e){super(La),this._config=n,this._injector=e}onStarting(){this._initialize()}_initialize(){var e;const n=[[oe,{useClass:wn}],[Lt,{useClass:xn}],[bt,{useClass:Xs}],[exports.FormulaDataModel],[Dt],[ke,{useFactory:()=>{var r;return this._injector.createInstance(ke,(r=this._config)==null?void 0:r.function)}}],[et]];(e=this._config)!=null&&e.notExecuteFormula||n.push([exports.CalculateFormulaService],[nr,{useClass:Vn}],[rr,{useClass:Pi}],[Le,{useClass:kt}],[N,{useClass:jt}],[Ze],[Ne],[tt],[rt],[Je],[$e],[Ve],[Te],[we],[Cn],[ct],[ht],[Sn],[ft],[lt],[dt],[mt],[gt],[Pn]),n.forEach(r=>this._injector.add(r))}onReady(){this._injector.get(exports.FormulaDataModel).initFormulaData()}};exports.UniverFormulaEnginePlugin=ya([ba(1,P.Inject(P.Injector))],exports.UniverFormulaEnginePlugin);exports.ArrayValueObject=J;exports.BaseFunction=F;exports.BaseReferenceObject=Be;exports.BaseValueObject=de;exports.BooleanValueObject=W;exports.ErrorType=f;exports.ErrorValueObject=d;exports.FUNCTION_NAMES_ARRAY=Rs;exports.FUNCTION_NAMES_COMPATIBILITY=qr;exports.FUNCTION_NAMES_CUBE=Jr;exports.FUNCTION_NAMES_DATABASE=en;exports.FUNCTION_NAMES_DATE=rn;exports.FUNCTION_NAMES_ENGINEERING=sn;exports.FUNCTION_NAMES_FINANCIAL=on;exports.FUNCTION_NAMES_INFORMATION=ln;exports.FUNCTION_NAMES_LOGICAL=ot;exports.FUNCTION_NAMES_LOOKUP=Se;exports.FUNCTION_NAMES_MATH=q;exports.FUNCTION_NAMES_STATISTICAL=le;exports.FUNCTION_NAMES_TEXT=yt;exports.FUNCTION_NAMES_UNIVER=Ws;exports.FUNCTION_NAMES_WEB=_n;exports.FeatureCalculationManagerService=xn;exports.FormulaExecuteStageType=ee;exports.FormulaExecutedStateType=Pe;exports.FunctionService=wn;exports.FunctionType=Pr;exports.IFeatureCalculationManagerService=Lt;exports.IFunctionService=oe;exports.LexerNode=V;exports.LexerTreeBuilder=Dt;exports.NumberValueObject=C;exports.OtherFormulaManagerService=Vn;exports.RangeReferenceObject=at;exports.RegisterFunctionMutation=Ht;exports.RemoveDefinedNameMutation=_t;exports.RemoveFeatureCalculationMutation=Xt;exports.RemoveOtherFormulaMutation=Zt;exports.RemoveSuperTableMutation=Yr;exports.SetArrayFormulaDataMutation=st;exports.SetArrayFormulaDataUndoMutationFactory=Zn;exports.SetDefinedNameMutation=Et;exports.SetFeatureCalculationMutation=Wt;exports.SetFormulaCalculationNotificationMutation=it;exports.SetFormulaCalculationResultMutation=It;exports.SetFormulaCalculationStartMutation=Gt;exports.SetFormulaCalculationStopMutation=Kt;exports.SetFormulaDataMutation=zt;exports.SetOtherFormulaMutation=qt;exports.SetSuperTableMutation=Hr;exports.SetSuperTableOptionMutation=Jt;exports.StringValueObject=Y;exports.UNIT_NAME_REGEX=ae;exports.UnregisterFunctionMutation=Nt;exports.ValueObjectFactory=fe;exports.compareToken=w;exports.convertUnitDataToRuntime=vr;exports.deserializeRangeForR1C1=Kr;exports.deserializeRangeWithSheet=ve;exports.functionArray=Ir;exports.functionCompatibility=zr;exports.functionCube=Zr;exports.functionDatabase=Nr;exports.functionDate=tn;exports.functionEngineering=nn;exports.functionFinancial=an;exports.functionInformation=un;exports.functionLogical=cn;exports.functionLookup=dn;exports.functionMath=mn;exports.functionMeta=gn;exports.functionStatistical=Rn;exports.functionText=pn;exports.functionUniver=Dn;exports.functionWeb=En;exports.generateStringWithSequence=jr;exports.getAbsoluteRefTypeWitString=kn;exports.getAbsoluteRefTypeWithSingleString=Me;exports.includeFormulaLexerToken=Vr;exports.initSheetFormulaData=Tr;exports.isFormulaLexerToken=ze;exports.isInDirtyRange=Sr;exports.matchToken=O;exports.normalizeSheetName=Fn;exports.sequenceNodeType=I;exports.serializeRange=Ee;exports.serializeRangeToRefString=Br;exports.serializeRangeWithSheet=Ar;exports.serializeRangeWithSpreadsheet=Or;
|
|
1
|
+
"use strict";var Un=Object.defineProperty;var Fn=(t,n,e)=>n in t?Un(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e;var _=(t,n,e)=>(Fn(t,typeof n!="symbol"?n+"":n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("@univerjs/core"),x=require("@wendellhu/redi"),xt=require("rxjs");function xr(t,n,e,r,s){for(let i=0,a=t.length;i<a;i++){const o=t[i];if(n!==o.unitId||e!==o.sheetId)continue;const{startRow:u,startColumn:l,endRow:c,endColumn:h}=o.range;if(r>=u&&r<=c&&s>=l&&s<=h)return!0}return!1}var f=(t=>(t.DIV_BY_ZERO="#DIV/0!",t.NAME="#NAME?",t.VALUE="#VALUE!",t.NUM="#NUM!",t.NA="#N/A",t.CYCLE="#CYCLE!",t.REF="#REF!",t.SPILL="#SPILL!",t.CALC="#CALC!",t.ERROR="#ERROR!",t.CONNECT="#GETTING_DATA",t.NULL="#NULL!",t))(f||{});const Yt=new Set(Object.values(f));var Ar=(t=>(t[t.Financial=0]="Financial",t[t.Date=1]="Date",t[t.Math=2]="Math",t[t.Statistical=3]="Statistical",t[t.Lookup=4]="Lookup",t[t.Database=5]="Database",t[t.Text=6]="Text",t[t.Logical=7]="Logical",t[t.Information=8]="Information",t[t.Engineering=9]="Engineering",t[t.Cube=10]="Cube",t[t.Compatibility=11]="Compatibility",t[t.Web=12]="Web",t[t.Array=13]="Array",t[t.Univer=14]="Univer",t[t.User=15]="User",t))(Ar||{}),X=(t=>(t.PLUS="+",t.MINUS="-",t.MULTIPLY="*",t.DIVIDED="/",t.CONCATENATE="&",t.POWER="^",t.EQUALS="=",t.NOT_EQUAL="<>",t.GREATER_THAN=">",t.GREATER_THAN_OR_EQUAL=">=",t.LESS_THAN="<",t.LESS_THAN_OR_EQUAL="<=",t))(X||{}),y=(t=>(t.EQUALS="=",t.NOT_EQUAL="<>",t.GREATER_THAN=">",t.GREATER_THAN_OR_EQUAL=">=",t.LESS_THAN="<",t.LESS_THAN_OR_EQUAL="<=",t))(y||{});const Ne=new Map([["<>",3],["<",3],[">=",3],["=",3],[">",3],["<=",3],["&",2],["+",2],["-",2],["/",1],["*",1],["^",0]]),je=new Set(Ne.keys()),Mn=new Set(["=","<>",">",">=","<","<="]);var B=(t=>(t.OPEN_BRACKET="(",t.CLOSE_BRACKET=")",t.COMMA=",",t.SINGLE_QUOTATION="'",t.DOUBLE_QUOTATION='"',t.OPEN_BRACES="{",t.CLOSE_BRACES="}",t.COLON=":",t.OPEN_SQUARE_BRACKET="[",t.CLOSE_SQUARE_BRACKET="]",t))(B||{}),le=(t=>(t.PERCENTAGE="%",t.POUND="#",t))(le||{});const $n=new Set(["%","#"]);var T=(t=>(t.AT="@",t.MINUS="-",t))(T||{});const Vr=[...Object.values(y),...Object.values(X),...Object.values(B),...Object.values(le),...Object.values(T)];function et(t){return Vr.includes(t)}function vr(t){for(const n of Vr)if(t.indexOf(n)>-1)return!0;return!1}function kn(t){return t[0]==="'"&&t[t.length-1]==="'"?t.substring(1,t.length-1):t}function Br(t){const n={};return Object.keys(t).forEach(e=>{const r=t[e];if(r==null)return!0;n[e]==null&&(n[e]={}),Object.keys(r).forEach(s=>{const i=r[s];n[e][s]=new g.ObjectMatrix(i)})}),n}const Wt={id:"formula.mutation.register-function",type:g.CommandType.MUTATION,handler:()=>!0};class Et{constructor(n){_(this,"_cache");this._cache=new g.LRUMap(n)}set(n,e){const r=this._hash(n);this._cache.set(r,e)}get(n){const e=this._hash(n);return this._cache.get(e)}clear(){this._cache.clear()}_hash(n){return g.hashAlgorithm(n)}}const ce='\\[([^\\[\\]\\/?:"<>|*\\\\]+)\\]',Qn=/[^0-9]/g,jn=/[^A-Za-z]/g;function Te(t){const n=t[0]==="$",r=t.substring(1).indexOf("$")>-1;return n&&r?g.AbsoluteRefType.ALL:n?g.AbsoluteRefType.COLUMN:r?g.AbsoluteRefType.ROW:g.AbsoluteRefType.NONE}function Tn(t){const n=t.split("!");n.length>1&&(t=n[n.length-1]);const e=t.split(":");return e.length>1?{startAbsoluteRefType:Te(e[0]),endAbsoluteRefType:Te(e[1])}:{startAbsoluteRefType:Te(e[0])}}function ar(t=g.AbsoluteRefType.NONE){let n="",e="";return t===g.AbsoluteRefType.ROW?n="$":t===g.AbsoluteRefType.COLUMN?e="$":t===g.AbsoluteRefType.ALL&&(n="$",e="$"),{rowAbsoluteString:n,columnAbsoluteString:e}}function Le(t){const{startColumn:n,startRow:e,endColumn:r,endRow:s,startAbsoluteRefType:i,endAbsoluteRefType:a,rangeType:o=g.RANGE_TYPE.NORMAL}=t,u=ar(i),l=ar(a);if(o===g.RANGE_TYPE.ROW||o===g.RANGE_TYPE.ALL){const m=`${u.rowAbsoluteString}${e+1}`,p=`${l.rowAbsoluteString}${s+1}`;return`${m}:${p}`}if(o===g.RANGE_TYPE.COLUMN){const m=`${u.columnAbsoluteString}${g.Tools.chatAtABC(n)}`,p=`${l.columnAbsoluteString}${g.Tools.chatAtABC(r)}`;return`${m}:${p}`}const c=`${u.columnAbsoluteString}${g.Tools.chatAtABC(n)}${u.rowAbsoluteString}${e+1}`,h=`${l.columnAbsoluteString}${g.Tools.chatAtABC(r)}${l.rowAbsoluteString}${s+1}`;return c===h?c:`${c}:${h}`}function Or(t,n){return ot(t)?`'${t}'!${Le(n)}`:`${t}!${Le(n)}`}function Ur(t,n,e){return ot(t)||ot(n)?`'[${t}]${n}'!${Le(e)}`:`[${t}]${n}!${Le(e)}`}function Fr(t){const{unitId:n,sheetName:e,range:r}=t;return n!=null&&n.length>0&&e!=null&&e.length>0?Ur(n,e,r):e!=null&&e.length>0?Or(e,r):Le(r)}function At(t){const n=Number.parseInt(t.replace(Qn,""))-1,e=g.Tools.ABCatNum(t.replace(jn,"")),r=Te(t);return{row:n,column:e,absoluteRefType:r}}function Mr(t){const n=new RegExp(ce).exec(t);let e="";n!=null&&(e=n[0].trim(),e=e.slice(1,e.length-1),t=t.replace(new RegExp(ce),""));const r=t.indexOf("!");let s="",i="";return r>-1?(s=t.substring(0,r),s[0]==="'"&&s[s.length-1]==="'"&&(s=s.substring(1,s.length-1)),i=t.substring(r)):i=t,{refBody:i,sheetName:s,unitId:e}}function Fe(t){const{refBody:n,sheetName:e,unitId:r}=Mr(t),s=n.indexOf(":");if(s===-1){const E=At(n),R=E.row,C=E.column,w=E.absoluteRefType;return{unitId:r,sheetName:e,range:{startRow:R,startColumn:C,endRow:R,endColumn:C,startAbsoluteRefType:w,endAbsoluteRefType:w}}}const i=n.substring(0,s),a=n.substring(s+1),o=At(i),u=At(a),l=o.row,c=o.column,h=u.row,m=u.column;let p=g.RANGE_TYPE.NORMAL;return isNaN(l)&&isNaN(h)?p=g.RANGE_TYPE.COLUMN:isNaN(c)&&isNaN(m)&&(p=g.RANGE_TYPE.ROW),{unitId:r,sheetName:e,range:{startRow:l,startColumn:c,endRow:h,endColumn:m,startAbsoluteRefType:o.absoluteRefType,endAbsoluteRefType:u.absoluteRefType,rangeType:p}}}function ot(t){return t.length===0?!1:!!(vr(t)||Hn(t)||Yn(t)||Wn(t)||/[\s!$%^&*()+\-=\[\]{};':"\\|,.<>\/?]/.test(t))}function Hn(t){const n=t.match(/[1-9][0-9]{0,6}/);return/^[A-Z]+[1-9][0-9]{0,6}$/.test(t)&&n!==null&&Number.parseInt(n[0],10)<=1048576}function Yn(t){return/^(R(-?[0-9]+)?C(-?[0-9]+)?|C(-?[0-9]+)?|R(-?[0-9]+)?)$/.test(t)}function Wn(t){return!new RegExp("^\\p{Letter}","u").test(t.charAt(0))}const Me="((?![\\[\\]\\/?*\\\\]).)*!",ge="$",It="\\s*?:\\s*?",kt=`\\${ge}?[A-Za-z]+\\${ge}?[0-9]+`,In=`^(${T.AT})?(${ce})?(${Me})?${kt}${It}${kt}$`,_t=`^(${ce})?(${Me})?\\s*?${kt}(${le.POUND})?$`,$r=`^(${ce})?(${Me})?\\${ge}?[0-9]+${It}\\${ge}?[0-9]+$`,kr=`^(${ce})?(${Me})?\\${ge}?[A-Za-z]+${It}\\${ge}?[A-Za-z]+$`,Xn=`^(${ce})?(${Me})?\\s*?\\${ge}?[0-9]+$`,Gn=`^(${ce})?(${Me})?\\s*?\\${ge}?[A-Za-z]+$`,Qr="[.*?]",Kn="{.*?}";function zn(t){return new RegExp(_t).test(t)||new RegExp(In).test(t)||new RegExp($r).test(t)||new RegExp(kr).test(t)}const Ce="P_1",me="R_1",Oe="L_1",Ge="LR_1",jr="LO_1",qn="LET",We="LAMBDA";var z=(t=>(t[t.NORMAL=0]="NORMAL",t[t.NUMBER=1]="NUMBER",t[t.STRING=2]="STRING",t[t.FUNCTION=3]="FUNCTION",t[t.REFERENCE=4]="REFERENCE",t[t.ARRAY=5]="ARRAY",t))(z||{});function Tr(t){let n="";for(const e of t)typeof e=="string"?n+=e:n+=e.token;return n}class A{constructor(){_(this,"_parent");_(this,"_token",me);_(this,"_children",[]);_(this,"_lambdaId");_(this,"_functionDefinitionPrivacyVar");_(this,"_lambdaParameter","");_(this,"_startIndex",-1);_(this,"_endIndex",-1)}dispose(){var n;this._children.forEach(e=>{typeof e!="string"&&e.dispose()}),(n=this._functionDefinitionPrivacyVar)==null||n.clear(),this._parent=null}getStartIndex(){return this._startIndex}getLambdaId(){return this._lambdaId}setLambdaId(n){this._lambdaId=n}getFunctionDefinitionPrivacyVar(){return this._functionDefinitionPrivacyVar}setLambdaPrivacyVar(n){this._functionDefinitionPrivacyVar=n}getLambdaParameter(){return this._lambdaParameter}setLambdaParameter(n){this._lambdaParameter=n}getParent(){return this._parent}setParent(n){this._parent=n}getChildren(){return this._children}setChildren(n){this._children=n}addChildren(n){this._children.push(n)}addChildrenFirst(n){this._children.unshift(n)}getToken(){return this._token}setToken(n){this._token=n}setIndex(n,e){this._startIndex=n,this._endIndex=e}replaceChild(n,e){const r=this._getIndexInParent(n);r!=null&&(this.getChildren().splice(r,1,e),e.setParent(this))}changeToParent(n){const e=this.getParent();e&&e.removeChild(this),this.setParent(n),n.getChildren().push(this)}removeChild(n){const e=this._getIndexInParent(n);e!=null&&this.getChildren().splice(e,1)}serialize(){const n=this.getToken(),e=this.getChildren(),r=[],s=e.length;for(let i=0;i<s;i++){const a=e[i];a instanceof A?r.push(a.serialize()):r.push(a)}return{token:n,st:this._startIndex,ed:this._endIndex,children:r}}_getIndexInParent(n){const e=this.getChildren(),r=e.length;for(let s=0;s<r;s++)if(e[s]===n)return s}}const Hr=1e5,Vt=new Et(Hr),vt=new Et(Hr);class Ct extends g.Disposable{constructor(){super(...arguments);_(this,"_currentLexerNode",new A);_(this,"_upLevel",0);_(this,"_segment","");_(this,"_bracketState",[]);_(this,"_squareBracketState",0);_(this,"_bracesState",0);_(this,"_singleQuotationState",0);_(this,"_doubleQuotationState",0);_(this,"_lambdaState",!1);_(this,"_colonState",!1);_(this,"_tableBracketState",!1)}dispose(){this._resetTemp(),this._currentLexerNode.dispose(),Vt.clear(),vt.clear()}getUpLevel(){return this._upLevel}isColonClose(){return this._colonState===!1}isColonOpen(){return this._colonState===!0}isDoubleQuotationClose(){return this._doubleQuotationState===0}isLambdaOpen(){return this._lambdaState===!0}isLambdaClose(){return this._lambdaState===!1}isSingleQuotationClose(){return this._singleQuotationState===0}isBracesClose(){return this._bracesState===0}isBracketClose(){return this._bracketState.length===0}isSquareBracketClose(){return this._squareBracketState===0}getCurrentLexerNode(){return this._currentLexerNode}getFunctionAndParameter(e,r){const s=this._getCurrentParamIndex(e,r);if(s==null||s===f.VALUE)return;const i=s[0];if(typeof i=="string")return;let a=i.getParent(),o=i;for(;a;){const u=a.getToken();if(u!==Ce&&!et(u)&&a.getStartIndex()!==-1){const l=a.getChildren().indexOf(o);return{functionName:u,paramIndex:l}}o=a,a=a.getParent()}}moveFormulaRefOffset(e,r,s){const i=this.sequenceNodesBuilder(e);if(i==null)return e;const a=[];for(let o=0,u=i.length;o<u;o++){const l=i[o];if(typeof l=="string"||l.nodeType!==z.REFERENCE){a.push(l);continue}const{token:c}=l,h=Fe(c),{range:m,sheetName:p,unitId:E}=h,R=g.Rectangle.moveOffset(m,r,s);let C="";g.isValidRange(R)?C=Fr({range:R,unitId:E,sheetName:p}):C=f.REF,a.push({...l,token:C})}return`=${Tr(a)}`}checkIfAddBracket(e){let r=0,s=e.length-1,i=e[s];for(;(i===B.CLOSE_BRACKET||i===" ")&&s>=0;)i===B.CLOSE_BRACKET&&r++,i=e[--s];const a=this._getCurrentParamIndex(e,e.length-2);if(a==null||a===f.VALUE)return 0;const o=a[0];if(typeof o=="string")return 0;let u=o.getParent(),l=0;for(;u;){const c=u.getToken();c!==Ce&&c!==B.COLON&&u.getStartIndex()!==-1&&c.toUpperCase()!==We&&(r===0?l+=1:r--),u=u.getParent()}return l}sequenceNodesBuilder(e){const r=vt.get(e);if(r)return[...r];const s=this._getSequenceArray(e);if(s.length===0)return;const i=this.getSequenceNode(s);return vt.set(e,[...i]),i}getSequenceNode(e){const r=[];let s=!1;for(let i=0,a=e.length;i<a;i++){const o=e[i],u=e[i-1],{segment:l,currentString:c,cur:h}=o;if(c===B.DOUBLE_QUOTATION&&(s=!0),(l!==""||i===0)&&i!==a-1){r.push(c);continue}let m=(u==null?void 0:u.segment)||"";const p=i-m.length;let E=i-1;const R=i-1;if(i===a-1&&this._isLastMergeString(c)&&(m+=c,E+=1),m===""||Ne.has(m)){r.push(c);continue}const C=m.trim(),w=this._replacePrefixString(C);s===!0&&C[C.length-1]===B.DOUBLE_QUOTATION?(s=!1,this._pushSequenceNode(r,{nodeType:z.STRING,token:m,startIndex:p,endIndex:E},R)):new RegExp(_t).test(w)?this._pushSequenceNode(r,{nodeType:z.REFERENCE,token:m,startIndex:p,endIndex:E},R):g.Tools.isStringNumber(C)?this._pushSequenceNode(r,{nodeType:z.NUMBER,token:m,startIndex:p,endIndex:E},R):C.length>0&&this._pushSequenceNode(r,{nodeType:z.FUNCTION,token:m,startIndex:p,endIndex:E},R),(i!==a-1||!this._isLastMergeString(c))&&r.push(c)}return this._mergeSequenceNodeReference(r)}_getCurrentParamIndex(e,r){return this._nodeMaker(e,void 0,r)}_isLastMergeString(e){return e===B.DOUBLE_QUOTATION||g.Tools.isStringNumber(e)||!et(e)}_mergeSequenceNodeReference(e){const r=[],s=e.length;let i=0;for(;i<s;){const a=e[i];if(typeof a=="string"){const o=e[i-1];if(a.trim()===B.CLOSE_BRACES&&o!=null&&typeof o!="string"&&o.nodeType===z.FUNCTION&&o.token.trim().substring(0,1)===B.OPEN_BRACES){o.nodeType=z.ARRAY,o.token+=a,o.endIndex+=a.length,i++;continue}r.push(a)}else{const o=e[i+1],u=e[i+2];o===B.COLON&&typeof a!="string"&&u!=null&&typeof u!="string"&&zn((a.token+o+u.token).trim())&&(a.nodeType=z.REFERENCE,a.token+=o+u.token,a.endIndex=u.endIndex,i+=2),r.push(a)}i++}return r}_pushSequenceNode(e,r,s){const i=s-r.startIndex+1;e.splice(e.length-i,i,r)}_replacePrefixString(e){return e.replace(new RegExp(T.AT,"g"),"").replace(new RegExp(T.MINUS,"g"),"")}nodeMakerTest(e){return this._nodeMaker(e)}treeBuilder(e,r=!0,s){if(r===!0){const c=Vt.get(e);if(c)return c}this._resetCurrentLexerNode(),this._currentLexerNode.setToken(me);const i=[];let a=this._nodeMaker(e,i);if(a===f.VALUE||i.length===0)return a;let o=!1,u="";if(s){const{hasDefinedName:c,sequenceString:h}=s(i);o=c,u=h}if(o&&(this._resetCurrentLexerNode(),this._currentLexerNode.setToken(me),a=this._nodeMaker(`=${u}`),a===f.VALUE))return a;const l=this._getTopNode(this._currentLexerNode);return l&&(this._currentLexerNode=l),r&&(this._suffixExpressionHandler(this._currentLexerNode),Vt.set(e,this._currentLexerNode)),this._currentLexerNode}_suffixExpressionHandler(e){var o,u;const r=e.getChildren();if(!r)return;const s=r.length,i=[],a=[];for(let l=0;l<s;l++){const c=r[l];if(c instanceof A)this._suffixExpressionHandler(c),i.push(c);else{const h=c.trim();if(h==="")continue;if(je.has(h)){for(;a.length>0;){const m=(o=a[a.length-1])==null?void 0:o.trim();if(!m||m===B.OPEN_BRACKET)break;const p=Ne.get(m),E=Ne.get(h);if(!p||!E)break;if(E>p)i.push(a.pop());else break}a.push(c)}else if(h===B.OPEN_BRACKET)a.push(c);else if(h===B.CLOSE_BRACKET)for(;a.length>0;){const m=(u=a[a.length-1])==null?void 0:u.trim();if(!m)break;if(m===B.OPEN_BRACKET){a.pop();break}i.push(a.pop())}else i.push(c)}}for(;a.length>0;)i.push(a.pop());e.setChildren(i)}_resetCurrentLexerNode(){this._currentLexerNode=new A}_resetSegment(){this._segment=""}_openBracket(e=0){this._bracketState.push(e)}_closeBracket(){this._bracketState.pop()}_openSquareBracket(){this._squareBracketState+=1}_closeSquareBracket(){this._squareBracketState-=1}_getCurrentBracket(){const e=this._bracketState;return e[e.length-1]}_openBraces(){this._bracesState+=1}_closeBraces(){this._bracesState-=1}_openSingleQuotation(){this._singleQuotationState+=1}_closeSingleQuotation(){this._singleQuotationState-=1}_openDoubleQuotation(){this._doubleQuotationState+=1}_closeDoubleQuotation(){this._doubleQuotationState-=1}_openLambda(){this._lambdaState=!0}_closeLambda(){this._lambdaState=!1}_openColon(e){this._upLevel=e,this._colonState=!0}_closeColon(){this._upLevel=0,this._colonState=!1}_isTableBracket(){return this._tableBracketState}_openTableBracket(){this._tableBracketState=!0}_closeTableBracket(){this._tableBracketState=!1}_getLastChildCurrentLexerNode(){const e=this._currentLexerNode.getChildren();if(e&&e.length>0){const r=e[e.length-1];if(r instanceof A)return r}return!1}_getLastChildCurrent(){const e=this._currentLexerNode.getChildren();return e&&e.length>0?e[e.length-1]:!1}_setParentCurrentLexerNode(){const e=this._currentLexerNode.getParent();return e?(this._currentLexerNode=e,!0):!1}_setAncestorCurrentLexerNode(){var s,i,a,o,u,l;const e=(s=this._currentLexerNode)==null?void 0:s.getParent();let r=!1;if(e&&e.getToken()===Oe){if((i=e==null?void 0:e.getParent())!=null&&i.getParent()){const c=(o=(a=this._currentLexerNode.getParent())==null?void 0:a.getParent())==null?void 0:o.getParent();c&&(this._currentLexerNode=c),r=!0}}else if(e!=null&&e.getParent()){const c=(u=this._currentLexerNode.getParent())==null?void 0:u.getParent();c&&(this._currentLexerNode=c),r=!0}for(let c=0;c<this._upLevel;c++){const h=(l=this._currentLexerNode)==null?void 0:l.getParent();h&&(this._currentLexerNode=h),this._currentLexerNode?r=!0:r=!1}return r}_segmentCount(){return this._segment.trim().length}_pushSegment(e){this._segment+=e}_pushNodeToChildren(e,r=!1){if(e!==""){const s=this._currentLexerNode.getChildren();if(!(e instanceof A)&&this.isColonOpen()){const i=new A;i.setToken(e),i.setParent(this._currentLexerNode),e=i}r?s.unshift(e):s.push(e)}this.isColonOpen()&&(this._setAncestorCurrentLexerNode(),this._closeColon())}_setCurrentLexerNode(e,r=!1){this._pushNodeToChildren(e,r),e.setParent(this._currentLexerNode),this._currentLexerNode=e}_newAndPushCurrentLexerNode(e,r,s=!1){const i=new A;i.setToken(e),i.setIndex(r-e.length,r-1),this._setCurrentLexerNode(i,s)}_getTopNode(e){let r=e;for(;r!=null&&r.getParent();)r=r.getParent();return r}_removeLastChild(){this._currentLexerNode.getChildren().splice(-1)}_findPreviousToken(e,r){for(;r>=0;){const s=e[r];if(s!==" ")return s;r--}}_negativeCondition(e){return!!(je.has(e)||e===B.OPEN_BRACKET||e===B.COMMA||e==="")}_getSequenceArray(e){const r=[];return this._nodeMaker(e,r),r}_resetTemp(){this._currentLexerNode=new A,this._upLevel=0,this._segment="",this._bracketState=[],this._bracesState=0,this._singleQuotationState=0,this._doubleQuotationState=0,this._lambdaState=!1,this._colonState=!1}_checkSimilarErrorToken(e,r,s){if(e!==le.POUND)return!0;let i=s[++r];for(;i===" ";)i=s[++r];return!!et(i)}_nodeMaker(e,r,s){e.substring(0,1)===X.EQUALS&&(e=e.substring(1));const i=e.split(""),a=i.length;let o=0;for(this._resetTemp();o<a;){const u=i[o];if(s===o)return[this._currentLexerNode,u];if(u===B.OPEN_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())if(this._segmentCount()>0||this.isLambdaOpen()){this.isLambdaClose()&&(this._newAndPushCurrentLexerNode(this._segment,o),this._resetSegment()),this._openBracket(1),this._closeLambda();const l=i[o+1];if(l&&l===B.CLOSE_BRACKET){if(!this._setParentCurrentLexerNode()&&o!==a-1)return f.VALUE;o++}else l&&this._newAndPushCurrentLexerNode(Ce,o)}else this._pushNodeToChildren(u),this._openBracket(0);else if(u===B.CLOSE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()){this._pushNodeToChildren(this._segment),this._resetSegment();const l=this._getCurrentBracket();if(l===0)this._pushNodeToChildren(u);else if(l===1){const c=i[o+1];if(c&&c===B.OPEN_BRACKET){if(!this._setParentCurrentLexerNode()&&o!==a-1)return f.VALUE;this._newAndPushCurrentLexerNode(Oe,o,!0),this._openLambda()}else if(!this._setAncestorCurrentLexerNode()&&o!==a-1)return f.VALUE}else return f.VALUE;this._closeBracket()}else if(u===B.OPEN_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(u),this._openBraces();else if(u===B.CLOSE_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(u),this._pushNodeToChildren(this._segment),this._resetSegment(),this._closeBraces();else if(u===B.OPEN_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._segment.length>0&&this._openTableBracket(),this._pushSegment(u),this._openSquareBracket();else if(u===B.CLOSE_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._closeSquareBracket(),this.isSquareBracketClose()?(this._pushSegment(u),this._isTableBracket()&&(this._pushNodeToChildren(this._segment),this._resetSegment()),this._closeTableBracket()):this._pushSegment(u);else if(u===B.DOUBLE_QUOTATION&&this.isSingleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){if(this.isDoubleQuotationClose())this._openDoubleQuotation();else{const l=i[o+1];l&&l===B.DOUBLE_QUOTATION?o++:this._closeDoubleQuotation()}this._pushSegment(u)}else if(u===B.SINGLE_QUOTATION&&this.isDoubleQuotationClose()){if(this.isSingleQuotationClose())this._openSingleQuotation();else{const l=i[o+1];l&&l===B.SINGLE_QUOTATION?o++:this._closeSingleQuotation()}this._pushSegment(u)}else if(u===B.COMMA&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=this._getCurrentBracket();if(l===1||l==null){if(this._pushNodeToChildren(this._segment),this._resetSegment(),!this._setParentCurrentLexerNode()&&o!==a-1&&l!=null)return f.VALUE;this._newAndPushCurrentLexerNode(Ce,o)}else return f.VALUE}else if(u===B.COLON&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=new A;l.setToken(u);const c=new A;c.setToken(Ce),c.setParent(l);const h=new A;h.setToken(Ce),h.setParent(l),l.getChildren().push(c,h);let m=l,p=0;if(this._segmentCount()>0){let E,R,C=0;const w=this._segment.trim(),b=w[0],L=w[1];if(b===T.MINUS&&(E=new A,E.setToken(T.MINUS),C++),(b===T.AT||L===T.AT)&&(R=new A,R.setToken(T.AT),E&&(E.addChildren(R),R.setParent(E)),C++),C>0&&(this._segment=w.slice(C)),p=C,R)if(R.addChildren(l),l.setParent(R),R.getParent()){const M=R.getParent();M&&(m=M)}else m=R;else E&&(m=E,E.addChildren(l),l.setParent(E));const S=new A;S.setToken(this._segment),S.setParent(c),c.getChildren().push(S),this._resetSegment()}else{const E=this._getLastChildCurrentLexerNode();E&&E.changeToParent(c)}this._setCurrentLexerNode(m),this._currentLexerNode=h,this._openColon(p)}else if($n.has(u)&&this._checkSimilarErrorToken(u,o,i)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){this._pushNodeToChildren(this._segment);const l=new A;l.setToken(u);const c=this._getLastChildCurrent();c instanceof A?c.changeToParent(l):c!==!1&&(l.getChildren().push(c),this._removeLastChild()),this._pushNodeToChildren(l),l.setParent(this._currentLexerNode),this._resetSegment()}else if(je.has(u)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){let l=this._segment.trim();if(u===X.MINUS&&l===""){const c=this._findPreviousToken(i,o-1)||"";if(this._negativeCondition(c)){this._pushSegment(X.MINUS),r==null||r.push({segment:this._segment,currentString:u,cur:o,currentLexerNode:this._currentLexerNode}),o++;continue}}else this._segment.length>0&&l===""?l=this._segment:(this._pushNodeToChildren(this._segment),l="");if(u===X.LESS_THAN||u===X.GREATER_THAN){const c=i[o+1];c&&je.has(u+c)?(this._pushNodeToChildren(l+u+c),o++):this._pushNodeToChildren(l+u)}else this._pushNodeToChildren(l+u);this._resetSegment()}else this._pushSegment(u);r==null||r.push({segment:this._segment,currentString:u,cur:o,currentLexerNode:this._currentLexerNode}),o++}this._pushNodeToChildren(this._segment)}}var Zn=Object.defineProperty,Jn=Object.getOwnPropertyDescriptor,Nn=(t,n,e,r)=>{for(var s=r>1?void 0:r?Jn(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Zn(n,e,s),s},or=(t,n)=>(e,r)=>n(e,r,t);exports.FormulaDataModel=class extends g.Disposable{constructor(e,r){super();_(this,"_formulaData",{});_(this,"_arrayFormulaRange",{});_(this,"_arrayFormulaCellData",{});this._currentUniverService=e,this._lexerTreeBuilder=r}clearPreviousArrayFormulaCellData(e){Object.keys(e).forEach(r=>{const s=e[r];if(s==null)return!0;Object.keys(s).forEach(i=>{var l,c,h,m;const a=s[i],o=(c=(l=this._arrayFormulaRange)==null?void 0:l[r])==null?void 0:c[i];if(o==null)return!0;let u=new g.ObjectMatrix;((h=this._arrayFormulaCellData[r])==null?void 0:h[i])!=null&&(u=new g.ObjectMatrix((m=this._arrayFormulaCellData[r])==null?void 0:m[i])),a.forValue((p,E)=>{var S;const R=(S=o==null?void 0:o[p])==null?void 0:S[E];if(R==null)return!0;const{startRow:C,startColumn:w,endRow:b,endColumn:L}=R;for(let M=C;M<=b;M++)for(let k=w;k<=L;k++)u.setValue(M,k,null)}),this._arrayFormulaCellData[r]&&(this._arrayFormulaCellData[r][i]=u.getData())})})}mergeArrayFormulaCellData(e){Object.keys(e).forEach(r=>{const s=e[r];if(s==null)return!0;this._arrayFormulaRange[r]==null&&(this._arrayFormulaRange[r]={}),this._arrayFormulaCellData[r]==null&&(this._arrayFormulaCellData[r]={}),Object.keys(s).forEach(i=>{var l,c,h,m;const a=s[i];let o=new g.ObjectMatrix,u=new g.ObjectMatrix;((l=this._arrayFormulaRange[r])==null?void 0:l[i])!=null&&(o=new g.ObjectMatrix((c=this._arrayFormulaRange[r])==null?void 0:c[i])),((h=this._arrayFormulaCellData[r])==null?void 0:h[i])!=null&&(u=new g.ObjectMatrix((m=this._arrayFormulaCellData[r])==null?void 0:m[i])),a.forValue((p,E)=>{const R=o==null?void 0:o.getValue(p,E);if(R==null)return!0;const{startRow:C,startColumn:w,endRow:b,endColumn:L}=R;for(let S=C;S<=b;S++)for(let M=w;M<=L;M++)u.setValue(S,M,null)}),a.forValue((p,E,R)=>{u.setValue(p,E,R)}),this._arrayFormulaCellData[r]&&(this._arrayFormulaCellData[r][i]=u.getData())})})}getFormulaData(){return this._formulaData}setFormulaData(e){this._formulaData=e}setArrayFormulaRange(e){this._arrayFormulaRange=e}getArrayFormulaRange(){return this._arrayFormulaRange}setArrayFormulaCellData(e){this._arrayFormulaCellData=e}getArrayFormulaCellData(){return this._arrayFormulaCellData}mergeArrayFormulaRange(e){Object.keys(e).forEach(r=>{const s=e[r];if(s==null)return!0;this._arrayFormulaRange[r]||(this._arrayFormulaRange[r]={}),Object.keys(s).forEach(i=>{var u,l;const a=new g.ObjectMatrix(s[i]);let o=new g.ObjectMatrix;(u=this._arrayFormulaRange[r])!=null&&u[i]&&(o=new g.ObjectMatrix((l=this._arrayFormulaRange[r])==null?void 0:l[i])),a.forValue((c,h,m)=>{o.setValue(c,h,m)}),this._arrayFormulaRange[r]&&(this._arrayFormulaRange[r][i]=o.getData())})})}deleteArrayFormulaRange(e,r,s,i){var u;const a=(u=this._arrayFormulaRange[e])==null?void 0:u[r];if(a==null)return;const o=new g.ObjectMatrix(a);o.getValue(s,i)&&(o.realDeleteValue(s,i),this._arrayFormulaRange[e]&&(this._arrayFormulaRange[e][r]=o.getData()))}initFormulaData(){this._currentUniverService.getAllUniverSheetsInstance();const e=this._currentUniverService.getCurrentUniverSheetInstance(),r=e.getUnitId();this._formulaData[r]={},e.getSheets().forEach(i=>{const a=i.getCellMatrix(),o=i.getSheetId();Yr(this._formulaData,r,o,a)})}getCalculateData(){const e=this._currentUniverService.getAllUniverSheetsInstance(),r={},s={};for(const i of e){const a=i.getUnitId(),o=i.getSheets(),u={},l={};for(const c of o){const h=c.getSheetId(),m=c.getConfig();u[h]={cellData:new g.ObjectMatrix(m.cellData),rowCount:m.rowCount,columnCount:m.columnCount},l[c.getName()]=c.getSheetId()}r[a]=u,s[a]=l}return{allUnitData:r,unitSheetNameMap:s}}updateFormulaData(e,r,s){const i=new g.ObjectMatrix(s),a=this.getFormulaIdMap(e,r),o=new Map,u=this._formulaData;u[e]==null&&(u[e]={});const l=u[e];l[r]==null&&(l[r]={});const c=new g.ObjectMatrix(l[r]);i.forValue((h,m,p)=>{const E=(p==null?void 0:p.f)||"",R=(p==null?void 0:p.si)||"",C=g.isFormulaString(E),w=g.isFormulaId(R);if(C&&w)c.setValue(h,m,{f:E,si:R}),a.set(R,{f:E,r:h,c:m});else if(C&&!w)c.setValue(h,m,{f:E});else if(!C&&w)c.setValue(h,m,{f:"",si:R});else if(!C&&!w&&c.getValue(h,m)){const b=c.getValue(h,m),L=(b==null?void 0:b.f)||"",S=(b==null?void 0:b.si)||"";g.isFormulaString(L)&&g.isFormulaId(S)&&o.set(S,L),c.realDeleteValue(h,m)}}),c.forValue((h,m,p)=>{const E=(p==null?void 0:p.f)||"",R=(p==null?void 0:p.si)||"";if(g.isFormulaId(R)){const C=a.get(R),w=o.get(R);if(C&&!g.isFormulaString(E)){const b=C.f,L=m-C.c,S=h-C.r;c.setValue(h,m,{f:b,si:R,x:L,y:S})}else if(typeof w=="string"){const b=p.x||0,L=p.y||0,S=this._lexerTreeBuilder.moveFormulaRefOffset(w,b,L);o.set(R,{r:h,c:m,f:S}),c.setValue(h,m,{f:S,si:R})}else if(typeof w=="object"){const b=m-w.c,L=h-w.r;c.setValue(h,m,{f:w.f,si:R,x:b,y:L})}}})}updateArrayFormulaRange(e,r,s){var u;const i=(u=this._arrayFormulaRange[e])==null?void 0:u[r];if(!i)return;const a=new g.ObjectMatrix(i);new g.ObjectMatrix(s).forValue((l,c,h)=>{if((a==null?void 0:a.getValue(l,c))==null)return!0;const p=(h==null?void 0:h.f)||"",E=(h==null?void 0:h.si)||"",R=g.isFormulaString(p),C=g.isFormulaId(E);!R&&!C&&a.realDeleteValue(l,c)})}updateArrayFormulaCellData(e,r,s){var c,h;const i=(c=this._arrayFormulaRange[e])==null?void 0:c[r];if(!i)return;const a=new g.ObjectMatrix(i),o=(h=this._arrayFormulaCellData[e])==null?void 0:h[r];if(!o)return;const u=new g.ObjectMatrix(o);new g.ObjectMatrix(s).forValue((m,p,E)=>{const R=a==null?void 0:a.getValue(m,p);if(R==null)return!0;const C=(E==null?void 0:E.f)||"",w=(E==null?void 0:E.si)||"",b=g.isFormulaString(C),L=g.isFormulaId(w);if(!b&&!L){const{startRow:S,startColumn:M,endRow:k,endColumn:j}=R;for(let v=S;v<=k;v++)for(let P=M;P<=j;P++)u.realDeleteValue(v,P)}})}getFormulaItemBySId(e,r,s){const i=this._formulaData;if(i[s]==null)return null;const a=i[s];if((a==null?void 0:a[r])==null)return null;const o=new g.ObjectMatrix(a[r]);let u=null;return o.forValue((l,c,h)=>{const{f:m,si:p,x:E=0,y:R=0}=h;if(p===e&&m.length>0&&E===0&&R===0)return u=h,!1}),u}getFormulaDataItem(e,r,s,i){var a,o,u,l;return(l=(u=(o=(a=this._formulaData)==null?void 0:a[i])==null?void 0:o[s])==null?void 0:u[e])==null?void 0:l[r]}getFormulaIdMap(e,r){const s=new Map,i=this._formulaData;if(i[e]==null)return s;const a=i[e];return(a==null?void 0:a[r])==null||new g.ObjectMatrix(a[r]).forValue((u,l,c)=>{const h=(c==null?void 0:c.f)||"",m=(c==null?void 0:c.si)||"",p=(c==null?void 0:c.x)||0,E=(c==null?void 0:c.y)||0;g.isFormulaString(h)&&g.isFormulaId(m)&&p===0&&E===0&&s.set(m,{f:h,r:u,c:l})}),s}};exports.FormulaDataModel=Nn([or(0,g.IUniverInstanceService),or(1,x.Inject(Ct))],exports.FormulaDataModel);function Yr(t,n,e,r){const s=new Map,i=new g.ObjectMatrix;r.forValue((a,o,u)=>{const l=(u==null?void 0:u.f)||"",c=(u==null?void 0:u.si)||"",h=g.isFormulaString(l),m=g.isFormulaId(c);h&&m?(i.setValue(a,o,{f:l,si:c}),s.set(c,{f:l,r:a,c:o})):h&&!m?i.setValue(a,o,{f:l}):!h&&m&&i.setValue(a,o,{f:"",si:c})}),i.forValue((a,o,u)=>{const l=(u==null?void 0:u.f)||"",c=(u==null?void 0:u.si)||"";if(g.isFormulaId(c)&&!g.isFormulaString(l)){const h=s.get(c);if(h){const m=h.f,p=o-h.c,E=a-h.r;i.setValue(a,o,{f:m,si:c,x:p,y:E})}}}),t[n]&&(t[n][e]=i.getData())}const es=t=>{const n=t.get(exports.FormulaDataModel),e=g.Tools.deepClone(n.getArrayFormulaRange()),r=g.Tools.deepClone(n.getArrayFormulaCellData());return{arrayFormulaRange:e,arrayFormulaCellData:r}},ut={id:"formula.mutation.set-array-formula-data",type:g.CommandType.MUTATION,handler:(t,n)=>{const e=t.get(exports.FormulaDataModel);return e.setArrayFormulaRange(n.arrayFormulaRange),e.setArrayFormulaCellData(n.arrayFormulaCellData),!0}},Dt={id:"formula.mutation.set-defined-name",type:g.CommandType.MUTATION,handler:()=>!0},wt={id:"formula.mutation.remove-defined-name",type:g.CommandType.MUTATION,handler:()=>!0},Xt={id:"formula.mutation.set-feature-calculation",type:g.CommandType.MUTATION,handler:()=>!0},Gt={id:"formula.mutation.remove-feature-calculation",type:g.CommandType.MUTATION,handler:()=>!0},Kt={id:"formula.mutation.set-formula-calculation-start",type:g.CommandType.MUTATION,handler:()=>!0},zt={id:"formula.mutation.set-formula-calculation-stop",type:g.CommandType.MUTATION,handler:()=>!0},lt={id:"formula.mutation.set-formula-calculation-notification",type:g.CommandType.MUTATION,handler:()=>!0},qt={id:"formula.mutation.set-formula-calculation-result",type:g.CommandType.MUTATION,handler:()=>!0},Zt={id:"formula.mutation.set-formula-data",type:g.CommandType.MUTATION,handler:(t,n)=>(t.get(exports.FormulaDataModel).setFormulaData(n.formulaData),!0)},Jt={id:"formula.mutation.set-other-formula",type:g.CommandType.MUTATION,handler:()=>!0},Nt={id:"formula.mutation.remove-other-formula",type:g.CommandType.MUTATION,handler:()=>!0},Wr={id:"formula.mutation.set-super-table",type:g.CommandType.MUTATION,handler:()=>!0},Ir={id:"formula.mutation.remove-super-table",type:g.CommandType.MUTATION,handler:()=>!0},er={id:"formula.mutation.set-super-table-option",type:g.CommandType.MUTATION,handler:()=>!0},tr={id:"formula.mutation.unregister-function",type:g.CommandType.MUTATION,handler:()=>!0};class yt extends g.Disposable{isError(){return!1}isAsyncObject(){return!1}isAsyncArrayObject(){return!1}isReferenceObject(){return!1}isValueObject(){return!1}isEqualType(n){return!1}}var Se=(t=>(t.FALSE="FALSE",t.TRUE="TRUE",t))(Se||{}),ye=(t=>(t[t.SUCCESS=0]="SUCCESS",t[t.ERROR=1]="ERROR",t))(ye||{}),De=(t=>(t.ALL="#All",t.DATA="#Data",t.HEADERS="#Headers",t.TOTALS="#Totals",t))(De||{}),J=(t=>(t[t.FRONT=0]="FRONT",t[t.BACK=1]="BACK",t))(J||{});class ts{constructor(){_(this,"_cache",new Map);_(this,"_continueBuildingCache",new Map)}set(n,e,r,s,i){if(!this.shouldContinueBuildingCache(n,e,r,i))return;let a=this._cache.get(n);a==null&&(a=new Map,this._cache.set(n,a));let o=a.get(e);o==null&&(o=new Map,a.set(e,o));let u=o.get(r);u==null&&(u=new Map,o.set(r,u));let l=u.get(s);l==null&&(l=[],u.set(s,l)),l.push(i)}getCellValuePositions(n,e,r){var s,i;return(i=(s=this._cache.get(n))==null?void 0:s.get(e))==null?void 0:i.get(r)}getCellPositions(n,e,r,s){var i,a,o;return(o=(a=(i=this._cache.get(n))==null?void 0:i.get(e))==null?void 0:a.get(r))==null?void 0:o.get(s)}getCellPosition(n,e,r,s,i,a){const o=this.getCellPositions(n,e,r,s);if(o!=null){for(const u of o)if(u>=i&&u<=a)return u}}setContinueBuildingCache(n,e,r,s,i){let a=this._continueBuildingCache.get(n);a==null&&(a=new Map,this._continueBuildingCache.set(n,a));let o=a.get(e);o==null&&(o=new Map,a.set(e,o));let u=o.get(r);if(u==null){u={startRow:s,endRow:i},o.set(r,u);return}u.startRow=Math.min(u.startRow,s),u.endRow=Math.max(u.endRow,i)}shouldContinueBuildingCache(n,e,r,s){var u,l;const i=(l=(u=this._continueBuildingCache.get(n))==null?void 0:u.get(e))==null?void 0:l.get(r);if(i==null)return!0;const{startRow:a,endRow:o}=i;return!(s>=a&&s<=o)}canUseCache(n,e,r,s,i){var l,c;if(r===-1||s===-1||i===-1)return!1;const a=(c=(l=this._continueBuildingCache.get(n))==null?void 0:l.get(e))==null?void 0:c.get(r);if(a==null)return!1;const{startRow:o,endRow:u}=a;return!(s>u||i<o)}clear(){this._cache.clear(),this._continueBuildingCache.clear()}}const fe=new ts;var be=(t=>(t[t.MIN=0]="MIN",t[t.MAX=1]="MAX",t))(be||{}),te=(t=>(t[t.NORMAL=0]="NORMAL",t[t.MIN=1]="MIN",t[t.MAX=2]="MAX",t))(te||{});function ur(){return Intl&&Intl.Collator?new Intl.Collator(void 0,{numeric:!1}).compare:(t,n)=>t.localeCompare(n)}function rs(t){return t.indexOf("*")>-1||t.indexOf("?")>-1}function lr(t,n){const e=n.replace(/~?[*?]/g,s=>s.startsWith("~")?`\\${s.substring(1)}`:s==="*"?".*":s==="?"?".":s);return new RegExp(`^${e}$`).test(t)}function cr(t){return t.replace(/~?[*?]/g,n=>n.startsWith("~")?n.substring(1):" ")}function ns(t,n,e){let r=!1;switch(e){case y.EQUALS:r=lr(t,n);break;case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:r=lr(t,n)||t>cr(n);break;case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:r=t<cr(n);break}return r}class pe extends yt{constructor(n){super(),this._rawValue=n}isValueObject(){return!0}toUnitRange(){return{range:{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1},sheetId:"",unitId:""}}getValue(){return 0}getArrayValue(){return[]}setValue(n){}setArrayValue(n){}isArray(){return!1}isString(){return!1}isNumber(){return!1}isBoolean(){return!1}isLambda(){return!1}isError(){return!1}isNull(){return!1}sum(){return new d(f.VALUE)}max(){return new d(f.VALUE)}min(){return new d(f.VALUE)}count(){return new d(f.VALUE)}countA(){return new d(f.VALUE)}countBlank(){return new d(f.VALUE)}getNegative(){return new d(f.NAME)}getReciprocal(){return new d(f.NAME)}plus(n){return new d(f.NAME)}minus(n){return new d(f.NAME)}multiply(n){return new d(f.NAME)}divided(n){return new d(f.NAME)}map(n){return new d(f.NAME)}mapValue(n){return new d(f.NAME)}product(n,e){return e(this,n)}compare(n,e){return new d(f.NAME)}isEqual(n){return this.compare(n,y.EQUALS)}isNotEqual(n){return this.compare(n,y.NOT_EQUAL)}isGreaterThanOrEqual(n){return this.compare(n,y.GREATER_THAN_OR_EQUAL)}isLessThanOrEqual(n){return this.compare(n,y.LESS_THAN_OR_EQUAL)}isLessThan(n){return this.compare(n,y.LESS_THAN)}isGreaterThan(n){return this.compare(n,y.GREATER_THAN)}concatenateFront(n){return new d(f.NAME)}concatenateBack(n){return new d(f.NAME)}plusBy(n){return new d(f.NAME)}minusBy(n){return new d(f.NAME)}multiplyBy(n){return new d(f.NAME)}dividedBy(n){return new d(f.NAME)}compareBy(n,e){return new d(f.NAME)}concatenate(n,e=J.FRONT){let r=this.getValue().toString();if(typeof n=="string")e===J.FRONT?r=n+r:r+=n;else if(typeof n=="number")e===J.FRONT?r=n.toString()+r:r+=n.toString();else if(typeof n=="boolean"){const s=n?"TRUE":"FALSE";e===J.FRONT?r=s+r:r+=s}return r}pow(n){return new d(f.VALUE)}powInverse(n){return new d(f.VALUE)}sqrt(){return new d(f.VALUE)}cbrt(){return new d(f.VALUE)}cos(){return new d(f.VALUE)}acos(){return new d(f.VALUE)}acosh(){return new d(f.VALUE)}sin(){return new d(f.VALUE)}asin(){return new d(f.VALUE)}asinh(){return new d(f.VALUE)}tan(){return new d(f.VALUE)}tanh(){return new d(f.VALUE)}atan(){return new d(f.VALUE)}atan2(n){return new d(f.VALUE)}atan2Inverse(n){return new d(f.VALUE)}atanh(){return new d(f.VALUE)}mean(){return this}median(){return this}var(){return this}std(){return this}log(){return new d(f.VALUE)}log10(){return new d(f.VALUE)}exp(){return new d(f.VALUE)}abs(){return new d(f.VALUE)}round(n){return new d(f.VALUE)}roundInverse(n){return new d(f.VALUE)}floor(n){return new d(f.VALUE)}floorInverse(n){return new d(f.VALUE)}ceil(n){return new d(f.VALUE)}ceilInverse(n){return new d(f.VALUE)}}class d extends pe{constructor(n,e=""){super(n),this._errorType=n,this._errorContent=e}getValue(){return this._errorType}getErrorType(){return this._errorType}getErrorContent(){return this._errorContent}isEqualType(n){return n.getErrorType()===this.getErrorType()}isError(){return!0}}var ss=20,is=1,Pe=1e6,hr=1e6,as=-7,os=21,us=!1,Ke="[big.js] ",Ae=Ke+"Invalid ",bt=Ae+"decimal places",ls=Ae+"rounding mode",Xr=Ke+"Division by zero",U={},re=void 0,cs=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function Gr(){function t(n){var e=this;if(!(e instanceof t))return n===re?Gr():new t(n);if(n instanceof t)e.s=n.s,e.e=n.e,e.c=n.c.slice();else{if(typeof n!="string"){if(t.strict===!0&&typeof n!="bigint")throw TypeError(Ae+"value");n=n===0&&1/n<0?"-0":String(n)}hs(e,n)}e.constructor=t}return t.prototype=U,t.DP=ss,t.RM=is,t.NE=as,t.PE=os,t.strict=us,t.roundDown=0,t.roundHalfUp=1,t.roundHalfEven=2,t.roundUp=3,t}function hs(t,n){var e,r,s;if(!cs.test(n))throw Error(Ae+"number");for(t.s=n.charAt(0)=="-"?(n=n.slice(1),-1):1,(e=n.indexOf("."))>-1&&(n=n.replace(".","")),(r=n.search(/e/i))>0?(e<0&&(e=r),e+=+n.slice(r+1),n=n.substring(0,r)):e<0&&(e=n.length),s=n.length,r=0;r<s&&n.charAt(r)=="0";)++r;if(r==s)t.c=[t.e=0];else{for(;s>0&&n.charAt(--s)=="0";);for(t.e=e-r-1,t.c=[],e=0;r<=s;)t.c[e++]=+n.charAt(r++)}return t}function Ve(t,n,e,r){var s=t.c;if(e===re&&(e=t.constructor.RM),e!==0&&e!==1&&e!==2&&e!==3)throw Error(ls);if(n<1)r=e===3&&(r||!!s[0])||n===0&&(e===1&&s[0]>=5||e===2&&(s[0]>5||s[0]===5&&(r||s[1]!==re))),s.length=1,r?(t.e=t.e-n+1,s[0]=1):s[0]=t.e=0;else if(n<s.length){if(r=e===1&&s[n]>=5||e===2&&(s[n]>5||s[n]===5&&(r||s[n+1]!==re||s[n-1]&1))||e===3&&(r||!!s[0]),s.length=n,r){for(;++s[--n]>9;)if(s[n]=0,n===0){++t.e,s.unshift(1);break}}for(n=s.length;!s[--n];)s.pop()}return t}function $e(t,n,e){var r=t.e,s=t.c.join(""),i=s.length;if(n)s=s.charAt(0)+(i>1?"."+s.slice(1):"")+(r<0?"e":"e+")+r;else if(r<0){for(;++r;)s="0"+s;s="0."+s}else if(r>0)if(++r>i)for(r-=i;r--;)s+="0";else r<i&&(s=s.slice(0,r)+"."+s.slice(r));else i>1&&(s=s.charAt(0)+"."+s.slice(1));return t.s<0&&e?"-"+s:s}U.abs=function(){var t=new this.constructor(this);return t.s=1,t};U.cmp=function(t){var n,e=this,r=e.c,s=(t=new e.constructor(t)).c,i=e.s,a=t.s,o=e.e,u=t.e;if(!r[0]||!s[0])return r[0]?i:s[0]?-a:0;if(i!=a)return i;if(n=i<0,o!=u)return o>u^n?1:-1;for(a=(o=r.length)<(u=s.length)?o:u,i=-1;++i<a;)if(r[i]!=s[i])return r[i]>s[i]^n?1:-1;return o==u?0:o>u^n?1:-1};U.div=function(t){var n=this,e=n.constructor,r=n.c,s=(t=new e(t)).c,i=n.s==t.s?1:-1,a=e.DP;if(a!==~~a||a<0||a>Pe)throw Error(bt);if(!s[0])throw Error(Xr);if(!r[0])return t.s=i,t.c=[t.e=0],t;var o,u,l,c,h,m=s.slice(),p=o=s.length,E=r.length,R=r.slice(0,o),C=R.length,w=t,b=w.c=[],L=0,S=a+(w.e=n.e-t.e)+1;for(w.s=i,i=S<0?0:S,m.unshift(0);C++<o;)R.push(0);do{for(l=0;l<10;l++){if(o!=(C=R.length))c=o>C?1:-1;else for(h=-1,c=0;++h<o;)if(s[h]!=R[h]){c=s[h]>R[h]?1:-1;break}if(c<0){for(u=C==o?s:m;C;){if(R[--C]<u[C]){for(h=C;h&&!R[--h];)R[h]=9;--R[h],R[C]+=10}R[C]-=u[C]}for(;!R[0];)R.shift()}else break}b[L++]=c?l:++l,R[0]&&c?R[C]=r[p]||0:R=[r[p]]}while((p++<E||R[0]!==re)&&i--);return!b[0]&&L!=1&&(b.shift(),w.e--,S--),L>S&&Ve(w,S,e.RM,R[0]!==re),w};U.eq=function(t){return this.cmp(t)===0};U.gt=function(t){return this.cmp(t)>0};U.gte=function(t){return this.cmp(t)>-1};U.lt=function(t){return this.cmp(t)<0};U.lte=function(t){return this.cmp(t)<1};U.minus=U.sub=function(t){var n,e,r,s,i=this,a=i.constructor,o=i.s,u=(t=new a(t)).s;if(o!=u)return t.s=-u,i.plus(t);var l=i.c.slice(),c=i.e,h=t.c,m=t.e;if(!l[0]||!h[0])return h[0]?t.s=-u:l[0]?t=new a(i):t.s=1,t;if(o=c-m){for((s=o<0)?(o=-o,r=l):(m=c,r=h),r.reverse(),u=o;u--;)r.push(0);r.reverse()}else for(e=((s=l.length<h.length)?l:h).length,o=u=0;u<e;u++)if(l[u]!=h[u]){s=l[u]<h[u];break}if(s&&(r=l,l=h,h=r,t.s=-t.s),(u=(e=h.length)-(n=l.length))>0)for(;u--;)l[n++]=0;for(u=n;e>o;){if(l[--e]<h[e]){for(n=e;n&&!l[--n];)l[n]=9;--l[n],l[e]+=10}l[e]-=h[e]}for(;l[--u]===0;)l.pop();for(;l[0]===0;)l.shift(),--m;return l[0]||(t.s=1,l=[m=0]),t.c=l,t.e=m,t};U.mod=function(t){var n,e=this,r=e.constructor,s=e.s,i=(t=new r(t)).s;if(!t.c[0])throw Error(Xr);return e.s=t.s=1,n=t.cmp(e)==1,e.s=s,t.s=i,n?new r(e):(s=r.DP,i=r.RM,r.DP=r.RM=0,e=e.div(t),r.DP=s,r.RM=i,this.minus(e.times(t)))};U.neg=function(){var t=new this.constructor(this);return t.s=-t.s,t};U.plus=U.add=function(t){var n,e,r,s=this,i=s.constructor;if(t=new i(t),s.s!=t.s)return t.s=-t.s,s.minus(t);var a=s.e,o=s.c,u=t.e,l=t.c;if(!o[0]||!l[0])return l[0]||(o[0]?t=new i(s):t.s=s.s),t;if(o=o.slice(),n=a-u){for(n>0?(u=a,r=l):(n=-n,r=o),r.reverse();n--;)r.push(0);r.reverse()}for(o.length-l.length<0&&(r=l,l=o,o=r),n=l.length,e=0;n;o[n]%=10)e=(o[--n]=o[n]+l[n]+e)/10|0;for(e&&(o.unshift(e),++u),n=o.length;o[--n]===0;)o.pop();return t.c=o,t.e=u,t};U.pow=function(t){var n=this,e=new n.constructor("1"),r=e,s=t<0;if(t!==~~t||t<-hr||t>hr)throw Error(Ae+"exponent");for(s&&(t=-t);t&1&&(r=r.times(n)),t>>=1,!!t;)n=n.times(n);return s?e.div(r):r};U.prec=function(t,n){if(t!==~~t||t<1||t>Pe)throw Error(Ae+"precision");return Ve(new this.constructor(this),t,n)};U.round=function(t,n){if(t===re)t=0;else if(t!==~~t||t<-Pe||t>Pe)throw Error(bt);return Ve(new this.constructor(this),t+this.e+1,n)};U.sqrt=function(){var t,n,e,r=this,s=r.constructor,i=r.s,a=r.e,o=new s("0.5");if(!r.c[0])return new s(r);if(i<0)throw Error(Ke+"No square root");i=Math.sqrt(r+""),i===0||i===1/0?(n=r.c.join(""),n.length+a&1||(n+="0"),i=Math.sqrt(n),a=((a+1)/2|0)-(a<0||a&1),t=new s((i==1/0?"5e":(i=i.toExponential()).slice(0,i.indexOf("e")+1))+a)):t=new s(i+""),a=t.e+(s.DP+=4);do e=t,t=o.times(e.plus(r.div(e)));while(e.c.slice(0,a).join("")!==t.c.slice(0,a).join(""));return Ve(t,(s.DP-=4)+t.e+1,s.RM)};U.times=U.mul=function(t){var n,e=this,r=e.constructor,s=e.c,i=(t=new r(t)).c,a=s.length,o=i.length,u=e.e,l=t.e;if(t.s=e.s==t.s?1:-1,!s[0]||!i[0])return t.c=[t.e=0],t;for(t.e=u+l,a<o&&(n=s,s=i,i=n,l=a,a=o,o=l),n=new Array(l=a+o);l--;)n[l]=0;for(u=o;u--;){for(o=0,l=a+u;l>u;)o=n[l]+i[u]*s[l-u-1]+o,n[l--]=o%10,o=o/10|0;n[l]=o}for(o?++t.e:n.shift(),u=n.length;!n[--u];)n.pop();return t.c=n,t};U.toExponential=function(t,n){var e=this,r=e.c[0];if(t!==re){if(t!==~~t||t<0||t>Pe)throw Error(bt);for(e=Ve(new e.constructor(e),++t,n);e.c.length<t;)e.c.push(0)}return $e(e,!0,!!r)};U.toFixed=function(t,n){var e=this,r=e.c[0];if(t!==re){if(t!==~~t||t<0||t>Pe)throw Error(bt);for(e=Ve(new e.constructor(e),t+e.e+1,n),t=t+e.e+1;e.c.length<t;)e.c.push(0)}return $e(e,!1,!!r)};U[Symbol.for("nodejs.util.inspect.custom")]=U.toJSON=U.toString=function(){var t=this,n=t.constructor;return $e(t,t.e<=n.NE||t.e>=n.PE,!!t.c[0])};U.toNumber=function(){var t=Number($e(this,!0,!0));if(this.constructor.strict===!0&&!this.eq(t.toString()))throw Error(Ke+"Imprecise conversion");return t};U.toPrecision=function(t,n){var e=this,r=e.constructor,s=e.c[0];if(t!==re){if(t!==~~t||t<1||t>Pe)throw Error(Ae+"precision");for(e=Ve(new r(e),t,n);e.c.length<t;)e.c.push(0)}return $e(e,t<=e.e||e.e<=r.NE||e.e>=r.PE,!!s)};U.valueOf=function(){var t=this,n=t.constructor;if(n.strict===!0)throw Error(Ke+"valueOf disallowed");return $e(t,t.e<=n.NE||t.e>=n.PE,!0)};var W=Gr();function Kr(t){let n;switch(t){case y.EQUALS:n=y.EQUALS;break;case y.GREATER_THAN:n=y.LESS_THAN;break;case y.GREATER_THAN_OR_EQUAL:n=y.LESS_THAN_OR_EQUAL;break;case y.LESS_THAN:n=y.GREATER_THAN;break;case y.LESS_THAN_OR_EQUAL:n=y.GREATER_THAN_OR_EQUAL;break;case y.NOT_EQUAL:n=y.NOT_EQUAL;break}return n}function rr(t,n){return W(t).times(n).toNumber()}function fr(t,n){const e=10**Math.floor(n);return Math.round(rr(t,e))/e}function dr(t,n){const e=10**Math.floor(n);return Math.floor(rr(t,e))/e}function mr(t,n){const e=10**Math.floor(n);return Math.ceil(rr(t,e))/e}function gr(t,n){return t**n}class ue extends pe{isNull(){return!0}plus(n){return new D(0,!0).plus(n)}minus(n){return new D(0,!0).minus(n)}multiply(n){return new D(0,!0).multiply(n)}divided(n){return new D(0,!0).divided(n)}compare(n,e){return n.isString()?new Y("").compare(n,e):n.isBoolean()?new Q(!1).compare(n,e):new D(0,!0).compare(n,e)}concatenateFront(n){return n.isArray()?n.concatenateBack(new Y("")):new Y(this.concatenate(n.getValue(),J.FRONT))}concatenateBack(n){return n.isArray()?n.concatenateFront(new Y("")):new Y(this.concatenate(n.getValue(),J.BACK))}plusBy(n){return new D(0).plusBy(n)}minusBy(n){return new D(0).minusBy(n)}multiplyBy(n){return new D(0).multiplyBy(n)}dividedBy(n){return new D(0).dividedBy(n)}compareBy(n,e){return typeof n=="string"?new Y("").compareBy(n,e):typeof n=="boolean"?new Q(!1).compareBy(n,e):new D(0,!0).compareBy(n,e)}pow(n){return new D(0,!0).pow(n)}sqrt(){return new D(0,!0)}cbrt(){return new D(0,!0)}cos(){return new D(0,!0)}acos(){return new D(0,!0)}acosh(){return new D(0,!0)}sin(){return new D(0,!0)}asin(){return new D(0,!0)}asinh(){return new D(0,!0)}tan(){return new D(0,!0)}tanh(){return new D(0,!0)}atan(){return new D(0,!0)}atan2(n){return new D(0,!0).atan2(n)}atanh(){return new D(0,!0)}log(){return new d(f.NUM)}log10(){return new d(f.NUM)}exp(){return new d(f.NUM)}abs(){return new d(f.NUM)}round(n){return new D(0,!0).round(n)}floor(n){return new D(0,!0).floor(n)}ceil(n){return new D(0,!0).ceil(n)}}class Q extends pe{constructor(e,r=!1){super(e);_(this,"_value",!1);if(r){this._value=e;return}if(typeof e=="boolean")this._value=e;else if(typeof e=="string"){const s=e.toLocaleUpperCase();s===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 r=0;return e&&(r=1),new D(-r,!0)}getReciprocal(){return this.getValue()?new D(1,!0):new d(f.DIV_BY_ZERO)}plus(e){return this._convertTonNumber().plus(e)}minus(e){return this._convertTonNumber().minus(e)}multiply(e){return this._convertTonNumber().multiply(e)}divided(e){return this._convertTonNumber().divided(e)}compare(e,r){return this._convertTonNumber().compare(e,r)}concatenateFront(e){return this._convertTonNumber().concatenateFront(e)}concatenateBack(e){return this._convertTonNumber().concatenateBack(e)}_convertTonNumber(){const e=this.getValue();let r=0;return e&&(r=1),new D(r,!0)}pow(e){return this._convertTonNumber().pow(e)}sqrt(){return this._convertTonNumber()}cbrt(){return this._convertTonNumber()}cos(){return this._convertTonNumber().cos()}acos(){return this._convertTonNumber().acos()}acosh(){return this._convertTonNumber().acosh()}sin(){return this._convertTonNumber().sin()}asin(){return this._convertTonNumber().asin()}asinh(){return this._convertTonNumber().asinh()}tan(){return this._convertTonNumber().tan()}tanh(){return this._convertTonNumber().tanh()}atan(){return this._convertTonNumber().atan()}atan2(e){return this._convertTonNumber().atan2(e)}atanh(){return this._convertTonNumber().atanh()}log(){return this._convertTonNumber().log()}log10(){return this._convertTonNumber().log10()}exp(){return this._convertTonNumber().exp()}abs(){return this._convertTonNumber().abs()}round(e){return this._convertTonNumber().round(e)}floor(e){return this._convertTonNumber().floor(e)}ceil(e){return this._convertTonNumber().ceil(e)}}class D extends pe{constructor(e,r=!1){super(e);_(this,"_value",0);if(r){this._value=e;return}this._value=Number(e)}getValue(){return this._value}setValue(e){this._value=e}isNumber(){return!0}getNegative(){return new D(0).minus(this)}getReciprocal(){return new D(1).divided(this)}plus(e){if(e.isArray())return e.plus(this);const r=this.plusBy(e.getValue());return r.isError()?this:r}equalZero(){return this._value===0}minus(e){if(e.isArray()){const s=e.getNegative();return s.isError()?s:s.plus(this)}const r=this.minusBy(e.getValue());return r.isError()?this:r}multiply(e){return e.isArray()?e.multiply(this):this.multiplyBy(e.getValue())}divided(e){if(e.isArray()){const r=e.getReciprocal();return r.isError()?r:r.multiply(this)}return this.dividedBy(e.getValue())}concatenateFront(e){return e.isArray()?e.concatenateBack(this):new Y(this.concatenate(e.getValue(),J.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new Y(this.concatenate(e.getValue(),J.BACK))}compare(e,r){return e.isArray()?e.compare(this,Kr(r)):this.compareBy(e.getValue(),r)}plusBy(e){const r=this.getValue();if(typeof e=="string")return new d(f.VALUE);if(typeof e=="number"){if(!Number.isFinite(r)||!Number.isFinite(e))return new d(f.NUM);const s=W(r).plus(e).toNumber();return Number.isFinite(s)?new D(s):new d(f.NUM)}return typeof e=="boolean"?new D(W(r).plus(e?1:0).toNumber()):this}minusBy(e){const r=this.getValue();if(typeof e=="string")return new d(f.VALUE);if(typeof e=="number"){if(!Number.isFinite(r)||!Number.isFinite(e))return new d(f.NUM);const s=W(r).minus(e).toNumber();return Number.isFinite(s)?new D(s):new d(f.NUM)}return typeof e=="boolean"?new D(W(r).minus(e?1:0).toNumber()):this}multiplyBy(e){const r=this.getValue();if(typeof e=="string")return new d(f.VALUE);if(typeof e=="number"){if(!Number.isFinite(r)||!Number.isFinite(e))return new d(f.NUM);const s=W(r).times(e).toNumber();return Number.isFinite(s)?new D(s):new d(f.NUM)}return typeof e=="boolean"?new D(W(r).times(e?1:0).toNumber()):this}dividedBy(e){const r=this.getValue();if(typeof e=="string")return new d(f.VALUE);if(typeof e=="number"){if(e===0)return new d(f.DIV_BY_ZERO);if(!Number.isFinite(r)||!Number.isFinite(e))return new d(f.NUM);const s=W(r).div(e).toNumber();return Number.isFinite(s)?new D(s):new d(f.NUM)}return typeof e=="boolean"?e===!1?new d(f.DIV_BY_ZERO):new D(W(r).div(1).toNumber()):this}compareBy(e,r){const s=this.getValue();let i=!1;if(typeof e=="string")switch(r){case y.EQUALS:case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:i=!1;break;case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:case y.NOT_EQUAL:i=!0;break}else if(typeof e=="number")if(!Number.isFinite(s)||!Number.isFinite(e))i=this._compareInfinity(s,e,r);else switch(r){case y.EQUALS:i=W(s).eq(e);break;case y.GREATER_THAN:i=W(s).gt(e);break;case y.GREATER_THAN_OR_EQUAL:i=W(s).gte(e);break;case y.LESS_THAN:i=W(s).lt(e);break;case y.LESS_THAN_OR_EQUAL:i=W(s).lte(e);break;case y.NOT_EQUAL:i=!W(s).eq(e);break}else if(typeof e=="boolean")switch(r){case y.EQUALS:case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:i=!1;break;case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:case y.NOT_EQUAL:i=!0;break}return new Q(i)}pow(e){if(e.isArray())return e.powInverse(this);const r=this.getValue(),s=e.getValue();if(typeof s=="string")return new d(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(r)||!Number.isFinite(s))return new d(f.NUM);const i=gr(r,s);return Number.isFinite(i)?new D(i):new d(f.NUM)}return typeof s=="boolean"?new D(gr(r,s?1:0)):this}sqrt(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=W(e).sqrt().toNumber();return Number.isFinite(r)?new D(r):new d(f.NUM)}cbrt(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.cbrt(e);return Number.isFinite(r)?new D(r):new d(f.NUM)}cos(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.cos(e);return Number.isFinite(r)?new D(r):new d(f.NUM)}acos(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.acos(e);return Number.isNaN(r)?new d(f.NUM):new D(r)}acosh(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.acosh(e);return Number.isNaN(r)?new d(f.NUM):new D(r)}sin(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.sin(e);return Number.isFinite(r)?new D(r):new d(f.NUM)}asin(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.asin(e);return Number.isNaN(r)?new d(f.NUM):new D(r)}asinh(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.asinh(e);return Number.isNaN(r)?new d(f.NUM):new D(r)}tan(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.tan(e);return Number.isFinite(r)?new D(r):new d(f.NUM)}tanh(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.tanh(e);return Number.isFinite(r)?new D(r):new d(f.NUM)}atan(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.atan(e);return Number.isFinite(r)?new D(r):new d(f.NUM)}atan2(e){if(e.isArray())return e.atan2Inverse(this);const r=this.getValue(),s=e.getValue();if(typeof s=="string")return new d(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(r)||!Number.isFinite(s))return new d(f.NUM);const i=Math.atan2(r,s);return Number.isFinite(i)?new D(i):new d(f.NUM)}return typeof s=="boolean"?new D(Math.atan2(r,s?1:0)):this}atanh(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.atanh(e);return Number.isFinite(r)?new D(r):new d(f.NUM)}log(){const e=this.getValue();if(typeof e=="number"&&e<=0)return new d(f.NUM);if(!Number.isFinite(e))return new d(f.NUM);const r=Math.log(e);return Number.isFinite(r)?new D(r):new d(f.NUM)}log10(){const e=this.getValue();if(typeof e=="number"&&e<=0)return new d(f.NUM);if(!Number.isFinite(e))return new d(f.NUM);const r=Math.log10(e);return Number.isFinite(r)?new D(r):new d(f.NUM)}exp(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.exp(e);return Number.isFinite(r)?new D(r):new d(f.NUM)}abs(){const e=this.getValue();if(!Number.isFinite(e))return new d(f.NUM);const r=Math.abs(e);return Number.isFinite(r)?new D(r):new d(f.NUM)}round(e){if(e.isArray())return e.roundInverse(this);const r=this.getValue(),s=e.getValue();if(typeof s=="string")return new d(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(r)||!Number.isFinite(s))return new d(f.NUM);const i=fr(r,s);return Number.isFinite(i)?new D(i):new d(f.NUM)}return typeof s=="boolean"?new D(fr(r,s?1:0)):this}floor(e){if(e.isArray())return e.floorInverse(this);const r=this.getValue(),s=e.getValue();if(typeof s=="string")return new d(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(r)||!Number.isFinite(s))return new d(f.NUM);const i=dr(r,s);return Number.isFinite(i)?new D(i):new d(f.NUM)}return typeof s=="boolean"?new D(dr(r,s?1:0)):this}ceil(e){if(e.isArray())return e.ceilInverse(this);const r=this.getValue(),s=e.getValue();if(typeof s=="string")return new d(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(r)||!Number.isFinite(s))return new d(f.NUM);const i=mr(r,s);return Number.isFinite(i)?new D(i):new d(f.NUM)}return typeof s=="boolean"?new D(mr(r,s?1:0)):this}_compareInfinity(e,r,s){let i=!1;switch(s){case y.EQUALS:i=e===r;break;case y.GREATER_THAN:i=e>r;break;case y.GREATER_THAN_OR_EQUAL:i=e>=r;break;case y.LESS_THAN:i=e<r;break;case y.LESS_THAN_OR_EQUAL:i=e<=r;break;case y.NOT_EQUAL:i=e!==r;break}return i}}class Y extends pe{constructor(e,r=!1){super(e);_(this,"_value");if(r){this._value=e;return}let s=e.toString();s.charAt(0)==='"'&&s.charAt(s.length-1)==='"'&&(s=s.slice(1,-1),s=s.replace(/""/g,'"')),this._value=s}getValue(){return this._value}isString(){return!0}concatenateFront(e){return e.isArray()?e.concatenateBack(this):new Y(this.concatenate(e.getValue(),J.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new Y(this.concatenate(e.getValue(),J.BACK))}compare(e,r){return e.isArray()?e.compare(this,Kr(r)):this.compareBy(e.getValue(),r)}compareBy(e,r){const s=this.getValue();let i=!1;if(typeof e=="string"){if(rs(e))return this._checkWildcard(e,r);switch(r){case y.EQUALS:i=s===e;break;case y.GREATER_THAN:i=s>e;break;case y.GREATER_THAN_OR_EQUAL:i=s>=e;break;case y.LESS_THAN:i=s<e;break;case y.LESS_THAN_OR_EQUAL:i=s<=e;break;case y.NOT_EQUAL:i=s!==e;break}}else if(typeof e=="number")switch(r){case y.NOT_EQUAL:case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:i=!0;break;case y.EQUALS:case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:i=!1;break}else if(typeof e=="boolean")switch(r){case y.EQUALS:case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:i=!1;break;case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:case y.NOT_EQUAL:i=!0;break}return new Q(i)}_checkWildcard(e,r){const s=this.getValue().toLocaleLowerCase(),i=ns(s,e,r);return new Q(i)}}function fs(t){return""}function ds(t=[]){const n=[];for(let e=0;e<t.length;e++){const r=t[e];n[e]==null&&(n[e]=[]);for(let s=0;s<r.length;s++){const i=r[s];n[e][s]=Re.create(i)}}return n}function ms(t=[]){const n=[];for(let e=0;e<t.length;e++){const r=t[e];n[e]==null&&(n[e]=[]);for(let s=0;s<r.length;s++){const i=r[s];i.isError()?n[e][s]=i.getErrorType():n[e][s]=i.getValue()}}return n}class G extends pe{constructor(e){var n=(...Ta)=>(super(...Ta),_(this,"_values",[]),_(this,"_rowCount",-1),_(this,"_columnCount",-1),_(this,"_unitId",""),_(this,"_sheetId",""),_(this,"_currentRow",-1),_(this,"_currentColumn",-1),_(this,"_sliceCache",new Map),_(this,"_flattenCache"),_(this,"_flattenPosition"),this);if(typeof e=="string")n(e);else{const r=fs();n(r)}this._values=this._formatValue(e)}dispose(){this._values.forEach(e=>{e.forEach(r=>{r.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,r){this._currentRow=e,this._currentColumn=r}setUnitId(e){this._unitId=e}getUnitId(){return this._unitId}setSheetId(e){this._sheetId=e}getSheetId(){return this._sheetId}getCurrentRow(){return this._currentRow}getCurrentColumn(){return this._currentColumn}getArrayValue(){return this._values}setArrayValue(e){this._clearCache(),this._values=e}isArray(){return!0}get(e,r){const s=this._values[e];if(s==null)return new ue(0);const i=s[r];return i==null?new ue(0):i}getRealValue(e,r){const s=this._values[e];if(s==null)return null;const i=s[r];return i==null?null:i}set(e,r,s){if(e>=this._rowCount||r>=this._columnCount)throw new Error("Exceeding array bounds.");this._clearCache(),this._values[e][r]=s}getRangePosition(){const r=this.getRowCount(),s=0,i=this.getColumnCount();return{startRow:0,endRow:r-1,startColumn:s,endColumn:i-1}}iterator(e){const{startRow:r,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),o=this.getArrayValue();for(let u=r;u<=s;u++)for(let l=i;l<=a;l++)if(e(o[u][l],u,l)===!1)return}iteratorReverse(e){const{startRow:r,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),o=this.getArrayValue();for(let u=s;u>=r;u--)for(let l=a;l>=i;l--)if(e(o[u][l],u,l)===!1)return}getLastTruePosition(){let e;return this.iteratorReverse((r,s,i)=>{if(r!=null&&r.isBoolean()&&r.getValue()===!0)return e={row:s,column:i},!1}),e}getFirstTruePosition(){let e;return this.iterator((r,s,i)=>{if(r!=null&&r.isBoolean()&&r.getValue()===!0)return e={row:s,column:i},!1}),e}getFirstCell(){const{startRow:e,startColumn:r}=this.getRangePosition();return this.get(e,r)}getLastCell(){const{endRow:e,endColumn:r}=this.getRangePosition();return this.get(e,r)}pick(e){const r=e.getRowCount(),s=e.getColumnCount();if(r!==this._rowCount||s!==this._columnCount)return this._createNewArray([[new ue(0)]],1,1);const i=[];i[0]=[];for(let a=0;a<r;a++)for(let o=0;o<s;o++){const u=e.get(a,o),l=this.get(a,o);u.isError()||u.getValue()===!0&&i[0].push(l)}return this._createNewArray(i,1,i[0].length)}flatten(){if(this._flattenCache!=null)return this._flattenCache;const e=[];e[0]=[];for(let s=0;s<this._rowCount;s++)for(let i=0;i<this._columnCount;i++){const a=this.get(s,i);e[0].push(a)}const r=this._createNewArray(e,1,e[0].length);return this._flattenCache=r,r}flattenPosition(){if(this._flattenPosition!=null)return this._flattenPosition;const e=[],r=[],s=[],i=[];let a=0;for(let u=0;u<this._rowCount;u++)for(let l=0;l<this._columnCount;l++){const c=this.get(u,l);if(c.isError()||c.isNull()){a++;continue}c.isString()?(e.push(c),s.push(a++)):(r.push(c),i.push(a++))}const o={stringArray:e,numberArray:r,stringPosition:s,numberPosition:i};return this._flattenPosition=o,o}slice(e,r){let s=0,i=this._rowCount,a=1,o=0,u=this._columnCount,l=1;if(e!=null&&(s=e[0]||0,i=e[1]||this._rowCount,a=e[2]||1),r!=null&&(o=r[0]||0,u=r[1]||this._columnCount,l=r[2]||1),s>=this._rowCount||o>=this._columnCount)return;const c=`${s}_${i}_${a}_${o}_${u}_${l}`,h=this._sliceCache.get(c);if(h!=null)return h;const m=[],p=this._values;let E=0,R=0;for(let L=s;L<i;L+=a){R=0,m[E]==null&&(m[E]=[]);for(let S=o;S<u;S+=l)m[E][R]=p[L][S],R++;E++}if(m.length===0||m[0].length===0)return;const C=a>1?-1:s+this._currentRow,w=l>1?-1:o+this._currentColumn,b=this._createNewArray(m,m.length,m[0].length,C,w);return this._sliceCache.set(c,b),b}sortByRow(e){const r=this._transposeArray(this._values);r.sort(this._sort(e)),this._clearCache(),this._values=this._transposeArray(r)}sortByColumn(e){this._clearCache(),this._values.sort(this._sort(e))}transpose(){const e=this._transposeArray(this._values),r=this._rowCount,s=this._columnCount;return this._createNewArray(e,s,r)}orderSearch(e,r=te.MIN,s=!1,i=!1){let a,o,u,l;const c=(h,m,p)=>{if(h==null)return!0;let E;if(i===!0?E=h.compare(e,y.EQUALS):E=h.isEqual(e),(E==null?void 0:E.getValue())===!0)return a=h,u={row:m,column:p},!1;r===te.MAX?h.isGreaterThan(e).getValue()===!0&&(o==null||h.minus(e).abs().isLessThanOrEqual(o.minus(e).abs()).getValue()===!0)&&(o=h,l={row:m,column:p}):r===te.MIN&&h.isLessThan(e).getValue()===!0&&(o==null||h.minus(e).abs().isLessThanOrEqual(o.minus(e).abs()).getValue()===!0)&&(o=h,l={row:m,column:p})};if(s){const h=this._values.length;if(this._values[0]==null)return;const m=this._values[0].length;for(let p=h-1;p>=0;p--)for(let E=m-1;E>=0;E--){const R=this._values[p][E];c(R,p,E)}}else this.iterator((h,m,p)=>{c(h,m,p)});if(a!=null)return u;if(o!=null)return l}binarySearch(e,r=be.MIN){if(e.isError())return;const{stringArray:s,stringPosition:i,numberArray:a,numberPosition:o}=this.flattenPosition();if(e.isString())return this._binarySearch(e,s,i,r);let u=this._binarySearch(e,a,o,r);return u==null&&(u=this._binarySearch(e,s,i,r)),u}_binarySearch(e,r,s,i=be.MIN){const a=ur(),o=e.getValue().toString();let u=0,l=r.length-1,c=null;for(;u<=l;){const h=Math.floor((u+l)/2),m=r[h];let p=0;if(m.isNull())p=1;else{const E=m.getValue();p=a(E.toString(),o)}if(p===0)return s[h];p===-1?(u=h+1,i===be.MIN&&(c=h)):(l=h-1,i===be.MAX&&(c=h))}if(c!=null)return s[c]}sum(){let e=new D(0);return this.iterator(r=>{if(r==null)return!0;if(r.isError())return e=r,!1;e=e.plus(r)}),e}max(){let e=new D(Number.NEGATIVE_INFINITY);return this.iterator(r=>{if(r==null)return!0;if(r.isError())return e=r,!1;if(r.isString()||r.isNull())return!0;e.isLessThan(r).getValue()&&(e=r)}),e}min(){let e=new D(Number.POSITIVE_INFINITY);return this.iterator(r=>{if(r==null)return!0;if(r.isError())return e=r,!1;if(r.isString()||r.isNull())return!0;e.isGreaterThan(r).getValue()&&(e=r)}),e}count(){let e=new D(0);return this.iterator(r=>{if(r==null||r.isError()||r.isString()||r.isNull())return!0;e=e.plusBy(1)}),e}countA(){let e=new D(0);return this.iterator(r=>{if(r==null||r.isNull())return!0;e=e.plusBy(1)}),e}countBlank(){let e=new D(0);return this.iterator(r=>{if(r!=null)return!0;e=e.plusBy(1)}),e}getNegative(){return new G("{0}").minus(this)}getReciprocal(){return new G("{1}").divided(this)}plus(e){return this._batchOperator(e,1)}minus(e){return this._batchOperator(e,0)}multiply(e){return this._batchOperator(e,2)}divided(e){return this._batchOperator(e,3)}compare(e,r){return this._batchOperator(e,4,r)}concatenateFront(e){return this._batchOperator(e,5)}concatenateBack(e){return this._batchOperator(e,6)}product(e,r){return this._batchOperator(e,7,r)}map(e){const r=(s,i,a)=>s.isError()?s:e(s,i,a);return this.mapValue(r)}mapValue(e){var a,o;const r=this._rowCount,s=this._columnCount,i=[];for(let u=0;u<r;u++){const l=[];for(let c=0;c<s;c++){const h=(o=(a=this._values)==null?void 0:a[u])==null?void 0:o[c];h?l[c]=e(h,u,c):l[c]=new d(f.VALUE)}i.push(l)}return this._createNewArray(i,r,s)}pow(e){return this._batchOperator(e,8)}powInverse(e){return this.map(r=>r.isError()?r:e.pow(r))}sqrt(){return this.map(e=>e.isError()?e:e.sqrt())}cbrt(){return this.map(e=>e.isError()?e:e.cbrt())}cos(){return this.map(e=>e.isError()?e:e.cos())}acos(){return this.map(e=>e.isError()?e:e.acos())}acosh(){return this.map(e=>e.isError()?e:e.acosh())}sin(){return this.map(e=>e.isError()?e:e.sin())}asin(){return this.map(e=>e.isError()?e:e.asin())}asinh(){return this.map(e=>e.isError()?e:e.asinh())}tan(){return this.map(e=>e.isError()?e:e.tan())}tanh(){return this.map(e=>e.isError()?e:e.tanh())}atan(){return this.map(e=>e.isError()?e:e.atan())}atanh(){return this.map(e=>e.isError()?e:e.atanh())}atan2(e){return this._batchOperator(e,12)}atan2Inverse(e){return this.map(r=>r.isError()?r:e.atan2(r))}mean(){const e=this.sum(),r=this.countA();return e.divided(r)}median(){const e=this.flattenPosition().numberArray,r=this._createNewArray([e],1,e.length),s=r.getColumnCount();if(s<=1)return r.get(0,0);if(r.sortByRow(0),s%2===0){const i=r.get(0,s/2),a=r.get(0,s/2-1);return i.plus(a).divided(new D(2,!0))}return r.get(0,(s-1)/2)}var(){const e=this.mean(),r=[];this.iterator((h,m,p)=>{(h==null||h.isError()||h.isString())&&(h=new D(0));let E=h.minus(e).pow(new D(2,!0));E.isError()&&(E=new D(0)),r[m]==null&&(r[m]=[]),r[m][p]=E});const{_rowCount:s,_columnCount:i,_unitId:a,_sheetId:o,_currentRow:u,_currentColumn:l}=this;return new G({calculateValueList:r,rowCount:s,columnCount:i,unitId:a,sheetId:o,row:u,column:l}).mean()}std(){const e=this.var();return e.isError()?e:e.sqrt()}log(){return this.map(e=>e.isError()?e:e.log())}log10(){return this.map(e=>e.isError()?e:e.log10())}exp(){return this.map(e=>e.isError()?e:e.exp())}abs(){return this.map(e=>e.isError()?e:e.abs())}round(e){return this._batchOperator(e,9)}roundInverse(e){return this.map(r=>r.isError()?r:e.round(r))}floor(e){return this._batchOperator(e,10)}floorInverse(e){return this.map(r=>r.isError()?r:e.floor(r))}ceil(e){return this._batchOperator(e,11)}ceilInverse(e){return this.map(r=>r.isError()?r:e.ceil(r))}toValue(){return ms(this._values)}_clearCache(){this._flattenCache=null,this._sliceCache.clear()}_sort(e){const r=ur();return(s,i)=>{const a=s[e],o=i[e];return a.isError()&&a.isError()?0:a.isError()?1:o.isError()?-1:r(a.getValue(),o.getValue())}}_transposeArray(e){const r=e.length,s=e[0].length,i=[];for(let a=0;a<s;a++){i[a]=[];for(let o=0;o<r;o++)i[a][o]=e[o][a]}return i}_batchOperator(e,r,s){const i=[];let a=this._rowCount,o=this._columnCount;if(e.isArray()){const l=e.getRowCount(),c=e.getColumnCount();if(a=Math.max(l,a),o=Math.max(c,o),l===1&&c===1){const h=e.getFirstCell();for(let m=0;m<o;m++)i.push(h)}else if(l===1&&this._columnCount>1){const h=e.getArrayValue();for(let m=0;m<o;m++)i.push(h[0][m])}else return this._batchOperatorArray(e,r,s)}else for(let l=0;l<o;l++)i.push(e);const u=[];for(let l=0;l<o;l++){const c=i[l];this._batchOperatorValue(c,l,u,r,s)}return this._createNewArray(u,a,o)}_batchOperatorValue(e,r,s,i,a){var p,E;const o=this._rowCount;let u=!1;const l=this.getUnitId(),c=this.getSheetId(),h=this.getCurrentRow(),m=this.getCurrentColumn();if(i===4&&(u=fe.canUseCache(l,c,r+m,h,h+o-1),u===!0)){if(a===y.EQUALS){const R=fe.getCellPositions(l,c,r+m,e.getValue());for(let C=0;C<o;C++)s[C]==null&&(s[C]=[]),R!=null&&R.includes(C+h)?s[C][r]=new Q(!0):s[C][r]=new Q(!1)}else{const R=fe.getCellValuePositions(l,c,r+m);if(R!=null){R.forEach((C,w)=>{let b;if(typeof w=="string"?b=new Y(w):typeof w=="number"?b=new D(w):typeof w=="boolean"&&(b=new Q(w)),b==null)return!0;b.compare(e,a).getValue()===!0&&C.forEach(S=>{S>=h&&S<=h+o-1&&(s[S-h]==null&&(s[S-h]=[]),s[S-h][r]=new Q(!0))})});for(let C=0;C<o;C++)s[C]==null&&(s[C]=[]),s[C][r]==null&&(s[C][r]=new Q(!1))}else for(let C=0;C<o;C++)s[C]==null&&(s[C]=[]),s[C][r]=new Q(!1)}return}for(let R=0;R<o;R++){const C=(E=(p=this._values)==null?void 0:p[R])==null?void 0:E[r];if(s[R]==null&&(s[R]=[]),C&&e)if(C.isError())s[R][r]=C;else if(e.isError())s[R][r]=new d(f.VALUE);else switch(i){case 1:s[R][r]=C.plus(e);break;case 0:s[R][r]=C.minus(e);break;case 2:s[R][r]=C.multiply(e);break;case 3:s[R][r]=C.divided(e);break;case 4:a?s[R][r]=C.compare(e,a):s[R][r]=new d(f.VALUE);break;case 5:s[R][r]=C.concatenateFront(e);break;case 6:s[R][r]=C.concatenateBack(e);break;case 7:a?s[R][r]=C.product(e,a):s[R][r]=new d(f.VALUE);break;case 8:s[R][r]=C.pow(e);break;case 9:s[R][r]=C.round(e);break;case 10:s[R][r]=C.floor(e);break;case 12:s[R][r]=C.atan2(e);break;case 11:s[R][r]=C.ceil(e);break}else s[R][r]=new d(f.NA);C!=null&&(C.isError()?fe.set(l,c,r+m,C.getErrorType(),R+h):C.isNull()?fe.set(l,c,r+m,null,R+h):fe.set(l,c,r+m,C.getValue(),R+h))}fe.setContinueBuildingCache(l,c,r+m,h,h+o-1)}_batchOperatorArray(e,r,s){var h,m,p,E,R,C,w,b,L,S,M,k;let i=e.getRowCount(),a=e.getColumnCount();i<this._rowCount&&(i=this._rowCount),a<this._columnCount&&(a=this._columnCount);const o=[],u=e.getArrayValue(),l=this._checkArrayCalculateType(this),c=this._checkArrayCalculateType(e);for(let j=0;j<i;j++){const v=[];for(let P=0;P<a;P++){let F;l===3?F=(m=(h=this._values)==null?void 0:h[0])==null?void 0:m[0]:l===1?F=(E=(p=this._values)==null?void 0:p[0])==null?void 0:E[P]:l===2?F=(C=(R=this._values)==null?void 0:R[j])==null?void 0:C[0]:F=(b=(w=this._values)==null?void 0:w[j])==null?void 0:b[P];let $;if(c===3?$=(L=u==null?void 0:u[0])==null?void 0:L[0]:c===1?$=(S=u==null?void 0:u[0])==null?void 0:S[P]:c===2?$=(M=u==null?void 0:u[j])==null?void 0:M[0]:$=(k=u==null?void 0:u[j])==null?void 0:k[P],F&&$)if(F.isError())v[P]=F;else if($.isError())v[P]=$;else switch(r){case 1:v[P]=F.plus($);break;case 0:v[P]=F.minus($);break;case 2:v[P]=F.multiply($);break;case 3:v[P]=F.divided($);break;case 4:s?v[P]=F.compare($,s):v[P]=new d(f.VALUE);break;case 5:v[P]=F.concatenateFront($);break;case 6:v[P]=F.concatenateBack($);break;case 7:s?v[P]=F.product($,s):v[P]=new d(f.VALUE);break;case 8:v[P]=F.pow($);break;case 9:v[P]=F.round($);break;case 12:v[P]=F.atan2($);break;case 10:v[P]=F.floor($);break;case 11:v[P]=F.ceil($);break}else v[P]=new d(f.NA)}o.push(v)}return this._createNewArray(o,i,a)}_checkArrayCalculateType(e){return e.getRowCount()===1&&e.getColumnCount()===1?3:e.getRowCount()===1?1:e.getColumnCount()===1?2:0}_formatValue(e){if(typeof e!="string")return e=e,this._rowCount=e.rowCount,this._columnCount=e.columnCount,this._unitId=e.unitId,this._sheetId=e.sheetId,this._currentRow=e.row,this._currentColumn=e.column,e.calculateValueList;e=e.slice(1,-1);const r=e.split(";"),s=r.length,i=[];let a=0;for(let o=0;o<s;o++){const l=r[o].split(","),c=l.length;a<c&&(a=c);const h=[];for(let m=0;m<c;m++){const p=l[m].trim();h.push(Re.create(p))}i.push(h)}return this._rowCount=s,this._columnCount=a,i}_createNewArray(e,r,s,i=-1,a=-1){(this._currentColumn===-1||this._currentRow===-1)&&(i=-1,a=-1);const o={calculateValueList:e,rowCount:r,columnCount:s,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:i,column:a};return new G(o)}}class Re{static create(n){if(n==null)return new ue(0);if(typeof n=="boolean")return new Q(n,!0);if(typeof n=="string"){const e=n.toLocaleUpperCase().trim();return Yt.has(e)?new d(e):e===Se.TRUE||e===Se.FALSE?new Q(e):g.isRealNum(n)?new D(n):new RegExp(Kn,"g").test(n.replace(/\n/g,"").replace(/\r/g,""))?new G(n.replace(/\n/g,"").replace(/\r/g,"")):new Y(n)}return typeof n=="number"?Number.isFinite(n)?new D(n,!0):new d(f.NUM):new d(f.NA)}}const gs=1e5,Qt=new Et(gs);class ke extends yt{constructor(e){super();_(this,"_forcedSheetId","");_(this,"_forcedSheetName","");_(this,"_defaultSheetId","");_(this,"_rangeData",{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1});_(this,"_unitData",{});_(this,"_defaultUnitId","");_(this,"_forcedUnitId","");_(this,"_runtimeData",{});_(this,"_arrayFormulaCellData",{});_(this,"_runtimeArrayFormulaCellData",{});_(this,"_runtimeFeatureCellData",{});_(this,"_refOffsetX",0);_(this,"_refOffsetY",0);this._token=e}dispose(){this._unitData={},this._runtimeData={}}isExceedRange(){const{startRow:e,endRow:r,startColumn:s,endColumn:i}=this.getRangePosition();return e<0||s<0||r>=this.getRowCount()||i>=this.getColumnCount()}setRefOffset(e=0,r=0){this._refOffsetX=e,this._refOffsetY=r}getRefOffset(){return{x:this._refOffsetX,y:this._refOffsetY}}getRangePosition(){let e=this._rangeData.startRow+this._refOffsetY,r=this._rangeData.endRow+this._refOffsetY,s=this._rangeData.startColumn+this._refOffsetX,i=this._rangeData.endColumn+this._refOffsetX;return isNaN(e)&&(e=0),isNaN(s)&&(s=0),isNaN(r)&&(r=this.getRowCount()-1),isNaN(i)&&(i=this.getColumnCount()-1),{startRow:e,endRow:r,startColumn:s,endColumn:i}}isReferenceObject(){return!0}iterator(e){const{startRow:r,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition();if(this._checkIfWorksheetMiss())return e(new d(f.VALUE),r,i);for(let o=r;o<=s;o++)for(let u=i;u<=a;u++){if(o<0||u<0)return e(new d(f.REF),o,u);const l=this.getCellData(o,u);let c=!1;if(l==null||g.isNullCell(l)){c=e(null,o,u);continue}const h=this.getCellValueObject(l);if(c=e(h,o,u),c===!1)return}}getFirstCell(){const{startRow:e,startColumn:r}=this.getRangePosition(),s=this.getCellData(e,r);return s?this.getCellValueObject(s):new D(0,!0)}getRangeData(){return this._rangeData}setRangeData(e){this._rangeData=e}getUnitId(){return this._forcedUnitId&&this._forcedUnitId.length>0?this._forcedUnitId:this._defaultUnitId}getSheetId(){return this._forcedSheetId&&this._forcedSheetId.length>0?this._forcedSheetId:this._defaultSheetId}setForcedUnitIdDirect(e){e.length>0&&(this._forcedUnitId=e)}getForcedUnitId(){return this._forcedUnitId}setForcedSheetId(e){var r;this._forcedSheetId=(r=e[this.getUnitId()])==null?void 0:r[this._forcedSheetName]}setForcedSheetIdDirect(e){this._forcedSheetId=e}getForcedSheetId(){return this._forcedSheetId}setForcedSheetName(e){e.length>0&&(this._forcedSheetName=e)}getForcedSheetName(){return this._forcedSheetName}setDefaultSheetId(e){this._defaultSheetId=e}getDefaultSheetId(){return this._defaultSheetId}setDefaultUnitId(e){this._defaultUnitId=e}getDefaultUnitId(){return this._defaultUnitId}getUnitData(){return this._unitData}setUnitData(e){this._unitData=e}getRuntimeData(){return this._runtimeData}setRuntimeData(e){this._runtimeData=e}getArrayFormulaCellData(){return this._arrayFormulaCellData}setArrayFormulaCellData(e){this._arrayFormulaCellData=e}getRuntimeArrayFormulaCellData(){return this._runtimeArrayFormulaCellData}setRuntimeArrayFormulaCellData(e){this._runtimeArrayFormulaCellData=e}getRuntimeFeatureCellData(){return this._runtimeFeatureCellData}setRuntimeFeatureCellData(e){this._runtimeFeatureCellData=e}getRowCount(){return this.getCurrentActiveSheetData().rowCount}getColumnCount(){return this.getCurrentActiveSheetData().columnCount}isCell(){return!1}isColumn(){return!1}isRow(){return!1}isRange(){return!1}isTable(){return!1}unionBy(e){return new d(f.REF)}unionRange(e,r){return{startRow:-1,startColumn:-1,endRow:-1,endColumn:-1}}getCellValueObject(e){const r=e.v||0;return Yt.has(r)?new d(r):e.t===g.CellValueType.NUMBER?new D(r):e.t===g.CellValueType.STRING||e.t===g.CellValueType.FORCE_STRING?new Y(r):e.t===g.CellValueType.BOOLEAN?new Q(r):Re.create(r)}getCellByRow(e){return this.getCellByPosition(e)}getCellByColumn(e){return this.getCellByPosition(void 0,e)}getCurrentActiveSheetData(){return this._unitData[this.getUnitId()][this.getSheetId()]}getCurrentRuntimeSheetData(){var e,r;return(r=(e=this._runtimeData)==null?void 0:e[this.getUnitId()])==null?void 0:r[this.getSheetId()]}getCurrentActiveArrayFormulaCellData(){var e,r;return(r=(e=this._arrayFormulaCellData)==null?void 0:e[this.getUnitId()])==null?void 0:r[this.getSheetId()]}getCurrentRuntimeActiveArrayFormulaCellData(){var e,r;return(r=(e=this._runtimeArrayFormulaCellData)==null?void 0:e[this.getUnitId()])==null?void 0:r[this.getSheetId()]}getCellData(e,r){const s=this.getCurrentActiveSheetData(),i=this.getCurrentRuntimeSheetData(),a=this.getCurrentActiveArrayFormulaCellData(),o=this.getCurrentRuntimeActiveArrayFormulaCellData();return(i==null?void 0:i.getValue(e,r))||(o==null?void 0:o.getValue(e,r))||this.getRuntimeFeatureCellValue(e,r)||(a==null?void 0:a.getValue(e,r))||(s==null?void 0:s.cellData.getValue(e,r))}getRuntimeFeatureCellValue(e,r){var i;const s=Object.keys(this._runtimeFeatureCellData);for(const a of s){const o=this._runtimeFeatureCellData[a],u=(i=o==null?void 0:o[this.getUnitId()])==null?void 0:i[this.getSheetId()];if(u==null)continue;const l=u.getValue(e,r);if(l!=null)return l}}getCellByPosition(e,r){e||(e=this._rangeData.startRow),r||(r=this._rangeData.startColumn);const s=this.getCellData(e,r);return s?this.getCellValueObject(s):new d(f.VALUE)}toArrayValueObject(e=!0){var E;const{startRow:r,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),o=`${this.getUnitId()}_${this.getSheetId()}_${r}_${s}_${i}_${a}`,u=Qt.get(o);if(u&&e)return u;const l=s-r+1,c=a-i+1;if(l<0||c<0)return this._getBlankArrayValueObject();const h=new Array(l);this.iterator((R,C,w)=>{const b=C-r,L=w-i;h[b]||(h[b]=new Array(c)),R==null&&(R=new ue(0)),h[b][L]=R});const m={calculateValueList:h,rowCount:h.length,columnCount:((E=h[0])==null?void 0:E.length)||0,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:r,column:i},p=new G(m);return e&&Qt.set(o,p),p}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 G(e)}}class Rs extends yt{constructor(n){super(),this._promise=n}isAsyncObject(){return!0}async getValue(){return this._promise}}class ps extends yt{constructor(n){super(),this._promiseList=n}isAsyncArrayObject(){return!0}async getValue(){var r;const n=[];for(let s=0;s<this._promiseList.length;s++){const i=this._promiseList[s];n[s]==null&&(n[s]=[]);for(let a=0;a<i.length;a++){const o=i[a];o.isAsyncObject()?n[s][a]=await o.getValue():n[s][a]=o}}const e={calculateValueList:n,rowCount:n.length,columnCount:((r=n[0])==null?void 0:r.length)||0,unitId:"",sheetId:"",row:0,column:0};return new G(e)}}class Ie extends ke{constructor(n,e,r){super(""),this.setRangeData(n),e&&this.setForcedSheetIdDirect(e),r&&this.setForcedUnitIdDirect(r)}isRange(){return!0}}const Rr=/[\[\]]/g;function pr(t,n){if(Rr.test(t)){const e=Number(t.replace(Rr,""));return n+e}return Number(t)-1}function Bt(t,n=0,e=0){t=t.toLocaleUpperCase();const r=t.split(/[RC]/),s=r[1],i=r[2],a=pr(s,n),o=pr(i,e);return{row:a,column:o,absoluteRefType:g.AbsoluteRefType.NONE}}function zr(t,n=0,e=0){const{refBody:r,sheetName:s,unitId:i}=Mr(t),a=r.indexOf(":");if(a===-1){const R=Bt(r,n,e),C=R.row,w=R.column,b=R.absoluteRefType;return{unitId:i,sheetName:s,range:{startRow:C,startColumn:w,endRow:C,endColumn:w,startAbsoluteRefType:b,endAbsoluteRefType:b}}}const o=r.substring(0,a),u=r.substring(a+1),l=Bt(o,n,e),c=Bt(u,n,e),h=l.row,m=l.column,p=c.row,E=c.column;return{unitId:i,sheetName:s,range:{startRow:h,startColumn:m,endRow:p,endColumn:E,startAbsoluteRefType:l.absoluteRefType,endAbsoluteRefType:c.absoluteRefType}}}function Es(t){const n=ze(t.startRow,t.startAbsoluteRefType,!0),e=ze(t.startColumn,t.startAbsoluteRefType,!1),r=ze(t.endRow,t.endAbsoluteRefType,!0),s=ze(t.endColumn,t.endAbsoluteRefType,!1);return n===r&&e===s?`R${n}C${e}`:`R${n}C${e}:R${r}C${s}`}function ze(t,n=g.AbsoluteRefType.ALL,e){switch(t+=1,n){case g.AbsoluteRefType.ALL:return`${t}`;case g.AbsoluteRefType.ROW:return e?`${t}`:`[${t}]`;case g.AbsoluteRefType.COLUMN:return e?`[${t}]`:`${t}`;case g.AbsoluteRefType.NONE:return`[${t}]`}}const qr=[];var _s=(t=>{})();class O extends g.Disposable{constructor(e){super();_(this,"_unitId");_(this,"_subUnitId");_(this,"_row",-1);_(this,"_column",-1);this._name=e}get name(){return this._name}get unitId(){return this._unitId}get subUnitId(){return this._subUnitId}get row(){return this._row}get column(){return this._column}isAsync(){return!1}isAddress(){return!1}isCustom(){return!1}setRefInfo(e,r,s,i){this._unitId=e,this._subUnitId=r,this._row=s,this._column=i}calculateCustom(...e){return null}calculate(...e){return new d(f.VALUE)}checkArrayType(e){return e.isReferenceObject()||e.isValueObject()&&e.isArray()}getIndexNumValue(e,r=1){if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())return e.getValue()===!1?new d(f.VALUE):r;if(e.isString()){const s=Number(e.getValue());return isNaN(s)?new d(f.REF):s}else if(e.isNumber())return e.getValue();return new d(f.VALUE)}getZeroOrOneByOneDefault(e){if(e==null)return 1;let r=1;if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())e.getValue()===!1&&(r=0);else{if(e.isString())return;e.isNumber()&&e.getValue()===0&&(r=0)}return r}binarySearch(e,r,s,i){const a=r.binarySearch(e,i);if(a==null)return new d(f.NA);let o;return s.getRowCount()===1?o=s.get(0,a):o=s.get(a,0),o.isNull()?new d(f.NA):o}equalSearch(e,r,s,i=!0){const a=s.pick(r.isEqual(e));let o;return i?o=a.getFirstCell():o=a.getLastCell(),o.isNull()?new d(f.NA):o}fuzzySearch(e,r,s,i=!0){const a=s.pick(r.compare(e,y.EQUALS));let o;return i?o=a.getFirstCell():o=a.getLastCell(),o.isNull()?new d(f.NA):o}orderSearch(e,r,s,i=te.MIN,a=!1){const o=r.orderSearch(e,i,a);if(o==null)return new d(f.NA);const u=s.get(o.row,o.column);return u.isNull()?new d(f.NA):u}binarySearchExpand(e,r,s,i=0,a){const o=r.binarySearch(e,a);return o==null?new d(f.NA):i===0?s.slice([o,o+1]):s.slice(void 0,[o,o+1])}equalSearchExpand(e,r,s,i=!0,a=0){const o=r.isEqual(e);let u;return i?u=o.getFirstTruePosition():u=o.getLastTruePosition(),u==null?new d(f.NA):a===0?s.slice([u.row,u.row+1]):s.slice(void 0,[u.column,u.column+1])}fuzzySearchExpand(e,r,s,i=!0,a=0){const o=r.compare(e,y.EQUALS);let u;return i?u=o.getFirstTruePosition():u=o.getLastTruePosition(),u==null?new d(f.NA):a===0?s.slice([u.row,u.row+1]):s.slice(void 0,[u.column,u.column+1])}orderSearchExpand(e,r,s,i=te.MIN,a=!1,o=0){const u=r.orderSearch(e,i,a);return u==null?new d(f.NA):o===0?s.slice([u.row,u.row+1]):s.slice(void 0,[u.column,u.column+1])}}const Zr=[];var Jr=(t=>(t.BETADIST="BETADIST",t.BETAINV="BETAINV",t.BINOMDIST="BINOMDIST",t.CHIDIST="CHIDIST",t.CHIINV="CHIINV",t.CHITEST="CHITEST",t.CONFIDENCE="CONFIDENCE",t.COVAR="COVAR",t.CRITBINOM="CRITBINOM",t.EXPONDIST="EXPONDIST",t.FDIST="FDIST",t.FINV="FINV",t.FTEST="FTEST",t.GAMMADIST="GAMMADIST",t.GAMMAINV="GAMMAINV",t.HYPGEOMDIST="HYPGEOMDIST",t.LOGINV="LOGINV",t.LOGNORMDIST="LOGNORMDIST",t.MODE="MODE",t.NEGBINOMDIST="NEGBINOMDIST",t.NORMDIST="NORMDIST",t.NORMINV="NORMINV",t.NORMSDIST="NORMSDIST",t.NORMSINV="NORMSINV",t.PERCENTILE="PERCENTILE",t.PERCENTRANK="PERCENTRANK",t.POISSON="POISSON",t.QUARTILE="QUARTILE",t.RANK="RANK",t.STDEV="STDEV",t.STDEVP="STDEVP",t.TDIST="TDIST",t.TINV="TINV",t.TTEST="TTEST",t.VAR="VAR",t.VARP="VARP",t.WEIBULL="WEIBULL",t.ZTEST="ZTEST",t))(Jr||{});const Nr=[];var en=(t=>(t.CUBEKPIMEMBER="CUBEKPIMEMBER",t.CUBEMEMBER="CUBEMEMBER",t.CUBEMEMBERPROPERTY="CUBEMEMBERPROPERTY",t.CUBERANKEDMEMBER="CUBERANKEDMEMBER",t.CUBESET="CUBESET",t.CUBESETCOUNT="CUBESETCOUNT",t.CUBEVALUE="CUBEVALUE",t))(en||{});const tn=[];var rn=(t=>(t.DAVERAGE="DAVERAGE",t.DCOUNT="DCOUNT",t.DCOUNTA="DCOUNTA",t.DGET="DGET",t.DMAX="DMAX",t.DMIN="DMIN",t.DPRODUCT="DPRODUCT",t.DSTDEV="DSTDEV",t.DSTDEVP="DSTDEVP",t.DSUM="DSUM",t.DVAR="DVAR",t.DVARP="DVARP",t))(rn||{});const nn=[];var sn=(t=>(t.DATE="DATE",t.DATEDIF="DATEDIF",t.DATEVALUE="DATEVALUE",t.DAY="DAY",t.DAYS="DAYS",t.DAYS360="DAYS360",t.EDATE="EDATE",t.EOMONTH="EOMONTH",t.HOUR="HOUR",t.ISOWEEKNUM="ISOWEEKNUM",t.MINUTE="MINUTE",t.MONTH="MONTH",t.NETWORKDAYS="NETWORKDAYS",t.NETWORKDAYS_INTL="NETWORKDAYS.INTL",t.NOW="NOW",t.SECOND="SECOND",t.TIME="TIME",t.TIMEVALUE="TIMEVALUE",t.TODAY="TODAY",t.WEEKDAY="WEEKDAY",t.WEEKNUM="WEEKNUM",t.WORKDAY="WORKDAY",t.WORKDAY_INTL="WORKDAY.INTL",t.YEAR="YEAR",t.YEARFRAC="YEARFRAC",t))(sn||{});const an=[];var on=(t=>(t.BESSELI="BESSELI",t.BESSELJ="BESSELJ",t.BESSELK="BESSELK",t.BESSELY="BESSELY",t.BIN2DEC="BIN2DEC",t.BIN2HEX="BIN2HEX",t.BIN2OCT="BIN2OCT",t.BITAND="BITAND",t.BITLSHIFT="BITLSHIFT",t.BITOR="BITOR",t.BITRSHIFT="BITRSHIFT",t.BITXOR="BITXOR",t.COMPLEX="COMPLEX",t.CONVERT="CONVERT",t.DEC2BIN="DEC2BIN",t.DEC2HEX="DEC2HEX",t.DEC2OCT="DEC2OCT",t.DELTA="DELTA",t.ERF="ERF",t.ERF_PRECISE="ERF.PRECISE",t.ERFC="ERFC",t.ERFC_PRECISE="ERFC.PRECISE",t.GESTEP="GESTEP",t.HEX2BIN="HEX2BIN",t.HEX2DEC="HEX2DEC",t.HEX2OCT="HEX2OCT",t.IMABS="IMABS",t.IMAGINARY="IMAGINARY",t.IMARGUMENT="IMARGUMENT",t.IMCONJUGATE="IMCONJUGATE",t.IMCOS="IMCOS",t.IMCOSH="IMCOSH",t.IMCOT="IMCOT",t.IMCSC="IMCSC",t.IMCSCH="IMCSCH",t.IMDIV="IMDIV",t.IMEXP="IMEXP",t.IMLN="IMLN",t.IMLOG10="IMLOG10",t.IMLOG2="IMLOG2",t.IMPOWER="IMPOWER",t.IMPRODUCT="IMPRODUCT",t.IMREAL="IMREAL",t.IMSEC="IMSEC",t.IMSECH="IMSECH",t.IMSIN="IMSIN",t.IMSINH="IMSINH",t.IMSQRT="IMSQRT",t.IMSUB="IMSUB",t.IMSUM="IMSUM",t.IMTAN="IMTAN",t.OCT2BIN="OCT2BIN",t.OCT2DEC="OCT2DEC",t.OCT2HEX="OCT2HEX",t))(on||{});const un=[];var ln=(t=>(t.ACCRINT="ACCRINT",t.ACCRINTM="ACCRINTM",t.AMORDEGRC="AMORDEGRC",t.AMORLINC="AMORLINC",t.COUPDAYBS="COUPDAYBS",t.COUPDAYS="COUPDAYS",t.COUPDAYSNC="COUPDAYSNC",t.COUPNCD="COUPNCD",t.COUPNUM="COUPNUM",t.COUPPCD="COUPPCD",t.CUMIPMT="CUMIPMT",t.CUMPRINC="CUMPRINC",t.DB="DB",t.DDB="DDB",t.DISC="DISC",t.DOLLARDE="DOLLARDE",t.DOLLARFR="DOLLARFR",t.DURATION="DURATION",t.EFFECT="EFFECT",t.FV="FV",t.FVSCHEDULE="FVSCHEDULE",t.INTRATE="INTRATE",t.IPMT="IPMT",t.IRR="IRR",t.ISPMT="ISPMT",t.MDURATION="MDURATION",t.MIRR="MIRR",t.NOMINAL="NOMINAL",t.NPER="NPER",t.NPV="NPV",t.ODDFPRICE="ODDFPRICE",t.ODDFYIELD="ODDFYIELD",t.ODDLPRICE="ODDLPRICE",t.ODDLYIELD="ODDLYIELD",t.PDURATION="PDURATION",t.PMT="PMT",t.PPMT="PPMT",t.PRICE="PRICE",t.PRICEDISC="PRICEDISC",t.PRICEMAT="PRICEMAT",t.PV="PV",t.RATE="RATE",t.RECEIVED="RECEIVED",t.RRI="RRI",t.SLN="SLN",t.SYD="SYD",t.TBILLEQ="TBILLEQ",t.TBILLPRICE="TBILLPRICE",t.TBILLYIELD="TBILLYIELD",t.VDB="VDB",t.XIRR="XIRR",t.XNPV="XNPV",t.YIELD="YIELD",t.YIELDDISC="YIELDDISC",t.YIELDMAT="YIELDMAT",t))(ln||{}),nr=(t=>(t.CELL="CELL",t.ERROR_TYPE="ERROR.TYPE",t.INFO="INFO",t.ISBLANK="ISBLANK",t.ISERR="ISERR",t.ISERROR="ISERROR",t.ISEVEN="ISEVEN",t.ISFORMULA="ISFORMULA",t.ISLOGICAL="ISLOGICAL",t.ISNA="ISNA",t.ISNONTEXT="ISNONTEXT",t.ISNUMBER="ISNUMBER",t.ISODD="ISODD",t.ISOMITTED="ISOMITTED",t.ISREF="ISREF",t.ISTEXT="ISTEXT",t.N="N",t.NA="NA",t.SHEET="SHEET",t.SHEETS="SHEETS",t.TYPE="TYPE",t))(nr||{});class Cs extends O{calculate(n){return n.isNull()?new Q(!0):n.isArray()?n.map(e=>e.isNull()?new Q(!0):new Q(!1)):new Q(!1)}}const cn=[[Cs,nr.ISBLANK]];class Ds extends O{calculate(...n){if(n.length===0)return new d(f.NA);let e=!0,r=!0,s=null;for(const i of n){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(),r=!1)}),s)return s}else(i.isBoolean()||i.isNumber())&&(e=e&&!!i.getValue(),r=!1)}return r?new d(f.VALUE):new Q(e)}}var we=(t=>(t.AND="AND",t.BYCOL="BYCOL",t.BYROW="BYROW",t.FALSE="FALSE",t.IF="IF",t.IFERROR="IFERROR",t.IFNA="IFNA",t.IFS="IFS",t.LAMBDA="LAMBDA",t.LET="LET",t.MAKEARRAY="MAKEARRAY",t.MAP="MAP",t.NOT="NOT",t.OR="OR",t.REDUCE="REDUCE",t.SCAN="SCAN",t.SWITCH="SWITCH",t.TRUE="TRUE",t.XOR="XOR",t))(we||{});function ne(t,n,e,r){const s=[];if(e.isArray()){const i=e.getRowCount(),a=e.getColumnCount();if(i===1&&a===1){const o=e.getFirstCell();for(let u=0;u<t;u++){const l=[];for(let c=0;c<n;c++)l.push(o);s.push(l)}}else if(i===1&&a>1)for(let o=0;o<t;o++){const u=[];for(let l=0;l<n;l++){const c=e.getRealValue(0,l)||(r!=null?r:new ue(0));u.push(c)}s.push(u)}else if(a===1&&i>1)for(let o=0;o<t;o++){const u=[];for(let l=0;l<n;l++){const c=e.getRealValue(o,0)||(r!=null?r:new ue(0));u.push(c)}s.push(u)}else for(let o=0;o<t;o++){const u=[];for(let l=0;l<n;l++){const c=e.getRealValue(o,l)||(r!=null?r:new ue(0));u.push(c)}s.push(u)}}else for(let i=0;i<t;i++){const a=[];for(let o=0;o<n;o++)a.push(e);s.push(a)}return ws(s,t,n)}function ws(t,n,e){const r={calculateValueList:t,rowCount:n,columnCount:e,unitId:"",sheetId:"",row:-1,column:-1};return new G(r)}class ys extends O{calculate(n,e,r=new Q(!1)){if(n.isError()||e.isError())return new d(f.NA);if(n=this._getSingleValueObject(n),!n.isArray())return n.getValue()?e:r;const s=Math.max(n.isArray()?n.getRowCount():1,e.isArray()?e.getRowCount():1,r.isArray()?r.getRowCount():1),i=Math.max(n.isArray()?n.getColumnCount():1,e.isArray()?e.getColumnCount():1,r.isArray()?r.getColumnCount():1),a=ne(s,i,n),o=ne(s,i,e,new d(f.NA)),u=ne(s,i,r,new d(f.NA));return a.map((l,c,h)=>{if(l.isNull())return new d(f.NA);{const m=o.get(c,h),p=u.get(c,h);return this._calculateSingleCell(l,m,p)}})}_getSingleValueObject(n){return n.isArray()&&n.getRowCount()===1&&n.getColumnCount()===1?n.getFirstCell():n}_calculateSingleCell(n,e,r){return n.isNull()?new d(f.NA):n.getValue()?e.isNull()?new d(f.NA):e:r.isNull()?new d(f.NA):r}}class bs extends O{calculate(n,e){if(!n.isArray())return n.isError()?e:n;const r=Math.max(n.isArray()?n.getRowCount():1,e.isArray()?e.getRowCount():1),s=Math.max(n.isArray()?n.getColumnCount():1,e.isArray()?e.getColumnCount():1),i=ne(r,s,n),a=ne(r,s,e);return i.iterator((o,u,l)=>{o!=null&&o.isError()&&i.set(u,l,a.get(u,l))}),i}}class Ls extends O{calculate(...n){return new d(f.VALUE)}}class Ss extends O{calculate(...n){if(n.length!==3)return new d(f.VALUE);const e=this.getIndexNumValue(n[0]);if(typeof e!="number")return e;const r=this.getIndexNumValue(n[1]);if(typeof r!="number")return r;if(!(n[2].isValueObject()&&n[2].isLambda()))return new d(f.VALUE);const s=n[2],i=[];for(let a=0;a<e;a++){i[a]==null&&(i[a]=[]);for(let o=0;o<r;o++){const u=s.execute(new D(a+1),new D(o+1));i[a][o]=u}}return new ps(i)}isAsync(){return!0}}const hn=[[Ds,we.AND],[Ls,we.LAMBDA],[Ss,we.MAKEARRAY],[ys,we.IF],[bs,we.IFERROR]];class Ps extends O{calculate(n,e,r,s,i){if(n.isError()||e.isError()||r&&r.isError()||s&&s.isError()||i&&i.isError())return new d(f.VALUE);const a=Number(n.getValue())-1,o=Number(e.getValue())-1;if(Number.isNaN(a)||Number.isNaN(o))return new d(f.VALUE);const u=r?xs(r.getValue()):g.AbsoluteRefType.ALL,l=this.getZeroOrOneByOneDefault(s),c=i?`${i.getValue()}`:"",h=ot(c)?`'${c}'`:c,m={startRow:a,startColumn:o,endRow:a,endColumn:o,startAbsoluteRefType:u,endAbsoluteRefType:u},p=s&&!l?Es(m):Le(m);return new Y(h!==""?`${h}!${p}`:p)}}function xs(t){switch(t){case 1:return g.AbsoluteRefType.ALL;case 2:return g.AbsoluteRefType.ROW;case 3:return g.AbsoluteRefType.COLUMN;case 4:return g.AbsoluteRefType.NONE;default:return g.AbsoluteRefType.ALL}}var oe=(t=>(t.ADDRESS="ADDRESS",t.AREAS="AREAS",t.CHOOSE="CHOOSE",t.CHOOSECOLS="CHOOSECOLS",t.CHOOSEROWS="CHOOSEROWS",t.COLUMN="COLUMN",t.COLUMNS="COLUMNS",t.DROP="DROP",t.EXPAND="EXPAND",t.FILTER="FILTER",t.FORMULATEXT="FORMULATEXT",t.GETPIVOTDATA="GETPIVOTDATA",t.HLOOKUP="HLOOKUP",t.HSTACK="HSTACK",t.HYPERLINK="HYPERLINK",t.IMAGE="IMAGE",t.INDEX="INDEX",t.INDIRECT="INDIRECT",t.LOOKUP="LOOKUP",t.MATCH="MATCH",t.OFFSET="OFFSET",t.ROW="ROW",t.ROWS="ROWS",t.RTD="RTD",t.SORT="SORT",t.SORTBY="SORTBY",t.TAKE="TAKE",t.TOCOL="TOCOL",t.TOROW="TOROW",t.TRANSPOSE="TRANSPOSE",t.UNIQUE="UNIQUE",t.VLOOKUP="VLOOKUP",t.VSTACK="VSTACK",t.WRAPCOLS="WRAPCOLS",t.WRAPROWS="WRAPROWS",t.XLOOKUP="XLOOKUP",t.XMATCH="XMATCH",t))(oe||{});class As extends O{calculate(n,e,r,s){if(n.isError())return n;if(e.isError())return new d(f.REF);if(!e.isArray())return new d(f.VALUE);if(r.isError())return new d(f.NA);if(s!=null&&s.isError())return new d(f.NA);const i=this.getZeroOrOneByOneDefault(s);if(i==null)return new d(f.VALUE);const a=this.getIndexNumValue(r);if(a instanceof d)return a;const o=e.slice([0,1]),u=e.slice([a-1,a]);return o==null||u==null?new d(f.VALUE):n.isArray()?n.map(l=>this._handleSingleObject(l,o,u,i)):this._handleSingleObject(n,o,u,i)}_handleSingleObject(n,e,r,s){return s===0?this.equalSearch(n,e,r):this.binarySearch(n,e,r)}}class fn extends ke{constructor(n){super(n);const e=Fe(n);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName),this.setRangeData(e.range)}isCell(){return!0}unionBy(n){if(!n.isCell())return new d(f.REF);const e=n,r=this.unionRange(this.getRangeData(),e.getRangeData());return this._createRange(r)}unionRange(n,e){const r=n.startRow,s=n.startColumn,i=e.startRow,a=e.startColumn,o={startRow:-1,startColumn:-1,endRow:-1,endColumn:-1};return r>i?(o.startRow=i,o.endRow=r):(o.startRow=r,o.endRow=i),s>a?(o.startColumn=a,o.endColumn=s):(o.startColumn=s,o.endColumn=a),o}_createRange(n){const e=new Ie(n,this.getForcedSheetId(),this.getForcedUnitId());e.setUnitData(this.getUnitData()),e.setDefaultSheetId(this.getDefaultSheetId()),e.setDefaultUnitId(this.getDefaultUnitId()),e.setRuntimeData(this.getRuntimeData()),e.setArrayFormulaCellData(this.getArrayFormulaCellData()),e.setRuntimeArrayFormulaCellData(this.getRuntimeArrayFormulaCellData()),e.setRuntimeFeatureCellData(this.getRuntimeFeatureCellData());const{x:r,y:s}=this.getRefOffset();e.setRefOffset(r,s);const i=this.getForcedSheetId();e.setForcedSheetName(this.getForcedSheetName()),i!=null&&e.setForcedSheetIdDirect(i);const a=this.getForcedUnitId();return a&&e.setForcedUnitIdDirect(a),e}}class dn extends ke{constructor(n){super(n);const e=Fe(n);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const r={startColumn:e.range.startColumn,startRow:NaN,endColumn:-1,endRow:NaN};this.setRangeData(r)}isColumn(){return!0}unionBy(n){if(!n.isColumn())return new d(f.REF);const e=n;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return new d(f.REF);const r=this.getRangeData(),s=e.getRangeData().startColumn,i=r.startColumn;return s>i?r.endColumn=s:(r.startColumn=s,r.endColumn=i),this}}class mn extends ke{constructor(n){super(n);const e=Fe(n);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const r={startColumn:NaN,startRow:e.range.startRow,endColumn:NaN,endRow:-1};this.setRangeData(r)}isRow(){return!0}unionBy(n){if(!n.isRow())return new d(f.REF);const e=n;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return new d(f.REF);const r=this.getRangeData(),s=e.getRangeData().startRow,i=r.startRow;return s>i?r.endRow=s:(r.startRow=s,r.endRow=i),this}}class Vs extends O{calculate(n,e){let r=this.getZeroOrOneByOneDefault(e);if(r==null&&(r=1),n.isError())return new d(f.NA);if(n.isArray()){const c=n;if(c.getRowCount()===1&&c.getColumnCount()===1)n=c.getFirstCell();else return c.map(()=>new d(f.VALUE))}if(!n.isString())return new d(f.REF);const s=n.getValue();if(r===0){const c=zr(s),{range:h,sheetName:m,unitId:p}=c,E=new Ie(h);return E.setForcedUnitIdDirect(p),E.setForcedSheetName(m),this._setDefault(E)}if(new RegExp(_t).test(s))return this._setDefault(new fn(s));if(new RegExp($r).test(s))return this._setDefault(new mn(s));if(new RegExp(kr).test(s))return this._setDefault(new dn(s));const i=Fe(s),{range:a,sheetName:o,unitId:u}=i,l=new Ie(a);return l.setForcedUnitIdDirect(u),l.setForcedSheetName(o),this._setDefault(l)}_setDefault(n){return this.unitId==null||this.subUnitId==null?new d(f.REF):(n.setDefaultUnitId(this.unitId),n.setDefaultSheetId(this.subUnitId),n)}}class vs extends O{calculate(n,e,r){return n.isError()?n:e.isError()?new d(f.REF):e.isArray()?r!=null&&r.isError()?r:e.getColumnCount()===1||e.getRowCount()===1?r!=null&&!r.isArray()?new d(f.REF):this._handleVector(n,e,r):this._handleArray(n,e):new d(f.VALUE)}_handleVector(n,e,r){if(r==null)r=e;else if(r.getRowCount()!==e.getRowCount()||r.getColumnCount()!==e.getColumnCount())return new d(f.REF);return n.isArray()?n.map(s=>this.binarySearch(s,e,r)):this.binarySearch(n,e,r)}_handleArray(n,e){const r=e.getRowCount(),s=e.getColumnCount();let i,a;return s>r?(i=e.slice([0,1]),a=e.slice([r-1,r])):(i=e.slice(void 0,[0,1]),a=e.slice(void 0,[s-1,s])),i==null||a==null?new d(f.VALUE):n.isArray()?n.map(o=>this.binarySearch(o,i,a)):this.binarySearch(n,i,a)}}class Bs extends O{calculate(n,e,r,s,i){var v,P;if(!n.isArray())return new d(f.VALUE);const a=n.getCurrentRow(),o=n.getCurrentColumn(),u=this.getIndexNumValue(e),l=this.getIndexNumValue(r);if(typeof u!="number"||typeof l!="number")return new d(f.VALUE);const c=a+u,h=o+l;if(c<0||h<0||c>1048576||h>16384)return new d(f.REF);const m=(v=s&&this.getIndexNumValue(s))!=null?v:1,p=(P=i&&this.getIndexNumValue(i))!=null?P:1;if(typeof m!="number"||typeof p!="number")return new d(f.VALUE);if(m===0||p===0)return new d(f.REF);const E=m>0?c+m-1:c+m+1,R=p>0?h+p-1:h+p+1;if(E<0||R<0||E>1048576||R>16384)return new d(f.REF);const C=c<E?c:E,w=h<R?h:R,b=c>E?c:E,L=h>R?h:R,S={startRow:C,startColumn:w,endRow:b,endColumn:L},M=n.getUnitId(),k=n.getSheetId(),j=new Ie(S,k,M);return this._setDefault(j)}_setDefault(n){return this.unitId==null||this.subUnitId==null?new d(f.REF):(n.setDefaultUnitId(this.unitId),n.setDefaultSheetId(this.subUnitId),n)}}class Os extends O{calculate(n,e,r,s){if(n.isError())return n;if(e.isError())return new d(f.REF);if(!e.isArray())return new d(f.VALUE);if(r.isError())return new d(f.NA);if(s!=null&&s.isError())return new d(f.NA);const i=this.getZeroOrOneByOneDefault(s);if(i==null)return new d(f.VALUE);const a=this.getIndexNumValue(r);if(a instanceof d)return a;const o=e.slice(void 0,[0,1]),u=e.slice(void 0,[a-1,a]);return o==null||u==null?new d(f.VALUE):n.isArray()?n.map(l=>this._handleSingleObject(l,o,u,i)):this._handleSingleObject(n,o,u,i)}_handleSingleObject(n,e,r,s){return s===0?this.equalSearch(n,e,r):this.binarySearch(n,e,r)}}class Us extends O{calculate(n,e,r,s,i,a){if(n.isError())return n;if(e.isError())return new d(f.REF);if(!e.isArray())return new d(f.VALUE);const o=e.getRowCount(),u=e.getColumnCount();if(o!==1&&u!==1)return new d(f.VALUE);if(r.isError())return new d(f.REF);if(!r.isArray())return new d(f.VALUE);const l=r.getRowCount(),c=r.getColumnCount();if(o!==l&&u!==c)return new d(f.VALUE);if(s!=null&&s.isError())return new d(f.NA);if(i!=null&&i.isError())return new d(f.NA);if(a!=null&&a.isError())return new d(f.NA);s==null&&(s=new d(f.NA));const h=this.getIndexNumValue(i||new D(0));if(h instanceof d)return h;const m=this.getIndexNumValue(a||new D(1));if(m instanceof d)return m;if(n.isArray()){let R;return o===1?R=r.slice([0,1]):R=r.slice(void 0,[0,1]),R==null?new d(f.NA):n.map(C=>{const w=this._handleSingleObject(C,e,R,h,m);return w.isError()?s:w})}if(u===c&&o===l){const R=this._handleSingleObject(n,e,r,h,m);return R.isError()?s:R}let p=0;u===c&&(p=1);const E=this._handleExpandObject(n,e,r,h,m,p);return E==null?new d(f.NA):E}_handleExpandObject(n,e,r,s,i,a=0){return(i===2||i===-2)&&s!==2?this.binarySearchExpand(n,e,r,a,this._getSearchModeValue(i)):s===2?this.fuzzySearchExpand(n,e,r,i!==-1,a):s===-1||s===1?this.orderSearchExpand(n,e,r,s===1?te.MAX:te.MIN,i===-1,a):this.equalSearchExpand(n,e,r,i!==-1,a)}_handleSingleObject(n,e,r,s,i){return(i===2||i===-2)&&s!==2?this.binarySearch(n,e,r,this._getSearchModeValue(i)):s===2?this.fuzzySearch(n,e,r,i!==-1):s===-1||s===1?this.orderSearch(n,e,r,s===1?te.MAX:te.MIN,i===-1):this.equalSearch(n,e,r,i!==-1)}_getSearchModeValue(n){return n===-2?be.MAX:be.MIN}}const gn=[[Ps,oe.ADDRESS],[Vs,oe.INDIRECT],[Bs,oe.OFFSET],[Os,oe.VLOOKUP],[vs,oe.LOOKUP],[As,oe.HLOOKUP],[Us,oe.XLOOKUP]];class Fs extends O{calculate(n){return n.isError()?new d(f.VALUE):(n.isReferenceObject()&&(n=n.toArrayValueObject()),n.abs())}}class Ms extends O{calculate(n){return n.isError()?new d(f.VALUE):(n.isReferenceObject()&&(n=n.toArrayValueObject()),n.acos())}}class $s extends O{calculate(n){return n.isError()?new d(f.VALUE):(n.isReferenceObject()&&(n=n.toArrayValueObject()),n.acosh())}}class ks extends O{calculate(n){return n.isError()?new d(f.VALUE):(n.isReferenceObject()&&(n=n.toArrayValueObject()),n.isArray()?n.map(e=>e.isError()?e:Er(e)):Er(n))}}function Er(t){let n=t.getValue();if(t.isBoolean()&&(n=n?1:0),!Number.isFinite(n))return new d(f.VALUE);const e=Math.atan(1/Number(n));return Number.isNaN(e)?new d(f.VALUE):new D(e)}var Z=(t=>(t.ABS="ABS",t.ACOS="ACOS",t.ACOSH="ACOSH",t.ACOT="ACOT",t.ACOTH="ACOTH",t.AGGREGATE="AGGREGATE",t.ARABIC="ARABIC",t.ASIN="ASIN",t.ASINH="ASINH",t.ATAN="ATAN",t.ATAN2="ATAN2",t.ATANH="ATANH",t.BASE="BASE",t.CEILING="CEILING",t.CEILING_MATH="CEILING.MATH",t.CEILING_PRECISE="CEILING.PRECISE",t.COMBIN="COMBIN",t.COMBINA="COMBINA",t.COS="COS",t.COSH="COSH",t.COT="COT",t.COTH="COTH",t.CSC="CSC",t.CSCH="CSCH",t.DECIMAL="DECIMAL",t.DEGREES="DEGREES",t.EVEN="EVEN",t.EXP="EXP",t.FACT="FACT",t.FACTDOUBLE="FACTDOUBLE",t.FLOOR="FLOOR",t.FLOOR_MATH="FLOOR.MATH",t.FLOOR_PRECISE="FLOOR.PRECISE",t.GCD="GCD",t.INT="INT",t.ISO_CEILING="ISO.CEILING",t.LCM="LCM",t.LET="LET",t.LN="LN",t.LOG="LOG",t.LOG10="LOG10",t.MDETERM="MDETERM",t.MINVERSE="MINVERSE",t.MMULT="MMULT",t.MOD="MOD",t.MROUND="MROUND",t.MULTINOMIAL="MULTINOMIAL",t.MUNIT="MUNIT",t.ODD="ODD",t.PI="PI",t.POWER="POWER",t.PRODUCT="PRODUCT",t.QUOTIENT="QUOTIENT",t.RADIANS="RADIANS",t.RAND="RAND",t.RANDARRAY="RANDARRAY",t.RANDBETWEEN="RANDBETWEEN",t.ROMAN="ROMAN",t.ROUND="ROUND",t.ROUNDDOWN="ROUNDDOWN",t.ROUNDUP="ROUNDUP",t.SEC="SEC",t.SECH="SECH",t.SERIESSUM="SERIESSUM",t.SEQUENCE="SEQUENCE",t.SIGN="SIGN",t.SIN="SIN",t.SINH="SINH",t.SQRT="SQRT",t.SQRTPI="SQRTPI",t.SUBTOTAL="SUBTOTAL",t.SUM="SUM",t.SUMIF="SUMIF",t.SUMIFS="SUMIFS",t.SUMPRODUCT="SUMPRODUCT",t.SUMSQ="SUMSQ",t.SUMX2MY2="SUMX2MY2",t.SUMX2PY2="SUMX2PY2",t.SUMXMY2="SUMXMY2",t.TAN="TAN",t.TANH="TANH",t.TRUNC="TRUNC",t))(Z||{});class Qs extends O{calculate(n,e){return new d(f.VALUE)}}class js extends O{calculate(...n){let e=new D(0);for(let r=0;r<n.length;r++){let s=n[r];if(s.isError())return s;if(s.isString())return new d(f.VALUE);if(e.isError())return e;s.isArray()&&(s=s.sum()),e=e.plus(s)}return e}}function Ts(t){const n=[y.EQUALS,y.NOT_EQUAL,y.GREATER_THAN_OR_EQUAL,y.GREATER_THAN,y.LESS_THAN_OR_EQUAL,y.LESS_THAN];for(const e of n)if(t.startsWith(e)){const r=t.substring(e.length);return[e,Re.create(r)]}return[y.EQUALS,Re.create(t)]}function Rn(t,n,e){if(!e)if(n.isString()){const r=`${n.getValue()}`,[s,i]=Ts(r);e=s,n=i}else e=y.EQUALS;return t.compare(n,e)}function Hs(t,n){const e=Math.max(t.isArray()?t.getRowCount():1,n.isArray()?n.getRowCount():1),r=Math.max(t.isArray()?t.getColumnCount():1,n.isArray()?n.getColumnCount():1),s=ne(e,r,t),i=ne(e,r,n);return s.mapValue((a,o,u)=>{const l=i.get(o,u);return a!=null&&a.isError()?a:l!=null&&l.isError()?l:a!=null&&a.isBoolean()&&(l!=null&&l.isBoolean())?new Q(a.getValue()&&l.getValue()):new Q(!1)})}class Ys extends O{calculate(n,e,r){return n.isError()||e.isError()||r!=null&&r.isError()?new d(f.NA):!n.isArray()||r&&!r.isArray()?new d(f.VALUE):e.isArray()?e.map(s=>this._handleSingleObject(n,s,r)):this._handleSingleObject(n,e,r)}_handleSingleObject(n,e,r){const s=Rn(n,e),i=r?r.slice([0,n.getRowCount()],[0,n.getColumnCount()]):n;return i?i.pick(s).sum():new d(f.VALUE)}}class Ws extends O{calculate(n,...e){if(n.isError())return new d(f.NA);if(!n.isArray())return new d(f.VALUE);if(e.length<2||e.length%2!==0)return new d(f.VALUE);if(e.some((c,h)=>h%2===0&&!c.isArray()))return new d(f.VALUE);const r=n.getRowCount(),s=n.getColumnCount();let i=0,a=0;e.forEach((c,h)=>{if(h%2===1)if(c.isArray()){const m=c;i=Math.max(i,m.getRowCount()),a=Math.max(a,m.getColumnCount())}else i=Math.max(i,1),a=Math.max(a,1)});const o=[];for(let c=0;c<e.length;c++){if(c%2===1)continue;const h=e[c],m=h.getRowCount(),p=h.getColumnCount();if(m!==r||p!==s)return ne(i,a,new d(f.NA));const E=e[c+1];ne(i,a,E,new d(f.NA)).iterator((C,w,b)=>{if(!C)return;const L=Rn(h,C);if(o[w]===void 0&&(o[w]=[]),o[w][b]===void 0){o[w][b]=L;return}o[w][b]=Hs(o[w][b],L)})}const u=o.map(c=>c.map(h=>n.pick(h).sum())),l={calculateValueList:u,rowCount:u.length,columnCount:u[0].length,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return new G(l)}}const pn=[[Fs,Z.ABS],[Ms,Z.ACOS],[$s,Z.ACOSH],[ks,Z.ACOT],[js,Z.SUM],[Ys,Z.SUMIF],[Ws,Z.SUMIFS],[Qs,Z.POWER]];class Is extends O{constructor(){super(...arguments);_(this,"_compareType",y.EQUALS)}setCompareType(e){this._compareType=e}calculate(e,r){return e.isError()||r.isError()?e:e.compare(r,this._compareType)}}class Xs extends O{calculate(n,e){return n.isError()||e.isError()?n:!e.isArray()&&e.getValue()===0?new d(f.DIV_BY_ZERO):n.divided(e)}}var I=(t=>(t.COMPARE="COMPARE",t.DIVIDED="DIVIDED",t.MINUS="MINUS",t.MULTIPLY="MULTIPLY",t.PLUS="PLUS",t.UNION="UNION",t))(I||{});class Gs extends O{calculate(n,e){return n.isError()||e.isError()?n:n.minus(e)}}class Ks extends O{calculate(n,e){return n.isError()?n:e.isError()?e:n.multiply(e)}}class zs extends O{calculate(n,e){return n.isError()?n:e.isError()?e:n.plus(e)}}const En=[[Is,I.COMPARE],[Xs,I.DIVIDED],[Gs,I.MINUS],[Ks,I.MULTIPLY],[zs,I.PLUS]];class qs extends O{calculate(...n){let e=new D(0),r=new D(0);for(let s=0;s<n.length;s++){const i=n[s];if(i.isError())return i;if(e.isError())return e;i.isArray()?(e=e.plus(i.sum()),r=r.plus(i.count())):i.isNull()||(r=r.plus(new D(1)))}return e.divided(r)}}class Zs extends O{calculate(...n){let e=new D(0);for(let r=0;r<n.length;r++){let s=n[r];s.isError()||(s.isArray()?(s=s.count(),e=e.plus(s)):!s.isNull()&&!s.isString()&&(e=e.plus(new D(1))))}return e}}class Js extends O{calculate(...n){let e=new D(0);for(let r=0;r<n.length;r++){let s=n[r];if(s.isError()){e=e.plus(new D(1));continue}s.isArray()?(s=s.countA(),e=e.plus(s)):s.isNull()||(e=e.plus(new D(1)))}return e}}var de=(t=>(t.AVEDEV="AVEDEV",t.AVERAGE="AVERAGE",t.AVERAGEA="AVERAGEA",t.AVERAGEIF="AVERAGEIF",t.AVERAGEIFS="AVERAGEIFS",t.BETA_DIST="BETA.DIST",t.BETA_INV="BETA.INV",t.BINOM_DIST="BINOM.DIST",t.BINOM_DIST_RANGE="BINOM.DIST.RANGE",t.BINOM_INV="BINOM.INV",t.CHISQ_DIST="CHISQ.DIST",t.CHISQ_DIST_RT="CHISQ.DIST.RT",t.CHISQ_INV="CHISQ.INV",t.CHISQ_INV_RT="CHISQ.INV.RT",t.CHISQ_TEST="CHISQ.TEST",t.CONFIDENCE_NORM="CONFIDENCE.NORM",t.CONFIDENCE_T="CONFIDENCE.T",t.CORREL="CORREL",t.COUNT="COUNT",t.COUNTA="COUNTA",t.COUNTBLANK="COUNTBLANK",t.COUNTIF="COUNTIF",t.COUNTIFS="COUNTIFS",t.COVARIANCE_P="COVARIANCE.P",t.COVARIANCE_S="COVARIANCE.S",t.DEVSQ="DEVSQ",t.EXPON_DIST="EXPON.DIST",t.F_DIST="F.DIST",t.F_DIST_RT="F.DIST.RT",t.F_INV="F.INV",t.F_INV_RT="F.INV.RT",t.F_TEST="F.TEST",t.FISHER="FISHER",t.FISHERINV="FISHERINV",t.FORECAST="FORECAST",t.FORECAST_ETS="FORECAST.ETS",t.FORECAST_ETS_CONFINT="FORECAST.ETS.CONFINT",t.FORECAST_ETS_SEASONALITY="FORECAST.ETS.SEASONALITY",t.FORECAST_ETS_STAT="FORECAST.ETS.STAT",t.FORECAST_LINEAR="FORECAST.LINEAR",t.FREQUENCY="FREQUENCY",t.GAMMA="GAMMA",t.GAMMA_DIST="GAMMA.DIST",t.GAMMA_INV="GAMMA.INV",t.GAMMALN="GAMMALN",t.GAMMALN_PRECISE="GAMMALN.PRECISE",t.GAUSS="GAUSS",t.GEOMEAN="GEOMEAN",t.GROWTH="GROWTH",t.HARMEAN="HARMEAN",t.HYPGEOM_DIST="HYPGEOM.DIST",t.INTERCEPT="INTERCEPT",t.KURT="KURT",t.LARGE="LARGE",t.LINEST="LINEST",t.LOGEST="LOGEST",t.LOGNORM_DIST="LOGNORM.DIST",t.LOGNORM_INV="LOGNORM.INV",t.MAX="MAX",t.MAXA="MAXA",t.MAXIFS="MAXIFS",t.MEDIAN="MEDIAN",t.MIN="MIN",t.MINA="MINA",t.MINIFS="MINIFS",t.MODE_MULT="MODE.MULT",t.MODE_SNGL="MODE.SNGL",t.NEGBINOM_DIST="NEGBINOM.DIST",t.NORM_DIST="NORM.DIST",t.NORM_INV="NORM.INV",t.NORM_S_DIST="NORM.S.DIST",t.NORM_S_INV="NORM.S.INV",t.PEARSON="PEARSON",t.PERCENTILE_EXC="PERCENTILE.EXC",t.PERCENTILE_INC="PERCENTILE.INC",t.PERCENTRANK_EXC="PERCENTRANK.EXC",t.PERCENTRANK_INC="PERCENTRANK.INC",t.PERMUT="PERMUT",t.PERMUTATIONA="PERMUTATIONA",t.PHI="PHI",t.POISSON_DIST="POISSON.DIST",t.PROB="PROB",t.QUARTILE_EXC="QUARTILE.EXC",t.QUARTILE_INC="QUARTILE.INC",t.RANK_AVG="RANK.AVG",t.RANK_EQ="RANK.EQ",t.RSQ="RSQ",t.SKEW="SKEW",t.SKEW_P="SKEW.P",t.SLOPE="SLOPE",t.SMALL="SMALL",t.STANDARDIZE="STANDARDIZE",t.STDEV_P="STDEV.P",t.STDEV_S="STDEV.S",t.STDEVA="STDEVA",t.STDEVPA="STDEVPA",t.STEYX="STEYX",t.T_DIST="T.DIST",t.T_DIST_2T="T.DIST.2T",t.T_DIST_RT="T.DIST.RT",t.T_INV="T.INV",t.T_INV_2T="T.INV.2T",t.T_TEST="T.TEST",t.TREND="TREND",t.TRIMMEAN="TRIMMEAN",t.VAR_P="VAR.P",t.VAR_S="VAR.S",t.VARA="VARA",t.VARPA="VARPA",t.WEIBULL_DIST="WEIBULL.DIST",t.Z_TEST="Z.TEST",t))(de||{});class Ns extends O{calculate(...n){let e=new D(-1/0);for(let r=0;r<n.length;r++){let s=n[r];if(s.isError())return s;s.isArray()&&(s=s.max()),!s.isNull()&&(e=this._validator(e,s))}return e}_validator(n,e){return n.isLessThan(e).getValue()&&(n=e),n}}class _r extends O{calculate(...n){let e=new D(1/0);for(let r=0;r<n.length;r++){let s=n[r];if(s.isError())return s;s.isArray()&&(s=s.min()),!s.isNull()&&(e=this._validator(e,s))}return e}_validator(n,e){return n.isGreaterThan(e).getValue()&&(n=e),n}}const _n=[[qs,de.AVERAGE],[Zs,de.COUNT],[Ns,de.MAX],[_r,de.MIN],[_r,de.MIN],[Js,de.COUNTA]];class ei extends O{calculate(...n){if(n.length===0)return new d(f.NA);let e=0,r=0;n.forEach(i=>{if(i.isArray()){const a=i;e=Math.max(e,a.getRowCount()),r=Math.max(r,a.getColumnCount())}else e=Math.max(e,1),r=Math.max(r,1)});let s=null;for(const i of n)s=ne(e,r,i,new d(f.NA)).mapValue((o,u,l)=>{const c=s&&s.get(u,l);return c!=null&&c.isError()?c:o.isError()?o:new Y(`${(c==null?void 0:c.getValue())||""}${o.getValue()}`)});return s||new d(f.VALUE)}}var Lt=(t=>(t.ASC="ASC",t.ARRAYTOTEXT="ARRAYTOTEXT",t.BAHTTEXT="BAHTTEXT",t.CHAR="CHAR",t.CLEAN="CLEAN",t.CODE="CODE",t.CONCAT="CONCAT",t.CONCATENATE="CONCATENATE",t.DBCS="DBCS",t.DOLLAR="DOLLAR",t.EXACT="EXACT",t.FIND="FIND",t.FINDB="FINDB",t.FIXED="FIXED",t.LEFT="LEFT",t.LEFTB="LEFTB",t.LEN="LEN",t.LENB="LENB",t.LOWER="LOWER",t.MID="MID",t.MIDB="MIDB",t.NUMBERVALUE="NUMBERVALUE",t.PHONETIC="PHONETIC",t.PROPER="PROPER",t.REPLACE="REPLACE",t.REPLACEB="REPLACEB",t.REPT="REPT",t.RIGHT="RIGHT",t.RIGHTB="RIGHTB",t.SEARCH="SEARCH",t.SEARCHB="SEARCHB",t.SUBSTITUTE="SUBSTITUTE",t.T="T",t.TEXT="TEXT",t.TEXTAFTER="TEXTAFTER",t.TEXTBEFORE="TEXTBEFORE",t.TEXTJOIN="TEXTJOIN",t.TEXTSPLIT="TEXTSPLIT",t.TRIM="TRIM",t.UNICHAR="UNICHAR",t.UNICODE="UNICODE",t.UPPER="UPPER",t.VALUE="VALUE",t.VALUETOTEXT="VALUETOTEXT",t.CALL="CALL",t.EUROCONVERT="EUROCONVERT",t.REGISTER_ID="REGISTER.ID",t))(Lt||{});const Cn=[[ei,Lt.CONCATENATE]],Dn=[];var ti=(t=>{})();const wn=[];var yn=(t=>(t.ENCODEURL="ENCODEURL",t.FILTERXML="FILTERXML",t.WEBSERVICE="WEBSERVICE",t))(yn||{});class ri extends g.Disposable{constructor(){super(...arguments);_(this,"_definedNameMap",new Map)}dispose(){this._definedNameMap.clear()}registerDefinedName(e,r,s){var a;this._definedNameMap.get(e)==null&&this._definedNameMap.set(e,new Map),(a=this._definedNameMap.get(e))==null||a.set(r,s)}removeDefinedName(e,r){var s;(s=this._definedNameMap.get(e))==null||s.delete(r)}getDefinedNameMap(e){return this._definedNameMap.get(e)}getValue(e,r){var s;return(s=this._definedNameMap.get(e))==null?void 0:s.get(r)}hasDefinedName(e){var s;return(((s=this._definedNameMap.get(e))==null?void 0:s.size)||0)!==0}}const St=x.createIdentifier("univer.formula.defined-names.service");var ni=Object.defineProperty,si=Object.getOwnPropertyDescriptor,ii=(t,n,e,r)=>{for(var s=r>1?void 0:r?si(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&ni(n,e,s),s},ai=(t,n)=>(e,r)=>n(e,r,t);let jt=class extends g.Disposable{constructor(n){super();_(this,"_unitData",{});_(this,"_arrayFormulaCellData",{});_(this,"_formulaData",{});_(this,"_sheetNameMap",{});_(this,"_forceCalculate",!1);_(this,"_dirtyRanges",[]);_(this,"_dirtyNameMap",{});_(this,"_dirtyUnitFeatureMap",{});_(this,"_excludedCell");this._currentUniverService=n}dispose(){this._unitData={},this._formulaData={},this._arrayFormulaCellData={},this._sheetNameMap={},this._dirtyRanges=[],this._dirtyNameMap={},this._dirtyUnitFeatureMap={},this._excludedCell={}}getExcludedRange(){return this._excludedCell}getUnitData(){return this._unitData}getFormulaData(){return this._formulaData}getArrayFormulaCellData(){return this._arrayFormulaCellData}getSheetNameMap(){return this._sheetNameMap}isForceCalculate(){return this._forceCalculate}getDirtyRanges(){return this._dirtyRanges}getDirtyNameMap(){return this._dirtyNameMap}getDirtyUnitFeatureMap(){return this._dirtyUnitFeatureMap}load(n){if(n.allUnitData&&n.unitSheetNameMap)this._unitData=n.allUnitData,this._sheetNameMap=n.unitSheetNameMap;else{const{allUnitData:e,unitSheetNameMap:r}=this._loadSheetData();this._unitData=e,this._sheetNameMap=r}this._formulaData=n.formulaData,this._arrayFormulaCellData=Br(n.arrayFormulaCellData),this._forceCalculate=n.forceCalculate,this._dirtyRanges=n.dirtyRanges,this._dirtyNameMap=n.dirtyNameMap,this._dirtyUnitFeatureMap=n.dirtyUnitFeatureMap,this._excludedCell=n.excludedCell,this._mergeNameMap(this._sheetNameMap,this._dirtyNameMap)}loadDirtyRangesAndExcludedCell(n,e){this._dirtyRanges=n,this._excludedCell=e,this._dirtyNameMap={}}registerUnitData(n){this._unitData=n}registerFormulaData(n){this._formulaData=n}registerSheetNameMap(n){this._sheetNameMap=n}_mergeNameMap(n,e){Object.keys(e).forEach(r=>{e[r]&&Object.keys(e[r]).forEach(s=>{n[r]==null&&(n[r]={}),n[r][e[r][s]]=s})})}_loadSheetData(){const n=this._currentUniverService.getAllUniverSheetsInstance(),e={},r={};for(const s of n){const i=s.getUnitId(),a=s.getSheets(),o={},u={};for(const l of a){const c=l.getSheetId(),h=l.getConfig();o[c]={cellData:new g.ObjectMatrix(h.cellData),rowCount:h.rowCount,columnCount:h.columnCount},u[l.getName()]=l.getSheetId()}e[i]=o,r[i]=u}return{allUnitData:e,unitSheetNameMap:r}}};jt=ii([ai(0,g.IUniverInstanceService)],jt);const ve=x.createIdentifier("univer.formula.current-data.service");var oi=Object.defineProperty,ui=Object.getOwnPropertyDescriptor,li=(t,n,e,r)=>{for(var s=r>1?void 0:r?ui(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&oi(n,e,s),s},ci=(t,n)=>(e,r)=>n(e,r,t),ee=(t=>(t[t.IDLE=0]="IDLE",t[t.START_DEPENDENCY=1]="START_DEPENDENCY",t[t.START_CALCULATION=2]="START_CALCULATION",t[t.CURRENTLY_CALCULATING=3]="CURRENTLY_CALCULATING",t[t.START_DEPENDENCY_ARRAY_FORMULA=4]="START_DEPENDENCY_ARRAY_FORMULA",t[t.START_CALCULATION_ARRAY_FORMULA=5]="START_CALCULATION_ARRAY_FORMULA",t[t.CURRENTLY_CALCULATING_ARRAY_FORMULA=6]="CURRENTLY_CALCULATING_ARRAY_FORMULA",t[t.CALCULATION_COMPLETED=7]="CALCULATION_COMPLETED",t))(ee||{}),Be=(t=>(t[t.INITIAL=0]="INITIAL",t[t.STOP_EXECUTION=1]="STOP_EXECUTION",t[t.NOT_EXECUTED=2]="NOT_EXECUTED",t[t.SUCCESS=3]="SUCCESS",t))(Be||{});let Tt=class extends g.Disposable{constructor(n){super();_(this,"_formulaExecuteStage",0);_(this,"_stopState",!1);_(this,"_currentRow",-1);_(this,"_currentColumn",-1);_(this,"_currentRowCount",-1/0);_(this,"_currentColumnCount",-1/0);_(this,"_currentSubUnitId","");_(this,"_currentUnitId","");_(this,"_runtimeData",{});_(this,"_runtimeOtherData",{});_(this,"_unitArrayFormulaRange",{});_(this,"_runtimeArrayFormulaCellData",{});_(this,"_runtimeClearArrayFormulaCellData",{});_(this,"_runtimeFeatureRange",{});_(this,"_runtimeFeatureCellData",{});_(this,"_functionsExecutedState",0);_(this,"_functionDefinitionPrivacyVar",new Map);_(this,"_totalFormulasToCalculate",0);_(this,"_completedFormulasCount",0);_(this,"_totalArrayFormulasToCalculate",0);_(this,"_completedArrayFormulasCount",0);_(this,"_isCycleDependency",!1);this._currentConfigService=n}get currentRow(){return this._currentRow}get currentColumn(){return this._currentColumn}get currentRowCount(){return this._currentRowCount}get currentColumnCount(){return this._currentColumnCount}get currentSubUnitId(){return this._currentSubUnitId}get currentUnitId(){return this._currentUnitId}dispose(){this.reset(),this._runtimeFeatureCellData={},this._runtimeFeatureRange={}}enableCycleDependency(){this._isCycleDependency=!0}disableCycleDependency(){this._isCycleDependency=!1}isCycleDependency(){return this._isCycleDependency}setTotalArrayFormulasToCalculate(n){this._totalArrayFormulasToCalculate=n}getTotalArrayFormulasToCalculate(){return this._totalArrayFormulasToCalculate}setCompletedArrayFormulasCount(n){this._completedArrayFormulasCount=n}getCompletedArrayFormulasCount(){return this._completedArrayFormulasCount}setTotalFormulasToCalculate(n){this._totalFormulasToCalculate=n}getTotalFormulasToCalculate(){return this._totalFormulasToCalculate}setCompletedFormulasCount(n){this._completedFormulasCount=n}getCompletedFormulasCount(){return this._completedFormulasCount}markedAsSuccessfullyExecuted(){this._functionsExecutedState=3}markedAsNoFunctionsExecuted(){this._functionsExecutedState=2}markedAsStopFunctionsExecuted(){this._functionsExecutedState=1}markedAsInitialFunctionsExecuted(){this._functionsExecutedState=0}stopExecution(){this._stopState=!0,this.setFormulaExecuteStage(0)}isStopExecution(){return this._stopState}setFormulaExecuteStage(n){this._formulaExecuteStage=n}getFormulaExecuteStage(){return this._formulaExecuteStage}reset(){this._formulaExecuteStage=0,this._runtimeData={},this._runtimeOtherData={},this._unitArrayFormulaRange={},this._runtimeArrayFormulaCellData={},this._runtimeClearArrayFormulaCellData={},this._functionDefinitionPrivacyVar.clear(),this.markedAsInitialFunctionsExecuted(),this._isCycleDependency=!1,this._totalFormulasToCalculate=0,this._completedFormulasCount=0}setCurrent(n,e,r,s,i,a){this._currentRow=n,this._currentColumn=e,this._currentRowCount=r,this._currentColumnCount=s,this._currentSubUnitId=i,this._currentUnitId=a}clearFunctionDefinitionPrivacyVar(){this._functionDefinitionPrivacyVar.clear()}registerFunctionDefinitionPrivacyVar(n,e){this._functionDefinitionPrivacyVar.set(n,e)}getFunctionDefinitionPrivacyVar(n){return this._functionDefinitionPrivacyVar.get(n)}setRuntimeOtherData(n,e){const r=this._currentSubUnitId,s=this._currentUnitId;this._runtimeOtherData[s]===void 0&&(this._runtimeOtherData[s]={});const i=this._runtimeOtherData[s];i[r]===void 0&&(i[r]={});const a=i[r];a[n]=this._objectValueToCellValue(e)}setRuntimeData(n){const e=this._currentRow,r=this._currentColumn,s=this._currentRowCount,i=this.currentColumnCount,a=this._currentSubUnitId,o=this._currentUnitId;this._runtimeData[o]==null&&(this._runtimeData[o]={});const u=this._runtimeData[o];u[a]==null&&(u[a]=new g.ObjectMatrix),this._unitArrayFormulaRange[o]==null&&(this._unitArrayFormulaRange[o]={});const l=this._unitArrayFormulaRange[o];let c=new g.ObjectMatrix;l[a]&&(c=new g.ObjectMatrix(l[a])),this._runtimeArrayFormulaCellData[o]===void 0&&(this._runtimeArrayFormulaCellData[o]={});const h=this._runtimeArrayFormulaCellData[o];h[a]==null&&(h[a]=new g.ObjectMatrix),this._runtimeClearArrayFormulaCellData[o]===void 0&&(this._runtimeClearArrayFormulaCellData[o]={});const m=this._runtimeClearArrayFormulaCellData[o];m[a]==null&&(m[a]=new g.ObjectMatrix);const p=u[a],E=h[a],R=m[a];if(n.isReferenceObject()||n.isValueObject()&&n.isArray()){const C=n,{startRow:w,startColumn:b,endRow:L,endColumn:S}=C.getRangePosition();if(w===L&&b===S){const k=this._objectValueToCellValue(C.getFirstCell());p.setValue(e,r,k),R.setValue(e,r,k);return}const M={startRow:e,startColumn:r,endRow:L-w+e,endColumn:S-b+r};if(c.setValue(e,r,M),l[a]=c.getData(),this._checkIfArrayFormulaRangeHasData(o,a,e,r,M)||this._checkIfArrayFormulaExceeded(s,i,M)){const k=this._objectValueToCellValue(new d(f.SPILL));p.setValue(e,r,k),R.setValue(e,r,k)}else{const k=new d(f.SPILL);C.iterator((j,v,P)=>{const F=this._objectValueToCellValue(j);if(v===w&&P===b){if(j!=null&&j.isError()&&j.isEqualType(k))return R.setValue(e,r,{}),p.setValue(e,r,{...this._objectValueToCellValue(k)}),!1;p.setValue(e,r,{...F})}E.setValue(v-w+e,P-b+r,F)})}}else{const C=this._objectValueToCellValue(n);p.setValue(e,r,C),R.setValue(e,r,C)}}getUnitData(){return this._runtimeData}getUnitArrayFormula(){return this._unitArrayFormulaRange}getRuntimeOtherData(){return this._runtimeOtherData}getRuntimeArrayFormulaCellData(){return this._runtimeArrayFormulaCellData}getRuntimeClearArrayFormulaCellData(){return this._runtimeClearArrayFormulaCellData}getRuntimeFeatureRange(){return this._runtimeFeatureRange}setRuntimeFeatureRange(n,e){this._runtimeFeatureRange[n]=e}getRuntimeFeatureCellData(){return this._runtimeFeatureCellData}setRuntimeFeatureCellData(n,e){this._runtimeFeatureCellData[n]=e}getAllRuntimeData(){return{unitData:this.getUnitData(),arrayFormulaRange:this.getUnitArrayFormula(),unitOtherData:this.getRuntimeOtherData(),functionsExecutedState:this._functionsExecutedState,arrayFormulaCellData:this.getRuntimeArrayFormulaCellData(),clearArrayFormulaCellData:this.getRuntimeClearArrayFormulaCellData(),runtimeFeatureRange:this.getRuntimeFeatureRange(),runtimeFeatureCellData:this.getRuntimeFeatureCellData()}}getRuntimeState(){return{totalFormulasToCalculate:this.getTotalFormulasToCalculate(),completedFormulasCount:this.getCompletedFormulasCount(),totalArrayFormulasToCalculate:this.getTotalArrayFormulasToCalculate(),completedArrayFormulasCount:this.getCompletedArrayFormulasCount(),stage:this.getFormulaExecuteStage()}}_objectValueToCellValue(n){if(n==null)return{v:0,t:g.CellValueType.NUMBER};if(n.isError())return{v:n.getErrorType(),t:g.CellValueType.STRING};if(n.isValueObject()){const e=n,r=e.getValue();return e.isNumber()?{v:r,t:g.CellValueType.NUMBER}:e.isBoolean()?{v:r,t:g.CellValueType.BOOLEAN}:{v:r,t:g.CellValueType.STRING}}}_checkIfArrayFormulaRangeHasData(n,e,r,s,i){var m,p,E,R,C,w,b,L,S,M,k,j;const{startRow:a,startColumn:o,endRow:u,endColumn:l}=i,c=this._currentConfigService.getUnitData(),h=(E=(p=(m=this._unitArrayFormulaRange[n])==null?void 0:m[e])==null?void 0:p[r])==null?void 0:E[s];for(let v=a;v<=u;v++)for(let P=o;P<=l;P++){if(v===r&&s===P)continue;const F=(w=(C=(R=this._runtimeData)==null?void 0:R[n])==null?void 0:C[e])==null?void 0:w.getValue(v,P),$=(S=(L=(b=this._runtimeArrayFormulaCellData)==null?void 0:b[n])==null?void 0:L[e])==null?void 0:S.getValue(v,P),On=(j=(k=(M=c==null?void 0:c[n])==null?void 0:M[e])==null?void 0:k.cellData)==null?void 0:j.getValue(v,P);if(!g.isNullCell(F)||!g.isNullCell($)&&!this._isInArrayFormulaRange(h,v,P)||!g.isNullCell(On))return!0}return!1}_isInArrayFormulaRange(n,e,r){if(n==null)return!1;const{startRow:s,startColumn:i,endRow:a,endColumn:o}=n;return e>=s&&e<=a&&r>=i&&r<=o}_checkIfArrayFormulaExceeded(n,e,r){return r.endRow>=n||r.endColumn>=e}_isInDirtyRange(n,e,r,s){const i=this._currentConfigService.getDirtyRanges();return i.length===0?!0:xr(i,n,e,r,s)}};Tt=li([ci(0,ve)],Tt);const N=x.createIdentifier("univer.formula.runtime.service");var hi=Object.defineProperty,fi=Object.getOwnPropertyDescriptor,di=(t,n,e,r)=>{for(var s=r>1?void 0:r?fi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&hi(n,e,s),s},Ot=(t,n)=>(e,r)=>n(e,r,t);let xe=class extends g.Disposable{constructor(t,n,e){super(),this._definedNamesService=t,this._runtimeService=n,this._lexerTreeBuilder=e}treeBuilder(t,n=!0){return this._lexerTreeBuilder.treeBuilder(t,n,this._injectDefinedName.bind(this))}_injectDefinedName(t){var i;const n=this._runtimeService.currentUnitId;if(!this._definedNamesService.hasDefinedName(n))return{sequenceString:"",hasDefinedName:!1};const e=this._lexerTreeBuilder.getSequenceNode(t);let r="",s=!1;for(let a=0,o=e.length;a<o;a++){const u=e[a];if(typeof u=="string"){r+=u;continue}const{nodeType:l,token:c}=u;if(l===z.REFERENCE||l===z.FUNCTION){const h=(i=this._definedNamesService.getDefinedNameMap(n))==null?void 0:i.get(c);h?(r+=h,s=!0):r+=c}else r+=c}return{sequenceString:r,hasDefinedName:s}}};xe=di([Ot(0,St),Ot(1,N),Ot(2,x.Inject(Ct))],xe);var V=(t=>(t.REFERENCE="ReferenceNode",t.VALUE="ValueNode",t.OPERATOR="OperatorNode",t.FUNCTION="FunctionNode",t.LAMBDA="LambdaNode",t.LAMBDA_PARAMETER="LambdaNodeParameter",t.ERROR="ErrorNode",t.BASE="Base",t.ROOT="Root",t.UNION="UnionNode",t.PREFIX="PrefixNode",t.SUFFIX="SuffixNode",t.NULL="NullNode",t))(V||{});const se=new Map([["ReferenceNode",7],["ValueNode",9],["OperatorNode",8],["FunctionNode",6],["LambdaNode",1],["LambdaNodeParameter",2],["Root",10],["UnionNode",3],["PrefixNode",4],["SuffixNode",5]]);class K extends g.Disposable{constructor(e){super();_(this,"_children",[]);_(this,"_parent");_(this,"_valueObject");_(this,"_calculateState",!1);_(this,"_async",!1);_(this,"_address",!1);_(this,"_refOffsetX",0);_(this,"_refOffsetY",0);this._token=e}dispose(){var e;this._children.forEach(r=>{r.dispose()}),(e=this._valueObject)==null||e.dispose(),this._parent=null}get nodeType(){return V.BASE}isAsync(){return this._async}isAddress(){return this._address}setAsync(){this._async=!0}setAddress(){this._address=!0}getParent(){return this._parent}setParent(e){this._parent=e,e.addChildren(this)}getChildren(){return this._children}addChildren(...e){this._children.push(...e)}getToken(){return this._token}setValue(e){this._valueObject=e}getValue(){return this._valueObject}isCalculated(){return this._calculateState}setCalculated(){this._calculateState=!0}execute(){}setNotEmpty(e=!0){}setRefOffset(e=0,r=0){this._refOffsetX=e,this._refOffsetY=r}getRefOffset(){return{x:this._refOffsetX,y:this._refOffsetY}}async executeAsync(){return Promise.resolve(ye.SUCCESS)}serialize(){const e=this.getToken(),r=this.getChildren(),s=[],i=r.length;for(let o=0;o<i;o++){const u=r[o];s.push(u.serialize())}const a={token:e,nodeType:this.nodeType};return i>0&&(a.children=s),a}}class H extends K{constructor(e){super(e);_(this,"_errorValueObject");this._errorValueObject=new d(e)}get nodeType(){return V.ERROR}static create(e){return new H(e)}getValue(){return this._errorValueObject}}const ie=100;class ae extends g.Disposable{get zIndex(){return 0}create(n,e,r){let s;return n instanceof A?s=n.getToken():s=n,new K(s)}checkAndCreateNodeType(n){}}class Ht extends K{get nodeType(){return V.ROOT}execute(){const e=this.getChildren()[0];this.setValue(e.getValue())}}class bn extends ae{get zIndex(){return se.get(V.ROOT)||ie}checkAndCreateNodeType(n){if(!(n instanceof A))return;if(n.getToken()===me)return new Ht(me)}}class Ln extends g.Disposable{constructor(){super(...arguments);_(this,"_functionExecutors",new Map);_(this,"_functionDescriptions",new Map)}dispose(){this._functionExecutors.clear(),this._functionDescriptions.clear()}registerExecutors(...e){for(let r=0;r<e.length;r++){const s=e[r];this._functionExecutors.set(s.name,s)}}getExecutors(){return this._functionExecutors}getExecutor(e){return this._functionExecutors.get(e)}hasExecutor(e){return this._functionExecutors.has(e)}unregisterExecutors(...e){for(let r=0;r<e.length;r++){const s=e[r];this._functionExecutors.delete(s)}}registerDescriptions(...e){for(let r=0;r<e.length;r++){const s=e[r];this._functionDescriptions.set(s.functionName,s)}}getDescriptions(){return this._functionDescriptions}getDescription(e){return this._functionDescriptions.get(e)}hasDescription(e){return this._functionDescriptions.has(e)}unregisterDescriptions(...e){for(let r=0;r<e.length;r++){const s=e[r];this._functionDescriptions.delete(s)}}}const he=x.createIdentifier("univer.formula.function.service");var mi=Object.defineProperty,gi=Object.getOwnPropertyDescriptor,Ri=(t,n,e,r)=>{for(var s=r>1?void 0:r?gi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&mi(n,e,s),s},Cr=(t,n)=>(e,r)=>n(e,r,t);class ct extends K{constructor(n,e,r){super(e),this._accessor=n,this._operatorString=e,this._functionExecutor=r}get nodeType(){return V.PREFIX}execute(){let e=this.getChildren()[0].getValue(),r;if(e==null)throw new Error("object is null");e.isReferenceObject()&&(e=e.toArrayValueObject()),this._operatorString===T.MINUS?r=this._functionExecutor.calculate(new D(0),e):this._operatorString===T.AT?r=this._handlerAT(e):r=new d(f.VALUE),this.setValue(r)}_handlerAT(n){if(!n.isReferenceObject())return new d(f.VALUE);const e=n;if(e.isCell())return new d(f.VALUE);const r=this._accessor.get(N),s=r.currentRow||0,i=r.currentColumn||0;return e.isRow()?e.getCellByColumn(i):e.isColumn()?e.getCellByRow(s):e.isRange()||e.isTable()?e.getCellByPosition():new d(f.VALUE)}}let ht=class extends ae{constructor(t,n){super(),this._functionService=t,this._injector=n}get zIndex(){return se.get(V.PREFIX)||ie}checkAndCreateNodeType(t){if(!(t instanceof A))return;const n=t.getToken(),e=n.trim();if(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;let r="";if(e===T.MINUS)r=I.MINUS;else return e===T.AT?new ct(this._injector,e):void 0;const s=this._functionService.getExecutor(r);return s?new ct(this._injector,e,s):(console.error(`No function ${n}`),H.create(f.NAME))}};ht=Ri([Cr(0,he),Cr(1,x.Inject(x.Injector))],ht);var pi=Object.defineProperty,Ei=Object.getOwnPropertyDescriptor,_i=(t,n,e,r)=>{for(var s=r>1?void 0:r?Ei(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&pi(n,e,s),s},qe=(t,n)=>(e,r)=>n(e,r,t);class Ci extends K{constructor(n,e,r,s){super(n),this._functionExecutor=e,this._currentConfigService=r,this._runtimeService=s,this._functionExecutor.isAsync()&&this.setAsync(),this._functionExecutor.isAddress()&&this.setAddress()}get nodeType(){return V.FUNCTION}async executeAsync(){const n=[],e=this.getChildren(),r=e.length;for(let a=0;a<r;a++){const o=e[a].getValue();o!=null&&(o.isReferenceObject()?n.push(o.toArrayValueObject()):n.push(o))}const s=this._calculate(n);let i;return s.isAsyncObject()||s.isAsyncArrayObject()?i=await s.getValue():i=s,this._setRefData(i),this.setValue(i),Promise.resolve(ye.SUCCESS)}execute(){const n=[],e=this.getChildren(),r=e.length;for(let i=0;i<r;i++){const a=e[i].getValue();a!=null&&(a.isReferenceObject()?n.push(a.toArrayValueObject()):n.push(a))}const s=this._calculate(n);this._setRefData(s),this.setValue(s)}_calculate(n){var r;let e;if(this._setRefInfo(),this._functionExecutor.isCustom()){const s=this._functionExecutor.calculateCustom(...n.map(i=>i.isArray()?i.toValue():i.getValue()));if(typeof s!="object"||s==null)e=Re.create(s);else{const i=ds(s);e=new G({calculateValueList:i,rowCount:i.length,columnCount:((r=i[0])==null?void 0:r.length)||0,unitId:"",sheetId:"",row:-1,column:-1})}}else e=this._functionExecutor.calculate(...n);return e}_setRefInfo(){const{currentUnitId:n,currentSubUnitId:e,currentRow:r,currentColumn:s}=this._runtimeService;this._functionExecutor.setRefInfo(n,e,r,s)}_setRefData(n){if(!n.isReferenceObject())return;const e=n;e.setForcedSheetId(this._currentConfigService.getSheetNameMap()),e.setUnitData(this._currentConfigService.getUnitData()),e.setArrayFormulaCellData(this._currentConfigService.getArrayFormulaCellData()),e.setRuntimeData(this._runtimeService.getUnitData()),e.setRuntimeArrayFormulaCellData(this._runtimeService.getRuntimeArrayFormulaCellData()),e.setRuntimeFeatureCellData(this._runtimeService.getRuntimeFeatureCellData())}}let ft=class extends ae{constructor(t,n,e,r){super(),this._functionService=t,this._currentConfigService=n,this._runtimeService=e,this._injector=r}get zIndex(){return se.get(V.FUNCTION)||ie}create(t){const n=this._functionService.getExecutor(t);return n?new Ci(t,n,this._currentConfigService,this._runtimeService):(console.error(`No function ${t}`),H.create(f.NAME))}checkAndCreateNodeType(t){if(typeof t=="string")return;let e=t.getToken().trim().toUpperCase(),r,s;const i=e.slice(0,2);let a=0;if(new RegExp(T.MINUS,"g").test(i)){const o=this._functionService.getExecutor(I.MINUS);r=new ct(this._injector,T.MINUS,o),a++}if(new RegExp(T.AT,"g").test(i)&&(s=new ct(this._injector,T.AT),r&&s.setParent(r),a++),a>0&&(e=e.slice(a)),this._functionService.hasExecutor(e)){const o=this.create(e);return s?o.setParent(s):r&&o.setParent(r),o}}};ft=_i([qe(0,he),qe(1,ve),qe(2,N),qe(3,x.Inject(x.Injector))],ft);var Di=Object.defineProperty,wi=Object.getOwnPropertyDescriptor,yi=(t,n,e,r)=>{for(var s=r>1?void 0:r?wi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Di(n,e,s),s},bi=(t,n)=>(e,r)=>n(e,r,t);let Ue=class extends g.Disposable{constructor(t){super(),this._runtimeService=t}dispose(){}async executeAsync(t){if(!t)return new d(f.VALUE);await this._executeAsync(t);const n=t.getValue();if(n==null)throw new Error("node value is null");return Promise.resolve(n)}execute(t){if(!t)return new d(f.VALUE);this._execute(t);const n=t.getValue();if(n==null)throw new Error("node value is null");return n}executePreCalculateNode(t){return t.execute(),t.getValue()}checkAsyncNode(t){const n=[];this._checkAsyncNode(t,n);for(let e=0,r=n.length;e<r;e++)if(n[e]===!0)return!0;return!1}_checkAsyncNode(t,n){const e=t.getChildren(),r=e.length;for(let s=0;s<r;s++){const i=e[s];n.push(i.isAsync()),this._checkAsyncNode(i,n)}}async _executeAsync(t){if(this._runtimeService.isStopExecution())return Promise.resolve(ye.ERROR);const n=t.getChildren(),e=n.length;for(let r=0;r<e;r++){const s=n[r];if(s.getToken().toUpperCase()===We&&s.isEmptyParamFunction()){s.execute();continue}await this._executeAsync(s)}return t.nodeType===V.FUNCTION&&t.isAsync()?await t.executeAsync():t.execute(),Promise.resolve(ye.SUCCESS)}_execute(t){if(this._runtimeService.isStopExecution())return ye.ERROR;const n=t.getChildren(),e=n.length;for(let r=0;r<e;r++){const s=n[r];if(s.getToken().toUpperCase()===We&&s.isEmptyParamFunction()){s.execute();continue}this._execute(s)}return t.execute(),ye.SUCCESS}};Ue=yi([bi(0,N)],Ue);function Sn(t){return t instanceof A?t.getToken()===Oe:!1}function Li(t){return t instanceof A?t.getToken()===jr:!1}function Pn(t){if(!t)return;if(t.getToken()!==Ge)return t;const n=t,e=n.getCurrentLambdaPrivacyVar(),r=n.getLambdaParameter();if(!e)return;const s=e.get(r);return s==null&&t.getValue()?t:Pn(s)}class Si extends pe{constructor(e,r,s){super(0);_(this,"_lambdaPrivacyValueMap",new Map);this._lambdaNode=e,this._interpreter=r,this._lambdaPrivacyVarKeys=s,this._lambdaPrivacyValueMap.clear()}isLambda(){return!0}execute(...e){const r=this._lambdaPrivacyVarKeys.length;if(e.length!==r)return new d(f.VALUE);this._setLambdaPrivacyValueMap(e),this._setLambdaNodeValue(this._lambdaNode),this._lambdaNode.setNotEmpty(!1);let s;if(this._interpreter.checkAsyncNode(this._lambdaNode))s=new Rs(this._interpreter.executeAsync(this._lambdaNode));else{const i=this._interpreter.execute(this._lambdaNode);i.isReferenceObject()?s=i.toArrayValueObject():s=i}return this._lambdaNode.setNotEmpty(!0),s}_setLambdaNodeValue(e){const r=e.getChildren(),s=r.length;for(let i=0;i<s;i++){const a=r[i];if(a.getToken()===Ge){const u=a.getLambdaParameter(),l=this._lambdaPrivacyValueMap.get(u);if(l)a.setValue(l);else{const c=a.getCurrentLambdaPrivacyVar(),h=Pn(c.get(u));h!=null&&a.setValue(h.getValue())}continue}this._setLambdaNodeValue(a)}}_setLambdaPrivacyValueMap(e){for(let r=0;r<e.length;r++){const s=e[r],i=this._lambdaPrivacyVarKeys[r];this._lambdaPrivacyValueMap.set(i,s)}}}var Pi=Object.defineProperty,xi=Object.getOwnPropertyDescriptor,Ai=(t,n,e,r)=>{for(var s=r>1?void 0:r?xi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Pi(n,e,s),s},Dr=(t,n)=>(e,r)=>n(e,r,t);class Vi extends K{constructor(e,r,s,i){super(e);_(this,"_isNotEmpty",!0);this._lambdaId=r,this._interpreter=s,this._lambdaPrivacyVarKeys=i}get nodeType(){return V.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 Si(this,this._interpreter,this._lambdaPrivacyVarKeys));else{const e=this.getChildren(),r=e.length;this.setValue(e[r-1].getValue())}}}let dt=class extends ae{constructor(t,n){super(),this._runtimeService=t,this._interpreter=n}get zIndex(){return se.get(V.LAMBDA)||ie}create(t){const n=t.getChildren(),e=n[0];let r=n.slice(1,-1);const s=n[n.length-1];if(!(e instanceof A&&s instanceof A))return H.create(f.NAME);if(e.getToken()===Oe){const o=e.getChildren();if(r.length!==o.length)return H.create(f.VALUE)}else r=n.slice(0,-1);const i=g.Tools.generateRandomId(8),a=new Map;for(let o=0;o<r.length;o++){const u=r[o];if(u instanceof A){const l=u.getChildren()[0];u.setToken(jr),a.set(l.trim(),void 0)}else return H.create(f.VALUE)}return this._runtimeService.registerFunctionDefinitionPrivacyVar(i,a),this._updateLambdaStatement(s,i,a),new Vi(t.getToken(),i,this._interpreter,[...a.keys()])}checkAndCreateNodeType(t){if(!(!(t instanceof A)||t.getToken().trim().toUpperCase()!==We))return this.create(t)}_updateLambdaStatement(t,n,e){this._updateTree(t,n,e)}_updateTree(t,n,e){const r=t.getChildren(),s=r.length,i=r[0];for(let a=0;a<s;a++){const o=r[a];if(!(Sn(i)&&a!==0))if(o instanceof A)this._updateTree(o,n,e);else{const u=o.trim();if(e.has(u)){const l=new A;l.setToken(Ge),l.setLambdaId(n),l.setLambdaPrivacyVar(e),l.setLambdaParameter(u),r[a]=l}}}}};dt=Ai([Dr(0,N),Dr(1,x.Inject(Ue))],dt);function xn(t){if(!t)return;if(t.getToken()!==Ge)return t;const n=t,e=n.getCurrentLambdaPrivacyVar(),r=n.getLambdaParameter();if(e)return xn(e.get(r))}class vi extends K{constructor(n,e,r){super(n),this._lambdaParameter=e,this._currentLambdaPrivacyVar=r}getLambdaParameter(){return this._lambdaParameter}getCurrentLambdaPrivacyVar(){return this._currentLambdaPrivacyVar}get nodeType(){return V.LAMBDA_PARAMETER}execute(){const n=xn(this._currentLambdaPrivacyVar.get(this._lambdaParameter));if(n)this.setValue(n.getValue());else{const e=this.getValue();(e==null||e.isError())&&this.setValue(new d(f.SPILL))}}}class An extends ae{get zIndex(){return se.get(V.LAMBDA_PARAMETER)||ie}create(n){const e=n.getFunctionDefinitionPrivacyVar(),r=n.getLambdaParameter();return e?new vi(n.getToken(),r,e):new H(f.SPILL)}checkAndCreateNodeType(n){if(!(!(n instanceof A)||n.getToken().trim()!==Ge))return this.create(n)}}class Bi extends K{constructor(n){super(n),this._operatorString=n}get nodeType(){return V.NULL}execute(){this.setValue(new ue(0))}}var Oi=Object.defineProperty,Ui=Object.getOwnPropertyDescriptor,Fi=(t,n,e,r)=>{for(var s=r>1?void 0:r?Ui(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Oi(n,e,s),s},Mi=(t,n)=>(e,r)=>n(e,r,t);class $i extends K{constructor(n,e){super(n),this._operatorString=n,this._functionExecutor=e}get nodeType(){return V.OPERATOR}execute(){const n=this.getChildren();this._functionExecutor.name===I.COMPARE&&this._functionExecutor.setCompareType(this.getToken());let e=n[0].getValue(),r=n[1].getValue();if(e==null||r==null)throw new Error("object1 or object2 is null");e.isReferenceObject()&&(e=e.toArrayValueObject()),r.isReferenceObject()&&(r=r.toArrayValueObject()),this.setValue(this._functionExecutor.calculate(e,r))}}let mt=class extends ae{constructor(t){super(),this._functionService=t}get zIndex(){return se.get(V.OPERATOR)||ie}create(t){let n="";const e=t;e===X.PLUS?n=I.PLUS:e===X.MINUS?n=I.MINUS:e===X.MULTIPLY?n=I.MULTIPLY:e===X.DIVIDED?n=I.DIVIDED:e===X.CONCATENATE?n=Lt.CONCATENATE:e===X.POWER?n=Z.POWER:Mn.has(e)&&(n=I.COMPARE);const r=this._functionService.getExecutor(n);return r?new $i(e,r):(console.error(`No function ${t}`),H.create(f.NAME))}checkAndCreateNodeType(t){if(t instanceof A)return;const n=t.trim();if(!(n.charAt(0)==='"'&&n.charAt(n.length-1)==='"')&&je.has(n))return this.create(n)}};mt=Fi([Mi(0,he)],mt);class ki extends g.Disposable{constructor(){super(...arguments);_(this,"_tableMap",new Map);_(this,"_tableOptionMap",new Map)}dispose(){this._tableMap.clear(),this._tableOptionMap.clear()}remove(e,r){var s;(s=this._tableMap.get(e))==null||s.delete(r)}getTableMap(e){return this._tableMap.get(e)}getTableOptionMap(){return this._tableOptionMap}registerTable(e,r,s){var i;this._tableMap.get(e)==null&&this._tableMap.set(e,new Map),(i=this._tableMap.get(e))==null||i.set(r,s)}registerTableOptionMap(e,r){this._tableOptionMap.set(e,r)}}const sr=x.createIdentifier("univer.formula.super-table.service");class Qi extends ke{constructor(n,e,r,s){super(n),this._tableData=e,this._columnDataString=r;const i=this._tableData.sheetId,a=this._tableData.range,o=this._tableData.titleMap;this.setForcedSheetIdDirect(i);const u=this._stringToColumnData(this._columnDataString,o,s),l=u.startColumn,c=u.endColumn,h=u.type;let m=-1,p=-1;const E=a.startRow,R=a.startColumn;h===De.ALL?(m=E,p=R):h===De.DATA?(m=E+1,p=R):h===De.HEADERS?(m=E,p=E):h===De.TOTALS&&(m=R,p=R),this.setRangeData({startColumn:l,endColumn:c,startRow:m,endRow:p})}isTable(){return!0}_stringToColumnData(n,e,r){n=n.substring(1,-1);const s=n.indexOf(B.COMMA);let i=-1,a=-1,o=De.ALL;if(s===-1){const u=this._columnHandler(n,e);i=u.startColumn,a=u.endColumn}else{const u=n.substring(0,s).substring(1,-1),l=n.substring(s+1),c=this._columnHandler(l,e,!0);i=c.startColumn,a=c.endColumn,o=r.get(u),o||(o=De.ALL)}return{startColumn:i,endColumn:a,type:o}}_columnHandler(n,e,r=!1){var o,u,l;let s=-1,i=-1;const a=n.indexOf(B.COLON);if(new RegExp(Qr,"g").test(n)){const c=n.substring(0,a).substring(1,-1),h=n.substring(a+1).substring(1,-1);s=(o=e.get(c))!=null?o:-1,i=(u=e.get(h))!=null?u:-1}else r&&(n=n.substring(1,-1)),s=(l=e.get(n))!=null?l:-1,i=s;return{startColumn:s,endColumn:i}}}var ji=Object.defineProperty,Ti=Object.getOwnPropertyDescriptor,Hi=(t,n,e,r)=>{for(var s=r>1?void 0:r?Ti(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&ji(n,e,s),s},Qe=(t,n)=>(e,r)=>n(e,r,t);class Ze extends K{constructor(n,e,r,s=!1){super(e),this._accessor=n,this._operatorString=e,this._referenceObject=r,this._isPrepareMerge=s}get nodeType(){return V.REFERENCE}execute(){const n=this._accessor.get(ve),e=this._accessor.get(N);this._referenceObject.setDefaultUnitId(e.currentUnitId),this._referenceObject.setDefaultSheetId(e.currentSubUnitId),this._referenceObject.setForcedSheetId(n.getSheetNameMap()),this._referenceObject.setUnitData(n.getUnitData()),this._referenceObject.setArrayFormulaCellData(n.getArrayFormulaCellData()),this._referenceObject.setRuntimeData(e.getUnitData()),this._referenceObject.setRuntimeArrayFormulaCellData(e.getRuntimeArrayFormulaCellData()),this._referenceObject.setRuntimeFeatureCellData(e.getRuntimeFeatureCellData());const{x:r,y:s}=this.getRefOffset();this._referenceObject.setRefOffset(r,s),!this._isPrepareMerge&&this._referenceObject.isExceedRange()?this.setValue(new d(f.NAME)):this.setValue(this._referenceObject)}}let gt=class extends ae{constructor(t,n,e,r,s){super(),this._definedNamesService=t,this._superTableService=n,this._formulaRuntimeService=e,this._lexer=r,this._injector=s}get zIndex(){return se.get(V.REFERENCE)||ie}checkAndCreateNodeType(t){var u,l;let n=!1,e,r=!1;if(t instanceof A?(n=!0,e=t.getToken().trim(),((l=(u=t.getParent())==null?void 0:u.getParent())==null?void 0:l.getToken().trim())===B.COLON&&(r=!0)):e=t.trim(),!n&&e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;if(new RegExp(_t).test(e))return new Ze(this._injector,e,new fn(e),r);if(n&&new RegExp(Xn).test(e))return new Ze(this._injector,e,new mn(e),r);if(n&&new RegExp(Gn).test(e))return new Ze(this._injector,e,new dn(e),r);const s=this._formulaRuntimeService.currentUnitId,i=this._superTableService.getTableMap(s),a=new RegExp(Qr,"g"),o=e.replace(a,"");if(!n&&(i!=null&&i.has(o))){const c=a.exec(e);let h="";c&&(h=c[0]);const m=i.get(o),p=this._superTableService.getTableOptionMap();return new Ze(this._injector,e,new Qi(e,m,h,p))}}};gt=Hi([Qe(0,St),Qe(1,sr),Qe(2,N),Qe(3,x.Inject(xe)),Qe(4,x.Inject(x.Injector))],gt);var Yi=Object.defineProperty,Wi=Object.getOwnPropertyDescriptor,Ii=(t,n,e,r)=>{for(var s=r>1?void 0:r?Wi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Yi(n,e,s),s},wr=(t,n)=>(e,r)=>n(e,r,t);class yr extends K{constructor(n,e,r){super(e),this._accessor=n,this._operatorString=e,this._functionExecutor=r}get nodeType(){return V.SUFFIX}execute(){let e=this.getChildren()[0].getValue(),r;if(e==null)throw new Error("object is null");this._operatorString===le.PERCENTAGE?(e.isReferenceObject()&&(e=e.toArrayValueObject()),r=this._functionExecutor.calculate(e,new D(100))):this._operatorString===le.POUND?r=this._handlerPound(e):r=new d(f.VALUE),this.setValue(r)}_handlerPound(n){var c,h,m,p;if(!n.isReferenceObject())return new d(f.VALUE);if(!n.isCell())return new d(f.VALUE);const e=this._accessor.get(ve),r=this._accessor.get(xe),s=n,i=s.getRangePosition(),a=s.getUnitId(),o=s.getSheetId(),u=e.getFormulaData(),l=(p=(m=(h=(c=u==null?void 0:u[a])==null?void 0:c[o])==null?void 0:h[i.startRow])==null?void 0:m[i.startColumn])==null?void 0:p.f;return l?(r.treeBuilder(l),new d(f.VALUE)):new d(f.VALUE)}}let Rt=class extends ae{constructor(t,n){super(),this._functionService=t,this._injector=n}get zIndex(){return se.get(V.SUFFIX)||ie}checkAndCreateNodeType(t){if(!(t instanceof A))return;const n=t.getToken().trim();if(n.charAt(0)==='"'&&n.charAt(n.length-1)==='"')return;let e="";if(n===le.PERCENTAGE)e=I.DIVIDED;else return n===le.POUND?new yr(this._injector,n):void 0;const r=this._functionService.getExecutor(e);return r?new yr(this._injector,n,r):(console.error(`No function ${t}`),H.create(f.NAME))}};Rt=Ii([wr(0,he),wr(1,x.Inject(x.Injector))],Rt);var Xi=Object.defineProperty,Gi=Object.getOwnPropertyDescriptor,Ki=(t,n,e,r)=>{for(var s=r>1?void 0:r?Gi(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Xi(n,e,s),s},zi=(t,n)=>(e,r)=>n(e,r,t);class qi extends K{constructor(n){super(n),this._operatorString=n}get nodeType(){return V.UNION}execute(){const n=this.getChildren(),e=n[0].getValue(),r=n[1].getValue();if(e==null||r==null)throw new Error("leftNode and rightNode");let s;this._operatorString===B.COLON?s=this._unionFunction(e,r):s=new d(f.NAME),this.setValue(s)}_unionFunction(n,e){return n.isError()||e.isError()?new d(f.REF):!n.isReferenceObject()||!e.isReferenceObject()?new d(f.REF):(n=n,e=e,n.isCell()&&e.isCell()||n.isRow()&&e.isRow()||n.isColumn()&&e.isColumn()?n.unionBy(e):new d(f.REF))}}let pt=class extends ae{constructor(t){super(),this._functionService=t}get zIndex(){return se.get(V.UNION)||ie}create(t){return new qi(t)}checkAndCreateNodeType(t){if(!(t instanceof A))return;const e=t.getToken().trim();if(!(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')&&e===B.COLON)return this.create(e)}};pt=Ki([zi(0,he)],pt);class Zi extends K{constructor(n){super(n),this._operatorString=n}get nodeType(){return V.VALUE}execute(){this.setValue(Re.create(this._operatorString))}}class Vn extends ae{get zIndex(){return se.get(V.VALUE)||ie}_checkValueNode(n){if(isNaN(Number(n))){const e=n.trim(),r=e.charAt(0),s=e.charAt(e.length-1);if(Yt.has(e))return this.create(e);if(r==='"'&&s==='"')return this.create(e);if(r==="{"&&s==="}")return this.create(e);if(e===Se.TRUE||e===Se.FALSE)return this.create(e)}else return this.create(n)}create(n){return new Zi(n)}checkAndCreateNodeType(n){if(!(n instanceof A))return this._checkValueNode(n)}}var Ji=Object.defineProperty,Ni=Object.getOwnPropertyDescriptor,ea=(t,n,e,r)=>{for(var s=r>1?void 0:r?Ni(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Ji(n,e,s),s},q=(t,n)=>(e,r)=>n(e,r,t);let Xe=class extends g.Disposable{constructor(n,e,r,s,i,a,o,u,l,c,h){super();_(this,"_astNodeFactoryList",[]);_(this,"_refOffsetX",0);_(this,"_refOffsetY",0);this._runtimeService=n,this._astRootNodeFactory=e,this._functionNodeFactory=r,this._lambdaNodeFactory=s,this._lambdaParameterNodeFactory=i,this._operatorNodeFactory=a,this._prefixNodeFactory=o,this._referenceNodeFactory=u,this._suffixNodeFactory=l,this._unionNodeFactory=c,this._valueNodeFactory=h,this._initializeAstNode()}dispose(){this._astNodeFactoryList.forEach(n=>{n.dispose()}),this._astNodeFactoryList=[]}parse(n,e=0,r=0){const s=new Ht(me);return this._refOffsetX=e,this._refOffsetY=r,this._parse(n,s)}_lambdaParameterHandler(n,e){const r=e.getLambdaId(),s=new Ht(me),i=this._runtimeService.getFunctionDefinitionPrivacyVar(r);if(!i)return!1;const a=[...i.keys()],o=n.getChildren(),u=o.length;for(let h=0;h<u;h++){const m=o[h];if(m instanceof A)this._parse(m,s);else return!1}const l=s.getChildren(),c=l.length;for(let h=0;h<c;h++){const m=l[h];i.set(a[h],m)}return s.setParent(e),e}_changeLetToLambda(n){const e=n.getChildren(),r=e.length;if(r%2!==1||r===0)return;const s=new A;s.setToken(We);const i=new A;i.setToken(Oe);const a=[...e];for(let u=0;u<r;u++){const l=a[u];if(!(l instanceof A))return;u%2===0?l.changeToParent(s):l.changeToParent(i)}s.addChildrenFirst(i),i.setParent(s);const o=n.getParent();return o==null||o.replaceChild(n,s),s}_getTopParent(n){let e=n;for(;e!=null&&e.getParent();)e=e.getParent();return e}_parse(n,e){const r=n.getChildren(),s=r.length,i=[];let a=null;const o=n.getToken().trim().toUpperCase();if(o===qn){const c=this._changeLetToLambda(n);return c!=null?this._parse(c,e):H.create(f.ERROR)}if(o===Ce){if(a=e,s===0)return new Bi(me).setParent(e),a}else{if(o===Oe){let c=this._lambdaParameterHandler(n,e);return c===!1&&(c=H.create(f.ERROR)),c}if(a=this._checkAstNode(n),a==null)return H.create(f.ERROR)}const u=r[0];for(let c=0;c<s;c++){const h=r[c];if(Sn(u)){if(c!==0&&c!==s-1)continue}else if(Li(h)&&c!==s-1)continue;let m=null;if(h instanceof A){if(m=this._parse(h,a),m===a)continue}else m=this._checkAstNode(h);if(m==null)return H.create(f.NAME);if(m=this._getTopParent(m),m==null)return;switch(m.nodeType){case V.ERROR:return m;case V.FUNCTION:i.push(m);break;case V.LAMBDA:i.push(m);break;case V.LAMBDA_PARAMETER:i.push(m);break;case V.OPERATOR:{const p=i.pop(),E=i.pop();if(E)E.setParent(m);else return H.create(f.ERROR);if(p)p.setParent(m);else return H.create(f.ERROR);i.push(m);break}case V.REFERENCE:m.setRefOffset(this._refOffsetX,this._refOffsetY),i.push(m);break;case V.ROOT:i.push(m);break;case V.UNION:i.push(m);break;case V.VALUE:i.push(m);break;case V.PREFIX:i.push(m);break;case V.SUFFIX:i.push(m);break}}const l=i.length;for(let c=0;c<l;c++)i[c].setParent(a);return a}_checkAstNode(n){let e=null;const r=this._astNodeFactoryList.length;for(let s=0;s<r&&(e=this._astNodeFactoryList[s].checkAndCreateNodeType(n),e==null);s++);return e}_initializeAstNode(){this._astNodeFactoryList=[this._astRootNodeFactory,this._functionNodeFactory,this._lambdaNodeFactory,this._lambdaParameterNodeFactory,this._operatorNodeFactory,this._prefixNodeFactory,this._referenceNodeFactory,this._suffixNodeFactory,this._unionNodeFactory,this._valueNodeFactory].sort(g.sortRules)}};Xe=ea([q(0,N),q(1,x.Inject(bn)),q(2,x.Inject(ft)),q(3,x.Inject(dt)),q(4,x.Inject(An)),q(5,x.Inject(mt)),q(6,x.Inject(ht)),q(7,x.Inject(gt)),q(8,x.Inject(Rt)),q(9,x.Inject(pt)),q(10,x.Inject(Vn))],Xe);class vn extends g.Disposable{constructor(){super(...arguments);_(this,"_referenceExecutorMap",new Map)}dispose(){this._referenceExecutorMap.clear()}remove(e){this._referenceExecutorMap.delete(e)}get(e){return this._referenceExecutorMap.get(e)}has(e){return this._referenceExecutorMap.has(e)}register(e,r){this._referenceExecutorMap.set(e,r)}getReferenceExecutorMap(){return this._referenceExecutorMap}}const Pt=x.createIdentifier("univer.formula.feature-calculation-manager.service");class Bn extends g.Disposable{constructor(){super(...arguments);_(this,"_otherFormulaData",{})}dispose(){this._otherFormulaData={}}remove(e){var a,o,u;const{unitId:r,subUnitId:s,formulaId:i}=e;(u=(o=(a=this._otherFormulaData)==null?void 0:a[r])==null?void 0:o[s])==null||delete u[i]}get(e){var a,o;const{unitId:r,subUnitId:s,formulaId:i}=e;return(o=(a=this._otherFormulaData[r])==null?void 0:a[s])==null?void 0:o[i]}has(e){var a,o;const{unitId:r,subUnitId:s,formulaId:i}=e;return((o=(a=this._otherFormulaData[r])==null?void 0:a[s])==null?void 0:o[i])!=null}register(e){const{unitId:r,subUnitId:s,formulaId:i,item:a}=e;this._otherFormulaData[r]&&(this._otherFormulaData[r]={}),this._otherFormulaData[r][s]&&(this._otherFormulaData[r][s]={}),this._otherFormulaData[r][s][i]=a}getOtherFormulaData(){return this._otherFormulaData}}const ir=x.createIdentifier("univer.formula.other-formula-manager.service");class Ut extends g.Disposable{constructor(){super(...arguments);_(this,"node");_(this,"children",[]);_(this,"parents",[]);_(this,"formula","");_(this,"row",-1);_(this,"column",-1);_(this,"rowCount",Number.NEGATIVE_INFINITY);_(this,"columnCount",Number.NEGATIVE_INFINITY);_(this,"subUnitId","");_(this,"unitId","");_(this,"rangeList",[]);_(this,"formulaId");_(this,"featureId");_(this,"getDirtyData");_(this,"_state",0)}dispose(){var e;this.children.forEach(r=>{r.dispose()}),this.rangeList=[],this.parents=[],(e=this.node)==null||e.dispose()}setAdded(){this._state=1}isAdded(){return this._state===1}setSkip(){this._state=2}isSkip(){return this._state===2}inRangeData(e){const r=e.startRow,s=e.startColumn,i=e.endRow,a=e.endColumn;return!(this.row<r||this.row>i||this.column<s||this.column>a)}dependencyRange(e,r,s){var i,a;if(this.rangeList.length===0)return!1;for(let o=0,u=this.rangeList.length;o<u;o++){const l=this.rangeList[o],{unitId:c,sheetId:h,range:m}=l;if(((i=r[c])==null?void 0:i[h])!=null)return!0;if(!e.has(c))continue;const p=e.get(c);if(!p.has(h))continue;const E=p.get(h),R=(a=s==null?void 0:s[c])==null?void 0:a[h];let{startRow:C,endRow:w,startColumn:b,endColumn:L}=m;isNaN(C)&&(C=0),isNaN(b)&&(b=0),isNaN(w)&&(w=Number.POSITIVE_INFINITY),isNaN(L)&&(L=Number.POSITIVE_INFINITY);for(const S of E){const{startRow:M,startColumn:k,endRow:j,endColumn:v}=S;if(!(C>j||w<M||b>v||L<k)){let P=!0;if(R==null||R.forValue((F,$)=>{if(F>=C&&F<=w&&$>=b&&$<=L)return P=!1,!1}),P)return!0}}}return!1}pushChildren(e){this.children.push(e),e._pushParent(this)}pushRangeList(e){this.rangeList.push(e)}dependency(e){if(this.rangeList.length===0)return!1;for(let r=0,s=this.rangeList.length;r<s;r++){const i=this.rangeList[r],a=i.unitId,o=i.sheetId,u=i.range;if(e.unitId===a&&e.subUnitId===o&&e.inRangeData(u))return!0}return!1}_pushParent(e){this.parents.push(e)}}var ta=Object.defineProperty,ra=Object.getOwnPropertyDescriptor,na=(t,n,e,r)=>{for(var s=r>1?void 0:r?ra(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&ta(n,e,s),s},Ee=(t,n)=>(e,r)=>n(e,r,t);const sa=1e5,Ft=new Et(sa);let He=class extends g.Disposable{constructor(n,e,r,s,i,a,o){super();_(this,"_updateRangeFlattenCache",new Map);_(this,"_dirtyUnitSheetNameMap",{});this._currentConfigService=n,this._runtimeService=e,this._otherFormulaManagerService=r,this._featureCalculationManagerService=s,this._interpreter=i,this._astTreeBuilder=a,this._lexer=o}dispose(){this._updateRangeFlattenCache.clear(),Ft.clear(),this._dirtyUnitSheetNameMap={}}async generate(){this._updateRangeFlatten();const n=this._currentConfigService.getFormulaData(),e=this._otherFormulaManagerService.getOtherFormulaData(),r=this._currentConfigService.getUnitData(),s=await this._generateTreeList(n,e,r),i=this._getUpdateTreeListAndMakeDependency(s);this._checkIsCycleDependency(i)&&this._runtimeService.enableCycleDependency();const o=this._calculateRunList(i);return Promise.resolve(o)}_isCyclicUtil(n,e,r){if(!e.has(n)){e.add(n),r.add(n);for(let s=0;s<n.children.length;s++)if(!e.has(n.children[s])&&this._isCyclicUtil(n.children[s],e,r)||r.has(n.children[s]))return!0}return r.delete(n),!1}_checkIsCycleDependency(n){const e=new Set,r=new Set;for(let s=0,i=n.length;s<i;s++){const a=n[s];if(this._isCyclicUtil(a,e,r)===!0)return!0}return!1}async _generateTreeList(n,e,r){const s=Object.keys(n),i=Object.keys(e),a=[];for(const o of s){const u=n[o];if(u==null)continue;const l=Object.keys(u);for(const c of l)new g.ObjectMatrix(u[c]).forValue((m,p,E)=>{if(E==null)return!0;const{f:R,x:C,y:w}=E,b=this._generateAstNode(R,C,w),L=new Ut,S=r[o][c];L.node=b,L.formula=R,L.unitId=o,L.subUnitId=c,L.row=m,L.column=p,L.rowCount=S.rowCount,L.columnCount=S.columnCount,a.push(L)})}for(const o of i){const u=e[o];if(u==null)continue;const l=Object.keys(u);for(const c of l){const h=u[c];if(h==null)continue;const m=Object.keys(h);for(const p of m){const E=h[p],{f:R}=E,C=this._generateAstNode(R),w=new Ut;w.node=C,w.formula=R,w.unitId=o,w.subUnitId=c,w.formulaId=p,a.push(w)}}}this._featureCalculationManagerService.getReferenceExecutorMap().forEach((o,u)=>{const{unitId:l,subUnitId:c,dependencyRanges:h,getDirtyData:m}=o,p=new Ut;p.unitId=l,p.subUnitId=c,p.getDirtyData=m,p.featureId=u,p.rangeList=h,a.push(p)});for(let o=0,u=a.length;o<u;o++){const l=a[o];if(this._runtimeService.setCurrent(l.row,l.column,l.rowCount,l.columnCount,l.subUnitId,l.unitId),l.node==null)continue;const c=await this._getRangeListByNode(l.node);for(let h=0,m=c.length;h<m;h++)l.pushRangeList(c[h])}return a}_updateRangeFlatten(){const n=this._currentConfigService.isForceCalculate(),e=this._currentConfigService.getDirtyRanges();if(!n){this._updateRangeFlattenCache.clear();for(let r=0;r<e.length;r++){const s=e[r],i=s.range,a=s.sheetId,o=s.unitId;this._addFlattenCache(o,a,i)}this._dirtyUnitSheetNameMap=this._currentConfigService.getDirtyNameMap()}}_generateAstNode(n,e=0,r=0){let s=Ft.get(`${n}##${e}${r}`);if(s)return s;const i=this._lexer.treeBuilder(n);if(i in f)return H.create(i);if(s=this._astTreeBuilder.parse(i,e,r),s==null)throw new Error("astNode is null");return Ft.set(`${n}##${e}${r}`,s),s}_addFlattenCache(n,e,r){let s=this._updateRangeFlattenCache.get(n);s==null&&(s=new Map,this._updateRangeFlattenCache.set(n,s));let i=s.get(e);i==null&&(i=[],s.set(e,i)),i.push(r)}_isPreCalculateNode(n){return n.nodeType===V.UNION||n.nodeType===V.PREFIX&&n.getToken()===T.AT||n.nodeType===V.SUFFIX&&n.getToken()===le.POUND}_nodeTraversalRef(n,e){const r=n.getChildren(),s=r.length;for(let i=0;i<s;i++){const a=r[i];if(this._isPreCalculateNode(a)){e.push(a);continue}else a.nodeType===V.REFERENCE&&e.push(a);this._nodeTraversalRef(a,e)}}_nodeTraversalReferenceFunction(n,e){const r=n.getChildren(),s=r.length;for(let i=0;i<s;i++){const a=r[i];if(a.nodeType===V.FUNCTION&&a.isAddress()){e.push(a);continue}this._nodeTraversalReferenceFunction(a,e)}}async _executeNode(n){let e;return this._interpreter.checkAsyncNode(n)?e=await this._interpreter.executeAsync(n):e=this._interpreter.execute(n),e}async _getRangeListByNode(n){const e=[],r=[];this._nodeTraversalRef(n,e),this._nodeTraversalReferenceFunction(n,r);const s=[];for(let i=0,a=e.length;i<a;i++){const o=e[i],l=(await this._executeNode(o)).toUnitRange();s.push(l)}for(let i=0,a=r.length;i<a;i++){const o=r[i],l=(await this._executeNode(o)).toUnitRange();s.push(l)}return s}_getUpdateTreeListAndMakeDependency(n){const e=[],r=new Set,s=this._currentConfigService.isForceCalculate();for(let i=0,a=n.length;i<a;i++){const o=n[i];for(let u=0,l=n.length;u<l;u++){const c=n[u];o!==c&&o.dependency(c)&&o.pushChildren(c)}(s||o.dependencyRange(this._updateRangeFlattenCache,this._dirtyUnitSheetNameMap,this._currentConfigService.getExcludedRange())||this._includeTree(o))&&!r.has(o)&&(e.push(o),r.add(o))}return e}_includeTree(n){var l,c,h,m,p;const e=n.unitId,r=n.subUnitId,s=n.featureId;if(s!=null){const E=this._currentConfigService.getDirtyUnitFeatureMap();if(((c=(l=E==null?void 0:E[e])==null?void 0:l[r])==null?void 0:c[s])!=null)return!0}const i=(m=(h=this._currentConfigService.getExcludedRange())==null?void 0:h[e])==null?void 0:m[r];let a=!1;if(i==null||i.forValue((E,R)=>{if(n.row===E&&n.column===R)return a=!0,!1}),a)return!1;if(((p=this._dirtyUnitSheetNameMap[e])==null?void 0:p[r])!=null)return!0;if(!this._updateRangeFlattenCache.has(e))return!1;const o=this._updateRangeFlattenCache.get(e);if(!o.has(r))return!1;const u=o.get(r);for(const E of u)if(n.inRangeData(E))return!0;return!1}_calculateRunList(n){let e=n;const r=[];for(;e.length>0;){const s=e.pop();if(s===void 0||s.isSkip())continue;if(s.isAdded()){r.push(s);continue}const i=[];for(let a=0,o=s.parents.length;a<o;a++){const u=s.parents[a];i.push(u)}i.length===0?(r.push(s),s.setSkip()):(s.setAdded(),e.push(s),e=e.concat(i))}return r.reverse()}};He=na([g.OnLifecycle(g.LifecycleStages.Rendered,He),Ee(0,ve),Ee(1,N),Ee(2,ir),Ee(3,Pt),Ee(4,x.Inject(Ue)),Ee(5,x.Inject(Xe)),Ee(6,x.Inject(xe))],He);var ia=Object.defineProperty,aa=Object.getOwnPropertyDescriptor,oa=(t,n,e,r)=>{for(var s=r>1?void 0:r?aa(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&ia(n,e,s),s},_e=(t,n)=>(e,r)=>n(e,r,t);const ua=1;exports.CalculateFormulaService=class extends g.Disposable{constructor(e,r,s,i,a,o,u){super();_(this,"_executionStartListener$",new xt.Subject);_(this,"executionStartListener$",this._executionStartListener$.asObservable());_(this,"_executionCompleteListener$",new xt.Subject);_(this,"executionCompleteListener$",this._executionCompleteListener$.asObservable());_(this,"_executionInProgressListener$",new xt.Subject);_(this,"executionInProgressListener$",this._executionInProgressListener$.asObservable());this._configService=e,this._lexer=r,this._currentConfigService=s,this._runtimeService=i,this._formulaDependencyGenerator=a,this._interpreter=o,this._astTreeBuilder=u}dispose(){}stopFormulaExecution(){this._runtimeService.stopExecution()}setRuntimeFeatureCellData(e,r){this._runtimeService.setRuntimeFeatureCellData(e,r)}setRuntimeFeatureRange(e,r){this._runtimeService.setRuntimeFeatureRange(e,r)}async execute(e){this._executionStartListener$.next(!0),this._currentConfigService.load(e),this._runtimeService.reset();const r=this._configService.getConfig("CYCLE_REFERENCE_COUNT")||ua;for(let s=0;s<r&&(await this._execute(),!!this._runtimeService.isCycleDependency());s++);this._runtimeService.setFormulaExecuteStage(ee.CALCULATION_COMPLETED),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState()),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData()),Qt.clear(),fe.clear()}async _execute(){const e=await this._apply();if(e==null)return;const{arrayFormulaRange:r,runtimeFeatureRange:s}=e,{dirtyRanges:i,excludedCell:a}=this._getArrayFormulaDirtyRangeAndExcludedRange(r,s);return i==null||i.length===0||(this._currentConfigService.loadDirtyRangesAndExcludedCell(i,a),await this._apply(!0)),!0}_getArrayFormulaDirtyRangeAndExcludedRange(e,r){const s=[],i={};return Object.keys(e).forEach(a=>{const o=e[a];if(o==null)return!0;Object.keys(o).forEach(u=>{const l=new g.ObjectMatrix(o[u]);if(l==null)return!0;const c=new g.ObjectMatrix;l.forValue((h,m,p)=>{c.setValue(h,m,!0),s.push({unitId:a,sheetId:u,range:p})}),i[a]==null&&(i[a]={}),i[a][u]=c})}),Object.keys(r).forEach(a=>{const o=r[a];Object.keys(o).forEach(u=>{const l=o[u];if(l==null)return!0;Object.keys(l).forEach(c=>{const h=l[c];if(h==null)return!0;for(const m of h)s.push({unitId:u,sheetId:c,range:m})})})}),{dirtyRanges:s,excludedCell:i}}async _apply(e=!1){e?this._runtimeService.setFormulaExecuteStage(ee.START_DEPENDENCY_ARRAY_FORMULA):this._runtimeService.setFormulaExecuteStage(ee.START_DEPENDENCY),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());const r=await this._formulaDependencyGenerator.generate(),s=this._interpreter;e?(this._runtimeService.setFormulaExecuteStage(ee.START_CALCULATION_ARRAY_FORMULA),this._runtimeService.setTotalArrayFormulasToCalculate(r.length)):(this._runtimeService.setFormulaExecuteStage(ee.START_CALCULATION),this._runtimeService.setTotalFormulasToCalculate(r.length)),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());for(let i=0,a=r.length;i<a;i++){if(await new Promise(h=>{g.requestImmediateMacroTask(h)}),this._runtimeService.isStopExecution()){this._runtimeService.setFormulaExecuteStage(ee.IDLE),this._runtimeService.markedAsStopFunctionsExecuted(),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData());return}const o=r[i],u=o.node,l=o.getDirtyData;let c;if(u==null&&l==null)throw new Error("AstNode or executor is null");if(this._runtimeService.setCurrent(o.row,o.column,o.rowCount,o.columnCount,o.subUnitId,o.unitId),l!=null&&o.featureId!=null){const{runtimeCellData:h,dirtyRanges:m}=l(o);this._runtimeService.setRuntimeFeatureCellData(o.featureId,h),this._runtimeService.setRuntimeFeatureRange(o.featureId,m)}else u!=null&&(s.checkAsyncNode(u)?c=await s.executeAsync(u):c=s.execute(u),o.formulaId!=null?this._runtimeService.setRuntimeOtherData(o.formulaId,c):this._runtimeService.setRuntimeData(c));e?(this._runtimeService.setFormulaExecuteStage(ee.CURRENTLY_CALCULATING_ARRAY_FORMULA),this._runtimeService.setCompletedArrayFormulasCount(i+1)):(this._runtimeService.setFormulaExecuteStage(ee.CURRENTLY_CALCULATING),this._runtimeService.setCompletedFormulasCount(i+1)),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState())}return r.length>0?this._runtimeService.markedAsSuccessfullyExecuted():e||this._runtimeService.markedAsNoFunctionsExecuted(),this._runtimeService.getAllRuntimeData()}calculate(e,r=!0){const s=this._lexer.treeBuilder(e,r);if(Object.values(f).includes(s))return H.create(s);const i=this._astTreeBuilder.parse(s);i==null||i.serialize()}};exports.CalculateFormulaService=oa([g.OnLifecycle(g.LifecycleStages.Rendered,exports.CalculateFormulaService),_e(0,g.IConfigService),_e(1,x.Inject(xe)),_e(2,ve),_e(3,N),_e(4,x.Inject(He)),_e(5,x.Inject(Ue)),_e(6,x.Inject(Xe))],exports.CalculateFormulaService);var la=Object.defineProperty,ca=Object.getOwnPropertyDescriptor,ha=(t,n,e,r)=>{for(var s=r>1?void 0:r?ca(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&la(n,e,s),s},Je=(t,n)=>(e,r)=>n(e,r,t);let tt=class extends g.Disposable{constructor(t,n,e,r){super(),this._commandService=t,this._calculateFormulaService=n,this._currentUniverService=e,this._formulaDataModel=r,this._initialize()}_initialize(){this._commandExecutedListener(),this._initialExecuteFormulaListener(),this._initialExecuteFormulaProcessListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{if(t.id===zt.id)this._calculateFormulaService.stopFormulaExecution();else if(t.id===Zt.id){const e=t.params.formulaData;this._formulaDataModel.setFormulaData(e)}else if(t.id===Kt.id){const e=t.params;if(e.forceCalculation===!0)this._calculate(!0);else{const{dirtyRanges:r,dirtyNameMap:s,dirtyUnitFeatureMap:i}=e;this._calculate(!1,r,s,i)}}else if(t.id===ut.id){const e=t.params;if(e==null)return;const{arrayFormulaRange:r,arrayFormulaCellData:s}=e;this._formulaDataModel.setArrayFormulaRange(r),this._formulaDataModel.setArrayFormulaCellData(s)}}))}async _calculate(t=!1,n=[],e={},r={}){if(n.length===0&&Object.keys(e).length===0&&Object.keys(r).length===0&&t===!1)return;const s=this._formulaDataModel.getFormulaData(),i=this._formulaDataModel.getArrayFormulaCellData();this._calculateFormulaService.execute({formulaData:s,arrayFormulaCellData:i,forceCalculate:t,dirtyRanges:n,dirtyNameMap:e,dirtyUnitFeatureMap:r})}_initialExecuteFormulaListener(){this._calculateFormulaService.executionCompleteListener$.subscribe(t=>{const n=t.functionsExecutedState;switch(n){case Be.NOT_EXECUTED:break;case Be.STOP_EXECUTION:break;case Be.SUCCESS:this._applyFormula(t);break;case Be.INITIAL:break}this._commandService.executeCommand(lt.id,{functionsExecutedState:n},{onlyLocal:!0})})}_initialExecuteFormulaProcessListener(){this._calculateFormulaService.executionInProgressListener$.subscribe(t=>{this._commandService.executeCommand(lt.id,{stageInfo:t},{onlyLocal:!0})})}async _applyFormula(t){const{unitData:n,unitOtherData:e,arrayFormulaRange:r,arrayFormulaCellData:s,clearArrayFormulaCellData:i}=t;if(!n){console.error("No sheetData from Formula Engine!");return}r&&(this._formulaDataModel.clearPreviousArrayFormulaCellData(i),this._formulaDataModel.mergeArrayFormulaCellData(s),this._formulaDataModel.mergeArrayFormulaRange(r),this._commandService.executeCommand(ut.id,{arrayFormulaRange:this._formulaDataModel.getArrayFormulaRange(),arrayFormulaCellData:this._formulaDataModel.getArrayFormulaCellData()},{onlyLocal:!0})),this._commandService.executeCommand(qt.id,{unitData:n,unitOtherData:e},{onlyLocal:!0})}};tt=ha([g.OnLifecycle(g.LifecycleStages.Ready,tt),Je(0,g.ICommandService),Je(1,x.Inject(exports.CalculateFormulaService)),Je(2,g.IUniverInstanceService),Je(3,x.Inject(exports.FormulaDataModel))],tt);var fa=Object.defineProperty,da=Object.getOwnPropertyDescriptor,ma=(t,n,e,r)=>{for(var s=r>1?void 0:r?da(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&fa(n,e,s),s},Mt=(t,n)=>(e,r)=>n(e,r,t);let Ye=class extends g.Disposable{constructor(t=[],n,e,r){super(),this._function=t,this._commandService=n,this._injector=e,this._functionService=r,this._initialize()}_initialize(){this._registerCommands(),this._registerFunctions()}_registerCommands(){[Zt,ut,Kt,zt,lt,qt,Dt,wt,Xt,Gt,Jt,Nt,Wr,Ir,er,Wt,tr].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}_registerFunctions(){const t=[...qr,...Zr,...Nr,...tn,...nn,...an,...un,...cn,...hn,...gn,...pn,...En,..._n,...Cn,...Dn,...wn].concat(this._function).map(n=>{const e=n[0],r=n[1];return new e(r)});this._functionService.registerExecutors(...t)}};Ye=ma([g.OnLifecycle(g.LifecycleStages.Ready,Ye),Mt(1,g.ICommandService),Mt(2,x.Inject(x.Injector)),Mt(3,he)],Ye);var ga=Object.defineProperty,Ra=Object.getOwnPropertyDescriptor,pa=(t,n,e,r)=>{for(var s=r>1?void 0:r?Ra(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&ga(n,e,s),s},$t=(t,n)=>(e,r)=>n(e,r,t);let rt=class extends g.Disposable{constructor(t,n,e){super(),this._commandService=t,this._formulaDataModel=n,this._functionService=e,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((t,n)=>{if(t.id===Wt.id){const e=t.params;if(e==null)return;const{functions:r}=e,s=r.map(i=>{const a=i[0],o=i[1];return _a(a,o)});this._functionService.registerExecutors(...s)}else if(t.id===tr.id){const e=t.params;if(e==null)return;const{functions:r}=e;this._functionService.unregisterExecutors(...r)}}))}};rt=pa([g.OnLifecycle(g.LifecycleStages.Ready,rt),$t(0,g.ICommandService),$t(1,x.Inject(exports.FormulaDataModel)),$t(2,he)],rt);class Ea extends O{isCustom(){return!0}}function _a(t,n){const e=new Ea(n),r=new Function(`return ${t}`)();return e.calculateCustom=r,e}var Ca=Object.defineProperty,Da=Object.getOwnPropertyDescriptor,wa=(t,n,e,r)=>{for(var s=r>1?void 0:r?Da(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Ca(n,e,s),s},br=(t,n)=>(e,r)=>n(e,r,t);let nt=class extends g.Disposable{constructor(t,n){super(),this._commandService=t,this._definedNamesService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===Dt.id){const n=t.params;if(n==null)return;const{unitId:e,name:r,formulaOrRefString:s}=n;this._definedNamesService.registerDefinedName(e,r,s)}else if(t.id===wt.id){const n=t.params;if(n==null)return;const{unitId:e,name:r}=n;this._definedNamesService.removeDefinedName(e,r)}}))}};nt=wa([g.OnLifecycle(g.LifecycleStages.Ready,nt),br(0,g.ICommandService),br(1,St)],nt);var ya=Object.defineProperty,ba=Object.getOwnPropertyDescriptor,La=(t,n,e,r)=>{for(var s=r>1?void 0:r?ba(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&ya(n,e,s),s},Lr=(t,n)=>(e,r)=>n(e,r,t);let st=class extends g.Disposable{constructor(t,n){super(),this._commandService=t,this._featureCalculationManagerService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===Xt.id){const n=t.params;if(n==null)return;const{featureId:e,calculationParam:r}=n;this._featureCalculationManagerService.register(e,r)}else if(t.id===Gt.id){const n=t.params;if(n==null)return;const{featureId:e}=n;this._featureCalculationManagerService.remove(e)}}))}};st=La([g.OnLifecycle(g.LifecycleStages.Ready,st),Lr(0,g.ICommandService),Lr(1,Pt)],st);var Sa=Object.defineProperty,Pa=Object.getOwnPropertyDescriptor,xa=(t,n,e,r)=>{for(var s=r>1?void 0:r?Pa(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Sa(n,e,s),s},Sr=(t,n)=>(e,r)=>n(e,r,t);let it=class extends g.Disposable{constructor(t,n){super(),this._commandService=t,this._otherFormulaManagerService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===Jt.id){const n=t.params;if(n==null)return;this._otherFormulaManagerService.register(n)}else if(t.id===Nt.id){const n=t.params;if(n==null)return;this._otherFormulaManagerService.remove(n)}}))}};it=xa([g.OnLifecycle(g.LifecycleStages.Ready,it),Sr(0,g.ICommandService),Sr(1,ir)],it);var Aa=Object.defineProperty,Va=Object.getOwnPropertyDescriptor,va=(t,n,e,r)=>{for(var s=r>1?void 0:r?Va(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Aa(n,e,s),s},Pr=(t,n)=>(e,r)=>n(e,r,t);let at=class extends g.Disposable{constructor(t,n){super(),this._commandService=t,this._superTableService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===Dt.id){const n=t.params;if(n==null)return;const{unitId:e,tableName:r,reference:s}=n;this._superTableService.registerTable(e,r,s)}else if(t.id===wt.id){const n=t.params;if(n==null)return;const{unitId:e,tableName:r}=n;this._superTableService.remove(e,r)}else if(t.id===er.id){const n=t.params;if(n==null)return;const{tableOption:e,tableOptionType:r}=n;this._superTableService.registerTableOptionMap(e,r)}}))}};at=va([g.OnLifecycle(g.LifecycleStages.Ready,at),Pr(0,g.ICommandService),Pr(1,sr)],at);var Ba=Object.defineProperty,Oa=Object.getOwnPropertyDescriptor,Ua=(t,n,e,r)=>{for(var s=r>1?void 0:r?Oa(n,e):n,i=t.length-1,a;i>=0;i--)(a=t[i])&&(s=(r?a(n,e,s):a(s))||s);return r&&s&&Ba(n,e,s),s},Fa=(t,n)=>(e,r)=>n(e,r,t);const Ma="base-formula-engine";exports.UniverFormulaEnginePlugin=class extends g.Plugin{constructor(n,e){super(Ma),this._config=n,this._injector=e}onStarting(){this._initialize()}_initialize(){var e;const n=[[he,{useClass:Ln}],[Pt,{useClass:vn}],[St,{useClass:ri}],[exports.FormulaDataModel],[Ct],[Ye,{useFactory:()=>{var r;return this._injector.createInstance(Ye,(r=this._config)==null?void 0:r.function)}}],[st]];(e=this._config)!=null&&e.notExecuteFormula||n.push([exports.CalculateFormulaService],[ir,{useClass:Bn}],[sr,{useClass:ki}],[ve,{useClass:jt}],[N,{useClass:Tt}],[tt],[nt],[it],[at],[rt],[He],[Ue],[Xe],[xe],[bn],[ft],[dt],[An],[mt],[ht],[gt],[Rt],[pt],[Vn]),n.forEach(r=>this._injector.add(r))}onReady(){this._injector.get(exports.FormulaDataModel).initFormulaData()}};exports.UniverFormulaEnginePlugin=Ua([Fa(1,x.Inject(x.Injector))],exports.UniverFormulaEnginePlugin);exports.ArrayValueObject=G;exports.BaseFunction=O;exports.BaseReferenceObject=ke;exports.BaseValueObject=pe;exports.BooleanValueObject=Q;exports.ErrorType=f;exports.ErrorValueObject=d;exports.FUNCTION_NAMES_ARRAY=_s;exports.FUNCTION_NAMES_COMPATIBILITY=Jr;exports.FUNCTION_NAMES_CUBE=en;exports.FUNCTION_NAMES_DATABASE=rn;exports.FUNCTION_NAMES_DATE=sn;exports.FUNCTION_NAMES_ENGINEERING=on;exports.FUNCTION_NAMES_FINANCIAL=ln;exports.FUNCTION_NAMES_INFORMATION=nr;exports.FUNCTION_NAMES_LOGICAL=we;exports.FUNCTION_NAMES_LOOKUP=oe;exports.FUNCTION_NAMES_MATH=Z;exports.FUNCTION_NAMES_STATISTICAL=de;exports.FUNCTION_NAMES_TEXT=Lt;exports.FUNCTION_NAMES_UNIVER=ti;exports.FUNCTION_NAMES_WEB=yn;exports.FeatureCalculationManagerService=vn;exports.FormulaExecuteStageType=ee;exports.FormulaExecutedStateType=Be;exports.FunctionService=Ln;exports.FunctionType=Ar;exports.IFeatureCalculationManagerService=Pt;exports.IFunctionService=he;exports.LexerNode=A;exports.LexerTreeBuilder=Ct;exports.NumberValueObject=D;exports.OtherFormulaManagerService=Bn;exports.RangeReferenceObject=Ie;exports.RegisterFunctionMutation=Wt;exports.RemoveDefinedNameMutation=wt;exports.RemoveFeatureCalculationMutation=Gt;exports.RemoveOtherFormulaMutation=Nt;exports.RemoveSuperTableMutation=Ir;exports.SetArrayFormulaDataMutation=ut;exports.SetArrayFormulaDataUndoMutationFactory=es;exports.SetDefinedNameMutation=Dt;exports.SetFeatureCalculationMutation=Xt;exports.SetFormulaCalculationNotificationMutation=lt;exports.SetFormulaCalculationResultMutation=qt;exports.SetFormulaCalculationStartMutation=Kt;exports.SetFormulaCalculationStopMutation=zt;exports.SetFormulaDataMutation=Zt;exports.SetOtherFormulaMutation=Jt;exports.SetSuperTableMutation=Wr;exports.SetSuperTableOptionMutation=er;exports.StringValueObject=Y;exports.UNIT_NAME_REGEX=ce;exports.UnregisterFunctionMutation=tr;exports.ValueObjectFactory=Re;exports.compareToken=y;exports.convertUnitDataToRuntime=Br;exports.deserializeRangeForR1C1=zr;exports.deserializeRangeWithSheet=Fe;exports.functionArray=qr;exports.functionCompatibility=Zr;exports.functionCube=Nr;exports.functionDatabase=tn;exports.functionDate=nn;exports.functionEngineering=an;exports.functionFinancial=un;exports.functionInformation=cn;exports.functionLogical=hn;exports.functionLookup=gn;exports.functionMath=pn;exports.functionMeta=En;exports.functionStatistical=_n;exports.functionText=Cn;exports.functionUniver=Dn;exports.functionWeb=wn;exports.generateStringWithSequence=Tr;exports.getAbsoluteRefTypeWitString=Tn;exports.getAbsoluteRefTypeWithSingleString=Te;exports.includeFormulaLexerToken=vr;exports.initSheetFormulaData=Yr;exports.isFormulaLexerToken=et;exports.isInDirtyRange=xr;exports.matchToken=B;exports.normalizeSheetName=kn;exports.sequenceNodeType=z;exports.serializeRange=Le;exports.serializeRangeToRefString=Fr;exports.serializeRangeWithSheet=Or;exports.serializeRangeWithSpreadsheet=Ur;
|